api.c 3.7 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865398663986739868398693987039871398723987339874398753987639877398783987939880398813988239883398843988539886398873988839889398903989139892398933989439895398963989739898398993990039901399023990339904399053990639907399083990939910399113991239913399143991539916399173991839919399203992139922399233992439925399263992739928399293993039931399323993339934399353993639937399383993939940399413994239943399443994539946399473994839949399503995139952399533995439955399563995739958399593996039961399623996339964399653996639967399683996939970399713997239973399743997539976399773997839979399803998139982399833998439985399863998739988399893999039991399923999339994399953999639997399983999940000400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042400434004440045400464004740048400494005040051400524005340054400554005640057400584005940060400614006240063400644006540066400674006840069400704007140072400734007440075400764007740078400794008040081400824008340084400854008640087400884008940090400914009240093400944009540096400974009840099401004010140102401034010440105401064010740108401094011040111401124011340114401154011640117401184011940120401214012240123401244012540126401274012840129401304013140132401334013440135401364013740138401394014040141401424014340144401454014640147401484014940150401514015240153401544015540156401574015840159401604016140162401634016440165401664016740168401694017040171401724017340174401754017640177401784017940180401814018240183401844018540186401874018840189401904019140192401934019440195401964019740198401994020040201402024020340204402054020640207402084020940210402114021240213402144021540216402174021840219402204022140222402234022440225402264022740228402294023040231402324023340234402354023640237402384023940240402414024240243402444024540246402474024840249402504025140252402534025440255402564025740258402594026040261402624026340264402654026640267402684026940270402714027240273402744027540276402774027840279402804028140282402834028440285402864028740288402894029040291402924029340294402954029640297402984029940300403014030240303403044030540306403074030840309403104031140312403134031440315403164031740318403194032040321403224032340324403254032640327403284032940330403314033240333403344033540336403374033840339403404034140342403434034440345403464034740348403494035040351403524035340354403554035640357403584035940360403614036240363403644036540366403674036840369403704037140372403734037440375403764037740378403794038040381403824038340384403854038640387403884038940390403914039240393403944039540396403974039840399404004040140402404034040440405404064040740408404094041040411404124041340414404154041640417404184041940420404214042240423404244042540426404274042840429404304043140432404334043440435404364043740438404394044040441404424044340444404454044640447404484044940450404514045240453404544045540456404574045840459404604046140462404634046440465404664046740468404694047040471404724047340474404754047640477404784047940480404814048240483404844048540486404874048840489404904049140492404934049440495404964049740498404994050040501405024050340504405054050640507405084050940510405114051240513405144051540516405174051840519405204052140522405234052440525405264052740528405294053040531405324053340534405354053640537405384053940540405414054240543405444054540546405474054840549405504055140552405534055440555405564055740558405594056040561405624056340564405654056640567405684056940570405714057240573405744057540576405774057840579405804058140582405834058440585405864058740588405894059040591405924059340594405954059640597405984059940600406014060240603406044060540606406074060840609406104061140612406134061440615406164061740618406194062040621406224062340624406254062640627406284062940630406314063240633406344063540636406374063840639406404064140642406434064440645406464064740648406494065040651406524065340654406554065640657406584065940660406614066240663406644066540666406674066840669406704067140672406734067440675406764067740678406794068040681406824068340684406854068640687406884068940690406914069240693406944069540696406974069840699407004070140702407034070440705407064070740708407094071040711407124071340714407154071640717407184071940720407214072240723407244072540726407274072840729407304073140732407334073440735407364073740738407394074040741407424074340744407454074640747407484074940750407514075240753407544075540756407574075840759407604076140762407634076440765407664076740768407694077040771407724077340774407754077640777407784077940780407814078240783407844078540786407874078840789407904079140792407934079440795407964079740798407994080040801408024080340804408054080640807408084080940810408114081240813408144081540816408174081840819408204082140822408234082440825408264082740828408294083040831408324083340834408354083640837408384083940840408414084240843408444084540846408474084840849408504085140852408534085440855408564085740858408594086040861408624086340864408654086640867408684086940870408714087240873408744087540876408774087840879408804088140882408834088440885408864088740888408894089040891408924089340894408954089640897408984089940900409014090240903409044090540906409074090840909409104091140912409134091440915409164091740918409194092040921409224092340924409254092640927409284092940930409314093240933409344093540936409374093840939409404094140942409434094440945409464094740948409494095040951409524095340954409554095640957409584095940960409614096240963409644096540966409674096840969409704097140972409734097440975409764097740978409794098040981409824098340984409854098640987409884098940990409914099240993409944099540996409974099840999410004100141002410034100441005410064100741008410094101041011410124101341014410154101641017410184101941020410214102241023410244102541026410274102841029410304103141032410334103441035410364103741038410394104041041410424104341044410454104641047410484104941050410514105241053410544105541056410574105841059410604106141062410634106441065410664106741068410694107041071410724107341074410754107641077410784107941080410814108241083410844108541086410874108841089410904109141092410934109441095410964109741098410994110041101411024110341104411054110641107411084110941110411114111241113411144111541116411174111841119411204112141122411234112441125411264112741128411294113041131411324113341134411354113641137411384113941140411414114241143411444114541146411474114841149411504115141152411534115441155411564115741158411594116041161411624116341164411654116641167411684116941170411714117241173411744117541176411774117841179411804118141182411834118441185411864118741188411894119041191411924119341194411954119641197411984119941200412014120241203412044120541206412074120841209412104121141212412134121441215412164121741218412194122041221412224122341224412254122641227412284122941230412314123241233412344123541236412374123841239412404124141242412434124441245412464124741248412494125041251412524125341254412554125641257412584125941260412614126241263412644126541266412674126841269412704127141272412734127441275412764127741278412794128041281412824128341284412854128641287412884128941290412914129241293412944129541296412974129841299413004130141302413034130441305413064130741308413094131041311413124131341314413154131641317413184131941320413214132241323413244132541326413274132841329413304133141332413334133441335413364133741338413394134041341413424134341344413454134641347413484134941350413514135241353413544135541356413574135841359413604136141362413634136441365413664136741368413694137041371413724137341374413754137641377413784137941380413814138241383413844138541386413874138841389413904139141392413934139441395413964139741398413994140041401414024140341404414054140641407414084140941410414114141241413414144141541416414174141841419414204142141422414234142441425414264142741428414294143041431414324143341434414354143641437414384143941440414414144241443414444144541446414474144841449414504145141452414534145441455414564145741458414594146041461414624146341464414654146641467414684146941470414714147241473414744147541476414774147841479414804148141482414834148441485414864148741488414894149041491414924149341494414954149641497414984149941500415014150241503415044150541506415074150841509415104151141512415134151441515415164151741518415194152041521415224152341524415254152641527415284152941530415314153241533415344153541536415374153841539415404154141542415434154441545415464154741548415494155041551415524155341554415554155641557415584155941560415614156241563415644156541566415674156841569415704157141572415734157441575415764157741578415794158041581415824158341584415854158641587415884158941590415914159241593415944159541596415974159841599416004160141602416034160441605416064160741608416094161041611416124161341614416154161641617416184161941620416214162241623416244162541626416274162841629416304163141632416334163441635416364163741638416394164041641416424164341644416454164641647416484164941650416514165241653416544165541656416574165841659416604166141662416634166441665416664166741668416694167041671416724167341674416754167641677416784167941680416814168241683416844168541686416874168841689416904169141692416934169441695416964169741698416994170041701417024170341704417054170641707417084170941710417114171241713417144171541716417174171841719417204172141722417234172441725417264172741728417294173041731417324173341734417354173641737417384173941740417414174241743417444174541746417474174841749417504175141752417534175441755417564175741758417594176041761417624176341764417654176641767417684176941770417714177241773417744177541776417774177841779417804178141782417834178441785417864178741788417894179041791417924179341794417954179641797417984179941800418014180241803418044180541806418074180841809418104181141812418134181441815418164181741818418194182041821418224182341824418254182641827418284182941830418314183241833418344183541836418374183841839418404184141842418434184441845418464184741848418494185041851418524185341854418554185641857418584185941860418614186241863418644186541866418674186841869418704187141872418734187441875418764187741878418794188041881418824188341884418854188641887418884188941890418914189241893418944189541896418974189841899419004190141902419034190441905419064190741908419094191041911419124191341914419154191641917419184191941920419214192241923419244192541926419274192841929419304193141932419334193441935419364193741938419394194041941419424194341944419454194641947419484194941950419514195241953419544195541956419574195841959419604196141962419634196441965419664196741968419694197041971419724197341974419754197641977419784197941980419814198241983419844198541986419874198841989419904199141992419934199441995419964199741998419994200042001420024200342004420054200642007420084200942010420114201242013420144201542016420174201842019420204202142022420234202442025420264202742028420294203042031420324203342034420354203642037420384203942040420414204242043420444204542046420474204842049420504205142052420534205442055420564205742058420594206042061420624206342064420654206642067420684206942070420714207242073420744207542076420774207842079420804208142082420834208442085420864208742088420894209042091420924209342094420954209642097420984209942100421014210242103421044210542106421074210842109421104211142112421134211442115421164211742118421194212042121421224212342124421254212642127421284212942130421314213242133421344213542136421374213842139421404214142142421434214442145421464214742148421494215042151421524215342154421554215642157421584215942160421614216242163421644216542166421674216842169421704217142172421734217442175421764217742178421794218042181421824218342184421854218642187421884218942190421914219242193421944219542196421974219842199422004220142202422034220442205422064220742208422094221042211422124221342214422154221642217422184221942220422214222242223422244222542226422274222842229422304223142232422334223442235422364223742238422394224042241422424224342244422454224642247422484224942250422514225242253422544225542256422574225842259422604226142262422634226442265422664226742268422694227042271422724227342274422754227642277422784227942280422814228242283422844228542286422874228842289422904229142292422934229442295422964229742298422994230042301423024230342304423054230642307423084230942310423114231242313423144231542316423174231842319423204232142322423234232442325423264232742328423294233042331423324233342334423354233642337423384233942340423414234242343423444234542346423474234842349423504235142352423534235442355423564235742358423594236042361423624236342364423654236642367423684236942370423714237242373423744237542376423774237842379423804238142382423834238442385423864238742388423894239042391423924239342394423954239642397423984239942400424014240242403424044240542406424074240842409424104241142412424134241442415424164241742418424194242042421424224242342424424254242642427424284242942430424314243242433424344243542436424374243842439424404244142442424434244442445424464244742448424494245042451424524245342454424554245642457424584245942460424614246242463424644246542466424674246842469424704247142472424734247442475424764247742478424794248042481424824248342484424854248642487424884248942490424914249242493424944249542496424974249842499425004250142502425034250442505425064250742508425094251042511425124251342514425154251642517425184251942520425214252242523425244252542526425274252842529425304253142532425334253442535425364253742538425394254042541425424254342544425454254642547425484254942550425514255242553425544255542556425574255842559425604256142562425634256442565425664256742568425694257042571425724257342574425754257642577425784257942580425814258242583425844258542586425874258842589425904259142592425934259442595425964259742598425994260042601426024260342604426054260642607426084260942610426114261242613426144261542616426174261842619426204262142622426234262442625426264262742628426294263042631426324263342634426354263642637426384263942640426414264242643426444264542646426474264842649426504265142652426534265442655426564265742658426594266042661426624266342664426654266642667426684266942670426714267242673426744267542676426774267842679426804268142682426834268442685426864268742688426894269042691426924269342694426954269642697426984269942700427014270242703427044270542706427074270842709427104271142712427134271442715427164271742718427194272042721427224272342724427254272642727427284272942730427314273242733427344273542736427374273842739427404274142742427434274442745427464274742748427494275042751427524275342754427554275642757427584275942760427614276242763427644276542766427674276842769427704277142772427734277442775427764277742778427794278042781427824278342784427854278642787427884278942790427914279242793427944279542796427974279842799428004280142802428034280442805428064280742808428094281042811428124281342814428154281642817428184281942820428214282242823428244282542826428274282842829428304283142832428334283442835428364283742838428394284042841428424284342844428454284642847428484284942850428514285242853428544285542856428574285842859428604286142862428634286442865428664286742868428694287042871428724287342874428754287642877428784287942880428814288242883428844288542886428874288842889428904289142892428934289442895428964289742898428994290042901429024290342904429054290642907429084290942910429114291242913429144291542916429174291842919429204292142922429234292442925429264292742928429294293042931429324293342934429354293642937429384293942940429414294242943429444294542946429474294842949429504295142952429534295442955429564295742958429594296042961429624296342964429654296642967429684296942970429714297242973429744297542976429774297842979429804298142982429834298442985429864298742988429894299042991429924299342994429954299642997429984299943000430014300243003430044300543006430074300843009430104301143012430134301443015430164301743018430194302043021430224302343024430254302643027430284302943030430314303243033430344303543036430374303843039430404304143042430434304443045430464304743048430494305043051430524305343054430554305643057430584305943060430614306243063430644306543066430674306843069430704307143072430734307443075430764307743078430794308043081430824308343084430854308643087430884308943090430914309243093430944309543096430974309843099431004310143102431034310443105431064310743108431094311043111431124311343114431154311643117431184311943120431214312243123431244312543126431274312843129431304313143132431334313443135431364313743138431394314043141431424314343144431454314643147431484314943150431514315243153431544315543156431574315843159431604316143162431634316443165431664316743168431694317043171431724317343174431754317643177431784317943180431814318243183431844318543186431874318843189431904319143192431934319443195431964319743198431994320043201432024320343204432054320643207432084320943210432114321243213432144321543216432174321843219432204322143222432234322443225432264322743228432294323043231432324323343234432354323643237432384323943240432414324243243432444324543246432474324843249432504325143252432534325443255432564325743258432594326043261432624326343264432654326643267432684326943270432714327243273432744327543276432774327843279432804328143282432834328443285432864328743288432894329043291432924329343294432954329643297432984329943300433014330243303433044330543306433074330843309433104331143312433134331443315433164331743318433194332043321433224332343324433254332643327433284332943330433314333243333433344333543336433374333843339433404334143342433434334443345433464334743348433494335043351433524335343354433554335643357433584335943360433614336243363433644336543366433674336843369433704337143372433734337443375433764337743378433794338043381433824338343384433854338643387433884338943390433914339243393433944339543396433974339843399434004340143402434034340443405434064340743408434094341043411434124341343414434154341643417434184341943420434214342243423434244342543426434274342843429434304343143432434334343443435434364343743438434394344043441434424344343444434454344643447434484344943450434514345243453434544345543456434574345843459434604346143462434634346443465434664346743468434694347043471434724347343474434754347643477434784347943480434814348243483434844348543486434874348843489434904349143492434934349443495434964349743498434994350043501435024350343504435054350643507435084350943510435114351243513435144351543516435174351843519435204352143522435234352443525435264352743528435294353043531435324353343534435354353643537435384353943540435414354243543435444354543546435474354843549435504355143552435534355443555435564355743558435594356043561435624356343564435654356643567435684356943570435714357243573435744357543576435774357843579435804358143582435834358443585435864358743588435894359043591435924359343594435954359643597435984359943600436014360243603436044360543606436074360843609436104361143612436134361443615436164361743618436194362043621436224362343624436254362643627436284362943630436314363243633436344363543636436374363843639436404364143642436434364443645436464364743648436494365043651436524365343654436554365643657436584365943660436614366243663436644366543666436674366843669436704367143672436734367443675436764367743678436794368043681436824368343684436854368643687436884368943690436914369243693436944369543696436974369843699437004370143702437034370443705437064370743708437094371043711437124371343714437154371643717437184371943720437214372243723437244372543726437274372843729437304373143732437334373443735437364373743738437394374043741437424374343744437454374643747437484374943750437514375243753437544375543756437574375843759437604376143762437634376443765437664376743768437694377043771437724377343774437754377643777437784377943780437814378243783437844378543786437874378843789437904379143792437934379443795437964379743798437994380043801438024380343804438054380643807438084380943810438114381243813438144381543816438174381843819438204382143822438234382443825438264382743828438294383043831438324383343834438354383643837438384383943840438414384243843438444384543846438474384843849438504385143852438534385443855438564385743858438594386043861438624386343864438654386643867438684386943870438714387243873438744387543876438774387843879438804388143882438834388443885438864388743888438894389043891438924389343894438954389643897438984389943900439014390243903439044390543906439074390843909439104391143912439134391443915439164391743918439194392043921439224392343924439254392643927439284392943930439314393243933439344393543936439374393843939439404394143942439434394443945439464394743948439494395043951439524395343954439554395643957439584395943960439614396243963439644396543966439674396843969439704397143972439734397443975439764397743978439794398043981439824398343984439854398643987439884398943990439914399243993439944399543996439974399843999440004400144002440034400444005440064400744008440094401044011440124401344014440154401644017440184401944020440214402244023440244402544026440274402844029440304403144032440334403444035440364403744038440394404044041440424404344044440454404644047440484404944050440514405244053440544405544056440574405844059440604406144062440634406444065440664406744068440694407044071440724407344074440754407644077440784407944080440814408244083440844408544086440874408844089440904409144092440934409444095440964409744098440994410044101441024410344104441054410644107441084410944110441114411244113441144411544116441174411844119441204412144122441234412444125441264412744128441294413044131441324413344134441354413644137441384413944140441414414244143441444414544146441474414844149441504415144152441534415444155441564415744158441594416044161441624416344164441654416644167441684416944170441714417244173441744417544176441774417844179441804418144182441834418444185441864418744188441894419044191441924419344194441954419644197441984419944200442014420244203442044420544206442074420844209442104421144212442134421444215442164421744218442194422044221442224422344224442254422644227442284422944230442314423244233442344423544236442374423844239442404424144242442434424444245442464424744248442494425044251442524425344254442554425644257442584425944260442614426244263442644426544266442674426844269442704427144272442734427444275442764427744278442794428044281442824428344284442854428644287442884428944290442914429244293442944429544296442974429844299443004430144302443034430444305443064430744308443094431044311443124431344314443154431644317443184431944320443214432244323443244432544326443274432844329443304433144332443334433444335443364433744338443394434044341443424434344344443454434644347443484434944350443514435244353443544435544356443574435844359443604436144362443634436444365443664436744368443694437044371443724437344374443754437644377443784437944380443814438244383443844438544386443874438844389443904439144392443934439444395443964439744398443994440044401444024440344404444054440644407444084440944410444114441244413444144441544416444174441844419444204442144422444234442444425444264442744428444294443044431444324443344434444354443644437444384443944440444414444244443444444444544446444474444844449444504445144452444534445444455444564445744458444594446044461444624446344464444654446644467444684446944470444714447244473444744447544476444774447844479444804448144482444834448444485444864448744488444894449044491444924449344494444954449644497444984449944500445014450244503445044450544506445074450844509445104451144512445134451444515445164451744518445194452044521445224452344524445254452644527445284452944530445314453244533445344453544536445374453844539445404454144542445434454444545445464454744548445494455044551445524455344554445554455644557445584455944560445614456244563445644456544566445674456844569445704457144572445734457444575445764457744578445794458044581445824458344584445854458644587445884458944590445914459244593445944459544596445974459844599446004460144602446034460444605446064460744608446094461044611446124461344614446154461644617446184461944620446214462244623446244462544626446274462844629446304463144632446334463444635446364463744638446394464044641446424464344644446454464644647446484464944650446514465244653446544465544656446574465844659446604466144662446634466444665446664466744668446694467044671446724467344674446754467644677446784467944680446814468244683446844468544686446874468844689446904469144692446934469444695446964469744698446994470044701447024470344704447054470644707447084470944710447114471244713447144471544716447174471844719447204472144722447234472444725447264472744728447294473044731447324473344734447354473644737447384473944740447414474244743447444474544746447474474844749447504475144752447534475444755447564475744758447594476044761447624476344764447654476644767447684476944770447714477244773447744477544776447774477844779447804478144782447834478444785447864478744788447894479044791447924479344794447954479644797447984479944800448014480244803448044480544806448074480844809448104481144812448134481444815448164481744818448194482044821448224482344824448254482644827448284482944830448314483244833448344483544836448374483844839448404484144842448434484444845448464484744848448494485044851448524485344854448554485644857448584485944860448614486244863448644486544866448674486844869448704487144872448734487444875448764487744878448794488044881448824488344884448854488644887448884488944890448914489244893448944489544896448974489844899449004490144902449034490444905449064490744908449094491044911449124491344914449154491644917449184491944920449214492244923449244492544926449274492844929449304493144932449334493444935449364493744938449394494044941449424494344944449454494644947449484494944950449514495244953449544495544956449574495844959449604496144962449634496444965449664496744968449694497044971449724497344974449754497644977449784497944980449814498244983449844498544986449874498844989449904499144992449934499444995449964499744998449994500045001450024500345004450054500645007450084500945010450114501245013450144501545016450174501845019450204502145022450234502445025450264502745028450294503045031450324503345034450354503645037450384503945040450414504245043450444504545046450474504845049450504505145052450534505445055450564505745058450594506045061450624506345064450654506645067450684506945070450714507245073450744507545076450774507845079450804508145082450834508445085450864508745088450894509045091450924509345094450954509645097450984509945100451014510245103451044510545106451074510845109451104511145112451134511445115451164511745118451194512045121451224512345124451254512645127451284512945130451314513245133451344513545136451374513845139451404514145142451434514445145451464514745148451494515045151451524515345154451554515645157451584515945160451614516245163451644516545166451674516845169451704517145172451734517445175451764517745178451794518045181451824518345184451854518645187451884518945190451914519245193451944519545196451974519845199452004520145202452034520445205452064520745208452094521045211452124521345214452154521645217452184521945220452214522245223452244522545226452274522845229452304523145232452334523445235452364523745238452394524045241452424524345244452454524645247452484524945250452514525245253452544525545256452574525845259452604526145262452634526445265452664526745268452694527045271452724527345274452754527645277452784527945280452814528245283452844528545286452874528845289452904529145292452934529445295452964529745298452994530045301453024530345304453054530645307453084530945310453114531245313453144531545316453174531845319453204532145322453234532445325453264532745328453294533045331453324533345334453354533645337453384533945340453414534245343453444534545346453474534845349453504535145352453534535445355453564535745358453594536045361453624536345364453654536645367453684536945370453714537245373453744537545376453774537845379453804538145382453834538445385453864538745388453894539045391453924539345394453954539645397453984539945400454014540245403454044540545406454074540845409454104541145412454134541445415454164541745418454194542045421454224542345424454254542645427454284542945430454314543245433454344543545436454374543845439454404544145442454434544445445454464544745448454494545045451454524545345454454554545645457454584545945460454614546245463454644546545466454674546845469454704547145472454734547445475454764547745478454794548045481454824548345484454854548645487454884548945490454914549245493454944549545496454974549845499455004550145502455034550445505455064550745508455094551045511455124551345514455154551645517455184551945520455214552245523455244552545526455274552845529455304553145532455334553445535455364553745538455394554045541455424554345544455454554645547455484554945550455514555245553455544555545556455574555845559455604556145562455634556445565455664556745568455694557045571455724557345574455754557645577455784557945580455814558245583455844558545586455874558845589455904559145592455934559445595455964559745598455994560045601456024560345604456054560645607456084560945610456114561245613456144561545616456174561845619456204562145622456234562445625456264562745628456294563045631456324563345634456354563645637456384563945640456414564245643456444564545646456474564845649456504565145652456534565445655456564565745658456594566045661456624566345664456654566645667456684566945670456714567245673456744567545676456774567845679456804568145682456834568445685456864568745688456894569045691456924569345694456954569645697456984569945700457014570245703457044570545706457074570845709457104571145712457134571445715457164571745718457194572045721457224572345724457254572645727457284572945730457314573245733457344573545736457374573845739457404574145742457434574445745457464574745748457494575045751457524575345754457554575645757457584575945760457614576245763457644576545766457674576845769457704577145772457734577445775457764577745778457794578045781457824578345784457854578645787457884578945790457914579245793457944579545796457974579845799458004580145802458034580445805458064580745808458094581045811458124581345814458154581645817458184581945820458214582245823458244582545826458274582845829458304583145832458334583445835458364583745838458394584045841458424584345844458454584645847458484584945850458514585245853458544585545856458574585845859458604586145862458634586445865458664586745868458694587045871458724587345874458754587645877458784587945880458814588245883458844588545886458874588845889458904589145892458934589445895458964589745898458994590045901459024590345904459054590645907459084590945910459114591245913459144591545916459174591845919459204592145922459234592445925459264592745928459294593045931459324593345934459354593645937459384593945940459414594245943459444594545946459474594845949459504595145952459534595445955459564595745958459594596045961459624596345964459654596645967459684596945970459714597245973459744597545976459774597845979459804598145982459834598445985459864598745988459894599045991459924599345994459954599645997459984599946000460014600246003460044600546006460074600846009460104601146012460134601446015460164601746018460194602046021460224602346024460254602646027460284602946030460314603246033460344603546036460374603846039460404604146042460434604446045460464604746048460494605046051460524605346054460554605646057460584605946060460614606246063460644606546066460674606846069460704607146072460734607446075460764607746078460794608046081460824608346084460854608646087460884608946090460914609246093460944609546096460974609846099461004610146102461034610446105461064610746108461094611046111461124611346114461154611646117461184611946120461214612246123461244612546126461274612846129461304613146132461334613446135461364613746138461394614046141461424614346144461454614646147461484614946150461514615246153461544615546156461574615846159461604616146162461634616446165461664616746168461694617046171461724617346174461754617646177461784617946180461814618246183461844618546186461874618846189461904619146192461934619446195461964619746198461994620046201462024620346204462054620646207462084620946210462114621246213462144621546216462174621846219462204622146222462234622446225462264622746228462294623046231462324623346234462354623646237462384623946240462414624246243462444624546246462474624846249462504625146252462534625446255462564625746258462594626046261462624626346264462654626646267462684626946270462714627246273462744627546276462774627846279462804628146282462834628446285462864628746288462894629046291462924629346294462954629646297462984629946300463014630246303463044630546306463074630846309463104631146312463134631446315463164631746318463194632046321463224632346324463254632646327463284632946330463314633246333463344633546336463374633846339463404634146342463434634446345463464634746348463494635046351463524635346354463554635646357463584635946360463614636246363463644636546366463674636846369463704637146372463734637446375463764637746378463794638046381463824638346384463854638646387463884638946390463914639246393463944639546396463974639846399464004640146402464034640446405464064640746408464094641046411464124641346414464154641646417464184641946420464214642246423464244642546426464274642846429464304643146432464334643446435464364643746438464394644046441464424644346444464454644646447464484644946450464514645246453464544645546456464574645846459464604646146462464634646446465464664646746468464694647046471464724647346474464754647646477464784647946480464814648246483464844648546486464874648846489464904649146492464934649446495464964649746498464994650046501465024650346504465054650646507465084650946510465114651246513465144651546516465174651846519465204652146522465234652446525465264652746528465294653046531465324653346534465354653646537465384653946540465414654246543465444654546546465474654846549465504655146552465534655446555465564655746558465594656046561465624656346564465654656646567465684656946570465714657246573465744657546576465774657846579465804658146582465834658446585465864658746588465894659046591465924659346594465954659646597465984659946600466014660246603466044660546606466074660846609466104661146612466134661446615466164661746618466194662046621466224662346624466254662646627466284662946630466314663246633466344663546636466374663846639466404664146642466434664446645466464664746648466494665046651466524665346654466554665646657466584665946660466614666246663466644666546666466674666846669466704667146672466734667446675466764667746678466794668046681466824668346684466854668646687466884668946690466914669246693466944669546696466974669846699467004670146702467034670446705467064670746708467094671046711467124671346714467154671646717467184671946720467214672246723467244672546726467274672846729467304673146732467334673446735467364673746738467394674046741467424674346744467454674646747467484674946750467514675246753467544675546756467574675846759467604676146762467634676446765467664676746768467694677046771467724677346774467754677646777467784677946780467814678246783467844678546786467874678846789467904679146792467934679446795467964679746798467994680046801468024680346804468054680646807468084680946810468114681246813468144681546816468174681846819468204682146822468234682446825468264682746828468294683046831468324683346834468354683646837468384683946840468414684246843468444684546846468474684846849468504685146852468534685446855468564685746858468594686046861468624686346864468654686646867468684686946870468714687246873468744687546876468774687846879468804688146882468834688446885468864688746888468894689046891468924689346894468954689646897468984689946900469014690246903469044690546906469074690846909469104691146912469134691446915469164691746918469194692046921469224692346924469254692646927469284692946930469314693246933469344693546936469374693846939469404694146942469434694446945469464694746948469494695046951469524695346954469554695646957469584695946960469614696246963469644696546966469674696846969469704697146972469734697446975469764697746978469794698046981469824698346984469854698646987469884698946990469914699246993469944699546996469974699846999470004700147002470034700447005470064700747008470094701047011470124701347014470154701647017470184701947020470214702247023470244702547026470274702847029470304703147032470334703447035470364703747038470394704047041470424704347044470454704647047470484704947050470514705247053470544705547056470574705847059470604706147062470634706447065470664706747068470694707047071470724707347074470754707647077470784707947080470814708247083470844708547086470874708847089470904709147092470934709447095470964709747098470994710047101471024710347104471054710647107471084710947110471114711247113471144711547116471174711847119471204712147122471234712447125471264712747128471294713047131471324713347134471354713647137471384713947140471414714247143471444714547146471474714847149471504715147152471534715447155471564715747158471594716047161471624716347164471654716647167471684716947170471714717247173471744717547176471774717847179471804718147182471834718447185471864718747188471894719047191471924719347194471954719647197471984719947200472014720247203472044720547206472074720847209472104721147212472134721447215472164721747218472194722047221472224722347224472254722647227472284722947230472314723247233472344723547236472374723847239472404724147242472434724447245472464724747248472494725047251472524725347254472554725647257472584725947260472614726247263472644726547266472674726847269472704727147272472734727447275472764727747278472794728047281472824728347284472854728647287472884728947290472914729247293472944729547296472974729847299473004730147302473034730447305473064730747308473094731047311473124731347314473154731647317473184731947320473214732247323473244732547326473274732847329473304733147332473334733447335473364733747338473394734047341473424734347344473454734647347473484734947350473514735247353473544735547356473574735847359473604736147362473634736447365473664736747368473694737047371473724737347374473754737647377473784737947380473814738247383473844738547386473874738847389473904739147392473934739447395473964739747398473994740047401474024740347404474054740647407474084740947410474114741247413474144741547416474174741847419474204742147422474234742447425474264742747428474294743047431474324743347434474354743647437474384743947440474414744247443474444744547446474474744847449474504745147452474534745447455474564745747458474594746047461474624746347464474654746647467474684746947470474714747247473474744747547476474774747847479474804748147482474834748447485474864748747488474894749047491474924749347494474954749647497474984749947500475014750247503475044750547506475074750847509475104751147512475134751447515475164751747518475194752047521475224752347524475254752647527475284752947530475314753247533475344753547536475374753847539475404754147542475434754447545475464754747548475494755047551475524755347554475554755647557475584755947560475614756247563475644756547566475674756847569475704757147572475734757447575475764757747578475794758047581475824758347584475854758647587475884758947590475914759247593475944759547596475974759847599476004760147602476034760447605476064760747608476094761047611476124761347614476154761647617476184761947620476214762247623476244762547626476274762847629476304763147632476334763447635476364763747638476394764047641476424764347644476454764647647476484764947650476514765247653476544765547656476574765847659476604766147662476634766447665476664766747668476694767047671476724767347674476754767647677476784767947680476814768247683476844768547686476874768847689476904769147692476934769447695476964769747698476994770047701477024770347704477054770647707477084770947710477114771247713477144771547716477174771847719477204772147722477234772447725477264772747728477294773047731477324773347734477354773647737477384773947740477414774247743477444774547746477474774847749477504775147752477534775447755477564775747758477594776047761477624776347764477654776647767477684776947770477714777247773477744777547776477774777847779477804778147782477834778447785477864778747788477894779047791477924779347794477954779647797477984779947800478014780247803478044780547806478074780847809478104781147812478134781447815478164781747818478194782047821478224782347824478254782647827478284782947830478314783247833478344783547836478374783847839478404784147842478434784447845478464784747848478494785047851478524785347854478554785647857478584785947860478614786247863478644786547866478674786847869478704787147872478734787447875478764787747878478794788047881478824788347884478854788647887478884788947890478914789247893478944789547896478974789847899479004790147902479034790447905479064790747908479094791047911479124791347914479154791647917479184791947920479214792247923479244792547926479274792847929479304793147932479334793447935479364793747938479394794047941479424794347944479454794647947479484794947950479514795247953479544795547956479574795847959479604796147962479634796447965479664796747968479694797047971479724797347974479754797647977479784797947980479814798247983479844798547986479874798847989479904799147992479934799447995479964799747998479994800048001480024800348004480054800648007480084800948010480114801248013480144801548016480174801848019480204802148022480234802448025480264802748028480294803048031480324803348034480354803648037480384803948040480414804248043480444804548046480474804848049480504805148052480534805448055480564805748058480594806048061480624806348064480654806648067480684806948070480714807248073480744807548076480774807848079480804808148082480834808448085480864808748088480894809048091480924809348094480954809648097480984809948100481014810248103481044810548106481074810848109481104811148112481134811448115481164811748118481194812048121481224812348124481254812648127481284812948130481314813248133481344813548136481374813848139481404814148142481434814448145481464814748148481494815048151481524815348154481554815648157481584815948160481614816248163481644816548166481674816848169481704817148172481734817448175481764817748178481794818048181481824818348184481854818648187481884818948190481914819248193481944819548196481974819848199482004820148202482034820448205482064820748208482094821048211482124821348214482154821648217482184821948220482214822248223482244822548226482274822848229482304823148232482334823448235482364823748238482394824048241482424824348244482454824648247482484824948250482514825248253482544825548256482574825848259482604826148262482634826448265482664826748268482694827048271482724827348274482754827648277482784827948280482814828248283482844828548286482874828848289482904829148292482934829448295482964829748298482994830048301483024830348304483054830648307483084830948310483114831248313483144831548316483174831848319483204832148322483234832448325483264832748328483294833048331483324833348334483354833648337483384833948340483414834248343483444834548346483474834848349483504835148352483534835448355483564835748358483594836048361483624836348364483654836648367483684836948370483714837248373483744837548376483774837848379483804838148382483834838448385483864838748388483894839048391483924839348394483954839648397483984839948400484014840248403484044840548406484074840848409484104841148412484134841448415484164841748418484194842048421484224842348424484254842648427484284842948430484314843248433484344843548436484374843848439484404844148442484434844448445484464844748448484494845048451484524845348454484554845648457484584845948460484614846248463484644846548466484674846848469484704847148472484734847448475484764847748478484794848048481484824848348484484854848648487484884848948490484914849248493484944849548496484974849848499485004850148502485034850448505485064850748508485094851048511485124851348514485154851648517485184851948520485214852248523485244852548526485274852848529485304853148532485334853448535485364853748538485394854048541485424854348544485454854648547485484854948550485514855248553485544855548556485574855848559485604856148562485634856448565485664856748568485694857048571485724857348574485754857648577485784857948580485814858248583485844858548586485874858848589485904859148592485934859448595485964859748598485994860048601486024860348604486054860648607486084860948610486114861248613486144861548616486174861848619486204862148622486234862448625486264862748628486294863048631486324863348634486354863648637486384863948640486414864248643486444864548646486474864848649486504865148652486534865448655486564865748658486594866048661486624866348664486654866648667486684866948670486714867248673486744867548676486774867848679486804868148682486834868448685486864868748688486894869048691486924869348694486954869648697486984869948700487014870248703487044870548706487074870848709487104871148712487134871448715487164871748718487194872048721487224872348724487254872648727487284872948730487314873248733487344873548736487374873848739487404874148742487434874448745487464874748748487494875048751487524875348754487554875648757487584875948760487614876248763487644876548766487674876848769487704877148772487734877448775487764877748778487794878048781487824878348784487854878648787487884878948790487914879248793487944879548796487974879848799488004880148802488034880448805488064880748808488094881048811488124881348814488154881648817488184881948820488214882248823488244882548826488274882848829488304883148832488334883448835488364883748838488394884048841488424884348844488454884648847488484884948850488514885248853488544885548856488574885848859488604886148862488634886448865488664886748868488694887048871488724887348874488754887648877488784887948880488814888248883488844888548886488874888848889488904889148892488934889448895488964889748898488994890048901489024890348904489054890648907489084890948910489114891248913489144891548916489174891848919489204892148922489234892448925489264892748928489294893048931489324893348934489354893648937489384893948940489414894248943489444894548946489474894848949489504895148952489534895448955489564895748958489594896048961489624896348964489654896648967489684896948970489714897248973489744897548976489774897848979489804898148982489834898448985489864898748988489894899048991489924899348994489954899648997489984899949000490014900249003490044900549006490074900849009490104901149012490134901449015490164901749018490194902049021490224902349024490254902649027490284902949030490314903249033490344903549036490374903849039490404904149042490434904449045490464904749048490494905049051490524905349054490554905649057490584905949060490614906249063490644906549066490674906849069490704907149072490734907449075490764907749078490794908049081490824908349084490854908649087490884908949090490914909249093490944909549096490974909849099491004910149102491034910449105491064910749108491094911049111491124911349114491154911649117491184911949120491214912249123491244912549126491274912849129491304913149132491334913449135491364913749138491394914049141491424914349144491454914649147491484914949150491514915249153491544915549156491574915849159491604916149162491634916449165491664916749168491694917049171491724917349174491754917649177491784917949180491814918249183491844918549186491874918849189491904919149192491934919449195491964919749198491994920049201492024920349204492054920649207492084920949210492114921249213492144921549216492174921849219492204922149222492234922449225492264922749228492294923049231492324923349234492354923649237492384923949240492414924249243492444924549246492474924849249492504925149252492534925449255492564925749258492594926049261492624926349264492654926649267492684926949270492714927249273492744927549276492774927849279492804928149282492834928449285492864928749288492894929049291492924929349294492954929649297492984929949300493014930249303493044930549306493074930849309493104931149312493134931449315493164931749318493194932049321493224932349324493254932649327493284932949330493314933249333493344933549336493374933849339493404934149342493434934449345493464934749348493494935049351493524935349354493554935649357493584935949360493614936249363493644936549366493674936849369493704937149372493734937449375493764937749378493794938049381493824938349384493854938649387493884938949390493914939249393493944939549396493974939849399494004940149402494034940449405494064940749408494094941049411494124941349414494154941649417494184941949420494214942249423494244942549426494274942849429494304943149432494334943449435494364943749438494394944049441494424944349444494454944649447494484944949450494514945249453494544945549456494574945849459494604946149462494634946449465494664946749468494694947049471494724947349474494754947649477494784947949480494814948249483494844948549486494874948849489494904949149492494934949449495494964949749498494994950049501495024950349504495054950649507495084950949510495114951249513495144951549516495174951849519495204952149522495234952449525495264952749528495294953049531495324953349534495354953649537495384953949540495414954249543495444954549546495474954849549495504955149552495534955449555495564955749558495594956049561495624956349564495654956649567495684956949570495714957249573495744957549576495774957849579495804958149582495834958449585495864958749588495894959049591495924959349594495954959649597495984959949600496014960249603496044960549606496074960849609496104961149612496134961449615496164961749618496194962049621496224962349624496254962649627496284962949630496314963249633496344963549636496374963849639496404964149642496434964449645496464964749648496494965049651496524965349654496554965649657496584965949660496614966249663496644966549666496674966849669496704967149672496734967449675496764967749678496794968049681496824968349684496854968649687496884968949690496914969249693496944969549696496974969849699497004970149702497034970449705497064970749708497094971049711497124971349714497154971649717497184971949720497214972249723497244972549726497274972849729497304973149732497334973449735497364973749738497394974049741497424974349744497454974649747497484974949750497514975249753497544975549756497574975849759497604976149762497634976449765497664976749768497694977049771497724977349774497754977649777497784977949780497814978249783497844978549786497874978849789497904979149792497934979449795497964979749798497994980049801498024980349804498054980649807498084980949810498114981249813498144981549816498174981849819498204982149822498234982449825498264982749828498294983049831498324983349834498354983649837498384983949840498414984249843498444984549846498474984849849498504985149852498534985449855498564985749858498594986049861498624986349864498654986649867498684986949870498714987249873498744987549876498774987849879498804988149882498834988449885498864988749888498894989049891498924989349894498954989649897498984989949900499014990249903499044990549906499074990849909499104991149912499134991449915499164991749918499194992049921499224992349924499254992649927499284992949930499314993249933499344993549936499374993849939499404994149942499434994449945499464994749948499494995049951499524995349954499554995649957499584995949960499614996249963499644996549966499674996849969499704997149972499734997449975499764997749978499794998049981499824998349984499854998649987499884998949990499914999249993499944999549996499974999849999500005000150002500035000450005500065000750008500095001050011500125001350014500155001650017500185001950020500215002250023500245002550026500275002850029500305003150032500335003450035500365003750038500395004050041500425004350044500455004650047500485004950050500515005250053500545005550056500575005850059500605006150062500635006450065500665006750068500695007050071500725007350074500755007650077500785007950080500815008250083500845008550086500875008850089500905009150092500935009450095500965009750098500995010050101501025010350104501055010650107501085010950110501115011250113501145011550116501175011850119501205012150122501235012450125501265012750128501295013050131501325013350134501355013650137501385013950140501415014250143501445014550146501475014850149501505015150152501535015450155501565015750158501595016050161501625016350164501655016650167501685016950170501715017250173501745017550176501775017850179501805018150182501835018450185501865018750188501895019050191501925019350194501955019650197501985019950200502015020250203502045020550206502075020850209502105021150212502135021450215502165021750218502195022050221502225022350224502255022650227502285022950230502315023250233502345023550236502375023850239502405024150242502435024450245502465024750248502495025050251502525025350254502555025650257502585025950260502615026250263502645026550266502675026850269502705027150272502735027450275502765027750278502795028050281502825028350284502855028650287502885028950290502915029250293502945029550296502975029850299503005030150302503035030450305503065030750308503095031050311503125031350314503155031650317503185031950320503215032250323503245032550326503275032850329503305033150332503335033450335503365033750338503395034050341503425034350344503455034650347503485034950350503515035250353503545035550356503575035850359503605036150362503635036450365503665036750368503695037050371503725037350374503755037650377503785037950380503815038250383503845038550386503875038850389503905039150392503935039450395503965039750398503995040050401504025040350404504055040650407504085040950410504115041250413504145041550416504175041850419504205042150422504235042450425504265042750428504295043050431504325043350434504355043650437504385043950440504415044250443504445044550446504475044850449504505045150452504535045450455504565045750458504595046050461504625046350464504655046650467504685046950470504715047250473504745047550476504775047850479504805048150482504835048450485504865048750488504895049050491504925049350494504955049650497504985049950500505015050250503505045050550506505075050850509505105051150512505135051450515505165051750518505195052050521505225052350524505255052650527505285052950530505315053250533505345053550536505375053850539505405054150542505435054450545505465054750548505495055050551505525055350554505555055650557505585055950560505615056250563505645056550566505675056850569505705057150572505735057450575505765057750578505795058050581505825058350584505855058650587505885058950590505915059250593505945059550596505975059850599506005060150602506035060450605506065060750608506095061050611506125061350614506155061650617506185061950620506215062250623506245062550626506275062850629506305063150632506335063450635506365063750638506395064050641506425064350644506455064650647506485064950650506515065250653506545065550656506575065850659506605066150662506635066450665506665066750668506695067050671506725067350674506755067650677506785067950680506815068250683506845068550686506875068850689506905069150692506935069450695506965069750698506995070050701507025070350704507055070650707507085070950710507115071250713507145071550716507175071850719507205072150722507235072450725507265072750728507295073050731507325073350734507355073650737507385073950740507415074250743507445074550746507475074850749507505075150752507535075450755507565075750758507595076050761507625076350764507655076650767507685076950770507715077250773507745077550776507775077850779507805078150782507835078450785507865078750788507895079050791507925079350794507955079650797507985079950800508015080250803508045080550806508075080850809508105081150812508135081450815508165081750818508195082050821508225082350824508255082650827508285082950830508315083250833508345083550836508375083850839508405084150842508435084450845508465084750848508495085050851508525085350854508555085650857508585085950860508615086250863508645086550866508675086850869508705087150872508735087450875508765087750878508795088050881508825088350884508855088650887508885088950890508915089250893508945089550896508975089850899509005090150902509035090450905509065090750908509095091050911509125091350914509155091650917509185091950920509215092250923509245092550926509275092850929509305093150932509335093450935509365093750938509395094050941509425094350944509455094650947509485094950950509515095250953509545095550956509575095850959509605096150962509635096450965509665096750968509695097050971509725097350974509755097650977509785097950980509815098250983509845098550986509875098850989509905099150992509935099450995509965099750998509995100051001510025100351004510055100651007510085100951010510115101251013510145101551016510175101851019510205102151022510235102451025510265102751028510295103051031510325103351034510355103651037510385103951040510415104251043510445104551046510475104851049510505105151052510535105451055510565105751058510595106051061510625106351064510655106651067510685106951070510715107251073510745107551076510775107851079510805108151082510835108451085510865108751088510895109051091510925109351094510955109651097510985109951100511015110251103511045110551106511075110851109511105111151112511135111451115511165111751118511195112051121511225112351124511255112651127511285112951130511315113251133511345113551136511375113851139511405114151142511435114451145511465114751148511495115051151511525115351154511555115651157511585115951160511615116251163511645116551166511675116851169511705117151172511735117451175511765117751178511795118051181511825118351184511855118651187511885118951190511915119251193511945119551196511975119851199512005120151202512035120451205512065120751208512095121051211512125121351214512155121651217512185121951220512215122251223512245122551226512275122851229512305123151232512335123451235512365123751238512395124051241512425124351244512455124651247512485124951250512515125251253512545125551256512575125851259512605126151262512635126451265512665126751268512695127051271512725127351274512755127651277512785127951280512815128251283512845128551286512875128851289512905129151292512935129451295512965129751298512995130051301513025130351304513055130651307513085130951310513115131251313513145131551316513175131851319513205132151322513235132451325513265132751328513295133051331513325133351334513355133651337513385133951340513415134251343513445134551346513475134851349513505135151352513535135451355513565135751358513595136051361513625136351364513655136651367513685136951370513715137251373513745137551376513775137851379513805138151382513835138451385513865138751388513895139051391513925139351394513955139651397513985139951400514015140251403514045140551406514075140851409514105141151412514135141451415514165141751418514195142051421514225142351424514255142651427514285142951430514315143251433514345143551436514375143851439514405144151442514435144451445514465144751448514495145051451514525145351454514555145651457514585145951460514615146251463514645146551466514675146851469514705147151472514735147451475514765147751478514795148051481514825148351484514855148651487514885148951490514915149251493514945149551496514975149851499515005150151502515035150451505515065150751508515095151051511515125151351514515155151651517515185151951520515215152251523515245152551526515275152851529515305153151532515335153451535515365153751538515395154051541515425154351544515455154651547515485154951550515515155251553515545155551556515575155851559515605156151562515635156451565515665156751568515695157051571515725157351574515755157651577515785157951580515815158251583515845158551586515875158851589515905159151592515935159451595515965159751598515995160051601516025160351604516055160651607516085160951610516115161251613516145161551616516175161851619516205162151622516235162451625516265162751628516295163051631516325163351634516355163651637516385163951640516415164251643516445164551646516475164851649516505165151652516535165451655516565165751658516595166051661516625166351664516655166651667516685166951670516715167251673516745167551676516775167851679516805168151682516835168451685516865168751688516895169051691516925169351694516955169651697516985169951700517015170251703517045170551706517075170851709517105171151712517135171451715517165171751718517195172051721517225172351724517255172651727517285172951730517315173251733517345173551736517375173851739517405174151742517435174451745517465174751748517495175051751517525175351754517555175651757517585175951760517615176251763517645176551766517675176851769517705177151772517735177451775517765177751778517795178051781517825178351784517855178651787517885178951790517915179251793517945179551796517975179851799518005180151802518035180451805518065180751808518095181051811518125181351814518155181651817518185181951820518215182251823518245182551826518275182851829518305183151832518335183451835518365183751838518395184051841518425184351844518455184651847518485184951850518515185251853518545185551856518575185851859518605186151862518635186451865518665186751868518695187051871518725187351874518755187651877518785187951880518815188251883518845188551886518875188851889518905189151892518935189451895518965189751898518995190051901519025190351904519055190651907519085190951910519115191251913519145191551916519175191851919519205192151922519235192451925519265192751928519295193051931519325193351934519355193651937519385193951940519415194251943519445194551946519475194851949519505195151952519535195451955519565195751958519595196051961519625196351964519655196651967519685196951970519715197251973519745197551976519775197851979519805198151982519835198451985519865198751988519895199051991519925199351994519955199651997519985199952000520015200252003520045200552006520075200852009520105201152012520135201452015520165201752018520195202052021520225202352024520255202652027520285202952030520315203252033520345203552036520375203852039520405204152042520435204452045520465204752048520495205052051520525205352054520555205652057520585205952060520615206252063520645206552066520675206852069520705207152072520735207452075520765207752078520795208052081520825208352084520855208652087520885208952090520915209252093520945209552096520975209852099521005210152102521035210452105521065210752108521095211052111521125211352114521155211652117521185211952120521215212252123521245212552126521275212852129521305213152132521335213452135521365213752138521395214052141521425214352144521455214652147521485214952150521515215252153521545215552156521575215852159521605216152162521635216452165521665216752168521695217052171521725217352174521755217652177521785217952180521815218252183521845218552186521875218852189521905219152192521935219452195521965219752198521995220052201522025220352204522055220652207522085220952210522115221252213522145221552216522175221852219522205222152222522235222452225522265222752228522295223052231522325223352234522355223652237522385223952240522415224252243522445224552246522475224852249522505225152252522535225452255522565225752258522595226052261522625226352264522655226652267522685226952270522715227252273522745227552276522775227852279522805228152282522835228452285522865228752288522895229052291522925229352294522955229652297522985229952300523015230252303523045230552306523075230852309523105231152312523135231452315523165231752318523195232052321523225232352324523255232652327523285232952330523315233252333523345233552336523375233852339523405234152342523435234452345523465234752348523495235052351523525235352354523555235652357523585235952360523615236252363523645236552366523675236852369523705237152372523735237452375523765237752378523795238052381523825238352384523855238652387523885238952390523915239252393523945239552396523975239852399524005240152402524035240452405524065240752408524095241052411524125241352414524155241652417524185241952420524215242252423524245242552426524275242852429524305243152432524335243452435524365243752438524395244052441524425244352444524455244652447524485244952450524515245252453524545245552456524575245852459524605246152462524635246452465524665246752468524695247052471524725247352474524755247652477524785247952480524815248252483524845248552486524875248852489524905249152492524935249452495524965249752498524995250052501525025250352504525055250652507525085250952510525115251252513525145251552516525175251852519525205252152522525235252452525525265252752528525295253052531525325253352534525355253652537525385253952540525415254252543525445254552546525475254852549525505255152552525535255452555525565255752558525595256052561525625256352564525655256652567525685256952570525715257252573525745257552576525775257852579525805258152582525835258452585525865258752588525895259052591525925259352594525955259652597525985259952600526015260252603526045260552606526075260852609526105261152612526135261452615526165261752618526195262052621526225262352624526255262652627526285262952630526315263252633526345263552636526375263852639526405264152642526435264452645526465264752648526495265052651526525265352654526555265652657526585265952660526615266252663526645266552666526675266852669526705267152672526735267452675526765267752678526795268052681526825268352684526855268652687526885268952690526915269252693526945269552696526975269852699527005270152702527035270452705527065270752708527095271052711527125271352714527155271652717527185271952720527215272252723527245272552726527275272852729527305273152732527335273452735527365273752738527395274052741527425274352744527455274652747527485274952750527515275252753527545275552756527575275852759527605276152762527635276452765527665276752768527695277052771527725277352774527755277652777527785277952780527815278252783527845278552786527875278852789527905279152792527935279452795527965279752798527995280052801528025280352804528055280652807528085280952810528115281252813528145281552816528175281852819528205282152822528235282452825528265282752828528295283052831528325283352834528355283652837528385283952840528415284252843528445284552846528475284852849528505285152852528535285452855528565285752858528595286052861528625286352864528655286652867528685286952870528715287252873528745287552876528775287852879528805288152882528835288452885528865288752888528895289052891528925289352894528955289652897528985289952900529015290252903529045290552906529075290852909529105291152912529135291452915529165291752918529195292052921529225292352924529255292652927529285292952930529315293252933529345293552936529375293852939529405294152942529435294452945529465294752948529495295052951529525295352954529555295652957529585295952960529615296252963529645296552966529675296852969529705297152972529735297452975529765297752978529795298052981529825298352984529855298652987529885298952990529915299252993529945299552996529975299852999530005300153002530035300453005530065300753008530095301053011530125301353014530155301653017530185301953020530215302253023530245302553026530275302853029530305303153032530335303453035530365303753038530395304053041530425304353044530455304653047530485304953050530515305253053530545305553056530575305853059530605306153062530635306453065530665306753068530695307053071530725307353074530755307653077530785307953080530815308253083530845308553086530875308853089530905309153092530935309453095530965309753098530995310053101531025310353104531055310653107531085310953110531115311253113531145311553116531175311853119531205312153122531235312453125531265312753128531295313053131531325313353134531355313653137531385313953140531415314253143531445314553146531475314853149531505315153152531535315453155531565315753158531595316053161531625316353164531655316653167531685316953170531715317253173531745317553176531775317853179531805318153182531835318453185531865318753188531895319053191531925319353194531955319653197531985319953200532015320253203532045320553206532075320853209532105321153212532135321453215532165321753218532195322053221532225322353224532255322653227532285322953230532315323253233532345323553236532375323853239532405324153242532435324453245532465324753248532495325053251532525325353254532555325653257532585325953260532615326253263532645326553266532675326853269532705327153272532735327453275532765327753278532795328053281532825328353284532855328653287532885328953290532915329253293532945329553296532975329853299533005330153302533035330453305533065330753308533095331053311533125331353314533155331653317533185331953320533215332253323533245332553326533275332853329533305333153332533335333453335533365333753338533395334053341533425334353344533455334653347533485334953350533515335253353533545335553356533575335853359533605336153362533635336453365533665336753368533695337053371533725337353374533755337653377533785337953380533815338253383533845338553386533875338853389533905339153392533935339453395533965339753398533995340053401534025340353404534055340653407534085340953410534115341253413534145341553416534175341853419534205342153422534235342453425534265342753428534295343053431534325343353434534355343653437534385343953440534415344253443534445344553446534475344853449534505345153452534535345453455534565345753458534595346053461534625346353464534655346653467534685346953470534715347253473534745347553476534775347853479534805348153482534835348453485534865348753488534895349053491534925349353494534955349653497534985349953500535015350253503535045350553506535075350853509535105351153512535135351453515535165351753518535195352053521535225352353524535255352653527535285352953530535315353253533535345353553536535375353853539535405354153542535435354453545535465354753548535495355053551535525355353554535555355653557535585355953560535615356253563535645356553566535675356853569535705357153572535735357453575535765357753578535795358053581535825358353584535855358653587535885358953590535915359253593535945359553596535975359853599536005360153602536035360453605536065360753608536095361053611536125361353614536155361653617536185361953620536215362253623536245362553626536275362853629536305363153632536335363453635536365363753638536395364053641536425364353644536455364653647536485364953650536515365253653536545365553656536575365853659536605366153662536635366453665536665366753668536695367053671536725367353674536755367653677536785367953680536815368253683536845368553686536875368853689536905369153692536935369453695536965369753698536995370053701537025370353704537055370653707537085370953710537115371253713537145371553716537175371853719537205372153722537235372453725537265372753728537295373053731537325373353734537355373653737537385373953740537415374253743537445374553746537475374853749537505375153752537535375453755537565375753758537595376053761537625376353764537655376653767537685376953770537715377253773537745377553776537775377853779537805378153782537835378453785537865378753788537895379053791537925379353794537955379653797537985379953800538015380253803538045380553806538075380853809538105381153812538135381453815538165381753818538195382053821538225382353824538255382653827538285382953830538315383253833538345383553836538375383853839538405384153842538435384453845538465384753848538495385053851538525385353854538555385653857538585385953860538615386253863538645386553866538675386853869538705387153872538735387453875538765387753878538795388053881538825388353884538855388653887538885388953890538915389253893538945389553896538975389853899539005390153902539035390453905539065390753908539095391053911539125391353914539155391653917539185391953920539215392253923539245392553926539275392853929539305393153932539335393453935539365393753938539395394053941539425394353944539455394653947539485394953950539515395253953539545395553956539575395853959539605396153962539635396453965539665396753968539695397053971539725397353974539755397653977539785397953980539815398253983539845398553986539875398853989539905399153992539935399453995539965399753998539995400054001540025400354004540055400654007540085400954010540115401254013540145401554016540175401854019540205402154022540235402454025540265402754028540295403054031540325403354034540355403654037540385403954040540415404254043540445404554046540475404854049540505405154052540535405454055540565405754058540595406054061540625406354064540655406654067540685406954070540715407254073540745407554076540775407854079540805408154082540835408454085540865408754088540895409054091540925409354094540955409654097540985409954100541015410254103541045410554106541075410854109541105411154112541135411454115541165411754118541195412054121541225412354124541255412654127541285412954130541315413254133541345413554136541375413854139541405414154142541435414454145541465414754148541495415054151541525415354154541555415654157541585415954160541615416254163541645416554166541675416854169541705417154172541735417454175541765417754178541795418054181541825418354184541855418654187541885418954190541915419254193541945419554196541975419854199542005420154202542035420454205542065420754208542095421054211542125421354214542155421654217542185421954220542215422254223542245422554226542275422854229542305423154232542335423454235542365423754238542395424054241542425424354244542455424654247542485424954250542515425254253542545425554256542575425854259542605426154262542635426454265542665426754268542695427054271542725427354274542755427654277542785427954280542815428254283542845428554286542875428854289542905429154292542935429454295542965429754298542995430054301543025430354304543055430654307543085430954310543115431254313543145431554316543175431854319543205432154322543235432454325543265432754328543295433054331543325433354334543355433654337543385433954340543415434254343543445434554346543475434854349543505435154352543535435454355543565435754358543595436054361543625436354364543655436654367543685436954370543715437254373543745437554376543775437854379543805438154382543835438454385543865438754388543895439054391543925439354394543955439654397543985439954400544015440254403544045440554406544075440854409544105441154412544135441454415544165441754418544195442054421544225442354424544255442654427544285442954430544315443254433544345443554436544375443854439544405444154442544435444454445544465444754448544495445054451544525445354454544555445654457544585445954460544615446254463544645446554466544675446854469544705447154472544735447454475544765447754478544795448054481544825448354484544855448654487544885448954490544915449254493544945449554496544975449854499545005450154502545035450454505545065450754508545095451054511545125451354514545155451654517545185451954520545215452254523545245452554526545275452854529545305453154532545335453454535545365453754538545395454054541545425454354544545455454654547545485454954550545515455254553545545455554556545575455854559545605456154562545635456454565545665456754568545695457054571545725457354574545755457654577545785457954580545815458254583545845458554586545875458854589545905459154592545935459454595545965459754598545995460054601546025460354604546055460654607546085460954610546115461254613546145461554616546175461854619546205462154622546235462454625546265462754628546295463054631546325463354634546355463654637546385463954640546415464254643546445464554646546475464854649546505465154652546535465454655546565465754658546595466054661546625466354664546655466654667546685466954670546715467254673546745467554676546775467854679546805468154682546835468454685546865468754688546895469054691546925469354694546955469654697546985469954700547015470254703547045470554706547075470854709547105471154712547135471454715547165471754718547195472054721547225472354724547255472654727547285472954730547315473254733547345473554736547375473854739547405474154742547435474454745547465474754748547495475054751547525475354754547555475654757547585475954760547615476254763547645476554766547675476854769547705477154772547735477454775547765477754778547795478054781547825478354784547855478654787547885478954790547915479254793547945479554796547975479854799548005480154802548035480454805548065480754808548095481054811548125481354814548155481654817548185481954820548215482254823548245482554826548275482854829548305483154832548335483454835548365483754838548395484054841548425484354844548455484654847548485484954850548515485254853548545485554856548575485854859548605486154862548635486454865548665486754868548695487054871548725487354874548755487654877548785487954880548815488254883548845488554886548875488854889548905489154892548935489454895548965489754898548995490054901549025490354904549055490654907549085490954910549115491254913549145491554916549175491854919549205492154922549235492454925549265492754928549295493054931549325493354934549355493654937549385493954940549415494254943549445494554946549475494854949549505495154952549535495454955549565495754958549595496054961549625496354964549655496654967549685496954970549715497254973549745497554976549775497854979549805498154982549835498454985549865498754988549895499054991549925499354994549955499654997549985499955000550015500255003550045500555006550075500855009550105501155012550135501455015550165501755018550195502055021550225502355024550255502655027550285502955030550315503255033550345503555036550375503855039550405504155042550435504455045550465504755048550495505055051550525505355054550555505655057550585505955060550615506255063550645506555066550675506855069550705507155072550735507455075550765507755078550795508055081550825508355084550855508655087550885508955090550915509255093550945509555096550975509855099551005510155102551035510455105551065510755108551095511055111551125511355114551155511655117551185511955120551215512255123551245512555126551275512855129551305513155132551335513455135551365513755138551395514055141551425514355144551455514655147551485514955150551515515255153551545515555156551575515855159551605516155162551635516455165551665516755168551695517055171551725517355174551755517655177551785517955180551815518255183551845518555186551875518855189551905519155192551935519455195551965519755198551995520055201552025520355204552055520655207552085520955210552115521255213552145521555216552175521855219552205522155222552235522455225552265522755228552295523055231552325523355234552355523655237552385523955240552415524255243552445524555246552475524855249552505525155252552535525455255552565525755258552595526055261552625526355264552655526655267552685526955270552715527255273552745527555276552775527855279552805528155282552835528455285552865528755288552895529055291552925529355294552955529655297552985529955300553015530255303553045530555306553075530855309553105531155312553135531455315553165531755318553195532055321553225532355324553255532655327553285532955330553315533255333553345533555336553375533855339553405534155342553435534455345553465534755348553495535055351553525535355354553555535655357553585535955360553615536255363553645536555366553675536855369553705537155372553735537455375553765537755378553795538055381553825538355384553855538655387553885538955390553915539255393553945539555396553975539855399554005540155402554035540455405554065540755408554095541055411554125541355414554155541655417554185541955420554215542255423554245542555426554275542855429554305543155432554335543455435554365543755438554395544055441554425544355444554455544655447554485544955450554515545255453554545545555456554575545855459554605546155462554635546455465554665546755468554695547055471554725547355474554755547655477554785547955480554815548255483554845548555486554875548855489554905549155492554935549455495554965549755498554995550055501555025550355504555055550655507555085550955510555115551255513555145551555516555175551855519555205552155522555235552455525555265552755528555295553055531555325553355534555355553655537555385553955540555415554255543555445554555546555475554855549555505555155552555535555455555555565555755558555595556055561555625556355564555655556655567555685556955570555715557255573555745557555576555775557855579555805558155582555835558455585555865558755588555895559055591555925559355594555955559655597555985559955600556015560255603556045560555606556075560855609556105561155612556135561455615556165561755618556195562055621556225562355624556255562655627556285562955630556315563255633556345563555636556375563855639556405564155642556435564455645556465564755648556495565055651556525565355654556555565655657556585565955660556615566255663556645566555666556675566855669556705567155672556735567455675556765567755678556795568055681556825568355684556855568655687556885568955690556915569255693556945569555696556975569855699557005570155702557035570455705557065570755708557095571055711557125571355714557155571655717557185571955720557215572255723557245572555726557275572855729557305573155732557335573455735557365573755738557395574055741557425574355744557455574655747557485574955750557515575255753557545575555756557575575855759557605576155762557635576455765557665576755768557695577055771557725577355774557755577655777557785577955780557815578255783557845578555786557875578855789557905579155792557935579455795557965579755798557995580055801558025580355804558055580655807558085580955810558115581255813558145581555816558175581855819558205582155822558235582455825558265582755828558295583055831558325583355834558355583655837558385583955840558415584255843558445584555846558475584855849558505585155852558535585455855558565585755858558595586055861558625586355864558655586655867558685586955870558715587255873558745587555876558775587855879558805588155882558835588455885558865588755888558895589055891558925589355894558955589655897558985589955900559015590255903559045590555906559075590855909559105591155912559135591455915559165591755918559195592055921559225592355924559255592655927559285592955930559315593255933559345593555936559375593855939559405594155942559435594455945559465594755948559495595055951559525595355954559555595655957559585595955960559615596255963559645596555966559675596855969559705597155972559735597455975559765597755978559795598055981559825598355984559855598655987559885598955990559915599255993559945599555996559975599855999560005600156002560035600456005560065600756008560095601056011560125601356014560155601656017560185601956020560215602256023560245602556026560275602856029560305603156032560335603456035560365603756038560395604056041560425604356044560455604656047560485604956050560515605256053560545605556056560575605856059560605606156062560635606456065560665606756068560695607056071560725607356074560755607656077560785607956080560815608256083560845608556086560875608856089560905609156092560935609456095560965609756098560995610056101561025610356104561055610656107561085610956110561115611256113561145611556116561175611856119561205612156122561235612456125561265612756128561295613056131561325613356134561355613656137561385613956140561415614256143561445614556146561475614856149561505615156152561535615456155561565615756158561595616056161561625616356164561655616656167561685616956170561715617256173561745617556176561775617856179561805618156182561835618456185561865618756188561895619056191561925619356194561955619656197561985619956200562015620256203562045620556206562075620856209562105621156212562135621456215562165621756218562195622056221562225622356224562255622656227562285622956230562315623256233562345623556236562375623856239562405624156242562435624456245562465624756248562495625056251562525625356254562555625656257562585625956260562615626256263562645626556266562675626856269562705627156272562735627456275562765627756278562795628056281562825628356284562855628656287562885628956290562915629256293562945629556296562975629856299563005630156302563035630456305563065630756308563095631056311563125631356314563155631656317563185631956320563215632256323563245632556326563275632856329563305633156332563335633456335563365633756338563395634056341563425634356344563455634656347563485634956350563515635256353563545635556356563575635856359563605636156362563635636456365563665636756368563695637056371563725637356374563755637656377563785637956380563815638256383563845638556386563875638856389563905639156392563935639456395563965639756398563995640056401564025640356404564055640656407564085640956410564115641256413564145641556416564175641856419564205642156422564235642456425564265642756428564295643056431564325643356434564355643656437564385643956440564415644256443564445644556446564475644856449564505645156452564535645456455564565645756458564595646056461564625646356464564655646656467564685646956470564715647256473564745647556476564775647856479564805648156482564835648456485564865648756488564895649056491564925649356494564955649656497564985649956500565015650256503565045650556506565075650856509565105651156512565135651456515565165651756518565195652056521565225652356524565255652656527565285652956530565315653256533565345653556536565375653856539565405654156542565435654456545565465654756548565495655056551565525655356554565555655656557565585655956560565615656256563565645656556566565675656856569565705657156572565735657456575565765657756578565795658056581565825658356584565855658656587565885658956590565915659256593565945659556596565975659856599566005660156602566035660456605566065660756608566095661056611566125661356614566155661656617566185661956620566215662256623566245662556626566275662856629566305663156632566335663456635566365663756638566395664056641566425664356644566455664656647566485664956650566515665256653566545665556656566575665856659566605666156662566635666456665566665666756668566695667056671566725667356674566755667656677566785667956680566815668256683566845668556686566875668856689566905669156692566935669456695566965669756698566995670056701567025670356704567055670656707567085670956710567115671256713567145671556716567175671856719567205672156722567235672456725567265672756728567295673056731567325673356734567355673656737567385673956740567415674256743567445674556746567475674856749567505675156752567535675456755567565675756758567595676056761567625676356764567655676656767567685676956770567715677256773567745677556776567775677856779567805678156782567835678456785567865678756788567895679056791567925679356794567955679656797567985679956800568015680256803568045680556806568075680856809568105681156812568135681456815568165681756818568195682056821568225682356824568255682656827568285682956830568315683256833568345683556836568375683856839568405684156842568435684456845568465684756848568495685056851568525685356854568555685656857568585685956860568615686256863568645686556866568675686856869568705687156872568735687456875568765687756878568795688056881568825688356884568855688656887568885688956890568915689256893568945689556896568975689856899569005690156902569035690456905569065690756908569095691056911569125691356914569155691656917569185691956920569215692256923569245692556926569275692856929569305693156932569335693456935569365693756938569395694056941569425694356944569455694656947569485694956950569515695256953569545695556956569575695856959569605696156962569635696456965569665696756968569695697056971569725697356974569755697656977569785697956980569815698256983569845698556986569875698856989569905699156992569935699456995569965699756998569995700057001570025700357004570055700657007570085700957010570115701257013570145701557016570175701857019570205702157022570235702457025570265702757028570295703057031570325703357034570355703657037570385703957040570415704257043570445704557046570475704857049570505705157052570535705457055570565705757058570595706057061570625706357064570655706657067570685706957070570715707257073570745707557076570775707857079570805708157082570835708457085570865708757088570895709057091570925709357094570955709657097570985709957100571015710257103571045710557106571075710857109571105711157112571135711457115571165711757118571195712057121571225712357124571255712657127571285712957130571315713257133571345713557136571375713857139571405714157142571435714457145571465714757148571495715057151571525715357154571555715657157571585715957160571615716257163571645716557166571675716857169571705717157172571735717457175571765717757178571795718057181571825718357184571855718657187571885718957190571915719257193571945719557196571975719857199572005720157202572035720457205572065720757208572095721057211572125721357214572155721657217572185721957220572215722257223572245722557226572275722857229572305723157232572335723457235572365723757238572395724057241572425724357244572455724657247572485724957250572515725257253572545725557256572575725857259572605726157262572635726457265572665726757268572695727057271572725727357274572755727657277572785727957280572815728257283572845728557286572875728857289572905729157292572935729457295572965729757298572995730057301573025730357304573055730657307573085730957310573115731257313573145731557316573175731857319573205732157322573235732457325573265732757328573295733057331573325733357334573355733657337573385733957340573415734257343573445734557346573475734857349573505735157352573535735457355573565735757358573595736057361573625736357364573655736657367573685736957370573715737257373573745737557376573775737857379573805738157382573835738457385573865738757388573895739057391573925739357394573955739657397573985739957400574015740257403574045740557406574075740857409574105741157412574135741457415574165741757418574195742057421574225742357424574255742657427574285742957430574315743257433574345743557436574375743857439574405744157442574435744457445574465744757448574495745057451574525745357454574555745657457574585745957460574615746257463574645746557466574675746857469574705747157472574735747457475574765747757478574795748057481574825748357484574855748657487574885748957490574915749257493574945749557496574975749857499575005750157502575035750457505575065750757508575095751057511575125751357514575155751657517575185751957520575215752257523575245752557526575275752857529575305753157532575335753457535575365753757538575395754057541575425754357544575455754657547575485754957550575515755257553575545755557556575575755857559575605756157562575635756457565575665756757568575695757057571575725757357574575755757657577575785757957580575815758257583575845758557586575875758857589575905759157592575935759457595575965759757598575995760057601576025760357604576055760657607576085760957610576115761257613576145761557616576175761857619576205762157622576235762457625576265762757628576295763057631576325763357634576355763657637576385763957640576415764257643576445764557646576475764857649576505765157652576535765457655576565765757658576595766057661576625766357664576655766657667576685766957670576715767257673576745767557676576775767857679576805768157682576835768457685576865768757688576895769057691576925769357694576955769657697576985769957700577015770257703577045770557706577075770857709577105771157712577135771457715577165771757718577195772057721577225772357724577255772657727577285772957730577315773257733577345773557736577375773857739577405774157742577435774457745577465774757748577495775057751577525775357754577555775657757577585775957760577615776257763577645776557766577675776857769577705777157772577735777457775577765777757778577795778057781577825778357784577855778657787577885778957790577915779257793577945779557796577975779857799578005780157802578035780457805578065780757808578095781057811578125781357814578155781657817578185781957820578215782257823578245782557826578275782857829578305783157832578335783457835578365783757838578395784057841578425784357844578455784657847578485784957850578515785257853578545785557856578575785857859578605786157862578635786457865578665786757868578695787057871578725787357874578755787657877578785787957880578815788257883578845788557886578875788857889578905789157892578935789457895578965789757898578995790057901579025790357904579055790657907579085790957910579115791257913579145791557916579175791857919579205792157922579235792457925579265792757928579295793057931579325793357934579355793657937579385793957940579415794257943579445794557946579475794857949579505795157952579535795457955579565795757958579595796057961579625796357964579655796657967579685796957970579715797257973579745797557976579775797857979579805798157982579835798457985579865798757988579895799057991579925799357994579955799657997579985799958000580015800258003580045800558006580075800858009580105801158012580135801458015580165801758018580195802058021580225802358024580255802658027580285802958030580315803258033580345803558036580375803858039580405804158042580435804458045580465804758048580495805058051580525805358054580555805658057580585805958060580615806258063580645806558066580675806858069580705807158072580735807458075580765807758078580795808058081580825808358084580855808658087580885808958090580915809258093580945809558096580975809858099581005810158102581035810458105581065810758108581095811058111581125811358114581155811658117581185811958120581215812258123581245812558126581275812858129581305813158132581335813458135581365813758138581395814058141581425814358144581455814658147581485814958150581515815258153581545815558156581575815858159581605816158162581635816458165581665816758168581695817058171581725817358174581755817658177581785817958180581815818258183581845818558186581875818858189581905819158192581935819458195581965819758198581995820058201582025820358204582055820658207582085820958210582115821258213582145821558216582175821858219582205822158222582235822458225582265822758228582295823058231582325823358234582355823658237582385823958240582415824258243582445824558246582475824858249582505825158252582535825458255582565825758258582595826058261582625826358264582655826658267582685826958270582715827258273582745827558276582775827858279582805828158282582835828458285582865828758288582895829058291582925829358294582955829658297582985829958300583015830258303583045830558306583075830858309583105831158312583135831458315583165831758318583195832058321583225832358324583255832658327583285832958330583315833258333583345833558336583375833858339583405834158342583435834458345583465834758348583495835058351583525835358354583555835658357583585835958360583615836258363583645836558366583675836858369583705837158372583735837458375583765837758378583795838058381583825838358384583855838658387583885838958390583915839258393583945839558396583975839858399584005840158402584035840458405584065840758408584095841058411584125841358414584155841658417584185841958420584215842258423584245842558426584275842858429584305843158432584335843458435584365843758438584395844058441584425844358444584455844658447584485844958450584515845258453584545845558456584575845858459584605846158462584635846458465584665846758468584695847058471584725847358474584755847658477584785847958480584815848258483584845848558486584875848858489584905849158492584935849458495584965849758498584995850058501585025850358504585055850658507585085850958510585115851258513585145851558516585175851858519585205852158522585235852458525585265852758528585295853058531585325853358534585355853658537585385853958540585415854258543585445854558546585475854858549585505855158552585535855458555585565855758558585595856058561585625856358564585655856658567585685856958570585715857258573585745857558576585775857858579585805858158582585835858458585585865858758588585895859058591585925859358594585955859658597585985859958600586015860258603586045860558606586075860858609586105861158612586135861458615586165861758618586195862058621586225862358624586255862658627586285862958630586315863258633586345863558636586375863858639586405864158642586435864458645586465864758648586495865058651586525865358654586555865658657586585865958660586615866258663586645866558666586675866858669586705867158672586735867458675586765867758678586795868058681586825868358684586855868658687586885868958690586915869258693586945869558696586975869858699587005870158702587035870458705587065870758708587095871058711587125871358714587155871658717587185871958720587215872258723587245872558726587275872858729587305873158732587335873458735587365873758738587395874058741587425874358744587455874658747587485874958750587515875258753587545875558756587575875858759587605876158762587635876458765587665876758768587695877058771587725877358774587755877658777587785877958780587815878258783587845878558786587875878858789587905879158792587935879458795587965879758798587995880058801588025880358804588055880658807588085880958810588115881258813588145881558816588175881858819588205882158822588235882458825588265882758828588295883058831588325883358834588355883658837588385883958840588415884258843588445884558846588475884858849588505885158852588535885458855588565885758858588595886058861588625886358864588655886658867588685886958870588715887258873588745887558876588775887858879588805888158882588835888458885588865888758888588895889058891588925889358894588955889658897588985889958900589015890258903589045890558906589075890858909589105891158912589135891458915589165891758918589195892058921589225892358924589255892658927589285892958930589315893258933589345893558936589375893858939589405894158942589435894458945589465894758948589495895058951589525895358954589555895658957589585895958960589615896258963589645896558966589675896858969589705897158972589735897458975589765897758978589795898058981589825898358984589855898658987589885898958990589915899258993589945899558996589975899858999590005900159002590035900459005590065900759008590095901059011590125901359014590155901659017590185901959020590215902259023590245902559026590275902859029590305903159032590335903459035590365903759038590395904059041590425904359044590455904659047590485904959050590515905259053590545905559056590575905859059590605906159062590635906459065590665906759068590695907059071590725907359074590755907659077590785907959080590815908259083590845908559086590875908859089590905909159092590935909459095590965909759098590995910059101591025910359104591055910659107591085910959110591115911259113591145911559116591175911859119591205912159122591235912459125591265912759128591295913059131591325913359134591355913659137591385913959140591415914259143591445914559146591475914859149591505915159152591535915459155591565915759158591595916059161591625916359164591655916659167591685916959170591715917259173591745917559176591775917859179591805918159182591835918459185591865918759188591895919059191591925919359194591955919659197591985919959200592015920259203592045920559206592075920859209592105921159212592135921459215592165921759218592195922059221592225922359224592255922659227592285922959230592315923259233592345923559236592375923859239592405924159242592435924459245592465924759248592495925059251592525925359254592555925659257592585925959260592615926259263592645926559266592675926859269592705927159272592735927459275592765927759278592795928059281592825928359284592855928659287592885928959290592915929259293592945929559296592975929859299593005930159302593035930459305593065930759308593095931059311593125931359314593155931659317593185931959320593215932259323593245932559326593275932859329593305933159332593335933459335593365933759338593395934059341593425934359344593455934659347593485934959350593515935259353593545935559356593575935859359593605936159362593635936459365593665936759368593695937059371593725937359374593755937659377593785937959380593815938259383593845938559386593875938859389593905939159392593935939459395593965939759398593995940059401594025940359404594055940659407594085940959410594115941259413594145941559416594175941859419594205942159422594235942459425594265942759428594295943059431594325943359434594355943659437594385943959440594415944259443594445944559446594475944859449594505945159452594535945459455594565945759458594595946059461594625946359464594655946659467594685946959470594715947259473594745947559476594775947859479594805948159482594835948459485594865948759488594895949059491594925949359494594955949659497594985949959500595015950259503595045950559506595075950859509595105951159512595135951459515595165951759518595195952059521595225952359524595255952659527595285952959530595315953259533595345953559536595375953859539595405954159542595435954459545595465954759548595495955059551595525955359554595555955659557595585955959560595615956259563595645956559566595675956859569595705957159572595735957459575595765957759578595795958059581595825958359584595855958659587595885958959590595915959259593595945959559596595975959859599596005960159602596035960459605596065960759608596095961059611596125961359614596155961659617596185961959620596215962259623596245962559626596275962859629596305963159632596335963459635596365963759638596395964059641596425964359644596455964659647596485964959650596515965259653596545965559656596575965859659596605966159662596635966459665596665966759668596695967059671596725967359674596755967659677596785967959680596815968259683596845968559686596875968859689596905969159692596935969459695596965969759698596995970059701597025970359704597055970659707597085970959710597115971259713597145971559716597175971859719597205972159722597235972459725597265972759728597295973059731597325973359734597355973659737597385973959740597415974259743597445974559746597475974859749597505975159752597535975459755597565975759758597595976059761597625976359764597655976659767597685976959770597715977259773597745977559776597775977859779597805978159782597835978459785597865978759788597895979059791597925979359794597955979659797597985979959800598015980259803598045980559806598075980859809598105981159812598135981459815598165981759818598195982059821598225982359824598255982659827598285982959830598315983259833598345983559836598375983859839598405984159842598435984459845598465984759848598495985059851598525985359854598555985659857598585985959860598615986259863598645986559866598675986859869598705987159872598735987459875598765987759878598795988059881598825988359884598855988659887598885988959890598915989259893598945989559896598975989859899599005990159902599035990459905599065990759908599095991059911599125991359914599155991659917599185991959920599215992259923599245992559926599275992859929599305993159932599335993459935599365993759938599395994059941599425994359944599455994659947599485994959950599515995259953599545995559956599575995859959599605996159962599635996459965599665996759968599695997059971599725997359974599755997659977599785997959980599815998259983599845998559986599875998859989599905999159992599935999459995599965999759998599996000060001600026000360004600056000660007600086000960010600116001260013600146001560016600176001860019600206002160022600236002460025600266002760028600296003060031600326003360034600356003660037600386003960040600416004260043600446004560046600476004860049600506005160052600536005460055600566005760058600596006060061600626006360064600656006660067600686006960070600716007260073600746007560076600776007860079600806008160082600836008460085600866008760088600896009060091600926009360094600956009660097600986009960100601016010260103601046010560106601076010860109601106011160112601136011460115601166011760118601196012060121601226012360124601256012660127601286012960130601316013260133601346013560136601376013860139601406014160142601436014460145601466014760148601496015060151601526015360154601556015660157601586015960160601616016260163601646016560166601676016860169601706017160172601736017460175601766017760178601796018060181601826018360184601856018660187601886018960190601916019260193601946019560196601976019860199602006020160202602036020460205602066020760208602096021060211602126021360214602156021660217602186021960220602216022260223602246022560226602276022860229602306023160232602336023460235602366023760238602396024060241602426024360244602456024660247602486024960250602516025260253602546025560256602576025860259602606026160262602636026460265602666026760268602696027060271602726027360274602756027660277602786027960280602816028260283602846028560286602876028860289602906029160292602936029460295602966029760298602996030060301603026030360304603056030660307603086030960310603116031260313603146031560316603176031860319603206032160322603236032460325603266032760328603296033060331603326033360334603356033660337603386033960340603416034260343603446034560346603476034860349603506035160352603536035460355603566035760358603596036060361603626036360364603656036660367603686036960370603716037260373603746037560376603776037860379603806038160382603836038460385603866038760388603896039060391603926039360394603956039660397603986039960400604016040260403604046040560406604076040860409604106041160412604136041460415604166041760418604196042060421604226042360424604256042660427604286042960430604316043260433604346043560436604376043860439604406044160442604436044460445604466044760448604496045060451604526045360454604556045660457604586045960460604616046260463604646046560466604676046860469604706047160472604736047460475604766047760478604796048060481604826048360484604856048660487604886048960490604916049260493604946049560496604976049860499605006050160502605036050460505605066050760508605096051060511605126051360514605156051660517605186051960520605216052260523605246052560526605276052860529605306053160532605336053460535605366053760538605396054060541605426054360544605456054660547605486054960550605516055260553605546055560556605576055860559605606056160562605636056460565605666056760568605696057060571605726057360574605756057660577605786057960580605816058260583605846058560586605876058860589605906059160592605936059460595605966059760598605996060060601606026060360604606056060660607606086060960610606116061260613606146061560616606176061860619606206062160622606236062460625606266062760628606296063060631606326063360634606356063660637606386063960640606416064260643606446064560646606476064860649606506065160652606536065460655606566065760658606596066060661606626066360664606656066660667606686066960670606716067260673606746067560676606776067860679606806068160682606836068460685606866068760688606896069060691606926069360694606956069660697606986069960700607016070260703607046070560706607076070860709607106071160712607136071460715607166071760718607196072060721607226072360724607256072660727607286072960730607316073260733607346073560736607376073860739607406074160742607436074460745607466074760748607496075060751607526075360754607556075660757607586075960760607616076260763607646076560766607676076860769607706077160772607736077460775607766077760778607796078060781607826078360784607856078660787607886078960790607916079260793607946079560796607976079860799608006080160802608036080460805608066080760808608096081060811608126081360814608156081660817608186081960820608216082260823608246082560826608276082860829608306083160832608336083460835608366083760838608396084060841608426084360844608456084660847608486084960850608516085260853608546085560856608576085860859608606086160862608636086460865608666086760868608696087060871608726087360874608756087660877608786087960880608816088260883608846088560886608876088860889608906089160892608936089460895608966089760898608996090060901609026090360904609056090660907609086090960910609116091260913609146091560916609176091860919609206092160922609236092460925609266092760928609296093060931609326093360934609356093660937609386093960940609416094260943609446094560946609476094860949609506095160952609536095460955609566095760958609596096060961609626096360964609656096660967609686096960970609716097260973609746097560976609776097860979609806098160982609836098460985609866098760988609896099060991609926099360994609956099660997609986099961000610016100261003610046100561006610076100861009610106101161012610136101461015610166101761018610196102061021610226102361024610256102661027610286102961030610316103261033610346103561036610376103861039610406104161042610436104461045610466104761048610496105061051610526105361054610556105661057610586105961060610616106261063610646106561066610676106861069610706107161072610736107461075610766107761078610796108061081610826108361084610856108661087610886108961090610916109261093610946109561096610976109861099611006110161102611036110461105611066110761108611096111061111611126111361114611156111661117611186111961120611216112261123611246112561126611276112861129611306113161132611336113461135611366113761138611396114061141611426114361144611456114661147611486114961150611516115261153611546115561156611576115861159611606116161162611636116461165611666116761168611696117061171611726117361174611756117661177611786117961180611816118261183611846118561186611876118861189611906119161192611936119461195611966119761198611996120061201612026120361204612056120661207612086120961210612116121261213612146121561216612176121861219612206122161222612236122461225612266122761228612296123061231612326123361234612356123661237612386123961240612416124261243612446124561246612476124861249612506125161252612536125461255612566125761258612596126061261612626126361264612656126661267612686126961270612716127261273612746127561276612776127861279612806128161282612836128461285612866128761288612896129061291612926129361294612956129661297612986129961300613016130261303613046130561306613076130861309613106131161312613136131461315613166131761318613196132061321613226132361324613256132661327613286132961330613316133261333613346133561336613376133861339613406134161342613436134461345613466134761348613496135061351613526135361354613556135661357613586135961360613616136261363613646136561366613676136861369613706137161372613736137461375613766137761378613796138061381613826138361384613856138661387613886138961390613916139261393613946139561396613976139861399614006140161402614036140461405614066140761408614096141061411614126141361414614156141661417614186141961420614216142261423614246142561426614276142861429614306143161432614336143461435614366143761438614396144061441614426144361444614456144661447614486144961450614516145261453614546145561456614576145861459614606146161462614636146461465614666146761468614696147061471614726147361474614756147661477614786147961480614816148261483614846148561486614876148861489614906149161492614936149461495614966149761498614996150061501615026150361504615056150661507615086150961510615116151261513615146151561516615176151861519615206152161522615236152461525615266152761528615296153061531615326153361534615356153661537615386153961540615416154261543615446154561546615476154861549615506155161552615536155461555615566155761558615596156061561615626156361564615656156661567615686156961570615716157261573615746157561576615776157861579615806158161582615836158461585615866158761588615896159061591615926159361594615956159661597615986159961600616016160261603616046160561606616076160861609616106161161612616136161461615616166161761618616196162061621616226162361624616256162661627616286162961630616316163261633616346163561636616376163861639616406164161642616436164461645616466164761648616496165061651616526165361654616556165661657616586165961660616616166261663616646166561666616676166861669616706167161672616736167461675616766167761678616796168061681616826168361684616856168661687616886168961690616916169261693616946169561696616976169861699617006170161702617036170461705617066170761708617096171061711617126171361714617156171661717617186171961720617216172261723617246172561726617276172861729617306173161732617336173461735617366173761738617396174061741617426174361744617456174661747617486174961750617516175261753617546175561756617576175861759617606176161762617636176461765617666176761768617696177061771617726177361774617756177661777617786177961780617816178261783617846178561786617876178861789617906179161792617936179461795617966179761798617996180061801618026180361804618056180661807618086180961810618116181261813618146181561816618176181861819618206182161822618236182461825618266182761828618296183061831618326183361834618356183661837618386183961840618416184261843618446184561846618476184861849618506185161852618536185461855618566185761858618596186061861618626186361864618656186661867618686186961870618716187261873618746187561876618776187861879618806188161882618836188461885618866188761888618896189061891618926189361894618956189661897618986189961900619016190261903619046190561906619076190861909619106191161912619136191461915619166191761918619196192061921619226192361924619256192661927619286192961930619316193261933619346193561936619376193861939619406194161942619436194461945619466194761948619496195061951619526195361954619556195661957619586195961960619616196261963619646196561966619676196861969619706197161972619736197461975619766197761978619796198061981619826198361984619856198661987619886198961990619916199261993619946199561996619976199861999620006200162002620036200462005620066200762008620096201062011620126201362014620156201662017620186201962020620216202262023620246202562026620276202862029620306203162032620336203462035620366203762038620396204062041620426204362044620456204662047620486204962050620516205262053620546205562056620576205862059620606206162062620636206462065620666206762068620696207062071620726207362074620756207662077620786207962080620816208262083620846208562086620876208862089620906209162092620936209462095620966209762098620996210062101621026210362104621056210662107621086210962110621116211262113621146211562116621176211862119621206212162122621236212462125621266212762128621296213062131621326213362134621356213662137621386213962140621416214262143621446214562146621476214862149621506215162152621536215462155621566215762158621596216062161621626216362164621656216662167621686216962170621716217262173621746217562176621776217862179621806218162182621836218462185621866218762188621896219062191621926219362194621956219662197621986219962200622016220262203622046220562206622076220862209622106221162212622136221462215622166221762218622196222062221622226222362224622256222662227622286222962230622316223262233622346223562236622376223862239622406224162242622436224462245622466224762248622496225062251622526225362254622556225662257622586225962260622616226262263622646226562266622676226862269622706227162272622736227462275622766227762278622796228062281622826228362284622856228662287622886228962290622916229262293622946229562296622976229862299623006230162302623036230462305623066230762308623096231062311623126231362314623156231662317623186231962320623216232262323623246232562326623276232862329623306233162332623336233462335623366233762338623396234062341623426234362344623456234662347623486234962350623516235262353623546235562356623576235862359623606236162362623636236462365623666236762368623696237062371623726237362374623756237662377623786237962380623816238262383623846238562386623876238862389623906239162392623936239462395623966239762398623996240062401624026240362404624056240662407624086240962410624116241262413624146241562416624176241862419624206242162422624236242462425624266242762428624296243062431624326243362434624356243662437624386243962440624416244262443624446244562446624476244862449624506245162452624536245462455624566245762458624596246062461624626246362464624656246662467624686246962470624716247262473624746247562476624776247862479624806248162482624836248462485624866248762488624896249062491624926249362494624956249662497624986249962500625016250262503625046250562506625076250862509625106251162512625136251462515625166251762518625196252062521625226252362524625256252662527625286252962530625316253262533625346253562536625376253862539625406254162542625436254462545625466254762548625496255062551625526255362554625556255662557625586255962560625616256262563625646256562566625676256862569625706257162572625736257462575625766257762578625796258062581625826258362584625856258662587625886258962590625916259262593625946259562596625976259862599626006260162602626036260462605626066260762608626096261062611626126261362614626156261662617626186261962620626216262262623626246262562626626276262862629626306263162632626336263462635626366263762638626396264062641626426264362644626456264662647626486264962650626516265262653626546265562656626576265862659626606266162662626636266462665626666266762668626696267062671626726267362674626756267662677626786267962680626816268262683626846268562686626876268862689626906269162692626936269462695626966269762698626996270062701627026270362704627056270662707627086270962710627116271262713627146271562716627176271862719627206272162722627236272462725627266272762728627296273062731627326273362734627356273662737627386273962740627416274262743627446274562746627476274862749627506275162752627536275462755627566275762758627596276062761627626276362764627656276662767627686276962770627716277262773627746277562776627776277862779627806278162782627836278462785627866278762788627896279062791627926279362794627956279662797627986279962800628016280262803628046280562806628076280862809628106281162812628136281462815628166281762818628196282062821628226282362824628256282662827628286282962830628316283262833628346283562836628376283862839628406284162842628436284462845628466284762848628496285062851628526285362854628556285662857628586285962860628616286262863628646286562866628676286862869628706287162872628736287462875628766287762878628796288062881628826288362884628856288662887628886288962890628916289262893628946289562896628976289862899629006290162902629036290462905629066290762908629096291062911629126291362914629156291662917629186291962920629216292262923629246292562926629276292862929629306293162932629336293462935629366293762938629396294062941629426294362944629456294662947629486294962950629516295262953629546295562956629576295862959629606296162962629636296462965629666296762968629696297062971629726297362974629756297662977629786297962980629816298262983629846298562986629876298862989629906299162992629936299462995629966299762998629996300063001630026300363004630056300663007630086300963010630116301263013630146301563016630176301863019630206302163022630236302463025630266302763028630296303063031630326303363034630356303663037630386303963040630416304263043630446304563046630476304863049630506305163052630536305463055630566305763058630596306063061630626306363064630656306663067630686306963070630716307263073630746307563076630776307863079630806308163082630836308463085630866308763088630896309063091630926309363094630956309663097630986309963100631016310263103631046310563106631076310863109631106311163112631136311463115631166311763118631196312063121631226312363124631256312663127631286312963130631316313263133631346313563136631376313863139631406314163142631436314463145631466314763148631496315063151631526315363154631556315663157631586315963160631616316263163631646316563166631676316863169631706317163172631736317463175631766317763178631796318063181631826318363184631856318663187631886318963190631916319263193631946319563196631976319863199632006320163202632036320463205632066320763208632096321063211632126321363214632156321663217632186321963220632216322263223632246322563226632276322863229632306323163232632336323463235632366323763238632396324063241632426324363244632456324663247632486324963250632516325263253632546325563256632576325863259632606326163262632636326463265632666326763268632696327063271632726327363274632756327663277632786327963280632816328263283632846328563286632876328863289632906329163292632936329463295632966329763298632996330063301633026330363304633056330663307633086330963310633116331263313633146331563316633176331863319633206332163322633236332463325633266332763328633296333063331633326333363334633356333663337633386333963340633416334263343633446334563346633476334863349633506335163352633536335463355633566335763358633596336063361633626336363364633656336663367633686336963370633716337263373633746337563376633776337863379633806338163382633836338463385633866338763388633896339063391633926339363394633956339663397633986339963400634016340263403634046340563406634076340863409634106341163412634136341463415634166341763418634196342063421634226342363424634256342663427634286342963430634316343263433634346343563436634376343863439634406344163442634436344463445634466344763448634496345063451634526345363454634556345663457634586345963460634616346263463634646346563466634676346863469634706347163472634736347463475634766347763478634796348063481634826348363484634856348663487634886348963490634916349263493634946349563496634976349863499635006350163502635036350463505635066350763508635096351063511635126351363514635156351663517635186351963520635216352263523635246352563526635276352863529635306353163532635336353463535635366353763538635396354063541635426354363544635456354663547635486354963550635516355263553635546355563556635576355863559635606356163562635636356463565635666356763568635696357063571635726357363574635756357663577635786357963580635816358263583635846358563586635876358863589635906359163592635936359463595635966359763598635996360063601636026360363604636056360663607636086360963610636116361263613636146361563616636176361863619636206362163622636236362463625636266362763628636296363063631636326363363634636356363663637636386363963640636416364263643636446364563646636476364863649636506365163652636536365463655636566365763658636596366063661636626366363664636656366663667636686366963670636716367263673636746367563676636776367863679636806368163682636836368463685636866368763688636896369063691636926369363694636956369663697636986369963700637016370263703637046370563706637076370863709637106371163712637136371463715637166371763718637196372063721637226372363724637256372663727637286372963730637316373263733637346373563736637376373863739637406374163742637436374463745637466374763748637496375063751637526375363754637556375663757637586375963760637616376263763637646376563766637676376863769637706377163772637736377463775637766377763778637796378063781637826378363784637856378663787637886378963790637916379263793637946379563796637976379863799638006380163802638036380463805638066380763808638096381063811638126381363814638156381663817638186381963820638216382263823638246382563826638276382863829638306383163832638336383463835638366383763838638396384063841638426384363844638456384663847638486384963850638516385263853638546385563856638576385863859638606386163862638636386463865638666386763868638696387063871638726387363874638756387663877638786387963880638816388263883638846388563886638876388863889638906389163892638936389463895638966389763898638996390063901639026390363904639056390663907639086390963910639116391263913639146391563916639176391863919639206392163922639236392463925639266392763928639296393063931639326393363934639356393663937639386393963940639416394263943639446394563946639476394863949639506395163952639536395463955639566395763958639596396063961639626396363964639656396663967639686396963970639716397263973639746397563976639776397863979639806398163982639836398463985639866398763988639896399063991639926399363994639956399663997639986399964000640016400264003640046400564006640076400864009640106401164012640136401464015640166401764018640196402064021640226402364024640256402664027640286402964030640316403264033640346403564036640376403864039640406404164042640436404464045640466404764048640496405064051640526405364054640556405664057640586405964060640616406264063640646406564066640676406864069640706407164072640736407464075640766407764078640796408064081640826408364084640856408664087640886408964090640916409264093640946409564096640976409864099641006410164102641036410464105641066410764108641096411064111641126411364114641156411664117641186411964120641216412264123641246412564126641276412864129641306413164132641336413464135641366413764138641396414064141641426414364144641456414664147641486414964150641516415264153641546415564156641576415864159641606416164162641636416464165641666416764168641696417064171641726417364174641756417664177641786417964180641816418264183641846418564186641876418864189641906419164192641936419464195641966419764198641996420064201642026420364204642056420664207642086420964210642116421264213642146421564216642176421864219642206422164222642236422464225642266422764228642296423064231642326423364234642356423664237642386423964240642416424264243642446424564246642476424864249642506425164252642536425464255642566425764258642596426064261642626426364264642656426664267642686426964270642716427264273642746427564276642776427864279642806428164282642836428464285642866428764288642896429064291642926429364294642956429664297642986429964300643016430264303643046430564306643076430864309643106431164312643136431464315643166431764318643196432064321643226432364324643256432664327643286432964330643316433264333643346433564336643376433864339643406434164342643436434464345643466434764348643496435064351643526435364354643556435664357643586435964360643616436264363643646436564366643676436864369643706437164372643736437464375643766437764378643796438064381643826438364384643856438664387643886438964390643916439264393643946439564396643976439864399644006440164402644036440464405644066440764408644096441064411644126441364414644156441664417644186441964420644216442264423644246442564426644276442864429644306443164432644336443464435644366443764438644396444064441644426444364444644456444664447644486444964450644516445264453644546445564456644576445864459644606446164462644636446464465644666446764468644696447064471644726447364474644756447664477644786447964480644816448264483644846448564486644876448864489644906449164492644936449464495644966449764498644996450064501645026450364504645056450664507645086450964510645116451264513645146451564516645176451864519645206452164522645236452464525645266452764528645296453064531645326453364534645356453664537645386453964540645416454264543645446454564546645476454864549645506455164552645536455464555645566455764558645596456064561645626456364564645656456664567645686456964570645716457264573645746457564576645776457864579645806458164582645836458464585645866458764588645896459064591645926459364594645956459664597645986459964600646016460264603646046460564606646076460864609646106461164612646136461464615646166461764618646196462064621646226462364624646256462664627646286462964630646316463264633646346463564636646376463864639646406464164642646436464464645646466464764648646496465064651646526465364654646556465664657646586465964660646616466264663646646466564666646676466864669646706467164672646736467464675646766467764678646796468064681646826468364684646856468664687646886468964690646916469264693646946469564696646976469864699647006470164702647036470464705647066470764708647096471064711647126471364714647156471664717647186471964720647216472264723647246472564726647276472864729647306473164732647336473464735647366473764738647396474064741647426474364744647456474664747647486474964750647516475264753647546475564756647576475864759647606476164762647636476464765647666476764768647696477064771647726477364774647756477664777647786477964780647816478264783647846478564786647876478864789647906479164792647936479464795647966479764798647996480064801648026480364804648056480664807648086480964810648116481264813648146481564816648176481864819648206482164822648236482464825648266482764828648296483064831648326483364834648356483664837648386483964840648416484264843648446484564846648476484864849648506485164852648536485464855648566485764858648596486064861648626486364864648656486664867648686486964870648716487264873648746487564876648776487864879648806488164882648836488464885648866488764888648896489064891648926489364894648956489664897648986489964900649016490264903649046490564906649076490864909649106491164912649136491464915649166491764918649196492064921649226492364924649256492664927649286492964930649316493264933649346493564936649376493864939649406494164942649436494464945649466494764948649496495064951649526495364954649556495664957649586495964960649616496264963649646496564966649676496864969649706497164972649736497464975649766497764978649796498064981649826498364984649856498664987649886498964990649916499264993649946499564996649976499864999650006500165002650036500465005650066500765008650096501065011650126501365014650156501665017650186501965020650216502265023650246502565026650276502865029650306503165032650336503465035650366503765038650396504065041650426504365044650456504665047650486504965050650516505265053650546505565056650576505865059650606506165062650636506465065650666506765068650696507065071650726507365074650756507665077650786507965080650816508265083650846508565086650876508865089650906509165092650936509465095650966509765098650996510065101651026510365104651056510665107651086510965110651116511265113651146511565116651176511865119651206512165122651236512465125651266512765128651296513065131651326513365134651356513665137651386513965140651416514265143651446514565146651476514865149651506515165152651536515465155651566515765158651596516065161651626516365164651656516665167651686516965170651716517265173651746517565176651776517865179651806518165182651836518465185651866518765188651896519065191651926519365194651956519665197651986519965200652016520265203652046520565206652076520865209652106521165212652136521465215652166521765218652196522065221652226522365224652256522665227652286522965230652316523265233652346523565236652376523865239652406524165242652436524465245652466524765248652496525065251652526525365254652556525665257652586525965260652616526265263652646526565266652676526865269652706527165272652736527465275652766527765278652796528065281652826528365284652856528665287652886528965290652916529265293652946529565296652976529865299653006530165302653036530465305653066530765308653096531065311653126531365314653156531665317653186531965320653216532265323653246532565326653276532865329653306533165332653336533465335653366533765338653396534065341653426534365344653456534665347653486534965350653516535265353653546535565356653576535865359653606536165362653636536465365653666536765368653696537065371653726537365374653756537665377653786537965380653816538265383653846538565386653876538865389653906539165392653936539465395653966539765398653996540065401654026540365404654056540665407654086540965410654116541265413654146541565416654176541865419654206542165422654236542465425654266542765428654296543065431654326543365434654356543665437654386543965440654416544265443654446544565446654476544865449654506545165452654536545465455654566545765458654596546065461654626546365464654656546665467654686546965470654716547265473654746547565476654776547865479654806548165482654836548465485654866548765488654896549065491654926549365494654956549665497654986549965500655016550265503655046550565506655076550865509655106551165512655136551465515655166551765518655196552065521655226552365524655256552665527655286552965530655316553265533655346553565536655376553865539655406554165542655436554465545655466554765548655496555065551655526555365554655556555665557655586555965560655616556265563655646556565566655676556865569655706557165572655736557465575655766557765578655796558065581655826558365584655856558665587655886558965590655916559265593655946559565596655976559865599656006560165602656036560465605656066560765608656096561065611656126561365614656156561665617656186561965620656216562265623656246562565626656276562865629656306563165632656336563465635656366563765638656396564065641656426564365644656456564665647656486564965650656516565265653656546565565656656576565865659656606566165662656636566465665656666566765668656696567065671656726567365674656756567665677656786567965680656816568265683656846568565686656876568865689656906569165692656936569465695656966569765698656996570065701657026570365704657056570665707657086570965710657116571265713657146571565716657176571865719657206572165722657236572465725657266572765728657296573065731657326573365734657356573665737657386573965740657416574265743657446574565746657476574865749657506575165752657536575465755657566575765758657596576065761657626576365764657656576665767657686576965770657716577265773657746577565776657776577865779657806578165782657836578465785657866578765788657896579065791657926579365794657956579665797657986579965800658016580265803658046580565806658076580865809658106581165812658136581465815658166581765818658196582065821658226582365824658256582665827658286582965830658316583265833658346583565836658376583865839658406584165842658436584465845658466584765848658496585065851658526585365854658556585665857658586585965860658616586265863658646586565866658676586865869658706587165872658736587465875658766587765878658796588065881658826588365884658856588665887658886588965890658916589265893658946589565896658976589865899659006590165902659036590465905659066590765908659096591065911659126591365914659156591665917659186591965920659216592265923659246592565926659276592865929659306593165932659336593465935659366593765938659396594065941659426594365944659456594665947659486594965950659516595265953659546595565956659576595865959659606596165962659636596465965659666596765968659696597065971659726597365974659756597665977659786597965980659816598265983659846598565986659876598865989659906599165992659936599465995659966599765998659996600066001660026600366004660056600666007660086600966010660116601266013660146601566016660176601866019660206602166022660236602466025660266602766028660296603066031660326603366034660356603666037660386603966040660416604266043660446604566046660476604866049660506605166052660536605466055660566605766058660596606066061660626606366064660656606666067660686606966070660716607266073660746607566076660776607866079660806608166082660836608466085660866608766088660896609066091660926609366094660956609666097660986609966100661016610266103661046610566106661076610866109661106611166112661136611466115661166611766118661196612066121661226612366124661256612666127661286612966130661316613266133661346613566136661376613866139661406614166142661436614466145661466614766148661496615066151661526615366154661556615666157661586615966160661616616266163661646616566166661676616866169661706617166172661736617466175661766617766178661796618066181661826618366184661856618666187661886618966190661916619266193661946619566196661976619866199662006620166202662036620466205662066620766208662096621066211662126621366214662156621666217662186621966220662216622266223662246622566226662276622866229662306623166232662336623466235662366623766238662396624066241662426624366244662456624666247662486624966250662516625266253662546625566256662576625866259662606626166262662636626466265662666626766268662696627066271662726627366274662756627666277662786627966280662816628266283662846628566286662876628866289662906629166292662936629466295662966629766298662996630066301663026630366304663056630666307663086630966310663116631266313663146631566316663176631866319663206632166322663236632466325663266632766328663296633066331663326633366334663356633666337663386633966340663416634266343663446634566346663476634866349663506635166352663536635466355663566635766358663596636066361663626636366364663656636666367663686636966370663716637266373663746637566376663776637866379663806638166382663836638466385663866638766388663896639066391663926639366394663956639666397663986639966400664016640266403664046640566406664076640866409664106641166412664136641466415664166641766418664196642066421664226642366424664256642666427664286642966430664316643266433664346643566436664376643866439664406644166442664436644466445664466644766448664496645066451664526645366454664556645666457664586645966460664616646266463664646646566466664676646866469664706647166472664736647466475664766647766478664796648066481664826648366484664856648666487664886648966490664916649266493664946649566496664976649866499665006650166502665036650466505665066650766508665096651066511665126651366514665156651666517665186651966520665216652266523665246652566526665276652866529665306653166532665336653466535665366653766538665396654066541665426654366544665456654666547665486654966550665516655266553665546655566556665576655866559665606656166562665636656466565665666656766568665696657066571665726657366574665756657666577665786657966580665816658266583665846658566586665876658866589665906659166592665936659466595665966659766598665996660066601666026660366604666056660666607666086660966610666116661266613666146661566616666176661866619666206662166622666236662466625666266662766628666296663066631666326663366634666356663666637666386663966640666416664266643666446664566646666476664866649666506665166652666536665466655666566665766658666596666066661666626666366664666656666666667666686666966670666716667266673666746667566676666776667866679666806668166682666836668466685666866668766688666896669066691666926669366694666956669666697666986669966700667016670266703667046670566706667076670866709667106671166712667136671466715667166671766718667196672066721667226672366724667256672666727667286672966730667316673266733667346673566736667376673866739667406674166742667436674466745667466674766748667496675066751667526675366754667556675666757667586675966760667616676266763667646676566766667676676866769667706677166772667736677466775667766677766778667796678066781667826678366784667856678666787667886678966790667916679266793667946679566796667976679866799668006680166802668036680466805668066680766808668096681066811668126681366814668156681666817668186681966820668216682266823668246682566826668276682866829668306683166832668336683466835668366683766838668396684066841668426684366844668456684666847668486684966850668516685266853668546685566856668576685866859668606686166862668636686466865668666686766868668696687066871668726687366874668756687666877668786687966880668816688266883668846688566886668876688866889668906689166892668936689466895668966689766898668996690066901669026690366904669056690666907669086690966910669116691266913669146691566916669176691866919669206692166922669236692466925669266692766928669296693066931669326693366934669356693666937669386693966940669416694266943669446694566946669476694866949669506695166952669536695466955669566695766958669596696066961669626696366964669656696666967669686696966970669716697266973669746697566976669776697866979669806698166982669836698466985669866698766988669896699066991669926699366994669956699666997669986699967000670016700267003670046700567006670076700867009670106701167012670136701467015670166701767018670196702067021670226702367024670256702667027670286702967030670316703267033670346703567036670376703867039670406704167042670436704467045670466704767048670496705067051670526705367054670556705667057670586705967060670616706267063670646706567066670676706867069670706707167072670736707467075670766707767078670796708067081670826708367084670856708667087670886708967090670916709267093670946709567096670976709867099671006710167102671036710467105671066710767108671096711067111671126711367114671156711667117671186711967120671216712267123671246712567126671276712867129671306713167132671336713467135671366713767138671396714067141671426714367144671456714667147671486714967150671516715267153671546715567156671576715867159671606716167162671636716467165671666716767168671696717067171671726717367174671756717667177671786717967180671816718267183671846718567186671876718867189671906719167192671936719467195671966719767198671996720067201672026720367204672056720667207672086720967210672116721267213672146721567216672176721867219672206722167222672236722467225672266722767228672296723067231672326723367234672356723667237672386723967240672416724267243672446724567246672476724867249672506725167252672536725467255672566725767258672596726067261672626726367264672656726667267672686726967270672716727267273672746727567276672776727867279672806728167282672836728467285672866728767288672896729067291672926729367294672956729667297672986729967300673016730267303673046730567306673076730867309673106731167312673136731467315673166731767318673196732067321673226732367324673256732667327673286732967330673316733267333673346733567336673376733867339673406734167342673436734467345673466734767348673496735067351673526735367354673556735667357673586735967360673616736267363673646736567366673676736867369673706737167372673736737467375673766737767378673796738067381673826738367384673856738667387673886738967390673916739267393673946739567396673976739867399674006740167402674036740467405674066740767408674096741067411674126741367414674156741667417674186741967420674216742267423674246742567426674276742867429674306743167432674336743467435674366743767438674396744067441674426744367444674456744667447674486744967450674516745267453674546745567456674576745867459674606746167462674636746467465674666746767468674696747067471674726747367474674756747667477674786747967480674816748267483674846748567486674876748867489674906749167492674936749467495674966749767498674996750067501675026750367504675056750667507675086750967510675116751267513675146751567516675176751867519675206752167522675236752467525675266752767528675296753067531675326753367534675356753667537675386753967540675416754267543675446754567546675476754867549675506755167552675536755467555675566755767558675596756067561675626756367564675656756667567675686756967570675716757267573675746757567576675776757867579675806758167582675836758467585675866758767588675896759067591675926759367594675956759667597675986759967600676016760267603676046760567606676076760867609676106761167612676136761467615676166761767618676196762067621676226762367624676256762667627676286762967630676316763267633676346763567636676376763867639676406764167642676436764467645676466764767648676496765067651676526765367654676556765667657676586765967660676616766267663676646766567666676676766867669676706767167672676736767467675676766767767678676796768067681676826768367684676856768667687676886768967690676916769267693676946769567696676976769867699677006770167702677036770467705677066770767708677096771067711677126771367714677156771667717677186771967720677216772267723677246772567726677276772867729677306773167732677336773467735677366773767738677396774067741677426774367744677456774667747677486774967750677516775267753677546775567756677576775867759677606776167762677636776467765677666776767768677696777067771677726777367774677756777667777677786777967780677816778267783677846778567786677876778867789677906779167792677936779467795677966779767798677996780067801678026780367804678056780667807678086780967810678116781267813678146781567816678176781867819678206782167822678236782467825678266782767828678296783067831678326783367834678356783667837678386783967840678416784267843678446784567846678476784867849678506785167852678536785467855678566785767858678596786067861678626786367864678656786667867678686786967870678716787267873678746787567876678776787867879678806788167882678836788467885678866788767888678896789067891678926789367894678956789667897678986789967900679016790267903679046790567906679076790867909679106791167912679136791467915679166791767918679196792067921679226792367924679256792667927679286792967930679316793267933679346793567936679376793867939679406794167942679436794467945679466794767948679496795067951679526795367954679556795667957679586795967960679616796267963679646796567966679676796867969679706797167972679736797467975679766797767978679796798067981679826798367984679856798667987679886798967990679916799267993679946799567996679976799867999680006800168002680036800468005680066800768008680096801068011680126801368014680156801668017680186801968020680216802268023680246802568026680276802868029680306803168032680336803468035680366803768038680396804068041680426804368044680456804668047680486804968050680516805268053680546805568056680576805868059680606806168062680636806468065680666806768068680696807068071680726807368074680756807668077680786807968080680816808268083680846808568086680876808868089680906809168092680936809468095680966809768098680996810068101681026810368104681056810668107681086810968110681116811268113681146811568116681176811868119681206812168122681236812468125681266812768128681296813068131681326813368134681356813668137681386813968140681416814268143681446814568146681476814868149681506815168152681536815468155681566815768158681596816068161681626816368164681656816668167681686816968170681716817268173681746817568176681776817868179681806818168182681836818468185681866818768188681896819068191681926819368194681956819668197681986819968200682016820268203682046820568206682076820868209682106821168212682136821468215682166821768218682196822068221682226822368224682256822668227682286822968230682316823268233682346823568236682376823868239682406824168242682436824468245682466824768248682496825068251682526825368254682556825668257682586825968260682616826268263682646826568266682676826868269682706827168272682736827468275682766827768278682796828068281682826828368284682856828668287682886828968290682916829268293682946829568296682976829868299683006830168302683036830468305683066830768308683096831068311683126831368314683156831668317683186831968320683216832268323683246832568326683276832868329683306833168332683336833468335683366833768338683396834068341683426834368344683456834668347683486834968350683516835268353683546835568356683576835868359683606836168362683636836468365683666836768368683696837068371683726837368374683756837668377683786837968380683816838268383683846838568386683876838868389683906839168392683936839468395683966839768398683996840068401684026840368404684056840668407684086840968410684116841268413684146841568416684176841868419684206842168422684236842468425684266842768428684296843068431684326843368434684356843668437684386843968440684416844268443684446844568446684476844868449684506845168452684536845468455684566845768458684596846068461684626846368464684656846668467684686846968470684716847268473684746847568476684776847868479684806848168482684836848468485684866848768488684896849068491684926849368494684956849668497684986849968500685016850268503685046850568506685076850868509685106851168512685136851468515685166851768518685196852068521685226852368524685256852668527685286852968530685316853268533685346853568536685376853868539685406854168542685436854468545685466854768548685496855068551685526855368554685556855668557685586855968560685616856268563685646856568566685676856868569685706857168572685736857468575685766857768578685796858068581685826858368584685856858668587685886858968590685916859268593685946859568596685976859868599686006860168602686036860468605686066860768608686096861068611686126861368614686156861668617686186861968620686216862268623686246862568626686276862868629686306863168632686336863468635686366863768638686396864068641686426864368644686456864668647686486864968650686516865268653686546865568656686576865868659686606866168662686636866468665686666866768668686696867068671686726867368674686756867668677686786867968680686816868268683686846868568686686876868868689686906869168692686936869468695686966869768698686996870068701687026870368704687056870668707687086870968710687116871268713687146871568716687176871868719687206872168722687236872468725687266872768728687296873068731687326873368734687356873668737687386873968740687416874268743687446874568746687476874868749687506875168752687536875468755687566875768758687596876068761687626876368764687656876668767687686876968770687716877268773687746877568776687776877868779687806878168782687836878468785687866878768788687896879068791687926879368794687956879668797687986879968800688016880268803688046880568806688076880868809688106881168812688136881468815688166881768818688196882068821688226882368824688256882668827688286882968830688316883268833688346883568836688376883868839688406884168842688436884468845688466884768848688496885068851688526885368854688556885668857688586885968860688616886268863688646886568866688676886868869688706887168872688736887468875688766887768878688796888068881688826888368884688856888668887688886888968890688916889268893688946889568896688976889868899689006890168902689036890468905689066890768908689096891068911689126891368914689156891668917689186891968920689216892268923689246892568926689276892868929689306893168932689336893468935689366893768938689396894068941689426894368944689456894668947689486894968950689516895268953689546895568956689576895868959689606896168962689636896468965689666896768968689696897068971689726897368974689756897668977689786897968980689816898268983689846898568986689876898868989689906899168992689936899468995689966899768998689996900069001690026900369004690056900669007690086900969010690116901269013690146901569016690176901869019690206902169022690236902469025690266902769028690296903069031690326903369034690356903669037690386903969040690416904269043690446904569046690476904869049690506905169052690536905469055690566905769058690596906069061690626906369064690656906669067690686906969070690716907269073690746907569076690776907869079690806908169082690836908469085690866908769088690896909069091690926909369094690956909669097690986909969100691016910269103691046910569106691076910869109691106911169112691136911469115691166911769118691196912069121691226912369124691256912669127691286912969130691316913269133691346913569136691376913869139691406914169142691436914469145691466914769148691496915069151691526915369154691556915669157691586915969160691616916269163691646916569166691676916869169691706917169172691736917469175691766917769178691796918069181691826918369184691856918669187691886918969190691916919269193691946919569196691976919869199692006920169202692036920469205692066920769208692096921069211692126921369214692156921669217692186921969220692216922269223692246922569226692276922869229692306923169232692336923469235692366923769238692396924069241692426924369244692456924669247692486924969250692516925269253692546925569256692576925869259692606926169262692636926469265692666926769268692696927069271692726927369274692756927669277692786927969280692816928269283692846928569286692876928869289692906929169292692936929469295692966929769298692996930069301693026930369304693056930669307693086930969310693116931269313693146931569316693176931869319693206932169322693236932469325693266932769328693296933069331693326933369334693356933669337693386933969340693416934269343693446934569346693476934869349693506935169352693536935469355693566935769358693596936069361693626936369364693656936669367693686936969370693716937269373693746937569376693776937869379693806938169382693836938469385693866938769388693896939069391693926939369394693956939669397693986939969400694016940269403694046940569406694076940869409694106941169412694136941469415694166941769418694196942069421694226942369424694256942669427694286942969430694316943269433694346943569436694376943869439694406944169442694436944469445694466944769448694496945069451694526945369454694556945669457694586945969460694616946269463694646946569466694676946869469694706947169472694736947469475694766947769478694796948069481694826948369484694856948669487694886948969490694916949269493694946949569496694976949869499695006950169502695036950469505695066950769508695096951069511695126951369514695156951669517695186951969520695216952269523695246952569526695276952869529695306953169532695336953469535695366953769538695396954069541695426954369544695456954669547695486954969550695516955269553695546955569556695576955869559695606956169562695636956469565695666956769568695696957069571695726957369574695756957669577695786957969580695816958269583695846958569586695876958869589695906959169592695936959469595695966959769598695996960069601696026960369604696056960669607696086960969610696116961269613696146961569616696176961869619696206962169622696236962469625696266962769628696296963069631696326963369634696356963669637696386963969640696416964269643696446964569646696476964869649696506965169652696536965469655696566965769658696596966069661696626966369664696656966669667696686966969670696716967269673696746967569676696776967869679696806968169682696836968469685696866968769688696896969069691696926969369694696956969669697696986969969700697016970269703697046970569706697076970869709697106971169712697136971469715697166971769718697196972069721697226972369724697256972669727697286972969730697316973269733697346973569736697376973869739697406974169742697436974469745697466974769748697496975069751697526975369754697556975669757697586975969760697616976269763697646976569766697676976869769697706977169772697736977469775697766977769778697796978069781697826978369784697856978669787697886978969790697916979269793697946979569796697976979869799698006980169802698036980469805698066980769808698096981069811698126981369814698156981669817698186981969820698216982269823698246982569826698276982869829698306983169832698336983469835698366983769838698396984069841698426984369844698456984669847698486984969850698516985269853698546985569856698576985869859698606986169862698636986469865698666986769868698696987069871698726987369874698756987669877698786987969880698816988269883698846988569886698876988869889698906989169892698936989469895698966989769898698996990069901699026990369904699056990669907699086990969910699116991269913699146991569916699176991869919699206992169922699236992469925699266992769928699296993069931699326993369934699356993669937699386993969940699416994269943699446994569946699476994869949699506995169952699536995469955699566995769958699596996069961699626996369964699656996669967699686996969970699716997269973699746997569976699776997869979699806998169982699836998469985699866998769988699896999069991699926999369994699956999669997699986999970000700017000270003700047000570006700077000870009700107001170012700137001470015700167001770018700197002070021700227002370024700257002670027700287002970030700317003270033700347003570036700377003870039700407004170042700437004470045700467004770048700497005070051700527005370054700557005670057700587005970060700617006270063700647006570066700677006870069700707007170072700737007470075700767007770078700797008070081700827008370084700857008670087700887008970090700917009270093700947009570096700977009870099701007010170102701037010470105701067010770108701097011070111701127011370114701157011670117701187011970120701217012270123701247012570126701277012870129701307013170132701337013470135701367013770138701397014070141701427014370144701457014670147701487014970150701517015270153701547015570156701577015870159701607016170162701637016470165701667016770168701697017070171701727017370174701757017670177701787017970180701817018270183701847018570186701877018870189701907019170192701937019470195701967019770198701997020070201702027020370204702057020670207702087020970210702117021270213702147021570216702177021870219702207022170222702237022470225702267022770228702297023070231702327023370234702357023670237702387023970240702417024270243702447024570246702477024870249702507025170252702537025470255702567025770258702597026070261702627026370264702657026670267702687026970270702717027270273702747027570276702777027870279702807028170282702837028470285702867028770288702897029070291702927029370294702957029670297702987029970300703017030270303703047030570306703077030870309703107031170312703137031470315703167031770318703197032070321703227032370324703257032670327703287032970330703317033270333703347033570336703377033870339703407034170342703437034470345703467034770348703497035070351703527035370354703557035670357703587035970360703617036270363703647036570366703677036870369703707037170372703737037470375703767037770378703797038070381703827038370384703857038670387703887038970390703917039270393703947039570396703977039870399704007040170402704037040470405704067040770408704097041070411704127041370414704157041670417704187041970420704217042270423704247042570426704277042870429704307043170432704337043470435704367043770438704397044070441704427044370444704457044670447704487044970450704517045270453704547045570456704577045870459704607046170462704637046470465704667046770468704697047070471704727047370474704757047670477704787047970480704817048270483704847048570486704877048870489704907049170492704937049470495704967049770498704997050070501705027050370504705057050670507705087050970510705117051270513705147051570516705177051870519705207052170522705237052470525705267052770528705297053070531705327053370534705357053670537705387053970540705417054270543705447054570546705477054870549705507055170552705537055470555705567055770558705597056070561705627056370564705657056670567705687056970570705717057270573705747057570576705777057870579705807058170582705837058470585705867058770588705897059070591705927059370594705957059670597705987059970600706017060270603706047060570606706077060870609706107061170612706137061470615706167061770618706197062070621706227062370624706257062670627706287062970630706317063270633706347063570636706377063870639706407064170642706437064470645706467064770648706497065070651706527065370654706557065670657706587065970660706617066270663706647066570666706677066870669706707067170672706737067470675706767067770678706797068070681706827068370684706857068670687706887068970690706917069270693706947069570696706977069870699707007070170702707037070470705707067070770708707097071070711707127071370714707157071670717707187071970720707217072270723707247072570726707277072870729707307073170732707337073470735707367073770738707397074070741707427074370744707457074670747707487074970750707517075270753707547075570756707577075870759707607076170762707637076470765707667076770768707697077070771707727077370774707757077670777707787077970780707817078270783707847078570786707877078870789707907079170792707937079470795707967079770798707997080070801708027080370804708057080670807708087080970810708117081270813708147081570816708177081870819708207082170822708237082470825708267082770828708297083070831708327083370834708357083670837708387083970840708417084270843708447084570846708477084870849708507085170852708537085470855708567085770858708597086070861708627086370864708657086670867708687086970870708717087270873708747087570876708777087870879708807088170882708837088470885708867088770888708897089070891708927089370894708957089670897708987089970900709017090270903709047090570906709077090870909709107091170912709137091470915709167091770918709197092070921709227092370924709257092670927709287092970930709317093270933709347093570936709377093870939709407094170942709437094470945709467094770948709497095070951709527095370954709557095670957709587095970960709617096270963709647096570966709677096870969709707097170972709737097470975709767097770978709797098070981709827098370984709857098670987709887098970990709917099270993709947099570996709977099870999710007100171002710037100471005710067100771008710097101071011710127101371014710157101671017710187101971020710217102271023710247102571026710277102871029710307103171032710337103471035710367103771038710397104071041710427104371044710457104671047710487104971050710517105271053710547105571056710577105871059710607106171062710637106471065710667106771068710697107071071710727107371074710757107671077710787107971080710817108271083710847108571086710877108871089710907109171092710937109471095710967109771098710997110071101711027110371104711057110671107711087110971110711117111271113711147111571116711177111871119711207112171122711237112471125711267112771128711297113071131711327113371134711357113671137711387113971140711417114271143711447114571146711477114871149711507115171152711537115471155711567115771158711597116071161711627116371164711657116671167711687116971170711717117271173711747117571176711777117871179711807118171182711837118471185711867118771188711897119071191711927119371194711957119671197711987119971200712017120271203712047120571206712077120871209712107121171212712137121471215712167121771218712197122071221712227122371224712257122671227712287122971230712317123271233712347123571236712377123871239712407124171242712437124471245712467124771248712497125071251712527125371254712557125671257712587125971260712617126271263712647126571266712677126871269712707127171272712737127471275712767127771278712797128071281712827128371284712857128671287712887128971290712917129271293712947129571296712977129871299713007130171302713037130471305713067130771308713097131071311713127131371314713157131671317713187131971320713217132271323713247132571326713277132871329713307133171332713337133471335713367133771338713397134071341713427134371344713457134671347713487134971350713517135271353713547135571356713577135871359713607136171362713637136471365713667136771368713697137071371713727137371374713757137671377713787137971380713817138271383713847138571386713877138871389713907139171392713937139471395713967139771398713997140071401714027140371404714057140671407714087140971410714117141271413714147141571416714177141871419714207142171422714237142471425714267142771428714297143071431714327143371434714357143671437714387143971440714417144271443714447144571446714477144871449714507145171452714537145471455714567145771458714597146071461714627146371464714657146671467714687146971470714717147271473714747147571476714777147871479714807148171482714837148471485714867148771488714897149071491714927149371494714957149671497714987149971500715017150271503715047150571506715077150871509715107151171512715137151471515715167151771518715197152071521715227152371524715257152671527715287152971530715317153271533715347153571536715377153871539715407154171542715437154471545715467154771548715497155071551715527155371554715557155671557715587155971560715617156271563715647156571566715677156871569715707157171572715737157471575715767157771578715797158071581715827158371584715857158671587715887158971590715917159271593715947159571596715977159871599716007160171602716037160471605716067160771608716097161071611716127161371614716157161671617716187161971620716217162271623716247162571626716277162871629716307163171632716337163471635716367163771638716397164071641716427164371644716457164671647716487164971650716517165271653716547165571656716577165871659716607166171662716637166471665716667166771668716697167071671716727167371674716757167671677716787167971680716817168271683716847168571686716877168871689716907169171692716937169471695716967169771698716997170071701717027170371704717057170671707717087170971710717117171271713717147171571716717177171871719717207172171722717237172471725717267172771728717297173071731717327173371734717357173671737717387173971740717417174271743717447174571746717477174871749717507175171752717537175471755717567175771758717597176071761717627176371764717657176671767717687176971770717717177271773717747177571776717777177871779717807178171782717837178471785717867178771788717897179071791717927179371794717957179671797717987179971800718017180271803718047180571806718077180871809718107181171812718137181471815718167181771818718197182071821718227182371824718257182671827718287182971830718317183271833718347183571836718377183871839718407184171842718437184471845718467184771848718497185071851718527185371854718557185671857718587185971860718617186271863718647186571866718677186871869718707187171872718737187471875718767187771878718797188071881718827188371884718857188671887718887188971890718917189271893718947189571896718977189871899719007190171902719037190471905719067190771908719097191071911719127191371914719157191671917719187191971920719217192271923719247192571926719277192871929719307193171932719337193471935719367193771938719397194071941719427194371944719457194671947719487194971950719517195271953719547195571956719577195871959719607196171962719637196471965719667196771968719697197071971719727197371974719757197671977719787197971980719817198271983719847198571986719877198871989719907199171992719937199471995719967199771998719997200072001720027200372004720057200672007720087200972010720117201272013720147201572016720177201872019720207202172022720237202472025720267202772028720297203072031720327203372034720357203672037720387203972040720417204272043720447204572046720477204872049720507205172052720537205472055720567205772058720597206072061720627206372064720657206672067720687206972070720717207272073720747207572076720777207872079720807208172082720837208472085720867208772088720897209072091720927209372094720957209672097720987209972100721017210272103721047210572106721077210872109721107211172112721137211472115721167211772118721197212072121721227212372124721257212672127721287212972130721317213272133721347213572136721377213872139721407214172142721437214472145721467214772148721497215072151721527215372154721557215672157721587215972160721617216272163721647216572166721677216872169721707217172172721737217472175721767217772178721797218072181721827218372184721857218672187721887218972190721917219272193721947219572196721977219872199722007220172202722037220472205722067220772208722097221072211722127221372214722157221672217722187221972220722217222272223722247222572226722277222872229722307223172232722337223472235722367223772238722397224072241722427224372244722457224672247722487224972250722517225272253722547225572256722577225872259722607226172262722637226472265722667226772268722697227072271722727227372274722757227672277722787227972280722817228272283722847228572286722877228872289722907229172292722937229472295722967229772298722997230072301723027230372304723057230672307723087230972310723117231272313723147231572316723177231872319723207232172322723237232472325723267232772328723297233072331723327233372334723357233672337723387233972340723417234272343723447234572346723477234872349723507235172352723537235472355723567235772358723597236072361723627236372364723657236672367723687236972370723717237272373723747237572376723777237872379723807238172382723837238472385723867238772388723897239072391723927239372394723957239672397723987239972400724017240272403724047240572406724077240872409724107241172412724137241472415724167241772418724197242072421724227242372424724257242672427724287242972430724317243272433724347243572436724377243872439724407244172442724437244472445724467244772448724497245072451724527245372454724557245672457724587245972460724617246272463724647246572466724677246872469724707247172472724737247472475724767247772478724797248072481724827248372484724857248672487724887248972490724917249272493724947249572496724977249872499725007250172502725037250472505725067250772508725097251072511725127251372514725157251672517725187251972520725217252272523725247252572526725277252872529725307253172532725337253472535725367253772538725397254072541725427254372544725457254672547725487254972550725517255272553725547255572556725577255872559725607256172562725637256472565725667256772568725697257072571725727257372574725757257672577725787257972580725817258272583725847258572586725877258872589725907259172592725937259472595725967259772598725997260072601726027260372604726057260672607726087260972610726117261272613726147261572616726177261872619726207262172622726237262472625726267262772628726297263072631726327263372634726357263672637726387263972640726417264272643726447264572646726477264872649726507265172652726537265472655726567265772658726597266072661726627266372664726657266672667726687266972670726717267272673726747267572676726777267872679726807268172682726837268472685726867268772688726897269072691726927269372694726957269672697726987269972700727017270272703727047270572706727077270872709727107271172712727137271472715727167271772718727197272072721727227272372724727257272672727727287272972730727317273272733727347273572736727377273872739727407274172742727437274472745727467274772748727497275072751727527275372754727557275672757727587275972760727617276272763727647276572766727677276872769727707277172772727737277472775727767277772778727797278072781727827278372784727857278672787727887278972790727917279272793727947279572796727977279872799728007280172802728037280472805728067280772808728097281072811728127281372814728157281672817728187281972820728217282272823728247282572826728277282872829728307283172832728337283472835728367283772838728397284072841728427284372844728457284672847728487284972850728517285272853728547285572856728577285872859728607286172862728637286472865728667286772868728697287072871728727287372874728757287672877728787287972880728817288272883728847288572886728877288872889728907289172892728937289472895728967289772898728997290072901729027290372904729057290672907729087290972910729117291272913729147291572916729177291872919729207292172922729237292472925729267292772928729297293072931729327293372934729357293672937729387293972940729417294272943729447294572946729477294872949729507295172952729537295472955729567295772958729597296072961729627296372964729657296672967729687296972970729717297272973729747297572976729777297872979729807298172982729837298472985729867298772988729897299072991729927299372994729957299672997729987299973000730017300273003730047300573006730077300873009730107301173012730137301473015730167301773018730197302073021730227302373024730257302673027730287302973030730317303273033730347303573036730377303873039730407304173042730437304473045730467304773048730497305073051730527305373054730557305673057730587305973060730617306273063730647306573066730677306873069730707307173072730737307473075730767307773078730797308073081730827308373084730857308673087730887308973090730917309273093730947309573096730977309873099731007310173102731037310473105731067310773108731097311073111731127311373114731157311673117731187311973120731217312273123731247312573126731277312873129731307313173132731337313473135731367313773138731397314073141731427314373144731457314673147731487314973150731517315273153731547315573156731577315873159731607316173162731637316473165731667316773168731697317073171731727317373174731757317673177731787317973180731817318273183731847318573186731877318873189731907319173192731937319473195731967319773198731997320073201732027320373204732057320673207732087320973210732117321273213732147321573216732177321873219732207322173222732237322473225732267322773228732297323073231732327323373234732357323673237732387323973240732417324273243732447324573246732477324873249732507325173252732537325473255732567325773258732597326073261732627326373264732657326673267732687326973270732717327273273732747327573276732777327873279732807328173282732837328473285732867328773288732897329073291732927329373294732957329673297732987329973300733017330273303733047330573306733077330873309733107331173312733137331473315733167331773318733197332073321733227332373324733257332673327733287332973330733317333273333733347333573336733377333873339733407334173342733437334473345733467334773348733497335073351733527335373354733557335673357733587335973360733617336273363733647336573366733677336873369733707337173372733737337473375733767337773378733797338073381733827338373384733857338673387733887338973390733917339273393733947339573396733977339873399734007340173402734037340473405734067340773408734097341073411734127341373414734157341673417734187341973420734217342273423734247342573426734277342873429734307343173432734337343473435734367343773438734397344073441734427344373444734457344673447734487344973450734517345273453734547345573456734577345873459734607346173462734637346473465734667346773468734697347073471734727347373474734757347673477734787347973480734817348273483734847348573486734877348873489734907349173492734937349473495734967349773498734997350073501735027350373504735057350673507735087350973510735117351273513735147351573516735177351873519735207352173522735237352473525735267352773528735297353073531735327353373534735357353673537735387353973540735417354273543735447354573546735477354873549735507355173552735537355473555735567355773558735597356073561735627356373564735657356673567735687356973570735717357273573735747357573576735777357873579735807358173582735837358473585735867358773588735897359073591735927359373594735957359673597735987359973600736017360273603736047360573606736077360873609736107361173612736137361473615736167361773618736197362073621736227362373624736257362673627736287362973630736317363273633736347363573636736377363873639736407364173642736437364473645736467364773648736497365073651736527365373654736557365673657736587365973660736617366273663736647366573666736677366873669736707367173672736737367473675736767367773678736797368073681736827368373684736857368673687736887368973690736917369273693736947369573696736977369873699737007370173702737037370473705737067370773708737097371073711737127371373714737157371673717737187371973720737217372273723737247372573726737277372873729737307373173732737337373473735737367373773738737397374073741737427374373744737457374673747737487374973750737517375273753737547375573756737577375873759737607376173762737637376473765737667376773768737697377073771737727377373774737757377673777737787377973780737817378273783737847378573786737877378873789737907379173792737937379473795737967379773798737997380073801738027380373804738057380673807738087380973810738117381273813738147381573816738177381873819738207382173822738237382473825738267382773828738297383073831738327383373834738357383673837738387383973840738417384273843738447384573846738477384873849738507385173852738537385473855738567385773858738597386073861738627386373864738657386673867738687386973870738717387273873738747387573876738777387873879738807388173882738837388473885738867388773888738897389073891738927389373894738957389673897738987389973900739017390273903739047390573906739077390873909739107391173912739137391473915739167391773918739197392073921739227392373924739257392673927739287392973930739317393273933739347393573936739377393873939739407394173942739437394473945739467394773948739497395073951739527395373954739557395673957739587395973960739617396273963739647396573966739677396873969739707397173972739737397473975739767397773978739797398073981739827398373984739857398673987739887398973990739917399273993739947399573996739977399873999740007400174002740037400474005740067400774008740097401074011740127401374014740157401674017740187401974020740217402274023740247402574026740277402874029740307403174032740337403474035740367403774038740397404074041740427404374044740457404674047740487404974050740517405274053740547405574056740577405874059740607406174062740637406474065740667406774068740697407074071740727407374074740757407674077740787407974080740817408274083740847408574086740877408874089740907409174092740937409474095740967409774098740997410074101741027410374104741057410674107741087410974110741117411274113741147411574116741177411874119741207412174122741237412474125741267412774128741297413074131741327413374134741357413674137741387413974140741417414274143741447414574146741477414874149741507415174152741537415474155741567415774158741597416074161741627416374164741657416674167741687416974170741717417274173741747417574176741777417874179741807418174182741837418474185741867418774188741897419074191741927419374194741957419674197741987419974200742017420274203742047420574206742077420874209742107421174212742137421474215742167421774218742197422074221742227422374224742257422674227742287422974230742317423274233742347423574236742377423874239742407424174242742437424474245742467424774248742497425074251742527425374254742557425674257742587425974260742617426274263742647426574266742677426874269742707427174272742737427474275742767427774278742797428074281742827428374284742857428674287742887428974290742917429274293742947429574296742977429874299743007430174302743037430474305743067430774308743097431074311743127431374314743157431674317743187431974320743217432274323743247432574326743277432874329743307433174332743337433474335743367433774338743397434074341743427434374344743457434674347743487434974350743517435274353743547435574356743577435874359743607436174362743637436474365743667436774368743697437074371743727437374374743757437674377743787437974380743817438274383743847438574386743877438874389743907439174392743937439474395743967439774398743997440074401744027440374404744057440674407744087440974410744117441274413744147441574416744177441874419744207442174422744237442474425744267442774428744297443074431744327443374434744357443674437744387443974440744417444274443744447444574446744477444874449744507445174452744537445474455744567445774458744597446074461744627446374464744657446674467744687446974470744717447274473744747447574476744777447874479744807448174482744837448474485744867448774488744897449074491744927449374494744957449674497744987449974500745017450274503745047450574506745077450874509745107451174512745137451474515745167451774518745197452074521745227452374524745257452674527745287452974530745317453274533745347453574536745377453874539745407454174542745437454474545745467454774548745497455074551745527455374554745557455674557745587455974560745617456274563745647456574566745677456874569745707457174572745737457474575745767457774578745797458074581745827458374584745857458674587745887458974590745917459274593745947459574596745977459874599746007460174602746037460474605746067460774608746097461074611746127461374614746157461674617746187461974620746217462274623746247462574626746277462874629746307463174632746337463474635746367463774638746397464074641746427464374644746457464674647746487464974650746517465274653746547465574656746577465874659746607466174662746637466474665746667466774668746697467074671746727467374674746757467674677746787467974680746817468274683746847468574686746877468874689746907469174692746937469474695746967469774698746997470074701747027470374704747057470674707747087470974710747117471274713747147471574716747177471874719747207472174722747237472474725747267472774728747297473074731747327473374734747357473674737747387473974740747417474274743747447474574746747477474874749747507475174752747537475474755747567475774758747597476074761747627476374764747657476674767747687476974770747717477274773747747477574776747777477874779747807478174782747837478474785747867478774788747897479074791747927479374794747957479674797747987479974800748017480274803748047480574806748077480874809748107481174812748137481474815748167481774818748197482074821748227482374824748257482674827748287482974830748317483274833748347483574836748377483874839748407484174842748437484474845748467484774848748497485074851748527485374854748557485674857748587485974860748617486274863748647486574866748677486874869748707487174872748737487474875748767487774878748797488074881748827488374884748857488674887748887488974890748917489274893748947489574896748977489874899749007490174902749037490474905749067490774908749097491074911749127491374914749157491674917749187491974920749217492274923749247492574926749277492874929749307493174932749337493474935749367493774938749397494074941749427494374944749457494674947749487494974950749517495274953749547495574956749577495874959749607496174962749637496474965749667496774968749697497074971749727497374974749757497674977749787497974980749817498274983749847498574986749877498874989749907499174992749937499474995749967499774998749997500075001750027500375004750057500675007750087500975010750117501275013750147501575016750177501875019750207502175022750237502475025750267502775028750297503075031750327503375034750357503675037750387503975040750417504275043750447504575046750477504875049750507505175052750537505475055750567505775058750597506075061750627506375064750657506675067750687506975070750717507275073750747507575076750777507875079750807508175082750837508475085750867508775088750897509075091750927509375094750957509675097750987509975100751017510275103751047510575106751077510875109751107511175112751137511475115751167511775118751197512075121751227512375124751257512675127751287512975130751317513275133751347513575136751377513875139751407514175142751437514475145751467514775148751497515075151751527515375154751557515675157751587515975160751617516275163751647516575166751677516875169751707517175172751737517475175751767517775178751797518075181751827518375184751857518675187751887518975190751917519275193751947519575196751977519875199752007520175202752037520475205752067520775208752097521075211752127521375214752157521675217752187521975220752217522275223752247522575226752277522875229752307523175232752337523475235752367523775238752397524075241752427524375244752457524675247752487524975250752517525275253752547525575256752577525875259752607526175262752637526475265752667526775268752697527075271752727527375274752757527675277752787527975280752817528275283752847528575286752877528875289752907529175292752937529475295752967529775298752997530075301753027530375304753057530675307753087530975310753117531275313753147531575316753177531875319753207532175322753237532475325753267532775328753297533075331753327533375334753357533675337753387533975340753417534275343753447534575346753477534875349753507535175352753537535475355753567535775358753597536075361753627536375364753657536675367753687536975370753717537275373753747537575376753777537875379753807538175382753837538475385753867538775388753897539075391753927539375394753957539675397753987539975400754017540275403754047540575406754077540875409754107541175412754137541475415754167541775418754197542075421754227542375424754257542675427754287542975430754317543275433754347543575436754377543875439754407544175442754437544475445754467544775448754497545075451754527545375454754557545675457754587545975460754617546275463754647546575466754677546875469754707547175472754737547475475754767547775478754797548075481754827548375484754857548675487754887548975490754917549275493754947549575496754977549875499755007550175502755037550475505755067550775508755097551075511755127551375514755157551675517755187551975520755217552275523755247552575526755277552875529755307553175532755337553475535755367553775538755397554075541755427554375544755457554675547755487554975550755517555275553755547555575556755577555875559755607556175562755637556475565755667556775568755697557075571755727557375574755757557675577755787557975580755817558275583755847558575586755877558875589755907559175592755937559475595755967559775598755997560075601756027560375604756057560675607756087560975610756117561275613756147561575616756177561875619756207562175622756237562475625756267562775628756297563075631756327563375634756357563675637756387563975640756417564275643756447564575646756477564875649756507565175652756537565475655756567565775658756597566075661756627566375664756657566675667756687566975670756717567275673756747567575676756777567875679756807568175682756837568475685756867568775688756897569075691756927569375694756957569675697756987569975700757017570275703757047570575706757077570875709757107571175712757137571475715757167571775718757197572075721757227572375724757257572675727757287572975730757317573275733757347573575736757377573875739757407574175742757437574475745757467574775748757497575075751757527575375754757557575675757757587575975760757617576275763757647576575766757677576875769757707577175772757737577475775757767577775778757797578075781757827578375784757857578675787757887578975790757917579275793757947579575796757977579875799758007580175802758037580475805758067580775808758097581075811758127581375814758157581675817758187581975820758217582275823758247582575826758277582875829758307583175832758337583475835758367583775838758397584075841758427584375844758457584675847758487584975850758517585275853758547585575856758577585875859758607586175862758637586475865758667586775868758697587075871758727587375874758757587675877758787587975880758817588275883758847588575886758877588875889758907589175892758937589475895758967589775898758997590075901759027590375904759057590675907759087590975910759117591275913759147591575916759177591875919759207592175922759237592475925759267592775928759297593075931759327593375934759357593675937759387593975940759417594275943759447594575946759477594875949759507595175952759537595475955759567595775958759597596075961759627596375964759657596675967759687596975970759717597275973759747597575976759777597875979759807598175982759837598475985759867598775988759897599075991759927599375994759957599675997759987599976000760017600276003760047600576006760077600876009760107601176012760137601476015760167601776018760197602076021760227602376024760257602676027760287602976030760317603276033760347603576036760377603876039760407604176042760437604476045760467604776048760497605076051760527605376054760557605676057760587605976060760617606276063760647606576066760677606876069760707607176072760737607476075760767607776078760797608076081760827608376084760857608676087760887608976090760917609276093760947609576096760977609876099761007610176102761037610476105761067610776108761097611076111761127611376114761157611676117761187611976120761217612276123761247612576126761277612876129761307613176132761337613476135761367613776138761397614076141761427614376144761457614676147761487614976150761517615276153761547615576156761577615876159761607616176162761637616476165761667616776168761697617076171761727617376174761757617676177761787617976180761817618276183761847618576186761877618876189761907619176192761937619476195761967619776198761997620076201762027620376204762057620676207762087620976210762117621276213762147621576216762177621876219762207622176222762237622476225762267622776228762297623076231762327623376234762357623676237762387623976240762417624276243762447624576246762477624876249762507625176252762537625476255762567625776258762597626076261762627626376264762657626676267762687626976270762717627276273762747627576276762777627876279762807628176282762837628476285762867628776288762897629076291762927629376294762957629676297762987629976300763017630276303763047630576306763077630876309763107631176312763137631476315763167631776318763197632076321763227632376324763257632676327763287632976330763317633276333763347633576336763377633876339763407634176342763437634476345763467634776348763497635076351763527635376354763557635676357763587635976360763617636276363763647636576366763677636876369763707637176372763737637476375763767637776378763797638076381763827638376384763857638676387763887638976390763917639276393763947639576396763977639876399764007640176402764037640476405764067640776408764097641076411764127641376414764157641676417764187641976420764217642276423764247642576426764277642876429764307643176432764337643476435764367643776438764397644076441764427644376444764457644676447764487644976450764517645276453764547645576456764577645876459764607646176462764637646476465764667646776468764697647076471764727647376474764757647676477764787647976480764817648276483764847648576486764877648876489764907649176492764937649476495764967649776498764997650076501765027650376504765057650676507765087650976510765117651276513765147651576516765177651876519765207652176522765237652476525765267652776528765297653076531765327653376534765357653676537765387653976540765417654276543765447654576546765477654876549765507655176552765537655476555765567655776558765597656076561765627656376564765657656676567765687656976570765717657276573765747657576576765777657876579765807658176582765837658476585765867658776588765897659076591765927659376594765957659676597765987659976600766017660276603766047660576606766077660876609766107661176612766137661476615766167661776618766197662076621766227662376624766257662676627766287662976630766317663276633766347663576636766377663876639766407664176642766437664476645766467664776648766497665076651766527665376654766557665676657766587665976660766617666276663766647666576666766677666876669766707667176672766737667476675766767667776678766797668076681766827668376684766857668676687766887668976690766917669276693766947669576696766977669876699767007670176702767037670476705767067670776708767097671076711767127671376714767157671676717767187671976720767217672276723767247672576726767277672876729767307673176732767337673476735767367673776738767397674076741767427674376744767457674676747767487674976750767517675276753767547675576756767577675876759767607676176762767637676476765767667676776768767697677076771767727677376774767757677676777767787677976780767817678276783767847678576786767877678876789767907679176792767937679476795767967679776798767997680076801768027680376804768057680676807768087680976810768117681276813768147681576816768177681876819768207682176822768237682476825768267682776828768297683076831768327683376834768357683676837768387683976840768417684276843768447684576846768477684876849768507685176852768537685476855768567685776858768597686076861768627686376864768657686676867768687686976870768717687276873768747687576876768777687876879768807688176882768837688476885768867688776888768897689076891768927689376894768957689676897768987689976900769017690276903769047690576906769077690876909769107691176912769137691476915769167691776918769197692076921769227692376924769257692676927769287692976930769317693276933769347693576936769377693876939769407694176942769437694476945769467694776948769497695076951769527695376954769557695676957769587695976960769617696276963769647696576966769677696876969769707697176972769737697476975769767697776978769797698076981769827698376984769857698676987769887698976990769917699276993769947699576996769977699876999770007700177002770037700477005770067700777008770097701077011770127701377014770157701677017770187701977020770217702277023770247702577026770277702877029770307703177032770337703477035770367703777038770397704077041770427704377044770457704677047770487704977050770517705277053770547705577056770577705877059770607706177062770637706477065770667706777068770697707077071770727707377074770757707677077770787707977080770817708277083770847708577086770877708877089770907709177092770937709477095770967709777098770997710077101771027710377104771057710677107771087710977110771117711277113771147711577116771177711877119771207712177122771237712477125771267712777128771297713077131771327713377134771357713677137771387713977140771417714277143771447714577146771477714877149771507715177152771537715477155771567715777158771597716077161771627716377164771657716677167771687716977170771717717277173771747717577176771777717877179771807718177182771837718477185771867718777188771897719077191771927719377194771957719677197771987719977200772017720277203772047720577206772077720877209772107721177212772137721477215772167721777218772197722077221772227722377224772257722677227772287722977230772317723277233772347723577236772377723877239772407724177242772437724477245772467724777248772497725077251772527725377254772557725677257772587725977260772617726277263772647726577266772677726877269772707727177272772737727477275772767727777278772797728077281772827728377284772857728677287772887728977290772917729277293772947729577296772977729877299773007730177302773037730477305773067730777308773097731077311773127731377314773157731677317773187731977320773217732277323773247732577326773277732877329773307733177332773337733477335773367733777338773397734077341773427734377344773457734677347773487734977350773517735277353773547735577356773577735877359773607736177362773637736477365773667736777368773697737077371773727737377374773757737677377773787737977380773817738277383773847738577386773877738877389773907739177392773937739477395773967739777398773997740077401774027740377404774057740677407774087740977410774117741277413774147741577416774177741877419774207742177422774237742477425774267742777428774297743077431774327743377434774357743677437774387743977440774417744277443774447744577446774477744877449774507745177452774537745477455774567745777458774597746077461774627746377464774657746677467774687746977470774717747277473774747747577476774777747877479774807748177482774837748477485774867748777488774897749077491774927749377494774957749677497774987749977500775017750277503775047750577506775077750877509775107751177512775137751477515775167751777518775197752077521775227752377524775257752677527775287752977530775317753277533775347753577536775377753877539775407754177542775437754477545775467754777548775497755077551775527755377554775557755677557775587755977560775617756277563775647756577566775677756877569775707757177572775737757477575775767757777578775797758077581775827758377584775857758677587775887758977590775917759277593775947759577596775977759877599776007760177602776037760477605776067760777608776097761077611776127761377614776157761677617776187761977620776217762277623776247762577626776277762877629776307763177632776337763477635776367763777638776397764077641776427764377644776457764677647776487764977650776517765277653776547765577656776577765877659776607766177662776637766477665776667766777668776697767077671776727767377674776757767677677776787767977680776817768277683776847768577686776877768877689776907769177692776937769477695776967769777698776997770077701777027770377704777057770677707777087770977710777117771277713777147771577716777177771877719777207772177722777237772477725777267772777728777297773077731777327773377734777357773677737777387773977740777417774277743777447774577746777477774877749777507775177752777537775477755777567775777758777597776077761777627776377764777657776677767777687776977770777717777277773777747777577776777777777877779777807778177782777837778477785777867778777788777897779077791777927779377794777957779677797777987779977800778017780277803778047780577806778077780877809778107781177812778137781477815778167781777818778197782077821778227782377824778257782677827778287782977830778317783277833778347783577836778377783877839778407784177842778437784477845778467784777848778497785077851778527785377854778557785677857778587785977860778617786277863778647786577866778677786877869778707787177872778737787477875778767787777878778797788077881778827788377884778857788677887778887788977890778917789277893778947789577896778977789877899779007790177902779037790477905779067790777908779097791077911779127791377914779157791677917779187791977920779217792277923779247792577926779277792877929779307793177932779337793477935779367793777938779397794077941779427794377944779457794677947779487794977950779517795277953779547795577956779577795877959779607796177962779637796477965779667796777968779697797077971779727797377974779757797677977779787797977980779817798277983779847798577986779877798877989779907799177992779937799477995779967799777998779997800078001780027800378004780057800678007780087800978010780117801278013780147801578016780177801878019780207802178022780237802478025780267802778028780297803078031780327803378034780357803678037780387803978040780417804278043780447804578046780477804878049780507805178052780537805478055780567805778058780597806078061780627806378064780657806678067780687806978070780717807278073780747807578076780777807878079780807808178082780837808478085780867808778088780897809078091780927809378094780957809678097780987809978100781017810278103781047810578106781077810878109781107811178112781137811478115781167811778118781197812078121781227812378124781257812678127781287812978130781317813278133781347813578136781377813878139781407814178142781437814478145781467814778148781497815078151781527815378154781557815678157781587815978160781617816278163781647816578166781677816878169781707817178172781737817478175781767817778178781797818078181781827818378184781857818678187781887818978190781917819278193781947819578196781977819878199782007820178202782037820478205782067820778208782097821078211782127821378214782157821678217782187821978220782217822278223782247822578226782277822878229782307823178232782337823478235782367823778238782397824078241782427824378244782457824678247782487824978250782517825278253782547825578256782577825878259782607826178262782637826478265782667826778268782697827078271782727827378274782757827678277782787827978280782817828278283782847828578286782877828878289782907829178292782937829478295782967829778298782997830078301783027830378304783057830678307783087830978310783117831278313783147831578316783177831878319783207832178322783237832478325783267832778328783297833078331783327833378334783357833678337783387833978340783417834278343783447834578346783477834878349783507835178352783537835478355783567835778358783597836078361783627836378364783657836678367783687836978370783717837278373783747837578376783777837878379783807838178382783837838478385783867838778388783897839078391783927839378394783957839678397783987839978400784017840278403784047840578406784077840878409784107841178412784137841478415784167841778418784197842078421784227842378424784257842678427784287842978430784317843278433784347843578436784377843878439784407844178442784437844478445784467844778448784497845078451784527845378454784557845678457784587845978460784617846278463784647846578466784677846878469784707847178472784737847478475784767847778478784797848078481784827848378484784857848678487784887848978490784917849278493784947849578496784977849878499785007850178502785037850478505785067850778508785097851078511785127851378514785157851678517785187851978520785217852278523785247852578526785277852878529785307853178532785337853478535785367853778538785397854078541785427854378544785457854678547785487854978550785517855278553785547855578556785577855878559785607856178562785637856478565785667856778568785697857078571785727857378574785757857678577785787857978580785817858278583785847858578586785877858878589785907859178592785937859478595785967859778598785997860078601786027860378604786057860678607786087860978610786117861278613786147861578616786177861878619786207862178622786237862478625786267862778628786297863078631786327863378634786357863678637786387863978640786417864278643786447864578646786477864878649786507865178652786537865478655786567865778658786597866078661786627866378664786657866678667786687866978670786717867278673786747867578676786777867878679786807868178682786837868478685786867868778688786897869078691786927869378694786957869678697786987869978700787017870278703787047870578706787077870878709787107871178712787137871478715787167871778718787197872078721787227872378724787257872678727787287872978730787317873278733787347873578736787377873878739787407874178742787437874478745787467874778748787497875078751787527875378754787557875678757787587875978760787617876278763787647876578766787677876878769787707877178772787737877478775787767877778778787797878078781787827878378784787857878678787787887878978790787917879278793787947879578796787977879878799788007880178802788037880478805788067880778808788097881078811788127881378814788157881678817788187881978820788217882278823788247882578826788277882878829788307883178832788337883478835788367883778838788397884078841788427884378844788457884678847788487884978850788517885278853788547885578856788577885878859788607886178862788637886478865788667886778868788697887078871788727887378874788757887678877788787887978880788817888278883788847888578886788877888878889788907889178892788937889478895788967889778898788997890078901789027890378904789057890678907789087890978910789117891278913789147891578916789177891878919789207892178922789237892478925789267892778928789297893078931789327893378934789357893678937789387893978940789417894278943789447894578946789477894878949789507895178952789537895478955789567895778958789597896078961789627896378964789657896678967789687896978970789717897278973789747897578976789777897878979789807898178982789837898478985789867898778988789897899078991789927899378994789957899678997789987899979000790017900279003790047900579006790077900879009790107901179012790137901479015790167901779018790197902079021790227902379024790257902679027790287902979030790317903279033790347903579036790377903879039790407904179042790437904479045790467904779048790497905079051790527905379054790557905679057790587905979060790617906279063790647906579066790677906879069790707907179072790737907479075790767907779078790797908079081790827908379084790857908679087790887908979090790917909279093790947909579096790977909879099791007910179102791037910479105791067910779108791097911079111791127911379114791157911679117791187911979120791217912279123791247912579126791277912879129791307913179132791337913479135791367913779138791397914079141791427914379144791457914679147791487914979150791517915279153791547915579156791577915879159791607916179162791637916479165791667916779168791697917079171791727917379174791757917679177791787917979180791817918279183791847918579186791877918879189791907919179192791937919479195791967919779198791997920079201792027920379204792057920679207792087920979210792117921279213792147921579216792177921879219792207922179222792237922479225792267922779228792297923079231792327923379234792357923679237792387923979240792417924279243792447924579246792477924879249792507925179252792537925479255792567925779258792597926079261792627926379264792657926679267792687926979270792717927279273792747927579276792777927879279792807928179282792837928479285792867928779288792897929079291792927929379294792957929679297792987929979300793017930279303793047930579306793077930879309793107931179312793137931479315793167931779318793197932079321793227932379324793257932679327793287932979330793317933279333793347933579336793377933879339793407934179342793437934479345793467934779348793497935079351793527935379354793557935679357793587935979360793617936279363793647936579366793677936879369793707937179372793737937479375793767937779378793797938079381793827938379384793857938679387793887938979390793917939279393793947939579396793977939879399794007940179402794037940479405794067940779408794097941079411794127941379414794157941679417794187941979420794217942279423794247942579426794277942879429794307943179432794337943479435794367943779438794397944079441794427944379444794457944679447794487944979450794517945279453794547945579456794577945879459794607946179462794637946479465794667946779468794697947079471794727947379474794757947679477794787947979480794817948279483794847948579486794877948879489794907949179492794937949479495794967949779498794997950079501795027950379504795057950679507795087950979510795117951279513795147951579516795177951879519795207952179522795237952479525795267952779528795297953079531795327953379534795357953679537795387953979540795417954279543795447954579546795477954879549795507955179552795537955479555795567955779558795597956079561795627956379564795657956679567795687956979570795717957279573795747957579576795777957879579795807958179582795837958479585795867958779588795897959079591795927959379594795957959679597795987959979600796017960279603796047960579606796077960879609796107961179612796137961479615796167961779618796197962079621796227962379624796257962679627796287962979630796317963279633796347963579636796377963879639796407964179642796437964479645796467964779648796497965079651796527965379654796557965679657796587965979660796617966279663796647966579666796677966879669796707967179672796737967479675796767967779678796797968079681796827968379684796857968679687796887968979690796917969279693796947969579696796977969879699797007970179702797037970479705797067970779708797097971079711797127971379714797157971679717797187971979720797217972279723797247972579726797277972879729797307973179732797337973479735797367973779738797397974079741797427974379744797457974679747797487974979750797517975279753797547975579756797577975879759797607976179762797637976479765797667976779768797697977079771797727977379774797757977679777797787977979780797817978279783797847978579786797877978879789797907979179792797937979479795797967979779798797997980079801798027980379804798057980679807798087980979810798117981279813798147981579816798177981879819798207982179822798237982479825798267982779828798297983079831798327983379834798357983679837798387983979840798417984279843798447984579846798477984879849798507985179852798537985479855798567985779858798597986079861798627986379864798657986679867798687986979870798717987279873798747987579876798777987879879798807988179882798837988479885798867988779888798897989079891798927989379894798957989679897798987989979900799017990279903799047990579906799077990879909799107991179912799137991479915799167991779918799197992079921799227992379924799257992679927799287992979930799317993279933799347993579936799377993879939799407994179942799437994479945799467994779948799497995079951799527995379954799557995679957799587995979960799617996279963799647996579966799677996879969799707997179972799737997479975799767997779978799797998079981799827998379984799857998679987799887998979990799917999279993799947999579996799977999879999800008000180002800038000480005800068000780008800098001080011800128001380014800158001680017800188001980020800218002280023800248002580026800278002880029800308003180032800338003480035800368003780038800398004080041800428004380044800458004680047800488004980050800518005280053800548005580056800578005880059800608006180062800638006480065800668006780068800698007080071800728007380074800758007680077800788007980080800818008280083800848008580086800878008880089800908009180092800938009480095800968009780098800998010080101801028010380104801058010680107801088010980110801118011280113801148011580116801178011880119801208012180122801238012480125801268012780128801298013080131801328013380134801358013680137801388013980140801418014280143801448014580146801478014880149801508015180152801538015480155801568015780158801598016080161801628016380164801658016680167801688016980170801718017280173801748017580176801778017880179801808018180182801838018480185801868018780188801898019080191801928019380194801958019680197801988019980200802018020280203802048020580206802078020880209802108021180212802138021480215802168021780218802198022080221802228022380224802258022680227802288022980230802318023280233802348023580236802378023880239802408024180242802438024480245802468024780248802498025080251802528025380254802558025680257802588025980260802618026280263802648026580266802678026880269802708027180272802738027480275802768027780278802798028080281802828028380284802858028680287802888028980290802918029280293802948029580296802978029880299803008030180302803038030480305803068030780308803098031080311803128031380314803158031680317803188031980320803218032280323803248032580326803278032880329803308033180332803338033480335803368033780338803398034080341803428034380344803458034680347803488034980350803518035280353803548035580356803578035880359803608036180362803638036480365803668036780368803698037080371803728037380374803758037680377803788037980380803818038280383803848038580386803878038880389803908039180392803938039480395803968039780398803998040080401804028040380404804058040680407804088040980410804118041280413804148041580416804178041880419804208042180422804238042480425804268042780428804298043080431804328043380434804358043680437804388043980440804418044280443804448044580446804478044880449804508045180452804538045480455804568045780458804598046080461804628046380464804658046680467804688046980470804718047280473804748047580476804778047880479804808048180482804838048480485804868048780488804898049080491804928049380494804958049680497804988049980500805018050280503805048050580506805078050880509805108051180512805138051480515805168051780518805198052080521805228052380524805258052680527805288052980530805318053280533805348053580536805378053880539805408054180542805438054480545805468054780548805498055080551805528055380554805558055680557805588055980560805618056280563805648056580566805678056880569805708057180572805738057480575805768057780578805798058080581805828058380584805858058680587805888058980590805918059280593805948059580596805978059880599806008060180602806038060480605806068060780608806098061080611806128061380614806158061680617806188061980620806218062280623806248062580626806278062880629806308063180632806338063480635806368063780638806398064080641806428064380644806458064680647806488064980650806518065280653806548065580656806578065880659806608066180662806638066480665806668066780668806698067080671806728067380674806758067680677806788067980680806818068280683806848068580686806878068880689806908069180692806938069480695806968069780698806998070080701807028070380704807058070680707807088070980710807118071280713807148071580716807178071880719807208072180722807238072480725807268072780728807298073080731807328073380734807358073680737807388073980740807418074280743807448074580746807478074880749807508075180752807538075480755807568075780758807598076080761807628076380764807658076680767807688076980770807718077280773807748077580776807778077880779807808078180782807838078480785807868078780788807898079080791807928079380794807958079680797807988079980800808018080280803808048080580806808078080880809808108081180812808138081480815808168081780818808198082080821808228082380824808258082680827808288082980830808318083280833808348083580836808378083880839808408084180842808438084480845808468084780848808498085080851808528085380854808558085680857808588085980860808618086280863808648086580866808678086880869808708087180872808738087480875808768087780878808798088080881808828088380884808858088680887808888088980890808918089280893808948089580896808978089880899809008090180902809038090480905809068090780908809098091080911809128091380914809158091680917809188091980920809218092280923809248092580926809278092880929809308093180932809338093480935809368093780938809398094080941809428094380944809458094680947809488094980950809518095280953809548095580956809578095880959809608096180962809638096480965809668096780968809698097080971809728097380974809758097680977809788097980980809818098280983809848098580986809878098880989809908099180992809938099480995809968099780998809998100081001810028100381004810058100681007810088100981010810118101281013810148101581016810178101881019810208102181022810238102481025810268102781028810298103081031810328103381034810358103681037810388103981040810418104281043810448104581046810478104881049810508105181052810538105481055810568105781058810598106081061810628106381064810658106681067810688106981070810718107281073810748107581076810778107881079810808108181082810838108481085810868108781088810898109081091810928109381094810958109681097810988109981100811018110281103811048110581106811078110881109811108111181112811138111481115811168111781118811198112081121811228112381124811258112681127811288112981130811318113281133811348113581136811378113881139811408114181142811438114481145811468114781148811498115081151811528115381154811558115681157811588115981160811618116281163811648116581166811678116881169811708117181172811738117481175811768117781178811798118081181811828118381184811858118681187811888118981190811918119281193811948119581196811978119881199812008120181202812038120481205812068120781208812098121081211812128121381214812158121681217812188121981220812218122281223812248122581226812278122881229812308123181232812338123481235812368123781238812398124081241812428124381244812458124681247812488124981250812518125281253812548125581256812578125881259812608126181262812638126481265812668126781268812698127081271812728127381274812758127681277812788127981280812818128281283812848128581286812878128881289812908129181292812938129481295812968129781298812998130081301813028130381304813058130681307813088130981310813118131281313813148131581316813178131881319813208132181322813238132481325813268132781328813298133081331813328133381334813358133681337813388133981340813418134281343813448134581346813478134881349813508135181352813538135481355813568135781358813598136081361813628136381364813658136681367813688136981370813718137281373813748137581376813778137881379813808138181382813838138481385813868138781388813898139081391813928139381394813958139681397813988139981400814018140281403814048140581406814078140881409814108141181412814138141481415814168141781418814198142081421814228142381424814258142681427814288142981430814318143281433814348143581436814378143881439814408144181442814438144481445814468144781448814498145081451814528145381454814558145681457814588145981460814618146281463814648146581466814678146881469814708147181472814738147481475814768147781478814798148081481814828148381484814858148681487814888148981490814918149281493814948149581496814978149881499815008150181502815038150481505815068150781508815098151081511815128151381514815158151681517815188151981520815218152281523815248152581526815278152881529815308153181532815338153481535815368153781538815398154081541815428154381544815458154681547815488154981550815518155281553815548155581556815578155881559815608156181562815638156481565815668156781568815698157081571815728157381574815758157681577815788157981580815818158281583815848158581586815878158881589815908159181592815938159481595815968159781598815998160081601816028160381604816058160681607816088160981610816118161281613816148161581616816178161881619816208162181622816238162481625816268162781628816298163081631816328163381634816358163681637816388163981640816418164281643816448164581646816478164881649816508165181652816538165481655816568165781658816598166081661816628166381664816658166681667816688166981670816718167281673816748167581676816778167881679816808168181682816838168481685816868168781688816898169081691816928169381694816958169681697816988169981700817018170281703817048170581706817078170881709817108171181712817138171481715817168171781718817198172081721817228172381724817258172681727817288172981730817318173281733817348173581736817378173881739817408174181742817438174481745817468174781748817498175081751817528175381754817558175681757817588175981760817618176281763817648176581766817678176881769817708177181772817738177481775817768177781778817798178081781817828178381784817858178681787817888178981790817918179281793817948179581796817978179881799818008180181802818038180481805818068180781808818098181081811818128181381814818158181681817818188181981820818218182281823818248182581826818278182881829818308183181832818338183481835818368183781838818398184081841818428184381844818458184681847818488184981850818518185281853818548185581856818578185881859818608186181862818638186481865818668186781868818698187081871818728187381874818758187681877818788187981880818818188281883818848188581886818878188881889818908189181892818938189481895818968189781898818998190081901819028190381904819058190681907819088190981910819118191281913819148191581916819178191881919819208192181922819238192481925819268192781928819298193081931819328193381934819358193681937819388193981940819418194281943819448194581946819478194881949819508195181952819538195481955819568195781958819598196081961819628196381964819658196681967819688196981970819718197281973819748197581976819778197881979819808198181982819838198481985819868198781988819898199081991819928199381994819958199681997819988199982000820018200282003820048200582006820078200882009820108201182012820138201482015820168201782018820198202082021820228202382024820258202682027820288202982030820318203282033820348203582036820378203882039820408204182042820438204482045820468204782048820498205082051820528205382054820558205682057820588205982060820618206282063820648206582066820678206882069820708207182072820738207482075820768207782078820798208082081820828208382084820858208682087820888208982090820918209282093820948209582096820978209882099821008210182102821038210482105821068210782108821098211082111821128211382114821158211682117821188211982120821218212282123821248212582126821278212882129821308213182132821338213482135821368213782138821398214082141821428214382144821458214682147821488214982150821518215282153821548215582156821578215882159821608216182162821638216482165821668216782168821698217082171821728217382174821758217682177821788217982180821818218282183821848218582186821878218882189821908219182192821938219482195821968219782198821998220082201822028220382204822058220682207822088220982210822118221282213822148221582216822178221882219822208222182222822238222482225822268222782228822298223082231822328223382234822358223682237822388223982240822418224282243822448224582246822478224882249822508225182252822538225482255822568225782258822598226082261822628226382264822658226682267822688226982270822718227282273822748227582276822778227882279822808228182282822838228482285822868228782288822898229082291822928229382294822958229682297822988229982300823018230282303823048230582306823078230882309823108231182312823138231482315823168231782318823198232082321823228232382324823258232682327823288232982330823318233282333823348233582336823378233882339823408234182342823438234482345823468234782348823498235082351823528235382354823558235682357823588235982360823618236282363823648236582366823678236882369823708237182372823738237482375823768237782378823798238082381823828238382384823858238682387823888238982390823918239282393823948239582396823978239882399824008240182402824038240482405824068240782408824098241082411824128241382414824158241682417824188241982420824218242282423824248242582426824278242882429824308243182432824338243482435824368243782438824398244082441824428244382444824458244682447824488244982450824518245282453824548245582456824578245882459824608246182462824638246482465824668246782468824698247082471824728247382474824758247682477824788247982480824818248282483824848248582486824878248882489824908249182492824938249482495824968249782498824998250082501825028250382504825058250682507825088250982510825118251282513825148251582516825178251882519825208252182522825238252482525825268252782528825298253082531825328253382534825358253682537825388253982540825418254282543825448254582546825478254882549825508255182552825538255482555825568255782558825598256082561825628256382564825658256682567825688256982570825718257282573825748257582576825778257882579825808258182582825838258482585825868258782588825898259082591825928259382594825958259682597825988259982600826018260282603826048260582606826078260882609826108261182612826138261482615826168261782618826198262082621826228262382624826258262682627826288262982630826318263282633826348263582636826378263882639826408264182642826438264482645826468264782648826498265082651826528265382654826558265682657826588265982660826618266282663826648266582666826678266882669826708267182672826738267482675826768267782678826798268082681826828268382684826858268682687826888268982690826918269282693826948269582696826978269882699827008270182702827038270482705827068270782708827098271082711827128271382714827158271682717827188271982720827218272282723827248272582726827278272882729827308273182732827338273482735827368273782738827398274082741827428274382744827458274682747827488274982750827518275282753827548275582756827578275882759827608276182762827638276482765827668276782768827698277082771827728277382774827758277682777827788277982780827818278282783827848278582786827878278882789827908279182792827938279482795827968279782798827998280082801828028280382804828058280682807828088280982810828118281282813828148281582816828178281882819828208282182822828238282482825828268282782828828298283082831828328283382834828358283682837828388283982840828418284282843828448284582846828478284882849828508285182852828538285482855828568285782858828598286082861828628286382864828658286682867828688286982870828718287282873828748287582876828778287882879828808288182882828838288482885828868288782888828898289082891828928289382894828958289682897828988289982900829018290282903829048290582906829078290882909829108291182912829138291482915829168291782918829198292082921829228292382924829258292682927829288292982930829318293282933829348293582936829378293882939829408294182942829438294482945829468294782948829498295082951829528295382954829558295682957829588295982960829618296282963829648296582966829678296882969829708297182972829738297482975829768297782978829798298082981829828298382984829858298682987829888298982990829918299282993829948299582996829978299882999830008300183002830038300483005830068300783008830098301083011830128301383014830158301683017830188301983020830218302283023830248302583026830278302883029830308303183032830338303483035830368303783038830398304083041830428304383044830458304683047830488304983050830518305283053830548305583056830578305883059830608306183062830638306483065830668306783068830698307083071830728307383074830758307683077830788307983080830818308283083830848308583086830878308883089830908309183092830938309483095830968309783098830998310083101831028310383104831058310683107831088310983110831118311283113831148311583116831178311883119831208312183122831238312483125831268312783128831298313083131831328313383134831358313683137831388313983140831418314283143831448314583146831478314883149831508315183152831538315483155831568315783158831598316083161831628316383164831658316683167831688316983170831718317283173831748317583176831778317883179831808318183182831838318483185831868318783188831898319083191831928319383194831958319683197831988319983200832018320283203832048320583206832078320883209832108321183212832138321483215832168321783218832198322083221832228322383224832258322683227832288322983230832318323283233832348323583236832378323883239832408324183242832438324483245832468324783248832498325083251832528325383254832558325683257832588325983260832618326283263832648326583266832678326883269832708327183272832738327483275832768327783278832798328083281832828328383284832858328683287832888328983290832918329283293832948329583296832978329883299833008330183302833038330483305833068330783308833098331083311833128331383314833158331683317833188331983320833218332283323833248332583326833278332883329833308333183332833338333483335833368333783338833398334083341833428334383344833458334683347833488334983350833518335283353833548335583356833578335883359833608336183362833638336483365833668336783368833698337083371833728337383374833758337683377833788337983380833818338283383833848338583386833878338883389833908339183392833938339483395833968339783398833998340083401834028340383404834058340683407834088340983410834118341283413834148341583416834178341883419834208342183422834238342483425834268342783428834298343083431834328343383434834358343683437834388343983440834418344283443834448344583446834478344883449834508345183452834538345483455834568345783458834598346083461834628346383464834658346683467834688346983470834718347283473834748347583476834778347883479834808348183482834838348483485834868348783488834898349083491834928349383494834958349683497834988349983500835018350283503835048350583506835078350883509835108351183512835138351483515835168351783518835198352083521835228352383524835258352683527835288352983530835318353283533835348353583536835378353883539835408354183542835438354483545835468354783548835498355083551835528355383554835558355683557835588355983560835618356283563835648356583566835678356883569835708357183572835738357483575835768357783578835798358083581835828358383584835858358683587835888358983590835918359283593835948359583596835978359883599836008360183602836038360483605836068360783608836098361083611836128361383614836158361683617836188361983620836218362283623836248362583626836278362883629836308363183632836338363483635836368363783638836398364083641836428364383644836458364683647836488364983650836518365283653836548365583656836578365883659836608366183662836638366483665836668366783668836698367083671836728367383674836758367683677836788367983680836818368283683836848368583686836878368883689836908369183692836938369483695836968369783698836998370083701837028370383704837058370683707837088370983710837118371283713837148371583716837178371883719837208372183722837238372483725837268372783728837298373083731837328373383734837358373683737837388373983740837418374283743837448374583746837478374883749837508375183752837538375483755837568375783758837598376083761837628376383764837658376683767837688376983770837718377283773837748377583776837778377883779837808378183782837838378483785837868378783788837898379083791837928379383794837958379683797837988379983800838018380283803838048380583806838078380883809838108381183812838138381483815838168381783818838198382083821838228382383824838258382683827838288382983830838318383283833838348383583836838378383883839838408384183842838438384483845838468384783848838498385083851838528385383854838558385683857838588385983860838618386283863838648386583866838678386883869838708387183872838738387483875838768387783878838798388083881838828388383884838858388683887838888388983890838918389283893838948389583896838978389883899839008390183902839038390483905839068390783908839098391083911839128391383914839158391683917839188391983920839218392283923839248392583926839278392883929839308393183932839338393483935839368393783938839398394083941839428394383944839458394683947839488394983950839518395283953839548395583956839578395883959839608396183962839638396483965839668396783968839698397083971839728397383974839758397683977839788397983980839818398283983839848398583986839878398883989839908399183992839938399483995839968399783998839998400084001840028400384004840058400684007840088400984010840118401284013840148401584016840178401884019840208402184022840238402484025840268402784028840298403084031840328403384034840358403684037840388403984040840418404284043840448404584046840478404884049840508405184052840538405484055840568405784058840598406084061840628406384064840658406684067840688406984070840718407284073840748407584076840778407884079840808408184082840838408484085840868408784088840898409084091840928409384094840958409684097840988409984100841018410284103841048410584106841078410884109841108411184112841138411484115841168411784118841198412084121841228412384124841258412684127841288412984130841318413284133841348413584136841378413884139841408414184142841438414484145841468414784148841498415084151841528415384154841558415684157841588415984160841618416284163841648416584166841678416884169841708417184172841738417484175841768417784178841798418084181841828418384184841858418684187841888418984190841918419284193841948419584196841978419884199842008420184202842038420484205842068420784208842098421084211842128421384214842158421684217842188421984220842218422284223842248422584226842278422884229842308423184232842338423484235842368423784238842398424084241842428424384244842458424684247842488424984250842518425284253842548425584256842578425884259842608426184262842638426484265842668426784268842698427084271842728427384274842758427684277842788427984280842818428284283842848428584286842878428884289842908429184292842938429484295842968429784298842998430084301843028430384304843058430684307843088430984310843118431284313843148431584316843178431884319843208432184322843238432484325843268432784328843298433084331843328433384334843358433684337843388433984340843418434284343843448434584346843478434884349843508435184352843538435484355843568435784358843598436084361843628436384364843658436684367843688436984370843718437284373843748437584376843778437884379843808438184382843838438484385843868438784388843898439084391843928439384394843958439684397843988439984400844018440284403844048440584406844078440884409844108441184412844138441484415844168441784418844198442084421844228442384424844258442684427844288442984430844318443284433844348443584436844378443884439844408444184442844438444484445844468444784448844498445084451844528445384454844558445684457844588445984460844618446284463844648446584466844678446884469844708447184472844738447484475844768447784478844798448084481844828448384484844858448684487844888448984490844918449284493844948449584496844978449884499845008450184502845038450484505845068450784508845098451084511845128451384514845158451684517845188451984520845218452284523845248452584526845278452884529845308453184532845338453484535845368453784538845398454084541845428454384544845458454684547845488454984550845518455284553845548455584556845578455884559845608456184562845638456484565845668456784568845698457084571845728457384574845758457684577845788457984580845818458284583845848458584586845878458884589845908459184592845938459484595845968459784598845998460084601846028460384604846058460684607846088460984610846118461284613846148461584616846178461884619846208462184622846238462484625846268462784628846298463084631846328463384634846358463684637846388463984640846418464284643846448464584646846478464884649846508465184652846538465484655846568465784658846598466084661846628466384664846658466684667846688466984670846718467284673846748467584676846778467884679846808468184682846838468484685846868468784688846898469084691846928469384694846958469684697846988469984700847018470284703847048470584706847078470884709847108471184712847138471484715847168471784718847198472084721847228472384724847258472684727847288472984730847318473284733847348473584736847378473884739847408474184742847438474484745847468474784748847498475084751847528475384754847558475684757847588475984760847618476284763847648476584766847678476884769847708477184772847738477484775847768477784778847798478084781847828478384784847858478684787847888478984790847918479284793847948479584796847978479884799848008480184802848038480484805848068480784808848098481084811848128481384814848158481684817848188481984820848218482284823848248482584826848278482884829848308483184832848338483484835848368483784838848398484084841848428484384844848458484684847848488484984850848518485284853848548485584856848578485884859848608486184862848638486484865848668486784868848698487084871848728487384874848758487684877848788487984880848818488284883848848488584886848878488884889848908489184892848938489484895848968489784898848998490084901849028490384904849058490684907849088490984910849118491284913849148491584916849178491884919849208492184922849238492484925849268492784928849298493084931849328493384934849358493684937849388493984940849418494284943849448494584946849478494884949849508495184952849538495484955849568495784958849598496084961849628496384964849658496684967849688496984970849718497284973849748497584976849778497884979849808498184982849838498484985849868498784988849898499084991849928499384994849958499684997849988499985000850018500285003850048500585006850078500885009850108501185012850138501485015850168501785018850198502085021850228502385024850258502685027850288502985030850318503285033850348503585036850378503885039850408504185042850438504485045850468504785048850498505085051850528505385054850558505685057850588505985060850618506285063850648506585066850678506885069850708507185072850738507485075850768507785078850798508085081850828508385084850858508685087850888508985090850918509285093850948509585096850978509885099851008510185102851038510485105851068510785108851098511085111851128511385114851158511685117851188511985120851218512285123851248512585126851278512885129851308513185132851338513485135851368513785138851398514085141851428514385144851458514685147851488514985150851518515285153851548515585156851578515885159851608516185162851638516485165851668516785168851698517085171851728517385174851758517685177851788517985180851818518285183851848518585186851878518885189851908519185192851938519485195851968519785198851998520085201852028520385204852058520685207852088520985210852118521285213852148521585216852178521885219852208522185222852238522485225852268522785228852298523085231852328523385234852358523685237852388523985240852418524285243852448524585246852478524885249852508525185252852538525485255852568525785258852598526085261852628526385264852658526685267852688526985270852718527285273852748527585276852778527885279852808528185282852838528485285852868528785288852898529085291852928529385294852958529685297852988529985300853018530285303853048530585306853078530885309853108531185312853138531485315853168531785318853198532085321853228532385324853258532685327853288532985330853318533285333853348533585336853378533885339853408534185342853438534485345853468534785348853498535085351853528535385354853558535685357853588535985360853618536285363853648536585366853678536885369853708537185372853738537485375853768537785378853798538085381853828538385384853858538685387853888538985390853918539285393853948539585396853978539885399854008540185402854038540485405854068540785408854098541085411854128541385414854158541685417854188541985420854218542285423854248542585426854278542885429854308543185432854338543485435854368543785438854398544085441854428544385444854458544685447854488544985450854518545285453854548545585456854578545885459854608546185462854638546485465854668546785468854698547085471854728547385474854758547685477854788547985480854818548285483854848548585486854878548885489854908549185492854938549485495854968549785498854998550085501855028550385504855058550685507855088550985510855118551285513855148551585516855178551885519855208552185522855238552485525855268552785528855298553085531855328553385534855358553685537855388553985540855418554285543855448554585546855478554885549855508555185552855538555485555855568555785558855598556085561855628556385564855658556685567855688556985570855718557285573855748557585576855778557885579855808558185582855838558485585855868558785588855898559085591855928559385594855958559685597855988559985600856018560285603856048560585606856078560885609856108561185612856138561485615856168561785618856198562085621856228562385624856258562685627856288562985630856318563285633856348563585636856378563885639856408564185642856438564485645856468564785648856498565085651856528565385654856558565685657856588565985660856618566285663856648566585666856678566885669856708567185672856738567485675856768567785678856798568085681856828568385684856858568685687856888568985690856918569285693856948569585696856978569885699857008570185702857038570485705857068570785708857098571085711857128571385714857158571685717857188571985720857218572285723857248572585726857278572885729857308573185732857338573485735857368573785738857398574085741857428574385744857458574685747857488574985750857518575285753857548575585756857578575885759857608576185762857638576485765857668576785768857698577085771857728577385774857758577685777857788577985780857818578285783857848578585786857878578885789857908579185792857938579485795857968579785798857998580085801858028580385804858058580685807858088580985810858118581285813858148581585816858178581885819858208582185822858238582485825858268582785828858298583085831858328583385834858358583685837858388583985840858418584285843858448584585846858478584885849858508585185852858538585485855858568585785858858598586085861858628586385864858658586685867858688586985870858718587285873858748587585876858778587885879858808588185882858838588485885858868588785888858898589085891858928589385894858958589685897858988589985900859018590285903859048590585906859078590885909859108591185912859138591485915859168591785918859198592085921859228592385924859258592685927859288592985930859318593285933859348593585936859378593885939859408594185942859438594485945859468594785948859498595085951859528595385954859558595685957859588595985960859618596285963859648596585966859678596885969859708597185972859738597485975859768597785978859798598085981859828598385984859858598685987859888598985990859918599285993859948599585996859978599885999860008600186002860038600486005860068600786008860098601086011860128601386014860158601686017860188601986020860218602286023860248602586026860278602886029860308603186032860338603486035860368603786038860398604086041860428604386044860458604686047860488604986050860518605286053860548605586056860578605886059860608606186062860638606486065860668606786068860698607086071860728607386074860758607686077860788607986080860818608286083860848608586086860878608886089860908609186092860938609486095860968609786098860998610086101861028610386104861058610686107861088610986110861118611286113861148611586116861178611886119861208612186122861238612486125861268612786128861298613086131861328613386134861358613686137861388613986140861418614286143861448614586146861478614886149861508615186152861538615486155861568615786158861598616086161861628616386164861658616686167861688616986170861718617286173861748617586176861778617886179861808618186182861838618486185861868618786188861898619086191861928619386194861958619686197861988619986200862018620286203862048620586206862078620886209862108621186212862138621486215862168621786218862198622086221862228622386224862258622686227862288622986230862318623286233862348623586236862378623886239862408624186242862438624486245862468624786248862498625086251862528625386254862558625686257862588625986260862618626286263862648626586266862678626886269862708627186272862738627486275862768627786278862798628086281862828628386284862858628686287862888628986290862918629286293862948629586296862978629886299863008630186302863038630486305863068630786308863098631086311863128631386314863158631686317863188631986320863218632286323863248632586326863278632886329863308633186332863338633486335863368633786338863398634086341863428634386344863458634686347863488634986350863518635286353863548635586356863578635886359863608636186362863638636486365863668636786368863698637086371863728637386374863758637686377863788637986380863818638286383863848638586386863878638886389863908639186392863938639486395863968639786398863998640086401864028640386404864058640686407864088640986410864118641286413864148641586416864178641886419864208642186422864238642486425864268642786428864298643086431864328643386434864358643686437864388643986440864418644286443864448644586446864478644886449864508645186452864538645486455864568645786458864598646086461864628646386464864658646686467864688646986470864718647286473864748647586476864778647886479864808648186482864838648486485864868648786488864898649086491864928649386494864958649686497864988649986500865018650286503865048650586506865078650886509865108651186512865138651486515865168651786518865198652086521865228652386524865258652686527865288652986530865318653286533865348653586536865378653886539865408654186542865438654486545865468654786548865498655086551865528655386554865558655686557865588655986560865618656286563865648656586566865678656886569865708657186572865738657486575865768657786578865798658086581865828658386584865858658686587865888658986590865918659286593865948659586596865978659886599866008660186602866038660486605866068660786608866098661086611866128661386614866158661686617866188661986620866218662286623866248662586626866278662886629866308663186632866338663486635866368663786638866398664086641866428664386644866458664686647866488664986650866518665286653866548665586656866578665886659866608666186662866638666486665866668666786668866698667086671866728667386674866758667686677866788667986680866818668286683866848668586686866878668886689866908669186692866938669486695866968669786698866998670086701867028670386704867058670686707867088670986710867118671286713867148671586716867178671886719867208672186722867238672486725867268672786728867298673086731867328673386734867358673686737867388673986740867418674286743867448674586746867478674886749867508675186752867538675486755867568675786758867598676086761867628676386764867658676686767867688676986770867718677286773867748677586776867778677886779867808678186782867838678486785867868678786788867898679086791867928679386794867958679686797867988679986800868018680286803868048680586806868078680886809868108681186812868138681486815868168681786818868198682086821868228682386824868258682686827868288682986830868318683286833868348683586836868378683886839868408684186842868438684486845868468684786848868498685086851868528685386854868558685686857868588685986860868618686286863868648686586866868678686886869868708687186872868738687486875868768687786878868798688086881868828688386884868858688686887868888688986890868918689286893868948689586896868978689886899869008690186902869038690486905869068690786908869098691086911869128691386914869158691686917869188691986920869218692286923869248692586926869278692886929869308693186932869338693486935869368693786938869398694086941869428694386944869458694686947869488694986950869518695286953869548695586956869578695886959869608696186962869638696486965869668696786968869698697086971869728697386974869758697686977869788697986980869818698286983869848698586986869878698886989869908699186992869938699486995869968699786998869998700087001870028700387004870058700687007870088700987010870118701287013870148701587016870178701887019870208702187022870238702487025870268702787028870298703087031870328703387034870358703687037870388703987040870418704287043870448704587046870478704887049870508705187052870538705487055870568705787058870598706087061870628706387064870658706687067870688706987070870718707287073870748707587076870778707887079870808708187082870838708487085870868708787088870898709087091870928709387094870958709687097870988709987100871018710287103871048710587106871078710887109871108711187112871138711487115871168711787118871198712087121871228712387124871258712687127871288712987130871318713287133871348713587136871378713887139871408714187142871438714487145871468714787148871498715087151871528715387154871558715687157871588715987160871618716287163871648716587166871678716887169871708717187172871738717487175871768717787178871798718087181871828718387184871858718687187871888718987190871918719287193871948719587196871978719887199872008720187202872038720487205872068720787208872098721087211872128721387214872158721687217872188721987220872218722287223872248722587226872278722887229872308723187232872338723487235872368723787238872398724087241872428724387244872458724687247872488724987250872518725287253872548725587256872578725887259872608726187262872638726487265872668726787268872698727087271872728727387274872758727687277872788727987280872818728287283872848728587286872878728887289872908729187292872938729487295872968729787298872998730087301873028730387304873058730687307873088730987310873118731287313873148731587316873178731887319873208732187322873238732487325873268732787328873298733087331873328733387334873358733687337873388733987340873418734287343873448734587346873478734887349873508735187352873538735487355873568735787358873598736087361873628736387364873658736687367873688736987370873718737287373873748737587376873778737887379873808738187382873838738487385873868738787388873898739087391873928739387394873958739687397873988739987400874018740287403874048740587406874078740887409874108741187412874138741487415874168741787418874198742087421874228742387424874258742687427874288742987430874318743287433874348743587436874378743887439874408744187442874438744487445874468744787448874498745087451874528745387454874558745687457874588745987460874618746287463874648746587466874678746887469874708747187472874738747487475874768747787478874798748087481874828748387484874858748687487874888748987490874918749287493874948749587496874978749887499875008750187502875038750487505875068750787508875098751087511875128751387514875158751687517875188751987520875218752287523875248752587526875278752887529875308753187532875338753487535875368753787538875398754087541875428754387544875458754687547875488754987550875518755287553875548755587556875578755887559875608756187562875638756487565875668756787568875698757087571875728757387574875758757687577875788757987580875818758287583875848758587586875878758887589875908759187592875938759487595875968759787598875998760087601876028760387604876058760687607876088760987610876118761287613876148761587616876178761887619876208762187622876238762487625876268762787628876298763087631876328763387634876358763687637876388763987640876418764287643876448764587646876478764887649876508765187652876538765487655876568765787658876598766087661876628766387664876658766687667876688766987670876718767287673876748767587676876778767887679876808768187682876838768487685876868768787688876898769087691876928769387694876958769687697876988769987700877018770287703877048770587706877078770887709877108771187712877138771487715877168771787718877198772087721877228772387724877258772687727877288772987730877318773287733877348773587736877378773887739877408774187742877438774487745877468774787748877498775087751877528775387754877558775687757877588775987760877618776287763877648776587766877678776887769877708777187772877738777487775877768777787778877798778087781877828778387784877858778687787877888778987790877918779287793877948779587796877978779887799878008780187802878038780487805878068780787808878098781087811878128781387814878158781687817878188781987820878218782287823878248782587826878278782887829878308783187832878338783487835878368783787838878398784087841878428784387844878458784687847878488784987850878518785287853878548785587856878578785887859878608786187862878638786487865878668786787868878698787087871878728787387874878758787687877878788787987880878818788287883878848788587886878878788887889878908789187892878938789487895878968789787898878998790087901879028790387904879058790687907879088790987910879118791287913879148791587916879178791887919879208792187922879238792487925879268792787928879298793087931879328793387934879358793687937879388793987940879418794287943879448794587946879478794887949879508795187952879538795487955879568795787958879598796087961879628796387964879658796687967879688796987970879718797287973879748797587976879778797887979879808798187982879838798487985879868798787988879898799087991879928799387994879958799687997879988799988000880018800288003880048800588006880078800888009880108801188012880138801488015880168801788018880198802088021880228802388024880258802688027880288802988030880318803288033880348803588036880378803888039880408804188042880438804488045880468804788048880498805088051880528805388054880558805688057880588805988060880618806288063880648806588066880678806888069880708807188072880738807488075880768807788078880798808088081880828808388084880858808688087880888808988090880918809288093880948809588096880978809888099881008810188102881038810488105881068810788108881098811088111881128811388114881158811688117881188811988120881218812288123881248812588126881278812888129881308813188132881338813488135881368813788138881398814088141881428814388144881458814688147881488814988150881518815288153881548815588156881578815888159881608816188162881638816488165881668816788168881698817088171881728817388174881758817688177881788817988180881818818288183881848818588186881878818888189881908819188192881938819488195881968819788198881998820088201882028820388204882058820688207882088820988210882118821288213882148821588216882178821888219882208822188222882238822488225882268822788228882298823088231882328823388234882358823688237882388823988240882418824288243882448824588246882478824888249882508825188252882538825488255882568825788258882598826088261882628826388264882658826688267882688826988270882718827288273882748827588276882778827888279882808828188282882838828488285882868828788288882898829088291882928829388294882958829688297882988829988300883018830288303883048830588306883078830888309883108831188312883138831488315883168831788318883198832088321883228832388324883258832688327883288832988330883318833288333883348833588336883378833888339883408834188342883438834488345883468834788348883498835088351883528835388354883558835688357883588835988360883618836288363883648836588366883678836888369883708837188372883738837488375883768837788378883798838088381883828838388384883858838688387883888838988390883918839288393883948839588396883978839888399884008840188402884038840488405884068840788408884098841088411884128841388414884158841688417884188841988420884218842288423884248842588426884278842888429884308843188432884338843488435884368843788438884398844088441884428844388444884458844688447884488844988450884518845288453884548845588456884578845888459884608846188462884638846488465884668846788468884698847088471884728847388474884758847688477884788847988480884818848288483884848848588486884878848888489884908849188492884938849488495884968849788498884998850088501885028850388504885058850688507885088850988510885118851288513885148851588516885178851888519885208852188522885238852488525885268852788528885298853088531885328853388534885358853688537885388853988540885418854288543885448854588546885478854888549885508855188552885538855488555885568855788558885598856088561885628856388564885658856688567885688856988570885718857288573885748857588576885778857888579885808858188582885838858488585885868858788588885898859088591885928859388594885958859688597885988859988600886018860288603886048860588606886078860888609886108861188612886138861488615886168861788618886198862088621886228862388624886258862688627886288862988630886318863288633886348863588636886378863888639886408864188642886438864488645886468864788648886498865088651886528865388654886558865688657886588865988660886618866288663886648866588666886678866888669886708867188672886738867488675886768867788678886798868088681886828868388684886858868688687886888868988690886918869288693886948869588696886978869888699887008870188702887038870488705887068870788708887098871088711887128871388714887158871688717887188871988720887218872288723887248872588726887278872888729887308873188732887338873488735887368873788738887398874088741887428874388744887458874688747887488874988750887518875288753887548875588756887578875888759887608876188762887638876488765887668876788768887698877088771887728877388774887758877688777887788877988780887818878288783887848878588786887878878888789887908879188792887938879488795887968879788798887998880088801888028880388804888058880688807888088880988810888118881288813888148881588816888178881888819888208882188822888238882488825888268882788828888298883088831888328883388834888358883688837888388883988840888418884288843888448884588846888478884888849888508885188852888538885488855888568885788858888598886088861888628886388864888658886688867888688886988870888718887288873888748887588876888778887888879888808888188882888838888488885888868888788888888898889088891888928889388894888958889688897888988889988900889018890288903889048890588906889078890888909889108891188912889138891488915889168891788918889198892088921889228892388924889258892688927889288892988930889318893288933889348893588936889378893888939889408894188942889438894488945889468894788948889498895088951889528895388954889558895688957889588895988960889618896288963889648896588966889678896888969889708897188972889738897488975889768897788978889798898088981889828898388984889858898688987889888898988990889918899288993889948899588996889978899888999890008900189002890038900489005890068900789008890098901089011890128901389014890158901689017890188901989020890218902289023890248902589026890278902889029890308903189032890338903489035890368903789038890398904089041890428904389044890458904689047890488904989050890518905289053890548905589056890578905889059890608906189062890638906489065890668906789068890698907089071890728907389074890758907689077890788907989080890818908289083890848908589086890878908889089890908909189092890938909489095890968909789098890998910089101891028910389104891058910689107891088910989110891118911289113891148911589116891178911889119891208912189122891238912489125891268912789128891298913089131891328913389134891358913689137891388913989140891418914289143891448914589146891478914889149891508915189152891538915489155891568915789158891598916089161891628916389164891658916689167891688916989170891718917289173891748917589176891778917889179891808918189182891838918489185891868918789188891898919089191891928919389194891958919689197891988919989200892018920289203892048920589206892078920889209892108921189212892138921489215892168921789218892198922089221892228922389224892258922689227892288922989230892318923289233892348923589236892378923889239892408924189242892438924489245892468924789248892498925089251892528925389254892558925689257892588925989260892618926289263892648926589266892678926889269892708927189272892738927489275892768927789278892798928089281892828928389284892858928689287892888928989290892918929289293892948929589296892978929889299893008930189302893038930489305893068930789308893098931089311893128931389314893158931689317893188931989320893218932289323893248932589326893278932889329893308933189332893338933489335893368933789338893398934089341893428934389344893458934689347893488934989350893518935289353893548935589356893578935889359893608936189362893638936489365893668936789368893698937089371893728937389374893758937689377893788937989380893818938289383893848938589386893878938889389893908939189392893938939489395893968939789398893998940089401894028940389404894058940689407894088940989410894118941289413894148941589416894178941889419894208942189422894238942489425894268942789428894298943089431894328943389434894358943689437894388943989440894418944289443894448944589446894478944889449894508945189452894538945489455894568945789458894598946089461894628946389464894658946689467894688946989470894718947289473894748947589476894778947889479894808948189482894838948489485894868948789488894898949089491894928949389494894958949689497894988949989500895018950289503895048950589506895078950889509895108951189512895138951489515895168951789518895198952089521895228952389524895258952689527895288952989530895318953289533895348953589536895378953889539895408954189542895438954489545895468954789548895498955089551895528955389554895558955689557895588955989560895618956289563895648956589566895678956889569895708957189572895738957489575895768957789578895798958089581895828958389584895858958689587895888958989590895918959289593895948959589596895978959889599896008960189602896038960489605896068960789608896098961089611896128961389614896158961689617896188961989620896218962289623896248962589626896278962889629896308963189632896338963489635896368963789638896398964089641896428964389644896458964689647896488964989650896518965289653896548965589656896578965889659896608966189662896638966489665896668966789668896698967089671896728967389674896758967689677896788967989680896818968289683896848968589686896878968889689896908969189692896938969489695896968969789698896998970089701897028970389704897058970689707897088970989710897118971289713897148971589716897178971889719897208972189722897238972489725897268972789728897298973089731897328973389734897358973689737897388973989740897418974289743897448974589746897478974889749897508975189752897538975489755897568975789758897598976089761897628976389764897658976689767897688976989770897718977289773897748977589776897778977889779897808978189782897838978489785897868978789788897898979089791897928979389794897958979689797897988979989800898018980289803898048980589806898078980889809898108981189812898138981489815898168981789818898198982089821898228982389824898258982689827898288982989830898318983289833898348983589836898378983889839898408984189842898438984489845898468984789848898498985089851898528985389854898558985689857898588985989860898618986289863898648986589866898678986889869898708987189872898738987489875898768987789878898798988089881898828988389884898858988689887898888988989890898918989289893898948989589896898978989889899899008990189902899038990489905899068990789908899098991089911899128991389914899158991689917899188991989920899218992289923899248992589926899278992889929899308993189932899338993489935899368993789938899398994089941899428994389944899458994689947899488994989950899518995289953899548995589956899578995889959899608996189962899638996489965899668996789968899698997089971899728997389974899758997689977899788997989980899818998289983899848998589986899878998889989899908999189992899938999489995899968999789998899999000090001900029000390004900059000690007900089000990010900119001290013900149001590016900179001890019900209002190022900239002490025900269002790028900299003090031900329003390034900359003690037900389003990040900419004290043900449004590046900479004890049900509005190052900539005490055900569005790058900599006090061900629006390064900659006690067900689006990070900719007290073900749007590076900779007890079900809008190082900839008490085900869008790088900899009090091900929009390094900959009690097900989009990100901019010290103901049010590106901079010890109901109011190112901139011490115901169011790118901199012090121901229012390124901259012690127901289012990130901319013290133901349013590136901379013890139901409014190142901439014490145901469014790148901499015090151901529015390154901559015690157901589015990160901619016290163901649016590166901679016890169901709017190172901739017490175901769017790178901799018090181901829018390184901859018690187901889018990190901919019290193901949019590196901979019890199902009020190202902039020490205902069020790208902099021090211902129021390214902159021690217902189021990220902219022290223902249022590226902279022890229902309023190232902339023490235902369023790238902399024090241902429024390244902459024690247902489024990250902519025290253902549025590256902579025890259902609026190262902639026490265902669026790268902699027090271902729027390274902759027690277902789027990280902819028290283902849028590286902879028890289902909029190292902939029490295902969029790298902999030090301903029030390304903059030690307903089030990310903119031290313903149031590316903179031890319903209032190322903239032490325903269032790328903299033090331903329033390334903359033690337903389033990340903419034290343903449034590346903479034890349903509035190352903539035490355903569035790358903599036090361903629036390364903659036690367903689036990370903719037290373903749037590376903779037890379903809038190382903839038490385903869038790388903899039090391903929039390394903959039690397903989039990400904019040290403904049040590406904079040890409904109041190412904139041490415904169041790418904199042090421904229042390424904259042690427904289042990430904319043290433904349043590436904379043890439904409044190442904439044490445904469044790448904499045090451904529045390454904559045690457904589045990460904619046290463904649046590466904679046890469904709047190472904739047490475904769047790478904799048090481904829048390484904859048690487904889048990490904919049290493904949049590496904979049890499905009050190502905039050490505905069050790508905099051090511905129051390514905159051690517905189051990520905219052290523905249052590526905279052890529905309053190532905339053490535905369053790538905399054090541905429054390544905459054690547905489054990550905519055290553905549055590556905579055890559905609056190562905639056490565905669056790568905699057090571905729057390574905759057690577905789057990580905819058290583905849058590586905879058890589905909059190592905939059490595905969059790598905999060090601906029060390604906059060690607906089060990610906119061290613906149061590616906179061890619906209062190622906239062490625906269062790628906299063090631906329063390634906359063690637906389063990640906419064290643906449064590646906479064890649906509065190652906539065490655906569065790658906599066090661906629066390664906659066690667906689066990670906719067290673906749067590676906779067890679906809068190682906839068490685906869068790688906899069090691906929069390694906959069690697906989069990700907019070290703907049070590706907079070890709907109071190712907139071490715907169071790718907199072090721907229072390724907259072690727907289072990730907319073290733907349073590736907379073890739907409074190742907439074490745907469074790748907499075090751907529075390754907559075690757907589075990760907619076290763907649076590766907679076890769907709077190772907739077490775907769077790778907799078090781907829078390784907859078690787907889078990790907919079290793907949079590796907979079890799908009080190802908039080490805908069080790808908099081090811908129081390814908159081690817908189081990820908219082290823908249082590826908279082890829908309083190832908339083490835908369083790838908399084090841908429084390844908459084690847908489084990850908519085290853908549085590856908579085890859908609086190862908639086490865908669086790868908699087090871908729087390874908759087690877908789087990880908819088290883908849088590886908879088890889908909089190892908939089490895908969089790898908999090090901909029090390904909059090690907909089090990910909119091290913909149091590916909179091890919909209092190922909239092490925909269092790928909299093090931909329093390934909359093690937909389093990940909419094290943909449094590946909479094890949909509095190952909539095490955909569095790958909599096090961909629096390964909659096690967909689096990970909719097290973909749097590976909779097890979909809098190982909839098490985909869098790988909899099090991909929099390994909959099690997909989099991000910019100291003910049100591006910079100891009910109101191012910139101491015910169101791018910199102091021910229102391024910259102691027910289102991030910319103291033910349103591036910379103891039910409104191042910439104491045910469104791048910499105091051910529105391054910559105691057910589105991060910619106291063910649106591066910679106891069910709107191072910739107491075910769107791078910799108091081910829108391084910859108691087910889108991090910919109291093910949109591096910979109891099911009110191102911039110491105911069110791108911099111091111911129111391114911159111691117911189111991120911219112291123911249112591126911279112891129911309113191132911339113491135911369113791138911399114091141911429114391144911459114691147911489114991150911519115291153911549115591156911579115891159911609116191162911639116491165911669116791168911699117091171911729117391174911759117691177911789117991180911819118291183911849118591186911879118891189911909119191192911939119491195911969119791198911999120091201912029120391204912059120691207912089120991210912119121291213912149121591216912179121891219912209122191222912239122491225912269122791228912299123091231912329123391234912359123691237912389123991240912419124291243912449124591246912479124891249912509125191252912539125491255912569125791258912599126091261912629126391264912659126691267912689126991270912719127291273912749127591276912779127891279912809128191282912839128491285912869128791288912899129091291912929129391294912959129691297912989129991300913019130291303913049130591306913079130891309913109131191312913139131491315913169131791318913199132091321913229132391324913259132691327913289132991330913319133291333913349133591336913379133891339913409134191342913439134491345913469134791348913499135091351913529135391354913559135691357913589135991360913619136291363913649136591366913679136891369913709137191372913739137491375913769137791378913799138091381913829138391384913859138691387913889138991390913919139291393913949139591396913979139891399914009140191402914039140491405914069140791408914099141091411914129141391414914159141691417914189141991420914219142291423914249142591426914279142891429914309143191432914339143491435914369143791438914399144091441914429144391444914459144691447914489144991450914519145291453914549145591456914579145891459914609146191462914639146491465914669146791468914699147091471914729147391474914759147691477914789147991480914819148291483914849148591486914879148891489914909149191492914939149491495914969149791498914999150091501915029150391504915059150691507915089150991510915119151291513915149151591516915179151891519915209152191522915239152491525915269152791528915299153091531915329153391534915359153691537915389153991540915419154291543915449154591546915479154891549915509155191552915539155491555915569155791558915599156091561915629156391564915659156691567915689156991570915719157291573915749157591576915779157891579915809158191582915839158491585915869158791588915899159091591915929159391594915959159691597915989159991600916019160291603916049160591606916079160891609916109161191612916139161491615916169161791618916199162091621916229162391624916259162691627916289162991630916319163291633916349163591636916379163891639916409164191642916439164491645916469164791648916499165091651916529165391654916559165691657916589165991660916619166291663916649166591666916679166891669916709167191672916739167491675916769167791678916799168091681916829168391684916859168691687916889168991690916919169291693916949169591696916979169891699917009170191702917039170491705917069170791708917099171091711917129171391714917159171691717917189171991720917219172291723917249172591726917279172891729917309173191732917339173491735917369173791738917399174091741917429174391744917459174691747917489174991750917519175291753917549175591756917579175891759917609176191762917639176491765917669176791768917699177091771917729177391774917759177691777917789177991780917819178291783917849178591786917879178891789917909179191792917939179491795917969179791798917999180091801918029180391804918059180691807918089180991810918119181291813918149181591816918179181891819918209182191822918239182491825918269182791828918299183091831918329183391834918359183691837918389183991840918419184291843918449184591846918479184891849918509185191852918539185491855918569185791858918599186091861918629186391864918659186691867918689186991870918719187291873918749187591876918779187891879918809188191882918839188491885918869188791888918899189091891918929189391894918959189691897918989189991900919019190291903919049190591906919079190891909919109191191912919139191491915919169191791918919199192091921919229192391924919259192691927919289192991930919319193291933919349193591936919379193891939919409194191942919439194491945919469194791948919499195091951919529195391954919559195691957919589195991960919619196291963919649196591966919679196891969919709197191972919739197491975919769197791978919799198091981919829198391984919859198691987919889198991990919919199291993919949199591996919979199891999920009200192002920039200492005920069200792008920099201092011920129201392014920159201692017920189201992020920219202292023920249202592026920279202892029920309203192032920339203492035920369203792038920399204092041920429204392044920459204692047920489204992050920519205292053920549205592056920579205892059920609206192062920639206492065920669206792068920699207092071920729207392074920759207692077920789207992080920819208292083920849208592086920879208892089920909209192092920939209492095920969209792098920999210092101921029210392104921059210692107921089210992110921119211292113921149211592116921179211892119921209212192122921239212492125921269212792128921299213092131921329213392134921359213692137921389213992140921419214292143921449214592146921479214892149921509215192152921539215492155921569215792158921599216092161921629216392164921659216692167921689216992170921719217292173921749217592176921779217892179921809218192182921839218492185921869218792188921899219092191921929219392194921959219692197921989219992200922019220292203922049220592206922079220892209922109221192212922139221492215922169221792218922199222092221922229222392224922259222692227922289222992230922319223292233922349223592236922379223892239922409224192242922439224492245922469224792248922499225092251922529225392254922559225692257922589225992260922619226292263922649226592266922679226892269922709227192272922739227492275922769227792278922799228092281922829228392284922859228692287922889228992290922919229292293922949229592296922979229892299923009230192302923039230492305923069230792308923099231092311923129231392314923159231692317923189231992320923219232292323923249232592326923279232892329923309233192332923339233492335923369233792338923399234092341923429234392344923459234692347923489234992350923519235292353923549235592356923579235892359923609236192362923639236492365923669236792368923699237092371923729237392374923759237692377923789237992380923819238292383923849238592386923879238892389923909239192392923939239492395923969239792398923999240092401924029240392404924059240692407924089240992410924119241292413924149241592416924179241892419924209242192422924239242492425924269242792428924299243092431924329243392434924359243692437924389243992440924419244292443924449244592446924479244892449924509245192452924539245492455924569245792458924599246092461924629246392464924659246692467924689246992470924719247292473924749247592476924779247892479924809248192482924839248492485924869248792488924899249092491924929249392494924959249692497924989249992500925019250292503925049250592506925079250892509925109251192512925139251492515925169251792518925199252092521925229252392524925259252692527925289252992530925319253292533925349253592536925379253892539925409254192542925439254492545925469254792548925499255092551925529255392554925559255692557925589255992560925619256292563925649256592566925679256892569925709257192572925739257492575925769257792578925799258092581925829258392584925859258692587925889258992590925919259292593925949259592596925979259892599926009260192602926039260492605926069260792608926099261092611926129261392614926159261692617926189261992620926219262292623926249262592626926279262892629926309263192632926339263492635926369263792638926399264092641926429264392644926459264692647926489264992650926519265292653926549265592656926579265892659926609266192662926639266492665926669266792668926699267092671926729267392674926759267692677926789267992680926819268292683926849268592686926879268892689926909269192692926939269492695926969269792698926999270092701927029270392704927059270692707927089270992710927119271292713927149271592716927179271892719927209272192722927239272492725927269272792728927299273092731927329273392734927359273692737927389273992740927419274292743927449274592746927479274892749927509275192752927539275492755927569275792758927599276092761927629276392764927659276692767927689276992770927719277292773927749277592776927779277892779927809278192782927839278492785927869278792788927899279092791927929279392794927959279692797927989279992800928019280292803928049280592806928079280892809928109281192812928139281492815928169281792818928199282092821928229282392824928259282692827928289282992830928319283292833928349283592836928379283892839928409284192842928439284492845928469284792848928499285092851928529285392854928559285692857928589285992860928619286292863928649286592866928679286892869928709287192872928739287492875928769287792878928799288092881928829288392884928859288692887928889288992890928919289292893928949289592896928979289892899929009290192902929039290492905929069290792908929099291092911929129291392914929159291692917929189291992920929219292292923929249292592926929279292892929929309293192932929339293492935929369293792938929399294092941929429294392944929459294692947929489294992950929519295292953929549295592956929579295892959929609296192962929639296492965929669296792968929699297092971929729297392974929759297692977929789297992980929819298292983929849298592986929879298892989929909299192992929939299492995929969299792998929999300093001930029300393004930059300693007930089300993010930119301293013930149301593016930179301893019930209302193022930239302493025930269302793028930299303093031930329303393034930359303693037930389303993040930419304293043930449304593046930479304893049930509305193052930539305493055930569305793058930599306093061930629306393064930659306693067930689306993070930719307293073930749307593076930779307893079930809308193082930839308493085930869308793088930899309093091930929309393094930959309693097930989309993100931019310293103931049310593106931079310893109931109311193112931139311493115931169311793118931199312093121931229312393124931259312693127931289312993130931319313293133931349313593136931379313893139931409314193142931439314493145931469314793148931499315093151931529315393154931559315693157931589315993160931619316293163931649316593166931679316893169931709317193172931739317493175931769317793178931799318093181931829318393184931859318693187931889318993190931919319293193931949319593196931979319893199932009320193202932039320493205932069320793208932099321093211932129321393214932159321693217932189321993220932219322293223932249322593226932279322893229932309323193232932339323493235932369323793238932399324093241932429324393244932459324693247932489324993250932519325293253932549325593256932579325893259932609326193262932639326493265932669326793268932699327093271932729327393274932759327693277932789327993280932819328293283932849328593286932879328893289932909329193292932939329493295932969329793298932999330093301933029330393304933059330693307933089330993310933119331293313933149331593316933179331893319933209332193322933239332493325933269332793328933299333093331933329333393334933359333693337933389333993340933419334293343933449334593346933479334893349933509335193352933539335493355933569335793358933599336093361933629336393364933659336693367933689336993370933719337293373933749337593376933779337893379933809338193382933839338493385933869338793388933899339093391933929339393394933959339693397933989339993400934019340293403934049340593406934079340893409934109341193412934139341493415934169341793418934199342093421934229342393424934259342693427934289342993430934319343293433934349343593436934379343893439934409344193442934439344493445934469344793448934499345093451934529345393454934559345693457934589345993460934619346293463934649346593466934679346893469934709347193472934739347493475934769347793478934799348093481934829348393484934859348693487934889348993490934919349293493934949349593496934979349893499935009350193502935039350493505935069350793508935099351093511935129351393514935159351693517935189351993520935219352293523935249352593526935279352893529935309353193532935339353493535935369353793538935399354093541935429354393544935459354693547935489354993550935519355293553935549355593556935579355893559935609356193562935639356493565935669356793568935699357093571935729357393574935759357693577935789357993580935819358293583935849358593586935879358893589935909359193592935939359493595935969359793598935999360093601936029360393604936059360693607936089360993610936119361293613936149361593616936179361893619936209362193622936239362493625936269362793628936299363093631936329363393634936359363693637936389363993640936419364293643936449364593646936479364893649936509365193652936539365493655936569365793658936599366093661936629366393664936659366693667936689366993670936719367293673936749367593676936779367893679936809368193682936839368493685936869368793688936899369093691936929369393694936959369693697936989369993700937019370293703937049370593706937079370893709937109371193712937139371493715937169371793718937199372093721937229372393724937259372693727937289372993730937319373293733937349373593736937379373893739937409374193742937439374493745937469374793748937499375093751937529375393754937559375693757937589375993760937619376293763937649376593766937679376893769937709377193772937739377493775937769377793778937799378093781937829378393784937859378693787937889378993790937919379293793937949379593796937979379893799938009380193802938039380493805938069380793808938099381093811938129381393814938159381693817938189381993820938219382293823938249382593826938279382893829938309383193832938339383493835938369383793838938399384093841938429384393844938459384693847938489384993850938519385293853938549385593856938579385893859938609386193862938639386493865938669386793868938699387093871938729387393874938759387693877938789387993880938819388293883938849388593886938879388893889938909389193892938939389493895938969389793898938999390093901939029390393904939059390693907939089390993910939119391293913939149391593916939179391893919939209392193922939239392493925939269392793928939299393093931939329393393934939359393693937939389393993940939419394293943939449394593946939479394893949939509395193952939539395493955939569395793958939599396093961939629396393964939659396693967939689396993970939719397293973939749397593976939779397893979939809398193982939839398493985939869398793988939899399093991939929399393994939959399693997939989399994000940019400294003940049400594006940079400894009940109401194012940139401494015940169401794018940199402094021940229402394024940259402694027940289402994030940319403294033940349403594036940379403894039940409404194042940439404494045940469404794048940499405094051940529405394054940559405694057940589405994060940619406294063940649406594066940679406894069940709407194072940739407494075940769407794078940799408094081940829408394084940859408694087940889408994090940919409294093940949409594096940979409894099941009410194102941039410494105941069410794108941099411094111941129411394114941159411694117941189411994120941219412294123941249412594126941279412894129941309413194132941339413494135941369413794138941399414094141941429414394144941459414694147941489414994150941519415294153941549415594156941579415894159941609416194162941639416494165941669416794168941699417094171941729417394174941759417694177941789417994180941819418294183941849418594186941879418894189941909419194192941939419494195941969419794198941999420094201942029420394204942059420694207942089420994210942119421294213942149421594216942179421894219942209422194222942239422494225942269422794228942299423094231942329423394234942359423694237942389423994240942419424294243942449424594246942479424894249942509425194252942539425494255942569425794258942599426094261942629426394264942659426694267942689426994270942719427294273942749427594276942779427894279942809428194282942839428494285942869428794288942899429094291942929429394294942959429694297942989429994300943019430294303943049430594306943079430894309943109431194312943139431494315943169431794318943199432094321943229432394324943259432694327943289432994330943319433294333943349433594336943379433894339943409434194342943439434494345943469434794348943499435094351943529435394354943559435694357943589435994360943619436294363943649436594366943679436894369943709437194372943739437494375943769437794378943799438094381943829438394384943859438694387943889438994390943919439294393943949439594396943979439894399944009440194402944039440494405944069440794408944099441094411944129441394414944159441694417944189441994420944219442294423944249442594426944279442894429944309443194432944339443494435944369443794438944399444094441944429444394444944459444694447944489444994450944519445294453944549445594456944579445894459944609446194462944639446494465944669446794468944699447094471944729447394474944759447694477944789447994480944819448294483944849448594486944879448894489944909449194492944939449494495944969449794498944999450094501945029450394504945059450694507945089450994510945119451294513945149451594516945179451894519945209452194522945239452494525945269452794528945299453094531945329453394534945359453694537945389453994540945419454294543945449454594546945479454894549945509455194552945539455494555945569455794558945599456094561945629456394564945659456694567945689456994570945719457294573945749457594576945779457894579945809458194582945839458494585945869458794588945899459094591945929459394594945959459694597945989459994600946019460294603946049460594606946079460894609946109461194612946139461494615946169461794618946199462094621946229462394624946259462694627946289462994630946319463294633946349463594636946379463894639946409464194642946439464494645946469464794648946499465094651946529465394654946559465694657946589465994660946619466294663946649466594666946679466894669946709467194672946739467494675946769467794678946799468094681946829468394684946859468694687946889468994690946919469294693946949469594696946979469894699947009470194702947039470494705947069470794708947099471094711947129471394714947159471694717947189471994720947219472294723947249472594726947279472894729947309473194732947339473494735947369473794738947399474094741947429474394744947459474694747947489474994750947519475294753947549475594756947579475894759947609476194762947639476494765947669476794768947699477094771947729477394774947759477694777947789477994780947819478294783947849478594786947879478894789947909479194792947939479494795947969479794798947999480094801948029480394804948059480694807948089480994810948119481294813948149481594816948179481894819948209482194822948239482494825948269482794828948299483094831948329483394834948359483694837948389483994840948419484294843948449484594846948479484894849948509485194852948539485494855948569485794858948599486094861948629486394864948659486694867948689486994870948719487294873948749487594876948779487894879948809488194882948839488494885948869488794888948899489094891948929489394894948959489694897948989489994900949019490294903949049490594906949079490894909949109491194912949139491494915949169491794918949199492094921949229492394924949259492694927949289492994930949319493294933949349493594936949379493894939949409494194942949439494494945949469494794948949499495094951949529495394954949559495694957949589495994960949619496294963949649496594966949679496894969949709497194972949739497494975949769497794978949799498094981949829498394984949859498694987949889498994990949919499294993949949499594996949979499894999950009500195002950039500495005950069500795008950099501095011950129501395014950159501695017950189501995020950219502295023950249502595026950279502895029950309503195032950339503495035950369503795038950399504095041950429504395044950459504695047950489504995050950519505295053950549505595056950579505895059950609506195062950639506495065950669506795068950699507095071950729507395074950759507695077950789507995080950819508295083950849508595086950879508895089950909509195092950939509495095950969509795098950999510095101951029510395104951059510695107951089510995110951119511295113951149511595116951179511895119951209512195122951239512495125951269512795128951299513095131951329513395134951359513695137951389513995140951419514295143951449514595146951479514895149951509515195152951539515495155951569515795158951599516095161951629516395164951659516695167951689516995170951719517295173951749517595176951779517895179951809518195182951839518495185951869518795188951899519095191951929519395194951959519695197951989519995200952019520295203952049520595206952079520895209952109521195212952139521495215952169521795218952199522095221952229522395224952259522695227952289522995230952319523295233952349523595236952379523895239952409524195242952439524495245952469524795248952499525095251952529525395254952559525695257952589525995260952619526295263952649526595266952679526895269952709527195272952739527495275952769527795278952799528095281952829528395284952859528695287952889528995290952919529295293952949529595296952979529895299953009530195302953039530495305953069530795308953099531095311953129531395314953159531695317953189531995320953219532295323953249532595326953279532895329953309533195332953339533495335953369533795338953399534095341953429534395344953459534695347953489534995350953519535295353953549535595356953579535895359953609536195362953639536495365953669536795368953699537095371953729537395374953759537695377953789537995380953819538295383953849538595386953879538895389953909539195392953939539495395953969539795398953999540095401954029540395404954059540695407954089540995410954119541295413954149541595416954179541895419954209542195422954239542495425954269542795428954299543095431954329543395434954359543695437954389543995440954419544295443954449544595446954479544895449954509545195452954539545495455954569545795458954599546095461954629546395464954659546695467954689546995470954719547295473954749547595476954779547895479954809548195482954839548495485954869548795488954899549095491954929549395494954959549695497954989549995500955019550295503955049550595506955079550895509955109551195512955139551495515955169551795518955199552095521955229552395524955259552695527955289552995530955319553295533955349553595536955379553895539955409554195542955439554495545955469554795548955499555095551955529555395554955559555695557955589555995560955619556295563955649556595566955679556895569955709557195572955739557495575955769557795578955799558095581955829558395584955859558695587955889558995590955919559295593955949559595596955979559895599956009560195602956039560495605956069560795608956099561095611956129561395614956159561695617956189561995620956219562295623956249562595626956279562895629956309563195632956339563495635956369563795638956399564095641956429564395644956459564695647956489564995650956519565295653956549565595656956579565895659956609566195662956639566495665956669566795668956699567095671956729567395674956759567695677956789567995680956819568295683956849568595686956879568895689956909569195692956939569495695956969569795698956999570095701957029570395704957059570695707957089570995710957119571295713957149571595716957179571895719957209572195722957239572495725957269572795728957299573095731957329573395734957359573695737957389573995740957419574295743957449574595746957479574895749957509575195752957539575495755957569575795758957599576095761957629576395764957659576695767957689576995770957719577295773957749577595776957779577895779957809578195782957839578495785957869578795788957899579095791957929579395794957959579695797957989579995800958019580295803958049580595806958079580895809958109581195812958139581495815958169581795818958199582095821958229582395824958259582695827958289582995830958319583295833958349583595836958379583895839958409584195842958439584495845958469584795848958499585095851958529585395854958559585695857958589585995860958619586295863958649586595866958679586895869958709587195872958739587495875958769587795878958799588095881958829588395884958859588695887958889588995890958919589295893958949589595896958979589895899959009590195902959039590495905959069590795908959099591095911959129591395914959159591695917959189591995920959219592295923959249592595926959279592895929959309593195932959339593495935959369593795938959399594095941959429594395944959459594695947959489594995950959519595295953959549595595956959579595895959959609596195962959639596495965959669596795968959699597095971959729597395974959759597695977959789597995980959819598295983959849598595986959879598895989959909599195992959939599495995959969599795998959999600096001960029600396004960059600696007960089600996010960119601296013960149601596016960179601896019960209602196022960239602496025960269602796028960299603096031960329603396034960359603696037960389603996040960419604296043960449604596046960479604896049960509605196052960539605496055960569605796058960599606096061960629606396064960659606696067960689606996070960719607296073960749607596076960779607896079960809608196082960839608496085960869608796088960899609096091960929609396094960959609696097960989609996100961019610296103961049610596106961079610896109961109611196112961139611496115961169611796118961199612096121961229612396124961259612696127961289612996130961319613296133961349613596136961379613896139961409614196142961439614496145961469614796148961499615096151961529615396154961559615696157961589615996160961619616296163961649616596166961679616896169961709617196172961739617496175961769617796178961799618096181961829618396184961859618696187961889618996190961919619296193961949619596196961979619896199962009620196202962039620496205962069620796208962099621096211962129621396214962159621696217962189621996220962219622296223962249622596226962279622896229962309623196232962339623496235962369623796238962399624096241962429624396244962459624696247962489624996250962519625296253962549625596256962579625896259962609626196262962639626496265962669626796268962699627096271962729627396274962759627696277962789627996280962819628296283962849628596286962879628896289962909629196292962939629496295962969629796298962999630096301963029630396304963059630696307963089630996310963119631296313963149631596316963179631896319963209632196322963239632496325963269632796328963299633096331963329633396334963359633696337963389633996340963419634296343963449634596346963479634896349963509635196352963539635496355963569635796358963599636096361963629636396364963659636696367963689636996370963719637296373963749637596376963779637896379963809638196382963839638496385963869638796388963899639096391963929639396394963959639696397963989639996400964019640296403964049640596406964079640896409964109641196412964139641496415964169641796418964199642096421964229642396424964259642696427964289642996430964319643296433964349643596436964379643896439964409644196442964439644496445964469644796448964499645096451964529645396454964559645696457964589645996460964619646296463964649646596466964679646896469964709647196472964739647496475964769647796478964799648096481964829648396484964859648696487964889648996490964919649296493964949649596496964979649896499965009650196502965039650496505965069650796508965099651096511965129651396514965159651696517965189651996520965219652296523965249652596526965279652896529965309653196532965339653496535965369653796538965399654096541965429654396544965459654696547965489654996550965519655296553965549655596556965579655896559965609656196562965639656496565965669656796568965699657096571965729657396574965759657696577965789657996580965819658296583965849658596586965879658896589965909659196592965939659496595965969659796598965999660096601966029660396604966059660696607966089660996610966119661296613966149661596616966179661896619966209662196622966239662496625966269662796628966299663096631966329663396634966359663696637966389663996640966419664296643966449664596646966479664896649966509665196652966539665496655966569665796658966599666096661966629666396664966659666696667966689666996670966719667296673966749667596676966779667896679966809668196682966839668496685966869668796688966899669096691966929669396694966959669696697966989669996700967019670296703967049670596706967079670896709967109671196712967139671496715967169671796718967199672096721967229672396724967259672696727967289672996730967319673296733967349673596736967379673896739967409674196742967439674496745967469674796748967499675096751967529675396754967559675696757967589675996760967619676296763967649676596766967679676896769967709677196772967739677496775967769677796778967799678096781967829678396784967859678696787967889678996790967919679296793967949679596796967979679896799968009680196802968039680496805968069680796808968099681096811968129681396814968159681696817968189681996820968219682296823968249682596826968279682896829968309683196832968339683496835968369683796838968399684096841968429684396844968459684696847968489684996850968519685296853968549685596856968579685896859968609686196862968639686496865968669686796868968699687096871968729687396874968759687696877968789687996880968819688296883968849688596886968879688896889968909689196892968939689496895968969689796898968999690096901969029690396904969059690696907969089690996910969119691296913969149691596916969179691896919969209692196922969239692496925969269692796928969299693096931969329693396934969359693696937969389693996940969419694296943969449694596946969479694896949969509695196952969539695496955969569695796958969599696096961969629696396964
  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. #endif /* WOLFSSL_DTLS */
  1054. #endif /* OPENSSL_EXTRA || WOLFSSL_EITHER_SIDE */
  1055. return EXPECT_RESULT();
  1056. }
  1057. #if defined(WOLFSSL_DUAL_ALG_CERTS) && !defined(NO_FILESYSTEM)
  1058. /*----------------------------------------------------------------------------*
  1059. | Dual algorithm Certificate Tests
  1060. *----------------------------------------------------------------------------*/
  1061. #define LARGE_TEMP_SZ 4096
  1062. /* To better understand this, please see the X9.146 example in wolfssl-examples
  1063. * repo. */
  1064. static int do_dual_alg_root_certgen(byte **out, char *caKeyFile,
  1065. char *sapkiFile, char *altPrivFile)
  1066. {
  1067. EXPECT_DECLS;
  1068. FILE* file = NULL;
  1069. Cert newCert;
  1070. DecodedCert preTBS;
  1071. byte caKeyBuf[LARGE_TEMP_SZ];
  1072. word32 caKeySz = LARGE_TEMP_SZ;
  1073. byte sapkiBuf[LARGE_TEMP_SZ];
  1074. word32 sapkiSz = LARGE_TEMP_SZ;
  1075. byte altPrivBuf[LARGE_TEMP_SZ];
  1076. word32 altPrivSz = LARGE_TEMP_SZ;
  1077. byte altSigAlgBuf[LARGE_TEMP_SZ];
  1078. word32 altSigAlgSz = LARGE_TEMP_SZ;
  1079. byte scratchBuf[LARGE_TEMP_SZ];
  1080. word32 scratchSz = LARGE_TEMP_SZ;
  1081. byte preTbsBuf[LARGE_TEMP_SZ];
  1082. word32 preTbsSz = LARGE_TEMP_SZ;
  1083. byte altSigValBuf[LARGE_TEMP_SZ];
  1084. word32 altSigValSz = LARGE_TEMP_SZ;
  1085. byte *outBuf = NULL;
  1086. word32 outSz = LARGE_TEMP_SZ;
  1087. WC_RNG rng;
  1088. RsaKey caKey;
  1089. ecc_key altCaKey;
  1090. word32 idx = 0;
  1091. XMEMSET(&rng, 0, sizeof(WC_RNG));
  1092. XMEMSET(&caKey, 0, sizeof(RsaKey));
  1093. XMEMSET(&altCaKey, 0, sizeof(ecc_key));
  1094. ExpectNotNull(outBuf = (byte*)XMALLOC(outSz, NULL,
  1095. DYNAMIC_TYPE_TMP_BUFFER));
  1096. ExpectIntEQ(wc_InitRng(&rng), 0);
  1097. XMEMSET(caKeyBuf, 0, caKeySz);
  1098. ExpectNotNull(file = fopen(caKeyFile, "rb"));
  1099. ExpectIntGT(caKeySz = (word32)fread(caKeyBuf, 1, caKeySz, file), 0);
  1100. if (file) {
  1101. fclose(file);
  1102. file = NULL;
  1103. }
  1104. ExpectIntEQ(wc_InitRsaKey_ex(&caKey, NULL, INVALID_DEVID), 0);
  1105. idx = 0;
  1106. ExpectIntEQ(wc_RsaPrivateKeyDecode(caKeyBuf, &idx, &caKey, caKeySz),
  1107. 0);
  1108. XMEMSET(sapkiBuf, 0, sapkiSz);
  1109. ExpectNotNull(file = fopen(sapkiFile, "rb"));
  1110. ExpectIntGT(sapkiSz = (word32)fread(sapkiBuf, 1, sapkiSz, file), 0);
  1111. if (file) {
  1112. fclose(file);
  1113. file = NULL;
  1114. }
  1115. XMEMSET(altPrivBuf, 0, altPrivSz);
  1116. ExpectNotNull(file = fopen(altPrivFile, "rb"));
  1117. ExpectIntGT(altPrivSz = (word32)fread(altPrivBuf, 1, altPrivSz, file), 0);
  1118. if (file) {
  1119. fclose(file);
  1120. file = NULL;
  1121. }
  1122. wc_ecc_init(&altCaKey);
  1123. idx = 0;
  1124. ExpectIntEQ(wc_EccPrivateKeyDecode(altPrivBuf, &idx, &altCaKey,
  1125. (word32)altPrivSz), 0);
  1126. XMEMSET(altSigAlgBuf, 0, altSigAlgSz);
  1127. ExpectIntGT(altSigAlgSz = SetAlgoID(CTC_SHA256wECDSA, altSigAlgBuf,
  1128. oidSigType, 0), 0);
  1129. wc_InitCert(&newCert);
  1130. strncpy(newCert.subject.country, "US", CTC_NAME_SIZE);
  1131. strncpy(newCert.subject.state, "MT", CTC_NAME_SIZE);
  1132. strncpy(newCert.subject.locality, "Bozeman", CTC_NAME_SIZE);
  1133. strncpy(newCert.subject.org, "wolfSSL", CTC_NAME_SIZE);
  1134. strncpy(newCert.subject.unit, "Engineering", CTC_NAME_SIZE);
  1135. strncpy(newCert.subject.commonName, "www.wolfssl.com", CTC_NAME_SIZE);
  1136. strncpy(newCert.subject.email, "root@wolfssl.com", CTC_NAME_SIZE);
  1137. newCert.sigType = CTC_SHA256wRSA;
  1138. newCert.isCA = 1;
  1139. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "1.2.3.4.5",
  1140. (const byte *)"This is NOT a critical extension", 32), 0);
  1141. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.72", sapkiBuf,
  1142. sapkiSz), 0);
  1143. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.73", altSigAlgBuf,
  1144. altSigAlgSz), 0);
  1145. XMEMSET(scratchBuf, 0, scratchSz);
  1146. ExpectIntGT(scratchSz = wc_MakeSelfCert(&newCert, scratchBuf, scratchSz,
  1147. &caKey, &rng), 0);
  1148. wc_InitDecodedCert(&preTBS, scratchBuf, scratchSz, 0);
  1149. ExpectIntEQ(wc_ParseCert(&preTBS, CERT_TYPE, NO_VERIFY, NULL), 0);
  1150. XMEMSET(preTbsBuf, 0, preTbsSz);
  1151. ExpectIntGT(preTbsSz = wc_GeneratePreTBS(&preTBS, preTbsBuf, preTbsSz), 0);
  1152. XMEMSET(altSigValBuf, 0, altSigValSz);
  1153. ExpectIntGT(altSigValSz = wc_MakeSigWithBitStr(altSigValBuf, altSigValSz,
  1154. CTC_SHA256wECDSA, preTbsBuf, preTbsSz, ECC_TYPE, &altCaKey,
  1155. &rng), 0);
  1156. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.74", altSigValBuf,
  1157. altSigValSz), 0);
  1158. /* Finally, generate the new certificate. */
  1159. if (outBuf != NULL) {
  1160. XMEMSET(outBuf, 0, outSz);
  1161. }
  1162. ExpectIntGT(outSz = wc_MakeSelfCert(&newCert, outBuf, outSz, &caKey, &rng),
  1163. 0);
  1164. *out = outBuf;
  1165. wc_FreeRsaKey(&caKey);
  1166. wc_FreeRng(&rng);
  1167. wc_FreeDecodedCert(&preTBS);
  1168. return outSz;
  1169. }
  1170. static int do_dual_alg_server_certgen(byte **out, char *caKeyFile,
  1171. char *sapkiFile, char *altPrivFile,
  1172. char *serverKeyFile,
  1173. byte *caCertBuf, int caCertSz)
  1174. {
  1175. EXPECT_DECLS;
  1176. FILE* file = NULL;
  1177. Cert newCert;
  1178. DecodedCert preTBS;
  1179. byte serverKeyBuf[LARGE_TEMP_SZ];
  1180. word32 serverKeySz = LARGE_TEMP_SZ;
  1181. byte caKeyBuf[LARGE_TEMP_SZ];
  1182. word32 caKeySz = LARGE_TEMP_SZ;
  1183. byte sapkiBuf[LARGE_TEMP_SZ];
  1184. word32 sapkiSz = LARGE_TEMP_SZ;
  1185. byte altPrivBuf[LARGE_TEMP_SZ];
  1186. word32 altPrivSz = LARGE_TEMP_SZ;
  1187. byte altSigAlgBuf[LARGE_TEMP_SZ];
  1188. word32 altSigAlgSz = LARGE_TEMP_SZ;
  1189. byte scratchBuf[LARGE_TEMP_SZ];
  1190. word32 scratchSz = LARGE_TEMP_SZ;
  1191. byte preTbsBuf[LARGE_TEMP_SZ];
  1192. word32 preTbsSz = LARGE_TEMP_SZ;
  1193. byte altSigValBuf[LARGE_TEMP_SZ];
  1194. word32 altSigValSz = LARGE_TEMP_SZ;
  1195. byte *outBuf = NULL;
  1196. word32 outSz = LARGE_TEMP_SZ;
  1197. WC_RNG rng;
  1198. RsaKey caKey;
  1199. RsaKey serverKey;
  1200. ecc_key altCaKey;
  1201. word32 idx = 0;
  1202. XMEMSET(&rng, 0, sizeof(WC_RNG));
  1203. XMEMSET(&caKey, 0, sizeof(RsaKey));
  1204. XMEMSET(&serverKey, 0, sizeof(RsaKey));
  1205. XMEMSET(&altCaKey, 0, sizeof(ecc_key));
  1206. ExpectNotNull(outBuf = (byte*)XMALLOC(outSz, NULL,
  1207. DYNAMIC_TYPE_TMP_BUFFER));
  1208. ExpectIntEQ(wc_InitRng(&rng), 0);
  1209. XMEMSET(serverKeyBuf, 0, serverKeySz);
  1210. ExpectNotNull(file = fopen(serverKeyFile, "rb"));
  1211. ExpectIntGT(serverKeySz = (word32)fread(serverKeyBuf, 1, serverKeySz, file),
  1212. 0);
  1213. if (file) {
  1214. fclose(file);
  1215. file = NULL;
  1216. }
  1217. ExpectIntEQ(wc_InitRsaKey_ex(&serverKey, NULL, INVALID_DEVID), 0);
  1218. idx = 0;
  1219. ExpectIntEQ(wc_RsaPrivateKeyDecode(serverKeyBuf, &idx, &serverKey,
  1220. (word32)serverKeySz), 0);
  1221. XMEMSET(caKeyBuf, 0, caKeySz);
  1222. ExpectNotNull(file = fopen(caKeyFile, "rb"));
  1223. ExpectIntGT(caKeySz = (word32)fread(caKeyBuf, 1, caKeySz, file), 0);
  1224. if (file) {
  1225. fclose(file);
  1226. file = NULL;
  1227. }
  1228. ExpectIntEQ(wc_InitRsaKey_ex(&caKey, NULL, INVALID_DEVID), 0);
  1229. idx = 0;
  1230. ExpectIntEQ(wc_RsaPrivateKeyDecode(caKeyBuf, &idx, &caKey,
  1231. (word32)caKeySz), 0);
  1232. XMEMSET(sapkiBuf, 0, sapkiSz);
  1233. ExpectNotNull(file = fopen(sapkiFile, "rb"));
  1234. ExpectIntGT(sapkiSz = (word32)fread(sapkiBuf, 1, sapkiSz, file), 0);
  1235. if (file) {
  1236. fclose(file);
  1237. file = NULL;
  1238. }
  1239. XMEMSET(altPrivBuf, 0, altPrivSz);
  1240. ExpectNotNull(file = fopen(altPrivFile, "rb"));
  1241. ExpectIntGT(altPrivSz = (word32)fread(altPrivBuf, 1, altPrivSz, file), 0);
  1242. if (file) {
  1243. fclose(file);
  1244. file = NULL;
  1245. }
  1246. wc_ecc_init(&altCaKey);
  1247. idx = 0;
  1248. ExpectIntEQ(wc_EccPrivateKeyDecode(altPrivBuf, &idx, &altCaKey,
  1249. (word32)altPrivSz), 0);
  1250. XMEMSET(altSigAlgBuf, 0, altSigAlgSz);
  1251. ExpectIntGT(altSigAlgSz = SetAlgoID(CTC_SHA256wECDSA, altSigAlgBuf,
  1252. oidSigType, 0), 0);
  1253. wc_InitCert(&newCert);
  1254. strncpy(newCert.subject.country, "US", CTC_NAME_SIZE);
  1255. strncpy(newCert.subject.state, "MT", CTC_NAME_SIZE);
  1256. strncpy(newCert.subject.locality, "Bozeman", CTC_NAME_SIZE);
  1257. strncpy(newCert.subject.org, "wolfSSL", CTC_NAME_SIZE);
  1258. strncpy(newCert.subject.unit, "Engineering", CTC_NAME_SIZE);
  1259. strncpy(newCert.subject.commonName, "www.wolfssl.com", CTC_NAME_SIZE);
  1260. strncpy(newCert.subject.email, "server@wolfssl.com", CTC_NAME_SIZE);
  1261. newCert.sigType = CTC_SHA256wRSA;
  1262. newCert.isCA = 0;
  1263. ExpectIntEQ(wc_SetIssuerBuffer(&newCert, caCertBuf, caCertSz), 0);
  1264. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.72", sapkiBuf,
  1265. sapkiSz), 0);
  1266. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.73", altSigAlgBuf,
  1267. altSigAlgSz), 0);
  1268. XMEMSET(scratchBuf, 0, scratchSz);
  1269. ExpectIntGT(wc_MakeCert(&newCert, scratchBuf, scratchSz, &serverKey, NULL,
  1270. &rng), 0);
  1271. ExpectIntGT(scratchSz = wc_SignCert(newCert.bodySz, newCert.sigType,
  1272. scratchBuf, scratchSz, &caKey, NULL, &rng), 0);
  1273. wc_InitDecodedCert(&preTBS, scratchBuf, scratchSz, 0);
  1274. ExpectIntEQ(wc_ParseCert(&preTBS, CERT_TYPE, NO_VERIFY, NULL), 0);
  1275. XMEMSET(preTbsBuf, 0, preTbsSz);
  1276. ExpectIntGT(preTbsSz = wc_GeneratePreTBS(&preTBS, preTbsBuf, preTbsSz), 0);
  1277. XMEMSET(altSigValBuf, 0, altSigValSz);
  1278. ExpectIntGT(altSigValSz = wc_MakeSigWithBitStr(altSigValBuf, altSigValSz,
  1279. CTC_SHA256wECDSA, preTbsBuf, preTbsSz, ECC_TYPE, &altCaKey,
  1280. &rng), 0);
  1281. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.74",
  1282. altSigValBuf, altSigValSz), 0);
  1283. /* Finally, generate the new certificate. */
  1284. if (outBuf != NULL) {
  1285. XMEMSET(outBuf, 0, outSz);
  1286. }
  1287. ExpectIntGT(wc_MakeCert(&newCert, outBuf, outSz, &serverKey, NULL, &rng),
  1288. 0);
  1289. ExpectIntGT(outSz = wc_SignCert(newCert.bodySz, newCert.sigType, outBuf,
  1290. outSz, &caKey, NULL, &rng), 0);
  1291. *out = outBuf;
  1292. wc_FreeRsaKey(&caKey);
  1293. wc_FreeRsaKey(&serverKey);
  1294. wc_FreeRng(&rng);
  1295. wc_FreeDecodedCert(&preTBS);
  1296. return outSz;
  1297. }
  1298. static int do_dual_alg_tls13_connection(byte *caCert, word32 caCertSz,
  1299. byte *serverCert, word32 serverCertSz,
  1300. byte *serverKey, word32 serverKeySz,
  1301. int negative_test)
  1302. {
  1303. EXPECT_DECLS;
  1304. WOLFSSL_CTX *ctx_c = NULL;
  1305. WOLFSSL_CTX *ctx_s = NULL;
  1306. WOLFSSL *ssl_c = NULL;
  1307. WOLFSSL *ssl_s = NULL;
  1308. struct test_memio_ctx test_ctx;
  1309. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  1310. ExpectIntEQ(test_memio_setup_ex(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  1311. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  1312. caCert, caCertSz, serverCert, serverCertSz,
  1313. serverKey, serverKeySz), 0);
  1314. if (negative_test) {
  1315. ExpectTrue(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0);
  1316. }
  1317. else {
  1318. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  1319. }
  1320. wolfSSL_free(ssl_c);
  1321. wolfSSL_free(ssl_s);
  1322. wolfSSL_CTX_free(ctx_c);
  1323. wolfSSL_CTX_free(ctx_s);
  1324. return EXPECT_RESULT();
  1325. }
  1326. static int test_dual_alg_support(void)
  1327. {
  1328. EXPECT_DECLS;
  1329. /* Root CA and server keys will be the same. This is only appropriate for
  1330. * testing. */
  1331. char keyFile[] = "./certs/ca-key.der";
  1332. char sapkiFile[] = "./certs/ecc-keyPub.der";
  1333. char altPrivFile[] = "./certs/ecc-key.der";
  1334. char wrongPrivFile[] = "./certs/ecc-client-key.der";
  1335. byte *serverKey = NULL;
  1336. size_t serverKeySz = 0;
  1337. byte *root = NULL;
  1338. int rootSz = 0;
  1339. byte *server = NULL;
  1340. int serverSz = 0;
  1341. ExpectIntEQ(load_file(keyFile, &serverKey, &serverKeySz), 0);
  1342. /* Base normal case. */
  1343. if (EXPECT_SUCCESS()) {
  1344. rootSz = do_dual_alg_root_certgen(&root, keyFile, sapkiFile,
  1345. altPrivFile);
  1346. }
  1347. ExpectNotNull(root);
  1348. ExpectIntGT(rootSz, 0);
  1349. if (EXPECT_SUCCESS()) {
  1350. serverSz = do_dual_alg_server_certgen(&server, keyFile, sapkiFile,
  1351. altPrivFile, keyFile, root, rootSz);
  1352. }
  1353. ExpectNotNull(server);
  1354. ExpectIntGT(serverSz, 0);
  1355. ExpectIntEQ(do_dual_alg_tls13_connection(root, rootSz,
  1356. server, serverSz, serverKey, (word32)serverKeySz, 0),
  1357. TEST_SUCCESS);
  1358. XFREE(root, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  1359. root = NULL;
  1360. XFREE(server, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  1361. server = NULL;
  1362. /* Now we try a negative case. Note that we use wrongPrivFile to generate
  1363. * the alternative signature and then set negative_test to true for the
  1364. * call to do_dual_alg_tls13_connection(). Its expecting a failed connection
  1365. * because the signature won't verify. The exception is if
  1366. * WOLFSSL_TRUST_PEER_CERT is defined. In that case, no verification happens
  1367. * and this is no longer a negative test. */
  1368. if (EXPECT_SUCCESS()) {
  1369. rootSz = do_dual_alg_root_certgen(&root, keyFile, sapkiFile,
  1370. wrongPrivFile);
  1371. }
  1372. ExpectNotNull(root);
  1373. ExpectIntGT(rootSz, 0);
  1374. if (EXPECT_SUCCESS()) {
  1375. serverSz = do_dual_alg_server_certgen(&server, keyFile, sapkiFile,
  1376. wrongPrivFile, keyFile, root, rootSz);
  1377. }
  1378. ExpectNotNull(server);
  1379. ExpectIntGT(serverSz, 0);
  1380. #ifdef WOLFSSL_TRUST_PEER_CERT
  1381. ExpectIntEQ(do_dual_alg_tls13_connection(root, rootSz,
  1382. server, serverSz, serverKey, (word32)serverKeySz, 0),
  1383. TEST_SUCCESS);
  1384. #else
  1385. ExpectIntEQ(do_dual_alg_tls13_connection(root, rootSz,
  1386. server, serverSz, serverKey, (word32)serverKeySz, 1),
  1387. TEST_SUCCESS);
  1388. #endif
  1389. XFREE(root, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  1390. XFREE(server, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  1391. free(serverKey);
  1392. return EXPECT_RESULT();
  1393. }
  1394. #else
  1395. static int test_dual_alg_support(void)
  1396. {
  1397. return TEST_SKIPPED;
  1398. }
  1399. #endif /* WOLFSSL_DUAL_ALG_CERTS && !NO_FILESYSTEM */
  1400. /*----------------------------------------------------------------------------*
  1401. | Context
  1402. *----------------------------------------------------------------------------*/
  1403. #ifndef NO_WOLFSSL_SERVER
  1404. static int test_wolfSSL_CTX_new(void)
  1405. {
  1406. EXPECT_DECLS;
  1407. WOLFSSL_CTX *ctx;
  1408. WOLFSSL_METHOD* method;
  1409. ExpectNull(ctx = wolfSSL_CTX_new(NULL));
  1410. ExpectNotNull(method = wolfSSLv23_server_method());
  1411. ExpectNotNull(ctx = wolfSSL_CTX_new(method));
  1412. wolfSSL_CTX_free(ctx);
  1413. return EXPECT_RESULT();
  1414. }
  1415. #endif
  1416. #if (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)) && \
  1417. (!defined(NO_RSA) || defined(HAVE_ECC)) && !defined(NO_FILESYSTEM)
  1418. static int test_for_double_Free(void)
  1419. {
  1420. EXPECT_DECLS;
  1421. WOLFSSL_CTX* ctx = NULL;
  1422. WOLFSSL* ssl = NULL;
  1423. int skipTest = 0;
  1424. const char* testCertFile;
  1425. const char* testKeyFile;
  1426. char optionsCiphers[] = "RC4-SHA:RC4-MD5:DES-CBC3-SHA:AES128-SHA:AES256-SHA"
  1427. ":NULL-SHA:NULL-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:DHE-PSK-AES256-GCM"
  1428. "-SHA384:DHE-PSK-AES128-GCM-SHA256:PSK-AES256-GCM-SHA384:PSK-AES128-GCM-SHA256:"
  1429. "DHE-PSK-AES256-CBC-SHA384:DHE-PSK-AES128-CBC-SHA256:PSK-AES256-CBC-SHA384:PSK-"
  1430. "AES128-CBC-SHA256:PSK-AES128-CBC-SHA:PSK-AES256-CBC-SHA:DHE-PSK-AES128-CCM:DHE"
  1431. "-PSK-AES256-CCM:PSK-AES128-CCM:PSK-AES256-CCM:PSK-AES128-CCM-8:PSK-AES256-CCM-"
  1432. "8:DHE-PSK-NULL-SHA384:DHE-PSK-NULL-SHA256:PSK-NULL-SHA384:PSK-NULL-SHA256:PSK-"
  1433. "NULL-SHA:AES128-CCM-8:AES256-CCM-8:ECDHE-ECDSA-"
  1434. "AES128-CCM:ECDHE-ECDSA-AES128-CCM-8:ECDHE-ECDSA-AES256-CCM-8:ECDHE-RSA-AES128-"
  1435. "SHA:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA:ECDHE-R"
  1436. "SA-RC4-SHA:ECDHE-RSA-DES-CBC3-SHA:ECDHE-ECDSA-RC4-SHA:ECDHE-ECDSA-DES-CBC3-SHA"
  1437. ":AES128-SHA256:AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA256:ECDH-"
  1438. "RSA-AES128-SHA:ECDH-RSA-AES256-SHA:ECDH-ECDSA-AES128-SHA:ECDH-ECDSA-AES256-SHA"
  1439. ":ECDH-RSA-RC4-SHA:ECDH-RSA-DES-CBC3-SHA:ECDH-ECDSA-RC4-SHA:ECDH-ECDSA-DES-CBC3"
  1440. "-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES"
  1441. "256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-E"
  1442. "CDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDH-RSA-AES128-GCM-SHA25"
  1443. "6:ECDH-RSA-AES256-GCM-SHA384:ECDH-ECDSA-AES128-GCM-SHA256:ECDH-ECDSA-AES256-GC"
  1444. "M-SHA384:CAMELLIA128-SHA:DHE-RSA-CAMELLIA128-SHA:CAMELLIA256-SHA:DHE-RSA-CAMEL"
  1445. "LIA256-SHA:CAMELLIA128-SHA256:DHE-RSA-CAMELLIA128-SHA256:CAMELLIA256-SHA256:DH"
  1446. "E-RSA-CAMELLIA256-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECD"
  1447. "H-RSA-AES128-SHA256:ECDH-ECDSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-ECD"
  1448. "SA-AES256-SHA384:ECDH-RSA-AES256-SHA384:ECDH-ECDSA-AES256-SHA384:ECDHE-RSA-CHA"
  1449. "CHA20-POLY1305:ECDHE-ECDSA-CHACHA20-POLY1305:DHE-RSA-CHACHA20-POLY1305:ECDHE-R"
  1450. "SA-CHACHA20-POLY1305-OLD:ECDHE-ECDSA-CHACHA20-POLY1305-OLD:DHE-RSA-CHACHA20-PO"
  1451. "LY1305-OLD:ECDHE-ECDSA-NULL-SHA:ECDHE-PSK-NULL-SHA256:ECDHE-PSK-A"
  1452. "ES128-CBC-SHA256:PSK-CHACHA20-POLY1305:ECDHE-PSK-CHACHA20-POLY1305:DHE-PSK-CHA"
  1453. "CHA20-POLY1305:EDH-RSA-DES-CBC3-SHA:TLS13-AES128-GCM-SHA256:TLS13-AES256-GCM-S"
  1454. "HA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES128-CCM-SHA256:TLS13-AES128-CCM-"
  1455. "8-SHA256:TLS13-SHA256-SHA256:TLS13-SHA384-SHA384";
  1456. /* OpenVPN uses a "blacklist" method to specify which ciphers NOT to use */
  1457. #ifdef OPENSSL_EXTRA
  1458. char openvpnCiphers[] = "DEFAULT:!EXP:!LOW:!MEDIUM:!kDH:!kECDH:!DSS:!PSK:"
  1459. "!SRP:!kRSA:!aNULL:!eNULL";
  1460. #endif
  1461. #ifndef NO_RSA
  1462. testCertFile = svrCertFile;
  1463. testKeyFile = svrKeyFile;
  1464. #elif defined(HAVE_ECC)
  1465. testCertFile = eccCertFile;
  1466. testKeyFile = eccKeyFile;
  1467. #else
  1468. skipTest = 1;
  1469. #endif
  1470. if (skipTest != 1) {
  1471. #ifndef NO_WOLFSSL_SERVER
  1472. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1473. #else
  1474. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1475. #endif
  1476. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  1477. WOLFSSL_FILETYPE_PEM));
  1478. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  1479. WOLFSSL_FILETYPE_PEM));
  1480. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1481. /* First test freeing SSL, then CTX */
  1482. wolfSSL_free(ssl);
  1483. ssl = NULL;
  1484. wolfSSL_CTX_free(ctx);
  1485. ctx = NULL;
  1486. #ifndef NO_WOLFSSL_CLIENT
  1487. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1488. #else
  1489. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1490. #endif
  1491. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  1492. WOLFSSL_FILETYPE_PEM));
  1493. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  1494. WOLFSSL_FILETYPE_PEM));
  1495. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1496. /* Next test freeing CTX then SSL */
  1497. wolfSSL_CTX_free(ctx);
  1498. ctx = NULL;
  1499. wolfSSL_free(ssl);
  1500. ssl = NULL;
  1501. #ifndef NO_WOLFSSL_SERVER
  1502. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1503. #else
  1504. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1505. #endif
  1506. /* Test setting ciphers at ctx level */
  1507. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  1508. WOLFSSL_FILETYPE_PEM));
  1509. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  1510. WOLFSSL_FILETYPE_PEM));
  1511. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx, optionsCiphers));
  1512. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_TLS13) && defined(HAVE_AESGCM) && \
  1513. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  1514. /* only update TLSv13 suites */
  1515. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx, "TLS13-AES256-GCM-SHA384"));
  1516. #endif
  1517. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && defined(HAVE_AESGCM) && \
  1518. !defined(NO_SHA256) && !defined(WOLFSSL_NO_TLS12) && \
  1519. defined(WOLFSSL_AES_128) && !defined(NO_RSA)
  1520. /* only update pre-TLSv13 suites */
  1521. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx,
  1522. "ECDHE-RSA-AES128-GCM-SHA256"));
  1523. #endif
  1524. #ifdef OPENSSL_EXTRA
  1525. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx, openvpnCiphers));
  1526. #endif
  1527. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1528. wolfSSL_CTX_free(ctx);
  1529. ctx = NULL;
  1530. wolfSSL_free(ssl);
  1531. ssl = NULL;
  1532. #ifndef NO_WOLFSSL_CLIENT
  1533. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1534. #else
  1535. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1536. #endif
  1537. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  1538. WOLFSSL_FILETYPE_PEM));
  1539. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  1540. WOLFSSL_FILETYPE_PEM));
  1541. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1542. /* test setting ciphers at SSL level */
  1543. ExpectTrue(wolfSSL_set_cipher_list(ssl, optionsCiphers));
  1544. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_TLS13) && defined(HAVE_AESGCM) && \
  1545. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  1546. /* only update TLSv13 suites */
  1547. ExpectTrue(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384"));
  1548. #endif
  1549. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && defined(HAVE_AESGCM) && \
  1550. !defined(NO_SHA256) && !defined(WOLFSSL_NO_TLS12) && \
  1551. defined(WOLFSSL_AES_128) && !defined(NO_RSA)
  1552. /* only update pre-TLSv13 suites */
  1553. ExpectTrue(wolfSSL_set_cipher_list(ssl, "ECDHE-RSA-AES128-GCM-SHA256"));
  1554. #endif
  1555. wolfSSL_CTX_free(ctx);
  1556. ctx = NULL;
  1557. wolfSSL_free(ssl);
  1558. ssl = NULL;
  1559. }
  1560. return EXPECT_RESULT();
  1561. }
  1562. #endif
  1563. static int test_wolfSSL_CTX_set_cipher_list_bytes(void)
  1564. {
  1565. EXPECT_DECLS;
  1566. #if (defined(OPENSSL_EXTRA) || defined(WOLFSSL_SET_CIPHER_BYTES)) && \
  1567. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)) && \
  1568. (!defined(NO_RSA) || defined(HAVE_ECC)) && !defined(NO_FILESYSTEM)
  1569. const char* testCertFile;
  1570. const char* testKeyFile;
  1571. WOLFSSL_CTX* ctx = NULL;
  1572. WOLFSSL* ssl = NULL;
  1573. const byte cipherList[] =
  1574. {
  1575. /* TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA */ 0x00, 0x16,
  1576. /* TLS_DHE_RSA_WITH_AES_256_CBC_SHA */ 0x00, 0x39,
  1577. /* TLS_DHE_RSA_WITH_AES_128_CBC_SHA */ 0x00, 0x33,
  1578. /* TLS_DH_anon_WITH_AES_128_CBC_SHA */ 0x00, 0x34,
  1579. /* TLS_RSA_WITH_AES_256_CBC_SHA */ 0x00, 0x35,
  1580. /* TLS_RSA_WITH_AES_128_CBC_SHA */ 0x00, 0x2F,
  1581. /* TLS_RSA_WITH_NULL_MD5 */ 0x00, 0x01,
  1582. /* TLS_RSA_WITH_NULL_SHA */ 0x00, 0x02,
  1583. /* TLS_PSK_WITH_AES_256_CBC_SHA */ 0x00, 0x8d,
  1584. /* TLS_PSK_WITH_AES_128_CBC_SHA256 */ 0x00, 0xae,
  1585. /* TLS_PSK_WITH_AES_256_CBC_SHA384 */ 0x00, 0xaf,
  1586. /* TLS_PSK_WITH_AES_128_CBC_SHA */ 0x00, 0x8c,
  1587. /* TLS_PSK_WITH_NULL_SHA256 */ 0x00, 0xb0,
  1588. /* TLS_PSK_WITH_NULL_SHA384 */ 0x00, 0xb1,
  1589. /* TLS_PSK_WITH_NULL_SHA */ 0x00, 0x2c,
  1590. /* SSL_RSA_WITH_RC4_128_SHA */ 0x00, 0x05,
  1591. /* SSL_RSA_WITH_RC4_128_MD5 */ 0x00, 0x04,
  1592. /* SSL_RSA_WITH_3DES_EDE_CBC_SHA */ 0x00, 0x0A,
  1593. /* ECC suites, first byte is 0xC0 (ECC_BYTE) */
  1594. /* TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA */ 0xC0, 0x14,
  1595. /* TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA */ 0xC0, 0x13,
  1596. /* TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA */ 0xC0, 0x0A,
  1597. /* TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA */ 0xC0, 0x09,
  1598. /* TLS_ECDHE_RSA_WITH_RC4_128_SHA */ 0xC0, 0x11,
  1599. /* TLS_ECDHE_ECDSA_WITH_RC4_128_SHA */ 0xC0, 0x07,
  1600. /* TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA */ 0xC0, 0x12,
  1601. /* TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA */ 0xC0, 0x08,
  1602. /* TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 */ 0xC0, 0x27,
  1603. /* TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256*/ 0xC0, 0x23,
  1604. /* TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 */ 0xC0, 0x28,
  1605. /* TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384*/ 0xC0, 0x24,
  1606. /* TLS_ECDHE_ECDSA_WITH_NULL_SHA */ 0xC0, 0x06,
  1607. /* TLS_ECDHE_PSK_WITH_NULL_SHA256 */ 0xC0, 0x3a,
  1608. /* TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 */ 0xC0, 0x37,
  1609. /* static ECDH, first byte is 0xC0 (ECC_BYTE) */
  1610. /* TLS_ECDH_RSA_WITH_AES_256_CBC_SHA */ 0xC0, 0x0F,
  1611. /* TLS_ECDH_RSA_WITH_AES_128_CBC_SHA */ 0xC0, 0x0E,
  1612. /* TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA */ 0xC0, 0x05,
  1613. /* TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA */ 0xC0, 0x04,
  1614. /* TLS_ECDH_RSA_WITH_RC4_128_SHA */ 0xC0, 0x0C,
  1615. /* TLS_ECDH_ECDSA_WITH_RC4_128_SHA */ 0xC0, 0x02,
  1616. /* TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA */ 0xC0, 0x0D,
  1617. /* TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA */ 0xC0, 0x03,
  1618. /* TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 */ 0xC0, 0x29,
  1619. /* TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 */ 0xC0, 0x25,
  1620. /* TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 */ 0xC0, 0x2A,
  1621. /* TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 */ 0xC0, 0x26,
  1622. /* WDM_WITH_NULL_SHA256 */ 0x00, 0xFE, /* wolfSSL DTLS Multicast */
  1623. /* SHA256 */
  1624. /* TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 */ 0x00, 0x6b,
  1625. /* TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 */ 0x00, 0x67,
  1626. /* TLS_RSA_WITH_AES_256_CBC_SHA256 */ 0x00, 0x3d,
  1627. /* TLS_RSA_WITH_AES_128_CBC_SHA256 */ 0x00, 0x3c,
  1628. /* TLS_RSA_WITH_NULL_SHA256 */ 0x00, 0x3b,
  1629. /* TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 */ 0x00, 0xb2,
  1630. /* TLS_DHE_PSK_WITH_NULL_SHA256 */ 0x00, 0xb4,
  1631. /* SHA384 */
  1632. /* TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 */ 0x00, 0xb3,
  1633. /* TLS_DHE_PSK_WITH_NULL_SHA384 */ 0x00, 0xb5,
  1634. /* AES-GCM */
  1635. /* TLS_RSA_WITH_AES_128_GCM_SHA256 */ 0x00, 0x9c,
  1636. /* TLS_RSA_WITH_AES_256_GCM_SHA384 */ 0x00, 0x9d,
  1637. /* TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 */ 0x00, 0x9e,
  1638. /* TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 */ 0x00, 0x9f,
  1639. /* TLS_DH_anon_WITH_AES_256_GCM_SHA384 */ 0x00, 0xa7,
  1640. /* TLS_PSK_WITH_AES_128_GCM_SHA256 */ 0x00, 0xa8,
  1641. /* TLS_PSK_WITH_AES_256_GCM_SHA384 */ 0x00, 0xa9,
  1642. /* TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 */ 0x00, 0xaa,
  1643. /* TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 */ 0x00, 0xab,
  1644. /* ECC AES-GCM, first byte is 0xC0 (ECC_BYTE) */
  1645. /* TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 */ 0xC0, 0x2b,
  1646. /* TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 */ 0xC0, 0x2c,
  1647. /* TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 */ 0xC0, 0x2d,
  1648. /* TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 */ 0xC0, 0x2e,
  1649. /* TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 */ 0xC0, 0x2f,
  1650. /* TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 */ 0xC0, 0x30,
  1651. /* TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 */ 0xC0, 0x31,
  1652. /* TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 */ 0xC0, 0x32,
  1653. /* AES-CCM, first byte is 0xC0 but isn't ECC,
  1654. * also, in some of the other AES-CCM suites
  1655. * there will be second byte number conflicts
  1656. * with non-ECC AES-GCM */
  1657. /* TLS_RSA_WITH_AES_128_CCM_8 */ 0xC0, 0xa0,
  1658. /* TLS_RSA_WITH_AES_256_CCM_8 */ 0xC0, 0xa1,
  1659. /* TLS_ECDHE_ECDSA_WITH_AES_128_CCM */ 0xC0, 0xac,
  1660. /* TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 */ 0xC0, 0xae,
  1661. /* TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 */ 0xC0, 0xaf,
  1662. /* TLS_PSK_WITH_AES_128_CCM */ 0xC0, 0xa4,
  1663. /* TLS_PSK_WITH_AES_256_CCM */ 0xC0, 0xa5,
  1664. /* TLS_PSK_WITH_AES_128_CCM_8 */ 0xC0, 0xa8,
  1665. /* TLS_PSK_WITH_AES_256_CCM_8 */ 0xC0, 0xa9,
  1666. /* TLS_DHE_PSK_WITH_AES_128_CCM */ 0xC0, 0xa6,
  1667. /* TLS_DHE_PSK_WITH_AES_256_CCM */ 0xC0, 0xa7,
  1668. /* Camellia */
  1669. /* TLS_RSA_WITH_CAMELLIA_128_CBC_SHA */ 0x00, 0x41,
  1670. /* TLS_RSA_WITH_CAMELLIA_256_CBC_SHA */ 0x00, 0x84,
  1671. /* TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 */ 0x00, 0xba,
  1672. /* TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 */ 0x00, 0xc0,
  1673. /* TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA */ 0x00, 0x45,
  1674. /* TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA */ 0x00, 0x88,
  1675. /* TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 */ 0x00, 0xbe,
  1676. /* TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 */ 0x00, 0xc4,
  1677. /* chacha20-poly1305 suites first byte is 0xCC (CHACHA_BYTE) */
  1678. /* TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xa8,
  1679. /* TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xa9,
  1680. /* TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xaa,
  1681. /* TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xac,
  1682. /* TLS_PSK_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xab,
  1683. /* TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xad,
  1684. /* chacha20-poly1305 earlier version of nonce and padding (CHACHA_BYTE) */
  1685. /* TLS_ECDHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256 */ 0xCC, 0x13,
  1686. /* TLS_ECDHE_ECDSA_WITH_CHACHA20_OLD_POLY1305_SHA256 */ 0xCC, 0x14,
  1687. /* TLS_DHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256 */ 0xCC, 0x15,
  1688. /* ECDHE_PSK RFC8442, first byte is 0xD0 (ECDHE_PSK_BYTE) */
  1689. /* TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256 */ 0xD0, 0x01,
  1690. /* TLS v1.3 cipher suites */
  1691. /* TLS_AES_128_GCM_SHA256 */ 0x13, 0x01,
  1692. /* TLS_AES_256_GCM_SHA384 */ 0x13, 0x02,
  1693. /* TLS_CHACHA20_POLY1305_SHA256 */ 0x13, 0x03,
  1694. /* TLS_AES_128_CCM_SHA256 */ 0x13, 0x04,
  1695. /* TLS_AES_128_CCM_8_SHA256 */ 0x13, 0x05,
  1696. /* TLS v1.3 Integrity only cipher suites - 0xC0 (ECC) first byte */
  1697. /* TLS_SHA256_SHA256 */ 0xC0, 0xB4,
  1698. /* TLS_SHA384_SHA384 */ 0xC0, 0xB5
  1699. };
  1700. #ifndef NO_RSA
  1701. testCertFile = svrCertFile;
  1702. testKeyFile = svrKeyFile;
  1703. #elif defined(HAVE_ECC)
  1704. testCertFile = eccCertFile;
  1705. testKeyFile = eccKeyFile;
  1706. #endif
  1707. #ifndef NO_WOLFSSL_SERVER
  1708. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1709. #else
  1710. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1711. #endif
  1712. ExpectTrue(wolfSSL_CTX_set_cipher_list_bytes(ctx, &cipherList[0U],
  1713. sizeof(cipherList)));
  1714. wolfSSL_CTX_free(ctx);
  1715. ctx = NULL;
  1716. #ifndef NO_WOLFSSL_SERVER
  1717. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1718. #else
  1719. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1720. #endif
  1721. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  1722. WOLFSSL_FILETYPE_PEM));
  1723. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  1724. WOLFSSL_FILETYPE_PEM));
  1725. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1726. ExpectTrue(wolfSSL_set_cipher_list_bytes(ssl, &cipherList[0U],
  1727. sizeof(cipherList)));
  1728. wolfSSL_free(ssl);
  1729. wolfSSL_CTX_free(ctx);
  1730. #endif /* (OPENSSL_EXTRA || WOLFSSL_SET_CIPHER_BYTES) &&
  1731. (!NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER) && (!NO_RSA || HAVE_ECC) */
  1732. return EXPECT_RESULT();
  1733. }
  1734. static int test_wolfSSL_CTX_use_certificate(void)
  1735. {
  1736. EXPECT_DECLS;
  1737. #if defined(OPENSSL_EXTRA) || defined(HAVE_LIGHTY) || \
  1738. defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(HAVE_STUNNEL) || \
  1739. defined(WOLFSSL_NGINX) || defined(HAVE_POCO_LIB) || \
  1740. defined(WOLFSSL_HAPROXY)
  1741. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  1742. WOLFSSL_CTX* ctx = NULL;
  1743. X509* x509 = NULL;
  1744. #ifndef NO_WOLFSSL_SERVER
  1745. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1746. #else
  1747. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1748. #endif
  1749. ExpectNotNull(x509 = wolfSSL_X509_new());
  1750. /* Negative tests. */
  1751. ExpectIntEQ(SSL_CTX_use_certificate(NULL, NULL), 0);
  1752. ExpectIntEQ(SSL_CTX_use_certificate(ctx, NULL), 0);
  1753. ExpectIntEQ(SSL_CTX_use_certificate(NULL, x509), 0);
  1754. /* Empty certificate */
  1755. ExpectIntEQ(SSL_CTX_use_certificate(ctx, x509), 0);
  1756. wolfSSL_X509_free(x509);
  1757. wolfSSL_CTX_free(ctx);
  1758. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  1759. #endif
  1760. return EXPECT_RESULT();
  1761. }
  1762. static int test_wolfSSL_CTX_use_certificate_file(void)
  1763. {
  1764. EXPECT_DECLS;
  1765. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_WOLFSSL_SERVER)
  1766. WOLFSSL_CTX *ctx = NULL;
  1767. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1768. /* invalid context */
  1769. ExpectFalse(wolfSSL_CTX_use_certificate_file(NULL, svrCertFile,
  1770. WOLFSSL_FILETYPE_PEM));
  1771. /* invalid cert file */
  1772. ExpectFalse(wolfSSL_CTX_use_certificate_file(ctx, bogusFile,
  1773. WOLFSSL_FILETYPE_PEM));
  1774. /* invalid cert type */
  1775. ExpectFalse(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, 9999));
  1776. #ifdef NO_RSA
  1777. /* rsa needed */
  1778. ExpectFalse(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  1779. WOLFSSL_FILETYPE_PEM));
  1780. #else
  1781. /* success */
  1782. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  1783. WOLFSSL_FILETYPE_PEM));
  1784. #endif
  1785. wolfSSL_CTX_free(ctx);
  1786. #endif
  1787. return EXPECT_RESULT();
  1788. }
  1789. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO)) && !defined(NO_RSA)
  1790. static int test_wolfSSL_CTX_use_certificate_ASN1(void)
  1791. {
  1792. EXPECT_DECLS;
  1793. #if !defined(NO_CERTS) && !defined(NO_WOLFSSL_SERVER) && !defined(NO_ASN)
  1794. WOLFSSL_CTX* ctx = NULL;
  1795. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1796. /* Failure cases. */
  1797. ExpectIntEQ(SSL_CTX_use_certificate_ASN1(NULL, 0, NULL ),
  1798. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1799. ExpectIntEQ(SSL_CTX_use_certificate_ASN1(ctx , 0, NULL ),
  1800. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1801. ExpectIntEQ(SSL_CTX_use_certificate_ASN1(NULL, 0, server_cert_der_2048),
  1802. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1803. ExpectIntEQ(SSL_CTX_use_certificate_ASN1(ctx , 0, server_cert_der_2048),
  1804. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1805. ExpectIntEQ(SSL_CTX_use_certificate_ASN1(ctx, sizeof_server_cert_der_2048,
  1806. server_cert_der_2048), WOLFSSL_SUCCESS);
  1807. wolfSSL_CTX_free(ctx);
  1808. #endif
  1809. return EXPECT_RESULT();
  1810. }
  1811. #endif /* (OPENSSL_ALL || WOLFSSL_ASIO) && !NO_RSA */
  1812. /* Test function for wolfSSL_CTX_use_certificate_buffer. Load cert into
  1813. * context using buffer.
  1814. * PRE: NO_CERTS not defined; USE_CERT_BUFFERS_2048 defined; compile with
  1815. * --enable-testcert flag.
  1816. */
  1817. static int test_wolfSSL_CTX_use_certificate_buffer(void)
  1818. {
  1819. EXPECT_DECLS;
  1820. #if !defined(NO_CERTS) && defined(USE_CERT_BUFFERS_2048) && \
  1821. !defined(NO_RSA) && !defined(NO_WOLFSSL_SERVER)
  1822. WOLFSSL_CTX* ctx = NULL;
  1823. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1824. /* Invalid parameters. */
  1825. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(NULL, NULL, 0,
  1826. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1827. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(ctx, NULL, 0,
  1828. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  1829. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(NULL, server_cert_der_2048,
  1830. 0, WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1831. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(ctx, server_cert_der_2048, 0,
  1832. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  1833. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(ctx,
  1834. server_cert_der_2048, sizeof_server_cert_der_2048,
  1835. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  1836. wolfSSL_CTX_free(ctx);
  1837. #endif
  1838. return EXPECT_RESULT();
  1839. } /* END test_wolfSSL_CTX_use_certificate_buffer */
  1840. static int test_wolfSSL_use_certificate_buffer(void)
  1841. {
  1842. EXPECT_DECLS;
  1843. #if !defined(NO_CERTS) && defined(USE_CERT_BUFFERS_2048) && \
  1844. !defined(NO_RSA) && !defined(NO_WOLFSSL_CLIENT)
  1845. WOLFSSL_CTX* ctx = NULL;
  1846. WOLFSSL* ssl = NULL;
  1847. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1848. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1849. /* Invalid parameters. */
  1850. ExpectIntEQ(wolfSSL_use_certificate_buffer(NULL, NULL, 0,
  1851. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1852. ExpectIntEQ(wolfSSL_use_certificate_buffer(ssl, NULL, 0,
  1853. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  1854. ExpectIntEQ(wolfSSL_use_certificate_buffer(NULL, client_cert_der_2048, 0,
  1855. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1856. ExpectIntEQ(wolfSSL_use_certificate_buffer(ssl, client_cert_der_2048, 0,
  1857. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  1858. ExpectIntEQ(wolfSSL_use_certificate_buffer(ssl,
  1859. client_cert_der_2048, sizeof_client_cert_der_2048,
  1860. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  1861. wolfSSL_free(ssl);
  1862. wolfSSL_CTX_free(ctx);
  1863. #endif
  1864. return EXPECT_RESULT();
  1865. }
  1866. static int test_wolfSSL_CTX_use_PrivateKey_file(void)
  1867. {
  1868. EXPECT_DECLS;
  1869. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_WOLFSSL_SERVER)
  1870. WOLFSSL_CTX *ctx = NULL;
  1871. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1872. /* invalid context */
  1873. ExpectFalse(wolfSSL_CTX_use_PrivateKey_file(NULL, svrKeyFile,
  1874. WOLFSSL_FILETYPE_PEM));
  1875. /* invalid key file */
  1876. ExpectFalse(wolfSSL_CTX_use_PrivateKey_file(ctx, bogusFile,
  1877. WOLFSSL_FILETYPE_PEM));
  1878. /* invalid key type */
  1879. ExpectFalse(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, 9999));
  1880. /* success */
  1881. #ifdef NO_RSA
  1882. /* rsa needed */
  1883. ExpectFalse(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  1884. WOLFSSL_FILETYPE_PEM));
  1885. #else
  1886. /* success */
  1887. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  1888. WOLFSSL_FILETYPE_PEM));
  1889. #endif
  1890. wolfSSL_CTX_free(ctx);
  1891. #endif
  1892. return EXPECT_RESULT();
  1893. }
  1894. static int test_wolfSSL_CTX_use_RSAPrivateKey_file(void)
  1895. {
  1896. EXPECT_DECLS;
  1897. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  1898. !defined(NO_WOLFSSL_SERVER) && defined(OPENSSL_EXTRA)
  1899. WOLFSSL_CTX *ctx = NULL;
  1900. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1901. /* invalid context */
  1902. ExpectIntEQ(wolfSSL_CTX_use_RSAPrivateKey_file(NULL, svrKeyFile,
  1903. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1904. /* invalid key file */
  1905. ExpectIntEQ(wolfSSL_CTX_use_RSAPrivateKey_file(ctx, bogusFile,
  1906. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1907. /* invalid key type */
  1908. ExpectIntEQ(wolfSSL_CTX_use_RSAPrivateKey_file(ctx, svrKeyFile, 9999),
  1909. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1910. /* success */
  1911. #ifdef NO_RSA
  1912. /* rsa needed */
  1913. ExpectIntEQ(wolfSSL_CTX_use_RSAPrivateKey_file(ctx, svrKeyFile,
  1914. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1915. #else
  1916. /* success */
  1917. ExpectIntEQ(wolfSSL_CTX_use_RSAPrivateKey_file(ctx, svrKeyFile,
  1918. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  1919. #endif
  1920. wolfSSL_CTX_free(ctx);
  1921. #endif
  1922. return EXPECT_RESULT();
  1923. }
  1924. static int test_wolfSSL_use_RSAPrivateKey_file(void)
  1925. {
  1926. EXPECT_DECLS;
  1927. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  1928. !defined(NO_WOLFSSL_CLIENT) && defined(OPENSSL_EXTRA)
  1929. WOLFSSL_CTX* ctx = NULL;
  1930. WOLFSSL* ssl = NULL;
  1931. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1932. ExpectNotNull(ssl = SSL_new(ctx));
  1933. /* invalid context */
  1934. ExpectIntEQ(wolfSSL_use_RSAPrivateKey_file(NULL, svrKeyFile,
  1935. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1936. /* invalid key file */
  1937. ExpectIntEQ(wolfSSL_use_RSAPrivateKey_file(ssl, bogusFile,
  1938. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1939. /* invalid key type */
  1940. ExpectIntEQ(wolfSSL_use_RSAPrivateKey_file(ssl, svrKeyFile, 9999),
  1941. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1942. /* success */
  1943. #ifdef NO_RSA
  1944. /* rsa needed */
  1945. ExpectIntEQ(wolfSSL_use_RSAPrivateKey_file(ssl, svrKeyFile,
  1946. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1947. #else
  1948. /* success */
  1949. ExpectIntEQ(wolfSSL_use_RSAPrivateKey_file(ssl, svrKeyFile,
  1950. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  1951. #endif
  1952. wolfSSL_free(ssl);
  1953. wolfSSL_CTX_free(ctx);
  1954. #endif
  1955. return EXPECT_RESULT();
  1956. }
  1957. static int test_wolfSSL_CTX_use_PrivateKey(void)
  1958. {
  1959. EXPECT_DECLS;
  1960. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  1961. !defined(NO_WOLFSSL_SERVER) && defined(OPENSSL_EXTRA)
  1962. WOLFSSL_CTX *ctx = NULL;
  1963. WOLFSSL_EVP_PKEY* pkey = NULL;
  1964. const unsigned char* p;
  1965. (void)p;
  1966. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1967. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  1968. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1969. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1970. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(NULL, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1971. /* No data. */
  1972. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1973. wolfSSL_EVP_PKEY_free(pkey);
  1974. pkey = NULL;
  1975. #if defined(USE_CERT_BUFFERS_2048)
  1976. #if !defined(NO_RSA)
  1977. p = client_key_der_2048;
  1978. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_RSA, NULL, &p,
  1979. sizeof_client_key_der_2048));
  1980. #if defined(WOLFSSL_KEY_GEN)
  1981. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WOLFSSL_SUCCESS);
  1982. #else
  1983. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1984. #endif
  1985. wolfSSL_EVP_PKEY_free(pkey);
  1986. pkey = NULL;
  1987. #endif
  1988. #if defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || defined(WOLFSSL_OPENSSH)
  1989. #ifndef NO_DSA
  1990. p = dsa_key_der_2048;
  1991. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_DSA, NULL, &p,
  1992. sizeof_dsa_key_der_2048));
  1993. #if !defined(HAVE_SELFTEST) && (defined(WOLFSSL_KEY_GEN) || \
  1994. defined(WOLFSSL_CERT_GEN))
  1995. /* Not supported in ProcessBuffer. */
  1996. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE));
  1997. #else
  1998. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1999. #endif
  2000. wolfSSL_EVP_PKEY_free(pkey);
  2001. pkey = NULL;
  2002. #endif
  2003. #endif /* WOLFSSL_QT || OPENSSL_ALL || WOLFSSL_OPENSSH */
  2004. #if !defined(NO_DH) && defined(OPENSSL_ALL) && \
  2005. (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0))
  2006. p = dh_ffdhe_statickey_der_2048;
  2007. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_DH, NULL, &p,
  2008. sizeof_dh_ffdhe_statickey_der_2048));
  2009. /* Not supported. */
  2010. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  2011. wolfSSL_EVP_PKEY_free(pkey);
  2012. pkey = NULL;
  2013. #endif
  2014. #endif /* USE_CERT_BUFFERS_2048 */
  2015. #if defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  2016. p = ecc_clikey_der_256;
  2017. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &p,
  2018. sizeof_ecc_clikey_der_256));
  2019. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WOLFSSL_SUCCESS);
  2020. wolfSSL_EVP_PKEY_free(pkey);
  2021. pkey = NULL;
  2022. #endif
  2023. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL,
  2024. (unsigned char*)"01234567012345670123456701234567", 32));
  2025. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  2026. wolfSSL_EVP_PKEY_free(pkey);
  2027. pkey = NULL;
  2028. wolfSSL_CTX_free(ctx);
  2029. #endif
  2030. return EXPECT_RESULT();
  2031. }
  2032. /* test both file and buffer versions along with unloading trusted peer certs */
  2033. static int test_wolfSSL_CTX_trust_peer_cert(void)
  2034. {
  2035. EXPECT_DECLS;
  2036. #if !defined(NO_CERTS) && defined(WOLFSSL_TRUST_PEER_CERT) && \
  2037. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_RSA)
  2038. WOLFSSL_CTX *ctx = NULL;
  2039. WOLFSSL* ssl = NULL;
  2040. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  2041. ExpectNotNull(ssl = wolfSSL_new(ctx));
  2042. #if !defined(NO_FILESYSTEM)
  2043. /* invalid file */
  2044. ExpectIntNE(wolfSSL_CTX_trust_peer_cert(ctx, NULL,
  2045. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  2046. ExpectIntNE(wolfSSL_CTX_trust_peer_cert(ctx, bogusFile,
  2047. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  2048. ExpectIntNE(wolfSSL_CTX_trust_peer_cert(ctx, cliCertFile,
  2049. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2050. /* success */
  2051. ExpectIntEQ(wolfSSL_CTX_trust_peer_cert(ctx, cliCertFile,
  2052. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  2053. /* unload cert */
  2054. ExpectIntNE(wolfSSL_CTX_Unload_trust_peers(NULL), WOLFSSL_SUCCESS);
  2055. ExpectIntEQ(wolfSSL_CTX_Unload_trust_peers(ctx), WOLFSSL_SUCCESS);
  2056. /* invalid file */
  2057. ExpectIntNE(wolfSSL_trust_peer_cert(ssl, NULL,
  2058. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  2059. ExpectIntNE(wolfSSL_trust_peer_cert(ssl, bogusFile,
  2060. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  2061. ExpectIntNE(wolfSSL_trust_peer_cert(ssl, cliCertFile,
  2062. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2063. /* success */
  2064. ExpectIntEQ(wolfSSL_trust_peer_cert(ssl, cliCertFile,
  2065. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  2066. #ifdef WOLFSSL_LOCAL_X509_STORE
  2067. /* unload cert */
  2068. ExpectIntNE(wolfSSL_Unload_trust_peers(NULL), WOLFSSL_SUCCESS);
  2069. ExpectIntEQ(wolfSSL_Unload_trust_peers(ssl), WOLFSSL_SUCCESS);
  2070. #endif
  2071. #endif
  2072. /* Test of loading certs from buffers */
  2073. /* invalid buffer */
  2074. ExpectIntNE(wolfSSL_CTX_trust_peer_buffer(ctx, NULL, -1,
  2075. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2076. /* success */
  2077. #ifdef USE_CERT_BUFFERS_1024
  2078. ExpectIntEQ(wolfSSL_CTX_trust_peer_buffer(ctx, client_cert_der_1024,
  2079. sizeof_client_cert_der_1024, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2080. #endif
  2081. #ifdef USE_CERT_BUFFERS_2048
  2082. ExpectIntEQ(wolfSSL_CTX_trust_peer_buffer(ctx, client_cert_der_2048,
  2083. sizeof_client_cert_der_2048, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2084. #endif
  2085. /* unload cert */
  2086. ExpectIntNE(wolfSSL_CTX_Unload_trust_peers(NULL), WOLFSSL_SUCCESS);
  2087. ExpectIntEQ(wolfSSL_CTX_Unload_trust_peers(ctx), WOLFSSL_SUCCESS);
  2088. wolfSSL_free(ssl);
  2089. wolfSSL_CTX_free(ctx);
  2090. #endif
  2091. return EXPECT_RESULT();
  2092. }
  2093. static int test_wolfSSL_CTX_load_verify_locations(void)
  2094. {
  2095. EXPECT_DECLS;
  2096. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_WOLFSSL_CLIENT)
  2097. WOLFSSL_CTX *ctx = NULL;
  2098. #ifndef NO_RSA
  2099. WOLFSSL_CERT_MANAGER* cm = NULL;
  2100. #ifdef PERSIST_CERT_CACHE
  2101. int cacheSz = 0;
  2102. unsigned char* cache = NULL;
  2103. int used = 0;
  2104. #ifndef NO_FILESYSTEM
  2105. const char* cacheFile = "./tests/cert_cache.tmp";
  2106. #endif
  2107. int i;
  2108. int t;
  2109. int* p;
  2110. #endif
  2111. #endif
  2112. #if !defined(NO_WOLFSSL_DIR) && !defined(WOLFSSL_TIRTOS)
  2113. const char* load_certs_path = "./certs/external";
  2114. const char* load_no_certs_path = "./examples";
  2115. const char* load_expired_path = "./certs/test/expired";
  2116. #endif
  2117. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  2118. /* invalid arguments */
  2119. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(NULL, caCertFile, NULL),
  2120. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  2121. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, NULL, NULL),
  2122. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  2123. /* invalid ca file */
  2124. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, bogusFile, NULL),
  2125. WS_RETURN_CODE(WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE),
  2126. WC_NO_ERR_TRACE(WOLFSSL_FAILURE)));
  2127. #if !defined(NO_WOLFSSL_DIR) && !defined(WOLFSSL_TIRTOS) && \
  2128. ((defined(WOLFSSL_QT) || defined(WOLFSSL_IGNORE_BAD_CERT_PATH)) && \
  2129. !(WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS & WOLFSSL_LOAD_FLAG_IGNORE_BAD_PATH_ERR))
  2130. /* invalid path */
  2131. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, NULL, bogusFile),
  2132. WS_RETURN_CODE(WC_NO_ERR_TRACE(BAD_PATH_ERROR),WC_NO_ERR_TRACE(WOLFSSL_FAILURE)));
  2133. #endif
  2134. #if defined(WOLFSSL_QT) || defined(WOLFSSL_IGNORE_BAD_CERT_PATH)
  2135. /* test ignoring the invalid path */
  2136. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL, bogusFile,
  2137. WOLFSSL_LOAD_FLAG_IGNORE_BAD_PATH_ERR), WOLFSSL_SUCCESS);
  2138. #endif
  2139. /* load ca cert */
  2140. #ifdef NO_RSA
  2141. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, NULL),
  2142. WS_RETURN_CODE(WC_NO_ERR_TRACE(ASN_UNKNOWN_OID_E),WC_NO_ERR_TRACE(WOLFSSL_FAILURE)));
  2143. #else /* Skip the following test without RSA certs. */
  2144. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, NULL),
  2145. WOLFSSL_SUCCESS);
  2146. #ifdef PERSIST_CERT_CACHE
  2147. /* Get cert cache size */
  2148. ExpectIntGT(cacheSz = wolfSSL_CTX_get_cert_cache_memsize(ctx), 0);
  2149. ExpectNotNull(cache = (byte*)XMALLOC(cacheSz, NULL,
  2150. DYNAMIC_TYPE_TMP_BUFFER));
  2151. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(NULL, NULL, -1, NULL),
  2152. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2153. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, NULL, -1, NULL),
  2154. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2155. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(NULL, cache, -1, NULL),
  2156. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2157. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(NULL, NULL, cacheSz, NULL),
  2158. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2159. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(NULL, NULL, -1, &used),
  2160. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2161. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(NULL, cache, cacheSz, &used),
  2162. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2163. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, NULL, cacheSz, &used),
  2164. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2165. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, cache, -1, &used),
  2166. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2167. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, cache, cacheSz, NULL),
  2168. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2169. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, cache, cacheSz - 10, &used),
  2170. WC_NO_ERR_TRACE(BUFFER_E));
  2171. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, cache, cacheSz, &used), 1);
  2172. ExpectIntEQ(cacheSz, used);
  2173. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(NULL, NULL, -1),
  2174. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2175. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, NULL, -1),
  2176. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2177. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(NULL, cache, -1),
  2178. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2179. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(NULL, NULL, cacheSz),
  2180. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2181. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(NULL, cache, cacheSz),
  2182. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2183. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, NULL, cacheSz),
  2184. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2185. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, -1),
  2186. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2187. /* Smaller than header. */
  2188. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, 1), WC_NO_ERR_TRACE(BUFFER_E));
  2189. for (i = 1; i < cacheSz; i++) {
  2190. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz - i),
  2191. WC_NO_ERR_TRACE(BUFFER_E));
  2192. }
  2193. if (EXPECT_SUCCESS()) {
  2194. /* Modify header for bad results! */
  2195. p = (int*)cache;
  2196. /* version */
  2197. t = p[0]; p[0] = 0xff;
  2198. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz),
  2199. WC_NO_ERR_TRACE(CACHE_MATCH_ERROR));
  2200. p[0] = t; p++;
  2201. /* rows */
  2202. t = p[0]; p[0] = 0xff;
  2203. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz),
  2204. WC_NO_ERR_TRACE(CACHE_MATCH_ERROR));
  2205. p[0] = t; p++;
  2206. /* columns[0] */
  2207. t = p[0]; p[0] = -1;
  2208. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz),
  2209. WC_NO_ERR_TRACE(PARSE_ERROR));
  2210. p[0] = t; p += CA_TABLE_SIZE;
  2211. /* signerSz*/
  2212. t = p[0]; p[0] = 0xff;
  2213. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz),
  2214. WC_NO_ERR_TRACE(CACHE_MATCH_ERROR));
  2215. p[0] = t;
  2216. }
  2217. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz), 1);
  2218. ExpectIntEQ(cacheSz = wolfSSL_CTX_get_cert_cache_memsize(ctx), used);
  2219. #ifndef NO_FILESYSTEM
  2220. ExpectIntEQ(wolfSSL_CTX_save_cert_cache(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2221. ExpectIntEQ(wolfSSL_CTX_save_cert_cache(ctx, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2222. ExpectIntEQ(wolfSSL_CTX_save_cert_cache(NULL, cacheFile), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2223. ExpectIntEQ(wolfSSL_CTX_save_cert_cache(ctx, cacheFile), 1);
  2224. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2225. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(ctx, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2226. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(NULL, cacheFile), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2227. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(ctx, "no-file"),
  2228. WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE));
  2229. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(ctx, cacheFile), 1);
  2230. /* File contents is not a cache. */
  2231. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(ctx, "./certs/ca-cert.pem"),
  2232. WC_NO_ERR_TRACE(CACHE_MATCH_ERROR));
  2233. #endif
  2234. XFREE(cache, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  2235. #endif
  2236. /* Test unloading CA's */
  2237. ExpectIntEQ(wolfSSL_CTX_UnloadCAs(ctx), WOLFSSL_SUCCESS);
  2238. #ifdef PERSIST_CERT_CACHE
  2239. /* Verify no certs (result is less than cacheSz) */
  2240. ExpectIntGT(cacheSz, wolfSSL_CTX_get_cert_cache_memsize(ctx));
  2241. #endif
  2242. /* load ca cert again */
  2243. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, NULL),
  2244. WOLFSSL_SUCCESS);
  2245. /* Test getting CERT_MANAGER */
  2246. ExpectNotNull(cm = wolfSSL_CTX_GetCertManager(ctx));
  2247. /* Test unloading CA's using CM */
  2248. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  2249. #ifdef PERSIST_CERT_CACHE
  2250. /* Verify no certs (result is less than cacheSz) */
  2251. ExpectIntGT(cacheSz, wolfSSL_CTX_get_cert_cache_memsize(ctx));
  2252. #endif
  2253. #endif
  2254. #if !defined(NO_WOLFSSL_DIR) && !defined(WOLFSSL_TIRTOS)
  2255. /* Test loading CA certificates using a path */
  2256. #ifdef NO_RSA
  2257. /* failure here okay since certs in external directory are RSA */
  2258. ExpectIntNE(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL, load_certs_path,
  2259. WOLFSSL_LOAD_FLAG_PEM_CA_ONLY), WOLFSSL_SUCCESS);
  2260. #else
  2261. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL, load_certs_path,
  2262. WOLFSSL_LOAD_FLAG_PEM_CA_ONLY), WOLFSSL_SUCCESS);
  2263. #endif
  2264. /* Test loading path with no files */
  2265. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL,
  2266. load_no_certs_path, WOLFSSL_LOAD_FLAG_PEM_CA_ONLY),
  2267. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  2268. /* Test loading expired CA certificates */
  2269. #ifdef NO_RSA
  2270. ExpectIntNE(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL,
  2271. load_expired_path,
  2272. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY | WOLFSSL_LOAD_FLAG_PEM_CA_ONLY),
  2273. WOLFSSL_SUCCESS);
  2274. #else
  2275. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL,
  2276. load_expired_path,
  2277. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY | WOLFSSL_LOAD_FLAG_PEM_CA_ONLY),
  2278. WOLFSSL_SUCCESS);
  2279. #endif
  2280. /* Test loading CA certificates and ignoring all errors */
  2281. #ifdef NO_RSA
  2282. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL, load_certs_path,
  2283. WOLFSSL_LOAD_FLAG_IGNORE_ERR), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  2284. #else
  2285. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL, load_certs_path,
  2286. WOLFSSL_LOAD_FLAG_IGNORE_ERR), WOLFSSL_SUCCESS);
  2287. #endif
  2288. #endif
  2289. wolfSSL_CTX_free(ctx);
  2290. #endif
  2291. return EXPECT_RESULT();
  2292. }
  2293. static int test_wolfSSL_CTX_load_system_CA_certs(void)
  2294. {
  2295. int res = TEST_SKIPPED;
  2296. #if defined(WOLFSSL_SYS_CA_CERTS) && !defined(NO_WOLFSSL_CLIENT) && \
  2297. (!defined(NO_RSA) || defined(HAVE_ECC))
  2298. WOLFSSL_CTX* ctx;
  2299. byte dirValid = 0;
  2300. int ret = 0;
  2301. ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  2302. if (ctx == NULL) {
  2303. fprintf(stderr, "wolfSSL_CTX_new failed.\n");
  2304. ret = -1;
  2305. }
  2306. if (ret == 0) {
  2307. #if defined(USE_WINDOWS_API) || defined(__APPLE__)
  2308. dirValid = 1;
  2309. #else
  2310. word32 numDirs;
  2311. const char** caDirs = wolfSSL_get_system_CA_dirs(&numDirs);
  2312. if (caDirs == NULL || numDirs == 0) {
  2313. fprintf(stderr, "wolfSSL_get_system_CA_dirs failed.\n");
  2314. ret = -1;
  2315. }
  2316. else {
  2317. ReadDirCtx dirCtx;
  2318. word32 i;
  2319. for (i = 0; i < numDirs; ++i) {
  2320. if (wc_ReadDirFirst(&dirCtx, caDirs[i], NULL) == 0) {
  2321. /* Directory isn't empty. */
  2322. dirValid = 1;
  2323. wc_ReadDirClose(&dirCtx);
  2324. break;
  2325. }
  2326. }
  2327. }
  2328. #endif
  2329. }
  2330. /*
  2331. * If the directory isn't empty, we should be able to load CA
  2332. * certs from it. On Windows/Mac, we assume the CA cert stores are
  2333. * usable.
  2334. */
  2335. if (ret == 0 && dirValid && wolfSSL_CTX_load_system_CA_certs(ctx) !=
  2336. WOLFSSL_SUCCESS) {
  2337. fprintf(stderr, "wolfSSL_CTX_load_system_CA_certs failed.\n");
  2338. ret = -1;
  2339. }
  2340. #ifdef OPENSSL_EXTRA
  2341. if (ret == 0 &&
  2342. wolfSSL_CTX_set_default_verify_paths(ctx) != WOLFSSL_SUCCESS) {
  2343. fprintf(stderr, "wolfSSL_CTX_set_default_verify_paths failed.\n");
  2344. ret = -1;
  2345. }
  2346. #endif /* OPENSSL_EXTRA */
  2347. wolfSSL_CTX_free(ctx);
  2348. res = TEST_RES_CHECK(ret == 0);
  2349. #endif /* WOLFSSL_SYS_CA_CERTS && !NO_WOLFSSL_CLIENT */
  2350. return res;
  2351. }
  2352. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
  2353. static int test_cm_load_ca_buffer(const byte* cert_buf, size_t cert_sz,
  2354. int file_type)
  2355. {
  2356. int ret;
  2357. WOLFSSL_CERT_MANAGER* cm;
  2358. cm = wolfSSL_CertManagerNew();
  2359. if (cm == NULL) {
  2360. fprintf(stderr, "test_cm_load_ca failed\n");
  2361. return -1;
  2362. }
  2363. ret = wolfSSL_CertManagerLoadCABuffer(cm, cert_buf, cert_sz, file_type);
  2364. wolfSSL_CertManagerFree(cm);
  2365. return ret;
  2366. }
  2367. static int test_cm_load_ca_file(const char* ca_cert_file)
  2368. {
  2369. int ret = 0;
  2370. byte* cert_buf = NULL;
  2371. size_t cert_sz = 0;
  2372. #if defined(WOLFSSL_PEM_TO_DER)
  2373. DerBuffer* pDer = NULL;
  2374. #endif
  2375. ret = load_file(ca_cert_file, &cert_buf, &cert_sz);
  2376. if (ret == 0) {
  2377. /* normal test */
  2378. ret = test_cm_load_ca_buffer(cert_buf, cert_sz, WOLFSSL_FILETYPE_PEM);
  2379. if (ret == WOLFSSL_SUCCESS) {
  2380. /* test including null terminator in length */
  2381. byte* tmp = (byte*)realloc(cert_buf, cert_sz+1);
  2382. if (tmp == NULL) {
  2383. ret = MEMORY_E;
  2384. }
  2385. else {
  2386. cert_buf = tmp;
  2387. cert_buf[cert_sz] = '\0';
  2388. ret = test_cm_load_ca_buffer(cert_buf, cert_sz+1,
  2389. WOLFSSL_FILETYPE_PEM);
  2390. }
  2391. }
  2392. #if defined(WOLFSSL_PEM_TO_DER)
  2393. if (ret == WOLFSSL_SUCCESS) {
  2394. /* test loading DER */
  2395. ret = wc_PemToDer(cert_buf, cert_sz, CA_TYPE, &pDer, NULL, NULL, NULL);
  2396. if (ret == 0 && pDer != NULL) {
  2397. ret = test_cm_load_ca_buffer(pDer->buffer, pDer->length,
  2398. WOLFSSL_FILETYPE_ASN1);
  2399. wc_FreeDer(&pDer);
  2400. }
  2401. }
  2402. #endif
  2403. }
  2404. free(cert_buf);
  2405. return ret;
  2406. }
  2407. static int test_cm_load_ca_buffer_ex(const byte* cert_buf, size_t cert_sz,
  2408. int file_type, word32 flags)
  2409. {
  2410. int ret;
  2411. WOLFSSL_CERT_MANAGER* cm;
  2412. cm = wolfSSL_CertManagerNew();
  2413. if (cm == NULL) {
  2414. fprintf(stderr, "test_cm_load_ca failed\n");
  2415. return -1;
  2416. }
  2417. ret = wolfSSL_CertManagerLoadCABuffer_ex(cm, cert_buf, cert_sz, file_type,
  2418. 0, flags);
  2419. wolfSSL_CertManagerFree(cm);
  2420. return ret;
  2421. }
  2422. static int test_cm_load_ca_file_ex(const char* ca_cert_file, word32 flags)
  2423. {
  2424. int ret = 0;
  2425. byte* cert_buf = NULL;
  2426. size_t cert_sz = 0;
  2427. #if defined(WOLFSSL_PEM_TO_DER)
  2428. DerBuffer* pDer = NULL;
  2429. #endif
  2430. ret = load_file(ca_cert_file, &cert_buf, &cert_sz);
  2431. if (ret == 0) {
  2432. /* normal test */
  2433. ret = test_cm_load_ca_buffer_ex(cert_buf, cert_sz,
  2434. WOLFSSL_FILETYPE_PEM, flags);
  2435. if (ret == WOLFSSL_SUCCESS) {
  2436. /* test including null terminator in length */
  2437. byte* tmp = (byte*)realloc(cert_buf, cert_sz+1);
  2438. if (tmp == NULL) {
  2439. ret = MEMORY_E;
  2440. }
  2441. else {
  2442. cert_buf = tmp;
  2443. cert_buf[cert_sz] = '\0';
  2444. ret = test_cm_load_ca_buffer_ex(cert_buf, cert_sz+1,
  2445. WOLFSSL_FILETYPE_PEM, flags);
  2446. }
  2447. }
  2448. #if defined(WOLFSSL_PEM_TO_DER)
  2449. if (ret == WOLFSSL_SUCCESS) {
  2450. /* test loading DER */
  2451. ret = wc_PemToDer(cert_buf, cert_sz, CA_TYPE, &pDer, NULL, NULL, NULL);
  2452. if (ret == 0 && pDer != NULL) {
  2453. ret = test_cm_load_ca_buffer_ex(pDer->buffer, pDer->length,
  2454. WOLFSSL_FILETYPE_ASN1, flags);
  2455. wc_FreeDer(&pDer);
  2456. }
  2457. }
  2458. #endif
  2459. }
  2460. free(cert_buf);
  2461. return ret;
  2462. }
  2463. #endif /* !NO_FILESYSTEM && !NO_CERTS */
  2464. static int test_wolfSSL_CertManagerAPI(void)
  2465. {
  2466. EXPECT_DECLS;
  2467. #ifndef NO_CERTS
  2468. WOLFSSL_CERT_MANAGER* cm = NULL;
  2469. unsigned char c;
  2470. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  2471. wolfSSL_CertManagerFree(NULL);
  2472. ExpectIntEQ(wolfSSL_CertManager_up_ref(NULL), 0);
  2473. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2474. #ifdef WOLFSSL_TRUST_PEER_CERT
  2475. ExpectIntEQ(wolfSSL_CertManagerUnload_trust_peers(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2476. #endif
  2477. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer_ex(NULL, &c, 1,
  2478. WOLFSSL_FILETYPE_ASN1, 0, 0), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2479. #if !defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)
  2480. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(NULL, NULL, -1,
  2481. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2482. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, NULL, -1,
  2483. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2484. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(NULL, &c, -1,
  2485. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2486. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(NULL, 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(cm, NULL, 1,
  2491. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2492. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, &c, -1,
  2493. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2494. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, &c, 1, -1),
  2495. WC_NO_ERR_TRACE(WOLFSSL_BAD_FILETYPE));
  2496. #endif
  2497. #if !defined(NO_FILESYSTEM)
  2498. {
  2499. const char* ca_cert = "./certs/ca-cert.pem";
  2500. #if !defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)
  2501. const char* ca_cert_der = "./certs/ca-cert.der";
  2502. #endif
  2503. const char* ca_path = "./certs";
  2504. #if !defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)
  2505. ExpectIntEQ(wolfSSL_CertManagerVerify(NULL, NULL, -1),
  2506. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2507. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, NULL, WOLFSSL_FILETYPE_ASN1),
  2508. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2509. ExpectIntEQ(wolfSSL_CertManagerVerify(NULL, ca_cert,
  2510. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2511. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, ca_cert, -1),
  2512. WC_NO_ERR_TRACE(WOLFSSL_BAD_FILETYPE));
  2513. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, "no-file",
  2514. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE));
  2515. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, ca_cert_der,
  2516. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  2517. #endif
  2518. ExpectIntEQ(wolfSSL_CertManagerLoadCA(NULL, NULL, NULL),
  2519. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2520. ExpectIntEQ(wolfSSL_CertManagerLoadCA(NULL, ca_cert, NULL),
  2521. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2522. ExpectIntEQ(wolfSSL_CertManagerLoadCA(NULL, NULL, ca_path),
  2523. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2524. ExpectIntEQ(wolfSSL_CertManagerLoadCA(NULL, ca_cert, ca_path),
  2525. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2526. }
  2527. #endif
  2528. #ifdef OPENSSL_COMPATIBLE_DEFAULTS
  2529. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, 0), 1);
  2530. #elif !defined(HAVE_CRL)
  2531. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, 0), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  2532. #endif
  2533. ExpectIntEQ(wolfSSL_CertManagerDisableCRL(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2534. ExpectIntEQ(wolfSSL_CertManagerDisableCRL(cm), 1);
  2535. #ifdef HAVE_CRL
  2536. /* Test APIs when CRL is disabled. */
  2537. #ifdef HAVE_CRL_IO
  2538. ExpectIntEQ(wolfSSL_CertManagerSetCRL_IOCb(cm, NULL), 1);
  2539. #endif
  2540. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048,
  2541. sizeof_server_cert_der_2048), 1);
  2542. ExpectIntEQ(wolfSSL_CertManagerFreeCRL(cm), 1);
  2543. #endif
  2544. /* OCSP */
  2545. ExpectIntEQ(wolfSSL_CertManagerEnableOCSP(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2546. ExpectIntEQ(wolfSSL_CertManagerDisableOCSP(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2547. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPStapling(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2548. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPStapling(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2549. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPMustStaple(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2550. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPMustStaple(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2551. #if !defined(HAVE_CERTIFICATE_STATUS_REQUEST) && \
  2552. !defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  2553. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPStapling(cm), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  2554. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPMustStaple(cm), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  2555. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPMustStaple(cm), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  2556. #endif
  2557. #ifdef HAVE_OCSP
  2558. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(NULL, NULL, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2559. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, NULL, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2560. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(NULL, &c, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2561. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2562. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(NULL, &c, 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(cm, &c, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2565. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(NULL, NULL, 0,
  2566. NULL, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2567. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, NULL, 1,
  2568. NULL, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2569. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(NULL, &c, 1,
  2570. NULL, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2571. ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(NULL, NULL),
  2572. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2573. ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(NULL, ""),
  2574. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2575. ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(cm, NULL), 1);
  2576. ExpectIntEQ(wolfSSL_CertManagerSetOCSP_Cb(NULL, NULL, NULL, NULL),
  2577. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2578. ExpectIntEQ(wolfSSL_CertManagerSetOCSP_Cb(cm, NULL, NULL, NULL), 1);
  2579. ExpectIntEQ(wolfSSL_CertManagerDisableOCSP(cm), 1);
  2580. /* Test APIs when OCSP is disabled. */
  2581. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, &c, 1,
  2582. NULL, NULL, NULL, NULL), 1);
  2583. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, &c, 1), 1);
  2584. #endif
  2585. ExpectIntEQ(wolfSSL_CertManager_up_ref(cm), 1);
  2586. if (EXPECT_SUCCESS()) {
  2587. wolfSSL_CertManagerFree(cm);
  2588. }
  2589. wolfSSL_CertManagerFree(cm);
  2590. cm = NULL;
  2591. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  2592. #ifdef HAVE_OCSP
  2593. ExpectIntEQ(wolfSSL_CertManagerEnableOCSP(cm, WOLFSSL_OCSP_URL_OVERRIDE |
  2594. WOLFSSL_OCSP_CHECKALL), 1);
  2595. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) || \
  2596. defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  2597. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPStapling(cm), 1);
  2598. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPStapling(cm), 1);
  2599. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPStapling(cm), 1);
  2600. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPStapling(cm), 1);
  2601. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPMustStaple(cm), 1);
  2602. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPMustStaple(cm), 1);
  2603. #endif
  2604. ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(cm, ""), 1);
  2605. ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(cm, ""), 1);
  2606. #endif
  2607. #ifdef WOLFSSL_TRUST_PEER_CERT
  2608. ExpectIntEQ(wolfSSL_CertManagerUnload_trust_peers(cm), 1);
  2609. #endif
  2610. wolfSSL_CertManagerFree(cm);
  2611. #endif
  2612. return EXPECT_RESULT();
  2613. }
  2614. static int test_wolfSSL_CertManagerLoadCABuffer(void)
  2615. {
  2616. EXPECT_DECLS;
  2617. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
  2618. const char* ca_cert = "./certs/ca-cert.pem";
  2619. const char* ca_expired_cert = "./certs/test/expired/expired-ca.pem";
  2620. int ret;
  2621. ExpectIntLE(ret = test_cm_load_ca_file(ca_cert), 1);
  2622. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  2623. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2624. #elif defined(NO_RSA)
  2625. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_UNKNOWN_OID_E));
  2626. #else
  2627. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  2628. #endif
  2629. ExpectIntLE(ret = test_cm_load_ca_file(ca_expired_cert), 1);
  2630. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  2631. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2632. #elif defined(NO_RSA)
  2633. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_UNKNOWN_OID_E));
  2634. #elif !(WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS & WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY) && \
  2635. !defined(NO_ASN_TIME)
  2636. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_AFTER_DATE_E));
  2637. #else
  2638. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  2639. #endif
  2640. #endif
  2641. return EXPECT_RESULT();
  2642. }
  2643. static int test_wolfSSL_CertManagerLoadCABuffer_ex(void)
  2644. {
  2645. EXPECT_DECLS;
  2646. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
  2647. const char* ca_cert = "./certs/ca-cert.pem";
  2648. const char* ca_expired_cert = "./certs/test/expired/expired-ca.pem";
  2649. int ret;
  2650. ExpectIntLE(ret = test_cm_load_ca_file_ex(ca_cert, WOLFSSL_LOAD_FLAG_NONE),
  2651. 1);
  2652. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  2653. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2654. #elif defined(NO_RSA)
  2655. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_UNKNOWN_OID_E));
  2656. #else
  2657. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  2658. #endif
  2659. ExpectIntLE(ret = test_cm_load_ca_file_ex(ca_expired_cert,
  2660. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), 1);
  2661. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  2662. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2663. #elif defined(NO_RSA)
  2664. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_UNKNOWN_OID_E));
  2665. #elif !(WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS & WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY) && \
  2666. !defined(NO_ASN_TIME) && defined(WOLFSSL_TRUST_PEER_CERT) && \
  2667. defined(OPENSSL_COMPATIBLE_DEFAULTS)
  2668. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_AFTER_DATE_E));
  2669. #else
  2670. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  2671. #endif
  2672. #endif
  2673. return EXPECT_RESULT();
  2674. }
  2675. static int test_wolfSSL_CertManagerGetCerts(void)
  2676. {
  2677. EXPECT_DECLS;
  2678. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  2679. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && \
  2680. defined(WOLFSSL_SIGNER_DER_CERT)
  2681. WOLFSSL_CERT_MANAGER* cm = NULL;
  2682. WOLFSSL_STACK* sk = NULL;
  2683. X509* x509 = NULL;
  2684. X509* cert1 = NULL;
  2685. FILE* file1 = NULL;
  2686. #ifdef DEBUG_WOLFSSL_VERBOSE
  2687. WOLFSSL_BIO* bio = NULL;
  2688. #endif
  2689. int i = 0;
  2690. int ret = 0;
  2691. const byte* der = NULL;
  2692. int derSz = 0;
  2693. ExpectNotNull(file1 = fopen("./certs/ca-cert.pem", "rb"));
  2694. ExpectNotNull(cert1 = wolfSSL_PEM_read_X509(file1, NULL, NULL, NULL));
  2695. if (file1 != NULL) {
  2696. fclose(file1);
  2697. }
  2698. ExpectNull(sk = wolfSSL_CertManagerGetCerts(NULL));
  2699. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  2700. ExpectNull(sk = wolfSSL_CertManagerGetCerts(cm));
  2701. ExpectNotNull(der = wolfSSL_X509_get_der(cert1, &derSz));
  2702. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
  2703. /* Check that ASN_SELF_SIGNED_E is returned for a self-signed cert for QT
  2704. * and full OpenSSL compatibility */
  2705. ExpectIntEQ(ret = wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2706. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E));
  2707. #else
  2708. ExpectIntEQ(ret = wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2709. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  2710. #endif
  2711. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCA(cm,
  2712. "./certs/ca-cert.pem", NULL));
  2713. ExpectNotNull(sk = wolfSSL_CertManagerGetCerts(cm));
  2714. for (i = 0; EXPECT_SUCCESS() && i < sk_X509_num(sk); i++) {
  2715. ExpectNotNull(x509 = sk_X509_value(sk, i));
  2716. ExpectIntEQ(0, wolfSSL_X509_cmp(x509, cert1));
  2717. #ifdef DEBUG_WOLFSSL_VERBOSE
  2718. bio = BIO_new(wolfSSL_BIO_s_file());
  2719. if (bio != NULL) {
  2720. BIO_set_fp(bio, stderr, BIO_NOCLOSE);
  2721. X509_print(bio, x509);
  2722. BIO_free(bio);
  2723. }
  2724. #endif /* DEBUG_WOLFSSL_VERBOSE */
  2725. }
  2726. wolfSSL_X509_free(cert1);
  2727. sk_X509_pop_free(sk, NULL);
  2728. wolfSSL_CertManagerFree(cm);
  2729. #endif /* defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  2730. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && \
  2731. defined(WOLFSSL_SIGNER_DER_CERT) */
  2732. return EXPECT_RESULT();
  2733. }
  2734. static int test_wolfSSL_CertManagerSetVerify(void)
  2735. {
  2736. EXPECT_DECLS;
  2737. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  2738. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  2739. (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH))
  2740. WOLFSSL_CERT_MANAGER* cm = NULL;
  2741. int tmp = myVerifyAction;
  2742. const char* ca_cert = "./certs/ca-cert.pem";
  2743. const char* expiredCert = "./certs/test/expired/expired-cert.pem";
  2744. wolfSSL_CertManagerSetVerify(NULL, NULL);
  2745. wolfSSL_CertManagerSetVerify(NULL, myVerify);
  2746. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  2747. wolfSSL_CertManagerSetVerify(cm, myVerify);
  2748. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  2749. ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL), -1);
  2750. #else
  2751. ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL),
  2752. WOLFSSL_SUCCESS);
  2753. #endif
  2754. /* Use the test CB that always accepts certs */
  2755. myVerifyAction = VERIFY_OVERRIDE_ERROR;
  2756. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, expiredCert,
  2757. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  2758. #ifdef WOLFSSL_ALWAYS_VERIFY_CB
  2759. {
  2760. const char* verifyCert = "./certs/server-cert.der";
  2761. /* Use the test CB that always fails certs */
  2762. myVerifyAction = VERIFY_FORCE_FAIL;
  2763. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, verifyCert,
  2764. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(VERIFY_CERT_ERROR));
  2765. }
  2766. #endif
  2767. wolfSSL_CertManagerFree(cm);
  2768. myVerifyAction = tmp;
  2769. #endif
  2770. return EXPECT_RESULT();
  2771. }
  2772. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  2773. defined(DEBUG_UNIT_TEST_CERTS)
  2774. /* Used when debugging name constraint tests. Not static to allow use in
  2775. * multiple locations with complex define guards. */
  2776. void DEBUG_WRITE_CERT_X509(WOLFSSL_X509* x509, const char* fileName)
  2777. {
  2778. BIO* out = BIO_new_file(fileName, "wb");
  2779. if (out != NULL) {
  2780. PEM_write_bio_X509(out, x509);
  2781. BIO_free(out);
  2782. }
  2783. }
  2784. void DEBUG_WRITE_DER(const byte* der, int derSz, const char* fileName)
  2785. {
  2786. BIO* out = BIO_new_file(fileName, "wb");
  2787. if (out != NULL) {
  2788. BIO_write(out, der, derSz);
  2789. BIO_free(out);
  2790. }
  2791. }
  2792. #else
  2793. #define DEBUG_WRITE_CERT_X509(x509, fileName) WC_DO_NOTHING
  2794. #define DEBUG_WRITE_DER(der, derSz, fileName) WC_DO_NOTHING
  2795. #endif
  2796. static int test_wolfSSL_CertManagerNameConstraint(void)
  2797. {
  2798. EXPECT_DECLS;
  2799. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  2800. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  2801. defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && \
  2802. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ALT_NAMES) && \
  2803. !defined(NO_SHA256)
  2804. WOLFSSL_CERT_MANAGER* cm = NULL;
  2805. WOLFSSL_EVP_PKEY *priv = NULL;
  2806. WOLFSSL_X509_NAME* name = NULL;
  2807. const char* ca_cert = "./certs/test/cert-ext-nc.der";
  2808. const char* server_cert = "./certs/test/server-goodcn.pem";
  2809. int i = 0;
  2810. static const byte extNameConsOid[] = {85, 29, 30};
  2811. RsaKey key;
  2812. WC_RNG rng;
  2813. byte *der = NULL;
  2814. int derSz = 0;
  2815. word32 idx = 0;
  2816. byte *pt;
  2817. WOLFSSL_X509 *x509 = NULL;
  2818. WOLFSSL_X509 *ca = NULL;
  2819. wc_InitRng(&rng);
  2820. /* load in CA private key for signing */
  2821. ExpectIntEQ(wc_InitRsaKey_ex(&key, HEAP_HINT, testDevId), 0);
  2822. ExpectIntEQ(wc_RsaPrivateKeyDecode(server_key_der_2048, &idx, &key,
  2823. sizeof_server_key_der_2048), 0);
  2824. /* get ca certificate then alter it */
  2825. ExpectNotNull(der =
  2826. (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER));
  2827. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(ca_cert,
  2828. WOLFSSL_FILETYPE_ASN1));
  2829. ExpectNotNull(pt = (byte*)wolfSSL_X509_get_tbs(x509, &derSz));
  2830. if (EXPECT_SUCCESS() && (der != NULL)) {
  2831. XMEMCPY(der, pt, derSz);
  2832. /* find the name constraint extension and alter it */
  2833. pt = der;
  2834. for (i = 0; i < derSz - 3; i++) {
  2835. if (XMEMCMP(pt, extNameConsOid, 3) == 0) {
  2836. pt += 3;
  2837. break;
  2838. }
  2839. pt++;
  2840. }
  2841. ExpectIntNE(i, derSz - 3); /* did not find OID if this case is hit */
  2842. /* go to the length value and set it to 0 */
  2843. while (i < derSz && *pt != 0x81) {
  2844. pt++;
  2845. i++;
  2846. }
  2847. ExpectIntNE(i, derSz); /* did not place to alter */
  2848. pt++;
  2849. *pt = 0x00;
  2850. }
  2851. /* resign the altered certificate */
  2852. ExpectIntGT((derSz = wc_SignCert(derSz, CTC_SHA256wRSA, der,
  2853. FOURK_BUF, &key, NULL, &rng)), 0);
  2854. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  2855. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  2856. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  2857. wolfSSL_CertManagerFree(cm);
  2858. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  2859. wolfSSL_X509_free(x509);
  2860. wc_FreeRsaKey(&key);
  2861. wc_FreeRng(&rng);
  2862. /* add email alt name to satisfy constraint */
  2863. pt = (byte*)server_key_der_2048;
  2864. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  2865. (const unsigned char**)&pt, sizeof_server_key_der_2048));
  2866. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  2867. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert,
  2868. WOLFSSL_FILETYPE_ASN1));
  2869. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz)));
  2870. DEBUG_WRITE_DER(der, derSz, "ca.der");
  2871. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  2872. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2873. /* Good cert test with proper alt email name */
  2874. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  2875. WOLFSSL_FILETYPE_PEM));
  2876. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  2877. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  2878. name = NULL;
  2879. ExpectNotNull(name = X509_NAME_new());
  2880. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  2881. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  2882. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  2883. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  2884. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  2885. (byte*)"support@info.wolfssl.com", 24, -1, 0), SSL_SUCCESS);
  2886. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  2887. X509_NAME_free(name);
  2888. name = NULL;
  2889. wolfSSL_X509_add_altname(x509, "wolfssl@info.wolfssl.com", ASN_RFC822_TYPE);
  2890. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  2891. DEBUG_WRITE_CERT_X509(x509, "good-cert.pem");
  2892. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  2893. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2894. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2895. wolfSSL_X509_free(x509);
  2896. x509 = NULL;
  2897. /* Cert with bad alt name list */
  2898. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  2899. WOLFSSL_FILETYPE_PEM));
  2900. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  2901. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  2902. name = NULL;
  2903. ExpectNotNull(name = X509_NAME_new());
  2904. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  2905. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  2906. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  2907. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  2908. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  2909. (byte*)"support@info.wolfssl.com", 24, -1, 0), SSL_SUCCESS);
  2910. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  2911. X509_NAME_free(name);
  2912. wolfSSL_X509_add_altname(x509, "wolfssl@info.com", ASN_RFC822_TYPE);
  2913. wolfSSL_X509_add_altname(x509, "wolfssl@info.wolfssl.com", ASN_RFC822_TYPE);
  2914. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  2915. DEBUG_WRITE_CERT_X509(x509, "bad-cert.pem");
  2916. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  2917. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2918. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  2919. wolfSSL_CertManagerFree(cm);
  2920. wolfSSL_X509_free(x509);
  2921. wolfSSL_X509_free(ca);
  2922. wolfSSL_EVP_PKEY_free(priv);
  2923. #endif
  2924. return EXPECT_RESULT();
  2925. }
  2926. static int test_wolfSSL_CertManagerNameConstraint2(void)
  2927. {
  2928. EXPECT_DECLS;
  2929. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  2930. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  2931. defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && \
  2932. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ALT_NAMES)
  2933. const char* ca_cert = "./certs/test/cert-ext-ndir.der";
  2934. const char* ca_cert2 = "./certs/test/cert-ext-ndir-exc.der";
  2935. const char* server_cert = "./certs/server-cert.pem";
  2936. WOLFSSL_CERT_MANAGER* cm = NULL;
  2937. WOLFSSL_X509 *x509 = NULL;
  2938. WOLFSSL_X509 *ca = NULL;
  2939. const unsigned char *der = NULL;
  2940. const unsigned char *pt;
  2941. WOLFSSL_EVP_PKEY *priv = NULL;
  2942. WOLFSSL_X509_NAME* name = NULL;
  2943. int derSz = 0;
  2944. /* C=US*/
  2945. char altName[] = {
  2946. 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09,
  2947. 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53
  2948. };
  2949. /* C=ID */
  2950. char altNameFail[] = {
  2951. 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09,
  2952. 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x49, 0x44
  2953. };
  2954. /* C=US ST=California*/
  2955. char altNameExc[] = {
  2956. 0x30, 0x22,
  2957. 0x31, 0x0B,
  2958. 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53,
  2959. 0x31, 0x13,
  2960. 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0C, 0x0A,
  2961. 0x43, 0x61, 0x6c, 0x69, 0x66, 0x6f, 0x72, 0x6e, 0x69, 0x61
  2962. };
  2963. /* load in CA private key for signing */
  2964. pt = ca_key_der_2048;
  2965. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, &pt,
  2966. sizeof_ca_key_der_2048));
  2967. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  2968. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert,
  2969. WOLFSSL_FILETYPE_ASN1));
  2970. ExpectNotNull((der = wolfSSL_X509_get_der(ca, &derSz)));
  2971. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  2972. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2973. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  2974. WOLFSSL_FILETYPE_PEM));
  2975. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  2976. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  2977. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  2978. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  2979. #else
  2980. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  2981. #endif
  2982. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  2983. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2984. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2985. /* add in matching DIR alt name and resign */
  2986. wolfSSL_X509_add_altname_ex(x509, altName, sizeof(altName), ASN_DIR_TYPE);
  2987. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  2988. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  2989. #else
  2990. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  2991. #endif
  2992. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  2993. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2994. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2995. wolfSSL_X509_free(x509);
  2996. x509 = NULL;
  2997. /* check verify fail */
  2998. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  2999. WOLFSSL_FILETYPE_PEM));
  3000. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3001. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3002. /* add in miss matching DIR alt name and resign */
  3003. wolfSSL_X509_add_altname_ex(x509, altNameFail, sizeof(altNameFail),
  3004. ASN_DIR_TYPE);
  3005. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  3006. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  3007. #else
  3008. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  3009. #endif
  3010. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  3011. #ifndef WOLFSSL_NO_ASN_STRICT
  3012. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3013. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3014. #else
  3015. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3016. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3017. #endif
  3018. /* check that it still fails if one bad altname and one good altname is in
  3019. * the certificate */
  3020. wolfSSL_X509_free(x509);
  3021. x509 = NULL;
  3022. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3023. WOLFSSL_FILETYPE_PEM));
  3024. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3025. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3026. wolfSSL_X509_add_altname_ex(x509, altName, sizeof(altName), ASN_DIR_TYPE);
  3027. wolfSSL_X509_add_altname_ex(x509, altNameFail, sizeof(altNameFail),
  3028. ASN_DIR_TYPE);
  3029. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  3030. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  3031. #else
  3032. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  3033. #endif
  3034. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  3035. #ifndef WOLFSSL_NO_ASN_STRICT
  3036. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3037. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3038. #else
  3039. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3040. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3041. #endif
  3042. /* check it fails with switching position of bad altname */
  3043. wolfSSL_X509_free(x509);
  3044. x509 = NULL;
  3045. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3046. WOLFSSL_FILETYPE_PEM));
  3047. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3048. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3049. wolfSSL_X509_add_altname_ex(x509, altNameFail, sizeof(altNameFail),
  3050. ASN_DIR_TYPE);
  3051. wolfSSL_X509_add_altname_ex(x509, altName, sizeof(altName), ASN_DIR_TYPE);
  3052. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  3053. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  3054. #else
  3055. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  3056. #endif
  3057. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  3058. #ifndef WOLFSSL_NO_ASN_STRICT
  3059. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3060. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3061. #else
  3062. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3063. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3064. #endif
  3065. wolfSSL_CertManagerFree(cm);
  3066. wolfSSL_X509_free(x509);
  3067. x509 = NULL;
  3068. wolfSSL_X509_free(ca);
  3069. ca = NULL;
  3070. /* now test with excluded name constraint */
  3071. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  3072. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert2,
  3073. WOLFSSL_FILETYPE_ASN1));
  3074. ExpectNotNull((der = wolfSSL_X509_get_der(ca, &derSz)));
  3075. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  3076. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3077. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3078. WOLFSSL_FILETYPE_PEM));
  3079. wolfSSL_X509_add_altname_ex(x509, altNameExc, sizeof(altNameExc),
  3080. ASN_DIR_TYPE);
  3081. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3082. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3083. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  3084. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  3085. #else
  3086. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  3087. #endif
  3088. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  3089. #ifndef WOLFSSL_NO_ASN_STRICT
  3090. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3091. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3092. #else
  3093. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3094. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3095. #endif
  3096. wolfSSL_CertManagerFree(cm);
  3097. wolfSSL_X509_free(x509);
  3098. wolfSSL_X509_free(ca);
  3099. wolfSSL_EVP_PKEY_free(priv);
  3100. #endif
  3101. return EXPECT_RESULT();
  3102. }
  3103. static int test_wolfSSL_CertManagerNameConstraint3(void)
  3104. {
  3105. EXPECT_DECLS;
  3106. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  3107. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  3108. defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && \
  3109. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ALT_NAMES) && \
  3110. !defined(NO_SHA256)
  3111. WOLFSSL_CERT_MANAGER* cm = NULL;
  3112. WOLFSSL_EVP_PKEY *priv = NULL;
  3113. WOLFSSL_X509_NAME* name = NULL;
  3114. const char* ca_cert = "./certs/test/cert-ext-mnc.der";
  3115. const char* server_cert = "./certs/test/server-goodcn.pem";
  3116. byte *der = NULL;
  3117. int derSz = 0;
  3118. byte *pt;
  3119. WOLFSSL_X509 *x509 = NULL;
  3120. WOLFSSL_X509 *ca = NULL;
  3121. pt = (byte*)server_key_der_2048;
  3122. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  3123. (const unsigned char**)&pt, sizeof_server_key_der_2048));
  3124. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  3125. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert,
  3126. WOLFSSL_FILETYPE_ASN1));
  3127. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz)));
  3128. DEBUG_WRITE_DER(der, derSz, "ca.der");
  3129. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  3130. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3131. /* check satisfying .wolfssl.com constraint passes */
  3132. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3133. WOLFSSL_FILETYPE_PEM));
  3134. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3135. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3136. name = NULL;
  3137. ExpectNotNull(name = X509_NAME_new());
  3138. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3139. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3140. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3141. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3142. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  3143. (byte*)"support@info.wolfssl.com", 24, -1, 0), SSL_SUCCESS);
  3144. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3145. X509_NAME_free(name);
  3146. name = NULL;
  3147. wolfSSL_X509_add_altname(x509, "wolfssl@info.wolfssl.com", ASN_RFC822_TYPE);
  3148. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3149. DEBUG_WRITE_CERT_X509(x509, "good-1st-constraint-cert.pem");
  3150. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3151. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3152. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3153. wolfSSL_X509_free(x509);
  3154. x509 = NULL;
  3155. /* check satisfying .random.com constraint passes */
  3156. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3157. WOLFSSL_FILETYPE_PEM));
  3158. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3159. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3160. name = NULL;
  3161. ExpectNotNull(name = X509_NAME_new());
  3162. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3163. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3164. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3165. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3166. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  3167. (byte*)"support@info.example.com", 24, -1, 0), SSL_SUCCESS);
  3168. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3169. X509_NAME_free(name);
  3170. name = NULL;
  3171. wolfSSL_X509_add_altname(x509, "wolfssl@info.example.com", ASN_RFC822_TYPE);
  3172. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3173. DEBUG_WRITE_CERT_X509(x509, "good-2nd-constraint-cert.pem");
  3174. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3175. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3176. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3177. wolfSSL_X509_free(x509);
  3178. x509 = NULL;
  3179. /* check fail case when neither constraint is matched */
  3180. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3181. WOLFSSL_FILETYPE_PEM));
  3182. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3183. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3184. name = NULL;
  3185. ExpectNotNull(name = X509_NAME_new());
  3186. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3187. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3188. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3189. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3190. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  3191. (byte*)"support@info.com", 16, -1, 0), SSL_SUCCESS);
  3192. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3193. X509_NAME_free(name);
  3194. wolfSSL_X509_add_altname(x509, "wolfssl@info.com", ASN_RFC822_TYPE);
  3195. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3196. DEBUG_WRITE_CERT_X509(x509, "bad-cert.pem");
  3197. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3198. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3199. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3200. wolfSSL_CertManagerFree(cm);
  3201. wolfSSL_X509_free(x509);
  3202. wolfSSL_X509_free(ca);
  3203. wolfSSL_EVP_PKEY_free(priv);
  3204. #endif
  3205. return EXPECT_RESULT();
  3206. }
  3207. static int test_wolfSSL_CertManagerNameConstraint4(void)
  3208. {
  3209. EXPECT_DECLS;
  3210. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  3211. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  3212. defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && \
  3213. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ALT_NAMES) && \
  3214. !defined(NO_SHA256)
  3215. WOLFSSL_CERT_MANAGER* cm = NULL;
  3216. WOLFSSL_EVP_PKEY *priv = NULL;
  3217. WOLFSSL_X509_NAME* name = NULL;
  3218. const char* ca_cert = "./certs/test/cert-ext-ncdns.der";
  3219. const char* server_cert = "./certs/test/server-goodcn.pem";
  3220. byte *der = NULL;
  3221. int derSz;
  3222. byte *pt;
  3223. WOLFSSL_X509 *x509 = NULL;
  3224. WOLFSSL_X509 *ca = NULL;
  3225. pt = (byte*)server_key_der_2048;
  3226. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  3227. (const unsigned char**)&pt, sizeof_server_key_der_2048));
  3228. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  3229. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert,
  3230. WOLFSSL_FILETYPE_ASN1));
  3231. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz)));
  3232. DEBUG_WRITE_DER(der, derSz, "ca.der");
  3233. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  3234. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3235. /* check satisfying wolfssl.com constraint passes */
  3236. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3237. WOLFSSL_FILETYPE_PEM));
  3238. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3239. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3240. name = NULL;
  3241. ExpectNotNull(name = X509_NAME_new());
  3242. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3243. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3244. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3245. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3246. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3247. X509_NAME_free(name);
  3248. name = NULL;
  3249. wolfSSL_X509_add_altname(x509, "www.wolfssl.com", ASN_DNS_TYPE);
  3250. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3251. DEBUG_WRITE_CERT_X509(x509, "good-1st-constraint-cert.pem");
  3252. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3253. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3254. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3255. wolfSSL_X509_free(x509);
  3256. x509 = NULL;
  3257. /* check satisfying example.com constraint passes */
  3258. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3259. WOLFSSL_FILETYPE_PEM));
  3260. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3261. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3262. name = NULL;
  3263. ExpectNotNull(name = X509_NAME_new());
  3264. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3265. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3266. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3267. (byte*)"example.com", 11, -1, 0), SSL_SUCCESS);
  3268. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3269. X509_NAME_free(name);
  3270. name = NULL;
  3271. wolfSSL_X509_add_altname(x509, "www.example.com", ASN_DNS_TYPE);
  3272. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3273. DEBUG_WRITE_CERT_X509(x509, "good-2nd-constraint-cert.pem");
  3274. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3275. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3276. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3277. wolfSSL_X509_free(x509);
  3278. x509 = NULL;
  3279. /* check satisfying wolfssl.com constraint passes with list of DNS's */
  3280. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3281. WOLFSSL_FILETYPE_PEM));
  3282. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3283. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3284. name = NULL;
  3285. ExpectNotNull(name = X509_NAME_new());
  3286. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3287. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3288. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3289. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3290. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3291. X509_NAME_free(name);
  3292. name = NULL;
  3293. wolfSSL_X509_add_altname(x509, "www.wolfssl.com", ASN_DNS_TYPE);
  3294. wolfSSL_X509_add_altname(x509, "www.info.wolfssl.com", ASN_DNS_TYPE);
  3295. wolfSSL_X509_add_altname(x509, "extra.wolfssl.com", ASN_DNS_TYPE);
  3296. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3297. DEBUG_WRITE_CERT_X509(x509, "good-multiple-constraint-cert.pem");
  3298. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3299. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3300. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3301. wolfSSL_X509_free(x509);
  3302. x509 = NULL;
  3303. /* check fail when one DNS in the list is bad */
  3304. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3305. WOLFSSL_FILETYPE_PEM));
  3306. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3307. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3308. name = NULL;
  3309. ExpectNotNull(name = X509_NAME_new());
  3310. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3311. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3312. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3313. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3314. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3315. X509_NAME_free(name);
  3316. name = NULL;
  3317. wolfSSL_X509_add_altname(x509, "www.wolfssl.com", ASN_DNS_TYPE);
  3318. wolfSSL_X509_add_altname(x509, "www.nomatch.com", ASN_DNS_TYPE);
  3319. wolfSSL_X509_add_altname(x509, "www.info.wolfssl.com", ASN_DNS_TYPE);
  3320. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3321. DEBUG_WRITE_CERT_X509(x509, "bad-multiple-constraint-cert.pem");
  3322. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3323. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3324. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3325. wolfSSL_X509_free(x509);
  3326. x509 = NULL;
  3327. /* check fail case when neither constraint is matched */
  3328. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3329. WOLFSSL_FILETYPE_PEM));
  3330. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3331. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3332. name = NULL;
  3333. ExpectNotNull(name = X509_NAME_new());
  3334. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3335. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3336. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3337. (byte*)"common", 6, -1, 0), SSL_SUCCESS);
  3338. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3339. X509_NAME_free(name);
  3340. wolfSSL_X509_add_altname(x509, "www.random.com", ASN_DNS_TYPE);
  3341. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3342. DEBUG_WRITE_CERT_X509(x509, "bad-cert.pem");
  3343. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3344. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3345. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3346. wolfSSL_CertManagerFree(cm);
  3347. wolfSSL_X509_free(x509);
  3348. wolfSSL_X509_free(ca);
  3349. wolfSSL_EVP_PKEY_free(priv);
  3350. #endif
  3351. return EXPECT_RESULT();
  3352. }
  3353. static int test_wolfSSL_CertManagerNameConstraint5(void)
  3354. {
  3355. EXPECT_DECLS;
  3356. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  3357. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  3358. defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && \
  3359. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ALT_NAMES) && \
  3360. !defined(NO_SHA256)
  3361. WOLFSSL_CERT_MANAGER* cm = NULL;
  3362. WOLFSSL_EVP_PKEY *priv = NULL;
  3363. WOLFSSL_X509_NAME* name = NULL;
  3364. const char* ca_cert = "./certs/test/cert-ext-ncmixed.der";
  3365. const char* server_cert = "./certs/test/server-goodcn.pem";
  3366. byte *der = NULL;
  3367. int derSz;
  3368. byte *pt;
  3369. WOLFSSL_X509 *x509 = NULL;
  3370. WOLFSSL_X509 *ca = NULL;
  3371. pt = (byte*)server_key_der_2048;
  3372. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  3373. (const unsigned char**)&pt, sizeof_server_key_der_2048));
  3374. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  3375. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert,
  3376. WOLFSSL_FILETYPE_ASN1));
  3377. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz)));
  3378. DEBUG_WRITE_DER(der, derSz, "ca.der");
  3379. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  3380. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3381. /* check satisfying wolfssl.com constraint passes */
  3382. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3383. WOLFSSL_FILETYPE_PEM));
  3384. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3385. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3386. name = NULL;
  3387. ExpectNotNull(name = X509_NAME_new());
  3388. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3389. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3390. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3391. (byte*)"example", 7, -1, 0), SSL_SUCCESS);
  3392. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3393. X509_NAME_free(name);
  3394. name = NULL;
  3395. wolfSSL_X509_add_altname(x509, "good.example", ASN_DNS_TYPE);
  3396. wolfSSL_X509_add_altname(x509, "facts@into.wolfssl.com", ASN_RFC822_TYPE);
  3397. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3398. DEBUG_WRITE_CERT_X509(x509, "good-cert.pem");
  3399. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3400. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3401. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3402. wolfSSL_X509_free(x509);
  3403. x509 = NULL;
  3404. /* fail with DNS check because of common name */
  3405. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3406. WOLFSSL_FILETYPE_PEM));
  3407. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3408. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3409. name = NULL;
  3410. ExpectNotNull(name = X509_NAME_new());
  3411. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3412. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3413. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3414. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3415. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3416. X509_NAME_free(name);
  3417. name = NULL;
  3418. wolfSSL_X509_add_altname(x509, "example", ASN_DNS_TYPE);
  3419. wolfSSL_X509_add_altname(x509, "facts@wolfssl.com", ASN_RFC822_TYPE);
  3420. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3421. DEBUG_WRITE_CERT_X509(x509, "bad-cn-cert.pem");
  3422. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3423. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3424. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3425. wolfSSL_X509_free(x509);
  3426. x509 = NULL;
  3427. /* fail on permitted DNS name constraint */
  3428. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3429. WOLFSSL_FILETYPE_PEM));
  3430. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3431. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3432. name = NULL;
  3433. ExpectNotNull(name = X509_NAME_new());
  3434. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3435. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3436. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3437. X509_NAME_free(name);
  3438. name = NULL;
  3439. wolfSSL_X509_add_altname(x509, "www.example", ASN_DNS_TYPE);
  3440. wolfSSL_X509_add_altname(x509, "www.wolfssl", ASN_DNS_TYPE);
  3441. wolfSSL_X509_add_altname(x509, "info@wolfssl.com", ASN_RFC822_TYPE);
  3442. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3443. DEBUG_WRITE_CERT_X509(x509, "bad-1st-constraint-cert.pem");
  3444. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3445. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3446. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3447. wolfSSL_X509_free(x509);
  3448. x509 = NULL;
  3449. /* fail on permitted email name constraint */
  3450. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3451. WOLFSSL_FILETYPE_PEM));
  3452. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3453. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3454. name = NULL;
  3455. ExpectNotNull(name = X509_NAME_new());
  3456. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3457. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3458. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3459. X509_NAME_free(name);
  3460. name = NULL;
  3461. wolfSSL_X509_add_altname(x509, "example", ASN_DNS_TYPE);
  3462. wolfSSL_X509_add_altname(x509, "info@wolfssl.com", ASN_RFC822_TYPE);
  3463. wolfSSL_X509_add_altname(x509, "info@example.com", ASN_RFC822_TYPE);
  3464. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3465. DEBUG_WRITE_CERT_X509(x509, "bad-2nd-constraint-cert.pem");
  3466. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3467. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3468. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3469. wolfSSL_X509_free(x509);
  3470. x509 = NULL;
  3471. /* success with empty email name */
  3472. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3473. WOLFSSL_FILETYPE_PEM));
  3474. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3475. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3476. name = NULL;
  3477. ExpectNotNull(name = X509_NAME_new());
  3478. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3479. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3480. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3481. X509_NAME_free(name);
  3482. wolfSSL_X509_add_altname(x509, "example", ASN_DNS_TYPE);
  3483. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3484. DEBUG_WRITE_CERT_X509(x509, "good-missing-constraint-cert.pem");
  3485. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3486. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3487. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3488. wolfSSL_X509_free(x509);
  3489. wolfSSL_CertManagerFree(cm);
  3490. wolfSSL_X509_free(ca);
  3491. wolfSSL_EVP_PKEY_free(priv);
  3492. #endif
  3493. return EXPECT_RESULT();
  3494. }
  3495. static int test_wolfSSL_CertManagerCRL(void)
  3496. {
  3497. EXPECT_DECLS;
  3498. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && defined(HAVE_CRL) && \
  3499. !defined(NO_RSA)
  3500. const char* ca_cert = "./certs/ca-cert.pem";
  3501. const char* crl1 = "./certs/crl/crl.pem";
  3502. const char* crl2 = "./certs/crl/crl2.pem";
  3503. #ifdef WC_RSA_PSS
  3504. const char* crl_rsapss = "./certs/crl/crl_rsapss.pem";
  3505. const char* ca_rsapss = "./certs/rsapss/ca-rsapss.pem";
  3506. #endif
  3507. const unsigned char crl_buff[] = {
  3508. 0x30, 0x82, 0x02, 0x04, 0x30, 0x81, 0xed, 0x02,
  3509. 0x01, 0x01, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86,
  3510. 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05,
  3511. 0x00, 0x30, 0x81, 0x94, 0x31, 0x0b, 0x30, 0x09,
  3512. 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55,
  3513. 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55,
  3514. 0x04, 0x08, 0x0c, 0x07, 0x4d, 0x6f, 0x6e, 0x74,
  3515. 0x61, 0x6e, 0x61, 0x31, 0x10, 0x30, 0x0e, 0x06,
  3516. 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f,
  3517. 0x7a, 0x65, 0x6d, 0x61, 0x6e, 0x31, 0x11, 0x30,
  3518. 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08,
  3519. 0x53, 0x61, 0x77, 0x74, 0x6f, 0x6f, 0x74, 0x68,
  3520. 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04,
  3521. 0x0b, 0x0c, 0x0a, 0x43, 0x6f, 0x6e, 0x73, 0x75,
  3522. 0x6c, 0x74, 0x69, 0x6e, 0x67, 0x31, 0x18, 0x30,
  3523. 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f,
  3524. 0x77, 0x77, 0x77, 0x2e, 0x77, 0x6f, 0x6c, 0x66,
  3525. 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x31,
  3526. 0x1f, 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48,
  3527. 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x10,
  3528. 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c,
  3529. 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d,
  3530. 0x17, 0x0d, 0x32, 0x32, 0x31, 0x32, 0x31, 0x36,
  3531. 0x32, 0x31, 0x31, 0x37, 0x35, 0x30, 0x5a, 0x17,
  3532. 0x0d, 0x32, 0x35, 0x30, 0x39, 0x31, 0x31, 0x32,
  3533. 0x31, 0x31, 0x37, 0x35, 0x30, 0x5a, 0x30, 0x14,
  3534. 0x30, 0x12, 0x02, 0x01, 0x02, 0x17, 0x0d, 0x32,
  3535. 0x32, 0x31, 0x32, 0x31, 0x36, 0x32, 0x31, 0x31,
  3536. 0x37, 0x35, 0x30, 0x5a, 0xa0, 0x0e, 0x30, 0x0c,
  3537. 0x30, 0x0a, 0x06, 0x03, 0x55, 0x1d, 0x14, 0x04,
  3538. 0x03, 0x02, 0x01, 0x02, 0x30, 0x0d, 0x06, 0x09,
  3539. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
  3540. 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00,
  3541. 0x39, 0x44, 0xff, 0x39, 0xf4, 0x04, 0x45, 0x79,
  3542. 0x7e, 0x73, 0xe2, 0x42, 0x48, 0xdb, 0x85, 0x66,
  3543. 0xfd, 0x99, 0x76, 0x94, 0x7c, 0xb5, 0x79, 0x5d,
  3544. 0x15, 0x71, 0x36, 0xa9, 0x87, 0xf0, 0x73, 0x05,
  3545. 0x50, 0x08, 0x6b, 0x1c, 0x6e, 0xde, 0x96, 0x45,
  3546. 0x31, 0xc3, 0xc0, 0xba, 0xba, 0xf5, 0x08, 0x1d,
  3547. 0x05, 0x4a, 0x52, 0x39, 0xe9, 0x03, 0xef, 0x59,
  3548. 0xc8, 0x1d, 0x4a, 0xf2, 0x86, 0x05, 0x99, 0x7b,
  3549. 0x4b, 0x74, 0xf6, 0xd3, 0x75, 0x8d, 0xb2, 0x57,
  3550. 0xba, 0xac, 0xa7, 0x11, 0x14, 0xd6, 0x6c, 0x71,
  3551. 0xc4, 0x4c, 0x1c, 0x68, 0xbc, 0x49, 0x78, 0xf0,
  3552. 0xc9, 0x52, 0x8a, 0xe7, 0x8b, 0x54, 0xe6, 0x20,
  3553. 0x58, 0x20, 0x60, 0x66, 0xf5, 0x14, 0xd8, 0xcb,
  3554. 0xff, 0xe0, 0xa0, 0x45, 0xbc, 0xb4, 0x81, 0xad,
  3555. 0x1d, 0xbc, 0xcf, 0xf8, 0x8e, 0xa8, 0x87, 0x24,
  3556. 0x55, 0x99, 0xd9, 0xce, 0x47, 0xf7, 0x5b, 0x4a,
  3557. 0x33, 0x6d, 0xdb, 0xbf, 0x93, 0x64, 0x1a, 0xa6,
  3558. 0x46, 0x5f, 0x27, 0xdc, 0xd8, 0xd4, 0xf9, 0xc2,
  3559. 0x42, 0x2a, 0x7e, 0xb2, 0x7c, 0xdd, 0x98, 0x77,
  3560. 0xf5, 0x88, 0x7d, 0x15, 0x25, 0x08, 0xbc, 0xe0,
  3561. 0xd0, 0x8d, 0xf4, 0xc3, 0xc3, 0x04, 0x41, 0xa4,
  3562. 0xd1, 0xb1, 0x39, 0x4a, 0x6b, 0x2c, 0xb5, 0x2e,
  3563. 0x9a, 0x65, 0x43, 0x0d, 0x0e, 0x73, 0xf4, 0x06,
  3564. 0xe1, 0xb3, 0x49, 0x34, 0x94, 0xb0, 0xb7, 0xff,
  3565. 0xc0, 0x27, 0xc1, 0xb5, 0xea, 0x06, 0xf7, 0x71,
  3566. 0x71, 0x97, 0xbb, 0xbc, 0xc7, 0x1a, 0x9f, 0xeb,
  3567. 0xf6, 0x3d, 0xa5, 0x7b, 0x55, 0xa7, 0xbf, 0xdd,
  3568. 0xd7, 0xee, 0x97, 0xb8, 0x9d, 0xdc, 0xcd, 0xe3,
  3569. 0x06, 0xdb, 0x9a, 0x2c, 0x60, 0xbf, 0x70, 0x84,
  3570. 0xfa, 0x6b, 0x8d, 0x70, 0x7d, 0xde, 0xe8, 0xb7,
  3571. 0xab, 0xb0, 0x38, 0x68, 0x6c, 0xc0, 0xb1, 0xe1,
  3572. 0xba, 0x45, 0xe0, 0xd7, 0x12, 0x3d, 0x71, 0x5b
  3573. };
  3574. WOLFSSL_CERT_MANAGER* cm = NULL;
  3575. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  3576. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3577. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), 1);
  3578. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECK), 1);
  3579. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm,
  3580. WOLFSSL_CRL_CHECK | WOLFSSL_CRL_CHECKALL), 1);
  3581. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, 16), 1);
  3582. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), 1);
  3583. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(NULL, NULL, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3584. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, NULL, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3585. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(NULL, server_cert_der_2048, -1),
  3586. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3587. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3588. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(NULL, server_cert_der_2048, 1),
  3589. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3590. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3591. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048, -1),
  3592. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3593. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048,
  3594. sizeof_server_cert_der_2048), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  3595. ExpectIntEQ(wolfSSL_CertManagerSetCRL_Cb(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3596. ExpectIntEQ(wolfSSL_CertManagerSetCRL_Cb(cm, NULL), 1);
  3597. #ifdef HAVE_CRL_IO
  3598. ExpectIntEQ(wolfSSL_CertManagerSetCRL_IOCb(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3599. ExpectIntEQ(wolfSSL_CertManagerSetCRL_IOCb(cm, NULL), 1);
  3600. #endif
  3601. #ifndef NO_FILESYSTEM
  3602. ExpectIntEQ(wolfSSL_CertManagerLoadCRL(NULL, NULL, WOLFSSL_FILETYPE_ASN1,
  3603. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3604. ExpectIntEQ(wolfSSL_CertManagerLoadCRL(cm, NULL, WOLFSSL_FILETYPE_ASN1,
  3605. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3606. /* -1 seen as !WOLFSSL_FILETYPE_PEM */
  3607. ExpectIntEQ(wolfSSL_CertManagerLoadCRL(cm, "./certs/crl", -1, 0), 1);
  3608. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(NULL, NULL,
  3609. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3610. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, NULL, WOLFSSL_FILETYPE_ASN1),
  3611. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3612. /* -1 seen as !WOLFSSL_FILETYPE_PEM */
  3613. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, "./certs/crl/crl.pem", -1),
  3614. WC_NO_ERR_TRACE(ASN_PARSE_E));
  3615. #endif
  3616. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(NULL, NULL, -1,
  3617. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3618. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, NULL, -1,
  3619. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3620. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(NULL, crl_buff, -1,
  3621. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3622. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(NULL, 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(cm, NULL, 1,
  3627. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3628. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_buff, -1,
  3629. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3630. ExpectIntEQ(wolfSSL_CertManagerFreeCRL(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3631. DoExpectIntEQ(wolfSSL_CertManagerFreeCRL(cm), 1);
  3632. ExpectIntEQ(WOLFSSL_SUCCESS,
  3633. wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL));
  3634. ExpectIntEQ(WOLFSSL_SUCCESS,
  3635. wolfSSL_CertManagerLoadCRL(cm, crl1, WOLFSSL_FILETYPE_PEM, 0));
  3636. ExpectIntEQ(WOLFSSL_SUCCESS,
  3637. wolfSSL_CertManagerLoadCRL(cm, crl2, WOLFSSL_FILETYPE_PEM, 0));
  3638. wolfSSL_CertManagerFreeCRL(cm);
  3639. #ifndef WOLFSSL_CRL_ALLOW_MISSING_CDP
  3640. ExpectIntEQ(WOLFSSL_SUCCESS,
  3641. wolfSSL_CertManagerLoadCRL(cm, crl1, WOLFSSL_FILETYPE_PEM, 0));
  3642. ExpectIntEQ(WOLFSSL_SUCCESS,
  3643. wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL));
  3644. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048,
  3645. sizeof_server_cert_der_2048), WC_NO_ERR_TRACE(CRL_MISSING));
  3646. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, server_cert_der_2048,
  3647. sizeof_server_cert_der_2048, WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(CRL_MISSING));
  3648. #endif /* !WOLFSSL_CRL_ALLOW_MISSING_CDP */
  3649. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_buff, sizeof(crl_buff),
  3650. WOLFSSL_FILETYPE_ASN1), 1);
  3651. #if !defined(NO_FILESYSTEM) && defined(WC_RSA_PSS)
  3652. /* loading should fail without the CA set */
  3653. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, crl_rsapss,
  3654. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(ASN_CRL_NO_SIGNER_E));
  3655. /* now successfully load the RSA-PSS crl once loading in it's CA */
  3656. ExpectIntEQ(WOLFSSL_SUCCESS,
  3657. wolfSSL_CertManagerLoadCA(cm, ca_rsapss, NULL));
  3658. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, crl_rsapss,
  3659. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  3660. #endif
  3661. wolfSSL_CertManagerFree(cm);
  3662. #endif
  3663. return EXPECT_RESULT();
  3664. }
  3665. static int test_wolfSSL_CertManagerCheckOCSPResponse(void)
  3666. {
  3667. EXPECT_DECLS;
  3668. #if defined(HAVE_OCSP) && !defined(NO_RSA) && !defined(NO_SHA)
  3669. /* Need one of these for wolfSSL_OCSP_REQUEST_new. */
  3670. #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \
  3671. defined(WOLFSSL_HAPROXY) || defined(WOLFSSL_APACHE_HTTPD) || \
  3672. defined(HAVE_LIGHTY)
  3673. WOLFSSL_CERT_MANAGER* cm = NULL;
  3674. /* Raw OCSP response bytes captured using the following setup:
  3675. * - Run responder with
  3676. * openssl ocsp -port 9999 -ndays 9999
  3677. * -index certs/ocsp/index-intermediate1-ca-issued-certs.txt
  3678. * -rsigner certs/ocsp/ocsp-responder-cert.pem
  3679. * -rkey certs/ocsp/ocsp-responder-key.pem
  3680. * -CA certs/ocsp/intermediate1-ca-cert.pem
  3681. * - Run client with
  3682. * openssl ocsp -host 127.0.0.1:9999 -respout resp.out
  3683. * -issuer certs/ocsp/intermediate1-ca-cert.pem
  3684. * -cert certs/ocsp/server1-cert.pem
  3685. * -CAfile certs/ocsp/root-ca-cert.pem -noverify
  3686. * - Select the response packet in Wireshark, and export it using
  3687. * "File->Export Packet Dissection->As "C" Arrays". Select "Selected
  3688. * packets only". After importing into the editor, remove the initial
  3689. * ~148 bytes of header, ending with the Content-Length and the \r\n\r\n.
  3690. */
  3691. static const byte response[] = {
  3692. 0x30, 0x82, 0x07, 0x40, /* ....0..@ */
  3693. 0x0a, 0x01, 0x00, 0xa0, 0x82, 0x07, 0x39, 0x30, /* ......90 */
  3694. 0x82, 0x07, 0x35, 0x06, 0x09, 0x2b, 0x06, 0x01, /* ..5..+.. */
  3695. 0x05, 0x05, 0x07, 0x30, 0x01, 0x01, 0x04, 0x82, /* ...0.... */
  3696. 0x07, 0x26, 0x30, 0x82, 0x07, 0x22, 0x30, 0x82, /* .&0.."0. */
  3697. 0x01, 0x40, 0xa1, 0x81, 0xa1, 0x30, 0x81, 0x9e, /* .@...0.. */
  3698. 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, /* 1.0...U. */
  3699. 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, /* ...US1.0 */
  3700. 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a, /* ...U.... */
  3701. 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67, 0x74, /* Washingt */
  3702. 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, /* on1.0... */
  3703. 0x55, 0x04, 0x07, 0x0c, 0x07, 0x53, 0x65, 0x61, /* U....Sea */
  3704. 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10, 0x30, 0x0e, /* ttle1.0. */
  3705. 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x77, /* ..U....w */
  3706. 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x31, 0x14, /* olfSSL1. */
  3707. 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, /* 0...U... */
  3708. 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, /* .Enginee */
  3709. 0x72, 0x69, 0x6e, 0x67, 0x31, 0x1f, 0x30, 0x1d, /* ring1.0. */
  3710. 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x16, 0x77, /* ..U....w */
  3711. 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x4f, /* olfSSL O */
  3712. 0x43, 0x53, 0x50, 0x20, 0x52, 0x65, 0x73, 0x70, /* CSP Resp */
  3713. 0x6f, 0x6e, 0x64, 0x65, 0x72, 0x31, 0x1f, 0x30, /* onder1.0 */
  3714. 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, /* ...*.H.. */
  3715. 0x0d, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6e, /* ......in */
  3716. 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, 0x66, 0x73, /* fo@wolfs */
  3717. 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x18, 0x0f, /* sl.com.. */
  3718. 0x32, 0x30, 0x32, 0x33, 0x31, 0x31, 0x30, 0x38, /* 20231108 */
  3719. 0x30, 0x30, 0x32, 0x36, 0x33, 0x37, 0x5a, 0x30, /* 002637Z0 */
  3720. 0x64, 0x30, 0x62, 0x30, 0x3a, 0x30, 0x09, 0x06, /* d0b0:0.. */
  3721. 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, /* .+...... */
  3722. 0x04, 0x14, 0x71, 0x4d, 0x82, 0x23, 0x40, 0x59, /* ..qM.#@Y */
  3723. 0xc0, 0x96, 0xa1, 0x37, 0x43, 0xfa, 0x31, 0xdb, /* ...7C.1. */
  3724. 0xba, 0xb1, 0x43, 0x18, 0xda, 0x04, 0x04, 0x14, /* ..C..... */
  3725. 0x83, 0xc6, 0x3a, 0x89, 0x2c, 0x81, 0xf4, 0x02, /* ..:.,... */
  3726. 0xd7, 0x9d, 0x4c, 0xe2, 0x2a, 0xc0, 0x71, 0x82, /* ..L.*.q. */
  3727. 0x64, 0x44, 0xda, 0x0e, 0x02, 0x01, 0x05, 0x80, /* dD...... */
  3728. 0x00, 0x18, 0x0f, 0x32, 0x30, 0x32, 0x33, 0x31, /* ...20231 */
  3729. 0x31, 0x30, 0x38, 0x30, 0x30, 0x32, 0x36, 0x33, /* 10800263 */
  3730. 0x37, 0x5a, 0xa0, 0x11, 0x18, 0x0f, 0x32, 0x30, /* 7Z....20 */
  3731. 0x35, 0x31, 0x30, 0x33, 0x32, 0x35, 0x30, 0x30, /* 51032500 */
  3732. 0x32, 0x36, 0x33, 0x37, 0x5a, 0xa1, 0x23, 0x30, /* 2637Z.#0 */
  3733. 0x21, 0x30, 0x1f, 0x06, 0x09, 0x2b, 0x06, 0x01, /* !0...+.. */
  3734. 0x05, 0x05, 0x07, 0x30, 0x01, 0x02, 0x04, 0x12, /* ...0.... */
  3735. 0x04, 0x10, 0xdb, 0xbc, 0x2a, 0x76, 0xa0, 0xb4, /* ....*v.. */
  3736. 0x1e, 0x5d, 0xf6, 0x2b, 0x8e, 0x38, 0x62, 0xdb, /* .].+.8b. */
  3737. 0x90, 0xed, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, /* ..0...*. */
  3738. 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, /* H....... */
  3739. 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x87, 0xde, /* ........ */
  3740. 0xfb, 0xf9, 0x3a, 0x90, 0x1f, 0x90, 0xde, 0xcf, /* ..:..... */
  3741. 0xfe, 0xad, 0x64, 0x19, 0x34, 0x17, 0xf8, 0x15, /* ..d.4... */
  3742. 0x01, 0x22, 0x5f, 0x67, 0x41, 0xa4, 0x18, 0xf7, /* ."_gA... */
  3743. 0x16, 0xb7, 0xc9, 0xf3, 0xe1, 0x9f, 0xcd, 0x40, /* .......@ */
  3744. 0x56, 0x77, 0x6e, 0x6a, 0xfb, 0x92, 0x6a, 0x6f, /* Vwnj..jo */
  3745. 0x28, 0x3e, 0x22, 0x48, 0xa1, 0xc2, 0xd8, 0x1d, /* (>"H.... */
  3746. 0xc7, 0xe6, 0x78, 0x7f, 0xb6, 0x09, 0xfe, 0x2c, /* ..x...., */
  3747. 0xb5, 0xef, 0x29, 0x7c, 0xc5, 0x51, 0x16, 0x7b, /* ..)|.Q.{ */
  3748. 0x8f, 0xfb, 0x44, 0xa8, 0xcd, 0xf5, 0x5c, 0x0f, /* ..D...\. */
  3749. 0x46, 0x0e, 0xb1, 0xa4, 0xeb, 0x5b, 0xf5, 0x86, /* F....[.. */
  3750. 0x11, 0x0f, 0xcd, 0xe2, 0xe5, 0x3c, 0x91, 0x72, /* .....<.r */
  3751. 0x0d, 0x6a, 0xcb, 0x95, 0x99, 0x39, 0x91, 0x48, /* .j...9.H */
  3752. 0x65, 0x97, 0xb9, 0x78, 0xb5, 0x88, 0x7f, 0x76, /* e..x...v */
  3753. 0xa1, 0x43, 0x2f, 0xf6, 0x1f, 0x49, 0xb7, 0x08, /* .C/..I.. */
  3754. 0x36, 0xe4, 0x2e, 0x34, 0x25, 0xda, 0x16, 0x74, /* 6..4%..t */
  3755. 0x47, 0x62, 0x56, 0xff, 0x2f, 0x02, 0x03, 0x44, /* GbV./..D */
  3756. 0x89, 0x04, 0xe7, 0xb8, 0xde, 0x0a, 0x35, 0x43, /* ......5C */
  3757. 0xae, 0xd7, 0x54, 0xbe, 0xc3, 0x7c, 0x95, 0xa5, /* ..T..|.. */
  3758. 0xc8, 0xe0, 0x2e, 0x52, 0xb6, 0xea, 0x99, 0x45, /* ...R...E */
  3759. 0xfd, 0xda, 0x4b, 0xd5, 0x79, 0x07, 0x64, 0xca, /* ..K.y.d. */
  3760. 0x64, 0xba, 0x52, 0x12, 0x62, 0x8c, 0x08, 0x9a, /* d.R.b... */
  3761. 0x32, 0xeb, 0x85, 0x65, 0x05, 0x39, 0x07, 0x5d, /* 2..e.9.] */
  3762. 0x39, 0x4a, 0xcf, 0xa5, 0x30, 0xf6, 0xd1, 0xf7, /* 9J..0... */
  3763. 0x29, 0xaa, 0x23, 0x42, 0xc6, 0x85, 0x16, 0x7f, /* ).#B.... */
  3764. 0x64, 0x16, 0xb1, 0xb0, 0x5d, 0xcd, 0x88, 0x2d, /* d...]..- */
  3765. 0x06, 0xb0, 0xa9, 0xdf, 0xa3, 0x9f, 0x25, 0x41, /* ......%A */
  3766. 0x89, 0x9a, 0x19, 0xe1, 0xaa, 0xcd, 0xdf, 0x51, /* .......Q */
  3767. 0xcb, 0xa9, 0xc3, 0x7e, 0x27, 0xbc, 0x7d, 0x9b, /* ...~'.}. */
  3768. 0x6f, 0x4d, 0x79, 0x87, 0x09, 0x3f, 0xac, 0xd2, /* oMy..?.. */
  3769. 0x4a, 0x3b, 0xbe, 0xf8, 0x7a, 0xa4, 0x93, 0x45, /* J;..z..E */
  3770. 0x11, 0x64, 0x40, 0xc5, 0x03, 0xc9, 0x24, 0x5b, /* .d@...$[ */
  3771. 0xe9, 0x6d, 0xfc, 0x94, 0x08, 0xbe, 0xa0, 0x82, /* .m...... */
  3772. 0x04, 0xc6, 0x30, 0x82, 0x04, 0xc2, 0x30, 0x82, /* ..0...0. */
  3773. 0x04, 0xbe, 0x30, 0x82, 0x03, 0xa6, 0xa0, 0x03, /* ..0..... */
  3774. 0x02, 0x01, 0x02, 0x02, 0x01, 0x04, 0x30, 0x0d, /* ......0. */
  3775. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, /* ..*.H... */
  3776. 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x81, 0x97, /* .....0.. */
  3777. 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, /* 1.0...U. */
  3778. 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, /* ...US1.0 */
  3779. 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a, /* ...U.... */
  3780. 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67, 0x74, /* Washingt */
  3781. 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, /* on1.0... */
  3782. 0x55, 0x04, 0x07, 0x0c, 0x07, 0x53, 0x65, 0x61, /* U....Sea */
  3783. 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10, 0x30, 0x0e, /* ttle1.0. */
  3784. 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x77, /* ..U....w */
  3785. 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x31, 0x14, /* olfSSL1. */
  3786. 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, /* 0...U... */
  3787. 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, /* .Enginee */
  3788. 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18, 0x30, 0x16, /* ring1.0. */
  3789. 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, /* ..U....w */
  3790. 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x72, /* olfSSL r */
  3791. 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x31, 0x1f, /* oot CA1. */
  3792. 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, /* 0...*.H. */
  3793. 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, /* .......i */
  3794. 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, 0x66, /* nfo@wolf */
  3795. 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x30, /* ssl.com0 */
  3796. 0x1e, 0x17, 0x0d, 0x32, 0x32, 0x31, 0x32, 0x31, /* ...22121 */
  3797. 0x36, 0x32, 0x31, 0x31, 0x37, 0x35, 0x30, 0x5a, /* 6211750Z */
  3798. 0x17, 0x0d, 0x32, 0x35, 0x30, 0x39, 0x31, 0x31, /* ..250911 */
  3799. 0x32, 0x31, 0x31, 0x37, 0x35, 0x30, 0x5a, 0x30, /* 211750Z0 */
  3800. 0x81, 0x9e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, /* ..1.0... */
  3801. 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, /* U....US1 */
  3802. 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, /* .0...U.. */
  3803. 0x0c, 0x0a, 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e, /* ..Washin */
  3804. 0x67, 0x74, 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, /* gton1.0. */
  3805. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x53, /* ..U....S */
  3806. 0x65, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10, /* eattle1. */
  3807. 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, /* 0...U... */
  3808. 0x07, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, /* .wolfSSL */
  3809. 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, /* 1.0...U. */
  3810. 0x0b, 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, /* ...Engin */
  3811. 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x1f, /* eering1. */
  3812. 0x30, 0x1d, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, /* 0...U... */
  3813. 0x16, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, /* .wolfSSL */
  3814. 0x20, 0x4f, 0x43, 0x53, 0x50, 0x20, 0x52, 0x65, /* OCSP Re */
  3815. 0x73, 0x70, 0x6f, 0x6e, 0x64, 0x65, 0x72, 0x31, /* sponder1 */
  3816. 0x1f, 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, /* .0...*.H */
  3817. 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x10, /* ........ */
  3818. 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, /* info@wol */
  3819. 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, /* fssl.com */
  3820. 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, /* 0.."0... */
  3821. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, /* *.H..... */
  3822. 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, /* ........ */
  3823. 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, /* 0....... */
  3824. 0x00, 0xb8, 0xba, 0x23, 0xb4, 0xf6, 0xc3, 0x7b, /* ...#...{ */
  3825. 0x14, 0xc3, 0xa4, 0xf5, 0x1d, 0x61, 0xa1, 0xf5, /* .....a.. */
  3826. 0x1e, 0x63, 0xb9, 0x85, 0x23, 0x34, 0x50, 0x6d, /* .c..#4Pm */
  3827. 0xf8, 0x7c, 0xa2, 0x8a, 0x04, 0x8b, 0xd5, 0x75, /* .|.....u */
  3828. 0x5c, 0x2d, 0xf7, 0x63, 0x88, 0xd1, 0x07, 0x7a, /* \-.c...z */
  3829. 0xea, 0x0b, 0x45, 0x35, 0x2b, 0xeb, 0x1f, 0xb1, /* ..E5+... */
  3830. 0x22, 0xb4, 0x94, 0x41, 0x38, 0xe2, 0x9d, 0x74, /* "..A8..t */
  3831. 0xd6, 0x8b, 0x30, 0x22, 0x10, 0x51, 0xc5, 0xdb, /* ..0".Q.. */
  3832. 0xca, 0x3f, 0x46, 0x2b, 0xfe, 0xe5, 0x5a, 0x3f, /* .?F+..Z? */
  3833. 0x41, 0x74, 0x67, 0x75, 0x95, 0xa9, 0x94, 0xd5, /* Atgu.... */
  3834. 0xc3, 0xee, 0x42, 0xf8, 0x8d, 0xeb, 0x92, 0x95, /* ..B..... */
  3835. 0xe1, 0xd9, 0x65, 0xb7, 0x43, 0xc4, 0x18, 0xde, /* ..e.C... */
  3836. 0x16, 0x80, 0x90, 0xce, 0x24, 0x35, 0x21, 0xc4, /* ....$5!. */
  3837. 0x55, 0xac, 0x5a, 0x51, 0xe0, 0x2e, 0x2d, 0xb3, /* U.ZQ..-. */
  3838. 0x0a, 0x5a, 0x4f, 0x4a, 0x73, 0x31, 0x50, 0xee, /* .ZOJs1P. */
  3839. 0x4a, 0x16, 0xbd, 0x39, 0x8b, 0xad, 0x05, 0x48, /* J..9...H */
  3840. 0x87, 0xb1, 0x99, 0xe2, 0x10, 0xa7, 0x06, 0x72, /* .......r */
  3841. 0x67, 0xca, 0x5c, 0xd1, 0x97, 0xbd, 0xc8, 0xf1, /* g.\..... */
  3842. 0x76, 0xf8, 0xe0, 0x4a, 0xec, 0xbc, 0x93, 0xf4, /* v..J.... */
  3843. 0x66, 0x4c, 0x28, 0x71, 0xd1, 0xd8, 0x66, 0x03, /* fL(q..f. */
  3844. 0xb4, 0x90, 0x30, 0xbb, 0x17, 0xb0, 0xfe, 0x97, /* ..0..... */
  3845. 0xf5, 0x1e, 0xe8, 0xc7, 0x5d, 0x9b, 0x8b, 0x11, /* ....]... */
  3846. 0x19, 0x12, 0x3c, 0xab, 0x82, 0x71, 0x78, 0xff, /* ..<..qx. */
  3847. 0xae, 0x3f, 0x32, 0xb2, 0x08, 0x71, 0xb2, 0x1b, /* .?2..q.. */
  3848. 0x8c, 0x27, 0xac, 0x11, 0xb8, 0xd8, 0x43, 0x49, /* .'....CI */
  3849. 0xcf, 0xb0, 0x70, 0xb1, 0xf0, 0x8c, 0xae, 0xda, /* ..p..... */
  3850. 0x24, 0x87, 0x17, 0x3b, 0xd8, 0x04, 0x65, 0x6c, /* $..;..el */
  3851. 0x00, 0x76, 0x50, 0xef, 0x15, 0x08, 0xd7, 0xb4, /* .vP..... */
  3852. 0x73, 0x68, 0x26, 0x14, 0x87, 0x95, 0xc3, 0x5f, /* sh&...._ */
  3853. 0x6e, 0x61, 0xb8, 0x87, 0x84, 0xfa, 0x80, 0x1a, /* na...... */
  3854. 0x0a, 0x8b, 0x98, 0xf3, 0xe3, 0xff, 0x4e, 0x44, /* ......ND */
  3855. 0x1c, 0x65, 0x74, 0x7c, 0x71, 0x54, 0x65, 0xe5, /* .et|qTe. */
  3856. 0x39, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x82, /* 9....... */
  3857. 0x01, 0x0a, 0x30, 0x82, 0x01, 0x06, 0x30, 0x09, /* ..0...0. */
  3858. 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, /* ..U....0 */
  3859. 0x00, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, /* .0...U.. */
  3860. 0x04, 0x16, 0x04, 0x14, 0x32, 0x67, 0xe1, 0xb1, /* ....2g.. */
  3861. 0x79, 0xd2, 0x81, 0xfc, 0x9f, 0x23, 0x0c, 0x70, /* y....#.p */
  3862. 0x40, 0x50, 0xb5, 0x46, 0x56, 0xb8, 0x30, 0x36, /* @P.FV.06 */
  3863. 0x30, 0x81, 0xc4, 0x06, 0x03, 0x55, 0x1d, 0x23, /* 0....U.# */
  3864. 0x04, 0x81, 0xbc, 0x30, 0x81, 0xb9, 0x80, 0x14, /* ...0.... */
  3865. 0x73, 0xb0, 0x1c, 0xa4, 0x2f, 0x82, 0xcb, 0xcf, /* s.../... */
  3866. 0x47, 0xa5, 0x38, 0xd7, 0xb0, 0x04, 0x82, 0x3a, /* G.8....: */
  3867. 0x7e, 0x72, 0x15, 0x21, 0xa1, 0x81, 0x9d, 0xa4, /* ~r.!.... */
  3868. 0x81, 0x9a, 0x30, 0x81, 0x97, 0x31, 0x0b, 0x30, /* ..0..1.0 */
  3869. 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, /* ...U.... */
  3870. 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, /* US1.0... */
  3871. 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x57, 0x61, 0x73, /* U....Was */
  3872. 0x68, 0x69, 0x6e, 0x67, 0x74, 0x6f, 0x6e, 0x31, /* hington1 */
  3873. 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, /* .0...U.. */
  3874. 0x0c, 0x07, 0x53, 0x65, 0x61, 0x74, 0x74, 0x6c, /* ..Seattl */
  3875. 0x65, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, /* e1.0...U */
  3876. 0x04, 0x0a, 0x0c, 0x07, 0x77, 0x6f, 0x6c, 0x66, /* ....wolf */
  3877. 0x53, 0x53, 0x4c, 0x31, 0x14, 0x30, 0x12, 0x06, /* SSL1.0.. */
  3878. 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45, 0x6e, /* .U....En */
  3879. 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, /* gineerin */
  3880. 0x67, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, /* g1.0...U */
  3881. 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x6f, 0x6c, 0x66, /* ....wolf */
  3882. 0x53, 0x53, 0x4c, 0x20, 0x72, 0x6f, 0x6f, 0x74, /* SSL root */
  3883. 0x20, 0x43, 0x41, 0x31, 0x1f, 0x30, 0x1d, 0x06, /* CA1.0.. */
  3884. 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, /* .*.H.... */
  3885. 0x09, 0x01, 0x16, 0x10, 0x69, 0x6e, 0x66, 0x6f, /* ....info */
  3886. 0x40, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, /* @wolfssl */
  3887. 0x2e, 0x63, 0x6f, 0x6d, 0x82, 0x01, 0x63, 0x30, /* .com..c0 */
  3888. 0x13, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x04, 0x0c, /* ...U.%.. */
  3889. 0x30, 0x0a, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, /* 0...+... */
  3890. 0x05, 0x07, 0x03, 0x09, 0x30, 0x0d, 0x06, 0x09, /* ....0... */
  3891. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, /* *.H..... */
  3892. 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, /* ........ */
  3893. 0x2f, 0xb7, 0x6b, 0xec, 0xb7, 0x12, 0x63, 0xb9, /* /.k...c. */
  3894. 0x57, 0xdc, 0x04, 0x4d, 0x9c, 0x67, 0x74, 0x98, /* W..M.gt. */
  3895. 0x06, 0x28, 0x68, 0x37, 0x34, 0xc2, 0x50, 0xe9, /* .(h74.P. */
  3896. 0x2a, 0xd4, 0x1a, 0xb2, 0x32, 0x1a, 0x9d, 0x2b, /* *...2..+ */
  3897. 0x4f, 0x23, 0x50, 0xea, 0xb4, 0x95, 0x86, 0xc3, /* O#P..... */
  3898. 0xb9, 0x5f, 0x34, 0x3e, 0x99, 0x91, 0xa7, 0x80, /* ._4>.... */
  3899. 0x5f, 0x6e, 0x1b, 0x6e, 0xdb, 0xe9, 0x02, 0x38, /* _n.n...8 */
  3900. 0x6f, 0xdf, 0xc5, 0x9b, 0x0d, 0xa3, 0x1c, 0xa9, /* o....... */
  3901. 0x15, 0x76, 0x16, 0x66, 0xa8, 0x4e, 0xfb, 0xd3, /* .v.f.N.. */
  3902. 0x43, 0x76, 0xf1, 0x72, 0xb7, 0xd1, 0xfa, 0xee, /* Cv.r.... */
  3903. 0x39, 0xa6, 0x96, 0xc1, 0xa2, 0x93, 0xa4, 0x9b, /* 9....... */
  3904. 0x1e, 0x9f, 0xba, 0x71, 0x8f, 0xba, 0xbd, 0x67, /* ...q...g */
  3905. 0x6a, 0xf2, 0x15, 0x5f, 0xf1, 0x64, 0xe7, 0xcf, /* j.._.d.. */
  3906. 0x26, 0xb8, 0x4c, 0xc0, 0xeb, 0x85, 0x04, 0x58, /* &.L....X */
  3907. 0xd9, 0x4a, 0x6b, 0xd9, 0x86, 0xf5, 0x80, 0x21, /* .Jk....! */
  3908. 0xbf, 0x91, 0xc8, 0x4b, 0x9f, 0x04, 0xed, 0x57, /* ...K...W */
  3909. 0x7a, 0xd2, 0x58, 0xac, 0x5b, 0x47, 0xaf, 0x4d, /* z.X.[G.M */
  3910. 0x7f, 0x5b, 0x1d, 0x6d, 0x68, 0x9b, 0x84, 0x98, /* .[.mh... */
  3911. 0x2a, 0x31, 0x02, 0x2c, 0xe9, 0x1b, 0xaf, 0x11, /* *1.,.... */
  3912. 0x0b, 0x78, 0x49, 0xbe, 0x68, 0x68, 0xcb, 0x9c, /* .xI.hh.. */
  3913. 0x41, 0x56, 0xe8, 0xb5, 0x59, 0xda, 0xff, 0xca, /* AV..Y... */
  3914. 0x59, 0x99, 0x17, 0x3e, 0x11, 0x0a, 0x8f, 0x49, /* Y..>...I */
  3915. 0x24, 0x0b, 0x81, 0x42, 0x63, 0xcd, 0x4f, 0xf6, /* $..Bc.O. */
  3916. 0x2b, 0x9d, 0xd1, 0x79, 0x75, 0xd7, 0x4a, 0xcc, /* +..yu.J. */
  3917. 0x4c, 0xb7, 0x2b, 0xd7, 0xe8, 0xe7, 0xd4, 0x48, /* L.+....H */
  3918. 0x3c, 0x14, 0x3b, 0x1c, 0x28, 0xe8, 0x46, 0x7a, /* <.;.(.Fz */
  3919. 0xdc, 0x11, 0x9d, 0x7f, 0x1c, 0xab, 0x10, 0x95, /* ........ */
  3920. 0x17, 0xb2, 0xc7, 0x7a, 0xbb, 0x17, 0x44, 0x59, /* ...z..DY */
  3921. 0x69, 0x8e, 0x16, 0x05, 0x94, 0x8c, 0x88, 0xd9, /* i....... */
  3922. 0xdc, 0x9a, 0xfd, 0xf2, 0x93, 0xbe, 0x68, 0xba, /* ......h. */
  3923. 0x3c, 0xd6, 0x2b, 0x61, 0x3a, 0x8b, 0xf7, 0x66, /* <.+a:..f */
  3924. 0xcb, 0x54, 0xe8, 0xe4, 0xdb, 0x9f, 0xcc, 0x9e /* .T...... */
  3925. };
  3926. OcspEntry entry[1];
  3927. CertStatus status[1];
  3928. OcspRequest* request = NULL;
  3929. #ifndef NO_FILESYSTEM
  3930. const char* ca_cert = "./certs/ca-cert.pem";
  3931. #endif
  3932. byte serial[] = {0x05};
  3933. byte issuerHash[] = {0x71, 0x4d, 0x82, 0x23, 0x40, 0x59, 0xc0, 0x96, 0xa1, 0x37, 0x43, 0xfa, 0x31, 0xdb, 0xba, 0xb1, 0x43, 0x18, 0xda, 0x04};
  3934. byte issuerKeyHash[] = {0x83, 0xc6, 0x3a, 0x89, 0x2c, 0x81, 0xf4, 0x02, 0xd7, 0x9d, 0x4c, 0xe2, 0x2a, 0xc0, 0x71, 0x82, 0x64, 0x44, 0xda, 0x0e};
  3935. XMEMSET(entry, 0, sizeof(OcspEntry));
  3936. XMEMSET(status, 0, sizeof(CertStatus));
  3937. ExpectNotNull(request = wolfSSL_OCSP_REQUEST_new());
  3938. ExpectNotNull(request->serial = (byte*)XMALLOC(sizeof(serial), NULL,
  3939. DYNAMIC_TYPE_OCSP_REQUEST));
  3940. if ((request != NULL) && (request->serial != NULL)) {
  3941. request->serialSz = sizeof(serial);
  3942. XMEMCPY(request->serial, serial, sizeof(serial));
  3943. XMEMCPY(request->issuerHash, issuerHash, sizeof(issuerHash));
  3944. XMEMCPY(request->issuerKeyHash, issuerKeyHash, sizeof(issuerKeyHash));
  3945. }
  3946. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  3947. ExpectIntEQ(wolfSSL_CertManagerEnableOCSP(cm, 0), WOLFSSL_SUCCESS);
  3948. ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm,
  3949. "./certs/ocsp/intermediate1-ca-cert.pem", NULL), WOLFSSL_SUCCESS);
  3950. /* Response should be valid. */
  3951. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, (byte *)response,
  3952. sizeof(response), NULL, status, entry, request), WOLFSSL_SUCCESS);
  3953. /* Flip a byte in the request serial number, response should be invalid
  3954. * now. */
  3955. if ((request != NULL) && (request->serial != NULL))
  3956. request->serial[0] ^= request->serial[0];
  3957. ExpectIntNE(wolfSSL_CertManagerCheckOCSPResponse(cm, (byte *)response,
  3958. sizeof(response), NULL, status, entry, request), WOLFSSL_SUCCESS);
  3959. #ifndef NO_FILESYSTEM
  3960. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, server_cert_der_2048,
  3961. sizeof(server_cert_der_2048)), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  3962. ExpectIntEQ(WOLFSSL_SUCCESS,
  3963. wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL));
  3964. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, server_cert_der_2048,
  3965. sizeof(server_cert_der_2048)), 1);
  3966. #endif
  3967. wolfSSL_OCSP_REQUEST_free(request);
  3968. wolfSSL_CertManagerFree(cm);
  3969. #endif /* OPENSSL_ALL || WOLFSSL_NGINX || WOLFSSL_HAPROXY ||
  3970. * WOLFSSL_APACHE_HTTPD || HAVE_LIGHTY */
  3971. #endif /* HAVE_OCSP */
  3972. return EXPECT_RESULT();
  3973. }
  3974. static int test_wolfSSL_CheckOCSPResponse(void)
  3975. {
  3976. EXPECT_DECLS;
  3977. #if defined(HAVE_OCSP) && defined(OPENSSL_EXTRA) && \
  3978. !defined(NO_RSA) && !defined(NO_SHA)
  3979. const char* responseFile = "./certs/ocsp/test-response.der";
  3980. const char* responseMultiFile = "./certs/ocsp/test-multi-response.der";
  3981. const char* responseNoInternFile =
  3982. "./certs/ocsp/test-response-nointern.der";
  3983. const char* caFile = "./certs/ocsp/root-ca-cert.pem";
  3984. OcspResponse* res = NULL;
  3985. byte data[4096];
  3986. const unsigned char* pt;
  3987. int dataSz = 0; /* initialize to mitigate spurious maybe-uninitialized from
  3988. * gcc sanitizer with --enable-heapmath.
  3989. */
  3990. XFILE f = XBADFILE;
  3991. WOLFSSL_OCSP_BASICRESP* bs = NULL;
  3992. WOLFSSL_X509_STORE* st = NULL;
  3993. WOLFSSL_X509* issuer = NULL;
  3994. ExpectTrue((f = XFOPEN(responseFile, "rb")) != XBADFILE);
  3995. ExpectIntGT(dataSz = (word32)XFREAD(data, 1, sizeof(data), f), 0);
  3996. if (f != XBADFILE) {
  3997. XFCLOSE(f);
  3998. f = XBADFILE;
  3999. }
  4000. pt = data;
  4001. ExpectNotNull(res = wolfSSL_d2i_OCSP_RESPONSE(NULL, &pt, dataSz));
  4002. ExpectNotNull(issuer = wolfSSL_X509_load_certificate_file(caFile,
  4003. SSL_FILETYPE_PEM));
  4004. ExpectNotNull(st = wolfSSL_X509_STORE_new());
  4005. ExpectIntEQ(wolfSSL_X509_STORE_add_cert(st, issuer), WOLFSSL_SUCCESS);
  4006. ExpectNotNull(bs = wolfSSL_OCSP_response_get1_basic(res));
  4007. ExpectIntEQ(wolfSSL_OCSP_basic_verify(bs, NULL, st, 0), WOLFSSL_SUCCESS);
  4008. wolfSSL_OCSP_BASICRESP_free(bs);
  4009. bs = NULL;
  4010. wolfSSL_OCSP_RESPONSE_free(res);
  4011. res = NULL;
  4012. wolfSSL_X509_STORE_free(st);
  4013. st = NULL;
  4014. wolfSSL_X509_free(issuer);
  4015. issuer = NULL;
  4016. /* check loading a response with optional certs */
  4017. ExpectTrue((f = XFOPEN(responseNoInternFile, "rb")) != XBADFILE);
  4018. ExpectIntGT(dataSz = (word32)XFREAD(data, 1, sizeof(data), f), 0);
  4019. if (f != XBADFILE)
  4020. XFCLOSE(f);
  4021. f = XBADFILE;
  4022. pt = data;
  4023. ExpectNotNull(res = wolfSSL_d2i_OCSP_RESPONSE(NULL, &pt, dataSz));
  4024. wolfSSL_OCSP_RESPONSE_free(res);
  4025. res = NULL;
  4026. /* check loading a response with multiple certs */
  4027. {
  4028. WOLFSSL_CERT_MANAGER* cm = NULL;
  4029. OcspEntry *entry = NULL;
  4030. CertStatus* status = NULL;
  4031. OcspRequest* request = NULL;
  4032. byte serial1[] = {0x01};
  4033. byte serial[] = {0x02};
  4034. byte issuerHash[] = {
  4035. 0x44, 0xA8, 0xDB, 0xD1, 0xBC, 0x97, 0x0A, 0x83,
  4036. 0x3B, 0x5B, 0x31, 0x9A, 0x4C, 0xB8, 0xD2, 0x52,
  4037. 0x37, 0x15, 0x8A, 0x88
  4038. };
  4039. byte issuerKeyHash[] = {
  4040. 0x73, 0xB0, 0x1C, 0xA4, 0x2F, 0x82, 0xCB, 0xCF,
  4041. 0x47, 0xA5, 0x38, 0xD7, 0xB0, 0x04, 0x82, 0x3A,
  4042. 0x7E, 0x72, 0x15, 0x21
  4043. };
  4044. ExpectNotNull(entry = (OcspEntry*)XMALLOC(sizeof(OcspEntry), NULL,
  4045. DYNAMIC_TYPE_OPENSSL));
  4046. ExpectNotNull(status = (CertStatus*)XMALLOC(sizeof(CertStatus), NULL,
  4047. DYNAMIC_TYPE_OPENSSL));
  4048. if (entry != NULL)
  4049. XMEMSET(entry, 0, sizeof(OcspEntry));
  4050. if (status != NULL)
  4051. XMEMSET(status, 0, sizeof(CertStatus));
  4052. ExpectNotNull(request = wolfSSL_OCSP_REQUEST_new());
  4053. ExpectNotNull(request->serial = (byte*)XMALLOC(sizeof(serial), NULL,
  4054. DYNAMIC_TYPE_OCSP_REQUEST));
  4055. if (request != NULL && request->serial != NULL) {
  4056. request->serialSz = sizeof(serial);
  4057. XMEMCPY(request->serial, serial, sizeof(serial));
  4058. XMEMCPY(request->issuerHash, issuerHash, sizeof(issuerHash));
  4059. XMEMCPY(request->issuerKeyHash, issuerKeyHash,
  4060. sizeof(issuerKeyHash));
  4061. }
  4062. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  4063. ExpectIntEQ(wolfSSL_CertManagerEnableOCSP(cm, 0), WOLFSSL_SUCCESS);
  4064. ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, caFile, NULL),
  4065. WOLFSSL_SUCCESS);
  4066. ExpectTrue((f = XFOPEN(responseMultiFile, "rb")) != XBADFILE);
  4067. ExpectIntGT(dataSz = (word32)XFREAD(data, 1, sizeof(data), f), 0);
  4068. if (f != XBADFILE)
  4069. XFCLOSE(f);
  4070. f = XBADFILE;
  4071. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, data,
  4072. dataSz, NULL, status, entry, request), WOLFSSL_SUCCESS);
  4073. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, data,
  4074. dataSz, NULL, entry->status, entry, request), WOLFSSL_SUCCESS);
  4075. ExpectNotNull(entry->status);
  4076. if (request != NULL && request->serial != NULL)
  4077. XMEMCPY(request->serial, serial1, sizeof(serial1));
  4078. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, data,
  4079. dataSz, NULL, status, entry, request), WOLFSSL_SUCCESS);
  4080. /* store both status's in the entry to check that "next" is not
  4081. * overwritten */
  4082. if (EXPECT_SUCCESS() && status != NULL && entry != NULL) {
  4083. status->next = entry->status;
  4084. entry->status = status;
  4085. }
  4086. if (request != NULL && request->serial != NULL)
  4087. XMEMCPY(request->serial, serial, sizeof(serial));
  4088. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, data,
  4089. dataSz, NULL, entry->status, entry, request), WOLFSSL_SUCCESS);
  4090. ExpectNotNull(entry->status->next);
  4091. /* compare the status found */
  4092. ExpectIntEQ(status->serialSz, entry->status->serialSz);
  4093. ExpectIntEQ(XMEMCMP(status->serial, entry->status->serial,
  4094. status->serialSz), 0);
  4095. if (status != NULL && entry != NULL && entry->status != status) {
  4096. XFREE(status, NULL, DYNAMIC_TYPE_OPENSSL);
  4097. }
  4098. wolfSSL_OCSP_CERTID_free(entry);
  4099. wolfSSL_OCSP_REQUEST_free(request);
  4100. wolfSSL_CertManagerFree(cm);
  4101. }
  4102. #if defined(WC_RSA_PSS)
  4103. {
  4104. const char* responsePssFile = "./certs/ocsp/test-response-rsapss.der";
  4105. /* check loading a response with RSA-PSS signature */
  4106. ExpectTrue((f = XFOPEN(responsePssFile, "rb")) != XBADFILE);
  4107. ExpectIntGT(dataSz = (word32)XFREAD(data, 1, sizeof(data), f), 0);
  4108. if (f != XBADFILE)
  4109. XFCLOSE(f);
  4110. pt = data;
  4111. ExpectNotNull(res = wolfSSL_d2i_OCSP_RESPONSE(NULL, &pt, dataSz));
  4112. /* try to verify the response */
  4113. ExpectNotNull(issuer = wolfSSL_X509_load_certificate_file(caFile,
  4114. SSL_FILETYPE_PEM));
  4115. ExpectNotNull(st = wolfSSL_X509_STORE_new());
  4116. ExpectIntEQ(wolfSSL_X509_STORE_add_cert(st, issuer), WOLFSSL_SUCCESS);
  4117. ExpectNotNull(bs = wolfSSL_OCSP_response_get1_basic(res));
  4118. ExpectIntEQ(wolfSSL_OCSP_basic_verify(bs, NULL, st, 0),
  4119. WOLFSSL_SUCCESS);
  4120. wolfSSL_OCSP_BASICRESP_free(bs);
  4121. wolfSSL_OCSP_RESPONSE_free(res);
  4122. wolfSSL_X509_STORE_free(st);
  4123. wolfSSL_X509_free(issuer);
  4124. }
  4125. #endif
  4126. #endif /* HAVE_OCSP */
  4127. return EXPECT_RESULT();
  4128. }
  4129. static int test_wolfSSL_FPKI(void)
  4130. {
  4131. EXPECT_DECLS;
  4132. #if defined(WOLFSSL_FPKI) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  4133. XFILE f = XBADFILE;
  4134. const char* fpkiCert = "./certs/fpki-cert.der";
  4135. DecodedCert cert;
  4136. byte buf[4096];
  4137. byte* uuid = NULL;
  4138. byte* fascn = NULL;
  4139. word32 fascnSz;
  4140. word32 uuidSz;
  4141. int bytes = 0;
  4142. ExpectTrue((f = XFOPEN(fpkiCert, "rb")) != XBADFILE);
  4143. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  4144. if (f != XBADFILE)
  4145. XFCLOSE(f);
  4146. wc_InitDecodedCert(&cert, buf, (word32)bytes, NULL);
  4147. ExpectIntEQ(wc_ParseCert(&cert, CERT_TYPE, 0, NULL), 0);
  4148. ExpectIntEQ(wc_GetFASCNFromCert(&cert, NULL, &fascnSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  4149. ExpectNotNull(fascn = (byte*)XMALLOC(fascnSz, NULL,
  4150. DYNAMIC_TYPE_TMP_BUFFER));
  4151. ExpectIntEQ(wc_GetFASCNFromCert(&cert, fascn, &fascnSz), 0);
  4152. XFREE(fascn, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  4153. ExpectIntEQ(wc_GetUUIDFromCert(&cert, NULL, &uuidSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  4154. ExpectNotNull(uuid = (byte*)XMALLOC(uuidSz, NULL, DYNAMIC_TYPE_TMP_BUFFER));
  4155. ExpectIntEQ(wc_GetUUIDFromCert(&cert, uuid, &uuidSz), 0);
  4156. XFREE(uuid, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  4157. wc_FreeDecodedCert(&cert);
  4158. #endif
  4159. return EXPECT_RESULT();
  4160. }
  4161. /* use RID in confuncture with other names to test parsing of unknown other
  4162. * names */
  4163. static int test_wolfSSL_OtherName(void)
  4164. {
  4165. EXPECT_DECLS;
  4166. #if !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  4167. XFILE f = XBADFILE;
  4168. const char* ridCert = "./certs/rid-cert.der";
  4169. DecodedCert cert;
  4170. byte buf[4096];
  4171. int bytes = 0;
  4172. ExpectTrue((f = XFOPEN(ridCert, "rb")) != XBADFILE);
  4173. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  4174. if (f != XBADFILE)
  4175. XFCLOSE(f);
  4176. wc_InitDecodedCert(&cert, buf, (word32)bytes, NULL);
  4177. ExpectIntEQ(wc_ParseCert(&cert, CERT_TYPE, 0, NULL), 0);
  4178. wc_FreeDecodedCert(&cert);
  4179. #endif
  4180. return EXPECT_RESULT();
  4181. }
  4182. #ifdef HAVE_CERT_CHAIN_VALIDATION
  4183. static int test_wolfSSL_CertRsaPss(void)
  4184. {
  4185. EXPECT_DECLS;
  4186. /* FIPS v2 and below don't support long salts. */
  4187. #if !defined(NO_RSA) && defined(WC_RSA_PSS) && !defined(NO_FILESYSTEM) && \
  4188. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  4189. (HAVE_FIPS_VERSION > 2))) && (!defined(HAVE_SELFTEST) || \
  4190. (defined(HAVE_SELFTEST_VERSION) && (HAVE_SELFTEST_VERSION > 2)))
  4191. XFILE f = XBADFILE;
  4192. const char* rsaPssSha256Cert = "./certs/rsapss/ca-rsapss.der";
  4193. const char* rsaPssRootSha256Cert = "./certs/rsapss/root-rsapss.pem";
  4194. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_PSS_LONG_SALT) && \
  4195. RSA_MAX_SIZE >= 3072
  4196. const char* rsaPssSha384Cert = "./certs/rsapss/ca-3072-rsapss.der";
  4197. #endif
  4198. #if defined(WOLFSSL_SHA384) && RSA_MAX_SIZE >= 3072
  4199. const char* rsaPssRootSha384Cert = "./certs/rsapss/root-3072-rsapss.pem";
  4200. #endif
  4201. DecodedCert cert;
  4202. byte buf[4096];
  4203. int bytes = 0;
  4204. WOLFSSL_CERT_MANAGER* cm = NULL;
  4205. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  4206. ExpectIntEQ(WOLFSSL_SUCCESS,
  4207. wolfSSL_CertManagerLoadCA(cm, rsaPssRootSha256Cert, NULL));
  4208. #if defined(WOLFSSL_SHA384) && RSA_MAX_SIZE >= 3072
  4209. ExpectIntEQ(WOLFSSL_SUCCESS,
  4210. wolfSSL_CertManagerLoadCA(cm, rsaPssRootSha384Cert, NULL));
  4211. #endif
  4212. ExpectTrue((f = XFOPEN(rsaPssSha256Cert, "rb")) != XBADFILE);
  4213. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  4214. if (f != XBADFILE) {
  4215. XFCLOSE(f);
  4216. f = XBADFILE;
  4217. }
  4218. wc_InitDecodedCert(&cert, buf, (word32)bytes, NULL);
  4219. ExpectIntEQ(wc_ParseCert(&cert, CERT_TYPE, VERIFY, cm), 0);
  4220. wc_FreeDecodedCert(&cert);
  4221. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_PSS_LONG_SALT) && \
  4222. RSA_MAX_SIZE >= 3072
  4223. ExpectTrue((f = XFOPEN(rsaPssSha384Cert, "rb")) != XBADFILE);
  4224. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  4225. if (f != XBADFILE)
  4226. XFCLOSE(f);
  4227. wc_InitDecodedCert(&cert, buf, (word32)bytes, NULL);
  4228. ExpectIntEQ(wc_ParseCert(&cert, CERT_TYPE, VERIFY, cm), 0);
  4229. wc_FreeDecodedCert(&cert);
  4230. #endif
  4231. wolfSSL_CertManagerFree(cm);
  4232. #endif
  4233. return EXPECT_RESULT();
  4234. }
  4235. #endif
  4236. static int test_wolfSSL_CTX_load_verify_locations_ex(void)
  4237. {
  4238. EXPECT_DECLS;
  4239. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4240. !defined(NO_WOLFSSL_CLIENT)
  4241. WOLFSSL_CTX* ctx = NULL;
  4242. const char* ca_cert = "./certs/ca-cert.pem";
  4243. const char* ca_expired_cert = "./certs/test/expired/expired-ca.pem";
  4244. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4245. /* test good CA */
  4246. ExpectTrue(WOLFSSL_SUCCESS ==
  4247. wolfSSL_CTX_load_verify_locations_ex(ctx, ca_cert, NULL,
  4248. WOLFSSL_LOAD_FLAG_NONE));
  4249. /* test expired CA */
  4250. #if !defined(OPENSSL_COMPATIBLE_DEFAULTS) && !defined(NO_ASN_TIME)
  4251. ExpectIntNE(wolfSSL_CTX_load_verify_locations_ex(ctx, ca_expired_cert, NULL,
  4252. WOLFSSL_LOAD_FLAG_NONE), WOLFSSL_SUCCESS);
  4253. #else
  4254. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, ca_expired_cert, NULL,
  4255. WOLFSSL_LOAD_FLAG_NONE), WOLFSSL_SUCCESS);
  4256. #endif
  4257. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, ca_expired_cert, NULL,
  4258. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), WOLFSSL_SUCCESS);
  4259. wolfSSL_CTX_free(ctx);
  4260. #endif
  4261. return EXPECT_RESULT();
  4262. }
  4263. static int test_wolfSSL_CTX_load_verify_buffer_ex(void)
  4264. {
  4265. EXPECT_DECLS;
  4266. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA)
  4267. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  4268. WOLFSSL_CTX* ctx;
  4269. const char* ca_expired_cert_file = "./certs/test/expired/expired-ca.der";
  4270. byte ca_expired_cert[TWOK_BUF];
  4271. word32 sizeof_ca_expired_cert = 0;
  4272. XFILE fp = XBADFILE;
  4273. #ifndef NO_WOLFSSL_CLIENT
  4274. ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  4275. #else
  4276. ctx = wolfSSL_CTX_new(wolfSSLv23_server_method());
  4277. #endif
  4278. ExpectNotNull(ctx);
  4279. #if defined(USE_CERT_BUFFERS_2048)
  4280. /* test good CA */
  4281. ExpectTrue(WOLFSSL_SUCCESS ==
  4282. wolfSSL_CTX_load_verify_buffer_ex(ctx, ca_cert_der_2048,
  4283. sizeof_ca_cert_der_2048, WOLFSSL_FILETYPE_ASN1, 0,
  4284. WOLFSSL_LOAD_FLAG_NONE));
  4285. #endif
  4286. /* load expired CA */
  4287. XMEMSET(ca_expired_cert, 0, sizeof(ca_expired_cert));
  4288. ExpectTrue((fp = XFOPEN(ca_expired_cert_file, "rb")) != XBADFILE);
  4289. ExpectIntGT(sizeof_ca_expired_cert = (word32)XFREAD(ca_expired_cert, 1,
  4290. sizeof(ca_expired_cert), fp), 0);
  4291. if (fp != XBADFILE)
  4292. XFCLOSE(fp);
  4293. /* test expired CA failure */
  4294. #if !defined(OPENSSL_COMPATIBLE_DEFAULTS) && !defined(NO_ASN_TIME)
  4295. ExpectIntNE(wolfSSL_CTX_load_verify_buffer_ex(ctx, ca_expired_cert,
  4296. sizeof_ca_expired_cert, WOLFSSL_FILETYPE_ASN1, 0,
  4297. WOLFSSL_LOAD_FLAG_NONE), WOLFSSL_SUCCESS);
  4298. #else
  4299. ExpectIntEQ(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. #endif
  4303. /* test expired CA success */
  4304. ExpectIntEQ(wolfSSL_CTX_load_verify_buffer_ex(ctx, ca_expired_cert,
  4305. sizeof_ca_expired_cert, WOLFSSL_FILETYPE_ASN1, 0,
  4306. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), WOLFSSL_SUCCESS);
  4307. /* Fail when ctx is NULL. */
  4308. ExpectIntEQ(wolfSSL_CTX_load_verify_buffer_ex(NULL, ca_expired_cert,
  4309. sizeof_ca_expired_cert, WOLFSSL_FILETYPE_ASN1, 0,
  4310. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4311. /* Load as modified cert - bad initial length. */
  4312. ca_expired_cert[2] = 0x7f;
  4313. ExpectIntEQ(wolfSSL_CTX_load_verify_buffer_ex(ctx, ca_expired_cert,
  4314. sizeof_ca_expired_cert, WOLFSSL_FILETYPE_ASN1, 1,
  4315. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), WC_NO_ERR_TRACE(ASN_PARSE_E));
  4316. wolfSSL_CTX_free(ctx);
  4317. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  4318. #endif
  4319. return EXPECT_RESULT();
  4320. }
  4321. static int test_wolfSSL_CTX_load_verify_chain_buffer_format(void)
  4322. {
  4323. EXPECT_DECLS;
  4324. #if !defined(NO_CERTS) && !defined(NO_RSA) && defined(OPENSSL_EXTRA) && \
  4325. defined(USE_CERT_BUFFERS_2048) && (WOLFSSL_MIN_RSA_BITS <= 1024) && \
  4326. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4327. WOLFSSL_CTX* ctx = NULL;
  4328. #ifndef NO_WOLFSSL_CLIENT
  4329. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4330. #else
  4331. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4332. #endif
  4333. /* Public key 140 bytes??? */
  4334. ExpectIntEQ(wolfSSL_CTX_load_verify_chain_buffer_format(ctx,
  4335. ca_cert_chain_der, sizeof_ca_cert_chain_der, WOLFSSL_FILETYPE_ASN1),
  4336. WOLFSSL_SUCCESS);
  4337. wolfSSL_CTX_free(ctx);
  4338. #endif
  4339. return EXPECT_RESULT();
  4340. }
  4341. static int test_wolfSSL_CTX_add1_chain_cert(void)
  4342. {
  4343. EXPECT_DECLS;
  4344. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && defined(OPENSSL_EXTRA) && \
  4345. defined(KEEP_OUR_CERT) && !defined(NO_RSA) && !defined(NO_WOLFSSL_CLIENT)
  4346. WOLFSSL_CTX* ctx;
  4347. WOLFSSL* ssl = NULL;
  4348. const char *certChain[] = {
  4349. "./certs/intermediate/client-int-cert.pem",
  4350. "./certs/intermediate/ca-int2-cert.pem",
  4351. "./certs/intermediate/ca-int-cert.pem",
  4352. "./certs/ca-cert.pem",
  4353. NULL
  4354. };
  4355. const char** cert;
  4356. WOLFSSL_X509* x509 = NULL;
  4357. WOLF_STACK_OF(X509)* chain = NULL;
  4358. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4359. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4360. ExpectNotNull(x509 = wolfSSL_X509_new());
  4361. ExpectIntEQ(SSL_CTX_add1_chain_cert(ctx, x509), 0);
  4362. ExpectIntEQ(SSL_CTX_add0_chain_cert(ctx, x509), 0);
  4363. ExpectIntEQ(SSL_add1_chain_cert(ssl, x509), 0);
  4364. ExpectIntEQ(SSL_add0_chain_cert(ssl, x509), 0);
  4365. wolfSSL_X509_free(x509);
  4366. x509 = NULL;
  4367. for (cert = certChain; EXPECT_SUCCESS() && *cert != NULL; cert++) {
  4368. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(*cert,
  4369. WOLFSSL_FILETYPE_PEM));
  4370. /* Do negative tests once */
  4371. if (cert == certChain) {
  4372. /* Negative tests. */
  4373. ExpectIntEQ(SSL_CTX_add1_chain_cert(NULL, NULL), 0);
  4374. ExpectIntEQ(SSL_CTX_add1_chain_cert(ctx, NULL), 0);
  4375. ExpectIntEQ(SSL_CTX_add1_chain_cert(NULL, x509), 0);
  4376. ExpectIntEQ(SSL_CTX_add0_chain_cert(NULL, NULL), 0);
  4377. ExpectIntEQ(SSL_CTX_add0_chain_cert(ctx, NULL), 0);
  4378. ExpectIntEQ(SSL_CTX_add0_chain_cert(NULL, x509), 0);
  4379. }
  4380. ExpectIntEQ(SSL_CTX_add1_chain_cert(ctx, x509), 1);
  4381. X509_free(x509);
  4382. x509 = NULL;
  4383. }
  4384. for (cert = certChain; EXPECT_SUCCESS() && *cert != NULL; cert++) {
  4385. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(*cert,
  4386. WOLFSSL_FILETYPE_PEM));
  4387. /* Do negative tests once */
  4388. if (cert == certChain) {
  4389. /* Negative tests. */
  4390. ExpectIntEQ(SSL_add1_chain_cert(NULL, NULL), 0);
  4391. ExpectIntEQ(SSL_add1_chain_cert(ssl, NULL), 0);
  4392. ExpectIntEQ(SSL_add1_chain_cert(NULL, x509), 0);
  4393. ExpectIntEQ(SSL_add0_chain_cert(NULL, NULL), 0);
  4394. ExpectIntEQ(SSL_add0_chain_cert(ssl, NULL), 0);
  4395. ExpectIntEQ(SSL_add0_chain_cert(NULL, x509), 0);
  4396. }
  4397. ExpectIntEQ(SSL_add1_chain_cert(ssl, x509), 1);
  4398. X509_free(x509);
  4399. x509 = NULL;
  4400. }
  4401. ExpectIntEQ(SSL_CTX_get0_chain_certs(ctx, &chain), 1);
  4402. ExpectIntEQ(sk_X509_num(chain), 3);
  4403. ExpectIntEQ(SSL_get0_chain_certs(ssl, &chain), 1);
  4404. ExpectIntEQ(sk_X509_num(chain), 3);
  4405. SSL_free(ssl);
  4406. SSL_CTX_free(ctx);
  4407. #endif
  4408. return EXPECT_RESULT();
  4409. }
  4410. static int test_wolfSSL_CTX_use_certificate_chain_buffer_format(void)
  4411. {
  4412. EXPECT_DECLS;
  4413. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4414. !defined(NO_WOLFSSL_CLIENT) && defined(USE_CERT_BUFFERS_2048)
  4415. WOLFSSL_CTX* ctx = NULL;
  4416. WOLFSSL* ssl = NULL;
  4417. const char* cert = "./certs/server-cert.pem";
  4418. unsigned char* buf = NULL;
  4419. size_t len;
  4420. ExpectIntEQ(load_file(cert, &buf, &len), 0);
  4421. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4422. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4423. /* Invalid parameters. */
  4424. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer_format(NULL,
  4425. NULL, 0, WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4426. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer_format(ctx,
  4427. NULL, 0, WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  4428. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer_format(NULL,
  4429. server_cert_der_2048, sizeof_server_cert_der_2048,
  4430. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4431. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(NULL, NULL, 0),
  4432. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4433. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(ctx, NULL, 0),
  4434. WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  4435. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(NULL, buf, (long)len),
  4436. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4437. ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(NULL, NULL, 0),
  4438. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4439. ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(ssl, NULL, 0),
  4440. WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  4441. ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(NULL, buf, (long)len),
  4442. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4443. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer_format(ctx,
  4444. server_cert_der_2048, sizeof_server_cert_der_2048,
  4445. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  4446. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer_format(ctx, buf,
  4447. (long)len, WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  4448. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(ctx, buf, (long)len),
  4449. WOLFSSL_SUCCESS);
  4450. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(ctx,
  4451. server_cert_der_2048, sizeof_server_cert_der_2048), WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  4452. ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(ssl, buf, (long)len),
  4453. WOLFSSL_SUCCESS);
  4454. ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(ssl, server_cert_der_2048,
  4455. sizeof_server_cert_der_2048), WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  4456. wolfSSL_free(ssl);
  4457. wolfSSL_CTX_free(ctx);
  4458. if (buf != NULL) {
  4459. free(buf);
  4460. }
  4461. #endif
  4462. return EXPECT_RESULT();
  4463. }
  4464. static int test_wolfSSL_CTX_use_certificate_chain_file_format(void)
  4465. {
  4466. EXPECT_DECLS;
  4467. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4468. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4469. const char* server_chain_der = "./certs/server-cert-chain.der";
  4470. const char* client_single_pem = "./certs/client-cert.pem";
  4471. WOLFSSL_CTX* ctx = NULL;
  4472. (void)server_chain_der;
  4473. (void)client_single_pem;
  4474. (void)ctx;
  4475. #ifndef NO_WOLFSSL_CLIENT
  4476. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4477. #else
  4478. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4479. #endif
  4480. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file_format(ctx,
  4481. server_chain_der, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  4482. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file_format(ctx,
  4483. client_single_pem, WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  4484. wolfSSL_CTX_free(ctx);
  4485. #endif
  4486. return EXPECT_RESULT();
  4487. }
  4488. static int test_wolfSSL_use_certificate_chain_file(void)
  4489. {
  4490. EXPECT_DECLS;
  4491. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4492. !defined(NO_WOLFSSL_CLIENT)
  4493. const char* server_chain_der = "./certs/server-cert-chain.der";
  4494. const char* client_single_pem = "./certs/client-cert.pem";
  4495. WOLFSSL_CTX* ctx = NULL;
  4496. WOLFSSL* ssl = NULL;
  4497. (void)server_chain_der;
  4498. (void)client_single_pem;
  4499. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4500. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4501. /* Invalid parameters. */
  4502. ExpectIntEQ(wolfSSL_use_certificate_chain_file_format(NULL, NULL,
  4503. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4504. ExpectIntEQ(wolfSSL_use_certificate_chain_file_format(ssl, NULL,
  4505. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4506. ExpectIntEQ(wolfSSL_use_certificate_chain_file_format(NULL,
  4507. server_chain_der, WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4508. ExpectIntEQ(wolfSSL_use_certificate_chain_file(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4509. ExpectIntEQ(wolfSSL_use_certificate_chain_file(ssl, NULL),
  4510. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4511. ExpectIntEQ(wolfSSL_use_certificate_chain_file(NULL, client_single_pem),
  4512. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4513. ExpectIntEQ(wolfSSL_use_certificate_chain_file(ssl, server_chain_der),
  4514. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4515. ExpectIntEQ(wolfSSL_use_certificate_chain_file_format(ssl,
  4516. server_chain_der, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  4517. ExpectIntEQ(wolfSSL_use_certificate_chain_file_format(ssl,
  4518. client_single_pem, WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  4519. ExpectIntEQ(wolfSSL_use_certificate_chain_file(ssl, client_single_pem),
  4520. WOLFSSL_SUCCESS);
  4521. wolfSSL_free(ssl);
  4522. wolfSSL_CTX_free(ctx);
  4523. #endif
  4524. return EXPECT_RESULT();
  4525. }
  4526. static int test_wolfSSL_CTX_SetTmpDH_file(void)
  4527. {
  4528. EXPECT_DECLS;
  4529. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_DH) && \
  4530. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4531. WOLFSSL_CTX *ctx = NULL;
  4532. #if defined(WOLFSSL_WPAS) && !defined(NO_DSA)
  4533. const char* dsaParamFile = "./certs/dsaparams.pem";
  4534. #endif
  4535. (void)ctx;
  4536. #ifndef NO_WOLFSSL_CLIENT
  4537. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4538. #else
  4539. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4540. #endif
  4541. /* invalid context */
  4542. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(NULL,
  4543. dhParamFile, WOLFSSL_FILETYPE_PEM));
  4544. /* invalid dhParamFile file */
  4545. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(ctx,
  4546. NULL, WOLFSSL_FILETYPE_PEM));
  4547. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(ctx,
  4548. bogusFile, WOLFSSL_FILETYPE_PEM));
  4549. /* success */
  4550. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(ctx, dhParamFile,
  4551. WOLFSSL_FILETYPE_PEM));
  4552. #if defined(WOLFSSL_WPAS) && !defined(NO_DSA)
  4553. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(ctx, dsaParamFile,
  4554. WOLFSSL_FILETYPE_PEM));
  4555. #endif
  4556. wolfSSL_CTX_free(ctx);
  4557. #endif
  4558. return EXPECT_RESULT();
  4559. }
  4560. static int test_wolfSSL_CTX_SetTmpDH_buffer(void)
  4561. {
  4562. EXPECT_DECLS;
  4563. #if !defined(NO_CERTS) && !defined(NO_DH) && \
  4564. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4565. WOLFSSL_CTX *ctx = NULL;
  4566. #ifndef NO_WOLFSSL_CLIENT
  4567. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4568. #else
  4569. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4570. #endif
  4571. /* invalid context */
  4572. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(NULL,
  4573. dh_key_der_2048, sizeof_dh_key_der_2048,
  4574. WOLFSSL_FILETYPE_ASN1));
  4575. /* invalid dhParamFile file */
  4576. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(NULL, NULL,
  4577. 0, WOLFSSL_FILETYPE_ASN1));
  4578. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx, NULL,
  4579. 0, WOLFSSL_FILETYPE_ASN1));
  4580. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4581. dsa_key_der_2048, sizeof_dsa_key_der_2048,
  4582. WOLFSSL_FILETYPE_ASN1));
  4583. /* invalid file format */
  4584. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4585. dh_key_der_2048, sizeof_dh_key_der_2048, -1));
  4586. /* success */
  4587. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4588. dh_key_der_2048, sizeof_dh_key_der_2048,
  4589. WOLFSSL_FILETYPE_ASN1));
  4590. wolfSSL_CTX_free(ctx);
  4591. #endif
  4592. return EXPECT_RESULT();
  4593. }
  4594. static int test_wolfSSL_CTX_SetMinMaxDhKey_Sz(void)
  4595. {
  4596. EXPECT_DECLS;
  4597. #if !defined(NO_CERTS) && !defined(NO_DH) && \
  4598. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4599. WOLFSSL_CTX *ctx;
  4600. (void)ctx;
  4601. #ifndef NO_WOLFSSL_CLIENT
  4602. ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  4603. #else
  4604. ctx = wolfSSL_CTX_new(wolfSSLv23_server_method());
  4605. #endif
  4606. ExpectNotNull(ctx);
  4607. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMinDhKey_Sz(ctx, 3072));
  4608. ExpectIntEQ(WC_NO_ERR_TRACE(DH_KEY_SIZE_E), wolfSSL_CTX_SetTmpDH_buffer(ctx, dh_key_der_2048,
  4609. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4610. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMinDhKey_Sz(ctx, 2048));
  4611. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4612. dh_key_der_2048, sizeof_dh_key_der_2048,
  4613. WOLFSSL_FILETYPE_ASN1));
  4614. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMaxDhKey_Sz(ctx, 1024));
  4615. ExpectIntEQ(WC_NO_ERR_TRACE(DH_KEY_SIZE_E), 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, 2048));
  4619. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4620. dh_key_der_2048, sizeof_dh_key_der_2048,
  4621. WOLFSSL_FILETYPE_ASN1));
  4622. wolfSSL_CTX_free(ctx);
  4623. #endif
  4624. return EXPECT_RESULT();
  4625. }
  4626. static int test_wolfSSL_CTX_der_load_verify_locations(void)
  4627. {
  4628. EXPECT_DECLS;
  4629. #if !defined(NO_FILESYSTEM) && defined(WOLFSSL_DER_LOAD) && \
  4630. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4631. WOLFSSL_CTX* ctx = NULL;
  4632. const char* derCert = "./certs/server-cert.der";
  4633. const char* nullPath = NULL;
  4634. const char* invalidPath = "./certs/this-cert-does-not-exist.der";
  4635. const char* emptyPath = "";
  4636. /* der load Case 1 ctx NULL */
  4637. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, derCert,
  4638. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4639. #ifndef NO_WOLFSSL_CLIENT
  4640. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4641. #else
  4642. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4643. #endif
  4644. /* Case 2 filePath NULL */
  4645. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, nullPath,
  4646. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4647. /* Case 3 invalid format */
  4648. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, derCert,
  4649. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4650. /* Case 4 filePath not valid */
  4651. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, invalidPath,
  4652. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4653. /* Case 5 filePath empty */
  4654. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, emptyPath,
  4655. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4656. #ifndef NO_RSA
  4657. /* Case 6 success case */
  4658. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, derCert,
  4659. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  4660. #endif
  4661. wolfSSL_CTX_free(ctx);
  4662. #endif
  4663. return EXPECT_RESULT();
  4664. }
  4665. static int test_wolfSSL_CTX_enable_disable(void)
  4666. {
  4667. EXPECT_DECLS;
  4668. #ifndef NO_CERTS
  4669. WOLFSSL_CTX* ctx = NULL;
  4670. #ifdef HAVE_CRL
  4671. ExpectIntEQ(wolfSSL_CTX_DisableCRL(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4672. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4673. #endif
  4674. #ifdef HAVE_OCSP
  4675. ExpectIntEQ(wolfSSL_CTX_DisableOCSP(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4676. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4677. #endif
  4678. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) || \
  4679. defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  4680. ExpectIntEQ(wolfSSL_CTX_DisableOCSPStapling(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4681. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4682. ExpectIntEQ(wolfSSL_CTX_DisableOCSPMustStaple(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4683. ExpectIntEQ(wolfSSL_CTX_EnableOCSPMustStaple(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4684. #endif
  4685. #ifndef NO_WOLFSSL_CLIENT
  4686. #ifdef HAVE_EXTENDED_MASTER
  4687. ExpectIntEQ(wolfSSL_CTX_DisableExtendedMasterSecret(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4688. #endif
  4689. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4690. #ifdef HAVE_EXTENDED_MASTER
  4691. ExpectIntEQ(wolfSSL_CTX_DisableExtendedMasterSecret(ctx), WOLFSSL_SUCCESS);
  4692. #endif
  4693. #elif !defined(NO_WOLFSSL_SERVER)
  4694. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4695. #endif
  4696. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  4697. #ifdef HAVE_CRL
  4698. ExpectIntEQ(wolfSSL_CTX_DisableCRL(ctx), WOLFSSL_SUCCESS);
  4699. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, 0), WOLFSSL_SUCCESS);
  4700. #endif
  4701. #ifdef HAVE_OCSP
  4702. ExpectIntEQ(wolfSSL_CTX_DisableOCSP(ctx), WOLFSSL_SUCCESS);
  4703. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, WOLFSSL_OCSP_URL_OVERRIDE),
  4704. WOLFSSL_SUCCESS);
  4705. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, WOLFSSL_OCSP_NO_NONCE),
  4706. WOLFSSL_SUCCESS);
  4707. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, WOLFSSL_OCSP_CHECKALL),
  4708. WOLFSSL_SUCCESS);
  4709. #endif
  4710. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) || \
  4711. defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  4712. ExpectIntEQ(wolfSSL_CTX_DisableOCSPStapling(ctx), WOLFSSL_SUCCESS);
  4713. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), WOLFSSL_SUCCESS);
  4714. ExpectIntEQ(wolfSSL_CTX_DisableOCSPMustStaple(ctx), WOLFSSL_SUCCESS);
  4715. ExpectIntEQ(wolfSSL_CTX_DisableOCSPMustStaple(ctx), WOLFSSL_SUCCESS);
  4716. #endif
  4717. wolfSSL_CTX_free(ctx);
  4718. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  4719. #endif /* NO_CERTS */
  4720. return EXPECT_RESULT();
  4721. }
  4722. static int test_wolfSSL_CTX_ticket_API(void)
  4723. {
  4724. EXPECT_DECLS;
  4725. #if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_SERVER)
  4726. WOLFSSL_CTX* ctx = NULL;
  4727. void *userCtx = (void*)"this is my ctx";
  4728. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4729. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_set_TicketEncCtx(ctx, userCtx));
  4730. ExpectTrue(userCtx == wolfSSL_CTX_get_TicketEncCtx(ctx));
  4731. wolfSSL_CTX_free(ctx);
  4732. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_set_TicketEncCtx(NULL, userCtx));
  4733. ExpectNull(wolfSSL_CTX_get_TicketEncCtx(NULL));
  4734. #endif /* HAVE_SESSION_TICKET && !NO_WOLFSSL_SERVER */
  4735. return EXPECT_RESULT();
  4736. }
  4737. static int test_wolfSSL_set_minmax_proto_version(void)
  4738. {
  4739. EXPECT_DECLS;
  4740. #ifdef OPENSSL_EXTRA
  4741. WOLFSSL_CTX *ctx = NULL;
  4742. WOLFSSL *ssl = NULL;
  4743. (void)ssl;
  4744. #ifndef NO_WOLFSSL_CLIENT
  4745. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4746. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4747. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4748. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4749. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, 0), SSL_SUCCESS);
  4750. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(ctx, 0), SSL_SUCCESS);
  4751. ExpectIntEQ(wolfSSL_set_min_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4752. ExpectIntEQ(wolfSSL_set_min_proto_version(ssl, 0), SSL_SUCCESS);
  4753. ExpectIntEQ(wolfSSL_set_max_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4754. ExpectIntEQ(wolfSSL_set_max_proto_version(ssl, 0), SSL_SUCCESS);
  4755. wolfSSL_free(ssl);
  4756. wolfSSL_CTX_free(ctx);
  4757. ctx = NULL;
  4758. #endif
  4759. #ifndef NO_WOLFSSL_SERVER
  4760. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4761. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4762. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4763. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, 0), SSL_SUCCESS);
  4764. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(ctx, 0), SSL_SUCCESS);
  4765. wolfSSL_CTX_free(ctx);
  4766. #endif
  4767. #endif
  4768. return EXPECT_RESULT();
  4769. }
  4770. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_TLS12) && \
  4771. defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  4772. static int test_wolfSSL_CTX_set_max_proto_version_on_result(WOLFSSL* ssl)
  4773. {
  4774. EXPECT_DECLS;
  4775. ExpectStrEQ(wolfSSL_get_version(ssl), "TLSv1.2");
  4776. return EXPECT_RESULT();
  4777. }
  4778. static int test_wolfSSL_CTX_set_max_proto_version_ctx_ready(WOLFSSL_CTX* ctx)
  4779. {
  4780. EXPECT_DECLS;
  4781. /* Set TLS 1.2 */
  4782. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(ctx, TLS1_2_VERSION),
  4783. WOLFSSL_SUCCESS);
  4784. return EXPECT_RESULT();
  4785. }
  4786. /* Test using wolfSSL_CTX_set_max_proto_version to limit the version below
  4787. * what was set at ctx creation. */
  4788. static int test_wolfSSL_CTX_set_max_proto_version(void)
  4789. {
  4790. EXPECT_DECLS;
  4791. test_ssl_cbf client_cbs;
  4792. test_ssl_cbf server_cbs;
  4793. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  4794. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  4795. client_cbs.method = wolfTLS_client_method;
  4796. server_cbs.method = wolfTLS_server_method;
  4797. server_cbs.ctx_ready = test_wolfSSL_CTX_set_max_proto_version_ctx_ready;
  4798. client_cbs.on_result = test_wolfSSL_CTX_set_max_proto_version_on_result;
  4799. server_cbs.on_result = test_wolfSSL_CTX_set_max_proto_version_on_result;
  4800. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  4801. &server_cbs, NULL), TEST_SUCCESS);
  4802. return EXPECT_RESULT();
  4803. }
  4804. #else
  4805. static int test_wolfSSL_CTX_set_max_proto_version(void)
  4806. {
  4807. return TEST_SKIPPED;
  4808. }
  4809. #endif
  4810. /*----------------------------------------------------------------------------*
  4811. | SSL
  4812. *----------------------------------------------------------------------------*/
  4813. static int test_server_wolfSSL_new(void)
  4814. {
  4815. EXPECT_DECLS;
  4816. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4817. !defined(NO_WOLFSSL_SERVER)
  4818. WOLFSSL_CTX *ctx = NULL;
  4819. WOLFSSL_CTX *ctx_nocert = NULL;
  4820. WOLFSSL *ssl = NULL;
  4821. ExpectNotNull(ctx_nocert = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4822. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4823. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  4824. WOLFSSL_FILETYPE_PEM));
  4825. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  4826. WOLFSSL_FILETYPE_PEM));
  4827. /* invalid context */
  4828. ExpectNull(ssl = wolfSSL_new(NULL));
  4829. #if !defined(WOLFSSL_SESSION_EXPORT) && !defined(WOLFSSL_QT) && \
  4830. !defined(OPENSSL_EXTRA) && !defined(WOLFSSL_NO_INIT_CTX_KEY)
  4831. ExpectNull(ssl = wolfSSL_new(ctx_nocert));
  4832. #endif
  4833. /* success */
  4834. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4835. wolfSSL_free(ssl);
  4836. wolfSSL_CTX_free(ctx);
  4837. wolfSSL_CTX_free(ctx_nocert);
  4838. #endif
  4839. return EXPECT_RESULT();
  4840. }
  4841. static int test_client_wolfSSL_new(void)
  4842. {
  4843. EXPECT_DECLS;
  4844. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4845. !defined(NO_WOLFSSL_CLIENT)
  4846. WOLFSSL_CTX *ctx = NULL;
  4847. WOLFSSL_CTX *ctx_nocert = NULL;
  4848. WOLFSSL *ssl = NULL;
  4849. ExpectNotNull(ctx_nocert = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4850. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4851. ExpectTrue(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0));
  4852. /* invalid context */
  4853. ExpectNull(ssl = wolfSSL_new(NULL));
  4854. /* success */
  4855. ExpectNotNull(ssl = wolfSSL_new(ctx_nocert));
  4856. wolfSSL_free(ssl);
  4857. ssl = NULL;
  4858. /* success */
  4859. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4860. wolfSSL_free(ssl);
  4861. wolfSSL_CTX_free(ctx);
  4862. wolfSSL_CTX_free(ctx_nocert);
  4863. #endif
  4864. return EXPECT_RESULT();
  4865. }
  4866. static int test_wolfSSL_SetTmpDH_file(void)
  4867. {
  4868. EXPECT_DECLS;
  4869. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_DH) && \
  4870. !defined(NO_WOLFSSL_SERVER)
  4871. WOLFSSL_CTX *ctx = NULL;
  4872. WOLFSSL *ssl = NULL;
  4873. const char* dhX942ParamFile = "./certs/x942dh2048.pem";
  4874. #if defined(WOLFSSL_WPAS) && !defined(NO_DSA)
  4875. const char* dsaParamFile = "./certs/dsaparams.pem";
  4876. #endif
  4877. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4878. #ifndef NO_RSA
  4879. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  4880. WOLFSSL_FILETYPE_PEM));
  4881. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  4882. WOLFSSL_FILETYPE_PEM));
  4883. #elif defined(HAVE_ECC)
  4884. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, eccCertFile,
  4885. WOLFSSL_FILETYPE_PEM));
  4886. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, eccKeyFile,
  4887. WOLFSSL_FILETYPE_PEM));
  4888. #elif defined(HAVE_ED25519)
  4889. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, edCertFile,
  4890. WOLFSSL_FILETYPE_PEM));
  4891. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, edKeyFile,
  4892. WOLFSSL_FILETYPE_PEM));
  4893. #elif defined(HAVE_ED448)
  4894. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, ed448CertFile,
  4895. WOLFSSL_FILETYPE_PEM));
  4896. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, ed448KeyFile,
  4897. WOLFSSL_FILETYPE_PEM));
  4898. #endif
  4899. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4900. /* invalid ssl */
  4901. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_file(NULL,
  4902. dhParamFile, WOLFSSL_FILETYPE_PEM));
  4903. /* invalid dhParamFile file */
  4904. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_file(ssl,
  4905. NULL, WOLFSSL_FILETYPE_PEM));
  4906. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_file(ssl,
  4907. bogusFile, WOLFSSL_FILETYPE_PEM));
  4908. /* success */
  4909. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_file(ssl, dhParamFile,
  4910. WOLFSSL_FILETYPE_PEM));
  4911. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_file(ssl, dhX942ParamFile,
  4912. WOLFSSL_FILETYPE_PEM));
  4913. #if defined(WOLFSSL_WPAS) && !defined(NO_DSA)
  4914. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(ctx, dsaParamFile,
  4915. WOLFSSL_FILETYPE_PEM));
  4916. #endif
  4917. wolfSSL_free(ssl);
  4918. wolfSSL_CTX_free(ctx);
  4919. #endif
  4920. return EXPECT_RESULT();
  4921. }
  4922. static int test_wolfSSL_SetTmpDH_buffer(void)
  4923. {
  4924. EXPECT_DECLS;
  4925. #if !defined(NO_CERTS) && !defined(NO_DH) && !defined(NO_WOLFSSL_SERVER)
  4926. WOLFSSL_CTX *ctx = NULL;
  4927. WOLFSSL *ssl = NULL;
  4928. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4929. ExpectTrue(wolfSSL_CTX_use_certificate_buffer(ctx, server_cert_der_2048,
  4930. sizeof_server_cert_der_2048, WOLFSSL_FILETYPE_ASN1));
  4931. ExpectTrue(wolfSSL_CTX_use_PrivateKey_buffer(ctx, server_key_der_2048,
  4932. sizeof_server_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4933. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4934. /* invalid ssl */
  4935. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(NULL, dh_key_der_2048,
  4936. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4937. /* invalid dhParamFile file */
  4938. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(NULL, NULL,
  4939. 0, WOLFSSL_FILETYPE_ASN1));
  4940. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl, NULL, 0,
  4941. WOLFSSL_FILETYPE_ASN1));
  4942. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl, dsa_key_der_2048,
  4943. sizeof_dsa_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4944. /* success */
  4945. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl, dh_key_der_2048,
  4946. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4947. wolfSSL_free(ssl);
  4948. wolfSSL_CTX_free(ctx);
  4949. #endif
  4950. return EXPECT_RESULT();
  4951. }
  4952. static int test_wolfSSL_SetMinMaxDhKey_Sz(void)
  4953. {
  4954. EXPECT_DECLS;
  4955. #if !defined(NO_CERTS) && !defined(NO_DH) && !defined(NO_WOLFSSL_SERVER)
  4956. WOLFSSL_CTX *ctx = NULL;
  4957. WOLFSSL_CTX *ctx2 = NULL;
  4958. WOLFSSL *ssl = NULL;
  4959. WOLFSSL *ssl2 = NULL;
  4960. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4961. ExpectTrue(wolfSSL_CTX_use_certificate_buffer(ctx, server_cert_der_2048,
  4962. sizeof_server_cert_der_2048, WOLFSSL_FILETYPE_ASN1));
  4963. ExpectTrue(wolfSSL_CTX_use_PrivateKey_buffer(ctx, server_key_der_2048,
  4964. sizeof_server_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4965. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMinDhKey_Sz(ctx, 3072));
  4966. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4967. ExpectNotNull(ctx2 = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4968. ExpectTrue(wolfSSL_CTX_use_certificate_buffer(ctx2, server_cert_der_2048,
  4969. sizeof_server_cert_der_2048, WOLFSSL_FILETYPE_ASN1));
  4970. ExpectTrue(wolfSSL_CTX_use_PrivateKey_buffer(ctx2, server_key_der_2048,
  4971. sizeof_server_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4972. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMaxDhKey_Sz(ctx, 1024));
  4973. ExpectNotNull(ssl2 = wolfSSL_new(ctx2));
  4974. ExpectIntEQ(WC_NO_ERR_TRACE(DH_KEY_SIZE_E), wolfSSL_SetTmpDH_buffer(ssl, dh_key_der_2048,
  4975. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4976. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetMinDhKey_Sz(ssl, 2048));
  4977. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl, dh_key_der_2048,
  4978. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4979. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetMinDhKey_Sz(ssl, 3072));
  4980. ExpectIntEQ(WC_NO_ERR_TRACE(DH_KEY_SIZE_E), wolfSSL_SetTmpDH_buffer(ssl, dh_key_der_2048,
  4981. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4982. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl2, dh_key_der_2048,
  4983. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4984. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetMaxDhKey_Sz(ssl2, 2048));
  4985. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl2, dh_key_der_2048,
  4986. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4987. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetMaxDhKey_Sz(ssl2, 1024));
  4988. ExpectIntEQ(WC_NO_ERR_TRACE(DH_KEY_SIZE_E), wolfSSL_SetTmpDH_buffer(ssl, dh_key_der_2048,
  4989. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4990. wolfSSL_free(ssl2);
  4991. wolfSSL_CTX_free(ctx2);
  4992. wolfSSL_free(ssl);
  4993. wolfSSL_CTX_free(ctx);
  4994. #endif
  4995. return EXPECT_RESULT();
  4996. }
  4997. /* Test function for wolfSSL_SetMinVersion. Sets the minimum downgrade version
  4998. * allowed.
  4999. * POST: return 1 on success.
  5000. */
  5001. static int test_wolfSSL_SetMinVersion(void)
  5002. {
  5003. int res = TEST_SKIPPED;
  5004. #ifndef NO_WOLFSSL_CLIENT
  5005. int failFlag = WOLFSSL_SUCCESS;
  5006. WOLFSSL_CTX* ctx = NULL;
  5007. WOLFSSL* ssl = NULL;
  5008. int itr;
  5009. #ifndef NO_OLD_TLS
  5010. const int versions[] = {
  5011. #ifdef WOLFSSL_ALLOW_TLSV10
  5012. WOLFSSL_TLSV1,
  5013. #endif
  5014. WOLFSSL_TLSV1_1,
  5015. WOLFSSL_TLSV1_2};
  5016. #elif !defined(WOLFSSL_NO_TLS12)
  5017. const int versions[] = { WOLFSSL_TLSV1_2 };
  5018. #else
  5019. const int versions[] = { WOLFSSL_TLSV1_3 };
  5020. #endif
  5021. ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  5022. ssl = wolfSSL_new(ctx);
  5023. for (itr = 0; itr < (int)(sizeof(versions)/sizeof(int)); itr++) {
  5024. if (wolfSSL_SetMinVersion(ssl, *(versions + itr)) != WOLFSSL_SUCCESS) {
  5025. failFlag = WOLFSSL_FAILURE;
  5026. }
  5027. }
  5028. wolfSSL_free(ssl);
  5029. wolfSSL_CTX_free(ctx);
  5030. res = TEST_RES_CHECK(failFlag == WOLFSSL_SUCCESS);
  5031. #endif
  5032. return res;
  5033. } /* END test_wolfSSL_SetMinVersion */
  5034. #ifdef OPENSSL_EXTRA
  5035. static int test_EC25519(void)
  5036. {
  5037. EXPECT_DECLS;
  5038. #if defined(HAVE_CURVE25519) && defined(WOLFSSL_KEY_GEN)
  5039. byte priv[CURVE25519_KEYSIZE];
  5040. unsigned int privSz = CURVE25519_KEYSIZE;
  5041. byte pub[CURVE25519_KEYSIZE];
  5042. unsigned int pubSz = CURVE25519_KEYSIZE;
  5043. byte priv2[CURVE25519_KEYSIZE];
  5044. unsigned int priv2Sz = CURVE25519_KEYSIZE;
  5045. byte pub2[CURVE25519_KEYSIZE];
  5046. unsigned int pub2Sz = CURVE25519_KEYSIZE;
  5047. byte shared[CURVE25519_KEYSIZE];
  5048. unsigned int sharedSz = CURVE25519_KEYSIZE;
  5049. byte shared2[CURVE25519_KEYSIZE];
  5050. unsigned int shared2Sz = CURVE25519_KEYSIZE;
  5051. /* Bad parameter testing of key generation. */
  5052. ExpectIntEQ(wolfSSL_EC25519_generate_key(NULL, NULL, NULL, NULL), 0);
  5053. ExpectIntEQ(wolfSSL_EC25519_generate_key(NULL, &privSz, NULL, &pubSz), 0);
  5054. ExpectIntEQ(wolfSSL_EC25519_generate_key(NULL, &privSz, pub, &pubSz), 0);
  5055. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, NULL, pub, &pubSz), 0);
  5056. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, &privSz, NULL, &pubSz), 0);
  5057. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, &privSz, pub, NULL), 0);
  5058. /* Bad length */
  5059. privSz = 1;
  5060. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, &privSz, pub, &pubSz), 0);
  5061. privSz = CURVE25519_KEYSIZE;
  5062. pubSz = 1;
  5063. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, &privSz, pub, &pubSz), 0);
  5064. pubSz = CURVE25519_KEYSIZE;
  5065. /* Good case of generating key. */
  5066. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, &privSz, pub, &pubSz), 1);
  5067. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv2, &priv2Sz, pub2, &pub2Sz),
  5068. 1);
  5069. ExpectIntEQ(privSz, CURVE25519_KEYSIZE);
  5070. ExpectIntEQ(pubSz, CURVE25519_KEYSIZE);
  5071. /* Bad parameter testing of shared key. */
  5072. ExpectIntEQ(wolfSSL_EC25519_shared_key( NULL, NULL, NULL, privSz,
  5073. NULL, pubSz), 0);
  5074. ExpectIntEQ(wolfSSL_EC25519_shared_key( NULL, &sharedSz, NULL, privSz,
  5075. NULL, pubSz), 0);
  5076. ExpectIntEQ(wolfSSL_EC25519_shared_key( NULL, &sharedSz, priv, privSz,
  5077. pub, pubSz), 0);
  5078. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, NULL, privSz,
  5079. pub, pubSz), 0);
  5080. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  5081. NULL, pubSz), 0);
  5082. ExpectIntEQ(wolfSSL_EC25519_shared_key( NULL, &sharedSz, priv, privSz,
  5083. pub, pubSz), 0);
  5084. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, NULL, priv, privSz,
  5085. pub, pubSz), 0);
  5086. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, NULL, privSz,
  5087. pub, pubSz), 0);
  5088. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  5089. NULL, pubSz), 0);
  5090. /* Bad length. */
  5091. sharedSz = 1;
  5092. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  5093. pub, pubSz), 0);
  5094. sharedSz = CURVE25519_KEYSIZE;
  5095. privSz = 1;
  5096. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  5097. pub, pubSz), 0);
  5098. privSz = CURVE25519_KEYSIZE;
  5099. pubSz = 1;
  5100. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  5101. pub, pubSz), 0);
  5102. pubSz = CURVE25519_KEYSIZE;
  5103. /* Good case of shared key. */
  5104. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  5105. pub2, pub2Sz), 1);
  5106. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared2, &shared2Sz, priv2, priv2Sz,
  5107. pub, pubSz), 1);
  5108. ExpectIntEQ(sharedSz, CURVE25519_KEYSIZE);
  5109. ExpectIntEQ(shared2Sz, CURVE25519_KEYSIZE);
  5110. ExpectIntEQ(XMEMCMP(shared, shared2, sharedSz), 0);
  5111. #endif /* HAVE_CURVE25519 && WOLFSSL_KEY_GEN */
  5112. return EXPECT_RESULT();
  5113. }
  5114. static int test_ED25519(void)
  5115. {
  5116. EXPECT_DECLS;
  5117. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT) && \
  5118. defined(WOLFSSL_KEY_GEN)
  5119. byte priv[ED25519_PRV_KEY_SIZE];
  5120. unsigned int privSz = (unsigned int)sizeof(priv);
  5121. byte pub[ED25519_PUB_KEY_SIZE];
  5122. unsigned int pubSz = (unsigned int)sizeof(pub);
  5123. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_IMPORT)
  5124. const char* msg = TEST_STRING;
  5125. unsigned int msglen = (unsigned int)TEST_STRING_SZ;
  5126. byte sig[ED25519_SIG_SIZE];
  5127. unsigned int sigSz = (unsigned int)sizeof(sig);
  5128. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_IMPORT */
  5129. /* Bad parameter testing of key generation. */
  5130. ExpectIntEQ(wolfSSL_ED25519_generate_key(NULL, NULL, NULL, NULL), 0);
  5131. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, NULL, NULL, NULL), 0);
  5132. ExpectIntEQ(wolfSSL_ED25519_generate_key(NULL, &privSz, NULL, NULL), 0);
  5133. ExpectIntEQ(wolfSSL_ED25519_generate_key(NULL, NULL, pub, NULL), 0);
  5134. ExpectIntEQ(wolfSSL_ED25519_generate_key(NULL, NULL, NULL, &pubSz), 0);
  5135. ExpectIntEQ(wolfSSL_ED25519_generate_key(NULL, &privSz, pub, &pubSz), 0);
  5136. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, NULL, pub, &pubSz), 0);
  5137. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, &privSz, NULL, &pubSz), 0);
  5138. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, &privSz, pub, NULL), 0);
  5139. /* Bad length. */
  5140. privSz = 1;
  5141. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, &privSz, pub, &pubSz), 0);
  5142. privSz = ED25519_PRV_KEY_SIZE;
  5143. pubSz = 1;
  5144. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, &privSz, pub, &pubSz), 0);
  5145. pubSz = ED25519_PUB_KEY_SIZE;
  5146. /* Good case of generating key. */
  5147. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, &privSz, pub, &pubSz),
  5148. 1);
  5149. ExpectIntEQ(privSz, ED25519_PRV_KEY_SIZE);
  5150. ExpectIntEQ(pubSz, ED25519_PUB_KEY_SIZE);
  5151. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_IMPORT)
  5152. /* Bad parameter testing of signing. */
  5153. ExpectIntEQ(wolfSSL_ED25519_sign( NULL, msglen, NULL, privSz, NULL,
  5154. NULL), 0);
  5155. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, NULL, privSz, NULL,
  5156. NULL), 0);
  5157. ExpectIntEQ(wolfSSL_ED25519_sign( NULL, msglen, priv, privSz, NULL,
  5158. NULL), 0);
  5159. ExpectIntEQ(wolfSSL_ED25519_sign( NULL, msglen, NULL, privSz, sig,
  5160. NULL), 0);
  5161. ExpectIntEQ(wolfSSL_ED25519_sign( NULL, msglen, NULL, privSz, NULL,
  5162. &sigSz), 0);
  5163. ExpectIntEQ(wolfSSL_ED25519_sign( NULL, msglen, priv, privSz, sig,
  5164. &sigSz), 0);
  5165. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, NULL, privSz, sig,
  5166. &sigSz), 0);
  5167. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, priv, privSz, NULL,
  5168. &sigSz), 0);
  5169. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, priv, privSz, sig,
  5170. NULL), 0);
  5171. /* Bad length. */
  5172. privSz = 1;
  5173. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, priv, privSz, sig,
  5174. &sigSz), 0);
  5175. privSz = ED25519_PRV_KEY_SIZE;
  5176. sigSz = 1;
  5177. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, priv, privSz, sig,
  5178. &sigSz), 0);
  5179. sigSz = ED25519_SIG_SIZE;
  5180. /* Good case of signing. */
  5181. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, priv, privSz, sig,
  5182. &sigSz), 1);
  5183. ExpectIntEQ(sigSz, ED25519_SIG_SIZE);
  5184. #ifdef HAVE_ED25519_VERIFY
  5185. /* Bad parameter testing of verification. */
  5186. ExpectIntEQ(wolfSSL_ED25519_verify( NULL, msglen, NULL, pubSz, NULL,
  5187. sigSz), 0);
  5188. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, NULL, pubSz, NULL,
  5189. sigSz), 0);
  5190. ExpectIntEQ(wolfSSL_ED25519_verify( NULL, msglen, pub, pubSz, NULL,
  5191. sigSz), 0);
  5192. ExpectIntEQ(wolfSSL_ED25519_verify( NULL, msglen, NULL, pubSz, sig,
  5193. sigSz), 0);
  5194. ExpectIntEQ(wolfSSL_ED25519_verify( NULL, msglen, pub, pubSz, sig,
  5195. sigSz), 0);
  5196. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, NULL, pubSz, sig,
  5197. sigSz), 0);
  5198. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, pub, pubSz, NULL,
  5199. sigSz), 0);
  5200. /* Bad length. */
  5201. pubSz = 1;
  5202. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, pub, pubSz, sig,
  5203. sigSz), 0);
  5204. pubSz = ED25519_PUB_KEY_SIZE;
  5205. sigSz = 1;
  5206. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, pub, pubSz, sig,
  5207. sigSz), 0);
  5208. sigSz = ED25519_SIG_SIZE;
  5209. /* Good case of verification. */
  5210. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, pub, pubSz, sig,
  5211. sigSz), 1);
  5212. /* Bad signature. */
  5213. if (EXPECT_SUCCESS()) {
  5214. sig[1] ^= 0x80;
  5215. }
  5216. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, pub, pubSz, sig,
  5217. sigSz), 0);
  5218. #endif /* HAVE_ED25519_VERIFY */
  5219. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_IMPORT */
  5220. #endif /* HAVE_ED25519 && HAVE_ED25519_KEY_EXPORT && WOLFSSL_KEY_GEN */
  5221. return EXPECT_RESULT();
  5222. }
  5223. static int test_EC448(void)
  5224. {
  5225. EXPECT_DECLS;
  5226. #if defined(HAVE_CURVE448) && defined(WOLFSSL_KEY_GEN)
  5227. byte priv[CURVE448_KEY_SIZE];
  5228. unsigned int privSz = CURVE448_KEY_SIZE;
  5229. byte pub[CURVE448_KEY_SIZE];
  5230. unsigned int pubSz = CURVE448_KEY_SIZE;
  5231. byte priv2[CURVE448_KEY_SIZE];
  5232. unsigned int priv2Sz = CURVE448_KEY_SIZE;
  5233. byte pub2[CURVE448_KEY_SIZE];
  5234. unsigned int pub2Sz = CURVE448_KEY_SIZE;
  5235. byte shared[CURVE448_KEY_SIZE];
  5236. unsigned int sharedSz = CURVE448_KEY_SIZE;
  5237. byte shared2[CURVE448_KEY_SIZE];
  5238. unsigned int shared2Sz = CURVE448_KEY_SIZE;
  5239. /* Bad parameter testing of key generation. */
  5240. ExpectIntEQ(wolfSSL_EC448_generate_key(NULL, NULL, NULL, NULL), 0);
  5241. ExpectIntEQ(wolfSSL_EC448_generate_key(NULL, &privSz, NULL, &pubSz), 0);
  5242. ExpectIntEQ(wolfSSL_EC448_generate_key(NULL, &privSz, pub, &pubSz), 0);
  5243. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, NULL, pub, &pubSz), 0);
  5244. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, &privSz, NULL, &pubSz), 0);
  5245. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, &privSz, pub, NULL), 0);
  5246. /* Bad length. */
  5247. privSz = 1;
  5248. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, &privSz, pub, &pubSz), 0);
  5249. privSz = CURVE448_KEY_SIZE;
  5250. pubSz = 1;
  5251. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, &privSz, pub, &pubSz), 0);
  5252. pubSz = CURVE448_KEY_SIZE;
  5253. /* Good case of generating key. */
  5254. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, &privSz, pub, &pubSz), 1);
  5255. ExpectIntEQ(wolfSSL_EC448_generate_key(priv2, &priv2Sz, pub2, &pub2Sz), 1);
  5256. ExpectIntEQ(privSz, CURVE448_KEY_SIZE);
  5257. ExpectIntEQ(pubSz, CURVE448_KEY_SIZE);
  5258. /* Bad parameter testing of shared key. */
  5259. ExpectIntEQ(wolfSSL_EC448_shared_key( NULL, NULL, NULL, privSz,
  5260. NULL, pubSz), 0);
  5261. ExpectIntEQ(wolfSSL_EC448_shared_key( NULL, &sharedSz, NULL, privSz,
  5262. NULL, pubSz), 0);
  5263. ExpectIntEQ(wolfSSL_EC448_shared_key( NULL, &sharedSz, priv, privSz,
  5264. pub, pubSz), 0);
  5265. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, NULL, privSz,
  5266. pub, pubSz), 0);
  5267. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5268. NULL, pubSz), 0);
  5269. ExpectIntEQ(wolfSSL_EC448_shared_key( NULL, &sharedSz, priv, privSz,
  5270. pub, pubSz), 0);
  5271. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, NULL, priv, privSz,
  5272. pub, pubSz), 0);
  5273. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, NULL, privSz,
  5274. pub, pubSz), 0);
  5275. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5276. NULL, pubSz), 0);
  5277. /* Bad length. */
  5278. sharedSz = 1;
  5279. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5280. pub, pubSz), 0);
  5281. sharedSz = CURVE448_KEY_SIZE;
  5282. privSz = 1;
  5283. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5284. pub, pubSz), 0);
  5285. privSz = CURVE448_KEY_SIZE;
  5286. pubSz = 1;
  5287. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5288. pub, pubSz), 0);
  5289. pubSz = CURVE448_KEY_SIZE;
  5290. /* Good case of shared key. */
  5291. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5292. pub2, pub2Sz), 1);
  5293. ExpectIntEQ(wolfSSL_EC448_shared_key(shared2, &shared2Sz, priv2, priv2Sz,
  5294. pub, pubSz), 1);
  5295. ExpectIntEQ(sharedSz, CURVE448_KEY_SIZE);
  5296. ExpectIntEQ(shared2Sz, CURVE448_KEY_SIZE);
  5297. ExpectIntEQ(XMEMCMP(shared, shared2, sharedSz), 0);
  5298. #endif /* HAVE_CURVE448 && WOLFSSL_KEY_GEN */
  5299. return EXPECT_RESULT();
  5300. }
  5301. static int test_ED448(void)
  5302. {
  5303. EXPECT_DECLS;
  5304. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT) && \
  5305. defined(WOLFSSL_KEY_GEN)
  5306. byte priv[ED448_PRV_KEY_SIZE];
  5307. unsigned int privSz = (unsigned int)sizeof(priv);
  5308. byte pub[ED448_PUB_KEY_SIZE];
  5309. unsigned int pubSz = (unsigned int)sizeof(pub);
  5310. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_IMPORT)
  5311. const char* msg = TEST_STRING;
  5312. unsigned int msglen = (unsigned int)TEST_STRING_SZ;
  5313. byte sig[ED448_SIG_SIZE];
  5314. unsigned int sigSz = (unsigned int)sizeof(sig);
  5315. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_IMPORT */
  5316. /* Bad parameter testing of key generation. */
  5317. ExpectIntEQ(wolfSSL_ED448_generate_key(NULL, NULL, NULL, NULL), 0);
  5318. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, NULL, NULL, NULL), 0);
  5319. ExpectIntEQ(wolfSSL_ED448_generate_key(NULL, &privSz, NULL, NULL), 0);
  5320. ExpectIntEQ(wolfSSL_ED448_generate_key(NULL, NULL, pub, NULL), 0);
  5321. ExpectIntEQ(wolfSSL_ED448_generate_key(NULL, NULL, NULL, &pubSz), 0);
  5322. ExpectIntEQ(wolfSSL_ED448_generate_key(NULL, &privSz, pub, &pubSz), 0);
  5323. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, NULL, pub, &pubSz), 0);
  5324. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, &privSz, NULL, &pubSz), 0);
  5325. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, &privSz, pub, NULL), 0);
  5326. /* Bad length. */
  5327. privSz = 1;
  5328. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, &privSz, pub, &pubSz), 0);
  5329. privSz = ED448_PRV_KEY_SIZE;
  5330. pubSz = 1;
  5331. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, &privSz, pub, &pubSz), 0);
  5332. pubSz = ED448_PUB_KEY_SIZE;
  5333. /* Good case of generating key. */
  5334. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, &privSz, pub, &pubSz), 1);
  5335. ExpectIntEQ(privSz, ED448_PRV_KEY_SIZE);
  5336. ExpectIntEQ(pubSz, ED448_PUB_KEY_SIZE);
  5337. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_IMPORT)
  5338. /* Bad parameter testing of signing. */
  5339. ExpectIntEQ(wolfSSL_ED448_sign( NULL, msglen, NULL, privSz, NULL,
  5340. NULL), 0);
  5341. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, NULL, privSz, NULL,
  5342. NULL), 0);
  5343. ExpectIntEQ(wolfSSL_ED448_sign( NULL, msglen, priv, privSz, NULL,
  5344. NULL), 0);
  5345. ExpectIntEQ(wolfSSL_ED448_sign( NULL, msglen, NULL, privSz, sig,
  5346. NULL), 0);
  5347. ExpectIntEQ(wolfSSL_ED448_sign( NULL, msglen, NULL, privSz, NULL,
  5348. &sigSz), 0);
  5349. ExpectIntEQ(wolfSSL_ED448_sign( NULL, msglen, priv, privSz, sig,
  5350. &sigSz), 0);
  5351. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, NULL, privSz, sig,
  5352. &sigSz), 0);
  5353. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, priv, privSz, NULL,
  5354. &sigSz), 0);
  5355. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, priv, privSz, sig,
  5356. NULL), 0);
  5357. /* Bad length. */
  5358. privSz = 1;
  5359. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, priv, privSz, sig,
  5360. &sigSz), 0);
  5361. privSz = ED448_PRV_KEY_SIZE;
  5362. sigSz = 1;
  5363. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, priv, privSz, sig,
  5364. &sigSz), 0);
  5365. sigSz = ED448_SIG_SIZE;
  5366. /* Good case of signing. */
  5367. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, priv, privSz, sig,
  5368. &sigSz), 1);
  5369. ExpectIntEQ(sigSz, ED448_SIG_SIZE);
  5370. #ifdef HAVE_ED448_VERIFY
  5371. /* Bad parameter testing of verification. */
  5372. ExpectIntEQ(wolfSSL_ED448_verify( NULL, msglen, NULL, pubSz, NULL,
  5373. sigSz), 0);
  5374. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, NULL, pubSz, NULL,
  5375. sigSz), 0);
  5376. ExpectIntEQ(wolfSSL_ED448_verify( NULL, msglen, pub, pubSz, NULL,
  5377. sigSz), 0);
  5378. ExpectIntEQ(wolfSSL_ED448_verify( NULL, msglen, NULL, pubSz, sig,
  5379. sigSz), 0);
  5380. ExpectIntEQ(wolfSSL_ED448_verify( NULL, msglen, pub, pubSz, sig,
  5381. sigSz), 0);
  5382. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, NULL, pubSz, sig,
  5383. sigSz), 0);
  5384. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, pub, pubSz, NULL,
  5385. sigSz), 0);
  5386. /* Bad length. */
  5387. pubSz = 1;
  5388. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, pub, pubSz, sig,
  5389. sigSz), 0);
  5390. pubSz = ED448_PUB_KEY_SIZE;
  5391. sigSz = 1;
  5392. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, pub, pubSz, sig,
  5393. sigSz), 0);
  5394. sigSz = ED448_SIG_SIZE;
  5395. /* Good case of verification. */
  5396. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, pub, pubSz, sig,
  5397. sigSz), 1);
  5398. /* Bad signature. */
  5399. if (EXPECT_SUCCESS()) {
  5400. sig[1] ^= 0x80;
  5401. }
  5402. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, pub, pubSz, sig,
  5403. sigSz), 0);
  5404. #endif /* HAVE_ED448_VERIFY */
  5405. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_IMPORT */
  5406. #endif /* HAVE_ED448 && HAVE_ED448_KEY_EXPORT && WOLFSSL_KEY_GEN */
  5407. return EXPECT_RESULT();
  5408. }
  5409. #endif /* OPENSSL_EXTRA */
  5410. #include <wolfssl/openssl/pem.h>
  5411. /*----------------------------------------------------------------------------*
  5412. | EVP
  5413. *----------------------------------------------------------------------------*/
  5414. static int test_wolfSSL_EVP_PKEY_print_public(void)
  5415. {
  5416. EXPECT_DECLS;
  5417. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  5418. WOLFSSL_BIO* rbio = NULL;
  5419. WOLFSSL_BIO* wbio = NULL;
  5420. WOLFSSL_EVP_PKEY* pkey = NULL;
  5421. char line[256] = { 0 };
  5422. char line1[256] = { 0 };
  5423. int i = 0;
  5424. /* test error cases */
  5425. ExpectIntEQ( EVP_PKEY_print_public(NULL,NULL,0,NULL),0L);
  5426. /*
  5427. * test RSA public key print
  5428. * in this test, pass '3' for indent
  5429. */
  5430. #if !defined(NO_RSA) && defined(USE_CERT_BUFFERS_1024)
  5431. ExpectNotNull(rbio = BIO_new_mem_buf( client_keypub_der_1024,
  5432. sizeof_client_keypub_der_1024));
  5433. ExpectNotNull(wolfSSL_d2i_PUBKEY_bio(rbio, &pkey));
  5434. ExpectNotNull(wbio = BIO_new(BIO_s_mem()));
  5435. ExpectIntEQ(EVP_PKEY_print_public(wbio, pkey,3,NULL),1);
  5436. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5437. strcpy(line1, " RSA Public-Key: (1024 bit)\n");
  5438. ExpectIntEQ(XSTRNCMP(line, line1, XSTRLEN(line1)), 0);
  5439. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5440. strcpy(line1, " Modulus:\n");
  5441. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5442. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5443. strcpy(line1, " 00:bc:73:0e:a8:49:f3:74:a2:a9:ef:18:a5:da:55:\n");
  5444. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5445. /* skip to the end of modulus element*/
  5446. for (i = 0; i < 8 ;i++) {
  5447. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5448. }
  5449. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5450. strcpy(line1, " Exponent: 65537 (0x010001)\n");
  5451. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5452. /* should reach EOF */
  5453. ExpectIntLE(BIO_gets(wbio, line, sizeof(line)), 0);
  5454. EVP_PKEY_free(pkey);
  5455. pkey = NULL;
  5456. BIO_free(rbio);
  5457. BIO_free(wbio);
  5458. rbio = NULL;
  5459. wbio = NULL;
  5460. #endif /* !NO_RSA && USE_CERT_BUFFERS_1024*/
  5461. /*
  5462. * test DSA public key print
  5463. */
  5464. #if !defined(NO_DSA) && defined(USE_CERT_BUFFERS_2048)
  5465. ExpectNotNull(rbio = BIO_new_mem_buf( dsa_pub_key_der_2048,
  5466. sizeof_dsa_pub_key_der_2048));
  5467. ExpectNotNull(wolfSSL_d2i_PUBKEY_bio(rbio, &pkey));
  5468. ExpectNotNull(wbio = BIO_new(BIO_s_mem()));
  5469. ExpectIntEQ(EVP_PKEY_print_public(wbio, pkey,0,NULL),1);
  5470. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5471. strcpy(line1, "DSA Public-Key: (2048 bit)\n");
  5472. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5473. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5474. strcpy(line1, "pub:\n");
  5475. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5476. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5477. strcpy(line1,
  5478. " 00:C2:35:2D:EC:83:83:6C:73:13:9E:52:7C:74:C8:\n");
  5479. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5480. /* skip to the end of pub element*/
  5481. for (i = 0; i < 17 ;i++) {
  5482. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5483. }
  5484. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5485. strcpy(line1, "P:\n");
  5486. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5487. /* skip to the end of P element*/
  5488. for (i = 0; i < 18 ;i++) {
  5489. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5490. }
  5491. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5492. strcpy(line1, "Q:\n");
  5493. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5494. /* skip to the end of Q element*/
  5495. for (i = 0; i < 3 ;i++) {
  5496. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5497. }
  5498. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5499. strcpy(line1, "G:\n");
  5500. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5501. /* skip to the end of G element*/
  5502. for (i = 0; i < 18 ;i++) {
  5503. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5504. }
  5505. /* should reach EOF */
  5506. ExpectIntLE(BIO_gets(wbio, line, sizeof(line)), 0);
  5507. EVP_PKEY_free(pkey);
  5508. pkey = NULL;
  5509. BIO_free(rbio);
  5510. BIO_free(wbio);
  5511. rbio = NULL;
  5512. wbio = NULL;
  5513. #endif /* !NO_DSA && USE_CERT_BUFFERS_2048 */
  5514. /*
  5515. * test ECC public key print
  5516. */
  5517. #if defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  5518. ExpectNotNull(rbio = BIO_new_mem_buf( ecc_clikeypub_der_256,
  5519. sizeof_ecc_clikeypub_der_256));
  5520. ExpectNotNull(wolfSSL_d2i_PUBKEY_bio(rbio, &pkey));
  5521. ExpectNotNull(wbio = BIO_new(BIO_s_mem()));
  5522. ExpectIntEQ(EVP_PKEY_print_public(wbio, pkey,0,NULL),1);
  5523. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5524. strcpy(line1, "Public-Key: (256 bit)\n");
  5525. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5526. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5527. strcpy(line1, "pub:\n");
  5528. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5529. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5530. strcpy(line1,
  5531. " 04:55:BF:F4:0F:44:50:9A:3D:CE:9B:B7:F0:C5:4D:\n");
  5532. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5533. /* skip to the end of pub element*/
  5534. for (i = 0; i < 4 ;i++) {
  5535. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5536. }
  5537. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5538. strcpy(line1, "ASN1 OID: prime256v1\n");
  5539. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5540. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5541. strcpy(line1, "NIST CURVE: P-256\n");
  5542. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5543. /* should reach EOF */
  5544. ExpectIntLE(BIO_gets(wbio, line, sizeof(line)), 0);
  5545. EVP_PKEY_free(pkey);
  5546. pkey = NULL;
  5547. BIO_free(rbio);
  5548. BIO_free(wbio);
  5549. rbio = NULL;
  5550. wbio = NULL;
  5551. #endif /* HAVE_ECC && USE_CERT_BUFFERS_256 */
  5552. /*
  5553. * test DH public key print
  5554. */
  5555. #if defined(WOLFSSL_DH_EXTRA) && defined(USE_CERT_BUFFERS_2048)
  5556. ExpectNotNull(rbio = BIO_new_mem_buf( dh_pub_key_der_2048,
  5557. sizeof_dh_pub_key_der_2048));
  5558. ExpectNotNull(wolfSSL_d2i_PUBKEY_bio(rbio, &pkey));
  5559. ExpectNotNull(wbio = BIO_new(BIO_s_mem()));
  5560. ExpectIntEQ(EVP_PKEY_print_public(wbio, pkey,0,NULL), 1);
  5561. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5562. strcpy(line1, "DH Public-Key: (2048 bit)\n");
  5563. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5564. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5565. strcpy(line1, "public-key:\n");
  5566. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5567. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5568. strcpy(line1,
  5569. " 34:41:BF:E9:F2:11:BF:05:DB:B2:72:A8:29:CC:BD:\n");
  5570. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5571. /* skip to the end of public-key element*/
  5572. for (i = 0; i < 17 ;i++) {
  5573. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5574. }
  5575. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5576. strcpy(line1, "prime:\n");
  5577. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5578. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5579. strcpy(line1,
  5580. " 00:D3:B2:99:84:5C:0A:4C:E7:37:CC:FC:18:37:01:\n");
  5581. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5582. /* skip to the end of prime element*/
  5583. for (i = 0; i < 17 ;i++) {
  5584. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5585. }
  5586. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5587. strcpy(line1, "generator: 2 (0x02)\n");
  5588. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5589. /* should reach EOF */
  5590. ExpectIntLE(BIO_gets(wbio, line, sizeof(line)), 0);
  5591. EVP_PKEY_free(pkey);
  5592. pkey = NULL;
  5593. BIO_free(rbio);
  5594. BIO_free(wbio);
  5595. rbio = NULL;
  5596. wbio = NULL;
  5597. #endif /* WOLFSSL_DH_EXTRA && USE_CERT_BUFFERS_2048 */
  5598. /* to prevent "unused variable" warning */
  5599. (void)pkey;
  5600. (void)wbio;
  5601. (void)rbio;
  5602. (void)line;
  5603. (void)line1;
  5604. (void)i;
  5605. #endif /* OPENSSL_EXTRA */
  5606. return EXPECT_RESULT();
  5607. }
  5608. /* Test functions for base64 encode/decode */
  5609. static int test_wolfSSL_EVP_ENCODE_CTX_new(void)
  5610. {
  5611. EXPECT_DECLS;
  5612. #if defined(OPENSSL_EXTRA) && \
  5613. ( defined(WOLFSSL_BASE64_ENCODE) || defined(WOLFSSL_BASE64_DECODE))
  5614. EVP_ENCODE_CTX* ctx = NULL;
  5615. ExpectNotNull(ctx = EVP_ENCODE_CTX_new());
  5616. ExpectIntEQ(ctx->remaining,0);
  5617. ExpectIntEQ(ctx->data[0],0);
  5618. ExpectIntEQ(ctx->data[sizeof(ctx->data) -1],0);
  5619. EVP_ENCODE_CTX_free(ctx);
  5620. #endif /* OPENSSL_EXTRA && (WOLFSSL_BASE64_ENCODE || WOLFSSL_BASE64_DECODE) */
  5621. return EXPECT_RESULT();
  5622. }
  5623. static int test_wolfSSL_EVP_ENCODE_CTX_free(void)
  5624. {
  5625. EXPECT_DECLS;
  5626. #if defined(OPENSSL_EXTRA) && \
  5627. ( defined(WOLFSSL_BASE64_ENCODE) || defined(WOLFSSL_BASE64_DECODE))
  5628. EVP_ENCODE_CTX* ctx = NULL;
  5629. ExpectNotNull(ctx = EVP_ENCODE_CTX_new());
  5630. EVP_ENCODE_CTX_free(ctx);
  5631. #endif /* OPENSSL_EXTRA && (WOLFSSL_BASE64_ENCODE || WOLFSSL_BASE64_DECODE) */
  5632. return EXPECT_RESULT();
  5633. }
  5634. static int test_wolfSSL_EVP_EncodeInit(void)
  5635. {
  5636. EXPECT_DECLS;
  5637. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_ENCODE)
  5638. EVP_ENCODE_CTX* ctx = NULL;
  5639. ExpectNotNull(ctx = EVP_ENCODE_CTX_new());
  5640. ExpectIntEQ(ctx->remaining, 0);
  5641. ExpectIntEQ(ctx->data[0], 0);
  5642. ExpectIntEQ(ctx->data[sizeof(ctx->data) -1], 0);
  5643. if (ctx != NULL) {
  5644. /* make ctx dirty */
  5645. ctx->remaining = 10;
  5646. XMEMSET(ctx->data, 0x77, sizeof(ctx->data));
  5647. }
  5648. EVP_EncodeInit(ctx);
  5649. ExpectIntEQ(ctx->remaining, 0);
  5650. ExpectIntEQ(ctx->data[0], 0);
  5651. ExpectIntEQ(ctx->data[sizeof(ctx->data) -1], 0);
  5652. EVP_ENCODE_CTX_free(ctx);
  5653. #endif /* OPENSSL_EXTRA && WOLFSSL_BASE64_ENCODE*/
  5654. return EXPECT_RESULT();
  5655. }
  5656. static int test_wolfSSL_EVP_EncodeUpdate(void)
  5657. {
  5658. EXPECT_DECLS;
  5659. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_ENCODE)
  5660. int outl;
  5661. int total;
  5662. const unsigned char plain0[] = {"Th"};
  5663. const unsigned char plain1[] = {"This is a base64 encodeing test."};
  5664. const unsigned char plain2[] = {"This is additional data."};
  5665. const unsigned char encBlock0[] = {"VGg="};
  5666. const unsigned char enc0[] = {"VGg=\n"};
  5667. /* expected encoded result for the first output 64 chars plus trailing LF*/
  5668. const unsigned char enc1[] = {"VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVpbmcgdGVzdC5UaGlzIGlzIGFkZGl0aW9u\n"};
  5669. const unsigned char enc2[] =
  5670. {"VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVpbmcgdGVzdC5UaGlzIGlzIGFkZGl0aW9u\nYWwgZGF0YS4=\n"};
  5671. unsigned char encOutBuff[300];
  5672. EVP_ENCODE_CTX* ctx = NULL;
  5673. ExpectNotNull(ctx = EVP_ENCODE_CTX_new());
  5674. EVP_EncodeInit(ctx);
  5675. /* illegal parameter test */
  5676. ExpectIntEQ(
  5677. EVP_EncodeUpdate(
  5678. NULL, /* pass NULL as ctx */
  5679. encOutBuff,
  5680. &outl,
  5681. plain1,
  5682. sizeof(plain1)-1),
  5683. 0 /* expected result code 0: fail */
  5684. );
  5685. ExpectIntEQ(
  5686. EVP_EncodeUpdate(
  5687. ctx,
  5688. NULL, /* pass NULL as out buff */
  5689. &outl,
  5690. plain1,
  5691. sizeof(plain1)-1),
  5692. 0 /* expected result code 0: fail */
  5693. );
  5694. ExpectIntEQ(
  5695. EVP_EncodeUpdate(
  5696. ctx,
  5697. encOutBuff,
  5698. NULL, /* pass NULL as outl */
  5699. plain1,
  5700. sizeof(plain1)-1),
  5701. 0 /* expected result code 0: fail */
  5702. );
  5703. ExpectIntEQ(
  5704. EVP_EncodeUpdate(
  5705. ctx,
  5706. encOutBuff,
  5707. &outl,
  5708. NULL, /* pass NULL as in */
  5709. sizeof(plain1)-1),
  5710. 0 /* expected result code 0: fail */
  5711. );
  5712. ExpectIntEQ(EVP_EncodeBlock(NULL, NULL, 0), -1);
  5713. /* meaningless parameter test */
  5714. ExpectIntEQ(
  5715. EVP_EncodeUpdate(
  5716. ctx,
  5717. encOutBuff,
  5718. &outl,
  5719. plain1,
  5720. 0), /* pass zero input */
  5721. 1 /* expected result code 1: success */
  5722. );
  5723. /* very small data encoding test */
  5724. EVP_EncodeInit(ctx);
  5725. ExpectIntEQ(
  5726. EVP_EncodeUpdate(
  5727. ctx,
  5728. encOutBuff,
  5729. &outl,
  5730. plain0,
  5731. sizeof(plain0)-1),
  5732. 1 /* expected result code 1: success */
  5733. );
  5734. ExpectIntEQ(outl,0);
  5735. if (EXPECT_SUCCESS()) {
  5736. EVP_EncodeFinal(
  5737. ctx,
  5738. encOutBuff + outl,
  5739. &outl);
  5740. }
  5741. ExpectIntEQ( outl, sizeof(enc0)-1);
  5742. ExpectIntEQ(
  5743. XSTRNCMP(
  5744. (const char*)encOutBuff,
  5745. (const char*)enc0,sizeof(enc0) ),
  5746. 0);
  5747. XMEMSET( encOutBuff,0, sizeof(encOutBuff));
  5748. ExpectIntEQ(EVP_EncodeBlock(encOutBuff, plain0, sizeof(plain0)-1),
  5749. sizeof(encBlock0)-1);
  5750. ExpectStrEQ(encOutBuff, encBlock0);
  5751. /* pass small size( < 48bytes ) input, then make sure they are not
  5752. * encoded and just stored in ctx
  5753. */
  5754. EVP_EncodeInit(ctx);
  5755. total = 0;
  5756. outl = 0;
  5757. XMEMSET( encOutBuff,0, sizeof(encOutBuff));
  5758. ExpectIntEQ(
  5759. EVP_EncodeUpdate(
  5760. ctx,
  5761. encOutBuff, /* buffer for output */
  5762. &outl, /* size of output */
  5763. plain1, /* input */
  5764. sizeof(plain1)-1), /* size of input */
  5765. 1); /* expected result code 1:success */
  5766. total += outl;
  5767. ExpectIntEQ(outl, 0); /* no output expected */
  5768. ExpectIntEQ(ctx->remaining, sizeof(plain1) -1);
  5769. ExpectTrue(
  5770. XSTRNCMP((const char*)(ctx->data),
  5771. (const char*)plain1,
  5772. ctx->remaining) ==0 );
  5773. ExpectTrue(encOutBuff[0] == 0);
  5774. /* call wolfSSL_EVP_EncodeUpdate again to make it encode
  5775. * the stored data and the new input together
  5776. */
  5777. ExpectIntEQ(
  5778. EVP_EncodeUpdate(
  5779. ctx,
  5780. encOutBuff + outl, /* buffer for output */
  5781. &outl, /* size of output */
  5782. plain2, /* additional input */
  5783. sizeof(plain2) -1), /* size of additional input */
  5784. 1); /* expected result code 1:success */
  5785. total += outl;
  5786. ExpectIntNE(outl, 0); /* some output is expected this time*/
  5787. ExpectIntEQ(outl, BASE64_ENCODE_RESULT_BLOCK_SIZE +1); /* 64 bytes and LF */
  5788. ExpectIntEQ(
  5789. XSTRNCMP((const char*)encOutBuff,(const char*)enc1,sizeof(enc1) ),0);
  5790. /* call wolfSSL_EVP_EncodeFinal to flush all the unprocessed input */
  5791. EVP_EncodeFinal(
  5792. ctx,
  5793. encOutBuff + outl,
  5794. &outl);
  5795. total += outl;
  5796. ExpectIntNE(total,0);
  5797. ExpectIntNE(outl,0);
  5798. ExpectIntEQ(XSTRNCMP(
  5799. (const char*)encOutBuff,(const char*)enc2,sizeof(enc2) ),0);
  5800. /* test with illeagal parameters */
  5801. outl = 1;
  5802. EVP_EncodeFinal(NULL, encOutBuff + outl, &outl);
  5803. ExpectIntEQ(outl, 0);
  5804. outl = 1;
  5805. EVP_EncodeFinal(ctx, NULL, &outl);
  5806. ExpectIntEQ(outl, 0);
  5807. EVP_EncodeFinal(ctx, encOutBuff + outl, NULL);
  5808. EVP_EncodeFinal(NULL, NULL, NULL);
  5809. EVP_ENCODE_CTX_free(ctx);
  5810. #endif /* OPENSSL_EXTRA && WOLFSSL_BASE64_ENCODE*/
  5811. return EXPECT_RESULT();
  5812. }
  5813. static int test_wolfSSL_EVP_EncodeFinal(void)
  5814. {
  5815. int res = TEST_SKIPPED;
  5816. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_ENCODE)
  5817. /* tests for wolfSSL_EVP_EncodeFinal are included in
  5818. * test_wolfSSL_EVP_EncodeUpdate
  5819. */
  5820. res = TEST_SUCCESS;
  5821. #endif /* OPENSSL_EXTRA && WOLFSSL_BASE64_ENCODE*/
  5822. return res;
  5823. }
  5824. static int test_wolfSSL_EVP_DecodeInit(void)
  5825. {
  5826. EXPECT_DECLS;
  5827. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_DECODE)
  5828. EVP_ENCODE_CTX* ctx = NULL;
  5829. ExpectNotNull( ctx = EVP_ENCODE_CTX_new());
  5830. ExpectIntEQ( ctx->remaining,0);
  5831. ExpectIntEQ( ctx->data[0],0);
  5832. ExpectIntEQ( ctx->data[sizeof(ctx->data) -1],0);
  5833. if (ctx != NULL) {
  5834. /* make ctx dirty */
  5835. ctx->remaining = 10;
  5836. XMEMSET( ctx->data, 0x77, sizeof(ctx->data));
  5837. }
  5838. EVP_DecodeInit(ctx);
  5839. ExpectIntEQ( ctx->remaining,0);
  5840. ExpectIntEQ( ctx->data[0],0);
  5841. ExpectIntEQ( ctx->data[sizeof(ctx->data) -1],0);
  5842. EVP_ENCODE_CTX_free(ctx);
  5843. #endif /* OPENSSL && WOLFSSL_BASE_DECODE */
  5844. return EXPECT_RESULT();
  5845. }
  5846. static int test_wolfSSL_EVP_DecodeUpdate(void)
  5847. {
  5848. EXPECT_DECLS;
  5849. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_DECODE)
  5850. int outl;
  5851. unsigned char decOutBuff[300];
  5852. EVP_ENCODE_CTX* ctx = NULL;
  5853. static const unsigned char enc1[] =
  5854. {"VGhpcyBpcyBhIGJhc2U2NCBkZWNvZGluZyB0ZXN0Lg==\n"};
  5855. /* const unsigned char plain1[] =
  5856. {"This is a base64 decoding test."} */
  5857. ExpectNotNull(ctx = EVP_ENCODE_CTX_new());
  5858. EVP_DecodeInit(ctx);
  5859. /* illegal parameter tests */
  5860. /* pass NULL as ctx */
  5861. ExpectIntEQ(
  5862. EVP_DecodeUpdate(
  5863. NULL, /* pass NULL as ctx */
  5864. decOutBuff,
  5865. &outl,
  5866. enc1,
  5867. sizeof(enc1)-1),
  5868. -1 /* expected result code -1: fail */
  5869. );
  5870. ExpectIntEQ( outl, 0);
  5871. /* pass NULL as output */
  5872. ExpectIntEQ(
  5873. EVP_DecodeUpdate(
  5874. ctx,
  5875. NULL, /* pass NULL as out buff */
  5876. &outl,
  5877. enc1,
  5878. sizeof(enc1)-1),
  5879. -1 /* expected result code -1: fail */
  5880. );
  5881. ExpectIntEQ( outl, 0);
  5882. /* pass NULL as outl */
  5883. ExpectIntEQ(
  5884. EVP_DecodeUpdate(
  5885. ctx,
  5886. decOutBuff,
  5887. NULL, /* pass NULL as outl */
  5888. enc1,
  5889. sizeof(enc1)-1),
  5890. -1 /* expected result code -1: fail */
  5891. );
  5892. /* pass NULL as input */
  5893. ExpectIntEQ(
  5894. EVP_DecodeUpdate(
  5895. ctx,
  5896. decOutBuff,
  5897. &outl,
  5898. NULL, /* pass NULL as in */
  5899. sizeof(enc1)-1),
  5900. -1 /* expected result code -1: fail */
  5901. );
  5902. ExpectIntEQ( outl, 0);
  5903. ExpectIntEQ(EVP_DecodeBlock(NULL, NULL, 0), -1);
  5904. /* pass zero length input */
  5905. ExpectIntEQ(
  5906. EVP_DecodeUpdate(
  5907. ctx,
  5908. decOutBuff,
  5909. &outl,
  5910. enc1,
  5911. 0), /* pass zero as input len */
  5912. 1 /* expected result code 1: success */
  5913. );
  5914. /* decode correct base64 string */
  5915. {
  5916. static const unsigned char enc2[] =
  5917. {"VGhpcyBpcyBhIGJhc2U2NCBkZWNvZGluZyB0ZXN0Lg==\n"};
  5918. static const unsigned char plain2[] =
  5919. {"This is a base64 decoding test."};
  5920. EVP_EncodeInit(ctx);
  5921. ExpectIntEQ(
  5922. EVP_DecodeUpdate(
  5923. ctx,
  5924. decOutBuff,
  5925. &outl,
  5926. enc2,
  5927. sizeof(enc2)-1),
  5928. 0 /* expected result code 0: success */
  5929. );
  5930. ExpectIntEQ(outl,sizeof(plain2) -1);
  5931. ExpectIntEQ(
  5932. EVP_DecodeFinal(
  5933. ctx,
  5934. decOutBuff + outl,
  5935. &outl),
  5936. 1 /* expected result code 1: success */
  5937. );
  5938. ExpectIntEQ(outl, 0); /* expected DecodeFinal output no data */
  5939. ExpectIntEQ(XSTRNCMP( (const char*)plain2,(const char*)decOutBuff,
  5940. sizeof(plain2) -1 ),0);
  5941. ExpectIntEQ(EVP_DecodeBlock(decOutBuff, enc2, sizeof(enc2)),
  5942. sizeof(plain2)-1);
  5943. ExpectIntEQ(XSTRNCMP( (const char*)plain2,(const char*)decOutBuff,
  5944. sizeof(plain2) -1 ),0);
  5945. }
  5946. /* decode correct base64 string which does not have '\n' in its last*/
  5947. {
  5948. static const unsigned char enc3[] =
  5949. {"VGhpcyBpcyBhIGJhc2U2NCBkZWNvZGluZyB0ZXN0Lg=="}; /* 44 chars */
  5950. static const unsigned char plain3[] =
  5951. {"This is a base64 decoding test."}; /* 31 chars */
  5952. EVP_EncodeInit(ctx);
  5953. ExpectIntEQ(
  5954. EVP_DecodeUpdate(
  5955. ctx,
  5956. decOutBuff,
  5957. &outl,
  5958. enc3,
  5959. sizeof(enc3)-1),
  5960. 0 /* expected result code 0: success */
  5961. );
  5962. ExpectIntEQ(outl,sizeof(plain3)-1); /* 31 chars should be output */
  5963. ExpectIntEQ(XSTRNCMP( (const char*)plain3,(const char*)decOutBuff,
  5964. sizeof(plain3) -1 ),0);
  5965. ExpectIntEQ(
  5966. EVP_DecodeFinal(
  5967. ctx,
  5968. decOutBuff + outl,
  5969. &outl),
  5970. 1 /* expected result code 1: success */
  5971. );
  5972. ExpectIntEQ(outl,0 );
  5973. ExpectIntEQ(EVP_DecodeBlock(decOutBuff, enc3, sizeof(enc3)-1),
  5974. sizeof(plain3)-1);
  5975. ExpectIntEQ(XSTRNCMP( (const char*)plain3,(const char*)decOutBuff,
  5976. sizeof(plain3) -1 ),0);
  5977. }
  5978. /* decode string which has a padding char ('=') in the illegal position*/
  5979. {
  5980. static const unsigned char enc4[] =
  5981. {"VGhpcyBpcyBhIGJhc2U2N=CBkZWNvZGluZyB0ZXN0Lg==\n"};
  5982. EVP_EncodeInit(ctx);
  5983. ExpectIntEQ(
  5984. EVP_DecodeUpdate(
  5985. ctx,
  5986. decOutBuff,
  5987. &outl,
  5988. enc4,
  5989. sizeof(enc4)-1),
  5990. -1 /* expected result code -1: error */
  5991. );
  5992. ExpectIntEQ(outl,0);
  5993. ExpectIntEQ(EVP_DecodeBlock(decOutBuff, enc4, sizeof(enc4)-1), -1);
  5994. }
  5995. /* small data decode test */
  5996. {
  5997. static const unsigned char enc00[] = {"VG"};
  5998. static const unsigned char enc01[] = {"g=\n"};
  5999. static const unsigned char plain4[] = {"Th"};
  6000. EVP_EncodeInit(ctx);
  6001. ExpectIntEQ(
  6002. EVP_DecodeUpdate(
  6003. ctx,
  6004. decOutBuff,
  6005. &outl,
  6006. enc00,
  6007. sizeof(enc00)-1),
  6008. 1 /* expected result code 1: success */
  6009. );
  6010. ExpectIntEQ(outl,0);
  6011. ExpectIntEQ(
  6012. EVP_DecodeUpdate(
  6013. ctx,
  6014. decOutBuff + outl,
  6015. &outl,
  6016. enc01,
  6017. sizeof(enc01)-1),
  6018. 0 /* expected result code 0: success */
  6019. );
  6020. ExpectIntEQ(outl,sizeof(plain4)-1);
  6021. /* test with illegal parameters */
  6022. ExpectIntEQ(EVP_DecodeFinal(NULL,decOutBuff + outl,&outl), -1);
  6023. ExpectIntEQ(EVP_DecodeFinal(ctx,NULL,&outl), -1);
  6024. ExpectIntEQ(EVP_DecodeFinal(ctx,decOutBuff + outl, NULL), -1);
  6025. ExpectIntEQ(EVP_DecodeFinal(NULL,NULL, NULL), -1);
  6026. if (EXPECT_SUCCESS()) {
  6027. EVP_DecodeFinal(
  6028. ctx,
  6029. decOutBuff + outl,
  6030. &outl);
  6031. }
  6032. ExpectIntEQ( outl, 0);
  6033. ExpectIntEQ(
  6034. XSTRNCMP(
  6035. (const char*)decOutBuff,
  6036. (const char*)plain4,sizeof(plain4)-1 ),
  6037. 0);
  6038. }
  6039. EVP_ENCODE_CTX_free(ctx);
  6040. #endif /* OPENSSL && WOLFSSL_BASE_DECODE */
  6041. return EXPECT_RESULT();
  6042. }
  6043. static int test_wolfSSL_EVP_DecodeFinal(void)
  6044. {
  6045. int res = TEST_SKIPPED;
  6046. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_DECODE)
  6047. /* tests for wolfSSL_EVP_DecodeFinal are included in
  6048. * test_wolfSSL_EVP_DecodeUpdate
  6049. */
  6050. res = TEST_SUCCESS;
  6051. #endif /* OPENSSL && WOLFSSL_BASE_DECODE */
  6052. return res;
  6053. }
  6054. /* Test function for wolfSSL_EVP_get_cipherbynid.
  6055. */
  6056. #ifdef OPENSSL_EXTRA
  6057. static int test_wolfSSL_EVP_get_cipherbynid(void)
  6058. {
  6059. EXPECT_DECLS;
  6060. #ifndef NO_AES
  6061. const WOLFSSL_EVP_CIPHER* c;
  6062. c = wolfSSL_EVP_get_cipherbynid(419);
  6063. #if (defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT)) && \
  6064. defined(WOLFSSL_AES_128)
  6065. ExpectNotNull(c);
  6066. ExpectNotNull(XSTRCMP("EVP_AES_128_CBC", c));
  6067. #else
  6068. ExpectNull(c);
  6069. #endif
  6070. c = wolfSSL_EVP_get_cipherbynid(423);
  6071. #if (defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT)) && \
  6072. defined(WOLFSSL_AES_192)
  6073. ExpectNotNull(c);
  6074. ExpectNotNull(XSTRCMP("EVP_AES_192_CBC", c));
  6075. #else
  6076. ExpectNull(c);
  6077. #endif
  6078. c = wolfSSL_EVP_get_cipherbynid(427);
  6079. #if (defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT)) && \
  6080. defined(WOLFSSL_AES_256)
  6081. ExpectNotNull(c);
  6082. ExpectNotNull(XSTRCMP("EVP_AES_256_CBC", c));
  6083. #else
  6084. ExpectNull(c);
  6085. #endif
  6086. c = wolfSSL_EVP_get_cipherbynid(904);
  6087. #if defined(WOLFSSL_AES_COUNTER) && defined(WOLFSSL_AES_128)
  6088. ExpectNotNull(c);
  6089. ExpectNotNull(XSTRCMP("EVP_AES_128_CTR", c));
  6090. #else
  6091. ExpectNull(c);
  6092. #endif
  6093. c = wolfSSL_EVP_get_cipherbynid(905);
  6094. #if defined(WOLFSSL_AES_COUNTER) && defined(WOLFSSL_AES_192)
  6095. ExpectNotNull(c);
  6096. ExpectNotNull(XSTRCMP("EVP_AES_192_CTR", c));
  6097. #else
  6098. ExpectNull(c);
  6099. #endif
  6100. c = wolfSSL_EVP_get_cipherbynid(906);
  6101. #if defined(WOLFSSL_AES_COUNTER) && defined(WOLFSSL_AES_256)
  6102. ExpectNotNull(c);
  6103. ExpectNotNull(XSTRCMP("EVP_AES_256_CTR", c));
  6104. #else
  6105. ExpectNull(c);
  6106. #endif
  6107. c = wolfSSL_EVP_get_cipherbynid(418);
  6108. #if defined(HAVE_AES_ECB) && defined(WOLFSSL_AES_128)
  6109. ExpectNotNull(c);
  6110. ExpectNotNull(XSTRCMP("EVP_AES_128_ECB", c));
  6111. #else
  6112. ExpectNull(c);
  6113. #endif
  6114. c = wolfSSL_EVP_get_cipherbynid(422);
  6115. #if defined(HAVE_AES_ECB) && defined(WOLFSSL_AES_192)
  6116. ExpectNotNull(c);
  6117. ExpectNotNull(XSTRCMP("EVP_AES_192_ECB", c));
  6118. #else
  6119. ExpectNull(c);
  6120. #endif
  6121. c = wolfSSL_EVP_get_cipherbynid(426);
  6122. #if defined(HAVE_AES_ECB) && defined(WOLFSSL_AES_256)
  6123. ExpectNotNull(c);
  6124. ExpectNotNull(XSTRCMP("EVP_AES_256_ECB", c));
  6125. #else
  6126. ExpectNull(c);
  6127. #endif
  6128. #endif /* !NO_AES */
  6129. #ifndef NO_DES3
  6130. ExpectNotNull(XSTRCMP("EVP_DES_CBC", wolfSSL_EVP_get_cipherbynid(31)));
  6131. #ifdef WOLFSSL_DES_ECB
  6132. ExpectNotNull(XSTRCMP("EVP_DES_ECB", wolfSSL_EVP_get_cipherbynid(29)));
  6133. #endif
  6134. ExpectNotNull(XSTRCMP("EVP_DES_EDE3_CBC", wolfSSL_EVP_get_cipherbynid(44)));
  6135. #ifdef WOLFSSL_DES_ECB
  6136. ExpectNotNull(XSTRCMP("EVP_DES_EDE3_ECB", wolfSSL_EVP_get_cipherbynid(33)));
  6137. #endif
  6138. #endif /* !NO_DES3 */
  6139. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  6140. ExpectNotNull(XSTRCMP("EVP_CHACHA20_POLY13O5", EVP_get_cipherbynid(1018)));
  6141. #endif
  6142. /* test for nid is out of range */
  6143. ExpectNull(wolfSSL_EVP_get_cipherbynid(1));
  6144. return EXPECT_RESULT();
  6145. }
  6146. static int test_wolfSSL_EVP_CIPHER_CTX(void)
  6147. {
  6148. EXPECT_DECLS;
  6149. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  6150. EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
  6151. const EVP_CIPHER *init = EVP_aes_128_cbc();
  6152. const EVP_CIPHER *test;
  6153. byte key[AES_BLOCK_SIZE] = {0};
  6154. byte iv[AES_BLOCK_SIZE] = {0};
  6155. ExpectNotNull(ctx);
  6156. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  6157. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  6158. test = EVP_CIPHER_CTX_cipher(ctx);
  6159. ExpectTrue(init == test);
  6160. ExpectIntEQ(EVP_CIPHER_nid(test), NID_aes_128_cbc);
  6161. ExpectIntEQ(EVP_CIPHER_CTX_reset(ctx), WOLFSSL_SUCCESS);
  6162. ExpectIntEQ(EVP_CIPHER_CTX_reset(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  6163. EVP_CIPHER_CTX_free(ctx);
  6164. /* test EVP_CIPHER_CTX_cleanup with NULL */
  6165. ExpectIntEQ(EVP_CIPHER_CTX_cleanup(NULL), WOLFSSL_SUCCESS);
  6166. #endif /* !NO_AES && HAVE_AES_CBC && WOLFSSL_AES_128 */
  6167. return EXPECT_RESULT();
  6168. }
  6169. #endif /* OPENSSL_EXTRA */
  6170. /*----------------------------------------------------------------------------*
  6171. | IO
  6172. *----------------------------------------------------------------------------*/
  6173. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) || \
  6174. defined(HAVE_IO_TESTS_DEPENDENCIES)
  6175. #ifdef WOLFSSL_HAVE_TLS_UNIQUE
  6176. #ifdef WC_SHA512_DIGEST_SIZE
  6177. #define MD_MAX_SIZE WC_SHA512_DIGEST_SIZE
  6178. #else
  6179. #define MD_MAX_SIZE WC_SHA256_DIGEST_SIZE
  6180. #endif
  6181. byte server_side_msg1[MD_MAX_SIZE] = {0};/* msg sent by server */
  6182. byte server_side_msg2[MD_MAX_SIZE] = {0};/* msg received from client */
  6183. byte client_side_msg1[MD_MAX_SIZE] = {0};/* msg sent by client */
  6184. byte client_side_msg2[MD_MAX_SIZE] = {0};/* msg received from server */
  6185. #endif /* WOLFSSL_HAVE_TLS_UNIQUE */
  6186. /* TODO: Expand and enable this when EVP_chacha20_poly1305 is supported */
  6187. #if defined(HAVE_SESSION_TICKET) && defined(OPENSSL_EXTRA) && \
  6188. defined(HAVE_AES_CBC)
  6189. typedef struct openssl_key_ctx {
  6190. byte name[WOLFSSL_TICKET_NAME_SZ]; /* server name */
  6191. byte key[WOLFSSL_TICKET_KEY_SZ]; /* cipher key */
  6192. byte hmacKey[WOLFSSL_TICKET_NAME_SZ]; /* hmac key */
  6193. byte iv[WOLFSSL_TICKET_IV_SZ]; /* cipher iv */
  6194. } openssl_key_ctx;
  6195. static THREAD_LS_T openssl_key_ctx myOpenSSLKey_ctx;
  6196. static THREAD_LS_T WC_RNG myOpenSSLKey_rng;
  6197. static WC_INLINE int OpenSSLTicketInit(void)
  6198. {
  6199. int ret = wc_InitRng(&myOpenSSLKey_rng);
  6200. if (ret != 0) return ret;
  6201. ret = wc_RNG_GenerateBlock(&myOpenSSLKey_rng, myOpenSSLKey_ctx.name,
  6202. sizeof(myOpenSSLKey_ctx.name));
  6203. if (ret != 0) return ret;
  6204. ret = wc_RNG_GenerateBlock(&myOpenSSLKey_rng, myOpenSSLKey_ctx.key,
  6205. sizeof(myOpenSSLKey_ctx.key));
  6206. if (ret != 0) return ret;
  6207. ret = wc_RNG_GenerateBlock(&myOpenSSLKey_rng, myOpenSSLKey_ctx.hmacKey,
  6208. sizeof(myOpenSSLKey_ctx.hmacKey));
  6209. if (ret != 0) return ret;
  6210. ret = wc_RNG_GenerateBlock(&myOpenSSLKey_rng, myOpenSSLKey_ctx.iv,
  6211. sizeof(myOpenSSLKey_ctx.iv));
  6212. if (ret != 0) return ret;
  6213. return 0;
  6214. }
  6215. static int myTicketEncCbOpenSSL(WOLFSSL* ssl,
  6216. byte name[WOLFSSL_TICKET_NAME_SZ],
  6217. byte iv[WOLFSSL_TICKET_IV_SZ],
  6218. WOLFSSL_EVP_CIPHER_CTX *ectx,
  6219. WOLFSSL_HMAC_CTX *hctx, int enc) {
  6220. (void)ssl;
  6221. if (enc) {
  6222. XMEMCPY(name, myOpenSSLKey_ctx.name, sizeof(myOpenSSLKey_ctx.name));
  6223. XMEMCPY(iv, myOpenSSLKey_ctx.iv, sizeof(myOpenSSLKey_ctx.iv));
  6224. }
  6225. else if (XMEMCMP(name, myOpenSSLKey_ctx.name,
  6226. sizeof(myOpenSSLKey_ctx.name)) != 0 ||
  6227. XMEMCMP(iv, myOpenSSLKey_ctx.iv,
  6228. sizeof(myOpenSSLKey_ctx.iv)) != 0) {
  6229. return 0;
  6230. }
  6231. HMAC_Init_ex(hctx, myOpenSSLKey_ctx.hmacKey, WOLFSSL_TICKET_NAME_SZ, EVP_sha256(), NULL);
  6232. if (enc)
  6233. EVP_EncryptInit_ex(ectx, EVP_aes_256_cbc(), NULL, myOpenSSLKey_ctx.key, iv);
  6234. else
  6235. EVP_DecryptInit_ex(ectx, EVP_aes_256_cbc(), NULL, myOpenSSLKey_ctx.key, iv);
  6236. return 1;
  6237. }
  6238. static WC_INLINE void OpenSSLTicketCleanup(void)
  6239. {
  6240. wc_FreeRng(&myOpenSSLKey_rng);
  6241. }
  6242. #endif
  6243. #endif
  6244. /* helper functions */
  6245. #ifdef HAVE_SSL_MEMIO_TESTS_DEPENDENCIES
  6246. static WC_INLINE int test_ssl_memio_write_cb(WOLFSSL *ssl, char *data, int sz,
  6247. void *ctx)
  6248. {
  6249. struct test_ssl_memio_ctx *test_ctx;
  6250. byte *buf;
  6251. int *len;
  6252. test_ctx = (struct test_ssl_memio_ctx*)ctx;
  6253. if (wolfSSL_GetSide(ssl) == WOLFSSL_SERVER_END) {
  6254. buf = test_ctx->c_buff;
  6255. len = &test_ctx->c_len;
  6256. }
  6257. else {
  6258. buf = test_ctx->s_buff;
  6259. len = &test_ctx->s_len;
  6260. }
  6261. if ((unsigned)(*len + sz) > TEST_SSL_MEMIO_BUF_SZ)
  6262. return WOLFSSL_CBIO_ERR_WANT_WRITE;
  6263. XMEMCPY(buf + *len, data, sz);
  6264. *len += sz;
  6265. #ifdef WOLFSSL_DUMP_MEMIO_STREAM
  6266. {
  6267. /* This can be imported into Wireshark by transforming the file with
  6268. * od -Ax -tx1 -v test_output.dump > test_output.dump.hex
  6269. * And then loading test_output.dump.hex into Wireshark using the
  6270. * "Import from Hex Dump..." option ion and selecting the TCP
  6271. * encapsulation option. */
  6272. char dump_file_name[64];
  6273. WOLFSSL_BIO *dump_file;
  6274. sprintf(dump_file_name, "%s/%s.dump", tmpDirName, currentTestName);
  6275. dump_file = wolfSSL_BIO_new_file(dump_file_name, "a");
  6276. if (dump_file != NULL) {
  6277. (void)wolfSSL_BIO_write(dump_file, data, sz);
  6278. wolfSSL_BIO_free(dump_file);
  6279. }
  6280. }
  6281. #endif
  6282. return sz;
  6283. }
  6284. static WC_INLINE int test_ssl_memio_read_cb(WOLFSSL *ssl, char *data, int sz,
  6285. void *ctx)
  6286. {
  6287. struct test_ssl_memio_ctx *test_ctx;
  6288. int read_sz;
  6289. byte *buf;
  6290. int *len;
  6291. test_ctx = (struct test_ssl_memio_ctx*)ctx;
  6292. if (wolfSSL_GetSide(ssl) == WOLFSSL_SERVER_END) {
  6293. buf = test_ctx->s_buff;
  6294. len = &test_ctx->s_len;
  6295. }
  6296. else {
  6297. buf = test_ctx->c_buff;
  6298. len = &test_ctx->c_len;
  6299. }
  6300. if (*len == 0)
  6301. return WOLFSSL_CBIO_ERR_WANT_READ;
  6302. read_sz = sz < *len ? sz : *len;
  6303. XMEMCPY(data, buf, read_sz);
  6304. XMEMMOVE(buf, buf + read_sz, *len - read_sz);
  6305. *len -= read_sz;
  6306. return read_sz;
  6307. }
  6308. static WC_INLINE int test_ssl_memio_setup(test_ssl_memio_ctx *ctx)
  6309. {
  6310. EXPECT_DECLS_NO_MSGS(-2000);
  6311. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6312. int c_sharedCtx = 0;
  6313. int s_sharedCtx = 0;
  6314. #endif
  6315. const char* clientCertFile = cliCertFile;
  6316. const char* clientKeyFile = cliKeyFile;
  6317. const char* serverCertFile = svrCertFile;
  6318. const char* serverKeyFile = svrKeyFile;
  6319. /********************************
  6320. * Create WOLFSSL_CTX for client.
  6321. ********************************/
  6322. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6323. if (ctx->c_ctx != NULL) {
  6324. c_sharedCtx = ctx->c_cb.isSharedCtx;
  6325. }
  6326. else
  6327. #endif
  6328. {
  6329. WOLFSSL_METHOD* method = NULL;
  6330. if (ctx->c_cb.method != NULL) {
  6331. method = ctx->c_cb.method();
  6332. }
  6333. else {
  6334. method = wolfSSLv23_client_method();
  6335. }
  6336. ExpectNotNull(ctx->c_ctx = wolfSSL_CTX_new(method));
  6337. }
  6338. wolfSSL_SetIORecv(ctx->c_ctx, test_ssl_memio_read_cb);
  6339. wolfSSL_SetIOSend(ctx->c_ctx, test_ssl_memio_write_cb);
  6340. #ifdef WOLFSSL_ENCRYPTED_KEYS
  6341. wolfSSL_CTX_set_default_passwd_cb(ctx->c_ctx, PasswordCallBack);
  6342. #endif
  6343. if (ctx->c_cb.caPemFile != NULL)
  6344. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx->c_ctx,
  6345. ctx->c_cb.caPemFile, 0), WOLFSSL_SUCCESS);
  6346. else
  6347. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx->c_ctx,
  6348. caCertFile, 0), WOLFSSL_SUCCESS);
  6349. if (ctx->c_cb.certPemFile != NULL) {
  6350. clientCertFile = ctx->c_cb.certPemFile;
  6351. }
  6352. if (ctx->c_cb.keyPemFile != NULL) {
  6353. clientKeyFile = ctx->c_cb.keyPemFile;
  6354. }
  6355. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6356. if (!c_sharedCtx)
  6357. #endif
  6358. {
  6359. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file(ctx->c_ctx,
  6360. clientCertFile), WOLFSSL_SUCCESS);
  6361. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx->c_ctx, clientKeyFile,
  6362. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  6363. }
  6364. #ifdef HAVE_CRL
  6365. if (ctx->c_cb.crlPemFile != NULL) {
  6366. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx->c_ctx, WOLFSSL_CRL_CHECKALL),
  6367. WOLFSSL_SUCCESS);
  6368. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx->c_ctx, ctx->c_cb.crlPemFile,
  6369. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  6370. }
  6371. #endif
  6372. if (ctx->c_ciphers != NULL) {
  6373. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx->c_ctx, ctx->c_ciphers),
  6374. WOLFSSL_SUCCESS);
  6375. }
  6376. if (ctx->c_cb.ctx_ready != NULL) {
  6377. ExpectIntEQ(ctx->c_cb.ctx_ready(ctx->c_ctx), TEST_SUCCESS);
  6378. }
  6379. /********************************
  6380. * Create WOLFSSL_CTX for server.
  6381. ********************************/
  6382. if (ctx->s_ctx != NULL) {
  6383. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6384. s_sharedCtx = 1;
  6385. #endif
  6386. ctx->s_cb.isSharedCtx = 1;
  6387. }
  6388. else
  6389. {
  6390. WOLFSSL_METHOD* method = NULL;
  6391. if (ctx->s_cb.method != NULL) {
  6392. method = ctx->s_cb.method();
  6393. }
  6394. else {
  6395. method = wolfSSLv23_server_method();
  6396. }
  6397. ExpectNotNull(ctx->s_ctx = wolfSSL_CTX_new(method));
  6398. ctx->s_cb.isSharedCtx = 0;
  6399. }
  6400. if (!ctx->s_cb.ticNoInit && (ctx->s_ctx != NULL)) {
  6401. #if defined(HAVE_SESSION_TICKET) && \
  6402. ((defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))
  6403. #if defined(OPENSSL_EXTRA) && defined(HAVE_AES_CBC)
  6404. OpenSSLTicketInit();
  6405. wolfSSL_CTX_set_tlsext_ticket_key_cb(ctx->s_ctx, myTicketEncCbOpenSSL);
  6406. #elif defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  6407. TicketInit();
  6408. wolfSSL_CTX_set_TicketEncCb(ctx->s_ctx, myTicketEncCb);
  6409. #endif
  6410. #endif
  6411. }
  6412. wolfSSL_SetIORecv(ctx->s_ctx, test_ssl_memio_read_cb);
  6413. wolfSSL_SetIOSend(ctx->s_ctx, test_ssl_memio_write_cb);
  6414. wolfSSL_CTX_set_verify(ctx->s_ctx, WOLFSSL_VERIFY_PEER |
  6415. WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  6416. if (ctx->s_cb.caPemFile != NULL)
  6417. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx->s_ctx,
  6418. ctx->s_cb.caPemFile, 0), WOLFSSL_SUCCESS);
  6419. else
  6420. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx->s_ctx,
  6421. cliCertFile, 0), WOLFSSL_SUCCESS);
  6422. #ifdef WOLFSSL_ENCRYPTED_KEYS
  6423. wolfSSL_CTX_set_default_passwd_cb(ctx->s_ctx, PasswordCallBack);
  6424. #endif
  6425. if (ctx->s_cb.certPemFile != NULL) {
  6426. serverCertFile = ctx->s_cb.certPemFile;
  6427. }
  6428. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6429. if (!s_sharedCtx)
  6430. #endif
  6431. {
  6432. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file(ctx->s_ctx,
  6433. serverCertFile), WOLFSSL_SUCCESS);
  6434. }
  6435. if (ctx->s_cb.keyPemFile != NULL) {
  6436. serverKeyFile = ctx->s_cb.keyPemFile;
  6437. }
  6438. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6439. if (!s_sharedCtx)
  6440. #endif
  6441. {
  6442. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx->s_ctx, serverKeyFile,
  6443. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  6444. }
  6445. if (ctx->s_ciphers != NULL) {
  6446. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx->s_ctx, ctx->s_ciphers),
  6447. WOLFSSL_SUCCESS);
  6448. }
  6449. if (ctx->s_cb.ctx_ready != NULL) {
  6450. ExpectIntEQ(ctx->s_cb.ctx_ready(ctx->s_ctx), TEST_SUCCESS);
  6451. }
  6452. /****************************
  6453. * Create WOLFSSL for client.
  6454. ****************************/
  6455. ExpectNotNull(ctx->c_ssl = wolfSSL_new(ctx->c_ctx));
  6456. wolfSSL_SetIOWriteCtx(ctx->c_ssl, ctx);
  6457. wolfSSL_SetIOReadCtx(ctx->c_ssl, ctx);
  6458. if (0
  6459. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6460. || c_sharedCtx
  6461. #endif
  6462. )
  6463. {
  6464. ExpectIntEQ(wolfSSL_use_certificate_chain_file(ctx->c_ssl,
  6465. clientCertFile), WOLFSSL_SUCCESS);
  6466. ExpectIntEQ(wolfSSL_use_PrivateKey_file(ctx->c_ssl, clientKeyFile,
  6467. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  6468. }
  6469. if (ctx->c_cb.ssl_ready != NULL) {
  6470. ExpectIntEQ(ctx->c_cb.ssl_ready(ctx->c_ssl), TEST_SUCCESS);
  6471. }
  6472. /****************************
  6473. * Create WOLFSSL for server.
  6474. ****************************/
  6475. ExpectNotNull(ctx->s_ssl = wolfSSL_new(ctx->s_ctx));
  6476. wolfSSL_SetIOWriteCtx(ctx->s_ssl, ctx);
  6477. wolfSSL_SetIOReadCtx(ctx->s_ssl, ctx);
  6478. if (0
  6479. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6480. || s_sharedCtx
  6481. #endif
  6482. )
  6483. {
  6484. ExpectIntEQ(wolfSSL_use_certificate_chain_file(ctx->s_ssl,
  6485. serverCertFile), WOLFSSL_SUCCESS);
  6486. ExpectIntEQ(wolfSSL_use_PrivateKey_file(ctx->s_ssl, serverKeyFile,
  6487. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  6488. }
  6489. #if !defined(NO_FILESYSTEM) && !defined(NO_DH)
  6490. wolfSSL_SetTmpDH_file(ctx->s_ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  6491. #elif !defined(NO_DH)
  6492. /* will repick suites with DHE, higher priority than PSK */
  6493. SetDH(ctx->s_ssl);
  6494. #endif
  6495. if (ctx->s_cb.ssl_ready != NULL) {
  6496. ExpectIntEQ(ctx->s_cb.ssl_ready(ctx->s_ssl), TEST_SUCCESS);
  6497. }
  6498. return EXPECT_RESULT();
  6499. }
  6500. static int test_ssl_memio_do_handshake(test_ssl_memio_ctx* ctx, int max_rounds,
  6501. int* rounds)
  6502. {
  6503. int handshake_complete = 0;
  6504. int hs_c = 0;
  6505. int hs_s = 0;
  6506. int failing_s = 0;
  6507. int failing_c = 0;
  6508. int ret;
  6509. int err;
  6510. if (rounds != NULL) {
  6511. *rounds = 0;
  6512. }
  6513. while ((!handshake_complete) && (max_rounds > 0)) {
  6514. if (!hs_c) {
  6515. wolfSSL_SetLoggingPrefix("client");
  6516. ret = wolfSSL_connect(ctx->c_ssl);
  6517. wolfSSL_SetLoggingPrefix(NULL);
  6518. if (ret == WOLFSSL_SUCCESS) {
  6519. hs_c = 1;
  6520. }
  6521. else {
  6522. err = wolfSSL_get_error(ctx->c_ssl, ret);
  6523. if (err != WOLFSSL_ERROR_WANT_READ &&
  6524. err != WOLFSSL_ERROR_WANT_WRITE) {
  6525. char buff[WOLFSSL_MAX_ERROR_SZ];
  6526. fprintf(stderr, "error = %d, %s\n", err,
  6527. wolfSSL_ERR_error_string(err, buff));
  6528. failing_c = 1;
  6529. hs_c = 1;
  6530. if (failing_c && failing_s) {
  6531. break;
  6532. }
  6533. }
  6534. }
  6535. }
  6536. if (!hs_s) {
  6537. wolfSSL_SetLoggingPrefix("server");
  6538. ret = wolfSSL_accept(ctx->s_ssl);
  6539. wolfSSL_SetLoggingPrefix(NULL);
  6540. if (ret == WOLFSSL_SUCCESS) {
  6541. hs_s = 1;
  6542. }
  6543. else {
  6544. err = wolfSSL_get_error(ctx->s_ssl, ret);
  6545. if (err != WOLFSSL_ERROR_WANT_READ &&
  6546. err != WOLFSSL_ERROR_WANT_WRITE) {
  6547. char buff[WOLFSSL_MAX_ERROR_SZ];
  6548. fprintf(stderr, "error = %d, %s\n", err,
  6549. wolfSSL_ERR_error_string(err, buff));
  6550. failing_s = 1;
  6551. hs_s = 1;
  6552. if (failing_c && failing_s) {
  6553. break;
  6554. }
  6555. }
  6556. }
  6557. }
  6558. handshake_complete = hs_c && hs_s;
  6559. max_rounds--;
  6560. if (rounds != NULL) {
  6561. *rounds += 1;
  6562. }
  6563. }
  6564. if (!handshake_complete || failing_c || failing_s) {
  6565. return TEST_FAIL;
  6566. }
  6567. return TEST_SUCCESS;
  6568. }
  6569. static int test_ssl_memio_read_write(test_ssl_memio_ctx* ctx)
  6570. {
  6571. EXPECT_DECLS_NO_MSGS(-3000);
  6572. char input[1024];
  6573. int idx = 0;
  6574. const char* msg_c = "hello wolfssl!";
  6575. int msglen_c = (int)XSTRLEN(msg_c);
  6576. const char* msg_s = "I hear you fa shizzle!";
  6577. int msglen_s = (int)XSTRLEN(msg_s);
  6578. if (ctx->c_msg != NULL) {
  6579. msg_c = ctx->c_msg;
  6580. msglen_c = ctx->c_msglen;
  6581. }
  6582. if (ctx->s_msg != NULL) {
  6583. msg_s = ctx->s_msg;
  6584. msglen_s = ctx->s_msglen;
  6585. }
  6586. wolfSSL_SetLoggingPrefix("client");
  6587. ExpectIntEQ(wolfSSL_write(ctx->c_ssl, msg_c, msglen_c), msglen_c);
  6588. wolfSSL_SetLoggingPrefix("server");
  6589. ExpectIntGT(idx = wolfSSL_read(ctx->s_ssl, input, sizeof(input) - 1), 0);
  6590. if (idx >= 0) {
  6591. input[idx] = '\0';
  6592. }
  6593. ExpectIntGT(fprintf(stderr, "Client message: %s\n", input), 0);
  6594. ExpectIntEQ(wolfSSL_write(ctx->s_ssl, msg_s, msglen_s), msglen_s);
  6595. ctx->s_cb.return_code = EXPECT_RESULT();
  6596. wolfSSL_SetLoggingPrefix("client");
  6597. ExpectIntGT(idx = wolfSSL_read(ctx->c_ssl, input, sizeof(input) - 1), 0);
  6598. wolfSSL_SetLoggingPrefix(NULL);
  6599. if (idx >= 0) {
  6600. input[idx] = '\0';
  6601. }
  6602. ExpectIntGT(fprintf(stderr, "Server response: %s\n", input), 0);
  6603. ctx->c_cb.return_code = EXPECT_RESULT();
  6604. if (ctx->c_cb.on_result != NULL) {
  6605. ExpectIntEQ(ctx->c_cb.on_result(ctx->c_ssl), TEST_SUCCESS);
  6606. }
  6607. if (ctx->s_cb.on_result != NULL) {
  6608. ExpectIntEQ(ctx->s_cb.on_result(ctx->s_ssl), TEST_SUCCESS);
  6609. }
  6610. return EXPECT_RESULT();
  6611. }
  6612. static void test_ssl_memio_cleanup(test_ssl_memio_ctx* ctx)
  6613. {
  6614. ctx->c_cb.last_err = wolfSSL_get_error(ctx->c_ssl, 0);
  6615. ctx->s_cb.last_err = wolfSSL_get_error(ctx->s_ssl, 0);
  6616. if (ctx->c_cb.on_cleanup != NULL) {
  6617. ctx->c_cb.on_cleanup(ctx->c_ssl);
  6618. }
  6619. if (ctx->s_cb.on_cleanup != NULL) {
  6620. ctx->s_cb.on_cleanup(ctx->s_ssl);
  6621. }
  6622. wolfSSL_shutdown(ctx->s_ssl);
  6623. wolfSSL_shutdown(ctx->c_ssl);
  6624. wolfSSL_free(ctx->s_ssl);
  6625. wolfSSL_free(ctx->c_ssl);
  6626. if (ctx->c_cb.on_ctx_cleanup != NULL) {
  6627. ctx->c_cb.on_ctx_cleanup(ctx->c_ctx);
  6628. }
  6629. if (!ctx->c_cb.isSharedCtx) {
  6630. wolfSSL_CTX_free(ctx->c_ctx);
  6631. ctx->c_ctx = NULL;
  6632. }
  6633. if (ctx->s_cb.on_ctx_cleanup != NULL) {
  6634. ctx->s_cb.on_ctx_cleanup(ctx->s_ctx);
  6635. }
  6636. if (!ctx->s_cb.isSharedCtx) {
  6637. wolfSSL_CTX_free(ctx->s_ctx);
  6638. ctx->s_ctx = NULL;
  6639. }
  6640. if (!ctx->s_cb.ticNoInit) {
  6641. #if defined(HAVE_SESSION_TICKET) && \
  6642. ((defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))
  6643. #if defined(OPENSSL_EXTRA) && defined(HAVE_AES_CBC)
  6644. OpenSSLTicketCleanup();
  6645. #elif defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  6646. TicketCleanup();
  6647. #endif
  6648. #endif
  6649. }
  6650. }
  6651. int test_wolfSSL_client_server_nofail_memio(test_ssl_cbf* client_cb,
  6652. test_ssl_cbf* server_cb, cbType client_on_handshake)
  6653. {
  6654. /* We use EXPECT_DECLS_NO_MSGS() here because this helper routine is used
  6655. * for numerous but varied expected-to-fail scenarios that should not emit
  6656. * error messages on the expected failures. Instead, we return a distinct
  6657. * code for each failure point, allowing the caller to assert on a
  6658. * particular mode of expected failure. On success, the usual TEST_SUCCESS
  6659. * is returned.
  6660. */
  6661. EXPECT_DECLS_NO_MSGS(-1000);
  6662. struct test_ssl_memio_ctx test_ctx;
  6663. #ifdef WOLFSSL_HAVE_TLS_UNIQUE
  6664. size_t msg_len;
  6665. #endif /* WOLFSSL_HAVE_TLS_UNIQUE */
  6666. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  6667. XMEMCPY(&test_ctx.c_cb, client_cb, sizeof(test_ssl_cbf));
  6668. XMEMCPY(&test_ctx.s_cb, server_cb, sizeof(test_ssl_cbf));
  6669. test_ctx.c_ctx = client_cb->ctx;
  6670. test_ctx.s_ctx = server_cb->ctx;
  6671. test_ctx.c_cb.return_code = EXPECT_FAILURE_CODEPOINT_ID;
  6672. test_ctx.s_cb.return_code = EXPECT_FAILURE_CODEPOINT_ID;
  6673. ExpectIntEQ(test_ssl_memio_setup(&test_ctx), TEST_SUCCESS);
  6674. ExpectIntEQ(test_ssl_memio_do_handshake(&test_ctx, 10, NULL), TEST_SUCCESS);
  6675. if (client_on_handshake != NULL) {
  6676. ExpectIntEQ(client_on_handshake(test_ctx.c_ctx, test_ctx.c_ssl),
  6677. TEST_SUCCESS);
  6678. }
  6679. if (client_cb->on_handshake != NULL) {
  6680. ExpectIntEQ(client_cb->on_handshake(&test_ctx.c_ctx, &test_ctx.c_ssl),
  6681. TEST_SUCCESS);
  6682. }
  6683. if (server_cb->on_handshake != NULL) {
  6684. ExpectIntEQ(server_cb->on_handshake(&test_ctx.s_ctx, &test_ctx.s_ssl),
  6685. TEST_SUCCESS);
  6686. }
  6687. #ifdef WOLFSSL_HAVE_TLS_UNIQUE
  6688. XMEMSET(server_side_msg2, 0, MD_MAX_SIZE);
  6689. msg_len = wolfSSL_get_peer_finished(test_ctx.s_ssl, server_side_msg2,
  6690. MD_MAX_SIZE);
  6691. ExpectIntGE(msg_len, 0);
  6692. XMEMSET(server_side_msg1, 0, MD_MAX_SIZE);
  6693. msg_len = wolfSSL_get_finished(test_ctx.s_ssl, server_side_msg1,
  6694. MD_MAX_SIZE);
  6695. ExpectIntGE(msg_len, 0);
  6696. #endif /* WOLFSSL_HAVE_TLS_UNIQUE */
  6697. ExpectIntEQ(test_ssl_memio_read_write(&test_ctx), TEST_SUCCESS);
  6698. test_ssl_memio_cleanup(&test_ctx);
  6699. client_cb->return_code = test_ctx.c_cb.return_code;
  6700. client_cb->last_err = test_ctx.c_cb.last_err;
  6701. server_cb->return_code = test_ctx.s_cb.return_code;
  6702. server_cb->last_err = test_ctx.s_cb.last_err;
  6703. return EXPECT_RESULT();
  6704. }
  6705. #endif
  6706. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  6707. #ifdef WOLFSSL_SESSION_EXPORT
  6708. #ifdef WOLFSSL_DTLS
  6709. /* set up function for sending session information */
  6710. static int test_export(WOLFSSL* inSsl, byte* buf, word32 sz, void* userCtx)
  6711. {
  6712. WOLFSSL_CTX* ctx = NULL;
  6713. WOLFSSL* ssl = NULL;
  6714. AssertNotNull(inSsl);
  6715. AssertNotNull(buf);
  6716. AssertIntNE(0, sz);
  6717. /* Set ctx to DTLS 1.2 */
  6718. ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method());
  6719. AssertNotNull(ctx);
  6720. ssl = wolfSSL_new(ctx);
  6721. AssertNotNull(ssl);
  6722. AssertIntGE(wolfSSL_dtls_import(ssl, buf, sz), 0);
  6723. wolfSSL_free(ssl);
  6724. wolfSSL_CTX_free(ctx);
  6725. (void)userCtx;
  6726. return 0;
  6727. }
  6728. #endif
  6729. /* returns negative value on fail and positive (including 0) on success */
  6730. static int nonblocking_accept_read(void* args, WOLFSSL* ssl, SOCKET_T* sockfd)
  6731. {
  6732. int ret, err, loop_count, count, timeout = 10;
  6733. char msg[] = "I hear you fa shizzle!";
  6734. char input[1024];
  6735. loop_count = ((func_args*)args)->argc;
  6736. #ifdef WOLFSSL_ASYNC_CRYPT
  6737. err = 0; /* Reset error */
  6738. #endif
  6739. do {
  6740. #ifdef WOLFSSL_ASYNC_CRYPT
  6741. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  6742. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  6743. if (ret < 0) { break; } else if (ret == 0) { continue; }
  6744. }
  6745. #endif
  6746. ret = wolfSSL_accept(ssl);
  6747. err = wolfSSL_get_error(ssl, 0);
  6748. if (err == WOLFSSL_ERROR_WANT_READ ||
  6749. err == WOLFSSL_ERROR_WANT_WRITE) {
  6750. int select_ret;
  6751. err = WC_PENDING_E;
  6752. select_ret = tcp_select(*sockfd, timeout);
  6753. if (select_ret == TEST_TIMEOUT) {
  6754. return WOLFSSL_FATAL_ERROR;
  6755. }
  6756. }
  6757. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  6758. if (ret != WOLFSSL_SUCCESS) {
  6759. char buff[WOLFSSL_MAX_ERROR_SZ];
  6760. fprintf(stderr, "error = %d, %s\n", err,
  6761. wolfSSL_ERR_error_string(err, buff));
  6762. return ret;
  6763. }
  6764. for (count = 0; count < loop_count; count++) {
  6765. int select_ret;
  6766. select_ret = tcp_select(*sockfd, timeout);
  6767. if (select_ret == TEST_TIMEOUT) {
  6768. ret = WOLFSSL_FATAL_ERROR;
  6769. break;
  6770. }
  6771. do {
  6772. ret = wolfSSL_read(ssl, input, sizeof(input)-1);
  6773. if (ret > 0) {
  6774. input[ret] = '\0';
  6775. fprintf(stderr, "Client message: %s\n", input);
  6776. }
  6777. } while (err == WOLFSSL_ERROR_WANT_READ && ret != WOLFSSL_SUCCESS);
  6778. do {
  6779. if ((ret = wolfSSL_write(ssl, msg, sizeof(msg))) != sizeof(msg)) {
  6780. return WOLFSSL_FATAL_ERROR;
  6781. }
  6782. err = wolfSSL_get_error(ssl, ret);
  6783. } while (err == WOLFSSL_ERROR_WANT_READ && ret != WOLFSSL_SUCCESS);
  6784. }
  6785. return ret;
  6786. }
  6787. #endif /* WOLFSSL_SESSION_EXPORT */
  6788. static THREAD_RETURN WOLFSSL_THREAD test_server_nofail(void* args)
  6789. {
  6790. SOCKET_T sockfd = 0;
  6791. SOCKET_T clientfd = 0;
  6792. word16 port;
  6793. callback_functions* cbf;
  6794. WOLFSSL_CTX* ctx = NULL;
  6795. WOLFSSL* ssl = NULL;
  6796. func_args* opts = (func_args*)args;
  6797. char msg[] = "I hear you fa shizzle!";
  6798. char input[1024];
  6799. int idx;
  6800. int ret, err = 0;
  6801. int sharedCtx = 0;
  6802. int doUdp = 0;
  6803. SOCKADDR_IN_T cliAddr;
  6804. socklen_t cliLen;
  6805. const char* certFile = svrCertFile;
  6806. const char* keyFile = svrKeyFile;
  6807. #ifdef WOLFSSL_HAVE_TLS_UNIQUE
  6808. size_t msg_len = 0;
  6809. #endif
  6810. wolfSSL_SetLoggingPrefix("server");
  6811. #ifdef WOLFSSL_TIRTOS
  6812. fdOpenSession(Task_self());
  6813. #endif
  6814. opts->return_code = TEST_FAIL;
  6815. cbf = opts->callbacks;
  6816. if (cbf != NULL && cbf->ctx) {
  6817. ctx = cbf->ctx;
  6818. sharedCtx = 1;
  6819. }
  6820. else
  6821. {
  6822. WOLFSSL_METHOD* method = NULL;
  6823. if (cbf != NULL && cbf->method != NULL) {
  6824. method = cbf->method();
  6825. }
  6826. else {
  6827. method = wolfSSLv23_server_method();
  6828. }
  6829. ctx = wolfSSL_CTX_new(method);
  6830. }
  6831. if (ctx == NULL) {
  6832. /* Release the wait for TCP ready. */
  6833. signal_ready(opts->signal);
  6834. goto done;
  6835. }
  6836. if (cbf == NULL || !cbf->ticNoInit) {
  6837. #if defined(HAVE_SESSION_TICKET) && \
  6838. ((defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))
  6839. #if defined(OPENSSL_EXTRA) && defined(HAVE_AES_CBC)
  6840. OpenSSLTicketInit();
  6841. wolfSSL_CTX_set_tlsext_ticket_key_cb(ctx, myTicketEncCbOpenSSL);
  6842. #elif defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  6843. TicketInit();
  6844. wolfSSL_CTX_set_TicketEncCb(ctx, myTicketEncCb);
  6845. #endif
  6846. #endif
  6847. }
  6848. #if defined(USE_WINDOWS_API)
  6849. port = opts->signal->port;
  6850. #elif defined(NO_MAIN_DRIVER) && !defined(WOLFSSL_SNIFFER) && \
  6851. !defined(WOLFSSL_MDK_SHELL) && !defined(WOLFSSL_TIRTOS)
  6852. /* Let tcp_listen assign port */
  6853. port = 0;
  6854. #else
  6855. /* Use default port */
  6856. port = wolfSSLPort;
  6857. #endif
  6858. if (cbf != NULL)
  6859. doUdp = cbf->doUdp;
  6860. /* do it here to detect failure */
  6861. tcp_accept(
  6862. &sockfd, &clientfd, opts, port, 0, doUdp, 0, 0, 1, 0, 0);
  6863. if (doUdp) {
  6864. cliLen = sizeof(cliAddr);
  6865. idx = (int)recvfrom(sockfd, input, sizeof(input), MSG_PEEK,
  6866. (struct sockaddr*)&cliAddr, &cliLen);
  6867. AssertIntGT(idx, 0);
  6868. }
  6869. else {
  6870. CloseSocket(sockfd);
  6871. }
  6872. wolfSSL_CTX_set_verify(ctx,
  6873. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  6874. #ifdef WOLFSSL_ENCRYPTED_KEYS
  6875. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  6876. #endif
  6877. if (wolfSSL_CTX_load_verify_locations(ctx, cliCertFile, 0)
  6878. != WOLFSSL_SUCCESS) {
  6879. /*err_sys("can't load ca file, Please run from wolfSSL home dir");*/
  6880. goto done;
  6881. }
  6882. if (cbf != NULL && cbf->certPemFile != NULL)
  6883. certFile = cbf->certPemFile;
  6884. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6885. if (!sharedCtx && wolfSSL_CTX_use_certificate_file(ctx, certFile,
  6886. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6887. #else
  6888. if (wolfSSL_CTX_use_certificate_file(ctx, certFile,
  6889. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6890. #endif
  6891. /*err_sys("can't load server cert chain file, "
  6892. "Please run from wolfSSL home dir");*/
  6893. goto done;
  6894. }
  6895. if (cbf != NULL && cbf->keyPemFile != NULL)
  6896. keyFile = cbf->keyPemFile;
  6897. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6898. if (!sharedCtx && wolfSSL_CTX_use_PrivateKey_file(ctx, keyFile,
  6899. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6900. #else
  6901. if (wolfSSL_CTX_use_PrivateKey_file(ctx, keyFile,
  6902. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6903. #endif
  6904. /*err_sys("can't load server key file, "
  6905. "Please run from wolfSSL home dir");*/
  6906. goto done;
  6907. }
  6908. #ifdef HAVE_CRL
  6909. if (cbf != NULL && cbf->crlPemFile != NULL) {
  6910. if (wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL) != WOLFSSL_SUCCESS)
  6911. goto done;
  6912. if (wolfSSL_CTX_LoadCRLFile(ctx, cbf->crlPemFile, WOLFSSL_FILETYPE_PEM)
  6913. != WOLFSSL_SUCCESS)
  6914. goto done;
  6915. }
  6916. #endif
  6917. /* call ctx setup callback */
  6918. if (cbf != NULL && cbf->ctx_ready != NULL) {
  6919. cbf->ctx_ready(ctx);
  6920. }
  6921. ssl = wolfSSL_new(ctx);
  6922. if (ssl == NULL) {
  6923. goto done;
  6924. }
  6925. if (doUdp) {
  6926. err = wolfSSL_dtls_set_peer(ssl, &cliAddr, cliLen);
  6927. if (err != WOLFSSL_SUCCESS)
  6928. goto done;
  6929. }
  6930. #ifdef WOLFSSL_SESSION_EXPORT
  6931. /* only add in more complex nonblocking case with session export tests */
  6932. if (args && opts->argc > 0) {
  6933. /* set as nonblock and time out for waiting on read/write */
  6934. tcp_set_nonblocking(&clientfd);
  6935. wolfSSL_dtls_set_using_nonblock(ssl, 1);
  6936. }
  6937. #endif
  6938. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6939. if (sharedCtx && wolfSSL_use_certificate_file(ssl, certFile,
  6940. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6941. #else
  6942. if (wolfSSL_use_certificate_file(ssl, certFile,
  6943. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6944. #endif
  6945. /*err_sys("can't load server cert chain file, "
  6946. "Please run from wolfSSL home dir");*/
  6947. goto done;
  6948. }
  6949. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6950. if (sharedCtx && wolfSSL_use_PrivateKey_file(ssl, keyFile,
  6951. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6952. #else
  6953. if (wolfSSL_use_PrivateKey_file(ssl, keyFile,
  6954. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6955. #endif
  6956. /*err_sys("can't load server key file, "
  6957. "Please run from wolfSSL home dir");*/
  6958. goto done;
  6959. }
  6960. if (wolfSSL_set_fd(ssl, clientfd) != WOLFSSL_SUCCESS) {
  6961. /*err_sys("SSL_set_fd failed");*/
  6962. goto done;
  6963. }
  6964. #if !defined(NO_FILESYSTEM) && !defined(NO_DH)
  6965. wolfSSL_SetTmpDH_file(ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  6966. #elif !defined(NO_DH)
  6967. SetDH(ssl); /* will repick suites with DHE, higher priority than PSK */
  6968. #endif
  6969. /* call ssl setup callback */
  6970. if (cbf != NULL && cbf->ssl_ready != NULL) {
  6971. cbf->ssl_ready(ssl);
  6972. }
  6973. #ifdef WOLFSSL_SESSION_EXPORT
  6974. /* only add in more complex nonblocking case with session export tests */
  6975. if (opts->argc > 0) {
  6976. ret = nonblocking_accept_read(args, ssl, &clientfd);
  6977. if (ret >= 0) {
  6978. opts->return_code = TEST_SUCCESS;
  6979. }
  6980. #ifdef WOLFSSL_TIRTOS
  6981. Task_yield();
  6982. #endif
  6983. goto done;
  6984. }
  6985. #endif
  6986. #ifdef WOLFSSL_ASYNC_CRYPT
  6987. err = 0; /* Reset error */
  6988. #endif
  6989. do {
  6990. #ifdef WOLFSSL_ASYNC_CRYPT
  6991. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  6992. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  6993. if (ret < 0) { break; } else if (ret == 0) { continue; }
  6994. }
  6995. #endif
  6996. ret = wolfSSL_negotiate(ssl);
  6997. err = wolfSSL_get_error(ssl, 0);
  6998. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  6999. if (ret != WOLFSSL_SUCCESS) {
  7000. char buff[WOLFSSL_MAX_ERROR_SZ];
  7001. fprintf(stderr, "error = %d, %s\n", err,
  7002. wolfSSL_ERR_error_string(err, buff));
  7003. /*err_sys("SSL_accept failed");*/
  7004. goto done;
  7005. }
  7006. #ifdef WOLFSSL_HAVE_TLS_UNIQUE
  7007. XMEMSET(server_side_msg2, 0, MD_MAX_SIZE);
  7008. msg_len = wolfSSL_get_peer_finished(ssl, server_side_msg2, MD_MAX_SIZE);
  7009. AssertIntGE(msg_len, 0);
  7010. XMEMSET(server_side_msg1, 0, MD_MAX_SIZE);
  7011. msg_len = wolfSSL_get_finished(ssl, server_side_msg1, MD_MAX_SIZE);
  7012. AssertIntGE(msg_len, 0);
  7013. #endif /* WOLFSSL_HAVE_TLS_UNIQUE */
  7014. idx = wolfSSL_read(ssl, input, sizeof(input)-1);
  7015. if (idx > 0) {
  7016. input[idx] = '\0';
  7017. fprintf(stderr, "Client message: %s\n", input);
  7018. }
  7019. else if (idx < 0) {
  7020. goto done;
  7021. }
  7022. if (wolfSSL_write(ssl, msg, sizeof(msg)) != sizeof(msg)) {
  7023. /*err_sys("SSL_write failed");*/
  7024. goto done;
  7025. }
  7026. if (cbf != NULL && cbf->on_result != NULL)
  7027. cbf->on_result(ssl);
  7028. #ifdef WOLFSSL_TIRTOS
  7029. Task_yield();
  7030. #endif
  7031. opts->return_code = TEST_SUCCESS;
  7032. done:
  7033. if (cbf != NULL)
  7034. cbf->last_err = err;
  7035. if (cbf != NULL && cbf->on_cleanup != NULL)
  7036. cbf->on_cleanup(ssl);
  7037. wolfSSL_shutdown(ssl);
  7038. wolfSSL_free(ssl);
  7039. if (!sharedCtx)
  7040. wolfSSL_CTX_free(ctx);
  7041. CloseSocket(clientfd);
  7042. #ifdef WOLFSSL_TIRTOS
  7043. fdCloseSession(Task_self());
  7044. #endif
  7045. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  7046. && defined(HAVE_THREAD_LS)
  7047. wc_ecc_fp_free(); /* free per thread cache */
  7048. #endif
  7049. if (cbf == NULL || !cbf->ticNoInit) {
  7050. #if defined(HAVE_SESSION_TICKET) && \
  7051. ((defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))
  7052. #if defined(OPENSSL_EXTRA) && defined(HAVE_AES_CBC)
  7053. OpenSSLTicketCleanup();
  7054. #elif defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  7055. TicketCleanup();
  7056. #endif
  7057. #endif
  7058. }
  7059. wolfSSL_SetLoggingPrefix(NULL);
  7060. WOLFSSL_RETURN_FROM_THREAD(0);
  7061. }
  7062. #if defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) && \
  7063. !defined(WOLFSSL_NO_TLS12)
  7064. static THREAD_RETURN WOLFSSL_THREAD test_server_loop(void* args)
  7065. {
  7066. SOCKET_T sockfd;
  7067. SOCKET_T clientfd = -1;
  7068. word16 port;
  7069. callback_functions* cbf;
  7070. WOLFSSL_CTX* ctx = 0;
  7071. WOLFSSL* ssl = 0;
  7072. char msg[] = "I hear you fa shizzle!";
  7073. char input[1024];
  7074. int idx;
  7075. int ret, err = 0;
  7076. int sharedCtx = 0;
  7077. func_args* opts = (func_args*)args;
  7078. int loop_count = opts->argc;
  7079. int count = 0;
  7080. #ifdef WOLFSSL_TIRTOS
  7081. fdOpenSession(Task_self());
  7082. #endif
  7083. opts->return_code = TEST_FAIL;
  7084. cbf = opts->callbacks;
  7085. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7086. if (cbf != NULL && cbf->ctx) {
  7087. ctx = cbf->ctx;
  7088. sharedCtx = 1;
  7089. }
  7090. else
  7091. #endif
  7092. {
  7093. WOLFSSL_METHOD* method = NULL;
  7094. if (cbf != NULL && cbf->method != NULL) {
  7095. method = cbf->method();
  7096. }
  7097. else {
  7098. method = wolfSSLv23_server_method();
  7099. }
  7100. ctx = wolfSSL_CTX_new(method);
  7101. }
  7102. #if defined(USE_WINDOWS_API)
  7103. port = opts->signal->port;
  7104. #elif defined(NO_MAIN_DRIVER) && !defined(WOLFSSL_SNIFFER) && \
  7105. !defined(WOLFSSL_MDK_SHELL) && !defined(WOLFSSL_TIRTOS)
  7106. /* Let tcp_listen assign port */
  7107. port = 0;
  7108. #else
  7109. /* Use default port */
  7110. port = wolfSSLPort;
  7111. #endif
  7112. wolfSSL_CTX_set_verify(ctx,
  7113. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  7114. #ifdef WOLFSSL_ENCRYPTED_KEYS
  7115. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  7116. #endif
  7117. if (wolfSSL_CTX_load_verify_locations(ctx, cliCertFile, 0)
  7118. != WOLFSSL_SUCCESS) {
  7119. /*err_sys("can't load ca file, Please run from wolfSSL home dir");*/
  7120. /* Release the wait for TCP ready. */
  7121. signal_ready(opts->signal);
  7122. goto done;
  7123. }
  7124. if (!sharedCtx && wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  7125. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7126. /*err_sys("can't load server cert chain file, "
  7127. "Please run from wolfSSL home dir");*/
  7128. /* Release the wait for TCP ready. */
  7129. signal_ready(opts->signal);
  7130. goto done;
  7131. }
  7132. if (!sharedCtx && wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  7133. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7134. /*err_sys("can't load server key file, "
  7135. "Please run from wolfSSL home dir");*/
  7136. /* Release the wait for TCP ready. */
  7137. signal_ready(opts->signal);
  7138. goto done;
  7139. }
  7140. /* call ctx setup callback */
  7141. if (cbf != NULL && cbf->ctx_ready != NULL) {
  7142. cbf->ctx_ready(ctx);
  7143. }
  7144. while (count != loop_count) {
  7145. ssl = wolfSSL_new(ctx);
  7146. if (ssl == NULL) {
  7147. signal_ready(opts->signal);
  7148. goto done;
  7149. }
  7150. if (sharedCtx && wolfSSL_use_certificate_file(ssl, svrCertFile,
  7151. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7152. /*err_sys("can't load server cert chain file, "
  7153. "Please run from wolfSSL home dir");*/
  7154. /* Release the wait for TCP ready. */
  7155. signal_ready(opts->signal);
  7156. goto done;
  7157. }
  7158. if (sharedCtx && wolfSSL_use_PrivateKey_file(ssl, svrKeyFile,
  7159. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7160. /*err_sys("can't load server key file, "
  7161. "Please run from wolfSSL home dir");*/
  7162. /* Release the wait for TCP ready. */
  7163. signal_ready(opts->signal);
  7164. goto done;
  7165. }
  7166. #if !defined(NO_FILESYSTEM) && !defined(NO_DH)
  7167. wolfSSL_SetTmpDH_file(ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  7168. #elif !defined(NO_DH)
  7169. SetDH(ssl); /* will repick suites with DHE, higher priority than PSK */
  7170. #endif
  7171. /* call ssl setup callback */
  7172. if (cbf != NULL && cbf->ssl_ready != NULL) {
  7173. cbf->ssl_ready(ssl);
  7174. }
  7175. /* do it here to detect failure */
  7176. tcp_accept(&sockfd, &clientfd, (func_args*)args, port, 0, 0, 0, 0, 1, 0,
  7177. 0);
  7178. CloseSocket(sockfd);
  7179. if (wolfSSL_set_fd(ssl, clientfd) != WOLFSSL_SUCCESS) {
  7180. /*err_sys("SSL_set_fd failed");*/
  7181. goto done;
  7182. }
  7183. #ifdef WOLFSSL_ASYNC_CRYPT
  7184. err = 0; /* Reset error */
  7185. #endif
  7186. do {
  7187. #ifdef WOLFSSL_ASYNC_CRYPT
  7188. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7189. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7190. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7191. }
  7192. #endif
  7193. ret = wolfSSL_accept(ssl);
  7194. err = wolfSSL_get_error(ssl, 0);
  7195. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7196. if (ret != WOLFSSL_SUCCESS) {
  7197. char buff[WOLFSSL_MAX_ERROR_SZ];
  7198. fprintf(stderr, "error = %d, %s\n", err,
  7199. wolfSSL_ERR_error_string(err, buff));
  7200. /*err_sys("SSL_accept failed");*/
  7201. goto done;
  7202. }
  7203. idx = wolfSSL_read(ssl, input, sizeof(input)-1);
  7204. if (idx > 0) {
  7205. input[idx] = '\0';
  7206. fprintf(stderr, "Client message: %s\n", input);
  7207. }
  7208. if (wolfSSL_write(ssl, msg, sizeof(msg)) != sizeof(msg)) {
  7209. /*err_sys("SSL_write failed");*/
  7210. goto done;
  7211. }
  7212. /* free ssl for this connection */
  7213. wolfSSL_shutdown(ssl);
  7214. wolfSSL_free(ssl); ssl = NULL;
  7215. CloseSocket(clientfd);
  7216. clientfd = -1;
  7217. count++;
  7218. }
  7219. #ifdef WOLFSSL_TIRTOS
  7220. Task_yield();
  7221. #endif
  7222. opts->return_code = TEST_SUCCESS;
  7223. done:
  7224. if (ssl != NULL) {
  7225. wolfSSL_shutdown(ssl);
  7226. wolfSSL_free(ssl);
  7227. }
  7228. if (!sharedCtx)
  7229. wolfSSL_CTX_free(ctx);
  7230. if (clientfd >= 0)
  7231. CloseSocket(clientfd);
  7232. #ifdef WOLFSSL_TIRTOS
  7233. fdCloseSession(Task_self());
  7234. #endif
  7235. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  7236. && defined(HAVE_THREAD_LS)
  7237. wc_ecc_fp_free(); /* free per thread cache */
  7238. #endif
  7239. WOLFSSL_RETURN_FROM_THREAD(0);
  7240. }
  7241. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) && !defined(WOLFSSL_TLS13) */
  7242. static int test_client_nofail(void* args, cbType cb)
  7243. {
  7244. #if !defined(NO_WOLFSSL_CLIENT)
  7245. SOCKET_T sockfd = 0;
  7246. callback_functions* cbf;
  7247. WOLFSSL_CTX* ctx = 0;
  7248. WOLFSSL* ssl = 0;
  7249. WOLFSSL_CIPHER* cipher;
  7250. char msg[64] = "hello wolfssl!";
  7251. char reply[1024];
  7252. int input;
  7253. int msgSz = (int)XSTRLEN(msg);
  7254. int ret, err = 0;
  7255. int cipherSuite;
  7256. int sharedCtx = 0;
  7257. int doUdp = 0;
  7258. const char* cipherName1, *cipherName2;
  7259. wolfSSL_SetLoggingPrefix("client");
  7260. #ifdef WOLFSSL_TIRTOS
  7261. fdOpenSession(Task_self());
  7262. #endif
  7263. ((func_args*)args)->return_code = TEST_FAIL;
  7264. cbf = ((func_args*)args)->callbacks;
  7265. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7266. if (cbf != NULL && cbf->ctx) {
  7267. ctx = cbf->ctx;
  7268. sharedCtx = cbf->isSharedCtx;
  7269. }
  7270. else
  7271. #endif
  7272. {
  7273. WOLFSSL_METHOD* method = NULL;
  7274. if (cbf != NULL && cbf->method != NULL) {
  7275. method = cbf->method();
  7276. }
  7277. else {
  7278. method = wolfSSLv23_client_method();
  7279. }
  7280. ctx = wolfSSL_CTX_new(method);
  7281. }
  7282. if (cbf != NULL)
  7283. doUdp = cbf->doUdp;
  7284. #ifdef WOLFSSL_ENCRYPTED_KEYS
  7285. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  7286. #endif
  7287. /* Do connect here so server detects failures */
  7288. tcp_connect(&sockfd, wolfSSLIP, ((func_args*)args)->signal->port,
  7289. doUdp, 0, NULL);
  7290. /* Connect the socket so that we don't have to set the peer later on */
  7291. if (doUdp)
  7292. udp_connect(&sockfd, wolfSSLIP, ((func_args*)args)->signal->port);
  7293. if (wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0) != WOLFSSL_SUCCESS)
  7294. {
  7295. /* err_sys("can't load ca file, Please run from wolfSSL home dir");*/
  7296. goto done;
  7297. }
  7298. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7299. if (!sharedCtx && wolfSSL_CTX_use_certificate_file(ctx, cliCertFile,
  7300. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7301. #else
  7302. if (wolfSSL_CTX_use_certificate_file(ctx, cliCertFile,
  7303. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7304. #endif
  7305. /*err_sys("can't load client cert file, "
  7306. "Please run from wolfSSL home dir");*/
  7307. goto done;
  7308. }
  7309. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7310. if (!sharedCtx && wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile,
  7311. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7312. #else
  7313. if (wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile,
  7314. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7315. #endif
  7316. /*err_sys("can't load client key file, "
  7317. "Please run from wolfSSL home dir");*/
  7318. goto done;
  7319. }
  7320. #ifdef HAVE_CRL
  7321. if (cbf != NULL && cbf->crlPemFile != NULL) {
  7322. if (wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL) != WOLFSSL_SUCCESS)
  7323. goto done;
  7324. if (wolfSSL_CTX_LoadCRLFile(ctx, cbf->crlPemFile, WOLFSSL_FILETYPE_PEM)
  7325. != WOLFSSL_SUCCESS)
  7326. goto done;
  7327. }
  7328. #endif
  7329. /* call ctx setup callback */
  7330. if (cbf != NULL && cbf->ctx_ready != NULL) {
  7331. cbf->ctx_ready(ctx);
  7332. }
  7333. ssl = wolfSSL_new(ctx);
  7334. if (ssl == NULL) {
  7335. goto done;
  7336. }
  7337. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7338. if (sharedCtx && wolfSSL_use_certificate_file(ssl, cliCertFile,
  7339. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7340. #else
  7341. if (wolfSSL_use_certificate_file(ssl, cliCertFile,
  7342. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7343. #endif
  7344. /*err_sys("can't load client cert file, "
  7345. "Please run from wolfSSL home dir");*/
  7346. goto done;
  7347. }
  7348. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7349. if (sharedCtx && wolfSSL_use_PrivateKey_file(ssl, cliKeyFile,
  7350. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7351. #else
  7352. if (wolfSSL_use_PrivateKey_file(ssl, cliKeyFile,
  7353. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7354. #endif
  7355. /*err_sys("can't load client key file, "
  7356. "Please run from wolfSSL home dir");*/
  7357. goto done;
  7358. }
  7359. if (!doUdp) {
  7360. if (wolfSSL_set_fd(ssl, sockfd) != WOLFSSL_SUCCESS) {
  7361. /*err_sys("SSL_set_fd failed");*/
  7362. goto done;
  7363. }
  7364. }
  7365. else {
  7366. #ifdef WOLFSSL_DTLS
  7367. if (wolfSSL_set_dtls_fd_connected(ssl, sockfd) != WOLFSSL_SUCCESS) {
  7368. /*err_sys("SSL_set_fd failed");*/
  7369. goto done;
  7370. }
  7371. #else
  7372. goto done;
  7373. #endif
  7374. }
  7375. /* call ssl setup callback */
  7376. if (cbf != NULL && cbf->ssl_ready != NULL) {
  7377. cbf->ssl_ready(ssl);
  7378. }
  7379. #ifdef WOLFSSL_ASYNC_CRYPT
  7380. err = 0; /* Reset error */
  7381. #endif
  7382. do {
  7383. #ifdef WOLFSSL_ASYNC_CRYPT
  7384. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7385. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7386. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7387. }
  7388. #endif
  7389. ret = wolfSSL_negotiate(ssl);
  7390. err = wolfSSL_get_error(ssl, 0);
  7391. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7392. if (ret != WOLFSSL_SUCCESS) {
  7393. char buff[WOLFSSL_MAX_ERROR_SZ];
  7394. fprintf(stderr, "error = %d, %s\n", err,
  7395. wolfSSL_ERR_error_string(err, buff));
  7396. /*err_sys("SSL_connect failed");*/
  7397. goto done;
  7398. }
  7399. /* test the various get cipher methods */
  7400. /* Internal cipher suite names */
  7401. cipherSuite = wolfSSL_get_current_cipher_suite(ssl);
  7402. cipherName1 = wolfSSL_get_cipher_name(ssl);
  7403. cipherName2 = wolfSSL_get_cipher_name_from_suite(
  7404. (cipherSuite >> 8), cipherSuite & 0xFF);
  7405. AssertStrEQ(cipherName1, cipherName2);
  7406. /* IANA Cipher Suites Names */
  7407. /* Unless WOLFSSL_CIPHER_INTERNALNAME or NO_ERROR_STRINGS,
  7408. then it's the internal cipher suite name */
  7409. cipher = wolfSSL_get_current_cipher(ssl);
  7410. cipherName1 = wolfSSL_CIPHER_get_name(cipher);
  7411. cipherName2 = wolfSSL_get_cipher(ssl);
  7412. AssertStrEQ(cipherName1, cipherName2);
  7413. #if !defined(WOLFSSL_CIPHER_INTERNALNAME) && !defined(NO_ERROR_STRINGS) && \
  7414. !defined(WOLFSSL_QT)
  7415. cipherName1 = wolfSSL_get_cipher_name_iana_from_suite(
  7416. (cipherSuite >> 8), cipherSuite & 0xFF);
  7417. AssertStrEQ(cipherName1, cipherName2);
  7418. #endif
  7419. if (cb != NULL)
  7420. (cb)(ctx, ssl);
  7421. if (wolfSSL_write(ssl, msg, msgSz) != msgSz) {
  7422. /*err_sys("SSL_write failed");*/
  7423. goto done;
  7424. }
  7425. input = wolfSSL_read(ssl, reply, sizeof(reply)-1);
  7426. if (input > 0) {
  7427. reply[input] = '\0';
  7428. fprintf(stderr, "Server response: %s\n", reply);
  7429. }
  7430. if (cbf != NULL && cbf->on_result != NULL)
  7431. cbf->on_result(ssl);
  7432. ((func_args*)args)->return_code = TEST_SUCCESS;
  7433. done:
  7434. if (cbf != NULL)
  7435. cbf->last_err = err;
  7436. if (cbf != NULL && cbf->on_cleanup != NULL)
  7437. cbf->on_cleanup(ssl);
  7438. wolfSSL_free(ssl);
  7439. if (!sharedCtx)
  7440. wolfSSL_CTX_free(ctx);
  7441. CloseSocket(sockfd);
  7442. #ifdef WOLFSSL_TIRTOS
  7443. fdCloseSession(Task_self());
  7444. #endif
  7445. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  7446. && defined(HAVE_THREAD_LS)
  7447. wc_ecc_fp_free(); /* free per thread cache */
  7448. #endif
  7449. #else
  7450. (void)args;
  7451. (void)cb;
  7452. #endif /* !NO_WOLFSSL_CLIENT */
  7453. wolfSSL_SetLoggingPrefix(NULL);
  7454. return 0;
  7455. }
  7456. void test_wolfSSL_client_server_nofail_ex(callback_functions* client_cb,
  7457. callback_functions* server_cb, cbType client_on_handshake)
  7458. {
  7459. func_args client_args;
  7460. func_args server_args;
  7461. tcp_ready ready;
  7462. THREAD_TYPE serverThread;
  7463. XMEMSET(&client_args, 0, sizeof(func_args));
  7464. XMEMSET(&server_args, 0, sizeof(func_args));
  7465. #ifdef WOLFSSL_TIRTOS
  7466. fdOpenSession(Task_self());
  7467. #endif
  7468. StartTCP();
  7469. InitTcpReady(&ready);
  7470. #if defined(USE_WINDOWS_API)
  7471. /* use RNG to get random port if using windows */
  7472. ready.port = GetRandomPort();
  7473. #endif
  7474. server_args.signal = &ready;
  7475. server_args.callbacks = server_cb;
  7476. client_args.signal = &ready;
  7477. client_args.callbacks = client_cb;
  7478. start_thread(test_server_nofail, &server_args, &serverThread);
  7479. wait_tcp_ready(&server_args);
  7480. test_client_nofail(&client_args, client_on_handshake);
  7481. join_thread(serverThread);
  7482. client_cb->return_code = client_args.return_code;
  7483. server_cb->return_code = server_args.return_code;
  7484. FreeTcpReady(&ready);
  7485. #ifdef WOLFSSL_TIRTOS
  7486. fdOpenSession(Task_self());
  7487. #endif
  7488. }
  7489. void test_wolfSSL_client_server_nofail(callback_functions* client_cb,
  7490. callback_functions* server_cb)
  7491. {
  7492. test_wolfSSL_client_server_nofail_ex(client_cb, server_cb, NULL);
  7493. }
  7494. #if defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) && \
  7495. !defined(WOLFSSL_NO_TLS12) && !defined(NO_WOLFSSL_CLIENT)
  7496. static void test_client_reuse_WOLFSSLobj(void* args, cbType cb,
  7497. void* server_args)
  7498. {
  7499. SOCKET_T sockfd = 0;
  7500. callback_functions* cbf;
  7501. WOLFSSL_CTX* ctx = 0;
  7502. WOLFSSL* ssl = 0;
  7503. WOLFSSL_SESSION* session = NULL;
  7504. char msg[64] = "hello wolfssl!";
  7505. char reply[1024];
  7506. int input;
  7507. int msgSz = (int)XSTRLEN(msg);
  7508. int ret, err = 0;
  7509. int sharedCtx = 0;
  7510. #ifdef WOLFSSL_TIRTOS
  7511. fdOpenSession(Task_self());
  7512. #endif
  7513. ((func_args*)args)->return_code = TEST_FAIL;
  7514. cbf = ((func_args*)args)->callbacks;
  7515. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7516. if (cbf != NULL && cbf->ctx) {
  7517. ctx = cbf->ctx;
  7518. sharedCtx = 1;
  7519. }
  7520. else
  7521. #endif
  7522. {
  7523. WOLFSSL_METHOD* method = NULL;
  7524. if (cbf != NULL && cbf->method != NULL) {
  7525. method = cbf->method();
  7526. }
  7527. else {
  7528. method = wolfSSLv23_client_method();
  7529. }
  7530. ctx = wolfSSL_CTX_new(method);
  7531. }
  7532. #ifdef WOLFSSL_ENCRYPTED_KEYS
  7533. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  7534. #endif
  7535. /* Do connect here so server detects failures */
  7536. tcp_connect(&sockfd, wolfSSLIP, ((func_args*)args)->signal->port,
  7537. 0, 0, NULL);
  7538. if (wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0) !=
  7539. WOLFSSL_SUCCESS) {
  7540. /* err_sys("can't load ca file, Please run from wolfSSL home dir");*/
  7541. goto done;
  7542. }
  7543. if (!sharedCtx && wolfSSL_CTX_use_certificate_file(ctx, cliCertFile,
  7544. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7545. /*err_sys("can't load client cert file, "
  7546. "Please run from wolfSSL home dir");*/
  7547. goto done;
  7548. }
  7549. if (!sharedCtx && wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile,
  7550. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7551. /*err_sys("can't load client key file, "
  7552. "Please run from wolfSSL home dir");*/
  7553. goto done;
  7554. }
  7555. /* call ctx setup callback */
  7556. if (cbf != NULL && cbf->ctx_ready != NULL) {
  7557. cbf->ctx_ready(ctx);
  7558. }
  7559. ssl = wolfSSL_new(ctx);
  7560. if (ssl == NULL) {
  7561. goto done;
  7562. }
  7563. /* keep handshake resources for re-using WOLFSSL obj */
  7564. wolfSSL_KeepArrays(ssl);
  7565. if (wolfSSL_KeepHandshakeResources(ssl)) {
  7566. /* err_sys("SSL_KeepHandshakeResources failed"); */
  7567. goto done;
  7568. }
  7569. if (sharedCtx && wolfSSL_use_certificate_file(ssl, cliCertFile,
  7570. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7571. /*err_sys("can't load client cert file, "
  7572. "Please run from wolfSSL home dir");*/
  7573. goto done;
  7574. }
  7575. if (sharedCtx && wolfSSL_use_PrivateKey_file(ssl, cliKeyFile,
  7576. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7577. /*err_sys("can't load client key file, "
  7578. "Please run from wolfSSL home dir");*/
  7579. goto done;
  7580. }
  7581. if (wolfSSL_set_fd(ssl, sockfd) != WOLFSSL_SUCCESS) {
  7582. /*err_sys("SSL_set_fd failed");*/
  7583. goto done;
  7584. }
  7585. /* call ssl setup callback */
  7586. if (cbf != NULL && cbf->ssl_ready != NULL) {
  7587. cbf->ssl_ready(ssl);
  7588. }
  7589. #ifdef WOLFSSL_ASYNC_CRYPT
  7590. err = 0; /* Reset error */
  7591. #endif
  7592. do {
  7593. #ifdef WOLFSSL_ASYNC_CRYPT
  7594. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7595. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7596. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7597. }
  7598. #endif
  7599. ret = wolfSSL_connect(ssl);
  7600. err = wolfSSL_get_error(ssl, 0);
  7601. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7602. if (ret != WOLFSSL_SUCCESS) {
  7603. char buff[WOLFSSL_MAX_ERROR_SZ];
  7604. fprintf(stderr, "error = %d, %s\n", err,
  7605. wolfSSL_ERR_error_string(err, buff));
  7606. /*err_sys("SSL_connect failed");*/
  7607. goto done;
  7608. }
  7609. /* Build first session */
  7610. if (cb != NULL)
  7611. cb(ctx, ssl);
  7612. if (wolfSSL_write(ssl, msg, msgSz) != msgSz) {
  7613. /*err_sys("SSL_write failed");*/
  7614. goto done;
  7615. }
  7616. input = wolfSSL_read(ssl, reply, sizeof(reply)-1);
  7617. if (input > 0) {
  7618. reply[input] = '\0';
  7619. fprintf(stderr, "Server response: %s\n", reply);
  7620. }
  7621. /* Session Resumption by re-using WOLFSSL object */
  7622. wolfSSL_set_quiet_shutdown(ssl, 1);
  7623. if (wolfSSL_shutdown(ssl) != WOLFSSL_SUCCESS) {
  7624. /* err_sys ("SSL shutdown failed"); */
  7625. goto done;
  7626. }
  7627. session = wolfSSL_get1_session(ssl);
  7628. if (wolfSSL_clear(ssl) != WOLFSSL_SUCCESS) {
  7629. wolfSSL_SESSION_free(session);
  7630. /* err_sys ("SSL_clear failed"); */
  7631. goto done;
  7632. }
  7633. wolfSSL_set_session(ssl, session);
  7634. wolfSSL_SESSION_free(session);
  7635. session = NULL;
  7636. /* close socket once */
  7637. CloseSocket(sockfd);
  7638. sockfd = 0;
  7639. /* wait until server ready */
  7640. wait_tcp_ready((func_args*)server_args);
  7641. fprintf(stderr, "session resumption\n");
  7642. /* Do re-connect */
  7643. tcp_connect(&sockfd, wolfSSLIP, ((func_args*)args)->signal->port,
  7644. 0, 0, NULL);
  7645. if (wolfSSL_set_fd(ssl, sockfd) != WOLFSSL_SUCCESS) {
  7646. /*err_sys("SSL_set_fd failed");*/
  7647. goto done;
  7648. }
  7649. #ifdef WOLFSSL_ASYNC_CRYPT
  7650. err = 0; /* Reset error */
  7651. #endif
  7652. do {
  7653. #ifdef WOLFSSL_ASYNC_CRYPT
  7654. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7655. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7656. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7657. }
  7658. #endif
  7659. ret = wolfSSL_connect(ssl);
  7660. err = wolfSSL_get_error(ssl, 0);
  7661. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7662. if (ret != WOLFSSL_SUCCESS) {
  7663. char buff[WOLFSSL_MAX_ERROR_SZ];
  7664. fprintf(stderr, "error = %d, %s\n", err,
  7665. wolfSSL_ERR_error_string(err, buff));
  7666. /*err_sys("SSL_connect failed");*/
  7667. goto done;
  7668. }
  7669. /* Build first session */
  7670. if (cb != NULL)
  7671. cb(ctx, ssl);
  7672. if (wolfSSL_write(ssl, msg, msgSz) != msgSz) {
  7673. /*err_sys("SSL_write failed");*/
  7674. goto done;
  7675. }
  7676. input = wolfSSL_read(ssl, reply, sizeof(reply)-1);
  7677. if (input > 0) {
  7678. reply[input] = '\0';
  7679. fprintf(stderr, "Server response: %s\n", reply);
  7680. }
  7681. ((func_args*)args)->return_code = TEST_SUCCESS;
  7682. done:
  7683. wolfSSL_free(ssl);
  7684. if (!sharedCtx)
  7685. wolfSSL_CTX_free(ctx);
  7686. CloseSocket(sockfd);
  7687. #ifdef WOLFSSL_TIRTOS
  7688. fdCloseSession(Task_self());
  7689. #endif
  7690. return;
  7691. }
  7692. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) &&
  7693. !defined(WOLFSSL_TLS13) && !defined(NO_WOLFSSL_CLIENT) */
  7694. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \
  7695. defined(WOLFSSL_HAPROXY) || defined(HAVE_LIGHTY)) && \
  7696. defined(HAVE_ALPN) && defined(HAVE_SNI) && \
  7697. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(NO_BIO)
  7698. #define HAVE_ALPN_PROTOS_SUPPORT
  7699. #endif
  7700. /* Generic TLS client / server with callbacks for API unit tests
  7701. * Used by SNI / ALPN / crypto callback helper functions */
  7702. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  7703. (defined(HAVE_SNI) || defined(HAVE_ALPN) || defined(WOLF_CRYPTO_CB) || \
  7704. defined(HAVE_ALPN_PROTOS_SUPPORT)) || defined(WOLFSSL_STATIC_MEMORY)
  7705. #define ENABLE_TLS_CALLBACK_TEST
  7706. #endif
  7707. #if defined(ENABLE_TLS_CALLBACK_TEST) || \
  7708. (defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT))
  7709. /* TLS server for API unit testing - generic */
  7710. static THREAD_RETURN WOLFSSL_THREAD run_wolfssl_server(void* args)
  7711. {
  7712. callback_functions* callbacks = ((func_args*)args)->callbacks;
  7713. WOLFSSL_CTX* ctx = NULL;
  7714. WOLFSSL* ssl = NULL;
  7715. SOCKET_T sfd = 0;
  7716. SOCKET_T cfd = 0;
  7717. word16 port;
  7718. char msg[] = "I hear you fa shizzle!";
  7719. int len = (int) XSTRLEN(msg);
  7720. char input[1024];
  7721. int idx;
  7722. int ret, err = 0;
  7723. ((func_args*)args)->return_code = TEST_FAIL;
  7724. #if defined(USE_WINDOWS_API)
  7725. port = ((func_args*)args)->signal->port;
  7726. #elif defined(NO_MAIN_DRIVER) && !defined(WOLFSSL_SNIFFER) && \
  7727. !defined(WOLFSSL_MDK_SHELL) && !defined(WOLFSSL_TIRTOS)
  7728. /* Let tcp_listen assign port */
  7729. port = 0;
  7730. #else
  7731. /* Use default port */
  7732. port = wolfSSLPort;
  7733. #endif
  7734. #ifdef WOLFSSL_DTLS
  7735. if (callbacks->method == wolfDTLS_server_method
  7736. #ifdef WOLFSSL_STATIC_MEMORY
  7737. || callbacks->method_ex == wolfDTLS_server_method_ex
  7738. #endif
  7739. #ifndef NO_OLD_TLS
  7740. || callbacks->method == wolfDTLSv1_server_method
  7741. #ifdef WOLFSSL_STATIC_MEMORY
  7742. || callbacks->method_ex == wolfDTLSv1_server_method_ex
  7743. #endif
  7744. #endif
  7745. #ifndef WOLFSSL_NO_TLS12
  7746. || callbacks->method == wolfDTLSv1_2_server_method
  7747. #ifdef WOLFSSL_STATIC_MEMORY
  7748. || callbacks->method_ex == wolfDTLSv1_2_server_method_ex
  7749. #endif
  7750. #endif
  7751. #ifdef WOLFSSL_DTLS13
  7752. || callbacks->method == wolfDTLSv1_3_server_method
  7753. #ifdef WOLFSSL_STATIC_MEMORY
  7754. || callbacks->method_ex == wolfDTLSv1_3_server_method_ex
  7755. #endif
  7756. #endif
  7757. ) {
  7758. tcp_accept(&sfd, &cfd, (func_args*)args, port, 0, 1, 0, 0, 0, 0, 0);
  7759. }
  7760. else
  7761. #endif
  7762. {
  7763. tcp_accept(&sfd, &cfd, (func_args*)args, port, 0, 0, 0, 0, 1, 0, 0);
  7764. }
  7765. #ifdef WOLFSSL_STATIC_MEMORY
  7766. if (callbacks->method_ex != NULL && callbacks->mem != NULL &&
  7767. callbacks->memSz > 0) {
  7768. ret = wolfSSL_CTX_load_static_memory(&ctx, callbacks->method_ex,
  7769. callbacks->mem, callbacks->memSz, 0, 1);
  7770. if (ret != WOLFSSL_SUCCESS) {
  7771. fprintf(stderr, "CTX static new failed %d\n", ret);
  7772. goto cleanup;
  7773. }
  7774. }
  7775. #else
  7776. ctx = wolfSSL_CTX_new(callbacks->method());
  7777. #endif
  7778. if (ctx == NULL) {
  7779. fprintf(stderr, "CTX new failed\n");
  7780. goto cleanup;
  7781. }
  7782. /* set defaults */
  7783. if (callbacks->caPemFile == NULL)
  7784. callbacks->caPemFile = cliCertFile;
  7785. if (callbacks->certPemFile == NULL)
  7786. callbacks->certPemFile = svrCertFile;
  7787. if (callbacks->keyPemFile == NULL)
  7788. callbacks->keyPemFile = svrKeyFile;
  7789. #ifdef WOLFSSL_TIRTOS
  7790. fdOpenSession(Task_self());
  7791. #endif
  7792. wolfSSL_CTX_SetDevId(ctx, callbacks->devId);
  7793. wolfSSL_CTX_set_verify(ctx,
  7794. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  7795. #ifdef WOLFSSL_ENCRYPTED_KEYS
  7796. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  7797. #endif
  7798. #if defined(WOLFSSL_SESSION_EXPORT) && defined(WOLFSSL_DTLS)
  7799. if (callbacks->method == wolfDTLSv1_2_server_method) {
  7800. if (wolfSSL_CTX_dtls_set_export(ctx, test_export) != WOLFSSL_SUCCESS)
  7801. goto cleanup;
  7802. }
  7803. #endif
  7804. if (wolfSSL_CTX_load_verify_locations(ctx, callbacks->caPemFile, 0) !=
  7805. WOLFSSL_SUCCESS) {
  7806. goto cleanup;
  7807. }
  7808. if (wolfSSL_CTX_use_certificate_file(ctx, callbacks->certPemFile,
  7809. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7810. goto cleanup;
  7811. }
  7812. if (wolfSSL_CTX_use_PrivateKey_file(ctx, callbacks->keyPemFile,
  7813. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7814. goto cleanup;
  7815. }
  7816. #ifdef HAVE_CRL
  7817. if (callbacks->crlPemFile != NULL) {
  7818. if (wolfSSL_CTX_LoadCRLFile(ctx, callbacks->crlPemFile,
  7819. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7820. goto cleanup;
  7821. }
  7822. }
  7823. #endif
  7824. if (callbacks->ctx_ready)
  7825. callbacks->ctx_ready(ctx);
  7826. ssl = wolfSSL_new(ctx);
  7827. if (ssl == NULL) {
  7828. fprintf(stderr, "SSL new failed\n");
  7829. goto cleanup;
  7830. }
  7831. if (wolfSSL_dtls(ssl)) {
  7832. SOCKADDR_IN_T cliAddr;
  7833. socklen_t cliLen;
  7834. cliLen = sizeof(cliAddr);
  7835. idx = (int)recvfrom(sfd, input, sizeof(input), MSG_PEEK,
  7836. (struct sockaddr*)&cliAddr, &cliLen);
  7837. if (idx <= 0) {
  7838. goto cleanup;
  7839. }
  7840. wolfSSL_dtls_set_peer(ssl, &cliAddr, cliLen);
  7841. }
  7842. else {
  7843. CloseSocket(sfd);
  7844. }
  7845. if (wolfSSL_set_fd(ssl, cfd) != WOLFSSL_SUCCESS) {
  7846. goto cleanup;
  7847. }
  7848. if (callbacks->loadToSSL) {
  7849. wolfSSL_SetDevId(ssl, callbacks->devId);
  7850. if (wolfSSL_use_certificate_file(ssl, callbacks->certPemFile,
  7851. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7852. goto cleanup;
  7853. }
  7854. if (wolfSSL_use_PrivateKey_file(ssl, callbacks->keyPemFile,
  7855. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7856. goto cleanup;
  7857. }
  7858. }
  7859. #ifdef NO_PSK
  7860. #if !defined(NO_FILESYSTEM) && !defined(NO_DH)
  7861. wolfSSL_SetTmpDH_file(ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  7862. #elif !defined(NO_DH)
  7863. SetDH(ssl); /* will repick suites with DHE, higher priority than PSK */
  7864. #endif
  7865. #endif
  7866. if (callbacks->ssl_ready)
  7867. callbacks->ssl_ready(ssl);
  7868. #ifdef WOLFSSL_ASYNC_CRYPT
  7869. err = 0; /* Reset error */
  7870. #endif
  7871. do {
  7872. #ifdef WOLFSSL_ASYNC_CRYPT
  7873. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7874. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7875. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7876. }
  7877. #endif
  7878. ret = wolfSSL_accept(ssl);
  7879. err = wolfSSL_get_error(ssl, ret);
  7880. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7881. if (ret != WOLFSSL_SUCCESS) {
  7882. char buff[WOLFSSL_MAX_ERROR_SZ];
  7883. fprintf(stderr, "accept error = %d, %s\n", err,
  7884. wolfSSL_ERR_error_string(err, buff));
  7885. /*err_sys("SSL_accept failed");*/
  7886. }
  7887. else {
  7888. #ifdef WOLFSSL_ASYNC_CRYPT
  7889. err = 0; /* Reset error */
  7890. #endif
  7891. do {
  7892. #ifdef WOLFSSL_ASYNC_CRYPT
  7893. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7894. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7895. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7896. }
  7897. #endif
  7898. idx = wolfSSL_read(ssl, input, sizeof(input)-1);
  7899. err = wolfSSL_get_error(ssl, idx);
  7900. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7901. if (idx > 0) {
  7902. input[idx] = 0;
  7903. fprintf(stderr, "Client message: %s\n", input);
  7904. }
  7905. #ifdef WOLFSSL_ASYNC_CRYPT
  7906. err = 0; /* Reset error */
  7907. #endif
  7908. do {
  7909. #ifdef WOLFSSL_ASYNC_CRYPT
  7910. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7911. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7912. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7913. }
  7914. #endif
  7915. ret = wolfSSL_write(ssl, msg, len);
  7916. err = wolfSSL_get_error(ssl, ret);
  7917. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7918. if (len != ret) {
  7919. goto cleanup;
  7920. }
  7921. #if defined(WOLFSSL_SESSION_EXPORT) && !defined(HAVE_IO_POOL) && \
  7922. defined(WOLFSSL_DTLS)
  7923. if (wolfSSL_dtls(ssl)) {
  7924. byte* import;
  7925. word32 sz;
  7926. wolfSSL_dtls_export(ssl, NULL, &sz);
  7927. import = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  7928. if (import == NULL) {
  7929. goto cleanup;
  7930. }
  7931. idx = wolfSSL_dtls_export(ssl, import, &sz);
  7932. if (idx < 0) {
  7933. goto cleanup;
  7934. }
  7935. if (wolfSSL_dtls_import(ssl, import, idx) < 0) {
  7936. goto cleanup;
  7937. }
  7938. XFREE(import, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  7939. }
  7940. #endif
  7941. #ifdef WOLFSSL_TIRTOS
  7942. Task_yield();
  7943. #endif
  7944. ((func_args*)args)->return_code = TEST_SUCCESS;
  7945. }
  7946. if (callbacks->on_result)
  7947. callbacks->on_result(ssl);
  7948. wolfSSL_shutdown(ssl);
  7949. cleanup:
  7950. wolfSSL_free(ssl);
  7951. wolfSSL_CTX_free(ctx);
  7952. CloseSocket(cfd);
  7953. #ifdef WOLFSSL_TIRTOS
  7954. fdCloseSession(Task_self());
  7955. #endif
  7956. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  7957. && defined(HAVE_THREAD_LS)
  7958. wc_ecc_fp_free(); /* free per thread cache */
  7959. #endif
  7960. WOLFSSL_RETURN_FROM_THREAD(0);
  7961. }
  7962. /* TLS Client for API unit testing - generic */
  7963. static void run_wolfssl_client(void* args)
  7964. {
  7965. callback_functions* callbacks = ((func_args*)args)->callbacks;
  7966. WOLFSSL_CTX* ctx = NULL;
  7967. WOLFSSL* ssl = NULL;
  7968. SOCKET_T sfd = 0;
  7969. char msg[] = "hello wolfssl server!";
  7970. int len = (int) XSTRLEN(msg);
  7971. char input[1024];
  7972. int ret, err = 0;
  7973. ((func_args*)args)->return_code = TEST_FAIL;
  7974. /* set defaults */
  7975. if (callbacks->caPemFile == NULL)
  7976. callbacks->caPemFile = caCertFile;
  7977. if (callbacks->certPemFile == NULL)
  7978. callbacks->certPemFile = cliCertFile;
  7979. if (callbacks->keyPemFile == NULL)
  7980. callbacks->keyPemFile = cliKeyFile;
  7981. #ifdef WOLFSSL_STATIC_MEMORY
  7982. if (callbacks->method_ex != NULL && callbacks->mem != NULL &&
  7983. callbacks->memSz > 0) {
  7984. ret = wolfSSL_CTX_load_static_memory(&ctx, callbacks->method_ex,
  7985. callbacks->mem, callbacks->memSz, 0, 1);
  7986. if (ret != WOLFSSL_SUCCESS) {
  7987. fprintf(stderr, "CTX static new failed %d\n", ret);
  7988. goto cleanup;
  7989. }
  7990. }
  7991. #else
  7992. ctx = wolfSSL_CTX_new(callbacks->method());
  7993. #endif
  7994. if (ctx == NULL) {
  7995. fprintf(stderr, "CTX new failed\n");
  7996. goto cleanup;
  7997. }
  7998. #ifdef WOLFSSL_TIRTOS
  7999. fdOpenSession(Task_self());
  8000. #endif
  8001. if (!callbacks->loadToSSL) {
  8002. wolfSSL_CTX_SetDevId(ctx, callbacks->devId);
  8003. }
  8004. #ifdef WOLFSSL_ENCRYPTED_KEYS
  8005. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  8006. #endif
  8007. if (wolfSSL_CTX_load_verify_locations(ctx, callbacks->caPemFile, 0) !=
  8008. WOLFSSL_SUCCESS) {
  8009. goto cleanup;
  8010. }
  8011. if (!callbacks->loadToSSL) {
  8012. if (wolfSSL_CTX_use_certificate_file(ctx, callbacks->certPemFile,
  8013. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  8014. goto cleanup;
  8015. }
  8016. if (wolfSSL_CTX_use_PrivateKey_file(ctx, callbacks->keyPemFile,
  8017. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  8018. goto cleanup;
  8019. }
  8020. }
  8021. #ifdef HAVE_CRL
  8022. if (callbacks->crlPemFile != NULL) {
  8023. if (wolfSSL_CTX_LoadCRLFile(ctx, callbacks->crlPemFile,
  8024. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  8025. goto cleanup;
  8026. }
  8027. }
  8028. #endif
  8029. if (callbacks->ctx_ready)
  8030. callbacks->ctx_ready(ctx);
  8031. ssl = wolfSSL_new(ctx);
  8032. if (wolfSSL_dtls(ssl)) {
  8033. tcp_connect(&sfd, wolfSSLIP, ((func_args*)args)->signal->port,
  8034. 1, 0, ssl);
  8035. }
  8036. else {
  8037. tcp_connect(&sfd, wolfSSLIP, ((func_args*)args)->signal->port,
  8038. 0, 0, ssl);
  8039. }
  8040. if (wolfSSL_set_fd(ssl, sfd) != WOLFSSL_SUCCESS) {
  8041. goto cleanup;
  8042. }
  8043. if (callbacks->loadToSSL) {
  8044. wolfSSL_SetDevId(ssl, callbacks->devId);
  8045. if (wolfSSL_use_certificate_file(ssl, callbacks->certPemFile,
  8046. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  8047. goto cleanup;
  8048. }
  8049. if (wolfSSL_use_PrivateKey_file(ssl, callbacks->keyPemFile,
  8050. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  8051. goto cleanup;
  8052. }
  8053. }
  8054. if (callbacks->ssl_ready)
  8055. callbacks->ssl_ready(ssl);
  8056. #ifdef WOLFSSL_ASYNC_CRYPT
  8057. err = 0; /* Reset error */
  8058. #endif
  8059. do {
  8060. #ifdef WOLFSSL_ASYNC_CRYPT
  8061. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  8062. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  8063. if (ret < 0) { break; } else if (ret == 0) { continue; }
  8064. }
  8065. #endif
  8066. ret = wolfSSL_connect(ssl);
  8067. err = wolfSSL_get_error(ssl, ret);
  8068. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  8069. if (ret != WOLFSSL_SUCCESS) {
  8070. char buff[WOLFSSL_MAX_ERROR_SZ];
  8071. fprintf(stderr, "error = %d, %s\n", err,
  8072. wolfSSL_ERR_error_string(err, buff));
  8073. /*err_sys("SSL_connect failed");*/
  8074. }
  8075. else {
  8076. #ifdef WOLFSSL_ASYNC_CRYPT
  8077. err = 0; /* Reset error */
  8078. #endif
  8079. do {
  8080. #ifdef WOLFSSL_ASYNC_CRYPT
  8081. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  8082. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  8083. if (ret < 0) { break; } else if (ret == 0) { continue; }
  8084. }
  8085. #endif
  8086. ret = wolfSSL_write(ssl, msg, len);
  8087. err = wolfSSL_get_error(ssl, ret);
  8088. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  8089. if (len != ret)
  8090. goto cleanup;
  8091. #ifdef WOLFSSL_ASYNC_CRYPT
  8092. err = 0; /* Reset error */
  8093. #endif
  8094. do {
  8095. #ifdef WOLFSSL_ASYNC_CRYPT
  8096. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  8097. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  8098. if (ret < 0) { break; } else if (ret == 0) { continue; }
  8099. }
  8100. #endif
  8101. ret = wolfSSL_read(ssl, input, sizeof(input)-1);
  8102. err = wolfSSL_get_error(ssl, ret);
  8103. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  8104. if (ret > 0) {
  8105. input[ret] = '\0'; /* null term */
  8106. fprintf(stderr, "Server response: %s\n", input);
  8107. }
  8108. ((func_args*)args)->return_code = TEST_SUCCESS;
  8109. }
  8110. if (callbacks->on_result)
  8111. callbacks->on_result(ssl);
  8112. cleanup:
  8113. wolfSSL_free(ssl);
  8114. wolfSSL_CTX_free(ctx);
  8115. CloseSocket(sfd);
  8116. #ifdef WOLFSSL_TIRTOS
  8117. fdCloseSession(Task_self());
  8118. #endif
  8119. }
  8120. #endif /* ENABLE_TLS_CALLBACK_TEST */
  8121. static int test_wolfSSL_read_write(void)
  8122. {
  8123. /* The unit testing for read and write shall happen simultaneously, since
  8124. * one can't do anything with one without the other. (Except for a failure
  8125. * test case.) This function will call all the others that will set up,
  8126. * execute, and report their test findings.
  8127. *
  8128. * Set up the success case first. This function will become the template
  8129. * for the other tests. This should eventually be renamed
  8130. *
  8131. * The success case isn't interesting, how can this fail?
  8132. * - Do not give the client context a CA certificate. The connect should
  8133. * fail. Do not need server for this?
  8134. * - Using NULL for the ssl object on server. Do not need client for this.
  8135. * - Using NULL for the ssl object on client. Do not need server for this.
  8136. * - Good ssl objects for client and server. Client write() without server
  8137. * read().
  8138. * - Good ssl objects for client and server. Server write() without client
  8139. * read().
  8140. * - Forgetting the password callback?
  8141. */
  8142. tcp_ready ready;
  8143. func_args client_args;
  8144. func_args server_args;
  8145. THREAD_TYPE serverThread;
  8146. EXPECT_DECLS;
  8147. XMEMSET(&client_args, 0, sizeof(func_args));
  8148. XMEMSET(&server_args, 0, sizeof(func_args));
  8149. #ifdef WOLFSSL_TIRTOS
  8150. fdOpenSession(Task_self());
  8151. #endif
  8152. StartTCP();
  8153. InitTcpReady(&ready);
  8154. #if defined(USE_WINDOWS_API)
  8155. /* use RNG to get random port if using windows */
  8156. ready.port = GetRandomPort();
  8157. #endif
  8158. server_args.signal = &ready;
  8159. client_args.signal = &ready;
  8160. start_thread(test_server_nofail, &server_args, &serverThread);
  8161. wait_tcp_ready(&server_args);
  8162. test_client_nofail(&client_args, NULL);
  8163. join_thread(serverThread);
  8164. ExpectTrue(client_args.return_code);
  8165. ExpectTrue(server_args.return_code);
  8166. FreeTcpReady(&ready);
  8167. #ifdef WOLFSSL_TIRTOS
  8168. fdOpenSession(Task_self());
  8169. #endif
  8170. return EXPECT_RESULT();
  8171. }
  8172. static int test_wolfSSL_reuse_WOLFSSLobj(void)
  8173. {
  8174. EXPECT_DECLS;
  8175. #if defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) && \
  8176. !defined(WOLFSSL_NO_TLS12)
  8177. /* The unit test for session resumption by re-using WOLFSSL object.
  8178. * WOLFSSL object is not cleared after first session. It reuse the object
  8179. * for second connection.
  8180. */
  8181. tcp_ready ready;
  8182. func_args client_args;
  8183. func_args server_args;
  8184. THREAD_TYPE serverThread;
  8185. callback_functions client_cbf;
  8186. callback_functions server_cbf;
  8187. XMEMSET(&client_args, 0, sizeof(func_args));
  8188. XMEMSET(&server_args, 0, sizeof(func_args));
  8189. XMEMSET(&client_cbf, 0, sizeof(callback_functions));
  8190. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  8191. #ifdef WOLFSSL_TIRTOS
  8192. fdOpenSession(Task_self());
  8193. #endif
  8194. StartTCP();
  8195. InitTcpReady(&ready);
  8196. #if defined(USE_WINDOWS_API)
  8197. /* use RNG to get random port if using windows */
  8198. ready.port = GetRandomPort();
  8199. #endif
  8200. client_cbf.method = wolfTLSv1_2_client_method;
  8201. server_cbf.method = wolfTLSv1_2_server_method;
  8202. client_args.callbacks = &client_cbf;
  8203. server_args.callbacks = &server_cbf;
  8204. server_args.signal = &ready;
  8205. client_args.signal = &ready;
  8206. /* the var is used for loop number */
  8207. server_args.argc = 2;
  8208. start_thread(test_server_loop, &server_args, &serverThread);
  8209. wait_tcp_ready(&server_args);
  8210. test_client_reuse_WOLFSSLobj(&client_args, NULL, &server_args);
  8211. join_thread(serverThread);
  8212. ExpectTrue(client_args.return_code);
  8213. ExpectTrue(server_args.return_code);
  8214. FreeTcpReady(&ready);
  8215. #ifdef WOLFSSL_TIRTOS
  8216. fdOpenSession(Task_self());
  8217. #endif
  8218. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) &&
  8219. * !defined(WOLFSSL_TLS13) */
  8220. return EXPECT_RESULT();
  8221. }
  8222. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8223. static int test_wolfSSL_CTX_verifyDepth_ServerClient_1_ctx_ready(
  8224. WOLFSSL_CTX* ctx)
  8225. {
  8226. wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, myVerify);
  8227. myVerifyAction = VERIFY_USE_PREVERFIY;
  8228. wolfSSL_CTX_set_verify_depth(ctx, 2);
  8229. return TEST_SUCCESS;
  8230. }
  8231. #endif
  8232. static int test_wolfSSL_CTX_verifyDepth_ServerClient_1(void)
  8233. {
  8234. EXPECT_DECLS;
  8235. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8236. test_ssl_cbf client_cbf;
  8237. test_ssl_cbf server_cbf;
  8238. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  8239. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  8240. #ifdef WOLFSSL_TLS13
  8241. client_cbf.method = wolfTLSv1_3_client_method;
  8242. #endif /* WOLFSSL_TLS13 */
  8243. client_cbf.ctx_ready =
  8244. test_wolfSSL_CTX_verifyDepth_ServerClient_1_ctx_ready;
  8245. /* test case 1 verify depth is equal to peer chain */
  8246. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  8247. &server_cbf, NULL), TEST_SUCCESS);
  8248. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  8249. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  8250. #endif /* OPENSSL_EXTRA && HAVE_SSL_MEMIO_TESTS_DEPENDENCIES */
  8251. return EXPECT_RESULT();
  8252. }
  8253. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8254. static int test_wolfSSL_CTX_verifyDepth_ServerClient_2_ctx_ready(
  8255. WOLFSSL_CTX* ctx)
  8256. {
  8257. wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, myVerify);
  8258. myVerifyAction = VERIFY_OVERRIDE_ERROR;
  8259. wolfSSL_CTX_set_verify_depth(ctx, 0);
  8260. return TEST_SUCCESS;
  8261. }
  8262. #endif
  8263. static int test_wolfSSL_CTX_verifyDepth_ServerClient_2(void)
  8264. {
  8265. EXPECT_DECLS;
  8266. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8267. test_ssl_cbf client_cbf;
  8268. test_ssl_cbf server_cbf;
  8269. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  8270. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  8271. #ifdef WOLFSSL_TLS13
  8272. client_cbf.method = wolfTLSv1_3_client_method;
  8273. #endif /* WOLFSSL_TLS13 */
  8274. client_cbf.ctx_ready =
  8275. test_wolfSSL_CTX_verifyDepth_ServerClient_2_ctx_ready;
  8276. /* test case 2
  8277. * verify depth is zero, number of peer's chain is 2.
  8278. * verify result becomes MAX_CHAIN_ERROR, but it is overridden in
  8279. * callback.
  8280. */
  8281. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  8282. &server_cbf, NULL), TEST_SUCCESS);
  8283. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  8284. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  8285. #endif /* OPENSSL_EXTRA && HAVE_SSL_MEMIO_TESTS_DEPENDENCIES */
  8286. return EXPECT_RESULT();
  8287. }
  8288. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8289. static int test_wolfSSL_CTX_verifyDepth_ServerClient_3_ctx_ready(
  8290. WOLFSSL_CTX* ctx)
  8291. {
  8292. wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, myVerify);
  8293. myVerifyAction = VERIFY_USE_PREVERFIY;
  8294. wolfSSL_CTX_set_verify_depth(ctx, 0);
  8295. return TEST_SUCCESS;
  8296. }
  8297. #endif
  8298. static int test_wolfSSL_CTX_verifyDepth_ServerClient_3(void)
  8299. {
  8300. EXPECT_DECLS;
  8301. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8302. test_ssl_cbf client_cbf;
  8303. test_ssl_cbf server_cbf;
  8304. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  8305. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  8306. #ifdef WOLFSSL_TLS13
  8307. client_cbf.method = wolfTLSv1_3_client_method;
  8308. #endif /* WOLFSSL_TLS13 */
  8309. client_cbf.ctx_ready =
  8310. test_wolfSSL_CTX_verifyDepth_ServerClient_3_ctx_ready;
  8311. /* test case 3
  8312. * verify depth is zero, number of peer's chain is 2
  8313. * verify result becomes MAX_CHAIN_ERRO. call-back returns failure.
  8314. * therefore, handshake becomes failure.
  8315. */
  8316. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  8317. &server_cbf, NULL), -1001);
  8318. ExpectIntEQ(client_cbf.return_code, -1000);
  8319. ExpectIntEQ(server_cbf.return_code, -1000);
  8320. ExpectIntEQ(client_cbf.last_err, WC_NO_ERR_TRACE(MAX_CHAIN_ERROR));
  8321. ExpectIntEQ(server_cbf.last_err, WC_NO_ERR_TRACE(FATAL_ERROR));
  8322. #endif /* OPENSSL_EXTRA && HAVE_SSL_MEMIO_TESTS_DEPENDENCIES */
  8323. return EXPECT_RESULT();
  8324. }
  8325. #if defined(OPENSSL_ALL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  8326. !defined(WOLFSSL_NO_TLS12) && \
  8327. defined(HAVE_ECC) && !defined(NO_AES) && !defined(NO_SHA256)
  8328. static int test_wolfSSL_CTX_set_cipher_list_server_ctx_ready(WOLFSSL_CTX* ctx)
  8329. {
  8330. EXPECT_DECLS;
  8331. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx, "DEFAULT:!NULL"));
  8332. return EXPECT_RESULT();
  8333. }
  8334. static int test_wolfSSL_CTX_set_cipher_list_client_ctx_ready(WOLFSSL_CTX* ctx)
  8335. {
  8336. EXPECT_DECLS;
  8337. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx, "ECDHE-RSA-AES128-SHA256"));
  8338. return EXPECT_RESULT();
  8339. }
  8340. #endif
  8341. static int test_wolfSSL_CTX_set_cipher_list(void)
  8342. {
  8343. EXPECT_DECLS;
  8344. #if defined(OPENSSL_ALL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  8345. defined(HAVE_ECC) && !defined(NO_AES) && !defined(NO_SHA256)
  8346. #if !defined(WOLFSSL_NO_TLS12)
  8347. WOLFSSL_CTX* ctxClient = NULL;
  8348. WOLFSSL* sslClient = NULL;
  8349. test_ssl_cbf client_cbf;
  8350. test_ssl_cbf server_cbf;
  8351. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  8352. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  8353. server_cbf.method = wolfTLSv1_2_server_method;
  8354. server_cbf.ctx_ready = test_wolfSSL_CTX_set_cipher_list_server_ctx_ready;
  8355. client_cbf.method = wolfTLSv1_2_client_method;
  8356. client_cbf.ctx_ready = test_wolfSSL_CTX_set_cipher_list_client_ctx_ready;
  8357. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  8358. &server_cbf, NULL), TEST_SUCCESS);
  8359. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  8360. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  8361. /* check with cipher string that has '+' */
  8362. ExpectNotNull((ctxClient = wolfSSL_CTX_new(wolfTLSv1_2_client_method())));
  8363. /* Use trailing : with nothing to test for ASAN */
  8364. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctxClient, "ECDHE+AESGCM:"));
  8365. ExpectNotNull((sslClient = wolfSSL_new(ctxClient)));
  8366. /* check for the existence of an ECDHE ECDSA cipher suite */
  8367. if (EXPECT_SUCCESS()) {
  8368. int i = 0;
  8369. int found = 0;
  8370. const char* suite;
  8371. WOLF_STACK_OF(WOLFSSL_CIPHER)* sk = NULL;
  8372. WOLFSSL_CIPHER* current;
  8373. ExpectNotNull((sk = wolfSSL_get_ciphers_compat(sslClient)));
  8374. do {
  8375. current = wolfSSL_sk_SSL_CIPHER_value(sk, i++);
  8376. if (current) {
  8377. suite = wolfSSL_CIPHER_get_name(current);
  8378. if (suite && XSTRSTR(suite, "ECDSA")) {
  8379. found = 1;
  8380. break;
  8381. }
  8382. }
  8383. } while (current);
  8384. ExpectIntEQ(found, 1);
  8385. }
  8386. wolfSSL_free(sslClient);
  8387. wolfSSL_CTX_free(ctxClient);
  8388. #endif /* !WOLFSSL_NO_TLS12 */
  8389. #endif
  8390. return EXPECT_RESULT();
  8391. }
  8392. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  8393. defined(WOLFSSL_HAVE_TLS_UNIQUE)
  8394. static int test_wolfSSL_get_finished_client_on_handshake(WOLFSSL_CTX* ctx,
  8395. WOLFSSL* ssl)
  8396. {
  8397. EXPECT_DECLS;
  8398. size_t msg_len;
  8399. (void)ctx;
  8400. /* get_finished test */
  8401. /* 1. get own sent message */
  8402. XMEMSET(client_side_msg1, 0, MD_MAX_SIZE);
  8403. msg_len = wolfSSL_get_finished(ssl, client_side_msg1, MD_MAX_SIZE);
  8404. ExpectIntGE(msg_len, 0);
  8405. /* 2. get peer message */
  8406. XMEMSET(client_side_msg2, 0, MD_MAX_SIZE);
  8407. msg_len = wolfSSL_get_peer_finished(ssl, client_side_msg2, MD_MAX_SIZE);
  8408. ExpectIntGE(msg_len, 0);
  8409. return EXPECT_RESULT();
  8410. }
  8411. #endif
  8412. static int test_wolfSSL_get_finished(void)
  8413. {
  8414. EXPECT_DECLS;
  8415. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  8416. defined(WOLFSSL_HAVE_TLS_UNIQUE)
  8417. test_ssl_cbf client_cbf;
  8418. test_ssl_cbf server_cbf;
  8419. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  8420. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  8421. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  8422. &server_cbf, test_wolfSSL_get_finished_client_on_handshake),
  8423. TEST_SUCCESS);
  8424. /* test received msg vs sent msg */
  8425. ExpectIntEQ(0, XMEMCMP(client_side_msg1, server_side_msg2, MD_MAX_SIZE));
  8426. ExpectIntEQ(0, XMEMCMP(client_side_msg2, server_side_msg1, MD_MAX_SIZE));
  8427. #endif /* HAVE_SSL_MEMIO_TESTS_DEPENDENCIES && WOLFSSL_HAVE_TLS_UNIQUE */
  8428. return EXPECT_RESULT();
  8429. }
  8430. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  8431. !defined(SINGLE_THREADED) && defined(WOLFSSL_TLS13) && \
  8432. !defined(NO_SESSION_CACHE)
  8433. /* Sessions to restore/store */
  8434. static WOLFSSL_SESSION* test_wolfSSL_CTX_add_session_client_sess;
  8435. static WOLFSSL_SESSION* test_wolfSSL_CTX_add_session_server_sess;
  8436. static WOLFSSL_CTX* test_wolfSSL_CTX_add_session_server_ctx;
  8437. static void test_wolfSSL_CTX_add_session_ctx_ready(WOLFSSL_CTX* ctx)
  8438. {
  8439. /* Don't store sessions. Lookup is still enabled. */
  8440. AssertIntEQ(wolfSSL_CTX_set_session_cache_mode(ctx,
  8441. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE), WOLFSSL_SUCCESS);
  8442. #ifdef OPENSSL_EXTRA
  8443. AssertIntEQ(wolfSSL_CTX_get_session_cache_mode(ctx) &
  8444. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE,
  8445. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE);
  8446. #endif
  8447. /* Require both peers to provide certs */
  8448. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8449. }
  8450. static void test_wolfSSL_CTX_add_session_on_result(WOLFSSL* ssl)
  8451. {
  8452. WOLFSSL_SESSION** sess;
  8453. if (wolfSSL_is_server(ssl))
  8454. sess = &test_wolfSSL_CTX_add_session_server_sess;
  8455. else
  8456. sess = &test_wolfSSL_CTX_add_session_client_sess;
  8457. if (*sess == NULL) {
  8458. #ifdef NO_SESSION_CACHE_REF
  8459. AssertNotNull(*sess = wolfSSL_get1_session(ssl));
  8460. #else
  8461. /* Test for backwards compatibility */
  8462. if (wolfSSL_is_server(ssl)) {
  8463. AssertNotNull(*sess = wolfSSL_get1_session(ssl));
  8464. }
  8465. else {
  8466. AssertNotNull(*sess = wolfSSL_get_session(ssl));
  8467. }
  8468. #endif
  8469. /* Now save the session in the internal store to make it available
  8470. * for lookup. For TLS 1.3, we can't save the session without
  8471. * WOLFSSL_TICKET_HAVE_ID because there is no way to retrieve the
  8472. * session from cache. */
  8473. if (wolfSSL_is_server(ssl)
  8474. #ifndef WOLFSSL_TICKET_HAVE_ID
  8475. && wolfSSL_version(ssl) != TLS1_3_VERSION
  8476. #endif
  8477. )
  8478. AssertIntEQ(wolfSSL_CTX_add_session(wolfSSL_get_SSL_CTX(ssl),
  8479. *sess), WOLFSSL_SUCCESS);
  8480. }
  8481. else {
  8482. /* If we have a session retrieved then remaining connections should be
  8483. * resuming on that session */
  8484. AssertIntEQ(wolfSSL_session_reused(ssl), 1);
  8485. }
  8486. /* Save CTX to be able to decrypt tickets */
  8487. if (wolfSSL_is_server(ssl) &&
  8488. test_wolfSSL_CTX_add_session_server_ctx == NULL) {
  8489. AssertNotNull(test_wolfSSL_CTX_add_session_server_ctx
  8490. = wolfSSL_get_SSL_CTX(ssl));
  8491. AssertIntEQ(wolfSSL_CTX_up_ref(wolfSSL_get_SSL_CTX(ssl)),
  8492. WOLFSSL_SUCCESS);
  8493. }
  8494. #ifdef SESSION_CERTS
  8495. #ifndef WOLFSSL_TICKET_HAVE_ID
  8496. if (wolfSSL_version(ssl) != TLS1_3_VERSION &&
  8497. wolfSSL_session_reused(ssl))
  8498. #endif
  8499. {
  8500. /* With WOLFSSL_TICKET_HAVE_ID the peer certs should be available
  8501. * for all connections. TLS 1.3 only has tickets so if we don't
  8502. * include the session id in the ticket then the certificates
  8503. * will not be available on resumption. */
  8504. WOLFSSL_X509* peer = wolfSSL_get_peer_certificate(ssl);
  8505. AssertNotNull(peer);
  8506. wolfSSL_X509_free(peer);
  8507. AssertNotNull(wolfSSL_SESSION_get_peer_chain(*sess));
  8508. #ifdef OPENSSL_EXTRA
  8509. AssertNotNull(SSL_SESSION_get0_peer(*sess));
  8510. #endif
  8511. }
  8512. #endif /* SESSION_CERTS */
  8513. }
  8514. static void test_wolfSSL_CTX_add_session_ssl_ready(WOLFSSL* ssl)
  8515. {
  8516. /* Set the session to reuse for the client */
  8517. AssertIntEQ(wolfSSL_set_session(ssl,
  8518. test_wolfSSL_CTX_add_session_client_sess), WOLFSSL_SUCCESS);
  8519. }
  8520. #endif
  8521. static int test_wolfSSL_CTX_add_session(void)
  8522. {
  8523. EXPECT_DECLS;
  8524. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  8525. !defined(SINGLE_THREADED) && defined(WOLFSSL_TLS13) && \
  8526. !defined(NO_SESSION_CACHE)
  8527. tcp_ready ready;
  8528. func_args client_args;
  8529. func_args server_args;
  8530. THREAD_TYPE serverThread;
  8531. callback_functions client_cb;
  8532. callback_functions server_cb;
  8533. method_provider methods[][2] = {
  8534. #if !defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \
  8535. !defined(NO_DES3))
  8536. /* Without AES there are almost no ciphersuites available. This leads
  8537. * to no ciphersuites being available and an error. */
  8538. { wolfTLSv1_1_client_method, wolfTLSv1_1_server_method },
  8539. #endif
  8540. #ifndef WOLFSSL_NO_TLS12
  8541. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method },
  8542. #endif
  8543. /* Needs the default ticket callback since it is tied to the
  8544. * connection context and this makes it easy to carry over the ticket
  8545. * crypto context between connections */
  8546. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  8547. defined(HAVE_SESSION_TICKET)
  8548. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method },
  8549. #endif
  8550. };
  8551. const size_t methodsLen = sizeof(methods)/sizeof(*methods);
  8552. size_t i, j;
  8553. for (i = 0; i < methodsLen; i++) {
  8554. /* First run creates a connection while the second+ run will attempt
  8555. * to resume the connection. The trick is that the internal cache
  8556. * is turned off. wolfSSL_CTX_add_session should put the session in
  8557. * the cache anyway. */
  8558. test_wolfSSL_CTX_add_session_client_sess = NULL;
  8559. test_wolfSSL_CTX_add_session_server_sess = NULL;
  8560. test_wolfSSL_CTX_add_session_server_ctx = NULL;
  8561. #ifdef NO_SESSION_CACHE_REF
  8562. for (j = 0; j < 4; j++) {
  8563. #else
  8564. /* The session may be overwritten in this case. Do only one resumption
  8565. * to stop this test from failing intermittently. */
  8566. for (j = 0; j < 2; j++) {
  8567. #endif
  8568. #ifdef WOLFSSL_TIRTOS
  8569. fdOpenSession(Task_self());
  8570. #endif
  8571. StartTCP();
  8572. InitTcpReady(&ready);
  8573. XMEMSET(&client_args, 0, sizeof(func_args));
  8574. XMEMSET(&server_args, 0, sizeof(func_args));
  8575. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  8576. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  8577. client_cb.method = methods[i][0];
  8578. server_cb.method = methods[i][1];
  8579. server_args.signal = &ready;
  8580. server_args.callbacks = &server_cb;
  8581. client_args.signal = &ready;
  8582. client_args.callbacks = &client_cb;
  8583. if (test_wolfSSL_CTX_add_session_server_ctx != NULL) {
  8584. server_cb.ctx = test_wolfSSL_CTX_add_session_server_ctx;
  8585. server_cb.isSharedCtx = 1;
  8586. }
  8587. server_cb.ctx_ready = test_wolfSSL_CTX_add_session_ctx_ready;
  8588. client_cb.ctx_ready = test_wolfSSL_CTX_add_session_ctx_ready;
  8589. if (j != 0)
  8590. client_cb.ssl_ready = test_wolfSSL_CTX_add_session_ssl_ready;
  8591. server_cb.on_result = test_wolfSSL_CTX_add_session_on_result;
  8592. client_cb.on_result = test_wolfSSL_CTX_add_session_on_result;
  8593. server_cb.ticNoInit = 1; /* Use default builtin */
  8594. start_thread(test_server_nofail, &server_args, &serverThread);
  8595. wait_tcp_ready(&server_args);
  8596. test_client_nofail(&client_args, NULL);
  8597. join_thread(serverThread);
  8598. ExpectTrue(client_args.return_code);
  8599. ExpectTrue(server_args.return_code);
  8600. FreeTcpReady(&ready);
  8601. if (EXPECT_FAIL())
  8602. break;
  8603. }
  8604. wolfSSL_SESSION_free(test_wolfSSL_CTX_add_session_client_sess);
  8605. wolfSSL_SESSION_free(test_wolfSSL_CTX_add_session_server_sess);
  8606. wolfSSL_CTX_free(test_wolfSSL_CTX_add_session_server_ctx);
  8607. if (EXPECT_FAIL())
  8608. break;
  8609. }
  8610. #endif
  8611. return EXPECT_RESULT();
  8612. }
  8613. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  8614. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  8615. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  8616. defined(HAVE_SESSION_TICKET) && \
  8617. !defined(TITAN_SESSION_CACHE) && \
  8618. !defined(HUGE_SESSION_CACHE) && \
  8619. !defined(BIG_SESSION_CACHE) && \
  8620. !defined(MEDIUM_SESSION_CACHE)
  8621. /* twcase - prefix for test_wolfSSL_CTX_add_session_ext */
  8622. /* Sessions to restore/store */
  8623. static WOLFSSL_SESSION* twcase_server_first_session_ptr;
  8624. static WOLFSSL_SESSION* twcase_client_first_session_ptr;
  8625. static WOLFSSL_CTX* twcase_server_current_ctx_ptr;
  8626. static int twcase_new_session_called = 0;
  8627. static int twcase_remove_session_called = 0;
  8628. static int twcase_get_session_called = 0;
  8629. /* Test default, SESSIONS_PER_ROW*SESSION_ROWS = 3*11, see ssl.c */
  8630. #define SESSION_CACHE_SIZE 33
  8631. typedef struct {
  8632. const byte* key; /* key, altSessionID, session ID, NULL if empty */
  8633. WOLFSSL_SESSION* value;
  8634. } hashTable_entry;
  8635. typedef struct {
  8636. hashTable_entry entries[SESSION_CACHE_SIZE]; /* hash slots */
  8637. size_t capacity; /* size of entries */
  8638. size_t length; /* number of items in the hash table */
  8639. wolfSSL_Mutex htLock; /* lock */
  8640. }hashTable;
  8641. static hashTable server_sessionCache;
  8642. static int twcase_new_sessionCb(WOLFSSL *ssl, WOLFSSL_SESSION *sess)
  8643. {
  8644. int i;
  8645. unsigned int len;
  8646. (void)ssl;
  8647. /*
  8648. * This example uses a hash table.
  8649. * Steps you should take for a non-demo code:
  8650. * - acquire a lock for the file named according to the session id
  8651. * - open the file
  8652. * - encrypt and write the SSL_SESSION object to the file
  8653. * - release the lock
  8654. *
  8655. * Return:
  8656. * 0: The callback does not wish to hold a reference of the sess
  8657. * 1: The callback wants to hold a reference of the sess. The callback is
  8658. * now also responsible for calling wolfSSL_SESSION_free() on sess.
  8659. */
  8660. if (sess == NULL)
  8661. return 0;
  8662. if (wc_LockMutex(&server_sessionCache.htLock) != 0) {
  8663. return 0;
  8664. }
  8665. for (i = 0; i < SESSION_CACHE_SIZE; i++) {
  8666. if (server_sessionCache.entries[i].value == NULL) {
  8667. server_sessionCache.entries[i].key = SSL_SESSION_get_id(sess, &len);
  8668. server_sessionCache.entries[i].value = sess;
  8669. server_sessionCache.length++;
  8670. break;
  8671. }
  8672. }
  8673. ++twcase_new_session_called;
  8674. wc_UnLockMutex(&server_sessionCache.htLock);
  8675. fprintf(stderr, "\t\ttwcase_new_session_called %d\n",
  8676. twcase_new_session_called);
  8677. return 1;
  8678. }
  8679. static void twcase_remove_sessionCb(WOLFSSL_CTX *ctx, WOLFSSL_SESSION *sess)
  8680. {
  8681. int i;
  8682. (void)ctx;
  8683. (void)sess;
  8684. if (sess == NULL)
  8685. return;
  8686. /*
  8687. * This example uses a hash table.
  8688. * Steps you should take for a non-demo code:
  8689. * - acquire a lock for the file named according to the session id
  8690. * - remove the file
  8691. * - release the lock
  8692. */
  8693. if (wc_LockMutex(&server_sessionCache.htLock) != 0) {
  8694. return;
  8695. }
  8696. for (i = 0; i < SESSION_CACHE_SIZE; i++) {
  8697. if (server_sessionCache.entries[i].key != NULL &&
  8698. XMEMCMP(server_sessionCache.entries[i].key,
  8699. sess->sessionID, SSL_MAX_SSL_SESSION_ID_LENGTH) == 0) {
  8700. wolfSSL_SESSION_free(server_sessionCache.entries[i].value);
  8701. server_sessionCache.entries[i].value = NULL;
  8702. server_sessionCache.entries[i].key = NULL;
  8703. server_sessionCache.length--;
  8704. break;
  8705. }
  8706. }
  8707. ++twcase_remove_session_called;
  8708. wc_UnLockMutex(&server_sessionCache.htLock);
  8709. fprintf(stderr, "\t\ttwcase_remove_session_called %d\n",
  8710. twcase_remove_session_called);
  8711. }
  8712. static WOLFSSL_SESSION *twcase_get_sessionCb(WOLFSSL *ssl,
  8713. const unsigned char *id, int len, int *ref)
  8714. {
  8715. int i;
  8716. (void)ssl;
  8717. (void)id;
  8718. (void)len;
  8719. /*
  8720. * This example uses a hash table.
  8721. * Steps you should take for a non-demo code:
  8722. * - acquire a lock for the file named according to the session id in the
  8723. * 2nd arg
  8724. * - read and decrypt contents of file and create a new SSL_SESSION
  8725. * - object release the lock
  8726. * - return the new session object
  8727. */
  8728. fprintf(stderr, "\t\ttwcase_get_session_called %d\n",
  8729. ++twcase_get_session_called);
  8730. /* This callback want to retain a copy of the object. If we want wolfSSL to
  8731. * be responsible for the pointer then set to 0. */
  8732. *ref = 1;
  8733. for (i = 0; i < SESSION_CACHE_SIZE; i++) {
  8734. if (server_sessionCache.entries[i].key != NULL &&
  8735. XMEMCMP(server_sessionCache.entries[i].key, id,
  8736. SSL_MAX_SSL_SESSION_ID_LENGTH) == 0) {
  8737. return server_sessionCache.entries[i].value;
  8738. }
  8739. }
  8740. return NULL;
  8741. }
  8742. static int twcase_get_sessionCb_cleanup(void)
  8743. {
  8744. int i;
  8745. int cnt = 0;
  8746. /* If twcase_get_sessionCb sets *ref = 1, the application is responsible
  8747. * for freeing sessions */
  8748. for (i = 0; i < SESSION_CACHE_SIZE; i++) {
  8749. if (server_sessionCache.entries[i].value != NULL) {
  8750. wolfSSL_SESSION_free(server_sessionCache.entries[i].value);
  8751. cnt++;
  8752. }
  8753. }
  8754. fprintf(stderr, "\t\ttwcase_get_sessionCb_cleanup freed %d sessions\n",
  8755. cnt);
  8756. return TEST_SUCCESS;
  8757. }
  8758. static int twcase_cache_intOff_extOff(WOLFSSL_CTX* ctx)
  8759. {
  8760. EXPECT_DECLS;
  8761. /* off - Disable internal cache */
  8762. ExpectIntEQ(wolfSSL_CTX_set_session_cache_mode(ctx,
  8763. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE), WOLFSSL_SUCCESS);
  8764. #ifdef OPENSSL_EXTRA
  8765. ExpectIntEQ(wolfSSL_CTX_get_session_cache_mode(ctx) &
  8766. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE,
  8767. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE);
  8768. #endif
  8769. /* off - Do not setup external cache */
  8770. /* Require both peers to provide certs */
  8771. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8772. return EXPECT_RESULT();
  8773. }
  8774. static int twcase_cache_intOn_extOff(WOLFSSL_CTX* ctx)
  8775. {
  8776. /* on - internal cache is on by default */
  8777. /* off - Do not setup external cache */
  8778. /* Require both peers to provide certs */
  8779. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8780. return TEST_SUCCESS;
  8781. }
  8782. static int twcase_cache_intOff_extOn(WOLFSSL_CTX* ctx)
  8783. {
  8784. EXPECT_DECLS;
  8785. /* off - Disable internal cache */
  8786. ExpectIntEQ(wolfSSL_CTX_set_session_cache_mode(ctx,
  8787. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE), WOLFSSL_SUCCESS);
  8788. #ifdef OPENSSL_EXTRA
  8789. ExpectIntEQ(wolfSSL_CTX_get_session_cache_mode(ctx) &
  8790. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE,
  8791. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE);
  8792. #endif
  8793. /* on - Enable external cache */
  8794. wolfSSL_CTX_sess_set_new_cb(ctx, twcase_new_sessionCb);
  8795. wolfSSL_CTX_sess_set_remove_cb(ctx, twcase_remove_sessionCb);
  8796. wolfSSL_CTX_sess_set_get_cb(ctx, twcase_get_sessionCb);
  8797. /* Require both peers to provide certs */
  8798. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8799. return EXPECT_RESULT();
  8800. }
  8801. static int twcase_cache_intOn_extOn(WOLFSSL_CTX* ctx)
  8802. {
  8803. /* on - internal cache is on by default */
  8804. /* on - Enable external cache */
  8805. wolfSSL_CTX_sess_set_new_cb(ctx, twcase_new_sessionCb);
  8806. wolfSSL_CTX_sess_set_remove_cb(ctx, twcase_remove_sessionCb);
  8807. wolfSSL_CTX_sess_set_get_cb(ctx, twcase_get_sessionCb);
  8808. /* Require both peers to provide certs */
  8809. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8810. return TEST_SUCCESS;
  8811. }
  8812. static int twcase_cache_intOn_extOn_noTicket(WOLFSSL_CTX* ctx)
  8813. {
  8814. /* on - internal cache is on by default */
  8815. /* on - Enable external cache */
  8816. wolfSSL_CTX_sess_set_new_cb(ctx, twcase_new_sessionCb);
  8817. wolfSSL_CTX_sess_set_remove_cb(ctx, twcase_remove_sessionCb);
  8818. wolfSSL_CTX_sess_set_get_cb(ctx, twcase_get_sessionCb);
  8819. wolfSSL_CTX_set_options(ctx, WOLFSSL_OP_NO_TICKET);
  8820. /* Require both peers to provide certs */
  8821. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8822. return TEST_SUCCESS;
  8823. }
  8824. static int twcase_server_sess_ctx_pre_shutdown(WOLFSSL* ssl)
  8825. {
  8826. EXPECT_DECLS;
  8827. WOLFSSL_SESSION** sess;
  8828. if (wolfSSL_is_server(ssl))
  8829. sess = &twcase_server_first_session_ptr;
  8830. else
  8831. return TEST_SUCCESS;
  8832. if (*sess == NULL) {
  8833. ExpectNotNull(*sess = wolfSSL_get1_session(ssl));
  8834. /* Now save the session in the internal store to make it available
  8835. * for lookup. For TLS 1.3, we can't save the session without
  8836. * WOLFSSL_TICKET_HAVE_ID because there is no way to retrieve the
  8837. * session from cache. */
  8838. if (wolfSSL_is_server(ssl)
  8839. #ifndef WOLFSSL_TICKET_HAVE_ID
  8840. && wolfSSL_version(ssl) != TLS1_3_VERSION
  8841. && wolfSSL_version(ssl) != DTLS1_3_VERSION
  8842. #endif
  8843. ) {
  8844. ExpectIntEQ(wolfSSL_CTX_add_session(wolfSSL_get_SSL_CTX(ssl),
  8845. *sess), WOLFSSL_SUCCESS);
  8846. }
  8847. }
  8848. /* Save CTX to be able to decrypt tickets */
  8849. if (twcase_server_current_ctx_ptr == NULL) {
  8850. ExpectNotNull(twcase_server_current_ctx_ptr = wolfSSL_get_SSL_CTX(ssl));
  8851. ExpectIntEQ(wolfSSL_CTX_up_ref(wolfSSL_get_SSL_CTX(ssl)),
  8852. WOLFSSL_SUCCESS);
  8853. }
  8854. #ifdef SESSION_CERTS
  8855. #ifndef WOLFSSL_TICKET_HAVE_ID
  8856. if (wolfSSL_version(ssl) != TLS1_3_VERSION &&
  8857. wolfSSL_session_reused(ssl))
  8858. #endif
  8859. {
  8860. /* With WOLFSSL_TICKET_HAVE_ID the peer certs should be available
  8861. * for all connections. TLS 1.3 only has tickets so if we don't
  8862. * include the session id in the ticket then the certificates
  8863. * will not be available on resumption. */
  8864. WOLFSSL_X509* peer = NULL;
  8865. ExpectNotNull(peer = wolfSSL_get_peer_certificate(ssl));
  8866. wolfSSL_X509_free(peer);
  8867. ExpectNotNull(wolfSSL_SESSION_get_peer_chain(*sess));
  8868. }
  8869. #endif
  8870. return EXPECT_RESULT();
  8871. }
  8872. static int twcase_client_sess_ctx_pre_shutdown(WOLFSSL* ssl)
  8873. {
  8874. EXPECT_DECLS;
  8875. WOLFSSL_SESSION** sess;
  8876. sess = &twcase_client_first_session_ptr;
  8877. if (*sess == NULL) {
  8878. ExpectNotNull(*sess = wolfSSL_get1_session(ssl));
  8879. }
  8880. else {
  8881. /* If we have a session retrieved then remaining connections should be
  8882. * resuming on that session */
  8883. ExpectIntEQ(wolfSSL_session_reused(ssl), 1);
  8884. }
  8885. #ifdef SESSION_CERTS
  8886. #ifndef WOLFSSL_TICKET_HAVE_ID
  8887. if (wolfSSL_version(ssl) != TLS1_3_VERSION &&
  8888. wolfSSL_session_reused(ssl))
  8889. #endif
  8890. {
  8891. WOLFSSL_X509* peer = wolfSSL_get_peer_certificate(ssl);
  8892. ExpectNotNull(peer);
  8893. wolfSSL_X509_free(peer);
  8894. ExpectNotNull(wolfSSL_SESSION_get_peer_chain(*sess));
  8895. #ifdef OPENSSL_EXTRA
  8896. ExpectNotNull(wolfSSL_SESSION_get0_peer(*sess));
  8897. #endif
  8898. }
  8899. #endif
  8900. return EXPECT_RESULT();
  8901. }
  8902. static int twcase_client_set_sess_ssl_ready(WOLFSSL* ssl)
  8903. {
  8904. EXPECT_DECLS;
  8905. /* Set the session to reuse for the client */
  8906. ExpectNotNull(ssl);
  8907. ExpectNotNull(twcase_client_first_session_ptr);
  8908. ExpectIntEQ(wolfSSL_set_session(ssl,twcase_client_first_session_ptr),
  8909. WOLFSSL_SUCCESS);
  8910. return EXPECT_RESULT();
  8911. }
  8912. struct test_add_session_ext_params {
  8913. method_provider client_meth;
  8914. method_provider server_meth;
  8915. const char* tls_version;
  8916. };
  8917. static int test_wolfSSL_CTX_add_session_ext(
  8918. struct test_add_session_ext_params* param)
  8919. {
  8920. EXPECT_DECLS;
  8921. /* Test the default 33 sessions */
  8922. int j;
  8923. /* Clear cache before starting */
  8924. wolfSSL_CTX_flush_sessions(NULL, -1);
  8925. XMEMSET(&server_sessionCache, 0, sizeof(hashTable));
  8926. if (wc_InitMutex(&server_sessionCache.htLock) != 0)
  8927. return BAD_MUTEX_E;
  8928. server_sessionCache.capacity = SESSION_CACHE_SIZE;
  8929. fprintf(stderr, "\tBegin %s\n", param->tls_version);
  8930. for (j = 0; j < 5; j++) {
  8931. int tls13 = XSTRSTR(param->tls_version, "TLSv1_3") != NULL;
  8932. int dtls = XSTRSTR(param->tls_version, "DTLS") != NULL;
  8933. test_ssl_cbf client_cb;
  8934. test_ssl_cbf server_cb;
  8935. (void)dtls;
  8936. /* Test five cache configurations */
  8937. twcase_client_first_session_ptr = NULL;
  8938. twcase_server_first_session_ptr = NULL;
  8939. twcase_server_current_ctx_ptr = NULL;
  8940. twcase_new_session_called = 0;
  8941. twcase_remove_session_called = 0;
  8942. twcase_get_session_called = 0;
  8943. /* connection 1 - first connection */
  8944. fprintf(stderr, "\tconnect: %s: j=%d\n", param->tls_version, j);
  8945. XMEMSET(&client_cb, 0, sizeof(client_cb));
  8946. XMEMSET(&server_cb, 0, sizeof(server_cb));
  8947. client_cb.method = param->client_meth;
  8948. server_cb.method = param->server_meth;
  8949. if (dtls)
  8950. client_cb.doUdp = server_cb.doUdp = 1;
  8951. /* Setup internal and external cache */
  8952. switch (j) {
  8953. case 0:
  8954. /* SSL_OP_NO_TICKET stateful ticket case */
  8955. server_cb.ctx_ready = twcase_cache_intOn_extOn_noTicket;
  8956. break;
  8957. case 1:
  8958. server_cb.ctx_ready = twcase_cache_intOn_extOn;
  8959. break;
  8960. case 2:
  8961. server_cb.ctx_ready = twcase_cache_intOff_extOn;
  8962. break;
  8963. case 3:
  8964. server_cb.ctx_ready = twcase_cache_intOn_extOff;
  8965. break;
  8966. case 4:
  8967. server_cb.ctx_ready = twcase_cache_intOff_extOff;
  8968. break;
  8969. }
  8970. client_cb.ctx_ready = twcase_cache_intOff_extOff;
  8971. /* Add session to internal cache and save SSL session for testing */
  8972. server_cb.on_result = twcase_server_sess_ctx_pre_shutdown;
  8973. /* Save client SSL session for testing */
  8974. client_cb.on_result = twcase_client_sess_ctx_pre_shutdown;
  8975. server_cb.ticNoInit = 1; /* Use default builtin */
  8976. /* Don't free/release ctx */
  8977. server_cb.ctx = twcase_server_current_ctx_ptr;
  8978. server_cb.isSharedCtx = 1;
  8979. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb,
  8980. &server_cb, NULL), TEST_SUCCESS);
  8981. ExpectIntEQ(twcase_get_session_called, 0);
  8982. if (EXPECT_FAIL()) {
  8983. wolfSSL_SESSION_free(twcase_client_first_session_ptr);
  8984. wolfSSL_SESSION_free(twcase_server_first_session_ptr);
  8985. wolfSSL_CTX_free(twcase_server_current_ctx_ptr);
  8986. break;
  8987. }
  8988. switch (j) {
  8989. case 0:
  8990. case 1:
  8991. case 2:
  8992. /* cache cannot be searched with out a connection */
  8993. /* Add a new session */
  8994. ExpectIntEQ(twcase_new_session_called, 1);
  8995. /* In twcase_server_sess_ctx_pre_shutdown
  8996. * wolfSSL_CTX_add_session which evicts the existing session
  8997. * in cache and adds it back in */
  8998. ExpectIntLE(twcase_remove_session_called, 1);
  8999. break;
  9000. case 3:
  9001. case 4:
  9002. /* no external cache */
  9003. ExpectIntEQ(twcase_new_session_called, 0);
  9004. ExpectIntEQ(twcase_remove_session_called, 0);
  9005. break;
  9006. }
  9007. /* connection 2 - session resume */
  9008. fprintf(stderr, "\tresume: %s: j=%d\n", param->tls_version, j);
  9009. twcase_new_session_called = 0;
  9010. twcase_remove_session_called = 0;
  9011. twcase_get_session_called = 0;
  9012. server_cb.on_result = 0;
  9013. client_cb.on_result = 0;
  9014. server_cb.ticNoInit = 1; /* Use default builtin */
  9015. server_cb.ctx = twcase_server_current_ctx_ptr;
  9016. /* try session resumption */
  9017. client_cb.ssl_ready = twcase_client_set_sess_ssl_ready;
  9018. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb,
  9019. &server_cb, NULL), TEST_SUCCESS);
  9020. /* Clear cache before checking */
  9021. wolfSSL_CTX_flush_sessions(NULL, -1);
  9022. switch (j) {
  9023. case 0:
  9024. if (tls13) {
  9025. /* (D)TLSv1.3 stateful case */
  9026. /* cache hit */
  9027. /* DTLS accesses cache once for stateless parsing and
  9028. * once for stateful parsing */
  9029. ExpectIntEQ(twcase_get_session_called, !dtls ? 1 : 2);
  9030. /* (D)TLSv1.3 creates a new ticket,
  9031. * updates both internal and external cache */
  9032. ExpectIntEQ(twcase_new_session_called, 1);
  9033. /* A new session ID is created for a new ticket */
  9034. ExpectIntEQ(twcase_remove_session_called, 2);
  9035. }
  9036. else {
  9037. /* non (D)TLSv1.3 case, no update */
  9038. /* DTLS accesses cache once for stateless parsing and
  9039. * once for stateful parsing */
  9040. #ifdef WOLFSSL_DTLS_NO_HVR_ON_RESUME
  9041. ExpectIntEQ(twcase_get_session_called, !dtls ? 1 : 2);
  9042. #else
  9043. ExpectIntEQ(twcase_get_session_called, 1);
  9044. #endif
  9045. ExpectIntEQ(twcase_new_session_called, 0);
  9046. /* Called on session added in
  9047. * twcase_server_sess_ctx_pre_shutdown */
  9048. ExpectIntEQ(twcase_remove_session_called, 1);
  9049. }
  9050. break;
  9051. case 1:
  9052. if (tls13) {
  9053. /* (D)TLSv1.3 case */
  9054. /* cache hit */
  9055. ExpectIntEQ(twcase_get_session_called, 1);
  9056. /* (D)TLSv1.3 creates a new ticket,
  9057. * updates both internal and external cache */
  9058. ExpectIntEQ(twcase_new_session_called, 1);
  9059. /* Called on session added in
  9060. * twcase_server_sess_ctx_pre_shutdown and by wolfSSL */
  9061. ExpectIntEQ(twcase_remove_session_called, 1);
  9062. }
  9063. else {
  9064. /* non (D)TLSv1.3 case */
  9065. /* cache hit */
  9066. /* DTLS accesses cache once for stateless parsing and
  9067. * once for stateful parsing */
  9068. #ifdef WOLFSSL_DTLS_NO_HVR_ON_RESUME
  9069. ExpectIntEQ(twcase_get_session_called, !dtls ? 1 : 2);
  9070. #else
  9071. ExpectIntEQ(twcase_get_session_called, 1);
  9072. #endif
  9073. ExpectIntEQ(twcase_new_session_called, 0);
  9074. /* Called on session added in
  9075. * twcase_server_sess_ctx_pre_shutdown */
  9076. ExpectIntEQ(twcase_remove_session_called, 1);
  9077. }
  9078. break;
  9079. case 2:
  9080. if (tls13) {
  9081. /* (D)TLSv1.3 case */
  9082. /* cache hit */
  9083. ExpectIntEQ(twcase_get_session_called, 1);
  9084. /* (D)TLSv1.3 creates a new ticket,
  9085. * updates both internal and external cache */
  9086. ExpectIntEQ(twcase_new_session_called, 1);
  9087. /* Called on session added in
  9088. * twcase_server_sess_ctx_pre_shutdown and by wolfSSL */
  9089. ExpectIntEQ(twcase_remove_session_called, 1);
  9090. }
  9091. else {
  9092. /* non (D)TLSv1.3 case */
  9093. /* cache hit */
  9094. /* DTLS accesses cache once for stateless parsing and
  9095. * once for stateful parsing */
  9096. #ifdef WOLFSSL_DTLS_NO_HVR_ON_RESUME
  9097. ExpectIntEQ(twcase_get_session_called, !dtls ? 1 : 2);
  9098. #else
  9099. ExpectIntEQ(twcase_get_session_called, 1);
  9100. #endif
  9101. ExpectIntEQ(twcase_new_session_called, 0);
  9102. /* Called on session added in
  9103. * twcase_server_sess_ctx_pre_shutdown */
  9104. ExpectIntEQ(twcase_remove_session_called, 1);
  9105. }
  9106. break;
  9107. case 3:
  9108. case 4:
  9109. /* no external cache */
  9110. ExpectIntEQ(twcase_get_session_called, 0);
  9111. ExpectIntEQ(twcase_new_session_called, 0);
  9112. ExpectIntEQ(twcase_remove_session_called, 0);
  9113. break;
  9114. }
  9115. wolfSSL_SESSION_free(twcase_client_first_session_ptr);
  9116. wolfSSL_SESSION_free(twcase_server_first_session_ptr);
  9117. wolfSSL_CTX_free(twcase_server_current_ctx_ptr);
  9118. if (EXPECT_FAIL())
  9119. break;
  9120. }
  9121. twcase_get_sessionCb_cleanup();
  9122. XMEMSET(&server_sessionCache.entries, 0,
  9123. sizeof(server_sessionCache.entries));
  9124. fprintf(stderr, "\tEnd %s\n", param->tls_version);
  9125. wc_FreeMutex(&server_sessionCache.htLock);
  9126. return EXPECT_RESULT();
  9127. }
  9128. #endif
  9129. static int test_wolfSSL_CTX_add_session_ext_tls13(void)
  9130. {
  9131. EXPECT_DECLS;
  9132. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  9133. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  9134. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  9135. defined(HAVE_SESSION_TICKET) && \
  9136. !defined(TITAN_SESSION_CACHE) && \
  9137. !defined(HUGE_SESSION_CACHE) && \
  9138. !defined(BIG_SESSION_CACHE) && \
  9139. !defined(MEDIUM_SESSION_CACHE)
  9140. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  9141. defined(HAVE_SESSION_TICKET) && defined(WOLFSSL_TICKET_HAVE_ID)
  9142. struct test_add_session_ext_params param[1] = {
  9143. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLSv1_3" }
  9144. };
  9145. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  9146. #endif
  9147. #endif
  9148. return EXPECT_RESULT();
  9149. }
  9150. static int test_wolfSSL_CTX_add_session_ext_dtls13(void)
  9151. {
  9152. EXPECT_DECLS;
  9153. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  9154. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  9155. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  9156. defined(HAVE_SESSION_TICKET) && \
  9157. !defined(TITAN_SESSION_CACHE) && \
  9158. !defined(HUGE_SESSION_CACHE) && \
  9159. !defined(BIG_SESSION_CACHE) && \
  9160. !defined(MEDIUM_SESSION_CACHE)
  9161. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  9162. defined(HAVE_SESSION_TICKET) && defined(WOLFSSL_TICKET_HAVE_ID)
  9163. #ifdef WOLFSSL_DTLS13
  9164. struct test_add_session_ext_params param[1] = {
  9165. { wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, "DTLSv1_3" }
  9166. };
  9167. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  9168. #endif
  9169. #endif
  9170. #endif
  9171. return EXPECT_RESULT();
  9172. }
  9173. static int test_wolfSSL_CTX_add_session_ext_tls12(void)
  9174. {
  9175. EXPECT_DECLS;
  9176. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  9177. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  9178. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  9179. defined(HAVE_SESSION_TICKET) && \
  9180. !defined(TITAN_SESSION_CACHE) && \
  9181. !defined(HUGE_SESSION_CACHE) && \
  9182. !defined(BIG_SESSION_CACHE) && \
  9183. !defined(MEDIUM_SESSION_CACHE)
  9184. #ifndef WOLFSSL_NO_TLS12
  9185. struct test_add_session_ext_params param[1] = {
  9186. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLSv1_2" }
  9187. };
  9188. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  9189. #endif
  9190. #endif
  9191. return EXPECT_RESULT();
  9192. }
  9193. static int test_wolfSSL_CTX_add_session_ext_dtls12(void)
  9194. {
  9195. EXPECT_DECLS;
  9196. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  9197. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  9198. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  9199. defined(HAVE_SESSION_TICKET) && \
  9200. !defined(TITAN_SESSION_CACHE) && \
  9201. !defined(HUGE_SESSION_CACHE) && \
  9202. !defined(BIG_SESSION_CACHE) && \
  9203. !defined(MEDIUM_SESSION_CACHE)
  9204. #ifndef WOLFSSL_NO_TLS12
  9205. #ifdef WOLFSSL_DTLS
  9206. struct test_add_session_ext_params param[1] = {
  9207. { wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, "DTLSv1_2" }
  9208. };
  9209. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  9210. #endif
  9211. #endif
  9212. #endif
  9213. return EXPECT_RESULT();
  9214. }
  9215. static int test_wolfSSL_CTX_add_session_ext_tls11(void)
  9216. {
  9217. EXPECT_DECLS;
  9218. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  9219. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  9220. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  9221. defined(HAVE_SESSION_TICKET) && \
  9222. !defined(TITAN_SESSION_CACHE) && \
  9223. !defined(HUGE_SESSION_CACHE) && \
  9224. !defined(BIG_SESSION_CACHE) && \
  9225. !defined(MEDIUM_SESSION_CACHE)
  9226. #if !defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \
  9227. !defined(NO_DES3))
  9228. struct test_add_session_ext_params param[1] = {
  9229. { wolfTLSv1_1_client_method, wolfTLSv1_1_server_method, "TLSv1_1" }
  9230. };
  9231. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  9232. #endif
  9233. #endif
  9234. return EXPECT_RESULT();
  9235. }
  9236. static int test_wolfSSL_CTX_add_session_ext_dtls1(void)
  9237. {
  9238. EXPECT_DECLS;
  9239. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  9240. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  9241. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  9242. defined(HAVE_SESSION_TICKET) && \
  9243. !defined(TITAN_SESSION_CACHE) && \
  9244. !defined(HUGE_SESSION_CACHE) && \
  9245. !defined(BIG_SESSION_CACHE) && \
  9246. !defined(MEDIUM_SESSION_CACHE)
  9247. #if !defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \
  9248. !defined(NO_DES3))
  9249. #ifdef WOLFSSL_DTLS
  9250. struct test_add_session_ext_params param[1] = {
  9251. { wolfDTLSv1_client_method, wolfDTLSv1_server_method, "DTLSv1_0" }
  9252. };
  9253. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  9254. #endif
  9255. #endif
  9256. #endif
  9257. return EXPECT_RESULT();
  9258. }
  9259. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT)
  9260. /* canned export of a session using older version 3 */
  9261. static unsigned char version_3[] = {
  9262. 0xA5, 0xA3, 0x01, 0x88, 0x00, 0x3c, 0x00, 0x01,
  9263. 0x00, 0x00, 0x00, 0x80, 0x0C, 0x00, 0x00, 0x00,
  9264. 0x00, 0x80, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00,
  9265. 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
  9266. 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  9267. 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9268. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x30,
  9269. 0x05, 0x09, 0x0A, 0x01, 0x01, 0x00, 0x0D, 0x05,
  9270. 0xFE, 0xFD, 0x01, 0x25, 0x00, 0x00, 0x00, 0x00,
  9271. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9272. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
  9273. 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00,
  9274. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9275. 0x00, 0x06, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00,
  9276. 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
  9277. 0x00, 0x06, 0x00, 0x01, 0x00, 0x07, 0x00, 0x00,
  9278. 0x00, 0x30, 0x00, 0x00, 0x00, 0x10, 0x01, 0x01,
  9279. 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
  9280. 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x3F,
  9281. 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00,
  9282. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9283. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9284. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9285. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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, 0x20, 0x05,
  9294. 0x12, 0xCF, 0x22, 0xA1, 0x9F, 0x1C, 0x39, 0x1D,
  9295. 0x31, 0x11, 0x12, 0x1D, 0x11, 0x18, 0x0D, 0x0B,
  9296. 0xF3, 0xE1, 0x4D, 0xDC, 0xB1, 0xF1, 0x39, 0x98,
  9297. 0x91, 0x6C, 0x48, 0xE5, 0xED, 0x11, 0x12, 0xA0,
  9298. 0x00, 0xF2, 0x25, 0x4C, 0x09, 0x26, 0xD1, 0x74,
  9299. 0xDF, 0x23, 0x40, 0x15, 0x6A, 0x42, 0x2A, 0x26,
  9300. 0xA5, 0xAC, 0x56, 0xD5, 0x4A, 0x20, 0xB7, 0xE9,
  9301. 0xEF, 0xEB, 0xAF, 0xA8, 0x1E, 0x23, 0x7C, 0x04,
  9302. 0xAA, 0xA1, 0x6D, 0x92, 0x79, 0x7B, 0xFA, 0x80,
  9303. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  9304. 0x0C, 0x79, 0x7B, 0xFA, 0x80, 0x00, 0x00, 0x00,
  9305. 0x00, 0x00, 0x00, 0x00, 0x00, 0xAA, 0xA1, 0x6D,
  9306. 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9307. 0x00, 0x00, 0x10, 0x00, 0x20, 0x00, 0x04, 0x00,
  9308. 0x10, 0x00, 0x10, 0x08, 0x02, 0x05, 0x08, 0x01,
  9309. 0x30, 0x28, 0x00, 0x00, 0x0F, 0x00, 0x02, 0x00,
  9310. 0x09, 0x31, 0x32, 0x37, 0x2E, 0x30, 0x2E, 0x30,
  9311. 0x2E, 0x31, 0xED, 0x4F
  9312. };
  9313. #endif /* defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT) */
  9314. static int test_wolfSSL_dtls_export(void)
  9315. {
  9316. EXPECT_DECLS;
  9317. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT)
  9318. tcp_ready ready;
  9319. func_args client_args;
  9320. func_args server_args;
  9321. THREAD_TYPE serverThread;
  9322. callback_functions server_cbf;
  9323. callback_functions client_cbf;
  9324. #ifdef WOLFSSL_TIRTOS
  9325. fdOpenSession(Task_self());
  9326. #endif
  9327. InitTcpReady(&ready);
  9328. #if defined(USE_WINDOWS_API)
  9329. /* use RNG to get random port if using windows */
  9330. ready.port = GetRandomPort();
  9331. #endif
  9332. /* set using dtls */
  9333. XMEMSET(&client_args, 0, sizeof(func_args));
  9334. XMEMSET(&server_args, 0, sizeof(func_args));
  9335. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  9336. XMEMSET(&client_cbf, 0, sizeof(callback_functions));
  9337. server_cbf.method = wolfDTLSv1_2_server_method;
  9338. client_cbf.method = wolfDTLSv1_2_client_method;
  9339. server_args.callbacks = &server_cbf;
  9340. client_args.callbacks = &client_cbf;
  9341. server_args.signal = &ready;
  9342. client_args.signal = &ready;
  9343. start_thread(run_wolfssl_server, &server_args, &serverThread);
  9344. wait_tcp_ready(&server_args);
  9345. run_wolfssl_client(&client_args);
  9346. join_thread(serverThread);
  9347. ExpectTrue(client_args.return_code);
  9348. ExpectTrue(server_args.return_code);
  9349. FreeTcpReady(&ready);
  9350. #ifdef WOLFSSL_TIRTOS
  9351. fdOpenSession(Task_self());
  9352. #endif
  9353. if (EXPECT_SUCCESS()) {
  9354. SOCKET_T sockfd = 0;
  9355. WOLFSSL_CTX* ctx = NULL;
  9356. WOLFSSL* ssl = NULL;
  9357. char msg[64] = "hello wolfssl!";
  9358. char reply[1024];
  9359. int msgSz = (int)XSTRLEN(msg);
  9360. byte *session, *window;
  9361. unsigned int sessionSz = 0;
  9362. unsigned int windowSz = 0;
  9363. #ifndef TEST_IPV6
  9364. struct sockaddr_in peerAddr;
  9365. #else
  9366. struct sockaddr_in6 peerAddr;
  9367. #endif /* TEST_IPV6 */
  9368. int i;
  9369. /* Set ctx to DTLS 1.2 */
  9370. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method()));
  9371. ExpectNotNull(ssl = wolfSSL_new(ctx));
  9372. /* test importing version 3 */
  9373. ExpectIntGE(wolfSSL_dtls_import(ssl, version_3, sizeof(version_3)), 0);
  9374. /* test importing bad length and bad version */
  9375. version_3[2] += 1;
  9376. ExpectIntLT(wolfSSL_dtls_import(ssl, version_3, sizeof(version_3)), 0);
  9377. version_3[2] -= 1; version_3[1] = 0XA0;
  9378. ExpectIntLT(wolfSSL_dtls_import(ssl, version_3, sizeof(version_3)), 0);
  9379. wolfSSL_free(ssl);
  9380. wolfSSL_CTX_free(ctx);
  9381. /* check storing client state after connection and storing window only */
  9382. #ifdef WOLFSSL_TIRTOS
  9383. fdOpenSession(Task_self());
  9384. #endif
  9385. InitTcpReady(&ready);
  9386. #if defined(USE_WINDOWS_API)
  9387. /* use RNG to get random port if using windows */
  9388. ready.port = GetRandomPort();
  9389. #endif
  9390. /* set using dtls */
  9391. XMEMSET(&server_args, 0, sizeof(func_args));
  9392. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  9393. server_cbf.method = wolfDTLSv1_2_server_method;
  9394. server_cbf.doUdp = 1;
  9395. server_args.callbacks = &server_cbf;
  9396. server_args.argc = 3; /* set loop_count to 3 */
  9397. server_args.signal = &ready;
  9398. start_thread(test_server_nofail, &server_args, &serverThread);
  9399. wait_tcp_ready(&server_args);
  9400. /* create and connect with client */
  9401. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_2_client_method()));
  9402. ExpectIntEQ(WOLFSSL_SUCCESS,
  9403. wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0));
  9404. ExpectIntEQ(WOLFSSL_SUCCESS,
  9405. wolfSSL_CTX_use_certificate_file(ctx, cliCertFile, SSL_FILETYPE_PEM));
  9406. ExpectIntEQ(WOLFSSL_SUCCESS,
  9407. wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, SSL_FILETYPE_PEM));
  9408. tcp_connect(&sockfd, wolfSSLIP, server_args.signal->port, 1, 0, NULL);
  9409. ExpectNotNull(ssl = wolfSSL_new(ctx));
  9410. ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS);
  9411. /* store server information connected too */
  9412. XMEMSET(&peerAddr, 0, sizeof(peerAddr));
  9413. #ifndef TEST_IPV6
  9414. peerAddr.sin_family = AF_INET;
  9415. ExpectIntEQ(XINET_PTON(AF_INET, wolfSSLIP, &peerAddr.sin_addr),1);
  9416. peerAddr.sin_port = XHTONS(server_args.signal->port);
  9417. #else
  9418. peerAddr.sin6_family = AF_INET6;
  9419. ExpectIntEQ(
  9420. XINET_PTON(AF_INET6, wolfSSLIP, &peerAddr.sin6_addr),1);
  9421. peerAddr.sin6_port = XHTONS(server_args.signal->port);
  9422. #endif
  9423. ExpectIntEQ(wolfSSL_dtls_set_peer(ssl, &peerAddr, sizeof(peerAddr)),
  9424. WOLFSSL_SUCCESS);
  9425. ExpectIntEQ(wolfSSL_connect(ssl), WOLFSSL_SUCCESS);
  9426. ExpectIntEQ(wolfSSL_dtls_export(ssl, NULL, &sessionSz), 0);
  9427. session = (byte*)XMALLOC(sessionSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9428. ExpectIntGT(wolfSSL_dtls_export(ssl, session, &sessionSz), 0);
  9429. ExpectIntEQ(wolfSSL_write(ssl, msg, msgSz), msgSz);
  9430. ExpectIntGT(wolfSSL_read(ssl, reply, sizeof(reply)), 0);
  9431. ExpectIntEQ(wolfSSL_dtls_export_state_only(ssl, NULL, &windowSz), 0);
  9432. window = (byte*)XMALLOC(windowSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9433. ExpectIntGT(wolfSSL_dtls_export_state_only(ssl, window, &windowSz), 0);
  9434. wolfSSL_free(ssl);
  9435. for (i = 1; EXPECT_SUCCESS() && i < server_args.argc; i++) {
  9436. /* restore state */
  9437. ExpectNotNull(ssl = wolfSSL_new(ctx));
  9438. ExpectIntGT(wolfSSL_dtls_import(ssl, session, sessionSz), 0);
  9439. ExpectIntGT(wolfSSL_dtls_import(ssl, window, windowSz), 0);
  9440. ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS);
  9441. ExpectIntEQ(wolfSSL_dtls_set_peer(ssl, &peerAddr, sizeof(peerAddr)),
  9442. WOLFSSL_SUCCESS);
  9443. ExpectIntEQ(wolfSSL_write(ssl, msg, msgSz), msgSz);
  9444. ExpectIntGE(wolfSSL_read(ssl, reply, sizeof(reply)), 0);
  9445. ExpectIntGT(wolfSSL_dtls_export_state_only(ssl, window, &windowSz), 0);
  9446. wolfSSL_free(ssl);
  9447. }
  9448. XFREE(session, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9449. XFREE(window, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9450. wolfSSL_CTX_free(ctx);
  9451. fprintf(stderr, "done and waiting for server\n");
  9452. join_thread(serverThread);
  9453. ExpectIntEQ(server_args.return_code, TEST_SUCCESS);
  9454. FreeTcpReady(&ready);
  9455. #ifdef WOLFSSL_TIRTOS
  9456. fdOpenSession(Task_self());
  9457. #endif
  9458. }
  9459. #endif
  9460. return EXPECT_RESULT();
  9461. }
  9462. #if defined(WOLFSSL_SESSION_EXPORT) && !defined(WOLFSSL_NO_TLS12)
  9463. #ifdef WOLFSSL_TLS13
  9464. static const byte canned_client_tls13_session[] = {
  9465. 0xA7, 0xA4, 0x01, 0x18, 0x00, 0x41, 0x00, 0x00,
  9466. 0x01, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x00,
  9467. 0x00, 0x80, 0x00, 0x1C, 0x01, 0x00, 0x00, 0x01,
  9468. 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
  9469. 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
  9470. 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  9471. 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13,
  9472. 0x01, 0x0A, 0x0F, 0x10, 0x01, 0x02, 0x09, 0x00,
  9473. 0x05, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00,
  9474. 0xB7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9475. 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9476. 0x01, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00,
  9477. 0x11, 0x01, 0x01, 0x00, 0x20, 0x84, 0x4F, 0x18,
  9478. 0xD8, 0xC1, 0x24, 0xD8, 0xBB, 0x17, 0x9E, 0x31,
  9479. 0xA3, 0xF8, 0xA7, 0x3C, 0xBA, 0xEC, 0xFA, 0xB4,
  9480. 0x7F, 0xC5, 0x78, 0xEB, 0x6D, 0xE3, 0x2B, 0x7B,
  9481. 0x94, 0xBE, 0x20, 0x11, 0x7E, 0x17, 0x10, 0xA7,
  9482. 0x10, 0x19, 0xEC, 0x62, 0xCC, 0xBE, 0xF5, 0x01,
  9483. 0x35, 0x3C, 0xEA, 0xEF, 0x44, 0x3C, 0x40, 0xA2,
  9484. 0xBC, 0x18, 0x43, 0xA1, 0xA1, 0x65, 0x5C, 0x48,
  9485. 0xE2, 0xF9, 0x38, 0xEB, 0x11, 0x10, 0x72, 0x7C,
  9486. 0x78, 0x22, 0x13, 0x3B, 0x19, 0x40, 0xF0, 0x73,
  9487. 0xBE, 0x96, 0x14, 0x78, 0x26, 0xB9, 0x6B, 0x2E,
  9488. 0x72, 0x22, 0x0D, 0x90, 0x94, 0xDD, 0x78, 0x77,
  9489. 0xFC, 0x0C, 0x2E, 0x63, 0x6E, 0xF0, 0x0C, 0x35,
  9490. 0x41, 0xCD, 0xF3, 0x49, 0x31, 0x08, 0xD0, 0x6F,
  9491. 0x02, 0x3D, 0xC1, 0xD3, 0xB7, 0xEE, 0x3A, 0xA0,
  9492. 0x8E, 0xA1, 0x4D, 0xC3, 0x2E, 0x5E, 0x06, 0x00,
  9493. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
  9494. 0x35, 0x41, 0xCD, 0xF3, 0x49, 0x31, 0x08, 0xD0,
  9495. 0x6F, 0x02, 0x3D, 0xC1, 0xD3, 0xB7, 0xEE, 0x3A,
  9496. 0xA0, 0x8E, 0xA1, 0x4D, 0xC3, 0x2E, 0x5E, 0x06,
  9497. 0x00, 0x10, 0x00, 0x10, 0x00, 0x0C, 0x00, 0x10,
  9498. 0x00, 0x10, 0x07, 0x02, 0x04, 0x00, 0x00, 0x20,
  9499. 0x28, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
  9500. 0x00, 0x03
  9501. };
  9502. static const byte canned_server_tls13_session[] = {
  9503. 0xA7, 0xA4, 0x01, 0x18, 0x00, 0x41, 0x01, 0x00,
  9504. 0x01, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x00,
  9505. 0x00, 0x80, 0x00, 0x1C, 0x01, 0x00, 0x00, 0x00,
  9506. 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
  9507. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9508. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  9509. 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13,
  9510. 0x01, 0x0A, 0x0F, 0x10, 0x01, 0x02, 0x00, 0x0F,
  9511. 0x05, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00,
  9512. 0xB7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9513. 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9514. 0x02, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00,
  9515. 0x11, 0x01, 0x01, 0x00, 0x20, 0x84, 0x4F, 0x18,
  9516. 0xD8, 0xC1, 0x24, 0xD8, 0xBB, 0x17, 0x9E, 0x31,
  9517. 0xA3, 0xF8, 0xA7, 0x3C, 0xBA, 0xEC, 0xFA, 0xB4,
  9518. 0x7F, 0xC5, 0x78, 0xEB, 0x6D, 0xE3, 0x2B, 0x7B,
  9519. 0x94, 0xBE, 0x20, 0x11, 0x7E, 0x17, 0x10, 0xA7,
  9520. 0x10, 0x19, 0xEC, 0x62, 0xCC, 0xBE, 0xF5, 0x01,
  9521. 0x35, 0x3C, 0xEA, 0xEF, 0x44, 0x3C, 0x40, 0xA2,
  9522. 0xBC, 0x18, 0x43, 0xA1, 0xA1, 0x65, 0x5C, 0x48,
  9523. 0xE2, 0xF9, 0x38, 0xEB, 0x11, 0x10, 0x72, 0x7C,
  9524. 0x78, 0x22, 0x13, 0x3B, 0x19, 0x40, 0xF0, 0x73,
  9525. 0xBE, 0x96, 0x14, 0x78, 0x26, 0xB9, 0x6B, 0x2E,
  9526. 0x72, 0x22, 0x0D, 0x90, 0x94, 0xDD, 0x78, 0x77,
  9527. 0xFC, 0x0C, 0x2E, 0x63, 0x6E, 0xF0, 0x0C, 0x35,
  9528. 0x41, 0xCD, 0xF3, 0x49, 0x31, 0x08, 0xD0, 0x6F,
  9529. 0x02, 0x3D, 0xC1, 0xD3, 0xB7, 0xEE, 0x3A, 0xA0,
  9530. 0x8E, 0xA1, 0x4D, 0xC3, 0x2E, 0x5E, 0x06, 0x00,
  9531. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
  9532. 0xD3, 0xB7, 0xEE, 0x3A, 0xA0, 0x8E, 0xA1, 0x4D,
  9533. 0xC3, 0x2E, 0x5E, 0x06, 0x35, 0x41, 0xCD, 0xF3,
  9534. 0x49, 0x31, 0x08, 0xD0, 0x6F, 0x02, 0x3D, 0xC1,
  9535. 0x00, 0x10, 0x00, 0x10, 0x00, 0x0C, 0x00, 0x10,
  9536. 0x00, 0x10, 0x07, 0x02, 0x04, 0x00, 0x00, 0x20,
  9537. 0x28, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
  9538. 0x00, 0x04
  9539. };
  9540. #endif /* WOLFSSL_TLS13 */
  9541. static const byte canned_client_session[] = {
  9542. 0xA7, 0xA4, 0x01, 0x40, 0x00, 0x41, 0x00, 0x00,
  9543. 0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x00,
  9544. 0x00, 0x80, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x01,
  9545. 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
  9546. 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
  9547. 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9548. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0,
  9549. 0x27, 0x0A, 0x0D, 0x10, 0x01, 0x01, 0x0A, 0x00,
  9550. 0x05, 0x00, 0x01, 0x01, 0x01, 0x03, 0x03, 0x00,
  9551. 0xBF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9552. 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9553. 0x02, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00,
  9554. 0x0A, 0x01, 0x01, 0x00, 0x20, 0x69, 0x11, 0x6D,
  9555. 0x97, 0x15, 0x6E, 0x52, 0x27, 0xD6, 0x1D, 0x1D,
  9556. 0xF5, 0x0D, 0x59, 0xA5, 0xAC, 0x2E, 0x8C, 0x0E,
  9557. 0xCB, 0x26, 0x1E, 0xE2, 0xCE, 0xBB, 0xCE, 0xE1,
  9558. 0x7D, 0xD7, 0xEF, 0xA5, 0x44, 0x80, 0x2A, 0xDE,
  9559. 0xBB, 0x75, 0xB0, 0x1D, 0x75, 0x17, 0x20, 0x4C,
  9560. 0x08, 0x05, 0x1B, 0xBA, 0x60, 0x1F, 0x6C, 0x91,
  9561. 0x8C, 0xAA, 0xBB, 0xE5, 0xA3, 0x0B, 0x12, 0x3E,
  9562. 0xC0, 0x35, 0x43, 0x1D, 0xE2, 0x10, 0xE2, 0x02,
  9563. 0x92, 0x4B, 0x8F, 0x05, 0xA9, 0x4B, 0xCC, 0x90,
  9564. 0xC3, 0x0E, 0xC2, 0x0F, 0xE9, 0x33, 0x85, 0x9B,
  9565. 0x3C, 0x19, 0x21, 0xD5, 0x62, 0xE5, 0xE1, 0x17,
  9566. 0x8F, 0x8C, 0x19, 0x52, 0xD8, 0x59, 0x10, 0x2D,
  9567. 0x20, 0x6F, 0xBA, 0xC1, 0x1C, 0xD1, 0x82, 0xC7,
  9568. 0x32, 0x1B, 0xBB, 0xCC, 0x30, 0x03, 0xD7, 0x3A,
  9569. 0xC8, 0x18, 0xED, 0x58, 0xC8, 0x11, 0xFE, 0x71,
  9570. 0x9C, 0x71, 0xD8, 0x6B, 0xE0, 0x25, 0x64, 0x00,
  9571. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
  9572. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9573. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9574. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9575. 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10,
  9576. 0x00, 0x00, 0x06, 0x01, 0x04, 0x08, 0x01, 0x20,
  9577. 0x28, 0x00, 0x09, 0xE1, 0x50, 0x70, 0x02, 0x2F,
  9578. 0x7E, 0xDA, 0xBD, 0x40, 0xC5, 0x58, 0x87, 0xCE,
  9579. 0x43, 0xF3, 0xC5, 0x8F, 0xA1, 0x59, 0x93, 0xEF,
  9580. 0x7E, 0xD3, 0xD0, 0xB5, 0x87, 0x1D, 0x81, 0x54,
  9581. 0x14, 0x63, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
  9582. 0x00, 0x03
  9583. };
  9584. static const byte canned_server_session[] = {
  9585. 0xA7, 0xA4, 0x01, 0x40, 0x00, 0x41, 0x00, 0x00,
  9586. 0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x00,
  9587. 0x00, 0x80, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00,
  9588. 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
  9589. 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  9590. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9591. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0,
  9592. 0x27, 0x08, 0x0F, 0x10, 0x01, 0x01, 0x00, 0x11,
  9593. 0x05, 0x00, 0x01, 0x01, 0x01, 0x03, 0x03, 0x00,
  9594. 0xBF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9595. 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9596. 0x02, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
  9597. 0x0A, 0x01, 0x01, 0x00, 0x20, 0x69, 0x11, 0x6D,
  9598. 0x97, 0x15, 0x6E, 0x52, 0x27, 0xD6, 0x1D, 0x1D,
  9599. 0xF5, 0x0D, 0x59, 0xA5, 0xAC, 0x2E, 0x8C, 0x0E,
  9600. 0xCB, 0x26, 0x1E, 0xE2, 0xCE, 0xBB, 0xCE, 0xE1,
  9601. 0x7D, 0xD7, 0xEF, 0xA5, 0x44, 0x80, 0x2A, 0xDE,
  9602. 0xBB, 0x75, 0xB0, 0x1D, 0x75, 0x17, 0x20, 0x4C,
  9603. 0x08, 0x05, 0x1B, 0xBA, 0x60, 0x1F, 0x6C, 0x91,
  9604. 0x8C, 0xAA, 0xBB, 0xE5, 0xA3, 0x0B, 0x12, 0x3E,
  9605. 0xC0, 0x35, 0x43, 0x1D, 0xE2, 0x10, 0xE2, 0x02,
  9606. 0x92, 0x4B, 0x8F, 0x05, 0xA9, 0x4B, 0xCC, 0x90,
  9607. 0xC3, 0x0E, 0xC2, 0x0F, 0xE9, 0x33, 0x85, 0x9B,
  9608. 0x3C, 0x19, 0x21, 0xD5, 0x62, 0xE5, 0xE1, 0x17,
  9609. 0x8F, 0x8C, 0x19, 0x52, 0xD8, 0x59, 0x10, 0x2D,
  9610. 0x20, 0x6F, 0xBA, 0xC1, 0x1C, 0xD1, 0x82, 0xC7,
  9611. 0x32, 0x1B, 0xBB, 0xCC, 0x30, 0x03, 0xD7, 0x3A,
  9612. 0xC8, 0x18, 0xED, 0x58, 0xC8, 0x11, 0xFE, 0x71,
  9613. 0x9C, 0x71, 0xD8, 0x6B, 0xE0, 0x25, 0x64, 0x00,
  9614. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
  9615. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9616. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9617. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9618. 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10,
  9619. 0x00, 0x00, 0x06, 0x01, 0x04, 0x08, 0x01, 0x20,
  9620. 0x28, 0x00, 0xC5, 0x8F, 0xA1, 0x59, 0x93, 0xEF,
  9621. 0x7E, 0xD3, 0xD0, 0xB5, 0x87, 0x1D, 0x81, 0x54,
  9622. 0x14, 0x63, 0x09, 0xE1, 0x50, 0x70, 0x02, 0x2F,
  9623. 0x7E, 0xDA, 0xBD, 0x40, 0xC5, 0x58, 0x87, 0xCE,
  9624. 0x43, 0xF3, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
  9625. 0x00, 0x04
  9626. };
  9627. static THREAD_RETURN WOLFSSL_THREAD tls_export_server(void* args)
  9628. {
  9629. SOCKET_T sockfd = 0;
  9630. SOCKET_T clientfd = 0;
  9631. word16 port;
  9632. callback_functions* cbf;
  9633. WOLFSSL_CTX* ctx = 0;
  9634. WOLFSSL* ssl = 0;
  9635. char msg[] = "I hear you fa shizzle!";
  9636. char input[1024];
  9637. int idx;
  9638. #ifdef WOLFSSL_TIRTOS
  9639. fdOpenSession(Task_self());
  9640. #endif
  9641. ((func_args*)args)->return_code = TEST_FAIL;
  9642. cbf = ((func_args*)args)->callbacks;
  9643. #if defined(USE_WINDOWS_API)
  9644. port = ((func_args*)args)->signal->port;
  9645. #elif defined(NO_MAIN_DRIVER) && !defined(WOLFSSL_SNIFFER) && \
  9646. !defined(WOLFSSL_MDK_SHELL) && !defined(WOLFSSL_TIRTOS)
  9647. /* Let tcp_listen assign port */
  9648. port = 0;
  9649. #else
  9650. /* Use default port */
  9651. port = wolfSSLPort;
  9652. #endif
  9653. /* do it here to detect failure */
  9654. tcp_accept(&sockfd, &clientfd, (func_args*)args, port, 0, 0, 0, 0, 1, 0, 0);
  9655. CloseSocket(sockfd);
  9656. {
  9657. WOLFSSL_METHOD* method = NULL;
  9658. if (cbf != NULL && cbf->method != NULL) {
  9659. method = cbf->method();
  9660. }
  9661. else {
  9662. method = wolfTLSv1_2_server_method();
  9663. }
  9664. ctx = wolfSSL_CTX_new(method);
  9665. }
  9666. if (ctx == NULL) {
  9667. goto done;
  9668. }
  9669. wolfSSL_CTX_set_cipher_list(ctx, "ECDHE-RSA-AES128-SHA256");
  9670. /* call ctx setup callback */
  9671. if (cbf != NULL && cbf->ctx_ready != NULL) {
  9672. cbf->ctx_ready(ctx);
  9673. }
  9674. ssl = wolfSSL_new(ctx);
  9675. if (ssl == NULL) {
  9676. goto done;
  9677. }
  9678. wolfSSL_set_fd(ssl, clientfd);
  9679. /* call ssl setup callback */
  9680. if (cbf != NULL && cbf->ssl_ready != NULL) {
  9681. cbf->ssl_ready(ssl);
  9682. }
  9683. idx = wolfSSL_read(ssl, input, sizeof(input)-1);
  9684. if (idx > 0) {
  9685. input[idx] = '\0';
  9686. fprintf(stderr, "Client message export/import: %s\n", input);
  9687. }
  9688. else {
  9689. fprintf(stderr, "ret = %d error = %d\n", idx,
  9690. wolfSSL_get_error(ssl, idx));
  9691. goto done;
  9692. }
  9693. if (wolfSSL_write(ssl, msg, sizeof(msg)) != sizeof(msg)) {
  9694. /*err_sys("SSL_write failed");*/
  9695. WOLFSSL_RETURN_FROM_THREAD(0);
  9696. }
  9697. #ifdef WOLFSSL_TIRTOS
  9698. Task_yield();
  9699. #endif
  9700. ((func_args*)args)->return_code = TEST_SUCCESS;
  9701. done:
  9702. wolfSSL_shutdown(ssl);
  9703. wolfSSL_free(ssl);
  9704. wolfSSL_CTX_free(ctx);
  9705. CloseSocket(clientfd);
  9706. #ifdef WOLFSSL_TIRTOS
  9707. fdCloseSession(Task_self());
  9708. #endif
  9709. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  9710. && defined(HAVE_THREAD_LS)
  9711. wc_ecc_fp_free(); /* free per thread cache */
  9712. #endif
  9713. #if defined(HAVE_SESSION_TICKET) && \
  9714. ((defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))
  9715. #if defined(OPENSSL_EXTRA) && defined(HAVE_AESGCM)
  9716. OpenSSLTicketCleanup();
  9717. #elif defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  9718. TicketCleanup();
  9719. #endif
  9720. #endif
  9721. WOLFSSL_RETURN_FROM_THREAD(0);
  9722. }
  9723. static void load_tls12_canned_server(WOLFSSL* ssl)
  9724. {
  9725. int clientfd = wolfSSL_get_fd(ssl);
  9726. AssertIntEQ(wolfSSL_tls_import(ssl, canned_server_session,
  9727. sizeof(canned_server_session)), sizeof(canned_server_session));
  9728. wolfSSL_set_fd(ssl, clientfd);
  9729. }
  9730. #ifdef WOLFSSL_TLS13
  9731. static void load_tls13_canned_server(WOLFSSL* ssl)
  9732. {
  9733. int clientfd = wolfSSL_get_fd(ssl);
  9734. AssertIntEQ(wolfSSL_tls_import(ssl, canned_server_tls13_session,
  9735. sizeof(canned_server_tls13_session)),
  9736. sizeof(canned_server_tls13_session));
  9737. wolfSSL_set_fd(ssl, clientfd);
  9738. }
  9739. #endif
  9740. /* v is for version WOLFSSL_TLSV1_2 or WOLFSSL_TLSV1_3 */
  9741. static int test_wolfSSL_tls_export_run(int v)
  9742. {
  9743. EXPECT_DECLS;
  9744. SOCKET_T sockfd = 0;
  9745. WOLFSSL_CTX* ctx = 0;
  9746. WOLFSSL* ssl = 0;
  9747. char msg[64] = "hello wolfssl!";
  9748. char reply[1024];
  9749. word32 replySz;
  9750. int msgSz = (int)XSTRLEN(msg);
  9751. const byte* clientSession = NULL;
  9752. int clientSessionSz = 0;
  9753. tcp_ready ready;
  9754. func_args server_args;
  9755. THREAD_TYPE serverThread;
  9756. callback_functions server_cbf;
  9757. #ifdef WOLFSSL_TIRTOS
  9758. fdOpenSession(Task_self());
  9759. #endif
  9760. InitTcpReady(&ready);
  9761. #if defined(USE_WINDOWS_API)
  9762. /* use RNG to get random port if using windows */
  9763. ready.port = GetRandomPort();
  9764. #endif
  9765. XMEMSET(&server_args, 0, sizeof(func_args));
  9766. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  9767. switch (v) {
  9768. case WOLFSSL_TLSV1_2:
  9769. server_cbf.method = wolfTLSv1_2_server_method;
  9770. server_cbf.ssl_ready = load_tls12_canned_server;
  9771. /* setup the client side */
  9772. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  9773. wolfSSL_CTX_set_cipher_list(ctx, "ECDHE-RSA-AES128-SHA256");
  9774. clientSession = canned_client_session;
  9775. clientSessionSz = sizeof(canned_client_session);
  9776. break;
  9777. #ifdef WOLFSSL_TLS13
  9778. case WOLFSSL_TLSV1_3:
  9779. server_cbf.method = wolfTLSv1_3_server_method;
  9780. server_cbf.ssl_ready = load_tls13_canned_server;
  9781. /* setup the client side */
  9782. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  9783. clientSession = canned_client_tls13_session;
  9784. clientSessionSz = sizeof(canned_client_tls13_session);
  9785. break;
  9786. #endif
  9787. }
  9788. server_args.callbacks = &server_cbf;
  9789. server_args.signal = &ready;
  9790. start_thread(tls_export_server, &server_args, &serverThread);
  9791. wait_tcp_ready(&server_args);
  9792. #ifdef WOLFSSL_TIRTOS
  9793. fdOpenSession(Task_self());
  9794. #endif
  9795. ExpectNotNull(ssl = wolfSSL_new(ctx));
  9796. tcp_connect(&sockfd, wolfSSLIP, ready.port, 0, 0, ssl);
  9797. ExpectIntEQ(wolfSSL_tls_import(ssl, clientSession, clientSessionSz),
  9798. clientSessionSz);
  9799. replySz = sizeof(reply);
  9800. ExpectIntGT(wolfSSL_tls_export(ssl, (byte*)reply, &replySz), 0);
  9801. #if !defined(NO_PSK) && defined(HAVE_ANON)
  9802. /* index 20 has is setting if PSK was on and 49 is if anon is allowed */
  9803. ExpectIntEQ(XMEMCMP(reply, clientSession, replySz), 0);
  9804. #endif
  9805. wolfSSL_set_fd(ssl, sockfd);
  9806. ExpectIntEQ(wolfSSL_write(ssl, msg, msgSz), msgSz);
  9807. ExpectIntGT(wolfSSL_read(ssl, reply, sizeof(reply)-1), 0);
  9808. wolfSSL_free(ssl);
  9809. wolfSSL_CTX_free(ctx);
  9810. CloseSocket(sockfd);
  9811. #ifdef WOLFSSL_TIRTOS
  9812. fdCloseSession(Task_self());
  9813. #endif
  9814. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  9815. && defined(HAVE_THREAD_LS)
  9816. wc_ecc_fp_free(); /* free per thread cache */
  9817. #endif
  9818. join_thread(serverThread);
  9819. ExpectIntEQ(server_args.return_code, TEST_SUCCESS);
  9820. FreeTcpReady(&ready);
  9821. #ifdef WOLFSSL_TIRTOS
  9822. fdOpenSession(Task_self());
  9823. #endif
  9824. return EXPECT_RESULT();
  9825. }
  9826. #endif
  9827. static int test_wolfSSL_tls_export(void)
  9828. {
  9829. int res = TEST_SKIPPED;
  9830. #if defined(WOLFSSL_SESSION_EXPORT) && !defined(WOLFSSL_NO_TLS12)
  9831. test_wolfSSL_tls_export_run(WOLFSSL_TLSV1_2);
  9832. #ifdef WOLFSSL_TLS13
  9833. test_wolfSSL_tls_export_run(WOLFSSL_TLSV1_3);
  9834. #endif
  9835. res = TEST_RES_CHECK(1);
  9836. #endif
  9837. return res;
  9838. }
  9839. /*----------------------------------------------------------------------------*
  9840. | TLS extensions tests
  9841. *----------------------------------------------------------------------------*/
  9842. #ifdef ENABLE_TLS_CALLBACK_TEST
  9843. /* Connection test runner - generic */
  9844. static void test_wolfSSL_client_server(callback_functions* client_callbacks,
  9845. callback_functions* server_callbacks)
  9846. {
  9847. tcp_ready ready;
  9848. func_args client_args;
  9849. func_args server_args;
  9850. THREAD_TYPE serverThread;
  9851. XMEMSET(&client_args, 0, sizeof(func_args));
  9852. XMEMSET(&server_args, 0, sizeof(func_args));
  9853. StartTCP();
  9854. client_args.callbacks = client_callbacks;
  9855. server_args.callbacks = server_callbacks;
  9856. #ifdef WOLFSSL_TIRTOS
  9857. fdOpenSession(Task_self());
  9858. #endif
  9859. /* RUN Server side */
  9860. InitTcpReady(&ready);
  9861. #if defined(USE_WINDOWS_API)
  9862. /* use RNG to get random port if using windows */
  9863. ready.port = GetRandomPort();
  9864. #endif
  9865. server_args.signal = &ready;
  9866. client_args.signal = &ready;
  9867. start_thread(run_wolfssl_server, &server_args, &serverThread);
  9868. wait_tcp_ready(&server_args);
  9869. /* RUN Client side */
  9870. run_wolfssl_client(&client_args);
  9871. join_thread(serverThread);
  9872. FreeTcpReady(&ready);
  9873. #ifdef WOLFSSL_TIRTOS
  9874. fdCloseSession(Task_self());
  9875. #endif
  9876. client_callbacks->return_code = client_args.return_code;
  9877. server_callbacks->return_code = server_args.return_code;
  9878. }
  9879. #endif /* ENABLE_TLS_CALLBACK_TEST */
  9880. #ifdef HAVE_SNI
  9881. static int test_wolfSSL_UseSNI_params(void)
  9882. {
  9883. EXPECT_DECLS;
  9884. #if !defined(NO_WOLFSSL_CLIENT)
  9885. WOLFSSL_CTX *ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  9886. WOLFSSL *ssl = wolfSSL_new(ctx);
  9887. ExpectNotNull(ctx);
  9888. ExpectNotNull(ssl);
  9889. /* invalid [ctx|ssl] */
  9890. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(NULL, 0, "ctx", 3));
  9891. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSNI( NULL, 0, "ssl", 3));
  9892. /* invalid type */
  9893. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(ctx, -1, "ctx", 3));
  9894. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSNI( ssl, -1, "ssl", 3));
  9895. /* invalid data */
  9896. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(ctx, 0, NULL, 3));
  9897. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSNI( ssl, 0, NULL, 3));
  9898. /* success case */
  9899. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(ctx, 0, "ctx", 3));
  9900. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSNI( ssl, 0, "ssl", 3));
  9901. wolfSSL_free(ssl);
  9902. wolfSSL_CTX_free(ctx);
  9903. #endif /* !NO_WOLFSSL_CLIENT */
  9904. return EXPECT_RESULT();
  9905. }
  9906. /* BEGIN of connection tests callbacks */
  9907. static void use_SNI_at_ctx(WOLFSSL_CTX* ctx)
  9908. {
  9909. AssertIntEQ(WOLFSSL_SUCCESS,
  9910. wolfSSL_CTX_UseSNI(ctx, WOLFSSL_SNI_HOST_NAME, "www.wolfssl.com", 15));
  9911. }
  9912. static void use_SNI_at_ssl(WOLFSSL* ssl)
  9913. {
  9914. AssertIntEQ(WOLFSSL_SUCCESS,
  9915. wolfSSL_UseSNI(ssl, WOLFSSL_SNI_HOST_NAME, "www.wolfssl.com", 15));
  9916. }
  9917. static void different_SNI_at_ssl(WOLFSSL* ssl)
  9918. {
  9919. AssertIntEQ(WOLFSSL_SUCCESS,
  9920. wolfSSL_UseSNI(ssl, WOLFSSL_SNI_HOST_NAME, "ww2.wolfssl.com", 15));
  9921. }
  9922. static void use_SNI_WITH_CONTINUE_at_ssl(WOLFSSL* ssl)
  9923. {
  9924. use_SNI_at_ssl(ssl);
  9925. wolfSSL_SNI_SetOptions(ssl, WOLFSSL_SNI_HOST_NAME,
  9926. WOLFSSL_SNI_CONTINUE_ON_MISMATCH);
  9927. }
  9928. static void use_SNI_WITH_FAKE_ANSWER_at_ssl(WOLFSSL* ssl)
  9929. {
  9930. use_SNI_at_ssl(ssl);
  9931. wolfSSL_SNI_SetOptions(ssl, WOLFSSL_SNI_HOST_NAME,
  9932. WOLFSSL_SNI_ANSWER_ON_MISMATCH);
  9933. }
  9934. static void use_MANDATORY_SNI_at_ctx(WOLFSSL_CTX* ctx)
  9935. {
  9936. use_SNI_at_ctx(ctx);
  9937. wolfSSL_CTX_SNI_SetOptions(ctx, WOLFSSL_SNI_HOST_NAME,
  9938. WOLFSSL_SNI_ABORT_ON_ABSENCE);
  9939. }
  9940. static void use_MANDATORY_SNI_at_ssl(WOLFSSL* ssl)
  9941. {
  9942. use_SNI_at_ssl(ssl);
  9943. wolfSSL_SNI_SetOptions(ssl, WOLFSSL_SNI_HOST_NAME,
  9944. WOLFSSL_SNI_ABORT_ON_ABSENCE);
  9945. }
  9946. static void use_PSEUDO_MANDATORY_SNI_at_ctx(WOLFSSL_CTX* ctx)
  9947. {
  9948. use_SNI_at_ctx(ctx);
  9949. wolfSSL_CTX_SNI_SetOptions(ctx, WOLFSSL_SNI_HOST_NAME,
  9950. WOLFSSL_SNI_ANSWER_ON_MISMATCH | WOLFSSL_SNI_ABORT_ON_ABSENCE);
  9951. }
  9952. static void verify_UNKNOWN_SNI_on_server(WOLFSSL* ssl)
  9953. {
  9954. AssertIntEQ(WC_NO_ERR_TRACE(UNKNOWN_SNI_HOST_NAME_E),
  9955. wolfSSL_get_error(ssl, 0));
  9956. }
  9957. static void verify_SNI_ABSENT_on_server(WOLFSSL* ssl)
  9958. {
  9959. AssertIntEQ(WC_NO_ERR_TRACE(SNI_ABSENT_ERROR), wolfSSL_get_error(ssl, 0));
  9960. }
  9961. static void verify_SNI_no_matching(WOLFSSL* ssl)
  9962. {
  9963. byte type = WOLFSSL_SNI_HOST_NAME;
  9964. void* request = (void*) &type; /* to be overwritten */
  9965. AssertIntEQ(WOLFSSL_SNI_NO_MATCH, wolfSSL_SNI_Status(ssl, type));
  9966. AssertNotNull(request);
  9967. AssertIntEQ(0, wolfSSL_SNI_GetRequest(ssl, type, &request));
  9968. AssertNull(request);
  9969. }
  9970. static void verify_SNI_real_matching(WOLFSSL* ssl)
  9971. {
  9972. byte type = WOLFSSL_SNI_HOST_NAME;
  9973. void* request = NULL;
  9974. AssertIntEQ(WOLFSSL_SNI_REAL_MATCH, wolfSSL_SNI_Status(ssl, type));
  9975. AssertIntEQ(15, wolfSSL_SNI_GetRequest(ssl, type, &request));
  9976. AssertNotNull(request);
  9977. AssertStrEQ("www.wolfssl.com", (char*)request);
  9978. }
  9979. static void verify_SNI_fake_matching(WOLFSSL* ssl)
  9980. {
  9981. byte type = WOLFSSL_SNI_HOST_NAME;
  9982. void* request = NULL;
  9983. AssertIntEQ(WOLFSSL_SNI_FAKE_MATCH, wolfSSL_SNI_Status(ssl, type));
  9984. AssertIntEQ(15, wolfSSL_SNI_GetRequest(ssl, type, &request));
  9985. AssertNotNull(request);
  9986. AssertStrEQ("ww2.wolfssl.com", (char*)request);
  9987. }
  9988. static void verify_FATAL_ERROR_on_client(WOLFSSL* ssl)
  9989. {
  9990. AssertIntEQ(WC_NO_ERR_TRACE(FATAL_ERROR), wolfSSL_get_error(ssl, 0));
  9991. }
  9992. /* END of connection tests callbacks */
  9993. static int test_wolfSSL_UseSNI_connection(void)
  9994. {
  9995. int res = TEST_SKIPPED;
  9996. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  9997. callback_functions client_cb;
  9998. callback_functions server_cb;
  9999. size_t i;
  10000. #ifdef WOLFSSL_STATIC_MEMORY
  10001. byte cliMem[TEST_TLS_STATIC_MEMSZ];
  10002. byte svrMem[TEST_TLS_STATIC_MEMSZ];
  10003. #endif
  10004. struct {
  10005. method_provider client_meth;
  10006. method_provider server_meth;
  10007. #ifdef WOLFSSL_STATIC_MEMORY
  10008. wolfSSL_method_func client_meth_ex;
  10009. wolfSSL_method_func server_meth_ex;
  10010. #endif
  10011. } methods[] = {
  10012. #if defined(WOLFSSL_NO_TLS12) && !defined(WOLFSSL_TLS13)
  10013. {wolfSSLv23_client_method, wolfSSLv23_server_method
  10014. #ifdef WOLFSSL_STATIC_MEMORY
  10015. ,wolfSSLv23_client_method_ex, wolfSSLv23_server_method_ex
  10016. #endif
  10017. },
  10018. #endif
  10019. #ifndef WOLFSSL_NO_TLS12
  10020. {wolfTLSv1_2_client_method, wolfTLSv1_2_server_method
  10021. #ifdef WOLFSSL_STATIC_MEMORY
  10022. ,wolfTLSv1_2_client_method_ex, wolfTLSv1_2_server_method_ex
  10023. #endif
  10024. },
  10025. #endif
  10026. #ifdef WOLFSSL_TLS13
  10027. {wolfTLSv1_3_client_method, wolfTLSv1_3_server_method
  10028. #ifdef WOLFSSL_STATIC_MEMORY
  10029. ,wolfTLSv1_3_client_method_ex, wolfTLSv1_3_server_method_ex
  10030. #endif
  10031. },
  10032. #endif
  10033. };
  10034. size_t methodsSz = sizeof(methods) / sizeof(*methods);
  10035. for (i = 0; i < methodsSz; i++) {
  10036. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  10037. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  10038. client_cb.method = methods[i].client_meth;
  10039. server_cb.method = methods[i].server_meth;
  10040. client_cb.devId = testDevId;
  10041. server_cb.devId = testDevId;
  10042. #ifdef WOLFSSL_STATIC_MEMORY
  10043. client_cb.method_ex = methods[i].client_meth_ex;
  10044. server_cb.method_ex = methods[i].server_meth_ex;
  10045. client_cb.mem = cliMem;
  10046. client_cb.memSz = (word32)sizeof(cliMem);
  10047. server_cb.mem = svrMem;
  10048. server_cb.memSz = (word32)sizeof(svrMem);;
  10049. #endif
  10050. /* success case at ctx */
  10051. fprintf(stderr, "\n\tsuccess case at ctx\n");
  10052. client_cb.ctx_ready = use_SNI_at_ctx; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
  10053. server_cb.ctx_ready = use_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_real_matching;
  10054. test_wolfSSL_client_server(&client_cb, &server_cb);
  10055. /* success case at ssl */
  10056. fprintf(stderr, "\tsuccess case at ssl\n");
  10057. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_SNI_at_ssl; client_cb.on_result = verify_SNI_real_matching;
  10058. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_at_ssl; server_cb.on_result = verify_SNI_real_matching;
  10059. test_wolfSSL_client_server(&client_cb, &server_cb);
  10060. /* default mismatch behavior */
  10061. fprintf(stderr, "\tdefault mismatch behavior\n");
  10062. client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = verify_FATAL_ERROR_on_client;
  10063. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_at_ssl; server_cb.on_result = verify_UNKNOWN_SNI_on_server;
  10064. test_wolfSSL_client_server(&client_cb, &server_cb);
  10065. /* continue on mismatch */
  10066. fprintf(stderr, "\tcontinue on mismatch\n");
  10067. client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = NULL;
  10068. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_WITH_CONTINUE_at_ssl; server_cb.on_result = verify_SNI_no_matching;
  10069. test_wolfSSL_client_server(&client_cb, &server_cb);
  10070. /* fake answer on mismatch */
  10071. fprintf(stderr, "\tfake answer on mismatch\n");
  10072. client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = NULL;
  10073. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_WITH_FAKE_ANSWER_at_ssl; server_cb.on_result = verify_SNI_fake_matching;
  10074. test_wolfSSL_client_server(&client_cb, &server_cb);
  10075. /* sni abort - success */
  10076. fprintf(stderr, "\tsni abort - success\n");
  10077. client_cb.ctx_ready = use_SNI_at_ctx; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
  10078. server_cb.ctx_ready = use_MANDATORY_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_real_matching;
  10079. test_wolfSSL_client_server(&client_cb, &server_cb);
  10080. /* sni abort - abort when absent (ctx) */
  10081. fprintf(stderr, "\tsni abort - abort when absent (ctx)\n");
  10082. client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = verify_FATAL_ERROR_on_client;
  10083. server_cb.ctx_ready = use_MANDATORY_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_ABSENT_on_server;
  10084. test_wolfSSL_client_server(&client_cb, &server_cb);
  10085. /* sni abort - abort when absent (ssl) */
  10086. fprintf(stderr, "\tsni abort - abort when absent (ssl)\n");
  10087. client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = verify_FATAL_ERROR_on_client;
  10088. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_MANDATORY_SNI_at_ssl; server_cb.on_result = verify_SNI_ABSENT_on_server;
  10089. test_wolfSSL_client_server(&client_cb, &server_cb);
  10090. /* sni abort - success when overwritten */
  10091. fprintf(stderr, "\tsni abort - success when overwritten\n");
  10092. client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
  10093. 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;
  10094. test_wolfSSL_client_server(&client_cb, &server_cb);
  10095. /* sni abort - success when allowing mismatches */
  10096. fprintf(stderr, "\tsni abort - success when allowing mismatches\n");
  10097. client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = NULL;
  10098. server_cb.ctx_ready = use_PSEUDO_MANDATORY_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_fake_matching;
  10099. test_wolfSSL_client_server(&client_cb, &server_cb);
  10100. }
  10101. res = TEST_RES_CHECK(1);
  10102. #endif /* !NO_WOLFSSL_CLIENT && !NO_WOLFSSL_SERVER */
  10103. return res;
  10104. }
  10105. static int test_wolfSSL_SNI_GetFromBuffer(void)
  10106. {
  10107. EXPECT_DECLS;
  10108. byte buff[] = { /* www.paypal.com */
  10109. 0x00, 0x00, 0x00, 0x00, 0xff, 0x01, 0x00, 0x00, 0x60, 0x03, 0x03, 0x5c,
  10110. 0xc4, 0xb3, 0x8c, 0x87, 0xef, 0xa4, 0x09, 0xe0, 0x02, 0xab, 0x86, 0xca,
  10111. 0x76, 0xf0, 0x9e, 0x01, 0x65, 0xf6, 0xa6, 0x06, 0x13, 0x1d, 0x0f, 0xa5,
  10112. 0x79, 0xb0, 0xd4, 0x77, 0x22, 0xeb, 0x1a, 0x00, 0x00, 0x16, 0x00, 0x6b,
  10113. 0x00, 0x67, 0x00, 0x39, 0x00, 0x33, 0x00, 0x3d, 0x00, 0x3c, 0x00, 0x35,
  10114. 0x00, 0x2f, 0x00, 0x05, 0x00, 0x04, 0x00, 0x0a, 0x01, 0x00, 0x00, 0x21,
  10115. 0x00, 0x00, 0x00, 0x13, 0x00, 0x11, 0x00, 0x00, 0x0e, 0x77, 0x77, 0x77,
  10116. 0x2e, 0x70, 0x61, 0x79, 0x70, 0x61, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x00,
  10117. 0x0d, 0x00, 0x06, 0x00, 0x04, 0x04, 0x01, 0x02, 0x01
  10118. };
  10119. byte buff2[] = { /* api.textmate.org */
  10120. 0x16, 0x03, 0x01, 0x00, 0xc6, 0x01, 0x00, 0x00, 0xc2, 0x03, 0x03, 0x52,
  10121. 0x8b, 0x7b, 0xca, 0x69, 0xec, 0x97, 0xd5, 0x08, 0x03, 0x50, 0xfe, 0x3b,
  10122. 0x99, 0xc3, 0x20, 0xce, 0xa5, 0xf6, 0x99, 0xa5, 0x71, 0xf9, 0x57, 0x7f,
  10123. 0x04, 0x38, 0xf6, 0x11, 0x0b, 0xb8, 0xd3, 0x00, 0x00, 0x5e, 0x00, 0xff,
  10124. 0xc0, 0x24, 0xc0, 0x23, 0xc0, 0x0a, 0xc0, 0x09, 0xc0, 0x07, 0xc0, 0x08,
  10125. 0xc0, 0x28, 0xc0, 0x27, 0xc0, 0x14, 0xc0, 0x13, 0xc0, 0x11, 0xc0, 0x12,
  10126. 0xc0, 0x26, 0xc0, 0x25, 0xc0, 0x2a, 0xc0, 0x29, 0xc0, 0x05, 0xc0, 0x04,
  10127. 0xc0, 0x02, 0xc0, 0x03, 0xc0, 0x0f, 0xc0, 0x0e, 0xc0, 0x0c, 0xc0, 0x0d,
  10128. 0x00, 0x3d, 0x00, 0x3c, 0x00, 0x2f, 0x00, 0x05, 0x00, 0x04, 0x00, 0x35,
  10129. 0x00, 0x0a, 0x00, 0x67, 0x00, 0x6b, 0x00, 0x33, 0x00, 0x39, 0x00, 0x16,
  10130. 0x00, 0xaf, 0x00, 0xae, 0x00, 0x8d, 0x00, 0x8c, 0x00, 0x8a, 0x00, 0x8b,
  10131. 0x00, 0xb1, 0x00, 0xb0, 0x00, 0x2c, 0x00, 0x3b, 0x01, 0x00, 0x00, 0x3b,
  10132. 0x00, 0x00, 0x00, 0x15, 0x00, 0x13, 0x00, 0x00, 0x10, 0x61, 0x70, 0x69,
  10133. 0x2e, 0x74, 0x65, 0x78, 0x74, 0x6d, 0x61, 0x74, 0x65, 0x2e, 0x6f, 0x72,
  10134. 0x67, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x06, 0x00, 0x17, 0x00, 0x18, 0x00,
  10135. 0x19, 0x00, 0x0b, 0x00, 0x02, 0x01, 0x00, 0x00, 0x0d, 0x00, 0x0c, 0x00,
  10136. 0x0a, 0x05, 0x01, 0x04, 0x01, 0x02, 0x01, 0x04, 0x03, 0x02, 0x03
  10137. };
  10138. byte buff3[] = { /* no sni extension */
  10139. 0x16, 0x03, 0x03, 0x00, 0x4d, 0x01, 0x00, 0x00, 0x49, 0x03, 0x03, 0xea,
  10140. 0xa1, 0x9f, 0x60, 0xdd, 0x52, 0x12, 0x13, 0xbd, 0x84, 0x34, 0xd5, 0x1c,
  10141. 0x38, 0x25, 0xa8, 0x97, 0xd2, 0xd5, 0xc6, 0x45, 0xaf, 0x1b, 0x08, 0xe4,
  10142. 0x1e, 0xbb, 0xdf, 0x9d, 0x39, 0xf0, 0x65, 0x00, 0x00, 0x16, 0x00, 0x6b,
  10143. 0x00, 0x67, 0x00, 0x39, 0x00, 0x33, 0x00, 0x3d, 0x00, 0x3c, 0x00, 0x35,
  10144. 0x00, 0x2f, 0x00, 0x05, 0x00, 0x04, 0x00, 0x0a, 0x01, 0x00, 0x00, 0x0a,
  10145. 0x00, 0x0d, 0x00, 0x06, 0x00, 0x04, 0x04, 0x01, 0x02, 0x01
  10146. };
  10147. byte buff4[] = { /* last extension has zero size */
  10148. 0x16, 0x03, 0x01, 0x00, 0xba, 0x01, 0x00, 0x00,
  10149. 0xb6, 0x03, 0x03, 0x83, 0xa3, 0xe6, 0xdc, 0x16, 0xa1, 0x43, 0xe9, 0x45,
  10150. 0x15, 0xbd, 0x64, 0xa9, 0xb6, 0x07, 0xb4, 0x50, 0xc6, 0xdd, 0xff, 0xc2,
  10151. 0xd3, 0x0d, 0x4f, 0x36, 0xb4, 0x41, 0x51, 0x61, 0xc1, 0xa5, 0x9e, 0x00,
  10152. 0x00, 0x28, 0xcc, 0x14, 0xcc, 0x13, 0xc0, 0x2b, 0xc0, 0x2f, 0x00, 0x9e,
  10153. 0xc0, 0x0a, 0xc0, 0x09, 0xc0, 0x13, 0xc0, 0x14, 0xc0, 0x07, 0xc0, 0x11,
  10154. 0x00, 0x33, 0x00, 0x32, 0x00, 0x39, 0x00, 0x9c, 0x00, 0x2f, 0x00, 0x35,
  10155. 0x00, 0x0a, 0x00, 0x05, 0x00, 0x04, 0x01, 0x00, 0x00, 0x65, 0xff, 0x01,
  10156. 0x00, 0x01, 0x00, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x06, 0x00, 0x17, 0x00,
  10157. 0x18, 0x00, 0x19, 0x00, 0x0b, 0x00, 0x02, 0x01, 0x00, 0x00, 0x23, 0x00,
  10158. 0x00, 0x33, 0x74, 0x00, 0x00, 0x00, 0x10, 0x00, 0x1b, 0x00, 0x19, 0x06,
  10159. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x33, 0x08, 0x73, 0x70, 0x64, 0x79, 0x2f,
  10160. 0x33, 0x2e, 0x31, 0x08, 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31,
  10161. 0x75, 0x50, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x01, 0x00, 0x00, 0x00,
  10162. 0x00, 0x00, 0x0d, 0x00, 0x12, 0x00, 0x10, 0x04, 0x01, 0x05, 0x01, 0x02,
  10163. 0x01, 0x04, 0x03, 0x05, 0x03, 0x02, 0x03, 0x04, 0x02, 0x02, 0x02, 0x00,
  10164. 0x12, 0x00, 0x00
  10165. };
  10166. byte buff5[] = { /* SSL v2.0 client hello */
  10167. 0x00, 0x2b, 0x01, 0x03, 0x01, 0x00, 0x09, 0x00, 0x00,
  10168. /* dummy bytes below, just to pass size check */
  10169. 0xb6, 0x03, 0x03, 0x83, 0xa3, 0xe6, 0xdc, 0x16, 0xa1, 0x43, 0xe9, 0x45,
  10170. 0x15, 0xbd, 0x64, 0xa9, 0xb6, 0x07, 0xb4, 0x50, 0xc6, 0xdd, 0xff, 0xc2,
  10171. 0xd3, 0x0d, 0x4f, 0x36, 0xb4, 0x41, 0x51, 0x61, 0xc1, 0xa5, 0x9e, 0x00,
  10172. };
  10173. byte result[32] = {0};
  10174. word32 length = 32;
  10175. ExpectIntEQ(0, wolfSSL_SNI_GetFromBuffer(buff4, sizeof(buff4),
  10176. 0, result, &length));
  10177. ExpectIntEQ(0, wolfSSL_SNI_GetFromBuffer(buff3, sizeof(buff3),
  10178. 0, result, &length));
  10179. ExpectIntEQ(0, wolfSSL_SNI_GetFromBuffer(buff2, sizeof(buff2),
  10180. 1, result, &length));
  10181. ExpectIntEQ(WC_NO_ERR_TRACE(BUFFER_ERROR), wolfSSL_SNI_GetFromBuffer(buff, sizeof(buff),
  10182. 0, result, &length));
  10183. buff[0] = 0x16;
  10184. ExpectIntEQ(WC_NO_ERR_TRACE(BUFFER_ERROR), wolfSSL_SNI_GetFromBuffer(buff, sizeof(buff),
  10185. 0, result, &length));
  10186. buff[1] = 0x03;
  10187. ExpectIntEQ(WC_NO_ERR_TRACE(SNI_UNSUPPORTED), wolfSSL_SNI_GetFromBuffer(buff,
  10188. sizeof(buff), 0, result, &length));
  10189. buff[2] = 0x03;
  10190. ExpectIntEQ(WC_NO_ERR_TRACE(INCOMPLETE_DATA), wolfSSL_SNI_GetFromBuffer(buff,
  10191. sizeof(buff), 0, result, &length));
  10192. buff[4] = 0x64;
  10193. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SNI_GetFromBuffer(buff, sizeof(buff),
  10194. 0, result, &length));
  10195. if (EXPECT_SUCCESS())
  10196. result[length] = 0;
  10197. ExpectStrEQ("www.paypal.com", (const char*) result);
  10198. length = 32;
  10199. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SNI_GetFromBuffer(buff2, sizeof(buff2),
  10200. 0, result, &length));
  10201. if (EXPECT_SUCCESS())
  10202. result[length] = 0;
  10203. ExpectStrEQ("api.textmate.org", (const char*) result);
  10204. /* SSL v2.0 tests */
  10205. ExpectIntEQ(WC_NO_ERR_TRACE(SNI_UNSUPPORTED), wolfSSL_SNI_GetFromBuffer(buff5,
  10206. sizeof(buff5), 0, result, &length));
  10207. buff5[2] = 0x02;
  10208. ExpectIntEQ(WC_NO_ERR_TRACE(BUFFER_ERROR), wolfSSL_SNI_GetFromBuffer(buff5,
  10209. sizeof(buff5), 0, result, &length));
  10210. buff5[2] = 0x01; buff5[6] = 0x08;
  10211. ExpectIntEQ(WC_NO_ERR_TRACE(BUFFER_ERROR), wolfSSL_SNI_GetFromBuffer(buff5,
  10212. sizeof(buff5), 0, result, &length));
  10213. buff5[6] = 0x09; buff5[8] = 0x01;
  10214. ExpectIntEQ(WC_NO_ERR_TRACE(BUFFER_ERROR), wolfSSL_SNI_GetFromBuffer(buff5,
  10215. sizeof(buff5), 0, result, &length));
  10216. return EXPECT_RESULT();
  10217. }
  10218. #endif /* HAVE_SNI */
  10219. #endif /* HAVE_IO_TESTS_DEPENDENCIES */
  10220. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT) && \
  10221. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  10222. /* Dummy peer functions to satisfy the exporter/importer */
  10223. static int test_wolfSSL_dtls_export_peers_get_peer(WOLFSSL* ssl, char* ip,
  10224. int* ipSz, unsigned short* port, int* fam)
  10225. {
  10226. (void)ssl;
  10227. ip[0] = -1;
  10228. *ipSz = 1;
  10229. *port = 1;
  10230. *fam = 2;
  10231. return 1;
  10232. }
  10233. static int test_wolfSSL_dtls_export_peers_set_peer(WOLFSSL* ssl, char* ip,
  10234. int ipSz, unsigned short port, int fam)
  10235. {
  10236. (void)ssl;
  10237. if (ip[0] != -1 || ipSz != 1 || port != 1 || fam != 2)
  10238. return 0;
  10239. return 1;
  10240. }
  10241. static int test_wolfSSL_dtls_export_peers_on_handshake(WOLFSSL_CTX **ctx,
  10242. WOLFSSL **ssl)
  10243. {
  10244. EXPECT_DECLS;
  10245. unsigned char* sessionBuf = NULL;
  10246. unsigned int sessionSz = 0;
  10247. void* ioWriteCtx = wolfSSL_GetIOWriteCtx(*ssl);
  10248. void* ioReadCtx = wolfSSL_GetIOReadCtx(*ssl);
  10249. wolfSSL_CTX_SetIOGetPeer(*ctx, test_wolfSSL_dtls_export_peers_get_peer);
  10250. wolfSSL_CTX_SetIOSetPeer(*ctx, test_wolfSSL_dtls_export_peers_set_peer);
  10251. ExpectIntGE(wolfSSL_dtls_export(*ssl, NULL, &sessionSz), 0);
  10252. ExpectNotNull(sessionBuf =
  10253. (unsigned char*)XMALLOC(sessionSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER));
  10254. ExpectIntGE(wolfSSL_dtls_export(*ssl, sessionBuf, &sessionSz), 0);
  10255. wolfSSL_free(*ssl);
  10256. *ssl = NULL;
  10257. ExpectNotNull(*ssl = wolfSSL_new(*ctx));
  10258. ExpectIntGE(wolfSSL_dtls_import(*ssl, sessionBuf, sessionSz), 0);
  10259. wolfSSL_SetIOWriteCtx(*ssl, ioWriteCtx);
  10260. wolfSSL_SetIOReadCtx(*ssl, ioReadCtx);
  10261. XFREE(sessionBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10262. return EXPECT_RESULT();
  10263. }
  10264. #endif
  10265. static int test_wolfSSL_dtls_export_peers(void)
  10266. {
  10267. EXPECT_DECLS;
  10268. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT) && \
  10269. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  10270. test_ssl_cbf client_cbf;
  10271. test_ssl_cbf server_cbf;
  10272. size_t i, j;
  10273. struct test_params {
  10274. method_provider client_meth;
  10275. method_provider server_meth;
  10276. const char* dtls_version;
  10277. } params[] = {
  10278. #ifndef NO_OLD_TLS
  10279. {wolfDTLSv1_client_method, wolfDTLSv1_server_method, "1.0"},
  10280. #endif
  10281. {wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, "1.2"},
  10282. /* TODO DTLS 1.3 exporting not supported
  10283. #ifdef WOLFSSL_DTLS13
  10284. {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, "1.3"},
  10285. #endif
  10286. */
  10287. };
  10288. for (i = 0; i < sizeof(params)/sizeof(*params); i++) {
  10289. for (j = 0; j <= 0b11; j++) {
  10290. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  10291. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  10292. printf("\n\tTesting DTLS %s connection;", params[i].dtls_version);
  10293. client_cbf.method = params[i].client_meth;
  10294. server_cbf.method = params[i].server_meth;
  10295. if (j & 0b01) {
  10296. client_cbf.on_handshake =
  10297. test_wolfSSL_dtls_export_peers_on_handshake;
  10298. printf(" With client export;");
  10299. }
  10300. if (j & 0b10) {
  10301. server_cbf.on_handshake =
  10302. test_wolfSSL_dtls_export_peers_on_handshake;
  10303. printf(" With server export;");
  10304. }
  10305. printf("\n");
  10306. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  10307. &server_cbf, NULL), TEST_SUCCESS);
  10308. if (!EXPECT_SUCCESS())
  10309. break;
  10310. }
  10311. }
  10312. #endif
  10313. return EXPECT_RESULT();
  10314. }
  10315. static int test_wolfSSL_UseTrustedCA(void)
  10316. {
  10317. EXPECT_DECLS;
  10318. #if defined(HAVE_TRUSTED_CA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) \
  10319. && !defined(NO_RSA)
  10320. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  10321. WOLFSSL_CTX *ctx = NULL;
  10322. WOLFSSL *ssl = NULL;
  10323. byte id[20];
  10324. #ifndef NO_WOLFSSL_SERVER
  10325. ExpectNotNull((ctx = wolfSSL_CTX_new(wolfSSLv23_server_method())));
  10326. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, WOLFSSL_FILETYPE_PEM));
  10327. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, WOLFSSL_FILETYPE_PEM));
  10328. #else
  10329. ExpectNotNull((ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())));
  10330. #endif
  10331. ExpectNotNull((ssl = wolfSSL_new(ctx)));
  10332. XMEMSET(id, 0, sizeof(id));
  10333. /* error cases */
  10334. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(NULL, 0, NULL, 0));
  10335. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10336. WOLFSSL_TRUSTED_CA_CERT_SHA1+1, NULL, 0));
  10337. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10338. WOLFSSL_TRUSTED_CA_CERT_SHA1, NULL, 0));
  10339. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10340. WOLFSSL_TRUSTED_CA_CERT_SHA1, id, 5));
  10341. #ifdef NO_SHA
  10342. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10343. WOLFSSL_TRUSTED_CA_KEY_SHA1, id, sizeof(id)));
  10344. #endif
  10345. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10346. WOLFSSL_TRUSTED_CA_X509_NAME, id, 0));
  10347. /* success cases */
  10348. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10349. WOLFSSL_TRUSTED_CA_PRE_AGREED, NULL, 0));
  10350. #ifndef NO_SHA
  10351. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10352. WOLFSSL_TRUSTED_CA_KEY_SHA1, id, sizeof(id)));
  10353. #endif
  10354. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10355. WOLFSSL_TRUSTED_CA_X509_NAME, id, 5));
  10356. wolfSSL_free(ssl);
  10357. wolfSSL_CTX_free(ctx);
  10358. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  10359. #endif /* HAVE_TRUSTED_CA */
  10360. return EXPECT_RESULT();
  10361. }
  10362. static int test_wolfSSL_UseMaxFragment(void)
  10363. {
  10364. EXPECT_DECLS;
  10365. #if defined(HAVE_MAX_FRAGMENT) && !defined(NO_CERTS) && \
  10366. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  10367. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  10368. #ifndef NO_WOLFSSL_SERVER
  10369. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfSSLv23_server_method());
  10370. #else
  10371. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10372. #endif
  10373. WOLFSSL *ssl = NULL;
  10374. #ifdef OPENSSL_EXTRA
  10375. int (*UseMaxFragment)(SSL *s, unsigned char mode);
  10376. int (*CTX_UseMaxFragment)(SSL_CTX *c, unsigned char mode);
  10377. #else
  10378. int (*UseMaxFragment)(WOLFSSL *s, unsigned char mode);
  10379. int (*CTX_UseMaxFragment)(WOLFSSL_CTX *c, unsigned char mode);
  10380. #endif
  10381. #ifndef NO_WOLFSSL_SERVER
  10382. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, WOLFSSL_FILETYPE_PEM));
  10383. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, WOLFSSL_FILETYPE_PEM));
  10384. #endif
  10385. ExpectNotNull(ctx);
  10386. ExpectNotNull(ssl = wolfSSL_new(ctx));
  10387. #ifdef OPENSSL_EXTRA
  10388. CTX_UseMaxFragment = SSL_CTX_set_tlsext_max_fragment_length;
  10389. UseMaxFragment = SSL_set_tlsext_max_fragment_length;
  10390. #else
  10391. UseMaxFragment = wolfSSL_UseMaxFragment;
  10392. CTX_UseMaxFragment = wolfSSL_CTX_UseMaxFragment;
  10393. #endif
  10394. /* error cases */
  10395. ExpectIntNE(WOLFSSL_SUCCESS, CTX_UseMaxFragment(NULL, WOLFSSL_MFL_2_9));
  10396. ExpectIntNE(WOLFSSL_SUCCESS, UseMaxFragment( NULL, WOLFSSL_MFL_2_9));
  10397. ExpectIntNE(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_MIN-1));
  10398. ExpectIntNE(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_MAX+1));
  10399. ExpectIntNE(WOLFSSL_SUCCESS, UseMaxFragment(ssl, WOLFSSL_MFL_MIN-1));
  10400. ExpectIntNE(WOLFSSL_SUCCESS, UseMaxFragment(ssl, WOLFSSL_MFL_MAX+1));
  10401. /* success case */
  10402. #ifdef OPENSSL_EXTRA
  10403. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_8));
  10404. #else
  10405. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_8));
  10406. #endif
  10407. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_9));
  10408. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_10));
  10409. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_11));
  10410. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_12));
  10411. #ifdef OPENSSL_EXTRA
  10412. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_13));
  10413. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), UseMaxFragment( ssl, WOLFSSL_MFL_2_8));
  10414. #else
  10415. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_13));
  10416. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_8));
  10417. #endif
  10418. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_9));
  10419. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_10));
  10420. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_11));
  10421. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_12));
  10422. #ifdef OPENSSL_EXTRA
  10423. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), UseMaxFragment( ssl, WOLFSSL_MFL_2_13));
  10424. #else
  10425. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_13));
  10426. #endif
  10427. wolfSSL_free(ssl);
  10428. wolfSSL_CTX_free(ctx);
  10429. #if defined(OPENSSL_EXTRA) && defined(HAVE_MAX_FRAGMENT) && \
  10430. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  10431. /* check negotiated max fragment size */
  10432. {
  10433. WOLFSSL *ssl_c = NULL;
  10434. WOLFSSL *ssl_s = NULL;
  10435. struct test_memio_ctx test_ctx;
  10436. WOLFSSL_CTX *ctx_c = NULL;
  10437. WOLFSSL_CTX *ctx_s = NULL;
  10438. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  10439. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  10440. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  10441. ExpectIntEQ(wolfSSL_UseMaxFragment(ssl_c, WOLFSSL_MFL_2_8),
  10442. WOLFSSL_SUCCESS);
  10443. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  10444. #ifndef NO_SESSION_CACHE
  10445. ExpectIntEQ(SSL_SESSION_get_max_fragment_length(
  10446. wolfSSL_get_session(ssl_c)), WOLFSSL_MFL_2_8);
  10447. #endif
  10448. wolfSSL_free(ssl_c);
  10449. wolfSSL_free(ssl_s);
  10450. wolfSSL_CTX_free(ctx_c);
  10451. wolfSSL_CTX_free(ctx_s);
  10452. }
  10453. #endif
  10454. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  10455. #endif
  10456. return EXPECT_RESULT();
  10457. }
  10458. static int test_wolfSSL_UseTruncatedHMAC(void)
  10459. {
  10460. EXPECT_DECLS;
  10461. #if defined(HAVE_TRUNCATED_HMAC) && !defined(NO_CERTS) && \
  10462. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  10463. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  10464. #ifndef NO_WOLFSSL_SERVER
  10465. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfSSLv23_server_method());
  10466. #else
  10467. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10468. #endif
  10469. WOLFSSL *ssl = NULL;
  10470. ExpectNotNull(ctx);
  10471. #ifndef NO_WOLFSSL_SERVER
  10472. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, WOLFSSL_FILETYPE_PEM));
  10473. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, WOLFSSL_FILETYPE_PEM));
  10474. #endif
  10475. ExpectNotNull(ssl = wolfSSL_new(ctx));
  10476. /* error cases */
  10477. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseTruncatedHMAC(NULL));
  10478. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTruncatedHMAC(NULL));
  10479. /* success case */
  10480. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseTruncatedHMAC(ctx));
  10481. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseTruncatedHMAC(ssl));
  10482. wolfSSL_free(ssl);
  10483. wolfSSL_CTX_free(ctx);
  10484. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  10485. #endif
  10486. return EXPECT_RESULT();
  10487. }
  10488. static int test_wolfSSL_UseSupportedCurve(void)
  10489. {
  10490. EXPECT_DECLS;
  10491. #if defined(HAVE_SUPPORTED_CURVES) && !defined(NO_WOLFSSL_CLIENT) && \
  10492. !defined(NO_TLS)
  10493. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10494. WOLFSSL *ssl = wolfSSL_new(ctx);
  10495. ExpectNotNull(ctx);
  10496. ExpectNotNull(ssl);
  10497. /* error cases */
  10498. ExpectIntNE(WOLFSSL_SUCCESS,
  10499. wolfSSL_CTX_UseSupportedCurve(NULL, WOLFSSL_ECC_SECP256R1));
  10500. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSupportedCurve(ctx, 0));
  10501. ExpectIntNE(WOLFSSL_SUCCESS,
  10502. wolfSSL_UseSupportedCurve(NULL, WOLFSSL_ECC_SECP256R1));
  10503. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSupportedCurve(ssl, 0));
  10504. /* success case */
  10505. ExpectIntEQ(WOLFSSL_SUCCESS,
  10506. wolfSSL_CTX_UseSupportedCurve(ctx, WOLFSSL_ECC_SECP256R1));
  10507. ExpectIntEQ(WOLFSSL_SUCCESS,
  10508. wolfSSL_UseSupportedCurve(ssl, WOLFSSL_ECC_SECP256R1));
  10509. wolfSSL_free(ssl);
  10510. wolfSSL_CTX_free(ctx);
  10511. #endif
  10512. return EXPECT_RESULT();
  10513. }
  10514. #if defined(HAVE_ALPN) && defined(HAVE_IO_TESTS_DEPENDENCIES)
  10515. static void verify_ALPN_FATAL_ERROR_on_client(WOLFSSL* ssl)
  10516. {
  10517. AssertIntEQ(WC_NO_ERR_TRACE(UNKNOWN_ALPN_PROTOCOL_NAME_E), wolfSSL_get_error(ssl, 0));
  10518. }
  10519. static void use_ALPN_all(WOLFSSL* ssl)
  10520. {
  10521. /* http/1.1,spdy/1,spdy/2,spdy/3 */
  10522. char alpn_list[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31, 0x2c,
  10523. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x31, 0x2c,
  10524. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x32, 0x2c,
  10525. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10526. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, alpn_list, sizeof(alpn_list),
  10527. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10528. }
  10529. static void use_ALPN_all_continue(WOLFSSL* ssl)
  10530. {
  10531. /* http/1.1,spdy/1,spdy/2,spdy/3 */
  10532. char alpn_list[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31, 0x2c,
  10533. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x31, 0x2c,
  10534. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x32, 0x2c,
  10535. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10536. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, alpn_list, sizeof(alpn_list),
  10537. WOLFSSL_ALPN_CONTINUE_ON_MISMATCH));
  10538. }
  10539. static void use_ALPN_one(WOLFSSL* ssl)
  10540. {
  10541. /* spdy/2 */
  10542. char proto[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x32};
  10543. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, proto, sizeof(proto),
  10544. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10545. }
  10546. static void use_ALPN_unknown(WOLFSSL* ssl)
  10547. {
  10548. /* http/2.0 */
  10549. char proto[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x32, 0x2e, 0x30};
  10550. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, proto, sizeof(proto),
  10551. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10552. }
  10553. static void use_ALPN_unknown_continue(WOLFSSL* ssl)
  10554. {
  10555. /* http/2.0 */
  10556. char proto[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x32, 0x2e, 0x30};
  10557. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, proto, sizeof(proto),
  10558. WOLFSSL_ALPN_CONTINUE_ON_MISMATCH));
  10559. }
  10560. static void verify_ALPN_not_matching_spdy3(WOLFSSL* ssl)
  10561. {
  10562. /* spdy/3 */
  10563. char nego_proto[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10564. char *proto = NULL;
  10565. word16 protoSz = 0;
  10566. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_ALPN_GetProtocol(ssl, &proto, &protoSz));
  10567. /* check value */
  10568. AssertIntNE(1, sizeof(nego_proto) == protoSz);
  10569. if (proto) {
  10570. AssertIntNE(0, XMEMCMP(nego_proto, proto, sizeof(nego_proto)));
  10571. }
  10572. }
  10573. static void verify_ALPN_not_matching_continue(WOLFSSL* ssl)
  10574. {
  10575. char *proto = NULL;
  10576. word16 protoSz = 0;
  10577. AssertIntEQ(WC_NO_ERR_TRACE(WOLFSSL_ALPN_NOT_FOUND),
  10578. wolfSSL_ALPN_GetProtocol(ssl, &proto, &protoSz));
  10579. /* check value */
  10580. AssertIntEQ(1, (0 == protoSz));
  10581. AssertIntEQ(1, (NULL == proto));
  10582. }
  10583. static void verify_ALPN_matching_http1(WOLFSSL* ssl)
  10584. {
  10585. /* http/1.1 */
  10586. char nego_proto[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31};
  10587. char *proto;
  10588. word16 protoSz = 0;
  10589. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_ALPN_GetProtocol(ssl, &proto, &protoSz));
  10590. /* check value */
  10591. AssertIntEQ(1, sizeof(nego_proto) == protoSz);
  10592. AssertIntEQ(0, XMEMCMP(nego_proto, proto, protoSz));
  10593. }
  10594. static void verify_ALPN_matching_spdy2(WOLFSSL* ssl)
  10595. {
  10596. /* spdy/2 */
  10597. char nego_proto[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x32};
  10598. char *proto;
  10599. word16 protoSz = 0;
  10600. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_ALPN_GetProtocol(ssl, &proto, &protoSz));
  10601. /* check value */
  10602. AssertIntEQ(1, sizeof(nego_proto) == protoSz);
  10603. AssertIntEQ(0, XMEMCMP(nego_proto, proto, protoSz));
  10604. }
  10605. static void verify_ALPN_client_list(WOLFSSL* ssl)
  10606. {
  10607. /* http/1.1,spdy/1,spdy/2,spdy/3 */
  10608. char alpn_list[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31, 0x2c,
  10609. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x31, 0x2c,
  10610. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x32, 0x2c,
  10611. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10612. char *clist = NULL;
  10613. word16 clistSz = 0;
  10614. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_ALPN_GetPeerProtocol(ssl, &clist,
  10615. &clistSz));
  10616. /* check value */
  10617. AssertIntEQ(1, sizeof(alpn_list) == clistSz);
  10618. AssertIntEQ(0, XMEMCMP(alpn_list, clist, clistSz));
  10619. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_ALPN_FreePeerProtocol(ssl, &clist));
  10620. }
  10621. #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \
  10622. defined(WOLFSSL_HAPROXY) || defined(HAVE_LIGHTY)
  10623. /* ALPN select callback, success with spdy/2 */
  10624. static int select_ALPN_spdy2(WOLFSSL *ssl, const unsigned char **out,
  10625. unsigned char *outlen, const unsigned char *in,
  10626. unsigned int inlen, void *arg)
  10627. {
  10628. /* spdy/2 */
  10629. const char proto[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x32};
  10630. (void)ssl;
  10631. (void)arg;
  10632. /* adding +1 since LEN byte comes first */
  10633. if (inlen < sizeof(proto) + 1) {
  10634. return SSL_TLSEXT_ERR_ALERT_FATAL;
  10635. }
  10636. if (XMEMCMP(in + 1, proto, sizeof(proto)) == 0) {
  10637. *out = in + 1;
  10638. *outlen = (unsigned char)sizeof(proto);
  10639. return SSL_TLSEXT_ERR_OK;
  10640. }
  10641. return SSL_TLSEXT_ERR_ALERT_FATAL;
  10642. }
  10643. /* ALPN select callback, force failure */
  10644. static int select_ALPN_failure(WOLFSSL *ssl, const unsigned char **out,
  10645. unsigned char *outlen, const unsigned char *in,
  10646. unsigned int inlen, void *arg)
  10647. {
  10648. (void)ssl;
  10649. (void)out;
  10650. (void)outlen;
  10651. (void)in;
  10652. (void)inlen;
  10653. (void)arg;
  10654. return SSL_TLSEXT_ERR_ALERT_FATAL;
  10655. }
  10656. static void use_ALPN_spdy2_callback(WOLFSSL* ssl)
  10657. {
  10658. wolfSSL_set_alpn_select_cb(ssl, select_ALPN_spdy2, NULL);
  10659. }
  10660. static void use_ALPN_failure_callback(WOLFSSL* ssl)
  10661. {
  10662. wolfSSL_set_alpn_select_cb(ssl, select_ALPN_failure, NULL);
  10663. }
  10664. #endif /* OPENSSL_ALL | NGINX | HAPROXY | LIGHTY | QUIC */
  10665. static int test_wolfSSL_UseALPN_connection(void)
  10666. {
  10667. int res = TEST_SKIPPED;
  10668. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  10669. callback_functions client_cb;
  10670. callback_functions server_cb;
  10671. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  10672. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  10673. client_cb.method = wolfSSLv23_client_method;
  10674. server_cb.method = wolfSSLv23_server_method;
  10675. client_cb.devId = testDevId;
  10676. server_cb.devId = testDevId;
  10677. /* success case same list */
  10678. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all; client_cb.on_result = NULL;
  10679. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_all; server_cb.on_result = verify_ALPN_matching_http1;
  10680. test_wolfSSL_client_server(&client_cb, &server_cb);
  10681. /* success case only one for server */
  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_one; server_cb.on_result = verify_ALPN_matching_spdy2;
  10684. test_wolfSSL_client_server(&client_cb, &server_cb);
  10685. /* success case only one for client */
  10686. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_one; client_cb.on_result = NULL;
  10687. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_all; server_cb.on_result = verify_ALPN_matching_spdy2;
  10688. test_wolfSSL_client_server(&client_cb, &server_cb);
  10689. /* success case none for client */
  10690. client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
  10691. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_all; server_cb.on_result = NULL;
  10692. test_wolfSSL_client_server(&client_cb, &server_cb);
  10693. /* success case mismatch behavior but option 'continue' set */
  10694. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all_continue; client_cb.on_result = verify_ALPN_not_matching_continue;
  10695. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_unknown_continue; server_cb.on_result = NULL;
  10696. test_wolfSSL_client_server(&client_cb, &server_cb);
  10697. /* success case read protocol send by client */
  10698. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all; client_cb.on_result = NULL;
  10699. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_one; server_cb.on_result = verify_ALPN_client_list;
  10700. test_wolfSSL_client_server(&client_cb, &server_cb);
  10701. /* mismatch behavior with same list
  10702. * the first and only this one must be taken */
  10703. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all; client_cb.on_result = NULL;
  10704. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_all; server_cb.on_result = verify_ALPN_not_matching_spdy3;
  10705. test_wolfSSL_client_server(&client_cb, &server_cb);
  10706. /* default mismatch behavior */
  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_unknown; server_cb.on_result = verify_ALPN_FATAL_ERROR_on_client;
  10709. test_wolfSSL_client_server(&client_cb, &server_cb);
  10710. #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \
  10711. defined(WOLFSSL_HAPROXY) || defined(HAVE_LIGHTY)
  10712. /* WOLFSSL-level ALPN select callback tests */
  10713. /* Callback: success (one protocol, spdy/2) */
  10714. client_cb.ctx_ready = NULL;
  10715. client_cb.ssl_ready = use_ALPN_one;
  10716. client_cb.on_result = verify_ALPN_matching_spdy2;
  10717. server_cb.ctx_ready = NULL;
  10718. server_cb.ssl_ready = use_ALPN_spdy2_callback;
  10719. server_cb.on_result = verify_ALPN_matching_spdy2;
  10720. test_wolfSSL_client_server(&client_cb, &server_cb);
  10721. /* Callback: failure (one client protocol, spdy/2) */
  10722. client_cb.ctx_ready = NULL;
  10723. client_cb.ssl_ready = use_ALPN_one;
  10724. client_cb.on_result = NULL;
  10725. server_cb.ctx_ready = NULL;
  10726. server_cb.ssl_ready = use_ALPN_failure_callback;
  10727. server_cb.on_result = verify_ALPN_FATAL_ERROR_on_client;
  10728. test_wolfSSL_client_server(&client_cb, &server_cb);
  10729. #endif /* OPENSSL_ALL | NGINX | HAPROXY | LIGHTY */
  10730. res = TEST_RES_CHECK(1);
  10731. #endif /* !NO_WOLFSSL_CLIENT && !NO_WOLFSSL_SERVER */
  10732. return res;
  10733. }
  10734. static int test_wolfSSL_UseALPN_params(void)
  10735. {
  10736. EXPECT_DECLS;
  10737. #ifndef NO_WOLFSSL_CLIENT
  10738. /* "http/1.1" */
  10739. char http1[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31};
  10740. /* "spdy/1" */
  10741. char spdy1[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x31};
  10742. /* "spdy/2" */
  10743. char spdy2[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x32};
  10744. /* "spdy/3" */
  10745. char spdy3[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10746. char buff[256];
  10747. word32 idx;
  10748. WOLFSSL_CTX *ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10749. WOLFSSL *ssl = wolfSSL_new(ctx);
  10750. ExpectNotNull(ctx);
  10751. ExpectNotNull(ssl);
  10752. /* error cases */
  10753. ExpectIntNE(WOLFSSL_SUCCESS,
  10754. wolfSSL_UseALPN(NULL, http1, sizeof(http1),
  10755. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10756. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, NULL, 0,
  10757. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10758. /* success case */
  10759. /* http1 only */
  10760. ExpectIntEQ(WOLFSSL_SUCCESS,
  10761. wolfSSL_UseALPN(ssl, http1, sizeof(http1),
  10762. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10763. /* http1, spdy1 */
  10764. XMEMCPY(buff, http1, sizeof(http1));
  10765. idx = sizeof(http1);
  10766. buff[idx++] = ',';
  10767. XMEMCPY(buff+idx, spdy1, sizeof(spdy1));
  10768. idx += sizeof(spdy1);
  10769. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, buff, idx,
  10770. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10771. /* http1, spdy2, spdy1 */
  10772. XMEMCPY(buff, http1, sizeof(http1));
  10773. idx = sizeof(http1);
  10774. buff[idx++] = ',';
  10775. XMEMCPY(buff+idx, spdy2, sizeof(spdy2));
  10776. idx += sizeof(spdy2);
  10777. buff[idx++] = ',';
  10778. XMEMCPY(buff+idx, spdy1, sizeof(spdy1));
  10779. idx += sizeof(spdy1);
  10780. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, buff, idx,
  10781. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10782. /* spdy3, http1, spdy2, spdy1 */
  10783. XMEMCPY(buff, spdy3, sizeof(spdy3));
  10784. idx = sizeof(spdy3);
  10785. buff[idx++] = ',';
  10786. XMEMCPY(buff+idx, http1, sizeof(http1));
  10787. idx += sizeof(http1);
  10788. buff[idx++] = ',';
  10789. XMEMCPY(buff+idx, spdy2, sizeof(spdy2));
  10790. idx += sizeof(spdy2);
  10791. buff[idx++] = ',';
  10792. XMEMCPY(buff+idx, spdy1, sizeof(spdy1));
  10793. idx += sizeof(spdy1);
  10794. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, buff, idx,
  10795. WOLFSSL_ALPN_CONTINUE_ON_MISMATCH));
  10796. wolfSSL_free(ssl);
  10797. wolfSSL_CTX_free(ctx);
  10798. #endif
  10799. return EXPECT_RESULT();
  10800. }
  10801. #endif /* HAVE_ALPN */
  10802. #ifdef HAVE_ALPN_PROTOS_SUPPORT
  10803. static void CTX_set_alpn_protos(SSL_CTX *ctx)
  10804. {
  10805. unsigned char p[] = {
  10806. 8, 'h', 't', 't', 'p', '/', '1', '.', '1',
  10807. 6, 's', 'p', 'd', 'y', '/', '2',
  10808. 6, 's', 'p', 'd', 'y', '/', '1',
  10809. };
  10810. unsigned char p_len = sizeof(p);
  10811. int ret;
  10812. ret = SSL_CTX_set_alpn_protos(ctx, p, p_len);
  10813. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  10814. AssertIntEQ(ret, 0);
  10815. #else
  10816. AssertIntEQ(ret, SSL_SUCCESS);
  10817. #endif
  10818. }
  10819. static void set_alpn_protos(SSL* ssl)
  10820. {
  10821. unsigned char p[] = {
  10822. 6, 's', 'p', 'd', 'y', '/', '3',
  10823. 8, 'h', 't', 't', 'p', '/', '1', '.', '1',
  10824. 6, 's', 'p', 'd', 'y', '/', '2',
  10825. 6, 's', 'p', 'd', 'y', '/', '1',
  10826. };
  10827. unsigned char p_len = sizeof(p);
  10828. int ret;
  10829. ret = SSL_set_alpn_protos(ssl, p, p_len);
  10830. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  10831. AssertIntEQ(ret, 0);
  10832. #else
  10833. AssertIntEQ(ret, SSL_SUCCESS);
  10834. #endif
  10835. }
  10836. static void verify_alpn_matching_spdy3(WOLFSSL* ssl)
  10837. {
  10838. /* "spdy/3" */
  10839. char nego_proto[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10840. const unsigned char *proto;
  10841. unsigned int protoSz = 0;
  10842. SSL_get0_alpn_selected(ssl, &proto, &protoSz);
  10843. /* check value */
  10844. AssertIntEQ(1, sizeof(nego_proto) == protoSz);
  10845. AssertIntEQ(0, XMEMCMP(nego_proto, proto, protoSz));
  10846. }
  10847. static void verify_alpn_matching_http1(WOLFSSL* ssl)
  10848. {
  10849. /* "http/1.1" */
  10850. char nego_proto[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31};
  10851. const unsigned char *proto;
  10852. unsigned int protoSz = 0;
  10853. SSL_get0_alpn_selected(ssl, &proto, &protoSz);
  10854. /* check value */
  10855. AssertIntEQ(1, sizeof(nego_proto) == protoSz);
  10856. AssertIntEQ(0, XMEMCMP(nego_proto, proto, protoSz));
  10857. }
  10858. static int test_wolfSSL_set_alpn_protos(void)
  10859. {
  10860. int res = TEST_SKIPPED;
  10861. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  10862. callback_functions client_cb;
  10863. callback_functions server_cb;
  10864. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  10865. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  10866. client_cb.method = wolfSSLv23_client_method;
  10867. server_cb.method = wolfSSLv23_server_method;
  10868. client_cb.devId = testDevId;
  10869. server_cb.devId = testDevId;
  10870. /* use CTX_alpn_protos */
  10871. client_cb.ctx_ready = CTX_set_alpn_protos; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
  10872. server_cb.ctx_ready = CTX_set_alpn_protos; server_cb.ssl_ready = NULL; server_cb.on_result = verify_alpn_matching_http1;
  10873. test_wolfSSL_client_server(&client_cb, &server_cb);
  10874. /* use set_alpn_protos */
  10875. client_cb.ctx_ready = NULL; client_cb.ssl_ready = set_alpn_protos; client_cb.on_result = NULL;
  10876. server_cb.ctx_ready = NULL; server_cb.ssl_ready = set_alpn_protos; server_cb.on_result = verify_alpn_matching_spdy3;
  10877. test_wolfSSL_client_server(&client_cb, &server_cb);
  10878. res = TEST_SUCCESS;
  10879. #endif /* !NO_WOLFSSL_CLIENT && !NO_WOLFSSL_SERVER */
  10880. return res;
  10881. }
  10882. #endif /* HAVE_ALPN_PROTOS_SUPPORT */
  10883. static int test_wolfSSL_DisableExtendedMasterSecret(void)
  10884. {
  10885. EXPECT_DECLS;
  10886. #if defined(HAVE_EXTENDED_MASTER) && !defined(NO_WOLFSSL_CLIENT)
  10887. WOLFSSL_CTX *ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10888. WOLFSSL *ssl = wolfSSL_new(ctx);
  10889. ExpectNotNull(ctx);
  10890. ExpectNotNull(ssl);
  10891. /* error cases */
  10892. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_DisableExtendedMasterSecret(NULL));
  10893. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_DisableExtendedMasterSecret(NULL));
  10894. /* success cases */
  10895. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_DisableExtendedMasterSecret(ctx));
  10896. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_DisableExtendedMasterSecret(ssl));
  10897. wolfSSL_free(ssl);
  10898. wolfSSL_CTX_free(ctx);
  10899. #endif
  10900. return EXPECT_RESULT();
  10901. }
  10902. static int test_wolfSSL_wolfSSL_UseSecureRenegotiation(void)
  10903. {
  10904. EXPECT_DECLS;
  10905. #if defined(HAVE_SECURE_RENEGOTIATION) && !defined(NO_WOLFSSL_CLIENT)
  10906. WOLFSSL_CTX *ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10907. WOLFSSL *ssl = wolfSSL_new(ctx);
  10908. ExpectNotNull(ctx);
  10909. ExpectNotNull(ssl);
  10910. /* error cases */
  10911. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSecureRenegotiation(NULL));
  10912. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSecureRenegotiation(NULL));
  10913. /* success cases */
  10914. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSecureRenegotiation(ctx));
  10915. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSecureRenegotiation(ssl));
  10916. wolfSSL_free(ssl);
  10917. wolfSSL_CTX_free(ctx);
  10918. #endif
  10919. return EXPECT_RESULT();
  10920. }
  10921. /* Test reconnecting with a different ciphersuite after a renegotiation. */
  10922. static int test_wolfSSL_SCR_Reconnect(void)
  10923. {
  10924. EXPECT_DECLS;
  10925. #if defined(HAVE_SECURE_RENEGOTIATION) && \
  10926. defined(BUILD_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) && \
  10927. defined(BUILD_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256) && \
  10928. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  10929. struct test_memio_ctx test_ctx;
  10930. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  10931. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  10932. byte data;
  10933. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  10934. test_ctx.c_ciphers = "ECDHE-RSA-AES256-GCM-SHA384";
  10935. test_ctx.s_ciphers =
  10936. "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-CHACHA20-POLY1305";
  10937. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  10938. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  10939. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSecureRenegotiation(ctx_c));
  10940. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSecureRenegotiation(ctx_s));
  10941. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSecureRenegotiation(ssl_c));
  10942. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSecureRenegotiation(ssl_s));
  10943. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  10944. /* WOLFSSL_FATAL_ERROR since it will block */
  10945. ExpectIntEQ(wolfSSL_Rehandshake(ssl_s), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  10946. ExpectIntEQ(wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  10947. WOLFSSL_ERROR_WANT_READ);
  10948. ExpectIntEQ(wolfSSL_read(ssl_c, &data, 1), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  10949. ExpectIntEQ(wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  10950. WOLFSSL_ERROR_WANT_READ);
  10951. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  10952. wolfSSL_free(ssl_c);
  10953. ssl_c = NULL;
  10954. wolfSSL_free(ssl_s);
  10955. ssl_s = NULL;
  10956. wolfSSL_CTX_free(ctx_c);
  10957. ctx_c = NULL;
  10958. test_ctx.c_ciphers = "ECDHE-RSA-CHACHA20-POLY1305";
  10959. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  10960. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  10961. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  10962. wolfSSL_free(ssl_s);
  10963. wolfSSL_free(ssl_c);
  10964. wolfSSL_CTX_free(ctx_s);
  10965. wolfSSL_CTX_free(ctx_c);
  10966. #endif
  10967. return EXPECT_RESULT();
  10968. }
  10969. #if !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_SERVER) && \
  10970. (!defined(NO_RSA) || defined(HAVE_ECC))
  10971. /* Called when writing. */
  10972. static int DummySend(WOLFSSL* ssl, char* buf, int sz, void* ctx)
  10973. {
  10974. (void)ssl;
  10975. (void)buf;
  10976. (void)sz;
  10977. (void)ctx;
  10978. /* Force error return from wolfSSL_accept_TLSv13(). */
  10979. return WANT_WRITE;
  10980. }
  10981. /* Called when reading. */
  10982. static int BufferInfoRecv(WOLFSSL* ssl, char* buf, int sz, void* ctx)
  10983. {
  10984. WOLFSSL_BUFFER_INFO* msg = (WOLFSSL_BUFFER_INFO*)ctx;
  10985. int len = (int)msg->length;
  10986. (void)ssl;
  10987. (void)sz;
  10988. /* Pass back as much of message as will fit in buffer. */
  10989. if (len > sz)
  10990. len = sz;
  10991. XMEMCPY(buf, msg->buffer, len);
  10992. /* Move over returned data. */
  10993. msg->buffer += len;
  10994. msg->length -= len;
  10995. /* Amount actually copied. */
  10996. return len;
  10997. }
  10998. #endif
  10999. /* Test the detection of duplicate known TLS extensions.
  11000. * Specifically in a ClientHello.
  11001. */
  11002. static int test_tls_ext_duplicate(void)
  11003. {
  11004. EXPECT_DECLS;
  11005. #if !defined(NO_WOLFSSL_SERVER) && (!defined(NO_RSA) || defined(HAVE_ECC)) && \
  11006. !defined(NO_FILESYSTEM)
  11007. const unsigned char clientHelloDupTlsExt[] = {
  11008. 0x16, 0x03, 0x03, 0x00, 0x6a, 0x01, 0x00, 0x00,
  11009. 0x66, 0x03, 0x03, 0xf4, 0x65, 0xbd, 0x22, 0xfe,
  11010. 0x6e, 0xab, 0x66, 0xdd, 0xcf, 0xe9, 0x65, 0x55,
  11011. 0xe8, 0xdf, 0xc3, 0x8e, 0x4b, 0x00, 0xbc, 0xf8,
  11012. 0x23, 0x57, 0x1b, 0xa0, 0xc8, 0xa9, 0xe2, 0x8c,
  11013. 0x91, 0x6e, 0xf9, 0x20, 0xf7, 0x5c, 0xc5, 0x5b,
  11014. 0x75, 0x8c, 0x47, 0x0a, 0x0e, 0xc4, 0x1a, 0xda,
  11015. 0xef, 0x75, 0xe5, 0x21, 0x00, 0x00, 0x00, 0x00,
  11016. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  11017. 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x13, 0x01,
  11018. 0x00, 0x9e, 0x01, 0x00,
  11019. /* Extensions - duplicate signature algorithms. */
  11020. 0x00, 0x19, 0x00, 0x0d,
  11021. 0x00, 0x04, 0x00, 0x02, 0x04, 0x01, 0x00, 0x0d,
  11022. 0x00, 0x04, 0x00, 0x02, 0x04, 0x01,
  11023. /* Supported Versions extension for TLS 1.3. */
  11024. 0x00, 0x2b,
  11025. 0x00, 0x05, 0x04, 0x03, 0x04, 0x03, 0x03
  11026. };
  11027. WOLFSSL_BUFFER_INFO msg;
  11028. const char* testCertFile;
  11029. const char* testKeyFile;
  11030. WOLFSSL_CTX *ctx = NULL;
  11031. WOLFSSL *ssl = NULL;
  11032. #ifndef NO_RSA
  11033. testCertFile = svrCertFile;
  11034. testKeyFile = svrKeyFile;
  11035. #elif defined(HAVE_ECC)
  11036. testCertFile = eccCertFile;
  11037. testKeyFile = eccKeyFile;
  11038. #endif
  11039. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  11040. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  11041. WOLFSSL_FILETYPE_PEM));
  11042. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  11043. WOLFSSL_FILETYPE_PEM));
  11044. /* Read from 'msg'. */
  11045. wolfSSL_SetIORecv(ctx, BufferInfoRecv);
  11046. /* No where to send to - dummy sender. */
  11047. wolfSSL_SetIOSend(ctx, DummySend);
  11048. ssl = wolfSSL_new(ctx);
  11049. ExpectNotNull(ssl);
  11050. msg.buffer = (unsigned char*)clientHelloDupTlsExt;
  11051. msg.length = (unsigned int)sizeof(clientHelloDupTlsExt);
  11052. wolfSSL_SetIOReadCtx(ssl, &msg);
  11053. ExpectIntNE(wolfSSL_accept(ssl), WOLFSSL_SUCCESS);
  11054. /* can return duplicate ext error or socket error if the peer closed down
  11055. * while sending alert */
  11056. if (wolfSSL_get_error(ssl, 0) != WC_NO_ERR_TRACE(SOCKET_ERROR_E)) {
  11057. ExpectIntEQ(wolfSSL_get_error(ssl, 0), WC_NO_ERR_TRACE(DUPLICATE_TLS_EXT_E));
  11058. }
  11059. wolfSSL_free(ssl);
  11060. wolfSSL_CTX_free(ctx);
  11061. #endif
  11062. return EXPECT_RESULT();
  11063. }
  11064. /*----------------------------------------------------------------------------*
  11065. | X509 Tests
  11066. *----------------------------------------------------------------------------*/
  11067. static int test_wolfSSL_X509_NAME_get_entry(void)
  11068. {
  11069. EXPECT_DECLS;
  11070. #if !defined(NO_CERTS) && !defined(NO_RSA)
  11071. #if defined(OPENSSL_ALL) || \
  11072. (defined(OPENSSL_EXTRA) && \
  11073. (defined(KEEP_PEER_CERT) || defined(SESSION_CERTS)))
  11074. /* use openssl like name to test mapping */
  11075. X509_NAME_ENTRY* ne = NULL;
  11076. X509_NAME* name = NULL;
  11077. X509* x509 = NULL;
  11078. #ifndef NO_FILESYSTEM
  11079. ASN1_STRING* asn = NULL;
  11080. char* subCN = NULL;
  11081. #endif
  11082. int idx = 0;
  11083. ASN1_OBJECT *object = NULL;
  11084. #if defined(WOLFSSL_APACHE_HTTPD) || defined(OPENSSL_ALL) || \
  11085. defined(WOLFSSL_NGINX)
  11086. #ifndef NO_BIO
  11087. BIO* bio = NULL;
  11088. #endif
  11089. #endif
  11090. #ifndef NO_FILESYSTEM
  11091. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  11092. WOLFSSL_FILETYPE_PEM));
  11093. ExpectNotNull(name = X509_get_subject_name(x509));
  11094. ExpectIntGE(idx = X509_NAME_get_index_by_NID(name, NID_commonName, -1), 0);
  11095. ExpectNotNull(ne = X509_NAME_get_entry(name, idx));
  11096. ExpectNotNull(asn = X509_NAME_ENTRY_get_data(ne));
  11097. ExpectNotNull(subCN = (char*)ASN1_STRING_data(asn));
  11098. wolfSSL_FreeX509(x509);
  11099. x509 = NULL;
  11100. #endif
  11101. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  11102. WOLFSSL_FILETYPE_PEM));
  11103. ExpectNotNull(name = X509_get_subject_name(x509));
  11104. ExpectIntGE(idx = X509_NAME_get_index_by_NID(name, NID_commonName, -1), 0);
  11105. #if defined(WOLFSSL_APACHE_HTTPD) || defined(OPENSSL_ALL) || \
  11106. defined(WOLFSSL_NGINX)
  11107. #ifndef NO_BIO
  11108. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  11109. ExpectIntEQ(X509_NAME_print_ex(bio, name, 4,
  11110. (XN_FLAG_RFC2253 & ~XN_FLAG_DN_REV)), WOLFSSL_SUCCESS);
  11111. ExpectIntEQ(X509_NAME_print_ex_fp(stderr, name, 4,
  11112. (XN_FLAG_RFC2253 & ~XN_FLAG_DN_REV)), WOLFSSL_SUCCESS);
  11113. BIO_free(bio);
  11114. #endif
  11115. #endif
  11116. ExpectNotNull(ne = X509_NAME_get_entry(name, idx));
  11117. ExpectNotNull(object = X509_NAME_ENTRY_get_object(ne));
  11118. wolfSSL_FreeX509(x509);
  11119. #endif /* OPENSSL_ALL || (OPENSSL_EXTRA && (KEEP_PEER_CERT || SESSION_CERTS) */
  11120. #endif /* !NO_CERTS && !NO_RSA */
  11121. return EXPECT_RESULT();
  11122. }
  11123. /* Testing functions dealing with PKCS12 parsing out X509 certs */
  11124. static int test_wolfSSL_PKCS12(void)
  11125. {
  11126. EXPECT_DECLS;
  11127. /* .p12 file is encrypted with DES3 */
  11128. #ifndef HAVE_FIPS /* Password used in cert "wolfSSL test" is only 12-bytes
  11129. * (96-bit) FIPS mode requires Minimum of 14-byte (112-bit)
  11130. * Password Key
  11131. */
  11132. #if defined(OPENSSL_EXTRA) && !defined(NO_DES3) && !defined(NO_FILESYSTEM) && \
  11133. !defined(NO_STDIO_FILESYSTEM) && \
  11134. !defined(NO_ASN) && !defined(NO_PWDBASED) && !defined(NO_RSA) && \
  11135. !defined(NO_SHA) && defined(HAVE_PKCS12) && !defined(NO_BIO)
  11136. byte buf[6000];
  11137. char file[] = "./certs/test-servercert.p12";
  11138. char order[] = "./certs/ecc-rsa-server.p12";
  11139. #ifdef WC_RC2
  11140. char rc2p12[] = "./certs/test-servercert-rc2.p12";
  11141. #endif
  11142. char pass[] = "a password";
  11143. const char goodPsw[] = "wolfSSL test";
  11144. const char badPsw[] = "bad";
  11145. #ifdef HAVE_ECC
  11146. WOLFSSL_X509_NAME *subject = NULL;
  11147. WOLFSSL_X509 *x509 = NULL;
  11148. #endif
  11149. XFILE f = XBADFILE;
  11150. int bytes = 0, ret = 0, goodPswLen = 0, badPswLen = 0;
  11151. WOLFSSL_BIO *bio = NULL;
  11152. WOLFSSL_EVP_PKEY *pkey = NULL;
  11153. WC_PKCS12 *pkcs12 = NULL;
  11154. WC_PKCS12 *pkcs12_2 = NULL;
  11155. WOLFSSL_X509 *cert = NULL;
  11156. WOLFSSL_X509 *tmp = NULL;
  11157. WOLF_STACK_OF(WOLFSSL_X509) *ca = NULL;
  11158. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO) || defined(WOLFSSL_HAPROXY) \
  11159. || defined(WOLFSSL_NGINX)) && defined(SESSION_CERTS)
  11160. WOLFSSL_CTX *ctx = NULL;
  11161. WOLFSSL *ssl = NULL;
  11162. WOLF_STACK_OF(WOLFSSL_X509) *tmp_ca = NULL;
  11163. #endif
  11164. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  11165. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  11166. if (f != XBADFILE) {
  11167. XFCLOSE(f);
  11168. f = XBADFILE;
  11169. }
  11170. goodPswLen = (int)XSTRLEN(goodPsw);
  11171. badPswLen = (int)XSTRLEN(badPsw);
  11172. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  11173. ExpectIntEQ(BIO_write(bio, buf, bytes), bytes); /* d2i consumes BIO */
  11174. ExpectNotNull(d2i_PKCS12_bio(bio, &pkcs12));
  11175. ExpectNotNull(pkcs12);
  11176. BIO_free(bio);
  11177. bio = NULL;
  11178. /* check verify MAC directly */
  11179. ExpectIntEQ(ret = PKCS12_verify_mac(pkcs12, goodPsw, goodPswLen), 1);
  11180. /* check verify MAC fail case directly */
  11181. ExpectIntEQ(ret = PKCS12_verify_mac(pkcs12, badPsw, badPswLen), 0);
  11182. /* check verify MAC fail case */
  11183. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "bad", &pkey, &cert, NULL), 0);
  11184. ExpectNull(pkey);
  11185. ExpectNull(cert);
  11186. /* check parse with no extra certs kept */
  11187. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, NULL),
  11188. 1);
  11189. ExpectNotNull(pkey);
  11190. ExpectNotNull(cert);
  11191. wolfSSL_EVP_PKEY_free(pkey);
  11192. pkey = NULL;
  11193. wolfSSL_X509_free(cert);
  11194. cert = NULL;
  11195. /* check parse with extra certs kept */
  11196. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, &ca),
  11197. 1);
  11198. ExpectNotNull(pkey);
  11199. ExpectNotNull(cert);
  11200. ExpectNotNull(ca);
  11201. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO) || defined(WOLFSSL_HAPROXY) \
  11202. || defined(WOLFSSL_NGINX)) && defined(SESSION_CERTS)
  11203. /* Check that SSL_CTX_set0_chain correctly sets the certChain buffer */
  11204. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  11205. #if !defined(NO_WOLFSSL_CLIENT) && defined(SESSION_CERTS)
  11206. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  11207. #else
  11208. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  11209. #endif
  11210. /* Copy stack structure */
  11211. ExpectNotNull(tmp_ca = X509_chain_up_ref(ca));
  11212. ExpectIntEQ(SSL_CTX_set0_chain(ctx, tmp_ca), 1);
  11213. /* CTX now owns the tmp_ca stack structure */
  11214. tmp_ca = NULL;
  11215. ExpectIntEQ(wolfSSL_CTX_get_extra_chain_certs(ctx, &tmp_ca), 1);
  11216. ExpectNotNull(tmp_ca);
  11217. ExpectIntEQ(sk_X509_num(tmp_ca), sk_X509_num(ca));
  11218. /* Check that the main cert is also set */
  11219. ExpectNotNull(SSL_CTX_get0_certificate(ctx));
  11220. ExpectNotNull(ssl = SSL_new(ctx));
  11221. ExpectNotNull(SSL_get_certificate(ssl));
  11222. SSL_free(ssl);
  11223. SSL_CTX_free(ctx);
  11224. ctx = NULL;
  11225. #endif
  11226. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  11227. /* should be 2 other certs on stack */
  11228. ExpectNotNull(tmp = sk_X509_pop(ca));
  11229. X509_free(tmp);
  11230. ExpectNotNull(tmp = sk_X509_pop(ca));
  11231. X509_free(tmp);
  11232. ExpectNull(sk_X509_pop(ca));
  11233. EVP_PKEY_free(pkey);
  11234. pkey = NULL;
  11235. X509_free(cert);
  11236. cert = NULL;
  11237. sk_X509_pop_free(ca, X509_free);
  11238. ca = NULL;
  11239. /* check PKCS12_create */
  11240. ExpectNull(PKCS12_create(pass, NULL, NULL, NULL, NULL, -1, -1, -1, -1,0));
  11241. ExpectIntEQ(PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, &ca),
  11242. SSL_SUCCESS);
  11243. ExpectNotNull((pkcs12_2 = PKCS12_create(pass, NULL, pkey, cert, ca,
  11244. -1, -1, 100, -1, 0)));
  11245. EVP_PKEY_free(pkey);
  11246. pkey = NULL;
  11247. X509_free(cert);
  11248. cert = NULL;
  11249. sk_X509_pop_free(ca, NULL);
  11250. ca = NULL;
  11251. ExpectIntEQ(PKCS12_parse(pkcs12_2, "a password", &pkey, &cert, &ca),
  11252. SSL_SUCCESS);
  11253. PKCS12_free(pkcs12_2);
  11254. pkcs12_2 = NULL;
  11255. ExpectNotNull((pkcs12_2 = PKCS12_create(pass, NULL, pkey, cert, ca,
  11256. NID_pbe_WithSHA1And3_Key_TripleDES_CBC,
  11257. NID_pbe_WithSHA1And3_Key_TripleDES_CBC,
  11258. 2000, 1, 0)));
  11259. EVP_PKEY_free(pkey);
  11260. pkey = NULL;
  11261. X509_free(cert);
  11262. cert = NULL;
  11263. sk_X509_pop_free(ca, NULL);
  11264. ca = NULL;
  11265. /* convert to DER then back and parse */
  11266. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  11267. ExpectIntEQ(i2d_PKCS12_bio(bio, pkcs12_2), SSL_SUCCESS);
  11268. PKCS12_free(pkcs12_2);
  11269. pkcs12_2 = NULL;
  11270. ExpectNotNull(pkcs12_2 = d2i_PKCS12_bio(bio, NULL));
  11271. BIO_free(bio);
  11272. bio = NULL;
  11273. ExpectIntEQ(PKCS12_parse(pkcs12_2, "a password", &pkey, &cert, &ca),
  11274. SSL_SUCCESS);
  11275. /* should be 2 other certs on stack */
  11276. ExpectNotNull(tmp = sk_X509_pop(ca));
  11277. X509_free(tmp);
  11278. ExpectNotNull(tmp = sk_X509_pop(ca));
  11279. X509_free(tmp);
  11280. ExpectNull(sk_X509_pop(ca));
  11281. #ifndef NO_RC4
  11282. PKCS12_free(pkcs12_2);
  11283. pkcs12_2 = NULL;
  11284. ExpectNotNull((pkcs12_2 = PKCS12_create(pass, NULL, pkey, cert, NULL,
  11285. NID_pbe_WithSHA1And128BitRC4,
  11286. NID_pbe_WithSHA1And128BitRC4,
  11287. 2000, 1, 0)));
  11288. EVP_PKEY_free(pkey);
  11289. pkey = NULL;
  11290. X509_free(cert);
  11291. cert = NULL;
  11292. sk_X509_pop_free(ca, NULL);
  11293. ca = NULL;
  11294. ExpectIntEQ(PKCS12_parse(pkcs12_2, "a password", &pkey, &cert, &ca),
  11295. SSL_SUCCESS);
  11296. #endif /* NO_RC4 */
  11297. EVP_PKEY_free(pkey);
  11298. pkey = NULL;
  11299. X509_free(cert);
  11300. cert = NULL;
  11301. PKCS12_free(pkcs12);
  11302. pkcs12 = NULL;
  11303. PKCS12_free(pkcs12_2);
  11304. pkcs12_2 = NULL;
  11305. sk_X509_pop_free(ca, NULL);
  11306. ca = NULL;
  11307. #ifdef HAVE_ECC
  11308. /* test order of parsing */
  11309. ExpectTrue((f = XFOPEN(order, "rb")) != XBADFILE);
  11310. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  11311. if (f != XBADFILE) {
  11312. XFCLOSE(f);
  11313. f = XBADFILE;
  11314. }
  11315. ExpectNotNull(bio = BIO_new_mem_buf((void*)buf, bytes));
  11316. ExpectNotNull(pkcs12 = d2i_PKCS12_bio(bio, NULL));
  11317. ExpectIntEQ((ret = PKCS12_parse(pkcs12, "", &pkey, &cert, &ca)),
  11318. WOLFSSL_SUCCESS);
  11319. /* check use of pkey after parse */
  11320. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO) || defined(WOLFSSL_HAPROXY) \
  11321. || defined(WOLFSSL_NGINX)) && defined(SESSION_CERTS)
  11322. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  11323. #if !defined(NO_WOLFSSL_CLIENT) && defined(SESSION_CERTS)
  11324. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  11325. #else
  11326. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  11327. #endif
  11328. ExpectIntEQ(SSL_CTX_use_PrivateKey(ctx, pkey), WOLFSSL_SUCCESS);
  11329. SSL_CTX_free(ctx);
  11330. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  11331. #endif
  11332. ExpectNotNull(pkey);
  11333. ExpectNotNull(cert);
  11334. ExpectNotNull(ca);
  11335. /* compare subject lines of certificates */
  11336. ExpectNotNull(subject = wolfSSL_X509_get_subject_name(cert));
  11337. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(eccRsaCertFile,
  11338. SSL_FILETYPE_PEM));
  11339. ExpectIntEQ(wolfSSL_X509_NAME_cmp((const WOLFSSL_X509_NAME*)subject,
  11340. (const WOLFSSL_X509_NAME*)wolfSSL_X509_get_subject_name(x509)), 0);
  11341. X509_free(x509);
  11342. x509 = NULL;
  11343. /* test expected fail case */
  11344. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(eccCertFile,
  11345. SSL_FILETYPE_PEM));
  11346. ExpectIntNE(wolfSSL_X509_NAME_cmp((const WOLFSSL_X509_NAME*)subject,
  11347. (const WOLFSSL_X509_NAME*)wolfSSL_X509_get_subject_name(x509)), 0);
  11348. X509_free(x509);
  11349. x509 = NULL;
  11350. X509_free(cert);
  11351. cert = NULL;
  11352. /* get subject line from ca stack */
  11353. ExpectNotNull(cert = sk_X509_pop(ca));
  11354. ExpectNotNull(subject = wolfSSL_X509_get_subject_name(cert));
  11355. /* compare subject from certificate in ca to expected */
  11356. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(eccCertFile,
  11357. SSL_FILETYPE_PEM));
  11358. ExpectIntEQ(wolfSSL_X509_NAME_cmp((const WOLFSSL_X509_NAME*)subject,
  11359. (const WOLFSSL_X509_NAME*)wolfSSL_X509_get_subject_name(x509)), 0);
  11360. /* modify case and compare subject from certificate in ca to expected.
  11361. * The first bit of the name is:
  11362. * /C=US/ST=Washington
  11363. * So we'll change subject->name[1] to 'c' (lower case) */
  11364. if (subject != NULL) {
  11365. subject->name[1] = 'c';
  11366. ExpectIntEQ(wolfSSL_X509_NAME_cmp((const WOLFSSL_X509_NAME*)subject,
  11367. (const WOLFSSL_X509_NAME*)wolfSSL_X509_get_subject_name(x509)), 0);
  11368. }
  11369. EVP_PKEY_free(pkey);
  11370. pkey = NULL;
  11371. X509_free(x509);
  11372. x509 = NULL;
  11373. X509_free(cert);
  11374. cert = NULL;
  11375. BIO_free(bio);
  11376. bio = NULL;
  11377. PKCS12_free(pkcs12);
  11378. pkcs12 = NULL;
  11379. sk_X509_pop_free(ca, NULL); /* TEST d2i_PKCS12_fp */
  11380. ca = NULL;
  11381. /* test order of parsing */
  11382. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  11383. ExpectNotNull(pkcs12 = d2i_PKCS12_fp(f, NULL));
  11384. if (f != XBADFILE) {
  11385. XFCLOSE(f);
  11386. f = XBADFILE;
  11387. }
  11388. /* check verify MAC fail case */
  11389. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "bad", &pkey, &cert, NULL), 0);
  11390. ExpectNull(pkey);
  11391. ExpectNull(cert);
  11392. /* check parse with no extra certs kept */
  11393. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, NULL),
  11394. 1);
  11395. ExpectNotNull(pkey);
  11396. ExpectNotNull(cert);
  11397. wolfSSL_EVP_PKEY_free(pkey);
  11398. pkey = NULL;
  11399. wolfSSL_X509_free(cert);
  11400. cert = NULL;
  11401. /* check parse with extra certs kept */
  11402. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, &ca),
  11403. 1);
  11404. ExpectNotNull(pkey);
  11405. ExpectNotNull(cert);
  11406. ExpectNotNull(ca);
  11407. wolfSSL_EVP_PKEY_free(pkey);
  11408. pkey = NULL;
  11409. wolfSSL_X509_free(cert);
  11410. cert = NULL;
  11411. sk_X509_pop_free(ca, NULL);
  11412. ca = NULL;
  11413. PKCS12_free(pkcs12);
  11414. pkcs12 = NULL;
  11415. #endif /* HAVE_ECC */
  11416. #ifdef WC_RC2
  11417. /* test PKCS#12 with RC2 encryption */
  11418. ExpectTrue((f = XFOPEN(rc2p12, "rb")) != XBADFILE);
  11419. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  11420. if (f != XBADFILE) {
  11421. XFCLOSE(f);
  11422. f = XBADFILE;
  11423. }
  11424. ExpectNotNull(bio = BIO_new_mem_buf((void*)buf, bytes));
  11425. ExpectNotNull(pkcs12 = d2i_PKCS12_bio(bio, NULL));
  11426. /* check verify MAC fail case */
  11427. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "bad", &pkey, &cert, NULL), 0);
  11428. ExpectNull(pkey);
  11429. ExpectNull(cert);
  11430. /* check parse with not extra certs kept */
  11431. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, NULL),
  11432. WOLFSSL_SUCCESS);
  11433. ExpectNotNull(pkey);
  11434. ExpectNotNull(cert);
  11435. wolfSSL_EVP_PKEY_free(pkey);
  11436. pkey = NULL;
  11437. wolfSSL_X509_free(cert);
  11438. cert = NULL;
  11439. /* check parse with extra certs kept */
  11440. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, &ca),
  11441. WOLFSSL_SUCCESS);
  11442. ExpectNotNull(pkey);
  11443. ExpectNotNull(cert);
  11444. ExpectNotNull(ca);
  11445. wolfSSL_EVP_PKEY_free(pkey);
  11446. wolfSSL_X509_free(cert);
  11447. sk_X509_pop_free(ca, NULL);
  11448. BIO_free(bio);
  11449. bio = NULL;
  11450. PKCS12_free(pkcs12);
  11451. pkcs12 = NULL;
  11452. #endif /* WC_RC2 */
  11453. /* Test i2d_PKCS12_bio */
  11454. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  11455. ExpectNotNull(pkcs12 = d2i_PKCS12_fp(f, NULL));
  11456. if (f != XBADFILE)
  11457. XFCLOSE(f);
  11458. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  11459. ExpectIntEQ(ret = i2d_PKCS12_bio(bio, pkcs12), 1);
  11460. ExpectIntEQ(ret = i2d_PKCS12_bio(NULL, pkcs12), 0);
  11461. ExpectIntEQ(ret = i2d_PKCS12_bio(bio, NULL), 0);
  11462. PKCS12_free(pkcs12);
  11463. BIO_free(bio);
  11464. (void)order;
  11465. #endif /* OPENSSL_EXTRA */
  11466. #endif /* HAVE_FIPS */
  11467. return EXPECT_RESULT();
  11468. }
  11469. #if !defined(NO_FILESYSTEM) && !defined(NO_ASN) && defined(HAVE_PKCS8) && \
  11470. defined(WOLFSSL_ENCRYPTED_KEYS) && !defined(NO_DES3) && !defined(NO_PWDBASED) && \
  11471. (!defined(NO_RSA) || defined(HAVE_ECC)) && !defined(NO_MD5)
  11472. #define TEST_PKCS8_ENC
  11473. #endif
  11474. #if !defined(NO_FILESYSTEM) && !defined(NO_ASN) && defined(HAVE_PKCS8) \
  11475. && defined(HAVE_ECC) && defined(WOLFSSL_ENCRYPTED_KEYS)
  11476. /* used to keep track if FailTestCallback was called */
  11477. static int failTestCallbackCalled = 0;
  11478. static WC_INLINE int FailTestCallBack(char* passwd, int sz, int rw, void* userdata)
  11479. {
  11480. (void)passwd;
  11481. (void)sz;
  11482. (void)rw;
  11483. (void)userdata;
  11484. /* mark called, test_wolfSSL_no_password_cb() will check and fail if set */
  11485. failTestCallbackCalled = 1;
  11486. return -1;
  11487. }
  11488. #endif
  11489. static int test_wolfSSL_no_password_cb(void)
  11490. {
  11491. EXPECT_DECLS;
  11492. #if !defined(NO_FILESYSTEM) && !defined(NO_ASN) && defined(HAVE_PKCS8) \
  11493. && defined(HAVE_ECC) && defined(WOLFSSL_ENCRYPTED_KEYS)
  11494. WOLFSSL_CTX* ctx = NULL;
  11495. byte buff[FOURK_BUF];
  11496. const char eccPkcs8PrivKeyDerFile[] = "./certs/ecc-privkeyPkcs8.der";
  11497. const char eccPkcs8PrivKeyPemFile[] = "./certs/ecc-privkeyPkcs8.pem";
  11498. XFILE f = XBADFILE;
  11499. int bytes = 0;
  11500. #ifndef NO_WOLFSSL_CLIENT
  11501. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLS_client_method()));
  11502. #else
  11503. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLS_server_method()));
  11504. #endif
  11505. wolfSSL_CTX_set_default_passwd_cb(ctx, FailTestCallBack);
  11506. ExpectTrue((f = XFOPEN(eccPkcs8PrivKeyDerFile, "rb")) != XBADFILE);
  11507. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11508. if (f != XBADFILE) {
  11509. XFCLOSE(f);
  11510. f = XBADFILE;
  11511. }
  11512. ExpectIntLE(bytes, sizeof(buff));
  11513. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11514. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11515. ExpectTrue((f = XFOPEN(eccPkcs8PrivKeyPemFile, "rb")) != XBADFILE);
  11516. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11517. if (f != XBADFILE)
  11518. XFCLOSE(f);
  11519. ExpectIntLE(bytes, sizeof(buff));
  11520. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11521. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11522. wolfSSL_CTX_free(ctx);
  11523. /* Password callback should not be called by default */
  11524. ExpectIntEQ(failTestCallbackCalled, 0);
  11525. #endif
  11526. return EXPECT_RESULT();
  11527. }
  11528. #ifdef TEST_PKCS8_ENC
  11529. /* for PKCS8 test case */
  11530. static int PKCS8TestCallBack(char* passwd, int sz, int rw, void* userdata)
  11531. {
  11532. int flag = 0;
  11533. (void)rw;
  11534. if (userdata != NULL) {
  11535. flag = *((int*)userdata); /* user set data */
  11536. }
  11537. switch (flag) {
  11538. case 1: /* flag set for specific WOLFSSL_CTX structure, note userdata
  11539. * can be anything the user wishes to be passed to the callback
  11540. * associated with the WOLFSSL_CTX */
  11541. XSTRNCPY(passwd, "yassl123", sz);
  11542. return 8;
  11543. default:
  11544. return BAD_FUNC_ARG;
  11545. }
  11546. }
  11547. #endif /* TEST_PKCS8_ENC */
  11548. /* Testing functions dealing with PKCS8 */
  11549. static int test_wolfSSL_PKCS8(void)
  11550. {
  11551. EXPECT_DECLS;
  11552. #if !defined(NO_FILESYSTEM) && !defined(NO_ASN) && defined(HAVE_PKCS8) && \
  11553. !defined(WOLFCRYPT_ONLY)
  11554. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  11555. byte buff[FOURK_BUF];
  11556. byte der[FOURK_BUF];
  11557. #ifndef NO_RSA
  11558. const char serverKeyPkcs8PemFile[] = "./certs/server-keyPkcs8.pem";
  11559. const char serverKeyPkcs8DerFile[] = "./certs/server-keyPkcs8.der";
  11560. #endif
  11561. const char eccPkcs8PrivKeyPemFile[] = "./certs/ecc-privkeyPkcs8.pem";
  11562. #ifdef HAVE_ECC
  11563. const char eccPkcs8PrivKeyDerFile[] = "./certs/ecc-privkeyPkcs8.der";
  11564. #endif
  11565. XFILE f = XBADFILE;
  11566. int bytes = 0;
  11567. WOLFSSL_CTX* ctx = NULL;
  11568. #if defined(HAVE_ECC) && !defined(NO_CODING) && !defined(WOLFSSL_NO_PEM)
  11569. int ret;
  11570. ecc_key key;
  11571. word32 x = 0;
  11572. #endif
  11573. #ifdef TEST_PKCS8_ENC
  11574. #if !defined(NO_RSA) && !defined(NO_SHA)
  11575. const char serverKeyPkcs8EncPemFile[] = "./certs/server-keyPkcs8Enc.pem";
  11576. const char serverKeyPkcs8EncDerFile[] = "./certs/server-keyPkcs8Enc.der";
  11577. #endif
  11578. #if defined(HAVE_ECC) && !defined(NO_SHA)
  11579. const char eccPkcs8EncPrivKeyPemFile[] = "./certs/ecc-keyPkcs8Enc.pem";
  11580. const char eccPkcs8EncPrivKeyDerFile[] = "./certs/ecc-keyPkcs8Enc.der";
  11581. #endif
  11582. int flag;
  11583. #endif
  11584. (void)der;
  11585. #ifndef NO_WOLFSSL_CLIENT
  11586. #ifndef WOLFSSL_NO_TLS12
  11587. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  11588. #else
  11589. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  11590. #endif
  11591. #else
  11592. #ifndef WOLFSSL_NO_TLS12
  11593. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method()));
  11594. #else
  11595. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  11596. #endif
  11597. #endif
  11598. #ifdef TEST_PKCS8_ENC
  11599. wolfSSL_CTX_set_default_passwd_cb(ctx, PKCS8TestCallBack);
  11600. wolfSSL_CTX_set_default_passwd_cb_userdata(ctx, (void*)&flag);
  11601. flag = 1; /* used by password callback as return code */
  11602. #if !defined(NO_RSA) && !defined(NO_SHA)
  11603. /* test loading PEM PKCS8 encrypted file */
  11604. ExpectTrue((f = XFOPEN(serverKeyPkcs8EncPemFile, "rb")) != XBADFILE);
  11605. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11606. if (f != XBADFILE) {
  11607. XFCLOSE(f);
  11608. f = XBADFILE;
  11609. }
  11610. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11611. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11612. /* this next case should fail because of password callback return code */
  11613. flag = 0; /* used by password callback as return code */
  11614. ExpectIntNE(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11615. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11616. /* decrypt PKCS8 PEM to key in DER format with not using WOLFSSL_CTX */
  11617. ExpectIntGT(wc_KeyPemToDer(buff, bytes, der, (word32)sizeof(der),
  11618. "yassl123"), 0);
  11619. /* test that error value is returned with a bad password */
  11620. ExpectIntLT(wc_KeyPemToDer(buff, bytes, der, (word32)sizeof(der),
  11621. "bad"), 0);
  11622. /* test loading PEM PKCS8 encrypted file */
  11623. ExpectTrue((f = XFOPEN(serverKeyPkcs8EncDerFile, "rb")) != XBADFILE);
  11624. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11625. if (f != XBADFILE) {
  11626. XFCLOSE(f);
  11627. f = XBADFILE;
  11628. }
  11629. flag = 1; /* used by password callback as return code */
  11630. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11631. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11632. /* this next case should fail because of password callback return code */
  11633. flag = 0; /* used by password callback as return code */
  11634. ExpectIntNE(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11635. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11636. #endif /* !NO_RSA && !NO_SHA */
  11637. #if defined(HAVE_ECC) && !defined(NO_SHA)
  11638. /* test loading PEM PKCS8 encrypted ECC Key file */
  11639. ExpectTrue((f = XFOPEN(eccPkcs8EncPrivKeyPemFile, "rb")) != XBADFILE);
  11640. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11641. if (f != XBADFILE) {
  11642. XFCLOSE(f);
  11643. f = XBADFILE;
  11644. }
  11645. flag = 1; /* used by password callback as return code */
  11646. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11647. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11648. /* this next case should fail because of password callback return code */
  11649. flag = 0; /* used by password callback as return code */
  11650. ExpectIntNE(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11651. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11652. /* decrypt PKCS8 PEM to key in DER format with not using WOLFSSL_CTX */
  11653. ExpectIntGT(wc_KeyPemToDer(buff, bytes, der, (word32)sizeof(der),
  11654. "yassl123"), 0);
  11655. /* test that error value is returned with a bad password */
  11656. ExpectIntLT(wc_KeyPemToDer(buff, bytes, der, (word32)sizeof(der),
  11657. "bad"), 0);
  11658. /* test loading DER PKCS8 encrypted ECC Key file */
  11659. ExpectTrue((f = XFOPEN(eccPkcs8EncPrivKeyDerFile, "rb")) != XBADFILE);
  11660. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11661. if (f != XBADFILE) {
  11662. XFCLOSE(f);
  11663. f = XBADFILE;
  11664. }
  11665. flag = 1; /* used by password callback as return code */
  11666. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11667. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11668. /* this next case should fail because of password callback return code */
  11669. flag = 0; /* used by password callback as return code */
  11670. ExpectIntNE(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11671. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11672. /* leave flag as "okay" */
  11673. flag = 1;
  11674. #endif /* HAVE_ECC && !NO_SHA */
  11675. #endif /* TEST_PKCS8_ENC */
  11676. #ifndef NO_RSA
  11677. /* test loading ASN.1 (DER) PKCS8 private key file (not encrypted) */
  11678. ExpectTrue((f = XFOPEN(serverKeyPkcs8DerFile, "rb")) != XBADFILE);
  11679. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11680. if (f != XBADFILE) {
  11681. XFCLOSE(f);
  11682. f = XBADFILE;
  11683. }
  11684. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11685. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11686. /* test loading PEM PKCS8 private key file (not encrypted) */
  11687. ExpectTrue((f = XFOPEN(serverKeyPkcs8PemFile, "rb")) != XBADFILE);
  11688. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11689. if (f != XBADFILE) {
  11690. XFCLOSE(f);
  11691. f = XBADFILE;
  11692. }
  11693. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11694. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11695. #endif /* !NO_RSA */
  11696. /* Test PKCS8 PEM ECC key no crypt */
  11697. ExpectTrue((f = XFOPEN(eccPkcs8PrivKeyPemFile, "rb")) != XBADFILE);
  11698. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11699. if (f != XBADFILE) {
  11700. XFCLOSE(f);
  11701. f = XBADFILE;
  11702. }
  11703. #ifdef HAVE_ECC
  11704. /* Test PKCS8 PEM ECC key no crypt */
  11705. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11706. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11707. #if !defined(NO_CODING) && !defined(WOLFSSL_NO_PEM)
  11708. /* decrypt PKCS8 PEM to key in DER format */
  11709. ExpectIntGT((bytes = wc_KeyPemToDer(buff, bytes, der,
  11710. (word32)sizeof(der), NULL)), 0);
  11711. ret = wc_ecc_init(&key);
  11712. if (ret == 0) {
  11713. ret = wc_EccPrivateKeyDecode(der, &x, &key, (word32)bytes);
  11714. wc_ecc_free(&key);
  11715. }
  11716. ExpectIntEQ(ret, 0);
  11717. #endif
  11718. /* Test PKCS8 DER ECC key no crypt */
  11719. ExpectTrue((f = XFOPEN(eccPkcs8PrivKeyDerFile, "rb")) != XBADFILE);
  11720. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11721. if (f != XBADFILE)
  11722. XFCLOSE(f);
  11723. /* Test using a PKCS8 ECC PEM */
  11724. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11725. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11726. #else
  11727. /* if HAVE_ECC is not defined then BEGIN EC PRIVATE KEY is not found */
  11728. ExpectIntEQ((bytes = wc_KeyPemToDer(buff, bytes, der,
  11729. (word32)sizeof(der), NULL)), WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  11730. #endif /* HAVE_ECC */
  11731. wolfSSL_CTX_free(ctx);
  11732. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  11733. #endif /* !NO_FILESYSTEM && !NO_ASN && HAVE_PKCS8 */
  11734. return EXPECT_RESULT();
  11735. }
  11736. static int test_wolfSSL_PKCS8_ED25519(void)
  11737. {
  11738. EXPECT_DECLS;
  11739. #if !defined(NO_ASN) && defined(HAVE_PKCS8) && defined(HAVE_AES_CBC) && \
  11740. defined(WOLFSSL_ENCRYPTED_KEYS) && defined(HAVE_ED25519) && \
  11741. defined(HAVE_ED25519_KEY_IMPORT)
  11742. const byte encPrivKey[] = \
  11743. "-----BEGIN ENCRYPTED PRIVATE KEY-----\n"
  11744. "MIGbMFcGCSqGSIb3DQEFDTBKMCkGCSqGSIb3DQEFDDAcBAheCGLmWGh7+AICCAAw\n"
  11745. "DAYIKoZIhvcNAgkFADAdBglghkgBZQMEASoEEC4L5P6GappsTyhOOoQfvh8EQJMX\n"
  11746. "OAdlsYKCOcFo4djg6AI1lRdeBRwVFWkha7gBdoCJOzS8wDvTbYcJMPvANu5ft3nl\n"
  11747. "2L9W4v7swXkV+X+a1ww=\n"
  11748. "-----END ENCRYPTED PRIVATE KEY-----\n";
  11749. const char password[] = "abcdefghijklmnopqrstuvwxyz";
  11750. byte der[FOURK_BUF];
  11751. WOLFSSL_CTX* ctx = NULL;
  11752. int bytes;
  11753. XMEMSET(der, 0, sizeof(der));
  11754. ExpectIntGT((bytes = wc_KeyPemToDer(encPrivKey, sizeof(encPrivKey), der,
  11755. (word32)sizeof(der), password)), 0);
  11756. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  11757. #ifndef NO_WOLFSSL_SERVER
  11758. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  11759. #else
  11760. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  11761. #endif
  11762. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, der, bytes,
  11763. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11764. wolfSSL_CTX_free(ctx);
  11765. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  11766. #endif
  11767. return EXPECT_RESULT();
  11768. }
  11769. static int test_wolfSSL_PKCS8_ED448(void)
  11770. {
  11771. EXPECT_DECLS;
  11772. #if !defined(NO_ASN) && defined(HAVE_PKCS8) && defined(HAVE_AES_CBC) && \
  11773. defined(WOLFSSL_ENCRYPTED_KEYS) && defined(HAVE_ED448) && \
  11774. defined(HAVE_ED448_KEY_IMPORT)
  11775. const byte encPrivKey[] = \
  11776. "-----BEGIN ENCRYPTED PRIVATE KEY-----\n"
  11777. "MIGrMFcGCSqGSIb3DQEFDTBKMCkGCSqGSIb3DQEFDDAcBAjSbZKnG4EPggICCAAw\n"
  11778. "DAYIKoZIhvcNAgkFADAdBglghkgBZQMEASoEEFvCFWBBHBlJBsYleBJlJWcEUNC7\n"
  11779. "Tf5pZviT5Btar4D/MNg6BsQHSDf5KW4ix871EsgDY2Zz+euaoWspiMntz7gU+PQu\n"
  11780. "T/JJcbD2Ly8BbE3l5WHMifAQqNLxJBfXrHkfYtAo\n"
  11781. "-----END ENCRYPTED PRIVATE KEY-----\n";
  11782. const char password[] = "abcdefghijklmnopqrstuvwxyz";
  11783. byte der[FOURK_BUF];
  11784. WOLFSSL_CTX* ctx = NULL;
  11785. int bytes;
  11786. XMEMSET(der, 0, sizeof(der));
  11787. ExpectIntGT((bytes = wc_KeyPemToDer(encPrivKey, sizeof(encPrivKey), der,
  11788. (word32)sizeof(der), password)), 0);
  11789. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  11790. #ifndef NO_WOLFSSL_SERVER
  11791. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  11792. #else
  11793. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  11794. #endif
  11795. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, der, bytes,
  11796. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11797. wolfSSL_CTX_free(ctx);
  11798. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  11799. #endif
  11800. return EXPECT_RESULT();
  11801. }
  11802. /* Testing functions dealing with PKCS5 */
  11803. static int test_wolfSSL_PKCS5(void)
  11804. {
  11805. EXPECT_DECLS;
  11806. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA) && !defined(NO_PWDBASED)
  11807. #ifdef HAVE_FIPS /* Password minimum length is 14 (112-bit) in FIPS MODE */
  11808. const char* passwd = "myfipsPa$$W0rd";
  11809. #else
  11810. const char *passwd = "pass1234";
  11811. #endif
  11812. const unsigned char *salt = (unsigned char *)"salt1234";
  11813. unsigned char *out = (unsigned char *)XMALLOC(WC_SHA_DIGEST_SIZE, NULL,
  11814. DYNAMIC_TYPE_TMP_BUFFER);
  11815. int ret = 0;
  11816. ExpectNotNull(out);
  11817. ExpectIntEQ(ret = PKCS5_PBKDF2_HMAC_SHA1(passwd,(int)XSTRLEN(passwd), salt,
  11818. (int)XSTRLEN((const char *) salt), 10, WC_SHA_DIGEST_SIZE,out),
  11819. WOLFSSL_SUCCESS);
  11820. #ifdef WOLFSSL_SHA512
  11821. ExpectIntEQ(ret = PKCS5_PBKDF2_HMAC(passwd,(int)XSTRLEN(passwd), salt,
  11822. (int)XSTRLEN((const char *) salt), 10, wolfSSL_EVP_sha512(),
  11823. WC_SHA_DIGEST_SIZE, out), SSL_SUCCESS);
  11824. #endif
  11825. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  11826. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_SHA) */
  11827. return EXPECT_RESULT();
  11828. }
  11829. /* test parsing URI from certificate */
  11830. static int test_wolfSSL_URI(void)
  11831. {
  11832. EXPECT_DECLS;
  11833. #if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) \
  11834. && (defined(KEEP_PEER_CERT) || defined(SESSION_CERTS) || \
  11835. defined(OPENSSL_EXTRA))
  11836. WOLFSSL_X509* x509 = NULL;
  11837. const char uri[] = "./certs/client-uri-cert.pem";
  11838. const char urn[] = "./certs/client-absolute-urn.pem";
  11839. const char badUri[] = "./certs/client-relative-uri.pem";
  11840. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(uri,
  11841. WOLFSSL_FILETYPE_PEM));
  11842. wolfSSL_FreeX509(x509);
  11843. x509 = NULL;
  11844. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(urn,
  11845. WOLFSSL_FILETYPE_PEM));
  11846. wolfSSL_FreeX509(x509);
  11847. x509 = NULL;
  11848. #if !defined(IGNORE_NAME_CONSTRAINTS) && !defined(WOLFSSL_NO_ASN_STRICT) \
  11849. && !defined(WOLFSSL_FPKI)
  11850. ExpectNull(x509 = wolfSSL_X509_load_certificate_file(badUri,
  11851. WOLFSSL_FILETYPE_PEM));
  11852. #else
  11853. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(badUri,
  11854. WOLFSSL_FILETYPE_PEM));
  11855. #endif
  11856. wolfSSL_FreeX509(x509);
  11857. #endif
  11858. return EXPECT_RESULT();
  11859. }
  11860. static int test_wolfSSL_TBS(void)
  11861. {
  11862. EXPECT_DECLS;
  11863. #if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) \
  11864. && defined(OPENSSL_EXTRA)
  11865. WOLFSSL_X509* x509 = NULL;
  11866. const unsigned char* tbs;
  11867. int tbsSz;
  11868. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(caCertFile,
  11869. WOLFSSL_FILETYPE_PEM));
  11870. ExpectNull(tbs = wolfSSL_X509_get_tbs(NULL, &tbsSz));
  11871. ExpectNull(tbs = wolfSSL_X509_get_tbs(x509, NULL));
  11872. ExpectNotNull(tbs = wolfSSL_X509_get_tbs(x509, &tbsSz));
  11873. ExpectIntEQ(tbsSz, 1003);
  11874. wolfSSL_FreeX509(x509);
  11875. #endif
  11876. return EXPECT_RESULT();
  11877. }
  11878. static int test_wolfSSL_X509_verify(void)
  11879. {
  11880. EXPECT_DECLS;
  11881. #if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) && \
  11882. defined(OPENSSL_EXTRA)
  11883. WOLFSSL_X509* ca = NULL;
  11884. WOLFSSL_X509* serv = NULL;
  11885. WOLFSSL_EVP_PKEY* pkey = NULL;
  11886. unsigned char buf[2048];
  11887. const unsigned char* pt = NULL;
  11888. int bufSz;
  11889. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(caCertFile,
  11890. WOLFSSL_FILETYPE_PEM));
  11891. ExpectIntNE(wolfSSL_X509_get_pubkey_buffer(NULL, buf, &bufSz),
  11892. WOLFSSL_SUCCESS);
  11893. ExpectIntEQ(wolfSSL_X509_get_pubkey_buffer(ca, NULL, &bufSz),
  11894. WOLFSSL_SUCCESS);
  11895. ExpectIntEQ(bufSz, 294);
  11896. bufSz = 2048;
  11897. ExpectIntEQ(wolfSSL_X509_get_pubkey_buffer(ca, buf, &bufSz),
  11898. WOLFSSL_SUCCESS);
  11899. ExpectIntEQ(wolfSSL_X509_get_pubkey_type(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  11900. ExpectIntEQ(wolfSSL_X509_get_pubkey_type(ca), RSAk);
  11901. ExpectNotNull(serv = wolfSSL_X509_load_certificate_file(svrCertFile,
  11902. WOLFSSL_FILETYPE_PEM));
  11903. /* success case */
  11904. pt = buf;
  11905. ExpectNotNull(pkey = wolfSSL_d2i_PUBKEY(NULL, &pt, bufSz));
  11906. ExpectIntEQ(i2d_PUBKEY(pkey, NULL), bufSz);
  11907. ExpectIntEQ(wolfSSL_X509_verify(serv, pkey), WOLFSSL_SUCCESS);
  11908. wolfSSL_EVP_PKEY_free(pkey);
  11909. pkey = NULL;
  11910. /* fail case */
  11911. bufSz = 2048;
  11912. ExpectIntEQ(wolfSSL_X509_get_pubkey_buffer(serv, buf, &bufSz),
  11913. WOLFSSL_SUCCESS);
  11914. pt = buf;
  11915. ExpectNotNull(pkey = wolfSSL_d2i_PUBKEY(NULL, &pt, bufSz));
  11916. ExpectIntEQ(wolfSSL_X509_verify(serv, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  11917. ExpectIntEQ(wolfSSL_X509_verify(NULL, pkey), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  11918. ExpectIntEQ(wolfSSL_X509_verify(serv, NULL), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  11919. wolfSSL_EVP_PKEY_free(pkey);
  11920. wolfSSL_FreeX509(ca);
  11921. wolfSSL_FreeX509(serv);
  11922. #endif
  11923. return EXPECT_RESULT();
  11924. }
  11925. #if defined(WOLFSSL_ACERT) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  11926. !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA)
  11927. /* Given acert file and its pubkey file, read them and then
  11928. * attempt to verify signed acert.
  11929. *
  11930. * If expect_pass is true, then verification should pass.
  11931. * If expect_pass is false, then verification should fail.
  11932. * */
  11933. static int do_acert_verify_test(const char * acert_file,
  11934. const char * pkey_file,
  11935. size_t expect_pass)
  11936. {
  11937. X509_ACERT * x509 = NULL;
  11938. EVP_PKEY * pkey = NULL;
  11939. BIO * bp = NULL;
  11940. int verify_rc = 0;
  11941. /* First read the attribute certificate. */
  11942. bp = BIO_new_file(acert_file, "r");
  11943. if (bp == NULL) {
  11944. return -1;
  11945. }
  11946. x509 = PEM_read_bio_X509_ACERT(bp, NULL, NULL, NULL);
  11947. BIO_free(bp);
  11948. bp = NULL;
  11949. if (x509 == NULL) {
  11950. return -1;
  11951. }
  11952. /* Next read the associated pub key. */
  11953. bp = BIO_new_file(pkey_file, "r");
  11954. if (bp == NULL) {
  11955. X509_ACERT_free(x509);
  11956. x509 = NULL;
  11957. return -1;
  11958. }
  11959. pkey = PEM_read_bio_PUBKEY(bp, &pkey, NULL, NULL);
  11960. BIO_free(bp);
  11961. bp = NULL;
  11962. if (pkey == NULL) {
  11963. X509_ACERT_free(x509);
  11964. x509 = NULL;
  11965. return -1;
  11966. }
  11967. /* Finally, do verification. */
  11968. verify_rc = X509_ACERT_verify(x509, pkey);
  11969. X509_ACERT_free(x509);
  11970. x509 = NULL;
  11971. EVP_PKEY_free(pkey);
  11972. pkey = NULL;
  11973. if (expect_pass && verify_rc != 1) {
  11974. return -1;
  11975. }
  11976. if (!expect_pass && verify_rc == 1) {
  11977. return -1;
  11978. }
  11979. return 0;
  11980. }
  11981. #endif
  11982. static int test_wolfSSL_X509_ACERT_verify(void)
  11983. {
  11984. EXPECT_DECLS;
  11985. #if defined(WOLFSSL_ACERT) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  11986. defined(WC_RSA_PSS) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA)
  11987. /* Walk over list of signed ACERTs and their pubkeys.
  11988. * All should load and pass verification. */
  11989. const char * acerts[4] = {"certs/acert/acert.pem",
  11990. "certs/acert/acert_ietf.pem",
  11991. "certs/acert/rsa_pss/acert.pem",
  11992. "certs/acert/rsa_pss/acert_ietf.pem"};
  11993. const char * pkeys[4] = {"certs/acert/acert_pubkey.pem",
  11994. "certs/acert/acert_ietf_pubkey.pem",
  11995. "certs/acert/rsa_pss/acert_pubkey.pem",
  11996. "certs/acert/rsa_pss/acert_ietf_pubkey.pem"};
  11997. int rc = 0;
  11998. size_t i = 0;
  11999. size_t j = 0;
  12000. for (i = 0; i < 4; ++i) {
  12001. for (j = i; j < 4; ++j) {
  12002. rc = do_acert_verify_test(acerts[i], pkeys[j], i == j);
  12003. if (rc) {
  12004. fprintf(stderr, "error: %s: i = %zu, j = %zu, rc = %d\n",
  12005. "do_acert_verify_test", i, j, rc);
  12006. break;
  12007. }
  12008. }
  12009. if (rc) { break; }
  12010. }
  12011. ExpectIntEQ(rc, 0);
  12012. #endif
  12013. return EXPECT_RESULT();
  12014. }
  12015. static int test_wolfSSL_X509_ACERT_misc_api(void)
  12016. {
  12017. EXPECT_DECLS;
  12018. #if defined(WOLFSSL_ACERT) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  12019. !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA)
  12020. const char * acerts[4] = {"certs/acert/acert.pem",
  12021. "certs/acert/acert_ietf.pem",
  12022. "certs/acert/rsa_pss/acert.pem",
  12023. "certs/acert/rsa_pss/acert_ietf.pem"};
  12024. int rc = 0;
  12025. X509_ACERT * x509 = NULL;
  12026. BIO * bp = NULL;
  12027. long ver_long = 0;
  12028. int ver = 0;
  12029. int nid = 0;
  12030. const byte * raw_attr = NULL;
  12031. word32 attr_len = 0;
  12032. size_t i = 0;
  12033. int buf_len = 0;
  12034. byte ietf_serial[] = {0x03, 0xb5, 0x90, 0x59, 0x02,
  12035. 0xa2, 0xaa, 0xb5, 0x40, 0x21,
  12036. 0x44, 0xb8, 0x2c, 0x4f, 0xd9,
  12037. 0x80, 0x1b, 0x5f, 0x57, 0xc2};
  12038. for (i = 0; i < 4; ++i) {
  12039. const char * acert_file = acerts[i];
  12040. int is_rsa_pss = 0;
  12041. int is_ietf_acert = 0;
  12042. byte serial[64];
  12043. int serial_len = sizeof(serial);
  12044. XMEMSET(serial, 0, sizeof(serial));
  12045. is_rsa_pss = XSTRSTR(acert_file, "rsa_pss") != NULL ? 1 : 0;
  12046. is_ietf_acert = XSTRSTR(acert_file, "ietf.pem") != NULL ? 1 : 0;
  12047. /* First read the attribute certificate. */
  12048. bp = BIO_new_file(acert_file, "r");
  12049. ExpectNotNull(bp);
  12050. x509 = PEM_read_bio_X509_ACERT(bp, NULL, NULL, NULL);
  12051. ExpectNotNull(x509);
  12052. /* We're done with the bio for now. */
  12053. if (bp != NULL) {
  12054. BIO_free(bp);
  12055. bp = NULL;
  12056. }
  12057. /* Check version and signature NID. */
  12058. ver_long = X509_ACERT_get_version(x509);
  12059. ExpectIntEQ(ver_long, 1);
  12060. ver = wolfSSL_X509_ACERT_version(x509);
  12061. ExpectIntEQ(ver, 2);
  12062. nid = X509_ACERT_get_signature_nid(x509);
  12063. if (is_rsa_pss) {
  12064. ExpectIntEQ(nid, NID_rsassaPss);
  12065. }
  12066. else {
  12067. ExpectIntEQ(nid, NID_sha256WithRSAEncryption);
  12068. }
  12069. /* Get the serial number buffer.
  12070. * The ietf acert example has a 20 byte serial number. */
  12071. rc = wolfSSL_X509_ACERT_get_serial_number(x509, serial, &serial_len);
  12072. ExpectIntEQ(rc, SSL_SUCCESS);
  12073. if (is_ietf_acert) {
  12074. ExpectIntEQ(serial_len, 20);
  12075. ExpectIntEQ(XMEMCMP(serial, ietf_serial, sizeof(ietf_serial)), 0);
  12076. }
  12077. else {
  12078. ExpectIntEQ(serial_len, 1);
  12079. ExpectTrue(serial[0] == 0x01);
  12080. }
  12081. /* Repeat the same but with null serial buffer. This is ok. */
  12082. rc = wolfSSL_X509_ACERT_get_serial_number(x509, NULL, &serial_len);
  12083. ExpectIntEQ(rc, SSL_SUCCESS);
  12084. if (is_ietf_acert) {
  12085. ExpectIntEQ(serial_len, 20);
  12086. }
  12087. else {
  12088. ExpectIntEQ(serial_len, 1);
  12089. ExpectTrue(serial[0] == 0x01);
  12090. }
  12091. /* Get the attributes buffer. */
  12092. rc = wolfSSL_X509_ACERT_get_attr_buf(x509, &raw_attr, &attr_len);
  12093. ExpectIntEQ(rc, SSL_SUCCESS);
  12094. if (is_ietf_acert) {
  12095. /* This cert has a 65 byte attributes field. */
  12096. ExpectNotNull(raw_attr);
  12097. ExpectIntEQ(attr_len, 65);
  12098. }
  12099. else {
  12100. /* This cert has a 237 byte attributes field. */
  12101. ExpectNotNull(raw_attr);
  12102. ExpectIntEQ(attr_len, 237);
  12103. }
  12104. /* Test printing acert to memory bio. */
  12105. ExpectNotNull(bp = BIO_new(BIO_s_mem()));
  12106. rc = X509_ACERT_print(bp, x509);
  12107. ExpectIntEQ(rc, SSL_SUCCESS);
  12108. /* Now do a bunch of invalid stuff with partially valid inputs. */
  12109. rc = wolfSSL_X509_ACERT_get_attr_buf(x509, &raw_attr, NULL);
  12110. ExpectIntEQ(rc, BAD_FUNC_ARG);
  12111. rc = wolfSSL_X509_ACERT_get_attr_buf(x509, NULL, &attr_len);
  12112. ExpectIntEQ(rc, BAD_FUNC_ARG);
  12113. rc = wolfSSL_X509_ACERT_get_attr_buf(NULL, &raw_attr, &attr_len);
  12114. ExpectIntEQ(rc, BAD_FUNC_ARG);
  12115. ver_long = X509_ACERT_get_version(NULL);
  12116. ExpectIntEQ(ver_long, 0);
  12117. ver = wolfSSL_X509_ACERT_version(NULL);
  12118. ExpectIntEQ(ver, 0);
  12119. rc = wolfSSL_X509_ACERT_get_signature(x509, NULL, NULL);
  12120. ExpectIntEQ(rc, WOLFSSL_FATAL_ERROR);
  12121. rc = wolfSSL_X509_ACERT_get_signature(x509, NULL, &buf_len);
  12122. ExpectIntEQ(rc, SSL_SUCCESS);
  12123. ExpectIntEQ(buf_len, 256);
  12124. rc = wolfSSL_X509_ACERT_get_serial_number(x509, serial, NULL);
  12125. ExpectIntEQ(rc, BAD_FUNC_ARG);
  12126. rc = X509_ACERT_print(bp, NULL);
  12127. ExpectIntEQ(rc, WOLFSSL_FAILURE);
  12128. rc = X509_ACERT_print(NULL, x509);
  12129. ExpectIntEQ(rc, WOLFSSL_FAILURE);
  12130. /* Finally free the acert and bio, we're done with them. */
  12131. if (x509 != NULL) {
  12132. X509_ACERT_free(x509);
  12133. x509 = NULL;
  12134. }
  12135. if (bp != NULL) {
  12136. BIO_free(bp);
  12137. bp = NULL;
  12138. }
  12139. }
  12140. #endif
  12141. return EXPECT_RESULT();
  12142. }
  12143. #if !defined(NO_DH) && !defined(NO_AES) && defined(WOLFSSL_CERT_GEN) && \
  12144. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  12145. defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  12146. /* create certificate with version 2 */
  12147. static int test_set_x509_badversion(WOLFSSL_CTX* ctx)
  12148. {
  12149. EXPECT_DECLS;
  12150. WOLFSSL_X509 *x509 = NULL, *x509v2 = NULL;
  12151. WOLFSSL_EVP_PKEY *priv = NULL, *pub = NULL;
  12152. unsigned char *der = NULL, *key = NULL, *pt;
  12153. char *header = NULL, *name = NULL;
  12154. int derSz;
  12155. long keySz;
  12156. XFILE fp = XBADFILE;
  12157. WOLFSSL_ASN1_TIME *notBefore = NULL, *notAfter = NULL;
  12158. time_t t;
  12159. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  12160. WOLFSSL_FILETYPE_PEM));
  12161. ExpectTrue((fp = XFOPEN(cliKeyFile, "rb")) != XBADFILE);
  12162. ExpectIntEQ(wolfSSL_PEM_read(fp, &name, &header, &key, &keySz),
  12163. WOLFSSL_SUCCESS);
  12164. if (fp != XBADFILE)
  12165. XFCLOSE(fp);
  12166. pt = key;
  12167. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  12168. (const unsigned char**)&pt, keySz));
  12169. /* create the version 2 certificate */
  12170. ExpectNotNull(x509v2 = X509_new());
  12171. ExpectIntEQ(wolfSSL_X509_set_version(x509v2, 1), WOLFSSL_SUCCESS);
  12172. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509v2,
  12173. wolfSSL_X509_get_subject_name(x509)), WOLFSSL_SUCCESS);
  12174. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509v2,
  12175. wolfSSL_X509_get_issuer_name(x509)), WOLFSSL_SUCCESS);
  12176. ExpectNotNull(pub = wolfSSL_X509_get_pubkey(x509));
  12177. ExpectIntEQ(X509_set_pubkey(x509v2, pub), WOLFSSL_SUCCESS);
  12178. t = time(NULL);
  12179. ExpectNotNull(notBefore = wolfSSL_ASN1_TIME_adj(NULL, t, 0, 0));
  12180. ExpectNotNull(notAfter = wolfSSL_ASN1_TIME_adj(NULL, t, 365, 0));
  12181. ExpectTrue(wolfSSL_X509_set_notBefore(x509v2, notBefore));
  12182. ExpectTrue(wolfSSL_X509_set_notAfter(x509v2, notAfter));
  12183. ExpectIntGT(wolfSSL_X509_sign(x509v2, priv, EVP_sha256()), 0);
  12184. derSz = wolfSSL_i2d_X509(x509v2, &der);
  12185. ExpectIntGT(derSz, 0);
  12186. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(ctx, der, derSz,
  12187. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  12188. /* TODO: Replace with API call */
  12189. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  12190. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12191. XFREE(name, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12192. XFREE(header, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12193. wolfSSL_X509_free(x509);
  12194. wolfSSL_X509_free(x509v2);
  12195. wolfSSL_EVP_PKEY_free(priv);
  12196. wolfSSL_EVP_PKEY_free(pub);
  12197. wolfSSL_ASN1_TIME_free(notBefore);
  12198. wolfSSL_ASN1_TIME_free(notAfter);
  12199. return EXPECT_RESULT();
  12200. }
  12201. /* override certificate version error */
  12202. static int test_override_x509(int preverify, WOLFSSL_X509_STORE_CTX* store)
  12203. {
  12204. EXPECT_DECLS;
  12205. #ifndef OPENSSL_COMPATIBLE_DEFAULTS
  12206. ExpectIntEQ(store->error, WC_NO_ERR_TRACE(ASN_VERSION_E));
  12207. #else
  12208. ExpectIntEQ(store->error, 0);
  12209. #endif
  12210. ExpectIntEQ((int)wolfSSL_X509_get_version(store->current_cert), 1);
  12211. (void)preverify;
  12212. return EXPECT_RESULT() == TEST_SUCCESS;
  12213. }
  12214. /* set verify callback that will override bad certificate version */
  12215. static int test_set_override_x509(WOLFSSL_CTX* ctx)
  12216. {
  12217. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, test_override_x509);
  12218. return TEST_SUCCESS;
  12219. }
  12220. #endif
  12221. static int test_wolfSSL_X509_TLS_version_test_1(void)
  12222. {
  12223. EXPECT_DECLS;
  12224. #if !defined(NO_DH) && !defined(NO_AES) && defined(WOLFSSL_CERT_GEN) && \
  12225. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  12226. defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  12227. test_ssl_cbf func_cb_client;
  12228. test_ssl_cbf func_cb_server;
  12229. /* test server rejects a client certificate that is not version 3 */
  12230. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  12231. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  12232. func_cb_client.ctx_ready = &test_set_x509_badversion;
  12233. #ifndef WOLFSSL_NO_TLS12
  12234. func_cb_client.method = wolfTLSv1_2_client_method;
  12235. #else
  12236. func_cb_client.method = wolfTLSv1_3_client_method;
  12237. #endif
  12238. #ifndef WOLFSSL_NO_TLS12
  12239. func_cb_server.method = wolfTLSv1_2_server_method;
  12240. #else
  12241. func_cb_server.method = wolfTLSv1_3_server_method;
  12242. #endif
  12243. #ifndef OPENSSL_COMPATIBLE_DEFAULTS
  12244. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  12245. &func_cb_server, NULL), -1001);
  12246. #else
  12247. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  12248. &func_cb_server, NULL), TEST_SUCCESS);
  12249. #endif
  12250. #endif
  12251. return EXPECT_RESULT();
  12252. }
  12253. static int test_wolfSSL_X509_TLS_version_test_2(void)
  12254. {
  12255. EXPECT_DECLS;
  12256. #if !defined(NO_DH) && !defined(NO_AES) && defined(WOLFSSL_CERT_GEN) && \
  12257. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  12258. defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  12259. test_ssl_cbf func_cb_client;
  12260. test_ssl_cbf func_cb_server;
  12261. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  12262. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  12263. func_cb_client.ctx_ready = &test_set_x509_badversion;
  12264. func_cb_server.ctx_ready = &test_set_override_x509;
  12265. #ifndef WOLFSSL_NO_TLS12
  12266. func_cb_client.method = wolfTLSv1_2_client_method;
  12267. #else
  12268. func_cb_client.method = wolfTLSv1_3_client_method;
  12269. #endif
  12270. #ifndef WOLFSSL_NO_TLS12
  12271. func_cb_server.method = wolfTLSv1_2_server_method;
  12272. #else
  12273. func_cb_server.method = wolfTLSv1_3_server_method;
  12274. #endif
  12275. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  12276. &func_cb_server, NULL), TEST_SUCCESS);
  12277. #endif
  12278. return EXPECT_RESULT();
  12279. }
  12280. /* Testing function wolfSSL_CTX_SetMinVersion; sets the minimum downgrade
  12281. * version allowed.
  12282. * POST: 1 on success.
  12283. */
  12284. static int test_wolfSSL_CTX_SetMinVersion(void)
  12285. {
  12286. int res = TEST_SKIPPED;
  12287. #ifndef NO_WOLFSSL_CLIENT
  12288. int failFlag = WOLFSSL_SUCCESS;
  12289. WOLFSSL_CTX* ctx;
  12290. int itr;
  12291. #ifndef NO_OLD_TLS
  12292. const int versions[] = {
  12293. #ifdef WOLFSSL_ALLOW_TLSV10
  12294. WOLFSSL_TLSV1,
  12295. #endif
  12296. WOLFSSL_TLSV1_1,
  12297. WOLFSSL_TLSV1_2 };
  12298. #elif !defined(WOLFSSL_NO_TLS12)
  12299. const int versions[] = { WOLFSSL_TLSV1_2 };
  12300. #elif defined(WOLFSSL_TLS13)
  12301. const int versions[] = { WOLFSSL_TLSV1_3 };
  12302. #else
  12303. const int versions[0];
  12304. #endif
  12305. ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  12306. for (itr = 0; itr < (int)(sizeof(versions)/sizeof(int)); itr++) {
  12307. if (wolfSSL_CTX_SetMinVersion(ctx, *(versions + itr))
  12308. != WOLFSSL_SUCCESS) {
  12309. failFlag = WOLFSSL_FAILURE;
  12310. }
  12311. }
  12312. wolfSSL_CTX_free(ctx);
  12313. res = TEST_RES_CHECK(failFlag == WOLFSSL_SUCCESS);
  12314. #endif
  12315. return res;
  12316. } /* END test_wolfSSL_CTX_SetMinVersion */
  12317. /*----------------------------------------------------------------------------*
  12318. | OCSP Stapling
  12319. *----------------------------------------------------------------------------*/
  12320. /* Testing wolfSSL_UseOCSPStapling function. OCSP stapling eliminates the need
  12321. * need to contact the CA, lowering the cost of cert revocation checking.
  12322. * PRE: HAVE_OCSP and HAVE_CERTIFICATE_STATUS_REQUEST
  12323. * POST: 1 returned for success.
  12324. */
  12325. static int test_wolfSSL_UseOCSPStapling(void)
  12326. {
  12327. EXPECT_DECLS;
  12328. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) && defined(HAVE_OCSP) && \
  12329. !defined(NO_WOLFSSL_CLIENT)
  12330. WOLFSSL_CTX* ctx = NULL;
  12331. WOLFSSL* ssl = NULL;
  12332. #ifndef NO_WOLFSSL_CLIENT
  12333. #ifndef WOLFSSL_NO_TLS12
  12334. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  12335. #else
  12336. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  12337. #endif
  12338. #else
  12339. #ifndef WOLFSSL_NO_TLS12
  12340. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method()));
  12341. #else
  12342. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  12343. #endif
  12344. #endif
  12345. ExpectNotNull(ssl = wolfSSL_new(ctx));
  12346. ExpectIntEQ(wolfSSL_UseOCSPStapling(NULL, WOLFSSL_CSR2_OCSP,
  12347. WOLFSSL_CSR2_OCSP_USE_NONCE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12348. #ifndef NO_WOLFSSL_CLIENT
  12349. ExpectIntEQ(wolfSSL_UseOCSPStapling(ssl, WOLFSSL_CSR2_OCSP,
  12350. WOLFSSL_CSR2_OCSP_USE_NONCE), 1);
  12351. #else
  12352. ExpectIntEQ(wolfSSL_UseOCSPStapling(ssl, WOLFSSL_CSR2_OCSP,
  12353. WOLFSSL_CSR2_OCSP_USE_NONCE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12354. #endif
  12355. wolfSSL_free(ssl);
  12356. wolfSSL_CTX_free(ctx);
  12357. #endif
  12358. return EXPECT_RESULT();
  12359. } /* END test_wolfSSL_UseOCSPStapling */
  12360. /* Testing OCSP stapling version 2, wolfSSL_UseOCSPStaplingV2 function. OCSP
  12361. * stapling eliminates the need to contact the CA and lowers cert revocation
  12362. * check.
  12363. * PRE: HAVE_CERTIFICATE_STATUS_REQUEST_V2 and HAVE_OCSP defined.
  12364. */
  12365. static int test_wolfSSL_UseOCSPStaplingV2(void)
  12366. {
  12367. EXPECT_DECLS;
  12368. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2) && defined(HAVE_OCSP) && \
  12369. !defined(NO_WOLFSSL_CLIENT)
  12370. WOLFSSL_CTX* ctx = NULL;
  12371. WOLFSSL* ssl = NULL;
  12372. #ifndef NO_WOLFSSL_CLIENT
  12373. #ifndef WOLFSSL_NO_TLS12
  12374. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  12375. #else
  12376. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  12377. #endif
  12378. #else
  12379. #ifndef WOLFSSL_NO_TLS12
  12380. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method()));
  12381. #else
  12382. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  12383. #endif
  12384. #endif
  12385. ExpectNotNull(ssl = wolfSSL_new(ctx));
  12386. ExpectIntEQ(wolfSSL_UseOCSPStaplingV2(NULL, WOLFSSL_CSR2_OCSP,
  12387. WOLFSSL_CSR2_OCSP_USE_NONCE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12388. #ifndef NO_WOLFSSL_CLIENT
  12389. ExpectIntEQ(wolfSSL_UseOCSPStaplingV2(ssl, WOLFSSL_CSR2_OCSP,
  12390. WOLFSSL_CSR2_OCSP_USE_NONCE), 1);
  12391. #else
  12392. ExpectIntEQ(wolfSSL_UseOCSPStaplingV2(ssl, WOLFSSL_CSR2_OCSP,
  12393. WOLFSSL_CSR2_OCSP_USE_NONCE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12394. #endif
  12395. wolfSSL_free(ssl);
  12396. wolfSSL_CTX_free(ctx);
  12397. #endif
  12398. return EXPECT_RESULT();
  12399. } /* END test_wolfSSL_UseOCSPStaplingV2 */
  12400. /*----------------------------------------------------------------------------*
  12401. | Multicast Tests
  12402. *----------------------------------------------------------------------------*/
  12403. static int test_wolfSSL_mcast(void)
  12404. {
  12405. EXPECT_DECLS;
  12406. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_MULTICAST) && \
  12407. (defined(WOLFSSL_TLS13) || defined(WOLFSSL_SNIFFER))
  12408. WOLFSSL_CTX* ctx = NULL;
  12409. WOLFSSL* ssl = NULL;
  12410. byte preMasterSecret[512];
  12411. byte clientRandom[32];
  12412. byte serverRandom[32];
  12413. byte suite[2] = {0, 0xfe}; /* WDM_WITH_NULL_SHA256 */
  12414. byte buf[256];
  12415. word16 newId;
  12416. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_2_client_method()));
  12417. ExpectIntEQ(wolfSSL_CTX_mcast_set_member_id(ctx, 0), WOLFSSL_SUCCESS);
  12418. ExpectNotNull(ssl = wolfSSL_new(ctx));
  12419. XMEMSET(preMasterSecret, 0x23, sizeof(preMasterSecret));
  12420. XMEMSET(clientRandom, 0xA5, sizeof(clientRandom));
  12421. XMEMSET(serverRandom, 0x5A, sizeof(serverRandom));
  12422. ExpectIntEQ(wolfSSL_set_secret(ssl, 23, preMasterSecret,
  12423. sizeof(preMasterSecret), clientRandom, serverRandom, suite),
  12424. WOLFSSL_SUCCESS);
  12425. ExpectIntLE(wolfSSL_mcast_read(ssl, &newId, buf, sizeof(buf)), 0);
  12426. ExpectIntLE(newId, 100);
  12427. wolfSSL_free(ssl);
  12428. wolfSSL_CTX_free(ctx);
  12429. #endif /* WOLFSSL_DTLS && WOLFSSL_MULTICAST && (WOLFSSL_TLS13 ||
  12430. * WOLFSSL_SNIFFER) */
  12431. return EXPECT_RESULT();
  12432. }
  12433. /*----------------------------------------------------------------------------*
  12434. | Wolfcrypt
  12435. *----------------------------------------------------------------------------*/
  12436. /*
  12437. * Unit test for the wc_InitBlake2b()
  12438. */
  12439. static int test_wc_InitBlake2b(void)
  12440. {
  12441. EXPECT_DECLS;
  12442. #ifdef HAVE_BLAKE2
  12443. Blake2b blake;
  12444. /* Test good arg. */
  12445. ExpectIntEQ(wc_InitBlake2b(&blake, 64), 0);
  12446. /* Test bad arg. */
  12447. ExpectIntEQ(wc_InitBlake2b(NULL, 64), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12448. ExpectIntEQ(wc_InitBlake2b(NULL, 128), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12449. ExpectIntEQ(wc_InitBlake2b(&blake, 128), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12450. ExpectIntEQ(wc_InitBlake2b(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12451. ExpectIntEQ(wc_InitBlake2b(&blake, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12452. #endif
  12453. return EXPECT_RESULT();
  12454. } /* END test_wc_InitBlake2b*/
  12455. /*
  12456. * Unit test for the wc_InitBlake2b_WithKey()
  12457. */
  12458. static int test_wc_InitBlake2b_WithKey(void)
  12459. {
  12460. EXPECT_DECLS;
  12461. #ifdef HAVE_BLAKE2
  12462. Blake2b blake;
  12463. word32 digestSz = BLAKE2B_KEYBYTES;
  12464. byte key[BLAKE2B_KEYBYTES];
  12465. word32 keylen = BLAKE2B_KEYBYTES;
  12466. XMEMSET(key, 0, sizeof(key));
  12467. /* Test good arg. */
  12468. ExpectIntEQ(wc_InitBlake2b_WithKey(&blake, digestSz, key, keylen), 0);
  12469. /* Test bad args. */
  12470. ExpectIntEQ(wc_InitBlake2b_WithKey(NULL, digestSz, key, keylen),
  12471. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12472. ExpectIntEQ(wc_InitBlake2b_WithKey(&blake, digestSz, key, 256),
  12473. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12474. ExpectIntEQ(wc_InitBlake2b_WithKey(&blake, digestSz, NULL, keylen), 0);
  12475. #endif
  12476. return EXPECT_RESULT();
  12477. } /* END wc_InitBlake2b_WithKey*/
  12478. /*
  12479. * Unit test for the wc_InitBlake2s_WithKey()
  12480. */
  12481. static int test_wc_InitBlake2s_WithKey(void)
  12482. {
  12483. EXPECT_DECLS;
  12484. #ifdef HAVE_BLAKE2S
  12485. Blake2s blake;
  12486. word32 digestSz = BLAKE2S_KEYBYTES;
  12487. byte *key = (byte*)"01234567890123456789012345678901";
  12488. word32 keylen = BLAKE2S_KEYBYTES;
  12489. /* Test good arg. */
  12490. ExpectIntEQ(wc_InitBlake2s_WithKey(&blake, digestSz, key, keylen), 0);
  12491. /* Test bad args. */
  12492. ExpectIntEQ(wc_InitBlake2s_WithKey(NULL, digestSz, key, keylen),
  12493. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12494. ExpectIntEQ(wc_InitBlake2s_WithKey(&blake, digestSz, key, 256),
  12495. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12496. ExpectIntEQ(wc_InitBlake2s_WithKey(&blake, digestSz, NULL, keylen), 0);
  12497. #endif
  12498. return EXPECT_RESULT();
  12499. } /* END wc_InitBlake2s_WithKey*/
  12500. /*
  12501. * Unit test for the wc_InitMd5()
  12502. */
  12503. static int test_wc_InitMd5(void)
  12504. {
  12505. EXPECT_DECLS;
  12506. #ifndef NO_MD5
  12507. wc_Md5 md5;
  12508. /* Test good arg. */
  12509. ExpectIntEQ(wc_InitMd5(&md5), 0);
  12510. /* Test bad arg. */
  12511. ExpectIntEQ(wc_InitMd5(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12512. wc_Md5Free(&md5);
  12513. #endif
  12514. return EXPECT_RESULT();
  12515. } /* END test_wc_InitMd5 */
  12516. /*
  12517. * Testing wc_UpdateMd5()
  12518. */
  12519. static int test_wc_Md5Update(void)
  12520. {
  12521. EXPECT_DECLS;
  12522. #ifndef NO_MD5
  12523. wc_Md5 md5;
  12524. byte hash[WC_MD5_DIGEST_SIZE];
  12525. testVector a, b, c;
  12526. ExpectIntEQ(wc_InitMd5(&md5), 0);
  12527. /* Input */
  12528. a.input = "a";
  12529. a.inLen = XSTRLEN(a.input);
  12530. ExpectIntEQ(wc_Md5Update(&md5, (byte*)a.input, (word32)a.inLen), 0);
  12531. ExpectIntEQ(wc_Md5Final(&md5, hash), 0);
  12532. /* Update input. */
  12533. a.input = "abc";
  12534. a.output = "\x90\x01\x50\x98\x3c\xd2\x4f\xb0\xd6\x96\x3f\x7d\x28\xe1\x7f"
  12535. "\x72";
  12536. a.inLen = XSTRLEN(a.input);
  12537. a.outLen = XSTRLEN(a.output);
  12538. ExpectIntEQ(wc_Md5Update(&md5, (byte*) a.input, (word32) a.inLen), 0);
  12539. ExpectIntEQ(wc_Md5Final(&md5, hash), 0);
  12540. ExpectIntEQ(XMEMCMP(hash, a.output, WC_MD5_DIGEST_SIZE), 0);
  12541. /* Pass in bad values. */
  12542. b.input = NULL;
  12543. b.inLen = 0;
  12544. ExpectIntEQ(wc_Md5Update(&md5, (byte*)b.input, (word32)b.inLen), 0);
  12545. c.input = NULL;
  12546. c.inLen = WC_MD5_DIGEST_SIZE;
  12547. ExpectIntEQ(wc_Md5Update(&md5, (byte*)c.input, (word32)c.inLen),
  12548. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12549. ExpectIntEQ(wc_Md5Update(NULL, (byte*)a.input, (word32)a.inLen),
  12550. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12551. wc_Md5Free(&md5);
  12552. #endif
  12553. return EXPECT_RESULT();
  12554. } /* END test_wc_Md5Update() */
  12555. /*
  12556. * Unit test on wc_Md5Final() in wolfcrypt/src/md5.c
  12557. */
  12558. static int test_wc_Md5Final(void)
  12559. {
  12560. EXPECT_DECLS;
  12561. #ifndef NO_MD5
  12562. /* Instantiate */
  12563. wc_Md5 md5;
  12564. byte* hash_test[3];
  12565. byte hash1[WC_MD5_DIGEST_SIZE];
  12566. byte hash2[2*WC_MD5_DIGEST_SIZE];
  12567. byte hash3[5*WC_MD5_DIGEST_SIZE];
  12568. int times, i;
  12569. /* Initialize */
  12570. ExpectIntEQ(wc_InitMd5(&md5), 0);
  12571. hash_test[0] = hash1;
  12572. hash_test[1] = hash2;
  12573. hash_test[2] = hash3;
  12574. times = sizeof(hash_test)/sizeof(byte*);
  12575. for (i = 0; i < times; i++) {
  12576. ExpectIntEQ(wc_Md5Final(&md5, hash_test[i]), 0);
  12577. }
  12578. /* Test bad args. */
  12579. ExpectIntEQ(wc_Md5Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12580. ExpectIntEQ(wc_Md5Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12581. ExpectIntEQ(wc_Md5Final(&md5, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12582. wc_Md5Free(&md5);
  12583. #endif
  12584. return EXPECT_RESULT();
  12585. }
  12586. /*
  12587. * Unit test for the wc_InitSha()
  12588. */
  12589. static int test_wc_InitSha(void)
  12590. {
  12591. EXPECT_DECLS;
  12592. #ifndef NO_SHA
  12593. wc_Sha sha;
  12594. /* Test good arg. */
  12595. ExpectIntEQ(wc_InitSha(&sha), 0);
  12596. /* Test bad arg. */
  12597. ExpectIntEQ(wc_InitSha(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12598. wc_ShaFree(&sha);
  12599. #endif
  12600. return EXPECT_RESULT();
  12601. } /* END test_wc_InitSha */
  12602. /*
  12603. * Tesing wc_ShaUpdate()
  12604. */
  12605. static int test_wc_ShaUpdate(void)
  12606. {
  12607. EXPECT_DECLS;
  12608. #ifndef NO_SHA
  12609. wc_Sha sha;
  12610. byte hash[WC_SHA_DIGEST_SIZE];
  12611. testVector a, b, c;
  12612. ExpectIntEQ(wc_InitSha(&sha), 0);
  12613. /* Input. */
  12614. a.input = "a";
  12615. a.inLen = XSTRLEN(a.input);
  12616. ExpectIntEQ(wc_ShaUpdate(&sha, NULL, 0), 0);
  12617. ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)a.input, 0), 0);
  12618. ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)a.input, (word32)a.inLen), 0);
  12619. ExpectIntEQ(wc_ShaFinal(&sha, hash), 0);
  12620. /* Update input. */
  12621. a.input = "abc";
  12622. a.output = "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E\x25\x71\x78\x50\xC2"
  12623. "\x6C\x9C\xD0\xD8\x9D";
  12624. a.inLen = XSTRLEN(a.input);
  12625. a.outLen = XSTRLEN(a.output);
  12626. ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)a.input, (word32)a.inLen), 0);
  12627. ExpectIntEQ(wc_ShaFinal(&sha, hash), 0);
  12628. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA_DIGEST_SIZE), 0);
  12629. /* Try passing in bad values. */
  12630. b.input = NULL;
  12631. b.inLen = 0;
  12632. ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)b.input, (word32)b.inLen), 0);
  12633. c.input = NULL;
  12634. c.inLen = WC_SHA_DIGEST_SIZE;
  12635. ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)c.input, (word32)c.inLen),
  12636. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12637. ExpectIntEQ(wc_ShaUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  12638. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12639. wc_ShaFree(&sha);
  12640. #endif
  12641. return EXPECT_RESULT();
  12642. } /* END test_wc_ShaUpdate() */
  12643. /*
  12644. * Unit test on wc_ShaFinal
  12645. */
  12646. static int test_wc_ShaFinal(void)
  12647. {
  12648. EXPECT_DECLS;
  12649. #ifndef NO_SHA
  12650. wc_Sha sha;
  12651. byte* hash_test[3];
  12652. byte hash1[WC_SHA_DIGEST_SIZE];
  12653. byte hash2[2*WC_SHA_DIGEST_SIZE];
  12654. byte hash3[5*WC_SHA_DIGEST_SIZE];
  12655. int times, i;
  12656. /* Initialize*/
  12657. ExpectIntEQ(wc_InitSha(&sha), 0);
  12658. hash_test[0] = hash1;
  12659. hash_test[1] = hash2;
  12660. hash_test[2] = hash3;
  12661. times = sizeof(hash_test)/sizeof(byte*);
  12662. for (i = 0; i < times; i++) {
  12663. ExpectIntEQ(wc_ShaFinal(&sha, hash_test[i]), 0);
  12664. }
  12665. /* Test bad args. */
  12666. ExpectIntEQ(wc_ShaFinal(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12667. ExpectIntEQ(wc_ShaFinal(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12668. ExpectIntEQ(wc_ShaFinal(&sha, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12669. wc_ShaFree(&sha);
  12670. #endif
  12671. return EXPECT_RESULT();
  12672. } /* END test_wc_ShaFinal */
  12673. /*
  12674. * Unit test for wc_InitSha256()
  12675. */
  12676. static int test_wc_InitSha256(void)
  12677. {
  12678. EXPECT_DECLS;
  12679. #ifndef NO_SHA256
  12680. wc_Sha256 sha256;
  12681. /* Test good arg. */
  12682. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12683. /* Test bad arg. */
  12684. ExpectIntEQ(wc_InitSha256(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12685. wc_Sha256Free(&sha256);
  12686. #endif
  12687. return EXPECT_RESULT();
  12688. } /* END test_wc_InitSha256 */
  12689. /*
  12690. * Unit test for wc_Sha256Update()
  12691. */
  12692. static int test_wc_Sha256Update(void)
  12693. {
  12694. EXPECT_DECLS;
  12695. #ifndef NO_SHA256
  12696. wc_Sha256 sha256;
  12697. byte hash[WC_SHA256_DIGEST_SIZE];
  12698. byte hash_unaligned[WC_SHA256_DIGEST_SIZE+1];
  12699. testVector a, b, c;
  12700. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12701. /* Input. */
  12702. a.input = "a";
  12703. a.inLen = XSTRLEN(a.input);
  12704. ExpectIntEQ(wc_Sha256Update(&sha256, NULL, 0), 0);
  12705. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)a.input, 0), 0);
  12706. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)a.input, (word32)a.inLen), 0);
  12707. ExpectIntEQ(wc_Sha256Final(&sha256, hash), 0);
  12708. /* Update input. */
  12709. a.input = "abc";
  12710. a.output = "\xBA\x78\x16\xBF\x8F\x01\xCF\xEA\x41\x41\x40\xDE\x5D\xAE\x22"
  12711. "\x23\xB0\x03\x61\xA3\x96\x17\x7A\x9C\xB4\x10\xFF\x61\xF2\x00"
  12712. "\x15\xAD";
  12713. a.inLen = XSTRLEN(a.input);
  12714. a.outLen = XSTRLEN(a.output);
  12715. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)a.input, (word32)a.inLen), 0);
  12716. ExpectIntEQ(wc_Sha256Final(&sha256, hash), 0);
  12717. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA256_DIGEST_SIZE), 0);
  12718. /* Unaligned check. */
  12719. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)a.input+1, (word32)a.inLen-1),
  12720. 0);
  12721. ExpectIntEQ(wc_Sha256Final(&sha256, hash_unaligned + 1), 0);
  12722. /* Try passing in bad values */
  12723. b.input = NULL;
  12724. b.inLen = 0;
  12725. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)b.input, (word32)b.inLen), 0);
  12726. c.input = NULL;
  12727. c.inLen = WC_SHA256_DIGEST_SIZE;
  12728. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)c.input, (word32)c.inLen),
  12729. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12730. ExpectIntEQ(wc_Sha256Update(NULL, (byte*)a.input, (word32)a.inLen),
  12731. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12732. wc_Sha256Free(&sha256);
  12733. #endif
  12734. return EXPECT_RESULT();
  12735. } /* END test_wc_Sha256Update */
  12736. /*
  12737. * Unit test function for wc_Sha256Final()
  12738. */
  12739. static int test_wc_Sha256Final(void)
  12740. {
  12741. EXPECT_DECLS;
  12742. #ifndef NO_SHA256
  12743. wc_Sha256 sha256;
  12744. byte* hash_test[3];
  12745. byte hash1[WC_SHA256_DIGEST_SIZE];
  12746. byte hash2[2*WC_SHA256_DIGEST_SIZE];
  12747. byte hash3[5*WC_SHA256_DIGEST_SIZE];
  12748. int times, i;
  12749. /* Initialize */
  12750. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12751. hash_test[0] = hash1;
  12752. hash_test[1] = hash2;
  12753. hash_test[2] = hash3;
  12754. times = sizeof(hash_test) / sizeof(byte*);
  12755. for (i = 0; i < times; i++) {
  12756. ExpectIntEQ(wc_Sha256Final(&sha256, hash_test[i]), 0);
  12757. }
  12758. /* Test bad args. */
  12759. ExpectIntEQ(wc_Sha256Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12760. ExpectIntEQ(wc_Sha256Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12761. ExpectIntEQ(wc_Sha256Final(&sha256, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12762. wc_Sha256Free(&sha256);
  12763. #endif
  12764. return EXPECT_RESULT();
  12765. } /* END test_wc_Sha256Final */
  12766. /*
  12767. * Unit test function for wc_Sha256FinalRaw()
  12768. */
  12769. static int test_wc_Sha256FinalRaw(void)
  12770. {
  12771. EXPECT_DECLS;
  12772. #if !defined(NO_SHA256) && !defined(HAVE_SELFTEST) && !defined(WOLFSSL_DEVCRYPTO) && (!defined(HAVE_FIPS) || \
  12773. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3))) && \
  12774. !defined(WOLFSSL_NO_HASH_RAW)
  12775. wc_Sha256 sha256;
  12776. byte* hash_test[3];
  12777. byte hash1[WC_SHA256_DIGEST_SIZE];
  12778. byte hash2[2*WC_SHA256_DIGEST_SIZE];
  12779. byte hash3[5*WC_SHA256_DIGEST_SIZE];
  12780. int times, i;
  12781. /* Initialize */
  12782. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12783. hash_test[0] = hash1;
  12784. hash_test[1] = hash2;
  12785. hash_test[2] = hash3;
  12786. times = sizeof(hash_test) / sizeof(byte*);
  12787. for (i = 0; i < times; i++) {
  12788. ExpectIntEQ(wc_Sha256FinalRaw(&sha256, hash_test[i]), 0);
  12789. }
  12790. /* Test bad args. */
  12791. ExpectIntEQ(wc_Sha256FinalRaw(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12792. ExpectIntEQ(wc_Sha256FinalRaw(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12793. ExpectIntEQ(wc_Sha256FinalRaw(&sha256, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12794. wc_Sha256Free(&sha256);
  12795. #endif
  12796. return EXPECT_RESULT();
  12797. } /* END test_wc_Sha256FinalRaw */
  12798. /*
  12799. * Unit test function for wc_Sha256GetFlags()
  12800. */
  12801. static int test_wc_Sha256GetFlags(void)
  12802. {
  12803. EXPECT_DECLS;
  12804. #if !defined(NO_SHA256) && defined(WOLFSSL_HASH_FLAGS)
  12805. wc_Sha256 sha256;
  12806. word32 flags = 0;
  12807. /* Initialize */
  12808. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12809. ExpectIntEQ(wc_Sha256GetFlags(&sha256, &flags), 0);
  12810. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  12811. wc_Sha256Free(&sha256);
  12812. #endif
  12813. return EXPECT_RESULT();
  12814. } /* END test_wc_Sha256GetFlags */
  12815. /*
  12816. * Unit test function for wc_Sha256Free()
  12817. */
  12818. static int test_wc_Sha256Free(void)
  12819. {
  12820. EXPECT_DECLS;
  12821. #ifndef NO_SHA256
  12822. wc_Sha256Free(NULL);
  12823. /* Set result to SUCCESS. */
  12824. ExpectTrue(1);
  12825. #endif
  12826. return EXPECT_RESULT();
  12827. } /* END test_wc_Sha256Free */
  12828. /*
  12829. * Unit test function for wc_Sha256GetHash()
  12830. */
  12831. static int test_wc_Sha256GetHash(void)
  12832. {
  12833. EXPECT_DECLS;
  12834. #ifndef NO_SHA256
  12835. wc_Sha256 sha256;
  12836. byte hash1[WC_SHA256_DIGEST_SIZE];
  12837. /* Initialize */
  12838. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12839. ExpectIntEQ(wc_Sha256GetHash(&sha256, hash1), 0);
  12840. /* test bad arguments*/
  12841. ExpectIntEQ(wc_Sha256GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12842. ExpectIntEQ(wc_Sha256GetHash(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12843. ExpectIntEQ(wc_Sha256GetHash(&sha256, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12844. wc_Sha256Free(&sha256);
  12845. #endif
  12846. return EXPECT_RESULT();
  12847. } /* END test_wc_Sha256GetHash */
  12848. /*
  12849. * Unit test function for wc_Sha256Copy()
  12850. */
  12851. static int test_wc_Sha256Copy(void)
  12852. {
  12853. EXPECT_DECLS;
  12854. #ifndef NO_SHA256
  12855. wc_Sha256 sha256;
  12856. wc_Sha256 temp;
  12857. XMEMSET(&sha256, 0, sizeof(sha256));
  12858. XMEMSET(&temp, 0, sizeof(temp));
  12859. /* Initialize */
  12860. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12861. ExpectIntEQ(wc_InitSha256(&temp), 0);
  12862. ExpectIntEQ(wc_Sha256Copy(&sha256, &temp), 0);
  12863. /* test bad arguments*/
  12864. ExpectIntEQ(wc_Sha256Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12865. ExpectIntEQ(wc_Sha256Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12866. ExpectIntEQ(wc_Sha256Copy(&sha256, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12867. wc_Sha256Free(&sha256);
  12868. wc_Sha256Free(&temp);
  12869. #endif
  12870. return EXPECT_RESULT();
  12871. } /* END test_wc_Sha256Copy */
  12872. /*
  12873. * Testing wc_InitSha512()
  12874. */
  12875. static int test_wc_InitSha512(void)
  12876. {
  12877. EXPECT_DECLS;
  12878. #ifdef WOLFSSL_SHA512
  12879. wc_Sha512 sha512;
  12880. /* Test good arg. */
  12881. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  12882. /* Test bad arg. */
  12883. ExpectIntEQ(wc_InitSha512(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12884. wc_Sha512Free(&sha512);
  12885. #endif
  12886. return EXPECT_RESULT();
  12887. } /* END test_wc_InitSha512 */
  12888. /*
  12889. * wc_Sha512Update() test.
  12890. */
  12891. static int test_wc_Sha512Update(void)
  12892. {
  12893. EXPECT_DECLS;
  12894. #ifdef WOLFSSL_SHA512
  12895. wc_Sha512 sha512;
  12896. byte hash[WC_SHA512_DIGEST_SIZE];
  12897. byte hash_unaligned[WC_SHA512_DIGEST_SIZE + 1];
  12898. testVector a, b, c;
  12899. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  12900. /* Input. */
  12901. a.input = "a";
  12902. a.inLen = XSTRLEN(a.input);
  12903. ExpectIntEQ(wc_Sha512Update(&sha512, NULL, 0), 0);
  12904. ExpectIntEQ(wc_Sha512Update(&sha512,(byte*)a.input, 0), 0);
  12905. ExpectIntEQ(wc_Sha512Update(&sha512, (byte*)a.input, (word32)a.inLen), 0);
  12906. ExpectIntEQ(wc_Sha512Final(&sha512, hash), 0);
  12907. /* Update input. */
  12908. a.input = "abc";
  12909. a.output = "\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41"
  12910. "\x31\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b"
  12911. "\x55\xd3\x9a\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c"
  12912. "\x23\xa3\xfe\xeb\xbd\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a"
  12913. "\x9a\xc9\x4f\xa5\x4c\xa4\x9f";
  12914. a.inLen = XSTRLEN(a.input);
  12915. a.outLen = XSTRLEN(a.output);
  12916. ExpectIntEQ(wc_Sha512Update(&sha512, (byte*) a.input, (word32) a.inLen), 0);
  12917. ExpectIntEQ(wc_Sha512Final(&sha512, hash), 0);
  12918. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA512_DIGEST_SIZE), 0);
  12919. /* Unaligned check. */
  12920. ExpectIntEQ(wc_Sha512Update(&sha512, (byte*)a.input+1, (word32)a.inLen-1),
  12921. 0);
  12922. ExpectIntEQ(wc_Sha512Final(&sha512, hash_unaligned+1), 0);
  12923. /* Try passing in bad values */
  12924. b.input = NULL;
  12925. b.inLen = 0;
  12926. ExpectIntEQ(wc_Sha512Update(&sha512, (byte*)b.input, (word32)b.inLen), 0);
  12927. c.input = NULL;
  12928. c.inLen = WC_SHA512_DIGEST_SIZE;
  12929. ExpectIntEQ(wc_Sha512Update(&sha512, (byte*)c.input, (word32)c.inLen),
  12930. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12931. ExpectIntEQ(wc_Sha512Update(NULL, (byte*)a.input, (word32)a.inLen),
  12932. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12933. wc_Sha512Free(&sha512);
  12934. #endif
  12935. return EXPECT_RESULT();
  12936. } /* END test_wc_Sha512Update */
  12937. #ifdef WOLFSSL_SHA512
  12938. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  12939. (!defined(WOLFSSL_NOSHA512_224) || !defined(WOLFSSL_NOSHA512_256))
  12940. /* Performs test for
  12941. * - wc_Sha512Final/wc_Sha512FinalRaw
  12942. * - wc_Sha512_224Final/wc_Sha512_224Final
  12943. * - wc_Sha512_256Final/wc_Sha512_256Final
  12944. * parameter:
  12945. * - type : must be one of WC_HASH_TYPE_SHA512, WC_HASH_TYPE_SHA512_224 or
  12946. * WC_HASH_TYPE_SHA512_256
  12947. * - isRaw: if is non-zero, xxxFinalRaw function will be tested
  12948. *return 0 on success
  12949. */
  12950. static int test_Sha512_Family_Final(int type, int isRaw)
  12951. {
  12952. EXPECT_DECLS;
  12953. wc_Sha512 sha512;
  12954. byte* hash_test[3];
  12955. byte hash1[WC_SHA512_DIGEST_SIZE];
  12956. byte hash2[2*WC_SHA512_DIGEST_SIZE];
  12957. byte hash3[5*WC_SHA512_DIGEST_SIZE];
  12958. int times, i;
  12959. int(*initFp)(wc_Sha512*);
  12960. int(*finalFp)(wc_Sha512*, byte*);
  12961. void(*freeFp)(wc_Sha512*);
  12962. if (type == WC_HASH_TYPE_SHA512) {
  12963. initFp = wc_InitSha512;
  12964. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  12965. !defined(WOLFSSL_NO_HASH_RAW)
  12966. finalFp = (isRaw)? wc_Sha512FinalRaw : wc_Sha512Final;
  12967. #else
  12968. finalFp = (isRaw)? NULL : wc_Sha512Final;
  12969. #endif
  12970. freeFp = wc_Sha512Free;
  12971. }
  12972. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  12973. #if !defined(WOLFSSL_NOSHA512_224)
  12974. else if (type == WC_HASH_TYPE_SHA512_224) {
  12975. initFp = wc_InitSha512_224;
  12976. #if !defined(WOLFSSL_NO_HASH_RAW)
  12977. finalFp = (isRaw)? wc_Sha512_224FinalRaw : wc_Sha512_224Final;
  12978. #else
  12979. finalFp = (isRaw)? NULL : wc_Sha512_224Final;
  12980. #endif
  12981. freeFp = wc_Sha512_224Free;
  12982. }
  12983. #endif
  12984. #if !defined(WOLFSSL_NOSHA512_256)
  12985. else if (type == WC_HASH_TYPE_SHA512_256) {
  12986. initFp = wc_InitSha512_256;
  12987. #if !defined(WOLFSSL_NO_HASH_RAW)
  12988. finalFp = (isRaw)? wc_Sha512_256FinalRaw : wc_Sha512_256Final;
  12989. #else
  12990. finalFp = (isRaw)? NULL : wc_Sha512_256Final;
  12991. #endif
  12992. freeFp = wc_Sha512_256Free;
  12993. }
  12994. #endif
  12995. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  12996. else
  12997. return TEST_FAIL;
  12998. /* Initialize */
  12999. ExpectIntEQ(initFp(&sha512), 0);
  13000. hash_test[0] = hash1;
  13001. hash_test[1] = hash2;
  13002. hash_test[2] = hash3;
  13003. times = sizeof(hash_test) / sizeof(byte *);
  13004. #if defined(HAVE_FIPS) || defined(HAVE_SELFTEST) || \
  13005. defined(WOLFSSL_NO_HASH_RAW)
  13006. if (finalFp != NULL)
  13007. #endif
  13008. {
  13009. /* Good test args. */
  13010. for (i = 0; i < times; i++) {
  13011. ExpectIntEQ(finalFp(&sha512, hash_test[i]), 0);
  13012. }
  13013. /* Test bad args. */
  13014. ExpectIntEQ(finalFp(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13015. ExpectIntEQ(finalFp(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13016. ExpectIntEQ(finalFp(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13017. }
  13018. freeFp(&sha512);
  13019. return EXPECT_RESULT();
  13020. }
  13021. #endif /* !HAVE_FIPS && !HAVE_SELFTEST &&
  13022. (!WOLFSSL_NOSHA512_224 || !WOLFSSL_NOSHA512_256) */
  13023. #endif /* WOLFSSL_SHA512 */
  13024. /*
  13025. * Unit test function for wc_Sha512Final()
  13026. */
  13027. static int test_wc_Sha512Final(void)
  13028. {
  13029. EXPECT_DECLS;
  13030. #ifdef WOLFSSL_SHA512
  13031. wc_Sha512 sha512;
  13032. byte* hash_test[3];
  13033. byte hash1[WC_SHA512_DIGEST_SIZE];
  13034. byte hash2[2*WC_SHA512_DIGEST_SIZE];
  13035. byte hash3[5*WC_SHA512_DIGEST_SIZE];
  13036. int times, i;
  13037. /* Initialize */
  13038. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  13039. hash_test[0] = hash1;
  13040. hash_test[1] = hash2;
  13041. hash_test[2] = hash3;
  13042. times = sizeof(hash_test) / sizeof(byte *);
  13043. for (i = 0; i < times; i++) {
  13044. ExpectIntEQ(wc_Sha512Final(&sha512, hash_test[i]), 0);
  13045. }
  13046. /* Test bad args. */
  13047. ExpectIntEQ(wc_Sha512Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13048. ExpectIntEQ(wc_Sha512Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13049. ExpectIntEQ(wc_Sha512Final(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13050. wc_Sha512Free(&sha512);
  13051. #endif
  13052. return EXPECT_RESULT();
  13053. } /* END test_wc_Sha512Final */
  13054. /*
  13055. * Unit test function for wc_Sha512GetFlags()
  13056. */
  13057. static int test_wc_Sha512GetFlags(void)
  13058. {
  13059. EXPECT_DECLS;
  13060. #if defined(WOLFSSL_SHA512) && defined(WOLFSSL_HASH_FLAGS)
  13061. wc_Sha512 sha512;
  13062. word32 flags = 0;
  13063. /* Initialize */
  13064. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  13065. ExpectIntEQ(wc_Sha512GetFlags(&sha512, &flags), 0);
  13066. ExpectIntEQ((flags & WC_HASH_FLAG_ISCOPY), 0);
  13067. wc_Sha512Free(&sha512);
  13068. #endif
  13069. return EXPECT_RESULT();
  13070. } /* END test_wc_Sha512GetFlags */
  13071. /*
  13072. * Unit test function for wc_Sha512FinalRaw()
  13073. */
  13074. static int test_wc_Sha512FinalRaw(void)
  13075. {
  13076. EXPECT_DECLS;
  13077. #if (defined(WOLFSSL_SHA512) && !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  13078. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3)))) && \
  13079. !defined(WOLFSSL_NO_HASH_RAW)
  13080. wc_Sha512 sha512;
  13081. byte* hash_test[3];
  13082. byte hash1[WC_SHA512_DIGEST_SIZE];
  13083. byte hash2[2*WC_SHA512_DIGEST_SIZE];
  13084. byte hash3[5*WC_SHA512_DIGEST_SIZE];
  13085. int times, i;
  13086. /* Initialize */
  13087. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  13088. hash_test[0] = hash1;
  13089. hash_test[1] = hash2;
  13090. hash_test[2] = hash3;
  13091. times = sizeof(hash_test) / sizeof(byte*);
  13092. /* Good test args. */
  13093. for (i = 0; i < times; i++) {
  13094. ExpectIntEQ(wc_Sha512FinalRaw(&sha512, hash_test[i]), 0);
  13095. }
  13096. /* Test bad args. */
  13097. ExpectIntEQ(wc_Sha512FinalRaw(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13098. ExpectIntEQ(wc_Sha512FinalRaw(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13099. ExpectIntEQ(wc_Sha512FinalRaw(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13100. wc_Sha512Free(&sha512);
  13101. #endif
  13102. return EXPECT_RESULT();
  13103. } /* END test_wc_Sha512FinalRaw */
  13104. /*
  13105. * Unit test function for wc_Sha512Free()
  13106. */
  13107. static int test_wc_Sha512Free(void)
  13108. {
  13109. EXPECT_DECLS;
  13110. #ifdef WOLFSSL_SHA512
  13111. wc_Sha512Free(NULL);
  13112. /* Set result to SUCCESS. */
  13113. ExpectTrue(1);
  13114. #endif
  13115. return EXPECT_RESULT();
  13116. } /* END test_wc_Sha512Free */
  13117. #ifdef WOLFSSL_SHA512
  13118. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  13119. (!defined(WOLFSSL_NOSHA512_224) || !defined(WOLFSSL_NOSHA512_256))
  13120. static int test_Sha512_Family_GetHash(int type )
  13121. {
  13122. EXPECT_DECLS;
  13123. int(*initFp)(wc_Sha512*);
  13124. int(*ghashFp)(wc_Sha512*, byte*);
  13125. wc_Sha512 sha512;
  13126. byte hash1[WC_SHA512_DIGEST_SIZE];
  13127. if (type == WC_HASH_TYPE_SHA512) {
  13128. initFp = wc_InitSha512;
  13129. ghashFp = wc_Sha512GetHash;
  13130. }
  13131. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13132. #if !defined(WOLFSSL_NOSHA512_224)
  13133. else if (type == WC_HASH_TYPE_SHA512_224) {
  13134. initFp = wc_InitSha512_224;
  13135. ghashFp = wc_Sha512_224GetHash;
  13136. }
  13137. #endif
  13138. #if !defined(WOLFSSL_NOSHA512_256)
  13139. else if (type == WC_HASH_TYPE_SHA512_256) {
  13140. initFp = wc_InitSha512_256;
  13141. ghashFp = wc_Sha512_256GetHash;
  13142. }
  13143. #endif
  13144. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13145. else {
  13146. initFp = NULL;
  13147. ghashFp = NULL;
  13148. }
  13149. if (initFp == NULL || ghashFp == NULL)
  13150. return TEST_FAIL;
  13151. ExpectIntEQ(initFp(&sha512), 0);
  13152. ExpectIntEQ(ghashFp(&sha512, hash1), 0);
  13153. /* test bad arguments*/
  13154. ExpectIntEQ(ghashFp(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13155. ExpectIntEQ(ghashFp(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13156. ExpectIntEQ(ghashFp(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13157. wc_Sha512Free(&sha512);
  13158. return EXPECT_RESULT();
  13159. }
  13160. #endif /* !HAVE_FIPS && !HAVE_SELFTEST &&
  13161. (!WOLFSSL_NOSHA512_224 || !WOLFSSL_NOSHA512_256) */
  13162. #endif /* WOLFSSL_SHA512 */
  13163. /*
  13164. * Unit test function for wc_Sha512GetHash()
  13165. */
  13166. static int test_wc_Sha512GetHash(void)
  13167. {
  13168. EXPECT_DECLS;
  13169. #ifdef WOLFSSL_SHA512
  13170. wc_Sha512 sha512;
  13171. byte hash1[WC_SHA512_DIGEST_SIZE];
  13172. /* Initialize */
  13173. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  13174. ExpectIntEQ(wc_Sha512GetHash(&sha512, hash1), 0);
  13175. /* test bad arguments*/
  13176. ExpectIntEQ(wc_Sha512GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13177. ExpectIntEQ(wc_Sha512GetHash(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13178. ExpectIntEQ(wc_Sha512GetHash(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13179. wc_Sha512Free(&sha512);
  13180. #endif
  13181. return EXPECT_RESULT();
  13182. } /* END test_wc_Sha512GetHash */
  13183. /*
  13184. * Unit test function for wc_Sha512Copy()
  13185. */
  13186. static int test_wc_Sha512Copy(void)
  13187. {
  13188. EXPECT_DECLS;
  13189. #ifdef WOLFSSL_SHA512
  13190. wc_Sha512 sha512;
  13191. wc_Sha512 temp;
  13192. XMEMSET(&sha512, 0, sizeof(wc_Sha512));
  13193. XMEMSET(&temp, 0, sizeof(wc_Sha512));
  13194. /* Initialize */
  13195. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  13196. ExpectIntEQ(wc_InitSha512(&temp), 0);
  13197. ExpectIntEQ(wc_Sha512Copy(&sha512, &temp), 0);
  13198. /* test bad arguments*/
  13199. ExpectIntEQ(wc_Sha512Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13200. ExpectIntEQ(wc_Sha512Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13201. ExpectIntEQ(wc_Sha512Copy(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13202. wc_Sha512Free(&sha512);
  13203. wc_Sha512Free(&temp);
  13204. #endif
  13205. return EXPECT_RESULT();
  13206. } /* END test_wc_Sha512Copy */
  13207. static int test_wc_InitSha512_224(void)
  13208. {
  13209. EXPECT_DECLS;
  13210. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13211. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  13212. wc_Sha512 sha512;
  13213. /* Test good arg. */
  13214. ExpectIntEQ(wc_InitSha512_224(&sha512), 0);
  13215. /* Test bad arg. */
  13216. ExpectIntEQ(wc_InitSha512_224(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13217. wc_Sha512_224Free(&sha512);
  13218. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_224 */
  13219. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13220. return EXPECT_RESULT();
  13221. }
  13222. static int test_wc_Sha512_224Update(void)
  13223. {
  13224. EXPECT_DECLS;
  13225. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13226. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  13227. wc_Sha512 sha512;
  13228. byte hash[WC_SHA512_DIGEST_SIZE];
  13229. testVector a, c;
  13230. ExpectIntEQ(wc_InitSha512_224(&sha512), 0);
  13231. /* Input. */
  13232. a.input = "a";
  13233. a.inLen = XSTRLEN(a.input);
  13234. ExpectIntEQ(wc_Sha512_224Update(&sha512, NULL, 0), 0);
  13235. ExpectIntEQ(wc_Sha512_224Update(&sha512,(byte*)a.input, 0), 0);
  13236. ExpectIntEQ(wc_Sha512_224Update(&sha512, (byte*)a.input, (word32)a.inLen),
  13237. 0);
  13238. ExpectIntEQ(wc_Sha512_224Final(&sha512, hash), 0);
  13239. /* Update input. */
  13240. a.input = "abc";
  13241. a.output = "\x46\x34\x27\x0f\x70\x7b\x6a\x54\xda\xae\x75\x30\x46\x08"
  13242. "\x42\xe2\x0e\x37\xed\x26\x5c\xee\xe9\xa4\x3e\x89\x24\xaa";
  13243. a.inLen = XSTRLEN(a.input);
  13244. a.outLen = XSTRLEN(a.output);
  13245. ExpectIntEQ(wc_Sha512_224Update(&sha512, (byte*) a.input, (word32) a.inLen),
  13246. 0);
  13247. ExpectIntEQ(wc_Sha512_224Final(&sha512, hash), 0);
  13248. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA512_224_DIGEST_SIZE), 0);
  13249. c.input = NULL;
  13250. c.inLen = WC_SHA512_224_DIGEST_SIZE;
  13251. ExpectIntEQ(wc_Sha512_224Update(&sha512, (byte*)c.input, (word32)c.inLen),
  13252. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13253. ExpectIntEQ(wc_Sha512_224Update(NULL, (byte*)a.input, (word32)a.inLen),
  13254. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13255. wc_Sha512_224Free(&sha512);
  13256. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_224 */
  13257. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13258. return EXPECT_RESULT();
  13259. }
  13260. static int test_wc_Sha512_224Final(void)
  13261. {
  13262. EXPECT_DECLS;
  13263. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13264. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  13265. ExpectIntEQ(test_Sha512_Family_Final(WC_HASH_TYPE_SHA512_224, 0),
  13266. TEST_SUCCESS);
  13267. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_224 */
  13268. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13269. return EXPECT_RESULT();
  13270. }
  13271. static int test_wc_Sha512_224GetFlags(void)
  13272. {
  13273. EXPECT_DECLS;
  13274. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13275. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224) && defined(WOLFSSL_HASH_FLAGS)
  13276. wc_Sha512 sha512;
  13277. wc_Sha512 copy;
  13278. word32 flags = 0;
  13279. XMEMSET(&sha512, 0, sizeof(wc_Sha512));
  13280. XMEMSET(&copy, 0, sizeof(wc_Sha512));
  13281. /* Initialize */
  13282. ExpectIntEQ(wc_InitSha512_224(&sha512), 0);
  13283. ExpectIntEQ(wc_InitSha512_224(&copy), 0);
  13284. ExpectIntEQ(wc_Sha512_224GetFlags(&sha512, &flags), 0);
  13285. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  13286. ExpectIntEQ(wc_Sha512_224Copy(&sha512, &copy), 0);
  13287. ExpectIntEQ(wc_Sha512_224GetFlags(&copy, &flags), 0);
  13288. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == WC_HASH_FLAG_ISCOPY);
  13289. wc_Sha512_224Free(&copy);
  13290. wc_Sha512_224Free(&sha512);
  13291. #endif
  13292. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13293. return EXPECT_RESULT();
  13294. }
  13295. static int test_wc_Sha512_224FinalRaw(void)
  13296. {
  13297. EXPECT_DECLS;
  13298. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  13299. defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224) && \
  13300. !defined(WOLFSSL_NO_HASH_RAW)
  13301. ExpectIntEQ(test_Sha512_Family_Final(WC_HASH_TYPE_SHA512_224, 1),
  13302. TEST_SUCCESS);
  13303. #endif
  13304. return EXPECT_RESULT();
  13305. }
  13306. static int test_wc_Sha512_224Free(void)
  13307. {
  13308. EXPECT_DECLS;
  13309. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13310. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  13311. wc_Sha512_224Free(NULL);
  13312. /* Set result to SUCCESS. */
  13313. ExpectTrue(1);
  13314. #endif
  13315. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13316. return EXPECT_RESULT();
  13317. }
  13318. static int test_wc_Sha512_224GetHash(void)
  13319. {
  13320. EXPECT_DECLS;
  13321. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13322. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  13323. ExpectIntEQ(test_Sha512_Family_GetHash(WC_HASH_TYPE_SHA512_224),
  13324. TEST_SUCCESS);
  13325. #endif
  13326. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13327. return EXPECT_RESULT();
  13328. }
  13329. static int test_wc_Sha512_224Copy(void)
  13330. {
  13331. EXPECT_DECLS;
  13332. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13333. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  13334. wc_Sha512 sha512;
  13335. wc_Sha512 temp;
  13336. XMEMSET(&sha512, 0, sizeof(wc_Sha512));
  13337. XMEMSET(&temp, 0, sizeof(wc_Sha512));
  13338. /* Initialize */
  13339. ExpectIntEQ(wc_InitSha512_224(&sha512), 0);
  13340. ExpectIntEQ(wc_InitSha512_224(&temp), 0);
  13341. ExpectIntEQ(wc_Sha512_224Copy(&sha512, &temp), 0);
  13342. /* test bad arguments*/
  13343. ExpectIntEQ(wc_Sha512_224Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13344. ExpectIntEQ(wc_Sha512_224Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13345. ExpectIntEQ(wc_Sha512_224Copy(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13346. wc_Sha512_224Free(&sha512);
  13347. wc_Sha512_224Free(&temp);
  13348. #endif
  13349. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13350. return EXPECT_RESULT();
  13351. }
  13352. static int test_wc_InitSha512_256(void)
  13353. {
  13354. EXPECT_DECLS;
  13355. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13356. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  13357. wc_Sha512 sha512;
  13358. /* Test good arg. */
  13359. ExpectIntEQ(wc_InitSha512_256(&sha512), 0);
  13360. /* Test bad arg. */
  13361. ExpectIntEQ(wc_InitSha512_256(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13362. wc_Sha512_256Free(&sha512);
  13363. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_256 */
  13364. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13365. return EXPECT_RESULT();
  13366. }
  13367. static int test_wc_Sha512_256Update(void)
  13368. {
  13369. EXPECT_DECLS;
  13370. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13371. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  13372. wc_Sha512 sha512;
  13373. byte hash[WC_SHA512_DIGEST_SIZE];
  13374. testVector a, c;
  13375. ExpectIntEQ(wc_InitSha512_256(&sha512), 0);
  13376. /* Input. */
  13377. a.input = "a";
  13378. a.inLen = XSTRLEN(a.input);
  13379. ExpectIntEQ(wc_Sha512_256Update(&sha512, NULL, 0), 0);
  13380. ExpectIntEQ(wc_Sha512_256Update(&sha512,(byte*)a.input, 0), 0);
  13381. ExpectIntEQ(wc_Sha512_256Update(&sha512, (byte*)a.input, (word32)a.inLen),
  13382. 0);
  13383. ExpectIntEQ(wc_Sha512_256Final(&sha512, hash), 0);
  13384. /* Update input. */
  13385. a.input = "abc";
  13386. a.output = "\x53\x04\x8e\x26\x81\x94\x1e\xf9\x9b\x2e\x29\xb7\x6b\x4c"
  13387. "\x7d\xab\xe4\xc2\xd0\xc6\x34\xfc\x6d\x46\xe0\xe2\xf1\x31"
  13388. "\x07\xe7\xaf\x23";
  13389. a.inLen = XSTRLEN(a.input);
  13390. a.outLen = XSTRLEN(a.output);
  13391. ExpectIntEQ(wc_Sha512_256Update(&sha512, (byte*) a.input, (word32) a.inLen),
  13392. 0);
  13393. ExpectIntEQ(wc_Sha512_256Final(&sha512, hash), 0);
  13394. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA512_256_DIGEST_SIZE), 0);
  13395. c.input = NULL;
  13396. c.inLen = WC_SHA512_256_DIGEST_SIZE;
  13397. ExpectIntEQ(wc_Sha512_256Update(&sha512, (byte*)c.input, (word32)c.inLen),
  13398. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13399. ExpectIntEQ(wc_Sha512_256Update(NULL, (byte*)a.input, (word32)a.inLen),
  13400. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13401. wc_Sha512_256Free(&sha512);
  13402. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_256 */
  13403. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13404. return EXPECT_RESULT();
  13405. }
  13406. static int test_wc_Sha512_256Final(void)
  13407. {
  13408. EXPECT_DECLS;
  13409. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13410. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  13411. ExpectIntEQ(test_Sha512_Family_Final(WC_HASH_TYPE_SHA512_256, 0),
  13412. TEST_SUCCESS);
  13413. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_256 */
  13414. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13415. return EXPECT_RESULT();
  13416. }
  13417. static int test_wc_Sha512_256GetFlags(void)
  13418. {
  13419. EXPECT_DECLS;
  13420. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13421. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256) && defined(WOLFSSL_HASH_FLAGS)
  13422. wc_Sha512 sha512, copy;
  13423. word32 flags = 0;
  13424. XMEMSET(&sha512, 0, sizeof(wc_Sha512));
  13425. XMEMSET(&copy, 0, sizeof(wc_Sha512));
  13426. /* Initialize */
  13427. ExpectIntEQ(wc_InitSha512_256(&sha512), 0);
  13428. ExpectIntEQ(wc_InitSha512_256(&copy), 0);
  13429. ExpectIntEQ(wc_Sha512_256GetFlags(&sha512, &flags), 0);
  13430. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  13431. ExpectIntEQ(wc_Sha512_256Copy(&sha512, &copy), 0);
  13432. ExpectIntEQ(wc_Sha512_256GetFlags(&copy, &flags), 0);
  13433. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == WC_HASH_FLAG_ISCOPY);
  13434. wc_Sha512_256Free(&sha512);
  13435. #endif
  13436. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13437. return EXPECT_RESULT();
  13438. }
  13439. static int test_wc_Sha512_256FinalRaw(void)
  13440. {
  13441. EXPECT_DECLS;
  13442. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  13443. defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256) && \
  13444. !defined(WOLFSSL_NO_HASH_RAW)
  13445. ExpectIntEQ(test_Sha512_Family_Final(WC_HASH_TYPE_SHA512_256, 1),
  13446. TEST_SUCCESS);
  13447. #endif
  13448. return EXPECT_RESULT();
  13449. }
  13450. static int test_wc_Sha512_256Free(void)
  13451. {
  13452. EXPECT_DECLS;
  13453. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13454. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  13455. wc_Sha512_256Free(NULL);
  13456. /* Set result to SUCCESS. */
  13457. ExpectTrue(1);
  13458. #endif
  13459. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13460. return EXPECT_RESULT();
  13461. }
  13462. static int test_wc_Sha512_256GetHash(void)
  13463. {
  13464. EXPECT_DECLS;
  13465. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13466. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  13467. ExpectIntEQ(test_Sha512_Family_GetHash(WC_HASH_TYPE_SHA512_256),
  13468. TEST_SUCCESS);
  13469. #endif
  13470. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13471. return EXPECT_RESULT();
  13472. }
  13473. static int test_wc_Sha512_256Copy(void)
  13474. {
  13475. EXPECT_DECLS;
  13476. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13477. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  13478. wc_Sha512 sha512;
  13479. wc_Sha512 temp;
  13480. XMEMSET(&sha512, 0, sizeof(wc_Sha512));
  13481. XMEMSET(&temp, 0, sizeof(wc_Sha512));
  13482. /* Initialize */
  13483. ExpectIntEQ(wc_InitSha512_256(&sha512), 0);
  13484. ExpectIntEQ(wc_InitSha512_256(&temp), 0);
  13485. ExpectIntEQ(wc_Sha512_256Copy(&sha512, &temp), 0);
  13486. /* test bad arguments*/
  13487. ExpectIntEQ(wc_Sha512_256Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13488. ExpectIntEQ(wc_Sha512_256Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13489. ExpectIntEQ(wc_Sha512_256Copy(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13490. wc_Sha512_256Free(&sha512);
  13491. wc_Sha512_256Free(&temp);
  13492. #endif
  13493. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13494. return EXPECT_RESULT();
  13495. }
  13496. /*
  13497. * Testing wc_InitSha384()
  13498. */
  13499. static int test_wc_InitSha384(void)
  13500. {
  13501. EXPECT_DECLS;
  13502. #ifdef WOLFSSL_SHA384
  13503. wc_Sha384 sha384;
  13504. /* Test good arg. */
  13505. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13506. /* Test bad arg. */
  13507. ExpectIntEQ(wc_InitSha384(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13508. wc_Sha384Free(&sha384);
  13509. #endif
  13510. return EXPECT_RESULT();
  13511. } /* END test_wc_InitSha384 */
  13512. /*
  13513. * test wc_Sha384Update()
  13514. */
  13515. static int test_wc_Sha384Update(void)
  13516. {
  13517. EXPECT_DECLS;
  13518. #ifdef WOLFSSL_SHA384
  13519. wc_Sha384 sha384;
  13520. byte hash[WC_SHA384_DIGEST_SIZE];
  13521. testVector a, b, c;
  13522. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13523. /* Input */
  13524. a.input = "a";
  13525. a.inLen = XSTRLEN(a.input);
  13526. ExpectIntEQ(wc_Sha384Update(&sha384, NULL, 0), 0);
  13527. ExpectIntEQ(wc_Sha384Update(&sha384, (byte*)a.input, 0), 0);
  13528. ExpectIntEQ(wc_Sha384Update(&sha384, (byte*)a.input, (word32)a.inLen), 0);
  13529. ExpectIntEQ(wc_Sha384Final(&sha384, hash), 0);
  13530. /* Update input. */
  13531. a.input = "abc";
  13532. a.output = "\xcb\x00\x75\x3f\x45\xa3\x5e\x8b\xb5\xa0\x3d\x69\x9a\xc6\x50"
  13533. "\x07\x27\x2c\x32\xab\x0e\xde\xd1\x63\x1a\x8b\x60\x5a\x43\xff"
  13534. "\x5b\xed\x80\x86\x07\x2b\xa1\xe7\xcc\x23\x58\xba\xec\xa1\x34"
  13535. "\xc8\x25\xa7";
  13536. a.inLen = XSTRLEN(a.input);
  13537. a.outLen = XSTRLEN(a.output);
  13538. ExpectIntEQ(wc_Sha384Update(&sha384, (byte*)a.input, (word32)a.inLen), 0);
  13539. ExpectIntEQ(wc_Sha384Final(&sha384, hash), 0);
  13540. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA384_DIGEST_SIZE), 0);
  13541. /* Pass in bad values. */
  13542. b.input = NULL;
  13543. b.inLen = 0;
  13544. ExpectIntEQ(wc_Sha384Update(&sha384, (byte*)b.input, (word32)b.inLen), 0);
  13545. c.input = NULL;
  13546. c.inLen = WC_SHA384_DIGEST_SIZE;
  13547. ExpectIntEQ( wc_Sha384Update(&sha384, (byte*)c.input, (word32)c.inLen),
  13548. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13549. ExpectIntEQ(wc_Sha384Update(NULL, (byte*)a.input, (word32)a.inLen),
  13550. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13551. wc_Sha384Free(&sha384);
  13552. #endif
  13553. return EXPECT_RESULT();
  13554. } /* END test_wc_Sha384Update */
  13555. /*
  13556. * Unit test function for wc_Sha384Final();
  13557. */
  13558. static int test_wc_Sha384Final(void)
  13559. {
  13560. EXPECT_DECLS;
  13561. #ifdef WOLFSSL_SHA384
  13562. wc_Sha384 sha384;
  13563. byte* hash_test[3];
  13564. byte hash1[WC_SHA384_DIGEST_SIZE];
  13565. byte hash2[2*WC_SHA384_DIGEST_SIZE];
  13566. byte hash3[5*WC_SHA384_DIGEST_SIZE];
  13567. int times, i;
  13568. /* Initialize */
  13569. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13570. hash_test[0] = hash1;
  13571. hash_test[1] = hash2;
  13572. hash_test[2] = hash3;
  13573. times = sizeof(hash_test) / sizeof(byte*);
  13574. /* Good test args. */
  13575. for (i = 0; i < times; i++) {
  13576. ExpectIntEQ(wc_Sha384Final(&sha384, hash_test[i]), 0);
  13577. }
  13578. /* Test bad args. */
  13579. ExpectIntEQ(wc_Sha384Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13580. ExpectIntEQ(wc_Sha384Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13581. ExpectIntEQ(wc_Sha384Final(&sha384, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13582. wc_Sha384Free(&sha384);
  13583. #endif
  13584. return EXPECT_RESULT();
  13585. } /* END test_wc_Sha384Final */
  13586. /*
  13587. * Unit test function for wc_Sha384GetFlags()
  13588. */
  13589. static int test_wc_Sha384GetFlags(void)
  13590. {
  13591. EXPECT_DECLS;
  13592. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_HASH_FLAGS)
  13593. wc_Sha384 sha384;
  13594. word32 flags = 0;
  13595. /* Initialize */
  13596. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13597. ExpectIntEQ(wc_Sha384GetFlags(&sha384, &flags), 0);
  13598. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  13599. wc_Sha384Free(&sha384);
  13600. #endif
  13601. return EXPECT_RESULT();
  13602. } /* END test_wc_Sha384GetFlags */
  13603. /*
  13604. * Unit test function for wc_Sha384FinalRaw()
  13605. */
  13606. static int test_wc_Sha384FinalRaw(void)
  13607. {
  13608. EXPECT_DECLS;
  13609. #if (defined(WOLFSSL_SHA384) && !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  13610. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3)))) && \
  13611. !defined(WOLFSSL_NO_HASH_RAW)
  13612. wc_Sha384 sha384;
  13613. byte* hash_test[3];
  13614. byte hash1[WC_SHA384_DIGEST_SIZE];
  13615. byte hash2[2*WC_SHA384_DIGEST_SIZE];
  13616. byte hash3[5*WC_SHA384_DIGEST_SIZE];
  13617. int times, i;
  13618. /* Initialize */
  13619. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13620. hash_test[0] = hash1;
  13621. hash_test[1] = hash2;
  13622. hash_test[2] = hash3;
  13623. times = sizeof(hash_test) / sizeof(byte*);
  13624. /* Good test args. */
  13625. for (i = 0; i < times; i++) {
  13626. ExpectIntEQ(wc_Sha384FinalRaw(&sha384, hash_test[i]), 0);
  13627. }
  13628. /* Test bad args. */
  13629. ExpectIntEQ(wc_Sha384FinalRaw(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13630. ExpectIntEQ(wc_Sha384FinalRaw(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13631. ExpectIntEQ(wc_Sha384FinalRaw(&sha384, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13632. wc_Sha384Free(&sha384);
  13633. #endif
  13634. return EXPECT_RESULT();
  13635. } /* END test_wc_Sha384FinalRaw */
  13636. /*
  13637. * Unit test function for wc_Sha384Free()
  13638. */
  13639. static int test_wc_Sha384Free(void)
  13640. {
  13641. EXPECT_DECLS;
  13642. #ifdef WOLFSSL_SHA384
  13643. wc_Sha384Free(NULL);
  13644. /* Set result to SUCCESS. */
  13645. ExpectTrue(1);
  13646. #endif
  13647. return EXPECT_RESULT();
  13648. } /* END test_wc_Sha384Free */
  13649. /*
  13650. * Unit test function for wc_Sha384GetHash()
  13651. */
  13652. static int test_wc_Sha384GetHash(void)
  13653. {
  13654. EXPECT_DECLS;
  13655. #ifdef WOLFSSL_SHA384
  13656. wc_Sha384 sha384;
  13657. byte hash1[WC_SHA384_DIGEST_SIZE];
  13658. /* Initialize */
  13659. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13660. ExpectIntEQ(wc_Sha384GetHash(&sha384, hash1), 0);
  13661. /* test bad arguments*/
  13662. ExpectIntEQ(wc_Sha384GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13663. ExpectIntEQ(wc_Sha384GetHash(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13664. ExpectIntEQ(wc_Sha384GetHash(&sha384, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13665. wc_Sha384Free(&sha384);
  13666. #endif
  13667. return EXPECT_RESULT();
  13668. } /* END test_wc_Sha384GetHash */
  13669. /*
  13670. * Unit test function for wc_Sha384Copy()
  13671. */
  13672. static int test_wc_Sha384Copy(void)
  13673. {
  13674. EXPECT_DECLS;
  13675. #ifdef WOLFSSL_SHA384
  13676. wc_Sha384 sha384;
  13677. wc_Sha384 temp;
  13678. XMEMSET(&sha384, 0, sizeof(wc_Sha384));
  13679. XMEMSET(&temp, 0, sizeof(wc_Sha384));
  13680. /* Initialize */
  13681. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13682. ExpectIntEQ(wc_InitSha384(&temp), 0);
  13683. ExpectIntEQ(wc_Sha384Copy(&sha384, &temp), 0);
  13684. /* test bad arguments*/
  13685. ExpectIntEQ(wc_Sha384Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13686. ExpectIntEQ(wc_Sha384Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13687. ExpectIntEQ(wc_Sha384Copy(&sha384, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13688. wc_Sha384Free(&sha384);
  13689. wc_Sha384Free(&temp);
  13690. #endif
  13691. return EXPECT_RESULT();
  13692. } /* END test_wc_Sha384Copy */
  13693. /*
  13694. * Testing wc_InitSha224();
  13695. */
  13696. static int test_wc_InitSha224(void)
  13697. {
  13698. EXPECT_DECLS;
  13699. #ifdef WOLFSSL_SHA224
  13700. wc_Sha224 sha224;
  13701. /* Test good arg. */
  13702. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13703. /* Test bad arg. */
  13704. ExpectIntEQ(wc_InitSha224(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13705. wc_Sha224Free(&sha224);
  13706. #endif
  13707. return EXPECT_RESULT();
  13708. } /* END test_wc_InitSha224 */
  13709. /*
  13710. * Unit test on wc_Sha224Update
  13711. */
  13712. static int test_wc_Sha224Update(void)
  13713. {
  13714. EXPECT_DECLS;
  13715. #ifdef WOLFSSL_SHA224
  13716. wc_Sha224 sha224;
  13717. byte hash[WC_SHA224_DIGEST_SIZE];
  13718. testVector a, b, c;
  13719. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13720. /* Input. */
  13721. a.input = "a";
  13722. a.inLen = XSTRLEN(a.input);
  13723. ExpectIntEQ(wc_Sha224Update(&sha224, NULL, 0), 0);
  13724. ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)a.input, 0), 0);
  13725. ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)a.input, (word32)a.inLen), 0);
  13726. ExpectIntEQ(wc_Sha224Final(&sha224, hash), 0);
  13727. /* Update input. */
  13728. a.input = "abc";
  13729. a.output = "\x23\x09\x7d\x22\x34\x05\xd8\x22\x86\x42\xa4\x77\xbd\xa2"
  13730. "\x55\xb3\x2a\xad\xbc\xe4\xbd\xa0\xb3\xf7\xe3\x6c\x9d\xa7";
  13731. a.inLen = XSTRLEN(a.input);
  13732. a.outLen = XSTRLEN(a.output);
  13733. ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)a.input, (word32)a.inLen), 0);
  13734. ExpectIntEQ(wc_Sha224Final(&sha224, hash), 0);
  13735. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA224_DIGEST_SIZE), 0);
  13736. /* Pass in bad values. */
  13737. b.input = NULL;
  13738. b.inLen = 0;
  13739. ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)b.input, (word32)b.inLen), 0);
  13740. c.input = NULL;
  13741. c.inLen = WC_SHA224_DIGEST_SIZE;
  13742. ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)c.input, (word32)c.inLen),
  13743. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13744. ExpectIntEQ(wc_Sha224Update(NULL, (byte*)a.input, (word32)a.inLen),
  13745. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13746. wc_Sha224Free(&sha224);
  13747. #endif
  13748. return EXPECT_RESULT();
  13749. } /* END test_wc_Sha224Update */
  13750. /*
  13751. * Unit test for wc_Sha224Final();
  13752. */
  13753. static int test_wc_Sha224Final(void)
  13754. {
  13755. EXPECT_DECLS;
  13756. #ifdef WOLFSSL_SHA224
  13757. wc_Sha224 sha224;
  13758. byte* hash_test[3];
  13759. byte hash1[WC_SHA224_DIGEST_SIZE];
  13760. byte hash2[2*WC_SHA224_DIGEST_SIZE];
  13761. byte hash3[5*WC_SHA224_DIGEST_SIZE];
  13762. int times, i;
  13763. /* Initialize */
  13764. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13765. hash_test[0] = hash1;
  13766. hash_test[1] = hash2;
  13767. hash_test[2] = hash3;
  13768. times = sizeof(hash_test) / sizeof(byte*);
  13769. /* Good test args. */
  13770. /* Testing oversized buffers. */
  13771. for (i = 0; i < times; i++) {
  13772. ExpectIntEQ(wc_Sha224Final(&sha224, hash_test[i]), 0);
  13773. }
  13774. /* Test bad args. */
  13775. ExpectIntEQ(wc_Sha224Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13776. ExpectIntEQ(wc_Sha224Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13777. ExpectIntEQ(wc_Sha224Final(&sha224, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13778. wc_Sha224Free(&sha224);
  13779. #endif
  13780. return EXPECT_RESULT();
  13781. } /* END test_wc_Sha224Final */
  13782. /*
  13783. * Unit test function for wc_Sha224SetFlags()
  13784. */
  13785. static int test_wc_Sha224SetFlags(void)
  13786. {
  13787. EXPECT_DECLS;
  13788. #if defined(WOLFSSL_SHA224) && defined(WOLFSSL_HASH_FLAGS)
  13789. wc_Sha224 sha224;
  13790. word32 flags = WC_HASH_FLAG_WILLCOPY;
  13791. /* Initialize */
  13792. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13793. ExpectIntEQ(wc_Sha224SetFlags(&sha224, flags), 0);
  13794. flags = 0;
  13795. ExpectIntEQ(wc_Sha224GetFlags(&sha224, &flags), 0);
  13796. ExpectTrue(flags == WC_HASH_FLAG_WILLCOPY);
  13797. wc_Sha224Free(&sha224);
  13798. #endif
  13799. return EXPECT_RESULT();
  13800. } /* END test_wc_Sha224SetFlags */
  13801. /*
  13802. * Unit test function for wc_Sha224GetFlags()
  13803. */
  13804. static int test_wc_Sha224GetFlags(void)
  13805. {
  13806. EXPECT_DECLS;
  13807. #if defined(WOLFSSL_SHA224) && defined(WOLFSSL_HASH_FLAGS)
  13808. wc_Sha224 sha224;
  13809. word32 flags = 0;
  13810. /* Initialize */
  13811. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13812. ExpectIntEQ(wc_Sha224GetFlags(&sha224, &flags), 0);
  13813. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  13814. wc_Sha224Free(&sha224);
  13815. #endif
  13816. return EXPECT_RESULT();
  13817. } /* END test_wc_Sha224GetFlags */
  13818. /*
  13819. * Unit test function for wc_Sha224Free()
  13820. */
  13821. static int test_wc_Sha224Free(void)
  13822. {
  13823. EXPECT_DECLS;
  13824. #ifdef WOLFSSL_SHA224
  13825. wc_Sha224Free(NULL);
  13826. /* Set result to SUCCESS. */
  13827. ExpectTrue(1);
  13828. #endif
  13829. return EXPECT_RESULT();
  13830. } /* END test_wc_Sha224Free */
  13831. /*
  13832. * Unit test function for wc_Sha224GetHash()
  13833. */
  13834. static int test_wc_Sha224GetHash(void)
  13835. {
  13836. EXPECT_DECLS;
  13837. #ifdef WOLFSSL_SHA224
  13838. wc_Sha224 sha224;
  13839. byte hash1[WC_SHA224_DIGEST_SIZE];
  13840. /* Initialize */
  13841. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13842. ExpectIntEQ(wc_Sha224GetHash(&sha224, hash1), 0);
  13843. /* test bad arguments*/
  13844. ExpectIntEQ(wc_Sha224GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13845. ExpectIntEQ(wc_Sha224GetHash(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13846. ExpectIntEQ(wc_Sha224GetHash(&sha224, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13847. wc_Sha224Free(&sha224);
  13848. #endif
  13849. return EXPECT_RESULT();
  13850. } /* END test_wc_Sha224GetHash */
  13851. /*
  13852. * Unit test function for wc_Sha224Copy()
  13853. */
  13854. static int test_wc_Sha224Copy(void)
  13855. {
  13856. EXPECT_DECLS;
  13857. #ifdef WOLFSSL_SHA224
  13858. wc_Sha224 sha224;
  13859. wc_Sha224 temp;
  13860. XMEMSET(&sha224, 0, sizeof(wc_Sha224));
  13861. XMEMSET(&temp, 0, sizeof(wc_Sha224));
  13862. /* Initialize */
  13863. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13864. ExpectIntEQ(wc_InitSha224(&temp), 0);
  13865. ExpectIntEQ(wc_Sha224Copy(&sha224, &temp), 0);
  13866. /* test bad arguments*/
  13867. ExpectIntEQ(wc_Sha224Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13868. ExpectIntEQ(wc_Sha224Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13869. ExpectIntEQ(wc_Sha224Copy(&sha224, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13870. wc_Sha224Free(&sha224);
  13871. wc_Sha224Free(&temp);
  13872. #endif
  13873. return EXPECT_RESULT();
  13874. } /* END test_wc_Sha224Copy */
  13875. /*
  13876. * Testing wc_InitRipeMd()
  13877. */
  13878. static int test_wc_InitRipeMd(void)
  13879. {
  13880. EXPECT_DECLS;
  13881. #ifdef WOLFSSL_RIPEMD
  13882. RipeMd ripemd;
  13883. /* Test good arg. */
  13884. ExpectIntEQ(wc_InitRipeMd(&ripemd), 0);
  13885. /* Test bad arg. */
  13886. ExpectIntEQ(wc_InitRipeMd(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13887. #endif
  13888. return EXPECT_RESULT();
  13889. } /* END test_wc_InitRipeMd */
  13890. /*
  13891. * Testing wc_RipeMdUpdate()
  13892. */
  13893. static int test_wc_RipeMdUpdate(void)
  13894. {
  13895. EXPECT_DECLS;
  13896. #ifdef WOLFSSL_RIPEMD
  13897. RipeMd ripemd;
  13898. byte hash[RIPEMD_DIGEST_SIZE];
  13899. testVector a, b, c;
  13900. ExpectIntEQ(wc_InitRipeMd(&ripemd), 0);
  13901. /* Input */
  13902. a.input = "a";
  13903. a.inLen = XSTRLEN(a.input);
  13904. ExpectIntEQ(wc_RipeMdUpdate(&ripemd, (byte*)a.input, (word32)a.inLen), 0);
  13905. ExpectIntEQ(wc_RipeMdFinal(&ripemd, hash), 0);
  13906. /* Update input. */
  13907. a.input = "abc";
  13908. a.output = "\x8e\xb2\x08\xf7\xe0\x5d\x98\x7a\x9b\x04\x4a\x8e\x98\xc6"
  13909. "\xb0\x87\xf1\x5a\x0b\xfc";
  13910. a.inLen = XSTRLEN(a.input);
  13911. a.outLen = XSTRLEN(a.output);
  13912. ExpectIntEQ(wc_RipeMdUpdate(&ripemd, (byte*)a.input, (word32)a.inLen), 0);
  13913. ExpectIntEQ(wc_RipeMdFinal(&ripemd, hash), 0);
  13914. ExpectIntEQ(XMEMCMP(hash, a.output, RIPEMD_DIGEST_SIZE), 0);
  13915. /* Pass in bad values. */
  13916. b.input = NULL;
  13917. b.inLen = 0;
  13918. ExpectIntEQ(wc_RipeMdUpdate(&ripemd, (byte*)b.input, (word32)b.inLen), 0);
  13919. c.input = NULL;
  13920. c.inLen = RIPEMD_DIGEST_SIZE;
  13921. ExpectIntEQ(wc_RipeMdUpdate(&ripemd, (byte*)c.input, (word32)c.inLen),
  13922. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13923. ExpectIntEQ(wc_RipeMdUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  13924. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13925. #endif
  13926. return EXPECT_RESULT();
  13927. } /* END test_wc_RipeMdUdpate */
  13928. /*
  13929. * Unit test function for wc_RipeMdFinal()
  13930. */
  13931. static int test_wc_RipeMdFinal(void)
  13932. {
  13933. EXPECT_DECLS;
  13934. #ifdef WOLFSSL_RIPEMD
  13935. RipeMd ripemd;
  13936. byte* hash_test[3];
  13937. byte hash1[RIPEMD_DIGEST_SIZE];
  13938. byte hash2[2*RIPEMD_DIGEST_SIZE];
  13939. byte hash3[5*RIPEMD_DIGEST_SIZE];
  13940. int times, i;
  13941. /* Initialize */
  13942. ExpectIntEQ(wc_InitRipeMd(&ripemd), 0);
  13943. hash_test[0] = hash1;
  13944. hash_test[1] = hash2;
  13945. hash_test[2] = hash3;
  13946. times = sizeof(hash_test) / sizeof(byte*);
  13947. /* Testing oversized buffers. */
  13948. for (i = 0; i < times; i++) {
  13949. ExpectIntEQ(wc_RipeMdFinal(&ripemd, hash_test[i]), 0);
  13950. }
  13951. /* Test bad args. */
  13952. ExpectIntEQ(wc_RipeMdFinal(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13953. ExpectIntEQ(wc_RipeMdFinal(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13954. ExpectIntEQ(wc_RipeMdFinal(&ripemd, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13955. #endif
  13956. return EXPECT_RESULT();
  13957. } /* END test_wc_RipeMdFinal */
  13958. /*
  13959. * Testing wc_InitSha3_224, wc_InitSha3_256, wc_InitSha3_384, and
  13960. * wc_InitSha3_512
  13961. */
  13962. static int test_wc_InitSha3(void)
  13963. {
  13964. EXPECT_DECLS;
  13965. #if defined(WOLFSSL_SHA3)
  13966. wc_Sha3 sha3;
  13967. (void)sha3;
  13968. #if !defined(WOLFSSL_NOSHA3_224)
  13969. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  13970. /* Test bad args. */
  13971. ExpectIntEQ(wc_InitSha3_224(NULL, HEAP_HINT, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13972. wc_Sha3_224_Free(&sha3);
  13973. #endif /* NOSHA3_224 */
  13974. #if !defined(WOLFSSL_NOSHA3_256)
  13975. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  13976. /* Test bad args. */
  13977. ExpectIntEQ(wc_InitSha3_256(NULL, HEAP_HINT, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13978. wc_Sha3_256_Free(&sha3);
  13979. #endif /* NOSHA3_256 */
  13980. #if !defined(WOLFSSL_NOSHA3_384)
  13981. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  13982. /* Test bad args. */
  13983. ExpectIntEQ(wc_InitSha3_384(NULL, HEAP_HINT, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13984. wc_Sha3_384_Free(&sha3);
  13985. #endif /* NOSHA3_384 */
  13986. #if !defined(WOLFSSL_NOSHA3_512)
  13987. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  13988. /* Test bad args. */
  13989. ExpectIntEQ(wc_InitSha3_512(NULL, HEAP_HINT, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13990. wc_Sha3_512_Free(&sha3);
  13991. #endif /* NOSHA3_512 */
  13992. #endif
  13993. return EXPECT_RESULT();
  13994. } /* END test_wc_InitSha3 */
  13995. /*
  13996. * Testing wc_Sha3_Update()
  13997. */
  13998. static int testing_wc_Sha3_Update(void)
  13999. {
  14000. EXPECT_DECLS;
  14001. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_XILINX_CRYPT) && \
  14002. !defined(WOLFSSL_AFALG_XILINX)
  14003. wc_Sha3 sha3;
  14004. byte msg[] = "Everybody's working for the weekend.";
  14005. byte msg2[] = "Everybody gets Friday off.";
  14006. byte msgCmp[] = "\x45\x76\x65\x72\x79\x62\x6f\x64\x79\x27\x73\x20"
  14007. "\x77\x6f\x72\x6b\x69\x6e\x67\x20\x66\x6f\x72\x20\x74"
  14008. "\x68\x65\x20\x77\x65\x65\x6b\x65\x6e\x64\x2e\x45\x76"
  14009. "\x65\x72\x79\x62\x6f\x64\x79\x20\x67\x65\x74\x73\x20"
  14010. "\x46\x72\x69\x64\x61\x79\x20\x6f\x66\x66\x2e";
  14011. word32 msglen = sizeof(msg) - 1;
  14012. word32 msg2len = sizeof(msg2);
  14013. word32 msgCmplen = sizeof(msgCmp);
  14014. #if !defined(WOLFSSL_NOSHA3_224)
  14015. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  14016. ExpectIntEQ(wc_Sha3_224_Update(&sha3, msg, msglen), 0);
  14017. ExpectIntEQ(XMEMCMP(msg, sha3.t, msglen), 0);
  14018. ExpectTrue(sha3.i == msglen);
  14019. ExpectIntEQ(wc_Sha3_224_Update(&sha3, msg2, msg2len), 0);
  14020. ExpectIntEQ(XMEMCMP(sha3.t, msgCmp, msgCmplen), 0);
  14021. /* Pass bad args. */
  14022. ExpectIntEQ(wc_Sha3_224_Update(NULL, msg2, msg2len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14023. ExpectIntEQ(wc_Sha3_224_Update(&sha3, NULL, 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14024. wc_Sha3_224_Free(&sha3);
  14025. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  14026. ExpectIntEQ(wc_Sha3_224_Update(&sha3, NULL, 0), 0);
  14027. ExpectIntEQ(wc_Sha3_224_Update(&sha3, msg2, msg2len), 0);
  14028. ExpectIntEQ(XMEMCMP(msg2, sha3.t, msg2len), 0);
  14029. wc_Sha3_224_Free(&sha3);
  14030. #endif /* SHA3_224 */
  14031. #if !defined(WOLFSSL_NOSHA3_256)
  14032. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  14033. ExpectIntEQ(wc_Sha3_256_Update(&sha3, msg, msglen), 0);
  14034. ExpectIntEQ(XMEMCMP(msg, sha3.t, msglen), 0);
  14035. ExpectTrue(sha3.i == msglen);
  14036. ExpectIntEQ(wc_Sha3_256_Update(&sha3, msg2, msg2len), 0);
  14037. ExpectIntEQ(XMEMCMP(sha3.t, msgCmp, msgCmplen), 0);
  14038. /* Pass bad args. */
  14039. ExpectIntEQ(wc_Sha3_256_Update(NULL, msg2, msg2len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14040. ExpectIntEQ(wc_Sha3_256_Update(&sha3, NULL, 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14041. wc_Sha3_256_Free(&sha3);
  14042. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  14043. ExpectIntEQ(wc_Sha3_256_Update(&sha3, NULL, 0), 0);
  14044. ExpectIntEQ(wc_Sha3_256_Update(&sha3, msg2, msg2len), 0);
  14045. ExpectIntEQ(XMEMCMP(msg2, sha3.t, msg2len), 0);
  14046. wc_Sha3_256_Free(&sha3);
  14047. #endif /* SHA3_256 */
  14048. #if !defined(WOLFSSL_NOSHA3_384)
  14049. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  14050. ExpectIntEQ(wc_Sha3_384_Update(&sha3, msg, msglen), 0);
  14051. ExpectIntEQ(XMEMCMP(msg, sha3.t, msglen), 0);
  14052. ExpectTrue(sha3.i == msglen);
  14053. ExpectIntEQ(wc_Sha3_384_Update(&sha3, msg2, msg2len), 0);
  14054. ExpectIntEQ(XMEMCMP(sha3.t, msgCmp, msgCmplen), 0);
  14055. /* Pass bad args. */
  14056. ExpectIntEQ(wc_Sha3_384_Update(NULL, msg2, msg2len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14057. ExpectIntEQ(wc_Sha3_384_Update(&sha3, NULL, 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14058. wc_Sha3_384_Free(&sha3);
  14059. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  14060. ExpectIntEQ(wc_Sha3_384_Update(&sha3, NULL, 0), 0);
  14061. ExpectIntEQ(wc_Sha3_384_Update(&sha3, msg2, msg2len), 0);
  14062. ExpectIntEQ(XMEMCMP(msg2, sha3.t, msg2len), 0);
  14063. wc_Sha3_384_Free(&sha3);
  14064. #endif /* SHA3_384 */
  14065. #if !defined(WOLFSSL_NOSHA3_512)
  14066. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  14067. ExpectIntEQ(wc_Sha3_512_Update(&sha3, msg, msglen), 0);
  14068. ExpectIntEQ(XMEMCMP(msg, sha3.t, msglen), 0);
  14069. ExpectTrue(sha3.i == msglen);
  14070. ExpectIntEQ(wc_Sha3_512_Update(&sha3, msg2, msg2len), 0);
  14071. ExpectIntEQ(XMEMCMP(sha3.t, msgCmp, msgCmplen), 0);
  14072. /* Pass bad args. */
  14073. ExpectIntEQ(wc_Sha3_512_Update(NULL, msg2, msg2len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14074. ExpectIntEQ(wc_Sha3_512_Update(&sha3, NULL, 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14075. wc_Sha3_512_Free(&sha3);
  14076. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  14077. ExpectIntEQ(wc_Sha3_512_Update(&sha3, NULL, 0), 0);
  14078. ExpectIntEQ(wc_Sha3_512_Update(&sha3, msg2, msg2len), 0);
  14079. ExpectIntEQ(XMEMCMP(msg2, sha3.t, msg2len), 0);
  14080. wc_Sha3_512_Free(&sha3);
  14081. #endif /* SHA3_512 */
  14082. #endif /* WOLFSSL_SHA3 */
  14083. return EXPECT_RESULT();
  14084. } /* END testing_wc_Sha3_Update */
  14085. /*
  14086. * Testing wc_Sha3_224_Final()
  14087. */
  14088. static int test_wc_Sha3_224_Final(void)
  14089. {
  14090. EXPECT_DECLS;
  14091. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_224)
  14092. wc_Sha3 sha3;
  14093. const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
  14094. "nopnopq";
  14095. const char* expOut = "\x8a\x24\x10\x8b\x15\x4a\xda\x21\xc9\xfd\x55"
  14096. "\x74\x49\x44\x79\xba\x5c\x7e\x7a\xb7\x6e\xf2"
  14097. "\x64\xea\xd0\xfc\xce\x33";
  14098. byte hash[WC_SHA3_224_DIGEST_SIZE];
  14099. byte hashRet[WC_SHA3_224_DIGEST_SIZE];
  14100. /* Init stack variables. */
  14101. XMEMSET(hash, 0, sizeof(hash));
  14102. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  14103. ExpectIntEQ(wc_Sha3_224_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14104. ExpectIntEQ(wc_Sha3_224_Final(&sha3, hash), 0);
  14105. ExpectIntEQ(XMEMCMP(expOut, hash, WC_SHA3_224_DIGEST_SIZE), 0);
  14106. /* Test bad args. */
  14107. ExpectIntEQ(wc_Sha3_224_Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14108. ExpectIntEQ(wc_Sha3_224_Final(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14109. wc_Sha3_224_Free(&sha3);
  14110. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  14111. /* Init stack variables. */
  14112. XMEMSET(hash, 0, sizeof(hash));
  14113. XMEMSET(hashRet, 0, sizeof(hashRet));
  14114. ExpectIntEQ(wc_Sha3_224_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14115. ExpectIntEQ(wc_Sha3_224_GetHash(&sha3, hashRet), 0);
  14116. ExpectIntEQ(wc_Sha3_224_Final(&sha3, hash), 0);
  14117. ExpectIntEQ(XMEMCMP(hash, hashRet, WC_SHA3_224_DIGEST_SIZE), 0);
  14118. /* Test bad args. */
  14119. ExpectIntEQ(wc_Sha3_224_GetHash(NULL, hashRet), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14120. ExpectIntEQ(wc_Sha3_224_GetHash(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14121. wc_Sha3_224_Free(&sha3);
  14122. #endif
  14123. return EXPECT_RESULT();
  14124. } /* END test_wc_Sha3_224_Final */
  14125. /*
  14126. * Testing wc_Sha3_256_Final()
  14127. */
  14128. static int test_wc_Sha3_256_Final(void)
  14129. {
  14130. EXPECT_DECLS;
  14131. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  14132. wc_Sha3 sha3;
  14133. const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
  14134. "nopnopq";
  14135. const char* expOut = "\x41\xc0\xdb\xa2\xa9\xd6\x24\x08\x49\x10\x03\x76\xa8"
  14136. "\x23\x5e\x2c\x82\xe1\xb9\x99\x8a\x99\x9e\x21\xdb\x32"
  14137. "\xdd\x97\x49\x6d\x33\x76";
  14138. byte hash[WC_SHA3_256_DIGEST_SIZE];
  14139. byte hashRet[WC_SHA3_256_DIGEST_SIZE];
  14140. /* Init stack variables. */
  14141. XMEMSET(hash, 0, sizeof(hash));
  14142. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  14143. ExpectIntEQ(wc_Sha3_256_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14144. ExpectIntEQ(wc_Sha3_256_Final(&sha3, hash), 0);
  14145. ExpectIntEQ(XMEMCMP(expOut, hash, WC_SHA3_256_DIGEST_SIZE), 0);
  14146. /* Test bad args. */
  14147. ExpectIntEQ(wc_Sha3_256_Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14148. ExpectIntEQ(wc_Sha3_256_Final(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14149. wc_Sha3_256_Free(&sha3);
  14150. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  14151. /* Init stack variables. */
  14152. XMEMSET(hash, 0, sizeof(hash));
  14153. XMEMSET(hashRet, 0, sizeof(hashRet));
  14154. ExpectIntEQ(wc_Sha3_256_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14155. ExpectIntEQ(wc_Sha3_256_GetHash(&sha3, hashRet), 0);
  14156. ExpectIntEQ(wc_Sha3_256_Final(&sha3, hash), 0);
  14157. ExpectIntEQ(XMEMCMP(hash, hashRet, WC_SHA3_256_DIGEST_SIZE), 0);
  14158. /* Test bad args. */
  14159. ExpectIntEQ(wc_Sha3_256_GetHash(NULL, hashRet), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14160. ExpectIntEQ(wc_Sha3_256_GetHash(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14161. wc_Sha3_256_Free(&sha3);
  14162. #endif
  14163. return EXPECT_RESULT();
  14164. } /* END test_wc_Sha3_256_Final */
  14165. /*
  14166. * Testing wc_Sha3_384_Final()
  14167. */
  14168. static int test_wc_Sha3_384_Final(void)
  14169. {
  14170. EXPECT_DECLS;
  14171. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_384)
  14172. wc_Sha3 sha3;
  14173. const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
  14174. "nopnopq";
  14175. const char* expOut = "\x99\x1c\x66\x57\x55\xeb\x3a\x4b\x6b\xbd\xfb\x75\xc7"
  14176. "\x8a\x49\x2e\x8c\x56\xa2\x2c\x5c\x4d\x7e\x42\x9b\xfd"
  14177. "\xbc\x32\xb9\xd4\xad\x5a\xa0\x4a\x1f\x07\x6e\x62\xfe"
  14178. "\xa1\x9e\xef\x51\xac\xd0\x65\x7c\x22";
  14179. byte hash[WC_SHA3_384_DIGEST_SIZE];
  14180. byte hashRet[WC_SHA3_384_DIGEST_SIZE];
  14181. /* Init stack variables. */
  14182. XMEMSET(hash, 0, sizeof(hash));
  14183. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  14184. ExpectIntEQ(wc_Sha3_384_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14185. ExpectIntEQ(wc_Sha3_384_Final(&sha3, hash), 0);
  14186. ExpectIntEQ(XMEMCMP(expOut, hash, WC_SHA3_384_DIGEST_SIZE), 0);
  14187. /* Test bad args. */
  14188. ExpectIntEQ(wc_Sha3_384_Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14189. ExpectIntEQ(wc_Sha3_384_Final(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14190. wc_Sha3_384_Free(&sha3);
  14191. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  14192. /* Init stack variables. */
  14193. XMEMSET(hash, 0, sizeof(hash));
  14194. XMEMSET(hashRet, 0, sizeof(hashRet));
  14195. ExpectIntEQ(wc_Sha3_384_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14196. ExpectIntEQ(wc_Sha3_384_GetHash(&sha3, hashRet), 0);
  14197. ExpectIntEQ(wc_Sha3_384_Final(&sha3, hash), 0);
  14198. ExpectIntEQ(XMEMCMP(hash, hashRet, WC_SHA3_384_DIGEST_SIZE), 0);
  14199. /* Test bad args. */
  14200. ExpectIntEQ(wc_Sha3_384_GetHash(NULL, hashRet), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14201. ExpectIntEQ(wc_Sha3_384_GetHash(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14202. wc_Sha3_384_Free(&sha3);
  14203. #endif
  14204. return EXPECT_RESULT();
  14205. } /* END test_wc_Sha3_384_Final */
  14206. /*
  14207. * Testing wc_Sha3_512_Final()
  14208. */
  14209. static int test_wc_Sha3_512_Final(void)
  14210. {
  14211. EXPECT_DECLS;
  14212. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_512) && \
  14213. !defined(WOLFSSL_NOSHA3_384)
  14214. wc_Sha3 sha3;
  14215. const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
  14216. "nopnopq";
  14217. const char* expOut = "\x04\xa3\x71\xe8\x4e\xcf\xb5\xb8\xb7\x7c\xb4\x86\x10"
  14218. "\xfc\xa8\x18\x2d\xd4\x57\xce\x6f\x32\x6a\x0f\xd3\xd7"
  14219. "\xec\x2f\x1e\x91\x63\x6d\xee\x69\x1f\xbe\x0c\x98\x53"
  14220. "\x02\xba\x1b\x0d\x8d\xc7\x8c\x08\x63\x46\xb5\x33\xb4"
  14221. "\x9c\x03\x0d\x99\xa2\x7d\xaf\x11\x39\xd6\xe7\x5e";
  14222. byte hash[WC_SHA3_512_DIGEST_SIZE];
  14223. byte hashRet[WC_SHA3_512_DIGEST_SIZE];
  14224. /* Init stack variables. */
  14225. XMEMSET(hash, 0, sizeof(hash));
  14226. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  14227. ExpectIntEQ(wc_Sha3_512_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14228. ExpectIntEQ(wc_Sha3_512_Final(&sha3, hash), 0);
  14229. ExpectIntEQ(XMEMCMP(expOut, hash, WC_SHA3_512_DIGEST_SIZE), 0);
  14230. /* Test bad args. */
  14231. ExpectIntEQ(wc_Sha3_512_Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14232. ExpectIntEQ(wc_Sha3_512_Final(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14233. wc_Sha3_512_Free(&sha3);
  14234. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  14235. /* Init stack variables. */
  14236. XMEMSET(hash, 0, sizeof(hash));
  14237. XMEMSET(hashRet, 0, sizeof(hashRet));
  14238. ExpectIntEQ(wc_Sha3_512_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14239. ExpectIntEQ(wc_Sha3_512_GetHash(&sha3, hashRet), 0);
  14240. ExpectIntEQ(wc_Sha3_512_Final(&sha3, hash), 0);
  14241. ExpectIntEQ(XMEMCMP(hash, hashRet, WC_SHA3_512_DIGEST_SIZE), 0);
  14242. /* Test bad args. */
  14243. ExpectIntEQ(wc_Sha3_512_GetHash(NULL, hashRet), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14244. ExpectIntEQ(wc_Sha3_512_GetHash(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14245. wc_Sha3_512_Free(&sha3);
  14246. #endif
  14247. return EXPECT_RESULT();
  14248. } /* END test_wc_Sha3_512_Final */
  14249. /*
  14250. * Testing wc_Sha3_224_Copy()
  14251. */
  14252. static int test_wc_Sha3_224_Copy(void)
  14253. {
  14254. EXPECT_DECLS;
  14255. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_224)
  14256. wc_Sha3 sha3, sha3Cpy;
  14257. const char* msg = TEST_STRING;
  14258. word32 msglen = (word32)TEST_STRING_SZ;
  14259. byte hash[WC_SHA3_224_DIGEST_SIZE];
  14260. byte hashCpy[WC_SHA3_224_DIGEST_SIZE];
  14261. XMEMSET(hash, 0, sizeof(hash));
  14262. XMEMSET(hashCpy, 0, sizeof(hashCpy));
  14263. XMEMSET(&sha3, 0, sizeof(wc_Sha3));
  14264. XMEMSET(&sha3Cpy, 0, sizeof(wc_Sha3));
  14265. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  14266. ExpectIntEQ(wc_InitSha3_224(&sha3Cpy, HEAP_HINT, testDevId), 0);
  14267. ExpectIntEQ(wc_Sha3_224_Update(&sha3, (byte*)msg, msglen), 0);
  14268. ExpectIntEQ(wc_Sha3_224_Copy(&sha3Cpy, &sha3), 0);
  14269. ExpectIntEQ(wc_Sha3_224_Final(&sha3, hash), 0);
  14270. ExpectIntEQ(wc_Sha3_224_Final(&sha3Cpy, hashCpy), 0);
  14271. ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0);
  14272. /* Test bad args. */
  14273. ExpectIntEQ(wc_Sha3_224_Copy(NULL, &sha3), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14274. ExpectIntEQ(wc_Sha3_224_Copy(&sha3Cpy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14275. wc_Sha3_224_Free(&sha3);
  14276. wc_Sha3_224_Free(&sha3Cpy);
  14277. #endif
  14278. return EXPECT_RESULT();
  14279. } /* END test_wc_Sha3_224_Copy */
  14280. /*
  14281. * Testing wc_Sha3_256_Copy()
  14282. */
  14283. static int test_wc_Sha3_256_Copy(void)
  14284. {
  14285. EXPECT_DECLS;
  14286. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  14287. wc_Sha3 sha3, sha3Cpy;
  14288. const char* msg = TEST_STRING;
  14289. word32 msglen = (word32)TEST_STRING_SZ;
  14290. byte hash[WC_SHA3_256_DIGEST_SIZE];
  14291. byte hashCpy[WC_SHA3_256_DIGEST_SIZE];
  14292. XMEMSET(hash, 0, sizeof(hash));
  14293. XMEMSET(hashCpy, 0, sizeof(hashCpy));
  14294. XMEMSET(&sha3, 0, sizeof(wc_Sha3));
  14295. XMEMSET(&sha3Cpy, 0, sizeof(wc_Sha3));
  14296. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  14297. ExpectIntEQ(wc_InitSha3_256(&sha3Cpy, HEAP_HINT, testDevId), 0);
  14298. ExpectIntEQ(wc_Sha3_256_Update(&sha3, (byte*)msg, msglen), 0);
  14299. ExpectIntEQ(wc_Sha3_256_Copy(&sha3Cpy, &sha3), 0);
  14300. ExpectIntEQ(wc_Sha3_256_Final(&sha3, hash), 0);
  14301. ExpectIntEQ(wc_Sha3_256_Final(&sha3Cpy, hashCpy), 0);
  14302. ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0);
  14303. /* Test bad args. */
  14304. ExpectIntEQ(wc_Sha3_256_Copy(NULL, &sha3), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14305. ExpectIntEQ(wc_Sha3_256_Copy(&sha3Cpy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14306. wc_Sha3_256_Free(&sha3);
  14307. wc_Sha3_256_Free(&sha3Cpy);
  14308. #endif
  14309. return EXPECT_RESULT();
  14310. } /* END test_wc_Sha3_256_Copy */
  14311. /*
  14312. * Testing wc_Sha3_384_Copy()
  14313. */
  14314. static int test_wc_Sha3_384_Copy(void)
  14315. {
  14316. EXPECT_DECLS;
  14317. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_384)
  14318. wc_Sha3 sha3, sha3Cpy;
  14319. const char* msg = TEST_STRING;
  14320. word32 msglen = (word32)TEST_STRING_SZ;
  14321. byte hash[WC_SHA3_384_DIGEST_SIZE];
  14322. byte hashCpy[WC_SHA3_384_DIGEST_SIZE];
  14323. XMEMSET(hash, 0, sizeof(hash));
  14324. XMEMSET(hashCpy, 0, sizeof(hashCpy));
  14325. XMEMSET(&sha3, 0, sizeof(wc_Sha3));
  14326. XMEMSET(&sha3Cpy, 0, sizeof(wc_Sha3));
  14327. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  14328. ExpectIntEQ(wc_InitSha3_384(&sha3Cpy, HEAP_HINT, testDevId), 0);
  14329. ExpectIntEQ(wc_Sha3_384_Update(&sha3, (byte*)msg, msglen), 0);
  14330. ExpectIntEQ(wc_Sha3_384_Copy(&sha3Cpy, &sha3), 0);
  14331. ExpectIntEQ(wc_Sha3_384_Final(&sha3, hash), 0);
  14332. ExpectIntEQ(wc_Sha3_384_Final(&sha3Cpy, hashCpy), 0);
  14333. ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0);
  14334. /* Test bad args. */
  14335. ExpectIntEQ(wc_Sha3_384_Copy(NULL, &sha3), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14336. ExpectIntEQ(wc_Sha3_384_Copy(&sha3Cpy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14337. wc_Sha3_384_Free(&sha3);
  14338. wc_Sha3_384_Free(&sha3Cpy);
  14339. #endif
  14340. return EXPECT_RESULT();
  14341. } /* END test_wc_Sha3_384_Copy */
  14342. /*
  14343. * Testing wc_Sha3_512_Copy()
  14344. */
  14345. static int test_wc_Sha3_512_Copy(void)
  14346. {
  14347. EXPECT_DECLS;
  14348. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_512)
  14349. wc_Sha3 sha3, sha3Cpy;
  14350. const char* msg = TEST_STRING;
  14351. word32 msglen = (word32)TEST_STRING_SZ;
  14352. byte hash[WC_SHA3_512_DIGEST_SIZE];
  14353. byte hashCpy[WC_SHA3_512_DIGEST_SIZE];
  14354. XMEMSET(hash, 0, sizeof(hash));
  14355. XMEMSET(hashCpy, 0, sizeof(hashCpy));
  14356. XMEMSET(&sha3, 0, sizeof(wc_Sha3));
  14357. XMEMSET(&sha3Cpy, 0, sizeof(wc_Sha3));
  14358. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  14359. ExpectIntEQ(wc_InitSha3_512(&sha3Cpy, HEAP_HINT, testDevId), 0);
  14360. ExpectIntEQ(wc_Sha3_512_Update(&sha3, (byte*)msg, msglen), 0);
  14361. ExpectIntEQ(wc_Sha3_512_Copy(&sha3Cpy, &sha3), 0);
  14362. ExpectIntEQ(wc_Sha3_512_Final(&sha3, hash), 0);
  14363. ExpectIntEQ(wc_Sha3_512_Final(&sha3Cpy, hashCpy), 0);
  14364. ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0);
  14365. /* Test bad args. */
  14366. ExpectIntEQ(wc_Sha3_512_Copy(NULL, &sha3), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14367. ExpectIntEQ(wc_Sha3_512_Copy(&sha3Cpy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14368. wc_Sha3_512_Free(&sha3);
  14369. wc_Sha3_512_Free(&sha3Cpy);
  14370. #endif
  14371. return EXPECT_RESULT();
  14372. } /* END test_wc_Sha3_512_Copy */
  14373. /*
  14374. * Unit test function for wc_Sha3_GetFlags()
  14375. */
  14376. static int test_wc_Sha3_GetFlags(void)
  14377. {
  14378. EXPECT_DECLS;
  14379. #if defined(WOLFSSL_SHA3) && defined(WOLFSSL_HASH_FLAGS)
  14380. wc_Sha3 sha3;
  14381. word32 flags = 0;
  14382. /* Initialize */
  14383. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  14384. ExpectIntEQ(wc_Sha3_GetFlags(&sha3, &flags), 0);
  14385. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  14386. wc_Sha3_224_Free(&sha3);
  14387. #endif
  14388. return EXPECT_RESULT();
  14389. } /* END test_wc_Sha3_GetFlags */
  14390. static int test_wc_InitShake256(void)
  14391. {
  14392. EXPECT_DECLS;
  14393. #ifdef WOLFSSL_SHAKE256
  14394. wc_Shake shake;
  14395. ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0);
  14396. /* Test bad args. */
  14397. ExpectIntEQ(wc_InitShake256(NULL, HEAP_HINT, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14398. wc_Shake256_Free(&shake);
  14399. #endif
  14400. return EXPECT_RESULT();
  14401. }
  14402. static int testing_wc_Shake256_Update(void)
  14403. {
  14404. EXPECT_DECLS;
  14405. #ifdef WOLFSSL_SHAKE256
  14406. wc_Shake shake;
  14407. byte msg[] = "Everybody's working for the weekend.";
  14408. byte msg2[] = "Everybody gets Friday off.";
  14409. byte msgCmp[] = "\x45\x76\x65\x72\x79\x62\x6f\x64\x79\x27\x73\x20"
  14410. "\x77\x6f\x72\x6b\x69\x6e\x67\x20\x66\x6f\x72\x20\x74"
  14411. "\x68\x65\x20\x77\x65\x65\x6b\x65\x6e\x64\x2e\x45\x76"
  14412. "\x65\x72\x79\x62\x6f\x64\x79\x20\x67\x65\x74\x73\x20"
  14413. "\x46\x72\x69\x64\x61\x79\x20\x6f\x66\x66\x2e";
  14414. word32 msglen = sizeof(msg) - 1;
  14415. word32 msg2len = sizeof(msg2);
  14416. word32 msgCmplen = sizeof(msgCmp);
  14417. ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0);
  14418. ExpectIntEQ(wc_Shake256_Update(&shake, msg, msglen), 0);
  14419. ExpectIntEQ(XMEMCMP(msg, shake.t, msglen), 0);
  14420. ExpectTrue(shake.i == msglen);
  14421. ExpectIntEQ(wc_Shake256_Update(&shake, msg2, msg2len), 0);
  14422. ExpectIntEQ(XMEMCMP(shake.t, msgCmp, msgCmplen), 0);
  14423. /* Pass bad args. */
  14424. ExpectIntEQ(wc_Shake256_Update(NULL, msg2, msg2len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14425. ExpectIntEQ(wc_Shake256_Update(&shake, NULL, 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14426. wc_Shake256_Free(&shake);
  14427. ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0);
  14428. ExpectIntEQ(wc_Shake256_Update(&shake, NULL, 0), 0);
  14429. ExpectIntEQ(wc_Shake256_Update(&shake, msg2, msg2len), 0);
  14430. ExpectIntEQ(XMEMCMP(msg2, shake.t, msg2len), 0);
  14431. wc_Shake256_Free(&shake);
  14432. #endif /* WOLFSSL_SHAKE256 */
  14433. return EXPECT_RESULT();
  14434. }
  14435. static int test_wc_Shake256_Final(void)
  14436. {
  14437. EXPECT_DECLS;
  14438. #ifdef WOLFSSL_SHAKE256
  14439. wc_Shake shake;
  14440. const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
  14441. "nopnopq";
  14442. const char* expOut = "\x4d\x8c\x2d\xd2\x43\x5a\x01\x28\xee\xfb\xb8\xc3\x6f"
  14443. "\x6f\x87\x13\x3a\x79\x11\xe1\x8d\x97\x9e\xe1\xae\x6b"
  14444. "\xe5\xd4\xfd\x2e\x33\x29\x40\xd8\x68\x8a\x4e\x6a\x59"
  14445. "\xaa\x80\x60\xf1\xf9\xbc\x99\x6c\x05\xac\xa3\xc6\x96"
  14446. "\xa8\xb6\x62\x79\xdc\x67\x2c\x74\x0b\xb2\x24\xec\x37"
  14447. "\xa9\x2b\x65\xdb\x05\x39\xc0\x20\x34\x55\xf5\x1d\x97"
  14448. "\xcc\xe4\xcf\xc4\x91\x27\xd7\x26\x0a\xfc\x67\x3a\xf2"
  14449. "\x08\xba\xf1\x9b\xe2\x12\x33\xf3\xde\xbe\x78\xd0\x67"
  14450. "\x60\xcf\xa5\x51\xee\x1e\x07\x91\x41\xd4";
  14451. byte hash[114];
  14452. /* Init stack variables. */
  14453. XMEMSET(hash, 0, sizeof(hash));
  14454. ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0);
  14455. ExpectIntEQ(wc_Shake256_Update(&shake, (byte*)msg, (word32)XSTRLEN(msg)),
  14456. 0);
  14457. ExpectIntEQ(wc_Shake256_Final(&shake, hash, (word32)sizeof(hash)), 0);
  14458. ExpectIntEQ(XMEMCMP(expOut, hash, (word32)sizeof(hash)), 0);
  14459. /* Test bad args. */
  14460. ExpectIntEQ(wc_Shake256_Final(NULL, hash, (word32)sizeof(hash)),
  14461. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14462. ExpectIntEQ(wc_Shake256_Final(&shake, NULL, (word32)sizeof(hash)),
  14463. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14464. wc_Shake256_Free(&shake);
  14465. #endif
  14466. return EXPECT_RESULT();
  14467. }
  14468. /*
  14469. * Testing wc_Shake256_Copy()
  14470. */
  14471. static int test_wc_Shake256_Copy(void)
  14472. {
  14473. EXPECT_DECLS;
  14474. #ifdef WOLFSSL_SHAKE256
  14475. wc_Shake shake, shakeCpy;
  14476. const char* msg = TEST_STRING;
  14477. word32 msglen = (word32)TEST_STRING_SZ;
  14478. byte hash[144];
  14479. byte hashCpy[144];
  14480. word32 hashLen = sizeof(hash);
  14481. word32 hashLenCpy = sizeof(hashCpy);
  14482. XMEMSET(hash, 0, sizeof(hash));
  14483. XMEMSET(hashCpy, 0, sizeof(hashCpy));
  14484. ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0);
  14485. ExpectIntEQ(wc_InitShake256(&shakeCpy, HEAP_HINT, testDevId), 0);
  14486. ExpectIntEQ(wc_Shake256_Update(&shake, (byte*)msg, msglen), 0);
  14487. ExpectIntEQ(wc_Shake256_Copy(&shakeCpy, &shake), 0);
  14488. ExpectIntEQ(wc_Shake256_Final(&shake, hash, hashLen), 0);
  14489. ExpectIntEQ(wc_Shake256_Final(&shakeCpy, hashCpy, hashLenCpy), 0);
  14490. ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0);
  14491. /* Test bad args. */
  14492. ExpectIntEQ(wc_Shake256_Copy(NULL, &shake), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14493. ExpectIntEQ(wc_Shake256_Copy(&shakeCpy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14494. wc_Shake256_Free(&shake);
  14495. wc_Shake256_Free(&shakeCpy);
  14496. #endif
  14497. return EXPECT_RESULT();
  14498. } /* END test_wc_Shake256_Copy */
  14499. /*
  14500. * Unit test function for wc_Shake256Hash()
  14501. */
  14502. static int test_wc_Shake256Hash(void)
  14503. {
  14504. EXPECT_DECLS;
  14505. #ifdef WOLFSSL_SHAKE256
  14506. const byte data[] = { /* Hello World */
  14507. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  14508. 0x72,0x6c,0x64
  14509. };
  14510. word32 len = sizeof(data);
  14511. byte hash[144];
  14512. word32 hashLen = sizeof(hash);
  14513. ExpectIntEQ(wc_Shake256Hash(data, len, hash, hashLen), 0);
  14514. #endif
  14515. return EXPECT_RESULT();
  14516. } /* END test_wc_Shake256Hash */
  14517. /*
  14518. * Testing wc_InitSm3(), wc_Sm3Free()
  14519. */
  14520. static int test_wc_InitSm3Free(void)
  14521. {
  14522. EXPECT_DECLS;
  14523. #ifdef WOLFSSL_SM3
  14524. wc_Sm3 sm3;
  14525. /* Invalid Parameters */
  14526. ExpectIntEQ(wc_InitSm3(NULL, NULL, INVALID_DEVID), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14527. /* Valid Parameters */
  14528. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14529. wc_Sm3Free(NULL);
  14530. wc_Sm3Free(&sm3);
  14531. #endif
  14532. return EXPECT_RESULT();
  14533. } /* END test_wc_InitSm3 */
  14534. /*
  14535. * Testing wc_Sm3Update(), wc_Sm3Final()
  14536. */
  14537. static int test_wc_Sm3UpdateFinal(void)
  14538. {
  14539. EXPECT_DECLS;
  14540. #ifdef WOLFSSL_SM3
  14541. wc_Sm3 sm3;
  14542. byte data[WC_SM3_BLOCK_SIZE * 4];
  14543. byte hash[WC_SM3_DIGEST_SIZE];
  14544. byte calcHash[WC_SM3_DIGEST_SIZE];
  14545. byte expHash[WC_SM3_DIGEST_SIZE] = {
  14546. 0x38, 0x48, 0x15, 0xa7, 0x0e, 0xae, 0x0b, 0x27,
  14547. 0x5c, 0xde, 0x9d, 0xa5, 0xd1, 0xa4, 0x30, 0xa1,
  14548. 0xca, 0xd4, 0x54, 0x58, 0x44, 0xa2, 0x96, 0x1b,
  14549. 0xd7, 0x14, 0x80, 0x3f, 0x80, 0x1a, 0x07, 0xb6
  14550. };
  14551. word32 chunk;
  14552. word32 i;
  14553. XMEMSET(data, 0, sizeof(data));
  14554. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14555. /* Invalid Parameters */
  14556. ExpectIntEQ(wc_Sm3Update(NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14557. ExpectIntEQ(wc_Sm3Update(&sm3, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14558. ExpectIntEQ(wc_Sm3Update(NULL, data, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14559. /* Valid Parameters */
  14560. ExpectIntEQ(wc_Sm3Update(&sm3, NULL, 0), 0);
  14561. ExpectIntEQ(wc_Sm3Update(&sm3, data, 1), 0);
  14562. ExpectIntEQ(wc_Sm3Update(&sm3, data, 1), 0);
  14563. ExpectIntEQ(wc_Sm3Update(&sm3, data, WC_SM3_BLOCK_SIZE), 0);
  14564. ExpectIntEQ(wc_Sm3Update(&sm3, data, WC_SM3_BLOCK_SIZE - 2), 0);
  14565. ExpectIntEQ(wc_Sm3Update(&sm3, data, WC_SM3_BLOCK_SIZE * 2), 0);
  14566. /* Ensure too many bytes for lengths. */
  14567. ExpectIntEQ(wc_Sm3Update(&sm3, data, WC_SM3_PAD_SIZE), 0);
  14568. /* Invalid Parameters */
  14569. ExpectIntEQ(wc_Sm3Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14570. ExpectIntEQ(wc_Sm3Final(&sm3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14571. ExpectIntEQ(wc_Sm3Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14572. /* Valid Parameters */
  14573. ExpectIntEQ(wc_Sm3Final(&sm3, hash), 0);
  14574. ExpectBufEQ(hash, expHash, WC_SM3_DIGEST_SIZE);
  14575. /* Chunk tests. */
  14576. ExpectIntEQ(wc_Sm3Update(&sm3, data, sizeof(data)), 0);
  14577. ExpectIntEQ(wc_Sm3Final(&sm3, calcHash), 0);
  14578. for (chunk = 1; chunk <= WC_SM3_BLOCK_SIZE + 1; chunk++) {
  14579. for (i = 0; i + chunk <= (word32)sizeof(data); i += chunk) {
  14580. ExpectIntEQ(wc_Sm3Update(&sm3, data + i, chunk), 0);
  14581. }
  14582. if (i < (word32)sizeof(data)) {
  14583. ExpectIntEQ(wc_Sm3Update(&sm3, data + i, (word32)sizeof(data) - i),
  14584. 0);
  14585. }
  14586. ExpectIntEQ(wc_Sm3Final(&sm3, hash), 0);
  14587. ExpectBufEQ(hash, calcHash, WC_SM3_DIGEST_SIZE);
  14588. }
  14589. /* Not testing when the low 32-bit length overflows. */
  14590. wc_Sm3Free(&sm3);
  14591. #endif
  14592. return EXPECT_RESULT();
  14593. } /* END test_wc_Sm3Update */
  14594. /*
  14595. * Testing wc_Sm3GetHash()
  14596. */
  14597. static int test_wc_Sm3GetHash(void)
  14598. {
  14599. EXPECT_DECLS;
  14600. #ifdef WOLFSSL_SM3
  14601. wc_Sm3 sm3;
  14602. byte hash[WC_SM3_DIGEST_SIZE];
  14603. byte calcHash[WC_SM3_DIGEST_SIZE];
  14604. byte data[WC_SM3_BLOCK_SIZE];
  14605. XMEMSET(data, 0, sizeof(data));
  14606. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14607. ExpectIntEQ(wc_Sm3Final(&sm3, calcHash), 0);
  14608. /* Invalid Parameters */
  14609. ExpectIntEQ(wc_Sm3GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14610. ExpectIntEQ(wc_Sm3GetHash(&sm3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14611. ExpectIntEQ(wc_Sm3GetHash(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14612. /* Valid Parameters */
  14613. ExpectIntEQ(wc_Sm3GetHash(&sm3, hash), 0);
  14614. ExpectBufEQ(hash, calcHash, WC_SM3_DIGEST_SIZE);
  14615. /* With update. */
  14616. ExpectIntEQ(wc_Sm3Update(&sm3, data, sizeof(data)), 0);
  14617. ExpectIntEQ(wc_Sm3GetHash(&sm3, hash), 0);
  14618. ExpectIntEQ(wc_Sm3Final(&sm3, calcHash), 0);
  14619. ExpectBufEQ(hash, calcHash, WC_SM3_DIGEST_SIZE);
  14620. wc_Sm3Free(&sm3);
  14621. #endif
  14622. return EXPECT_RESULT();
  14623. } /* END test_wc_Sm3Update */
  14624. /*
  14625. * Testing wc_Sm3Copy()
  14626. */
  14627. static int test_wc_Sm3Copy(void)
  14628. {
  14629. EXPECT_DECLS;
  14630. #if defined(WOLFSSL_SM3) && defined(WOLFSSL_HASH_FLAGS)
  14631. wc_Sm3 sm3;
  14632. wc_Sm3 sm3Copy;
  14633. byte hash[WC_SM3_DIGEST_SIZE];
  14634. byte hashCopy[WC_SM3_DIGEST_SIZE];
  14635. byte data[WC_SM3_BLOCK_SIZE + 1];
  14636. int i;
  14637. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14638. ExpectIntEQ(wc_InitSm3(&sm3Copy, NULL, INVALID_DEVID), 0);
  14639. /* Invalid Parameters */
  14640. ExpectIntEQ(wc_Sm3Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14641. ExpectIntEQ(wc_Sm3Copy(&sm3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14642. ExpectIntEQ(wc_Sm3Copy(NULL, &sm3Copy), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14643. /* Valid Parameters */
  14644. ExpectIntEQ(wc_Sm3Copy(&sm3, &sm3Copy), 0);
  14645. /* Ensure all parts of data updated during hashing are copied. */
  14646. for (i = 0; i < WC_SM3_BLOCK_SIZE + 1; i++) {
  14647. ExpectIntEQ(wc_Sm3Update(&sm3, data, i), 0);
  14648. ExpectIntEQ(wc_Sm3Copy(&sm3, &sm3Copy), 0);
  14649. ExpectIntEQ(wc_Sm3Update(&sm3, data, 1), 0);
  14650. ExpectIntEQ(wc_Sm3Update(&sm3Copy, data, 1), 0);
  14651. ExpectIntEQ(wc_Sm3Final(&sm3, hash), 0);
  14652. ExpectIntEQ(wc_Sm3Final(&sm3Copy, hashCopy), 0);
  14653. ExpectBufEQ(hash, hashCopy, WC_SM3_DIGEST_SIZE);
  14654. }
  14655. wc_Sm3Free(&sm3Copy);
  14656. wc_Sm3Free(&sm3);
  14657. #endif
  14658. return EXPECT_RESULT();
  14659. } /* END test_wc_Sm3Copy */
  14660. /*
  14661. * Testing wc_Sm3FinalRaw()
  14662. */
  14663. static int test_wc_Sm3FinalRaw(void)
  14664. {
  14665. EXPECT_DECLS;
  14666. #if defined(WOLFSSL_SM3) && !defined(HAVE_SELFTEST) && \
  14667. !defined(WOLFSSL_DEVCRYPTO) && (!defined(HAVE_FIPS) || \
  14668. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3))) && \
  14669. !defined(WOLFSSL_NO_HASH_RAW)
  14670. wc_Sm3 sm3;
  14671. byte hash1[WC_SM3_DIGEST_SIZE];
  14672. byte hash2[WC_SM3_DIGEST_SIZE];
  14673. byte hash3[WC_SM3_DIGEST_SIZE];
  14674. byte* hash_test[3] = { hash1, hash2, hash3 };
  14675. int times;
  14676. int i;
  14677. XMEMSET(&sm3, 0, sizeof(sm3));
  14678. /* Initialize */
  14679. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14680. /* Invalid Parameters */
  14681. ExpectIntEQ(wc_Sm3FinalRaw(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14682. ExpectIntEQ(wc_Sm3FinalRaw(&sm3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14683. ExpectIntEQ(wc_Sm3FinalRaw(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14684. times = sizeof(hash_test) / sizeof(byte*);
  14685. for (i = 0; i < times; i++) {
  14686. ExpectIntEQ(wc_Sm3FinalRaw(&sm3, hash_test[i]), 0);
  14687. }
  14688. wc_Sm3Free(&sm3);
  14689. #endif
  14690. return EXPECT_RESULT();
  14691. } /* END test_wc_Sm3FinalRaw */
  14692. /*
  14693. * Testing wc_Sm3GetFlags, wc_Sm3SetFlags()
  14694. */
  14695. static int test_wc_Sm3GetSetFlags(void)
  14696. {
  14697. EXPECT_DECLS;
  14698. #if defined(WOLFSSL_SM3) && defined(WOLFSSL_HASH_FLAGS)
  14699. wc_Sm3 sm3;
  14700. wc_Sm3 sm3Copy;
  14701. word32 flags = 0;
  14702. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14703. ExpectIntEQ(wc_InitSm3(&sm3Copy, NULL, INVALID_DEVID), 0);
  14704. ExpectIntEQ(wc_Sm3GetFlags(NULL, &flags), 0);
  14705. ExpectIntEQ(flags, 0);
  14706. ExpectIntEQ(wc_Sm3SetFlags(NULL, WC_HASH_FLAG_WILLCOPY), 0);
  14707. ExpectIntEQ(wc_Sm3GetFlags(NULL, &flags), 0);
  14708. ExpectIntEQ(flags, 0);
  14709. ExpectIntEQ(wc_Sm3GetFlags(&sm3, &flags), 0);
  14710. ExpectIntEQ(flags, 0);
  14711. ExpectIntEQ(wc_Sm3SetFlags(&sm3, WC_HASH_FLAG_WILLCOPY), 0);
  14712. ExpectIntEQ(wc_Sm3GetFlags(&sm3, &flags), 0);
  14713. ExpectIntEQ(flags, WC_HASH_FLAG_WILLCOPY);
  14714. ExpectIntEQ(wc_Sm3Copy(&sm3, &sm3Copy), 0);
  14715. ExpectIntEQ(wc_Sm3GetFlags(&sm3Copy, &flags), 0);
  14716. ExpectIntEQ(flags, WC_HASH_FLAG_ISCOPY | WC_HASH_FLAG_WILLCOPY);
  14717. wc_Sm3Free(&sm3Copy);
  14718. wc_Sm3Free(&sm3);
  14719. #endif
  14720. return EXPECT_RESULT();
  14721. } /* END test_wc_Sm3Update */
  14722. /*
  14723. * Testing wc_Sm3Hash()
  14724. */
  14725. static int test_wc_Sm3Hash(void)
  14726. {
  14727. EXPECT_DECLS;
  14728. #if defined(WOLFSSL_SM3) && defined(WOLFSSL_HASH_FLAGS)
  14729. byte data[WC_SM3_BLOCK_SIZE];
  14730. byte hash[WC_SM3_DIGEST_SIZE];
  14731. /* Invalid parameters. */
  14732. ExpectIntEQ(wc_Sm3Hash(NULL, sizeof(data), hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14733. ExpectIntEQ(wc_Sm3Hash(data, sizeof(data), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14734. /* Valid parameters. */
  14735. ExpectIntEQ(wc_Sm3Hash(data, sizeof(data), hash), 0);
  14736. #endif
  14737. return EXPECT_RESULT();
  14738. } /* END test_wc_Sm3Hash */
  14739. /*
  14740. * Test function for wc_HmacSetKey
  14741. */
  14742. static int test_wc_Md5HmacSetKey(void)
  14743. {
  14744. EXPECT_DECLS;
  14745. #if !defined(NO_HMAC) && !defined(NO_MD5)
  14746. Hmac hmac;
  14747. int ret, times, itr;
  14748. const char* keys[]=
  14749. {
  14750. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
  14751. #ifndef HAVE_FIPS
  14752. "Jefe", /* smaller than minimum FIPS key size */
  14753. #endif
  14754. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  14755. };
  14756. times = sizeof(keys) / sizeof(char*);
  14757. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14758. for (itr = 0; itr < times; itr++) {
  14759. ret = wc_HmacSetKey(&hmac, WC_MD5, (byte*)keys[itr],
  14760. (word32)XSTRLEN(keys[itr]));
  14761. #if defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 5)
  14762. wc_HmacFree(&hmac);
  14763. ExpectIntEQ(ret, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14764. #else
  14765. ExpectIntEQ(ret, 0);
  14766. #endif
  14767. }
  14768. /* Bad args. */
  14769. ExpectIntEQ(wc_HmacSetKey(NULL, WC_MD5, (byte*)keys[0],
  14770. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14771. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_MD5, NULL, (word32)XSTRLEN(keys[0])),
  14772. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14773. ExpectIntEQ(wc_HmacSetKey(&hmac, 21, (byte*)keys[0],
  14774. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14775. ret = wc_HmacSetKey(&hmac, WC_MD5, (byte*)keys[0], 0);
  14776. #if defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 5)
  14777. ExpectIntEQ(ret, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14778. #elif defined(HAVE_FIPS)
  14779. ExpectIntEQ(ret, WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E));
  14780. #else
  14781. ExpectIntEQ(ret, 0);
  14782. #endif
  14783. wc_HmacFree(&hmac);
  14784. #endif
  14785. return EXPECT_RESULT();
  14786. } /* END test_wc_Md5HmacSetKey */
  14787. /*
  14788. * testing wc_HmacSetKey() on wc_Sha hash.
  14789. */
  14790. static int test_wc_ShaHmacSetKey(void)
  14791. {
  14792. EXPECT_DECLS;
  14793. #if !defined(NO_HMAC) && !defined(NO_SHA)
  14794. Hmac hmac;
  14795. int ret, times, itr;
  14796. const char* keys[]=
  14797. {
  14798. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  14799. "\x0b\x0b\x0b",
  14800. #ifndef HAVE_FIPS
  14801. "Jefe", /* smaller than minimum FIPS key size */
  14802. #endif
  14803. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  14804. "\xAA\xAA\xAA"
  14805. };
  14806. times = sizeof(keys) / sizeof(char*);
  14807. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14808. for (itr = 0; itr < times; itr++) {
  14809. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA, (byte*)keys[itr],
  14810. (word32)XSTRLEN(keys[itr])), 0);
  14811. }
  14812. /* Bad args. */
  14813. ExpectIntEQ(wc_HmacSetKey(NULL, WC_SHA, (byte*)keys[0],
  14814. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14815. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA, NULL, (word32)XSTRLEN(keys[0])),
  14816. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14817. ExpectIntEQ(wc_HmacSetKey(&hmac, 21, (byte*)keys[0],
  14818. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14819. ret = wc_HmacSetKey(&hmac, WC_SHA, (byte*)keys[0], 0);
  14820. #ifdef HAVE_FIPS
  14821. ExpectIntEQ(ret, WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E));
  14822. #else
  14823. ExpectIntEQ(ret, 0);
  14824. #endif
  14825. wc_HmacFree(&hmac);
  14826. #endif
  14827. return EXPECT_RESULT();
  14828. } /* END test_wc_ShaHmacSetKey() */
  14829. /*
  14830. * testing wc_HmacSetKey() on Sha224 hash.
  14831. */
  14832. static int test_wc_Sha224HmacSetKey(void)
  14833. {
  14834. EXPECT_DECLS;
  14835. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA224)
  14836. Hmac hmac;
  14837. int ret, times, itr;
  14838. const char* keys[]=
  14839. {
  14840. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  14841. "\x0b\x0b\x0b",
  14842. #ifndef HAVE_FIPS
  14843. "Jefe", /* smaller than minimum FIPS key size */
  14844. #endif
  14845. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  14846. "\xAA\xAA\xAA"
  14847. };
  14848. times = sizeof(keys) / sizeof(char*);
  14849. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14850. for (itr = 0; itr < times; itr++) {
  14851. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA224, (byte*)keys[itr],
  14852. (word32)XSTRLEN(keys[itr])), 0);
  14853. }
  14854. /* Bad args. */
  14855. ExpectIntEQ(wc_HmacSetKey(NULL, WC_SHA224, (byte*)keys[0],
  14856. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14857. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA224, NULL, (word32)XSTRLEN(keys[0])),
  14858. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14859. ExpectIntEQ(wc_HmacSetKey(&hmac, 21, (byte*)keys[0],
  14860. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14861. ret = wc_HmacSetKey(&hmac, WC_SHA224, (byte*)keys[0], 0);
  14862. #ifdef HAVE_FIPS
  14863. ExpectIntEQ(ret, WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E));
  14864. #else
  14865. ExpectIntEQ(ret, 0);
  14866. #endif
  14867. wc_HmacFree(&hmac);
  14868. #endif
  14869. return EXPECT_RESULT();
  14870. } /* END test_wc_Sha224HmacSetKey() */
  14871. /*
  14872. * testing wc_HmacSetKey() on Sha256 hash
  14873. */
  14874. static int test_wc_Sha256HmacSetKey(void)
  14875. {
  14876. EXPECT_DECLS;
  14877. #if !defined(NO_HMAC) && !defined(NO_SHA256)
  14878. Hmac hmac;
  14879. int ret, times, itr;
  14880. const char* keys[]=
  14881. {
  14882. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  14883. "\x0b\x0b\x0b",
  14884. #ifndef HAVE_FIPS
  14885. "Jefe", /* smaller than minimum FIPS key size */
  14886. #endif
  14887. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  14888. "\xAA\xAA\xAA"
  14889. };
  14890. times = sizeof(keys) / sizeof(char*);
  14891. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14892. for (itr = 0; itr < times; itr++) {
  14893. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA256, (byte*)keys[itr],
  14894. (word32)XSTRLEN(keys[itr])), 0);
  14895. }
  14896. /* Bad args. */
  14897. ExpectIntEQ(wc_HmacSetKey(NULL, WC_SHA256, (byte*)keys[0],
  14898. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14899. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA256, NULL, (word32)XSTRLEN(keys[0])),
  14900. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14901. ExpectIntEQ(wc_HmacSetKey(&hmac, 21, (byte*)keys[0],
  14902. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14903. ret = wc_HmacSetKey(&hmac, WC_SHA256, (byte*)keys[0], 0);
  14904. #ifdef HAVE_FIPS
  14905. ExpectIntEQ(ret, WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E));
  14906. #else
  14907. ExpectIntEQ(ret, 0);
  14908. #endif
  14909. wc_HmacFree(&hmac);
  14910. #endif
  14911. return EXPECT_RESULT();
  14912. } /* END test_wc_Sha256HmacSetKey() */
  14913. /*
  14914. * testing wc_HmacSetKey on Sha384 hash.
  14915. */
  14916. static int test_wc_Sha384HmacSetKey(void)
  14917. {
  14918. EXPECT_DECLS;
  14919. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  14920. Hmac hmac;
  14921. int ret, times, itr;
  14922. const char* keys[]=
  14923. {
  14924. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  14925. "\x0b\x0b\x0b",
  14926. #ifndef HAVE_FIPS
  14927. "Jefe", /* smaller than minimum FIPS key size */
  14928. #endif
  14929. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  14930. "\xAA\xAA\xAA"
  14931. };
  14932. times = sizeof(keys) / sizeof(char*);
  14933. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14934. for (itr = 0; itr < times; itr++) {
  14935. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA384, (byte*)keys[itr],
  14936. (word32)XSTRLEN(keys[itr])), 0);
  14937. }
  14938. /* Bad args. */
  14939. ExpectIntEQ(wc_HmacSetKey(NULL, WC_SHA384, (byte*)keys[0],
  14940. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14941. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA384, NULL, (word32)XSTRLEN(keys[0])),
  14942. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14943. ExpectIntEQ(wc_HmacSetKey(&hmac, 21, (byte*)keys[0],
  14944. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14945. ret = wc_HmacSetKey(&hmac, WC_SHA384, (byte*)keys[0], 0);
  14946. #ifdef HAVE_FIPS
  14947. ExpectIntEQ(ret, WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E));
  14948. #else
  14949. ExpectIntEQ(ret, 0);
  14950. #endif
  14951. wc_HmacFree(&hmac);
  14952. #endif
  14953. return EXPECT_RESULT();
  14954. } /* END test_wc_Sha384HmacSetKey() */
  14955. /*
  14956. * testing wc_HmacUpdate on wc_Md5 hash.
  14957. */
  14958. static int test_wc_Md5HmacUpdate(void)
  14959. {
  14960. EXPECT_DECLS;
  14961. #if !defined(NO_HMAC) && !defined(NO_MD5) && !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 5))
  14962. Hmac hmac;
  14963. testVector a, b;
  14964. #ifdef HAVE_FIPS
  14965. const char* keys =
  14966. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  14967. #else
  14968. const char* keys = "Jefe";
  14969. #endif
  14970. a.input = "what do ya want for nothing?";
  14971. a.inLen = XSTRLEN(a.input);
  14972. b.input = "Hi There";
  14973. b.inLen = XSTRLEN(b.input);
  14974. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14975. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_MD5, (byte*)keys,
  14976. (word32)XSTRLEN(keys)), 0);
  14977. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0);
  14978. /* Update Hmac. */
  14979. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  14980. /* Test bad args. */
  14981. ExpectIntEQ(wc_HmacUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  14982. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14983. ExpectIntEQ(wc_HmacUpdate(&hmac, NULL, (word32)a.inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14984. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, 0), 0);
  14985. wc_HmacFree(&hmac);
  14986. #endif
  14987. return EXPECT_RESULT();
  14988. } /* END test_wc_Md5HmacUpdate */
  14989. /*
  14990. * testing wc_HmacUpdate on SHA hash.
  14991. */
  14992. static int test_wc_ShaHmacUpdate(void)
  14993. {
  14994. EXPECT_DECLS;
  14995. #if !defined(NO_HMAC) && !defined(NO_SHA)
  14996. Hmac hmac;
  14997. testVector a, b;
  14998. #ifdef HAVE_FIPS
  14999. const char* keys =
  15000. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  15001. #else
  15002. const char* keys = "Jefe";
  15003. #endif
  15004. a.input = "what do ya want for nothing?";
  15005. a.inLen = XSTRLEN(a.input);
  15006. b.input = "Hi There";
  15007. b.inLen = XSTRLEN(b.input);
  15008. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15009. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA, (byte*)keys,
  15010. (word32)XSTRLEN(keys)), 0);
  15011. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0);
  15012. /* Update Hmac. */
  15013. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15014. /* Test bad args. */
  15015. ExpectIntEQ(wc_HmacUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  15016. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15017. ExpectIntEQ(wc_HmacUpdate(&hmac, NULL, (word32)a.inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15018. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, 0), 0);
  15019. wc_HmacFree(&hmac);
  15020. #endif
  15021. return EXPECT_RESULT();
  15022. } /* END test_wc_ShaHmacUpdate */
  15023. /*
  15024. * testing wc_HmacUpdate on SHA224 hash.
  15025. */
  15026. static int test_wc_Sha224HmacUpdate(void)
  15027. {
  15028. EXPECT_DECLS;
  15029. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA224)
  15030. Hmac hmac;
  15031. testVector a, b;
  15032. #ifdef HAVE_FIPS
  15033. const char* keys =
  15034. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  15035. #else
  15036. const char* keys = "Jefe";
  15037. #endif
  15038. a.input = "what do ya want for nothing?";
  15039. a.inLen = XSTRLEN(a.input);
  15040. b.input = "Hi There";
  15041. b.inLen = XSTRLEN(b.input);
  15042. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15043. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA224, (byte*)keys,
  15044. (word32)XSTRLEN(keys)), 0);
  15045. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0);
  15046. /* Update Hmac. */
  15047. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15048. /* Test bad args. */
  15049. ExpectIntEQ(wc_HmacUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  15050. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15051. ExpectIntEQ(wc_HmacUpdate(&hmac, NULL, (word32)a.inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15052. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, 0), 0);
  15053. wc_HmacFree(&hmac);
  15054. #endif
  15055. return EXPECT_RESULT();
  15056. } /* END test_wc_Sha224HmacUpdate */
  15057. /*
  15058. * testing wc_HmacUpdate on SHA256 hash.
  15059. */
  15060. static int test_wc_Sha256HmacUpdate(void)
  15061. {
  15062. EXPECT_DECLS;
  15063. #if !defined(NO_HMAC) && !defined(NO_SHA256)
  15064. Hmac hmac;
  15065. testVector a, b;
  15066. #ifdef HAVE_FIPS
  15067. const char* keys =
  15068. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  15069. #else
  15070. const char* keys = "Jefe";
  15071. #endif
  15072. a.input = "what do ya want for nothing?";
  15073. a.inLen = XSTRLEN(a.input);
  15074. b.input = "Hi There";
  15075. b.inLen = XSTRLEN(b.input);
  15076. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15077. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA256, (byte*)keys,
  15078. (word32)XSTRLEN(keys)), 0);
  15079. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0);
  15080. /* Update Hmac. */
  15081. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15082. /* Test bad args. */
  15083. ExpectIntEQ(wc_HmacUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  15084. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15085. ExpectIntEQ(wc_HmacUpdate(&hmac, NULL, (word32)a.inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15086. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, 0), 0);
  15087. wc_HmacFree(&hmac);
  15088. #endif
  15089. return EXPECT_RESULT();
  15090. } /* END test_wc_Sha256HmacUpdate */
  15091. /*
  15092. * testing wc_HmacUpdate on SHA384 hash.
  15093. */
  15094. static int test_wc_Sha384HmacUpdate(void)
  15095. {
  15096. EXPECT_DECLS;
  15097. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  15098. Hmac hmac;
  15099. testVector a, b;
  15100. #ifdef HAVE_FIPS
  15101. const char* keys =
  15102. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  15103. #else
  15104. const char* keys = "Jefe";
  15105. #endif
  15106. a.input = "what do ya want for nothing?";
  15107. a.inLen = XSTRLEN(a.input);
  15108. b.input = "Hi There";
  15109. b.inLen = XSTRLEN(b.input);
  15110. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15111. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA384, (byte*)keys,
  15112. (word32)XSTRLEN(keys)), 0);
  15113. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0);
  15114. /* Update Hmac. */
  15115. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15116. /* Test bad args. */
  15117. ExpectIntEQ(wc_HmacUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  15118. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15119. ExpectIntEQ(wc_HmacUpdate(&hmac, NULL, (word32)a.inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15120. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, 0), 0);
  15121. wc_HmacFree(&hmac);
  15122. #endif
  15123. return EXPECT_RESULT();
  15124. } /* END test_wc_Sha384HmacUpdate */
  15125. /*
  15126. * Testing wc_HmacFinal() with MD5
  15127. */
  15128. static int test_wc_Md5HmacFinal(void)
  15129. {
  15130. EXPECT_DECLS;
  15131. #if !defined(NO_HMAC) && !defined(NO_MD5) && !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 5))
  15132. Hmac hmac;
  15133. byte hash[WC_MD5_DIGEST_SIZE];
  15134. testVector a;
  15135. const char* key;
  15136. key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  15137. a.input = "Hi There";
  15138. a.output = "\x92\x94\x72\x7a\x36\x38\xbb\x1c\x13\xf4\x8e\xf8\x15\x8b\xfc"
  15139. "\x9d";
  15140. a.inLen = XSTRLEN(a.input);
  15141. a.outLen = XSTRLEN(a.output);
  15142. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15143. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_MD5, (byte*)key, (word32)XSTRLEN(key)),
  15144. 0);
  15145. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15146. ExpectIntEQ(wc_HmacFinal(&hmac, hash), 0);
  15147. ExpectIntEQ(XMEMCMP(hash, a.output, WC_MD5_DIGEST_SIZE), 0);
  15148. /* Try bad parameters. */
  15149. ExpectIntEQ(wc_HmacFinal(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15150. #ifndef HAVE_FIPS
  15151. ExpectIntEQ(wc_HmacFinal(&hmac, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15152. #endif
  15153. wc_HmacFree(&hmac);
  15154. #endif
  15155. return EXPECT_RESULT();
  15156. } /* END test_wc_Md5HmacFinal */
  15157. /*
  15158. * Testing wc_HmacFinal() with SHA
  15159. */
  15160. static int test_wc_ShaHmacFinal(void)
  15161. {
  15162. EXPECT_DECLS;
  15163. #if !defined(NO_HMAC) && !defined(NO_SHA)
  15164. Hmac hmac;
  15165. byte hash[WC_SHA_DIGEST_SIZE];
  15166. testVector a;
  15167. const char* key;
  15168. key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  15169. "\x0b\x0b\x0b";
  15170. a.input = "Hi There";
  15171. a.output = "\xb6\x17\x31\x86\x55\x05\x72\x64\xe2\x8b\xc0\xb6\xfb\x37\x8c"
  15172. "\x8e\xf1\x46\xbe\x00";
  15173. a.inLen = XSTRLEN(a.input);
  15174. a.outLen = XSTRLEN(a.output);
  15175. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15176. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA, (byte*)key, (word32)XSTRLEN(key)),
  15177. 0);
  15178. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15179. ExpectIntEQ(wc_HmacFinal(&hmac, hash), 0);
  15180. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA_DIGEST_SIZE), 0);
  15181. /* Try bad parameters. */
  15182. ExpectIntEQ(wc_HmacFinal(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15183. #ifndef HAVE_FIPS
  15184. ExpectIntEQ(wc_HmacFinal(&hmac, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15185. #endif
  15186. wc_HmacFree(&hmac);
  15187. #endif
  15188. return EXPECT_RESULT();
  15189. } /* END test_wc_ShaHmacFinal */
  15190. /*
  15191. * Testing wc_HmacFinal() with SHA224
  15192. */
  15193. static int test_wc_Sha224HmacFinal(void)
  15194. {
  15195. EXPECT_DECLS;
  15196. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA224)
  15197. Hmac hmac;
  15198. byte hash[WC_SHA224_DIGEST_SIZE];
  15199. testVector a;
  15200. const char* key;
  15201. key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  15202. "\x0b\x0b\x0b";
  15203. a.input = "Hi There";
  15204. a.output = "\x89\x6f\xb1\x12\x8a\xbb\xdf\x19\x68\x32\x10\x7c\xd4\x9d\xf3"
  15205. "\x3f\x47\xb4\xb1\x16\x99\x12\xba\x4f\x53\x68\x4b\x22";
  15206. a.inLen = XSTRLEN(a.input);
  15207. a.outLen = XSTRLEN(a.output);
  15208. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15209. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA224, (byte*)key,
  15210. (word32)XSTRLEN(key)), 0);
  15211. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15212. ExpectIntEQ(wc_HmacFinal(&hmac, hash), 0);
  15213. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA224_DIGEST_SIZE), 0);
  15214. /* Try bad parameters. */
  15215. ExpectIntEQ(wc_HmacFinal(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15216. #ifndef HAVE_FIPS
  15217. ExpectIntEQ(wc_HmacFinal(&hmac, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15218. #endif
  15219. wc_HmacFree(&hmac);
  15220. #endif
  15221. return EXPECT_RESULT();
  15222. } /* END test_wc_Sha224HmacFinal */
  15223. /*
  15224. * Testing wc_HmacFinal() with SHA256
  15225. */
  15226. static int test_wc_Sha256HmacFinal(void)
  15227. {
  15228. EXPECT_DECLS;
  15229. #if !defined(NO_HMAC) && !defined(NO_SHA256)
  15230. Hmac hmac;
  15231. byte hash[WC_SHA256_DIGEST_SIZE];
  15232. testVector a;
  15233. const char* key;
  15234. key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  15235. "\x0b\x0b\x0b";
  15236. a.input = "Hi There";
  15237. a.output = "\xb0\x34\x4c\x61\xd8\xdb\x38\x53\x5c\xa8\xaf\xce\xaf\x0b\xf1"
  15238. "\x2b\x88\x1d\xc2\x00\xc9\x83\x3d\xa7\x26\xe9\x37\x6c\x2e\x32"
  15239. "\xcf\xf7";
  15240. a.inLen = XSTRLEN(a.input);
  15241. a.outLen = XSTRLEN(a.output);
  15242. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15243. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA256, (byte*)key,
  15244. (word32)XSTRLEN(key)), 0);
  15245. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15246. ExpectIntEQ(wc_HmacFinal(&hmac, hash), 0);
  15247. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA256_DIGEST_SIZE), 0);
  15248. /* Try bad parameters. */
  15249. ExpectIntEQ(wc_HmacFinal(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15250. #ifndef HAVE_FIPS
  15251. ExpectIntEQ(wc_HmacFinal(&hmac, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15252. #endif
  15253. wc_HmacFree(&hmac);
  15254. #endif
  15255. return EXPECT_RESULT();
  15256. } /* END test_wc_Sha256HmacFinal */
  15257. /*
  15258. * Testing wc_HmacFinal() with SHA384
  15259. */
  15260. static int test_wc_Sha384HmacFinal(void)
  15261. {
  15262. EXPECT_DECLS;
  15263. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  15264. Hmac hmac;
  15265. byte hash[WC_SHA384_DIGEST_SIZE];
  15266. testVector a;
  15267. const char* key;
  15268. key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  15269. "\x0b\x0b\x0b";
  15270. a.input = "Hi There";
  15271. a.output = "\xaf\xd0\x39\x44\xd8\x48\x95\x62\x6b\x08\x25\xf4\xab\x46\x90"
  15272. "\x7f\x15\xf9\xda\xdb\xe4\x10\x1e\xc6\x82\xaa\x03\x4c\x7c\xeb"
  15273. "\xc5\x9c\xfa\xea\x9e\xa9\x07\x6e\xde\x7f\x4a\xf1\x52\xe8\xb2"
  15274. "\xfa\x9c\xb6";
  15275. a.inLen = XSTRLEN(a.input);
  15276. a.outLen = XSTRLEN(a.output);
  15277. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15278. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA384, (byte*)key,
  15279. (word32)XSTRLEN(key)), 0);
  15280. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15281. ExpectIntEQ(wc_HmacFinal(&hmac, hash), 0);
  15282. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA384_DIGEST_SIZE), 0);
  15283. /* Try bad parameters. */
  15284. ExpectIntEQ(wc_HmacFinal(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15285. #ifndef HAVE_FIPS
  15286. ExpectIntEQ(wc_HmacFinal(&hmac, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15287. #endif
  15288. wc_HmacFree(&hmac);
  15289. #endif
  15290. return EXPECT_RESULT();
  15291. } /* END test_wc_Sha384HmacFinal */
  15292. /*
  15293. * Testing wc_InitCmac()
  15294. */
  15295. static int test_wc_InitCmac(void)
  15296. {
  15297. EXPECT_DECLS;
  15298. #if defined(WOLFSSL_CMAC) && !defined(NO_AES)
  15299. Cmac cmac1;
  15300. Cmac cmac2;
  15301. Cmac cmac3;
  15302. /* AES 128 key. */
  15303. byte key1[] = "\x01\x02\x03\x04\x05\x06\x07\x08"
  15304. "\x09\x10\x11\x12\x13\x14\x15\x16";
  15305. /* AES 192 key. */
  15306. byte key2[] = "\x01\x02\x03\x04\x05\x06\x07\x08"
  15307. "\x09\x01\x11\x12\x13\x14\x15\x16"
  15308. "\x01\x02\x03\x04\x05\x06\x07\x08";
  15309. /* AES 256 key. */
  15310. byte key3[] = "\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. "\x09\x01\x11\x12\x13\x14\x15\x16";
  15314. word32 key1Sz = (word32)sizeof(key1) - 1;
  15315. word32 key2Sz = (word32)sizeof(key2) - 1;
  15316. word32 key3Sz = (word32)sizeof(key3) - 1;
  15317. int type = WC_CMAC_AES;
  15318. (void)key1;
  15319. (void)key1Sz;
  15320. (void)key2;
  15321. (void)key2Sz;
  15322. XMEMSET(&cmac1, 0, sizeof(Cmac));
  15323. XMEMSET(&cmac2, 0, sizeof(Cmac));
  15324. XMEMSET(&cmac3, 0, sizeof(Cmac));
  15325. #ifdef WOLFSSL_AES_128
  15326. ExpectIntEQ(wc_InitCmac(&cmac1, key1, key1Sz, type, NULL), 0);
  15327. #endif
  15328. #ifdef WOLFSSL_AES_192
  15329. wc_AesFree(&cmac1.aes);
  15330. ExpectIntEQ(wc_InitCmac(&cmac2, key2, key2Sz, type, NULL), 0);
  15331. #endif
  15332. #ifdef WOLFSSL_AES_256
  15333. wc_AesFree(&cmac2.aes);
  15334. ExpectIntEQ(wc_InitCmac(&cmac3, key3, key3Sz, type, NULL), 0);
  15335. #endif
  15336. wc_AesFree(&cmac3.aes);
  15337. /* Test bad args. */
  15338. ExpectIntEQ(wc_InitCmac(NULL, key3, key3Sz, type, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15339. ExpectIntEQ(wc_InitCmac(&cmac3, NULL, key3Sz, type, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15340. ExpectIntEQ(wc_InitCmac(&cmac3, key3, 0, type, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15341. ExpectIntEQ(wc_InitCmac(&cmac3, key3, key3Sz, 0, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15342. #endif
  15343. return EXPECT_RESULT();
  15344. } /* END test_wc_InitCmac */
  15345. /*
  15346. * Testing wc_CmacUpdate()
  15347. */
  15348. static int test_wc_CmacUpdate(void)
  15349. {
  15350. EXPECT_DECLS;
  15351. #if defined(WOLFSSL_CMAC) && !defined(NO_AES) && defined(WOLFSSL_AES_128)
  15352. Cmac cmac;
  15353. byte key[] = {
  15354. 0x64, 0x4c, 0xbf, 0x12, 0x85, 0x9d, 0xf0, 0x55,
  15355. 0x7e, 0xa9, 0x1f, 0x08, 0xe0, 0x51, 0xff, 0x27
  15356. };
  15357. byte in[] = "\xe2\xb4\xb6\xf9\x48\x44\x02\x64"
  15358. "\x5c\x47\x80\x9e\xd5\xa8\x3a\x17"
  15359. "\xb3\x78\xcf\x85\x22\x41\x74\xd9"
  15360. "\xa0\x97\x39\x71\x62\xf1\x8e\x8f"
  15361. "\xf4";
  15362. word32 inSz = (word32)sizeof(in) - 1;
  15363. word32 keySz = (word32)sizeof(key);
  15364. int type = WC_CMAC_AES;
  15365. XMEMSET(&cmac, 0, sizeof(Cmac));
  15366. ExpectIntEQ(wc_InitCmac(&cmac, key, keySz, type, NULL), 0);
  15367. ExpectIntEQ(wc_CmacUpdate(&cmac, in, inSz), 0);
  15368. /* Test bad args. */
  15369. ExpectIntEQ(wc_CmacUpdate(NULL, in, inSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15370. ExpectIntEQ(wc_CmacUpdate(&cmac, NULL, 30), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15371. wc_AesFree(&cmac.aes);
  15372. #endif
  15373. return EXPECT_RESULT();
  15374. } /* END test_wc_CmacUpdate */
  15375. /*
  15376. * Testing wc_CmacFinal()
  15377. */
  15378. static int test_wc_CmacFinal(void)
  15379. {
  15380. EXPECT_DECLS;
  15381. #if defined(WOLFSSL_CMAC) && !defined(NO_AES) && defined(WOLFSSL_AES_128)
  15382. Cmac cmac;
  15383. byte key[] = {
  15384. 0x64, 0x4c, 0xbf, 0x12, 0x85, 0x9d, 0xf0, 0x55,
  15385. 0x7e, 0xa9, 0x1f, 0x08, 0xe0, 0x51, 0xff, 0x27
  15386. };
  15387. byte msg[] = {
  15388. 0xe2, 0xb4, 0xb6, 0xf9, 0x48, 0x44, 0x02, 0x64,
  15389. 0x5c, 0x47, 0x80, 0x9e, 0xd5, 0xa8, 0x3a, 0x17,
  15390. 0xb3, 0x78, 0xcf, 0x85, 0x22, 0x41, 0x74, 0xd9,
  15391. 0xa0, 0x97, 0x39, 0x71, 0x62, 0xf1, 0x8e, 0x8f,
  15392. 0xf4
  15393. };
  15394. /* Test vectors from CMACGenAES128.rsp from
  15395. * http://csrc.nist.gov/groups/STM/cavp/block-cipher-modes.html#cmac
  15396. * Per RFC4493 truncation of lsb is possible.
  15397. */
  15398. byte expMac[] = {
  15399. 0x4e, 0x6e, 0xc5, 0x6f, 0xf9, 0x5d, 0x0e, 0xae,
  15400. 0x1c, 0xf8, 0x3e, 0xfc, 0xf4, 0x4b, 0xeb
  15401. };
  15402. byte mac[AES_BLOCK_SIZE];
  15403. word32 msgSz = (word32)sizeof(msg);
  15404. word32 keySz = (word32)sizeof(key);
  15405. word32 macSz = sizeof(mac);
  15406. word32 badMacSz = 17;
  15407. int expMacSz = sizeof(expMac);
  15408. int type = WC_CMAC_AES;
  15409. XMEMSET(&cmac, 0, sizeof(Cmac));
  15410. XMEMSET(mac, 0, macSz);
  15411. ExpectIntEQ(wc_InitCmac(&cmac, key, keySz, type, NULL), 0);
  15412. ExpectIntEQ(wc_CmacUpdate(&cmac, msg, msgSz), 0);
  15413. #if (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  15414. /* Pass in bad args. */
  15415. ExpectIntEQ(wc_CmacFinalNoFree(NULL, mac, &macSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15416. ExpectIntEQ(wc_CmacFinalNoFree(&cmac, NULL, &macSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15417. ExpectIntEQ(wc_CmacFinalNoFree(&cmac, mac, &badMacSz), WC_NO_ERR_TRACE(BUFFER_E));
  15418. /* For the last call, use the API with implicit wc_CmacFree(). */
  15419. ExpectIntEQ(wc_CmacFinal(&cmac, mac, &macSz), 0);
  15420. ExpectIntEQ(XMEMCMP(mac, expMac, expMacSz), 0);
  15421. #else /* !HAVE_FIPS || FIPS>=5.3 */
  15422. ExpectIntEQ(wc_CmacFinal(&cmac, mac, &macSz), 0);
  15423. ExpectIntEQ(XMEMCMP(mac, expMac, expMacSz), 0);
  15424. /* Pass in bad args. */
  15425. ExpectIntEQ(wc_CmacFinal(NULL, mac, &macSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15426. ExpectIntEQ(wc_CmacFinal(&cmac, NULL, &macSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15427. ExpectIntEQ(wc_CmacFinal(&cmac, mac, &badMacSz), WC_NO_ERR_TRACE(BUFFER_E));
  15428. #endif /* !HAVE_FIPS || FIPS>=5.3 */
  15429. #endif
  15430. return EXPECT_RESULT();
  15431. } /* END test_wc_CmacFinal */
  15432. /*
  15433. * Testing wc_AesCmacGenerate() && wc_AesCmacVerify()
  15434. */
  15435. static int test_wc_AesCmacGenerate(void)
  15436. {
  15437. EXPECT_DECLS;
  15438. #if defined(WOLFSSL_CMAC) && !defined(NO_AES) && defined(WOLFSSL_AES_128)
  15439. byte key[] = {
  15440. 0x26, 0xef, 0x8b, 0x40, 0x34, 0x11, 0x7d, 0x9e,
  15441. 0xbe, 0xc0, 0xc7, 0xfc, 0x31, 0x08, 0x54, 0x69
  15442. };
  15443. byte msg[] = "\x18\x90\x49\xef\xfd\x7c\xf9\xc8"
  15444. "\xf3\x59\x65\xbc\xb0\x97\x8f\xd4";
  15445. byte expMac[] = "\x29\x5f\x2f\x71\xfc\x58\xe6\xf6"
  15446. "\x3d\x32\x65\x4c\x66\x23\xc5";
  15447. byte mac[AES_BLOCK_SIZE];
  15448. word32 keySz = sizeof(key);
  15449. word32 macSz = sizeof(mac);
  15450. word32 msgSz = sizeof(msg) - 1;
  15451. word32 expMacSz = sizeof(expMac) - 1;
  15452. XMEMSET(mac, 0, macSz);
  15453. ExpectIntEQ(wc_AesCmacGenerate(mac, &macSz, msg, msgSz, key, keySz), 0);
  15454. ExpectIntEQ(XMEMCMP(mac, expMac, expMacSz), 0);
  15455. /* Pass in bad args. */
  15456. ExpectIntEQ(wc_AesCmacGenerate(NULL, &macSz, msg, msgSz, key, keySz),
  15457. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15458. ExpectIntEQ(wc_AesCmacGenerate(mac, &macSz, msg, msgSz, NULL, keySz),
  15459. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15460. ExpectIntEQ(wc_AesCmacGenerate(mac, &macSz, msg, msgSz, key, 0),
  15461. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15462. ExpectIntEQ(wc_AesCmacGenerate(mac, &macSz, NULL, msgSz, key, keySz),
  15463. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15464. ExpectIntEQ(wc_AesCmacVerify(mac, macSz, msg, msgSz, key, keySz), 0);
  15465. /* Test bad args. */
  15466. ExpectIntEQ(wc_AesCmacVerify(NULL, macSz, msg, msgSz, key, keySz),
  15467. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15468. ExpectIntEQ(wc_AesCmacVerify(mac, 0, msg, msgSz, key, keySz),
  15469. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15470. ExpectIntEQ(wc_AesCmacVerify(mac, macSz, msg, msgSz, NULL, keySz),
  15471. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15472. ExpectIntEQ(wc_AesCmacVerify(mac, macSz, msg, msgSz, key, 0),
  15473. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15474. ExpectIntEQ(wc_AesCmacVerify(mac, macSz, NULL, msgSz, key, keySz),
  15475. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15476. #endif
  15477. return EXPECT_RESULT();
  15478. } /* END test_wc_AesCmacGenerate */
  15479. /*
  15480. * Testing streaming AES-GCM API.
  15481. */
  15482. static int test_wc_AesGcmStream(void)
  15483. {
  15484. EXPECT_DECLS;
  15485. #if !defined(NO_AES) && defined(WOLFSSL_AES_128) && defined(HAVE_AESGCM) && \
  15486. defined(WOLFSSL_AESGCM_STREAM)
  15487. int i;
  15488. WC_RNG rng[1];
  15489. Aes aesEnc[1];
  15490. Aes aesDec[1];
  15491. byte tag[AES_BLOCK_SIZE];
  15492. byte in[AES_BLOCK_SIZE * 3 + 2] = { 0, };
  15493. byte out[AES_BLOCK_SIZE * 3 + 2];
  15494. byte plain[AES_BLOCK_SIZE * 3 + 2];
  15495. byte aad[AES_BLOCK_SIZE * 3 + 2] = { 0, };
  15496. byte key[AES_128_KEY_SIZE] = { 0, };
  15497. byte iv[AES_IV_SIZE] = { 1, };
  15498. byte ivOut[AES_IV_SIZE];
  15499. static const byte expTagAAD1[AES_BLOCK_SIZE] = {
  15500. 0x6c, 0x35, 0xe6, 0x7f, 0x59, 0x9e, 0xa9, 0x2f,
  15501. 0x27, 0x2d, 0x5f, 0x8e, 0x7e, 0x42, 0xd3, 0x05
  15502. };
  15503. static const byte expTagPlain1[AES_BLOCK_SIZE] = {
  15504. 0x24, 0xba, 0x57, 0x95, 0xd0, 0x27, 0x9e, 0x78,
  15505. 0x3a, 0x88, 0x4c, 0x0a, 0x5d, 0x50, 0x23, 0xd1
  15506. };
  15507. static const byte expTag[AES_BLOCK_SIZE] = {
  15508. 0x22, 0x91, 0x70, 0xad, 0x42, 0xc3, 0xad, 0x96,
  15509. 0xe0, 0x31, 0x57, 0x60, 0xb7, 0x92, 0xa3, 0x6d
  15510. };
  15511. XMEMSET(&rng, 0, sizeof(WC_RNG));
  15512. XMEMSET(&aesEnc, 0, sizeof(Aes));
  15513. XMEMSET(&aesDec, 0, sizeof(Aes));
  15514. /* Create a random for generating IV/nonce. */
  15515. ExpectIntEQ(wc_InitRng(rng), 0);
  15516. /* Initialize data structures. */
  15517. ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
  15518. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15519. /* BadParameters to streaming init. */
  15520. ExpectIntEQ(wc_AesGcmEncryptInit(NULL, NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15521. ExpectIntEQ(wc_AesGcmDecryptInit(NULL, NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15522. ExpectIntEQ(wc_AesGcmDecryptInit(aesEnc, NULL, AES_128_KEY_SIZE, NULL, 0),
  15523. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15524. ExpectIntEQ(wc_AesGcmDecryptInit(aesEnc, NULL, 0, NULL, GCM_NONCE_MID_SZ),
  15525. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15526. /* Bad parameters to encrypt update. */
  15527. ExpectIntEQ(wc_AesGcmEncryptUpdate(NULL, NULL, NULL, 0, NULL, 0),
  15528. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15529. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 1, NULL, 0),
  15530. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15531. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, in, 1, NULL, 0),
  15532. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15533. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, out, NULL, 1, NULL, 0),
  15534. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15535. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 0, NULL, 1),
  15536. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15537. /* Bad parameters to decrypt update. */
  15538. ExpectIntEQ(wc_AesGcmDecryptUpdate(NULL, NULL, NULL, 0, NULL, 0),
  15539. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15540. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 1, NULL, 0),
  15541. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15542. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, in, 1, NULL, 0),
  15543. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15544. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, out, NULL, 1, NULL, 0),
  15545. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15546. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 0, NULL, 1),
  15547. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15548. /* Bad parameters to encrypt final. */
  15549. ExpectIntEQ(wc_AesGcmEncryptFinal(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15550. ExpectIntEQ(wc_AesGcmEncryptFinal(NULL, tag, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15551. ExpectIntEQ(wc_AesGcmEncryptFinal(NULL, NULL, AES_BLOCK_SIZE),
  15552. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15553. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15554. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, NULL, AES_BLOCK_SIZE),
  15555. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15556. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE + 1),
  15557. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15558. /* Bad parameters to decrypt final. */
  15559. ExpectIntEQ(wc_AesGcmDecryptFinal(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15560. ExpectIntEQ(wc_AesGcmDecryptFinal(NULL, tag, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15561. ExpectIntEQ(wc_AesGcmDecryptFinal(NULL, NULL, AES_BLOCK_SIZE),
  15562. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15563. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15564. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, NULL, AES_BLOCK_SIZE),
  15565. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15566. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE + 1),
  15567. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15568. /* Check calling final before setting key fails. */
  15569. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, sizeof(tag)), WC_NO_ERR_TRACE(MISSING_KEY));
  15570. ExpectIntEQ(wc_AesGcmEncryptFinal(aesDec, tag, sizeof(tag)), WC_NO_ERR_TRACE(MISSING_KEY));
  15571. /* Check calling update before setting key else fails. */
  15572. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 0, aad, 1),
  15573. WC_NO_ERR_TRACE(MISSING_KEY));
  15574. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 0, aad, 1),
  15575. WC_NO_ERR_TRACE(MISSING_KEY));
  15576. /* Set key but not IV. */
  15577. ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), NULL, 0), 0);
  15578. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), NULL, 0), 0);
  15579. /* Check calling final before setting IV fails. */
  15580. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, sizeof(tag)), WC_NO_ERR_TRACE(MISSING_IV));
  15581. ExpectIntEQ(wc_AesGcmEncryptFinal(aesDec, tag, sizeof(tag)), WC_NO_ERR_TRACE(MISSING_IV));
  15582. /* Check calling update before setting IV else fails. */
  15583. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 0, aad, 1),
  15584. WC_NO_ERR_TRACE(MISSING_IV));
  15585. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 0, aad, 1),
  15586. WC_NO_ERR_TRACE(MISSING_IV));
  15587. /* Set IV using fixed part IV and external IV APIs. */
  15588. ExpectIntEQ(wc_AesGcmSetIV(aesEnc, GCM_NONCE_MID_SZ, iv, AES_IV_FIXED_SZ,
  15589. rng), 0);
  15590. ExpectIntEQ(wc_AesGcmEncryptInit_ex(aesEnc, NULL, 0, ivOut,
  15591. GCM_NONCE_MID_SZ), 0);
  15592. ExpectIntEQ(wc_AesGcmSetExtIV(aesDec, ivOut, GCM_NONCE_MID_SZ), 0);
  15593. ExpectIntEQ(wc_AesGcmInit(aesDec, NULL, 0, NULL, 0), 0);
  15594. /* Encrypt and decrypt data. */
  15595. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, out, in, 1, aad, 1), 0);
  15596. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, plain, out, 1, aad, 1), 0);
  15597. ExpectIntEQ(XMEMCMP(plain, in, 1), 0);
  15598. /* Finalize and check tag matches. */
  15599. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE), 0);
  15600. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
  15601. /* Set key and IV through streaming init API. */
  15602. wc_AesFree(aesEnc);
  15603. wc_AesFree(aesDec);
  15604. ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
  15605. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15606. ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15607. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15608. /* Encrypt/decrypt one block and AAD of one block. */
  15609. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, out, in, AES_BLOCK_SIZE, aad,
  15610. AES_BLOCK_SIZE), 0);
  15611. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, plain, out, AES_BLOCK_SIZE, aad,
  15612. AES_BLOCK_SIZE), 0);
  15613. ExpectIntEQ(XMEMCMP(plain, in, AES_BLOCK_SIZE), 0);
  15614. /* Finalize and check tag matches. */
  15615. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE), 0);
  15616. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
  15617. /* Set key and IV through streaming init API. */
  15618. wc_AesFree(aesEnc);
  15619. wc_AesFree(aesDec);
  15620. ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
  15621. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15622. ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15623. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15624. /* No data to encrypt/decrypt one byte of AAD. */
  15625. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 0, aad, 1), 0);
  15626. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 0, aad, 1), 0);
  15627. /* Finalize and check tag matches. */
  15628. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE), 0);
  15629. ExpectIntEQ(XMEMCMP(tag, expTagAAD1, AES_BLOCK_SIZE), 0);
  15630. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
  15631. /* Set key and IV through streaming init API. */
  15632. wc_AesFree(aesEnc);
  15633. wc_AesFree(aesDec);
  15634. ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
  15635. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15636. ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15637. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15638. /* Encrypt/decrypt one byte and no AAD. */
  15639. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, out, in, 1, NULL, 0), 0);
  15640. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, plain, out, 1, NULL, 0), 0);
  15641. ExpectIntEQ(XMEMCMP(plain, in, 1), 0);
  15642. /* Finalize and check tag matches. */
  15643. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE), 0);
  15644. ExpectIntEQ(XMEMCMP(tag, expTagPlain1, AES_BLOCK_SIZE), 0);
  15645. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
  15646. /* Set key and IV through streaming init API. */
  15647. wc_AesFree(aesEnc);
  15648. wc_AesFree(aesDec);
  15649. ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
  15650. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15651. ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15652. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15653. /* Encryption AES is one byte at a time */
  15654. for (i = 0; i < (int)sizeof(aad); i++) {
  15655. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 0, aad + i, 1),
  15656. 0);
  15657. }
  15658. for (i = 0; i < (int)sizeof(in); i++) {
  15659. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, out + i, in + i, 1, NULL, 0),
  15660. 0);
  15661. }
  15662. /* Decryption AES is two bytes at a time */
  15663. for (i = 0; i < (int)sizeof(aad); i += 2) {
  15664. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 0, aad + i, 2),
  15665. 0);
  15666. }
  15667. for (i = 0; i < (int)sizeof(aad); i += 2) {
  15668. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, plain + i, out + i, 2, NULL,
  15669. 0), 0);
  15670. }
  15671. ExpectIntEQ(XMEMCMP(plain, in, sizeof(in)), 0);
  15672. /* Finalize and check tag matches. */
  15673. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE), 0);
  15674. ExpectIntEQ(XMEMCMP(tag, expTag, AES_BLOCK_SIZE), 0);
  15675. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
  15676. /* Check streaming encryption can be decrypted with one shot. */
  15677. wc_AesFree(aesDec);
  15678. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15679. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15680. ExpectIntEQ(wc_AesGcmSetKey(aesDec, key, sizeof(key)), 0);
  15681. ExpectIntEQ(wc_AesGcmDecrypt(aesDec, plain, out, sizeof(in), iv,
  15682. AES_IV_SIZE, tag, AES_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15683. ExpectIntEQ(XMEMCMP(plain, in, sizeof(in)), 0);
  15684. wc_AesFree(aesEnc);
  15685. wc_AesFree(aesDec);
  15686. wc_FreeRng(rng);
  15687. #endif
  15688. return EXPECT_RESULT();
  15689. } /* END test_wc_AesGcmStream */
  15690. /*
  15691. * Testing streaming SM4 API.
  15692. */
  15693. static int test_wc_Sm4(void)
  15694. {
  15695. int res = TEST_SKIPPED;
  15696. #ifdef WOLFSSL_SM4
  15697. EXPECT_DECLS;
  15698. wc_Sm4 sm4;
  15699. #if defined(WOLFSSL_SM4_ECB) || defined(WOLFSSL_SM4_CBC) || \
  15700. defined(WOLFSSL_SM4_CTR) || defined(WOLFSSL_SM4_CCM)
  15701. unsigned char key[SM4_KEY_SIZE];
  15702. #endif
  15703. #if defined(WOLFSSL_SM4_CBC) || defined(WOLFSSL_SM4_CTR)
  15704. unsigned char iv[SM4_IV_SIZE];
  15705. #endif
  15706. /* Invalid parameters - wc_Sm4Init */
  15707. ExpectIntEQ(wc_Sm4Init(NULL, NULL, INVALID_DEVID), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15708. /* Valid cases - wc_Sm4Init */
  15709. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  15710. #if defined(WOLFSSL_SM4_ECB) || defined(WOLFSSL_SM4_CBC) || \
  15711. defined(WOLFSSL_SM4_CTR) || defined(WOLFSSL_SM4_CCM)
  15712. XMEMSET(key, 0, sizeof(key));
  15713. /* Invalid parameters - wc_Sm4SetKey. */
  15714. ExpectIntEQ(wc_Sm4SetKey(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15715. ExpectIntEQ(wc_Sm4SetKey(&sm4, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15716. ExpectIntEQ(wc_Sm4SetKey(NULL, key, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15717. ExpectIntEQ(wc_Sm4SetKey(NULL, NULL, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15718. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15719. ExpectIntEQ(wc_Sm4SetKey(&sm4, NULL, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15720. ExpectIntEQ(wc_Sm4SetKey(NULL, key, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15721. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE-1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15722. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE+1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15723. /* Valid cases - wc_Sm4SetKey. */
  15724. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE), 0);
  15725. #endif
  15726. #if defined(WOLFSSL_SM4_CBC) || defined(WOLFSSL_SM4_CTR)
  15727. XMEMSET(iv, 0, sizeof(iv));
  15728. /* Invalid parameters - wc_Sm4SetIV. */
  15729. ExpectIntEQ(wc_Sm4SetIV(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15730. ExpectIntEQ(wc_Sm4SetIV(&sm4, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15731. ExpectIntEQ(wc_Sm4SetIV(NULL, iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15732. /* Valid cases - wc_Sm4SetIV. */
  15733. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15734. #endif
  15735. /* Valid cases - wc_Sm4Free */
  15736. wc_Sm4Free(NULL);
  15737. wc_Sm4Free(&sm4);
  15738. res = EXPECT_RESULT();
  15739. #endif
  15740. return res;
  15741. } /* END test_wc_Sm4 */
  15742. /*
  15743. * Testing block based SM4-ECB API.
  15744. */
  15745. static int test_wc_Sm4Ecb(void)
  15746. {
  15747. int res = TEST_SKIPPED;
  15748. #ifdef WOLFSSL_SM4_ECB
  15749. EXPECT_DECLS;
  15750. wc_Sm4 sm4;
  15751. unsigned char key[SM4_KEY_SIZE];
  15752. unsigned char in[SM4_BLOCK_SIZE * 2];
  15753. unsigned char out[SM4_BLOCK_SIZE * 2];
  15754. unsigned char out2[SM4_BLOCK_SIZE];
  15755. XMEMSET(key, 0, sizeof(key));
  15756. XMEMSET(in, 0, sizeof(in));
  15757. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  15758. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_KEY));
  15759. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_KEY));
  15760. /* Tested in test_wc_Sm4. */
  15761. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE), 0);
  15762. /* Invalid parameters - wc_Sm4EcbEncrypt. */
  15763. ExpectIntEQ(wc_Sm4EcbEncrypt(NULL, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15764. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15765. ExpectIntEQ(wc_Sm4EcbEncrypt(NULL, out, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15766. ExpectIntEQ(wc_Sm4EcbEncrypt(NULL, NULL, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15767. ExpectIntEQ(wc_Sm4EcbEncrypt(NULL, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15768. ExpectIntEQ(wc_Sm4EcbEncrypt(NULL, out, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15769. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15770. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15771. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15772. /* Valid cases - wc_Sm4EcbEncrypt. */
  15773. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out, in, 0), 0);
  15774. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out2, in, SM4_BLOCK_SIZE), 0);
  15775. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15776. ExpectIntEQ(XMEMCMP(out, out2, SM4_BLOCK_SIZE), 0);
  15777. /* In and out are same pointer. */
  15778. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, in, in, SM4_BLOCK_SIZE * 2), 0);
  15779. ExpectIntEQ(XMEMCMP(in, out, SM4_BLOCK_SIZE * 2), 0);
  15780. /* Invalid parameters - wc_Sm4EcbDecrypt. */
  15781. ExpectIntEQ(wc_Sm4EcbDecrypt(NULL, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15782. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15783. ExpectIntEQ(wc_Sm4EcbDecrypt(NULL, out, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15784. ExpectIntEQ(wc_Sm4EcbDecrypt(NULL, NULL, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15785. ExpectIntEQ(wc_Sm4EcbDecrypt(NULL, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15786. ExpectIntEQ(wc_Sm4EcbDecrypt(NULL, out, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15787. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15788. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15789. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15790. /* Valid cases - wc_Sm4EcbDecrypt. */
  15791. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out, in, 0), 0);
  15792. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out2, in, SM4_BLOCK_SIZE), 0);
  15793. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15794. ExpectIntEQ(XMEMCMP(out, out2, SM4_BLOCK_SIZE), 0);
  15795. /* In and out are same pointer. */
  15796. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, in, in, SM4_BLOCK_SIZE * 2), 0);
  15797. ExpectIntEQ(XMEMCMP(in, out, SM4_BLOCK_SIZE * 2), 0);
  15798. wc_Sm4Free(&sm4);
  15799. res = EXPECT_RESULT();
  15800. #endif
  15801. return res;
  15802. } /* END test_wc_Sm4Ecb */
  15803. /*
  15804. * Testing block based SM4-CBC API.
  15805. */
  15806. static int test_wc_Sm4Cbc(void)
  15807. {
  15808. int res = TEST_SKIPPED;
  15809. #ifdef WOLFSSL_SM4_CBC
  15810. EXPECT_DECLS;
  15811. wc_Sm4 sm4;
  15812. unsigned char key[SM4_KEY_SIZE];
  15813. unsigned char iv[SM4_IV_SIZE];
  15814. unsigned char in[SM4_BLOCK_SIZE * 2];
  15815. unsigned char out[SM4_BLOCK_SIZE * 2];
  15816. unsigned char out2[SM4_BLOCK_SIZE];
  15817. XMEMSET(key, 0, sizeof(key));
  15818. XMEMSET(iv, 0, sizeof(iv));
  15819. XMEMSET(in, 0, sizeof(in));
  15820. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  15821. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_KEY));
  15822. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_KEY));
  15823. /* Tested in test_wc_Sm4. */
  15824. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE), 0);
  15825. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_IV));
  15826. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_IV));
  15827. /* Tested in test_wc_Sm4. */
  15828. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15829. /* Invalid parameters - wc_Sm4CbcEncrypt. */
  15830. ExpectIntEQ(wc_Sm4CbcEncrypt(NULL, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15831. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15832. ExpectIntEQ(wc_Sm4CbcEncrypt(NULL, out, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15833. ExpectIntEQ(wc_Sm4CbcEncrypt(NULL, NULL, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15834. ExpectIntEQ(wc_Sm4CbcEncrypt(NULL, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15835. ExpectIntEQ(wc_Sm4CbcEncrypt(NULL, out, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15836. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15837. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15838. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15839. /* Valid cases - wc_Sm4CbcEncrypt. */
  15840. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, in, 0), 0);
  15841. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out2, in, SM4_BLOCK_SIZE), 0);
  15842. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15843. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15844. ExpectIntEQ(XMEMCMP(out, out2, SM4_BLOCK_SIZE), 0);
  15845. /* In and out are same pointer. */
  15846. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15847. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, in, in, SM4_BLOCK_SIZE * 2), 0);
  15848. ExpectIntEQ(XMEMCMP(in, out, SM4_BLOCK_SIZE * 2), 0);
  15849. /* Invalid parameters - wc_Sm4CbcDecrypt. */
  15850. ExpectIntEQ(wc_Sm4CbcDecrypt(NULL, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15851. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15852. ExpectIntEQ(wc_Sm4CbcDecrypt(NULL, out, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15853. ExpectIntEQ(wc_Sm4CbcDecrypt(NULL, NULL, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15854. ExpectIntEQ(wc_Sm4CbcDecrypt(NULL, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15855. ExpectIntEQ(wc_Sm4CbcDecrypt(NULL, out, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15856. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15857. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15858. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15859. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15860. /* Valid cases - wc_Sm4CbcDecrypt. */
  15861. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, in, 0), 0);
  15862. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out2, in, SM4_BLOCK_SIZE), 0);
  15863. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15864. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15865. ExpectIntEQ(XMEMCMP(out, out2, SM4_BLOCK_SIZE), 0);
  15866. /* In and out are same pointer. */
  15867. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15868. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, in, in, SM4_BLOCK_SIZE * 2), 0);
  15869. ExpectIntEQ(XMEMCMP(in, out, SM4_BLOCK_SIZE * 2), 0);
  15870. wc_Sm4Free(&sm4);
  15871. res = EXPECT_RESULT();
  15872. #endif
  15873. return res;
  15874. } /* END test_wc_Sm4Cbc */
  15875. /*
  15876. * Testing streaming SM4-CTR API.
  15877. */
  15878. static int test_wc_Sm4Ctr(void)
  15879. {
  15880. int res = TEST_SKIPPED;
  15881. #ifdef WOLFSSL_SM4_CTR
  15882. EXPECT_DECLS;
  15883. wc_Sm4 sm4;
  15884. unsigned char key[SM4_KEY_SIZE];
  15885. unsigned char iv[SM4_IV_SIZE];
  15886. unsigned char in[SM4_BLOCK_SIZE * 4];
  15887. unsigned char out[SM4_BLOCK_SIZE * 4];
  15888. unsigned char out2[SM4_BLOCK_SIZE * 4];
  15889. word32 chunk;
  15890. word32 i;
  15891. XMEMSET(key, 0, sizeof(key));
  15892. XMEMSET(iv, 0, sizeof(iv));
  15893. XMEMSET(in, 0, sizeof(in));
  15894. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  15895. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_KEY));
  15896. /* Tested in test_wc_Sm4. */
  15897. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE), 0);
  15898. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_IV));
  15899. /* Tested in test_wc_Sm4. */
  15900. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15901. /* Invalid parameters - wc_Sm4CtrEncrypt. */
  15902. ExpectIntEQ(wc_Sm4CtrEncrypt(NULL, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15903. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15904. ExpectIntEQ(wc_Sm4CtrEncrypt(NULL, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15905. ExpectIntEQ(wc_Sm4CtrEncrypt(NULL, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15906. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15907. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15908. ExpectIntEQ(wc_Sm4CtrEncrypt(NULL, out, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15909. /* Valid cases - wc_Sm4CtrEncrypt. */
  15910. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, 0), 0);
  15911. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out2, in, 1), 0);
  15912. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15913. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, 2), 0);
  15914. ExpectIntEQ(XMEMCMP(out, out2, 1), 0);
  15915. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15916. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out2, in, SM4_BLOCK_SIZE), 0);
  15917. ExpectIntEQ(XMEMCMP(out2, out, 2), 0);
  15918. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15919. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15920. ExpectIntEQ(XMEMCMP(out, out2, SM4_BLOCK_SIZE), 0);
  15921. /* In and out are same pointer. Also check encrypt of cipher text produces
  15922. * plaintext.
  15923. */
  15924. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15925. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, out, SM4_BLOCK_SIZE * 2), 0);
  15926. ExpectIntEQ(XMEMCMP(in, out, SM4_BLOCK_SIZE * 2), 0);
  15927. /* Chunking tests. */
  15928. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15929. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out2, in, (word32)sizeof(in)), 0);
  15930. for (chunk = 1; chunk <= SM4_BLOCK_SIZE + 1; chunk++) {
  15931. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15932. for (i = 0; i + chunk <= (word32)sizeof(in); i += chunk) {
  15933. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out + i, in + i, chunk), 0);
  15934. }
  15935. if (i < (word32)sizeof(in)) {
  15936. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out + i, in + i,
  15937. (word32)sizeof(in) - i), 0);
  15938. }
  15939. ExpectIntEQ(XMEMCMP(out, out2, (word32)sizeof(out)), 0);
  15940. }
  15941. for (i = 0; i < (word32)sizeof(iv); i++) {
  15942. iv[i] = 0xff;
  15943. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15944. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15945. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15946. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out2, out, SM4_BLOCK_SIZE * 2), 0);
  15947. ExpectIntEQ(XMEMCMP(out2, in, SM4_BLOCK_SIZE * 2), 0);
  15948. }
  15949. wc_Sm4Free(&sm4);
  15950. res = EXPECT_RESULT();
  15951. #endif
  15952. return res;
  15953. } /* END test_wc_Sm4Ctr */
  15954. /*
  15955. * Testing stream SM4-GCM API.
  15956. */
  15957. static int test_wc_Sm4Gcm(void)
  15958. {
  15959. int res = TEST_SKIPPED;
  15960. #ifdef WOLFSSL_SM4_GCM
  15961. EXPECT_DECLS;
  15962. wc_Sm4 sm4;
  15963. unsigned char key[SM4_KEY_SIZE];
  15964. unsigned char nonce[GCM_NONCE_MAX_SZ];
  15965. unsigned char in[SM4_BLOCK_SIZE * 2];
  15966. unsigned char in2[SM4_BLOCK_SIZE * 2];
  15967. unsigned char out[SM4_BLOCK_SIZE * 2];
  15968. unsigned char out2[SM4_BLOCK_SIZE * 2];
  15969. unsigned char dec[SM4_BLOCK_SIZE * 2];
  15970. unsigned char tag[SM4_BLOCK_SIZE];
  15971. unsigned char aad[SM4_BLOCK_SIZE * 2];
  15972. word32 i;
  15973. XMEMSET(key, 0, sizeof(key));
  15974. XMEMSET(nonce, 0, sizeof(nonce));
  15975. XMEMSET(in, 0, sizeof(in));
  15976. XMEMSET(in2, 0, sizeof(in2));
  15977. XMEMSET(aad, 0, sizeof(aad));
  15978. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  15979. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 0, nonce, GCM_NONCE_MID_SZ, tag,
  15980. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(MISSING_KEY));
  15981. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 0, nonce, GCM_NONCE_MID_SZ, tag,
  15982. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(MISSING_KEY));
  15983. /* Invalid parameters - wc_Sm4GcmSetKey. */
  15984. ExpectIntEQ(wc_Sm4GcmSetKey(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15985. ExpectIntEQ(wc_Sm4GcmSetKey(&sm4, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15986. ExpectIntEQ(wc_Sm4GcmSetKey(NULL, key, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15987. ExpectIntEQ(wc_Sm4GcmSetKey(NULL, NULL, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15988. ExpectIntEQ(wc_Sm4GcmSetKey(&sm4, key, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15989. ExpectIntEQ(wc_Sm4GcmSetKey(&sm4, NULL, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15990. ExpectIntEQ(wc_Sm4GcmSetKey(NULL, key, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15991. /* Valid parameters - wc_Sm4GcmSetKey. */
  15992. ExpectIntEQ(wc_Sm4GcmSetKey(&sm4, key, SM4_KEY_SIZE), 0);
  15993. /* Invalid parameters - wc_Sm4GcmEncrypt. */
  15994. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  15995. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15996. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  15997. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15998. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, out, NULL, 1, NULL, 0, NULL, 0, NULL,
  15999. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16000. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, NULL, in, 1, NULL, 0, NULL, 0, NULL,
  16001. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16002. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, NULL, NULL, 1, nonce, GCM_NONCE_MID_SZ,
  16003. NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16004. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, NULL, NULL, 1, NULL, 0, tag,
  16005. SM4_BLOCK_SIZE, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16006. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  16007. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16008. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, NULL, in, 1, nonce, GCM_NONCE_MID_SZ,
  16009. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16010. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, NULL, 1, nonce, GCM_NONCE_MID_SZ,
  16011. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16012. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, NULL, GCM_NONCE_MID_SZ, tag,
  16013. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16014. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, nonce, 0, tag,
  16015. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16016. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ,
  16017. NULL, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16018. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  16019. WOLFSSL_MIN_AUTH_TAG_SZ-1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16020. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  16021. SM4_BLOCK_SIZE+1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16022. /* Invalid parameters - wc_Sm4GcmDecrypt. */
  16023. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  16024. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16025. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  16026. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16027. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, out, NULL, 1, NULL, 0, NULL, 0, NULL,
  16028. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16029. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, NULL, in, 1, NULL, 0, NULL, 0, NULL,
  16030. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16031. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, NULL, NULL, 1, nonce, GCM_NONCE_MID_SZ,
  16032. NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16033. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, NULL, NULL, 1, NULL, 0, tag,
  16034. SM4_BLOCK_SIZE, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16035. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  16036. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16037. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, NULL, in, 1, nonce, GCM_NONCE_MID_SZ,
  16038. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16039. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, NULL, 1, nonce, GCM_NONCE_MID_SZ,
  16040. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16041. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 1, NULL, GCM_NONCE_MID_SZ, tag,
  16042. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16043. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 1, nonce, 0, tag,
  16044. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16045. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ,
  16046. NULL, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16047. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  16048. WOLFSSL_MIN_AUTH_TAG_SZ-1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16049. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  16050. SM4_BLOCK_SIZE+1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16051. /* Valid cases - wc_Sm4GcmEncrypt/wc_Sm4GcmDecrypt. */
  16052. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, NULL, NULL, 0, nonce, GCM_NONCE_MID_SZ,
  16053. tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16054. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, NULL, NULL, 0, nonce, GCM_NONCE_MID_SZ,
  16055. tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16056. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, NULL, NULL, 0, nonce, GCM_NONCE_MID_SZ,
  16057. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16058. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, NULL, NULL, 0, nonce, GCM_NONCE_MID_SZ,
  16059. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16060. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16061. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16062. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16063. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16064. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16065. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 1), 0);
  16066. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16067. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 1), 0);
  16068. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2, nonce,
  16069. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16070. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE * 2, nonce,
  16071. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16072. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, in2, in2, SM4_BLOCK_SIZE * 2, nonce,
  16073. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16074. ExpectIntEQ(XMEMCMP(in2, out, SM4_BLOCK_SIZE * 2), 0);
  16075. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in2, in2, SM4_BLOCK_SIZE * 2, nonce,
  16076. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16077. ExpectIntEQ(XMEMCMP(in2, in, SM4_BLOCK_SIZE * 2), 0);
  16078. /* Check vald values of nonce - wc_Sm4GcmEncrypt/wc_Sm4GcmDecrypt. */
  16079. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16080. GCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16081. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16082. GCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16083. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2, nonce,
  16084. GCM_NONCE_MIN_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16085. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE * 2, nonce,
  16086. GCM_NONCE_MIN_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16087. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE * 2, nonce,
  16088. GCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)),
  16089. WC_NO_ERR_TRACE(SM4_GCM_AUTH_E));
  16090. /* Check valid values of tag size - wc_Sm4GcmEncrypt/wc_Sm4GcmDecrypt. */
  16091. for (i = WOLFSSL_MIN_AUTH_TAG_SZ; i < SM4_BLOCK_SIZE; i++) {
  16092. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16093. GCM_NONCE_MID_SZ, tag, i, aad, sizeof(aad)), 0);
  16094. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16095. GCM_NONCE_MID_SZ, tag, i, aad, sizeof(aad)), 0);
  16096. }
  16097. /* Check different in/out sizes. */
  16098. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 0, nonce,
  16099. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16100. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 0, nonce,
  16101. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16102. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, nonce,
  16103. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16104. for (i = 2; i <= SM4_BLOCK_SIZE * 2; i++) {
  16105. XMEMCPY(out2, out, i - 1);
  16106. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, i, nonce, GCM_NONCE_MID_SZ,
  16107. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16108. ExpectIntEQ(XMEMCMP(out, out2, i - 1), 0);
  16109. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, dec, out, i, nonce, GCM_NONCE_MID_SZ,
  16110. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16111. ExpectIntEQ(XMEMCMP(in, dec, i), 0);
  16112. }
  16113. /* Force the counter to roll over in first byte. */
  16114. {
  16115. static unsigned char largeIn[256 * SM4_BLOCK_SIZE];
  16116. static unsigned char largeOut[256 * SM4_BLOCK_SIZE];
  16117. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, largeOut, largeIn, sizeof(largeIn),
  16118. nonce, GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16119. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, largeOut, largeOut, sizeof(largeIn),
  16120. nonce, GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16121. ExpectIntEQ(XMEMCMP(largeOut, largeIn, sizeof(largeIn)), 0);
  16122. }
  16123. wc_Sm4Free(&sm4);
  16124. res = EXPECT_RESULT();
  16125. #endif
  16126. return res;
  16127. } /* END test_wc_Sm4Gcm */
  16128. /*
  16129. * Testing stream SM4-CCM API.
  16130. */
  16131. static int test_wc_Sm4Ccm(void)
  16132. {
  16133. int res = TEST_SKIPPED;
  16134. #ifdef WOLFSSL_SM4_CCM
  16135. EXPECT_DECLS;
  16136. wc_Sm4 sm4;
  16137. unsigned char key[SM4_KEY_SIZE];
  16138. unsigned char nonce[CCM_NONCE_MAX_SZ];
  16139. unsigned char in[SM4_BLOCK_SIZE * 2];
  16140. unsigned char in2[SM4_BLOCK_SIZE * 2];
  16141. unsigned char out[SM4_BLOCK_SIZE * 2];
  16142. unsigned char out2[SM4_BLOCK_SIZE * 2];
  16143. unsigned char dec[SM4_BLOCK_SIZE * 2];
  16144. unsigned char tag[SM4_BLOCK_SIZE];
  16145. unsigned char aad[SM4_BLOCK_SIZE * 2];
  16146. word32 i;
  16147. XMEMSET(key, 0, sizeof(key));
  16148. XMEMSET(nonce, 0, sizeof(nonce));
  16149. XMEMSET(in, 0, sizeof(in));
  16150. XMEMSET(in2, 0, sizeof(in2));
  16151. XMEMSET(aad, 0, sizeof(aad));
  16152. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  16153. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 0, nonce, CCM_NONCE_MAX_SZ, tag,
  16154. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(MISSING_KEY));
  16155. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 0, nonce, CCM_NONCE_MAX_SZ, tag,
  16156. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(MISSING_KEY));
  16157. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE), 0);
  16158. /* Invalid parameters - wc_Sm4CcmEncrypt. */
  16159. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  16160. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16161. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  16162. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16163. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, out, NULL, 1, NULL, 0, NULL, 0, NULL,
  16164. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16165. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, NULL, in, 1, NULL, 0, NULL, 0, NULL,
  16166. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16167. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, NULL, NULL, 1, nonce, CCM_NONCE_MAX_SZ,
  16168. NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16169. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, NULL, NULL, 1, NULL, 0, tag,
  16170. SM4_BLOCK_SIZE, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16171. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  16172. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16173. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, NULL, in, 1, nonce, CCM_NONCE_MAX_SZ,
  16174. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16175. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, NULL, 1, nonce, CCM_NONCE_MAX_SZ,
  16176. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16177. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, NULL, CCM_NONCE_MAX_SZ, tag,
  16178. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16179. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, nonce, 0, tag,
  16180. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16181. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ,
  16182. NULL, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16183. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  16184. WOLFSSL_MIN_AUTH_TAG_SZ-1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16185. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  16186. SM4_BLOCK_SIZE+1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16187. /* Invalid parameters - wc_Sm4CcmDecrypt. */
  16188. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  16189. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16190. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  16191. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16192. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, out, NULL, 1, NULL, 0, NULL, 0, NULL,
  16193. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16194. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, NULL, in, 1, NULL, 0, NULL, 0, NULL,
  16195. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16196. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, NULL, NULL, 1, nonce, CCM_NONCE_MAX_SZ,
  16197. NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16198. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, NULL, NULL, 1, NULL, 0, tag,
  16199. SM4_BLOCK_SIZE, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16200. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  16201. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16202. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, NULL, in, 1, nonce, CCM_NONCE_MAX_SZ,
  16203. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16204. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, NULL, 1, nonce, CCM_NONCE_MAX_SZ,
  16205. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16206. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 1, NULL, CCM_NONCE_MAX_SZ, tag,
  16207. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16208. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 1, nonce, 0, tag,
  16209. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16210. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ,
  16211. NULL, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16212. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  16213. WOLFSSL_MIN_AUTH_TAG_SZ - 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16214. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  16215. SM4_BLOCK_SIZE + 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16216. /* Valid cases - wc_Sm4CcmEncrypt/wc_Sm4CcmDecrypt. */
  16217. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, NULL, NULL, 0, nonce, CCM_NONCE_MAX_SZ,
  16218. tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16219. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, NULL, NULL, 0, nonce, CCM_NONCE_MAX_SZ,
  16220. tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16221. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, NULL, NULL, 0, nonce, CCM_NONCE_MAX_SZ,
  16222. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16223. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, NULL, NULL, 0, nonce, CCM_NONCE_MAX_SZ,
  16224. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16225. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16226. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16227. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16228. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16229. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16230. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 1), 0);
  16231. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16232. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 1), 0);
  16233. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2, nonce,
  16234. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16235. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE * 2, nonce,
  16236. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16237. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, in2, in2, SM4_BLOCK_SIZE * 2, nonce,
  16238. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16239. ExpectIntEQ(XMEMCMP(in2, out, SM4_BLOCK_SIZE * 2), 0);
  16240. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in2, in2, SM4_BLOCK_SIZE * 2, nonce,
  16241. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16242. ExpectIntEQ(XMEMCMP(in2, in, SM4_BLOCK_SIZE * 2), 0);
  16243. /* Check vald values of nonce - wc_Sm4CcmEncrypt/wc_Sm4CcmDecrypt. */
  16244. for (i = CCM_NONCE_MIN_SZ; i <= CCM_NONCE_MAX_SZ; i++) {
  16245. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16246. i, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16247. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16248. i, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16249. }
  16250. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16251. CCM_NONCE_MIN_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)),
  16252. WC_NO_ERR_TRACE(SM4_CCM_AUTH_E));
  16253. /* Check invalid values of tag size - wc_Sm4CcmEncrypt/wc_Sm4CcmDecrypt. */
  16254. for (i = 0; i < 4; i++) {
  16255. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16256. CCM_NONCE_MAX_SZ, tag, i * 2 + 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16257. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16258. CCM_NONCE_MAX_SZ, tag, i * 2 + 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16259. }
  16260. /* Odd values in range 4..SM4_BLOCK_SIZE. */
  16261. for (i = 2; i < SM4_BLOCK_SIZE / 2; i++) {
  16262. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16263. CCM_NONCE_MAX_SZ, tag, i * 2 + 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16264. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16265. CCM_NONCE_MAX_SZ, tag, i * 2 + 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16266. }
  16267. /* Check valid values of tag size - wc_Sm4CcmEncrypt/wc_Sm4CcmDecrypt.
  16268. * Even values in range 4..SM4_BLOCK_SIZE.
  16269. */
  16270. for (i = 2; i < SM4_BLOCK_SIZE / 2; i++) {
  16271. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16272. CCM_NONCE_MAX_SZ, tag, i * 2, aad, sizeof(aad)), 0);
  16273. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16274. CCM_NONCE_MAX_SZ, tag, i * 2, aad, sizeof(aad)), 0);
  16275. }
  16276. /* Check different in/out sizes. */
  16277. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 0, nonce,
  16278. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16279. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 0, nonce,
  16280. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16281. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, nonce,
  16282. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16283. for (i = 2; i <= SM4_BLOCK_SIZE * 2; i++) {
  16284. XMEMCPY(out2, out, i - 1);
  16285. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, i, nonce, CCM_NONCE_MAX_SZ,
  16286. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16287. ExpectIntEQ(XMEMCMP(out, out2, i - 1), 0);
  16288. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, dec, out, i, nonce, CCM_NONCE_MAX_SZ,
  16289. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16290. ExpectIntEQ(XMEMCMP(in, dec, i), 0);
  16291. }
  16292. /* Force the counter to roll over in first byte. */
  16293. {
  16294. static unsigned char largeIn[256 * SM4_BLOCK_SIZE];
  16295. static unsigned char largeOut[256 * SM4_BLOCK_SIZE];
  16296. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, largeOut, largeIn, sizeof(largeIn),
  16297. nonce, CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16298. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, largeOut, largeOut, sizeof(largeIn),
  16299. nonce, CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16300. ExpectIntEQ(XMEMCMP(largeOut, largeIn, sizeof(largeIn)), 0);
  16301. }
  16302. wc_Sm4Free(&sm4);
  16303. res = EXPECT_RESULT();
  16304. #endif
  16305. return res;
  16306. } /* END test_wc_Sm4Ccm */
  16307. /*
  16308. * unit test for wc_Des3_SetIV()
  16309. */
  16310. static int test_wc_Des3_SetIV(void)
  16311. {
  16312. EXPECT_DECLS;
  16313. #ifndef NO_DES3
  16314. Des3 des;
  16315. const byte key[] = {
  16316. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  16317. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  16318. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  16319. };
  16320. const byte iv[] = {
  16321. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  16322. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  16323. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  16324. };
  16325. XMEMSET(&des, 0, sizeof(Des3));
  16326. ExpectIntEQ(wc_Des3Init(&des, NULL, INVALID_DEVID), 0);
  16327. /* DES_ENCRYPTION or DES_DECRYPTION */
  16328. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, DES_ENCRYPTION), 0);
  16329. ExpectIntEQ(XMEMCMP(iv, des.reg, DES_BLOCK_SIZE), 0);
  16330. #ifndef HAVE_FIPS /* no sanity checks with FIPS wrapper */
  16331. /* Test explicitly wc_Des3_SetIV() */
  16332. ExpectIntEQ(wc_Des3_SetIV(NULL, iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16333. ExpectIntEQ(wc_Des3_SetIV(&des, NULL), 0);
  16334. #endif
  16335. wc_Des3Free(&des);
  16336. #endif
  16337. return EXPECT_RESULT();
  16338. } /* END test_wc_Des3_SetIV */
  16339. /*
  16340. * unit test for wc_Des3_SetKey()
  16341. */
  16342. static int test_wc_Des3_SetKey(void)
  16343. {
  16344. EXPECT_DECLS;
  16345. #ifndef NO_DES3
  16346. Des3 des;
  16347. const byte key[] = {
  16348. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  16349. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  16350. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  16351. };
  16352. const byte iv[] = {
  16353. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  16354. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  16355. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  16356. };
  16357. XMEMSET(&des, 0, sizeof(Des3));
  16358. ExpectIntEQ(wc_Des3Init(&des, NULL, INVALID_DEVID), 0);
  16359. /* DES_ENCRYPTION or DES_DECRYPTION */
  16360. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, DES_ENCRYPTION), 0);
  16361. ExpectIntEQ(XMEMCMP(iv, des.reg, DES_BLOCK_SIZE), 0);
  16362. /* Test bad args. */
  16363. ExpectIntEQ(wc_Des3_SetKey(NULL, key, iv, DES_ENCRYPTION), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16364. ExpectIntEQ(wc_Des3_SetKey(&des, NULL, iv, DES_ENCRYPTION), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16365. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16366. /* Default case. Should return 0. */
  16367. ExpectIntEQ(wc_Des3_SetKey(&des, key, NULL, DES_ENCRYPTION), 0);
  16368. wc_Des3Free(&des);
  16369. #endif
  16370. return EXPECT_RESULT();
  16371. } /* END test_wc_Des3_SetKey */
  16372. /*
  16373. * Test function for wc_Des3_CbcEncrypt and wc_Des3_CbcDecrypt
  16374. */
  16375. static int test_wc_Des3_CbcEncryptDecrypt(void)
  16376. {
  16377. EXPECT_DECLS;
  16378. #ifndef NO_DES3
  16379. Des3 des;
  16380. byte cipher[24];
  16381. byte plain[24];
  16382. const byte key[] = {
  16383. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  16384. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  16385. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  16386. };
  16387. const byte iv[] = {
  16388. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  16389. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  16390. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  16391. };
  16392. const byte vector[] = { /* "Now is the time for all " w/o trailing 0 */
  16393. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  16394. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  16395. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  16396. };
  16397. XMEMSET(&des, 0, sizeof(Des3));
  16398. ExpectIntEQ(wc_Des3Init(&des, NULL, INVALID_DEVID), 0);
  16399. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, DES_ENCRYPTION), 0);
  16400. ExpectIntEQ(wc_Des3_CbcEncrypt(&des, cipher, vector, 24), 0);
  16401. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, DES_DECRYPTION), 0);
  16402. ExpectIntEQ(wc_Des3_CbcDecrypt(&des, plain, cipher, 24), 0);
  16403. ExpectIntEQ(XMEMCMP(plain, vector, 24), 0);
  16404. /* Pass in bad args. */
  16405. ExpectIntEQ(wc_Des3_CbcEncrypt(NULL, cipher, vector, 24), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16406. ExpectIntEQ(wc_Des3_CbcEncrypt(&des, NULL, vector, 24), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16407. ExpectIntEQ(wc_Des3_CbcEncrypt(&des, cipher, NULL, sizeof(vector)),
  16408. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16409. ExpectIntEQ(wc_Des3_CbcDecrypt(NULL, plain, cipher, 24), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16410. ExpectIntEQ(wc_Des3_CbcDecrypt(&des, NULL, cipher, 24), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16411. ExpectIntEQ(wc_Des3_CbcDecrypt(&des, plain, NULL, 24), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16412. wc_Des3Free(&des);
  16413. #endif
  16414. return EXPECT_RESULT();
  16415. } /* END wc_Des3_CbcEncrypt */
  16416. /*
  16417. * Unit test for wc_Des3_CbcEncryptWithKey and wc_Des3_CbcDecryptWithKey
  16418. */
  16419. static int test_wc_Des3_CbcEncryptDecryptWithKey(void)
  16420. {
  16421. EXPECT_DECLS;
  16422. #ifndef NO_DES3
  16423. word32 vectorSz, cipherSz;
  16424. byte cipher[24];
  16425. byte plain[24];
  16426. byte vector[] = { /* Now is the time for all w/o trailing 0 */
  16427. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  16428. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  16429. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  16430. };
  16431. byte key[] = {
  16432. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  16433. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  16434. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  16435. };
  16436. byte iv[] = {
  16437. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  16438. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  16439. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  16440. };
  16441. vectorSz = sizeof(byte) * 24;
  16442. cipherSz = sizeof(byte) * 24;
  16443. ExpectIntEQ(wc_Des3_CbcEncryptWithKey(cipher, vector, vectorSz, key, iv),
  16444. 0);
  16445. ExpectIntEQ(wc_Des3_CbcDecryptWithKey(plain, cipher, cipherSz, key, iv), 0);
  16446. ExpectIntEQ(XMEMCMP(plain, vector, 24), 0);
  16447. /* pass in bad args. */
  16448. ExpectIntEQ(wc_Des3_CbcEncryptWithKey(NULL, vector, vectorSz, key, iv),
  16449. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16450. ExpectIntEQ(wc_Des3_CbcEncryptWithKey(cipher, NULL, vectorSz, key, iv),
  16451. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16452. ExpectIntEQ(wc_Des3_CbcEncryptWithKey(cipher, vector, vectorSz, NULL, iv),
  16453. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16454. ExpectIntEQ(wc_Des3_CbcEncryptWithKey(cipher, vector, vectorSz, key, NULL),
  16455. 0);
  16456. ExpectIntEQ(wc_Des3_CbcDecryptWithKey(NULL, cipher, cipherSz, key, iv),
  16457. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16458. ExpectIntEQ(wc_Des3_CbcDecryptWithKey(plain, NULL, cipherSz, key, iv),
  16459. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16460. ExpectIntEQ(wc_Des3_CbcDecryptWithKey(plain, cipher, cipherSz, NULL, iv),
  16461. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16462. ExpectIntEQ(wc_Des3_CbcDecryptWithKey(plain, cipher, cipherSz, key, NULL),
  16463. 0);
  16464. #endif
  16465. return EXPECT_RESULT();
  16466. } /* END test_wc_Des3_CbcEncryptDecryptWithKey */
  16467. /*
  16468. * Unit test for wc_Des3_EcbEncrypt
  16469. */
  16470. static int test_wc_Des3_EcbEncrypt(void)
  16471. {
  16472. EXPECT_DECLS;
  16473. #if !defined(NO_DES3) && defined(WOLFSSL_DES_ECB)
  16474. Des3 des;
  16475. byte cipher[24];
  16476. word32 cipherSz = sizeof(cipher);
  16477. const byte key[] = {
  16478. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  16479. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  16480. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  16481. };
  16482. const byte iv[] = {
  16483. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  16484. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  16485. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  16486. };
  16487. const byte vector[] = { /* "Now is the time for all " w/o trailing 0 */
  16488. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  16489. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  16490. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  16491. };
  16492. XMEMSET(&des, 0, sizeof(Des3));
  16493. ExpectIntEQ(wc_Des3Init(&des, NULL, INVALID_DEVID), 0);
  16494. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, DES_ENCRYPTION), 0);
  16495. /* Bad Cases */
  16496. ExpectIntEQ(wc_Des3_EcbEncrypt(NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16497. ExpectIntEQ(wc_Des3_EcbEncrypt(NULL, cipher, vector, cipherSz),
  16498. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16499. ExpectIntEQ(wc_Des3_EcbEncrypt(&des, 0, vector, cipherSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16500. ExpectIntEQ(wc_Des3_EcbEncrypt(&des, cipher, NULL, cipherSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16501. ExpectIntEQ(wc_Des3_EcbEncrypt(&des, cipher, vector, 0), 0);
  16502. /* Good Cases */
  16503. ExpectIntEQ(wc_Des3_EcbEncrypt(&des, cipher, vector, cipherSz), 0);
  16504. wc_Des3Free(&des);
  16505. #endif
  16506. return EXPECT_RESULT();
  16507. } /* END test_wc_Des3_EcbEncrypt */
  16508. /*
  16509. * Testing wc_Chacha_SetKey() and wc_Chacha_SetIV()
  16510. */
  16511. static int test_wc_Chacha_SetKey(void)
  16512. {
  16513. EXPECT_DECLS;
  16514. #ifdef HAVE_CHACHA
  16515. ChaCha ctx;
  16516. const byte key[] = {
  16517. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16518. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16519. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16520. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  16521. };
  16522. word32 keySz = (word32)(sizeof(key)/sizeof(byte));
  16523. byte cipher[128];
  16524. XMEMSET(cipher, 0, sizeof(cipher));
  16525. ExpectIntEQ(wc_Chacha_SetKey(&ctx, key, keySz), 0);
  16526. /* Test bad args. */
  16527. ExpectIntEQ(wc_Chacha_SetKey(NULL, key, keySz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16528. ExpectIntEQ(wc_Chacha_SetKey(&ctx, key, 18), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16529. ExpectIntEQ(wc_Chacha_SetIV(&ctx, cipher, 0), 0);
  16530. /* Test bad args. */
  16531. ExpectIntEQ(wc_Chacha_SetIV(NULL, cipher, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16532. #endif
  16533. return EXPECT_RESULT();
  16534. } /* END test_wc_Chacha_SetKey */
  16535. /*
  16536. * unit test for wc_Poly1305SetKey()
  16537. */
  16538. static int test_wc_Poly1305SetKey(void)
  16539. {
  16540. EXPECT_DECLS;
  16541. #ifdef HAVE_POLY1305
  16542. Poly1305 ctx;
  16543. const byte key[] =
  16544. {
  16545. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16546. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16547. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16548. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  16549. };
  16550. word32 keySz = (word32)(sizeof(key)/sizeof(byte));
  16551. ExpectIntEQ(wc_Poly1305SetKey(&ctx, key, keySz), 0);
  16552. /* Test bad args. */
  16553. ExpectIntEQ(wc_Poly1305SetKey(NULL, key,keySz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16554. ExpectIntEQ(wc_Poly1305SetKey(&ctx, NULL, keySz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16555. ExpectIntEQ(wc_Poly1305SetKey(&ctx, key, 18), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16556. #endif
  16557. return EXPECT_RESULT();
  16558. } /* END test_wc_Poly1305_SetKey() */
  16559. /*
  16560. * Testing wc_Chacha_Process()
  16561. */
  16562. static int test_wc_Chacha_Process(void)
  16563. {
  16564. EXPECT_DECLS;
  16565. #ifdef HAVE_CHACHA
  16566. ChaCha enc, dec;
  16567. byte cipher[128];
  16568. byte plain[128];
  16569. const byte key[] =
  16570. {
  16571. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16572. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16573. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16574. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  16575. };
  16576. const char* input = "Everybody gets Friday off.";
  16577. word32 keySz = sizeof(key)/sizeof(byte);
  16578. unsigned long int inlen = XSTRLEN(input);
  16579. /* Initialize stack variables. */
  16580. XMEMSET(cipher, 0, 128);
  16581. XMEMSET(plain, 0, 128);
  16582. ExpectIntEQ(wc_Chacha_SetKey(&enc, key, keySz), 0);
  16583. ExpectIntEQ(wc_Chacha_SetKey(&dec, key, keySz), 0);
  16584. ExpectIntEQ(wc_Chacha_SetIV(&enc, cipher, 0), 0);
  16585. ExpectIntEQ(wc_Chacha_SetIV(&dec, cipher, 0), 0);
  16586. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, (byte*)input, (word32)inlen),
  16587. 0);
  16588. ExpectIntEQ(wc_Chacha_Process(&dec, plain, cipher, (word32)inlen), 0);
  16589. ExpectIntEQ(XMEMCMP(input, plain, (int)inlen), 0);
  16590. #if !defined(USE_INTEL_CHACHA_SPEEDUP) && !defined(WOLFSSL_ARMASM)
  16591. /* test checking and using leftovers, currently just in C code */
  16592. ExpectIntEQ(wc_Chacha_SetIV(&enc, cipher, 0), 0);
  16593. ExpectIntEQ(wc_Chacha_SetIV(&dec, cipher, 0), 0);
  16594. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, (byte*)input,
  16595. (word32)inlen - 2), 0);
  16596. ExpectIntEQ(wc_Chacha_Process(&enc, cipher + (inlen - 2),
  16597. (byte*)input + (inlen - 2), 2), 0);
  16598. ExpectIntEQ(wc_Chacha_Process(&dec, plain, (byte*)cipher,
  16599. (word32)inlen - 2), 0);
  16600. ExpectIntEQ(wc_Chacha_Process(&dec, cipher + (inlen - 2),
  16601. (byte*)input + (inlen - 2), 2), 0);
  16602. ExpectIntEQ(XMEMCMP(input, plain, (int)inlen), 0);
  16603. /* check edge cases with counter increment */
  16604. {
  16605. /* expected results collected from wolfSSL 4.3.0 encrypted in one call*/
  16606. const byte expected[] = {
  16607. 0x54,0xB1,0xE2,0xD4,0xA2,0x4D,0x52,0x5F,
  16608. 0x42,0x04,0x89,0x7C,0x6E,0x2D,0xFC,0x2D,
  16609. 0x10,0x25,0xB6,0x92,0x71,0xD5,0xC3,0x20,
  16610. 0xE3,0x0E,0xEC,0xF4,0xD8,0x10,0x70,0x29,
  16611. 0x2D,0x4C,0x2A,0x56,0x21,0xE1,0xC7,0x37,
  16612. 0x0B,0x86,0xF5,0x02,0x8C,0xB8,0xB8,0x38,
  16613. 0x41,0xFD,0xDF,0xD9,0xC3,0xE6,0xC8,0x88,
  16614. 0x06,0x82,0xD4,0x80,0x6A,0x50,0x69,0xD5,
  16615. 0xB9,0xB0,0x2F,0x44,0x36,0x5D,0xDA,0x5E,
  16616. 0xDE,0xF6,0xF5,0xFC,0x44,0xDC,0x07,0x51,
  16617. 0xA7,0x32,0x42,0xDB,0xCC,0xBD,0xE2,0xE5,
  16618. 0x0B,0xB1,0x14,0xFF,0x12,0x80,0x16,0x43,
  16619. 0xE7,0x40,0xD5,0xEA,0xC7,0x3F,0x69,0x07,
  16620. 0x64,0xD4,0x86,0x6C,0xE2,0x1F,0x8F,0x6E,
  16621. 0x35,0x41,0xE7,0xD3,0xB5,0x5D,0xD6,0xD4,
  16622. 0x9F,0x00,0xA9,0xAE,0x3D,0x28,0xA5,0x37,
  16623. 0x80,0x3D,0x11,0x25,0xE2,0xB6,0x99,0xD9,
  16624. 0x9B,0x98,0xE9,0x37,0xB9,0xF8,0xA0,0x04,
  16625. 0xDF,0x13,0x49,0x3F,0x19,0x6A,0x45,0x06,
  16626. 0x21,0xB4,0xC7,0x3B,0x49,0x45,0xB4,0xC8,
  16627. 0x03,0x5B,0x43,0x89,0xBD,0xB3,0x96,0x4B,
  16628. 0x17,0x6F,0x85,0xC6,0xCF,0xA6,0x05,0x35,
  16629. 0x1E,0x25,0x03,0xBB,0x55,0x0A,0xD5,0x54,
  16630. 0x41,0xEA,0xEB,0x50,0x40,0x1B,0x43,0x19,
  16631. 0x59,0x1B,0x0E,0x12,0x3E,0xA2,0x71,0xC3,
  16632. 0x1A,0xA7,0x11,0x50,0x43,0x9D,0x56,0x3B,
  16633. 0x63,0x2F,0x63,0xF1,0x8D,0xAE,0xF3,0x23,
  16634. 0xFA,0x1E,0xD8,0x6A,0xE1,0xB2,0x4B,0xF3,
  16635. 0xB9,0x13,0x7A,0x72,0x2B,0x6D,0xCC,0x41,
  16636. 0x1C,0x69,0x7C,0xCD,0x43,0x6F,0xE4,0xE2,
  16637. 0x38,0x99,0xFB,0xC3,0x38,0x92,0x62,0x35,
  16638. 0xC0,0x1D,0x60,0xE4,0x4B,0xDD,0x0C,0x14
  16639. };
  16640. const byte iv2[] = {
  16641. 0x9D,0xED,0xE7,0x0F,0xEC,0x81,0x51,0xD9,
  16642. 0x77,0x39,0x71,0xA6,0x21,0xDF,0xB8,0x93
  16643. };
  16644. byte input2[256];
  16645. int i;
  16646. for (i = 0; i < 256; i++)
  16647. input2[i] = i;
  16648. ExpectIntEQ(wc_Chacha_SetIV(&enc, iv2, 0), 0);
  16649. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, input2, 64), 0);
  16650. ExpectIntEQ(XMEMCMP(expected, cipher, 64), 0);
  16651. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, input2 + 64, 128), 0);
  16652. ExpectIntEQ(XMEMCMP(expected + 64, cipher, 128), 0);
  16653. /* partial */
  16654. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, input2 + 192, 32), 0);
  16655. ExpectIntEQ(XMEMCMP(expected + 192, cipher, 32), 0);
  16656. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, input2 + 224, 32), 0);
  16657. ExpectIntEQ(XMEMCMP(expected + 224, cipher, 32), 0);
  16658. }
  16659. #endif
  16660. /* Test bad args. */
  16661. ExpectIntEQ(wc_Chacha_Process(NULL, cipher, (byte*)input, (word32)inlen),
  16662. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16663. #endif
  16664. return EXPECT_RESULT();
  16665. } /* END test_wc_Chacha_Process */
  16666. /*
  16667. * Testing wc_ChaCha20Poly1305_Encrypt() and wc_ChaCha20Poly1305_Decrypt()
  16668. */
  16669. static int test_wc_ChaCha20Poly1305_aead(void)
  16670. {
  16671. EXPECT_DECLS;
  16672. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  16673. const byte key[] = {
  16674. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  16675. 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  16676. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
  16677. 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f
  16678. };
  16679. const byte plaintext[] = {
  16680. 0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61,
  16681. 0x6e, 0x64, 0x20, 0x47, 0x65, 0x6e, 0x74, 0x6c,
  16682. 0x65, 0x6d, 0x65, 0x6e, 0x20, 0x6f, 0x66, 0x20,
  16683. 0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73,
  16684. 0x73, 0x20, 0x6f, 0x66, 0x20, 0x27, 0x39, 0x39,
  16685. 0x3a, 0x20, 0x49, 0x66, 0x20, 0x49, 0x20, 0x63,
  16686. 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x6f, 0x66, 0x66,
  16687. 0x65, 0x72, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6f,
  16688. 0x6e, 0x6c, 0x79, 0x20, 0x6f, 0x6e, 0x65, 0x20,
  16689. 0x74, 0x69, 0x70, 0x20, 0x66, 0x6f, 0x72, 0x20,
  16690. 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x74, 0x75,
  16691. 0x72, 0x65, 0x2c, 0x20, 0x73, 0x75, 0x6e, 0x73,
  16692. 0x63, 0x72, 0x65, 0x65, 0x6e, 0x20, 0x77, 0x6f,
  16693. 0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, 0x20, 0x69,
  16694. 0x74, 0x2e
  16695. };
  16696. const byte iv[] = {
  16697. 0x07, 0x00, 0x00, 0x00, 0x40, 0x41, 0x42, 0x43,
  16698. 0x44, 0x45, 0x46, 0x47
  16699. };
  16700. const byte aad[] = { /* additional data */
  16701. 0x50, 0x51, 0x52, 0x53, 0xc0, 0xc1, 0xc2, 0xc3,
  16702. 0xc4, 0xc5, 0xc6, 0xc7
  16703. };
  16704. const byte cipher[] = { /* expected output from operation */
  16705. 0xd3, 0x1a, 0x8d, 0x34, 0x64, 0x8e, 0x60, 0xdb,
  16706. 0x7b, 0x86, 0xaf, 0xbc, 0x53, 0xef, 0x7e, 0xc2,
  16707. 0xa4, 0xad, 0xed, 0x51, 0x29, 0x6e, 0x08, 0xfe,
  16708. 0xa9, 0xe2, 0xb5, 0xa7, 0x36, 0xee, 0x62, 0xd6,
  16709. 0x3d, 0xbe, 0xa4, 0x5e, 0x8c, 0xa9, 0x67, 0x12,
  16710. 0x82, 0xfa, 0xfb, 0x69, 0xda, 0x92, 0x72, 0x8b,
  16711. 0x1a, 0x71, 0xde, 0x0a, 0x9e, 0x06, 0x0b, 0x29,
  16712. 0x05, 0xd6, 0xa5, 0xb6, 0x7e, 0xcd, 0x3b, 0x36,
  16713. 0x92, 0xdd, 0xbd, 0x7f, 0x2d, 0x77, 0x8b, 0x8c,
  16714. 0x98, 0x03, 0xae, 0xe3, 0x28, 0x09, 0x1b, 0x58,
  16715. 0xfa, 0xb3, 0x24, 0xe4, 0xfa, 0xd6, 0x75, 0x94,
  16716. 0x55, 0x85, 0x80, 0x8b, 0x48, 0x31, 0xd7, 0xbc,
  16717. 0x3f, 0xf4, 0xde, 0xf0, 0x8e, 0x4b, 0x7a, 0x9d,
  16718. 0xe5, 0x76, 0xd2, 0x65, 0x86, 0xce, 0xc6, 0x4b,
  16719. 0x61, 0x16
  16720. };
  16721. const byte authTag[] = { /* expected output from operation */
  16722. 0x1a, 0xe1, 0x0b, 0x59, 0x4f, 0x09, 0xe2, 0x6a,
  16723. 0x7e, 0x90, 0x2e, 0xcb, 0xd0, 0x60, 0x06, 0x91
  16724. };
  16725. byte generatedCiphertext[272];
  16726. byte generatedPlaintext[272];
  16727. byte generatedAuthTag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE];
  16728. /* Initialize stack variables. */
  16729. XMEMSET(generatedCiphertext, 0, 272);
  16730. XMEMSET(generatedPlaintext, 0, 272);
  16731. /* Test Encrypt */
  16732. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, iv, aad, sizeof(aad),
  16733. plaintext, sizeof(plaintext), generatedCiphertext, generatedAuthTag),
  16734. 0);
  16735. ExpectIntEQ(XMEMCMP(generatedCiphertext, cipher,
  16736. sizeof(cipher)/sizeof(byte)), 0);
  16737. /* Test bad args. */
  16738. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(NULL, iv, aad, sizeof(aad),
  16739. plaintext, sizeof(plaintext), generatedCiphertext, generatedAuthTag),
  16740. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16741. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, NULL, aad, sizeof(aad),
  16742. plaintext, sizeof(plaintext), generatedCiphertext, generatedAuthTag),
  16743. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16744. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, iv, aad, sizeof(aad), NULL,
  16745. sizeof(plaintext), generatedCiphertext, generatedAuthTag),
  16746. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16747. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, iv, aad, sizeof(aad),
  16748. NULL, sizeof(plaintext), generatedCiphertext, generatedAuthTag),
  16749. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16750. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, iv, aad, sizeof(aad),
  16751. plaintext, sizeof(plaintext), NULL, generatedAuthTag), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16752. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, iv, aad, sizeof(aad),
  16753. plaintext, sizeof(plaintext), generatedCiphertext, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16754. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, iv, aad, sizeof(aad), cipher,
  16755. sizeof(cipher), authTag, generatedPlaintext), 0);
  16756. ExpectIntEQ(XMEMCMP(generatedPlaintext, plaintext,
  16757. sizeof(plaintext)/sizeof(byte)), 0);
  16758. /* Test bad args. */
  16759. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(NULL, iv, aad, sizeof(aad), cipher,
  16760. sizeof(cipher), authTag, generatedPlaintext), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16761. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, NULL, aad, sizeof(aad),
  16762. cipher, sizeof(cipher), authTag, generatedPlaintext), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16763. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, iv, aad, sizeof(aad), NULL,
  16764. sizeof(cipher), authTag, generatedPlaintext), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16765. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, iv, aad, sizeof(aad), cipher,
  16766. sizeof(cipher), NULL, generatedPlaintext), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16767. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, iv, aad, sizeof(aad), cipher,
  16768. sizeof(cipher), authTag, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16769. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, iv, aad, sizeof(aad), NULL,
  16770. sizeof(cipher), authTag, generatedPlaintext), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16771. #endif
  16772. return EXPECT_RESULT();
  16773. } /* END test_wc_ChaCha20Poly1305_aead */
  16774. /*
  16775. * Testing function for wc_Rc2SetKey().
  16776. */
  16777. static int test_wc_Rc2SetKey(void)
  16778. {
  16779. EXPECT_DECLS;
  16780. #ifdef WC_RC2
  16781. Rc2 rc2;
  16782. byte key40[] = { 0x01, 0x02, 0x03, 0x04, 0x05 };
  16783. byte iv[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
  16784. /* valid key and IV */
  16785. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, (word32) sizeof(key40) / sizeof(byte),
  16786. iv, 40), 0);
  16787. /* valid key, no IV */
  16788. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, (word32) sizeof(key40) / sizeof(byte),
  16789. NULL, 40), 0);
  16790. /* bad arguments */
  16791. /* null Rc2 struct */
  16792. ExpectIntEQ(wc_Rc2SetKey(NULL, key40, (word32) sizeof(key40) / sizeof(byte),
  16793. iv, 40), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16794. /* null key */
  16795. ExpectIntEQ(wc_Rc2SetKey(&rc2, NULL, (word32) sizeof(key40) / sizeof(byte),
  16796. iv, 40), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16797. /* key size == 0 */
  16798. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, 0, iv, 40), WC_NO_ERR_TRACE(WC_KEY_SIZE_E));
  16799. /* key size > 128 */
  16800. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, 129, iv, 40), WC_NO_ERR_TRACE(WC_KEY_SIZE_E));
  16801. /* effective bits == 0 */
  16802. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, (word32)sizeof(key40) / sizeof(byte),
  16803. iv, 0), WC_NO_ERR_TRACE(WC_KEY_SIZE_E));
  16804. /* effective bits > 1024 */
  16805. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, (word32)sizeof(key40) / sizeof(byte),
  16806. iv, 1025), WC_NO_ERR_TRACE(WC_KEY_SIZE_E));
  16807. #endif
  16808. return EXPECT_RESULT();
  16809. } /* END test_wc_Rc2SetKey */
  16810. /*
  16811. * Testing function for wc_Rc2SetIV().
  16812. */
  16813. static int test_wc_Rc2SetIV(void)
  16814. {
  16815. EXPECT_DECLS;
  16816. #ifdef WC_RC2
  16817. Rc2 rc2;
  16818. byte iv[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
  16819. /* valid IV */
  16820. ExpectIntEQ(wc_Rc2SetIV(&rc2, iv), 0);
  16821. /* valid NULL IV */
  16822. ExpectIntEQ(wc_Rc2SetIV(&rc2, NULL), 0);
  16823. /* bad arguments */
  16824. ExpectIntEQ(wc_Rc2SetIV(NULL, iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16825. ExpectIntEQ(wc_Rc2SetIV(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16826. #endif
  16827. return EXPECT_RESULT();
  16828. } /* END test_wc_Rc2SetIV */
  16829. /*
  16830. * Testing function for wc_Rc2EcbEncrypt() and wc_Rc2EcbDecrypt().
  16831. */
  16832. static int test_wc_Rc2EcbEncryptDecrypt(void)
  16833. {
  16834. EXPECT_DECLS;
  16835. #ifdef WC_RC2
  16836. Rc2 rc2;
  16837. int effectiveKeyBits = 63;
  16838. byte cipher[RC2_BLOCK_SIZE];
  16839. byte plain[RC2_BLOCK_SIZE];
  16840. byte key[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  16841. byte input[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  16842. byte output[] = { 0xeb, 0xb7, 0x73, 0xf9, 0x93, 0x27, 0x8e, 0xff };
  16843. XMEMSET(cipher, 0, sizeof(cipher));
  16844. XMEMSET(plain, 0, sizeof(plain));
  16845. ExpectIntEQ(wc_Rc2SetKey(&rc2, key, (word32) sizeof(key) / sizeof(byte),
  16846. NULL, effectiveKeyBits), 0);
  16847. ExpectIntEQ(wc_Rc2EcbEncrypt(&rc2, cipher, input, RC2_BLOCK_SIZE), 0);
  16848. ExpectIntEQ(XMEMCMP(cipher, output, RC2_BLOCK_SIZE), 0);
  16849. ExpectIntEQ(wc_Rc2EcbDecrypt(&rc2, plain, cipher, RC2_BLOCK_SIZE), 0);
  16850. ExpectIntEQ(XMEMCMP(plain, input, RC2_BLOCK_SIZE), 0);
  16851. /* Rc2EcbEncrypt bad arguments */
  16852. /* null Rc2 struct */
  16853. ExpectIntEQ(wc_Rc2EcbEncrypt(NULL, cipher, input, RC2_BLOCK_SIZE),
  16854. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16855. /* null out buffer */
  16856. ExpectIntEQ(wc_Rc2EcbEncrypt(&rc2, NULL, input, RC2_BLOCK_SIZE),
  16857. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16858. /* null input buffer */
  16859. ExpectIntEQ(wc_Rc2EcbEncrypt(&rc2, cipher, NULL, RC2_BLOCK_SIZE),
  16860. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16861. /* output buffer sz != RC2_BLOCK_SIZE (8) */
  16862. ExpectIntEQ(wc_Rc2EcbEncrypt(&rc2, cipher, input, 7), WC_NO_ERR_TRACE(BUFFER_E));
  16863. /* Rc2EcbDecrypt bad arguments */
  16864. /* null Rc2 struct */
  16865. ExpectIntEQ(wc_Rc2EcbDecrypt(NULL, plain, output, RC2_BLOCK_SIZE),
  16866. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16867. /* null out buffer */
  16868. ExpectIntEQ(wc_Rc2EcbDecrypt(&rc2, NULL, output, RC2_BLOCK_SIZE),
  16869. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16870. /* null input buffer */
  16871. ExpectIntEQ(wc_Rc2EcbDecrypt(&rc2, plain, NULL, RC2_BLOCK_SIZE),
  16872. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16873. /* output buffer sz != RC2_BLOCK_SIZE (8) */
  16874. ExpectIntEQ(wc_Rc2EcbDecrypt(&rc2, plain, output, 7), WC_NO_ERR_TRACE(BUFFER_E));
  16875. #endif
  16876. return EXPECT_RESULT();
  16877. } /* END test_wc_Rc2EcbEncryptDecrypt */
  16878. /*
  16879. * Testing function for wc_Rc2CbcEncrypt() and wc_Rc2CbcDecrypt().
  16880. */
  16881. static int test_wc_Rc2CbcEncryptDecrypt(void)
  16882. {
  16883. EXPECT_DECLS;
  16884. #ifdef WC_RC2
  16885. Rc2 rc2;
  16886. int effectiveKeyBits = 63;
  16887. byte cipher[RC2_BLOCK_SIZE*2];
  16888. byte plain[RC2_BLOCK_SIZE*2];
  16889. /* vector taken from test.c */
  16890. byte key[] = {
  16891. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  16892. };
  16893. byte iv[] = {
  16894. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  16895. };
  16896. byte input[] = {
  16897. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  16898. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  16899. };
  16900. byte output[] = {
  16901. 0xeb, 0xb7, 0x73, 0xf9, 0x93, 0x27, 0x8e, 0xff,
  16902. 0xf0, 0x51, 0x77, 0x8b, 0x65, 0xdb, 0x13, 0x57
  16903. };
  16904. XMEMSET(cipher, 0, sizeof(cipher));
  16905. XMEMSET(plain, 0, sizeof(plain));
  16906. ExpectIntEQ(wc_Rc2SetKey(&rc2, key, (word32) sizeof(key) / sizeof(byte),
  16907. iv, effectiveKeyBits), 0);
  16908. ExpectIntEQ(wc_Rc2CbcEncrypt(&rc2, cipher, input, sizeof(input)), 0);
  16909. ExpectIntEQ(XMEMCMP(cipher, output, sizeof(output)), 0);
  16910. /* reset IV for decrypt */
  16911. ExpectIntEQ(wc_Rc2SetIV(&rc2, iv), 0);
  16912. ExpectIntEQ(wc_Rc2CbcDecrypt(&rc2, plain, cipher, sizeof(cipher)), 0);
  16913. ExpectIntEQ(XMEMCMP(plain, input, sizeof(input)), 0);
  16914. /* Rc2CbcEncrypt bad arguments */
  16915. /* null Rc2 struct */
  16916. ExpectIntEQ(wc_Rc2CbcEncrypt(NULL, cipher, input, sizeof(input)),
  16917. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16918. /* null out buffer */
  16919. ExpectIntEQ(wc_Rc2CbcEncrypt(&rc2, NULL, input, sizeof(input)),
  16920. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16921. /* null input buffer */
  16922. ExpectIntEQ(wc_Rc2CbcEncrypt(&rc2, cipher, NULL, sizeof(input)),
  16923. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16924. /* Rc2CbcDecrypt bad arguments */
  16925. /* in size is 0 */
  16926. ExpectIntEQ(wc_Rc2CbcDecrypt(&rc2, plain, output, 0), 0);
  16927. /* null Rc2 struct */
  16928. ExpectIntEQ(wc_Rc2CbcDecrypt(NULL, plain, output, sizeof(output)),
  16929. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16930. /* null out buffer */
  16931. ExpectIntEQ(wc_Rc2CbcDecrypt(&rc2, NULL, output, sizeof(output)),
  16932. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16933. /* null input buffer */
  16934. ExpectIntEQ(wc_Rc2CbcDecrypt(&rc2, plain, NULL, sizeof(output)),
  16935. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16936. #endif
  16937. return EXPECT_RESULT();
  16938. } /* END test_wc_Rc2CbcEncryptDecrypt */
  16939. /*
  16940. * Testing function for wc_AesSetIV
  16941. */
  16942. static int test_wc_AesSetIV(void)
  16943. {
  16944. int res = TEST_SKIPPED;
  16945. #if !defined(NO_AES) && defined(WOLFSSL_AES_128)
  16946. Aes aes;
  16947. int ret = 0;
  16948. byte key16[] =
  16949. {
  16950. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16951. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  16952. };
  16953. byte iv1[] = "1234567890abcdef";
  16954. byte iv2[] = "0987654321fedcba";
  16955. ret = wc_AesInit(&aes, NULL, INVALID_DEVID);
  16956. if (ret != 0)
  16957. return ret;
  16958. ret = wc_AesSetKey(&aes, key16, (word32) sizeof(key16) / sizeof(byte),
  16959. iv1, AES_ENCRYPTION);
  16960. if (ret == 0) {
  16961. ret = wc_AesSetIV(&aes, iv2);
  16962. }
  16963. /* Test bad args. */
  16964. if (ret == 0) {
  16965. ret = wc_AesSetIV(NULL, iv1);
  16966. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  16967. /* NULL iv should return 0. */
  16968. ret = wc_AesSetIV(&aes, NULL);
  16969. }
  16970. else {
  16971. ret = WOLFSSL_FATAL_ERROR;
  16972. }
  16973. }
  16974. wc_AesFree(&aes);
  16975. res = TEST_RES_CHECK(ret == 0);
  16976. #endif
  16977. return res;
  16978. } /* test_wc_AesSetIV */
  16979. /*
  16980. * Testing function for wc_AesSetKey().
  16981. */
  16982. static int test_wc_AesSetKey(void)
  16983. {
  16984. EXPECT_DECLS;
  16985. #ifndef NO_AES
  16986. Aes aes;
  16987. byte key16[] = {
  16988. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16989. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  16990. };
  16991. #ifdef WOLFSSL_AES_192
  16992. byte key24[] = {
  16993. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  16994. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  16995. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
  16996. };
  16997. #endif
  16998. #ifdef WOLFSSL_AES_256
  16999. byte key32[] = {
  17000. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17001. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17002. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17003. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17004. };
  17005. #endif
  17006. byte badKey16[] = {
  17007. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17008. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65
  17009. };
  17010. byte iv[] = "1234567890abcdef";
  17011. XMEMSET(&aes, 0, sizeof(Aes));
  17012. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  17013. #ifdef WOLFSSL_AES_128
  17014. ExpectIntEQ(wc_AesSetKey(&aes, key16, (word32)sizeof(key16) / sizeof(byte),
  17015. iv, AES_ENCRYPTION), 0);
  17016. #endif
  17017. #ifdef WOLFSSL_AES_192
  17018. ExpectIntEQ(wc_AesSetKey(&aes, key24, (word32)sizeof(key24) / sizeof(byte),
  17019. iv, AES_ENCRYPTION), 0);
  17020. #endif
  17021. #ifdef WOLFSSL_AES_256
  17022. ExpectIntEQ(wc_AesSetKey(&aes, key32, (word32)sizeof(key32) / sizeof(byte),
  17023. iv, AES_ENCRYPTION), 0);
  17024. #endif
  17025. /* Pass in bad args. */
  17026. ExpectIntEQ(wc_AesSetKey(NULL, key16, (word32)sizeof(key16) / sizeof(byte),
  17027. iv, AES_ENCRYPTION), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17028. ExpectIntEQ(wc_AesSetKey(&aes, badKey16,
  17029. (word32)sizeof(badKey16) / sizeof(byte), iv, AES_ENCRYPTION),
  17030. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17031. wc_AesFree(&aes);
  17032. #endif
  17033. return EXPECT_RESULT();
  17034. } /* END test_wc_AesSetKey */
  17035. /*
  17036. * test function for wc_AesCbcEncrypt(), wc_AesCbcDecrypt(),
  17037. * and wc_AesCbcDecryptWithKey()
  17038. */
  17039. static int test_wc_AesCbcEncryptDecrypt(void)
  17040. {
  17041. EXPECT_DECLS;
  17042. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(HAVE_AES_DECRYPT)&& \
  17043. defined(WOLFSSL_AES_256)
  17044. Aes aes;
  17045. byte key32[] = {
  17046. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17047. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17048. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17049. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17050. };
  17051. byte vector[] = { /* Now is the time for all good men w/o trailing 0 */
  17052. 0x4e, 0x6f, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74,
  17053. 0x68, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20,
  17054. 0x66, 0x6f, 0x72, 0x20, 0x61, 0x6c, 0x6c, 0x20,
  17055. 0x67, 0x6f, 0x6f, 0x64, 0x20, 0x6d, 0x65, 0x6e
  17056. };
  17057. byte iv[] = "1234567890abcdef";
  17058. byte enc[sizeof(vector)];
  17059. byte dec[sizeof(vector)];
  17060. byte dec2[sizeof(vector)];
  17061. /* Init stack variables. */
  17062. XMEMSET(&aes, 0, sizeof(Aes));
  17063. XMEMSET(enc, 0, sizeof(enc));
  17064. XMEMSET(dec, 0, sizeof(vector));
  17065. XMEMSET(dec2, 0, sizeof(vector));
  17066. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  17067. ExpectIntEQ(wc_AesSetKey(&aes, key32, AES_BLOCK_SIZE * 2, iv,
  17068. AES_ENCRYPTION), 0);
  17069. ExpectIntEQ(wc_AesCbcEncrypt(&aes, enc, vector, sizeof(vector)), 0);
  17070. /* Re init for decrypt and set flag. */
  17071. ExpectIntEQ(wc_AesSetKey(&aes, key32, AES_BLOCK_SIZE * 2, iv,
  17072. AES_DECRYPTION), 0);
  17073. ExpectIntEQ(wc_AesCbcDecrypt(&aes, dec, enc, sizeof(vector)), 0);
  17074. ExpectIntEQ(XMEMCMP(vector, dec, sizeof(vector)), 0);
  17075. ExpectIntEQ(wc_AesCbcDecryptWithKey(dec2, enc, AES_BLOCK_SIZE, key32,
  17076. sizeof(key32)/sizeof(byte), iv), 0);
  17077. ExpectIntEQ(XMEMCMP(vector, dec2, AES_BLOCK_SIZE), 0);
  17078. /* Pass in bad args */
  17079. ExpectIntEQ(wc_AesCbcEncrypt(NULL, enc, vector, sizeof(vector)),
  17080. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17081. ExpectIntEQ(wc_AesCbcEncrypt(&aes, NULL, vector, sizeof(vector)),
  17082. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17083. ExpectIntEQ(wc_AesCbcEncrypt(&aes, enc, NULL, sizeof(vector)),
  17084. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17085. #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS
  17086. ExpectIntEQ(wc_AesCbcEncrypt(&aes, enc, vector, sizeof(vector) - 1),
  17087. WC_NO_ERR_TRACE(BAD_LENGTH_E));
  17088. #endif
  17089. #if defined(HAVE_FIPS) && defined(HAVE_FIPS_VERSION) && \
  17090. (HAVE_FIPS_VERSION == 2) && defined(WOLFSSL_AESNI)
  17091. fprintf(stderr, "Zero length inputs not supported with AESNI in FIPS "
  17092. "mode (v2), skip test");
  17093. #else
  17094. /* Test passing in size of 0 */
  17095. XMEMSET(enc, 0, sizeof(enc));
  17096. ExpectIntEQ(wc_AesCbcEncrypt(&aes, enc, vector, 0), 0);
  17097. /* Check enc was not modified */
  17098. {
  17099. int i;
  17100. for (i = 0; i < (int)sizeof(enc); i++)
  17101. ExpectIntEQ(enc[i], 0);
  17102. }
  17103. #endif
  17104. ExpectIntEQ(wc_AesCbcDecrypt(NULL, dec, enc, AES_BLOCK_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17105. ExpectIntEQ(wc_AesCbcDecrypt(&aes, NULL, enc, AES_BLOCK_SIZE),
  17106. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17107. ExpectIntEQ(wc_AesCbcDecrypt(&aes, dec, NULL, AES_BLOCK_SIZE),
  17108. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17109. #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS
  17110. ExpectIntEQ(wc_AesCbcDecrypt(&aes, dec, enc, AES_BLOCK_SIZE * 2 - 1),
  17111. WC_NO_ERR_TRACE(BAD_LENGTH_E));
  17112. #else
  17113. ExpectIntEQ(wc_AesCbcDecrypt(&aes, dec, enc, AES_BLOCK_SIZE * 2 - 1),
  17114. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17115. #endif
  17116. /* Test passing in size of 0 */
  17117. XMEMSET(dec, 0, sizeof(dec));
  17118. ExpectIntEQ(wc_AesCbcDecrypt(&aes, dec, enc, 0), 0);
  17119. /* Check dec was not modified */
  17120. {
  17121. int i;
  17122. for (i = 0; i < (int)sizeof(dec); i++)
  17123. ExpectIntEQ(dec[i], 0);
  17124. }
  17125. ExpectIntEQ(wc_AesCbcDecryptWithKey(NULL, enc, AES_BLOCK_SIZE,
  17126. key32, sizeof(key32)/sizeof(byte), iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17127. ExpectIntEQ(wc_AesCbcDecryptWithKey(dec2, NULL, AES_BLOCK_SIZE,
  17128. key32, sizeof(key32)/sizeof(byte), iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17129. ExpectIntEQ(wc_AesCbcDecryptWithKey(dec2, enc, AES_BLOCK_SIZE,
  17130. NULL, sizeof(key32)/sizeof(byte), iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17131. ExpectIntEQ(wc_AesCbcDecryptWithKey(dec2, enc, AES_BLOCK_SIZE,
  17132. key32, sizeof(key32)/sizeof(byte), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17133. wc_AesFree(&aes);
  17134. #endif
  17135. return EXPECT_RESULT();
  17136. } /* END test_wc_AesCbcEncryptDecrypt */
  17137. /*
  17138. * Testing wc_AesCtrEncrypt and wc_AesCtrDecrypt
  17139. */
  17140. static int test_wc_AesCtrEncryptDecrypt(void)
  17141. {
  17142. EXPECT_DECLS;
  17143. #if !defined(NO_AES) && defined(WOLFSSL_AES_COUNTER) && defined(WOLFSSL_AES_256)
  17144. Aes aesEnc;
  17145. Aes aesDec;
  17146. byte key32[] = {
  17147. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17148. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17149. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17150. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17151. };
  17152. byte vector[] = { /* Now is the time for all w/o trailing 0 */
  17153. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  17154. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  17155. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  17156. };
  17157. byte iv[] = "1234567890abcdef";
  17158. byte enc[AES_BLOCK_SIZE * 2];
  17159. byte dec[AES_BLOCK_SIZE * 2];
  17160. /* Init stack variables. */
  17161. XMEMSET(&aesEnc, 0, sizeof(Aes));
  17162. XMEMSET(&aesDec, 0, sizeof(Aes));
  17163. XMEMSET(enc, 0, AES_BLOCK_SIZE * 2);
  17164. XMEMSET(dec, 0, AES_BLOCK_SIZE * 2);
  17165. ExpectIntEQ(wc_AesInit(&aesEnc, NULL, INVALID_DEVID), 0);
  17166. ExpectIntEQ(wc_AesInit(&aesDec, NULL, INVALID_DEVID), 0);
  17167. ExpectIntEQ(wc_AesSetKey(&aesEnc, key32, AES_BLOCK_SIZE * 2, iv,
  17168. AES_ENCRYPTION), 0);
  17169. ExpectIntEQ(wc_AesCtrEncrypt(&aesEnc, enc, vector,
  17170. sizeof(vector)/sizeof(byte)), 0);
  17171. /* Decrypt with wc_AesCtrEncrypt() */
  17172. ExpectIntEQ(wc_AesSetKey(&aesDec, key32, AES_BLOCK_SIZE * 2, iv,
  17173. AES_ENCRYPTION), 0);
  17174. ExpectIntEQ(wc_AesCtrEncrypt(&aesDec, dec, enc, sizeof(enc)/sizeof(byte)),
  17175. 0);
  17176. ExpectIntEQ(XMEMCMP(vector, dec, sizeof(vector)), 0);
  17177. /* Test bad args. */
  17178. ExpectIntEQ(wc_AesCtrEncrypt(NULL, dec, enc, sizeof(enc)/sizeof(byte)),
  17179. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17180. ExpectIntEQ(wc_AesCtrEncrypt(&aesDec, NULL, enc, sizeof(enc)/sizeof(byte)),
  17181. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17182. ExpectIntEQ(wc_AesCtrEncrypt(&aesDec, dec, NULL, sizeof(enc)/sizeof(byte)),
  17183. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17184. wc_AesFree(&aesEnc);
  17185. wc_AesFree(&aesDec);
  17186. #endif
  17187. return EXPECT_RESULT();
  17188. } /* END test_wc_AesCtrEncryptDecrypt */
  17189. /*
  17190. * test function for wc_AesGcmSetKey()
  17191. */
  17192. static int test_wc_AesGcmSetKey(void)
  17193. {
  17194. EXPECT_DECLS;
  17195. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  17196. Aes aes;
  17197. #ifdef WOLFSSL_AES_128
  17198. byte key16[] = {
  17199. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17200. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17201. };
  17202. #endif
  17203. #ifdef WOLFSSL_AES_192
  17204. byte key24[] = {
  17205. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17206. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17207. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
  17208. };
  17209. #endif
  17210. #ifdef WOLFSSL_AES_256
  17211. byte key32[] = {
  17212. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17213. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17214. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17215. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17216. };
  17217. #endif
  17218. byte badKey16[] = {
  17219. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17220. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65
  17221. };
  17222. byte badKey24[] = {
  17223. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17224. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17225. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36
  17226. };
  17227. byte badKey32[] = {
  17228. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x37, 0x37,
  17229. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17230. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17231. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65
  17232. };
  17233. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  17234. #ifdef WOLFSSL_AES_128
  17235. ExpectIntEQ(wc_AesGcmSetKey(&aes, key16, sizeof(key16)/sizeof(byte)), 0);
  17236. #endif
  17237. #ifdef WOLFSSL_AES_192
  17238. ExpectIntEQ(wc_AesGcmSetKey(&aes, key24, sizeof(key24)/sizeof(byte)), 0);
  17239. #endif
  17240. #ifdef WOLFSSL_AES_256
  17241. ExpectIntEQ(wc_AesGcmSetKey(&aes, key32, sizeof(key32)/sizeof(byte)), 0);
  17242. #endif
  17243. /* Pass in bad args. */
  17244. ExpectIntEQ(wc_AesGcmSetKey(&aes, badKey16, sizeof(badKey16)/sizeof(byte)),
  17245. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17246. ExpectIntEQ(wc_AesGcmSetKey(&aes, badKey24, sizeof(badKey24)/sizeof(byte)),
  17247. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17248. ExpectIntEQ(wc_AesGcmSetKey(&aes, badKey32, sizeof(badKey32)/sizeof(byte)),
  17249. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17250. wc_AesFree(&aes);
  17251. #endif
  17252. return EXPECT_RESULT();
  17253. } /* END test_wc_AesGcmSetKey */
  17254. /*
  17255. * test function for wc_AesGcmEncrypt and wc_AesGcmDecrypt
  17256. */
  17257. static int test_wc_AesGcmEncryptDecrypt(void)
  17258. {
  17259. EXPECT_DECLS;
  17260. /* WOLFSSL_AFALG requires 12 byte IV */
  17261. #if !defined(NO_AES) && defined(HAVE_AESGCM) && defined(WOLFSSL_AES_256) && \
  17262. !defined(WOLFSSL_AFALG) && !defined(WOLFSSL_DEVCRYPTO_AES)
  17263. Aes aes;
  17264. byte key32[] = {
  17265. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17266. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17267. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17268. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17269. };
  17270. byte vector[] = { /* Now is the time for all w/o trailing 0 */
  17271. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  17272. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  17273. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  17274. };
  17275. const byte a[] = {
  17276. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  17277. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  17278. 0xab, 0xad, 0xda, 0xd2
  17279. };
  17280. byte iv[] = "1234567890a";
  17281. byte longIV[] = "1234567890abcdefghij";
  17282. byte enc[sizeof(vector)];
  17283. byte resultT[AES_BLOCK_SIZE];
  17284. byte dec[sizeof(vector)];
  17285. /* Init stack variables. */
  17286. XMEMSET(&aes, 0, sizeof(Aes));
  17287. XMEMSET(enc, 0, sizeof(vector));
  17288. XMEMSET(dec, 0, sizeof(vector));
  17289. XMEMSET(resultT, 0, AES_BLOCK_SIZE);
  17290. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  17291. ExpectIntEQ(wc_AesGcmSetKey(&aes, key32, sizeof(key32)/sizeof(byte)), 0);
  17292. ExpectIntEQ(wc_AesGcmEncrypt(&aes, enc, vector, sizeof(vector), iv,
  17293. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)), 0);
  17294. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(vector), iv,
  17295. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)), 0);
  17296. ExpectIntEQ(XMEMCMP(vector, dec, sizeof(vector)), 0);
  17297. /* Test bad args for wc_AesGcmEncrypt and wc_AesGcmDecrypt */
  17298. ExpectIntEQ(wc_AesGcmEncrypt(NULL, enc, vector, sizeof(vector), iv,
  17299. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  17300. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17301. ExpectIntEQ(wc_AesGcmEncrypt(&aes, enc, vector, sizeof(vector), iv,
  17302. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT) + 1, a, sizeof(a)),
  17303. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17304. ExpectIntEQ(wc_AesGcmEncrypt(&aes, enc, vector, sizeof(vector), iv,
  17305. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT) - 5, a, sizeof(a)),
  17306. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17307. #if (defined(HAVE_FIPS) && defined(HAVE_FIPS_VERSION) && \
  17308. (HAVE_FIPS_VERSION == 2)) || defined(HAVE_SELFTEST) || \
  17309. defined(WOLFSSL_AES_GCM_FIXED_IV_AAD)
  17310. /* FIPS does not check the lower bound of ivSz */
  17311. #else
  17312. ExpectIntEQ(wc_AesGcmEncrypt(&aes, enc, vector, sizeof(vector), iv, 0,
  17313. resultT, sizeof(resultT), a, sizeof(a)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17314. #endif
  17315. /* This case is now considered good. Long IVs are now allowed.
  17316. * Except for the original FIPS release, it still has an upper
  17317. * bound on the IV length. */
  17318. #if (!defined(HAVE_FIPS) || \
  17319. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))) && \
  17320. !defined(WOLFSSL_AES_GCM_FIXED_IV_AAD)
  17321. ExpectIntEQ(wc_AesGcmEncrypt(&aes, enc, vector, sizeof(vector), longIV,
  17322. sizeof(longIV)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  17323. 0);
  17324. #else
  17325. (void)longIV;
  17326. #endif /* Old FIPS */
  17327. /* END wc_AesGcmEncrypt */
  17328. #ifdef HAVE_AES_DECRYPT
  17329. ExpectIntEQ(wc_AesGcmDecrypt(NULL, dec, enc, sizeof(enc)/sizeof(byte), iv,
  17330. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  17331. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17332. ExpectIntEQ(wc_AesGcmDecrypt(&aes, NULL, enc, sizeof(enc)/sizeof(byte), iv,
  17333. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  17334. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17335. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, NULL, sizeof(enc)/sizeof(byte), iv,
  17336. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  17337. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17338. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(enc)/sizeof(byte), NULL,
  17339. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  17340. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17341. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(enc)/sizeof(byte), iv,
  17342. sizeof(iv)/sizeof(byte), NULL, sizeof(resultT), a, sizeof(a)),
  17343. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17344. #if (defined(HAVE_FIPS) && FIPS_VERSION_LE(2,0) && defined(WOLFSSL_ARMASM))
  17345. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(enc)/sizeof(byte), iv,
  17346. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT) + 1, a, sizeof(a)),
  17347. WC_NO_ERR_TRACE(AES_GCM_AUTH_E));
  17348. #else
  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(BAD_FUNC_ARG));
  17352. #endif
  17353. #if ((defined(HAVE_FIPS) && defined(HAVE_FIPS_VERSION) && \
  17354. (HAVE_FIPS_VERSION == 2)) || defined(HAVE_SELFTEST)) && \
  17355. !defined(WOLFSSL_AES_GCM_FIXED_IV_AAD)
  17356. /* FIPS does not check the lower bound of ivSz */
  17357. #else
  17358. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(enc)/sizeof(byte),
  17359. iv, 0, resultT, sizeof(resultT), a, sizeof(a)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17360. #endif
  17361. #endif /* HAVE_AES_DECRYPT */
  17362. wc_AesFree(&aes);
  17363. #endif
  17364. return EXPECT_RESULT();
  17365. } /* END test_wc_AesGcmEncryptDecrypt */
  17366. /*
  17367. * test function for mixed (one-shot encrpytion + stream decryption) AES GCM
  17368. * using a long IV (older FIPS does NOT support long IVs). Relates to zd15423
  17369. */
  17370. static int test_wc_AesGcmMixedEncDecLongIV(void)
  17371. {
  17372. EXPECT_DECLS;
  17373. #if (!defined(HAVE_FIPS) || \
  17374. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))) && \
  17375. !defined(NO_AES) && defined(HAVE_AESGCM) && defined(WOLFSSL_AESGCM_STREAM)
  17376. const byte key[] = {
  17377. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17378. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17379. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17380. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17381. };
  17382. const byte in[] = {
  17383. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  17384. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  17385. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  17386. };
  17387. const byte aad[] = {
  17388. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  17389. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  17390. 0xab, 0xad, 0xda, 0xd2
  17391. };
  17392. Aes aesEnc;
  17393. Aes aesDec;
  17394. byte iv[] = "1234567890abcdefghij";
  17395. byte out[sizeof(in)];
  17396. byte plain[sizeof(in)];
  17397. byte tag[AES_BLOCK_SIZE];
  17398. XMEMSET(&aesEnc, 0, sizeof(Aes));
  17399. XMEMSET(&aesDec, 0, sizeof(Aes));
  17400. XMEMSET(out, 0, sizeof(out));
  17401. XMEMSET(plain, 0, sizeof(plain));
  17402. XMEMSET(tag, 0, sizeof(tag));
  17403. /* Perform one-shot encryption using long IV */
  17404. ExpectIntEQ(wc_AesInit(&aesEnc, NULL, INVALID_DEVID), 0);
  17405. ExpectIntEQ(wc_AesGcmSetKey(&aesEnc, key, sizeof(key)), 0);
  17406. ExpectIntEQ(wc_AesGcmEncrypt(&aesEnc, out, in, sizeof(in), iv, sizeof(iv),
  17407. tag, sizeof(tag), aad, sizeof(aad)), 0);
  17408. /* Perform streaming decryption using long IV */
  17409. ExpectIntEQ(wc_AesInit(&aesDec, NULL, INVALID_DEVID), 0);
  17410. ExpectIntEQ(wc_AesGcmInit(&aesDec, key, sizeof(key), iv, sizeof(iv)), 0);
  17411. ExpectIntEQ(wc_AesGcmDecryptUpdate(&aesDec, plain, out, sizeof(out), aad,
  17412. sizeof(aad)), 0);
  17413. ExpectIntEQ(wc_AesGcmDecryptFinal(&aesDec, tag, sizeof(tag)), 0);
  17414. ExpectIntEQ(XMEMCMP(plain, in, sizeof(in)), 0);
  17415. /* Free resources */
  17416. wc_AesFree(&aesEnc);
  17417. wc_AesFree(&aesDec);
  17418. #endif
  17419. return EXPECT_RESULT();
  17420. } /* END wc_AesGcmMixedEncDecLongIV */
  17421. /*
  17422. * unit test for wc_GmacSetKey()
  17423. */
  17424. static int test_wc_GmacSetKey(void)
  17425. {
  17426. EXPECT_DECLS;
  17427. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  17428. Gmac gmac;
  17429. byte key16[] = {
  17430. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17431. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17432. };
  17433. #ifdef WOLFSSL_AES_192
  17434. byte key24[] = {
  17435. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17436. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17437. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
  17438. };
  17439. #endif
  17440. #ifdef WOLFSSL_AES_256
  17441. byte key32[] = {
  17442. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17443. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17444. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17445. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17446. };
  17447. #endif
  17448. byte badKey16[] = {
  17449. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17450. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x66
  17451. };
  17452. byte badKey24[] = {
  17453. 0x30, 0x31, 0x32, 0x33, 0x34, 0x36, 0x37,
  17454. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17455. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
  17456. };
  17457. byte badKey32[] = {
  17458. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17459. 0x38, 0x39, 0x61, 0x62, 0x64, 0x65, 0x66,
  17460. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17461. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17462. };
  17463. XMEMSET(&gmac, 0, sizeof(Gmac));
  17464. ExpectIntEQ(wc_AesInit(&gmac.aes, NULL, INVALID_DEVID), 0);
  17465. #ifdef WOLFSSL_AES_128
  17466. ExpectIntEQ(wc_GmacSetKey(&gmac, key16, sizeof(key16)/sizeof(byte)), 0);
  17467. #endif
  17468. #ifdef WOLFSSL_AES_192
  17469. ExpectIntEQ(wc_GmacSetKey(&gmac, key24, sizeof(key24)/sizeof(byte)), 0);
  17470. #endif
  17471. #ifdef WOLFSSL_AES_256
  17472. ExpectIntEQ(wc_GmacSetKey(&gmac, key32, sizeof(key32)/sizeof(byte)), 0);
  17473. #endif
  17474. /* Pass in bad args. */
  17475. ExpectIntEQ(wc_GmacSetKey(NULL, key16, sizeof(key16)/sizeof(byte)),
  17476. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17477. ExpectIntEQ(wc_GmacSetKey(&gmac, NULL, sizeof(key16)/sizeof(byte)),
  17478. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17479. ExpectIntEQ(wc_GmacSetKey(&gmac, badKey16, sizeof(badKey16)/sizeof(byte)),
  17480. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17481. ExpectIntEQ(wc_GmacSetKey(&gmac, badKey24, sizeof(badKey24)/sizeof(byte)),
  17482. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17483. ExpectIntEQ(wc_GmacSetKey(&gmac, badKey32, sizeof(badKey32)/sizeof(byte)),
  17484. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17485. wc_AesFree(&gmac.aes);
  17486. #endif
  17487. return EXPECT_RESULT();
  17488. } /* END test_wc_GmacSetKey */
  17489. /*
  17490. * unit test for wc_GmacUpdate
  17491. */
  17492. static int test_wc_GmacUpdate(void)
  17493. {
  17494. EXPECT_DECLS;
  17495. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  17496. Gmac gmac;
  17497. #ifdef WOLFSSL_AES_128
  17498. const byte key16[] = {
  17499. 0x89, 0xc9, 0x49, 0xe9, 0xc8, 0x04, 0xaf, 0x01,
  17500. 0x4d, 0x56, 0x04, 0xb3, 0x94, 0x59, 0xf2, 0xc8
  17501. };
  17502. #endif
  17503. #ifdef WOLFSSL_AES_192
  17504. byte key24[] = {
  17505. 0x41, 0xc5, 0xda, 0x86, 0x67, 0xef, 0x72, 0x52,
  17506. 0x20, 0xff, 0xe3, 0x9a, 0xe0, 0xac, 0x59, 0x0a,
  17507. 0xc9, 0xfc, 0xa7, 0x29, 0xab, 0x60, 0xad, 0xa0
  17508. };
  17509. #endif
  17510. #ifdef WOLFSSL_AES_256
  17511. byte key32[] = {
  17512. 0x78, 0xdc, 0x4e, 0x0a, 0xaf, 0x52, 0xd9, 0x35,
  17513. 0xc3, 0xc0, 0x1e, 0xea, 0x57, 0x42, 0x8f, 0x00,
  17514. 0xca, 0x1f, 0xd4, 0x75, 0xf5, 0xda, 0x86, 0xa4,
  17515. 0x9c, 0x8d, 0xd7, 0x3d, 0x68, 0xc8, 0xe2, 0x23
  17516. };
  17517. #endif
  17518. #ifdef WOLFSSL_AES_128
  17519. const byte authIn[] = {
  17520. 0x82, 0xad, 0xcd, 0x63, 0x8d, 0x3f, 0xa9, 0xd9,
  17521. 0xf3, 0xe8, 0x41, 0x00, 0xd6, 0x1e, 0x07, 0x77
  17522. };
  17523. #endif
  17524. #ifdef WOLFSSL_AES_192
  17525. const byte authIn2[] = {
  17526. 0x8b, 0x5c, 0x12, 0x4b, 0xef, 0x6e, 0x2f, 0x0f,
  17527. 0xe4, 0xd8, 0xc9, 0x5c, 0xd5, 0xfa, 0x4c, 0xf1
  17528. };
  17529. #endif
  17530. const byte authIn3[] = {
  17531. 0xb9, 0x6b, 0xaa, 0x8c, 0x1c, 0x75, 0xa6, 0x71,
  17532. 0xbf, 0xb2, 0xd0, 0x8d, 0x06, 0xbe, 0x5f, 0x36
  17533. };
  17534. #ifdef WOLFSSL_AES_128
  17535. const byte tag1[] = { /* Known. */
  17536. 0x88, 0xdb, 0x9d, 0x62, 0x17, 0x2e, 0xd0, 0x43,
  17537. 0xaa, 0x10, 0xf1, 0x6d, 0x22, 0x7d, 0xc4, 0x1b
  17538. };
  17539. #endif
  17540. #ifdef WOLFSSL_AES_192
  17541. const byte tag2[] = { /* Known */
  17542. 0x20, 0x4b, 0xdb, 0x1b, 0xd6, 0x21, 0x54, 0xbf,
  17543. 0x08, 0x92, 0x2a, 0xaa, 0x54, 0xee, 0xd7, 0x05
  17544. };
  17545. #endif
  17546. const byte tag3[] = { /* Known */
  17547. 0x3e, 0x5d, 0x48, 0x6a, 0xa2, 0xe3, 0x0b, 0x22,
  17548. 0xe0, 0x40, 0xb8, 0x57, 0x23, 0xa0, 0x6e, 0x76
  17549. };
  17550. #ifdef WOLFSSL_AES_128
  17551. const byte iv[] = {
  17552. 0xd1, 0xb1, 0x04, 0xc8, 0x15, 0xbf, 0x1e, 0x94,
  17553. 0xe2, 0x8c, 0x8f, 0x16
  17554. };
  17555. #endif
  17556. #ifdef WOLFSSL_AES_192
  17557. const byte iv2[] = {
  17558. 0x05, 0xad, 0x13, 0xa5, 0xe2, 0xc2, 0xab, 0x66,
  17559. 0x7e, 0x1a, 0x6f, 0xbc
  17560. };
  17561. #endif
  17562. const byte iv3[] = {
  17563. 0xd7, 0x9c, 0xf2, 0x2d, 0x50, 0x4c, 0xc7, 0x93,
  17564. 0xc3, 0xfb, 0x6c, 0x8a
  17565. };
  17566. byte tagOut[16];
  17567. byte tagOut2[24];
  17568. byte tagOut3[32];
  17569. /* Init stack variables. */
  17570. XMEMSET(&gmac, 0, sizeof(Gmac));
  17571. XMEMSET(tagOut, 0, sizeof(tagOut));
  17572. XMEMSET(tagOut2, 0, sizeof(tagOut2));
  17573. XMEMSET(tagOut3, 0, sizeof(tagOut3));
  17574. #ifdef WOLFSSL_AES_128
  17575. ExpectIntEQ(wc_AesInit(&gmac.aes, NULL, INVALID_DEVID), 0);
  17576. ExpectIntEQ(wc_GmacSetKey(&gmac, key16, sizeof(key16)), 0);
  17577. ExpectIntEQ(wc_GmacUpdate(&gmac, iv, sizeof(iv), authIn, sizeof(authIn),
  17578. tagOut, sizeof(tag1)), 0);
  17579. ExpectIntEQ(XMEMCMP(tag1, tagOut, sizeof(tag1)), 0);
  17580. wc_AesFree(&gmac.aes);
  17581. #endif
  17582. #ifdef WOLFSSL_AES_192
  17583. ExpectNotNull(XMEMSET(&gmac, 0, sizeof(Gmac)));
  17584. ExpectIntEQ(wc_AesInit(&gmac.aes, HEAP_HINT, INVALID_DEVID), 0);
  17585. ExpectIntEQ(wc_GmacSetKey(&gmac, key24, sizeof(key24)/sizeof(byte)), 0);
  17586. ExpectIntEQ(wc_GmacUpdate(&gmac, iv2, sizeof(iv2), authIn2, sizeof(authIn2),
  17587. tagOut2, sizeof(tag2)), 0);
  17588. ExpectIntEQ(XMEMCMP(tagOut2, tag2, sizeof(tag2)), 0);
  17589. wc_AesFree(&gmac.aes);
  17590. #endif
  17591. #ifdef WOLFSSL_AES_256
  17592. ExpectNotNull(XMEMSET(&gmac, 0, sizeof(Gmac)));
  17593. ExpectIntEQ(wc_AesInit(&gmac.aes, HEAP_HINT, INVALID_DEVID), 0);
  17594. ExpectIntEQ(wc_GmacSetKey(&gmac, key32, sizeof(key32)/sizeof(byte)), 0);
  17595. ExpectIntEQ(wc_GmacUpdate(&gmac, iv3, sizeof(iv3), authIn3, sizeof(authIn3),
  17596. tagOut3, sizeof(tag3)), 0);
  17597. ExpectIntEQ(XMEMCMP(tag3, tagOut3, sizeof(tag3)), 0);
  17598. wc_AesFree(&gmac.aes);
  17599. #endif
  17600. /* Pass bad args. */
  17601. ExpectIntEQ(wc_AesInit(&gmac.aes, NULL, INVALID_DEVID), 0);
  17602. ExpectIntEQ(wc_GmacUpdate(NULL, iv3, sizeof(iv3), authIn3, sizeof(authIn3),
  17603. tagOut3, sizeof(tag3)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17604. ExpectIntEQ(wc_GmacUpdate(&gmac, iv3, sizeof(iv3), authIn3, sizeof(authIn3),
  17605. tagOut3, sizeof(tag3) - 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17606. ExpectIntEQ(wc_GmacUpdate(&gmac, iv3, sizeof(iv3), authIn3, sizeof(authIn3),
  17607. tagOut3, sizeof(tag3) + 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17608. wc_AesFree(&gmac.aes);
  17609. #endif
  17610. return EXPECT_RESULT();
  17611. } /* END test_wc_GmacUpdate */
  17612. /*
  17613. * testing wc_CamelliaSetKey
  17614. */
  17615. static int test_wc_CamelliaSetKey(void)
  17616. {
  17617. EXPECT_DECLS;
  17618. #ifdef HAVE_CAMELLIA
  17619. Camellia camellia;
  17620. /*128-bit key*/
  17621. static const byte key16[] = {
  17622. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  17623. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10
  17624. };
  17625. /* 192-bit key */
  17626. static const byte key24[] = {
  17627. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  17628. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  17629. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77
  17630. };
  17631. /* 256-bit key */
  17632. static const byte key32[] = {
  17633. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  17634. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  17635. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  17636. 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
  17637. };
  17638. static const byte iv[] = {
  17639. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  17640. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  17641. };
  17642. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key16, (word32)sizeof(key16), iv),
  17643. 0);
  17644. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key16, (word32)sizeof(key16),
  17645. NULL), 0);
  17646. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key24, (word32)sizeof(key24), iv),
  17647. 0);
  17648. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key24, (word32)sizeof(key24),
  17649. NULL), 0);
  17650. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key32, (word32)sizeof(key32), iv),
  17651. 0);
  17652. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key32, (word32)sizeof(key32),
  17653. NULL), 0);
  17654. /* Bad args. */
  17655. ExpectIntEQ(wc_CamelliaSetKey(NULL, key32, (word32)sizeof(key32), iv),
  17656. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17657. #endif
  17658. return EXPECT_RESULT();
  17659. } /* END test_wc_CammeliaSetKey */
  17660. /*
  17661. * Testing wc_CamelliaSetIV()
  17662. */
  17663. static int test_wc_CamelliaSetIV(void)
  17664. {
  17665. EXPECT_DECLS;
  17666. #ifdef HAVE_CAMELLIA
  17667. Camellia camellia;
  17668. static const byte iv[] = {
  17669. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  17670. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  17671. };
  17672. ExpectIntEQ(wc_CamelliaSetIV(&camellia, iv), 0);
  17673. ExpectIntEQ(wc_CamelliaSetIV(&camellia, NULL), 0);
  17674. /* Bad args. */
  17675. ExpectIntEQ(wc_CamelliaSetIV(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17676. ExpectIntEQ(wc_CamelliaSetIV(NULL, iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17677. #endif
  17678. return EXPECT_RESULT();
  17679. } /* END test_wc_CamelliaSetIV*/
  17680. /*
  17681. * Test wc_CamelliaEncryptDirect and wc_CamelliaDecryptDirect
  17682. */
  17683. static int test_wc_CamelliaEncryptDecryptDirect(void)
  17684. {
  17685. EXPECT_DECLS;
  17686. #ifdef HAVE_CAMELLIA
  17687. Camellia camellia;
  17688. static const byte key24[] = {
  17689. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  17690. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  17691. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77
  17692. };
  17693. static const byte iv[] = {
  17694. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  17695. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  17696. };
  17697. static const byte plainT[] = {
  17698. 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
  17699. 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A
  17700. };
  17701. byte enc[sizeof(plainT)];
  17702. byte dec[sizeof(enc)];
  17703. /* Init stack variables.*/
  17704. XMEMSET(enc, 0, 16);
  17705. XMEMSET(enc, 0, 16);
  17706. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key24, (word32)sizeof(key24), iv),
  17707. 0);
  17708. ExpectIntEQ(wc_CamelliaEncryptDirect(&camellia, enc, plainT), 0);
  17709. ExpectIntEQ(wc_CamelliaDecryptDirect(&camellia, dec, enc), 0);
  17710. ExpectIntEQ(XMEMCMP(plainT, dec, CAMELLIA_BLOCK_SIZE), 0);
  17711. /* Pass bad args. */
  17712. ExpectIntEQ(wc_CamelliaEncryptDirect(NULL, enc, plainT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17713. ExpectIntEQ(wc_CamelliaEncryptDirect(&camellia, NULL, plainT),
  17714. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17715. ExpectIntEQ(wc_CamelliaEncryptDirect(&camellia, enc, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17716. ExpectIntEQ(wc_CamelliaDecryptDirect(NULL, dec, enc), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17717. ExpectIntEQ(wc_CamelliaDecryptDirect(&camellia, NULL, enc), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17718. ExpectIntEQ(wc_CamelliaDecryptDirect(&camellia, dec, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17719. #endif
  17720. return EXPECT_RESULT();
  17721. } /* END test-wc_CamelliaEncryptDecryptDirect */
  17722. /*
  17723. * Testing wc_CamelliaCbcEncrypt and wc_CamelliaCbcDecrypt
  17724. */
  17725. static int test_wc_CamelliaCbcEncryptDecrypt(void)
  17726. {
  17727. EXPECT_DECLS;
  17728. #ifdef HAVE_CAMELLIA
  17729. Camellia camellia;
  17730. static const byte key24[] = {
  17731. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  17732. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  17733. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77
  17734. };
  17735. static const byte plainT[] = {
  17736. 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
  17737. 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A
  17738. };
  17739. byte enc[CAMELLIA_BLOCK_SIZE];
  17740. byte dec[CAMELLIA_BLOCK_SIZE];
  17741. /* Init stack variables. */
  17742. XMEMSET(enc, 0, CAMELLIA_BLOCK_SIZE);
  17743. XMEMSET(enc, 0, CAMELLIA_BLOCK_SIZE);
  17744. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key24, (word32)sizeof(key24),
  17745. NULL), 0);
  17746. ExpectIntEQ(wc_CamelliaCbcEncrypt(&camellia, enc, plainT,
  17747. CAMELLIA_BLOCK_SIZE), 0);
  17748. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key24, (word32)sizeof(key24),
  17749. NULL), 0);
  17750. ExpectIntEQ(wc_CamelliaCbcDecrypt(&camellia, dec, enc, CAMELLIA_BLOCK_SIZE),
  17751. 0);
  17752. ExpectIntEQ(XMEMCMP(plainT, dec, CAMELLIA_BLOCK_SIZE), 0);
  17753. /* Pass in bad args. */
  17754. ExpectIntEQ(wc_CamelliaCbcEncrypt(NULL, enc, plainT, CAMELLIA_BLOCK_SIZE),
  17755. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17756. ExpectIntEQ(wc_CamelliaCbcEncrypt(&camellia, NULL, plainT,
  17757. CAMELLIA_BLOCK_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17758. ExpectIntEQ(wc_CamelliaCbcEncrypt(&camellia, enc, NULL,
  17759. CAMELLIA_BLOCK_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17760. ExpectIntEQ(wc_CamelliaCbcDecrypt(NULL, dec, enc, CAMELLIA_BLOCK_SIZE),
  17761. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17762. ExpectIntEQ(wc_CamelliaCbcDecrypt(&camellia, NULL, enc,
  17763. CAMELLIA_BLOCK_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17764. ExpectIntEQ(wc_CamelliaCbcDecrypt(&camellia, dec, NULL,
  17765. CAMELLIA_BLOCK_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17766. #endif
  17767. return EXPECT_RESULT();
  17768. } /* END test_wc_CamelliaCbcEncryptDecrypt */
  17769. /*
  17770. * Testing wc_Arc4SetKey()
  17771. */
  17772. static int test_wc_Arc4SetKey(void)
  17773. {
  17774. EXPECT_DECLS;
  17775. #ifndef NO_RC4
  17776. Arc4 arc;
  17777. const char* key = "\x01\x23\x45\x67\x89\xab\xcd\xef";
  17778. int keyLen = 8;
  17779. ExpectIntEQ(wc_Arc4SetKey(&arc, (byte*)key, (word32)keyLen), 0);
  17780. /* Test bad args. */
  17781. ExpectIntEQ(wc_Arc4SetKey(NULL, (byte*)key, (word32)keyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17782. ExpectIntEQ(wc_Arc4SetKey(&arc, NULL , (word32)keyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17783. ExpectIntEQ(wc_Arc4SetKey(&arc, (byte*)key, 0 ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17784. #endif
  17785. return EXPECT_RESULT();
  17786. } /* END test_wc_Arc4SetKey */
  17787. /*
  17788. * Testing wc_Arc4Process for ENC/DEC.
  17789. */
  17790. static int test_wc_Arc4Process(void)
  17791. {
  17792. EXPECT_DECLS;
  17793. #ifndef NO_RC4
  17794. Arc4 enc;
  17795. Arc4 dec;
  17796. const char* key = "\x01\x23\x45\x67\x89\xab\xcd\xef";
  17797. int keyLen = 8;
  17798. const char* input = "\x01\x23\x45\x67\x89\xab\xcd\xef";
  17799. byte cipher[8];
  17800. byte plain[8];
  17801. /* Init stack variables */
  17802. XMEMSET(&enc, 0, sizeof(Arc4));
  17803. XMEMSET(&dec, 0, sizeof(Arc4));
  17804. XMEMSET(cipher, 0, sizeof(cipher));
  17805. XMEMSET(plain, 0, sizeof(plain));
  17806. /* Use for async. */
  17807. ExpectIntEQ(wc_Arc4Init(&enc, NULL, INVALID_DEVID), 0);
  17808. ExpectIntEQ(wc_Arc4Init(&dec, NULL, INVALID_DEVID), 0);
  17809. ExpectIntEQ(wc_Arc4SetKey(&enc, (byte*)key, (word32)keyLen), 0);
  17810. ExpectIntEQ(wc_Arc4SetKey(&dec, (byte*)key, (word32)keyLen), 0);
  17811. ExpectIntEQ(wc_Arc4Process(&enc, cipher, (byte*)input, (word32)keyLen), 0);
  17812. ExpectIntEQ(wc_Arc4Process(&dec, plain, cipher, (word32)keyLen), 0);
  17813. ExpectIntEQ(XMEMCMP(plain, input, keyLen), 0);
  17814. /* Bad args. */
  17815. ExpectIntEQ(wc_Arc4Process(NULL, plain, cipher, (word32)keyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17816. ExpectIntEQ(wc_Arc4Process(&dec, NULL, cipher, (word32)keyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17817. ExpectIntEQ(wc_Arc4Process(&dec, plain, NULL, (word32)keyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17818. wc_Arc4Free(&enc);
  17819. wc_Arc4Free(&dec);
  17820. #endif
  17821. return EXPECT_RESULT();
  17822. } /* END test_wc_Arc4Process */
  17823. /*
  17824. * Testing wc_Init RsaKey()
  17825. */
  17826. static int test_wc_InitRsaKey(void)
  17827. {
  17828. EXPECT_DECLS;
  17829. #ifndef NO_RSA
  17830. RsaKey key;
  17831. XMEMSET(&key, 0, sizeof(RsaKey));
  17832. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  17833. /* Test bad args. */
  17834. ExpectIntEQ(wc_InitRsaKey(NULL, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17835. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  17836. #endif
  17837. return EXPECT_RESULT();
  17838. } /* END test_wc_InitRsaKey */
  17839. /*
  17840. * Testing wc_RsaPrivateKeyDecode()
  17841. */
  17842. static int test_wc_RsaPrivateKeyDecode(void)
  17843. {
  17844. EXPECT_DECLS;
  17845. #if !defined(NO_RSA) && (defined(USE_CERT_BUFFERS_1024)\
  17846. || defined(USE_CERT_BUFFERS_2048)) && !defined(HAVE_FIPS)
  17847. RsaKey key;
  17848. byte* tmp = NULL;
  17849. word32 idx = 0;
  17850. int bytes = 0;
  17851. XMEMSET(&key, 0, sizeof(RsaKey));
  17852. ExpectNotNull(tmp = (byte*)XMALLOC(FOURK_BUF, NULL,
  17853. DYNAMIC_TYPE_TMP_BUFFER));
  17854. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  17855. if (tmp != NULL) {
  17856. #ifdef USE_CERT_BUFFERS_1024
  17857. XMEMCPY(tmp, client_key_der_1024, sizeof_client_key_der_1024);
  17858. bytes = sizeof_client_key_der_1024;
  17859. #else
  17860. XMEMCPY(tmp, client_key_der_2048, sizeof_client_key_der_2048);
  17861. bytes = sizeof_client_key_der_2048;
  17862. #endif /* Use cert buffers. */
  17863. }
  17864. ExpectIntEQ(wc_RsaPrivateKeyDecode(tmp, &idx, &key, (word32)bytes), 0);
  17865. /* Test bad args. */
  17866. ExpectIntEQ(wc_RsaPrivateKeyDecode(NULL, &idx, &key, (word32)bytes),
  17867. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17868. ExpectIntEQ(wc_RsaPrivateKeyDecode(tmp, NULL, &key, (word32)bytes),
  17869. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17870. ExpectIntEQ(wc_RsaPrivateKeyDecode(tmp, &idx, NULL, (word32)bytes),
  17871. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17872. XFREE(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  17873. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  17874. #endif
  17875. return EXPECT_RESULT();
  17876. } /* END test_wc_RsaPrivateKeyDecode */
  17877. /*
  17878. * Testing wc_RsaPublicKeyDecode()
  17879. */
  17880. static int test_wc_RsaPublicKeyDecode(void)
  17881. {
  17882. EXPECT_DECLS;
  17883. #if !defined(NO_RSA) && (defined(USE_CERT_BUFFERS_1024)\
  17884. || defined(USE_CERT_BUFFERS_2048)) && !defined(HAVE_FIPS)
  17885. RsaKey keyPub;
  17886. byte* tmp = NULL;
  17887. word32 idx = 0;
  17888. int bytes = 0;
  17889. word32 keySz = 0;
  17890. word32 tstKeySz = 0;
  17891. #if defined(WC_RSA_PSS) && !defined(NO_FILESYSTEM)
  17892. XFILE f = XBADFILE;
  17893. const char* rsaPssPubKey = "./certs/rsapss/ca-rsapss-key.der";
  17894. const char* rsaPssPubKeyNoParams = "./certs/rsapss/ca-3072-rsapss-key.der";
  17895. byte buf[4096];
  17896. #endif
  17897. XMEMSET(&keyPub, 0, sizeof(RsaKey));
  17898. ExpectNotNull(tmp = (byte*)XMALLOC(GEN_BUF, NULL, DYNAMIC_TYPE_TMP_BUFFER));
  17899. ExpectIntEQ(wc_InitRsaKey(&keyPub, HEAP_HINT), 0);
  17900. if (tmp != NULL) {
  17901. #ifdef USE_CERT_BUFFERS_1024
  17902. XMEMCPY(tmp, client_keypub_der_1024, sizeof_client_keypub_der_1024);
  17903. bytes = sizeof_client_keypub_der_1024;
  17904. keySz = 1024;
  17905. #else
  17906. XMEMCPY(tmp, client_keypub_der_2048, sizeof_client_keypub_der_2048);
  17907. bytes = sizeof_client_keypub_der_2048;
  17908. keySz = 2048;
  17909. #endif
  17910. }
  17911. ExpectIntEQ(wc_RsaPublicKeyDecode(tmp, &idx, &keyPub, (word32)bytes), 0);
  17912. /* Pass in bad args. */
  17913. ExpectIntEQ(wc_RsaPublicKeyDecode(NULL, &idx, &keyPub, (word32)bytes),
  17914. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17915. ExpectIntEQ(wc_RsaPublicKeyDecode(tmp, NULL, &keyPub, (word32)bytes),
  17916. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17917. ExpectIntEQ(wc_RsaPublicKeyDecode(tmp, &idx, NULL, (word32)bytes),
  17918. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17919. DoExpectIntEQ(wc_FreeRsaKey(&keyPub), 0);
  17920. /* Test for getting modulus key size */
  17921. idx = 0;
  17922. ExpectIntEQ(wc_RsaPublicKeyDecode_ex(tmp, &idx, (word32)bytes, NULL,
  17923. &tstKeySz, NULL, NULL), 0);
  17924. ExpectIntEQ(tstKeySz, keySz/8);
  17925. #if defined(WC_RSA_PSS) && !defined(NO_FILESYSTEM)
  17926. ExpectTrue((f = XFOPEN(rsaPssPubKey, "rb")) != XBADFILE);
  17927. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  17928. if (f != XBADFILE) {
  17929. XFCLOSE(f);
  17930. f = XBADFILE;
  17931. }
  17932. idx = 0;
  17933. ExpectIntEQ(wc_RsaPublicKeyDecode_ex(buf, &idx, (word32)bytes, NULL, NULL, NULL,
  17934. NULL), 0);
  17935. ExpectTrue((f = XFOPEN(rsaPssPubKeyNoParams, "rb")) != XBADFILE);
  17936. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  17937. if (f != XBADFILE)
  17938. XFCLOSE(f);
  17939. idx = 0;
  17940. ExpectIntEQ(wc_RsaPublicKeyDecode_ex(buf, &idx, (word32)bytes, NULL, NULL, NULL,
  17941. NULL), 0);
  17942. #endif
  17943. XFREE(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  17944. #endif
  17945. return EXPECT_RESULT();
  17946. } /* END test_wc_RsaPublicKeyDecode */
  17947. /*
  17948. * Testing wc_RsaPublicKeyDecodeRaw()
  17949. */
  17950. static int test_wc_RsaPublicKeyDecodeRaw(void)
  17951. {
  17952. EXPECT_DECLS;
  17953. #if !defined(NO_RSA)
  17954. RsaKey key;
  17955. const byte n = 0x23;
  17956. const byte e = 0x03;
  17957. int nSz = sizeof(n);
  17958. int eSz = sizeof(e);
  17959. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  17960. ExpectIntEQ(wc_RsaPublicKeyDecodeRaw(&n, nSz, &e, eSz, &key), 0);
  17961. /* Pass in bad args. */
  17962. ExpectIntEQ(wc_RsaPublicKeyDecodeRaw(NULL, nSz, &e, eSz, &key),
  17963. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17964. ExpectIntEQ(wc_RsaPublicKeyDecodeRaw(&n, nSz, NULL, eSz, &key),
  17965. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17966. ExpectIntEQ(wc_RsaPublicKeyDecodeRaw(&n, nSz, &e, eSz, NULL),
  17967. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17968. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  17969. #endif
  17970. return EXPECT_RESULT();
  17971. } /* END test_wc_RsaPublicKeyDecodeRaw */
  17972. /*
  17973. * Testing wc_RsaPrivateKeyDecodeRaw()
  17974. */
  17975. static int test_wc_RsaPrivateKeyDecodeRaw(void)
  17976. {
  17977. EXPECT_DECLS;
  17978. #if !defined(NO_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) \
  17979. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  17980. RsaKey key;
  17981. const byte n = 33;
  17982. const byte e = 3;
  17983. const byte d = 7;
  17984. const byte u = 2;
  17985. const byte p = 3;
  17986. const byte q = 11;
  17987. const byte dp = 1;
  17988. const byte dq = 7;
  17989. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  17990. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  17991. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  17992. &p, sizeof(p), &q, sizeof(q), NULL, 0,
  17993. NULL, 0, &key), 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), &dp, sizeof(dp),
  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), NULL, 0,
  18001. &dq, sizeof(dq), &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), &dp, sizeof(dp),
  18005. &dq, sizeof(dq), &key), 0);
  18006. /* Pass in bad args. */
  18007. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(NULL, sizeof(n),
  18008. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  18009. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18010. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18011. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, 0,
  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, sizeof(n),
  18016. NULL, 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. &e, 0, &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, sizeof(e), NULL, 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), &d, 0, &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, sizeof(d), &u, sizeof(u),
  18033. NULL, 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. &p, 0, &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, sizeof(p), NULL, 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), &q, 0, &dp, sizeof(dp),
  18046. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18047. #if defined(WOLFSSL_KEY_GEN) || defined(OPENSSL_EXTRA) || !defined(RSA_LOW_MEM)
  18048. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18049. &e, sizeof(e), &d, sizeof(d), &u, 0,
  18050. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18051. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18052. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18053. &e, sizeof(e), &d, sizeof(d), NULL, sizeof(u),
  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), &u, 0,
  18058. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18059. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18060. #endif
  18061. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18062. #endif
  18063. return EXPECT_RESULT();
  18064. } /* END test_wc_RsaPrivateKeyDecodeRaw */
  18065. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18066. /* In FIPS builds, wc_MakeRsaKey() will return an error if it cannot find
  18067. * a probable prime in 5*(modLen/2) attempts. In non-FIPS builds, it keeps
  18068. * trying until it gets a probable prime. */
  18069. #ifdef HAVE_FIPS
  18070. static int MakeRsaKeyRetry(RsaKey* key, int size, long e, WC_RNG* rng)
  18071. {
  18072. int ret;
  18073. for (;;) {
  18074. ret = wc_MakeRsaKey(key, size, e, rng);
  18075. if (ret != WC_NO_ERR_TRACE(PRIME_GEN_E)) break;
  18076. fprintf(stderr, "MakeRsaKey couldn't find prime; "
  18077. "trying again.\n");
  18078. }
  18079. return ret;
  18080. }
  18081. #define MAKE_RSA_KEY(a, b, c, d) MakeRsaKeyRetry(a, b, c, d)
  18082. #else
  18083. #define MAKE_RSA_KEY(a, b, c, d) wc_MakeRsaKey(a, b, c, d)
  18084. #endif
  18085. #endif
  18086. /*
  18087. * Testing wc_MakeRsaKey()
  18088. */
  18089. static int test_wc_MakeRsaKey(void)
  18090. {
  18091. EXPECT_DECLS;
  18092. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18093. RsaKey genKey;
  18094. WC_RNG rng;
  18095. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  18096. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4)) && \
  18097. (defined(RSA_MIN_SIZE) && (RSA_MIN_SIZE <= 1024))
  18098. int bits = 1024;
  18099. #else
  18100. int bits = 2048;
  18101. #endif
  18102. XMEMSET(&genKey, 0, sizeof(RsaKey));
  18103. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18104. ExpectIntEQ(wc_InitRsaKey(&genKey, HEAP_HINT), 0);
  18105. ExpectIntEQ(wc_InitRng(&rng), 0);
  18106. ExpectIntEQ(MAKE_RSA_KEY(&genKey, bits, WC_RSA_EXPONENT, &rng), 0);
  18107. DoExpectIntEQ(wc_FreeRsaKey(&genKey), 0);
  18108. /* Test bad args. */
  18109. ExpectIntEQ(MAKE_RSA_KEY(NULL, bits, WC_RSA_EXPONENT, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18110. ExpectIntEQ(MAKE_RSA_KEY(&genKey, bits, WC_RSA_EXPONENT, NULL),
  18111. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18112. /* e < 3 */
  18113. ExpectIntEQ(MAKE_RSA_KEY(&genKey, bits, 2, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18114. /* e & 1 == 0 */
  18115. ExpectIntEQ(MAKE_RSA_KEY(&genKey, bits, 6, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18116. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18117. #endif
  18118. return EXPECT_RESULT();
  18119. } /* END test_wc_MakeRsaKey */
  18120. /*
  18121. * Test the bounds checking on the cipher text versus the key modulus.
  18122. * 1. Make a new RSA key.
  18123. * 2. Set c to 1.
  18124. * 3. Decrypt c into k. (error)
  18125. * 4. Copy the key modulus to c and sub 1 from the copy.
  18126. * 5. Decrypt c into k. (error)
  18127. * Valid bounds test cases are covered by all the other RSA tests.
  18128. */
  18129. static int test_RsaDecryptBoundsCheck(void)
  18130. {
  18131. EXPECT_DECLS;
  18132. #if !defined(NO_RSA) && defined(WC_RSA_NO_PADDING) && \
  18133. (defined(USE_CERT_BUFFERS_1024) || defined(USE_CERT_BUFFERS_2048)) && \
  18134. defined(WOLFSSL_PUBLIC_MP) && !defined(NO_RSA_BOUNDS_CHECK)
  18135. WC_RNG rng;
  18136. RsaKey key;
  18137. byte flatC[256];
  18138. word32 flatCSz;
  18139. byte out[256];
  18140. word32 outSz = sizeof(out);
  18141. XMEMSET(&key, 0, sizeof(RsaKey));
  18142. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18143. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18144. ExpectIntEQ(wc_InitRng(&rng), 0);
  18145. if (EXPECT_SUCCESS()) {
  18146. const byte* derKey;
  18147. word32 derKeySz;
  18148. word32 idx = 0;
  18149. #ifdef USE_CERT_BUFFERS_1024
  18150. derKey = server_key_der_1024;
  18151. derKeySz = (word32)sizeof_server_key_der_1024;
  18152. flatCSz = 128;
  18153. #else
  18154. derKey = server_key_der_2048;
  18155. derKeySz = (word32)sizeof_server_key_der_2048;
  18156. flatCSz = 256;
  18157. #endif
  18158. ExpectIntEQ(wc_RsaPrivateKeyDecode(derKey, &idx, &key, derKeySz), 0);
  18159. }
  18160. if (EXPECT_SUCCESS()) {
  18161. XMEMSET(flatC, 0, flatCSz);
  18162. flatC[flatCSz-1] = 1;
  18163. ExpectIntEQ(wc_RsaDirect(flatC, flatCSz, out, &outSz, &key,
  18164. RSA_PRIVATE_DECRYPT, &rng), WC_NO_ERR_TRACE(RSA_OUT_OF_RANGE_E));
  18165. if (EXPECT_SUCCESS()) {
  18166. mp_int c;
  18167. ExpectIntEQ(mp_init_copy(&c, &key.n), 0);
  18168. ExpectIntEQ(mp_sub_d(&c, 1, &c), 0);
  18169. ExpectIntEQ(mp_to_unsigned_bin(&c, flatC), 0);
  18170. ExpectIntEQ(wc_RsaDirect(flatC, flatCSz, out, &outSz, &key,
  18171. RSA_PRIVATE_DECRYPT, NULL), WC_NO_ERR_TRACE(RSA_OUT_OF_RANGE_E));
  18172. mp_clear(&c);
  18173. }
  18174. }
  18175. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18176. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18177. #endif
  18178. return EXPECT_RESULT();
  18179. } /* END test_wc_RsaDecryptBoundsCheck */
  18180. /*
  18181. * Testing wc_SetKeyUsage()
  18182. */
  18183. static int test_wc_SetKeyUsage(void)
  18184. {
  18185. EXPECT_DECLS;
  18186. #if !defined(NO_RSA) && defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN) && !defined(HAVE_FIPS)
  18187. Cert myCert;
  18188. ExpectIntEQ(wc_InitCert(&myCert), 0);
  18189. ExpectIntEQ(wc_SetKeyUsage(&myCert, "keyEncipherment,keyAgreement"), 0);
  18190. ExpectIntEQ(wc_SetKeyUsage(&myCert, "digitalSignature,nonRepudiation"), 0);
  18191. ExpectIntEQ(wc_SetKeyUsage(&myCert, "contentCommitment,encipherOnly"), 0);
  18192. ExpectIntEQ(wc_SetKeyUsage(&myCert, "decipherOnly"), 0);
  18193. ExpectIntEQ(wc_SetKeyUsage(&myCert, "cRLSign,keyCertSign"), 0);
  18194. /* Test bad args. */
  18195. ExpectIntEQ(wc_SetKeyUsage(NULL, "decipherOnly"), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18196. ExpectIntEQ(wc_SetKeyUsage(&myCert, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18197. ExpectIntEQ(wc_SetKeyUsage(&myCert, ""), WC_NO_ERR_TRACE(KEYUSAGE_E));
  18198. ExpectIntEQ(wc_SetKeyUsage(&myCert, ","), WC_NO_ERR_TRACE(KEYUSAGE_E));
  18199. ExpectIntEQ(wc_SetKeyUsage(&myCert, "digitalSignature, cRLSign"),
  18200. WC_NO_ERR_TRACE(KEYUSAGE_E));
  18201. #endif
  18202. return EXPECT_RESULT();
  18203. } /* END test_wc_SetKeyUsage */
  18204. /*
  18205. * Testing wc_CheckProbablePrime()
  18206. */
  18207. static int test_wc_CheckProbablePrime(void)
  18208. {
  18209. EXPECT_DECLS;
  18210. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(HAVE_SELFTEST) && \
  18211. !defined(HAVE_FIPS) && defined(WC_RSA_BLINDING)
  18212. #define CHECK_PROBABLE_PRIME_KEY_BITS 2048
  18213. RsaKey key;
  18214. WC_RNG rng;
  18215. byte e[3];
  18216. word32 eSz = (word32)sizeof(e);
  18217. byte n[CHECK_PROBABLE_PRIME_KEY_BITS / 8];
  18218. word32 nSz = (word32)sizeof(n);
  18219. byte d[CHECK_PROBABLE_PRIME_KEY_BITS / 8];
  18220. word32 dSz = (word32)sizeof(d);
  18221. byte p[CHECK_PROBABLE_PRIME_KEY_BITS / 8 / 2];
  18222. word32 pSz = (word32)sizeof(p);
  18223. byte q[CHECK_PROBABLE_PRIME_KEY_BITS / 8 / 2];
  18224. word32 qSz = (word32)sizeof(q);
  18225. int nlen = CHECK_PROBABLE_PRIME_KEY_BITS;
  18226. int* isPrime;
  18227. int test[5];
  18228. isPrime = test;
  18229. XMEMSET(&key, 0, sizeof(RsaKey));
  18230. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18231. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18232. ExpectIntEQ(wc_InitRng(&rng), 0);
  18233. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  18234. ExpectIntEQ(wc_MakeRsaKey(&key, CHECK_PROBABLE_PRIME_KEY_BITS,
  18235. WC_RSA_EXPONENT, &rng), 0);
  18236. PRIVATE_KEY_UNLOCK();
  18237. ExpectIntEQ(wc_RsaExportKey(&key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q,
  18238. &qSz), 0);
  18239. PRIVATE_KEY_LOCK();
  18240. /* Bad cases */
  18241. ExpectIntEQ(wc_CheckProbablePrime(NULL, pSz, q, qSz, e, eSz, nlen, isPrime),
  18242. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18243. ExpectIntEQ(wc_CheckProbablePrime(p, 0, q, qSz, e, eSz, nlen, isPrime),
  18244. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18245. ExpectIntEQ(wc_CheckProbablePrime(p, pSz, NULL, qSz, e, eSz, nlen, isPrime),
  18246. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18247. ExpectIntEQ(wc_CheckProbablePrime(p, pSz, q, 0, e, eSz, nlen, isPrime),
  18248. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18249. ExpectIntEQ(wc_CheckProbablePrime(p, pSz, q, qSz, NULL, eSz, nlen, isPrime),
  18250. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18251. ExpectIntEQ(wc_CheckProbablePrime(p, pSz, q, qSz, e, 0, nlen, isPrime),
  18252. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18253. ExpectIntEQ(wc_CheckProbablePrime(NULL, 0, NULL, 0, NULL, 0, nlen, isPrime),
  18254. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18255. /* Good case */
  18256. ExpectIntEQ(wc_CheckProbablePrime(p, pSz, q, qSz, e, eSz, nlen, isPrime),
  18257. 0);
  18258. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18259. wc_FreeRng(&rng);
  18260. #undef CHECK_PROBABLE_PRIME_KEY_BITS
  18261. #endif
  18262. return EXPECT_RESULT();
  18263. } /* END test_wc_CheckProbablePrime */
  18264. /*
  18265. * Testing wc_RsaPSS_Verify()
  18266. */
  18267. static int test_wc_RsaPSS_Verify(void)
  18268. {
  18269. EXPECT_DECLS;
  18270. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(HAVE_SELFTEST) && \
  18271. !defined(HAVE_FIPS) && defined(WC_RSA_BLINDING) && defined(WC_RSA_PSS)
  18272. RsaKey key;
  18273. WC_RNG rng;
  18274. int sz = 256;
  18275. const char* szMessage = "This is the string to be signed";
  18276. unsigned char pSignature[2048/8]; /* 2048 is RSA_KEY_SIZE */
  18277. unsigned char pDecrypted[2048/8];
  18278. byte* pt = pDecrypted;
  18279. word32 outLen = sizeof(pDecrypted);
  18280. XMEMSET(&key, 0, sizeof(RsaKey));
  18281. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18282. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18283. ExpectIntEQ(wc_InitRng(&rng), 0);
  18284. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  18285. ExpectIntEQ(wc_MakeRsaKey(&key, 2048, WC_RSA_EXPONENT, &rng), 0);
  18286. ExpectIntGT(sz = wc_RsaPSS_Sign((byte*)szMessage,
  18287. (word32)XSTRLEN(szMessage)+1, pSignature, sizeof(pSignature),
  18288. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key, &rng), 0);
  18289. /* Bad cases */
  18290. ExpectIntEQ(wc_RsaPSS_Verify(NULL, (word32)sz, pt, outLen,
  18291. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18292. ExpectIntEQ(wc_RsaPSS_Verify(pSignature, 0, pt, outLen,
  18293. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18294. ExpectIntEQ(wc_RsaPSS_Verify(pSignature, (word32)sz, NULL, outLen,
  18295. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18296. ExpectIntEQ(wc_RsaPSS_Verify(NULL, 0, NULL, outLen,
  18297. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18298. /* Good case */
  18299. ExpectIntGT(wc_RsaPSS_Verify(pSignature, (word32)sz, pt, outLen,
  18300. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), 0);
  18301. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18302. wc_FreeRng(&rng);
  18303. #endif
  18304. return EXPECT_RESULT();
  18305. } /* END test_wc_RsaPSS_Verify */
  18306. /*
  18307. * Testing wc_RsaPSS_VerifyCheck()
  18308. */
  18309. static int test_wc_RsaPSS_VerifyCheck(void)
  18310. {
  18311. EXPECT_DECLS;
  18312. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(HAVE_SELFTEST) && \
  18313. !defined(HAVE_FIPS) && defined(WC_RSA_BLINDING) && defined(WC_RSA_PSS)
  18314. RsaKey key;
  18315. WC_RNG rng;
  18316. int sz = 256; /* 2048/8 */
  18317. byte digest[32];
  18318. word32 digestSz = sizeof(digest);
  18319. unsigned char pSignature[2048/8]; /* 2048 is RSA_KEY_SIZE */
  18320. word32 pSignatureSz = sizeof(pSignature);
  18321. unsigned char pDecrypted[2048/8];
  18322. byte* pt = pDecrypted;
  18323. word32 outLen = sizeof(pDecrypted);
  18324. XMEMSET(&key, 0, sizeof(RsaKey));
  18325. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18326. XMEMSET(digest, 0, sizeof(digest));
  18327. XMEMSET(pSignature, 0, sizeof(pSignature));
  18328. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18329. ExpectIntEQ(wc_InitRng(&rng), 0);
  18330. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  18331. ExpectIntEQ(wc_MakeRsaKey(&key, 2048, WC_RSA_EXPONENT, &rng), 0);
  18332. ExpectTrue((digestSz = (word32)wc_HashGetDigestSize(WC_HASH_TYPE_SHA256)) > 0);
  18333. ExpectIntEQ(wc_Hash(WC_HASH_TYPE_SHA256, pSignature, (word32)sz, digest, digestSz),
  18334. 0);
  18335. ExpectIntGT(sz = wc_RsaPSS_Sign(digest, digestSz, pSignature, pSignatureSz,
  18336. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key, &rng), 0);
  18337. /* Bad cases */
  18338. ExpectIntEQ(wc_RsaPSS_VerifyCheck(NULL, (word32)sz, pt, outLen, digest,
  18339. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18340. ExpectIntEQ(wc_RsaPSS_VerifyCheck(pSignature, 0, pt, outLen, digest,
  18341. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18342. ExpectIntEQ(wc_RsaPSS_VerifyCheck(pSignature, (word32)sz, NULL, outLen, digest,
  18343. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18344. ExpectIntEQ(wc_RsaPSS_VerifyCheck(NULL, 0, NULL, outLen, digest,
  18345. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18346. /* Good case */
  18347. ExpectIntGT(wc_RsaPSS_VerifyCheck(pSignature, (word32)sz, pt, outLen, digest,
  18348. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), 0);
  18349. ExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18350. wc_FreeRng(&rng);
  18351. #endif
  18352. return EXPECT_RESULT();
  18353. } /* END test_wc_RsaPSS_VerifyCheck */
  18354. /*
  18355. * Testing wc_RsaPSS_VerifyCheckInline()
  18356. */
  18357. static int test_wc_RsaPSS_VerifyCheckInline(void)
  18358. {
  18359. EXPECT_DECLS;
  18360. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(HAVE_SELFTEST) && \
  18361. !defined(HAVE_FIPS) && defined(WC_RSA_BLINDING) && defined(WC_RSA_PSS)
  18362. RsaKey key;
  18363. WC_RNG rng;
  18364. int sz = 256;
  18365. byte digest[32];
  18366. word32 digestSz = sizeof(digest);
  18367. unsigned char pSignature[2048/8]; /* 2048 is RSA_KEY_SIZE */
  18368. unsigned char pDecrypted[2048/8];
  18369. byte* pt = pDecrypted;
  18370. XMEMSET(&key, 0, sizeof(RsaKey));
  18371. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18372. XMEMSET(digest, 0, sizeof(digest));
  18373. XMEMSET(pSignature, 0, sizeof(pSignature));
  18374. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18375. ExpectIntEQ(wc_InitRng(&rng), 0);
  18376. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  18377. ExpectIntEQ(wc_MakeRsaKey(&key, 2048, WC_RSA_EXPONENT, &rng), 0);
  18378. ExpectTrue((digestSz = (word32)wc_HashGetDigestSize(WC_HASH_TYPE_SHA256)) > 0);
  18379. ExpectIntEQ(wc_Hash(WC_HASH_TYPE_SHA256, pSignature, (word32)sz, digest, digestSz),
  18380. 0);
  18381. ExpectIntGT(sz = wc_RsaPSS_Sign(digest, digestSz, pSignature,
  18382. sizeof(pSignature), WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key, &rng), 0);
  18383. /* Bad Cases */
  18384. ExpectIntEQ(wc_RsaPSS_VerifyCheckInline(NULL, (word32)sz, &pt, digest,
  18385. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18386. ExpectIntEQ(wc_RsaPSS_VerifyCheckInline(pSignature, 0, NULL, digest,
  18387. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18388. ExpectIntEQ(wc_RsaPSS_VerifyCheckInline(NULL, 0, &pt, digest,
  18389. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18390. ExpectIntEQ(wc_RsaPSS_VerifyCheckInline(pSignature, (word32)sz, &pt, digest,
  18391. digestSz, WC_HASH_TYPE_SHA, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18392. /* Good case */
  18393. ExpectIntGT(wc_RsaPSS_VerifyCheckInline(pSignature, (word32)sz, &pt, digest,
  18394. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), 0);
  18395. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18396. wc_FreeRng(&rng);
  18397. #endif
  18398. return EXPECT_RESULT();
  18399. } /* END test_wc_RsaPSS_VerifyCheckInline */
  18400. #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
  18401. static void sample_mutex_cb (int flag, int type, const char* file, int line)
  18402. {
  18403. (void)flag;
  18404. (void)type;
  18405. (void)file;
  18406. (void)line;
  18407. }
  18408. #endif
  18409. /*
  18410. * Testing wc_LockMutex_ex
  18411. */
  18412. static int test_wc_LockMutex_ex(void)
  18413. {
  18414. EXPECT_DECLS;
  18415. #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
  18416. int flag = CRYPTO_LOCK;
  18417. int type = 0;
  18418. const char* file = "./test-LockMutex_ex.txt";
  18419. int line = 0;
  18420. /* without SetMutexCb */
  18421. ExpectIntEQ(wc_LockMutex_ex(flag, type, file, line), WC_NO_ERR_TRACE(BAD_STATE_E));
  18422. /* with SetMutexCb */
  18423. ExpectIntEQ(wc_SetMutexCb(sample_mutex_cb), 0);
  18424. ExpectIntEQ(wc_LockMutex_ex(flag, type, file, line), 0);
  18425. ExpectIntEQ(wc_SetMutexCb(NULL), 0);
  18426. #endif
  18427. return EXPECT_RESULT();
  18428. } /* End test_wc_LockMutex_ex*/
  18429. /*
  18430. * Testing wc_SetMutexCb
  18431. */
  18432. static int test_wc_SetMutexCb(void)
  18433. {
  18434. EXPECT_DECLS;
  18435. #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
  18436. ExpectIntEQ(wc_SetMutexCb(sample_mutex_cb), 0);
  18437. ExpectIntEQ(wc_SetMutexCb(NULL), 0);
  18438. #endif
  18439. return EXPECT_RESULT();
  18440. } /* End test_wc_SetMutexCb*/
  18441. /*
  18442. * Testing wc_RsaKeyToDer()
  18443. */
  18444. static int test_wc_RsaKeyToDer(void)
  18445. {
  18446. EXPECT_DECLS;
  18447. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18448. RsaKey genKey;
  18449. WC_RNG rng;
  18450. byte* der = NULL;
  18451. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  18452. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4)) && \
  18453. (defined(RSA_MIN_SIZE) && (RSA_MIN_SIZE <= 1024))
  18454. int bits = 1024;
  18455. word32 derSz = 611;
  18456. /* (2 x 128) + 2 (possible leading 00) + (5 x 64) + 5 (possible leading 00)
  18457. + 3 (e) + 8 (ASN tag) + 10 (ASN length) + 4 seqSz + 3 version */
  18458. #else
  18459. int bits = 2048;
  18460. word32 derSz = 1196;
  18461. /* (2 x 256) + 2 (possible leading 00) + (5 x 128) + 5 (possible leading 00)
  18462. + 3 (e) + 8 (ASN tag) + 17 (ASN length) + 4 seqSz + 3 version */
  18463. #endif
  18464. XMEMSET(&rng, 0, sizeof(rng));
  18465. XMEMSET(&genKey, 0, sizeof(genKey));
  18466. ExpectNotNull(der = (byte*)XMALLOC(derSz, NULL, DYNAMIC_TYPE_TMP_BUFFER));
  18467. /* Init structures. */
  18468. ExpectIntEQ(wc_InitRsaKey(&genKey, HEAP_HINT), 0);
  18469. ExpectIntEQ(wc_InitRng(&rng), 0);
  18470. /* Make key. */
  18471. ExpectIntEQ(MAKE_RSA_KEY(&genKey, bits, WC_RSA_EXPONENT, &rng), 0);
  18472. ExpectIntGT(wc_RsaKeyToDer(&genKey, der, derSz), 0);
  18473. /* Pass good/bad args. */
  18474. ExpectIntEQ(wc_RsaKeyToDer(NULL, der, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18475. /* Get just the output length */
  18476. ExpectIntGT(wc_RsaKeyToDer(&genKey, NULL, 0), 0);
  18477. /* Try Public Key. */
  18478. genKey.type = 0;
  18479. ExpectIntEQ(wc_RsaKeyToDer(&genKey, der, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18480. #ifdef WOLFSSL_CHECK_MEM_ZERO
  18481. /* Put back to Private Key */
  18482. genKey.type = 1;
  18483. #endif
  18484. XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  18485. DoExpectIntEQ(wc_FreeRsaKey(&genKey), 0);
  18486. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18487. #endif
  18488. return EXPECT_RESULT();
  18489. } /* END test_wc_RsaKeyToDer */
  18490. /*
  18491. * Testing wc_RsaKeyToPublicDer()
  18492. */
  18493. static int test_wc_RsaKeyToPublicDer(void)
  18494. {
  18495. EXPECT_DECLS;
  18496. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18497. RsaKey key;
  18498. WC_RNG rng;
  18499. byte* der = NULL;
  18500. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  18501. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4)) && \
  18502. (defined(RSA_MIN_SIZE) && (RSA_MIN_SIZE <= 1024))
  18503. int bits = 1024;
  18504. word32 derLen = 162;
  18505. #else
  18506. int bits = 2048;
  18507. word32 derLen = 294;
  18508. #endif
  18509. int ret;
  18510. XMEMSET(&rng, 0, sizeof(rng));
  18511. XMEMSET(&key, 0, sizeof(key));
  18512. ExpectNotNull(der = (byte*)XMALLOC(derLen, NULL, DYNAMIC_TYPE_TMP_BUFFER));
  18513. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18514. ExpectIntEQ(wc_InitRng(&rng), 0);
  18515. ExpectIntEQ(MAKE_RSA_KEY(&key, bits, WC_RSA_EXPONENT, &rng), 0);
  18516. /* test getting size only */
  18517. ExpectIntGT(wc_RsaKeyToPublicDer(&key, NULL, derLen), 0);
  18518. ExpectIntGT(wc_RsaKeyToPublicDer(&key, der, derLen), 0);
  18519. /* test getting size only */
  18520. ExpectIntGT(wc_RsaKeyToPublicDer_ex(&key, NULL, derLen, 0), 0);
  18521. ExpectIntGT(wc_RsaKeyToPublicDer_ex(&key, der, derLen, 0), 0);
  18522. /* Pass in bad args. */
  18523. ExpectIntEQ(wc_RsaKeyToPublicDer(NULL, der, derLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18524. ExpectIntLT(ret = wc_RsaKeyToPublicDer(&key, der, -1), 0);
  18525. ExpectTrue((ret == WC_NO_ERR_TRACE(BUFFER_E)) || (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)));
  18526. XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  18527. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18528. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18529. #endif
  18530. return EXPECT_RESULT();
  18531. } /* END test_wc_RsaKeyToPublicDer */
  18532. /*
  18533. * Testing wc_RsaPublicEncrypt() and wc_RsaPrivateDecrypt()
  18534. */
  18535. static int test_wc_RsaPublicEncryptDecrypt(void)
  18536. {
  18537. EXPECT_DECLS;
  18538. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18539. RsaKey key;
  18540. WC_RNG rng;
  18541. const char inStr[] = TEST_STRING;
  18542. const word32 plainLen = (word32)TEST_STRING_SZ;
  18543. const word32 inLen = (word32)TEST_STRING_SZ;
  18544. int bits = TEST_RSA_BITS;
  18545. const word32 cipherLen = TEST_RSA_BYTES;
  18546. word32 cipherLenResult = cipherLen;
  18547. WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, NULL);
  18548. WC_DECLARE_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18549. WC_DECLARE_VAR(cipher, byte, TEST_RSA_BYTES, NULL);
  18550. WC_ALLOC_VAR(in, byte, TEST_STRING_SZ, NULL);
  18551. WC_ALLOC_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18552. WC_ALLOC_VAR(cipher, byte, TEST_RSA_BYTES, NULL);
  18553. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  18554. ExpectNotNull(in);
  18555. ExpectNotNull(plain);
  18556. ExpectNotNull(cipher);
  18557. #endif
  18558. ExpectNotNull(XMEMCPY(in, inStr, inLen));
  18559. /* Initialize stack structures. */
  18560. XMEMSET(&key, 0, sizeof(RsaKey));
  18561. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18562. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18563. ExpectIntEQ(wc_InitRng(&rng), 0);
  18564. ExpectIntEQ(MAKE_RSA_KEY(&key, bits, WC_RSA_EXPONENT, &rng), 0);
  18565. /* Encrypt. */
  18566. ExpectIntGT(cipherLenResult = (word32)wc_RsaPublicEncrypt(in, inLen, cipher,
  18567. cipherLen, &key, &rng), 0);
  18568. /* Pass bad args - tested in another testing function.*/
  18569. /* Decrypt */
  18570. #if defined(WC_RSA_BLINDING) && !defined(HAVE_FIPS)
  18571. /* Bind rng */
  18572. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  18573. #endif
  18574. ExpectIntGE(wc_RsaPrivateDecrypt(cipher, cipherLenResult, plain, plainLen,
  18575. &key), 0);
  18576. ExpectIntEQ(XMEMCMP(plain, inStr, plainLen), 0);
  18577. /* Pass bad args - tested in another testing function.*/
  18578. WC_FREE_VAR(in, NULL);
  18579. WC_FREE_VAR(plain, NULL);
  18580. WC_FREE_VAR(cipher, NULL);
  18581. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18582. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18583. #endif
  18584. return EXPECT_RESULT();
  18585. } /* END test_wc_RsaPublicEncryptDecrypt */
  18586. /*
  18587. * Testing wc_RsaPrivateDecrypt_ex() and wc_RsaPrivateDecryptInline_ex()
  18588. */
  18589. static int test_wc_RsaPublicEncryptDecrypt_ex(void)
  18590. {
  18591. EXPECT_DECLS;
  18592. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(HAVE_FIPS)\
  18593. && !defined(WC_NO_RSA_OAEP) && !defined(NO_SHA256)
  18594. RsaKey key;
  18595. WC_RNG rng;
  18596. const char inStr[] = TEST_STRING;
  18597. const word32 inLen = (word32)TEST_STRING_SZ;
  18598. const word32 plainSz = (word32)TEST_STRING_SZ;
  18599. byte* res = NULL;
  18600. int idx = 0;
  18601. int bits = TEST_RSA_BITS;
  18602. const word32 cipherSz = TEST_RSA_BYTES;
  18603. WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, NULL);
  18604. WC_DECLARE_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18605. WC_DECLARE_VAR(cipher, byte, TEST_RSA_BYTES, NULL);
  18606. WC_ALLOC_VAR(in, byte, TEST_STRING_SZ, NULL);
  18607. WC_ALLOC_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18608. WC_ALLOC_VAR(cipher, byte, TEST_RSA_BYTES, NULL);
  18609. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  18610. ExpectNotNull(in);
  18611. ExpectNotNull(plain);
  18612. ExpectNotNull(cipher);
  18613. #endif
  18614. ExpectNotNull(XMEMCPY(in, inStr, inLen));
  18615. /* Initialize stack structures. */
  18616. XMEMSET(&key, 0, sizeof(RsaKey));
  18617. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18618. ExpectIntEQ(wc_InitRsaKey_ex(&key, HEAP_HINT, INVALID_DEVID), 0);
  18619. ExpectIntEQ(wc_InitRng(&rng), 0);
  18620. ExpectIntEQ(MAKE_RSA_KEY(&key, bits, WC_RSA_EXPONENT, &rng), 0);
  18621. /* Encrypt */
  18622. ExpectIntGE(idx = wc_RsaPublicEncrypt_ex(in, inLen, cipher, cipherSz, &key,
  18623. &rng, WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0), 0);
  18624. /* Pass bad args - tested in another testing function.*/
  18625. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18626. /* Decrypt */
  18627. #if defined(WC_RSA_BLINDING) && !defined(HAVE_FIPS)
  18628. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  18629. #endif
  18630. ExpectIntGE(wc_RsaPrivateDecrypt_ex(cipher, (word32)idx, plain, plainSz,
  18631. &key, WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0), 0);
  18632. ExpectIntEQ(XMEMCMP(plain, inStr, plainSz), 0);
  18633. /* Pass bad args - tested in another testing function.*/
  18634. ExpectIntGE(wc_RsaPrivateDecryptInline_ex(cipher, (word32)idx, &res, &key,
  18635. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0), 0);
  18636. ExpectIntEQ(XMEMCMP(inStr, res, plainSz), 0);
  18637. #endif
  18638. WC_FREE_VAR(in, NULL);
  18639. WC_FREE_VAR(plain, NULL);
  18640. WC_FREE_VAR(cipher, NULL);
  18641. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18642. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18643. #endif
  18644. return EXPECT_RESULT();
  18645. } /* END test_wc_RsaPublicEncryptDecrypt_ex */
  18646. /*
  18647. * Tesing wc_RsaSSL_Sign() and wc_RsaSSL_Verify()
  18648. */
  18649. static int test_wc_RsaSSL_SignVerify(void)
  18650. {
  18651. EXPECT_DECLS;
  18652. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18653. RsaKey key;
  18654. WC_RNG rng;
  18655. const char inStr[] = TEST_STRING;
  18656. const word32 plainSz = (word32)TEST_STRING_SZ;
  18657. const word32 inLen = (word32)TEST_STRING_SZ;
  18658. word32 idx = 0;
  18659. int bits = TEST_RSA_BITS;
  18660. const word32 outSz = TEST_RSA_BYTES;
  18661. WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, NULL);
  18662. WC_DECLARE_VAR(out, byte, TEST_RSA_BYTES, NULL);
  18663. WC_DECLARE_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18664. WC_ALLOC_VAR(in, byte, TEST_STRING_SZ, NULL);
  18665. WC_ALLOC_VAR(out, byte, TEST_RSA_BYTES, NULL);
  18666. WC_ALLOC_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18667. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  18668. ExpectNotNull(in);
  18669. ExpectNotNull(out);
  18670. ExpectNotNull(plain);
  18671. #endif
  18672. ExpectNotNull(XMEMCPY(in, inStr, inLen));
  18673. XMEMSET(&key, 0, sizeof(RsaKey));
  18674. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18675. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18676. ExpectIntEQ(wc_InitRng(&rng), 0);
  18677. ExpectIntEQ(MAKE_RSA_KEY(&key, bits, WC_RSA_EXPONENT, &rng), 0);
  18678. /* Sign. */
  18679. ExpectIntEQ(wc_RsaSSL_Sign(in, inLen, out, outSz, &key, &rng), (int)outSz);
  18680. idx = (int)outSz;
  18681. /* Test bad args. */
  18682. ExpectIntEQ(wc_RsaSSL_Sign(NULL, inLen, out, outSz, &key, &rng),
  18683. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18684. ExpectIntEQ(wc_RsaSSL_Sign(in, 0, out, outSz, &key, &rng),
  18685. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18686. ExpectIntEQ(wc_RsaSSL_Sign(in, inLen, NULL, outSz, &key, &rng),
  18687. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18688. ExpectIntEQ(wc_RsaSSL_Sign(in, inLen, out, outSz, NULL, &rng),
  18689. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18690. /* Verify. */
  18691. ExpectIntEQ(wc_RsaSSL_Verify(out, idx, plain, plainSz, &key), (int)inLen);
  18692. /* Pass bad args. */
  18693. ExpectIntEQ(wc_RsaSSL_Verify(NULL, idx, plain, plainSz, &key),
  18694. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18695. ExpectIntEQ(wc_RsaSSL_Verify(out, 0, plain, plainSz, &key),
  18696. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18697. ExpectIntEQ(wc_RsaSSL_Verify(out, idx, NULL, plainSz, &key),
  18698. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18699. ExpectIntEQ(wc_RsaSSL_Verify(out, idx, plain, plainSz, NULL),
  18700. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18701. WC_FREE_VAR(in, NULL);
  18702. WC_FREE_VAR(out, NULL);
  18703. WC_FREE_VAR(plain, NULL);
  18704. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18705. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18706. #endif
  18707. return EXPECT_RESULT();
  18708. } /* END test_wc_RsaSSL_SignVerify */
  18709. /*
  18710. * Testing wc_RsaEncryptSize()
  18711. */
  18712. static int test_wc_RsaEncryptSize(void)
  18713. {
  18714. EXPECT_DECLS;
  18715. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18716. RsaKey key;
  18717. WC_RNG rng;
  18718. XMEMSET(&key, 0, sizeof(RsaKey));
  18719. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18720. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18721. ExpectIntEQ(wc_InitRng(&rng), 0);
  18722. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  18723. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4)) && \
  18724. (defined(RSA_MIN_SIZE) && (RSA_MIN_SIZE <= 1024))
  18725. ExpectIntEQ(MAKE_RSA_KEY(&key, 1024, WC_RSA_EXPONENT, &rng), 0);
  18726. ExpectIntEQ(wc_RsaEncryptSize(&key), 128);
  18727. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18728. #endif
  18729. ExpectIntEQ(MAKE_RSA_KEY(&key, 2048, WC_RSA_EXPONENT, &rng), 0);
  18730. ExpectIntEQ(wc_RsaEncryptSize(&key), 256);
  18731. /* Pass in bad arg. */
  18732. ExpectIntEQ(wc_RsaEncryptSize(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18733. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18734. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18735. #endif
  18736. return EXPECT_RESULT();
  18737. } /* END test_wc_RsaEncryptSize*/
  18738. /*
  18739. * Testing wc_RsaFlattenPublicKey()
  18740. */
  18741. static int test_wc_RsaFlattenPublicKey(void)
  18742. {
  18743. EXPECT_DECLS;
  18744. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18745. RsaKey key;
  18746. WC_RNG rng;
  18747. byte e[256];
  18748. byte n[256];
  18749. word32 eSz = sizeof(e);
  18750. word32 nSz = sizeof(n);
  18751. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  18752. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4)) && \
  18753. (defined(RSA_MIN_SIZE) && (RSA_MIN_SIZE <= 1024))
  18754. int bits = 1024;
  18755. #else
  18756. int bits = 2048;
  18757. #endif
  18758. XMEMSET(&key, 0, sizeof(RsaKey));
  18759. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18760. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18761. ExpectIntEQ(wc_InitRng(&rng), 0);
  18762. ExpectIntEQ(MAKE_RSA_KEY(&key, bits, WC_RSA_EXPONENT, &rng), 0);
  18763. ExpectIntEQ(wc_RsaFlattenPublicKey(&key, e, &eSz, n, &nSz), 0);
  18764. /* Pass bad args. */
  18765. ExpectIntEQ(wc_RsaFlattenPublicKey(NULL, e, &eSz, n, &nSz),
  18766. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18767. ExpectIntEQ(wc_RsaFlattenPublicKey(&key, NULL, &eSz, n, &nSz),
  18768. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18769. ExpectIntEQ(wc_RsaFlattenPublicKey(&key, e, NULL, n, &nSz),
  18770. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18771. ExpectIntEQ(wc_RsaFlattenPublicKey(&key, e, &eSz, NULL, &nSz),
  18772. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18773. ExpectIntEQ(wc_RsaFlattenPublicKey(&key, e, &eSz, n, NULL),
  18774. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18775. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18776. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18777. #endif
  18778. return EXPECT_RESULT();
  18779. } /* END test_wc_RsaFlattenPublicKey */
  18780. /*
  18781. * unit test for wc_AesCcmSetKey
  18782. */
  18783. static int test_wc_AesCcmSetKey(void)
  18784. {
  18785. EXPECT_DECLS;
  18786. #ifdef HAVE_AESCCM
  18787. Aes aes;
  18788. const byte key16[] = {
  18789. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
  18790. 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf
  18791. };
  18792. const byte key24[] = {
  18793. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  18794. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  18795. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
  18796. };
  18797. const byte key32[] = {
  18798. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  18799. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  18800. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  18801. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  18802. };
  18803. XMEMSET(&aes, 0, sizeof(Aes));
  18804. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  18805. #ifdef WOLFSSL_AES_128
  18806. ExpectIntEQ(wc_AesCcmSetKey(&aes, key16, sizeof(key16)), 0);
  18807. #endif
  18808. #ifdef WOLFSSL_AES_192
  18809. ExpectIntEQ(wc_AesCcmSetKey(&aes, key24, sizeof(key24)), 0);
  18810. #endif
  18811. #ifdef WOLFSSL_AES_256
  18812. ExpectIntEQ(wc_AesCcmSetKey(&aes, key32, sizeof(key32)), 0);
  18813. #endif
  18814. /* Test bad args. */
  18815. ExpectIntEQ(wc_AesCcmSetKey(&aes, key16, sizeof(key16) - 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18816. ExpectIntEQ(wc_AesCcmSetKey(&aes, key24, sizeof(key24) - 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18817. ExpectIntEQ(wc_AesCcmSetKey(&aes, key32, sizeof(key32) - 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18818. wc_AesFree(&aes);
  18819. #endif
  18820. return EXPECT_RESULT();
  18821. } /* END test_wc_AesCcmSetKey */
  18822. /*
  18823. * Unit test function for wc_AesCcmEncrypt and wc_AesCcmDecrypt
  18824. */
  18825. static int test_wc_AesCcmEncryptDecrypt(void)
  18826. {
  18827. EXPECT_DECLS;
  18828. #if defined(HAVE_AESCCM) && defined(WOLFSSL_AES_128)
  18829. Aes aes;
  18830. const byte key16[] = {
  18831. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
  18832. 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf
  18833. };
  18834. /* plaintext */
  18835. const byte plainT[] = {
  18836. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  18837. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  18838. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e
  18839. };
  18840. /* nonce */
  18841. const byte iv[] = {
  18842. 0x00, 0x00, 0x00, 0x03, 0x02, 0x01, 0x00, 0xa0,
  18843. 0xa1, 0xa2, 0xa3, 0xa4, 0xa5
  18844. };
  18845. const byte c[] = { /* cipher text. */
  18846. 0x58, 0x8c, 0x97, 0x9a, 0x61, 0xc6, 0x63, 0xd2,
  18847. 0xf0, 0x66, 0xd0, 0xc2, 0xc0, 0xf9, 0x89, 0x80,
  18848. 0x6d, 0x5f, 0x6b, 0x61, 0xda, 0xc3, 0x84
  18849. };
  18850. const byte t[] = { /* Auth tag */
  18851. 0x17, 0xe8, 0xd1, 0x2c, 0xfd, 0xf9, 0x26, 0xe0
  18852. };
  18853. const byte authIn[] = {
  18854. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
  18855. };
  18856. byte cipherOut[sizeof(plainT)];
  18857. byte authTag[sizeof(t)];
  18858. #ifdef HAVE_AES_DECRYPT
  18859. byte plainOut[sizeof(cipherOut)];
  18860. #endif
  18861. XMEMSET(&aes, 0, sizeof(Aes));
  18862. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  18863. ExpectIntEQ(wc_AesCcmSetKey(&aes, key16, sizeof(key16)), 0);
  18864. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, plainT, sizeof(cipherOut),
  18865. iv, sizeof(iv), authTag, sizeof(authTag), authIn , sizeof(authIn)), 0);
  18866. ExpectIntEQ(XMEMCMP(cipherOut, c, sizeof(c)), 0);
  18867. ExpectIntEQ(XMEMCMP(t, authTag, sizeof(t)), 0);
  18868. #ifdef HAVE_AES_DECRYPT
  18869. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, cipherOut, sizeof(plainOut),
  18870. iv, sizeof(iv), authTag, sizeof(authTag), authIn, sizeof(authIn)), 0);
  18871. ExpectIntEQ(XMEMCMP(plainOut, plainT, sizeof(plainT)), 0);
  18872. #endif
  18873. /* Pass in bad args. Encrypt*/
  18874. ExpectIntEQ(wc_AesCcmEncrypt(NULL, cipherOut, plainT, sizeof(cipherOut),
  18875. iv, sizeof(iv), authTag, sizeof(authTag), authIn , sizeof(authIn)),
  18876. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18877. ExpectIntEQ(wc_AesCcmEncrypt(&aes, NULL, plainT, sizeof(cipherOut),
  18878. iv, sizeof(iv), authTag, sizeof(authTag), authIn , sizeof(authIn)),
  18879. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18880. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, NULL, sizeof(cipherOut),
  18881. iv, sizeof(iv), authTag, sizeof(authTag), authIn , sizeof(authIn)),
  18882. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18883. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, plainT, sizeof(cipherOut),
  18884. NULL, sizeof(iv), authTag, sizeof(authTag), authIn , sizeof(authIn)),
  18885. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18886. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, plainT, sizeof(cipherOut),
  18887. iv, sizeof(iv), NULL, sizeof(authTag), authIn , sizeof(authIn)),
  18888. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18889. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, plainT, sizeof(cipherOut),
  18890. iv, sizeof(iv) + 1, authTag, sizeof(authTag), authIn , sizeof(authIn)),
  18891. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18892. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, plainT, sizeof(cipherOut),
  18893. iv, sizeof(iv) - 7, authTag, sizeof(authTag), authIn , sizeof(authIn)),
  18894. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18895. #ifdef HAVE_AES_DECRYPT
  18896. /* Pass in bad args. Decrypt*/
  18897. ExpectIntEQ(wc_AesCcmDecrypt(NULL, plainOut, cipherOut, sizeof(plainOut),
  18898. iv, sizeof(iv), authTag, sizeof(authTag), authIn, sizeof(authIn)),
  18899. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18900. ExpectIntEQ(wc_AesCcmDecrypt(&aes, NULL, cipherOut, sizeof(plainOut),
  18901. iv, sizeof(iv), authTag, sizeof(authTag), authIn, sizeof(authIn)),
  18902. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18903. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, NULL, sizeof(plainOut),
  18904. iv, sizeof(iv), authTag, sizeof(authTag), authIn, sizeof(authIn)),
  18905. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18906. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, cipherOut, sizeof(plainOut),
  18907. NULL, sizeof(iv), authTag, sizeof(authTag), authIn, sizeof(authIn)),
  18908. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18909. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, cipherOut, sizeof(plainOut),
  18910. iv, sizeof(iv), NULL, sizeof(authTag), authIn, sizeof(authIn)),
  18911. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18912. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, cipherOut, sizeof(plainOut),
  18913. iv, sizeof(iv) + 1, authTag, sizeof(authTag), authIn, sizeof(authIn)),
  18914. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18915. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, cipherOut, sizeof(plainOut),
  18916. iv, sizeof(iv) - 7, authTag, sizeof(authTag), authIn, sizeof(authIn)),
  18917. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18918. #endif
  18919. wc_AesFree(&aes);
  18920. #endif /* HAVE_AESCCM */
  18921. return EXPECT_RESULT();
  18922. } /* END test_wc_AesCcmEncryptDecrypt */
  18923. #if defined(WOLFSSL_AES_EAX) && \
  18924. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  18925. /*
  18926. * Testing test_wc_AesEaxVectors()
  18927. */
  18928. static int test_wc_AesEaxVectors(void)
  18929. {
  18930. EXPECT_DECLS;
  18931. typedef struct {
  18932. byte key[AES_256_KEY_SIZE];
  18933. int key_length;
  18934. byte iv[AES_BLOCK_SIZE];
  18935. int iv_length;
  18936. byte aad[AES_BLOCK_SIZE * 2];
  18937. int aad_length;
  18938. byte msg[AES_BLOCK_SIZE * 5];
  18939. int msg_length;
  18940. byte ct[AES_BLOCK_SIZE * 5];
  18941. int ct_length;
  18942. byte tag[AES_BLOCK_SIZE];
  18943. int tag_length;
  18944. int valid;
  18945. } AadVector;
  18946. /* Test vectors obtained from Google wycheproof project
  18947. * https://github.com/google/wycheproof
  18948. * from testvectors/aes_eax_test.json
  18949. */
  18950. const AadVector vectors[] = {
  18951. {
  18952. /* key, key length */
  18953. {0x23, 0x39, 0x52, 0xde, 0xe4, 0xd5, 0xed, 0x5f,
  18954. 0x9b, 0x9c, 0x6d, 0x6f, 0xf8, 0x0f, 0xf4, 0x78}, 16,
  18955. /* iv, iv length */
  18956. {0x62, 0xec, 0x67, 0xf9, 0xc3, 0xa4, 0xa4, 0x07,
  18957. 0xfc, 0xb2, 0xa8, 0xc4, 0x90, 0x31, 0xa8, 0xb3}, 16,
  18958. /* aad, aad length */
  18959. {0x6b, 0xfb, 0x91, 0x4f, 0xd0, 0x7e, 0xae, 0x6b}, 8,
  18960. /* msg, msg length */
  18961. {0x00}, 0,
  18962. /* ct, ct length */
  18963. {0x00}, 0,
  18964. /* tag, tag length */
  18965. {0xe0, 0x37, 0x83, 0x0e, 0x83, 0x89, 0xf2, 0x7b,
  18966. 0x02, 0x5a, 0x2d, 0x65, 0x27, 0xe7, 0x9d, 0x01}, 16,
  18967. /* valid */
  18968. 1,
  18969. },
  18970. {
  18971. /* key, key length */
  18972. {0x91, 0x94, 0x5d, 0x3f, 0x4d, 0xcb, 0xee, 0x0b,
  18973. 0xf4, 0x5e, 0xf5, 0x22, 0x55, 0xf0, 0x95, 0xa4}, 16,
  18974. /* iv, iv length */
  18975. {0xbe, 0xca, 0xf0, 0x43, 0xb0, 0xa2, 0x3d, 0x84,
  18976. 0x31, 0x94, 0xba, 0x97, 0x2c, 0x66, 0xde, 0xbd}, 16,
  18977. /* aad, aad length */
  18978. {0xfa, 0x3b, 0xfd, 0x48, 0x06, 0xeb, 0x53, 0xfa}, 8,
  18979. /* msg, msg length */
  18980. {0xf7, 0xfb}, 2,
  18981. /* ct, ct length */
  18982. {0x19, 0xdd}, 2,
  18983. /* tag, tag length */
  18984. {0x5c, 0x4c, 0x93, 0x31, 0x04, 0x9d, 0x0b, 0xda,
  18985. 0xb0, 0x27, 0x74, 0x08, 0xf6, 0x79, 0x67, 0xe5}, 16,
  18986. /* valid */
  18987. 1,
  18988. },
  18989. {
  18990. /* key, key length */
  18991. {0x01, 0xf7, 0x4a, 0xd6, 0x40, 0x77, 0xf2, 0xe7,
  18992. 0x04, 0xc0, 0xf6, 0x0a, 0xda, 0x3d, 0xd5, 0x23}, 16,
  18993. /* iv, iv length */
  18994. {0x70, 0xc3, 0xdb, 0x4f, 0x0d, 0x26, 0x36, 0x84,
  18995. 0x00, 0xa1, 0x0e, 0xd0, 0x5d, 0x2b, 0xff, 0x5e}, 16,
  18996. /* aad, aad length */
  18997. {0x23, 0x4a, 0x34, 0x63, 0xc1, 0x26, 0x4a, 0xc6}, 8,
  18998. /* msg, msg length */
  18999. {0x1a, 0x47, 0xcb, 0x49, 0x33}, 5,
  19000. /* ct, ct length */
  19001. {0xd8, 0x51, 0xd5, 0xba, 0xe0}, 5,
  19002. /* tag, tag length */
  19003. {0x3a, 0x59, 0xf2, 0x38, 0xa2, 0x3e, 0x39, 0x19,
  19004. 0x9d, 0xc9, 0x26, 0x66, 0x26, 0xc4, 0x0f, 0x80}, 16,
  19005. /* valid */
  19006. 1,
  19007. },
  19008. {
  19009. /* key, key length */
  19010. {0xd0, 0x7c, 0xf6, 0xcb, 0xb7, 0xf3, 0x13, 0xbd,
  19011. 0xde, 0x66, 0xb7, 0x27, 0xaf, 0xd3, 0xc5, 0xe8}, 16,
  19012. /* iv, iv length */
  19013. {0x84, 0x08, 0xdf, 0xff, 0x3c, 0x1a, 0x2b, 0x12,
  19014. 0x92, 0xdc, 0x19, 0x9e, 0x46, 0xb7, 0xd6, 0x17}, 16,
  19015. /* aad, aad length */
  19016. {0x33, 0xcc, 0xe2, 0xea, 0xbf, 0xf5, 0xa7, 0x9d}, 8,
  19017. /* msg, msg length */
  19018. {0x48, 0x1c, 0x9e, 0x39, 0xb1}, 5,
  19019. /* ct, ct length */
  19020. {0x63, 0x2a, 0x9d, 0x13, 0x1a}, 5,
  19021. /* tag, tag length */
  19022. {0xd4, 0xc1, 0x68, 0xa4, 0x22, 0x5d, 0x8e, 0x1f,
  19023. 0xf7, 0x55, 0x93, 0x99, 0x74, 0xa7, 0xbe, 0xde}, 16,
  19024. /* valid */
  19025. 1,
  19026. },
  19027. {
  19028. /* key, key length */
  19029. {0x35, 0xb6, 0xd0, 0x58, 0x00, 0x05, 0xbb, 0xc1,
  19030. 0x2b, 0x05, 0x87, 0x12, 0x45, 0x57, 0xd2, 0xc2}, 16,
  19031. /* iv, iv length */
  19032. {0xfd, 0xb6, 0xb0, 0x66, 0x76, 0xee, 0xdc, 0x5c,
  19033. 0x61, 0xd7, 0x42, 0x76, 0xe1, 0xf8, 0xe8, 0x16}, 16,
  19034. /* aad, aad length */
  19035. {0xae, 0xb9, 0x6e, 0xae, 0xbe, 0x29, 0x70, 0xe9}, 8,
  19036. /* msg, msg length */
  19037. {0x40, 0xd0, 0xc0, 0x7d, 0xa5, 0xe4}, 6,
  19038. /* ct, ct length */
  19039. {0x07, 0x1d, 0xfe, 0x16, 0xc6, 0x75}, 6,
  19040. /* tag, tag length */
  19041. {0xcb, 0x06, 0x77, 0xe5, 0x36, 0xf7, 0x3a, 0xfe,
  19042. 0x6a, 0x14, 0xb7, 0x4e, 0xe4, 0x98, 0x44, 0xdd}, 16,
  19043. /* valid */
  19044. 1,
  19045. },
  19046. {
  19047. /* key, key length */
  19048. {0xbd, 0x8e, 0x6e, 0x11, 0x47, 0x5e, 0x60, 0xb2,
  19049. 0x68, 0x78, 0x4c, 0x38, 0xc6, 0x2f, 0xeb, 0x22}, 16,
  19050. /* iv, iv length */
  19051. {0x6e, 0xac, 0x5c, 0x93, 0x07, 0x2d, 0x8e, 0x85,
  19052. 0x13, 0xf7, 0x50, 0x93, 0x5e, 0x46, 0xda, 0x1b}, 16,
  19053. /* aad, aad length */
  19054. {0xd4, 0x48, 0x2d, 0x1c, 0xa7, 0x8d, 0xce, 0x0f}, 8,
  19055. /* msg, msg length */
  19056. {0x4d, 0xe3, 0xb3, 0x5c, 0x3f, 0xc0, 0x39, 0x24,
  19057. 0x5b, 0xd1, 0xfb, 0x7d}, 12,
  19058. /* ct, ct length */
  19059. {0x83, 0x5b, 0xb4, 0xf1, 0x5d, 0x74, 0x3e, 0x35,
  19060. 0x0e, 0x72, 0x84, 0x14}, 12,
  19061. /* tag, tag length */
  19062. {0xab, 0xb8, 0x64, 0x4f, 0xd6, 0xcc, 0xb8, 0x69,
  19063. 0x47, 0xc5, 0xe1, 0x05, 0x90, 0x21, 0x0a, 0x4f}, 16,
  19064. /* valid */
  19065. 1,
  19066. },
  19067. {
  19068. /* key, key length */
  19069. {0x7c, 0x77, 0xd6, 0xe8, 0x13, 0xbe, 0xd5, 0xac,
  19070. 0x98, 0xba, 0xa4, 0x17, 0x47, 0x7a, 0x2e, 0x7d}, 16,
  19071. /* iv, iv length */
  19072. {0x1a, 0x8c, 0x98, 0xdc, 0xd7, 0x3d, 0x38, 0x39,
  19073. 0x3b, 0x2b, 0xf1, 0x56, 0x9d, 0xee, 0xfc, 0x19}, 16,
  19074. /* aad, aad length */
  19075. {0x65, 0xd2, 0x01, 0x79, 0x90, 0xd6, 0x25, 0x28}, 8,
  19076. /* msg, msg length */
  19077. {0x8b, 0x0a, 0x79, 0x30, 0x6c, 0x9c, 0xe7, 0xed,
  19078. 0x99, 0xda, 0xe4, 0xf8, 0x7f, 0x8d, 0xd6, 0x16,
  19079. 0x36}, 17,
  19080. /* ct, ct length */
  19081. {0x02, 0x08, 0x3e, 0x39, 0x79, 0xda, 0x01, 0x48,
  19082. 0x12, 0xf5, 0x9f, 0x11, 0xd5, 0x26, 0x30, 0xda,
  19083. 0x30}, 17,
  19084. /* tag, tag length */
  19085. {0x13, 0x73, 0x27, 0xd1, 0x06, 0x49, 0xb0, 0xaa,
  19086. 0x6e, 0x1c, 0x18, 0x1d, 0xb6, 0x17, 0xd7, 0xf2}, 16,
  19087. /* valid */
  19088. 1,
  19089. },
  19090. {
  19091. /* key, key length */
  19092. {0x5f, 0xff, 0x20, 0xca, 0xfa, 0xb1, 0x19, 0xca,
  19093. 0x2f, 0xc7, 0x35, 0x49, 0xe2, 0x0f, 0x5b, 0x0d}, 16,
  19094. /* iv, iv length */
  19095. {0xdd, 0xe5, 0x9b, 0x97, 0xd7, 0x22, 0x15, 0x6d,
  19096. 0x4d, 0x9a, 0xff, 0x2b, 0xc7, 0x55, 0x98, 0x26}, 16,
  19097. /* aad, aad length */
  19098. {0x54, 0xb9, 0xf0, 0x4e, 0x6a, 0x09, 0x18, 0x9a}, 8,
  19099. /* msg, msg length */
  19100. {0x1b, 0xda, 0x12, 0x2b, 0xce, 0x8a, 0x8d, 0xba,
  19101. 0xf1, 0x87, 0x7d, 0x96, 0x2b, 0x85, 0x92, 0xdd,
  19102. 0x2d, 0x56}, 18,
  19103. /* ct, ct length */
  19104. {0x2e, 0xc4, 0x7b, 0x2c, 0x49, 0x54, 0xa4, 0x89,
  19105. 0xaf, 0xc7, 0xba, 0x48, 0x97, 0xed, 0xcd, 0xae,
  19106. 0x8c, 0xc3}, 18,
  19107. /* tag, tag length */
  19108. {0x3b, 0x60, 0x45, 0x05, 0x99, 0xbd, 0x02, 0xc9,
  19109. 0x63, 0x82, 0x90, 0x2a, 0xef, 0x7f, 0x83, 0x2a}, 16,
  19110. /* valid */
  19111. 1,
  19112. },
  19113. {
  19114. /* key, key length */
  19115. {0xa4, 0xa4, 0x78, 0x2b, 0xcf, 0xfd, 0x3e, 0xc5,
  19116. 0xe7, 0xef, 0x6d, 0x8c, 0x34, 0xa5, 0x61, 0x23}, 16,
  19117. /* iv, iv length */
  19118. {0xb7, 0x81, 0xfc, 0xf2, 0xf7, 0x5f, 0xa5, 0xa8,
  19119. 0xde, 0x97, 0xa9, 0xca, 0x48, 0xe5, 0x22, 0xec}, 16,
  19120. /* aad, aad length */
  19121. {0x89, 0x9a, 0x17, 0x58, 0x97, 0x56, 0x1d, 0x7e}, 8,
  19122. /* msg, msg length */
  19123. {0x6c, 0xf3, 0x67, 0x20, 0x87, 0x2b, 0x85, 0x13,
  19124. 0xf6, 0xea, 0xb1, 0xa8, 0xa4, 0x44, 0x38, 0xd5,
  19125. 0xef, 0x11}, 18,
  19126. /* ct, ct length */
  19127. {0x0d, 0xe1, 0x8f, 0xd0, 0xfd, 0xd9, 0x1e, 0x7a,
  19128. 0xf1, 0x9f, 0x1d, 0x8e, 0xe8, 0x73, 0x39, 0x38,
  19129. 0xb1, 0xe8}, 18,
  19130. /* tag, tag length */
  19131. {0xe7, 0xf6, 0xd2, 0x23, 0x16, 0x18, 0x10, 0x2f,
  19132. 0xdb, 0x7f, 0xe5, 0x5f, 0xf1, 0x99, 0x17, 0x00}, 16,
  19133. /* valid */
  19134. 1,
  19135. },
  19136. {
  19137. /* key, key length */
  19138. {0x83, 0x95, 0xfc, 0xf1, 0xe9, 0x5b, 0xeb, 0xd6,
  19139. 0x97, 0xbd, 0x01, 0x0b, 0xc7, 0x66, 0xaa, 0xc3}, 16,
  19140. /* iv, iv length */
  19141. {0x22, 0xe7, 0xad, 0xd9, 0x3c, 0xfc, 0x63, 0x93,
  19142. 0xc5, 0x7e, 0xc0, 0xb3, 0xc1, 0x7d, 0x6b, 0x44}, 16,
  19143. /* aad, aad length */
  19144. {0x12, 0x67, 0x35, 0xfc, 0xc3, 0x20, 0xd2, 0x5a}, 8,
  19145. /* msg, msg length */
  19146. {0xca, 0x40, 0xd7, 0x44, 0x6e, 0x54, 0x5f, 0xfa,
  19147. 0xed, 0x3b, 0xd1, 0x2a, 0x74, 0x0a, 0x65, 0x9f,
  19148. 0xfb, 0xbb, 0x3c, 0xea, 0xb7}, 21,
  19149. /* ct, ct length */
  19150. {0xcb, 0x89, 0x20, 0xf8, 0x7a, 0x6c, 0x75, 0xcf,
  19151. 0xf3, 0x96, 0x27, 0xb5, 0x6e, 0x3e, 0xd1, 0x97,
  19152. 0xc5, 0x52, 0xd2, 0x95, 0xa7}, 21,
  19153. /* tag, tag length */
  19154. {0xcf, 0xc4, 0x6a, 0xfc, 0x25, 0x3b, 0x46, 0x52,
  19155. 0xb1, 0xaf, 0x37, 0x95, 0xb1, 0x24, 0xab, 0x6e}, 16,
  19156. /* valid */
  19157. 1,
  19158. },
  19159. {
  19160. /* key, key length */
  19161. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19162. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19163. /* iv, iv length */
  19164. {0x3c, 0x8c, 0xc2, 0x97, 0x0a, 0x00, 0x8f, 0x75,
  19165. 0xcc, 0x5b, 0xea, 0xe2, 0x84, 0x72, 0x58, 0xc2}, 16,
  19166. /* aad, aad length */
  19167. {0x00}, 0,
  19168. /* msg, msg length */
  19169. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19170. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19171. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19172. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  19173. /* ct, ct length */
  19174. {0x3c, 0x44, 0x1f, 0x32, 0xce, 0x07, 0x82, 0x23,
  19175. 0x64, 0xd7, 0xa2, 0x99, 0x0e, 0x50, 0xbb, 0x13,
  19176. 0xd7, 0xb0, 0x2a, 0x26, 0x96, 0x9e, 0x4a, 0x93,
  19177. 0x7e, 0x5e, 0x90, 0x73, 0xb0, 0xd9, 0xc9, 0x68}, 32,
  19178. /* tag, tag length */
  19179. {0xdb, 0x90, 0xbd, 0xb3, 0xda, 0x3d, 0x00, 0xaf,
  19180. 0xd0, 0xfc, 0x6a, 0x83, 0x55, 0x1d, 0xa9, 0x5e}, 16,
  19181. /* valid */
  19182. 1,
  19183. },
  19184. {
  19185. /* key, key length */
  19186. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19187. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19188. /* iv, iv length */
  19189. {0xae, 0xf0, 0x3d, 0x00, 0x59, 0x84, 0x94, 0xe9,
  19190. 0xfb, 0x03, 0xcd, 0x7d, 0x8b, 0x59, 0x08, 0x66}, 16,
  19191. /* aad, aad length */
  19192. {0x00}, 0,
  19193. /* msg, msg length */
  19194. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19195. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19196. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19197. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  19198. /* ct, ct length */
  19199. {0xd1, 0x9a, 0xc5, 0x98, 0x49, 0x02, 0x6a, 0x91,
  19200. 0xaa, 0x1b, 0x9a, 0xec, 0x29, 0xb1, 0x1a, 0x20,
  19201. 0x2a, 0x4d, 0x73, 0x9f, 0xd8, 0x6c, 0x28, 0xe3,
  19202. 0xae, 0x3d, 0x58, 0x8e, 0xa2, 0x1d, 0x70, 0xc6}, 32,
  19203. /* tag, tag length */
  19204. {0xc3, 0x0f, 0x6c, 0xd9, 0x20, 0x20, 0x74, 0xed,
  19205. 0x6e, 0x2a, 0x2a, 0x36, 0x0e, 0xac, 0x8c, 0x47}, 16,
  19206. /* valid */
  19207. 1,
  19208. },
  19209. {
  19210. /* key, key length */
  19211. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19212. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19213. /* iv, iv length */
  19214. {0x55, 0xd1, 0x25, 0x11, 0xc6, 0x96, 0xa8, 0x0d,
  19215. 0x05, 0x14, 0xd1, 0xff, 0xba, 0x49, 0xca, 0xda}, 16,
  19216. /* aad, aad length */
  19217. {0x00}, 0,
  19218. /* msg, msg length */
  19219. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19220. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19221. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19222. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  19223. /* ct, ct length */
  19224. {0x21, 0x08, 0x55, 0x8a, 0xc4, 0xb2, 0xc2, 0xd5,
  19225. 0xcc, 0x66, 0xce, 0xa5, 0x1d, 0x62, 0x10, 0xe0,
  19226. 0x46, 0x17, 0x7a, 0x67, 0x63, 0x1c, 0xd2, 0xdd,
  19227. 0x8f, 0x09, 0x46, 0x97, 0x33, 0xac, 0xb5, 0x17}, 32,
  19228. /* tag, tag length */
  19229. {0xfc, 0x35, 0x5e, 0x87, 0xa2, 0x67, 0xbe, 0x3a,
  19230. 0xe3, 0xe4, 0x4c, 0x0b, 0xf3, 0xf9, 0x9b, 0x2b}, 16,
  19231. /* valid */
  19232. 1,
  19233. },
  19234. {
  19235. /* key, key length */
  19236. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19237. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19238. /* iv, iv length */
  19239. {0x79, 0x42, 0x2d, 0xdd, 0x91, 0xc4, 0xee, 0xe2,
  19240. 0xde, 0xae, 0xf1, 0xf9, 0x68, 0x30, 0x53, 0x04}, 16,
  19241. /* aad, aad length */
  19242. {0x00}, 0,
  19243. /* msg, msg length */
  19244. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19245. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19246. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19247. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  19248. /* ct, ct length */
  19249. {0x4d, 0x2c, 0x15, 0x24, 0xca, 0x4b, 0xaa, 0x4e,
  19250. 0xef, 0xcc, 0xe6, 0xb9, 0x1b, 0x22, 0x7e, 0xe8,
  19251. 0x3a, 0xba, 0xff, 0x81, 0x05, 0xdc, 0xaf, 0xa2,
  19252. 0xab, 0x19, 0x1f, 0x5d, 0xf2, 0x57, 0x50, 0x35}, 32,
  19253. /* tag, tag length */
  19254. {0xe2, 0xc8, 0x65, 0xce, 0x2d, 0x7a, 0xbd, 0xac,
  19255. 0x02, 0x4c, 0x6f, 0x99, 0x1a, 0x84, 0x83, 0x90}, 16,
  19256. /* valid */
  19257. 1,
  19258. },
  19259. {
  19260. /* key, key length */
  19261. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19262. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19263. /* iv, iv length */
  19264. {0x0a, 0xf5, 0xaa, 0x7a, 0x76, 0x76, 0xe2, 0x83,
  19265. 0x06, 0x30, 0x6b, 0xcd, 0x9b, 0xf2, 0x00, 0x3a}, 16,
  19266. /* aad, aad length */
  19267. {0x00}, 0,
  19268. /* msg, msg length */
  19269. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19270. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19271. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19272. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  19273. /* ct, ct length */
  19274. {0x8e, 0xb0, 0x1e, 0x62, 0x18, 0x5d, 0x78, 0x2e,
  19275. 0xb9, 0x28, 0x7a, 0x34, 0x1a, 0x68, 0x62, 0xac,
  19276. 0x52, 0x57, 0xd6, 0xf9, 0xad, 0xc9, 0x9e, 0xe0,
  19277. 0xa2, 0x4d, 0x9c, 0x22, 0xb3, 0xe9, 0xb3, 0x8a}, 32,
  19278. /* tag, tag length */
  19279. {0x39, 0xc3, 0x39, 0xbc, 0x8a, 0x74, 0xc7, 0x5e,
  19280. 0x2c, 0x65, 0xc6, 0x11, 0x95, 0x44, 0xd6, 0x1e}, 16,
  19281. /* valid */
  19282. 1,
  19283. },
  19284. {
  19285. /* key, key length */
  19286. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19287. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19288. /* iv, iv length */
  19289. {0xaf, 0x5a, 0x03, 0xae, 0x7e, 0xdd, 0x73, 0x47,
  19290. 0x1b, 0xdc, 0xdf, 0xac, 0x5e, 0x19, 0x4a, 0x60}, 16,
  19291. /* aad, aad length */
  19292. {0x00}, 0,
  19293. /* msg, msg length */
  19294. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19295. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19296. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19297. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  19298. /* ct, ct length */
  19299. {0x94, 0xc5, 0xd2, 0xac, 0xa6, 0xdb, 0xbc, 0xe8,
  19300. 0xc2, 0x45, 0x13, 0xa2, 0x5e, 0x09, 0x5c, 0x0e,
  19301. 0x54, 0xa9, 0x42, 0x86, 0x0d, 0x32, 0x7a, 0x22,
  19302. 0x2a, 0x81, 0x5c, 0xc7, 0x13, 0xb1, 0x63, 0xb4}, 32,
  19303. /* tag, tag length */
  19304. {0xf5, 0x0b, 0x30, 0x30, 0x4e, 0x45, 0xc9, 0xd4,
  19305. 0x11, 0xe8, 0xdf, 0x45, 0x08, 0xa9, 0x86, 0x12}, 16,
  19306. /* valid */
  19307. 1,
  19308. },
  19309. {
  19310. /* key, key length */
  19311. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19312. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19313. /* iv, iv length */
  19314. {0xb3, 0x70, 0x87, 0x68, 0x0f, 0x0e, 0xdd, 0x5a,
  19315. 0x52, 0x22, 0x8b, 0x8c, 0x7a, 0xae, 0xa6, 0x64}, 16,
  19316. /* aad, aad length */
  19317. {0x00}, 0,
  19318. /* msg, msg length */
  19319. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19320. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19321. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19322. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19323. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  19324. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  19325. 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
  19326. 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33}, 64,
  19327. /* ct, ct length */
  19328. {0x3b, 0xb6, 0x17, 0x3e, 0x37, 0x72, 0xd4, 0xb6,
  19329. 0x2e, 0xef, 0x37, 0xf9, 0xef, 0x07, 0x81, 0xf3,
  19330. 0x60, 0xb6, 0xc7, 0x4b, 0xe3, 0xbf, 0x6b, 0x37,
  19331. 0x10, 0x67, 0xbc, 0x1b, 0x09, 0x0d, 0x9d, 0x66,
  19332. 0x22, 0xa1, 0xfb, 0xec, 0x6a, 0xc4, 0x71, 0xb3,
  19333. 0x34, 0x9c, 0xd4, 0x27, 0x7a, 0x10, 0x1d, 0x40,
  19334. 0x89, 0x0f, 0xbf, 0x27, 0xdf, 0xdc, 0xd0, 0xb4,
  19335. 0xe3, 0x78, 0x1f, 0x98, 0x06, 0xda, 0xab, 0xb6}, 64,
  19336. /* tag, tag length */
  19337. {0xa0, 0x49, 0x87, 0x45, 0xe5, 0x99, 0x99, 0xdd,
  19338. 0xc3, 0x2d, 0x5b, 0x14, 0x02, 0x41, 0x12, 0x4e}, 16,
  19339. /* valid */
  19340. 1,
  19341. },
  19342. {
  19343. /* key, key length */
  19344. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19345. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19346. /* iv, iv length */
  19347. {0x4f, 0x80, 0x2d, 0xa6, 0x2a, 0x38, 0x45, 0x55,
  19348. 0xa1, 0x9b, 0xc2, 0xb3, 0x82, 0xeb, 0x25, 0xaf}, 16,
  19349. /* aad, aad length */
  19350. {0x00}, 0,
  19351. /* msg, msg length */
  19352. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19353. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19354. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19355. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19356. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  19357. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  19358. 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
  19359. 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
  19360. 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
  19361. 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44}, 80,
  19362. /* ct, ct length */
  19363. {0xe9, 0xb0, 0xbb, 0x88, 0x57, 0x81, 0x8c, 0xe3,
  19364. 0x20, 0x1c, 0x36, 0x90, 0xd2, 0x1d, 0xaa, 0x7f,
  19365. 0x26, 0x4f, 0xb8, 0xee, 0x93, 0xcc, 0x7a, 0x46,
  19366. 0x74, 0xea, 0x2f, 0xc3, 0x2b, 0xf1, 0x82, 0xfb,
  19367. 0x2a, 0x7e, 0x8a, 0xd5, 0x15, 0x07, 0xad, 0x4f,
  19368. 0x31, 0xce, 0xfc, 0x23, 0x56, 0xfe, 0x79, 0x36,
  19369. 0xa7, 0xf6, 0xe1, 0x9f, 0x95, 0xe8, 0x8f, 0xdb,
  19370. 0xf1, 0x76, 0x20, 0x91, 0x6d, 0x3a, 0x6f, 0x3d,
  19371. 0x01, 0xfc, 0x17, 0xd3, 0x58, 0x67, 0x2f, 0x77,
  19372. 0x7f, 0xd4, 0x09, 0x92, 0x46, 0xe4, 0x36, 0xe1}, 80,
  19373. /* tag, tag length */
  19374. {0x67, 0x91, 0x0b, 0xe7, 0x44, 0xb8, 0x31, 0x5a,
  19375. 0xe0, 0xeb, 0x61, 0x24, 0x59, 0x0c, 0x5d, 0x8b}, 16,
  19376. /* valid */
  19377. 1,
  19378. },
  19379. {
  19380. /* key, key length */
  19381. {0xb6, 0x7b, 0x1a, 0x6e, 0xfd, 0xd4, 0x0d, 0x37,
  19382. 0x08, 0x0f, 0xbe, 0x8f, 0x80, 0x47, 0xae, 0xb9}, 16,
  19383. /* iv, iv length */
  19384. {0xfa, 0x29, 0x4b, 0x12, 0x99, 0x72, 0xf7, 0xfc,
  19385. 0x5b, 0xbd, 0x5b, 0x96, 0xbb, 0xa8, 0x37, 0xc9}, 16,
  19386. /* aad, aad length */
  19387. {0x00}, 0,
  19388. /* msg, msg length */
  19389. {0x00}, 0,
  19390. /* ct, ct length */
  19391. {0x00}, 0,
  19392. /* tag, tag length */
  19393. {0xb1, 0x4b, 0x64, 0xfb, 0x58, 0x98, 0x99, 0x69,
  19394. 0x95, 0x70, 0xcc, 0x91, 0x60, 0xe3, 0x98, 0x96}, 16,
  19395. /* valid */
  19396. 1,
  19397. },
  19398. {
  19399. /* key, key length */
  19400. {0x20, 0x9e, 0x6d, 0xbf, 0x2a, 0xd2, 0x6a, 0x10,
  19401. 0x54, 0x45, 0xfc, 0x02, 0x07, 0xcd, 0x9e, 0x9a}, 16,
  19402. /* iv, iv length */
  19403. {0x94, 0x77, 0x84, 0x9d, 0x6c, 0xcd, 0xfc, 0xa1,
  19404. 0x12, 0xd9, 0x2e, 0x53, 0xfa, 0xe4, 0xa7, 0xca}, 16,
  19405. /* aad, aad length */
  19406. {0x00}, 0,
  19407. /* msg, msg length */
  19408. {0x01}, 1,
  19409. /* ct, ct length */
  19410. {0x1d}, 1,
  19411. /* tag, tag length */
  19412. {0x52, 0xa5, 0xf6, 0x00, 0xfe, 0x53, 0x38, 0x02,
  19413. 0x6a, 0x7c, 0xb0, 0x9c, 0x11, 0x64, 0x00, 0x82}, 16,
  19414. /* valid */
  19415. 1,
  19416. },
  19417. {
  19418. /* key, key length */
  19419. {0xa5, 0x49, 0x44, 0x2e, 0x35, 0x15, 0x40, 0x32,
  19420. 0xd0, 0x7c, 0x86, 0x66, 0x00, 0x6a, 0xa6, 0xa2}, 16,
  19421. /* iv, iv length */
  19422. {0x51, 0x71, 0x52, 0x45, 0x68, 0xe8, 0x1d, 0x97,
  19423. 0xe8, 0xc4, 0xde, 0x4b, 0xa5, 0x6c, 0x10, 0xa0}, 16,
  19424. /* aad, aad length */
  19425. {0x00}, 0,
  19426. /* msg, msg length */
  19427. {0x11, 0x82, 0xe9, 0x35, 0x96, 0xca, 0xc5, 0x60,
  19428. 0x89, 0x46, 0x40, 0x0b, 0xc7, 0x3f, 0x3a}, 15,
  19429. /* ct, ct length */
  19430. {0xd7, 0xb8, 0xa6, 0xb4, 0x3d, 0x2e, 0x9f, 0x98,
  19431. 0xc2, 0xb4, 0x4c, 0xe5, 0xe3, 0xcf, 0xdb}, 15,
  19432. /* tag, tag length */
  19433. {0x1b, 0xdd, 0x52, 0xfc, 0x98, 0x7d, 0xaf, 0x0e,
  19434. 0xe1, 0x92, 0x34, 0xc9, 0x05, 0xea, 0x64, 0x5f}, 16,
  19435. /* valid */
  19436. 1,
  19437. },
  19438. {
  19439. /* key, key length */
  19440. {0x95, 0x8b, 0xcd, 0xb6, 0x6a, 0x39, 0x52, 0xb5,
  19441. 0x37, 0x01, 0x58, 0x2a, 0x68, 0xa0, 0xe4, 0x74}, 16,
  19442. /* iv, iv length */
  19443. {0x0e, 0x6e, 0xc8, 0x79, 0xb0, 0x2c, 0x6f, 0x51,
  19444. 0x69, 0x76, 0xe3, 0x58, 0x98, 0x42, 0x8d, 0xa7}, 16,
  19445. /* aad, aad length */
  19446. {0x00}, 0,
  19447. /* msg, msg length */
  19448. {0x14, 0x04, 0x15, 0x82, 0x3e, 0xcc, 0x89, 0x32,
  19449. 0xa0, 0x58, 0x38, 0x4b, 0x73, 0x8e, 0xa6, 0xea,
  19450. 0x6d, 0x4d, 0xfe, 0x3b, 0xbe, 0xee}, 22,
  19451. /* ct, ct length */
  19452. {0x73, 0xe5, 0xc6, 0xf0, 0xe7, 0x03, 0xa5, 0x2d,
  19453. 0x02, 0xf7, 0xf7, 0xfa, 0xeb, 0x1b, 0x77, 0xfd,
  19454. 0x4f, 0xd0, 0xcb, 0x42, 0x1e, 0xaf}, 22,
  19455. /* tag, tag length */
  19456. {0x6c, 0x15, 0x4a, 0x85, 0x96, 0x8e, 0xdd, 0x74,
  19457. 0x77, 0x65, 0x75, 0xa4, 0x45, 0x0b, 0xd8, 0x97}, 16,
  19458. /* valid */
  19459. 1,
  19460. },
  19461. {
  19462. /* key, key length */
  19463. {0x96, 0x5b, 0x75, 0x7b, 0xa5, 0x01, 0x8a, 0x8d,
  19464. 0x66, 0xed, 0xc7, 0x8e, 0x0c, 0xee, 0xe8, 0x6b}, 16,
  19465. /* iv, iv length */
  19466. {0x2e, 0x35, 0x90, 0x1a, 0xe7, 0xd4, 0x91, 0xee,
  19467. 0xcc, 0x88, 0x38, 0xfe, 0xdd, 0x63, 0x14, 0x05}, 16,
  19468. /* aad, aad length */
  19469. {0xdf, 0x10, 0xd0, 0xd2, 0x12, 0x24, 0x24, 0x50}, 8,
  19470. /* msg, msg length */
  19471. {0x36, 0xe5, 0x7a, 0x76, 0x39, 0x58, 0xb0, 0x2c,
  19472. 0xea, 0x9d, 0x6a, 0x67, 0x6e, 0xbc, 0xe8, 0x1f}, 16,
  19473. /* ct, ct length */
  19474. {0x93, 0x6b, 0x69, 0xb6, 0xc9, 0x55, 0xad, 0xfd,
  19475. 0x15, 0x53, 0x9b, 0x9b, 0xe4, 0x98, 0x9c, 0xb6}, 16,
  19476. /* tag, tag length */
  19477. {0xee, 0x15, 0xa1, 0x45, 0x4e, 0x88, 0xfa, 0xad,
  19478. 0x8e, 0x48, 0xa8, 0xdf, 0x29, 0x83, 0xb4, 0x25}, 16,
  19479. /* valid */
  19480. 1,
  19481. },
  19482. {
  19483. /* key, key length */
  19484. {0x88, 0xd0, 0x20, 0x33, 0x78, 0x1c, 0x7b, 0x41,
  19485. 0x64, 0x71, 0x1a, 0x05, 0x42, 0x0f, 0x25, 0x6e}, 16,
  19486. /* iv, iv length */
  19487. {0x7f, 0x29, 0x85, 0x29, 0x63, 0x15, 0x50, 0x7a,
  19488. 0xa4, 0xc0, 0xa9, 0x3d, 0x5c, 0x12, 0xbd, 0x77}, 16,
  19489. /* aad, aad length */
  19490. {0x7c, 0x57, 0x1d, 0x2f, 0xbb, 0x5f, 0x62, 0x52,
  19491. 0x3c, 0x0e, 0xb3, 0x38, 0xbe, 0xf9, 0xa9}, 15,
  19492. /* msg, msg length */
  19493. {0xd9, 0x8a, 0xdc, 0x03, 0xd9, 0xd5, 0x82, 0x73,
  19494. 0x2e, 0xb0, 0x7d, 0xf2, 0x3d, 0x7b, 0x9f, 0x74}, 16,
  19495. /* ct, ct length */
  19496. {0x67, 0xca, 0xac, 0x35, 0x44, 0x3a, 0x31, 0x38,
  19497. 0xd2, 0xcb, 0x81, 0x1f, 0x0c, 0xe0, 0x4d, 0xd2}, 16,
  19498. /* tag, tag length */
  19499. {0xb7, 0x96, 0x8e, 0x0b, 0x56, 0x40, 0xe3, 0xb2,
  19500. 0x36, 0x56, 0x96, 0x53, 0x20, 0x8b, 0x9d, 0xeb}, 16,
  19501. /* valid */
  19502. 1,
  19503. },
  19504. {
  19505. /* key, key length */
  19506. {0x51, 0x58, 0x40, 0xcf, 0x67, 0xd2, 0xe4, 0x0e,
  19507. 0xb6, 0x5e, 0x54, 0xa2, 0x4c, 0x72, 0xcb, 0xf2}, 16,
  19508. /* iv, iv length */
  19509. {0xbf, 0x47, 0xaf, 0xdf, 0xd4, 0x92, 0x13, 0x7a,
  19510. 0x24, 0x23, 0x6b, 0xc3, 0x67, 0x97, 0xa8, 0x8e}, 16,
  19511. /* aad, aad length */
  19512. {0x16, 0x84, 0x3c, 0x09, 0x1d, 0x43, 0xb0, 0xa1,
  19513. 0x91, 0xd0, 0xc7, 0x3d, 0x15, 0x60, 0x1b, 0xe9}, 16,
  19514. /* msg, msg length */
  19515. {0xc8, 0x34, 0x58, 0x8c, 0xb6, 0xda, 0xf9, 0xf0,
  19516. 0x6d, 0xd2, 0x35, 0x19, 0xf4, 0xbe, 0x9f, 0x56}, 16,
  19517. /* ct, ct length */
  19518. {0x20, 0x0a, 0xc4, 0x51, 0xfb, 0xeb, 0x0f, 0x61,
  19519. 0x51, 0xd6, 0x15, 0x83, 0xa4, 0x3b, 0x73, 0x43}, 16,
  19520. /* tag, tag length */
  19521. {0x2a, 0xd4, 0x3e, 0x4c, 0xaa, 0x51, 0x98, 0x3a,
  19522. 0x9d, 0x4d, 0x24, 0x48, 0x1b, 0xf4, 0xc8, 0x39}, 16,
  19523. /* valid */
  19524. 1,
  19525. },
  19526. {
  19527. /* key, key length */
  19528. {0x2e, 0x44, 0x92, 0xd4, 0x44, 0xe5, 0xb6, 0xf4,
  19529. 0xce, 0xc8, 0xc2, 0xd3, 0x61, 0x5a, 0xc8, 0x58}, 16,
  19530. /* iv, iv length */
  19531. {0xd0, 0x2b, 0xf0, 0x76, 0x3a, 0x9f, 0xef, 0xbf,
  19532. 0x70, 0xc3, 0x3a, 0xee, 0x1e, 0x9d, 0xa1, 0xd6}, 16,
  19533. /* aad, aad length */
  19534. {0x90, 0x4d, 0x86, 0xf1, 0x33, 0xce, 0xc1, 0x5a,
  19535. 0x0c, 0x3c, 0xaf, 0x14, 0xd7, 0xe0, 0x29, 0xc8,
  19536. 0x2a, 0x07, 0x70, 0x5a, 0x23, 0xf0, 0xd0, 0x80}, 24,
  19537. /* msg, msg length */
  19538. {0x9e, 0x62, 0xd6, 0x51, 0x1b, 0x0b, 0xda, 0x7d,
  19539. 0xd7, 0x74, 0x0b, 0x61, 0x4d, 0x97, 0xba, 0xe0}, 16,
  19540. /* ct, ct length */
  19541. {0x27, 0xc6, 0xe9, 0xa6, 0x53, 0xc5, 0x25, 0x3c,
  19542. 0xa1, 0xc5, 0x67, 0x3f, 0x97, 0xb9, 0xb3, 0x3e}, 16,
  19543. /* tag, tag length */
  19544. {0x2d, 0x58, 0x12, 0x71, 0xe1, 0xfa, 0x9e, 0x36,
  19545. 0x86, 0x13, 0x6c, 0xaa, 0x8f, 0x4d, 0x6c, 0x8e}, 16,
  19546. /* valid */
  19547. 1,
  19548. },
  19549. {
  19550. /* key, key length */
  19551. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19552. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19553. /* iv, iv length */
  19554. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19555. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19556. /* aad, aad length */
  19557. {0x00}, 0,
  19558. /* msg, msg length */
  19559. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19560. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19561. /* ct, ct length */
  19562. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19563. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19564. /* tag, tag length */
  19565. {0xe7, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19566. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19567. /* valid */
  19568. 0,
  19569. },
  19570. {
  19571. /* key, key length */
  19572. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19573. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19574. /* iv, iv length */
  19575. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19576. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19577. /* aad, aad length */
  19578. {0x00}, 0,
  19579. /* msg, msg length */
  19580. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19581. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19582. /* ct, ct length */
  19583. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19584. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19585. /* tag, tag length */
  19586. {0xe4, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19587. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19588. /* valid */
  19589. 0,
  19590. },
  19591. {
  19592. /* key, key length */
  19593. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19594. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19595. /* iv, iv length */
  19596. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19597. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19598. /* aad, aad length */
  19599. {0x00}, 0,
  19600. /* msg, msg length */
  19601. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19602. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19603. /* ct, ct length */
  19604. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19605. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19606. /* tag, tag length */
  19607. {0x66, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19608. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19609. /* valid */
  19610. 0,
  19611. },
  19612. {
  19613. /* key, key length */
  19614. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19615. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19616. /* iv, iv length */
  19617. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19618. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19619. /* aad, aad length */
  19620. {0x00}, 0,
  19621. /* msg, msg length */
  19622. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19623. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19624. /* ct, ct length */
  19625. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19626. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19627. /* tag, tag length */
  19628. {0xe6, 0x0f, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19629. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19630. /* valid */
  19631. 0,
  19632. },
  19633. {
  19634. /* key, key length */
  19635. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19636. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19637. /* iv, iv length */
  19638. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19639. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19640. /* aad, aad length */
  19641. {0x00}, 0,
  19642. /* msg, msg length */
  19643. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19644. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19645. /* ct, ct length */
  19646. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19647. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19648. /* tag, tag length */
  19649. {0xe6, 0x0e, 0x7c, 0xd0, 0x13, 0xa6, 0xdb, 0xf2,
  19650. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19651. /* valid */
  19652. 0,
  19653. },
  19654. {
  19655. /* key, key length */
  19656. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19657. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19658. /* iv, iv length */
  19659. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19660. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19661. /* aad, aad length */
  19662. {0x00}, 0,
  19663. /* msg, msg length */
  19664. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19665. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19666. /* ct, ct length */
  19667. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19668. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19669. /* tag, tag length */
  19670. {0xe6, 0x0e, 0x7c, 0x50, 0x12, 0xa6, 0xdb, 0xf2,
  19671. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19672. /* valid */
  19673. 0,
  19674. },
  19675. {
  19676. /* key, key length */
  19677. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19678. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19679. /* iv, iv length */
  19680. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19681. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19682. /* aad, aad length */
  19683. {0x00}, 0,
  19684. /* msg, msg length */
  19685. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19686. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19687. /* ct, ct length */
  19688. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19689. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19690. /* tag, tag length */
  19691. {0xe6, 0x0e, 0x7c, 0x50, 0x11, 0xa6, 0xdb, 0xf2,
  19692. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19693. /* valid */
  19694. 0,
  19695. },
  19696. {
  19697. /* key, key length */
  19698. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19699. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19700. /* iv, iv length */
  19701. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19702. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19703. /* aad, aad length */
  19704. {0x00}, 0,
  19705. /* msg, msg length */
  19706. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19707. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19708. /* ct, ct length */
  19709. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19710. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19711. /* tag, tag length */
  19712. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0x72,
  19713. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19714. /* valid */
  19715. 0,
  19716. },
  19717. {
  19718. /* key, key length */
  19719. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19720. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19721. /* iv, iv length */
  19722. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19723. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19724. /* aad, aad length */
  19725. {0x00}, 0,
  19726. /* msg, msg length */
  19727. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19728. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19729. /* ct, ct length */
  19730. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19731. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19732. /* tag, tag length */
  19733. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19734. 0x53, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19735. /* valid */
  19736. 0,
  19737. },
  19738. {
  19739. /* key, key length */
  19740. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19741. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19742. /* iv, iv length */
  19743. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19744. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19745. /* aad, aad length */
  19746. {0x00}, 0,
  19747. /* msg, msg length */
  19748. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19749. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19750. /* ct, ct length */
  19751. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19752. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19753. /* tag, tag length */
  19754. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19755. 0xd2, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19756. /* valid */
  19757. 0,
  19758. },
  19759. {
  19760. /* key, key length */
  19761. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19762. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19763. /* iv, iv length */
  19764. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19765. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19766. /* aad, aad length */
  19767. {0x00}, 0,
  19768. /* msg, msg length */
  19769. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19770. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19771. /* ct, ct length */
  19772. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19773. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19774. /* tag, tag length */
  19775. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19776. 0x52, 0xb8, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19777. /* valid */
  19778. 0,
  19779. },
  19780. {
  19781. /* key, key length */
  19782. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19783. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19784. /* iv, iv length */
  19785. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19786. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19787. /* aad, aad length */
  19788. {0x00}, 0,
  19789. /* msg, msg length */
  19790. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19791. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19792. /* ct, ct length */
  19793. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19794. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19795. /* tag, tag length */
  19796. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19797. 0x52, 0x98, 0xb0, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19798. /* valid */
  19799. 0,
  19800. },
  19801. {
  19802. /* key, key length */
  19803. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19804. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19805. /* iv, iv length */
  19806. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19807. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19808. /* aad, aad length */
  19809. {0x00}, 0,
  19810. /* msg, msg length */
  19811. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19812. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19813. /* ct, ct length */
  19814. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19815. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19816. /* tag, tag length */
  19817. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19818. 0x52, 0x98, 0xb1, 0x92, 0x9a, 0xc3, 0x56, 0xa7}, 16,
  19819. /* valid */
  19820. 0,
  19821. },
  19822. {
  19823. /* key, key length */
  19824. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19825. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19826. /* iv, iv length */
  19827. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19828. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19829. /* aad, aad length */
  19830. {0x00}, 0,
  19831. /* msg, msg length */
  19832. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19833. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19834. /* ct, ct length */
  19835. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19836. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19837. /* tag, tag length */
  19838. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19839. 0x52, 0x98, 0xb1, 0x92, 0x99, 0xc3, 0x56, 0xa7}, 16,
  19840. /* valid */
  19841. 0,
  19842. },
  19843. {
  19844. /* key, key length */
  19845. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19846. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19847. /* iv, iv length */
  19848. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19849. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19850. /* aad, aad length */
  19851. {0x00}, 0,
  19852. /* msg, msg length */
  19853. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19854. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19855. /* ct, ct length */
  19856. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19857. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19858. /* tag, tag length */
  19859. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19860. 0x52, 0x98, 0xb1, 0x92, 0x1b, 0xc3, 0x56, 0xa7}, 16,
  19861. /* valid */
  19862. 0,
  19863. },
  19864. {
  19865. /* key, key length */
  19866. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19867. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19868. /* iv, iv length */
  19869. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19870. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19871. /* aad, aad length */
  19872. {0x00}, 0,
  19873. /* msg, msg length */
  19874. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19875. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19876. /* ct, ct length */
  19877. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19878. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19879. /* tag, tag length */
  19880. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19881. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa6}, 16,
  19882. /* valid */
  19883. 0,
  19884. },
  19885. {
  19886. /* key, key length */
  19887. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19888. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19889. /* iv, iv length */
  19890. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19891. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19892. /* aad, aad length */
  19893. {0x00}, 0,
  19894. /* msg, msg length */
  19895. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19896. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19897. /* ct, ct length */
  19898. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19899. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19900. /* tag, tag length */
  19901. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19902. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa5}, 16,
  19903. /* valid */
  19904. 0,
  19905. },
  19906. {
  19907. /* key, key length */
  19908. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19909. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19910. /* iv, iv length */
  19911. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19912. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19913. /* aad, aad length */
  19914. {0x00}, 0,
  19915. /* msg, msg length */
  19916. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19917. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19918. /* ct, ct length */
  19919. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19920. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19921. /* tag, tag length */
  19922. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19923. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xe7}, 16,
  19924. /* valid */
  19925. 0,
  19926. },
  19927. {
  19928. /* key, key length */
  19929. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19930. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19931. /* iv, iv length */
  19932. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19933. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19934. /* aad, aad length */
  19935. {0x00}, 0,
  19936. /* msg, msg length */
  19937. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19938. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19939. /* ct, ct length */
  19940. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19941. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19942. /* tag, tag length */
  19943. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19944. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0x27}, 16,
  19945. /* valid */
  19946. 0,
  19947. },
  19948. {
  19949. /* key, key length */
  19950. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19951. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19952. /* iv, iv length */
  19953. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19954. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19955. /* aad, aad length */
  19956. {0x00}, 0,
  19957. /* msg, msg length */
  19958. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19959. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19960. /* ct, ct length */
  19961. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19962. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19963. /* tag, tag length */
  19964. {0xe7, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19965. 0x53, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19966. /* valid */
  19967. 0,
  19968. },
  19969. {
  19970. /* key, key length */
  19971. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19972. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19973. /* iv, iv length */
  19974. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19975. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19976. /* aad, aad length */
  19977. {0x00}, 0,
  19978. /* msg, msg length */
  19979. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19980. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19981. /* ct, ct length */
  19982. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19983. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19984. /* tag, tag length */
  19985. {0xe6, 0x0e, 0x7c, 0xd0, 0x13, 0xa6, 0xdb, 0x72,
  19986. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19987. /* valid */
  19988. 0,
  19989. },
  19990. {
  19991. /* key, key length */
  19992. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19993. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19994. /* iv, iv length */
  19995. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19996. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19997. /* aad, aad length */
  19998. {0x00}, 0,
  19999. /* msg, msg length */
  20000. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  20001. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  20002. /* ct, ct length */
  20003. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  20004. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  20005. /* tag, tag length */
  20006. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0x72,
  20007. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0x27}, 16,
  20008. /* valid */
  20009. 0,
  20010. },
  20011. {
  20012. /* key, key length */
  20013. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20014. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  20015. /* iv, iv length */
  20016. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  20017. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  20018. /* aad, aad length */
  20019. {0x00}, 0,
  20020. /* msg, msg length */
  20021. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  20022. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  20023. /* ct, ct length */
  20024. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  20025. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  20026. /* tag, tag length */
  20027. {0x19, 0xf1, 0x83, 0xaf, 0xec, 0x59, 0x24, 0x0d,
  20028. 0xad, 0x67, 0x4e, 0x6d, 0x64, 0x3c, 0xa9, 0x58}, 16,
  20029. /* valid */
  20030. 0,
  20031. },
  20032. {
  20033. /* key, key length */
  20034. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20035. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  20036. /* iv, iv length */
  20037. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  20038. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  20039. /* aad, aad length */
  20040. {0x00}, 0,
  20041. /* msg, msg length */
  20042. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  20043. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  20044. /* ct, ct length */
  20045. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  20046. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  20047. /* tag, tag length */
  20048. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  20049. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 16,
  20050. /* valid */
  20051. 0,
  20052. },
  20053. {
  20054. /* key, key length */
  20055. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20056. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  20057. /* iv, iv length */
  20058. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  20059. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  20060. /* aad, aad length */
  20061. {0x00}, 0,
  20062. /* msg, msg length */
  20063. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  20064. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  20065. /* ct, ct length */
  20066. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  20067. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  20068. /* tag, tag length */
  20069. {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  20070. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 16,
  20071. /* valid */
  20072. 0,
  20073. },
  20074. {
  20075. /* key, key length */
  20076. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20077. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  20078. /* iv, iv length */
  20079. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  20080. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  20081. /* aad, aad length */
  20082. {0x00}, 0,
  20083. /* msg, msg length */
  20084. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  20085. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  20086. /* ct, ct length */
  20087. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  20088. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  20089. /* tag, tag length */
  20090. {0x66, 0x8e, 0xfc, 0xd0, 0x93, 0x26, 0x5b, 0x72,
  20091. 0xd2, 0x18, 0x31, 0x12, 0x1b, 0x43, 0xd6, 0x27}, 16,
  20092. /* valid */
  20093. 0,
  20094. },
  20095. {
  20096. /* key, key length */
  20097. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20098. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  20099. /* iv, iv length */
  20100. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  20101. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  20102. /* aad, aad length */
  20103. {0x00}, 0,
  20104. /* msg, msg length */
  20105. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  20106. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  20107. /* ct, ct length */
  20108. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  20109. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  20110. /* tag, tag length */
  20111. {0xe7, 0x0f, 0x7d, 0x51, 0x12, 0xa7, 0xda, 0xf3,
  20112. 0x53, 0x99, 0xb0, 0x93, 0x9a, 0xc2, 0x57, 0xa6}, 16,
  20113. /* valid */
  20114. 0,
  20115. },
  20116. };
  20117. byte ciphertext[sizeof(vectors[0].ct)];
  20118. byte authtag[sizeof(vectors[0].tag)];
  20119. int i;
  20120. int len;
  20121. int ret;
  20122. for (i = 0; i < (int)(sizeof(vectors)/sizeof(vectors[0])); i++) {
  20123. XMEMSET(ciphertext, 0, sizeof(ciphertext));
  20124. len = sizeof(authtag);
  20125. ExpectIntEQ(wc_AesEaxEncryptAuth(vectors[i].key, vectors[i].key_length,
  20126. ciphertext,
  20127. vectors[i].msg, vectors[i].msg_length,
  20128. vectors[i].iv, vectors[i].iv_length,
  20129. authtag, len,
  20130. vectors[i].aad, vectors[i].aad_length),
  20131. 0);
  20132. /* check ciphertext matches vector */
  20133. ExpectIntEQ(XMEMCMP(ciphertext, vectors[i].ct, vectors[i].ct_length),
  20134. 0);
  20135. /* check that computed tag matches vector only for vectors marked as valid */
  20136. ret = XMEMCMP(authtag, vectors[i].tag, len);
  20137. if (vectors[i].valid) {
  20138. ExpectIntEQ(ret, 0);
  20139. }
  20140. else {
  20141. ExpectIntNE(ret, 0);
  20142. }
  20143. XMEMSET(ciphertext, 0, sizeof(ciphertext));
  20144. /* Decrypt, checking that the computed auth tags match */
  20145. ExpectIntEQ(wc_AesEaxDecryptAuth(vectors[i].key, vectors[i].key_length,
  20146. ciphertext,
  20147. vectors[i].ct, vectors[i].ct_length,
  20148. vectors[i].iv, vectors[i].iv_length,
  20149. authtag, len,
  20150. vectors[i].aad, vectors[i].aad_length),
  20151. 0);
  20152. /* check decrypted ciphertext matches vector plaintext */
  20153. ExpectIntEQ(XMEMCMP(ciphertext, vectors[i].msg, vectors[i].msg_length),
  20154. 0);
  20155. }
  20156. return EXPECT_RESULT();
  20157. } /* END test_wc_AesEaxVectors */
  20158. /*
  20159. * Testing test_wc_AesEaxEncryptAuth()
  20160. */
  20161. static int test_wc_AesEaxEncryptAuth(void)
  20162. {
  20163. EXPECT_DECLS;
  20164. const byte key[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20165. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  20166. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  20167. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
  20168. const byte iv[] = {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 aad[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
  20173. const byte msg[] = {0x00, 0x01, 0x02, 0x03, 0x04};
  20174. byte ciphertext[sizeof(msg)];
  20175. byte authtag[AES_BLOCK_SIZE];
  20176. int i;
  20177. int len;
  20178. len = sizeof(authtag);
  20179. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  20180. ciphertext,
  20181. msg, sizeof(msg),
  20182. iv, sizeof(iv),
  20183. authtag, (word32)len,
  20184. aad, sizeof(aad)),
  20185. 0);
  20186. /* Test null checking */
  20187. ExpectIntEQ(wc_AesEaxEncryptAuth(NULL, sizeof(key),
  20188. ciphertext,
  20189. msg, sizeof(msg),
  20190. iv, sizeof(iv),
  20191. authtag, (word32)len,
  20192. aad, sizeof(aad)),
  20193. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20194. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  20195. NULL,
  20196. msg, sizeof(msg),
  20197. iv, sizeof(iv),
  20198. authtag, (word32)len,
  20199. aad, sizeof(aad)),
  20200. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20201. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  20202. ciphertext,
  20203. NULL, sizeof(msg),
  20204. iv, sizeof(iv),
  20205. authtag, (word32)len,
  20206. aad, sizeof(aad)),
  20207. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20208. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  20209. ciphertext,
  20210. msg, sizeof(msg),
  20211. NULL, sizeof(iv),
  20212. authtag, (word32)len,
  20213. aad, sizeof(aad)),
  20214. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20215. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  20216. ciphertext,
  20217. msg, sizeof(msg),
  20218. iv, sizeof(iv),
  20219. NULL, (word32)len,
  20220. aad, sizeof(aad)),
  20221. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20222. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  20223. ciphertext,
  20224. msg, sizeof(msg),
  20225. iv, sizeof(iv),
  20226. authtag, (word32)len,
  20227. NULL, sizeof(aad)),
  20228. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20229. /* Test bad key lengths */
  20230. for (i = 0; i <= 32; i++) {
  20231. int exp_ret;
  20232. if (i == AES_128_KEY_SIZE || i == AES_192_KEY_SIZE
  20233. || i == AES_256_KEY_SIZE) {
  20234. exp_ret = 0;
  20235. }
  20236. else {
  20237. exp_ret = WC_NO_ERR_TRACE(BAD_FUNC_ARG);
  20238. }
  20239. ExpectIntEQ(wc_AesEaxEncryptAuth(key, (word32)i,
  20240. ciphertext,
  20241. msg, sizeof(msg),
  20242. iv, sizeof(iv),
  20243. authtag, (word32)len,
  20244. aad, sizeof(aad)),
  20245. exp_ret);
  20246. }
  20247. /* Test auth tag size out of range */
  20248. len = AES_BLOCK_SIZE + 1;
  20249. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  20250. ciphertext,
  20251. msg, sizeof(msg),
  20252. iv, sizeof(iv),
  20253. authtag, (word32)len,
  20254. aad, sizeof(aad)),
  20255. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20256. return EXPECT_RESULT();
  20257. } /* END test_wc_AesEaxEncryptAuth() */
  20258. /*
  20259. * Testing test_wc_AesEaxDecryptAuth()
  20260. */
  20261. static int test_wc_AesEaxDecryptAuth(void)
  20262. {
  20263. EXPECT_DECLS;
  20264. const byte key[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20265. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  20266. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  20267. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
  20268. const byte iv[] = {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 aad[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
  20273. const byte ct[] = {0x00, 0x01, 0x02, 0x03, 0x04};
  20274. /* Garbage tag that should always fail for above aad */
  20275. const byte tag[] = {0xFE, 0xED, 0xBE, 0xEF, 0xDE, 0xAD, 0xC0, 0xDE,
  20276. 0xCA, 0xFE, 0xBE, 0xEF, 0xDE, 0xAF, 0xBE, 0xEF};
  20277. byte plaintext[sizeof(ct)];
  20278. int i;
  20279. int len;
  20280. len = sizeof(tag);
  20281. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20282. plaintext,
  20283. ct, sizeof(ct),
  20284. iv, sizeof(iv),
  20285. tag, (word32)len,
  20286. aad, sizeof(aad)),
  20287. WC_NO_ERR_TRACE(AES_EAX_AUTH_E));
  20288. /* Test null checking */
  20289. ExpectIntEQ(wc_AesEaxDecryptAuth(NULL, sizeof(key),
  20290. plaintext,
  20291. ct, sizeof(ct),
  20292. iv, sizeof(iv),
  20293. tag, (word32)len,
  20294. aad, sizeof(aad)),
  20295. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20296. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20297. NULL,
  20298. ct, sizeof(ct),
  20299. iv, sizeof(iv),
  20300. tag, (word32)len,
  20301. aad, sizeof(aad)),
  20302. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20303. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20304. plaintext,
  20305. NULL, sizeof(ct),
  20306. iv, sizeof(iv),
  20307. tag, (word32)len,
  20308. aad, sizeof(aad)),
  20309. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20310. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20311. plaintext,
  20312. ct, sizeof(ct),
  20313. NULL, sizeof(iv),
  20314. tag, (word32)len,
  20315. aad, sizeof(aad)),
  20316. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20317. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20318. plaintext,
  20319. ct, sizeof(ct),
  20320. iv, sizeof(iv),
  20321. NULL, (word32)len,
  20322. aad, sizeof(aad)),
  20323. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20324. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20325. plaintext,
  20326. ct, sizeof(ct),
  20327. iv, sizeof(iv),
  20328. tag, (word32)len,
  20329. NULL, sizeof(aad)),
  20330. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20331. /* Test bad key lengths */
  20332. for (i = 0; i <= 32; i++) {
  20333. int exp_ret;
  20334. if (i == AES_128_KEY_SIZE || i == AES_192_KEY_SIZE
  20335. || i == AES_256_KEY_SIZE) {
  20336. exp_ret = WC_NO_ERR_TRACE(AES_EAX_AUTH_E);
  20337. }
  20338. else {
  20339. exp_ret = WC_NO_ERR_TRACE(BAD_FUNC_ARG);
  20340. }
  20341. ExpectIntEQ(wc_AesEaxDecryptAuth(key, (word32)i,
  20342. plaintext,
  20343. ct, sizeof(ct),
  20344. iv, sizeof(iv),
  20345. tag, (word32)len,
  20346. aad, sizeof(aad)),
  20347. exp_ret);
  20348. }
  20349. /* Test auth tag size out of range */
  20350. len = AES_BLOCK_SIZE + 1;
  20351. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20352. plaintext,
  20353. ct, sizeof(ct),
  20354. iv, sizeof(iv),
  20355. tag, (word32)len,
  20356. aad, sizeof(aad)),
  20357. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20358. return EXPECT_RESULT();
  20359. } /* END test_wc_AesEaxDecryptAuth() */
  20360. #endif /* WOLFSSL_AES_EAX &&
  20361. * (!HAVE_FIPS || FIPS_VERSION_GE(5, 3)) && !HAVE_SELFTEST
  20362. */
  20363. /*
  20364. * Testing wc_InitDsaKey()
  20365. */
  20366. static int test_wc_InitDsaKey(void)
  20367. {
  20368. EXPECT_DECLS;
  20369. #ifndef NO_DSA
  20370. DsaKey key;
  20371. XMEMSET(&key, 0, sizeof(DsaKey));
  20372. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20373. /* Pass in bad args. */
  20374. ExpectIntEQ(wc_InitDsaKey(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20375. wc_FreeDsaKey(&key);
  20376. #endif
  20377. return EXPECT_RESULT();
  20378. } /* END test_wc_InitDsaKey */
  20379. /*
  20380. * Testing wc_DsaSign() and wc_DsaVerify()
  20381. */
  20382. static int test_wc_DsaSignVerify(void)
  20383. {
  20384. EXPECT_DECLS;
  20385. #if !defined(NO_DSA)
  20386. DsaKey key;
  20387. WC_RNG rng;
  20388. wc_Sha sha;
  20389. byte signature[DSA_SIG_SIZE];
  20390. byte hash[WC_SHA_DIGEST_SIZE];
  20391. word32 idx = 0;
  20392. word32 bytes;
  20393. int answer;
  20394. #ifdef USE_CERT_BUFFERS_1024
  20395. byte tmp[ONEK_BUF];
  20396. XMEMSET(tmp, 0, sizeof(tmp));
  20397. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  20398. bytes = sizeof_dsa_key_der_1024;
  20399. #elif defined(USE_CERT_BUFFERS_2048)
  20400. byte tmp[TWOK_BUF];
  20401. XMEMSET(tmp, 0, sizeof(tmp));
  20402. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  20403. bytes = sizeof_dsa_key_der_2048;
  20404. #else
  20405. byte tmp[TWOK_BUF];
  20406. XFILE fp = XBADFILE;
  20407. XMEMSET(tmp, 0, sizeof(tmp));
  20408. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb")) != XBADFILE);
  20409. ExpectTrue((bytes = (word32)XFREAD(tmp, 1, sizeof(tmp), fp)) > 0);
  20410. if (fp != XBADFILE)
  20411. XFCLOSE(fp);
  20412. #endif /* END USE_CERT_BUFFERS_1024 */
  20413. ExpectIntEQ(wc_InitSha(&sha), 0);
  20414. ExpectIntEQ(wc_ShaUpdate(&sha, tmp, bytes), 0);
  20415. ExpectIntEQ(wc_ShaFinal(&sha, hash), 0);
  20416. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20417. ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, &idx, &key, bytes), 0);
  20418. ExpectIntEQ(wc_InitRng(&rng), 0);
  20419. /* Sign. */
  20420. ExpectIntEQ(wc_DsaSign(hash, signature, &key, &rng), 0);
  20421. /* Test bad args. */
  20422. ExpectIntEQ(wc_DsaSign(NULL, signature, &key, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20423. ExpectIntEQ(wc_DsaSign(hash, NULL, &key, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20424. ExpectIntEQ(wc_DsaSign(hash, signature, NULL, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20425. ExpectIntEQ(wc_DsaSign(hash, signature, &key, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20426. /* Verify. */
  20427. ExpectIntEQ(wc_DsaVerify(hash, signature, &key, &answer), 0);
  20428. ExpectIntEQ(answer, 1);
  20429. /* Pass in bad args. */
  20430. ExpectIntEQ(wc_DsaVerify(NULL, signature, &key, &answer), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20431. ExpectIntEQ(wc_DsaVerify(hash, NULL, &key, &answer), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20432. ExpectIntEQ(wc_DsaVerify(hash, signature, NULL, &answer), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20433. ExpectIntEQ(wc_DsaVerify(hash, signature, &key, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20434. #if !defined(HAVE_FIPS) && defined(WOLFSSL_PUBLIC_MP)
  20435. /* hard set q to 0 and test fail case */
  20436. mp_free(&key.q);
  20437. mp_init(&key.q);
  20438. ExpectIntEQ(wc_DsaSign(hash, signature, &key, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20439. mp_set(&key.q, 1);
  20440. ExpectIntEQ(wc_DsaSign(hash, signature, &key, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20441. #endif
  20442. DoExpectIntEQ(wc_FreeRng(&rng),0);
  20443. wc_FreeDsaKey(&key);
  20444. wc_ShaFree(&sha);
  20445. #endif
  20446. return EXPECT_RESULT();
  20447. } /* END test_wc_DsaSign */
  20448. /*
  20449. * Testing wc_DsaPrivateKeyDecode() and wc_DsaPublicKeyDecode()
  20450. */
  20451. static int test_wc_DsaPublicPrivateKeyDecode(void)
  20452. {
  20453. EXPECT_DECLS;
  20454. #if !defined(NO_DSA)
  20455. DsaKey key;
  20456. word32 bytes = 0;
  20457. word32 idx = 0;
  20458. int ret = 0;
  20459. #ifdef USE_CERT_BUFFERS_1024
  20460. byte tmp[ONEK_BUF];
  20461. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  20462. bytes = sizeof_dsa_key_der_1024;
  20463. #elif defined(USE_CERT_BUFFERS_2048)
  20464. byte tmp[TWOK_BUF];
  20465. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  20466. bytes = sizeof_dsa_key_der_2048;
  20467. #else
  20468. byte tmp[TWOK_BUF];
  20469. XFILE fp = XBADFILE;
  20470. XMEMSET(tmp, 0, sizeof(tmp));
  20471. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb")) != XBADFILE);
  20472. ExpectTrue((bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), fp)) > 0);
  20473. if (fp != XBADFILE)
  20474. XFCLOSE(fp);
  20475. #endif /* END USE_CERT_BUFFERS_1024 */
  20476. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20477. ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, &idx, &key, bytes), 0);
  20478. /* Test bad args. */
  20479. ExpectIntEQ(wc_DsaPrivateKeyDecode(NULL, &idx, &key, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20480. ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, NULL, &key, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20481. ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, &idx, NULL, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20482. ExpectIntLT(ret = wc_DsaPrivateKeyDecode(tmp, &idx, &key, bytes), 0);
  20483. ExpectTrue((ret == WC_NO_ERR_TRACE(ASN_PARSE_E)) || (ret == WC_NO_ERR_TRACE(BUFFER_E)));
  20484. wc_FreeDsaKey(&key);
  20485. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20486. idx = 0; /* Reset */
  20487. ExpectIntEQ(wc_DsaPublicKeyDecode(tmp, &idx, &key, bytes), 0);
  20488. /* Test bad args. */
  20489. ExpectIntEQ(wc_DsaPublicKeyDecode(NULL, &idx, &key, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20490. ExpectIntEQ(wc_DsaPublicKeyDecode(tmp, NULL, &key, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20491. ExpectIntEQ(wc_DsaPublicKeyDecode(tmp, &idx, NULL, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20492. ExpectIntLT(ret = wc_DsaPublicKeyDecode(tmp, &idx, &key, bytes), 0);
  20493. ExpectTrue((ret == WC_NO_ERR_TRACE(ASN_PARSE_E)) || (ret == WC_NO_ERR_TRACE(BUFFER_E)));
  20494. wc_FreeDsaKey(&key);
  20495. #endif /* !NO_DSA */
  20496. return EXPECT_RESULT();
  20497. } /* END test_wc_DsaPublicPrivateKeyDecode */
  20498. /*
  20499. * Testing wc_MakeDsaKey() and wc_MakeDsaParameters()
  20500. */
  20501. static int test_wc_MakeDsaKey(void)
  20502. {
  20503. EXPECT_DECLS;
  20504. #if !defined(NO_DSA) && defined(WOLFSSL_KEY_GEN)
  20505. DsaKey genKey;
  20506. WC_RNG rng;
  20507. XMEMSET(&genKey, 0, sizeof(genKey));
  20508. XMEMSET(&rng, 0, sizeof(rng));
  20509. ExpectIntEQ(wc_InitDsaKey(&genKey), 0);
  20510. ExpectIntEQ(wc_InitRng(&rng), 0);
  20511. ExpectIntEQ(wc_MakeDsaParameters(&rng, ONEK_BUF, &genKey), 0);
  20512. /* Test bad args. */
  20513. ExpectIntEQ(wc_MakeDsaParameters(NULL, ONEK_BUF, &genKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20514. ExpectIntEQ(wc_MakeDsaParameters(&rng, ONEK_BUF, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20515. ExpectIntEQ(wc_MakeDsaParameters(&rng, ONEK_BUF + 1, &genKey),
  20516. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20517. ExpectIntEQ(wc_MakeDsaKey(&rng, &genKey), 0);
  20518. /* Test bad args. */
  20519. ExpectIntEQ(wc_MakeDsaKey(NULL, &genKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20520. ExpectIntEQ(wc_MakeDsaKey(&rng, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20521. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20522. wc_FreeDsaKey(&genKey);
  20523. #endif
  20524. return EXPECT_RESULT();
  20525. } /* END test_wc_MakeDsaKey */
  20526. /*
  20527. * Testing wc_DsaKeyToDer()
  20528. */
  20529. static int test_wc_DsaKeyToDer(void)
  20530. {
  20531. EXPECT_DECLS;
  20532. #if !defined(NO_DSA) && defined(WOLFSSL_KEY_GEN)
  20533. DsaKey key;
  20534. word32 bytes;
  20535. word32 idx = 0;
  20536. #ifdef USE_CERT_BUFFERS_1024
  20537. byte tmp[ONEK_BUF];
  20538. byte der[ONEK_BUF];
  20539. XMEMSET(tmp, 0, sizeof(tmp));
  20540. XMEMSET(der, 0, sizeof(der));
  20541. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  20542. bytes = sizeof_dsa_key_der_1024;
  20543. #elif defined(USE_CERT_BUFFERS_2048)
  20544. byte tmp[TWOK_BUF];
  20545. byte der[TWOK_BUF];
  20546. XMEMSET(tmp, 0, sizeof(tmp));
  20547. XMEMSET(der, 0, sizeof(der));
  20548. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  20549. bytes = sizeof_dsa_key_der_2048;
  20550. #else
  20551. byte tmp[TWOK_BUF];
  20552. byte der[TWOK_BUF];
  20553. XFILE fp = XBADFILE;
  20554. XMEMSET(tmp, 0, sizeof(tmp));
  20555. XMEMSET(der, 0, sizeof(der));
  20556. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb")) != XBADFILE);
  20557. ExpectTrue((bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), fp)) > 0);
  20558. if (fp != XBADFILE)
  20559. XFCLOSE(fp);
  20560. #endif /* END USE_CERT_BUFFERS_1024 */
  20561. XMEMSET(&key, 0, sizeof(DsaKey));
  20562. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20563. ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, &idx, &key, bytes), 0);
  20564. ExpectIntGE(wc_DsaKeyToDer(&key, der, bytes), 0);
  20565. ExpectIntEQ(XMEMCMP(der, tmp, bytes), 0);
  20566. /* Test bad args. */
  20567. ExpectIntEQ(wc_DsaKeyToDer(NULL, der, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20568. ExpectIntEQ(wc_DsaKeyToDer(&key, NULL, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20569. wc_FreeDsaKey(&key);
  20570. #endif /* !NO_DSA && WOLFSSL_KEY_GEN */
  20571. return EXPECT_RESULT();
  20572. } /* END test_wc_DsaKeyToDer */
  20573. /*
  20574. * Testing wc_DsaKeyToPublicDer()
  20575. * (indirectly testing setDsaPublicKey())
  20576. */
  20577. static int test_wc_DsaKeyToPublicDer(void)
  20578. {
  20579. EXPECT_DECLS;
  20580. #ifndef HAVE_SELFTEST
  20581. #if !defined(NO_DSA) && defined(WOLFSSL_KEY_GEN)
  20582. DsaKey key;
  20583. WC_RNG rng;
  20584. byte* der = NULL;
  20585. word32 sz = 0;
  20586. word32 idx = 0;
  20587. XMEMSET(&key, 0, sizeof(DsaKey));
  20588. XMEMSET(&rng, 0, sizeof(WC_RNG));
  20589. ExpectNotNull(der = (byte*)XMALLOC(ONEK_BUF, NULL,
  20590. DYNAMIC_TYPE_TMP_BUFFER));
  20591. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20592. ExpectIntEQ(wc_InitRng(&rng), 0);
  20593. ExpectIntEQ(wc_MakeDsaParameters(&rng, ONEK_BUF, &key), 0);
  20594. ExpectIntEQ(wc_MakeDsaKey(&rng, &key), 0);
  20595. ExpectIntGE(sz = (word32)wc_DsaKeyToPublicDer(&key, der, ONEK_BUF), 0);
  20596. wc_FreeDsaKey(&key);
  20597. idx = 0;
  20598. ExpectIntEQ(wc_DsaPublicKeyDecode(der, &idx, &key, sz), 0);
  20599. /* Test without the SubjectPublicKeyInfo header */
  20600. ExpectIntGE(sz = (word32)wc_SetDsaPublicKey(der, &key, ONEK_BUF, 0), 0);
  20601. wc_FreeDsaKey(&key);
  20602. idx = 0;
  20603. ExpectIntEQ(wc_DsaPublicKeyDecode(der, &idx, &key, sz), 0);
  20604. /* Test bad args. */
  20605. ExpectIntEQ(wc_DsaKeyToPublicDer(NULL, der, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20606. ExpectIntEQ(wc_DsaKeyToPublicDer(&key, NULL, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20607. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20608. wc_FreeDsaKey(&key);
  20609. XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  20610. #endif /* !NO_DSA && WOLFSSL_KEY_GEN */
  20611. #endif /* !HAVE_SELFTEST */
  20612. return EXPECT_RESULT();
  20613. } /* END test_wc_DsaKeyToPublicDer */
  20614. /*
  20615. * Testing wc_DsaImportParamsRaw()
  20616. */
  20617. static int test_wc_DsaImportParamsRaw(void)
  20618. {
  20619. EXPECT_DECLS;
  20620. #if !defined(NO_DSA)
  20621. DsaKey key;
  20622. /* [mod = L=1024, N=160], from CAVP KeyPair */
  20623. const char* p = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d"
  20624. "4b725ef341eabb47cf8a7a8a41e792a156b7ce97206c4f9c"
  20625. "5ce6fc5ae7912102b6b502e59050b5b21ce263dddb2044b6"
  20626. "52236f4d42ab4b5d6aa73189cef1ace778d7845a5c1c1c71"
  20627. "47123188f8dc551054ee162b634d60f097f719076640e209"
  20628. "80a0093113a8bd73";
  20629. const char* q = "96c5390a8b612c0e422bb2b0ea194a3ec935a281";
  20630. const char* g = "06b7861abbd35cc89e79c52f68d20875389b127361ca66822"
  20631. "138ce4991d2b862259d6b4548a6495b195aa0e0b6137ca37e"
  20632. "b23b94074d3c3d300042bdf15762812b6333ef7b07ceba786"
  20633. "07610fcc9ee68491dbc1e34cd12615474e52b18bc934fb00c"
  20634. "61d39e7da8902291c4434a4e2224c3f4fd9f93cd6f4f17fc0"
  20635. "76341a7e7d9";
  20636. /* invalid p and q parameters */
  20637. const char* invalidP = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d";
  20638. const char* invalidQ = "96c5390a";
  20639. XMEMSET(&key, 0, sizeof(DsaKey));
  20640. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20641. ExpectIntEQ(wc_DsaImportParamsRaw(&key, p, q, g), 0);
  20642. /* test bad args */
  20643. /* null key struct */
  20644. ExpectIntEQ(wc_DsaImportParamsRaw(NULL, p, q, g), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20645. /* null param pointers */
  20646. ExpectIntEQ(wc_DsaImportParamsRaw(&key, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20647. /* illegal p length */
  20648. ExpectIntEQ(wc_DsaImportParamsRaw(&key, invalidP, q, g), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20649. /* illegal q length */
  20650. ExpectIntEQ(wc_DsaImportParamsRaw(&key, p, invalidQ, g), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20651. wc_FreeDsaKey(&key);
  20652. #endif
  20653. return EXPECT_RESULT();
  20654. } /* END test_wc_DsaImportParamsRaw */
  20655. /*
  20656. * Testing wc_DsaImportParamsRawCheck()
  20657. */
  20658. static int test_wc_DsaImportParamsRawCheck(void)
  20659. {
  20660. EXPECT_DECLS;
  20661. #if !defined(NO_DSA) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  20662. DsaKey key;
  20663. int trusted = 0;
  20664. /* [mod = L=1024, N=160], from CAVP KeyPair */
  20665. const char* p = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d"
  20666. "4b725ef341eabb47cf8a7a8a41e792a156b7ce97206c4f9c"
  20667. "5ce6fc5ae7912102b6b502e59050b5b21ce263dddb2044b6"
  20668. "52236f4d42ab4b5d6aa73189cef1ace778d7845a5c1c1c71"
  20669. "47123188f8dc551054ee162b634d60f097f719076640e209"
  20670. "80a0093113a8bd73";
  20671. const char* q = "96c5390a8b612c0e422bb2b0ea194a3ec935a281";
  20672. const char* g = "06b7861abbd35cc89e79c52f68d20875389b127361ca66822"
  20673. "138ce4991d2b862259d6b4548a6495b195aa0e0b6137ca37e"
  20674. "b23b94074d3c3d300042bdf15762812b6333ef7b07ceba786"
  20675. "07610fcc9ee68491dbc1e34cd12615474e52b18bc934fb00c"
  20676. "61d39e7da8902291c4434a4e2224c3f4fd9f93cd6f4f17fc0"
  20677. "76341a7e7d9";
  20678. /* invalid p and q parameters */
  20679. const char* invalidP = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d";
  20680. const char* invalidQ = "96c5390a";
  20681. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20682. ExpectIntEQ(wc_DsaImportParamsRawCheck(&key, p, q, g, trusted, NULL), 0);
  20683. /* test bad args */
  20684. /* null key struct */
  20685. ExpectIntEQ(wc_DsaImportParamsRawCheck(NULL, p, q, g, trusted, NULL),
  20686. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20687. /* null param pointers */
  20688. ExpectIntEQ(wc_DsaImportParamsRawCheck(&key, NULL, NULL, NULL, trusted,
  20689. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20690. /* illegal p length */
  20691. ExpectIntEQ(wc_DsaImportParamsRawCheck(&key, invalidP, q, g, trusted, NULL),
  20692. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20693. /* illegal q length */
  20694. ExpectIntEQ(wc_DsaImportParamsRawCheck(&key, p, invalidQ, g, trusted, NULL),
  20695. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20696. wc_FreeDsaKey(&key);
  20697. #endif
  20698. return EXPECT_RESULT();
  20699. } /* END test_wc_DsaImportParamsRawCheck */
  20700. /*
  20701. * Testing wc_DsaExportParamsRaw()
  20702. */
  20703. static int test_wc_DsaExportParamsRaw(void)
  20704. {
  20705. EXPECT_DECLS;
  20706. #if !defined(NO_DSA)
  20707. DsaKey key;
  20708. /* [mod = L=1024, N=160], from CAVP KeyPair */
  20709. const char* p = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d"
  20710. "4b725ef341eabb47cf8a7a8a41e792a156b7ce97206c4f9c"
  20711. "5ce6fc5ae7912102b6b502e59050b5b21ce263dddb2044b6"
  20712. "52236f4d42ab4b5d6aa73189cef1ace778d7845a5c1c1c71"
  20713. "47123188f8dc551054ee162b634d60f097f719076640e209"
  20714. "80a0093113a8bd73";
  20715. const char* q = "96c5390a8b612c0e422bb2b0ea194a3ec935a281";
  20716. const char* g = "06b7861abbd35cc89e79c52f68d20875389b127361ca66822"
  20717. "138ce4991d2b862259d6b4548a6495b195aa0e0b6137ca37e"
  20718. "b23b94074d3c3d300042bdf15762812b6333ef7b07ceba786"
  20719. "07610fcc9ee68491dbc1e34cd12615474e52b18bc934fb00c"
  20720. "61d39e7da8902291c4434a4e2224c3f4fd9f93cd6f4f17fc0"
  20721. "76341a7e7d9";
  20722. const char* pCompare = "\xd3\x83\x11\xe2\xcd\x38\x8c\x3e\xd6\x98\xe8\x2f"
  20723. "\xdf\x88\xeb\x92\xb5\xa9\xa4\x83\xdc\x88\x00\x5d"
  20724. "\x4b\x72\x5e\xf3\x41\xea\xbb\x47\xcf\x8a\x7a\x8a"
  20725. "\x41\xe7\x92\xa1\x56\xb7\xce\x97\x20\x6c\x4f\x9c"
  20726. "\x5c\xe6\xfc\x5a\xe7\x91\x21\x02\xb6\xb5\x02\xe5"
  20727. "\x90\x50\xb5\xb2\x1c\xe2\x63\xdd\xdb\x20\x44\xb6"
  20728. "\x52\x23\x6f\x4d\x42\xab\x4b\x5d\x6a\xa7\x31\x89"
  20729. "\xce\xf1\xac\xe7\x78\xd7\x84\x5a\x5c\x1c\x1c\x71"
  20730. "\x47\x12\x31\x88\xf8\xdc\x55\x10\x54\xee\x16\x2b"
  20731. "\x63\x4d\x60\xf0\x97\xf7\x19\x07\x66\x40\xe2\x09"
  20732. "\x80\xa0\x09\x31\x13\xa8\xbd\x73";
  20733. const char* qCompare = "\x96\xc5\x39\x0a\x8b\x61\x2c\x0e\x42\x2b\xb2\xb0"
  20734. "\xea\x19\x4a\x3e\xc9\x35\xa2\x81";
  20735. const char* gCompare = "\x06\xb7\x86\x1a\xbb\xd3\x5c\xc8\x9e\x79\xc5\x2f"
  20736. "\x68\xd2\x08\x75\x38\x9b\x12\x73\x61\xca\x66\x82"
  20737. "\x21\x38\xce\x49\x91\xd2\xb8\x62\x25\x9d\x6b\x45"
  20738. "\x48\xa6\x49\x5b\x19\x5a\xa0\xe0\xb6\x13\x7c\xa3"
  20739. "\x7e\xb2\x3b\x94\x07\x4d\x3c\x3d\x30\x00\x42\xbd"
  20740. "\xf1\x57\x62\x81\x2b\x63\x33\xef\x7b\x07\xce\xba"
  20741. "\x78\x60\x76\x10\xfc\xc9\xee\x68\x49\x1d\xbc\x1e"
  20742. "\x34\xcd\x12\x61\x54\x74\xe5\x2b\x18\xbc\x93\x4f"
  20743. "\xb0\x0c\x61\xd3\x9e\x7d\xa8\x90\x22\x91\xc4\x43"
  20744. "\x4a\x4e\x22\x24\xc3\xf4\xfd\x9f\x93\xcd\x6f\x4f"
  20745. "\x17\xfc\x07\x63\x41\xa7\xe7\xd9";
  20746. byte pOut[MAX_DSA_PARAM_SIZE];
  20747. byte qOut[MAX_DSA_PARAM_SIZE];
  20748. byte gOut[MAX_DSA_PARAM_SIZE];
  20749. word32 pOutSz;
  20750. word32 qOutSz;
  20751. word32 gOutSz;
  20752. XMEMSET(&key, 0, sizeof(DsaKey));
  20753. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20754. /* first test using imported raw parameters, for expected */
  20755. ExpectIntEQ(wc_DsaImportParamsRaw(&key, p, q, g), 0);
  20756. pOutSz = sizeof(pOut);
  20757. qOutSz = sizeof(qOut);
  20758. gOutSz = sizeof(gOut);
  20759. ExpectIntEQ(wc_DsaExportParamsRaw(&key, pOut, &pOutSz, qOut, &qOutSz, gOut,
  20760. &gOutSz), 0);
  20761. /* validate exported parameters are correct */
  20762. ExpectIntEQ(XMEMCMP(pOut, pCompare, pOutSz), 0);
  20763. ExpectIntEQ(XMEMCMP(qOut, qCompare, qOutSz), 0);
  20764. ExpectIntEQ(XMEMCMP(gOut, gCompare, gOutSz), 0);
  20765. /* test bad args */
  20766. /* null key struct */
  20767. ExpectIntEQ(wc_DsaExportParamsRaw(NULL, pOut, &pOutSz, qOut, &qOutSz, gOut,
  20768. &gOutSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20769. /* null output pointers */
  20770. ExpectIntEQ(wc_DsaExportParamsRaw(&key, NULL, &pOutSz, NULL, &qOutSz, NULL,
  20771. &gOutSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  20772. /* null output size pointers */
  20773. ExpectIntEQ( wc_DsaExportParamsRaw(&key, pOut, NULL, qOut, NULL, gOut,
  20774. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20775. /* p output buffer size too small */
  20776. pOutSz = 1;
  20777. ExpectIntEQ(wc_DsaExportParamsRaw(&key, pOut, &pOutSz, qOut, &qOutSz, gOut,
  20778. &gOutSz), WC_NO_ERR_TRACE(BUFFER_E));
  20779. pOutSz = sizeof(pOut);
  20780. /* q output buffer size too small */
  20781. qOutSz = 1;
  20782. ExpectIntEQ(wc_DsaExportParamsRaw(&key, pOut, &pOutSz, qOut, &qOutSz, gOut,
  20783. &gOutSz), WC_NO_ERR_TRACE(BUFFER_E));
  20784. qOutSz = sizeof(qOut);
  20785. /* g output buffer size too small */
  20786. gOutSz = 1;
  20787. ExpectIntEQ(wc_DsaExportParamsRaw(&key, pOut, &pOutSz, qOut, &qOutSz, gOut,
  20788. &gOutSz), WC_NO_ERR_TRACE(BUFFER_E));
  20789. wc_FreeDsaKey(&key);
  20790. #endif
  20791. return EXPECT_RESULT();
  20792. } /* END test_wc_DsaExportParamsRaw */
  20793. /*
  20794. * Testing wc_DsaExportKeyRaw()
  20795. */
  20796. static int test_wc_DsaExportKeyRaw(void)
  20797. {
  20798. EXPECT_DECLS;
  20799. #if !defined(NO_DSA) && defined(WOLFSSL_KEY_GEN)
  20800. DsaKey key;
  20801. WC_RNG rng;
  20802. byte xOut[MAX_DSA_PARAM_SIZE];
  20803. byte yOut[MAX_DSA_PARAM_SIZE];
  20804. word32 xOutSz, yOutSz;
  20805. XMEMSET(&key, 0, sizeof(key));
  20806. XMEMSET(&rng, 0, sizeof(rng));
  20807. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20808. ExpectIntEQ(wc_InitRng(&rng), 0);
  20809. ExpectIntEQ(wc_MakeDsaParameters(&rng, 1024, &key), 0);
  20810. ExpectIntEQ(wc_MakeDsaKey(&rng, &key), 0);
  20811. /* try successful export */
  20812. xOutSz = sizeof(xOut);
  20813. yOutSz = sizeof(yOut);
  20814. ExpectIntEQ(wc_DsaExportKeyRaw(&key, xOut, &xOutSz, yOut, &yOutSz), 0);
  20815. /* test bad args */
  20816. /* null key struct */
  20817. ExpectIntEQ(wc_DsaExportKeyRaw(NULL, xOut, &xOutSz, yOut, &yOutSz),
  20818. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20819. /* null output pointers */
  20820. ExpectIntEQ(wc_DsaExportKeyRaw(&key, NULL, &xOutSz, NULL, &yOutSz),
  20821. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  20822. /* null output size pointers */
  20823. ExpectIntEQ(wc_DsaExportKeyRaw(&key, xOut, NULL, yOut, NULL),
  20824. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20825. /* x output buffer size too small */
  20826. xOutSz = 1;
  20827. ExpectIntEQ(wc_DsaExportKeyRaw(&key, xOut, &xOutSz, yOut, &yOutSz),
  20828. WC_NO_ERR_TRACE(BUFFER_E));
  20829. xOutSz = sizeof(xOut);
  20830. /* y output buffer size too small */
  20831. yOutSz = 1;
  20832. ExpectIntEQ(wc_DsaExportKeyRaw(&key, xOut, &xOutSz, yOut, &yOutSz),
  20833. WC_NO_ERR_TRACE(BUFFER_E));
  20834. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20835. wc_FreeDsaKey(&key);
  20836. #endif
  20837. return EXPECT_RESULT();
  20838. } /* END test_wc_DsaExportParamsRaw */
  20839. /*
  20840. * Testing wc_ed25519_make_key().
  20841. */
  20842. static int test_wc_ed25519_make_key(void)
  20843. {
  20844. EXPECT_DECLS;
  20845. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_MAKE_KEY)
  20846. ed25519_key key;
  20847. WC_RNG rng;
  20848. unsigned char pubkey[ED25519_PUB_KEY_SIZE+1];
  20849. int pubkey_sz = ED25519_PUB_KEY_SIZE;
  20850. XMEMSET(&key, 0, sizeof(ed25519_key));
  20851. XMEMSET(&rng, 0, sizeof(WC_RNG));
  20852. ExpectIntEQ(wc_ed25519_init(&key), 0);
  20853. ExpectIntEQ(wc_InitRng(&rng), 0);
  20854. ExpectIntEQ(wc_ed25519_make_public(&key, pubkey, (word32)pubkey_sz),
  20855. WC_NO_ERR_TRACE(ECC_PRIV_KEY_E));
  20856. ExpectIntEQ(wc_ed25519_make_public(&key, pubkey+1, (word32)pubkey_sz),
  20857. WC_NO_ERR_TRACE(ECC_PRIV_KEY_E));
  20858. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  20859. /* Test bad args. */
  20860. ExpectIntEQ(wc_ed25519_make_key(NULL, ED25519_KEY_SIZE, &key),
  20861. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20862. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, NULL),
  20863. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20864. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE - 1, &key),
  20865. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20866. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE + 1, &key),
  20867. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20868. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20869. wc_ed25519_free(&key);
  20870. #endif
  20871. return EXPECT_RESULT();
  20872. } /* END test_wc_ed25519_make_key */
  20873. /*
  20874. * Testing wc_ed25519_init()
  20875. */
  20876. static int test_wc_ed25519_init(void)
  20877. {
  20878. EXPECT_DECLS;
  20879. #if defined(HAVE_ED25519)
  20880. ed25519_key key;
  20881. XMEMSET(&key, 0, sizeof(ed25519_key));
  20882. ExpectIntEQ(wc_ed25519_init(&key), 0);
  20883. /* Test bad args. */
  20884. ExpectIntEQ(wc_ed25519_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20885. wc_ed25519_free(&key);
  20886. #endif
  20887. return EXPECT_RESULT();
  20888. } /* END test_wc_ed25519_init */
  20889. /*
  20890. * Test wc_ed25519_sign_msg() and wc_ed25519_verify_msg()
  20891. */
  20892. static int test_wc_ed25519_sign_msg(void)
  20893. {
  20894. EXPECT_DECLS;
  20895. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_SIGN)
  20896. WC_RNG rng;
  20897. ed25519_key key;
  20898. byte msg[] = "Everybody gets Friday off.\n";
  20899. byte sig[ED25519_SIG_SIZE+1];
  20900. word32 msglen = sizeof(msg);
  20901. word32 siglen = ED25519_SIG_SIZE;
  20902. word32 badSigLen = ED25519_SIG_SIZE - 1;
  20903. #ifdef HAVE_ED25519_VERIFY
  20904. int verify_ok = 0; /*1 = Verify success.*/
  20905. #endif
  20906. /* Initialize stack variables. */
  20907. XMEMSET(&key, 0, sizeof(ed25519_key));
  20908. XMEMSET(&rng, 0, sizeof(WC_RNG));
  20909. XMEMSET(sig, 0, sizeof(sig));
  20910. /* Initialize key. */
  20911. ExpectIntEQ(wc_ed25519_init(&key), 0);
  20912. ExpectIntEQ(wc_InitRng(&rng), 0);
  20913. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  20914. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig, &siglen, &key), 0);
  20915. ExpectIntEQ(siglen, ED25519_SIG_SIZE);
  20916. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig+1, &siglen, &key), 0);
  20917. ExpectIntEQ(siglen, ED25519_SIG_SIZE);
  20918. /* Test bad args. */
  20919. ExpectIntEQ(wc_ed25519_sign_msg(NULL, msglen, sig, &siglen, &key),
  20920. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20921. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, NULL, &siglen, &key),
  20922. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20923. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig, NULL, &key),
  20924. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20925. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig, &siglen, NULL),
  20926. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20927. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig, &badSigLen, &key),
  20928. WC_NO_ERR_TRACE(BUFFER_E));
  20929. ExpectIntEQ(badSigLen, ED25519_SIG_SIZE);
  20930. badSigLen -= 1;
  20931. #ifdef HAVE_ED25519_VERIFY
  20932. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen, msg, msglen, &verify_ok,
  20933. &key), 0);
  20934. ExpectIntEQ(verify_ok, 1);
  20935. /* Test bad args. */
  20936. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen - 1, msg, msglen,
  20937. &verify_ok, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20938. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen + 1, msg, msglen,
  20939. &verify_ok, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20940. ExpectIntEQ(wc_ed25519_verify_msg(NULL, siglen, msg, msglen, &verify_ok,
  20941. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20942. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen, NULL, msglen, &verify_ok,
  20943. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20944. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen, msg, msglen, NULL, &key),
  20945. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20946. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen, msg, msglen, &verify_ok,
  20947. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20948. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, badSigLen, msg, msglen, &verify_ok,
  20949. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20950. #endif /* Verify. */
  20951. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20952. wc_ed25519_free(&key);
  20953. #endif
  20954. return EXPECT_RESULT();
  20955. } /* END test_wc_ed25519_sign_msg */
  20956. /*
  20957. * Testing wc_ed25519_import_public()
  20958. */
  20959. static int test_wc_ed25519_import_public(void)
  20960. {
  20961. EXPECT_DECLS;
  20962. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_IMPORT)
  20963. ed25519_key pubKey;
  20964. WC_RNG rng;
  20965. const byte in[] = "Ed25519PublicKeyUnitTest......\n";
  20966. word32 inlen = sizeof(in);
  20967. XMEMSET(&pubKey, 0, sizeof(ed25519_key));
  20968. XMEMSET(&rng, 0, sizeof(WC_RNG));
  20969. ExpectIntEQ(wc_ed25519_init(&pubKey), 0);
  20970. ExpectIntEQ(wc_InitRng(&rng), 0);
  20971. #ifdef HAVE_ED25519_MAKE_KEY
  20972. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &pubKey), 0);
  20973. #endif
  20974. ExpectIntEQ(wc_ed25519_import_public_ex(in, inlen, &pubKey, 1), 0);
  20975. ExpectIntEQ(XMEMCMP(in, pubKey.p, inlen), 0);
  20976. /* Test bad args. */
  20977. ExpectIntEQ(wc_ed25519_import_public(NULL, inlen, &pubKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20978. ExpectIntEQ(wc_ed25519_import_public(in, inlen, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20979. ExpectIntEQ(wc_ed25519_import_public(in, inlen - 1, &pubKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20980. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20981. wc_ed25519_free(&pubKey);
  20982. #endif
  20983. return EXPECT_RESULT();
  20984. } /* END wc_ed25519_import_public */
  20985. /*
  20986. * Testing wc_ed25519_import_private_key()
  20987. */
  20988. static int test_wc_ed25519_import_private_key(void)
  20989. {
  20990. EXPECT_DECLS;
  20991. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_IMPORT)
  20992. ed25519_key key;
  20993. WC_RNG rng;
  20994. const byte privKey[] = "Ed25519PrivateKeyUnitTest.....\n";
  20995. const byte pubKey[] = "Ed25519PublicKeyUnitTest......\n";
  20996. word32 privKeySz = sizeof(privKey);
  20997. word32 pubKeySz = sizeof(pubKey);
  20998. #ifdef HAVE_ED25519_KEY_EXPORT
  20999. byte bothKeys[sizeof(privKey) + sizeof(pubKey)];
  21000. word32 bothKeysSz = sizeof(bothKeys);
  21001. #endif
  21002. XMEMSET(&key, 0, sizeof(ed25519_key));
  21003. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21004. ExpectIntEQ(wc_ed25519_init(&key), 0);
  21005. ExpectIntEQ(wc_InitRng(&rng), 0);
  21006. #ifdef HAVE_ED25519_MAKE_KEY
  21007. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  21008. #endif
  21009. ExpectIntEQ(wc_ed25519_import_private_key_ex(privKey, privKeySz, pubKey,
  21010. pubKeySz, &key, 1), 0);
  21011. ExpectIntEQ(XMEMCMP(pubKey, key.p, privKeySz), 0);
  21012. ExpectIntEQ(XMEMCMP(privKey, key.k, pubKeySz), 0);
  21013. #ifdef HAVE_ED25519_KEY_EXPORT
  21014. PRIVATE_KEY_UNLOCK();
  21015. ExpectIntEQ(wc_ed25519_export_private(&key, bothKeys, &bothKeysSz), 0);
  21016. PRIVATE_KEY_LOCK();
  21017. ExpectIntEQ(wc_ed25519_import_private_key_ex(bothKeys, bothKeysSz, NULL, 0,
  21018. &key, 1), 0);
  21019. ExpectIntEQ(XMEMCMP(pubKey, key.p, privKeySz), 0);
  21020. ExpectIntEQ(XMEMCMP(privKey, key.k, pubKeySz), 0);
  21021. #endif
  21022. /* Test bad args. */
  21023. ExpectIntEQ(wc_ed25519_import_private_key(NULL, privKeySz, pubKey, pubKeySz,
  21024. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21025. ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz, NULL,
  21026. pubKeySz, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21027. ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz, pubKey,
  21028. pubKeySz, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21029. ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz - 1, pubKey,
  21030. pubKeySz, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21031. ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz, pubKey,
  21032. pubKeySz - 1, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21033. ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz, NULL, 0,
  21034. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21035. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21036. wc_ed25519_free(&key);
  21037. #endif
  21038. return EXPECT_RESULT();
  21039. } /* END test_wc_ed25519_import_private_key */
  21040. /*
  21041. * Testing wc_ed25519_export_public() and wc_ed25519_export_private_only()
  21042. */
  21043. static int test_wc_ed25519_export(void)
  21044. {
  21045. EXPECT_DECLS;
  21046. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  21047. ed25519_key key;
  21048. WC_RNG rng;
  21049. byte priv[ED25519_PRV_KEY_SIZE];
  21050. byte pub[ED25519_PUB_KEY_SIZE];
  21051. word32 privSz = sizeof(priv);
  21052. word32 pubSz = sizeof(pub);
  21053. #ifndef HAVE_ED25519_MAKE_KEY
  21054. const byte privKey[] = {
  21055. 0xf8, 0x55, 0xb7, 0xb6, 0x49, 0x3f, 0x99, 0x9c,
  21056. 0x88, 0xe3, 0xc5, 0x42, 0x6a, 0xa4, 0x47, 0x4a,
  21057. 0xe4, 0x95, 0xda, 0xdb, 0xbf, 0xf8, 0xa7, 0x42,
  21058. 0x9d, 0x0e, 0xe7, 0xd0, 0x57, 0x8f, 0x16, 0x69
  21059. };
  21060. const byte pubKey[] = {
  21061. 0x42, 0x3b, 0x7a, 0xf9, 0x82, 0xcf, 0xf9, 0xdf,
  21062. 0x19, 0xdd, 0xf3, 0xf0, 0x32, 0x29, 0x6d, 0xfa,
  21063. 0xfd, 0x76, 0x4f, 0x68, 0xc2, 0xc2, 0xe0, 0x6c,
  21064. 0x47, 0xae, 0xc2, 0x55, 0x68, 0xac, 0x0d, 0x4d
  21065. };
  21066. #endif
  21067. XMEMSET(&key, 0, sizeof(ed25519_key));
  21068. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21069. ExpectIntEQ(wc_ed25519_init(&key), 0);
  21070. ExpectIntEQ(wc_InitRng(&rng), 0);
  21071. #ifdef HAVE_ED25519_MAKE_KEY
  21072. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  21073. #else
  21074. ExpectIntEQ(wc_ed25519_import_private_key_ex(privKey, sizeof(privKey),
  21075. pubKey, sizeof(pubKey), &key, 1), 0);
  21076. #endif
  21077. PRIVATE_KEY_UNLOCK();
  21078. ExpectIntEQ(wc_ed25519_export_public(&key, pub, &pubSz), 0);
  21079. ExpectIntEQ(pubSz, ED25519_KEY_SIZE);
  21080. ExpectIntEQ(XMEMCMP(key.p, pub, pubSz), 0);
  21081. /* Test bad args. */
  21082. ExpectIntEQ(wc_ed25519_export_public(NULL, pub, &pubSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21083. ExpectIntEQ(wc_ed25519_export_public(&key, NULL, &pubSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21084. ExpectIntEQ(wc_ed25519_export_public(&key, pub, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21085. ExpectIntEQ(wc_ed25519_export_private_only(&key, priv, &privSz), 0);
  21086. ExpectIntEQ(privSz, ED25519_KEY_SIZE);
  21087. ExpectIntEQ(XMEMCMP(key.k, priv, privSz), 0);
  21088. /* Test bad args. */
  21089. ExpectIntEQ(wc_ed25519_export_private_only(NULL, priv, &privSz),
  21090. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21091. ExpectIntEQ(wc_ed25519_export_private_only(&key, NULL, &privSz),
  21092. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21093. ExpectIntEQ(wc_ed25519_export_private_only(&key, priv, NULL),
  21094. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21095. PRIVATE_KEY_LOCK();
  21096. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21097. wc_ed25519_free(&key);
  21098. #endif
  21099. return EXPECT_RESULT();
  21100. } /* END test_wc_ed25519_export */
  21101. /*
  21102. * Testing wc_ed25519_size()
  21103. */
  21104. static int test_wc_ed25519_size(void)
  21105. {
  21106. EXPECT_DECLS;
  21107. #if defined(HAVE_ED25519)
  21108. ed25519_key key;
  21109. WC_RNG rng;
  21110. #ifndef HAVE_ED25519_MAKE_KEY
  21111. const byte privKey[] = {
  21112. 0xf8, 0x55, 0xb7, 0xb6, 0x49, 0x3f, 0x99, 0x9c,
  21113. 0x88, 0xe3, 0xc5, 0x42, 0x6a, 0xa4, 0x47, 0x4a,
  21114. 0xe4, 0x95, 0xda, 0xdb, 0xbf, 0xf8, 0xa7, 0x42,
  21115. 0x9d, 0x0e, 0xe7, 0xd0, 0x57, 0x8f, 0x16, 0x69
  21116. };
  21117. const byte pubKey[] = {
  21118. 0x42, 0x3b, 0x7a, 0xf9, 0x82, 0xcf, 0xf9, 0xdf,
  21119. 0x19, 0xdd, 0xf3, 0xf0, 0x32, 0x29, 0x6d, 0xfa,
  21120. 0xfd, 0x76, 0x4f, 0x68, 0xc2, 0xc2, 0xe0, 0x6c,
  21121. 0x47, 0xae, 0xc2, 0x55, 0x68, 0xac, 0x0d, 0x4d
  21122. };
  21123. #endif
  21124. XMEMSET(&key, 0, sizeof(ed25519_key));
  21125. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21126. ExpectIntEQ(wc_ed25519_init(&key), 0);
  21127. ExpectIntEQ(wc_InitRng(&rng), 0);
  21128. #ifdef HAVE_ED25519_MAKE_KEY
  21129. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  21130. #else
  21131. ExpectIntEQ(wc_ed25519_import_private_key_ex(privKey, sizeof(privKey),
  21132. pubKey, sizeof(pubKey), &key, 1), 0);
  21133. #endif
  21134. ExpectIntEQ(wc_ed25519_size(&key), ED25519_KEY_SIZE);
  21135. /* Test bad args. */
  21136. ExpectIntEQ(wc_ed25519_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21137. ExpectIntEQ(wc_ed25519_sig_size(&key), ED25519_SIG_SIZE);
  21138. /* Test bad args. */
  21139. ExpectIntEQ(wc_ed25519_sig_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21140. ExpectIntEQ(wc_ed25519_pub_size(&key), ED25519_PUB_KEY_SIZE);
  21141. /* Test bad args. */
  21142. ExpectIntEQ(wc_ed25519_pub_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21143. ExpectIntEQ(wc_ed25519_priv_size(&key), ED25519_PRV_KEY_SIZE);
  21144. /* Test bad args. */
  21145. ExpectIntEQ(wc_ed25519_priv_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21146. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21147. wc_ed25519_free(&key);
  21148. #endif
  21149. return EXPECT_RESULT();
  21150. } /* END test_wc_ed25519_size */
  21151. /*
  21152. * Testing wc_ed25519_export_private() and wc_ed25519_export_key()
  21153. */
  21154. static int test_wc_ed25519_exportKey(void)
  21155. {
  21156. EXPECT_DECLS;
  21157. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  21158. WC_RNG rng;
  21159. ed25519_key key;
  21160. byte priv[ED25519_PRV_KEY_SIZE];
  21161. byte pub[ED25519_PUB_KEY_SIZE];
  21162. byte privOnly[ED25519_PRV_KEY_SIZE];
  21163. word32 privSz = sizeof(priv);
  21164. word32 pubSz = sizeof(pub);
  21165. word32 privOnlySz = sizeof(privOnly);
  21166. #ifndef HAVE_ED25519_MAKE_KEY
  21167. const byte privKey[] = {
  21168. 0xf8, 0x55, 0xb7, 0xb6, 0x49, 0x3f, 0x99, 0x9c,
  21169. 0x88, 0xe3, 0xc5, 0x42, 0x6a, 0xa4, 0x47, 0x4a,
  21170. 0xe4, 0x95, 0xda, 0xdb, 0xbf, 0xf8, 0xa7, 0x42,
  21171. 0x9d, 0x0e, 0xe7, 0xd0, 0x57, 0x8f, 0x16, 0x69
  21172. };
  21173. const byte pubKey[] = {
  21174. 0x42, 0x3b, 0x7a, 0xf9, 0x82, 0xcf, 0xf9, 0xdf,
  21175. 0x19, 0xdd, 0xf3, 0xf0, 0x32, 0x29, 0x6d, 0xfa,
  21176. 0xfd, 0x76, 0x4f, 0x68, 0xc2, 0xc2, 0xe0, 0x6c,
  21177. 0x47, 0xae, 0xc2, 0x55, 0x68, 0xac, 0x0d, 0x4d
  21178. };
  21179. #endif
  21180. XMEMSET(&key, 0, sizeof(ed25519_key));
  21181. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21182. ExpectIntEQ(wc_ed25519_init(&key), 0);
  21183. ExpectIntEQ(wc_InitRng(&rng), 0);
  21184. #ifdef HAVE_ED25519_MAKE_KEY
  21185. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  21186. #else
  21187. ExpectIntEQ(wc_ed25519_import_private_key_ex(privKey, sizeof(privKey),
  21188. pubKey, sizeof(pubKey), &key, 1), 0);
  21189. #endif
  21190. PRIVATE_KEY_UNLOCK();
  21191. ExpectIntEQ(wc_ed25519_export_private(&key, privOnly, &privOnlySz), 0);
  21192. /* Test bad args. */
  21193. ExpectIntEQ(wc_ed25519_export_private(NULL, privOnly, &privOnlySz),
  21194. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21195. ExpectIntEQ(wc_ed25519_export_private(&key, NULL, &privOnlySz),
  21196. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21197. ExpectIntEQ(wc_ed25519_export_private(&key, privOnly, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21198. ExpectIntEQ(wc_ed25519_export_key(&key, priv, &privSz, pub, &pubSz), 0);
  21199. /* Test bad args. */
  21200. ExpectIntEQ(wc_ed25519_export_key(NULL, priv, &privSz, pub, &pubSz),
  21201. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21202. ExpectIntEQ(wc_ed25519_export_key(&key, NULL, &privSz, pub, &pubSz),
  21203. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21204. ExpectIntEQ(wc_ed25519_export_key(&key, priv, NULL, pub, &pubSz),
  21205. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21206. ExpectIntEQ(wc_ed25519_export_key(&key, priv, &privSz, NULL, &pubSz),
  21207. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21208. ExpectIntEQ(wc_ed25519_export_key(&key, priv, &privSz, pub, NULL),
  21209. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21210. PRIVATE_KEY_LOCK();
  21211. /* Cross check output. */
  21212. ExpectIntEQ(XMEMCMP(priv, privOnly, privSz), 0);
  21213. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21214. wc_ed25519_free(&key);
  21215. #endif
  21216. return EXPECT_RESULT();
  21217. } /* END test_wc_ed25519_exportKey */
  21218. /*
  21219. * Testing wc_Ed25519PublicKeyToDer
  21220. */
  21221. static int test_wc_Ed25519PublicKeyToDer(void)
  21222. {
  21223. EXPECT_DECLS;
  21224. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT) && \
  21225. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  21226. ed25519_key key;
  21227. byte derBuf[1024];
  21228. XMEMSET(&key, 0, sizeof(ed25519_key));
  21229. /* Test bad args */
  21230. ExpectIntEQ(wc_Ed25519PublicKeyToDer(NULL, NULL, 0, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21231. ExpectIntEQ(wc_ed25519_init(&key), 0);
  21232. ExpectIntEQ(wc_Ed25519PublicKeyToDer(&key, derBuf, 0, 0), WC_NO_ERR_TRACE(BUFFER_E));
  21233. wc_ed25519_free(&key);
  21234. /* Test good args */
  21235. if (EXPECT_SUCCESS()) {
  21236. WC_RNG rng;
  21237. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21238. ExpectIntEQ(wc_ed25519_init(&key), 0);
  21239. ExpectIntEQ(wc_InitRng(&rng), 0);
  21240. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  21241. /* length only */
  21242. ExpectIntGT(wc_Ed25519PublicKeyToDer(&key, NULL, 0, 0), 0);
  21243. ExpectIntGT(wc_Ed25519PublicKeyToDer(&key, NULL, 0, 1), 0);
  21244. ExpectIntGT(wc_Ed25519PublicKeyToDer(&key, derBuf,
  21245. (word32)sizeof(derBuf), 1), 0);
  21246. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21247. wc_ed25519_free(&key);
  21248. }
  21249. #endif
  21250. return EXPECT_RESULT();
  21251. } /* END testing wc_Ed25519PublicKeyToDer */
  21252. /*
  21253. * Testing wc_curve25519_init and wc_curve25519_free.
  21254. */
  21255. static int test_wc_curve25519_init(void)
  21256. {
  21257. EXPECT_DECLS;
  21258. #if defined(HAVE_CURVE25519)
  21259. curve25519_key key;
  21260. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21261. /* Test bad args for wc_curve25519_init */
  21262. ExpectIntEQ(wc_curve25519_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21263. /* Test good args for wc_curve_25519_free */
  21264. wc_curve25519_free(&key);
  21265. /* Test bad args for wc_curve25519 free. */
  21266. wc_curve25519_free(NULL);
  21267. #endif
  21268. return EXPECT_RESULT();
  21269. } /* END test_wc_curve25519_init and wc_curve_25519_free*/
  21270. /*
  21271. * Testing test_wc_curve25519_size.
  21272. */
  21273. static int test_wc_curve25519_size(void)
  21274. {
  21275. EXPECT_DECLS;
  21276. #if defined(HAVE_CURVE25519)
  21277. curve25519_key key;
  21278. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21279. /* Test good args for wc_curve25519_size */
  21280. ExpectIntEQ(wc_curve25519_size(&key), CURVE25519_KEYSIZE);
  21281. /* Test bad args for wc_curve25519_size */
  21282. ExpectIntEQ(wc_curve25519_size(NULL), 0);
  21283. wc_curve25519_free(&key);
  21284. #endif
  21285. return EXPECT_RESULT();
  21286. } /* END test_wc_curve25519_size*/
  21287. /*
  21288. * Testing test_wc_curve25519_export_key_raw().
  21289. */
  21290. static int test_wc_curve25519_export_key_raw(void)
  21291. {
  21292. EXPECT_DECLS;
  21293. #if defined(HAVE_CURVE25519) && defined(HAVE_CURVE25519_KEY_EXPORT)
  21294. curve25519_key key;
  21295. WC_RNG rng;
  21296. byte privateKey[CURVE25519_KEYSIZE];
  21297. byte publicKey[CURVE25519_KEYSIZE];
  21298. word32 prvkSz;
  21299. word32 pubkSz;
  21300. byte prik[CURVE25519_KEYSIZE];
  21301. byte pubk[CURVE25519_KEYSIZE];
  21302. word32 prksz;
  21303. word32 pbksz;
  21304. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21305. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21306. ExpectIntEQ(wc_InitRng(&rng), 0);
  21307. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21308. /* bad-argument-test cases - target function should return BAD_FUNC_ARG */
  21309. prvkSz = CURVE25519_KEYSIZE;
  21310. pubkSz = CURVE25519_KEYSIZE;
  21311. ExpectIntEQ(wc_curve25519_export_key_raw(NULL, privateKey, &prvkSz,
  21312. publicKey, &pubkSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21313. prvkSz = CURVE25519_KEYSIZE;
  21314. pubkSz = CURVE25519_KEYSIZE;
  21315. ExpectIntEQ(wc_curve25519_export_key_raw(&key, NULL, &prvkSz, publicKey,
  21316. &pubkSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21317. prvkSz = CURVE25519_KEYSIZE;
  21318. pubkSz = CURVE25519_KEYSIZE;
  21319. ExpectIntEQ(wc_curve25519_export_key_raw(&key, privateKey, NULL,
  21320. publicKey, &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, &prvkSz,
  21324. NULL, &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. publicKey, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21329. /* cross-testing */
  21330. prksz = CURVE25519_KEYSIZE;
  21331. ExpectIntEQ(wc_curve25519_export_private_raw(&key, prik, &prksz), 0);
  21332. pbksz = CURVE25519_KEYSIZE;
  21333. ExpectIntEQ(wc_curve25519_export_public(&key, pubk, &pbksz), 0);
  21334. prvkSz = CURVE25519_KEYSIZE;
  21335. /* pubkSz = CURVE25519_KEYSIZE; */
  21336. ExpectIntEQ(wc_curve25519_export_key_raw(&key, privateKey, &prvkSz,
  21337. publicKey, &pubkSz), 0);
  21338. ExpectIntEQ(prksz, CURVE25519_KEYSIZE);
  21339. ExpectIntEQ(pbksz, CURVE25519_KEYSIZE);
  21340. ExpectIntEQ(prvkSz, CURVE25519_KEYSIZE);
  21341. ExpectIntEQ(pubkSz, CURVE25519_KEYSIZE);
  21342. ExpectIntEQ(XMEMCMP(privateKey, prik, CURVE25519_KEYSIZE), 0);
  21343. ExpectIntEQ(XMEMCMP(publicKey, pubk, CURVE25519_KEYSIZE), 0);
  21344. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21345. wc_curve25519_free(&key);
  21346. #endif
  21347. return EXPECT_RESULT();
  21348. } /* end of test_wc_curve25519_export_key_raw */
  21349. /*
  21350. * Testing test_wc_curve25519_export_key_raw_ex().
  21351. */
  21352. static int test_wc_curve25519_export_key_raw_ex(void)
  21353. {
  21354. EXPECT_DECLS;
  21355. #if defined(HAVE_CURVE25519) && defined(HAVE_CURVE25519_KEY_EXPORT)
  21356. curve25519_key key;
  21357. WC_RNG rng;
  21358. byte privateKey[CURVE25519_KEYSIZE];
  21359. byte publicKey[CURVE25519_KEYSIZE];
  21360. word32 prvkSz;
  21361. word32 pubkSz;
  21362. byte prik[CURVE25519_KEYSIZE];
  21363. byte pubk[CURVE25519_KEYSIZE];
  21364. word32 prksz;
  21365. word32 pbksz;
  21366. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21367. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21368. ExpectIntEQ(wc_InitRng(&rng), 0);
  21369. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21370. /* bad-argument-test cases - target function should return BAD_FUNC_ARG */
  21371. prvkSz = CURVE25519_KEYSIZE;
  21372. pubkSz = CURVE25519_KEYSIZE;
  21373. ExpectIntEQ(wc_curve25519_export_key_raw_ex(NULL, privateKey,
  21374. &prvkSz, publicKey, &pubkSz, EC25519_LITTLE_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21375. prvkSz = CURVE25519_KEYSIZE;
  21376. pubkSz = CURVE25519_KEYSIZE;
  21377. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, NULL,
  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, privateKey,
  21382. NULL, 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. &prvkSz, NULL, &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, publicKey, NULL, 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(NULL, privateKey,
  21394. &prvkSz, publicKey, &pubkSz, EC25519_BIG_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21395. prvkSz = CURVE25519_KEYSIZE;
  21396. pubkSz = CURVE25519_KEYSIZE;
  21397. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, NULL,
  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, privateKey,
  21402. NULL, 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. &prvkSz, NULL, &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, publicKey, NULL, EC25519_BIG_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21411. /* illegal value for endian */
  21412. prvkSz = CURVE25519_KEYSIZE;
  21413. /* pubkSz = CURVE25519_KEYSIZE; */
  21414. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey, &prvkSz,
  21415. publicKey, NULL, EC25519_BIG_ENDIAN + 10), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21416. /* cross-testing */
  21417. prksz = CURVE25519_KEYSIZE;
  21418. ExpectIntEQ(wc_curve25519_export_private_raw( &key, prik, &prksz), 0);
  21419. pbksz = CURVE25519_KEYSIZE;
  21420. ExpectIntEQ(wc_curve25519_export_public( &key, pubk, &pbksz), 0);
  21421. prvkSz = CURVE25519_KEYSIZE;
  21422. /* pubkSz = CURVE25519_KEYSIZE; */
  21423. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey, &prvkSz,
  21424. publicKey, &pubkSz, EC25519_BIG_ENDIAN), 0);
  21425. ExpectIntEQ(prksz, CURVE25519_KEYSIZE);
  21426. ExpectIntEQ(pbksz, CURVE25519_KEYSIZE);
  21427. ExpectIntEQ(prvkSz, CURVE25519_KEYSIZE);
  21428. ExpectIntEQ(pubkSz, CURVE25519_KEYSIZE);
  21429. ExpectIntEQ(XMEMCMP(privateKey, prik, CURVE25519_KEYSIZE), 0);
  21430. ExpectIntEQ(XMEMCMP(publicKey, pubk, CURVE25519_KEYSIZE), 0);
  21431. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey, &prvkSz,
  21432. publicKey, &pubkSz, EC25519_LITTLE_ENDIAN), 0);
  21433. ExpectIntEQ(prvkSz, CURVE25519_KEYSIZE);
  21434. ExpectIntEQ(pubkSz, CURVE25519_KEYSIZE);
  21435. /* try once with another endian */
  21436. prvkSz = CURVE25519_KEYSIZE;
  21437. pubkSz = CURVE25519_KEYSIZE;
  21438. ExpectIntEQ(wc_curve25519_export_key_raw_ex( &key, privateKey, &prvkSz,
  21439. publicKey, &pubkSz, EC25519_BIG_ENDIAN), 0);
  21440. ExpectIntEQ(prvkSz, CURVE25519_KEYSIZE);
  21441. ExpectIntEQ(pubkSz, CURVE25519_KEYSIZE);
  21442. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21443. wc_curve25519_free(&key);
  21444. #endif
  21445. return EXPECT_RESULT();
  21446. } /* end of test_wc_curve25519_export_key_raw_ex */
  21447. /*
  21448. * Testing wc_curve25519_make_key
  21449. */
  21450. static int test_wc_curve25519_make_key(void)
  21451. {
  21452. EXPECT_DECLS;
  21453. #if defined(HAVE_CURVE25519)
  21454. curve25519_key key;
  21455. WC_RNG rng;
  21456. int keysize;
  21457. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21458. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21459. ExpectIntEQ(wc_InitRng(&rng), 0);
  21460. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21461. ExpectIntEQ(keysize = wc_curve25519_size(&key), CURVE25519_KEYSIZE);
  21462. ExpectIntEQ(wc_curve25519_make_key(&rng, keysize, &key), 0);
  21463. /* test bad cases*/
  21464. ExpectIntEQ(wc_curve25519_make_key(NULL, 0, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21465. ExpectIntEQ(wc_curve25519_make_key(&rng, keysize, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21466. ExpectIntEQ(wc_curve25519_make_key(NULL, keysize, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21467. ExpectIntEQ(wc_curve25519_make_key(&rng, 0, &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21468. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21469. wc_curve25519_free(&key);
  21470. #endif
  21471. return EXPECT_RESULT();
  21472. } /* END test_wc_curve25519_make_key*/
  21473. /*
  21474. * Testing wc_curve25519_shared_secret_ex
  21475. */
  21476. static int test_wc_curve25519_shared_secret_ex(void)
  21477. {
  21478. EXPECT_DECLS;
  21479. #if defined(HAVE_CURVE25519)
  21480. curve25519_key private_key;
  21481. curve25519_key public_key;
  21482. WC_RNG rng;
  21483. byte out[CURVE25519_KEYSIZE];
  21484. word32 outLen = sizeof(out);
  21485. int endian = EC25519_BIG_ENDIAN;
  21486. ExpectIntEQ(wc_curve25519_init(&private_key), 0);
  21487. ExpectIntEQ(wc_curve25519_init(&public_key), 0);
  21488. ExpectIntEQ(wc_InitRng(&rng), 0);
  21489. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &private_key),
  21490. 0);
  21491. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &public_key),
  21492. 0);
  21493. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, out,
  21494. &outLen, endian), 0);
  21495. /* test bad cases*/
  21496. ExpectIntEQ(wc_curve25519_shared_secret_ex(NULL, NULL, NULL, 0, endian),
  21497. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21498. ExpectIntEQ(wc_curve25519_shared_secret_ex(NULL, &public_key, out, &outLen,
  21499. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21500. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, NULL, out, &outLen,
  21501. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21502. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, NULL,
  21503. &outLen, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21504. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, out,
  21505. NULL, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21506. /* curve25519.c is checking for public_key size less than or equal to 0x7f,
  21507. * increasing to 0x8f checks for error being returned*/
  21508. public_key.p.point[CURVE25519_KEYSIZE-1] = 0x8F;
  21509. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, out,
  21510. &outLen, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21511. outLen = outLen - 2;
  21512. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, out,
  21513. &outLen, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21514. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21515. wc_curve25519_free(&private_key);
  21516. wc_curve25519_free(&public_key);
  21517. #endif
  21518. return EXPECT_RESULT();
  21519. } /* END test_wc_curve25519_shared_secret_ex*/
  21520. /*
  21521. * Testing wc_curve25519_make_pub
  21522. */
  21523. static int test_wc_curve25519_make_pub(void)
  21524. {
  21525. EXPECT_DECLS;
  21526. #ifdef HAVE_CURVE25519
  21527. curve25519_key key;
  21528. WC_RNG rng;
  21529. byte out[CURVE25519_KEYSIZE];
  21530. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21531. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21532. ExpectIntEQ(wc_InitRng(&rng), 0);
  21533. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21534. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof(out), out,
  21535. (int)sizeof(key.k), key.k), 0);
  21536. /* test bad cases*/
  21537. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof(key.k) - 1, key.k,
  21538. (int)sizeof out, out), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21539. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out, out, (int)sizeof(key.k),
  21540. NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21541. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out - 1, out,
  21542. (int)sizeof(key.k), key.k), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21543. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out, NULL,
  21544. (int)sizeof(key.k), key.k), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21545. /* verify clamping test */
  21546. key.k[0] |= ~248;
  21547. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out, out, (int)sizeof(key.k),
  21548. key.k), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21549. key.k[0] &= 248;
  21550. /* repeat the expected-to-succeed test. */
  21551. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out, out, (int)sizeof(key.k),
  21552. key.k), 0);
  21553. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21554. wc_curve25519_free(&key);
  21555. #endif
  21556. return EXPECT_RESULT();
  21557. } /* END test_wc_curve25519_make_pub */
  21558. /*
  21559. * Testing test_wc_curve25519_export_public_ex
  21560. */
  21561. static int test_wc_curve25519_export_public_ex(void)
  21562. {
  21563. EXPECT_DECLS;
  21564. #if defined(HAVE_CURVE25519)
  21565. curve25519_key key;
  21566. WC_RNG rng;
  21567. byte out[CURVE25519_KEYSIZE];
  21568. word32 outLen = sizeof(out);
  21569. int endian = EC25519_BIG_ENDIAN;
  21570. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21571. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21572. ExpectIntEQ(wc_InitRng(&rng), 0);
  21573. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21574. ExpectIntEQ(wc_curve25519_export_public(&key, out, &outLen), 0);
  21575. ExpectIntEQ(wc_curve25519_export_public_ex(&key, out, &outLen, endian), 0);
  21576. /* test bad cases*/
  21577. ExpectIntEQ(wc_curve25519_export_public_ex(NULL, NULL, NULL, endian),
  21578. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21579. ExpectIntEQ(wc_curve25519_export_public_ex(NULL, out, &outLen, endian),
  21580. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21581. ExpectIntEQ(wc_curve25519_export_public_ex(&key, NULL, &outLen, endian),
  21582. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21583. ExpectIntEQ(wc_curve25519_export_public_ex(&key, out, NULL, endian),
  21584. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21585. outLen = outLen - 2;
  21586. ExpectIntEQ(wc_curve25519_export_public_ex(&key, out, &outLen, endian),
  21587. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21588. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21589. wc_curve25519_free(&key);
  21590. #endif
  21591. return EXPECT_RESULT();
  21592. } /* END test_wc_curve25519_export_public_ex*/
  21593. /*
  21594. * Testing test_wc_curve25519_import_private_raw_ex
  21595. */
  21596. static int test_wc_curve25519_import_private_raw_ex(void)
  21597. {
  21598. EXPECT_DECLS;
  21599. #if defined(HAVE_CURVE25519)
  21600. curve25519_key key;
  21601. WC_RNG rng;
  21602. byte priv[CURVE25519_KEYSIZE];
  21603. byte pub[CURVE25519_KEYSIZE];
  21604. word32 privSz = sizeof(priv);
  21605. word32 pubSz = sizeof(pub);
  21606. int endian = EC25519_BIG_ENDIAN;
  21607. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21608. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21609. ExpectIntEQ(wc_InitRng(&rng), 0);
  21610. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21611. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, priv, &privSz,
  21612. endian), 0);
  21613. ExpectIntEQ(wc_curve25519_export_public(&key, pub, &pubSz), 0);
  21614. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, pub, pubSz,
  21615. &key, endian), 0);
  21616. /* test bad cases*/
  21617. ExpectIntEQ(wc_curve25519_import_private_raw_ex(NULL, 0, NULL, 0, NULL,
  21618. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21619. ExpectIntEQ(wc_curve25519_import_private_raw_ex(NULL, privSz, pub, pubSz,
  21620. &key, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21621. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, NULL, pubSz,
  21622. &key, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21623. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, pub, pubSz,
  21624. NULL, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21625. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, 0, pub, pubSz,
  21626. &key, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21627. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, pub, 0,
  21628. &key, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21629. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, pub, pubSz,
  21630. &key, EC25519_LITTLE_ENDIAN), 0);
  21631. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21632. wc_curve25519_free(&key);
  21633. #endif
  21634. return EXPECT_RESULT();
  21635. } /* END test_wc_curve25519_import_private_raw_ex*/
  21636. /*
  21637. * Testing test_wc_curve25519_import_private
  21638. */
  21639. static int test_wc_curve25519_import_private(void)
  21640. {
  21641. EXPECT_DECLS;
  21642. #if defined(HAVE_CURVE25519)
  21643. curve25519_key key;
  21644. WC_RNG rng;
  21645. byte priv[CURVE25519_KEYSIZE];
  21646. word32 privSz = sizeof(priv);
  21647. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21648. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21649. ExpectIntEQ(wc_InitRng(&rng), 0);
  21650. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21651. ExpectIntEQ(wc_curve25519_export_private_raw(&key, priv, &privSz), 0);
  21652. ExpectIntEQ(wc_curve25519_import_private(priv, privSz, &key), 0);
  21653. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21654. wc_curve25519_free(&key);
  21655. #endif
  21656. return EXPECT_RESULT();
  21657. } /* END test_wc_curve25519_import*/
  21658. /*
  21659. * Testing test_wc_curve25519_export_private_raw_ex
  21660. */
  21661. static int test_wc_curve25519_export_private_raw_ex(void)
  21662. {
  21663. EXPECT_DECLS;
  21664. #if defined(HAVE_CURVE25519)
  21665. curve25519_key key;
  21666. byte out[CURVE25519_KEYSIZE];
  21667. word32 outLen = sizeof(out);
  21668. int endian = EC25519_BIG_ENDIAN;
  21669. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21670. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, out, &outLen, endian),
  21671. 0);
  21672. /* test bad cases*/
  21673. ExpectIntEQ(wc_curve25519_export_private_raw_ex(NULL, NULL, NULL, endian),
  21674. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21675. ExpectIntEQ(wc_curve25519_export_private_raw_ex(NULL, out, &outLen, endian),
  21676. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21677. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, NULL, &outLen,
  21678. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21679. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, out, NULL, endian),
  21680. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21681. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, out, &outLen,
  21682. EC25519_LITTLE_ENDIAN), 0);
  21683. outLen = outLen - 2;
  21684. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, out, &outLen, endian),
  21685. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21686. wc_curve25519_free(&key);
  21687. #endif
  21688. return EXPECT_RESULT();
  21689. } /* END test_wc_curve25519_export_private_raw_ex*/
  21690. /*
  21691. * Testing wc_ed448_make_key().
  21692. */
  21693. static int test_wc_ed448_make_key(void)
  21694. {
  21695. EXPECT_DECLS;
  21696. #if defined(HAVE_ED448)
  21697. ed448_key key;
  21698. WC_RNG rng;
  21699. unsigned char pubkey[ED448_PUB_KEY_SIZE];
  21700. XMEMSET(&key, 0, sizeof(ed448_key));
  21701. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21702. ExpectIntEQ(wc_ed448_init(&key), 0);
  21703. ExpectIntEQ(wc_InitRng(&rng), 0);
  21704. ExpectIntEQ(wc_ed448_make_public(&key, pubkey, sizeof(pubkey)),
  21705. WC_NO_ERR_TRACE(ECC_PRIV_KEY_E));
  21706. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21707. /* Test bad args. */
  21708. ExpectIntEQ(wc_ed448_make_key(NULL, ED448_KEY_SIZE, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21709. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21710. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE - 1, &key),
  21711. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21712. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE + 1, &key),
  21713. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21714. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21715. wc_ed448_free(&key);
  21716. #endif
  21717. return EXPECT_RESULT();
  21718. } /* END test_wc_ed448_make_key */
  21719. /*
  21720. * Testing wc_ed448_init()
  21721. */
  21722. static int test_wc_ed448_init(void)
  21723. {
  21724. EXPECT_DECLS;
  21725. #if defined(HAVE_ED448)
  21726. ed448_key key;
  21727. XMEMSET(&key, 0, sizeof(ed448_key));
  21728. ExpectIntEQ(wc_ed448_init(&key), 0);
  21729. /* Test bad args. */
  21730. ExpectIntEQ(wc_ed448_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21731. wc_ed448_free(&key);
  21732. #endif
  21733. return EXPECT_RESULT();
  21734. } /* END test_wc_ed448_init */
  21735. /*
  21736. * Test wc_ed448_sign_msg() and wc_ed448_verify_msg()
  21737. */
  21738. static int test_wc_ed448_sign_msg(void)
  21739. {
  21740. EXPECT_DECLS;
  21741. #if defined(HAVE_ED448) && defined(HAVE_ED448_SIGN)
  21742. ed448_key key;
  21743. WC_RNG rng;
  21744. byte msg[] = "Everybody gets Friday off.\n";
  21745. byte sig[ED448_SIG_SIZE];
  21746. word32 msglen = sizeof(msg);
  21747. word32 siglen = sizeof(sig);
  21748. word32 badSigLen = sizeof(sig) - 1;
  21749. #ifdef HAVE_ED448_VERIFY
  21750. int verify_ok = 0; /*1 = Verify success.*/
  21751. #endif
  21752. /* Initialize stack variables. */
  21753. XMEMSET(&key, 0, sizeof(ed448_key));
  21754. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21755. XMEMSET(sig, 0, siglen);
  21756. /* Initialize key. */
  21757. ExpectIntEQ(wc_ed448_init(&key), 0);
  21758. ExpectIntEQ(wc_InitRng(&rng), 0);
  21759. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21760. ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, sig, &siglen, &key, NULL, 0), 0);
  21761. ExpectIntEQ(siglen, ED448_SIG_SIZE);
  21762. /* Test bad args. */
  21763. ExpectIntEQ(wc_ed448_sign_msg(NULL, msglen, sig, &siglen, &key, NULL, 0),
  21764. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21765. ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, NULL, &siglen, &key, NULL, 0),
  21766. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21767. ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, sig, NULL, &key, NULL, 0),
  21768. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21769. ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, sig, &siglen, NULL, NULL, 0),
  21770. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21771. ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, sig, &badSigLen, &key, NULL, 0),
  21772. WC_NO_ERR_TRACE(BUFFER_E));
  21773. ExpectIntEQ(badSigLen, ED448_SIG_SIZE);
  21774. badSigLen -= 1;
  21775. #ifdef HAVE_ED448_VERIFY
  21776. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen, msg, msglen, &verify_ok, &key,
  21777. NULL, 0), 0);
  21778. ExpectIntEQ(verify_ok, 1);
  21779. /* Test bad args. */
  21780. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen - 1, msg, msglen, &verify_ok,
  21781. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21782. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen + 1, msg, msglen, &verify_ok,
  21783. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21784. ExpectIntEQ(wc_ed448_verify_msg(NULL, siglen, msg, msglen, &verify_ok,
  21785. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21786. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen, NULL, msglen, &verify_ok,
  21787. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21788. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen, msg, msglen, NULL,
  21789. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21790. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen, msg, msglen, &verify_ok,
  21791. NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21792. ExpectIntEQ(wc_ed448_verify_msg(sig, badSigLen, msg, msglen, &verify_ok,
  21793. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21794. #endif /* Verify. */
  21795. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21796. wc_ed448_free(&key);
  21797. #endif
  21798. return EXPECT_RESULT();
  21799. } /* END test_wc_ed448_sign_msg */
  21800. /*
  21801. * Testing wc_ed448_import_public()
  21802. */
  21803. static int test_wc_ed448_import_public(void)
  21804. {
  21805. EXPECT_DECLS;
  21806. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_IMPORT)
  21807. ed448_key pubKey;
  21808. WC_RNG rng;
  21809. const byte in[] =
  21810. "Ed448PublicKeyUnitTest.................................\n";
  21811. word32 inlen = sizeof(in);
  21812. XMEMSET(&pubKey, 0, sizeof(ed448_key));
  21813. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21814. ExpectIntEQ(wc_ed448_init(&pubKey), 0);
  21815. ExpectIntEQ(wc_InitRng(&rng), 0);
  21816. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &pubKey), 0);
  21817. ExpectIntEQ(wc_ed448_import_public_ex(in, inlen, &pubKey, 1), 0);
  21818. ExpectIntEQ(XMEMCMP(in, pubKey.p, inlen), 0);
  21819. /* Test bad args. */
  21820. ExpectIntEQ(wc_ed448_import_public(NULL, inlen, &pubKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21821. ExpectIntEQ(wc_ed448_import_public(in, inlen, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21822. ExpectIntEQ(wc_ed448_import_public(in, inlen - 1, &pubKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21823. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21824. wc_ed448_free(&pubKey);
  21825. #endif
  21826. return EXPECT_RESULT();
  21827. } /* END wc_ed448_import_public */
  21828. /*
  21829. * Testing wc_ed448_import_private_key()
  21830. */
  21831. static int test_wc_ed448_import_private_key(void)
  21832. {
  21833. EXPECT_DECLS;
  21834. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_IMPORT)
  21835. ed448_key key;
  21836. WC_RNG rng;
  21837. const byte privKey[] =
  21838. "Ed448PrivateKeyUnitTest................................\n";
  21839. const byte pubKey[] =
  21840. "Ed448PublicKeyUnitTest.................................\n";
  21841. word32 privKeySz = sizeof(privKey);
  21842. word32 pubKeySz = sizeof(pubKey);
  21843. #ifdef HAVE_ED448_KEY_EXPORT
  21844. byte bothKeys[sizeof(privKey) + sizeof(pubKey)];
  21845. word32 bothKeysSz = sizeof(bothKeys);
  21846. #endif
  21847. XMEMSET(&key, 0, sizeof(ed448_key));
  21848. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21849. ExpectIntEQ(wc_ed448_init(&key), 0);
  21850. ExpectIntEQ(wc_InitRng(&rng), 0);
  21851. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21852. ExpectIntEQ(wc_ed448_import_private_key_ex(privKey, privKeySz, pubKey,
  21853. pubKeySz, &key, 1), 0);
  21854. ExpectIntEQ(XMEMCMP(pubKey, key.p, privKeySz), 0);
  21855. ExpectIntEQ(XMEMCMP(privKey, key.k, pubKeySz), 0);
  21856. #ifdef HAVE_ED448_KEY_EXPORT
  21857. PRIVATE_KEY_UNLOCK();
  21858. ExpectIntEQ(wc_ed448_export_private(&key, bothKeys, &bothKeysSz), 0);
  21859. PRIVATE_KEY_LOCK();
  21860. ExpectIntEQ(wc_ed448_import_private_key_ex(bothKeys, bothKeysSz, NULL, 0,
  21861. &key, 1), 0);
  21862. ExpectIntEQ(XMEMCMP(pubKey, key.p, privKeySz), 0);
  21863. ExpectIntEQ(XMEMCMP(privKey, key.k, pubKeySz), 0);
  21864. #endif
  21865. /* Test bad args. */
  21866. ExpectIntEQ(wc_ed448_import_private_key(NULL, privKeySz, pubKey, pubKeySz,
  21867. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21868. ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz, NULL, pubKeySz,
  21869. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21870. ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz, pubKey,
  21871. pubKeySz, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21872. ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz - 1, pubKey,
  21873. pubKeySz, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21874. ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz, pubKey,
  21875. pubKeySz - 1, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21876. ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz, NULL, 0, &key),
  21877. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21878. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21879. wc_ed448_free(&key);
  21880. #endif
  21881. return EXPECT_RESULT();
  21882. } /* END test_wc_ed448_import_private_key */
  21883. /*
  21884. * Testing wc_ed448_export_public() and wc_ed448_export_private_only()
  21885. */
  21886. static int test_wc_ed448_export(void)
  21887. {
  21888. EXPECT_DECLS;
  21889. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  21890. ed448_key key;
  21891. WC_RNG rng;
  21892. byte priv[ED448_PRV_KEY_SIZE];
  21893. byte pub[ED448_PUB_KEY_SIZE];
  21894. word32 privSz = sizeof(priv);
  21895. word32 pubSz = sizeof(pub);
  21896. XMEMSET(&key, 0, sizeof(ed448_key));
  21897. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21898. ExpectIntEQ(wc_ed448_init(&key), 0);
  21899. ExpectIntEQ(wc_InitRng(&rng), 0);
  21900. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21901. ExpectIntEQ(wc_ed448_export_public(&key, pub, &pubSz), 0);
  21902. ExpectIntEQ(pubSz, ED448_KEY_SIZE);
  21903. ExpectIntEQ(XMEMCMP(key.p, pub, pubSz), 0);
  21904. /* Test bad args. */
  21905. ExpectIntEQ(wc_ed448_export_public(NULL, pub, &pubSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21906. ExpectIntEQ(wc_ed448_export_public(&key, NULL, &pubSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21907. ExpectIntEQ(wc_ed448_export_public(&key, pub, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21908. PRIVATE_KEY_UNLOCK();
  21909. ExpectIntEQ(wc_ed448_export_private_only(&key, priv, &privSz), 0);
  21910. ExpectIntEQ(privSz, ED448_KEY_SIZE);
  21911. ExpectIntEQ(XMEMCMP(key.k, priv, privSz), 0);
  21912. /* Test bad args. */
  21913. ExpectIntEQ(wc_ed448_export_private_only(NULL, priv, &privSz),
  21914. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21915. ExpectIntEQ(wc_ed448_export_private_only(&key, NULL, &privSz),
  21916. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21917. ExpectIntEQ(wc_ed448_export_private_only(&key, priv, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21918. PRIVATE_KEY_LOCK();
  21919. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21920. wc_ed448_free(&key);
  21921. #endif
  21922. return EXPECT_RESULT();
  21923. } /* END test_wc_ed448_export */
  21924. /*
  21925. * Testing wc_ed448_size()
  21926. */
  21927. static int test_wc_ed448_size(void)
  21928. {
  21929. EXPECT_DECLS;
  21930. #if defined(HAVE_ED448)
  21931. ed448_key key;
  21932. WC_RNG rng;
  21933. XMEMSET(&key, 0, sizeof(ed448_key));
  21934. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21935. ExpectIntEQ(wc_ed448_init(&key), 0);
  21936. ExpectIntEQ(wc_InitRng(&rng), 0);
  21937. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21938. ExpectIntEQ(wc_ed448_size(&key), ED448_KEY_SIZE);
  21939. /* Test bad args. */
  21940. ExpectIntEQ(wc_ed448_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21941. ExpectIntEQ(wc_ed448_sig_size(&key), ED448_SIG_SIZE);
  21942. /* Test bad args. */
  21943. ExpectIntEQ(wc_ed448_sig_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21944. ExpectIntEQ(wc_ed448_pub_size(&key), ED448_PUB_KEY_SIZE);
  21945. /* Test bad args. */
  21946. ExpectIntEQ(wc_ed448_pub_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21947. ExpectIntEQ(wc_ed448_priv_size(&key), ED448_PRV_KEY_SIZE);
  21948. /* Test bad args. */
  21949. ExpectIntEQ(wc_ed448_priv_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21950. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21951. wc_ed448_free(&key);
  21952. #endif
  21953. return EXPECT_RESULT();
  21954. } /* END test_wc_ed448_size */
  21955. /*
  21956. * Testing wc_ed448_export_private() and wc_ed448_export_key()
  21957. */
  21958. static int test_wc_ed448_exportKey(void)
  21959. {
  21960. EXPECT_DECLS;
  21961. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  21962. ed448_key key;
  21963. WC_RNG rng;
  21964. byte priv[ED448_PRV_KEY_SIZE];
  21965. byte pub[ED448_PUB_KEY_SIZE];
  21966. byte privOnly[ED448_PRV_KEY_SIZE];
  21967. word32 privSz = sizeof(priv);
  21968. word32 pubSz = sizeof(pub);
  21969. word32 privOnlySz = sizeof(privOnly);
  21970. XMEMSET(&key, 0, sizeof(ed448_key));
  21971. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21972. ExpectIntEQ(wc_ed448_init(&key), 0);
  21973. ExpectIntEQ(wc_InitRng(&rng), 0);
  21974. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21975. PRIVATE_KEY_UNLOCK();
  21976. ExpectIntEQ(wc_ed448_export_private(&key, privOnly, &privOnlySz), 0);
  21977. /* Test bad args. */
  21978. ExpectIntEQ(wc_ed448_export_private(NULL, privOnly, &privOnlySz),
  21979. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21980. ExpectIntEQ(wc_ed448_export_private(&key, NULL, &privOnlySz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21981. ExpectIntEQ(wc_ed448_export_private(&key, privOnly, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21982. ExpectIntEQ(wc_ed448_export_key(&key, priv, &privSz, pub, &pubSz), 0);
  21983. /* Test bad args. */
  21984. ExpectIntEQ(wc_ed448_export_key(NULL, priv, &privSz, pub, &pubSz),
  21985. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21986. ExpectIntEQ(wc_ed448_export_key(&key, NULL, &privSz, pub, &pubSz),
  21987. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21988. ExpectIntEQ(wc_ed448_export_key(&key, priv, NULL, pub, &pubSz),
  21989. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21990. ExpectIntEQ(wc_ed448_export_key(&key, priv, &privSz, NULL, &pubSz),
  21991. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21992. ExpectIntEQ(wc_ed448_export_key(&key, priv, &privSz, pub, NULL),
  21993. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21994. PRIVATE_KEY_LOCK();
  21995. /* Cross check output. */
  21996. ExpectIntEQ(XMEMCMP(priv, privOnly, privSz), 0);
  21997. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21998. wc_ed448_free(&key);
  21999. #endif
  22000. return EXPECT_RESULT();
  22001. } /* END test_wc_ed448_exportKey */
  22002. /*
  22003. * Testing wc_Ed448PublicKeyToDer
  22004. */
  22005. static int test_wc_Ed448PublicKeyToDer(void)
  22006. {
  22007. EXPECT_DECLS;
  22008. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT) && \
  22009. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  22010. ed448_key key;
  22011. byte derBuf[1024];
  22012. XMEMSET(&key, 0, sizeof(ed448_key));
  22013. /* Test bad args */
  22014. ExpectIntEQ(wc_Ed448PublicKeyToDer(NULL, NULL, 0, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22015. ExpectIntEQ(wc_ed448_init(&key), 0);
  22016. ExpectIntEQ(wc_Ed448PublicKeyToDer(&key, derBuf, 0, 0), WC_NO_ERR_TRACE(BUFFER_E));
  22017. wc_ed448_free(&key);
  22018. /* Test good args */
  22019. if (EXPECT_SUCCESS()) {
  22020. WC_RNG rng;
  22021. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22022. ExpectIntEQ(wc_ed448_init(&key), 0);
  22023. ExpectIntEQ(wc_InitRng(&rng), 0);
  22024. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  22025. /* length only */
  22026. ExpectIntGT(wc_Ed448PublicKeyToDer(&key, NULL, 0, 0), 0);
  22027. ExpectIntGT(wc_Ed448PublicKeyToDer(&key, NULL, 0, 1), 0);
  22028. ExpectIntGT(wc_Ed448PublicKeyToDer(&key, derBuf,
  22029. (word32)sizeof(derBuf), 1), 0);
  22030. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22031. wc_ed448_free(&key);
  22032. }
  22033. #endif
  22034. return EXPECT_RESULT();
  22035. } /* END testing wc_Ed448PublicKeyToDer */
  22036. /*
  22037. * Testing wc_curve448_init and wc_curve448_free.
  22038. */
  22039. static int test_wc_curve448_init(void)
  22040. {
  22041. EXPECT_DECLS;
  22042. #if defined(HAVE_CURVE448)
  22043. curve448_key key;
  22044. /* Test bad args for wc_curve448_init */
  22045. ExpectIntEQ(wc_curve448_init(&key), 0);
  22046. /* Test bad args for wc_curve448_init */
  22047. ExpectIntEQ(wc_curve448_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22048. /* Test good args for wc_curve_448_free */
  22049. wc_curve448_free(&key);
  22050. /* Test bad args for wc_curve448_free */
  22051. wc_curve448_free(NULL);
  22052. #endif
  22053. return EXPECT_RESULT();
  22054. } /* END test_wc_curve448_init and wc_curve_448_free*/
  22055. /*
  22056. * Testing wc_curve448_make_key
  22057. */
  22058. static int test_wc_curve448_make_key(void)
  22059. {
  22060. EXPECT_DECLS;
  22061. #if defined(HAVE_CURVE448)
  22062. curve448_key key;
  22063. WC_RNG rng;
  22064. int keysize;
  22065. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22066. ExpectIntEQ(wc_curve448_init(&key), 0);
  22067. ExpectIntEQ(wc_InitRng(&rng), 0);
  22068. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
  22069. ExpectIntEQ(keysize = wc_curve448_size(&key), CURVE448_KEY_SIZE);
  22070. ExpectIntEQ(wc_curve448_make_key(&rng, keysize, &key), 0);
  22071. /* test bad cases */
  22072. ExpectIntEQ(wc_curve448_make_key(NULL, 0, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22073. ExpectIntEQ(wc_curve448_make_key(&rng, keysize, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22074. ExpectIntEQ(wc_curve448_make_key(NULL, keysize, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22075. ExpectIntEQ(wc_curve448_make_key(&rng, 0, &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22076. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22077. wc_curve448_free(&key);
  22078. #endif
  22079. return EXPECT_RESULT();
  22080. } /* END test_wc_curve448_make_key*/
  22081. /*
  22082. * Testing test_wc_curve448_shared_secret_ex
  22083. */
  22084. static int test_wc_curve448_shared_secret_ex(void)
  22085. {
  22086. EXPECT_DECLS;
  22087. #if defined(HAVE_CURVE448)
  22088. curve448_key private_key;
  22089. curve448_key public_key;
  22090. WC_RNG rng;
  22091. byte out[CURVE448_KEY_SIZE];
  22092. word32 outLen = sizeof(out);
  22093. int endian = EC448_BIG_ENDIAN;
  22094. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22095. ExpectIntEQ(wc_curve448_init(&private_key), 0);
  22096. ExpectIntEQ(wc_InitRng(&rng), 0);
  22097. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &private_key), 0);
  22098. ExpectIntEQ(wc_curve448_init(&public_key), 0);
  22099. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &public_key), 0);
  22100. ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, &public_key, out,
  22101. &outLen, endian), 0);
  22102. /* test bad cases */
  22103. ExpectIntEQ(wc_curve448_shared_secret_ex(NULL, NULL, NULL, 0, endian),
  22104. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22105. ExpectIntEQ(wc_curve448_shared_secret_ex(NULL, &public_key, out, &outLen,
  22106. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22107. ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, NULL, out, &outLen,
  22108. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22109. ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, &public_key, NULL,
  22110. &outLen, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22111. ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, &public_key, out,
  22112. NULL, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22113. outLen = outLen - 2;
  22114. ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, &public_key, out,
  22115. &outLen, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22116. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22117. wc_curve448_free(&private_key);
  22118. wc_curve448_free(&public_key);
  22119. #endif
  22120. return EXPECT_RESULT();
  22121. } /* END test_wc_curve448_shared_secret_ex*/
  22122. /*
  22123. * Testing test_wc_curve448_export_public_ex
  22124. */
  22125. static int test_wc_curve448_export_public_ex(void)
  22126. {
  22127. EXPECT_DECLS;
  22128. #if defined(HAVE_CURVE448)
  22129. WC_RNG rng;
  22130. curve448_key key;
  22131. byte out[CURVE448_KEY_SIZE];
  22132. word32 outLen = sizeof(out);
  22133. int endian = EC448_BIG_ENDIAN;
  22134. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22135. ExpectIntEQ(wc_curve448_init(&key), 0);
  22136. ExpectIntEQ(wc_InitRng(&rng), 0);
  22137. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
  22138. ExpectIntEQ(wc_curve448_export_public(&key, out, &outLen), 0);
  22139. ExpectIntEQ(wc_curve448_export_public_ex(&key, out, &outLen, endian), 0);
  22140. /* test bad cases*/
  22141. ExpectIntEQ(wc_curve448_export_public_ex(NULL, NULL, NULL, endian),
  22142. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22143. ExpectIntEQ(wc_curve448_export_public_ex(NULL, out, &outLen, endian),
  22144. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22145. ExpectIntEQ(wc_curve448_export_public_ex(&key, NULL, &outLen, endian),
  22146. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22147. ExpectIntEQ(wc_curve448_export_public_ex(&key, out, NULL, endian),
  22148. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22149. outLen = outLen - 2;
  22150. ExpectIntEQ(wc_curve448_export_public_ex(&key, out, &outLen, endian),
  22151. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22152. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22153. wc_curve448_free(&key);
  22154. #endif
  22155. return EXPECT_RESULT();
  22156. } /* END test_wc_curve448_export_public_ex*/
  22157. /*
  22158. * Testing test_wc_curve448_export_private_raw_ex
  22159. */
  22160. static int test_wc_curve448_export_private_raw_ex(void)
  22161. {
  22162. EXPECT_DECLS;
  22163. #if defined(HAVE_CURVE448)
  22164. curve448_key key;
  22165. byte out[CURVE448_KEY_SIZE];
  22166. word32 outLen = sizeof(out);
  22167. int endian = EC448_BIG_ENDIAN;
  22168. ExpectIntEQ(wc_curve448_init(&key), 0);
  22169. ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, out, &outLen, endian),
  22170. 0);
  22171. /* test bad cases*/
  22172. ExpectIntEQ(wc_curve448_export_private_raw_ex(NULL, NULL, NULL, endian),
  22173. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22174. ExpectIntEQ(wc_curve448_export_private_raw_ex(NULL, out, &outLen, endian),
  22175. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22176. ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, NULL, &outLen, endian),
  22177. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22178. ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, out, NULL, endian),
  22179. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22180. ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, out, &outLen,
  22181. EC448_LITTLE_ENDIAN), 0);
  22182. outLen = outLen - 2;
  22183. ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, out, &outLen, endian),
  22184. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22185. wc_curve448_free(&key);
  22186. #endif
  22187. return EXPECT_RESULT();
  22188. } /* END test_wc_curve448_export_private_raw_ex*/
  22189. /*
  22190. * Testing test_wc_curve448_import_private_raw_ex
  22191. */
  22192. static int test_wc_curve448_import_private_raw_ex(void)
  22193. {
  22194. EXPECT_DECLS;
  22195. #if defined(HAVE_CURVE448)
  22196. curve448_key key;
  22197. WC_RNG rng;
  22198. byte priv[CURVE448_KEY_SIZE];
  22199. byte pub[CURVE448_KEY_SIZE];
  22200. word32 privSz = sizeof(priv);
  22201. word32 pubSz = sizeof(pub);
  22202. int endian = EC448_BIG_ENDIAN;
  22203. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22204. ExpectIntEQ(wc_curve448_init(&key), 0);
  22205. ExpectIntEQ(wc_InitRng(&rng), 0);
  22206. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
  22207. ExpectIntEQ(wc_curve448_export_private_raw(&key, priv, &privSz), 0);
  22208. ExpectIntEQ(wc_curve448_export_public(&key, pub, &pubSz), 0);
  22209. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, pub, pubSz,
  22210. &key, endian), 0);
  22211. /* test bad cases */
  22212. ExpectIntEQ(wc_curve448_import_private_raw_ex(NULL, 0, NULL, 0, NULL, 0),
  22213. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22214. ExpectIntEQ(wc_curve448_import_private_raw_ex(NULL, privSz, pub, pubSz,
  22215. &key, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22216. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, NULL, pubSz,
  22217. &key, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22218. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, pub, pubSz,
  22219. NULL, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22220. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, 0, pub, pubSz,
  22221. &key, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22222. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, pub, 0,
  22223. &key, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22224. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, pub, pubSz,
  22225. &key, EC448_LITTLE_ENDIAN), 0);
  22226. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22227. wc_curve448_free(&key);
  22228. #endif
  22229. return EXPECT_RESULT();
  22230. } /* END test_wc_curve448_import_private_raw_ex*/
  22231. /*
  22232. * Testing test_curve448_export_key_raw
  22233. */
  22234. static int test_wc_curve448_export_key_raw(void)
  22235. {
  22236. EXPECT_DECLS;
  22237. #if defined(HAVE_CURVE448)
  22238. curve448_key key;
  22239. WC_RNG rng;
  22240. byte priv[CURVE448_KEY_SIZE];
  22241. byte pub[CURVE448_KEY_SIZE];
  22242. word32 privSz = sizeof(priv);
  22243. word32 pubSz = sizeof(pub);
  22244. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22245. ExpectIntEQ(wc_curve448_init(&key), 0);
  22246. ExpectIntEQ(wc_InitRng(&rng), 0);
  22247. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
  22248. ExpectIntEQ(wc_curve448_export_private_raw(&key, priv, &privSz), 0);
  22249. ExpectIntEQ(wc_curve448_export_public(&key, pub, &pubSz), 0);
  22250. ExpectIntEQ(wc_curve448_export_key_raw(&key, priv, &privSz, pub, &pubSz),
  22251. 0);
  22252. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22253. wc_curve448_free(&key);
  22254. #endif
  22255. return EXPECT_RESULT();
  22256. } /* END test_wc_curve448_import_private_raw_ex*/
  22257. /*
  22258. * Testing test_wc_curve448_import_private
  22259. */
  22260. static int test_wc_curve448_import_private(void)
  22261. {
  22262. EXPECT_DECLS;
  22263. #if defined(HAVE_CURVE448)
  22264. curve448_key key;
  22265. WC_RNG rng;
  22266. byte priv[CURVE448_KEY_SIZE];
  22267. word32 privSz = sizeof(priv);
  22268. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22269. ExpectIntEQ(wc_curve448_init(&key), 0);
  22270. ExpectIntEQ(wc_InitRng(&rng), 0);
  22271. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
  22272. ExpectIntEQ(wc_curve448_export_private_raw(&key, priv, &privSz), 0);
  22273. ExpectIntEQ(wc_curve448_import_private(priv, privSz, &key), 0);
  22274. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22275. wc_curve448_free(&key);
  22276. #endif
  22277. return EXPECT_RESULT();
  22278. } /* END test_wc_curve448_import*/
  22279. /*
  22280. * Testing test_wc_curve448_size.
  22281. */
  22282. static int test_wc_curve448_size(void)
  22283. {
  22284. EXPECT_DECLS;
  22285. #if defined(HAVE_CURVE448)
  22286. curve448_key key;
  22287. ExpectIntEQ(wc_curve448_init(&key), 0);
  22288. /* Test good args for wc_curve448_size */
  22289. ExpectIntEQ(wc_curve448_size(&key), CURVE448_KEY_SIZE);
  22290. /* Test bad args for wc_curve448_size */
  22291. ExpectIntEQ(wc_curve448_size(NULL), 0);
  22292. wc_curve448_free(&key);
  22293. #endif
  22294. return EXPECT_RESULT();
  22295. } /* END test_wc_curve448_size*/
  22296. /*
  22297. * Testing wc_ecc_make_key.
  22298. */
  22299. static int test_wc_ecc_make_key(void)
  22300. {
  22301. EXPECT_DECLS;
  22302. #if defined(HAVE_ECC) && !defined(WC_NO_RNG)
  22303. ecc_key key;
  22304. WC_RNG rng;
  22305. int ret;
  22306. XMEMSET(&key, 0, sizeof(ecc_key));
  22307. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22308. ExpectIntEQ(wc_ecc_init(&key), 0);
  22309. ExpectIntEQ(wc_InitRng(&rng), 0);
  22310. ret = wc_ecc_make_key(&rng, KEY14, &key);
  22311. #if defined(WOLFSSL_ASYNC_CRYPT)
  22312. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22313. #endif
  22314. ExpectIntEQ(ret, 0);
  22315. /* Pass in bad args. */
  22316. ExpectIntEQ(wc_ecc_make_key(NULL, KEY14, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22317. ExpectIntEQ(wc_ecc_make_key(&rng, KEY14, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22318. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22319. wc_ecc_free(&key);
  22320. #ifdef FP_ECC
  22321. wc_ecc_fp_free();
  22322. #endif
  22323. #endif
  22324. return EXPECT_RESULT();
  22325. } /* END test_wc_ecc_make_key */
  22326. /*
  22327. * Testing wc_ecc_init()
  22328. */
  22329. static int test_wc_ecc_init(void)
  22330. {
  22331. EXPECT_DECLS;
  22332. #ifdef HAVE_ECC
  22333. ecc_key key;
  22334. XMEMSET(&key, 0, sizeof(ecc_key));
  22335. ExpectIntEQ(wc_ecc_init(&key), 0);
  22336. /* Pass in bad args. */
  22337. ExpectIntEQ(wc_ecc_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22338. wc_ecc_free(&key);
  22339. #endif
  22340. return EXPECT_RESULT();
  22341. } /* END test_wc_ecc_init */
  22342. /*
  22343. * Testing wc_ecc_check_key()
  22344. */
  22345. static int test_wc_ecc_check_key(void)
  22346. {
  22347. EXPECT_DECLS;
  22348. #if defined(HAVE_ECC) && !defined(WC_NO_RNG)
  22349. ecc_key key;
  22350. WC_RNG rng;
  22351. int ret;
  22352. XMEMSET(&rng, 0, sizeof(rng));
  22353. XMEMSET(&key, 0, sizeof(key));
  22354. ExpectIntEQ(wc_ecc_init(&key), 0);
  22355. ExpectIntEQ(wc_InitRng(&rng), 0);
  22356. ret = wc_ecc_make_key(&rng, KEY14, &key);
  22357. #if defined(WOLFSSL_ASYNC_CRYPT)
  22358. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22359. #endif
  22360. ExpectIntEQ(ret, 0);
  22361. ExpectIntEQ(wc_ecc_check_key(&key), 0);
  22362. /* Pass in bad args. */
  22363. ExpectIntEQ(wc_ecc_check_key(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22364. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22365. wc_ecc_free(&key);
  22366. #ifdef FP_ECC
  22367. wc_ecc_fp_free();
  22368. #endif
  22369. #endif
  22370. return EXPECT_RESULT();
  22371. } /* END test_wc_ecc_check_key */
  22372. /*
  22373. * Testing wc_ecc_get_generator()
  22374. */
  22375. static int test_wc_ecc_get_generator(void)
  22376. {
  22377. EXPECT_DECLS;
  22378. #if defined(HAVE_ECC) && !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST) && \
  22379. !defined(HAVE_FIPS) && defined(OPENSSL_EXTRA)
  22380. ecc_point* pt = NULL;
  22381. ExpectNotNull(pt = wc_ecc_new_point());
  22382. ExpectIntEQ(wc_ecc_get_generator(pt, wc_ecc_get_curve_idx(ECC_SECP256R1)),
  22383. MP_OKAY);
  22384. /* Test bad args. */
  22385. /* Returns Zero for bad arg. */
  22386. ExpectIntNE(wc_ecc_get_generator(pt, -1), MP_OKAY);
  22387. ExpectIntNE(wc_ecc_get_generator(NULL, wc_ecc_get_curve_idx(ECC_SECP256R1)),
  22388. MP_OKAY);
  22389. /* If we ever get to 1000 curves increase this number */
  22390. ExpectIntNE(wc_ecc_get_generator(pt, 1000), MP_OKAY);
  22391. ExpectIntNE(wc_ecc_get_generator(NULL, -1), MP_OKAY);
  22392. wc_ecc_del_point(pt);
  22393. #endif
  22394. return EXPECT_RESULT();
  22395. } /* END test_wc_ecc_get_generator */
  22396. /*
  22397. * Testing wc_ecc_size()
  22398. */
  22399. static int test_wc_ecc_size(void)
  22400. {
  22401. EXPECT_DECLS;
  22402. #if defined(HAVE_ECC) && !defined(WC_NO_RNG)
  22403. WC_RNG rng;
  22404. ecc_key key;
  22405. int ret;
  22406. XMEMSET(&key, 0, sizeof(ecc_key));
  22407. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22408. ExpectIntEQ(wc_ecc_init(&key), 0);
  22409. ExpectIntEQ(wc_InitRng(&rng), 0);
  22410. ret = wc_ecc_make_key(&rng, KEY14, &key);
  22411. #if defined(WOLFSSL_ASYNC_CRYPT)
  22412. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22413. #endif
  22414. ExpectIntEQ(ret, 0);
  22415. ExpectIntEQ(wc_ecc_size(&key), KEY14);
  22416. /* Test bad args. */
  22417. /* Returns Zero for bad arg. */
  22418. ExpectIntEQ(wc_ecc_size(NULL), 0);
  22419. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22420. wc_ecc_free(&key);
  22421. #endif
  22422. return EXPECT_RESULT();
  22423. } /* END test_wc_ecc_size */
  22424. static int test_wc_ecc_params(void)
  22425. {
  22426. EXPECT_DECLS;
  22427. /* FIPS/CAVP self-test modules do not have `wc_ecc_get_curve_params`.
  22428. It was added after certifications */
  22429. #if defined(HAVE_ECC) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  22430. const ecc_set_type* ecc_set;
  22431. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  22432. /* Test for SECP256R1 curve */
  22433. int curve_id = ECC_SECP256R1;
  22434. int curve_idx;
  22435. ExpectIntNE(curve_idx = wc_ecc_get_curve_idx(curve_id), ECC_CURVE_INVALID);
  22436. ExpectNotNull(ecc_set = wc_ecc_get_curve_params(curve_idx));
  22437. ExpectIntEQ(ecc_set->id, curve_id);
  22438. #endif
  22439. /* Test case when SECP256R1 is not enabled */
  22440. /* Test that we get curve params for index 0 */
  22441. ExpectNotNull(ecc_set = wc_ecc_get_curve_params(0));
  22442. #endif /* HAVE_ECC && !HAVE_FIPS && !HAVE_SELFTEST */
  22443. return EXPECT_RESULT();
  22444. }
  22445. /*
  22446. * Testing wc_ecc_sign_hash() and wc_ecc_verify_hash()
  22447. */
  22448. static int test_wc_ecc_signVerify_hash(void)
  22449. {
  22450. EXPECT_DECLS;
  22451. #if defined(HAVE_ECC) && defined(HAVE_ECC_SIGN) && !defined(NO_ASN) && !defined(WC_NO_RNG)
  22452. ecc_key key;
  22453. WC_RNG rng;
  22454. int ret;
  22455. #ifdef HAVE_ECC_VERIFY
  22456. int verify = 0;
  22457. #endif
  22458. word32 siglen = ECC_BUFSIZE;
  22459. byte sig[ECC_BUFSIZE];
  22460. byte adjustedSig[ECC_BUFSIZE+1];
  22461. byte digest[] = TEST_STRING;
  22462. word32 digestlen = (word32)TEST_STRING_SZ;
  22463. /* Init stack var */
  22464. XMEMSET(&key, 0, sizeof(ecc_key));
  22465. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22466. XMEMSET(sig, 0, siglen);
  22467. XMEMSET(adjustedSig, 0, ECC_BUFSIZE+1);
  22468. /* Init structs. */
  22469. ExpectIntEQ(wc_ecc_init(&key), 0);
  22470. ExpectIntEQ(wc_InitRng(&rng), 0);
  22471. ret = wc_ecc_make_key(&rng, KEY14, &key);
  22472. #if defined(WOLFSSL_ASYNC_CRYPT)
  22473. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22474. #endif
  22475. ExpectIntEQ(ret, 0);
  22476. ExpectIntEQ(wc_ecc_sign_hash(digest, digestlen, sig, &siglen, &rng, &key),
  22477. 0);
  22478. /* Check bad args. */
  22479. ExpectIntEQ(wc_ecc_sign_hash(NULL, digestlen, sig, &siglen, &rng, &key),
  22480. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22481. ExpectIntEQ(wc_ecc_sign_hash(digest, digestlen, NULL, &siglen, &rng, &key),
  22482. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22483. ExpectIntEQ(wc_ecc_sign_hash(digest, digestlen, sig, NULL, &rng, &key),
  22484. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22485. ExpectIntEQ(wc_ecc_sign_hash(digest, digestlen, sig, &siglen, NULL, &key),
  22486. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22487. ExpectIntEQ(wc_ecc_sign_hash(digest, digestlen, sig, &siglen, &rng, NULL),
  22488. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22489. #ifdef HAVE_ECC_VERIFY
  22490. ExpectIntEQ(wc_ecc_verify_hash(sig, siglen, digest, digestlen, &verify,
  22491. &key), 0);
  22492. ExpectIntEQ(verify, 1);
  22493. /* test check on length of signature passed in */
  22494. XMEMCPY(adjustedSig, sig, siglen);
  22495. adjustedSig[1] = adjustedSig[1] + 1; /* add 1 to length for extra byte*/
  22496. #ifndef NO_STRICT_ECDSA_LEN
  22497. ExpectIntNE(wc_ecc_verify_hash(adjustedSig, siglen+1, digest, digestlen,
  22498. &verify, &key), 0);
  22499. #else
  22500. /* if NO_STRICT_ECDSA_LEN is set then extra bytes after the signature
  22501. * is allowed */
  22502. ExpectIntEQ(wc_ecc_verify_hash(adjustedSig, siglen+1, digest, digestlen,
  22503. &verify, &key), 0);
  22504. #endif
  22505. /* Test bad args. */
  22506. ExpectIntEQ(wc_ecc_verify_hash(NULL, siglen, digest, digestlen, &verify,
  22507. &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22508. ExpectIntEQ(wc_ecc_verify_hash(sig, siglen, NULL, digestlen, &verify, &key),
  22509. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22510. ExpectIntEQ(wc_ecc_verify_hash(sig, siglen, digest, digestlen, NULL, &key),
  22511. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22512. ExpectIntEQ(wc_ecc_verify_hash(sig, siglen, digest, digestlen, &verify,
  22513. NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22514. #endif /* HAVE_ECC_VERIFY */
  22515. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22516. wc_ecc_free(&key);
  22517. #ifdef FP_ECC
  22518. wc_ecc_fp_free();
  22519. #endif
  22520. #endif
  22521. return EXPECT_RESULT();
  22522. } /* END test_wc_ecc_sign_hash */
  22523. /*
  22524. * Testing wc_ecc_shared_secret()
  22525. */
  22526. static int test_wc_ecc_shared_secret(void)
  22527. {
  22528. EXPECT_DECLS;
  22529. #if defined(HAVE_ECC) && defined(HAVE_ECC_DHE) && !defined(WC_NO_RNG)
  22530. ecc_key key;
  22531. ecc_key pubKey;
  22532. WC_RNG rng;
  22533. #if defined(NO_ECC256)
  22534. int ret;
  22535. #endif
  22536. byte out[KEY32];
  22537. int keySz = sizeof(out);
  22538. word32 outlen = (word32)sizeof(out);
  22539. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  22540. const char* qx =
  22541. "bb33ac4c27504ac64aa504c33cde9f36db722dce94ea2bfacb2009392c16e861";
  22542. const char* qy =
  22543. "02e9af4dd302939a315b9792217ff0cf18da9111023486e82058330b803489d8";
  22544. const char* d =
  22545. "45b66902739c6c85a1385b72e8e8c7acc4038d533504fa6c28dc348de1a8098c";
  22546. const char* curveName = "SECP256R1";
  22547. const byte expected_shared_secret[] =
  22548. {
  22549. 0x65, 0xc0, 0xd4, 0x61, 0x17, 0xe6, 0x09, 0x75,
  22550. 0xf0, 0x12, 0xa0, 0x4d, 0x0b, 0x41, 0x30, 0x7a,
  22551. 0x51, 0xf0, 0xb3, 0xaf, 0x23, 0x8f, 0x0f, 0xdf,
  22552. 0xf1, 0xff, 0x23, 0x64, 0x28, 0xca, 0xf8, 0x06
  22553. };
  22554. #endif
  22555. PRIVATE_KEY_UNLOCK();
  22556. /* Initialize variables. */
  22557. XMEMSET(&key, 0, sizeof(ecc_key));
  22558. XMEMSET(&pubKey, 0, sizeof(ecc_key));
  22559. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22560. XMEMSET(out, 0, keySz);
  22561. ExpectIntEQ(wc_ecc_init(&key), 0);
  22562. ExpectIntEQ(wc_ecc_init(&pubKey), 0);
  22563. ExpectIntEQ(wc_InitRng(&rng), 0);
  22564. #if !defined(NO_ECC256)
  22565. ExpectIntEQ(wc_ecc_import_raw(&key, qx, qy, d, curveName), 0);
  22566. ExpectIntEQ(wc_ecc_import_raw(&pubKey, qx, qy, NULL, curveName), 0);
  22567. #else
  22568. ret = wc_ecc_make_key(&rng, keySz, &key);
  22569. #if defined(WOLFSSL_ASYNC_CRYPT)
  22570. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22571. #endif
  22572. ExpectIntEQ(ret, 0);
  22573. ret = wc_ecc_make_key(&rng, keySz, &key);
  22574. #if defined(WOLFSSL_ASYNC_CRYPT)
  22575. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22576. #endif
  22577. ExpectIntEQ(ret, 0);
  22578. #endif
  22579. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  22580. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  22581. !defined(HAVE_SELFTEST)
  22582. ExpectIntEQ(wc_ecc_set_rng(&key, &rng), 0);
  22583. #endif
  22584. ExpectIntEQ(wc_ecc_shared_secret(&key, &pubKey, out, &outlen), 0);
  22585. #if !defined(NO_ECC256)
  22586. ExpectIntEQ(XMEMCMP(out, expected_shared_secret, outlen), 0);
  22587. #endif
  22588. /* Test bad args. */
  22589. ExpectIntEQ(wc_ecc_shared_secret(NULL, &pubKey, out, &outlen),
  22590. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22591. ExpectIntEQ(wc_ecc_shared_secret(&key, NULL, out, &outlen),
  22592. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22593. ExpectIntEQ(wc_ecc_shared_secret(&key, &pubKey, NULL, &outlen),
  22594. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22595. ExpectIntEQ(wc_ecc_shared_secret(&key, &pubKey, out, NULL),
  22596. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22597. /* Invalid length */
  22598. outlen = 1;
  22599. ExpectIntEQ(wc_ecc_shared_secret(&key, &pubKey, out, &outlen),
  22600. WC_NO_ERR_TRACE(BUFFER_E));
  22601. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22602. wc_ecc_free(&pubKey);
  22603. wc_ecc_free(&key);
  22604. #ifdef FP_ECC
  22605. wc_ecc_fp_free();
  22606. #endif
  22607. PRIVATE_KEY_LOCK();
  22608. #endif
  22609. return EXPECT_RESULT();
  22610. } /* END tests_wc_ecc_shared_secret */
  22611. /*
  22612. * testint wc_ecc_export_x963()
  22613. */
  22614. static int test_wc_ecc_export_x963(void)
  22615. {
  22616. EXPECT_DECLS;
  22617. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  22618. ecc_key key;
  22619. WC_RNG rng;
  22620. byte out[ECC_ASN963_MAX_BUF_SZ];
  22621. word32 outlen = sizeof(out);
  22622. int ret;
  22623. PRIVATE_KEY_UNLOCK();
  22624. /* Initialize variables. */
  22625. XMEMSET(&key, 0, sizeof(ecc_key));
  22626. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22627. XMEMSET(out, 0, outlen);
  22628. ExpectIntEQ(wc_ecc_init(&key), 0);
  22629. ExpectIntEQ(wc_InitRng(&rng), 0);
  22630. ret = wc_ecc_make_key(&rng, KEY20, &key);
  22631. #if defined(WOLFSSL_ASYNC_CRYPT)
  22632. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22633. #endif
  22634. ExpectIntEQ(ret, 0);
  22635. ExpectIntEQ(wc_ecc_export_x963(&key, out, &outlen), 0);
  22636. /* Test bad args. */
  22637. ExpectIntEQ(wc_ecc_export_x963(NULL, out, &outlen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22638. ExpectIntEQ(wc_ecc_export_x963(&key, NULL, &outlen), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  22639. ExpectIntEQ(wc_ecc_export_x963(&key, out, NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22640. key.idx = -4;
  22641. ExpectIntEQ(wc_ecc_export_x963(&key, out, &outlen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22642. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22643. wc_ecc_free(&key);
  22644. #ifdef FP_ECC
  22645. wc_ecc_fp_free();
  22646. #endif
  22647. PRIVATE_KEY_LOCK();
  22648. #endif
  22649. return EXPECT_RESULT();
  22650. } /* END test_wc_ecc_export_x963 */
  22651. /*
  22652. * Testing wc_ecc_export_x963_ex()
  22653. * compile with --enable-compkey will use compression.
  22654. */
  22655. static int test_wc_ecc_export_x963_ex(void)
  22656. {
  22657. EXPECT_DECLS;
  22658. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  22659. ecc_key key;
  22660. WC_RNG rng;
  22661. int ret;
  22662. byte out[ECC_ASN963_MAX_BUF_SZ];
  22663. word32 outlen = sizeof(out);
  22664. #ifdef HAVE_COMP_KEY
  22665. word32 badOutLen = 5;
  22666. #endif
  22667. /* Init stack variables. */
  22668. XMEMSET(&key, 0, sizeof(ecc_key));
  22669. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22670. XMEMSET(out, 0, outlen);
  22671. PRIVATE_KEY_UNLOCK();
  22672. ExpectIntEQ(wc_ecc_init(&key), 0);
  22673. ExpectIntEQ(wc_InitRng(&rng), 0);
  22674. ret = wc_ecc_make_key(&rng, KEY64, &key);
  22675. #if defined(WOLFSSL_ASYNC_CRYPT)
  22676. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22677. #endif
  22678. ExpectIntEQ(ret, 0);
  22679. #ifdef HAVE_COMP_KEY
  22680. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &outlen, COMP), 0);
  22681. #else
  22682. ExpectIntEQ(ret = wc_ecc_export_x963_ex(&key, out, &outlen, NOCOMP), 0);
  22683. #endif
  22684. /* Test bad args. */
  22685. #ifdef HAVE_COMP_KEY
  22686. ExpectIntEQ(wc_ecc_export_x963_ex(NULL, out, &outlen, COMP), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22687. ExpectIntEQ(wc_ecc_export_x963_ex(&key, NULL, &outlen, COMP), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22688. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, NULL, COMP), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22689. #if defined(HAVE_FIPS) && (!defined(FIPS_VERSION_LT) || FIPS_VERSION_LT(5,3))
  22690. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &badOutLen, COMP), WC_NO_ERR_TRACE(BUFFER_E));
  22691. #else
  22692. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &badOutLen, COMP),
  22693. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  22694. #endif
  22695. key.idx = -4;
  22696. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &outlen, COMP), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22697. #else
  22698. ExpectIntEQ(wc_ecc_export_x963_ex(NULL, out, &outlen, NOCOMP),
  22699. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22700. ExpectIntEQ(wc_ecc_export_x963_ex(&key, NULL, &outlen, NOCOMP),
  22701. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  22702. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &outlen, 1), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  22703. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, NULL, NOCOMP),
  22704. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22705. key.idx = -4;
  22706. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &outlen, NOCOMP),
  22707. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22708. #endif
  22709. PRIVATE_KEY_LOCK();
  22710. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22711. wc_ecc_free(&key);
  22712. #ifdef FP_ECC
  22713. wc_ecc_fp_free();
  22714. #endif
  22715. #endif
  22716. return EXPECT_RESULT();
  22717. } /* END test_wc_ecc_export_x963_ex */
  22718. /*
  22719. * testing wc_ecc_import_x963()
  22720. */
  22721. static int test_wc_ecc_import_x963(void)
  22722. {
  22723. EXPECT_DECLS;
  22724. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_IMPORT) && \
  22725. defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  22726. ecc_key pubKey;
  22727. ecc_key key;
  22728. WC_RNG rng;
  22729. byte x963[ECC_ASN963_MAX_BUF_SZ];
  22730. word32 x963Len = (word32)sizeof(x963);
  22731. int ret;
  22732. /* Init stack variables. */
  22733. XMEMSET(&key, 0, sizeof(ecc_key));
  22734. XMEMSET(&pubKey, 0, sizeof(ecc_key));
  22735. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22736. XMEMSET(x963, 0, x963Len);
  22737. ExpectIntEQ(wc_ecc_init(&pubKey), 0);
  22738. ExpectIntEQ(wc_ecc_init(&key), 0);
  22739. ExpectIntEQ(wc_InitRng(&rng), 0);
  22740. #if FIPS_VERSION3_GE(6,0,0)
  22741. ret = wc_ecc_make_key(&rng, KEY32, &key);
  22742. #else
  22743. ret = wc_ecc_make_key(&rng, KEY24, &key);
  22744. #endif
  22745. #if defined(WOLFSSL_ASYNC_CRYPT)
  22746. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22747. #endif
  22748. ExpectIntEQ(ret, 0);
  22749. PRIVATE_KEY_UNLOCK();
  22750. ExpectIntEQ(wc_ecc_export_x963(&key, x963, &x963Len), 0);
  22751. PRIVATE_KEY_LOCK();
  22752. ExpectIntEQ(wc_ecc_import_x963(x963, x963Len, &pubKey), 0);
  22753. /* Test bad args. */
  22754. ExpectIntEQ(wc_ecc_import_x963(NULL, x963Len, &pubKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22755. ExpectIntEQ(wc_ecc_import_x963(x963, x963Len, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22756. ExpectIntEQ(wc_ecc_import_x963(x963, x963Len + 1, &pubKey), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22757. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22758. wc_ecc_free(&key);
  22759. wc_ecc_free(&pubKey);
  22760. #ifdef FP_ECC
  22761. wc_ecc_fp_free();
  22762. #endif
  22763. #endif
  22764. return EXPECT_RESULT();
  22765. } /* END wc_ecc_import_x963 */
  22766. /*
  22767. * testing wc_ecc_import_private_key()
  22768. */
  22769. static int test_wc_ecc_import_private_key(void)
  22770. {
  22771. EXPECT_DECLS;
  22772. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_IMPORT) && \
  22773. defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  22774. ecc_key key;
  22775. ecc_key keyImp;
  22776. WC_RNG rng;
  22777. byte privKey[ECC_PRIV_KEY_BUF]; /* Raw private key.*/
  22778. byte x963Key[ECC_ASN963_MAX_BUF_SZ];
  22779. word32 privKeySz = (word32)sizeof(privKey);
  22780. word32 x963KeySz = (word32)sizeof(x963Key);
  22781. int ret;
  22782. /* Init stack variables. */
  22783. XMEMSET(&key, 0, sizeof(ecc_key));
  22784. XMEMSET(&keyImp, 0, sizeof(ecc_key));
  22785. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22786. XMEMSET(privKey, 0, privKeySz);
  22787. XMEMSET(x963Key, 0, x963KeySz);
  22788. PRIVATE_KEY_UNLOCK();
  22789. ExpectIntEQ(wc_ecc_init(&key), 0);
  22790. ExpectIntEQ(wc_ecc_init(&keyImp), 0);
  22791. ExpectIntEQ(wc_InitRng(&rng), 0);
  22792. ret = wc_ecc_make_key(&rng, KEY48, &key);
  22793. #if defined(WOLFSSL_ASYNC_CRYPT)
  22794. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22795. #endif
  22796. ExpectIntEQ(ret, 0);
  22797. PRIVATE_KEY_UNLOCK();
  22798. ExpectIntEQ(wc_ecc_export_x963(&key, x963Key, &x963KeySz), 0);
  22799. PRIVATE_KEY_LOCK();
  22800. ExpectIntEQ(wc_ecc_export_private_only(&key, privKey, &privKeySz), 0);
  22801. ExpectIntEQ(wc_ecc_import_private_key(privKey, privKeySz, x963Key,
  22802. x963KeySz, &keyImp), 0);
  22803. /* Pass in bad args. */
  22804. ExpectIntEQ(wc_ecc_import_private_key(privKey, privKeySz, x963Key,
  22805. x963KeySz, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22806. ExpectIntEQ(wc_ecc_import_private_key(NULL, privKeySz, x963Key, x963KeySz,
  22807. &keyImp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22808. PRIVATE_KEY_LOCK();
  22809. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22810. wc_ecc_free(&keyImp);
  22811. wc_ecc_free(&key);
  22812. #ifdef FP_ECC
  22813. wc_ecc_fp_free();
  22814. #endif
  22815. #endif
  22816. return EXPECT_RESULT();
  22817. } /* END test_wc_ecc_import_private_key */
  22818. /*
  22819. * Testing wc_ecc_export_private_only()
  22820. */
  22821. static int test_wc_ecc_export_private_only(void)
  22822. {
  22823. EXPECT_DECLS;
  22824. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  22825. ecc_key key;
  22826. WC_RNG rng;
  22827. byte out[ECC_PRIV_KEY_BUF];
  22828. word32 outlen = sizeof(out);
  22829. int ret;
  22830. /* Init stack variables. */
  22831. XMEMSET(&key, 0, sizeof(ecc_key));
  22832. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22833. XMEMSET(out, 0, outlen);
  22834. PRIVATE_KEY_UNLOCK();
  22835. ExpectIntEQ(wc_ecc_init(&key), 0);
  22836. ExpectIntEQ(wc_InitRng(&rng), 0);
  22837. ret = wc_ecc_make_key(&rng, KEY32, &key);
  22838. #if defined(WOLFSSL_ASYNC_CRYPT)
  22839. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22840. #endif
  22841. ExpectIntEQ(ret, 0);
  22842. ExpectIntEQ(wc_ecc_export_private_only(&key, out, &outlen), 0);
  22843. /* Pass in bad args. */
  22844. ExpectIntEQ(wc_ecc_export_private_only(NULL, out, &outlen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22845. ExpectIntEQ(wc_ecc_export_private_only(&key, NULL, &outlen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22846. ExpectIntEQ(wc_ecc_export_private_only(&key, out, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22847. PRIVATE_KEY_LOCK();
  22848. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22849. wc_ecc_free(&key);
  22850. #ifdef FP_ECC
  22851. wc_ecc_fp_free();
  22852. #endif
  22853. #endif
  22854. return EXPECT_RESULT();
  22855. } /* END test_wc_ecc_export_private_only */
  22856. /*
  22857. * Testing wc_ecc_rs_to_sig()
  22858. */
  22859. static int test_wc_ecc_rs_to_sig(void)
  22860. {
  22861. EXPECT_DECLS;
  22862. #if defined(HAVE_ECC) && !defined(NO_ASN)
  22863. /* first [P-192,SHA-1] vector from FIPS 186-3 NIST vectors */
  22864. const char* R = "6994d962bdd0d793ffddf855ec5bf2f91a9698b46258a63e";
  22865. const char* S = "02ba6465a234903744ab02bc8521405b73cf5fc00e1a9f41";
  22866. const char* zeroStr = "0";
  22867. byte sig[ECC_MAX_SIG_SIZE];
  22868. word32 siglen = (word32)sizeof(sig);
  22869. /* R and S max size is the order of curve. 2^192.*/
  22870. int keySz = KEY24;
  22871. byte r[KEY24];
  22872. byte s[KEY24];
  22873. word32 rlen = (word32)sizeof(r);
  22874. word32 slen = (word32)sizeof(s);
  22875. /* Init stack variables. */
  22876. XMEMSET(sig, 0, ECC_MAX_SIG_SIZE);
  22877. XMEMSET(r, 0, keySz);
  22878. XMEMSET(s, 0, keySz);
  22879. ExpectIntEQ(wc_ecc_rs_to_sig(R, S, sig, &siglen), 0);
  22880. ExpectIntEQ(wc_ecc_sig_to_rs(sig, siglen, r, &rlen, s, &slen), 0);
  22881. /* Test bad args. */
  22882. ExpectIntEQ(wc_ecc_rs_to_sig(NULL, S, sig, &siglen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22883. ExpectIntEQ(wc_ecc_rs_to_sig(R, NULL, sig, &siglen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22884. ExpectIntEQ(wc_ecc_rs_to_sig(R, S, sig, NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22885. ExpectIntEQ(wc_ecc_rs_to_sig(R, S, NULL, &siglen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22886. ExpectIntEQ(wc_ecc_rs_to_sig(R, zeroStr, sig, &siglen), WC_NO_ERR_TRACE(MP_ZERO_E));
  22887. ExpectIntEQ(wc_ecc_rs_to_sig(zeroStr, S, sig, &siglen), WC_NO_ERR_TRACE(MP_ZERO_E));
  22888. ExpectIntEQ(wc_ecc_sig_to_rs(NULL, siglen, r, &rlen, s, &slen),
  22889. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22890. ExpectIntEQ(wc_ecc_sig_to_rs(sig, siglen, NULL, &rlen, s, &slen),
  22891. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22892. ExpectIntEQ(wc_ecc_sig_to_rs(sig, siglen, r, NULL, s, &slen),
  22893. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22894. ExpectIntEQ(wc_ecc_sig_to_rs(sig, siglen, r, &rlen, NULL, &slen),
  22895. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22896. ExpectIntEQ(wc_ecc_sig_to_rs(sig, siglen, r, &rlen, s, NULL),
  22897. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22898. #endif
  22899. return EXPECT_RESULT();
  22900. } /* END test_wc_ecc_rs_to_sig */
  22901. static int test_wc_ecc_import_raw(void)
  22902. {
  22903. EXPECT_DECLS;
  22904. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  22905. ecc_key key;
  22906. const char* qx =
  22907. "bb33ac4c27504ac64aa504c33cde9f36db722dce94ea2bfacb2009392c16e861";
  22908. const char* qy =
  22909. "02e9af4dd302939a315b9792217ff0cf18da9111023486e82058330b803489d8";
  22910. const char* d =
  22911. "45b66902739c6c85a1385b72e8e8c7acc4038d533504fa6c28dc348de1a8098c";
  22912. const char* curveName = "SECP256R1";
  22913. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  22914. const char* kNullStr = "";
  22915. int ret;
  22916. #endif
  22917. XMEMSET(&key, 0, sizeof(ecc_key));
  22918. ExpectIntEQ(wc_ecc_init(&key), 0);
  22919. /* Test good import */
  22920. ExpectIntEQ(wc_ecc_import_raw(&key, qx, qy, d, curveName), 0);
  22921. /* Test bad args. */
  22922. ExpectIntEQ(wc_ecc_import_raw(NULL, qx, qy, d, curveName), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22923. ExpectIntEQ(wc_ecc_import_raw(&key, NULL, qy, d, curveName), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22924. ExpectIntEQ(wc_ecc_import_raw(&key, qx, NULL, d, curveName), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22925. ExpectIntEQ(wc_ecc_import_raw(&key, qx, qy, d, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22926. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  22927. #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_SP_MATH)
  22928. wc_ecc_free(&key);
  22929. #endif
  22930. ExpectIntLT(ret = wc_ecc_import_raw(&key, kNullStr, kNullStr, kNullStr,
  22931. curveName), 0);
  22932. ExpectTrue((ret == WC_NO_ERR_TRACE(ECC_INF_E)) || (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)));
  22933. #endif
  22934. #if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  22935. #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_SP_MATH)
  22936. wc_ecc_free(&key);
  22937. #endif
  22938. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  22939. ExpectIntLT(ret = wc_ecc_import_raw(&key, "0", qy, d, curveName), 0);
  22940. ExpectTrue((ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)) || (ret == WC_NO_ERR_TRACE(MP_VAL)));
  22941. #else
  22942. ExpectIntEQ(wc_ecc_import_raw(&key, "0", qy, d, curveName), 0);
  22943. #endif
  22944. #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_SP_MATH)
  22945. wc_ecc_free(&key);
  22946. #endif
  22947. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  22948. ExpectIntLT(ret = wc_ecc_import_raw(&key, qx, "0", d, curveName), 0);
  22949. ExpectTrue((ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)) || (ret == WC_NO_ERR_TRACE(MP_VAL)));
  22950. #else
  22951. ExpectIntEQ(wc_ecc_import_raw(&key, qx, "0", d, curveName), 0);
  22952. #endif
  22953. #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_SP_MATH)
  22954. wc_ecc_free(&key);
  22955. #endif
  22956. ExpectIntEQ(wc_ecc_import_raw(&key, "0", "0", d, curveName), WC_NO_ERR_TRACE(ECC_INF_E));
  22957. #endif
  22958. wc_ecc_free(&key);
  22959. #endif
  22960. return EXPECT_RESULT();
  22961. } /* END test_wc_ecc_import_raw */
  22962. static int test_wc_ecc_import_unsigned(void)
  22963. {
  22964. EXPECT_DECLS;
  22965. #if defined(HAVE_ECC) && !defined(NO_ECC256) && !defined(HAVE_SELFTEST) && \
  22966. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  22967. HAVE_FIPS_VERSION >= 2))
  22968. ecc_key key;
  22969. const byte qx[] = {
  22970. 0xbb, 0x33, 0xac, 0x4c, 0x27, 0x50, 0x4a, 0xc6,
  22971. 0x4a, 0xa5, 0x04, 0xc3, 0x3c, 0xde, 0x9f, 0x36,
  22972. 0xdb, 0x72, 0x2d, 0xce, 0x94, 0xea, 0x2b, 0xfa,
  22973. 0xcb, 0x20, 0x09, 0x39, 0x2c, 0x16, 0xe8, 0x61
  22974. };
  22975. const byte qy[] = {
  22976. 0x02, 0xe9, 0xaf, 0x4d, 0xd3, 0x02, 0x93, 0x9a,
  22977. 0x31, 0x5b, 0x97, 0x92, 0x21, 0x7f, 0xf0, 0xcf,
  22978. 0x18, 0xda, 0x91, 0x11, 0x02, 0x34, 0x86, 0xe8,
  22979. 0x20, 0x58, 0x33, 0x0b, 0x80, 0x34, 0x89, 0xd8
  22980. };
  22981. const byte d[] = {
  22982. 0x45, 0xb6, 0x69, 0x02, 0x73, 0x9c, 0x6c, 0x85,
  22983. 0xa1, 0x38, 0x5b, 0x72, 0xe8, 0xe8, 0xc7, 0xac,
  22984. 0xc4, 0x03, 0x8d, 0x53, 0x35, 0x04, 0xfa, 0x6c,
  22985. 0x28, 0xdc, 0x34, 0x8d, 0xe1, 0xa8, 0x09, 0x8c
  22986. };
  22987. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  22988. const byte nullBytes[32] = {0};
  22989. int ret;
  22990. #endif
  22991. int curveId = ECC_SECP256R1;
  22992. XMEMSET(&key, 0, sizeof(ecc_key));
  22993. ExpectIntEQ(wc_ecc_init(&key), 0);
  22994. ExpectIntEQ(wc_ecc_import_unsigned(&key, (byte*)qx, (byte*)qy, (byte*)d,
  22995. curveId), 0);
  22996. /* Test bad args. */
  22997. ExpectIntEQ(wc_ecc_import_unsigned(NULL, (byte*)qx, (byte*)qy, (byte*)d,
  22998. curveId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22999. ExpectIntEQ(wc_ecc_import_unsigned(&key, NULL, (byte*)qy, (byte*)d,
  23000. curveId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23001. ExpectIntEQ(wc_ecc_import_unsigned(&key, (byte*)qx, NULL, (byte*)d,
  23002. curveId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23003. ExpectIntEQ(wc_ecc_import_unsigned(&key, (byte*)qx, (byte*)qy, (byte*)d,
  23004. ECC_CURVE_INVALID), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23005. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  23006. ExpectIntLT(ret = wc_ecc_import_unsigned(&key, (byte*)nullBytes,
  23007. (byte*)nullBytes, (byte*)nullBytes, curveId), 0);
  23008. ExpectTrue((ret == WC_NO_ERR_TRACE(ECC_INF_E)) || (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)));
  23009. #endif
  23010. wc_ecc_free(&key);
  23011. #endif
  23012. return EXPECT_RESULT();
  23013. } /* END test_wc_ecc_import_unsigned */
  23014. /*
  23015. * Testing wc_ecc_sig_size()
  23016. */
  23017. static int test_wc_ecc_sig_size(void)
  23018. {
  23019. EXPECT_DECLS;
  23020. #if defined(HAVE_ECC) && !defined(WC_NO_RNG)
  23021. ecc_key key;
  23022. WC_RNG rng;
  23023. int keySz = KEY16;
  23024. int ret;
  23025. XMEMSET(&rng, 0, sizeof(rng));
  23026. XMEMSET(&key, 0, sizeof(key));
  23027. ExpectIntEQ(wc_ecc_init(&key), 0);
  23028. ExpectIntEQ(wc_InitRng(&rng), 0);
  23029. ret = wc_ecc_make_key(&rng, keySz, &key);
  23030. #if defined(WOLFSSL_ASYNC_CRYPT)
  23031. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  23032. #endif
  23033. ExpectIntEQ(ret, 0);
  23034. ExpectIntLE(wc_ecc_sig_size(&key),
  23035. (2 * keySz + SIG_HEADER_SZ + ECC_MAX_PAD_SZ));
  23036. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23037. wc_ecc_free(&key);
  23038. #endif
  23039. return EXPECT_RESULT();
  23040. } /* END test_wc_ecc_sig_size */
  23041. /*
  23042. * Testing wc_ecc_ctx_new()
  23043. */
  23044. static int test_wc_ecc_ctx_new(void)
  23045. {
  23046. EXPECT_DECLS;
  23047. #if defined(HAVE_ECC) && defined(HAVE_ECC_ENCRYPT) && !defined(WC_NO_RNG)
  23048. WC_RNG rng;
  23049. ecEncCtx* cli = NULL;
  23050. ecEncCtx* srv = NULL;
  23051. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23052. ExpectIntEQ(wc_InitRng(&rng), 0);
  23053. ExpectNotNull(cli = wc_ecc_ctx_new(REQ_RESP_CLIENT, &rng));
  23054. ExpectNotNull(srv = wc_ecc_ctx_new(REQ_RESP_SERVER, &rng));
  23055. wc_ecc_ctx_free(cli);
  23056. cli = NULL;
  23057. wc_ecc_ctx_free(srv);
  23058. /* Test bad args. */
  23059. /* wc_ecc_ctx_new_ex() will free if returned NULL. */
  23060. ExpectNull(cli = wc_ecc_ctx_new(0, &rng));
  23061. ExpectNull(cli = wc_ecc_ctx_new(REQ_RESP_CLIENT, NULL));
  23062. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23063. wc_ecc_ctx_free(cli);
  23064. #endif
  23065. return EXPECT_RESULT();
  23066. } /* END test_wc_ecc_ctx_new */
  23067. /*
  23068. * Tesing wc_ecc_reset()
  23069. */
  23070. static int test_wc_ecc_ctx_reset(void)
  23071. {
  23072. EXPECT_DECLS;
  23073. #if defined(HAVE_ECC) && defined(HAVE_ECC_ENCRYPT) && !defined(WC_NO_RNG)
  23074. ecEncCtx* ctx = NULL;
  23075. WC_RNG rng;
  23076. XMEMSET(&rng, 0, sizeof(rng));
  23077. ExpectIntEQ(wc_InitRng(&rng), 0);
  23078. ExpectNotNull(ctx = wc_ecc_ctx_new(REQ_RESP_CLIENT, &rng));
  23079. ExpectIntEQ(wc_ecc_ctx_reset(ctx, &rng), 0);
  23080. /* Pass in bad args. */
  23081. ExpectIntEQ(wc_ecc_ctx_reset(NULL, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23082. ExpectIntEQ(wc_ecc_ctx_reset(ctx, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23083. wc_ecc_ctx_free(ctx);
  23084. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23085. #endif
  23086. return EXPECT_RESULT();
  23087. } /* END test_wc_ecc_ctx_reset */
  23088. /*
  23089. * Testing wc_ecc_ctx_set_peer_salt() and wc_ecc_ctx_get_own_salt()
  23090. */
  23091. static int test_wc_ecc_ctx_set_peer_salt(void)
  23092. {
  23093. EXPECT_DECLS;
  23094. #if defined(HAVE_ECC) && defined(HAVE_ECC_ENCRYPT) && !defined(WC_NO_RNG)
  23095. WC_RNG rng;
  23096. ecEncCtx* cliCtx = NULL;
  23097. ecEncCtx* servCtx = NULL;
  23098. const byte* cliSalt = NULL;
  23099. const byte* servSalt = NULL;
  23100. XMEMSET(&rng, 0, sizeof(rng));
  23101. ExpectIntEQ(wc_InitRng(&rng), 0);
  23102. ExpectNotNull(cliCtx = wc_ecc_ctx_new(REQ_RESP_CLIENT, &rng));
  23103. ExpectNotNull(servCtx = wc_ecc_ctx_new(REQ_RESP_SERVER, &rng));
  23104. /* Test bad args. */
  23105. ExpectNull(cliSalt = wc_ecc_ctx_get_own_salt(NULL));
  23106. ExpectNotNull(cliSalt = wc_ecc_ctx_get_own_salt(cliCtx));
  23107. ExpectNotNull(servSalt = wc_ecc_ctx_get_own_salt(servCtx));
  23108. ExpectIntEQ(wc_ecc_ctx_set_peer_salt(cliCtx, servSalt), 0);
  23109. /* Test bad args. */
  23110. ExpectIntEQ(wc_ecc_ctx_set_peer_salt(NULL, servSalt), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23111. ExpectIntEQ(wc_ecc_ctx_set_peer_salt(cliCtx, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23112. wc_ecc_ctx_free(cliCtx);
  23113. wc_ecc_ctx_free(servCtx);
  23114. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23115. #endif
  23116. return EXPECT_RESULT();
  23117. } /* END test_wc_ecc_ctx_set_peer_salt */
  23118. /*
  23119. * Testing wc_ecc_ctx_set_info()
  23120. */
  23121. static int test_wc_ecc_ctx_set_info(void)
  23122. {
  23123. EXPECT_DECLS;
  23124. #if defined(HAVE_ECC) && defined(HAVE_ECC_ENCRYPT) && !defined(WC_NO_RNG)
  23125. ecEncCtx* ctx = NULL;
  23126. WC_RNG rng;
  23127. const char* optInfo = "Optional Test Info.";
  23128. int optInfoSz = (int)XSTRLEN(optInfo);
  23129. const char* badOptInfo = NULL;
  23130. XMEMSET(&rng, 0, sizeof(rng));
  23131. ExpectIntEQ(wc_InitRng(&rng), 0);
  23132. ExpectNotNull(ctx = wc_ecc_ctx_new(REQ_RESP_CLIENT, &rng));
  23133. ExpectIntEQ(wc_ecc_ctx_set_info(ctx, (byte*)optInfo, optInfoSz), 0);
  23134. /* Test bad args. */
  23135. ExpectIntEQ(wc_ecc_ctx_set_info(NULL, (byte*)optInfo, optInfoSz),
  23136. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23137. ExpectIntEQ(wc_ecc_ctx_set_info(ctx, (byte*)badOptInfo, optInfoSz),
  23138. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23139. ExpectIntEQ(wc_ecc_ctx_set_info(ctx, (byte*)optInfo, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23140. wc_ecc_ctx_free(ctx);
  23141. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23142. #endif
  23143. return EXPECT_RESULT();
  23144. } /* END test_wc_ecc_ctx_set_info */
  23145. /*
  23146. * Testing wc_ecc_encrypt() and wc_ecc_decrypt()
  23147. */
  23148. static int test_wc_ecc_encryptDecrypt(void)
  23149. {
  23150. EXPECT_DECLS;
  23151. #if defined(HAVE_ECC) && defined(HAVE_ECC_ENCRYPT) && !defined(WC_NO_RNG) && \
  23152. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  23153. ecc_key srvKey;
  23154. ecc_key cliKey;
  23155. ecc_key tmpKey;
  23156. WC_RNG rng;
  23157. int ret;
  23158. const char* msg = "EccBlock Size 16";
  23159. word32 msgSz = (word32)XSTRLEN("EccBlock Size 16");
  23160. #ifdef WOLFSSL_ECIES_OLD
  23161. byte out[(sizeof("EccBlock Size 16") - 1) + WC_SHA256_DIGEST_SIZE];
  23162. #elif defined(WOLFSSL_ECIES_GEN_IV)
  23163. byte out[KEY20 * 2 + 1 + AES_BLOCK_SIZE +
  23164. (sizeof("EccBlock Size 16") - 1) + WC_SHA256_DIGEST_SIZE];
  23165. #else
  23166. byte out[KEY20 * 2 + 1 + (sizeof("EccBlock Size 16") - 1) +
  23167. WC_SHA256_DIGEST_SIZE];
  23168. #endif
  23169. word32 outSz = (word32)sizeof(out);
  23170. byte plain[sizeof("EccBlock Size 16")];
  23171. word32 plainSz = (word32)sizeof(plain);
  23172. int keySz = KEY20;
  23173. /* Init stack variables. */
  23174. XMEMSET(out, 0, outSz);
  23175. XMEMSET(plain, 0, plainSz);
  23176. XMEMSET(&rng, 0, sizeof(rng));
  23177. XMEMSET(&srvKey, 0, sizeof(ecc_key));
  23178. XMEMSET(&cliKey, 0, sizeof(ecc_key));
  23179. XMEMSET(&tmpKey, 0, sizeof(ecc_key));
  23180. ExpectIntEQ(wc_InitRng(&rng), 0);
  23181. ExpectIntEQ(wc_ecc_init(&cliKey), 0);
  23182. ret = wc_ecc_make_key(&rng, keySz, &cliKey);
  23183. #if defined(WOLFSSL_ASYNC_CRYPT)
  23184. ret = wc_AsyncWait(ret, &cliKey.asyncDev, WC_ASYNC_FLAG_NONE);
  23185. #endif
  23186. ExpectIntEQ(ret, 0);
  23187. ExpectIntEQ(wc_ecc_init(&srvKey), 0);
  23188. ret = wc_ecc_make_key(&rng, keySz, &srvKey);
  23189. #if defined(WOLFSSL_ASYNC_CRYPT)
  23190. ret = wc_AsyncWait(ret, &srvKey.asyncDev, WC_ASYNC_FLAG_NONE);
  23191. #endif
  23192. ExpectIntEQ(ret, 0);
  23193. ExpectIntEQ(wc_ecc_init(&tmpKey), 0);
  23194. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  23195. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  23196. !defined(HAVE_SELFTEST)
  23197. ExpectIntEQ(wc_ecc_set_rng(&srvKey, &rng), 0);
  23198. ExpectIntEQ(wc_ecc_set_rng(&cliKey, &rng), 0);
  23199. #endif
  23200. ExpectIntEQ(wc_ecc_encrypt(&cliKey, &srvKey, (byte*)msg, msgSz, out,
  23201. &outSz, NULL), 0);
  23202. /* Test bad args. */
  23203. ExpectIntEQ(wc_ecc_encrypt(NULL, &srvKey, (byte*)msg, msgSz, out, &outSz,
  23204. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23205. ExpectIntEQ(wc_ecc_encrypt(&cliKey, NULL, (byte*)msg, msgSz, out, &outSz,
  23206. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23207. ExpectIntEQ(wc_ecc_encrypt(&cliKey, &srvKey, NULL, msgSz, out, &outSz,
  23208. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23209. ExpectIntEQ(wc_ecc_encrypt(&cliKey, &srvKey, (byte*)msg, msgSz, NULL,
  23210. &outSz, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23211. ExpectIntEQ(wc_ecc_encrypt(&cliKey, &srvKey, (byte*)msg, msgSz, out, NULL,
  23212. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23213. #ifdef WOLFSSL_ECIES_OLD
  23214. tmpKey.dp = cliKey.dp;
  23215. ExpectIntEQ(wc_ecc_copy_point(&cliKey.pubkey, &tmpKey.pubkey), 0);
  23216. #endif
  23217. ExpectIntEQ(wc_ecc_decrypt(&srvKey, &tmpKey, out, outSz, plain, &plainSz,
  23218. NULL), 0);
  23219. ExpectIntEQ(wc_ecc_decrypt(NULL, &tmpKey, out, outSz, plain, &plainSz,
  23220. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23221. #ifdef WOLFSSL_ECIES_OLD
  23222. /* NULL parameter allowed in new implementations - public key comes from
  23223. * the message. */
  23224. ExpectIntEQ(wc_ecc_decrypt(&srvKey, NULL, out, outSz, plain, &plainSz,
  23225. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23226. #endif
  23227. ExpectIntEQ(wc_ecc_decrypt(&srvKey, &tmpKey, NULL, outSz, plain, &plainSz,
  23228. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23229. ExpectIntEQ(wc_ecc_decrypt(&srvKey, &tmpKey, out, outSz, NULL, &plainSz,
  23230. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23231. ExpectIntEQ(wc_ecc_decrypt(&srvKey, &tmpKey, out, outSz, plain, NULL, NULL),
  23232. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23233. ExpectIntEQ(XMEMCMP(msg, plain, msgSz), 0);
  23234. wc_ecc_free(&tmpKey);
  23235. wc_ecc_free(&srvKey);
  23236. wc_ecc_free(&cliKey);
  23237. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23238. #endif
  23239. return EXPECT_RESULT();
  23240. } /* END test_wc_ecc_encryptDecrypt */
  23241. /*
  23242. * Testing wc_ecc_del_point() and wc_ecc_new_point()
  23243. */
  23244. static int test_wc_ecc_del_point(void)
  23245. {
  23246. EXPECT_DECLS;
  23247. #if defined(HAVE_ECC)
  23248. ecc_point* pt = NULL;
  23249. ExpectNotNull(pt = wc_ecc_new_point());
  23250. wc_ecc_del_point(pt);
  23251. #endif
  23252. return EXPECT_RESULT();
  23253. } /* END test_wc_ecc_del_point */
  23254. /*
  23255. * Testing wc_ecc_point_is_at_infinity(), wc_ecc_export_point_der(),
  23256. * wc_ecc_import_point_der(), wc_ecc_copy_point(), wc_ecc_point_is_on_curve(),
  23257. * and wc_ecc_cmp_point()
  23258. */
  23259. static int test_wc_ecc_pointFns(void)
  23260. {
  23261. EXPECT_DECLS;
  23262. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT) && \
  23263. !defined(WC_NO_RNG) && !defined(WOLFSSL_ATECC508A) && \
  23264. !defined(WOLFSSL_ATECC608A)
  23265. ecc_key key;
  23266. WC_RNG rng;
  23267. int ret;
  23268. ecc_point* point = NULL;
  23269. ecc_point* cpypt = NULL;
  23270. int idx = 0;
  23271. int keySz = KEY32;
  23272. byte der[DER_SZ(KEY32)];
  23273. word32 derlenChk = 0;
  23274. word32 derSz = DER_SZ(KEY32);
  23275. /* Init stack variables. */
  23276. XMEMSET(der, 0, derSz);
  23277. XMEMSET(&key, 0, sizeof(ecc_key));
  23278. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23279. ExpectIntEQ(wc_InitRng(&rng), 0);
  23280. ExpectIntEQ(wc_ecc_init(&key), 0);
  23281. ret = wc_ecc_make_key(&rng, keySz, &key);
  23282. #if defined(WOLFSSL_ASYNC_CRYPT)
  23283. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  23284. #endif
  23285. ExpectIntEQ(ret, 0);
  23286. ExpectNotNull(point = wc_ecc_new_point());
  23287. ExpectNotNull(cpypt = wc_ecc_new_point());
  23288. /* Export */
  23289. ExpectIntEQ(wc_ecc_export_point_der((idx = key.idx), &key.pubkey, NULL,
  23290. &derlenChk), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  23291. /* Check length value. */
  23292. ExpectIntEQ(derSz, derlenChk);
  23293. ExpectIntEQ(wc_ecc_export_point_der((idx = key.idx), &key.pubkey, der,
  23294. &derSz), 0);
  23295. /* Test bad args. */
  23296. ExpectIntEQ(wc_ecc_export_point_der(-2, &key.pubkey, der, &derSz),
  23297. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23298. ExpectIntEQ(wc_ecc_export_point_der((idx = key.idx), NULL, der, &derSz),
  23299. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23300. ExpectIntEQ(wc_ecc_export_point_der((idx = key.idx), &key.pubkey, der,
  23301. NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23302. /* Import */
  23303. ExpectIntEQ(wc_ecc_import_point_der(der, derSz, idx, point), 0);
  23304. ExpectIntEQ(wc_ecc_cmp_point(&key.pubkey, point), 0);
  23305. /* Test bad args. */
  23306. ExpectIntEQ( wc_ecc_import_point_der(NULL, derSz, idx, point),
  23307. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23308. ExpectIntEQ(wc_ecc_import_point_der(der, derSz, idx, NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23309. ExpectIntEQ(wc_ecc_import_point_der(der, derSz, -1, point), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23310. ExpectIntEQ(wc_ecc_import_point_der(der, derSz + 1, idx, point),
  23311. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23312. /* Copy */
  23313. ExpectIntEQ(wc_ecc_copy_point(point, cpypt), 0);
  23314. /* Test bad args. */
  23315. ExpectIntEQ(wc_ecc_copy_point(NULL, cpypt), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23316. ExpectIntEQ(wc_ecc_copy_point(point, NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23317. /* Compare point */
  23318. ExpectIntEQ(wc_ecc_cmp_point(point, cpypt), 0);
  23319. /* Test bad args. */
  23320. ExpectIntEQ(wc_ecc_cmp_point(NULL, cpypt), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23321. ExpectIntEQ(wc_ecc_cmp_point(point, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23322. /* At infinity if return == 1, otherwise return == 0. */
  23323. ExpectIntEQ(wc_ecc_point_is_at_infinity(point), 0);
  23324. /* Test bad args. */
  23325. ExpectIntEQ(wc_ecc_point_is_at_infinity(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23326. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  23327. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2)))
  23328. #ifdef USE_ECC_B_PARAM
  23329. /* On curve if ret == 0 */
  23330. ExpectIntEQ(wc_ecc_point_is_on_curve(point, idx), 0);
  23331. /* Test bad args. */
  23332. ExpectIntEQ(wc_ecc_point_is_on_curve(NULL, idx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23333. ExpectIntEQ(wc_ecc_point_is_on_curve(point, 1000), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23334. #endif /* USE_ECC_B_PARAM */
  23335. #endif /* !HAVE_SELFTEST && (!HAVE_FIPS || HAVE_FIPS_VERSION > 2) */
  23336. /* Free */
  23337. wc_ecc_del_point(point);
  23338. wc_ecc_del_point(cpypt);
  23339. wc_ecc_free(&key);
  23340. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23341. #endif
  23342. return EXPECT_RESULT();
  23343. } /* END test_wc_ecc_pointFns */
  23344. /*
  23345. * Testing wc_ecc_shared_secret_ssh()
  23346. */
  23347. static int test_wc_ecc_shared_secret_ssh(void)
  23348. {
  23349. EXPECT_DECLS;
  23350. #if defined(HAVE_ECC) && defined(HAVE_ECC_DHE) && \
  23351. !defined(WC_NO_RNG) && !defined(WOLFSSL_ATECC508A) && \
  23352. !defined(WOLFSSL_ATECC608A) && !defined(PLUTON_CRYPTO_ECC) && \
  23353. !defined(WOLFSSL_CRYPTOCELL)
  23354. ecc_key key;
  23355. ecc_key key2;
  23356. WC_RNG rng;
  23357. int ret;
  23358. int keySz = KEY32;
  23359. #if FIPS_VERSION3_GE(6,0,0)
  23360. int key2Sz = KEY28;
  23361. #else
  23362. int key2Sz = KEY24;
  23363. #endif
  23364. byte secret[KEY32];
  23365. word32 secretLen = (word32)keySz;
  23366. /* Init stack variables. */
  23367. XMEMSET(&key, 0, sizeof(ecc_key));
  23368. XMEMSET(&key2, 0, sizeof(ecc_key));
  23369. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23370. XMEMSET(secret, 0, secretLen);
  23371. PRIVATE_KEY_UNLOCK();
  23372. /* Make keys */
  23373. ExpectIntEQ(wc_ecc_init(&key), 0);
  23374. ExpectIntEQ(wc_InitRng(&rng), 0);
  23375. ret = wc_ecc_make_key(&rng, keySz, &key);
  23376. #if defined(WOLFSSL_ASYNC_CRYPT)
  23377. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  23378. #endif
  23379. ExpectIntEQ(ret, 0);
  23380. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23381. ExpectIntEQ(wc_ecc_init(&key2), 0);
  23382. ExpectIntEQ(wc_InitRng(&rng), 0);
  23383. ret = wc_ecc_make_key(&rng, key2Sz, &key2);
  23384. #if defined(WOLFSSL_ASYNC_CRYPT)
  23385. ret = wc_AsyncWait(ret, &key2.asyncDev, WC_ASYNC_FLAG_NONE);
  23386. #endif
  23387. ExpectIntEQ(ret, 0);
  23388. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  23389. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  23390. !defined(HAVE_SELFTEST)
  23391. ExpectIntEQ(wc_ecc_set_rng(&key, &rng), 0);
  23392. #endif
  23393. ExpectIntEQ(wc_ecc_shared_secret_ssh(&key, &key2.pubkey, secret,
  23394. &secretLen), 0);
  23395. /* Pass in bad args. */
  23396. ExpectIntEQ(wc_ecc_shared_secret_ssh(NULL, &key2.pubkey, secret,
  23397. &secretLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23398. ExpectIntEQ(wc_ecc_shared_secret_ssh(&key, NULL, secret, &secretLen),
  23399. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23400. ExpectIntEQ(wc_ecc_shared_secret_ssh(&key, &key2.pubkey, NULL, &secretLen),
  23401. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23402. ExpectIntEQ(wc_ecc_shared_secret_ssh(&key, &key2.pubkey, secret, NULL),
  23403. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23404. key.type = ECC_PUBLICKEY;
  23405. ExpectIntEQ(wc_ecc_shared_secret_ssh(&key, &key2.pubkey, secret,
  23406. &secretLen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23407. PRIVATE_KEY_LOCK();
  23408. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23409. wc_ecc_free(&key);
  23410. wc_ecc_free(&key2);
  23411. #ifdef FP_ECC
  23412. wc_ecc_fp_free();
  23413. #endif
  23414. #endif
  23415. return EXPECT_RESULT();
  23416. } /* END test_wc_ecc_shared_secret_ssh */
  23417. /*
  23418. * Testing wc_ecc_verify_hash_ex() and wc_ecc_verify_hash_ex()
  23419. */
  23420. static int test_wc_ecc_verify_hash_ex(void)
  23421. {
  23422. EXPECT_DECLS;
  23423. #if defined(HAVE_ECC) && defined(HAVE_ECC_SIGN) && defined(WOLFSSL_PUBLIC_MP) \
  23424. && !defined(WC_NO_RNG) && !defined(WOLFSSL_ATECC508A) && \
  23425. !defined(WOLFSSL_ATECC608A) && !defined(WOLFSSL_KCAPI_ECC)
  23426. ecc_key key;
  23427. WC_RNG rng;
  23428. int ret;
  23429. mp_int r;
  23430. mp_int s;
  23431. mp_int z;
  23432. unsigned char hash[] = "Everyone gets Friday off.EccSig";
  23433. unsigned char iHash[] = "Everyone gets Friday off.......";
  23434. unsigned char shortHash[] = TEST_STRING;
  23435. word32 hashlen = sizeof(hash);
  23436. word32 iHashLen = sizeof(iHash);
  23437. word32 shortHashLen = sizeof(shortHash);
  23438. int keySz = KEY32;
  23439. int verify_ok = 0;
  23440. XMEMSET(&key, 0, sizeof(ecc_key));
  23441. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23442. XMEMSET(&r, 0, sizeof(mp_int));
  23443. XMEMSET(&s, 0, sizeof(mp_int));
  23444. XMEMSET(&z, 0, sizeof(mp_int));
  23445. /* Initialize r, s and z. */
  23446. ExpectIntEQ(mp_init_multi(&r, &s, &z, NULL, NULL, NULL), MP_OKAY);
  23447. ExpectIntEQ(wc_ecc_init(&key), 0);
  23448. ExpectIntEQ(wc_InitRng(&rng), 0);
  23449. ret = wc_ecc_make_key(&rng, keySz, &key);
  23450. #if defined(WOLFSSL_ASYNC_CRYPT)
  23451. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  23452. #endif
  23453. ExpectIntEQ(ret, 0);
  23454. ExpectIntEQ(wc_ecc_sign_hash_ex(hash, hashlen, &rng, &key, &r, &s), 0);
  23455. /* verify_ok should be 1. */
  23456. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, hash, hashlen, &verify_ok, &key),
  23457. 0);
  23458. ExpectIntEQ(verify_ok, 1);
  23459. /* verify_ok should be 0 */
  23460. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, iHash, iHashLen, &verify_ok,
  23461. &key), 0);
  23462. ExpectIntEQ(verify_ok, 0);
  23463. /* verify_ok should be 0. */
  23464. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, shortHash, shortHashLen,
  23465. &verify_ok, &key), 0);
  23466. ExpectIntEQ(verify_ok, 0);
  23467. /* Test bad args. */
  23468. ExpectIntEQ(wc_ecc_sign_hash_ex(NULL, hashlen, &rng, &key, &r, &s),
  23469. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23470. ExpectIntEQ(wc_ecc_sign_hash_ex(hash, hashlen, NULL, &key, &r, &s),
  23471. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23472. ExpectIntEQ(wc_ecc_sign_hash_ex(hash, hashlen, &rng, NULL, &r, &s),
  23473. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23474. ExpectIntEQ(wc_ecc_sign_hash_ex(hash, hashlen, &rng, &key, NULL, &s),
  23475. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23476. ExpectIntEQ(wc_ecc_sign_hash_ex(hash, hashlen, &rng, &key, &r, NULL),
  23477. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23478. /* Test bad args. */
  23479. ExpectIntEQ(wc_ecc_verify_hash_ex(NULL, &s, shortHash, shortHashLen,
  23480. &verify_ok, &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23481. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, NULL, shortHash, shortHashLen,
  23482. &verify_ok, &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23483. ExpectIntEQ(wc_ecc_verify_hash_ex(&z, &s, shortHash, shortHashLen,
  23484. &verify_ok, &key), WC_NO_ERR_TRACE(MP_ZERO_E));
  23485. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &z, shortHash, shortHashLen,
  23486. &verify_ok, &key), WC_NO_ERR_TRACE(MP_ZERO_E));
  23487. ExpectIntEQ(wc_ecc_verify_hash_ex(&z, &z, shortHash, shortHashLen,
  23488. &verify_ok, &key), WC_NO_ERR_TRACE(MP_ZERO_E));
  23489. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, NULL, shortHashLen, &verify_ok,
  23490. &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23491. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, shortHash, shortHashLen, NULL,
  23492. &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23493. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, shortHash, shortHashLen,
  23494. &verify_ok, NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23495. wc_ecc_free(&key);
  23496. mp_free(&r);
  23497. mp_free(&s);
  23498. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23499. #endif
  23500. return EXPECT_RESULT();
  23501. } /* END test_wc_ecc_verify_hash_ex */
  23502. /*
  23503. * Testing wc_ecc_mulmod()
  23504. */
  23505. static int test_wc_ecc_mulmod(void)
  23506. {
  23507. EXPECT_DECLS;
  23508. #if defined(HAVE_ECC) && !defined(WC_NO_RNG) && \
  23509. !(defined(WOLFSSL_ATECC508A) || defined(WOLFSSL_ATECC608A) || \
  23510. defined(WOLFSSL_VALIDATE_ECC_IMPORT))
  23511. ecc_key key1;
  23512. ecc_key key2;
  23513. ecc_key key3;
  23514. WC_RNG rng;
  23515. int ret;
  23516. XMEMSET(&key1, 0, sizeof(ecc_key));
  23517. XMEMSET(&key2, 0, sizeof(ecc_key));
  23518. XMEMSET(&key3, 0, sizeof(ecc_key));
  23519. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23520. ExpectIntEQ(wc_ecc_init(&key1), 0);
  23521. ExpectIntEQ(wc_ecc_init(&key2), 0);
  23522. ExpectIntEQ(wc_ecc_init(&key3), 0);
  23523. ExpectIntEQ(wc_InitRng(&rng), 0);
  23524. ret = wc_ecc_make_key(&rng, KEY32, &key1);
  23525. #if defined(WOLFSSL_ASYNC_CRYPT)
  23526. ret = wc_AsyncWait(ret, &key1.asyncDev, WC_ASYNC_FLAG_NONE);
  23527. #endif
  23528. ExpectIntEQ(ret, 0);
  23529. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23530. ExpectIntEQ(wc_ecc_import_raw_ex(&key2, key1.dp->Gx, key1.dp->Gy,
  23531. key1.dp->Af, ECC_SECP256R1), 0);
  23532. ExpectIntEQ(wc_ecc_import_raw_ex(&key3, key1.dp->Gx, key1.dp->Gy,
  23533. key1.dp->prime, ECC_SECP256R1), 0);
  23534. ExpectIntEQ(wc_ecc_mulmod(wc_ecc_key_get_priv(&key1), &key2.pubkey,
  23535. &key3.pubkey, wc_ecc_key_get_priv(&key2), wc_ecc_key_get_priv(&key3),
  23536. 1), 0);
  23537. /* Test bad args. */
  23538. ExpectIntEQ(ret = wc_ecc_mulmod(NULL, &key2.pubkey, &key3.pubkey,
  23539. wc_ecc_key_get_priv(&key2), wc_ecc_key_get_priv(&key3), 1),
  23540. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23541. ExpectIntEQ(wc_ecc_mulmod(wc_ecc_key_get_priv(&key1), NULL, &key3.pubkey,
  23542. wc_ecc_key_get_priv(&key2), wc_ecc_key_get_priv(&key3), 1),
  23543. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23544. ExpectIntEQ(wc_ecc_mulmod(wc_ecc_key_get_priv(&key1), &key2.pubkey, NULL,
  23545. wc_ecc_key_get_priv(&key2), wc_ecc_key_get_priv(&key3), 1),
  23546. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23547. ExpectIntEQ(wc_ecc_mulmod(wc_ecc_key_get_priv(&key1), &key2.pubkey,
  23548. &key3.pubkey, wc_ecc_key_get_priv(&key2), NULL, 1), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23549. wc_ecc_free(&key1);
  23550. wc_ecc_free(&key2);
  23551. wc_ecc_free(&key3);
  23552. #ifdef FP_ECC
  23553. wc_ecc_fp_free();
  23554. #endif
  23555. #endif /* HAVE_ECC && !WOLFSSL_ATECC508A */
  23556. return EXPECT_RESULT();
  23557. } /* END test_wc_ecc_mulmod */
  23558. /*
  23559. * Testing wc_ecc_is_valid_idx()
  23560. */
  23561. static int test_wc_ecc_is_valid_idx(void)
  23562. {
  23563. EXPECT_DECLS;
  23564. #if defined(HAVE_ECC) && !defined(WC_NO_RNG)
  23565. ecc_key key;
  23566. WC_RNG rng;
  23567. int ret;
  23568. int iVal = -2;
  23569. int iVal2 = 3000;
  23570. XMEMSET(&key, 0, sizeof(ecc_key));
  23571. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23572. ExpectIntEQ(wc_ecc_init(&key), 0);
  23573. ExpectIntEQ(wc_InitRng(&rng), 0);
  23574. ret = wc_ecc_make_key(&rng, 32, &key);
  23575. #if defined(WOLFSSL_ASYNC_CRYPT)
  23576. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  23577. #endif
  23578. ExpectIntEQ(ret, 0);
  23579. ExpectIntEQ(wc_ecc_is_valid_idx(key.idx), 1);
  23580. /* Test bad args. */
  23581. ExpectIntEQ(wc_ecc_is_valid_idx(iVal), 0);
  23582. ExpectIntEQ(wc_ecc_is_valid_idx(iVal2), 0);
  23583. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23584. wc_ecc_free(&key);
  23585. #ifdef FP_ECC
  23586. wc_ecc_fp_free();
  23587. #endif
  23588. #endif
  23589. return EXPECT_RESULT();
  23590. } /* END test_wc_ecc_is_valid_idx */
  23591. /*
  23592. * Testing wc_ecc_get_curve_id_from_oid()
  23593. */
  23594. static int test_wc_ecc_get_curve_id_from_oid(void)
  23595. {
  23596. EXPECT_DECLS;
  23597. #if defined(HAVE_ECC) && !defined(NO_ECC256) && !defined(HAVE_SELFTEST) && \
  23598. !defined(HAVE_FIPS)
  23599. const byte oid[] = {0x2A,0x86,0x48,0xCE,0x3D,0x03,0x01,0x07};
  23600. word32 len = sizeof(oid);
  23601. /* Bad Cases */
  23602. ExpectIntEQ(wc_ecc_get_curve_id_from_oid(NULL, len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23603. ExpectIntEQ(wc_ecc_get_curve_id_from_oid(oid, 0), ECC_CURVE_INVALID);
  23604. /* Good Case */
  23605. ExpectIntEQ(wc_ecc_get_curve_id_from_oid(oid, len), ECC_SECP256R1);
  23606. #endif
  23607. return EXPECT_RESULT();
  23608. } /* END test_wc_ecc_get_curve_id_from_oid */
  23609. /*
  23610. * Testing wc_ecc_sig_size_calc()
  23611. */
  23612. static int test_wc_ecc_sig_size_calc(void)
  23613. {
  23614. EXPECT_DECLS;
  23615. #if defined(HAVE_ECC) && !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST)
  23616. ecc_key key;
  23617. WC_RNG rng;
  23618. int sz = 0;
  23619. int ret;
  23620. XMEMSET(&key, 0, sizeof(ecc_key));
  23621. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23622. ExpectIntEQ(wc_ecc_init(&key), 0);
  23623. ExpectIntEQ(wc_InitRng(&rng), 0);
  23624. ret = wc_ecc_make_key(&rng, 16, &key);
  23625. #if defined(WOLFSSL_ASYNC_CRYPT)
  23626. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  23627. #endif
  23628. #if FIPS_VERSION3_GE(6,0,0)
  23629. ExpectIntEQ(ret, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23630. #else
  23631. ExpectIntEQ(ret, 0);
  23632. #endif
  23633. #if FIPS_VERSION3_LT(6,0,0)
  23634. sz = key.dp->size;
  23635. ExpectIntGT(wc_ecc_sig_size_calc(sz), 0);
  23636. #else
  23637. (void) sz;
  23638. #endif
  23639. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23640. wc_ecc_free(&key);
  23641. #endif
  23642. return EXPECT_RESULT();
  23643. } /* END test_wc_ecc_sig_size_calc */
  23644. /*
  23645. * Testing wc_ecc_sm2_make_key()
  23646. */
  23647. static int test_wc_ecc_sm2_make_key(void)
  23648. {
  23649. int res = TEST_SKIPPED;
  23650. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2)
  23651. EXPECT_DECLS;
  23652. WC_RNG rng[1];
  23653. ecc_key key[1];
  23654. XMEMSET(rng, 0, sizeof(*rng));
  23655. XMEMSET(key, 0, sizeof(*key));
  23656. ExpectIntEQ(wc_InitRng(rng), 0);
  23657. ExpectIntEQ(wc_ecc_init(key), 0);
  23658. /* Test invalid parameters. */
  23659. ExpectIntEQ(wc_ecc_sm2_make_key(NULL, NULL, WC_ECC_FLAG_NONE),
  23660. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23661. ExpectIntEQ(wc_ecc_sm2_make_key(rng, NULL, WC_ECC_FLAG_NONE),
  23662. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23663. ExpectIntEQ(wc_ecc_sm2_make_key(NULL, key, WC_ECC_FLAG_NONE),
  23664. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23665. /* Test valid parameters. */
  23666. ExpectIntEQ(wc_ecc_sm2_make_key(rng, key, WC_ECC_FLAG_NONE), 0);
  23667. ExpectIntEQ(key->dp->id, ECC_SM2P256V1);
  23668. wc_ecc_free(key);
  23669. wc_FreeRng(rng);
  23670. #ifdef FP_ECC
  23671. wc_ecc_fp_free();
  23672. #endif
  23673. res = EXPECT_RESULT();
  23674. #endif
  23675. return res;
  23676. }
  23677. /*
  23678. * Testing wc_ecc_sm2_shared_secret()
  23679. */
  23680. static int test_wc_ecc_sm2_shared_secret(void)
  23681. {
  23682. int res = TEST_SKIPPED;
  23683. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2)
  23684. EXPECT_DECLS;
  23685. WC_RNG rng[1];
  23686. ecc_key keyA[1];
  23687. ecc_key keyB[1];
  23688. byte outA[32];
  23689. byte outB[32];
  23690. word32 outALen = 32;
  23691. word32 outBLen = 32;
  23692. XMEMSET(rng, 0, sizeof(*rng));
  23693. XMEMSET(keyA, 0, sizeof(*keyA));
  23694. XMEMSET(keyB, 0, sizeof(*keyB));
  23695. ExpectIntEQ(wc_InitRng(rng), 0);
  23696. ExpectIntEQ(wc_ecc_init(keyA), 0);
  23697. ExpectIntEQ(wc_ecc_init(keyB), 0);
  23698. ExpectIntEQ(wc_ecc_sm2_make_key(rng, keyA, WC_ECC_FLAG_NONE), 0);
  23699. ExpectIntEQ(wc_ecc_sm2_make_key(rng, keyB, WC_ECC_FLAG_NONE), 0);
  23700. #ifdef ECC_TIMING_RESISTANT
  23701. ExpectIntEQ(wc_ecc_set_rng(keyA, rng), 0);
  23702. ExpectIntEQ(wc_ecc_set_rng(keyB, rng), 0);
  23703. #endif
  23704. /* Test invalid parameters. */
  23705. ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23706. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23707. ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, keyB, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23708. ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, NULL, outA, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23709. ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, NULL, NULL, &outALen),
  23710. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23711. ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, keyB, outA, &outALen),
  23712. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23713. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, NULL, outA, &outALen),
  23714. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23715. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, keyB, NULL, &outALen),
  23716. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23717. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, keyB, outA, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23718. /* Test valid parameters. */
  23719. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, keyB, outA, &outALen), 0);
  23720. ExpectIntLE(outALen, 32);
  23721. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyB, keyA, outB, &outBLen), 0);
  23722. ExpectIntLE(outBLen, 32);
  23723. ExpectIntEQ(outALen, outBLen);
  23724. ExpectBufEQ(outA, outB, outALen);
  23725. wc_ecc_free(keyB);
  23726. wc_ecc_free(keyA);
  23727. wc_FreeRng(rng);
  23728. #ifdef FP_ECC
  23729. wc_ecc_fp_free();
  23730. #endif
  23731. res = EXPECT_RESULT();
  23732. #endif
  23733. return res;
  23734. }
  23735. /*
  23736. * Testing wc_ecc_sm2_create_digest()
  23737. */
  23738. static int test_wc_ecc_sm2_create_digest(void)
  23739. {
  23740. int res = TEST_SKIPPED;
  23741. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && !defined(NO_HASH_WRAPPER) && \
  23742. (defined(WOLFSSL_SM3) || !defined(NO_SHA256))
  23743. EXPECT_DECLS;
  23744. ecc_key key[1];
  23745. enum wc_HashType hashType;
  23746. unsigned char pub[] = {
  23747. 0x04,
  23748. 0x63, 0x7F, 0x1B, 0x13, 0x50, 0x36, 0xC9, 0x33,
  23749. 0xDC, 0x3F, 0x7A, 0x8E, 0xBB, 0x1B, 0x7B, 0x2F,
  23750. 0xD1, 0xDF, 0xBD, 0x26, 0x8D, 0x4F, 0x89, 0x4B,
  23751. 0x5A, 0xD4, 0x7D, 0xBD, 0xBE, 0xCD, 0x55, 0x8F,
  23752. 0xE8, 0x81, 0x01, 0xD0, 0x80, 0x48, 0xE3, 0x6C,
  23753. 0xCB, 0xF6, 0x1C, 0xA3, 0x8D, 0xDF, 0x7A, 0xBA,
  23754. 0x54, 0x2B, 0x44, 0x86, 0xE9, 0x9E, 0x49, 0xF3,
  23755. 0xA7, 0x47, 0x0A, 0x85, 0x7A, 0x09, 0x64, 0x33
  23756. };
  23757. unsigned char id[] = {
  23758. 0x01, 0x02, 0x03,
  23759. };
  23760. unsigned char msg[] = {
  23761. 0x01, 0x02, 0x03,
  23762. };
  23763. unsigned char hash[32];
  23764. #ifdef WOLFSSL_SM3
  23765. unsigned char expHash[32] = {
  23766. 0xc1, 0xdd, 0x92, 0xc5, 0x60, 0xd3, 0x94, 0x28,
  23767. 0xeb, 0x0f, 0x57, 0x79, 0x3f, 0xc9, 0x96, 0xc5,
  23768. 0xfa, 0xf5, 0x90, 0xb2, 0x64, 0x2f, 0xaf, 0x9c,
  23769. 0xc8, 0x57, 0x21, 0x6a, 0x52, 0x7e, 0xf1, 0x95
  23770. };
  23771. #else
  23772. unsigned char expHash[32] = {
  23773. 0xea, 0x41, 0x55, 0x21, 0x61, 0x00, 0x5c, 0x9a,
  23774. 0x57, 0x35, 0x6b, 0x49, 0xca, 0x8f, 0x65, 0xc2,
  23775. 0x0e, 0x29, 0x0c, 0xa0, 0x1d, 0xa7, 0xc4, 0xed,
  23776. 0xdd, 0x51, 0x12, 0xf6, 0xe7, 0x55, 0xc5, 0xf4
  23777. };
  23778. #endif
  23779. #ifdef WOLFSSL_SM3
  23780. hashType = WC_HASH_TYPE_SM3;
  23781. #else
  23782. hashType = WC_HASH_TYPE_SHA256;
  23783. #endif
  23784. XMEMSET(key, 0, sizeof(*key));
  23785. ExpectIntEQ(wc_ecc_init(key), 0);
  23786. /* Test with no curve set. */
  23787. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23788. hashType, hash, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23789. ExpectIntEQ(wc_ecc_import_x963_ex(pub, sizeof(pub), key, ECC_SM2P256V1), 0);
  23790. /* Test invalid parameters. */
  23791. ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), NULL, sizeof(msg),
  23792. hashType, NULL, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23793. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), NULL, sizeof(msg),
  23794. hashType, NULL, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23795. ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), msg, sizeof(msg),
  23796. hashType, NULL, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23797. ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), NULL, sizeof(msg),
  23798. hashType, hash, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23799. ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), NULL, sizeof(msg),
  23800. hashType, NULL, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23801. ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), msg, sizeof(msg),
  23802. hashType, hash, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23803. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), NULL, sizeof(msg),
  23804. hashType, hash, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23805. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23806. hashType, NULL, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23807. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23808. hashType, hash, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23809. /* Bad hash type. */
  23810. /* // NOLINTBEGIN(clang-analyzer-optin.core.EnumCastOutOfRange) */
  23811. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23812. -1, hash, 0, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23813. /* // NOLINTEND(clang-analyzer-optin.core.EnumCastOutOfRange) */
  23814. /* Bad hash size. */
  23815. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23816. hashType, hash, 0, key), WC_NO_ERR_TRACE(BUFFER_E));
  23817. /* Test valid parameters. */
  23818. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23819. hashType, hash, sizeof(hash), key), 0);
  23820. ExpectBufEQ(hash, expHash, sizeof(expHash));
  23821. wc_ecc_free(key);
  23822. res = EXPECT_RESULT();
  23823. #endif
  23824. return res;
  23825. }
  23826. /*
  23827. * Testing wc_ecc_sm2_verify_hash_ex()
  23828. */
  23829. static int test_wc_ecc_sm2_verify_hash_ex(void)
  23830. {
  23831. int res = TEST_SKIPPED;
  23832. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && defined(HAVE_ECC_VERIFY) && \
  23833. defined(WOLFSSL_PUBLIC_MP)
  23834. EXPECT_DECLS;
  23835. ecc_key key[1];
  23836. mp_int r[1];
  23837. mp_int s[1];
  23838. int verified;
  23839. unsigned char pub[] = {
  23840. 0x04,
  23841. 0x63, 0x7F, 0x1B, 0x13, 0x50, 0x36, 0xC9, 0x33,
  23842. 0xDC, 0x3F, 0x7A, 0x8E, 0xBB, 0x1B, 0x7B, 0x2F,
  23843. 0xD1, 0xDF, 0xBD, 0x26, 0x8D, 0x4F, 0x89, 0x4B,
  23844. 0x5A, 0xD4, 0x7D, 0xBD, 0xBE, 0xCD, 0x55, 0x8F,
  23845. 0xE8, 0x81, 0x01, 0xD0, 0x80, 0x48, 0xE3, 0x6C,
  23846. 0xCB, 0xF6, 0x1C, 0xA3, 0x8D, 0xDF, 0x7A, 0xBA,
  23847. 0x54, 0x2B, 0x44, 0x86, 0xE9, 0x9E, 0x49, 0xF3,
  23848. 0xA7, 0x47, 0x0A, 0x85, 0x7A, 0x09, 0x64, 0x33
  23849. };
  23850. unsigned char hash[] = {
  23851. 0x3B, 0xFA, 0x5F, 0xFB, 0xC4, 0x27, 0x8C, 0x9D,
  23852. 0x02, 0x3A, 0x19, 0xCB, 0x1E, 0xAA, 0xD2, 0xF1,
  23853. 0x50, 0x69, 0x5B, 0x20
  23854. };
  23855. unsigned char rData[] = {
  23856. 0xD2, 0xFC, 0xA3, 0x88, 0xE3, 0xDF, 0xA3, 0x00,
  23857. 0x73, 0x9B, 0x3C, 0x2A, 0x0D, 0xAD, 0x44, 0xA2,
  23858. 0xFC, 0x62, 0xD5, 0x6B, 0x84, 0x54, 0xD8, 0x40,
  23859. 0x22, 0x62, 0x3D, 0x5C, 0xA6, 0x61, 0x9B, 0xE7,
  23860. };
  23861. unsigned char sData[] = {
  23862. 0x1D,
  23863. 0xB5, 0xB5, 0xD9, 0xD8, 0xF1, 0x20, 0xDD, 0x97,
  23864. 0x92, 0xBF, 0x7E, 0x9B, 0x3F, 0xE6, 0x3C, 0x4B,
  23865. 0x03, 0xD8, 0x80, 0xBD, 0xB7, 0x27, 0x7E, 0x6A,
  23866. 0x84, 0x23, 0xDE, 0x61, 0x7C, 0x8D, 0xDC
  23867. };
  23868. unsigned char rBadData[] = {
  23869. 0xD2, 0xFC, 0xA3, 0x88, 0xE3, 0xDF, 0xA3, 0x00,
  23870. 0x73, 0x9B, 0x3C, 0x2A, 0x0D, 0xAD, 0x44, 0xA2,
  23871. 0xFC, 0x62, 0xD5, 0x6B, 0x84, 0x54, 0xD8, 0x40,
  23872. 0x22, 0x62, 0x3D, 0x5C, 0xA6, 0x61, 0x9B, 0xE8,
  23873. };
  23874. XMEMSET(key, 0, sizeof(*key));
  23875. XMEMSET(r, 0, sizeof(*r));
  23876. XMEMSET(s, 0, sizeof(*s));
  23877. ExpectIntEQ(mp_init(r), 0);
  23878. ExpectIntEQ(mp_init(s), 0);
  23879. ExpectIntEQ(mp_read_unsigned_bin(r, rData, sizeof(rData)), 0);
  23880. ExpectIntEQ(mp_read_unsigned_bin(s, sData, sizeof(sData)), 0);
  23881. ExpectIntEQ(wc_ecc_init(key), 0);
  23882. /* Test with no curve set. */
  23883. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  23884. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23885. ExpectIntEQ(wc_ecc_import_x963_ex(pub, sizeof(pub), key, ECC_SM2P256V1), 0);
  23886. /* Test invalid parameters. */
  23887. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, NULL, NULL, sizeof(hash),
  23888. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23889. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, NULL, NULL, sizeof(hash),
  23890. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23891. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, s, NULL, sizeof(hash),
  23892. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23893. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, NULL, hash, sizeof(hash),
  23894. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23895. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, NULL, NULL, sizeof(hash),
  23896. &verified, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23897. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, NULL, NULL, sizeof(hash),
  23898. NULL, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23899. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, s, hash, sizeof(hash),
  23900. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23901. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, NULL, hash, sizeof(hash),
  23902. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23903. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, NULL, sizeof(hash),
  23904. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23905. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  23906. NULL, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23907. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  23908. &verified, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23909. /* Make key not on the SM2 curve. */
  23910. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SECP256R1), 0);
  23911. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  23912. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23913. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SM2P256V1), 0);
  23914. /* Test valid parameters. */
  23915. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  23916. &verified, key), 0);
  23917. ExpectIntEQ(verified, 1);
  23918. ExpectIntEQ(mp_read_unsigned_bin(r, rBadData, sizeof(rBadData)), 0);
  23919. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  23920. &verified, key), 0);
  23921. ExpectIntEQ(verified, 0);
  23922. mp_free(s);
  23923. mp_free(r);
  23924. wc_ecc_free(key);
  23925. #ifdef FP_ECC
  23926. wc_ecc_fp_free();
  23927. #endif
  23928. res = EXPECT_RESULT();
  23929. #endif
  23930. return res;
  23931. }
  23932. /*
  23933. * Testing wc_ecc_sm2_verify_hash()
  23934. */
  23935. static int test_wc_ecc_sm2_verify_hash(void)
  23936. {
  23937. int res = TEST_SKIPPED;
  23938. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && defined(HAVE_ECC_VERIFY)
  23939. EXPECT_DECLS;
  23940. ecc_key key[1];
  23941. int verified;
  23942. unsigned char pub[] = {
  23943. 0x04,
  23944. 0x63, 0x7F, 0x1B, 0x13, 0x50, 0x36, 0xC9, 0x33,
  23945. 0xDC, 0x3F, 0x7A, 0x8E, 0xBB, 0x1B, 0x7B, 0x2F,
  23946. 0xD1, 0xDF, 0xBD, 0x26, 0x8D, 0x4F, 0x89, 0x4B,
  23947. 0x5A, 0xD4, 0x7D, 0xBD, 0xBE, 0xCD, 0x55, 0x8F,
  23948. 0xE8, 0x81, 0x01, 0xD0, 0x80, 0x48, 0xE3, 0x6C,
  23949. 0xCB, 0xF6, 0x1C, 0xA3, 0x8D, 0xDF, 0x7A, 0xBA,
  23950. 0x54, 0x2B, 0x44, 0x86, 0xE9, 0x9E, 0x49, 0xF3,
  23951. 0xA7, 0x47, 0x0A, 0x85, 0x7A, 0x09, 0x64, 0x33
  23952. };
  23953. unsigned char hash[] = {
  23954. 0x3B, 0xFA, 0x5F, 0xFB, 0xC4, 0x27, 0x8C, 0x9D,
  23955. 0x02, 0x3A, 0x19, 0xCB, 0x1E, 0xAA, 0xD2, 0xF1,
  23956. 0x50, 0x69, 0x5B, 0x20
  23957. };
  23958. unsigned char sig[] = {
  23959. 0x30, 0x45, 0x02, 0x21, 0x00, 0xD2, 0xFC, 0xA3,
  23960. 0x88, 0xE3, 0xDF, 0xA3, 0x00, 0x73, 0x9B, 0x3C,
  23961. 0x2A, 0x0D, 0xAD, 0x44, 0xA2, 0xFC, 0x62, 0xD5,
  23962. 0x6B, 0x84, 0x54, 0xD8, 0x40, 0x22, 0x62, 0x3D,
  23963. 0x5C, 0xA6, 0x61, 0x9B, 0xE7, 0x02, 0x20, 0x1D,
  23964. 0xB5, 0xB5, 0xD9, 0xD8, 0xF1, 0x20, 0xDD, 0x97,
  23965. 0x92, 0xBF, 0x7E, 0x9B, 0x3F, 0xE6, 0x3C, 0x4B,
  23966. 0x03, 0xD8, 0x80, 0xBD, 0xB7, 0x27, 0x7E, 0x6A,
  23967. 0x84, 0x23, 0xDE, 0x61, 0x7C, 0x8D, 0xDC
  23968. };
  23969. unsigned char sigBad[] = {
  23970. 0x30, 0x45, 0x02, 0x21, 0x00, 0xD2, 0xFC, 0xA3,
  23971. 0x88, 0xE3, 0xDF, 0xA3, 0x00, 0x73, 0x9B, 0x3C,
  23972. 0x2A, 0x0D, 0xAD, 0x44, 0xA2, 0xFC, 0x62, 0xD5,
  23973. 0x6B, 0x84, 0x54, 0xD8, 0x40, 0x22, 0x62, 0x3D,
  23974. 0x5C, 0xA6, 0x61, 0x9B, 0xE7, 0x02, 0x20, 0x1D,
  23975. 0xB5, 0xB5, 0xD9, 0xD8, 0xF1, 0x20, 0xDD, 0x97,
  23976. 0x92, 0xBF, 0x7E, 0x9B, 0x3F, 0xE6, 0x3C, 0x4B,
  23977. 0x03, 0xD8, 0x80, 0xBD, 0xB7, 0x27, 0x7E, 0x6A,
  23978. 0x84, 0x23, 0xDE, 0x61, 0x7C, 0x8D, 0xDD
  23979. };
  23980. XMEMSET(key, 0, sizeof(*key));
  23981. ExpectIntEQ(wc_ecc_init(key), 0);
  23982. /* Test with no curve set. */
  23983. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
  23984. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23985. ExpectIntEQ(wc_ecc_import_x963_ex(pub, sizeof(pub), key, ECC_SM2P256V1), 0);
  23986. /* Test invalid parameters. */
  23987. ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), NULL, sizeof(hash),
  23988. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23989. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), NULL, sizeof(hash),
  23990. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23991. ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), hash, sizeof(hash),
  23992. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23993. ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), NULL, sizeof(hash),
  23994. &verified, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23995. ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), NULL, sizeof(hash),
  23996. NULL, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23997. ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), hash, sizeof(hash),
  23998. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23999. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), NULL, sizeof(hash),
  24000. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24001. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
  24002. NULL, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24003. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
  24004. &verified, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24005. /* Make key not on the SM2 curve. */
  24006. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SECP256R1), 0);
  24007. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
  24008. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24009. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SM2P256V1), 0);
  24010. /* Test valid parameters. */
  24011. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
  24012. &verified, key), 0);
  24013. ExpectIntEQ(verified, 1);
  24014. ExpectIntEQ(wc_ecc_sm2_verify_hash(sigBad, sizeof(sigBad), hash,
  24015. sizeof(hash), &verified, key), 0);
  24016. ExpectIntEQ(verified, 0);
  24017. wc_ecc_free(key);
  24018. #ifdef FP_ECC
  24019. wc_ecc_fp_free();
  24020. #endif
  24021. res = EXPECT_RESULT();
  24022. #endif
  24023. return res;
  24024. }
  24025. /*
  24026. * Testing wc_ecc_sm2_verify_hash_ex()
  24027. */
  24028. static int test_wc_ecc_sm2_sign_hash_ex(void)
  24029. {
  24030. int res = TEST_SKIPPED;
  24031. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && defined(HAVE_ECC_SIGN) && \
  24032. defined(WOLFSSL_PUBLIC_MP)
  24033. EXPECT_DECLS;
  24034. WC_RNG rng[1];
  24035. ecc_key key[1];
  24036. mp_int r[1];
  24037. mp_int s[1];
  24038. unsigned char hash[32];
  24039. #ifdef HAVE_ECC_VERIFY
  24040. int verified;
  24041. #endif
  24042. XMEMSET(rng, 0, sizeof(*rng));
  24043. XMEMSET(key, 0, sizeof(*key));
  24044. XMEMSET(r, 0, sizeof(*r));
  24045. XMEMSET(s, 0, sizeof(*s));
  24046. ExpectIntEQ(wc_InitRng(rng), 0);
  24047. ExpectIntEQ(mp_init(r), 0);
  24048. ExpectIntEQ(mp_init(s), 0);
  24049. ExpectIntEQ(wc_RNG_GenerateBlock(rng, hash, sizeof(hash)), 0);
  24050. ExpectIntEQ(wc_ecc_init(key), 0);
  24051. /* Test with no curve set. */
  24052. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, r, s),
  24053. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24054. ExpectIntEQ(wc_ecc_sm2_make_key(rng, key, WC_ECC_FLAG_NONE), 0);
  24055. /* Test invalid parameters. */
  24056. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), NULL, NULL, NULL,
  24057. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24058. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), NULL, NULL, NULL,
  24059. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24060. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), rng, NULL, NULL,
  24061. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24062. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), NULL, key, NULL,
  24063. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24064. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), NULL, NULL, r,
  24065. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24066. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), NULL, NULL, NULL,
  24067. s), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24068. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), rng, key, r, s),
  24069. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24070. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), NULL, key, r, s),
  24071. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24072. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, NULL, r, s),
  24073. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24074. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, NULL, s),
  24075. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24076. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, r, NULL),
  24077. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24078. /* Make key not on the SM2 curve. */
  24079. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SECP256R1), 0);
  24080. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, r, s),
  24081. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24082. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SM2P256V1), 0);
  24083. #ifdef WOLFSSL_SP_MATH_ALL
  24084. {
  24085. mp_int smallR[1];
  24086. sp_init_size(smallR, 1);
  24087. /* Force failure in _ecc_sm2_calc_r_s by r being too small. */
  24088. ExpectIntLT(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key,
  24089. smallR, s), 0);
  24090. }
  24091. #endif
  24092. /* Test valid parameters. */
  24093. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, r, s),
  24094. 0);
  24095. #ifdef HAVE_ECC_VERIFY
  24096. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash), &verified,
  24097. key), 0);
  24098. ExpectIntEQ(verified, 1);
  24099. #endif
  24100. mp_free(s);
  24101. mp_free(r);
  24102. wc_ecc_free(key);
  24103. wc_FreeRng(rng);
  24104. #ifdef FP_ECC
  24105. wc_ecc_fp_free();
  24106. #endif
  24107. res = EXPECT_RESULT();
  24108. #endif
  24109. return res;
  24110. }
  24111. /*
  24112. * Testing wc_ecc_sm2_verify_hash()
  24113. */
  24114. static int test_wc_ecc_sm2_sign_hash(void)
  24115. {
  24116. int res = TEST_SKIPPED;
  24117. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && defined(HAVE_ECC_SIGN)
  24118. EXPECT_DECLS;
  24119. WC_RNG rng[1];
  24120. ecc_key key[1];
  24121. unsigned char hash[32];
  24122. unsigned char sig[72];
  24123. word32 sigSz = sizeof(sig);
  24124. #ifdef HAVE_ECC_VERIFY
  24125. int verified;
  24126. #endif
  24127. XMEMSET(rng, 0, sizeof(*rng));
  24128. XMEMSET(key, 0, sizeof(*key));
  24129. ExpectIntEQ(wc_InitRng(rng), 0);
  24130. ExpectIntEQ(wc_RNG_GenerateBlock(rng, hash, sizeof(hash)), 0);
  24131. ExpectIntEQ(wc_ecc_init(key), 0);
  24132. /* Test with no curve set. */
  24133. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key),
  24134. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24135. ExpectIntEQ(wc_ecc_sm2_make_key(rng, key, WC_ECC_FLAG_NONE), 0);
  24136. /* Test invalid parameters. */
  24137. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), NULL, NULL, NULL,
  24138. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24139. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), NULL, NULL, NULL,
  24140. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24141. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), sig, NULL, NULL,
  24142. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24143. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), NULL, &sigSz, NULL,
  24144. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24145. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), NULL, NULL, rng,
  24146. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24147. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), NULL, NULL, NULL,
  24148. key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24149. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), sig, &sigSz, rng,
  24150. key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24151. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), NULL, &sigSz, rng,
  24152. key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24153. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, NULL, rng,
  24154. key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24155. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, NULL,
  24156. key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24157. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, rng,
  24158. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24159. /* Make key not on the SM2 curve. */
  24160. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SECP256R1), 0);
  24161. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key),
  24162. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24163. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SM2P256V1), 0);
  24164. /* Test valid parameters. */
  24165. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key),
  24166. 0);
  24167. #ifdef HAVE_ECC_VERIFY
  24168. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sigSz, hash, sizeof(hash),
  24169. &verified, key), 0);
  24170. ExpectIntEQ(verified, 1);
  24171. #endif
  24172. wc_ecc_free(key);
  24173. wc_FreeRng(rng);
  24174. #ifdef FP_ECC
  24175. wc_ecc_fp_free();
  24176. #endif
  24177. res = EXPECT_RESULT();
  24178. #endif
  24179. return res;
  24180. }
  24181. /*
  24182. * Testing ToTraditional
  24183. */
  24184. static int test_ToTraditional(void)
  24185. {
  24186. EXPECT_DECLS;
  24187. #if !defined(NO_ASN) && (defined(HAVE_PKCS8) || defined(HAVE_PKCS12)) && \
  24188. (defined(WOLFSSL_TEST_CERT) || defined(OPENSSL_EXTRA) || \
  24189. defined(OPENSSL_EXTRA_X509_SMALL)) && !defined(NO_FILESYSTEM)
  24190. XFILE f = XBADFILE;
  24191. byte input[TWOK_BUF];
  24192. word32 sz = 0;
  24193. ExpectTrue((f = XFOPEN("./certs/server-keyPkcs8.der", "rb")) != XBADFILE);
  24194. ExpectTrue((sz = (word32)XFREAD(input, 1, sizeof(input), f)) > 0);
  24195. if (f != XBADFILE)
  24196. XFCLOSE(f);
  24197. /* Good case */
  24198. ExpectIntGT(ToTraditional(input, sz), 0);
  24199. /* Bad cases */
  24200. ExpectIntEQ(ToTraditional(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24201. ExpectIntEQ(ToTraditional(NULL, sz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24202. #ifdef WOLFSSL_ASN_TEMPLATE
  24203. ExpectIntEQ(ToTraditional(input, 0), WC_NO_ERR_TRACE(BUFFER_E));
  24204. #else
  24205. ExpectIntEQ(ToTraditional(input, 0), WC_NO_ERR_TRACE(ASN_PARSE_E));
  24206. #endif
  24207. #endif
  24208. return EXPECT_RESULT();
  24209. } /* End test_ToTraditional*/
  24210. /*
  24211. * Testing wc_EccPrivateKeyToDer
  24212. */
  24213. static int test_wc_EccPrivateKeyToDer(void)
  24214. {
  24215. EXPECT_DECLS;
  24216. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  24217. byte output[ONEK_BUF];
  24218. ecc_key eccKey;
  24219. WC_RNG rng;
  24220. word32 inLen;
  24221. word32 outLen = 0;
  24222. int ret;
  24223. XMEMSET(&eccKey, 0, sizeof(ecc_key));
  24224. XMEMSET(&rng, 0, sizeof(WC_RNG));
  24225. PRIVATE_KEY_UNLOCK();
  24226. ExpectIntEQ(wc_InitRng(&rng), 0);
  24227. ExpectIntEQ(wc_ecc_init(&eccKey), 0);
  24228. ret = wc_ecc_make_key(&rng, KEY14, &eccKey);
  24229. #if defined(WOLFSSL_ASYNC_CRYPT)
  24230. ret = wc_AsyncWait(ret, &eccKey.asyncDev, WC_ASYNC_FLAG_NONE);
  24231. #endif
  24232. ExpectIntEQ(ret, 0);
  24233. inLen = (word32)sizeof(output);
  24234. /* Bad Cases */
  24235. ExpectIntEQ(wc_EccPrivateKeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24236. ExpectIntEQ(wc_EccPrivateKeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24237. ExpectIntEQ(wc_EccPrivateKeyToDer(&eccKey, NULL, inLen), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  24238. ExpectIntEQ(wc_EccPrivateKeyToDer(&eccKey, output, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24239. /* Good Case */
  24240. ExpectIntGT(outLen = (word32)wc_EccPrivateKeyToDer(&eccKey, output, inLen), 0);
  24241. wc_ecc_free(&eccKey);
  24242. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  24243. #if defined(OPENSSL_EXTRA) && defined(HAVE_ALL_CURVES)
  24244. {
  24245. /* test importing private only into a PKEY struct */
  24246. EC_KEY* ec = NULL;
  24247. EVP_PKEY* pkey = NULL;
  24248. const unsigned char* der;
  24249. der = output;
  24250. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &der, outLen));
  24251. der = output;
  24252. ExpectNotNull(ec = d2i_ECPrivateKey(NULL, &der, outLen));
  24253. ExpectIntEQ(EVP_PKEY_assign_EC_KEY(pkey, ec), SSL_SUCCESS);
  24254. if (EXPECT_FAIL()) {
  24255. EC_KEY_free(ec);
  24256. }
  24257. EVP_PKEY_free(pkey); /* EC_KEY should be free'd by free'ing pkey */
  24258. }
  24259. #endif
  24260. PRIVATE_KEY_LOCK();
  24261. #endif
  24262. return EXPECT_RESULT();
  24263. } /* End test_wc_EccPrivateKeyToDer*/
  24264. /*
  24265. * Testing wc_DhPublicKeyDecode
  24266. */
  24267. static int test_wc_DhPublicKeyDecode(void)
  24268. {
  24269. EXPECT_DECLS;
  24270. #ifndef NO_DH
  24271. #if defined(WOLFSSL_DH_EXTRA) && defined(USE_CERT_BUFFERS_2048)
  24272. DhKey key;
  24273. word32 inOutIdx;
  24274. XMEMSET(&key, 0, sizeof(DhKey));
  24275. ExpectIntEQ(wc_InitDhKey(&key), 0);
  24276. ExpectIntEQ(wc_DhPublicKeyDecode(NULL,NULL,NULL,0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24277. ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,NULL,NULL,0),
  24278. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24279. ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,NULL,NULL,0),
  24280. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24281. inOutIdx = 0;
  24282. ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,&inOutIdx,NULL, 0),
  24283. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24284. inOutIdx = 0;
  24285. ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,&inOutIdx,&key, 0),
  24286. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24287. inOutIdx = 0;
  24288. ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,&inOutIdx,&key,
  24289. sizeof_dh_pub_key_der_2048), 0);
  24290. ExpectIntNE(key.p.used, 0);
  24291. ExpectIntNE(key.g.used, 0);
  24292. ExpectIntEQ(key.q.used, 0);
  24293. ExpectIntNE(key.pub.used, 0);
  24294. ExpectIntEQ(key.priv.used, 0);
  24295. DoExpectIntEQ(wc_FreeDhKey(&key), 0);
  24296. #endif
  24297. #endif /* !NO_DH */
  24298. return EXPECT_RESULT();
  24299. }
  24300. /*
  24301. * Testing wc_Ed25519KeyToDer
  24302. */
  24303. static int test_wc_Ed25519KeyToDer(void)
  24304. {
  24305. EXPECT_DECLS;
  24306. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT) && \
  24307. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  24308. byte output[ONEK_BUF];
  24309. ed25519_key ed25519Key;
  24310. WC_RNG rng;
  24311. word32 inLen;
  24312. XMEMSET(&ed25519Key, 0, sizeof(ed25519_key));
  24313. XMEMSET(&rng, 0, sizeof(WC_RNG));
  24314. ExpectIntEQ(wc_ed25519_init(&ed25519Key), 0);
  24315. ExpectIntEQ(wc_InitRng(&rng), 0);
  24316. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &ed25519Key), 0);
  24317. inLen = (word32)sizeof(output);
  24318. /* Bad Cases */
  24319. ExpectIntEQ(wc_Ed25519KeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24320. ExpectIntEQ(wc_Ed25519KeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24321. ExpectIntEQ(wc_Ed25519KeyToDer(&ed25519Key, output, 0), WC_NO_ERR_TRACE(BUFFER_E));
  24322. /* Good Cases */
  24323. /* length only */
  24324. ExpectIntGT(wc_Ed25519KeyToDer(&ed25519Key, NULL, 0), 0);
  24325. ExpectIntGT(wc_Ed25519KeyToDer(&ed25519Key, NULL, inLen), 0);
  24326. ExpectIntGT(wc_Ed25519KeyToDer(&ed25519Key, output, inLen), 0);
  24327. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  24328. wc_ed25519_free(&ed25519Key);
  24329. #endif
  24330. return EXPECT_RESULT();
  24331. } /* End test_wc_Ed25519KeyToDer*/
  24332. /*
  24333. * Testing wc_Ed25519PrivateKeyToDer
  24334. */
  24335. static int test_wc_Ed25519PrivateKeyToDer(void)
  24336. {
  24337. EXPECT_DECLS;
  24338. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT) && \
  24339. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  24340. byte output[ONEK_BUF];
  24341. ed25519_key ed25519PrivKey;
  24342. WC_RNG rng;
  24343. word32 inLen;
  24344. XMEMSET(&ed25519PrivKey, 0, sizeof(ed25519_key));
  24345. XMEMSET(&rng, 0, sizeof(WC_RNG));
  24346. ExpectIntEQ(wc_ed25519_init(&ed25519PrivKey), 0);
  24347. ExpectIntEQ(wc_InitRng(&rng), 0);
  24348. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &ed25519PrivKey),
  24349. 0);
  24350. inLen = (word32)sizeof(output);
  24351. /* Bad Cases */
  24352. ExpectIntEQ(wc_Ed25519PrivateKeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24353. ExpectIntEQ(wc_Ed25519PrivateKeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24354. ExpectIntEQ(wc_Ed25519PrivateKeyToDer(&ed25519PrivKey, output, 0),
  24355. WC_NO_ERR_TRACE(BUFFER_E));
  24356. /* Good Cases */
  24357. /* length only */
  24358. ExpectIntGT(wc_Ed25519PrivateKeyToDer(&ed25519PrivKey, NULL, 0), 0);
  24359. ExpectIntGT(wc_Ed25519PrivateKeyToDer(&ed25519PrivKey, output, inLen), 0);
  24360. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  24361. wc_ed25519_free(&ed25519PrivKey);
  24362. #endif
  24363. return EXPECT_RESULT();
  24364. } /* End test_wc_Ed25519PrivateKeyToDer*/
  24365. /*
  24366. * Testing wc_Ed448KeyToDer
  24367. */
  24368. static int test_wc_Ed448KeyToDer(void)
  24369. {
  24370. EXPECT_DECLS;
  24371. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT) && \
  24372. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  24373. byte output[ONEK_BUF];
  24374. ed448_key ed448Key;
  24375. WC_RNG rng;
  24376. word32 inLen;
  24377. XMEMSET(&ed448Key, 0, sizeof(ed448_key));
  24378. XMEMSET(&rng, 0, sizeof(WC_RNG));
  24379. ExpectIntEQ(wc_ed448_init(&ed448Key), 0);
  24380. ExpectIntEQ(wc_InitRng(&rng), 0);
  24381. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &ed448Key), 0);
  24382. inLen = (word32)sizeof(output);
  24383. /* Bad Cases */
  24384. ExpectIntEQ(wc_Ed448KeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24385. ExpectIntEQ(wc_Ed448KeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24386. ExpectIntEQ(wc_Ed448KeyToDer(&ed448Key, output, 0), WC_NO_ERR_TRACE(BUFFER_E));
  24387. /* Good Cases */
  24388. /* length only */
  24389. ExpectIntGT(wc_Ed448KeyToDer(&ed448Key, NULL, 0), 0);
  24390. ExpectIntGT(wc_Ed448KeyToDer(&ed448Key, output, inLen), 0);
  24391. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  24392. wc_ed448_free(&ed448Key);
  24393. #endif
  24394. return EXPECT_RESULT();
  24395. } /* End test_wc_Ed448KeyToDer*/
  24396. /*
  24397. * Testing wc_Ed448PrivateKeyToDer
  24398. */
  24399. static int test_wc_Ed448PrivateKeyToDer(void)
  24400. {
  24401. EXPECT_DECLS;
  24402. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT) && \
  24403. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  24404. byte output[ONEK_BUF];
  24405. ed448_key ed448PrivKey;
  24406. WC_RNG rng;
  24407. word32 inLen;
  24408. XMEMSET(&ed448PrivKey, 0, sizeof(ed448_key));
  24409. XMEMSET(&rng, 0, sizeof(WC_RNG));
  24410. ExpectIntEQ(wc_ed448_init(&ed448PrivKey), 0);
  24411. ExpectIntEQ(wc_InitRng(&rng), 0);
  24412. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &ed448PrivKey),
  24413. 0);
  24414. inLen = (word32)sizeof(output);
  24415. /* Bad Cases */
  24416. ExpectIntEQ(wc_Ed448PrivateKeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24417. ExpectIntEQ(wc_Ed448PrivateKeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24418. ExpectIntEQ(wc_Ed448PrivateKeyToDer(&ed448PrivKey, output, 0),
  24419. WC_NO_ERR_TRACE(BUFFER_E));
  24420. /* Good cases */
  24421. /* length only */
  24422. ExpectIntGT(wc_Ed448PrivateKeyToDer(&ed448PrivKey, NULL, 0), 0);
  24423. ExpectIntGT(wc_Ed448PrivateKeyToDer(&ed448PrivKey, output, inLen), 0);
  24424. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  24425. wc_ed448_free(&ed448PrivKey);
  24426. #endif
  24427. return EXPECT_RESULT();
  24428. } /* End test_wc_Ed448PrivateKeyToDer*/
  24429. /*
  24430. * Testing wc_Curve448PrivateKeyToDer
  24431. */
  24432. static int test_wc_Curve448PrivateKeyToDer(void)
  24433. {
  24434. EXPECT_DECLS;
  24435. #if defined(HAVE_CURVE448) && defined(HAVE_CURVE448_KEY_EXPORT) && \
  24436. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  24437. byte output[ONEK_BUF];
  24438. curve448_key curve448PrivKey;
  24439. WC_RNG rng;
  24440. word32 inLen;
  24441. XMEMSET(&curve448PrivKey, 0, sizeof(curve448PrivKey));
  24442. XMEMSET(&rng, 0, sizeof(WC_RNG));
  24443. ExpectIntEQ(wc_curve448_init(&curve448PrivKey), 0);
  24444. ExpectIntEQ(wc_InitRng(&rng), 0);
  24445. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &curve448PrivKey),
  24446. 0);
  24447. inLen = (word32)sizeof(output);
  24448. /* Bad Cases */
  24449. ExpectIntEQ(wc_Curve448PrivateKeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24450. ExpectIntEQ(wc_Curve448PrivateKeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24451. ExpectIntEQ(wc_Curve448PrivateKeyToDer(&curve448PrivKey, output, 0),
  24452. WC_NO_ERR_TRACE(BUFFER_E));
  24453. /* Good cases */
  24454. /* length only */
  24455. ExpectIntGT(wc_Curve448PrivateKeyToDer(&curve448PrivKey, NULL, 0), 0);
  24456. ExpectIntGT(wc_Curve448PrivateKeyToDer(&curve448PrivKey, output, inLen), 0);
  24457. /* Bad Cases */
  24458. ExpectIntEQ(wc_Curve448PublicKeyToDer(NULL, NULL, 0, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24459. ExpectIntEQ(wc_Curve448PublicKeyToDer(NULL, output, inLen, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24460. ExpectIntEQ(wc_Curve448PublicKeyToDer(&curve448PrivKey, output, 0, 0),
  24461. WC_NO_ERR_TRACE(BUFFER_E));
  24462. ExpectIntEQ(wc_Curve448PublicKeyToDer(&curve448PrivKey, output, 0, 1),
  24463. WC_NO_ERR_TRACE(BUFFER_E));
  24464. /* Good cases */
  24465. /* length only */
  24466. ExpectIntGT(wc_Curve448PublicKeyToDer(&curve448PrivKey, NULL, 0, 0), 0);
  24467. ExpectIntGT(wc_Curve448PublicKeyToDer(&curve448PrivKey, NULL, 0, 1), 0);
  24468. ExpectIntGT(wc_Curve448PublicKeyToDer(&curve448PrivKey, output, inLen, 0), 0);
  24469. ExpectIntGT(wc_Curve448PublicKeyToDer(&curve448PrivKey, output, inLen, 1), 0);
  24470. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  24471. wc_curve448_free(&curve448PrivKey);
  24472. #endif
  24473. return EXPECT_RESULT();
  24474. } /* End wc_Curve448PrivateKeyToDer*/
  24475. static int test_wc_kyber_make_key_kats(void)
  24476. {
  24477. EXPECT_DECLS;
  24478. #if defined(WOLFSSL_HAVE_KYBER) && defined(WOLFSSL_WC_KYBER) && \
  24479. !defined(WOLFSSL_KYBER_ORIGINAL)
  24480. KyberKey* key;
  24481. #ifndef WOLFSSL_NO_KYBER512
  24482. static const byte seed_512[KYBER_MAKEKEY_RAND_SZ] = {
  24483. /* d */
  24484. 0x2C, 0xB8, 0x43, 0xA0, 0x2E, 0xF0, 0x2E, 0xE1,
  24485. 0x09, 0x30, 0x5F, 0x39, 0x11, 0x9F, 0xAB, 0xF4,
  24486. 0x9A, 0xB9, 0x0A, 0x57, 0xFF, 0xEC, 0xB3, 0xA0,
  24487. 0xE7, 0x5E, 0x17, 0x94, 0x50, 0xF5, 0x27, 0x61,
  24488. /* z */
  24489. 0x84, 0xCC, 0x91, 0x21, 0xAE, 0x56, 0xFB, 0xF3,
  24490. 0x9E, 0x67, 0xAD, 0xBD, 0x83, 0xAD, 0x2D, 0x3E,
  24491. 0x3B, 0xB8, 0x08, 0x43, 0x64, 0x52, 0x06, 0xBD,
  24492. 0xD9, 0xF2, 0xF6, 0x29, 0xE3, 0xCC, 0x49, 0xB7
  24493. };
  24494. static const byte ek_512[KYBER512_PUBLIC_KEY_SIZE] = {
  24495. 0xA3, 0x24, 0x39, 0xF8, 0x5A, 0x3C, 0x21, 0xD2,
  24496. 0x1A, 0x71, 0xB9, 0xB9, 0x2A, 0x9B, 0x64, 0xEA,
  24497. 0x0A, 0xB8, 0x43, 0x12, 0xC7, 0x70, 0x23, 0x69,
  24498. 0x4F, 0xD6, 0x4E, 0xAA, 0xB9, 0x07, 0xA4, 0x35,
  24499. 0x39, 0xDD, 0xB2, 0x7B, 0xA0, 0xA8, 0x53, 0xCC,
  24500. 0x90, 0x69, 0xEA, 0xC8, 0x50, 0x8C, 0x65, 0x3E,
  24501. 0x60, 0x0B, 0x2A, 0xC0, 0x18, 0x38, 0x1B, 0x4B,
  24502. 0xB4, 0xA8, 0x79, 0xAC, 0xDA, 0xD3, 0x42, 0xF9,
  24503. 0x11, 0x79, 0xCA, 0x82, 0x49, 0x52, 0x5C, 0xB1,
  24504. 0x96, 0x8B, 0xBE, 0x52, 0xF7, 0x55, 0xB7, 0xF5,
  24505. 0xB4, 0x3D, 0x66, 0x63, 0xD7, 0xA3, 0xBF, 0x0F,
  24506. 0x33, 0x57, 0xD8, 0xA2, 0x1D, 0x15, 0xB5, 0x2D,
  24507. 0xB3, 0x81, 0x8E, 0xCE, 0x5B, 0x40, 0x2A, 0x60,
  24508. 0xC9, 0x93, 0xE7, 0xCF, 0x43, 0x64, 0x87, 0xB8,
  24509. 0xD2, 0xAE, 0x91, 0xE6, 0xC5, 0xB8, 0x82, 0x75,
  24510. 0xE7, 0x58, 0x24, 0xB0, 0x00, 0x7E, 0xF3, 0x12,
  24511. 0x3C, 0x0A, 0xB5, 0x1B, 0x5C, 0xC6, 0x1B, 0x9B,
  24512. 0x22, 0x38, 0x0D, 0xE6, 0x6C, 0x5B, 0x20, 0xB0,
  24513. 0x60, 0xCB, 0xB9, 0x86, 0xF8, 0x12, 0x3D, 0x94,
  24514. 0x06, 0x00, 0x49, 0xCD, 0xF8, 0x03, 0x68, 0x73,
  24515. 0xA7, 0xBE, 0x10, 0x94, 0x44, 0xA0, 0xA1, 0xCD,
  24516. 0x87, 0xA4, 0x8C, 0xAE, 0x54, 0x19, 0x24, 0x84,
  24517. 0xAF, 0x84, 0x44, 0x29, 0xC1, 0xC5, 0x8C, 0x29,
  24518. 0xAC, 0x62, 0x4C, 0xD5, 0x04, 0xF1, 0xC4, 0x4F,
  24519. 0x1E, 0x13, 0x47, 0x82, 0x2B, 0x6F, 0x22, 0x13,
  24520. 0x23, 0x85, 0x9A, 0x7F, 0x6F, 0x75, 0x4B, 0xFE,
  24521. 0x71, 0x0B, 0xDA, 0x60, 0x27, 0x62, 0x40, 0xA4,
  24522. 0xFF, 0x2A, 0x53, 0x50, 0x70, 0x37, 0x86, 0xF5,
  24523. 0x67, 0x1F, 0x44, 0x9F, 0x20, 0xC2, 0xA9, 0x5A,
  24524. 0xE7, 0xC2, 0x90, 0x3A, 0x42, 0xCB, 0x3B, 0x30,
  24525. 0x3F, 0xF4, 0xC4, 0x27, 0xC0, 0x8B, 0x11, 0xB4,
  24526. 0xCD, 0x31, 0xC4, 0x18, 0xC6, 0xD1, 0x8D, 0x08,
  24527. 0x61, 0x87, 0x3B, 0xFA, 0x03, 0x32, 0xF1, 0x12,
  24528. 0x71, 0x55, 0x2E, 0xD7, 0xC0, 0x35, 0xF0, 0xE4,
  24529. 0xBC, 0x42, 0x8C, 0x43, 0x72, 0x0B, 0x39, 0xA6,
  24530. 0x51, 0x66, 0xBA, 0x9C, 0x2D, 0x3D, 0x77, 0x0E,
  24531. 0x13, 0x03, 0x60, 0xCC, 0x23, 0x84, 0xE8, 0x30,
  24532. 0x95, 0xB1, 0xA1, 0x59, 0x49, 0x55, 0x33, 0xF1,
  24533. 0x16, 0xC7, 0xB5, 0x58, 0xB6, 0x50, 0xDB, 0x04,
  24534. 0xD5, 0xA2, 0x6E, 0xAA, 0xA0, 0x8C, 0x3E, 0xE5,
  24535. 0x7D, 0xE4, 0x5A, 0x7F, 0x88, 0xC6, 0xA3, 0xCE,
  24536. 0xB2, 0x4D, 0xC5, 0x39, 0x7B, 0x88, 0xC3, 0xCE,
  24537. 0xF0, 0x03, 0x31, 0x9B, 0xB0, 0x23, 0x3F, 0xD6,
  24538. 0x92, 0xFD, 0xA1, 0x52, 0x44, 0x75, 0xB3, 0x51,
  24539. 0xF3, 0xC7, 0x82, 0x18, 0x2D, 0xEC, 0xF5, 0x90,
  24540. 0xB7, 0x72, 0x3B, 0xE4, 0x00, 0xBE, 0x14, 0x80,
  24541. 0x9C, 0x44, 0x32, 0x99, 0x63, 0xFC, 0x46, 0x95,
  24542. 0x92, 0x11, 0xD6, 0xA6, 0x23, 0x33, 0x95, 0x37,
  24543. 0x84, 0x8C, 0x25, 0x16, 0x69, 0x94, 0x1D, 0x90,
  24544. 0xB1, 0x30, 0x25, 0x8A, 0xDF, 0x55, 0xA7, 0x20,
  24545. 0xA7, 0x24, 0xE8, 0xB6, 0xA6, 0xCA, 0xE3, 0xC2,
  24546. 0x26, 0x4B, 0x16, 0x24, 0xCC, 0xBE, 0x7B, 0x45,
  24547. 0x6B, 0x30, 0xC8, 0xC7, 0x39, 0x32, 0x94, 0xCA,
  24548. 0x51, 0x80, 0xBC, 0x83, 0x7D, 0xD2, 0xE4, 0x5D,
  24549. 0xBD, 0x59, 0xB6, 0xE1, 0x7B, 0x24, 0xFE, 0x93,
  24550. 0x05, 0x2E, 0xB7, 0xC4, 0x3B, 0x27, 0xAC, 0x3D,
  24551. 0xC2, 0x49, 0xCA, 0x0C, 0xBC, 0xA4, 0xFB, 0x58,
  24552. 0x97, 0xC0, 0xB7, 0x44, 0x08, 0x8A, 0x8A, 0x07,
  24553. 0x79, 0xD3, 0x22, 0x33, 0x82, 0x6A, 0x01, 0xDD,
  24554. 0x64, 0x89, 0x95, 0x2A, 0x48, 0x25, 0xE5, 0x35,
  24555. 0x8A, 0x70, 0x0B, 0xE0, 0xE1, 0x79, 0xAC, 0x19,
  24556. 0x77, 0x10, 0xD8, 0x3E, 0xCC, 0x85, 0x3E, 0x52,
  24557. 0x69, 0x5E, 0x9B, 0xF8, 0x7B, 0xB1, 0xF6, 0xCB,
  24558. 0xD0, 0x5B, 0x02, 0xD4, 0xE6, 0x79, 0xE3, 0xB8,
  24559. 0x8D, 0xD4, 0x83, 0xB0, 0x74, 0x9B, 0x11, 0xBD,
  24560. 0x37, 0xB3, 0x83, 0xDC, 0xCA, 0x71, 0xF9, 0x09,
  24561. 0x18, 0x34, 0xA1, 0x69, 0x55, 0x02, 0xC4, 0xB9,
  24562. 0x5F, 0xC9, 0x11, 0x8C, 0x1C, 0xFC, 0x34, 0xC8,
  24563. 0x4C, 0x22, 0x65, 0xBB, 0xBC, 0x56, 0x3C, 0x28,
  24564. 0x26, 0x66, 0xB6, 0x0A, 0xE5, 0xC7, 0xF3, 0x85,
  24565. 0x1D, 0x25, 0xEC, 0xBB, 0x50, 0x21, 0xCC, 0x38,
  24566. 0xCB, 0x73, 0xEB, 0x6A, 0x34, 0x11, 0xB1, 0xC2,
  24567. 0x90, 0x46, 0xCA, 0x66, 0x54, 0x06, 0x67, 0xD1,
  24568. 0x36, 0x95, 0x44, 0x60, 0xC6, 0xFC, 0xBC, 0x4B,
  24569. 0xC7, 0xC0, 0x49, 0xBB, 0x04, 0x7F, 0xA6, 0x7A,
  24570. 0x63, 0xB3, 0xCC, 0x11, 0x11, 0xC1, 0xD8, 0xAC,
  24571. 0x27, 0xE8, 0x05, 0x8B, 0xCC, 0xA4, 0xA1, 0x54,
  24572. 0x55, 0x85, 0x8A, 0x58, 0x35, 0x8F, 0x7A, 0x61,
  24573. 0x02, 0x0B, 0xC9, 0xC4, 0xC1, 0x7F, 0x8B, 0x95,
  24574. 0xC2, 0x68, 0xCC, 0xB4, 0x04, 0xB9, 0xAA, 0xB4,
  24575. 0xA2, 0x72, 0xA2, 0x1A, 0x70, 0xDA, 0xF6, 0xB6,
  24576. 0xF1, 0x51, 0x21, 0xEE, 0x01, 0xC1, 0x56, 0xA3,
  24577. 0x54, 0xAA, 0x17, 0x08, 0x7E, 0x07, 0x70, 0x2E,
  24578. 0xAB, 0x38, 0xB3, 0x24, 0x1F, 0xDB, 0x55, 0x3F,
  24579. 0x65, 0x73, 0x39, 0xD5, 0xE2, 0x9D, 0xC5, 0xD9,
  24580. 0x1B, 0x7A, 0x5A, 0x82, 0x8E, 0xE9, 0x59, 0xFE,
  24581. 0xBB, 0x90, 0xB0, 0x72, 0x29, 0xF6, 0xE4, 0x9D,
  24582. 0x23, 0xC3, 0xA1, 0x90, 0x29, 0x70, 0x42, 0xFB,
  24583. 0x43, 0x98, 0x69, 0x55, 0xB6, 0x9C, 0x28, 0xE1,
  24584. 0x01, 0x6F, 0x77, 0xA5, 0x8B, 0x43, 0x15, 0x14,
  24585. 0xD2, 0x1B, 0x88, 0x88, 0x99, 0xC3, 0x60, 0x82,
  24586. 0x76, 0x08, 0x1B, 0x75, 0xF5, 0x68, 0x09, 0x7C,
  24587. 0xDC, 0x17, 0x48, 0xF3, 0x23, 0x07, 0x88, 0x58,
  24588. 0x15, 0xF3, 0xAE, 0xC9, 0x65, 0x18, 0x19, 0xAA,
  24589. 0x68, 0x73, 0xD1, 0xA4, 0xEB, 0x83, 0xB1, 0x95,
  24590. 0x38, 0x43, 0xB9, 0x34, 0x22, 0x51, 0x94, 0x83,
  24591. 0xFE, 0xF0, 0x05, 0x9D, 0x36, 0xBB, 0x2D, 0xB1,
  24592. 0xF3, 0xD4, 0x68, 0xFB, 0x06, 0x8C, 0x86, 0xE8,
  24593. 0x97, 0x37, 0x33, 0xC3, 0x98, 0xEA, 0xF0, 0x0E,
  24594. 0x17, 0x02, 0xC6, 0x73, 0x4A, 0xD8, 0xEB, 0x3B
  24595. };
  24596. static const byte dk_512[KYBER512_PRIVATE_KEY_SIZE] = {
  24597. 0x7F, 0xE4, 0x20, 0x6F, 0x26, 0xBE, 0xDB, 0x64,
  24598. 0xC1, 0xED, 0x00, 0x09, 0x61, 0x52, 0x45, 0xDC,
  24599. 0x98, 0x48, 0x3F, 0x66, 0x3A, 0xCC, 0x61, 0x7E,
  24600. 0x65, 0x89, 0x8D, 0x59, 0x6A, 0x88, 0x36, 0xC4,
  24601. 0x9F, 0xBD, 0x3B, 0x4A, 0x84, 0x97, 0x59, 0xAA,
  24602. 0x15, 0x46, 0xBD, 0xA8, 0x35, 0xCA, 0xF1, 0x75,
  24603. 0x64, 0x2C, 0x28, 0x28, 0x08, 0x92, 0xA7, 0x87,
  24604. 0x8C, 0xC3, 0x18, 0xBC, 0xC7, 0x5B, 0x83, 0x4C,
  24605. 0xB2, 0x9F, 0xDF, 0x53, 0x60, 0xD7, 0xF9, 0x82,
  24606. 0xA5, 0x2C, 0x88, 0xAE, 0x91, 0x4D, 0xBF, 0x02,
  24607. 0xB5, 0x8B, 0xEB, 0x8B, 0xA8, 0x87, 0xAE, 0x8F,
  24608. 0xAB, 0x5E, 0xB7, 0x87, 0x31, 0xC6, 0x75, 0x78,
  24609. 0x05, 0x47, 0x1E, 0xBC, 0xEC, 0x2E, 0x38, 0xDB,
  24610. 0x1F, 0x4B, 0x83, 0x10, 0xD2, 0x88, 0x92, 0x0D,
  24611. 0x8A, 0x49, 0x27, 0x95, 0xA3, 0x90, 0xA7, 0x4B,
  24612. 0xCD, 0x55, 0xCD, 0x85, 0x57, 0xB4, 0xDA, 0xAB,
  24613. 0xA8, 0x2C, 0x28, 0xCB, 0x3F, 0x15, 0x2C, 0x52,
  24614. 0x31, 0x19, 0x61, 0x93, 0xA6, 0x6A, 0x8C, 0xCF,
  24615. 0x34, 0xB8, 0x0E, 0x1F, 0x69, 0x42, 0xC3, 0x2B,
  24616. 0xCF, 0xF9, 0x6A, 0x6E, 0x3C, 0xF3, 0x93, 0x9B,
  24617. 0x7B, 0x94, 0x24, 0x98, 0xCC, 0x5E, 0x4C, 0xB8,
  24618. 0xE8, 0x46, 0x8E, 0x70, 0x27, 0x59, 0x85, 0x2A,
  24619. 0xA2, 0x29, 0xC0, 0x25, 0x7F, 0x02, 0x98, 0x20,
  24620. 0x97, 0x33, 0x86, 0x07, 0xC0, 0xF0, 0xF4, 0x54,
  24621. 0x46, 0xFA, 0xB4, 0x26, 0x79, 0x93, 0xB8, 0xA5,
  24622. 0x90, 0x8C, 0xAB, 0x9C, 0x46, 0x78, 0x01, 0x34,
  24623. 0x80, 0x4A, 0xE1, 0x88, 0x15, 0xB1, 0x02, 0x05,
  24624. 0x27, 0xA2, 0x22, 0xEC, 0x4B, 0x39, 0xA3, 0x19,
  24625. 0x4E, 0x66, 0x17, 0x37, 0x79, 0x17, 0x14, 0x12,
  24626. 0x26, 0x62, 0xD8, 0xB9, 0x76, 0x9F, 0x6C, 0x67,
  24627. 0xDE, 0x62, 0x5C, 0x0D, 0x48, 0x3C, 0x3D, 0x42,
  24628. 0x0F, 0xF1, 0xBB, 0x88, 0x9A, 0x72, 0x7E, 0x75,
  24629. 0x62, 0x81, 0x51, 0x3A, 0x70, 0x04, 0x76, 0x48,
  24630. 0xD2, 0x9C, 0x0C, 0x30, 0xF9, 0xBE, 0x52, 0xEC,
  24631. 0x0D, 0xEB, 0x97, 0x7C, 0xF0, 0xF3, 0x4F, 0xC2,
  24632. 0x07, 0x84, 0x83, 0x45, 0x69, 0x64, 0x74, 0x34,
  24633. 0x10, 0x63, 0x8C, 0x57, 0xB5, 0x53, 0x95, 0x77,
  24634. 0xBF, 0x85, 0x66, 0x90, 0x78, 0xC3, 0x56, 0xB3,
  24635. 0x46, 0x2E, 0x9F, 0xA5, 0x80, 0x7D, 0x49, 0x59,
  24636. 0x1A, 0xFA, 0x41, 0xC1, 0x96, 0x9F, 0x65, 0xE3,
  24637. 0x40, 0x5C, 0xB6, 0x4D, 0xDF, 0x16, 0x3F, 0x26,
  24638. 0x73, 0x4C, 0xE3, 0x48, 0xB9, 0xCF, 0x45, 0x67,
  24639. 0xA3, 0x3A, 0x59, 0x69, 0xEB, 0x32, 0x6C, 0xFB,
  24640. 0x5A, 0xDC, 0x69, 0x5D, 0xCA, 0x0C, 0x8B, 0x2A,
  24641. 0x7B, 0x1F, 0x4F, 0x40, 0x4C, 0xC7, 0xA0, 0x98,
  24642. 0x1E, 0x2C, 0xC2, 0x4C, 0x1C, 0x23, 0xD1, 0x6A,
  24643. 0xA9, 0xB4, 0x39, 0x24, 0x15, 0xE2, 0x6C, 0x22,
  24644. 0xF4, 0xA9, 0x34, 0xD7, 0x94, 0xC1, 0xFB, 0x4E,
  24645. 0x5A, 0x67, 0x05, 0x11, 0x23, 0xCC, 0xD1, 0x53,
  24646. 0x76, 0x4D, 0xEC, 0x99, 0xD5, 0x53, 0x52, 0x90,
  24647. 0x53, 0xC3, 0xDA, 0x55, 0x0B, 0xCE, 0xA3, 0xAC,
  24648. 0x54, 0x13, 0x6A, 0x26, 0xA6, 0x76, 0xD2, 0xBA,
  24649. 0x84, 0x21, 0x06, 0x70, 0x68, 0xC6, 0x38, 0x1C,
  24650. 0x2A, 0x62, 0xA7, 0x27, 0xC9, 0x33, 0x70, 0x2E,
  24651. 0xE5, 0x80, 0x4A, 0x31, 0xCA, 0x86, 0x5A, 0x45,
  24652. 0x58, 0x8F, 0xB7, 0x4D, 0xE7, 0xE2, 0x22, 0x3D,
  24653. 0x88, 0xC0, 0x60, 0x8A, 0x16, 0xBF, 0xEC, 0x4F,
  24654. 0xAD, 0x67, 0x52, 0xDB, 0x56, 0xB4, 0x8B, 0x88,
  24655. 0x72, 0xBF, 0x26, 0xBA, 0x2F, 0xFA, 0x0C, 0xED,
  24656. 0xE5, 0x34, 0x3B, 0xE8, 0x14, 0x36, 0x89, 0x26,
  24657. 0x5E, 0x06, 0x5F, 0x41, 0xA6, 0x92, 0x5B, 0x86,
  24658. 0xC8, 0x92, 0xE6, 0x2E, 0xB0, 0x77, 0x27, 0x34,
  24659. 0xF5, 0xA3, 0x57, 0xC7, 0x5C, 0xA1, 0xAC, 0x6D,
  24660. 0xF7, 0x8A, 0xB1, 0xB8, 0x88, 0x5A, 0xD0, 0x81,
  24661. 0x96, 0x15, 0x37, 0x6D, 0x33, 0xEB, 0xB9, 0x8F,
  24662. 0x87, 0x33, 0xA6, 0x75, 0x58, 0x03, 0xD9, 0x77,
  24663. 0xBF, 0x51, 0xC1, 0x27, 0x40, 0x42, 0x4B, 0x2B,
  24664. 0x49, 0xC2, 0x83, 0x82, 0xA6, 0x91, 0x7C, 0xBF,
  24665. 0xA0, 0x34, 0xC3, 0xF1, 0x26, 0xA3, 0x8C, 0x21,
  24666. 0x6C, 0x03, 0xC3, 0x57, 0x70, 0xAD, 0x48, 0x1B,
  24667. 0x90, 0x84, 0xB5, 0x58, 0x8D, 0xA6, 0x5F, 0xF1,
  24668. 0x18, 0xA7, 0x4F, 0x93, 0x2C, 0x7E, 0x53, 0x7A,
  24669. 0xBE, 0x58, 0x63, 0xFB, 0x29, 0xA1, 0x0C, 0x09,
  24670. 0x70, 0x1B, 0x44, 0x1F, 0x83, 0x99, 0xC1, 0xF8,
  24671. 0xA6, 0x37, 0x82, 0x5A, 0xCE, 0xA3, 0xE9, 0x31,
  24672. 0x80, 0x57, 0x4F, 0xDE, 0xB8, 0x80, 0x76, 0x66,
  24673. 0x1A, 0xB4, 0x69, 0x51, 0x71, 0x6A, 0x50, 0x01,
  24674. 0x84, 0xA0, 0x40, 0x55, 0x72, 0x66, 0x59, 0x8C,
  24675. 0xAF, 0x76, 0x10, 0x5E, 0x1C, 0x18, 0x70, 0xB4,
  24676. 0x39, 0x69, 0xC3, 0xBC, 0xC1, 0xA0, 0x49, 0x27,
  24677. 0x63, 0x80, 0x17, 0x49, 0x8B, 0xB6, 0x2C, 0xAF,
  24678. 0xD3, 0xA6, 0xB0, 0x82, 0xB7, 0xBF, 0x7A, 0x23,
  24679. 0x45, 0x0E, 0x19, 0x17, 0x99, 0x61, 0x9B, 0x92,
  24680. 0x51, 0x12, 0xD0, 0x72, 0x02, 0x5C, 0xA8, 0x88,
  24681. 0x54, 0x8C, 0x79, 0x1A, 0xA4, 0x22, 0x51, 0x50,
  24682. 0x4D, 0x5D, 0x1C, 0x1C, 0xDD, 0xB2, 0x13, 0x30,
  24683. 0x3B, 0x04, 0x9E, 0x73, 0x46, 0xE8, 0xD8, 0x3A,
  24684. 0xD5, 0x87, 0x83, 0x6F, 0x35, 0x28, 0x4E, 0x10,
  24685. 0x97, 0x27, 0xE6, 0x6B, 0xBC, 0xC9, 0x52, 0x1F,
  24686. 0xE0, 0xB1, 0x91, 0x63, 0x00, 0x47, 0xD1, 0x58,
  24687. 0xF7, 0x56, 0x40, 0xFF, 0xEB, 0x54, 0x56, 0x07,
  24688. 0x27, 0x40, 0x02, 0x1A, 0xFD, 0x15, 0xA4, 0x54,
  24689. 0x69, 0xC5, 0x83, 0x82, 0x9D, 0xAA, 0xC8, 0xA7,
  24690. 0xDE, 0xB0, 0x5B, 0x24, 0xF0, 0x56, 0x7E, 0x43,
  24691. 0x17, 0xB3, 0xE3, 0xB3, 0x33, 0x89, 0xB5, 0xC5,
  24692. 0xF8, 0xB0, 0x4B, 0x09, 0x9F, 0xB4, 0xD1, 0x03,
  24693. 0xA3, 0x24, 0x39, 0xF8, 0x5A, 0x3C, 0x21, 0xD2,
  24694. 0x1A, 0x71, 0xB9, 0xB9, 0x2A, 0x9B, 0x64, 0xEA,
  24695. 0x0A, 0xB8, 0x43, 0x12, 0xC7, 0x70, 0x23, 0x69,
  24696. 0x4F, 0xD6, 0x4E, 0xAA, 0xB9, 0x07, 0xA4, 0x35,
  24697. 0x39, 0xDD, 0xB2, 0x7B, 0xA0, 0xA8, 0x53, 0xCC,
  24698. 0x90, 0x69, 0xEA, 0xC8, 0x50, 0x8C, 0x65, 0x3E,
  24699. 0x60, 0x0B, 0x2A, 0xC0, 0x18, 0x38, 0x1B, 0x4B,
  24700. 0xB4, 0xA8, 0x79, 0xAC, 0xDA, 0xD3, 0x42, 0xF9,
  24701. 0x11, 0x79, 0xCA, 0x82, 0x49, 0x52, 0x5C, 0xB1,
  24702. 0x96, 0x8B, 0xBE, 0x52, 0xF7, 0x55, 0xB7, 0xF5,
  24703. 0xB4, 0x3D, 0x66, 0x63, 0xD7, 0xA3, 0xBF, 0x0F,
  24704. 0x33, 0x57, 0xD8, 0xA2, 0x1D, 0x15, 0xB5, 0x2D,
  24705. 0xB3, 0x81, 0x8E, 0xCE, 0x5B, 0x40, 0x2A, 0x60,
  24706. 0xC9, 0x93, 0xE7, 0xCF, 0x43, 0x64, 0x87, 0xB8,
  24707. 0xD2, 0xAE, 0x91, 0xE6, 0xC5, 0xB8, 0x82, 0x75,
  24708. 0xE7, 0x58, 0x24, 0xB0, 0x00, 0x7E, 0xF3, 0x12,
  24709. 0x3C, 0x0A, 0xB5, 0x1B, 0x5C, 0xC6, 0x1B, 0x9B,
  24710. 0x22, 0x38, 0x0D, 0xE6, 0x6C, 0x5B, 0x20, 0xB0,
  24711. 0x60, 0xCB, 0xB9, 0x86, 0xF8, 0x12, 0x3D, 0x94,
  24712. 0x06, 0x00, 0x49, 0xCD, 0xF8, 0x03, 0x68, 0x73,
  24713. 0xA7, 0xBE, 0x10, 0x94, 0x44, 0xA0, 0xA1, 0xCD,
  24714. 0x87, 0xA4, 0x8C, 0xAE, 0x54, 0x19, 0x24, 0x84,
  24715. 0xAF, 0x84, 0x44, 0x29, 0xC1, 0xC5, 0x8C, 0x29,
  24716. 0xAC, 0x62, 0x4C, 0xD5, 0x04, 0xF1, 0xC4, 0x4F,
  24717. 0x1E, 0x13, 0x47, 0x82, 0x2B, 0x6F, 0x22, 0x13,
  24718. 0x23, 0x85, 0x9A, 0x7F, 0x6F, 0x75, 0x4B, 0xFE,
  24719. 0x71, 0x0B, 0xDA, 0x60, 0x27, 0x62, 0x40, 0xA4,
  24720. 0xFF, 0x2A, 0x53, 0x50, 0x70, 0x37, 0x86, 0xF5,
  24721. 0x67, 0x1F, 0x44, 0x9F, 0x20, 0xC2, 0xA9, 0x5A,
  24722. 0xE7, 0xC2, 0x90, 0x3A, 0x42, 0xCB, 0x3B, 0x30,
  24723. 0x3F, 0xF4, 0xC4, 0x27, 0xC0, 0x8B, 0x11, 0xB4,
  24724. 0xCD, 0x31, 0xC4, 0x18, 0xC6, 0xD1, 0x8D, 0x08,
  24725. 0x61, 0x87, 0x3B, 0xFA, 0x03, 0x32, 0xF1, 0x12,
  24726. 0x71, 0x55, 0x2E, 0xD7, 0xC0, 0x35, 0xF0, 0xE4,
  24727. 0xBC, 0x42, 0x8C, 0x43, 0x72, 0x0B, 0x39, 0xA6,
  24728. 0x51, 0x66, 0xBA, 0x9C, 0x2D, 0x3D, 0x77, 0x0E,
  24729. 0x13, 0x03, 0x60, 0xCC, 0x23, 0x84, 0xE8, 0x30,
  24730. 0x95, 0xB1, 0xA1, 0x59, 0x49, 0x55, 0x33, 0xF1,
  24731. 0x16, 0xC7, 0xB5, 0x58, 0xB6, 0x50, 0xDB, 0x04,
  24732. 0xD5, 0xA2, 0x6E, 0xAA, 0xA0, 0x8C, 0x3E, 0xE5,
  24733. 0x7D, 0xE4, 0x5A, 0x7F, 0x88, 0xC6, 0xA3, 0xCE,
  24734. 0xB2, 0x4D, 0xC5, 0x39, 0x7B, 0x88, 0xC3, 0xCE,
  24735. 0xF0, 0x03, 0x31, 0x9B, 0xB0, 0x23, 0x3F, 0xD6,
  24736. 0x92, 0xFD, 0xA1, 0x52, 0x44, 0x75, 0xB3, 0x51,
  24737. 0xF3, 0xC7, 0x82, 0x18, 0x2D, 0xEC, 0xF5, 0x90,
  24738. 0xB7, 0x72, 0x3B, 0xE4, 0x00, 0xBE, 0x14, 0x80,
  24739. 0x9C, 0x44, 0x32, 0x99, 0x63, 0xFC, 0x46, 0x95,
  24740. 0x92, 0x11, 0xD6, 0xA6, 0x23, 0x33, 0x95, 0x37,
  24741. 0x84, 0x8C, 0x25, 0x16, 0x69, 0x94, 0x1D, 0x90,
  24742. 0xB1, 0x30, 0x25, 0x8A, 0xDF, 0x55, 0xA7, 0x20,
  24743. 0xA7, 0x24, 0xE8, 0xB6, 0xA6, 0xCA, 0xE3, 0xC2,
  24744. 0x26, 0x4B, 0x16, 0x24, 0xCC, 0xBE, 0x7B, 0x45,
  24745. 0x6B, 0x30, 0xC8, 0xC7, 0x39, 0x32, 0x94, 0xCA,
  24746. 0x51, 0x80, 0xBC, 0x83, 0x7D, 0xD2, 0xE4, 0x5D,
  24747. 0xBD, 0x59, 0xB6, 0xE1, 0x7B, 0x24, 0xFE, 0x93,
  24748. 0x05, 0x2E, 0xB7, 0xC4, 0x3B, 0x27, 0xAC, 0x3D,
  24749. 0xC2, 0x49, 0xCA, 0x0C, 0xBC, 0xA4, 0xFB, 0x58,
  24750. 0x97, 0xC0, 0xB7, 0x44, 0x08, 0x8A, 0x8A, 0x07,
  24751. 0x79, 0xD3, 0x22, 0x33, 0x82, 0x6A, 0x01, 0xDD,
  24752. 0x64, 0x89, 0x95, 0x2A, 0x48, 0x25, 0xE5, 0x35,
  24753. 0x8A, 0x70, 0x0B, 0xE0, 0xE1, 0x79, 0xAC, 0x19,
  24754. 0x77, 0x10, 0xD8, 0x3E, 0xCC, 0x85, 0x3E, 0x52,
  24755. 0x69, 0x5E, 0x9B, 0xF8, 0x7B, 0xB1, 0xF6, 0xCB,
  24756. 0xD0, 0x5B, 0x02, 0xD4, 0xE6, 0x79, 0xE3, 0xB8,
  24757. 0x8D, 0xD4, 0x83, 0xB0, 0x74, 0x9B, 0x11, 0xBD,
  24758. 0x37, 0xB3, 0x83, 0xDC, 0xCA, 0x71, 0xF9, 0x09,
  24759. 0x18, 0x34, 0xA1, 0x69, 0x55, 0x02, 0xC4, 0xB9,
  24760. 0x5F, 0xC9, 0x11, 0x8C, 0x1C, 0xFC, 0x34, 0xC8,
  24761. 0x4C, 0x22, 0x65, 0xBB, 0xBC, 0x56, 0x3C, 0x28,
  24762. 0x26, 0x66, 0xB6, 0x0A, 0xE5, 0xC7, 0xF3, 0x85,
  24763. 0x1D, 0x25, 0xEC, 0xBB, 0x50, 0x21, 0xCC, 0x38,
  24764. 0xCB, 0x73, 0xEB, 0x6A, 0x34, 0x11, 0xB1, 0xC2,
  24765. 0x90, 0x46, 0xCA, 0x66, 0x54, 0x06, 0x67, 0xD1,
  24766. 0x36, 0x95, 0x44, 0x60, 0xC6, 0xFC, 0xBC, 0x4B,
  24767. 0xC7, 0xC0, 0x49, 0xBB, 0x04, 0x7F, 0xA6, 0x7A,
  24768. 0x63, 0xB3, 0xCC, 0x11, 0x11, 0xC1, 0xD8, 0xAC,
  24769. 0x27, 0xE8, 0x05, 0x8B, 0xCC, 0xA4, 0xA1, 0x54,
  24770. 0x55, 0x85, 0x8A, 0x58, 0x35, 0x8F, 0x7A, 0x61,
  24771. 0x02, 0x0B, 0xC9, 0xC4, 0xC1, 0x7F, 0x8B, 0x95,
  24772. 0xC2, 0x68, 0xCC, 0xB4, 0x04, 0xB9, 0xAA, 0xB4,
  24773. 0xA2, 0x72, 0xA2, 0x1A, 0x70, 0xDA, 0xF6, 0xB6,
  24774. 0xF1, 0x51, 0x21, 0xEE, 0x01, 0xC1, 0x56, 0xA3,
  24775. 0x54, 0xAA, 0x17, 0x08, 0x7E, 0x07, 0x70, 0x2E,
  24776. 0xAB, 0x38, 0xB3, 0x24, 0x1F, 0xDB, 0x55, 0x3F,
  24777. 0x65, 0x73, 0x39, 0xD5, 0xE2, 0x9D, 0xC5, 0xD9,
  24778. 0x1B, 0x7A, 0x5A, 0x82, 0x8E, 0xE9, 0x59, 0xFE,
  24779. 0xBB, 0x90, 0xB0, 0x72, 0x29, 0xF6, 0xE4, 0x9D,
  24780. 0x23, 0xC3, 0xA1, 0x90, 0x29, 0x70, 0x42, 0xFB,
  24781. 0x43, 0x98, 0x69, 0x55, 0xB6, 0x9C, 0x28, 0xE1,
  24782. 0x01, 0x6F, 0x77, 0xA5, 0x8B, 0x43, 0x15, 0x14,
  24783. 0xD2, 0x1B, 0x88, 0x88, 0x99, 0xC3, 0x60, 0x82,
  24784. 0x76, 0x08, 0x1B, 0x75, 0xF5, 0x68, 0x09, 0x7C,
  24785. 0xDC, 0x17, 0x48, 0xF3, 0x23, 0x07, 0x88, 0x58,
  24786. 0x15, 0xF3, 0xAE, 0xC9, 0x65, 0x18, 0x19, 0xAA,
  24787. 0x68, 0x73, 0xD1, 0xA4, 0xEB, 0x83, 0xB1, 0x95,
  24788. 0x38, 0x43, 0xB9, 0x34, 0x22, 0x51, 0x94, 0x83,
  24789. 0xFE, 0xF0, 0x05, 0x9D, 0x36, 0xBB, 0x2D, 0xB1,
  24790. 0xF3, 0xD4, 0x68, 0xFB, 0x06, 0x8C, 0x86, 0xE8,
  24791. 0x97, 0x37, 0x33, 0xC3, 0x98, 0xEA, 0xF0, 0x0E,
  24792. 0x17, 0x02, 0xC6, 0x73, 0x4A, 0xD8, 0xEB, 0x3B,
  24793. 0x62, 0x01, 0x30, 0xD6, 0xC2, 0xB8, 0xC9, 0x04,
  24794. 0xA3, 0xBB, 0x93, 0x07, 0xBE, 0x51, 0x03, 0xF8,
  24795. 0xD8, 0x14, 0x50, 0x5F, 0xB6, 0xA6, 0x0A, 0xF7,
  24796. 0x93, 0x7E, 0xA6, 0xCA, 0xA1, 0x17, 0x31, 0x5E,
  24797. 0x84, 0xCC, 0x91, 0x21, 0xAE, 0x56, 0xFB, 0xF3,
  24798. 0x9E, 0x67, 0xAD, 0xBD, 0x83, 0xAD, 0x2D, 0x3E,
  24799. 0x3B, 0xB8, 0x08, 0x43, 0x64, 0x52, 0x06, 0xBD,
  24800. 0xD9, 0xF2, 0xF6, 0x29, 0xE3, 0xCC, 0x49, 0xB7
  24801. };
  24802. #endif
  24803. #ifndef WOLFSSL_NO_KYBER768
  24804. static const byte seed_768[KYBER_MAKEKEY_RAND_SZ] = {
  24805. /* d */
  24806. 0xE3, 0x4A, 0x70, 0x1C, 0x4C, 0x87, 0x58, 0x2F,
  24807. 0x42, 0x26, 0x4E, 0xE4, 0x22, 0xD3, 0xC6, 0x84,
  24808. 0xD9, 0x76, 0x11, 0xF2, 0x52, 0x3E, 0xFE, 0x0C,
  24809. 0x99, 0x8A, 0xF0, 0x50, 0x56, 0xD6, 0x93, 0xDC,
  24810. /* z */
  24811. 0xA8, 0x57, 0x68, 0xF3, 0x48, 0x6B, 0xD3, 0x2A,
  24812. 0x01, 0xBF, 0x9A, 0x8F, 0x21, 0xEA, 0x93, 0x8E,
  24813. 0x64, 0x8E, 0xAE, 0x4E, 0x54, 0x48, 0xC3, 0x4C,
  24814. 0x3E, 0xB8, 0x88, 0x20, 0xB1, 0x59, 0xEE, 0xDD
  24815. };
  24816. static const byte ek_768[KYBER768_PUBLIC_KEY_SIZE] = {
  24817. 0x6D, 0x14, 0xA0, 0x71, 0xF7, 0xCC, 0x45, 0x25,
  24818. 0x58, 0xD5, 0xE7, 0x1A, 0x7B, 0x08, 0x70, 0x62,
  24819. 0xEC, 0xB1, 0x38, 0x68, 0x44, 0x58, 0x82, 0x46,
  24820. 0x12, 0x64, 0x02, 0xB1, 0xFA, 0x16, 0x37, 0x73,
  24821. 0x3C, 0xD5, 0xF6, 0x0C, 0xC8, 0x4B, 0xCB, 0x64,
  24822. 0x6A, 0x78, 0x92, 0x61, 0x4D, 0x7C, 0x51, 0xB1,
  24823. 0xC7, 0xF1, 0xA2, 0x79, 0x91, 0x32, 0xF1, 0x34,
  24824. 0x27, 0xDC, 0x48, 0x21, 0x58, 0xDA, 0x25, 0x44,
  24825. 0x70, 0xA5, 0x9E, 0x00, 0xA4, 0xE4, 0x96, 0x86,
  24826. 0xFD, 0xC0, 0x77, 0x55, 0x93, 0x67, 0x27, 0x0C,
  24827. 0x21, 0x53, 0xF1, 0x10, 0x07, 0x59, 0x2C, 0x9C,
  24828. 0x43, 0x10, 0xCF, 0x8A, 0x12, 0xC6, 0xA8, 0x71,
  24829. 0x3B, 0xD6, 0xBB, 0x51, 0xF3, 0x12, 0x4F, 0x98,
  24830. 0x9B, 0xA0, 0xD5, 0x40, 0x73, 0xCC, 0x24, 0x2E,
  24831. 0x09, 0x68, 0x78, 0x0B, 0x87, 0x5A, 0x86, 0x9E,
  24832. 0xFB, 0x85, 0x15, 0x86, 0xB9, 0xA8, 0x68, 0xA3,
  24833. 0x84, 0xB9, 0xE6, 0x82, 0x1B, 0x20, 0x1B, 0x93,
  24834. 0x2C, 0x45, 0x53, 0x69, 0xA7, 0x39, 0xEC, 0x22,
  24835. 0x56, 0x9C, 0x97, 0x7C, 0x21, 0x2B, 0x38, 0x18,
  24836. 0x71, 0x81, 0x36, 0x56, 0xAF, 0x5B, 0x56, 0x7E,
  24837. 0xF8, 0x93, 0xB5, 0x84, 0x62, 0x4C, 0x86, 0x3A,
  24838. 0x25, 0x90, 0x00, 0xF1, 0x7B, 0x25, 0x4B, 0x98,
  24839. 0xB1, 0x85, 0x09, 0x7C, 0x50, 0xEB, 0xB6, 0x8B,
  24840. 0x24, 0x43, 0x42, 0xE0, 0x5D, 0x4D, 0xE5, 0x20,
  24841. 0x12, 0x5B, 0x8E, 0x10, 0x33, 0xB1, 0x43, 0x60,
  24842. 0x93, 0xAC, 0xE7, 0xCE, 0x8E, 0x71, 0xB4, 0x58,
  24843. 0xD5, 0x25, 0x67, 0x33, 0x63, 0x04, 0x5A, 0x3B,
  24844. 0x3E, 0xEA, 0x94, 0x55, 0x42, 0x8A, 0x39, 0x87,
  24845. 0x05, 0xA4, 0x23, 0x27, 0xAD, 0xB3, 0x77, 0x4B,
  24846. 0x70, 0x57, 0xF4, 0x2B, 0x01, 0x7E, 0xC0, 0x73,
  24847. 0x9A, 0x98, 0x3F, 0x19, 0xE8, 0x21, 0x4D, 0x09,
  24848. 0x19, 0x5F, 0xA2, 0x4D, 0x2D, 0x57, 0x1D, 0xB7,
  24849. 0x3C, 0x19, 0xA6, 0xF8, 0x46, 0x0E, 0x50, 0x83,
  24850. 0x0D, 0x41, 0x5F, 0x62, 0x7B, 0x88, 0xE9, 0x4A,
  24851. 0x7B, 0x15, 0x37, 0x91, 0xA0, 0xC0, 0xC7, 0xE9,
  24852. 0x48, 0x4C, 0x74, 0xD5, 0x3C, 0x71, 0x48, 0x89,
  24853. 0xF0, 0xE3, 0x21, 0xB6, 0x66, 0x0A, 0x53, 0x2A,
  24854. 0x5B, 0xC0, 0xE5, 0x57, 0xFB, 0xCA, 0x35, 0xE2,
  24855. 0x9B, 0xC6, 0x11, 0x20, 0x0E, 0xD3, 0xC6, 0x33,
  24856. 0x07, 0x7A, 0x4D, 0x87, 0x3C, 0x5C, 0xC6, 0x70,
  24857. 0x06, 0xB7, 0x53, 0xBF, 0x6D, 0x6B, 0x7A, 0xF6,
  24858. 0xCA, 0x40, 0x2A, 0xB6, 0x18, 0x23, 0x6C, 0x0A,
  24859. 0xFF, 0xBC, 0x80, 0x1F, 0x82, 0x22, 0xFB, 0xC3,
  24860. 0x6C, 0xE0, 0x98, 0x4E, 0x2B, 0x18, 0xC9, 0x44,
  24861. 0xBB, 0xCB, 0xEF, 0x03, 0xB1, 0xE1, 0x36, 0x1C,
  24862. 0x1F, 0x44, 0xB0, 0xD7, 0x34, 0xAF, 0xB1, 0x56,
  24863. 0x6C, 0xFF, 0x87, 0x44, 0xDA, 0x8B, 0x99, 0x43,
  24864. 0xD6, 0xB4, 0x5A, 0x3C, 0x09, 0x03, 0x07, 0x02,
  24865. 0xCA, 0x20, 0x1F, 0xFE, 0x20, 0xCB, 0x7E, 0xC5,
  24866. 0xB0, 0xD4, 0x14, 0x9E, 0xE2, 0xC2, 0x8E, 0x8B,
  24867. 0x23, 0x37, 0x4F, 0x47, 0x1B, 0x57, 0x15, 0x0D,
  24868. 0x0E, 0xC9, 0x33, 0x62, 0x61, 0xA2, 0xD5, 0xCB,
  24869. 0x84, 0xA3, 0xAC, 0xAC, 0xC4, 0x28, 0x94, 0x73,
  24870. 0xA4, 0xC0, 0xAB, 0xC6, 0x17, 0xC9, 0xAB, 0xC1,
  24871. 0x78, 0x73, 0x44, 0x34, 0xC8, 0x2E, 0x16, 0x85,
  24872. 0x58, 0x8A, 0x5C, 0x2E, 0xA2, 0x67, 0x8F, 0x6B,
  24873. 0x3C, 0x22, 0x28, 0x73, 0x31, 0x30, 0xC4, 0x66,
  24874. 0xE5, 0xB8, 0x6E, 0xF4, 0x91, 0x15, 0x3E, 0x48,
  24875. 0x66, 0x22, 0x47, 0xB8, 0x75, 0xD2, 0x01, 0x02,
  24876. 0x0B, 0x56, 0x6B, 0x81, 0xB6, 0x4D, 0x83, 0x9A,
  24877. 0xB4, 0x63, 0x3B, 0xAA, 0x8A, 0xCE, 0x20, 0x2B,
  24878. 0xAA, 0xB4, 0x49, 0x62, 0x97, 0xF9, 0x80, 0x7A,
  24879. 0xDB, 0xBB, 0x1E, 0x33, 0x2C, 0x6F, 0x80, 0x22,
  24880. 0xB2, 0xA1, 0x8C, 0xFD, 0xD4, 0xA8, 0x25, 0x30,
  24881. 0xB6, 0xD3, 0xF0, 0x07, 0xC3, 0x35, 0x38, 0x98,
  24882. 0xD9, 0x66, 0xCC, 0x2C, 0x21, 0xCB, 0x42, 0x44,
  24883. 0xBD, 0x00, 0x44, 0x3F, 0x20, 0x98, 0x70, 0xAC,
  24884. 0xC4, 0x2B, 0xC3, 0x30, 0x68, 0xC7, 0x24, 0xEC,
  24885. 0x17, 0x22, 0x36, 0x19, 0xC1, 0x09, 0x3C, 0xCA,
  24886. 0x6A, 0xEB, 0x29, 0x50, 0x06, 0x64, 0xD1, 0x22,
  24887. 0x50, 0x36, 0xB4, 0xB8, 0x10, 0x91, 0x90, 0x69,
  24888. 0x69, 0x48, 0x1F, 0x1C, 0x72, 0x3C, 0x14, 0x0B,
  24889. 0x9D, 0x6C, 0x16, 0x8F, 0x5B, 0x64, 0xBE, 0xA6,
  24890. 0x9C, 0x5F, 0xD6, 0x38, 0x5D, 0xF7, 0x36, 0x4B,
  24891. 0x87, 0x23, 0xBC, 0xC8, 0x5E, 0x03, 0x8C, 0x7E,
  24892. 0x46, 0x4A, 0x90, 0x0D, 0x68, 0xA2, 0x12, 0x78,
  24893. 0x18, 0x99, 0x42, 0x17, 0xAE, 0xC8, 0xBD, 0xB3,
  24894. 0x9A, 0x97, 0x0A, 0x99, 0x63, 0xDE, 0x93, 0x68,
  24895. 0x8E, 0x2A, 0xC8, 0x2A, 0xBC, 0xC2, 0x2F, 0xB9,
  24896. 0x27, 0x7B, 0xA2, 0x20, 0x09, 0xE8, 0x78, 0x38,
  24897. 0x1A, 0x38, 0x16, 0x39, 0x01, 0xC7, 0xD4, 0xC8,
  24898. 0x50, 0x19, 0x53, 0x8D, 0x35, 0xCA, 0xAE, 0x9C,
  24899. 0x41, 0xAF, 0x8C, 0x92, 0x9E, 0xE2, 0x0B, 0xB0,
  24900. 0x8C, 0xA6, 0x19, 0xE7, 0x2C, 0x2F, 0x22, 0x62,
  24901. 0xC1, 0xC9, 0x93, 0x85, 0x72, 0x55, 0x1A, 0xC0,
  24902. 0x2D, 0xC9, 0x26, 0x8F, 0xBC, 0xC3, 0x5D, 0x79,
  24903. 0x01, 0x1C, 0x3C, 0x09, 0x0A, 0xD4, 0x0A, 0x4F,
  24904. 0x11, 0x1C, 0x9B, 0xE5, 0x5C, 0x42, 0x7E, 0xB7,
  24905. 0x96, 0xC1, 0x93, 0x2D, 0x86, 0x73, 0x57, 0x9A,
  24906. 0xF1, 0xB4, 0xC6, 0x38, 0xB0, 0x94, 0x44, 0x89,
  24907. 0x01, 0x2A, 0x25, 0x59, 0xA3, 0xB0, 0x24, 0x81,
  24908. 0xB0, 0x1A, 0xC3, 0x0B, 0xA8, 0x96, 0x0F, 0x80,
  24909. 0xC0, 0xC2, 0xB3, 0x94, 0x7D, 0x36, 0xA1, 0x2C,
  24910. 0x08, 0x04, 0x98, 0xBE, 0xE4, 0x48, 0x71, 0x6C,
  24911. 0x97, 0x34, 0x16, 0xC8, 0x24, 0x28, 0x04, 0xA3,
  24912. 0xDA, 0x09, 0x9E, 0xE1, 0x37, 0xB0, 0xBA, 0x90,
  24913. 0xFE, 0x4A, 0x5C, 0x6A, 0x89, 0x20, 0x02, 0x76,
  24914. 0xA0, 0xCF, 0xB6, 0x43, 0xEC, 0x2C, 0x56, 0xA2,
  24915. 0xD7, 0x08, 0xD7, 0xB4, 0x37, 0x3E, 0x44, 0xC1,
  24916. 0x50, 0x2A, 0x76, 0x3A, 0x60, 0x05, 0x86, 0xE6,
  24917. 0xCD, 0xA6, 0x27, 0x38, 0x97, 0xD4, 0x44, 0x48,
  24918. 0x28, 0x7D, 0xC2, 0xE6, 0x02, 0xDC, 0x39, 0x20,
  24919. 0x0B, 0xF6, 0x16, 0x62, 0x36, 0x55, 0x9F, 0xD1,
  24920. 0x2A, 0x60, 0x89, 0x2A, 0xEB, 0x15, 0x3D, 0xD6,
  24921. 0x51, 0xBB, 0x46, 0x99, 0x10, 0xB4, 0xB3, 0x46,
  24922. 0x69, 0xF9, 0x1D, 0xA8, 0x65, 0x4D, 0x1E, 0xB7,
  24923. 0x2E, 0xB6, 0xE0, 0x28, 0x00, 0xB3, 0xB0, 0xA7,
  24924. 0xD0, 0xA4, 0x8C, 0x83, 0x68, 0x54, 0xD3, 0xA8,
  24925. 0x3E, 0x65, 0x56, 0x9C, 0xB7, 0x23, 0x0B, 0xB4,
  24926. 0x4F, 0x3F, 0x14, 0x3A, 0x6D, 0xEC, 0x5F, 0x2C,
  24927. 0x39, 0xAB, 0x90, 0xF2, 0x74, 0xF2, 0x08, 0x8B,
  24928. 0xD3, 0xD6, 0xA6, 0xFC, 0xA0, 0x07, 0x02, 0x73,
  24929. 0xBE, 0xDC, 0x84, 0x77, 0x7F, 0xB5, 0x2E, 0x3C,
  24930. 0x55, 0x8B, 0x0A, 0xE0, 0x61, 0x83, 0xD5, 0xA4,
  24931. 0x8D, 0x45, 0x2F, 0x68, 0xE1, 0x52, 0x07, 0xF8,
  24932. 0x61, 0x62, 0x7A, 0xCA, 0x14, 0x27, 0x96, 0x30,
  24933. 0xF8, 0x2E, 0xC3, 0xA0, 0xCA, 0x07, 0x86, 0x33,
  24934. 0xB6, 0x00, 0xAF, 0xA7, 0x97, 0x43, 0xA6, 0x00,
  24935. 0x21, 0x5B, 0xE5, 0x63, 0x74, 0x58, 0xCE, 0x2C,
  24936. 0xE8, 0xAF, 0xF5, 0xA0, 0x8E, 0xB5, 0x01, 0x7B,
  24937. 0x2C, 0x76, 0x65, 0x77, 0x47, 0x9F, 0x8D, 0xC6,
  24938. 0xBF, 0x9F, 0x5C, 0xC7, 0x50, 0x89, 0x93, 0x21,
  24939. 0x61, 0xB9, 0x6C, 0xEA, 0x40, 0x66, 0x20, 0xAE,
  24940. 0xDB, 0x63, 0x04, 0x07, 0xF7, 0x68, 0x7E, 0xBB,
  24941. 0xB4, 0x81, 0x4C, 0x79, 0x81, 0x63, 0x7A, 0x48,
  24942. 0xA9, 0x0D, 0xE6, 0x80, 0x31, 0xE0, 0x62, 0xA7,
  24943. 0xAF, 0x76, 0x12, 0xB4, 0xF5, 0xC7, 0xA6, 0xDA,
  24944. 0x86, 0xBD, 0x13, 0x65, 0x29, 0xE6, 0x42, 0x95,
  24945. 0xA5, 0x61, 0x3E, 0xA7, 0x3B, 0xD3, 0xD4, 0x44,
  24946. 0x8C, 0xB8, 0x1F, 0x24, 0x31, 0x35, 0xC0, 0xA6,
  24947. 0x60, 0xBE, 0xB9, 0xC1, 0x7E, 0x65, 0x1D, 0xEF,
  24948. 0x46, 0x9A, 0x7D, 0x90, 0xA1, 0x5D, 0x34, 0x81,
  24949. 0x09, 0x0B, 0xCB, 0xF2, 0x27, 0x01, 0x23, 0x28,
  24950. 0x94, 0x1F, 0xA4, 0x6F, 0x39, 0xC5, 0x00, 0x6A,
  24951. 0xD9, 0x3D, 0x45, 0x8A, 0xA6, 0xAD, 0xD6, 0x55,
  24952. 0x86, 0x2B, 0x41, 0x8C, 0x30, 0x94, 0xF5, 0x51,
  24953. 0x46, 0x0D, 0xF2, 0x15, 0x3A, 0x58, 0x10, 0xA7,
  24954. 0xDA, 0x74, 0xF0, 0x61, 0x4C, 0x25, 0x88, 0xBE,
  24955. 0x49, 0xDC, 0x6F, 0x5E, 0x88, 0x15, 0x46, 0x42,
  24956. 0xBD, 0x1D, 0x37, 0x62, 0x56, 0x33, 0x26, 0x43,
  24957. 0x35, 0x07, 0x15, 0x6A, 0x57, 0xC5, 0x76, 0x94,
  24958. 0xBD, 0xD2, 0x6E, 0x7A, 0x24, 0x6F, 0xEB, 0x72,
  24959. 0x3A, 0xED, 0x67, 0xB0, 0x48, 0x87, 0xC8, 0xE4,
  24960. 0x76, 0xB4, 0x8C, 0xAB, 0x59, 0xE5, 0x36, 0x2F,
  24961. 0x26, 0xA9, 0xEF, 0x50, 0xC2, 0xBC, 0x80, 0xBA,
  24962. 0x14, 0x62, 0x26, 0x21, 0x6F, 0xE6, 0x29, 0x68,
  24963. 0xA6, 0x0D, 0x04, 0xE8, 0xC1, 0x70, 0xD7, 0x41,
  24964. 0xC7, 0xA2, 0xB0, 0xE1, 0xAB, 0xDA, 0xC9, 0x68
  24965. };
  24966. static const byte dk_768[KYBER768_PRIVATE_KEY_SIZE] = {
  24967. 0x98, 0xA1, 0xB2, 0xDA, 0x4A, 0x65, 0xCF, 0xB5,
  24968. 0x84, 0x5E, 0xA7, 0x31, 0x1E, 0x6A, 0x06, 0xDB,
  24969. 0x73, 0x1F, 0x15, 0x90, 0xC4, 0x1E, 0xE7, 0x4B,
  24970. 0xA1, 0x07, 0x82, 0x71, 0x5B, 0x35, 0xA3, 0x10,
  24971. 0x2D, 0xF6, 0x37, 0x87, 0x2B, 0xE6, 0x5B, 0xAB,
  24972. 0x37, 0xA1, 0xDE, 0x25, 0x11, 0xD7, 0x03, 0xC7,
  24973. 0x02, 0x47, 0xB3, 0x5E, 0xF2, 0x74, 0x35, 0x48,
  24974. 0x50, 0x24, 0xD9, 0x3F, 0xD9, 0xE7, 0x7C, 0x43,
  24975. 0x80, 0x4F, 0x37, 0x17, 0x49, 0xBA, 0x00, 0xB2,
  24976. 0x0A, 0x8C, 0x5C, 0x58, 0x8B, 0xC9, 0xAB, 0xE0,
  24977. 0x68, 0xAE, 0xAA, 0xA9, 0x38, 0x51, 0x7E, 0xBF,
  24978. 0xE5, 0x3B, 0x6B, 0x66, 0x32, 0x82, 0x90, 0x3D,
  24979. 0xCD, 0x18, 0x97, 0x36, 0xD7, 0x29, 0x68, 0x16,
  24980. 0xC7, 0x33, 0xA1, 0xC7, 0x7C, 0x63, 0x75, 0xE5,
  24981. 0x39, 0x7C, 0x0F, 0x18, 0x9B, 0xBF, 0xE4, 0x76,
  24982. 0x43, 0xA6, 0x1F, 0x58, 0xF8, 0xA3, 0xC6, 0x91,
  24983. 0x1B, 0xE4, 0x61, 0x1A, 0x8C, 0x7B, 0xC0, 0x50,
  24984. 0x02, 0x11, 0x63, 0xD0, 0xA4, 0x04, 0xDC, 0x14,
  24985. 0x06, 0x57, 0x48, 0xFF, 0x29, 0xBE, 0x60, 0xD2,
  24986. 0xB9, 0xFD, 0xCC, 0x8F, 0xFD, 0x98, 0xC5, 0x87,
  24987. 0xF3, 0x8C, 0x67, 0x11, 0x57, 0x86, 0x46, 0x4B,
  24988. 0xDB, 0x34, 0x2B, 0x17, 0xE8, 0x97, 0xD6, 0x46,
  24989. 0x17, 0xCB, 0xFB, 0x11, 0x79, 0x73, 0xA5, 0x45,
  24990. 0x89, 0x77, 0xA7, 0xD7, 0x61, 0x7A, 0x1B, 0x4D,
  24991. 0x83, 0xBA, 0x03, 0xC6, 0x11, 0x13, 0x8A, 0x46,
  24992. 0x73, 0xB1, 0xEB, 0x34, 0xB0, 0x78, 0x03, 0x3F,
  24993. 0x97, 0xCF, 0xFE, 0x80, 0xC1, 0x46, 0xA2, 0x69,
  24994. 0x43, 0xF8, 0x42, 0xB9, 0x76, 0x32, 0x7B, 0xF1,
  24995. 0xCB, 0xC6, 0x01, 0x19, 0x52, 0x5B, 0xB9, 0xA3,
  24996. 0xC0, 0x34, 0x93, 0x34, 0x90, 0x00, 0xDD, 0x8F,
  24997. 0x51, 0xBA, 0x21, 0xA2, 0xE9, 0x23, 0x61, 0x76,
  24998. 0x23, 0x24, 0x60, 0x0E, 0x0C, 0x13, 0xAA, 0xA6,
  24999. 0xCB, 0x69, 0xBF, 0xB2, 0x42, 0x76, 0x48, 0x3F,
  25000. 0x6B, 0x02, 0x42, 0x12, 0x59, 0xB7, 0x58, 0x52,
  25001. 0x63, 0xC1, 0xA0, 0x28, 0xD6, 0x82, 0xC5, 0x08,
  25002. 0xBB, 0xC2, 0x80, 0x1A, 0x56, 0xE9, 0x8B, 0x8F,
  25003. 0x62, 0x0B, 0x04, 0x83, 0xD7, 0x9B, 0x5A, 0xD8,
  25004. 0x58, 0x5A, 0xC0, 0xA4, 0x75, 0xBA, 0xC7, 0x78,
  25005. 0x65, 0x19, 0x41, 0x96, 0x33, 0x87, 0x91, 0xB7,
  25006. 0x98, 0x5A, 0x05, 0xD1, 0x09, 0x39, 0x5C, 0xCA,
  25007. 0x89, 0x32, 0x72, 0x2A, 0x91, 0x95, 0x0D, 0x37,
  25008. 0xE1, 0x2B, 0x89, 0x14, 0x20, 0xA5, 0x2B, 0x62,
  25009. 0xCB, 0xFA, 0x81, 0x5D, 0xF6, 0x17, 0x4C, 0xE0,
  25010. 0x0E, 0x68, 0xBC, 0xA7, 0x5D, 0x48, 0x38, 0xCA,
  25011. 0x28, 0x0F, 0x71, 0x3C, 0x7E, 0x69, 0x24, 0xAF,
  25012. 0xD9, 0x5B, 0xAA, 0x0D, 0x01, 0xAD, 0xA6, 0x37,
  25013. 0xB1, 0x58, 0x34, 0x70, 0x34, 0xC0, 0xAB, 0x1A,
  25014. 0x71, 0x83, 0x33, 0x1A, 0x82, 0x0A, 0xCB, 0xCB,
  25015. 0x83, 0x19, 0x3A, 0x1A, 0x94, 0xC8, 0xF7, 0xE3,
  25016. 0x84, 0xAE, 0xD0, 0xC3, 0x5E, 0xD3, 0xCB, 0x33,
  25017. 0x97, 0xBB, 0x63, 0x80, 0x86, 0xE7, 0xA3, 0x5A,
  25018. 0x64, 0x08, 0xA3, 0xA4, 0xB9, 0x0C, 0xE9, 0x53,
  25019. 0x70, 0x7C, 0x19, 0xBC, 0x46, 0xC3, 0xB2, 0xDA,
  25020. 0x3B, 0x2E, 0xE3, 0x23, 0x19, 0xC5, 0x6B, 0x92,
  25021. 0x80, 0x32, 0xB5, 0xED, 0x12, 0x56, 0xD0, 0x75,
  25022. 0x3D, 0x34, 0x14, 0x23, 0xE9, 0xDB, 0x13, 0x9D,
  25023. 0xE7, 0x71, 0x4F, 0xF0, 0x75, 0xCA, 0xF5, 0x8F,
  25024. 0xD9, 0xF5, 0x7D, 0x1A, 0x54, 0x01, 0x9B, 0x59,
  25025. 0x26, 0x40, 0x68, 0x30, 0xDA, 0xE2, 0x9A, 0x87,
  25026. 0x53, 0x02, 0xA8, 0x12, 0x56, 0xF4, 0xD6, 0xCF,
  25027. 0x5E, 0x74, 0x03, 0x4E, 0xA6, 0x14, 0xBF, 0x70,
  25028. 0xC2, 0x76, 0x4B, 0x20, 0xC9, 0x58, 0x9C, 0xDB,
  25029. 0x5C, 0x25, 0x76, 0x1A, 0x04, 0xE5, 0x82, 0x92,
  25030. 0x90, 0x7C, 0x57, 0x8A, 0x94, 0xA3, 0x58, 0x36,
  25031. 0xBE, 0xE3, 0x11, 0x2D, 0xC2, 0xC3, 0xAE, 0x21,
  25032. 0x92, 0xC9, 0xDE, 0xAA, 0x30, 0x4B, 0x29, 0xC7,
  25033. 0xFE, 0xA1, 0xBD, 0xF4, 0x7B, 0x3B, 0x6B, 0xCB,
  25034. 0xA2, 0xC0, 0xE5, 0x5C, 0x9C, 0xDB, 0x6D, 0xE7,
  25035. 0x14, 0x9E, 0x9C, 0xB1, 0x79, 0x17, 0x71, 0x8F,
  25036. 0x12, 0xC8, 0x03, 0x2D, 0xE1, 0xAD, 0xE0, 0x64,
  25037. 0x8D, 0x40, 0x55, 0x19, 0xC7, 0x07, 0x19, 0xBE,
  25038. 0xCC, 0x70, 0x18, 0x45, 0xCF, 0x9F, 0x4B, 0x91,
  25039. 0x2F, 0xE7, 0x19, 0x83, 0xCA, 0x34, 0xF9, 0x01,
  25040. 0x8C, 0x7C, 0xA7, 0xBB, 0x2F, 0x6C, 0x5D, 0x7F,
  25041. 0x8C, 0x5B, 0x29, 0x73, 0x59, 0xEC, 0x75, 0x20,
  25042. 0x9C, 0x25, 0x43, 0xFF, 0x11, 0xC4, 0x24, 0x49,
  25043. 0x77, 0xC5, 0x96, 0x95, 0x24, 0xEC, 0x45, 0x4D,
  25044. 0x44, 0xC3, 0x23, 0xFC, 0xCA, 0x94, 0xAC, 0xAC,
  25045. 0x27, 0x3A, 0x0E, 0xC4, 0x9B, 0x4A, 0x8A, 0x58,
  25046. 0x5B, 0xCE, 0x7A, 0x5B, 0x30, 0x5C, 0x04, 0xC3,
  25047. 0x50, 0x64, 0x22, 0x58, 0x03, 0x57, 0x01, 0x6A,
  25048. 0x85, 0x0C, 0x3F, 0x7E, 0xE1, 0x72, 0x05, 0xA7,
  25049. 0x7B, 0x29, 0x1C, 0x77, 0x31, 0xC9, 0x83, 0x6C,
  25050. 0x02, 0xAE, 0xE5, 0x40, 0x6F, 0x63, 0xC6, 0xA0,
  25051. 0x7A, 0x21, 0x43, 0x82, 0xAA, 0x15, 0x33, 0x6C,
  25052. 0x05, 0xD1, 0x04, 0x55, 0x88, 0x10, 0x76, 0x45,
  25053. 0xEA, 0x7D, 0xE6, 0x87, 0x0F, 0xC0, 0xE5, 0x5E,
  25054. 0x15, 0x40, 0x97, 0x43, 0x01, 0xC4, 0x2E, 0xC1,
  25055. 0x41, 0x05, 0x51, 0x86, 0x80, 0xF6, 0x88, 0xAB,
  25056. 0xE4, 0xCE, 0x45, 0x37, 0x38, 0xFE, 0x47, 0x1B,
  25057. 0x87, 0xFC, 0x31, 0xF5, 0xC6, 0x8A, 0x39, 0xE6,
  25058. 0x8A, 0xF5, 0x1B, 0x02, 0x40, 0xB9, 0x0E, 0x03,
  25059. 0x64, 0xB0, 0x4B, 0xAC, 0x43, 0xD6, 0xFB, 0x68,
  25060. 0xAB, 0x65, 0xAE, 0x02, 0x8B, 0x62, 0xBD, 0x68,
  25061. 0x3B, 0x7D, 0x28, 0xAD, 0x38, 0x80, 0x6B, 0xEE,
  25062. 0x72, 0x5B, 0x5B, 0x24, 0x16, 0xA8, 0xD7, 0x9C,
  25063. 0x16, 0xEC, 0x2A, 0x99, 0xEA, 0x4A, 0x8D, 0x92,
  25064. 0xA2, 0xF5, 0x05, 0x2E, 0x67, 0xF9, 0x73, 0x52,
  25065. 0x28, 0x97, 0x61, 0xC5, 0xC3, 0x9F, 0xC5, 0xC7,
  25066. 0x42, 0xE9, 0xC0, 0xA7, 0x40, 0xCA, 0x59, 0xFC,
  25067. 0x01, 0x82, 0xF7, 0x09, 0xD0, 0x1B, 0x51, 0x87,
  25068. 0xF0, 0x00, 0x63, 0xDA, 0xAB, 0x39, 0x75, 0x96,
  25069. 0xEE, 0xA4, 0xA3, 0x1B, 0xDB, 0xCB, 0xD4, 0xC1,
  25070. 0xBB, 0x0C, 0x55, 0xBE, 0x7C, 0x68, 0x50, 0xFD,
  25071. 0xA9, 0x32, 0x6B, 0x35, 0x3E, 0x28, 0x8C, 0x50,
  25072. 0x13, 0x22, 0x6C, 0x3C, 0x39, 0x23, 0xA7, 0x91,
  25073. 0x60, 0x9E, 0x80, 0x02, 0xE7, 0x3A, 0x5F, 0x7B,
  25074. 0x6B, 0xB4, 0xA8, 0x77, 0xB1, 0xFD, 0xF5, 0x3B,
  25075. 0xB2, 0xBA, 0xB3, 0xDD, 0x42, 0x4D, 0x31, 0xBB,
  25076. 0xB4, 0x48, 0xE6, 0x09, 0xA6, 0x6B, 0x0E, 0x34,
  25077. 0x3C, 0x28, 0x6E, 0x87, 0x60, 0x31, 0x2B, 0x6D,
  25078. 0x37, 0xAA, 0x52, 0x01, 0xD2, 0x1F, 0x53, 0x50,
  25079. 0x3D, 0x88, 0x38, 0x9A, 0xDC, 0xA2, 0x1C, 0x70,
  25080. 0xFB, 0x6C, 0x0F, 0xC9, 0xC6, 0x9D, 0x66, 0x16,
  25081. 0xC9, 0xEA, 0x37, 0x80, 0xE3, 0x55, 0x65, 0xC0,
  25082. 0xC9, 0x7C, 0x15, 0x17, 0x9C, 0x95, 0x34, 0x3E,
  25083. 0xCC, 0x5E, 0x1C, 0x2A, 0x24, 0xDE, 0x46, 0x99,
  25084. 0xF6, 0x87, 0x5E, 0xA2, 0xFA, 0x2D, 0xD3, 0xE3,
  25085. 0x57, 0xBC, 0x43, 0x91, 0x47, 0x95, 0x20, 0x7E,
  25086. 0x02, 0x6B, 0x85, 0x0A, 0x22, 0x37, 0x95, 0x0C,
  25087. 0x10, 0x8A, 0x51, 0x2F, 0xC8, 0x8C, 0x22, 0x48,
  25088. 0x81, 0x12, 0x60, 0x70, 0x88, 0x18, 0x5F, 0xB0,
  25089. 0xE0, 0x9C, 0x2C, 0x41, 0x97, 0xA8, 0x36, 0x87,
  25090. 0x26, 0x6B, 0xAB, 0x2E, 0x58, 0x3E, 0x21, 0xC4,
  25091. 0x0F, 0x4C, 0xC0, 0x08, 0xFE, 0x65, 0x28, 0x04,
  25092. 0xD8, 0x22, 0x3F, 0x15, 0x20, 0xA9, 0x0B, 0x0D,
  25093. 0x53, 0x85, 0xC7, 0x55, 0x3C, 0xC7, 0x67, 0xC5,
  25094. 0x8D, 0x12, 0x0C, 0xCD, 0x3E, 0xF5, 0xB5, 0xD1,
  25095. 0xA6, 0xCD, 0x7B, 0xC0, 0x0D, 0xFF, 0x13, 0x21,
  25096. 0xB2, 0xF2, 0xC4, 0x32, 0xB6, 0x4E, 0xFB, 0x8A,
  25097. 0x3F, 0x5D, 0x00, 0x64, 0xB3, 0xF3, 0x42, 0x93,
  25098. 0x02, 0x6C, 0x85, 0x1C, 0x2D, 0xED, 0x68, 0xB9,
  25099. 0xDF, 0xF4, 0xA2, 0x8F, 0x6A, 0x8D, 0x22, 0x55,
  25100. 0x35, 0xE0, 0x47, 0x70, 0x84, 0x43, 0x0C, 0xFF,
  25101. 0xDA, 0x0A, 0xC0, 0x55, 0x2F, 0x9A, 0x21, 0x27,
  25102. 0x85, 0xB7, 0x49, 0x91, 0x3A, 0x06, 0xFA, 0x22,
  25103. 0x74, 0xC0, 0xD1, 0x5B, 0xAD, 0x32, 0x54, 0x58,
  25104. 0xD3, 0x23, 0xEF, 0x6B, 0xAE, 0x13, 0xC0, 0x01,
  25105. 0x0D, 0x52, 0x5C, 0x1D, 0x52, 0x69, 0x97, 0x3A,
  25106. 0xC2, 0x9B, 0xDA, 0x7C, 0x98, 0x37, 0x46, 0x91,
  25107. 0x8B, 0xA0, 0xE0, 0x02, 0x58, 0x8E, 0x30, 0x37,
  25108. 0x5D, 0x78, 0x32, 0x9E, 0x6B, 0x8B, 0xA8, 0xC4,
  25109. 0x46, 0x2A, 0x69, 0x2F, 0xB6, 0x08, 0x38, 0x42,
  25110. 0xB8, 0xC8, 0xC9, 0x2C, 0x60, 0xF2, 0x52, 0x72,
  25111. 0x6D, 0x14, 0xA0, 0x71, 0xF7, 0xCC, 0x45, 0x25,
  25112. 0x58, 0xD5, 0xE7, 0x1A, 0x7B, 0x08, 0x70, 0x62,
  25113. 0xEC, 0xB1, 0x38, 0x68, 0x44, 0x58, 0x82, 0x46,
  25114. 0x12, 0x64, 0x02, 0xB1, 0xFA, 0x16, 0x37, 0x73,
  25115. 0x3C, 0xD5, 0xF6, 0x0C, 0xC8, 0x4B, 0xCB, 0x64,
  25116. 0x6A, 0x78, 0x92, 0x61, 0x4D, 0x7C, 0x51, 0xB1,
  25117. 0xC7, 0xF1, 0xA2, 0x79, 0x91, 0x32, 0xF1, 0x34,
  25118. 0x27, 0xDC, 0x48, 0x21, 0x58, 0xDA, 0x25, 0x44,
  25119. 0x70, 0xA5, 0x9E, 0x00, 0xA4, 0xE4, 0x96, 0x86,
  25120. 0xFD, 0xC0, 0x77, 0x55, 0x93, 0x67, 0x27, 0x0C,
  25121. 0x21, 0x53, 0xF1, 0x10, 0x07, 0x59, 0x2C, 0x9C,
  25122. 0x43, 0x10, 0xCF, 0x8A, 0x12, 0xC6, 0xA8, 0x71,
  25123. 0x3B, 0xD6, 0xBB, 0x51, 0xF3, 0x12, 0x4F, 0x98,
  25124. 0x9B, 0xA0, 0xD5, 0x40, 0x73, 0xCC, 0x24, 0x2E,
  25125. 0x09, 0x68, 0x78, 0x0B, 0x87, 0x5A, 0x86, 0x9E,
  25126. 0xFB, 0x85, 0x15, 0x86, 0xB9, 0xA8, 0x68, 0xA3,
  25127. 0x84, 0xB9, 0xE6, 0x82, 0x1B, 0x20, 0x1B, 0x93,
  25128. 0x2C, 0x45, 0x53, 0x69, 0xA7, 0x39, 0xEC, 0x22,
  25129. 0x56, 0x9C, 0x97, 0x7C, 0x21, 0x2B, 0x38, 0x18,
  25130. 0x71, 0x81, 0x36, 0x56, 0xAF, 0x5B, 0x56, 0x7E,
  25131. 0xF8, 0x93, 0xB5, 0x84, 0x62, 0x4C, 0x86, 0x3A,
  25132. 0x25, 0x90, 0x00, 0xF1, 0x7B, 0x25, 0x4B, 0x98,
  25133. 0xB1, 0x85, 0x09, 0x7C, 0x50, 0xEB, 0xB6, 0x8B,
  25134. 0x24, 0x43, 0x42, 0xE0, 0x5D, 0x4D, 0xE5, 0x20,
  25135. 0x12, 0x5B, 0x8E, 0x10, 0x33, 0xB1, 0x43, 0x60,
  25136. 0x93, 0xAC, 0xE7, 0xCE, 0x8E, 0x71, 0xB4, 0x58,
  25137. 0xD5, 0x25, 0x67, 0x33, 0x63, 0x04, 0x5A, 0x3B,
  25138. 0x3E, 0xEA, 0x94, 0x55, 0x42, 0x8A, 0x39, 0x87,
  25139. 0x05, 0xA4, 0x23, 0x27, 0xAD, 0xB3, 0x77, 0x4B,
  25140. 0x70, 0x57, 0xF4, 0x2B, 0x01, 0x7E, 0xC0, 0x73,
  25141. 0x9A, 0x98, 0x3F, 0x19, 0xE8, 0x21, 0x4D, 0x09,
  25142. 0x19, 0x5F, 0xA2, 0x4D, 0x2D, 0x57, 0x1D, 0xB7,
  25143. 0x3C, 0x19, 0xA6, 0xF8, 0x46, 0x0E, 0x50, 0x83,
  25144. 0x0D, 0x41, 0x5F, 0x62, 0x7B, 0x88, 0xE9, 0x4A,
  25145. 0x7B, 0x15, 0x37, 0x91, 0xA0, 0xC0, 0xC7, 0xE9,
  25146. 0x48, 0x4C, 0x74, 0xD5, 0x3C, 0x71, 0x48, 0x89,
  25147. 0xF0, 0xE3, 0x21, 0xB6, 0x66, 0x0A, 0x53, 0x2A,
  25148. 0x5B, 0xC0, 0xE5, 0x57, 0xFB, 0xCA, 0x35, 0xE2,
  25149. 0x9B, 0xC6, 0x11, 0x20, 0x0E, 0xD3, 0xC6, 0x33,
  25150. 0x07, 0x7A, 0x4D, 0x87, 0x3C, 0x5C, 0xC6, 0x70,
  25151. 0x06, 0xB7, 0x53, 0xBF, 0x6D, 0x6B, 0x7A, 0xF6,
  25152. 0xCA, 0x40, 0x2A, 0xB6, 0x18, 0x23, 0x6C, 0x0A,
  25153. 0xFF, 0xBC, 0x80, 0x1F, 0x82, 0x22, 0xFB, 0xC3,
  25154. 0x6C, 0xE0, 0x98, 0x4E, 0x2B, 0x18, 0xC9, 0x44,
  25155. 0xBB, 0xCB, 0xEF, 0x03, 0xB1, 0xE1, 0x36, 0x1C,
  25156. 0x1F, 0x44, 0xB0, 0xD7, 0x34, 0xAF, 0xB1, 0x56,
  25157. 0x6C, 0xFF, 0x87, 0x44, 0xDA, 0x8B, 0x99, 0x43,
  25158. 0xD6, 0xB4, 0x5A, 0x3C, 0x09, 0x03, 0x07, 0x02,
  25159. 0xCA, 0x20, 0x1F, 0xFE, 0x20, 0xCB, 0x7E, 0xC5,
  25160. 0xB0, 0xD4, 0x14, 0x9E, 0xE2, 0xC2, 0x8E, 0x8B,
  25161. 0x23, 0x37, 0x4F, 0x47, 0x1B, 0x57, 0x15, 0x0D,
  25162. 0x0E, 0xC9, 0x33, 0x62, 0x61, 0xA2, 0xD5, 0xCB,
  25163. 0x84, 0xA3, 0xAC, 0xAC, 0xC4, 0x28, 0x94, 0x73,
  25164. 0xA4, 0xC0, 0xAB, 0xC6, 0x17, 0xC9, 0xAB, 0xC1,
  25165. 0x78, 0x73, 0x44, 0x34, 0xC8, 0x2E, 0x16, 0x85,
  25166. 0x58, 0x8A, 0x5C, 0x2E, 0xA2, 0x67, 0x8F, 0x6B,
  25167. 0x3C, 0x22, 0x28, 0x73, 0x31, 0x30, 0xC4, 0x66,
  25168. 0xE5, 0xB8, 0x6E, 0xF4, 0x91, 0x15, 0x3E, 0x48,
  25169. 0x66, 0x22, 0x47, 0xB8, 0x75, 0xD2, 0x01, 0x02,
  25170. 0x0B, 0x56, 0x6B, 0x81, 0xB6, 0x4D, 0x83, 0x9A,
  25171. 0xB4, 0x63, 0x3B, 0xAA, 0x8A, 0xCE, 0x20, 0x2B,
  25172. 0xAA, 0xB4, 0x49, 0x62, 0x97, 0xF9, 0x80, 0x7A,
  25173. 0xDB, 0xBB, 0x1E, 0x33, 0x2C, 0x6F, 0x80, 0x22,
  25174. 0xB2, 0xA1, 0x8C, 0xFD, 0xD4, 0xA8, 0x25, 0x30,
  25175. 0xB6, 0xD3, 0xF0, 0x07, 0xC3, 0x35, 0x38, 0x98,
  25176. 0xD9, 0x66, 0xCC, 0x2C, 0x21, 0xCB, 0x42, 0x44,
  25177. 0xBD, 0x00, 0x44, 0x3F, 0x20, 0x98, 0x70, 0xAC,
  25178. 0xC4, 0x2B, 0xC3, 0x30, 0x68, 0xC7, 0x24, 0xEC,
  25179. 0x17, 0x22, 0x36, 0x19, 0xC1, 0x09, 0x3C, 0xCA,
  25180. 0x6A, 0xEB, 0x29, 0x50, 0x06, 0x64, 0xD1, 0x22,
  25181. 0x50, 0x36, 0xB4, 0xB8, 0x10, 0x91, 0x90, 0x69,
  25182. 0x69, 0x48, 0x1F, 0x1C, 0x72, 0x3C, 0x14, 0x0B,
  25183. 0x9D, 0x6C, 0x16, 0x8F, 0x5B, 0x64, 0xBE, 0xA6,
  25184. 0x9C, 0x5F, 0xD6, 0x38, 0x5D, 0xF7, 0x36, 0x4B,
  25185. 0x87, 0x23, 0xBC, 0xC8, 0x5E, 0x03, 0x8C, 0x7E,
  25186. 0x46, 0x4A, 0x90, 0x0D, 0x68, 0xA2, 0x12, 0x78,
  25187. 0x18, 0x99, 0x42, 0x17, 0xAE, 0xC8, 0xBD, 0xB3,
  25188. 0x9A, 0x97, 0x0A, 0x99, 0x63, 0xDE, 0x93, 0x68,
  25189. 0x8E, 0x2A, 0xC8, 0x2A, 0xBC, 0xC2, 0x2F, 0xB9,
  25190. 0x27, 0x7B, 0xA2, 0x20, 0x09, 0xE8, 0x78, 0x38,
  25191. 0x1A, 0x38, 0x16, 0x39, 0x01, 0xC7, 0xD4, 0xC8,
  25192. 0x50, 0x19, 0x53, 0x8D, 0x35, 0xCA, 0xAE, 0x9C,
  25193. 0x41, 0xAF, 0x8C, 0x92, 0x9E, 0xE2, 0x0B, 0xB0,
  25194. 0x8C, 0xA6, 0x19, 0xE7, 0x2C, 0x2F, 0x22, 0x62,
  25195. 0xC1, 0xC9, 0x93, 0x85, 0x72, 0x55, 0x1A, 0xC0,
  25196. 0x2D, 0xC9, 0x26, 0x8F, 0xBC, 0xC3, 0x5D, 0x79,
  25197. 0x01, 0x1C, 0x3C, 0x09, 0x0A, 0xD4, 0x0A, 0x4F,
  25198. 0x11, 0x1C, 0x9B, 0xE5, 0x5C, 0x42, 0x7E, 0xB7,
  25199. 0x96, 0xC1, 0x93, 0x2D, 0x86, 0x73, 0x57, 0x9A,
  25200. 0xF1, 0xB4, 0xC6, 0x38, 0xB0, 0x94, 0x44, 0x89,
  25201. 0x01, 0x2A, 0x25, 0x59, 0xA3, 0xB0, 0x24, 0x81,
  25202. 0xB0, 0x1A, 0xC3, 0x0B, 0xA8, 0x96, 0x0F, 0x80,
  25203. 0xC0, 0xC2, 0xB3, 0x94, 0x7D, 0x36, 0xA1, 0x2C,
  25204. 0x08, 0x04, 0x98, 0xBE, 0xE4, 0x48, 0x71, 0x6C,
  25205. 0x97, 0x34, 0x16, 0xC8, 0x24, 0x28, 0x04, 0xA3,
  25206. 0xDA, 0x09, 0x9E, 0xE1, 0x37, 0xB0, 0xBA, 0x90,
  25207. 0xFE, 0x4A, 0x5C, 0x6A, 0x89, 0x20, 0x02, 0x76,
  25208. 0xA0, 0xCF, 0xB6, 0x43, 0xEC, 0x2C, 0x56, 0xA2,
  25209. 0xD7, 0x08, 0xD7, 0xB4, 0x37, 0x3E, 0x44, 0xC1,
  25210. 0x50, 0x2A, 0x76, 0x3A, 0x60, 0x05, 0x86, 0xE6,
  25211. 0xCD, 0xA6, 0x27, 0x38, 0x97, 0xD4, 0x44, 0x48,
  25212. 0x28, 0x7D, 0xC2, 0xE6, 0x02, 0xDC, 0x39, 0x20,
  25213. 0x0B, 0xF6, 0x16, 0x62, 0x36, 0x55, 0x9F, 0xD1,
  25214. 0x2A, 0x60, 0x89, 0x2A, 0xEB, 0x15, 0x3D, 0xD6,
  25215. 0x51, 0xBB, 0x46, 0x99, 0x10, 0xB4, 0xB3, 0x46,
  25216. 0x69, 0xF9, 0x1D, 0xA8, 0x65, 0x4D, 0x1E, 0xB7,
  25217. 0x2E, 0xB6, 0xE0, 0x28, 0x00, 0xB3, 0xB0, 0xA7,
  25218. 0xD0, 0xA4, 0x8C, 0x83, 0x68, 0x54, 0xD3, 0xA8,
  25219. 0x3E, 0x65, 0x56, 0x9C, 0xB7, 0x23, 0x0B, 0xB4,
  25220. 0x4F, 0x3F, 0x14, 0x3A, 0x6D, 0xEC, 0x5F, 0x2C,
  25221. 0x39, 0xAB, 0x90, 0xF2, 0x74, 0xF2, 0x08, 0x8B,
  25222. 0xD3, 0xD6, 0xA6, 0xFC, 0xA0, 0x07, 0x02, 0x73,
  25223. 0xBE, 0xDC, 0x84, 0x77, 0x7F, 0xB5, 0x2E, 0x3C,
  25224. 0x55, 0x8B, 0x0A, 0xE0, 0x61, 0x83, 0xD5, 0xA4,
  25225. 0x8D, 0x45, 0x2F, 0x68, 0xE1, 0x52, 0x07, 0xF8,
  25226. 0x61, 0x62, 0x7A, 0xCA, 0x14, 0x27, 0x96, 0x30,
  25227. 0xF8, 0x2E, 0xC3, 0xA0, 0xCA, 0x07, 0x86, 0x33,
  25228. 0xB6, 0x00, 0xAF, 0xA7, 0x97, 0x43, 0xA6, 0x00,
  25229. 0x21, 0x5B, 0xE5, 0x63, 0x74, 0x58, 0xCE, 0x2C,
  25230. 0xE8, 0xAF, 0xF5, 0xA0, 0x8E, 0xB5, 0x01, 0x7B,
  25231. 0x2C, 0x76, 0x65, 0x77, 0x47, 0x9F, 0x8D, 0xC6,
  25232. 0xBF, 0x9F, 0x5C, 0xC7, 0x50, 0x89, 0x93, 0x21,
  25233. 0x61, 0xB9, 0x6C, 0xEA, 0x40, 0x66, 0x20, 0xAE,
  25234. 0xDB, 0x63, 0x04, 0x07, 0xF7, 0x68, 0x7E, 0xBB,
  25235. 0xB4, 0x81, 0x4C, 0x79, 0x81, 0x63, 0x7A, 0x48,
  25236. 0xA9, 0x0D, 0xE6, 0x80, 0x31, 0xE0, 0x62, 0xA7,
  25237. 0xAF, 0x76, 0x12, 0xB4, 0xF5, 0xC7, 0xA6, 0xDA,
  25238. 0x86, 0xBD, 0x13, 0x65, 0x29, 0xE6, 0x42, 0x95,
  25239. 0xA5, 0x61, 0x3E, 0xA7, 0x3B, 0xD3, 0xD4, 0x44,
  25240. 0x8C, 0xB8, 0x1F, 0x24, 0x31, 0x35, 0xC0, 0xA6,
  25241. 0x60, 0xBE, 0xB9, 0xC1, 0x7E, 0x65, 0x1D, 0xEF,
  25242. 0x46, 0x9A, 0x7D, 0x90, 0xA1, 0x5D, 0x34, 0x81,
  25243. 0x09, 0x0B, 0xCB, 0xF2, 0x27, 0x01, 0x23, 0x28,
  25244. 0x94, 0x1F, 0xA4, 0x6F, 0x39, 0xC5, 0x00, 0x6A,
  25245. 0xD9, 0x3D, 0x45, 0x8A, 0xA6, 0xAD, 0xD6, 0x55,
  25246. 0x86, 0x2B, 0x41, 0x8C, 0x30, 0x94, 0xF5, 0x51,
  25247. 0x46, 0x0D, 0xF2, 0x15, 0x3A, 0x58, 0x10, 0xA7,
  25248. 0xDA, 0x74, 0xF0, 0x61, 0x4C, 0x25, 0x88, 0xBE,
  25249. 0x49, 0xDC, 0x6F, 0x5E, 0x88, 0x15, 0x46, 0x42,
  25250. 0xBD, 0x1D, 0x37, 0x62, 0x56, 0x33, 0x26, 0x43,
  25251. 0x35, 0x07, 0x15, 0x6A, 0x57, 0xC5, 0x76, 0x94,
  25252. 0xBD, 0xD2, 0x6E, 0x7A, 0x24, 0x6F, 0xEB, 0x72,
  25253. 0x3A, 0xED, 0x67, 0xB0, 0x48, 0x87, 0xC8, 0xE4,
  25254. 0x76, 0xB4, 0x8C, 0xAB, 0x59, 0xE5, 0x36, 0x2F,
  25255. 0x26, 0xA9, 0xEF, 0x50, 0xC2, 0xBC, 0x80, 0xBA,
  25256. 0x14, 0x62, 0x26, 0x21, 0x6F, 0xE6, 0x29, 0x68,
  25257. 0xA6, 0x0D, 0x04, 0xE8, 0xC1, 0x70, 0xD7, 0x41,
  25258. 0xC7, 0xA2, 0xB0, 0xE1, 0xAB, 0xDA, 0xC9, 0x68,
  25259. 0xE2, 0x90, 0x20, 0x83, 0x9D, 0x05, 0x2F, 0xA3,
  25260. 0x72, 0x58, 0x56, 0x27, 0xF8, 0xB5, 0x9E, 0xE3,
  25261. 0x12, 0xAE, 0x41, 0x4C, 0x97, 0x9D, 0x82, 0x5F,
  25262. 0x06, 0xA6, 0x92, 0x9A, 0x79, 0x62, 0x57, 0x18,
  25263. 0xA8, 0x57, 0x68, 0xF3, 0x48, 0x6B, 0xD3, 0x2A,
  25264. 0x01, 0xBF, 0x9A, 0x8F, 0x21, 0xEA, 0x93, 0x8E,
  25265. 0x64, 0x8E, 0xAE, 0x4E, 0x54, 0x48, 0xC3, 0x4C,
  25266. 0x3E, 0xB8, 0x88, 0x20, 0xB1, 0x59, 0xEE, 0xDD
  25267. };
  25268. #endif
  25269. #ifndef WOLFSSL_NO_KYBER1024
  25270. static const byte seed_1024[KYBER_MAKEKEY_RAND_SZ] = {
  25271. /* d */
  25272. 0x49, 0xAC, 0x8B, 0x99, 0xBB, 0x1E, 0x6A, 0x8E,
  25273. 0xA8, 0x18, 0x26, 0x1F, 0x8B, 0xE6, 0x8B, 0xDE,
  25274. 0xAA, 0x52, 0x89, 0x7E, 0x7E, 0xC6, 0xC4, 0x0B,
  25275. 0x53, 0x0B, 0xC7, 0x60, 0xAB, 0x77, 0xDC, 0xE3,
  25276. /* z */
  25277. 0x99, 0xE3, 0x24, 0x68, 0x84, 0x18, 0x1F, 0x8E,
  25278. 0x1D, 0xD4, 0x4E, 0x0C, 0x76, 0x29, 0x09, 0x33,
  25279. 0x30, 0x22, 0x1F, 0xD6, 0x7D, 0x9B, 0x7D, 0x6E,
  25280. 0x15, 0x10, 0xB2, 0xDB, 0xAD, 0x87, 0x62, 0xF7
  25281. };
  25282. static const byte ek_1024[KYBER1024_PUBLIC_KEY_SIZE] = {
  25283. 0xA0, 0x41, 0x84, 0xD4, 0xBC, 0x7B, 0x53, 0x2A,
  25284. 0x0F, 0x70, 0xA5, 0x4D, 0x77, 0x57, 0xCD, 0xE6,
  25285. 0x17, 0x5A, 0x68, 0x43, 0xB8, 0x61, 0xCB, 0x2B,
  25286. 0xC4, 0x83, 0x0C, 0x00, 0x12, 0x55, 0x4C, 0xFC,
  25287. 0x5D, 0x2C, 0x8A, 0x20, 0x27, 0xAA, 0x3C, 0xD9,
  25288. 0x67, 0x13, 0x0E, 0x9B, 0x96, 0x24, 0x1B, 0x11,
  25289. 0xC4, 0x32, 0x0C, 0x76, 0x49, 0xCC, 0x23, 0xA7,
  25290. 0x1B, 0xAF, 0xE6, 0x91, 0xAF, 0xC0, 0x8E, 0x68,
  25291. 0x0B, 0xCE, 0xF4, 0x29, 0x07, 0x00, 0x07, 0x18,
  25292. 0xE4, 0xEA, 0xCE, 0x8D, 0xA2, 0x82, 0x14, 0x19,
  25293. 0x7B, 0xE1, 0xC2, 0x69, 0xDA, 0x9C, 0xB5, 0x41,
  25294. 0xE1, 0xA3, 0xCE, 0x97, 0xCF, 0xAD, 0xF9, 0xC6,
  25295. 0x05, 0x87, 0x80, 0xFE, 0x67, 0x93, 0xDB, 0xFA,
  25296. 0x82, 0x18, 0xA2, 0x76, 0x0B, 0x80, 0x2B, 0x8D,
  25297. 0xA2, 0xAA, 0x27, 0x1A, 0x38, 0x77, 0x25, 0x23,
  25298. 0xA7, 0x67, 0x36, 0xA7, 0xA3, 0x1B, 0x9D, 0x30,
  25299. 0x37, 0xAD, 0x21, 0xCE, 0xBB, 0x11, 0xA4, 0x72,
  25300. 0xB8, 0x79, 0x2E, 0xB1, 0x75, 0x58, 0xB9, 0x40,
  25301. 0xE7, 0x08, 0x83, 0xF2, 0x64, 0x59, 0x2C, 0x68,
  25302. 0x9B, 0x24, 0x0B, 0xB4, 0x3D, 0x54, 0x08, 0xBF,
  25303. 0x44, 0x64, 0x32, 0xF4, 0x12, 0xF4, 0xB9, 0xA5,
  25304. 0xF6, 0x86, 0x5C, 0xC2, 0x52, 0xA4, 0x3C, 0xF4,
  25305. 0x0A, 0x32, 0x03, 0x91, 0x55, 0x55, 0x91, 0xD6,
  25306. 0x75, 0x61, 0xFD, 0xD0, 0x53, 0x53, 0xAB, 0x6B,
  25307. 0x01, 0x9B, 0x3A, 0x08, 0xA7, 0x33, 0x53, 0xD5,
  25308. 0x1B, 0x61, 0x13, 0xAB, 0x2F, 0xA5, 0x1D, 0x97,
  25309. 0x56, 0x48, 0xEE, 0x25, 0x4A, 0xF8, 0x9A, 0x23,
  25310. 0x05, 0x04, 0xA2, 0x36, 0xA4, 0x65, 0x82, 0x57,
  25311. 0x74, 0x0B, 0xDC, 0xBB, 0xE1, 0x70, 0x8A, 0xB0,
  25312. 0x22, 0xC3, 0xC5, 0x88, 0xA4, 0x10, 0xDB, 0x3B,
  25313. 0x9C, 0x30, 0x8A, 0x06, 0x27, 0x5B, 0xDF, 0x5B,
  25314. 0x48, 0x59, 0xD3, 0xA2, 0x61, 0x7A, 0x29, 0x5E,
  25315. 0x1A, 0x22, 0xF9, 0x01, 0x98, 0xBA, 0xD0, 0x16,
  25316. 0x6F, 0x4A, 0x94, 0x34, 0x17, 0xC5, 0xB8, 0x31,
  25317. 0x73, 0x6C, 0xB2, 0xC8, 0x58, 0x0A, 0xBF, 0xDE,
  25318. 0x57, 0x14, 0xB5, 0x86, 0xAB, 0xEE, 0xC0, 0xA1,
  25319. 0x75, 0xA0, 0x8B, 0xC7, 0x10, 0xC7, 0xA2, 0x89,
  25320. 0x5D, 0xE9, 0x3A, 0xC4, 0x38, 0x06, 0x1B, 0xF7,
  25321. 0x76, 0x5D, 0x0D, 0x21, 0xCD, 0x41, 0x81, 0x67,
  25322. 0xCA, 0xF8, 0x9D, 0x1E, 0xFC, 0x34, 0x48, 0xBC,
  25323. 0xBB, 0x96, 0xD6, 0x9B, 0x3E, 0x01, 0x0C, 0x82,
  25324. 0xD1, 0x5C, 0xAB, 0x6C, 0xAC, 0xC6, 0x79, 0x9D,
  25325. 0x36, 0x39, 0x66, 0x9A, 0x5B, 0x21, 0xA6, 0x33,
  25326. 0xC8, 0x65, 0xF8, 0x59, 0x3B, 0x5B, 0x7B, 0xC8,
  25327. 0x00, 0x26, 0x2B, 0xB8, 0x37, 0xA9, 0x24, 0xA6,
  25328. 0xC5, 0x44, 0x0E, 0x4F, 0xC7, 0x3B, 0x41, 0xB2,
  25329. 0x30, 0x92, 0xC3, 0x91, 0x2F, 0x4C, 0x6B, 0xEB,
  25330. 0xB4, 0xC7, 0xB4, 0xC6, 0x29, 0x08, 0xB0, 0x37,
  25331. 0x75, 0x66, 0x6C, 0x22, 0x22, 0x0D, 0xF9, 0xC8,
  25332. 0x88, 0x23, 0xE3, 0x44, 0xC7, 0x30, 0x83, 0x32,
  25333. 0x34, 0x5C, 0x8B, 0x79, 0x5D, 0x34, 0xE8, 0xC0,
  25334. 0x51, 0xF2, 0x1F, 0x5A, 0x21, 0xC2, 0x14, 0xB6,
  25335. 0x98, 0x41, 0x35, 0x87, 0x09, 0xB1, 0xC3, 0x05,
  25336. 0xB3, 0x2C, 0xC2, 0xC3, 0x80, 0x6A, 0xE9, 0xCC,
  25337. 0xD3, 0x81, 0x9F, 0xFF, 0x45, 0x07, 0xFE, 0x52,
  25338. 0x0F, 0xBF, 0xC2, 0x71, 0x99, 0xBC, 0x23, 0xBE,
  25339. 0x6B, 0x9B, 0x2D, 0x2A, 0xC1, 0x71, 0x75, 0x79,
  25340. 0xAC, 0x76, 0x92, 0x79, 0xE2, 0xA7, 0xAA, 0xC6,
  25341. 0x8A, 0x37, 0x1A, 0x47, 0xBA, 0x3A, 0x7D, 0xBE,
  25342. 0x01, 0x6F, 0x14, 0xE1, 0xA7, 0x27, 0x33, 0x36,
  25343. 0x63, 0xC4, 0xA5, 0xCD, 0x1A, 0x0F, 0x88, 0x36,
  25344. 0xCF, 0x7B, 0x5C, 0x49, 0xAC, 0x51, 0x48, 0x5C,
  25345. 0xA6, 0x03, 0x45, 0xC9, 0x90, 0xE0, 0x68, 0x88,
  25346. 0x72, 0x00, 0x03, 0x73, 0x13, 0x22, 0xC5, 0xB8,
  25347. 0xCD, 0x5E, 0x69, 0x07, 0xFD, 0xA1, 0x15, 0x7F,
  25348. 0x46, 0x8F, 0xD3, 0xFC, 0x20, 0xFA, 0x81, 0x75,
  25349. 0xEE, 0xC9, 0x5C, 0x29, 0x1A, 0x26, 0x2B, 0xA8,
  25350. 0xC5, 0xBE, 0x99, 0x08, 0x72, 0x41, 0x89, 0x30,
  25351. 0x85, 0x23, 0x39, 0xD8, 0x8A, 0x19, 0xB3, 0x7F,
  25352. 0xEF, 0xA3, 0xCF, 0xE8, 0x21, 0x75, 0xC2, 0x24,
  25353. 0x40, 0x7C, 0xA4, 0x14, 0xBA, 0xEB, 0x37, 0x92,
  25354. 0x3B, 0x4D, 0x2D, 0x83, 0x13, 0x4A, 0xE1, 0x54,
  25355. 0xE4, 0x90, 0xA9, 0xB4, 0x5A, 0x05, 0x63, 0xB0,
  25356. 0x6C, 0x95, 0x3C, 0x33, 0x01, 0x45, 0x0A, 0x21,
  25357. 0x76, 0xA0, 0x7C, 0x61, 0x4A, 0x74, 0xE3, 0x47,
  25358. 0x8E, 0x48, 0x50, 0x9F, 0x9A, 0x60, 0xAE, 0x94,
  25359. 0x5A, 0x8E, 0xBC, 0x78, 0x15, 0x12, 0x1D, 0x90,
  25360. 0xA3, 0xB0, 0xE0, 0x70, 0x91, 0xA0, 0x96, 0xCF,
  25361. 0x02, 0xC5, 0x7B, 0x25, 0xBC, 0xA5, 0x81, 0x26,
  25362. 0xAD, 0x0C, 0x62, 0x9C, 0xE1, 0x66, 0xA7, 0xED,
  25363. 0xB4, 0xB3, 0x32, 0x21, 0xA0, 0xD3, 0xF7, 0x2B,
  25364. 0x85, 0xD5, 0x62, 0xEC, 0x69, 0x8B, 0x7D, 0x0A,
  25365. 0x91, 0x3D, 0x73, 0x80, 0x6F, 0x1C, 0x5C, 0x87,
  25366. 0xB3, 0x8E, 0xC0, 0x03, 0xCB, 0x30, 0x3A, 0x3D,
  25367. 0xC5, 0x1B, 0x4B, 0x35, 0x35, 0x6A, 0x67, 0x82,
  25368. 0x6D, 0x6E, 0xDA, 0xA8, 0xFE, 0xB9, 0x3B, 0x98,
  25369. 0x49, 0x3B, 0x2D, 0x1C, 0x11, 0xB6, 0x76, 0xA6,
  25370. 0xAD, 0x95, 0x06, 0xA1, 0xAA, 0xAE, 0x13, 0xA8,
  25371. 0x24, 0xC7, 0xC0, 0x8D, 0x1C, 0x6C, 0x2C, 0x4D,
  25372. 0xBA, 0x96, 0x42, 0xC7, 0x6E, 0xA7, 0xF6, 0xC8,
  25373. 0x26, 0x4B, 0x64, 0xA2, 0x3C, 0xCC, 0xA9, 0xA7,
  25374. 0x46, 0x35, 0xFC, 0xBF, 0x03, 0xE0, 0x0F, 0x1B,
  25375. 0x57, 0x22, 0xB2, 0x14, 0x37, 0x67, 0x90, 0x79,
  25376. 0x3B, 0x2C, 0x4F, 0x0A, 0x13, 0xB5, 0xC4, 0x07,
  25377. 0x60, 0xB4, 0x21, 0x8E, 0x1D, 0x25, 0x94, 0xDC,
  25378. 0xB3, 0x0A, 0x70, 0xD9, 0xC1, 0x78, 0x2A, 0x5D,
  25379. 0xD3, 0x05, 0x76, 0xFA, 0x41, 0x44, 0xBF, 0xC8,
  25380. 0x41, 0x6E, 0xDA, 0x81, 0x18, 0xFC, 0x64, 0x72,
  25381. 0xF5, 0x6A, 0x97, 0x95, 0x86, 0xF3, 0x3B, 0xB0,
  25382. 0x70, 0xFB, 0x0F, 0x1B, 0x0B, 0x10, 0xBC, 0x48,
  25383. 0x97, 0xEB, 0xE0, 0x1B, 0xCA, 0x38, 0x93, 0xD4,
  25384. 0xE1, 0x6A, 0xDB, 0x25, 0x09, 0x3A, 0x74, 0x17,
  25385. 0xD0, 0x70, 0x8C, 0x83, 0xA2, 0x63, 0x22, 0xE2,
  25386. 0x2E, 0x63, 0x30, 0x09, 0x1E, 0x30, 0x15, 0x2B,
  25387. 0xF8, 0x23, 0x59, 0x7C, 0x04, 0xCC, 0xF4, 0xCF,
  25388. 0xC7, 0x33, 0x15, 0x78, 0xF4, 0x3A, 0x27, 0x26,
  25389. 0xCC, 0xB4, 0x28, 0x28, 0x9A, 0x90, 0xC8, 0x63,
  25390. 0x25, 0x9D, 0xD1, 0x80, 0xC5, 0xFF, 0x14, 0x2B,
  25391. 0xEF, 0x41, 0xC7, 0x71, 0x70, 0x94, 0xBE, 0x07,
  25392. 0x85, 0x6D, 0xA2, 0xB1, 0x40, 0xFA, 0x67, 0x71,
  25393. 0x09, 0x67, 0x35, 0x6A, 0xA4, 0x7D, 0xFB, 0xC8,
  25394. 0xD2, 0x55, 0xB4, 0x72, 0x2A, 0xB8, 0x6D, 0x43,
  25395. 0x9B, 0x7E, 0x0A, 0x60, 0x90, 0x25, 0x1D, 0x2D,
  25396. 0x4C, 0x1E, 0xD5, 0xF2, 0x0B, 0xBE, 0x68, 0x07,
  25397. 0xBF, 0x65, 0xA9, 0x0B, 0x7C, 0xB2, 0xEC, 0x01,
  25398. 0x02, 0xAF, 0x02, 0x80, 0x9D, 0xC9, 0xAC, 0x7D,
  25399. 0x0A, 0x3A, 0xBC, 0x69, 0xC1, 0x83, 0x65, 0xBC,
  25400. 0xFF, 0x59, 0x18, 0x5F, 0x33, 0x99, 0x68, 0x87,
  25401. 0x74, 0x61, 0x85, 0x90, 0x6C, 0x01, 0x91, 0xAE,
  25402. 0xD4, 0x40, 0x7E, 0x13, 0x94, 0x46, 0x45, 0x9B,
  25403. 0xE2, 0x9C, 0x68, 0x22, 0x71, 0x76, 0x44, 0x35,
  25404. 0x3D, 0x24, 0xAB, 0x63, 0x39, 0x15, 0x6A, 0x9C,
  25405. 0x42, 0x49, 0x09, 0xF0, 0xA9, 0x02, 0x5B, 0xB7,
  25406. 0x47, 0x20, 0x77, 0x9B, 0xE4, 0x3F, 0x16, 0xD8,
  25407. 0x1C, 0x8C, 0xC6, 0x66, 0xE9, 0x97, 0x10, 0xD8,
  25408. 0xC6, 0x8B, 0xB5, 0xCC, 0x4E, 0x12, 0xF3, 0x14,
  25409. 0xE9, 0x25, 0xA5, 0x51, 0xF0, 0x9C, 0xC5, 0x90,
  25410. 0x03, 0xA1, 0xF8, 0x81, 0x03, 0xC2, 0x54, 0xBB,
  25411. 0x97, 0x8D, 0x75, 0xF3, 0x94, 0xD3, 0x54, 0x0E,
  25412. 0x31, 0xE7, 0x71, 0xCD, 0xA3, 0x6E, 0x39, 0xEC,
  25413. 0x54, 0xA6, 0x2B, 0x58, 0x32, 0x66, 0x4D, 0x82,
  25414. 0x1A, 0x72, 0xF1, 0xE6, 0xAF, 0xBB, 0xA2, 0x7F,
  25415. 0x84, 0x29, 0x5B, 0x26, 0x94, 0xC4, 0x98, 0x49,
  25416. 0x8E, 0x81, 0x2B, 0xC8, 0xE9, 0x37, 0x8F, 0xE5,
  25417. 0x41, 0xCE, 0xC5, 0x89, 0x1B, 0x25, 0x06, 0x29,
  25418. 0x01, 0xCB, 0x72, 0x12, 0xE3, 0xCD, 0xC4, 0x61,
  25419. 0x79, 0xEC, 0x5B, 0xCE, 0xC1, 0x0B, 0xC0, 0xB9,
  25420. 0x31, 0x1D, 0xE0, 0x50, 0x74, 0x29, 0x06, 0x87,
  25421. 0xFD, 0x6A, 0x53, 0x92, 0x67, 0x16, 0x54, 0x28,
  25422. 0x4C, 0xD9, 0xC8, 0xCC, 0x3E, 0xBA, 0x80, 0xEB,
  25423. 0x3B, 0x66, 0x2E, 0xB5, 0x3E, 0xB7, 0x51, 0x16,
  25424. 0x70, 0x4A, 0x1F, 0xEB, 0x5C, 0x2D, 0x05, 0x63,
  25425. 0x38, 0x53, 0x28, 0x68, 0xDD, 0xF2, 0x4E, 0xB8,
  25426. 0x99, 0x2A, 0xB8, 0x56, 0x5D, 0x9E, 0x49, 0x0C,
  25427. 0xAD, 0xF1, 0x48, 0x04, 0x36, 0x0D, 0xAA, 0x90,
  25428. 0x71, 0x8E, 0xAB, 0x61, 0x6B, 0xAB, 0x07, 0x65,
  25429. 0xD3, 0x39, 0x87, 0xB4, 0x7E, 0xFB, 0x65, 0x99,
  25430. 0xC5, 0x56, 0x32, 0x35, 0xE6, 0x1E, 0x4B, 0xE6,
  25431. 0x70, 0xE9, 0x79, 0x55, 0xAB, 0x29, 0x2D, 0x97,
  25432. 0x32, 0xCB, 0x89, 0x30, 0x94, 0x8A, 0xC8, 0x2D,
  25433. 0xF2, 0x30, 0xAC, 0x72, 0x29, 0x7A, 0x23, 0x67,
  25434. 0x9D, 0x6B, 0x94, 0xC1, 0x7F, 0x13, 0x59, 0x48,
  25435. 0x32, 0x54, 0xFE, 0xDC, 0x2F, 0x05, 0x81, 0x9F,
  25436. 0x0D, 0x06, 0x9A, 0x44, 0x3B, 0x78, 0xE3, 0xFC,
  25437. 0x6C, 0x3E, 0xF4, 0x71, 0x4B, 0x05, 0xA3, 0xFC,
  25438. 0xA8, 0x1C, 0xBB, 0xA6, 0x02, 0x42, 0xA7, 0x06,
  25439. 0x0C, 0xD8, 0x85, 0xD8, 0xF3, 0x99, 0x81, 0xBB,
  25440. 0x18, 0x09, 0x2B, 0x23, 0xDA, 0xA5, 0x9F, 0xD9,
  25441. 0x57, 0x83, 0x88, 0x68, 0x8A, 0x09, 0xBB, 0xA0,
  25442. 0x79, 0xBC, 0x80, 0x9A, 0x54, 0x84, 0x3A, 0x60,
  25443. 0x38, 0x5E, 0x23, 0x10, 0xBB, 0xCB, 0xCC, 0x02,
  25444. 0x13, 0xCE, 0x3D, 0xFA, 0xAB, 0x33, 0xB4, 0x7F,
  25445. 0x9D, 0x63, 0x05, 0xBC, 0x95, 0xC6, 0x10, 0x78,
  25446. 0x13, 0xC5, 0x85, 0xC4, 0xB6, 0x57, 0xBF, 0x30,
  25447. 0x54, 0x28, 0x33, 0xB1, 0x49, 0x49, 0xF5, 0x73,
  25448. 0xC0, 0x61, 0x2A, 0xD5, 0x24, 0xBA, 0xAE, 0x69,
  25449. 0x59, 0x0C, 0x12, 0x77, 0xB8, 0x6C, 0x28, 0x65,
  25450. 0x71, 0xBF, 0x66, 0xB3, 0xCF, 0xF4, 0x6A, 0x38,
  25451. 0x58, 0xC0, 0x99, 0x06, 0xA7, 0x94, 0xDF, 0x4A,
  25452. 0x06, 0xE9, 0xD4, 0xB0, 0xA2, 0xE4, 0x3F, 0x10,
  25453. 0xF7, 0x2A, 0x6C, 0x6C, 0x47, 0xE5, 0x64, 0x6E,
  25454. 0x2C, 0x79, 0x9B, 0x71, 0xC3, 0x3E, 0xD2, 0xF0,
  25455. 0x1E, 0xEB, 0x45, 0x93, 0x8E, 0xB7, 0xA4, 0xE2,
  25456. 0xE2, 0x90, 0x8C, 0x53, 0x55, 0x8A, 0x54, 0x0D,
  25457. 0x35, 0x03, 0x69, 0xFA, 0x18, 0x9C, 0x61, 0x69,
  25458. 0x43, 0xF7, 0x98, 0x1D, 0x76, 0x18, 0xCF, 0x02,
  25459. 0xA5, 0xB0, 0xA2, 0xBC, 0xC4, 0x22, 0xE8, 0x57,
  25460. 0xD1, 0xA4, 0x78, 0x71, 0x25, 0x3D, 0x08, 0x29,
  25461. 0x3C, 0x1C, 0x17, 0x9B, 0xCD, 0xC0, 0x43, 0x70,
  25462. 0x69, 0x10, 0x74, 0x18, 0x20, 0x5F, 0xDB, 0x98,
  25463. 0x56, 0x62, 0x3B, 0x8C, 0xA6, 0xB6, 0x94, 0xC9,
  25464. 0x6C, 0x08, 0x4B, 0x17, 0xF1, 0x3B, 0xB6, 0xDF,
  25465. 0x12, 0xB2, 0xCF, 0xBB, 0xC2, 0xB0, 0xE0, 0xC3,
  25466. 0x4B, 0x00, 0xD0, 0xFC, 0xD0, 0xAE, 0xCF, 0xB2,
  25467. 0x79, 0x24, 0xF6, 0x98, 0x4E, 0x74, 0x7B, 0xE2,
  25468. 0xA0, 0x9D, 0x83, 0xA8, 0x66, 0x45, 0x90, 0xA8,
  25469. 0x07, 0x73, 0x31, 0x49, 0x1A, 0x4F, 0x7D, 0x72,
  25470. 0x08, 0x43, 0xF2, 0x3E, 0x65, 0x2C, 0x6F, 0xA8,
  25471. 0x40, 0x30, 0x8D, 0xB4, 0x02, 0x03, 0x37, 0xAA,
  25472. 0xD3, 0x79, 0x67, 0x03, 0x4A, 0x9F, 0xB5, 0x23,
  25473. 0xB6, 0x7C, 0xA7, 0x03, 0x30, 0xF0, 0x2D, 0x9E,
  25474. 0xA2, 0x0C, 0x1E, 0x84, 0xCB, 0x8E, 0x57, 0x57,
  25475. 0xC9, 0xE1, 0x89, 0x6B, 0x60, 0x58, 0x14, 0x41,
  25476. 0xED, 0x61, 0x8A, 0xA5, 0xB2, 0x6D, 0xA5, 0x6C,
  25477. 0x0A, 0x5A, 0x73, 0xC4, 0xDC, 0xFD, 0x75, 0x5E,
  25478. 0x61, 0x0B, 0x4F, 0xC8, 0x1F, 0xF8, 0x4E, 0x21
  25479. };
  25480. static const byte dk_1024[KYBER1024_PRIVATE_KEY_SIZE] = {
  25481. 0x8C, 0x8B, 0x37, 0x22, 0xA8, 0x2E, 0x55, 0x05,
  25482. 0x65, 0x52, 0x16, 0x11, 0xEB, 0xBC, 0x63, 0x07,
  25483. 0x99, 0x44, 0xC9, 0xB1, 0xAB, 0xB3, 0xB0, 0x02,
  25484. 0x0F, 0xF1, 0x2F, 0x63, 0x18, 0x91, 0xA9, 0xC4,
  25485. 0x68, 0xD3, 0xA6, 0x7B, 0xF6, 0x27, 0x12, 0x80,
  25486. 0xDA, 0x58, 0xD0, 0x3C, 0xB0, 0x42, 0xB3, 0xA4,
  25487. 0x61, 0x44, 0x16, 0x37, 0xF9, 0x29, 0xC2, 0x73,
  25488. 0x46, 0x9A, 0xD1, 0x53, 0x11, 0xE9, 0x10, 0xDE,
  25489. 0x18, 0xCB, 0x95, 0x37, 0xBA, 0x1B, 0xE4, 0x2E,
  25490. 0x98, 0xBB, 0x59, 0xE4, 0x98, 0xA1, 0x3F, 0xD4,
  25491. 0x40, 0xD0, 0xE6, 0x9E, 0xE8, 0x32, 0xB4, 0x5C,
  25492. 0xD9, 0x5C, 0x38, 0x21, 0x77, 0xD6, 0x70, 0x96,
  25493. 0xA1, 0x8C, 0x07, 0xF1, 0x78, 0x16, 0x63, 0x65,
  25494. 0x1B, 0xDC, 0xAC, 0x90, 0xDE, 0xDA, 0x3D, 0xDD,
  25495. 0x14, 0x34, 0x85, 0x86, 0x41, 0x81, 0xC9, 0x1F,
  25496. 0xA2, 0x08, 0x0F, 0x6D, 0xAB, 0x3F, 0x86, 0x20,
  25497. 0x4C, 0xEB, 0x64, 0xA7, 0xB4, 0x44, 0x68, 0x95,
  25498. 0xC0, 0x39, 0x87, 0xA0, 0x31, 0xCB, 0x4B, 0x6D,
  25499. 0x9E, 0x04, 0x62, 0xFD, 0xA8, 0x29, 0x17, 0x2B,
  25500. 0x6C, 0x01, 0x2C, 0x63, 0x8B, 0x29, 0xB5, 0xCD,
  25501. 0x75, 0xA2, 0xC9, 0x30, 0xA5, 0x59, 0x6A, 0x31,
  25502. 0x81, 0xC3, 0x3A, 0x22, 0xD5, 0x74, 0xD3, 0x02,
  25503. 0x61, 0x19, 0x6B, 0xC3, 0x50, 0x73, 0x8D, 0x4F,
  25504. 0xD9, 0x18, 0x3A, 0x76, 0x33, 0x36, 0x24, 0x3A,
  25505. 0xCE, 0xD9, 0x9B, 0x32, 0x21, 0xC7, 0x1D, 0x88,
  25506. 0x66, 0x89, 0x5C, 0x4E, 0x52, 0xC1, 0x19, 0xBF,
  25507. 0x32, 0x80, 0xDA, 0xF8, 0x0A, 0x95, 0xE1, 0x52,
  25508. 0x09, 0xA7, 0x95, 0xC4, 0x43, 0x5F, 0xBB, 0x35,
  25509. 0x70, 0xFD, 0xB8, 0xAA, 0x9B, 0xF9, 0xAE, 0xFD,
  25510. 0x43, 0xB0, 0x94, 0xB7, 0x81, 0xD5, 0xA8, 0x11,
  25511. 0x36, 0xDA, 0xB8, 0x8B, 0x87, 0x99, 0x69, 0x65,
  25512. 0x56, 0xFE, 0xC6, 0xAE, 0x14, 0xB0, 0xBB, 0x8B,
  25513. 0xE4, 0x69, 0x5E, 0x9A, 0x12, 0x4C, 0x2A, 0xB8,
  25514. 0xFF, 0x4A, 0xB1, 0x22, 0x9B, 0x8A, 0xAA, 0x8C,
  25515. 0x6F, 0x41, 0xA6, 0x0C, 0x34, 0xC7, 0xB5, 0x61,
  25516. 0x82, 0xC5, 0x5C, 0x2C, 0x68, 0x5E, 0x73, 0x7C,
  25517. 0x6C, 0xA0, 0x0A, 0x23, 0xFB, 0x8A, 0x68, 0xC1,
  25518. 0xCD, 0x61, 0xF3, 0x0D, 0x39, 0x93, 0xA1, 0x65,
  25519. 0x3C, 0x16, 0x75, 0xAC, 0x5F, 0x09, 0x01, 0xA7,
  25520. 0x16, 0x0A, 0x73, 0x96, 0x64, 0x08, 0xB8, 0x87,
  25521. 0x6B, 0x71, 0x53, 0x96, 0xCF, 0xA4, 0x90, 0x3F,
  25522. 0xC6, 0x9D, 0x60, 0x49, 0x1F, 0x81, 0x46, 0x80,
  25523. 0x8C, 0x97, 0xCD, 0x5C, 0x53, 0x3E, 0x71, 0x01,
  25524. 0x79, 0x09, 0xE9, 0x7B, 0x83, 0x5B, 0x86, 0xFF,
  25525. 0x84, 0x7B, 0x42, 0xA6, 0x96, 0x37, 0x54, 0x35,
  25526. 0xE0, 0x06, 0x06, 0x1C, 0xF7, 0xA4, 0x79, 0x46,
  25527. 0x32, 0x72, 0x11, 0x4A, 0x89, 0xEB, 0x3E, 0xAF,
  25528. 0x22, 0x46, 0xF0, 0xF8, 0xC1, 0x04, 0xA1, 0x49,
  25529. 0x86, 0x82, 0x8E, 0x0A, 0xD2, 0x04, 0x20, 0xC9,
  25530. 0xB3, 0x7E, 0xA2, 0x3F, 0x5C, 0x51, 0x49, 0x49,
  25531. 0xE7, 0x7A, 0xD9, 0xE9, 0xAD, 0x12, 0x29, 0x0D,
  25532. 0xD1, 0x21, 0x5E, 0x11, 0xDA, 0x27, 0x44, 0x57,
  25533. 0xAC, 0x86, 0xB1, 0xCE, 0x68, 0x64, 0xB1, 0x22,
  25534. 0x67, 0x7F, 0x37, 0x18, 0xAA, 0x31, 0xB0, 0x25,
  25535. 0x80, 0xE6, 0x43, 0x17, 0x17, 0x8D, 0x38, 0xF2,
  25536. 0x5F, 0x60, 0x9B, 0xC6, 0xC5, 0x5B, 0xC3, 0x74,
  25537. 0xA1, 0xBF, 0x78, 0xEA, 0x8E, 0xCC, 0x21, 0x9B,
  25538. 0x30, 0xB7, 0x4C, 0xBB, 0x32, 0x72, 0xA5, 0x99,
  25539. 0x23, 0x8C, 0x93, 0x98, 0x51, 0x70, 0x04, 0x8F,
  25540. 0x17, 0x67, 0x75, 0xFB, 0x19, 0x96, 0x2A, 0xC3,
  25541. 0xB1, 0x35, 0xAA, 0x59, 0xDB, 0x10, 0x4F, 0x71,
  25542. 0x14, 0xDB, 0xC2, 0xC2, 0xD4, 0x29, 0x49, 0xAD,
  25543. 0xEC, 0xA6, 0xA8, 0x5B, 0x32, 0x3E, 0xE2, 0xB2,
  25544. 0xB2, 0x3A, 0x77, 0xD9, 0xDB, 0x23, 0x59, 0x79,
  25545. 0xA8, 0xE2, 0xD6, 0x7C, 0xF7, 0xD2, 0x13, 0x6B,
  25546. 0xBB, 0xA7, 0x1F, 0x26, 0x95, 0x74, 0xB3, 0x88,
  25547. 0x88, 0xE1, 0x54, 0x13, 0x40, 0xC1, 0x92, 0x84,
  25548. 0x07, 0x4F, 0x9B, 0x7C, 0x8C, 0xF3, 0x7E, 0xB0,
  25549. 0x13, 0x84, 0xE6, 0xE3, 0x82, 0x2E, 0xC4, 0x88,
  25550. 0x2D, 0xFB, 0xBE, 0xC4, 0xE6, 0x09, 0x8E, 0xF2,
  25551. 0xB2, 0xFC, 0x17, 0x7A, 0x1F, 0x0B, 0xCB, 0x65,
  25552. 0xA5, 0x7F, 0xDA, 0xA8, 0x93, 0x15, 0x46, 0x1B,
  25553. 0xEB, 0x78, 0x85, 0xFB, 0x68, 0xB3, 0xCD, 0x09,
  25554. 0x6E, 0xDA, 0x59, 0x6A, 0xC0, 0xE6, 0x1D, 0xD7,
  25555. 0xA9, 0xC5, 0x07, 0xBC, 0x63, 0x45, 0xE0, 0x82,
  25556. 0x7D, 0xFC, 0xC8, 0xA3, 0xAC, 0x2D, 0xCE, 0x51,
  25557. 0xAD, 0x73, 0x1A, 0xA0, 0xEB, 0x93, 0x2A, 0x6D,
  25558. 0x09, 0x83, 0x99, 0x23, 0x47, 0xCB, 0xEB, 0x3C,
  25559. 0xD0, 0xD9, 0xC9, 0x71, 0x97, 0x97, 0xCC, 0x21,
  25560. 0xCF, 0x00, 0x62, 0xB0, 0xAD, 0x94, 0xCA, 0xD7,
  25561. 0x34, 0xC6, 0x3E, 0x6B, 0x5D, 0x85, 0x9C, 0xBE,
  25562. 0x19, 0xF0, 0x36, 0x82, 0x45, 0x35, 0x1B, 0xF4,
  25563. 0x64, 0xD7, 0x50, 0x55, 0x69, 0x79, 0x0D, 0x2B,
  25564. 0xB7, 0x24, 0xD8, 0x65, 0x9A, 0x9F, 0xEB, 0x1C,
  25565. 0x7C, 0x47, 0x3D, 0xC4, 0xD0, 0x61, 0xE2, 0x98,
  25566. 0x63, 0xA2, 0x71, 0x4B, 0xAC, 0x42, 0xAD, 0xCD,
  25567. 0x1A, 0x83, 0x72, 0x77, 0x65, 0x56, 0xF7, 0x92,
  25568. 0x8A, 0x7A, 0x44, 0xE9, 0x4B, 0x6A, 0x25, 0x32,
  25569. 0x2D, 0x03, 0xC0, 0xA1, 0x62, 0x2A, 0x7F, 0xD2,
  25570. 0x61, 0x52, 0x2B, 0x73, 0x58, 0xF0, 0x85, 0xBD,
  25571. 0xFB, 0x60, 0x75, 0x87, 0x62, 0xCB, 0x90, 0x10,
  25572. 0x31, 0x90, 0x1B, 0x5E, 0xEC, 0xF4, 0x92, 0x0C,
  25573. 0x81, 0x02, 0x0A, 0x9B, 0x17, 0x81, 0xBC, 0xB9,
  25574. 0xDD, 0x19, 0xA9, 0xDF, 0xB6, 0x64, 0x58, 0xE7,
  25575. 0x75, 0x7C, 0x52, 0xCE, 0xC7, 0x5B, 0x4B, 0xA7,
  25576. 0x40, 0xA2, 0x40, 0x99, 0xCB, 0x56, 0xBB, 0x60,
  25577. 0xA7, 0x6B, 0x69, 0x01, 0xAA, 0x3E, 0x01, 0x69,
  25578. 0xC9, 0xE8, 0x34, 0x96, 0xD7, 0x3C, 0x4C, 0x99,
  25579. 0x43, 0x5A, 0x28, 0xD6, 0x13, 0xE9, 0x7A, 0x11,
  25580. 0x77, 0xF5, 0x8B, 0x6C, 0xC5, 0x95, 0xD3, 0xB2,
  25581. 0x33, 0x1E, 0x9C, 0xA7, 0xB5, 0x7B, 0x74, 0xDC,
  25582. 0x2C, 0x52, 0x77, 0xD2, 0x6F, 0x2F, 0xE1, 0x92,
  25583. 0x40, 0xA5, 0x5C, 0x35, 0xD6, 0xCF, 0xCA, 0x26,
  25584. 0xC7, 0x3E, 0x9A, 0x2D, 0x7C, 0x98, 0x0D, 0x97,
  25585. 0x96, 0x0A, 0xE1, 0xA0, 0x46, 0x98, 0xC1, 0x6B,
  25586. 0x39, 0x8A, 0x5F, 0x20, 0xC3, 0x5A, 0x09, 0x14,
  25587. 0x14, 0x5C, 0xE1, 0x67, 0x4B, 0x71, 0xAB, 0xC6,
  25588. 0x06, 0x6A, 0x90, 0x9A, 0x3E, 0x4B, 0x91, 0x1E,
  25589. 0x69, 0xD5, 0xA8, 0x49, 0x43, 0x03, 0x61, 0xF7,
  25590. 0x31, 0xB0, 0x72, 0x46, 0xA6, 0x32, 0x9B, 0x52,
  25591. 0x36, 0x19, 0x04, 0x22, 0x50, 0x82, 0xD0, 0xAA,
  25592. 0xC5, 0xB2, 0x1D, 0x6B, 0x34, 0x86, 0x24, 0x81,
  25593. 0xA8, 0x90, 0xC3, 0xC3, 0x60, 0x76, 0x6F, 0x04,
  25594. 0x26, 0x36, 0x03, 0xA6, 0xB7, 0x3E, 0x80, 0x2B,
  25595. 0x1F, 0x70, 0xB2, 0xEB, 0x00, 0x04, 0x68, 0x36,
  25596. 0xB8, 0xF4, 0x93, 0xBF, 0x10, 0xB9, 0x0B, 0x87,
  25597. 0x37, 0xC6, 0xC5, 0x48, 0x44, 0x9B, 0x29, 0x4C,
  25598. 0x47, 0x25, 0x3B, 0xE2, 0x6C, 0xA7, 0x23, 0x36,
  25599. 0xA6, 0x32, 0x06, 0x3A, 0xD3, 0xD0, 0xB4, 0x8C,
  25600. 0x8B, 0x0F, 0x4A, 0x34, 0x44, 0x7E, 0xF1, 0x3B,
  25601. 0x76, 0x40, 0x20, 0xDE, 0x73, 0x9E, 0xB7, 0x9A,
  25602. 0xBA, 0x20, 0xE2, 0xBE, 0x19, 0x51, 0x82, 0x5F,
  25603. 0x29, 0x3B, 0xED, 0xD1, 0x08, 0x9F, 0xCB, 0x0A,
  25604. 0x91, 0xF5, 0x60, 0xC8, 0xE1, 0x7C, 0xDF, 0x52,
  25605. 0x54, 0x1D, 0xC2, 0xB8, 0x1F, 0x97, 0x2A, 0x73,
  25606. 0x75, 0xB2, 0x01, 0xF1, 0x0C, 0x08, 0xD9, 0xB5,
  25607. 0xBC, 0x8B, 0x95, 0x10, 0x00, 0x54, 0xA3, 0xD0,
  25608. 0xAA, 0xFF, 0x89, 0xBD, 0x08, 0xD6, 0xA0, 0xE7,
  25609. 0xF2, 0x11, 0x5A, 0x43, 0x52, 0x31, 0x29, 0x04,
  25610. 0x60, 0xC9, 0xAD, 0x43, 0x5A, 0x3B, 0x3C, 0xF3,
  25611. 0x5E, 0x52, 0x09, 0x1E, 0xDD, 0x18, 0x90, 0x04,
  25612. 0x7B, 0xCC, 0x0A, 0xAB, 0xB1, 0xAC, 0xEB, 0xC7,
  25613. 0x5F, 0x4A, 0x32, 0xBC, 0x14, 0x51, 0xAC, 0xC4,
  25614. 0x96, 0x99, 0x40, 0x78, 0x8E, 0x89, 0x41, 0x21,
  25615. 0x88, 0x94, 0x6C, 0x91, 0x43, 0xC5, 0x04, 0x6B,
  25616. 0xD1, 0xB4, 0x58, 0xDF, 0x61, 0x7C, 0x5D, 0xF5,
  25617. 0x33, 0xB0, 0x52, 0xCD, 0x60, 0x38, 0xB7, 0x75,
  25618. 0x40, 0x34, 0xA2, 0x3C, 0x2F, 0x77, 0x20, 0x13,
  25619. 0x4C, 0x7B, 0x4E, 0xAC, 0xE0, 0x1F, 0xAC, 0x0A,
  25620. 0x28, 0x53, 0xA9, 0x28, 0x58, 0x47, 0xAB, 0xBD,
  25621. 0x06, 0xA3, 0x34, 0x3A, 0x77, 0x8A, 0xC6, 0x06,
  25622. 0x2E, 0x45, 0x8B, 0xC5, 0xE6, 0x1E, 0xCE, 0x1C,
  25623. 0x0D, 0xE0, 0x20, 0x6E, 0x6F, 0xE8, 0xA8, 0x40,
  25624. 0x34, 0xA7, 0xC5, 0xF1, 0xB0, 0x05, 0xFB, 0x0A,
  25625. 0x58, 0x40, 0x51, 0xD3, 0x22, 0x9B, 0x86, 0xC9,
  25626. 0x09, 0xAC, 0x56, 0x47, 0xB3, 0xD7, 0x55, 0x69,
  25627. 0xE0, 0x5A, 0x88, 0x27, 0x9D, 0x80, 0xE5, 0xC3,
  25628. 0x0F, 0x57, 0x4D, 0xC3, 0x27, 0x51, 0x2C, 0x6B,
  25629. 0xBE, 0x81, 0x01, 0x23, 0x9E, 0xC6, 0x28, 0x61,
  25630. 0xF4, 0xBE, 0x67, 0xB0, 0x5B, 0x9C, 0xDA, 0x9C,
  25631. 0x54, 0x5C, 0x13, 0xE7, 0xEB, 0x53, 0xCF, 0xF2,
  25632. 0x60, 0xAD, 0x98, 0x70, 0x19, 0x9C, 0x21, 0xF8,
  25633. 0xC6, 0x3D, 0x64, 0xF0, 0x45, 0x8A, 0x71, 0x41,
  25634. 0x28, 0x50, 0x23, 0xFE, 0xB8, 0x29, 0x29, 0x08,
  25635. 0x72, 0x38, 0x96, 0x44, 0xB0, 0xC3, 0xB7, 0x3A,
  25636. 0xC2, 0xC8, 0xE1, 0x21, 0xA2, 0x9B, 0xB1, 0xC4,
  25637. 0x3C, 0x19, 0xA2, 0x33, 0xD5, 0x6B, 0xED, 0x82,
  25638. 0x74, 0x0E, 0xB0, 0x21, 0xC9, 0x7B, 0x8E, 0xBB,
  25639. 0xA4, 0x0F, 0xF3, 0x28, 0xB5, 0x41, 0x76, 0x0F,
  25640. 0xCC, 0x37, 0x2B, 0x52, 0xD3, 0xBC, 0x4F, 0xCB,
  25641. 0xC0, 0x6F, 0x42, 0x4E, 0xAF, 0x25, 0x38, 0x04,
  25642. 0xD4, 0xCB, 0x46, 0xF4, 0x1F, 0xF2, 0x54, 0xC0,
  25643. 0xC5, 0xBA, 0x48, 0x3B, 0x44, 0xA8, 0x7C, 0x21,
  25644. 0x96, 0x54, 0x55, 0x5E, 0xC7, 0xC1, 0x63, 0xC7,
  25645. 0x9B, 0x9C, 0xB7, 0x60, 0xA2, 0xAD, 0x9B, 0xB7,
  25646. 0x22, 0xB9, 0x3E, 0x0C, 0x28, 0xBD, 0x4B, 0x16,
  25647. 0x85, 0x94, 0x9C, 0x49, 0x6E, 0xAB, 0x1A, 0xFF,
  25648. 0x90, 0x91, 0x9E, 0x37, 0x61, 0xB3, 0x46, 0x83,
  25649. 0x8A, 0xBB, 0x2F, 0x01, 0xA9, 0x1E, 0x55, 0x43,
  25650. 0x75, 0xAF, 0xDA, 0xAA, 0xF3, 0x82, 0x6E, 0x6D,
  25651. 0xB7, 0x9F, 0xE7, 0x35, 0x3A, 0x7A, 0x57, 0x8A,
  25652. 0x7C, 0x05, 0x98, 0xCE, 0x28, 0xB6, 0xD9, 0x91,
  25653. 0x52, 0x14, 0x23, 0x6B, 0xBF, 0xFA, 0x6D, 0x45,
  25654. 0xB6, 0x37, 0x6A, 0x07, 0x92, 0x4A, 0x39, 0xA7,
  25655. 0xBE, 0x81, 0x82, 0x86, 0x71, 0x5C, 0x8A, 0x3C,
  25656. 0x11, 0x0C, 0xD7, 0x6C, 0x02, 0xE0, 0x41, 0x7A,
  25657. 0xF1, 0x38, 0xBD, 0xB9, 0x5C, 0x3C, 0xCA, 0x79,
  25658. 0x8A, 0xC8, 0x09, 0xED, 0x69, 0xCF, 0xB6, 0x72,
  25659. 0xB6, 0xFD, 0xDC, 0x24, 0xD8, 0x9C, 0x06, 0xA6,
  25660. 0x55, 0x88, 0x14, 0xAB, 0x0C, 0x21, 0xC6, 0x2B,
  25661. 0x2F, 0x84, 0xC0, 0xE3, 0xE0, 0x80, 0x3D, 0xB3,
  25662. 0x37, 0xA4, 0xE0, 0xC7, 0x12, 0x7A, 0x6B, 0x4C,
  25663. 0x8C, 0x08, 0xB1, 0xD1, 0xA7, 0x6B, 0xF0, 0x7E,
  25664. 0xB6, 0xE5, 0xB5, 0xBB, 0x47, 0xA1, 0x6C, 0x74,
  25665. 0xBC, 0x54, 0x83, 0x75, 0xFB, 0x29, 0xCD, 0x78,
  25666. 0x9A, 0x5C, 0xFF, 0x91, 0xBD, 0xBD, 0x07, 0x18,
  25667. 0x59, 0xF4, 0x84, 0x6E, 0x35, 0x5B, 0xB0, 0xD2,
  25668. 0x94, 0x84, 0xE2, 0x64, 0xDF, 0xF3, 0x6C, 0x91,
  25669. 0x77, 0xA7, 0xAC, 0xA7, 0x89, 0x08, 0x87, 0x96,
  25670. 0x95, 0xCA, 0x87, 0xF2, 0x54, 0x36, 0xBC, 0x12,
  25671. 0x63, 0x07, 0x24, 0xBB, 0x22, 0xF0, 0xCB, 0x64,
  25672. 0x89, 0x7F, 0xE5, 0xC4, 0x11, 0x95, 0x28, 0x0D,
  25673. 0xA0, 0x41, 0x84, 0xD4, 0xBC, 0x7B, 0x53, 0x2A,
  25674. 0x0F, 0x70, 0xA5, 0x4D, 0x77, 0x57, 0xCD, 0xE6,
  25675. 0x17, 0x5A, 0x68, 0x43, 0xB8, 0x61, 0xCB, 0x2B,
  25676. 0xC4, 0x83, 0x0C, 0x00, 0x12, 0x55, 0x4C, 0xFC,
  25677. 0x5D, 0x2C, 0x8A, 0x20, 0x27, 0xAA, 0x3C, 0xD9,
  25678. 0x67, 0x13, 0x0E, 0x9B, 0x96, 0x24, 0x1B, 0x11,
  25679. 0xC4, 0x32, 0x0C, 0x76, 0x49, 0xCC, 0x23, 0xA7,
  25680. 0x1B, 0xAF, 0xE6, 0x91, 0xAF, 0xC0, 0x8E, 0x68,
  25681. 0x0B, 0xCE, 0xF4, 0x29, 0x07, 0x00, 0x07, 0x18,
  25682. 0xE4, 0xEA, 0xCE, 0x8D, 0xA2, 0x82, 0x14, 0x19,
  25683. 0x7B, 0xE1, 0xC2, 0x69, 0xDA, 0x9C, 0xB5, 0x41,
  25684. 0xE1, 0xA3, 0xCE, 0x97, 0xCF, 0xAD, 0xF9, 0xC6,
  25685. 0x05, 0x87, 0x80, 0xFE, 0x67, 0x93, 0xDB, 0xFA,
  25686. 0x82, 0x18, 0xA2, 0x76, 0x0B, 0x80, 0x2B, 0x8D,
  25687. 0xA2, 0xAA, 0x27, 0x1A, 0x38, 0x77, 0x25, 0x23,
  25688. 0xA7, 0x67, 0x36, 0xA7, 0xA3, 0x1B, 0x9D, 0x30,
  25689. 0x37, 0xAD, 0x21, 0xCE, 0xBB, 0x11, 0xA4, 0x72,
  25690. 0xB8, 0x79, 0x2E, 0xB1, 0x75, 0x58, 0xB9, 0x40,
  25691. 0xE7, 0x08, 0x83, 0xF2, 0x64, 0x59, 0x2C, 0x68,
  25692. 0x9B, 0x24, 0x0B, 0xB4, 0x3D, 0x54, 0x08, 0xBF,
  25693. 0x44, 0x64, 0x32, 0xF4, 0x12, 0xF4, 0xB9, 0xA5,
  25694. 0xF6, 0x86, 0x5C, 0xC2, 0x52, 0xA4, 0x3C, 0xF4,
  25695. 0x0A, 0x32, 0x03, 0x91, 0x55, 0x55, 0x91, 0xD6,
  25696. 0x75, 0x61, 0xFD, 0xD0, 0x53, 0x53, 0xAB, 0x6B,
  25697. 0x01, 0x9B, 0x3A, 0x08, 0xA7, 0x33, 0x53, 0xD5,
  25698. 0x1B, 0x61, 0x13, 0xAB, 0x2F, 0xA5, 0x1D, 0x97,
  25699. 0x56, 0x48, 0xEE, 0x25, 0x4A, 0xF8, 0x9A, 0x23,
  25700. 0x05, 0x04, 0xA2, 0x36, 0xA4, 0x65, 0x82, 0x57,
  25701. 0x74, 0x0B, 0xDC, 0xBB, 0xE1, 0x70, 0x8A, 0xB0,
  25702. 0x22, 0xC3, 0xC5, 0x88, 0xA4, 0x10, 0xDB, 0x3B,
  25703. 0x9C, 0x30, 0x8A, 0x06, 0x27, 0x5B, 0xDF, 0x5B,
  25704. 0x48, 0x59, 0xD3, 0xA2, 0x61, 0x7A, 0x29, 0x5E,
  25705. 0x1A, 0x22, 0xF9, 0x01, 0x98, 0xBA, 0xD0, 0x16,
  25706. 0x6F, 0x4A, 0x94, 0x34, 0x17, 0xC5, 0xB8, 0x31,
  25707. 0x73, 0x6C, 0xB2, 0xC8, 0x58, 0x0A, 0xBF, 0xDE,
  25708. 0x57, 0x14, 0xB5, 0x86, 0xAB, 0xEE, 0xC0, 0xA1,
  25709. 0x75, 0xA0, 0x8B, 0xC7, 0x10, 0xC7, 0xA2, 0x89,
  25710. 0x5D, 0xE9, 0x3A, 0xC4, 0x38, 0x06, 0x1B, 0xF7,
  25711. 0x76, 0x5D, 0x0D, 0x21, 0xCD, 0x41, 0x81, 0x67,
  25712. 0xCA, 0xF8, 0x9D, 0x1E, 0xFC, 0x34, 0x48, 0xBC,
  25713. 0xBB, 0x96, 0xD6, 0x9B, 0x3E, 0x01, 0x0C, 0x82,
  25714. 0xD1, 0x5C, 0xAB, 0x6C, 0xAC, 0xC6, 0x79, 0x9D,
  25715. 0x36, 0x39, 0x66, 0x9A, 0x5B, 0x21, 0xA6, 0x33,
  25716. 0xC8, 0x65, 0xF8, 0x59, 0x3B, 0x5B, 0x7B, 0xC8,
  25717. 0x00, 0x26, 0x2B, 0xB8, 0x37, 0xA9, 0x24, 0xA6,
  25718. 0xC5, 0x44, 0x0E, 0x4F, 0xC7, 0x3B, 0x41, 0xB2,
  25719. 0x30, 0x92, 0xC3, 0x91, 0x2F, 0x4C, 0x6B, 0xEB,
  25720. 0xB4, 0xC7, 0xB4, 0xC6, 0x29, 0x08, 0xB0, 0x37,
  25721. 0x75, 0x66, 0x6C, 0x22, 0x22, 0x0D, 0xF9, 0xC8,
  25722. 0x88, 0x23, 0xE3, 0x44, 0xC7, 0x30, 0x83, 0x32,
  25723. 0x34, 0x5C, 0x8B, 0x79, 0x5D, 0x34, 0xE8, 0xC0,
  25724. 0x51, 0xF2, 0x1F, 0x5A, 0x21, 0xC2, 0x14, 0xB6,
  25725. 0x98, 0x41, 0x35, 0x87, 0x09, 0xB1, 0xC3, 0x05,
  25726. 0xB3, 0x2C, 0xC2, 0xC3, 0x80, 0x6A, 0xE9, 0xCC,
  25727. 0xD3, 0x81, 0x9F, 0xFF, 0x45, 0x07, 0xFE, 0x52,
  25728. 0x0F, 0xBF, 0xC2, 0x71, 0x99, 0xBC, 0x23, 0xBE,
  25729. 0x6B, 0x9B, 0x2D, 0x2A, 0xC1, 0x71, 0x75, 0x79,
  25730. 0xAC, 0x76, 0x92, 0x79, 0xE2, 0xA7, 0xAA, 0xC6,
  25731. 0x8A, 0x37, 0x1A, 0x47, 0xBA, 0x3A, 0x7D, 0xBE,
  25732. 0x01, 0x6F, 0x14, 0xE1, 0xA7, 0x27, 0x33, 0x36,
  25733. 0x63, 0xC4, 0xA5, 0xCD, 0x1A, 0x0F, 0x88, 0x36,
  25734. 0xCF, 0x7B, 0x5C, 0x49, 0xAC, 0x51, 0x48, 0x5C,
  25735. 0xA6, 0x03, 0x45, 0xC9, 0x90, 0xE0, 0x68, 0x88,
  25736. 0x72, 0x00, 0x03, 0x73, 0x13, 0x22, 0xC5, 0xB8,
  25737. 0xCD, 0x5E, 0x69, 0x07, 0xFD, 0xA1, 0x15, 0x7F,
  25738. 0x46, 0x8F, 0xD3, 0xFC, 0x20, 0xFA, 0x81, 0x75,
  25739. 0xEE, 0xC9, 0x5C, 0x29, 0x1A, 0x26, 0x2B, 0xA8,
  25740. 0xC5, 0xBE, 0x99, 0x08, 0x72, 0x41, 0x89, 0x30,
  25741. 0x85, 0x23, 0x39, 0xD8, 0x8A, 0x19, 0xB3, 0x7F,
  25742. 0xEF, 0xA3, 0xCF, 0xE8, 0x21, 0x75, 0xC2, 0x24,
  25743. 0x40, 0x7C, 0xA4, 0x14, 0xBA, 0xEB, 0x37, 0x92,
  25744. 0x3B, 0x4D, 0x2D, 0x83, 0x13, 0x4A, 0xE1, 0x54,
  25745. 0xE4, 0x90, 0xA9, 0xB4, 0x5A, 0x05, 0x63, 0xB0,
  25746. 0x6C, 0x95, 0x3C, 0x33, 0x01, 0x45, 0x0A, 0x21,
  25747. 0x76, 0xA0, 0x7C, 0x61, 0x4A, 0x74, 0xE3, 0x47,
  25748. 0x8E, 0x48, 0x50, 0x9F, 0x9A, 0x60, 0xAE, 0x94,
  25749. 0x5A, 0x8E, 0xBC, 0x78, 0x15, 0x12, 0x1D, 0x90,
  25750. 0xA3, 0xB0, 0xE0, 0x70, 0x91, 0xA0, 0x96, 0xCF,
  25751. 0x02, 0xC5, 0x7B, 0x25, 0xBC, 0xA5, 0x81, 0x26,
  25752. 0xAD, 0x0C, 0x62, 0x9C, 0xE1, 0x66, 0xA7, 0xED,
  25753. 0xB4, 0xB3, 0x32, 0x21, 0xA0, 0xD3, 0xF7, 0x2B,
  25754. 0x85, 0xD5, 0x62, 0xEC, 0x69, 0x8B, 0x7D, 0x0A,
  25755. 0x91, 0x3D, 0x73, 0x80, 0x6F, 0x1C, 0x5C, 0x87,
  25756. 0xB3, 0x8E, 0xC0, 0x03, 0xCB, 0x30, 0x3A, 0x3D,
  25757. 0xC5, 0x1B, 0x4B, 0x35, 0x35, 0x6A, 0x67, 0x82,
  25758. 0x6D, 0x6E, 0xDA, 0xA8, 0xFE, 0xB9, 0x3B, 0x98,
  25759. 0x49, 0x3B, 0x2D, 0x1C, 0x11, 0xB6, 0x76, 0xA6,
  25760. 0xAD, 0x95, 0x06, 0xA1, 0xAA, 0xAE, 0x13, 0xA8,
  25761. 0x24, 0xC7, 0xC0, 0x8D, 0x1C, 0x6C, 0x2C, 0x4D,
  25762. 0xBA, 0x96, 0x42, 0xC7, 0x6E, 0xA7, 0xF6, 0xC8,
  25763. 0x26, 0x4B, 0x64, 0xA2, 0x3C, 0xCC, 0xA9, 0xA7,
  25764. 0x46, 0x35, 0xFC, 0xBF, 0x03, 0xE0, 0x0F, 0x1B,
  25765. 0x57, 0x22, 0xB2, 0x14, 0x37, 0x67, 0x90, 0x79,
  25766. 0x3B, 0x2C, 0x4F, 0x0A, 0x13, 0xB5, 0xC4, 0x07,
  25767. 0x60, 0xB4, 0x21, 0x8E, 0x1D, 0x25, 0x94, 0xDC,
  25768. 0xB3, 0x0A, 0x70, 0xD9, 0xC1, 0x78, 0x2A, 0x5D,
  25769. 0xD3, 0x05, 0x76, 0xFA, 0x41, 0x44, 0xBF, 0xC8,
  25770. 0x41, 0x6E, 0xDA, 0x81, 0x18, 0xFC, 0x64, 0x72,
  25771. 0xF5, 0x6A, 0x97, 0x95, 0x86, 0xF3, 0x3B, 0xB0,
  25772. 0x70, 0xFB, 0x0F, 0x1B, 0x0B, 0x10, 0xBC, 0x48,
  25773. 0x97, 0xEB, 0xE0, 0x1B, 0xCA, 0x38, 0x93, 0xD4,
  25774. 0xE1, 0x6A, 0xDB, 0x25, 0x09, 0x3A, 0x74, 0x17,
  25775. 0xD0, 0x70, 0x8C, 0x83, 0xA2, 0x63, 0x22, 0xE2,
  25776. 0x2E, 0x63, 0x30, 0x09, 0x1E, 0x30, 0x15, 0x2B,
  25777. 0xF8, 0x23, 0x59, 0x7C, 0x04, 0xCC, 0xF4, 0xCF,
  25778. 0xC7, 0x33, 0x15, 0x78, 0xF4, 0x3A, 0x27, 0x26,
  25779. 0xCC, 0xB4, 0x28, 0x28, 0x9A, 0x90, 0xC8, 0x63,
  25780. 0x25, 0x9D, 0xD1, 0x80, 0xC5, 0xFF, 0x14, 0x2B,
  25781. 0xEF, 0x41, 0xC7, 0x71, 0x70, 0x94, 0xBE, 0x07,
  25782. 0x85, 0x6D, 0xA2, 0xB1, 0x40, 0xFA, 0x67, 0x71,
  25783. 0x09, 0x67, 0x35, 0x6A, 0xA4, 0x7D, 0xFB, 0xC8,
  25784. 0xD2, 0x55, 0xB4, 0x72, 0x2A, 0xB8, 0x6D, 0x43,
  25785. 0x9B, 0x7E, 0x0A, 0x60, 0x90, 0x25, 0x1D, 0x2D,
  25786. 0x4C, 0x1E, 0xD5, 0xF2, 0x0B, 0xBE, 0x68, 0x07,
  25787. 0xBF, 0x65, 0xA9, 0x0B, 0x7C, 0xB2, 0xEC, 0x01,
  25788. 0x02, 0xAF, 0x02, 0x80, 0x9D, 0xC9, 0xAC, 0x7D,
  25789. 0x0A, 0x3A, 0xBC, 0x69, 0xC1, 0x83, 0x65, 0xBC,
  25790. 0xFF, 0x59, 0x18, 0x5F, 0x33, 0x99, 0x68, 0x87,
  25791. 0x74, 0x61, 0x85, 0x90, 0x6C, 0x01, 0x91, 0xAE,
  25792. 0xD4, 0x40, 0x7E, 0x13, 0x94, 0x46, 0x45, 0x9B,
  25793. 0xE2, 0x9C, 0x68, 0x22, 0x71, 0x76, 0x44, 0x35,
  25794. 0x3D, 0x24, 0xAB, 0x63, 0x39, 0x15, 0x6A, 0x9C,
  25795. 0x42, 0x49, 0x09, 0xF0, 0xA9, 0x02, 0x5B, 0xB7,
  25796. 0x47, 0x20, 0x77, 0x9B, 0xE4, 0x3F, 0x16, 0xD8,
  25797. 0x1C, 0x8C, 0xC6, 0x66, 0xE9, 0x97, 0x10, 0xD8,
  25798. 0xC6, 0x8B, 0xB5, 0xCC, 0x4E, 0x12, 0xF3, 0x14,
  25799. 0xE9, 0x25, 0xA5, 0x51, 0xF0, 0x9C, 0xC5, 0x90,
  25800. 0x03, 0xA1, 0xF8, 0x81, 0x03, 0xC2, 0x54, 0xBB,
  25801. 0x97, 0x8D, 0x75, 0xF3, 0x94, 0xD3, 0x54, 0x0E,
  25802. 0x31, 0xE7, 0x71, 0xCD, 0xA3, 0x6E, 0x39, 0xEC,
  25803. 0x54, 0xA6, 0x2B, 0x58, 0x32, 0x66, 0x4D, 0x82,
  25804. 0x1A, 0x72, 0xF1, 0xE6, 0xAF, 0xBB, 0xA2, 0x7F,
  25805. 0x84, 0x29, 0x5B, 0x26, 0x94, 0xC4, 0x98, 0x49,
  25806. 0x8E, 0x81, 0x2B, 0xC8, 0xE9, 0x37, 0x8F, 0xE5,
  25807. 0x41, 0xCE, 0xC5, 0x89, 0x1B, 0x25, 0x06, 0x29,
  25808. 0x01, 0xCB, 0x72, 0x12, 0xE3, 0xCD, 0xC4, 0x61,
  25809. 0x79, 0xEC, 0x5B, 0xCE, 0xC1, 0x0B, 0xC0, 0xB9,
  25810. 0x31, 0x1D, 0xE0, 0x50, 0x74, 0x29, 0x06, 0x87,
  25811. 0xFD, 0x6A, 0x53, 0x92, 0x67, 0x16, 0x54, 0x28,
  25812. 0x4C, 0xD9, 0xC8, 0xCC, 0x3E, 0xBA, 0x80, 0xEB,
  25813. 0x3B, 0x66, 0x2E, 0xB5, 0x3E, 0xB7, 0x51, 0x16,
  25814. 0x70, 0x4A, 0x1F, 0xEB, 0x5C, 0x2D, 0x05, 0x63,
  25815. 0x38, 0x53, 0x28, 0x68, 0xDD, 0xF2, 0x4E, 0xB8,
  25816. 0x99, 0x2A, 0xB8, 0x56, 0x5D, 0x9E, 0x49, 0x0C,
  25817. 0xAD, 0xF1, 0x48, 0x04, 0x36, 0x0D, 0xAA, 0x90,
  25818. 0x71, 0x8E, 0xAB, 0x61, 0x6B, 0xAB, 0x07, 0x65,
  25819. 0xD3, 0x39, 0x87, 0xB4, 0x7E, 0xFB, 0x65, 0x99,
  25820. 0xC5, 0x56, 0x32, 0x35, 0xE6, 0x1E, 0x4B, 0xE6,
  25821. 0x70, 0xE9, 0x79, 0x55, 0xAB, 0x29, 0x2D, 0x97,
  25822. 0x32, 0xCB, 0x89, 0x30, 0x94, 0x8A, 0xC8, 0x2D,
  25823. 0xF2, 0x30, 0xAC, 0x72, 0x29, 0x7A, 0x23, 0x67,
  25824. 0x9D, 0x6B, 0x94, 0xC1, 0x7F, 0x13, 0x59, 0x48,
  25825. 0x32, 0x54, 0xFE, 0xDC, 0x2F, 0x05, 0x81, 0x9F,
  25826. 0x0D, 0x06, 0x9A, 0x44, 0x3B, 0x78, 0xE3, 0xFC,
  25827. 0x6C, 0x3E, 0xF4, 0x71, 0x4B, 0x05, 0xA3, 0xFC,
  25828. 0xA8, 0x1C, 0xBB, 0xA6, 0x02, 0x42, 0xA7, 0x06,
  25829. 0x0C, 0xD8, 0x85, 0xD8, 0xF3, 0x99, 0x81, 0xBB,
  25830. 0x18, 0x09, 0x2B, 0x23, 0xDA, 0xA5, 0x9F, 0xD9,
  25831. 0x57, 0x83, 0x88, 0x68, 0x8A, 0x09, 0xBB, 0xA0,
  25832. 0x79, 0xBC, 0x80, 0x9A, 0x54, 0x84, 0x3A, 0x60,
  25833. 0x38, 0x5E, 0x23, 0x10, 0xBB, 0xCB, 0xCC, 0x02,
  25834. 0x13, 0xCE, 0x3D, 0xFA, 0xAB, 0x33, 0xB4, 0x7F,
  25835. 0x9D, 0x63, 0x05, 0xBC, 0x95, 0xC6, 0x10, 0x78,
  25836. 0x13, 0xC5, 0x85, 0xC4, 0xB6, 0x57, 0xBF, 0x30,
  25837. 0x54, 0x28, 0x33, 0xB1, 0x49, 0x49, 0xF5, 0x73,
  25838. 0xC0, 0x61, 0x2A, 0xD5, 0x24, 0xBA, 0xAE, 0x69,
  25839. 0x59, 0x0C, 0x12, 0x77, 0xB8, 0x6C, 0x28, 0x65,
  25840. 0x71, 0xBF, 0x66, 0xB3, 0xCF, 0xF4, 0x6A, 0x38,
  25841. 0x58, 0xC0, 0x99, 0x06, 0xA7, 0x94, 0xDF, 0x4A,
  25842. 0x06, 0xE9, 0xD4, 0xB0, 0xA2, 0xE4, 0x3F, 0x10,
  25843. 0xF7, 0x2A, 0x6C, 0x6C, 0x47, 0xE5, 0x64, 0x6E,
  25844. 0x2C, 0x79, 0x9B, 0x71, 0xC3, 0x3E, 0xD2, 0xF0,
  25845. 0x1E, 0xEB, 0x45, 0x93, 0x8E, 0xB7, 0xA4, 0xE2,
  25846. 0xE2, 0x90, 0x8C, 0x53, 0x55, 0x8A, 0x54, 0x0D,
  25847. 0x35, 0x03, 0x69, 0xFA, 0x18, 0x9C, 0x61, 0x69,
  25848. 0x43, 0xF7, 0x98, 0x1D, 0x76, 0x18, 0xCF, 0x02,
  25849. 0xA5, 0xB0, 0xA2, 0xBC, 0xC4, 0x22, 0xE8, 0x57,
  25850. 0xD1, 0xA4, 0x78, 0x71, 0x25, 0x3D, 0x08, 0x29,
  25851. 0x3C, 0x1C, 0x17, 0x9B, 0xCD, 0xC0, 0x43, 0x70,
  25852. 0x69, 0x10, 0x74, 0x18, 0x20, 0x5F, 0xDB, 0x98,
  25853. 0x56, 0x62, 0x3B, 0x8C, 0xA6, 0xB6, 0x94, 0xC9,
  25854. 0x6C, 0x08, 0x4B, 0x17, 0xF1, 0x3B, 0xB6, 0xDF,
  25855. 0x12, 0xB2, 0xCF, 0xBB, 0xC2, 0xB0, 0xE0, 0xC3,
  25856. 0x4B, 0x00, 0xD0, 0xFC, 0xD0, 0xAE, 0xCF, 0xB2,
  25857. 0x79, 0x24, 0xF6, 0x98, 0x4E, 0x74, 0x7B, 0xE2,
  25858. 0xA0, 0x9D, 0x83, 0xA8, 0x66, 0x45, 0x90, 0xA8,
  25859. 0x07, 0x73, 0x31, 0x49, 0x1A, 0x4F, 0x7D, 0x72,
  25860. 0x08, 0x43, 0xF2, 0x3E, 0x65, 0x2C, 0x6F, 0xA8,
  25861. 0x40, 0x30, 0x8D, 0xB4, 0x02, 0x03, 0x37, 0xAA,
  25862. 0xD3, 0x79, 0x67, 0x03, 0x4A, 0x9F, 0xB5, 0x23,
  25863. 0xB6, 0x7C, 0xA7, 0x03, 0x30, 0xF0, 0x2D, 0x9E,
  25864. 0xA2, 0x0C, 0x1E, 0x84, 0xCB, 0x8E, 0x57, 0x57,
  25865. 0xC9, 0xE1, 0x89, 0x6B, 0x60, 0x58, 0x14, 0x41,
  25866. 0xED, 0x61, 0x8A, 0xA5, 0xB2, 0x6D, 0xA5, 0x6C,
  25867. 0x0A, 0x5A, 0x73, 0xC4, 0xDC, 0xFD, 0x75, 0x5E,
  25868. 0x61, 0x0B, 0x4F, 0xC8, 0x1F, 0xF8, 0x4E, 0x21,
  25869. 0xD2, 0xE5, 0x74, 0xDF, 0xD8, 0xCD, 0x0A, 0xE8,
  25870. 0x93, 0xAA, 0x7E, 0x12, 0x5B, 0x44, 0xB9, 0x24,
  25871. 0xF4, 0x52, 0x23, 0xEC, 0x09, 0xF2, 0xAD, 0x11,
  25872. 0x41, 0xEA, 0x93, 0xA6, 0x80, 0x50, 0xDB, 0xF6,
  25873. 0x99, 0xE3, 0x24, 0x68, 0x84, 0x18, 0x1F, 0x8E,
  25874. 0x1D, 0xD4, 0x4E, 0x0C, 0x76, 0x29, 0x09, 0x33,
  25875. 0x30, 0x22, 0x1F, 0xD6, 0x7D, 0x9B, 0x7D, 0x6E,
  25876. 0x15, 0x10, 0xB2, 0xDB, 0xAD, 0x87, 0x62, 0xF7
  25877. };
  25878. #endif
  25879. static byte pubKey[KYBER_MAX_PUBLIC_KEY_SIZE];
  25880. static byte privKey[KYBER_MAX_PRIVATE_KEY_SIZE];
  25881. key = (KyberKey*)XMALLOC(sizeof(KyberKey), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  25882. ExpectNotNull(key);
  25883. if (key != NULL) {
  25884. XMEMSET(key, 0, sizeof(KyberKey));
  25885. }
  25886. #ifndef WOLFSSL_NO_KYBER512
  25887. ExpectIntEQ(wc_KyberKey_Init(KYBER512, key, NULL, INVALID_DEVID), 0);
  25888. ExpectIntEQ(wc_KyberKey_MakeKeyWithRandom(key, seed_512, sizeof(seed_512)),
  25889. 0);
  25890. ExpectIntEQ(wc_KyberKey_EncodePublicKey(key, pubKey,
  25891. KYBER512_PUBLIC_KEY_SIZE), 0);
  25892. ExpectIntEQ(wc_KyberKey_EncodePrivateKey(key, privKey,
  25893. KYBER512_PRIVATE_KEY_SIZE), 0);
  25894. ExpectIntEQ(XMEMCMP(pubKey, ek_512, KYBER512_PUBLIC_KEY_SIZE), 0);
  25895. ExpectIntEQ(XMEMCMP(privKey, dk_512, KYBER512_PRIVATE_KEY_SIZE), 0);
  25896. wc_KyberKey_Free(key);
  25897. #endif
  25898. #ifndef WOLFSSL_NO_KYBER768
  25899. ExpectIntEQ(wc_KyberKey_Init(KYBER768, key, NULL, INVALID_DEVID), 0);
  25900. ExpectIntEQ(wc_KyberKey_MakeKeyWithRandom(key, seed_768, sizeof(seed_768)),
  25901. 0);
  25902. ExpectIntEQ(wc_KyberKey_EncodePublicKey(key, pubKey,
  25903. KYBER768_PUBLIC_KEY_SIZE), 0);
  25904. ExpectIntEQ(wc_KyberKey_EncodePrivateKey(key, privKey,
  25905. KYBER768_PRIVATE_KEY_SIZE), 0);
  25906. ExpectIntEQ(XMEMCMP(pubKey, ek_768, KYBER768_PUBLIC_KEY_SIZE), 0);
  25907. ExpectIntEQ(XMEMCMP(privKey, dk_768, KYBER768_PRIVATE_KEY_SIZE), 0);
  25908. wc_KyberKey_Free(key);
  25909. #endif
  25910. #ifndef WOLFSSL_NO_KYBER1024
  25911. ExpectIntEQ(wc_KyberKey_Init(KYBER1024, key, NULL, INVALID_DEVID), 0);
  25912. ExpectIntEQ(wc_KyberKey_MakeKeyWithRandom(key, seed_1024,
  25913. sizeof(seed_1024)), 0);
  25914. ExpectIntEQ(wc_KyberKey_EncodePublicKey(key, pubKey,
  25915. KYBER1024_PUBLIC_KEY_SIZE), 0);
  25916. ExpectIntEQ(wc_KyberKey_EncodePrivateKey(key, privKey,
  25917. KYBER1024_PRIVATE_KEY_SIZE), 0);
  25918. ExpectIntEQ(XMEMCMP(pubKey, ek_1024, KYBER1024_PUBLIC_KEY_SIZE), 0);
  25919. ExpectIntEQ(XMEMCMP(privKey, dk_1024, KYBER1024_PRIVATE_KEY_SIZE), 0);
  25920. wc_KyberKey_Free(key);
  25921. #endif
  25922. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  25923. #endif
  25924. return EXPECT_RESULT();
  25925. }
  25926. static int test_wc_kyber_encapsulate_kats(void)
  25927. {
  25928. EXPECT_DECLS;
  25929. #if defined(WOLFSSL_HAVE_KYBER) && defined(WOLFSSL_WC_KYBER) && \
  25930. !defined(WOLFSSL_KYBER_ORIGINAL)
  25931. KyberKey* key;
  25932. #ifndef WOLFSSL_NO_KYBER512
  25933. static const byte ek_512[KYBER512_PUBLIC_KEY_SIZE] = {
  25934. 0xDD, 0x19, 0x24, 0x93, 0x5A, 0xA8, 0xE6, 0x17,
  25935. 0xAF, 0x18, 0xB5, 0xA0, 0x65, 0xAC, 0x45, 0x72,
  25936. 0x77, 0x67, 0xEE, 0x89, 0x7C, 0xF4, 0xF9, 0x44,
  25937. 0x2B, 0x2A, 0xCE, 0x30, 0xC0, 0x23, 0x7B, 0x30,
  25938. 0x7D, 0x3E, 0x76, 0xBF, 0x8E, 0xEB, 0x78, 0xAD,
  25939. 0xDC, 0x4A, 0xAC, 0xD1, 0x64, 0x63, 0xD8, 0x60,
  25940. 0x2F, 0xD5, 0x48, 0x7B, 0x63, 0xC8, 0x8B, 0xB6,
  25941. 0x60, 0x27, 0xF3, 0x7D, 0x0D, 0x61, 0x4D, 0x6F,
  25942. 0x9C, 0x24, 0x60, 0x3C, 0x42, 0x94, 0x76, 0x64,
  25943. 0xAC, 0x43, 0x98, 0xC6, 0xC5, 0x23, 0x83, 0x46,
  25944. 0x9B, 0x4F, 0x97, 0x77, 0xE5, 0xEC, 0x72, 0x06,
  25945. 0x21, 0x0F, 0x3E, 0x5A, 0x79, 0x6B, 0xF4, 0x5C,
  25946. 0x53, 0x26, 0x8E, 0x25, 0xF3, 0x9A, 0xC2, 0x61,
  25947. 0xAF, 0x3B, 0xFA, 0x2E, 0xE7, 0x55, 0xBE, 0xB8,
  25948. 0xB6, 0x7A, 0xB3, 0xAC, 0x8D, 0xF6, 0xC6, 0x29,
  25949. 0xC1, 0x17, 0x6E, 0x9E, 0x3B, 0x96, 0x5E, 0x93,
  25950. 0x69, 0xF9, 0xB3, 0xB9, 0x2A, 0xD7, 0xC2, 0x09,
  25951. 0x55, 0x64, 0x1D, 0x99, 0x52, 0x6F, 0xE7, 0xB9,
  25952. 0xFE, 0x8C, 0x85, 0x08, 0x20, 0x27, 0x5C, 0xD9,
  25953. 0x64, 0x84, 0x92, 0x50, 0x09, 0x07, 0x33, 0xCE,
  25954. 0x12, 0x4E, 0xCF, 0x31, 0x66, 0x24, 0x37, 0x4B,
  25955. 0xD1, 0x8B, 0x7C, 0x35, 0x8C, 0x06, 0xE9, 0xC1,
  25956. 0x36, 0xEE, 0x12, 0x59, 0xA9, 0x24, 0x5A, 0xBC,
  25957. 0x55, 0xB9, 0x64, 0xD6, 0x89, 0xF5, 0xA0, 0x82,
  25958. 0x92, 0xD2, 0x82, 0x65, 0x65, 0x8E, 0xBB, 0x40,
  25959. 0xCB, 0xFE, 0x48, 0x8A, 0x22, 0x28, 0x27, 0x55,
  25960. 0x90, 0xAB, 0x9F, 0x32, 0xA3, 0x41, 0x09, 0x70,
  25961. 0x9C, 0x1C, 0x29, 0x1D, 0x4A, 0x23, 0x33, 0x72,
  25962. 0x74, 0xC7, 0xA5, 0xA5, 0x99, 0x1C, 0x7A, 0x87,
  25963. 0xB8, 0x1C, 0x97, 0x4A, 0xB1, 0x8C, 0xE7, 0x78,
  25964. 0x59, 0xE4, 0x99, 0x5E, 0x7C, 0x14, 0xF0, 0x37,
  25965. 0x17, 0x48, 0xB7, 0x71, 0x2F, 0xB5, 0x2C, 0x59,
  25966. 0x66, 0xCD, 0x63, 0x06, 0x3C, 0x4F, 0x3B, 0x81,
  25967. 0xB4, 0x7C, 0x45, 0xDD, 0xE8, 0x3F, 0xB3, 0xA2,
  25968. 0x72, 0x40, 0x29, 0xB1, 0x0B, 0x32, 0x30, 0x21,
  25969. 0x4C, 0x04, 0xFA, 0x05, 0x77, 0xFC, 0x29, 0xAC,
  25970. 0x90, 0x86, 0xAE, 0x18, 0xC5, 0x3B, 0x3E, 0xD4,
  25971. 0x4E, 0x50, 0x74, 0x12, 0xFC, 0xA0, 0x4B, 0x4F,
  25972. 0x53, 0x8A, 0x51, 0x58, 0x8E, 0xC1, 0xF1, 0x02,
  25973. 0x9D, 0x15, 0x2D, 0x9A, 0xE7, 0x73, 0x5F, 0x76,
  25974. 0xA0, 0x77, 0xAA, 0x94, 0x84, 0x38, 0x0A, 0xED,
  25975. 0x91, 0x89, 0xE5, 0x91, 0x24, 0x87, 0xFC, 0xC5,
  25976. 0xB7, 0xC7, 0x01, 0x2D, 0x92, 0x23, 0xDD, 0x96,
  25977. 0x7E, 0xEC, 0xDA, 0xC3, 0x00, 0x8A, 0x89, 0x31,
  25978. 0xB6, 0x48, 0x24, 0x35, 0x37, 0xF5, 0x48, 0xC1,
  25979. 0x71, 0x69, 0x8C, 0x5B, 0x38, 0x1D, 0x84, 0x6A,
  25980. 0x72, 0xE5, 0xC9, 0x2D, 0x42, 0x26, 0xC5, 0xA8,
  25981. 0x90, 0x98, 0x84, 0xF1, 0xC4, 0xA3, 0x40, 0x4C,
  25982. 0x17, 0x20, 0xA5, 0x27, 0x94, 0x14, 0xD7, 0xF2,
  25983. 0x7B, 0x2B, 0x98, 0x26, 0x52, 0xB6, 0x74, 0x02,
  25984. 0x19, 0xC5, 0x6D, 0x21, 0x77, 0x80, 0xD7, 0xA5,
  25985. 0xE5, 0xBA, 0x59, 0x83, 0x63, 0x49, 0xF7, 0x26,
  25986. 0x88, 0x1D, 0xEA, 0x18, 0xEF, 0x75, 0xC0, 0x77,
  25987. 0x2A, 0x8B, 0x92, 0x27, 0x66, 0x95, 0x37, 0x18,
  25988. 0xCA, 0xCC, 0x14, 0xCC, 0xBA, 0xCB, 0x5F, 0xC4,
  25989. 0x12, 0xA2, 0xD0, 0xBE, 0x52, 0x18, 0x17, 0x64,
  25990. 0x5A, 0xB2, 0xBF, 0x6A, 0x47, 0x85, 0xE9, 0x2B,
  25991. 0xC9, 0x4C, 0xAF, 0x47, 0x7A, 0x96, 0x78, 0x76,
  25992. 0x79, 0x6C, 0x0A, 0x51, 0x90, 0x31, 0x5A, 0xC0,
  25993. 0x88, 0x56, 0x71, 0xA4, 0xC7, 0x49, 0x56, 0x4C,
  25994. 0x3B, 0x2C, 0x7A, 0xED, 0x90, 0x64, 0xEB, 0xA2,
  25995. 0x99, 0xEF, 0x21, 0x4B, 0xA2, 0xF4, 0x04, 0x93,
  25996. 0x66, 0x7C, 0x8B, 0xD0, 0x32, 0xAE, 0xC5, 0x62,
  25997. 0x17, 0x11, 0xB4, 0x1A, 0x38, 0x52, 0xC5, 0xC2,
  25998. 0xBA, 0xB4, 0xA3, 0x49, 0xCE, 0x4B, 0x7F, 0x08,
  25999. 0x5A, 0x81, 0x2B, 0xBB, 0xC8, 0x20, 0xB8, 0x1B,
  26000. 0xEF, 0xE6, 0x3A, 0x05, 0xB8, 0xBC, 0xDF, 0xE9,
  26001. 0xC2, 0xA7, 0x0A, 0x8B, 0x1A, 0xCA, 0x9B, 0xF9,
  26002. 0x81, 0x64, 0x81, 0x90, 0x7F, 0xF4, 0x43, 0x24,
  26003. 0x61, 0x11, 0x12, 0x87, 0x30, 0x3F, 0x0B, 0xD8,
  26004. 0x17, 0xC0, 0x57, 0x26, 0xBF, 0xA1, 0x8A, 0x2E,
  26005. 0x24, 0xC7, 0x72, 0x49, 0x21, 0x02, 0x80, 0x32,
  26006. 0xF6, 0x22, 0xBD, 0x96, 0x0A, 0x31, 0x7D, 0x83,
  26007. 0xB3, 0x56, 0xB5, 0x7F, 0x4A, 0x80, 0x04, 0x49,
  26008. 0x9C, 0xBC, 0x73, 0xC9, 0x7D, 0x1E, 0xB7, 0x74,
  26009. 0x59, 0x72, 0x63, 0x1C, 0x05, 0x61, 0xC1, 0xA3,
  26010. 0xAB, 0x6E, 0xF9, 0x1B, 0xD3, 0x63, 0x28, 0x0A,
  26011. 0x10, 0x54, 0x5D, 0xA6, 0x93, 0xE6, 0xD5, 0x8A,
  26012. 0xED, 0x68, 0x45, 0xE7, 0xCC, 0x5F, 0x0D, 0x08,
  26013. 0xCA, 0x79, 0x05, 0x05, 0x2C, 0x77, 0x36, 0x6D,
  26014. 0x19, 0x72, 0xCC, 0xFC, 0xC1, 0xA2, 0x76, 0x10,
  26015. 0xCB, 0x54, 0x36, 0x65, 0xAA, 0x79, 0x8E, 0x20,
  26016. 0x94, 0x01, 0x28, 0xB9, 0x56, 0x7A, 0x7E, 0xDB,
  26017. 0x7A, 0x90, 0x04, 0x07, 0xC7, 0x0D, 0x35, 0x94,
  26018. 0x38, 0x43, 0x5E, 0x13, 0x96, 0x16, 0x08, 0xD5,
  26019. 0x52, 0xA9, 0x4C, 0x5C, 0xDA, 0x78, 0x59, 0x22,
  26020. 0x05, 0x09, 0xB4, 0x83, 0xC5, 0xC5, 0x2A, 0x21,
  26021. 0x0E, 0x9C, 0x81, 0x2B, 0xC0, 0xC2, 0x32, 0x8C,
  26022. 0xA0, 0x0E, 0x78, 0x9A, 0x56, 0xB2, 0x60, 0x6B,
  26023. 0x90, 0x29, 0x2E, 0x35, 0x43, 0xDA, 0xCA, 0xA2,
  26024. 0x43, 0x18, 0x41, 0xD6, 0x1A, 0x22, 0xCA, 0x90,
  26025. 0xC1, 0xCC, 0xF0, 0xB5, 0xB4, 0xE0, 0xA6, 0xF6,
  26026. 0x40, 0x53, 0x6D, 0x1A, 0x26, 0xAB, 0x5B, 0x8D,
  26027. 0x21, 0x51, 0x32, 0x79, 0x28, 0xCE, 0x02, 0x90,
  26028. 0x4C, 0xF1, 0xD1, 0x5E, 0x32, 0x78, 0x8A, 0x95,
  26029. 0xF6, 0x2D, 0x3C, 0x27, 0x0B, 0x6F, 0xA1, 0x50,
  26030. 0x8F, 0x97, 0xB9, 0x15, 0x5A, 0x27, 0x26, 0xD8,
  26031. 0x0A, 0x1A, 0xFA, 0x3C, 0x53, 0x87, 0xA2, 0x76,
  26032. 0xA4, 0xD0, 0x31, 0xA0, 0x8A, 0xBF, 0x4F, 0x2E,
  26033. 0x74, 0xF1, 0xA0, 0xBB, 0x8A, 0x0F, 0xD3, 0xCB
  26034. };
  26035. static const byte seed_512[KYBER_ENC_RAND_SZ] = {
  26036. 0x6F, 0xF0, 0x2E, 0x1D, 0xC7, 0xFD, 0x91, 0x1B,
  26037. 0xEE, 0xE0, 0xC6, 0x92, 0xC8, 0xBD, 0x10, 0x0C,
  26038. 0x3E, 0x5C, 0x48, 0x96, 0x4D, 0x31, 0xDF, 0x92,
  26039. 0x99, 0x42, 0x18, 0xE8, 0x06, 0x64, 0xA6, 0xCA
  26040. };
  26041. static const byte c_512[KYBER512_CIPHER_TEXT_SIZE] = {
  26042. 0x19, 0xC5, 0x92, 0x50, 0x59, 0x07, 0xC2, 0x4C,
  26043. 0x5F, 0xA2, 0xEB, 0xFA, 0x93, 0x2D, 0x2C, 0xBB,
  26044. 0x48, 0xF3, 0xE4, 0x34, 0x0A, 0x28, 0xF7, 0xEB,
  26045. 0xA5, 0xD0, 0x68, 0xFC, 0xAC, 0xAB, 0xED, 0xF7,
  26046. 0x77, 0x84, 0xE2, 0xB2, 0x4D, 0x79, 0x61, 0x77,
  26047. 0x5F, 0x0B, 0xF1, 0xA9, 0x97, 0xAE, 0x8B, 0xA9,
  26048. 0xFC, 0x43, 0x11, 0xBE, 0x63, 0x71, 0x67, 0x79,
  26049. 0xC2, 0xB7, 0x88, 0xF8, 0x12, 0xCB, 0xB7, 0x8C,
  26050. 0x74, 0xE7, 0x51, 0x7E, 0x22, 0xE9, 0x10, 0xEF,
  26051. 0xF5, 0xF3, 0x8D, 0x44, 0x46, 0x9C, 0x50, 0xDE,
  26052. 0x16, 0x75, 0xAE, 0x19, 0x8F, 0xD6, 0xA2, 0x89,
  26053. 0xAE, 0x7E, 0x6C, 0x30, 0xA9, 0xD4, 0x35, 0x1B,
  26054. 0x3D, 0x1F, 0x4C, 0x36, 0xEF, 0xF9, 0xC6, 0x8D,
  26055. 0xA9, 0x1C, 0x40, 0xB8, 0x2D, 0xC9, 0xB2, 0x79,
  26056. 0x9A, 0x33, 0xA2, 0x6B, 0x60, 0xA4, 0xE7, 0x0D,
  26057. 0x71, 0x01, 0x86, 0x27, 0x79, 0x46, 0x9F, 0x3A,
  26058. 0x9D, 0xAE, 0xC8, 0xE3, 0xE8, 0xF8, 0xC6, 0xA1,
  26059. 0x6B, 0xF0, 0x92, 0xFB, 0xA5, 0x86, 0x61, 0x86,
  26060. 0xB8, 0xD2, 0x08, 0xFD, 0xEB, 0x27, 0x4A, 0xC1,
  26061. 0xF8, 0x29, 0x65, 0x9D, 0xC2, 0xBE, 0x4A, 0xC4,
  26062. 0xF3, 0x06, 0xCB, 0x55, 0x84, 0xBA, 0xD1, 0x93,
  26063. 0x6A, 0x92, 0xC9, 0xB7, 0x68, 0x19, 0x23, 0x42,
  26064. 0x81, 0xBB, 0x39, 0x58, 0x41, 0xC2, 0x57, 0x56,
  26065. 0x08, 0x6E, 0xA5, 0x64, 0xCA, 0x3E, 0x22, 0x7E,
  26066. 0x3D, 0x9F, 0x10, 0x52, 0xC0, 0x76, 0x6D, 0x2E,
  26067. 0xB7, 0x9A, 0x47, 0xC1, 0x50, 0x72, 0x1E, 0x0D,
  26068. 0xEA, 0x7C, 0x00, 0x69, 0xD5, 0x51, 0xB2, 0x64,
  26069. 0x80, 0x1B, 0x77, 0x27, 0xEC, 0xAF, 0x82, 0xEE,
  26070. 0xCB, 0x99, 0xA8, 0x76, 0xFD, 0xA0, 0x90, 0xBF,
  26071. 0x6C, 0x3F, 0xC6, 0xB1, 0x09, 0xF1, 0x70, 0x14,
  26072. 0x85, 0xF0, 0x3C, 0xE6, 0x62, 0x74, 0xB8, 0x43,
  26073. 0x5B, 0x0A, 0x01, 0x4C, 0xFB, 0x3E, 0x79, 0xCC,
  26074. 0xED, 0x67, 0x05, 0x7B, 0x5A, 0xE2, 0xAD, 0x7F,
  26075. 0x52, 0x79, 0xEB, 0x71, 0x49, 0x42, 0xE4, 0xC1,
  26076. 0xCC, 0xFF, 0x7E, 0x85, 0xC0, 0xDB, 0x43, 0xE5,
  26077. 0xD4, 0x12, 0x89, 0x20, 0x73, 0x63, 0xB4, 0x44,
  26078. 0xBB, 0x51, 0xBB, 0x8A, 0xB0, 0x37, 0x1E, 0x70,
  26079. 0xCB, 0xD5, 0x5F, 0x0F, 0x3D, 0xAD, 0x40, 0x3E,
  26080. 0x10, 0x51, 0x76, 0xE3, 0xE8, 0xA2, 0x25, 0xD8,
  26081. 0x4A, 0xC8, 0xBE, 0xE3, 0x8C, 0x82, 0x1E, 0xE0,
  26082. 0xF5, 0x47, 0x43, 0x11, 0x45, 0xDC, 0xB3, 0x13,
  26083. 0x92, 0x86, 0xAB, 0xB1, 0x17, 0x94, 0xA4, 0x3A,
  26084. 0x3C, 0x1B, 0x52, 0x29, 0xE4, 0xBC, 0xFE, 0x95,
  26085. 0x9C, 0x78, 0xAD, 0xAE, 0xE2, 0xD5, 0xF2, 0x49,
  26086. 0x7B, 0x5D, 0x24, 0xBC, 0x21, 0xFA, 0x03, 0xA9,
  26087. 0xA5, 0x8C, 0x24, 0x55, 0x37, 0x3E, 0xC8, 0x95,
  26088. 0x83, 0xE7, 0xE5, 0x88, 0xD7, 0xFE, 0x67, 0x99,
  26089. 0x1E, 0xE9, 0x37, 0x83, 0xED, 0x4A, 0x6F, 0x9E,
  26090. 0xEA, 0xE0, 0x4E, 0x64, 0xE2, 0xE1, 0xE0, 0xE6,
  26091. 0x99, 0xF6, 0xDC, 0x9C, 0x5D, 0x39, 0xEF, 0x92,
  26092. 0x78, 0xC9, 0x85, 0xE7, 0xFD, 0xF2, 0xA7, 0x64,
  26093. 0xFF, 0xD1, 0xA0, 0xB9, 0x57, 0x92, 0xAD, 0x68,
  26094. 0x1E, 0x93, 0x0D, 0x76, 0xDF, 0x4E, 0xFE, 0x5D,
  26095. 0x65, 0xDB, 0xBD, 0x0F, 0x14, 0x38, 0x48, 0x1E,
  26096. 0xD8, 0x33, 0xAD, 0x49, 0x46, 0xAD, 0x1C, 0x69,
  26097. 0xAD, 0x21, 0xDD, 0x7C, 0x86, 0x18, 0x57, 0x74,
  26098. 0x42, 0x6F, 0x3F, 0xCF, 0x53, 0xB5, 0x2A, 0xD4,
  26099. 0xB4, 0x0D, 0x22, 0x8C, 0xE1, 0x24, 0x07, 0x2F,
  26100. 0x59, 0x2C, 0x7D, 0xAA, 0x05, 0x7F, 0x17, 0xD7,
  26101. 0x90, 0xA5, 0xBD, 0x5B, 0x93, 0x83, 0x4D, 0x58,
  26102. 0xC0, 0x8C, 0x88, 0xDC, 0x8F, 0x0E, 0xF4, 0x88,
  26103. 0x15, 0x64, 0x25, 0xB7, 0x44, 0x65, 0x4E, 0xAC,
  26104. 0xA9, 0xD6, 0x48, 0x58, 0xA4, 0xD6, 0xCE, 0xB4,
  26105. 0x78, 0x79, 0x51, 0x94, 0xBF, 0xAD, 0xB1, 0x8D,
  26106. 0xC0, 0xEA, 0x05, 0x4F, 0x97, 0x71, 0x21, 0x5A,
  26107. 0xD3, 0xCB, 0x1F, 0xD0, 0x31, 0xD7, 0xBE, 0x45,
  26108. 0x98, 0x62, 0x19, 0x26, 0x47, 0x8D, 0x37, 0x5A,
  26109. 0x18, 0x45, 0xAA, 0x91, 0xD7, 0xC7, 0x33, 0xF8,
  26110. 0xF0, 0xE1, 0x88, 0xC8, 0x38, 0x96, 0xED, 0xF8,
  26111. 0x3B, 0x86, 0x46, 0xC9, 0x9E, 0x29, 0xC0, 0xDA,
  26112. 0x22, 0x90, 0xE7, 0x1C, 0x3D, 0x2E, 0x97, 0x07,
  26113. 0x20, 0xC9, 0x7B, 0x5B, 0x7F, 0x95, 0x04, 0x86,
  26114. 0x03, 0x3C, 0x6A, 0x25, 0x71, 0xDD, 0xF2, 0xBC,
  26115. 0xCD, 0xAB, 0xB2, 0xDF, 0xA5, 0xFC, 0xE4, 0xC3,
  26116. 0xA1, 0x88, 0x46, 0x06, 0x04, 0x1D, 0x18, 0x1C,
  26117. 0x72, 0x87, 0x94, 0xAE, 0x0E, 0x80, 0x6E, 0xCB,
  26118. 0x49, 0xAF, 0x16, 0x75, 0x6A, 0x4C, 0xE7, 0x3C,
  26119. 0x87, 0xBD, 0x42, 0x34, 0xE6, 0x0F, 0x05, 0x53,
  26120. 0x5F, 0xA5, 0x92, 0x9F, 0xD5, 0xA3, 0x44, 0x73,
  26121. 0x26, 0x64, 0x01, 0xF6, 0x3B, 0xBD, 0x6B, 0x90,
  26122. 0xE0, 0x03, 0x47, 0x2A, 0xC0, 0xCE, 0x88, 0xF1,
  26123. 0xB6, 0x66, 0x59, 0x72, 0x79, 0xD0, 0x56, 0xA6,
  26124. 0x32, 0xC8, 0xD6, 0xB7, 0x90, 0xFD, 0x41, 0x17,
  26125. 0x67, 0x84, 0x8A, 0x69, 0xE3, 0x7A, 0x8A, 0x83,
  26126. 0x9B, 0xC7, 0x66, 0xA0, 0x2C, 0xA2, 0xF6, 0x95,
  26127. 0xEC, 0x63, 0xF0, 0x56, 0xA4, 0xE2, 0xA1, 0x14,
  26128. 0xCA, 0xCF, 0x9F, 0xD9, 0x0D, 0x73, 0x0C, 0x97,
  26129. 0x0D, 0xB3, 0x87, 0xF6, 0xDE, 0x73, 0x39, 0x5F,
  26130. 0x70, 0x1A, 0x1D, 0x95, 0x3B, 0x2A, 0x89, 0xDD,
  26131. 0x7E, 0xDA, 0xD4, 0x39, 0xFC, 0x20, 0x5A, 0x54,
  26132. 0xA4, 0x81, 0xE8, 0x89, 0xB0, 0x98, 0xD5, 0x25,
  26133. 0x56, 0x70, 0xF0, 0x26, 0xB4, 0xA2, 0xBF, 0x02,
  26134. 0xD2, 0xBD, 0xDE, 0x87, 0xC7, 0x66, 0xB2, 0x5F,
  26135. 0xC5, 0xE0, 0xFD, 0x45, 0x37, 0x57, 0xE7, 0x56,
  26136. 0xD1, 0x8C, 0x8C, 0xD9, 0x12, 0xF9, 0xA7, 0x7F,
  26137. 0x8E, 0x6B, 0xF0, 0x20, 0x53, 0x74, 0xB4, 0x62
  26138. };
  26139. static const byte k_512[KYBER_SS_SZ] = {
  26140. 0x0B, 0xF3, 0x23, 0x33, 0x8D, 0x6F, 0x0A, 0x21,
  26141. 0xD5, 0x51, 0x4B, 0x67, 0x3C, 0xD1, 0x0B, 0x71,
  26142. 0x4C, 0xE6, 0xE3, 0x6F, 0x35, 0xBC, 0xD1, 0xBF,
  26143. 0x54, 0x41, 0x96, 0x36, 0x8E, 0xE5, 0x1A, 0x13
  26144. };
  26145. #endif
  26146. #ifndef WOLFSSL_NO_KYBER768
  26147. static const byte ek_768[KYBER768_PUBLIC_KEY_SIZE] = {
  26148. 0x89, 0xD2, 0xCB, 0x65, 0xF9, 0x4D, 0xCB, 0xFC,
  26149. 0x89, 0x0E, 0xFC, 0x7D, 0x0E, 0x5A, 0x7A, 0x38,
  26150. 0x34, 0x4D, 0x16, 0x41, 0xA3, 0xD0, 0xB0, 0x24,
  26151. 0xD5, 0x07, 0x97, 0xA5, 0xF2, 0x3C, 0x3A, 0x18,
  26152. 0xB3, 0x10, 0x1A, 0x12, 0x69, 0x06, 0x9F, 0x43,
  26153. 0xA8, 0x42, 0xBA, 0xCC, 0x09, 0x8A, 0x88, 0x21,
  26154. 0x27, 0x1C, 0x67, 0x3D, 0xB1, 0xBE, 0xB3, 0x30,
  26155. 0x34, 0xE4, 0xD7, 0x77, 0x4D, 0x16, 0x63, 0x5C,
  26156. 0x7C, 0x2C, 0x3C, 0x27, 0x63, 0x45, 0x35, 0x38,
  26157. 0xBC, 0x16, 0x32, 0xE1, 0x85, 0x15, 0x91, 0xA5,
  26158. 0x16, 0x42, 0x97, 0x4E, 0x59, 0x28, 0xAB, 0xB8,
  26159. 0xE5, 0x5F, 0xE5, 0x56, 0x12, 0xF9, 0xB1, 0x41,
  26160. 0xAF, 0xF0, 0x15, 0x54, 0x53, 0x94, 0xB2, 0x09,
  26161. 0x2E, 0x59, 0x09, 0x70, 0xEC, 0x29, 0xA7, 0xB7,
  26162. 0xE7, 0xAA, 0x1F, 0xB4, 0x49, 0x3B, 0xF7, 0xCB,
  26163. 0x73, 0x19, 0x06, 0xC2, 0xA5, 0xCB, 0x49, 0xE6,
  26164. 0x61, 0x48, 0x59, 0x06, 0x4E, 0x19, 0xB8, 0xFA,
  26165. 0x26, 0xAF, 0x51, 0xC4, 0x4B, 0x5E, 0x75, 0x35,
  26166. 0xBF, 0xDA, 0xC0, 0x72, 0xB6, 0x46, 0xD3, 0xEA,
  26167. 0x49, 0x0D, 0x27, 0x7F, 0x0D, 0x97, 0xCE, 0xD4,
  26168. 0x73, 0x95, 0xFE, 0xD9, 0x1E, 0x8F, 0x2B, 0xCE,
  26169. 0x0E, 0x3C, 0xA1, 0x22, 0xC2, 0x02, 0x5F, 0x74,
  26170. 0x06, 0x7A, 0xB9, 0x28, 0xA8, 0x22, 0xB3, 0x56,
  26171. 0x53, 0xA7, 0x4F, 0x06, 0x75, 0x76, 0x29, 0xAF,
  26172. 0xB1, 0xA1, 0xCA, 0xF2, 0x37, 0x10, 0x0E, 0xA9,
  26173. 0x35, 0xE7, 0x93, 0xC8, 0xF5, 0x8A, 0x71, 0xB3,
  26174. 0xD6, 0xAE, 0x2C, 0x86, 0x58, 0xB1, 0x01, 0x50,
  26175. 0xD4, 0xA3, 0x8F, 0x57, 0x2A, 0x0D, 0x49, 0xD2,
  26176. 0x8A, 0xE8, 0x94, 0x51, 0xD3, 0x38, 0x32, 0x6F,
  26177. 0xDB, 0x3B, 0x43, 0x50, 0x03, 0x6C, 0x10, 0x81,
  26178. 0x11, 0x77, 0x40, 0xED, 0xB8, 0x6B, 0x12, 0x08,
  26179. 0x1C, 0x5C, 0x12, 0x23, 0xDB, 0xB5, 0x66, 0x0D,
  26180. 0x5B, 0x3C, 0xB3, 0x78, 0x7D, 0x48, 0x18, 0x49,
  26181. 0x30, 0x4C, 0x68, 0xBE, 0x87, 0x54, 0x66, 0xF1,
  26182. 0x4E, 0xE5, 0x49, 0x5C, 0x2B, 0xD7, 0x95, 0xAE,
  26183. 0x41, 0x2D, 0x09, 0x00, 0x2D, 0x65, 0xB8, 0x71,
  26184. 0x9B, 0x90, 0xCB, 0xA3, 0x60, 0x3A, 0xC4, 0x95,
  26185. 0x8E, 0xA0, 0x3C, 0xC1, 0x38, 0xC8, 0x6F, 0x78,
  26186. 0x51, 0x59, 0x31, 0x25, 0x33, 0x47, 0x01, 0xB6,
  26187. 0x77, 0xF8, 0x2F, 0x49, 0x52, 0xA4, 0xC9, 0x3B,
  26188. 0x5B, 0x4C, 0x13, 0x4B, 0xB4, 0x2A, 0x85, 0x7F,
  26189. 0xD1, 0x5C, 0x65, 0x08, 0x64, 0xA6, 0xAA, 0x94,
  26190. 0xEB, 0x69, 0x1C, 0x0B, 0x69, 0x1B, 0xE4, 0x68,
  26191. 0x4C, 0x1F, 0x5B, 0x74, 0x90, 0x46, 0x7F, 0xC0,
  26192. 0x1B, 0x1D, 0x1F, 0xDA, 0x4D, 0xDA, 0x35, 0xC4,
  26193. 0xEC, 0xC2, 0x31, 0xBC, 0x73, 0xA6, 0xFE, 0xF4,
  26194. 0x2C, 0x99, 0xD3, 0x4E, 0xB8, 0x2A, 0x4D, 0x01,
  26195. 0x49, 0x87, 0xB3, 0xE3, 0x86, 0x91, 0x0C, 0x62,
  26196. 0x67, 0x9A, 0x11, 0x8F, 0x3C, 0x5B, 0xD9, 0xF4,
  26197. 0x67, 0xE4, 0x16, 0x20, 0x42, 0x42, 0x43, 0x57,
  26198. 0xDB, 0x92, 0xEF, 0x48, 0x4A, 0x4A, 0x17, 0x98,
  26199. 0xC1, 0x25, 0x7E, 0x87, 0x0A, 0x30, 0xCB, 0x20,
  26200. 0xAA, 0xA0, 0x33, 0x5D, 0x83, 0x31, 0x4F, 0xE0,
  26201. 0xAA, 0x7E, 0x63, 0xA8, 0x62, 0x64, 0x80, 0x41,
  26202. 0xA7, 0x2A, 0x63, 0x21, 0x52, 0x32, 0x20, 0xB1,
  26203. 0xAC, 0xE9, 0xBB, 0x70, 0x1B, 0x21, 0xAC, 0x12,
  26204. 0x53, 0xCB, 0x81, 0x2C, 0x15, 0x57, 0x5A, 0x90,
  26205. 0x85, 0xEA, 0xBE, 0xAD, 0xE7, 0x3A, 0x4A, 0xE7,
  26206. 0x6E, 0x6A, 0x7B, 0x15, 0x8A, 0x20, 0x58, 0x6D,
  26207. 0x78, 0xA5, 0xAC, 0x62, 0x0A, 0x5C, 0x9A, 0xBC,
  26208. 0xC9, 0xC0, 0x43, 0x35, 0x0A, 0x73, 0x65, 0x6B,
  26209. 0x0A, 0xBE, 0x82, 0x2D, 0xA5, 0xE0, 0xBA, 0x76,
  26210. 0x04, 0x5F, 0xAD, 0x75, 0x40, 0x1D, 0x7A, 0x3B,
  26211. 0x70, 0x37, 0x91, 0xB7, 0xE9, 0x92, 0x61, 0x71,
  26212. 0x0F, 0x86, 0xB7, 0x24, 0x21, 0xD2, 0x40, 0xA3,
  26213. 0x47, 0x63, 0x83, 0x77, 0x20, 0x5A, 0x15, 0x2C,
  26214. 0x79, 0x41, 0x30, 0xA4, 0xE0, 0x47, 0x74, 0x2B,
  26215. 0x88, 0x83, 0x03, 0xBD, 0xDC, 0x30, 0x91, 0x16,
  26216. 0x76, 0x4D, 0xE7, 0x42, 0x4C, 0xEB, 0xEA, 0x6D,
  26217. 0xB6, 0x53, 0x48, 0xAC, 0x53, 0x7E, 0x01, 0xA9,
  26218. 0xCC, 0x56, 0xEA, 0x66, 0x7D, 0x5A, 0xA8, 0x7A,
  26219. 0xC9, 0xAA, 0xA4, 0x31, 0x7D, 0x26, 0x2C, 0x10,
  26220. 0x14, 0x30, 0x50, 0xB8, 0xD0, 0x7A, 0x72, 0x8C,
  26221. 0xA6, 0x33, 0xC1, 0x3E, 0x46, 0x8A, 0xBC, 0xEA,
  26222. 0xD3, 0x72, 0xC7, 0x7B, 0x8E, 0xCF, 0x3B, 0x98,
  26223. 0x6B, 0x98, 0xC1, 0xE5, 0x58, 0x60, 0xB2, 0xB4,
  26224. 0x21, 0x67, 0x66, 0xAD, 0x87, 0x4C, 0x35, 0xED,
  26225. 0x72, 0x05, 0x06, 0x87, 0x39, 0x23, 0x02, 0x20,
  26226. 0xB5, 0xA2, 0x31, 0x7D, 0x10, 0x2C, 0x59, 0x83,
  26227. 0x56, 0xF1, 0x68, 0xAC, 0xBE, 0x80, 0x60, 0x8D,
  26228. 0xE4, 0xC9, 0xA7, 0x10, 0xB8, 0xDD, 0x07, 0x07,
  26229. 0x8C, 0xD7, 0xC6, 0x71, 0x05, 0x8A, 0xF1, 0xB0,
  26230. 0xB8, 0x30, 0x4A, 0x31, 0x4F, 0x7B, 0x29, 0xBE,
  26231. 0x78, 0xA9, 0x33, 0xC7, 0xB9, 0x29, 0x44, 0x24,
  26232. 0x95, 0x4A, 0x1B, 0xF8, 0xBC, 0x74, 0x5D, 0xE8,
  26233. 0x61, 0x98, 0x65, 0x9E, 0x0E, 0x12, 0x25, 0xA9,
  26234. 0x10, 0x72, 0x60, 0x74, 0x96, 0x9C, 0x39, 0xA9,
  26235. 0x7C, 0x19, 0x24, 0x06, 0x01, 0xA4, 0x6E, 0x01,
  26236. 0x3D, 0xCD, 0xCB, 0x67, 0x7A, 0x8C, 0xBD, 0x2C,
  26237. 0x95, 0xA4, 0x06, 0x29, 0xC2, 0x56, 0xF2, 0x4A,
  26238. 0x32, 0x89, 0x51, 0xDF, 0x57, 0x50, 0x2A, 0xB3,
  26239. 0x07, 0x72, 0xCC, 0x7E, 0x5B, 0x85, 0x00, 0x27,
  26240. 0xC8, 0x55, 0x17, 0x81, 0xCE, 0x49, 0x85, 0xBD,
  26241. 0xAC, 0xF6, 0xB8, 0x65, 0xC1, 0x04, 0xE8, 0xA4,
  26242. 0xBC, 0x65, 0xC4, 0x16, 0x94, 0xD4, 0x56, 0xB7,
  26243. 0x16, 0x9E, 0x45, 0xAB, 0x3D, 0x7A, 0xCA, 0xBE,
  26244. 0xAF, 0xE2, 0x3A, 0xD6, 0xA7, 0xB9, 0x4D, 0x19,
  26245. 0x79, 0xA2, 0xF4, 0xC1, 0xCA, 0xE7, 0xCD, 0x77,
  26246. 0xD6, 0x81, 0xD2, 0x90, 0xB5, 0xD8, 0xE4, 0x51,
  26247. 0xBF, 0xDC, 0xCC, 0xF5, 0x31, 0x0B, 0x9D, 0x12,
  26248. 0xA8, 0x8E, 0xC2, 0x9B, 0x10, 0x25, 0x5D, 0x5E,
  26249. 0x17, 0xA1, 0x92, 0x67, 0x0A, 0xA9, 0x73, 0x1C,
  26250. 0x5C, 0xA6, 0x7E, 0xC7, 0x84, 0xC5, 0x02, 0x78,
  26251. 0x1B, 0xE8, 0x52, 0x7D, 0x6F, 0xC0, 0x03, 0xC6,
  26252. 0x70, 0x1B, 0x36, 0x32, 0x28, 0x4B, 0x40, 0x30,
  26253. 0x7A, 0x52, 0x7C, 0x76, 0x20, 0x37, 0x7F, 0xEB,
  26254. 0x0B, 0x73, 0xF7, 0x22, 0xC9, 0xE3, 0xCD, 0x4D,
  26255. 0xEC, 0x64, 0x87, 0x6B, 0x93, 0xAB, 0x5B, 0x7C,
  26256. 0xFC, 0x4A, 0x65, 0x7F, 0x85, 0x2B, 0x65, 0x92,
  26257. 0x82, 0x86, 0x43, 0x84, 0xF4, 0x42, 0xB2, 0x2E,
  26258. 0x8A, 0x21, 0x10, 0x93, 0x87, 0xB8, 0xB4, 0x75,
  26259. 0x85, 0xFC, 0x68, 0x0D, 0x0B, 0xA4, 0x5C, 0x7A,
  26260. 0x8B, 0x1D, 0x72, 0x74, 0xBD, 0xA5, 0x78, 0x45,
  26261. 0xD1, 0x00, 0xD0, 0xF4, 0x2A, 0x3B, 0x74, 0x62,
  26262. 0x87, 0x73, 0x35, 0x1F, 0xD7, 0xAC, 0x30, 0x5B,
  26263. 0x24, 0x97, 0x63, 0x9B, 0xE9, 0x0B, 0x3F, 0x4F,
  26264. 0x71, 0xA6, 0xAA, 0x35, 0x61, 0xEE, 0xCC, 0x6A,
  26265. 0x69, 0x1B, 0xB5, 0xCB, 0x39, 0x14, 0xD8, 0x63,
  26266. 0x4C, 0xA1, 0xE1, 0xAF, 0x54, 0x3C, 0x04, 0x9A,
  26267. 0x8C, 0x6E, 0x86, 0x8C, 0x51, 0xF0, 0x42, 0x3B,
  26268. 0xD2, 0xD5, 0xAE, 0x09, 0xB7, 0x9E, 0x57, 0xC2,
  26269. 0x7F, 0x3F, 0xE3, 0xAE, 0x2B, 0x26, 0xA4, 0x41,
  26270. 0xBA, 0xBF, 0xC6, 0x71, 0x8C, 0xE8, 0xC0, 0x5B,
  26271. 0x4F, 0xE7, 0x93, 0xB9, 0x10, 0xB8, 0xFB, 0xCB,
  26272. 0xBE, 0x7F, 0x10, 0x13, 0x24, 0x2B, 0x40, 0xE0,
  26273. 0x51, 0x4D, 0x0B, 0xDC, 0x5C, 0x88, 0xBA, 0xC5,
  26274. 0x94, 0xC7, 0x94, 0xCE, 0x51, 0x22, 0xFB, 0xF3,
  26275. 0x48, 0x96, 0x81, 0x91, 0x47, 0xB9, 0x28, 0x38,
  26276. 0x15, 0x87, 0x96, 0x3B, 0x0B, 0x90, 0x03, 0x4A,
  26277. 0xA0, 0x7A, 0x10, 0xBE, 0x17, 0x6E, 0x01, 0xC8,
  26278. 0x0A, 0xD6, 0xA4, 0xB7, 0x1B, 0x10, 0xAF, 0x42,
  26279. 0x41, 0x40, 0x0A, 0x2A, 0x4C, 0xBB, 0xC0, 0x59,
  26280. 0x61, 0xA1, 0x5E, 0xC1, 0x47, 0x4E, 0xD5, 0x1A,
  26281. 0x3C, 0xC6, 0xD3, 0x58, 0x00, 0x67, 0x9A, 0x46,
  26282. 0x28, 0x09, 0xCA, 0xA3, 0xAB, 0x4F, 0x70, 0x94,
  26283. 0xCD, 0x66, 0x10, 0xB4, 0xA7, 0x00, 0xCB, 0xA9,
  26284. 0x39, 0xE7, 0xEA, 0xC9, 0x3E, 0x38, 0xC9, 0x97,
  26285. 0x55, 0x90, 0x87, 0x27, 0x61, 0x9E, 0xD7, 0x6A,
  26286. 0x34, 0xE5, 0x3C, 0x4F, 0xA2, 0x5B, 0xFC, 0x97,
  26287. 0x00, 0x82, 0x06, 0x69, 0x7D, 0xD1, 0x45, 0xE5,
  26288. 0xB9, 0x18, 0x8E, 0x5B, 0x01, 0x4E, 0x94, 0x16,
  26289. 0x81, 0xE1, 0x5F, 0xE3, 0xE1, 0x32, 0xB8, 0xA3,
  26290. 0x90, 0x34, 0x74, 0x14, 0x8B, 0xA2, 0x8B, 0x98,
  26291. 0x71, 0x11, 0xC9, 0xBC, 0xB3, 0x98, 0x9B, 0xBB,
  26292. 0xC6, 0x71, 0xC5, 0x81, 0xB4, 0x4A, 0x49, 0x28,
  26293. 0x45, 0xF2, 0x88, 0xE6, 0x21, 0x96, 0xE4, 0x71,
  26294. 0xFE, 0xD3, 0xC3, 0x9C, 0x1B, 0xBD, 0xDB, 0x08,
  26295. 0x37, 0xD0, 0xD4, 0x70, 0x6B, 0x09, 0x22, 0xC4
  26296. };
  26297. static const byte seed_768[KYBER_ENC_RAND_SZ] = {
  26298. 0x2C, 0xE7, 0x4A, 0xD2, 0x91, 0x13, 0x35, 0x18,
  26299. 0xFE, 0x60, 0xC7, 0xDF, 0x5D, 0x25, 0x1B, 0x9D,
  26300. 0x82, 0xAD, 0xD4, 0x84, 0x62, 0xFF, 0x50, 0x5C,
  26301. 0x6E, 0x54, 0x7E, 0x94, 0x9E, 0x6B, 0x6B, 0xF7
  26302. };
  26303. static const byte c_768[KYBER768_CIPHER_TEXT_SIZE] = {
  26304. 0x56, 0xB4, 0x2D, 0x59, 0x3A, 0xAB, 0x8E, 0x87,
  26305. 0x73, 0xBD, 0x92, 0xD7, 0x6E, 0xAB, 0xDD, 0xF3,
  26306. 0xB1, 0x54, 0x6F, 0x83, 0x26, 0xF5, 0x7A, 0x7B,
  26307. 0x77, 0x37, 0x64, 0xB6, 0xC0, 0xDD, 0x30, 0x47,
  26308. 0x0F, 0x68, 0xDF, 0xF8, 0x2E, 0x0D, 0xCA, 0x92,
  26309. 0x50, 0x92, 0x74, 0xEC, 0xFE, 0x83, 0xA9, 0x54,
  26310. 0x73, 0x5F, 0xDE, 0x6E, 0x14, 0x67, 0x6D, 0xAA,
  26311. 0xA3, 0x68, 0x0C, 0x30, 0xD5, 0x24, 0xF4, 0xEF,
  26312. 0xA7, 0x9E, 0xD6, 0xA1, 0xF9, 0xED, 0x7E, 0x1C,
  26313. 0x00, 0x56, 0x0E, 0x86, 0x83, 0x53, 0x8C, 0x31,
  26314. 0x05, 0xAB, 0x93, 0x1B, 0xE0, 0xD2, 0xB2, 0x49,
  26315. 0xB3, 0x8C, 0xB9, 0xB1, 0x3A, 0xF5, 0xCE, 0xAF,
  26316. 0x78, 0x87, 0xA5, 0x9D, 0xBA, 0x16, 0x68, 0x8A,
  26317. 0x7F, 0x28, 0xDE, 0x0B, 0x14, 0xD1, 0x9F, 0x39,
  26318. 0x1E, 0xB4, 0x18, 0x32, 0xA5, 0x64, 0x79, 0x41,
  26319. 0x6C, 0xCF, 0x94, 0xE9, 0x97, 0x39, 0x0E, 0xD7,
  26320. 0x87, 0x8E, 0xEA, 0xFF, 0x49, 0x32, 0x8A, 0x70,
  26321. 0xE0, 0xAB, 0x5F, 0xCE, 0x6C, 0x63, 0xC0, 0x9B,
  26322. 0x35, 0xF4, 0xE4, 0x59, 0x94, 0xDE, 0x61, 0x5B,
  26323. 0x88, 0xBB, 0x72, 0x2F, 0x70, 0xE8, 0x7D, 0x2B,
  26324. 0xBD, 0x72, 0xAE, 0x71, 0xE1, 0xEE, 0x90, 0x08,
  26325. 0xE4, 0x59, 0xD8, 0xE7, 0x43, 0x03, 0x9A, 0x8D,
  26326. 0xDE, 0xB8, 0x74, 0xFC, 0xE5, 0x30, 0x1A, 0x2F,
  26327. 0x8C, 0x0E, 0xE8, 0xC2, 0xFE, 0xE7, 0xA4, 0xEE,
  26328. 0x68, 0xB5, 0xED, 0x6A, 0x6D, 0x9A, 0xB7, 0x4F,
  26329. 0x98, 0xBB, 0x3B, 0xA0, 0xFE, 0x89, 0xE8, 0x2B,
  26330. 0xD5, 0xA5, 0x25, 0xC5, 0xE8, 0x79, 0x0F, 0x81,
  26331. 0x8C, 0xCC, 0x60, 0x58, 0x77, 0xD4, 0x6C, 0x8B,
  26332. 0xDB, 0x5C, 0x33, 0x7B, 0x02, 0x5B, 0xB8, 0x40,
  26333. 0xFF, 0x47, 0x18, 0x96, 0xE4, 0x3B, 0xFA, 0x99,
  26334. 0xD7, 0x3D, 0xBE, 0x31, 0x80, 0x5C, 0x27, 0xA4,
  26335. 0x3E, 0x57, 0xF0, 0x61, 0x8B, 0x3A, 0xE5, 0x22,
  26336. 0xA4, 0x64, 0x4E, 0x0D, 0x4E, 0x4C, 0x1C, 0x54,
  26337. 0x84, 0x89, 0x43, 0x1B, 0xE5, 0x58, 0xF3, 0xBF,
  26338. 0xC5, 0x0E, 0x16, 0x61, 0x7E, 0x11, 0x0D, 0xD7,
  26339. 0xAF, 0x9A, 0x6F, 0xD8, 0x3E, 0x3F, 0xBB, 0x68,
  26340. 0xC3, 0x04, 0xD1, 0x5F, 0x6C, 0xB7, 0x00, 0xD6,
  26341. 0x1D, 0x7A, 0xA9, 0x15, 0xA6, 0x75, 0x1E, 0xA3,
  26342. 0xBA, 0x80, 0x22, 0x3E, 0x65, 0x41, 0x32, 0xA2,
  26343. 0x09, 0x99, 0xA4, 0x3B, 0xF4, 0x08, 0x59, 0x27,
  26344. 0x30, 0xB9, 0xA9, 0x49, 0x96, 0x36, 0xC0, 0x9F,
  26345. 0xA7, 0x29, 0xF9, 0xCB, 0x1F, 0x9D, 0x34, 0x42,
  26346. 0xF4, 0x73, 0x57, 0xA2, 0xB9, 0xCF, 0x15, 0xD3,
  26347. 0x10, 0x3B, 0x9B, 0xF3, 0x96, 0xC2, 0x30, 0x88,
  26348. 0xF1, 0x18, 0xED, 0xE3, 0x46, 0xB5, 0xC0, 0x38,
  26349. 0x91, 0xCF, 0xA5, 0xD5, 0x17, 0xCE, 0xF8, 0x47,
  26350. 0x13, 0x22, 0xE7, 0xE3, 0x10, 0x87, 0xC4, 0xB0,
  26351. 0x36, 0xAB, 0xAD, 0x78, 0x4B, 0xFF, 0x72, 0xA9,
  26352. 0xB1, 0x1F, 0xA1, 0x98, 0xFA, 0xCB, 0xCB, 0x91,
  26353. 0xF0, 0x67, 0xFE, 0xAF, 0x76, 0xFC, 0xFE, 0x53,
  26354. 0x27, 0xC1, 0x07, 0x0B, 0x3D, 0xA6, 0x98, 0x84,
  26355. 0x00, 0x75, 0x67, 0x60, 0xD2, 0xD1, 0xF0, 0x60,
  26356. 0x29, 0x8F, 0x16, 0x83, 0xD5, 0x1E, 0x36, 0x16,
  26357. 0xE9, 0x8C, 0x51, 0xC9, 0xC0, 0x3A, 0xA4, 0x2F,
  26358. 0x2E, 0x63, 0x36, 0x51, 0xA4, 0x7A, 0xD3, 0xCC,
  26359. 0x2A, 0xB4, 0xA8, 0x52, 0xAE, 0x0C, 0x4B, 0x04,
  26360. 0xB4, 0xE1, 0xC3, 0xDD, 0x94, 0x44, 0x45, 0xA2,
  26361. 0xB1, 0x2B, 0x4F, 0x42, 0xA6, 0x43, 0x51, 0x05,
  26362. 0xC0, 0x41, 0x22, 0xFC, 0x35, 0x87, 0xAF, 0xE4,
  26363. 0x09, 0xA0, 0x0B, 0x30, 0x8D, 0x63, 0xC5, 0xDD,
  26364. 0x81, 0x63, 0x65, 0x45, 0x04, 0xEE, 0xDB, 0xB7,
  26365. 0xB5, 0x32, 0x95, 0x77, 0xC3, 0x5F, 0xBE, 0xB3,
  26366. 0xF4, 0x63, 0x87, 0x2C, 0xAC, 0x28, 0x14, 0x2B,
  26367. 0x3C, 0x12, 0xA7, 0x40, 0xEC, 0x6E, 0xA7, 0xCE,
  26368. 0x9A, 0xD7, 0x8C, 0x6F, 0xC8, 0xFE, 0x1B, 0x4D,
  26369. 0xF5, 0xFC, 0x55, 0xC1, 0x66, 0x7F, 0x31, 0xF2,
  26370. 0x31, 0x2D, 0xA0, 0x77, 0x99, 0xDC, 0x87, 0x0A,
  26371. 0x47, 0x86, 0x08, 0x54, 0x9F, 0xED, 0xAF, 0xE0,
  26372. 0x21, 0xF1, 0xCF, 0x29, 0x84, 0x18, 0x03, 0x64,
  26373. 0xE9, 0x0A, 0xD9, 0x8D, 0x84, 0x56, 0x52, 0xAA,
  26374. 0x3C, 0xDD, 0x7A, 0x8E, 0xB0, 0x9F, 0x5E, 0x51,
  26375. 0x42, 0x3F, 0xAB, 0x42, 0xA7, 0xB7, 0xBB, 0x4D,
  26376. 0x51, 0x48, 0x64, 0xBE, 0x8D, 0x71, 0x29, 0x7E,
  26377. 0x9C, 0x3B, 0x17, 0xA9, 0x93, 0xF0, 0xAE, 0x62,
  26378. 0xE8, 0xEF, 0x52, 0x63, 0x7B, 0xD1, 0xB8, 0x85,
  26379. 0xBD, 0x9B, 0x6A, 0xB7, 0x27, 0x85, 0x4D, 0x70,
  26380. 0x3D, 0x8D, 0xC4, 0x78, 0xF9, 0x6C, 0xB8, 0x1F,
  26381. 0xCE, 0x4C, 0x60, 0x38, 0x3A, 0xC0, 0x1F, 0xCF,
  26382. 0x0F, 0x97, 0x1D, 0x4C, 0x8F, 0x35, 0x2B, 0x7A,
  26383. 0x82, 0xE2, 0x18, 0x65, 0x2F, 0x2C, 0x10, 0x6C,
  26384. 0xA9, 0x2A, 0xE6, 0x86, 0xBA, 0xCF, 0xCE, 0xF5,
  26385. 0xD3, 0x27, 0x34, 0x7A, 0x97, 0xA9, 0xB3, 0x75,
  26386. 0xD6, 0x73, 0x41, 0x55, 0x2B, 0xC2, 0xC5, 0x38,
  26387. 0x77, 0x8E, 0x0F, 0x98, 0x01, 0x82, 0x3C, 0xCD,
  26388. 0xFC, 0xD1, 0xEA, 0xAD, 0xED, 0x55, 0xB1, 0x8C,
  26389. 0x97, 0x57, 0xE3, 0xF2, 0x12, 0xB2, 0x88, 0x9D,
  26390. 0x38, 0x57, 0xDB, 0x51, 0xF9, 0x81, 0xD1, 0x61,
  26391. 0x85, 0xFD, 0x0F, 0x90, 0x08, 0x53, 0xA7, 0x50,
  26392. 0x05, 0xE3, 0x02, 0x0A, 0x8B, 0x95, 0xB7, 0xD8,
  26393. 0xF2, 0xF2, 0x63, 0x1C, 0x70, 0xD7, 0x8A, 0x95,
  26394. 0x7C, 0x7A, 0x62, 0xE1, 0xB3, 0x71, 0x90, 0x70,
  26395. 0xAC, 0xD1, 0xFD, 0x48, 0x0C, 0x25, 0xB8, 0x38,
  26396. 0x47, 0xDA, 0x02, 0x7B, 0x6E, 0xBB, 0xC2, 0xEE,
  26397. 0xC2, 0xDF, 0x22, 0xC8, 0x7F, 0x9B, 0x46, 0xD5,
  26398. 0xD7, 0xBA, 0xF1, 0x56, 0xB5, 0x3C, 0xEE, 0x92,
  26399. 0x95, 0x72, 0xB9, 0x2C, 0x47, 0x84, 0xC4, 0xE8,
  26400. 0x29, 0xF3, 0x44, 0x6A, 0x1F, 0xFE, 0x47, 0xF9,
  26401. 0x9D, 0xEC, 0xD0, 0x43, 0x60, 0x29, 0xDD, 0xEB,
  26402. 0xD3, 0xED, 0x8E, 0x87, 0xE5, 0xE7, 0x3D, 0x12,
  26403. 0x3D, 0xBE, 0x8A, 0x4D, 0xDA, 0xCF, 0x2A, 0xBD,
  26404. 0xE8, 0x7F, 0x33, 0xAE, 0x2B, 0x62, 0x1C, 0x0E,
  26405. 0xC5, 0xD5, 0xCA, 0xD1, 0x25, 0x9D, 0xEE, 0xC2,
  26406. 0xAE, 0xFF, 0x60, 0x88, 0xF0, 0x4F, 0x27, 0xA2,
  26407. 0x03, 0x38, 0xB5, 0x76, 0x25, 0x43, 0xE5, 0x10,
  26408. 0x08, 0x99, 0xA4, 0xCB, 0xFB, 0x7B, 0x3C, 0xA4,
  26409. 0x56, 0xB3, 0xA1, 0x9B, 0x83, 0xA4, 0xC4, 0x32,
  26410. 0x23, 0x0C, 0x23, 0xE1, 0xC7, 0xF1, 0x07, 0xC4,
  26411. 0xCB, 0x11, 0x21, 0x52, 0xF1, 0xC0, 0xF3, 0x0D,
  26412. 0xA0, 0xBB, 0x33, 0xF4, 0xF1, 0x1F, 0x47, 0xEE,
  26413. 0xA4, 0x38, 0x72, 0xBA, 0xFA, 0x84, 0xAE, 0x22,
  26414. 0x25, 0x6D, 0x70, 0x8E, 0x06, 0x04, 0xDA, 0xDE,
  26415. 0x4B, 0x2A, 0x4D, 0xDE, 0x8C, 0xCC, 0xF1, 0x19,
  26416. 0x30, 0xE1, 0x35, 0x53, 0x93, 0x4A, 0xE3, 0xEC,
  26417. 0xE5, 0x2F, 0x3D, 0x7C, 0xCC, 0x00, 0x28, 0x73,
  26418. 0x77, 0x87, 0x9F, 0xE6, 0xB8, 0xEC, 0xE7, 0xEF,
  26419. 0x79, 0x42, 0x35, 0x07, 0xC9, 0xDA, 0x33, 0x95,
  26420. 0x59, 0xC2, 0x0D, 0xE1, 0xC5, 0x19, 0x55, 0x99,
  26421. 0x9B, 0xAE, 0x47, 0x40, 0x1D, 0xC3, 0xCD, 0xFA,
  26422. 0xA1, 0xB2, 0x56, 0xD0, 0x9C, 0x7D, 0xB9, 0xFC,
  26423. 0x86, 0x98, 0xBF, 0xCE, 0xFA, 0x73, 0x02, 0xD5,
  26424. 0x6F, 0xBC, 0xDE, 0x1F, 0xBA, 0xAA, 0x1C, 0x65,
  26425. 0x34, 0x54, 0xE6, 0xFD, 0x3D, 0x84, 0xE4, 0xF7,
  26426. 0x9A, 0x93, 0x1C, 0x68, 0x1C, 0xBB, 0x6C, 0xB4,
  26427. 0x62, 0xB1, 0x0D, 0xAE, 0x11, 0x2B, 0xDF, 0xB7,
  26428. 0xF6, 0x5C, 0x7F, 0xDF, 0x6E, 0x5F, 0xC5, 0x94,
  26429. 0xEC, 0x3A, 0x47, 0x4A, 0x94, 0xBD, 0x97, 0xE6,
  26430. 0xEC, 0x81, 0xF7, 0x1C, 0x23, 0x0B, 0xF7, 0x0C,
  26431. 0xA0, 0xF1, 0x3C, 0xE3, 0xDF, 0xFB, 0xD9, 0xFF,
  26432. 0x98, 0x04, 0xEF, 0xD8, 0xF3, 0x7A, 0x4D, 0x36,
  26433. 0x29, 0xB4, 0x3A, 0x8F, 0x55, 0x54, 0x4E, 0xBC,
  26434. 0x5A, 0xC0, 0xAB, 0xD9, 0xA3, 0x3D, 0x79, 0x69,
  26435. 0x90, 0x68, 0x34, 0x6A, 0x0F, 0x1A, 0x3A, 0x96,
  26436. 0xE1, 0x15, 0xA5, 0xD8, 0x0B, 0xE1, 0x65, 0xB5,
  26437. 0x62, 0xD0, 0x82, 0x98, 0x4D, 0x5A, 0xAC, 0xC3,
  26438. 0xA2, 0x30, 0x19, 0x81, 0xA6, 0x41, 0x8F, 0x8B,
  26439. 0xA7, 0xD7, 0xB0, 0xD7, 0xCA, 0x58, 0x75, 0xC6
  26440. };
  26441. static const byte k_768[KYBER_SS_SZ] = {
  26442. 0x26, 0x96, 0xD2, 0x8E, 0x9C, 0x61, 0xC2, 0xA0,
  26443. 0x1C, 0xE9, 0xB1, 0x60, 0x8D, 0xCB, 0x9D, 0x29,
  26444. 0x27, 0x85, 0xA0, 0xCD, 0x58, 0xEF, 0xB7, 0xFE,
  26445. 0x13, 0xB1, 0xDE, 0x95, 0xF0, 0xDB, 0x55, 0xB3
  26446. };
  26447. #endif
  26448. #ifndef WOLFSSL_NO_KYBER1024
  26449. static const byte ek_1024[KYBER1024_PUBLIC_KEY_SIZE] = {
  26450. 0x30, 0x7A, 0x4C, 0xEA, 0x41, 0x48, 0x21, 0x9B,
  26451. 0x95, 0x8E, 0xA0, 0xB7, 0x88, 0x66, 0x59, 0x23,
  26452. 0x5A, 0x4D, 0x19, 0x80, 0xB1, 0x92, 0x61, 0x08,
  26453. 0x47, 0xD8, 0x6E, 0xF3, 0x27, 0x39, 0xF9, 0x4C,
  26454. 0x3B, 0x44, 0x6C, 0x4D, 0x81, 0xD8, 0x9B, 0x8B,
  26455. 0x42, 0x2A, 0x9D, 0x07, 0x9C, 0x88, 0xB1, 0x1A,
  26456. 0xCA, 0xF3, 0x21, 0xB0, 0x14, 0x29, 0x4E, 0x18,
  26457. 0xB2, 0x96, 0xE5, 0x2F, 0x3F, 0x74, 0x4C, 0xF9,
  26458. 0x63, 0x4A, 0x4F, 0xB0, 0x1D, 0xB0, 0xD9, 0x9E,
  26459. 0xF2, 0x0A, 0x63, 0x3A, 0x55, 0x2E, 0x76, 0xA0,
  26460. 0x58, 0x5C, 0x61, 0x09, 0xF0, 0x18, 0x76, 0x8B,
  26461. 0x76, 0x3A, 0xF3, 0x67, 0x8B, 0x47, 0x80, 0x08,
  26462. 0x9C, 0x13, 0x42, 0xB9, 0x69, 0x07, 0xA2, 0x9A,
  26463. 0x1C, 0x11, 0x52, 0x1C, 0x74, 0x4C, 0x27, 0x97,
  26464. 0xD0, 0xBF, 0x2B, 0x9C, 0xCD, 0xCA, 0x61, 0x46,
  26465. 0x72, 0xB4, 0x50, 0x76, 0x77, 0x3F, 0x45, 0x8A,
  26466. 0x31, 0xEF, 0x86, 0x9B, 0xE1, 0xEB, 0x2E, 0xFE,
  26467. 0xB5, 0x0D, 0x0E, 0x37, 0x49, 0x5D, 0xC5, 0xCA,
  26468. 0x55, 0xE0, 0x75, 0x28, 0x93, 0x4F, 0x62, 0x93,
  26469. 0xC4, 0x16, 0x80, 0x27, 0xD0, 0xE5, 0x3D, 0x07,
  26470. 0xFA, 0xCC, 0x66, 0x30, 0xCB, 0x08, 0x19, 0x7E,
  26471. 0x53, 0xFB, 0x19, 0x3A, 0x17, 0x11, 0x35, 0xDC,
  26472. 0x8A, 0xD9, 0x97, 0x94, 0x02, 0xA7, 0x1B, 0x69,
  26473. 0x26, 0xBC, 0xDC, 0xDC, 0x47, 0xB9, 0x34, 0x01,
  26474. 0x91, 0x0A, 0x5F, 0xCC, 0x1A, 0x81, 0x3B, 0x68,
  26475. 0x2B, 0x09, 0xBA, 0x7A, 0x72, 0xD2, 0x48, 0x6D,
  26476. 0x6C, 0x79, 0x95, 0x16, 0x46, 0x5C, 0x14, 0x72,
  26477. 0x9B, 0x26, 0x94, 0x9B, 0x0B, 0x7C, 0xBC, 0x7C,
  26478. 0x64, 0x0F, 0x26, 0x7F, 0xED, 0x80, 0xB1, 0x62,
  26479. 0xC5, 0x1F, 0xD8, 0xE0, 0x92, 0x27, 0xC1, 0x01,
  26480. 0xD5, 0x05, 0xA8, 0xFA, 0xE8, 0xA2, 0xD7, 0x05,
  26481. 0x4E, 0x28, 0xA7, 0x8B, 0xA8, 0x75, 0x0D, 0xEC,
  26482. 0xF9, 0x05, 0x7C, 0x83, 0x97, 0x9F, 0x7A, 0xBB,
  26483. 0x08, 0x49, 0x45, 0x64, 0x80, 0x06, 0xC5, 0xB2,
  26484. 0x88, 0x04, 0xF3, 0x4E, 0x73, 0xB2, 0x38, 0x11,
  26485. 0x1A, 0x65, 0xA1, 0xF5, 0x00, 0xB1, 0xCC, 0x60,
  26486. 0x6A, 0x84, 0x8F, 0x28, 0x59, 0x07, 0x0B, 0xEB,
  26487. 0xA7, 0x57, 0x31, 0x79, 0xF3, 0x61, 0x49, 0xCF,
  26488. 0x58, 0x01, 0xBF, 0x89, 0xA1, 0xC3, 0x8C, 0xC2,
  26489. 0x78, 0x41, 0x55, 0x28, 0xD0, 0x3B, 0xDB, 0x94,
  26490. 0x3F, 0x96, 0x28, 0x0C, 0x8C, 0xC5, 0x20, 0x42,
  26491. 0xD9, 0xB9, 0x1F, 0xAA, 0x9D, 0x6E, 0xA7, 0xBC,
  26492. 0xBB, 0x7A, 0xB1, 0x89, 0x7A, 0x32, 0x66, 0x96,
  26493. 0x6F, 0x78, 0x39, 0x34, 0x26, 0xC7, 0x6D, 0x8A,
  26494. 0x49, 0x57, 0x8B, 0x98, 0xB1, 0x59, 0xEB, 0xB4,
  26495. 0x6E, 0xE0, 0xA8, 0x83, 0xA2, 0x70, 0xD8, 0x05,
  26496. 0x7C, 0xD0, 0x23, 0x1C, 0x86, 0x90, 0x6A, 0x91,
  26497. 0xDB, 0xBA, 0xDE, 0x6B, 0x24, 0x69, 0x58, 0x1E,
  26498. 0x2B, 0xCA, 0x2F, 0xEA, 0x83, 0x89, 0xF7, 0xC7,
  26499. 0x4B, 0xCD, 0x70, 0x96, 0x1E, 0xA5, 0xB9, 0x34,
  26500. 0xFB, 0xCF, 0x9A, 0x65, 0x90, 0xBF, 0x86, 0xB8,
  26501. 0xDB, 0x54, 0x88, 0x54, 0xD9, 0xA3, 0xFB, 0x30,
  26502. 0x11, 0x04, 0x33, 0xBD, 0x7A, 0x1B, 0x65, 0x9C,
  26503. 0xA8, 0x56, 0x80, 0x85, 0x63, 0x92, 0x37, 0xB3,
  26504. 0xBD, 0xC3, 0x7B, 0x7F, 0xA7, 0x16, 0xD4, 0x82,
  26505. 0xA2, 0x5B, 0x54, 0x10, 0x6B, 0x3A, 0x8F, 0x54,
  26506. 0xD3, 0xAA, 0x99, 0xB5, 0x12, 0x3D, 0xA9, 0x60,
  26507. 0x66, 0x90, 0x45, 0x92, 0xF3, 0xA5, 0x4E, 0xE2,
  26508. 0x3A, 0x79, 0x81, 0xAB, 0x60, 0x8A, 0x2F, 0x44,
  26509. 0x13, 0xCC, 0x65, 0x89, 0x46, 0xC6, 0xD7, 0x78,
  26510. 0x0E, 0xA7, 0x65, 0x64, 0x4B, 0x3C, 0xC0, 0x6C,
  26511. 0x70, 0x03, 0x4A, 0xB4, 0xEB, 0x35, 0x19, 0x12,
  26512. 0xE7, 0x71, 0x5B, 0x56, 0x75, 0x5D, 0x09, 0x02,
  26513. 0x15, 0x71, 0xBF, 0x34, 0x0A, 0xB9, 0x25, 0x98,
  26514. 0xA2, 0x4E, 0x81, 0x18, 0x93, 0x19, 0x5B, 0x96,
  26515. 0xA1, 0x62, 0x9F, 0x80, 0x41, 0xF5, 0x86, 0x58,
  26516. 0x43, 0x15, 0x61, 0xFC, 0x0A, 0xB1, 0x52, 0x92,
  26517. 0xB9, 0x13, 0xEC, 0x47, 0x3F, 0x04, 0x47, 0x9B,
  26518. 0xC1, 0x45, 0xCD, 0x4C, 0x56, 0x3A, 0x28, 0x62,
  26519. 0x35, 0x64, 0x6C, 0xD3, 0x05, 0xA9, 0xBE, 0x10,
  26520. 0x14, 0xE2, 0xC7, 0xB1, 0x30, 0xC3, 0x3E, 0xB7,
  26521. 0x7C, 0xC4, 0xA0, 0xD9, 0x78, 0x6B, 0xD6, 0xBC,
  26522. 0x2A, 0x95, 0x4B, 0xF3, 0x00, 0x57, 0x78, 0xF8,
  26523. 0x91, 0x7C, 0xE1, 0x37, 0x89, 0xBB, 0xB9, 0x62,
  26524. 0x80, 0x78, 0x58, 0xB6, 0x77, 0x31, 0x57, 0x2B,
  26525. 0x6D, 0x3C, 0x9B, 0x4B, 0x52, 0x06, 0xFA, 0xC9,
  26526. 0xA7, 0xC8, 0x96, 0x16, 0x98, 0xD8, 0x83, 0x24,
  26527. 0xA9, 0x15, 0x18, 0x68, 0x99, 0xB2, 0x99, 0x23,
  26528. 0xF0, 0x84, 0x42, 0xA3, 0xD3, 0x86, 0xBD, 0x41,
  26529. 0x6B, 0xCC, 0x9A, 0x10, 0x01, 0x64, 0xC9, 0x30,
  26530. 0xEC, 0x35, 0xEA, 0xFB, 0x6A, 0xB3, 0x58, 0x51,
  26531. 0xB6, 0xC8, 0xCE, 0x63, 0x77, 0x36, 0x6A, 0x17,
  26532. 0x5F, 0x3D, 0x75, 0x29, 0x8C, 0x51, 0x8D, 0x44,
  26533. 0x89, 0x89, 0x33, 0xF5, 0x3D, 0xEE, 0x61, 0x71,
  26534. 0x45, 0x09, 0x33, 0x79, 0xC4, 0x65, 0x9F, 0x68,
  26535. 0x58, 0x3B, 0x2B, 0x28, 0x12, 0x26, 0x66, 0xBE,
  26536. 0xC5, 0x78, 0x38, 0x99, 0x1F, 0xF1, 0x6C, 0x36,
  26537. 0x8D, 0xD2, 0x2C, 0x36, 0xE7, 0x80, 0xC9, 0x1A,
  26538. 0x35, 0x82, 0xE2, 0x5E, 0x19, 0x79, 0x4C, 0x6B,
  26539. 0xF2, 0xAB, 0x42, 0x45, 0x8A, 0x8D, 0xD7, 0x70,
  26540. 0x5D, 0xE2, 0xC2, 0xAA, 0x20, 0xC0, 0x54, 0xE8,
  26541. 0x4B, 0x3E, 0xF3, 0x50, 0x32, 0x79, 0x86, 0x26,
  26542. 0xC2, 0x48, 0x26, 0x32, 0x53, 0xA7, 0x1A, 0x11,
  26543. 0x94, 0x35, 0x71, 0x34, 0x0A, 0x97, 0x8C, 0xD0,
  26544. 0xA6, 0x02, 0xE4, 0x7D, 0xEE, 0x54, 0x0A, 0x88,
  26545. 0x14, 0xBA, 0x06, 0xF3, 0x14, 0x14, 0x79, 0x7C,
  26546. 0xDF, 0x60, 0x49, 0x58, 0x23, 0x61, 0xBB, 0xAB,
  26547. 0xA3, 0x87, 0xA8, 0x3D, 0x89, 0x91, 0x3F, 0xE4,
  26548. 0xC0, 0xC1, 0x12, 0xB9, 0x56, 0x21, 0xA4, 0xBD,
  26549. 0xA8, 0x12, 0x3A, 0x14, 0xD1, 0xA8, 0x42, 0xFB,
  26550. 0x57, 0xB8, 0x3A, 0x4F, 0xBA, 0xF3, 0x3A, 0x8E,
  26551. 0x55, 0x22, 0x38, 0xA5, 0x96, 0xAA, 0xE7, 0xA1,
  26552. 0x50, 0xD7, 0x5D, 0xA6, 0x48, 0xBC, 0x44, 0x64,
  26553. 0x49, 0x77, 0xBA, 0x1F, 0x87, 0xA4, 0xC6, 0x8A,
  26554. 0x8C, 0x4B, 0xD2, 0x45, 0xB7, 0xD0, 0x07, 0x21,
  26555. 0xF7, 0xD6, 0x4E, 0x82, 0x2B, 0x08, 0x5B, 0x90,
  26556. 0x13, 0x12, 0xEC, 0x37, 0xA8, 0x16, 0x98, 0x02,
  26557. 0x16, 0x0C, 0xCE, 0x11, 0x60, 0xF0, 0x10, 0xBE,
  26558. 0x8C, 0xBC, 0xAC, 0xE8, 0xE7, 0xB0, 0x05, 0xD7,
  26559. 0x83, 0x92, 0x34, 0xA7, 0x07, 0x86, 0x83, 0x09,
  26560. 0xD0, 0x37, 0x84, 0xB4, 0x27, 0x3B, 0x1C, 0x8A,
  26561. 0x16, 0x01, 0x33, 0xED, 0x29, 0x81, 0x84, 0x70,
  26562. 0x46, 0x25, 0xF2, 0x9C, 0xFA, 0x08, 0x6D, 0x13,
  26563. 0x26, 0x3E, 0xE5, 0x89, 0x91, 0x23, 0xC5, 0x96,
  26564. 0xBA, 0x78, 0x8E, 0x5C, 0x54, 0xA8, 0xE9, 0xBA,
  26565. 0x82, 0x9B, 0x8A, 0x9D, 0x90, 0x4B, 0xC4, 0xBC,
  26566. 0x0B, 0xBE, 0xA7, 0x6B, 0xC5, 0x3F, 0xF8, 0x11,
  26567. 0x21, 0x45, 0x98, 0x47, 0x2C, 0x9C, 0x20, 0x2B,
  26568. 0x73, 0xEF, 0xF0, 0x35, 0xDC, 0x09, 0x70, 0x3A,
  26569. 0xF7, 0xBF, 0x1B, 0xAB, 0xAA, 0xC7, 0x31, 0x93,
  26570. 0xCB, 0x46, 0x11, 0x7A, 0x7C, 0x94, 0x92, 0xA4,
  26571. 0x3F, 0xC9, 0x57, 0x89, 0xA9, 0x24, 0xC5, 0x91,
  26572. 0x27, 0x87, 0xB2, 0xE2, 0x09, 0x0E, 0xBB, 0xCF,
  26573. 0xD3, 0x79, 0x62, 0x21, 0xF0, 0x6D, 0xEB, 0xF9,
  26574. 0xCF, 0x70, 0xE0, 0x56, 0xB8, 0xB9, 0x16, 0x1D,
  26575. 0x63, 0x47, 0xF4, 0x73, 0x35, 0xF3, 0xE1, 0x77,
  26576. 0x6D, 0xA4, 0xBB, 0x87, 0xC1, 0x5C, 0xC8, 0x26,
  26577. 0x14, 0x6F, 0xF0, 0x24, 0x9A, 0x41, 0x3B, 0x45,
  26578. 0xAA, 0x93, 0xA8, 0x05, 0x19, 0x6E, 0xA4, 0x53,
  26579. 0x11, 0x4B, 0x52, 0x4E, 0x31, 0x0A, 0xED, 0xAA,
  26580. 0x46, 0xE3, 0xB9, 0x96, 0x42, 0x36, 0x87, 0x82,
  26581. 0x56, 0x6D, 0x04, 0x9A, 0x72, 0x6D, 0x6C, 0xCA,
  26582. 0x91, 0x09, 0x93, 0xAE, 0xD6, 0x21, 0xD0, 0x14,
  26583. 0x9E, 0xA5, 0x88, 0xA9, 0xAB, 0xD9, 0x09, 0xDB,
  26584. 0xB6, 0x9A, 0xA2, 0x28, 0x29, 0xD9, 0xB8, 0x3A,
  26585. 0xDA, 0x22, 0x09, 0xA6, 0xC2, 0x65, 0x9F, 0x21,
  26586. 0x69, 0xD6, 0x68, 0xB9, 0x31, 0x48, 0x42, 0xC6,
  26587. 0xE2, 0x2A, 0x74, 0x95, 0x8B, 0x4C, 0x25, 0xBB,
  26588. 0xDC, 0xD2, 0x93, 0xD9, 0x9C, 0xB6, 0x09, 0xD8,
  26589. 0x66, 0x74, 0x9A, 0x48, 0x5D, 0xFB, 0x56, 0x02,
  26590. 0x48, 0x83, 0xCF, 0x54, 0x65, 0xDB, 0xA0, 0x36,
  26591. 0x32, 0x06, 0x58, 0x7F, 0x45, 0x59, 0x7F, 0x89,
  26592. 0x00, 0x2F, 0xB8, 0x60, 0x72, 0x32, 0x13, 0x8E,
  26593. 0x03, 0xB2, 0xA8, 0x94, 0x52, 0x5F, 0x26, 0x53,
  26594. 0x70, 0x05, 0x4B, 0x48, 0x86, 0x36, 0x14, 0x47,
  26595. 0x2B, 0x95, 0xD0, 0xA2, 0x30, 0x34, 0x42, 0xE3,
  26596. 0x78, 0xB0, 0xDD, 0x1C, 0x75, 0xAC, 0xBA, 0xB9,
  26597. 0x71, 0xA9, 0xA8, 0xD1, 0x28, 0x1C, 0x79, 0x61,
  26598. 0x3A, 0xCE, 0xC6, 0x93, 0x3C, 0x37, 0x7B, 0x3C,
  26599. 0x57, 0x8C, 0x2A, 0x61, 0xA1, 0xEC, 0x18, 0x1B,
  26600. 0x10, 0x12, 0x97, 0xA3, 0x7C, 0xC5, 0x19, 0x7B,
  26601. 0x29, 0x42, 0xF6, 0xA0, 0xE4, 0x70, 0x4C, 0x0E,
  26602. 0xC6, 0x35, 0x40, 0x48, 0x1B, 0x9F, 0x15, 0x9D,
  26603. 0xC2, 0x55, 0xB5, 0x9B, 0xB5, 0x5D, 0xF4, 0x96,
  26604. 0xAE, 0x54, 0x21, 0x7B, 0x76, 0x89, 0xBD, 0x51,
  26605. 0xDB, 0xA0, 0x38, 0x3A, 0x3D, 0x72, 0xD8, 0x52,
  26606. 0xFF, 0xCA, 0x76, 0xDF, 0x05, 0xB6, 0x6E, 0xEC,
  26607. 0xCB, 0xD4, 0x7B, 0xC5, 0x30, 0x40, 0x81, 0x76,
  26608. 0x28, 0xC7, 0x1E, 0x36, 0x1D, 0x6A, 0xF8, 0x89,
  26609. 0x08, 0x49, 0x16, 0xB4, 0x08, 0xA4, 0x66, 0xC9,
  26610. 0x6E, 0x70, 0x86, 0xC4, 0xA6, 0x0A, 0x10, 0xFC,
  26611. 0xF7, 0x53, 0x7B, 0xB9, 0x4A, 0xFB, 0xCC, 0x7D,
  26612. 0x43, 0x75, 0x90, 0x91, 0x9C, 0x28, 0x65, 0x0C,
  26613. 0x4F, 0x23, 0x68, 0x25, 0x92, 0x26, 0xA9, 0xBF,
  26614. 0xDA, 0x3A, 0x3A, 0x0B, 0xA1, 0xB5, 0x08, 0x7D,
  26615. 0x9D, 0x76, 0x44, 0x2F, 0xD7, 0x86, 0xC6, 0xF8,
  26616. 0x1C, 0x68, 0xC0, 0x36, 0x0D, 0x71, 0x94, 0xD7,
  26617. 0x07, 0x2C, 0x45, 0x33, 0xAE, 0xA8, 0x6C, 0x2D,
  26618. 0x1F, 0x8C, 0x0A, 0x27, 0x69, 0x60, 0x66, 0xF6,
  26619. 0xCF, 0xD1, 0x10, 0x03, 0xF7, 0x97, 0x27, 0x0B,
  26620. 0x32, 0x38, 0x97, 0x13, 0xCF, 0xFA, 0x09, 0x3D,
  26621. 0x99, 0x1B, 0x63, 0x84, 0x4C, 0x38, 0x5E, 0x72,
  26622. 0x27, 0x7F, 0x16, 0x6F, 0x5A, 0x39, 0x34, 0xD6,
  26623. 0xBB, 0x89, 0xA4, 0x78, 0x8D, 0xE2, 0x83, 0x21,
  26624. 0xDE, 0xFC, 0x74, 0x57, 0xAB, 0x48, 0x4B, 0xD3,
  26625. 0x09, 0x86, 0xDC, 0x1D, 0xAB, 0x30, 0x08, 0xCD,
  26626. 0x7B, 0x22, 0xF6, 0x97, 0x02, 0xFA, 0xBB, 0x9A,
  26627. 0x10, 0x45, 0x40, 0x7D, 0xA4, 0x79, 0x1C, 0x35,
  26628. 0x90, 0xFF, 0x59, 0x9D, 0x81, 0xD6, 0x88, 0xCF,
  26629. 0xA7, 0xCC, 0x12, 0xA6, 0x8C, 0x50, 0xF5, 0x1A,
  26630. 0x10, 0x09, 0x41, 0x1B, 0x44, 0x85, 0x0F, 0x90,
  26631. 0x15, 0xDC, 0x84, 0xA9, 0x3B, 0x17, 0xC7, 0xA2,
  26632. 0x07, 0x55, 0x2C, 0x66, 0x1E, 0xA9, 0x83, 0x8E,
  26633. 0x31, 0xB9, 0x5E, 0xAD, 0x54, 0x62, 0x48, 0xE5,
  26634. 0x6B, 0xE7, 0xA5, 0x13, 0x05, 0x05, 0x26, 0x87,
  26635. 0x71, 0x19, 0x98, 0x80, 0xA1, 0x41, 0x77, 0x1A,
  26636. 0x9E, 0x47, 0xAC, 0xFE, 0xD5, 0x90, 0xCB, 0x3A,
  26637. 0xA7, 0xCB, 0x7C, 0x5F, 0x74, 0x91, 0x1D, 0x89,
  26638. 0x12, 0xC2, 0x9D, 0x62, 0x33, 0xF4, 0xD5, 0x3B,
  26639. 0xC6, 0x41, 0x39, 0xE2, 0xF5, 0x5B, 0xE7, 0x55,
  26640. 0x07, 0xDD, 0x77, 0x86, 0x8E, 0x38, 0x4A, 0xEC,
  26641. 0x58, 0x1F, 0x3F, 0x41, 0x1D, 0xB1, 0xA7, 0x42,
  26642. 0x97, 0x2D, 0x3E, 0xBF, 0xD3, 0x31, 0x5C, 0x84,
  26643. 0xA5, 0xAD, 0x63, 0xA0, 0xE7, 0x5C, 0x8B, 0xCA,
  26644. 0x3E, 0x30, 0x41, 0xE0, 0x5D, 0x90, 0x67, 0xAF,
  26645. 0xF3, 0xB1, 0x24, 0x4F, 0x76, 0x3E, 0x79, 0x83
  26646. };
  26647. static const byte seed_1024[KYBER_ENC_RAND_SZ] = {
  26648. 0x59, 0xC5, 0x15, 0x4C, 0x04, 0xAE, 0x43, 0xAA,
  26649. 0xFF, 0x32, 0x70, 0x0F, 0x08, 0x17, 0x00, 0x38,
  26650. 0x9D, 0x54, 0xBE, 0xC4, 0xC3, 0x7C, 0x08, 0x8B,
  26651. 0x1C, 0x53, 0xF6, 0x62, 0x12, 0xB1, 0x2C, 0x72
  26652. };
  26653. static const byte c_1024[KYBER1024_CIPHER_TEXT_SIZE] = {
  26654. 0xE2, 0xD5, 0xFD, 0x4C, 0x13, 0xCE, 0xA0, 0xB5,
  26655. 0x2D, 0x87, 0x4F, 0xEA, 0x90, 0x12, 0xF3, 0xA5,
  26656. 0x17, 0x43, 0xA1, 0x09, 0x37, 0x10, 0xBB, 0xF2,
  26657. 0x39, 0x50, 0xF9, 0x14, 0x7A, 0x47, 0x2E, 0xE5,
  26658. 0x53, 0x39, 0x28, 0xA2, 0xF4, 0x6D, 0x59, 0x2F,
  26659. 0x35, 0xDA, 0x8B, 0x4F, 0x75, 0x8C, 0x89, 0x3B,
  26660. 0x0D, 0x7B, 0x98, 0x94, 0x8B, 0xE4, 0x47, 0xB1,
  26661. 0x7C, 0xB2, 0xAE, 0x58, 0xAF, 0x8A, 0x48, 0x9D,
  26662. 0xDD, 0x92, 0x32, 0xB9, 0x9B, 0x1C, 0x0D, 0x2D,
  26663. 0xE7, 0x7C, 0xAA, 0x47, 0x2B, 0xC3, 0xBB, 0xD4,
  26664. 0xA7, 0xC6, 0x0D, 0xBF, 0xDC, 0xA9, 0x2E, 0xBF,
  26665. 0x3A, 0x1C, 0xE1, 0xC2, 0x2D, 0xAD, 0x13, 0xE8,
  26666. 0x87, 0x00, 0x4E, 0x29, 0x24, 0xFD, 0x22, 0x65,
  26667. 0x6F, 0x5E, 0x50, 0x87, 0x91, 0xDE, 0x06, 0xD8,
  26668. 0x5E, 0x1A, 0x14, 0x26, 0x80, 0x8E, 0xD9, 0xA8,
  26669. 0x9F, 0x6E, 0x2F, 0xD3, 0xC2, 0x45, 0xD4, 0x75,
  26670. 0x8B, 0x22, 0xB0, 0x2C, 0xAD, 0xE3, 0x3B, 0x60,
  26671. 0xFC, 0x88, 0x9A, 0x33, 0xFC, 0x44, 0x47, 0xED,
  26672. 0xEB, 0xBF, 0xD4, 0x53, 0x0D, 0xE8, 0x65, 0x96,
  26673. 0xA3, 0x37, 0x89, 0xD5, 0xDB, 0xA6, 0xE6, 0xEC,
  26674. 0x9F, 0x89, 0x87, 0x9A, 0xF4, 0xBE, 0x49, 0x09,
  26675. 0xA6, 0x90, 0x17, 0xC9, 0xBB, 0x7A, 0x5E, 0x31,
  26676. 0x81, 0x5E, 0xA5, 0xF1, 0x32, 0xEE, 0xC4, 0x98,
  26677. 0x4F, 0xAA, 0x7C, 0xCF, 0x59, 0x4D, 0xD0, 0x0D,
  26678. 0x4D, 0x84, 0x87, 0xE4, 0x56, 0x21, 0xAF, 0x8F,
  26679. 0x6E, 0x33, 0x05, 0x51, 0x43, 0x9C, 0x93, 0xEC,
  26680. 0x07, 0x8A, 0x7A, 0x3C, 0xC1, 0x59, 0x4A, 0xF9,
  26681. 0x1F, 0x84, 0x17, 0x37, 0x5F, 0xD6, 0x08, 0x8C,
  26682. 0xEB, 0x5E, 0x85, 0xC6, 0x70, 0x99, 0x09, 0x1B,
  26683. 0xAC, 0x11, 0x49, 0x8A, 0x0D, 0x71, 0x14, 0x55,
  26684. 0xF5, 0xE0, 0xD9, 0x5C, 0xD7, 0xBB, 0xE5, 0xCD,
  26685. 0xD8, 0xFE, 0xCB, 0x31, 0x9E, 0x68, 0x53, 0xC2,
  26686. 0x3C, 0x9B, 0xE2, 0xC7, 0x63, 0xDF, 0x57, 0x86,
  26687. 0x66, 0xC4, 0x0A, 0x40, 0xA8, 0x74, 0x86, 0xE4,
  26688. 0x6B, 0xA8, 0x71, 0x61, 0x46, 0x19, 0x29, 0x04,
  26689. 0x51, 0x0A, 0x6D, 0xC5, 0x9D, 0xA8, 0x02, 0x58,
  26690. 0x25, 0x28, 0x3D, 0x68, 0x4D, 0xB9, 0x14, 0x10,
  26691. 0xB4, 0xF1, 0x2C, 0x6D, 0x8F, 0xBD, 0x0A, 0xDD,
  26692. 0x75, 0xD3, 0x09, 0x89, 0x18, 0xCB, 0x04, 0xAC,
  26693. 0x7B, 0xC4, 0xDB, 0x0D, 0x6B, 0xCD, 0xF1, 0x19,
  26694. 0x4D, 0xD8, 0x62, 0x92, 0xE0, 0x5B, 0x7B, 0x86,
  26695. 0x30, 0x62, 0x5B, 0x58, 0x9C, 0xC5, 0x09, 0xD2,
  26696. 0x15, 0xBB, 0xD0, 0x6A, 0x2E, 0x7C, 0x66, 0xF4,
  26697. 0x24, 0xCD, 0xF8, 0xC4, 0x0A, 0xC6, 0xC1, 0xE5,
  26698. 0xAE, 0x6C, 0x96, 0x4B, 0x7D, 0x9E, 0x92, 0xF9,
  26699. 0x5F, 0xC5, 0xC8, 0x85, 0x22, 0x81, 0x62, 0x8B,
  26700. 0x81, 0xB9, 0xAF, 0xAB, 0xC7, 0xF0, 0x3B, 0xE3,
  26701. 0xF6, 0x2E, 0x80, 0x47, 0xBB, 0x88, 0xD0, 0x1C,
  26702. 0x68, 0x68, 0x7B, 0x8D, 0xD4, 0xFE, 0x63, 0x82,
  26703. 0x00, 0x62, 0xB6, 0x78, 0x8A, 0x53, 0x72, 0x90,
  26704. 0x53, 0x82, 0x6E, 0xD3, 0xB7, 0xC7, 0xEF, 0x82,
  26705. 0x41, 0xE1, 0x9C, 0x85, 0x11, 0x7B, 0x3C, 0x53,
  26706. 0x41, 0x88, 0x1D, 0x4F, 0x29, 0x9E, 0x50, 0x37,
  26707. 0x4C, 0x8E, 0xEF, 0xD5, 0x56, 0x0B, 0xD1, 0x83,
  26708. 0x19, 0xA7, 0x96, 0x3A, 0x3D, 0x02, 0xF0, 0xFB,
  26709. 0xE8, 0x4B, 0xC4, 0x84, 0xB5, 0xA4, 0x01, 0x8B,
  26710. 0x97, 0xD2, 0x74, 0x19, 0x1C, 0x95, 0xF7, 0x02,
  26711. 0xBA, 0xB9, 0xB0, 0xD1, 0x05, 0xFA, 0xF9, 0xFD,
  26712. 0xCF, 0xF9, 0x7E, 0x43, 0x72, 0x36, 0x56, 0x75,
  26713. 0x99, 0xFA, 0xF7, 0x3B, 0x07, 0x5D, 0x40, 0x61,
  26714. 0x04, 0xD4, 0x03, 0xCD, 0xF8, 0x12, 0x24, 0xDA,
  26715. 0x59, 0x0B, 0xEC, 0x28, 0x97, 0xE3, 0x01, 0x09,
  26716. 0xE1, 0xF2, 0xE5, 0xAE, 0x46, 0x10, 0xC8, 0x09,
  26717. 0xA7, 0x3F, 0x63, 0x8C, 0x84, 0x21, 0x0B, 0x34,
  26718. 0x47, 0xA7, 0xC8, 0xB6, 0xDD, 0xDB, 0x5A, 0xE2,
  26719. 0x00, 0xBF, 0x20, 0xE2, 0xFE, 0x4D, 0x4B, 0xA6,
  26720. 0xC6, 0xB1, 0x27, 0x67, 0xFB, 0x87, 0x60, 0xF6,
  26721. 0x6C, 0x51, 0x18, 0xE7, 0xA9, 0x93, 0x5B, 0x41,
  26722. 0xC9, 0xA4, 0x71, 0xA1, 0xD3, 0x23, 0x76, 0x88,
  26723. 0xC1, 0xE6, 0x18, 0xCC, 0x3B, 0xE9, 0x36, 0xAA,
  26724. 0x3F, 0x5E, 0x44, 0xE0, 0x86, 0x82, 0x0B, 0x81,
  26725. 0x0E, 0x06, 0x32, 0x11, 0xFC, 0x21, 0xC4, 0x04,
  26726. 0x4B, 0x3A, 0xC4, 0xD0, 0x0D, 0xF1, 0xBC, 0xC7,
  26727. 0xB2, 0x4D, 0xC0, 0x7B, 0xA4, 0x8B, 0x23, 0xB0,
  26728. 0xFC, 0x12, 0xA3, 0xED, 0x3D, 0x0A, 0x5C, 0xF7,
  26729. 0x67, 0x14, 0x15, 0xAB, 0x9C, 0xF2, 0x12, 0x86,
  26730. 0xFE, 0x63, 0xFB, 0x41, 0x41, 0x85, 0x70, 0x55,
  26731. 0x5D, 0x47, 0x39, 0xB8, 0x81, 0x04, 0xA8, 0x59,
  26732. 0x3F, 0x29, 0x30, 0x25, 0xA4, 0xE3, 0xEE, 0x7C,
  26733. 0x67, 0xE4, 0xB4, 0x8E, 0x40, 0xF6, 0xBA, 0x8C,
  26734. 0x09, 0x86, 0x0C, 0x3F, 0xBB, 0xE5, 0x5D, 0x45,
  26735. 0xB4, 0x5F, 0xC9, 0xAB, 0x62, 0x9B, 0x17, 0xC2,
  26736. 0x76, 0xC9, 0xC9, 0xE2, 0xAF, 0x3A, 0x04, 0x3B,
  26737. 0xEA, 0xFC, 0x18, 0xFD, 0x4F, 0x25, 0xEE, 0x7F,
  26738. 0x83, 0xBD, 0xDC, 0xD2, 0xD9, 0x39, 0x14, 0xB7,
  26739. 0xED, 0x4F, 0x7C, 0x9A, 0xF1, 0x27, 0xF3, 0xF1,
  26740. 0x5C, 0x27, 0x7B, 0xE1, 0x65, 0x51, 0xFE, 0xF3,
  26741. 0xAE, 0x03, 0xD7, 0xB9, 0x14, 0x3F, 0x0C, 0x9C,
  26742. 0x01, 0x9A, 0xB9, 0x7E, 0xEA, 0x07, 0x63, 0x66,
  26743. 0x13, 0x1F, 0x51, 0x83, 0x63, 0x71, 0x1B, 0x34,
  26744. 0xE9, 0x6D, 0x3F, 0x8A, 0x51, 0x3F, 0x3E, 0x20,
  26745. 0xB1, 0xD4, 0x52, 0xC4, 0xB7, 0xAE, 0x3B, 0x97,
  26746. 0x5E, 0xA9, 0x4D, 0x88, 0x0D, 0xAC, 0x66, 0x93,
  26747. 0x39, 0x97, 0x50, 0xD0, 0x22, 0x20, 0x40, 0x3F,
  26748. 0x0D, 0x3E, 0x3F, 0xC1, 0x17, 0x2A, 0x4D, 0xE9,
  26749. 0xDC, 0x28, 0x0E, 0xAF, 0x0F, 0xEE, 0x28, 0x83,
  26750. 0xA6, 0x66, 0x0B, 0xF5, 0xA3, 0xD2, 0x46, 0xFF,
  26751. 0x41, 0xD2, 0x1B, 0x36, 0xEA, 0x52, 0x1C, 0xF7,
  26752. 0xAA, 0x68, 0x9F, 0x80, 0x0D, 0x0F, 0x86, 0xF4,
  26753. 0xFA, 0x10, 0x57, 0xD8, 0xA1, 0x3F, 0x9D, 0xA8,
  26754. 0xFF, 0xFD, 0x0D, 0xC1, 0xFA, 0xD3, 0xC0, 0x4B,
  26755. 0xB1, 0xCC, 0xCB, 0x7C, 0x83, 0x4D, 0xB0, 0x51,
  26756. 0xA7, 0xAC, 0x2E, 0x4C, 0x60, 0x30, 0x19, 0x96,
  26757. 0xC9, 0x30, 0x71, 0xEA, 0x41, 0x6B, 0x42, 0x17,
  26758. 0x59, 0x93, 0x56, 0x59, 0xCF, 0x62, 0xCA, 0x5F,
  26759. 0x13, 0xAE, 0x07, 0xC3, 0xB1, 0x95, 0xC1, 0x48,
  26760. 0x15, 0x9D, 0x8B, 0xEB, 0x03, 0xD4, 0x40, 0xB0,
  26761. 0x0F, 0x53, 0x05, 0x76, 0x5F, 0x20, 0xC0, 0xC4,
  26762. 0x6E, 0xEE, 0x59, 0xC6, 0xD1, 0x62, 0x06, 0x40,
  26763. 0x2D, 0xB1, 0xC7, 0x15, 0xE8, 0x88, 0xBD, 0xE5,
  26764. 0x9C, 0x78, 0x1F, 0x35, 0xA7, 0xCC, 0x7C, 0x1C,
  26765. 0x5E, 0xCB, 0x21, 0x55, 0xAE, 0x3E, 0x95, 0x9C,
  26766. 0x09, 0x64, 0xCC, 0x1E, 0xF8, 0xD7, 0xC6, 0x9D,
  26767. 0x14, 0x58, 0xA9, 0xA4, 0x2F, 0x95, 0xF4, 0xC6,
  26768. 0xB5, 0xB9, 0x96, 0x34, 0x57, 0x12, 0xAA, 0x29,
  26769. 0x0F, 0xBB, 0xF7, 0xDF, 0xD4, 0xA6, 0xE8, 0x64,
  26770. 0x63, 0x02, 0x2A, 0x3F, 0x47, 0x25, 0xF6, 0x51,
  26771. 0x1B, 0xF7, 0xEA, 0x5E, 0x95, 0xC7, 0x07, 0xCD,
  26772. 0x35, 0x73, 0x60, 0x9A, 0xAD, 0xEA, 0xF5, 0x40,
  26773. 0x15, 0x2C, 0x49, 0x5F, 0x37, 0xFE, 0x6E, 0xC8,
  26774. 0xBB, 0x9F, 0xA2, 0xAA, 0x61, 0xD1, 0x57, 0x35,
  26775. 0x93, 0x4F, 0x47, 0x37, 0x92, 0x8F, 0xDE, 0x90,
  26776. 0xBA, 0x99, 0x57, 0x22, 0x46, 0x5D, 0x4A, 0x64,
  26777. 0x50, 0x5A, 0x52, 0x01, 0xF0, 0x7A, 0xA5, 0x8C,
  26778. 0xFD, 0x8A, 0xE2, 0x26, 0xE0, 0x20, 0x70, 0xB2,
  26779. 0xDB, 0xF5, 0x12, 0xB9, 0x75, 0x31, 0x9A, 0x7E,
  26780. 0x87, 0x53, 0xB4, 0xFD, 0xAE, 0x0E, 0xB4, 0x92,
  26781. 0x28, 0x69, 0xCC, 0x8E, 0x25, 0xC4, 0xA5, 0x56,
  26782. 0x0C, 0x2A, 0x06, 0x85, 0xDE, 0x3A, 0xC3, 0x92,
  26783. 0xA8, 0x92, 0x5B, 0xA8, 0x82, 0x00, 0x48, 0x94,
  26784. 0x74, 0x2E, 0x43, 0xCC, 0xFC, 0x27, 0x74, 0x39,
  26785. 0xEC, 0x80, 0x50, 0xA9, 0xAE, 0xB4, 0x29, 0x32,
  26786. 0xE0, 0x1C, 0x84, 0x0D, 0xFC, 0xED, 0xCC, 0x34,
  26787. 0xD3, 0x99, 0x12, 0x89, 0xA6, 0x2C, 0x17, 0xD1,
  26788. 0x28, 0x4C, 0x83, 0x95, 0x14, 0xB9, 0x33, 0x51,
  26789. 0xDB, 0xB2, 0xDD, 0xA8, 0x1F, 0x92, 0x45, 0x65,
  26790. 0xD7, 0x0E, 0x70, 0x79, 0xD5, 0xB8, 0x12, 0x6C,
  26791. 0xAA, 0xB7, 0xA4, 0xA1, 0xC7, 0x31, 0x65, 0x5A,
  26792. 0x53, 0xBC, 0xC0, 0x9F, 0x5D, 0x63, 0xEC, 0x90,
  26793. 0x86, 0xDE, 0xA6, 0x50, 0x05, 0x59, 0x85, 0xED,
  26794. 0xFA, 0x82, 0x97, 0xD9, 0xC9, 0x54, 0x10, 0xC5,
  26795. 0xD1, 0x89, 0x4D, 0x17, 0xD5, 0x93, 0x05, 0x49,
  26796. 0xAD, 0xBC, 0x2B, 0x87, 0x33, 0xC9, 0x9F, 0xE6,
  26797. 0x2E, 0x17, 0xC4, 0xDE, 0x34, 0xA5, 0xD8, 0x9B,
  26798. 0x12, 0xD1, 0x8E, 0x42, 0xA4, 0x22, 0xD2, 0xCE,
  26799. 0x77, 0x9C, 0x2C, 0x28, 0xEB, 0x2D, 0x98, 0x00,
  26800. 0x3D, 0x5C, 0xD3, 0x23, 0xFC, 0xBE, 0xCF, 0x02,
  26801. 0xB5, 0x06, 0x6E, 0x0E, 0x73, 0x48, 0x10, 0xF0,
  26802. 0x9E, 0xD8, 0x90, 0x13, 0xC0, 0x0F, 0x01, 0x1B,
  26803. 0xD2, 0x20, 0xF2, 0xE5, 0xD6, 0xA3, 0x62, 0xDF,
  26804. 0x90, 0x59, 0x91, 0x98, 0xA0, 0x93, 0xB0, 0x3C,
  26805. 0x8D, 0x8E, 0xFB, 0xFE, 0x0B, 0x61, 0x75, 0x92,
  26806. 0xFA, 0xF1, 0xE6, 0x42, 0x20, 0xC4, 0x44, 0x0B,
  26807. 0x53, 0xFF, 0xB4, 0x71, 0x64, 0xF3, 0x69, 0xC9,
  26808. 0x52, 0x90, 0xBA, 0x9F, 0x31, 0x08, 0xD6, 0x86,
  26809. 0xC5, 0x7D, 0xB6, 0x45, 0xC5, 0x3C, 0x01, 0x2E,
  26810. 0x57, 0xAF, 0x25, 0xBD, 0x66, 0x93, 0xE2, 0xCC,
  26811. 0x6B, 0x57, 0x65, 0x1A, 0xF1, 0x59, 0x1F, 0xE5,
  26812. 0xD8, 0x91, 0x66, 0x40, 0xEC, 0x01, 0x7C, 0x25,
  26813. 0x3D, 0xF0, 0x60, 0x6B, 0xB6, 0xB3, 0x03, 0x5F,
  26814. 0xAE, 0x74, 0x8F, 0x3D, 0x40, 0x34, 0x22, 0x3B,
  26815. 0x1B, 0x5E, 0xFB, 0xF5, 0x28, 0x3E, 0x77, 0x8C,
  26816. 0x10, 0x94, 0x29, 0x1C, 0xF7, 0xB1, 0x9B, 0xE0,
  26817. 0xF3, 0x17, 0x35, 0x0E, 0x6F, 0x85, 0x18, 0xFD,
  26818. 0xE0, 0xEF, 0xB1, 0x38, 0x1F, 0xB6, 0xE1, 0x6C,
  26819. 0x24, 0x1F, 0x7F, 0x17, 0xA5, 0x21, 0x06, 0x93,
  26820. 0xA2, 0x74, 0x15, 0x9E, 0x7F, 0xAC, 0x86, 0x8C,
  26821. 0xD0, 0xDC, 0x43, 0x59, 0xC3, 0xD9, 0xEE, 0xFE,
  26822. 0xA0, 0xD9, 0xE3, 0x1E, 0x43, 0xFA, 0x65, 0x13,
  26823. 0x92, 0xC6, 0x5A, 0x54, 0x3A, 0x59, 0xB3, 0xEE,
  26824. 0xE3, 0xA6, 0x39, 0xDC, 0x94, 0x17, 0xD0, 0x56,
  26825. 0xA5, 0xFF, 0x0F, 0x16, 0x0B, 0xEE, 0xE2, 0xEA,
  26826. 0xC2, 0x9A, 0x7D, 0x88, 0xC0, 0x98, 0x2C, 0xF7,
  26827. 0x0B, 0x5A, 0x46, 0x37, 0x9F, 0x21, 0xE5, 0x06,
  26828. 0xAA, 0xC6, 0x1A, 0x9B, 0xB1, 0xB8, 0xC2, 0xB9,
  26829. 0xDA, 0xB0, 0xE4, 0x4A, 0x82, 0x3B, 0x61, 0xD0,
  26830. 0xAA, 0x11, 0xD9, 0x4F, 0x76, 0xA4, 0xA8, 0xE2,
  26831. 0x1F, 0x9D, 0x42, 0x80, 0x68, 0x32, 0x08, 0xF4,
  26832. 0xEA, 0x91, 0x11, 0x16, 0xF6, 0xFD, 0x6A, 0x97,
  26833. 0x42, 0x69, 0x34, 0xEC, 0x34, 0x26, 0xB8, 0xC8,
  26834. 0xF7, 0x03, 0xDA, 0x85, 0xE9, 0xDC, 0xF9, 0x93,
  26835. 0x36, 0x13, 0x60, 0x03, 0x72, 0x8B, 0x8E, 0xCD,
  26836. 0xD0, 0x4A, 0x38, 0x9F, 0x6A, 0x81, 0x7A, 0x78,
  26837. 0xBF, 0xA6, 0x1B, 0xA4, 0x60, 0x20, 0xBF, 0x3C,
  26838. 0x34, 0x82, 0x95, 0x08, 0xF9, 0xD0, 0x6D, 0x15,
  26839. 0x53, 0xCD, 0x98, 0x7A, 0xAC, 0x38, 0x0D, 0x86,
  26840. 0xF1, 0x68, 0x84, 0x3B, 0xA3, 0x90, 0x4D, 0xE5,
  26841. 0xF7, 0x05, 0x8A, 0x41, 0xB4, 0xCD, 0x38, 0x8B,
  26842. 0xC9, 0xCE, 0x3A, 0xBA, 0x7E, 0xE7, 0x13, 0x9B,
  26843. 0x7F, 0xC9, 0xE5, 0xB8, 0xCF, 0xAA, 0xA3, 0x89,
  26844. 0x90, 0xBD, 0x4A, 0x5D, 0xB3, 0x2E, 0x26, 0x13,
  26845. 0xE7, 0xEC, 0x4F, 0x5F, 0x8B, 0x12, 0x92, 0xA3,
  26846. 0x8C, 0x6F, 0x4F, 0xF5, 0xA4, 0x04, 0x90, 0xD7,
  26847. 0x6B, 0x12, 0x66, 0x52, 0xFC, 0xF8, 0x6E, 0x24,
  26848. 0x52, 0x35, 0xD6, 0x36, 0xC6, 0x5C, 0xD1, 0x02,
  26849. 0xB0, 0x1E, 0x22, 0x78, 0x1A, 0x72, 0x91, 0x8C
  26850. };
  26851. static const byte k_1024[KYBER_SS_SZ] = {
  26852. 0x72, 0x64, 0xBD, 0xE5, 0xC6, 0xCE, 0xC1, 0x48,
  26853. 0x49, 0x69, 0x3E, 0x2C, 0x3C, 0x86, 0xE4, 0x8F,
  26854. 0x80, 0x95, 0x8A, 0x4F, 0x61, 0x86, 0xFC, 0x69,
  26855. 0x33, 0x3A, 0x41, 0x48, 0xE6, 0xE4, 0x97, 0xF3
  26856. };
  26857. #endif
  26858. static byte ct[KYBER_MAX_CIPHER_TEXT_SIZE];
  26859. static byte ss[KYBER_SS_SZ];
  26860. key = (KyberKey*)XMALLOC(sizeof(KyberKey), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  26861. ExpectNotNull(key);
  26862. if (key != NULL) {
  26863. XMEMSET(key, 0, sizeof(KyberKey));
  26864. }
  26865. #ifndef WOLFSSL_NO_KYBER512
  26866. ExpectIntEQ(wc_KyberKey_Init(KYBER512, key, NULL, INVALID_DEVID), 0);
  26867. ExpectIntEQ(wc_KyberKey_DecodePublicKey(key, ek_512, sizeof(ek_512)), 0);
  26868. ExpectIntEQ(wc_KyberKey_EncapsulateWithRandom(key, ct, ss, seed_512,
  26869. sizeof(seed_512)), 0);
  26870. ExpectIntEQ(XMEMCMP(ct, c_512, KYBER512_CIPHER_TEXT_SIZE), 0);
  26871. ExpectIntEQ(XMEMCMP(ss, k_512, KYBER_SS_SZ), 0);
  26872. wc_KyberKey_Free(key);
  26873. #endif
  26874. #ifndef WOLFSSL_NO_KYBER768
  26875. ExpectIntEQ(wc_KyberKey_Init(KYBER768, key, NULL, INVALID_DEVID), 0);
  26876. ExpectIntEQ(wc_KyberKey_DecodePublicKey(key, ek_768, sizeof(ek_768)), 0);
  26877. ExpectIntEQ(wc_KyberKey_EncapsulateWithRandom(key, ct, ss, seed_768,
  26878. sizeof(seed_768)), 0);
  26879. ExpectIntEQ(XMEMCMP(ct, c_768, KYBER768_CIPHER_TEXT_SIZE), 0);
  26880. ExpectIntEQ(XMEMCMP(ss, k_768, KYBER_SS_SZ), 0);
  26881. wc_KyberKey_Free(key);
  26882. #endif
  26883. #ifndef WOLFSSL_NO_KYBER1024
  26884. ExpectIntEQ(wc_KyberKey_Init(KYBER1024, key, NULL, INVALID_DEVID), 0);
  26885. ExpectIntEQ(wc_KyberKey_DecodePublicKey(key, ek_1024, sizeof(ek_1024)), 0);
  26886. ExpectIntEQ(wc_KyberKey_EncapsulateWithRandom(key, ct, ss, seed_1024,
  26887. sizeof(seed_1024)), 0);
  26888. ExpectIntEQ(XMEMCMP(ct, c_1024, KYBER1024_CIPHER_TEXT_SIZE), 0);
  26889. ExpectIntEQ(XMEMCMP(ss, k_1024, KYBER_SS_SZ), 0);
  26890. wc_KyberKey_Free(key);
  26891. #endif
  26892. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  26893. #endif
  26894. return EXPECT_RESULT();
  26895. }
  26896. static int test_wc_kyber_decapsulate_kats(void)
  26897. {
  26898. EXPECT_DECLS;
  26899. #if defined(WOLFSSL_HAVE_KYBER) && defined(WOLFSSL_WC_KYBER) && \
  26900. !defined(WOLFSSL_KYBER_ORIGINAL)
  26901. KyberKey* key;
  26902. #ifndef WOLFSSL_NO_KYBER512
  26903. static const byte dk_512[KYBER512_PRIVATE_KEY_SIZE] = {
  26904. 0x69, 0xF9, 0xCB, 0xFD, 0x12, 0x37, 0xBA, 0x16,
  26905. 0x1C, 0xF6, 0xE6, 0xC1, 0x8F, 0x48, 0x8F, 0xC6,
  26906. 0xE3, 0x9A, 0xB4, 0xA5, 0xC9, 0xE6, 0xC2, 0x2E,
  26907. 0xA4, 0xE3, 0xAD, 0x8F, 0x26, 0x7A, 0x9C, 0x44,
  26908. 0x20, 0x10, 0xD3, 0x2E, 0x61, 0xF8, 0x3E, 0x6B,
  26909. 0xFA, 0x5C, 0x58, 0x70, 0x61, 0x45, 0x37, 0x6D,
  26910. 0xBB, 0x84, 0x95, 0x28, 0xF6, 0x80, 0x07, 0xC8,
  26911. 0x22, 0xB3, 0x3A, 0x95, 0xB8, 0x49, 0x04, 0xDC,
  26912. 0xD2, 0x70, 0x8D, 0x03, 0x40, 0xC8, 0xB8, 0x08,
  26913. 0xBC, 0xD3, 0xAA, 0xD0, 0xE4, 0x8B, 0x85, 0x84,
  26914. 0x95, 0x83, 0xA1, 0xB4, 0xE5, 0x94, 0x5D, 0xD9,
  26915. 0x51, 0x4A, 0x7F, 0x64, 0x61, 0xE0, 0x57, 0xB7,
  26916. 0xEC, 0xF6, 0x19, 0x57, 0xE9, 0x7C, 0xF6, 0x28,
  26917. 0x15, 0xF9, 0xC3, 0x22, 0x94, 0xB3, 0x26, 0xE1,
  26918. 0xA1, 0xC4, 0xE3, 0x60, 0xB9, 0x49, 0x8B, 0xA8,
  26919. 0x0F, 0x8C, 0xA9, 0x15, 0x32, 0xB1, 0x71, 0xD0,
  26920. 0xAE, 0xFC, 0x48, 0x49, 0xFA, 0x53, 0xBC, 0x61,
  26921. 0x79, 0x32, 0xE2, 0x08, 0xA6, 0x77, 0xC6, 0x04,
  26922. 0x4A, 0x66, 0x00, 0xB8, 0xD8, 0xB8, 0x3F, 0x26,
  26923. 0xA7, 0x47, 0xB1, 0x8C, 0xFB, 0x78, 0xBE, 0xAF,
  26924. 0xC5, 0x51, 0xAD, 0x52, 0xB7, 0xCA, 0x6C, 0xB8,
  26925. 0x8F, 0x3B, 0x5D, 0x9C, 0xE2, 0xAF, 0x6C, 0x67,
  26926. 0x95, 0x6C, 0x47, 0x8C, 0xEF, 0x49, 0x1F, 0x59,
  26927. 0xE0, 0x19, 0x1B, 0x3B, 0xBE, 0x92, 0x9B, 0x94,
  26928. 0xB6, 0x66, 0xC1, 0x76, 0x13, 0x8B, 0x00, 0xF4,
  26929. 0x97, 0x24, 0x34, 0x1E, 0xE2, 0xE1, 0x64, 0xB9,
  26930. 0x4C, 0x05, 0x3C, 0x18, 0x5A, 0x51, 0xF9, 0x3E,
  26931. 0x00, 0xF3, 0x68, 0x61, 0x61, 0x3A, 0x7F, 0xD7,
  26932. 0x2F, 0xEB, 0xD2, 0x3A, 0x8B, 0x96, 0xA2, 0x60,
  26933. 0x23, 0x42, 0x39, 0xC9, 0x62, 0x8F, 0x99, 0x5D,
  26934. 0xC1, 0x38, 0x07, 0xB4, 0x3A, 0x69, 0x46, 0x81,
  26935. 0x67, 0xCB, 0x1A, 0x8F, 0x9D, 0xD0, 0x7E, 0xE3,
  26936. 0xB3, 0x32, 0x38, 0xF6, 0x30, 0x96, 0xEB, 0xC4,
  26937. 0x9D, 0x50, 0x51, 0xC4, 0xB6, 0x59, 0x63, 0xD7,
  26938. 0x4A, 0x47, 0x66, 0xC2, 0x26, 0xF0, 0xB9, 0x4F,
  26939. 0x18, 0x62, 0xC2, 0x12, 0x4C, 0x8C, 0x74, 0x97,
  26940. 0x48, 0xC0, 0xBC, 0x4D, 0xC1, 0x4C, 0xB3, 0x49,
  26941. 0x06, 0xB8, 0x1C, 0x55, 0x24, 0xFB, 0x81, 0x00,
  26942. 0x79, 0x85, 0x42, 0xDC, 0x6C, 0xC2, 0xAA, 0x0A,
  26943. 0x70, 0x85, 0x75, 0xEA, 0xBC, 0xC1, 0x1F, 0x96,
  26944. 0xA9, 0xE6, 0x1C, 0x01, 0x7A, 0x96, 0xA7, 0xCE,
  26945. 0x93, 0xC4, 0x20, 0x91, 0x73, 0x71, 0x13, 0xAE,
  26946. 0x78, 0x3C, 0x0A, 0xE8, 0x75, 0x5E, 0x59, 0x41,
  26947. 0x11, 0xED, 0xFA, 0xBF, 0xD8, 0x6C, 0x32, 0x12,
  26948. 0xC6, 0x12, 0xA7, 0xB6, 0x2A, 0xFD, 0x3C, 0x7A,
  26949. 0x5C, 0x78, 0xB2, 0xF0, 0x73, 0x44, 0xB7, 0x89,
  26950. 0xC2, 0xB2, 0xDB, 0xB5, 0xF4, 0x44, 0x8B, 0xE9,
  26951. 0x7B, 0xBA, 0x42, 0x33, 0xC0, 0x03, 0x9C, 0x0F,
  26952. 0xE8, 0x43, 0x00, 0xF9, 0xB0, 0x3A, 0xC9, 0x94,
  26953. 0x97, 0xE6, 0xD4, 0x6B, 0x6E, 0x95, 0x30, 0x8F,
  26954. 0xF8, 0x47, 0x90, 0xF6, 0x12, 0xCF, 0x18, 0x6E,
  26955. 0xC1, 0x68, 0x11, 0xE8, 0x0C, 0x17, 0x93, 0x16,
  26956. 0xA6, 0x3B, 0x25, 0x70, 0x3F, 0x60, 0xB8, 0x42,
  26957. 0xB6, 0x19, 0x07, 0xE6, 0x28, 0x94, 0xE7, 0x36,
  26958. 0x64, 0x7B, 0x3C, 0x09, 0xDA, 0x6F, 0xEC, 0x59,
  26959. 0x32, 0x78, 0x2B, 0x36, 0xE0, 0x63, 0x50, 0x85,
  26960. 0xA3, 0x94, 0x9E, 0x69, 0x4D, 0x7E, 0x17, 0xCB,
  26961. 0xA3, 0xD9, 0x06, 0x43, 0x30, 0x43, 0x8C, 0x07,
  26962. 0x1B, 0x58, 0x36, 0xA7, 0x70, 0xC5, 0x5F, 0x62,
  26963. 0x13, 0xCC, 0x14, 0x25, 0x84, 0x5D, 0xE5, 0xA3,
  26964. 0x34, 0xD7, 0x5D, 0x3E, 0x50, 0x58, 0xC7, 0x80,
  26965. 0x9F, 0xDA, 0x4B, 0xCD, 0x78, 0x19, 0x1D, 0xA9,
  26966. 0x79, 0x73, 0x25, 0xE6, 0x23, 0x6C, 0x26, 0x50,
  26967. 0xFC, 0x60, 0x4E, 0xE4, 0x3A, 0x83, 0xCE, 0xB3,
  26968. 0x49, 0x80, 0x08, 0x44, 0x03, 0xA3, 0x32, 0x59,
  26969. 0x85, 0x79, 0x07, 0x79, 0x9A, 0x9D, 0x2A, 0x71,
  26970. 0x3A, 0x63, 0x3B, 0x5C, 0x90, 0x47, 0x27, 0xF6,
  26971. 0x1E, 0x42, 0x52, 0x09, 0x91, 0xD6, 0x55, 0x70,
  26972. 0x5C, 0xB6, 0xBC, 0x1B, 0x74, 0xAF, 0x60, 0x71,
  26973. 0x3E, 0xF8, 0x71, 0x2F, 0x14, 0x08, 0x68, 0x69,
  26974. 0xBE, 0x8E, 0xB2, 0x97, 0xD2, 0x28, 0xB3, 0x25,
  26975. 0xA0, 0x60, 0x9F, 0xD6, 0x15, 0xEA, 0xB7, 0x08,
  26976. 0x15, 0x40, 0xA6, 0x1A, 0x82, 0xAB, 0xF4, 0x3B,
  26977. 0x7D, 0xF9, 0x8A, 0x59, 0x5B, 0xE1, 0x1F, 0x41,
  26978. 0x6B, 0x41, 0xE1, 0xEB, 0x75, 0xBB, 0x57, 0x97,
  26979. 0x7C, 0x25, 0xC6, 0x4E, 0x97, 0x43, 0x7D, 0x88,
  26980. 0xCA, 0x5F, 0xDA, 0x61, 0x59, 0xD6, 0x68, 0xF6,
  26981. 0xBA, 0xB8, 0x15, 0x75, 0x55, 0xB5, 0xD5, 0x4C,
  26982. 0x0F, 0x47, 0xCB, 0xCD, 0x16, 0x84, 0x3B, 0x1A,
  26983. 0x0A, 0x0F, 0x02, 0x10, 0xEE, 0x31, 0x03, 0x13,
  26984. 0x96, 0x7F, 0x3D, 0x51, 0x64, 0x99, 0x01, 0x8F,
  26985. 0xDF, 0x31, 0x14, 0x77, 0x24, 0x70, 0xA1, 0x88,
  26986. 0x9C, 0xC0, 0x6C, 0xB6, 0xB6, 0x69, 0x0A, 0xC3,
  26987. 0x1A, 0xBC, 0xFA, 0xF4, 0xBC, 0x70, 0x76, 0x84,
  26988. 0x54, 0x5B, 0x00, 0x0B, 0x58, 0x0C, 0xCB, 0xFC,
  26989. 0xBC, 0xE9, 0xFA, 0x70, 0xAA, 0xEA, 0x0B, 0xBD,
  26990. 0x91, 0x10, 0x99, 0x2A, 0x7C, 0x6C, 0x06, 0xCB,
  26991. 0x36, 0x85, 0x27, 0xFD, 0x22, 0x90, 0x90, 0x75,
  26992. 0x7E, 0x6F, 0xE7, 0x57, 0x05, 0xFA, 0x59, 0x2A,
  26993. 0x76, 0x08, 0xF0, 0x50, 0xC6, 0xF8, 0x87, 0x03,
  26994. 0xCC, 0x28, 0xCB, 0x00, 0x0C, 0x1D, 0x7E, 0x77,
  26995. 0xB8, 0x97, 0xB7, 0x2C, 0x62, 0xBC, 0xC7, 0xAE,
  26996. 0xA2, 0x1A, 0x57, 0x72, 0x94, 0x83, 0xD2, 0x21,
  26997. 0x18, 0x32, 0xBE, 0xD6, 0x12, 0x43, 0x0C, 0x98,
  26998. 0x31, 0x03, 0xC6, 0x9E, 0x8C, 0x07, 0x2C, 0x0E,
  26999. 0xA7, 0x89, 0x8F, 0x22, 0x83, 0xBE, 0xC4, 0x8C,
  27000. 0x5A, 0xC8, 0x19, 0x84, 0xD4, 0xA5, 0xA8, 0x36,
  27001. 0x19, 0x73, 0x5A, 0x84, 0x2B, 0xD1, 0x72, 0xC0,
  27002. 0xD1, 0xB3, 0x9F, 0x43, 0x58, 0x8A, 0xF1, 0x70,
  27003. 0x45, 0x8B, 0xA9, 0xEE, 0x74, 0x92, 0xEA, 0xAA,
  27004. 0x94, 0xEA, 0x53, 0xA4, 0xD3, 0x84, 0x98, 0xEC,
  27005. 0xBB, 0x98, 0xA5, 0xF4, 0x07, 0xE7, 0xC9, 0x7B,
  27006. 0x4E, 0x16, 0x6E, 0x39, 0x71, 0x92, 0xC2, 0x16,
  27007. 0x03, 0x30, 0x14, 0xB8, 0x78, 0xE9, 0x38, 0x07,
  27008. 0x5C, 0x6C, 0x1F, 0x10, 0xA0, 0x06, 0x5A, 0xBC,
  27009. 0x31, 0x63, 0x72, 0x2F, 0x1A, 0x2E, 0xFF, 0xEC,
  27010. 0x8D, 0x6E, 0x3A, 0x0C, 0x4F, 0x71, 0x74, 0xFC,
  27011. 0x16, 0xB7, 0x9F, 0xB5, 0x18, 0x6A, 0x75, 0x16,
  27012. 0x8F, 0x81, 0xA5, 0x6A, 0xA4, 0x8A, 0x20, 0xA0,
  27013. 0x4B, 0xDD, 0xF1, 0x82, 0xC6, 0xE1, 0x79, 0xC3,
  27014. 0xF6, 0x90, 0x61, 0x55, 0x5E, 0xF7, 0x39, 0x6D,
  27015. 0xD0, 0xB7, 0x49, 0x96, 0x01, 0xA6, 0xEB, 0x3A,
  27016. 0x96, 0xA9, 0xA2, 0x2D, 0x04, 0xF1, 0x16, 0x8D,
  27017. 0xB5, 0x63, 0x55, 0xB0, 0x76, 0x00, 0xA2, 0x03,
  27018. 0x70, 0x63, 0x7B, 0x64, 0x59, 0x76, 0xBB, 0xD9,
  27019. 0x7B, 0x6D, 0x62, 0x88, 0xA0, 0xD3, 0x03, 0x63,
  27020. 0x60, 0x47, 0x2E, 0x3A, 0xC7, 0x1D, 0x56, 0x6D,
  27021. 0xB8, 0xFB, 0xB1, 0xB1, 0xD7, 0x6C, 0xB7, 0x55,
  27022. 0xCD, 0x0D, 0x68, 0xBD, 0xBF, 0xC0, 0x48, 0xEB,
  27023. 0xA2, 0x52, 0x5E, 0xEA, 0x9D, 0xD5, 0xB1, 0x44,
  27024. 0xFB, 0x3B, 0x60, 0xFB, 0xC3, 0x42, 0x39, 0x32,
  27025. 0x0C, 0xBC, 0x06, 0x9B, 0x35, 0xAB, 0x16, 0xB8,
  27026. 0x75, 0x65, 0x36, 0xFB, 0x33, 0xE8, 0xA6, 0xAF,
  27027. 0x1D, 0xD4, 0x2C, 0x79, 0xF4, 0x8A, 0xD1, 0x20,
  27028. 0xAE, 0x4B, 0x15, 0x9D, 0x3D, 0x8C, 0x31, 0x90,
  27029. 0x60, 0xCC, 0xE5, 0x69, 0xC3, 0xF6, 0x03, 0x53,
  27030. 0x65, 0x58, 0x5D, 0x34, 0x41, 0x37, 0x95, 0xA6,
  27031. 0xA1, 0x8E, 0xC5, 0x13, 0x6A, 0xB1, 0x3C, 0x90,
  27032. 0xE3, 0xAF, 0x14, 0xC0, 0xB8, 0xA4, 0x64, 0xC8,
  27033. 0x6B, 0x90, 0x73, 0x22, 0x2B, 0x56, 0xB3, 0xF7,
  27034. 0x32, 0x8A, 0xEA, 0x79, 0x81, 0x55, 0x32, 0x59,
  27035. 0x11, 0x25, 0x0E, 0xF0, 0x16, 0xD7, 0x28, 0x02,
  27036. 0xE3, 0x87, 0x8A, 0xA5, 0x05, 0x40, 0xCC, 0x98,
  27037. 0x39, 0x56, 0x97, 0x1D, 0x6E, 0xFA, 0x35, 0x2C,
  27038. 0x02, 0x55, 0x4D, 0xC7, 0x60, 0xA5, 0xA9, 0x13,
  27039. 0x58, 0xEA, 0x56, 0x37, 0x08, 0x84, 0xFD, 0x5B,
  27040. 0x3F, 0x85, 0xB7, 0x0E, 0x83, 0xE4, 0x69, 0x7D,
  27041. 0xEB, 0x17, 0x05, 0x16, 0x9E, 0x9C, 0x60, 0xA7,
  27042. 0x45, 0x28, 0xCF, 0x15, 0x28, 0x1C, 0xB1, 0xB1,
  27043. 0xC4, 0x57, 0xD4, 0x67, 0xB5, 0xF9, 0x3A, 0x60,
  27044. 0x37, 0x3D, 0x10, 0xE0, 0xCF, 0x6A, 0x83, 0x7A,
  27045. 0xA3, 0xC9, 0x59, 0x6A, 0x72, 0xBE, 0xC2, 0x9B,
  27046. 0x2D, 0x7E, 0x58, 0x65, 0x3D, 0x53, 0x30, 0x61,
  27047. 0xD3, 0x81, 0xD5, 0x17, 0x59, 0x75, 0x22, 0x17,
  27048. 0xEB, 0x46, 0xCA, 0xC7, 0x80, 0x7C, 0x4A, 0xD3,
  27049. 0x8B, 0x61, 0x16, 0x44, 0xAC, 0xF0, 0xA3, 0xF2,
  27050. 0x6B, 0x6B, 0x08, 0x4A, 0xB4, 0x7A, 0x83, 0xBF,
  27051. 0x0D, 0x69, 0x6F, 0x8A, 0x47, 0x68, 0xFC, 0x35,
  27052. 0xBC, 0xA6, 0xBC, 0x79, 0x03, 0xB2, 0xA2, 0x37,
  27053. 0xC2, 0x77, 0x49, 0xF5, 0x51, 0x0C, 0x86, 0x38,
  27054. 0x69, 0xE6, 0xAE, 0x56, 0xBB, 0x2A, 0xFE, 0x47,
  27055. 0x71, 0xC9, 0x22, 0x18, 0x74, 0xF5, 0x0F, 0x5B,
  27056. 0x14, 0xBA, 0xAD, 0x59, 0x93, 0xB4, 0x92, 0x38,
  27057. 0xFD, 0x0A, 0x0C, 0x9F, 0x79, 0xB7, 0xB4, 0x58,
  27058. 0x4E, 0x41, 0x30, 0x1F, 0x7A, 0x88, 0x5C, 0x9F,
  27059. 0x91, 0x81, 0x9B, 0xEA, 0x00, 0xD5, 0x12, 0x58,
  27060. 0x17, 0x30, 0x53, 0x9F, 0xB3, 0x7E, 0x59, 0xE8,
  27061. 0x6A, 0x6D, 0x19, 0xCA, 0x25, 0xF0, 0xA8, 0x11,
  27062. 0xC9, 0xB4, 0x28, 0xBA, 0x86, 0x14, 0xAA, 0x4F,
  27063. 0x94, 0x80, 0x7B, 0xC0, 0x31, 0xCB, 0xCC, 0x18,
  27064. 0x3F, 0x3B, 0xF0, 0x7F, 0xE2, 0xC1, 0xA6, 0xEB,
  27065. 0xA8, 0x0D, 0x5A, 0x70, 0x6E, 0xE0, 0xDA, 0xB2,
  27066. 0x7E, 0x23, 0x14, 0x58, 0x02, 0x5D, 0x84, 0xA7,
  27067. 0xA9, 0xB0, 0x23, 0x05, 0x01, 0x11, 0x6C, 0x29,
  27068. 0x0A, 0x6B, 0xB5, 0x06, 0x26, 0xD9, 0x7B, 0x93,
  27069. 0x98, 0x50, 0x94, 0x28, 0x28, 0x39, 0x0B, 0x0A,
  27070. 0x20, 0x01, 0xB7, 0x85, 0x3A, 0xD1, 0xAE, 0x9B,
  27071. 0x01, 0x1B, 0x2D, 0xB3, 0x6C, 0xAE, 0xEA, 0x73,
  27072. 0xA2, 0x32, 0x8E, 0x3C, 0x56, 0x48, 0x5B, 0x49,
  27073. 0x1C, 0x29, 0x91, 0x15, 0xA0, 0x17, 0xC9, 0x07,
  27074. 0xAB, 0x54, 0x31, 0x72, 0x60, 0xA5, 0x93, 0xA0,
  27075. 0xD7, 0xBA, 0x6D, 0x06, 0x61, 0x5D, 0x6E, 0x2C,
  27076. 0xA8, 0x4B, 0x86, 0x0E, 0xFF, 0x3C, 0xCB, 0x59,
  27077. 0x72, 0x11, 0xBF, 0xE3, 0x6B, 0xDE, 0xF8, 0x06,
  27078. 0x9A, 0xFA, 0x36, 0xC5, 0xA7, 0x33, 0x92, 0x72,
  27079. 0x26, 0x50, 0xE4, 0x95, 0x7D, 0xCA, 0x59, 0x7A,
  27080. 0xCB, 0xA5, 0x60, 0x5B, 0x63, 0xC1, 0x63, 0xCF,
  27081. 0xA9, 0x4B, 0x64, 0xDD, 0xD6, 0x23, 0x01, 0xA4,
  27082. 0x33, 0x20, 0x83, 0x36, 0x19, 0x72, 0x58, 0x9D,
  27083. 0xB0, 0x59, 0x9A, 0x69, 0x4D, 0xD4, 0x54, 0x7A,
  27084. 0x5E, 0xE9, 0x19, 0x65, 0x77, 0xC2, 0x2E, 0xD4,
  27085. 0x27, 0xAC, 0x89, 0xBB, 0x8B, 0xA3, 0x75, 0x3E,
  27086. 0xB7, 0x6C, 0x41, 0xF2, 0xC1, 0x12, 0x9C, 0x8A,
  27087. 0x77, 0xD6, 0x80, 0x5F, 0xA7, 0x19, 0xB1, 0xB6,
  27088. 0xCA, 0x11, 0xB7, 0x40, 0xA7, 0x8A, 0x3D, 0x41,
  27089. 0xB5, 0x33, 0x05, 0x26, 0xAB, 0x87, 0xD5, 0x8D,
  27090. 0x59, 0x25, 0x31, 0x5A, 0x14, 0x85, 0xED, 0xC6,
  27091. 0x47, 0xC1, 0x60, 0x4E, 0xB3, 0x81, 0x38, 0xDE,
  27092. 0x63, 0x7A, 0xD2, 0xC6, 0xCA, 0x5B, 0xE4, 0x4E,
  27093. 0x10, 0x08, 0xB2, 0xC0, 0x86, 0x7B, 0x22, 0x9C,
  27094. 0xCC, 0x36, 0x61, 0x9E, 0x27, 0x58, 0xC4, 0xC2,
  27095. 0x02, 0x9E, 0xAE, 0xB2, 0x6E, 0x7A, 0x80, 0x3F,
  27096. 0xCA, 0x30, 0x5A, 0x59, 0xCD, 0x58, 0x5E, 0x11,
  27097. 0x7D, 0x69, 0x8E, 0xCE, 0x01, 0x1C, 0xC3, 0xFC,
  27098. 0xE5, 0x4D, 0x2E, 0x11, 0x45, 0x45, 0xA2, 0x1A,
  27099. 0xC5, 0xBE, 0x67, 0x71, 0xAB, 0x8F, 0x13, 0x12,
  27100. 0x2F, 0xAD, 0x29, 0x5E, 0x74, 0x5A, 0x50, 0x3B,
  27101. 0x14, 0x2F, 0x91, 0xAE, 0xF7, 0xBD, 0xE9, 0x99,
  27102. 0x98, 0x84, 0x5F, 0xDA, 0x04, 0x35, 0x55, 0xC9,
  27103. 0xC1, 0xEE, 0x53, 0x5B, 0xE1, 0x25, 0xE5, 0xDC,
  27104. 0xE5, 0xD2, 0x66, 0x66, 0x7E, 0x72, 0x3E, 0x67,
  27105. 0xB6, 0xBA, 0x89, 0x1C, 0x16, 0xCB, 0xA1, 0x74,
  27106. 0x09, 0x8A, 0x3F, 0x35, 0x17, 0x78, 0xB0, 0x88,
  27107. 0x8C, 0x95, 0x90, 0xA9, 0x09, 0x0C, 0xD4, 0x04
  27108. };
  27109. static const byte c_512[KYBER512_CIPHER_TEXT_SIZE] = {
  27110. 0x16, 0x1C, 0xD2, 0x59, 0xFE, 0xAA, 0x7E, 0xC6,
  27111. 0xB2, 0x86, 0x49, 0x8A, 0x9A, 0x6F, 0x69, 0xF8,
  27112. 0xB2, 0x62, 0xA2, 0xE2, 0x09, 0x3D, 0x0F, 0xBD,
  27113. 0x76, 0xD5, 0xDC, 0x1C, 0x9F, 0xDE, 0x0D, 0xED,
  27114. 0xB3, 0x65, 0x81, 0x00, 0x4C, 0xB4, 0x81, 0x12,
  27115. 0xF8, 0x52, 0xE7, 0xF8, 0x7F, 0x64, 0x9E, 0x8A,
  27116. 0x42, 0xCD, 0x9E, 0x03, 0x49, 0xE7, 0xDA, 0xBD,
  27117. 0xF0, 0xA9, 0xAC, 0x1B, 0x52, 0x1C, 0x37, 0xEA,
  27118. 0x52, 0x41, 0x37, 0x0A, 0x8A, 0xB2, 0x91, 0x1C,
  27119. 0xC7, 0x99, 0x02, 0xC9, 0x5D, 0x28, 0x22, 0x4F,
  27120. 0xA8, 0x89, 0x6A, 0xD7, 0x15, 0x20, 0x9E, 0xCD,
  27121. 0xD5, 0xD7, 0x84, 0xE9, 0x1D, 0xD9, 0xD0, 0xBE,
  27122. 0x91, 0x6B, 0x45, 0x65, 0xF4, 0xD5, 0x66, 0x9A,
  27123. 0xEE, 0x0D, 0xEF, 0x93, 0x1E, 0x97, 0x68, 0x29,
  27124. 0x4E, 0xEC, 0x52, 0x58, 0xDE, 0x83, 0x91, 0xEC,
  27125. 0xE2, 0x71, 0xE7, 0xE4, 0xCF, 0xD9, 0xD2, 0x3A,
  27126. 0x79, 0xFA, 0xC3, 0xA8, 0xE0, 0xDB, 0x5D, 0xDD,
  27127. 0x6E, 0x01, 0x07, 0x23, 0x56, 0x88, 0xBB, 0xDF,
  27128. 0x7B, 0xC5, 0xD5, 0x63, 0x2F, 0x20, 0x6C, 0x63,
  27129. 0xA0, 0xC9, 0x56, 0x4F, 0x30, 0x96, 0x5C, 0xA5,
  27130. 0x8C, 0x69, 0xFF, 0x92, 0xD2, 0x5A, 0x4F, 0x93,
  27131. 0xA0, 0x9E, 0xAB, 0x9B, 0x90, 0x85, 0x94, 0x7E,
  27132. 0x07, 0x8A, 0x23, 0xE4, 0xD9, 0xC1, 0x3B, 0x8A,
  27133. 0x56, 0xE7, 0x3E, 0x18, 0xDF, 0x42, 0xD6, 0x94,
  27134. 0x9F, 0xAF, 0x59, 0x21, 0xF2, 0xE3, 0x73, 0xD4,
  27135. 0x50, 0xC8, 0xC0, 0x9D, 0x07, 0xB1, 0x52, 0xA9,
  27136. 0x7C, 0x24, 0x54, 0x47, 0x42, 0x94, 0x81, 0xD4,
  27137. 0x98, 0xBE, 0xB7, 0x25, 0x6B, 0xC4, 0x7F, 0x68,
  27138. 0xF9, 0x92, 0x2B, 0x0B, 0x1C, 0x62, 0xD9, 0xC2,
  27139. 0x3F, 0x9F, 0x73, 0x3D, 0xD7, 0x37, 0x92, 0xCF,
  27140. 0xC7, 0xB4, 0x3C, 0xBC, 0xEA, 0x27, 0x7D, 0x51,
  27141. 0xB2, 0xB8, 0xAD, 0x4A, 0x4F, 0x52, 0x2F, 0x64,
  27142. 0x2C, 0xAD, 0x5C, 0x5D, 0xEB, 0x21, 0xF3, 0x62,
  27143. 0x7F, 0x8A, 0xF4, 0xD3, 0xE5, 0xBC, 0x9E, 0x91,
  27144. 0xD4, 0xCB, 0x2F, 0x12, 0x4B, 0x5B, 0xD7, 0xC2,
  27145. 0xF4, 0xA0, 0x50, 0xCA, 0x75, 0x5B, 0xDB, 0x80,
  27146. 0x56, 0x60, 0x96, 0x63, 0xFB, 0x95, 0x11, 0xC9,
  27147. 0xAD, 0x83, 0xB5, 0x03, 0x90, 0x88, 0xCC, 0x01,
  27148. 0xF0, 0xDD, 0x54, 0x35, 0x3B, 0x0D, 0xD7, 0x43,
  27149. 0x3F, 0x0C, 0x6C, 0xEE, 0x0D, 0x07, 0x59, 0x59,
  27150. 0x81, 0x0D, 0xEC, 0x54, 0x16, 0x52, 0x2B, 0xB1,
  27151. 0xF1, 0xF6, 0x55, 0x47, 0xA0, 0xC2, 0xE9, 0xCC,
  27152. 0x9B, 0xC1, 0x7F, 0x8D, 0x39, 0xD2, 0x93, 0x09,
  27153. 0xEB, 0xE7, 0x9F, 0x21, 0x33, 0x1B, 0x75, 0xE1,
  27154. 0x2A, 0xF2, 0xE9, 0x3F, 0x03, 0xF7, 0x4F, 0x7F,
  27155. 0x87, 0xD3, 0x60, 0xF1, 0xDA, 0xF8, 0x6C, 0xED,
  27156. 0x73, 0x60, 0x92, 0xA2, 0x11, 0xA8, 0x15, 0x88,
  27157. 0x59, 0xC4, 0x2E, 0x22, 0x3C, 0xFE, 0x2E, 0x6E,
  27158. 0x55, 0x34, 0x37, 0xD8, 0x05, 0x76, 0xCF, 0xD1,
  27159. 0x94, 0x4E, 0x97, 0xEE, 0xFF, 0x9B, 0x49, 0xE5,
  27160. 0xEC, 0xCF, 0xC6, 0x78, 0xEE, 0x16, 0x52, 0x68,
  27161. 0xDF, 0xE3, 0xD3, 0x59, 0x6B, 0x4B, 0x86, 0x20,
  27162. 0x4A, 0x81, 0xC6, 0x06, 0x3B, 0x0C, 0xDC, 0xE6,
  27163. 0x19, 0xFD, 0xBB, 0x96, 0xDF, 0x7D, 0xE6, 0xE0,
  27164. 0xBD, 0x52, 0x70, 0xB4, 0xD5, 0x9C, 0x4D, 0xC5,
  27165. 0x08, 0x47, 0x6E, 0x7F, 0x07, 0x08, 0xF9, 0x8C,
  27166. 0x7A, 0x4F, 0x66, 0x45, 0xC4, 0x9D, 0x06, 0x10,
  27167. 0x0C, 0x76, 0x0C, 0x59, 0x95, 0x28, 0xD1, 0xB8,
  27168. 0xBB, 0xFE, 0x62, 0x81, 0x91, 0xCC, 0x08, 0x3C,
  27169. 0x8D, 0x22, 0x5A, 0x09, 0x3F, 0x9F, 0x17, 0xE3,
  27170. 0x55, 0x74, 0x98, 0x6F, 0x86, 0xBA, 0xA4, 0x68,
  27171. 0x98, 0xB5, 0x89, 0xF3, 0xCB, 0x7D, 0xB4, 0x6A,
  27172. 0x45, 0xF3, 0xED, 0xD4, 0xFA, 0xC2, 0x08, 0x08,
  27173. 0xF4, 0xCD, 0x02, 0x49, 0xDA, 0x69, 0x3F, 0x8F,
  27174. 0xAB, 0xFB, 0xD4, 0xE1, 0x0C, 0x02, 0xC6, 0x5B,
  27175. 0xA8, 0xC8, 0x61, 0x0F, 0xA8, 0xC6, 0xDF, 0x3D,
  27176. 0xBA, 0xEB, 0x67, 0x63, 0xDD, 0x48, 0x2A, 0xF4,
  27177. 0x15, 0x58, 0xB1, 0xE1, 0x5C, 0xC9, 0xC7, 0xA7,
  27178. 0x2E, 0x07, 0x16, 0x85, 0xAC, 0x19, 0xA0, 0x51,
  27179. 0xF1, 0x92, 0x45, 0xB9, 0xF7, 0x7C, 0x30, 0x38,
  27180. 0xA5, 0x4E, 0x29, 0x58, 0x62, 0x3E, 0xB8, 0x10,
  27181. 0x59, 0x55, 0x60, 0x9E, 0x27, 0xD6, 0x7C, 0xF7,
  27182. 0x2E, 0xC5, 0xC4, 0xA8, 0xE9, 0xB9, 0xC2, 0x92,
  27183. 0x4A, 0x9E, 0x22, 0x98, 0x50, 0x8B, 0xAB, 0xA1,
  27184. 0x3C, 0xF1, 0x11, 0xFD, 0xFB, 0x06, 0x2C, 0x96,
  27185. 0x07, 0xAC, 0x1A, 0xAA, 0x6C, 0x63, 0x73, 0x10,
  27186. 0xA8, 0x89, 0x4B, 0xF0, 0xB9, 0x6F, 0x0C, 0x19,
  27187. 0x13, 0x61, 0x86, 0xB6, 0x18, 0xDF, 0xFB, 0x27,
  27188. 0x55, 0x28, 0xBE, 0xD1, 0xCC, 0x27, 0x15, 0xDE,
  27189. 0xF4, 0x12, 0xF7, 0x7A, 0x3C, 0xF9, 0x66, 0x45,
  27190. 0x73, 0x3B, 0x04, 0x8A, 0x78, 0x47, 0x43, 0x20,
  27191. 0xD1, 0xA3, 0x80, 0xF5, 0xEE, 0xDB, 0xDA, 0x21,
  27192. 0xFA, 0x01, 0x25, 0xC9, 0x1D, 0x3C, 0x37, 0xC5,
  27193. 0x4B, 0xF3, 0x75, 0x2A, 0x1F, 0x84, 0x71, 0xC8,
  27194. 0x1F, 0xCA, 0xE2, 0xD3, 0xED, 0xA9, 0x66, 0xE1,
  27195. 0x4E, 0x66, 0xF2, 0x23, 0xB0, 0x54, 0xD7, 0x98,
  27196. 0x48, 0xFF, 0x94, 0x11, 0xD6, 0x34, 0x02, 0x4A,
  27197. 0x09, 0x89, 0x70, 0xAD, 0xE6, 0xA8, 0x8B, 0x5F,
  27198. 0x90, 0x69, 0xF7, 0x60, 0x58, 0x4D, 0xC4, 0xCF,
  27199. 0xFF, 0xCE, 0xA8, 0xEC, 0xE1, 0x1B, 0xB5, 0x56,
  27200. 0x6B, 0xD2, 0x36, 0x0A, 0xB7, 0x07, 0xDF, 0x2D,
  27201. 0x21, 0xB6, 0x74, 0x88, 0xD9, 0x31, 0xF0, 0x20,
  27202. 0x06, 0x91, 0x76, 0x42, 0x3E, 0x69, 0x44, 0x49,
  27203. 0x0C, 0xB3, 0x85, 0xE7, 0x0B, 0x35, 0x8A, 0x25,
  27204. 0x34, 0x6B, 0xAF, 0xCD, 0xD0, 0x6D, 0x40, 0x2F,
  27205. 0xF2, 0x4D, 0x6C, 0x1E, 0x5F, 0x61, 0xA8, 0x5D
  27206. };
  27207. static const byte kprime_512[KYBER_SS_SZ] = {
  27208. 0xDF, 0x46, 0x2A, 0xD6, 0x8F, 0x1E, 0xC8, 0x97,
  27209. 0x2E, 0xD9, 0xB0, 0x2D, 0x6D, 0xE0, 0x60, 0x4B,
  27210. 0xDE, 0xC7, 0x57, 0x20, 0xE0, 0x50, 0x49, 0x73,
  27211. 0x51, 0xE6, 0xEC, 0x93, 0x3E, 0x71, 0xF8, 0x82
  27212. };
  27213. #endif
  27214. #ifndef WOLFSSL_NO_KYBER768
  27215. static const byte dk_768[KYBER768_PRIVATE_KEY_SIZE] = {
  27216. 0x1E, 0x4A, 0xC8, 0x7B, 0x1A, 0x69, 0x2A, 0x52,
  27217. 0x9F, 0xDB, 0xBA, 0xB9, 0x33, 0x74, 0xC5, 0x7D,
  27218. 0x11, 0x0B, 0x10, 0xF2, 0xB1, 0xDD, 0xEB, 0xAC,
  27219. 0x0D, 0x19, 0x6B, 0x7B, 0xA6, 0x31, 0xB8, 0xE9,
  27220. 0x29, 0x30, 0x28, 0xA8, 0xF3, 0x79, 0x88, 0x8C,
  27221. 0x42, 0x2D, 0xC8, 0xD3, 0x2B, 0xBF, 0x22, 0x60,
  27222. 0x10, 0xC2, 0xC1, 0xEC, 0x73, 0x18, 0x90, 0x80,
  27223. 0x45, 0x6B, 0x05, 0x64, 0xB2, 0x58, 0xB0, 0xF2,
  27224. 0x31, 0x31, 0xBC, 0x79, 0xC8, 0xE8, 0xC1, 0x1C,
  27225. 0xEF, 0x39, 0x38, 0xB2, 0x43, 0xC5, 0xCE, 0x9C,
  27226. 0x0E, 0xDD, 0x37, 0xC8, 0xF9, 0xD2, 0x98, 0x77,
  27227. 0xDB, 0xBB, 0x61, 0x5B, 0x9B, 0x5A, 0xC3, 0xC9,
  27228. 0x48, 0x48, 0x7E, 0x46, 0x71, 0x96, 0xA9, 0x14,
  27229. 0x3E, 0xFB, 0xC7, 0xCE, 0xDB, 0x64, 0xB4, 0x5D,
  27230. 0x4A, 0xCD, 0xA2, 0x66, 0x6C, 0xBC, 0x28, 0x04,
  27231. 0xF2, 0xC8, 0x66, 0x2E, 0x12, 0x8F, 0x6A, 0x99,
  27232. 0x69, 0xEC, 0x15, 0xBC, 0x0B, 0x93, 0x51, 0xF6,
  27233. 0xF9, 0x63, 0x46, 0xAA, 0x7A, 0xBC, 0x74, 0x3A,
  27234. 0x14, 0xFA, 0x03, 0x0E, 0x37, 0xA2, 0xE7, 0x59,
  27235. 0x7B, 0xDD, 0xFC, 0x5A, 0x22, 0xF9, 0xCE, 0xDA,
  27236. 0xF8, 0x61, 0x48, 0x32, 0x52, 0x72, 0x10, 0xB2,
  27237. 0x6F, 0x02, 0x4C, 0x7F, 0x6C, 0x0D, 0xCF, 0x55,
  27238. 0x1E, 0x97, 0xA4, 0x85, 0x87, 0x64, 0xC3, 0x21,
  27239. 0xD1, 0x83, 0x4A, 0xD5, 0x1D, 0x75, 0xBB, 0x24,
  27240. 0x6D, 0x27, 0x72, 0x37, 0xB7, 0xBD, 0x41, 0xDC,
  27241. 0x43, 0x62, 0xD0, 0x63, 0xF4, 0x29, 0x82, 0x92,
  27242. 0x27, 0x2D, 0x01, 0x01, 0x17, 0x80, 0xB7, 0x98,
  27243. 0x56, 0xB2, 0x96, 0xC4, 0xE9, 0x46, 0x65, 0x8B,
  27244. 0x79, 0x60, 0x31, 0x97, 0xC9, 0xB2, 0xA9, 0x9E,
  27245. 0xC6, 0x6A, 0xCB, 0x06, 0xCE, 0x2F, 0x69, 0xB5,
  27246. 0xA5, 0xA6, 0x1E, 0x9B, 0xD0, 0x6A, 0xD4, 0x43,
  27247. 0xCE, 0xB0, 0xC7, 0x4E, 0xD6, 0x53, 0x45, 0xA9,
  27248. 0x03, 0xB6, 0x14, 0xE8, 0x13, 0x68, 0xAA, 0xC2,
  27249. 0xB3, 0xD2, 0xA7, 0x9C, 0xA8, 0xCC, 0xAA, 0x1C,
  27250. 0x3B, 0x88, 0xFB, 0x82, 0xA3, 0x66, 0x32, 0x86,
  27251. 0x0B, 0x3F, 0x79, 0x50, 0x83, 0x3F, 0xD0, 0x21,
  27252. 0x2E, 0xC9, 0x6E, 0xDE, 0x4A, 0xB6, 0xF5, 0xA0,
  27253. 0xBD, 0xA3, 0xEC, 0x60, 0x60, 0xA6, 0x58, 0xF9,
  27254. 0x45, 0x7F, 0x6C, 0xC8, 0x7C, 0x6B, 0x62, 0x0C,
  27255. 0x1A, 0x14, 0x51, 0x98, 0x74, 0x86, 0xE4, 0x96,
  27256. 0x61, 0x2A, 0x10, 0x1D, 0x0E, 0x9C, 0x20, 0x57,
  27257. 0x7C, 0x57, 0x1E, 0xDB, 0x52, 0x82, 0x60, 0x8B,
  27258. 0xF4, 0xE1, 0xAC, 0x92, 0x6C, 0x0D, 0xB1, 0xC8,
  27259. 0x2A, 0x50, 0x4A, 0x79, 0x9D, 0x89, 0x88, 0x5C,
  27260. 0xA6, 0x25, 0x2B, 0xD5, 0xB1, 0xC1, 0x83, 0xAF,
  27261. 0x70, 0x13, 0x92, 0xA4, 0x07, 0xC0, 0x5B, 0x84,
  27262. 0x8C, 0x2A, 0x30, 0x16, 0xC4, 0x06, 0x13, 0xF0,
  27263. 0x2A, 0x44, 0x9B, 0x3C, 0x79, 0x26, 0xDA, 0x06,
  27264. 0x7A, 0x53, 0x31, 0x16, 0x50, 0x68, 0x40, 0x09,
  27265. 0x75, 0x10, 0x46, 0x0B, 0xBF, 0xD3, 0x60, 0x73,
  27266. 0xDC, 0xB0, 0xBF, 0xA0, 0x09, 0xB3, 0x6A, 0x91,
  27267. 0x23, 0xEA, 0xA6, 0x8F, 0x83, 0x5F, 0x74, 0xA0,
  27268. 0x1B, 0x00, 0xD2, 0x09, 0x78, 0x35, 0x96, 0x4D,
  27269. 0xF5, 0x21, 0xCE, 0x92, 0x10, 0x78, 0x9C, 0x30,
  27270. 0xB7, 0xF0, 0x6E, 0x58, 0x44, 0xB4, 0x44, 0xC5,
  27271. 0x33, 0x22, 0x39, 0x6E, 0x47, 0x99, 0xBA, 0xF6,
  27272. 0xA8, 0x8A, 0xF7, 0x31, 0x58, 0x60, 0xD0, 0x19,
  27273. 0x2D, 0x48, 0xC2, 0xC0, 0xDA, 0x6B, 0x5B, 0xA6,
  27274. 0x43, 0x25, 0x54, 0x3A, 0xCD, 0xF5, 0x90, 0x0E,
  27275. 0x8B, 0xC4, 0x77, 0xAB, 0x05, 0x82, 0x00, 0x72,
  27276. 0xD4, 0x63, 0xAF, 0xFE, 0xD0, 0x97, 0xE0, 0x62,
  27277. 0xBD, 0x78, 0xC9, 0x9D, 0x12, 0xB3, 0x85, 0x13,
  27278. 0x1A, 0x24, 0x1B, 0x70, 0x88, 0x65, 0xB4, 0x19,
  27279. 0x0A, 0xF6, 0x9E, 0xA0, 0xA6, 0x4D, 0xB7, 0x14,
  27280. 0x48, 0xA6, 0x08, 0x29, 0x36, 0x9C, 0x75, 0x55,
  27281. 0x19, 0x8E, 0x43, 0x8C, 0x9A, 0xBC, 0x31, 0x0B,
  27282. 0xC7, 0x01, 0x01, 0x91, 0x3B, 0xB1, 0x2F, 0xAA,
  27283. 0x5B, 0xEE, 0xF9, 0x75, 0x84, 0x16, 0x17, 0xC8,
  27284. 0x47, 0xCD, 0x6B, 0x33, 0x6F, 0x87, 0x79, 0x87,
  27285. 0x75, 0x38, 0x22, 0x02, 0x0B, 0x92, 0xC4, 0xCC,
  27286. 0x97, 0x05, 0x5C, 0x9B, 0x1E, 0x0B, 0x12, 0x8B,
  27287. 0xF1, 0x1F, 0x50, 0x50, 0x05, 0xB6, 0xAB, 0x0E,
  27288. 0x62, 0x77, 0x95, 0xA2, 0x06, 0x09, 0xEF, 0xA9,
  27289. 0x91, 0xE5, 0x98, 0xB8, 0x0F, 0x37, 0xB1, 0xC6,
  27290. 0xA1, 0xC3, 0xA1, 0xE9, 0xAE, 0xE7, 0x02, 0x8F,
  27291. 0x77, 0x57, 0x0A, 0xB2, 0x13, 0x91, 0x28, 0xA0,
  27292. 0x01, 0x08, 0xC5, 0x0E, 0xB3, 0x05, 0xCD, 0xB8,
  27293. 0xF9, 0xA6, 0x03, 0xA6, 0xB0, 0x78, 0x41, 0x3F,
  27294. 0x6F, 0x9B, 0x14, 0xC6, 0xD8, 0x2B, 0x51, 0x99,
  27295. 0xCE, 0x59, 0xD8, 0x87, 0x90, 0x2A, 0x28, 0x1A,
  27296. 0x02, 0x7B, 0x71, 0x74, 0x95, 0xFE, 0x12, 0x67,
  27297. 0x2A, 0x12, 0x7B, 0xBF, 0x9B, 0x25, 0x6C, 0x43,
  27298. 0x72, 0x0D, 0x7C, 0x16, 0x0B, 0x28, 0x1C, 0x12,
  27299. 0x75, 0x7D, 0xA1, 0x35, 0xB1, 0x93, 0x33, 0x52,
  27300. 0xBE, 0x4A, 0xB6, 0x7E, 0x40, 0x24, 0x8A, 0xFC,
  27301. 0x31, 0x8E, 0x23, 0x70, 0xC3, 0xB8, 0x20, 0x8E,
  27302. 0x69, 0x5B, 0xDF, 0x33, 0x74, 0x59, 0xB9, 0xAC,
  27303. 0xBF, 0xE5, 0xB4, 0x87, 0xF7, 0x6E, 0x9B, 0x4B,
  27304. 0x40, 0x01, 0xD6, 0xCF, 0x90, 0xCA, 0x8C, 0x69,
  27305. 0x9A, 0x17, 0x4D, 0x42, 0x97, 0x2D, 0xC7, 0x33,
  27306. 0xF3, 0x33, 0x89, 0xFD, 0xF5, 0x9A, 0x1D, 0xAB,
  27307. 0xA8, 0x1D, 0x83, 0x49, 0x55, 0x02, 0x73, 0x34,
  27308. 0x18, 0x5A, 0xD0, 0x2C, 0x76, 0xCF, 0x29, 0x48,
  27309. 0x46, 0xCA, 0x92, 0x94, 0xBA, 0x0E, 0xD6, 0x67,
  27310. 0x41, 0xDD, 0xEC, 0x79, 0x1C, 0xAB, 0x34, 0x19,
  27311. 0x6A, 0xC5, 0x65, 0x7C, 0x5A, 0x78, 0x32, 0x1B,
  27312. 0x56, 0xC3, 0x33, 0x06, 0xB5, 0x10, 0x23, 0x97,
  27313. 0xA5, 0xC0, 0x9C, 0x35, 0x08, 0xF7, 0x6B, 0x48,
  27314. 0x28, 0x24, 0x59, 0xF8, 0x1D, 0x0C, 0x72, 0xA4,
  27315. 0x3F, 0x73, 0x7B, 0xC2, 0xF1, 0x2F, 0x45, 0x42,
  27316. 0x26, 0x28, 0xB6, 0x7D, 0xB5, 0x1A, 0xC1, 0x42,
  27317. 0x42, 0x76, 0xA6, 0xC0, 0x8C, 0x3F, 0x76, 0x15,
  27318. 0x66, 0x5B, 0xBB, 0x8E, 0x92, 0x81, 0x48, 0xA2,
  27319. 0x70, 0xF9, 0x91, 0xBC, 0xF3, 0x65, 0xA9, 0x0F,
  27320. 0x87, 0xC3, 0x06, 0x87, 0xB6, 0x88, 0x09, 0xC9,
  27321. 0x1F, 0x23, 0x18, 0x13, 0xB8, 0x66, 0xBE, 0xA8,
  27322. 0x2E, 0x30, 0x37, 0x4D, 0x80, 0xAA, 0x0C, 0x02,
  27323. 0x97, 0x34, 0x37, 0x49, 0x8A, 0x53, 0xB1, 0x4B,
  27324. 0xF6, 0xB6, 0xCA, 0x1E, 0xD7, 0x6A, 0xB8, 0xA2,
  27325. 0x0D, 0x54, 0xA0, 0x83, 0xF4, 0xA2, 0x6B, 0x7C,
  27326. 0x03, 0x8D, 0x81, 0x96, 0x76, 0x40, 0xC2, 0x0B,
  27327. 0xF4, 0x43, 0x1E, 0x71, 0xDA, 0xCC, 0xE8, 0x57,
  27328. 0x7B, 0x21, 0x24, 0x0E, 0x49, 0x4C, 0x31, 0xF2,
  27329. 0xD8, 0x77, 0xDA, 0xF4, 0x92, 0x4F, 0xD3, 0x9D,
  27330. 0x82, 0xD6, 0x16, 0x7F, 0xBC, 0xC1, 0xF9, 0xC5,
  27331. 0xA2, 0x59, 0xF8, 0x43, 0xE3, 0x09, 0x87, 0xCC,
  27332. 0xC4, 0xBC, 0xE7, 0x49, 0x3A, 0x24, 0x04, 0xB5,
  27333. 0xE4, 0x43, 0x87, 0xF7, 0x07, 0x42, 0x57, 0x81,
  27334. 0xB7, 0x43, 0xFB, 0x55, 0x56, 0x85, 0x58, 0x4E,
  27335. 0x25, 0x57, 0xCC, 0x03, 0x8B, 0x1A, 0x9B, 0x3F,
  27336. 0x40, 0x43, 0x12, 0x1F, 0x54, 0x72, 0xEB, 0x2B,
  27337. 0x96, 0xE5, 0x94, 0x1F, 0xEC, 0x01, 0x1C, 0xEE,
  27338. 0xA5, 0x07, 0x91, 0x63, 0x6C, 0x6A, 0xBC, 0x26,
  27339. 0xC1, 0x37, 0x7E, 0xE3, 0xB5, 0x14, 0x6F, 0xC7,
  27340. 0xC8, 0x5C, 0xB3, 0x35, 0xB1, 0xE7, 0x95, 0xEE,
  27341. 0xC2, 0x03, 0x3E, 0xE4, 0x4B, 0x9A, 0xA9, 0x06,
  27342. 0x85, 0x24, 0x5E, 0xF7, 0xB4, 0x43, 0x6C, 0x00,
  27343. 0x0E, 0x66, 0xBC, 0x8B, 0xCB, 0xF1, 0xCD, 0xB8,
  27344. 0x03, 0xAC, 0x14, 0x21, 0xB1, 0xFD, 0xB2, 0x66,
  27345. 0xD5, 0x29, 0x1C, 0x83, 0x10, 0x37, 0x3A, 0x8A,
  27346. 0x3C, 0xE9, 0x56, 0x2A, 0xB1, 0x97, 0x95, 0x38,
  27347. 0x71, 0xAB, 0x99, 0xF3, 0x82, 0xCC, 0x5A, 0xA9,
  27348. 0xC0, 0xF2, 0x73, 0xD1, 0xDC, 0xA5, 0x5D, 0x27,
  27349. 0x12, 0x85, 0x38, 0x71, 0xE1, 0xA8, 0x3C, 0xB3,
  27350. 0xB8, 0x54, 0x50, 0xF7, 0x6D, 0x3F, 0x3C, 0x42,
  27351. 0xBA, 0xB5, 0x50, 0x5F, 0x72, 0x12, 0xFD, 0xB6,
  27352. 0xB8, 0xB7, 0xF6, 0x02, 0x99, 0x72, 0xA8, 0xF3,
  27353. 0x75, 0x1E, 0x4C, 0x94, 0xC1, 0x10, 0x8B, 0x02,
  27354. 0xD6, 0xAC, 0x79, 0xF8, 0xD9, 0x38, 0xF0, 0x5A,
  27355. 0x1B, 0x2C, 0x22, 0x9B, 0x14, 0xB4, 0x2B, 0x31,
  27356. 0xB0, 0x1A, 0x36, 0x40, 0x17, 0xE5, 0x95, 0x78,
  27357. 0xC6, 0xB0, 0x33, 0x83, 0x37, 0x74, 0xCB, 0x9B,
  27358. 0x57, 0x0F, 0x90, 0x86, 0xB7, 0x22, 0x90, 0x3B,
  27359. 0x37, 0x54, 0x46, 0xB4, 0x95, 0xD8, 0xA2, 0x9B,
  27360. 0xF8, 0x07, 0x51, 0x87, 0x7A, 0x80, 0xFB, 0x72,
  27361. 0x4A, 0x02, 0x10, 0xC3, 0xE1, 0x69, 0x2F, 0x39,
  27362. 0x7C, 0x2F, 0x1D, 0xDC, 0x2E, 0x6B, 0xA1, 0x7A,
  27363. 0xF8, 0x1B, 0x92, 0xAC, 0xFA, 0xBE, 0xF5, 0xF7,
  27364. 0x57, 0x3C, 0xB4, 0x93, 0xD1, 0x84, 0x02, 0x7B,
  27365. 0x71, 0x82, 0x38, 0xC8, 0x9A, 0x35, 0x49, 0xB8,
  27366. 0x90, 0x5B, 0x28, 0xA8, 0x33, 0x62, 0x86, 0x7C,
  27367. 0x08, 0x2D, 0x30, 0x19, 0xD3, 0xCA, 0x70, 0x70,
  27368. 0x07, 0x31, 0xCE, 0xB7, 0x3E, 0x84, 0x72, 0xC1,
  27369. 0xA3, 0xA0, 0x93, 0x36, 0x1C, 0x5F, 0xEA, 0x6A,
  27370. 0x7D, 0x40, 0x95, 0x5D, 0x07, 0xA4, 0x1B, 0x64,
  27371. 0xE5, 0x00, 0x81, 0xA3, 0x61, 0xB6, 0x04, 0xCC,
  27372. 0x51, 0x84, 0x47, 0xC8, 0xE2, 0x57, 0x65, 0xAB,
  27373. 0x7D, 0x68, 0xB2, 0x43, 0x27, 0x52, 0x07, 0xAF,
  27374. 0x8C, 0xA6, 0x56, 0x4A, 0x4C, 0xB1, 0xE9, 0x41,
  27375. 0x99, 0xDB, 0xA1, 0x87, 0x8C, 0x59, 0xBE, 0xC8,
  27376. 0x09, 0xAB, 0x48, 0xB2, 0xF2, 0x11, 0xBA, 0xDC,
  27377. 0x6A, 0x19, 0x98, 0xD9, 0xC7, 0x22, 0x7C, 0x13,
  27378. 0x03, 0xF4, 0x69, 0xD4, 0x6A, 0x9C, 0x7E, 0x53,
  27379. 0x03, 0xF9, 0x8A, 0xBA, 0x67, 0x56, 0x9A, 0xE8,
  27380. 0x22, 0x7C, 0x16, 0xBA, 0x1F, 0xB3, 0x24, 0x44,
  27381. 0x66, 0xA2, 0x5E, 0x7F, 0x82, 0x36, 0x71, 0x81,
  27382. 0x0C, 0xC2, 0x62, 0x06, 0xFE, 0xB2, 0x9C, 0x7E,
  27383. 0x2A, 0x1A, 0x91, 0x95, 0x9E, 0xEB, 0x03, 0xA9,
  27384. 0x82, 0x52, 0xA4, 0xF7, 0x41, 0x26, 0x74, 0xEB,
  27385. 0x9A, 0x4B, 0x27, 0x7E, 0x1F, 0x25, 0x95, 0xFC,
  27386. 0xA6, 0x40, 0x33, 0xB4, 0x1B, 0x40, 0x33, 0x08,
  27387. 0x12, 0xE9, 0x73, 0x5B, 0x7C, 0x60, 0x75, 0x01,
  27388. 0xCD, 0x81, 0x83, 0xA2, 0x2A, 0xFC, 0x33, 0x92,
  27389. 0x55, 0x37, 0x44, 0xF3, 0x3C, 0x4D, 0x20, 0x25,
  27390. 0x26, 0x94, 0x5C, 0x6D, 0x78, 0xA6, 0x0E, 0x20,
  27391. 0x1A, 0x16, 0x98, 0x7A, 0x6F, 0xA5, 0x9D, 0x94,
  27392. 0x46, 0x4B, 0x56, 0x50, 0x65, 0x56, 0x78, 0x48,
  27393. 0x24, 0xA0, 0x70, 0x58, 0xF5, 0x73, 0x20, 0xE7,
  27394. 0x6C, 0x82, 0x5B, 0x93, 0x47, 0xF2, 0x93, 0x6F,
  27395. 0x4A, 0x0E, 0x5C, 0xDA, 0xA1, 0x8C, 0xF8, 0x83,
  27396. 0x39, 0x45, 0xAE, 0x31, 0x2A, 0x36, 0xB5, 0xF5,
  27397. 0xA3, 0x81, 0x0A, 0xAC, 0x82, 0x38, 0x1F, 0xDA,
  27398. 0xE4, 0xCB, 0x9C, 0x68, 0x31, 0xD8, 0xEB, 0x8A,
  27399. 0xBA, 0xB8, 0x50, 0x41, 0x64, 0x43, 0xD7, 0x39,
  27400. 0x08, 0x6B, 0x1C, 0x32, 0x6F, 0xC2, 0xA3, 0x97,
  27401. 0x57, 0x04, 0xE3, 0x96, 0xA5, 0x96, 0x80, 0xC3,
  27402. 0xB5, 0xF3, 0x60, 0xF5, 0x48, 0x0D, 0x2B, 0x62,
  27403. 0x16, 0x9C, 0xD9, 0x4C, 0xA7, 0x1B, 0x37, 0xBC,
  27404. 0x58, 0x78, 0xBA, 0x29, 0x85, 0xE0, 0x68, 0xBA,
  27405. 0x05, 0x0B, 0x2C, 0xE5, 0x07, 0x26, 0xD4, 0xB4,
  27406. 0x45, 0x1B, 0x77, 0xAA, 0xA8, 0x67, 0x6E, 0xAE,
  27407. 0x09, 0x49, 0x82, 0x21, 0x01, 0x92, 0x19, 0x7B,
  27408. 0x1E, 0x92, 0xA2, 0x7F, 0x59, 0x86, 0x8B, 0x78,
  27409. 0x86, 0x78, 0x87, 0xB9, 0xA7, 0x0C, 0x32, 0xAF,
  27410. 0x84, 0x63, 0x0A, 0xA9, 0x08, 0x81, 0x43, 0x79,
  27411. 0xE6, 0x51, 0x91, 0x50, 0xBA, 0x16, 0x43, 0x9B,
  27412. 0x5E, 0x2B, 0x06, 0x03, 0xD0, 0x6A, 0xA6, 0x67,
  27413. 0x45, 0x57, 0xF5, 0xB0, 0x98, 0x3E, 0x5C, 0xB6,
  27414. 0xA9, 0x75, 0x96, 0x06, 0x9B, 0x01, 0xBB, 0x31,
  27415. 0x28, 0xC4, 0x16, 0x68, 0x06, 0x57, 0x20, 0x4F,
  27416. 0xD0, 0x76, 0x40, 0x39, 0x2E, 0x16, 0xB1, 0x9F,
  27417. 0x33, 0x7A, 0x99, 0xA3, 0x04, 0x84, 0x4E, 0x1A,
  27418. 0xA4, 0x74, 0xE9, 0xC7, 0x99, 0x06, 0x29, 0x71,
  27419. 0xF6, 0x72, 0x26, 0x89, 0x60, 0xF5, 0xA8, 0x2F,
  27420. 0x95, 0x00, 0x70, 0xBB, 0xE9, 0xC2, 0xA7, 0x19,
  27421. 0x50, 0xA3, 0x78, 0x5B, 0xDF, 0x0B, 0x84, 0x40,
  27422. 0x25, 0x5E, 0xD6, 0x39, 0x28, 0xD2, 0x57, 0x84,
  27423. 0x51, 0x68, 0xB1, 0xEC, 0xCC, 0x41, 0x91, 0x32,
  27424. 0x5A, 0xA7, 0x66, 0x45, 0x71, 0x9B, 0x28, 0xEB,
  27425. 0xD8, 0x93, 0x02, 0xDC, 0x67, 0x23, 0xC7, 0x86,
  27426. 0xDF, 0x52, 0x17, 0xB2, 0x43, 0x09, 0x9C, 0xA7,
  27427. 0x82, 0x38, 0xE5, 0x7E, 0x64, 0x69, 0x2F, 0x20,
  27428. 0x6B, 0x17, 0x7A, 0xBC, 0x25, 0x96, 0x60, 0x39,
  27429. 0x5C, 0xD7, 0x86, 0x0F, 0xB3, 0x5A, 0x16, 0xF6,
  27430. 0xB2, 0xFE, 0x65, 0x48, 0xC8, 0x5A, 0xB6, 0x63,
  27431. 0x30, 0xC5, 0x17, 0xFA, 0x74, 0xCD, 0xF3, 0xCB,
  27432. 0x49, 0xD2, 0x6B, 0x11, 0x81, 0x90, 0x1A, 0xF7,
  27433. 0x75, 0xA1, 0xE1, 0x80, 0x81, 0x3B, 0x6A, 0x24,
  27434. 0xC4, 0x56, 0x82, 0x9B, 0x5C, 0x38, 0x10, 0x4E,
  27435. 0xCE, 0x43, 0xC7, 0x6A, 0x43, 0x7A, 0x6A, 0x33,
  27436. 0xB6, 0xFC, 0x6C, 0x5E, 0x65, 0xC8, 0xA8, 0x94,
  27437. 0x66, 0xC1, 0x42, 0x54, 0x85, 0xB2, 0x9B, 0x9E,
  27438. 0x18, 0x54, 0x36, 0x8A, 0xFC, 0xA3, 0x53, 0xE1,
  27439. 0x43, 0xD0, 0xA9, 0x0A, 0x6C, 0x6C, 0x9E, 0x7F,
  27440. 0xDB, 0x62, 0xA6, 0x06, 0x85, 0x6B, 0x56, 0x14,
  27441. 0xF1, 0x2B, 0x64, 0xB7, 0x96, 0x02, 0x0C, 0x35,
  27442. 0x34, 0xC3, 0x60, 0x5C, 0xFD, 0xC7, 0x3B, 0x86,
  27443. 0x71, 0x4F, 0x41, 0x18, 0x50, 0x22, 0x8A, 0x28,
  27444. 0xB8, 0xF4, 0xB4, 0x9E, 0x66, 0x34, 0x16, 0xC8,
  27445. 0x4F, 0x7E, 0x38, 0x1F, 0x6A, 0xF1, 0x07, 0x13,
  27446. 0x43, 0xBF, 0x9D, 0x39, 0xB4, 0x54, 0x39, 0x24,
  27447. 0x0C, 0xC0, 0x38, 0x97, 0x29, 0x5F, 0xEA, 0x08,
  27448. 0x0B, 0x14, 0xBB, 0x2D, 0x81, 0x19, 0xA8, 0x80,
  27449. 0xE1, 0x64, 0x49, 0x5C, 0x61, 0xBE, 0xBC, 0x71,
  27450. 0x39, 0xC1, 0x18, 0x57, 0xC8, 0x5E, 0x17, 0x50,
  27451. 0x33, 0x8D, 0x63, 0x43, 0x91, 0x37, 0x06, 0xA5,
  27452. 0x07, 0xC9, 0x56, 0x64, 0x64, 0xCD, 0x28, 0x37,
  27453. 0xCF, 0x91, 0x4D, 0x1A, 0x3C, 0x35, 0xE8, 0x9B,
  27454. 0x23, 0x5C, 0x6A, 0xB7, 0xED, 0x07, 0x8B, 0xED,
  27455. 0x23, 0x47, 0x57, 0xC0, 0x2E, 0xF6, 0x99, 0x3D,
  27456. 0x4A, 0x27, 0x3C, 0xB8, 0x15, 0x05, 0x28, 0xDA,
  27457. 0x4D, 0x76, 0x70, 0x81, 0x77, 0xE9, 0x42, 0x55,
  27458. 0x46, 0xC8, 0x3E, 0x14, 0x70, 0x39, 0x76, 0x66,
  27459. 0x03, 0xB3, 0x0D, 0xA6, 0x26, 0x8F, 0x45, 0x98,
  27460. 0xA5, 0x31, 0x94, 0x24, 0x0A, 0x28, 0x32, 0xA3,
  27461. 0xD6, 0x75, 0x33, 0xB5, 0x05, 0x6F, 0x9A, 0xAA,
  27462. 0xC6, 0x1B, 0x4B, 0x17, 0xB9, 0xA2, 0x69, 0x3A,
  27463. 0xA0, 0xD5, 0x88, 0x91, 0xE6, 0xCC, 0x56, 0xCD,
  27464. 0xD7, 0x72, 0x41, 0x09, 0x00, 0xC4, 0x05, 0xAF,
  27465. 0x20, 0xB9, 0x03, 0x79, 0x7C, 0x64, 0x87, 0x69,
  27466. 0x15, 0xC3, 0x7B, 0x84, 0x87, 0xA1, 0x44, 0x9C,
  27467. 0xE9, 0x24, 0xCD, 0x34, 0x5C, 0x29, 0xA3, 0x6E,
  27468. 0x08, 0x23, 0x8F, 0x7A, 0x15, 0x7C, 0xC7, 0xE5,
  27469. 0x16, 0xAB, 0x5B, 0xA7, 0x3C, 0x80, 0x63, 0xF7,
  27470. 0x26, 0xBB, 0x5A, 0x0A, 0x03, 0x19, 0xE5, 0x71,
  27471. 0x27, 0x43, 0x8C, 0x7F, 0xC6, 0x01, 0xC9, 0x9C,
  27472. 0xCA, 0xAE, 0x4C, 0x1A, 0x83, 0x72, 0x6F, 0xDC,
  27473. 0xB5, 0x04, 0x5E, 0xD1, 0xA8, 0x2A, 0x98, 0x5E,
  27474. 0xA9, 0x95, 0x39, 0x6D, 0x77, 0x27, 0x2C, 0x66,
  27475. 0xCE, 0x49, 0x32, 0x89, 0xF6, 0x11, 0x09, 0x10,
  27476. 0xF3, 0x7C, 0x27, 0x41, 0xCE, 0x47, 0x02, 0x6A,
  27477. 0x6F, 0x82, 0x61, 0x99, 0x9C, 0x64, 0x82, 0x57,
  27478. 0x2B, 0x16, 0x93, 0x91, 0x2E, 0xF1, 0x2E, 0xEB,
  27479. 0xEA, 0x7A, 0xCF, 0x92, 0x34, 0xFB, 0x40, 0x9F,
  27480. 0x2A, 0x60, 0x90, 0xE6, 0xB0, 0xBF, 0xD8, 0x95,
  27481. 0x46, 0x9D, 0x0B, 0x2A, 0x92, 0x1B, 0xB7, 0x23,
  27482. 0xF8, 0x7A, 0x33, 0xEA, 0x54, 0x65, 0xAB, 0x90,
  27483. 0xF5, 0x14, 0xB6, 0x76, 0x98, 0xC0, 0x76, 0x8B,
  27484. 0x6C, 0xA4, 0x98, 0xB0, 0x22, 0xC5, 0x12, 0xFA,
  27485. 0x08, 0x75, 0xF0, 0x54, 0xAA, 0x22, 0x65, 0x86,
  27486. 0x7E, 0x31, 0xC0, 0xE5, 0x22, 0x65, 0x1E, 0x02,
  27487. 0x4A, 0x07, 0xD6, 0x0D, 0xD9, 0xF6, 0x33, 0x16,
  27488. 0x69, 0x21, 0xF4, 0x12, 0x6B, 0xC2, 0xB6, 0xAA,
  27489. 0x01, 0xCC, 0x15, 0xA0, 0x9B, 0x85, 0xBF, 0xF8,
  27490. 0x21, 0x8C, 0x5A, 0xAE, 0x95, 0xBC, 0x1F, 0xFB,
  27491. 0x26, 0xAE, 0x5A, 0x13, 0x76, 0x70, 0xF0, 0x49,
  27492. 0x10, 0xCA, 0x9D, 0x72, 0x41, 0xB6, 0x66, 0x0C,
  27493. 0x39, 0x4C, 0x54, 0x55, 0x91, 0x77, 0x46, 0xA2,
  27494. 0x66, 0x82, 0xFB, 0x71, 0xA4, 0x32, 0xEA, 0x95,
  27495. 0x30, 0xE8, 0x39, 0xBD, 0xEB, 0x07, 0x43, 0x30,
  27496. 0x04, 0xF4, 0x5A, 0x0D, 0xDA, 0xA0, 0xB2, 0x4E,
  27497. 0x3A, 0x56, 0x6A, 0x54, 0x08, 0x15, 0xF2, 0x81,
  27498. 0xE3, 0xFC, 0x25, 0x9A, 0xC6, 0xCB, 0xC0, 0xAC,
  27499. 0xB8, 0xD6, 0x22, 0x68, 0xB6, 0x03, 0xBC, 0x67,
  27500. 0x6A, 0xB4, 0x15, 0xC4, 0x74, 0xBB, 0x94, 0x87,
  27501. 0x3E, 0x44, 0x87, 0xAE, 0x31, 0xA4, 0xE3, 0x84,
  27502. 0x5C, 0x79, 0x90, 0x15, 0x50, 0x89, 0x0E, 0xE8,
  27503. 0x78, 0x4E, 0xEF, 0x90, 0x4F, 0xEE, 0x62, 0xBA,
  27504. 0x8C, 0x5F, 0x95, 0x2C, 0x68, 0x41, 0x30, 0x52,
  27505. 0xE0, 0xA7, 0xE3, 0x38, 0x8B, 0xB8, 0xFF, 0x0A,
  27506. 0xD6, 0x02, 0xAE, 0x3E, 0xA1, 0x4D, 0x9D, 0xF6,
  27507. 0xDD, 0x5E, 0x4C, 0xC6, 0xA3, 0x81, 0xA4, 0x1D,
  27508. 0xA5, 0xC1, 0x37, 0xEC, 0xC4, 0x9D, 0xF5, 0x87,
  27509. 0xE1, 0x78, 0xEA, 0xF4, 0x77, 0x02, 0xEC, 0x62,
  27510. 0x37, 0x80, 0x69, 0x1A, 0x32, 0x33, 0xF6, 0x9F,
  27511. 0x12, 0xBD, 0x9C, 0x9B, 0x96, 0x37, 0xC5, 0x13,
  27512. 0x78, 0xAD, 0x71, 0xA8, 0x31, 0x05, 0x52, 0x77,
  27513. 0x25, 0x4C, 0xC6, 0x3C, 0x5A, 0xD4, 0xCB, 0x76,
  27514. 0xB4, 0xAB, 0x82, 0xE5, 0xFC, 0xA1, 0x35, 0xE8,
  27515. 0xD2, 0x6A, 0x6B, 0x3A, 0x89, 0xFA, 0x5B, 0x6F
  27516. };
  27517. static const byte c_768[KYBER768_CIPHER_TEXT_SIZE] = {
  27518. 0xA5, 0xC8, 0x1C, 0x76, 0xC2, 0x43, 0x05, 0xE1,
  27519. 0xCE, 0x5D, 0x81, 0x35, 0xD4, 0x15, 0x23, 0x68,
  27520. 0x2E, 0x9E, 0xE6, 0xD7, 0xB4, 0x0A, 0xD4, 0x1D,
  27521. 0xF1, 0xF3, 0x7C, 0x9B, 0x17, 0xDC, 0xE7, 0x80,
  27522. 0x76, 0x01, 0x9A, 0x6B, 0x0B, 0x7C, 0x95, 0xC9,
  27523. 0xBE, 0x7A, 0xF2, 0x95, 0x07, 0xB2, 0xD5, 0xA6,
  27524. 0x98, 0x7C, 0x8E, 0xE3, 0x25, 0x91, 0x90, 0x85,
  27525. 0x52, 0x43, 0xE6, 0xE5, 0x6F, 0x56, 0x20, 0x60,
  27526. 0x8C, 0x52, 0xD9, 0x6F, 0xAB, 0x10, 0x3A, 0x87,
  27527. 0x00, 0xFB, 0xA1, 0xA8, 0x7D, 0xCA, 0x60, 0x78,
  27528. 0x11, 0x8A, 0x08, 0x71, 0x76, 0x2C, 0x95, 0x34,
  27529. 0xC0, 0xC0, 0xC3, 0x97, 0x8C, 0x91, 0xC3, 0xA0,
  27530. 0x1F, 0x0F, 0x60, 0x8D, 0xCF, 0x75, 0x78, 0x15,
  27531. 0x43, 0x8F, 0xE8, 0x95, 0x7C, 0x8A, 0x85, 0x91,
  27532. 0x83, 0xB1, 0xB6, 0x72, 0x1A, 0x08, 0x65, 0xBE,
  27533. 0xBC, 0x79, 0x9D, 0x4E, 0x5C, 0x0E, 0x7B, 0xD3,
  27534. 0xEA, 0xE4, 0x85, 0x8E, 0x6A, 0xB6, 0xA2, 0xE7,
  27535. 0x65, 0x8E, 0xD8, 0x0D, 0x4E, 0xD1, 0x58, 0xB0,
  27536. 0x36, 0xB9, 0x3F, 0xA0, 0x3A, 0xFA, 0x6A, 0xE3,
  27537. 0x13, 0x6C, 0xF3, 0xD6, 0x93, 0xC9, 0x11, 0xBC,
  27538. 0xC7, 0x59, 0x05, 0xE5, 0xB0, 0xCB, 0x28, 0x65,
  27539. 0xB9, 0xE9, 0x88, 0x45, 0x22, 0xA7, 0x77, 0x77,
  27540. 0x61, 0x3E, 0x53, 0x11, 0x1D, 0x5A, 0x1C, 0x7D,
  27541. 0x3D, 0xAB, 0x73, 0x4C, 0xEB, 0x03, 0x65, 0x7A,
  27542. 0xE0, 0xC8, 0x97, 0x63, 0xE9, 0x94, 0x71, 0x05,
  27543. 0x47, 0x76, 0xBA, 0xE7, 0xD5, 0x1B, 0x0E, 0x73,
  27544. 0xA5, 0xBB, 0x35, 0xAE, 0xC3, 0x0F, 0xF6, 0xBC,
  27545. 0x93, 0x68, 0x49, 0x16, 0xFE, 0xF1, 0x16, 0x25,
  27546. 0x86, 0x45, 0x2F, 0x42, 0x66, 0x53, 0xE2, 0xCA,
  27547. 0x84, 0x4D, 0x57, 0x44, 0x30, 0x7F, 0xF9, 0xAE,
  27548. 0xB2, 0x87, 0xA6, 0x44, 0x77, 0x83, 0xB2, 0x1A,
  27549. 0x0E, 0x93, 0x9C, 0x81, 0x42, 0x1D, 0x63, 0x1F,
  27550. 0x5D, 0xCB, 0x45, 0x2E, 0x51, 0xED, 0x34, 0xE3,
  27551. 0xDA, 0xD1, 0xCF, 0x50, 0x4E, 0x0A, 0x3B, 0x0F,
  27552. 0x47, 0x11, 0xA8, 0xDC, 0x64, 0x99, 0xD1, 0x69,
  27553. 0x1D, 0x10, 0x95, 0x69, 0x33, 0x6C, 0xE1, 0x55,
  27554. 0x8A, 0x4C, 0x0A, 0x46, 0x4E, 0x20, 0x87, 0xEA,
  27555. 0x8F, 0x9E, 0x3B, 0x18, 0xF7, 0x47, 0xEF, 0x61,
  27556. 0xF4, 0x57, 0x6A, 0xEB, 0x42, 0xB1, 0x7C, 0xAD,
  27557. 0xB7, 0xF0, 0xFD, 0x84, 0xDA, 0x8E, 0x3A, 0x6F,
  27558. 0x47, 0x1D, 0x95, 0xED, 0xFA, 0x65, 0xBE, 0x9E,
  27559. 0x6C, 0x9F, 0x6A, 0xE7, 0x56, 0xA2, 0x2A, 0x4F,
  27560. 0x1A, 0x5C, 0x54, 0x3C, 0x26, 0xBA, 0x7B, 0xAD,
  27561. 0x88, 0xE1, 0x6D, 0x5F, 0x5B, 0x7E, 0x12, 0xE2,
  27562. 0xD4, 0xCA, 0x34, 0xB3, 0xA6, 0x4D, 0x17, 0xF8,
  27563. 0x7C, 0xCF, 0xC4, 0xFF, 0x8C, 0x5E, 0x4F, 0x53,
  27564. 0x75, 0x2A, 0x07, 0x7C, 0x68, 0x72, 0x1E, 0x8C,
  27565. 0xC8, 0x17, 0xF9, 0xFF, 0x24, 0x87, 0x61, 0x70,
  27566. 0xFF, 0x2A, 0xF8, 0x9F, 0xA9, 0x58, 0x55, 0xA5,
  27567. 0xB1, 0xDE, 0x34, 0x7C, 0x07, 0xFD, 0xDB, 0xCF,
  27568. 0xE7, 0x26, 0x4A, 0xA5, 0xED, 0x64, 0x01, 0x49,
  27569. 0x15, 0x61, 0xD8, 0x31, 0x53, 0x8F, 0x85, 0x2B,
  27570. 0x0E, 0xD7, 0xB9, 0xE8, 0xEB, 0xAF, 0xFC, 0x06,
  27571. 0x02, 0x84, 0xF2, 0x2D, 0x2B, 0xAE, 0xE5, 0x6F,
  27572. 0xA9, 0xF6, 0xD0, 0x14, 0x32, 0xA1, 0x15, 0xA2,
  27573. 0xD6, 0xA6, 0x4C, 0x38, 0xAE, 0x0A, 0x50, 0xBA,
  27574. 0x36, 0x2F, 0xB5, 0x7B, 0x53, 0xE3, 0xE8, 0x55,
  27575. 0xB8, 0x3C, 0xE8, 0xC4, 0x22, 0x74, 0x04, 0x55,
  27576. 0x99, 0xF6, 0x5F, 0xA6, 0xA8, 0x92, 0x1D, 0x85,
  27577. 0xF9, 0x4E, 0xD2, 0x30, 0xB5, 0x16, 0x71, 0x2D,
  27578. 0xB6, 0xFD, 0x2F, 0xF2, 0x8B, 0x3A, 0x33, 0x71,
  27579. 0xD9, 0xBE, 0x05, 0x8A, 0xE7, 0x5C, 0x2F, 0xA5,
  27580. 0x91, 0xB7, 0xEC, 0x3C, 0x3D, 0xAA, 0x1F, 0x76,
  27581. 0x42, 0xBC, 0x26, 0xC3, 0x24, 0xC0, 0x80, 0x90,
  27582. 0x60, 0x7E, 0x66, 0x62, 0x15, 0x4D, 0xB3, 0x7C,
  27583. 0xF7, 0x47, 0x96, 0x7A, 0x1F, 0x9F, 0xC2, 0x90,
  27584. 0x89, 0xF5, 0x70, 0xEB, 0xE6, 0x0E, 0xEE, 0xF8,
  27585. 0x9F, 0xD2, 0x44, 0x81, 0x02, 0x8C, 0x85, 0xAE,
  27586. 0xF1, 0xDC, 0x3B, 0x09, 0xF2, 0x2C, 0xD3, 0x69,
  27587. 0x1B, 0xBB, 0xB8, 0x21, 0xC7, 0xA8, 0xA0, 0xF3,
  27588. 0x5A, 0xD1, 0x2B, 0xE1, 0xDD, 0x19, 0x9B, 0x97,
  27589. 0x70, 0x48, 0xF3, 0xD4, 0x8C, 0x16, 0xBB, 0x2C,
  27590. 0xA9, 0x4C, 0xEC, 0xB8, 0x92, 0x87, 0x70, 0xD5,
  27591. 0xBB, 0x32, 0x9A, 0x03, 0x27, 0xE0, 0xB2, 0x86,
  27592. 0xFA, 0xA1, 0xC6, 0x52, 0x81, 0x03, 0x1A, 0x31,
  27593. 0xC8, 0x4F, 0x2E, 0xDC, 0x9C, 0x04, 0xD4, 0x75,
  27594. 0xED, 0x4E, 0x12, 0x8E, 0x51, 0xEF, 0xA9, 0x7D,
  27595. 0x01, 0x48, 0xCB, 0xA6, 0xC9, 0x5F, 0x67, 0x4C,
  27596. 0x58, 0x9F, 0x30, 0x1C, 0x26, 0x5B, 0xED, 0x70,
  27597. 0x8E, 0x9A, 0xD8, 0xDA, 0x3C, 0x5C, 0xEC, 0xBD,
  27598. 0xEE, 0xED, 0x35, 0xEF, 0x1E, 0x25, 0x31, 0x32,
  27599. 0xBA, 0x89, 0x92, 0x0D, 0x78, 0x6B, 0x88, 0x23,
  27600. 0x0B, 0x01, 0x3B, 0xCF, 0x2D, 0xC9, 0x2D, 0x6B,
  27601. 0x15, 0x7A, 0xFA, 0x8D, 0xA8, 0x59, 0x2C, 0xD0,
  27602. 0x74, 0x3D, 0x49, 0x82, 0xBE, 0x60, 0xD7, 0xC2,
  27603. 0xD5, 0xC4, 0x72, 0xAB, 0x9F, 0xA7, 0xF4, 0xCC,
  27604. 0x3D, 0x12, 0xB0, 0xEB, 0xAF, 0x0A, 0xBE, 0x55,
  27605. 0x5C, 0x75, 0x80, 0x54, 0x26, 0x84, 0x4D, 0xD9,
  27606. 0x42, 0x86, 0x43, 0xF8, 0x44, 0x06, 0xA1, 0xB8,
  27607. 0xD6, 0xFA, 0xED, 0xFD, 0x8A, 0xE6, 0xE7, 0x3A,
  27608. 0x72, 0x77, 0x2A, 0x21, 0x59, 0xAC, 0xAB, 0xD9,
  27609. 0x72, 0xAE, 0xB6, 0xF7, 0xDE, 0x09, 0x1A, 0xC5,
  27610. 0xFD, 0xD7, 0xF4, 0x9A, 0x3D, 0xC6, 0x64, 0x1C,
  27611. 0xDF, 0x62, 0x44, 0x6B, 0x4B, 0x04, 0xA3, 0x1F,
  27612. 0x73, 0xB8, 0x0A, 0x62, 0xF8, 0x0A, 0x40, 0x4A,
  27613. 0x8C, 0xB1, 0x8C, 0xE3, 0xE6, 0x54, 0x80, 0xEF,
  27614. 0x7B, 0x52, 0xBF, 0x00, 0x91, 0x11, 0x7E, 0x5D,
  27615. 0x08, 0xEA, 0xE1, 0xB0, 0xAA, 0xBB, 0x72, 0xE6,
  27616. 0xDF, 0xFF, 0xF7, 0x6F, 0x6E, 0x44, 0xBB, 0xD7,
  27617. 0xEA, 0x57, 0x0D, 0x66, 0x04, 0xBC, 0x2E, 0x74,
  27618. 0x31, 0x8B, 0xAF, 0xA3, 0x15, 0xA3, 0x88, 0x61,
  27619. 0xAA, 0x1B, 0x21, 0xAF, 0xB2, 0xA5, 0x3F, 0x26,
  27620. 0x14, 0xF1, 0xD6, 0x40, 0x07, 0x59, 0x84, 0xAE,
  27621. 0x62, 0xE2, 0xFC, 0xA1, 0xD1, 0xB4, 0xDB, 0x36,
  27622. 0x9F, 0x15, 0x70, 0x5C, 0xE7, 0xD4, 0xDF, 0x8A,
  27623. 0xE9, 0x82, 0x64, 0x50, 0x10, 0x51, 0xC0, 0xDE,
  27624. 0xF2, 0x1D, 0x64, 0x5D, 0x49, 0x62, 0x5A, 0xF0,
  27625. 0x2C, 0xA4, 0x28, 0xD9, 0xF0, 0xC2, 0xCD, 0x9F,
  27626. 0xBA, 0xEE, 0xAB, 0x97, 0xE8, 0xE9, 0x15, 0x16,
  27627. 0x62, 0xB6, 0x99, 0x2B, 0x4C, 0x99, 0xAB, 0x1B,
  27628. 0x92, 0x5D, 0x08, 0x92, 0x03, 0x63, 0x37, 0x3F,
  27629. 0x76, 0xD3, 0xFD, 0xF0, 0x82, 0x8C, 0xAA, 0x69,
  27630. 0xC8, 0xB1, 0xBD, 0xC6, 0xF5, 0x21, 0xDF, 0x64,
  27631. 0x1C, 0xF1, 0xC8, 0xA4, 0xE7, 0xEF, 0x0C, 0x23,
  27632. 0x28, 0x9A, 0x4E, 0x2C, 0xF1, 0x8A, 0xCE, 0xBB,
  27633. 0xE4, 0xC1, 0xE6, 0x83, 0x69, 0xBD, 0x52, 0x35,
  27634. 0x12, 0x01, 0x42, 0xEC, 0xDD, 0x1A, 0x73, 0x81,
  27635. 0x1E, 0x2E, 0x53, 0x3A, 0x64, 0x7D, 0x7A, 0xEE,
  27636. 0x16, 0xDA, 0xA0, 0x3B, 0x68, 0x36, 0x39, 0xDC,
  27637. 0xF1, 0xE1, 0xF1, 0xE7, 0x1C, 0xFA, 0xED, 0x48,
  27638. 0xF6, 0x9A, 0xEC, 0x3E, 0x83, 0x17, 0x33, 0xDA,
  27639. 0x19, 0xCE, 0xBE, 0xC1, 0xDD, 0xBF, 0x71, 0xCB,
  27640. 0xAE, 0x08, 0x00, 0xF2, 0xF6, 0xD6, 0x4A, 0x09,
  27641. 0x6E, 0xC4, 0x95, 0xD6, 0x2F, 0x43, 0x44, 0xF7,
  27642. 0xAA, 0x56, 0x21, 0xB3, 0x22, 0x35, 0x3A, 0x79,
  27643. 0x5A, 0xA0, 0x99, 0xEA, 0x3A, 0x07, 0x02, 0x72,
  27644. 0xD0, 0x53, 0xD4, 0x65, 0x3A, 0x20, 0xCF, 0x21,
  27645. 0x0E, 0xAA, 0xF1, 0x2C, 0xAE, 0x60, 0x23, 0xD8,
  27646. 0xE5, 0x11, 0x8D, 0xF0, 0x4B, 0x38, 0x4A, 0x44,
  27647. 0xD1, 0xED, 0xB9, 0x1C, 0x44, 0x98, 0x9E, 0xF7,
  27648. 0xEE, 0x57, 0xF2, 0xBF, 0x81, 0xA2, 0x4B, 0xDC,
  27649. 0x76, 0x80, 0x7D, 0xA9, 0x67, 0xEE, 0x65, 0x25,
  27650. 0x41, 0x0C, 0x5C, 0x48, 0x50, 0x67, 0xEF, 0xC3,
  27651. 0xD3, 0x9A, 0x9A, 0xD4, 0x2C, 0xC7, 0x53, 0xBA,
  27652. 0xA5, 0x9A, 0x1F, 0xD2, 0x8A, 0xF3, 0x5C, 0x00,
  27653. 0xD1, 0x8A, 0x40, 0x6A, 0x28, 0xFC, 0x79, 0xBA
  27654. };
  27655. static const byte kprime_768[KYBER_SS_SZ] = {
  27656. 0xDC, 0x5B, 0x88, 0x88, 0xBC, 0x1E, 0xBA, 0x5C,
  27657. 0x19, 0x69, 0xC2, 0x11, 0x64, 0xEA, 0x43, 0xE2,
  27658. 0x2E, 0x7A, 0xC0, 0xCD, 0x01, 0x2A, 0x2F, 0x26,
  27659. 0xCB, 0x8C, 0x48, 0x7E, 0x69, 0xEF, 0x7C, 0xE4
  27660. };
  27661. #endif
  27662. #ifndef WOLFSSL_NO_KYBER1024
  27663. static const byte dk_1024[KYBER1024_PRIVATE_KEY_SIZE] = {
  27664. 0x84, 0x45, 0xC3, 0x36, 0xF3, 0x51, 0x8B, 0x29,
  27665. 0x81, 0x63, 0xDC, 0xBB, 0x63, 0x57, 0x59, 0x79,
  27666. 0x83, 0xCA, 0x2E, 0x87, 0x3D, 0xCB, 0x49, 0x61,
  27667. 0x0C, 0xF5, 0x2F, 0x14, 0xDB, 0xCB, 0x94, 0x7C,
  27668. 0x1F, 0x3E, 0xE9, 0x26, 0x69, 0x67, 0x27, 0x6B,
  27669. 0x0C, 0x57, 0x6C, 0xF7, 0xC3, 0x0E, 0xE6, 0xB9,
  27670. 0x3D, 0xEA, 0x51, 0x18, 0x67, 0x6C, 0xBE, 0xE1,
  27671. 0xB1, 0xD4, 0x79, 0x42, 0x06, 0xFB, 0x36, 0x9A,
  27672. 0xBA, 0x41, 0x16, 0x7B, 0x43, 0x93, 0x85, 0x5C,
  27673. 0x84, 0xEB, 0xA8, 0xF3, 0x23, 0x73, 0xC0, 0x5B,
  27674. 0xAE, 0x76, 0x31, 0xC8, 0x02, 0x74, 0x4A, 0xAD,
  27675. 0xB6, 0xC2, 0xDE, 0x41, 0x25, 0x0C, 0x49, 0x43,
  27676. 0x15, 0x23, 0x0B, 0x52, 0x82, 0x6C, 0x34, 0x58,
  27677. 0x7C, 0xB2, 0x1B, 0x18, 0x3B, 0x49, 0xB2, 0xA5,
  27678. 0xAC, 0x04, 0x92, 0x1A, 0xC6, 0xBF, 0xAC, 0x1B,
  27679. 0x24, 0xA4, 0xB3, 0x7A, 0x93, 0xA4, 0xB1, 0x68,
  27680. 0xCC, 0xE7, 0x59, 0x1B, 0xE6, 0x11, 0x1F, 0x47,
  27681. 0x62, 0x60, 0xF2, 0x76, 0x29, 0x59, 0xF5, 0xC1,
  27682. 0x64, 0x01, 0x18, 0xC2, 0x42, 0x37, 0x72, 0xE2,
  27683. 0xAD, 0x03, 0xDC, 0x71, 0x68, 0xA3, 0x8C, 0x6D,
  27684. 0xD3, 0x9F, 0x5F, 0x72, 0x54, 0x26, 0x42, 0x80,
  27685. 0xC8, 0xBC, 0x10, 0xB9, 0x14, 0x16, 0x80, 0x70,
  27686. 0x47, 0x2F, 0xA8, 0x80, 0xAC, 0xB8, 0x60, 0x1A,
  27687. 0x8A, 0x08, 0x37, 0xF2, 0x5F, 0xE1, 0x94, 0x68,
  27688. 0x7C, 0xD6, 0x8B, 0x7D, 0xE2, 0x34, 0x0F, 0x03,
  27689. 0x6D, 0xAD, 0x89, 0x1D, 0x38, 0xD1, 0xB0, 0xCE,
  27690. 0x9C, 0x26, 0x33, 0x35, 0x5C, 0xF5, 0x7B, 0x50,
  27691. 0xB8, 0x96, 0x03, 0x6F, 0xCA, 0x26, 0x0D, 0x26,
  27692. 0x69, 0xF8, 0x5B, 0xAC, 0x79, 0x71, 0x4F, 0xDA,
  27693. 0xFB, 0x41, 0xEF, 0x80, 0xB8, 0xC3, 0x02, 0x64,
  27694. 0xC3, 0x13, 0x86, 0xAE, 0x60, 0xB0, 0x5F, 0xAA,
  27695. 0x54, 0x2A, 0x26, 0xB4, 0x1E, 0xB8, 0x5F, 0x67,
  27696. 0x06, 0x8F, 0x08, 0x80, 0x34, 0xFF, 0x67, 0xAA,
  27697. 0x2E, 0x81, 0x5A, 0xAB, 0x8B, 0xCA, 0x6B, 0xF7,
  27698. 0x1F, 0x70, 0xEC, 0xC3, 0xCB, 0xCB, 0xC4, 0x5E,
  27699. 0xF7, 0x01, 0xFC, 0xD5, 0x42, 0xBD, 0x21, 0xC7,
  27700. 0xB0, 0x95, 0x68, 0xF3, 0x69, 0xC6, 0x69, 0xF3,
  27701. 0x96, 0x47, 0x38, 0x44, 0xFB, 0xA1, 0x49, 0x57,
  27702. 0xF5, 0x19, 0x74, 0xD8, 0x52, 0xB9, 0x78, 0x01,
  27703. 0x46, 0x03, 0xA2, 0x10, 0xC0, 0x19, 0x03, 0x62,
  27704. 0x87, 0x00, 0x89, 0x94, 0xF2, 0x12, 0x55, 0xB2,
  27705. 0x50, 0x99, 0xAD, 0x82, 0xAA, 0x13, 0x24, 0x38,
  27706. 0x96, 0x3B, 0x2C, 0x0A, 0x47, 0xCD, 0xF5, 0xF3,
  27707. 0x2B, 0xA4, 0x6B, 0x76, 0xC7, 0xA6, 0x55, 0x9F,
  27708. 0x18, 0xBF, 0xD5, 0x55, 0xB7, 0x62, 0xE4, 0x87,
  27709. 0xB6, 0xAC, 0x99, 0x2F, 0xE2, 0x0E, 0x28, 0x3C,
  27710. 0xA0, 0xB3, 0xF6, 0x16, 0x44, 0x96, 0x95, 0x59,
  27711. 0x95, 0xC3, 0xB2, 0x8A, 0x57, 0xBB, 0xC2, 0x98,
  27712. 0x26, 0xF0, 0x6F, 0xB3, 0x8B, 0x25, 0x34, 0x70,
  27713. 0xAF, 0x63, 0x1B, 0xC4, 0x6C, 0x3A, 0x8F, 0x9C,
  27714. 0xE8, 0x24, 0x32, 0x19, 0x85, 0xDD, 0x01, 0xC0,
  27715. 0x5F, 0x69, 0xB8, 0x24, 0xF9, 0x16, 0x63, 0x3B,
  27716. 0x40, 0x65, 0x4C, 0x75, 0xAA, 0xEB, 0x93, 0x85,
  27717. 0x57, 0x6F, 0xFD, 0xE2, 0x99, 0x0A, 0x6B, 0x0A,
  27718. 0x3B, 0xE8, 0x29, 0xD6, 0xD8, 0x4E, 0x34, 0xF1,
  27719. 0x78, 0x05, 0x89, 0xC7, 0x92, 0x04, 0xC6, 0x3C,
  27720. 0x79, 0x8F, 0x55, 0xD2, 0x31, 0x87, 0xE4, 0x61,
  27721. 0xD4, 0x8C, 0x21, 0xE5, 0xC0, 0x47, 0xE5, 0x35,
  27722. 0xB1, 0x9F, 0x45, 0x8B, 0xBA, 0x13, 0x45, 0xB9,
  27723. 0xE4, 0x1E, 0x0C, 0xB4, 0xA9, 0xC2, 0xD8, 0xC4,
  27724. 0x0B, 0x49, 0x0A, 0x3B, 0xAB, 0xC5, 0x53, 0xB3,
  27725. 0x02, 0x6B, 0x16, 0x72, 0xD2, 0x8C, 0xBC, 0x8B,
  27726. 0x49, 0x8A, 0x3A, 0x99, 0x57, 0x9A, 0x83, 0x2F,
  27727. 0xEA, 0xE7, 0x46, 0x10, 0xF0, 0xB6, 0x25, 0x0C,
  27728. 0xC3, 0x33, 0xE9, 0x49, 0x3E, 0xB1, 0x62, 0x1E,
  27729. 0xD3, 0x4A, 0xA4, 0xAB, 0x17, 0x5F, 0x2C, 0xA2,
  27730. 0x31, 0x15, 0x25, 0x09, 0xAC, 0xB6, 0xAC, 0x86,
  27731. 0xB2, 0x0F, 0x6B, 0x39, 0x10, 0x84, 0x39, 0xE5,
  27732. 0xEC, 0x12, 0xD4, 0x65, 0xA0, 0xFE, 0xF3, 0x50,
  27733. 0x03, 0xE1, 0x42, 0x77, 0xA2, 0x18, 0x12, 0x14,
  27734. 0x6B, 0x25, 0x44, 0x71, 0x6D, 0x6A, 0xB8, 0x2D,
  27735. 0x1B, 0x07, 0x26, 0xC2, 0x7A, 0x98, 0xD5, 0x89,
  27736. 0xEB, 0xDA, 0xCC, 0x4C, 0x54, 0xBA, 0x77, 0xB2,
  27737. 0x49, 0x8F, 0x21, 0x7E, 0x14, 0xE3, 0x4E, 0x66,
  27738. 0x02, 0x5A, 0x2A, 0x14, 0x3A, 0x99, 0x25, 0x20,
  27739. 0xA6, 0x1C, 0x06, 0x72, 0xCC, 0x9C, 0xCE, 0xD7,
  27740. 0xC9, 0x45, 0x0C, 0x68, 0x3E, 0x90, 0xA3, 0xE4,
  27741. 0x65, 0x1D, 0xB6, 0x23, 0xA6, 0xDB, 0x39, 0xAC,
  27742. 0x26, 0x12, 0x5B, 0x7F, 0xC1, 0x98, 0x6D, 0x7B,
  27743. 0x04, 0x93, 0xB8, 0xB7, 0x2D, 0xE7, 0x70, 0x7D,
  27744. 0xC2, 0x0B, 0xBD, 0xD4, 0x37, 0x13, 0x15, 0x6A,
  27745. 0xF7, 0xD9, 0x43, 0x0E, 0xF4, 0x53, 0x99, 0x66,
  27746. 0x3C, 0x22, 0x02, 0x73, 0x91, 0x68, 0x69, 0x2D,
  27747. 0xD6, 0x57, 0x54, 0x5B, 0x05, 0x6D, 0x9C, 0x92,
  27748. 0x38, 0x5A, 0x7F, 0x41, 0x4B, 0x34, 0xB9, 0x0C,
  27749. 0x79, 0x60, 0xD5, 0x7B, 0x35, 0xBA, 0x7D, 0xDE,
  27750. 0x7B, 0x81, 0xFC, 0xA0, 0x11, 0x9D, 0x74, 0x1B,
  27751. 0x12, 0x78, 0x09, 0x26, 0x01, 0x8F, 0xE4, 0xC8,
  27752. 0x03, 0x0B, 0xF0, 0x38, 0xE1, 0x8B, 0x4F, 0xA3,
  27753. 0x37, 0x43, 0xD0, 0xD3, 0xC8, 0x46, 0x41, 0x7E,
  27754. 0x9D, 0x59, 0x15, 0xC2, 0x46, 0x31, 0x59, 0x38,
  27755. 0xB1, 0xE2, 0x33, 0x61, 0x45, 0x01, 0xD0, 0x26,
  27756. 0x95, 0x95, 0x51, 0x25, 0x8B, 0x23, 0x32, 0x30,
  27757. 0xD4, 0x28, 0xB1, 0x81, 0xB1, 0x32, 0xF1, 0xD0,
  27758. 0xB0, 0x26, 0x06, 0x7B, 0xA8, 0x16, 0x99, 0x9B,
  27759. 0xC0, 0xCD, 0x6B, 0x54, 0x7E, 0x54, 0x8B, 0x63,
  27760. 0xC9, 0xEA, 0xA0, 0x91, 0xBA, 0xC4, 0x93, 0xDC,
  27761. 0x59, 0x8D, 0xBC, 0x2B, 0x0E, 0x14, 0x6A, 0x25,
  27762. 0x91, 0xC2, 0xA8, 0xC0, 0x09, 0xDD, 0x51, 0x70,
  27763. 0xAA, 0xE0, 0x27, 0xC5, 0x41, 0xA1, 0xB5, 0xE6,
  27764. 0x6E, 0x45, 0xC6, 0x56, 0x12, 0x98, 0x4C, 0x46,
  27765. 0x77, 0x04, 0x93, 0xEC, 0x89, 0x6E, 0xF2, 0x5A,
  27766. 0xA9, 0x30, 0x5E, 0x9F, 0x06, 0x69, 0x2C, 0xD0,
  27767. 0xB2, 0xF0, 0x69, 0x62, 0xE2, 0x05, 0xBE, 0xBE,
  27768. 0x11, 0x3A, 0x34, 0xEB, 0xB1, 0xA4, 0x83, 0x0A,
  27769. 0x9B, 0x37, 0x49, 0x64, 0x1B, 0xB9, 0x35, 0x00,
  27770. 0x7B, 0x23, 0xB2, 0x4B, 0xFE, 0x57, 0x69, 0x56,
  27771. 0x25, 0x4D, 0x7A, 0x35, 0xAA, 0x49, 0x6A, 0xC4,
  27772. 0x46, 0xC6, 0x7A, 0x7F, 0xEC, 0x85, 0xA6, 0x00,
  27773. 0x57, 0xE8, 0x58, 0x06, 0x17, 0xBC, 0xB3, 0xFA,
  27774. 0xD1, 0x5C, 0x76, 0x44, 0x0F, 0xED, 0x54, 0xCC,
  27775. 0x78, 0x93, 0x94, 0xFE, 0xA2, 0x44, 0x52, 0xCC,
  27776. 0x6B, 0x05, 0x85, 0xB7, 0xEB, 0x0A, 0x88, 0xBB,
  27777. 0xA9, 0x50, 0x0D, 0x98, 0x00, 0xE6, 0x24, 0x1A,
  27778. 0xFE, 0xB5, 0x23, 0xB5, 0x5A, 0x96, 0xA5, 0x35,
  27779. 0x15, 0x1D, 0x10, 0x49, 0x57, 0x32, 0x06, 0xE5,
  27780. 0x9C, 0x7F, 0xEB, 0x07, 0x09, 0x66, 0x82, 0x36,
  27781. 0x34, 0xF7, 0x7D, 0x5F, 0x12, 0x91, 0x75, 0x5A,
  27782. 0x24, 0x31, 0x19, 0x62, 0x1A, 0xF8, 0x08, 0x4A,
  27783. 0xB7, 0xAC, 0x1E, 0x22, 0xA0, 0x56, 0x8C, 0x62,
  27784. 0x01, 0x41, 0x7C, 0xBE, 0x36, 0x55, 0xD8, 0xA0,
  27785. 0x8D, 0xD5, 0xB5, 0x13, 0x88, 0x4C, 0x98, 0xD5,
  27786. 0xA4, 0x93, 0xFD, 0x49, 0x38, 0x2E, 0xA4, 0x18,
  27787. 0x60, 0xF1, 0x33, 0xCC, 0xD6, 0x01, 0xE8, 0x85,
  27788. 0x96, 0x64, 0x26, 0xA2, 0xB1, 0xF2, 0x3D, 0x42,
  27789. 0xD8, 0x2E, 0x24, 0x58, 0x2D, 0x99, 0x72, 0x51,
  27790. 0x92, 0xC2, 0x17, 0x77, 0x46, 0x7B, 0x14, 0x57,
  27791. 0xB1, 0xDD, 0x42, 0x9A, 0x0C, 0x41, 0xA5, 0xC3,
  27792. 0xD7, 0x04, 0xCE, 0xA0, 0x62, 0x78, 0xC5, 0x99,
  27793. 0x41, 0xB4, 0x38, 0xC6, 0x27, 0x27, 0x09, 0x78,
  27794. 0x09, 0xB4, 0x53, 0x0D, 0xBE, 0x83, 0x7E, 0xA3,
  27795. 0x96, 0xB6, 0xD3, 0x10, 0x77, 0xFA, 0xD3, 0x73,
  27796. 0x30, 0x53, 0x98, 0x9A, 0x84, 0x42, 0xAA, 0xC4,
  27797. 0x25, 0x5C, 0xB1, 0x63, 0xB8, 0xCA, 0x2F, 0x27,
  27798. 0x50, 0x1E, 0xA9, 0x67, 0x30, 0x56, 0x95, 0xAB,
  27799. 0xD6, 0x59, 0xAA, 0x02, 0xC8, 0x3E, 0xE6, 0x0B,
  27800. 0xB5, 0x74, 0x20, 0x3E, 0x99, 0x37, 0xAE, 0x1C,
  27801. 0x62, 0x1C, 0x8E, 0xCB, 0x5C, 0xC1, 0xD2, 0x1D,
  27802. 0x55, 0x69, 0x60, 0xB5, 0xB9, 0x16, 0x1E, 0xA9,
  27803. 0x6F, 0xFF, 0xEB, 0xAC, 0x72, 0xE1, 0xB8, 0xA6,
  27804. 0x15, 0x4F, 0xC4, 0xD8, 0x8B, 0x56, 0xC0, 0x47,
  27805. 0x41, 0xF0, 0x90, 0xCB, 0xB1, 0x56, 0xA7, 0x37,
  27806. 0xC9, 0xE6, 0xA2, 0x2B, 0xA8, 0xAC, 0x70, 0x4B,
  27807. 0xC3, 0x04, 0xF8, 0xE1, 0x7E, 0x5E, 0xA8, 0x45,
  27808. 0xFD, 0xE5, 0x9F, 0xBF, 0x78, 0x8C, 0xCE, 0x0B,
  27809. 0x97, 0xC8, 0x76, 0x1F, 0x89, 0xA2, 0x42, 0xF3,
  27810. 0x05, 0x25, 0x83, 0xC6, 0x84, 0x4A, 0x63, 0x20,
  27811. 0x31, 0xC9, 0x64, 0xA6, 0xC4, 0xA8, 0x5A, 0x12,
  27812. 0x8A, 0x28, 0x61, 0x9B, 0xA1, 0xBB, 0x3D, 0x1B,
  27813. 0xEA, 0x4B, 0x49, 0x84, 0x1F, 0xC8, 0x47, 0x61,
  27814. 0x4A, 0x06, 0x68, 0x41, 0xF5, 0x2E, 0xD0, 0xEB,
  27815. 0x8A, 0xE0, 0xB8, 0xB0, 0x96, 0xE9, 0x2B, 0x81,
  27816. 0x95, 0x40, 0x58, 0x15, 0xB2, 0x31, 0x26, 0x6F,
  27817. 0x36, 0xB1, 0x8C, 0x1A, 0x53, 0x33, 0x3D, 0xAB,
  27818. 0x95, 0xD2, 0xA9, 0xA3, 0x74, 0xB5, 0x47, 0x8A,
  27819. 0x4A, 0x41, 0xFB, 0x87, 0x59, 0x95, 0x7C, 0x9A,
  27820. 0xB2, 0x2C, 0xAE, 0x54, 0x5A, 0xB5, 0x44, 0xBA,
  27821. 0x8D, 0xD0, 0x5B, 0x83, 0xF3, 0xA6, 0x13, 0xA2,
  27822. 0x43, 0x7A, 0xDB, 0x07, 0x3A, 0x96, 0x35, 0xCB,
  27823. 0x4B, 0xBC, 0x96, 0x5F, 0xB4, 0x54, 0xCF, 0x27,
  27824. 0xB2, 0x98, 0xA4, 0x0C, 0xD0, 0xDA, 0x3B, 0x8F,
  27825. 0x9C, 0xA9, 0x9D, 0x8C, 0xB4, 0x28, 0x6C, 0x5E,
  27826. 0xB4, 0x76, 0x41, 0x67, 0x96, 0x07, 0x0B, 0xA5,
  27827. 0x35, 0xAA, 0xA5, 0x8C, 0xDB, 0x45, 0x1C, 0xD6,
  27828. 0xDB, 0x5C, 0xBB, 0x0C, 0xA2, 0x0F, 0x0C, 0x71,
  27829. 0xDE, 0x97, 0xC3, 0x0D, 0xA9, 0x7E, 0xC7, 0x90,
  27830. 0x6D, 0x06, 0xB4, 0xB9, 0x39, 0x39, 0x60, 0x28,
  27831. 0xC4, 0x6B, 0xA0, 0xE7, 0xA8, 0x65, 0xBC, 0x83,
  27832. 0x08, 0xA3, 0x81, 0x0F, 0x12, 0x12, 0x00, 0x63,
  27833. 0x39, 0xF7, 0xBC, 0x16, 0x9B, 0x16, 0x66, 0xFD,
  27834. 0xF4, 0x75, 0x91, 0x1B, 0xBC, 0x8A, 0xAA, 0xB4,
  27835. 0x17, 0x55, 0xC9, 0xA8, 0xAA, 0xBF, 0xA2, 0x3C,
  27836. 0x0E, 0x37, 0xF8, 0x4F, 0xE4, 0x69, 0x99, 0xE0,
  27837. 0x30, 0x49, 0x4B, 0x92, 0x98, 0xEF, 0x99, 0x34,
  27838. 0xE8, 0xA6, 0x49, 0xC0, 0xA5, 0xCC, 0xE2, 0xB2,
  27839. 0x2F, 0x31, 0x80, 0x9A, 0xFE, 0xD2, 0x39, 0x55,
  27840. 0xD8, 0x78, 0x81, 0xD9, 0x9F, 0xC1, 0xD3, 0x52,
  27841. 0x89, 0x6C, 0xAC, 0x90, 0x55, 0xBE, 0xA0, 0xD0,
  27842. 0x16, 0xCC, 0xBA, 0x78, 0x05, 0xA3, 0xA5, 0x0E,
  27843. 0x22, 0x16, 0x30, 0x37, 0x9B, 0xD0, 0x11, 0x35,
  27844. 0x22, 0x1C, 0xAD, 0x5D, 0x95, 0x17, 0xC8, 0xCC,
  27845. 0x42, 0x63, 0x7B, 0x9F, 0xC0, 0x71, 0x8E, 0x9A,
  27846. 0x9B, 0xB4, 0x94, 0x5C, 0x72, 0xD8, 0xD1, 0x1D,
  27847. 0x3D, 0x65, 0x9D, 0x83, 0xA3, 0xC4, 0x19, 0x50,
  27848. 0x9A, 0xF5, 0xB4, 0x70, 0xDD, 0x89, 0xB7, 0xF3,
  27849. 0xAC, 0xCF, 0x5F, 0x35, 0xCF, 0xC3, 0x22, 0x11,
  27850. 0x5F, 0xD6, 0x6A, 0x5C, 0xD2, 0x87, 0x56, 0x51,
  27851. 0x32, 0x6F, 0x9B, 0x31, 0x68, 0x91, 0x3B, 0xE5,
  27852. 0xB9, 0xC8, 0x7A, 0xE0, 0xB0, 0x25, 0xEC, 0x7A,
  27853. 0x2F, 0x4A, 0x07, 0x27, 0x50, 0x94, 0x6A, 0xC6,
  27854. 0x11, 0x70, 0xA7, 0x82, 0x6D, 0x97, 0x04, 0xC5,
  27855. 0xA2, 0x3A, 0x1C, 0x0A, 0x23, 0x25, 0x14, 0x6C,
  27856. 0x3B, 0xC1, 0x85, 0x88, 0x26, 0xC6, 0xB3, 0x92,
  27857. 0x79, 0xC2, 0xDA, 0x74, 0x38, 0xA3, 0x70, 0xED,
  27858. 0x8A, 0x0A, 0xA5, 0x16, 0x9E, 0x3B, 0xEC, 0x29,
  27859. 0xED, 0x88, 0x47, 0x87, 0x32, 0x75, 0x8D, 0x45,
  27860. 0x41, 0x43, 0xE2, 0x27, 0xF8, 0x59, 0x58, 0x83,
  27861. 0x29, 0x78, 0x42, 0xE6, 0xAF, 0x13, 0x3B, 0x17,
  27862. 0xE4, 0x81, 0x1B, 0x0F, 0x57, 0x13, 0xAC, 0x73,
  27863. 0xB7, 0xE3, 0x47, 0x42, 0x3E, 0xB9, 0x28, 0x22,
  27864. 0xD2, 0x30, 0x6F, 0xA1, 0x45, 0x00, 0xA7, 0x20,
  27865. 0x7A, 0x06, 0x72, 0x67, 0x20, 0x46, 0x54, 0x4A,
  27866. 0xCC, 0x4E, 0xA9, 0xC1, 0x6E, 0xD7, 0x42, 0x1A,
  27867. 0x06, 0x9E, 0x0D, 0x73, 0x7A, 0x98, 0x62, 0x85,
  27868. 0x19, 0xC6, 0xA2, 0x9A, 0x42, 0x4A, 0x86, 0x8B,
  27869. 0x46, 0xD9, 0xA0, 0xCC, 0x7C, 0x6C, 0x9D, 0xDD,
  27870. 0x8B, 0x8B, 0xCB, 0xF4, 0x22, 0xC8, 0xF4, 0x8A,
  27871. 0x73, 0x14, 0x3D, 0x5A, 0xBB, 0x66, 0xBC, 0x55,
  27872. 0x49, 0x94, 0x18, 0x43, 0x08, 0x02, 0xBA, 0xC5,
  27873. 0x44, 0x46, 0x3C, 0xC7, 0x31, 0x9D, 0x17, 0x99,
  27874. 0x8F, 0x29, 0x41, 0x13, 0x65, 0x76, 0x6D, 0x04,
  27875. 0xC8, 0x47, 0xF3, 0x12, 0x9D, 0x90, 0x77, 0xB7,
  27876. 0xD8, 0x33, 0x9B, 0xFB, 0x96, 0xA6, 0x73, 0x9C,
  27877. 0x3F, 0x6B, 0x74, 0xA8, 0xF0, 0x5F, 0x91, 0x38,
  27878. 0xAB, 0x2F, 0xE3, 0x7A, 0xCB, 0x57, 0x63, 0x4D,
  27879. 0x18, 0x20, 0xB5, 0x01, 0x76, 0xF5, 0xA0, 0xB6,
  27880. 0xBC, 0x29, 0x40, 0xF1, 0xD5, 0x93, 0x8F, 0x19,
  27881. 0x36, 0xB5, 0xF9, 0x58, 0x28, 0xB9, 0x2E, 0xB7,
  27882. 0x29, 0x73, 0xC1, 0x59, 0x0A, 0xEB, 0x7A, 0x55,
  27883. 0x2C, 0xEC, 0xA1, 0x0B, 0x00, 0xC3, 0x03, 0xB7,
  27884. 0xC7, 0x5D, 0x40, 0x20, 0x71, 0xA7, 0x9E, 0x2C,
  27885. 0x81, 0x0A, 0xF7, 0xC7, 0x45, 0xE3, 0x33, 0x67,
  27886. 0x12, 0x49, 0x2A, 0x42, 0x04, 0x3F, 0x29, 0x03,
  27887. 0xA3, 0x7C, 0x64, 0x34, 0xCE, 0xE2, 0x0B, 0x1D,
  27888. 0x15, 0x9B, 0x05, 0x76, 0x99, 0xFF, 0x9C, 0x1D,
  27889. 0x3B, 0xD6, 0x80, 0x29, 0x83, 0x9A, 0x08, 0xF4,
  27890. 0x3E, 0x6C, 0x1C, 0x81, 0x99, 0x13, 0x53, 0x2F,
  27891. 0x91, 0x1D, 0xD3, 0x70, 0xC7, 0x02, 0x14, 0x88,
  27892. 0xE1, 0x1C, 0xB5, 0x04, 0xCB, 0x9C, 0x70, 0x57,
  27893. 0x0F, 0xFF, 0x35, 0xB4, 0xB4, 0x60, 0x11, 0x91,
  27894. 0xDC, 0x1A, 0xD9, 0xE6, 0xAD, 0xC5, 0xFA, 0x96,
  27895. 0x18, 0x79, 0x8D, 0x7C, 0xC8, 0x60, 0xC8, 0x7A,
  27896. 0x93, 0x9E, 0x4C, 0xCF, 0x85, 0x33, 0x63, 0x22,
  27897. 0x68, 0xCF, 0x1A, 0x51, 0xAF, 0xF0, 0xCB, 0x81,
  27898. 0x1C, 0x55, 0x45, 0xCB, 0x16, 0x56, 0xE6, 0x52,
  27899. 0x69, 0x47, 0x74, 0x30, 0x69, 0x9C, 0xCD, 0xEA,
  27900. 0x38, 0x00, 0x63, 0x0B, 0x78, 0xCD, 0x58, 0x10,
  27901. 0x33, 0x4C, 0xCF, 0x02, 0xE0, 0x13, 0xF3, 0xB8,
  27902. 0x02, 0x44, 0xE7, 0x0A, 0xCD, 0xB0, 0x60, 0xBB,
  27903. 0xE7, 0xA5, 0x53, 0xB0, 0x63, 0x45, 0x6B, 0x2E,
  27904. 0xA8, 0x07, 0x47, 0x34, 0x13, 0x16, 0x5C, 0xE5,
  27905. 0x7D, 0xD5, 0x63, 0x47, 0x3C, 0xFB, 0xC9, 0x06,
  27906. 0x18, 0xAD, 0xE1, 0xF0, 0xB8, 0x88, 0xAA, 0x48,
  27907. 0xE7, 0x22, 0xBB, 0x27, 0x51, 0x85, 0x8F, 0xE1,
  27908. 0x96, 0x87, 0x44, 0x2A, 0x48, 0xE7, 0xCA, 0x0D,
  27909. 0x2A, 0x29, 0xCD, 0x51, 0xBF, 0xD8, 0xF7, 0x8C,
  27910. 0x17, 0xB9, 0x66, 0x0B, 0xFB, 0x54, 0xA4, 0x70,
  27911. 0xB2, 0xAE, 0x9A, 0x95, 0x5C, 0x6A, 0xB8, 0xD6,
  27912. 0xE5, 0xCC, 0x92, 0xAC, 0x8E, 0xD3, 0xC1, 0x85,
  27913. 0xDA, 0xA8, 0xBC, 0x29, 0xF0, 0x57, 0x8E, 0xBB,
  27914. 0x81, 0x2B, 0x97, 0xC9, 0xE5, 0xA8, 0x48, 0xA6,
  27915. 0x38, 0x4D, 0xE4, 0xE7, 0x5A, 0x31, 0x47, 0x0B,
  27916. 0x53, 0x06, 0x6A, 0x8D, 0x02, 0x7B, 0xA4, 0x4B,
  27917. 0x21, 0x74, 0x9C, 0x04, 0x92, 0x46, 0x5F, 0x90,
  27918. 0x72, 0xB2, 0x83, 0x76, 0xC4, 0xE2, 0x90, 0xB3,
  27919. 0x0C, 0x18, 0x63, 0xF9, 0xE5, 0xB7, 0x99, 0x96,
  27920. 0x08, 0x34, 0x22, 0xBD, 0x8C, 0x27, 0x2C, 0x10,
  27921. 0xEC, 0xC6, 0xEB, 0x9A, 0x0A, 0x82, 0x25, 0xB3,
  27922. 0x1A, 0xA0, 0xA6, 0x6E, 0x35, 0xB9, 0xC0, 0xB9,
  27923. 0xA7, 0x95, 0x82, 0xBA, 0x20, 0xA3, 0xC0, 0x4C,
  27924. 0xD2, 0x99, 0x14, 0xF0, 0x83, 0xA0, 0x15, 0x82,
  27925. 0x88, 0xBA, 0x4D, 0x6E, 0xB6, 0x2D, 0x87, 0x26,
  27926. 0x4B, 0x91, 0x2B, 0xCA, 0x39, 0x73, 0x2F, 0xBD,
  27927. 0xE5, 0x36, 0xA3, 0x77, 0xAD, 0x02, 0xB8, 0xC8,
  27928. 0x35, 0xD4, 0xA2, 0xF4, 0xE7, 0xB1, 0xCE, 0x11,
  27929. 0x5D, 0x0C, 0x86, 0x0B, 0xEA, 0xA7, 0x95, 0x5A,
  27930. 0x49, 0xAD, 0x68, 0x95, 0x86, 0xA8, 0x9A, 0x2B,
  27931. 0x9F, 0x9B, 0x10, 0xD1, 0x59, 0x5D, 0x2F, 0xC0,
  27932. 0x65, 0xAD, 0x01, 0x8A, 0x7D, 0x56, 0xC6, 0x14,
  27933. 0x47, 0x1F, 0x8E, 0x94, 0x6F, 0xE8, 0xAB, 0x49,
  27934. 0xE8, 0x22, 0x65, 0x91, 0x11, 0x9F, 0xCA, 0xDB,
  27935. 0x4F, 0x9A, 0x86, 0x16, 0x31, 0x37, 0x87, 0x36,
  27936. 0xB6, 0x68, 0x8B, 0x78, 0x2D, 0x58, 0xE9, 0x7E,
  27937. 0x45, 0x72, 0x75, 0x3A, 0x96, 0x64, 0xB6, 0xB8,
  27938. 0x53, 0x68, 0x12, 0xB2, 0x59, 0x11, 0xAA, 0x76,
  27939. 0xA2, 0x42, 0x37, 0x54, 0x33, 0x19, 0x27, 0x38,
  27940. 0xEE, 0xE7, 0x62, 0xF6, 0xB8, 0x43, 0x15, 0xBB,
  27941. 0x34, 0x36, 0x23, 0x1E, 0x0A, 0x9B, 0x27, 0x7E,
  27942. 0xD2, 0x8A, 0xE0, 0x05, 0x07, 0x28, 0x34, 0x64,
  27943. 0x57, 0xE1, 0x34, 0x05, 0x06, 0x2D, 0xB2, 0x80,
  27944. 0x4B, 0x8D, 0xA6, 0x0B, 0xB5, 0xC7, 0x93, 0xD4,
  27945. 0xCC, 0x0E, 0x10, 0x1C, 0xBA, 0x2D, 0x91, 0x82,
  27946. 0xFD, 0x71, 0x24, 0xFF, 0x52, 0xBF, 0x4C, 0xA2,
  27947. 0x82, 0x92, 0xAC, 0x26, 0xD6, 0x78, 0x08, 0x89,
  27948. 0x53, 0x97, 0x1D, 0xBA, 0x0B, 0x6F, 0xEC, 0x2C,
  27949. 0x96, 0x59, 0x35, 0x32, 0x91, 0xC7, 0x0C, 0x5B,
  27950. 0x92, 0x45, 0xA0, 0xCA, 0x25, 0x33, 0x04, 0xAF,
  27951. 0xD3, 0xC9, 0x51, 0x02, 0xBE, 0xA6, 0x68, 0x75,
  27952. 0xC6, 0x20, 0x16, 0x80, 0xB4, 0xBD, 0xA3, 0x86,
  27953. 0x87, 0xB6, 0x48, 0xC2, 0x8E, 0xB3, 0x74, 0x78,
  27954. 0xE3, 0xBC, 0x00, 0xCA, 0x8A, 0x3C, 0xC2, 0x72,
  27955. 0x04, 0x64, 0x2B, 0x42, 0xB6, 0x8F, 0xCB, 0xE7,
  27956. 0xB2, 0x1A, 0x36, 0x6D, 0x06, 0x68, 0xA5, 0x02,
  27957. 0x9A, 0x7D, 0xEE, 0xF9, 0x4C, 0xDD, 0x6A, 0x95,
  27958. 0xD7, 0xEA, 0x89, 0x31, 0x67, 0x3B, 0xF7, 0x11,
  27959. 0x2D, 0x40, 0x42, 0x10, 0x7B, 0x1B, 0x8B, 0x97,
  27960. 0x00, 0xC9, 0x74, 0xF9, 0xC4, 0xE8, 0x3A, 0x8F,
  27961. 0xAC, 0xD8, 0x9B, 0xFE, 0x0C, 0xA3, 0xCC, 0x4C,
  27962. 0x2F, 0xCE, 0x80, 0xA0, 0x3D, 0x35, 0x76, 0xC2,
  27963. 0x22, 0xA7, 0x92, 0xB7, 0x2B, 0x1F, 0x07, 0x0A,
  27964. 0xB7, 0xF6, 0xB6, 0xF2, 0xB5, 0xCA, 0x2A, 0xF5,
  27965. 0x05, 0x4A, 0xFA, 0x70, 0xA8, 0x96, 0x99, 0x01,
  27966. 0x59, 0xB4, 0x5D, 0x10, 0x03, 0xE2, 0xA0, 0x56,
  27967. 0x48, 0x67, 0x5E, 0x59, 0x60, 0x16, 0xF1, 0xB7,
  27968. 0x1D, 0xD0, 0xF7, 0xBD, 0xA7, 0xE2, 0x09, 0x7F,
  27969. 0xC7, 0x3B, 0x3A, 0x14, 0x3D, 0x12, 0xC7, 0x26,
  27970. 0x02, 0x0A, 0xC3, 0x49, 0x58, 0xAD, 0x70, 0x62,
  27971. 0xB9, 0x2B, 0x9A, 0xBF, 0x3C, 0xA6, 0xBE, 0x5A,
  27972. 0xE2, 0x9F, 0x57, 0x13, 0x5E, 0x62, 0x5A, 0x36,
  27973. 0x79, 0x71, 0x83, 0x7E, 0x63, 0x63, 0xD1, 0x53,
  27974. 0x20, 0x94, 0xE0, 0x22, 0xA2, 0x34, 0x67, 0xCF,
  27975. 0x93, 0x2E, 0x1F, 0x89, 0xB5, 0xB0, 0x80, 0x3C,
  27976. 0x1E, 0xC9, 0x9B, 0x58, 0x5A, 0x78, 0xB5, 0x86,
  27977. 0x50, 0x96, 0x74, 0x6F, 0x32, 0x25, 0x82, 0x14,
  27978. 0xEC, 0xB3, 0x80, 0x65, 0xC9, 0x7F, 0x45, 0x5E,
  27979. 0x15, 0x5A, 0xCC, 0x2D, 0xD0, 0x05, 0xA9, 0xC7,
  27980. 0x6B, 0xED, 0x59, 0xCD, 0xA7, 0x38, 0x37, 0xD3,
  27981. 0x03, 0x50, 0x4E, 0x6C, 0x97, 0x6A, 0x60, 0x6A,
  27982. 0x2B, 0xE7, 0xBB, 0xEC, 0x59, 0x48, 0xB9, 0x1A,
  27983. 0x34, 0x9E, 0x89, 0x36, 0x68, 0x8C, 0xC0, 0x27,
  27984. 0x97, 0x54, 0xB7, 0x43, 0xAB, 0xC5, 0x86, 0x66,
  27985. 0xB1, 0x9B, 0x6C, 0x32, 0x60, 0x05, 0x1F, 0x19,
  27986. 0x20, 0x6B, 0xB9, 0x62, 0xBB, 0x66, 0x33, 0xEB,
  27987. 0x00, 0x48, 0xE3, 0x2B, 0xAA, 0xCC, 0x5B, 0x02,
  27988. 0x0D, 0x02, 0xC8, 0x6C, 0xA9, 0x77, 0x0A, 0xD4,
  27989. 0x69, 0xDB, 0x54, 0xA1, 0x06, 0xAC, 0x73, 0xA3,
  27990. 0x5B, 0x80, 0x57, 0x42, 0x2B, 0x3D, 0xB2, 0x02,
  27991. 0xC5, 0xA5, 0xB4, 0xE3, 0xD5, 0x35, 0xF0, 0xFC,
  27992. 0x99, 0x32, 0x6C, 0x4B, 0x8B, 0x7B, 0x16, 0xF1,
  27993. 0xCB, 0x5A, 0xF9, 0x68, 0x03, 0xFA, 0x8C, 0x19,
  27994. 0x5F, 0xC0, 0xBC, 0xED, 0xDA, 0xAF, 0x01, 0x2A,
  27995. 0x51, 0x72, 0x8B, 0x76, 0x48, 0x90, 0x82, 0x37,
  27996. 0x3C, 0x91, 0xE9, 0x2C, 0x87, 0xAC, 0xCA, 0x79,
  27997. 0x51, 0x60, 0x78, 0x2E, 0x3B, 0x0D, 0xD6, 0x43,
  27998. 0x54, 0x4B, 0xB9, 0x6A, 0xBC, 0x27, 0x08, 0xD4,
  27999. 0x9B, 0x75, 0x9C, 0xF0, 0x57, 0xAA, 0x22, 0x3B,
  28000. 0xAF, 0xD9, 0x6A, 0x33, 0x0B, 0xAF, 0x39, 0x81,
  28001. 0x0F, 0xE8, 0x67, 0x1B, 0x43, 0x43, 0xC2, 0x97,
  28002. 0xDA, 0x1E, 0x19, 0x69, 0xC9, 0x96, 0x21, 0x6A,
  28003. 0xB5, 0x10, 0x6D, 0xA6, 0x68, 0x94, 0x1B, 0x16,
  28004. 0x0D, 0x44, 0x77, 0x01, 0x71, 0x36, 0xCB, 0xCA,
  28005. 0x5B, 0x5A, 0x8D, 0x44, 0xC4, 0xA8, 0xB1, 0xCF,
  28006. 0x3E, 0xF7, 0x97, 0x85, 0xE5, 0xAA, 0x25, 0xC3,
  28007. 0xA1, 0xAD, 0x6C, 0x24, 0xFD, 0x14, 0x0F, 0x79,
  28008. 0x20, 0x7D, 0xE5, 0xA4, 0x99, 0xF8, 0xA1, 0x53,
  28009. 0x4F, 0xFA, 0x80, 0x4A, 0xA7, 0xB3, 0x88, 0x9C,
  28010. 0xBE, 0x25, 0xC0, 0x41, 0x47, 0x04, 0xAA, 0x57,
  28011. 0x89, 0x7F, 0x17, 0x86, 0x23, 0x64, 0xEC, 0xA5,
  28012. 0x62, 0x58, 0x00, 0x72, 0x48, 0x81, 0x39, 0x12,
  28013. 0xB8, 0x36, 0x49, 0x7F, 0x03, 0x59, 0xC2, 0xF7,
  28014. 0x23, 0x8A, 0x05, 0xD3, 0x05, 0xA0, 0xEA, 0x15,
  28015. 0x2E, 0x72, 0xB4, 0x44, 0x17, 0xA8, 0x68, 0x13,
  28016. 0x4E, 0x91, 0xB3, 0xCA, 0x79, 0x31, 0x23, 0x2F,
  28017. 0xD4, 0xC2, 0x5F, 0x8C, 0x2A, 0x49, 0x2A, 0x33,
  28018. 0x9C, 0xDC, 0x0A, 0x13, 0x89, 0x67, 0x21, 0x14,
  28019. 0x51, 0xF2, 0x56, 0x26, 0x78, 0xFA, 0x14, 0x08,
  28020. 0x0A, 0x34, 0x43, 0x6C, 0x42, 0xB0, 0x78, 0x65,
  28021. 0xAC, 0x03, 0x6A, 0x81, 0xE9, 0x7A, 0x77, 0x87,
  28022. 0xA9, 0x38, 0x02, 0x5C, 0xAF, 0x81, 0x34, 0x50,
  28023. 0x36, 0x8B, 0xED, 0x0C, 0x94, 0xB1, 0x85, 0x76,
  28024. 0x04, 0x52, 0x64, 0x05, 0xD2, 0x7A, 0x1C, 0x1A,
  28025. 0xBC, 0x81, 0xB5, 0xB6, 0xEC, 0x13, 0xC7, 0x19,
  28026. 0x30, 0xA9, 0x7D, 0x92, 0x32, 0xCF, 0x70, 0x21,
  28027. 0xEF, 0x87, 0xA4, 0xD1, 0x55, 0x32, 0x8E, 0x62,
  28028. 0xB5, 0x83, 0xA8, 0x3B, 0x4A, 0xF2, 0x1F, 0x9F,
  28029. 0x57, 0x50, 0xF8, 0x57, 0x51, 0x50, 0x42, 0x4F,
  28030. 0x63, 0xB8, 0x99, 0xD7, 0x1C, 0xAD, 0x26, 0x7C,
  28031. 0x09, 0xE4, 0x46, 0x71, 0x46, 0xE1, 0x6E, 0x9B,
  28032. 0x6C, 0x65, 0x3F, 0x00, 0x8C, 0x31, 0x13, 0x75,
  28033. 0xE2, 0xE0, 0x06, 0xD4, 0x07, 0x6A, 0x54, 0x6B,
  28034. 0x82, 0xF5, 0x31, 0x42, 0x22, 0xF7, 0xC6, 0x54,
  28035. 0x31, 0x7E, 0x79, 0xEC, 0x60, 0x35, 0xB7, 0x3F,
  28036. 0xAF, 0x49, 0x17, 0x57, 0xE6, 0x1C, 0x82, 0x83,
  28037. 0x26, 0xD5, 0x30, 0x44, 0x54, 0x1C, 0x4D, 0x45,
  28038. 0x37, 0xAB, 0xD3, 0xEA, 0x1E, 0x67, 0x99, 0x8C,
  28039. 0x33, 0x82, 0x97, 0x4C, 0xA7, 0x8A, 0xE1, 0xB1,
  28040. 0x96, 0x0E, 0x4A, 0x92, 0x26, 0xB0, 0x21, 0x9A,
  28041. 0xB0, 0x70, 0xF0, 0xD7, 0xAA, 0x66, 0xD7, 0x6F,
  28042. 0x93, 0x16, 0xAD, 0xB8, 0x0C, 0x54, 0xD6, 0x49,
  28043. 0x97, 0x71, 0xB4, 0x71, 0xE8, 0x16, 0x8D, 0x47,
  28044. 0xBC, 0xAA, 0x08, 0x32, 0x4A, 0xB6, 0xBA, 0x92,
  28045. 0xC3, 0xA7, 0x02, 0x75, 0xF2, 0x4F, 0xA4, 0xDC,
  28046. 0x10, 0xE2, 0x51, 0x63, 0x3F, 0xB9, 0x8D, 0x16,
  28047. 0x2B, 0xB5, 0x53, 0x72, 0x02, 0xC6, 0xA5, 0x53,
  28048. 0xCE, 0x78, 0x41, 0xC4, 0xD4, 0x0B, 0x87, 0x3B,
  28049. 0x85, 0xCA, 0x03, 0xA0, 0xA1, 0xE1, 0xCF, 0xAD,
  28050. 0xE6, 0xBA, 0x51, 0x80, 0xAB, 0x13, 0x23, 0xCC,
  28051. 0xBA, 0x9A, 0x3E, 0x9C, 0x53, 0xD3, 0x75, 0x75,
  28052. 0xAB, 0x1F, 0xD9, 0xE7, 0x31, 0x6C, 0x6F, 0xEE,
  28053. 0xCB, 0x0A, 0x14, 0xDF, 0x6F, 0x2D, 0xA5, 0x6C,
  28054. 0x2F, 0x56, 0xF5, 0x5A, 0x89, 0x63, 0x5C, 0xFC,
  28055. 0xFD, 0xA4, 0x79, 0x27, 0xAF, 0x1F, 0x0A, 0x47,
  28056. 0xB2, 0xD4, 0xE4, 0xE6, 0x16, 0x34, 0xB1, 0xB5,
  28057. 0x1D, 0x37, 0xA3, 0xA3, 0x07, 0xA9, 0x72, 0x42,
  28058. 0x0D, 0xE1, 0xB7, 0xA4, 0x81, 0xB8, 0x3E, 0x58,
  28059. 0x3B, 0x6A, 0xF1, 0x6F, 0x63, 0xCB, 0x00, 0xC6
  28060. };
  28061. static const byte c_1024[KYBER1024_CIPHER_TEXT_SIZE] = {
  28062. 0x0C, 0x68, 0x1B, 0x4A, 0xA8, 0x1F, 0x26, 0xAD,
  28063. 0xFB, 0x64, 0x5E, 0xC2, 0x4B, 0x37, 0x52, 0xF6,
  28064. 0xB3, 0x2C, 0x68, 0x64, 0x5A, 0xA5, 0xE7, 0xA9,
  28065. 0x99, 0xB6, 0x20, 0x36, 0xA5, 0x3D, 0xC5, 0xCB,
  28066. 0x06, 0x0A, 0x47, 0x3C, 0x08, 0xE5, 0xDA, 0x5C,
  28067. 0x0F, 0x5A, 0xF0, 0xE5, 0x17, 0x0C, 0x65, 0x97,
  28068. 0xE5, 0x0E, 0xC0, 0x80, 0x60, 0xF9, 0x9B, 0x0C,
  28069. 0x00, 0xEE, 0x9B, 0xDD, 0xAD, 0x7E, 0x7D, 0x25,
  28070. 0xA2, 0x2B, 0x22, 0x6F, 0x90, 0x14, 0x9B, 0x4C,
  28071. 0xE8, 0x87, 0xC7, 0x2F, 0xB6, 0x0A, 0xFF, 0x21,
  28072. 0x44, 0xEA, 0x2A, 0x72, 0x38, 0x3B, 0x31, 0x18,
  28073. 0xF9, 0x22, 0xD0, 0x32, 0xA1, 0x6F, 0x55, 0x42,
  28074. 0x89, 0x90, 0x2A, 0x14, 0xCF, 0x77, 0x55, 0x51,
  28075. 0x2B, 0xB1, 0x18, 0x6B, 0xAF, 0xAF, 0xFE, 0x79,
  28076. 0x4D, 0x2B, 0x6C, 0xDE, 0x90, 0x10, 0x9E, 0x65,
  28077. 0x82, 0xD3, 0x9C, 0xE0, 0xC9, 0x61, 0x97, 0x48,
  28078. 0x4B, 0x3F, 0xA0, 0x7F, 0xC9, 0x1D, 0x39, 0x4F,
  28079. 0xC8, 0xD8, 0x8E, 0x7F, 0xC4, 0xBE, 0x00, 0x2E,
  28080. 0x2D, 0xB5, 0x6F, 0x0C, 0x4D, 0x9D, 0x3F, 0xBD,
  28081. 0xA2, 0x74, 0x53, 0x6A, 0x0B, 0x86, 0xAB, 0xC6,
  28082. 0xE3, 0x9B, 0xDA, 0x52, 0x93, 0x1A, 0xEB, 0xB8,
  28083. 0xF1, 0x08, 0x4C, 0x5C, 0x1F, 0x7C, 0xB3, 0x17,
  28084. 0x77, 0x88, 0xB7, 0xF3, 0x31, 0xB7, 0x07, 0x43,
  28085. 0x61, 0x16, 0x34, 0x91, 0xD4, 0x28, 0xE7, 0x8B,
  28086. 0xCB, 0xB5, 0x7B, 0x63, 0x08, 0x41, 0xAA, 0x98,
  28087. 0x73, 0x33, 0x37, 0x7C, 0xF0, 0x95, 0x69, 0xCF,
  28088. 0xD1, 0x4C, 0xC2, 0xA1, 0x1C, 0x50, 0x1B, 0xDF,
  28089. 0x82, 0xC9, 0x3D, 0xE0, 0x5B, 0xEA, 0x20, 0x06,
  28090. 0x0D, 0xE8, 0x9C, 0x68, 0x6B, 0x82, 0x45, 0x71,
  28091. 0xCE, 0xF9, 0x4A, 0xB3, 0xFD, 0xAF, 0xA8, 0x51,
  28092. 0x26, 0x19, 0x81, 0x36, 0x69, 0xD4, 0xF5, 0x36,
  28093. 0x37, 0xFE, 0xFA, 0x4D, 0x02, 0x8C, 0xB2, 0x33,
  28094. 0xE5, 0x69, 0x30, 0xE2, 0x23, 0x5F, 0x7E, 0x60,
  28095. 0x34, 0xCA, 0x94, 0xB1, 0x43, 0xB7, 0x7A, 0xD4,
  28096. 0xA6, 0x87, 0x56, 0xE8, 0xA9, 0x18, 0x4D, 0xBA,
  28097. 0x61, 0xA8, 0x9F, 0x91, 0xED, 0xFB, 0x51, 0xA3,
  28098. 0x92, 0x11, 0x40, 0x24, 0x73, 0xA5, 0xF8, 0x91,
  28099. 0x45, 0x73, 0x6B, 0x2B, 0xF8, 0x56, 0x9C, 0x70,
  28100. 0x5B, 0x0C, 0xDB, 0x89, 0x80, 0xA4, 0x47, 0xE4,
  28101. 0xE1, 0xEA, 0xAD, 0x3E, 0x7E, 0x05, 0x78, 0xF5,
  28102. 0xF8, 0x6B, 0x8D, 0x03, 0xC9, 0xDA, 0xFE, 0x87,
  28103. 0x5E, 0x33, 0x9B, 0x44, 0x23, 0x84, 0x56, 0x16,
  28104. 0x79, 0x9E, 0xDC, 0xE0, 0x5F, 0x31, 0xB9, 0x26,
  28105. 0x64, 0xC5, 0xA5, 0x92, 0x53, 0xA6, 0x0E, 0x9D,
  28106. 0x89, 0x54, 0x8A, 0x30, 0x0C, 0x1A, 0xDB, 0x6D,
  28107. 0x19, 0x0A, 0x77, 0x5C, 0x5E, 0xE6, 0xE8, 0xA8,
  28108. 0x9B, 0x6E, 0x77, 0x9B, 0x03, 0x4C, 0x34, 0x00,
  28109. 0xA6, 0x25, 0xF4, 0xBB, 0xED, 0xBF, 0x91, 0x9C,
  28110. 0x45, 0xB2, 0xBC, 0xD1, 0x4C, 0x66, 0x92, 0x48,
  28111. 0xFC, 0x43, 0xC3, 0xEF, 0x47, 0xE1, 0x00, 0x75,
  28112. 0x89, 0x42, 0xE7, 0x5E, 0x8E, 0xD6, 0x07, 0x5A,
  28113. 0x96, 0xD7, 0x0D, 0x4E, 0xBD, 0x2B, 0x61, 0x35,
  28114. 0x82, 0x24, 0xDD, 0xA1, 0xEC, 0x4C, 0x19, 0xC2,
  28115. 0xA9, 0x28, 0x98, 0x17, 0x6F, 0xEB, 0x3C, 0x02,
  28116. 0xED, 0xCB, 0x99, 0x08, 0xBA, 0xE4, 0x9B, 0xD9,
  28117. 0x4A, 0xF0, 0x28, 0xED, 0xF8, 0xCF, 0xC2, 0xE5,
  28118. 0xF2, 0xE0, 0xBD, 0x37, 0x50, 0x06, 0x98, 0x6A,
  28119. 0xD4, 0x9E, 0x71, 0x75, 0x48, 0xE7, 0x46, 0xFE,
  28120. 0xF4, 0x9C, 0x86, 0x8B, 0xCE, 0xA2, 0x79, 0x0A,
  28121. 0xA9, 0x7E, 0x04, 0x06, 0x1B, 0x75, 0x60, 0x5C,
  28122. 0xB3, 0x9E, 0xFD, 0x46, 0x3D, 0x7B, 0x3D, 0x68,
  28123. 0xBA, 0x57, 0x44, 0x34, 0xFF, 0x7B, 0xE8, 0xE2,
  28124. 0xB8, 0x4B, 0xFC, 0x47, 0xE6, 0x7E, 0x9C, 0xD1,
  28125. 0x5F, 0x3E, 0xD4, 0x50, 0xC6, 0x1A, 0xFB, 0xA7,
  28126. 0x9A, 0x20, 0xB0, 0xB6, 0xF2, 0x87, 0x77, 0x7C,
  28127. 0x72, 0xF4, 0xAD, 0x24, 0x81, 0x74, 0xF1, 0x95,
  28128. 0x94, 0x77, 0xAA, 0x7A, 0x7C, 0x97, 0xF1, 0x22,
  28129. 0xC5, 0x04, 0x47, 0xC7, 0x48, 0x4F, 0x38, 0x2B,
  28130. 0xC4, 0x7D, 0x81, 0xFC, 0xC9, 0xC7, 0xE8, 0x92,
  28131. 0xC8, 0x83, 0x9D, 0x37, 0xB3, 0x53, 0x94, 0xB5,
  28132. 0x3E, 0x6B, 0x2B, 0x18, 0x95, 0xAB, 0xB0, 0xDE,
  28133. 0x8C, 0x98, 0xF2, 0x63, 0x3D, 0xC4, 0x41, 0x3A,
  28134. 0x8D, 0x57, 0x35, 0xDF, 0xC9, 0xA6, 0x40, 0x26,
  28135. 0xB6, 0xF3, 0x47, 0x79, 0xD6, 0xAC, 0x8A, 0xD9,
  28136. 0x9C, 0xC3, 0x1A, 0xA8, 0x98, 0xC2, 0xE7, 0x05,
  28137. 0x7F, 0x3D, 0xB8, 0xA1, 0xA8, 0xA9, 0x85, 0x27,
  28138. 0xA7, 0x9E, 0x43, 0x55, 0x2F, 0x28, 0xD1, 0x02,
  28139. 0x3E, 0x1F, 0x6A, 0x6B, 0x84, 0x85, 0x5C, 0xF5,
  28140. 0xE6, 0xDF, 0x88, 0x9B, 0xA2, 0x69, 0xF0, 0x48,
  28141. 0x94, 0x6E, 0x84, 0x02, 0x1C, 0x65, 0xC5, 0xA9,
  28142. 0x3B, 0x00, 0x7B, 0x07, 0x74, 0x1C, 0x1E, 0xE1,
  28143. 0x76, 0xC7, 0x39, 0x49, 0x11, 0x0F, 0x54, 0x8E,
  28144. 0xF4, 0x33, 0x2D, 0xCD, 0xD4, 0x91, 0xD2, 0xCE,
  28145. 0xFD, 0x02, 0x48, 0x88, 0x3F, 0x5E, 0x95, 0x25,
  28146. 0xBC, 0x91, 0xF3, 0x0A, 0xF1, 0x7C, 0xF5, 0xA9,
  28147. 0x8D, 0xD4, 0x4E, 0xF9, 0xA7, 0x1F, 0x99, 0xBB,
  28148. 0x73, 0x29, 0x85, 0xBA, 0x10, 0xA7, 0x23, 0xEF,
  28149. 0x47, 0x6F, 0xCF, 0x96, 0x6D, 0xA9, 0x45, 0x6B,
  28150. 0x24, 0x97, 0x8E, 0x33, 0x05, 0x0D, 0x0E, 0xC9,
  28151. 0x0D, 0x3C, 0xE4, 0x63, 0x78, 0x85, 0x1C, 0x9E,
  28152. 0xCF, 0xCF, 0xD3, 0x6C, 0x89, 0x5D, 0x44, 0xE9,
  28153. 0xE5, 0x06, 0x99, 0x30, 0x82, 0x52, 0x3D, 0x26,
  28154. 0x18, 0x57, 0x66, 0xB2, 0x35, 0x68, 0xCB, 0x95,
  28155. 0xE6, 0x41, 0x08, 0xF8, 0x9D, 0x10, 0x14, 0x74,
  28156. 0x7C, 0x67, 0xB6, 0xF3, 0xC8, 0x76, 0x7B, 0xE5,
  28157. 0xFC, 0x34, 0x12, 0x27, 0xDE, 0x94, 0x88, 0x86,
  28158. 0x1C, 0x5F, 0xE8, 0x11, 0x40, 0x9F, 0x80, 0x95,
  28159. 0x7D, 0x07, 0x52, 0x2A, 0x72, 0xCF, 0x6A, 0xB0,
  28160. 0x37, 0x8D, 0x0F, 0x2F, 0x28, 0xAF, 0x54, 0x81,
  28161. 0x85, 0xC3, 0x93, 0x67, 0x77, 0x99, 0x44, 0x66,
  28162. 0xA0, 0x19, 0xD3, 0x3B, 0x18, 0xA5, 0x4F, 0x38,
  28163. 0x0A, 0x33, 0x89, 0x2A, 0xB4, 0xD4, 0xBD, 0x50,
  28164. 0x7B, 0x5A, 0x61, 0xD0, 0xD3, 0x58, 0x34, 0x1A,
  28165. 0xC9, 0x2F, 0x07, 0xB4, 0x3B, 0x8F, 0x6A, 0xFC,
  28166. 0x69, 0x91, 0xBB, 0x6A, 0x1E, 0xAC, 0x23, 0xCA,
  28167. 0x6F, 0x73, 0xE9, 0x1F, 0x24, 0x64, 0xBD, 0x11,
  28168. 0x90, 0x98, 0xD7, 0xE7, 0x68, 0xE7, 0x7E, 0xCE,
  28169. 0x53, 0xFB, 0x89, 0x9B, 0xEB, 0x42, 0x26, 0x5E,
  28170. 0xCF, 0x7B, 0x27, 0x1F, 0x66, 0x54, 0x62, 0x82,
  28171. 0xD4, 0x72, 0xC3, 0x62, 0x39, 0x00, 0x6B, 0xB0,
  28172. 0xAB, 0xAB, 0xCC, 0xA2, 0x45, 0x50, 0xBA, 0xA0,
  28173. 0xA6, 0x01, 0x34, 0x8C, 0x81, 0x0F, 0xF5, 0xF9,
  28174. 0xEE, 0x50, 0x4B, 0xF7, 0x15, 0x5D, 0xEE, 0x41,
  28175. 0x41, 0xA1, 0x16, 0x05, 0xA4, 0xF3, 0x50, 0x9A,
  28176. 0xC9, 0xCA, 0xEF, 0x66, 0x24, 0xD2, 0x1D, 0xE3,
  28177. 0x32, 0xD5, 0xD5, 0x08, 0x28, 0xB5, 0x2E, 0x92,
  28178. 0x88, 0x5D, 0x3B, 0x90, 0x55, 0x3B, 0x14, 0x46,
  28179. 0x3A, 0xFB, 0x1E, 0xDC, 0xCD, 0x3B, 0x56, 0x9B,
  28180. 0x5A, 0x7F, 0x00, 0xBB, 0x66, 0x76, 0x9D, 0xAD,
  28181. 0xAC, 0x23, 0xAD, 0x8B, 0xB5, 0xD7, 0x3A, 0x6F,
  28182. 0x39, 0x0E, 0x6F, 0xC2, 0xF6, 0xF8, 0xEE, 0x3C,
  28183. 0xF4, 0x00, 0x9A, 0x5C, 0x3E, 0x1E, 0xF6, 0x0E,
  28184. 0x8F, 0x04, 0x06, 0x72, 0xD2, 0x62, 0xE6, 0x49,
  28185. 0x03, 0x79, 0xBB, 0xC7, 0x04, 0x95, 0xDF, 0xF2,
  28186. 0x37, 0xBE, 0xCD, 0x99, 0x52, 0xCD, 0x7E, 0xDE,
  28187. 0xB6, 0xD1, 0xDF, 0xC3, 0x60, 0xB3, 0xFC, 0x8B,
  28188. 0x0A, 0xF4, 0x80, 0xFF, 0xE0, 0x24, 0xAE, 0xEF,
  28189. 0xCD, 0x4E, 0x9C, 0xE9, 0x5D, 0x9B, 0x46, 0x9C,
  28190. 0x9A, 0x70, 0xE5, 0x11, 0x0D, 0xA0, 0xBA, 0xC1,
  28191. 0x24, 0xFC, 0x37, 0x41, 0xDC, 0xF4, 0x91, 0x16,
  28192. 0x26, 0x17, 0x96, 0x50, 0x4D, 0x5F, 0x49, 0x0B,
  28193. 0x43, 0x3C, 0x33, 0xC4, 0x0E, 0xDC, 0xE2, 0xB7,
  28194. 0x51, 0x51, 0xDA, 0x25, 0x6A, 0x86, 0x8A, 0x5E,
  28195. 0x35, 0xF8, 0x62, 0x26, 0xB8, 0x15, 0x1C, 0x91,
  28196. 0x93, 0x4C, 0xCC, 0x3D, 0xAC, 0xA3, 0x91, 0xDE,
  28197. 0xCC, 0xA7, 0x45, 0x37, 0x56, 0x60, 0xB6, 0xEC,
  28198. 0x41, 0xAE, 0x5D, 0x81, 0x08, 0x38, 0xCB, 0xEE,
  28199. 0xFF, 0xA1, 0x25, 0x57, 0x88, 0x44, 0x12, 0x35,
  28200. 0x7B, 0x10, 0x08, 0x36, 0x3D, 0x32, 0xB2, 0x37,
  28201. 0xAA, 0x1D, 0xD8, 0xE2, 0xD9, 0xC6, 0x36, 0x7A,
  28202. 0xDA, 0x09, 0xB2, 0xC9, 0x50, 0x60, 0x20, 0x6C,
  28203. 0xEC, 0x3E, 0xED, 0x39, 0x1F, 0xDC, 0x5D, 0xBE,
  28204. 0xF6, 0xF0, 0x8B, 0xDF, 0x04, 0x08, 0xE5, 0x85,
  28205. 0xAE, 0x5E, 0xBC, 0x8E, 0x97, 0x45, 0xD4, 0x4F,
  28206. 0xEC, 0xA9, 0x75, 0xAB, 0xBC, 0x14, 0x0B, 0xB3,
  28207. 0x7B, 0x8A, 0xDD, 0x16, 0xFC, 0xC2, 0x95, 0x69,
  28208. 0x10, 0xDC, 0x72, 0xBB, 0x3F, 0x02, 0xE9, 0xA1,
  28209. 0x30, 0xC9, 0xA8, 0x4F, 0x9C, 0xCB, 0x74, 0xD1,
  28210. 0x34, 0xCD, 0xF4, 0x0A, 0xFC, 0xBA, 0x20, 0x09,
  28211. 0xC8, 0xF0, 0x04, 0x02, 0x39, 0xBC, 0x99, 0x22,
  28212. 0x0E, 0xF6, 0x4C, 0x4D, 0xCC, 0xDE, 0x2E, 0x2E,
  28213. 0x5C, 0x9B, 0x68, 0x60, 0x2F, 0xBE, 0x8E, 0xF4,
  28214. 0xC9, 0x8B, 0x34, 0x68, 0xC7, 0x9D, 0xF4, 0xE0,
  28215. 0x78, 0x51, 0x1B, 0xFB, 0x8A, 0xA3, 0xDA, 0x09,
  28216. 0x59, 0x7A, 0x02, 0x51, 0x1E, 0x7C, 0x21, 0xA7,
  28217. 0xCF, 0x66, 0xA9, 0x38, 0x43, 0xA9, 0x48, 0x68,
  28218. 0xF1, 0x9E, 0x85, 0x52, 0x55, 0x2E, 0x3A, 0xCD,
  28219. 0xF6, 0xCB, 0x81, 0x06, 0x34, 0xDB, 0x97, 0xCB,
  28220. 0xC4, 0xBB, 0x56, 0x97, 0x09, 0xDA, 0xD4, 0x84,
  28221. 0x56, 0x45, 0x44, 0x6F, 0xA8, 0xD2, 0x89, 0xFC,
  28222. 0x59, 0x30, 0x7B, 0x80, 0x1E, 0x60, 0xCE, 0x2A,
  28223. 0x91, 0xE0, 0x6E, 0x9C, 0x22, 0xC1, 0x6E, 0x2E,
  28224. 0x59, 0xBD, 0xE3, 0x8A, 0x41, 0x6B, 0xB1, 0xB4,
  28225. 0xAC, 0x54, 0x57, 0x43, 0x8F, 0xDC, 0x5D, 0x64,
  28226. 0x45, 0x0A, 0x89, 0xEC, 0xB8, 0x32, 0xC1, 0xBB,
  28227. 0x27, 0x9D, 0xBF, 0x59, 0x33, 0x46, 0x81, 0x77,
  28228. 0x6A, 0xC0, 0x04, 0x09, 0x84, 0x6D, 0x09, 0xD6,
  28229. 0xF6, 0x87, 0x77, 0x2E, 0x34, 0x08, 0x50, 0xAB,
  28230. 0x86, 0x73, 0x38, 0x42, 0x15, 0xE1, 0x2C, 0x8D,
  28231. 0x0F, 0x53, 0x1C, 0x45, 0x1E, 0x58, 0x49, 0x3E,
  28232. 0x0E, 0xE4, 0x15, 0xAD, 0x59, 0x4D, 0xF3, 0x8C,
  28233. 0x34, 0x40, 0x8C, 0x7E, 0xD9, 0xF0, 0xC3, 0x92,
  28234. 0xF1, 0x53, 0x46, 0x04, 0xEA, 0xC3, 0xD9, 0xC1,
  28235. 0x54, 0x65, 0xA9, 0xA4, 0x66, 0x32, 0x21, 0x4B,
  28236. 0x53, 0x69, 0x90, 0xD7, 0x80, 0x78, 0xE5, 0xBD,
  28237. 0x7E, 0xAE, 0x20, 0x13, 0xFF, 0xF8, 0xFD, 0xD8,
  28238. 0xB2, 0x75, 0xC8, 0x9D, 0x97, 0xC9, 0x35, 0x3D,
  28239. 0xF3, 0xC4, 0x2A, 0x28, 0xE8, 0x14, 0xD8, 0x46,
  28240. 0x8E, 0x2B, 0x48, 0xDB, 0x09, 0x76, 0xD8, 0x8F,
  28241. 0x5E, 0xEC, 0xEF, 0xEA, 0xFB, 0x8F, 0x7F, 0x4A,
  28242. 0xF2, 0x91, 0xA7, 0x28, 0xF6, 0x24, 0x9E, 0xCF,
  28243. 0x56, 0x22, 0x33, 0x92, 0x69, 0xAA, 0x94, 0x53,
  28244. 0x29, 0xE9, 0x19, 0xF8, 0xB4, 0x41, 0xC8, 0x3D,
  28245. 0x55, 0x07, 0xF3, 0x0D, 0xF0, 0xFD, 0x2B, 0x13,
  28246. 0xFF, 0x80, 0x6F, 0x52, 0x2D, 0xAA, 0x11, 0xAF,
  28247. 0x67, 0x6A, 0x51, 0x3C, 0x14, 0x9C, 0x70, 0xF0,
  28248. 0xD6, 0xE9, 0x9A, 0x88, 0x04, 0x50, 0xA5, 0x4E,
  28249. 0x04, 0x17, 0xFE, 0x3C, 0x1E, 0x51, 0x3E, 0x9D,
  28250. 0x92, 0x0E, 0x30, 0xA8, 0xB4, 0x28, 0x91, 0x26,
  28251. 0x7A, 0x2D, 0xC5, 0x0A, 0xD8, 0x1F, 0x98, 0x04,
  28252. 0x49, 0x20, 0xC0, 0x99, 0xDF, 0x22, 0xC7, 0x39,
  28253. 0x98, 0xA2, 0x5C, 0x58, 0x1A, 0x51, 0x78, 0xC7,
  28254. 0x2B, 0x17, 0xAC, 0x87, 0x5B, 0xC6, 0x85, 0x48,
  28255. 0xA0, 0xFB, 0x0C, 0xBE, 0xE3, 0x8F, 0x05, 0x01,
  28256. 0x7B, 0x12, 0x43, 0x33, 0x43, 0xA6, 0x58, 0xF1,
  28257. 0x98, 0x0C, 0x81, 0x24, 0xEA, 0x6D, 0xD8, 0x1F
  28258. };
  28259. static const byte kprime_1024[KYBER_SS_SZ] = {
  28260. 0x8F, 0x33, 0x6E, 0x9C, 0x28, 0xDF, 0x34, 0x9E,
  28261. 0x03, 0x22, 0x0A, 0xF0, 0x1C, 0x42, 0x83, 0x2F,
  28262. 0xEF, 0xAB, 0x1F, 0x2A, 0x74, 0xC1, 0x6F, 0xAF,
  28263. 0x6F, 0x64, 0xAD, 0x07, 0x1C, 0x1A, 0x33, 0x94
  28264. };
  28265. #endif
  28266. static byte ss[KYBER_SS_SZ];
  28267. key = (KyberKey*)XMALLOC(sizeof(KyberKey), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28268. ExpectNotNull(key);
  28269. if (key != NULL) {
  28270. XMEMSET(key, 0, sizeof(KyberKey));
  28271. }
  28272. #ifndef WOLFSSL_NO_KYBER512
  28273. ExpectIntEQ(wc_KyberKey_Init(KYBER512, key, NULL, INVALID_DEVID), 0);
  28274. ExpectIntEQ(wc_KyberKey_DecodePrivateKey(key, dk_512, sizeof(dk_512)), 0);
  28275. ExpectIntEQ(wc_KyberKey_Decapsulate(key, ss, c_512, sizeof(c_512)), 0);
  28276. ExpectIntEQ(XMEMCMP(ss, kprime_512, KYBER_SS_SZ), 0);
  28277. wc_KyberKey_Free(key);
  28278. #endif
  28279. #ifndef WOLFSSL_NO_KYBER768
  28280. ExpectIntEQ(wc_KyberKey_Init(KYBER768, key, NULL, INVALID_DEVID), 0);
  28281. ExpectIntEQ(wc_KyberKey_DecodePrivateKey(key, dk_768, sizeof(dk_768)), 0);
  28282. ExpectIntEQ(wc_KyberKey_Decapsulate(key, ss, c_768, sizeof(c_768)), 0);
  28283. ExpectIntEQ(XMEMCMP(ss, kprime_768, KYBER_SS_SZ), 0);
  28284. wc_KyberKey_Free(key);
  28285. #endif
  28286. #ifndef WOLFSSL_NO_KYBER1024
  28287. ExpectIntEQ(wc_KyberKey_Init(KYBER1024, key, NULL, INVALID_DEVID), 0);
  28288. ExpectIntEQ(wc_KyberKey_DecodePrivateKey(key, dk_1024, sizeof(dk_1024)), 0);
  28289. ExpectIntEQ(wc_KyberKey_Decapsulate(key, ss, c_1024, sizeof(c_1024)), 0);
  28290. ExpectIntEQ(XMEMCMP(ss, kprime_1024, KYBER_SS_SZ), 0);
  28291. wc_KyberKey_Free(key);
  28292. #endif
  28293. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28294. #endif
  28295. return EXPECT_RESULT();
  28296. }
  28297. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  28298. !defined(WOLFSSL_DILITHIUM_NO_VERIFY) && !defined(WOLFSSL_NO_ML_DSA_44)
  28299. static const byte ml_dsa_44_pub_key[] = {
  28300. 0x7c, 0x33, 0x31, 0x41, 0x15, 0xa7, 0x2d, 0x6b,
  28301. 0x17, 0x7c, 0x10, 0xab, 0x75, 0xf7, 0x83, 0xb3,
  28302. 0x30, 0x75, 0x6f, 0xa9, 0x42, 0xb0, 0x9b, 0x59,
  28303. 0x59, 0x99, 0x2b, 0x5d, 0x7d, 0x6e, 0xeb, 0xdd,
  28304. 0xd9, 0x99, 0x8f, 0x7b, 0xad, 0xe5, 0x90, 0x0f,
  28305. 0xa4, 0x80, 0xd8, 0xa2, 0x0d, 0x95, 0xea, 0x63,
  28306. 0x2b, 0xcf, 0xb4, 0x5b, 0x3c, 0xd1, 0x5a, 0xc4,
  28307. 0xc4, 0xd1, 0x71, 0x28, 0x4b, 0x0b, 0x28, 0x32,
  28308. 0x73, 0xb5, 0x0d, 0xd6, 0x8f, 0x6b, 0x01, 0x26,
  28309. 0x04, 0x45, 0xa3, 0x80, 0xc0, 0x21, 0x12, 0xee,
  28310. 0x52, 0x0f, 0x35, 0xe4, 0x8e, 0xca, 0xf8, 0x91,
  28311. 0xf4, 0x99, 0x51, 0xe2, 0x80, 0x76, 0xa7, 0x2d,
  28312. 0x09, 0xf5, 0x04, 0xcc, 0xa6, 0x6b, 0x20, 0xc4,
  28313. 0xac, 0xcd, 0x6c, 0x9c, 0x09, 0xe7, 0x51, 0xa2,
  28314. 0x29, 0x60, 0xfd, 0xf2, 0xbd, 0x7e, 0x4c, 0x9d,
  28315. 0xc0, 0xba, 0x62, 0x2f, 0x53, 0xb2, 0x47, 0x03,
  28316. 0xf2, 0x6f, 0x70, 0x51, 0xa8, 0xe1, 0xb7, 0x9f,
  28317. 0x37, 0x15, 0xfa, 0xd1, 0x6c, 0x74, 0x1a, 0x2b,
  28318. 0x4f, 0x39, 0x4f, 0x43, 0x49, 0x71, 0x6a, 0xf8,
  28319. 0x7c, 0x65, 0x1a, 0xdd, 0x1a, 0x25, 0xf8, 0x79,
  28320. 0xfa, 0x8c, 0x02, 0xf2, 0xf7, 0xf7, 0x7b, 0x9f,
  28321. 0xe4, 0xaf, 0x9e, 0x1a, 0x0b, 0x5b, 0x2e, 0x41,
  28322. 0xbb, 0xa9, 0x4f, 0xd0, 0xdb, 0xad, 0xe5, 0x25,
  28323. 0xff, 0x36, 0x3b, 0x9a, 0xc3, 0xdf, 0xb6, 0x27,
  28324. 0xd3, 0xba, 0xb0, 0xd4, 0xb2, 0x07, 0xc3, 0xd8,
  28325. 0xab, 0x10, 0x3d, 0xcd, 0x23, 0x52, 0x46, 0xe6,
  28326. 0x96, 0x57, 0x85, 0xc7, 0x60, 0xe2, 0x8c, 0x46,
  28327. 0x65, 0x7d, 0x76, 0x1c, 0x45, 0x20, 0x5d, 0x51,
  28328. 0xd6, 0x13, 0xde, 0xe5, 0x3d, 0xc2, 0x8c, 0x36,
  28329. 0xdb, 0x7f, 0x83, 0x6f, 0x6a, 0xc2, 0xa3, 0xf2,
  28330. 0xdc, 0x63, 0x69, 0x7f, 0xbd, 0xd0, 0xc1, 0x90,
  28331. 0xfb, 0x62, 0x42, 0xa1, 0xf6, 0xf7, 0xdd, 0xc2,
  28332. 0x4a, 0x38, 0x62, 0x9b, 0xef, 0x67, 0xf9, 0x5c,
  28333. 0xd8, 0xff, 0xf4, 0xf2, 0x67, 0x90, 0x42, 0x85,
  28334. 0xaf, 0xe2, 0x92, 0x6e, 0xc4, 0x9b, 0x63, 0xc3,
  28335. 0x91, 0xa5, 0x11, 0x66, 0x13, 0x83, 0xbc, 0xbb,
  28336. 0xc7, 0x34, 0x3b, 0x30, 0x40, 0x53, 0x91, 0xdf,
  28337. 0x7c, 0x3d, 0x17, 0xdd, 0xa1, 0xa6, 0x80, 0xfd,
  28338. 0x26, 0x9d, 0x60, 0x7b, 0xcd, 0xb4, 0x2b, 0xba,
  28339. 0x61, 0x0f, 0x43, 0x7c, 0x51, 0x3c, 0xb9, 0xfa,
  28340. 0xdb, 0x48, 0x35, 0x9f, 0x0d, 0x0c, 0x04, 0xe8,
  28341. 0xf9, 0x6e, 0x07, 0x65, 0x7d, 0x46, 0x1b, 0xd2,
  28342. 0x51, 0xdb, 0x55, 0x27, 0xd7, 0x3d, 0x1e, 0x36,
  28343. 0x07, 0x59, 0x18, 0xec, 0x04, 0x4b, 0x87, 0xbb,
  28344. 0xfb, 0x27, 0xac, 0xeb, 0x8f, 0x43, 0x46, 0xd0,
  28345. 0x39, 0x00, 0x90, 0x54, 0x70, 0xb1, 0x71, 0xf2,
  28346. 0xe7, 0x3d, 0x02, 0x1a, 0xcf, 0x87, 0x16, 0x67,
  28347. 0xa2, 0x3c, 0x31, 0x48, 0xe8, 0xbd, 0x4f, 0xb3,
  28348. 0xc2, 0xfd, 0x3d, 0xa1, 0x9c, 0x87, 0x54, 0x60,
  28349. 0x30, 0x21, 0x52, 0x57, 0xcd, 0x03, 0x96, 0x9e,
  28350. 0xa7, 0x8d, 0xe5, 0x02, 0x04, 0x78, 0x43, 0x72,
  28351. 0xda, 0xb2, 0x22, 0xf1, 0xee, 0x8f, 0x27, 0x0b,
  28352. 0x8f, 0x7b, 0xf8, 0xbc, 0x16, 0xa1, 0xef, 0x0b,
  28353. 0x35, 0xda, 0xfc, 0x29, 0x1b, 0xf8, 0xa1, 0x35,
  28354. 0x40, 0xe7, 0xed, 0x4c, 0x02, 0x4a, 0x83, 0xb7,
  28355. 0x49, 0x75, 0x34, 0x3f, 0x2b, 0xb3, 0x61, 0xf5,
  28356. 0xa3, 0x9b, 0x23, 0xca, 0xfb, 0x58, 0x16, 0x4f,
  28357. 0x3c, 0x50, 0xbf, 0x81, 0xab, 0x54, 0x50, 0x1a,
  28358. 0x39, 0x57, 0x5f, 0x9a, 0x72, 0x22, 0xba, 0xa4,
  28359. 0xf6, 0xbf, 0xac, 0x31, 0x5c, 0xc5, 0x96, 0xd7,
  28360. 0xa9, 0xe4, 0x3b, 0x0c, 0xd0, 0x7f, 0x79, 0x68,
  28361. 0x4d, 0x41, 0x04, 0x81, 0x73, 0xcf, 0x47, 0x4a,
  28362. 0x7b, 0x37, 0xac, 0x8e, 0x47, 0x0d, 0x72, 0x65,
  28363. 0x0f, 0x9d, 0x44, 0xd7, 0x08, 0x21, 0x5b, 0x3f,
  28364. 0xc8, 0x9d, 0xea, 0xa2, 0x64, 0x7b, 0x0d, 0x98,
  28365. 0xc1, 0x61, 0xcd, 0xa4, 0xf7, 0x8c, 0x4a, 0xa3,
  28366. 0x3b, 0xdd, 0x92, 0xce, 0x61, 0x97, 0x0e, 0x98,
  28367. 0xa4, 0x10, 0xb5, 0x1f, 0xc5, 0xfb, 0xee, 0x49,
  28368. 0x36, 0x8f, 0xe3, 0x2d, 0x46, 0x9c, 0xa9, 0xff,
  28369. 0xdd, 0x1a, 0x48, 0x1b, 0x5a, 0x99, 0x84, 0x0a,
  28370. 0x3d, 0x5c, 0xd7, 0x67, 0x32, 0x88, 0x87, 0x2a,
  28371. 0x34, 0x50, 0x04, 0xad, 0xe6, 0xbb, 0x3c, 0xb5,
  28372. 0xee, 0x80, 0x99, 0x70, 0xaa, 0x9d, 0x5a, 0x63,
  28373. 0xec, 0xd5, 0x9a, 0x6a, 0x3a, 0xe8, 0xaa, 0x3d,
  28374. 0x3f, 0xe8, 0x15, 0x2c, 0x16, 0x3e, 0x86, 0x46,
  28375. 0x21, 0xf2, 0xd2, 0x6e, 0x74, 0x3d, 0x53, 0x94,
  28376. 0x7c, 0x41, 0xec, 0x5b, 0xf5, 0xa4, 0xc8, 0x1f,
  28377. 0x75, 0x22, 0x50, 0x58, 0x31, 0xf5, 0x29, 0x9a,
  28378. 0xc2, 0x2c, 0x67, 0xd9, 0xf6, 0x2e, 0xa1, 0xa9,
  28379. 0x0a, 0x69, 0x90, 0x7a, 0xd8, 0xed, 0x5c, 0x09,
  28380. 0x3d, 0x14, 0xa3, 0x2b, 0xc0, 0x47, 0x88, 0xb7,
  28381. 0xea, 0x14, 0x8a, 0xec, 0xaf, 0x0c, 0xb7, 0xc6,
  28382. 0x7c, 0x32, 0x0f, 0x57, 0xea, 0x9f, 0xd4, 0x99,
  28383. 0x8d, 0xab, 0xd6, 0xc9, 0x31, 0x07, 0x81, 0x37,
  28384. 0x3d, 0xf5, 0x07, 0xb3, 0x93, 0xb7, 0x04, 0x20,
  28385. 0xdf, 0x91, 0xef, 0xfb, 0xa6, 0x7d, 0x4b, 0x5d,
  28386. 0xd4, 0x24, 0xd2, 0x0b, 0xc5, 0x34, 0xf6, 0x7a,
  28387. 0xf9, 0x4a, 0x48, 0xc7, 0xab, 0xaf, 0xa8, 0xd2,
  28388. 0xfc, 0x41, 0xc9, 0x8b, 0xa8, 0xc4, 0x2f, 0x94,
  28389. 0x4e, 0xb0, 0xab, 0xd3, 0xd9, 0x09, 0x4b, 0x1f,
  28390. 0x35, 0xb7, 0xb4, 0x4c, 0x2d, 0x6b, 0xe6, 0xb4,
  28391. 0x2e, 0x8a, 0x09, 0xd3, 0x9d, 0x54, 0x3f, 0x53,
  28392. 0xcc, 0x8e, 0x16, 0x18, 0x4e, 0x9a, 0xe8, 0x52,
  28393. 0x84, 0x3a, 0x3e, 0xdb, 0xab, 0x65, 0xc4, 0xa1,
  28394. 0x3c, 0xd0, 0xf6, 0x57, 0x3c, 0x0e, 0x10, 0xed,
  28395. 0xb2, 0xa9, 0x7d, 0x70, 0x3f, 0x18, 0x1a, 0xba,
  28396. 0x31, 0x33, 0xcb, 0x2a, 0xfd, 0x13, 0xf5, 0x23,
  28397. 0xd7, 0x71, 0xfa, 0xb6, 0xe8, 0xda, 0x63, 0xca,
  28398. 0x55, 0x3c, 0x5b, 0x87, 0x27, 0x96, 0x3d, 0xd0,
  28399. 0x43, 0x9d, 0x76, 0x9f, 0x28, 0x5a, 0xb6, 0xc8,
  28400. 0x81, 0xe4, 0x7c, 0x2a, 0x7a, 0x84, 0x0f, 0x2d,
  28401. 0x1b, 0xd0, 0xe4, 0x0e, 0x1b, 0x47, 0x32, 0xc8,
  28402. 0x02, 0x2d, 0x39, 0x0e, 0x7d, 0xb1, 0x12, 0x56,
  28403. 0x50, 0x00, 0xae, 0xcc, 0x45, 0x0a, 0xd5, 0x30,
  28404. 0x16, 0xe7, 0x3a, 0x53, 0x02, 0xbc, 0xd5, 0xef,
  28405. 0xca, 0x00, 0xea, 0x5f, 0xbe, 0x15, 0x0d, 0x08,
  28406. 0x76, 0xc1, 0x03, 0x93, 0x96, 0x4a, 0x88, 0xda,
  28407. 0x9d, 0x0b, 0x51, 0x39, 0x9a, 0xef, 0xd2, 0xde,
  28408. 0x8a, 0x2c, 0xe6, 0xf3, 0xa5, 0x70, 0x15, 0x3a,
  28409. 0x17, 0x43, 0x31, 0xfc, 0x47, 0x9d, 0xec, 0x3b,
  28410. 0x28, 0x6f, 0xdf, 0x45, 0x6f, 0x9e, 0x10, 0xbb,
  28411. 0x8e, 0x43, 0xc5, 0x59, 0xe5, 0x61, 0x9b, 0xa7,
  28412. 0xa1, 0xb8, 0x7a, 0x1c, 0xd4, 0x25, 0x26, 0xca,
  28413. 0xe9, 0x2b, 0x0b, 0x3d, 0x06, 0xeb, 0x44, 0x44,
  28414. 0xab, 0x4a, 0x5e, 0x68, 0x5c, 0x93, 0xf1, 0x3f,
  28415. 0x39, 0x01, 0xb9, 0xf1, 0x01, 0xb7, 0xb6, 0x14,
  28416. 0x44, 0x1d, 0x6d, 0x6b, 0x03, 0x45, 0x0d, 0xf3,
  28417. 0xbf, 0x71, 0x4e, 0xf3, 0x84, 0x3d, 0xef, 0xea,
  28418. 0x60, 0x2e, 0x2e, 0xf7, 0x33, 0xa6, 0xbe, 0x53,
  28419. 0x49, 0x26, 0xed, 0xb4, 0xbf, 0x7f, 0xb0, 0x1d,
  28420. 0x39, 0xb2, 0xc2, 0x88, 0xc2, 0xa2, 0xd4, 0x7f,
  28421. 0x0e, 0x1c, 0x44, 0xa3, 0x38, 0x76, 0xa7, 0xa6,
  28422. 0x19, 0x7e, 0x4c, 0x84, 0x25, 0x01, 0xb2, 0x78,
  28423. 0xb4, 0x56, 0xc5, 0xc1, 0x50, 0x3f, 0xf2, 0xb6,
  28424. 0x76, 0x09, 0x55, 0x57, 0x1c, 0xd1, 0x55, 0x23,
  28425. 0x16, 0x2a, 0x51, 0x16, 0xaa, 0x13, 0x4f, 0x35,
  28426. 0x69, 0xaf, 0xea, 0x01, 0x5f, 0x22, 0xc9, 0x2e,
  28427. 0xe9, 0x8c, 0x6c, 0xa2, 0x17, 0x92, 0xdc, 0x3d,
  28428. 0xd6, 0xf0, 0xfa, 0x5a, 0x53, 0xe0, 0xcd, 0x55,
  28429. 0xa2, 0x91, 0x62, 0xba, 0xae, 0x67, 0x40, 0x1c,
  28430. 0xda, 0xb4, 0xcc, 0xfc, 0x67, 0x1f, 0x44, 0xa0,
  28431. 0x50, 0xa5, 0xde, 0xc5, 0xde, 0x5e, 0xa0, 0x3b,
  28432. 0x05, 0x84, 0x1c, 0x2a, 0xc4, 0x96, 0x47, 0xd6,
  28433. 0x97, 0x56, 0x40, 0x33, 0x99, 0x7c, 0x8b, 0x56,
  28434. 0xb4, 0xfb, 0xf4, 0x23, 0xcb, 0x48, 0x81, 0x6c,
  28435. 0xa4, 0x53, 0x41, 0x8c, 0x28, 0x61, 0xd7, 0x8c,
  28436. 0xde, 0xde, 0xeb, 0xd4, 0xe7, 0x8a, 0x2a, 0x40,
  28437. 0x83, 0x1c, 0xa4, 0x19, 0x0f, 0x6c, 0x73, 0xa5,
  28438. 0x0e, 0xb6, 0x5c, 0x14, 0x36, 0xff, 0xc9, 0x99,
  28439. 0x56, 0x53, 0x8c, 0x4e, 0x4f, 0x4a, 0x82, 0xc8,
  28440. 0x76, 0x83, 0x81, 0xf1, 0x17, 0x82, 0x98, 0x3e,
  28441. 0x9c, 0x99, 0x3a, 0x7c, 0x08, 0x77, 0x3e, 0xe2,
  28442. 0x10, 0x98, 0xb0, 0xf6, 0x1d, 0xd3, 0x24, 0xe8,
  28443. 0x98, 0xcf, 0xd8, 0x9a, 0xb8, 0xd7, 0xbe, 0x56,
  28444. 0xa2, 0xb6, 0xf8, 0x2e, 0xfe, 0xeb, 0x96, 0xfa,
  28445. 0xd0, 0xba, 0x79, 0x9e, 0xde, 0x72, 0x0d, 0x53,
  28446. 0x5f, 0xdd, 0x0d, 0xb2, 0x0a, 0x8f, 0x14, 0x94,
  28447. 0x87, 0x25, 0x5e, 0xcd, 0xd4, 0x4b, 0xaa, 0xc9,
  28448. 0x7e, 0x41, 0x9f, 0x33, 0x77, 0xbe, 0x6d, 0x57,
  28449. 0x68, 0xef, 0xee, 0x1a, 0xc4, 0x5c, 0x7b, 0xca,
  28450. 0x7e, 0x33, 0x93, 0x3d, 0x88, 0x91, 0xd1, 0x34,
  28451. 0x6a, 0x39, 0x98, 0x92, 0x50, 0x1a, 0x02, 0xcf,
  28452. 0x89, 0x34, 0x33, 0x10, 0x65, 0x23, 0x4d, 0xb7,
  28453. 0x00, 0xcc, 0xc1, 0x60, 0xdd, 0x7d, 0x8e, 0xd1,
  28454. 0x16, 0xa7, 0x71, 0x7b, 0x20, 0xcb, 0xe4, 0xe8,
  28455. 0xcc, 0xfc, 0xb8, 0x5f, 0xe4, 0xe2, 0xd6, 0x8c,
  28456. 0x43, 0x9c, 0x06, 0xf4, 0x8d, 0xbc, 0x56, 0xd0,
  28457. 0x0c, 0xd6, 0x0b, 0x6c, 0x33, 0x0e, 0x08, 0x77,
  28458. 0x66, 0x52, 0x1f, 0x48, 0x0c, 0x50, 0x4a, 0xc2,
  28459. 0x99, 0x0a, 0x15, 0x86, 0xc3, 0x9b, 0x7a, 0x5f,
  28460. 0xfb, 0x58, 0xbd, 0x63, 0x0c, 0xbe, 0x83, 0x40,
  28461. 0x8f, 0xba, 0x39, 0xfb, 0x45, 0xb9, 0xf7, 0x96,
  28462. 0x62, 0xec, 0x7e, 0x77, 0xa4, 0xfb, 0xe1, 0x86,
  28463. 0x5c, 0x0a, 0xae, 0x32, 0xbd, 0x79, 0x76, 0x8b
  28464. };
  28465. static const byte ml_dsa_44_good_sig[] = {
  28466. 0x09, 0xf0, 0xae, 0xbb, 0x25, 0xc7, 0xfc, 0xdd,
  28467. 0x93, 0x25, 0x9c, 0x50, 0xd9, 0x2e, 0x72, 0x5d,
  28468. 0x53, 0xf5, 0x29, 0xd7, 0x4c, 0xc2, 0xd6, 0x81,
  28469. 0x5c, 0xf3, 0x3f, 0x9a, 0x8a, 0xa9, 0x00, 0x21,
  28470. 0x6c, 0xc6, 0xb9, 0x72, 0xb7, 0x0e, 0x00, 0x55,
  28471. 0x9f, 0xd7, 0xae, 0x92, 0xc3, 0xbc, 0x8f, 0x2d,
  28472. 0x4f, 0x54, 0x87, 0x56, 0x52, 0xd3, 0xdd, 0xaf,
  28473. 0xe0, 0xff, 0xda, 0x80, 0x1b, 0xf3, 0x56, 0x90,
  28474. 0xdd, 0x07, 0x86, 0xad, 0xf7, 0xf3, 0x8e, 0xcf,
  28475. 0x3a, 0x57, 0x30, 0x52, 0xaa, 0xd2, 0xb1, 0xf0,
  28476. 0x66, 0xea, 0x67, 0xab, 0x94, 0x1d, 0x96, 0x04,
  28477. 0xaa, 0xcf, 0x0e, 0xb0, 0xbc, 0x7d, 0x8a, 0x4c,
  28478. 0x62, 0x21, 0x82, 0x81, 0x98, 0x63, 0x22, 0x91,
  28479. 0xb9, 0xfe, 0x53, 0x63, 0x8d, 0xdf, 0xe6, 0x19,
  28480. 0xc1, 0x54, 0x3b, 0xf0, 0xf5, 0xe4, 0xc4, 0x36,
  28481. 0x66, 0x2f, 0xcc, 0x4f, 0xed, 0xc6, 0x62, 0x7d,
  28482. 0x8b, 0x7b, 0x89, 0xac, 0x23, 0x0b, 0x40, 0x4e,
  28483. 0x2d, 0xdc, 0xe5, 0xa2, 0xbc, 0x8b, 0xac, 0xe7,
  28484. 0x0b, 0xaa, 0x15, 0xa0, 0x79, 0x4a, 0x97, 0x8a,
  28485. 0xc8, 0xb1, 0x31, 0xea, 0x29, 0x99, 0x14, 0x5d,
  28486. 0x5b, 0x8c, 0xc2, 0xd0, 0xc2, 0x29, 0xd0, 0x85,
  28487. 0xb9, 0x25, 0x16, 0x08, 0xe8, 0x41, 0xa7, 0x77,
  28488. 0x1a, 0xbf, 0x5a, 0x48, 0x5a, 0x7f, 0x97, 0x44,
  28489. 0x62, 0xb4, 0x68, 0x2e, 0x05, 0x48, 0xde, 0x0f,
  28490. 0x69, 0xcc, 0x05, 0x3c, 0xa4, 0x85, 0x20, 0x60,
  28491. 0xfd, 0x45, 0x6a, 0x14, 0xb9, 0x76, 0x8d, 0x48,
  28492. 0xe7, 0x71, 0xd0, 0xd7, 0xbe, 0xe3, 0x36, 0xd6,
  28493. 0x94, 0x5c, 0x22, 0x6e, 0x28, 0xc6, 0x34, 0x93,
  28494. 0xf4, 0x6c, 0xf2, 0x62, 0xbf, 0x8f, 0x6d, 0x07,
  28495. 0xff, 0x38, 0x92, 0x23, 0x19, 0x55, 0xd0, 0x66,
  28496. 0x72, 0x76, 0xc1, 0x43, 0xbc, 0x60, 0x5d, 0xaa,
  28497. 0x61, 0x10, 0xdb, 0x0c, 0x49, 0x7b, 0x99, 0xce,
  28498. 0x14, 0xe3, 0x0b, 0x80, 0xdc, 0x8a, 0x3d, 0xa5,
  28499. 0x3a, 0x0e, 0x29, 0x88, 0x09, 0x1f, 0x9c, 0x03,
  28500. 0x32, 0x13, 0xc2, 0xe1, 0x49, 0x26, 0xc7, 0x11,
  28501. 0xfa, 0x7f, 0x2d, 0x64, 0xfc, 0xf9, 0xaf, 0xd0,
  28502. 0x4d, 0xcf, 0x3a, 0x23, 0x49, 0xde, 0xf2, 0x5d,
  28503. 0xad, 0xf3, 0xde, 0xe0, 0x9a, 0xa2, 0x96, 0x0a,
  28504. 0x9d, 0x97, 0x39, 0x88, 0x60, 0x75, 0xec, 0x29,
  28505. 0x9b, 0x93, 0xfc, 0x80, 0xb3, 0xeb, 0xb0, 0xc6,
  28506. 0xa8, 0xea, 0x75, 0x67, 0xed, 0xbd, 0x42, 0x2a,
  28507. 0xed, 0x22, 0x27, 0xdb, 0x41, 0x3a, 0x94, 0x86,
  28508. 0xd7, 0x4a, 0xf1, 0x8f, 0xa5, 0x47, 0x38, 0xa3,
  28509. 0x3c, 0xe7, 0x17, 0x5d, 0xce, 0xdc, 0x32, 0x7c,
  28510. 0xe4, 0x05, 0x58, 0x98, 0x67, 0xc8, 0xaf, 0x35,
  28511. 0x5d, 0xf9, 0xc0, 0x10, 0x6d, 0x9d, 0xd3, 0x27,
  28512. 0x79, 0x3c, 0x1d, 0xdd, 0xfb, 0x53, 0x3c, 0x03,
  28513. 0x4c, 0xb3, 0x1b, 0x0b, 0x3a, 0x60, 0x80, 0xcd,
  28514. 0x9b, 0x1e, 0x5f, 0x3f, 0x29, 0xfa, 0xb1, 0x09,
  28515. 0x9a, 0x88, 0x58, 0x4a, 0xf5, 0xed, 0xe9, 0x7c,
  28516. 0x9d, 0x70, 0xbe, 0x57, 0xfb, 0x92, 0x12, 0xc9,
  28517. 0x8c, 0x6b, 0x77, 0xe2, 0x44, 0xc6, 0x82, 0x2a,
  28518. 0x29, 0xb3, 0x9c, 0xb0, 0x60, 0xda, 0x3d, 0xcd,
  28519. 0x4e, 0x49, 0x96, 0x8c, 0xd7, 0x2b, 0x29, 0x28,
  28520. 0x7b, 0xec, 0xf1, 0x46, 0x40, 0xf0, 0xe1, 0xd7,
  28521. 0x48, 0x9e, 0xdf, 0xfd, 0xa6, 0xd0, 0xaa, 0x35,
  28522. 0x94, 0x7a, 0x94, 0x57, 0xf3, 0xd4, 0x15, 0x19,
  28523. 0xd3, 0xc5, 0x35, 0x73, 0xc4, 0xf5, 0x86, 0x0d,
  28524. 0x2a, 0x5b, 0x67, 0x0d, 0x8d, 0xaa, 0x18, 0x3e,
  28525. 0xea, 0x9d, 0x80, 0xe7, 0xf8, 0xbb, 0x23, 0xea,
  28526. 0x5d, 0x1c, 0x4d, 0xb2, 0x58, 0x7e, 0xe5, 0xef,
  28527. 0x80, 0xc1, 0x63, 0x44, 0xaf, 0x1d, 0xed, 0xf6,
  28528. 0x92, 0x05, 0x0c, 0xda, 0xcc, 0x58, 0x39, 0x27,
  28529. 0xdd, 0x24, 0xac, 0x63, 0x23, 0x34, 0xaa, 0x2d,
  28530. 0xd0, 0x5b, 0xd7, 0x7f, 0x6d, 0xcb, 0x64, 0xed,
  28531. 0xb3, 0x9b, 0x05, 0x90, 0x79, 0xc2, 0x25, 0x68,
  28532. 0xed, 0xf6, 0xa8, 0x7e, 0x30, 0x4a, 0x46, 0x44,
  28533. 0xad, 0xc8, 0x12, 0x8d, 0x04, 0xc3, 0x11, 0x83,
  28534. 0x7e, 0x77, 0xef, 0x9c, 0xa2, 0xf9, 0x3b, 0x06,
  28535. 0x84, 0x7f, 0x72, 0xd9, 0x2f, 0x22, 0x95, 0xb7,
  28536. 0x7b, 0x4e, 0x35, 0x6a, 0xfa, 0x73, 0x7d, 0x88,
  28537. 0x5b, 0xac, 0x7b, 0xc5, 0x53, 0xc1, 0xfe, 0x6b,
  28538. 0x7c, 0x05, 0xc3, 0xe4, 0xae, 0x48, 0x1a, 0xea,
  28539. 0x6e, 0x51, 0x46, 0x1e, 0x82, 0x80, 0xde, 0x31,
  28540. 0xe1, 0x41, 0x71, 0x88, 0x41, 0xa7, 0xb2, 0xcd,
  28541. 0x3d, 0xf7, 0x5c, 0x4f, 0x4c, 0xfd, 0x3f, 0x6f,
  28542. 0x6c, 0x82, 0xc1, 0xba, 0xe0, 0xf0, 0xb4, 0x8c,
  28543. 0xd5, 0xb5, 0x32, 0xbf, 0x91, 0x49, 0x7e, 0x39,
  28544. 0x5e, 0x0a, 0xdf, 0x4b, 0xd6, 0x07, 0x72, 0xff,
  28545. 0x58, 0x65, 0x1b, 0x1f, 0xc6, 0x56, 0xd2, 0x00,
  28546. 0xec, 0x60, 0xd1, 0x22, 0xc9, 0x1a, 0xa4, 0xcc,
  28547. 0x26, 0xb4, 0xd1, 0x93, 0xbc, 0xfc, 0x52, 0xdf,
  28548. 0xa1, 0x23, 0x37, 0x9b, 0xa2, 0xa8, 0x8f, 0xf3,
  28549. 0x39, 0x03, 0xa5, 0x4c, 0xf0, 0x68, 0xe5, 0x95,
  28550. 0x62, 0xfb, 0xd8, 0x88, 0x39, 0xf6, 0x02, 0x0a,
  28551. 0x4e, 0x7c, 0xf0, 0xbf, 0x71, 0x99, 0x0f, 0x19,
  28552. 0x61, 0xd9, 0x39, 0xe8, 0x3f, 0x59, 0x22, 0x4a,
  28553. 0xaa, 0xdd, 0x03, 0xf8, 0x09, 0xb8, 0xaf, 0xd9,
  28554. 0xb9, 0x9c, 0x3f, 0xf1, 0xfe, 0x49, 0xae, 0x99,
  28555. 0x2f, 0xa2, 0x22, 0x5a, 0x3c, 0xe9, 0xe9, 0xf7,
  28556. 0xba, 0x2d, 0xeb, 0x1f, 0x6c, 0xa7, 0xe1, 0x87,
  28557. 0x2f, 0xa5, 0xff, 0xcf, 0x1c, 0x22, 0x8d, 0xf2,
  28558. 0x5f, 0x63, 0xf5, 0xbb, 0x36, 0x66, 0xcc, 0x62,
  28559. 0x89, 0x8e, 0xf7, 0x78, 0xc5, 0x97, 0x95, 0xde,
  28560. 0xec, 0x43, 0x39, 0x6e, 0x0d, 0xe0, 0x8e, 0xbd,
  28561. 0x2b, 0x3b, 0xe6, 0xff, 0xf5, 0x8f, 0x90, 0xd2,
  28562. 0xd2, 0xce, 0x3b, 0x6f, 0x78, 0xf5, 0xd3, 0x42,
  28563. 0xf3, 0x0f, 0x27, 0x4b, 0x2b, 0xe4, 0xd8, 0x0d,
  28564. 0x31, 0xfa, 0xba, 0xdc, 0x54, 0x21, 0x9a, 0xbf,
  28565. 0x1e, 0x1d, 0x06, 0x8e, 0xd9, 0x58, 0xce, 0x9a,
  28566. 0x71, 0x79, 0x4d, 0xcb, 0xfb, 0x99, 0x4b, 0x66,
  28567. 0xed, 0xef, 0x75, 0x20, 0x4d, 0x47, 0x9b, 0x40,
  28568. 0xd5, 0xcf, 0xd9, 0x00, 0xfe, 0x32, 0x45, 0xae,
  28569. 0x4b, 0x7e, 0x8e, 0x7b, 0xf9, 0xd4, 0xd4, 0x2e,
  28570. 0x1a, 0x2a, 0xac, 0x73, 0xdb, 0x79, 0xb7, 0x02,
  28571. 0x6a, 0x3d, 0xa2, 0xfe, 0x52, 0x27, 0x25, 0x43,
  28572. 0xd1, 0xb5, 0x48, 0x0e, 0xef, 0xf1, 0x0f, 0xe7,
  28573. 0x27, 0xc2, 0x59, 0x4e, 0x47, 0xe2, 0x12, 0xaa,
  28574. 0x1e, 0xae, 0xbc, 0x86, 0x22, 0x70, 0x33, 0xa5,
  28575. 0x50, 0x3f, 0xed, 0x3c, 0x98, 0xbb, 0xd5, 0xb3,
  28576. 0x3e, 0x43, 0x21, 0x8e, 0x3e, 0x8c, 0xcc, 0x0c,
  28577. 0xcf, 0x50, 0xcd, 0xeb, 0x1b, 0x9d, 0x0c, 0xc9,
  28578. 0xe3, 0x2f, 0xbb, 0x4b, 0x43, 0xfc, 0x37, 0x27,
  28579. 0xcb, 0xc9, 0x5a, 0xe9, 0x45, 0x92, 0x9d, 0xe9,
  28580. 0x60, 0x8f, 0x93, 0x1b, 0xd8, 0x6a, 0x68, 0x86,
  28581. 0xc2, 0x1d, 0x49, 0x92, 0x11, 0x29, 0x62, 0x14,
  28582. 0x15, 0x4c, 0xe9, 0x33, 0xe3, 0x70, 0x2d, 0x6b,
  28583. 0x8b, 0xb5, 0x22, 0x44, 0x82, 0xbe, 0x43, 0xe2,
  28584. 0x80, 0xfb, 0xb5, 0xfa, 0x6a, 0x30, 0x04, 0x20,
  28585. 0xb6, 0x58, 0xe1, 0xf4, 0x8c, 0xe6, 0x4c, 0x7c,
  28586. 0x8d, 0x38, 0xf6, 0xdd, 0x59, 0xfc, 0x5a, 0xd7,
  28587. 0x9f, 0x34, 0x92, 0xcc, 0xde, 0x65, 0x89, 0xa7,
  28588. 0xd9, 0x57, 0xf7, 0xf2, 0x71, 0x39, 0xaf, 0xb6,
  28589. 0x88, 0x02, 0x40, 0x24, 0x8b, 0x4f, 0xc5, 0xfc,
  28590. 0xdc, 0x5c, 0xc0, 0x1d, 0xa6, 0x68, 0x87, 0xe0,
  28591. 0x8f, 0xdc, 0xf0, 0xac, 0xd8, 0x5f, 0x1c, 0xb3,
  28592. 0x07, 0xac, 0x58, 0x97, 0x3f, 0x3e, 0x72, 0x19,
  28593. 0x18, 0x64, 0x55, 0x73, 0x11, 0x71, 0xd1, 0xa4,
  28594. 0xa6, 0x57, 0xb0, 0x27, 0xaf, 0xad, 0x8a, 0xf7,
  28595. 0xdf, 0xde, 0x1e, 0xdb, 0x31, 0xc9, 0x32, 0x85,
  28596. 0x90, 0x40, 0x3d, 0xfe, 0x64, 0x5d, 0xe3, 0x94,
  28597. 0x74, 0x98, 0xa7, 0xed, 0x84, 0x44, 0x13, 0x76,
  28598. 0xba, 0xe9, 0x09, 0x9a, 0x17, 0xe0, 0x38, 0x03,
  28599. 0x3b, 0x7a, 0xa7, 0x0e, 0x74, 0xbd, 0x93, 0xb1,
  28600. 0x85, 0x64, 0xc9, 0xc4, 0x22, 0xb9, 0xdf, 0x80,
  28601. 0xac, 0xa1, 0x17, 0xdb, 0x11, 0xdb, 0xfa, 0xeb,
  28602. 0x90, 0x3c, 0x28, 0xfb, 0xa2, 0x36, 0x76, 0x61,
  28603. 0x20, 0x00, 0x88, 0x15, 0xc0, 0x79, 0x9f, 0x7d,
  28604. 0x9f, 0x90, 0xdb, 0x79, 0xbf, 0x1c, 0xdf, 0x86,
  28605. 0xc9, 0x60, 0x8c, 0xea, 0xa6, 0x24, 0x81, 0xd6,
  28606. 0x6d, 0xd8, 0x8d, 0x17, 0x5f, 0x5c, 0x6d, 0x93,
  28607. 0xbc, 0xed, 0xe5, 0x41, 0x05, 0xbe, 0xc6, 0x0f,
  28608. 0x66, 0x50, 0xc3, 0xce, 0x7e, 0x6c, 0x80, 0x88,
  28609. 0xf5, 0x52, 0x61, 0xaf, 0xdb, 0xc0, 0x80, 0xbe,
  28610. 0x78, 0x49, 0x64, 0x39, 0x54, 0x26, 0xeb, 0xab,
  28611. 0x07, 0x4d, 0x38, 0x66, 0x06, 0x98, 0x58, 0xaa,
  28612. 0x40, 0xc4, 0x89, 0xb2, 0x08, 0x85, 0xf3, 0x14,
  28613. 0x58, 0x5d, 0x36, 0xf7, 0xf0, 0x6b, 0x72, 0x79,
  28614. 0x6d, 0xbe, 0x5e, 0x24, 0x68, 0xf1, 0x3c, 0xa2,
  28615. 0x82, 0x22, 0x6e, 0xc4, 0x46, 0x94, 0x8e, 0x00,
  28616. 0xcb, 0xc0, 0x07, 0x69, 0xa5, 0x6d, 0x57, 0x04,
  28617. 0x79, 0xeb, 0x06, 0x7a, 0x42, 0x20, 0x6e, 0xdc,
  28618. 0xb5, 0xa4, 0xdd, 0x74, 0xb3, 0x92, 0x16, 0x71,
  28619. 0x7d, 0x99, 0xfa, 0x26, 0x35, 0x57, 0xe2, 0x83,
  28620. 0xc2, 0xb6, 0xfb, 0x0a, 0xae, 0x22, 0xed, 0xe3,
  28621. 0x98, 0x65, 0x18, 0x32, 0xf8, 0xe5, 0xed, 0xa9,
  28622. 0xf9, 0x7d, 0xb8, 0xea, 0x21, 0x51, 0x6c, 0x70,
  28623. 0x4c, 0xfa, 0xec, 0x6d, 0x4c, 0xf4, 0xcb, 0x1c,
  28624. 0x43, 0xfb, 0xfc, 0xbb, 0xa9, 0xcb, 0xc5, 0x21,
  28625. 0xb3, 0x89, 0xd6, 0x4c, 0xc4, 0x42, 0xd1, 0x55,
  28626. 0x3d, 0x43, 0x74, 0xbf, 0xb7, 0x47, 0xb3, 0x5b,
  28627. 0x14, 0xc3, 0x8f, 0x42, 0x30, 0x57, 0xb0, 0x22,
  28628. 0x56, 0xbe, 0x8d, 0x88, 0x7e, 0x7d, 0x63, 0xc8,
  28629. 0xec, 0x01, 0x41, 0xd5, 0x9d, 0xb6, 0x7a, 0x3b,
  28630. 0xfe, 0x8b, 0x95, 0x94, 0xdb, 0xca, 0xf1, 0xb4,
  28631. 0x56, 0xd7, 0x83, 0xf4, 0x11, 0x05, 0x65, 0xde,
  28632. 0x7a, 0xa3, 0x5a, 0x7a, 0x70, 0xe4, 0xd2, 0xad,
  28633. 0xc0, 0xff, 0x3f, 0x66, 0x2e, 0x1a, 0x65, 0x38,
  28634. 0xda, 0x1f, 0x3f, 0xac, 0x04, 0x2f, 0x0f, 0xde,
  28635. 0x7e, 0x55, 0x05, 0x12, 0xe9, 0xe7, 0x69, 0xf9,
  28636. 0x34, 0x2c, 0x84, 0x97, 0xa8, 0x86, 0x0c, 0x24,
  28637. 0x32, 0x87, 0xfd, 0xbe, 0x67, 0xd1, 0x02, 0x21,
  28638. 0x3b, 0x33, 0xfd, 0x11, 0xb1, 0xca, 0x4f, 0xeb,
  28639. 0x40, 0x38, 0xf6, 0x19, 0x83, 0x9d, 0x73, 0x44,
  28640. 0x37, 0xd6, 0x69, 0x6d, 0x85, 0xda, 0xf7, 0x69,
  28641. 0xfb, 0x88, 0x2b, 0xe7, 0xe7, 0x3c, 0x18, 0xa8,
  28642. 0x13, 0xb7, 0xee, 0x5c, 0x50, 0x5b, 0xa3, 0x09,
  28643. 0x1c, 0xef, 0x8d, 0x37, 0x89, 0x75, 0x0f, 0x8b,
  28644. 0xea, 0x17, 0x02, 0x47, 0x21, 0xcb, 0xa8, 0x73,
  28645. 0x71, 0x23, 0x4c, 0xf7, 0x50, 0xdd, 0x21, 0xe5,
  28646. 0xdb, 0x40, 0x3a, 0x87, 0x40, 0x8d, 0x60, 0x89,
  28647. 0x9e, 0x20, 0x00, 0x58, 0xeb, 0xbb, 0x24, 0x9b,
  28648. 0x0a, 0x17, 0x8f, 0xf6, 0x56, 0x07, 0x11, 0x5b,
  28649. 0xa7, 0xcd, 0x93, 0x0a, 0x31, 0x3d, 0x1f, 0x45,
  28650. 0xa0, 0x08, 0x8f, 0x88, 0x34, 0xa5, 0x01, 0x3b,
  28651. 0xea, 0x07, 0xa3, 0x7b, 0x66, 0x3e, 0x96, 0xe8,
  28652. 0xf7, 0x4d, 0x63, 0x04, 0x55, 0x89, 0xf1, 0x02,
  28653. 0x1e, 0x4a, 0x21, 0xb1, 0x2b, 0x8c, 0x7f, 0x2e,
  28654. 0x0c, 0x64, 0x26, 0x36, 0xd8, 0x63, 0xab, 0xf5,
  28655. 0x22, 0xaf, 0xa9, 0xfa, 0xfa, 0x21, 0x4b, 0x7e,
  28656. 0x6f, 0x8c, 0xce, 0x98, 0xf2, 0x85, 0x3f, 0x2c,
  28657. 0x07, 0x90, 0xc3, 0x2c, 0x06, 0xc5, 0xde, 0xc8,
  28658. 0xc2, 0x7c, 0xd7, 0x9b, 0x64, 0x25, 0x8a, 0x9b,
  28659. 0x77, 0x07, 0xc7, 0x4c, 0xd7, 0x67, 0xff, 0xe6,
  28660. 0xdb, 0x17, 0xf5, 0xc4, 0x2a, 0x14, 0x44, 0x1a,
  28661. 0xff, 0xda, 0xe0, 0xa7, 0x09, 0x1c, 0xe9, 0x03,
  28662. 0xde, 0x4a, 0x59, 0xe4, 0xdf, 0xa3, 0x0d, 0x3a,
  28663. 0x43, 0xdf, 0x80, 0x82, 0x87, 0xfa, 0x75, 0xf5,
  28664. 0xe8, 0xef, 0x6f, 0xd0, 0x89, 0xdd, 0xa1, 0x75,
  28665. 0x17, 0x5b, 0x71, 0x47, 0xe8, 0x8d, 0xae, 0xf6,
  28666. 0x18, 0x7f, 0xb9, 0x24, 0x68, 0x3f, 0x17, 0x6b,
  28667. 0xa8, 0x30, 0x67, 0x7e, 0x02, 0x9b, 0xf6, 0x4d,
  28668. 0x03, 0xa8, 0xfb, 0x33, 0x2f, 0xb4, 0x65, 0x72,
  28669. 0x2a, 0x30, 0xa6, 0x93, 0x94, 0x7a, 0x41, 0x0f,
  28670. 0xd3, 0x67, 0x0b, 0xba, 0xa4, 0x49, 0x7c, 0xcf,
  28671. 0x1f, 0x59, 0x1e, 0x2e, 0x45, 0xd4, 0xa8, 0xb1,
  28672. 0x98, 0x2b, 0xd7, 0x6f, 0x55, 0xb8, 0xf2, 0x65,
  28673. 0x7b, 0x96, 0x18, 0xf7, 0x2e, 0xde, 0x9c, 0x39,
  28674. 0x7a, 0x08, 0x2e, 0xe7, 0x3c, 0x9e, 0x4a, 0xfe,
  28675. 0xba, 0x49, 0xce, 0xba, 0x65, 0x18, 0xae, 0xae,
  28676. 0x9b, 0xd5, 0xf5, 0xeb, 0xd3, 0xdc, 0xd7, 0x2c,
  28677. 0x92, 0x3c, 0xe2, 0x93, 0xb9, 0x69, 0xf2, 0x20,
  28678. 0xea, 0xbd, 0xa9, 0x01, 0x2b, 0x72, 0x7c, 0x93,
  28679. 0x6c, 0x1f, 0x80, 0x3a, 0xd2, 0x2d, 0xf6, 0xc1,
  28680. 0x31, 0x63, 0xd2, 0x2f, 0x6c, 0x1a, 0x54, 0x1f,
  28681. 0x74, 0xe6, 0xa0, 0xac, 0xb1, 0x04, 0x03, 0xb3,
  28682. 0x22, 0x19, 0x48, 0x0a, 0xa7, 0x55, 0x25, 0xc1,
  28683. 0x77, 0x28, 0xb9, 0xbe, 0xef, 0xa8, 0xc6, 0x2b,
  28684. 0xd5, 0x6c, 0x5d, 0x7b, 0x85, 0xcd, 0x10, 0x2d,
  28685. 0x9e, 0xfd, 0xb8, 0xa5, 0x10, 0x65, 0xf7, 0x29,
  28686. 0xa7, 0x41, 0x18, 0xc8, 0xc2, 0x23, 0xe5, 0xcb,
  28687. 0x96, 0x91, 0x8a, 0x7e, 0x45, 0x30, 0x6b, 0x91,
  28688. 0xf1, 0x88, 0xb3, 0x2e, 0x92, 0x96, 0x0a, 0x42,
  28689. 0x4a, 0x16, 0x9d, 0x0c, 0xa8, 0xa7, 0xe5, 0x64,
  28690. 0x38, 0x8a, 0x53, 0x41, 0x28, 0xbf, 0xd7, 0xa4,
  28691. 0x14, 0x05, 0x59, 0x11, 0x2e, 0x0f, 0xc8, 0x5c,
  28692. 0x97, 0x8d, 0xd3, 0x92, 0xbf, 0xb9, 0x05, 0xfa,
  28693. 0xff, 0x38, 0xbf, 0xd6, 0xc5, 0x22, 0xf8, 0xa4,
  28694. 0x75, 0x30, 0x45, 0x93, 0x14, 0xda, 0xc0, 0x7f,
  28695. 0xea, 0x24, 0xe0, 0x33, 0x68, 0xf2, 0x6d, 0xe1,
  28696. 0xb1, 0x0c, 0x7d, 0x40, 0xaa, 0x16, 0x53, 0xa1,
  28697. 0xf6, 0x26, 0xb1, 0x25, 0xe8, 0x83, 0xe9, 0xea,
  28698. 0xea, 0xd2, 0x5a, 0x24, 0xda, 0xe2, 0x6e, 0xd1,
  28699. 0x2a, 0x87, 0x64, 0x48, 0x13, 0x55, 0xb1, 0x2c,
  28700. 0x1a, 0x58, 0x43, 0x5b, 0x63, 0x14, 0x3e, 0x02,
  28701. 0xf0, 0xcf, 0x61, 0x7d, 0x83, 0x81, 0xb9, 0x65,
  28702. 0x4b, 0x72, 0xee, 0xff, 0xfb, 0x6a, 0xbe, 0x71,
  28703. 0x26, 0x56, 0x28, 0x13, 0x9f, 0x31, 0xda, 0x8c,
  28704. 0x2f, 0xdb, 0x21, 0xbe, 0x4b, 0x66, 0xbb, 0xad,
  28705. 0x7a, 0x13, 0x55, 0x92, 0x7c, 0xb5, 0x6e, 0x5f,
  28706. 0x45, 0x1b, 0x64, 0x2d, 0xad, 0x6d, 0x32, 0x07,
  28707. 0xe4, 0x91, 0xdc, 0x0c, 0x1b, 0x5f, 0xcd, 0x86,
  28708. 0xe2, 0x99, 0x2b, 0xb9, 0x7e, 0x60, 0xbd, 0xad,
  28709. 0xa1, 0x5c, 0xab, 0x7f, 0x76, 0xf3, 0x77, 0xba,
  28710. 0x73, 0x7f, 0x6a, 0x88, 0x4e, 0xff, 0x40, 0x72,
  28711. 0x7a, 0x4d, 0x9b, 0x20, 0x2d, 0xc9, 0x2a, 0x30,
  28712. 0x0f, 0x8f, 0x0f, 0xc9, 0x79, 0xc8, 0xc3, 0x8a,
  28713. 0x83, 0x52, 0xff, 0x66, 0x7a, 0x42, 0x04, 0x08,
  28714. 0x6e, 0x5b, 0x13, 0xda, 0xb9, 0xb6, 0x2d, 0x45,
  28715. 0x77, 0x9a, 0xa0, 0x2b, 0xc1, 0x87, 0xc2, 0xa6,
  28716. 0x35, 0x7f, 0x39, 0x34, 0x2e, 0x95, 0x1e, 0x8c,
  28717. 0xbf, 0x89, 0x6d, 0xcf, 0x82, 0xb8, 0x9f, 0x9b,
  28718. 0xd1, 0xbc, 0xa2, 0x55, 0x83, 0xf4, 0xca, 0x21,
  28719. 0x11, 0x8f, 0x28, 0xa9, 0x5e, 0x28, 0x23, 0xb4,
  28720. 0x43, 0x60, 0xb6, 0x11, 0x1a, 0x6f, 0xb4, 0xd1,
  28721. 0x96, 0xc8, 0x79, 0xf2, 0x39, 0x8b, 0x82, 0xae,
  28722. 0xe0, 0xc2, 0xe4, 0xf9, 0xfb, 0xf8, 0x85, 0x64,
  28723. 0x28, 0xad, 0xb5, 0xfd, 0x37, 0xc5, 0x21, 0x38,
  28724. 0x31, 0x94, 0x0d, 0xbe, 0xd8, 0xaf, 0x9b, 0x8a,
  28725. 0x7d, 0xfb, 0x56, 0xd8, 0x23, 0xf7, 0x55, 0x55,
  28726. 0xe7, 0xd9, 0x63, 0x65, 0xfd, 0x64, 0x2e, 0x8a,
  28727. 0x1d, 0x1b, 0xac, 0x4e, 0x2f, 0xef, 0x1b, 0x77,
  28728. 0xca, 0x01, 0xd6, 0xfc, 0xb0, 0x11, 0xda, 0x6b,
  28729. 0xef, 0x9f, 0x76, 0x81, 0x3e, 0x3f, 0x26, 0x4b,
  28730. 0x3b, 0x97, 0xa0, 0x7d, 0xd6, 0xcf, 0x51, 0x0d,
  28731. 0x06, 0xf7, 0xf5, 0x88, 0x64, 0x34, 0x7a, 0xe3,
  28732. 0xb9, 0x16, 0xc3, 0x06, 0x04, 0xf3, 0xe9, 0x55,
  28733. 0xd2, 0xff, 0x49, 0xec, 0x57, 0x84, 0x1f, 0x39,
  28734. 0x28, 0x71, 0x57, 0x87, 0x40, 0xf2, 0x7a, 0x30,
  28735. 0xa0, 0x88, 0xba, 0x6c, 0xb1, 0x09, 0x30, 0x3a,
  28736. 0x11, 0x75, 0xcf, 0xbe, 0x4c, 0xf7, 0xf7, 0xca,
  28737. 0x44, 0x52, 0x91, 0xd0, 0x4c, 0x12, 0x3e, 0x3a,
  28738. 0x4b, 0x31, 0x20, 0xfe, 0x27, 0xd2, 0x08, 0x5b,
  28739. 0x83, 0x7b, 0x82, 0xd3, 0xa3, 0x72, 0xba, 0x2f,
  28740. 0x5f, 0xa3, 0x71, 0xcd, 0x8d, 0x3f, 0x94, 0xce,
  28741. 0x86, 0xa8, 0x6b, 0x43, 0xb7, 0x06, 0x80, 0x70,
  28742. 0x64, 0x06, 0xab, 0x54, 0xce, 0xb5, 0x29, 0xaf,
  28743. 0x73, 0xf7, 0x0f, 0x65, 0x70, 0xa7, 0x84, 0x1a,
  28744. 0x0b, 0xdb, 0x0c, 0xa9, 0x20, 0xea, 0x06, 0x7a,
  28745. 0xba, 0x80, 0xc6, 0xae, 0x3e, 0x0a, 0x7b, 0xd6,
  28746. 0x21, 0x99, 0xe0, 0xae, 0x6e, 0x8f, 0x80, 0xa9,
  28747. 0x97, 0x27, 0x3d, 0x7e, 0xb2, 0xd8, 0x06, 0x10,
  28748. 0x36, 0x07, 0x64, 0x12, 0xd0, 0xc7, 0x91, 0xd2,
  28749. 0x81, 0x74, 0x22, 0x8b, 0x8f, 0xe0, 0x48, 0xc4,
  28750. 0xe1, 0x9b, 0x05, 0xc8, 0xc5, 0xc3, 0x9a, 0x7b,
  28751. 0x9d, 0xee, 0x23, 0xe0, 0x98, 0xc0, 0xd0, 0x05,
  28752. 0x21, 0x89, 0x9a, 0xf4, 0x45, 0xd1, 0x1d, 0x80,
  28753. 0x79, 0xb7, 0xfe, 0x3c, 0xff, 0x84, 0x86, 0xf0,
  28754. 0x2a, 0x69, 0x8b, 0x2d, 0x3b, 0x82, 0xa0, 0xab,
  28755. 0xee, 0xe6, 0xf4, 0x64, 0x84, 0x2b, 0x7a, 0x42,
  28756. 0x12, 0x8d, 0x10, 0xa6, 0xae, 0x10, 0x6d, 0x03,
  28757. 0xb5, 0x72, 0x09, 0xf8, 0x3f, 0xe4, 0x1c, 0x0a,
  28758. 0x08, 0x0d, 0x1a, 0x45, 0x5b, 0x70, 0x7b, 0x95,
  28759. 0xa1, 0xa7, 0xb4, 0xb6, 0xbf, 0xcc, 0xfc, 0x09,
  28760. 0x1a, 0x30, 0x40, 0x44, 0x5e, 0x69, 0x73, 0x7a,
  28761. 0x81, 0xa5, 0xb9, 0xd7, 0xdd, 0xe3, 0xee, 0xfb,
  28762. 0x16, 0x1a, 0x1d, 0x40, 0x41, 0x4e, 0x8d, 0x90,
  28763. 0x92, 0x9d, 0xaf, 0xb0, 0xbb, 0xc2, 0xe0, 0xfc,
  28764. 0x06, 0x0b, 0x20, 0x37, 0x47, 0x50, 0x53, 0x65,
  28765. 0x87, 0x89, 0x99, 0xa4, 0xb7, 0xdb, 0x00, 0x00,
  28766. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  28767. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  28768. 0x0f, 0x20, 0x30, 0x3e
  28769. };
  28770. #endif
  28771. static int test_wc_dilithium(void)
  28772. {
  28773. EXPECT_DECLS;
  28774. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM)
  28775. dilithium_key* key;
  28776. byte level;
  28777. #if !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) || \
  28778. !defined(WOLFSSL_DILITHIUM_NO_SIGN)
  28779. WC_RNG rng;
  28780. #endif
  28781. byte* privKey = NULL;
  28782. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  28783. word32 privKeyLen = DILITHIUM_MAX_KEY_SIZE;
  28784. #endif
  28785. byte* pubKey = NULL;
  28786. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  28787. word32 pubKeyLen = DILITHIUM_MAX_PUB_KEY_SIZE;
  28788. #endif
  28789. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28790. ExpectNotNull(key);
  28791. privKey = (byte*)XMALLOC(DILITHIUM_MAX_KEY_SIZE, NULL,
  28792. DYNAMIC_TYPE_TMP_BUFFER);
  28793. ExpectNotNull(privKey);
  28794. pubKey = (byte*)XMALLOC(DILITHIUM_MAX_PUB_KEY_SIZE, NULL,
  28795. DYNAMIC_TYPE_TMP_BUFFER);
  28796. ExpectNotNull(pubKey);
  28797. if (key != NULL) {
  28798. XMEMSET(key, 0, sizeof(*key));
  28799. }
  28800. #if !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) || \
  28801. !defined(WOLFSSL_DILITHIUM_NO_SIGN)
  28802. XMEMSET(&rng, 0, sizeof(WC_RNG));
  28803. #endif
  28804. #if !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) || \
  28805. !defined(WOLFSSL_DILITHIUM_NO_SIGN)
  28806. ExpectIntEQ(wc_InitRng(&rng), 0);
  28807. #endif
  28808. ExpectIntEQ(wc_dilithium_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28809. ExpectIntEQ(wc_dilithium_init_ex(NULL, NULL, INVALID_DEVID), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28810. wc_dilithium_free(NULL);
  28811. ExpectIntEQ(wc_dilithium_init(key), 0);
  28812. wc_dilithium_free(key);
  28813. ExpectIntEQ(wc_dilithium_init_ex(key, NULL, INVALID_DEVID), 0);
  28814. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  28815. ExpectIntEQ(wc_dilithium_export_public(key, pubKey, &pubKeyLen),
  28816. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28817. #endif
  28818. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  28819. ExpectIntEQ(wc_dilithium_export_private(key, privKey, &privKeyLen),
  28820. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28821. #endif
  28822. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  28823. ExpectIntEQ(wc_dilithium_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28824. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28825. ExpectIntEQ(wc_dilithium_priv_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28826. #endif
  28827. #endif
  28828. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28829. ExpectIntEQ(wc_dilithium_pub_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28830. #endif
  28831. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  28832. ExpectIntEQ(wc_dilithium_sig_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28833. #endif
  28834. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  28835. ExpectIntEQ(wc_dilithium_size(key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28836. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28837. ExpectIntEQ(wc_dilithium_priv_size(key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28838. #endif
  28839. #endif
  28840. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28841. ExpectIntEQ(wc_dilithium_pub_size(key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28842. #endif
  28843. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  28844. ExpectIntEQ(wc_dilithium_sig_size(key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28845. #endif
  28846. ExpectIntEQ(wc_dilithium_set_level(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28847. ExpectIntEQ(wc_dilithium_set_level(key, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28848. ExpectIntEQ(wc_dilithium_set_level(NULL, WC_ML_DSA_44), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28849. ExpectIntEQ(wc_dilithium_set_level(key, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28850. ExpectIntEQ(wc_dilithium_set_level(key, 4), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28851. ExpectIntEQ(wc_dilithium_get_level(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28852. ExpectIntEQ(wc_dilithium_get_level(key, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28853. ExpectIntEQ(wc_dilithium_get_level(NULL, &level), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28854. ExpectIntEQ(wc_dilithium_get_level(key, &level), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28855. #ifndef WOLFSSL_NO_ML_DSA_87
  28856. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  28857. ExpectIntEQ(wc_dilithium_get_level(key, &level), 0);
  28858. ExpectIntEQ(level, WC_ML_DSA_87);
  28859. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  28860. ExpectIntEQ(wc_dilithium_size(key), DILITHIUM_LEVEL5_KEY_SIZE);
  28861. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28862. ExpectIntEQ(wc_dilithium_priv_size(key), DILITHIUM_LEVEL5_PRV_KEY_SIZE);
  28863. #endif
  28864. #endif
  28865. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28866. ExpectIntEQ(wc_dilithium_pub_size(key), DILITHIUM_LEVEL5_PUB_KEY_SIZE);
  28867. #endif
  28868. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  28869. ExpectIntEQ(wc_dilithium_sig_size(key), DILITHIUM_LEVEL5_SIG_SIZE);
  28870. #endif
  28871. #else
  28872. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  28873. #endif
  28874. #ifndef WOLFSSL_NO_ML_DSA_65
  28875. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  28876. ExpectIntEQ(wc_dilithium_get_level(key, &level), 0);
  28877. ExpectIntEQ(level, WC_ML_DSA_65);
  28878. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  28879. ExpectIntEQ(wc_dilithium_size(key), DILITHIUM_LEVEL3_KEY_SIZE);
  28880. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28881. ExpectIntEQ(wc_dilithium_priv_size(key), DILITHIUM_LEVEL3_PRV_KEY_SIZE);
  28882. #endif
  28883. #endif
  28884. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28885. ExpectIntEQ(wc_dilithium_pub_size(key), DILITHIUM_LEVEL3_PUB_KEY_SIZE);
  28886. #endif
  28887. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  28888. ExpectIntEQ(wc_dilithium_sig_size(key), DILITHIUM_LEVEL3_SIG_SIZE);
  28889. #endif
  28890. #else
  28891. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  28892. #endif
  28893. #ifndef WOLFSSL_NO_ML_DSA_44
  28894. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  28895. ExpectIntEQ(wc_dilithium_get_level(key, &level), 0);
  28896. ExpectIntEQ(level, WC_ML_DSA_44);
  28897. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  28898. ExpectIntEQ(wc_dilithium_size(key), DILITHIUM_LEVEL2_KEY_SIZE);
  28899. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28900. ExpectIntEQ(wc_dilithium_priv_size(key), DILITHIUM_LEVEL2_PRV_KEY_SIZE);
  28901. #endif
  28902. #endif
  28903. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28904. ExpectIntEQ(wc_dilithium_pub_size(key), DILITHIUM_LEVEL2_PUB_KEY_SIZE);
  28905. #endif
  28906. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  28907. ExpectIntEQ(wc_dilithium_sig_size(key), DILITHIUM_LEVEL2_SIG_SIZE);
  28908. #endif
  28909. #else
  28910. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  28911. #endif
  28912. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  28913. ExpectIntEQ(wc_dilithium_export_public(key, pubKey, &pubKeyLen),
  28914. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28915. #endif
  28916. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  28917. ExpectIntEQ(wc_dilithium_export_private(key, privKey, &privKeyLen),
  28918. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28919. #endif
  28920. wc_dilithium_free(key);
  28921. #if !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) || \
  28922. !defined(WOLFSSL_DILITHIUM_NO_SIGN)
  28923. wc_FreeRng(&rng);
  28924. #endif
  28925. XFREE(pubKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28926. XFREE(privKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28927. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28928. #endif
  28929. return EXPECT_RESULT();
  28930. }
  28931. static int test_wc_dilithium_make_key(void)
  28932. {
  28933. EXPECT_DECLS;
  28934. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  28935. !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY)
  28936. dilithium_key* key;
  28937. WC_RNG rng;
  28938. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28939. ExpectNotNull(key);
  28940. if (key != NULL) {
  28941. XMEMSET(key, 0, sizeof(*key));
  28942. }
  28943. XMEMSET(&rng, 0, sizeof(WC_RNG));
  28944. ExpectIntEQ(wc_InitRng(&rng), 0);
  28945. ExpectIntEQ(wc_dilithium_init(key), 0);
  28946. ExpectIntEQ(wc_dilithium_make_key(key, &rng), WC_NO_ERR_TRACE(BAD_STATE_E));
  28947. #ifndef WOLFSSL_NO_ML_DSA_44
  28948. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  28949. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  28950. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  28951. #else
  28952. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  28953. #endif
  28954. ExpectIntEQ(wc_dilithium_make_key(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28955. ExpectIntEQ(wc_dilithium_make_key(key, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28956. ExpectIntEQ(wc_dilithium_make_key(NULL, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28957. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  28958. wc_dilithium_free(key);
  28959. wc_FreeRng(&rng);
  28960. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28961. #endif
  28962. return EXPECT_RESULT();
  28963. }
  28964. static int test_wc_dilithium_sign(void)
  28965. {
  28966. EXPECT_DECLS;
  28967. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  28968. !defined(WOLFSSL_DILITHIUM_NO_SIGN)
  28969. dilithium_key* key;
  28970. dilithium_key* importKey = NULL;
  28971. WC_RNG rng;
  28972. byte* privKey = NULL;
  28973. word32 privKeyLen = DILITHIUM_MAX_KEY_SIZE;
  28974. word32 badKeyLen;
  28975. byte msg[32];
  28976. byte* sig = NULL;
  28977. word32 sigLen = DILITHIUM_MAX_SIG_SIZE;
  28978. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28979. ExpectNotNull(key);
  28980. importKey = (dilithium_key*)XMALLOC(sizeof(*key), NULL,
  28981. DYNAMIC_TYPE_TMP_BUFFER);
  28982. ExpectNotNull(importKey);
  28983. privKey = (byte*)XMALLOC(DILITHIUM_MAX_KEY_SIZE, NULL,
  28984. DYNAMIC_TYPE_TMP_BUFFER);
  28985. ExpectNotNull(privKey);
  28986. sig = (byte*)XMALLOC(DILITHIUM_MAX_SIG_SIZE, NULL,
  28987. DYNAMIC_TYPE_TMP_BUFFER);
  28988. ExpectNotNull(sig);
  28989. if (key != NULL) {
  28990. XMEMSET(key, 0, sizeof(*key));
  28991. }
  28992. if (importKey != NULL) {
  28993. XMEMSET(importKey, 0, sizeof(*importKey));
  28994. }
  28995. XMEMSET(&rng, 0, sizeof(WC_RNG));
  28996. XMEMSET(msg, 0x55, sizeof(msg));
  28997. ExpectIntEQ(wc_InitRng(&rng), 0);
  28998. ExpectIntEQ(wc_dilithium_init(key), 0);
  28999. #ifndef WOLFSSL_NO_ML_DSA_44
  29000. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  29001. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29002. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  29003. #else
  29004. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  29005. #endif
  29006. #ifdef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  29007. #ifndef WOLFSSL_NO_ML_DSA_44
  29008. ExpectIntEQ(wc_dilithium_import_private(bench_dilithium_level2_key,
  29009. sizeof_bench_dilithium_level2_key, key), 0);
  29010. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29011. ExpectIntEQ(wc_dilithium_import_private(bench_dilithium_level3_key,
  29012. sizeof_bench_dilithium_level3_key, key), 0);
  29013. #else
  29014. ExpectIntEQ(wc_dilithium_import_private(bench_dilithium_level5_key,
  29015. sizeof_bench_dilithium_level5_key, key), 0);
  29016. #endif
  29017. #else
  29018. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  29019. #endif
  29020. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, NULL, NULL, NULL, NULL),
  29021. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29022. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, NULL, NULL, NULL, NULL),
  29023. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29024. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, sig, NULL, NULL, NULL),
  29025. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29026. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, NULL, &sigLen, NULL, NULL),
  29027. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29028. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, NULL, NULL, key, NULL),
  29029. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29030. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, NULL, NULL, NULL, &rng),
  29031. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29032. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, sig, &sigLen, key, &rng),
  29033. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29034. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, NULL, &sigLen, key, &rng),
  29035. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29036. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, NULL, key, &rng),
  29037. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29038. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, &sigLen, NULL, &rng),
  29039. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29040. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, &sigLen, key, NULL),
  29041. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29042. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, &sigLen, key, &rng), 0);
  29043. ExpectIntEQ(wc_dilithium_export_private(NULL, NULL, NULL),
  29044. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29045. ExpectIntEQ(wc_dilithium_export_private(key, NULL, NULL),
  29046. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29047. ExpectIntEQ(wc_dilithium_export_private(NULL, privKey, NULL),
  29048. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29049. ExpectIntEQ(wc_dilithium_export_private(NULL, NULL, &privKeyLen),
  29050. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29051. ExpectIntEQ(wc_dilithium_export_private(NULL, privKey, &privKeyLen),
  29052. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29053. ExpectIntEQ(wc_dilithium_export_private(key, NULL, &privKeyLen),
  29054. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29055. ExpectIntEQ(wc_dilithium_export_private(key, privKey, NULL),
  29056. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29057. badKeyLen = 0;
  29058. ExpectIntEQ(wc_dilithium_export_private(key, privKey, &badKeyLen),
  29059. WC_NO_ERR_TRACE(BUFFER_E));
  29060. #ifndef WOLFSSL_NO_ML_DSA_44
  29061. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL2_KEY_SIZE);
  29062. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29063. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL3_KEY_SIZE);
  29064. #else
  29065. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL5_KEY_SIZE);
  29066. #endif
  29067. ExpectIntEQ(wc_dilithium_export_private(key, privKey, &privKeyLen),
  29068. 0);
  29069. #ifndef WOLFSSL_NO_ML_DSA_44
  29070. ExpectIntEQ(privKeyLen, DILITHIUM_LEVEL2_KEY_SIZE);
  29071. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29072. ExpectIntEQ(privKeyLen, DILITHIUM_LEVEL3_KEY_SIZE);
  29073. #else
  29074. ExpectIntEQ(privKeyLen, DILITHIUM_LEVEL5_KEY_SIZE);
  29075. #endif
  29076. ExpectIntEQ(wc_dilithium_init(importKey), 0);
  29077. ExpectIntEQ(wc_dilithium_import_private(privKey, privKeyLen, importKey),
  29078. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29079. #ifndef WOLFSSL_NO_ML_DSA_44
  29080. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_44), 0);
  29081. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29082. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_65), 0);
  29083. #else
  29084. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_87), 0);
  29085. #endif
  29086. ExpectIntEQ(wc_dilithium_import_private(NULL, 0, NULL),
  29087. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29088. ExpectIntEQ(wc_dilithium_import_private(privKey, 0, NULL),
  29089. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29090. ExpectIntEQ(wc_dilithium_import_private(NULL, privKeyLen, NULL),
  29091. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29092. ExpectIntEQ(wc_dilithium_import_private(NULL, 0, importKey),
  29093. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29094. ExpectIntEQ(wc_dilithium_import_private(NULL, privKeyLen, importKey),
  29095. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29096. ExpectIntEQ(wc_dilithium_import_private(privKey, 0, importKey),
  29097. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29098. ExpectIntEQ(wc_dilithium_import_private(privKey, privKeyLen, NULL),
  29099. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29100. ExpectIntEQ(wc_dilithium_import_private(privKey, privKeyLen, importKey),
  29101. 0);
  29102. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, &sigLen, key, &rng), 0);
  29103. #ifdef WOLFSSL_DILITHIUM_CHECK_KEY
  29104. ExpectIntEQ(wc_dilithium_check_key(importKey), WC_NO_ERR_TRACE(PUBLIC_KEY_E));
  29105. #endif
  29106. wc_dilithium_free(importKey);
  29107. wc_dilithium_free(key);
  29108. wc_FreeRng(&rng);
  29109. XFREE(sig, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29110. XFREE(privKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29111. XFREE(importKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29112. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29113. #endif
  29114. return EXPECT_RESULT();
  29115. }
  29116. static int test_wc_dilithium_verify(void)
  29117. {
  29118. EXPECT_DECLS;
  29119. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  29120. !defined(WOLFSSL_DILITHIUM_NO_VERIFY) && \
  29121. (!defined(WOLFSSL_NO_ML_DSA_44) || !defined(WOLFSSL_DILITHIUM_NO_SIGN))
  29122. dilithium_key* key;
  29123. dilithium_key* importKey = NULL;
  29124. WC_RNG rng;
  29125. byte* pubKey = NULL;
  29126. word32 pubKeyLen = DILITHIUM_MAX_PUB_KEY_SIZE;
  29127. word32 badKeyLen;
  29128. byte msg[32];
  29129. byte* sig = NULL;
  29130. word32 sigLen = DILITHIUM_MAX_SIG_SIZE;
  29131. int res;
  29132. #ifndef WOLFSSL_NO_ML_DSA_44
  29133. byte b;
  29134. #endif
  29135. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29136. ExpectNotNull(key);
  29137. importKey = (dilithium_key*)XMALLOC(sizeof(*key), NULL,
  29138. DYNAMIC_TYPE_TMP_BUFFER);
  29139. ExpectNotNull(importKey);
  29140. pubKey = (byte*)XMALLOC(DILITHIUM_MAX_PUB_KEY_SIZE, NULL,
  29141. DYNAMIC_TYPE_TMP_BUFFER);
  29142. ExpectNotNull(pubKey);
  29143. sig = (byte*)XMALLOC(DILITHIUM_MAX_SIG_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29144. ExpectNotNull(sig);
  29145. if (key != NULL) {
  29146. XMEMSET(key, 0, sizeof(*key));
  29147. }
  29148. if (importKey != NULL) {
  29149. XMEMSET(importKey, 0, sizeof(*importKey));
  29150. }
  29151. XMEMSET(&rng, 0, sizeof(WC_RNG));
  29152. XMEMSET(msg, 0x55, sizeof(msg));
  29153. ExpectIntEQ(wc_InitRng(&rng), 0);
  29154. ExpectIntEQ(wc_dilithium_init(key), 0);
  29155. #ifndef WOLFSSL_NO_ML_DSA_44
  29156. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  29157. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29158. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  29159. #else
  29160. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  29161. #endif
  29162. #if !defined(WOLFSSL_NO_ML_DSA_44)
  29163. ExpectIntEQ(wc_dilithium_import_public(ml_dsa_44_pub_key,
  29164. (word32)sizeof(ml_dsa_44_pub_key), key), 0);
  29165. if (sig != NULL) {
  29166. XMEMCPY(sig, ml_dsa_44_good_sig, sizeof(ml_dsa_44_good_sig));
  29167. }
  29168. sigLen = (word32)sizeof(ml_dsa_44_good_sig);
  29169. #else
  29170. #ifdef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  29171. #ifndef WOLFSSL_NO_ML_DSA_65
  29172. ExpectIntEQ(wc_dilithium_import_public(bench_dilithium_level3_pub_key,
  29173. sizeof_bench_dilithium_level3_pub_key, key), 0);
  29174. #else
  29175. ExpectIntEQ(wc_dilithium_import_public(bench_dilithium_level5_pub_key,
  29176. sizeof_bench_dilithium_level5_pub_key, key), 0);
  29177. #endif /* !WOLFSSL_NO_ML_DSA_65 */
  29178. #else
  29179. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  29180. #endif /* WOLFSSL_DILITHIUM_NO_MAKE_KEY */
  29181. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, &sigLen, key, &rng), 0);
  29182. #endif /* !WOLFSSL_NO_ML_DSA_44 */
  29183. ExpectIntEQ(wc_dilithium_export_public(NULL, NULL, NULL),
  29184. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29185. ExpectIntEQ(wc_dilithium_export_public(key, NULL, NULL),
  29186. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29187. ExpectIntEQ(wc_dilithium_export_public(NULL, pubKey, NULL),
  29188. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29189. ExpectIntEQ(wc_dilithium_export_public(NULL, NULL, &pubKeyLen),
  29190. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29191. ExpectIntEQ(wc_dilithium_export_public(NULL, pubKey, &pubKeyLen),
  29192. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29193. ExpectIntEQ(wc_dilithium_export_public(key, NULL, &pubKeyLen),
  29194. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29195. ExpectIntEQ(wc_dilithium_export_public(key, pubKey, NULL),
  29196. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29197. badKeyLen = 0;
  29198. ExpectIntEQ(wc_dilithium_export_public(key, pubKey, &badKeyLen),
  29199. WC_NO_ERR_TRACE(BUFFER_E));
  29200. #ifndef WOLFSSL_NO_ML_DSA_44
  29201. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL2_PUB_KEY_SIZE);
  29202. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29203. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL3_PUB_KEY_SIZE);
  29204. #else
  29205. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL5_PUB_KEY_SIZE);
  29206. #endif
  29207. ExpectIntEQ(wc_dilithium_export_public(key, pubKey, &pubKeyLen), 0);
  29208. #ifndef WOLFSSL_NO_ML_DSA_44
  29209. ExpectIntEQ(pubKeyLen, DILITHIUM_LEVEL2_PUB_KEY_SIZE);
  29210. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29211. ExpectIntEQ(pubKeyLen, DILITHIUM_LEVEL3_PUB_KEY_SIZE);
  29212. #else
  29213. ExpectIntEQ(pubKeyLen, DILITHIUM_LEVEL5_PUB_KEY_SIZE);
  29214. #endif
  29215. ExpectIntEQ(wc_dilithium_verify_msg(NULL, 0, NULL, 32, NULL, NULL),
  29216. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29217. ExpectIntEQ(wc_dilithium_verify_msg(sig, 0, NULL, 32, NULL, NULL),
  29218. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29219. ExpectIntEQ(wc_dilithium_verify_msg(NULL, 0, msg, 32, NULL, NULL),
  29220. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29221. ExpectIntEQ(wc_dilithium_verify_msg(NULL, 0, NULL, 32, &res, NULL),
  29222. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29223. ExpectIntEQ(wc_dilithium_verify_msg(NULL, 0, NULL, 32, NULL, key),
  29224. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29225. ExpectIntEQ(wc_dilithium_verify_msg(NULL, sigLen, msg, 32, &res, key),
  29226. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29227. ExpectIntEQ(wc_dilithium_verify_msg(sig, 0, msg, 32, &res, key),
  29228. WC_NO_ERR_TRACE(BUFFER_E));
  29229. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, NULL, 32, &res, key),
  29230. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29231. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, NULL, key),
  29232. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29233. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, NULL),
  29234. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29235. res = 0;
  29236. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, key), 0);
  29237. ExpectIntEQ(res, 1);
  29238. ExpectIntEQ(wc_dilithium_init(importKey), 0);
  29239. ExpectIntEQ(wc_dilithium_import_public(pubKey, pubKeyLen, importKey),
  29240. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29241. #ifndef WOLFSSL_NO_ML_DSA_44
  29242. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_44), 0);
  29243. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29244. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_65), 0);
  29245. #else
  29246. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_87), 0);
  29247. #endif
  29248. ExpectIntEQ(wc_dilithium_import_public(NULL, 0, NULL),
  29249. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29250. ExpectIntEQ(wc_dilithium_import_public(pubKey, 0, NULL),
  29251. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29252. ExpectIntEQ(wc_dilithium_import_public(NULL, pubKeyLen, NULL),
  29253. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29254. ExpectIntEQ(wc_dilithium_import_public(NULL, 0, importKey),
  29255. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29256. ExpectIntEQ(wc_dilithium_import_public(NULL, pubKeyLen, importKey),
  29257. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29258. ExpectIntEQ(wc_dilithium_import_public(pubKey, 0, importKey),
  29259. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29260. ExpectIntEQ(wc_dilithium_import_public(pubKey, pubKeyLen, NULL),
  29261. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29262. ExpectIntEQ(wc_dilithium_import_public(pubKey, pubKeyLen, importKey), 0);
  29263. res = 0;
  29264. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, importKey),
  29265. 0);
  29266. ExpectIntEQ(res, 1);
  29267. #ifdef WOLFSSL_DILITHIUM_CHECK_KEY
  29268. ExpectIntEQ(wc_dilithium_check_key(importKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29269. #endif
  29270. wc_dilithium_free(importKey);
  29271. #ifndef WOLFSSL_NO_ML_DSA_44
  29272. if (sig != NULL) {
  29273. if (sig[sigLen - 5] == 0) {
  29274. /* Unused hints meant to be 0. */
  29275. sig[sigLen - 5] = 0xff;
  29276. res = 1;
  29277. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res,
  29278. key), WC_NO_ERR_TRACE(SIG_VERIFY_E));
  29279. ExpectIntEQ(res, 0);
  29280. sig[sigLen - 5] = 0x00;
  29281. }
  29282. /* Last count of hints must be less than PARAMS_ML_DSA_44_OMEGA == 80 */
  29283. b = sig[sigLen - 1];
  29284. sig[sigLen - 1] = 0xff;
  29285. res = 1;
  29286. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, key),
  29287. WC_NO_ERR_TRACE(SIG_VERIFY_E));
  29288. ExpectIntEQ(res, 0);
  29289. sig[sigLen - 1] = b;
  29290. if (sig[sigLen - 4] > 1) {
  29291. /* Index must be less than previous. */
  29292. b = sig[sigLen - 84];
  29293. sig[sigLen - 84] = 0xff;
  29294. res = 1;
  29295. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res,
  29296. key), WC_NO_ERR_TRACE(SIG_VERIFY_E));
  29297. ExpectIntEQ(res, 0);
  29298. sig[sigLen - 84] = b;
  29299. }
  29300. /* Mess up commit hash. */
  29301. sig[0] ^= 0x80;
  29302. res = 1;
  29303. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, key),
  29304. 0);
  29305. ExpectIntEQ(res, 0);
  29306. sig[0] ^= 0x80;
  29307. /* Mess up z. */
  29308. sig[100] ^= 0x80;
  29309. res = 1;
  29310. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, key),
  29311. 0);
  29312. ExpectIntEQ(res, 0);
  29313. sig[100] ^= 0x80;
  29314. /* Set all indeces to 0. */
  29315. XMEMSET(sig + sigLen - 4, 0, 4);
  29316. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, key),
  29317. WC_NO_ERR_TRACE(SIG_VERIFY_E));
  29318. ExpectIntEQ(res, 0);
  29319. }
  29320. #endif
  29321. wc_dilithium_free(key);
  29322. wc_FreeRng(&rng);
  29323. XFREE(sig, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29324. XFREE(pubKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29325. XFREE(importKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29326. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29327. #endif
  29328. return EXPECT_RESULT();
  29329. }
  29330. static int test_wc_dilithium_sign_vfy(void)
  29331. {
  29332. EXPECT_DECLS;
  29333. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  29334. !defined(WOLFSSL_DILITHIUM_FIPS204_DRAFT) && \
  29335. !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) && \
  29336. !defined(WOLFSSL_DILITHIUM_NO_SIGN) && !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  29337. dilithium_key* key;
  29338. WC_RNG rng;
  29339. byte msg[64];
  29340. byte* sig = NULL;
  29341. word32 sigLen;
  29342. byte ctx[10];
  29343. int res;
  29344. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29345. ExpectNotNull(key);
  29346. sig = (byte*)XMALLOC(DILITHIUM_MAX_SIG_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29347. ExpectNotNull(sig);
  29348. if (key != NULL) {
  29349. XMEMSET(key, 0, sizeof(*key));
  29350. }
  29351. XMEMSET(&rng, 0, sizeof(WC_RNG));
  29352. XMEMSET(msg, 0xAA, sizeof(msg));
  29353. XMEMSET(ctx, 0x01, sizeof(ctx));
  29354. ExpectIntEQ(wc_InitRng(&rng), 0);
  29355. #ifndef WOLFSSL_NO_ML_DSA_44
  29356. ExpectIntEQ(wc_dilithium_init(key), 0);
  29357. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  29358. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  29359. sigLen = DILITHIUM_MAX_SIG_SIZE;
  29360. ExpectIntEQ(wc_dilithium_sign_ctx_msg(ctx, sizeof(ctx), msg, sizeof(msg),
  29361. sig, &sigLen, key, &rng), 0);
  29362. ExpectIntEQ(wc_dilithium_verify_ctx_msg(sig, sigLen, ctx, sizeof(ctx), msg,
  29363. sizeof(msg), &res, key), 0);
  29364. ExpectIntEQ(res, 1);
  29365. sigLen = DILITHIUM_MAX_SIG_SIZE;
  29366. ExpectIntEQ(wc_dilithium_sign_ctx_hash(ctx, sizeof(ctx),
  29367. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), sig, &sigLen, key, &rng), 0);
  29368. ExpectIntEQ(wc_dilithium_verify_ctx_hash(sig, sigLen, ctx, sizeof(ctx),
  29369. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), &res, key), 0);
  29370. ExpectIntEQ(res, 1);
  29371. wc_dilithium_free(key);
  29372. #endif
  29373. #ifndef WOLFSSL_NO_ML_DSA_65
  29374. ExpectIntEQ(wc_dilithium_init(key), 0);
  29375. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  29376. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  29377. sigLen = DILITHIUM_MAX_SIG_SIZE;
  29378. ExpectIntEQ(wc_dilithium_sign_ctx_msg(ctx, sizeof(ctx), msg, sizeof(msg),
  29379. sig, &sigLen, key, &rng), 0);
  29380. ExpectIntEQ(wc_dilithium_verify_ctx_msg(sig, sigLen, ctx, sizeof(ctx), msg,
  29381. sizeof(msg), &res, key), 0);
  29382. ExpectIntEQ(res, 1);
  29383. sigLen = DILITHIUM_MAX_SIG_SIZE;
  29384. ExpectIntEQ(wc_dilithium_sign_ctx_hash(ctx, sizeof(ctx),
  29385. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), sig, &sigLen, key, &rng), 0);
  29386. ExpectIntEQ(wc_dilithium_verify_ctx_hash(sig, sigLen, ctx, sizeof(ctx),
  29387. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), &res, key), 0);
  29388. ExpectIntEQ(res, 1);
  29389. wc_dilithium_free(key);
  29390. #endif
  29391. #ifndef WOLFSSL_NO_ML_DSA_87
  29392. ExpectIntEQ(wc_dilithium_init(key), 0);
  29393. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  29394. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  29395. sigLen = DILITHIUM_MAX_SIG_SIZE;
  29396. ExpectIntEQ(wc_dilithium_sign_ctx_msg(ctx, sizeof(ctx), msg, sizeof(msg),
  29397. sig, &sigLen, key, &rng), 0);
  29398. ExpectIntEQ(wc_dilithium_verify_ctx_msg(sig, sigLen, ctx, sizeof(ctx), msg,
  29399. sizeof(msg), &res, key), 0);
  29400. ExpectIntEQ(res, 1);
  29401. sigLen = DILITHIUM_MAX_SIG_SIZE;
  29402. ExpectIntEQ(wc_dilithium_sign_ctx_hash(ctx, sizeof(ctx),
  29403. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), sig, &sigLen, key, &rng), 0);
  29404. ExpectIntEQ(wc_dilithium_verify_ctx_hash(sig, sigLen, ctx, sizeof(ctx),
  29405. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), &res, key), 0);
  29406. ExpectIntEQ(res, 1);
  29407. wc_dilithium_free(key);
  29408. #endif
  29409. wc_FreeRng(&rng);
  29410. XFREE(sig, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29411. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29412. #endif
  29413. return EXPECT_RESULT();
  29414. }
  29415. static int test_wc_dilithium_check_key(void)
  29416. {
  29417. EXPECT_DECLS;
  29418. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  29419. defined(WOLFSSL_DILITHIUM_CHECK_KEY) && \
  29420. !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY)
  29421. dilithium_key* checkKey;
  29422. WC_RNG rng;
  29423. byte* privCheckKey = NULL;
  29424. word32 privCheckKeyLen = DILITHIUM_MAX_KEY_SIZE;
  29425. byte* pubCheckKey = NULL;
  29426. word32 pubCheckKeyLen = DILITHIUM_MAX_PUB_KEY_SIZE;
  29427. checkKey = (dilithium_key*)XMALLOC(sizeof(*checkKey), NULL,
  29428. DYNAMIC_TYPE_TMP_BUFFER);
  29429. ExpectNotNull(checkKey);
  29430. privCheckKey = (byte*)XMALLOC(DILITHIUM_MAX_KEY_SIZE, NULL,
  29431. DYNAMIC_TYPE_TMP_BUFFER);
  29432. ExpectNotNull(privCheckKey);
  29433. pubCheckKey = (byte*)XMALLOC(DILITHIUM_MAX_PUB_KEY_SIZE, NULL,
  29434. DYNAMIC_TYPE_TMP_BUFFER);
  29435. ExpectNotNull(pubCheckKey);
  29436. if (checkKey != NULL) {
  29437. XMEMSET(checkKey, 0, sizeof(*checkKey));
  29438. }
  29439. XMEMSET(&rng, 0, sizeof(WC_RNG));
  29440. ExpectIntEQ(wc_InitRng(&rng), 0);
  29441. ExpectIntEQ(wc_dilithium_check_key(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29442. ExpectIntEQ(wc_dilithium_init(checkKey), 0);
  29443. ExpectIntEQ(wc_dilithium_export_key(NULL, privCheckKey,
  29444. &privCheckKeyLen, pubCheckKey, &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29445. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29446. privCheckKeyLen, pubCheckKey, pubCheckKeyLen, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29447. ExpectIntEQ(wc_dilithium_export_key(checkKey, privCheckKey,
  29448. &privCheckKeyLen, pubCheckKey, &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29449. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29450. privCheckKeyLen, pubCheckKey, pubCheckKeyLen, checkKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29451. #ifndef WOLFSSL_NO_ML_DSA_44
  29452. ExpectIntEQ(wc_dilithium_set_level(checkKey, WC_ML_DSA_44), 0);
  29453. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29454. ExpectIntEQ(wc_dilithium_set_level(checkKey, WC_ML_DSA_65), 0);
  29455. #else
  29456. ExpectIntEQ(wc_dilithium_set_level(checkKey, WC_ML_DSA_87), 0);
  29457. #endif
  29458. ExpectIntEQ(wc_dilithium_make_key(checkKey, &rng), 0);
  29459. ExpectIntEQ(wc_dilithium_export_key(NULL, NULL, NULL, NULL, NULL),
  29460. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29461. ExpectIntEQ(wc_dilithium_export_key(checkKey, NULL, NULL, NULL, NULL),
  29462. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29463. ExpectIntEQ(wc_dilithium_export_key(NULL, privCheckKey, NULL, NULL, NULL),
  29464. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29465. ExpectIntEQ(wc_dilithium_export_key(NULL, NULL, &privCheckKeyLen, NULL,
  29466. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29467. ExpectIntEQ(wc_dilithium_export_key(NULL, NULL, NULL, pubCheckKey, NULL),
  29468. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29469. ExpectIntEQ(wc_dilithium_export_key(NULL, NULL, NULL, NULL,
  29470. &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29471. ExpectIntEQ(wc_dilithium_export_key(NULL , privCheckKey,
  29472. &privCheckKeyLen, pubCheckKey, &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29473. ExpectIntEQ(wc_dilithium_export_key(checkKey, NULL ,
  29474. &privCheckKeyLen, pubCheckKey, &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29475. ExpectIntEQ(wc_dilithium_export_key(checkKey, privCheckKey,
  29476. NULL , pubCheckKey, &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29477. ExpectIntEQ(wc_dilithium_export_key(checkKey, privCheckKey,
  29478. &privCheckKeyLen, NULL , &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29479. ExpectIntEQ(wc_dilithium_export_key(checkKey, privCheckKey,
  29480. &privCheckKeyLen, pubCheckKey, NULL ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29481. ExpectIntEQ(wc_dilithium_export_key(checkKey, privCheckKey,
  29482. &privCheckKeyLen, pubCheckKey, &pubCheckKeyLen), 0);
  29483. /* Modify hash. */
  29484. if (pubCheckKey != NULL) {
  29485. pubCheckKey[0] ^= 0x80;
  29486. ExpectIntEQ(wc_dilithium_import_key(NULL, 0, NULL, 0, NULL),
  29487. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29488. ExpectIntEQ(wc_dilithium_import_key(privCheckKey, 0, NULL, 0, NULL),
  29489. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29490. ExpectIntEQ(wc_dilithium_import_key(NULL, 0, pubCheckKey, 0, NULL),
  29491. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29492. ExpectIntEQ(wc_dilithium_import_key(NULL, 0, NULL, 0, checkKey),
  29493. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29494. ExpectIntEQ(wc_dilithium_import_key(NULL ,
  29495. privCheckKeyLen, pubCheckKey, pubCheckKeyLen, checkKey),
  29496. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29497. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29498. 0 , pubCheckKey, pubCheckKeyLen, checkKey),
  29499. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29500. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29501. privCheckKeyLen, NULL , pubCheckKeyLen, checkKey),
  29502. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29503. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29504. privCheckKeyLen, pubCheckKey, 0 , checkKey),
  29505. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29506. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29507. privCheckKeyLen, pubCheckKey, pubCheckKeyLen, NULL ),
  29508. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29509. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29510. privCheckKeyLen, pubCheckKey, pubCheckKeyLen, checkKey), 0);
  29511. ExpectIntEQ(wc_dilithium_check_key(checkKey), WC_NO_ERR_TRACE(PUBLIC_KEY_E));
  29512. pubCheckKey[0] ^= 0x80;
  29513. /* Modify encoded t1. */
  29514. pubCheckKey[48] ^= 0x80;
  29515. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29516. privCheckKeyLen,pubCheckKey, pubCheckKeyLen, checkKey), 0);
  29517. ExpectIntEQ(wc_dilithium_check_key(checkKey), WC_NO_ERR_TRACE(PUBLIC_KEY_E));
  29518. pubCheckKey[48] ^= 0x80;
  29519. }
  29520. wc_dilithium_free(checkKey);
  29521. wc_FreeRng(&rng);
  29522. XFREE(pubCheckKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29523. XFREE(privCheckKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29524. XFREE(checkKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29525. #endif
  29526. return EXPECT_RESULT();
  29527. }
  29528. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  29529. defined(WOLFSSL_DILITHIUM_PUBLIC_KEY)
  29530. static const unsigned char dilithium_public_der[] = {
  29531. #ifndef WOLFSSL_NO_ML_DSA_44
  29532. 0x30, 0x82, 0x05, 0x34, 0x30, 0x0d, 0x06, 0x0b,
  29533. 0x2b, 0x06, 0x01, 0x04, 0x01, 0x02, 0x82, 0x0b,
  29534. 0x0c, 0x04, 0x04, 0x03, 0x82, 0x05, 0x21, 0x00,
  29535. 0x0a, 0xf7, 0xc8, 0xa4, 0x96, 0x01, 0xa7, 0xb2,
  29536. 0x2e, 0x4d, 0xc9, 0xd9, 0x1c, 0xa1, 0x86, 0x09,
  29537. 0xce, 0x14, 0x6f, 0xe8, 0x33, 0x3c, 0x7b, 0xdb,
  29538. 0x19, 0x9c, 0x56, 0x39, 0x6a, 0x6c, 0x5d, 0x1f,
  29539. 0xe4, 0x26, 0xcb, 0x16, 0x91, 0x4d, 0xeb, 0x5a,
  29540. 0x36, 0x22, 0xee, 0xda, 0xdf, 0x46, 0x3e, 0xa1,
  29541. 0x4f, 0x9a, 0x30, 0xb5, 0x3f, 0x60, 0xf7, 0x75,
  29542. 0x47, 0xdc, 0x55, 0xf1, 0xbe, 0xbc, 0x87, 0x6c,
  29543. 0x50, 0x7c, 0x21, 0x55, 0x35, 0xad, 0xa7, 0xf9,
  29544. 0x1c, 0xf8, 0xa1, 0x92, 0x79, 0x10, 0x52, 0x7a,
  29545. 0xc3, 0xba, 0xd3, 0x9d, 0xc6, 0x9b, 0xf4, 0xcb,
  29546. 0x1b, 0xa2, 0xde, 0x83, 0x86, 0xa6, 0x35, 0xea,
  29547. 0xf2, 0x8c, 0xdc, 0xba, 0x3e, 0xef, 0x9c, 0xf5,
  29548. 0x8e, 0xc3, 0xb0, 0xc0, 0x5b, 0xcc, 0x35, 0x6a,
  29549. 0x81, 0xe5, 0x17, 0xb3, 0x9a, 0x57, 0xa6, 0x4a,
  29550. 0x87, 0xb1, 0xa7, 0xf5, 0xa2, 0x96, 0x40, 0x8b,
  29551. 0xc1, 0x62, 0xb2, 0xd9, 0x76, 0xe8, 0x51, 0x33,
  29552. 0x44, 0x3d, 0xeb, 0x14, 0x86, 0x88, 0x2c, 0xc1,
  29553. 0x47, 0xba, 0x2b, 0x85, 0x3b, 0x72, 0xcb, 0x9f,
  29554. 0x40, 0xba, 0x19, 0x58, 0xa4, 0x34, 0x0a, 0xd2,
  29555. 0x8c, 0x97, 0xbd, 0x3d, 0x09, 0xb0, 0x4a, 0xeb,
  29556. 0xaa, 0xee, 0x58, 0x1e, 0xc1, 0x19, 0x26, 0x70,
  29557. 0x15, 0xa5, 0x17, 0x7e, 0xd0, 0xa1, 0x08, 0xf9,
  29558. 0x6d, 0xcf, 0x20, 0x62, 0x95, 0x8e, 0x61, 0xf4,
  29559. 0x29, 0x96, 0x6f, 0x38, 0x1c, 0x67, 0xd5, 0xa6,
  29560. 0x4c, 0xf5, 0x1f, 0xda, 0x12, 0x22, 0x24, 0x6b,
  29561. 0x0d, 0xb7, 0x6a, 0xe5, 0xaf, 0x6c, 0x89, 0x52,
  29562. 0xc2, 0x85, 0x85, 0x5f, 0x16, 0x33, 0x0c, 0xc6,
  29563. 0x7a, 0xe0, 0xa8, 0xed, 0x13, 0x58, 0xf3, 0xa0,
  29564. 0x80, 0x42, 0x3c, 0xe3, 0x57, 0xd1, 0xe2, 0x66,
  29565. 0xc4, 0xe0, 0x3d, 0x49, 0x32, 0x21, 0xd9, 0xa1,
  29566. 0x3c, 0x93, 0x0a, 0xf7, 0x5f, 0x34, 0x65, 0xa4,
  29567. 0x30, 0xf9, 0xe7, 0x8a, 0x96, 0x04, 0xdb, 0xc5,
  29568. 0x16, 0x15, 0x10, 0x74, 0x4f, 0xc9, 0x6b, 0x4b,
  29569. 0x66, 0x29, 0xb0, 0xd1, 0x3b, 0xdd, 0x41, 0x0a,
  29570. 0xfe, 0xdf, 0x5f, 0x72, 0x91, 0xbc, 0x99, 0x2f,
  29571. 0x8d, 0x72, 0x3a, 0x4a, 0xde, 0x11, 0x3a, 0x20,
  29572. 0xb2, 0x56, 0xb5, 0x73, 0x89, 0xb4, 0x63, 0x37,
  29573. 0x86, 0xbd, 0x99, 0x8b, 0x03, 0x56, 0x50, 0x21,
  29574. 0x11, 0x78, 0x8c, 0xd5, 0xc1, 0x92, 0x33, 0x72,
  29575. 0x6e, 0x8d, 0x88, 0x2d, 0x10, 0x8f, 0x31, 0xd3,
  29576. 0x23, 0xe5, 0xaa, 0x1f, 0xe1, 0x37, 0xec, 0x34,
  29577. 0x42, 0x30, 0x75, 0xff, 0xb2, 0x1a, 0x8e, 0x29,
  29578. 0x03, 0x4c, 0xfd, 0xdf, 0x53, 0xf2, 0x0b, 0x2d,
  29579. 0xf9, 0x1c, 0x9e, 0xb6, 0x5a, 0x6c, 0x5e, 0x88,
  29580. 0x48, 0x29, 0x89, 0x42, 0xfc, 0x97, 0xfb, 0x27,
  29581. 0x1c, 0x99, 0x2a, 0xbf, 0x7f, 0x04, 0xb2, 0xcd,
  29582. 0xc9, 0x3a, 0x39, 0xfe, 0x4f, 0x47, 0x92, 0x0b,
  29583. 0x85, 0xfc, 0x92, 0x57, 0xc5, 0x0b, 0x23, 0x1f,
  29584. 0x0b, 0x72, 0xb4, 0xde, 0xfe, 0xbe, 0xb7, 0x39,
  29585. 0xb3, 0xd7, 0x48, 0x03, 0xed, 0x76, 0xac, 0x63,
  29586. 0xf7, 0x2a, 0x58, 0xef, 0xdb, 0x63, 0x5a, 0x56,
  29587. 0x68, 0xcc, 0xb2, 0x8b, 0x22, 0xac, 0xdf, 0xc4,
  29588. 0xad, 0x6f, 0xad, 0x24, 0xfd, 0x30, 0xfb, 0xed,
  29589. 0x6e, 0xde, 0x65, 0x2b, 0xb4, 0x57, 0x35, 0x49,
  29590. 0xc1, 0xc9, 0x82, 0xf4, 0x72, 0x69, 0xef, 0x34,
  29591. 0xc0, 0x37, 0x8b, 0x8b, 0xd3, 0xd3, 0x25, 0xcc,
  29592. 0xe5, 0xf5, 0xf6, 0x9c, 0xa3, 0xe7, 0x88, 0xd7,
  29593. 0x55, 0x73, 0x31, 0x4c, 0xb1, 0x7b, 0x64, 0xb3,
  29594. 0x38, 0xde, 0x47, 0x9a, 0xfc, 0xf1, 0xfa, 0xf8,
  29595. 0x6e, 0xc5, 0x95, 0xb9, 0xaf, 0x6a, 0x7a, 0x94,
  29596. 0x80, 0x0d, 0x29, 0x62, 0x99, 0x0a, 0x34, 0xa2,
  29597. 0x8f, 0xa1, 0x5e, 0x98, 0x7c, 0x4e, 0x18, 0xcd,
  29598. 0x63, 0x68, 0x0e, 0xfa, 0x6f, 0x49, 0x01, 0x02,
  29599. 0xcd, 0xf1, 0xc1, 0x09, 0x57, 0xa3, 0x03, 0xec,
  29600. 0x94, 0x36, 0xab, 0xc6, 0x1c, 0xc0, 0x98, 0x22,
  29601. 0x15, 0x5b, 0x5b, 0x61, 0x3c, 0xc2, 0x5b, 0x6f,
  29602. 0x1c, 0x82, 0x41, 0x39, 0x87, 0xde, 0x92, 0xa9,
  29603. 0xe4, 0x12, 0x74, 0x3b, 0x31, 0x36, 0xac, 0x92,
  29604. 0xb0, 0x23, 0x26, 0xfa, 0xd8, 0xa3, 0xe8, 0x84,
  29605. 0xfc, 0x52, 0xc5, 0x7b, 0xd1, 0x4b, 0xe2, 0x1a,
  29606. 0x33, 0xdd, 0x3c, 0xdf, 0x27, 0x50, 0x6f, 0x12,
  29607. 0xd3, 0x17, 0x66, 0xd7, 0x54, 0x33, 0x30, 0x2b,
  29608. 0xe8, 0xd1, 0x1f, 0x2d, 0xf3, 0x37, 0x81, 0xa0,
  29609. 0x3c, 0x21, 0x8c, 0xea, 0x95, 0xa5, 0x5b, 0x3a,
  29610. 0x24, 0xed, 0xf7, 0x67, 0x7b, 0x72, 0x3a, 0xda,
  29611. 0x31, 0xbd, 0xa7, 0x63, 0xa6, 0x6f, 0xf9, 0xdf,
  29612. 0x06, 0x36, 0xb4, 0xe2, 0x35, 0x4b, 0xa5, 0x8e,
  29613. 0x29, 0x8e, 0x6c, 0x02, 0xc5, 0x06, 0x9b, 0x98,
  29614. 0x6e, 0x5e, 0x00, 0x6a, 0x42, 0x09, 0x4b, 0xc3,
  29615. 0x09, 0x37, 0x67, 0x19, 0x58, 0x6d, 0x40, 0x50,
  29616. 0xb0, 0x62, 0x5b, 0xd6, 0x63, 0x7f, 0xed, 0xb0,
  29617. 0x97, 0x80, 0x9e, 0x91, 0x3f, 0x82, 0xfd, 0x83,
  29618. 0x36, 0xce, 0x06, 0xc4, 0xdc, 0xa4, 0x1e, 0x70,
  29619. 0xd4, 0x94, 0xfc, 0x6e, 0x46, 0xa3, 0xc8, 0xed,
  29620. 0x34, 0x0a, 0xb1, 0x9a, 0x66, 0x5d, 0xc0, 0xce,
  29621. 0x73, 0xd3, 0x65, 0xcb, 0xfb, 0x79, 0xdd, 0xf6,
  29622. 0x19, 0xf6, 0xd8, 0xa9, 0xe6, 0x34, 0x15, 0x86,
  29623. 0x7a, 0x30, 0x79, 0xde, 0x2b, 0x06, 0xa4, 0xc0,
  29624. 0xc8, 0xa2, 0xc1, 0x41, 0xb3, 0x4c, 0xf6, 0xdb,
  29625. 0x16, 0xcd, 0xd2, 0x8b, 0xf1, 0x18, 0x5a, 0xc8,
  29626. 0x3e, 0xd9, 0x54, 0x40, 0xd4, 0xce, 0x88, 0xbb,
  29627. 0x66, 0xf1, 0x74, 0x20, 0xa2, 0x3c, 0x31, 0x09,
  29628. 0xba, 0xac, 0x61, 0x15, 0x9f, 0x73, 0x5f, 0xa7,
  29629. 0xe5, 0x0d, 0xb3, 0xab, 0xa2, 0x72, 0x25, 0xc9,
  29630. 0x87, 0x9b, 0x18, 0xdb, 0xff, 0xfb, 0x39, 0x84,
  29631. 0x8d, 0xf8, 0x97, 0x47, 0xab, 0xc4, 0xfb, 0xc2,
  29632. 0xd8, 0xe8, 0xce, 0x6e, 0x65, 0x76, 0x88, 0x4a,
  29633. 0x22, 0x2f, 0xdd, 0x43, 0xa7, 0xc4, 0x8d, 0x32,
  29634. 0x12, 0x75, 0x0b, 0x72, 0xd6, 0xb7, 0x43, 0x84,
  29635. 0xc8, 0x59, 0xa8, 0xb7, 0x8b, 0x84, 0x33, 0x92,
  29636. 0x8f, 0x94, 0xe8, 0xd0, 0xaf, 0x11, 0x35, 0xde,
  29637. 0xb7, 0x63, 0xb8, 0x91, 0x4c, 0x96, 0x4e, 0x9c,
  29638. 0x62, 0x28, 0xa2, 0xbc, 0x0b, 0x90, 0xae, 0x94,
  29639. 0x90, 0xe9, 0x32, 0xeb, 0xe3, 0x77, 0x60, 0x5f,
  29640. 0x87, 0x48, 0x4b, 0xb0, 0x78, 0x0e, 0xe2, 0x85,
  29641. 0x47, 0x06, 0xa4, 0xc9, 0x26, 0xac, 0x8f, 0xe7,
  29642. 0xc2, 0xc7, 0xce, 0xf5, 0xd1, 0x20, 0xa8, 0x56,
  29643. 0xe1, 0x4f, 0x50, 0x90, 0xb3, 0xc1, 0x03, 0x57,
  29644. 0xd3, 0x62, 0x0e, 0x2a, 0xe8, 0x86, 0xf4, 0x94,
  29645. 0x0e, 0xa5, 0x8b, 0x4e, 0x73, 0xa2, 0x76, 0xac,
  29646. 0x00, 0x29, 0xe5, 0x80, 0x26, 0x02, 0x13, 0xd1,
  29647. 0xb2, 0x68, 0x72, 0x23, 0x38, 0x55, 0xfc, 0x4d,
  29648. 0x05, 0x60, 0x49, 0x7b, 0xfb, 0xaa, 0x17, 0x8f,
  29649. 0x26, 0x0a, 0x08, 0x33, 0x8d, 0x7f, 0x4e, 0xe5,
  29650. 0x6e, 0xf8, 0x84, 0x9b, 0x9f, 0xcb, 0xa2, 0x2b,
  29651. 0xfb, 0xaf, 0xad, 0x21, 0xe2, 0x4f, 0x6f, 0x55,
  29652. 0xc1, 0x78, 0x46, 0xe3, 0xb5, 0x63, 0x06, 0x9b,
  29653. 0x93, 0x7d, 0xac, 0xd4, 0xe0, 0x64, 0x01, 0x8d,
  29654. 0xac, 0x30, 0x8b, 0x8b, 0x55, 0xb7, 0x8a, 0x16,
  29655. 0x3f, 0xc9, 0x82, 0x7f, 0xb5, 0x3b, 0x0d, 0xc0,
  29656. 0x46, 0x89, 0x5c, 0x6c, 0x45, 0x21, 0x78, 0xda,
  29657. 0x84, 0x1f, 0xc8, 0xcf, 0xf1, 0x1e, 0x79, 0x71,
  29658. 0x3b, 0xc8, 0xe2, 0x8b, 0x41, 0xfe, 0xaf, 0x2f,
  29659. 0x3b, 0x23, 0x13, 0xc5, 0x46, 0x87, 0xc6, 0x24,
  29660. 0x37, 0x21, 0x68, 0x8a, 0x3e, 0x45, 0x61, 0xf4,
  29661. 0xad, 0xf5, 0x1c, 0x23, 0x45, 0xa3, 0x42, 0xf2,
  29662. 0xa9, 0xac, 0x94, 0x50, 0xc9, 0x3d, 0x5e, 0x70,
  29663. 0x33, 0x2b, 0x78, 0xd1, 0x5c, 0x13, 0x35, 0xe6,
  29664. 0x13, 0x80, 0x5e, 0x55, 0xa7, 0xcc, 0x67, 0xb0,
  29665. 0x6c, 0xfe, 0xa2, 0x24, 0x02, 0x6d, 0xb3, 0xcb,
  29666. 0x9e, 0x94, 0xb3, 0xc6, 0x01, 0xf3, 0x01, 0x3a,
  29667. 0xe4, 0xa7, 0xa3, 0xdf, 0x56, 0x4c, 0x30, 0xce,
  29668. 0xb1, 0xd5, 0x1b, 0x68, 0x9b, 0x75, 0xae, 0xf4,
  29669. 0xb9, 0x2a, 0xe5, 0x8b, 0x7b, 0xe5, 0x99, 0x46,
  29670. 0x5f, 0x29, 0xf6, 0x82, 0xd0, 0x42, 0xb1, 0x45,
  29671. 0x09, 0x16, 0x5b, 0x32, 0x11, 0xca, 0x48, 0xea,
  29672. 0x51, 0x12, 0x0a, 0x9f, 0x6e, 0x3f, 0x74, 0xe6,
  29673. 0xe0, 0xfe, 0xf8, 0xa5, 0xc0, 0xfd, 0x15, 0x6e,
  29674. 0x2b, 0x4a, 0xd5, 0x76, 0xa8, 0x3d, 0xe3, 0x0d,
  29675. 0xfe, 0x44, 0x11, 0x5e, 0x7a, 0xde, 0x12, 0x29,
  29676. 0x5a, 0x5a, 0x25, 0xc0, 0x8e, 0x98, 0xd1, 0x11,
  29677. 0xc8, 0x00, 0x65, 0xb2, 0xf4, 0xd7, 0x56, 0x32,
  29678. 0x46, 0x2b, 0x4f, 0x7e, 0xc3, 0x4e, 0xf1, 0x17,
  29679. 0xff, 0x03, 0x32, 0xae, 0xe3, 0xbe, 0x0b, 0xab,
  29680. 0xfb, 0x43, 0x0f, 0x6d, 0xa5, 0xc6, 0x44, 0xba,
  29681. 0xc9, 0xe3, 0x3d, 0x40, 0xe7, 0x6c, 0xe8, 0x21,
  29682. 0xb2, 0x46, 0x7b, 0x3b, 0x3d, 0xde, 0x80, 0xc8,
  29683. 0xea, 0xf4, 0x6b, 0xf3, 0x53, 0xca, 0x51, 0x84,
  29684. 0xcf, 0xad, 0x7e, 0xce, 0xce, 0xc2, 0x65, 0xfc,
  29685. 0x03, 0x8c, 0xcb, 0xfa, 0xcb, 0x37, 0x89, 0x82,
  29686. 0x59, 0x5e, 0x36, 0x52, 0xe4, 0xbc, 0x8d, 0x47,
  29687. 0x7c, 0xb8, 0x3f, 0x63, 0x59, 0xdc, 0xd3, 0x74,
  29688. 0x11, 0x33, 0xb4, 0x69, 0x74, 0x40, 0x0d, 0x42,
  29689. 0x63, 0x1d, 0xe6, 0x5c, 0x1b, 0xca, 0x41, 0xff,
  29690. 0x23, 0x4e, 0xe8, 0x3d, 0x14, 0xa8, 0x17, 0x18,
  29691. 0xd0, 0x78, 0x08, 0x87, 0x7d, 0x5e, 0xdc, 0x3a,
  29692. 0x07, 0xba, 0x12, 0x8e, 0x8e, 0x56, 0x0a, 0xcb,
  29693. 0x37, 0xf6, 0x54, 0xeb, 0x55, 0x16, 0x8f, 0x06,
  29694. 0x15, 0x28, 0x6b, 0xfb, 0xed, 0x38, 0x9e, 0x9b,
  29695. 0x98, 0x5b, 0xdc, 0x67, 0x33, 0x0e, 0x02, 0x36,
  29696. 0x1b, 0x7a, 0x9a, 0x43, 0xcd, 0xf2, 0x65, 0xef,
  29697. 0x37, 0x19, 0x24, 0x6f, 0x4b, 0xb9, 0x4d, 0x3e,
  29698. 0x0b, 0x47, 0xd1, 0x67, 0x50, 0x6a, 0x7f, 0x07
  29699. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29700. 0x30, 0x82, 0x07, 0xb4, 0x30, 0x0d, 0x06, 0x0b,
  29701. 0x2b, 0x06, 0x01, 0x04, 0x01, 0x02, 0x82, 0x0b,
  29702. 0x0c, 0x06, 0x05, 0x03, 0x82, 0x07, 0xa1, 0x00,
  29703. 0xff, 0x89, 0xee, 0xad, 0x20, 0x8f, 0x61, 0xa4,
  29704. 0x07, 0x1c, 0x54, 0x98, 0x8c, 0xf4, 0x2e, 0xd9,
  29705. 0xe6, 0x0f, 0xcb, 0x0e, 0xab, 0xa1, 0x37, 0x4d,
  29706. 0xc0, 0x48, 0x24, 0x78, 0xd6, 0x2d, 0x9b, 0x6f,
  29707. 0x0f, 0x17, 0x08, 0x71, 0xc3, 0xd1, 0xc8, 0x7a,
  29708. 0xe7, 0x32, 0xcb, 0xcd, 0xd6, 0xb5, 0x90, 0x08,
  29709. 0xe1, 0xda, 0xaa, 0x89, 0x3e, 0x4a, 0x62, 0x98,
  29710. 0x3d, 0xc6, 0x71, 0x30, 0xb4, 0x63, 0xa5, 0x3b,
  29711. 0xb3, 0x69, 0x75, 0x10, 0xaf, 0x5e, 0x72, 0x78,
  29712. 0xa2, 0xef, 0x63, 0x63, 0x21, 0xe7, 0xf4, 0xa7,
  29713. 0x9c, 0x50, 0x74, 0x14, 0x3e, 0xdd, 0x73, 0x9e,
  29714. 0x97, 0x65, 0xdd, 0xdf, 0x3c, 0x40, 0x4d, 0x03,
  29715. 0x49, 0xe4, 0xbf, 0x65, 0xe7, 0x44, 0x8f, 0x59,
  29716. 0x00, 0xe2, 0x98, 0xb5, 0x66, 0xa3, 0x3b, 0x11,
  29717. 0x9f, 0xc7, 0xc2, 0x16, 0x61, 0xf0, 0x1e, 0x89,
  29718. 0xc8, 0x96, 0x8d, 0x18, 0xac, 0x86, 0xa0, 0xe2,
  29719. 0xd9, 0x8c, 0xef, 0x53, 0x6d, 0x4e, 0x74, 0xc9,
  29720. 0x66, 0x28, 0x16, 0xf3, 0x62, 0xc4, 0x6f, 0x2b,
  29721. 0x6e, 0x36, 0x03, 0xad, 0xc5, 0xe4, 0x8f, 0x0b,
  29722. 0x90, 0x8c, 0x8f, 0xff, 0x5d, 0xdf, 0x7a, 0xe6,
  29723. 0xaf, 0x9a, 0x43, 0xbc, 0xd4, 0x73, 0x22, 0xdc,
  29724. 0x5f, 0x08, 0xa1, 0x17, 0x97, 0x89, 0x79, 0xf5,
  29725. 0xdc, 0xed, 0x4f, 0x85, 0x8e, 0x0c, 0x23, 0x35,
  29726. 0x3c, 0x34, 0x19, 0x65, 0xf5, 0xd6, 0xc9, 0x2d,
  29727. 0x7a, 0x2e, 0x67, 0xd5, 0xf1, 0x82, 0x97, 0xaa,
  29728. 0x05, 0x26, 0x84, 0x25, 0x47, 0x58, 0x2c, 0xe6,
  29729. 0x59, 0xc7, 0x98, 0x7a, 0xdb, 0x40, 0x45, 0x1c,
  29730. 0x71, 0x55, 0x2e, 0xea, 0x3f, 0x6e, 0x7c, 0x82,
  29731. 0x52, 0x6a, 0x19, 0x3a, 0xd3, 0xa1, 0x3c, 0xce,
  29732. 0x00, 0x06, 0xec, 0xed, 0x97, 0xce, 0xd8, 0xdf,
  29733. 0xde, 0xa3, 0xed, 0xe7, 0x81, 0x62, 0x02, 0x9c,
  29734. 0x1b, 0x51, 0xa1, 0xf4, 0x9d, 0x1b, 0x28, 0x76,
  29735. 0x93, 0x96, 0x20, 0x55, 0x60, 0x1f, 0xaf, 0x52,
  29736. 0xc3, 0xce, 0xb9, 0x12, 0x66, 0xf5, 0x64, 0x22,
  29737. 0x87, 0x86, 0x29, 0x80, 0x8f, 0x18, 0x33, 0xba,
  29738. 0x48, 0x71, 0x1d, 0x00, 0xfe, 0xa5, 0xfc, 0xc6,
  29739. 0x87, 0xbe, 0x44, 0x3c, 0xc9, 0x49, 0xfb, 0x68,
  29740. 0x3c, 0xdf, 0xca, 0xef, 0xa7, 0xdc, 0x67, 0xb8,
  29741. 0x28, 0xd6, 0xad, 0x18, 0xaf, 0xad, 0x1f, 0x4c,
  29742. 0x85, 0xa3, 0x64, 0xac, 0x3f, 0xa9, 0x39, 0x28,
  29743. 0xef, 0x8a, 0x45, 0x7e, 0xb0, 0xf4, 0x89, 0x72,
  29744. 0xf7, 0xb1, 0xef, 0x9d, 0x1c, 0x3c, 0x93, 0xcb,
  29745. 0xa0, 0xfb, 0x2a, 0x90, 0xe2, 0x1d, 0x49, 0x8e,
  29746. 0x36, 0xb8, 0x07, 0xf4, 0xb3, 0x09, 0xf0, 0x6f,
  29747. 0x3c, 0xd9, 0x37, 0x19, 0x57, 0xd4, 0x1e, 0x2a,
  29748. 0xa2, 0xa7, 0x2e, 0xc1, 0xcd, 0x8d, 0x48, 0x47,
  29749. 0xb5, 0x8a, 0x12, 0x93, 0x34, 0xb8, 0xec, 0x32,
  29750. 0x07, 0x49, 0xb6, 0x8d, 0x73, 0xd4, 0x2c, 0x6a,
  29751. 0xa0, 0x33, 0x29, 0x21, 0x5d, 0x37, 0xa9, 0x39,
  29752. 0x40, 0xbe, 0x71, 0x29, 0xbe, 0xd1, 0x4b, 0xbc,
  29753. 0x9a, 0x17, 0x93, 0x52, 0xb8, 0x81, 0xee, 0xc5,
  29754. 0xff, 0x25, 0x78, 0x2f, 0x52, 0x0a, 0x8f, 0xb2,
  29755. 0xef, 0xf3, 0x1d, 0x68, 0x56, 0x31, 0x29, 0x84,
  29756. 0x55, 0x47, 0x32, 0x34, 0x0f, 0x60, 0x07, 0xd6,
  29757. 0x2b, 0xb9, 0x29, 0xaf, 0x0f, 0xcd, 0x1c, 0xc0,
  29758. 0x77, 0x4c, 0xc6, 0x31, 0xdb, 0xf4, 0x17, 0xbe,
  29759. 0x3d, 0xf8, 0x8c, 0xf1, 0x02, 0x7c, 0x6b, 0xd4,
  29760. 0xaf, 0x03, 0xb2, 0xf4, 0x78, 0x8d, 0xd3, 0x4e,
  29761. 0x5c, 0x04, 0xb9, 0x01, 0xe3, 0x73, 0xb4, 0x67,
  29762. 0xe9, 0xa8, 0x77, 0x6f, 0x87, 0x2b, 0xe2, 0x00,
  29763. 0x98, 0x5f, 0x02, 0x43, 0x85, 0x03, 0x4c, 0x71,
  29764. 0xd2, 0xe7, 0x61, 0x03, 0x22, 0x9e, 0xe5, 0xc2,
  29765. 0xa7, 0x66, 0x42, 0x7c, 0x9f, 0xf4, 0xb8, 0x6b,
  29766. 0x2d, 0xe4, 0xaa, 0x51, 0xda, 0x08, 0x73, 0x75,
  29767. 0x26, 0x45, 0xdc, 0xa6, 0x20, 0xd7, 0xcb, 0x00,
  29768. 0xfc, 0xe4, 0xdb, 0x28, 0x92, 0xf8, 0xb0, 0xc7,
  29769. 0xf0, 0x4b, 0x6d, 0xe8, 0xc1, 0x84, 0x38, 0xed,
  29770. 0x1a, 0xd4, 0x66, 0x69, 0xc4, 0x96, 0x40, 0xc4,
  29771. 0x7d, 0xfa, 0x58, 0x70, 0x7e, 0x70, 0x40, 0xba,
  29772. 0xfc, 0x95, 0xb6, 0x4c, 0x7c, 0x58, 0xbc, 0xb3,
  29773. 0x59, 0x08, 0x14, 0x03, 0x35, 0xf3, 0xf1, 0xaa,
  29774. 0xd5, 0xa2, 0x57, 0x70, 0xb6, 0x20, 0x75, 0x0a,
  29775. 0x58, 0x66, 0x74, 0xf7, 0x1c, 0xfd, 0x99, 0x7c,
  29776. 0x20, 0xda, 0xe7, 0x76, 0xcb, 0xf4, 0xa3, 0x9b,
  29777. 0xbc, 0x8f, 0x74, 0xef, 0xe2, 0x46, 0x5a, 0x72,
  29778. 0x33, 0x06, 0x32, 0x1e, 0xbd, 0x4e, 0x4c, 0xf6,
  29779. 0x16, 0x43, 0xa5, 0xa5, 0xa5, 0x6c, 0x76, 0x33,
  29780. 0x35, 0x63, 0xdc, 0xe4, 0xec, 0x7f, 0x8a, 0xfa,
  29781. 0xc3, 0x53, 0x69, 0x28, 0xf7, 0xd6, 0x97, 0xb9,
  29782. 0x3a, 0xf4, 0x15, 0x90, 0x50, 0xd3, 0xdf, 0xf5,
  29783. 0xd3, 0xcf, 0x15, 0x76, 0xe3, 0x3d, 0x24, 0x14,
  29784. 0xfd, 0xd3, 0x01, 0x25, 0x82, 0xb4, 0xe3, 0xd8,
  29785. 0x68, 0x89, 0x86, 0xa8, 0x26, 0x02, 0x5f, 0xc6,
  29786. 0xf4, 0x99, 0x3b, 0x97, 0xa8, 0x65, 0xed, 0x18,
  29787. 0xbb, 0x3c, 0x43, 0x4a, 0x6e, 0xaa, 0xbc, 0x83,
  29788. 0x85, 0x19, 0x9f, 0x9b, 0xb8, 0xa4, 0xa3, 0xb2,
  29789. 0xb7, 0x56, 0x07, 0x6c, 0xbf, 0x7d, 0xff, 0x5d,
  29790. 0xb5, 0x1e, 0x83, 0xc8, 0x74, 0x70, 0x98, 0x17,
  29791. 0x40, 0xe0, 0x2d, 0xad, 0x31, 0x00, 0x8e, 0x42,
  29792. 0xd5, 0xb2, 0x25, 0xaa, 0x82, 0xaf, 0x33, 0xd8,
  29793. 0x5b, 0xe2, 0x07, 0xed, 0xda, 0x84, 0xe9, 0xa2,
  29794. 0xff, 0xbb, 0xa5, 0x47, 0x95, 0x6e, 0xa1, 0x8d,
  29795. 0x59, 0x52, 0xeb, 0xf3, 0x3c, 0x18, 0x29, 0x92,
  29796. 0x72, 0x27, 0x18, 0xfc, 0x95, 0xb9, 0xde, 0x46,
  29797. 0xda, 0xcc, 0x4c, 0x31, 0x1d, 0x78, 0x86, 0xd2,
  29798. 0x8c, 0x38, 0x9c, 0x32, 0xab, 0xf7, 0xca, 0x73,
  29799. 0x85, 0xa5, 0xf1, 0xe0, 0x25, 0x06, 0xf9, 0x18,
  29800. 0x14, 0xab, 0x3b, 0x73, 0x26, 0xee, 0xa0, 0xfd,
  29801. 0x15, 0xac, 0xd6, 0x4e, 0x6b, 0xdb, 0x01, 0xa1,
  29802. 0xdc, 0xd1, 0x2f, 0xd2, 0xb7, 0x5e, 0x12, 0x4f,
  29803. 0x4b, 0x59, 0xd8, 0x03, 0x12, 0x60, 0xc9, 0x81,
  29804. 0xb7, 0x06, 0x23, 0x09, 0xc4, 0xd9, 0xa8, 0x93,
  29805. 0x6e, 0x96, 0xf4, 0x93, 0x53, 0xf0, 0x3d, 0xde,
  29806. 0x10, 0x88, 0xb1, 0xd0, 0xcc, 0xad, 0x2c, 0xbf,
  29807. 0x88, 0x98, 0x8f, 0x25, 0x76, 0xd7, 0x65, 0x77,
  29808. 0xcc, 0x36, 0x1d, 0x1b, 0x6b, 0x60, 0x58, 0xc4,
  29809. 0xfe, 0xe6, 0xca, 0xa8, 0x29, 0x33, 0x69, 0x36,
  29810. 0xb8, 0x12, 0x95, 0x38, 0xd9, 0xd4, 0x16, 0xe9,
  29811. 0x3e, 0x40, 0x8c, 0xc7, 0xae, 0x04, 0x11, 0xdf,
  29812. 0x51, 0xd3, 0xdd, 0xbf, 0xa9, 0x41, 0x43, 0x4c,
  29813. 0xff, 0x87, 0x2f, 0xea, 0x0f, 0x13, 0x66, 0x2a,
  29814. 0x2b, 0x18, 0xe8, 0xc4, 0xff, 0xa0, 0x1c, 0x78,
  29815. 0x79, 0x21, 0xf8, 0xaa, 0x8a, 0xf8, 0x92, 0xdf,
  29816. 0x7b, 0x5f, 0x6a, 0x71, 0x60, 0x67, 0x5d, 0x94,
  29817. 0xf6, 0xbb, 0x1d, 0x90, 0x7c, 0x51, 0x70, 0x1d,
  29818. 0x87, 0xde, 0xf8, 0x91, 0xcb, 0x42, 0x9f, 0xc7,
  29819. 0x4b, 0xa0, 0x16, 0xee, 0xb4, 0x73, 0xe8, 0xe0,
  29820. 0x0b, 0xa5, 0xd3, 0x26, 0x9e, 0x52, 0xda, 0x4a,
  29821. 0x1f, 0xae, 0x76, 0xbf, 0xbb, 0x4d, 0x74, 0x98,
  29822. 0xa6, 0xae, 0xc0, 0x60, 0x96, 0xc5, 0xad, 0x9b,
  29823. 0x91, 0x31, 0xb9, 0x50, 0x3d, 0x9a, 0x0f, 0xe1,
  29824. 0x93, 0xef, 0x08, 0x72, 0xb2, 0x66, 0xe5, 0x5d,
  29825. 0xe4, 0x15, 0x53, 0x8e, 0xb0, 0xb3, 0xf8, 0x78,
  29826. 0xfc, 0x5d, 0x44, 0xc5, 0xbf, 0xf5, 0x01, 0x54,
  29827. 0xc5, 0x45, 0xa9, 0x30, 0xa4, 0xf1, 0x49, 0x79,
  29828. 0x4e, 0xab, 0xfc, 0xb2, 0x93, 0xe7, 0x3a, 0xe1,
  29829. 0x7f, 0x1f, 0x2f, 0x45, 0x3a, 0x53, 0x2b, 0x68,
  29830. 0xb3, 0xa4, 0xac, 0x23, 0x54, 0xb7, 0x5d, 0x25,
  29831. 0xa3, 0xe3, 0x90, 0x8a, 0xb0, 0x02, 0xfb, 0x7f,
  29832. 0x2d, 0xeb, 0x80, 0xc2, 0x5c, 0x62, 0xe1, 0x36,
  29833. 0x5a, 0x82, 0x8f, 0x4e, 0x74, 0xeb, 0x7d, 0x70,
  29834. 0xaf, 0x23, 0x92, 0x65, 0x3a, 0x11, 0xc0, 0x29,
  29835. 0xdb, 0xf7, 0x9a, 0xdc, 0x81, 0x45, 0x25, 0x0c,
  29836. 0x2e, 0x4f, 0x88, 0x41, 0x34, 0x53, 0xc6, 0x08,
  29837. 0x21, 0x77, 0xc1, 0xbb, 0x61, 0x48, 0x20, 0x69,
  29838. 0x1a, 0xbb, 0x71, 0x1b, 0x56, 0x18, 0x79, 0x75,
  29839. 0x16, 0x9a, 0xb3, 0x79, 0x31, 0x11, 0xa2, 0x89,
  29840. 0x8d, 0xea, 0x10, 0xb0, 0x04, 0x7f, 0xf8, 0x6e,
  29841. 0xdc, 0x08, 0x9b, 0x51, 0xa7, 0x64, 0xbd, 0x8d,
  29842. 0xd4, 0xd0, 0x1e, 0x38, 0x50, 0x1a, 0xa8, 0x7e,
  29843. 0x20, 0xae, 0xee, 0x8c, 0xa7, 0x72, 0x94, 0xc9,
  29844. 0xba, 0xf0, 0x67, 0xbd, 0x25, 0x1a, 0x3a, 0xdf,
  29845. 0x75, 0x39, 0xb7, 0xd3, 0x83, 0x3b, 0x89, 0xdf,
  29846. 0xb5, 0x2d, 0xd3, 0x12, 0x24, 0x21, 0x7c, 0x9e,
  29847. 0x92, 0x1c, 0x19, 0xae, 0x28, 0xcb, 0x2e, 0x2e,
  29848. 0x3c, 0xa9, 0x9b, 0xbd, 0xf9, 0x33, 0x30, 0xb2,
  29849. 0xbd, 0x8b, 0xbf, 0xc1, 0x8b, 0x32, 0xf1, 0x20,
  29850. 0xa1, 0x00, 0xfd, 0x11, 0x7d, 0x9a, 0xa8, 0x14,
  29851. 0x2c, 0xce, 0x16, 0x16, 0x4b, 0xdd, 0x56, 0x91,
  29852. 0x15, 0x36, 0x83, 0xcb, 0x01, 0x58, 0x35, 0xe1,
  29853. 0xdc, 0x22, 0x3d, 0xf8, 0xc2, 0x06, 0x54, 0x68,
  29854. 0x77, 0xd1, 0x47, 0x28, 0xdc, 0x09, 0x2a, 0x86,
  29855. 0x13, 0x80, 0xa6, 0xe9, 0xd0, 0xb4, 0xa3, 0x41,
  29856. 0x47, 0xf4, 0x71, 0x24, 0x10, 0x4c, 0x9f, 0xb7,
  29857. 0x57, 0x34, 0x48, 0x1b, 0xb4, 0xed, 0x0e, 0x89,
  29858. 0x4c, 0xf1, 0x73, 0x44, 0xff, 0x35, 0xb6, 0xe0,
  29859. 0x8f, 0x02, 0xa3, 0xa3, 0x81, 0x55, 0x38, 0xb5,
  29860. 0xc1, 0x99, 0xb3, 0x88, 0x84, 0x0d, 0xd9, 0x73,
  29861. 0x77, 0x65, 0x0b, 0xd7, 0xf8, 0x03, 0x88, 0xcb,
  29862. 0xdf, 0x25, 0xaf, 0xc6, 0xf1, 0xfa, 0x5c, 0x4d,
  29863. 0xfa, 0xc3, 0x7b, 0x8f, 0xb8, 0x38, 0x5d, 0x29,
  29864. 0xbb, 0x3d, 0x3e, 0x62, 0x1c, 0xdd, 0xe6, 0x97,
  29865. 0xe6, 0xe9, 0xbe, 0x6e, 0xd2, 0xb7, 0x7a, 0x9a,
  29866. 0x8e, 0xaf, 0xb3, 0xc8, 0x9e, 0x19, 0xee, 0x3d,
  29867. 0x5b, 0x1f, 0xec, 0x34, 0x3a, 0x1c, 0x27, 0x90,
  29868. 0xbd, 0x1e, 0x49, 0x72, 0x25, 0x2e, 0x38, 0x48,
  29869. 0x7d, 0xe1, 0x85, 0x46, 0xa7, 0x1b, 0x4a, 0xd5,
  29870. 0x23, 0x75, 0x6d, 0x8b, 0xc3, 0xf1, 0x87, 0xec,
  29871. 0x8b, 0x45, 0xf0, 0x9b, 0xb2, 0x14, 0x7a, 0x7c,
  29872. 0x8d, 0x78, 0x9c, 0x82, 0x64, 0x14, 0xfe, 0x01,
  29873. 0xfa, 0x04, 0x33, 0x96, 0xdd, 0x5f, 0x56, 0xbc,
  29874. 0xb2, 0x03, 0xe3, 0x0c, 0xa1, 0x09, 0x66, 0xa0,
  29875. 0x5e, 0x44, 0xde, 0x21, 0xae, 0x7d, 0x7a, 0x0e,
  29876. 0x81, 0x27, 0xd2, 0xfb, 0x85, 0xed, 0x27, 0x27,
  29877. 0xac, 0x11, 0x1c, 0xa1, 0x6d, 0xe9, 0xc1, 0xca,
  29878. 0xf6, 0x40, 0x7c, 0x95, 0x01, 0xb7, 0xa8, 0x29,
  29879. 0x9a, 0xd2, 0xcc, 0x62, 0x70, 0x1c, 0x7d, 0x0e,
  29880. 0xe5, 0x60, 0xcb, 0x79, 0xa3, 0xd7, 0x5d, 0x48,
  29881. 0x4b, 0x3c, 0xf8, 0x12, 0xe8, 0x7a, 0x7e, 0x83,
  29882. 0xab, 0x24, 0x33, 0x0f, 0x7b, 0x0a, 0x38, 0xae,
  29883. 0xb1, 0xfc, 0xc3, 0x50, 0x5c, 0x83, 0x53, 0xfd,
  29884. 0x15, 0xd6, 0x49, 0x54, 0xb6, 0x40, 0xe5, 0xe8,
  29885. 0x55, 0xba, 0x08, 0x2f, 0x21, 0xd7, 0x0e, 0x71,
  29886. 0x8a, 0xb2, 0xe1, 0x6b, 0xc6, 0x7e, 0x0f, 0x1c,
  29887. 0x4d, 0x41, 0x9f, 0x38, 0xc2, 0xce, 0x41, 0x41,
  29888. 0x48, 0xcd, 0xec, 0x16, 0x1d, 0x23, 0x8e, 0x41,
  29889. 0xcd, 0x5e, 0xf9, 0x5f, 0x01, 0x5e, 0x73, 0xa2,
  29890. 0xa1, 0xef, 0xe9, 0x57, 0xe0, 0xba, 0xe6, 0xbb,
  29891. 0x2b, 0xff, 0x3e, 0xb8, 0xad, 0xd5, 0x12, 0xc1,
  29892. 0x54, 0x49, 0xca, 0x93, 0xb0, 0x7d, 0x7b, 0xcf,
  29893. 0xf0, 0xc5, 0x94, 0x43, 0x30, 0x94, 0x11, 0x8d,
  29894. 0x15, 0x79, 0x2e, 0x57, 0xb8, 0x24, 0xcd, 0x2e,
  29895. 0xc2, 0x49, 0x3d, 0x92, 0x44, 0x23, 0x0c, 0x3e,
  29896. 0xa0, 0xf9, 0xa5, 0xad, 0x2a, 0x56, 0xec, 0xf4,
  29897. 0x6d, 0x0f, 0x5b, 0xb5, 0xd4, 0x2a, 0x3f, 0x2b,
  29898. 0x17, 0x9f, 0x5d, 0x33, 0x97, 0x42, 0xd4, 0x1e,
  29899. 0x14, 0x49, 0x01, 0xfb, 0xb6, 0x72, 0xbc, 0x14,
  29900. 0x5b, 0x79, 0xf4, 0x0a, 0xc5, 0x49, 0xe1, 0x76,
  29901. 0x44, 0x78, 0x87, 0xd1, 0x8e, 0x5b, 0xd5, 0x95,
  29902. 0xad, 0x19, 0x7c, 0x0d, 0x39, 0x7f, 0x41, 0x2e,
  29903. 0xd7, 0x9e, 0xbc, 0xfd, 0x2c, 0xde, 0xfa, 0x01,
  29904. 0x7d, 0x2b, 0x04, 0xef, 0x4d, 0xf9, 0xf4, 0x5b,
  29905. 0xed, 0x05, 0x9a, 0x50, 0x35, 0xe7, 0xb0, 0xba,
  29906. 0x24, 0xea, 0x16, 0x51, 0xe1, 0x6f, 0x32, 0x08,
  29907. 0x94, 0xd6, 0x19, 0x9d, 0x0e, 0x4c, 0xc1, 0xbb,
  29908. 0x01, 0x87, 0xa5, 0x90, 0x5f, 0x6f, 0xc4, 0xed,
  29909. 0xa1, 0x4c, 0x06, 0x4d, 0x2c, 0x47, 0x24, 0xda,
  29910. 0xae, 0xd2, 0x41, 0x92, 0x1f, 0x46, 0xce, 0xec,
  29911. 0xb1, 0xcc, 0x80, 0x1e, 0xb2, 0xcb, 0x66, 0x48,
  29912. 0x22, 0xec, 0x0e, 0x47, 0xfc, 0xad, 0x17, 0xfe,
  29913. 0x7b, 0xc5, 0x4d, 0x34, 0x95, 0x40, 0xd0, 0x02,
  29914. 0x7e, 0x90, 0xaa, 0x92, 0xaf, 0x48, 0x64, 0xc5,
  29915. 0xc1, 0x56, 0xd8, 0x9b, 0x6c, 0x5f, 0x2e, 0xfa,
  29916. 0xd7, 0x84, 0xdc, 0x71, 0x65, 0x1b, 0xfb, 0xbc,
  29917. 0x21, 0xc7, 0x57, 0xf4, 0x71, 0x2e, 0x6f, 0x34,
  29918. 0x85, 0x99, 0xa8, 0x5c, 0x6f, 0x34, 0x22, 0x44,
  29919. 0x89, 0x01, 0xf9, 0x48, 0xd2, 0xe2, 0xe4, 0x71,
  29920. 0x9d, 0x48, 0x07, 0x97, 0xd4, 0x66, 0xe4, 0x4d,
  29921. 0x48, 0xa3, 0x08, 0x7f, 0x6e, 0xaa, 0x7b, 0xe9,
  29922. 0x93, 0x81, 0x03, 0x0c, 0xd2, 0x48, 0xcf, 0x3f,
  29923. 0x5f, 0xbe, 0x03, 0xfb, 0x0f, 0xad, 0xc3, 0x81,
  29924. 0xd9, 0xce, 0x88, 0x0b, 0xfa, 0xed, 0x29, 0x7e,
  29925. 0x0b, 0xa1, 0x6f, 0x4c, 0x7d, 0xe4, 0x36, 0xff,
  29926. 0xdf, 0x94, 0x1a, 0x24, 0xb3, 0x7b, 0xca, 0x24,
  29927. 0x7e, 0x3a, 0x19, 0x53, 0x13, 0x4a, 0x17, 0x58,
  29928. 0xe7, 0x16, 0x9b, 0x50, 0xd8, 0xda, 0xcc, 0x6e,
  29929. 0x05, 0x25, 0xfe, 0x16, 0xcb, 0x5b, 0xd5, 0x35,
  29930. 0x76, 0x40, 0x44, 0x96, 0x23, 0x97, 0xe2, 0x4a,
  29931. 0x72, 0x0c, 0x54, 0x43, 0xc0, 0x09, 0x85, 0x8e,
  29932. 0x15, 0x85, 0xaf, 0x3c, 0x5e, 0x5f, 0x3c, 0x2d,
  29933. 0x21, 0x42, 0x75, 0xb7, 0xe4, 0x50, 0xf9, 0x00,
  29934. 0xa3, 0x4f, 0xb1, 0x7c, 0xfe, 0x62, 0xd0, 0xe9,
  29935. 0x6d, 0x51, 0xcc, 0x83, 0xc1, 0xdc, 0x37, 0x10,
  29936. 0x90, 0x0a, 0x15, 0xd8, 0xd5, 0x02, 0xf7, 0x74,
  29937. 0xb8, 0x46, 0x84, 0xc3, 0x61, 0x17, 0x26, 0x0f,
  29938. 0xe4, 0xde, 0x1a, 0xcf, 0x42, 0x53, 0x63, 0x2f,
  29939. 0x8d, 0xf7, 0x06, 0x07, 0xc3, 0x33, 0x39, 0x59,
  29940. 0xe9, 0x17, 0xc8, 0x05, 0xd2, 0xa2, 0xae, 0x53,
  29941. 0x2c, 0x7e, 0xd0, 0x9d, 0x5c, 0xb5, 0x42, 0x9f,
  29942. 0x84, 0xd7, 0xfe, 0x93, 0x74, 0xfb, 0xbb, 0xd2,
  29943. 0x1e, 0x57, 0x4e, 0x7f, 0x79, 0xaf, 0xd2, 0xf9,
  29944. 0x5e, 0x41, 0x9e, 0x63, 0x54, 0x61, 0x47, 0x0c,
  29945. 0x92, 0x4c, 0xc9, 0xfe, 0x4f, 0xcb, 0xe5, 0x8e,
  29946. 0x65, 0xb3, 0x97, 0x1b, 0xd8, 0xd1, 0x62, 0xfd
  29947. #else
  29948. 0x30, 0x82, 0x0a, 0x34, 0x30, 0x0d, 0x06, 0x0b,
  29949. 0x2b, 0x06, 0x01, 0x04, 0x01, 0x02, 0x82, 0x0b,
  29950. 0x0c, 0x08, 0x07, 0x03, 0x82, 0x0a, 0x21, 0x00,
  29951. 0x7f, 0x5f, 0x63, 0x81, 0x6f, 0x04, 0x4c, 0xec,
  29952. 0xa8, 0xaf, 0x7b, 0x99, 0x41, 0xc6, 0xff, 0xdf,
  29953. 0x77, 0x66, 0x28, 0xc0, 0xe2, 0x58, 0xea, 0x9c,
  29954. 0x60, 0xbb, 0x03, 0x3e, 0xca, 0xa8, 0x38, 0x64,
  29955. 0xfb, 0xf7, 0x1b, 0x3f, 0xec, 0xfd, 0x0f, 0xf1,
  29956. 0x9c, 0xe4, 0xfd, 0xad, 0x83, 0xf7, 0x03, 0x66,
  29957. 0x6e, 0x7f, 0x4d, 0x42, 0xab, 0x6b, 0x73, 0x26,
  29958. 0xde, 0x6f, 0x8c, 0xc4, 0xca, 0x21, 0x66, 0x31,
  29959. 0x79, 0x57, 0x88, 0xcb, 0x1e, 0xab, 0xda, 0x1d,
  29960. 0x56, 0x70, 0xd9, 0x83, 0xa1, 0xb4, 0x83, 0xce,
  29961. 0xcc, 0x0f, 0xeb, 0xd6, 0x63, 0xbd, 0xf6, 0x02,
  29962. 0x5d, 0x5b, 0x0c, 0x17, 0x3c, 0x3e, 0x15, 0x02,
  29963. 0x22, 0xa1, 0x5d, 0xb5, 0xc5, 0x81, 0x28, 0x95,
  29964. 0x0b, 0x34, 0x2b, 0x96, 0x0a, 0xae, 0x6a, 0xa8,
  29965. 0xb5, 0x1d, 0x56, 0xbb, 0x7d, 0x83, 0x9a, 0x15,
  29966. 0xad, 0x63, 0x9e, 0x86, 0x8c, 0x6e, 0x6a, 0xa8,
  29967. 0xde, 0x55, 0xd0, 0xce, 0xc0, 0x2e, 0x05, 0xfe,
  29968. 0x1f, 0x4d, 0xd7, 0x12, 0xa4, 0x5a, 0xe9, 0x04,
  29969. 0x0d, 0x20, 0x84, 0x90, 0xb9, 0xca, 0x64, 0xe4,
  29970. 0xad, 0x2e, 0x74, 0x4b, 0x1d, 0x2f, 0xcc, 0xac,
  29971. 0xd8, 0x1a, 0x5e, 0xb2, 0x78, 0xbe, 0x61, 0xf7,
  29972. 0x36, 0xa3, 0xd1, 0x93, 0x86, 0xb5, 0x15, 0xf1,
  29973. 0x74, 0xf8, 0x9f, 0x6d, 0x6a, 0x8f, 0x6d, 0x86,
  29974. 0x8b, 0x36, 0x61, 0x10, 0xc9, 0x1a, 0x31, 0x39,
  29975. 0x09, 0xe6, 0x15, 0xa0, 0xb1, 0xfa, 0x69, 0xd4,
  29976. 0xc2, 0xb2, 0x56, 0x4c, 0x06, 0x33, 0x13, 0xc4,
  29977. 0x78, 0x53, 0x16, 0xfc, 0x52, 0x99, 0xe6, 0x27,
  29978. 0xc9, 0x3b, 0x24, 0x5c, 0x3e, 0x85, 0x73, 0x76,
  29979. 0x61, 0xa3, 0x61, 0xf0, 0x95, 0xd5, 0xb2, 0xf5,
  29980. 0x21, 0xe7, 0x09, 0xc3, 0x0c, 0x5c, 0xb0, 0x36,
  29981. 0xce, 0x45, 0x68, 0x41, 0x45, 0xcb, 0x1c, 0x36,
  29982. 0x2f, 0x3a, 0x00, 0x07, 0x56, 0xbe, 0x61, 0xd2,
  29983. 0x77, 0x37, 0x63, 0xa4, 0xdb, 0xfa, 0xa9, 0x6b,
  29984. 0x37, 0x90, 0x35, 0xd1, 0x1e, 0x27, 0x5b, 0x3e,
  29985. 0xc0, 0x0a, 0x02, 0x64, 0xe4, 0x58, 0x49, 0xab,
  29986. 0x2d, 0xc1, 0x38, 0x29, 0x3d, 0x44, 0xf9, 0xac,
  29987. 0xb7, 0x65, 0xd1, 0x5f, 0xf8, 0xce, 0x52, 0x76,
  29988. 0x22, 0x15, 0x61, 0x02, 0x1f, 0xa7, 0xcd, 0xff,
  29989. 0xeb, 0xa6, 0x7f, 0x6b, 0xba, 0x75, 0xe3, 0x09,
  29990. 0x01, 0x06, 0x41, 0x20, 0x88, 0x75, 0x64, 0x6b,
  29991. 0x97, 0x38, 0x13, 0xab, 0x4c, 0x0a, 0xd4, 0x7e,
  29992. 0xd2, 0xfa, 0x78, 0xe8, 0x9f, 0x5d, 0xf9, 0x53,
  29993. 0x30, 0x17, 0xf1, 0x10, 0x9e, 0x4a, 0x32, 0x17,
  29994. 0x3a, 0x9b, 0xb9, 0x25, 0x8e, 0xeb, 0xd9, 0x41,
  29995. 0x01, 0xa2, 0xc6, 0x58, 0x4a, 0x9f, 0xc3, 0x73,
  29996. 0xfd, 0xe2, 0xe4, 0x2c, 0x92, 0xb4, 0xa2, 0x3d,
  29997. 0x0f, 0x1f, 0x37, 0x64, 0xf1, 0x17, 0x2a, 0x8c,
  29998. 0xc6, 0xb5, 0xb0, 0x69, 0x7d, 0xfe, 0x08, 0xe0,
  29999. 0x8e, 0xaa, 0xe0, 0x08, 0xd5, 0x28, 0x92, 0x51,
  30000. 0x73, 0x8a, 0x2f, 0x7a, 0x4a, 0xbf, 0x52, 0x8d,
  30001. 0x3e, 0x9b, 0x36, 0x6a, 0xfb, 0x19, 0xf0, 0xea,
  30002. 0xfe, 0x05, 0xbd, 0x2d, 0xa9, 0x58, 0x48, 0x02,
  30003. 0xa8, 0x20, 0x9e, 0xdc, 0x04, 0x57, 0xc2, 0x0c,
  30004. 0xae, 0xc1, 0x03, 0xe7, 0x17, 0x48, 0x80, 0x00,
  30005. 0x8d, 0x1b, 0xd0, 0xc5, 0xdc, 0x2a, 0x02, 0x6e,
  30006. 0x8e, 0x54, 0xf3, 0x79, 0x31, 0x02, 0x93, 0xc5,
  30007. 0xf2, 0x55, 0xea, 0x61, 0xd0, 0xb2, 0x8e, 0xc9,
  30008. 0x74, 0x17, 0x0d, 0x38, 0xf8, 0xab, 0xf4, 0x42,
  30009. 0xd4, 0xc2, 0xdc, 0xf7, 0x1b, 0xdb, 0x65, 0x36,
  30010. 0x9f, 0x56, 0xe2, 0xeb, 0xf7, 0xe5, 0x2d, 0x45,
  30011. 0xae, 0xc0, 0x95, 0xbc, 0xe4, 0x1f, 0x22, 0xdc,
  30012. 0x0f, 0x54, 0xed, 0x14, 0xb8, 0xf1, 0x2f, 0x5d,
  30013. 0xd1, 0x79, 0xa0, 0x81, 0x17, 0x71, 0xa1, 0xd6,
  30014. 0xf0, 0x88, 0x9c, 0x1c, 0xc7, 0x95, 0x07, 0xb0,
  30015. 0xea, 0xf7, 0xd3, 0xa2, 0x55, 0xfe, 0x85, 0x65,
  30016. 0x42, 0x06, 0xec, 0xd2, 0xbe, 0x03, 0x8f, 0x63,
  30017. 0x84, 0x4b, 0xb1, 0x47, 0x48, 0x20, 0x71, 0xd2,
  30018. 0xdf, 0xc9, 0x59, 0xb0, 0x24, 0x8a, 0x6e, 0xf9,
  30019. 0x4a, 0xa1, 0x7b, 0xed, 0x11, 0xb6, 0xf9, 0x9b,
  30020. 0xf7, 0x93, 0x0e, 0xcb, 0x7a, 0x32, 0x22, 0x23,
  30021. 0x4e, 0x86, 0xce, 0xad, 0x9d, 0x1b, 0x84, 0x57,
  30022. 0xaf, 0xa5, 0x04, 0x03, 0x0a, 0xc9, 0x04, 0x97,
  30023. 0xd0, 0xce, 0x8e, 0x2a, 0x9a, 0x00, 0x15, 0xeb,
  30024. 0xac, 0x96, 0x57, 0xde, 0xe6, 0xc1, 0x2d, 0xbd,
  30025. 0xfc, 0xd6, 0x95, 0x0f, 0x5f, 0x19, 0xac, 0xaf,
  30026. 0x6c, 0xd8, 0xa6, 0x1e, 0xd8, 0xdb, 0x14, 0xfd,
  30027. 0xba, 0x0f, 0xd0, 0x3f, 0x61, 0xe3, 0x76, 0xfc,
  30028. 0x47, 0x61, 0x07, 0x24, 0x49, 0x17, 0xca, 0x24,
  30029. 0x31, 0x16, 0x26, 0x4f, 0xdc, 0x2b, 0x39, 0xae,
  30030. 0x5f, 0xfa, 0x4f, 0x82, 0xef, 0xe1, 0x41, 0x8c,
  30031. 0x3e, 0x8e, 0xa7, 0x6c, 0xf2, 0x51, 0xf7, 0x85,
  30032. 0x35, 0x6c, 0xad, 0xea, 0x32, 0x35, 0xf3, 0xc0,
  30033. 0x14, 0x17, 0xe2, 0x98, 0x27, 0x36, 0x7e, 0x60,
  30034. 0x2f, 0x01, 0x60, 0x3e, 0x18, 0xf4, 0x4e, 0xe0,
  30035. 0xf5, 0x14, 0x21, 0x81, 0x05, 0x78, 0x1c, 0x5f,
  30036. 0x4e, 0x89, 0xbb, 0x23, 0x60, 0xb1, 0x8f, 0x07,
  30037. 0x53, 0x16, 0x6e, 0xfb, 0x86, 0x07, 0x90, 0xff,
  30038. 0xa6, 0x27, 0x60, 0xe6, 0x3e, 0x92, 0x2a, 0x3c,
  30039. 0xa3, 0x57, 0xec, 0x97, 0x23, 0xaf, 0xd2, 0x44,
  30040. 0xac, 0x09, 0x87, 0xb0, 0x54, 0xe9, 0x5b, 0x50,
  30041. 0x37, 0xfa, 0x12, 0xa4, 0xcb, 0x6f, 0xed, 0x9f,
  30042. 0x29, 0x73, 0xa7, 0x09, 0x29, 0x91, 0x93, 0x5c,
  30043. 0x54, 0xf4, 0x44, 0xc2, 0x04, 0x64, 0xfc, 0xd2,
  30044. 0xf2, 0x0a, 0x0b, 0x45, 0x1f, 0xc5, 0x18, 0xf0,
  30045. 0xff, 0x10, 0x1f, 0x3a, 0x97, 0xf8, 0xb1, 0x83,
  30046. 0x0e, 0x08, 0xe2, 0x55, 0x75, 0x6a, 0x45, 0x96,
  30047. 0xf8, 0x1b, 0xdc, 0xb6, 0x57, 0x83, 0x8c, 0x28,
  30048. 0xc0, 0x4a, 0x57, 0xc6, 0xfb, 0x27, 0x3d, 0xfa,
  30049. 0x5a, 0x0d, 0x69, 0x56, 0x23, 0x66, 0x02, 0x78,
  30050. 0xca, 0xf1, 0xfa, 0xcb, 0xc1, 0xf6, 0x92, 0x1c,
  30051. 0xa0, 0xe3, 0x09, 0x7d, 0x48, 0x5e, 0x86, 0xa0,
  30052. 0x82, 0xa8, 0xf1, 0x1e, 0xe1, 0xfe, 0xc6, 0x9d,
  30053. 0x4f, 0x2e, 0xf4, 0xfc, 0xc6, 0x48, 0x1d, 0xc1,
  30054. 0x2a, 0x6a, 0xb7, 0xea, 0x46, 0x89, 0x04, 0xe9,
  30055. 0xbd, 0xf1, 0xed, 0x16, 0x76, 0xd8, 0x4b, 0x42,
  30056. 0xd5, 0x43, 0xa4, 0xfb, 0x02, 0x01, 0x54, 0x00,
  30057. 0xaf, 0x55, 0x52, 0x27, 0xff, 0x00, 0xe2, 0xbb,
  30058. 0x4a, 0xf2, 0x69, 0xb4, 0x4e, 0x6c, 0x6b, 0xa3,
  30059. 0x96, 0x4f, 0xf4, 0x65, 0x90, 0x2d, 0xc8, 0x57,
  30060. 0x1f, 0xb2, 0xf0, 0x86, 0x7b, 0x93, 0x09, 0x49,
  30061. 0x31, 0xc4, 0xf4, 0x8f, 0xc8, 0x2d, 0xac, 0x1d,
  30062. 0xfc, 0xba, 0xa4, 0xa5, 0x41, 0x90, 0x76, 0x7d,
  30063. 0x9e, 0x47, 0xdc, 0x10, 0xe6, 0x0c, 0xf7, 0x0f,
  30064. 0xa4, 0xba, 0x4f, 0xe2, 0x46, 0x38, 0x4c, 0x28,
  30065. 0xa0, 0x57, 0xb5, 0x3c, 0xb3, 0x4b, 0x8f, 0x03,
  30066. 0x04, 0xff, 0xf6, 0xec, 0x60, 0x90, 0x62, 0xfe,
  30067. 0x74, 0x76, 0x48, 0xb3, 0xf4, 0x0a, 0x6a, 0x5a,
  30068. 0x5b, 0xad, 0xc8, 0x54, 0x62, 0x11, 0x52, 0xd9,
  30069. 0x84, 0x1a, 0x09, 0x4b, 0xca, 0x66, 0xaa, 0x3c,
  30070. 0x36, 0x08, 0x9d, 0x58, 0xd0, 0x4a, 0x3a, 0x8b,
  30071. 0x24, 0xe0, 0x80, 0x9f, 0xe3, 0x76, 0xb6, 0x07,
  30072. 0xb1, 0xbc, 0x00, 0x98, 0xb0, 0xc1, 0xe0, 0xf6,
  30073. 0x1f, 0x4d, 0xa8, 0xd1, 0x69, 0x44, 0x9c, 0x33,
  30074. 0xb0, 0x0f, 0x9c, 0xc9, 0x0c, 0x8c, 0xbc, 0x03,
  30075. 0x58, 0x81, 0x76, 0xab, 0x0d, 0xef, 0x25, 0x5a,
  30076. 0xf6, 0xab, 0x3b, 0xf1, 0x1f, 0x97, 0x12, 0x8e,
  30077. 0x7f, 0x28, 0x77, 0x26, 0x18, 0xc4, 0xc4, 0xda,
  30078. 0x2c, 0x43, 0x57, 0xd2, 0x1f, 0x67, 0x95, 0x40,
  30079. 0x2c, 0x94, 0x41, 0x69, 0x22, 0x8a, 0x24, 0xd9,
  30080. 0xc7, 0xfc, 0xea, 0x49, 0x83, 0x8f, 0x5d, 0x2e,
  30081. 0x9d, 0xac, 0x17, 0xb6, 0xe0, 0xc4, 0xe7, 0xe6,
  30082. 0xd5, 0xc2, 0x73, 0xa1, 0x8f, 0x33, 0x14, 0x02,
  30083. 0xae, 0x01, 0x9f, 0x6f, 0x40, 0x92, 0x4e, 0x03,
  30084. 0xc2, 0xa9, 0xf1, 0x36, 0x78, 0xe4, 0xde, 0x39,
  30085. 0x4d, 0x29, 0x2e, 0xc2, 0x00, 0x93, 0x79, 0xe4,
  30086. 0xb2, 0x29, 0x4b, 0x81, 0x5c, 0x06, 0x06, 0xbc,
  30087. 0xc1, 0x01, 0x1c, 0xa7, 0x08, 0xf7, 0x47, 0x1f,
  30088. 0x52, 0x4f, 0xdf, 0x94, 0x1e, 0xe6, 0x89, 0xe6,
  30089. 0x26, 0x71, 0x2e, 0xa2, 0xd2, 0xfe, 0x04, 0xf2,
  30090. 0x12, 0x4c, 0x06, 0x78, 0x34, 0xc0, 0xb9, 0x76,
  30091. 0x62, 0x3b, 0x72, 0x25, 0x8c, 0x0d, 0x73, 0x24,
  30092. 0xcf, 0x4b, 0x4c, 0x47, 0x20, 0x9d, 0x04, 0x7f,
  30093. 0x86, 0x2c, 0x45, 0xb8, 0xfe, 0xb2, 0xaa, 0x36,
  30094. 0xf8, 0xe0, 0x24, 0x25, 0x05, 0x23, 0x12, 0x16,
  30095. 0xbf, 0x64, 0x10, 0xdd, 0xe4, 0xc0, 0xb0, 0x85,
  30096. 0xa7, 0xd3, 0xd1, 0x18, 0x1b, 0x81, 0x6b, 0x94,
  30097. 0xfd, 0x07, 0x43, 0xdd, 0x12, 0x37, 0x78, 0x69,
  30098. 0xec, 0x8c, 0xd0, 0x41, 0x2c, 0x42, 0x94, 0x3e,
  30099. 0x9f, 0xe3, 0x49, 0xb3, 0xb8, 0x45, 0x0b, 0x1d,
  30100. 0xc1, 0x9b, 0x4d, 0x21, 0x85, 0x62, 0xea, 0xd1,
  30101. 0xc9, 0x12, 0x30, 0x8c, 0x4b, 0x63, 0xeb, 0x7d,
  30102. 0x02, 0x52, 0x15, 0xa1, 0x95, 0x48, 0x9f, 0xc2,
  30103. 0xce, 0xf3, 0x4b, 0xff, 0x5a, 0xb6, 0x8f, 0xce,
  30104. 0xcd, 0x42, 0x21, 0x40, 0x82, 0xad, 0x08, 0x99,
  30105. 0x4d, 0x24, 0x58, 0x25, 0xf3, 0x7e, 0x42, 0x86,
  30106. 0x06, 0x33, 0x1f, 0x53, 0xbb, 0x07, 0x33, 0xca,
  30107. 0xc0, 0x02, 0x18, 0x30, 0x3c, 0xc5, 0x67, 0x1c,
  30108. 0x32, 0x3f, 0x2d, 0x58, 0x4c, 0x24, 0x6e, 0x60,
  30109. 0x96, 0x1a, 0xf4, 0xd0, 0x55, 0xb8, 0x84, 0xf0,
  30110. 0xb9, 0x83, 0xbf, 0x3d, 0x37, 0xe4, 0xa6, 0x06,
  30111. 0x1c, 0xd1, 0xd7, 0x91, 0x24, 0xdc, 0x3f, 0xcc,
  30112. 0x71, 0xf3, 0x0c, 0x90, 0x2c, 0x1d, 0x2f, 0x90,
  30113. 0xc8, 0x3c, 0x6f, 0x2c, 0x5d, 0xad, 0x8c, 0xdf,
  30114. 0xbb, 0x0d, 0x2a, 0x7f, 0x4a, 0x34, 0x5a, 0xd9,
  30115. 0x83, 0xfd, 0x61, 0x36, 0xe0, 0x0a, 0xb3, 0xf6,
  30116. 0x69, 0xb1, 0xaf, 0x81, 0x22, 0xd6, 0x9e, 0x9a,
  30117. 0xf8, 0xa6, 0x24, 0x8e, 0x0c, 0xcb, 0x25, 0xc2,
  30118. 0xfc, 0xc5, 0x94, 0xbd, 0x23, 0x9c, 0xa9, 0xbd,
  30119. 0x76, 0x28, 0xa4, 0x55, 0x92, 0x7c, 0xe6, 0x76,
  30120. 0xf7, 0x30, 0xf8, 0x7d, 0xdc, 0x0a, 0x93, 0x9e,
  30121. 0x7c, 0x39, 0x0a, 0x70, 0xa0, 0xb2, 0x77, 0xe0,
  30122. 0x7a, 0x89, 0x50, 0xce, 0x75, 0xca, 0x2f, 0xa4,
  30123. 0x12, 0x0e, 0xcb, 0x75, 0x1f, 0x0a, 0x83, 0xe8,
  30124. 0x14, 0x80, 0xa7, 0xb0, 0xe8, 0x11, 0xca, 0x12,
  30125. 0x5e, 0xf7, 0x31, 0x65, 0xbd, 0x20, 0x3d, 0x8c,
  30126. 0xa6, 0x89, 0x83, 0x68, 0x66, 0x03, 0x28, 0x49,
  30127. 0x17, 0xc4, 0x3f, 0x43, 0x02, 0x9b, 0xf8, 0xed,
  30128. 0xae, 0x8e, 0x68, 0xbc, 0x8e, 0x39, 0xe7, 0x15,
  30129. 0x32, 0x45, 0x66, 0x2c, 0x1f, 0xce, 0x56, 0xc7,
  30130. 0xc0, 0x15, 0x52, 0x19, 0x40, 0xcf, 0x87, 0x20,
  30131. 0xcd, 0x3d, 0xec, 0x90, 0x8d, 0x04, 0x01, 0x31,
  30132. 0x0b, 0x74, 0x80, 0x6e, 0x61, 0xa7, 0xf3, 0x4c,
  30133. 0xb2, 0x16, 0x00, 0xd5, 0xdb, 0xcc, 0xbb, 0x2c,
  30134. 0x9f, 0xb6, 0x02, 0x4a, 0xcf, 0x71, 0x06, 0xfd,
  30135. 0x60, 0xe0, 0x00, 0xbe, 0x22, 0xba, 0x39, 0x36,
  30136. 0xa8, 0x7e, 0xe5, 0xcb, 0xea, 0x87, 0xb1, 0xee,
  30137. 0xa2, 0x6c, 0x85, 0x94, 0x18, 0x6c, 0xab, 0x9a,
  30138. 0x93, 0xa7, 0xab, 0x4e, 0x3b, 0x85, 0xf3, 0xef,
  30139. 0x8f, 0x15, 0x74, 0x21, 0x9f, 0x5d, 0x9c, 0x22,
  30140. 0x32, 0x71, 0xb5, 0x4d, 0x7f, 0xaa, 0x85, 0xe0,
  30141. 0x05, 0x2a, 0x53, 0xbb, 0x3c, 0xab, 0xc3, 0xd2,
  30142. 0x73, 0x6e, 0x97, 0xa3, 0xfd, 0x05, 0x58, 0xaa,
  30143. 0x49, 0xc8, 0x69, 0xa9, 0x0b, 0x73, 0xd4, 0xe9,
  30144. 0x1d, 0x84, 0x60, 0x34, 0x2a, 0x09, 0xb3, 0x0f,
  30145. 0x08, 0x13, 0x67, 0x77, 0xb3, 0x24, 0xdf, 0xad,
  30146. 0xbf, 0x51, 0x71, 0x2b, 0xbe, 0x4f, 0x5d, 0xf4,
  30147. 0xe7, 0x25, 0x4c, 0x24, 0xa2, 0x4a, 0x22, 0xec,
  30148. 0xcc, 0x7c, 0x6c, 0x62, 0xee, 0x47, 0x12, 0x43,
  30149. 0x88, 0xe4, 0x71, 0xaa, 0x63, 0xaa, 0x2b, 0xed,
  30150. 0x70, 0xbf, 0x26, 0x37, 0xcc, 0xa4, 0xff, 0xe9,
  30151. 0xb6, 0x65, 0x31, 0x4d, 0x0d, 0x32, 0xd6, 0x84,
  30152. 0xb8, 0xab, 0x98, 0xa7, 0x10, 0x44, 0x77, 0xc7,
  30153. 0x2a, 0x60, 0xf0, 0xf5, 0xd5, 0xd4, 0x3a, 0x73,
  30154. 0x11, 0xa5, 0x1b, 0x18, 0x3c, 0x13, 0xfb, 0xda,
  30155. 0x76, 0x9d, 0xeb, 0x3e, 0xb9, 0x7a, 0xce, 0x02,
  30156. 0xa7, 0x5e, 0x25, 0x96, 0xd2, 0xbc, 0x85, 0x1a,
  30157. 0xd1, 0xa4, 0xe2, 0x02, 0x15, 0x08, 0x49, 0x16,
  30158. 0x7c, 0xaf, 0xc6, 0x38, 0x7b, 0x95, 0xf9, 0x37,
  30159. 0xc0, 0x87, 0x73, 0x6f, 0x01, 0xcd, 0x2b, 0xf1,
  30160. 0xe7, 0x6e, 0x47, 0x18, 0x30, 0xb8, 0x16, 0x87,
  30161. 0x1d, 0x23, 0x62, 0x22, 0x85, 0x92, 0x69, 0x46,
  30162. 0x9c, 0x65, 0xd8, 0xf1, 0x27, 0x32, 0xe4, 0x16,
  30163. 0x7f, 0x9a, 0xba, 0x46, 0x61, 0x60, 0x34, 0xe5,
  30164. 0xc0, 0x14, 0xb5, 0xde, 0x4d, 0xd1, 0x71, 0x39,
  30165. 0x26, 0xdc, 0x0c, 0x0a, 0x53, 0x9e, 0x31, 0x10,
  30166. 0x45, 0x7a, 0xf9, 0xc8, 0xfa, 0x1d, 0x69, 0x5e,
  30167. 0x25, 0xc1, 0xe2, 0x00, 0xbf, 0x94, 0xa3, 0xa2,
  30168. 0x97, 0xca, 0xb4, 0x6a, 0x89, 0x68, 0xdd, 0xed,
  30169. 0x6b, 0x99, 0x5a, 0x87, 0x9e, 0xe9, 0x68, 0xe4,
  30170. 0xf2, 0xc2, 0x7e, 0x37, 0x02, 0xdf, 0x96, 0x1a,
  30171. 0x5b, 0xed, 0xa1, 0xe8, 0xdf, 0x3c, 0xf7, 0xd2,
  30172. 0x25, 0xac, 0xf7, 0x4a, 0x7f, 0x10, 0x27, 0x2b,
  30173. 0x02, 0xc7, 0x95, 0x10, 0x5a, 0xb5, 0xb0, 0xcd,
  30174. 0xa9, 0xe1, 0x36, 0xe2, 0x1c, 0x87, 0x99, 0x0e,
  30175. 0x0a, 0x44, 0xec, 0x97, 0x75, 0xa7, 0x03, 0x27,
  30176. 0x38, 0x3b, 0x16, 0x30, 0x00, 0x98, 0xbe, 0x77,
  30177. 0xfe, 0x3a, 0xac, 0x6f, 0x8f, 0x4d, 0xe1, 0xa9,
  30178. 0x9c, 0xba, 0x39, 0x52, 0xe8, 0xf7, 0xe4, 0xe6,
  30179. 0xf9, 0xe9, 0xb3, 0x57, 0x82, 0xb2, 0x23, 0xd6,
  30180. 0xa5, 0x14, 0xc0, 0x78, 0xb4, 0xa0, 0xf9, 0x96,
  30181. 0xe4, 0x03, 0xe8, 0x6c, 0x27, 0xd8, 0x37, 0x7c,
  30182. 0x8f, 0xf4, 0x80, 0x09, 0x09, 0xc9, 0x32, 0x15,
  30183. 0xe0, 0x3f, 0x37, 0xa7, 0x1a, 0x5f, 0x8c, 0xfb,
  30184. 0xdd, 0xfe, 0x6b, 0x34, 0x28, 0x53, 0x03, 0x4b,
  30185. 0x39, 0x91, 0xf2, 0x48, 0x4c, 0x2a, 0x45, 0xfe,
  30186. 0x66, 0xf7, 0x23, 0x74, 0xb8, 0x30, 0x70, 0xb4,
  30187. 0x0c, 0x2c, 0x65, 0xb1, 0x4e, 0x32, 0x0f, 0x50,
  30188. 0xbb, 0x46, 0x9b, 0x03, 0x34, 0x38, 0xfb, 0xe4,
  30189. 0x25, 0x37, 0x8d, 0x0f, 0xa1, 0x41, 0x50, 0x85,
  30190. 0x92, 0x07, 0x71, 0xff, 0x3c, 0xe6, 0xd9, 0x1d,
  30191. 0x55, 0xb7, 0x10, 0x9c, 0xea, 0x70, 0x5f, 0xa3,
  30192. 0xba, 0x84, 0x99, 0x91, 0x30, 0x3d, 0x4c, 0x98,
  30193. 0x0b, 0x1f, 0x1f, 0xcc, 0x17, 0x94, 0xdd, 0x78,
  30194. 0x7d, 0x50, 0xe5, 0xf5, 0x21, 0x88, 0x5a, 0x52,
  30195. 0x76, 0x5a, 0x97, 0xbe, 0xba, 0xa9, 0xfe, 0x82,
  30196. 0x8a, 0xb5, 0x46, 0xcf, 0x9c, 0xbe, 0xe8, 0x2f,
  30197. 0x01, 0x2f, 0x6a, 0x03, 0x8a, 0xfa, 0x4b, 0x0b,
  30198. 0xdc, 0x78, 0x79, 0x9c, 0x49, 0xc4, 0x01, 0x26,
  30199. 0x16, 0x58, 0xc6, 0xb8, 0xee, 0x6c, 0xc9, 0xa9,
  30200. 0x38, 0x7c, 0xcf, 0xf3, 0xf8, 0xd0, 0x6b, 0x99,
  30201. 0x43, 0x13, 0xe0, 0x43, 0x8e, 0xfb, 0xb2, 0xdb,
  30202. 0x61, 0x67, 0xf4, 0xfc, 0x01, 0x21, 0xd9, 0xb1,
  30203. 0x1e, 0x6c, 0x6f, 0x2a, 0x9a, 0x4b, 0x86, 0x3c,
  30204. 0x62, 0x03, 0x53, 0x83, 0x11, 0x18, 0x1a, 0x59,
  30205. 0x9e, 0x25, 0xfe, 0xdb, 0x85, 0xd0, 0xee, 0x7c,
  30206. 0x97, 0x72, 0xca, 0xf3, 0x0d, 0xd4, 0x19, 0x66,
  30207. 0x14, 0xaf, 0x46, 0x68, 0x75, 0xdb, 0x8f, 0x5f,
  30208. 0x77, 0x7f, 0xfe, 0xa9, 0xe6, 0xa1, 0x9e, 0x46,
  30209. 0x5e, 0x92, 0xda, 0xea, 0xdd, 0x89, 0x01, 0xd9,
  30210. 0xab, 0x25, 0x7d, 0xb4, 0x64, 0x50, 0x8f, 0xa3,
  30211. 0xbe, 0xe2, 0x03, 0xd5, 0xc6, 0x9c, 0xc2, 0xf8,
  30212. 0xac, 0xa4, 0x36, 0xa9, 0x37, 0x10, 0x59, 0x00,
  30213. 0x45, 0xbb, 0x55, 0x33, 0xb9, 0x6f, 0xbc, 0xa2,
  30214. 0x02, 0x9e, 0xa3, 0x1d, 0xf4, 0x17, 0x78, 0x9b,
  30215. 0xbc, 0x42, 0x4e, 0x21, 0xc3, 0xde, 0xb5, 0x70,
  30216. 0x4a, 0x23, 0x1e, 0xd4, 0x36, 0x5d, 0x7a, 0x08,
  30217. 0x37, 0x55, 0x98, 0x07, 0xa0, 0x16, 0xa3, 0x4e,
  30218. 0xa1, 0x2b, 0x96, 0x8b, 0x51, 0x63, 0x48, 0xab,
  30219. 0xc9, 0x19, 0x6f, 0x5f, 0x25, 0x9d, 0xe7, 0x25,
  30220. 0x63, 0xf0, 0x8e, 0xdb, 0x06, 0x2d, 0x42, 0x31,
  30221. 0xfd, 0x14, 0x2b, 0x7a, 0x31, 0x43, 0x04, 0xd5,
  30222. 0xe2, 0x89, 0x2e, 0xa8, 0xe4, 0x6e, 0xd5, 0xa5,
  30223. 0x21, 0x67, 0x9b, 0x92, 0x61, 0x79, 0xdd, 0xe5,
  30224. 0x44, 0x43, 0x45, 0x57, 0x13, 0xec, 0x04, 0xc1,
  30225. 0x41, 0xa3, 0x14, 0x70, 0x86, 0xda, 0x76, 0x5d,
  30226. 0xe8, 0x61, 0xd2, 0xfb, 0x7b, 0xe4, 0x71, 0x46,
  30227. 0xa3, 0x52, 0xbf, 0xf2, 0xa0, 0x3c, 0xc1, 0x90,
  30228. 0x0c, 0x2e, 0xeb, 0xb3, 0x38, 0xae, 0x13, 0x27,
  30229. 0x84, 0xe9, 0x7a, 0xd6, 0x02, 0x40, 0x84, 0xff,
  30230. 0x87, 0x1f, 0x37, 0x44, 0xd8, 0x2e, 0x93, 0xf7,
  30231. 0x0a, 0xff, 0x5b, 0x4d, 0x07, 0x82, 0xfd, 0x6e,
  30232. 0x44, 0xcc, 0x19, 0xc3, 0x7d, 0x7c, 0x31, 0xf9,
  30233. 0x0e, 0xa8, 0x1c, 0x0d, 0xcb, 0x8e, 0xe8, 0x33,
  30234. 0xb2, 0xff, 0x9e, 0x1d, 0x99, 0x7c, 0x46, 0x5b,
  30235. 0xc7, 0x28, 0xec, 0x01, 0x62, 0x82, 0xfe, 0x2a,
  30236. 0x22, 0xa3, 0x86, 0x4e, 0x47, 0xe2, 0x57, 0xf1,
  30237. 0xb4, 0x58, 0x94, 0x89, 0xe5, 0xf1, 0xcd, 0x4d,
  30238. 0x90, 0xd1, 0xa4, 0x4c, 0x34, 0x5d, 0xde, 0xdc,
  30239. 0x39, 0x63, 0x8b, 0x85, 0xfd, 0x02, 0x21, 0xf1,
  30240. 0x12, 0xa3, 0x6d, 0x65, 0x0f, 0x8d, 0xe5, 0xcd,
  30241. 0x70, 0xd5, 0x1d, 0xf8, 0x65, 0x99, 0xfb, 0xe8,
  30242. 0xb5, 0x5a, 0x09, 0x39, 0x9e, 0x09, 0x45, 0x62,
  30243. 0x22, 0x1d, 0xa2, 0x46, 0xbf, 0x75, 0x20, 0xd1,
  30244. 0xe7, 0xb0, 0x06, 0x68, 0xc3, 0x50, 0x48, 0xfc,
  30245. 0xf8, 0x5c, 0x67, 0x69, 0x68, 0x66, 0xb6, 0x81,
  30246. 0x95, 0x91, 0x81, 0x3d, 0xf6, 0x34, 0xd9, 0x4b,
  30247. 0x06, 0x35, 0x17, 0x59, 0x89, 0x18, 0x74, 0x32,
  30248. 0x50, 0xcf, 0x81, 0x16, 0x8e, 0x53, 0x9d, 0x1c,
  30249. 0xad, 0x2d, 0x8e, 0x16, 0x41, 0xda, 0xca, 0xab,
  30250. 0x78, 0x0d, 0xc9, 0x49, 0x61, 0xaa, 0x18, 0xf4,
  30251. 0x56, 0x48, 0x29, 0x8c, 0xe3, 0x9a, 0x7d, 0x58,
  30252. 0xf8, 0x99, 0x72, 0xf1, 0x78, 0xa8, 0x5a, 0x97,
  30253. 0xe3, 0x2a, 0xc6, 0xa9, 0x59, 0xde, 0xcc, 0x62,
  30254. 0xfb, 0xab, 0xc5, 0x9a, 0x0b, 0xc7, 0x16, 0x8f,
  30255. 0x18, 0x20, 0x6e, 0x01, 0x7e, 0x04, 0xef, 0x72,
  30256. 0x83, 0x61, 0xb8, 0x1a, 0x77, 0x0f, 0xd1, 0xa9,
  30257. 0x75, 0xe0, 0x4a, 0x11, 0x69, 0x9d, 0xb6, 0xc9,
  30258. 0x2e, 0xd3, 0xbf, 0xe2, 0x5b, 0x24, 0x77, 0x30,
  30259. 0x85, 0x91, 0xef, 0xa8, 0x93, 0x4e, 0xad, 0x99,
  30260. 0xad, 0xcb, 0x6d, 0x9d, 0x8f, 0xd8, 0x0f, 0xe5,
  30261. 0x41, 0xd9, 0x9e, 0x0b, 0xce, 0x33, 0xd9, 0xbb,
  30262. 0x87, 0x66, 0x2c, 0xa3, 0x0b, 0x68, 0x1b, 0xb0,
  30263. 0x71, 0x30, 0xfa, 0x15, 0x2e, 0xe8, 0xc1, 0x99,
  30264. 0x71, 0x01, 0xcc, 0xdb, 0x6f, 0x9f, 0x8a, 0xfd,
  30265. 0xb4, 0x0f, 0x35, 0xa1, 0x36, 0xf4, 0x3a, 0xc4,
  30266. 0x17, 0x77, 0x43, 0x60, 0x10, 0x18, 0xb4, 0xc2,
  30267. 0xe5, 0xc0, 0x64, 0xd8, 0x38, 0x7c, 0x05, 0x9a,
  30268. 0xfb, 0x2b, 0xb3, 0x9b, 0x9e, 0x34, 0x6b, 0x4b,
  30269. 0xc8, 0x3b, 0x77, 0xe0, 0x6f, 0x08, 0xa1, 0x7b,
  30270. 0x66, 0x69, 0x2f, 0xdb, 0x34, 0x9e, 0x98, 0x90,
  30271. 0x5b, 0x4d, 0x7b, 0xa2, 0x32, 0x8e, 0x64, 0xe6,
  30272. 0x0d, 0x75, 0xc9, 0x96, 0xe3, 0x57, 0xba, 0xad,
  30273. 0x3e, 0x3b, 0x23, 0xfb, 0x9e, 0x7f, 0xc0, 0x3c,
  30274. 0xd5, 0x41, 0x9c, 0xfb, 0xbc, 0xb3, 0x52, 0x49
  30275. #endif
  30276. };
  30277. #endif
  30278. static int test_wc_dilithium_public_der_decode(void)
  30279. {
  30280. EXPECT_DECLS;
  30281. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  30282. defined(WOLFSSL_DILITHIUM_PUBLIC_KEY)
  30283. dilithium_key* key;
  30284. word32 idx = 0;
  30285. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  30286. ExpectNotNull(key);
  30287. if (key != NULL) {
  30288. XMEMSET(key, 0, sizeof(*key));
  30289. }
  30290. ExpectIntEQ(wc_dilithium_init(key), 0);
  30291. #ifndef WOLFSSL_NO_ML_DSA_44
  30292. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  30293. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  30294. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  30295. #else
  30296. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  30297. #endif
  30298. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(dilithium_public_der, &idx, key,
  30299. (word32)sizeof(dilithium_public_der)), 0);
  30300. wc_dilithium_free(key);
  30301. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  30302. #endif
  30303. return EXPECT_RESULT();
  30304. }
  30305. static int test_wc_dilithium_der(void)
  30306. {
  30307. EXPECT_DECLS;
  30308. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  30309. !defined(WOLFSSL_DILITHIUM_NO_ASN1) && \
  30310. !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY)
  30311. #define DILITHIUM_MAX_DER_SIZE 8192
  30312. dilithium_key* key;
  30313. WC_RNG rng;
  30314. byte* der = NULL;
  30315. int len;
  30316. int pubLen;
  30317. int pubDerLen;
  30318. int privDerLen;
  30319. int keyDerLen;
  30320. word32 idx;
  30321. #ifndef WOLFSSL_NO_ML_DSA_44
  30322. pubLen = DILITHIUM_LEVEL2_PUB_KEY_SIZE;
  30323. pubDerLen = DILITHIUM_LEVEL2_PUB_KEY_SIZE + 24;
  30324. privDerLen = DILITHIUM_LEVEL2_KEY_SIZE + 30;
  30325. keyDerLen = DILITHIUM_LEVEL2_PUB_KEY_SIZE + DILITHIUM_LEVEL2_KEY_SIZE + 34;
  30326. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  30327. pubLen = DILITHIUM_LEVEL3_PUB_KEY_SIZE;
  30328. pubDerLen = DILITHIUM_LEVEL3_PUB_KEY_SIZE + 24;
  30329. privDerLen = DILITHIUM_LEVEL3_KEY_SIZE + 30;
  30330. keyDerLen = DILITHIUM_LEVEL3_PUB_KEY_SIZE + DILITHIUM_LEVEL3_KEY_SIZE + 34;
  30331. #else
  30332. pubLen = DILITHIUM_LEVEL5_PUB_KEY_SIZE;
  30333. pubDerLen = DILITHIUM_LEVEL5_PUB_KEY_SIZE + 24;
  30334. privDerLen = DILITHIUM_LEVEL5_KEY_SIZE + 30;
  30335. keyDerLen = DILITHIUM_LEVEL5_PUB_KEY_SIZE + DILITHIUM_LEVEL5_KEY_SIZE + 34;
  30336. #endif
  30337. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  30338. ExpectNotNull(key);
  30339. der = (byte*)XMALLOC(DILITHIUM_MAX_DER_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  30340. ExpectNotNull(der);
  30341. if (key != NULL) {
  30342. XMEMSET(key, 0, sizeof(*key));
  30343. }
  30344. XMEMSET(&rng, 0, sizeof(WC_RNG));
  30345. ExpectIntEQ(wc_InitRng(&rng), 0);
  30346. ExpectIntEQ(wc_dilithium_init(key), 0);
  30347. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE,
  30348. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30349. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE,
  30350. 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30351. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE),
  30352. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30353. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der, &idx, key, pubDerLen),
  30354. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30355. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der, &idx, key, privDerLen),
  30356. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30357. #ifndef WOLFSSL_NO_ML_DSA_44
  30358. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  30359. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  30360. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  30361. #else
  30362. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  30363. #endif
  30364. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE,
  30365. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30366. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE,
  30367. 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30368. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE),
  30369. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30370. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  30371. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(NULL, NULL, 0 ,
  30372. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30373. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(NULL, der , 0 ,
  30374. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30375. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(NULL, NULL, DILITHIUM_MAX_DER_SIZE,
  30376. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30377. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(NULL, der , DILITHIUM_MAX_DER_SIZE,
  30378. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30379. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key , der , 0 ,
  30380. 0), WC_NO_ERR_TRACE(BUFFER_E));
  30381. /* Get length only. */
  30382. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key , NULL, 0 ,
  30383. 0), pubLen);
  30384. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key , NULL, DILITHIUM_MAX_DER_SIZE,
  30385. 0), pubLen);
  30386. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key , NULL, 0 ,
  30387. 1), pubDerLen);
  30388. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key , NULL, DILITHIUM_MAX_DER_SIZE,
  30389. 1), pubDerLen);
  30390. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(NULL, NULL,
  30391. 0 ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30392. ExpectIntGT(wc_Dilithium_PrivateKeyToDer(key , NULL,
  30393. 0 ), 0);
  30394. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(NULL, der ,
  30395. 0 ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30396. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(NULL, NULL,
  30397. DILITHIUM_MAX_DER_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30398. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(NULL, der ,
  30399. DILITHIUM_MAX_DER_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30400. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(key , der ,
  30401. 0 ), WC_NO_ERR_TRACE(BUFFER_E));
  30402. /* Get length only. */
  30403. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(key , NULL,
  30404. DILITHIUM_MAX_DER_SIZE), privDerLen);
  30405. ExpectIntEQ(wc_Dilithium_KeyToDer(NULL, NULL, 0 ),
  30406. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30407. ExpectIntGT(wc_Dilithium_KeyToDer(key , NULL, 0 ),
  30408. 0 );
  30409. ExpectIntEQ(wc_Dilithium_KeyToDer(NULL, der , 0 ),
  30410. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30411. ExpectIntEQ(wc_Dilithium_KeyToDer(NULL, NULL, DILITHIUM_MAX_DER_SIZE),
  30412. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30413. ExpectIntEQ(wc_Dilithium_KeyToDer(NULL, der , DILITHIUM_MAX_DER_SIZE),
  30414. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30415. ExpectIntEQ(wc_Dilithium_KeyToDer(key , der , 0 ),
  30416. WC_NO_ERR_TRACE(BUFFER_E));
  30417. /* Get length only. */
  30418. ExpectIntEQ(wc_Dilithium_KeyToDer(key , NULL, DILITHIUM_MAX_DER_SIZE),
  30419. keyDerLen);
  30420. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(NULL, NULL, NULL, 0 ),
  30421. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30422. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der , NULL, NULL, 0 ),
  30423. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30424. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(NULL, &idx, NULL, 0 ),
  30425. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30426. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(NULL, NULL, key , 0 ),
  30427. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30428. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(NULL, NULL, NULL, pubDerLen),
  30429. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30430. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(NULL, &idx, key , pubDerLen),
  30431. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30432. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der , NULL, key , pubDerLen),
  30433. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30434. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der , &idx, NULL, pubDerLen),
  30435. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30436. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der , &idx, key , 0 ),
  30437. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30438. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(NULL, NULL, NULL, 0 ),
  30439. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30440. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der , NULL, NULL, 0 ),
  30441. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30442. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(NULL, &idx, NULL, 0 ),
  30443. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30444. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(NULL, NULL, key , 0 ),
  30445. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30446. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(NULL, NULL, NULL, privDerLen),
  30447. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30448. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(NULL, &idx, key , privDerLen),
  30449. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30450. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der , NULL, key , privDerLen),
  30451. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30452. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der , &idx, NULL, privDerLen),
  30453. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30454. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der , &idx, key , 0 ),
  30455. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  30456. ExpectIntEQ(len = wc_Dilithium_PublicKeyToDer(key, der,
  30457. DILITHIUM_MAX_DER_SIZE, 0), pubLen);
  30458. ExpectIntEQ(wc_dilithium_import_public(der, len, key), 0);
  30459. ExpectIntEQ(len = wc_Dilithium_PublicKeyToDer(key, der,
  30460. DILITHIUM_MAX_DER_SIZE, 1), pubDerLen);
  30461. idx = 0;
  30462. {
  30463. fprintf(stderr, "\n");
  30464. for (int ii = 0; ii < pubDerLen; ii++) {
  30465. if ((ii % 8) == 0) fprintf(stderr, " ");
  30466. fprintf(stderr, "0x%02x,", der[ii]);
  30467. if ((ii % 8) == 7) fprintf(stderr, "\n");
  30468. else fprintf(stderr, " ");
  30469. }
  30470. }
  30471. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der, &idx, key, len), 0);
  30472. ExpectIntEQ(len = wc_Dilithium_PrivateKeyToDer(key, der,
  30473. DILITHIUM_MAX_DER_SIZE), privDerLen);
  30474. idx = 0;
  30475. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der, &idx, key, len), 0);
  30476. ExpectIntEQ(len = wc_Dilithium_KeyToDer(key, der, DILITHIUM_MAX_DER_SIZE),
  30477. keyDerLen);
  30478. idx = 0;
  30479. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der, &idx, key, len), 0);
  30480. wc_dilithium_free(key);
  30481. wc_FreeRng(&rng);
  30482. XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  30483. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  30484. #endif
  30485. return EXPECT_RESULT();
  30486. }
  30487. static int test_wc_dilithium_make_key_from_seed(void)
  30488. {
  30489. EXPECT_DECLS;
  30490. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  30491. !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY)
  30492. dilithium_key* key;
  30493. #ifndef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  30494. #ifndef WOLFSSL_NO_ML_DSA_44
  30495. static const byte seed_44[] = {
  30496. 0x93, 0xEF, 0x2E, 0x6E, 0xF1, 0xFB, 0x08, 0x99,
  30497. 0x9D, 0x14, 0x2A, 0xBE, 0x02, 0x95, 0x48, 0x23,
  30498. 0x70, 0xD3, 0xF4, 0x3B, 0xDB, 0x25, 0x4A, 0x78,
  30499. 0xE2, 0xB0, 0xD5, 0x16, 0x8E, 0xCA, 0x06, 0x5F
  30500. };
  30501. static const byte pk_44[] = {
  30502. 0xBC, 0x5F, 0xF8, 0x10, 0xEB, 0x08, 0x90, 0x48,
  30503. 0xB8, 0xAB, 0x30, 0x20, 0xA7, 0xBD, 0x3B, 0x16,
  30504. 0xC0, 0xE0, 0xCA, 0x3D, 0x6B, 0x97, 0xE4, 0x64,
  30505. 0x6C, 0x2C, 0xCA, 0xE0, 0xBB, 0xF1, 0x9E, 0xF7,
  30506. 0x23, 0x0A, 0x19, 0xD7, 0x5A, 0xDB, 0xDE, 0xD5,
  30507. 0x2D, 0xB8, 0x55, 0xE2, 0x52, 0xA7, 0x19, 0xFC,
  30508. 0xBD, 0x14, 0x7B, 0xA6, 0x7B, 0x2F, 0xAD, 0x14,
  30509. 0xED, 0x0E, 0x68, 0xFD, 0xFE, 0x8C, 0x65, 0xBA,
  30510. 0xDE, 0xAC, 0xB0, 0x91, 0x11, 0x93, 0xAD, 0xFA,
  30511. 0x87, 0x94, 0xD7, 0x8F, 0x8E, 0x3D, 0x66, 0x2A,
  30512. 0x1C, 0x49, 0xDA, 0x81, 0x9F, 0xD9, 0x59, 0xE7,
  30513. 0xF0, 0x78, 0xF2, 0x03, 0xC4, 0x56, 0xF8, 0xB6,
  30514. 0xE7, 0xC9, 0x41, 0x58, 0x98, 0xE5, 0x41, 0xC7,
  30515. 0x30, 0x32, 0xDB, 0xD6, 0x19, 0xEA, 0xF6, 0x0F,
  30516. 0x8D, 0x64, 0xF8, 0x68, 0x3D, 0xA9, 0x9E, 0xCA,
  30517. 0x51, 0x22, 0x0B, 0x0A, 0xCA, 0x28, 0x46, 0x40,
  30518. 0x99, 0xF5, 0x47, 0xC0, 0x27, 0x77, 0xBD, 0x37,
  30519. 0xD8, 0x4A, 0x59, 0xBD, 0x37, 0xED, 0x7A, 0x8A,
  30520. 0x92, 0x63, 0x3C, 0x75, 0xD0, 0x7C, 0x79, 0x3F,
  30521. 0xE7, 0x25, 0x2B, 0x58, 0x4A, 0xBF, 0x6A, 0x15,
  30522. 0xEE, 0x14, 0x50, 0x7E, 0x5E, 0x19, 0x3F, 0x89,
  30523. 0x86, 0x4D, 0x09, 0xAC, 0x87, 0x27, 0xA6, 0xD0,
  30524. 0x42, 0x1F, 0x0C, 0x19, 0xF0, 0xE2, 0xFB, 0xFC,
  30525. 0x21, 0x3D, 0x3F, 0xBD, 0x70, 0xF4, 0xF9, 0x76,
  30526. 0x2C, 0xEC, 0xFF, 0x23, 0x1E, 0x9C, 0x8A, 0x76,
  30527. 0x28, 0xD3, 0xF8, 0xB0, 0x85, 0x7B, 0x03, 0x2D,
  30528. 0x32, 0xDE, 0x62, 0xFF, 0x8E, 0xCB, 0xF4, 0x00,
  30529. 0x82, 0x89, 0xBF, 0x34, 0x40, 0x36, 0x65, 0xF8,
  30530. 0x1A, 0x08, 0x1A, 0xD5, 0xA8, 0x5A, 0x28, 0x2F,
  30531. 0x99, 0xBA, 0xB9, 0xE5, 0x38, 0x5A, 0xFB, 0xCC,
  30532. 0xCF, 0x44, 0xB7, 0x4C, 0x01, 0x96, 0xC7, 0x54,
  30533. 0x55, 0x27, 0xEC, 0x30, 0x26, 0xDA, 0x12, 0x80,
  30534. 0xC4, 0xEB, 0x37, 0xD0, 0x9C, 0xFE, 0x3E, 0xC4,
  30535. 0xB4, 0x91, 0x0B, 0x62, 0xEB, 0x98, 0x15, 0xA4,
  30536. 0x25, 0xC6, 0x59, 0x0F, 0xC4, 0xAD, 0x3F, 0xBB,
  30537. 0x22, 0x57, 0x52, 0xCC, 0x1F, 0xC5, 0x69, 0x3F,
  30538. 0x18, 0x7E, 0x7D, 0xEC, 0x4E, 0xEF, 0xBE, 0xB6,
  30539. 0xB9, 0x1B, 0xD9, 0x1C, 0x5E, 0x2E, 0xA6, 0xA9,
  30540. 0x1D, 0x14, 0xD0, 0x97, 0xBE, 0x20, 0x3F, 0xBA,
  30541. 0x0B, 0xF9, 0x37, 0xC9, 0x75, 0x07, 0xDC, 0x00,
  30542. 0x7C, 0x4C, 0xAA, 0x9B, 0x07, 0x85, 0x89, 0x29,
  30543. 0x66, 0xFF, 0x15, 0x90, 0x09, 0x24, 0xE5, 0x79,
  30544. 0xD4, 0xFB, 0xA0, 0x2B, 0xDA, 0x87, 0x55, 0x5F,
  30545. 0x07, 0x3D, 0xAE, 0x00, 0x51, 0x3E, 0x70, 0x80,
  30546. 0x9A, 0xBB, 0xC7, 0x11, 0xFB, 0xA2, 0xE7, 0x64,
  30547. 0x95, 0x77, 0xC4, 0x2A, 0xFD, 0xC2, 0x4B, 0xF7,
  30548. 0x41, 0x3E, 0x51, 0x26, 0x8A, 0xD6, 0xDB, 0x61,
  30549. 0x13, 0xB7, 0xD9, 0x19, 0x1A, 0xF9, 0xD0, 0x61,
  30550. 0xDB, 0xDE, 0xD5, 0xD6, 0x30, 0x87, 0x76, 0x50,
  30551. 0xC1, 0x24, 0xF1, 0x1B, 0xC4, 0xBD, 0xC3, 0xFD,
  30552. 0xC6, 0xA9, 0x00, 0xF6, 0x31, 0x26, 0xF9, 0x21,
  30553. 0xE8, 0x38, 0xAD, 0x0C, 0x22, 0x75, 0xA3, 0x38,
  30554. 0x9A, 0x39, 0xBD, 0x99, 0xA1, 0x34, 0x50, 0x45,
  30555. 0x50, 0x10, 0x1C, 0xD3, 0xE9, 0x5E, 0x6D, 0x14,
  30556. 0x96, 0xBE, 0x7D, 0xE6, 0x62, 0x7D, 0xF4, 0xFD,
  30557. 0x6C, 0x28, 0xBB, 0xF4, 0x0B, 0x30, 0xEF, 0xA9,
  30558. 0xB5, 0xC3, 0xD5, 0xC8, 0x5A, 0xB1, 0x4A, 0x65,
  30559. 0xC0, 0x2D, 0x6D, 0x47, 0x81, 0xFF, 0x13, 0xD3,
  30560. 0x28, 0x60, 0x85, 0x54, 0xB6, 0xD1, 0x5E, 0xD9,
  30561. 0x12, 0x89, 0xA6, 0xD5, 0x5A, 0xAC, 0x0C, 0x38,
  30562. 0xE3, 0x77, 0x06, 0xF7, 0x35, 0x5E, 0x9A, 0x4F,
  30563. 0xDA, 0x61, 0x5B, 0x87, 0x59, 0x26, 0xBF, 0xE5,
  30564. 0xA5, 0x9D, 0x9E, 0xF2, 0x73, 0xBF, 0x94, 0xA0,
  30565. 0x7C, 0xFA, 0x57, 0x31, 0x78, 0xF0, 0xE0, 0x04,
  30566. 0xB6, 0xE1, 0xEF, 0x0A, 0x83, 0x49, 0xE9, 0xBC,
  30567. 0xC0, 0x19, 0x81, 0xF2, 0x46, 0x0F, 0x0A, 0x27,
  30568. 0x43, 0xC2, 0x8D, 0x1E, 0x13, 0x8F, 0xFB, 0x76,
  30569. 0x5E, 0x7E, 0x33, 0x97, 0xB7, 0x91, 0x33, 0x35,
  30570. 0xD4, 0x02, 0xFE, 0x91, 0x80, 0x6A, 0xA8, 0xFC,
  30571. 0x81, 0x92, 0x53, 0xAF, 0x32, 0x69, 0x2F, 0xA6,
  30572. 0x51, 0xE8, 0x67, 0xF5, 0x90, 0x7E, 0xF4, 0x6F,
  30573. 0x00, 0x62, 0x5A, 0x03, 0x0E, 0xC9, 0x04, 0xED,
  30574. 0xAB, 0x21, 0x42, 0x6D, 0x59, 0x11, 0x9D, 0x2C,
  30575. 0xAA, 0x43, 0xBD, 0x93, 0x5D, 0xEC, 0x0A, 0x55,
  30576. 0x0C, 0x61, 0xEE, 0x4B, 0x27, 0x9C, 0x1C, 0xA3,
  30577. 0xA7, 0x9C, 0x79, 0xA6, 0x6E, 0x3F, 0x2D, 0x2F,
  30578. 0xAD, 0xB0, 0x0F, 0x59, 0xA3, 0xA4, 0x38, 0xAA,
  30579. 0x44, 0x57, 0x01, 0x06, 0x07, 0x30, 0x17, 0xFA,
  30580. 0x1C, 0x87, 0x57, 0x50, 0x01, 0x09, 0x72, 0x0D,
  30581. 0x12, 0x5B, 0xBA, 0x23, 0x1A, 0x0C, 0x36, 0x35,
  30582. 0x0C, 0x78, 0x08, 0x6D, 0xFD, 0xC8, 0xD6, 0x13,
  30583. 0xAE, 0xCA, 0x88, 0xC4, 0xCC, 0xAE, 0xB4, 0xA4,
  30584. 0x4D, 0x13, 0xAD, 0xB3, 0xC7, 0x17, 0xD6, 0x5C,
  30585. 0x82, 0xA3, 0x51, 0xB9, 0xB6, 0xEA, 0xBF, 0x6A,
  30586. 0x10, 0xF4, 0xB4, 0xE9, 0x62, 0x3E, 0x3A, 0x95,
  30587. 0xB4, 0xD4, 0x0A, 0x12, 0xA8, 0x18, 0xAC, 0x6B,
  30588. 0x38, 0x22, 0xDB, 0x82, 0xFB, 0x05, 0xDC, 0x42,
  30589. 0x02, 0x64, 0x8B, 0x44, 0x54, 0x68, 0x9A, 0xEB,
  30590. 0x69, 0xEA, 0x32, 0x5F, 0x03, 0xE3, 0x5D, 0xEF,
  30591. 0xA5, 0x47, 0x08, 0x48, 0x14, 0x20, 0xC6, 0xD6,
  30592. 0x97, 0xBB, 0x91, 0x2F, 0xCA, 0x0D, 0x3F, 0x19,
  30593. 0x2E, 0xF2, 0x97, 0xDF, 0xE7, 0x7F, 0xF3, 0x6B,
  30594. 0x21, 0x03, 0xF1, 0xAD, 0x1A, 0xEE, 0xCE, 0xD1,
  30595. 0xC8, 0x14, 0xC2, 0xCD, 0x7E, 0xF1, 0x6B, 0xCE,
  30596. 0x47, 0x6A, 0xD0, 0x4F, 0x94, 0x1A, 0xFC, 0x79,
  30597. 0xE3, 0x29, 0x54, 0x74, 0xA4, 0x10, 0x62, 0x51,
  30598. 0x8C, 0x00, 0x37, 0x86, 0x09, 0x34, 0xF0, 0xE5,
  30599. 0xE6, 0x52, 0xF7, 0x27, 0x49, 0xA6, 0x98, 0x63,
  30600. 0x2A, 0x09, 0x91, 0xF6, 0x13, 0xF5, 0xCB, 0x96,
  30601. 0xCA, 0x11, 0x78, 0xF9, 0x74, 0xF2, 0xC4, 0xAA,
  30602. 0x0C, 0xE6, 0x3D, 0xC2, 0x4E, 0x36, 0x4C, 0x92,
  30603. 0xA6, 0x43, 0xB9, 0x0A, 0x5F, 0x85, 0xA6, 0x2F,
  30604. 0xD4, 0xD8, 0xD2, 0xB1, 0x93, 0xD2, 0x9B, 0x18,
  30605. 0xBE, 0xDE, 0x26, 0x53, 0xFC, 0x5D, 0x3F, 0x24,
  30606. 0xF5, 0xB2, 0xC0, 0x18, 0xDB, 0xBC, 0xB6, 0xEF,
  30607. 0x00, 0xF3, 0x05, 0xBF, 0x93, 0x66, 0x6B, 0xD4,
  30608. 0x7F, 0xEA, 0x91, 0x93, 0xBC, 0x23, 0x3D, 0xB3,
  30609. 0x91, 0x21, 0x44, 0x2E, 0x93, 0x8D, 0xA5, 0xDD,
  30610. 0x07, 0xEE, 0x6E, 0x87, 0x9C, 0x5B, 0x9D, 0xFF,
  30611. 0x41, 0xEC, 0xEE, 0x5E, 0x05, 0x89, 0xAE, 0x61,
  30612. 0x75, 0xFF, 0x5E, 0xC6, 0xF6, 0xD2, 0x62, 0x9F,
  30613. 0x56, 0xB1, 0x8B, 0x4D, 0xE6, 0x6F, 0xCB, 0x13,
  30614. 0xDF, 0x04, 0x00, 0xA7, 0x97, 0xC9, 0x22, 0x70,
  30615. 0xF6, 0x9B, 0xDE, 0xBD, 0xDC, 0xB8, 0x8C, 0x42,
  30616. 0x48, 0x91, 0x9B, 0x56, 0xCD, 0xA7, 0x0B, 0x8A,
  30617. 0xC4, 0xF9, 0x42, 0x9C, 0x29, 0x2D, 0xA9, 0x4D,
  30618. 0x64, 0x78, 0x28, 0x07, 0x64, 0xFE, 0x23, 0x86,
  30619. 0xFC, 0x38, 0xCB, 0x09, 0x31, 0x45, 0x88, 0x39,
  30620. 0xEF, 0x4E, 0x7D, 0xE8, 0xF0, 0x68, 0x9D, 0x99,
  30621. 0x80, 0x59, 0x88, 0xC7, 0xF9, 0x61, 0x11, 0x85,
  30622. 0x2C, 0x89, 0x29, 0xE5, 0xA5, 0x40, 0xD3, 0xB7,
  30623. 0x8D, 0x71, 0x2D, 0xEC, 0xC3, 0x96, 0xFE, 0xF3,
  30624. 0xEC, 0x34, 0x40, 0x21, 0x84, 0xE4, 0xFD, 0x29,
  30625. 0xF3, 0x63, 0xEA, 0x80, 0xF6, 0xFC, 0x50, 0xBA,
  30626. 0x9A, 0x11, 0x35, 0x1A, 0xCE, 0xEA, 0x8F, 0xE6,
  30627. 0x8D, 0x54, 0x1E, 0x1A, 0xA5, 0x84, 0x8D, 0x9F,
  30628. 0x6E, 0x61, 0xDF, 0xB6, 0x2B, 0x2F, 0x23, 0xBC,
  30629. 0x50, 0x81, 0xE8, 0x2F, 0x76, 0x22, 0x6E, 0x03,
  30630. 0x28, 0x49, 0x82, 0xEC, 0x48, 0x48, 0x12, 0x09,
  30631. 0xB1, 0xA7, 0xD4, 0xC8, 0x79, 0x7E, 0x44, 0xBF,
  30632. 0xA8, 0x70, 0xB2, 0x20, 0x04, 0xDB, 0x74, 0xBD,
  30633. 0x7D, 0x47, 0x8D, 0x5B, 0x36, 0x14, 0xD2, 0xB1,
  30634. 0xDA, 0x75, 0x02, 0xB3, 0x98, 0xEB, 0x9D, 0xA8,
  30635. 0x0D, 0x06, 0x46, 0x1E, 0x90, 0xE0, 0x30, 0x60,
  30636. 0x44, 0x6A, 0xB4, 0xA8, 0x23, 0x84, 0x32, 0xBF,
  30637. 0xAF, 0x75, 0x2F, 0x39, 0x17, 0x91, 0x21, 0x4F,
  30638. 0x1E, 0x6B, 0x63, 0x59, 0x0D, 0x53, 0x60, 0x60,
  30639. 0xD1, 0xC2, 0x45, 0x30, 0x7B, 0xC5, 0xC1, 0xBA,
  30640. 0xC4, 0xAA, 0xA0, 0x99, 0xD3, 0x6B, 0xB6, 0xDC,
  30641. 0xBC, 0x97, 0x3C, 0xF2, 0xE6, 0x9F, 0x27, 0x34,
  30642. 0xD0, 0xF2, 0x9A, 0xEE, 0xC4, 0x56, 0x7B, 0x99,
  30643. 0xA1, 0x6B, 0xC1, 0x7C, 0x6C, 0xDD, 0xAC, 0xEF,
  30644. 0xE4, 0x99, 0x27, 0xFB, 0x14, 0xE7, 0xD9, 0x8D,
  30645. 0xD4, 0x26, 0x35, 0x19, 0x46, 0x9C, 0xCA, 0x3D,
  30646. 0xB4, 0x67, 0x9A, 0x68, 0xCE, 0xED, 0xA9, 0x55,
  30647. 0x59, 0x22, 0x10, 0xFC, 0x49, 0xAA, 0x5F, 0xBE,
  30648. 0x93, 0x4C, 0xC7, 0x3D, 0x84, 0xE4, 0xBA, 0x54,
  30649. 0x78, 0x00, 0x2D, 0x68, 0x90, 0x98, 0x90, 0x68,
  30650. 0xEF, 0x8F, 0xC9, 0x8C, 0x25, 0x32, 0xB8, 0x3B,
  30651. 0xF3, 0xCB, 0x9E, 0xF0, 0x28, 0x93, 0xC2, 0x15,
  30652. 0x24, 0x26, 0xB9, 0xD1, 0xA9, 0x47, 0x34, 0xDF,
  30653. 0xB4, 0xF9, 0x11, 0x35, 0x14, 0x3C, 0x9E, 0xED,
  30654. 0x18, 0xFD, 0x51, 0xAE, 0x87, 0x5D, 0x07, 0xA2,
  30655. 0x37, 0x75, 0x60, 0x6A, 0x73, 0x4F, 0xBA, 0x98,
  30656. 0xC0, 0x63, 0xB4, 0xA1, 0x62, 0x2E, 0x7F, 0xF2,
  30657. 0x1A, 0xA7, 0xE6, 0x52, 0xA3, 0xD6, 0xC1, 0x9F,
  30658. 0xE0, 0xDC, 0x67, 0x61, 0xB7, 0xD3, 0x53, 0x02,
  30659. 0xBF, 0x21, 0x4D, 0x30, 0x79, 0xF7, 0x60, 0x51,
  30660. 0x08, 0x2A, 0x87, 0x59, 0x29, 0x92, 0x0D, 0xC3,
  30661. 0xB3, 0xCB, 0x43, 0x21, 0x1A, 0x23, 0xA4, 0x3A,
  30662. 0x50, 0x33, 0x2F, 0xAF, 0x1A, 0xC2, 0x19, 0x1E,
  30663. 0x71, 0x71, 0x25, 0xF6, 0x3E, 0x25, 0x86, 0xC4,
  30664. 0xD8, 0x6D, 0xCA, 0x6B, 0xCD, 0x3D, 0x03, 0x8F,
  30665. 0x9D, 0x3A, 0x7B, 0x66, 0xCB, 0xC7, 0xDF, 0x34
  30666. };
  30667. static const byte sk_44[] = {
  30668. 0xBC, 0x5F, 0xF8, 0x10, 0xEB, 0x08, 0x90, 0x48,
  30669. 0xB8, 0xAB, 0x30, 0x20, 0xA7, 0xBD, 0x3B, 0x16,
  30670. 0xC0, 0xE0, 0xCA, 0x3D, 0x6B, 0x97, 0xE4, 0x64,
  30671. 0x6C, 0x2C, 0xCA, 0xE0, 0xBB, 0xF1, 0x9E, 0xF7,
  30672. 0xBA, 0x2B, 0x57, 0xC4, 0x46, 0x55, 0x6E, 0xE2,
  30673. 0xB7, 0x2C, 0x78, 0xB9, 0x6B, 0xB7, 0xA8, 0x50,
  30674. 0x3D, 0xE4, 0x0A, 0xFB, 0x54, 0x18, 0x4E, 0x3B,
  30675. 0x54, 0x63, 0xC2, 0x1A, 0xF7, 0x48, 0x53, 0x23,
  30676. 0xDF, 0x98, 0xF0, 0x16, 0x0A, 0xE5, 0xD1, 0x37,
  30677. 0x51, 0x27, 0x25, 0xF8, 0x9D, 0x56, 0x3B, 0xC9,
  30678. 0xA1, 0x89, 0xD3, 0x1D, 0x20, 0xB3, 0xB3, 0xC8,
  30679. 0xFF, 0xAA, 0xF5, 0xE4, 0x86, 0xE7, 0x90, 0x51,
  30680. 0xF6, 0xF3, 0x60, 0x5C, 0xCA, 0x25, 0x69, 0xFD,
  30681. 0xB4, 0x6B, 0x33, 0x18, 0xD2, 0x38, 0x42, 0xCE,
  30682. 0x40, 0xD6, 0x43, 0x86, 0x13, 0xF6, 0x8B, 0x45,
  30683. 0x5B, 0x0D, 0x3B, 0xCA, 0x0E, 0x05, 0x0D, 0x4D,
  30684. 0x11, 0x99, 0x88, 0xA2, 0xC4, 0x80, 0x1B, 0x90,
  30685. 0x84, 0xE0, 0xB0, 0x48, 0xC9, 0x28, 0x09, 0x22,
  30686. 0x30, 0x90, 0x24, 0x06, 0x49, 0x98, 0x40, 0x65,
  30687. 0x5A, 0x26, 0x8A, 0xDA, 0x32, 0x90, 0xDA, 0x48,
  30688. 0x08, 0x22, 0x81, 0x90, 0xC8, 0x14, 0x61, 0xDC,
  30689. 0x16, 0x6A, 0x21, 0x47, 0x8E, 0x08, 0xB2, 0x21,
  30690. 0xE3, 0x08, 0x68, 0x1A, 0x02, 0x44, 0x14, 0xC6,
  30691. 0x65, 0xE1, 0x98, 0x71, 0x90, 0xC6, 0x69, 0x0C,
  30692. 0x15, 0x44, 0xC9, 0xA0, 0x11, 0xCC, 0x34, 0x71,
  30693. 0x83, 0x40, 0x45, 0x00, 0x12, 0x4D, 0x91, 0x08,
  30694. 0x00, 0x83, 0x36, 0x84, 0x12, 0x85, 0x4C, 0xCC,
  30695. 0x00, 0x41, 0x09, 0x90, 0x70, 0x18, 0x95, 0x00,
  30696. 0xA2, 0xB2, 0x85, 0x94, 0x26, 0x41, 0x0B, 0x00,
  30697. 0x41, 0x0A, 0xB9, 0x80, 0xC0, 0xC6, 0x10, 0x0C,
  30698. 0x33, 0x29, 0xA3, 0xA6, 0x28, 0x1C, 0x26, 0x10,
  30699. 0x1A, 0x37, 0x49, 0x13, 0x35, 0x8A, 0x0B, 0x29,
  30700. 0x2E, 0x82, 0xA2, 0x70, 0x8B, 0x38, 0x49, 0x94,
  30701. 0x04, 0x80, 0x9B, 0x26, 0x10, 0xA4, 0x80, 0x30,
  30702. 0x04, 0x37, 0x0C, 0x48, 0xB2, 0x60, 0x04, 0x17,
  30703. 0x2E, 0x19, 0x49, 0x64, 0xC8, 0xC4, 0x64, 0x1A,
  30704. 0x96, 0x60, 0x10, 0x83, 0x6D, 0x20, 0x38, 0x22,
  30705. 0x49, 0x06, 0x08, 0x1B, 0xB7, 0x20, 0x01, 0x48,
  30706. 0x4D, 0xE1, 0x10, 0x49, 0x08, 0x38, 0x44, 0x4C,
  30707. 0x16, 0x8E, 0x04, 0xB2, 0x2C, 0x09, 0x91, 0x50,
  30708. 0x83, 0x36, 0x06, 0x5C, 0x02, 0x8C, 0x8A, 0x38,
  30709. 0x05, 0x1A, 0xB5, 0x81, 0x82, 0xC0, 0x09, 0x51,
  30710. 0x12, 0x72, 0x22, 0x10, 0x0D, 0x04, 0x08, 0x2A,
  30711. 0xA4, 0x84, 0x10, 0x58, 0x08, 0x52, 0x08, 0x26,
  30712. 0x0A, 0x02, 0xB6, 0x2D, 0x8A, 0x12, 0x0E, 0x14,
  30713. 0x22, 0x10, 0x48, 0x44, 0x0A, 0x14, 0x23, 0x91,
  30714. 0x50, 0x40, 0x90, 0x0A, 0x27, 0x92, 0xA4, 0xB0,
  30715. 0x60, 0x08, 0x84, 0x11, 0xC4, 0x40, 0x22, 0x63,
  30716. 0x46, 0x2A, 0xDA, 0xA6, 0x90, 0xC1, 0xB2, 0x30,
  30717. 0x50, 0x10, 0x00, 0xA0, 0xB4, 0x6C, 0x53, 0xB4,
  30718. 0x50, 0x13, 0x05, 0x8D, 0x02, 0x31, 0x0E, 0x08,
  30719. 0x20, 0x10, 0x91, 0xC8, 0x4C, 0x22, 0xA7, 0x50,
  30720. 0xC2, 0xA6, 0x70, 0x92, 0x46, 0x41, 0x63, 0x16,
  30721. 0x8C, 0x84, 0x00, 0x11, 0x0B, 0x81, 0x90, 0x13,
  30722. 0x83, 0x71, 0x21, 0x85, 0x30, 0x1B, 0x18, 0x46,
  30723. 0xA3, 0x10, 0x84, 0x14, 0x43, 0x40, 0x80, 0x98,
  30724. 0x25, 0x0C, 0x27, 0x2C, 0x94, 0x42, 0x41, 0xA2,
  30725. 0x88, 0x45, 0x02, 0x13, 0x05, 0x44, 0xB6, 0x44,
  30726. 0x52, 0x22, 0x92, 0xD0, 0x80, 0x50, 0x4B, 0xA6,
  30727. 0x04, 0x84, 0x36, 0x70, 0x09, 0xB2, 0x4D, 0x19,
  30728. 0xA8, 0x84, 0x24, 0x93, 0x49, 0x94, 0xA2, 0x80,
  30729. 0x49, 0xB4, 0x48, 0x91, 0x28, 0x64, 0xA1, 0xC8,
  30730. 0x65, 0x4B, 0x82, 0x85, 0x93, 0x30, 0x06, 0x63,
  30731. 0x12, 0x66, 0x10, 0x37, 0x01, 0x4A, 0x40, 0x80,
  30732. 0x18, 0x18, 0x90, 0x44, 0xC4, 0x0D, 0x4B, 0x28,
  30733. 0x81, 0xA2, 0x06, 0x40, 0xD4, 0x30, 0x2C, 0x1B,
  30734. 0x96, 0x4C, 0xE1, 0xB2, 0x60, 0x44, 0x28, 0x41,
  30735. 0xD8, 0x30, 0x65, 0x24, 0x09, 0x04, 0x64, 0x00,
  30736. 0x89, 0x63, 0xC2, 0x24, 0xC0, 0x00, 0x49, 0x92,
  30737. 0x16, 0x52, 0x23, 0xC1, 0x29, 0x42, 0x26, 0x91,
  30738. 0xD0, 0x38, 0x31, 0x83, 0x28, 0x28, 0x4C, 0x28,
  30739. 0x61, 0x1A, 0xB2, 0x88, 0x80, 0x26, 0x2D, 0x0C,
  30740. 0x19, 0x52, 0x5B, 0x22, 0x60, 0x8A, 0x92, 0x28,
  30741. 0xA2, 0x18, 0x90, 0xD9, 0x42, 0x52, 0xCB, 0x40,
  30742. 0x8E, 0x9B, 0x16, 0x06, 0x4B, 0xC8, 0x05, 0xE0,
  30743. 0x06, 0x6C, 0x49, 0xC2, 0x25, 0xD4, 0x22, 0x69,
  30744. 0x14, 0x11, 0x69, 0x1C, 0x34, 0x90, 0x0C, 0x85,
  30745. 0x8D, 0x1C, 0x84, 0x49, 0x63, 0x10, 0x85, 0x08,
  30746. 0x34, 0x89, 0x58, 0x16, 0x66, 0xA0, 0x38, 0x68,
  30747. 0x0B, 0xA2, 0x50, 0xE0, 0x84, 0x61, 0xC1, 0x26,
  30748. 0x6E, 0xC9, 0x14, 0x6A, 0xC0, 0xC0, 0x31, 0x84,
  30749. 0x18, 0x2E, 0xDC, 0x16, 0x52, 0x14, 0x18, 0x91,
  30750. 0x0A, 0x39, 0x2C, 0x83, 0xA6, 0x8D, 0x12, 0x29,
  30751. 0x62, 0x92, 0xA6, 0x60, 0x08, 0xA5, 0x10, 0xD9,
  30752. 0xC8, 0x4D, 0x24, 0x48, 0x24, 0x83, 0x98, 0x24,
  30753. 0x1A, 0x44, 0x42, 0x08, 0x08, 0x48, 0xC8, 0x96,
  30754. 0x2D, 0xA1, 0x10, 0x20, 0x60, 0x24, 0x51, 0x9C,
  30755. 0x30, 0x11, 0xDB, 0xC8, 0x04, 0x11, 0x22, 0x51,
  30756. 0x18, 0x04, 0x68, 0xE2, 0x24, 0x4E, 0x10, 0xC4,
  30757. 0x0D, 0x18, 0x37, 0x29, 0x11, 0xB7, 0x84, 0x43,
  30758. 0x84, 0x8D, 0x54, 0x40, 0x70, 0x64, 0x80, 0x70,
  30759. 0x21, 0xB0, 0x4D, 0x00, 0x26, 0x62, 0x00, 0x45,
  30760. 0x25, 0x1B, 0x83, 0x84, 0x84, 0x80, 0x70, 0x19,
  30761. 0xB0, 0x04, 0x0A, 0xC9, 0x28, 0xCA, 0x80, 0x05,
  30762. 0x1B, 0x21, 0x4E, 0xD4, 0xB0, 0x49, 0x8C, 0x96,
  30763. 0x6C, 0xD0, 0x96, 0x25, 0x48, 0x32, 0x72, 0x54,
  30764. 0x12, 0x05, 0x09, 0x98, 0x8C, 0x8A, 0x32, 0x6D,
  30765. 0xC0, 0x04, 0x31, 0x63, 0xC8, 0x61, 0xC8, 0xC2,
  30766. 0x68, 0x9B, 0xB4, 0x8C, 0x5B, 0xC0, 0x2D, 0xC3,
  30767. 0xA8, 0x8D, 0x1B, 0x16, 0x6C, 0xD8, 0x96, 0x41,
  30768. 0x98, 0x34, 0x02, 0x44, 0x14, 0x2C, 0xD3, 0x86,
  30769. 0x44, 0x0A, 0x18, 0x8A, 0x1A, 0x46, 0x92, 0x1A,
  30770. 0xB7, 0x08, 0x4C, 0x34, 0x24, 0x21, 0x91, 0x0D,
  30771. 0x9A, 0x96, 0x2D, 0xCB, 0x24, 0x22, 0x92, 0x86,
  30772. 0x08, 0x98, 0xA0, 0x50, 0xDA, 0x44, 0x6A, 0x19,
  30773. 0xB1, 0x05, 0x8B, 0x20, 0x6E, 0x24, 0xC4, 0x81,
  30774. 0xC9, 0x98, 0x40, 0x22, 0x19, 0x32, 0x11, 0x05,
  30775. 0x69, 0xD3, 0x94, 0x91, 0x08, 0xA7, 0x71, 0xDB,
  30776. 0xC0, 0x70, 0x02, 0xB8, 0x28, 0x83, 0xB4, 0x49,
  30777. 0xA0, 0x44, 0x8A, 0x0B, 0xB4, 0x10, 0x61, 0x02,
  30778. 0x48, 0x1C, 0xA6, 0x11, 0xE3, 0x20, 0x66, 0x40,
  30779. 0xB4, 0x70, 0x03, 0xB6, 0x04, 0x60, 0x48, 0x21,
  30780. 0x5B, 0x21, 0x83, 0x39, 0x88, 0xDB, 0x67, 0x4A,
  30781. 0x61, 0xE7, 0xC2, 0x08, 0xDE, 0xBE, 0x8D, 0xAE,
  30782. 0x41, 0x19, 0xAF, 0xB0, 0x26, 0x61, 0xA6, 0x9A,
  30783. 0xBC, 0x8B, 0xDD, 0x24, 0x5B, 0x5D, 0x0F, 0xB1,
  30784. 0xA2, 0x67, 0x01, 0xC9, 0xB9, 0xC9, 0xA8, 0xF7,
  30785. 0xD9, 0xFC, 0xD4, 0xC2, 0x87, 0xFF, 0x3D, 0x60,
  30786. 0x8C, 0xF2, 0x58, 0x28, 0x2A, 0x1E, 0xB2, 0x9F,
  30787. 0x93, 0x04, 0xE8, 0x9C, 0x14, 0xF3, 0xE1, 0xCE,
  30788. 0x56, 0x12, 0x89, 0x1C, 0x60, 0x29, 0x34, 0x52,
  30789. 0x60, 0x06, 0xC9, 0x9B, 0x4A, 0xA2, 0x39, 0x9B,
  30790. 0xF4, 0x94, 0xBC, 0xF8, 0xDF, 0x61, 0xD6, 0xDF,
  30791. 0x4C, 0x69, 0xBC, 0x93, 0xE0, 0x2D, 0x49, 0x95,
  30792. 0xE2, 0xF7, 0x6E, 0x9F, 0xDA, 0x4E, 0xF6, 0x7E,
  30793. 0xB7, 0x25, 0x6C, 0xA8, 0x9A, 0x3F, 0x38, 0xFE,
  30794. 0xB2, 0xE9, 0xDF, 0x6A, 0x01, 0x0D, 0xC1, 0xC1,
  30795. 0x50, 0x02, 0xFB, 0xD4, 0x56, 0xFA, 0xE8, 0x84,
  30796. 0x82, 0x1A, 0x34, 0x16, 0x6B, 0x06, 0x58, 0xA2,
  30797. 0x41, 0x25, 0x95, 0x71, 0x8E, 0x14, 0x9B, 0xBC,
  30798. 0x6E, 0x22, 0x0A, 0xEE, 0x26, 0x8D, 0x4D, 0x82,
  30799. 0x18, 0xC2, 0x5F, 0x6A, 0x95, 0x7D, 0xE5, 0xB2,
  30800. 0x6C, 0xEA, 0x7B, 0x14, 0xCB, 0x32, 0x0D, 0x89,
  30801. 0xE1, 0x69, 0x9A, 0xD9, 0xF2, 0xB3, 0x89, 0xC6,
  30802. 0x7E, 0xF9, 0x33, 0x86, 0xA2, 0xC6, 0x5F, 0x2C,
  30803. 0x32, 0x23, 0x33, 0x67, 0xD7, 0x6A, 0xE4, 0xAB,
  30804. 0x2A, 0xBB, 0xD4, 0x22, 0xE9, 0x8E, 0x49, 0x3D,
  30805. 0xCC, 0x3C, 0xC5, 0xDA, 0xF6, 0x89, 0xB6, 0x5C,
  30806. 0xC4, 0xBC, 0x3F, 0xA5, 0x1C, 0x9C, 0x59, 0xEE,
  30807. 0xAF, 0x07, 0x55, 0x17, 0x0C, 0x24, 0x95, 0x80,
  30808. 0x4D, 0x02, 0xA6, 0x07, 0xC5, 0xBF, 0x88, 0x7C,
  30809. 0xD8, 0x6A, 0x03, 0x89, 0xF2, 0x8F, 0xC9, 0x72,
  30810. 0x5E, 0xF4, 0x60, 0x03, 0xF1, 0x3B, 0x01, 0x87,
  30811. 0x68, 0x4B, 0xEA, 0xB1, 0xF2, 0x4A, 0x29, 0xF5,
  30812. 0x31, 0x96, 0x01, 0xF3, 0x09, 0xC9, 0x1D, 0x2A,
  30813. 0x33, 0x3D, 0x1B, 0x88, 0xDF, 0x20, 0x5A, 0x51,
  30814. 0x20, 0xC4, 0xCF, 0xDC, 0x22, 0x38, 0x12, 0x4E,
  30815. 0x4E, 0x2B, 0x47, 0xD0, 0xB5, 0xE6, 0x6A, 0x65,
  30816. 0x4F, 0xE4, 0xCC, 0xCB, 0x07, 0x8F, 0x07, 0xCB,
  30817. 0xD4, 0x55, 0xD1, 0x5D, 0x3E, 0xEC, 0x7D, 0xA2,
  30818. 0x74, 0xD2, 0x4A, 0x2E, 0x57, 0x18, 0x84, 0xDE,
  30819. 0x41, 0xC3, 0xA9, 0xA4, 0xFD, 0xB3, 0xF6, 0x09,
  30820. 0x8A, 0x17, 0x2C, 0x30, 0x96, 0x80, 0x39, 0xBD,
  30821. 0x0E, 0x4E, 0xB3, 0xE2, 0xFB, 0x6D, 0x6E, 0xEE,
  30822. 0xD3, 0x9E, 0x0B, 0x63, 0x62, 0xD5, 0x4E, 0x7B,
  30823. 0x88, 0x95, 0x98, 0x69, 0xDD, 0xD5, 0xD8, 0x73,
  30824. 0xD9, 0x65, 0x24, 0x01, 0xA2, 0x9F, 0x27, 0xA2,
  30825. 0x8E, 0xA6, 0x6D, 0x32, 0xCC, 0xB0, 0xEF, 0x3B,
  30826. 0xF4, 0x60, 0x0F, 0x75, 0x57, 0xEE, 0x8D, 0x54,
  30827. 0xBF, 0x1D, 0xAD, 0x18, 0xF4, 0x5D, 0xDC, 0xD4,
  30828. 0xC9, 0xED, 0x57, 0xB1, 0x3E, 0x44, 0x5B, 0xF1,
  30829. 0x22, 0xA4, 0x3F, 0x53, 0x94, 0x03, 0x89, 0xBF,
  30830. 0x87, 0x14, 0xFF, 0xAC, 0x72, 0x1E, 0x59, 0x31,
  30831. 0x7E, 0x4B, 0x70, 0x50, 0x0A, 0xD0, 0xD1, 0xB9,
  30832. 0xA6, 0x27, 0x05, 0x4D, 0x31, 0x93, 0x20, 0x8C,
  30833. 0x77, 0x4E, 0x0B, 0x20, 0xED, 0x04, 0x1A, 0x8C,
  30834. 0x05, 0x5E, 0x75, 0xEE, 0xCD, 0x37, 0x38, 0xF0,
  30835. 0x07, 0x15, 0x8F, 0xAD, 0xDF, 0xCA, 0x5F, 0x43,
  30836. 0x56, 0x2D, 0x63, 0x6A, 0x5A, 0xCF, 0x3A, 0x39,
  30837. 0x83, 0xD3, 0xCF, 0xEB, 0xCA, 0x10, 0xB8, 0x13,
  30838. 0xF9, 0xF6, 0x52, 0x65, 0x19, 0x19, 0x9A, 0x03,
  30839. 0x13, 0xCD, 0x1D, 0xE1, 0x3F, 0x06, 0xAD, 0x53,
  30840. 0x86, 0xE1, 0xE1, 0x20, 0x79, 0x5F, 0xD2, 0x67,
  30841. 0xB7, 0xF4, 0x20, 0x19, 0xD8, 0x4D, 0xF6, 0xCD,
  30842. 0x1B, 0xF9, 0x19, 0x30, 0xFC, 0xA7, 0xAF, 0xD5,
  30843. 0x2E, 0x80, 0x70, 0x0F, 0x4C, 0xF5, 0xCD, 0xC3,
  30844. 0x8A, 0x5F, 0x7A, 0x57, 0x49, 0x79, 0x1C, 0x2F,
  30845. 0xDF, 0xFC, 0x4A, 0x10, 0x75, 0x3C, 0x24, 0xDB,
  30846. 0x19, 0xE8, 0xEB, 0x65, 0x1C, 0x5B, 0x36, 0x32,
  30847. 0x00, 0xF0, 0xB5, 0xD1, 0x69, 0x94, 0x70, 0x26,
  30848. 0xE9, 0xF7, 0x4F, 0x01, 0x2D, 0xC7, 0xC5, 0xB3,
  30849. 0x39, 0xDD, 0x49, 0xD2, 0x61, 0xCA, 0x1D, 0x37,
  30850. 0xF8, 0xF2, 0x83, 0x46, 0xE6, 0x19, 0x78, 0x05,
  30851. 0x4F, 0x45, 0xAE, 0xE4, 0x36, 0xDC, 0xCB, 0xE7,
  30852. 0xBF, 0xAF, 0xE0, 0x7C, 0xE9, 0xA8, 0xB8, 0x3C,
  30853. 0x90, 0xA2, 0x68, 0x6F, 0xA9, 0x54, 0x02, 0x85,
  30854. 0x09, 0x25, 0xC8, 0x58, 0x2B, 0xC9, 0xB7, 0x34,
  30855. 0xE4, 0xEC, 0xA1, 0xF7, 0xB2, 0x0B, 0x08, 0x6F,
  30856. 0x12, 0x9F, 0x27, 0x7A, 0x5C, 0xBD, 0xAA, 0x96,
  30857. 0x3C, 0x92, 0x71, 0x7E, 0xF7, 0x0E, 0xC1, 0x9B,
  30858. 0xF3, 0xDB, 0xC6, 0xDA, 0x20, 0x3A, 0xD9, 0x0F,
  30859. 0x3B, 0x13, 0xBB, 0xC2, 0x2F, 0xBD, 0x98, 0x0B,
  30860. 0xB1, 0xB9, 0xD3, 0xA3, 0x44, 0x52, 0xB3, 0x35,
  30861. 0x70, 0x21, 0xCE, 0x36, 0x13, 0x58, 0x4E, 0x09,
  30862. 0x36, 0xBF, 0x1D, 0x09, 0x42, 0x09, 0x37, 0x81,
  30863. 0x5E, 0x11, 0xCC, 0x5D, 0x5D, 0xDB, 0x4B, 0xF1,
  30864. 0xD8, 0x30, 0xC4, 0xF8, 0x3F, 0x30, 0xE5, 0x15,
  30865. 0x92, 0x1C, 0x78, 0x4D, 0x87, 0xBB, 0x20, 0xC0,
  30866. 0x9E, 0x3C, 0x64, 0xBD, 0xCE, 0x9A, 0xB1, 0xC6,
  30867. 0x9F, 0xD3, 0x07, 0xEF, 0xE3, 0x59, 0xC7, 0xF9,
  30868. 0x38, 0x56, 0x6C, 0x9F, 0x25, 0x17, 0xB0, 0x63,
  30869. 0x38, 0x51, 0x67, 0xE2, 0x47, 0xF3, 0x10, 0x81,
  30870. 0x11, 0x9B, 0xAC, 0x6B, 0x55, 0xA0, 0xBD, 0xD7,
  30871. 0x14, 0x25, 0x51, 0x0F, 0xFA, 0x2A, 0xBD, 0xFA,
  30872. 0x88, 0x83, 0x76, 0xA3, 0x7F, 0x20, 0xC2, 0x48,
  30873. 0x01, 0x52, 0xBB, 0x36, 0x16, 0x34, 0x52, 0x00,
  30874. 0x07, 0xC5, 0xB3, 0x4B, 0xF2, 0x28, 0x17, 0xCB,
  30875. 0x2E, 0x67, 0xAC, 0x1A, 0x82, 0x67, 0x0B, 0x71,
  30876. 0xF1, 0x96, 0xC8, 0x9F, 0x23, 0xBA, 0x31, 0x4B,
  30877. 0x16, 0xA9, 0x48, 0x49, 0x93, 0x04, 0xEF, 0x5C,
  30878. 0x03, 0xDC, 0xF5, 0x8E, 0x52, 0xBE, 0x31, 0x48,
  30879. 0x63, 0xE7, 0x23, 0xC5, 0x6D, 0x3A, 0xEB, 0x34,
  30880. 0x0B, 0xFF, 0x18, 0xAB, 0xFA, 0x20, 0xDC, 0x03,
  30881. 0x44, 0x20, 0x30, 0x23, 0x05, 0x33, 0xD9, 0x12,
  30882. 0x9B, 0x83, 0xED, 0x22, 0xC3, 0x51, 0xF2, 0x32,
  30883. 0x81, 0x72, 0xE3, 0x63, 0x44, 0x74, 0x44, 0xAE,
  30884. 0x5C, 0x69, 0x02, 0xB7, 0x92, 0x79, 0x9F, 0x54,
  30885. 0x44, 0x50, 0x78, 0x71, 0x19, 0x61, 0x2E, 0x9B,
  30886. 0xB4, 0x13, 0x0A, 0x33, 0xA2, 0xA5, 0x96, 0x2A,
  30887. 0xC0, 0x9D, 0x57, 0x7D, 0x6D, 0xDC, 0x88, 0x1F,
  30888. 0xE6, 0x61, 0x61, 0x26, 0xD8, 0xA0, 0xA7, 0xDF,
  30889. 0x2B, 0x22, 0x53, 0xBC, 0x8E, 0xC4, 0xE3, 0x53,
  30890. 0x86, 0xEA, 0x55, 0x11, 0xF0, 0xF1, 0x58, 0x87,
  30891. 0x14, 0x5B, 0x6C, 0x23, 0xAB, 0x3D, 0x40, 0x33,
  30892. 0x39, 0xE4, 0x04, 0x07, 0x3E, 0xD9, 0xC6, 0xA8,
  30893. 0x96, 0xA2, 0xF9, 0xEC, 0x70, 0xC4, 0x4B, 0xD2,
  30894. 0xAE, 0xC1, 0x0F, 0xC4, 0x36, 0x0E, 0x87, 0x63,
  30895. 0x6B, 0xE1, 0x55, 0xB6, 0xA6, 0x7B, 0x7E, 0xDF,
  30896. 0x38, 0xCF, 0x73, 0x00, 0x48, 0x13, 0xC9, 0xE7,
  30897. 0xD2, 0xC6, 0x54, 0xC2, 0x53, 0x0A, 0x71, 0xE5,
  30898. 0xF8, 0xC1, 0x09, 0x42, 0xFB, 0x6D, 0x88, 0x41,
  30899. 0x53, 0x5A, 0xB1, 0xDA, 0x43, 0xE8, 0xCB, 0x0B,
  30900. 0xB8, 0x9E, 0x78, 0xEC, 0x91, 0xF8, 0xDE, 0x15,
  30901. 0x31, 0xA0, 0x36, 0x65, 0xCC, 0xD5, 0xA7, 0x5B,
  30902. 0xDA, 0x0E, 0xD0, 0xE5, 0x98, 0x64, 0xEE, 0xEF,
  30903. 0x51, 0xA8, 0x3F, 0xA5, 0x53, 0xAF, 0x66, 0x2A,
  30904. 0xEE, 0x00, 0xD1, 0xF8, 0x36, 0x7B, 0x4D, 0x5D,
  30905. 0xDD, 0xC3, 0x45, 0x54, 0x4C, 0x6B, 0xD5, 0x14,
  30906. 0xF8, 0x88, 0xE6, 0x03, 0x3C, 0x25, 0x5D, 0xB6,
  30907. 0x50, 0xDA, 0x73, 0x4A, 0xD3, 0x3A, 0x3C, 0xF8,
  30908. 0x4B, 0xD3, 0xF0, 0x6F, 0xA1, 0xA7, 0xCA, 0x02,
  30909. 0xE4, 0xB8, 0xE9, 0x93, 0xAE, 0x7A, 0xE6, 0x34,
  30910. 0x20, 0xA4, 0x6B, 0xA8, 0xA3, 0x81, 0x3D, 0x1E,
  30911. 0x9D, 0x29, 0x66, 0xBB, 0x85, 0x60, 0xD7, 0x1C,
  30912. 0x62, 0xA0, 0x44, 0xEA, 0x94, 0x17, 0x9F, 0x4E,
  30913. 0xB1, 0xB6, 0xED, 0x60, 0x71, 0x9D, 0x51, 0xE0,
  30914. 0xEE, 0xF6, 0xCD, 0x07, 0x91, 0x52, 0xF6, 0xBE,
  30915. 0x48, 0x8E, 0xC9, 0x19, 0x11, 0xC6, 0xD3, 0xF1,
  30916. 0xD1, 0x17, 0x3C, 0x54, 0x1F, 0x9D, 0x25, 0xBF,
  30917. 0x34, 0x2F, 0xCA, 0xA3, 0xFF, 0x46, 0xC1, 0x8F,
  30918. 0x2A, 0x04, 0x41, 0xD8, 0x3B, 0xDE, 0x35, 0x46,
  30919. 0xA9, 0x82, 0x6C, 0x34, 0x96, 0xE0, 0x6F, 0x2F,
  30920. 0x2B, 0x0E, 0xEB, 0x9D, 0x5B, 0xE8, 0x73, 0x9F,
  30921. 0x83, 0xA4, 0x2D, 0x3B, 0x30, 0x0E, 0x70, 0xEE,
  30922. 0x84, 0xDF, 0xFF, 0xB2, 0x07, 0x64, 0xA0, 0x60,
  30923. 0x21, 0x2F, 0x05, 0x8C, 0x8A, 0x5F, 0xFA, 0x9A,
  30924. 0x34, 0xE9, 0x28, 0xD6, 0xA7, 0xE0, 0x77, 0x08,
  30925. 0xFE, 0x53, 0x93, 0xE3, 0x01, 0x7C, 0xE4, 0x70,
  30926. 0xEB, 0x96, 0x58, 0xA7, 0x4E, 0x49, 0x51, 0xE6,
  30927. 0xFA, 0x48, 0x54, 0xC9, 0xE9, 0xC2, 0x89, 0x88,
  30928. 0x81, 0x2E, 0x44, 0x18, 0xA2, 0xE8, 0x32, 0x58,
  30929. 0x0B, 0x4A, 0x27, 0x03, 0x72, 0xBC, 0x69, 0x67,
  30930. 0x68, 0x89, 0xD0, 0xCC, 0x43, 0x24, 0x0E, 0xDA,
  30931. 0xBC, 0x1D, 0x31, 0x14, 0xD8, 0xF3, 0x5A, 0xB2,
  30932. 0xE9, 0xEA, 0x95, 0x30, 0x82, 0xE9, 0x53, 0x62,
  30933. 0x79, 0xAC, 0xB3, 0xBE, 0x16, 0xD3, 0xA2, 0x05,
  30934. 0xF4, 0x6C, 0xB6, 0x7B, 0x22, 0x14, 0x96, 0x93,
  30935. 0x5A, 0xC0, 0x42, 0x92, 0xBB, 0xFB, 0x9A, 0x61,
  30936. 0xC0, 0xA0, 0x3E, 0xF4, 0xC9, 0xB6, 0x82, 0x04,
  30937. 0x95, 0xF3, 0xD8, 0x0E, 0x4A, 0x6F, 0xB7, 0xE1,
  30938. 0xC6, 0x99, 0x03, 0xFA, 0x22, 0x6E, 0x02, 0x3E,
  30939. 0x95, 0xBA, 0x41, 0x6D, 0xF2, 0xE5, 0xE4, 0x54,
  30940. 0x1E, 0x15, 0xDC, 0xC0, 0x00, 0xB5, 0xE6, 0x5C,
  30941. 0x97, 0x20, 0xDA, 0xF6, 0x96, 0x01, 0x2F, 0xA2,
  30942. 0xA6, 0xCF, 0x75, 0x8E, 0xD6, 0xD2, 0x25, 0xA3,
  30943. 0xE4, 0xFE, 0xE4, 0x5A, 0xC5, 0xFB, 0x48, 0x70,
  30944. 0x7F, 0xAE, 0x13, 0x3D, 0x59, 0x2C, 0xFD, 0x2E,
  30945. 0x8C, 0x43, 0xC2, 0x12, 0x6F, 0x65, 0x2B, 0xEE,
  30946. 0x9B, 0xAB, 0x43, 0xA1, 0xA1, 0x0B, 0xE2, 0x41,
  30947. 0x1A, 0x67, 0x94, 0xB2, 0x6C, 0xB5, 0x5C, 0xC2,
  30948. 0x17, 0xEB, 0x7B, 0x0B, 0x14, 0x6D, 0x23, 0xF7,
  30949. 0x92, 0x2D, 0x32, 0x22, 0xAE, 0x5E, 0xE8, 0xC6,
  30950. 0xD3, 0x8E, 0x83, 0x99, 0xBA, 0x51, 0xC6, 0x81,
  30951. 0xB8, 0x38, 0x16, 0xFC, 0xF7, 0x44, 0x38, 0x82,
  30952. 0x59, 0x20, 0xF9, 0xCE, 0x8A, 0x20, 0x2A, 0x8F,
  30953. 0x6D, 0x94, 0x2D, 0xA8, 0x62, 0x38, 0xFB, 0x4C,
  30954. 0x9F, 0x21, 0x98, 0xEA, 0x8D, 0xFF, 0x81, 0xC1,
  30955. 0x72, 0x86, 0xE0, 0x18, 0xDF, 0x4B, 0x7F, 0xE3,
  30956. 0x88, 0x4D, 0x17, 0x59, 0xE4, 0xC5, 0x9B, 0xB5,
  30957. 0x26, 0x17, 0xAE, 0xD4, 0xE7, 0x8E, 0x4E, 0x7C,
  30958. 0x4E, 0x9A, 0x36, 0xE4, 0xE9, 0x96, 0xD3, 0x23,
  30959. 0x91, 0xA3, 0x4A, 0x0D, 0xAA, 0xAB, 0x6B, 0x54,
  30960. 0x08, 0x15, 0xA3, 0x4D, 0x20, 0x40, 0x7A, 0xEF,
  30961. 0x81, 0x94, 0x9B, 0xE6, 0x7B, 0x90, 0x69, 0x50,
  30962. 0xD8, 0x9B, 0xE9, 0xF0, 0x85, 0xE9, 0x9E, 0xB5,
  30963. 0x87, 0x26, 0x95, 0x17, 0x3B, 0x3E, 0xFA, 0xCA,
  30964. 0xE9, 0x45, 0x5D, 0x2B, 0x2C, 0xD4, 0xF7, 0x10,
  30965. 0xB8, 0x72, 0xCF, 0x66, 0x2B, 0x73, 0x62, 0x16,
  30966. 0xB1, 0xBB, 0xFB, 0x1F, 0x5F, 0x3D, 0x48, 0x6C,
  30967. 0x7B, 0x4B, 0x87, 0x56, 0x12, 0x33, 0x3F, 0x8E,
  30968. 0x4B, 0xA9, 0x33, 0xDC, 0x79, 0xF0, 0xED, 0xFD,
  30969. 0x7B, 0xAA, 0xDE, 0x2C, 0x16, 0xF2, 0x14, 0x6A,
  30970. 0x49, 0x6F, 0x79, 0xC4, 0x2A, 0x4D, 0x6B, 0x52,
  30971. 0x39, 0xA3, 0x0D, 0xD3, 0xC4, 0x8B, 0xEB, 0x09,
  30972. 0x2C, 0xA0, 0x75, 0x00, 0x10, 0xF6, 0x9E, 0xD4,
  30973. 0xB9, 0x23, 0x20, 0x14, 0x7D, 0xBB, 0xE2, 0x08,
  30974. 0xF6, 0xE8, 0xEB, 0x1C, 0xF2, 0x47, 0xD2, 0x1A,
  30975. 0x3A, 0x3B, 0x01, 0xDF, 0x58, 0xC0, 0xAA, 0x62,
  30976. 0x94, 0x4D, 0xA0, 0xEF, 0x04, 0x50, 0xE8, 0xCE,
  30977. 0x48, 0xAA, 0x13, 0x7E, 0x7E, 0x15, 0x16, 0xC1,
  30978. 0xD5, 0xC8, 0x6E, 0xEA, 0x17, 0xFD, 0xFA, 0xC1,
  30979. 0x69, 0x07, 0x46, 0xE7, 0x26, 0x70, 0x45, 0xA3,
  30980. 0xE9, 0x05, 0x96, 0xBD, 0xB7, 0x5D, 0x50, 0xB6,
  30981. 0xDD, 0x5C, 0x34, 0xE5, 0xC8, 0xD8, 0x9D, 0xC6,
  30982. 0xF2, 0xF1, 0xD2, 0x44, 0x40, 0xE5, 0x7B, 0x47,
  30983. 0x59, 0xB8, 0x62, 0x5F, 0x72, 0xBC, 0x4A, 0x7B,
  30984. 0x10, 0xD5, 0x19, 0xD3, 0x31, 0xF9, 0xC4, 0x00,
  30985. 0xAA, 0xE1, 0xE5, 0x0D, 0x48, 0x0C, 0xAA, 0xE5,
  30986. 0xA1, 0xC0, 0xFA, 0x99, 0xD7, 0x79, 0x24, 0xCF,
  30987. 0x8D, 0xFE, 0x56, 0xCD, 0x70, 0x92, 0xE7, 0xB9
  30988. };
  30989. #endif /* !WOLFSSL_NO_ML_DSA_44 */
  30990. #ifndef WOLFSSL_NO_ML_DSA_65
  30991. static const byte seed_65[] = {
  30992. 0x70, 0xCE, 0xFB, 0x9A, 0xED, 0x5B, 0x68, 0xE0,
  30993. 0x18, 0xB0, 0x79, 0xDA, 0x82, 0x84, 0xB9, 0xD5,
  30994. 0xCA, 0xD5, 0x49, 0x9E, 0xD9, 0xC2, 0x65, 0xFF,
  30995. 0x73, 0x58, 0x80, 0x05, 0xD8, 0x5C, 0x22, 0x5C
  30996. };
  30997. static const byte pk_65[] = {
  30998. 0xD2, 0xFD, 0x03, 0xF3, 0xA1, 0xB7, 0xF6, 0x35,
  30999. 0xAF, 0x9F, 0x34, 0xD5, 0x80, 0xA9, 0x8F, 0x52,
  31000. 0x4C, 0x73, 0x5B, 0xD5, 0xBA, 0x23, 0x55, 0xDC,
  31001. 0x6E, 0x03, 0x5B, 0xD2, 0x17, 0x65, 0x58, 0x0C,
  31002. 0xBB, 0x11, 0x19, 0x23, 0xF1, 0x94, 0xA7, 0xCC,
  31003. 0x8A, 0x7B, 0xB2, 0xEB, 0xC5, 0xC0, 0xE7, 0x1A,
  31004. 0xA6, 0x37, 0xCC, 0x80, 0x0E, 0x61, 0x03, 0xB8,
  31005. 0x50, 0xA5, 0x39, 0xB2, 0xA3, 0x9E, 0x1B, 0x6D,
  31006. 0x71, 0x3E, 0x5D, 0xB8, 0x31, 0x4C, 0x9A, 0xE1,
  31007. 0xF8, 0xBF, 0x8A, 0x38, 0xF0, 0x6A, 0xFB, 0x9D,
  31008. 0x73, 0xB1, 0x61, 0xB0, 0xFF, 0xE3, 0xA4, 0x89,
  31009. 0x17, 0x06, 0xAE, 0x26, 0xD5, 0x4F, 0xFB, 0x49,
  31010. 0x6D, 0xF8, 0xDC, 0x0F, 0x19, 0x83, 0x50, 0x95,
  31011. 0x00, 0xC9, 0xAB, 0xBD, 0x28, 0xE5, 0x9B, 0x3F,
  31012. 0xCD, 0xAB, 0xBD, 0xAD, 0xAB, 0xD4, 0x5E, 0xC3,
  31013. 0x14, 0x99, 0x37, 0x8B, 0xDE, 0x84, 0x9E, 0x7C,
  31014. 0x1F, 0x19, 0xB7, 0x04, 0x4D, 0x67, 0xE0, 0x51,
  31015. 0x06, 0xD7, 0x13, 0x6D, 0x95, 0x38, 0x0D, 0x56,
  31016. 0x05, 0xD4, 0x46, 0x5D, 0x87, 0x75, 0x57, 0x06,
  31017. 0x5D, 0xF0, 0xA7, 0x5D, 0x3C, 0x28, 0x54, 0x2F,
  31018. 0x40, 0xFE, 0xED, 0x42, 0xEC, 0x7E, 0x28, 0x06,
  31019. 0x37, 0xB0, 0x83, 0xD9, 0x88, 0xBC, 0xA5, 0xF6,
  31020. 0x39, 0x4E, 0x02, 0x39, 0x6C, 0x46, 0x76, 0x18,
  31021. 0x4F, 0xB6, 0x33, 0x18, 0xDA, 0xFA, 0xF5, 0xBB,
  31022. 0xDD, 0xE0, 0x0E, 0x30, 0x8F, 0xE8, 0x40, 0x19,
  31023. 0xC2, 0x34, 0x0A, 0x3F, 0x3E, 0x1C, 0x08, 0x65,
  31024. 0x62, 0x49, 0x70, 0x71, 0x12, 0x83, 0x35, 0x6A,
  31025. 0xE1, 0x4B, 0xD6, 0xB9, 0x4D, 0x1C, 0x9A, 0xE1,
  31026. 0x88, 0xDE, 0x1A, 0x8A, 0x2C, 0xA8, 0x24, 0xA8,
  31027. 0xEA, 0xE2, 0xFE, 0x6A, 0xFB, 0x38, 0xD8, 0x3A,
  31028. 0x2D, 0x99, 0x99, 0x6A, 0xB2, 0x1F, 0xE3, 0xE8,
  31029. 0x4C, 0x0B, 0xE6, 0xB6, 0xDA, 0x08, 0x87, 0x9B,
  31030. 0x67, 0x73, 0x74, 0xFA, 0x7C, 0x69, 0x1B, 0x13,
  31031. 0xD4, 0x0F, 0xA9, 0xD4, 0xCC, 0x26, 0xB2, 0x28,
  31032. 0x8D, 0x5A, 0x8C, 0x9A, 0x43, 0x72, 0x43, 0x81,
  31033. 0x00, 0x4D, 0x61, 0xB0, 0xD5, 0x7F, 0xF4, 0x00,
  31034. 0x31, 0x4C, 0x8E, 0x30, 0xEE, 0x79, 0x6A, 0xF1,
  31035. 0x0F, 0x7E, 0xE2, 0x1B, 0xF1, 0x3D, 0x08, 0x18,
  31036. 0x04, 0x65, 0xAB, 0xC7, 0x2E, 0xDD, 0xB0, 0x80,
  31037. 0xC6, 0xA0, 0x71, 0x84, 0xE3, 0xEE, 0xDC, 0x47,
  31038. 0xC1, 0x9A, 0xA7, 0xF0, 0x9D, 0x1F, 0x33, 0x09,
  31039. 0xE1, 0x83, 0xA2, 0xBD, 0x9B, 0x05, 0x73, 0xDD,
  31040. 0xE4, 0x74, 0xA8, 0x1B, 0xA4, 0xF7, 0x8D, 0x0C,
  31041. 0x52, 0x3D, 0x0C, 0x04, 0xF9, 0x00, 0x60, 0xFD,
  31042. 0x57, 0x1A, 0x35, 0xC0, 0x37, 0xE0, 0x79, 0xC5,
  31043. 0xE2, 0x10, 0xD7, 0x39, 0x0D, 0xF5, 0x68, 0xF2,
  31044. 0xE2, 0xF0, 0x3C, 0xE4, 0x44, 0x20, 0xC8, 0x2F,
  31045. 0x3F, 0xE6, 0x9E, 0xB9, 0xB4, 0x8E, 0xE9, 0x09,
  31046. 0x62, 0xD6, 0xB0, 0xF2, 0x44, 0x40, 0x64, 0x8F,
  31047. 0x71, 0xED, 0xB2, 0x41, 0xEE, 0x65, 0x66, 0xFC,
  31048. 0x1A, 0x64, 0xCA, 0xBF, 0x66, 0xBE, 0x6F, 0xEC,
  31049. 0xBC, 0xB1, 0x38, 0x7C, 0x82, 0xA7, 0xBC, 0x20,
  31050. 0x2D, 0x9E, 0x36, 0x79, 0x98, 0xE2, 0xA2, 0x91,
  31051. 0xAF, 0x0C, 0xD1, 0x57, 0x06, 0x77, 0xFE, 0x8D,
  31052. 0x63, 0xA3, 0x28, 0x5A, 0x2E, 0xA6, 0xEB, 0x29,
  31053. 0xAF, 0x9D, 0xC1, 0xAE, 0xC1, 0xC3, 0x6C, 0x47,
  31054. 0x06, 0xB1, 0x2B, 0xAA, 0x20, 0x83, 0x96, 0x92,
  31055. 0xF2, 0x86, 0xA6, 0xE0, 0x32, 0x14, 0x68, 0xF7,
  31056. 0x47, 0x93, 0x45, 0xC4, 0xD5, 0x2F, 0xBD, 0xB2,
  31057. 0xF0, 0x67, 0x25, 0xB5, 0x54, 0xB8, 0x9E, 0x24,
  31058. 0x92, 0x61, 0x26, 0x81, 0xAC, 0xEB, 0xC6, 0xC7,
  31059. 0xBA, 0xDA, 0x92, 0x25, 0x81, 0x8D, 0xBC, 0x35,
  31060. 0xD6, 0x4C, 0x22, 0xC4, 0x8B, 0xFF, 0x80, 0xA7,
  31061. 0x30, 0xD0, 0x71, 0x6D, 0xFA, 0xC9, 0x9D, 0xFD,
  31062. 0x5B, 0x89, 0x92, 0x61, 0x1D, 0x0C, 0x93, 0xEE,
  31063. 0x90, 0xBD, 0xB2, 0x60, 0x02, 0x2A, 0xFE, 0x25,
  31064. 0xD9, 0x13, 0xE0, 0x6E, 0xFF, 0xB5, 0x9C, 0xB1,
  31065. 0xF8, 0xA6, 0x0C, 0xBF, 0xA5, 0xAB, 0x2F, 0x45,
  31066. 0x9A, 0x16, 0xF4, 0x67, 0xE9, 0x89, 0x52, 0x5E,
  31067. 0x0A, 0x37, 0xEB, 0xE5, 0x6E, 0x83, 0x3F, 0xDE,
  31068. 0x55, 0xDB, 0x9D, 0x15, 0x30, 0xAD, 0xCF, 0x45,
  31069. 0x84, 0x6D, 0xF2, 0x81, 0xE4, 0x7C, 0xAA, 0x1E,
  31070. 0x0A, 0x27, 0xEF, 0xDE, 0x21, 0x07, 0xD3, 0x54,
  31071. 0xCE, 0xA0, 0xF6, 0xA4, 0x54, 0x69, 0x2F, 0x04,
  31072. 0xCD, 0x83, 0x8E, 0xBD, 0xD4, 0x6E, 0x19, 0x1E,
  31073. 0x5D, 0x9C, 0x11, 0x83, 0x9A, 0x2C, 0x3F, 0x48,
  31074. 0x8A, 0x4F, 0xC7, 0xCD, 0x26, 0x5A, 0x7B, 0x5D,
  31075. 0x32, 0xB0, 0x8C, 0xBD, 0xBF, 0xAB, 0x9D, 0x2C,
  31076. 0xCD, 0x76, 0x22, 0x2C, 0x8E, 0xE3, 0x7D, 0xDC,
  31077. 0xBD, 0x2A, 0xA0, 0x63, 0xED, 0x86, 0x14, 0x73,
  31078. 0xA6, 0x45, 0x4C, 0xAE, 0xA3, 0x77, 0x85, 0x0B,
  31079. 0x1A, 0x2B, 0x9D, 0xDB, 0xBC, 0xB3, 0x74, 0xFA,
  31080. 0xB5, 0xB1, 0x2F, 0x35, 0x1C, 0x8E, 0x58, 0x88,
  31081. 0x87, 0x2E, 0x5C, 0xD1, 0xF6, 0x0A, 0x4F, 0xAE,
  31082. 0x1F, 0xF8, 0x37, 0xD1, 0x92, 0xC2, 0x2B, 0xEB,
  31083. 0x41, 0xEE, 0x6F, 0xA3, 0x92, 0xFC, 0xDF, 0x45,
  31084. 0x50, 0xFF, 0x46, 0xB5, 0xCE, 0x90, 0x6D, 0x01,
  31085. 0x7E, 0xF3, 0x07, 0x7D, 0xF1, 0x32, 0x30, 0x0D,
  31086. 0x8B, 0xBF, 0xA9, 0xBB, 0x03, 0xC7, 0x5E, 0x79,
  31087. 0xE2, 0xF0, 0x4C, 0x28, 0x4A, 0xD0, 0x6A, 0x44,
  31088. 0x39, 0x96, 0x49, 0xC3, 0xE2, 0xA2, 0xA8, 0xD1,
  31089. 0xEF, 0xE9, 0xB7, 0xA4, 0xE0, 0xC2, 0x71, 0x04,
  31090. 0x7A, 0xB7, 0x59, 0x08, 0xBF, 0xF7, 0xDF, 0x9E,
  31091. 0x30, 0xEC, 0xA5, 0x47, 0x74, 0x5B, 0xAE, 0x23,
  31092. 0xA8, 0x6F, 0xF9, 0xA8, 0xB5, 0x8C, 0x25, 0x38,
  31093. 0xB8, 0x8B, 0x86, 0x64, 0x01, 0x07, 0x69, 0x02,
  31094. 0xDC, 0x5F, 0x0B, 0xD7, 0x61, 0x68, 0x7B, 0x49,
  31095. 0xEA, 0xFE, 0x36, 0xD3, 0x50, 0xCB, 0xED, 0xFD,
  31096. 0xD3, 0x6C, 0x12, 0x1C, 0xF2, 0x37, 0x86, 0xBF,
  31097. 0xCF, 0x7E, 0x47, 0x07, 0x64, 0x96, 0xEA, 0xB6,
  31098. 0xBB, 0xDA, 0x77, 0x40, 0x49, 0xC2, 0xEB, 0xAB,
  31099. 0xE2, 0xDE, 0x99, 0xC4, 0xC2, 0x4F, 0x2D, 0xB7,
  31100. 0x36, 0x84, 0x01, 0x5B, 0x37, 0x39, 0x77, 0x49,
  31101. 0x67, 0x60, 0xCF, 0x9A, 0xC2, 0x3D, 0x8B, 0x62,
  31102. 0x31, 0x33, 0xDB, 0x2D, 0xE1, 0x0D, 0x73, 0xFA,
  31103. 0x6A, 0xD1, 0xC6, 0xDA, 0xC8, 0x43, 0x4F, 0x28,
  31104. 0xC6, 0xE2, 0x51, 0xCE, 0x72, 0x93, 0xCF, 0xF3,
  31105. 0xF3, 0xB6, 0x1E, 0xFC, 0xB5, 0xA4, 0x35, 0x12,
  31106. 0x36, 0x70, 0xF2, 0x98, 0x46, 0xA1, 0x3D, 0xF3,
  31107. 0xEE, 0x71, 0x26, 0x04, 0x46, 0x1F, 0x1B, 0xAB,
  31108. 0x8F, 0x4E, 0xBC, 0x83, 0x6D, 0xE0, 0x58, 0x97,
  31109. 0x8A, 0xE7, 0x34, 0x39, 0x6A, 0x98, 0x08, 0x1B,
  31110. 0x35, 0xCC, 0x98, 0x18, 0x8A, 0x86, 0x94, 0x9C,
  31111. 0x99, 0x27, 0x0D, 0x47, 0x09, 0x85, 0x4C, 0x5B,
  31112. 0x35, 0xB1, 0x7F, 0x48, 0xA3, 0x73, 0x13, 0x4C,
  31113. 0x81, 0x4C, 0xC8, 0xA0, 0xF3, 0xE2, 0xFA, 0x80,
  31114. 0x7F, 0x2A, 0x91, 0x85, 0x30, 0x90, 0x78, 0x64,
  31115. 0x77, 0x82, 0x82, 0xD7, 0x5E, 0x03, 0xA4, 0x1B,
  31116. 0x25, 0x04, 0xEE, 0xD8, 0x16, 0xA4, 0x17, 0xA3,
  31117. 0xAC, 0x6B, 0xA1, 0x60, 0x80, 0xC3, 0x9B, 0x73,
  31118. 0x10, 0x19, 0x20, 0x02, 0xA7, 0x28, 0xF7, 0xF2,
  31119. 0x03, 0x95, 0x00, 0x9A, 0x9E, 0x16, 0x76, 0x7C,
  31120. 0xE1, 0x97, 0x1F, 0x5D, 0xE7, 0xD2, 0x29, 0xA5,
  31121. 0x06, 0x13, 0x36, 0x9E, 0x43, 0x82, 0x04, 0x5A,
  31122. 0x8E, 0x81, 0x90, 0x1F, 0x4D, 0xBA, 0x81, 0x02,
  31123. 0xF3, 0xD4, 0x13, 0xFE, 0x35, 0xB3, 0x26, 0xA8,
  31124. 0x74, 0xF2, 0x33, 0xB7, 0x19, 0xA7, 0x13, 0x76,
  31125. 0x00, 0xD3, 0x5D, 0x33, 0xAE, 0xB6, 0xB7, 0x25,
  31126. 0x96, 0x24, 0x08, 0x3A, 0xA9, 0x68, 0x73, 0x0C,
  31127. 0x8F, 0x78, 0x29, 0x2A, 0xD2, 0x8F, 0x14, 0xEE,
  31128. 0xAB, 0xE6, 0x60, 0x83, 0x59, 0x84, 0xFE, 0x69,
  31129. 0xEF, 0x23, 0xDE, 0xC8, 0xC3, 0x27, 0xC0, 0xEB,
  31130. 0x0B, 0x88, 0x2D, 0x58, 0x7E, 0x1E, 0xC4, 0x33,
  31131. 0xDA, 0x85, 0xC9, 0xFD, 0x1E, 0x0A, 0x34, 0x99,
  31132. 0x4D, 0xEA, 0x24, 0x0C, 0x85, 0x44, 0x52, 0xD1,
  31133. 0x8C, 0x30, 0xF4, 0x96, 0xE4, 0x9E, 0xC9, 0x04,
  31134. 0xB6, 0x02, 0xE0, 0xF5, 0x06, 0x2E, 0xDC, 0xDA,
  31135. 0x03, 0x28, 0x0A, 0x53, 0xB4, 0x31, 0x35, 0x74,
  31136. 0xCC, 0x2C, 0x0D, 0x54, 0x71, 0xBC, 0x96, 0x13,
  31137. 0xBD, 0xFD, 0x66, 0x41, 0xF5, 0xBD, 0x12, 0x7B,
  31138. 0xAB, 0x5B, 0x5E, 0xB3, 0xD4, 0x99, 0xA3, 0x31,
  31139. 0x14, 0x04, 0x82, 0x20, 0xE8, 0x19, 0xF8, 0xEE,
  31140. 0x12, 0xCA, 0x92, 0x2C, 0x8F, 0x17, 0xD9, 0xC9,
  31141. 0xF5, 0x1A, 0xD5, 0xBD, 0x68, 0x83, 0xB1, 0x0E,
  31142. 0x6A, 0xA2, 0x48, 0x3B, 0xA4, 0x9D, 0xC5, 0x47,
  31143. 0xDA, 0x76, 0x86, 0x15, 0x13, 0x44, 0xF4, 0xE9,
  31144. 0x09, 0x9B, 0x38, 0xE4, 0x30, 0xB5, 0x22, 0x6B,
  31145. 0x05, 0x98, 0x32, 0xCF, 0x03, 0xDB, 0x48, 0xFB,
  31146. 0x02, 0xDB, 0xA4, 0xE6, 0x15, 0x93, 0xDC, 0x45,
  31147. 0x76, 0x36, 0x04, 0x91, 0x89, 0x0E, 0x53, 0xEC,
  31148. 0x0E, 0x6A, 0xC7, 0x3C, 0xF3, 0x2B, 0x25, 0xD8,
  31149. 0x23, 0xB3, 0x84, 0x56, 0xE2, 0x86, 0x50, 0x5A,
  31150. 0x54, 0x1E, 0x5A, 0xEE, 0xE9, 0x6B, 0x19, 0x14,
  31151. 0xF5, 0xF7, 0x66, 0x87, 0xCE, 0x2B, 0x01, 0x60,
  31152. 0x22, 0x7A, 0xBE, 0xD7, 0x79, 0x93, 0x59, 0x4B,
  31153. 0xCD, 0x83, 0x13, 0x66, 0x20, 0x6D, 0x75, 0x71,
  31154. 0x40, 0x82, 0xF1, 0xC4, 0x6F, 0x1F, 0x44, 0x39,
  31155. 0xAC, 0x81, 0xA5, 0x7A, 0xF3, 0x1C, 0x81, 0xC5,
  31156. 0x55, 0x30, 0x7A, 0x07, 0x0F, 0xFA, 0x94, 0xE0,
  31157. 0x47, 0x9B, 0x78, 0x4B, 0xBD, 0x88, 0xA6, 0x0C,
  31158. 0xD4, 0xC7, 0xCF, 0xD9, 0x4E, 0x6A, 0xFE, 0x02,
  31159. 0xF6, 0xB2, 0x1F, 0x72, 0xAF, 0x0D, 0xCD, 0x66,
  31160. 0x09, 0xD4, 0x0C, 0x96, 0x5C, 0x14, 0xE5, 0xF2,
  31161. 0x38, 0x91, 0x83, 0xE5, 0x3D, 0xE9, 0x30, 0xF7,
  31162. 0xDE, 0x1D, 0x44, 0x21, 0x5C, 0xF4, 0x91, 0x44,
  31163. 0x84, 0x4E, 0x8B, 0x87, 0xF7, 0x8A, 0x7F, 0x13,
  31164. 0x2A, 0xEF, 0xE2, 0x2B, 0xE8, 0x0B, 0x4E, 0x3A,
  31165. 0x05, 0xEE, 0x3A, 0x68, 0xCC, 0xF6, 0x09, 0xEF,
  31166. 0x44, 0x04, 0x74, 0x02, 0xE4, 0x49, 0x30, 0x46,
  31167. 0xE6, 0xF9, 0xC7, 0x67, 0xFF, 0x8A, 0x75, 0xE2,
  31168. 0x8B, 0x3C, 0xE0, 0x77, 0xFD, 0xE7, 0xE7, 0xEE,
  31169. 0xD3, 0x13, 0xB5, 0xBF, 0x7E, 0x46, 0x01, 0x27,
  31170. 0xCA, 0x81, 0x82, 0xE9, 0xBC, 0x79, 0x4C, 0x0D,
  31171. 0xFA, 0x73, 0x0F, 0xB9, 0x20, 0x08, 0x05, 0x75,
  31172. 0xA7, 0x51, 0xB5, 0xCA, 0xEC, 0x85, 0xA1, 0x09,
  31173. 0xB4, 0x42, 0x2B, 0xA2, 0x66, 0x74, 0x3F, 0x0D,
  31174. 0x03, 0x2B, 0xDA, 0x8F, 0x1C, 0xA6, 0x24, 0x8C,
  31175. 0xDB, 0x91, 0x75, 0x30, 0xDF, 0x13, 0x02, 0xA5,
  31176. 0xF8, 0xC1, 0x8D, 0xC6, 0x42, 0xD5, 0x24, 0x78,
  31177. 0xC9, 0x8C, 0x12, 0xA3, 0xF1, 0x6E, 0xF2, 0xB6,
  31178. 0x2B, 0x4F, 0x59, 0xEA, 0x1B, 0xB5, 0x8D, 0xE7,
  31179. 0xB6, 0x5B, 0x3C, 0x71, 0x53, 0xCE, 0x6D, 0xA5,
  31180. 0xE4, 0x95, 0x07, 0x46, 0xF8, 0x0E, 0x08, 0x7A,
  31181. 0x0E, 0x35, 0x86, 0xD0, 0x97, 0x79, 0x1B, 0xF3,
  31182. 0x6D, 0xEF, 0x86, 0x5D, 0x68, 0x59, 0x1D, 0x39,
  31183. 0xD0, 0x90, 0x37, 0x73, 0xEE, 0xA9, 0x62, 0x14,
  31184. 0x7F, 0x34, 0x70, 0x41, 0x38, 0xB5, 0x4D, 0xF7,
  31185. 0x92, 0x4C, 0xDD, 0x8C, 0x33, 0x3D, 0xB5, 0xE1,
  31186. 0xA4, 0x09, 0xCC, 0xB2, 0xB3, 0x4E, 0x2C, 0x3C,
  31187. 0x8C, 0x7F, 0xDD, 0x3F, 0xD8, 0xD0, 0x12, 0xCB,
  31188. 0xF3, 0x82, 0xAA, 0xA8, 0x5E, 0x83, 0xA1, 0x2F,
  31189. 0x23, 0x5A, 0x2D, 0x14, 0x7D, 0x03, 0x5B, 0x7B,
  31190. 0x28, 0xB3, 0x4B, 0x6F, 0x57, 0x94, 0x9F, 0x32,
  31191. 0x24, 0x82, 0xA7, 0xD4, 0xD3, 0xB1, 0x50, 0x45,
  31192. 0xC4, 0x20, 0xD5, 0xAD, 0xDC, 0x7F, 0x0E, 0x69,
  31193. 0xB4, 0xDC, 0x1C, 0xBA, 0x58, 0xB0, 0x1D, 0x87,
  31194. 0x24, 0x80, 0xB0, 0x6A, 0x26, 0x0D, 0x82, 0x7D,
  31195. 0x89, 0x1B, 0x13, 0xC4, 0xC5, 0xCA, 0x50, 0xC7,
  31196. 0x48, 0xDE, 0x3C, 0x77, 0x1B, 0xE6, 0x1E, 0x9A,
  31197. 0xA1, 0x70, 0x16, 0x5C, 0xB0, 0x1F, 0x4B, 0xF5,
  31198. 0xDA, 0x27, 0xA7, 0x79, 0x1D, 0x3A, 0xD3, 0xF6,
  31199. 0x26, 0x7B, 0x4C, 0xB4, 0xE6, 0x1B, 0x28, 0xFA,
  31200. 0x17, 0x08, 0x41, 0x8D, 0x93, 0x2D, 0xFC, 0x41,
  31201. 0x61, 0x88, 0x0C, 0x5D, 0x3B, 0x17, 0xA9, 0x66,
  31202. 0x3A, 0x90, 0x61, 0xFA, 0x8F, 0x18, 0x04, 0x31,
  31203. 0x58, 0x50, 0xFE, 0x4E, 0x73, 0x06, 0xC8, 0x82,
  31204. 0xB3, 0x82, 0x27, 0xE8, 0x67, 0xF8, 0x08, 0x72,
  31205. 0xCD, 0xC1, 0x94, 0x4D, 0x47, 0x26, 0x15, 0xEA,
  31206. 0x49, 0x00, 0xEF, 0x7D, 0x27, 0x0B, 0x88, 0x1D,
  31207. 0x41, 0x30, 0xF5, 0x6C, 0x5C, 0xC9, 0x80, 0xD9,
  31208. 0x2A, 0x47, 0xAD, 0xA6, 0x65, 0x7E, 0xB6, 0xF3,
  31209. 0x7A, 0x38, 0x5D, 0x2D, 0x8C, 0xC9, 0x93, 0xE1,
  31210. 0x44, 0x2E, 0xB0, 0x52, 0x81, 0x85, 0x36, 0x36,
  31211. 0x99, 0x1E, 0x34, 0xAA, 0xDC, 0x68, 0x95, 0x4D,
  31212. 0x04, 0xE7, 0xAD, 0xEF, 0x76, 0xBF, 0x88, 0x0F,
  31213. 0x05, 0x9B, 0x0C, 0xBB, 0x55, 0xD9, 0x15, 0xA4,
  31214. 0xB1, 0x23, 0xE2, 0xF1, 0x33, 0x9A, 0x07, 0x3C,
  31215. 0xBF, 0xBC, 0x40, 0x9B, 0xEF, 0xF6, 0x40, 0x0A,
  31216. 0xE0, 0x96, 0xD5, 0xAE, 0x18, 0xEC, 0x42, 0xCF,
  31217. 0xFA, 0xD5, 0xB4, 0x98, 0x0F, 0xA3, 0x5B, 0xF0,
  31218. 0x34, 0x13, 0xAD, 0xB5, 0xD7, 0xE6, 0x87, 0x6A,
  31219. 0xC3, 0x55, 0xD1, 0xC9, 0xED, 0x70, 0xCA, 0x2B,
  31220. 0x97, 0x39, 0x54, 0xD1, 0x2B, 0x3C, 0xDD, 0x76,
  31221. 0xAC, 0x68, 0x35, 0xDB, 0x96, 0x00, 0x3E, 0xD8,
  31222. 0xC4, 0xE2, 0x88, 0xB7, 0x1F, 0xD7, 0x7D, 0xBA,
  31223. 0xA7, 0x63, 0x57, 0x20, 0xE1, 0x2A, 0xE0, 0xA3,
  31224. 0x17, 0xDE, 0x80, 0x8C, 0x66, 0x4E, 0x31, 0x7F,
  31225. 0x55, 0x27, 0x57, 0x91, 0xF3, 0x24, 0x5C, 0xA4,
  31226. 0xFE, 0x5D, 0x4D, 0x41, 0x07, 0x7F, 0xC1, 0x50,
  31227. 0xA6, 0xE4, 0x03, 0xD5, 0xA2, 0x08, 0xE4, 0x6E,
  31228. 0xAD, 0xBE, 0x8F, 0x2C, 0xFB, 0x8A, 0xF4, 0x72,
  31229. 0xF4, 0xA0, 0xCE, 0xAC, 0x01, 0x52, 0x19, 0x47,
  31230. 0x8E, 0x6B, 0x86, 0xC9, 0x58, 0xCF, 0x86, 0x52,
  31231. 0x5B, 0x74, 0x85, 0xC1, 0x73, 0x4C, 0x7E, 0xF0,
  31232. 0x0E, 0x90, 0x68, 0x3F, 0xFF, 0x5D, 0xBD, 0x0A,
  31233. 0x7D, 0x41, 0x3A, 0x85, 0x50, 0x21, 0x02, 0x6A,
  31234. 0x1B, 0x32, 0x01, 0x3A, 0x46, 0x16, 0xCB, 0xCD,
  31235. 0x37, 0x00, 0xAC, 0xBC, 0x70, 0x5B, 0xE3, 0xEF,
  31236. 0xBA, 0x62, 0x5C, 0x69, 0xA0, 0x25, 0x26, 0x7B,
  31237. 0xCE, 0x9D, 0x13, 0x5E, 0x3F, 0x5B, 0x5C, 0xC8,
  31238. 0xC4, 0x39, 0x56, 0x40, 0x7E, 0x84, 0xB6, 0x66,
  31239. 0x31, 0x03, 0xE2, 0x9C, 0x24, 0x20, 0x35, 0x55,
  31240. 0x1A, 0xE7, 0x97, 0xF5, 0x6C, 0x63, 0x74, 0xBE,
  31241. 0x0C, 0x79, 0x8C, 0x0C, 0xF3, 0x98, 0xF1, 0xED
  31242. };
  31243. static const byte sk_65[] = {
  31244. 0xD2, 0xFD, 0x03, 0xF3, 0xA1, 0xB7, 0xF6, 0x35,
  31245. 0xAF, 0x9F, 0x34, 0xD5, 0x80, 0xA9, 0x8F, 0x52,
  31246. 0x4C, 0x73, 0x5B, 0xD5, 0xBA, 0x23, 0x55, 0xDC,
  31247. 0x6E, 0x03, 0x5B, 0xD2, 0x17, 0x65, 0x58, 0x0C,
  31248. 0xE3, 0x8D, 0x1C, 0x14, 0xF6, 0x46, 0x7C, 0x35,
  31249. 0xA9, 0xF3, 0x80, 0xD2, 0x7D, 0xE6, 0x1F, 0x7C,
  31250. 0x75, 0x03, 0x15, 0x69, 0xEA, 0x2E, 0xC8, 0x26,
  31251. 0x0E, 0xEE, 0x91, 0x05, 0x26, 0x1B, 0x7F, 0xE1,
  31252. 0x60, 0xC9, 0x13, 0x44, 0xB0, 0xC6, 0x76, 0x4C,
  31253. 0x20, 0x4E, 0x5B, 0x8D, 0x42, 0x46, 0x50, 0xBE,
  31254. 0xC0, 0x6B, 0x9E, 0x2E, 0x62, 0x5A, 0xF0, 0x7E,
  31255. 0x23, 0xF4, 0x95, 0x0C, 0xA2, 0x4F, 0xB4, 0xD6,
  31256. 0xEC, 0x2C, 0x8B, 0x3A, 0x71, 0x7C, 0x93, 0x11,
  31257. 0xEB, 0x87, 0x27, 0x9F, 0xE2, 0x5E, 0x31, 0x1F,
  31258. 0x48, 0xB8, 0x25, 0x65, 0x01, 0xF6, 0x46, 0x34,
  31259. 0x12, 0xB5, 0x0D, 0xBC, 0x89, 0xA8, 0x69, 0xBA,
  31260. 0x22, 0x41, 0x11, 0x26, 0x48, 0x40, 0x07, 0x38,
  31261. 0x73, 0x02, 0x12, 0x44, 0x25, 0x44, 0x57, 0x54,
  31262. 0x83, 0x72, 0x50, 0x33, 0x35, 0x62, 0x58, 0x42,
  31263. 0x32, 0x01, 0x62, 0x11, 0x83, 0x61, 0x02, 0x45,
  31264. 0x66, 0x56, 0x48, 0x35, 0x61, 0x20, 0x84, 0x52,
  31265. 0x60, 0x68, 0x50, 0x45, 0x65, 0x55, 0x12, 0x72,
  31266. 0x47, 0x47, 0x21, 0x21, 0x25, 0x40, 0x22, 0x21,
  31267. 0x42, 0x81, 0x17, 0x65, 0x03, 0x06, 0x42, 0x61,
  31268. 0x52, 0x13, 0x43, 0x25, 0x24, 0x33, 0x82, 0x12,
  31269. 0x11, 0x35, 0x62, 0x33, 0x32, 0x07, 0x47, 0x86,
  31270. 0x22, 0x31, 0x50, 0x83, 0x70, 0x84, 0x26, 0x43,
  31271. 0x45, 0x64, 0x51, 0x48, 0x31, 0x14, 0x86, 0x24,
  31272. 0x66, 0x86, 0x74, 0x33, 0x71, 0x36, 0x67, 0x26,
  31273. 0x01, 0x47, 0x07, 0x72, 0x11, 0x61, 0x58, 0x85,
  31274. 0x58, 0x38, 0x71, 0x83, 0x80, 0x67, 0x01, 0x65,
  31275. 0x78, 0x70, 0x64, 0x77, 0x85, 0x60, 0x02, 0x88,
  31276. 0x53, 0x48, 0x46, 0x62, 0x25, 0x83, 0x54, 0x88,
  31277. 0x04, 0x74, 0x40, 0x12, 0x57, 0x43, 0x71, 0x07,
  31278. 0x75, 0x44, 0x38, 0x71, 0x21, 0x14, 0x22, 0x08,
  31279. 0x88, 0x72, 0x23, 0x58, 0x87, 0x46, 0x14, 0x85,
  31280. 0x53, 0x71, 0x67, 0x73, 0x82, 0x28, 0x22, 0x74,
  31281. 0x14, 0x03, 0x57, 0x73, 0x28, 0x71, 0x83, 0x80,
  31282. 0x78, 0x14, 0x34, 0x87, 0x52, 0x07, 0x64, 0x74,
  31283. 0x01, 0x60, 0x75, 0x61, 0x06, 0x08, 0x61, 0x32,
  31284. 0x21, 0x46, 0x15, 0x65, 0x42, 0x67, 0x08, 0x20,
  31285. 0x84, 0x10, 0x73, 0x13, 0x03, 0x61, 0x02, 0x86,
  31286. 0x50, 0x45, 0x26, 0x12, 0x16, 0x68, 0x33, 0x55,
  31287. 0x25, 0x84, 0x73, 0x53, 0x54, 0x52, 0x65, 0x17,
  31288. 0x10, 0x60, 0x00, 0x38, 0x57, 0x77, 0x81, 0x24,
  31289. 0x26, 0x80, 0x41, 0x46, 0x43, 0x26, 0x67, 0x41,
  31290. 0x06, 0x03, 0x55, 0x41, 0x28, 0x33, 0x37, 0x25,
  31291. 0x23, 0x06, 0x77, 0x82, 0x15, 0x16, 0x31, 0x73,
  31292. 0x00, 0x08, 0x75, 0x26, 0x58, 0x46, 0x34, 0x63,
  31293. 0x88, 0x08, 0x84, 0x64, 0x51, 0x11, 0x24, 0x05,
  31294. 0x32, 0x10, 0x11, 0x18, 0x18, 0x64, 0x78, 0x22,
  31295. 0x41, 0x00, 0x38, 0x55, 0x75, 0x42, 0x10, 0x46,
  31296. 0x83, 0x43, 0x73, 0x38, 0x80, 0x07, 0x83, 0x43,
  31297. 0x78, 0x74, 0x13, 0x57, 0x62, 0x32, 0x68, 0x80,
  31298. 0x65, 0x86, 0x48, 0x53, 0x48, 0x35, 0x51, 0x58,
  31299. 0x50, 0x74, 0x46, 0x05, 0x88, 0x70, 0x07, 0x72,
  31300. 0x01, 0x31, 0x00, 0x87, 0x54, 0x88, 0x14, 0x20,
  31301. 0x84, 0x16, 0x61, 0x15, 0x60, 0x56, 0x85, 0x11,
  31302. 0x58, 0x08, 0x05, 0x88, 0x63, 0x01, 0x82, 0x86,
  31303. 0x13, 0x14, 0x17, 0x22, 0x01, 0x68, 0x17, 0x17,
  31304. 0x86, 0x58, 0x53, 0x10, 0x62, 0x28, 0x52, 0x82,
  31305. 0x26, 0x15, 0x04, 0x31, 0x42, 0x88, 0x54, 0x31,
  31306. 0x78, 0x05, 0x80, 0x11, 0x50, 0x45, 0x68, 0x82,
  31307. 0x33, 0x66, 0x36, 0x36, 0x40, 0x65, 0x15, 0x24,
  31308. 0x47, 0x67, 0x06, 0x45, 0x36, 0x42, 0x26, 0x86,
  31309. 0x75, 0x06, 0x35, 0x41, 0x33, 0x47, 0x85, 0x12,
  31310. 0x17, 0x80, 0x83, 0x87, 0x65, 0x51, 0x42, 0x31,
  31311. 0x38, 0x87, 0x56, 0x62, 0x05, 0x17, 0x40, 0x85,
  31312. 0x28, 0x14, 0x17, 0x21, 0x38, 0x12, 0x60, 0x81,
  31313. 0x24, 0x41, 0x45, 0x75, 0x01, 0x82, 0x87, 0x10,
  31314. 0x10, 0x02, 0x13, 0x25, 0x57, 0x04, 0x21, 0x72,
  31315. 0x42, 0x78, 0x61, 0x11, 0x70, 0x05, 0x30, 0x47,
  31316. 0x72, 0x13, 0x20, 0x30, 0x21, 0x67, 0x44, 0x31,
  31317. 0x57, 0x71, 0x45, 0x57, 0x10, 0x54, 0x16, 0x65,
  31318. 0x74, 0x15, 0x24, 0x02, 0x43, 0x71, 0x51, 0x20,
  31319. 0x55, 0x11, 0x67, 0x83, 0x67, 0x82, 0x52, 0x53,
  31320. 0x35, 0x66, 0x42, 0x46, 0x13, 0x70, 0x22, 0x32,
  31321. 0x74, 0x00, 0x07, 0x06, 0x81, 0x87, 0x17, 0x57,
  31322. 0x80, 0x28, 0x68, 0x01, 0x72, 0x10, 0x04, 0x27,
  31323. 0x55, 0x22, 0x86, 0x42, 0x53, 0x15, 0x81, 0x76,
  31324. 0x30, 0x86, 0x40, 0x83, 0x11, 0x43, 0x30, 0x53,
  31325. 0x82, 0x73, 0x53, 0x03, 0x72, 0x35, 0x68, 0x70,
  31326. 0x45, 0x41, 0x15, 0x73, 0x14, 0x12, 0x31, 0x64,
  31327. 0x32, 0x66, 0x63, 0x56, 0x21, 0x51, 0x50, 0x82,
  31328. 0x10, 0x30, 0x23, 0x38, 0x17, 0x21, 0x27, 0x10,
  31329. 0x23, 0x14, 0x22, 0x75, 0x77, 0x28, 0x37, 0x71,
  31330. 0x62, 0x75, 0x06, 0x88, 0x72, 0x14, 0x18, 0x73,
  31331. 0x13, 0x03, 0x01, 0x50, 0x71, 0x58, 0x62, 0x86,
  31332. 0x62, 0x88, 0x86, 0x86, 0x03, 0x27, 0x01, 0x46,
  31333. 0x17, 0x22, 0x71, 0x38, 0x53, 0x81, 0x70, 0x33,
  31334. 0x88, 0x68, 0x13, 0x78, 0x81, 0x04, 0x86, 0x57,
  31335. 0x30, 0x16, 0x52, 0x31, 0x40, 0x83, 0x07, 0x56,
  31336. 0x82, 0x10, 0x32, 0x31, 0x28, 0x50, 0x06, 0x50,
  31337. 0x81, 0x63, 0x06, 0x75, 0x76, 0x65, 0x11, 0x60,
  31338. 0x14, 0x17, 0x12, 0x12, 0x55, 0x56, 0x48, 0x11,
  31339. 0x41, 0x13, 0x28, 0x82, 0x62, 0x07, 0x47, 0x64,
  31340. 0x24, 0x48, 0x23, 0x24, 0x77, 0x53, 0x26, 0x08,
  31341. 0x17, 0x58, 0x11, 0x56, 0x37, 0x48, 0x35, 0x51,
  31342. 0x47, 0x86, 0x85, 0x66, 0x66, 0x81, 0x73, 0x20,
  31343. 0x21, 0x36, 0x75, 0x22, 0x74, 0x66, 0x83, 0x44,
  31344. 0x57, 0x00, 0x66, 0x64, 0x77, 0x20, 0x47, 0x22,
  31345. 0x28, 0x56, 0x87, 0x12, 0x47, 0x02, 0x48, 0x07,
  31346. 0x02, 0x54, 0x23, 0x01, 0x25, 0x71, 0x37, 0x36,
  31347. 0x75, 0x36, 0x00, 0x52, 0x68, 0x15, 0x33, 0x35,
  31348. 0x82, 0x06, 0x13, 0x73, 0x24, 0x08, 0x71, 0x76,
  31349. 0x15, 0x22, 0x42, 0x60, 0x18, 0x53, 0x43, 0x11,
  31350. 0x64, 0x57, 0x76, 0x17, 0x61, 0x56, 0x68, 0x76,
  31351. 0x60, 0x65, 0x54, 0x78, 0x10, 0x33, 0x63, 0x14,
  31352. 0x21, 0x83, 0x21, 0x60, 0x15, 0x55, 0x80, 0x42,
  31353. 0x38, 0x42, 0x03, 0x13, 0x12, 0x34, 0x36, 0x25,
  31354. 0x27, 0x30, 0x82, 0x81, 0x25, 0x47, 0x51, 0x35,
  31355. 0x44, 0x12, 0x67, 0x35, 0x00, 0x10, 0x01, 0x83,
  31356. 0x85, 0x74, 0x42, 0x40, 0x13, 0x03, 0x61, 0x27,
  31357. 0x81, 0x26, 0x26, 0x81, 0x18, 0x87, 0x43, 0x51,
  31358. 0x20, 0x62, 0x71, 0x27, 0x51, 0x56, 0x10, 0x22,
  31359. 0x22, 0x81, 0x11, 0x81, 0x41, 0x66, 0x66, 0x38,
  31360. 0x20, 0x86, 0x75, 0x56, 0x12, 0x40, 0x06, 0x54,
  31361. 0x61, 0x12, 0x74, 0x40, 0x34, 0x58, 0x58, 0x78,
  31362. 0x10, 0x07, 0x85, 0x25, 0x72, 0x88, 0x57, 0x22,
  31363. 0x22, 0x25, 0x50, 0x84, 0x00, 0x41, 0x26, 0x08,
  31364. 0x36, 0x46, 0x28, 0x78, 0x46, 0x78, 0x05, 0x02,
  31365. 0x28, 0x20, 0x77, 0x13, 0x60, 0x75, 0x14, 0x43,
  31366. 0x68, 0x78, 0x64, 0x31, 0x38, 0x77, 0x73, 0x73,
  31367. 0x55, 0x41, 0x27, 0x00, 0x54, 0x07, 0x08, 0x28,
  31368. 0x68, 0x80, 0x04, 0x53, 0x83, 0x43, 0x22, 0x81,
  31369. 0x00, 0x64, 0x35, 0x48, 0x67, 0x66, 0x50, 0x17,
  31370. 0x75, 0x76, 0x12, 0x75, 0x43, 0x81, 0x62, 0x40,
  31371. 0x33, 0x43, 0x45, 0x38, 0x87, 0x21, 0x66, 0x14,
  31372. 0x70, 0x48, 0x41, 0x43, 0x14, 0x66, 0x58, 0x78,
  31373. 0x45, 0x82, 0x02, 0x25, 0x45, 0x73, 0x15, 0x21,
  31374. 0x32, 0x03, 0x02, 0x48, 0x80, 0x80, 0x13, 0x71,
  31375. 0x25, 0x54, 0x32, 0x72, 0x05, 0x68, 0x65, 0x24,
  31376. 0x68, 0x04, 0x06, 0x16, 0x83, 0x50, 0x54, 0x53,
  31377. 0x37, 0x37, 0x27, 0x22, 0x20, 0x68, 0x08, 0x25,
  31378. 0x50, 0x84, 0x72, 0x86, 0x74, 0x22, 0x36, 0x16,
  31379. 0x80, 0x07, 0x55, 0x18, 0x12, 0x17, 0x84, 0x44,
  31380. 0x81, 0x15, 0x64, 0x50, 0x71, 0x10, 0x58, 0x15,
  31381. 0x51, 0x10, 0x10, 0x47, 0x16, 0x21, 0x07, 0x58,
  31382. 0x61, 0x18, 0x78, 0x00, 0x52, 0x72, 0x64, 0x52,
  31383. 0x17, 0x43, 0x23, 0x40, 0x76, 0x48, 0x67, 0x30,
  31384. 0x77, 0x63, 0x64, 0x87, 0x51, 0x31, 0x63, 0x84,
  31385. 0x68, 0x74, 0x53, 0x63, 0x84, 0x23, 0x54, 0x66,
  31386. 0x10, 0x48, 0x36, 0x33, 0x85, 0x21, 0x48, 0x42,
  31387. 0x03, 0x82, 0x51, 0x10, 0x33, 0x57, 0x46, 0x80,
  31388. 0x16, 0x43, 0x34, 0x02, 0x07, 0x03, 0x53, 0x22,
  31389. 0x12, 0x75, 0x73, 0x34, 0x65, 0x83, 0x33, 0x87,
  31390. 0x43, 0x85, 0x17, 0x50, 0x36, 0x60, 0x88, 0x02,
  31391. 0x58, 0x75, 0x80, 0x88, 0x31, 0x63, 0x60, 0x18,
  31392. 0x21, 0x32, 0x26, 0x15, 0x68, 0x74, 0x11, 0x10,
  31393. 0x33, 0x14, 0x13, 0x05, 0x34, 0x16, 0x72, 0x65,
  31394. 0x35, 0x50, 0x13, 0x34, 0x80, 0x87, 0x10, 0x26,
  31395. 0x48, 0x68, 0x84, 0x52, 0x71, 0x44, 0x23, 0x58,
  31396. 0x80, 0x35, 0x57, 0x70, 0x54, 0x84, 0x28, 0x70,
  31397. 0x55, 0x88, 0x86, 0x83, 0x86, 0x25, 0x21, 0x82,
  31398. 0x72, 0x61, 0x17, 0x78, 0x85, 0x17, 0x67, 0x73,
  31399. 0x00, 0x57, 0x71, 0x11, 0x78, 0x51, 0x10, 0x65,
  31400. 0x63, 0x57, 0x02, 0x87, 0x40, 0x13, 0x40, 0x01,
  31401. 0x26, 0x53, 0x45, 0x12, 0x05, 0x46, 0x75, 0x18,
  31402. 0x80, 0x70, 0x33, 0x35, 0x66, 0x22, 0x62, 0x00,
  31403. 0x70, 0x23, 0x26, 0x87, 0x72, 0x63, 0x11, 0x13,
  31404. 0x33, 0x33, 0x81, 0x41, 0x70, 0x62, 0x28, 0x61,
  31405. 0x51, 0x47, 0x31, 0x30, 0x25, 0x46, 0x51, 0x17,
  31406. 0x61, 0x58, 0x07, 0x41, 0x61, 0x37, 0x37, 0x06,
  31407. 0x14, 0x00, 0x54, 0x88, 0x77, 0x75, 0x67, 0x77,
  31408. 0x66, 0x53, 0x16, 0x72, 0x66, 0x66, 0x88, 0x76,
  31409. 0x43, 0x58, 0x31, 0x04, 0x87, 0x57, 0x06, 0x76,
  31410. 0x47, 0x00, 0x43, 0x63, 0x58, 0x60, 0x52, 0x03,
  31411. 0x44, 0x27, 0x36, 0x48, 0x61, 0x23, 0x72, 0x16,
  31412. 0x10, 0x62, 0x42, 0x08, 0x60, 0x83, 0x23, 0x54,
  31413. 0x03, 0x55, 0x55, 0x73, 0x00, 0x61, 0x03, 0x65,
  31414. 0x34, 0x27, 0x14, 0x15, 0x86, 0x62, 0x55, 0x80,
  31415. 0x16, 0x53, 0x10, 0x18, 0x26, 0x11, 0x35, 0x46,
  31416. 0x82, 0x46, 0x13, 0x25, 0x83, 0x47, 0x70, 0x50,
  31417. 0x06, 0x01, 0x56, 0x02, 0x11, 0x68, 0x54, 0x53,
  31418. 0x03, 0x68, 0x73, 0x36, 0x41, 0x88, 0x86, 0x33,
  31419. 0x42, 0x52, 0x01, 0x58, 0x33, 0x42, 0x32, 0x88,
  31420. 0x56, 0x81, 0x77, 0x55, 0x51, 0x48, 0x48, 0x12,
  31421. 0x01, 0x58, 0x13, 0x85, 0x04, 0x14, 0x71, 0x83,
  31422. 0x57, 0x07, 0x54, 0x55, 0x54, 0x55, 0x28, 0x27,
  31423. 0x31, 0x36, 0x02, 0x12, 0x32, 0x68, 0x32, 0x13,
  31424. 0x82, 0x58, 0x70, 0x28, 0x58, 0x53, 0x44, 0x86,
  31425. 0x72, 0x73, 0x42, 0x84, 0x18, 0x22, 0x08, 0x83,
  31426. 0x61, 0x02, 0x14, 0x16, 0x17, 0x12, 0x41, 0x57,
  31427. 0x48, 0x85, 0x25, 0x10, 0x26, 0x07, 0x36, 0x76,
  31428. 0x12, 0x66, 0x17, 0x21, 0x32, 0x36, 0x03, 0x25,
  31429. 0x41, 0x10, 0x11, 0x22, 0x66, 0x60, 0x16, 0x16,
  31430. 0x32, 0x64, 0x26, 0x05, 0x18, 0x63, 0x51, 0x58,
  31431. 0x51, 0x31, 0x42, 0x53, 0x84, 0x56, 0x66, 0x27,
  31432. 0x83, 0x33, 0x54, 0x50, 0x76, 0x46, 0x50, 0x80,
  31433. 0x25, 0x43, 0x41, 0x57, 0x35, 0x78, 0x25, 0x43,
  31434. 0x02, 0x82, 0x38, 0x47, 0x45, 0x70, 0x15, 0x67,
  31435. 0x51, 0x77, 0x47, 0x80, 0x31, 0x52, 0x75, 0x00,
  31436. 0x00, 0x94, 0x7B, 0xCA, 0x93, 0xC2, 0x7D, 0x58,
  31437. 0x4E, 0x2C, 0x66, 0xEA, 0xC9, 0xC7, 0x64, 0x0C,
  31438. 0x1C, 0xA2, 0x17, 0xEE, 0xF6, 0x6D, 0xAB, 0xBC,
  31439. 0xB2, 0x60, 0xB4, 0xC3, 0x43, 0x00, 0xFA, 0x05,
  31440. 0x13, 0x57, 0x82, 0x0F, 0x57, 0x39, 0x25, 0x44,
  31441. 0x98, 0x2F, 0xD1, 0x10, 0x57, 0xDE, 0x23, 0x3E,
  31442. 0x6D, 0x2D, 0xD8, 0x49, 0x72, 0xA7, 0xE4, 0x7D,
  31443. 0x4D, 0xBA, 0x99, 0xBC, 0x30, 0xCF, 0x8F, 0x2A,
  31444. 0xD5, 0xA2, 0xC0, 0x24, 0x31, 0x95, 0xED, 0x27,
  31445. 0x30, 0xFF, 0xA9, 0x2D, 0x22, 0x7D, 0x15, 0x30,
  31446. 0x95, 0x97, 0x2D, 0x4B, 0x34, 0x47, 0xFF, 0xAC,
  31447. 0x45, 0xA2, 0x3E, 0xB4, 0x1C, 0xBC, 0x87, 0xCD,
  31448. 0xD1, 0x25, 0x0A, 0x8A, 0x47, 0x8B, 0x0F, 0x7A,
  31449. 0x1D, 0x5B, 0x39, 0xAA, 0x22, 0x06, 0xE4, 0x86,
  31450. 0x45, 0x58, 0x4F, 0xE7, 0xBF, 0x7A, 0x13, 0x16,
  31451. 0x8F, 0x48, 0x27, 0x65, 0xE5, 0x7B, 0xB9, 0x24,
  31452. 0xAC, 0x6D, 0x9A, 0x11, 0x36, 0x9F, 0x4A, 0x6A,
  31453. 0xFF, 0xCD, 0x16, 0x9B, 0x7D, 0x75, 0x12, 0x9B,
  31454. 0x35, 0xD5, 0x13, 0x4A, 0x31, 0x76, 0x1B, 0xB8,
  31455. 0x35, 0x5A, 0xEE, 0xED, 0x27, 0xE2, 0x01, 0xA0,
  31456. 0x63, 0x13, 0x01, 0x3E, 0x30, 0x7A, 0x01, 0xA7,
  31457. 0x3A, 0xEA, 0x79, 0x55, 0xC0, 0x57, 0x8C, 0x8C,
  31458. 0x5E, 0x5A, 0x1A, 0x2D, 0x2F, 0xA4, 0x59, 0x3F,
  31459. 0xAC, 0xD9, 0x04, 0xC6, 0x20, 0x40, 0xBD, 0xB9,
  31460. 0xF3, 0x29, 0x93, 0x35, 0x36, 0xBF, 0x8D, 0x81,
  31461. 0xC4, 0x25, 0x6B, 0xAA, 0xE8, 0x72, 0x3F, 0xD4,
  31462. 0xDC, 0x66, 0xBB, 0x5E, 0x7F, 0x9C, 0xA4, 0x90,
  31463. 0x31, 0xA1, 0x93, 0xEC, 0xEC, 0xBB, 0x5D, 0xC3,
  31464. 0x90, 0xEC, 0x6D, 0x55, 0x13, 0xC7, 0x9A, 0x05,
  31465. 0x2B, 0x3F, 0xD4, 0x36, 0x12, 0xFB, 0x73, 0x75,
  31466. 0x31, 0x5D, 0x80, 0x91, 0xF7, 0x9B, 0xAB, 0x13,
  31467. 0x18, 0xF1, 0x78, 0x54, 0x56, 0x1B, 0xC9, 0x3A,
  31468. 0xE0, 0xE5, 0xCD, 0x6D, 0x13, 0x1E, 0x56, 0x2C,
  31469. 0x81, 0x14, 0x81, 0x0C, 0x93, 0x9A, 0xE5, 0x63,
  31470. 0xAA, 0x10, 0xB4, 0x7C, 0xE4, 0x48, 0x43, 0x17,
  31471. 0xF3, 0x4A, 0xBD, 0x02, 0xD0, 0xCC, 0xAD, 0x58,
  31472. 0xDD, 0x29, 0xBC, 0xF6, 0x57, 0xBB, 0xD9, 0x25,
  31473. 0x4B, 0x01, 0xCA, 0x97, 0x26, 0x09, 0x19, 0x38,
  31474. 0xED, 0x32, 0x05, 0x4B, 0x37, 0xDD, 0x61, 0x72,
  31475. 0x40, 0xF4, 0x43, 0x4C, 0x1A, 0x4A, 0x87, 0x11,
  31476. 0xAA, 0x3A, 0x39, 0x9A, 0x8A, 0x53, 0x88, 0x33,
  31477. 0x0B, 0x70, 0x59, 0xEC, 0xCB, 0xB6, 0xB1, 0xB9,
  31478. 0xCF, 0x71, 0x87, 0xAD, 0xF1, 0x0B, 0x0C, 0x91,
  31479. 0x71, 0xD3, 0xC0, 0xF6, 0xE2, 0xD4, 0x60, 0xA4,
  31480. 0x19, 0x24, 0x76, 0x72, 0xE3, 0xB9, 0xFE, 0xA2,
  31481. 0xC9, 0x59, 0x10, 0xBF, 0x2F, 0xB6, 0xA5, 0xD6,
  31482. 0x1F, 0x25, 0x74, 0x53, 0xB0, 0x7A, 0xFB, 0x64,
  31483. 0xB0, 0xBA, 0x27, 0x58, 0xBC, 0xD7, 0x35, 0x75,
  31484. 0x1F, 0x2D, 0x53, 0x51, 0x5E, 0x23, 0x6F, 0xE8,
  31485. 0xA5, 0xB4, 0x39, 0x3B, 0x80, 0xBF, 0x06, 0xDF,
  31486. 0x97, 0xBD, 0xC6, 0x38, 0x00, 0x87, 0xE6, 0xAA,
  31487. 0x8D, 0xDE, 0x6E, 0x09, 0x81, 0x11, 0xA7, 0x34,
  31488. 0x3F, 0xCD, 0xD1, 0xE9, 0x03, 0x70, 0x8E, 0x63,
  31489. 0x7E, 0xBF, 0x28, 0x32, 0x3C, 0xDA, 0x6B, 0x94,
  31490. 0x05, 0x81, 0x0E, 0xDC, 0xFB, 0x36, 0x91, 0x14,
  31491. 0x9E, 0xCF, 0x22, 0x4C, 0x50, 0xF8, 0xDF, 0x92,
  31492. 0xA9, 0x4A, 0xA4, 0x77, 0x0A, 0x0E, 0x91, 0x46,
  31493. 0x61, 0x94, 0xBB, 0x0E, 0x27, 0xBF, 0x1C, 0xAB,
  31494. 0xF1, 0x6A, 0xDF, 0xD3, 0x51, 0x22, 0x00, 0x33,
  31495. 0xF7, 0x6F, 0x59, 0x25, 0x55, 0x7B, 0xCF, 0x96,
  31496. 0x34, 0xE9, 0x46, 0x13, 0x59, 0x62, 0x1D, 0x80,
  31497. 0xB4, 0xBB, 0xAD, 0x7E, 0x2A, 0x6E, 0x43, 0x2D,
  31498. 0xC4, 0x3B, 0x12, 0x6C, 0xA4, 0x2A, 0xB8, 0x8A,
  31499. 0xA8, 0x8F, 0x0A, 0x84, 0xAF, 0x58, 0x02, 0x9C,
  31500. 0x99, 0xA0, 0x24, 0x8F, 0x0C, 0x45, 0x40, 0x71,
  31501. 0xF3, 0x5B, 0x83, 0x1F, 0xED, 0x12, 0x54, 0xD6,
  31502. 0xF4, 0xE2, 0x72, 0x04, 0x85, 0x78, 0x62, 0x15,
  31503. 0xF7, 0xC7, 0xF0, 0xC4, 0xED, 0x15, 0xFA, 0x85,
  31504. 0x3C, 0xD3, 0xAA, 0x07, 0x25, 0x9B, 0x39, 0x24,
  31505. 0x0A, 0x82, 0x13, 0x5C, 0x29, 0x23, 0xA7, 0x2B,
  31506. 0x87, 0x6F, 0xAB, 0xB3, 0xF0, 0xF2, 0xC0, 0x96,
  31507. 0x13, 0xDE, 0x39, 0xD4, 0x59, 0xA0, 0x7C, 0x14,
  31508. 0xE7, 0xBA, 0x43, 0x7D, 0x80, 0x41, 0x49, 0x1F,
  31509. 0xCE, 0xC1, 0x43, 0x34, 0x04, 0xBA, 0xD1, 0xDA,
  31510. 0x9E, 0xE9, 0x47, 0x1E, 0x17, 0xCB, 0x69, 0x1B,
  31511. 0x2A, 0x35, 0x37, 0x10, 0xC9, 0xFF, 0xA4, 0xE5,
  31512. 0x17, 0x81, 0x12, 0x02, 0x77, 0x64, 0xEB, 0x7D,
  31513. 0xE8, 0x09, 0xC3, 0xE1, 0xF1, 0xFA, 0x41, 0x78,
  31514. 0xA5, 0xD4, 0xDC, 0x9E, 0xE2, 0x78, 0x57, 0xEF,
  31515. 0xF2, 0x6B, 0x91, 0x71, 0x1F, 0xC1, 0x44, 0xD5,
  31516. 0xA7, 0x75, 0xB8, 0xB5, 0x0D, 0x5D, 0xB9, 0x39,
  31517. 0xBA, 0x32, 0x07, 0x68, 0x0C, 0x24, 0x2F, 0xC8,
  31518. 0x21, 0x94, 0x7F, 0x93, 0x4C, 0x8D, 0xAE, 0xE2,
  31519. 0x03, 0x56, 0x3D, 0x28, 0x60, 0x6B, 0xE6, 0x24,
  31520. 0xA3, 0x29, 0x01, 0x93, 0x2D, 0xAE, 0x85, 0x71,
  31521. 0x2A, 0xF6, 0xC8, 0x01, 0x60, 0x26, 0x92, 0x7E,
  31522. 0x9B, 0x81, 0x29, 0x57, 0x4B, 0xE3, 0xCB, 0x1E,
  31523. 0x95, 0x33, 0x2B, 0x05, 0x27, 0x07, 0xAC, 0x8A,
  31524. 0xA8, 0xF4, 0x35, 0xE8, 0x8B, 0x7E, 0x56, 0x8D,
  31525. 0x49, 0x87, 0xC6, 0xAC, 0x0E, 0x90, 0x2B, 0x06,
  31526. 0x09, 0xA0, 0x2D, 0x91, 0xB3, 0xF5, 0xFD, 0x3F,
  31527. 0xD9, 0x01, 0xDD, 0xD0, 0xDB, 0x98, 0x73, 0xBD,
  31528. 0x7C, 0x71, 0xED, 0x92, 0x1D, 0x45, 0x77, 0xA7,
  31529. 0x8C, 0x4F, 0xCC, 0x9B, 0xF0, 0x75, 0x20, 0x3D,
  31530. 0x38, 0xF5, 0xE7, 0x6E, 0x74, 0xF2, 0x77, 0x48,
  31531. 0x4E, 0x05, 0x7B, 0x61, 0x89, 0x00, 0x41, 0x31,
  31532. 0xB0, 0xC9, 0xB1, 0xA1, 0x55, 0x29, 0x4D, 0x1C,
  31533. 0xD3, 0xD5, 0x20, 0x8E, 0x26, 0x69, 0x01, 0xD7,
  31534. 0xD3, 0x14, 0xFA, 0xCC, 0xE7, 0xE2, 0xAA, 0x58,
  31535. 0x45, 0x83, 0xA1, 0x1E, 0x4D, 0x7C, 0x21, 0xB9,
  31536. 0x4A, 0x32, 0xE5, 0x08, 0xED, 0xDB, 0xBD, 0x7A,
  31537. 0x65, 0xAA, 0x86, 0xB4, 0xFD, 0xFA, 0x6B, 0xC2,
  31538. 0x85, 0xD4, 0xCF, 0xF5, 0x39, 0x26, 0xC7, 0x17,
  31539. 0x3F, 0xBE, 0x1F, 0x89, 0xCC, 0x30, 0x32, 0x34,
  31540. 0xB8, 0x78, 0xC6, 0xB8, 0x10, 0x1F, 0x58, 0xAC,
  31541. 0x8D, 0x3E, 0x5E, 0x1B, 0xF5, 0xAB, 0x6B, 0x26,
  31542. 0x29, 0x7C, 0xC9, 0x7B, 0x95, 0x95, 0x4A, 0xAB,
  31543. 0xDB, 0x25, 0xBE, 0x00, 0x8A, 0x3F, 0x47, 0xE5,
  31544. 0x64, 0x87, 0xB0, 0x0D, 0x3D, 0xED, 0xA8, 0x90,
  31545. 0xD9, 0x2C, 0x83, 0x95, 0x7F, 0xEA, 0xC6, 0xB8,
  31546. 0x29, 0x1A, 0xF6, 0x59, 0x59, 0xE1, 0xD1, 0xFC,
  31547. 0xA3, 0xBD, 0x19, 0x6E, 0x9F, 0xC9, 0xE6, 0x7E,
  31548. 0x06, 0x07, 0x09, 0x48, 0x22, 0xE5, 0xB4, 0x19,
  31549. 0x1D, 0xB9, 0x68, 0x24, 0xB9, 0xF0, 0x3F, 0x2E,
  31550. 0xF5, 0x7F, 0x52, 0x38, 0xBA, 0x7E, 0x1E, 0x84,
  31551. 0xED, 0x55, 0xB7, 0xDF, 0xF3, 0xD6, 0xC2, 0xC1,
  31552. 0x27, 0x36, 0x92, 0xA9, 0xA1, 0x92, 0x72, 0x16,
  31553. 0x61, 0x30, 0xDB, 0x89, 0xFC, 0x67, 0xDC, 0x94,
  31554. 0xDB, 0x61, 0x4E, 0x3E, 0x82, 0xBA, 0x3A, 0x35,
  31555. 0x12, 0xB0, 0x12, 0xD5, 0x1F, 0xB4, 0x86, 0xB5,
  31556. 0xA3, 0x15, 0x0B, 0x78, 0xE7, 0x24, 0xE2, 0xA1,
  31557. 0x2D, 0xE0, 0x7D, 0x86, 0x71, 0xFB, 0xA2, 0xDA,
  31558. 0x7F, 0xD5, 0xD1, 0x47, 0x20, 0x8F, 0xC3, 0xAF,
  31559. 0x65, 0x3E, 0x65, 0x20, 0xFC, 0x40, 0x87, 0x1A,
  31560. 0xF2, 0x17, 0x7E, 0x65, 0xCB, 0xD0, 0xEA, 0xF3,
  31561. 0x04, 0x21, 0x7B, 0x36, 0x7A, 0x66, 0x5F, 0x22,
  31562. 0x4C, 0xAE, 0xDF, 0xE9, 0x30, 0x06, 0xAC, 0x1E,
  31563. 0x14, 0xBC, 0xD6, 0x7A, 0x88, 0xD1, 0x71, 0xF3,
  31564. 0xD8, 0xF3, 0xE3, 0x58, 0xA7, 0x19, 0x26, 0xBA,
  31565. 0x3E, 0x5C, 0x23, 0x9A, 0x53, 0x12, 0x63, 0xEC,
  31566. 0x94, 0x37, 0xBF, 0x2A, 0x03, 0x3B, 0x8B, 0x55,
  31567. 0xB2, 0xC0, 0xCB, 0x6E, 0x7E, 0x97, 0x31, 0x6E,
  31568. 0x22, 0xDF, 0x77, 0xCA, 0xD9, 0x10, 0xD2, 0x0E,
  31569. 0xEC, 0xE1, 0xC5, 0x09, 0x10, 0xA5, 0xCC, 0x32,
  31570. 0xAD, 0xAB, 0x09, 0x37, 0x75, 0x50, 0xF9, 0x2D,
  31571. 0x5B, 0xB1, 0xF4, 0xC0, 0x7F, 0x4A, 0x28, 0x22,
  31572. 0x33, 0x8E, 0x2C, 0xFF, 0x53, 0x48, 0xDF, 0x77,
  31573. 0xCF, 0x8E, 0xF8, 0xE6, 0x65, 0x7D, 0xED, 0x1E,
  31574. 0x0C, 0xE0, 0x58, 0xE3, 0xCC, 0xFB, 0xF3, 0x9B,
  31575. 0x3F, 0x16, 0x6E, 0x30, 0x3D, 0x33, 0xC3, 0x55,
  31576. 0x6C, 0x9A, 0xC8, 0xEC, 0xB3, 0xDF, 0x7C, 0x74,
  31577. 0xAB, 0x36, 0xD0, 0xF2, 0x79, 0x44, 0x41, 0xBA,
  31578. 0x98, 0x08, 0x82, 0x7B, 0x57, 0x8F, 0xB5, 0xC2,
  31579. 0x9E, 0x49, 0x4E, 0x21, 0x53, 0x9A, 0xD3, 0xAB,
  31580. 0x2B, 0x41, 0xBF, 0x16, 0x1D, 0x7F, 0x69, 0x58,
  31581. 0x9D, 0x45, 0x24, 0xC5, 0x4C, 0x89, 0xB4, 0x86,
  31582. 0xF7, 0x5D, 0x25, 0x2F, 0x54, 0x1C, 0xC6, 0x3B,
  31583. 0x9E, 0x70, 0x6D, 0x64, 0xA1, 0x28, 0x9A, 0x23,
  31584. 0x06, 0xC5, 0x95, 0x36, 0x3C, 0xB6, 0xFB, 0xEF,
  31585. 0x0A, 0x1B, 0x5B, 0x17, 0xAB, 0x5B, 0x17, 0x94,
  31586. 0xBF, 0x27, 0x03, 0x6F, 0x64, 0xEA, 0xF0, 0xBD,
  31587. 0x43, 0x0D, 0xD5, 0x8D, 0x80, 0x01, 0x0C, 0xCD,
  31588. 0xAD, 0xA4, 0xA5, 0xA3, 0xA1, 0xE4, 0x1A, 0x6F,
  31589. 0xBF, 0x12, 0x9D, 0x73, 0x77, 0x9A, 0x37, 0xAE,
  31590. 0x5C, 0x8D, 0x68, 0x41, 0xA9, 0x99, 0x3C, 0x51,
  31591. 0xE3, 0x64, 0xE0, 0x4F, 0xAC, 0x8E, 0x25, 0xA4,
  31592. 0xE6, 0x87, 0x2F, 0x6C, 0x86, 0x0F, 0xA2, 0x65,
  31593. 0xC1, 0xC4, 0x42, 0x6A, 0xD9, 0xC2, 0x1D, 0x26,
  31594. 0xDA, 0x8C, 0x27, 0x85, 0x46, 0xAD, 0xCD, 0x83,
  31595. 0x1F, 0x2B, 0x8B, 0x26, 0xD4, 0xE1, 0xF6, 0x70,
  31596. 0x62, 0x3D, 0x95, 0xC8, 0x36, 0x2D, 0xA6, 0x62,
  31597. 0xD1, 0xFF, 0x0A, 0xB6, 0x87, 0x50, 0x3F, 0x32,
  31598. 0x8D, 0xE0, 0x95, 0x81, 0x0E, 0xDE, 0x12, 0xB4,
  31599. 0x9E, 0xAD, 0x15, 0x33, 0x51, 0x95, 0x58, 0xC1,
  31600. 0xE9, 0x40, 0xB4, 0x6E, 0x4E, 0xDB, 0x02, 0x7B,
  31601. 0xE9, 0xDA, 0x20, 0x39, 0xB2, 0x5D, 0xCF, 0x73,
  31602. 0x57, 0xE1, 0x9E, 0x54, 0x16, 0xAE, 0x26, 0x8C,
  31603. 0x14, 0xFB, 0x3A, 0x8B, 0xAB, 0xCB, 0x3D, 0x23,
  31604. 0xF7, 0x0C, 0xC9, 0xD5, 0x96, 0x81, 0xC5, 0xD8,
  31605. 0x33, 0xAC, 0x22, 0xE6, 0x53, 0xD8, 0x6E, 0x22,
  31606. 0xCE, 0x82, 0x25, 0x40, 0x75, 0x5D, 0x8D, 0x24,
  31607. 0x3C, 0x15, 0x21, 0x3D, 0x07, 0x6C, 0x6B, 0x26,
  31608. 0x43, 0x6D, 0xDC, 0x07, 0xC7, 0xE0, 0x01, 0x34,
  31609. 0x7B, 0x0C, 0xB8, 0x78, 0x3D, 0xFE, 0xFE, 0xDF,
  31610. 0x27, 0x5F, 0xEC, 0x47, 0x92, 0x68, 0x67, 0x34,
  31611. 0x00, 0x7F, 0x0F, 0xF8, 0x54, 0x08, 0x11, 0xC2,
  31612. 0xAF, 0xE6, 0xCA, 0x15, 0x14, 0x20, 0x53, 0x2F,
  31613. 0xA5, 0x52, 0x6A, 0x10, 0x74, 0xC3, 0xD7, 0x89,
  31614. 0xF2, 0x93, 0x2D, 0xE4, 0x2E, 0x3A, 0xCF, 0xBF,
  31615. 0x94, 0x76, 0x0F, 0x42, 0x6D, 0x96, 0xCF, 0x03,
  31616. 0x3F, 0xA4, 0x9E, 0x2F, 0x45, 0x8F, 0x9A, 0x9C,
  31617. 0x2E, 0x71, 0xDA, 0xCF, 0xE0, 0x09, 0xDD, 0x9C,
  31618. 0x3F, 0x3C, 0x8A, 0xB3, 0x28, 0x2D, 0x6F, 0x38,
  31619. 0x3B, 0x98, 0x1C, 0x82, 0xD6, 0x36, 0x4F, 0x0E,
  31620. 0x4B, 0xDB, 0x2A, 0xF6, 0xA9, 0x5B, 0xA6, 0x1F,
  31621. 0x47, 0x41, 0x50, 0xCA, 0xD7, 0x23, 0x3F, 0x89,
  31622. 0x03, 0xDF, 0x97, 0x2D, 0xBB, 0x03, 0x28, 0xC0,
  31623. 0xCB, 0x9D, 0x0C, 0xCB, 0xEF, 0x88, 0x3D, 0x2E,
  31624. 0x6A, 0xDD, 0x18, 0x0E, 0xCA, 0x1B, 0x66, 0x2F,
  31625. 0xC1, 0xD2, 0xDB, 0xBD, 0xDB, 0x36, 0x34, 0x21,
  31626. 0x9E, 0x1E, 0xFF, 0x38, 0xB1, 0xE5, 0x28, 0x75,
  31627. 0x35, 0x6C, 0x03, 0xEA, 0xDE, 0x94, 0x20, 0x55,
  31628. 0xF4, 0x83, 0x50, 0x4B, 0xBB, 0xCB, 0x43, 0x02,
  31629. 0xA4, 0x17, 0xCF, 0x6D, 0x32, 0x8E, 0xD7, 0x93,
  31630. 0xB1, 0xA3, 0xC0, 0x96, 0x9B, 0x7B, 0x34, 0x18,
  31631. 0xF5, 0x0A, 0xB3, 0x9F, 0x83, 0xC5, 0x66, 0x6C,
  31632. 0x90, 0xE3, 0x83, 0x56, 0xF7, 0xF9, 0xD4, 0x94,
  31633. 0xA6, 0xDC, 0xB6, 0x3D, 0x67, 0xC3, 0x4E, 0x3D,
  31634. 0x14, 0xA4, 0xE1, 0x55, 0x96, 0x49, 0x79, 0x26,
  31635. 0xC8, 0x56, 0x8D, 0x8E, 0xC3, 0xDB, 0xD9, 0xC2,
  31636. 0xE8, 0x2C, 0x38, 0x5B, 0xCF, 0xB8, 0xD9, 0x67,
  31637. 0x48, 0x63, 0xBD, 0x4F, 0xBF, 0x17, 0x57, 0xDB,
  31638. 0x44, 0x7B, 0xF8, 0x04, 0xAE, 0x95, 0x01, 0x47,
  31639. 0xC9, 0x1F, 0xBF, 0x9A, 0xA1, 0x78, 0x91, 0x04,
  31640. 0x4C, 0xCA, 0xA7, 0x3B, 0x45, 0x52, 0x85, 0x97,
  31641. 0x46, 0x2C, 0xED, 0x75, 0x1D, 0x01, 0x5E, 0xBB,
  31642. 0xA9, 0xE2, 0xB7, 0xCD, 0xCB, 0xE6, 0xDC, 0x05,
  31643. 0xAA, 0x9E, 0xAE, 0x0C, 0x86, 0x84, 0x8A, 0x34,
  31644. 0x75, 0xBB, 0x1C, 0x57, 0x44, 0xF5, 0x90, 0x3E,
  31645. 0xE4, 0xA8, 0x42, 0xA4, 0x69, 0xCC, 0x18, 0x12,
  31646. 0x71, 0xF2, 0x45, 0xAD, 0x70, 0xD0, 0x2A, 0x48,
  31647. 0x37, 0x86, 0x3B, 0x29, 0x6B, 0x4A, 0xDB, 0x4E,
  31648. 0x8D, 0x03, 0xD8, 0x2B, 0x64, 0xAA, 0x11, 0xDD,
  31649. 0x31, 0xCD, 0xF2, 0x1E, 0xDF, 0x1D, 0xFE, 0x32,
  31650. 0x76, 0xC4, 0xDB, 0xC8, 0x77, 0xE3, 0x5B, 0x15,
  31651. 0xFB, 0x28, 0x35, 0xEC, 0x3A, 0x1C, 0x45, 0x31,
  31652. 0x68, 0xA3, 0x8C, 0xA8, 0xE5, 0x63, 0xCF, 0x3E,
  31653. 0x9A, 0x00, 0x73, 0x6C, 0xD5, 0xCF, 0xBD, 0x28,
  31654. 0x41, 0xD1, 0x0F, 0x94, 0xAD, 0x55, 0x79, 0x9C,
  31655. 0x29, 0x27, 0xE5, 0x46, 0x1B, 0x28, 0xBA, 0xC5,
  31656. 0x17, 0x4D, 0x0C, 0xE3, 0xF8, 0xF7, 0xCD, 0x76,
  31657. 0x09, 0xFB, 0xC8, 0xDA, 0x0C, 0x38, 0xCC, 0x21,
  31658. 0x69, 0x5C, 0xED, 0xAD, 0x12, 0xF8, 0xD2, 0xE6,
  31659. 0x49, 0x51, 0xA8, 0x99, 0x6E, 0x51, 0x0D, 0x6D,
  31660. 0x52, 0x79, 0x7C, 0x5B, 0xA0, 0xEB, 0x4A, 0xFA,
  31661. 0x6B, 0xF2, 0xCC, 0x43, 0xDA, 0x09, 0xDE, 0x31,
  31662. 0x79, 0xE8, 0x99, 0xBD, 0x71, 0x88, 0xB3, 0x2A,
  31663. 0x98, 0xA4, 0x99, 0xD3, 0x72, 0xF3, 0x70, 0x7C,
  31664. 0xED, 0x47, 0x9B, 0x09, 0x81, 0xCB, 0x50, 0xC0,
  31665. 0xC0, 0x53, 0x9C, 0xF7, 0xE3, 0x10, 0x0B, 0x72,
  31666. 0x0E, 0x46, 0x66, 0x52, 0xA4, 0xF4, 0x99, 0xC2,
  31667. 0xBA, 0x3A, 0x17, 0xF5, 0x23, 0x22, 0x68, 0x73,
  31668. 0x0B, 0x96, 0x2B, 0xC5, 0x72, 0xC0, 0xDE, 0x96,
  31669. 0xE8, 0xC9, 0xE2, 0x8F, 0x7E, 0x35, 0x32, 0xC2,
  31670. 0x22, 0x41, 0x96, 0xAA, 0x9E, 0x27, 0x68, 0x8D,
  31671. 0xD0, 0x50, 0xD7, 0xCB, 0x78, 0x54, 0xFB, 0x3C,
  31672. 0x35, 0xF9, 0xC6, 0x2E, 0xFB, 0x10, 0xDA, 0x84,
  31673. 0x83, 0x3F, 0x29, 0xBB, 0x1B, 0xE5, 0xEF, 0x3B,
  31674. 0x53, 0x36, 0x38, 0xEE, 0xF7, 0x43, 0xD8, 0x11,
  31675. 0x9D, 0xDC, 0x29, 0x0B, 0xDF, 0x08, 0xB6, 0xF0,
  31676. 0xF9, 0xE4, 0xE1, 0xE1, 0x34, 0x46, 0xC5, 0x3E,
  31677. 0xD6, 0x98, 0x05, 0xDA, 0x26, 0x90, 0x8A, 0x15,
  31678. 0xDF, 0x1C, 0x48, 0xE0, 0x09, 0xEC, 0x12, 0x53,
  31679. 0xBD, 0x5A, 0x58, 0x98, 0xEB, 0xB5, 0x12, 0x1C,
  31680. 0xC2, 0x49, 0x04, 0xC8, 0xB1, 0x0E, 0x24, 0xE6,
  31681. 0x80, 0xE5, 0x65, 0x98, 0x50, 0x76, 0xFD, 0xA1,
  31682. 0x1D, 0x13, 0xFF, 0xDF, 0xA4, 0xDB, 0x28, 0xAC,
  31683. 0x9F, 0x0A, 0xEA, 0x2F, 0x81, 0xFD, 0x7E, 0xD4,
  31684. 0xDC, 0xA8, 0xD3, 0xB2, 0xE3, 0x84, 0x8B, 0x4D,
  31685. 0x60, 0x46, 0xF6, 0xE0, 0xDE, 0x3A, 0x4F, 0x68,
  31686. 0x3F, 0x25, 0xE0, 0x60, 0x5E, 0x84, 0xB3, 0x6F,
  31687. 0x48, 0x3C, 0x40, 0x4E, 0xF8, 0x99, 0xCB, 0x3F,
  31688. 0xCC, 0xBE, 0x8C, 0xB2, 0xA6, 0xF0, 0xA7, 0xE1,
  31689. 0x0B, 0x19, 0x48, 0xCD, 0x4F, 0x93, 0xF1, 0x81,
  31690. 0x55, 0x5F, 0x66, 0x1D, 0x31, 0xD4, 0x26, 0x80,
  31691. 0x8B, 0xBF, 0x9F, 0x66, 0xFD, 0x60, 0xD6, 0x49,
  31692. 0x26, 0x9C, 0xA3, 0xFE, 0x99, 0x1B, 0x22, 0x42,
  31693. 0x8C, 0x37, 0xAD, 0x2A, 0x08, 0x68, 0x0F, 0x74,
  31694. 0x7C, 0xC0, 0x36, 0x0C, 0xCD, 0x37, 0x3D, 0xC6,
  31695. 0xA9, 0xF4, 0x3A, 0x66, 0x47, 0x0E, 0x01, 0x4E,
  31696. 0x72, 0xB3, 0xD8, 0xC3, 0x8E, 0x02, 0x04, 0x42,
  31697. 0xD8, 0xAA, 0xB9, 0x74, 0xE6, 0x04, 0x93, 0x74,
  31698. 0x14, 0x5B, 0x04, 0xCB, 0x7F, 0x30, 0x44, 0xAA,
  31699. 0xC1, 0xEF, 0xDA, 0xB2, 0xA1, 0x8B, 0xB4, 0x64,
  31700. 0xD4, 0xF2, 0xF2, 0xD8, 0x14, 0x39, 0x74, 0xC9,
  31701. 0x5E, 0xEE, 0x85, 0x6D, 0x59, 0xEC, 0x00, 0x28,
  31702. 0x8E, 0xD4, 0x3F, 0xF5, 0xCC, 0x88, 0x03, 0x00,
  31703. 0x6C, 0x99, 0x55, 0x14, 0xA2, 0xCC, 0x9C, 0xA6,
  31704. 0x22, 0xB6, 0x1B, 0xCD, 0x75, 0xEC, 0x51, 0xC2,
  31705. 0x02, 0xA9, 0x17, 0x10, 0x5B, 0x4A, 0x4B, 0xED,
  31706. 0x1B, 0x80, 0x14, 0x68, 0x31, 0xDC, 0xED, 0x07,
  31707. 0xEF, 0xD2, 0xED, 0x25, 0x73, 0x9F, 0x54, 0x09,
  31708. 0x69, 0x11, 0xB1, 0x50, 0xD3, 0x07, 0x7C, 0xCD,
  31709. 0x73, 0x1A, 0x03, 0x61, 0x68, 0x27, 0x25, 0xD5,
  31710. 0x38, 0x03, 0xF8, 0xFC, 0xEA, 0xA8, 0x39, 0x19,
  31711. 0x29, 0x1E, 0xDB, 0x44, 0x93, 0xEC, 0x84, 0xCC,
  31712. 0xE1, 0xD0, 0xF8, 0x2A, 0x67, 0x92, 0x36, 0xEA,
  31713. 0xD1, 0x00, 0x2A, 0xE8, 0x01, 0x8C, 0xAC, 0x9F,
  31714. 0xDB, 0xD2, 0x46, 0xFF, 0x09, 0x3D, 0x80, 0x3C,
  31715. 0x0D, 0xE3, 0x32, 0x6A, 0x57, 0x90, 0x7B, 0x0D,
  31716. 0xD6, 0xB0, 0x1D, 0x08, 0x14, 0x58, 0xC7, 0x57,
  31717. 0x28, 0xC6, 0x00, 0x82, 0x99, 0x28, 0x89, 0x0A,
  31718. 0x56, 0xAA, 0xAF, 0xEF, 0xCF, 0x74, 0x23, 0xB7,
  31719. 0x0A, 0x6D, 0x86, 0xB4, 0x15, 0xB8, 0x35, 0x8D,
  31720. 0xD0, 0x44, 0xAB, 0xEE, 0x00, 0xB9, 0xC9, 0x79,
  31721. 0x5F, 0xC8, 0xF6, 0x1A, 0x64, 0x68, 0x6D, 0xF5,
  31722. 0xF8, 0x76, 0xA8, 0xF3, 0x30, 0x61, 0x59, 0x9A,
  31723. 0xE8, 0x30, 0xF7, 0xEB, 0x4C, 0x4B, 0xFF, 0x87,
  31724. 0x5F, 0x4A, 0x93, 0x6C, 0x40, 0x3C, 0x5D, 0x16,
  31725. 0x0D, 0xE5, 0xD3, 0x3C, 0xAE, 0xE4, 0x0F, 0xB7,
  31726. 0x18, 0xDD, 0xA4, 0x47, 0x8A, 0xC6, 0xF5, 0x1C,
  31727. 0x59, 0xC2, 0x15, 0x52, 0x54, 0xBD, 0x77, 0x67,
  31728. 0x11, 0x18, 0x41, 0x1E, 0x26, 0x09, 0xD0, 0x00,
  31729. 0x30, 0x6F, 0xC9, 0x50, 0x70, 0x04, 0xA3, 0x1E,
  31730. 0x89, 0x57, 0xEA, 0x40, 0xC2, 0x56, 0x4B, 0x83,
  31731. 0xC3, 0xAB, 0xB7, 0x1A, 0x87, 0xC1, 0x1B, 0xD1,
  31732. 0x8D, 0x78, 0x91, 0xC4, 0x49, 0xDB, 0xBE, 0x79,
  31733. 0xB4, 0xA4, 0xFB, 0x04, 0x83, 0x07, 0xCE, 0x0E,
  31734. 0x81, 0x2B, 0x2C, 0x68, 0xEC, 0xAB, 0x77, 0xFD,
  31735. 0x11, 0x11, 0x52, 0x6A, 0xB0, 0x81, 0x73, 0x06,
  31736. 0xCE, 0xBC, 0xB0, 0x49, 0x7C, 0x55, 0x24, 0x31,
  31737. 0xCE, 0x15, 0xE4, 0xAB, 0x52, 0x28, 0x3F, 0x67,
  31738. 0x94, 0x80, 0xD6, 0x9D, 0xDD, 0xE1, 0xF2, 0x57,
  31739. 0x9C, 0xFD, 0xBE, 0x0B, 0xCA, 0x95, 0xFC, 0x5B,
  31740. 0x2D, 0xB0, 0xC5, 0xCC, 0x76, 0xA3, 0x19, 0x50,
  31741. 0xF5, 0x11, 0x6A, 0xAE, 0x5F, 0x02, 0xD4, 0x67,
  31742. 0x10, 0xE4, 0x25, 0x7A, 0x75, 0xFD, 0xED, 0xF2,
  31743. 0xF4, 0x7C, 0xE3, 0x7C, 0x20, 0x3E, 0x7F, 0x24,
  31744. 0xD3, 0xC9, 0x17, 0x97, 0x13, 0xC5, 0xD8, 0x07,
  31745. 0xC2, 0x96, 0x14, 0x9A, 0x75, 0xCC, 0xB4, 0x44,
  31746. 0xF0, 0xC6, 0xF6, 0xAB, 0xDD, 0x2D, 0xBB, 0x29,
  31747. 0x85, 0xFE, 0x26, 0x74, 0x82, 0x85, 0x8A, 0x1E
  31748. };
  31749. #endif /* WOLFSSL_NO_ML_DSA_65 */
  31750. #ifndef WOLFSSL_NO_ML_DSA_87
  31751. static const byte seed_87[] = {
  31752. 0x38, 0x35, 0x9F, 0xBC, 0xD7, 0x95, 0x82, 0xCF,
  31753. 0xFE, 0x60, 0x9E, 0x13, 0x7E, 0xE2, 0xEF, 0xE8,
  31754. 0xA8, 0xDB, 0xCB, 0xAD, 0x18, 0xBA, 0x92, 0xBB,
  31755. 0x43, 0x3A, 0xB4, 0xF0, 0x9B, 0x49, 0x29, 0x9D
  31756. };
  31757. static const byte pk_87[] = {
  31758. 0x69, 0x24, 0xBB, 0x42, 0x57, 0xA7, 0xB9, 0xAF,
  31759. 0xF0, 0x95, 0xC3, 0x0B, 0xB3, 0x5C, 0x6A, 0xE4,
  31760. 0x19, 0x82, 0x63, 0x12, 0x0F, 0x80, 0x39, 0xAA,
  31761. 0x4E, 0x78, 0xE1, 0x74, 0xA7, 0x86, 0xCE, 0x00,
  31762. 0x83, 0x01, 0xE6, 0x66, 0xF5, 0x9D, 0x3E, 0xC5,
  31763. 0x04, 0x4D, 0xE4, 0x56, 0x78, 0x8F, 0xDE, 0x19,
  31764. 0xEB, 0x39, 0x67, 0x7B, 0x5F, 0x9F, 0xE1, 0x41,
  31765. 0x50, 0xDA, 0x46, 0x3A, 0x70, 0x6F, 0x3B, 0xAF,
  31766. 0x71, 0x5B, 0x95, 0x33, 0x6B, 0x2D, 0x68, 0x5A,
  31767. 0x7C, 0xD7, 0x88, 0x07, 0x13, 0xE4, 0x58, 0x7B,
  31768. 0xF7, 0xD8, 0x57, 0xBF, 0x7E, 0x31, 0x56, 0x96,
  31769. 0xB8, 0xD0, 0xD9, 0xD4, 0x9E, 0x14, 0x29, 0x18,
  31770. 0xBF, 0x09, 0x74, 0xE7, 0xF4, 0x32, 0x37, 0xD4,
  31771. 0xBE, 0x3A, 0xD3, 0x94, 0x59, 0x9E, 0x3D, 0x39,
  31772. 0xBB, 0x76, 0x49, 0x93, 0x25, 0x53, 0x44, 0x7E,
  31773. 0x5D, 0x5A, 0xCC, 0x34, 0x99, 0x93, 0x01, 0x76,
  31774. 0xEC, 0xD3, 0xA8, 0x44, 0xA4, 0x25, 0xF5, 0x0D,
  31775. 0x05, 0x11, 0xC9, 0x22, 0x6C, 0x4B, 0x9A, 0x24,
  31776. 0xF2, 0xA0, 0x11, 0xCD, 0x88, 0xD3, 0x23, 0x08,
  31777. 0xE0, 0x31, 0x2A, 0x0C, 0x87, 0xCC, 0x34, 0xA9,
  31778. 0x95, 0x82, 0x3C, 0x65, 0xF4, 0xF0, 0xF9, 0x8E,
  31779. 0x50, 0xC3, 0x77, 0x88, 0xCE, 0x38, 0xDC, 0x28,
  31780. 0xFB, 0x8B, 0x9B, 0xFA, 0xAF, 0xA9, 0x04, 0xB5,
  31781. 0x41, 0xEE, 0x71, 0x2F, 0x6A, 0x04, 0x1E, 0x06,
  31782. 0x11, 0x37, 0x4F, 0x6B, 0xF1, 0x7E, 0xAC, 0x0B,
  31783. 0xD5, 0x6F, 0x3B, 0x6B, 0xF3, 0x36, 0xDA, 0x92,
  31784. 0x42, 0x07, 0x0C, 0x24, 0x69, 0xA2, 0x0C, 0x4D,
  31785. 0x16, 0x16, 0x14, 0x9A, 0x61, 0x59, 0x25, 0x20,
  31786. 0x11, 0xD2, 0x99, 0xF9, 0x3F, 0x98, 0x6D, 0x87,
  31787. 0x5D, 0xD3, 0x0B, 0x38, 0xA2, 0x25, 0x49, 0x17,
  31788. 0x45, 0x70, 0x13, 0x8C, 0x2B, 0xB3, 0xAA, 0x9C,
  31789. 0xBE, 0xA9, 0x19, 0x74, 0xF3, 0xD8, 0x9B, 0xF5,
  31790. 0xAE, 0x32, 0xBE, 0x9E, 0x58, 0xB8, 0x54, 0xA2,
  31791. 0xF8, 0xE8, 0x6F, 0xF7, 0x67, 0x80, 0xC0, 0x34,
  31792. 0x90, 0xF4, 0x67, 0xDB, 0x06, 0x51, 0xC2, 0x0B,
  31793. 0x1D, 0xF6, 0x0E, 0xB9, 0x7A, 0x3C, 0x99, 0xD9,
  31794. 0xBD, 0x66, 0x4B, 0xE6, 0xA5, 0xE4, 0xC8, 0xA8,
  31795. 0xAD, 0x4C, 0xC3, 0x63, 0x90, 0xD7, 0x00, 0x4E,
  31796. 0x4B, 0xB4, 0x21, 0xDA, 0xED, 0x65, 0x4C, 0x35,
  31797. 0x7D, 0xA4, 0xD6, 0x84, 0x98, 0x93, 0x3E, 0xC7,
  31798. 0x17, 0x77, 0xAD, 0x64, 0xC2, 0xAE, 0x01, 0x3C,
  31799. 0x73, 0xEB, 0x45, 0x7C, 0x68, 0xEF, 0x9A, 0x74,
  31800. 0x5A, 0xDE, 0xEB, 0x4F, 0xDF, 0xC8, 0x79, 0xE7,
  31801. 0x74, 0xD0, 0x3F, 0xAF, 0x6B, 0x14, 0xAA, 0xB1,
  31802. 0x07, 0x52, 0xE2, 0x4B, 0x52, 0xD0, 0xF2, 0xD9,
  31803. 0x4D, 0x54, 0x0A, 0x1E, 0xBE, 0x10, 0xF5, 0x97,
  31804. 0xE5, 0x14, 0x44, 0x2D, 0x6C, 0x13, 0xC2, 0xE2,
  31805. 0x49, 0x8E, 0x8A, 0xF3, 0x01, 0x7C, 0x52, 0xDB,
  31806. 0x23, 0x3A, 0x90, 0x71, 0x7D, 0xF2, 0x5B, 0x4D,
  31807. 0x07, 0x2B, 0x7D, 0x88, 0xEE, 0x87, 0x31, 0xD1,
  31808. 0x68, 0x24, 0xC9, 0x5D, 0x1F, 0xB9, 0x83, 0xC4,
  31809. 0x49, 0xDE, 0xB4, 0x66, 0x27, 0x60, 0x60, 0xFE,
  31810. 0xE4, 0xC7, 0xEE, 0x38, 0x14, 0x51, 0xF2, 0x32,
  31811. 0xC2, 0x9C, 0x7C, 0x32, 0x20, 0x85, 0x0C, 0x61,
  31812. 0xD1, 0xC3, 0xC0, 0x0D, 0xB1, 0xCD, 0x97, 0x26,
  31813. 0xA0, 0x2A, 0x56, 0x60, 0x9F, 0x3A, 0x65, 0xD3,
  31814. 0xD1, 0x64, 0x60, 0x45, 0x88, 0xCD, 0x9B, 0x43,
  31815. 0x14, 0x12, 0xF1, 0xAD, 0xD9, 0x14, 0xC5, 0xC2,
  31816. 0xDA, 0xBB, 0xC9, 0x04, 0x67, 0xC0, 0xC4, 0xEA,
  31817. 0x5F, 0x76, 0xE2, 0x4A, 0xA6, 0x18, 0x76, 0x5F,
  31818. 0x8B, 0x06, 0x36, 0xD7, 0xB0, 0x65, 0xE1, 0xF4,
  31819. 0xE6, 0xF6, 0x22, 0xEA, 0xE1, 0x71, 0x52, 0x45,
  31820. 0x8C, 0x76, 0x65, 0x86, 0x77, 0x2D, 0x36, 0x3F,
  31821. 0xA9, 0x92, 0x14, 0xF4, 0x72, 0xB0, 0xDB, 0x8A,
  31822. 0x1E, 0x49, 0xD8, 0x2D, 0x02, 0x78, 0xF2, 0x95,
  31823. 0x8B, 0x0A, 0xAA, 0x15, 0x86, 0xDB, 0x13, 0x4B,
  31824. 0xDF, 0xD2, 0x43, 0x87, 0x42, 0x49, 0x50, 0x07,
  31825. 0xE2, 0xFE, 0x5B, 0x60, 0xE2, 0x46, 0x39, 0x92,
  31826. 0x26, 0x94, 0x7A, 0x12, 0xEA, 0x17, 0x63, 0x1C,
  31827. 0xAA, 0x53, 0x46, 0x87, 0xCB, 0x75, 0xC0, 0x60,
  31828. 0xB4, 0x79, 0x7E, 0xAB, 0x82, 0x77, 0xCC, 0x4F,
  31829. 0x8A, 0x7A, 0x20, 0x38, 0x76, 0x06, 0xEF, 0xE2,
  31830. 0xDB, 0xD3, 0xE7, 0x36, 0x24, 0x92, 0x77, 0xD9,
  31831. 0x0F, 0xCA, 0xB9, 0x92, 0xA8, 0xC9, 0x9E, 0x85,
  31832. 0xAB, 0x03, 0xEB, 0x4C, 0xAC, 0x5D, 0x88, 0x55,
  31833. 0x39, 0x58, 0x52, 0x8A, 0xF9, 0x29, 0x74, 0x71,
  31834. 0x81, 0x35, 0xF1, 0xD0, 0xC7, 0x93, 0xEB, 0x00,
  31835. 0x0E, 0xA0, 0xAE, 0xC3, 0xEC, 0x18, 0x58, 0xFD,
  31836. 0xD1, 0x86, 0x88, 0xD1, 0xDA, 0x27, 0x27, 0x8D,
  31837. 0xEB, 0xF2, 0xCA, 0x81, 0x10, 0xBA, 0x4A, 0x20,
  31838. 0x4F, 0x79, 0x30, 0xE1, 0xC8, 0xCE, 0xEC, 0xAF,
  31839. 0xB7, 0x3F, 0x75, 0xDD, 0xB3, 0x4C, 0x5C, 0x55,
  31840. 0x96, 0x8A, 0x79, 0x33, 0x05, 0x84, 0x26, 0xB5,
  31841. 0x5D, 0x03, 0x9F, 0x72, 0x92, 0xAC, 0x43, 0xF6,
  31842. 0x45, 0x84, 0xF6, 0xDF, 0x18, 0x7A, 0x1D, 0x6B,
  31843. 0x00, 0x3F, 0x51, 0x4C, 0xC1, 0x3B, 0x26, 0xC2,
  31844. 0xF3, 0x48, 0x19, 0x5A, 0xA3, 0x21, 0xDE, 0x6A,
  31845. 0x27, 0xEC, 0x11, 0x34, 0x8D, 0xE5, 0x0D, 0x82,
  31846. 0x5A, 0x29, 0x64, 0xC6, 0x31, 0x99, 0x2E, 0x4B,
  31847. 0x0B, 0x42, 0x5B, 0x1B, 0xEB, 0x4F, 0x96, 0x00,
  31848. 0xE3, 0xAD, 0xC4, 0x43, 0x1C, 0xF2, 0xE8, 0x8B,
  31849. 0x42, 0x23, 0xD2, 0xDB, 0x66, 0x3C, 0x3C, 0xE7,
  31850. 0x0E, 0xF8, 0x5D, 0xDD, 0x56, 0xA9, 0xBA, 0xF1,
  31851. 0x38, 0xA9, 0xD7, 0xED, 0xD8, 0x94, 0x13, 0x1C,
  31852. 0x3A, 0x8F, 0x41, 0xA0, 0x4E, 0xF9, 0xF8, 0x67,
  31853. 0x52, 0xB7, 0x21, 0x81, 0xFA, 0xBB, 0x37, 0xC8,
  31854. 0x6B, 0x87, 0x7E, 0x61, 0xD6, 0x0E, 0xED, 0x95,
  31855. 0xEE, 0xFF, 0xAB, 0xE6, 0x37, 0x6E, 0x14, 0xAC,
  31856. 0xA8, 0x17, 0xC5, 0xF4, 0x19, 0x61, 0xAF, 0x8A,
  31857. 0x78, 0x49, 0xBA, 0xC0, 0x94, 0x91, 0x7B, 0x2D,
  31858. 0x13, 0x22, 0x76, 0xB6, 0xB3, 0x48, 0x6A, 0xFF,
  31859. 0x95, 0x0D, 0x23, 0xD4, 0xAA, 0xDC, 0x24, 0xCE,
  31860. 0x98, 0xA5, 0x26, 0x9E, 0x1C, 0x69, 0x91, 0x79,
  31861. 0x60, 0xA3, 0x1E, 0xE0, 0x9A, 0x52, 0x7C, 0x35,
  31862. 0x81, 0x75, 0xCA, 0xA0, 0xCB, 0x1B, 0x01, 0x8E,
  31863. 0x95, 0x26, 0xD9, 0x35, 0x34, 0xEA, 0xDB, 0xAC,
  31864. 0xB5, 0x2B, 0x27, 0x3D, 0x73, 0x5E, 0x22, 0xDD,
  31865. 0x0D, 0x5C, 0x28, 0xFA, 0x3E, 0x47, 0xCF, 0xE9,
  31866. 0x0B, 0x52, 0x15, 0xAE, 0x24, 0xF1, 0x46, 0xC3,
  31867. 0x46, 0x4B, 0xFE, 0xAF, 0x01, 0xD2, 0x8D, 0xAA,
  31868. 0x55, 0x3C, 0x1E, 0x94, 0x42, 0x8A, 0x10, 0x4A,
  31869. 0x9D, 0x78, 0xAE, 0xC7, 0x62, 0x59, 0x1E, 0x88,
  31870. 0x79, 0xF7, 0x68, 0x51, 0xCF, 0xB4, 0x64, 0x85,
  31871. 0x66, 0x72, 0x1B, 0x0C, 0xAC, 0x1F, 0x14, 0xFE,
  31872. 0x16, 0x14, 0x9A, 0x9D, 0x82, 0x10, 0xCC, 0x8F,
  31873. 0x2F, 0x50, 0xDE, 0xF7, 0xB4, 0x6C, 0x84, 0x3B,
  31874. 0xE9, 0x3B, 0xD8, 0xD5, 0x56, 0x02, 0x49, 0x33,
  31875. 0x50, 0xAB, 0x56, 0x0E, 0xA5, 0xBA, 0x17, 0x71,
  31876. 0x64, 0x23, 0xBE, 0x0E, 0xB8, 0x36, 0x0A, 0xB1,
  31877. 0x09, 0xD8, 0xFB, 0x18, 0xBF, 0xEA, 0x04, 0x08,
  31878. 0x47, 0xB7, 0x33, 0x51, 0x45, 0xD4, 0xF2, 0x00,
  31879. 0xD1, 0x9C, 0xF6, 0xFE, 0x7B, 0xAC, 0x91, 0x7F,
  31880. 0x42, 0x6C, 0x9B, 0x3D, 0x39, 0xA9, 0xCA, 0x43,
  31881. 0x29, 0x81, 0x8F, 0x24, 0x0E, 0x7D, 0xA3, 0x82,
  31882. 0x76, 0x10, 0x72, 0xF4, 0xA6, 0x50, 0x5E, 0xA8,
  31883. 0xE7, 0x6C, 0x1E, 0x44, 0x6F, 0xEB, 0x66, 0x25,
  31884. 0xE3, 0x8D, 0xDB, 0xCD, 0x3C, 0xDA, 0x81, 0xE8,
  31885. 0x3B, 0xF7, 0x68, 0xF3, 0xE0, 0x1D, 0x9D, 0x26,
  31886. 0x3B, 0x36, 0x73, 0x03, 0xAE, 0x15, 0x6C, 0x0B,
  31887. 0x71, 0x83, 0x36, 0x4A, 0x1E, 0x79, 0x41, 0xA0,
  31888. 0x92, 0x98, 0xA3, 0xAD, 0xF7, 0xBD, 0x23, 0x1E,
  31889. 0x61, 0x14, 0xB9, 0xDC, 0xE7, 0x95, 0x2B, 0x11,
  31890. 0x3F, 0x78, 0x16, 0x31, 0x38, 0xB9, 0x26, 0x6F,
  31891. 0x84, 0x3F, 0x1E, 0xD9, 0x7D, 0x9C, 0x2B, 0x16,
  31892. 0x3A, 0x6E, 0x8B, 0xD4, 0xC1, 0xAB, 0x4E, 0x17,
  31893. 0x93, 0x67, 0xC5, 0xAC, 0x96, 0xCE, 0xCF, 0x50,
  31894. 0x50, 0xFE, 0x82, 0x1F, 0xDF, 0xA4, 0x4E, 0x9E,
  31895. 0x68, 0x0B, 0x61, 0xC6, 0x01, 0x89, 0x32, 0xDF,
  31896. 0x71, 0x78, 0x11, 0x45, 0x9A, 0xF2, 0x54, 0x2E,
  31897. 0x2C, 0xDE, 0x77, 0x17, 0x8C, 0x2E, 0x98, 0x80,
  31898. 0xF0, 0x11, 0xE4, 0x05, 0xEA, 0xFA, 0x59, 0xC8,
  31899. 0xCB, 0xBE, 0xD7, 0x6E, 0x5A, 0x19, 0x41, 0x10,
  31900. 0x4B, 0x1B, 0x9D, 0x3A, 0x60, 0x49, 0x1C, 0x95,
  31901. 0x47, 0x55, 0xE0, 0x2E, 0x89, 0x41, 0x03, 0xF1,
  31902. 0xF4, 0x97, 0x74, 0x75, 0xE9, 0xEA, 0x36, 0x60,
  31903. 0x9F, 0xD6, 0x7C, 0x9D, 0xE3, 0x18, 0xED, 0xA2,
  31904. 0x37, 0x0D, 0xCC, 0xDB, 0xB9, 0xCE, 0xF7, 0xAE,
  31905. 0x63, 0x60, 0x90, 0x5E, 0xC2, 0x20, 0x83, 0x8C,
  31906. 0x97, 0x69, 0x82, 0x34, 0x41, 0xCD, 0xD0, 0xDA,
  31907. 0x8E, 0xF0, 0xAB, 0xE5, 0xF2, 0xD1, 0xD7, 0x6E,
  31908. 0x2F, 0xE0, 0x8F, 0xEF, 0x53, 0xDE, 0x1D, 0x61,
  31909. 0x66, 0xAB, 0x1A, 0x92, 0xB1, 0xAC, 0x09, 0x3E,
  31910. 0x5A, 0xBF, 0x76, 0x58, 0xC4, 0xB5, 0x72, 0x87,
  31911. 0xF2, 0xD1, 0xFD, 0x7B, 0x82, 0xDE, 0xDA, 0xF8,
  31912. 0xD5, 0xA4, 0xFB, 0xAC, 0x4B, 0x35, 0xD5, 0x82,
  31913. 0x31, 0x69, 0x4E, 0x16, 0x24, 0x97, 0x57, 0x8A,
  31914. 0xBD, 0x7A, 0xA7, 0xC8, 0xFE, 0x7B, 0x35, 0x41,
  31915. 0xA7, 0xF1, 0x8E, 0x54, 0xE8, 0xB7, 0xF0, 0x87,
  31916. 0x64, 0xC5, 0xE6, 0x84, 0x49, 0xDF, 0x65, 0x59,
  31917. 0x01, 0x54, 0x98, 0x32, 0xD6, 0x28, 0xFA, 0x63,
  31918. 0xD2, 0xB2, 0xC5, 0xA1, 0x50, 0x93, 0x39, 0x94,
  31919. 0xA9, 0x86, 0x33, 0x17, 0xAD, 0x40, 0xD7, 0x78,
  31920. 0xD9, 0xD2, 0xC0, 0x5C, 0x78, 0x98, 0x85, 0x0B,
  31921. 0x90, 0x17, 0x32, 0x23, 0xC7, 0xA0, 0xAF, 0x89,
  31922. 0x0F, 0xD7, 0xE6, 0x62, 0x21, 0xB6, 0xF0, 0x63,
  31923. 0x18, 0xB2, 0xED, 0x5E, 0x19, 0x9C, 0xB4, 0x24,
  31924. 0x88, 0x5A, 0xB8, 0x41, 0xE7, 0xA4, 0x72, 0x6F,
  31925. 0xAB, 0xA2, 0xF9, 0xBB, 0x53, 0xBC, 0x32, 0x36,
  31926. 0x43, 0x4C, 0x35, 0xFB, 0xBE, 0x4B, 0x1A, 0x0F,
  31927. 0x93, 0xF5, 0x0C, 0x37, 0x89, 0x6C, 0x29, 0xF8,
  31928. 0xE3, 0x02, 0xAD, 0x31, 0xED, 0x33, 0x31, 0xD6,
  31929. 0x20, 0xE3, 0xB6, 0x29, 0x45, 0x51, 0x01, 0xA1,
  31930. 0xF1, 0xCC, 0x7B, 0xA5, 0xE4, 0x6E, 0x68, 0xED,
  31931. 0x4A, 0x8C, 0xCC, 0x87, 0xB4, 0xDC, 0x75, 0xBC,
  31932. 0x01, 0x62, 0xB6, 0x33, 0x0F, 0x83, 0x3F, 0xBA,
  31933. 0x25, 0x75, 0xDF, 0xAF, 0x5B, 0x5F, 0x28, 0xBC,
  31934. 0x54, 0xFF, 0x2B, 0xA8, 0x1E, 0x7A, 0x47, 0x31,
  31935. 0x3C, 0x15, 0x48, 0x2B, 0x60, 0x5E, 0x66, 0xBB,
  31936. 0x38, 0xC6, 0x19, 0x8F, 0x13, 0x92, 0x10, 0x40,
  31937. 0x80, 0xFB, 0xE7, 0x8B, 0x86, 0xB1, 0xBC, 0x9A,
  31938. 0x6F, 0xB8, 0x81, 0xF5, 0xC7, 0x82, 0x01, 0x47,
  31939. 0xE6, 0xBA, 0x14, 0xB8, 0x1A, 0xCC, 0xF2, 0x0C,
  31940. 0xAE, 0x96, 0x64, 0x10, 0x94, 0xC2, 0x16, 0x90,
  31941. 0x2E, 0xA5, 0xC1, 0x25, 0xF6, 0xC9, 0x35, 0xA1,
  31942. 0x50, 0xD7, 0xC9, 0xAC, 0xC5, 0xD9, 0xE2, 0xE5,
  31943. 0xD9, 0x0E, 0x38, 0xC0, 0x50, 0x3A, 0xA9, 0x42,
  31944. 0x60, 0x17, 0xC7, 0x6A, 0xAF, 0xCD, 0x52, 0x61,
  31945. 0xB5, 0x06, 0x27, 0x4E, 0xC1, 0x3A, 0x96, 0x79,
  31946. 0xFB, 0x09, 0x79, 0x60, 0x27, 0xA4, 0xBB, 0x75,
  31947. 0x9D, 0x92, 0x82, 0x79, 0xB9, 0x4D, 0x84, 0x1A,
  31948. 0x09, 0x73, 0x93, 0xBF, 0x7E, 0x5B, 0xD6, 0x9A,
  31949. 0x49, 0x6C, 0xC3, 0xDE, 0xCD, 0x2B, 0x0F, 0x07,
  31950. 0xF8, 0x33, 0x92, 0xAA, 0xDE, 0x33, 0xDC, 0x51,
  31951. 0xB2, 0xA8, 0x4F, 0x6A, 0x07, 0x63, 0x5D, 0xC0,
  31952. 0xEF, 0x57, 0xA9, 0xAD, 0x59, 0x59, 0xB6, 0xA5,
  31953. 0x0B, 0x7B, 0xA5, 0x09, 0xAD, 0x5B, 0x11, 0xFA,
  31954. 0xD2, 0x6B, 0x41, 0x9F, 0x9F, 0x1E, 0x3F, 0x9C,
  31955. 0x73, 0x29, 0xB5, 0xA9, 0x53, 0xD7, 0xCC, 0x87,
  31956. 0xB2, 0xDE, 0x21, 0x06, 0x11, 0xCF, 0x52, 0xA6,
  31957. 0x39, 0xEF, 0x2B, 0x39, 0x08, 0x01, 0x2C, 0xB8,
  31958. 0x8E, 0x1D, 0x6F, 0x57, 0x62, 0x50, 0x79, 0xCB,
  31959. 0x10, 0x3D, 0x6C, 0x98, 0x10, 0x1A, 0x11, 0xBD,
  31960. 0x22, 0x33, 0xB6, 0x56, 0x02, 0xCA, 0x30, 0x49,
  31961. 0xBD, 0x32, 0x05, 0x20, 0x41, 0x9F, 0x76, 0xB0,
  31962. 0x61, 0xE3, 0x59, 0x8D, 0xE3, 0x81, 0x52, 0xC8,
  31963. 0x87, 0x67, 0xD1, 0xA2, 0x4F, 0xBD, 0x02, 0xBB,
  31964. 0x10, 0xC3, 0x8E, 0xAC, 0xAE, 0x31, 0x7D, 0xE6,
  31965. 0xBB, 0x28, 0x7B, 0x4D, 0x2C, 0xAE, 0x5D, 0xA0,
  31966. 0x21, 0x49, 0x65, 0xD8, 0x77, 0x37, 0x78, 0x62,
  31967. 0x6E, 0x9B, 0x97, 0x28, 0x59, 0xD8, 0x48, 0x2B,
  31968. 0x8D, 0x05, 0x47, 0xE4, 0xF5, 0x6D, 0xFF, 0x87,
  31969. 0x68, 0x1D, 0x5B, 0xC5, 0x12, 0x0F, 0x61, 0x3F,
  31970. 0xBB, 0xD9, 0x1E, 0x1F, 0x14, 0xE6, 0xDE, 0xFE,
  31971. 0x67, 0x2E, 0x2A, 0x7E, 0xAB, 0xCB, 0xBB, 0x9B,
  31972. 0x11, 0x08, 0x2C, 0x5E, 0x70, 0x0A, 0xA0, 0xB1,
  31973. 0xF7, 0xC1, 0x78, 0x5F, 0xCE, 0xD1, 0x9A, 0x93,
  31974. 0xAF, 0xE7, 0xC5, 0x9F, 0xA2, 0x51, 0x9B, 0xCD,
  31975. 0xEB, 0x49, 0x4C, 0x3D, 0x13, 0xB2, 0x12, 0x5F,
  31976. 0x38, 0x53, 0x23, 0xB8, 0x16, 0xC6, 0x8F, 0x8F,
  31977. 0x56, 0x28, 0xC7, 0xC2, 0xAB, 0xFD, 0x02, 0x78,
  31978. 0xA3, 0x37, 0x07, 0x3D, 0xA7, 0x4D, 0x16, 0x09,
  31979. 0x96, 0x98, 0xC4, 0xB1, 0x14, 0xE8, 0xA8, 0xCE,
  31980. 0x34, 0x4E, 0x0A, 0x15, 0xD0, 0xFC, 0x7E, 0xD4,
  31981. 0x97, 0xB0, 0x01, 0xD5, 0x3D, 0x4C, 0x96, 0xDC,
  31982. 0x39, 0x54, 0xD3, 0xB4, 0xB9, 0x56, 0xCB, 0x9D,
  31983. 0x2A, 0x27, 0x2C, 0x51, 0xF1, 0x55, 0x9B, 0x22,
  31984. 0x90, 0x4B, 0x40, 0xCC, 0x85, 0x31, 0xE4, 0x0C,
  31985. 0xC4, 0x12, 0xC6, 0x8C, 0xB6, 0xEE, 0xA4, 0xA4,
  31986. 0x09, 0x0B, 0x38, 0xE2, 0x79, 0x73, 0x29, 0x98,
  31987. 0x54, 0x67, 0xE8, 0x18, 0xA5, 0x24, 0xD3, 0x22,
  31988. 0x8E, 0xAC, 0xAE, 0x78, 0x25, 0xD3, 0xDA, 0xD2,
  31989. 0xEA, 0xA4, 0x22, 0xFD, 0xC7, 0x7A, 0xED, 0x71,
  31990. 0xA2, 0x05, 0xDA, 0x78, 0x38, 0xD9, 0x45, 0xE7,
  31991. 0xFE, 0xC3, 0x7E, 0x4D, 0xCA, 0x67, 0xE5, 0x04,
  31992. 0xCE, 0x35, 0xE5, 0xB0, 0x45, 0xF5, 0x6F, 0x1E,
  31993. 0x8D, 0x75, 0x29, 0xEB, 0xD6, 0xF1, 0xAF, 0x7B,
  31994. 0x6E, 0x93, 0x9E, 0x2B, 0x7A, 0xB4, 0x02, 0x7D,
  31995. 0x37, 0xA5, 0x13, 0x5D, 0x17, 0x2D, 0xA1, 0xAF,
  31996. 0x9C, 0xA2, 0xF7, 0x28, 0xA6, 0xF3, 0x7D, 0xE6,
  31997. 0x0D, 0xD2, 0x3D, 0x97, 0xD1, 0x1E, 0x75, 0xAB,
  31998. 0x1F, 0xD5, 0x1F, 0x8E, 0x9A, 0x13, 0x97, 0xE5,
  31999. 0x82, 0x21, 0x59, 0xDB, 0x58, 0x38, 0x02, 0xB3,
  32000. 0x2E, 0xEB, 0xB4, 0x56, 0x7E, 0xCE, 0x37, 0x46,
  32001. 0xD1, 0xAE, 0x33, 0x31, 0x47, 0x85, 0x64, 0x3D,
  32002. 0xD2, 0xA0, 0x74, 0x1E, 0x7F, 0x1B, 0xF2, 0xD2,
  32003. 0x61, 0xF2, 0x21, 0x24, 0xE8, 0xDD, 0xD0, 0x8C,
  32004. 0x64, 0x0A, 0x48, 0xB5, 0x47, 0x17, 0x51, 0x7C,
  32005. 0x21, 0xCD, 0x32, 0x53, 0x28, 0xBC, 0x23, 0x9C,
  32006. 0xA0, 0x28, 0xB2, 0x63, 0x0D, 0x06, 0x3C, 0x8C,
  32007. 0xC2, 0x0B, 0xE9, 0xBD, 0xB4, 0x85, 0x02, 0xDA,
  32008. 0xDD, 0xE7, 0x3F, 0xFE, 0xD5, 0x96, 0x38, 0x16,
  32009. 0x53, 0x3E, 0x02, 0x0A, 0xED, 0x12, 0x08, 0x53,
  32010. 0x62, 0x55, 0xB1, 0xCC, 0xE9, 0x85, 0x43, 0x31,
  32011. 0x27, 0xFF, 0x4F, 0x04, 0xD5, 0xB1, 0xE2, 0xF2,
  32012. 0x10, 0x87, 0x04, 0xB8, 0xB9, 0x66, 0x58, 0x8C,
  32013. 0x01, 0x56, 0xAF, 0xC2, 0xAE, 0x19, 0x29, 0x86,
  32014. 0xFB, 0xEC, 0x44, 0x3B, 0xAE, 0xF6, 0xCB, 0x85,
  32015. 0xA6, 0xF2, 0x9C, 0x77, 0x92, 0x40, 0x5A, 0x24,
  32016. 0x11, 0x47, 0x10, 0xAE, 0x1C, 0x74, 0x64, 0x44,
  32017. 0xFD, 0xF5, 0xFB, 0x65, 0x9E, 0x5E, 0x34, 0x68,
  32018. 0x26, 0x20, 0x7B, 0x8C, 0x54, 0x46, 0x3A, 0x06,
  32019. 0x17, 0xCE, 0x17, 0xFF, 0x33, 0xE4, 0x0F, 0x93,
  32020. 0x1F, 0xE5, 0x76, 0x71, 0x5C, 0x93, 0x2E, 0xF2,
  32021. 0x9F, 0xD7, 0x6B, 0x04, 0xA6, 0x9B, 0x58, 0xE0,
  32022. 0x30, 0x3D, 0x8E, 0xF2, 0x56, 0x78, 0xC8, 0xB7,
  32023. 0x0A, 0xF1, 0x2E, 0x90, 0x45, 0x59, 0x1C, 0x04,
  32024. 0xE8, 0xB7, 0x71, 0x06, 0x94, 0x04, 0x15, 0x17,
  32025. 0x7E, 0x86, 0x85, 0x93, 0xA0, 0x9C, 0x7E, 0x14,
  32026. 0x61, 0x9A, 0x4B, 0x33, 0x2F, 0x9A, 0xDC, 0x3A,
  32027. 0x65, 0x8B, 0x86, 0x01, 0x7F, 0x32, 0x65, 0x6C,
  32028. 0x54, 0x29, 0xC1, 0x15, 0xE1, 0x10, 0x03, 0x7A,
  32029. 0x8C, 0xC7, 0xE5, 0x44, 0x67, 0x7D, 0x2D, 0xD2,
  32030. 0x39, 0xA5, 0x9D, 0x54, 0xD0, 0xF3, 0xC7, 0x46,
  32031. 0x0E, 0xC1, 0x52, 0x08, 0x34, 0x6B, 0xA5, 0x6D,
  32032. 0xF5, 0x08, 0x6C, 0x5D, 0xBC, 0xC4, 0x1E, 0x0C,
  32033. 0x95, 0xFC, 0xB6, 0x86, 0x1C, 0x2C, 0x0C, 0x32,
  32034. 0xAA, 0xF3, 0x45, 0x4E, 0xFE, 0xE2, 0xFF, 0xBA,
  32035. 0x21, 0x4B, 0x43, 0x0E, 0xF2, 0x48, 0xA5, 0x9B,
  32036. 0x32, 0x44, 0x4D, 0x8D, 0x0D, 0x3D, 0xB8, 0x7C,
  32037. 0x9D, 0x4B, 0x15, 0x36, 0xD1, 0x57, 0x72, 0x8E,
  32038. 0xE7, 0x58, 0x5E, 0xF5, 0x32, 0x77, 0x6A, 0x00,
  32039. 0x3A, 0x02, 0x3C, 0x0A, 0xB0, 0xE9, 0xFF, 0x55,
  32040. 0x71, 0x08, 0xC3, 0x90, 0x68, 0x4D, 0x56, 0x5A,
  32041. 0x66, 0x50, 0x63, 0x26, 0x6A, 0xE6, 0x67, 0x0E,
  32042. 0xD5, 0x3B, 0x0F, 0xAF, 0x8F, 0xF6, 0x78, 0x29,
  32043. 0xBB, 0x73, 0x78, 0x25, 0xB1, 0x53, 0xA9, 0x33,
  32044. 0x8C, 0xBE, 0x3D, 0xF1, 0xA4, 0x62, 0x84, 0x9B,
  32045. 0x93, 0xA8, 0x1F, 0x84, 0xED, 0x07, 0xBE, 0x6D,
  32046. 0x62, 0x40, 0x00, 0x32, 0x74, 0x73, 0x7F, 0x61,
  32047. 0x8D, 0xCB, 0x26, 0xE4, 0x82, 0x52, 0xCE, 0x42,
  32048. 0x04, 0xDD, 0x31, 0x39, 0xFF, 0x68, 0x76, 0xF4,
  32049. 0x3B, 0x30, 0x5D, 0x83, 0x56, 0x20, 0xFE, 0xDF,
  32050. 0x79, 0xAA, 0x67, 0x43, 0x3D, 0xC2, 0x52, 0x87,
  32051. 0x32, 0x0E, 0x99, 0x17, 0x96, 0x7B, 0x70, 0xB2,
  32052. 0xD8, 0x66, 0xD1, 0x7B, 0x69, 0x8B, 0xFF, 0xF2,
  32053. 0xB3, 0xAB, 0x95, 0x14, 0x94, 0x9E, 0x58, 0xB5,
  32054. 0x7C, 0x68, 0xA4, 0x54, 0x12, 0xC1, 0xFC, 0x42,
  32055. 0x1C, 0x76, 0x8B, 0xF5, 0xEE, 0x8A, 0x10, 0xC8,
  32056. 0xAE, 0xF5, 0x69, 0x26, 0xF5, 0x1E, 0xC6, 0x2C,
  32057. 0x11, 0x56, 0x9F, 0x31, 0xAA, 0x51, 0x78, 0x68,
  32058. 0xE5, 0xCA, 0xD8, 0x9E, 0x95, 0x80, 0x66, 0xEB,
  32059. 0x9E, 0xDD, 0x72, 0x71, 0xB3, 0x1C, 0xB4, 0xB1,
  32060. 0xD6, 0xCE, 0x21, 0x12, 0x25, 0xAE, 0xB5, 0xB5,
  32061. 0x7F, 0x74, 0x97, 0x19, 0xDA, 0x07, 0xEC, 0xBE,
  32062. 0xFE, 0x03, 0x88, 0x1D, 0xDE, 0x3D, 0x81, 0xE4,
  32063. 0x13, 0x5F, 0x2D, 0xC8, 0x1A, 0xF7, 0x79, 0x77,
  32064. 0x6C, 0x1B, 0x80, 0x57, 0x16, 0x2A, 0x6C, 0x98,
  32065. 0x2F, 0xBB, 0x4D, 0xA6, 0xA9, 0xAD, 0x28, 0x4A,
  32066. 0xB1, 0x0C, 0x70, 0x02, 0x20, 0x44, 0xF4, 0x6D,
  32067. 0x40, 0x0B, 0xF6, 0xAD, 0x71, 0x82, 0xD1, 0x97,
  32068. 0x78, 0x99, 0x83, 0xBE, 0x99, 0x22, 0x79, 0x79,
  32069. 0xA1, 0x33, 0x4B, 0xA1, 0x49, 0xD8, 0x69, 0xBA,
  32070. 0x1C, 0x40, 0x88, 0x12, 0x34, 0x35, 0xBF, 0x97,
  32071. 0x85, 0x41, 0x35, 0x6D, 0xAF, 0x17, 0x1F, 0x33,
  32072. 0xAD, 0xB1, 0xC9, 0x79, 0x07, 0xA0, 0xFB, 0x58,
  32073. 0x45, 0x07, 0x4A, 0x85, 0xD2, 0x6F, 0x54, 0x61,
  32074. 0x35, 0xAE, 0xD0, 0xF9, 0x1B, 0xE4, 0x53, 0x9C,
  32075. 0x12, 0xBF, 0x94, 0x11, 0xE4, 0xB5, 0x56, 0xF6,
  32076. 0x87, 0xD0, 0x69, 0xDB, 0x6B, 0x21, 0xFE, 0x2B,
  32077. 0x7F, 0x32, 0x18, 0x87, 0x44, 0x8C, 0xEA, 0x55,
  32078. 0xDB, 0x19, 0xFB, 0xB8, 0xB0, 0x48, 0x2A, 0x55,
  32079. 0xAE, 0xC1, 0x67, 0x38, 0xD7, 0x4C, 0xD2, 0x65,
  32080. 0x09, 0x38, 0x36, 0xBE, 0x99, 0xD4, 0xFB, 0x53,
  32081. 0xE9, 0xB0, 0x14, 0xB0, 0x37, 0xCD, 0xBF, 0xE9
  32082. };
  32083. static const byte sk_87[] = {
  32084. 0x69, 0x24, 0xBB, 0x42, 0x57, 0xA7, 0xB9, 0xAF,
  32085. 0xF0, 0x95, 0xC3, 0x0B, 0xB3, 0x5C, 0x6A, 0xE4,
  32086. 0x19, 0x82, 0x63, 0x12, 0x0F, 0x80, 0x39, 0xAA,
  32087. 0x4E, 0x78, 0xE1, 0x74, 0xA7, 0x86, 0xCE, 0x00,
  32088. 0x3B, 0x9A, 0xC2, 0xC1, 0x42, 0x2A, 0x1A, 0xE8,
  32089. 0x02, 0xDD, 0xD7, 0x46, 0x4D, 0x3F, 0x32, 0x72,
  32090. 0x9A, 0x3C, 0x7D, 0xE8, 0x94, 0xD5, 0x06, 0xAC,
  32091. 0xAD, 0x25, 0xCE, 0xB3, 0x72, 0xEA, 0x31, 0x49,
  32092. 0xC9, 0x87, 0x80, 0xDC, 0xD1, 0x31, 0x4B, 0xAA,
  32093. 0x29, 0xB9, 0xB8, 0x07, 0x75, 0x4C, 0x47, 0xDE,
  32094. 0x5D, 0xCA, 0x95, 0x40, 0x64, 0xF2, 0x85, 0x28,
  32095. 0xB8, 0x15, 0xFE, 0x27, 0xB7, 0x9A, 0xC5, 0x06,
  32096. 0xB3, 0xAD, 0x76, 0x29, 0xD2, 0xC9, 0x71, 0xAB,
  32097. 0x8F, 0x28, 0x2E, 0x0C, 0x6E, 0x7E, 0x55, 0x48,
  32098. 0xEE, 0x0E, 0x11, 0x32, 0x42, 0xB7, 0xA0, 0xE0,
  32099. 0x64, 0xA6, 0xDB, 0xCE, 0x30, 0xC5, 0x61, 0x9B,
  32100. 0x19, 0x80, 0x08, 0x89, 0xA0, 0x44, 0x04, 0xB5,
  32101. 0x00, 0x13, 0xC0, 0x88, 0xC1, 0x30, 0x29, 0x62,
  32102. 0x12, 0x4C, 0xD3, 0xB4, 0x91, 0x0A, 0x35, 0x2C,
  32103. 0x43, 0x12, 0x31, 0x19, 0x99, 0x65, 0x22, 0x18,
  32104. 0x52, 0x02, 0xC3, 0x85, 0x23, 0x44, 0x0D, 0x90,
  32105. 0x24, 0x4A, 0x1A, 0x30, 0x22, 0x44, 0x28, 0x61,
  32106. 0x81, 0x06, 0x29, 0x18, 0x97, 0x68, 0x0A, 0x20,
  32107. 0x09, 0x08, 0x32, 0x6A, 0x44, 0xA4, 0x4C, 0x44,
  32108. 0x90, 0x21, 0x8A, 0x16, 0x68, 0x9A, 0xA8, 0x51,
  32109. 0x1A, 0xA5, 0x2C, 0x62, 0x46, 0x8D, 0x04, 0xC3,
  32110. 0x40, 0xD3, 0x86, 0x28, 0x60, 0xA4, 0x60, 0x13,
  32111. 0x18, 0x70, 0x84, 0x94, 0x8C, 0x63, 0xC0, 0x44,
  32112. 0x04, 0xA9, 0x28, 0x20, 0x08, 0x20, 0x43, 0x16,
  32113. 0x2A, 0x23, 0x29, 0x2D, 0x1A, 0xB1, 0x29, 0x48,
  32114. 0xB6, 0x09, 0x21, 0x88, 0x31, 0x00, 0xC5, 0x30,
  32115. 0x00, 0xC4, 0x8C, 0xD9, 0x82, 0x68, 0xE1, 0x30,
  32116. 0x4C, 0x63, 0x32, 0x45, 0x0C, 0x32, 0x86, 0x18,
  32117. 0x08, 0x31, 0x91, 0x98, 0x0D, 0x10, 0xB8, 0x70,
  32118. 0x9B, 0x30, 0x22, 0x64, 0x04, 0x08, 0x93, 0xA4,
  32119. 0x8C, 0x21, 0xC9, 0x70, 0x0C, 0x35, 0x71, 0x5B,
  32120. 0x00, 0x0D, 0x14, 0x31, 0x22, 0xCC, 0x98, 0x10,
  32121. 0x21, 0x04, 0x80, 0x9B, 0x28, 0x64, 0x1C, 0x30,
  32122. 0x80, 0x21, 0x30, 0x71, 0x18, 0x33, 0x50, 0x24,
  32123. 0x25, 0x44, 0x08, 0x17, 0x8C, 0xC0, 0x08, 0x48,
  32124. 0x84, 0x44, 0x90, 0x48, 0x98, 0x30, 0xCA, 0x44,
  32125. 0x00, 0x09, 0x19, 0x51, 0x19, 0x23, 0x0C, 0x52,
  32126. 0x20, 0x0E, 0x49, 0x06, 0x32, 0x1C, 0x15, 0x4E,
  32127. 0x19, 0x48, 0x85, 0x13, 0x25, 0x49, 0xA3, 0x00,
  32128. 0x04, 0x08, 0x15, 0x6D, 0x20, 0x41, 0x0C, 0xDA,
  32129. 0x42, 0x52, 0xC1, 0x34, 0x8C, 0x00, 0x31, 0x69,
  32130. 0x43, 0x82, 0x24, 0x64, 0x94, 0x6D, 0x1C, 0x81,
  32131. 0x11, 0x01, 0x96, 0x21, 0x4B, 0x02, 0x00, 0xCA,
  32132. 0x28, 0x84, 0xCC, 0x46, 0x64, 0x51, 0x18, 0x6A,
  32133. 0x18, 0x10, 0x00, 0xA4, 0x98, 0x21, 0x60, 0xB0,
  32134. 0x68, 0x03, 0x94, 0x6C, 0x94, 0x48, 0x51, 0x80,
  32135. 0x40, 0x46, 0x92, 0x22, 0x2C, 0x23, 0x44, 0x69,
  32136. 0x98, 0x26, 0x4D, 0x1C, 0x01, 0x08, 0x52, 0x02,
  32137. 0x20, 0x8A, 0xA6, 0x08, 0x0A, 0x31, 0x61, 0x93,
  32138. 0x40, 0x0E, 0x9C, 0xC8, 0x11, 0x81, 0x32, 0x2E,
  32139. 0x21, 0x15, 0x84, 0x84, 0xC2, 0x41, 0x00, 0x22,
  32140. 0x72, 0x54, 0x22, 0x62, 0x58, 0x06, 0x92, 0x48,
  32141. 0x48, 0x44, 0x11, 0x27, 0x04, 0x04, 0xC0, 0x11,
  32142. 0x92, 0x82, 0x45, 0xA1, 0xC6, 0x8C, 0xE3, 0x32,
  32143. 0x66, 0xC1, 0x38, 0x72, 0x5A, 0x86, 0x01, 0x0C,
  32144. 0xC9, 0x90, 0x84, 0x34, 0x08, 0x58, 0xA8, 0x60,
  32145. 0x80, 0xC0, 0x70, 0xD0, 0x26, 0x62, 0x9B, 0x30,
  32146. 0x2A, 0x04, 0x29, 0x69, 0x04, 0x10, 0x8D, 0x0B,
  32147. 0xB9, 0x04, 0x50, 0x46, 0x28, 0x50, 0x48, 0x24,
  32148. 0xD0, 0x48, 0x05, 0xA2, 0x48, 0x02, 0xC3, 0x20,
  32149. 0x8C, 0xA0, 0x14, 0x00, 0x41, 0x38, 0x21, 0x4B,
  32150. 0x24, 0x01, 0x04, 0xB5, 0x49, 0x42, 0x00, 0x00,
  32151. 0x0C, 0x24, 0x28, 0x12, 0x40, 0x84, 0xA2, 0x20,
  32152. 0x44, 0x9B, 0x06, 0x90, 0x63, 0xC0, 0x88, 0x8C,
  32153. 0x14, 0x21, 0x49, 0x12, 0x10, 0x54, 0x16, 0x24,
  32154. 0x20, 0x87, 0x44, 0x50, 0x10, 0x85, 0x0C, 0xB5,
  32155. 0x64, 0xDB, 0x24, 0x41, 0xD0, 0x42, 0x29, 0x9A,
  32156. 0x16, 0x8A, 0x21, 0xB4, 0x4C, 0x13, 0xB7, 0x70,
  32157. 0x10, 0xC0, 0x85, 0x19, 0x02, 0x69, 0xCC, 0x40,
  32158. 0x61, 0x1C, 0x48, 0x46, 0x98, 0x06, 0x25, 0x60,
  32159. 0x14, 0x46, 0xE4, 0x22, 0x62, 0x24, 0x27, 0x22,
  32160. 0x62, 0x24, 0x29, 0x44, 0xC6, 0x2D, 0x08, 0x31,
  32161. 0x84, 0x20, 0x32, 0x21, 0x04, 0xB4, 0x61, 0x0A,
  32162. 0x38, 0x12, 0xD9, 0x28, 0x44, 0xA4, 0x08, 0x20,
  32163. 0xCC, 0xA8, 0x29, 0x0B, 0x21, 0x31, 0x0A, 0x34,
  32164. 0x29, 0x03, 0x21, 0x40, 0xC1, 0xA2, 0x6C, 0x8A,
  32165. 0x16, 0x12, 0x52, 0xA6, 0x64, 0xA3, 0xB2, 0x51,
  32166. 0x04, 0x29, 0x51, 0xC4, 0x04, 0x91, 0x63, 0xB0,
  32167. 0x2D, 0x14, 0x44, 0x30, 0x8C, 0x40, 0x66, 0x0C,
  32168. 0x40, 0x0C, 0x01, 0xA5, 0x2C, 0x09, 0x94, 0x2D,
  32169. 0x62, 0xC6, 0x11, 0x03, 0x98, 0x50, 0x19, 0x10,
  32170. 0x4D, 0x19, 0xA8, 0x28, 0xD3, 0x86, 0x40, 0xC0,
  32171. 0x30, 0x65, 0x54, 0xA6, 0x71, 0xE0, 0xB4, 0x85,
  32172. 0x9B, 0x86, 0x10, 0x04, 0x36, 0x69, 0xD0, 0x46,
  32173. 0x29, 0x18, 0xA3, 0x71, 0x40, 0x22, 0x49, 0x00,
  32174. 0x43, 0x85, 0xCB, 0x40, 0x28, 0x89, 0x36, 0x66,
  32175. 0x41, 0x22, 0x69, 0xA4, 0x28, 0x51, 0xD9, 0x80,
  32176. 0x29, 0x14, 0x07, 0x21, 0xDA, 0x80, 0x91, 0x1B,
  32177. 0x26, 0x50, 0x5B, 0xA0, 0x60, 0x99, 0x42, 0x71,
  32178. 0x50, 0x88, 0x49, 0x10, 0x23, 0x09, 0x5A, 0x90,
  32179. 0x21, 0x22, 0x27, 0x8E, 0x43, 0xB2, 0x70, 0x0C,
  32180. 0xC9, 0x4C, 0xA4, 0x02, 0x70, 0x92, 0x40, 0x10,
  32181. 0x0A, 0x39, 0x70, 0x02, 0x36, 0x0E, 0x11, 0x30,
  32182. 0x41, 0xD8, 0x40, 0x2D, 0x1B, 0x24, 0x6D, 0xC3,
  32183. 0x92, 0x61, 0x4C, 0x86, 0x8D, 0x21, 0xB8, 0x00,
  32184. 0xD3, 0x24, 0x22, 0x12, 0xC8, 0x21, 0x12, 0x99,
  32185. 0x85, 0x09, 0x16, 0x0C, 0x5A, 0xA2, 0x24, 0x09,
  32186. 0x34, 0x42, 0x10, 0xA2, 0x24, 0x03, 0x42, 0x8C,
  32187. 0xC0, 0xB2, 0x8D, 0x12, 0xB6, 0x69, 0x63, 0x34,
  32188. 0x0D, 0xCC, 0xB0, 0x65, 0xA1, 0x12, 0x11, 0x4A,
  32189. 0x38, 0x69, 0xCC, 0x14, 0x81, 0x58, 0x44, 0x09,
  32190. 0x54, 0xA6, 0x80, 0x0C, 0xA8, 0x05, 0xC4, 0x38,
  32191. 0x8A, 0x84, 0x06, 0x01, 0x9B, 0x32, 0x2D, 0x83,
  32192. 0x12, 0x90, 0x09, 0x02, 0x60, 0xA1, 0x28, 0x88,
  32193. 0x58, 0x10, 0x41, 0x24, 0x40, 0x02, 0x19, 0x34,
  32194. 0x48, 0x18, 0xA0, 0x4D, 0x00, 0x10, 0x62, 0x13,
  32195. 0x22, 0x50, 0xE3, 0x38, 0x21, 0x9A, 0x96, 0x21,
  32196. 0x53, 0x08, 0x80, 0x51, 0x26, 0x01, 0x99, 0xC4,
  32197. 0x28, 0x1B, 0xB9, 0x71, 0x04, 0x97, 0x84, 0x04,
  32198. 0x05, 0x2C, 0xA0, 0xC2, 0x10, 0xD3, 0x42, 0x81,
  32199. 0x81, 0x42, 0x4D, 0x61, 0x84, 0x6C, 0x5A, 0x30,
  32200. 0x49, 0x1B, 0xC2, 0x24, 0xC0, 0x20, 0x28, 0xCA,
  32201. 0x92, 0x2D, 0x4A, 0x90, 0x10, 0x04, 0x27, 0x86,
  32202. 0x4C, 0x96, 0x21, 0x09, 0x19, 0x45, 0x14, 0x82,
  32203. 0x2C, 0x11, 0xA6, 0x91, 0x13, 0xB8, 0x04, 0x03,
  32204. 0x18, 0x70, 0x01, 0xA2, 0x51, 0x52, 0x14, 0x49,
  32205. 0x5A, 0x02, 0x30, 0xCB, 0x30, 0x2C, 0x94, 0x10,
  32206. 0x2C, 0x00, 0x49, 0x86, 0x09, 0xA0, 0x25, 0xC2,
  32207. 0x12, 0x4C, 0x1B, 0x02, 0x69, 0x40, 0xA4, 0x44,
  32208. 0x41, 0x16, 0x62, 0x02, 0x25, 0x28, 0xDC, 0xA2,
  32209. 0x2D, 0x00, 0x16, 0x42, 0x58, 0x30, 0x66, 0x5B,
  32210. 0x86, 0x24, 0xD4, 0x24, 0x48, 0xDB, 0x26, 0x0C,
  32211. 0x4C, 0x08, 0x85, 0x01, 0x90, 0x49, 0x21, 0x24,
  32212. 0x41, 0x54, 0x06, 0x84, 0x02, 0x43, 0x4A, 0x24,
  32213. 0x42, 0x05, 0x40, 0x14, 0x48, 0xCA, 0x44, 0x84,
  32214. 0xC0, 0x42, 0x0C, 0x98, 0x26, 0x04, 0x9C, 0xA2,
  32215. 0x05, 0xD1, 0xC2, 0x51, 0x13, 0x01, 0x86, 0x1C,
  32216. 0xA1, 0x50, 0xD9, 0x02, 0x50, 0x0C, 0x39, 0x86,
  32217. 0x8C, 0x00, 0x31, 0x22, 0x05, 0x48, 0xD3, 0x10,
  32218. 0x81, 0x12, 0x48, 0x05, 0xD1, 0x08, 0x69, 0x62,
  32219. 0x38, 0x2C, 0x0A, 0x23, 0x70, 0x9B, 0x44, 0x72,
  32220. 0xE3, 0x48, 0x6E, 0x22, 0x96, 0x70, 0x14, 0x33,
  32221. 0x6C, 0xD8, 0x90, 0x29, 0x03, 0x00, 0x49, 0x63,
  32222. 0x20, 0x8A, 0x03, 0x91, 0x25, 0x08, 0x89, 0x21,
  32223. 0xC0, 0x82, 0x0C, 0x99, 0x40, 0x32, 0xC2, 0x34,
  32224. 0x4E, 0x4B, 0x98, 0x69, 0x09, 0x80, 0x44, 0xE4,
  32225. 0x04, 0x69, 0x94, 0x20, 0x09, 0x99, 0x24, 0x6D,
  32226. 0x09, 0xA9, 0x60, 0x01, 0x29, 0x2D, 0xC8, 0x42,
  32227. 0x28, 0x8A, 0x34, 0x02, 0xE4, 0x08, 0x70, 0x0C,
  32228. 0x23, 0x6E, 0x0A, 0x05, 0x49, 0x64, 0x44, 0x2A,
  32229. 0x82, 0xC8, 0x00, 0x02, 0x48, 0x31, 0xCB, 0x90,
  32230. 0x50, 0x1C, 0x05, 0x68, 0x12, 0x12, 0x2C, 0xD0,
  32231. 0x80, 0x0C, 0x59, 0x48, 0x61, 0xCB, 0xA6, 0x09,
  32232. 0x9C, 0xC0, 0x81, 0x42, 0xB8, 0x00, 0x24, 0x41,
  32233. 0x8A, 0x94, 0x20, 0x40, 0x42, 0x14, 0x4D, 0x19,
  32234. 0x46, 0x62, 0x18, 0x05, 0x09, 0x24, 0x33, 0x6A,
  32235. 0xD4, 0x00, 0x61, 0x12, 0x48, 0x32, 0x8A, 0x04,
  32236. 0x72, 0x93, 0xB4, 0x69, 0x62, 0xC2, 0x71, 0x41,
  32237. 0xA6, 0x89, 0x44, 0x96, 0x31, 0x62, 0x30, 0x46,
  32238. 0x83, 0x42, 0x6C, 0x00, 0x19, 0x22, 0x09, 0x46,
  32239. 0x4D, 0x8B, 0x06, 0x49, 0xE1, 0xB0, 0x70, 0x42,
  32240. 0x44, 0x31, 0xC1, 0x80, 0x65, 0x9C, 0x00, 0x24,
  32241. 0x11, 0xA8, 0x31, 0x13, 0x21, 0x2C, 0x4B, 0x46,
  32242. 0x28, 0x1B, 0x18, 0x0D, 0x88, 0x42, 0x70, 0xD1,
  32243. 0xB0, 0x0D, 0x90, 0xC8, 0x45, 0xDA, 0xC2, 0x48,
  32244. 0x59, 0x14, 0x26, 0x22, 0x44, 0x00, 0xC2, 0x94,
  32245. 0x41, 0x50, 0xC8, 0x04, 0x18, 0x00, 0x00, 0xCB,
  32246. 0xA6, 0x24, 0x19, 0x02, 0x10, 0x10, 0x89, 0x0C,
  32247. 0x18, 0x22, 0x21, 0x62, 0xA8, 0x81, 0xC8, 0x92,
  32248. 0x48, 0xD3, 0x94, 0x20, 0x82, 0x06, 0x72, 0x09,
  32249. 0xA8, 0x90, 0x0C, 0x49, 0x8A, 0x41, 0x86, 0x28,
  32250. 0x19, 0xC5, 0x80, 0x9A, 0x18, 0x4D, 0x14, 0x10,
  32251. 0x2E, 0x22, 0x12, 0x52, 0x00, 0x08, 0x12, 0x0C,
  32252. 0x33, 0x45, 0x63, 0xC6, 0x30, 0x10, 0x93, 0x4C,
  32253. 0x60, 0xC6, 0x31, 0xDC, 0x40, 0x0E, 0x98, 0x82,
  32254. 0x50, 0x60, 0x02, 0x2A, 0xD2, 0x22, 0x40, 0xE4,
  32255. 0x06, 0x2D, 0xDB, 0x32, 0x0E, 0xCA, 0x32, 0x4E,
  32256. 0xD4, 0x18, 0x24, 0x08, 0xC3, 0x28, 0x4A, 0xC2,
  32257. 0x68, 0xE2, 0x80, 0x40, 0xA1, 0xC8, 0x64, 0x51,
  32258. 0xC2, 0x65, 0xCB, 0x16, 0x60, 0x23, 0x09, 0x4C,
  32259. 0x82, 0x04, 0x68, 0xD9, 0x22, 0x2E, 0x1C, 0x49,
  32260. 0x92, 0x42, 0x24, 0x21, 0x00, 0x37, 0x0E, 0xC8,
  32261. 0x12, 0x72, 0x64, 0x08, 0x25, 0x0A, 0x20, 0x2A,
  32262. 0x58, 0x24, 0x04, 0x59, 0x16, 0x4C, 0x08, 0x17,
  32263. 0x30, 0x00, 0x46, 0x05, 0x12, 0x90, 0x40, 0x03,
  32264. 0x07, 0x21, 0x52, 0xC0, 0x64, 0x1C, 0x83, 0x6D,
  32265. 0x9C, 0x32, 0x2E, 0x11, 0x15, 0x8A, 0x10, 0x35,
  32266. 0x88, 0x5A, 0xA0, 0x8D, 0xD9, 0x80, 0x48, 0x03,
  32267. 0xB6, 0x4C, 0x01, 0x10, 0x65, 0x10, 0x86, 0x40,
  32268. 0x11, 0x01, 0x42, 0x0A, 0xC1, 0x64, 0xDB, 0x22,
  32269. 0x4D, 0x64, 0xB2, 0x51, 0x02, 0x36, 0x0D, 0x93,
  32270. 0x46, 0x31, 0x14, 0xB6, 0x68, 0x63, 0x84, 0x29,
  32271. 0xC8, 0x10, 0x24, 0x94, 0x30, 0x08, 0x19, 0x37,
  32272. 0x02, 0x14, 0x82, 0x45, 0x88, 0x28, 0x40, 0x54,
  32273. 0xA8, 0x29, 0x90, 0x14, 0x12, 0x61, 0x36, 0x12,
  32274. 0x0B, 0x09, 0x8C, 0xA4, 0x98, 0x28, 0xC2, 0x92,
  32275. 0x45, 0x4C, 0x00, 0x60, 0x63, 0xC4, 0x81, 0xC0,
  32276. 0x36, 0x25, 0xCA, 0x88, 0x2D, 0x24, 0x40, 0x30,
  32277. 0xD3, 0xA8, 0x2D, 0xC9, 0xC8, 0x25, 0xD2, 0x84,
  32278. 0x48, 0x00, 0x32, 0x92, 0x50, 0xA2, 0x71, 0xD3,
  32279. 0x44, 0x0D, 0x22, 0x34, 0x60, 0x12, 0x13, 0x12,
  32280. 0x86, 0x8C, 0x5F, 0x86, 0x20, 0x79, 0x4A, 0x05,
  32281. 0x0E, 0x20, 0xD0, 0xE1, 0x01, 0x17, 0x86, 0x24,
  32282. 0x0E, 0xA6, 0x64, 0xF2, 0xF6, 0x9B, 0xB1, 0xB7,
  32283. 0xE3, 0x0E, 0xC6, 0x6B, 0x1A, 0x4A, 0x0B, 0xE5,
  32284. 0x9B, 0x79, 0xF2, 0x19, 0x8A, 0xD9, 0x80, 0x44,
  32285. 0x83, 0xE4, 0x75, 0xE5, 0x3B, 0x3C, 0x49, 0xCB,
  32286. 0x0C, 0xE5, 0xEF, 0x92, 0x91, 0x2A, 0xF4, 0x40,
  32287. 0xF2, 0x3B, 0x99, 0x58, 0x13, 0xD1, 0x1B, 0x59,
  32288. 0xF7, 0x98, 0xE9, 0x3C, 0x9D, 0x13, 0x53, 0x98,
  32289. 0x17, 0xC7, 0xAC, 0x68, 0xCA, 0xD1, 0xAA, 0x1A,
  32290. 0xC2, 0x76, 0x56, 0xBD, 0x0C, 0x47, 0x97, 0xE9,
  32291. 0xC8, 0xEC, 0x17, 0x78, 0x4C, 0x1A, 0x32, 0x7A,
  32292. 0x9D, 0xFE, 0xAF, 0x4D, 0x61, 0x91, 0xEE, 0xCD,
  32293. 0xAF, 0xE0, 0x49, 0xB7, 0x33, 0xFE, 0x39, 0xD5,
  32294. 0xEB, 0x40, 0x00, 0x93, 0x6F, 0xEE, 0xFC, 0xF8,
  32295. 0x29, 0x28, 0xE9, 0xF9, 0x4C, 0xFD, 0x5C, 0xF4,
  32296. 0xC1, 0xE3, 0xDE, 0xB1, 0x43, 0x3A, 0x47, 0xF6,
  32297. 0xD3, 0x28, 0xB5, 0xE8, 0x3D, 0xD1, 0x56, 0xD0,
  32298. 0x18, 0x2D, 0xC6, 0x92, 0x34, 0x75, 0x91, 0xAA,
  32299. 0x6F, 0x73, 0x2C, 0xFB, 0xE9, 0x82, 0x93, 0x5F,
  32300. 0xD1, 0x84, 0x6C, 0xAC, 0xF4, 0xCB, 0x85, 0x15,
  32301. 0xC5, 0x5A, 0xB8, 0x5E, 0xE5, 0xAD, 0x44, 0xCB,
  32302. 0x09, 0xD3, 0x26, 0x9E, 0x2E, 0x6D, 0x11, 0x78,
  32303. 0x09, 0x61, 0xFD, 0x13, 0x1D, 0x5E, 0x6F, 0xBF,
  32304. 0x89, 0x84, 0x9F, 0x47, 0xF2, 0xB7, 0x1D, 0x82,
  32305. 0x83, 0xFF, 0x25, 0x38, 0x5E, 0x52, 0xB0, 0x7D,
  32306. 0xBB, 0x26, 0x6C, 0x67, 0x4C, 0xEE, 0x3D, 0x0B,
  32307. 0x5D, 0xF5, 0xA5, 0x6D, 0x8B, 0xDC, 0xDC, 0xFA,
  32308. 0xAE, 0xE6, 0xA2, 0x48, 0xE7, 0x1D, 0xB1, 0x34,
  32309. 0x5A, 0xFC, 0x59, 0x7C, 0xA8, 0x30, 0xA1, 0xA3,
  32310. 0x5B, 0x43, 0x96, 0xEF, 0x4C, 0x1A, 0xDF, 0x9E,
  32311. 0xD0, 0x1B, 0xCE, 0x9B, 0x6E, 0xB6, 0x37, 0xFA,
  32312. 0x24, 0xAA, 0x16, 0x0B, 0x90, 0x76, 0xBA, 0xE3,
  32313. 0x05, 0x59, 0xF8, 0xB2, 0x9D, 0xED, 0xB3, 0xD2,
  32314. 0x5B, 0x79, 0x06, 0x4A, 0xB0, 0xCF, 0x8B, 0x8D,
  32315. 0x70, 0xAD, 0xDD, 0xEB, 0x8B, 0x17, 0x42, 0x48,
  32316. 0xD5, 0xAE, 0xA4, 0xD1, 0x8D, 0xE4, 0x3B, 0x89,
  32317. 0x38, 0xCD, 0xD2, 0xAC, 0xBA, 0x54, 0x77, 0xBD,
  32318. 0x4A, 0xAC, 0xC3, 0xCE, 0x59, 0x5E, 0x5D, 0x26,
  32319. 0x9F, 0xE6, 0x75, 0x21, 0x0D, 0x23, 0x15, 0x2B,
  32320. 0x04, 0x71, 0x0F, 0x36, 0x84, 0x28, 0x79, 0x4A,
  32321. 0x75, 0xF4, 0x9B, 0x68, 0x3E, 0xD2, 0x0D, 0xD6,
  32322. 0x47, 0x51, 0x57, 0x77, 0x95, 0x5A, 0x8C, 0xB3,
  32323. 0x8A, 0x36, 0xAF, 0xCD, 0x2C, 0xE0, 0xAC, 0xEC,
  32324. 0x4F, 0x0D, 0xFE, 0x80, 0x77, 0x02, 0xD1, 0xEB,
  32325. 0x3B, 0xDE, 0x72, 0xE9, 0xE0, 0x85, 0xAA, 0x4E,
  32326. 0x09, 0xEB, 0x1B, 0x09, 0x47, 0x41, 0x38, 0x52,
  32327. 0xEC, 0x3C, 0x0A, 0xC5, 0x2F, 0x06, 0xCB, 0x95,
  32328. 0x9C, 0x85, 0x39, 0x4E, 0xB3, 0x74, 0x81, 0x19,
  32329. 0xED, 0xBE, 0x6C, 0x80, 0xD2, 0xD8, 0xF7, 0x92,
  32330. 0xCE, 0x0D, 0x91, 0x5E, 0x4F, 0x4B, 0x15, 0x1E,
  32331. 0xFB, 0x13, 0x5E, 0x7F, 0x4D, 0xC9, 0x7D, 0x85,
  32332. 0x81, 0x41, 0xC5, 0x7F, 0x70, 0x41, 0x7B, 0x43,
  32333. 0xA6, 0xA1, 0x26, 0x95, 0x69, 0x78, 0xD7, 0x8E,
  32334. 0xFB, 0x9F, 0x03, 0x72, 0x43, 0xB4, 0xCB, 0x41,
  32335. 0xDF, 0x96, 0x8B, 0x7E, 0xE5, 0xB5, 0x20, 0x87,
  32336. 0xF0, 0x5A, 0xA9, 0xFE, 0x48, 0x7B, 0xD1, 0x6C,
  32337. 0x03, 0x47, 0xCF, 0x13, 0x35, 0x76, 0x0B, 0xD2,
  32338. 0x39, 0x8A, 0xD5, 0x4D, 0xDA, 0x00, 0xA5, 0xAA,
  32339. 0xC4, 0x46, 0xD8, 0x0B, 0x1C, 0x79, 0x98, 0xC6,
  32340. 0x02, 0x19, 0x2A, 0xDA, 0xFC, 0xB8, 0x09, 0xD1,
  32341. 0x4E, 0xE3, 0x28, 0x64, 0x1B, 0xA3, 0xAA, 0x00,
  32342. 0xF8, 0xD2, 0x9C, 0x3A, 0x84, 0x8A, 0xCB, 0xDC,
  32343. 0x19, 0x46, 0xBC, 0x0D, 0x35, 0xE0, 0xBE, 0x0F,
  32344. 0x8F, 0x7E, 0x3D, 0xA3, 0xF6, 0x8D, 0x9F, 0xA9,
  32345. 0x76, 0x8F, 0x5C, 0xF2, 0x75, 0x53, 0x4A, 0x0E,
  32346. 0xCA, 0x9E, 0x60, 0xFC, 0xEA, 0x38, 0xF1, 0xE0,
  32347. 0x42, 0xC3, 0x16, 0x14, 0x3A, 0x76, 0x7B, 0x33,
  32348. 0xAC, 0xCA, 0xD8, 0xC8, 0xD6, 0x6C, 0x70, 0xC7,
  32349. 0x5F, 0xD1, 0xF0, 0xB2, 0x58, 0x6B, 0x65, 0x3A,
  32350. 0xD4, 0xAF, 0x54, 0xE5, 0x6E, 0xF0, 0x69, 0x33,
  32351. 0xEA, 0xD3, 0x1D, 0xE3, 0x65, 0xD1, 0x10, 0xB9,
  32352. 0xC4, 0xA2, 0xA9, 0x8B, 0xCB, 0xA1, 0x65, 0xCA,
  32353. 0xFE, 0x38, 0x6F, 0x88, 0x7C, 0x72, 0x15, 0x6E,
  32354. 0xB1, 0x4F, 0xF0, 0xDA, 0xD6, 0x65, 0x61, 0x6C,
  32355. 0xE3, 0xCE, 0x65, 0xC1, 0x90, 0x4F, 0x2C, 0x17,
  32356. 0x47, 0xB2, 0xEC, 0x2B, 0x5C, 0x9D, 0x67, 0x76,
  32357. 0xBC, 0xD7, 0x9E, 0x5A, 0xC6, 0x4B, 0x79, 0x33,
  32358. 0xBD, 0xDE, 0xDE, 0xDD, 0xBB, 0xC7, 0x25, 0xBF,
  32359. 0xDB, 0xCC, 0xDE, 0x2F, 0xB3, 0x75, 0xAE, 0x2B,
  32360. 0xE3, 0x53, 0x7B, 0xDF, 0x89, 0xBF, 0x4C, 0x25,
  32361. 0xF8, 0x3A, 0x49, 0xD6, 0xA6, 0xA8, 0xD0, 0x76,
  32362. 0x1C, 0xF3, 0x9D, 0x62, 0x0C, 0x53, 0xED, 0x83,
  32363. 0x7D, 0x19, 0x82, 0x55, 0xCF, 0x5B, 0x91, 0x0A,
  32364. 0x6D, 0xB5, 0x78, 0x77, 0xDF, 0x92, 0xD8, 0xBB,
  32365. 0x6E, 0x9C, 0x52, 0x6B, 0x8C, 0x4E, 0xC9, 0x31,
  32366. 0x00, 0xDE, 0xE0, 0x50, 0x0A, 0x21, 0x0C, 0x98,
  32367. 0x45, 0x83, 0xE1, 0x53, 0x81, 0x60, 0xED, 0xAC,
  32368. 0x2C, 0x6F, 0x86, 0x6E, 0x7F, 0x5D, 0x99, 0xD7,
  32369. 0xB1, 0xB8, 0x15, 0x82, 0xF5, 0xD0, 0xEB, 0xBF,
  32370. 0x27, 0x86, 0xE3, 0xF5, 0x56, 0x01, 0x3B, 0xA9,
  32371. 0xB6, 0xF6, 0x56, 0xEB, 0x79, 0x88, 0x38, 0xEA,
  32372. 0x05, 0x79, 0x20, 0x1A, 0x95, 0xD5, 0x6B, 0xBC,
  32373. 0x3B, 0xCD, 0xB9, 0x51, 0x1A, 0xFB, 0xD4, 0xD8,
  32374. 0x12, 0x88, 0x89, 0x6F, 0x87, 0x10, 0x8C, 0x07,
  32375. 0x7F, 0x1A, 0x81, 0xA3, 0xBD, 0x29, 0x7B, 0xB1,
  32376. 0x24, 0xA8, 0x00, 0x86, 0x89, 0x02, 0x42, 0x99,
  32377. 0x5E, 0x03, 0xCF, 0x42, 0xA0, 0xC2, 0x1E, 0x27,
  32378. 0x2A, 0x9A, 0xFA, 0x1D, 0xC1, 0x03, 0x46, 0x3D,
  32379. 0x2A, 0xB4, 0x94, 0xF7, 0xD0, 0x17, 0x68, 0x6D,
  32380. 0x31, 0x89, 0x4D, 0xD2, 0xF6, 0xEB, 0xB0, 0xC3,
  32381. 0xCB, 0x62, 0x23, 0xEC, 0x79, 0xC6, 0x5D, 0x45,
  32382. 0xC1, 0xB0, 0xD4, 0xEF, 0x19, 0x61, 0xF1, 0x6D,
  32383. 0x65, 0x3F, 0xCF, 0x25, 0x97, 0x7B, 0x65, 0x1E,
  32384. 0xC5, 0x1A, 0x13, 0xAE, 0x8D, 0x4A, 0x34, 0x72,
  32385. 0xEE, 0x71, 0x96, 0x9A, 0x7A, 0x93, 0x6F, 0x5D,
  32386. 0xBB, 0xB9, 0x39, 0x6A, 0x46, 0xD9, 0x76, 0x42,
  32387. 0x35, 0x8C, 0xAF, 0x48, 0x94, 0xC9, 0xA6, 0xDF,
  32388. 0x84, 0xA5, 0x9C, 0x59, 0x62, 0xA6, 0x99, 0x0A,
  32389. 0x76, 0xF0, 0x61, 0x48, 0x90, 0x16, 0x9F, 0x00,
  32390. 0x18, 0x70, 0xD4, 0x9C, 0xF2, 0xE7, 0x50, 0x08,
  32391. 0xCC, 0x4A, 0x5D, 0x85, 0xE7, 0x2D, 0xE2, 0xD6,
  32392. 0xCF, 0x3F, 0xA7, 0x18, 0x52, 0x25, 0x35, 0x22,
  32393. 0xFE, 0x8B, 0x0E, 0x42, 0x3C, 0xB4, 0x17, 0xA3,
  32394. 0x8E, 0xB7, 0x8C, 0x87, 0x63, 0xC3, 0x72, 0x0C,
  32395. 0x04, 0xE6, 0x7F, 0xF8, 0x89, 0x79, 0xEB, 0xA0,
  32396. 0x9E, 0x34, 0x53, 0x8B, 0xB5, 0x23, 0xB9, 0x9B,
  32397. 0x8E, 0x34, 0x16, 0x74, 0x12, 0xF7, 0x7A, 0xEA,
  32398. 0x89, 0x4D, 0x83, 0xAC, 0xF9, 0x46, 0xFC, 0x05,
  32399. 0x4D, 0x0A, 0xF4, 0x72, 0x95, 0xE5, 0x1E, 0xD8,
  32400. 0x3F, 0x74, 0x86, 0x94, 0x0A, 0x4D, 0x41, 0xC0,
  32401. 0x4A, 0xD7, 0xEB, 0xEE, 0x61, 0x0B, 0xF1, 0xD0,
  32402. 0x3F, 0xA5, 0x40, 0x71, 0xD5, 0x1A, 0x15, 0x09,
  32403. 0xE4, 0xF4, 0x91, 0x63, 0xA2, 0x50, 0x81, 0xBE,
  32404. 0x87, 0x90, 0xD0, 0x87, 0xF5, 0xF4, 0xF0, 0x5C,
  32405. 0x88, 0x55, 0x0F, 0xCA, 0x9B, 0xF9, 0x9C, 0x9B,
  32406. 0xE5, 0x95, 0x3D, 0x51, 0xDD, 0x08, 0x45, 0xC9,
  32407. 0x3E, 0x41, 0xEE, 0xEF, 0x62, 0xE0, 0x79, 0x4B,
  32408. 0x29, 0x27, 0xC4, 0xF5, 0xED, 0x9B, 0xD3, 0xE3,
  32409. 0x4E, 0xA9, 0x20, 0x0A, 0x79, 0xDD, 0xEB, 0x4B,
  32410. 0x2D, 0x8F, 0x30, 0x5F, 0xE0, 0x5F, 0x82, 0x7C,
  32411. 0x7E, 0x2E, 0xD1, 0x86, 0x34, 0x1C, 0xB5, 0xD1,
  32412. 0x15, 0x2F, 0xC8, 0x01, 0x04, 0xE0, 0xE1, 0x36,
  32413. 0x83, 0xD9, 0x41, 0x29, 0x4C, 0x77, 0x84, 0x17,
  32414. 0x16, 0x4B, 0x68, 0x4A, 0x97, 0x6E, 0x56, 0xE7,
  32415. 0x8D, 0xA4, 0xD1, 0x7C, 0x3C, 0x73, 0x22, 0x93,
  32416. 0x14, 0x87, 0x0B, 0x85, 0xC4, 0x55, 0xC2, 0x3B,
  32417. 0x83, 0x0B, 0x9A, 0x28, 0xA3, 0xD8, 0xC0, 0xB5,
  32418. 0x66, 0x42, 0x6D, 0xC1, 0x69, 0xF3, 0x26, 0xAB,
  32419. 0xCE, 0x2E, 0xFF, 0xF3, 0x9E, 0x9B, 0x19, 0x9A,
  32420. 0xE5, 0xC1, 0x29, 0x2B, 0x6F, 0x2E, 0xF3, 0x7A,
  32421. 0xF1, 0xDE, 0xA9, 0x27, 0x2C, 0x8D, 0x54, 0x23,
  32422. 0xDF, 0x8A, 0x56, 0x32, 0xF9, 0x91, 0xE1, 0x4D,
  32423. 0xCA, 0x25, 0x14, 0x78, 0x8B, 0x62, 0xBE, 0x16,
  32424. 0x48, 0x28, 0xE9, 0xAC, 0xB8, 0x93, 0xDD, 0xA6,
  32425. 0x02, 0xA5, 0xE2, 0xFB, 0x9E, 0xFC, 0xBE, 0xFD,
  32426. 0x95, 0xAB, 0xFB, 0x82, 0xD2, 0xB0, 0x2D, 0x49,
  32427. 0xCC, 0x53, 0x08, 0x4A, 0x49, 0xAB, 0x1B, 0xEC,
  32428. 0x23, 0xE5, 0xB4, 0xC8, 0xE7, 0x14, 0xCB, 0x03,
  32429. 0x40, 0x5F, 0x1B, 0xCF, 0x7E, 0x11, 0xBB, 0x59,
  32430. 0x72, 0x9D, 0xDC, 0x0B, 0x7B, 0xEF, 0xB2, 0x91,
  32431. 0x27, 0x6D, 0xCE, 0xDA, 0xCA, 0xAD, 0x39, 0xA2,
  32432. 0xF0, 0x1C, 0x7D, 0xC9, 0x8B, 0x9E, 0x06, 0x5E,
  32433. 0xAF, 0xED, 0x1C, 0xC8, 0xCE, 0x3E, 0x84, 0x80,
  32434. 0x80, 0xA2, 0xFC, 0x5B, 0x98, 0xC9, 0xF6, 0xBF,
  32435. 0x50, 0x40, 0x27, 0x33, 0x42, 0xF0, 0x31, 0x2F,
  32436. 0x8B, 0x98, 0x44, 0x59, 0x4A, 0x50, 0x3D, 0xD3,
  32437. 0xE6, 0xAF, 0x1C, 0x9E, 0x35, 0xC1, 0x03, 0x2A,
  32438. 0x4A, 0x8A, 0x5E, 0x7B, 0xF3, 0x3A, 0x82, 0xF3,
  32439. 0x5E, 0x16, 0xED, 0xF8, 0xC6, 0x0C, 0x90, 0x02,
  32440. 0x1D, 0x8C, 0x0B, 0xA4, 0xC3, 0x86, 0x24, 0x5D,
  32441. 0xFE, 0xF0, 0x94, 0x48, 0x43, 0x1D, 0x8C, 0x00,
  32442. 0xD1, 0xE2, 0x6E, 0xE4, 0xD8, 0xC7, 0x7D, 0xAA,
  32443. 0x1A, 0x70, 0x5E, 0xD4, 0x79, 0x2A, 0xCB, 0x4E,
  32444. 0xA2, 0x7C, 0x15, 0x66, 0xFB, 0x56, 0x68, 0x3C,
  32445. 0x43, 0xBF, 0x67, 0x84, 0x2E, 0x67, 0x53, 0x4C,
  32446. 0xB3, 0xF9, 0x67, 0x7C, 0x8A, 0xB9, 0xD0, 0xEE,
  32447. 0xE7, 0x82, 0x7C, 0xDE, 0xFC, 0x22, 0x3A, 0xC9,
  32448. 0x48, 0xB8, 0x80, 0xB5, 0xF1, 0xCE, 0x95, 0x37,
  32449. 0x27, 0x29, 0x32, 0x00, 0x2C, 0x1A, 0x4D, 0xD2,
  32450. 0x18, 0xF5, 0x27, 0x16, 0x6E, 0xBF, 0xB2, 0xB2,
  32451. 0xFA, 0x2B, 0xF3, 0x72, 0x46, 0xEC, 0xDF, 0xDF,
  32452. 0xA7, 0x2B, 0x6D, 0xA1, 0x1C, 0x30, 0xD1, 0xC7,
  32453. 0xD2, 0x48, 0xAD, 0x64, 0x81, 0x8F, 0x69, 0x1D,
  32454. 0x59, 0xB7, 0x55, 0xDA, 0xF7, 0x1B, 0xED, 0x9A,
  32455. 0xB5, 0xFB, 0x52, 0xE0, 0x36, 0x22, 0xA9, 0x00,
  32456. 0xD6, 0x6B, 0x4C, 0x63, 0x84, 0x16, 0x9B, 0xDF,
  32457. 0x9E, 0xB6, 0x1C, 0x02, 0xDF, 0x45, 0xFB, 0x76,
  32458. 0xB1, 0xA2, 0x6F, 0x34, 0xE9, 0x38, 0xB1, 0x90,
  32459. 0x86, 0x17, 0x45, 0xC0, 0x21, 0xFA, 0x87, 0x62,
  32460. 0x00, 0xC7, 0xFC, 0x8E, 0x22, 0x2D, 0xDB, 0xFA,
  32461. 0xD8, 0xBE, 0x78, 0x1B, 0x18, 0x54, 0x24, 0xAA,
  32462. 0xAF, 0xC6, 0x58, 0x62, 0xDB, 0x13, 0x2B, 0xEC,
  32463. 0x6D, 0x18, 0x83, 0x7A, 0x1F, 0x58, 0xA8, 0x76,
  32464. 0xC9, 0x9E, 0x63, 0xF5, 0x14, 0x20, 0xB8, 0x3F,
  32465. 0x45, 0x96, 0x75, 0x61, 0x2F, 0x7A, 0xCF, 0x80,
  32466. 0xB4, 0xEB, 0x1D, 0xD0, 0x72, 0x1C, 0xAA, 0x1B,
  32467. 0x49, 0x70, 0xDA, 0x60, 0x86, 0x79, 0xC6, 0x38,
  32468. 0x3E, 0x81, 0x7F, 0xE1, 0x6B, 0x66, 0xB1, 0x91,
  32469. 0x81, 0xED, 0xFC, 0x39, 0x27, 0x0C, 0x7E, 0x91,
  32470. 0x7B, 0x1F, 0x10, 0xEB, 0x7A, 0x01, 0x19, 0x97,
  32471. 0xE9, 0x67, 0x85, 0x3B, 0x78, 0xE0, 0x0C, 0xFD,
  32472. 0x58, 0xD2, 0x24, 0xD9, 0x33, 0xCC, 0x5A, 0x99,
  32473. 0x55, 0x32, 0xDC, 0xD4, 0xE5, 0x32, 0xE4, 0x03,
  32474. 0x05, 0x15, 0xF4, 0xA0, 0x5B, 0x33, 0x1D, 0x57,
  32475. 0x5D, 0xDA, 0xC2, 0x9B, 0xAB, 0x06, 0x9F, 0x09,
  32476. 0xAF, 0x0D, 0x17, 0x33, 0x73, 0xDB, 0x1E, 0xC2,
  32477. 0xB6, 0x36, 0x6B, 0xB3, 0x71, 0x00, 0x8A, 0x23,
  32478. 0x86, 0xFD, 0x88, 0xBE, 0x77, 0xF5, 0xED, 0x5E,
  32479. 0x19, 0x8C, 0xBE, 0x88, 0xDF, 0x24, 0xBC, 0x6E,
  32480. 0x39, 0x3F, 0xEB, 0xC1, 0x0C, 0x47, 0x0A, 0x72,
  32481. 0xD4, 0x7C, 0x0F, 0x83, 0x46, 0x53, 0xC9, 0xAE,
  32482. 0x80, 0x0E, 0x89, 0x3C, 0x6B, 0xA6, 0x8E, 0xA2,
  32483. 0x8A, 0x83, 0x8F, 0xCB, 0xB6, 0x9C, 0x3E, 0x96,
  32484. 0x4A, 0x5F, 0xAF, 0xC2, 0x06, 0x7D, 0xD4, 0x06,
  32485. 0xB2, 0x57, 0xC9, 0x8D, 0xD3, 0x97, 0x9E, 0xC7,
  32486. 0xC7, 0xEC, 0xBE, 0x96, 0xA3, 0x3D, 0x85, 0x51,
  32487. 0x5D, 0xA2, 0xCB, 0x6A, 0xA5, 0xE1, 0xFF, 0xF2,
  32488. 0x04, 0xAF, 0x62, 0xDD, 0x41, 0x19, 0xA0, 0xE4,
  32489. 0x8C, 0x04, 0xA3, 0xF2, 0xB3, 0x86, 0x60, 0xF5,
  32490. 0x29, 0x64, 0xD8, 0xD4, 0xAE, 0xE1, 0x46, 0xA9,
  32491. 0xC5, 0x3C, 0x31, 0x90, 0x6D, 0xAD, 0x0F, 0xD9,
  32492. 0x0B, 0x5D, 0x83, 0xB3, 0xE3, 0x1B, 0x69, 0x0A,
  32493. 0x4C, 0x49, 0x35, 0x24, 0x99, 0x81, 0xBE, 0x1F,
  32494. 0x1A, 0x85, 0xEC, 0x6E, 0x0F, 0xEE, 0x4C, 0x88,
  32495. 0xF2, 0xD8, 0x9E, 0x29, 0x69, 0xAB, 0x8C, 0xBB,
  32496. 0xEB, 0x50, 0x19, 0x16, 0x55, 0x8D, 0x29, 0xEA,
  32497. 0x7C, 0x3E, 0xCF, 0x1C, 0x9E, 0xF1, 0xA0, 0x43,
  32498. 0x50, 0x63, 0x3B, 0x4C, 0xDA, 0x73, 0x7D, 0xFB,
  32499. 0x15, 0x1C, 0xB5, 0xE7, 0x36, 0x11, 0x73, 0xF3,
  32500. 0xAE, 0xDD, 0xDF, 0x52, 0x7D, 0x73, 0xF2, 0xF9,
  32501. 0xD5, 0xB6, 0x21, 0x3A, 0xA6, 0x8F, 0x88, 0x3E,
  32502. 0x9A, 0x26, 0x33, 0x78, 0x5E, 0xC6, 0xBE, 0x64,
  32503. 0x2A, 0x9F, 0xD0, 0xF2, 0x1A, 0x42, 0xF6, 0xB9,
  32504. 0xDA, 0xAB, 0xDC, 0xD1, 0xE6, 0xAD, 0xBE, 0xF6,
  32505. 0x48, 0x41, 0xB5, 0x96, 0x86, 0xEA, 0xE3, 0xEC,
  32506. 0x88, 0xEE, 0xF0, 0xA9, 0xCB, 0xC1, 0x2B, 0xC0,
  32507. 0x12, 0x62, 0x2D, 0xF2, 0xDD, 0x93, 0xA8, 0x62,
  32508. 0x29, 0x04, 0x4A, 0xF2, 0xF2, 0x60, 0xD2, 0x18,
  32509. 0x3F, 0x51, 0xE8, 0x33, 0xEE, 0x92, 0xD9, 0x8F,
  32510. 0x02, 0x51, 0xE3, 0xF8, 0x5F, 0xAB, 0x74, 0xCE,
  32511. 0x36, 0x7B, 0x8B, 0x7A, 0xA6, 0x3D, 0x3C, 0xF8,
  32512. 0xC8, 0xBF, 0x4D, 0x78, 0x35, 0x8B, 0xAE, 0x0A,
  32513. 0x02, 0x41, 0xE2, 0x10, 0xAC, 0x69, 0x35, 0x30,
  32514. 0x87, 0xCC, 0x73, 0x31, 0x35, 0x7E, 0xB4, 0x45,
  32515. 0x0F, 0x95, 0x09, 0xCF, 0xE5, 0x95, 0xF5, 0x40,
  32516. 0x32, 0xEE, 0x05, 0x77, 0x54, 0xA8, 0xED, 0xD7,
  32517. 0x46, 0xCB, 0x92, 0x82, 0xE7, 0x68, 0xDC, 0x6B,
  32518. 0x83, 0x0C, 0x5B, 0x4A, 0x21, 0x93, 0x43, 0xAD,
  32519. 0x12, 0x4E, 0xDB, 0x3B, 0xBC, 0x42, 0x50, 0x55,
  32520. 0x66, 0xA7, 0x03, 0x8C, 0x95, 0x9B, 0xC3, 0x55,
  32521. 0x85, 0xB6, 0x05, 0x5F, 0x19, 0x68, 0xDA, 0x24,
  32522. 0x3F, 0x77, 0x8F, 0x4E, 0x46, 0xDB, 0x46, 0x2A,
  32523. 0xBE, 0xB9, 0x3B, 0x81, 0x24, 0x3C, 0x31, 0xEB,
  32524. 0x59, 0x62, 0x2E, 0xDF, 0x81, 0xF0, 0x6C, 0xCC,
  32525. 0x61, 0xD2, 0xA6, 0xEA, 0x73, 0xE1, 0x09, 0xC3,
  32526. 0x87, 0x91, 0x5F, 0x27, 0x7B, 0xCF, 0x1F, 0xC1,
  32527. 0x11, 0x05, 0xBB, 0xA7, 0x02, 0x93, 0xC0, 0xFA,
  32528. 0xB5, 0xC0, 0x65, 0xF2, 0x3B, 0xAA, 0x19, 0x29,
  32529. 0x0A, 0x30, 0x2F, 0x08, 0x09, 0x11, 0x07, 0xA4,
  32530. 0xB1, 0xD5, 0x68, 0x85, 0x26, 0x22, 0x09, 0x83,
  32531. 0x83, 0x42, 0x77, 0x60, 0xEF, 0x8F, 0x29, 0x28,
  32532. 0x62, 0x5B, 0xDD, 0xA5, 0xF5, 0x14, 0xC5, 0xAD,
  32533. 0xE9, 0x59, 0x89, 0x1E, 0xF2, 0x95, 0x9F, 0x24,
  32534. 0x8A, 0x35, 0x32, 0xBF, 0x9D, 0x30, 0xE7, 0x14,
  32535. 0x05, 0x9E, 0xBD, 0xEC, 0x95, 0x87, 0x08, 0xF8,
  32536. 0xA8, 0x3C, 0x26, 0x8B, 0xEF, 0x26, 0x82, 0xD6,
  32537. 0x03, 0xCA, 0x88, 0x63, 0x47, 0xE1, 0x98, 0xFD,
  32538. 0x68, 0x23, 0x39, 0x99, 0xC7, 0x7D, 0x30, 0xD7,
  32539. 0x45, 0x5D, 0xE6, 0xBC, 0xFD, 0x01, 0x44, 0x27,
  32540. 0x70, 0x62, 0xB3, 0x04, 0xBE, 0xF0, 0xE3, 0x4C,
  32541. 0x5A, 0x9D, 0x8D, 0x78, 0x0D, 0x29, 0xEC, 0x23,
  32542. 0x21, 0xE0, 0x73, 0x40, 0x77, 0x1C, 0x46, 0x36,
  32543. 0x04, 0x83, 0xAD, 0xCA, 0xF1, 0x2D, 0x5B, 0x79,
  32544. 0xFD, 0xBF, 0xE2, 0x85, 0x6A, 0xCE, 0x88, 0x59,
  32545. 0xF6, 0xB1, 0x24, 0x14, 0xB3, 0xF7, 0xE8, 0xBB,
  32546. 0x58, 0x13, 0x49, 0x89, 0x60, 0xF3, 0x4F, 0xDC,
  32547. 0x64, 0xFC, 0x84, 0x85, 0x79, 0xCA, 0xF9, 0xDC,
  32548. 0xCF, 0x19, 0xB4, 0xFB, 0x82, 0x5E, 0xD5, 0x71,
  32549. 0x6D, 0xCC, 0xCD, 0x68, 0x72, 0xCB, 0xDE, 0x38,
  32550. 0x31, 0xD6, 0x73, 0x84, 0x94, 0x2C, 0xD8, 0xA9,
  32551. 0xEC, 0x4B, 0xBF, 0xEF, 0x57, 0x06, 0xB8, 0xF9,
  32552. 0xF0, 0x5F, 0xE1, 0xE8, 0xFE, 0x69, 0xD3, 0xEA,
  32553. 0x6A, 0x86, 0x21, 0xC2, 0x21, 0x44, 0x17, 0x7B,
  32554. 0x1C, 0x12, 0x59, 0xE1, 0xA7, 0x9D, 0xFD, 0xF8,
  32555. 0x97, 0x28, 0x88, 0x7B, 0xEF, 0x1A, 0x70, 0x48,
  32556. 0x25, 0x56, 0x83, 0x1B, 0x67, 0x24, 0x40, 0xE1,
  32557. 0x3F, 0xE3, 0xE3, 0xFC, 0x82, 0x04, 0xA0, 0x2E,
  32558. 0xA1, 0xEF, 0xF1, 0x9D, 0x95, 0x25, 0x38, 0x87,
  32559. 0x28, 0x5B, 0xFB, 0xEA, 0x16, 0xA0, 0xF2, 0x19,
  32560. 0xEF, 0xBC, 0xEC, 0x30, 0xA8, 0xAE, 0x86, 0x58,
  32561. 0x9A, 0x57, 0x03, 0x10, 0x3A, 0x8A, 0x39, 0x3F,
  32562. 0xA6, 0xF6, 0xB6, 0x57, 0x70, 0x4A, 0xC6, 0x77,
  32563. 0xC1, 0x4C, 0xD1, 0x0D, 0x3D, 0x62, 0xD1, 0x3F,
  32564. 0xBD, 0x37, 0x8C, 0x2D, 0xDA, 0x32, 0x5B, 0x61,
  32565. 0xB8, 0x59, 0x52, 0xD5, 0x12, 0x93, 0x87, 0x1E,
  32566. 0x1F, 0xCD, 0xC9, 0x48, 0xC7, 0x7B, 0xEA, 0xE9,
  32567. 0xA6, 0xF0, 0xE8, 0x7C, 0xE1, 0xA8, 0x05, 0x1C,
  32568. 0x8F, 0x80, 0x87, 0x68, 0x5C, 0x12, 0x62, 0x4B,
  32569. 0xDF, 0x58, 0x38, 0x0E, 0xD6, 0x6F, 0x55, 0xB4,
  32570. 0x3D, 0xDD, 0x6D, 0x36, 0x21, 0x73, 0xA5, 0xBD,
  32571. 0x38, 0x98, 0x59, 0xC1, 0x7D, 0x95, 0xEC, 0xE3,
  32572. 0xAB, 0x73, 0x26, 0x39, 0xFF, 0xE4, 0x51, 0xCD,
  32573. 0x10, 0x3E, 0xE4, 0x85, 0x4D, 0xB2, 0xF3, 0x96,
  32574. 0x14, 0xF6, 0x58, 0xBA, 0xA3, 0x84, 0xBC, 0x99,
  32575. 0x48, 0xD0, 0x71, 0x4E, 0xB4, 0x8A, 0x88, 0x71,
  32576. 0x43, 0xE7, 0xA1, 0xFA, 0x4B, 0x69, 0x0C, 0x22,
  32577. 0xB4, 0x92, 0xA7, 0x0C, 0x61, 0x2B, 0x59, 0xFF,
  32578. 0xD2, 0xD6, 0xB3, 0xB5, 0xE9, 0x9C, 0x20, 0x03,
  32579. 0xE2, 0xC3, 0x59, 0xB1, 0xE6, 0x2D, 0xCB, 0x62,
  32580. 0x0C, 0x7A, 0x24, 0x6A, 0x7B, 0x9B, 0x32, 0x46,
  32581. 0x13, 0x15, 0x56, 0xF2, 0xF3, 0xD5, 0x13, 0xA2,
  32582. 0x3C, 0x6A, 0x9F, 0xD2, 0x28, 0x0E, 0xD6, 0x86,
  32583. 0xD7, 0x67, 0xCC, 0xD0, 0x17, 0x54, 0xEB, 0x4C,
  32584. 0x99, 0x69, 0x2F, 0x2B, 0x38, 0x0C, 0x36, 0x08,
  32585. 0x13, 0x44, 0xC1, 0xD3, 0x5E, 0xE1, 0x94, 0x97,
  32586. 0x36, 0xB6, 0x97, 0x6F, 0x48, 0x52, 0xCF, 0xBE,
  32587. 0x64, 0xFA, 0xBC, 0xF1, 0x1B, 0x9A, 0xFB, 0x82,
  32588. 0x85, 0x76, 0xB4, 0xF9, 0x78, 0x7A, 0xA7, 0xD0,
  32589. 0x3E, 0x84, 0x59, 0x8A, 0x71, 0x43, 0xEF, 0x73,
  32590. 0x11, 0xFA, 0xF2, 0x97, 0x0E, 0x23, 0xED, 0x4C,
  32591. 0x17, 0x3F, 0x98, 0x5D, 0x64, 0x50, 0x16, 0x5A,
  32592. 0xE3, 0xE2, 0x41, 0xA1, 0x82, 0x34, 0xE7, 0x4F,
  32593. 0xF3, 0xDD, 0xB9, 0x21, 0xA5, 0x30, 0x0B, 0x1C,
  32594. 0x4F, 0xB6, 0xE4, 0x32, 0xE6, 0x98, 0xF5, 0x3F,
  32595. 0x66, 0xE3, 0x8C, 0x07, 0xBC, 0xD6, 0xE7, 0x76,
  32596. 0x05, 0xDF, 0x46, 0x24, 0xD5, 0x79, 0x07, 0x62,
  32597. 0x92, 0xDE, 0x1C, 0xE6, 0xFC, 0x6F, 0x00, 0x81,
  32598. 0xA3, 0x8B, 0xD9, 0x2D, 0x39, 0xB2, 0x4B, 0x73,
  32599. 0xBA, 0xC1, 0xC5, 0x2B, 0xD6, 0x8E, 0x91, 0x81,
  32600. 0xD3, 0xDC, 0xD0, 0xAC, 0x75, 0x34, 0xDB, 0x48,
  32601. 0x90, 0x1E, 0x59, 0x84, 0xF9, 0x90, 0x25, 0x57,
  32602. 0xBF, 0xA2, 0x31, 0xB2, 0xEA, 0x28, 0xC3, 0x18,
  32603. 0x32, 0x62, 0xA1, 0xB2, 0x22, 0x1F, 0x74, 0x26,
  32604. 0xEA, 0x88, 0xA5, 0x81, 0x60, 0x93, 0xA5, 0xCA,
  32605. 0xE2, 0xCD, 0x5D, 0x59, 0xA9, 0x39, 0x0F, 0xC9,
  32606. 0x3A, 0x29, 0x56, 0x94, 0x4B, 0x06, 0x4C, 0xF0,
  32607. 0x13, 0xBC, 0xDB, 0x67, 0xFB, 0x42, 0x3D, 0x13,
  32608. 0x28, 0xD2, 0xC6, 0xD7, 0xBA, 0x32, 0x90, 0x13,
  32609. 0xFA, 0x2D, 0x30, 0xEF, 0xD6, 0x9F, 0xDC, 0xA1,
  32610. 0xA9, 0x5E, 0xA6, 0xD0, 0x6C, 0x73, 0x63, 0x53,
  32611. 0x4B, 0x2F, 0x3F, 0x7D, 0xAA, 0xFA, 0x29, 0x6E,
  32612. 0xAA, 0x09, 0xB3, 0x66, 0x8E, 0x9C, 0xF8, 0x2D,
  32613. 0x9B, 0xA9, 0x59, 0xB3, 0x2F, 0x3C, 0xAD, 0x3C,
  32614. 0x10, 0xC6, 0xEA, 0x48, 0x61, 0x15, 0x54, 0x53,
  32615. 0x9C, 0x37, 0xDF, 0x6B, 0xCA, 0x33, 0x85, 0xEA,
  32616. 0xD3, 0xFC, 0xFF, 0x96, 0xD3, 0x72, 0xB4, 0x23,
  32617. 0x93, 0xB7, 0x3C, 0x8D, 0xAA, 0xAA, 0x31, 0x50,
  32618. 0x6E, 0xE0, 0x52, 0x7B, 0x7F, 0xB3, 0xE5, 0x93,
  32619. 0xDC, 0xCC, 0xA5, 0x7C, 0x8F, 0xBB, 0xD4, 0xA3,
  32620. 0xC7, 0xF8, 0xA5, 0x38, 0x99, 0x86, 0x91, 0x32,
  32621. 0xFB, 0xC3, 0xE4, 0x05, 0x06, 0x07, 0xBB, 0xFE,
  32622. 0x29, 0xC6, 0x75, 0xE3, 0x94, 0x5E, 0x74, 0xA3,
  32623. 0x1C, 0xD5, 0x31, 0xBA, 0x7A, 0xEB, 0x2E, 0x2F,
  32624. 0x0C, 0xD9, 0x90, 0xB8, 0xF9, 0x83, 0xA9, 0x0D,
  32625. 0xFE, 0xA0, 0x56, 0x8F, 0x06, 0x77, 0xEA, 0x95,
  32626. 0x63, 0xF7, 0xC4, 0x79, 0xDE, 0x96, 0x89, 0x40,
  32627. 0xCF, 0x24, 0x29, 0x92, 0x69, 0x28, 0x65, 0xCF,
  32628. 0xDA, 0x89, 0xFA, 0x07, 0x8B, 0xBE, 0xF4, 0x9C,
  32629. 0xE4, 0x57, 0x5B, 0xDF, 0xB3, 0x80, 0x36, 0x60,
  32630. 0x11, 0xC8, 0x43, 0x5F, 0x12, 0xB4, 0x2D, 0x9A,
  32631. 0xB9, 0x9A, 0xB6, 0xA3, 0x19, 0x12, 0xC4, 0x35,
  32632. 0x41, 0x49, 0xD7, 0x23, 0x10, 0x1D, 0x13, 0x65,
  32633. 0xA6, 0x5E, 0x7C, 0xC6, 0x8D, 0x82, 0xE3, 0x05,
  32634. 0x17, 0x77, 0x39, 0x02, 0xFB, 0x38, 0xDD, 0xA2,
  32635. 0xB3, 0x24, 0xE7, 0x20, 0x8E, 0x98, 0x7E, 0xD2,
  32636. 0x87, 0xD0, 0x92, 0xE7, 0x66, 0x2A, 0x43, 0x02,
  32637. 0x41, 0xBF, 0xCA, 0x55, 0x2D, 0x31, 0x41, 0x27,
  32638. 0xE3, 0x8C, 0x85, 0x97, 0xA8, 0x95, 0x19, 0xD4,
  32639. 0xF1, 0xE6, 0x2A, 0x79, 0x46, 0x5A, 0xD5, 0xF4,
  32640. 0xEA, 0xA3, 0xFA, 0x77, 0xCD, 0x98, 0x32, 0x6D,
  32641. 0x2F, 0x92, 0xCE, 0x98, 0x52, 0x05, 0x5C, 0xEC,
  32642. 0xCF, 0x62, 0xD6, 0x3C, 0xB9, 0xD7, 0xF1, 0x98,
  32643. 0xAE, 0x08, 0x5E, 0x4D, 0x45, 0xC8, 0xE4, 0x8F,
  32644. 0xCF, 0xFE, 0x59, 0x3A, 0xD6, 0x52, 0xD9, 0x15,
  32645. 0x41, 0x67, 0xBF, 0x3E, 0x61, 0x95, 0x81, 0x0A,
  32646. 0x44, 0x5A, 0xE1, 0x58, 0xF1, 0xF9, 0xA6, 0x79,
  32647. 0x33, 0x63, 0xAF, 0xC1, 0xF2, 0x2C, 0xA8, 0x82,
  32648. 0xFE, 0xED, 0x3A, 0x5F, 0x57, 0x27, 0xCA, 0x76,
  32649. 0x47, 0x7C, 0x5F, 0x23, 0xF0, 0xFC, 0x87, 0x00,
  32650. 0xCD, 0xC6, 0xA5, 0xBC, 0xB2, 0xB2, 0x0B, 0x4F,
  32651. 0x92, 0x66, 0x35, 0x1D, 0x30, 0x4A, 0x96, 0xA8,
  32652. 0x2B, 0xF5, 0xF3, 0x14, 0xAF, 0x68, 0x5C, 0x1C,
  32653. 0x70, 0x7C, 0x92, 0xE3, 0xE8, 0x47, 0xB7, 0x04,
  32654. 0x7D, 0x68, 0x9C, 0x70, 0xB2, 0x5E, 0x55, 0x01,
  32655. 0xCA, 0xEC, 0x99, 0x19, 0x62, 0x6F, 0x4A, 0x0F,
  32656. 0xC8, 0x15, 0x86, 0xAF, 0x1E, 0xC8, 0x88, 0x89,
  32657. 0xB4, 0x23, 0x38, 0x7D, 0x5D, 0x95, 0x48, 0x26,
  32658. 0x18, 0xA6, 0x50, 0xE8, 0x0B, 0x53, 0xB0, 0x7C,
  32659. 0xAC, 0xE3, 0x22, 0x89, 0x40, 0x60, 0x2E, 0x3D,
  32660. 0xB4, 0x74, 0x66, 0xCE, 0x9B, 0xCC, 0xB6, 0xE4,
  32661. 0xD8, 0xAA, 0x61, 0xC8, 0x91, 0x25, 0x83, 0xE8,
  32662. 0x10, 0xB3, 0xB2, 0xE7, 0xE9, 0xCB, 0x48, 0xBD,
  32663. 0x40, 0x3E, 0xCF, 0x08, 0xD2, 0x8C, 0x70, 0xAE,
  32664. 0x0B, 0x62, 0x08, 0x59, 0xC1, 0xF0, 0x9B, 0x61,
  32665. 0x13, 0x14, 0x04, 0xC3, 0xD5, 0xBF, 0xFC, 0xD8,
  32666. 0x60, 0xE0, 0xF4, 0x2A, 0xB2, 0x99, 0x00, 0x62,
  32667. 0x30, 0xB2, 0x87, 0x6D, 0x77, 0xDD, 0xA9, 0x1C,
  32668. 0x8C, 0x62, 0xBD, 0x93, 0xA8, 0x44, 0xE4, 0xB3,
  32669. 0x44, 0xE3, 0x25, 0x5E, 0xEA, 0x53, 0x1C, 0x6C,
  32670. 0x45, 0x8D, 0x04, 0xAB, 0xDB, 0x0F, 0xAE, 0xF2,
  32671. 0xD1, 0xC0, 0xB4, 0xC5, 0x5F, 0x57, 0x0A, 0x5A,
  32672. 0x51, 0x02, 0x3F, 0x4D, 0x4E, 0xFF, 0xF5, 0x9F,
  32673. 0x9A, 0xBE, 0x17, 0x92, 0x2F, 0xE7, 0x32, 0xCA,
  32674. 0x71, 0xBC, 0xD4, 0x34, 0xAD, 0x77, 0x10, 0xB8,
  32675. 0x4C, 0xD4, 0xAC, 0x9F, 0x25, 0x07, 0xA0, 0x68,
  32676. 0x26, 0x56, 0x2A, 0xD7, 0xF6, 0x47, 0x82, 0x6F,
  32677. 0x9D, 0xBB, 0xE4, 0xED, 0xD2, 0x3F, 0x12, 0x43,
  32678. 0x69, 0xDB, 0x85, 0x26, 0xFC, 0x2B, 0x4D, 0x52,
  32679. 0xF0, 0x74, 0x14, 0x15, 0xF9, 0x72, 0xBE, 0xF6,
  32680. 0xA9, 0x35, 0xBD, 0x81, 0x2A, 0x56, 0xC8, 0x22,
  32681. 0x1B, 0x7D, 0xEF, 0x0F, 0x51, 0x06, 0xBC, 0x01,
  32682. 0xE9, 0x13, 0xE3, 0xD4, 0x3D, 0xB8, 0x6C, 0x2B,
  32683. 0xB4, 0xC7, 0xE0, 0x76, 0x26, 0x63, 0xC6, 0xDE,
  32684. 0x78, 0x87, 0x21, 0xC2, 0xAA, 0x07, 0xF8, 0x95,
  32685. 0x48, 0x87, 0xE2, 0x14, 0x2F, 0x2E, 0x91, 0x4A,
  32686. 0x09, 0x9E, 0xFC, 0x0A, 0xEE, 0x13, 0x39, 0x21,
  32687. 0x0D, 0x3E, 0x53, 0xDA, 0x3E, 0xCF, 0x88, 0x62,
  32688. 0x4B, 0x11, 0x19, 0xBE, 0x34, 0x01, 0x0B, 0x88,
  32689. 0x6C, 0x80, 0xF5, 0x1D, 0x18, 0x50, 0x83, 0x8F,
  32690. 0x21, 0x50, 0xE7, 0x2B, 0x04, 0x2A, 0xF3, 0x28,
  32691. 0x99, 0xC0, 0xD3, 0xD7, 0xB0, 0x2A, 0x57, 0xF8,
  32692. 0xCF, 0x26, 0x3A, 0x36, 0x95, 0x62, 0xE4, 0xE9,
  32693. 0x45, 0xA3, 0x12, 0x82, 0xA5, 0x02, 0xA9, 0x5E,
  32694. 0xE9, 0xBB, 0x03, 0x16, 0xC6, 0x86, 0x10, 0x06,
  32695. 0xDA, 0xC1, 0x7F, 0x93, 0x6F, 0x54, 0xC4, 0xC7
  32696. };
  32697. #endif /* WOLFSSL_NO_ML_DSA_87 */
  32698. #else
  32699. #ifndef WOLFSSL_NO_ML_DSA_44
  32700. static const byte seed_44[] = {
  32701. 0xBA, 0xC0, 0x59, 0x52, 0x75, 0x5B, 0x26, 0x47,
  32702. 0x01, 0xCA, 0x7D, 0x80, 0x6D, 0xFA, 0x08, 0x35,
  32703. 0x10, 0x28, 0xF6, 0x7B, 0x0E, 0x83, 0xC4, 0x24,
  32704. 0x01, 0x6F, 0x66, 0xCC, 0x83, 0x87, 0xD4, 0x69
  32705. };
  32706. static const byte pk_44[] = {
  32707. 0x86, 0xF0, 0x0C, 0x20, 0xE0, 0xDA, 0xEE, 0x5E,
  32708. 0x1E, 0xDE, 0x71, 0x39, 0x49, 0x0C, 0xC8, 0xCF,
  32709. 0xEF, 0xC9, 0xAB, 0x62, 0x3B, 0x8D, 0xEF, 0x0B,
  32710. 0xD8, 0x03, 0x12, 0x5B, 0x4A, 0xB2, 0x83, 0x61,
  32711. 0xED, 0x7E, 0xA9, 0xED, 0x2D, 0xED, 0x5A, 0x71,
  32712. 0xDD, 0xAE, 0x4A, 0x06, 0xE0, 0x2A, 0x5A, 0xAF,
  32713. 0x99, 0x69, 0x89, 0xC6, 0xAF, 0xE3, 0x2A, 0xFE,
  32714. 0x3D, 0x6E, 0x0A, 0x46, 0x71, 0x48, 0xD7, 0x17,
  32715. 0x99, 0x20, 0x01, 0x78, 0xD5, 0x8B, 0x40, 0xCB,
  32716. 0x81, 0xA0, 0x33, 0x38, 0xAE, 0x2B, 0x83, 0x4A,
  32717. 0xFD, 0x5F, 0xE0, 0xB7, 0xEE, 0xA0, 0xC4, 0x3D,
  32718. 0xB6, 0xA4, 0xD5, 0x59, 0x4B, 0xDD, 0x87, 0x1A,
  32719. 0xFC, 0x03, 0x30, 0xA0, 0xB3, 0xAD, 0x75, 0x3C,
  32720. 0xD4, 0x47, 0x72, 0x59, 0xCE, 0xB7, 0x80, 0xFD,
  32721. 0x34, 0x35, 0x5E, 0x96, 0xC8, 0x42, 0xD9, 0xDD,
  32722. 0x6C, 0xF1, 0xAB, 0xEF, 0x48, 0xD1, 0xA8, 0x02,
  32723. 0x02, 0x0F, 0x5B, 0x71, 0x4D, 0x36, 0x1E, 0x0D,
  32724. 0xC2, 0x09, 0x46, 0x7B, 0xF9, 0xEA, 0x24, 0x8F,
  32725. 0x7C, 0xCF, 0xB8, 0x9C, 0xF7, 0x49, 0x15, 0x8E,
  32726. 0x16, 0x49, 0x7E, 0xC5, 0x54, 0xF5, 0x03, 0x1D,
  32727. 0x16, 0x12, 0x02, 0x72, 0x1B, 0x38, 0x2D, 0x58,
  32728. 0x53, 0x15, 0x5E, 0xB6, 0x72, 0xCC, 0xA1, 0x09,
  32729. 0xB0, 0x2F, 0x10, 0xFA, 0x21, 0x45, 0x46, 0x37,
  32730. 0xD4, 0xFA, 0x7F, 0xFB, 0xB0, 0xD9, 0x20, 0xE2,
  32731. 0xCB, 0x56, 0xB3, 0x1E, 0xDF, 0x82, 0x67, 0x25,
  32732. 0x09, 0xD1, 0x8F, 0xFF, 0xE0, 0x43, 0xBD, 0x37,
  32733. 0x2B, 0x73, 0x0E, 0x13, 0x08, 0xC9, 0x49, 0x88,
  32734. 0x69, 0x69, 0xD9, 0x8C, 0x86, 0xE4, 0x7E, 0x63,
  32735. 0x35, 0xC5, 0xE1, 0xD0, 0x14, 0x9A, 0x89, 0x27,
  32736. 0x28, 0x17, 0xB0, 0x5B, 0x7A, 0x8F, 0xDD, 0x72,
  32737. 0x8B, 0x0A, 0x0D, 0x49, 0x58, 0x59, 0x2F, 0x0D,
  32738. 0x8F, 0x3D, 0x16, 0xCE, 0x7B, 0x11, 0xC7, 0x06,
  32739. 0x5D, 0xD5, 0x6D, 0x7B, 0x96, 0xED, 0x1E, 0x1A,
  32740. 0xF4, 0x10, 0x85, 0xDA, 0xDE, 0x84, 0x2F, 0x2B,
  32741. 0xBA, 0xFB, 0xA2, 0x5F, 0x33, 0x7D, 0x7C, 0x18,
  32742. 0x6B, 0xDF, 0x43, 0x3C, 0xE9, 0xEB, 0xB4, 0xC5,
  32743. 0x8E, 0x52, 0xF5, 0x7E, 0x4C, 0x3E, 0x6A, 0x33,
  32744. 0x41, 0x4C, 0x14, 0x05, 0x8E, 0x2C, 0x19, 0x0E,
  32745. 0x86, 0x91, 0x66, 0xDE, 0xF6, 0x4B, 0x35, 0xC2,
  32746. 0xDF, 0x3D, 0x4C, 0x7B, 0xC5, 0x58, 0x5E, 0x86,
  32747. 0x89, 0x6A, 0xFC, 0x86, 0x48, 0x75, 0xD1, 0x18,
  32748. 0xD1, 0xCB, 0x41, 0xC0, 0xF6, 0xD8, 0x87, 0x79,
  32749. 0xD9, 0xA2, 0x56, 0x2E, 0x83, 0x26, 0x11, 0xC1,
  32750. 0x4B, 0x53, 0x37, 0x85, 0x62, 0xFF, 0x6A, 0x67,
  32751. 0xFD, 0x18, 0x79, 0xD7, 0x55, 0x9B, 0xF7, 0x64,
  32752. 0xA9, 0x21, 0xB6, 0x1B, 0xF6, 0x11, 0x85, 0xF8,
  32753. 0xC0, 0x68, 0xDE, 0x61, 0x0C, 0x61, 0x7E, 0x8E,
  32754. 0xED, 0x9E, 0x58, 0x84, 0x16, 0x1A, 0x28, 0xC5,
  32755. 0x41, 0x63, 0xB3, 0xF0, 0x82, 0xAA, 0xE8, 0x36,
  32756. 0x81, 0x5C, 0xD3, 0xB7, 0xFB, 0x92, 0xF4, 0x7A,
  32757. 0x1E, 0x85, 0xA2, 0xB7, 0x21, 0xD5, 0xFA, 0xC8,
  32758. 0xE8, 0x02, 0x43, 0x5B, 0x56, 0x42, 0x03, 0x17,
  32759. 0x67, 0xEE, 0x3E, 0x31, 0x23, 0x63, 0xC7, 0x33,
  32760. 0x95, 0xDE, 0x07, 0xF6, 0x11, 0x3A, 0x2C, 0x3F,
  32761. 0x7B, 0xBB, 0x2D, 0x5C, 0x23, 0xF9, 0x2F, 0x9C,
  32762. 0x51, 0x19, 0x9F, 0x35, 0xC3, 0x18, 0x9F, 0x83,
  32763. 0x6E, 0xA8, 0x03, 0xF1, 0x79, 0x1F, 0xB0, 0xC8,
  32764. 0x2F, 0xF4, 0x2E, 0x9A, 0x26, 0xF3, 0x44, 0x02,
  32765. 0x8F, 0x45, 0x8B, 0xB0, 0x25, 0x1D, 0xF2, 0xD4,
  32766. 0x55, 0xB7, 0x65, 0xEF, 0xDB, 0x3D, 0x8E, 0x92,
  32767. 0xC8, 0xA0, 0x63, 0x4C, 0x38, 0xA3, 0x54, 0xD3,
  32768. 0xC2, 0x5A, 0x2A, 0x6A, 0x15, 0x27, 0x2A, 0xE2,
  32769. 0xFC, 0x25, 0xB6, 0xC8, 0x68, 0xEB, 0xED, 0x2D,
  32770. 0x23, 0xE8, 0x6D, 0x5C, 0xDD, 0x3F, 0x18, 0xB4,
  32771. 0x6E, 0x79, 0x36, 0xC9, 0x1C, 0xB4, 0x92, 0x41,
  32772. 0xAD, 0x35, 0xD4, 0x15, 0xE4, 0x64, 0x1C, 0x51,
  32773. 0xCB, 0x0C, 0x41, 0xB7, 0xFD, 0xC1, 0x09, 0x3E,
  32774. 0xD2, 0x4D, 0x38, 0x88, 0x77, 0x1C, 0x71, 0x91,
  32775. 0x74, 0xD3, 0x28, 0xE0, 0xCE, 0x9A, 0x11, 0x8D,
  32776. 0xBF, 0x4D, 0x8D, 0xF0, 0x44, 0xF6, 0x79, 0xFC,
  32777. 0x4C, 0xAD, 0x17, 0x88, 0xC0, 0x8C, 0x0B, 0x7A,
  32778. 0x90, 0x01, 0x53, 0x6C, 0x6B, 0x44, 0xF6, 0xE5,
  32779. 0x2E, 0xEC, 0x44, 0x4F, 0xB8, 0x9B, 0x10, 0xBE,
  32780. 0xCF, 0x55, 0x55, 0x29, 0x83, 0xB8, 0xD0, 0x25,
  32781. 0x5B, 0xCE, 0x8F, 0xA5, 0xB7, 0x6C, 0xA7, 0x47,
  32782. 0x65, 0xA9, 0xE9, 0x9B, 0xA5, 0xBC, 0x28, 0x1D,
  32783. 0x9F, 0x1F, 0x5E, 0x97, 0x42, 0x10, 0x84, 0x92,
  32784. 0xFB, 0x38, 0x0B, 0x2E, 0xAC, 0x79, 0x0A, 0x7D,
  32785. 0x00, 0x2C, 0x35, 0xD0, 0x54, 0x0D, 0x28, 0xE7,
  32786. 0xAB, 0x06, 0x02, 0xDA, 0x89, 0xA3, 0x06, 0x8E,
  32787. 0x13, 0x9A, 0xA7, 0xCA, 0x48, 0x09, 0xB0, 0x48,
  32788. 0x37, 0x08, 0xA7, 0x7D, 0xDA, 0xEB, 0x58, 0x64,
  32789. 0x39, 0xB3, 0xF3, 0xB2, 0x4C, 0x00, 0x4B, 0xCB,
  32790. 0x94, 0x36, 0xD4, 0x7C, 0x73, 0x45, 0xC8, 0x93,
  32791. 0xE5, 0x2A, 0x11, 0xF0, 0xEF, 0x0C, 0xED, 0x5F,
  32792. 0x8B, 0x0C, 0x86, 0xAD, 0x3A, 0x01, 0x07, 0x1A,
  32793. 0xC0, 0x34, 0xE8, 0x74, 0x21, 0x27, 0x73, 0x56,
  32794. 0x93, 0x76, 0x5D, 0x80, 0x59, 0xB4, 0xA4, 0xDC,
  32795. 0x80, 0xE7, 0xCE, 0x70, 0x0E, 0x0F, 0xEC, 0x56,
  32796. 0x42, 0x6E, 0x9C, 0x76, 0x3D, 0xF6, 0xB4, 0x41,
  32797. 0xE2, 0x3E, 0xAC, 0x25, 0xE7, 0x86, 0xA7, 0xA7,
  32798. 0x0A, 0x0D, 0x5D, 0x04, 0x1F, 0x45, 0xD4, 0x5B,
  32799. 0x42, 0x38, 0x4C, 0x60, 0xE7, 0xB7, 0x0D, 0xC7,
  32800. 0x28, 0x4F, 0xA5, 0x4E, 0x0C, 0x1B, 0xC4, 0xDA,
  32801. 0x50, 0x1A, 0xA0, 0x93, 0xAE, 0x10, 0x9A, 0x1A,
  32802. 0xC8, 0xC6, 0x56, 0xFC, 0x0A, 0xEA, 0x89, 0x3A,
  32803. 0x28, 0x21, 0xE9, 0x52, 0x9D, 0xEB, 0x07, 0x68,
  32804. 0xC1, 0x57, 0x32, 0x25, 0x1F, 0x93, 0x5D, 0x35,
  32805. 0xB2, 0x4B, 0x58, 0x30, 0xAF, 0x51, 0xC6, 0x7D,
  32806. 0x47, 0xD1, 0xA2, 0xAD, 0xDE, 0x75, 0x48, 0x84,
  32807. 0x74, 0x19, 0x74, 0x18, 0xA0, 0x2C, 0xD8, 0xB2,
  32808. 0xFE, 0x44, 0x78, 0x95, 0x6A, 0xBF, 0x56, 0x4D,
  32809. 0x20, 0x79, 0xE7, 0xE2, 0xE3, 0x56, 0x69, 0xB3,
  32810. 0xFA, 0xE1, 0xEB, 0xE6, 0x11, 0xAC, 0x18, 0xB3,
  32811. 0x98, 0xC1, 0x04, 0x20, 0x96, 0x4B, 0xAD, 0xDE,
  32812. 0x5B, 0x18, 0xEB, 0x7B, 0xBC, 0x15, 0x11, 0x57,
  32813. 0x29, 0x10, 0xE5, 0x80, 0x78, 0x4A, 0xF0, 0x87,
  32814. 0xF6, 0xD1, 0x3C, 0x23, 0xC5, 0xF4, 0x2D, 0xD7,
  32815. 0xAB, 0xA4, 0xD7, 0xB8, 0x45, 0x8E, 0x04, 0x1B,
  32816. 0x78, 0x59, 0x9F, 0x81, 0xE6, 0x04, 0xDF, 0x70,
  32817. 0x2B, 0x14, 0x74, 0x16, 0x49, 0xDA, 0xF0, 0xE1,
  32818. 0xC8, 0x29, 0xCC, 0x87, 0x8C, 0x2F, 0xFB, 0x18,
  32819. 0x3B, 0x47, 0xFC, 0x79, 0x04, 0x84, 0xCB, 0x0A,
  32820. 0xD2, 0x64, 0xBF, 0x86, 0xEA, 0x01, 0xAC, 0xE0,
  32821. 0xBD, 0xEC, 0x3B, 0xE1, 0xA7, 0x6C, 0xDE, 0x1D,
  32822. 0x58, 0x76, 0xCC, 0x53, 0x9E, 0xF6, 0xC6, 0xD4,
  32823. 0x2C, 0x87, 0x92, 0xA2, 0x89, 0x27, 0x31, 0x33,
  32824. 0x01, 0xA5, 0xA2, 0xE8, 0x8F, 0x13, 0x19, 0x0F,
  32825. 0xFD, 0x73, 0xB9, 0x91, 0xBD, 0xB8, 0x80, 0x9A,
  32826. 0xA3, 0xB1, 0x21, 0x6C, 0x91, 0x13, 0x8A, 0xAE,
  32827. 0xC7, 0xCB, 0x67, 0x14, 0xD1, 0xC0, 0x28, 0x89,
  32828. 0x04, 0x8C, 0x9F, 0xDE, 0xA0, 0x9A, 0x99, 0xA8,
  32829. 0x61, 0xE6, 0x8F, 0x8E, 0x39, 0xEF, 0x6B, 0x5E,
  32830. 0x84, 0x5F, 0x5D, 0x24, 0x37, 0x73, 0x9D, 0x75,
  32831. 0xC4, 0xEF, 0xE2, 0xA1, 0xF2, 0xBC, 0x0D, 0xE1,
  32832. 0x0D, 0xEC, 0xFA, 0xEE, 0xC1, 0x63, 0xC8, 0x2E,
  32833. 0x7D, 0x85, 0x65, 0xC3, 0xF2, 0x0D, 0x8B, 0x73,
  32834. 0xF9, 0x3B, 0x0B, 0x3D, 0x49, 0x8B, 0xFB, 0x16,
  32835. 0x5B, 0x75, 0x48, 0x9B, 0x56, 0x0A, 0x83, 0x4C,
  32836. 0x0D, 0x13, 0xB2, 0xB4, 0x25, 0xC7, 0x2C, 0xCB,
  32837. 0xA7, 0x9E, 0xCA, 0x41, 0x44, 0x14, 0x9A, 0x03,
  32838. 0xD3, 0x01, 0x8C, 0xB0, 0xD5, 0xA9, 0x36, 0xA4,
  32839. 0x16, 0x21, 0x49, 0x0A, 0x99, 0xA1, 0x89, 0xA5,
  32840. 0x91, 0x10, 0xA2, 0x1B, 0x3F, 0x98, 0x1E, 0x1C,
  32841. 0x43, 0xAA, 0x9C, 0x16, 0x5A, 0xF0, 0x18, 0x64,
  32842. 0x0F, 0x6A, 0xE3, 0x97, 0x83, 0x31, 0x4E, 0x84,
  32843. 0xC9, 0xEA, 0xD8, 0x9F, 0xEA, 0x9E, 0xD6, 0xF2,
  32844. 0x0E, 0x15, 0xA5, 0x48, 0x15, 0x8B, 0x10, 0x1D,
  32845. 0x77, 0x78, 0x1B, 0x54, 0x03, 0xC1, 0x2C, 0xB1,
  32846. 0xC8, 0x22, 0x11, 0x9D, 0xB8, 0x82, 0x94, 0x26,
  32847. 0xA0, 0xED, 0x6C, 0xAD, 0xA8, 0x03, 0xC2, 0xED,
  32848. 0x02, 0x74, 0x3E, 0x54, 0xBD, 0x77, 0xA6, 0x0B,
  32849. 0x37, 0xFE, 0x04, 0xCD, 0x25, 0x10, 0x2D, 0x52,
  32850. 0xC2, 0xD4, 0x5B, 0x9B, 0xAE, 0xFE, 0x35, 0x73,
  32851. 0x16, 0x61, 0x84, 0x25, 0x1D, 0xBE, 0x95, 0x34,
  32852. 0xA4, 0xF6, 0xB9, 0xA4, 0xF9, 0xAA, 0x5D, 0x1E,
  32853. 0x49, 0xBB, 0x19, 0xD9, 0x64, 0xD7, 0x48, 0x1A,
  32854. 0x0A, 0x93, 0xC3, 0x69, 0x13, 0x12, 0x68, 0xBB,
  32855. 0x97, 0x97, 0xBD, 0x99, 0x69, 0xCE, 0xE6, 0xF5,
  32856. 0x84, 0x7B, 0xCC, 0xE4, 0x7D, 0xD3, 0xCD, 0x8A,
  32857. 0x7A, 0x4B, 0x98, 0xF4, 0x09, 0x9D, 0xEA, 0x5D,
  32858. 0x4E, 0x1F, 0xE1, 0x1E, 0x6C, 0x48, 0xD3, 0x5E,
  32859. 0x67, 0xD9, 0xFF, 0x64, 0x4D, 0xA7, 0x64, 0x7A,
  32860. 0x01, 0xB2, 0xE9, 0x63, 0x14, 0x10, 0xB7, 0x08,
  32861. 0x0C, 0xF9, 0x4D, 0x66, 0x48, 0x46, 0xE3, 0xC2,
  32862. 0x48, 0x6B, 0x47, 0xCE, 0x00, 0x98, 0x92, 0x83,
  32863. 0xF7, 0xE0, 0x1F, 0x96, 0xFA, 0x53, 0xD5, 0x49,
  32864. 0x1C, 0xC7, 0x89, 0xB4, 0xA5, 0x4B, 0x63, 0xBF,
  32865. 0xD2, 0x00, 0x79, 0xDD, 0xC1, 0x60, 0xAA, 0xF2,
  32866. 0x0F, 0x47, 0xB9, 0x4F, 0x8A, 0x66, 0x05, 0x3D,
  32867. 0x96, 0x36, 0x64, 0x48, 0x5F, 0x7E, 0x56, 0x2B,
  32868. 0xB3, 0x47, 0xE2, 0x76, 0x64, 0x21, 0x65, 0x34,
  32869. 0xFC, 0xDD, 0x2D, 0x4C, 0xE2, 0x99, 0x33, 0x04,
  32870. 0xE4, 0x26, 0x15, 0x37, 0x6C, 0x32, 0xB9, 0x17
  32871. };
  32872. static const byte sk_44[] = {
  32873. 0x86, 0xF0, 0x0C, 0x20, 0xE0, 0xDA, 0xEE, 0x5E,
  32874. 0x1E, 0xDE, 0x71, 0x39, 0x49, 0x0C, 0xC8, 0xCF,
  32875. 0xEF, 0xC9, 0xAB, 0x62, 0x3B, 0x8D, 0xEF, 0x0B,
  32876. 0xD8, 0x03, 0x12, 0x5B, 0x4A, 0xB2, 0x83, 0x61,
  32877. 0x73, 0x61, 0x49, 0x01, 0x0F, 0x94, 0x08, 0x30,
  32878. 0x26, 0x02, 0x12, 0x63, 0x64, 0x15, 0x7A, 0x4D,
  32879. 0xBA, 0xF5, 0x25, 0xA7, 0xAA, 0x0B, 0x7C, 0x3D,
  32880. 0xCE, 0x05, 0x91, 0x95, 0xEF, 0x17, 0x2F, 0xE2,
  32881. 0x5A, 0x03, 0x5E, 0x2E, 0x4D, 0xFA, 0xE7, 0x5F,
  32882. 0xCD, 0x61, 0x34, 0xFB, 0x3D, 0x3C, 0x5C, 0x60,
  32883. 0x1A, 0x6F, 0x09, 0xB5, 0x9D, 0xDD, 0x90, 0x53,
  32884. 0xF6, 0x89, 0x50, 0xC2, 0xE1, 0xED, 0x0A, 0x61,
  32885. 0x8F, 0xFA, 0xDC, 0x2D, 0xB2, 0x8B, 0xA1, 0x56,
  32886. 0xAC, 0x5E, 0x0E, 0xF1, 0x3B, 0x1E, 0x22, 0x9F,
  32887. 0xAA, 0x05, 0x96, 0xA3, 0x5E, 0x44, 0x86, 0xA8,
  32888. 0xBA, 0x15, 0xD1, 0x11, 0x7D, 0xAA, 0xD0, 0xAA,
  32889. 0x01, 0x27, 0x25, 0x04, 0x82, 0x89, 0xA4, 0x22,
  32890. 0x2E, 0xDB, 0x80, 0x45, 0xD2, 0x30, 0x45, 0x59,
  32891. 0x16, 0x64, 0xE2, 0x08, 0x86, 0x50, 0x00, 0x8E,
  32892. 0xCA, 0x08, 0x51, 0x5A, 0x06, 0x01, 0x54, 0x82,
  32893. 0x20, 0xC4, 0x92, 0x30, 0x02, 0x21, 0x4E, 0x0A,
  32894. 0x93, 0x89, 0x84, 0xB8, 0x70, 0x24, 0x40, 0x51,
  32895. 0x24, 0xB3, 0x44, 0xDB, 0x08, 0x40, 0x1B, 0x37,
  32896. 0x44, 0x21, 0x22, 0x8E, 0x8C, 0x16, 0x42, 0x10,
  32897. 0x22, 0x0E, 0xA1, 0xB2, 0x8D, 0x18, 0x49, 0x30,
  32898. 0xC1, 0x32, 0x69, 0x21, 0x03, 0x8E, 0x49, 0x44,
  32899. 0x08, 0xD3, 0x16, 0x89, 0x10, 0xA4, 0x25, 0x5C,
  32900. 0x22, 0x8A, 0xC0, 0xC8, 0x08, 0xC1, 0x04, 0x6A,
  32901. 0xD2, 0xA0, 0x50, 0x8A, 0x02, 0x52, 0x92, 0x16,
  32902. 0x44, 0x54, 0x30, 0x4A, 0x92, 0x32, 0x0C, 0x4C,
  32903. 0x44, 0x2D, 0x04, 0x15, 0x2A, 0x99, 0x24, 0x42,
  32904. 0x52, 0xA8, 0x30, 0x53, 0x24, 0x85, 0x9A, 0xB8,
  32905. 0x01, 0xE2, 0x08, 0x09, 0x23, 0x28, 0x08, 0xC4,
  32906. 0x98, 0x85, 0x0B, 0xB9, 0x40, 0x60, 0x26, 0x28,
  32907. 0x0A, 0x45, 0x12, 0x0C, 0x43, 0x84, 0x82, 0x16,
  32908. 0x89, 0xC4, 0x48, 0x28, 0x58, 0x18, 0x2A, 0x20,
  32909. 0x07, 0x02, 0xD3, 0x82, 0x45, 0x50, 0xB0, 0x50,
  32910. 0x64, 0x36, 0x91, 0x52, 0x02, 0x45, 0x5A, 0x42,
  32911. 0x26, 0x01, 0x28, 0x71, 0xD4, 0x86, 0x10, 0x19,
  32912. 0xC4, 0x68, 0xC4, 0x30, 0x66, 0xE0, 0x02, 0x49,
  32913. 0x18, 0x34, 0x05, 0x04, 0x02, 0x04, 0x90, 0x94,
  32914. 0x4C, 0x01, 0xA7, 0x80, 0x12, 0x97, 0x08, 0x19,
  32915. 0xC5, 0x41, 0x24, 0xC1, 0x61, 0x08, 0xB0, 0x0C,
  32916. 0x21, 0xC1, 0x49, 0x9B, 0x42, 0x51, 0x62, 0x18,
  32917. 0x22, 0x54, 0x06, 0x06, 0x93, 0x26, 0x70, 0x49,
  32918. 0x86, 0x91, 0x00, 0x28, 0x6C, 0x02, 0xC9, 0x60,
  32919. 0x13, 0xC3, 0x09, 0xCB, 0x14, 0x66, 0x09, 0x17,
  32920. 0x25, 0x1C, 0x16, 0x89, 0x01, 0xB6, 0x01, 0x60,
  32921. 0x86, 0x71, 0x58, 0x96, 0x04, 0x82, 0x38, 0x61,
  32922. 0x43, 0x40, 0x72, 0xCC, 0x46, 0x71, 0x81, 0x20,
  32923. 0x2C, 0x18, 0x20, 0x6E, 0x03, 0x91, 0x11, 0x9A,
  32924. 0x08, 0x89, 0x43, 0x06, 0x48, 0x64, 0x02, 0x6C,
  32925. 0x21, 0x33, 0x8D, 0x48, 0x16, 0x66, 0x9B, 0xA4,
  32926. 0x2D, 0x01, 0x10, 0x66, 0xDC, 0xB0, 0x25, 0x40,
  32927. 0xA0, 0x24, 0xA2, 0xB4, 0x44, 0xC8, 0x26, 0x61,
  32928. 0x0A, 0x10, 0x4E, 0xD0, 0x04, 0x11, 0x4A, 0x82,
  32929. 0x51, 0x03, 0x04, 0x6C, 0x18, 0x88, 0x6C, 0xE0,
  32930. 0x98, 0x41, 0x11, 0x29, 0x06, 0x62, 0x12, 0x8E,
  32931. 0xDA, 0x42, 0x91, 0x09, 0x48, 0x60, 0xD1, 0xB4,
  32932. 0x80, 0x10, 0x30, 0x30, 0x80, 0x38, 0x82, 0xD0,
  32933. 0x84, 0x0D, 0x08, 0x14, 0x92, 0x24, 0x41, 0x40,
  32934. 0x0C, 0x10, 0x89, 0xCC, 0x38, 0x8A, 0x13, 0xB6,
  32935. 0x89, 0x1A, 0xA7, 0x24, 0x5C, 0x10, 0x12, 0x1B,
  32936. 0x21, 0x50, 0x91, 0xB4, 0x29, 0x99, 0xB6, 0x51,
  32937. 0x04, 0xB1, 0x91, 0x59, 0xA6, 0x05, 0x19, 0x08,
  32938. 0x4A, 0x4A, 0x84, 0x6C, 0x1C, 0x49, 0x02, 0x44,
  32939. 0x20, 0x85, 0x14, 0xB1, 0x89, 0x09, 0x44, 0x2C,
  32940. 0x10, 0x02, 0x22, 0xE1, 0xB4, 0x25, 0x01, 0x21,
  32941. 0x71, 0x53, 0xC2, 0x85, 0x82, 0x88, 0x28, 0xC0,
  32942. 0x02, 0x52, 0x19, 0xC5, 0x51, 0x19, 0xA5, 0x09,
  32943. 0xC0, 0x82, 0x91, 0x21, 0x47, 0x0D, 0x1C, 0x30,
  32944. 0x69, 0xDC, 0xB8, 0x6C, 0x04, 0x41, 0x6A, 0x91,
  32945. 0x16, 0x40, 0xA0, 0xC8, 0x24, 0x1A, 0x10, 0x01,
  32946. 0x04, 0x39, 0x25, 0x80, 0x16, 0x02, 0x63, 0x36,
  32947. 0x71, 0x90, 0xB0, 0x8D, 0x44, 0x16, 0x8E, 0xDA,
  32948. 0x16, 0x2E, 0xCB, 0x44, 0x20, 0x54, 0x38, 0x06,
  32949. 0x54, 0xC4, 0x01, 0x51, 0x40, 0x86, 0x52, 0x44,
  32950. 0x0E, 0x82, 0x02, 0x32, 0x21, 0x38, 0x89, 0x19,
  32951. 0x04, 0x40, 0xD8, 0x12, 0x68, 0x21, 0x98, 0x11,
  32952. 0x03, 0x33, 0x8A, 0x18, 0x00, 0x45, 0xCB, 0x22,
  32953. 0x32, 0xC3, 0x04, 0x46, 0x09, 0x18, 0x51, 0x22,
  32954. 0x44, 0x89, 0x13, 0x16, 0x6E, 0xDA, 0x46, 0x45,
  32955. 0x09, 0x19, 0x41, 0x81, 0x10, 0x01, 0xDC, 0x18,
  32956. 0x8E, 0xC8, 0x44, 0x4C, 0x00, 0x17, 0x82, 0x9C,
  32957. 0xA6, 0x4D, 0xC8, 0x08, 0x10, 0x24, 0x42, 0x6D,
  32958. 0x91, 0x38, 0x89, 0x8C, 0x40, 0x6E, 0x00, 0x35,
  32959. 0x11, 0xD3, 0x24, 0x09, 0x1A, 0x01, 0x65, 0x88,
  32960. 0x48, 0x45, 0x09, 0x01, 0x71, 0x43, 0xB8, 0x80,
  32961. 0x11, 0x82, 0x2C, 0x84, 0xB8, 0x49, 0x58, 0x14,
  32962. 0x28, 0x92, 0x20, 0x32, 0x09, 0x12, 0x05, 0x20,
  32963. 0x81, 0x2D, 0x5B, 0x86, 0x11, 0x04, 0x90, 0x45,
  32964. 0x49, 0x80, 0x40, 0xD1, 0xC8, 0x24, 0x98, 0xC2,
  32965. 0x2C, 0x99, 0xA2, 0x30, 0x04, 0x98, 0x8C, 0x53,
  32966. 0x24, 0x02, 0x8A, 0x04, 0x01, 0x4C, 0x28, 0x71,
  32967. 0xC3, 0x86, 0x6C, 0x24, 0x49, 0x81, 0x04, 0x02,
  32968. 0x28, 0x62, 0x44, 0x32, 0x61, 0x20, 0x28, 0x01,
  32969. 0x04, 0x11, 0x0C, 0x09, 0x08, 0x90, 0x98, 0x84,
  32970. 0x63, 0xB2, 0x45, 0x63, 0x38, 0x2E, 0x04, 0xA4,
  32971. 0x0C, 0x18, 0x05, 0x4E, 0xCC, 0x86, 0x90, 0x43,
  32972. 0x40, 0x91, 0x54, 0x02, 0x21, 0x43, 0x28, 0x42,
  32973. 0x23, 0x94, 0x29, 0xC8, 0xA6, 0x91, 0x02, 0x09,
  32974. 0x80, 0xE3, 0x82, 0x00, 0xC1, 0x34, 0x08, 0xD1,
  32975. 0x34, 0x84, 0x12, 0x45, 0x8C, 0x02, 0xC6, 0x81,
  32976. 0x41, 0xC6, 0x6C, 0x1B, 0x12, 0x24, 0x04, 0x08,
  32977. 0x0D, 0x02, 0x00, 0x0C, 0x9C, 0xA2, 0x05, 0x49,
  32978. 0x34, 0x65, 0x00, 0x06, 0x89, 0x88, 0x34, 0x00,
  32979. 0xD8, 0x82, 0x29, 0x92, 0x12, 0x91, 0xE3, 0x36,
  32980. 0x86, 0xD1, 0x80, 0x71, 0x98, 0xB0, 0x50, 0x48,
  32981. 0xC6, 0x11, 0x14, 0x80, 0x0D, 0xA0, 0x12, 0x4D,
  32982. 0x9B, 0xB2, 0x40, 0x21, 0x41, 0x50, 0x4B, 0x36,
  32983. 0x05, 0x52, 0x10, 0x26, 0x19, 0xB2, 0x60, 0x92,
  32984. 0xA2, 0x24, 0xCB, 0x08, 0x00, 0x14, 0x22, 0x49,
  32985. 0x5A, 0xD0, 0x55, 0xBD, 0x2B, 0x45, 0xE4, 0x31,
  32986. 0x41, 0xA8, 0xC3, 0xA3, 0xAD, 0xBD, 0xB6, 0x37,
  32987. 0x92, 0x06, 0x95, 0x6B, 0x3D, 0xD8, 0xE5, 0x33,
  32988. 0x71, 0xB6, 0x62, 0xB7, 0x67, 0x6C, 0x77, 0x84,
  32989. 0x63, 0x2F, 0x41, 0x1D, 0xBA, 0x51, 0x27, 0xE1,
  32990. 0x24, 0x5D, 0xC2, 0x38, 0x71, 0x65, 0x9E, 0x8E,
  32991. 0xE4, 0xEB, 0xBB, 0x1D, 0x89, 0xEB, 0x18, 0xCA,
  32992. 0x0C, 0xA6, 0x86, 0xA3, 0x4D, 0x7C, 0x7A, 0x02,
  32993. 0xAC, 0xDD, 0x34, 0xCE, 0x05, 0x3B, 0x1B, 0x49,
  32994. 0xF4, 0x6D, 0x12, 0x33, 0xBC, 0x52, 0x70, 0x59,
  32995. 0xDF, 0xBC, 0x5D, 0x49, 0x42, 0x6A, 0xED, 0xC7,
  32996. 0xF1, 0x8C, 0xF5, 0x6D, 0x1F, 0xBC, 0xE4, 0xBD,
  32997. 0x45, 0x5D, 0x59, 0xF8, 0xCE, 0x9A, 0x39, 0xB5,
  32998. 0x96, 0x32, 0xFD, 0x93, 0x65, 0x8E, 0x92, 0xF1,
  32999. 0x8F, 0xB0, 0x99, 0xF3, 0x80, 0x0F, 0x66, 0x14,
  33000. 0xFE, 0xEB, 0x23, 0x17, 0x2D, 0x4C, 0x8F, 0x41,
  33001. 0x9A, 0x9B, 0xD1, 0x5B, 0x5B, 0xC0, 0x3D, 0xA6,
  33002. 0x0E, 0xF3, 0xE0, 0xA1, 0x04, 0xDC, 0x24, 0x18,
  33003. 0x9D, 0x90, 0xC6, 0x89, 0x5A, 0x7F, 0x10, 0x1E,
  33004. 0x4B, 0x21, 0xEC, 0x91, 0xD8, 0x5D, 0x65, 0xDB,
  33005. 0xCF, 0x90, 0x62, 0x85, 0xE9, 0x58, 0xA3, 0x47,
  33006. 0x92, 0x1C, 0xD0, 0x0C, 0xA3, 0xF3, 0x3E, 0x36,
  33007. 0xDB, 0x24, 0xA6, 0x98, 0xAB, 0xA7, 0x89, 0x2B,
  33008. 0x71, 0x6C, 0x4D, 0x00, 0xB0, 0xD5, 0xA0, 0xCA,
  33009. 0x1A, 0x76, 0x8E, 0x80, 0xB7, 0xAE, 0x83, 0x89,
  33010. 0x50, 0xF8, 0xA7, 0x52, 0x8B, 0x94, 0xD2, 0x2B,
  33011. 0x9F, 0x49, 0x92, 0x3D, 0x54, 0x0D, 0xB8, 0xD1,
  33012. 0x19, 0x49, 0xAC, 0x91, 0xAF, 0xDB, 0xE9, 0x24,
  33013. 0x4D, 0xD8, 0xE1, 0xD5, 0x16, 0x0E, 0xB1, 0x39,
  33014. 0x40, 0x7D, 0x5F, 0xF5, 0x92, 0xB4, 0xAF, 0xC3,
  33015. 0x76, 0x2B, 0xDB, 0x7D, 0x52, 0x97, 0x62, 0x9F,
  33016. 0xCF, 0x32, 0x19, 0x5F, 0xE6, 0x32, 0xFB, 0x8E,
  33017. 0x39, 0x24, 0xB4, 0xEB, 0xE9, 0x17, 0x9E, 0x47,
  33018. 0x69, 0x4D, 0x92, 0x82, 0x96, 0x88, 0x38, 0x11,
  33019. 0xCE, 0xD6, 0xBF, 0x18, 0xE3, 0x51, 0x40, 0x81,
  33020. 0x11, 0xA0, 0x74, 0xDA, 0x0D, 0x5E, 0xEC, 0xD8,
  33021. 0x5D, 0x33, 0x22, 0x1E, 0xB9, 0x5D, 0xBF, 0x79,
  33022. 0xB0, 0xA1, 0xEF, 0xD1, 0x2D, 0xA0, 0x5F, 0xA1,
  33023. 0xC7, 0x6E, 0xD5, 0x08, 0xB8, 0xD0, 0xC1, 0x95,
  33024. 0x51, 0x9B, 0x07, 0xC3, 0x4A, 0x0A, 0xB5, 0xA1,
  33025. 0x28, 0xFE, 0x95, 0x95, 0x0A, 0xCF, 0x83, 0xA8,
  33026. 0xEB, 0x8F, 0xFB, 0x18, 0xD5, 0xBD, 0x69, 0x50,
  33027. 0xF1, 0xDF, 0x06, 0xFA, 0x9A, 0x65, 0x47, 0xBB,
  33028. 0x56, 0xE9, 0xCB, 0x8F, 0x69, 0x5F, 0xE0, 0xAD,
  33029. 0x19, 0x3A, 0x70, 0xE5, 0x66, 0x42, 0xD7, 0x1C,
  33030. 0x0C, 0xB4, 0x03, 0x89, 0x7D, 0x47, 0x4D, 0x29,
  33031. 0x67, 0x8C, 0x41, 0x73, 0xAB, 0x7D, 0xFD, 0x69,
  33032. 0x15, 0xAD, 0xE3, 0xB7, 0xF8, 0x98, 0x3B, 0xCA,
  33033. 0x8F, 0x27, 0x37, 0x7B, 0x72, 0x2C, 0x5F, 0x23,
  33034. 0x73, 0x15, 0xE2, 0xB6, 0xBD, 0xDE, 0x84, 0xF8,
  33035. 0x7E, 0x22, 0xB9, 0xFD, 0xD3, 0x4D, 0x62, 0x80,
  33036. 0xBA, 0xC5, 0x57, 0x29, 0x30, 0x1B, 0x06, 0x4D,
  33037. 0x20, 0xB1, 0x53, 0x86, 0xCB, 0x6A, 0x4A, 0xE3,
  33038. 0xC1, 0xA9, 0x88, 0xCF, 0xEB, 0x15, 0x2F, 0xA8,
  33039. 0xA8, 0x6F, 0xFC, 0x2A, 0xA8, 0x0E, 0xD9, 0xFA,
  33040. 0xEA, 0xD7, 0x3B, 0xCE, 0xF8, 0x5B, 0xD8, 0x92,
  33041. 0x22, 0x6A, 0x1A, 0x8E, 0x5E, 0x91, 0x37, 0x2C,
  33042. 0x21, 0x05, 0xC4, 0xAC, 0xF7, 0x62, 0x83, 0xBA,
  33043. 0x55, 0xD5, 0x2C, 0xCE, 0xA1, 0x19, 0x93, 0x0E,
  33044. 0xDE, 0xB6, 0xB8, 0x78, 0x0F, 0xBF, 0x4C, 0xA4,
  33045. 0x66, 0xAD, 0x97, 0x2F, 0xEE, 0x34, 0xE9, 0xA2,
  33046. 0xB6, 0x1D, 0x3C, 0x60, 0xFB, 0xB8, 0x7F, 0xF8,
  33047. 0xFD, 0x34, 0x8C, 0xC5, 0xC7, 0x38, 0x72, 0x74,
  33048. 0x19, 0xA9, 0xCF, 0x54, 0x49, 0x5B, 0xBA, 0x70,
  33049. 0x12, 0xC1, 0x61, 0xDC, 0x32, 0x61, 0x49, 0x66,
  33050. 0xF3, 0x57, 0xAA, 0x0F, 0xE6, 0x44, 0x9E, 0x8A,
  33051. 0x19, 0x9C, 0x6B, 0x63, 0x2C, 0x14, 0x1E, 0xDD,
  33052. 0x00, 0x27, 0xE3, 0x95, 0xE3, 0xE7, 0xD9, 0xFF,
  33053. 0x30, 0x2D, 0x14, 0x19, 0x4F, 0x49, 0x20, 0x0B,
  33054. 0x58, 0x2A, 0x23, 0x1C, 0xE2, 0xAD, 0x6B, 0x9C,
  33055. 0x7B, 0xB6, 0x20, 0x63, 0x08, 0x24, 0x55, 0x04,
  33056. 0x58, 0x1F, 0x0E, 0xBE, 0x2A, 0x6F, 0x79, 0x90,
  33057. 0x9E, 0x15, 0x8F, 0x4B, 0xDB, 0xE2, 0xBE, 0xBC,
  33058. 0x28, 0xB1, 0xC8, 0xFE, 0x00, 0x6D, 0x71, 0xCC,
  33059. 0x91, 0x6A, 0xCC, 0xF8, 0x12, 0x8B, 0xEC, 0xF3,
  33060. 0x46, 0x53, 0xB1, 0x7F, 0xB3, 0x79, 0xF0, 0xC7,
  33061. 0xD7, 0xA5, 0xCF, 0x2C, 0xC3, 0x09, 0x66, 0x82,
  33062. 0x53, 0x43, 0xFD, 0xAC, 0xDE, 0xD5, 0x85, 0xB3,
  33063. 0x79, 0x74, 0x55, 0xE8, 0xF6, 0xE5, 0xFB, 0xF0,
  33064. 0x63, 0x0C, 0x36, 0x63, 0x65, 0x10, 0x43, 0xC9,
  33065. 0x60, 0x99, 0xD6, 0x0C, 0xB9, 0x66, 0x1C, 0xA9,
  33066. 0x97, 0x4D, 0xDB, 0xA8, 0x13, 0x9E, 0xAE, 0xCA,
  33067. 0x7A, 0x5F, 0xE3, 0x24, 0xA0, 0xEE, 0x8A, 0x9D,
  33068. 0x7F, 0x03, 0x53, 0x21, 0x6B, 0xAF, 0x3D, 0xF9,
  33069. 0x38, 0xF3, 0x7A, 0x1D, 0xDA, 0xE2, 0xEF, 0xBA,
  33070. 0x86, 0x21, 0x85, 0x1F, 0x36, 0x08, 0x0B, 0xDA,
  33071. 0x37, 0x5A, 0x0A, 0xD7, 0x55, 0x41, 0xD5, 0x84,
  33072. 0x1B, 0x36, 0xA2, 0x50, 0x65, 0xD7, 0xF3, 0xA3,
  33073. 0xEB, 0xE1, 0xDE, 0x0F, 0x85, 0xAA, 0xF6, 0x2F,
  33074. 0xAB, 0xBB, 0xC8, 0xF1, 0x2A, 0xD1, 0x0A, 0x9B,
  33075. 0xE4, 0x7B, 0xBC, 0x4D, 0x42, 0xD8, 0xA3, 0x4C,
  33076. 0x07, 0x6A, 0x60, 0x3E, 0xE2, 0xDA, 0xE7, 0x00,
  33077. 0xDF, 0x27, 0x94, 0xEF, 0x90, 0x99, 0x88, 0x2C,
  33078. 0xCF, 0xAA, 0xE1, 0x71, 0x2D, 0xFD, 0x00, 0x9C,
  33079. 0x55, 0xBF, 0xC4, 0x7A, 0x55, 0xE9, 0xE0, 0xB4,
  33080. 0x7F, 0x3D, 0xE9, 0xB0, 0x01, 0xA7, 0x27, 0x23,
  33081. 0x27, 0x58, 0x31, 0x0E, 0x8E, 0x80, 0xD8, 0xEB,
  33082. 0x64, 0xA0, 0xC3, 0xC9, 0xEA, 0x69, 0x9C, 0x74,
  33083. 0x5E, 0xAF, 0xD5, 0xEF, 0x5C, 0x4E, 0x40, 0x71,
  33084. 0xD6, 0x57, 0x77, 0xE2, 0xAF, 0x0E, 0x1D, 0xB8,
  33085. 0x5A, 0x91, 0x20, 0x4C, 0x33, 0x4D, 0xD8, 0x4F,
  33086. 0x98, 0xE0, 0x86, 0x1D, 0x02, 0xA0, 0xDA, 0x06,
  33087. 0x17, 0xC4, 0x5D, 0x2E, 0x49, 0x31, 0xE6, 0xE4,
  33088. 0xDC, 0x18, 0x23, 0x26, 0xF3, 0x61, 0xF5, 0x8D,
  33089. 0x26, 0x2C, 0x18, 0x4C, 0xDF, 0x71, 0x90, 0x24,
  33090. 0x96, 0xD3, 0xD4, 0x1A, 0x6F, 0x08, 0xAB, 0x29,
  33091. 0x7D, 0xFF, 0x4E, 0x27, 0x6D, 0x39, 0x83, 0x17,
  33092. 0x90, 0xA4, 0x07, 0x8A, 0xDE, 0x79, 0x53, 0xF6,
  33093. 0x99, 0x2E, 0xA6, 0x39, 0x47, 0xC3, 0xBE, 0x12,
  33094. 0xC7, 0xA5, 0x7E, 0xA2, 0x19, 0x57, 0x04, 0x45,
  33095. 0xBE, 0x44, 0x62, 0x92, 0xCA, 0x56, 0xE1, 0xF0,
  33096. 0x45, 0x3B, 0xA4, 0xF8, 0xF5, 0xCD, 0xC7, 0xD2,
  33097. 0xB2, 0x46, 0x57, 0x51, 0x0B, 0x06, 0xDA, 0x54,
  33098. 0x03, 0x9E, 0x52, 0xA2, 0x78, 0x69, 0x25, 0x2E,
  33099. 0x75, 0x83, 0x25, 0x3F, 0xA3, 0x62, 0x27, 0xB9,
  33100. 0xA6, 0x59, 0x7A, 0xB1, 0xB6, 0xE9, 0xC1, 0xDD,
  33101. 0x2F, 0x22, 0x2D, 0x3B, 0xA3, 0x22, 0xD6, 0x11,
  33102. 0x7B, 0x08, 0x27, 0x92, 0x83, 0x7A, 0x5D, 0x0D,
  33103. 0x6B, 0x9D, 0x5B, 0xEB, 0xE9, 0xC0, 0x88, 0xDE,
  33104. 0x44, 0x55, 0xBA, 0x69, 0xC1, 0x7A, 0x4D, 0xE6,
  33105. 0x35, 0x67, 0x6F, 0x99, 0x9B, 0x07, 0xD8, 0x04,
  33106. 0xAA, 0xEA, 0x7D, 0xFF, 0x8E, 0xB8, 0xAA, 0x4C,
  33107. 0x79, 0xE2, 0x88, 0xA8, 0x1D, 0xE8, 0xA6, 0x77,
  33108. 0xCA, 0x06, 0xC0, 0xDF, 0x0E, 0x2B, 0xCB, 0xFF,
  33109. 0x9F, 0x64, 0x67, 0x11, 0xF1, 0xB9, 0x38, 0x83,
  33110. 0x19, 0x05, 0x30, 0x9B, 0x01, 0x11, 0x55, 0x03,
  33111. 0xAD, 0x44, 0x7D, 0x3C, 0x07, 0xEF, 0x88, 0x19,
  33112. 0x92, 0xC0, 0xFE, 0xE1, 0xAB, 0xDB, 0x24, 0x18,
  33113. 0x17, 0xD0, 0x03, 0x5C, 0x91, 0xD4, 0xA6, 0x2A,
  33114. 0xF1, 0xE9, 0x72, 0x62, 0x58, 0x22, 0x7D, 0x55,
  33115. 0x15, 0xE2, 0xA1, 0x70, 0x14, 0x5E, 0x34, 0xB9,
  33116. 0x5A, 0xB7, 0x5D, 0x3F, 0xB8, 0xB5, 0x45, 0x44,
  33117. 0xD2, 0x50, 0xD1, 0xC6, 0x7E, 0xE7, 0x3D, 0xF4,
  33118. 0xD3, 0xEC, 0xFB, 0x97, 0x32, 0x11, 0x72, 0x51,
  33119. 0xB7, 0x4A, 0xC8, 0x38, 0x96, 0xFC, 0x6F, 0x69,
  33120. 0xC2, 0xD5, 0xD3, 0x28, 0xE9, 0x63, 0x14, 0x14,
  33121. 0xFE, 0xB1, 0xA4, 0x02, 0x80, 0x65, 0x73, 0xD3,
  33122. 0x57, 0x07, 0x95, 0x21, 0x40, 0x00, 0x77, 0xA7,
  33123. 0x6D, 0x44, 0x2B, 0x0D, 0x77, 0x07, 0x92, 0x64,
  33124. 0xD4, 0x3A, 0xE2, 0x7F, 0xF2, 0x1C, 0x14, 0x08,
  33125. 0x60, 0x74, 0x8F, 0xFC, 0x0B, 0xE8, 0xEC, 0xA9,
  33126. 0xB7, 0x97, 0xA7, 0x85, 0x8A, 0xEF, 0xD7, 0x7E,
  33127. 0xD5, 0x15, 0xF7, 0x45, 0x8D, 0x9C, 0xBF, 0x23,
  33128. 0xEB, 0x8C, 0x4D, 0xD2, 0x28, 0x7E, 0x0A, 0x61,
  33129. 0x2E, 0xBA, 0xBE, 0x89, 0x1D, 0x64, 0x45, 0x22,
  33130. 0x70, 0x9D, 0x48, 0xEB, 0x2F, 0x96, 0xF1, 0xA7,
  33131. 0xDE, 0xD3, 0x28, 0x4C, 0xC9, 0xFB, 0xF2, 0x9C,
  33132. 0x5B, 0xFC, 0xBE, 0xBE, 0xF4, 0x38, 0xC9, 0x43,
  33133. 0xC3, 0x66, 0x53, 0xA9, 0x06, 0xE5, 0x71, 0x16,
  33134. 0xA4, 0xBB, 0x3B, 0x50, 0x53, 0xCF, 0xF4, 0x1F,
  33135. 0xD6, 0x00, 0x07, 0x46, 0xFB, 0x97, 0x0B, 0xF9,
  33136. 0x3D, 0xF4, 0xC6, 0x60, 0xD0, 0x37, 0x70, 0xC0,
  33137. 0x2D, 0xD1, 0x9F, 0xA5, 0x78, 0xF3, 0x1F, 0x03,
  33138. 0x81, 0xB1, 0x93, 0xBA, 0xE5, 0x82, 0xE6, 0xD1,
  33139. 0x66, 0x93, 0x83, 0x5B, 0xB9, 0xAD, 0xD9, 0x01,
  33140. 0xA5, 0xB6, 0x5C, 0x69, 0x82, 0xD7, 0x2F, 0x35,
  33141. 0x35, 0x98, 0xEE, 0xE9, 0xA0, 0x74, 0xC1, 0x91,
  33142. 0x44, 0x0A, 0x04, 0xCD, 0x97, 0xBE, 0x6B, 0x60,
  33143. 0x90, 0x9A, 0x48, 0x7B, 0x83, 0xA2, 0x28, 0x97,
  33144. 0xB5, 0xBA, 0xB1, 0x4D, 0x35, 0x8B, 0x34, 0x0A,
  33145. 0xA1, 0xCB, 0xA5, 0xC2, 0xA4, 0x6A, 0x36, 0xB3,
  33146. 0x12, 0x46, 0x59, 0xDB, 0x63, 0xE5, 0xF9, 0xF1,
  33147. 0x7F, 0xAD, 0x42, 0xF4, 0x24, 0xF0, 0x02, 0x3D,
  33148. 0x1E, 0x6C, 0xD5, 0xB3, 0x06, 0x8F, 0x1F, 0x59,
  33149. 0x79, 0xCC, 0xF9, 0x5B, 0x4F, 0x8B, 0xD6, 0x03,
  33150. 0xC7, 0x53, 0xE6, 0xCE, 0xBB, 0xD8, 0x52, 0x89,
  33151. 0x70, 0x5D, 0x98, 0x86, 0xA5, 0x9E, 0x44, 0xA9,
  33152. 0xC8, 0x17, 0xA2, 0x6F, 0x43, 0x2D, 0x8D, 0xA7,
  33153. 0xDE, 0x3E, 0xFA, 0xE7, 0x98, 0x7B, 0xB5, 0xBE,
  33154. 0x7B, 0x10, 0xB8, 0xB8, 0xA5, 0x3D, 0x3E, 0xCD,
  33155. 0x94, 0x19, 0x5E, 0x06, 0x51, 0xB8, 0x58, 0x1E,
  33156. 0x0E, 0xCF, 0xFE, 0xE5, 0xED, 0x84, 0xB5, 0xF5,
  33157. 0x0F, 0x34, 0x32, 0xAC, 0x0A, 0x7F, 0x03, 0xF0,
  33158. 0xF8, 0xFC, 0x69, 0xA0, 0x26, 0x0D, 0x2E, 0xFA,
  33159. 0x62, 0x49, 0x5C, 0xC4, 0xE5, 0xF6, 0x8B, 0xC5,
  33160. 0x26, 0x21, 0x23, 0x3B, 0xBD, 0x9A, 0x23, 0x95,
  33161. 0x69, 0xA7, 0x48, 0x94, 0x30, 0x1E, 0xC3, 0x82,
  33162. 0xB6, 0x75, 0x30, 0xA6, 0xF3, 0x1E, 0xBB, 0xBC,
  33163. 0xF7, 0x21, 0x27, 0x12, 0x2C, 0x51, 0x50, 0x55,
  33164. 0x87, 0x0D, 0xF1, 0xCC, 0x6C, 0xFF, 0xEA, 0x7E,
  33165. 0x2C, 0xDA, 0x8B, 0x9B, 0x20, 0xF4, 0x75, 0xFB,
  33166. 0xC2, 0x3F, 0xBE, 0x09, 0xA6, 0xC9, 0x26, 0xE7,
  33167. 0xB5, 0xC7, 0xE6, 0xB9, 0x35, 0x8C, 0xAF, 0xFA,
  33168. 0xC0, 0x8D, 0x43, 0x33, 0x25, 0xBA, 0xAA, 0xDC,
  33169. 0xCF, 0xBC, 0xE4, 0xC4, 0xC6, 0x26, 0x4A, 0x0D,
  33170. 0x9D, 0xCC, 0x2A, 0xE0, 0x5B, 0x1E, 0xC9, 0x78,
  33171. 0xF8, 0xA2, 0xB5, 0x46, 0xE5, 0x49, 0xB8, 0x4C,
  33172. 0xC2, 0x22, 0x40, 0xCE, 0x97, 0x9A, 0x95, 0x40,
  33173. 0xF7, 0xD6, 0x52, 0x54, 0x3B, 0xBB, 0x42, 0xC5,
  33174. 0x6F, 0x00, 0x7F, 0x83, 0xDD, 0x88, 0x71, 0xF7,
  33175. 0xD4, 0x1B, 0x3D, 0x81, 0xC4, 0xB1, 0x49, 0x9B,
  33176. 0xF3, 0x68, 0x15, 0xC5, 0x15, 0x97, 0x0F, 0xC5,
  33177. 0x43, 0xDD, 0x07, 0xBE, 0x98, 0x43, 0x2C, 0xB3,
  33178. 0xEF, 0x08, 0xCA, 0xDC, 0x9C, 0x27, 0x58, 0xFE,
  33179. 0x49, 0xE9, 0x77, 0xD9, 0x1C, 0x62, 0xA4, 0xA2,
  33180. 0xF9, 0x78, 0xCC, 0xB3, 0x21, 0x06, 0x10, 0xDE,
  33181. 0x5A, 0x52, 0xA3, 0x67, 0xBD, 0x5E, 0xBC, 0x9B,
  33182. 0x4E, 0x40, 0x87, 0x93, 0xCF, 0x0E, 0x27, 0x0E,
  33183. 0xE3, 0x11, 0x4B, 0xB3, 0xE0, 0xCE, 0x24, 0xB6,
  33184. 0x0A, 0x53, 0x03, 0xF8, 0x01, 0x6A, 0x7E, 0xFE,
  33185. 0xC8, 0x66, 0x9F, 0x29, 0xF3, 0x45, 0x94, 0xD6,
  33186. 0x0E, 0x30, 0xB5, 0x61, 0xA9, 0xEC, 0x8F, 0x71,
  33187. 0xF7, 0x36, 0xD6, 0x43, 0x4B, 0x0C, 0xCD, 0x45,
  33188. 0xBB, 0xA4, 0xBD, 0xE9, 0xA9, 0xC3, 0xC1, 0x95,
  33189. 0x1E, 0xF9, 0x42, 0x07, 0x18, 0xEA, 0xF5, 0x0B,
  33190. 0x27, 0xB6, 0xDE, 0xEF, 0x67, 0x33, 0x83, 0x0D,
  33191. 0xD9, 0x5E, 0x3A, 0x93, 0xD2, 0xD0, 0xDB, 0xB9,
  33192. 0x98, 0xF0, 0x25, 0x21, 0xF3, 0xDF, 0x0B, 0x1E
  33193. };
  33194. #endif /* !WOLFSSL_NO_ML_DSA_44 */
  33195. #ifndef WOLFSSL_NO_ML_DSA_65
  33196. static const byte seed_65[] = {
  33197. 0x41, 0xAF, 0x98, 0x7B, 0x02, 0x6E, 0x47, 0x5F,
  33198. 0x37, 0x91, 0x7F, 0x2A, 0x6A, 0x9A, 0x87, 0xE7,
  33199. 0x51, 0xAD, 0xF9, 0x5B, 0x92, 0x7F, 0x2D, 0xCE,
  33200. 0xF0, 0xD4, 0xF3, 0xDA, 0x8F, 0x8C, 0x86, 0x6B
  33201. };
  33202. static const byte pk_65[] = {
  33203. 0xDC, 0x38, 0xE5, 0x5F, 0xDF, 0x2E, 0x9D, 0xD4,
  33204. 0x34, 0x5C, 0xAE, 0x1A, 0x7D, 0xF4, 0x2E, 0x2E,
  33205. 0xBC, 0x58, 0x57, 0x80, 0x55, 0x02, 0xE4, 0x3F,
  33206. 0xA5, 0x19, 0x41, 0xE4, 0x44, 0x58, 0x66, 0x41,
  33207. 0x39, 0x5D, 0xF9, 0x20, 0x6C, 0x36, 0x0D, 0x4F,
  33208. 0x83, 0x43, 0xBE, 0x86, 0xEF, 0x6C, 0x43, 0xD0,
  33209. 0x3E, 0xD0, 0x63, 0x0A, 0x5B, 0x92, 0x8D, 0x31,
  33210. 0x19, 0x1D, 0xA9, 0x51, 0x61, 0x48, 0xE6, 0x26,
  33211. 0x50, 0x07, 0x54, 0x9B, 0xB0, 0xB7, 0x62, 0x54,
  33212. 0xDB, 0x80, 0x4E, 0x48, 0x7F, 0x48, 0xC5, 0x11,
  33213. 0x91, 0xFC, 0xA9, 0x26, 0x25, 0x08, 0xA5, 0x99,
  33214. 0xA0, 0x3C, 0xB9, 0x0C, 0xCF, 0x6C, 0xCD, 0x83,
  33215. 0x9A, 0x38, 0x6D, 0x22, 0xDE, 0x0A, 0xC3, 0x8F,
  33216. 0xF7, 0xD0, 0x57, 0x40, 0x53, 0xE9, 0xE9, 0x4E,
  33217. 0x73, 0xFA, 0x58, 0x40, 0x9F, 0x6D, 0x8A, 0xD3,
  33218. 0x6F, 0x86, 0x84, 0x4D, 0x18, 0xD7, 0x4C, 0x76,
  33219. 0x39, 0x57, 0x9E, 0xC0, 0xC7, 0xE4, 0xEE, 0x54,
  33220. 0xF4, 0xAD, 0x10, 0xC5, 0x69, 0x59, 0xE0, 0xBC,
  33221. 0x9B, 0xF4, 0x20, 0x8F, 0xBA, 0x0A, 0x94, 0x10,
  33222. 0x55, 0x07, 0x7E, 0xD1, 0xF9, 0x20, 0xCC, 0x2F,
  33223. 0xA9, 0xAE, 0x9D, 0xF5, 0xE4, 0x29, 0x40, 0x7E,
  33224. 0x44, 0xA4, 0xDF, 0xB2, 0xE9, 0x25, 0xE0, 0xBA,
  33225. 0x8D, 0x6C, 0x33, 0x88, 0x9C, 0xEE, 0x27, 0xDB,
  33226. 0xC7, 0x0A, 0x6E, 0x5A, 0x08, 0x92, 0x9B, 0x53,
  33227. 0xF8, 0xFD, 0xF9, 0x5B, 0xEB, 0x03, 0x8E, 0x45,
  33228. 0xCB, 0x91, 0x19, 0x4E, 0x6B, 0x1E, 0xA0, 0xA4,
  33229. 0xF0, 0x43, 0xC9, 0x8F, 0xDF, 0x93, 0x5E, 0x86,
  33230. 0xB0, 0x09, 0xD3, 0x47, 0x38, 0x7C, 0x8E, 0x78,
  33231. 0x85, 0x71, 0x3D, 0x07, 0x2E, 0x2E, 0x12, 0x6F,
  33232. 0x06, 0x97, 0x0E, 0x54, 0xAD, 0x71, 0x09, 0xEF,
  33233. 0xA5, 0x55, 0x0A, 0x39, 0x86, 0xE6, 0x17, 0x17,
  33234. 0x70, 0x9A, 0xA7, 0xA7, 0x1B, 0xCE, 0x78, 0x06,
  33235. 0x2C, 0x61, 0x1A, 0xB9, 0x48, 0x22, 0x41, 0x45,
  33236. 0x15, 0xEB, 0x10, 0x3C, 0x6E, 0x24, 0x37, 0xA4,
  33237. 0xB5, 0xE8, 0x82, 0x4D, 0x6D, 0xCC, 0x44, 0xC6,
  33238. 0xB0, 0x5D, 0xBE, 0x46, 0xDA, 0x5F, 0x00, 0x36,
  33239. 0x5B, 0xBD, 0x87, 0x65, 0x3A, 0x96, 0x21, 0x58,
  33240. 0x45, 0x65, 0xDB, 0xD8, 0x77, 0x76, 0x7B, 0x25,
  33241. 0xC3, 0x78, 0x6E, 0xD9, 0x14, 0xA7, 0x19, 0x69,
  33242. 0x4F, 0xBB, 0x1B, 0xDB, 0x37, 0xCE, 0xAF, 0x8C,
  33243. 0x88, 0x2E, 0x9E, 0x30, 0xF6, 0xAE, 0x43, 0xCC,
  33244. 0x59, 0x0F, 0x67, 0x8A, 0xCB, 0x4F, 0x08, 0x20,
  33245. 0x6D, 0x99, 0xD7, 0xA9, 0xDE, 0xE5, 0xE5, 0xB3,
  33246. 0xFF, 0xAA, 0x45, 0x3C, 0xF1, 0xE3, 0x02, 0x7D,
  33247. 0x2F, 0xEE, 0x69, 0x04, 0x81, 0x73, 0x01, 0x37,
  33248. 0x51, 0x68, 0xC8, 0x0B, 0x51, 0xFD, 0x05, 0xB4,
  33249. 0x05, 0xBB, 0xA1, 0xDB, 0x1D, 0xF6, 0x5F, 0x70,
  33250. 0xD3, 0x0A, 0x37, 0x4B, 0x9C, 0xC4, 0x45, 0x30,
  33251. 0x11, 0x36, 0xE2, 0x48, 0x9F, 0xC4, 0x2E, 0x4E,
  33252. 0x0C, 0x0C, 0xA1, 0x04, 0x41, 0x75, 0x95, 0xAA,
  33253. 0xED, 0xAC, 0xD4, 0xB2, 0xE7, 0x85, 0x7E, 0xE1,
  33254. 0xA6, 0xFE, 0x2A, 0x09, 0x19, 0x09, 0x3D, 0x7C,
  33255. 0x20, 0x1E, 0x98, 0x3D, 0x6E, 0x02, 0xC1, 0xCA,
  33256. 0xBB, 0x24, 0x82, 0x9F, 0x45, 0x1D, 0x26, 0x99,
  33257. 0xAE, 0x02, 0x82, 0xF9, 0x86, 0x3B, 0x67, 0x8C,
  33258. 0xBD, 0xFE, 0xF1, 0xD0, 0xB6, 0xB8, 0xAB, 0x00,
  33259. 0x0F, 0xEC, 0x30, 0xDC, 0x27, 0x58, 0xE2, 0x29,
  33260. 0x18, 0x05, 0x5A, 0x66, 0xA5, 0x88, 0x39, 0x8E,
  33261. 0x49, 0x5B, 0xB9, 0x52, 0x43, 0x84, 0xDC, 0xA9,
  33262. 0x50, 0x2B, 0x83, 0x3C, 0x84, 0x81, 0x37, 0x52,
  33263. 0x30, 0x79, 0xBD, 0x04, 0xB8, 0xDD, 0x47, 0xC1,
  33264. 0x02, 0x2E, 0xEC, 0x24, 0xD0, 0x56, 0x23, 0xE1,
  33265. 0x92, 0xD0, 0x65, 0x7F, 0xC7, 0xC2, 0xF7, 0x60,
  33266. 0x73, 0xB8, 0xAF, 0x0A, 0xF4, 0xEF, 0xFC, 0x1B,
  33267. 0xC2, 0xB9, 0x76, 0x87, 0x8A, 0xA6, 0xC2, 0x3F,
  33268. 0xD3, 0x9F, 0x1F, 0x2D, 0x94, 0xBC, 0x89, 0x4E,
  33269. 0x31, 0x8D, 0x28, 0xD0, 0x90, 0xB5, 0x5B, 0x60,
  33270. 0x30, 0xC6, 0x0B, 0x37, 0x63, 0x5D, 0xDC, 0xC6,
  33271. 0xE0, 0x1A, 0xBA, 0x6B, 0x23, 0xCD, 0x2E, 0x09,
  33272. 0x2D, 0x6A, 0x7E, 0x0C, 0xD9, 0x4F, 0xB1, 0xE2,
  33273. 0x89, 0x67, 0xE7, 0xB1, 0x54, 0x08, 0xB2, 0xFA,
  33274. 0x83, 0x43, 0x7C, 0x77, 0x06, 0xED, 0xE2, 0x29,
  33275. 0x53, 0xB7, 0x09, 0xC4, 0x1B, 0x81, 0x55, 0x12,
  33276. 0x41, 0x8E, 0x8B, 0x03, 0x36, 0xEE, 0x45, 0x70,
  33277. 0x57, 0xA8, 0x73, 0xEF, 0x70, 0x7B, 0x1F, 0x63,
  33278. 0xB0, 0xE8, 0x00, 0xBD, 0x1E, 0xE6, 0xA9, 0x93,
  33279. 0x9D, 0x03, 0x19, 0x22, 0xDF, 0xE1, 0x01, 0xF2,
  33280. 0xA9, 0x6B, 0x90, 0x5C, 0xD2, 0xC1, 0xAC, 0x9F,
  33281. 0xB2, 0x21, 0x1C, 0x2D, 0xC6, 0x80, 0x9A, 0xB5,
  33282. 0x1E, 0x46, 0x95, 0x6C, 0xCE, 0x47, 0x3E, 0x67,
  33283. 0xCD, 0xD6, 0xC9, 0xB9, 0x81, 0x74, 0x7F, 0x17,
  33284. 0xA3, 0xF7, 0x48, 0x99, 0xF3, 0x36, 0x84, 0xF3,
  33285. 0x16, 0x41, 0x55, 0x5F, 0xA7, 0xBF, 0x4B, 0x69,
  33286. 0x8D, 0xA3, 0x3D, 0x1E, 0xEA, 0xF5, 0x1E, 0xC6,
  33287. 0xB8, 0x1C, 0xD6, 0x89, 0x45, 0x68, 0xFA, 0xE7,
  33288. 0xCA, 0x86, 0xE4, 0xB1, 0xC9, 0x9C, 0xB2, 0xAB,
  33289. 0x89, 0x03, 0xE7, 0x19, 0x7B, 0xA9, 0xF2, 0x6B,
  33290. 0x4A, 0x43, 0x1D, 0x90, 0xAF, 0xA4, 0xE3, 0xBC,
  33291. 0xEF, 0xD4, 0x37, 0xC5, 0x55, 0x5C, 0x9E, 0x14,
  33292. 0xC6, 0x18, 0xDD, 0x45, 0x3F, 0x80, 0x49, 0x1C,
  33293. 0x93, 0xFF, 0xBD, 0xDD, 0x75, 0x54, 0x0B, 0xD1,
  33294. 0xA9, 0xF6, 0xBC, 0x89, 0x98, 0x7D, 0x6F, 0x03,
  33295. 0x7B, 0x06, 0xD5, 0x40, 0x7D, 0x85, 0x48, 0x2E,
  33296. 0x11, 0x3E, 0xF0, 0x47, 0x77, 0xD0, 0xBA, 0x03,
  33297. 0x33, 0x58, 0xC4, 0x8F, 0x76, 0xF8, 0x72, 0x47,
  33298. 0x04, 0x21, 0x5E, 0x85, 0x5A, 0x0F, 0x35, 0x77,
  33299. 0xFB, 0x96, 0x29, 0x81, 0x2D, 0x55, 0x6E, 0x53,
  33300. 0xC6, 0x13, 0x1E, 0xFA, 0x4D, 0xCE, 0xA9, 0x36,
  33301. 0x1D, 0x8F, 0xAB, 0xAC, 0x13, 0x19, 0x94, 0xFC,
  33302. 0x4B, 0xCD, 0x36, 0x4C, 0x6E, 0x21, 0xAE, 0xF1,
  33303. 0x13, 0xA4, 0xF7, 0x64, 0x8E, 0xE1, 0xAF, 0x50,
  33304. 0x6A, 0x63, 0x0E, 0xCA, 0x2F, 0xE9, 0x0C, 0x8A,
  33305. 0xE7, 0xF2, 0xE3, 0x68, 0x03, 0xE0, 0x40, 0x1C,
  33306. 0x64, 0xAB, 0xC3, 0xEC, 0xC0, 0x92, 0xE9, 0x57,
  33307. 0x3E, 0x66, 0x72, 0x36, 0x39, 0x22, 0x4E, 0xCD,
  33308. 0x13, 0x08, 0xBA, 0xF8, 0x2B, 0xA1, 0xF2, 0x69,
  33309. 0x44, 0x7E, 0x90, 0x5C, 0xC8, 0xEC, 0xB6, 0xBE,
  33310. 0x8C, 0x30, 0xE0, 0x69, 0xB7, 0x97, 0xA1, 0x1C,
  33311. 0x18, 0xE5, 0x54, 0x62, 0xC3, 0x29, 0x99, 0x21,
  33312. 0x16, 0xD9, 0x78, 0x1C, 0x4C, 0x9C, 0x88, 0x4C,
  33313. 0xA5, 0xE1, 0x11, 0x66, 0x5B, 0x6E, 0x71, 0xE7,
  33314. 0xE2, 0xE7, 0xE4, 0x02, 0xDD, 0x1A, 0x8D, 0x0C,
  33315. 0xF5, 0x32, 0xFD, 0x41, 0x28, 0x35, 0x75, 0xD0,
  33316. 0x0C, 0x5F, 0x06, 0x6A, 0x5A, 0x61, 0x49, 0x59,
  33317. 0xC1, 0x0C, 0xD4, 0x9E, 0xD6, 0x29, 0xE2, 0x37,
  33318. 0xDF, 0x2B, 0x3D, 0xE8, 0x98, 0xB9, 0xDF, 0x8E,
  33319. 0xA0, 0xC4, 0xE2, 0xFC, 0x45, 0x70, 0xE8, 0x1B,
  33320. 0xF4, 0xFA, 0xC5, 0xE6, 0xA7, 0xCF, 0x4F, 0xA2,
  33321. 0xDA, 0x3D, 0x90, 0x49, 0x24, 0x8F, 0x61, 0x54,
  33322. 0xD5, 0x50, 0x8E, 0xE8, 0x0C, 0x14, 0xAD, 0x6F,
  33323. 0x65, 0x88, 0x3A, 0xF6, 0x92, 0xDB, 0x35, 0x5D,
  33324. 0xFF, 0x21, 0x20, 0xAC, 0x01, 0x16, 0x0B, 0xEC,
  33325. 0x84, 0x15, 0x3B, 0xA9, 0x93, 0x92, 0x75, 0xB3,
  33326. 0x73, 0xF1, 0x23, 0x69, 0x94, 0x10, 0xF5, 0xFE,
  33327. 0x20, 0xA8, 0xAF, 0x05, 0x87, 0x49, 0x4E, 0x9C,
  33328. 0xEB, 0x21, 0x0A, 0xCF, 0x0B, 0xA1, 0x65, 0x38,
  33329. 0xA6, 0x18, 0x4D, 0xF7, 0xD8, 0xC1, 0x2C, 0x14,
  33330. 0x4C, 0xD9, 0x40, 0xC2, 0xF7, 0xBF, 0xE3, 0x07,
  33331. 0x79, 0x55, 0xAE, 0xB9, 0xB6, 0x50, 0x06, 0x92,
  33332. 0x94, 0x8C, 0x6A, 0x0E, 0x22, 0x14, 0xE2, 0xCC,
  33333. 0x65, 0xBA, 0x0C, 0x4D, 0xB6, 0x5C, 0x4A, 0xE9,
  33334. 0x0A, 0x08, 0x0C, 0xF9, 0x26, 0xA2, 0x51, 0x85,
  33335. 0x36, 0xE2, 0xC1, 0xF1, 0x0A, 0x66, 0x51, 0x66,
  33336. 0x7A, 0x98, 0x9B, 0x2C, 0x30, 0x1A, 0x0D, 0x49,
  33337. 0x3C, 0x1E, 0xEC, 0x63, 0x53, 0x5E, 0xD9, 0xDD,
  33338. 0x84, 0x69, 0xCD, 0x7E, 0x79, 0x58, 0x3D, 0x6E,
  33339. 0xD9, 0x98, 0x58, 0xD8, 0x0A, 0x48, 0xB5, 0x13,
  33340. 0x3F, 0x72, 0x4C, 0x11, 0x90, 0x15, 0x12, 0x74,
  33341. 0xFF, 0x5C, 0x0D, 0xC6, 0x20, 0x8C, 0xC1, 0x99,
  33342. 0xCA, 0x8E, 0xFC, 0xA2, 0xE8, 0xB8, 0xEE, 0xAA,
  33343. 0x27, 0xC2, 0x97, 0x8D, 0xFA, 0xBE, 0xE0, 0x43,
  33344. 0x99, 0xB6, 0x90, 0x60, 0x00, 0x7C, 0x33, 0xD4,
  33345. 0x87, 0x71, 0x7B, 0x56, 0x6C, 0xAA, 0xE0, 0xAC,
  33346. 0x9D, 0x7E, 0x7E, 0xA3, 0xCF, 0xBB, 0xB3, 0xA0,
  33347. 0x5F, 0xD4, 0xC4, 0x3A, 0xA7, 0xB9, 0x0C, 0xCE,
  33348. 0xF3, 0x05, 0x09, 0x91, 0xA7, 0xE9, 0x11, 0x55,
  33349. 0x32, 0x45, 0xA6, 0x08, 0x0E, 0x10, 0x37, 0x91,
  33350. 0xF3, 0xBF, 0xED, 0x64, 0x26, 0xEB, 0x39, 0xC2,
  33351. 0x57, 0xAE, 0x64, 0x79, 0x33, 0x7C, 0x51, 0xB2,
  33352. 0xC8, 0x85, 0xE0, 0xF9, 0x6D, 0x10, 0x52, 0x9F,
  33353. 0x72, 0xF4, 0xD1, 0x5B, 0x54, 0x5B, 0x93, 0x28,
  33354. 0x36, 0xA8, 0xCD, 0xB3, 0x30, 0x5B, 0x7A, 0xB0,
  33355. 0xB6, 0xF0, 0xD8, 0xA0, 0xBA, 0x24, 0x59, 0x5F,
  33356. 0x43, 0x02, 0x01, 0x57, 0x91, 0x7B, 0x94, 0x07,
  33357. 0x63, 0x23, 0x12, 0x94, 0xFB, 0x9F, 0xF2, 0xC1,
  33358. 0xD6, 0x80, 0x8F, 0x4E, 0xA7, 0x9E, 0x11, 0xD8,
  33359. 0xB3, 0x08, 0xB6, 0x3B, 0x3B, 0xF2, 0xEE, 0x14,
  33360. 0xA5, 0xDB, 0xB0, 0xBB, 0x17, 0xA5, 0x96, 0x3C,
  33361. 0x2F, 0xB9, 0xE7, 0x4A, 0xD7, 0x52, 0x34, 0x98,
  33362. 0xCB, 0x0C, 0xEB, 0x42, 0x5B, 0x2D, 0x2D, 0x2B,
  33363. 0x0D, 0x94, 0x66, 0xD3, 0xAD, 0x08, 0x0A, 0x28,
  33364. 0xF6, 0x0E, 0xDA, 0xD4, 0x54, 0xFD, 0xC6, 0x48,
  33365. 0x08, 0xA1, 0x8D, 0xB0, 0x30, 0xFD, 0x18, 0xB1,
  33366. 0x50, 0xB1, 0xFD, 0xE0, 0x6E, 0x33, 0x25, 0x0D,
  33367. 0x90, 0xB1, 0xC1, 0xE7, 0x88, 0x74, 0x87, 0x05,
  33368. 0xE7, 0xBE, 0xBD, 0xAA, 0x8C, 0x6D, 0xC2, 0x3D,
  33369. 0x6F, 0x95, 0x84, 0xFA, 0x03, 0x74, 0x85, 0xE1,
  33370. 0xED, 0xE5, 0xF4, 0xE8, 0x26, 0x4A, 0x0B, 0x20,
  33371. 0x87, 0xB6, 0xE1, 0x10, 0x75, 0x6D, 0x9F, 0x95,
  33372. 0x39, 0x4C, 0x0F, 0x50, 0x1B, 0xA8, 0x69, 0x82,
  33373. 0xBB, 0xE2, 0xD6, 0x11, 0xD7, 0xBE, 0xFB, 0x4F,
  33374. 0x60, 0xD3, 0x16, 0xC6, 0x04, 0x3A, 0x5A, 0xF5,
  33375. 0x78, 0x9B, 0x0B, 0x21, 0xA1, 0x00, 0x96, 0xCD,
  33376. 0x63, 0x78, 0x1D, 0x2D, 0x4F, 0x6E, 0x50, 0xEE,
  33377. 0x62, 0x2D, 0x88, 0x62, 0x01, 0xF6, 0xB4, 0x17,
  33378. 0x4F, 0x8C, 0xAD, 0xCB, 0x4B, 0xF9, 0xF6, 0x9D,
  33379. 0xC7, 0xD8, 0xCC, 0xBF, 0x96, 0x1B, 0x1B, 0x79,
  33380. 0xF3, 0x25, 0x85, 0x23, 0x10, 0x63, 0x30, 0x8D,
  33381. 0xA8, 0x3A, 0x4B, 0x92, 0x1B, 0x88, 0x53, 0x24,
  33382. 0x2D, 0x29, 0xA5, 0x2E, 0x7A, 0xD5, 0x58, 0xEB,
  33383. 0x1B, 0x1C, 0xE6, 0xB8, 0x94, 0x0C, 0x58, 0x96,
  33384. 0x5B, 0xA0, 0x2C, 0xBF, 0xE2, 0x99, 0xA0, 0x1F,
  33385. 0x0C, 0xCC, 0xBD, 0x83, 0x72, 0x56, 0xBB, 0x13,
  33386. 0x61, 0x5A, 0xC2, 0x04, 0x27, 0x29, 0x1F, 0xD4,
  33387. 0xE4, 0x3D, 0x8A, 0x87, 0xE3, 0x81, 0x91, 0x07,
  33388. 0xD3, 0x9B, 0xBC, 0xA9, 0xB3, 0xBA, 0xF5, 0x8B,
  33389. 0x6A, 0xAD, 0xDE, 0xB0, 0x54, 0x3E, 0xFE, 0xCC,
  33390. 0xD3, 0xCB, 0x2C, 0x69, 0xF0, 0x58, 0xD7, 0xEF,
  33391. 0xA9, 0xC0, 0x15, 0x9B, 0x5A, 0xDF, 0x71, 0x25,
  33392. 0x38, 0x44, 0xEC, 0xA9, 0x18, 0x47, 0x41, 0xCE,
  33393. 0x3D, 0x53, 0x10, 0x12, 0xC3, 0x1B, 0x59, 0x9A,
  33394. 0x93, 0xA1, 0xEA, 0xBE, 0x3E, 0xBA, 0x74, 0xF6,
  33395. 0x2D, 0x40, 0x9D, 0xCB, 0x9E, 0xA1, 0xA5, 0x85,
  33396. 0xFF, 0xDC, 0xC5, 0x60, 0x6F, 0x61, 0xE8, 0x17,
  33397. 0x6C, 0x36, 0x9F, 0x7A, 0x48, 0x47, 0xDD, 0xF1,
  33398. 0xF4, 0x43, 0x21, 0xCB, 0xB3, 0x55, 0x86, 0xD0,
  33399. 0xE9, 0x46, 0x7D, 0xB5, 0x3D, 0x90, 0x34, 0x1E,
  33400. 0xBB, 0x40, 0xD3, 0x2A, 0xEB, 0xE6, 0x4C, 0x46,
  33401. 0x42, 0xA2, 0x8A, 0xBF, 0x90, 0xE7, 0x4B, 0x6D,
  33402. 0x5C, 0x94, 0x97, 0xD2, 0xF0, 0x97, 0x74, 0x4C,
  33403. 0x76, 0x03, 0xAC, 0x3D, 0xDE, 0x15, 0x96, 0x0C,
  33404. 0xEF, 0x18, 0x9D, 0xBD, 0x1A, 0x20, 0x35, 0x7E,
  33405. 0x2A, 0x70, 0x9D, 0xEA, 0x2E, 0x11, 0xDF, 0xF3,
  33406. 0x2F, 0xFE, 0x23, 0xA9, 0xB6, 0xCF, 0xB7, 0xB9,
  33407. 0x3F, 0x4F, 0x30, 0x6B, 0x3B, 0x0D, 0x3B, 0xED,
  33408. 0xCD, 0x77, 0xD4, 0xBF, 0xEE, 0xDD, 0xB6, 0x56,
  33409. 0x24, 0xD4, 0x29, 0x83, 0xDE, 0xDB, 0xC1, 0xFB,
  33410. 0x6A, 0xCE, 0x7F, 0x47, 0xD2, 0xC5, 0xF1, 0x78,
  33411. 0x5C, 0x2C, 0x5A, 0x28, 0x3E, 0x05, 0x50, 0x2E,
  33412. 0xD9, 0xAE, 0x9B, 0x95, 0x64, 0xC7, 0xD2, 0x7B,
  33413. 0xCB, 0xC5, 0x91, 0x80, 0xEB, 0x79, 0xC7, 0xCC,
  33414. 0xA8, 0x06, 0xC8, 0xF9, 0xDF, 0x2A, 0x49, 0x4A,
  33415. 0xF8, 0xFE, 0xBA, 0xA5, 0x85, 0x67, 0x1B, 0xDA,
  33416. 0x51, 0x3B, 0xC2, 0x04, 0xA6, 0xA3, 0xFF, 0x99,
  33417. 0x21, 0xE8, 0x17, 0x91, 0x33, 0x9B, 0x83, 0x75,
  33418. 0x20, 0x5E, 0x95, 0xBE, 0x49, 0xDF, 0x53, 0xFC,
  33419. 0x05, 0xA2, 0x3C, 0xAA, 0x5A, 0x22, 0x15, 0xA5,
  33420. 0x56, 0xE0, 0x51, 0x30, 0x4E, 0x32, 0x14, 0xF2,
  33421. 0x9F, 0x03, 0x51, 0x8E, 0xDD, 0x8B, 0x39, 0x19,
  33422. 0x1E, 0x39, 0xC5, 0xA7, 0x1C, 0xC6, 0xA4, 0xE1,
  33423. 0x77, 0xCA, 0x8C, 0x9D, 0x27, 0xBC, 0xCC, 0x16,
  33424. 0xD6, 0xFC, 0x59, 0x10, 0x23, 0xFF, 0x64, 0x90,
  33425. 0x9C, 0x23, 0x5A, 0xFF, 0x7E, 0x27, 0x1B, 0xC7,
  33426. 0x7F, 0x21, 0x3B, 0x41, 0xDB, 0xBC, 0x96, 0x60,
  33427. 0x0B, 0x35, 0xA1, 0xF3, 0xF8, 0x51, 0x0A, 0x65,
  33428. 0xCF, 0xDF, 0x7A, 0xB8, 0x04, 0x56, 0x49, 0xD7,
  33429. 0xD3, 0xC5, 0x0B, 0x4A, 0x1F, 0x60, 0xE1, 0x86,
  33430. 0x36, 0x53, 0x8E, 0x6C, 0x3E, 0xAF, 0x5B, 0xC1,
  33431. 0xCA, 0xCB, 0x22, 0x1A, 0x07, 0xDA, 0x54, 0xEC,
  33432. 0xAA, 0x06, 0x72, 0x17, 0xCF, 0x80, 0xC4, 0x89,
  33433. 0x56, 0x24, 0x1B, 0xD4, 0xFF, 0x50, 0x6B, 0x51,
  33434. 0x55, 0x4D, 0x6E, 0x79, 0x7E, 0xEC, 0x61, 0xC6,
  33435. 0xE4, 0x21, 0xC8, 0x0E, 0x10, 0x3F, 0x8C, 0x85,
  33436. 0x3A, 0x27, 0xEA, 0x91, 0x07, 0xCB, 0x37, 0x18,
  33437. 0x14, 0xB5, 0x63, 0x6E, 0x00, 0xBC, 0x0F, 0x36,
  33438. 0xF9, 0x54, 0x75, 0xE7, 0x0B, 0xDC, 0xE7, 0xA0,
  33439. 0x59, 0xF0, 0x64, 0xFB, 0x73, 0x07, 0x0E, 0xFE,
  33440. 0x57, 0x7F, 0x0D, 0x12, 0xBC, 0xB0, 0xBF, 0xA2,
  33441. 0x3A, 0x18, 0x08, 0x7E, 0xD5, 0x6C, 0xF0, 0x6F,
  33442. 0xF8, 0x98, 0xFB, 0xA5, 0x10, 0x7B, 0x10, 0x5F,
  33443. 0x6B, 0xC8, 0x6D, 0xDE, 0x2F, 0x1F, 0xE0, 0xC8,
  33444. 0x19, 0xEE, 0xC2, 0x03, 0x39, 0x49, 0x70, 0x3E,
  33445. 0x36, 0xE3, 0x3C, 0x70, 0xE3, 0xEA, 0xAC, 0x34,
  33446. 0x32, 0xB7, 0x0D, 0xBA, 0x7C, 0xAB, 0xE6, 0x18
  33447. };
  33448. static const byte sk_65[] = {
  33449. 0xDC, 0x38, 0xE5, 0x5F, 0xDF, 0x2E, 0x9D, 0xD4,
  33450. 0x34, 0x5C, 0xAE, 0x1A, 0x7D, 0xF4, 0x2E, 0x2E,
  33451. 0xBC, 0x58, 0x57, 0x80, 0x55, 0x02, 0xE4, 0x3F,
  33452. 0xA5, 0x19, 0x41, 0xE4, 0x44, 0x58, 0x66, 0x41,
  33453. 0x52, 0x8D, 0xA0, 0xC7, 0xD2, 0x80, 0xDD, 0x49,
  33454. 0x0D, 0x5E, 0xB7, 0x65, 0xDB, 0x32, 0x33, 0x15,
  33455. 0x0F, 0x9E, 0xC8, 0xEB, 0xC9, 0x6E, 0xE8, 0xE8,
  33456. 0x5C, 0xBD, 0x18, 0x4F, 0xDC, 0xF8, 0xA8, 0xD9,
  33457. 0xC5, 0x33, 0x84, 0x79, 0x5A, 0x5E, 0xB7, 0x3C,
  33458. 0x6D, 0x82, 0xCA, 0xB9, 0xBA, 0x94, 0xB6, 0x46,
  33459. 0xAE, 0x3A, 0xD9, 0x19, 0x6C, 0xB4, 0xDA, 0xE2,
  33460. 0xF1, 0x4B, 0xB6, 0x43, 0xF0, 0x24, 0x08, 0xE5,
  33461. 0xF7, 0x9A, 0x41, 0xF1, 0x15, 0x9C, 0xA8, 0x08,
  33462. 0x79, 0x9F, 0xB8, 0x26, 0xD4, 0x08, 0x32, 0x47,
  33463. 0xC8, 0xF0, 0xD5, 0x31, 0xA1, 0xC1, 0x19, 0x04,
  33464. 0x02, 0x06, 0x2B, 0x4D, 0x46, 0xAE, 0x43, 0x6A,
  33465. 0x25, 0x82, 0x75, 0x41, 0x70, 0x36, 0x42, 0x48,
  33466. 0x78, 0x06, 0x36, 0x50, 0x23, 0x84, 0x68, 0x10,
  33467. 0x87, 0x08, 0x62, 0x00, 0x08, 0x34, 0x20, 0x73,
  33468. 0x32, 0x13, 0x36, 0x61, 0x87, 0x61, 0x43, 0x50,
  33469. 0x30, 0x02, 0x26, 0x07, 0x65, 0x45, 0x32, 0x00,
  33470. 0x25, 0x75, 0x01, 0x04, 0x88, 0x81, 0x58, 0x64,
  33471. 0x52, 0x40, 0x84, 0x22, 0x88, 0x42, 0x82, 0x56,
  33472. 0x47, 0x50, 0x05, 0x21, 0x88, 0x25, 0x32, 0x25,
  33473. 0x12, 0x85, 0x14, 0x52, 0x87, 0x77, 0x67, 0x18,
  33474. 0x46, 0x54, 0x63, 0x07, 0x88, 0x67, 0x37, 0x26,
  33475. 0x72, 0x62, 0x41, 0x02, 0x00, 0x01, 0x17, 0x84,
  33476. 0x33, 0x64, 0x32, 0x57, 0x06, 0x20, 0x05, 0x44,
  33477. 0x88, 0x57, 0x33, 0x45, 0x70, 0x55, 0x14, 0x43,
  33478. 0x12, 0x54, 0x04, 0x38, 0x37, 0x08, 0x42, 0x57,
  33479. 0x36, 0x05, 0x30, 0x03, 0x86, 0x53, 0x02, 0x53,
  33480. 0x75, 0x22, 0x62, 0x13, 0x38, 0x82, 0x48, 0x30,
  33481. 0x83, 0x83, 0x64, 0x83, 0x13, 0x74, 0x57, 0x32,
  33482. 0x46, 0x70, 0x06, 0x05, 0x82, 0x52, 0x73, 0x55,
  33483. 0x25, 0x77, 0x21, 0x78, 0x57, 0x83, 0x66, 0x20,
  33484. 0x38, 0x53, 0x21, 0x41, 0x77, 0x56, 0x77, 0x46,
  33485. 0x34, 0x42, 0x58, 0x31, 0x08, 0x06, 0x03, 0x62,
  33486. 0x20, 0x35, 0x11, 0x42, 0x35, 0x38, 0x63, 0x86,
  33487. 0x64, 0x13, 0x13, 0x75, 0x40, 0x01, 0x53, 0x74,
  33488. 0x41, 0x31, 0x56, 0x64, 0x38, 0x17, 0x14, 0x16,
  33489. 0x62, 0x33, 0x22, 0x12, 0x64, 0x40, 0x67, 0x11,
  33490. 0x62, 0x42, 0x25, 0x60, 0x38, 0x05, 0x83, 0x13,
  33491. 0x51, 0x00, 0x28, 0x36, 0x62, 0x56, 0x41, 0x43,
  33492. 0x58, 0x37, 0x51, 0x22, 0x70, 0x25, 0x82, 0x82,
  33493. 0x35, 0x24, 0x06, 0x83, 0x48, 0x58, 0x81, 0x78,
  33494. 0x07, 0x86, 0x23, 0x15, 0x75, 0x32, 0x46, 0x75,
  33495. 0x35, 0x40, 0x08, 0x43, 0x10, 0x66, 0x74, 0x05,
  33496. 0x13, 0x72, 0x74, 0x08, 0x83, 0x41, 0x81, 0x08,
  33497. 0x75, 0x87, 0x83, 0x28, 0x56, 0x66, 0x20, 0x01,
  33498. 0x18, 0x83, 0x57, 0x22, 0x14, 0x64, 0x18, 0x05,
  33499. 0x27, 0x75, 0x22, 0x84, 0x12, 0x38, 0x87, 0x52,
  33500. 0x32, 0x25, 0x28, 0x08, 0x14, 0x41, 0x81, 0x14,
  33501. 0x03, 0x24, 0x54, 0x23, 0x04, 0x81, 0x40, 0x36,
  33502. 0x38, 0x38, 0x64, 0x42, 0x46, 0x36, 0x68, 0x11,
  33503. 0x55, 0x00, 0x11, 0x25, 0x76, 0x16, 0x43, 0x07,
  33504. 0x23, 0x03, 0x34, 0x10, 0x46, 0x41, 0x14, 0x02,
  33505. 0x26, 0x10, 0x74, 0x38, 0x38, 0x72, 0x07, 0x87,
  33506. 0x54, 0x11, 0x12, 0x83, 0x75, 0x05, 0x82, 0x17,
  33507. 0x45, 0x20, 0x38, 0x41, 0x37, 0x20, 0x00, 0x08,
  33508. 0x32, 0x18, 0x16, 0x25, 0x58, 0x85, 0x16, 0x88,
  33509. 0x71, 0x82, 0x45, 0x60, 0x33, 0x11, 0x13, 0x42,
  33510. 0x43, 0x37, 0x68, 0x11, 0x16, 0x54, 0x04, 0x08,
  33511. 0x52, 0x78, 0x13, 0x56, 0x83, 0x52, 0x15, 0x24,
  33512. 0x03, 0x61, 0x78, 0x44, 0x13, 0x70, 0x67, 0x36,
  33513. 0x74, 0x86, 0x52, 0x50, 0x15, 0x41, 0x88, 0x74,
  33514. 0x53, 0x00, 0x05, 0x18, 0x65, 0x62, 0x14, 0x84,
  33515. 0x12, 0x32, 0x01, 0x88, 0x40, 0x42, 0x34, 0x05,
  33516. 0x32, 0x80, 0x72, 0x55, 0x20, 0x68, 0x16, 0x43,
  33517. 0x14, 0x15, 0x15, 0x38, 0x43, 0x85, 0x27, 0x60,
  33518. 0x70, 0x18, 0x27, 0x35, 0x53, 0x01, 0x28, 0x73,
  33519. 0x27, 0x84, 0x10, 0x53, 0x67, 0x10, 0x45, 0x40,
  33520. 0x81, 0x52, 0x86, 0x06, 0x11, 0x18, 0x04, 0x31,
  33521. 0x57, 0x25, 0x22, 0x44, 0x47, 0x81, 0x45, 0x44,
  33522. 0x55, 0x04, 0x72, 0x57, 0x06, 0x46, 0x76, 0x23,
  33523. 0x38, 0x85, 0x65, 0x30, 0x08, 0x48, 0x20, 0x13,
  33524. 0x22, 0x77, 0x44, 0x60, 0x43, 0x14, 0x15, 0x27,
  33525. 0x86, 0x22, 0x37, 0x37, 0x27, 0x04, 0x27, 0x50,
  33526. 0x74, 0x31, 0x10, 0x82, 0x00, 0x75, 0x80, 0x44,
  33527. 0x38, 0x10, 0x58, 0x40, 0x86, 0x60, 0x63, 0x13,
  33528. 0x65, 0x18, 0x33, 0x70, 0x57, 0x68, 0x05, 0x10,
  33529. 0x81, 0x03, 0x42, 0x05, 0x25, 0x65, 0x33, 0x57,
  33530. 0x38, 0x05, 0x65, 0x34, 0x46, 0x53, 0x68, 0x11,
  33531. 0x75, 0x10, 0x04, 0x54, 0x18, 0x47, 0x52, 0x24,
  33532. 0x63, 0x23, 0x74, 0x45, 0x11, 0x34, 0x68, 0x32,
  33533. 0x35, 0x38, 0x52, 0x85, 0x28, 0x08, 0x71, 0x78,
  33534. 0x37, 0x38, 0x27, 0x10, 0x80, 0x54, 0x26, 0x33,
  33535. 0x31, 0x82, 0x44, 0x88, 0x33, 0x24, 0x62, 0x86,
  33536. 0x32, 0x82, 0x73, 0x31, 0x28, 0x14, 0x73, 0x87,
  33537. 0x06, 0x35, 0x80, 0x36, 0x67, 0x02, 0x33, 0x75,
  33538. 0x27, 0x36, 0x38, 0x16, 0x35, 0x70, 0x52, 0x16,
  33539. 0x87, 0x58, 0x85, 0x17, 0x22, 0x13, 0x54, 0x85,
  33540. 0x07, 0x53, 0x31, 0x26, 0x78, 0x01, 0x85, 0x18,
  33541. 0x08, 0x68, 0x38, 0x52, 0x11, 0x73, 0x32, 0x25,
  33542. 0x58, 0x82, 0x70, 0x70, 0x36, 0x30, 0x50, 0x38,
  33543. 0x65, 0x12, 0x78, 0x31, 0x77, 0x72, 0x18, 0x41,
  33544. 0x05, 0x42, 0x32, 0x26, 0x26, 0x50, 0x52, 0x86,
  33545. 0x15, 0x76, 0x28, 0x66, 0x88, 0x03, 0x78, 0x28,
  33546. 0x70, 0x33, 0x36, 0x27, 0x16, 0x61, 0x43, 0x56,
  33547. 0x62, 0x81, 0x85, 0x75, 0x47, 0x60, 0x63, 0x38,
  33548. 0x66, 0x81, 0x51, 0x78, 0x03, 0x42, 0x60, 0x38,
  33549. 0x01, 0x24, 0x73, 0x63, 0x81, 0x12, 0x01, 0x27,
  33550. 0x63, 0x13, 0x11, 0x78, 0x36, 0x37, 0x15, 0x03,
  33551. 0x84, 0x58, 0x17, 0x25, 0x67, 0x87, 0x57, 0x83,
  33552. 0x71, 0x85, 0x37, 0x53, 0x86, 0x22, 0x33, 0x28,
  33553. 0x77, 0x30, 0x18, 0x15, 0x01, 0x37, 0x85, 0x40,
  33554. 0x15, 0x38, 0x51, 0x33, 0x17, 0x42, 0x64, 0x04,
  33555. 0x56, 0x27, 0x50, 0x45, 0x11, 0x27, 0x20, 0x17,
  33556. 0x76, 0x55, 0x33, 0x37, 0x58, 0x88, 0x88, 0x45,
  33557. 0x16, 0x55, 0x08, 0x53, 0x52, 0x48, 0x72, 0x85,
  33558. 0x30, 0x15, 0x23, 0x44, 0x22, 0x02, 0x43, 0x45,
  33559. 0x41, 0x10, 0x00, 0x52, 0x32, 0x73, 0x05, 0x75,
  33560. 0x72, 0x16, 0x08, 0x11, 0x51, 0x36, 0x20, 0x04,
  33561. 0x76, 0x48, 0x78, 0x56, 0x60, 0x88, 0x07, 0x47,
  33562. 0x70, 0x20, 0x46, 0x40, 0x43, 0x26, 0x04, 0x37,
  33563. 0x17, 0x51, 0x58, 0x46, 0x72, 0x44, 0x50, 0x23,
  33564. 0x67, 0x63, 0x60, 0x84, 0x30, 0x51, 0x52, 0x53,
  33565. 0x21, 0x74, 0x85, 0x45, 0x74, 0x43, 0x11, 0x72,
  33566. 0x52, 0x65, 0x76, 0x08, 0x78, 0x63, 0x14, 0x27,
  33567. 0x41, 0x34, 0x67, 0x07, 0x45, 0x15, 0x10, 0x83,
  33568. 0x24, 0x02, 0x80, 0x53, 0x07, 0x21, 0x58, 0x10,
  33569. 0x34, 0x20, 0x54, 0x12, 0x58, 0x44, 0x25, 0x53,
  33570. 0x33, 0x46, 0x02, 0x38, 0x60, 0x17, 0x70, 0x64,
  33571. 0x18, 0x52, 0x62, 0x26, 0x65, 0x61, 0x42, 0x31,
  33572. 0x22, 0x57, 0x34, 0x57, 0x02, 0x34, 0x62, 0x76,
  33573. 0x74, 0x38, 0x73, 0x21, 0x68, 0x71, 0x07, 0x21,
  33574. 0x61, 0x05, 0x20, 0x20, 0x86, 0x83, 0x30, 0x25,
  33575. 0x50, 0x50, 0x83, 0x30, 0x31, 0x56, 0x30, 0x31,
  33576. 0x76, 0x04, 0x54, 0x80, 0x75, 0x18, 0x82, 0x23,
  33577. 0x61, 0x87, 0x58, 0x25, 0x13, 0x63, 0x21, 0x51,
  33578. 0x48, 0x02, 0x67, 0x37, 0x12, 0x88, 0x70, 0x60,
  33579. 0x07, 0x36, 0x18, 0x15, 0x87, 0x74, 0x55, 0x60,
  33580. 0x00, 0x54, 0x37, 0x11, 0x01, 0x37, 0x14, 0x17,
  33581. 0x11, 0x72, 0x14, 0x55, 0x31, 0x75, 0x77, 0x48,
  33582. 0x10, 0x23, 0x83, 0x20, 0x00, 0x04, 0x32, 0x64,
  33583. 0x66, 0x61, 0x71, 0x31, 0x03, 0x15, 0x44, 0x32,
  33584. 0x57, 0x25, 0x64, 0x31, 0x28, 0x15, 0x33, 0x67,
  33585. 0x86, 0x87, 0x37, 0x03, 0x12, 0x78, 0x86, 0x13,
  33586. 0x47, 0x80, 0x61, 0x42, 0x50, 0x40, 0x23, 0x37,
  33587. 0x01, 0x01, 0x66, 0x24, 0x06, 0x57, 0x82, 0x02,
  33588. 0x22, 0x42, 0x41, 0x02, 0x26, 0x06, 0x41, 0x35,
  33589. 0x64, 0x16, 0x44, 0x42, 0x38, 0x30, 0x86, 0x88,
  33590. 0x47, 0x71, 0x62, 0x33, 0x24, 0x02, 0x12, 0x37,
  33591. 0x42, 0x33, 0x20, 0x81, 0x80, 0x53, 0x07, 0x65,
  33592. 0x71, 0x27, 0x13, 0x53, 0x15, 0x43, 0x76, 0x38,
  33593. 0x71, 0x30, 0x07, 0x87, 0x25, 0x63, 0x03, 0x33,
  33594. 0x70, 0x56, 0x18, 0x13, 0x83, 0x51, 0x44, 0x40,
  33595. 0x04, 0x80, 0x62, 0x24, 0x20, 0x64, 0x54, 0x40,
  33596. 0x20, 0x73, 0x61, 0x45, 0x01, 0x24, 0x47, 0x78,
  33597. 0x23, 0x34, 0x56, 0x10, 0x25, 0x32, 0x02, 0x70,
  33598. 0x08, 0x02, 0x23, 0x24, 0x80, 0x43, 0x04, 0x02,
  33599. 0x81, 0x11, 0x23, 0x82, 0x03, 0x61, 0x30, 0x33,
  33600. 0x15, 0x36, 0x25, 0x32, 0x14, 0x73, 0x22, 0x46,
  33601. 0x81, 0x25, 0x16, 0x13, 0x52, 0x58, 0x71, 0x61,
  33602. 0x67, 0x08, 0x38, 0x76, 0x71, 0x15, 0x88, 0x47,
  33603. 0x31, 0x25, 0x27, 0x18, 0x31, 0x50, 0x40, 0x71,
  33604. 0x06, 0x87, 0x37, 0x30, 0x85, 0x64, 0x62, 0x78,
  33605. 0x32, 0x74, 0x18, 0x83, 0x67, 0x40, 0x37, 0x44,
  33606. 0x56, 0x02, 0x72, 0x61, 0x27, 0x28, 0x38, 0x38,
  33607. 0x67, 0x17, 0x58, 0x04, 0x61, 0x28, 0x67, 0x37,
  33608. 0x46, 0x50, 0x38, 0x15, 0x45, 0x12, 0x71, 0x44,
  33609. 0x22, 0x02, 0x34, 0x83, 0x40, 0x70, 0x55, 0x75,
  33610. 0x54, 0x26, 0x88, 0x07, 0x25, 0x58, 0x73, 0x60,
  33611. 0x58, 0x61, 0x45, 0x63, 0x35, 0x05, 0x48, 0x63,
  33612. 0x48, 0x57, 0x03, 0x31, 0x28, 0x14, 0x05, 0x01,
  33613. 0x57, 0x34, 0x64, 0x50, 0x23, 0x86, 0x75, 0x85,
  33614. 0x18, 0x75, 0x56, 0x88, 0x08, 0x26, 0x01, 0x34,
  33615. 0x01, 0x57, 0x05, 0x28, 0x35, 0x48, 0x17, 0x57,
  33616. 0x71, 0x81, 0x41, 0x33, 0x77, 0x86, 0x07, 0x77,
  33617. 0x02, 0x25, 0x71, 0x74, 0x37, 0x31, 0x20, 0x14,
  33618. 0x32, 0x54, 0x20, 0x35, 0x54, 0x76, 0x83, 0x15,
  33619. 0x80, 0x73, 0x27, 0x23, 0x00, 0x58, 0x22, 0x84,
  33620. 0x64, 0x56, 0x14, 0x84, 0x38, 0x34, 0x16, 0x21,
  33621. 0x77, 0x07, 0x34, 0x81, 0x66, 0x87, 0x40, 0x11,
  33622. 0x62, 0x46, 0x45, 0x01, 0x20, 0x53, 0x21, 0x73,
  33623. 0x07, 0x76, 0x44, 0x15, 0x61, 0x50, 0x83, 0x48,
  33624. 0x58, 0x58, 0x45, 0x33, 0x25, 0x36, 0x07, 0x42,
  33625. 0x70, 0x24, 0x07, 0x41, 0x08, 0x35, 0x00, 0x78,
  33626. 0x41, 0x47, 0x02, 0x56, 0x07, 0x14, 0x68, 0x33,
  33627. 0x55, 0x77, 0x32, 0x40, 0x55, 0x24, 0x50, 0x26,
  33628. 0x47, 0x12, 0x65, 0x58, 0x43, 0x05, 0x52, 0x55,
  33629. 0x75, 0x50, 0x18, 0x46, 0x65, 0x48, 0x03, 0x32,
  33630. 0x85, 0x31, 0x16, 0x52, 0x71, 0x57, 0x87, 0x46,
  33631. 0x76, 0x14, 0x42, 0x81, 0x28, 0x74, 0x60, 0x34,
  33632. 0x35, 0x55, 0x52, 0x16, 0x58, 0x48, 0x61, 0x75,
  33633. 0x80, 0x88, 0x15, 0x32, 0x72, 0x26, 0x31, 0x03,
  33634. 0x05, 0x03, 0x16, 0x04, 0x07, 0x37, 0x37, 0x73,
  33635. 0x43, 0x81, 0x57, 0x31, 0x88, 0x04, 0x72, 0x76,
  33636. 0x01, 0x61, 0x81, 0x17, 0x37, 0x65, 0x44, 0x38,
  33637. 0x61, 0x23, 0x16, 0x26, 0x52, 0x45, 0x00, 0x73,
  33638. 0x83, 0x63, 0x64, 0x62, 0x26, 0x74, 0x60, 0x11,
  33639. 0x81, 0x08, 0x06, 0x30, 0x36, 0x05, 0x10, 0x48,
  33640. 0x47, 0x35, 0x10, 0x85, 0x30, 0x86, 0x71, 0x38,
  33641. 0x16, 0x37, 0x6F, 0x3B, 0x1C, 0x18, 0xB1, 0xE3,
  33642. 0xE8, 0xEE, 0x83, 0x3E, 0x8D, 0x38, 0x43, 0x9E,
  33643. 0x78, 0x1C, 0xA3, 0xB8, 0x94, 0x06, 0x54, 0xEF,
  33644. 0x44, 0x6C, 0x9A, 0xAC, 0xC3, 0xF1, 0xD3, 0x0E,
  33645. 0xE0, 0x10, 0x5B, 0x8F, 0x63, 0xEB, 0x89, 0x74,
  33646. 0x6E, 0xF4, 0xBE, 0xB5, 0x4C, 0xFC, 0xE8, 0x81,
  33647. 0x2C, 0xF9, 0x47, 0xCF, 0x54, 0x54, 0xFB, 0x1C,
  33648. 0xA5, 0x5F, 0x25, 0xA0, 0xFE, 0x57, 0xF5, 0xFC,
  33649. 0xFD, 0x73, 0xB0, 0xDA, 0x04, 0xB0, 0xBF, 0x28,
  33650. 0x92, 0x92, 0xAF, 0x39, 0x74, 0x72, 0x56, 0x69,
  33651. 0xC3, 0x00, 0x03, 0xE0, 0x50, 0x9F, 0xED, 0xC8,
  33652. 0x0F, 0x6C, 0x89, 0x4B, 0xB0, 0x47, 0xC2, 0xE2,
  33653. 0xAF, 0x48, 0x5C, 0xAD, 0x68, 0xC2, 0x1D, 0x80,
  33654. 0xEF, 0x33, 0xB0, 0xC4, 0xFD, 0xA6, 0x7B, 0x85,
  33655. 0x31, 0xA1, 0x58, 0x87, 0x67, 0x54, 0x71, 0x3F,
  33656. 0xF8, 0xA8, 0xA6, 0x8D, 0x9A, 0xBD, 0xC4, 0x81,
  33657. 0x6B, 0x24, 0xB4, 0xA3, 0x6A, 0x8A, 0x2B, 0xB1,
  33658. 0xFD, 0x1C, 0x2C, 0x25, 0xC3, 0x72, 0xC4, 0xB7,
  33659. 0x75, 0xF8, 0xCC, 0x17, 0x39, 0xCF, 0x2C, 0xE9,
  33660. 0xA4, 0x54, 0x58, 0xE4, 0x1A, 0xAE, 0xC6, 0x4A,
  33661. 0xEE, 0xDE, 0x75, 0x7C, 0xE7, 0x38, 0xBC, 0xDF,
  33662. 0x4D, 0xA0, 0xEE, 0x2B, 0xDD, 0x5F, 0x80, 0x5C,
  33663. 0xCF, 0xF7, 0x2A, 0x5F, 0x73, 0x8B, 0xAC, 0x12,
  33664. 0x34, 0x2E, 0xE3, 0xF1, 0x4C, 0xB7, 0x22, 0x68,
  33665. 0xC2, 0xD6, 0x36, 0x7D, 0xF1, 0x7F, 0x20, 0x46,
  33666. 0xA2, 0x4B, 0x47, 0x4B, 0x32, 0x58, 0xF7, 0xB0,
  33667. 0x88, 0x54, 0x6C, 0x99, 0x3B, 0x0D, 0xA1, 0xE2,
  33668. 0x92, 0x92, 0xEB, 0x72, 0x1E, 0xE7, 0xE5, 0xA1,
  33669. 0xF8, 0x6E, 0x14, 0xA5, 0x39, 0xB0, 0x63, 0x6F,
  33670. 0x78, 0x82, 0xA1, 0x9C, 0x8D, 0x79, 0x02, 0x85,
  33671. 0xA6, 0xDF, 0x7D, 0xEE, 0xCE, 0x17, 0x4D, 0x63,
  33672. 0xCF, 0xF3, 0xB2, 0xFF, 0x85, 0x68, 0x81, 0xCB,
  33673. 0x38, 0x6B, 0x1B, 0x38, 0xA2, 0xE0, 0xF2, 0x4C,
  33674. 0x31, 0xE0, 0x91, 0x93, 0xDD, 0xF3, 0x71, 0x47,
  33675. 0xF2, 0x69, 0xD9, 0x4C, 0xDE, 0xF9, 0x90, 0x61,
  33676. 0x34, 0x62, 0x07, 0x71, 0x79, 0xD0, 0xDD, 0x09,
  33677. 0x32, 0x64, 0x39, 0x49, 0x93, 0x1A, 0x02, 0xBA,
  33678. 0xFA, 0x80, 0x17, 0x6E, 0xDF, 0x97, 0xB6, 0xA2,
  33679. 0x31, 0x34, 0x71, 0xF0, 0xB1, 0x9B, 0x3B, 0x59,
  33680. 0xF4, 0x3B, 0xD2, 0x2A, 0x05, 0x49, 0x3E, 0xFB,
  33681. 0x0C, 0xF8, 0xB5, 0xD7, 0xB6, 0x25, 0x2B, 0x09,
  33682. 0x8B, 0x4B, 0xFA, 0x39, 0x5B, 0xF9, 0xA2, 0x09,
  33683. 0xE9, 0xBB, 0x46, 0x01, 0x30, 0x00, 0x90, 0x32,
  33684. 0x58, 0xA6, 0x9B, 0x67, 0xF5, 0x94, 0x11, 0xC8,
  33685. 0x35, 0x95, 0xFA, 0x6E, 0x67, 0x42, 0x8D, 0x96,
  33686. 0x6D, 0x20, 0xFC, 0xD3, 0x09, 0x61, 0x11, 0x86,
  33687. 0x77, 0xC0, 0x86, 0xA3, 0x54, 0xAE, 0x6D, 0x41,
  33688. 0xEE, 0x17, 0xDC, 0xA1, 0xB0, 0xB7, 0x50, 0x43,
  33689. 0xD6, 0xCE, 0x23, 0xBD, 0xB0, 0x1E, 0x02, 0xE5,
  33690. 0x9E, 0xCF, 0xC6, 0x2E, 0x8C, 0x39, 0x71, 0xB1,
  33691. 0x45, 0x02, 0x75, 0xBA, 0x7F, 0x60, 0xB0, 0x8B,
  33692. 0x1C, 0x33, 0xBA, 0x0C, 0xFF, 0x54, 0x63, 0xE3,
  33693. 0x47, 0x5B, 0x07, 0x77, 0x77, 0xC5, 0x72, 0x24,
  33694. 0x60, 0xFA, 0xDB, 0x0B, 0xF6, 0x41, 0x82, 0x69,
  33695. 0x3C, 0x68, 0x37, 0xF5, 0xFD, 0x45, 0x4A, 0x66,
  33696. 0x6C, 0xD7, 0x01, 0x10, 0x78, 0x4A, 0xED, 0x09,
  33697. 0xAE, 0x49, 0x0A, 0x60, 0xC7, 0x78, 0x56, 0x51,
  33698. 0x15, 0xE3, 0x4A, 0xB5, 0xAE, 0xAD, 0x09, 0xD1,
  33699. 0x71, 0xA8, 0xCA, 0x3C, 0x8A, 0xE6, 0xCA, 0x39,
  33700. 0x43, 0x60, 0x56, 0x83, 0x3C, 0x58, 0x04, 0xD4,
  33701. 0xB4, 0x62, 0xDD, 0x53, 0x05, 0xC8, 0x51, 0xAF,
  33702. 0x59, 0xF6, 0x4F, 0x04, 0xC3, 0x1E, 0x69, 0xFF,
  33703. 0x82, 0xBF, 0xD7, 0x89, 0xD2, 0x30, 0x9F, 0xF2,
  33704. 0xE6, 0x38, 0x05, 0x9C, 0xD5, 0x08, 0xB8, 0x25,
  33705. 0xF3, 0x3B, 0x99, 0x85, 0x4E, 0x40, 0xF8, 0x40,
  33706. 0xF2, 0x4B, 0x5C, 0x3A, 0xA8, 0x64, 0x41, 0x92,
  33707. 0xEA, 0xCA, 0x9A, 0x7B, 0xCF, 0xBA, 0x1F, 0xDE,
  33708. 0xE0, 0x9D, 0xCA, 0xAD, 0xB4, 0x0C, 0x90, 0xFF,
  33709. 0xE1, 0x6C, 0xEC, 0xDD, 0x32, 0x38, 0x2A, 0xF7,
  33710. 0x19, 0x20, 0x39, 0xCB, 0x29, 0x67, 0x2F, 0x70,
  33711. 0x71, 0x12, 0x10, 0xB6, 0xB8, 0x3E, 0x8D, 0xFD,
  33712. 0xB5, 0xFB, 0xBD, 0xBF, 0xA8, 0xCA, 0x19, 0xC4,
  33713. 0xC6, 0xAC, 0x37, 0x31, 0xFC, 0x33, 0xC2, 0x7F,
  33714. 0xA2, 0xA2, 0x6D, 0xEB, 0x15, 0x2E, 0xA1, 0x90,
  33715. 0xF8, 0x29, 0xC6, 0x34, 0xD1, 0x39, 0x30, 0x24,
  33716. 0x1C, 0xB9, 0x26, 0xAC, 0xDD, 0xE5, 0x24, 0x9C,
  33717. 0xDD, 0x35, 0x60, 0x7E, 0x38, 0x0C, 0xC1, 0x2A,
  33718. 0x7D, 0x1E, 0xA9, 0xBA, 0xA5, 0x58, 0x4C, 0xDD,
  33719. 0x26, 0x86, 0x09, 0xDC, 0xC3, 0xB0, 0x1F, 0xCD,
  33720. 0xC9, 0xAD, 0xCB, 0x4A, 0x7E, 0x51, 0x67, 0xE5,
  33721. 0xED, 0x5A, 0xD2, 0x21, 0xDB, 0x2E, 0xAB, 0xD9,
  33722. 0x0A, 0xEC, 0xAE, 0x71, 0xFA, 0x23, 0x7A, 0xEF,
  33723. 0x98, 0xDF, 0x53, 0x89, 0x93, 0xE8, 0x71, 0xD7,
  33724. 0x35, 0xDA, 0x6B, 0x88, 0x31, 0xAF, 0x67, 0xF2,
  33725. 0x97, 0x29, 0x1C, 0x39, 0x67, 0xEB, 0xAF, 0x60,
  33726. 0xD9, 0x53, 0xC4, 0x0F, 0x7A, 0x46, 0x4E, 0xF3,
  33727. 0x2F, 0x8E, 0xAE, 0xFA, 0x64, 0x2E, 0x37, 0xDE,
  33728. 0xA9, 0x74, 0x73, 0x5D, 0xDD, 0xBB, 0x83, 0x54,
  33729. 0x27, 0xB9, 0x7A, 0x63, 0x2B, 0x19, 0x8B, 0x26,
  33730. 0x22, 0x28, 0x84, 0xA0, 0x58, 0x00, 0x2D, 0x55,
  33731. 0xEA, 0x2A, 0x80, 0x0D, 0x6C, 0x97, 0x0E, 0x8B,
  33732. 0xF7, 0x67, 0xB2, 0x8B, 0x2D, 0xDE, 0x8F, 0x58,
  33733. 0xFE, 0x97, 0x81, 0xE7, 0xE2, 0x58, 0x8D, 0x7E,
  33734. 0x1B, 0xAB, 0xE5, 0x15, 0x9D, 0x54, 0xF4, 0x00,
  33735. 0x34, 0x1D, 0x12, 0x1B, 0x03, 0x23, 0x2B, 0x06,
  33736. 0x2E, 0x8C, 0xD0, 0x0A, 0xDC, 0x19, 0xA1, 0x69,
  33737. 0x1D, 0x72, 0x91, 0xB4, 0xED, 0x0E, 0x81, 0xF7,
  33738. 0x05, 0x99, 0x84, 0xFC, 0x74, 0x0F, 0x7D, 0xF8,
  33739. 0x9B, 0x3E, 0x7F, 0x63, 0x7C, 0x73, 0xEB, 0xF5,
  33740. 0x36, 0xB3, 0x24, 0x22, 0xAA, 0x33, 0x0C, 0x30,
  33741. 0x42, 0xC3, 0xE2, 0x04, 0x6B, 0x3F, 0x2A, 0x0D,
  33742. 0xAB, 0xE8, 0x5A, 0x9A, 0x09, 0xD7, 0xB6, 0xAA,
  33743. 0x9C, 0x3E, 0xD0, 0x9E, 0xB5, 0x9B, 0x52, 0x7B,
  33744. 0xAF, 0x2D, 0x6B, 0xE0, 0x40, 0x12, 0x34, 0xBE,
  33745. 0x49, 0xAB, 0xD2, 0xC8, 0xB5, 0x89, 0x1B, 0x79,
  33746. 0xEC, 0xAE, 0x88, 0x89, 0x3C, 0x05, 0xC7, 0x75,
  33747. 0xC5, 0x84, 0xF7, 0x10, 0x49, 0x48, 0x92, 0x69,
  33748. 0x9E, 0xD5, 0x56, 0xB2, 0x1E, 0x81, 0x18, 0x78,
  33749. 0xCB, 0x93, 0x5D, 0x70, 0x3A, 0xB2, 0x67, 0xD1,
  33750. 0xCC, 0x8F, 0x83, 0x03, 0xB9, 0x64, 0x46, 0x22,
  33751. 0x78, 0x0D, 0x55, 0x67, 0x22, 0x58, 0x0E, 0x22,
  33752. 0x6B, 0xBA, 0x01, 0xD4, 0x77, 0x05, 0xA7, 0xAC,
  33753. 0xB7, 0xE5, 0xFC, 0xE6, 0x11, 0xCC, 0x92, 0x5A,
  33754. 0x8C, 0xC0, 0x08, 0x24, 0xAF, 0xCC, 0x4D, 0xBD,
  33755. 0x79, 0xD3, 0x5C, 0x52, 0x2C, 0xFF, 0x1A, 0x48,
  33756. 0xBB, 0x91, 0x59, 0x6A, 0x80, 0x32, 0x8C, 0x75,
  33757. 0x7C, 0xD2, 0xC1, 0x94, 0x94, 0xA8, 0x55, 0x4B,
  33758. 0xF2, 0x96, 0xF7, 0x86, 0xF7, 0x53, 0x4F, 0x54,
  33759. 0x74, 0x05, 0x5C, 0xEF, 0x02, 0xA0, 0x8A, 0xD1,
  33760. 0x88, 0x72, 0xEB, 0x1B, 0x82, 0xF9, 0xFB, 0xDA,
  33761. 0xBC, 0xB9, 0x90, 0x98, 0xF2, 0x4B, 0x9A, 0xA6,
  33762. 0x89, 0xD5, 0xB3, 0xD8, 0x7B, 0x94, 0xE3, 0x1F,
  33763. 0x17, 0x4F, 0xEB, 0x24, 0x06, 0x2B, 0xAB, 0x5F,
  33764. 0x27, 0x9B, 0xCD, 0xCE, 0x50, 0x06, 0x40, 0xDD,
  33765. 0x7A, 0x8C, 0x67, 0xF0, 0x8E, 0x07, 0xB4, 0x1C,
  33766. 0x3C, 0x13, 0xB2, 0x07, 0x6A, 0x38, 0x59, 0x94,
  33767. 0x2C, 0xB1, 0x72, 0xA8, 0x77, 0x5B, 0x15, 0x8F,
  33768. 0x88, 0xC4, 0x5C, 0xDC, 0x92, 0xCA, 0xC0, 0xED,
  33769. 0x02, 0xFF, 0x1D, 0x57, 0x25, 0xBE, 0x67, 0x3E,
  33770. 0x4C, 0xE8, 0x95, 0x2A, 0x80, 0xB2, 0x5D, 0xBC,
  33771. 0xFA, 0x17, 0xA9, 0x35, 0x0A, 0x6B, 0x07, 0xC8,
  33772. 0x8F, 0x88, 0x8D, 0xBC, 0x97, 0x84, 0xE2, 0x07,
  33773. 0x57, 0x92, 0x99, 0x4B, 0xE8, 0xDD, 0xD7, 0xA4,
  33774. 0x58, 0xCB, 0x61, 0xCE, 0x16, 0xFC, 0x22, 0xCD,
  33775. 0x4B, 0x1A, 0x08, 0xC9, 0xAD, 0x3D, 0xB1, 0xF2,
  33776. 0xA9, 0x1B, 0x8E, 0xD0, 0xC7, 0xBC, 0xCE, 0xF9,
  33777. 0x0A, 0x7A, 0x4D, 0xBE, 0x82, 0x0A, 0xBD, 0x6C,
  33778. 0x42, 0x99, 0xBF, 0x86, 0x65, 0x53, 0xAA, 0x04,
  33779. 0x79, 0xD6, 0x6D, 0x7E, 0x0F, 0x40, 0xFA, 0xEE,
  33780. 0xCE, 0x38, 0x3B, 0x1C, 0x2F, 0xA4, 0x45, 0xA3,
  33781. 0x78, 0x2B, 0xA0, 0x29, 0xC5, 0xAA, 0xA9, 0x09,
  33782. 0x29, 0x51, 0xDC, 0x5B, 0xB5, 0x95, 0xE4, 0xCE,
  33783. 0xC8, 0x50, 0x71, 0x2D, 0xE9, 0x32, 0x12, 0xA0,
  33784. 0x7C, 0x88, 0x6B, 0xED, 0xE4, 0x38, 0xB7, 0x92,
  33785. 0xCA, 0xE4, 0xDC, 0xD4, 0x05, 0x3B, 0x2B, 0x84,
  33786. 0x95, 0x07, 0xFF, 0xF4, 0x79, 0xFF, 0x1E, 0x73,
  33787. 0x1B, 0x8E, 0xDF, 0xA3, 0x15, 0xBD, 0x56, 0xAC,
  33788. 0xDA, 0xAD, 0x73, 0x95, 0xC2, 0xD3, 0x72, 0xA8,
  33789. 0xF0, 0x8E, 0x6C, 0xE3, 0x7D, 0xBE, 0x4C, 0x87,
  33790. 0xFC, 0x0F, 0xA6, 0x3B, 0xED, 0xA4, 0x0F, 0x4F,
  33791. 0xF1, 0x5D, 0xF2, 0x56, 0x54, 0xD1, 0xCE, 0x6C,
  33792. 0xCA, 0x1C, 0xCB, 0xC2, 0x45, 0x7F, 0x90, 0x61,
  33793. 0x0E, 0x3D, 0xCE, 0xBB, 0x5E, 0x41, 0x38, 0x2B,
  33794. 0xD4, 0x41, 0x7C, 0x67, 0x7C, 0x71, 0x95, 0x34,
  33795. 0xD7, 0xED, 0x4D, 0xAC, 0x6E, 0xF1, 0x46, 0xEA,
  33796. 0x7D, 0xA4, 0x4C, 0x69, 0x0B, 0x9C, 0x2F, 0xAA,
  33797. 0xF1, 0x17, 0x90, 0x1B, 0xF4, 0x4C, 0x03, 0xBE,
  33798. 0x9D, 0x56, 0xCE, 0x0C, 0xCF, 0xE0, 0x87, 0x44,
  33799. 0xBE, 0x2C, 0x52, 0xD3, 0xBC, 0xAE, 0x02, 0x30,
  33800. 0xC7, 0x26, 0x06, 0x88, 0xA6, 0xAA, 0x9D, 0x50,
  33801. 0xF1, 0x94, 0x58, 0xC7, 0x60, 0xF3, 0xA0, 0x6F,
  33802. 0x53, 0x66, 0x53, 0xCD, 0x1D, 0xBE, 0xD1, 0xF2,
  33803. 0x39, 0xBA, 0x1F, 0xE8, 0x40, 0x84, 0xCD, 0x1C,
  33804. 0x8F, 0x3D, 0xB7, 0xD1, 0x51, 0x00, 0xDE, 0xB8,
  33805. 0x11, 0xD9, 0x66, 0xAD, 0xD5, 0xE9, 0x33, 0x09,
  33806. 0xE1, 0xA8, 0x00, 0x58, 0x65, 0xF1, 0xC1, 0x67,
  33807. 0xB4, 0x3A, 0xA7, 0x98, 0x90, 0x6A, 0xDB, 0x91,
  33808. 0xDB, 0x4A, 0x16, 0x35, 0xDC, 0x3D, 0x69, 0xEB,
  33809. 0x7B, 0xDE, 0xCC, 0x91, 0x1B, 0x8D, 0xE6, 0x46,
  33810. 0x61, 0x8E, 0x3F, 0x4C, 0x88, 0x81, 0x85, 0x4A,
  33811. 0x73, 0x08, 0x56, 0x52, 0xAE, 0xE6, 0x4A, 0x60,
  33812. 0x4A, 0x2E, 0x0C, 0x9A, 0x93, 0x76, 0x35, 0xC9,
  33813. 0x36, 0x28, 0x0C, 0x72, 0x19, 0xAD, 0x33, 0xCF,
  33814. 0x2B, 0xFB, 0xCE, 0x1A, 0x7D, 0xAC, 0xAA, 0x75,
  33815. 0x15, 0x76, 0x81, 0x52, 0x55, 0xCC, 0xB9, 0x39,
  33816. 0x07, 0xA3, 0x39, 0x12, 0x8D, 0x6F, 0x53, 0xAF,
  33817. 0xC7, 0x14, 0x7F, 0xC7, 0x96, 0x5A, 0x49, 0x3C,
  33818. 0x5C, 0xB0, 0x26, 0x47, 0xF4, 0x9D, 0xCA, 0x23,
  33819. 0xA6, 0x7D, 0xA6, 0x61, 0xC4, 0xA3, 0x26, 0x40,
  33820. 0x0F, 0xA7, 0x27, 0x09, 0xBC, 0x39, 0xFD, 0xA7,
  33821. 0x75, 0x38, 0x74, 0xD0, 0x9D, 0x29, 0x15, 0x97,
  33822. 0xDE, 0x25, 0x60, 0x4D, 0x19, 0x36, 0x04, 0xFB,
  33823. 0xA5, 0x2C, 0xB0, 0xC8, 0xB5, 0xFE, 0xE5, 0x94,
  33824. 0x7C, 0xE2, 0x1F, 0x84, 0xBB, 0xFB, 0x78, 0x9E,
  33825. 0xA5, 0x7C, 0x5D, 0x4A, 0xB2, 0x48, 0x6F, 0x6E,
  33826. 0x67, 0x95, 0x16, 0x5F, 0x01, 0x2A, 0xF8, 0x70,
  33827. 0x95, 0xCB, 0x06, 0x93, 0x26, 0x6E, 0x7A, 0x75,
  33828. 0xB5, 0xE5, 0x4E, 0x27, 0x1D, 0x8B, 0x30, 0xA6,
  33829. 0x67, 0x67, 0xD6, 0xE2, 0xD6, 0xD1, 0x99, 0xA4,
  33830. 0x55, 0x73, 0x19, 0x32, 0xF6, 0x0B, 0x6B, 0x4A,
  33831. 0xEE, 0x23, 0x33, 0x38, 0x30, 0x68, 0x6F, 0x8E,
  33832. 0x60, 0xA9, 0x60, 0x97, 0x3E, 0xEA, 0x5D, 0xE1,
  33833. 0x40, 0x6F, 0x0C, 0x76, 0x84, 0xCF, 0xAF, 0x86,
  33834. 0x8D, 0x36, 0xE5, 0x7D, 0xAE, 0x9A, 0x13, 0x70,
  33835. 0x22, 0x2A, 0x31, 0xFE, 0xC2, 0xFB, 0xE1, 0x58,
  33836. 0xA5, 0x4E, 0xEF, 0x10, 0x5B, 0x5E, 0xD4, 0x39,
  33837. 0xFC, 0xF9, 0x15, 0x64, 0x78, 0x43, 0x7D, 0x03,
  33838. 0x9F, 0x5B, 0xCB, 0x86, 0xD2, 0xEF, 0x28, 0xBD,
  33839. 0x14, 0xCB, 0x8A, 0x04, 0x1D, 0x59, 0x23, 0x53,
  33840. 0x4D, 0x13, 0xF9, 0x93, 0xFE, 0x19, 0x9C, 0xC3,
  33841. 0x3F, 0xD9, 0xC1, 0x12, 0x94, 0x84, 0x13, 0x95,
  33842. 0x8F, 0xD9, 0x10, 0xAB, 0x37, 0x69, 0x08, 0x04,
  33843. 0x4A, 0x97, 0x82, 0x28, 0x75, 0xBB, 0xC9, 0xF4,
  33844. 0x3F, 0x19, 0x6B, 0x00, 0x4C, 0x56, 0x16, 0x1F,
  33845. 0x50, 0x82, 0xD1, 0x45, 0xFF, 0x0C, 0x37, 0x28,
  33846. 0x04, 0xBB, 0x6C, 0x00, 0x97, 0x3A, 0x79, 0x2D,
  33847. 0x9A, 0xB9, 0xA5, 0x16, 0x52, 0x02, 0xA3, 0x86,
  33848. 0x81, 0xAA, 0x3A, 0x31, 0xE5, 0xB5, 0x44, 0x2D,
  33849. 0x34, 0xE2, 0x7A, 0xD8, 0xFE, 0xA1, 0x36, 0xC0,
  33850. 0x36, 0x65, 0x73, 0x12, 0x9F, 0x61, 0x3F, 0x59,
  33851. 0xC9, 0x68, 0xB6, 0x34, 0x41, 0x40, 0x25, 0xD6,
  33852. 0xE7, 0xAD, 0x25, 0x7D, 0xCB, 0xF1, 0x2A, 0xD8,
  33853. 0x53, 0x48, 0x9D, 0xBF, 0xB5, 0xD5, 0x61, 0x18,
  33854. 0x0E, 0x2A, 0x21, 0x3E, 0x61, 0x18, 0x07, 0x8E,
  33855. 0x6F, 0x9A, 0x96, 0xA8, 0x61, 0xFE, 0x8D, 0x66,
  33856. 0x1A, 0x21, 0x99, 0xD9, 0x60, 0x8B, 0xAC, 0x85,
  33857. 0x84, 0x3D, 0x41, 0xF9, 0x93, 0x35, 0x24, 0x32,
  33858. 0xFF, 0xC0, 0x8A, 0xFA, 0xBC, 0xA7, 0x85, 0x57,
  33859. 0x3C, 0x16, 0x83, 0xAE, 0x90, 0xDE, 0x40, 0x12,
  33860. 0xE4, 0x2B, 0xA2, 0x47, 0xA4, 0x92, 0x73, 0x54,
  33861. 0x6C, 0xA5, 0xB7, 0xEE, 0x62, 0xEA, 0x62, 0x37,
  33862. 0xD9, 0xD7, 0x73, 0x58, 0x43, 0xDB, 0x20, 0x60,
  33863. 0x8C, 0x4F, 0x87, 0x58, 0xB2, 0x2B, 0xC3, 0x40,
  33864. 0xB0, 0xC1, 0xB6, 0xB6, 0xA9, 0xCD, 0xCC, 0x05,
  33865. 0x4F, 0x38, 0x5F, 0x08, 0xB3, 0x3B, 0x08, 0x4D,
  33866. 0x78, 0x6B, 0x0D, 0x40, 0x46, 0xB9, 0x20, 0xDE,
  33867. 0x29, 0x6F, 0x23, 0x96, 0xDA, 0x02, 0xF5, 0x1C,
  33868. 0x1A, 0x1A, 0x36, 0xA3, 0x3A, 0xFA, 0x1D, 0x80,
  33869. 0x36, 0x3C, 0xF6, 0xB4, 0xDC, 0x2C, 0x88, 0x54,
  33870. 0xF7, 0x86, 0xC6, 0xF2, 0x15, 0xF8, 0x85, 0x33,
  33871. 0xFB, 0x21, 0x20, 0x59, 0xCE, 0x60, 0x4B, 0xE8,
  33872. 0xF1, 0xB7, 0x54, 0x17, 0x1E, 0x83, 0xCD, 0x82,
  33873. 0x39, 0x40, 0x14, 0x31, 0xEC, 0x89, 0xC8, 0xE2,
  33874. 0x6A, 0xAE, 0x3F, 0x49, 0x5B, 0x38, 0xE7, 0xCD,
  33875. 0xE2, 0xF6, 0xEF, 0x90, 0x51, 0x10, 0x83, 0x79,
  33876. 0x27, 0x80, 0x2F, 0x45, 0x78, 0x67, 0xAF, 0xF4,
  33877. 0x65, 0x95, 0x2D, 0xFE, 0x00, 0xF3, 0x2A, 0x60,
  33878. 0x00, 0xF7, 0x26, 0xFA, 0x3C, 0xAD, 0xA9, 0xAF,
  33879. 0xCA, 0xF6, 0x69, 0x48, 0x03, 0xBE, 0x18, 0x73,
  33880. 0x54, 0x06, 0x06, 0x3E, 0x4E, 0xAD, 0xFC, 0x8B,
  33881. 0xC3, 0x43, 0x24, 0x5D, 0xE9, 0xDE, 0x78, 0xDC,
  33882. 0xD0, 0xA7, 0x04, 0x77, 0xF0, 0x0D, 0xA3, 0x37,
  33883. 0x8C, 0x5F, 0x8B, 0xDF, 0xBE, 0x90, 0x1F, 0xA6,
  33884. 0xB3, 0x17, 0x9D, 0x68, 0x36, 0x45, 0x11, 0x60,
  33885. 0xFF, 0xF9, 0xBA, 0xDA, 0x80, 0xAA, 0x37, 0x57,
  33886. 0xDD, 0x34, 0x30, 0x42, 0x7A, 0x9C, 0x86, 0xB4,
  33887. 0x91, 0x30, 0xB8, 0xC0, 0xC4, 0x29, 0x15, 0x31,
  33888. 0xF3, 0x9A, 0xB0, 0xCD, 0xAC, 0x8C, 0x7C, 0x8C,
  33889. 0x4A, 0xDC, 0x76, 0xB6, 0x31, 0x30, 0xDE, 0x2D,
  33890. 0x81, 0x04, 0xC7, 0x48, 0x73, 0x69, 0x02, 0x40,
  33891. 0x30, 0x19, 0x66, 0x94, 0x21, 0x65, 0x13, 0x18,
  33892. 0xC2, 0x09, 0x14, 0x5F, 0xC4, 0x2F, 0xC4, 0xD6,
  33893. 0xA6, 0x05, 0x37, 0xAF, 0x72, 0x0C, 0x47, 0x02,
  33894. 0x29, 0x95, 0x08, 0x9D, 0xC9, 0x07, 0x31, 0x38,
  33895. 0xA9, 0xB5, 0xDA, 0x21, 0x76, 0x1D, 0x84, 0xD0,
  33896. 0x15, 0xAF, 0x2A, 0xA3, 0x69, 0x0A, 0xE9, 0x4F,
  33897. 0x75, 0x8A, 0x50, 0xA5, 0x11, 0xD4, 0x5F, 0xAF,
  33898. 0x70, 0x43, 0xCB, 0xD7, 0x03, 0x9E, 0xB0, 0xBD,
  33899. 0x19, 0x47, 0x94, 0x58, 0x22, 0x86, 0xC6, 0xE3,
  33900. 0x62, 0xD8, 0x63, 0x05, 0xD9, 0xE2, 0xE5, 0x4A,
  33901. 0x04, 0x54, 0x5A, 0x55, 0x25, 0xAD, 0x15, 0x5C,
  33902. 0x4B, 0x71, 0x25, 0xE1, 0x50, 0xE3, 0x62, 0x1B,
  33903. 0xD2, 0x43, 0x28, 0xD2, 0x84, 0xE4, 0xE2, 0x05,
  33904. 0xE3, 0x01, 0x4C, 0x8F, 0x38, 0x17, 0x49, 0xFD,
  33905. 0x3B, 0x52, 0x1A, 0x55, 0xB3, 0x1D, 0x69, 0x83,
  33906. 0xAB, 0x9E, 0xC4, 0x73, 0xEE, 0x64, 0x7A, 0x73,
  33907. 0x19, 0xEF, 0xCD, 0x7D, 0xB7, 0xF4, 0x2E, 0xCB,
  33908. 0x55, 0x2A, 0x8A, 0xCC, 0x8F, 0xF8, 0x4E, 0xFB,
  33909. 0xD2, 0x63, 0x8F, 0xF1, 0x10, 0x89, 0x02, 0x93,
  33910. 0x3E, 0xAC, 0xA4, 0xB4, 0x89, 0xC7, 0xF7, 0x8B,
  33911. 0x3E, 0xE1, 0xE8, 0x93, 0xB9, 0x8E, 0x36, 0x25,
  33912. 0xC1, 0xC0, 0xD9, 0x44, 0x81, 0xC0, 0x99, 0x3C,
  33913. 0x2B, 0x89, 0xF7, 0xDF, 0xDB, 0xD8, 0xCC, 0x84,
  33914. 0xE6, 0xFF, 0xFE, 0xAC, 0x21, 0x16, 0xF1, 0xE2,
  33915. 0xEF, 0x0A, 0x32, 0xA7, 0xDE, 0x87, 0x51, 0xEC,
  33916. 0xB1, 0x0C, 0x0B, 0xC7, 0x07, 0xD9, 0x9A, 0xF8,
  33917. 0xE8, 0xB0, 0xFE, 0xA5, 0x67, 0xAF, 0x53, 0x9F,
  33918. 0xEF, 0x23, 0xEF, 0x7D, 0xFF, 0xA8, 0x8E, 0xDE,
  33919. 0x97, 0x93, 0x32, 0xA6, 0x7C, 0xCF, 0x49, 0xBC,
  33920. 0x36, 0x0D, 0x88, 0x90, 0x89, 0x39, 0x76, 0xA8,
  33921. 0x82, 0x19, 0x02, 0xB6, 0x02, 0x82, 0xFE, 0xED,
  33922. 0x9C, 0x28, 0x8D, 0xB0, 0x1E, 0x2B, 0x2A, 0xCF,
  33923. 0xF3, 0x94, 0xFF, 0x66, 0x33, 0x93, 0x31, 0xD6,
  33924. 0xFC, 0xAF, 0xE7, 0xC5, 0x98, 0x01, 0x46, 0xCD,
  33925. 0xCB, 0xC4, 0x41, 0x13, 0x6D, 0x42, 0xF5, 0x13,
  33926. 0xDF, 0xF9, 0x97, 0x65, 0xD4, 0x7B, 0x6E, 0x10,
  33927. 0x79, 0x5D, 0x5A, 0x82, 0xA2, 0x49, 0x53, 0xA7,
  33928. 0x6D, 0x9C, 0xDD, 0x0A, 0x80, 0x98, 0x58, 0x07,
  33929. 0x30, 0xBF, 0x0B, 0x30, 0xAC, 0x24, 0x9E, 0xA0,
  33930. 0xE8, 0xE4, 0x7A, 0x0D, 0xD0, 0x50, 0x82, 0xAE,
  33931. 0xBB, 0xEC, 0x15, 0x30, 0x2A, 0xF2, 0xA7, 0xA6,
  33932. 0x6A, 0xC8, 0xAE, 0x1E, 0x14, 0x80, 0x7C, 0x18,
  33933. 0xE7, 0x2B, 0x88, 0x65, 0xB7, 0x93, 0x12, 0xB3,
  33934. 0xC1, 0x2A, 0x20, 0xAD, 0x3B, 0x2E, 0x84, 0xC4,
  33935. 0x0D, 0xA7, 0x62, 0x5C, 0x79, 0x52, 0x5D, 0x59,
  33936. 0xA4, 0x69, 0x5C, 0x26, 0xFD, 0x4F, 0x80, 0xCC,
  33937. 0xFE, 0x8E, 0x70, 0x72, 0xB1, 0x41, 0xE1, 0x75,
  33938. 0x53, 0x51, 0xCF, 0x4C, 0x0B, 0x57, 0xF2, 0xB8,
  33939. 0x59, 0x76, 0xE6, 0xEF, 0x6D, 0x74, 0xA6, 0x73,
  33940. 0x69, 0x7F, 0x7C, 0xB2, 0x35, 0xFE, 0x8A, 0x02,
  33941. 0x2F, 0xBE, 0x7C, 0x4D, 0x02, 0xBE, 0x8F, 0xFB,
  33942. 0x7A, 0x58, 0x45, 0xEC, 0xBA, 0x1B, 0xC6, 0xB9,
  33943. 0x8D, 0xF5, 0xB0, 0x82, 0xD1, 0xB4, 0x97, 0x86,
  33944. 0x9B, 0x33, 0x54, 0x49, 0x5B, 0x88, 0xD9, 0xB5,
  33945. 0xD0, 0x93, 0x8A, 0x00, 0x5D, 0x0F, 0x37, 0x88,
  33946. 0x57, 0xE3, 0xFA, 0x7E, 0x7B, 0xFA, 0x43, 0x74,
  33947. 0x8D, 0x64, 0x07, 0xD7, 0x07, 0x85, 0x4D, 0x49,
  33948. 0xBC, 0x83, 0xF5, 0xD4, 0x95, 0x3E, 0x3E, 0x09,
  33949. 0x65, 0xF3, 0xFC, 0x88, 0xA7, 0xF0, 0x46, 0x61,
  33950. 0x44, 0x7D, 0x76, 0xED, 0xC9, 0x8D, 0x0F, 0x8D,
  33951. 0xDA, 0x0D, 0x01, 0xC8, 0xB1, 0xA8, 0x9B, 0x4A,
  33952. 0xF0, 0xA3, 0x88, 0x54, 0xC1, 0xD6, 0x52, 0x97
  33953. };
  33954. #endif /* WOLFSSL_NO_ML_DSA_65 */
  33955. #ifndef WOLFSSL_NO_ML_DSA_87
  33956. static const byte seed_87[] = {
  33957. 0x22, 0x5F, 0x77, 0x07, 0x5E, 0x66, 0xCE, 0x1C,
  33958. 0x99, 0xBA, 0x95, 0xB4, 0xFC, 0xDF, 0x25, 0x8B,
  33959. 0xBB, 0x6F, 0xA5, 0xFE, 0x9C, 0x34, 0x9F, 0x0F,
  33960. 0xDE, 0x3F, 0x71, 0xD5, 0x33, 0x9F, 0x6F, 0xD8
  33961. };
  33962. static const byte pk_87[] = {
  33963. 0x8C, 0x52, 0x4B, 0xD9, 0xAC, 0x48, 0x5C, 0xC6,
  33964. 0x9A, 0xA0, 0x75, 0x64, 0xE1, 0x4F, 0x0F, 0x60,
  33965. 0x13, 0x0E, 0xDE, 0x34, 0x08, 0xA5, 0xD4, 0x81,
  33966. 0xFD, 0x76, 0xC2, 0x51, 0x74, 0x75, 0xA8, 0xFB,
  33967. 0x24, 0xBF, 0x9E, 0x97, 0x9C, 0xD2, 0x3E, 0xDA,
  33968. 0x8A, 0x1B, 0xB6, 0x76, 0xDA, 0x7D, 0x7F, 0x44,
  33969. 0xAD, 0x6B, 0xB9, 0xB0, 0x70, 0xD3, 0xD6, 0x44,
  33970. 0x7F, 0xBE, 0x6C, 0x0C, 0x71, 0x37, 0xC6, 0xFB,
  33971. 0x7B, 0x39, 0x83, 0x63, 0x9C, 0x41, 0x5C, 0xF2,
  33972. 0xC9, 0x15, 0xFF, 0xD4, 0x18, 0xEA, 0xA1, 0x4D,
  33973. 0xA9, 0xD1, 0xAD, 0x3C, 0x09, 0x8E, 0xA9, 0x05,
  33974. 0x34, 0x6C, 0xAA, 0x75, 0x78, 0xF8, 0x6B, 0x6E,
  33975. 0x52, 0xE6, 0x57, 0x55, 0x16, 0xF4, 0x92, 0x3E,
  33976. 0x74, 0x3F, 0x96, 0xA3, 0x2A, 0xD0, 0x0E, 0xEE,
  33977. 0xA1, 0xCE, 0x8A, 0x33, 0xF4, 0x87, 0xB9, 0xF3,
  33978. 0x22, 0x5D, 0x2D, 0x84, 0xCD, 0x27, 0x57, 0xCC,
  33979. 0xCF, 0xE6, 0xA3, 0x66, 0x24, 0x53, 0x0E, 0x52,
  33980. 0x8A, 0x2F, 0x64, 0xFC, 0xE7, 0x04, 0xE7, 0xA7,
  33981. 0x6C, 0x2E, 0x6A, 0xDC, 0x00, 0xEF, 0x9B, 0xEC,
  33982. 0x91, 0x07, 0xB9, 0x69, 0x8F, 0x11, 0x59, 0xFC,
  33983. 0x52, 0xEF, 0x4C, 0x36, 0x5A, 0xFD, 0xB1, 0x50,
  33984. 0xED, 0xC3, 0x43, 0x5E, 0x03, 0xBB, 0x70, 0x26,
  33985. 0x00, 0x6E, 0x5A, 0x55, 0x13, 0x51, 0xA4, 0xB1,
  33986. 0x5F, 0xB8, 0x9F, 0xD2, 0xE9, 0x98, 0x38, 0xE8,
  33987. 0xCF, 0x41, 0x73, 0xFD, 0x0D, 0xF1, 0xF6, 0x80,
  33988. 0x89, 0xE1, 0x51, 0x8D, 0xD4, 0xB5, 0x79, 0x27,
  33989. 0x76, 0xBD, 0xD9, 0x2F, 0xC7, 0xC7, 0x9B, 0xC7,
  33990. 0x99, 0x7F, 0x78, 0x84, 0xD2, 0xB8, 0x80, 0xC5,
  33991. 0xD2, 0xB7, 0xEE, 0xC8, 0x0A, 0xFE, 0x35, 0x59,
  33992. 0x84, 0x5D, 0x39, 0x08, 0x39, 0xBE, 0x5E, 0xBF,
  33993. 0x95, 0x93, 0xA7, 0x3E, 0xD0, 0x1E, 0xF6, 0x7D,
  33994. 0x50, 0x3F, 0xFB, 0x74, 0x47, 0x04, 0xA2, 0xDC,
  33995. 0x49, 0x48, 0x76, 0x2B, 0xC8, 0x43, 0x45, 0x75,
  33996. 0x72, 0x84, 0x4D, 0x15, 0x74, 0xE3, 0xEB, 0x37,
  33997. 0x83, 0x0A, 0x3B, 0x7C, 0xD4, 0x02, 0xC7, 0x6E,
  33998. 0xD5, 0xB4, 0xFC, 0x15, 0xF0, 0x5E, 0x76, 0x03,
  33999. 0x4C, 0xBB, 0x6A, 0x29, 0xDE, 0xBC, 0x7E, 0x2B,
  34000. 0x34, 0xB2, 0x14, 0x2A, 0x57, 0xCF, 0x1B, 0x39,
  34001. 0x73, 0xE5, 0x8B, 0xFF, 0x47, 0x50, 0x42, 0xDC,
  34002. 0x22, 0x6C, 0x7E, 0x13, 0x71, 0xF3, 0x37, 0x51,
  34003. 0x40, 0xF2, 0x90, 0x57, 0xAC, 0xB4, 0x64, 0x7C,
  34004. 0x5F, 0x92, 0x6D, 0x3F, 0xDC, 0xCC, 0xC8, 0xD2,
  34005. 0xE1, 0x6B, 0x81, 0xA9, 0xED, 0xCD, 0x0C, 0x8B,
  34006. 0x5B, 0x2E, 0x11, 0x89, 0x87, 0x42, 0x4B, 0xEC,
  34007. 0xAD, 0x40, 0xA5, 0xE5, 0xB4, 0x6D, 0x1C, 0xB4,
  34008. 0x01, 0x0A, 0x8E, 0x9F, 0x6F, 0x25, 0x92, 0x5D,
  34009. 0xFE, 0x6B, 0x6F, 0x24, 0x64, 0x5F, 0x9C, 0x88,
  34010. 0x86, 0x96, 0xE8, 0x79, 0x64, 0x5B, 0x6A, 0x3A,
  34011. 0x76, 0x21, 0x90, 0xCC, 0xB7, 0xD6, 0x26, 0x9D,
  34012. 0x35, 0x54, 0x79, 0xDF, 0x71, 0x90, 0x55, 0x2A,
  34013. 0x38, 0x52, 0xD1, 0xE9, 0x56, 0x73, 0xE7, 0x19,
  34014. 0x44, 0x6A, 0xD3, 0x10, 0x24, 0xB9, 0x4B, 0xF8,
  34015. 0xBB, 0xC9, 0x7B, 0x04, 0x66, 0x39, 0xCE, 0x12,
  34016. 0x3F, 0xDE, 0xC3, 0x75, 0xAF, 0x9F, 0x8D, 0x4C,
  34017. 0xF7, 0x16, 0x9B, 0xEB, 0x5F, 0xE5, 0x1B, 0xBF,
  34018. 0x82, 0x2C, 0x53, 0xBA, 0x2D, 0x98, 0xA4, 0xA0,
  34019. 0x14, 0xA2, 0xDE, 0x69, 0x7F, 0x03, 0x3C, 0x9E,
  34020. 0x4A, 0x57, 0xC6, 0xED, 0xF6, 0x10, 0x6A, 0x76,
  34021. 0x2A, 0x81, 0x92, 0x9F, 0x3E, 0xF0, 0xFD, 0xE9,
  34022. 0xB7, 0xB3, 0x8A, 0xF6, 0x1A, 0x19, 0x9A, 0x16,
  34023. 0x0F, 0x09, 0x45, 0xBD, 0xBB, 0x96, 0x7C, 0x72,
  34024. 0x40, 0xFE, 0x94, 0xBD, 0xE1, 0x60, 0x50, 0x53,
  34025. 0x13, 0xC9, 0x2B, 0xFA, 0x52, 0x40, 0xA2, 0xA7,
  34026. 0xF0, 0x8C, 0x85, 0x78, 0xDB, 0xD6, 0x7F, 0x21,
  34027. 0x39, 0xB5, 0x06, 0x72, 0xEE, 0x99, 0xA1, 0xBD,
  34028. 0x78, 0x1F, 0xA4, 0xE9, 0x54, 0xF4, 0xFA, 0xDF,
  34029. 0xA7, 0x9E, 0xDD, 0x8E, 0xB1, 0xCF, 0xA8, 0x48,
  34030. 0x84, 0x5D, 0x70, 0xCB, 0x2D, 0xA9, 0x66, 0x09,
  34031. 0x0B, 0x75, 0x75, 0xA2, 0x32, 0xFE, 0xDF, 0x96,
  34032. 0x33, 0x84, 0xA7, 0x84, 0x48, 0x1A, 0xFA, 0x82,
  34033. 0x79, 0x0A, 0x87, 0xE1, 0x1F, 0x11, 0x74, 0xD4,
  34034. 0x3C, 0xC0, 0x8D, 0x4F, 0xD2, 0x5D, 0xBB, 0x40,
  34035. 0x10, 0xB2, 0x6F, 0x23, 0xD2, 0xD6, 0xF4, 0xA5,
  34036. 0x87, 0xEF, 0x7D, 0xE8, 0xC6, 0xF7, 0xC6, 0x0F,
  34037. 0xF9, 0x6F, 0xF8, 0x4C, 0x39, 0xE4, 0x82, 0x1E,
  34038. 0x1E, 0x6A, 0x80, 0x2F, 0xEC, 0x22, 0xD6, 0xA0,
  34039. 0xAA, 0xB6, 0x2C, 0xCB, 0x16, 0x43, 0x68, 0xC2,
  34040. 0x27, 0xF6, 0xA2, 0x31, 0x62, 0x66, 0xEC, 0x2F,
  34041. 0xFF, 0x8D, 0xB4, 0x19, 0x51, 0x19, 0xA0, 0x8C,
  34042. 0x67, 0xE2, 0x04, 0x04, 0xB9, 0x1F, 0x08, 0x70,
  34043. 0x9E, 0xAA, 0xC2, 0xDE, 0xCB, 0x96, 0x19, 0x8F,
  34044. 0x02, 0x74, 0x10, 0xCC, 0x1B, 0x82, 0x5D, 0x9C,
  34045. 0x07, 0x00, 0xE5, 0xD7, 0x04, 0x51, 0xBA, 0x7F,
  34046. 0x67, 0xF9, 0x64, 0x0C, 0xA3, 0x6B, 0xF3, 0x12,
  34047. 0x21, 0x80, 0x68, 0xD6, 0xA2, 0xCA, 0xFF, 0x59,
  34048. 0x33, 0x43, 0x7D, 0x67, 0xBF, 0xD4, 0x88, 0x4A,
  34049. 0x6E, 0x92, 0xBA, 0x41, 0xE1, 0x28, 0xDA, 0xEB,
  34050. 0xE1, 0xEA, 0x25, 0x60, 0xE1, 0x2F, 0xED, 0x2C,
  34051. 0xD4, 0x4B, 0xC9, 0x4E, 0x9E, 0x9D, 0xFA, 0xBB,
  34052. 0xF9, 0x61, 0x41, 0x4C, 0x24, 0x24, 0xFC, 0x9B,
  34053. 0x62, 0xFE, 0x73, 0x74, 0xF6, 0xB8, 0x9B, 0xA9,
  34054. 0x02, 0x96, 0xF4, 0x90, 0x18, 0xA7, 0xF5, 0x49,
  34055. 0xC1, 0xA3, 0x94, 0xB8, 0xED, 0xBD, 0x0B, 0xF3,
  34056. 0xDB, 0xF3, 0xBC, 0x10, 0x6A, 0x6B, 0x3F, 0x79,
  34057. 0x07, 0xF2, 0x11, 0x09, 0xD5, 0x42, 0x8F, 0xA9,
  34058. 0x09, 0x94, 0xBE, 0xF2, 0x0D, 0x3A, 0x91, 0x33,
  34059. 0x01, 0x31, 0x34, 0xBF, 0x0A, 0xCA, 0xF1, 0x3E,
  34060. 0x66, 0x18, 0xA6, 0x69, 0xEC, 0xEA, 0xC5, 0xE9,
  34061. 0x8B, 0x80, 0xFE, 0x4D, 0x93, 0x7B, 0xD4, 0xE5,
  34062. 0x74, 0x90, 0xFA, 0xFD, 0xCE, 0x45, 0xE8, 0xD7,
  34063. 0xD8, 0x8F, 0x08, 0x8B, 0x3A, 0xA8, 0x01, 0xA2,
  34064. 0xB4, 0xE5, 0xF2, 0x29, 0x41, 0x02, 0xBD, 0xCB,
  34065. 0xF9, 0x4A, 0x62, 0x54, 0x99, 0x94, 0x61, 0xB7,
  34066. 0x8F, 0xA5, 0x8A, 0x7F, 0xDC, 0xAD, 0xD2, 0xF2,
  34067. 0x28, 0x1E, 0xF3, 0x18, 0xAE, 0x21, 0x81, 0xF7,
  34068. 0xE9, 0xE5, 0xBF, 0x2B, 0xC2, 0x98, 0x24, 0xB1,
  34069. 0x45, 0x56, 0x57, 0x31, 0xA1, 0x48, 0xAB, 0x39,
  34070. 0xC2, 0x04, 0x29, 0x1B, 0x5B, 0xD3, 0x23, 0x35,
  34071. 0xCC, 0x5A, 0x58, 0x10, 0x11, 0x5B, 0xD5, 0x88,
  34072. 0xC2, 0x60, 0x37, 0x3D, 0x1C, 0x1C, 0x7B, 0x09,
  34073. 0x95, 0xB5, 0x05, 0x12, 0xD8, 0x52, 0x8D, 0xF5,
  34074. 0xBD, 0x4A, 0xA5, 0x45, 0x6F, 0x3D, 0x55, 0x9D,
  34075. 0x90, 0xAD, 0xD7, 0xA9, 0xD0, 0x25, 0x0B, 0xD7,
  34076. 0x55, 0x11, 0x5C, 0x60, 0xBF, 0xBD, 0xFB, 0x9D,
  34077. 0x2A, 0xCE, 0x4F, 0xE6, 0xB8, 0x36, 0x3A, 0x4D,
  34078. 0xE7, 0xB6, 0xFF, 0x6B, 0xD8, 0xBA, 0xD4, 0xEE,
  34079. 0x95, 0x9A, 0x0A, 0x47, 0xD4, 0x76, 0xE0, 0xF7,
  34080. 0xAC, 0x02, 0xB6, 0xA8, 0x10, 0x1E, 0xA5, 0x98,
  34081. 0xC0, 0xF4, 0x68, 0x5E, 0x55, 0xC1, 0x67, 0xCD,
  34082. 0x16, 0x31, 0xBD, 0xA2, 0x86, 0xF3, 0xF8, 0xC0,
  34083. 0xED, 0x4A, 0xFF, 0xE8, 0xF5, 0x2C, 0xFA, 0xD2,
  34084. 0x06, 0x78, 0x6D, 0x34, 0xBE, 0xF9, 0x15, 0x84,
  34085. 0x6D, 0xE5, 0x5F, 0xA4, 0xAC, 0x84, 0x3B, 0x3A,
  34086. 0xA6, 0x2D, 0xC2, 0x01, 0xE0, 0x63, 0x92, 0xC7,
  34087. 0x77, 0xB5, 0x4E, 0x2C, 0x40, 0x90, 0x48, 0xAF,
  34088. 0x8B, 0xE9, 0x6C, 0x1E, 0xEE, 0x16, 0x8F, 0x4E,
  34089. 0x4F, 0xFF, 0x35, 0x15, 0xE5, 0x51, 0xF4, 0xB2,
  34090. 0x23, 0x1C, 0x6A, 0xCE, 0x05, 0xDC, 0xDC, 0xAD,
  34091. 0x7F, 0x9D, 0xDA, 0xB3, 0x0C, 0xAD, 0x9C, 0x62,
  34092. 0x68, 0xD6, 0x84, 0x00, 0x76, 0xFF, 0xD3, 0x01,
  34093. 0x18, 0xB0, 0xC4, 0xE5, 0xE5, 0x0D, 0x87, 0x8E,
  34094. 0xAF, 0x77, 0xEE, 0xCB, 0x56, 0x88, 0x7F, 0xED,
  34095. 0xC5, 0x7C, 0x54, 0xD6, 0x28, 0x46, 0xE0, 0x8C,
  34096. 0xE6, 0x87, 0xF2, 0x4D, 0x0D, 0x2F, 0x12, 0x62,
  34097. 0x06, 0xDF, 0xB2, 0x4E, 0x03, 0x04, 0x78, 0x0B,
  34098. 0x03, 0x4C, 0xCE, 0x86, 0xD1, 0xCD, 0x53, 0x00,
  34099. 0xED, 0xC6, 0xF8, 0x9A, 0xCB, 0x59, 0x14, 0xA6,
  34100. 0x0C, 0x87, 0x35, 0x92, 0x66, 0x0D, 0x02, 0xA9,
  34101. 0xEF, 0x0D, 0x7D, 0xC6, 0x45, 0xF3, 0x11, 0xEF,
  34102. 0x1F, 0x55, 0x72, 0x1F, 0x1B, 0x45, 0xD2, 0xE4,
  34103. 0x8F, 0x3F, 0x9F, 0xEB, 0x27, 0x02, 0xD8, 0x2C,
  34104. 0xEF, 0xAD, 0x7E, 0x7E, 0x10, 0xDD, 0x91, 0x5E,
  34105. 0x39, 0x06, 0x7C, 0x39, 0xEA, 0x61, 0xB9, 0xCC,
  34106. 0xF1, 0x45, 0x56, 0x81, 0x53, 0x55, 0x42, 0xD4,
  34107. 0x37, 0x0F, 0x53, 0xF0, 0x7F, 0xA0, 0xC6, 0x50,
  34108. 0x9B, 0x1D, 0xC6, 0x7E, 0x9F, 0x1D, 0x89, 0x3B,
  34109. 0xEB, 0x85, 0x59, 0x6D, 0x9C, 0x12, 0xEE, 0xAC,
  34110. 0xFC, 0xAE, 0xC0, 0xAE, 0x5F, 0xD4, 0x9C, 0x62,
  34111. 0xE7, 0x09, 0x8C, 0xFA, 0x80, 0x1A, 0x19, 0x09,
  34112. 0x0F, 0x8D, 0x68, 0x9E, 0x45, 0x33, 0xE2, 0x58,
  34113. 0x7B, 0xEF, 0xC7, 0x6A, 0xDC, 0x38, 0x33, 0x3E,
  34114. 0x5C, 0x53, 0xB5, 0x99, 0xDB, 0x04, 0xA7, 0xEA,
  34115. 0xFB, 0x07, 0x9B, 0x25, 0x47, 0xED, 0xAC, 0x5A,
  34116. 0xAA, 0x1E, 0xE5, 0x23, 0xDE, 0x64, 0xE5, 0x87,
  34117. 0x46, 0x8C, 0x41, 0x52, 0xC9, 0x4F, 0x90, 0x48,
  34118. 0x1C, 0xAA, 0xA6, 0xB0, 0x3A, 0x1E, 0xC9, 0x08,
  34119. 0xF7, 0x82, 0x71, 0x13, 0x76, 0x6B, 0x9E, 0x52,
  34120. 0x22, 0x32, 0xE0, 0xC6, 0xF7, 0xD7, 0x4C, 0xBD,
  34121. 0xC3, 0x1C, 0x18, 0xAF, 0xA0, 0x12, 0xD3, 0x22,
  34122. 0x6A, 0xFC, 0x71, 0x8A, 0x64, 0x24, 0xAC, 0x19,
  34123. 0x4E, 0x85, 0x3C, 0x51, 0xE6, 0xA3, 0xAD, 0xA9,
  34124. 0x59, 0x94, 0xD2, 0x7F, 0xC4, 0x9D, 0x93, 0x5B,
  34125. 0x51, 0xD7, 0xF3, 0x03, 0xE7, 0x7D, 0x5B, 0x13,
  34126. 0x0E, 0xCD, 0x7D, 0x0F, 0x77, 0x3E, 0x84, 0xD7,
  34127. 0x4E, 0x69, 0x57, 0x1B, 0x73, 0x99, 0xC9, 0x4D,
  34128. 0xC0, 0x19, 0x6B, 0x9D, 0x5F, 0xBA, 0x69, 0xEE,
  34129. 0x11, 0xBD, 0x7C, 0x45, 0xD9, 0xA9, 0x65, 0x88,
  34130. 0xA7, 0x0E, 0x16, 0xBF, 0xB3, 0x82, 0x5E, 0x5E,
  34131. 0x56, 0x13, 0x02, 0x7D, 0xB1, 0xDC, 0xF5, 0x4A,
  34132. 0x82, 0x73, 0x72, 0x35, 0x9B, 0x91, 0xAC, 0x04,
  34133. 0x69, 0xE9, 0xEA, 0x19, 0xC9, 0xD8, 0x59, 0xEB,
  34134. 0x8F, 0x22, 0x5F, 0x43, 0x11, 0x0C, 0xCF, 0xB4,
  34135. 0x16, 0x6C, 0x7D, 0x60, 0xCE, 0x14, 0x24, 0xAD,
  34136. 0xD7, 0x07, 0xC2, 0x4E, 0x98, 0xA0, 0xDE, 0x9E,
  34137. 0xE6, 0x31, 0xED, 0xF8, 0x5B, 0x9C, 0xAF, 0xF7,
  34138. 0x57, 0x59, 0x10, 0xA9, 0x92, 0xDC, 0x4F, 0x0C,
  34139. 0x2B, 0x88, 0x75, 0x19, 0x1D, 0xB3, 0xBF, 0x70,
  34140. 0x23, 0x17, 0xD5, 0x1A, 0x50, 0x30, 0x18, 0x14,
  34141. 0x1A, 0x14, 0xE6, 0x1D, 0x4F, 0x8A, 0x96, 0x3E,
  34142. 0xD8, 0x6E, 0xD9, 0xBF, 0x94, 0x4E, 0xDE, 0xB8,
  34143. 0xFF, 0xE1, 0x6F, 0xFD, 0x31, 0xE8, 0xFE, 0x43,
  34144. 0xC2, 0x40, 0x82, 0x45, 0x50, 0xFE, 0x1B, 0xBC,
  34145. 0x77, 0x4B, 0xB4, 0x30, 0xA7, 0xD4, 0x46, 0x32,
  34146. 0x6A, 0xF7, 0xC5, 0x92, 0xDA, 0x70, 0xB1, 0xB7,
  34147. 0xA1, 0x5A, 0x5D, 0x17, 0x3B, 0xDB, 0x2F, 0x28,
  34148. 0x8A, 0x6E, 0xEC, 0xDA, 0xC4, 0xF7, 0x2E, 0xCB,
  34149. 0xEB, 0x96, 0x60, 0x92, 0x1B, 0xDD, 0xD6, 0x13,
  34150. 0x7C, 0x85, 0x9F, 0x8A, 0x9A, 0xE9, 0x5F, 0xC4,
  34151. 0x24, 0xFD, 0x33, 0xDF, 0xB3, 0x98, 0x66, 0xF7,
  34152. 0xA1, 0x5A, 0xDC, 0x01, 0xC9, 0xFA, 0x37, 0xF1,
  34153. 0x7B, 0xD0, 0xF6, 0x66, 0x8A, 0x26, 0x7C, 0xC2,
  34154. 0x1B, 0xFF, 0x62, 0xBC, 0xFD, 0xCD, 0x47, 0xDA,
  34155. 0xEE, 0x75, 0xF2, 0xAC, 0x60, 0x69, 0x87, 0x26,
  34156. 0xCC, 0x92, 0x10, 0x1C, 0x92, 0xC1, 0x43, 0x09,
  34157. 0xE9, 0xCE, 0x7D, 0x05, 0x5C, 0x64, 0x55, 0xCB,
  34158. 0xBB, 0x7A, 0xAE, 0x05, 0xDB, 0x38, 0xD3, 0xD5,
  34159. 0xBB, 0xD9, 0x9F, 0xCB, 0xCF, 0xB7, 0x9C, 0xEF,
  34160. 0x7E, 0x7B, 0x2A, 0x6F, 0x84, 0x4E, 0x6A, 0x7F,
  34161. 0xD3, 0x5F, 0xF3, 0xB3, 0xC1, 0xF0, 0x02, 0x9C,
  34162. 0xA2, 0x4C, 0x86, 0x0E, 0x6B, 0xE2, 0x2B, 0x1D,
  34163. 0x1D, 0xB4, 0x55, 0x7F, 0x85, 0x54, 0x2D, 0x85,
  34164. 0x64, 0x89, 0x92, 0x19, 0x65, 0x44, 0xD7, 0x95,
  34165. 0x48, 0x2C, 0x46, 0x8D, 0x0E, 0xBA, 0xFB, 0x13,
  34166. 0x63, 0x52, 0x2E, 0x22, 0x19, 0x3F, 0x7F, 0xFB,
  34167. 0x54, 0x4D, 0x73, 0xA1, 0x3C, 0x22, 0xD6, 0x5D,
  34168. 0x2B, 0x4A, 0xBD, 0xD7, 0xBB, 0x72, 0x55, 0x80,
  34169. 0xD4, 0x57, 0x4E, 0xDC, 0xF2, 0x8B, 0xB3, 0x09,
  34170. 0x6A, 0xF9, 0x1A, 0xD3, 0x41, 0x0E, 0x72, 0x95,
  34171. 0x49, 0xE7, 0xD1, 0xDC, 0x05, 0x22, 0xC3, 0x3E,
  34172. 0x26, 0x95, 0x00, 0x01, 0x8C, 0xE1, 0x54, 0x47,
  34173. 0x84, 0x10, 0xA7, 0x67, 0x45, 0xBB, 0xB9, 0x7B,
  34174. 0x0B, 0xB4, 0x74, 0x82, 0xED, 0x6C, 0x26, 0x6E,
  34175. 0xF2, 0x56, 0xCA, 0x1A, 0xD1, 0x10, 0x68, 0x40,
  34176. 0x28, 0x23, 0xD5, 0x98, 0xB3, 0x6B, 0x75, 0x16,
  34177. 0x13, 0x87, 0xE1, 0xF2, 0x3F, 0xAB, 0xC0, 0x2A,
  34178. 0xF0, 0x16, 0x59, 0x85, 0x1A, 0x5B, 0x41, 0xB7,
  34179. 0x52, 0xB1, 0x79, 0x46, 0x20, 0xDF, 0x59, 0xFB,
  34180. 0x33, 0xB3, 0x05, 0xF1, 0x12, 0x8B, 0xDB, 0x7C,
  34181. 0x51, 0x90, 0xC9, 0x8A, 0xC9, 0x48, 0x10, 0x54,
  34182. 0xF4, 0x0F, 0x88, 0x1D, 0xDB, 0x40, 0x1B, 0x3A,
  34183. 0xD7, 0x62, 0xD1, 0x75, 0x73, 0xD6, 0xCA, 0x23,
  34184. 0x26, 0xB2, 0xBF, 0x4C, 0xCA, 0x22, 0xDD, 0xF6,
  34185. 0xAF, 0x22, 0xB8, 0x4F, 0xC2, 0xC3, 0xB3, 0xD3,
  34186. 0xED, 0xFA, 0xBA, 0x2E, 0x38, 0x28, 0x6A, 0xAE,
  34187. 0x60, 0xE9, 0x2D, 0x11, 0x33, 0xED, 0x7E, 0xE9,
  34188. 0x29, 0x8E, 0x01, 0xB0, 0x0F, 0x13, 0x83, 0x44,
  34189. 0x17, 0xFA, 0xB6, 0x54, 0x7C, 0xAC, 0x1F, 0xED,
  34190. 0xC9, 0x22, 0xF2, 0x4F, 0x69, 0x24, 0x04, 0xFE,
  34191. 0xC2, 0x6A, 0xEB, 0xB0, 0xE4, 0xF5, 0x03, 0xCB,
  34192. 0xB3, 0x99, 0x50, 0x66, 0x1F, 0x6B, 0xF3, 0xFE,
  34193. 0xB7, 0xBF, 0x8D, 0xBA, 0x59, 0x75, 0x75, 0x51,
  34194. 0xB0, 0xA5, 0xB9, 0x66, 0xC8, 0xDD, 0x35, 0xAE,
  34195. 0x20, 0x66, 0x21, 0x9B, 0x04, 0x3F, 0xC6, 0x90,
  34196. 0x6F, 0x2B, 0x5C, 0x78, 0x49, 0x3C, 0x40, 0xE6,
  34197. 0xF9, 0x6B, 0x1A, 0xEF, 0xCE, 0x5A, 0xC1, 0x68,
  34198. 0xD3, 0x34, 0x05, 0xD0, 0x21, 0x6C, 0xF8, 0xA8,
  34199. 0x55, 0xE4, 0x6E, 0x80, 0x9B, 0xAD, 0xA5, 0xC3,
  34200. 0x55, 0x0B, 0x28, 0xBB, 0x54, 0x02, 0xD4, 0xF6,
  34201. 0x82, 0x73, 0xAB, 0x56, 0x0B, 0xB1, 0x5F, 0x94,
  34202. 0xC3, 0xDA, 0x24, 0x1E, 0x7F, 0x62, 0x6B, 0x98,
  34203. 0x6B, 0x2A, 0xF3, 0x92, 0x37, 0x3A, 0xB9, 0xE6,
  34204. 0x27, 0xC4, 0xBB, 0xAB, 0xE4, 0x9A, 0x60, 0xD2,
  34205. 0xAE, 0xCE, 0xFD, 0x44, 0xEB, 0x1C, 0xCF, 0x74,
  34206. 0x54, 0xFC, 0xEC, 0x4F, 0xC2, 0xBA, 0xF4, 0x3B,
  34207. 0xAC, 0x03, 0xC7, 0x2E, 0xE6, 0x62, 0x44, 0x61,
  34208. 0x42, 0xC8, 0xAE, 0xF1, 0xB2, 0xA9, 0xAC, 0xE0,
  34209. 0xCE, 0x23, 0xAF, 0xCC, 0x86, 0x61, 0xFE, 0xC5,
  34210. 0xCB, 0xAC, 0x4A, 0x1B, 0x5C, 0xC7, 0x2B, 0xFF,
  34211. 0x8A, 0x20, 0x62, 0x0E, 0xB9, 0x1D, 0xDD, 0x93,
  34212. 0x19, 0x29, 0xE4, 0xD9, 0x13, 0x1D, 0x28, 0x32,
  34213. 0x03, 0x5A, 0xA6, 0x8E, 0x20, 0xC7, 0xD6, 0xC6,
  34214. 0x4D, 0x19, 0x17, 0xCC, 0x65, 0xB8, 0x84, 0x0C,
  34215. 0x38, 0xB4, 0xA9, 0x45, 0x2B, 0x91, 0x61, 0x79,
  34216. 0x87, 0x08, 0xA6, 0xBD, 0x28, 0x9A, 0x58, 0x48,
  34217. 0xD5, 0x58, 0xC6, 0xCE, 0xC2, 0xC5, 0x72, 0x16,
  34218. 0xD9, 0xF4, 0xED, 0x66, 0xAC, 0xFA, 0x93, 0xE8,
  34219. 0x26, 0x10, 0x3B, 0x3D, 0x8F, 0xEA, 0x51, 0xCC,
  34220. 0x82, 0xC0, 0xDB, 0xDF, 0xA7, 0x13, 0xFB, 0x1B,
  34221. 0x77, 0x7E, 0x6F, 0x9E, 0x3C, 0xC5, 0x86, 0x35,
  34222. 0x92, 0x5B, 0x6F, 0x76, 0xA1, 0x71, 0x0D, 0x8C,
  34223. 0xDC, 0x95, 0x9F, 0xAC, 0x2C, 0x8E, 0x21, 0x01,
  34224. 0x37, 0x06, 0x28, 0x64, 0x4C, 0x23, 0xE2, 0x75,
  34225. 0x0B, 0xA7, 0xA4, 0xF5, 0x90, 0x87, 0xD2, 0x43,
  34226. 0x71, 0x59, 0x7C, 0x8C, 0xCA, 0x77, 0x3B, 0xC5,
  34227. 0x36, 0x46, 0xF7, 0x2F, 0xD3, 0x47, 0x18, 0xD7,
  34228. 0xC9, 0x4E, 0x56, 0x2D, 0x49, 0x82, 0xAC, 0x7D,
  34229. 0xD7, 0x3D, 0xF1, 0xDD, 0x73, 0x8B, 0xE4, 0xA1,
  34230. 0x10, 0x85, 0xB6, 0x94, 0xBE, 0x6A, 0x5E, 0xEE,
  34231. 0xBD, 0x60, 0xEB, 0x95, 0x76, 0xA8, 0x52, 0xE1,
  34232. 0x47, 0x57, 0xA1, 0x9C, 0xEC, 0x44, 0xE5, 0x6F,
  34233. 0x68, 0x34, 0x7E, 0x19, 0xBE, 0xCE, 0x56, 0xC9,
  34234. 0xBE, 0xCE, 0xFC, 0xB8, 0x32, 0x6D, 0xCB, 0x84,
  34235. 0x59, 0xBF, 0x4D, 0xF6, 0xE1, 0x53, 0x41, 0x61,
  34236. 0x5C, 0xFB, 0xD2, 0x48, 0xA6, 0x7F, 0x05, 0xB2,
  34237. 0xFC, 0xE8, 0xB2, 0x8A, 0x55, 0x7D, 0x19, 0xC0,
  34238. 0x69, 0x3B, 0x91, 0x5D, 0x71, 0xE7, 0xBB, 0x72,
  34239. 0x7D, 0xB9, 0x64, 0x6E, 0x8B, 0x5B, 0x70, 0x51,
  34240. 0xB5, 0x69, 0x8C, 0xC0, 0xFC, 0x95, 0xB2, 0x43,
  34241. 0x08, 0xF8, 0x70, 0xE4, 0x6F, 0x87, 0xA7, 0xDF,
  34242. 0x23, 0x84, 0xEE, 0xCF, 0x73, 0x38, 0xDE, 0x99,
  34243. 0x4C, 0xF8, 0xF1, 0x2D, 0xA2, 0x68, 0x99, 0xE3,
  34244. 0x9B, 0xB8, 0xF6, 0xC1, 0x5C, 0x83, 0x07, 0xE9,
  34245. 0xB9, 0xE2, 0x51, 0x62, 0xC8, 0x53, 0xF1, 0xC2,
  34246. 0xF7, 0x57, 0x8A, 0xA0, 0x42, 0x3C, 0x18, 0x36,
  34247. 0xF3, 0x99, 0xFD, 0x34, 0xB2, 0xF0, 0x1D, 0xBA,
  34248. 0x43, 0xEA, 0x72, 0x1C, 0x0B, 0x37, 0x47, 0xBC,
  34249. 0xAF, 0xDA, 0x22, 0x1F, 0x1C, 0x08, 0x16, 0x13,
  34250. 0xBD, 0xAA, 0x07, 0xFD, 0x7E, 0xCA, 0x70, 0x57,
  34251. 0x74, 0xDF, 0x68, 0x6B, 0x9F, 0x2D, 0x56, 0xBD,
  34252. 0x21, 0x89, 0xFA, 0x09, 0x04, 0xCA, 0x09, 0xBD,
  34253. 0x4F, 0xE6, 0x15, 0xF5, 0x89, 0xAB, 0xAC, 0xB2,
  34254. 0xC9, 0xBF, 0xC8, 0xBB, 0x87, 0x83, 0xB4, 0xD3,
  34255. 0xDC, 0xB1, 0x25, 0x9B, 0xAE, 0xC5, 0x75, 0x0C,
  34256. 0x9E, 0x6A, 0x83, 0x41, 0x85, 0x9D, 0x4B, 0xBF,
  34257. 0x62, 0x0C, 0x7D, 0x77, 0xC9, 0x89, 0xA6, 0xE1,
  34258. 0x28, 0xBD, 0x13, 0x5D, 0x41, 0x26, 0x80, 0x75,
  34259. 0x23, 0x57, 0xE7, 0x4F, 0x4D, 0x02, 0x8E, 0x0F,
  34260. 0x43, 0x67, 0xF6, 0xA6, 0xE6, 0xB6, 0x84, 0x8D,
  34261. 0xF5, 0x7B, 0x6A, 0x95, 0x73, 0x27, 0x86, 0x02,
  34262. 0x72, 0xCB, 0xDF, 0x77, 0x1C, 0x6C, 0x5E, 0xD3,
  34263. 0xF0, 0x1C, 0x82, 0x7A, 0x0D, 0xBB, 0x70, 0xA3,
  34264. 0x98, 0x8B, 0x7B, 0x4A, 0xFE, 0x2D, 0xB1, 0x5C,
  34265. 0x61, 0x89, 0x34, 0x4C, 0x81, 0x4B, 0x52, 0x17,
  34266. 0x03, 0x81, 0x54, 0x4F, 0x9E, 0x9E, 0x07, 0x16,
  34267. 0xF3, 0xD9, 0x18, 0x01, 0x11, 0xFD, 0x67, 0x18,
  34268. 0xA2, 0x64, 0x35, 0x42, 0x81, 0x80, 0x4A, 0xBA,
  34269. 0xCB, 0xD5, 0xF5, 0x4A, 0x10, 0x7F, 0xE2, 0xCF,
  34270. 0xA5, 0x1E, 0xCB, 0x0C, 0xAB, 0x3E, 0x03, 0x98,
  34271. 0x73, 0x89, 0xA4, 0x10, 0x75, 0xD5, 0xAC, 0x3D,
  34272. 0xCF, 0x56, 0x75, 0xD8, 0x86, 0xC2, 0x21, 0x42,
  34273. 0x99, 0x8D, 0x1B, 0x49, 0x09, 0xFE, 0x86, 0x41,
  34274. 0xC9, 0xDC, 0x87, 0x8D, 0x5A, 0xF0, 0xF5, 0xBE,
  34275. 0xF5, 0x49, 0x64, 0x5A, 0x7A, 0xC3, 0x5D, 0xE4,
  34276. 0xD6, 0xB7, 0x30, 0x92, 0x2A, 0x15, 0x86, 0x02,
  34277. 0xBE, 0xBA, 0x6E, 0xF6, 0x3D, 0x2D, 0x70, 0x89,
  34278. 0xFB, 0xB5, 0x1E, 0xBA, 0xDA, 0x20, 0x12, 0x49,
  34279. 0x22, 0xA0, 0xD8, 0x33, 0x9E, 0x4C, 0xC0, 0x27,
  34280. 0x0F, 0x9C, 0x1F, 0xD2, 0xA9, 0xF4, 0xD2, 0xA9,
  34281. 0x6D, 0xC5, 0x32, 0x16, 0x35, 0x9F, 0x19, 0x88,
  34282. 0xC1, 0xAA, 0xA4, 0x66, 0x33, 0xE6, 0x2C, 0x6A,
  34283. 0x6E, 0xA2, 0x1B, 0x33, 0xCB, 0xC3, 0x7E, 0xC5,
  34284. 0x31, 0x4D, 0x5C, 0x17, 0x4C, 0x33, 0x7F, 0x09,
  34285. 0x01, 0x33, 0x82, 0x84, 0x37, 0x03, 0xEB, 0x0E,
  34286. 0xB1, 0x5F, 0x1B, 0x60, 0x8A, 0x2C, 0x9F, 0x39
  34287. };
  34288. static const byte sk_87[] = {
  34289. 0x8C, 0x52, 0x4B, 0xD9, 0xAC, 0x48, 0x5C, 0xC6,
  34290. 0x9A, 0xA0, 0x75, 0x64, 0xE1, 0x4F, 0x0F, 0x60,
  34291. 0x13, 0x0E, 0xDE, 0x34, 0x08, 0xA5, 0xD4, 0x81,
  34292. 0xFD, 0x76, 0xC2, 0x51, 0x74, 0x75, 0xA8, 0xFB,
  34293. 0x9A, 0xFE, 0xF5, 0x92, 0x58, 0xBB, 0x3C, 0xEB,
  34294. 0x4C, 0x5E, 0x83, 0xF9, 0xFF, 0xBC, 0x3B, 0x49,
  34295. 0xAE, 0xE1, 0xFC, 0x4B, 0x94, 0x4B, 0x8C, 0x75,
  34296. 0xD4, 0x67, 0x75, 0x66, 0x7D, 0x6B, 0xA4, 0xF2,
  34297. 0xDA, 0xC2, 0xB7, 0xC4, 0xD8, 0x50, 0x25, 0xCB,
  34298. 0x5A, 0xDB, 0xA4, 0xAD, 0xBB, 0x44, 0x20, 0x24,
  34299. 0x90, 0xEA, 0xA5, 0x2C, 0xAE, 0x80, 0x22, 0xC9,
  34300. 0x59, 0x02, 0xB7, 0x10, 0xB0, 0x5E, 0x1E, 0x5F,
  34301. 0x52, 0x7D, 0x88, 0xDA, 0xE2, 0x04, 0xBF, 0x45,
  34302. 0xA7, 0xA8, 0x49, 0x97, 0x7D, 0xAD, 0x7C, 0x7C,
  34303. 0x9E, 0x9C, 0x4A, 0xCC, 0x36, 0x33, 0x0F, 0x30,
  34304. 0xFA, 0xDE, 0x52, 0xE9, 0xAE, 0x23, 0x29, 0x13,
  34305. 0x10, 0x17, 0x8A, 0xD0, 0x08, 0x8E, 0xE1, 0x10,
  34306. 0x30, 0xD0, 0x84, 0x65, 0x92, 0x12, 0x2A, 0x81,
  34307. 0x26, 0x2E, 0x11, 0x14, 0x30, 0x61, 0x38, 0x61,
  34308. 0x64, 0x42, 0x05, 0x08, 0x91, 0x90, 0x4C, 0x06,
  34309. 0x82, 0xCC, 0x90, 0x45, 0x10, 0x39, 0x90, 0x22,
  34310. 0x40, 0x2A, 0x9B, 0x16, 0x26, 0x9A, 0xA8, 0x50,
  34311. 0x91, 0x12, 0x70, 0x91, 0x20, 0x4D, 0xC0, 0x34,
  34312. 0x90, 0x18, 0x28, 0x31, 0x10, 0x02, 0x11, 0x22,
  34313. 0xB3, 0x6C, 0x8B, 0xB8, 0x2C, 0x22, 0xB0, 0x69,
  34314. 0x53, 0x36, 0x31, 0x61, 0x42, 0x6C, 0xD9, 0x06,
  34315. 0x6A, 0xD9, 0x04, 0x45, 0xDB, 0x18, 0x05, 0x12,
  34316. 0x37, 0x4A, 0xD4, 0x06, 0x64, 0xD3, 0xA2, 0x85,
  34317. 0xA0, 0x38, 0x8A, 0x14, 0xA5, 0x85, 0x50, 0x20,
  34318. 0x85, 0xE4, 0xA8, 0x24, 0xC3, 0xC6, 0x31, 0xC9,
  34319. 0x34, 0x4E, 0xD2, 0x14, 0x68, 0x82, 0x90, 0x85,
  34320. 0xC4, 0x02, 0x61, 0x24, 0x38, 0x05, 0x01, 0xA3,
  34321. 0x50, 0x48, 0x08, 0x62, 0x20, 0xB0, 0x25, 0x5B,
  34322. 0xA6, 0x4D, 0x98, 0x92, 0x11, 0xC2, 0x06, 0x00,
  34323. 0xD1, 0xB0, 0x4D, 0x21, 0xA4, 0x8C, 0x01, 0x16,
  34324. 0x72, 0x11, 0xA6, 0x20, 0xD0, 0x16, 0x45, 0x10,
  34325. 0x31, 0x8E, 0xCB, 0xC2, 0x69, 0x02, 0x08, 0x91,
  34326. 0xD4, 0x30, 0x89, 0x03, 0x41, 0x05, 0x93, 0x16,
  34327. 0x8E, 0x5A, 0x18, 0x04, 0x41, 0x10, 0x6D, 0x18,
  34328. 0x42, 0x70, 0x53, 0x16, 0x31, 0x52, 0x30, 0x8E,
  34329. 0x0C, 0x49, 0x66, 0x0C, 0x90, 0x0C, 0xA4, 0x08,
  34330. 0x2E, 0x41, 0x92, 0x05, 0x24, 0x07, 0x30, 0x12,
  34331. 0x46, 0x72, 0x13, 0x99, 0x20, 0xE0, 0xA2, 0x4C,
  34332. 0x1B, 0x14, 0x52, 0x5A, 0x90, 0x05, 0x08, 0x82,
  34333. 0x31, 0x53, 0xC2, 0x90, 0xCC, 0x42, 0x68, 0x18,
  34334. 0xB0, 0x2C, 0x00, 0x80, 0x65, 0x58, 0x12, 0x84,
  34335. 0x19, 0x90, 0x08, 0x44, 0x26, 0x4A, 0x10, 0xA9,
  34336. 0x0C, 0x12, 0x25, 0x0C, 0x9C, 0x10, 0x25, 0x0C,
  34337. 0x28, 0x25, 0xD8, 0x46, 0x84, 0x1A, 0x22, 0x71,
  34338. 0x5B, 0x28, 0x6E, 0x98, 0x02, 0x51, 0x61, 0xB4,
  34339. 0x51, 0x01, 0xA1, 0x21, 0x24, 0x39, 0x12, 0xC8,
  34340. 0x08, 0x85, 0xD1, 0x34, 0x64, 0xA4, 0xA8, 0x04,
  34341. 0xA2, 0xC0, 0x09, 0x44, 0x48, 0x48, 0x03, 0x37,
  34342. 0x00, 0x20, 0x05, 0x4D, 0x20, 0xA4, 0x05, 0x11,
  34343. 0x18, 0x82, 0x42, 0x94, 0x4D, 0x24, 0x16, 0x01,
  34344. 0x02, 0x93, 0x4C, 0x00, 0x16, 0x06, 0xC1, 0xC0,
  34345. 0x0C, 0x8B, 0xC0, 0x41, 0x41, 0x06, 0x42, 0xA3,
  34346. 0xC6, 0x64, 0x1A, 0x85, 0x91, 0x41, 0x06, 0x49,
  34347. 0x04, 0xA7, 0x44, 0x82, 0x22, 0x6A, 0x50, 0x08,
  34348. 0x0E, 0x14, 0x18, 0x20, 0x4B, 0x88, 0x91, 0x01,
  34349. 0xA0, 0x49, 0x1A, 0x85, 0x4D, 0x94, 0x18, 0x10,
  34350. 0x0A, 0x05, 0x44, 0x94, 0x38, 0x05, 0x93, 0x40,
  34351. 0x68, 0x23, 0x07, 0x85, 0xE2, 0x12, 0x22, 0x9B,
  34352. 0xB8, 0x08, 0xD2, 0x10, 0x2A, 0x08, 0xA8, 0x10,
  34353. 0x92, 0x40, 0x2D, 0xD8, 0x44, 0x4C, 0xCC, 0x94,
  34354. 0x05, 0x24, 0x43, 0x4C, 0xD3, 0xC2, 0x48, 0x10,
  34355. 0x21, 0x2D, 0xC9, 0xB6, 0x08, 0xC9, 0x06, 0x4D,
  34356. 0xE1, 0x90, 0x20, 0x14, 0x24, 0x70, 0x5C, 0x84,
  34357. 0x28, 0xC0, 0xC2, 0x81, 0x22, 0x13, 0x50, 0x44,
  34358. 0x84, 0x91, 0xCA, 0xA2, 0x48, 0x12, 0x91, 0x05,
  34359. 0x5B, 0x92, 0x8D, 0x92, 0x92, 0x24, 0x82, 0x42,
  34360. 0x48, 0x03, 0x37, 0x46, 0xD8, 0x44, 0x86, 0x44,
  34361. 0x20, 0x89, 0xE4, 0xC2, 0x84, 0xC2, 0x04, 0x65,
  34362. 0x49, 0xA8, 0x4D, 0xA4, 0x38, 0x28, 0xDB, 0xA4,
  34363. 0x64, 0x24, 0x00, 0x51, 0xC8, 0x12, 0x6D, 0x19,
  34364. 0x82, 0x24, 0xCB, 0x00, 0x44, 0x4B, 0x20, 0x20,
  34365. 0x9B, 0x82, 0x4C, 0x5C, 0xA8, 0x08, 0xD2, 0xB6,
  34366. 0x8C, 0x08, 0x35, 0x20, 0xC0, 0x92, 0x45, 0xE3,
  34367. 0xB4, 0x2C, 0x50, 0x32, 0x0E, 0xD1, 0x82, 0x11,
  34368. 0x4A, 0x96, 0x08, 0x1C, 0x86, 0x29, 0x02, 0x19,
  34369. 0x71, 0x12, 0x03, 0x6E, 0x94, 0x08, 0x50, 0x12,
  34370. 0x27, 0x20, 0x0B, 0x10, 0x12, 0xA1, 0x18, 0x06,
  34371. 0x5A, 0x36, 0x4C, 0x93, 0xB4, 0x68, 0x21, 0xA7,
  34372. 0x28, 0x09, 0x34, 0x91, 0x18, 0x93, 0x49, 0x4A,
  34373. 0x32, 0x60, 0x00, 0x29, 0x2D, 0x94, 0x48, 0x44,
  34374. 0x09, 0x94, 0x2C, 0x21, 0x07, 0x6C, 0x41, 0x38,
  34375. 0x60, 0x8C, 0x10, 0x46, 0x11, 0x19, 0x65, 0x01,
  34376. 0x46, 0x60, 0x1A, 0x29, 0x42, 0x23, 0x30, 0x29,
  34377. 0x40, 0x96, 0x85, 0x81, 0xC6, 0x6C, 0x09, 0xA2,
  34378. 0x31, 0x23, 0xC9, 0x84, 0x18, 0x27, 0x61, 0x02,
  34379. 0xA6, 0x05, 0x1B, 0x11, 0x32, 0xD1, 0x80, 0x24,
  34380. 0x59, 0x22, 0x52, 0x21, 0x34, 0x64, 0x0A, 0x21,
  34381. 0x52, 0x10, 0xC2, 0x80, 0x5C, 0x98, 0x0D, 0x81,
  34382. 0xA0, 0x84, 0x14, 0x97, 0x04, 0xCC, 0xC2, 0x04,
  34383. 0x1A, 0x81, 0x45, 0x23, 0x44, 0x6C, 0x13, 0xC0,
  34384. 0x44, 0x59, 0xC2, 0x68, 0x64, 0x08, 0x52, 0x51,
  34385. 0x30, 0x71, 0x12, 0x49, 0x70, 0x12, 0x94, 0x84,
  34386. 0x80, 0x12, 0x12, 0x1B, 0x00, 0x50, 0x84, 0x10,
  34387. 0x45, 0x4A, 0x30, 0x10, 0x22, 0x95, 0x49, 0xC9,
  34388. 0x82, 0x24, 0x03, 0x35, 0x21, 0x18, 0x16, 0x72,
  34389. 0x09, 0x89, 0x65, 0x88, 0xB2, 0x89, 0x41, 0xB4,
  34390. 0x90, 0x92, 0x38, 0x8C, 0x08, 0x23, 0x26, 0x0B,
  34391. 0x80, 0x61, 0x84, 0x28, 0x6A, 0x4C, 0x98, 0x44,
  34392. 0x10, 0xB9, 0x30, 0x93, 0x02, 0x49, 0x22, 0x13,
  34393. 0x80, 0x1C, 0xC3, 0x48, 0x50, 0xA8, 0x20, 0x1C,
  34394. 0x05, 0x00, 0x5B, 0x02, 0x41, 0xD2, 0x84, 0x61,
  34395. 0x4B, 0x40, 0x46, 0x20, 0x21, 0x44, 0xD9, 0xC4,
  34396. 0x21, 0xD3, 0xA4, 0x4D, 0xC0, 0xC0, 0x09, 0x5B,
  34397. 0x28, 0x91, 0x18, 0x15, 0x41, 0x18, 0xC5, 0x4C,
  34398. 0x14, 0xB7, 0x61, 0xDB, 0x34, 0x25, 0x02, 0x06,
  34399. 0x41, 0x14, 0xA9, 0x65, 0x0B, 0x10, 0x04, 0x23,
  34400. 0xC7, 0x49, 0x13, 0x47, 0x0A, 0xD0, 0x30, 0x80,
  34401. 0x99, 0x32, 0x68, 0x50, 0x18, 0x06, 0xA2, 0x28,
  34402. 0x65, 0x13, 0x35, 0x82, 0xD3, 0x06, 0x81, 0x22,
  34403. 0x49, 0x4D, 0x48, 0x44, 0x30, 0xCA, 0x96, 0x2C,
  34404. 0x12, 0xC8, 0x08, 0xA1, 0x24, 0x2C, 0x52, 0xA8,
  34405. 0x28, 0x23, 0x14, 0x0A, 0xD4, 0x20, 0x4D, 0x18,
  34406. 0x12, 0x72, 0xD4, 0x80, 0x44, 0xDC, 0x26, 0x2C,
  34407. 0x88, 0x10, 0x0A, 0x04, 0x14, 0x51, 0xC1, 0x96,
  34408. 0x00, 0xA3, 0x40, 0x30, 0x99, 0x48, 0x92, 0x9B,
  34409. 0x08, 0x86, 0x81, 0x04, 0x20, 0x4C, 0xB2, 0x29,
  34410. 0x18, 0x31, 0x08, 0x09, 0x23, 0x8C, 0x4C, 0x02,
  34411. 0x6A, 0xCA, 0x00, 0x62, 0x09, 0x22, 0x2D, 0x21,
  34412. 0x00, 0x02, 0x0A, 0x39, 0x41, 0x04, 0xA3, 0x50,
  34413. 0x90, 0x80, 0x2D, 0x59, 0xB4, 0x71, 0x13, 0x16,
  34414. 0x31, 0x11, 0x90, 0x4C, 0xC3, 0x14, 0x20, 0x60,
  34415. 0xB2, 0x30, 0x0A, 0xB6, 0x24, 0x21, 0xA9, 0x10,
  34416. 0x89, 0x80, 0x88, 0x44, 0x06, 0x8A, 0x91, 0x22,
  34417. 0x8E, 0xD9, 0x36, 0x86, 0x10, 0x46, 0x0A, 0xE1,
  34418. 0x16, 0x85, 0x42, 0x40, 0x6C, 0x09, 0x49, 0x11,
  34419. 0xE0, 0x88, 0x68, 0x12, 0x08, 0x68, 0x5C, 0x26,
  34420. 0x24, 0x04, 0xA8, 0x70, 0xC8, 0x08, 0x05, 0x13,
  34421. 0x87, 0x41, 0x23, 0x29, 0x72, 0xC9, 0xB8, 0x88,
  34422. 0x1B, 0x22, 0x66, 0x11, 0xA5, 0x2D, 0x11, 0x29,
  34423. 0x12, 0x50, 0x12, 0x70, 0x03, 0x09, 0x6A, 0x4B,
  34424. 0x88, 0x4C, 0xD2, 0xC8, 0x31, 0x40, 0x26, 0x40,
  34425. 0x4C, 0x04, 0x50, 0x58, 0x16, 0x71, 0x90, 0xC2,
  34426. 0x00, 0x0A, 0x30, 0x8A, 0xDC, 0x24, 0x85, 0x19,
  34427. 0xB0, 0x65, 0x1A, 0xA3, 0x64, 0x13, 0xA3, 0x45,
  34428. 0xC8, 0x48, 0x91, 0x91, 0x12, 0x20, 0xDC, 0x42,
  34429. 0x40, 0x24, 0xC0, 0x4D, 0xA3, 0x98, 0x10, 0x40,
  34430. 0x26, 0x25, 0xDC, 0xB4, 0x68, 0x4B, 0xC2, 0x45,
  34431. 0x13, 0x06, 0x91, 0xC8, 0x92, 0x24, 0x82, 0xA8,
  34432. 0x20, 0x4C, 0x30, 0x48, 0x52, 0x06, 0x01, 0x0B,
  34433. 0x24, 0x51, 0x41, 0x36, 0x40, 0x93, 0xC4, 0x70,
  34434. 0x44, 0x40, 0x2C, 0x24, 0x28, 0x22, 0x81, 0xA4,
  34435. 0x4C, 0x43, 0x84, 0x60, 0x20, 0x23, 0x90, 0x01,
  34436. 0x94, 0x6C, 0xDB, 0x28, 0x21, 0x93, 0x30, 0x80,
  34437. 0x93, 0xC0, 0x25, 0xC8, 0xA6, 0x50, 0xCA, 0x24,
  34438. 0x26, 0xD1, 0x40, 0x31, 0x04, 0xC4, 0x8D, 0xE2,
  34439. 0xC0, 0x04, 0x08, 0x33, 0x8C, 0x18, 0x87, 0x91,
  34440. 0xC8, 0xC8, 0x71, 0x40, 0x46, 0x06, 0x00, 0x44,
  34441. 0x20, 0x22, 0x49, 0x70, 0x11, 0x45, 0x90, 0x02,
  34442. 0xC3, 0x61, 0x60, 0xB4, 0x25, 0x80, 0x16, 0x21,
  34443. 0x11, 0x09, 0x04, 0x88, 0x04, 0x05, 0xCC, 0x36,
  34444. 0x20, 0x01, 0xB1, 0x2C, 0x64, 0xB6, 0x50, 0x54,
  34445. 0x32, 0x42, 0x0B, 0x08, 0x8D, 0x12, 0x39, 0x0D,
  34446. 0x10, 0x29, 0x52, 0x88, 0xB0, 0x04, 0x11, 0x38,
  34447. 0x44, 0xD2, 0xA6, 0x71, 0x0B, 0x45, 0x48, 0x9C,
  34448. 0x34, 0x72, 0xA0, 0x28, 0x49, 0x82, 0x16, 0x86,
  34449. 0x12, 0x18, 0x61, 0x04, 0x41, 0x0D, 0x8A, 0xA6,
  34450. 0x41, 0x80, 0xA8, 0x61, 0xDA, 0x30, 0x65, 0x82,
  34451. 0x84, 0x30, 0x08, 0xA3, 0x29, 0x04, 0x33, 0x8E,
  34452. 0x02, 0x24, 0x0D, 0x9C, 0x44, 0x10, 0xC9, 0x02,
  34453. 0x81, 0x53, 0x06, 0x66, 0x8B, 0x06, 0x90, 0x03,
  34454. 0x87, 0x69, 0x21, 0xC9, 0x69, 0x83, 0x46, 0x4E,
  34455. 0x14, 0x24, 0x89, 0x8C, 0xA0, 0x6C, 0x99, 0xA2,
  34456. 0x2C, 0x11, 0x37, 0x66, 0x0C, 0xA6, 0x4D, 0xD3,
  34457. 0xC8, 0x70, 0x03, 0x02, 0x61, 0xC3, 0xB6, 0x65,
  34458. 0x23, 0xC1, 0x6C, 0x10, 0x34, 0x8D, 0x1A, 0xC1,
  34459. 0x31, 0x43, 0x40, 0x44, 0xD4, 0x08, 0x02, 0x0A,
  34460. 0x36, 0x20, 0xE3, 0x26, 0x42, 0x0A, 0x48, 0x26,
  34461. 0x1A, 0x13, 0x44, 0x0C, 0x18, 0x61, 0x91, 0x96,
  34462. 0x84, 0x02, 0x17, 0x46, 0x9C, 0x20, 0x40, 0x41,
  34463. 0xC6, 0x2D, 0x1B, 0x16, 0x0C, 0x98, 0xB2, 0x90,
  34464. 0x1A, 0x20, 0x84, 0xE2, 0x34, 0x2D, 0xCB, 0x14,
  34465. 0x44, 0x93, 0xC6, 0x8D, 0x58, 0xB2, 0x69, 0x22,
  34466. 0xB2, 0x88, 0xC0, 0xB8, 0x2D, 0xA2, 0xC2, 0x31,
  34467. 0x20, 0xA3, 0x24, 0x11, 0x46, 0x48, 0x4A, 0xA6,
  34468. 0x50, 0x24, 0x09, 0x21, 0x1A, 0x01, 0x0D, 0x20,
  34469. 0x36, 0x01, 0xC4, 0x34, 0x70, 0xDA, 0x16, 0x68,
  34470. 0x84, 0x22, 0x4C, 0x11, 0x14, 0x09, 0x13, 0xC4,
  34471. 0x68, 0x11, 0x41, 0x2D, 0x1C, 0x10, 0x31, 0xDC,
  34472. 0xB2, 0x64, 0x42, 0x36, 0x08, 0x5C, 0x10, 0x88,
  34473. 0x04, 0x91, 0x25, 0xE1, 0xA0, 0x20, 0x14, 0x18,
  34474. 0x12, 0x14, 0x94, 0x91, 0x4C, 0xC2, 0x24, 0xD4,
  34475. 0x06, 0x71, 0x21, 0x02, 0x8D, 0xD4, 0x88, 0x30,
  34476. 0xC9, 0x36, 0x0E, 0xE4, 0x82, 0x81, 0xC0, 0x04,
  34477. 0x6D, 0x24, 0x23, 0x09, 0x21, 0x45, 0x45, 0x20,
  34478. 0x06, 0x65, 0xC2, 0x30, 0x2A, 0x18, 0x30, 0x8E,
  34479. 0x24, 0x83, 0x89, 0x93, 0x32, 0x66, 0xC1, 0x48,
  34480. 0x45, 0x62, 0x48, 0x0A, 0x52, 0xB8, 0x80, 0x11,
  34481. 0x86, 0x21, 0x04, 0x34, 0x11, 0x24, 0xB5, 0x6C,
  34482. 0x50, 0x36, 0x0A, 0x19, 0xA7, 0x8C, 0x14, 0x90,
  34483. 0x0D, 0x1A, 0xA5, 0x68, 0x0B, 0xB1, 0x11, 0x50,
  34484. 0x40, 0x08, 0x48, 0xB6, 0x31, 0x14, 0x28, 0x8D,
  34485. 0xE3, 0x47, 0xB4, 0xA1, 0x44, 0x94, 0xCC, 0x9F,
  34486. 0x0B, 0x94, 0x9F, 0x25, 0x49, 0xD9, 0xB3, 0x8F,
  34487. 0x71, 0xF4, 0x17, 0xA4, 0xA6, 0xAC, 0x24, 0x58,
  34488. 0x14, 0x25, 0x03, 0xC8, 0x63, 0x3E, 0x10, 0xA8,
  34489. 0xD4, 0x10, 0xD7, 0x90, 0x4A, 0x28, 0x37, 0x90,
  34490. 0x70, 0x27, 0xE3, 0x56, 0x5F, 0x04, 0x67, 0x76,
  34491. 0xC3, 0x67, 0x3F, 0xF5, 0xA5, 0x11, 0xA2, 0x2C,
  34492. 0x11, 0x01, 0x5D, 0x63, 0x71, 0x1A, 0xE6, 0x70,
  34493. 0x86, 0x46, 0xAB, 0xCE, 0x03, 0xB6, 0x82, 0xAF,
  34494. 0x51, 0xBA, 0x81, 0x94, 0x9C, 0x82, 0x36, 0xA9,
  34495. 0x49, 0xA5, 0xA3, 0x11, 0x08, 0x8C, 0x4B, 0x13,
  34496. 0x41, 0xF0, 0x08, 0xFD, 0xB2, 0x99, 0xED, 0xA8,
  34497. 0x07, 0x61, 0x3C, 0x2E, 0xBC, 0x49, 0x7B, 0x1C,
  34498. 0xBC, 0x87, 0xBC, 0xAE, 0x5F, 0x5E, 0x8F, 0x5D,
  34499. 0xE7, 0xB9, 0x0C, 0x70, 0x36, 0x25, 0x61, 0xFD,
  34500. 0x95, 0x9F, 0xAE, 0x0F, 0x8D, 0xF3, 0xA2, 0x45,
  34501. 0x24, 0xA7, 0xDE, 0x60, 0xD1, 0x4E, 0x6D, 0xAC,
  34502. 0xC7, 0x6A, 0x32, 0x42, 0xC0, 0x73, 0xEB, 0x78,
  34503. 0x50, 0xF4, 0x49, 0x52, 0x5E, 0x6F, 0x81, 0x42,
  34504. 0x54, 0xF8, 0x82, 0x05, 0xC9, 0x64, 0x74, 0x6A,
  34505. 0x60, 0x5E, 0x36, 0x59, 0x40, 0x50, 0xA3, 0xFE,
  34506. 0xDA, 0xE2, 0x6D, 0x8D, 0x6E, 0xE4, 0x5A, 0x27,
  34507. 0x73, 0x89, 0xDB, 0x0C, 0x5B, 0x14, 0xD9, 0xED,
  34508. 0xB2, 0xC7, 0x1D, 0x71, 0x93, 0x91, 0x0A, 0x72,
  34509. 0x32, 0xBE, 0xA3, 0xD8, 0x95, 0x8C, 0x94, 0x7E,
  34510. 0x63, 0xEB, 0xCE, 0x8B, 0xFC, 0xB0, 0x3F, 0x77,
  34511. 0x5C, 0x43, 0x48, 0x18, 0x83, 0xFE, 0xC8, 0xDA,
  34512. 0x89, 0xF2, 0x3B, 0x54, 0x82, 0x44, 0xC6, 0x9C,
  34513. 0xCC, 0x77, 0x0A, 0xC1, 0x6F, 0xB9, 0x98, 0x10,
  34514. 0xD5, 0xF2, 0x60, 0xFF, 0x38, 0xD2, 0x0D, 0xD6,
  34515. 0x8C, 0x38, 0x54, 0x5B, 0xD8, 0x38, 0x84, 0x50,
  34516. 0x36, 0xF4, 0x02, 0xC1, 0x06, 0x0F, 0x15, 0x1B,
  34517. 0xC8, 0x90, 0x9B, 0x6E, 0x36, 0xC8, 0x3F, 0xE9,
  34518. 0x8B, 0x62, 0x15, 0x6F, 0xF0, 0xC2, 0x86, 0x7F,
  34519. 0xD1, 0xB5, 0x97, 0x53, 0xAE, 0x41, 0xAE, 0x21,
  34520. 0x84, 0xAC, 0x57, 0xA5, 0x1F, 0xA7, 0xC7, 0x24,
  34521. 0xDF, 0xDE, 0x2F, 0x3C, 0xCD, 0xA2, 0x7E, 0x1D,
  34522. 0x97, 0xE1, 0x96, 0xC5, 0xB4, 0x7D, 0xF9, 0x5F,
  34523. 0x7E, 0xEF, 0x09, 0xC4, 0xF3, 0x57, 0xF0, 0x51,
  34524. 0x73, 0xAB, 0x0E, 0x6A, 0xCA, 0x64, 0xE4, 0x99,
  34525. 0x0F, 0xD2, 0x20, 0xAC, 0x72, 0xF1, 0xA8, 0x23,
  34526. 0x8F, 0x94, 0x63, 0xDC, 0xB3, 0xBB, 0x62, 0x2C,
  34527. 0xEA, 0xA6, 0x27, 0x5A, 0x93, 0xC6, 0xCD, 0xCE,
  34528. 0x1E, 0x09, 0xAF, 0x89, 0xEC, 0x22, 0xE4, 0x30,
  34529. 0x2D, 0xB9, 0xCD, 0x08, 0x2E, 0x12, 0x76, 0x79,
  34530. 0x99, 0xBC, 0xA0, 0x34, 0x0B, 0xDA, 0x89, 0x08,
  34531. 0x14, 0x60, 0x7B, 0x98, 0xE6, 0xAF, 0xD2, 0xE1,
  34532. 0x87, 0xC8, 0xDA, 0x50, 0xF7, 0x10, 0x2C, 0x72,
  34533. 0x74, 0x50, 0xD0, 0x3C, 0x98, 0x06, 0xFE, 0xEB,
  34534. 0xC6, 0xC5, 0x69, 0x31, 0x06, 0xE2, 0x2E, 0x7E,
  34535. 0x7D, 0x3D, 0x2B, 0x1F, 0x48, 0x43, 0xC5, 0x95,
  34536. 0xDA, 0x84, 0x08, 0x1E, 0x2B, 0x50, 0x6D, 0x91,
  34537. 0xA6, 0x2B, 0xCD, 0x08, 0x43, 0x7B, 0xA2, 0xD8,
  34538. 0x60, 0x6E, 0xF7, 0x80, 0x08, 0xC3, 0x3F, 0x35,
  34539. 0xF3, 0x70, 0xA5, 0xC7, 0x56, 0xFC, 0xBD, 0x34,
  34540. 0x46, 0x7B, 0xBF, 0x63, 0x19, 0xAC, 0xB6, 0xC3,
  34541. 0x1B, 0x81, 0x84, 0x9F, 0xBB, 0x54, 0x05, 0x99,
  34542. 0xAE, 0x43, 0xE2, 0xA5, 0x20, 0xFD, 0x5C, 0xC7,
  34543. 0x25, 0x47, 0xB1, 0xFD, 0x80, 0xB5, 0x78, 0xC2,
  34544. 0x00, 0x98, 0x02, 0xB9, 0x61, 0x2A, 0xBA, 0x39,
  34545. 0xC7, 0x20, 0xB8, 0x7D, 0x7A, 0x03, 0x68, 0xE5,
  34546. 0x37, 0x71, 0x1F, 0x72, 0xAA, 0x41, 0x61, 0xB4,
  34547. 0xC0, 0xC2, 0xD3, 0x7A, 0xCD, 0xD2, 0xED, 0xC2,
  34548. 0xC5, 0x99, 0x8C, 0x62, 0xA3, 0x7D, 0xC8, 0x9C,
  34549. 0xD2, 0x50, 0x02, 0x0D, 0xCB, 0x68, 0x15, 0xB0,
  34550. 0xD6, 0x19, 0x03, 0xC8, 0x01, 0x12, 0x72, 0xA1,
  34551. 0x3A, 0xC2, 0xA6, 0x63, 0x51, 0x26, 0x03, 0x5D,
  34552. 0x3F, 0x1D, 0x3B, 0x0E, 0x30, 0x6B, 0xB7, 0xEC,
  34553. 0xB6, 0x8E, 0x2D, 0x76, 0xC8, 0xD7, 0xAE, 0x59,
  34554. 0x81, 0xFC, 0x5F, 0x57, 0x5E, 0xAD, 0xA0, 0x20,
  34555. 0xC8, 0xB4, 0x91, 0x2D, 0xEC, 0x03, 0xC4, 0xC6,
  34556. 0x55, 0x05, 0x87, 0xA4, 0xA2, 0x21, 0x09, 0x25,
  34557. 0x97, 0x21, 0xA4, 0x46, 0x45, 0x46, 0x40, 0x3B,
  34558. 0xDC, 0x6F, 0xCD, 0xFB, 0xFB, 0xD9, 0xF4, 0x2C,
  34559. 0xEC, 0xF1, 0xC4, 0x73, 0x41, 0x30, 0x60, 0x63,
  34560. 0x9A, 0xF2, 0xA5, 0x26, 0x78, 0x9A, 0x5E, 0x70,
  34561. 0x98, 0xDE, 0x35, 0x10, 0xA0, 0x5D, 0x45, 0xD5,
  34562. 0x95, 0xF7, 0x11, 0xBC, 0x99, 0xD3, 0x00, 0x67,
  34563. 0x9A, 0x30, 0x85, 0x36, 0x50, 0xDB, 0x18, 0xEA,
  34564. 0x6D, 0xB2, 0xF3, 0x14, 0xDA, 0x23, 0xE2, 0x8A,
  34565. 0x44, 0x21, 0x25, 0xD4, 0xA3, 0x28, 0x43, 0xA0,
  34566. 0xC6, 0x5C, 0x99, 0xB0, 0x72, 0x6B, 0xC2, 0x1A,
  34567. 0x30, 0xBE, 0x6B, 0x7B, 0xE0, 0x31, 0x54, 0x8C,
  34568. 0x29, 0xE5, 0xC6, 0x69, 0x53, 0xDE, 0x05, 0x1E,
  34569. 0x43, 0xCC, 0x7E, 0x9A, 0x82, 0x4A, 0xC4, 0x0A,
  34570. 0x50, 0x65, 0xDC, 0xD8, 0xF9, 0x01, 0x32, 0x65,
  34571. 0x1E, 0xF9, 0xA4, 0xCC, 0x07, 0xB9, 0x55, 0x97,
  34572. 0x45, 0xA9, 0x61, 0xF8, 0xBE, 0x99, 0x00, 0x12,
  34573. 0xD8, 0x17, 0x62, 0xFB, 0x89, 0xE7, 0x05, 0x5E,
  34574. 0x1B, 0xCD, 0x2B, 0x09, 0x6C, 0x5A, 0x5C, 0xA3,
  34575. 0x66, 0x4D, 0x02, 0x78, 0x0C, 0xC3, 0x63, 0x30,
  34576. 0xD0, 0xFA, 0x7B, 0x11, 0x00, 0x40, 0xDD, 0xF0,
  34577. 0x8C, 0x7C, 0xBA, 0x4C, 0x63, 0x78, 0xDA, 0xBB,
  34578. 0xDF, 0xF9, 0xC9, 0xA4, 0x40, 0x25, 0x86, 0xD1,
  34579. 0xBA, 0x22, 0xD7, 0x69, 0x98, 0x4E, 0x9D, 0x15,
  34580. 0x21, 0xA8, 0x56, 0xC0, 0xFF, 0x52, 0xE4, 0xB4,
  34581. 0x0F, 0xB2, 0x53, 0xE7, 0xA1, 0x34, 0x18, 0xEA,
  34582. 0x5B, 0x25, 0x42, 0x13, 0xE3, 0x13, 0xE7, 0xDF,
  34583. 0x54, 0x2B, 0x8D, 0x70, 0x51, 0xC7, 0x60, 0xB1,
  34584. 0x1E, 0x4D, 0x3A, 0x46, 0x04, 0xA1, 0x11, 0x43,
  34585. 0xAD, 0x24, 0x29, 0x90, 0xC9, 0x04, 0x15, 0xC5,
  34586. 0x07, 0xE5, 0x46, 0xB8, 0x50, 0x16, 0x6B, 0x66,
  34587. 0xFE, 0x1C, 0x8B, 0xFC, 0x20, 0x9C, 0xC4, 0x88,
  34588. 0x10, 0x36, 0x5E, 0x56, 0xE8, 0x45, 0x75, 0x89,
  34589. 0xFB, 0xD6, 0xD0, 0x8D, 0x9D, 0x53, 0xAE, 0x89,
  34590. 0x19, 0x54, 0xCF, 0xE1, 0xFF, 0x12, 0x13, 0xF2,
  34591. 0xC7, 0xBE, 0x4C, 0x1E, 0xB0, 0x70, 0x6E, 0xDC,
  34592. 0x0A, 0x64, 0x3B, 0x60, 0x3A, 0xEA, 0x0D, 0x41,
  34593. 0xDD, 0x8E, 0x09, 0xB9, 0x96, 0x8F, 0x6A, 0x49,
  34594. 0x50, 0xEF, 0xDF, 0xD7, 0x73, 0x8D, 0x16, 0x32,
  34595. 0xA8, 0x5C, 0x0A, 0x90, 0x18, 0xA1, 0xEB, 0x19,
  34596. 0xCC, 0x50, 0xD5, 0x59, 0xD7, 0x35, 0x3F, 0xBA,
  34597. 0x38, 0x1B, 0x5F, 0x71, 0x56, 0x70, 0xB3, 0x20,
  34598. 0x4D, 0x9E, 0x16, 0xA8, 0xF7, 0x35, 0x19, 0xD2,
  34599. 0x09, 0x0A, 0x22, 0x28, 0x81, 0x61, 0x26, 0x5B,
  34600. 0x9C, 0xEC, 0x9D, 0x4A, 0x61, 0xCF, 0x0D, 0x3C,
  34601. 0x88, 0xEA, 0x0B, 0x7A, 0xA7, 0xC6, 0xAE, 0x31,
  34602. 0xBE, 0xC2, 0xBA, 0x48, 0xBB, 0x9D, 0x06, 0xE1,
  34603. 0x32, 0x6D, 0x80, 0xCE, 0x27, 0x5C, 0x6F, 0x13,
  34604. 0x79, 0x35, 0x9F, 0x9C, 0x11, 0xEA, 0xDB, 0xF5,
  34605. 0x49, 0x15, 0xB6, 0x51, 0x86, 0xFC, 0x62, 0x34,
  34606. 0x3D, 0x58, 0x6B, 0x0E, 0xF8, 0x3B, 0xBB, 0x42,
  34607. 0xF6, 0x2D, 0x5C, 0xE2, 0xF3, 0xAA, 0x9F, 0x03,
  34608. 0x43, 0xE9, 0x9E, 0x90, 0xB9, 0xFF, 0x55, 0x93,
  34609. 0x60, 0xF8, 0x10, 0x2F, 0xFC, 0xBD, 0x40, 0x23,
  34610. 0xB8, 0x4F, 0x4C, 0x7A, 0x74, 0x9F, 0xDC, 0x55,
  34611. 0xDF, 0x5E, 0xCD, 0x23, 0xEB, 0xAC, 0x47, 0x4E,
  34612. 0x0D, 0x0F, 0xBE, 0xDE, 0x02, 0x64, 0x61, 0x7E,
  34613. 0x73, 0x78, 0x8E, 0x25, 0xE9, 0x7D, 0x66, 0xE5,
  34614. 0x82, 0xBF, 0x98, 0x5B, 0x36, 0xCE, 0x17, 0x72,
  34615. 0x56, 0x9C, 0xDA, 0x63, 0x77, 0x55, 0x8B, 0xA9,
  34616. 0x75, 0xF5, 0x28, 0xC3, 0x78, 0x6D, 0x8F, 0xC2,
  34617. 0x75, 0x5F, 0x28, 0x9E, 0x3F, 0xFB, 0xF1, 0xFD,
  34618. 0xB7, 0xDE, 0x05, 0x3C, 0xD3, 0xE8, 0xD7, 0x7A,
  34619. 0x7D, 0xC9, 0xF7, 0x9D, 0x58, 0xB4, 0xA6, 0x21,
  34620. 0x25, 0xFC, 0x52, 0x84, 0x21, 0xF6, 0x0B, 0x6D,
  34621. 0xA6, 0x62, 0x51, 0x97, 0xCD, 0xA9, 0xA1, 0x0C,
  34622. 0x88, 0x21, 0x67, 0xA5, 0xFB, 0x8C, 0x8A, 0x50,
  34623. 0xC5, 0x21, 0x91, 0x3A, 0xAB, 0x95, 0x96, 0xF3,
  34624. 0x30, 0x6D, 0x08, 0x42, 0x07, 0x4B, 0x78, 0x1F,
  34625. 0xC1, 0xD3, 0x41, 0x15, 0x68, 0xED, 0x93, 0x09,
  34626. 0xC7, 0x8B, 0xF9, 0x77, 0x25, 0xD3, 0xCE, 0x2B,
  34627. 0xA2, 0x0D, 0xB4, 0xC6, 0x84, 0x7F, 0x8E, 0xE5,
  34628. 0x24, 0x46, 0x59, 0x8D, 0x6F, 0x0F, 0x0C, 0xA8,
  34629. 0xFC, 0x04, 0x9B, 0x4D, 0x2B, 0xA7, 0x70, 0x1F,
  34630. 0x46, 0x7E, 0x76, 0x03, 0xC6, 0x7E, 0xA5, 0x3D,
  34631. 0x79, 0xE2, 0xF1, 0xAC, 0xBC, 0xDD, 0xF6, 0x91,
  34632. 0x69, 0x4C, 0x44, 0x1F, 0xC3, 0xBF, 0x9F, 0xFC,
  34633. 0x4E, 0xB0, 0x79, 0x30, 0x68, 0x89, 0xAC, 0xF2,
  34634. 0xD7, 0xC6, 0xE1, 0x6C, 0x37, 0xFB, 0xB3, 0x38,
  34635. 0x44, 0x2C, 0x97, 0xAB, 0xDA, 0x2C, 0x88, 0xC7,
  34636. 0xF2, 0x80, 0x08, 0x00, 0x4E, 0x44, 0xED, 0xBE,
  34637. 0xA4, 0x28, 0x3D, 0xC1, 0xCF, 0x9E, 0x83, 0xE7,
  34638. 0x2E, 0x7F, 0xF5, 0x08, 0x47, 0x26, 0xE0, 0xBD,
  34639. 0x1A, 0x17, 0xDB, 0x2F, 0xED, 0x19, 0x2E, 0x65,
  34640. 0x1B, 0x62, 0x5F, 0x08, 0x82, 0x10, 0x61, 0xCB,
  34641. 0xAA, 0xA7, 0xF8, 0x59, 0x4B, 0x46, 0xCB, 0xA2,
  34642. 0xCB, 0x41, 0x34, 0x30, 0x51, 0x58, 0x2A, 0xEE,
  34643. 0xE1, 0x5E, 0xAC, 0xCA, 0xBF, 0x37, 0x45, 0x98,
  34644. 0xBD, 0x93, 0x1B, 0x5A, 0x5E, 0x92, 0x14, 0x05,
  34645. 0x75, 0x2D, 0xFB, 0x8F, 0xBD, 0x24, 0x9B, 0x81,
  34646. 0xCD, 0xDD, 0xF5, 0xBE, 0x05, 0x0D, 0xBD, 0x4B,
  34647. 0x2B, 0x8C, 0x0A, 0xF0, 0x3A, 0x85, 0xD6, 0x74,
  34648. 0x65, 0x7F, 0x98, 0xF8, 0x57, 0xA2, 0x36, 0xA2,
  34649. 0xFE, 0xE4, 0xB4, 0xA4, 0x0D, 0xEA, 0x9A, 0xBE,
  34650. 0x41, 0x79, 0x68, 0x63, 0x70, 0x3F, 0x3E, 0x38,
  34651. 0x60, 0xC3, 0x40, 0x81, 0x72, 0xDD, 0x25, 0x34,
  34652. 0xB4, 0xFE, 0xAC, 0x41, 0x6E, 0x4A, 0xE7, 0xBF,
  34653. 0xE3, 0x87, 0xFA, 0x20, 0x8B, 0xBD, 0x68, 0x9E,
  34654. 0x06, 0xA9, 0x15, 0x23, 0x07, 0x04, 0x4B, 0xFA,
  34655. 0x45, 0x45, 0xB7, 0x75, 0xD3, 0x3E, 0x16, 0x70,
  34656. 0xF6, 0x26, 0xF2, 0x3A, 0x9D, 0xFB, 0xEA, 0xEB,
  34657. 0x47, 0xCE, 0x99, 0x6B, 0x0E, 0xB2, 0xE8, 0x2B,
  34658. 0x18, 0x15, 0x14, 0x2E, 0xF2, 0x14, 0x0D, 0x44,
  34659. 0x47, 0x1E, 0x63, 0x84, 0x5B, 0x3F, 0xA8, 0xEF,
  34660. 0x5F, 0xEB, 0xA0, 0x41, 0x77, 0xC1, 0xF4, 0x4F,
  34661. 0x8E, 0x2E, 0x29, 0xCD, 0xDB, 0xF2, 0x75, 0x24,
  34662. 0x24, 0x46, 0x73, 0xC3, 0x46, 0xB5, 0xCA, 0x13,
  34663. 0x35, 0x12, 0x0A, 0x8D, 0x88, 0x89, 0x17, 0x99,
  34664. 0x13, 0xCA, 0x66, 0x07, 0x67, 0x6B, 0x7B, 0x3B,
  34665. 0x20, 0xD3, 0x5F, 0x78, 0x1C, 0xC0, 0x99, 0x59,
  34666. 0x0A, 0xBA, 0x8F, 0xA0, 0xDB, 0xDF, 0xCC, 0x03,
  34667. 0xC4, 0xA6, 0xC7, 0x08, 0xB9, 0xFD, 0x95, 0xC2,
  34668. 0x45, 0xF9, 0xF3, 0x11, 0x62, 0xF7, 0x14, 0xB9,
  34669. 0xEB, 0x09, 0xB3, 0x7C, 0xF8, 0xF6, 0x67, 0xCC,
  34670. 0x03, 0xB3, 0x06, 0x6F, 0x60, 0xAC, 0x72, 0xF2,
  34671. 0xD3, 0x71, 0x6C, 0x4D, 0xAD, 0x3A, 0x99, 0x75,
  34672. 0x5C, 0x52, 0x2D, 0x87, 0x69, 0x3E, 0xD6, 0x7E,
  34673. 0x12, 0x96, 0xD3, 0x88, 0x8D, 0x11, 0x85, 0xAA,
  34674. 0x0A, 0xA5, 0x32, 0x90, 0x51, 0xC5, 0x65, 0x64,
  34675. 0xE0, 0xA9, 0x73, 0xA4, 0xF3, 0x8A, 0x32, 0x83,
  34676. 0xE5, 0x08, 0x09, 0x39, 0x6A, 0x90, 0x2C, 0xC3,
  34677. 0xFC, 0x92, 0x29, 0x7A, 0x45, 0xBE, 0x02, 0x79,
  34678. 0x15, 0x1B, 0xBB, 0x60, 0xBB, 0xD9, 0x42, 0xF1,
  34679. 0xE5, 0x14, 0xB4, 0xA5, 0xFF, 0x12, 0x42, 0x30,
  34680. 0xB0, 0xCB, 0xD0, 0x1D, 0xB4, 0x62, 0x49, 0xC5,
  34681. 0xB7, 0xDA, 0x37, 0x47, 0x2C, 0x8B, 0x16, 0xCA,
  34682. 0xD2, 0x2C, 0xA1, 0x24, 0xE6, 0x57, 0xFA, 0xEB,
  34683. 0x2C, 0x62, 0x2E, 0x12, 0x74, 0x37, 0x2B, 0x3F,
  34684. 0x56, 0x23, 0x9C, 0xED, 0x90, 0xDE, 0x0D, 0x6E,
  34685. 0x9E, 0x11, 0x78, 0xA4, 0x9C, 0xB3, 0xA1, 0x37,
  34686. 0xF7, 0x4B, 0x09, 0x61, 0xD8, 0x33, 0x1D, 0x80,
  34687. 0x68, 0x5C, 0xDD, 0xBD, 0x3E, 0xAE, 0x9D, 0xB8,
  34688. 0xBA, 0x42, 0x41, 0xDC, 0xC9, 0x93, 0xF1, 0x92,
  34689. 0x2F, 0x7A, 0xF9, 0xFE, 0x67, 0x13, 0x87, 0xBD,
  34690. 0x7D, 0x04, 0x17, 0x91, 0xB6, 0x03, 0x5E, 0xA0,
  34691. 0x5B, 0x23, 0xEA, 0x0C, 0xFA, 0x45, 0xCB, 0x1A,
  34692. 0xC5, 0x7F, 0x63, 0xD6, 0x3D, 0x3C, 0x66, 0x4A,
  34693. 0x83, 0x4E, 0x4E, 0x90, 0xA6, 0x63, 0xB0, 0x8A,
  34694. 0xD7, 0x0D, 0xB4, 0xB7, 0xA9, 0x0F, 0xC6, 0xC7,
  34695. 0x3B, 0xAD, 0x07, 0xA6, 0x94, 0x47, 0xDB, 0x63,
  34696. 0x26, 0x00, 0x18, 0x5E, 0x27, 0xB5, 0xE2, 0xE3,
  34697. 0xED, 0x8D, 0x97, 0x95, 0x38, 0x20, 0x24, 0x9F,
  34698. 0x40, 0x84, 0x44, 0x7E, 0x8C, 0x05, 0xAB, 0xB1,
  34699. 0x89, 0x26, 0x7D, 0x46, 0x2C, 0x9F, 0xE5, 0xC1,
  34700. 0x27, 0xCE, 0x1D, 0x5A, 0x9F, 0xF1, 0xF8, 0x57,
  34701. 0x8F, 0xCF, 0xB7, 0x4E, 0x07, 0xF3, 0xBA, 0x56,
  34702. 0xCF, 0xE9, 0x87, 0x21, 0x61, 0xD6, 0x97, 0x7B,
  34703. 0x26, 0x97, 0x07, 0xB4, 0x87, 0xFE, 0x25, 0x9C,
  34704. 0xA9, 0x8E, 0x06, 0x90, 0x17, 0x2C, 0x98, 0x26,
  34705. 0x23, 0xEE, 0xBB, 0x91, 0x8A, 0x15, 0x38, 0xA1,
  34706. 0x38, 0xCB, 0x8B, 0xA0, 0xF3, 0x4A, 0xF2, 0x12,
  34707. 0xA7, 0xB7, 0x05, 0xB6, 0x09, 0xD0, 0xEC, 0xDD,
  34708. 0x21, 0xB6, 0xFA, 0x29, 0x95, 0xB4, 0x08, 0xD5,
  34709. 0x95, 0xB7, 0xB8, 0x2E, 0x23, 0xAA, 0x89, 0x81,
  34710. 0xE2, 0xD0, 0xFD, 0x9C, 0x8D, 0xF0, 0xCA, 0x61,
  34711. 0xE3, 0x1E, 0x73, 0x9E, 0xD1, 0x72, 0x5C, 0x63,
  34712. 0xB8, 0x74, 0x0E, 0x2C, 0x27, 0x3A, 0x71, 0xF9,
  34713. 0xFE, 0x66, 0x33, 0xE9, 0x41, 0x27, 0x61, 0xA3,
  34714. 0xFA, 0xD8, 0x66, 0x2A, 0x52, 0x6D, 0xAB, 0xBF,
  34715. 0x32, 0xC2, 0x8E, 0x8F, 0xB0, 0x60, 0x52, 0xE1,
  34716. 0x96, 0xC8, 0x1E, 0x9A, 0x3E, 0x07, 0xFA, 0x34,
  34717. 0xFA, 0x9C, 0x4C, 0x0D, 0x29, 0x0F, 0x68, 0xA6,
  34718. 0x59, 0x28, 0x22, 0xB1, 0x99, 0x56, 0x2C, 0x01,
  34719. 0x04, 0x2F, 0x34, 0x65, 0xFD, 0xD4, 0xD0, 0xD5,
  34720. 0x17, 0x7C, 0x14, 0x92, 0x73, 0x6C, 0x31, 0xCE,
  34721. 0xD4, 0xB3, 0x59, 0x83, 0x6B, 0x34, 0x7C, 0x76,
  34722. 0x8C, 0xED, 0xD5, 0xE2, 0x4F, 0x39, 0x44, 0xBF,
  34723. 0x90, 0x53, 0x9A, 0xC7, 0xD4, 0x6A, 0x86, 0xA3,
  34724. 0xE2, 0x15, 0x59, 0xD0, 0x0F, 0x32, 0x92, 0xC2,
  34725. 0x9B, 0x9E, 0xE3, 0xF6, 0x94, 0x96, 0xFD, 0x0B,
  34726. 0xB6, 0x06, 0x8F, 0x0D, 0x1F, 0x38, 0xFC, 0x6F,
  34727. 0xA2, 0x78, 0xAC, 0xC5, 0xB5, 0x6A, 0x6B, 0xEC,
  34728. 0x78, 0x8A, 0x6F, 0xD8, 0x21, 0xB7, 0xCF, 0x66,
  34729. 0x73, 0x03, 0xCA, 0x2E, 0x3C, 0x7F, 0x2F, 0x29,
  34730. 0x41, 0xC9, 0x88, 0xFD, 0x0E, 0xA0, 0x43, 0xD6,
  34731. 0x9E, 0xB1, 0xE7, 0x13, 0x9C, 0xF0, 0x9C, 0xCF,
  34732. 0x33, 0x22, 0x57, 0xEF, 0xE5, 0xCE, 0xD9, 0xAC,
  34733. 0x7D, 0x34, 0x75, 0xBD, 0xAE, 0x84, 0xEE, 0xE8,
  34734. 0x5D, 0x8C, 0x55, 0x86, 0xBA, 0x19, 0xE5, 0x9D,
  34735. 0x35, 0x6D, 0xD8, 0x70, 0xC5, 0xE0, 0xEA, 0x77,
  34736. 0x3A, 0xE5, 0xB5, 0x2C, 0xD2, 0x28, 0xB5, 0xE8,
  34737. 0xAF, 0xB1, 0xD2, 0xC4, 0xE5, 0x59, 0x06, 0xB8,
  34738. 0x2E, 0xA6, 0x8F, 0xC4, 0x9B, 0x30, 0xF9, 0x37,
  34739. 0xDB, 0x29, 0xA1, 0x44, 0x0B, 0xB7, 0xB5, 0xB4,
  34740. 0x12, 0xD3, 0x4E, 0xB3, 0xB7, 0xD8, 0x2F, 0x19,
  34741. 0xDE, 0x3B, 0xC3, 0x53, 0xCE, 0x1C, 0x34, 0x4C,
  34742. 0xA4, 0x6A, 0xE2, 0xD0, 0x04, 0xDF, 0x3C, 0x53,
  34743. 0x8B, 0x06, 0x8F, 0x36, 0xE5, 0x77, 0xB2, 0x7A,
  34744. 0x1A, 0xC0, 0x0C, 0xBD, 0xA3, 0xA0, 0xEE, 0xB6,
  34745. 0x40, 0xAD, 0x5C, 0x04, 0xAE, 0xCF, 0x64, 0x2B,
  34746. 0x8A, 0x18, 0x58, 0x86, 0xDE, 0xC9, 0x3D, 0x7D,
  34747. 0x15, 0xBC, 0xEE, 0x4C, 0x22, 0xF4, 0x98, 0xD9,
  34748. 0x37, 0xEE, 0xE2, 0x40, 0x43, 0xFF, 0xB2, 0x6F,
  34749. 0x05, 0xC0, 0x0E, 0x30, 0xDE, 0xD8, 0x0C, 0x0B,
  34750. 0xAD, 0xED, 0xCC, 0xBC, 0x29, 0x95, 0x07, 0x40,
  34751. 0x10, 0x99, 0xA0, 0xD1, 0x08, 0xF7, 0xD5, 0xF1,
  34752. 0xAD, 0xC9, 0xDD, 0xC8, 0x6A, 0x1E, 0x9E, 0x06,
  34753. 0xDF, 0x12, 0xFF, 0x66, 0x33, 0x5E, 0x21, 0x47,
  34754. 0xC3, 0xDE, 0x36, 0x98, 0x5B, 0xBF, 0x42, 0x9E,
  34755. 0x30, 0xA0, 0x81, 0x5C, 0x28, 0x34, 0x1B, 0x3A,
  34756. 0x32, 0xBC, 0xDE, 0x52, 0x53, 0x25, 0x1E, 0xF6,
  34757. 0xE2, 0x99, 0x12, 0x92, 0x07, 0x1D, 0xEB, 0x08,
  34758. 0x36, 0xA7, 0xD5, 0x18, 0x1F, 0xDB, 0x44, 0xA7,
  34759. 0xE1, 0x13, 0x06, 0xB0, 0xDF, 0x63, 0x82, 0x68,
  34760. 0xEF, 0xF5, 0x2B, 0x04, 0x0B, 0x93, 0xE8, 0xB0,
  34761. 0x92, 0x7B, 0xDE, 0x1F, 0xC9, 0x39, 0x8F, 0x42,
  34762. 0x9D, 0x06, 0x22, 0x13, 0xC9, 0x97, 0x2F, 0x43,
  34763. 0x8A, 0xBA, 0xAF, 0xF9, 0x71, 0xE3, 0x55, 0x5D,
  34764. 0x06, 0x77, 0x38, 0x39, 0xA3, 0xED, 0x41, 0x63,
  34765. 0xFE, 0x2A, 0xB3, 0x23, 0x43, 0x0C, 0xF3, 0x17,
  34766. 0x3B, 0x69, 0xED, 0x32, 0x0A, 0x54, 0xF3, 0x8D,
  34767. 0x76, 0xC6, 0x09, 0xDD, 0x88, 0x5B, 0x23, 0x57,
  34768. 0x72, 0xC4, 0x87, 0xB8, 0x9D, 0xF7, 0xCA, 0xFB,
  34769. 0x7C, 0x61, 0x67, 0x5C, 0x65, 0xF8, 0xD6, 0xD7,
  34770. 0x1E, 0x95, 0xB9, 0x73, 0x4D, 0x2E, 0x1F, 0x43,
  34771. 0x3E, 0x2B, 0x58, 0x92, 0x15, 0x2E, 0xAA, 0x51,
  34772. 0xF0, 0xD4, 0xF2, 0xA6, 0xCD, 0x12, 0x21, 0xD6,
  34773. 0xCA, 0x46, 0x2A, 0xFF, 0xCB, 0x1B, 0x6B, 0xB4,
  34774. 0x09, 0x17, 0x3B, 0xA2, 0x94, 0xDF, 0x1D, 0x68,
  34775. 0x8B, 0x75, 0xEA, 0x11, 0xD6, 0x99, 0x04, 0xD1,
  34776. 0x00, 0xDB, 0x61, 0xBC, 0xF2, 0x3B, 0x88, 0x4B,
  34777. 0x33, 0xDF, 0x0F, 0xD4, 0xFB, 0x14, 0x0C, 0x6A,
  34778. 0x53, 0x61, 0x1F, 0xBD, 0x28, 0xB2, 0x11, 0x19,
  34779. 0x38, 0x71, 0x17, 0x76, 0x4D, 0xEE, 0x01, 0xC4,
  34780. 0x77, 0x53, 0x2A, 0xAF, 0xD3, 0x78, 0xFF, 0x45,
  34781. 0x7F, 0x97, 0x9D, 0x26, 0x92, 0x0E, 0xD9, 0x4E,
  34782. 0x34, 0x1D, 0xE8, 0xDD, 0xBF, 0x5F, 0x87, 0xE6,
  34783. 0x35, 0x9A, 0x39, 0x71, 0x59, 0x20, 0x01, 0xFB,
  34784. 0x53, 0x2C, 0x61, 0x38, 0x0C, 0x8C, 0x02, 0xD3,
  34785. 0xA0, 0x53, 0x95, 0x02, 0xED, 0x5C, 0xFE, 0x9B,
  34786. 0xD3, 0x6A, 0xF3, 0x3F, 0x92, 0x6F, 0x33, 0x37,
  34787. 0x19, 0x97, 0x81, 0x3A, 0x50, 0xE1, 0xD9, 0x27,
  34788. 0x7E, 0x64, 0xF8, 0x01, 0x52, 0x26, 0x51, 0xD1,
  34789. 0x06, 0xAF, 0x20, 0xA0, 0x28, 0x0F, 0x3F, 0xCB,
  34790. 0x21, 0xB7, 0x55, 0x1A, 0x76, 0xB8, 0x9B, 0x4D,
  34791. 0xED, 0x2A, 0x05, 0x0E, 0x6E, 0xAF, 0xCC, 0xA1,
  34792. 0x08, 0x9C, 0xBE, 0x3F, 0x98, 0xE6, 0xB4, 0xB9,
  34793. 0x83, 0xC9, 0x08, 0x41, 0x96, 0xDD, 0xD9, 0x0D,
  34794. 0x52, 0x66, 0x94, 0xA4, 0xEA, 0xFC, 0xE5, 0x48,
  34795. 0x04, 0x73, 0x64, 0x79, 0x68, 0xC9, 0x4A, 0x81,
  34796. 0xA8, 0x07, 0xF8, 0xD9, 0x4E, 0x07, 0x1E, 0xC1,
  34797. 0x8F, 0x62, 0xAB, 0xA6, 0xD7, 0x68, 0xFC, 0x57,
  34798. 0x5E, 0x75, 0x1B, 0xBF, 0x3D, 0xA6, 0x91, 0xC5,
  34799. 0x08, 0x14, 0x5E, 0xF2, 0x4C, 0x22, 0x8B, 0x4E,
  34800. 0x29, 0x2D, 0xC0, 0x46, 0x3A, 0x9C, 0x9D, 0x86,
  34801. 0xCF, 0x51, 0x85, 0x9D, 0x93, 0x23, 0xA1, 0xA1,
  34802. 0xF3, 0x76, 0xB1, 0x56, 0xB0, 0xF4, 0x1F, 0x39,
  34803. 0xDA, 0xDB, 0x13, 0x70, 0x29, 0x89, 0x95, 0xD2,
  34804. 0xC5, 0xF3, 0x76, 0xFE, 0xEE, 0x99, 0xCF, 0xA0,
  34805. 0x84, 0xEC, 0x70, 0xF0, 0xD3, 0xFA, 0x42, 0xDB,
  34806. 0xFD, 0x99, 0x65, 0x2F, 0x84, 0x11, 0x99, 0xCD,
  34807. 0x38, 0xB3, 0x1B, 0xAB, 0x8C, 0x2D, 0x33, 0x04,
  34808. 0xCA, 0xE1, 0xB3, 0x05, 0x9A, 0x20, 0x80, 0xDB,
  34809. 0xED, 0x59, 0x42, 0x30, 0x48, 0x37, 0xB3, 0x85,
  34810. 0x5C, 0xEE, 0x54, 0x06, 0x92, 0x97, 0x4E, 0xFC,
  34811. 0xFA, 0xF7, 0x25, 0xE0, 0x4E, 0x57, 0xC4, 0x72,
  34812. 0x38, 0x59, 0xCA, 0x3C, 0x4A, 0x3F, 0x09, 0xD6,
  34813. 0x09, 0x15, 0x83, 0xEF, 0x24, 0x21, 0xDD, 0xFD,
  34814. 0x66, 0x9E, 0xBF, 0xEE, 0xCC, 0xBF, 0x86, 0x20,
  34815. 0x29, 0x40, 0x5E, 0x42, 0xD2, 0xC0, 0x24, 0x2D,
  34816. 0x76, 0xE6, 0x64, 0xF9, 0x5D, 0xC2, 0x85, 0xB6,
  34817. 0x09, 0x41, 0x04, 0x62, 0x17, 0xDC, 0xF8, 0xFA,
  34818. 0x2A, 0x4C, 0xD1, 0x82, 0x31, 0x57, 0xB7, 0x2B,
  34819. 0x49, 0xE8, 0x40, 0x13, 0x2A, 0xA1, 0x86, 0xD2,
  34820. 0x9A, 0xB8, 0xA9, 0xBE, 0x39, 0xBE, 0xE9, 0xA5,
  34821. 0x35, 0x12, 0x08, 0xF1, 0xA9, 0x9E, 0x57, 0x46,
  34822. 0x3A, 0x55, 0x16, 0xA7, 0x41, 0xD9, 0x25, 0xB8,
  34823. 0x2F, 0xAF, 0xA8, 0x81, 0x5F, 0x5F, 0x46, 0xA4,
  34824. 0x3B, 0xB3, 0xE9, 0x1B, 0x74, 0xEF, 0x5D, 0x57,
  34825. 0x48, 0x4A, 0x72, 0x08, 0xDA, 0xFE, 0x1D, 0x55,
  34826. 0x6B, 0xAB, 0x8B, 0x13, 0x18, 0xBF, 0xDD, 0xF4,
  34827. 0x4E, 0x01, 0x5F, 0x4B, 0xF6, 0x80, 0xD4, 0x16,
  34828. 0x4B, 0x2F, 0x03, 0x4B, 0xF8, 0x93, 0x20, 0x21,
  34829. 0x55, 0x52, 0x49, 0x4A, 0x6C, 0x1F, 0x7D, 0xAD,
  34830. 0x04, 0xEF, 0xB3, 0x74, 0xEE, 0xC5, 0xB6, 0xBC,
  34831. 0x33, 0x7A, 0xCF, 0x64, 0xB9, 0xF9, 0x41, 0x70,
  34832. 0xAF, 0xE9, 0xC7, 0xD6, 0x25, 0x18, 0x17, 0xAB,
  34833. 0xBA, 0xC9, 0x05, 0xEF, 0x40, 0x89, 0xD5, 0x69,
  34834. 0x76, 0xAA, 0xA0, 0x3E, 0x4D, 0x1C, 0xE7, 0x9D,
  34835. 0x9E, 0x74, 0xF4, 0xF2, 0x7B, 0x40, 0xF6, 0x57,
  34836. 0x78, 0x66, 0xFC, 0xDA, 0xE3, 0x6B, 0xD2, 0x6E,
  34837. 0xC7, 0x9D, 0x65, 0x84, 0xAF, 0x7A, 0x1F, 0xE4,
  34838. 0x34, 0xD4, 0x1A, 0x17, 0xA2, 0x72, 0xB0, 0xEE,
  34839. 0x5A, 0x0C, 0xF4, 0x02, 0xAC, 0x1D, 0x6F, 0x4A,
  34840. 0xD0, 0xB2, 0x02, 0x3A, 0x7D, 0x2C, 0xF1, 0x43,
  34841. 0x0E, 0x1E, 0x96, 0xEB, 0x42, 0xF8, 0x3A, 0xF5,
  34842. 0x0B, 0x5D, 0xA9, 0x23, 0x02, 0x28, 0xE5, 0x26,
  34843. 0x5E, 0x69, 0x38, 0x2F, 0x85, 0x34, 0x32, 0x5E,
  34844. 0x5E, 0x29, 0x33, 0x94, 0x05, 0xBD, 0x58, 0xF8,
  34845. 0xE8, 0x9C, 0xBF, 0xB1, 0x5A, 0x05, 0xC6, 0x23,
  34846. 0x9B, 0xBB, 0x57, 0x69, 0x8C, 0xE6, 0x41, 0x97,
  34847. 0x48, 0x01, 0x95, 0xAF, 0xE9, 0x62, 0x8C, 0x6F,
  34848. 0x09, 0x43, 0xF3, 0x64, 0x50, 0x90, 0x2F, 0x14,
  34849. 0xF7, 0x30, 0x07, 0xE0, 0x4B, 0xA8, 0x39, 0xAC,
  34850. 0x21, 0xC4, 0x07, 0x45, 0x5F, 0xD9, 0x87, 0xB1,
  34851. 0x57, 0x47, 0x07, 0x66, 0xFF, 0xC7, 0xAB, 0xEE,
  34852. 0x1F, 0x55, 0x71, 0x50, 0x63, 0xCF, 0x58, 0x3B,
  34853. 0xC8, 0x1B, 0xEA, 0xA5, 0xE2, 0xF1, 0x57, 0xB3,
  34854. 0x77, 0x65, 0xA9, 0xBD, 0x23, 0xC8, 0x30, 0x86,
  34855. 0xC3, 0x5F, 0xBF, 0x16, 0x3F, 0x42, 0x28, 0x0A,
  34856. 0xC6, 0x5A, 0x57, 0x15, 0x2F, 0xA1, 0x96, 0xA9,
  34857. 0x25, 0xC5, 0x8E, 0x32, 0x11, 0x62, 0xB3, 0x54,
  34858. 0x18, 0x00, 0xA4, 0xA6, 0xD4, 0x0F, 0x68, 0x27,
  34859. 0x8F, 0x21, 0x78, 0x02, 0x37, 0x98, 0xBD, 0xCE,
  34860. 0x3F, 0xBC, 0xF2, 0x9C, 0x66, 0x8E, 0x79, 0xA1,
  34861. 0x54, 0x12, 0x55, 0x2E, 0xC0, 0x59, 0xC7, 0x18,
  34862. 0x18, 0x22, 0x4D, 0x27, 0x8B, 0x8D, 0xF3, 0x08,
  34863. 0x99, 0xE6, 0x35, 0x14, 0xB1, 0xE3, 0xB8, 0x7A,
  34864. 0x40, 0x7B, 0x68, 0x7B, 0xFF, 0xDC, 0x54, 0x41,
  34865. 0x06, 0xCA, 0x91, 0xFE, 0xDB, 0x2B, 0xDA, 0x9E,
  34866. 0xC5, 0x20, 0xD8, 0xBF, 0x42, 0xBC, 0xE6, 0x39,
  34867. 0xC4, 0x26, 0x9E, 0xF3, 0x82, 0xD9, 0xF1, 0xA0,
  34868. 0x04, 0xAF, 0xFB, 0x77, 0x13, 0x36, 0xAF, 0xD7,
  34869. 0x91, 0x9B, 0x3A, 0x57, 0x98, 0xFE, 0xAD, 0xCD,
  34870. 0x46, 0xF8, 0xF8, 0xF1, 0x87, 0x53, 0xBD, 0x57,
  34871. 0x3F, 0x99, 0xBC, 0xA6, 0xBD, 0x9B, 0x6E, 0xF4,
  34872. 0x17, 0x7A, 0x78, 0x30, 0x70, 0xA3, 0x43, 0xFF,
  34873. 0x92, 0xCD, 0x99, 0x73, 0xAE, 0x65, 0x6A, 0x10,
  34874. 0xFF, 0x70, 0x47, 0x0F, 0x16, 0x4C, 0x4A, 0x90,
  34875. 0xF4, 0x52, 0x05, 0x79, 0x33, 0x63, 0xDE, 0x14,
  34876. 0x65, 0xAF, 0x8A, 0x5E, 0x67, 0x20, 0x03, 0x9F,
  34877. 0xE6, 0x70, 0x13, 0x6B, 0xE0, 0xF3, 0x6A, 0x4C,
  34878. 0x6B, 0x5B, 0xCB, 0xE1, 0x7C, 0x5D, 0x7D, 0xE3,
  34879. 0x23, 0xFD, 0xB8, 0x6A, 0xDA, 0x56, 0x1E, 0xA8,
  34880. 0x36, 0xC4, 0x29, 0x2D, 0x70, 0x41, 0x03, 0x18,
  34881. 0x31, 0x40, 0x79, 0x2E, 0xC8, 0x22, 0x98, 0x5E,
  34882. 0x11, 0xED, 0xA6, 0xDD, 0xB9, 0xAF, 0x8C, 0x27,
  34883. 0x5C, 0x1B, 0x2E, 0xEA, 0xB8, 0xC6, 0x2F, 0xA0,
  34884. 0x40, 0xB2, 0x64, 0x61, 0xFC, 0x0A, 0x3A, 0x10,
  34885. 0x88, 0xC2, 0x58, 0xEC, 0xA5, 0x8D, 0x14, 0xE9,
  34886. 0x9D, 0x21, 0xAF, 0x64, 0xD6, 0xC2, 0x5D, 0xAA,
  34887. 0x0B, 0x8A, 0x57, 0x0F, 0x84, 0x3E, 0x60, 0x8D,
  34888. 0xED, 0x05, 0x1D, 0x98, 0xED, 0xAE, 0x11, 0xD9,
  34889. 0x27, 0x03, 0x55, 0xED, 0xF5, 0x34, 0x92, 0x52,
  34890. 0xF2, 0x6F, 0x30, 0x3E, 0x69, 0xA5, 0x54, 0xA7,
  34891. 0x2E, 0x1B, 0x85, 0xAB, 0xA2, 0x3B, 0xEC, 0xC8,
  34892. 0x9D, 0xA9, 0xA3, 0xE4, 0xEF, 0x58, 0xB5, 0x33,
  34893. 0x88, 0x55, 0x16, 0x5E, 0x7D, 0x7E, 0x69, 0xFC,
  34894. 0xCA, 0xBD, 0x9C, 0x65, 0xFA, 0x0B, 0xBD, 0x7B,
  34895. 0x16, 0xC4, 0xE2, 0x9C, 0xB4, 0xF1, 0x6A, 0x25,
  34896. 0x70, 0x30, 0x32, 0xED, 0xEA, 0xD3, 0x1D, 0xDB,
  34897. 0x6F, 0x29, 0x2E, 0x42, 0x14, 0xBE, 0x03, 0x29,
  34898. 0x0A, 0x8A, 0x98, 0x9A, 0xD7, 0xB7, 0x0C, 0xF8,
  34899. 0xB9, 0xCF, 0x37, 0xC6, 0xAC, 0xAC, 0x6D, 0xCC,
  34900. 0x03, 0x23, 0x9F, 0x66, 0x85, 0x4B, 0x70, 0x45
  34901. };
  34902. #endif /* WOLFSSL_NO_ML_DSA_87 */
  34903. #endif
  34904. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  34905. ExpectNotNull(key);
  34906. if (key != NULL) {
  34907. XMEMSET(key, 0, sizeof(*key));
  34908. }
  34909. ExpectIntEQ(wc_dilithium_init_ex(key, NULL, INVALID_DEVID), 0);
  34910. #ifndef WOLFSSL_NO_ML_DSA_44
  34911. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  34912. ExpectIntEQ(wc_dilithium_make_key_from_seed(key, seed_44), 0);
  34913. ExpectIntEQ(XMEMCMP(key->p, pk_44, sizeof(pk_44)), 0);
  34914. ExpectIntEQ(XMEMCMP(key->k, sk_44, sizeof(sk_44)), 0);
  34915. #endif
  34916. #ifndef WOLFSSL_NO_ML_DSA_65
  34917. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  34918. ExpectIntEQ(wc_dilithium_make_key_from_seed(key, seed_65), 0);
  34919. ExpectIntEQ(XMEMCMP(key->p, pk_65, sizeof(pk_65)), 0);
  34920. ExpectIntEQ(XMEMCMP(key->k, sk_65, sizeof(sk_65)), 0);
  34921. #endif
  34922. #ifndef WOLFSSL_NO_ML_DSA_87
  34923. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  34924. ExpectIntEQ(wc_dilithium_make_key_from_seed(key, seed_87), 0);
  34925. ExpectIntEQ(XMEMCMP(key->p, pk_87, sizeof(pk_87)), 0);
  34926. ExpectIntEQ(XMEMCMP(key->k, sk_87, sizeof(sk_87)), 0);
  34927. #endif
  34928. wc_dilithium_free(key);
  34929. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  34930. #endif
  34931. return EXPECT_RESULT();
  34932. }
  34933. static int test_wc_dilithium_sig_kats(void)
  34934. {
  34935. EXPECT_DECLS;
  34936. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  34937. !defined(WOLFSSL_DILITHIUM_NO_SIGN) && \
  34938. !defined(WOLFSSL_DILITHIUM_FIPS204_DRAFT)
  34939. dilithium_key* key;
  34940. #ifndef WOLFSSL_NO_ML_DSA_44
  34941. static const byte sk_44[] = {
  34942. 0x5D, 0xFB, 0x07, 0xA2, 0x04, 0x4B, 0x93, 0x16,
  34943. 0x75, 0xC7, 0x89, 0x43, 0xEA, 0xC3, 0xC4, 0xC5,
  34944. 0x7B, 0x07, 0x77, 0x8A, 0xD9, 0xAF, 0x2E, 0x87,
  34945. 0xC4, 0x70, 0xB9, 0xCC, 0x2C, 0x8D, 0xA1, 0xE3,
  34946. 0x75, 0xBC, 0xB3, 0xBC, 0xD1, 0x9E, 0x7B, 0xB9,
  34947. 0x83, 0xC9, 0x63, 0x66, 0xCC, 0xEA, 0x14, 0x1E,
  34948. 0xAE, 0x22, 0x07, 0x75, 0x52, 0x24, 0xC8, 0xC6,
  34949. 0xC6, 0x1F, 0x90, 0x89, 0x89, 0xCF, 0xF2, 0xF6,
  34950. 0x27, 0x98, 0xA6, 0x86, 0x45, 0x77, 0x95, 0x15,
  34951. 0xD4, 0x74, 0xDD, 0xA6, 0x1F, 0x33, 0x41, 0x42,
  34952. 0x4E, 0xDA, 0x24, 0x79, 0x60, 0x27, 0x34, 0x4E,
  34953. 0x36, 0x94, 0x14, 0x74, 0x81, 0x9A, 0x58, 0x44,
  34954. 0x2B, 0x74, 0xBF, 0x50, 0x60, 0xB8, 0x40, 0x94,
  34955. 0x4A, 0xEF, 0xDE, 0xA7, 0xA4, 0xCF, 0xFC, 0xB3,
  34956. 0x9D, 0xE2, 0x07, 0xFD, 0x9E, 0x6A, 0xC6, 0x2E,
  34957. 0x6D, 0x0D, 0xB2, 0xB4, 0x51, 0x2E, 0x20, 0x26,
  34958. 0x00, 0xB5, 0x30, 0x01, 0xA9, 0x2D, 0xE2, 0x42,
  34959. 0x02, 0x42, 0x12, 0x71, 0x24, 0xB7, 0x28, 0x94,
  34960. 0x30, 0x86, 0xDA, 0x22, 0x30, 0x00, 0x87, 0x65,
  34961. 0xCC, 0x22, 0x91, 0x1B, 0x05, 0x82, 0x03, 0x46,
  34962. 0x8A, 0xA0, 0x32, 0x26, 0x40, 0xB4, 0x84, 0xC3,
  34963. 0x14, 0x2D, 0x88, 0x14, 0x8C, 0x94, 0x92, 0x49,
  34964. 0x23, 0x15, 0x0E, 0xCA, 0x88, 0x09, 0x18, 0x94,
  34965. 0x68, 0x82, 0x38, 0x00, 0x21, 0x41, 0x28, 0x8C,
  34966. 0xB8, 0x80, 0x02, 0x09, 0x49, 0x5A, 0xB4, 0x11,
  34967. 0x9B, 0x28, 0x05, 0xE4, 0x42, 0x30, 0xCA, 0x24,
  34968. 0x80, 0xA4, 0x06, 0x2A, 0xD3, 0x92, 0x05, 0x1C,
  34969. 0x03, 0x6A, 0x22, 0x36, 0x4A, 0x92, 0x44, 0x52,
  34970. 0xE2, 0x48, 0x28, 0x19, 0x83, 0x68, 0x88, 0xC6,
  34971. 0x31, 0x41, 0x90, 0x50, 0x00, 0x43, 0x8E, 0x23,
  34972. 0x87, 0x60, 0x19, 0x43, 0x81, 0x50, 0x32, 0x69,
  34973. 0x81, 0xC0, 0x51, 0x12, 0x06, 0x08, 0x02, 0x08,
  34974. 0x82, 0xC4, 0xA6, 0x81, 0x03, 0xA5, 0x90, 0x8C,
  34975. 0xB6, 0x00, 0x90, 0x14, 0x66, 0x01, 0xB1, 0x08,
  34976. 0x12, 0x25, 0x48, 0x1A, 0x88, 0x11, 0x43, 0x38,
  34977. 0x60, 0x23, 0x26, 0x2E, 0x14, 0x45, 0x0D, 0x9C,
  34978. 0x92, 0x8C, 0xA2, 0x46, 0x12, 0x94, 0xA6, 0x05,
  34979. 0x88, 0xB0, 0x11, 0x0A, 0xB0, 0x28, 0xA4, 0x42,
  34980. 0x09, 0x9C, 0x82, 0x80, 0x1A, 0x80, 0x61, 0x59,
  34981. 0xB0, 0x8D, 0x40, 0xA6, 0x6D, 0x12, 0xC9, 0x0C,
  34982. 0xD9, 0x18, 0x68, 0xA3, 0x84, 0x2C, 0x02, 0xB6,
  34983. 0x25, 0x01, 0x40, 0x2C, 0xD8, 0x20, 0x4D, 0x1B,
  34984. 0x35, 0x30, 0x11, 0x10, 0x49, 0x63, 0x44, 0x31,
  34985. 0x8A, 0xB2, 0x70, 0x4B, 0x24, 0x28, 0xA0, 0x46,
  34986. 0x08, 0xC9, 0x06, 0x81, 0x08, 0xC5, 0x04, 0x4A,
  34987. 0xB2, 0x30, 0x08, 0x15, 0x04, 0x24, 0xA2, 0x65,
  34988. 0x9B, 0x88, 0x41, 0x19, 0x36, 0x2E, 0xE2, 0xB8,
  34989. 0x29, 0xD9, 0x12, 0x64, 0x41, 0xA6, 0x30, 0x22,
  34990. 0xB7, 0x8C, 0x93, 0x38, 0x69, 0x93, 0x30, 0x0A,
  34991. 0xC8, 0xB6, 0x85, 0x23, 0xB1, 0x8D, 0x01, 0x38,
  34992. 0x0A, 0x59, 0xA0, 0x09, 0x64, 0x12, 0x6E, 0x88,
  34993. 0x08, 0x22, 0xDB, 0x00, 0x08, 0x0C, 0x08, 0x12,
  34994. 0x99, 0x42, 0x44, 0x1B, 0x00, 0x68, 0x08, 0x13,
  34995. 0x26, 0x53, 0xA2, 0x40, 0x5A, 0x34, 0x25, 0x98,
  34996. 0x90, 0x8C, 0x00, 0x34, 0x2D, 0x93, 0x94, 0x48,
  34997. 0xC8, 0x22, 0x4C, 0xE2, 0x44, 0x29, 0xE2, 0x00,
  34998. 0x28, 0x14, 0x22, 0x40, 0x48, 0x28, 0x24, 0x22,
  34999. 0x49, 0x06, 0xCA, 0xC8, 0x0C, 0x4C, 0x12, 0x80,
  35000. 0x1B, 0xA5, 0x41, 0x11, 0x06, 0x48, 0x1B, 0x27,
  35001. 0x72, 0x20, 0x07, 0x31, 0x24, 0x10, 0x8E, 0x9C,
  35002. 0x94, 0x91, 0x1B, 0x37, 0x82, 0x51, 0x28, 0x2E,
  35003. 0x11, 0x06, 0x42, 0x01, 0x34, 0x6E, 0x8C, 0x22,
  35004. 0x25, 0x24, 0x34, 0x6A, 0x19, 0x47, 0x21, 0x23,
  35005. 0xB6, 0x09, 0x51, 0xB2, 0x31, 0x18, 0x34, 0x45,
  35006. 0x8C, 0xB8, 0x20, 0x1C, 0x19, 0x0A, 0x19, 0xB7,
  35007. 0x6D, 0x18, 0x97, 0x48, 0x09, 0x82, 0x04, 0x9C,
  35008. 0x12, 0x8A, 0x41, 0x08, 0x46, 0x24, 0x13, 0x31,
  35009. 0xD0, 0x42, 0x46, 0xC3, 0x16, 0x80, 0x51, 0x10,
  35010. 0x2E, 0x51, 0x48, 0x04, 0x5C, 0xC2, 0x64, 0x1A,
  35011. 0x10, 0x8E, 0xD9, 0x86, 0x64, 0x90, 0x24, 0x68,
  35012. 0x93, 0xB4, 0x45, 0x94, 0x30, 0x4A, 0xE3, 0x12,
  35013. 0x0C, 0x54, 0x04, 0x90, 0x03, 0x31, 0x40, 0x62,
  35014. 0x92, 0x4D, 0x5C, 0xC8, 0x10, 0x8A, 0xB8, 0x61,
  35015. 0x5C, 0x04, 0x6A, 0xC8, 0xB0, 0x85, 0x93, 0x00,
  35016. 0x05, 0xC3, 0x06, 0x69, 0x1B, 0x34, 0x8E, 0x03,
  35017. 0x84, 0x0C, 0x50, 0x00, 0x2C, 0x8C, 0x96, 0x90,
  35018. 0x08, 0x32, 0x68, 0x0B, 0x90, 0x8C, 0x02, 0x86,
  35019. 0x2D, 0x18, 0x38, 0x09, 0x1C, 0xB2, 0x21, 0x1B,
  35020. 0x48, 0x04, 0x5C, 0x10, 0x86, 0xD8, 0x34, 0x51,
  35021. 0x43, 0x84, 0x88, 0x43, 0xB2, 0x65, 0x12, 0xB6,
  35022. 0x8D, 0x03, 0x01, 0x45, 0x19, 0xB8, 0x8D, 0x92,
  35023. 0x26, 0x4E, 0x12, 0x12, 0x88, 0x52, 0xB2, 0x64,
  35024. 0x21, 0x09, 0x26, 0x49, 0x38, 0x05, 0x24, 0x11,
  35025. 0x0A, 0x22, 0x38, 0x32, 0x23, 0x31, 0x20, 0x4A,
  35026. 0x24, 0x42, 0xC4, 0xA2, 0x44, 0x20, 0x10, 0x0D,
  35027. 0xA1, 0xA8, 0x51, 0x23, 0x86, 0x84, 0x81, 0x38,
  35028. 0x8E, 0x02, 0x00, 0x4A, 0x1C, 0xB7, 0x24, 0x4C,
  35029. 0x06, 0x0A, 0x1C, 0x26, 0x4E, 0xCC, 0x22, 0x48,
  35030. 0x4C, 0x92, 0x2D, 0xC0, 0x20, 0x2D, 0xA1, 0x16,
  35031. 0x89, 0xC3, 0x44, 0x82, 0x19, 0xA7, 0x6D, 0xC4,
  35032. 0x90, 0x10, 0x01, 0x82, 0x89, 0xD8, 0x44, 0x22,
  35033. 0xD9, 0x98, 0x20, 0xC0, 0x88, 0x45, 0x88, 0x22,
  35034. 0x0C, 0x90, 0x36, 0x90, 0x90, 0xA4, 0x05, 0xD3,
  35035. 0x82, 0x21, 0xD0, 0xA6, 0x28, 0x00, 0x33, 0x25,
  35036. 0xA2, 0xC2, 0x6C, 0xD8, 0x10, 0x71, 0xD1, 0x96,
  35037. 0x50, 0xC3, 0x34, 0x08, 0x8B, 0x94, 0x2D, 0x61,
  35038. 0x88, 0x04, 0x1B, 0xC8, 0x2D, 0xE2, 0x30, 0x64,
  35039. 0x20, 0x28, 0x24, 0x1A, 0x34, 0x50, 0x10, 0x25,
  35040. 0x6A, 0x64, 0x36, 0x81, 0x09, 0xC1, 0x45, 0xE3,
  35041. 0x30, 0x80, 0xC3, 0xA6, 0x8C, 0xE0, 0xB6, 0x10,
  35042. 0xC3, 0x34, 0x8D, 0xD1, 0x06, 0x11, 0x88, 0x20,
  35043. 0x0A, 0x0A, 0xC8, 0x21, 0x20, 0x81, 0x30, 0x9C,
  35044. 0x14, 0x61, 0x9B, 0xC2, 0x50, 0x22, 0x15, 0x8D,
  35045. 0x80, 0xA0, 0x41, 0x89, 0x24, 0x41, 0x20, 0x93,
  35046. 0x40, 0x01, 0xA6, 0x09, 0x08, 0x25, 0x2E, 0xC1,
  35047. 0xC6, 0x85, 0x00, 0x17, 0x62, 0x41, 0x30, 0x32,
  35048. 0xDC, 0x06, 0x6D, 0x48, 0x88, 0x08, 0x84, 0xC8,
  35049. 0x30, 0x5B, 0x96, 0x8D, 0x42, 0xB4, 0x4C, 0xD0,
  35050. 0x34, 0x88, 0xD0, 0x04, 0x02, 0x18, 0x15, 0x52,
  35051. 0x52, 0x26, 0x30, 0x8C, 0x46, 0x28, 0x20, 0x94,
  35052. 0x4C, 0x21, 0x18, 0x00, 0xD0, 0xB2, 0x48, 0x1B,
  35053. 0x17, 0x0A, 0x09, 0x30, 0x4C, 0x44, 0xC2, 0x04,
  35054. 0x47, 0x5E, 0xF2, 0x33, 0x31, 0xFF, 0x66, 0x73,
  35055. 0xE2, 0x6E, 0x6A, 0x32, 0xF2, 0x94, 0xBE, 0xFB,
  35056. 0xD5, 0x96, 0x4F, 0xED, 0x98, 0x7A, 0x42, 0xA2,
  35057. 0x35, 0xFC, 0x5B, 0x16, 0x08, 0x61, 0x45, 0xC0,
  35058. 0xB8, 0xA8, 0x23, 0xFB, 0xC1, 0x4F, 0x1C, 0x8C,
  35059. 0xD0, 0x3F, 0xD6, 0xEE, 0xC4, 0x95, 0x28, 0x3E,
  35060. 0x03, 0x5C, 0x0D, 0xCA, 0xE5, 0x2E, 0x68, 0xF3,
  35061. 0x29, 0xDE, 0x7A, 0xDF, 0xD6, 0x4F, 0xEE, 0x0B,
  35062. 0x11, 0x6D, 0x4A, 0x14, 0xE1, 0x53, 0x94, 0xB3,
  35063. 0x1D, 0xF8, 0x8B, 0xCA, 0x10, 0xD1, 0xC9, 0x06,
  35064. 0xAA, 0x82, 0x28, 0x7C, 0x11, 0x74, 0x99, 0xE9,
  35065. 0xD8, 0xC7, 0x7D, 0x17, 0xA9, 0x5C, 0xCC, 0x14,
  35066. 0xAF, 0xF9, 0xC2, 0x05, 0xD2, 0x64, 0x80, 0xA5,
  35067. 0x70, 0xB5, 0x77, 0x0B, 0x04, 0x81, 0x99, 0xCF,
  35068. 0x3F, 0x0E, 0x1B, 0x91, 0xAB, 0x39, 0x4B, 0x1F,
  35069. 0x65, 0xD4, 0x7F, 0x92, 0x98, 0xD0, 0x96, 0xCA,
  35070. 0x25, 0xC0, 0x99, 0xBC, 0x67, 0xF4, 0x33, 0x42,
  35071. 0x63, 0xE3, 0x6B, 0xD9, 0xE6, 0x6B, 0x99, 0x8A,
  35072. 0x07, 0xDC, 0x1E, 0x18, 0x1E, 0x05, 0x38, 0x6E,
  35073. 0x96, 0x8F, 0x1C, 0xB0, 0xAB, 0x1E, 0x9A, 0x67,
  35074. 0xD5, 0xD3, 0x30, 0x11, 0x20, 0x37, 0x82, 0x24,
  35075. 0x88, 0x1F, 0x65, 0x17, 0x59, 0xEC, 0x7D, 0xBF,
  35076. 0x45, 0x78, 0x1E, 0xF8, 0xA8, 0x4D, 0xAD, 0xAF,
  35077. 0xE6, 0x13, 0xD6, 0x01, 0x69, 0x66, 0xBD, 0x88,
  35078. 0x44, 0xB6, 0xA6, 0x17, 0xAC, 0xA1, 0xEE, 0xF6,
  35079. 0x73, 0xB7, 0x74, 0xCC, 0x80, 0x7B, 0x36, 0xDD,
  35080. 0x02, 0xDD, 0x45, 0x21, 0x66, 0x86, 0x03, 0x7F,
  35081. 0x9A, 0xC0, 0xB1, 0x2F, 0x57, 0x26, 0xF2, 0x51,
  35082. 0xC5, 0x72, 0x43, 0xE2, 0xC1, 0x88, 0xF5, 0xEC,
  35083. 0xC0, 0x97, 0xE0, 0xB9, 0x89, 0xB5, 0x8A, 0x5D,
  35084. 0x80, 0x4A, 0xBF, 0xD7, 0x20, 0x25, 0x55, 0x77,
  35085. 0x66, 0x8E, 0xE3, 0x04, 0xD0, 0x1C, 0x50, 0xFE,
  35086. 0x8B, 0x6D, 0x90, 0x68, 0x53, 0xCF, 0x7A, 0x49,
  35087. 0x4F, 0xB4, 0x79, 0x91, 0xF1, 0x81, 0xB7, 0x42,
  35088. 0x0E, 0x74, 0x19, 0x9C, 0x82, 0xE7, 0x1A, 0x82,
  35089. 0x4B, 0xF8, 0xC6, 0x13, 0x1D, 0xF4, 0xD1, 0x85,
  35090. 0x6F, 0x11, 0xE7, 0x04, 0x07, 0x70, 0x72, 0x4D,
  35091. 0xE7, 0x2C, 0x81, 0x5A, 0xC0, 0x44, 0x3F, 0x2E,
  35092. 0x77, 0xEC, 0x22, 0xA1, 0x28, 0xDB, 0x18, 0xE1,
  35093. 0x18, 0x3E, 0xE7, 0x96, 0x82, 0xC4, 0x30, 0x24,
  35094. 0xC9, 0x07, 0x46, 0x6C, 0x35, 0x4B, 0x1C, 0x7B,
  35095. 0x0E, 0x0E, 0xF0, 0x9F, 0x16, 0x48, 0x7B, 0xD8,
  35096. 0xA9, 0x9C, 0x3A, 0x0A, 0x9E, 0xDB, 0xF0, 0x0F,
  35097. 0x15, 0xA5, 0xEB, 0x1C, 0x50, 0xD4, 0x27, 0x36,
  35098. 0xDB, 0x07, 0x63, 0xBD, 0x56, 0xBD, 0xFA, 0x81,
  35099. 0x09, 0x9A, 0xDE, 0xCE, 0xE8, 0x4A, 0xEA, 0x06,
  35100. 0x9C, 0x06, 0x5B, 0x67, 0x03, 0x14, 0xB9, 0xE4,
  35101. 0x8C, 0x66, 0x75, 0xA3, 0xCC, 0x69, 0x39, 0x57,
  35102. 0xDA, 0x1D, 0x21, 0xBA, 0xCE, 0xD8, 0x70, 0x02,
  35103. 0xFF, 0xF5, 0x6F, 0x25, 0x3A, 0x3D, 0xFC, 0x79,
  35104. 0xA3, 0xF0, 0x3A, 0x3F, 0x2B, 0x10, 0x51, 0x9A,
  35105. 0xCB, 0xC9, 0x1A, 0xF5, 0xF1, 0x98, 0x5B, 0x5C,
  35106. 0x87, 0x96, 0x4E, 0xC8, 0x00, 0x8A, 0x3A, 0x6E,
  35107. 0x85, 0x02, 0xA5, 0xF1, 0x69, 0x32, 0x6E, 0xC1,
  35108. 0x95, 0x68, 0xCF, 0xA8, 0xE8, 0x85, 0x55, 0x4D,
  35109. 0x6A, 0x68, 0x1F, 0x00, 0xDD, 0x26, 0xB3, 0x24,
  35110. 0xF4, 0x9D, 0xD2, 0x4D, 0x81, 0x06, 0xDA, 0xE6,
  35111. 0x4D, 0x11, 0x73, 0xDF, 0xFE, 0x4F, 0xA6, 0x22,
  35112. 0x5E, 0x6C, 0x6D, 0x5E, 0xE3, 0x59, 0xCF, 0xF4,
  35113. 0x35, 0xA0, 0x80, 0x86, 0x89, 0x49, 0xB2, 0xED,
  35114. 0x0C, 0xC7, 0x3B, 0x42, 0x06, 0x68, 0x8D, 0x90,
  35115. 0x04, 0x1A, 0xBD, 0x51, 0xF6, 0xB9, 0x29, 0x2E,
  35116. 0xB6, 0xF0, 0x79, 0x40, 0x1E, 0x6E, 0x59, 0x94,
  35117. 0xFB, 0xF5, 0x6B, 0x72, 0x82, 0x4C, 0xB6, 0xC7,
  35118. 0x2B, 0x12, 0x71, 0x77, 0xDD, 0x89, 0xCC, 0x2F,
  35119. 0x98, 0xB0, 0x93, 0x1C, 0x98, 0xCE, 0x5E, 0x89,
  35120. 0x0D, 0x95, 0x7B, 0x98, 0xE1, 0xEA, 0xDC, 0xB7,
  35121. 0xFF, 0x22, 0xC5, 0x31, 0x40, 0x9E, 0x1C, 0x80,
  35122. 0x59, 0x47, 0x01, 0x49, 0xEC, 0x81, 0xEF, 0x16,
  35123. 0x32, 0x6B, 0xB0, 0x4E, 0xE2, 0x3B, 0xA3, 0xC1,
  35124. 0x03, 0x12, 0x0D, 0xA6, 0x65, 0xDE, 0x8D, 0xB0,
  35125. 0xA0, 0xBB, 0x75, 0xEF, 0x5C, 0xDA, 0xF4, 0xEE,
  35126. 0x47, 0x6E, 0x55, 0x02, 0x38, 0xCD, 0xC1, 0xAC,
  35127. 0xDD, 0x71, 0xA6, 0x34, 0xAB, 0xCE, 0xA5, 0x5C,
  35128. 0x90, 0xFF, 0xF8, 0xE0, 0xA7, 0x87, 0xBD, 0x21,
  35129. 0x36, 0x91, 0x4F, 0x23, 0xD8, 0x75, 0x58, 0xC5,
  35130. 0xF6, 0xBA, 0xAC, 0x54, 0x6C, 0x24, 0xB1, 0x41,
  35131. 0x02, 0x02, 0xB9, 0x44, 0x31, 0x0E, 0xC4, 0xC9,
  35132. 0xC6, 0x87, 0x85, 0x36, 0x05, 0xC8, 0xAE, 0xC9,
  35133. 0xF1, 0xEF, 0x6B, 0x67, 0x52, 0xD3, 0x9A, 0x15,
  35134. 0xBF, 0xA2, 0x47, 0xEF, 0x89, 0xFC, 0x06, 0x99,
  35135. 0xA1, 0x1A, 0xE4, 0x5A, 0x75, 0xE5, 0x09, 0xD4,
  35136. 0x54, 0xE9, 0x89, 0xF2, 0x60, 0x6E, 0xAB, 0x10,
  35137. 0xF8, 0x42, 0xE4, 0xAD, 0x57, 0xC6, 0xE3, 0x65,
  35138. 0x48, 0x94, 0x14, 0x05, 0x4F, 0x62, 0x20, 0x0F,
  35139. 0x3A, 0x1E, 0xC7, 0x62, 0xDC, 0x5C, 0x8E, 0xFA,
  35140. 0x19, 0x88, 0x47, 0x5D, 0xE8, 0xC3, 0xD5, 0x8C,
  35141. 0x2B, 0x71, 0xBA, 0x11, 0x98, 0x7C, 0x0A, 0xC6,
  35142. 0x42, 0x08, 0x3B, 0xAC, 0x76, 0xFB, 0x50, 0x78,
  35143. 0x8C, 0x26, 0x8F, 0xEE, 0x7B, 0xE2, 0x59, 0x9B,
  35144. 0x34, 0x58, 0x09, 0x2A, 0x8B, 0xCB, 0x1F, 0x31,
  35145. 0x94, 0x8F, 0xE4, 0x82, 0xDF, 0x9A, 0x54, 0x5B,
  35146. 0x63, 0x85, 0x94, 0xD6, 0x7A, 0x44, 0x06, 0x91,
  35147. 0x5C, 0xCD, 0xC7, 0x55, 0x57, 0x47, 0xC0, 0x4E,
  35148. 0x72, 0xA5, 0x48, 0xAB, 0x8F, 0xEE, 0x87, 0x6B,
  35149. 0x25, 0x82, 0x61, 0x3C, 0xCA, 0xBD, 0xA9, 0x6C,
  35150. 0xF1, 0x4A, 0xAA, 0xF6, 0x71, 0x6B, 0x79, 0x0B,
  35151. 0xFE, 0x4D, 0x92, 0x32, 0xD9, 0x03, 0x70, 0xD6,
  35152. 0x0B, 0xBC, 0x18, 0x4B, 0xA3, 0x3B, 0xCF, 0x77,
  35153. 0x83, 0x16, 0xE3, 0x4B, 0x11, 0x83, 0x8D, 0x8F,
  35154. 0x71, 0xFE, 0xEA, 0xC0, 0x42, 0xF0, 0x35, 0xB0,
  35155. 0x76, 0xEA, 0xC1, 0xC2, 0x62, 0xFA, 0x9C, 0x32,
  35156. 0xBC, 0x8D, 0x69, 0xB1, 0x38, 0xB3, 0x51, 0x31,
  35157. 0x8E, 0xD1, 0xF3, 0x44, 0x95, 0x95, 0x11, 0x52,
  35158. 0x36, 0xF4, 0xCA, 0x7C, 0xBA, 0x2B, 0xA9, 0xE1,
  35159. 0x03, 0xF0, 0xF5, 0x09, 0xAB, 0x91, 0x6E, 0x48,
  35160. 0xB8, 0xAF, 0x03, 0x9B, 0xDC, 0xD5, 0x1C, 0xAB,
  35161. 0xFA, 0xCA, 0xDC, 0xEE, 0x8E, 0x49, 0x84, 0xF5,
  35162. 0x61, 0xF9, 0x7D, 0x17, 0xCB, 0xF1, 0xDE, 0x9A,
  35163. 0x7A, 0x7B, 0xDA, 0xF3, 0x26, 0xE6, 0xD8, 0xAD,
  35164. 0x90, 0xE9, 0x5B, 0xAF, 0x15, 0x45, 0xD3, 0xE2,
  35165. 0x46, 0x69, 0xD1, 0xC5, 0xF4, 0x28, 0xE0, 0x7E,
  35166. 0x2C, 0x71, 0x10, 0xFF, 0x43, 0x59, 0x80, 0x93,
  35167. 0xE6, 0xF9, 0x28, 0xA0, 0x34, 0xC6, 0x86, 0xBA,
  35168. 0xE7, 0x5A, 0x56, 0x7A, 0xE4, 0xF5, 0x20, 0xB4,
  35169. 0x4D, 0xAC, 0xB4, 0x95, 0xE5, 0xB2, 0xC6, 0x43,
  35170. 0x9E, 0x2E, 0x67, 0x8E, 0x7C, 0x05, 0x4F, 0xF7,
  35171. 0x60, 0x14, 0x88, 0xC6, 0xAE, 0x4A, 0x05, 0x36,
  35172. 0x99, 0x73, 0x55, 0x10, 0xF9, 0xDB, 0xC3, 0x4C,
  35173. 0xD7, 0x6A, 0x19, 0x94, 0xC0, 0xFE, 0x74, 0x12,
  35174. 0xC0, 0xCE, 0x95, 0x15, 0xBF, 0x60, 0x3A, 0x8E,
  35175. 0xB5, 0xFC, 0x8A, 0xBC, 0xAC, 0x9F, 0x15, 0x10,
  35176. 0x44, 0x73, 0x58, 0x60, 0x5D, 0xA1, 0x33, 0xFD,
  35177. 0xDE, 0xBD, 0xF2, 0x22, 0x69, 0xEE, 0x1D, 0x46,
  35178. 0x8E, 0x2E, 0xE8, 0x21, 0x62, 0x1D, 0x27, 0x84,
  35179. 0xC4, 0x6D, 0xA8, 0x30, 0x02, 0xA6, 0x26, 0x94,
  35180. 0xFA, 0xB1, 0xEF, 0xEC, 0x3B, 0x8D, 0x6F, 0x1B,
  35181. 0x2C, 0xCE, 0x2A, 0x4E, 0xC4, 0x28, 0x35, 0x4E,
  35182. 0x39, 0xA4, 0xF4, 0x5C, 0x96, 0x65, 0xC1, 0xB8,
  35183. 0x55, 0xA5, 0x09, 0x15, 0xBC, 0x4D, 0x3B, 0xD0,
  35184. 0x1F, 0x7F, 0xBA, 0x90, 0x20, 0xCD, 0xBD, 0xC2,
  35185. 0xC8, 0xE5, 0xC6, 0xB0, 0x6F, 0x14, 0x4E, 0x6B,
  35186. 0xEA, 0x8A, 0x24, 0x44, 0xE1, 0x0A, 0xCD, 0xB2,
  35187. 0x05, 0xF3, 0x15, 0x71, 0x7C, 0x86, 0xFC, 0xF1,
  35188. 0xFD, 0x6B, 0xA6, 0xE3, 0xFC, 0x86, 0xE3, 0xBA,
  35189. 0x56, 0x6B, 0x8F, 0xBE, 0x02, 0x9A, 0x03, 0x0C,
  35190. 0x8C, 0x69, 0xE5, 0x7C, 0x15, 0xAE, 0x13, 0x12,
  35191. 0x25, 0x2B, 0x36, 0xFB, 0x51, 0xA1, 0x61, 0x5E,
  35192. 0x37, 0x46, 0x92, 0x0C, 0x0B, 0x71, 0x5C, 0x1D,
  35193. 0xA4, 0xDB, 0x04, 0xC1, 0x08, 0xED, 0x5C, 0x44,
  35194. 0x80, 0x70, 0xC1, 0x0E, 0x63, 0x6D, 0x92, 0xC2,
  35195. 0x1E, 0x18, 0x8E, 0x71, 0x0E, 0x7C, 0x10, 0x21,
  35196. 0x1E, 0xC2, 0xCF, 0xD6, 0x38, 0x7A, 0x9B, 0x5C,
  35197. 0x9E, 0xE8, 0x82, 0x3D, 0xDD, 0x40, 0x0C, 0x96,
  35198. 0x17, 0xEF, 0xB1, 0x25, 0xBA, 0x84, 0x45, 0x4F,
  35199. 0x64, 0xA6, 0x8E, 0x2B, 0xBA, 0xF1, 0xED, 0xB3,
  35200. 0x4F, 0x92, 0x5F, 0x1A, 0x73, 0x2A, 0x2A, 0x22,
  35201. 0x68, 0x19, 0x4C, 0x8A, 0x87, 0x51, 0x75, 0x78,
  35202. 0xCF, 0x3C, 0xC5, 0x97, 0xFD, 0x77, 0x43, 0xCB,
  35203. 0xAE, 0x3D, 0x9C, 0xB6, 0x45, 0x54, 0x45, 0xF4,
  35204. 0x1B, 0x92, 0xEE, 0xF4, 0x9D, 0xC4, 0x32, 0x10,
  35205. 0x6A, 0x48, 0xAB, 0xE9, 0x47, 0xBF, 0x2B, 0x92,
  35206. 0x49, 0x84, 0x23, 0x52, 0x05, 0xA1, 0x92, 0x3B,
  35207. 0xD7, 0x78, 0x2D, 0x9A, 0x15, 0xB4, 0xD9, 0xD3,
  35208. 0x45, 0xD0, 0x69, 0xF1, 0x38, 0x4D, 0x39, 0xEA,
  35209. 0x49, 0x7E, 0xC0, 0xE7, 0x7A, 0x07, 0x88, 0x1D,
  35210. 0x1F, 0xA3, 0xAC, 0xE9, 0xC3, 0xFD, 0x6B, 0x5D,
  35211. 0xF6, 0xB2, 0xB9, 0xAA, 0x9A, 0xBE, 0xF4, 0x06,
  35212. 0xD9, 0x5E, 0x81, 0xE5, 0x68, 0xDF, 0xEA, 0x20,
  35213. 0x4C, 0xEE, 0xED, 0x42, 0xA4, 0xD3, 0x7B, 0xA8,
  35214. 0x82, 0x98, 0x0D, 0xB4, 0xC8, 0xC3, 0x43, 0x28,
  35215. 0x13, 0xE9, 0x6B, 0x11, 0x0E, 0x54, 0xE6, 0xCD,
  35216. 0x11, 0x0A, 0x01, 0x36, 0x41, 0x78, 0xC5, 0x7D,
  35217. 0x00, 0xC6, 0x8D, 0xE7, 0x7B, 0x4C, 0xE6, 0x35,
  35218. 0x57, 0x8F, 0x56, 0xA9, 0x73, 0x5A, 0xEF, 0x93,
  35219. 0xF0, 0xD8, 0x16, 0xE3, 0x44, 0x8A, 0xA0, 0xA9,
  35220. 0xF1, 0x9C, 0x2E, 0x02, 0xD1, 0x3C, 0x66, 0xDD,
  35221. 0xE5, 0x35, 0xFE, 0x81, 0x77, 0x8D, 0xC2, 0x46,
  35222. 0x64, 0x03, 0x23, 0xCC, 0x37, 0x22, 0x60, 0x68,
  35223. 0xCC, 0x7F, 0x79, 0xE8, 0x6B, 0xD0, 0xEE, 0x1C,
  35224. 0x6A, 0xC3, 0x3C, 0xEB, 0x51, 0x95, 0xFA, 0xE4,
  35225. 0x28, 0x17, 0x94, 0x49, 0x22, 0x69, 0x64, 0x98,
  35226. 0x82, 0x8B, 0x68, 0x9F, 0x69, 0x35, 0xF9, 0xBF,
  35227. 0x33, 0x22, 0xA4, 0x32, 0x0F, 0x4C, 0x26, 0xE4,
  35228. 0x8D, 0xDF, 0xAE, 0xBD, 0xF4, 0x4D, 0x01, 0xAF,
  35229. 0xA1, 0xFA, 0x3E, 0xCE, 0xD3, 0xB0, 0x5D, 0x02,
  35230. 0xDB, 0x3B, 0xB4, 0x23, 0xB8, 0x55, 0x97, 0xB5,
  35231. 0x1F, 0x25, 0x64, 0xA7, 0x5D, 0x4A, 0x8C, 0x90,
  35232. 0xD4, 0xB6, 0x85, 0x20, 0x32, 0x09, 0x37, 0x26,
  35233. 0x00, 0xD5, 0x4D, 0x98, 0x5A, 0xCF, 0x29, 0x3B,
  35234. 0x0E, 0xAF, 0x69, 0x88, 0x78, 0x18, 0xAD, 0xD1,
  35235. 0xE1, 0xB7, 0xC5, 0xD7, 0xB7, 0x5F, 0xFE, 0xB5,
  35236. 0x64, 0xE0, 0x68, 0x0B, 0x4F, 0x46, 0x7B, 0xDE,
  35237. 0x0B, 0x11, 0x7A, 0x42, 0x10, 0x86, 0x09, 0x60,
  35238. 0xB5, 0xE0, 0x22, 0x17, 0x28, 0x68, 0x7A, 0xE9,
  35239. 0xEB, 0xBC, 0x6B, 0xD5, 0x95, 0x4C, 0xE0, 0xAE,
  35240. 0x57, 0xB1, 0x45, 0xFF, 0xC2, 0x7E, 0xB6, 0xA0,
  35241. 0xD3, 0x8E, 0x46, 0x16, 0xCE, 0xBE, 0x76, 0xCE,
  35242. 0x59, 0x5B, 0xA4, 0x96, 0x1E, 0x9F, 0x80, 0xF0,
  35243. 0x06, 0x7E, 0xCD, 0x6E, 0x27, 0xB8, 0x7D, 0x26,
  35244. 0xB6, 0x60, 0xA3, 0xAB, 0x52, 0xC1, 0x37, 0x9A,
  35245. 0xDD, 0x46, 0xF5, 0xB9, 0x39, 0x75, 0xAA, 0x19,
  35246. 0xF3, 0xE4, 0xA8, 0x95, 0x4B, 0x25, 0x3F, 0x0B,
  35247. 0x44, 0x13, 0xF5, 0x82, 0x10, 0x68, 0x03, 0xD5,
  35248. 0x0F, 0x99, 0xB5, 0xB2, 0x8B, 0x85, 0x77, 0x2E,
  35249. 0x78, 0x3E, 0xEE, 0x21, 0x6E, 0xAD, 0x2D, 0xCF,
  35250. 0x95, 0x62, 0x94, 0x1C, 0x50, 0xAB, 0xC5, 0xFA,
  35251. 0x8E, 0x24, 0xB6, 0x14, 0x86, 0x46, 0x8A, 0xAA,
  35252. 0x20, 0xDF, 0x15, 0xD1, 0x72, 0xF6, 0xAC, 0x03,
  35253. 0xAF, 0xDF, 0xCD, 0x53, 0x81, 0xBA, 0xDB, 0x07,
  35254. 0x8B, 0x8E, 0xBB, 0x70, 0x91, 0x57, 0x04, 0xB9,
  35255. 0x88, 0xE5, 0x8F, 0x45, 0xD3, 0xD6, 0x31, 0x12,
  35256. 0xA5, 0xC1, 0x28, 0xC6, 0x49, 0x90, 0x0F, 0x1D,
  35257. 0x69, 0x66, 0xE3, 0x98, 0x56, 0x7D, 0xE3, 0x48,
  35258. 0xAC, 0xC0, 0xDE, 0xE4, 0x2B, 0x88, 0x01, 0x19,
  35259. 0x4E, 0x99, 0xBB, 0x1A, 0xAF, 0x02, 0x5A, 0x91,
  35260. 0xE3, 0x2C, 0xE6, 0x56, 0x4D, 0x05, 0x10, 0xB9,
  35261. 0x10, 0xF2, 0x2A, 0x27, 0xDE, 0xCF, 0x9D, 0x2E
  35262. };
  35263. static const byte msg_44[] = {
  35264. 0xB1, 0x34, 0x49, 0x15, 0xCC, 0xD6, 0x93, 0x41,
  35265. 0x6B, 0x37, 0xFE, 0xBD, 0x8D, 0xC7, 0xC7, 0xDB,
  35266. 0x9F, 0x25, 0x3E, 0x9D, 0xF5, 0x3C, 0xEC, 0x51,
  35267. 0x49, 0x23, 0xAA, 0xA2, 0x67, 0x6F, 0xBF, 0xA4,
  35268. 0xCC, 0x04, 0xFC, 0x68, 0xF9, 0xE3, 0x2F, 0x9E,
  35269. 0x86, 0x4C, 0x68, 0x95, 0xDB, 0x37, 0xE9, 0xFF,
  35270. 0xEB, 0x80, 0xF0, 0xF6, 0xB8, 0x6C, 0xB6, 0xAD,
  35271. 0x9C, 0x42, 0xF8, 0xFC, 0x75, 0x19, 0x8D, 0xD3,
  35272. 0xCC, 0xDA, 0xF5, 0x77, 0xC7, 0xB3, 0x5B, 0x8F,
  35273. 0x1B, 0xF6, 0x0A, 0xAB, 0xEA, 0x89, 0x94, 0x42,
  35274. 0x20, 0x1F, 0xBB, 0xF4, 0x42, 0x8C, 0x7E, 0xC1,
  35275. 0x7B, 0xC3, 0x1B, 0x54, 0x72, 0x4B, 0x95, 0x90,
  35276. 0xF7, 0x53, 0x1E, 0x6F, 0x79, 0x0A, 0x1F, 0xA7,
  35277. 0x74, 0x32, 0x83, 0x37, 0x2D, 0x31, 0x71, 0xB8,
  35278. 0x96, 0x6B, 0x47, 0x0A, 0xAA, 0x85, 0x26, 0xEB,
  35279. 0x4A, 0x6E, 0x81, 0xE6, 0x5A, 0xD0, 0xC2, 0x9F,
  35280. 0x2D, 0x37, 0xDD, 0x5B, 0x41, 0x2B, 0xAE, 0x68,
  35281. 0x2A, 0x66, 0x79, 0x68, 0x77, 0xC8, 0x2F, 0xFD,
  35282. 0xA9, 0x76, 0x24, 0x34, 0xEA, 0xC2, 0xC7, 0xD4,
  35283. 0xAF, 0x60, 0x9B, 0x27, 0x72, 0x49, 0x0D, 0xEE,
  35284. 0x9B, 0xFB, 0x00, 0x5D, 0x2F, 0x1A, 0x2E, 0xBB,
  35285. 0xA0, 0x32, 0xCD, 0x71, 0x59, 0xD5, 0x4B, 0xE5,
  35286. 0x96, 0xF3, 0x30, 0x68, 0xBE, 0x5D, 0x9A, 0x2D,
  35287. 0x94, 0x0C, 0x76, 0x70, 0xE6, 0x4E, 0x9A, 0xF7,
  35288. 0xD7, 0xD3, 0x3E, 0xC3, 0xAE, 0xC6, 0xF1, 0xD9,
  35289. 0xDE, 0xE3, 0x92, 0x84, 0xF0, 0x5C, 0xE0, 0x25,
  35290. 0xD1, 0x81, 0x76, 0x0D, 0x40, 0xE5, 0xC2, 0xD9,
  35291. 0xBE, 0xAE, 0x24, 0x20, 0xF4, 0x0D, 0x9F, 0x32,
  35292. 0xB7, 0xBD, 0xCD, 0x3A, 0xFB, 0x1C, 0x66, 0x0D,
  35293. 0x01, 0x71, 0x4D, 0x81, 0x37, 0x58, 0xDB, 0xB8,
  35294. 0x2C, 0x6B, 0x7E, 0x85, 0x80, 0x52, 0xB5, 0xA5,
  35295. 0x0E, 0x39, 0xE0, 0x15, 0xD3, 0xF2, 0x4A, 0x2C,
  35296. 0x64, 0xC9, 0xDD, 0xCC, 0x15, 0x0D, 0x90, 0x4F,
  35297. 0x07, 0xF6, 0x5F, 0xF6, 0x8A, 0xD0, 0x12, 0x9E,
  35298. 0xC3, 0xF8, 0x12, 0x3F, 0x3A, 0x03, 0xFC, 0x95,
  35299. 0x8A, 0xE2, 0x47, 0x8C, 0x6C, 0x6E, 0x03, 0x61,
  35300. 0x67, 0xD8, 0x51, 0x49, 0xF7, 0x9F, 0xB0, 0x3F,
  35301. 0xAA, 0xB9, 0x89, 0x7C, 0xE7, 0x3F, 0x88, 0x55,
  35302. 0xC5, 0x4C, 0x83, 0xD7, 0x53, 0xB1, 0x04, 0xB5,
  35303. 0x13, 0xD5, 0x6B, 0xC6, 0x4C, 0x3B, 0x08, 0x91,
  35304. 0x73, 0x47, 0x35, 0x13, 0x26, 0xD8, 0xEB, 0x47,
  35305. 0xCF, 0x66, 0xF1, 0x3F, 0xB9, 0x0F, 0x6A, 0xF5,
  35306. 0xA8, 0x94, 0xC7, 0x75, 0x00, 0x77, 0xA8, 0x9C,
  35307. 0xEB, 0x77, 0x22, 0xE2, 0xE6, 0x80, 0xA5, 0x9B,
  35308. 0xF8, 0x43, 0x8C, 0x52, 0x35, 0x31, 0xEA, 0x8C,
  35309. 0xC2, 0x83, 0x4F, 0xFC, 0x4E, 0xF0, 0x2D, 0x35,
  35310. 0xB8, 0x51, 0x46, 0xF2, 0xD6, 0x01, 0xD5, 0x00,
  35311. 0x99, 0x6A, 0x44, 0x10, 0x64, 0xAD, 0xCA, 0x1F,
  35312. 0x62, 0x3F, 0x2F, 0xE7, 0x45, 0x22, 0x47, 0xEF,
  35313. 0x86, 0x9D, 0x76, 0xD5, 0x78, 0x42, 0x07, 0x30,
  35314. 0x88, 0x86, 0x90, 0xB1, 0xA0, 0x08, 0xDA, 0x28,
  35315. 0x2A, 0xD1, 0x75, 0x7D, 0x21, 0x71, 0x29, 0x38,
  35316. 0x59, 0xC7, 0x3F, 0x55, 0x20, 0xB5, 0xBB, 0x48,
  35317. 0x03, 0xE7, 0xFA, 0xB0, 0x29, 0x00, 0xD2, 0x0F,
  35318. 0xE7, 0x65, 0x81, 0x8E, 0xE6, 0x24, 0xE7, 0xA1,
  35319. 0x94, 0x50, 0x9D, 0x01, 0x6B, 0x4B, 0xD7, 0x81,
  35320. 0x4E, 0xA0, 0xD5, 0x4A, 0x51, 0xEE, 0x95, 0x0A,
  35321. 0x14, 0x76, 0xD5, 0x87, 0xAA, 0x6F, 0x78, 0xC8,
  35322. 0xD2, 0xE0, 0xC8, 0xF8, 0xF2, 0x78, 0xD8, 0x2E,
  35323. 0x11, 0x90, 0x44, 0xB6, 0xBF, 0xD0, 0xBE, 0xD8,
  35324. 0x6F, 0xA4, 0x20, 0xA2, 0xC8, 0xA4, 0xEF, 0xB0,
  35325. 0x5D, 0x73, 0x06, 0xBE, 0x52, 0xF9, 0x32, 0xD8,
  35326. 0x06, 0x5D, 0xD1, 0x29, 0x23, 0x46, 0x25, 0x6E,
  35327. 0x42, 0x9D, 0xEE, 0x41, 0x9E, 0xF3, 0x7D, 0x1B,
  35328. 0x35, 0x28, 0x81, 0xDC, 0x47, 0x7F, 0x25, 0xA4,
  35329. 0x0A, 0xEB, 0x3E, 0x17, 0xE6, 0x1B, 0xCC, 0x00,
  35330. 0xD2, 0xE2, 0xA9, 0x3D, 0xEC, 0xF3, 0x00, 0xF0,
  35331. 0x81, 0x68, 0x21, 0xED, 0x49, 0xF9, 0x9B, 0x9B,
  35332. 0x8B, 0xED, 0xD9, 0x1E, 0xFA, 0x04, 0xBB, 0xB0,
  35333. 0x9A, 0xBD, 0x1D, 0x24, 0x36, 0xA7, 0xD6, 0x64,
  35334. 0x8A, 0x38, 0x3A, 0x3A, 0x8F, 0x09, 0x08, 0x0E,
  35335. 0x46, 0x7B, 0xE1, 0x03, 0x30, 0xBF, 0x62, 0x27,
  35336. 0x10, 0x74, 0xBE, 0xBD, 0x7F, 0x56, 0x39, 0x0D,
  35337. 0x1D, 0x39, 0x47, 0xF4, 0x02, 0x47, 0x6B, 0x62,
  35338. 0x6B, 0x52, 0xAC, 0xAB, 0x21, 0xAC, 0x10, 0x4A,
  35339. 0xAB, 0x59, 0x75, 0x33, 0x11, 0xD9, 0xE9, 0xE2,
  35340. 0xB2, 0x20, 0x6B, 0xA1, 0x09, 0x42, 0xB6, 0x37,
  35341. 0xE4, 0x5C, 0xE6, 0x9F, 0x54, 0xB4, 0x67, 0xBC,
  35342. 0xAE, 0xF3, 0xDC, 0x1A, 0xA2, 0x15, 0x47, 0x7B,
  35343. 0x15, 0xC8, 0x00, 0x35, 0x8E, 0x1D, 0x69, 0x04,
  35344. 0xD8, 0x9C, 0xA9, 0x6A, 0x03, 0x1A, 0x55, 0x48,
  35345. 0x6C, 0x4F, 0xC1, 0x68, 0x27, 0x26, 0x13, 0xAB,
  35346. 0x8E, 0x03, 0x50, 0x7B, 0xDD, 0xC2, 0x7E, 0x5C,
  35347. 0x8A, 0x6F, 0xBB, 0x5F, 0x8B, 0x22, 0x86, 0xA5,
  35348. 0xC5, 0x0E, 0xC5, 0x68, 0x60, 0xF6, 0xBF, 0xFF,
  35349. 0x6E, 0xBA, 0xDC, 0x21, 0x71, 0xD2, 0xEB, 0xD1,
  35350. 0x27, 0x8C, 0x58, 0x14, 0xC3, 0x2E, 0x13, 0x9E,
  35351. 0x04, 0x09, 0x61, 0xC3, 0x19, 0xC3, 0x03, 0x48,
  35352. 0x70, 0x33, 0x3B, 0x12, 0xF7, 0x3B, 0x38, 0xE7,
  35353. 0x18, 0x14, 0xA9, 0xF1, 0x60, 0x83, 0x65, 0xEB,
  35354. 0x32, 0xD5, 0x23, 0x8F, 0x6B, 0xF7, 0xD8, 0x00,
  35355. 0x21, 0xBD, 0xA3, 0x98, 0xDE, 0xD7, 0x13, 0x17,
  35356. 0xAB, 0x3C, 0xA4, 0xD7, 0xBE, 0x1D, 0xA7, 0x4A,
  35357. 0x1B, 0xC4, 0x0C, 0x9B, 0x2E, 0x34, 0x5B, 0xA7,
  35358. 0xA2, 0x3F, 0x9B, 0x2D, 0xDB, 0xAF, 0x85, 0x14,
  35359. 0x0A, 0xF9, 0x30, 0x9E, 0x86, 0x53, 0xAC, 0x24,
  35360. 0xAF, 0xD8, 0x25, 0xBC, 0x2A, 0x07, 0x2B, 0xCD,
  35361. 0x02, 0xFE, 0x3E, 0xF0, 0x0B, 0xE3, 0xF9, 0x51,
  35362. 0x5C, 0x29, 0xEB, 0x8A, 0xFB, 0xC3, 0xEF, 0xD1,
  35363. 0xF9, 0xCF, 0xDF, 0xE9, 0xEB, 0xA9, 0x49, 0x59,
  35364. 0xB5, 0x17, 0x7E, 0x28, 0x86, 0xB8, 0xD1, 0x8D,
  35365. 0xCA, 0x97, 0xF0, 0xCB, 0x80, 0x7E, 0xE3, 0xEA,
  35366. 0xE3, 0x1B, 0x48, 0xCF, 0xAC, 0x61, 0x3C, 0x2E,
  35367. 0x00, 0xAB, 0x74, 0xFB, 0x95, 0xF6, 0x64, 0xF3,
  35368. 0xCA, 0xBF, 0x6E, 0xEF, 0xCD, 0xDD, 0x6D, 0xA5,
  35369. 0xF8, 0x98, 0xEC, 0x38, 0xF2, 0xF0, 0x7D, 0x6D,
  35370. 0xCB, 0x75, 0xE0, 0x50, 0x9D, 0x13, 0x19, 0x24,
  35371. 0x07, 0x4C, 0x05, 0xF4, 0x5D, 0xCA, 0x25, 0xB7,
  35372. 0xCF, 0xE2, 0xBC, 0xFE, 0xEC, 0xAF, 0x5F, 0xC3,
  35373. 0x6C, 0xE6, 0xE3, 0xC5, 0x85, 0x43, 0x7B, 0x06,
  35374. 0x9F, 0xD2, 0xC6, 0xBB, 0xAD, 0x33, 0xD6, 0x86,
  35375. 0xBD, 0x5B, 0x9E, 0x2C, 0xA0, 0xD9, 0x8B, 0xDC,
  35376. 0x5E, 0x71, 0x7B, 0x6D, 0xF7, 0x1D, 0x40, 0x91,
  35377. 0x30, 0x8E, 0x84, 0x73, 0x9A, 0xD6, 0x7F, 0xA6,
  35378. 0x79, 0xA6, 0xCE, 0xE9, 0xA6, 0x83, 0x28, 0x4B,
  35379. 0x4F, 0xB3, 0x1B, 0x2C, 0x40, 0x8F, 0x52, 0xF0,
  35380. 0x59, 0x7D, 0x9C, 0x04, 0xEA, 0xF4, 0xAC, 0x6D,
  35381. 0xBB, 0x6C, 0x3F, 0xD6, 0x7F, 0x25, 0x39, 0xD8,
  35382. 0x87, 0xDF, 0xBC, 0xF3, 0xCA, 0xE4, 0x59, 0xFA,
  35383. 0x76, 0x66, 0x61, 0xA4, 0x8B, 0xFC, 0xFD, 0x6F,
  35384. 0x64, 0x03, 0x99, 0xD3, 0xAF, 0x07, 0x86, 0x35,
  35385. 0x99, 0x98, 0xCE, 0xFF, 0x7E, 0x9E, 0xB1, 0xB0,
  35386. 0x57, 0xA6, 0x29, 0x3D, 0xFF, 0xB7, 0xF3, 0xF2,
  35387. 0x51, 0x4B, 0x0B, 0x70, 0x29, 0x46, 0x06, 0x8A,
  35388. 0x6B, 0xBD, 0x75, 0x30, 0xD6, 0x91, 0x7F, 0xB1,
  35389. 0x1D, 0xBB, 0xAA, 0xBE, 0xD7, 0xAA, 0x46, 0x81,
  35390. 0xD7, 0x8A, 0xEA, 0x91, 0x86, 0x69, 0x2D, 0xDA,
  35391. 0x34, 0x70, 0x65, 0x2E, 0xB8, 0xA3, 0xF1, 0x44,
  35392. 0x56, 0xA5, 0xAA, 0xC4, 0x20, 0x88, 0x3B, 0x42,
  35393. 0x37, 0xB0, 0xA7, 0x2D, 0x91, 0x27, 0x63, 0xB6,
  35394. 0x7A, 0xC4, 0x13, 0x1A, 0x8A, 0x5D, 0x2F, 0x16,
  35395. 0x82, 0x96, 0xB9, 0x12, 0xD3, 0xB6, 0x61, 0xC4,
  35396. 0xE8, 0x3C, 0xE6, 0x3A, 0x61, 0xC0, 0x45, 0xEB,
  35397. 0xA5, 0x75, 0xEE, 0xB6, 0x7F, 0xB0, 0x70, 0xED,
  35398. 0x82, 0x39, 0xE5, 0x1A, 0x67, 0xD9, 0x80, 0x3C,
  35399. 0xE0, 0x0B, 0x85, 0x66, 0x74, 0xE0, 0xB7, 0x26,
  35400. 0x66, 0x26, 0xDD, 0x02, 0x15, 0xE5, 0xEF, 0x5F,
  35401. 0xDE, 0x7B, 0xF4, 0x0B, 0x99, 0x10, 0x21, 0x08,
  35402. 0xFC, 0x2D, 0xF2, 0x8B, 0xDC, 0xC8, 0xEA, 0xC6,
  35403. 0x3E, 0xFB, 0x20, 0x50, 0x1F, 0x24, 0x66, 0x99,
  35404. 0x80, 0x88, 0xC7, 0xA0, 0xB9, 0x6D, 0x1B, 0x75,
  35405. 0xC4, 0xC2, 0xE2, 0x52, 0xA0, 0xBF, 0x38, 0x01,
  35406. 0x5C, 0xA5, 0x8A, 0xDA, 0x79, 0x38, 0xAE, 0x2E,
  35407. 0xC7, 0x96, 0x6F, 0x30, 0x5B, 0xB4, 0x21, 0xC0,
  35408. 0xCD, 0x95, 0xCA, 0xD2, 0x12, 0x7D, 0xAD, 0x87,
  35409. 0x08, 0x6C, 0xC3, 0x8B, 0xF6, 0xB1, 0x5D, 0xAD,
  35410. 0x2C, 0x7C, 0x04, 0x41, 0xE5, 0x34, 0x2E, 0x4B,
  35411. 0x5A, 0xD9, 0x1E, 0x66, 0xF4, 0x23, 0xE2, 0x88,
  35412. 0x4D, 0xD9, 0x03, 0xFE, 0x6C, 0x64, 0x7D, 0x61,
  35413. 0xE6, 0x70, 0x0E, 0xA8, 0x83, 0x08, 0x07, 0xE6,
  35414. 0xFD, 0x64, 0x54, 0x3E, 0x3C, 0x6E, 0x9A, 0xD1,
  35415. 0x93, 0x37, 0x36, 0x90, 0xDE, 0x94, 0xF7, 0x16,
  35416. 0x15, 0x47, 0x94, 0xFE, 0x97, 0x5B, 0x11, 0x80,
  35417. 0xBA, 0x40, 0xAF, 0x7F, 0x05, 0xC1, 0x82, 0x91,
  35418. 0x69, 0xFD, 0xFB, 0xEC, 0x3A, 0xF7, 0xCF, 0xE1,
  35419. 0xD7, 0x9B, 0x59, 0x7E, 0xE4, 0x38, 0xA2, 0x96,
  35420. 0xEF, 0x14, 0x6A, 0x05, 0x99, 0x71, 0xE3, 0xF9,
  35421. 0x50, 0x8E, 0x35, 0x0B, 0x50, 0x71, 0x6D, 0xEC,
  35422. 0xB5, 0x1B, 0xC8, 0x80, 0x2A, 0xE6, 0x2A, 0x7F,
  35423. 0x4C, 0x2E, 0x6F, 0x7B, 0x54, 0x62, 0x0E, 0xF0,
  35424. 0x4C, 0x00, 0xF0, 0x72, 0xAE, 0x37, 0xAC, 0x32,
  35425. 0x7E, 0x26, 0xD3, 0x65, 0x76, 0x1C, 0x10, 0x46,
  35426. 0x17, 0xAE, 0xE0, 0xF3, 0x28, 0xEE, 0x97, 0xE0,
  35427. 0x86, 0x18, 0x3D, 0x46, 0xA3, 0x62, 0x1F, 0x23,
  35428. 0xF3, 0xAC, 0x27, 0x60, 0xB8, 0x85, 0x9A, 0x96,
  35429. 0x0E, 0xF1, 0x6F, 0xC1, 0xC6, 0xB1, 0x97, 0x8A,
  35430. 0x74, 0x12, 0xDD, 0x73, 0x85, 0x02, 0x9C, 0x73,
  35431. 0x61, 0xA8, 0xF7, 0x49, 0xCE, 0xBA, 0x23, 0xED,
  35432. 0xE7, 0x9A, 0x17, 0x0E, 0xA6, 0x84, 0x59, 0xF5,
  35433. 0x21, 0x66, 0xF5, 0xC5, 0x61, 0xF8, 0x88, 0x7E,
  35434. 0x62, 0x0C, 0x00, 0xC6, 0x4F, 0x06, 0xBD, 0x0A,
  35435. 0xBB, 0xCD, 0xE5, 0x11, 0x7A, 0xBC, 0xFD, 0x03,
  35436. 0xB6, 0xD1, 0xBA, 0x4F, 0x30, 0xFA, 0x96, 0x75,
  35437. 0xD8, 0x2D, 0x7A, 0x43, 0x0D, 0x58, 0x41, 0x46,
  35438. 0xBA, 0x72, 0x06, 0xCB, 0xBD, 0xD9, 0xBE, 0xA1,
  35439. 0xEA, 0x47, 0x08, 0x3D, 0xF9, 0x32, 0x23, 0x9C,
  35440. 0xAA, 0x02, 0x1D, 0xA3, 0x3E, 0x43, 0xF1, 0x68,
  35441. 0xD8, 0xBE, 0x9F, 0x0E, 0xA8, 0xA8, 0x52, 0xC4,
  35442. 0x0A, 0xDE, 0x43, 0x9D, 0x58, 0xA8, 0x05, 0xD4,
  35443. 0x74, 0xF8, 0x93, 0x21, 0x62, 0x6E, 0x33, 0x78,
  35444. 0x3C, 0x23, 0xEB, 0x60, 0x1C, 0x4C, 0x25, 0xFE,
  35445. 0x0F, 0x5E, 0x73, 0xC3, 0xAD, 0x33, 0x9A, 0x7D,
  35446. 0x69, 0x6B, 0xAB, 0x2C, 0xAA, 0x5F, 0xBF, 0x96,
  35447. 0x62, 0x3A, 0xF0, 0x63, 0x41, 0x00, 0xC7, 0x4C,
  35448. 0x81, 0x4D, 0x42, 0x43, 0x25, 0xBC, 0x30, 0xB6,
  35449. 0x0B, 0xEE, 0xFC, 0x18, 0x3E, 0x68, 0x0E, 0x64,
  35450. 0x5C, 0xD4, 0x22, 0x2A, 0xBA, 0xB5, 0xC6, 0x7E,
  35451. 0x67, 0x11, 0x1C, 0x4C, 0x03, 0x30, 0xEC, 0x0C,
  35452. 0x77, 0xB2, 0x2B, 0xBC, 0x98, 0xF7, 0x52, 0x8C,
  35453. 0x95, 0x66, 0xE1, 0x71, 0xDD, 0x26, 0xA7, 0x7F,
  35454. 0x87, 0xF3, 0x94, 0x2E, 0x0D, 0x3E, 0xFE, 0xAD,
  35455. 0x0A, 0xDA, 0x3B, 0x77, 0x49, 0xC5, 0x1D, 0xED,
  35456. 0x5F, 0xDA, 0x3F, 0xE6, 0xE7, 0x96, 0x58, 0xF1,
  35457. 0x02, 0x30, 0x68, 0xB9, 0x62, 0xD0, 0x58, 0xA2,
  35458. 0x89, 0x65, 0x12, 0x20, 0x1E, 0x4C, 0xE7, 0xB6,
  35459. 0x98, 0x12, 0x52, 0xF0, 0xE8, 0x55, 0xBC, 0xFE,
  35460. 0x1F, 0x44, 0x42, 0x36, 0xC9, 0x30, 0xE4, 0x9A,
  35461. 0x13, 0xB3, 0x7A, 0xF4, 0xF5, 0x97, 0xC0, 0x5D,
  35462. 0xCA, 0x23, 0xCC, 0x05, 0xC4, 0x3C, 0x32, 0xA2,
  35463. 0x11, 0x08, 0x17, 0xCB, 0x30, 0x6B, 0xA4, 0x7D,
  35464. 0x24, 0x5E, 0x50, 0x22, 0x2E, 0x23, 0xC6, 0x55,
  35465. 0x6B, 0xD7, 0x5D, 0x50, 0xEE, 0xF8, 0xBE, 0xB0,
  35466. 0xDE, 0x83, 0x5C, 0x8D, 0xD2, 0xE1, 0x5C, 0x70,
  35467. 0x66, 0x70, 0x59, 0x8F, 0x86, 0x50, 0x71, 0x71,
  35468. 0x04, 0x69, 0xEC, 0xB3, 0x47, 0x9E, 0xE0, 0x26,
  35469. 0xB1, 0x9F, 0xE6, 0x21, 0xAC, 0x99, 0x12, 0x6B,
  35470. 0x97, 0x9E, 0x1B, 0xA1, 0xDD, 0xA8, 0xE6, 0x11,
  35471. 0x12, 0x97, 0xC1, 0x0E, 0x4A, 0x77, 0xF5, 0x52,
  35472. 0xF8, 0x09, 0xE9, 0x01, 0x63, 0x56, 0x4E, 0xFA,
  35473. 0x24, 0x39, 0x36, 0xB9, 0xF2, 0x6E, 0x07, 0x28,
  35474. 0x7F, 0xA4, 0x07, 0x7C, 0xA2, 0x69, 0x7B, 0xED,
  35475. 0x6A, 0x4F, 0x0A, 0x95, 0x99, 0x05, 0x60, 0xE7,
  35476. 0x58, 0xD9, 0x90, 0xB4, 0xC1, 0x92, 0x0F, 0x9E,
  35477. 0x1A, 0xBE, 0x0B, 0x58, 0x96, 0x50, 0x61, 0x1C,
  35478. 0x2D, 0x5A, 0x13, 0xAA, 0x5F, 0x4E, 0x2B, 0x88,
  35479. 0xBE, 0xAB, 0x93, 0x72, 0xF4, 0x68, 0xB8, 0x30,
  35480. 0x91, 0xCD, 0x0A, 0x53, 0x8A, 0x35, 0x82, 0x93,
  35481. 0x4F, 0x66, 0xCA, 0xCD, 0xF2, 0x39, 0x98, 0xFE,
  35482. 0xC2, 0xFE, 0xFE, 0x51, 0x35, 0xF1, 0xB5, 0x62,
  35483. 0x2D, 0x1A, 0xE9, 0x43, 0x25, 0x5E, 0x05, 0xE4,
  35484. 0x8B, 0xFE, 0x91, 0x2F, 0x4F, 0x24, 0x1B, 0x2B,
  35485. 0xAC, 0x49, 0x9C, 0x14, 0xB0, 0x58, 0xA3, 0xA8,
  35486. 0xEE, 0xB9, 0xD1, 0xFA, 0x4D, 0x44, 0x2E, 0x23,
  35487. 0xFC, 0x59, 0x77, 0xA5, 0x60, 0x2E, 0xDC, 0xEB,
  35488. 0x7B, 0x7B, 0x26, 0x95, 0xE1, 0x87, 0xB7, 0x94,
  35489. 0xF8, 0x4B, 0x96, 0x63, 0x15, 0xB1, 0xBB, 0xA5,
  35490. 0xC0, 0x4A, 0x72, 0x02, 0x4A, 0x80, 0x5F, 0xB1,
  35491. 0x94, 0x73, 0xB7, 0x06, 0xB8, 0x13, 0x76, 0x42,
  35492. 0xAD, 0xB1, 0xC6, 0x6C, 0xFD, 0x64, 0xF2, 0x60,
  35493. 0xBB, 0x1B, 0x7A, 0xAD, 0xF6, 0xC2, 0x96, 0xB3,
  35494. 0x5F, 0x30, 0xB9, 0xD7, 0x70, 0x8A, 0x9D, 0x41,
  35495. 0xE7, 0x23, 0xFA, 0xD4, 0xE8, 0x72, 0xAF, 0x73,
  35496. 0xF8, 0x8C, 0x26, 0xAB, 0x65, 0x1B, 0xD5, 0x7A,
  35497. 0x21, 0xE2, 0x8C, 0xE8, 0xC2, 0x47, 0xD5, 0x8E,
  35498. 0x47, 0x9F, 0x79, 0x68, 0x87, 0x6F, 0xCE, 0xD3,
  35499. 0x5D, 0x2B, 0x87, 0xD2, 0xDF, 0x14, 0x43, 0x47,
  35500. 0x03, 0x3D, 0xF4, 0xCB, 0x50, 0xDE, 0x52, 0xD8,
  35501. 0x98, 0x41, 0x46, 0x3F, 0x5D, 0xFB, 0x6D, 0x6F,
  35502. 0xF6, 0xD9, 0xE8, 0x2B, 0xBA, 0xB3, 0xB1, 0xEC,
  35503. 0x58, 0x77, 0x8A, 0xB8, 0xF3, 0x6D, 0xBC, 0x68,
  35504. 0x22, 0xEA, 0xE3, 0x2F, 0xB6, 0xCB, 0x67, 0x30,
  35505. 0xCB, 0x33, 0x1C, 0x39, 0x5C, 0x27, 0x4A, 0xE7,
  35506. 0xE3, 0x7B, 0x40, 0x9B, 0x7C, 0x66, 0x32, 0xE7,
  35507. 0x6D, 0xAA, 0x97, 0xB8, 0x0F, 0x1E, 0x0C, 0xB4,
  35508. 0x7A, 0xA3, 0x66, 0xA8, 0xE3, 0x50, 0xEA, 0x36,
  35509. 0x74, 0x65, 0x92, 0xEC, 0x9B, 0x1E, 0x97, 0xF0,
  35510. 0x2F, 0x99, 0xD6, 0x00, 0x21, 0x37, 0x0B, 0x89,
  35511. 0x93, 0xC6, 0x80, 0xA1, 0x02, 0xDC, 0x96, 0x5D,
  35512. 0x20, 0xB7, 0x57, 0xF4, 0x17, 0x7A, 0x81, 0xBA,
  35513. 0x7B, 0x61, 0xD2, 0x88, 0xEF, 0xC5, 0xAD, 0xED,
  35514. 0x4C, 0x9A, 0x94, 0xA5, 0x7B, 0x2C, 0x6B, 0xD2,
  35515. 0x97, 0x7E, 0x23, 0x64, 0x0A, 0x66, 0x98, 0x47,
  35516. 0xEE, 0x81, 0xB1, 0x49, 0x0B, 0xE3, 0x8A, 0xC4,
  35517. 0x3E, 0x52, 0x2C, 0x8D, 0x09, 0xA2, 0x07, 0xB6,
  35518. 0x2A, 0x8B, 0x07, 0x9A, 0x24, 0x84, 0xDE, 0xD1,
  35519. 0x00, 0x63, 0xD7, 0xA1, 0x3F, 0xBF, 0x0C, 0xA8,
  35520. 0xEE, 0xDC, 0x2B, 0xF6, 0x7B, 0xD8, 0x78, 0x53,
  35521. 0x35, 0xB8, 0x29, 0x5A, 0xFE, 0x6B, 0x35, 0x6E,
  35522. 0x20, 0x62, 0x24, 0x17, 0x0E, 0x87, 0x23, 0x1A,
  35523. 0x77, 0x2D, 0x21, 0x84, 0x37, 0xBF, 0x7D, 0x68,
  35524. 0xAC, 0x2A, 0xF9, 0x3F, 0x11, 0x27, 0x18, 0x4F,
  35525. 0xA2, 0x15, 0x21, 0x47, 0x9E, 0x56, 0xFF, 0x22,
  35526. 0xE8, 0x0F, 0x61, 0xBC, 0x28, 0xB8, 0xD2, 0xE7,
  35527. 0x1B, 0x3D, 0x1D, 0x94, 0x28, 0x1B, 0x69, 0x56,
  35528. 0x00, 0xC8, 0xB0, 0xFD, 0x8E, 0x1D, 0x7E, 0x81,
  35529. 0x1F, 0x4C, 0xCF, 0xE1, 0x6E, 0x3F, 0x57, 0x95,
  35530. 0xC2, 0x4A, 0xA0, 0xA0, 0x16, 0x7E, 0x30, 0x5C,
  35531. 0x28, 0x87, 0x5C, 0x8F, 0xA9, 0x38, 0x9B, 0x72,
  35532. 0xF7, 0x90, 0x86, 0xF6, 0xEC, 0xC1, 0x6C, 0x88,
  35533. 0xB0, 0x78, 0x3A, 0x58, 0x15, 0xFB, 0x6F, 0x77,
  35534. 0xCD, 0xC7, 0xCC, 0xC3, 0x8D, 0x60, 0xE7, 0x87,
  35535. 0xBE, 0x9C, 0xBF, 0xFA, 0xA6, 0x2E, 0xF9, 0x59,
  35536. 0xA5, 0xE5, 0xDC, 0xDE, 0xB6, 0x25, 0x5C, 0x8E,
  35537. 0x0D, 0x2E, 0x01, 0xFE, 0x05, 0xEF, 0xF9, 0xE7,
  35538. 0x81, 0x02, 0xBE, 0xA2, 0x91, 0x40, 0x57, 0xD3,
  35539. 0x6E, 0x3D, 0x1B, 0x48, 0x50, 0x7A, 0xB6, 0xB1,
  35540. 0x76, 0x40, 0x47, 0x0F, 0xE3, 0xF1, 0x7A, 0x8B,
  35541. 0x6A, 0x5E, 0x04, 0xE5, 0x34, 0x56, 0xC5, 0xD9,
  35542. 0xE5, 0x0F, 0x74, 0x5D, 0xE0, 0x6F, 0x9A, 0xED,
  35543. 0xF4, 0xBF, 0xCF, 0x31, 0xB0, 0xC6, 0xED, 0x12,
  35544. 0x13, 0x36, 0x54, 0xCB, 0xC8, 0xDE, 0xF7, 0xF6,
  35545. 0x60, 0x9E, 0x12, 0x2C, 0x2E, 0x4C, 0x93, 0x3E,
  35546. 0x6F, 0xCB, 0x0F, 0x3D, 0x8C, 0xCA, 0xE8, 0xCA,
  35547. 0x0B, 0x10, 0xED, 0xDA, 0xE8, 0xDB, 0x29, 0x7C,
  35548. 0x8B, 0x32, 0x31, 0xC8, 0x94, 0x34, 0xA5, 0xF5,
  35549. 0x4D, 0x01, 0x28, 0xC8, 0x3A, 0xA6, 0xFD, 0xE2,
  35550. 0x9A, 0xB7, 0x0C, 0xDA, 0x43, 0x78, 0x45, 0x45,
  35551. 0xFE, 0xE9, 0xFF, 0x6E, 0xD4, 0x44, 0xF8, 0x88,
  35552. 0x66, 0x4D, 0xD2, 0x2B, 0x2E, 0x2D, 0xF5, 0x7C,
  35553. 0xA6, 0x53, 0xB6, 0xD2, 0x10, 0xE6, 0xB4, 0x0B,
  35554. 0x7F, 0xC2, 0x1F, 0xE0, 0x63, 0x90, 0xCA, 0x5D,
  35555. 0x5E, 0x60, 0xF5, 0x8A, 0xB1, 0x4C, 0x49, 0x03,
  35556. 0xD4, 0x38, 0xAE, 0xEF, 0xB1, 0x7C, 0xA4, 0xB9,
  35557. 0x98, 0x70, 0x6A, 0x0E, 0xD6, 0xA4, 0xA6, 0xF4,
  35558. 0x74, 0xB1, 0xBA, 0x1D, 0x48, 0xCC, 0xC1, 0x14,
  35559. 0x3C, 0x84, 0xA8, 0xD2, 0xE7, 0x8D, 0xEC, 0x11,
  35560. 0x61, 0x8C, 0x76, 0xB6, 0xDA, 0x28, 0xBC, 0x39,
  35561. 0xDF, 0x68, 0xAD, 0x24, 0xA4, 0x07, 0xE1, 0x07,
  35562. 0x33, 0xDD, 0x18, 0x9D, 0x5D, 0xAA, 0x90, 0x4B,
  35563. 0xEF, 0x88, 0x18, 0x6E, 0xB6, 0x83, 0x21, 0x45,
  35564. 0x94, 0x0F, 0x15, 0xB8, 0xAC, 0xD9, 0xD1, 0x8D,
  35565. 0x4F, 0x17, 0xC8, 0xD9, 0x17, 0xB0, 0x9D, 0x54,
  35566. 0xF2, 0x5F, 0x56, 0x09, 0xD3, 0x80, 0x20, 0x77,
  35567. 0x44, 0x23, 0x90, 0xAB, 0xB6, 0x0B, 0x51, 0xA7,
  35568. 0x41, 0xC5, 0xD4, 0x42, 0x5B, 0xD4, 0x67, 0x89,
  35569. 0xE6, 0xEC, 0x1E, 0x7D, 0x22, 0xD5, 0x6E, 0x7F,
  35570. 0x34, 0xCE, 0x7A, 0x07, 0x2B, 0x63, 0x0A, 0x69,
  35571. 0x51, 0x71, 0x8C, 0x13, 0x63, 0xB8, 0x79, 0x6D,
  35572. 0x94, 0xEA, 0xAF, 0x86, 0x30, 0xD2, 0x22, 0x6C,
  35573. 0x67, 0x82, 0x6C, 0xDE, 0xEA, 0x71, 0xE8, 0xD1,
  35574. 0x36, 0xF3, 0x64, 0x2F, 0x79, 0xE6, 0x92, 0xF0,
  35575. 0x4B, 0x05, 0x14, 0x7E, 0x40, 0xCE, 0x0C, 0x53,
  35576. 0xCA, 0x08, 0xEF, 0x0A, 0xA6, 0xA5, 0x73, 0x99,
  35577. 0xFD, 0xF3, 0xED, 0xBD, 0x54, 0x56, 0x6E, 0x66,
  35578. 0xEF, 0xCC, 0xE1, 0x6F, 0x0C, 0x44, 0x76, 0x84,
  35579. 0xF5, 0x55, 0x2B, 0xA3, 0x6B, 0x20, 0x60, 0x54,
  35580. 0x3F, 0xC1, 0x35, 0x58, 0xD8, 0xD8, 0x9E, 0x18,
  35581. 0x63, 0x70, 0x73, 0xEF, 0x6A, 0x87, 0x46, 0x77,
  35582. 0xA9, 0x7F, 0x9F, 0xA0, 0x23, 0x4B, 0x14, 0x00,
  35583. 0x61, 0xC7, 0xE3, 0x44, 0xBE, 0xD6, 0x09, 0x71,
  35584. 0xE3, 0x58, 0x44, 0x9A, 0xCD, 0x17, 0xE5, 0x8E,
  35585. 0x6D, 0x05, 0xBB, 0x21, 0x44, 0xD7, 0x4B, 0xD8,
  35586. 0x9A, 0xE9, 0x7A, 0x75, 0x91, 0x43, 0xAD, 0x84,
  35587. 0x5B, 0x02, 0x70, 0xBE, 0x67, 0x0B, 0x1E, 0x1E,
  35588. 0x92, 0xB8, 0xC7, 0xB6, 0x5F, 0xE1, 0x60, 0x23,
  35589. 0xF5, 0x30, 0xE4, 0xD0, 0xCF, 0x70, 0x03, 0xD1,
  35590. 0x85, 0x4A, 0x50, 0xDC, 0xF4, 0x9C, 0x29, 0xAB,
  35591. 0x0E, 0xA4, 0x7B, 0x2E, 0x3B, 0xDB, 0xBF, 0x52,
  35592. 0xD5, 0x8A, 0x91, 0x47, 0xA9, 0xD1, 0x23, 0xEB,
  35593. 0xC5, 0x6F, 0x11, 0xBB, 0xEE, 0xBB, 0x29, 0xD7,
  35594. 0x31, 0xAB, 0x99, 0x27, 0x5E, 0xF3, 0xA9, 0x23,
  35595. 0xFF, 0x70, 0x87, 0x83, 0xCC, 0x26, 0x92, 0x06,
  35596. 0xEC, 0xD3, 0x8C, 0xF9, 0x47, 0x34, 0x7D, 0x1E,
  35597. 0x71, 0xAF, 0xCF, 0x9D, 0xBF, 0x29, 0x1B, 0x95,
  35598. 0x27, 0x48, 0x55, 0xCE, 0xE2, 0xAC, 0x25, 0x61,
  35599. 0x83, 0xD9, 0x7B, 0x26, 0xEF, 0x94, 0x9A, 0x95,
  35600. 0x0C, 0xD1, 0xE4, 0x0A, 0x51, 0x50, 0x1F, 0x86,
  35601. 0x7A, 0x7B, 0xD3, 0x83, 0x55, 0x2D, 0xFC, 0x7B,
  35602. 0x97, 0x77, 0x17, 0x67, 0xBB, 0x9F, 0xD7, 0xD1,
  35603. 0xDD, 0xDD, 0x49, 0x67, 0xBB, 0xF7, 0x9A, 0x45,
  35604. 0x33, 0x24, 0xCA, 0xBC, 0xA5, 0xB2, 0x0D, 0x3F,
  35605. 0xB0, 0x10, 0x6D, 0xB9, 0x7D, 0x03, 0x3F, 0xCD,
  35606. 0x40, 0x37, 0x1E, 0x8A, 0xDA, 0xCD, 0xBA, 0xD7,
  35607. 0x8D, 0x89, 0xBD, 0x5E, 0x90, 0xCF, 0x97, 0xE8,
  35608. 0x35, 0x51, 0x87, 0x94, 0xFA, 0x3D, 0xB2, 0xB5,
  35609. 0x01, 0xF2, 0x35, 0x75, 0x77, 0x65, 0x5B, 0x9A,
  35610. 0x3C, 0xDA, 0x36, 0x52, 0xDF, 0xCF, 0x96, 0xBA,
  35611. 0xB9, 0xC5, 0xF9, 0x57, 0x67, 0x0E, 0x32, 0xE5,
  35612. 0x86, 0xE5, 0x1F, 0xD8, 0x9D, 0x7B, 0xA8, 0x76,
  35613. 0x89, 0xFD, 0x59, 0x70, 0x88, 0x73, 0x9D, 0x87,
  35614. 0xE1, 0x24, 0x6D, 0xC2, 0xB5, 0x1E, 0xCD, 0x54,
  35615. 0x29, 0x25, 0x10, 0xA3, 0xB4, 0x3C, 0xB2, 0x5A,
  35616. 0x62, 0xBD, 0xE9, 0x14, 0xEC, 0x3C, 0xBF, 0xA9,
  35617. 0x9D, 0xEC, 0x70, 0xAC, 0x23, 0xC0, 0xDF, 0xC9,
  35618. 0x69, 0xAD, 0x94, 0x1A, 0x69, 0x94, 0xA3, 0x70,
  35619. 0xF9, 0x0B, 0x15, 0x5D, 0x25, 0x45, 0x63, 0xFA,
  35620. 0xAA, 0x7D, 0x30, 0x67, 0x3C, 0x06, 0x34, 0x75,
  35621. 0x3F, 0xD6, 0x57, 0x58, 0x8E, 0xC6, 0x60, 0x3F,
  35622. 0x82, 0x35, 0xE9, 0x17, 0x36, 0x5D, 0xD8, 0x93,
  35623. 0x25, 0x25, 0x1B, 0x21, 0xB2, 0xFF, 0x80, 0xF5,
  35624. 0x44, 0xFE, 0x73, 0x84, 0xFF, 0x62, 0xFE, 0x52,
  35625. 0xC4, 0xCA, 0x77, 0x41, 0x28, 0xC8, 0x95, 0x15,
  35626. 0x2C, 0xC7, 0x5C, 0xA6, 0x3B, 0xA8, 0xF8, 0x1E,
  35627. 0x01, 0x30, 0xC9, 0x3B, 0x59, 0xF9, 0x40, 0xB7,
  35628. 0x18, 0x80, 0x21, 0x24, 0xDB, 0x8D, 0x07, 0xDF,
  35629. 0xDC, 0x24, 0xBF, 0x2F, 0x7B, 0xD9, 0xC4, 0xEF,
  35630. 0x61, 0x74, 0x1A, 0xF2, 0xB6, 0x98, 0x75, 0x66,
  35631. 0x22, 0x4F, 0x11, 0x06, 0x41, 0xDB, 0x77, 0x83,
  35632. 0xFA, 0xF3, 0x1B, 0xEC, 0xB8, 0xF7, 0x89, 0x47,
  35633. 0xBA, 0x12, 0x3F, 0xB0, 0x0E, 0x1B, 0x6D, 0x13,
  35634. 0x36, 0x0B, 0x16, 0xD0, 0x7C, 0x3A, 0xAA, 0x33,
  35635. 0x6D, 0xDA, 0x1B, 0x65, 0xD4, 0xC2, 0xF2, 0x1B,
  35636. 0xD5, 0xCD, 0x4B, 0xE9, 0xED, 0xFA, 0xFA, 0x78,
  35637. 0x45, 0x97, 0x2D, 0x60, 0xCC, 0xE3, 0x40, 0x3E,
  35638. 0xB5, 0xE5, 0xC8, 0x33, 0xF6, 0x4C, 0x51, 0x45,
  35639. 0xDC, 0x08, 0xE7, 0xB3, 0x6F, 0xCF, 0xDE, 0xE8,
  35640. 0x73, 0x0B, 0x94, 0x4F, 0x5A, 0x23, 0xF9, 0xFF,
  35641. 0x3F, 0x0D, 0x1D, 0xCE, 0x80, 0x86, 0x3B, 0x55,
  35642. 0x8D, 0x8A, 0x35, 0xB2, 0xAA, 0x65, 0x27, 0x69,
  35643. 0x1D, 0xA5, 0x0C, 0xE6, 0xFA, 0x39, 0x85, 0x62,
  35644. 0x65, 0xAD, 0xE6, 0x08, 0x38, 0xCE, 0xC9, 0xEA,
  35645. 0x98, 0x73, 0x99, 0x1D, 0xB5, 0x6F, 0xEA, 0xE8,
  35646. 0xEE, 0xE2, 0xEC, 0xF4, 0x32, 0x44, 0x96, 0x5A,
  35647. 0x13, 0xCC, 0x1D, 0x23, 0x0E, 0x91, 0x72, 0xD8,
  35648. 0x2A, 0xD2, 0x3D, 0x6A, 0x6E, 0x2A, 0x37, 0x7A,
  35649. 0x7F, 0x67, 0xF6, 0x40, 0xBF, 0x3A, 0x36, 0x3B,
  35650. 0xC8, 0x1A, 0x78, 0x6D, 0x12, 0xB0, 0x35, 0xA3,
  35651. 0x18, 0x55, 0x33, 0x70, 0x48, 0x48, 0x52, 0x8F,
  35652. 0xB4, 0x59, 0x58, 0xEB, 0xAA, 0xB3, 0x03, 0x67,
  35653. 0x4F, 0xFF, 0xA5, 0x68, 0xE7, 0xAE, 0xAF, 0x46,
  35654. 0x3D, 0x66, 0x6B, 0x60, 0x21, 0x26, 0x31, 0x83,
  35655. 0xBE, 0xE8, 0x1E, 0x72, 0x92, 0x87, 0x79, 0x24,
  35656. 0xCF, 0xDE, 0xEF, 0x6F, 0x81, 0x73, 0xA1, 0x34,
  35657. 0x7B, 0x99, 0x94, 0x43, 0x33, 0xF4, 0x8B, 0x36,
  35658. 0xC8, 0xC5, 0xF8, 0xC1, 0x6D, 0x22, 0x6D, 0xA3,
  35659. 0xC9, 0xDA, 0x5F, 0x4C, 0xE7, 0x7F, 0x00, 0xE4,
  35660. 0x42, 0xD8, 0x5C, 0x73, 0xE5, 0x78, 0x0C, 0x36,
  35661. 0x28, 0xD9, 0x83, 0x8F, 0xCA, 0xFA, 0x5D, 0x1D,
  35662. 0x34, 0x05, 0xF1, 0x93, 0x6C, 0xBC, 0xFD, 0x2C,
  35663. 0x52, 0xD4, 0xE8, 0x8D, 0xA9, 0xC9, 0x0D, 0xFF,
  35664. 0x28, 0x5E, 0x3E, 0x91, 0x12, 0xC0, 0x3C, 0xBA,
  35665. 0x58, 0x64, 0x7E, 0x6B, 0x4E, 0xC0, 0x77, 0xB1,
  35666. 0x67, 0x08, 0x16, 0xF5, 0x7E, 0x29, 0x42, 0x81,
  35667. 0x6A, 0x6F, 0x34, 0x21, 0x32, 0x64, 0x9A, 0xA6,
  35668. 0x44, 0xD1, 0x4F, 0x41, 0xAB, 0xC5, 0x26, 0x4A,
  35669. 0xFA, 0x70, 0xBC, 0xAE, 0x3D, 0x67, 0x9B, 0x86,
  35670. 0xF5, 0x1A, 0xF2, 0x44, 0x70, 0x52, 0xD0, 0x78,
  35671. 0xA0, 0xEA, 0x56, 0x39, 0x0B, 0x37, 0x2A, 0x15,
  35672. 0x13, 0xBC, 0xD2, 0xEA, 0x46, 0x6D, 0xCB, 0x5A,
  35673. 0x4D, 0x86, 0x47, 0x4F, 0xA1, 0xE2, 0x6B, 0xC0,
  35674. 0xA8, 0x3F, 0x58, 0x5C, 0x79, 0xAD, 0x62, 0x17,
  35675. 0xBC, 0x96, 0xAF, 0x77, 0x1F, 0x74, 0xD1, 0x42,
  35676. 0xBF, 0x5E, 0x91, 0xA9, 0x28, 0x44, 0xC5, 0x4E,
  35677. 0x76, 0x6B, 0xF2, 0xD3, 0x69, 0x8C, 0x0E, 0x4F,
  35678. 0x61, 0x76, 0xAD, 0xDC, 0x79, 0xE9, 0x74, 0xA4,
  35679. 0x66, 0xFB, 0x2E, 0x0C, 0xBB, 0x42, 0xC5, 0x3F,
  35680. 0x59, 0xB0, 0xDC, 0xB0, 0x32, 0xCD, 0x37, 0x56,
  35681. 0x1B, 0xD2, 0x46, 0xED, 0x52, 0xC8, 0x12, 0xEA,
  35682. 0xA3, 0x6B, 0xB9, 0xE5, 0xB3, 0x2A, 0xF3, 0x9B,
  35683. 0x0F, 0xC3, 0x77, 0x5F, 0x9A, 0xE1, 0x20, 0xBC,
  35684. 0x59, 0x44, 0x9B, 0x7B, 0x77, 0xB1, 0xBA, 0x1A,
  35685. 0x5B, 0x60, 0x06, 0x6C, 0x85, 0x83, 0x68, 0xDD,
  35686. 0x5A, 0xC8, 0xEE, 0xDC, 0xFE, 0x1F, 0x83, 0xF5,
  35687. 0x2C, 0x53, 0x62, 0xED, 0xE8, 0x93, 0xB7, 0x22,
  35688. 0x3E, 0xCB, 0x70, 0xBA, 0xA6, 0x6D, 0xB2, 0x91,
  35689. 0x47, 0xB8, 0x04, 0x37, 0x20, 0x1F, 0xEF, 0x71,
  35690. 0xB0, 0x5F, 0xF2, 0x51, 0x03, 0x5F, 0x88, 0xCA,
  35691. 0xFF, 0x42, 0xE8, 0x2A, 0x43, 0x02, 0xD3, 0x60,
  35692. 0x98, 0x26, 0x8B, 0x74, 0xF4, 0x18, 0x3D, 0x4D,
  35693. 0x19, 0xF1, 0x3B, 0x87, 0xE9, 0x83, 0x37, 0x15,
  35694. 0x7D, 0xA5, 0xEF, 0xBB, 0xF3, 0x4F, 0x48, 0xCA,
  35695. 0x40, 0x65, 0xD3, 0xE3, 0xBA, 0xCC, 0x83, 0x83,
  35696. 0x3F, 0xEE, 0xBA, 0x57, 0x34, 0x6D, 0x16, 0x9F,
  35697. 0x1B, 0xE6, 0xA0, 0x4C, 0x29, 0xC8, 0x2F, 0xD2,
  35698. 0x25, 0xA3, 0xF7, 0xC6, 0x85, 0x12, 0x4F, 0x53,
  35699. 0x7E, 0xC0, 0xE1, 0x0A, 0xB8, 0x58, 0x34, 0xBA,
  35700. 0x3E, 0x65, 0x4F, 0x19, 0x55, 0x5C, 0xB9, 0x74,
  35701. 0x6B, 0x74, 0xCE, 0x43, 0xA2, 0xC7, 0x8B, 0x21,
  35702. 0x70, 0x8C, 0x3B, 0xEF, 0x87, 0xC1, 0xE8, 0x8F,
  35703. 0x08, 0x10, 0xB4, 0xED, 0xE1, 0x81, 0x14, 0xE9,
  35704. 0x2A, 0x43, 0x13, 0xB4, 0xEA, 0xA0, 0x5F, 0x60,
  35705. 0x93, 0x7E, 0x87, 0x6D, 0xA2, 0x57, 0x63, 0x32,
  35706. 0xAE, 0xC3, 0x8C, 0xCD, 0x42, 0x5E, 0xFD, 0x51,
  35707. 0x1A, 0x39, 0xB9, 0xB4, 0xBD, 0x4C, 0xF3, 0xF2,
  35708. 0xE2, 0x70, 0x9A, 0x05, 0xF9, 0x39, 0xE5, 0xFC,
  35709. 0x59, 0x7D, 0x4E, 0x85, 0x12, 0x02, 0xC9, 0xC2,
  35710. 0xC5, 0x71, 0x3A, 0xD5, 0x73, 0xF7, 0x5A, 0xC5,
  35711. 0x49, 0x0D, 0xEE, 0xCF, 0x9D, 0xB8, 0xDE, 0xE2,
  35712. 0x03, 0x99, 0x70, 0x6B, 0x19, 0x29, 0xA4, 0xE8,
  35713. 0x99, 0x00, 0xC4, 0x9C, 0x24, 0x46, 0x5E, 0x08,
  35714. 0x09, 0x56, 0x6D, 0x9C, 0x2E, 0xF7, 0x8C, 0x52,
  35715. 0xDB, 0xB4, 0x2F, 0x9E, 0x22, 0x7E, 0xFD, 0x1E,
  35716. 0x1A, 0x72, 0xCB, 0x71, 0x0B, 0xD2, 0x19, 0x33,
  35717. 0x0E, 0x69, 0xCC, 0x00, 0x49, 0x36, 0x79, 0x78,
  35718. 0xAB, 0x11, 0x4D, 0x9A, 0xD7, 0xF9, 0x55, 0xCF,
  35719. 0x0B, 0x7B, 0x3D, 0x32, 0x5C, 0xB3, 0x51, 0x65,
  35720. 0x00, 0x0E, 0xD2, 0x9D, 0xBE, 0x0A, 0x19, 0x56,
  35721. 0xF1, 0x45, 0x95, 0x83, 0xC6, 0x97, 0xCD, 0x19,
  35722. 0xE7, 0x8B, 0x51, 0x74, 0xE4, 0xFD, 0x2C, 0xEC,
  35723. 0x10, 0x8A, 0x7C, 0x24, 0x28, 0x0A, 0x78, 0xA3,
  35724. 0xEC, 0x93, 0x97, 0x16, 0x4F, 0x60, 0x03, 0xFD,
  35725. 0x85, 0x31, 0x98, 0x04, 0xE5, 0x65, 0x5A, 0x87,
  35726. 0x9F, 0x66, 0x3D, 0xD4, 0x56, 0x3E, 0xF9, 0x98,
  35727. 0x25, 0x21, 0xFE, 0xC2, 0x07, 0x9E, 0x88, 0x89,
  35728. 0x49, 0x7B, 0xE9, 0x20, 0x1F, 0x6D, 0x7F, 0x24,
  35729. 0x60, 0xA8, 0xB2, 0xDD, 0x96, 0x51, 0x0E, 0x0E,
  35730. 0x4C, 0x83, 0xC3, 0xB1, 0x93, 0xC1, 0x1F, 0xD6,
  35731. 0xB4, 0xB6, 0x84, 0xCE, 0x85, 0x63, 0xA5, 0x38,
  35732. 0x0F, 0x2E, 0x55, 0xF4, 0x74, 0xA6, 0x0B, 0x63,
  35733. 0x17, 0xD0, 0x96, 0x76, 0x15, 0xAD, 0x4F, 0xA9,
  35734. 0xF0, 0x83, 0x25, 0xAD, 0xD7, 0x97, 0xB7, 0x9E,
  35735. 0x6F, 0x5D, 0xC7, 0x2A, 0xD1, 0x97, 0xF5, 0xF6,
  35736. 0x1E, 0xC8, 0x8B, 0xE5, 0xFB, 0xFF, 0x92, 0x72,
  35737. 0x31, 0x9A, 0x49, 0x4B, 0x60, 0x8F, 0x34, 0x7C,
  35738. 0xE1, 0x55, 0x66, 0x7A, 0x59, 0xC3, 0x00, 0x9A,
  35739. 0x14, 0x50, 0xF3, 0x06, 0x19, 0x3C, 0xFE, 0x61,
  35740. 0x1C, 0xF7, 0x05, 0x49, 0x2A, 0x30, 0xFF, 0x56,
  35741. 0xFE, 0x7F, 0x71, 0xD7, 0x32, 0xCC, 0xEF, 0x63,
  35742. 0x64, 0xE1, 0x66, 0xCF, 0xF8, 0x12, 0xED, 0x23,
  35743. 0x11, 0xB5, 0x16, 0xFA, 0x56, 0x90, 0xF2, 0xA2,
  35744. 0x72, 0x7B, 0x18, 0x50, 0xF2, 0x98, 0x5D, 0x48,
  35745. 0x25, 0x5E, 0x8C, 0x47, 0xE7, 0x11, 0x50, 0x2A,
  35746. 0x4B, 0x4A, 0x97, 0x0B, 0xDF, 0x70, 0xDC, 0x34,
  35747. 0x47, 0xF8, 0xE2, 0x88, 0x78, 0x24, 0xB5, 0x8A,
  35748. 0xC7, 0x58, 0xE8, 0x83, 0xF7, 0x3B, 0xAD, 0xFC,
  35749. 0xED, 0x46, 0x40, 0xD5, 0x46, 0x35, 0x1B, 0xF3,
  35750. 0x3E, 0x8F, 0x1E, 0x0B, 0x1B, 0xB9, 0xFB, 0x5A,
  35751. 0xFF, 0x0F, 0x8B, 0xA0, 0x95, 0x4A, 0x8E, 0x65,
  35752. 0x33, 0xD3, 0x7C, 0x03, 0x04, 0x8E, 0xBA, 0x6A,
  35753. 0x55, 0xB3, 0xC5, 0xDA, 0xCB, 0xDC, 0x44, 0xD3,
  35754. 0x98, 0x77, 0xD3, 0x07, 0x8A, 0xE9, 0x5E, 0x44,
  35755. 0x5B, 0xED, 0x12, 0xB1, 0xA5, 0x03, 0xAF, 0xB2,
  35756. 0x20, 0x0C, 0xB1, 0x8B, 0x08, 0xB4, 0x6A, 0x11,
  35757. 0x96, 0xA9, 0xF5, 0x7A, 0xFD, 0x56, 0x48, 0x11,
  35758. 0xC0, 0x30, 0xA4, 0x45, 0xFC, 0xAE, 0x72, 0xE5,
  35759. 0x5E, 0x85, 0xB7, 0x6F, 0xA0, 0x50, 0x13, 0x4B,
  35760. 0x2E, 0xC2, 0x31, 0x13, 0xED, 0x04, 0x04, 0x3D,
  35761. 0xBC, 0xD0, 0xB6, 0xFC, 0xCE, 0xBD, 0xC9, 0x13,
  35762. 0x5C, 0xB2, 0x02, 0xB8, 0x4F, 0xDD, 0x74, 0x51,
  35763. 0x1F, 0x9E, 0x8F, 0x0C, 0xF2, 0x26, 0xE1, 0x4C,
  35764. 0xA5, 0xC4, 0x38, 0xC7, 0x6A, 0xA5, 0xC3, 0xC2,
  35765. 0xE9, 0xF3, 0x22, 0x71, 0x00, 0x91, 0x83, 0xEE,
  35766. 0x92, 0xA9, 0x95, 0x81, 0x9D, 0xB9, 0x0F, 0x66,
  35767. 0x89, 0x9B, 0xB9, 0xB0, 0xC7, 0xED, 0x31, 0xDF,
  35768. 0x41, 0xB6, 0x8E, 0x52, 0xAC, 0x5B, 0xBD, 0xF2,
  35769. 0x33, 0x9F, 0x71, 0x5E, 0x43, 0xFE, 0xED, 0xD9,
  35770. 0x4F, 0x57, 0xF9, 0x23, 0x05, 0x23, 0x03, 0x34,
  35771. 0x17, 0xE4, 0x22, 0x27, 0x97, 0xF7, 0x62, 0x5B,
  35772. 0x52, 0x66, 0x70, 0xEE, 0x6B, 0xD3, 0x46, 0x8C,
  35773. 0xCD, 0x9B, 0xA4, 0xA1, 0xED, 0x26, 0x4A, 0xAC,
  35774. 0xC2, 0x50, 0xA8, 0x2A, 0x48, 0x83, 0x46, 0xB2,
  35775. 0xA5, 0xF9, 0x26, 0xF2, 0xE7, 0x8A, 0x8E, 0xD8,
  35776. 0x40, 0x5F, 0x85, 0x8E, 0xAB, 0xB0, 0x29, 0xF7,
  35777. 0x81, 0x42, 0xA7, 0x4B, 0xD5, 0xA8, 0x2D, 0x3D,
  35778. 0xD7, 0x0A, 0xB1, 0x26, 0xCF, 0xA3, 0xBA, 0xD7,
  35779. 0xF5, 0x1B, 0x9E, 0x95, 0xCB, 0xC8, 0xCE, 0x75,
  35780. 0xE7, 0x7A, 0x4A, 0x1B, 0x63, 0x21, 0xB7, 0x74,
  35781. 0x77, 0x78, 0xCD, 0x03, 0x5B, 0x3B, 0xCD, 0x44,
  35782. 0x8E, 0xF1, 0xBB, 0xB6, 0xFF, 0x75, 0x52, 0x8A,
  35783. 0x7A, 0xE9, 0xAF, 0x62, 0x24, 0xA1, 0x6F, 0x4F,
  35784. 0x45, 0x03, 0x87, 0xA3, 0xED, 0xBC, 0x2E, 0x92,
  35785. 0xC0, 0xB1, 0x9C, 0x22, 0x2E, 0x35, 0xC1, 0xA5,
  35786. 0x7E, 0xC3, 0x36, 0x3B, 0x18, 0x14, 0x78, 0x6E,
  35787. 0x1D, 0x37, 0xD7, 0x92, 0xB3, 0x78, 0x26, 0x13,
  35788. 0x9A, 0xFB, 0x38, 0x1D, 0xE0, 0x4C, 0x07, 0xC4,
  35789. 0x2C, 0xD3, 0xCA, 0x78, 0xE4, 0x70, 0xC2, 0x52,
  35790. 0x7C, 0x63, 0xDB, 0x4B, 0xB4, 0x0A, 0x4B, 0x7D,
  35791. 0x20, 0x67, 0xF0, 0xF4, 0x80, 0x5B, 0x65, 0x8B,
  35792. 0x29, 0x80, 0x92, 0xF0, 0x87, 0x3D, 0x09, 0x5A,
  35793. 0x0E, 0xEA, 0x45, 0x63, 0x92, 0x99, 0xD6, 0x0D,
  35794. 0x2B, 0x58, 0xEE, 0x19, 0x03, 0x4F, 0x94, 0x2D,
  35795. 0xEC, 0xBF, 0x5A, 0xE9, 0xA6, 0x16, 0xAF, 0x72,
  35796. 0x37, 0x5C, 0x12, 0xBB, 0x7D, 0xED, 0xAA, 0x6A,
  35797. 0x7D, 0xDF, 0x9A, 0x48, 0x37, 0x37, 0x3D, 0x7B,
  35798. 0x51, 0x96, 0x0B, 0x30, 0xCE, 0x9C, 0xE7, 0x3B,
  35799. 0x3C, 0x10, 0xDE, 0x32, 0xA7, 0x86, 0x39, 0xA9,
  35800. 0x33, 0x7D, 0x9B, 0xCF, 0x15, 0x27, 0xA4, 0x36,
  35801. 0x88, 0xBD, 0xB6, 0xEB, 0x8B, 0xD0, 0x3D, 0xCA,
  35802. 0xF1, 0x02, 0x70, 0xDF, 0xC0, 0xE2, 0xF0, 0xD2,
  35803. 0x2C, 0x27, 0xE3, 0x22, 0x24, 0x33, 0x27, 0x34,
  35804. 0xCA, 0x26, 0x19, 0x74, 0x02, 0x2F, 0x7E, 0xC1,
  35805. 0x76, 0xCB, 0x12, 0xBE, 0x6F, 0x13, 0x62, 0x1F,
  35806. 0x32, 0x03, 0x65, 0xCF, 0xBB, 0x03, 0xD0, 0x4C,
  35807. 0xF2, 0x9E, 0xFE, 0x93, 0xE9, 0x1B, 0x02, 0x9B,
  35808. 0x7B, 0x26, 0xFF, 0xEE, 0xF0, 0x6F, 0xCE, 0x57,
  35809. 0xD1, 0x2B, 0xE3, 0x90, 0x2E, 0xE2, 0x71, 0x2A,
  35810. 0xBA, 0xCC, 0x3D, 0x27, 0xCE, 0xA3, 0x5A, 0xCA,
  35811. 0x15, 0x09, 0xE4, 0xD0, 0x86, 0x4F, 0xEC, 0x5A,
  35812. 0x5B, 0x41, 0xA0, 0xE0, 0x3E, 0x1D, 0xEC, 0x6F,
  35813. 0x2A, 0x33, 0x72, 0x15, 0xCD, 0xE5, 0x55, 0xD6,
  35814. 0x6F, 0x84, 0xE3, 0xD6, 0x75, 0x5D, 0xDC, 0x1C,
  35815. 0x07, 0x3D, 0x0C, 0xDC, 0xDE, 0xF8, 0x8A, 0x44,
  35816. 0x40, 0xB1, 0x76, 0x84, 0xB8, 0xE0, 0xAF, 0x9D,
  35817. 0xA2, 0xB2, 0x84, 0xAA, 0xBF, 0x61, 0x08, 0x21,
  35818. 0xE5, 0xC2, 0xC9, 0x11, 0x94, 0x2D, 0x0B, 0xD1,
  35819. 0xC6, 0x59, 0xC1, 0xEE, 0xBA, 0x8E, 0x21, 0xAF,
  35820. 0xDE, 0x32, 0x77, 0xD5, 0x07, 0x3B, 0x98, 0x39,
  35821. 0x95, 0x77, 0x03, 0x80, 0x2F, 0xA2, 0x76, 0xC8,
  35822. 0x2C, 0xC6, 0x6A, 0x00, 0xA8, 0x69, 0x77, 0xB8,
  35823. 0x87, 0x7D, 0xC0, 0x51, 0x19, 0x45, 0x14, 0xA6,
  35824. 0x33, 0xB3, 0x4D, 0x36, 0x29, 0x34, 0xE8, 0x50,
  35825. 0xC2, 0x71, 0x7A, 0x0B, 0xE5, 0x92, 0x4E, 0x86,
  35826. 0xAA, 0xDA, 0x33, 0xCF, 0x34, 0x54, 0x63, 0x2C,
  35827. 0x68, 0xA1, 0x0A, 0xEF, 0x8B, 0x5B, 0xAA, 0x10,
  35828. 0x83, 0xE9, 0x13, 0x7D, 0x29, 0x20, 0xA2, 0x5F,
  35829. 0x96, 0x9F, 0x54, 0x0B, 0x95, 0xDF, 0x59, 0x91,
  35830. 0x6C, 0x4C, 0xAC, 0xC4, 0x55, 0x98, 0x8F, 0x46,
  35831. 0x31, 0x77, 0x56, 0xCC, 0x93, 0x7E, 0xF0, 0x17,
  35832. 0x7C, 0x0F, 0xEB, 0x3F, 0x23, 0xBB, 0xD3, 0x56,
  35833. 0x9E, 0x89, 0x67, 0xC4, 0x9B, 0x95, 0xA3, 0xBF,
  35834. 0x6D, 0x9D, 0x6D, 0x7C, 0x72, 0x27, 0x20, 0x6E,
  35835. 0x28, 0x37, 0x39, 0xFC, 0x77, 0x41, 0xE9, 0xFE,
  35836. 0x64, 0xEF, 0xA0, 0x38, 0x9F, 0xC7, 0x2F, 0xDA,
  35837. 0xC8, 0x1F, 0xEB, 0x75, 0x07, 0xB8, 0x7E, 0x6B,
  35838. 0x73, 0xCE, 0x0E, 0x7C, 0x7C, 0x54, 0x06, 0x1D,
  35839. 0x48, 0x8A, 0x06, 0x53, 0x95, 0x9B, 0x75, 0x8A,
  35840. 0xFF, 0x6F, 0x7D, 0x19, 0x00, 0x17, 0x8D, 0x7C,
  35841. 0x1A, 0xEA, 0xD0, 0x79, 0x45, 0x68, 0xF9, 0x2F,
  35842. 0x8A, 0xCE, 0x98, 0xED, 0xCC, 0xE8, 0x6D, 0xE1,
  35843. 0x08, 0xA0, 0x50, 0x2C, 0x43, 0x49, 0xC4, 0x99,
  35844. 0x98, 0x31, 0xDE, 0x00, 0xE8, 0x08, 0x39, 0x0B,
  35845. 0xBB, 0xDB, 0x65, 0xEA, 0x36, 0x0F, 0xBE, 0x98,
  35846. 0xB7, 0x4A, 0x9C, 0x59, 0x34, 0x0E, 0xBB, 0xDD,
  35847. 0x6F, 0x65, 0x21, 0x39, 0x23, 0x48, 0x57, 0x7F,
  35848. 0xD4, 0x07, 0x89, 0x03, 0x01, 0xB0, 0x79, 0x27,
  35849. 0x28, 0xCC, 0xFB, 0x88, 0xC5, 0xDD, 0x47, 0x2A,
  35850. 0xDA, 0x73, 0x75, 0x9B, 0xC9, 0x99, 0xA0, 0x21,
  35851. 0x34, 0xDF, 0xB1, 0x62, 0x2F, 0x61, 0xD8, 0xB7,
  35852. 0x63, 0x2A, 0xC7, 0x7E, 0x3A, 0x98, 0x0B, 0x2C,
  35853. 0xE5, 0x66, 0xF3, 0xD5, 0x30, 0xF0, 0xBC, 0x21,
  35854. 0xC7, 0x51, 0x9B, 0xFB, 0x00, 0xBB, 0xAA, 0x9C,
  35855. 0x85, 0xC3, 0x9B, 0x0C, 0xDC, 0x5F, 0x8D, 0x1B,
  35856. 0xA1, 0x2B, 0x78, 0x82, 0xFE, 0x0F, 0x7C, 0x75,
  35857. 0x6E, 0x75, 0x56, 0x74, 0x35, 0x25, 0xE5, 0xD0,
  35858. 0xEC, 0x8E, 0xC1, 0xBD, 0x7D, 0x7A, 0xE3, 0xDC,
  35859. 0xAD, 0xC6, 0x8D, 0xB6, 0x0D, 0x7A, 0xA1, 0x3C,
  35860. 0xDB, 0x29, 0xFA, 0x15, 0xC0, 0xA9, 0xAF, 0x89,
  35861. 0x0F, 0x18, 0x75, 0xE3, 0x97, 0x58, 0x62, 0x12,
  35862. 0x79, 0xA9, 0x87, 0x7D, 0x9C, 0x69, 0x44, 0x9C,
  35863. 0x41, 0x39, 0x2C, 0xAD, 0x98, 0x8B, 0x8D, 0xE4,
  35864. 0x58, 0xEE, 0xCD, 0x98, 0x38, 0x5F, 0x79, 0x73,
  35865. 0x0B, 0x5E, 0x26, 0xC1, 0x16, 0x24, 0x15, 0xD9,
  35866. 0x73, 0x26, 0x41, 0x9B, 0x5F, 0xF9, 0x2A, 0xA8,
  35867. 0xC1, 0x33, 0x74, 0x39, 0x1D, 0xBB, 0xE7, 0x36,
  35868. 0xD9, 0x8C, 0x07, 0xAD, 0x32, 0xD6, 0x38, 0xBB,
  35869. 0x44, 0xE6, 0x77, 0xC7, 0x11, 0x05, 0xCF, 0xB5,
  35870. 0x72, 0x49, 0x68, 0x80, 0xC1, 0x67, 0x71, 0x5F,
  35871. 0x9B, 0xFF, 0x6E, 0x71, 0x1A, 0xBE, 0x5A, 0x83,
  35872. 0x25, 0x38, 0xC7, 0xE6, 0xDA, 0x88, 0x22, 0xDC,
  35873. 0xA6, 0x03, 0x02, 0xD1, 0x59, 0xC6, 0xA8, 0x2F,
  35874. 0xA4, 0x8F, 0xF8, 0x77, 0x3E, 0x0C, 0x6F, 0xA1,
  35875. 0x73, 0xE1, 0x35, 0x55, 0xB2, 0xDF, 0xBF, 0x47,
  35876. 0xB7, 0xD0, 0x8D, 0xBA, 0x35, 0x74, 0x44, 0x6B,
  35877. 0xC0, 0xA7, 0x8D, 0x30, 0x08, 0xE4, 0x41, 0xD1,
  35878. 0x55, 0x21, 0x50, 0xD9, 0x06, 0x12, 0x54, 0xB2,
  35879. 0xF3, 0xFC, 0x5A, 0x1E, 0xF3, 0xE3, 0x84, 0x33,
  35880. 0x34, 0x0B, 0xB5, 0x9A, 0x97, 0xFD, 0x51, 0xF4,
  35881. 0x68, 0xFE, 0x8A, 0x92, 0xBF, 0x62, 0x9D, 0xCD,
  35882. 0x00, 0x29, 0x39, 0x37, 0x12, 0xF3, 0x53, 0x6D,
  35883. 0x6B, 0x24, 0xB8, 0x86, 0x68, 0xAD, 0x6A, 0x4B,
  35884. 0x3A, 0x4C, 0x93, 0xA6, 0xB1, 0x41, 0xFA, 0x8E,
  35885. 0x58, 0x63, 0xCD, 0x59, 0x80, 0xBF, 0xD7, 0xAB,
  35886. 0x83, 0xC3, 0xCC, 0x5D, 0x2F, 0xBE, 0x80, 0xC7,
  35887. 0xB1, 0x67, 0xDC, 0x92, 0x8C, 0xA9, 0x57, 0x36,
  35888. 0x58, 0x0A, 0x52, 0x96, 0x0E, 0x20, 0x90, 0xCD,
  35889. 0x87, 0x68, 0xF5, 0x93, 0xBB, 0x04, 0xD4, 0x48,
  35890. 0xB6, 0x45, 0x30, 0xC0, 0xE3, 0xC2, 0x56, 0x8C,
  35891. 0xE3, 0xA2, 0xC6, 0x42, 0x0F, 0x81, 0xF7, 0x4D,
  35892. 0xF6, 0x88, 0x5D, 0x55, 0x07, 0x8E, 0xF1, 0xB3,
  35893. 0x83, 0xB0, 0x20, 0x85, 0x4A, 0x63, 0x6A, 0x78,
  35894. 0xA9, 0xEC, 0x13, 0x84, 0xF7, 0x4E, 0xBE, 0xB6,
  35895. 0x5F, 0x5A, 0x25, 0xFF, 0xD4, 0x14, 0x7D, 0xA7,
  35896. 0xEE, 0x40, 0xF6, 0x25, 0x7C, 0x7E, 0x34, 0xCA,
  35897. 0xC9, 0x27, 0x0E, 0xA2, 0x78, 0xB6, 0xE6, 0x08,
  35898. 0xA1, 0x9B, 0x56, 0x8D, 0x29, 0xE5, 0x8D, 0xEC,
  35899. 0xAD, 0xDA, 0xD3, 0x3C, 0x59, 0xBA, 0xDB, 0x92,
  35900. 0x52, 0x99, 0x3B, 0x31, 0x6B, 0x0B, 0x13, 0x00,
  35901. 0x79, 0x3D, 0x69, 0x85, 0x3A, 0x6B, 0x90, 0x33,
  35902. 0x96
  35903. };
  35904. static const byte rnd_44[] = {
  35905. 0x08, 0x34, 0x57, 0xD4, 0x0E, 0x25, 0x04, 0x88,
  35906. 0xA6, 0x0E, 0x76, 0x34, 0xA0, 0x1D, 0x43, 0x0A,
  35907. 0x60, 0xE8, 0x57, 0x2B, 0xA8, 0x8A, 0xED, 0xC5,
  35908. 0x54, 0x49, 0x18, 0x81, 0x37, 0x13, 0xA0, 0xB1
  35909. };
  35910. static const byte sig_44[] = {
  35911. 0x63, 0xA8, 0x23, 0x20, 0xD4, 0xCE, 0x09, 0xC4,
  35912. 0x7A, 0xD1, 0x27, 0xC5, 0xBB, 0x7F, 0x6C, 0x2D,
  35913. 0xFF, 0x15, 0x29, 0xCD, 0xAF, 0x9F, 0x74, 0x56,
  35914. 0xFF, 0xC2, 0xC6, 0xED, 0x90, 0x51, 0x17, 0xDC,
  35915. 0xAD, 0x8C, 0x08, 0x7A, 0xC0, 0xD8, 0x9E, 0x0C,
  35916. 0xE9, 0x61, 0xC0, 0x94, 0xFA, 0x9C, 0x2E, 0xDE,
  35917. 0x27, 0x9C, 0x65, 0xE6, 0x99, 0xD1, 0xD1, 0x7E,
  35918. 0xA6, 0x95, 0x98, 0x8F, 0xA1, 0xC4, 0x98, 0x3F,
  35919. 0x7E, 0x1F, 0x18, 0x86, 0x2A, 0xFE, 0xB2, 0xEC,
  35920. 0x9D, 0x0F, 0x5B, 0x0C, 0x11, 0xB2, 0xAA, 0x0B,
  35921. 0xDE, 0x95, 0x7C, 0x40, 0xA1, 0x5B, 0xFF, 0x97,
  35922. 0xD7, 0xCB, 0xCF, 0x4E, 0x59, 0xDA, 0xE9, 0xD5,
  35923. 0xA3, 0xC9, 0xF8, 0x7D, 0xDD, 0xA5, 0xB9, 0x06,
  35924. 0x9D, 0x82, 0xCC, 0x18, 0x10, 0x20, 0x80, 0x92,
  35925. 0xBC, 0xBA, 0x1C, 0x43, 0x73, 0xF2, 0xA8, 0x3E,
  35926. 0x19, 0x15, 0x80, 0x9E, 0x81, 0xD8, 0xD2, 0x06,
  35927. 0xEA, 0x78, 0x10, 0x3F, 0x68, 0x66, 0x3D, 0xBE,
  35928. 0xB1, 0x79, 0xB0, 0x28, 0x83, 0xCD, 0xD3, 0x33,
  35929. 0xEE, 0xFE, 0x6D, 0x02, 0x39, 0x17, 0xC6, 0xF2,
  35930. 0xA4, 0x6E, 0x5A, 0x5C, 0x45, 0x14, 0xF5, 0x7D,
  35931. 0xCA, 0x7B, 0x62, 0x4A, 0xF4, 0xE7, 0x71, 0x7B,
  35932. 0xD7, 0x1B, 0x51, 0x26, 0xE6, 0xDE, 0x2D, 0xC9,
  35933. 0x65, 0x24, 0x30, 0x2C, 0x08, 0x04, 0xD7, 0xBE,
  35934. 0x3A, 0xDA, 0x64, 0xAF, 0x11, 0x6F, 0xC6, 0xE7,
  35935. 0x38, 0xEF, 0xA6, 0xE6, 0x5E, 0x87, 0x90, 0xB4,
  35936. 0x0E, 0xB1, 0xB4, 0x83, 0x64, 0xD2, 0x15, 0xEF,
  35937. 0xD6, 0x1F, 0x7A, 0x44, 0x75, 0x3A, 0x95, 0x50,
  35938. 0x6E, 0x52, 0xC9, 0x9C, 0xE9, 0xB4, 0x56, 0xDC,
  35939. 0x93, 0x85, 0x92, 0xF1, 0x35, 0xEC, 0x50, 0x1B,
  35940. 0x3B, 0xCF, 0x82, 0xDA, 0x69, 0xA1, 0xDD, 0x44,
  35941. 0xE8, 0xB3, 0xC1, 0xCB, 0x8D, 0xD5, 0x13, 0xD0,
  35942. 0xF3, 0x14, 0x2C, 0x80, 0x82, 0x2C, 0x31, 0xBF,
  35943. 0x75, 0x20, 0x14, 0x39, 0x9F, 0x81, 0x79, 0x76,
  35944. 0x0F, 0xB6, 0x7D, 0xB6, 0x58, 0x1C, 0xF3, 0xE6,
  35945. 0x93, 0x5A, 0x9B, 0xE1, 0x8B, 0x92, 0xC2, 0xDB,
  35946. 0xF1, 0x89, 0xAA, 0x46, 0x67, 0xFA, 0x80, 0x45,
  35947. 0x72, 0xAA, 0xB4, 0xE2, 0x5E, 0xE9, 0xD1, 0xA7,
  35948. 0xA0, 0xD7, 0x05, 0x5C, 0xC6, 0xC7, 0x6D, 0x1D,
  35949. 0x66, 0x3D, 0x35, 0x0C, 0xB7, 0x1A, 0xFA, 0xB1,
  35950. 0xDB, 0xD0, 0xCB, 0x3A, 0x8B, 0xB7, 0x1B, 0x03,
  35951. 0x60, 0xA0, 0xA4, 0xDA, 0xD0, 0xE2, 0x3A, 0x1E,
  35952. 0xB5, 0xE4, 0x59, 0x68, 0x6A, 0x02, 0x94, 0x66,
  35953. 0x05, 0x60, 0x08, 0x64, 0xB4, 0xEE, 0x0F, 0x3A,
  35954. 0xCE, 0xFD, 0x40, 0x7B, 0x6F, 0xF5, 0x8D, 0x1E,
  35955. 0xFF, 0x0C, 0x75, 0xAF, 0xC1, 0x41, 0xC6, 0x24,
  35956. 0x1D, 0xF3, 0x76, 0x02, 0x48, 0x6B, 0xBA, 0x58,
  35957. 0xBC, 0xBB, 0xFE, 0xD3, 0x51, 0xC2, 0x68, 0x21,
  35958. 0x4B, 0x20, 0x4E, 0xAF, 0x8A, 0x0C, 0x74, 0x7F,
  35959. 0x5F, 0xB7, 0xAA, 0x43, 0xFC, 0x5A, 0x77, 0xA1,
  35960. 0x81, 0xCD, 0xBA, 0xE1, 0x31, 0x87, 0x1F, 0xA8,
  35961. 0x1F, 0x76, 0x30, 0x6C, 0xE0, 0x84, 0xCD, 0x14,
  35962. 0x4A, 0xDB, 0x67, 0xFD, 0x65, 0x8C, 0x35, 0xC0,
  35963. 0x91, 0x6C, 0x2B, 0xCF, 0x5B, 0x89, 0x29, 0x58,
  35964. 0x42, 0x9B, 0x65, 0xDB, 0x34, 0x7D, 0xD8, 0x31,
  35965. 0xC9, 0xB8, 0x0D, 0x07, 0xD1, 0x94, 0x60, 0x63,
  35966. 0x65, 0xDC, 0xB3, 0x70, 0x48, 0x46, 0x37, 0x18,
  35967. 0x4D, 0x5D, 0xE0, 0xAC, 0x77, 0xD0, 0x9E, 0xE1,
  35968. 0xD9, 0xB2, 0x2D, 0x09, 0xD6, 0xF8, 0x94, 0x96,
  35969. 0x7B, 0x43, 0xD9, 0x76, 0x36, 0xE6, 0x24, 0xA4,
  35970. 0x4A, 0xFF, 0x12, 0xFE, 0x30, 0x95, 0xD7, 0xCB,
  35971. 0xA9, 0xA0, 0x3A, 0xCA, 0xFC, 0x52, 0x57, 0xB8,
  35972. 0x20, 0x80, 0xF2, 0xD8, 0xAE, 0x3E, 0x18, 0xFC,
  35973. 0x0D, 0xE0, 0x9D, 0x01, 0x7B, 0x03, 0xAD, 0x6B,
  35974. 0xEE, 0xA4, 0xEC, 0x38, 0x40, 0xAC, 0x85, 0x42,
  35975. 0xF8, 0xCF, 0x93, 0x10, 0x8F, 0x8C, 0xFE, 0xF8,
  35976. 0x22, 0x64, 0xFC, 0xDD, 0x2C, 0xDD, 0x86, 0x97,
  35977. 0x5B, 0x3F, 0x8F, 0xDF, 0x1F, 0x58, 0x22, 0x08,
  35978. 0x26, 0x8A, 0x76, 0xE6, 0xC9, 0xFE, 0xDF, 0x42,
  35979. 0x90, 0x8D, 0x52, 0x78, 0xA2, 0xBF, 0xBD, 0x3F,
  35980. 0xD5, 0xD5, 0xDB, 0xAF, 0xDD, 0x5E, 0x2C, 0x2B,
  35981. 0x9F, 0x2E, 0xDC, 0xC1, 0xC4, 0x52, 0x96, 0x38,
  35982. 0x49, 0xCB, 0x34, 0xEC, 0x51, 0x00, 0x8D, 0x1B,
  35983. 0xF6, 0xDA, 0x50, 0xA0, 0xD1, 0x9D, 0x82, 0x34,
  35984. 0x5B, 0x78, 0x8C, 0x05, 0x40, 0xE1, 0x7B, 0x25,
  35985. 0xFF, 0xDC, 0xE8, 0xD4, 0x45, 0x3B, 0xBE, 0x75,
  35986. 0x1E, 0xDA, 0x96, 0xA4, 0x4C, 0x75, 0xFD, 0xD9,
  35987. 0x00, 0x81, 0x85, 0x7D, 0xC0, 0xF8, 0x26, 0x2A,
  35988. 0x30, 0x7B, 0x34, 0xCB, 0xEC, 0xD1, 0x56, 0x58,
  35989. 0x69, 0xA3, 0x14, 0xD6, 0x4C, 0x09, 0xDC, 0x9D,
  35990. 0x4A, 0x80, 0x26, 0x52, 0x2F, 0xDF, 0xE4, 0xCB,
  35991. 0x5B, 0x8B, 0x11, 0x05, 0xDA, 0xE0, 0xDB, 0x66,
  35992. 0xC8, 0x5B, 0xB4, 0x32, 0x1D, 0xBE, 0x76, 0x84,
  35993. 0xEB, 0x6B, 0x6F, 0x85, 0x87, 0xD8, 0x32, 0x0C,
  35994. 0x6D, 0xB3, 0x8D, 0xED, 0xD6, 0x18, 0x96, 0xED,
  35995. 0x51, 0xAB, 0x0C, 0x7F, 0x42, 0x8F, 0x19, 0xD2,
  35996. 0x55, 0xC6, 0xB0, 0xFD, 0xF5, 0x89, 0x51, 0xE5,
  35997. 0xCD, 0xB1, 0x96, 0x9C, 0xD9, 0xA7, 0x93, 0x4E,
  35998. 0xFD, 0xB9, 0xC8, 0x2E, 0x1E, 0x8D, 0x2A, 0x59,
  35999. 0xC9, 0xF7, 0x9D, 0xF1, 0xAA, 0x93, 0xE5, 0x07,
  36000. 0x1E, 0x3F, 0xAC, 0x73, 0x19, 0xFF, 0x68, 0x87,
  36001. 0x8C, 0xF2, 0x49, 0xDC, 0xBD, 0xCD, 0x10, 0x46,
  36002. 0x16, 0xCC, 0xC1, 0xC1, 0xFB, 0xD7, 0x85, 0x56,
  36003. 0x9F, 0x55, 0x87, 0x10, 0x44, 0x1B, 0x31, 0xCA,
  36004. 0xE3, 0x16, 0x7A, 0x4C, 0xD7, 0xDD, 0xD1, 0x86,
  36005. 0x26, 0xC5, 0x43, 0x62, 0x96, 0x20, 0x32, 0xE6,
  36006. 0xB7, 0xA2, 0x76, 0x05, 0x61, 0x96, 0xFC, 0x22,
  36007. 0x96, 0x7E, 0x90, 0x7C, 0x32, 0x0A, 0x7A, 0xF5,
  36008. 0x8C, 0xE3, 0xF5, 0x01, 0xC4, 0xCD, 0x31, 0x8A,
  36009. 0x70, 0x75, 0x04, 0xF1, 0xC2, 0x59, 0xE5, 0x07,
  36010. 0xA0, 0xD4, 0x7D, 0x25, 0x8E, 0x2F, 0x38, 0xE2,
  36011. 0x6A, 0x53, 0x41, 0x34, 0x7A, 0x06, 0xB5, 0x8B,
  36012. 0xB0, 0xBF, 0x21, 0xDE, 0xE6, 0x5F, 0x55, 0x6A,
  36013. 0xD4, 0x88, 0xA7, 0x36, 0xD4, 0xC6, 0x5C, 0x82,
  36014. 0xC6, 0x73, 0xC0, 0x60, 0xD7, 0xA6, 0xA0, 0x77,
  36015. 0x5C, 0xF8, 0xC3, 0x9A, 0xA1, 0x31, 0xFD, 0x64,
  36016. 0xDB, 0xB1, 0x7B, 0x72, 0x70, 0x4B, 0x7D, 0x1D,
  36017. 0x24, 0xBC, 0x5F, 0x84, 0x08, 0x3B, 0xF8, 0xA6,
  36018. 0x47, 0xEB, 0xED, 0xCF, 0xDD, 0xA0, 0x91, 0x14,
  36019. 0x26, 0x7D, 0x77, 0xCF, 0xBF, 0x39, 0x9B, 0xD9,
  36020. 0x2F, 0x3B, 0x2A, 0xA7, 0x2B, 0xBC, 0xF7, 0xDE,
  36021. 0x9D, 0x69, 0xBF, 0x90, 0xA4, 0xDE, 0x2C, 0xF8,
  36022. 0x24, 0x92, 0x7D, 0xE2, 0xB8, 0xBD, 0xF4, 0x6B,
  36023. 0x10, 0x9E, 0xD6, 0x08, 0x51, 0xC5, 0x9C, 0x44,
  36024. 0x8E, 0xCB, 0x44, 0x3F, 0x00, 0x26, 0x3C, 0x9C,
  36025. 0x25, 0xF4, 0x62, 0x74, 0xD1, 0x7C, 0x29, 0x4C,
  36026. 0xEB, 0xF2, 0x53, 0x7D, 0x8F, 0xEA, 0xBD, 0x78,
  36027. 0xEE, 0xBC, 0xBA, 0x72, 0x64, 0xA5, 0xB9, 0x45,
  36028. 0x08, 0xE0, 0xBF, 0x62, 0xEF, 0xC2, 0x1E, 0x06,
  36029. 0xE1, 0xE2, 0xFB, 0x14, 0x44, 0xC5, 0xAB, 0x6F,
  36030. 0x84, 0x7F, 0x52, 0x2F, 0x8A, 0xBE, 0xED, 0x04,
  36031. 0x6D, 0x6D, 0xDC, 0xFF, 0xBC, 0xB8, 0xC8, 0x1F,
  36032. 0xD0, 0x5D, 0x4D, 0x7F, 0x2E, 0x1B, 0xC9, 0x9B,
  36033. 0xEA, 0xF8, 0xC1, 0xAF, 0xE3, 0xE0, 0x5B, 0x36,
  36034. 0x90, 0xFE, 0xE4, 0xAA, 0x37, 0x5A, 0x3D, 0xCB,
  36035. 0x77, 0x57, 0x7C, 0xCC, 0x6E, 0x3E, 0xBE, 0x8A,
  36036. 0x98, 0x7C, 0x6D, 0x7E, 0x89, 0x60, 0x73, 0xC0,
  36037. 0xCC, 0x0C, 0x48, 0x25, 0x46, 0xB5, 0x39, 0xB4,
  36038. 0xFD, 0xF0, 0x4E, 0xED, 0x8E, 0x87, 0xF8, 0x5B,
  36039. 0x00, 0xBE, 0x43, 0xA6, 0x0B, 0x21, 0x7E, 0x96,
  36040. 0x88, 0x3B, 0x91, 0xD7, 0x88, 0x1A, 0xA0, 0xDD,
  36041. 0x3E, 0xBF, 0x5B, 0x0D, 0x08, 0xD0, 0x85, 0x4E,
  36042. 0xD4, 0x27, 0x8F, 0xC9, 0x02, 0xE0, 0x60, 0xEA,
  36043. 0x16, 0xFB, 0xC2, 0x54, 0xA5, 0x08, 0xC8, 0x6F,
  36044. 0x7A, 0xE7, 0x54, 0x93, 0xB8, 0xDD, 0xA0, 0x86,
  36045. 0xE9, 0xC1, 0xB2, 0x17, 0xF5, 0xC9, 0x11, 0x97,
  36046. 0x83, 0x66, 0x88, 0xCD, 0x2D, 0x0B, 0xB8, 0xE5,
  36047. 0x52, 0xD1, 0x13, 0x7A, 0xA7, 0xEB, 0xD5, 0xD5,
  36048. 0x60, 0x53, 0x8E, 0x9B, 0xB6, 0xB4, 0x1D, 0x06,
  36049. 0x90, 0xB0, 0x6C, 0x66, 0xD1, 0x57, 0x5B, 0x86,
  36050. 0x1C, 0x8A, 0x7D, 0x3A, 0x88, 0x4C, 0xC9, 0x88,
  36051. 0x1A, 0xC3, 0x00, 0x1F, 0x30, 0x0D, 0xF3, 0x47,
  36052. 0x62, 0x79, 0x85, 0x89, 0xF9, 0xEE, 0x5C, 0x92,
  36053. 0x43, 0x61, 0x53, 0xD8, 0xC7, 0x32, 0x55, 0x9B,
  36054. 0x33, 0x3D, 0x69, 0x8F, 0x3E, 0xC5, 0x82, 0x0E,
  36055. 0x8A, 0xA5, 0xF2, 0xE5, 0xA7, 0x69, 0xC2, 0xB4,
  36056. 0x7A, 0xFA, 0x27, 0x5F, 0xE4, 0x74, 0xAF, 0x81,
  36057. 0x37, 0xC7, 0x01, 0x9A, 0xF2, 0xE6, 0x0C, 0xA7,
  36058. 0x5E, 0xDB, 0xE4, 0x8F, 0x81, 0xA6, 0x51, 0xCE,
  36059. 0x6B, 0xAB, 0xD3, 0x37, 0x4C, 0x07, 0x72, 0xA8,
  36060. 0xAC, 0x36, 0x77, 0xB1, 0x0F, 0x54, 0x77, 0x17,
  36061. 0xC9, 0x67, 0x50, 0xDA, 0x44, 0x8B, 0xD9, 0xC7,
  36062. 0x93, 0x8C, 0x66, 0xCD, 0x6F, 0xB7, 0x5D, 0x73,
  36063. 0x2D, 0xAC, 0x83, 0x1A, 0xDC, 0xE9, 0x17, 0x6D,
  36064. 0x94, 0x85, 0x6E, 0x1B, 0xF6, 0x08, 0x38, 0xD0,
  36065. 0x9E, 0x63, 0x23, 0xA2, 0x7B, 0x16, 0x09, 0xF9,
  36066. 0xC1, 0x21, 0xF4, 0x98, 0xD2, 0xBB, 0x68, 0x58,
  36067. 0x18, 0xA0, 0x0D, 0xE7, 0xBA, 0x6B, 0x28, 0x47,
  36068. 0xC5, 0x16, 0x14, 0x9F, 0x35, 0x6E, 0xCE, 0xF0,
  36069. 0x4F, 0x34, 0xEA, 0x48, 0x35, 0x46, 0xFE, 0xEB,
  36070. 0x12, 0xEA, 0x40, 0x77, 0x62, 0x04, 0x30, 0xC3,
  36071. 0x9D, 0xBF, 0x47, 0xC0, 0x5E, 0xED, 0x5E, 0xD5,
  36072. 0x87, 0xFF, 0xF5, 0x92, 0x21, 0x7C, 0xA9, 0x5A,
  36073. 0x2C, 0x3D, 0x1E, 0x6F, 0x6F, 0xF9, 0xFF, 0x20,
  36074. 0x9F, 0x8B, 0x30, 0xA9, 0x9D, 0x56, 0xA3, 0x97,
  36075. 0x7A, 0x33, 0x17, 0x49, 0x0B, 0x2B, 0x00, 0x1F,
  36076. 0x43, 0xCD, 0x8D, 0xDD, 0x1D, 0x8F, 0xC1, 0x6A,
  36077. 0x3F, 0xA9, 0xB4, 0x31, 0x54, 0x62, 0x84, 0x5B,
  36078. 0x99, 0x5D, 0x2A, 0xB7, 0x6E, 0xA5, 0x39, 0xC7,
  36079. 0xF0, 0x4C, 0x31, 0x6C, 0x71, 0xD6, 0x00, 0xE1,
  36080. 0xAC, 0x4F, 0xD5, 0xC8, 0xC6, 0x34, 0x3B, 0xC8,
  36081. 0x05, 0x5F, 0x17, 0x00, 0xB4, 0x0E, 0xA2, 0xF1,
  36082. 0xAB, 0xE9, 0x4B, 0xE0, 0x06, 0x01, 0x3A, 0xA2,
  36083. 0x61, 0xF0, 0x72, 0x0A, 0xB7, 0x99, 0xD0, 0xFC,
  36084. 0x6D, 0xB5, 0xE9, 0xA4, 0xC3, 0xC5, 0xA7, 0xF8,
  36085. 0x2D, 0x70, 0xD2, 0x8E, 0x41, 0x0D, 0xD1, 0x64,
  36086. 0xE3, 0xE4, 0x61, 0xA4, 0x6E, 0x81, 0xFB, 0xDC,
  36087. 0xB8, 0x10, 0x84, 0x8B, 0xCE, 0xE0, 0x6F, 0x88,
  36088. 0x33, 0x25, 0x64, 0x6E, 0x1E, 0x2A, 0x69, 0x3F,
  36089. 0xA5, 0xDA, 0x7C, 0x25, 0xEB, 0x21, 0xC4, 0xEA,
  36090. 0xB8, 0x7D, 0xC7, 0x87, 0xA2, 0x67, 0x7C, 0xEB,
  36091. 0x6A, 0x26, 0xE1, 0x06, 0xFE, 0x78, 0xE1, 0x18,
  36092. 0xFF, 0x54, 0x71, 0x3E, 0x00, 0x59, 0x7B, 0xFA,
  36093. 0x52, 0x8C, 0x2A, 0xED, 0x06, 0x9A, 0x12, 0x6D,
  36094. 0xE3, 0x74, 0x6F, 0x06, 0x65, 0xE1, 0x75, 0x80,
  36095. 0x63, 0x0F, 0x70, 0x2F, 0xAB, 0xC0, 0xF1, 0xCD,
  36096. 0x7F, 0x57, 0xAA, 0x71, 0xF6, 0x38, 0xD8, 0xAF,
  36097. 0x37, 0xD3, 0xD9, 0xE0, 0xA7, 0xE9, 0x05, 0x5D,
  36098. 0xA3, 0xDF, 0x86, 0x48, 0x3F, 0x25, 0xDE, 0xBA,
  36099. 0x18, 0xCE, 0xF6, 0x99, 0xEB, 0x87, 0x70, 0xC7,
  36100. 0x85, 0x84, 0x79, 0x8A, 0xD8, 0x02, 0x8B, 0xAD,
  36101. 0xC5, 0x9D, 0x2A, 0xF9, 0xAE, 0xAE, 0x37, 0xEC,
  36102. 0x93, 0x91, 0x16, 0x10, 0x5F, 0x9F, 0x64, 0xEF,
  36103. 0x82, 0x78, 0xC6, 0x4D, 0xED, 0x3F, 0xD4, 0x33,
  36104. 0xA7, 0xB8, 0x82, 0x09, 0x16, 0xBE, 0xDC, 0x6B,
  36105. 0x7A, 0x75, 0x69, 0x8A, 0xDE, 0xD3, 0xFD, 0xE8,
  36106. 0x86, 0x75, 0x42, 0x83, 0x03, 0x57, 0x30, 0x70,
  36107. 0xA5, 0xA3, 0x85, 0x1F, 0x9F, 0x21, 0xEA, 0xC7,
  36108. 0x80, 0xFA, 0x8A, 0xA4, 0x02, 0x3E, 0x39, 0x11,
  36109. 0x48, 0x7D, 0x85, 0x2A, 0x53, 0x77, 0x43, 0x5A,
  36110. 0x5F, 0xFF, 0x9C, 0x60, 0x4B, 0x5D, 0x95, 0xB0,
  36111. 0x96, 0x8A, 0xE0, 0xEC, 0xF4, 0x43, 0x1B, 0x10,
  36112. 0x3F, 0xA6, 0xBA, 0x71, 0xC4, 0xDC, 0x81, 0x73,
  36113. 0xA2, 0xDE, 0x1F, 0x79, 0xDD, 0xB6, 0x0D, 0x2D,
  36114. 0x0C, 0x8E, 0x56, 0x55, 0xD0, 0x94, 0x44, 0x29,
  36115. 0x16, 0x92, 0x99, 0x2D, 0x99, 0xFC, 0x48, 0xF2,
  36116. 0x16, 0x0E, 0xC0, 0xAC, 0xE4, 0xC4, 0x92, 0x07,
  36117. 0xBB, 0xB7, 0x6D, 0x7F, 0x2A, 0x85, 0xE1, 0x81,
  36118. 0x02, 0xB9, 0x5A, 0x51, 0x45, 0x88, 0xF5, 0x9F,
  36119. 0x16, 0x2D, 0x33, 0xCE, 0xD6, 0x18, 0x07, 0x03,
  36120. 0xED, 0xC3, 0x6C, 0x8B, 0x33, 0x94, 0x88, 0x81,
  36121. 0x0D, 0x2E, 0xAE, 0x96, 0x25, 0xCE, 0xE3, 0x83,
  36122. 0x27, 0x1C, 0x71, 0x72, 0xEE, 0xD6, 0xB5, 0x48,
  36123. 0x69, 0x60, 0xE8, 0x99, 0x18, 0x74, 0xB0, 0x13,
  36124. 0x53, 0x59, 0x3D, 0x70, 0x70, 0xBD, 0xEB, 0x7A,
  36125. 0x9F, 0x92, 0x29, 0xAB, 0x77, 0x0E, 0xEB, 0x46,
  36126. 0x37, 0x8D, 0x57, 0xD9, 0x56, 0xDF, 0x7A, 0x86,
  36127. 0x40, 0x04, 0x02, 0x98, 0xF7, 0x00, 0xF4, 0x41,
  36128. 0x5B, 0xDD, 0x3A, 0x96, 0x15, 0xA4, 0x65, 0xDB,
  36129. 0x01, 0x28, 0x22, 0x12, 0xCF, 0x1A, 0xEC, 0x4B,
  36130. 0x0B, 0x8C, 0xB3, 0xB1, 0x7E, 0x5E, 0xFA, 0x28,
  36131. 0x6C, 0x6C, 0x04, 0x5B, 0x43, 0x9C, 0x74, 0x9F,
  36132. 0xE1, 0xD4, 0x50, 0x75, 0xD8, 0xE7, 0xA0, 0x0F,
  36133. 0xBE, 0x84, 0x48, 0xFC, 0xAC, 0xAA, 0x15, 0x3D,
  36134. 0x69, 0x70, 0x9D, 0x9F, 0xF2, 0xB9, 0x7C, 0xDB,
  36135. 0x26, 0xC0, 0xC3, 0x79, 0x28, 0x7C, 0xE6, 0x48,
  36136. 0x61, 0xAD, 0xD7, 0x89, 0xD0, 0xC8, 0x93, 0x9A,
  36137. 0x14, 0x21, 0xB0, 0x85, 0xD6, 0x23, 0x4C, 0xE1,
  36138. 0xA7, 0x49, 0xDE, 0x3D, 0xCB, 0xE8, 0xE0, 0x61,
  36139. 0x5C, 0xB3, 0xBC, 0xDC, 0x6A, 0x81, 0xA5, 0xC4,
  36140. 0x9D, 0x92, 0x85, 0x74, 0x5F, 0x1C, 0xA8, 0xA0,
  36141. 0x64, 0x1E, 0x32, 0x68, 0x83, 0x41, 0x93, 0x34,
  36142. 0x82, 0x18, 0x3E, 0x24, 0x5C, 0x1F, 0x9C, 0xD2,
  36143. 0x80, 0x28, 0xC3, 0x8A, 0x23, 0x18, 0x1A, 0x44,
  36144. 0x5A, 0xA6, 0xEA, 0xCC, 0xE2, 0x06, 0x06, 0xE6,
  36145. 0xF7, 0xF1, 0xDF, 0x70, 0x68, 0x83, 0xCD, 0xA5,
  36146. 0x2F, 0x3F, 0x2B, 0x68, 0xDE, 0x26, 0xDD, 0x37,
  36147. 0x71, 0xE9, 0x50, 0x03, 0x2C, 0xC7, 0x20, 0x0C,
  36148. 0x20, 0x23, 0xC8, 0x24, 0x96, 0x50, 0x82, 0x82,
  36149. 0xCD, 0x3B, 0xC4, 0x7F, 0xEC, 0xE5, 0xD9, 0x7C,
  36150. 0xA1, 0xCE, 0x35, 0x74, 0x4D, 0x03, 0xD7, 0xA4,
  36151. 0x28, 0xB7, 0xAF, 0x12, 0xB0, 0xCB, 0x8E, 0x65,
  36152. 0x7C, 0x01, 0x30, 0xF8, 0xA3, 0xA2, 0x54, 0x97,
  36153. 0x6E, 0xC8, 0xF7, 0xDC, 0xCF, 0x3A, 0xBF, 0x31,
  36154. 0xF4, 0xB0, 0xB3, 0xF7, 0x12, 0x6F, 0xFC, 0x48,
  36155. 0x77, 0xF3, 0xD1, 0xA0, 0x66, 0xD2, 0x6A, 0x23,
  36156. 0x2F, 0xA9, 0x99, 0x21, 0x61, 0x22, 0x54, 0x11,
  36157. 0xED, 0x7D, 0xDB, 0x93, 0xC3, 0x5C, 0x6A, 0x37,
  36158. 0x7F, 0x30, 0xCF, 0x22, 0xAA, 0x39, 0x2D, 0x5C,
  36159. 0x4F, 0xEE, 0x4F, 0x73, 0xC9, 0xEF, 0x6E, 0xD3,
  36160. 0xA0, 0x27, 0x97, 0x14, 0x52, 0x3B, 0x19, 0x18,
  36161. 0x65, 0x1E, 0x9B, 0x0F, 0xFA, 0x55, 0x0F, 0x16,
  36162. 0x10, 0x53, 0xEE, 0x78, 0x01, 0x39, 0x7B, 0x4C,
  36163. 0x18, 0x49, 0x98, 0x7C, 0x17, 0x9E, 0x76, 0x3E,
  36164. 0xCC, 0x60, 0xA4, 0xE4, 0xC5, 0x36, 0xB7, 0xE2,
  36165. 0x66, 0x3E, 0x4C, 0x72, 0x67, 0x14, 0xB0, 0x2E,
  36166. 0xC3, 0x16, 0x9E, 0x84, 0x07, 0xBA, 0x59, 0x2B,
  36167. 0x0E, 0xB8, 0x46, 0xF3, 0x69, 0x2D, 0xD4, 0x46,
  36168. 0x51, 0xEE, 0x08, 0x47, 0x21, 0xCA, 0xC0, 0xFE,
  36169. 0x1C, 0xCC, 0x30, 0x27, 0x07, 0xEF, 0xE2, 0x46,
  36170. 0x64, 0xE0, 0x5B, 0xDC, 0x69, 0xC8, 0x39, 0x04,
  36171. 0xAC, 0xB8, 0xCF, 0x97, 0x12, 0x1C, 0x7E, 0x5C,
  36172. 0x6D, 0xB2, 0x7E, 0xA2, 0x8E, 0x77, 0xBC, 0xDA,
  36173. 0x55, 0xD2, 0xBC, 0xC1, 0xC5, 0xFC, 0xC5, 0x52,
  36174. 0xAB, 0x83, 0xBC, 0xE4, 0x23, 0x8C, 0xA1, 0x80,
  36175. 0x62, 0xC2, 0xD2, 0x3A, 0x8B, 0x80, 0x0C, 0x82,
  36176. 0x09, 0xC3, 0xA4, 0xCD, 0xDA, 0xF1, 0x16, 0x16,
  36177. 0x57, 0x8A, 0x84, 0x55, 0x66, 0xFC, 0x28, 0x9A,
  36178. 0x8E, 0x3C, 0x88, 0xF5, 0x54, 0xC4, 0x92, 0x60,
  36179. 0x71, 0xDA, 0x89, 0x32, 0x6B, 0xEB, 0x25, 0x9A,
  36180. 0x0E, 0x1F, 0x6D, 0x84, 0x4E, 0xBF, 0x7B, 0x28,
  36181. 0x1F, 0x9F, 0xC3, 0x74, 0x3A, 0x65, 0x49, 0x9E,
  36182. 0x73, 0x94, 0x63, 0x48, 0x18, 0xE1, 0x33, 0xFA,
  36183. 0xC6, 0x64, 0xFA, 0x0C, 0x88, 0xF1, 0x01, 0xCE,
  36184. 0xC3, 0xFE, 0xD8, 0x79, 0x29, 0x50, 0xBF, 0x6E,
  36185. 0x49, 0x74, 0x84, 0x9E, 0x1E, 0xBD, 0x27, 0x69,
  36186. 0x1B, 0xF5, 0x51, 0x9B, 0x70, 0x2E, 0x1A, 0xA4,
  36187. 0xB3, 0xDB, 0xAD, 0xAB, 0x5D, 0xFA, 0x34, 0xFB,
  36188. 0x0E, 0xD9, 0xD4, 0xA9, 0xDF, 0x4B, 0x6B, 0x63,
  36189. 0xCA, 0x71, 0x65, 0xE2, 0xA9, 0x08, 0x27, 0x40,
  36190. 0x8C, 0x48, 0x2D, 0x9D, 0xBC, 0x97, 0x24, 0x68,
  36191. 0x58, 0x4F, 0x42, 0x37, 0x60, 0x04, 0xE7, 0x8B,
  36192. 0xE0, 0x67, 0x00, 0x9E, 0x43, 0x30, 0x4B, 0xED,
  36193. 0xC1, 0x07, 0xA4, 0xE2, 0xA8, 0x9C, 0xAF, 0x18,
  36194. 0x5C, 0x9B, 0xB7, 0xE9, 0xFD, 0x2C, 0xB9, 0x2A,
  36195. 0xEF, 0x36, 0x3B, 0xD7, 0x96, 0xF3, 0x60, 0x4E,
  36196. 0xDC, 0x08, 0xA7, 0xC5, 0x45, 0xB8, 0x37, 0x02,
  36197. 0xD3, 0xCF, 0x80, 0x88, 0x52, 0x10, 0x3E, 0x01,
  36198. 0x3B, 0xFE, 0xA1, 0x61, 0xAF, 0x25, 0x0B, 0xCC,
  36199. 0x72, 0x77, 0x1D, 0x0C, 0x48, 0x4D, 0xD5, 0x55,
  36200. 0x41, 0x72, 0x3A, 0x21, 0x0D, 0x68, 0x3B, 0x99,
  36201. 0x8C, 0xDB, 0xAF, 0x3D, 0x9A, 0x5E, 0x71, 0x78,
  36202. 0x6F, 0x1C, 0xF4, 0x7B, 0x86, 0x22, 0x51, 0xB5,
  36203. 0x16, 0x33, 0x60, 0x87, 0x9A, 0xC0, 0x20, 0x2D,
  36204. 0x33, 0x49, 0x51, 0x54, 0x5C, 0x5F, 0x71, 0x76,
  36205. 0x7C, 0x8F, 0x96, 0xA9, 0xD6, 0xE4, 0xF2, 0x1F,
  36206. 0x28, 0x43, 0x4D, 0x7E, 0x96, 0xBB, 0xC5, 0xE3,
  36207. 0xEF, 0xF3, 0xFD, 0x02, 0x0C, 0x17, 0x23, 0x3E,
  36208. 0x7F, 0x99, 0xB0, 0xE3, 0xE8, 0xF5, 0x00, 0x00,
  36209. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  36210. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  36211. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  36212. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  36213. 0x06, 0x17, 0x23, 0x2E
  36214. };
  36215. #endif
  36216. #ifndef WOLFSSL_NO_ML_DSA_65
  36217. static const byte sk_65[] = {
  36218. 0xF2, 0x6B, 0xFE, 0x12, 0x68, 0x86, 0xF4, 0x82,
  36219. 0x22, 0x94, 0x4D, 0x02, 0x18, 0xFA, 0xC1, 0x7C,
  36220. 0xD8, 0xA9, 0xCC, 0x6D, 0x67, 0xA0, 0x23, 0xFD,
  36221. 0xC0, 0x7A, 0xFF, 0xC2, 0xD0, 0x25, 0xF7, 0x70,
  36222. 0x63, 0x85, 0x0D, 0x88, 0x0E, 0x98, 0xFE, 0xE5,
  36223. 0x02, 0xE0, 0x17, 0x32, 0x70, 0x00, 0xCC, 0xAF,
  36224. 0x61, 0x45, 0x73, 0xB3, 0x5A, 0xDE, 0xFE, 0xBC,
  36225. 0xAC, 0xEE, 0xA4, 0xB2, 0xC4, 0xD0, 0x45, 0xE5,
  36226. 0xBB, 0xFD, 0x3E, 0x5A, 0x72, 0xE3, 0x71, 0xAD,
  36227. 0x83, 0xB9, 0x94, 0x98, 0x77, 0xD8, 0xE6, 0x56,
  36228. 0xD4, 0x6B, 0x47, 0x75, 0x0F, 0x73, 0x0F, 0x96,
  36229. 0xDB, 0x43, 0x0B, 0x18, 0x60, 0x88, 0x67, 0x5D,
  36230. 0x9A, 0x9B, 0xD7, 0x8E, 0x47, 0xB8, 0x9D, 0x04,
  36231. 0xA8, 0x51, 0x7E, 0xD2, 0x22, 0x06, 0x95, 0x33,
  36232. 0x9F, 0x99, 0xA9, 0x7F, 0x35, 0x3C, 0xE4, 0x20,
  36233. 0x47, 0x77, 0x20, 0x9F, 0x5F, 0x3C, 0x9E, 0x9A,
  36234. 0x36, 0x14, 0x54, 0x01, 0x57, 0x48, 0x60, 0x50,
  36235. 0x75, 0x28, 0x64, 0x61, 0x72, 0x60, 0x54, 0x20,
  36236. 0x75, 0x48, 0x60, 0x32, 0x73, 0x85, 0x34, 0x24,
  36237. 0x68, 0x63, 0x71, 0x73, 0x81, 0x26, 0x71, 0x68,
  36238. 0x32, 0x61, 0x24, 0x71, 0x14, 0x18, 0x26, 0x15,
  36239. 0x05, 0x77, 0x36, 0x27, 0x50, 0x35, 0x21, 0x82,
  36240. 0x50, 0x15, 0x31, 0x47, 0x48, 0x24, 0x43, 0x76,
  36241. 0x18, 0x85, 0x66, 0x18, 0x05, 0x64, 0x27, 0x01,
  36242. 0x06, 0x06, 0x01, 0x45, 0x42, 0x60, 0x80, 0x68,
  36243. 0x25, 0x08, 0x08, 0x36, 0x13, 0x05, 0x04, 0x32,
  36244. 0x34, 0x87, 0x00, 0x70, 0x71, 0x70, 0x02, 0x51,
  36245. 0x37, 0x15, 0x08, 0x28, 0x25, 0x72, 0x61, 0x67,
  36246. 0x08, 0x52, 0x63, 0x44, 0x07, 0x88, 0x60, 0x42,
  36247. 0x03, 0x17, 0x24, 0x64, 0x80, 0x08, 0x70, 0x23,
  36248. 0x56, 0x41, 0x46, 0x17, 0x46, 0x01, 0x57, 0x74,
  36249. 0x02, 0x76, 0x31, 0x64, 0x73, 0x83, 0x50, 0x62,
  36250. 0x72, 0x61, 0x62, 0x75, 0x45, 0x73, 0x46, 0x33,
  36251. 0x65, 0x14, 0x36, 0x46, 0x12, 0x26, 0x04, 0x34,
  36252. 0x02, 0x81, 0x20, 0x34, 0x41, 0x88, 0x26, 0x77,
  36253. 0x33, 0x40, 0x18, 0x58, 0x03, 0x41, 0x16, 0x58,
  36254. 0x88, 0x04, 0x88, 0x32, 0x71, 0x05, 0x85, 0x83,
  36255. 0x42, 0x55, 0x34, 0x20, 0x18, 0x46, 0x12, 0x54,
  36256. 0x28, 0x03, 0x67, 0x10, 0x84, 0x31, 0x76, 0x00,
  36257. 0x40, 0x85, 0x46, 0x71, 0x71, 0x56, 0x00, 0x50,
  36258. 0x15, 0x33, 0x43, 0x13, 0x37, 0x57, 0x13, 0x86,
  36259. 0x43, 0x77, 0x85, 0x57, 0x54, 0x81, 0x75, 0x60,
  36260. 0x37, 0x31, 0x28, 0x52, 0x20, 0x78, 0x65, 0x53,
  36261. 0x76, 0x10, 0x84, 0x87, 0x57, 0x13, 0x66, 0x03,
  36262. 0x56, 0x81, 0x36, 0x66, 0x68, 0x41, 0x55, 0x64,
  36263. 0x63, 0x70, 0x26, 0x21, 0x02, 0x30, 0x28, 0x35,
  36264. 0x02, 0x45, 0x88, 0x80, 0x02, 0x06, 0x44, 0x58,
  36265. 0x24, 0x13, 0x88, 0x83, 0x22, 0x34, 0x22, 0x50,
  36266. 0x47, 0x11, 0x01, 0x86, 0x45, 0x60, 0x67, 0x36,
  36267. 0x82, 0x22, 0x18, 0x74, 0x11, 0x60, 0x58, 0x60,
  36268. 0x87, 0x26, 0x31, 0x85, 0x12, 0x70, 0x84, 0x83,
  36269. 0x88, 0x68, 0x88, 0x51, 0x00, 0x55, 0x02, 0x57,
  36270. 0x77, 0x42, 0x13, 0x23, 0x14, 0x04, 0x76, 0x80,
  36271. 0x72, 0x25, 0x51, 0x56, 0x10, 0x63, 0x12, 0x21,
  36272. 0x03, 0x86, 0x27, 0x30, 0x28, 0x12, 0x01, 0x37,
  36273. 0x48, 0x32, 0x53, 0x86, 0x15, 0x46, 0x50, 0x05,
  36274. 0x34, 0x87, 0x61, 0x04, 0x88, 0x18, 0x35, 0x85,
  36275. 0x44, 0x46, 0x24, 0x67, 0x43, 0x83, 0x02, 0x26,
  36276. 0x56, 0x41, 0x41, 0x77, 0x86, 0x56, 0x41, 0x75,
  36277. 0x25, 0x61, 0x36, 0x05, 0x47, 0x65, 0x00, 0x14,
  36278. 0x32, 0x38, 0x16, 0x81, 0x06, 0x30, 0x61, 0x25,
  36279. 0x16, 0x30, 0x50, 0x44, 0x13, 0x08, 0x75, 0x00,
  36280. 0x50, 0x20, 0x68, 0x21, 0x55, 0x74, 0x61, 0x18,
  36281. 0x62, 0x05, 0x15, 0x51, 0x08, 0x24, 0x01, 0x13,
  36282. 0x81, 0x33, 0x64, 0x83, 0x23, 0x00, 0x55, 0x73,
  36283. 0x62, 0x40, 0x61, 0x75, 0x15, 0x78, 0x21, 0x14,
  36284. 0x13, 0x64, 0x21, 0x47, 0x07, 0x76, 0x80, 0x76,
  36285. 0x76, 0x17, 0x75, 0x50, 0x61, 0x14, 0x40, 0x82,
  36286. 0x87, 0x83, 0x50, 0x87, 0x30, 0x86, 0x35, 0x30,
  36287. 0x28, 0x20, 0x10, 0x01, 0x48, 0x18, 0x34, 0x65,
  36288. 0x23, 0x10, 0x25, 0x42, 0x40, 0x22, 0x54, 0x34,
  36289. 0x35, 0x33, 0x71, 0x70, 0x20, 0x61, 0x55, 0x74,
  36290. 0x33, 0x01, 0x02, 0x60, 0x58, 0x24, 0x80, 0x12,
  36291. 0x46, 0x41, 0x38, 0x10, 0x76, 0x67, 0x34, 0x63,
  36292. 0x48, 0x85, 0x06, 0x48, 0x04, 0x23, 0x22, 0x66,
  36293. 0x57, 0x71, 0x68, 0x18, 0x04, 0x32, 0x01, 0x31,
  36294. 0x01, 0x55, 0x22, 0x27, 0x55, 0x72, 0x10, 0x00,
  36295. 0x43, 0x88, 0x76, 0x62, 0x84, 0x77, 0x07, 0x77,
  36296. 0x14, 0x07, 0x20, 0x53, 0x74, 0x17, 0x51, 0x17,
  36297. 0x66, 0x84, 0x47, 0x83, 0x61, 0x03, 0x52, 0x10,
  36298. 0x05, 0x40, 0x46, 0x55, 0x61, 0x47, 0x26, 0x70,
  36299. 0x40, 0x22, 0x10, 0x34, 0x41, 0x01, 0x03, 0x48,
  36300. 0x33, 0x05, 0x72, 0x32, 0x75, 0x82, 0x45, 0x85,
  36301. 0x20, 0x70, 0x80, 0x82, 0x20, 0x23, 0x62, 0x81,
  36302. 0x15, 0x47, 0x80, 0x23, 0x67, 0x23, 0x73, 0x34,
  36303. 0x44, 0x33, 0x85, 0x10, 0x05, 0x50, 0x30, 0x03,
  36304. 0x48, 0x13, 0x01, 0x36, 0x45, 0x11, 0x06, 0x33,
  36305. 0x82, 0x22, 0x78, 0x75, 0x42, 0x02, 0x40, 0x45,
  36306. 0x04, 0x47, 0x43, 0x05, 0x30, 0x44, 0x42, 0x02,
  36307. 0x28, 0x26, 0x64, 0x24, 0x74, 0x75, 0x86, 0x11,
  36308. 0x85, 0x43, 0x25, 0x46, 0x10, 0x62, 0x82, 0x71,
  36309. 0x08, 0x27, 0x45, 0x13, 0x73, 0x18, 0x84, 0x73,
  36310. 0x51, 0x51, 0x67, 0x14, 0x70, 0x11, 0x07, 0x08,
  36311. 0x62, 0x16, 0x25, 0x27, 0x36, 0x68, 0x44, 0x01,
  36312. 0x18, 0x63, 0x74, 0x50, 0x31, 0x13, 0x43, 0x65,
  36313. 0x80, 0x11, 0x16, 0x52, 0x86, 0x42, 0x51, 0x81,
  36314. 0x51, 0x17, 0x05, 0x68, 0x05, 0x73, 0x60, 0x37,
  36315. 0x63, 0x85, 0x86, 0x11, 0x23, 0x23, 0x38, 0x13,
  36316. 0x87, 0x48, 0x82, 0x74, 0x71, 0x81, 0x87, 0x65,
  36317. 0x58, 0x26, 0x60, 0x34, 0x76, 0x16, 0x15, 0x24,
  36318. 0x06, 0x78, 0x16, 0x40, 0x03, 0x45, 0x72, 0x31,
  36319. 0x63, 0x73, 0x31, 0x85, 0x02, 0x66, 0x44, 0x36,
  36320. 0x24, 0x82, 0x56, 0x38, 0x86, 0x10, 0x40, 0x54,
  36321. 0x72, 0x70, 0x24, 0x22, 0x72, 0x78, 0x47, 0x07,
  36322. 0x86, 0x30, 0x48, 0x72, 0x84, 0x57, 0x06, 0x34,
  36323. 0x78, 0x37, 0x63, 0x25, 0x56, 0x64, 0x81, 0x30,
  36324. 0x62, 0x77, 0x22, 0x84, 0x20, 0x10, 0x74, 0x25,
  36325. 0x04, 0x21, 0x76, 0x47, 0x72, 0x35, 0x05, 0x06,
  36326. 0x22, 0x50, 0x34, 0x11, 0x26, 0x67, 0x03, 0x05,
  36327. 0x42, 0x04, 0x16, 0x01, 0x27, 0x17, 0x86, 0x67,
  36328. 0x70, 0x51, 0x53, 0x13, 0x12, 0x62, 0x03, 0x25,
  36329. 0x05, 0x38, 0x37, 0x44, 0x02, 0x66, 0x84, 0x74,
  36330. 0x14, 0x40, 0x35, 0x20, 0x40, 0x30, 0x44, 0x64,
  36331. 0x27, 0x50, 0x77, 0x47, 0x06, 0x15, 0x84, 0x48,
  36332. 0x13, 0x14, 0x32, 0x48, 0x11, 0x74, 0x80, 0x68,
  36333. 0x85, 0x81, 0x17, 0x67, 0x38, 0x22, 0x76, 0x16,
  36334. 0x18, 0x44, 0x55, 0x47, 0x85, 0x36, 0x44, 0x11,
  36335. 0x52, 0x01, 0x81, 0x50, 0x41, 0x00, 0x00, 0x25,
  36336. 0x83, 0x41, 0x62, 0x22, 0x12, 0x54, 0x88, 0x77,
  36337. 0x70, 0x48, 0x84, 0x25, 0x77, 0x75, 0x40, 0x16,
  36338. 0x46, 0x24, 0x88, 0x81, 0x65, 0x70, 0x02, 0x66,
  36339. 0x28, 0x64, 0x12, 0x40, 0x30, 0x60, 0x53, 0x06,
  36340. 0x44, 0x02, 0x48, 0x78, 0x75, 0x68, 0x21, 0x23,
  36341. 0x30, 0x05, 0x81, 0x17, 0x72, 0x66, 0x88, 0x71,
  36342. 0x50, 0x25, 0x03, 0x51, 0x42, 0x27, 0x20, 0x81,
  36343. 0x03, 0x52, 0x73, 0x53, 0x63, 0x57, 0x13, 0x60,
  36344. 0x41, 0x20, 0x47, 0x12, 0x55, 0x57, 0x58, 0x16,
  36345. 0x38, 0x63, 0x21, 0x34, 0x51, 0x76, 0x33, 0x26,
  36346. 0x70, 0x41, 0x18, 0x11, 0x07, 0x37, 0x16, 0x12,
  36347. 0x01, 0x14, 0x28, 0x56, 0x78, 0x10, 0x86, 0x24,
  36348. 0x24, 0x32, 0x01, 0x13, 0x57, 0x53, 0x46, 0x46,
  36349. 0x24, 0x05, 0x20, 0x16, 0x56, 0x83, 0x30, 0x30,
  36350. 0x61, 0x20, 0x75, 0x07, 0x05, 0x74, 0x14, 0x17,
  36351. 0x43, 0x72, 0x23, 0x04, 0x18, 0x61, 0x50, 0x13,
  36352. 0x67, 0x31, 0x75, 0x36, 0x71, 0x02, 0x38, 0x74,
  36353. 0x21, 0x80, 0x20, 0x48, 0x66, 0x23, 0x52, 0x54,
  36354. 0x77, 0x27, 0x45, 0x73, 0x23, 0x88, 0x60, 0x50,
  36355. 0x88, 0x82, 0x70, 0x23, 0x72, 0x08, 0x44, 0x66,
  36356. 0x44, 0x36, 0x12, 0x57, 0x66, 0x14, 0x25, 0x12,
  36357. 0x17, 0x34, 0x64, 0x82, 0x01, 0x54, 0x61, 0x57,
  36358. 0x50, 0x31, 0x65, 0x64, 0x75, 0x44, 0x76, 0x48,
  36359. 0x16, 0x44, 0x46, 0x55, 0x80, 0x64, 0x26, 0x53,
  36360. 0x27, 0x22, 0x10, 0x87, 0x84, 0x03, 0x15, 0x35,
  36361. 0x15, 0x20, 0x86, 0x14, 0x04, 0x03, 0x26, 0x43,
  36362. 0x31, 0x43, 0x31, 0x45, 0x46, 0x34, 0x36, 0x87,
  36363. 0x44, 0x41, 0x21, 0x77, 0x61, 0x20, 0x85, 0x06,
  36364. 0x28, 0x51, 0x15, 0x62, 0x77, 0x20, 0x38, 0x58,
  36365. 0x78, 0x27, 0x12, 0x22, 0x46, 0x71, 0x51, 0x38,
  36366. 0x11, 0x15, 0x40, 0x03, 0x78, 0x36, 0x15, 0x57,
  36367. 0x34, 0x28, 0x53, 0x21, 0x37, 0x35, 0x04, 0x76,
  36368. 0x00, 0x56, 0x72, 0x48, 0x46, 0x01, 0x56, 0x67,
  36369. 0x62, 0x36, 0x14, 0x51, 0x23, 0x54, 0x32, 0x35,
  36370. 0x82, 0x83, 0x21, 0x60, 0x38, 0x62, 0x21, 0x03,
  36371. 0x62, 0x76, 0x40, 0x34, 0x66, 0x88, 0x50, 0x73,
  36372. 0x00, 0x53, 0x87, 0x31, 0x37, 0x50, 0x11, 0x32,
  36373. 0x86, 0x52, 0x18, 0x64, 0x16, 0x63, 0x48, 0x71,
  36374. 0x70, 0x47, 0x24, 0x85, 0x31, 0x86, 0x60, 0x86,
  36375. 0x33, 0x52, 0x85, 0x82, 0x68, 0x17, 0x70, 0x88,
  36376. 0x84, 0x56, 0x52, 0x77, 0x04, 0x48, 0x22, 0x22,
  36377. 0x54, 0x57, 0x20, 0x31, 0x76, 0x47, 0x26, 0x25,
  36378. 0x04, 0x35, 0x38, 0x44, 0x55, 0x21, 0x14, 0x02,
  36379. 0x13, 0x64, 0x74, 0x87, 0x68, 0x68, 0x73, 0x05,
  36380. 0x22, 0x45, 0x54, 0x45, 0x83, 0x46, 0x64, 0x54,
  36381. 0x80, 0x07, 0x32, 0x87, 0x52, 0x43, 0x54, 0x54,
  36382. 0x14, 0x73, 0x24, 0x87, 0x36, 0x41, 0x74, 0x84,
  36383. 0x06, 0x35, 0x13, 0x40, 0x61, 0x54, 0x21, 0x31,
  36384. 0x48, 0x63, 0x05, 0x74, 0x24, 0x84, 0x74, 0x76,
  36385. 0x11, 0x10, 0x16, 0x63, 0x77, 0x12, 0x26, 0x61,
  36386. 0x31, 0x28, 0x70, 0x34, 0x25, 0x01, 0x30, 0x76,
  36387. 0x76, 0x06, 0x21, 0x58, 0x42, 0x87, 0x31, 0x72,
  36388. 0x76, 0x03, 0x76, 0x26, 0x78, 0x05, 0x88, 0x25,
  36389. 0x25, 0x86, 0x17, 0x02, 0x85, 0x88, 0x76, 0x20,
  36390. 0x36, 0x57, 0x30, 0x81, 0x83, 0x61, 0x05, 0x80,
  36391. 0x21, 0x45, 0x74, 0x01, 0x12, 0x74, 0x51, 0x28,
  36392. 0x77, 0x26, 0x30, 0x14, 0x54, 0x84, 0x13, 0x78,
  36393. 0x06, 0x00, 0x12, 0x64, 0x00, 0x37, 0x44, 0x68,
  36394. 0x40, 0x57, 0x05, 0x27, 0x07, 0x41, 0x56, 0x22,
  36395. 0x31, 0x40, 0x23, 0x26, 0x55, 0x42, 0x55, 0x16,
  36396. 0x02, 0x65, 0x32, 0x16, 0x33, 0x44, 0x46, 0x48,
  36397. 0x04, 0x52, 0x06, 0x53, 0x44, 0x40, 0x11, 0x28,
  36398. 0x46, 0x67, 0x56, 0x81, 0x72, 0x75, 0x51, 0x38,
  36399. 0x21, 0x86, 0x46, 0x03, 0x22, 0x87, 0x21, 0x70,
  36400. 0x68, 0x50, 0x75, 0x13, 0x11, 0x44, 0x35, 0x12,
  36401. 0x60, 0x02, 0x13, 0x47, 0x18, 0x38, 0x78, 0x86,
  36402. 0x38, 0x58, 0x45, 0x57, 0x23, 0x03, 0x88, 0x66,
  36403. 0x56, 0x82, 0x18, 0x31, 0x20, 0x08, 0x61, 0x47,
  36404. 0x78, 0x08, 0x68, 0x37, 0x21, 0x04, 0x65, 0x47,
  36405. 0x58, 0x70, 0x34, 0x58, 0x73, 0x24, 0x22, 0x30,
  36406. 0x66, 0x05, 0x01, 0x28, 0x87, 0x85, 0x77, 0x74,
  36407. 0x23, 0x86, 0x65, 0x84, 0x85, 0x57, 0x85, 0x63,
  36408. 0x06, 0x55, 0x61, 0x75, 0x46, 0x22, 0x87, 0x00,
  36409. 0x18, 0x53, 0x08, 0x03, 0x07, 0x50, 0x42, 0x70,
  36410. 0xFC, 0xB8, 0x7B, 0x22, 0x3D, 0x24, 0xAE, 0x5D,
  36411. 0xB1, 0x89, 0x04, 0x21, 0xC3, 0xFF, 0x1D, 0x59,
  36412. 0xB8, 0x4B, 0x19, 0xE2, 0x4D, 0x14, 0x36, 0x99,
  36413. 0x19, 0x1C, 0x7E, 0x9A, 0x46, 0x48, 0x42, 0x20,
  36414. 0x6B, 0xBA, 0x24, 0x7E, 0x8C, 0x6B, 0x27, 0xBA,
  36415. 0x26, 0xE6, 0x8A, 0xD5, 0xA7, 0x1D, 0x03, 0x61,
  36416. 0xCD, 0x5C, 0x74, 0xCE, 0x50, 0xC2, 0xCE, 0xF1,
  36417. 0x91, 0x31, 0xEF, 0x54, 0x66, 0x23, 0x7F, 0xFE,
  36418. 0xF7, 0xFE, 0x6B, 0x5F, 0xD1, 0x98, 0x23, 0x8E,
  36419. 0x1C, 0xA0, 0xB1, 0x01, 0x30, 0xC6, 0x29, 0xCC,
  36420. 0x91, 0x91, 0xF5, 0x78, 0x6F, 0x5C, 0xD6, 0x28,
  36421. 0xA4, 0x22, 0x56, 0xCB, 0x6F, 0xC7, 0xD7, 0x09,
  36422. 0x56, 0x88, 0xAF, 0x1B, 0xC8, 0x43, 0x51, 0xA4,
  36423. 0x7B, 0x4B, 0x38, 0x2E, 0xF6, 0x1F, 0xD6, 0x5C,
  36424. 0x9E, 0xC2, 0x26, 0xF4, 0x2B, 0x0A, 0x19, 0x7C,
  36425. 0x6A, 0xD8, 0xF0, 0xB0, 0x15, 0xD0, 0xB1, 0xC7,
  36426. 0xE0, 0x14, 0x28, 0x95, 0x6A, 0x9B, 0xB2, 0xDE,
  36427. 0x9A, 0x97, 0xE5, 0x75, 0x66, 0xF8, 0xF5, 0x66,
  36428. 0x86, 0xA1, 0xF4, 0x68, 0x0C, 0xEC, 0xEA, 0x87,
  36429. 0x3B, 0x69, 0x1C, 0xF8, 0xBD, 0x63, 0xAB, 0x73,
  36430. 0x73, 0xBA, 0xE8, 0x09, 0x5B, 0xA7, 0x76, 0x3E,
  36431. 0x50, 0xD6, 0x83, 0x9D, 0x00, 0x35, 0xBB, 0xFB,
  36432. 0x91, 0xBA, 0x60, 0x72, 0x17, 0x98, 0xFB, 0x2C,
  36433. 0x80, 0x2C, 0x60, 0x3A, 0x08, 0xA1, 0x24, 0x05,
  36434. 0xE0, 0xB5, 0x20, 0xEA, 0x41, 0x43, 0x8F, 0xEA,
  36435. 0xEF, 0xA5, 0x62, 0xDC, 0x78, 0x92, 0xF4, 0x58,
  36436. 0x9F, 0x8D, 0x2B, 0x96, 0x5E, 0xE5, 0x49, 0x73,
  36437. 0xA7, 0x2C, 0x8D, 0x33, 0x5C, 0x62, 0x61, 0x98,
  36438. 0x80, 0x64, 0x13, 0x31, 0x03, 0x10, 0xE3, 0x2E,
  36439. 0xFE, 0x6B, 0x39, 0xB5, 0xCF, 0xB1, 0xD1, 0x33,
  36440. 0xAD, 0xE0, 0x1B, 0xCE, 0x94, 0x21, 0x6C, 0xF4,
  36441. 0xCD, 0x8F, 0x86, 0x43, 0x03, 0x1D, 0xB8, 0xC2,
  36442. 0x47, 0xB5, 0x73, 0x21, 0xCA, 0x1E, 0xFB, 0xB8,
  36443. 0x53, 0x63, 0x7D, 0x0C, 0x57, 0x52, 0x14, 0xFC,
  36444. 0x77, 0xA5, 0xA6, 0x84, 0xD5, 0x0A, 0xBF, 0xE4,
  36445. 0xE9, 0x71, 0x99, 0x8E, 0x06, 0x6E, 0x50, 0x24,
  36446. 0xDA, 0x02, 0x76, 0x8A, 0xED, 0xE1, 0x3E, 0x83,
  36447. 0xF0, 0x51, 0x54, 0xA9, 0x99, 0x29, 0x48, 0x42,
  36448. 0x7A, 0xA9, 0x8C, 0x87, 0x42, 0x51, 0xAF, 0x56,
  36449. 0x94, 0x23, 0x53, 0x89, 0x44, 0xFA, 0xD8, 0x93,
  36450. 0xFC, 0x65, 0x6E, 0x9C, 0xED, 0x80, 0x6A, 0x85,
  36451. 0xD9, 0xC3, 0x36, 0x71, 0x02, 0x25, 0x29, 0x36,
  36452. 0x8E, 0x7E, 0xC7, 0x0C, 0x9E, 0xE9, 0x74, 0x30,
  36453. 0x1C, 0x08, 0xCB, 0xE6, 0xAC, 0x5E, 0x88, 0xE6,
  36454. 0x37, 0x79, 0x5C, 0xB2, 0xA2, 0x15, 0xFF, 0xAA,
  36455. 0x08, 0xED, 0xDE, 0x40, 0xAC, 0xFA, 0xEE, 0x2A,
  36456. 0x40, 0xD5, 0x05, 0xCF, 0x58, 0xA6, 0x69, 0x66,
  36457. 0x31, 0x5A, 0x68, 0x98, 0x24, 0x03, 0xD8, 0x1B,
  36458. 0xFA, 0x89, 0xE3, 0x7C, 0x9E, 0x42, 0x1D, 0xA5,
  36459. 0x88, 0xBA, 0x7E, 0x42, 0x2A, 0xC7, 0x44, 0x6A,
  36460. 0x1E, 0x61, 0xC8, 0x22, 0x29, 0x9D, 0xFC, 0x34,
  36461. 0xEC, 0xFA, 0xBE, 0x5C, 0xB6, 0x26, 0xB9, 0x6C,
  36462. 0x8E, 0xA6, 0xC9, 0x3B, 0xDB, 0xD2, 0xD5, 0xBD,
  36463. 0x70, 0xC5, 0xF8, 0x26, 0x7A, 0x84, 0xE0, 0x07,
  36464. 0xA7, 0x11, 0x5E, 0x5B, 0xE5, 0xF1, 0x20, 0x32,
  36465. 0xA3, 0x7C, 0xAB, 0x05, 0xD5, 0x41, 0xE3, 0xDE,
  36466. 0xA5, 0x1A, 0x83, 0x2E, 0xDE, 0x8D, 0x34, 0x9A,
  36467. 0xFD, 0xD5, 0xE6, 0xFC, 0xFC, 0x83, 0x46, 0xE3,
  36468. 0xD4, 0x7C, 0xF1, 0x7F, 0xEA, 0x87, 0x5E, 0x38,
  36469. 0x5D, 0xB9, 0x8A, 0xC2, 0xDB, 0xE8, 0xB4, 0xF8,
  36470. 0x05, 0x37, 0x31, 0x0D, 0xD9, 0x4C, 0xD0, 0xB6,
  36471. 0x25, 0xE9, 0x97, 0x85, 0xDB, 0x04, 0x9A, 0x01,
  36472. 0xF5, 0x4B, 0xA1, 0xF4, 0x2A, 0xDF, 0xEC, 0xAE,
  36473. 0x24, 0x11, 0xD3, 0x2B, 0x2F, 0x84, 0x6C, 0x88,
  36474. 0xA3, 0x0C, 0x76, 0xEA, 0x0A, 0x38, 0xB2, 0x71,
  36475. 0xB6, 0xAC, 0xA8, 0x23, 0x6E, 0x61, 0xEB, 0xB8,
  36476. 0x4A, 0x9D, 0xC4, 0x9E, 0x5C, 0x5B, 0xEE, 0x7E,
  36477. 0x7D, 0x8D, 0xA2, 0xC1, 0xA1, 0xA0, 0xA3, 0x14,
  36478. 0x50, 0xE0, 0x8F, 0xAB, 0xBB, 0x1B, 0x1F, 0x05,
  36479. 0xAA, 0xE3, 0x00, 0xD8, 0xCD, 0xE7, 0x35, 0xB4,
  36480. 0x7B, 0xBD, 0xB0, 0x5C, 0xCC, 0x0C, 0x05, 0x33,
  36481. 0x6B, 0xE4, 0x51, 0x73, 0x1B, 0x6B, 0x77, 0x7B,
  36482. 0xE5, 0xCB, 0xAF, 0x98, 0x53, 0x5F, 0x7E, 0x08,
  36483. 0xFF, 0xCD, 0x8A, 0x44, 0x9E, 0x1D, 0x43, 0x6A,
  36484. 0x4F, 0x05, 0x99, 0x01, 0xF5, 0x6F, 0x01, 0x30,
  36485. 0xBD, 0x15, 0xD7, 0x51, 0x16, 0x45, 0x40, 0x6B,
  36486. 0xF3, 0x13, 0xCA, 0x1F, 0x22, 0x02, 0xA4, 0xA8,
  36487. 0x6A, 0x1D, 0x04, 0x7F, 0xD5, 0x8A, 0x3E, 0x87,
  36488. 0x7F, 0x1D, 0x5A, 0x79, 0x75, 0xD1, 0x6D, 0x67,
  36489. 0xB3, 0x23, 0xC6, 0x28, 0x7B, 0x9C, 0xCE, 0xEE,
  36490. 0x98, 0x9E, 0xE8, 0x44, 0xA9, 0x3E, 0x7E, 0xFD,
  36491. 0x3B, 0xD9, 0xD8, 0x31, 0x6D, 0xA3, 0x77, 0xDF,
  36492. 0x0B, 0xB9, 0xE2, 0x61, 0xA2, 0x71, 0xD5, 0x0C,
  36493. 0xB7, 0x01, 0x67, 0xC3, 0x0D, 0x19, 0x2D, 0xAA,
  36494. 0xDE, 0x96, 0x0E, 0xEA, 0x33, 0x5E, 0xEC, 0x52,
  36495. 0xE5, 0x2D, 0x95, 0x39, 0xE1, 0xF9, 0x5D, 0x9E,
  36496. 0xB6, 0x5E, 0x54, 0x8F, 0x16, 0x60, 0x99, 0xED,
  36497. 0x88, 0x2C, 0x30, 0x72, 0x53, 0x6A, 0x6C, 0xAA,
  36498. 0x05, 0x21, 0xA5, 0xAA, 0x7C, 0x64, 0x72, 0xA0,
  36499. 0xC0, 0x4F, 0x80, 0xDA, 0x20, 0x5D, 0x52, 0x18,
  36500. 0x77, 0x07, 0xDF, 0x5C, 0x2F, 0x2E, 0xA2, 0x5F,
  36501. 0xEF, 0x00, 0xCA, 0x7B, 0xF0, 0xD3, 0xB7, 0xF8,
  36502. 0x1E, 0x31, 0x9E, 0x61, 0xCA, 0x2C, 0xC5, 0xA5,
  36503. 0x25, 0xA2, 0x7B, 0x56, 0xAA, 0xBA, 0xE4, 0xD5,
  36504. 0x35, 0xE5, 0xEC, 0x24, 0x2D, 0x81, 0x1A, 0x24,
  36505. 0xD7, 0x45, 0x76, 0xBF, 0x4B, 0x8A, 0x72, 0xFA,
  36506. 0x5F, 0xAE, 0xC1, 0xA2, 0x83, 0xB6, 0x1D, 0x60,
  36507. 0x28, 0x7E, 0x1E, 0x2E, 0xC8, 0xC6, 0xAB, 0x04,
  36508. 0x56, 0x5F, 0xD5, 0xCD, 0x64, 0x26, 0x34, 0x94,
  36509. 0xE8, 0x03, 0x41, 0x63, 0x35, 0x5B, 0x45, 0x84,
  36510. 0xCE, 0xFA, 0x0B, 0x66, 0x40, 0x85, 0x1A, 0xE1,
  36511. 0x23, 0xE9, 0x8F, 0xBD, 0xA9, 0x23, 0xFC, 0xA3,
  36512. 0x8E, 0x38, 0xB3, 0x84, 0xE2, 0xB9, 0x54, 0x41,
  36513. 0x4B, 0x36, 0x4F, 0xB8, 0xB0, 0x87, 0x56, 0x04,
  36514. 0x8B, 0x75, 0xC7, 0x85, 0x31, 0xD4, 0xA5, 0x12,
  36515. 0x99, 0xC4, 0x9D, 0xEA, 0x4B, 0x36, 0x8C, 0x19,
  36516. 0x82, 0xFE, 0xAD, 0x4A, 0xB1, 0xAA, 0x52, 0x35,
  36517. 0xA4, 0xA1, 0x7F, 0xB0, 0x64, 0x6F, 0x04, 0x04,
  36518. 0x7B, 0xF0, 0x80, 0x48, 0xA1, 0x1C, 0xF8, 0x95,
  36519. 0x8B, 0x68, 0x34, 0xB7, 0xFD, 0x00, 0x31, 0x30,
  36520. 0x6A, 0x39, 0xC8, 0xAE, 0x68, 0xC3, 0x53, 0x65,
  36521. 0x19, 0x7C, 0x1E, 0x57, 0x97, 0xFC, 0x47, 0x3E,
  36522. 0xB1, 0x94, 0x54, 0x48, 0x6F, 0xEB, 0xAA, 0xEC,
  36523. 0x5C, 0x2E, 0xE9, 0x2C, 0xCC, 0x3A, 0xF3, 0xC7,
  36524. 0x43, 0x08, 0x7D, 0x2D, 0x56, 0x4B, 0x7D, 0xE9,
  36525. 0xE5, 0x96, 0xF3, 0x12, 0x4B, 0xE9, 0x08, 0xF3,
  36526. 0x04, 0x5A, 0x75, 0x1A, 0x7D, 0x7E, 0x37, 0xE6,
  36527. 0xC8, 0xC1, 0xFE, 0xF3, 0x32, 0x63, 0x2D, 0x0B,
  36528. 0xBE, 0x05, 0x13, 0x6A, 0x44, 0x58, 0x7F, 0x54,
  36529. 0x5F, 0x5F, 0xF5, 0x2F, 0xB8, 0x0B, 0xF2, 0xBF,
  36530. 0x0B, 0xF4, 0x30, 0x2F, 0xCF, 0xEC, 0xFE, 0x08,
  36531. 0xEC, 0x51, 0xF2, 0x29, 0xD7, 0xAC, 0x28, 0xE1,
  36532. 0x75, 0x42, 0x61, 0xBC, 0xE7, 0xB1, 0x53, 0x4F,
  36533. 0x7D, 0x3B, 0xB0, 0x8D, 0x01, 0x15, 0x1E, 0xBE,
  36534. 0xEC, 0xD9, 0x54, 0xC2, 0x4E, 0x70, 0x3E, 0xEA,
  36535. 0x39, 0x14, 0x26, 0xB7, 0x01, 0x79, 0x5D, 0x06,
  36536. 0x93, 0x85, 0x99, 0xAA, 0x7D, 0xDC, 0xF9, 0x2E,
  36537. 0x44, 0x56, 0x9B, 0xFA, 0x9D, 0x91, 0x2A, 0x8E,
  36538. 0x89, 0x48, 0x51, 0xE3, 0xD0, 0x53, 0xB3, 0xAD,
  36539. 0x43, 0x29, 0xB7, 0x6A, 0x50, 0xC0, 0x78, 0x4D,
  36540. 0x42, 0xF3, 0x7C, 0x5F, 0x90, 0x06, 0xAC, 0x2A,
  36541. 0x9D, 0x5D, 0xE5, 0x18, 0x3F, 0xA3, 0xC6, 0x5E,
  36542. 0xCD, 0xB6, 0xCF, 0x31, 0x67, 0xA4, 0x7A, 0x8F,
  36543. 0x5C, 0x59, 0xBD, 0xD7, 0x9B, 0x7C, 0x24, 0x06,
  36544. 0x97, 0xE1, 0x59, 0x72, 0x85, 0x02, 0x74, 0xFE,
  36545. 0x41, 0xAD, 0x84, 0xD9, 0x0D, 0xCB, 0x34, 0x16,
  36546. 0x11, 0xE7, 0x66, 0xD2, 0x12, 0xDC, 0x76, 0x3C,
  36547. 0xF9, 0x4C, 0x8C, 0x41, 0x94, 0xCC, 0xA9, 0x1B,
  36548. 0x21, 0x03, 0x28, 0xE4, 0xA3, 0x37, 0x4E, 0x29,
  36549. 0xD2, 0x48, 0x11, 0x2B, 0xB6, 0x68, 0xA3, 0x92,
  36550. 0xC2, 0x0D, 0x87, 0x91, 0x03, 0x76, 0xB5, 0x00,
  36551. 0x1F, 0x3F, 0xFB, 0xBE, 0xC3, 0xE0, 0x08, 0xBF,
  36552. 0x2F, 0x46, 0xF7, 0x40, 0x73, 0x83, 0xA8, 0x0D,
  36553. 0xDA, 0x08, 0x2B, 0xDB, 0x8F, 0xE9, 0x25, 0xE4,
  36554. 0xF1, 0x2B, 0x37, 0x92, 0x27, 0x0E, 0x5A, 0x46,
  36555. 0xB8, 0xC5, 0x7B, 0x6E, 0x5A, 0x4B, 0x95, 0x58,
  36556. 0x4E, 0xF3, 0x80, 0xED, 0x49, 0x93, 0xEC, 0x52,
  36557. 0x9F, 0xF2, 0xAA, 0x39, 0xDD, 0x6D, 0xFE, 0x88,
  36558. 0xFD, 0xEB, 0x6E, 0xDA, 0x0E, 0x8D, 0xA7, 0x95,
  36559. 0x66, 0xB0, 0x7D, 0x37, 0xAE, 0xCC, 0x64, 0x37,
  36560. 0x25, 0x95, 0x18, 0xF9, 0x7E, 0x6C, 0x86, 0x12,
  36561. 0xB3, 0xC3, 0x57, 0x03, 0xBF, 0xF9, 0x92, 0x15,
  36562. 0x3E, 0x66, 0x0E, 0x2E, 0x20, 0x77, 0xA0, 0x5F,
  36563. 0x26, 0x5F, 0xB5, 0x12, 0x1D, 0xD7, 0x9F, 0x0A,
  36564. 0x33, 0xBC, 0x38, 0xEC, 0x83, 0x08, 0xE2, 0xA9,
  36565. 0x84, 0xCD, 0x3D, 0x8A, 0xC6, 0x09, 0x30, 0x6F,
  36566. 0x77, 0x93, 0xD7, 0xDE, 0x08, 0xD8, 0x45, 0xA4,
  36567. 0x21, 0x28, 0x26, 0x4E, 0x5C, 0x17, 0x77, 0x74,
  36568. 0xE3, 0x5D, 0x58, 0x7C, 0x96, 0xB2, 0x47, 0x05,
  36569. 0x42, 0x21, 0x78, 0x5D, 0xB3, 0x8D, 0xDC, 0x6F,
  36570. 0xDB, 0xF7, 0xBF, 0x6F, 0x66, 0x4B, 0xD6, 0x30,
  36571. 0x14, 0xC0, 0xBF, 0x94, 0x2A, 0x83, 0x91, 0x6C,
  36572. 0xBF, 0x2C, 0x42, 0x85, 0x41, 0xED, 0xA2, 0xBB,
  36573. 0xCB, 0xFC, 0xF9, 0x35, 0xDE, 0xFC, 0xB3, 0x63,
  36574. 0xE1, 0x64, 0xAA, 0x51, 0x2D, 0xD5, 0xFA, 0x79,
  36575. 0x53, 0x31, 0x40, 0x0B, 0x9B, 0xD0, 0x3C, 0xE3,
  36576. 0xD7, 0x2D, 0x91, 0x05, 0x62, 0xC3, 0x81, 0xFE,
  36577. 0x93, 0x1E, 0x8C, 0x37, 0x9E, 0x30, 0x23, 0x73,
  36578. 0x3A, 0xB9, 0x18, 0x6E, 0x5D, 0xEF, 0x31, 0xE9,
  36579. 0xF6, 0x25, 0x7F, 0xB8, 0x47, 0x74, 0xCE, 0x28,
  36580. 0x23, 0xD4, 0x4F, 0xC1, 0x42, 0xCB, 0xEB, 0x59,
  36581. 0x8A, 0x68, 0xFD, 0x39, 0x48, 0x37, 0x1A, 0x5D,
  36582. 0x0C, 0x09, 0x64, 0xC6, 0xE1, 0x21, 0x5D, 0x89,
  36583. 0xF6, 0x58, 0xE5, 0x50, 0x4A, 0xD0, 0x93, 0xBC,
  36584. 0x86, 0x02, 0xBA, 0xD2, 0x36, 0x24, 0x9D, 0x7E,
  36585. 0xAF, 0xB6, 0xA1, 0xA0, 0x7C, 0xA7, 0xC7, 0x4D,
  36586. 0xAC, 0x30, 0x7A, 0x70, 0x0F, 0x2F, 0x81, 0x40,
  36587. 0xC1, 0x08, 0x6B, 0x21, 0xF2, 0xE1, 0x51, 0x9C,
  36588. 0x1D, 0x46, 0x94, 0x93, 0x2A, 0x1C, 0x18, 0xCB,
  36589. 0xED, 0x0D, 0x0E, 0x29, 0xDE, 0xFC, 0x52, 0x52,
  36590. 0x97, 0x93, 0x70, 0x85, 0xE2, 0x63, 0x0D, 0xC6,
  36591. 0x2C, 0x0C, 0x05, 0x0C, 0x4F, 0xF2, 0x70, 0x87,
  36592. 0x2B, 0xE7, 0xBB, 0x52, 0x2D, 0xD6, 0x99, 0x1B,
  36593. 0x59, 0x6F, 0xC2, 0x92, 0x11, 0x72, 0x5D, 0x99,
  36594. 0x60, 0xB1, 0x6A, 0x52, 0xEA, 0x91, 0x78, 0x19,
  36595. 0x23, 0xC0, 0x3B, 0x71, 0x9D, 0x09, 0xD6, 0xE7,
  36596. 0x10, 0x6D, 0xC5, 0x70, 0x55, 0xC1, 0x9E, 0xF8,
  36597. 0x76, 0xE5, 0xEC, 0x23, 0x17, 0xE7, 0xE4, 0x23,
  36598. 0xC9, 0x71, 0x45, 0x40, 0x72, 0x01, 0x9E, 0x28,
  36599. 0xE6, 0x5C, 0x81, 0xED, 0x52, 0x7A, 0xF1, 0x89,
  36600. 0xBD, 0xFC, 0xF5, 0x21, 0xC9, 0x23, 0x40, 0x75,
  36601. 0x54, 0xAC, 0xBF, 0x69, 0x45, 0xD1, 0x85, 0x44,
  36602. 0x3D, 0xAC, 0x1A, 0x1A, 0x08, 0x8A, 0x68, 0xB5,
  36603. 0x17, 0xD5, 0xD9, 0x90, 0xE1, 0x10, 0x30, 0xDE,
  36604. 0x4F, 0x75, 0x09, 0xE8, 0x7A, 0x77, 0xB3, 0x7C,
  36605. 0xF2, 0x0A, 0x78, 0xE2, 0xCD, 0x48, 0x94, 0x17,
  36606. 0x3C, 0x32, 0xA3, 0x27, 0x35, 0x51, 0x16, 0xB7,
  36607. 0x18, 0x51, 0x44, 0x42, 0x65, 0x60, 0x6A, 0x0A,
  36608. 0x9A, 0x6D, 0x94, 0x61, 0xCC, 0x5D, 0xD8, 0x3B,
  36609. 0x52, 0x7E, 0x4D, 0xBD, 0x6A, 0xEE, 0x03, 0x3D,
  36610. 0x66, 0x1C, 0x3D, 0xE8, 0xC1, 0x82, 0x97, 0xE5,
  36611. 0xD1, 0x31, 0xDB, 0xC8, 0xF6, 0x96, 0xE9, 0x47,
  36612. 0xC9, 0x5C, 0x71, 0x77, 0x2B, 0x62, 0x44, 0x74,
  36613. 0x4D, 0x06, 0x1E, 0x14, 0x45, 0x3B, 0x9F, 0xB1,
  36614. 0x17, 0x34, 0x80, 0x2D, 0xBA, 0x6F, 0x81, 0x79,
  36615. 0xB8, 0x0D, 0xAC, 0xFE, 0xB6, 0xBA, 0xDF, 0xD1,
  36616. 0x4E, 0x05, 0x76, 0x73, 0x6F, 0x80, 0x10, 0xC5,
  36617. 0x32, 0x87, 0xA3, 0xD3, 0x93, 0x18, 0x79, 0xEF,
  36618. 0x27, 0x3B, 0xBF, 0xCD, 0xB5, 0xDE, 0x5B, 0x88,
  36619. 0xAF, 0x51, 0xFD, 0x8A, 0x8C, 0x8F, 0x0A, 0x58,
  36620. 0x94, 0xE2, 0x25, 0xDF, 0xE8, 0x73, 0xFC, 0xC0,
  36621. 0x3C, 0xB1, 0xC9, 0xB5, 0x78, 0x25, 0xF1, 0x11,
  36622. 0x75, 0xC8, 0x7D, 0x08, 0x78, 0xB9, 0xE6, 0x15,
  36623. 0x6B, 0x40, 0x1B, 0x2F, 0xBE, 0x30, 0x03, 0x6B,
  36624. 0xFC, 0x7D, 0xB1, 0x00, 0x02, 0x71, 0xB7, 0xFF,
  36625. 0x5D, 0x63, 0xA8, 0x09, 0x50, 0x75, 0xEF, 0xBD,
  36626. 0x34, 0xEE, 0x73, 0xDE, 0x60, 0x14, 0x95, 0x2D,
  36627. 0x15, 0xBC, 0x30, 0x23, 0x07, 0x02, 0xD8, 0x7C,
  36628. 0x9A, 0x96, 0xD5, 0xE9, 0xF1, 0xF0, 0xF9, 0x26,
  36629. 0x25, 0x96, 0xAA, 0x58, 0xB7, 0xE4, 0x1A, 0xD9,
  36630. 0xA0, 0x9E, 0xAD, 0xB9, 0x44, 0xB6, 0x3F, 0xD9,
  36631. 0x8B, 0x34, 0x7D, 0x11, 0xBD, 0x52, 0x97, 0xC3,
  36632. 0xBE, 0x28, 0x23, 0x85, 0x9F, 0x2F, 0x35, 0xA4,
  36633. 0xE5, 0x4E, 0x13, 0x68, 0x89, 0x09, 0xC3, 0x1A,
  36634. 0x83, 0xE7, 0xDE, 0xCE, 0x4B, 0xDF, 0x31, 0x03,
  36635. 0x9C, 0x72, 0xBA, 0x54, 0xA1, 0x20, 0x2D, 0x17,
  36636. 0x2A, 0x6B, 0x8A, 0x2C, 0xE9, 0x6D, 0xED, 0xCA,
  36637. 0x5B, 0x24, 0xF7, 0xB9, 0x42, 0xC1, 0x4E, 0x13,
  36638. 0x3D, 0xAA, 0x8A, 0xB8, 0xCB, 0xD2, 0x4C, 0x1F,
  36639. 0x0B, 0xBE, 0xB1, 0x27, 0x97, 0x67, 0x26, 0x72,
  36640. 0xE2, 0x2C, 0xE6, 0xC2, 0x12, 0x37, 0xB2, 0x79,
  36641. 0x7D, 0x8E, 0x54, 0xCC, 0x8F, 0xC7, 0x6C, 0x43,
  36642. 0xB4, 0x75, 0x29, 0x66, 0xA3, 0xA4, 0x09, 0x44,
  36643. 0xE7, 0x2D, 0x37, 0x3F, 0x0D, 0x3E, 0x84, 0xF9,
  36644. 0xA3, 0x30, 0x1E, 0xAE, 0x9E, 0xDA, 0x35, 0x44,
  36645. 0x4B, 0x1E, 0x49, 0xE6, 0x61, 0x18, 0x20, 0x6A,
  36646. 0x56, 0xEB, 0x46, 0xD4, 0x8D, 0x20, 0x95, 0x4A,
  36647. 0x77, 0x9A, 0x1E, 0x74, 0xE3, 0xE3, 0xB2, 0xBD,
  36648. 0x40, 0x3D, 0x46, 0xB3, 0x35, 0x10, 0x11, 0xCB,
  36649. 0x6F, 0x8A, 0x86, 0x72, 0xB2, 0xF3, 0xD9, 0x90,
  36650. 0x31, 0x47, 0x55, 0x77, 0x6C, 0xE3, 0x23, 0x7F,
  36651. 0x0A, 0x50, 0xE7, 0x71, 0x20, 0x53, 0x09, 0xC0,
  36652. 0x5D, 0x9A, 0x78, 0xD3, 0x68, 0x88, 0xA8, 0x3B,
  36653. 0xAD, 0x78, 0xE8, 0x6E, 0xDF, 0x36, 0xA8, 0x8D,
  36654. 0xC7, 0x1C, 0x5F, 0x11, 0x56, 0x83, 0x90, 0xD0,
  36655. 0xB5, 0x92, 0x02, 0xE2, 0x9E, 0xE1, 0x1E, 0xCB,
  36656. 0x9F, 0x56, 0x89, 0x63, 0xE8, 0x17, 0x70, 0x83,
  36657. 0x9F, 0xF2, 0x39, 0xAD, 0x03, 0x15, 0x6C, 0xC0,
  36658. 0x71, 0xE8, 0xB7, 0x40, 0x15, 0x95, 0xEC, 0xEE,
  36659. 0x62, 0x34, 0xAC, 0x34, 0xB7, 0x11, 0x70, 0x3D,
  36660. 0x68, 0xC6, 0x7A, 0x28, 0x83, 0xBE, 0x9C, 0x18,
  36661. 0xAB, 0x7F, 0x1A, 0x1B, 0x2E, 0x5C, 0x90, 0xA2,
  36662. 0x32, 0x3C, 0xDF, 0x1E, 0xD4, 0x98, 0x50, 0xB8,
  36663. 0x39, 0x38, 0x19, 0x2F, 0x62, 0x8C, 0x9E, 0xF6,
  36664. 0x5B, 0x77, 0x93, 0x95, 0xEE, 0x37, 0x34, 0xC7,
  36665. 0xA9, 0x01, 0xF7, 0x47, 0x38, 0x86, 0xD7, 0x12,
  36666. 0xD2, 0x15, 0x41, 0x68, 0x16, 0xC3, 0x01, 0x6C,
  36667. 0xC2, 0x83, 0x83, 0xD4, 0x78, 0x7B, 0x46, 0xF6,
  36668. 0x89, 0xDC, 0xE1, 0x11, 0xDA, 0x4D, 0xB8, 0xAC,
  36669. 0x10, 0xE8, 0x4F, 0x66, 0xA5, 0xC2, 0xBD, 0xA1,
  36670. 0xB3, 0xFC, 0x97, 0x7F, 0x6A, 0x0F, 0x73, 0x2E,
  36671. 0xDA, 0x4F, 0x69, 0xB9, 0x75, 0x51, 0xA4, 0xB8,
  36672. 0xB2, 0x61, 0xD6, 0x88, 0x71, 0x94, 0xD3, 0xAF,
  36673. 0xE7, 0xF4, 0xB8, 0x7F, 0xB3, 0xD4, 0x1A, 0xC6,
  36674. 0xDC, 0xDB, 0x8F, 0xD3, 0x9B, 0xE5, 0x0F, 0x2F,
  36675. 0x38, 0x2B, 0xAA, 0x4D, 0x19, 0xC7, 0x45, 0x0A,
  36676. 0xB3, 0xA1, 0xAC, 0x4C, 0x63, 0xCF, 0x93, 0x0A,
  36677. 0xAA, 0x51, 0x7A, 0x15, 0xD5, 0xC0, 0xD5, 0x49,
  36678. 0xFE, 0x03, 0x22, 0x00, 0x71, 0xD3, 0x69, 0x22,
  36679. 0x3E, 0x51, 0x29, 0x6E, 0xCB, 0xF8, 0x0D, 0xCD,
  36680. 0x79, 0xFB, 0xDF, 0xB8, 0xDF, 0x62, 0x90, 0x4D,
  36681. 0x5A, 0x36, 0x20, 0x0F, 0x29, 0xCC, 0x47, 0xE8,
  36682. 0x0C, 0x86, 0x15, 0xEF, 0x1B, 0x78, 0xDB, 0xB2,
  36683. 0x6A, 0x1A, 0xA7, 0xA6, 0x6E, 0x4D, 0x9A, 0x51,
  36684. 0xC9, 0x72, 0xAC, 0x9C, 0x94, 0xEA, 0xB9, 0x95,
  36685. 0x14, 0xB5, 0xAD, 0xAE, 0x62, 0x51, 0xE8, 0xAA,
  36686. 0x30, 0xA5, 0xE5, 0x87, 0x42, 0x4E, 0x3B, 0x7B,
  36687. 0xCC, 0x42, 0xEB, 0xE7, 0x33, 0x3D, 0x92, 0x10,
  36688. 0x97, 0x26, 0x53, 0xF8, 0x11, 0x8B, 0x83, 0xAB,
  36689. 0xE1, 0xBF, 0x7E, 0x9E, 0xE9, 0xCD, 0xAC, 0x28,
  36690. 0x99, 0x7D, 0x14, 0x4C, 0x34, 0xDE, 0xA6, 0x5B,
  36691. 0x59, 0x51, 0x2C, 0x73, 0x29, 0x27, 0xDB, 0xA8,
  36692. 0x20, 0x7D, 0x56, 0x91, 0x98, 0x47, 0x21, 0xB7,
  36693. 0x27, 0x9A, 0xFC, 0xDD, 0xE0, 0x6A, 0x6B, 0xD2,
  36694. 0x68, 0x0E, 0xBB, 0x9B, 0x2E, 0x3C, 0xFE, 0xE9,
  36695. 0xA6, 0x6D, 0x73, 0xD0, 0xC0, 0xDE, 0xD6, 0x53,
  36696. 0x70, 0x8B, 0x09, 0x0B, 0x82, 0x30, 0x65, 0xF9,
  36697. 0x70, 0x78, 0x49, 0xE3, 0xB3, 0x7D, 0x41, 0x25,
  36698. 0xCA, 0x69, 0x3E, 0x74, 0x2E, 0x02, 0x3F, 0x05,
  36699. 0x8A, 0xDC, 0x95, 0x07, 0x9B, 0xB0, 0x0C, 0x56,
  36700. 0xBE, 0x0D, 0x2F, 0x07, 0x81, 0x82, 0xEF, 0xAB,
  36701. 0x30, 0x72, 0xB0, 0xFD, 0x09, 0x76, 0x7B, 0x8A,
  36702. 0x13, 0xC2, 0x80, 0x5A, 0x75, 0x91, 0xB5, 0xB2,
  36703. 0xE1, 0x24, 0x75, 0xB5, 0xC8, 0x24, 0xDB, 0xEB,
  36704. 0x15, 0x79, 0x30, 0xAB, 0x38, 0x9F, 0x91, 0x5F,
  36705. 0xCC, 0xEC, 0x8F, 0x48, 0x64, 0x7E, 0xE4, 0xB6,
  36706. 0x6A, 0xB6, 0xB5, 0x36, 0xC2, 0x2D, 0xE3, 0xE5,
  36707. 0xEE, 0x4A, 0xBB, 0x42, 0xF8, 0xE0, 0x00, 0x9A,
  36708. 0xF0, 0x45, 0x54, 0xF1, 0x28, 0xAC, 0xA3, 0xCC,
  36709. 0xE4, 0x03, 0xBB, 0x01, 0xFD, 0xB7, 0xB5, 0xE2,
  36710. 0xA7, 0x2B, 0x82, 0x91, 0x1C, 0x1F, 0xD0, 0x65,
  36711. 0x23, 0xFF, 0x90, 0x19, 0x21, 0x41, 0xC6, 0x89,
  36712. 0xEC, 0xCB, 0x0B, 0xE6, 0x1B, 0x4C, 0x6D, 0x77,
  36713. 0x06, 0x29, 0x59, 0x02, 0x18, 0xA4, 0x01, 0x1A,
  36714. 0x68, 0xB8, 0x6F, 0xF5, 0x0D, 0x23, 0x03, 0x9C,
  36715. 0x9B, 0xCD, 0x43, 0x61, 0xF6, 0x98, 0x0A, 0x60,
  36716. 0xEF, 0x88, 0xD1, 0x44, 0x0D, 0x30, 0x4C, 0x5B,
  36717. 0x4B, 0x52, 0xD6, 0xED, 0xC2, 0x91, 0x12, 0xDC,
  36718. 0x3A, 0x8A, 0xF2, 0x85, 0x89, 0xE8, 0xF6, 0x29,
  36719. 0x48, 0xED, 0xB6, 0xBE, 0x76, 0x64, 0x6D, 0x59,
  36720. 0x66, 0x06, 0xB9, 0xE7, 0x05, 0xFE, 0xE3, 0xF1,
  36721. 0x44, 0xA0, 0x7B, 0xC9, 0xED, 0x1D, 0x40, 0x0C
  36722. };
  36723. static const byte msg_65[] = {
  36724. 0x88, 0x5A, 0x0B, 0xDD, 0x8D, 0xE7, 0x4B, 0xC7,
  36725. 0x11, 0x69, 0x0A, 0xA6, 0x14, 0xDD, 0xA5, 0x32,
  36726. 0xF4, 0xD8, 0xC7, 0xEA, 0x2C, 0x27, 0x85, 0x5A,
  36727. 0x57, 0x8E, 0x63, 0x61, 0xCA, 0xAE, 0x2C, 0x0B,
  36728. 0xF7, 0xE7, 0x73, 0xB4, 0x90, 0x0A, 0x32, 0x93,
  36729. 0x12, 0x1A, 0x6E, 0x0D, 0xD6, 0x10, 0x10, 0x7A,
  36730. 0x7A, 0x65, 0xBD, 0x6E, 0x11, 0xF6, 0x19, 0xFC,
  36731. 0x0E, 0x9C, 0xE7, 0xBF, 0x7B, 0x5D, 0xE1, 0x80,
  36732. 0x76, 0xE1, 0xB7, 0x25, 0x57, 0x20, 0x97, 0xB2,
  36733. 0x47, 0xD8, 0xE0, 0x46, 0x24, 0x94, 0xF6, 0x3F,
  36734. 0x4E, 0xDF, 0xBE, 0xAC, 0x2F, 0xA2, 0xEC, 0xAE,
  36735. 0x0C, 0xCA, 0xD4, 0x28, 0xBD, 0x79, 0x6C, 0xF2,
  36736. 0x60, 0x92, 0xA1, 0xCD, 0x50, 0x5F, 0x59, 0x39,
  36737. 0x11, 0xED, 0x10, 0xFD, 0xA4, 0x26, 0xC7, 0xE3,
  36738. 0xC5, 0xA4, 0x39, 0xE8, 0x50, 0x42, 0x13, 0x18,
  36739. 0xAE, 0x07, 0x85, 0xB0, 0x5A, 0xA9, 0x9F, 0x58,
  36740. 0xD6, 0x85, 0x6D, 0xEB, 0x78, 0xBB, 0xE4, 0x88,
  36741. 0xC7, 0x0E, 0xEE, 0x42, 0xBB, 0x9A, 0xB5, 0x92,
  36742. 0x7B, 0x2E, 0xD2, 0x5C, 0xD1, 0x43, 0x77, 0xCD,
  36743. 0x7E, 0x1A, 0x88, 0x34, 0xE8, 0x21, 0x48, 0x00,
  36744. 0x2F, 0xCB, 0x98, 0x5A, 0xB9, 0x43, 0x12, 0x97,
  36745. 0x01, 0x0B, 0x2B, 0xC7, 0x0F, 0x91, 0x32, 0x37,
  36746. 0x3C, 0x6D, 0xD2, 0xA2, 0xA9, 0xCF, 0x24, 0x6F,
  36747. 0xE0, 0x26, 0x2E, 0x8B, 0x53, 0xE6, 0x93, 0xF3,
  36748. 0xD6, 0xFE, 0xD3, 0xED, 0xD1, 0xF2, 0x00, 0x4E,
  36749. 0xD1, 0x7C, 0x2C, 0xF5, 0xB2, 0x57, 0xF4, 0xAD,
  36750. 0xA5, 0xDC, 0x1A, 0x7C, 0x15, 0x1F, 0xFE, 0x03,
  36751. 0xB9, 0x6A, 0x4D, 0xB9, 0x91, 0xE4, 0x13, 0x2D,
  36752. 0x01, 0xDE, 0x1F, 0x03, 0x3E, 0xD8, 0x13, 0x57,
  36753. 0xEA, 0xE7, 0xC1, 0xA8, 0xD2, 0xDD, 0xD9, 0x2D,
  36754. 0xDF, 0xC0, 0x6F, 0x67, 0x13, 0x94, 0xD2, 0xF6,
  36755. 0x02, 0x12, 0xC6, 0xE4, 0x49, 0xEA, 0x35, 0x93,
  36756. 0x24, 0xFE, 0xD3, 0x8C, 0x84, 0xD3, 0x6D, 0x15,
  36757. 0x43, 0x2E, 0x11, 0xE7, 0x15, 0x00, 0x15, 0x80,
  36758. 0x4F, 0x97, 0xA3, 0xC6, 0x77, 0x38, 0x2C, 0xD4,
  36759. 0x6A, 0xA4, 0xD7, 0xAC, 0xEE, 0x56, 0x86, 0xFB,
  36760. 0xCE, 0xD7, 0xA9, 0xE8, 0x5D, 0x29, 0xC4, 0x83,
  36761. 0x86, 0xE6, 0x9F, 0x40, 0x69, 0x3D, 0x9A, 0xDA,
  36762. 0xBE, 0xB4, 0x3B, 0xD0, 0xE5, 0x03, 0x6A, 0xCD,
  36763. 0xE6, 0x31, 0xB5, 0x49, 0x57, 0xF4, 0xFC, 0xE2,
  36764. 0x6F, 0x7A, 0x24, 0xB0, 0xDA, 0xD4, 0x34, 0x8A,
  36765. 0x67, 0x89, 0xCA, 0xE1, 0x06, 0x13, 0x06, 0x20,
  36766. 0xED, 0x2F, 0xA0, 0xEA, 0x38, 0xF5, 0x75, 0xF2,
  36767. 0x87, 0x83, 0xBC, 0x92, 0xB3, 0x2B, 0x0C, 0x51,
  36768. 0xC8, 0xA6, 0x54, 0x6F, 0x5D, 0x88, 0x09, 0x5F,
  36769. 0x9F, 0x73, 0xC6, 0x5B, 0xF6, 0xF2, 0x51, 0xA2,
  36770. 0xC4, 0x69, 0x74, 0x64, 0x45, 0xC5, 0x88, 0xC3,
  36771. 0xEA, 0x81, 0x39, 0xE4, 0x33, 0xD4, 0xFE, 0x2D,
  36772. 0xE4, 0xC0, 0xD3, 0x58, 0xB6, 0xCA, 0x8A, 0x62,
  36773. 0x94, 0xE6, 0xAF, 0xC1, 0xB9, 0x60, 0x74, 0xC0,
  36774. 0x68, 0xEF, 0x67, 0xB1, 0x58, 0xF1, 0x12, 0x9C,
  36775. 0xFE, 0x0A, 0x3A, 0xE7, 0xEB, 0x9D, 0x45, 0x4F,
  36776. 0x35, 0x7F, 0xBB, 0x6A, 0xB3, 0xB9, 0x92, 0x2B,
  36777. 0x1B, 0xCD, 0x55, 0x58, 0x61, 0x87, 0xCD, 0x24,
  36778. 0x69, 0x24, 0x82, 0x78, 0x23, 0x34, 0xAC, 0x9F,
  36779. 0x2B, 0x86, 0x12, 0x48, 0xF6, 0xA5, 0x30, 0xE9,
  36780. 0x3E, 0x11, 0x48, 0x87, 0x84, 0xDD, 0xE5, 0xEA,
  36781. 0x67, 0x8A, 0xE5, 0x05, 0x90, 0x3E, 0x23, 0x10,
  36782. 0x53, 0x30, 0x8C, 0x1B, 0x87, 0x84, 0x60, 0x7E,
  36783. 0x06, 0x3F, 0x48, 0x98, 0xA4, 0xFA, 0xB6, 0x01,
  36784. 0xD3, 0xE6, 0x96, 0x85, 0x97, 0x21, 0x55, 0xF6,
  36785. 0x3F, 0x09, 0xFD, 0x84, 0xB2, 0xB3, 0xDF, 0x74,
  36786. 0x1F, 0xB6, 0x42, 0xAC, 0xA6, 0x03, 0xD0, 0xD5,
  36787. 0x96, 0xE0, 0xA8, 0xDA, 0xD4, 0x24, 0xF4, 0x64,
  36788. 0x0F, 0x98, 0xB9, 0x6F, 0xB2, 0x42, 0xC6, 0x95,
  36789. 0xDC, 0x33, 0x1F, 0x57, 0x59, 0xF7, 0x5E, 0xAF,
  36790. 0x19, 0x1C, 0xBD, 0x98, 0x5E, 0xC5, 0x99, 0x8D,
  36791. 0x56, 0x48, 0xC8, 0x5E, 0xB6, 0x31, 0x29, 0x5F,
  36792. 0x61, 0x56, 0x7C, 0x11, 0x63, 0xF9, 0x90, 0xDC,
  36793. 0x4F, 0xA1, 0x71, 0x40, 0x91, 0x26, 0x1E, 0x5F,
  36794. 0x3E, 0x5F, 0x0B, 0xFE, 0x84, 0x55, 0xBB, 0x8B,
  36795. 0xAA, 0x1D, 0x69, 0x42, 0x1F, 0x15, 0x37, 0x4E,
  36796. 0x73, 0xB0, 0x7E, 0x78, 0x57, 0x9D, 0x0E, 0x25,
  36797. 0x1A, 0x41, 0xEE, 0x1A, 0x50, 0x43, 0xAA, 0xBF,
  36798. 0x8B, 0xE7, 0x73, 0xEE, 0x7F, 0x9D, 0x0F, 0xDF,
  36799. 0xCF, 0xD3, 0xAE, 0x71, 0x1F, 0xAB, 0x1D, 0x3D,
  36800. 0xBC, 0xC2, 0x84, 0x3B, 0xE5, 0xA9, 0x46, 0xB2,
  36801. 0x4D, 0x8B, 0x9B, 0x94, 0x35, 0x8B, 0x5F, 0x59,
  36802. 0x8E, 0x88, 0xED, 0x3D, 0x53, 0xF3, 0x10, 0xF8,
  36803. 0xEC, 0x63, 0x22, 0x9D, 0x4F, 0x5B, 0xB1, 0xB6,
  36804. 0xD5, 0x24, 0xA5, 0xAF, 0x9C, 0x39, 0x47, 0x79,
  36805. 0x25, 0xC7, 0xE2, 0x90, 0x95, 0xFC, 0x43, 0xF1,
  36806. 0x71, 0xFE, 0xCD, 0xD0, 0x61, 0xF3, 0x62, 0x62,
  36807. 0x71, 0x21, 0x75, 0x2C, 0x23, 0x6B, 0x79, 0x2F,
  36808. 0x1B, 0x31, 0x90, 0x79, 0x7C, 0xD0, 0x57, 0x5C,
  36809. 0x58, 0x4F, 0x30, 0xB5, 0x56, 0x81, 0x19, 0x61,
  36810. 0x90, 0x45, 0x09, 0xC9, 0x8B, 0xCD, 0xE8, 0x65,
  36811. 0x9D, 0x22, 0x80, 0xF4, 0x95, 0xA0, 0xC9, 0x55,
  36812. 0x7D, 0x38, 0x11, 0xAF, 0x5E, 0xD4, 0x37, 0x7B,
  36813. 0xC7, 0x59, 0x9E, 0x49, 0x59, 0xFF, 0x85, 0xF2,
  36814. 0x15, 0x0A, 0xCD, 0xEC, 0xC1, 0xF7, 0x67, 0x2D,
  36815. 0xE1, 0xEE, 0x4D, 0xB4, 0x4C, 0x1F, 0xB5, 0xF7,
  36816. 0x99, 0x8A, 0xB5, 0xDB, 0x74, 0x2F, 0x6C, 0x5D,
  36817. 0x32, 0xCB, 0xC0, 0xF2, 0xFB, 0xC9, 0x54, 0xEA,
  36818. 0xD6, 0xCC, 0x13, 0x4B, 0x97, 0x62, 0xDF, 0x33,
  36819. 0x13, 0x86, 0xDE, 0xCA, 0x31, 0x69, 0x47, 0x88,
  36820. 0x4B, 0x9A, 0x13, 0xAD, 0xEA, 0x5C, 0xBE, 0x29,
  36821. 0x56, 0x64, 0x4F, 0xA1, 0x2A, 0x7B, 0xB3, 0xBF,
  36822. 0xB9, 0x7E, 0x1D, 0x93, 0xA7, 0x01, 0x91, 0xAC,
  36823. 0x38, 0xA0, 0x37, 0x32, 0x58, 0xC2, 0xC2, 0x81,
  36824. 0x6D, 0xEA, 0x6E, 0xAF, 0x88, 0x0D, 0x69, 0xF4,
  36825. 0x5F, 0xBA, 0x4C, 0x29, 0x0F, 0x18, 0xD3, 0x4B,
  36826. 0xB8, 0x36, 0x8C, 0xF4, 0xEB, 0xB4, 0x72, 0xBA,
  36827. 0x49, 0x9C, 0xBB, 0x54, 0x50, 0x1E, 0xE3, 0xA2,
  36828. 0x8E, 0x5F, 0xB9, 0xFD, 0xC6, 0x6C, 0xF6, 0x45,
  36829. 0x72, 0x09, 0x47, 0x19, 0xBB, 0xDB, 0x48, 0xF3,
  36830. 0xF4, 0x88, 0x51, 0x3B, 0x65, 0x50, 0xE1, 0x27,
  36831. 0xE8, 0x34, 0x1C, 0x7E, 0x53, 0xDC, 0xFD, 0xA7,
  36832. 0xD4, 0x08, 0x05, 0x58, 0x0B, 0xC7, 0xD3, 0x0A,
  36833. 0x72, 0xF2, 0x44, 0xCC, 0xDB, 0x5A, 0xEF, 0x66,
  36834. 0x1B, 0x0F, 0x30, 0x4E, 0xC5, 0xB7, 0xAB, 0x93,
  36835. 0xB8, 0xC5, 0xC4, 0x9A, 0x77, 0x68, 0x38, 0xB7,
  36836. 0xD5, 0x23, 0x74, 0xAA, 0x41, 0x63, 0x02, 0x24,
  36837. 0xD6, 0x16, 0xF3, 0x10, 0xE4, 0x99, 0xEC, 0xAD,
  36838. 0xCE, 0x93, 0xE7, 0x8B, 0x94, 0xD3, 0xCA, 0x48,
  36839. 0xB3, 0x47, 0xBC, 0x0E, 0xEC, 0xAA, 0x20, 0x66,
  36840. 0x02, 0x29, 0x65, 0xC8, 0x07, 0xBE, 0xF9, 0x02,
  36841. 0x9B, 0xC5, 0x22, 0x8F, 0x00, 0x5E, 0xDB, 0x74,
  36842. 0xD4, 0xB1, 0x44, 0x98, 0xCE, 0x3A, 0xE1, 0x3B,
  36843. 0xEB, 0x7C, 0x69, 0x3B, 0x66, 0x9E, 0xE9, 0xF9,
  36844. 0xA6, 0xF4, 0x6F, 0xC0, 0x0E, 0xC0, 0x5E, 0x13,
  36845. 0x2B, 0xB6, 0xC6, 0x76, 0x0F, 0xB5, 0xC5, 0x1C,
  36846. 0x83, 0x23, 0xAC, 0xD6, 0xA3, 0xC7, 0x5A, 0x72,
  36847. 0xE9, 0x73, 0x89, 0x66, 0xD1, 0x25, 0xB9, 0x61,
  36848. 0x3B, 0x31, 0x45, 0xC6, 0x7B, 0x5E, 0x98, 0x81,
  36849. 0x87, 0xE8, 0x5F, 0x29, 0xAD, 0xCB, 0xAF, 0x74,
  36850. 0xE3, 0x3A, 0x61, 0x1F, 0xFF, 0x25, 0x2A, 0xEB,
  36851. 0xBA, 0xEB, 0x1E, 0xA6, 0x41, 0xE6, 0xFC, 0x8B,
  36852. 0xDF, 0x73, 0x41, 0xBE, 0x2A, 0xA8, 0x57, 0xE4,
  36853. 0x43, 0xAC, 0xFB, 0xCE, 0xB2, 0x15, 0x5D, 0x08,
  36854. 0x1A, 0xCB, 0x4C, 0xCD, 0xB0, 0x98, 0xD5, 0x7C,
  36855. 0xEF, 0x6F, 0x6F, 0xD3, 0x42, 0xDB, 0x2D, 0x83,
  36856. 0xB6, 0x12, 0x3E, 0x0A, 0xD3, 0xC9, 0x3F, 0x30,
  36857. 0x08, 0x11, 0xB8, 0xD5, 0xA1, 0x1A, 0x5A, 0x29,
  36858. 0xBE, 0x60, 0x81, 0x6F, 0x69, 0xB2, 0x9D, 0x1D,
  36859. 0x7E, 0x15, 0x88, 0x69, 0xD8, 0x60, 0xF6, 0xFB,
  36860. 0x82, 0x9D, 0xE8, 0x0D, 0x3E, 0x1B, 0x69, 0x9C,
  36861. 0x3A, 0xB6, 0x80, 0x4E, 0xB6, 0x54, 0x91, 0x78,
  36862. 0xD9, 0x47, 0x33, 0x38, 0xD6, 0xAF, 0x20, 0x9E,
  36863. 0x1F, 0x7D, 0x26, 0x3C, 0x66, 0x7A, 0xE6, 0x89,
  36864. 0x5F, 0x6E, 0x29, 0x33, 0x92, 0x34, 0x71, 0xF1,
  36865. 0x99, 0x58, 0x1F, 0x8A, 0x51, 0xBD, 0x9A, 0xA4,
  36866. 0x52, 0xEE, 0xE4, 0xBF, 0xE9, 0x56, 0x69, 0xAC,
  36867. 0xD0, 0x7B, 0x41, 0xB0, 0x0C, 0x03, 0xF5, 0x5A,
  36868. 0x40, 0xD1, 0x0B, 0x50, 0xF8, 0xE4, 0x67, 0xBD,
  36869. 0x07, 0x1C, 0x8F, 0x40, 0x5C, 0xF1, 0x19, 0x61,
  36870. 0x2D, 0x32, 0x40, 0x5B, 0xD5, 0x27, 0x5A, 0x6B,
  36871. 0xBF, 0x22, 0x17, 0xF9, 0xF1, 0x79, 0x0D, 0x29,
  36872. 0x99, 0x7B, 0x7B, 0x6B, 0x1E, 0xC8, 0xD7, 0x92,
  36873. 0x4A, 0xB9, 0xE6, 0x44, 0xC1, 0x29, 0xCE, 0xE8,
  36874. 0x74, 0x33, 0x29, 0x1A, 0x2C, 0x8E, 0xD6, 0xBC,
  36875. 0x3C, 0x2A, 0x19, 0xD0, 0x76, 0xB1, 0x77, 0xEE,
  36876. 0x60, 0x50, 0x69, 0x2A, 0xDA, 0x8E, 0x95, 0x57,
  36877. 0x4D, 0x6C, 0xE9, 0xAB, 0xE4, 0x97, 0x95, 0xD8,
  36878. 0xF2, 0x8E, 0xAB, 0x69, 0x67, 0x6E, 0x79, 0x03,
  36879. 0xA6, 0x56, 0xFA, 0xB3, 0x20, 0x25, 0xFE, 0x34,
  36880. 0x65, 0xCB, 0xDB, 0x57, 0x01, 0xC1, 0x77, 0x20,
  36881. 0x9D, 0x91, 0x89, 0xA5, 0x91, 0x7C, 0x13, 0x37,
  36882. 0xDE, 0x39, 0xF5, 0x75, 0xE5, 0xDD, 0xB9, 0x3C,
  36883. 0xA7, 0x6B, 0xEB, 0x52, 0xAF, 0x32, 0xE8, 0xD7,
  36884. 0x12, 0x7B, 0x28, 0xF7, 0xCE, 0x73, 0x12, 0xE8,
  36885. 0x03, 0x90, 0x47, 0x21, 0xAB, 0x21, 0x6E, 0x92,
  36886. 0xA8, 0xA9, 0xE6, 0x09, 0xFC, 0x10, 0xAF, 0x8D,
  36887. 0xC2, 0xAA, 0xCA, 0x14, 0xA9, 0x7B, 0xB0, 0xE4,
  36888. 0xB2, 0x34, 0xC7, 0x00, 0x0E, 0xBB, 0xE0, 0xC4,
  36889. 0x42, 0xF1, 0x85, 0x94, 0x6B, 0x7C, 0xE7, 0x72,
  36890. 0x80, 0x95, 0xCD, 0x60, 0x16, 0x9B, 0x0B, 0xD9,
  36891. 0x7B, 0x36, 0xB3, 0xAE, 0x38, 0x55, 0xD9, 0x89,
  36892. 0x25, 0xB2, 0x9D, 0x92, 0x94, 0xEF, 0x27, 0x75,
  36893. 0x09, 0xFC, 0xA4, 0x07, 0xEA, 0x2B, 0xC4, 0x76,
  36894. 0x59, 0x02, 0x6A, 0x82, 0x04, 0xD6, 0x96, 0x4F,
  36895. 0xC6, 0x5B, 0xEF, 0x35, 0x31, 0xE9, 0xC1, 0xE6,
  36896. 0xF9, 0x70, 0xBF, 0x2F, 0xF2, 0x40, 0x75, 0xEA,
  36897. 0x17, 0xD1, 0x36, 0xAD, 0xEA, 0xD2, 0x35, 0x6B,
  36898. 0x6C, 0xE4, 0x98, 0xF9, 0x3C, 0xD2, 0xF9, 0xE5,
  36899. 0xE1, 0x90, 0xD2, 0x09, 0xD9, 0x3E, 0x47, 0x3F,
  36900. 0xAA, 0x8E, 0xD9, 0x20, 0x96, 0x31, 0x5B, 0xF1,
  36901. 0xFC, 0xA6, 0x55, 0xFE, 0xBC, 0x78, 0xE0, 0x99,
  36902. 0x65, 0xC9, 0x74, 0x78, 0x29, 0x6B, 0x75, 0xD3,
  36903. 0x90, 0x56, 0x60, 0x4D, 0x32, 0x71, 0x91, 0x6D,
  36904. 0xCF, 0xF2, 0x25, 0xCB, 0x6B, 0x9A, 0x34, 0xE1,
  36905. 0x5D, 0xC1, 0x64, 0xB2, 0xA6, 0x8A, 0x3B, 0x42,
  36906. 0xDE, 0x05, 0x7A, 0x6B, 0xAC, 0x17, 0x32, 0xCF,
  36907. 0x59, 0x45, 0xBB, 0xCA, 0x12, 0xB8, 0xB3, 0x61,
  36908. 0x59, 0xFB, 0x89, 0xF7, 0xBB, 0xBE, 0x9F, 0xE0,
  36909. 0x34, 0x21, 0x8F, 0x5B, 0x3B, 0xCF, 0x18, 0x4C,
  36910. 0x20, 0x73, 0x06, 0xE6, 0xD2, 0xEA, 0x69, 0x59,
  36911. 0xEA, 0xE0, 0x89, 0x0A, 0x7B, 0x68, 0x02, 0xEC,
  36912. 0x1D, 0xA0, 0x82, 0xBE, 0xD6, 0x5B, 0xB6, 0xE4,
  36913. 0xEB, 0x4D, 0x56, 0x15, 0x70, 0x1C, 0xB0, 0xE3,
  36914. 0x50, 0x36, 0x33, 0x14, 0xA4, 0xD1, 0x01, 0xDB,
  36915. 0xBA, 0x60, 0x53, 0x71, 0xA3, 0x8B, 0x2D, 0x8A,
  36916. 0x37, 0xFF, 0x78, 0xEB, 0xB3, 0x69, 0x82, 0x53,
  36917. 0x88, 0xAA, 0xB7, 0xD3, 0xC6, 0x23, 0xB9, 0x3E,
  36918. 0x51, 0x2D, 0x96, 0xA9, 0xF3, 0x39, 0xEC, 0x96,
  36919. 0x8B, 0x35, 0x27, 0x59, 0xAF, 0x3E, 0x8F, 0xA3,
  36920. 0x21, 0x1C, 0x39, 0x29, 0x5B, 0x01, 0x10, 0xE6,
  36921. 0xDF, 0x26, 0x4E, 0x90, 0x67, 0x8C, 0x11, 0xE2,
  36922. 0xB9, 0x03, 0xAF, 0x32, 0x2E, 0x4F, 0xA7, 0x70,
  36923. 0x28, 0xD3, 0xEC, 0xC4, 0x4F, 0x62, 0x79, 0xD6,
  36924. 0x3B, 0x1E, 0x60, 0xD8, 0x06, 0x72, 0x41, 0x01,
  36925. 0x5F, 0xC4, 0xF8, 0x9B, 0xAA, 0x15, 0x6A, 0x78,
  36926. 0xFA, 0x77, 0xBB, 0x29, 0x14, 0xCA, 0xC2, 0x81,
  36927. 0xF4, 0x40, 0x9C, 0x9C, 0x03, 0x70, 0xAB, 0xD7,
  36928. 0xC1, 0xF8, 0xA5, 0xD1, 0x04, 0x0B, 0x59, 0x75,
  36929. 0x2C, 0xC4, 0xFD, 0xF0, 0xD1, 0x9C, 0xB0, 0xC5,
  36930. 0x6F, 0xEF, 0x34, 0xFA, 0x3A, 0x3B, 0xCE, 0xE1,
  36931. 0xF0, 0x64, 0xE3, 0x60, 0xE8, 0x6D, 0xC5, 0x5D,
  36932. 0xB5, 0xC9, 0x37, 0x5B, 0xDA, 0xDA, 0x67, 0x2E,
  36933. 0x72, 0xF6, 0x64, 0xE3, 0xAC, 0xB2, 0xE6, 0xD8,
  36934. 0xA0, 0x84, 0x09, 0xC8, 0xCD, 0x60, 0xA1, 0xF9,
  36935. 0x53, 0x80, 0xAB, 0x6C, 0x3A, 0xCB, 0x6B, 0x91,
  36936. 0xA8, 0xA9, 0xA3, 0xB7, 0x75, 0x50, 0x49, 0x79,
  36937. 0xB8, 0x02, 0x5A, 0xDB, 0x34, 0x22, 0x61, 0x9B,
  36938. 0xD1, 0x1E, 0x2B, 0x54, 0xFE, 0x6D, 0x07, 0x58,
  36939. 0x81, 0xAC, 0xAC, 0x24, 0x53, 0x20, 0x31, 0xCC,
  36940. 0xD2, 0x99, 0x06, 0x0E, 0x4E, 0xB7, 0xF7, 0xCB,
  36941. 0xD8, 0x08, 0x36, 0xD4, 0xB8, 0x23, 0xA5, 0xFF,
  36942. 0xA4, 0xFE, 0x8C, 0x6B, 0x98, 0x3D, 0x2A, 0xAE,
  36943. 0xB8, 0xF1, 0x6F, 0x6C, 0x1C, 0x22, 0x81, 0xEF,
  36944. 0xD7, 0x13, 0xFF, 0xDA, 0x22, 0x06, 0x9A, 0x5D,
  36945. 0x8A, 0xC4, 0x91, 0x29, 0x1C, 0xBF, 0x49, 0xF1,
  36946. 0x18, 0xC9, 0x46, 0xD5, 0x0F, 0x08, 0xE0, 0xD1,
  36947. 0x73, 0x28, 0x14, 0xE8, 0x15, 0x81, 0x90, 0x6A,
  36948. 0x31, 0x53, 0x94, 0x01, 0x14, 0xBE, 0xC8, 0xEB,
  36949. 0xD4, 0x9C, 0x73, 0x79, 0x0F, 0x9E, 0xD7, 0xCC,
  36950. 0xD9, 0x85, 0xED, 0xAD, 0x8D, 0xB3, 0x42, 0x6B,
  36951. 0x15, 0x13, 0x98, 0xEB, 0xF1, 0x6E, 0xFA, 0xFE,
  36952. 0x3D, 0xA0, 0xC7, 0xF3, 0x8B, 0x22, 0x76, 0x05,
  36953. 0x76, 0xD4, 0x88, 0x52, 0x73, 0xF5, 0xE4, 0x0B,
  36954. 0x14, 0x05, 0x57, 0x10, 0x7F, 0xCE, 0x0B, 0xF8,
  36955. 0x46, 0x1F, 0x24, 0x8B, 0xC4, 0x3F, 0xBF, 0x5C,
  36956. 0xEE, 0xE7, 0x6E, 0xF3, 0xA9, 0xEB, 0xD2, 0x30,
  36957. 0x95, 0x6C, 0x7B, 0x98, 0xAC, 0x89, 0x8A, 0x39,
  36958. 0x9E, 0x5C, 0x2A, 0xB0, 0xCB, 0xE9, 0xE5, 0xAB,
  36959. 0x94, 0x71, 0xDF, 0x5E, 0x53, 0x0C, 0x72, 0xF2,
  36960. 0x6C, 0x34, 0xDB, 0xFE, 0x2F, 0x83, 0x68, 0x3E,
  36961. 0xB6, 0x22, 0xF9, 0x64, 0x7A, 0xA0, 0x6A, 0x26,
  36962. 0x7D, 0x78, 0x97, 0x36, 0x31, 0x2C, 0x90, 0xC9,
  36963. 0xE5, 0x9D, 0x77, 0x12, 0x2A, 0x88, 0x53, 0x8F,
  36964. 0xD0, 0xF5, 0x39, 0x16, 0xAF, 0x08, 0xB2, 0x36,
  36965. 0x93, 0x5C, 0xDC, 0x5B, 0xB3, 0xCB, 0x49, 0x0C,
  36966. 0x83, 0x09, 0xE6, 0xA7, 0x9B, 0x43, 0xE7, 0xA5,
  36967. 0x4A, 0x8A, 0x07, 0xE1, 0xBA, 0xFB, 0x9B, 0x93,
  36968. 0x7E, 0xAC, 0x2F, 0xC3, 0xAC, 0xED, 0x30, 0x64,
  36969. 0x1F, 0x33, 0x79, 0x19, 0xD2, 0xDB, 0x54, 0xEC,
  36970. 0x7F, 0x32, 0x0E, 0xC5, 0x1C, 0xD1, 0x3C, 0x00,
  36971. 0xB9, 0xE6, 0x03, 0xDF, 0x6D, 0xD2, 0x69, 0x0C,
  36972. 0x75, 0xAF, 0x37, 0x07, 0xB7, 0xC9, 0x3E, 0x91,
  36973. 0xCF, 0x02, 0x78, 0xD7, 0x43, 0xA1, 0x8B, 0x4E,
  36974. 0x69, 0x74, 0xB4, 0x24, 0x08, 0x10, 0x42, 0xB5,
  36975. 0xB4, 0xE7, 0x8C, 0xEB, 0x7F, 0xFF, 0x67, 0x98,
  36976. 0x0B, 0xBC, 0xBA, 0x5E, 0x29, 0xBE, 0x61, 0x33,
  36977. 0x56, 0x16, 0xD6, 0x5E, 0x86, 0xF0, 0xE7, 0x46,
  36978. 0xD1, 0x83, 0xDF, 0xD4, 0x6B, 0x75, 0xC9, 0x30,
  36979. 0x0D, 0x60, 0xC5, 0x19, 0xFD, 0x95, 0xA8, 0xA6,
  36980. 0x61, 0xFF, 0xC8, 0x2A, 0xE7, 0x5D, 0xD1, 0x49,
  36981. 0x49, 0x1F, 0x99, 0xD1, 0x41, 0x4F, 0x15, 0x79,
  36982. 0x00, 0x8A, 0x80, 0x27, 0xA6, 0xC9, 0x98, 0xD3,
  36983. 0xE7, 0xA2, 0xBB, 0xFA, 0x07, 0xAB, 0x53, 0xEF,
  36984. 0xE8, 0x17, 0xAE, 0x9C, 0x6A, 0xE8, 0xD0, 0x52,
  36985. 0xAA, 0x85, 0x9D, 0x03, 0x48, 0xB0, 0xD2, 0xC8,
  36986. 0x5B, 0xCC, 0xC4, 0x50, 0x84, 0x90, 0xBE, 0x0F,
  36987. 0x9B, 0x32, 0x13, 0xB8, 0xAF, 0x7C, 0xCE, 0xE7,
  36988. 0x22, 0xE2, 0x82, 0x13, 0x18, 0x71, 0x46, 0xC5,
  36989. 0xDA, 0x05, 0xB7, 0x65, 0xD8, 0x33, 0x06, 0xFA,
  36990. 0x5A, 0x6B, 0x76, 0xD6, 0x92, 0x76, 0xD1, 0x6A,
  36991. 0x2B, 0xC6, 0x0D, 0xB1, 0xAD, 0xAB, 0x57, 0x62,
  36992. 0xEA, 0x76, 0x37, 0x4E, 0xAB, 0x2D, 0x34, 0xD2,
  36993. 0xA3, 0x57, 0xC7, 0x56, 0xFB, 0xEA, 0xD6, 0xA9,
  36994. 0xE3, 0xC1, 0x63, 0x07, 0xDE, 0xB9, 0x5E, 0x5A,
  36995. 0x30, 0x2E, 0x41, 0x4D, 0x43, 0xE9, 0x1C, 0xA1,
  36996. 0x5B, 0xB2, 0x4F, 0xAF, 0xDC, 0xE9, 0xBB, 0xBE,
  36997. 0x73, 0x55, 0x90, 0xF0, 0xD0, 0x02, 0x98, 0x6D,
  36998. 0x13, 0x50, 0x9A, 0xCA, 0x4C, 0xB3, 0x15, 0x3A,
  36999. 0x26, 0x14, 0x38, 0x67, 0xEB, 0xA7, 0x27, 0x33,
  37000. 0x48, 0x97, 0x58, 0x94, 0x57, 0xEA, 0xF9, 0x7E,
  37001. 0x8B, 0xB0, 0xBB, 0xF3, 0xF4, 0x84, 0x6E, 0x69,
  37002. 0x95, 0x2C, 0xF4, 0x6B, 0x1C, 0x65, 0x39, 0xB4,
  37003. 0x46, 0xA7, 0x99, 0xD6, 0x68, 0x47, 0x6E, 0x2E,
  37004. 0x49, 0x84, 0x75, 0x3E, 0x6C, 0x2E, 0x9A, 0x08,
  37005. 0xBC, 0xB7, 0x2F, 0x86, 0x68, 0x5C, 0xE1, 0xBF,
  37006. 0xEA, 0xA1, 0xAF, 0x59, 0xD6, 0x71, 0xB7, 0xBD,
  37007. 0xD6, 0xC5, 0xC2, 0xF2, 0xF3, 0xB5, 0x36, 0xBB,
  37008. 0x36, 0x23, 0x4F, 0xD6, 0x44, 0x59, 0x0A, 0x44,
  37009. 0x86, 0xCA, 0xDC, 0xD4, 0x22, 0x0F, 0x79, 0x09,
  37010. 0x99, 0x8C, 0x8C, 0x9E, 0x03, 0xA4, 0x51, 0x99,
  37011. 0x5A, 0xB9, 0x97, 0x76, 0x73, 0x20, 0xD3, 0x98,
  37012. 0x8C, 0x52, 0x96, 0xE1, 0x65, 0x7B, 0x4C, 0x77,
  37013. 0x40, 0xB2, 0xFE, 0x27, 0x0A, 0x11, 0x76, 0x6E,
  37014. 0x3B, 0x35, 0x12, 0xC6, 0x4E, 0xC2, 0x0E, 0xCC,
  37015. 0x04, 0xB5, 0x51, 0x91, 0xD0, 0x4A, 0xF7, 0x84,
  37016. 0xF2, 0xE7, 0xE5, 0x99, 0x7E, 0xB5, 0x3E, 0xAC,
  37017. 0x53, 0xDB, 0x61, 0x11, 0x71, 0x56, 0x4E, 0xAB,
  37018. 0x4A, 0x68, 0xC1, 0x6A, 0xA5, 0xC5, 0x7F, 0x72,
  37019. 0xEB, 0x14, 0x97, 0xA4, 0x27, 0xA0, 0x53, 0xA1,
  37020. 0xC4, 0x70, 0x7D, 0x58, 0xBD, 0xC1, 0xD7, 0xFD,
  37021. 0x9F, 0xB8, 0x8C, 0xCE, 0x34, 0xF9, 0xE1, 0x9C,
  37022. 0x59, 0x79, 0x31, 0x24, 0xEC, 0xBB, 0xF5, 0x6F,
  37023. 0x3F, 0xA3, 0x5A, 0x55, 0xB3, 0xDE, 0x64, 0xDF,
  37024. 0xA9, 0x95, 0x0B, 0x53, 0xF2, 0xA7, 0x25, 0x7B,
  37025. 0x8C, 0xAD, 0x25, 0x9A, 0x35, 0xBF, 0x15, 0x46,
  37026. 0x69, 0x4A, 0x83, 0x8C, 0x80, 0xFC, 0x37, 0xD0,
  37027. 0xC3, 0x6F, 0x00, 0xE2, 0x3C, 0x63, 0xAB, 0xC5,
  37028. 0x53, 0xC1, 0x8D, 0x4A, 0x40, 0x4B, 0xE6, 0xDC,
  37029. 0x05, 0xB1, 0x20, 0x23, 0x8B, 0xB8, 0xDF, 0x40,
  37030. 0x86, 0x97, 0xB9, 0x5E, 0xA4, 0xB7, 0xA1, 0x37,
  37031. 0xE0, 0x4B, 0x9E, 0xD9, 0x84, 0x2B, 0x2D, 0xAD,
  37032. 0xD1, 0xB1, 0x52, 0x15, 0x00, 0x9B, 0xDD, 0x23,
  37033. 0xA9, 0x27, 0x44, 0x21, 0x33, 0x17, 0x1C, 0x61,
  37034. 0x49, 0x84, 0x0D, 0x6A, 0x11, 0x7C, 0x77, 0xA5,
  37035. 0xD6, 0x8E, 0xE6, 0x1D, 0x6E, 0x90, 0x04, 0x4A,
  37036. 0xD3, 0x54, 0x3A, 0xA7, 0x1A, 0x28, 0xC5, 0x94,
  37037. 0x01, 0xCA, 0xDB, 0x1B, 0x5D, 0x78, 0xC5, 0xC6,
  37038. 0x69, 0x0D, 0x69, 0x88, 0x75, 0x00, 0x02, 0x0B,
  37039. 0x59, 0x6C, 0x3E, 0xC5, 0x30, 0xDF, 0xEE, 0x85,
  37040. 0x43, 0xA2, 0x9A, 0xF9, 0xDD, 0x85, 0x6E, 0xB3,
  37041. 0x0D, 0x83, 0x6A, 0x13, 0x88, 0xD0, 0x12, 0x15,
  37042. 0x53, 0x16, 0xFC, 0x5C, 0x15, 0x47, 0xEC, 0x6D,
  37043. 0x4D, 0x18, 0x2D, 0x88, 0xDB, 0xD2, 0x17, 0x6C,
  37044. 0xDE, 0x64, 0xEC, 0x70, 0x8D, 0x19, 0xDC, 0x66,
  37045. 0x69, 0x7F, 0xCF, 0x61, 0x6E, 0x4F, 0x23, 0x86,
  37046. 0xF5, 0x1A, 0x98, 0x47, 0x4B, 0xCC, 0xE9, 0x2F,
  37047. 0x12, 0x28, 0x12, 0xB9, 0xEB, 0xD8, 0x32, 0xDC,
  37048. 0xE4, 0xD8, 0x63, 0xAC, 0x56, 0x08, 0x2F, 0xEC,
  37049. 0x5E, 0x47, 0x29, 0xFF, 0x76, 0xFE, 0x95, 0x60,
  37050. 0xD2, 0x19, 0x61, 0x0E, 0xAF, 0xFC, 0x44, 0x42,
  37051. 0x11, 0x42, 0x79, 0xBC, 0x06, 0x3A, 0xAD, 0x93,
  37052. 0x7E, 0x46, 0x60, 0x03, 0xB0, 0xF5, 0x9F, 0x57,
  37053. 0x28, 0x48, 0x44, 0x8F, 0x0E, 0xFA, 0x72, 0x8C,
  37054. 0xE4, 0x18, 0xF4, 0x99, 0x6B, 0xB1, 0x23, 0x45,
  37055. 0xDC, 0x13, 0xA2, 0xF6, 0x5F, 0x57, 0x35, 0xA2,
  37056. 0xD7, 0x38, 0xF9, 0xE9, 0x8A, 0x7A, 0x79, 0xC6,
  37057. 0xB2, 0xCD, 0xBF, 0xD3, 0x41, 0x21, 0x56, 0xB3,
  37058. 0x39, 0xD9, 0x14, 0x3B, 0xDD, 0x85, 0xCB, 0x78,
  37059. 0x2F, 0xEB, 0x7E, 0x29, 0xBC, 0x52, 0x24, 0xE7,
  37060. 0x1B, 0x85, 0xB1, 0x65, 0xAE, 0xAB, 0x65, 0xF9,
  37061. 0x54, 0xD2, 0x1F, 0x37, 0x29, 0x52, 0x30, 0x5B,
  37062. 0x3D, 0x5F, 0x48, 0x84, 0x3F, 0x51, 0x27, 0x88,
  37063. 0x9D, 0xA7, 0x94, 0xF0, 0x73, 0xCD, 0x98, 0xD2,
  37064. 0x05, 0xE8, 0x25, 0x71, 0x7C, 0x93, 0x13, 0x82,
  37065. 0x5D, 0x53, 0x8D, 0x05, 0x0E, 0x69, 0x20, 0xC4,
  37066. 0xDB, 0xF2, 0xF6, 0x55, 0x24, 0x29, 0xD0, 0x41,
  37067. 0xF6, 0x2D, 0xF8, 0xC1, 0x2E, 0xC2, 0x4D, 0xE1,
  37068. 0xD7, 0x2D, 0xA0, 0x49, 0x16, 0x0B, 0x4D, 0x34,
  37069. 0xB5, 0x6D, 0xAE, 0x10, 0x93, 0x1E, 0xB6, 0x95,
  37070. 0x69, 0xC2, 0xB3, 0xC0, 0xAF, 0x6F, 0xFF, 0xA5,
  37071. 0x32, 0x3C, 0x7D, 0xC9, 0xC7, 0xC8, 0xEF, 0x0C,
  37072. 0x64, 0x20, 0x23, 0xC4, 0xFE, 0x89, 0x87, 0x8E,
  37073. 0xB3, 0xA6, 0xC5, 0x24, 0xCF, 0x03, 0x7E, 0x74,
  37074. 0xF7, 0xBF, 0x89, 0x1E, 0xCF, 0xB1, 0x02, 0xFA,
  37075. 0xF2, 0x9F, 0xD3, 0x9D, 0x99, 0x00, 0xDA, 0x7A,
  37076. 0x92, 0x7D, 0x13, 0x11, 0x92, 0xAD, 0x55, 0xF2,
  37077. 0xE1, 0x82, 0x72, 0xB1, 0x6A, 0xF1, 0x45, 0x05,
  37078. 0xDA, 0x17, 0xC9, 0xA1, 0x42, 0x82, 0x89, 0x77,
  37079. 0x31, 0xB6, 0x72, 0x54, 0x7C, 0x68, 0x10, 0x25,
  37080. 0x57, 0x30, 0x16, 0x15, 0x08, 0x58, 0x8B, 0xC1,
  37081. 0x61, 0xCB, 0xA0, 0x58, 0x29, 0x33, 0xB1, 0x64,
  37082. 0xF4, 0x4F, 0x06, 0xAA, 0x25, 0x31, 0xAA, 0xA8,
  37083. 0x92, 0x1C, 0x69, 0x1E, 0x6E, 0xB6, 0xBE, 0x81,
  37084. 0xDA, 0x9B, 0xE5, 0x1C, 0x56, 0x39, 0x55, 0xE0,
  37085. 0xC1, 0xEF, 0xD3, 0xED, 0x2A, 0x1C, 0x94, 0x9B,
  37086. 0xD4, 0xE0, 0x0B, 0x3A, 0xE9, 0xEB, 0xC1, 0x3C,
  37087. 0x4C, 0x6C, 0x4E, 0x5E, 0x39, 0x4C, 0xB0, 0x34,
  37088. 0xB9, 0xCB, 0x75, 0xBE, 0xCE, 0x86, 0x44, 0xFF,
  37089. 0x89, 0xEF, 0x95, 0xE7, 0x6E, 0xF7, 0x15, 0xE1,
  37090. 0x7A, 0xA2, 0x6B, 0x1F, 0xEB, 0x77, 0x4C, 0x50,
  37091. 0x59, 0xB3, 0xA3, 0x9A, 0x38, 0xDF, 0xD0, 0x57,
  37092. 0xD6, 0x41, 0xE4, 0x3F, 0xFE, 0x0F, 0x3E, 0x40,
  37093. 0xFF, 0xF6, 0xB2, 0x36, 0x3C, 0x1B, 0xF0, 0xEF,
  37094. 0x07, 0x87, 0x3D, 0x09, 0xA4, 0x87, 0x76, 0x9D,
  37095. 0x0A, 0x73, 0xCD, 0x0C, 0xC6, 0x44, 0xF5, 0x3C,
  37096. 0x25, 0xD2, 0x02, 0x5E, 0xE7, 0x1C, 0x69, 0xB7,
  37097. 0xAC, 0x0F, 0xA6, 0x61, 0x15, 0x57, 0xC4, 0x27,
  37098. 0xC0, 0x69, 0xDF, 0x2E, 0x1B, 0xF6, 0x29, 0xD9,
  37099. 0xA0, 0xCB, 0x5C, 0x67, 0xC7, 0xEA, 0x4F, 0xA6,
  37100. 0x58, 0xC7, 0x8D, 0x00, 0x42, 0xB0, 0x59, 0xE6,
  37101. 0xB6, 0x58, 0xFF, 0xCE, 0x60, 0x16, 0x69, 0x67,
  37102. 0xDB, 0x94, 0xF7, 0x16, 0xEB, 0x4D, 0x04, 0xB3,
  37103. 0xD2, 0x45, 0x0F, 0x40, 0x03, 0x1F, 0x10, 0xAC,
  37104. 0xDD, 0x07, 0x77, 0x7F, 0xBE, 0x9F, 0xBB, 0xB7,
  37105. 0x7F, 0xCB, 0x7C, 0x1F, 0xA9, 0xFC, 0x1E, 0xAF,
  37106. 0x0C, 0x5F, 0x86, 0xD7, 0x96, 0x2D, 0xAE, 0xD0,
  37107. 0x47, 0x4B, 0xA0, 0xFE, 0x68, 0xD9, 0xB2, 0x32,
  37108. 0x77, 0xA9, 0xCA, 0x7F, 0xC6, 0x76, 0xC6, 0x61,
  37109. 0x6B, 0x8E, 0x43, 0x9A, 0x1D, 0x4B, 0xFF, 0x72,
  37110. 0x43, 0x78, 0x19, 0xB5, 0x51, 0x87, 0x56, 0xA7,
  37111. 0x87, 0x3E, 0xF5, 0x84, 0x01, 0x26, 0x46, 0xC3,
  37112. 0x65, 0x9A, 0x6B, 0xA8, 0x6E, 0x62, 0x27, 0x26,
  37113. 0x14, 0xD8, 0x5E, 0xEC, 0xD5, 0x35, 0x0E, 0x3C,
  37114. 0xD0, 0xA1, 0x25, 0xAE, 0x9C, 0x17, 0xCC, 0xE2,
  37115. 0x52, 0x39, 0xE1, 0xEE, 0x9C, 0xDB, 0x39, 0xCA,
  37116. 0x7B, 0x18, 0xCF, 0x2C, 0x88, 0xCF, 0x14, 0x68,
  37117. 0x26, 0xB6, 0xCC, 0x1E, 0x6A, 0xA8, 0xE1, 0x69,
  37118. 0x2C, 0x91, 0x5F, 0x3B, 0xF1, 0xC1, 0xDB, 0x34,
  37119. 0xC6, 0xF3, 0x78, 0x83, 0xCB, 0x4E, 0xDC, 0xE0,
  37120. 0xF7, 0xC9, 0x95, 0xB6, 0x9E, 0x3A, 0xCE, 0x30,
  37121. 0xDC, 0x16, 0x6F, 0x78, 0x4C, 0x93, 0xD6, 0xCB,
  37122. 0xBC, 0xAC, 0x3C, 0x79, 0xBC, 0x31, 0x93, 0x10,
  37123. 0xCE, 0x6E, 0x66, 0x57, 0x00, 0xF1, 0x7F, 0x96,
  37124. 0x2F, 0x18, 0xB2, 0x40, 0x73, 0x9D, 0x15, 0x69,
  37125. 0x0B, 0x1B, 0x6C, 0x85, 0xD1, 0xAA, 0xA3, 0x2D,
  37126. 0x4A, 0x79, 0x74, 0x4A, 0xE5, 0x0C, 0xF9, 0xA9,
  37127. 0x0A, 0x09, 0x54, 0xB4, 0xA4, 0xD9, 0x4C, 0x49,
  37128. 0x9B, 0x41, 0x23, 0xEF, 0xC0, 0x20, 0x44, 0x31,
  37129. 0xF7, 0x22, 0x85, 0xB5, 0xDA, 0x9E, 0x19, 0x22,
  37130. 0x23, 0x0A, 0x30, 0x4D, 0x3A, 0x1B, 0xD8, 0x52,
  37131. 0x08, 0x72, 0x61, 0xB7, 0xCF, 0x0D, 0x8B, 0x90,
  37132. 0xD1, 0x46, 0x23, 0xEB, 0xCD, 0xC6, 0x38, 0x7B,
  37133. 0xC6, 0xAF, 0x65, 0xBE, 0x5F, 0x01, 0x1B, 0x6B,
  37134. 0xC1, 0x23, 0xC1, 0x30, 0x6A, 0x1E, 0x8F, 0xBF,
  37135. 0x2D, 0xF0, 0xB6, 0xF8, 0x9B, 0x0A, 0xE0, 0x5D,
  37136. 0xE0, 0xE4, 0xB7, 0xF5, 0x0A, 0xDA, 0x46, 0xE5,
  37137. 0x3A, 0x9B, 0x6B, 0xCA, 0xDA, 0x06, 0x43, 0xBE,
  37138. 0x6B, 0xFD, 0xC2, 0xB0, 0x6A, 0x6C, 0x75, 0x88,
  37139. 0x3C, 0x2D, 0xC6, 0x13, 0xAC, 0x72, 0x16, 0x31,
  37140. 0x7A, 0x40, 0xC4, 0xA2, 0xC0, 0x86, 0x69, 0x83,
  37141. 0xD3, 0x2C, 0x9C, 0xE0, 0xA6, 0xCC, 0xED, 0xF4,
  37142. 0x03, 0x62, 0x6B, 0xB2, 0x3B, 0x5B, 0x9D, 0xA5,
  37143. 0x86, 0x77, 0x7C, 0x73, 0x5E, 0x19, 0x11, 0xD7,
  37144. 0x7B, 0x11, 0x96, 0xC8, 0xFA, 0x47, 0x21, 0xD6,
  37145. 0xB0, 0xFE, 0x0B, 0x08, 0x11, 0xFC, 0x00, 0xB9,
  37146. 0xA1, 0x24, 0x2C, 0xBD, 0x4A, 0x92, 0x43, 0x10,
  37147. 0x08, 0xBE, 0xE9, 0xE1, 0x5D, 0x19, 0x82, 0xDE,
  37148. 0x34, 0xAE, 0xDC, 0xA6, 0x85, 0x8F, 0x19, 0x30,
  37149. 0x20, 0xB6, 0x44, 0x7F, 0x6B, 0xA6, 0x63, 0x70,
  37150. 0x59, 0xDA, 0x8D, 0xE0, 0xF8, 0x46, 0x86, 0x57,
  37151. 0xB8, 0x1C, 0x57, 0x13, 0x78, 0x41, 0x8C, 0xF5,
  37152. 0x7D, 0x77, 0xAE, 0x75, 0x6C, 0x59, 0x93, 0x2E,
  37153. 0x05, 0x25, 0x03, 0xD1, 0xEA, 0xFB, 0x2D, 0x60,
  37154. 0xD2, 0x61, 0x23, 0xEA, 0x0E, 0xFF, 0x55, 0xE3,
  37155. 0x24, 0x49, 0x00, 0x19, 0xBD, 0x1E, 0x56, 0x24,
  37156. 0x87, 0x2F, 0x7B, 0x98, 0x07, 0x36, 0xD2, 0x7C,
  37157. 0xC5, 0x9B, 0xE0, 0x4E, 0x29, 0xAB, 0xA1, 0xB8,
  37158. 0x35, 0x15, 0x31, 0xCE, 0x65, 0x14, 0x24, 0xF8,
  37159. 0x10, 0xB5, 0xAB, 0x3E, 0xD5, 0x58, 0xCA, 0xE5,
  37160. 0x73, 0x2D, 0x7C, 0x8B, 0xB4, 0x62, 0x75, 0x03,
  37161. 0x30, 0x89, 0xFE, 0x32, 0xF8, 0x65, 0x99, 0xD0,
  37162. 0x88, 0xD5, 0x72, 0x88, 0x03, 0xC9, 0x51, 0x03,
  37163. 0xBA, 0x2F, 0xFB, 0x7C, 0x39, 0x02, 0x05, 0xC4,
  37164. 0xCE, 0xD8, 0xB3, 0xC2, 0x7B, 0x29, 0x8E, 0xA7,
  37165. 0x9D, 0x35, 0x97, 0xB7, 0x17, 0xDE, 0x28, 0x0B,
  37166. 0x32, 0xE5, 0x41, 0xDA, 0x1D, 0x98, 0xBD, 0x27,
  37167. 0xEF, 0xF7, 0xB4, 0x43, 0x09, 0x13, 0x39, 0xC7,
  37168. 0x40, 0x16, 0x11, 0x20, 0x71, 0xCB, 0xB6, 0xC9,
  37169. 0xB0, 0x8F, 0x20, 0xC1, 0xF0, 0x40, 0xFB, 0x6E,
  37170. 0x73, 0x04, 0x8F, 0x73, 0xCA, 0x45, 0xDB, 0xE0,
  37171. 0xF9, 0x25, 0x8D, 0x32, 0xF2, 0x3E, 0x36, 0xBE,
  37172. 0xF7, 0x88, 0xF8, 0x13, 0x4D, 0x9B, 0x10, 0xC2,
  37173. 0x58, 0x0B, 0x20, 0xF8, 0x78, 0xB6, 0x4C, 0x7D,
  37174. 0x2A, 0xA6, 0x81, 0x40, 0xD1, 0x30, 0x50, 0x38,
  37175. 0x2A, 0x5F, 0xBC, 0x81, 0x8E, 0x0F, 0xD4, 0xD0,
  37176. 0x87, 0x99, 0x78, 0x3D, 0xBE, 0x25, 0x15, 0xF4,
  37177. 0x45, 0x61, 0xA3, 0x1A, 0x7D, 0x05, 0x3F, 0xB5,
  37178. 0xA6, 0x1C, 0x41, 0xC6, 0x0E, 0xBE, 0x57, 0x6F,
  37179. 0xC5, 0xB6, 0x38, 0x63, 0x90, 0x55, 0x23, 0xFC,
  37180. 0x26, 0x9E, 0xFD, 0xB8, 0x6C, 0xF2, 0x99, 0x6B,
  37181. 0x6D, 0x90, 0xFE, 0x28, 0xA0, 0x16, 0xEE, 0x63,
  37182. 0xC2, 0x4C, 0xD6, 0xB2, 0x0C, 0xFA, 0x6E, 0x85,
  37183. 0x51, 0xE4, 0x2F, 0x57, 0x91, 0x82, 0x84, 0x43,
  37184. 0x8A, 0x44, 0x31, 0x6C, 0x68, 0x02, 0x01, 0x7C,
  37185. 0xCE, 0x4D, 0xC0, 0x7C, 0x43, 0xA9, 0x54, 0xF5,
  37186. 0x0E, 0xCA, 0xE6, 0x15, 0x98, 0xAE, 0x41, 0x57,
  37187. 0x0A, 0x66, 0xBA, 0x6D, 0x6E, 0x68, 0xB9, 0x2E,
  37188. 0x0D, 0x42, 0xD2, 0xF5, 0x0B, 0xFC, 0x2D, 0xA8,
  37189. 0x61, 0x6E, 0x60, 0x4E, 0x51, 0x78, 0xEB, 0x0C,
  37190. 0x52, 0x9E, 0xC0, 0x4A, 0xB0, 0x92, 0x85, 0x5C,
  37191. 0x3A, 0x3D, 0x69, 0x95, 0xAB, 0x62, 0xEB, 0x2F,
  37192. 0x9B, 0x12, 0xF5, 0x2E, 0xB5, 0xA6, 0x93, 0xCE,
  37193. 0x14, 0x97, 0xA7, 0x1E, 0x0A, 0x7B, 0x94, 0x74,
  37194. 0xFB, 0x65, 0xD0, 0x5A, 0x97, 0x55, 0x40, 0x02,
  37195. 0x71, 0x87, 0x9C, 0x9F, 0xCB, 0x41, 0x3F, 0x08,
  37196. 0x8D, 0x6A, 0xCA, 0xE6, 0xEC, 0xE6, 0x71, 0x22,
  37197. 0xF8, 0x58, 0x9F, 0xF1, 0x94, 0xF6, 0xE4, 0xD6,
  37198. 0xDC, 0x35, 0xD7, 0xEB, 0x6B, 0x78, 0x99, 0x66,
  37199. 0xF9, 0xE2, 0x15, 0x27, 0xC9, 0x8C, 0x27, 0xB4,
  37200. 0x89, 0x3C, 0x15, 0xEE, 0x52, 0x71, 0xA9, 0xD2,
  37201. 0x50, 0x3C, 0xD2, 0x31, 0xBB, 0x3A, 0xE5, 0x87,
  37202. 0xAF, 0x65, 0x2B, 0xF2, 0xF5, 0xC9, 0x44, 0xA2,
  37203. 0x59, 0x1C, 0x57, 0x96, 0xB9, 0xC2, 0x5E, 0xCB,
  37204. 0x8A, 0x5B, 0x2B, 0x7A, 0x7E, 0x93, 0x3C, 0x08,
  37205. 0x27, 0xCD, 0xB4, 0xB0, 0x1B, 0xF3, 0x82, 0x50,
  37206. 0x78, 0xCF, 0xEA, 0x28, 0x57, 0xB1, 0x0F, 0xB4,
  37207. 0xB6, 0x93, 0x82, 0x8E, 0x7A, 0xD1, 0x9F, 0x04,
  37208. 0xEC, 0xEE, 0x24, 0x3D, 0x8A, 0x5E, 0x56, 0x99,
  37209. 0x8D, 0x83, 0xA4, 0x05, 0x7D, 0xFB, 0x36, 0xDB,
  37210. 0xAB, 0xD1, 0x67, 0x59, 0xC7, 0x4A, 0xB9, 0xAF,
  37211. 0x99, 0xB6, 0xD8, 0xD4, 0x2C, 0xCA, 0x8C, 0xCC,
  37212. 0xD2, 0x32, 0xAB, 0x51, 0xCE, 0x2D, 0x22, 0xE0,
  37213. 0x29, 0xB1, 0x73, 0x10, 0x60, 0xA8, 0x6B, 0x8F,
  37214. 0x68, 0xAF, 0x58, 0x06, 0x9D, 0x72, 0x36, 0x98,
  37215. 0x3F, 0xF3, 0x6B, 0xAD, 0x3E, 0x7F, 0x4A, 0x00,
  37216. 0x94, 0x04, 0xAE, 0xE9, 0x8A, 0x9E, 0x8A, 0x03,
  37217. 0xD8, 0x04, 0xCC, 0xFE, 0xE3, 0xF8, 0xA2, 0x04,
  37218. 0x64, 0x17, 0x54, 0x77, 0xCA, 0x20, 0xD0, 0x80,
  37219. 0x1B, 0x36, 0xEF, 0x59, 0x31, 0xFA, 0xE4, 0xF5,
  37220. 0xAF, 0x56, 0x09, 0x02, 0xAD, 0xCF, 0xA6, 0xBC,
  37221. 0x26, 0x23, 0x27, 0x6D, 0xF3, 0x52, 0xCE, 0x2F,
  37222. 0x4C, 0x9C, 0xA8, 0x23, 0x75, 0xFA, 0x56, 0x9E,
  37223. 0x07, 0x5B, 0xB9, 0x30, 0x5A, 0xB1, 0x27, 0xFF,
  37224. 0x72, 0xBF, 0x50, 0xB1, 0x27, 0xEF, 0xA1, 0x0C,
  37225. 0x3A, 0xC9, 0x72, 0x21, 0xBE, 0xD8, 0xDC, 0xD5,
  37226. 0x66, 0x4A, 0x0A, 0x58, 0xFA, 0x57, 0xB4, 0x00,
  37227. 0x07, 0x31, 0xF2, 0x4E, 0xDC, 0xE0, 0x86, 0x99,
  37228. 0x45, 0xE5, 0x45, 0xCF, 0x27, 0x35, 0x79, 0x57,
  37229. 0xF5, 0xA2, 0x7A, 0x29, 0xFA, 0x5E, 0xCF, 0xF9,
  37230. 0xA9, 0x96, 0x11, 0xE1, 0x4A, 0x6C, 0xE5, 0xB8,
  37231. 0x8E, 0x78, 0xE6, 0xA1, 0x46, 0x97, 0xAE, 0xB4,
  37232. 0xF3, 0x6D, 0x7F, 0x8E, 0xD1, 0x86, 0x6B, 0x78,
  37233. 0x2B, 0x55, 0xC5, 0xDF, 0x0F, 0x43, 0x78, 0xED,
  37234. 0xD2, 0x38, 0xE5, 0x8B, 0x94, 0x7A, 0x06, 0xC5,
  37235. 0x73, 0x17, 0x55, 0x93, 0xAD, 0xA5, 0xAC, 0xBA,
  37236. 0x81, 0x8A, 0x6D, 0x73, 0x4B, 0xA1, 0x32, 0x8F,
  37237. 0x21, 0xA6, 0x5B, 0x51, 0x31, 0x58, 0xD0, 0xE4,
  37238. 0x0B, 0x93, 0x46, 0xF2, 0x51, 0x30, 0x3E, 0x60,
  37239. 0xE1, 0xCB, 0x30, 0x04, 0x15, 0x8D, 0x1E, 0x87,
  37240. 0xA6, 0xF6, 0x38, 0xE0, 0x27, 0x84, 0x81, 0x18,
  37241. 0x2B, 0x37, 0xBB, 0xD3, 0xDB, 0xE7, 0x91, 0xA3,
  37242. 0x1B, 0x6B, 0x20, 0xCB, 0x2C, 0x52, 0xB1, 0xB9,
  37243. 0x6A, 0x94, 0xF8, 0xCD, 0xBA, 0x5D, 0xC7, 0xDD,
  37244. 0x79, 0x36, 0x38, 0xC2, 0xFC, 0xEC, 0x4F, 0x2B,
  37245. 0x5F, 0x73, 0x44, 0x03, 0xE9, 0xA9, 0xF5, 0xD9,
  37246. 0x99, 0xEA, 0x61, 0xDC, 0x6A, 0x98, 0xBE, 0xDE,
  37247. 0xB9, 0x34, 0xCC, 0x76, 0xB0, 0xE1, 0x8C, 0x70,
  37248. 0x3A, 0xA5, 0x7C, 0xD1, 0xC0, 0x2A, 0x8E, 0x7D,
  37249. 0x47, 0x8A, 0x63, 0xEA, 0x30, 0x6B, 0xEE, 0x36,
  37250. 0x0B, 0xA8, 0xAE, 0x46, 0xCD, 0x01, 0x83, 0xF6,
  37251. 0x07, 0xF9, 0xED, 0x8B, 0x69, 0x97, 0xB6, 0xC3,
  37252. 0x5D, 0x75, 0x6E, 0xD8, 0xDF, 0x01, 0x82, 0x48,
  37253. 0x31, 0x2F, 0xDE, 0xED, 0x8E, 0xC5, 0xD8, 0xA6,
  37254. 0xC0, 0x36, 0x0E, 0x66, 0xA4, 0xE9, 0xE5, 0xA9,
  37255. 0x7D, 0x5C, 0xD2, 0x43, 0x72, 0xC0, 0xAD, 0x26,
  37256. 0x78, 0xF2, 0xB0, 0x08, 0x12, 0xAE, 0x6C, 0x1A,
  37257. 0x0F, 0x53, 0x30, 0xB3, 0xAB, 0x01, 0x53, 0xDA,
  37258. 0x3C, 0x5F, 0x4C, 0x17, 0xBD, 0x2F, 0xB6, 0x0E,
  37259. 0x7E, 0x80, 0x87, 0x4C, 0x1B, 0x92, 0x9B, 0x62,
  37260. 0xE3, 0x89, 0xEE, 0xE2, 0xA0, 0x14, 0x06, 0x0D,
  37261. 0x4D, 0xCC, 0x96, 0x5A, 0xF8, 0x64, 0x2A, 0x05,
  37262. 0xA9, 0xEE, 0xD5, 0x0D, 0x23, 0x90, 0xB0, 0x67,
  37263. 0xD5, 0x51, 0x1D, 0x18, 0xBC, 0xBA, 0xE6, 0xA5,
  37264. 0xAD, 0x29, 0x18, 0xD5, 0x06, 0xFC, 0xC9, 0x12,
  37265. 0x6D, 0x70, 0xA8, 0x6E, 0x96, 0x8B, 0x5F, 0x9C,
  37266. 0x99, 0x43, 0x07, 0x02, 0x37, 0x48, 0x8C, 0xFB,
  37267. 0x5F, 0xF5, 0xDE, 0x69, 0x26, 0x73, 0x7D, 0xF6,
  37268. 0x3A, 0x2C, 0xE5, 0x58, 0x01, 0xC3, 0x48, 0xB0,
  37269. 0xF0, 0x0D, 0x56, 0xAF, 0x8C, 0x0F, 0x5C, 0xB3,
  37270. 0xBA, 0x44, 0x8C, 0x39, 0xB0, 0x20, 0xD2, 0x93,
  37271. 0x81, 0x19, 0x99, 0x4E, 0xAC, 0xB9, 0x1F, 0xC3,
  37272. 0x1F, 0x34, 0x7D, 0xF3, 0x3E, 0x1A, 0xE1, 0x26,
  37273. 0x7C, 0xB7, 0x22, 0x0A, 0xDC, 0x0D, 0x14, 0xF8,
  37274. 0x43, 0x8A, 0x23, 0x46, 0x37, 0x9C, 0x2A, 0xB8,
  37275. 0x1F, 0x24, 0x72, 0xE2, 0xEA, 0xC4, 0x67, 0x13,
  37276. 0x17, 0x33, 0xBD, 0xA0, 0x07, 0xA0, 0x3E, 0xDE,
  37277. 0x8B, 0xC4, 0xD6, 0xDB, 0xD9, 0xF1, 0xB8, 0xF4,
  37278. 0xFB, 0x83, 0x13, 0x14, 0xCD, 0x36, 0xF6, 0xDC,
  37279. 0xD5, 0x85, 0x93, 0x7C, 0xF9, 0x6C, 0xEA, 0x52,
  37280. 0x92, 0xFB, 0xFC, 0x95, 0x02, 0x10, 0x7B, 0x57,
  37281. 0x9F, 0xF0, 0x7C, 0x2E, 0x79, 0x00, 0x3D, 0xB2,
  37282. 0xA1, 0x6C, 0x4E, 0xD4, 0x17, 0xFA, 0x0F, 0x13,
  37283. 0xC8, 0xBF, 0xB1, 0x82, 0xF7, 0xDD, 0xCF, 0x08,
  37284. 0xF2, 0x50, 0xDB, 0x16, 0xA4, 0x5A, 0x60, 0x4A,
  37285. 0x57, 0x2B, 0x0E, 0xDC, 0x4A, 0xBF, 0x9C, 0x86,
  37286. 0x08, 0x8A, 0x5A, 0xC8, 0x74, 0xDD, 0xA2, 0x6E,
  37287. 0x12, 0xA0, 0xEF, 0x63, 0x5A, 0xD2, 0x82, 0xAD,
  37288. 0xCD, 0xC7, 0xED, 0x16, 0x86, 0x45, 0x3D, 0xFB,
  37289. 0x35, 0xC3, 0xB1, 0xBA, 0x68, 0x21, 0xB4, 0xB7,
  37290. 0x22, 0x0B, 0x55, 0x79, 0x8B, 0x9C, 0xCF, 0xE0,
  37291. 0x66, 0x61, 0x5C, 0xE2, 0x55, 0x96, 0x0D, 0x09,
  37292. 0xE6, 0x77, 0xFE, 0xFE, 0x76, 0xBE, 0x91, 0x5E,
  37293. 0x04, 0xE5, 0x65, 0x44, 0xBD, 0x09, 0xD0, 0x6F,
  37294. 0x83, 0x44, 0xF9, 0x68, 0xDC, 0x68, 0x25, 0xCB,
  37295. 0xC6, 0x64, 0xD5, 0x18, 0xA4, 0x41, 0xE1, 0x9B,
  37296. 0x07, 0x6F, 0xC3, 0x38, 0x91, 0x37, 0xFC, 0x1B,
  37297. 0x73, 0x32, 0xE2, 0xB0, 0x68, 0x95, 0x44, 0x3B,
  37298. 0x7A, 0x00, 0x23, 0x36, 0x31, 0x15, 0x79, 0xA9,
  37299. 0xB0, 0x8F, 0x36, 0x73, 0xDA, 0x05, 0x90, 0xE6,
  37300. 0x96, 0xCE, 0xD9, 0x01, 0x44, 0x4A, 0x70, 0xA6,
  37301. 0x7B, 0x2A, 0x7D, 0x55, 0x12, 0xD6, 0x5B, 0xFC,
  37302. 0xD7, 0xAF, 0x1E, 0x34, 0x27, 0x77, 0x69, 0xE1,
  37303. 0x71, 0x08, 0x83, 0x01, 0xDE, 0x78, 0x46, 0xF0,
  37304. 0x88, 0xF4, 0x87, 0xC4, 0x92, 0x1B, 0xEB, 0x98,
  37305. 0x35, 0x4B, 0xAE, 0x9A, 0xF6, 0xEA, 0xB2, 0x34,
  37306. 0x91, 0x14, 0xEB, 0x21, 0xF6, 0x18, 0xDB, 0x1D,
  37307. 0x92, 0x6C, 0x1D, 0x2F, 0xE3, 0xA5, 0xF2, 0x29,
  37308. 0xC5, 0x73, 0x40, 0xC4, 0x0A, 0xEC, 0x11, 0xC2,
  37309. 0xD0, 0x14, 0x4D, 0x03, 0x94, 0xFC, 0x4D, 0x8E,
  37310. 0x38, 0x66, 0xA7, 0xD0, 0xA1, 0x0B, 0x64, 0xC8,
  37311. 0xB9, 0x92, 0xB0, 0xA4, 0xDD, 0xBC, 0xAD, 0x82,
  37312. 0x4E, 0x43, 0x97, 0x43, 0x78, 0xEA, 0x9A, 0x38,
  37313. 0xE5, 0x8C, 0x2C, 0x5A, 0xE1, 0x94, 0xAF, 0x43,
  37314. 0x10, 0xFB, 0xEC, 0x90, 0x28, 0x41, 0x6C, 0x5C,
  37315. 0xB7, 0xB8, 0xAF, 0xA5, 0x24, 0xF7, 0x4F, 0xFD,
  37316. 0x6F, 0x2E, 0x98, 0x44, 0x3F, 0x5E, 0x89, 0x24,
  37317. 0xF6, 0xCF, 0x11, 0x0E, 0x67, 0x1B, 0x81, 0x68,
  37318. 0x37, 0xD5, 0x9B, 0x2D, 0xB9, 0x1C, 0xB1, 0xE6,
  37319. 0x87, 0xD6, 0xA2, 0x02, 0x0F, 0x91, 0x08, 0xF6,
  37320. 0x9B, 0x94, 0x76, 0x62, 0xFD, 0xE7, 0x18, 0xAC,
  37321. 0x28, 0xA6, 0xAC, 0xDA, 0x27, 0xF4, 0x33, 0x59,
  37322. 0xBB, 0xBE, 0x36, 0x2C, 0xEE, 0xEA, 0x91, 0xE6,
  37323. 0x91, 0x95, 0x2C, 0x58, 0x0A, 0xB2, 0xCA, 0xA3,
  37324. 0xAA, 0x39, 0x03, 0x9A, 0x75, 0x3C, 0x27, 0x6E,
  37325. 0x02, 0x89, 0x17, 0x4B, 0x02, 0x42, 0x7C, 0xB4,
  37326. 0x2E, 0xAD, 0xB4, 0xD9, 0x35, 0xB2, 0x30, 0x9E,
  37327. 0x2F, 0xEC, 0x9F, 0x25, 0x56, 0x1A, 0x35, 0x40,
  37328. 0xF1, 0xAF, 0x1D, 0xA4, 0xA8, 0x62, 0x07, 0x70,
  37329. 0x98, 0x6C, 0xDE, 0x1E, 0x89, 0xC1, 0xD3, 0x30,
  37330. 0xBB, 0x82, 0x72, 0x40, 0xF2, 0xBC, 0x53, 0xC7,
  37331. 0xDE, 0xAB, 0xFC, 0x7D, 0xAD, 0xBF, 0xDA, 0xE0,
  37332. 0xA7, 0xA1, 0x0C, 0xD6, 0x73, 0x37, 0x36, 0xA1,
  37333. 0xEE, 0xA6, 0x96, 0x88, 0x79, 0x0E, 0x4A, 0x2C,
  37334. 0x69, 0x4C, 0xE5, 0x30, 0xFB, 0xDD, 0xE1, 0xFE,
  37335. 0x86, 0x90, 0xDC, 0xDF, 0x03, 0xF5, 0x17, 0x2F,
  37336. 0xF4, 0x58, 0x2D, 0xD3, 0xED, 0x3D, 0x7D, 0xA0,
  37337. 0xB3, 0x6E, 0x1E, 0xD3, 0xBB, 0xD9, 0x57, 0xBA,
  37338. 0x8B, 0x00, 0x72, 0xC4, 0xEE, 0xCF, 0x39, 0xD5,
  37339. 0x74, 0xFA, 0x13, 0xF0, 0xD7, 0xE9, 0x10, 0x0C,
  37340. 0x7A, 0x52, 0x62, 0xD0, 0xC9, 0xD5, 0x2D, 0xDC,
  37341. 0x11, 0xD4, 0xFF, 0x34, 0xB2, 0x55, 0xF9, 0x99,
  37342. 0x81, 0xB4, 0xC9, 0x14, 0x02, 0x91, 0x81, 0x56,
  37343. 0x29, 0xF6, 0xA9, 0x1A, 0x19, 0x8E, 0x74, 0xB3,
  37344. 0xA3, 0xD1, 0x28, 0xB5, 0x72, 0xD8, 0x6F, 0x54,
  37345. 0x15, 0x74, 0x55, 0x70, 0x26, 0x62, 0xCB, 0x1D,
  37346. 0x15, 0x2C, 0x7F, 0x4C, 0x9C, 0xB4, 0xDE, 0xA2,
  37347. 0x07, 0xD5, 0xA9, 0x38, 0x29, 0x42, 0x51, 0x67,
  37348. 0x44, 0x26, 0x97, 0x7E, 0x73, 0x0E, 0xC6, 0x01,
  37349. 0x00, 0x65, 0xC8, 0xE0, 0x34, 0x88, 0x2B, 0xD3,
  37350. 0x2F, 0xD3, 0x5C, 0x6A, 0xF6, 0xB8, 0xD9, 0x3A,
  37351. 0x50, 0x9C, 0xC3, 0x39, 0xD9, 0x6F, 0xB9, 0xDD,
  37352. 0x55, 0x8A, 0xF9, 0x52, 0x35, 0xFB, 0xF1, 0x71,
  37353. 0x97, 0x76, 0x04, 0x75, 0xEE, 0x2E, 0x3F, 0xCA,
  37354. 0x0E, 0x83, 0xA8, 0xE3, 0x1F, 0xA7, 0xF1, 0x3D,
  37355. 0x78, 0xCC, 0x79, 0x64, 0x80, 0x5E, 0x77, 0x05,
  37356. 0xDB, 0xB7, 0x0F, 0x73, 0x53, 0x3A, 0x56, 0xD8,
  37357. 0xB7, 0x7C, 0x12, 0xE8, 0xF6, 0x51, 0x07, 0xC9,
  37358. 0x01, 0x43, 0x97, 0x51, 0x75, 0x95, 0x94, 0x65,
  37359. 0xFD, 0x4D, 0x8C, 0x8C, 0xD3, 0xA8, 0xEE, 0xA9,
  37360. 0x5E, 0xFB, 0xC7, 0xF6, 0xF8, 0x40, 0x0E, 0xA5,
  37361. 0xD5, 0x1E, 0x79, 0xB4, 0x0C, 0xEF, 0x8B, 0x04,
  37362. 0x59, 0x4D, 0x0C, 0x6F, 0x08, 0xD5, 0x00, 0xA2,
  37363. 0xAD, 0x08, 0xB4, 0x62, 0xE0, 0x2C, 0xF6, 0x30,
  37364. 0x31, 0x1E, 0xD7, 0x81, 0x56, 0x61, 0x17, 0x0D,
  37365. 0xB3, 0x9F, 0x27, 0x75, 0x38, 0x42, 0x6E, 0xB2,
  37366. 0xB0, 0x6C, 0xB8, 0xC9, 0xD8, 0x20, 0xC8, 0x36,
  37367. 0x7D, 0x1D, 0x57, 0x10, 0x4E, 0xC1, 0x45, 0xFC,
  37368. 0x93, 0xB1, 0xF7, 0x7B, 0xA1, 0x3B, 0x71, 0x12,
  37369. 0x16, 0xE5, 0x8F, 0xD0, 0x0C, 0x7D, 0xC0, 0x05,
  37370. 0x18, 0x02, 0x24, 0x25, 0x28, 0x8A, 0xE1, 0x29,
  37371. 0x9A, 0x79, 0xBD, 0xC7, 0x73, 0x2D, 0xF3, 0x42,
  37372. 0x70, 0x33, 0xF3, 0xF8, 0x48, 0x87, 0xB4, 0xD4,
  37373. 0x91, 0xE1, 0x53, 0xBA, 0x4A, 0x63, 0xAF, 0x3A,
  37374. 0xE5, 0xCB, 0x3D, 0x41, 0x04, 0xB5, 0x30, 0x87,
  37375. 0xAA, 0x40, 0x03, 0x56, 0x10, 0x02, 0xF3, 0x6A,
  37376. 0x9F, 0xDA, 0x33, 0xBC, 0xB8, 0xA5, 0xD0, 0x56,
  37377. 0x43, 0x29, 0xDA, 0x58, 0x12, 0x8B, 0x6A, 0x9D,
  37378. 0xCF, 0xCD, 0xCA, 0x66, 0x98, 0x92, 0x1D, 0xA4,
  37379. 0xEF, 0xAC, 0x9E, 0x19, 0xDE, 0xF7, 0xFE, 0x6C,
  37380. 0x3A, 0x66, 0x46, 0xB4, 0x00, 0x7F, 0x08, 0xAF,
  37381. 0x31, 0xD6, 0xD3, 0x22, 0x59, 0x1F, 0x34, 0x48,
  37382. 0x5A, 0xE1, 0x4E, 0x0F, 0x6F, 0x2D, 0xD0, 0xE5,
  37383. 0x8E, 0x34, 0x3B, 0xC0, 0x55, 0x02, 0x2D, 0x17,
  37384. 0x4B, 0x34, 0x78, 0x46, 0xD4, 0xC4, 0x7F, 0x1D,
  37385. 0xDC, 0x39, 0x94, 0x69, 0x78, 0xAB, 0xD8, 0x2B,
  37386. 0x6D, 0xF3, 0x1C, 0x0B, 0x0F, 0x4A, 0xA0, 0xB2,
  37387. 0xAC, 0x1A, 0x79, 0x7F, 0x9D, 0xE5, 0xE8, 0xC6,
  37388. 0x40, 0x4B, 0xCE, 0x32, 0x4B, 0xA1, 0x3C, 0x77,
  37389. 0xED, 0x5D, 0x59, 0x0F, 0xE0, 0x7D, 0x00, 0x07,
  37390. 0xB4, 0xD8, 0xA6, 0x3E, 0xC9, 0x6D, 0x62, 0x19,
  37391. 0x66, 0xC3, 0xE7, 0x10, 0x3B, 0x6C, 0x7A, 0x36,
  37392. 0x49, 0x75, 0xE6, 0x78, 0xB3, 0x8D, 0x04, 0x13,
  37393. 0x31, 0xE6, 0x79, 0x72, 0x64, 0x07, 0x76, 0x94,
  37394. 0x2B, 0xB4, 0xEC, 0x18, 0x1C, 0x32, 0x3C, 0x26,
  37395. 0xC4, 0x81, 0xBF, 0x4F, 0xB5, 0x6E, 0x5D, 0x67,
  37396. 0xCF, 0xBE, 0x17, 0x57, 0x11, 0x2B, 0xBC, 0xA0,
  37397. 0xF0, 0xC2, 0x70, 0x06, 0x94, 0x26, 0x9B, 0x26,
  37398. 0x12, 0x9C, 0x7F, 0x99, 0xD4, 0x4A, 0xF5, 0x60,
  37399. 0xCD, 0xF7, 0xA4, 0x70, 0x2E, 0xF5, 0xD6, 0xA2,
  37400. 0xEC, 0x0E, 0x99, 0x00, 0x2E, 0x89, 0x30, 0xAA,
  37401. 0x4E, 0xC0, 0x62, 0x11, 0x93, 0x0A, 0x1E, 0x68,
  37402. 0xF2, 0xED, 0x44, 0x8B, 0x10, 0x4A, 0x75, 0x68,
  37403. 0xBF, 0x46, 0xE1, 0x41, 0xD6, 0x0B, 0x61, 0x53,
  37404. 0xD4, 0x03, 0x10, 0xB3, 0x8F, 0x8E, 0x14, 0x57,
  37405. 0x27, 0x8F, 0xE3, 0x49, 0xB2, 0xB4, 0xA7, 0xAE,
  37406. 0x39, 0x7A, 0x7B, 0x8F, 0x48, 0xAA, 0xA5, 0xFD,
  37407. 0xC1, 0x28, 0x8E, 0x43, 0xE0, 0x58, 0x39, 0x32,
  37408. 0x0A, 0x14, 0xC6, 0x3A, 0xB8, 0x58, 0xE2, 0x6E,
  37409. 0x7D, 0x8C, 0x35, 0xB6, 0x47, 0x37, 0x90, 0x4D,
  37410. 0x89, 0xC1, 0x9A, 0x10, 0x3D, 0x6B, 0x68, 0x9A,
  37411. 0x3D, 0xC9, 0x0C, 0x72, 0xFC, 0x92, 0xE3, 0x5D,
  37412. 0x45, 0x2B, 0x81, 0x43, 0x02, 0x30, 0x70, 0xD4,
  37413. 0x8B, 0xB9, 0xFB, 0xB0, 0x45, 0xE3, 0xC6, 0xCE,
  37414. 0x9A, 0x8B, 0xD5, 0xC4, 0xB6, 0x7F, 0x5D, 0x8B,
  37415. 0x58, 0xC9, 0x6A, 0x28, 0x2D, 0x6E, 0x27, 0x78,
  37416. 0x3D, 0x7B, 0x99, 0x0E, 0x05, 0x2B, 0xD9, 0x5E,
  37417. 0x86, 0x50, 0x8F, 0x9B, 0xF7, 0xC0, 0x64, 0xA8,
  37418. 0xF2, 0x39, 0xE0, 0x24, 0x0A, 0x20, 0xD8, 0xDF,
  37419. 0x3A, 0x87, 0x6E, 0xDC, 0x8F, 0xF6, 0x24, 0x1B,
  37420. 0x54, 0xF2, 0x70, 0xA9, 0x8C, 0xB8, 0x07, 0x7A,
  37421. 0xAF, 0xE0, 0xE5, 0x8E, 0x5E, 0x98, 0x13, 0xC6,
  37422. 0xA5, 0xF9, 0x1F, 0x52, 0x89, 0x7B, 0x6A, 0xAD,
  37423. 0x24, 0x26, 0xC6, 0x0D, 0xA5, 0x88, 0x3E, 0x6B,
  37424. 0xDF, 0xEE, 0x33, 0x0A, 0x86, 0x09, 0xA2, 0x11,
  37425. 0x8B, 0x69, 0x9F, 0x75, 0xCE, 0xFD, 0x05, 0x01,
  37426. 0x95, 0x14, 0x64, 0xCD, 0x62, 0x04, 0x09, 0x87,
  37427. 0xFC, 0xF6, 0xB2, 0x2E, 0xCA, 0x92, 0xE4, 0x4F,
  37428. 0x55, 0xB3, 0x8C, 0x64, 0x99, 0xA8, 0xDA, 0x0A,
  37429. 0xC7, 0x82, 0x56, 0x93, 0x03, 0x67, 0xA4, 0xD7,
  37430. 0x54, 0x91, 0xA0, 0x89, 0xD8, 0x94, 0x1F, 0x6C,
  37431. 0x53, 0xCC, 0xB2, 0x60, 0x13, 0x6A, 0x93, 0xE1,
  37432. 0xFC, 0xA3, 0xDD, 0x72, 0xD5, 0x5A, 0x92, 0x35,
  37433. 0x9E, 0x3D, 0x62, 0x82, 0x70, 0x5D, 0x54, 0xAF,
  37434. 0x57, 0xC6, 0x98, 0x5E, 0x74, 0xE0, 0xF2, 0x33,
  37435. 0x26, 0x61, 0xBF, 0x2B, 0xDD, 0x78, 0x47, 0x29,
  37436. 0x04, 0xC7, 0xF0, 0x58, 0x17, 0xFC, 0x9D, 0xED,
  37437. 0xEF, 0x15, 0x6A, 0xCA, 0xC7, 0x46, 0xCE, 0x12,
  37438. 0xF8, 0x90, 0xD8, 0x5A, 0x93, 0x98, 0xA9, 0xED,
  37439. 0xFB, 0xF4, 0x6E, 0x73, 0x48, 0x81, 0x4A, 0x08,
  37440. 0x07, 0x29, 0xC8, 0x3E, 0x70, 0x4C, 0x40, 0x30,
  37441. 0x20, 0x2C, 0xF6, 0x1E, 0xCD, 0xEE, 0x27, 0x95,
  37442. 0xD5, 0x07, 0xAC, 0x28, 0x81, 0x4F, 0x53, 0xCD,
  37443. 0x06, 0x60, 0xA5, 0x57, 0x2C, 0xBE, 0x1A, 0xE5,
  37444. 0x33, 0x38, 0xB8, 0xEF, 0xDC, 0xA3, 0x1A, 0xA5,
  37445. 0xB9, 0x5A, 0xA9, 0xE7, 0x65, 0xAF, 0x4D, 0xA0,
  37446. 0x4C, 0x9B, 0x31, 0x62, 0x67, 0x7E, 0x41, 0xC0,
  37447. 0x18, 0xA5, 0xE1, 0x8A, 0xF2, 0xF9, 0x8A, 0xCA,
  37448. 0x14, 0x5C, 0xCD, 0x1B, 0x8F, 0x74, 0x31, 0x07,
  37449. 0x6A, 0x14, 0xA7, 0xC2, 0x0F, 0x6C, 0x72, 0xE8,
  37450. 0xEB, 0x97, 0x51, 0xB7, 0x89, 0x2E, 0x41, 0x01,
  37451. 0x54, 0x47, 0x63, 0x0E, 0xAA, 0x84, 0xB9, 0x60,
  37452. 0x1C, 0xB9, 0x54, 0xD8, 0x97, 0x39, 0x38, 0x9D,
  37453. 0x52, 0xBB, 0x91, 0xA9, 0x7F, 0x96, 0x08, 0x7C,
  37454. 0xB3, 0x8B, 0x0E, 0xAB, 0x59, 0xA7, 0x84, 0x68,
  37455. 0x34, 0x65, 0x55, 0xC7, 0x12, 0x84, 0xC2, 0xFB,
  37456. 0xBD, 0x27, 0x58, 0x18, 0xE9, 0x26, 0x73, 0xFA,
  37457. 0x42, 0xAB, 0x5E, 0x0D, 0x97, 0x76, 0x67, 0xA9,
  37458. 0x0F, 0x75, 0x92, 0x6C, 0x80, 0x76, 0x87, 0x75,
  37459. 0xD2, 0x3D, 0xFE, 0x0B, 0x33, 0x7B, 0x48, 0xB0,
  37460. 0xC8, 0x28, 0x1F, 0xE6, 0x3F, 0x18, 0xF2, 0x45,
  37461. 0xF8, 0x8F, 0x21, 0xE1, 0x1C, 0x56, 0xA5, 0x33,
  37462. 0x71, 0x88, 0x42, 0x5A, 0x34, 0x8B, 0x24, 0xDD,
  37463. 0x0E, 0x98, 0x30, 0xDB, 0x6B, 0x6C, 0x89, 0x64,
  37464. 0x8C, 0x7A, 0x63, 0x3C, 0xA9, 0xD8, 0x32, 0x51,
  37465. 0xD0, 0xC6, 0xF7, 0xA4, 0x53, 0x95, 0x0D, 0x02,
  37466. 0x19, 0x6A, 0x77, 0xBC, 0xDF, 0xD5, 0x2B, 0x2C,
  37467. 0x65, 0xC9, 0xBF, 0x72, 0x69, 0xC3, 0x0C, 0xEF,
  37468. 0x34, 0x75, 0x76, 0x29, 0x59, 0xBE, 0x9D, 0xE9,
  37469. 0x44, 0x21, 0x2F, 0x5F, 0xB7, 0x89, 0xA6, 0xCD,
  37470. 0x0A, 0x9A, 0x9E, 0x77, 0x5B, 0xBD, 0xDA, 0x03,
  37471. 0xA4, 0xBC, 0xFB, 0x47, 0xC1, 0x77, 0x73, 0x00,
  37472. 0x26, 0xAE, 0x2E, 0xFA, 0x62, 0x18, 0x9D, 0xB8,
  37473. 0xE2, 0xD3, 0x7A, 0xB9, 0xD8, 0xCF, 0xE9, 0x61,
  37474. 0x11, 0x80, 0xE9, 0xDC, 0xC3, 0x32, 0x9E, 0x63,
  37475. 0x6F, 0xD9, 0x42, 0xF6, 0x76, 0x7F, 0xBC, 0xBF,
  37476. 0xDB, 0x08, 0x2F, 0xA0, 0xEB, 0xB8, 0x4D, 0xF3,
  37477. 0x76, 0x62, 0xAA, 0xFA, 0x20, 0x4A, 0xDD, 0xE6,
  37478. 0xB3, 0x72, 0xC7, 0x7D, 0x36, 0x4F, 0x08, 0x56,
  37479. 0x4F, 0x19, 0xB2, 0xB0, 0x0C, 0x13, 0x1A, 0x8C,
  37480. 0xCE, 0x9A, 0x04, 0xB5, 0xB6, 0x9C, 0xD3, 0xD8,
  37481. 0xFE, 0x1F, 0x2C, 0xCC, 0x89, 0xEE, 0x7D, 0x22,
  37482. 0x8A, 0x4E, 0x0A, 0x91, 0x0C, 0x8B, 0x5A, 0xE0,
  37483. 0xBD, 0xE5, 0x3D, 0xBE, 0x90, 0x4B, 0x13, 0xA3,
  37484. 0x2F, 0x33, 0xE9, 0x9D, 0x6C, 0x67, 0x35, 0xBD,
  37485. 0x03, 0xD4, 0x09, 0x90, 0x2F, 0xC6, 0x3C, 0x8D,
  37486. 0xD8, 0x43, 0xFC, 0x1F, 0xB7, 0x49, 0xC0, 0xB7,
  37487. 0x38, 0x70, 0x1D, 0xEB, 0x5A, 0xD7, 0xAC, 0x07,
  37488. 0xAF, 0x5B, 0x93, 0xC5, 0x7B, 0x55, 0x65, 0x86,
  37489. 0x6E, 0xC1, 0xDB, 0xCD, 0x42, 0x92, 0x50, 0xDB,
  37490. 0xD1, 0x97, 0x95, 0x3D, 0x53, 0xC3, 0xFE, 0xC2,
  37491. 0xF9, 0x65, 0xF3, 0xD2, 0xEE, 0xA4, 0x7E, 0xDE,
  37492. 0xA1, 0x4B, 0x23, 0x7F, 0xA1, 0x0D, 0x25, 0x6E,
  37493. 0x80, 0x4F, 0xE3, 0xB5, 0x0C, 0xBA, 0x1C, 0x2B,
  37494. 0x42, 0x0B, 0x8F, 0xD9, 0xB6, 0x4E, 0x52, 0xD2,
  37495. 0xDB, 0x35, 0xD2, 0xA1, 0xC4, 0xE6, 0xD6, 0x51,
  37496. 0x76, 0xE7, 0x87, 0x5E, 0xBE, 0x93, 0xE6, 0x61,
  37497. 0x71, 0x4C, 0x8B, 0xA6, 0x96, 0xDA, 0xF7, 0xCB,
  37498. 0x06, 0xB7, 0xB8, 0xC4, 0xF6, 0xF5, 0xC6, 0x29,
  37499. 0xAA, 0xE1, 0x13, 0x87, 0x6F, 0x96, 0xBA, 0x0C,
  37500. 0xF6, 0x79, 0x8F, 0x03, 0x86, 0x22, 0xE3, 0xFB,
  37501. 0xCF, 0x86, 0xCF, 0x7C, 0x77, 0xFD, 0xB4, 0xEE,
  37502. 0xBD, 0x42, 0x38, 0x7F, 0xF2, 0xCC, 0xCB, 0x06,
  37503. 0xEA, 0x0D, 0x81, 0xA1, 0x8E, 0xB5, 0xE7, 0x40,
  37504. 0xC8, 0x03, 0xA3, 0x4B, 0xC8, 0xB4, 0x0E, 0x3E,
  37505. 0x36, 0xAB, 0x90, 0xC1, 0xFC, 0xB0, 0x37, 0x2B,
  37506. 0x83, 0xA1, 0x3D, 0x56, 0xD6, 0x83, 0x0F, 0x99,
  37507. 0xC4, 0x58, 0xB8, 0x94, 0x61, 0x19, 0xA6, 0x60,
  37508. 0x47, 0xCB, 0x2D, 0xAF, 0x29, 0x38, 0x90, 0xFA,
  37509. 0x99, 0x0F, 0x02, 0x02, 0x65, 0x90, 0x5F, 0xA2,
  37510. 0xA2, 0xE3, 0xBB, 0x34, 0x15, 0x2F, 0x0B, 0xF5,
  37511. 0xB2, 0xCC, 0x83, 0x59, 0xAF, 0xA7, 0x4D, 0x38,
  37512. 0xAD, 0xF6, 0x52, 0x5C, 0x53, 0xD9, 0x0E, 0x3F,
  37513. 0xD6, 0x53, 0x86, 0xE2, 0x79, 0xC2, 0x65, 0x48,
  37514. 0xB2, 0x67, 0x3B, 0xAF, 0x52, 0x53, 0x57, 0x9A,
  37515. 0x27, 0x80, 0x88, 0x37, 0x77, 0x67, 0x4E, 0x1F,
  37516. 0xF1, 0x7B, 0xC5, 0xCB, 0xD8, 0x11, 0x0A, 0xDD,
  37517. 0x92, 0x0E, 0x88, 0x6C, 0xCA, 0x33, 0x76, 0x3B,
  37518. 0x04, 0xFA, 0xC0, 0xFD, 0xC6, 0x3F, 0xB4, 0x72,
  37519. 0xC2, 0x2B, 0x6D, 0x5E, 0xB6, 0xA1, 0x4E, 0x5F,
  37520. 0xC0, 0x50, 0x16, 0xEF, 0xFE, 0x6A, 0x42, 0x72,
  37521. 0x65, 0x02, 0xEE, 0x07, 0xC6, 0x19, 0xC6, 0x95,
  37522. 0xDE, 0x3F, 0xD9, 0xC5, 0xC6, 0x0E, 0x70, 0x07,
  37523. 0x6A, 0xC3, 0x36, 0x1B, 0x84, 0x6F, 0xDF, 0x80,
  37524. 0x16, 0x4E, 0x86, 0x90, 0xC8, 0x55, 0x7B, 0xDD,
  37525. 0xC0, 0x86, 0x0C, 0x37, 0x47, 0x1F, 0x35, 0xF8,
  37526. 0x47, 0xF2, 0xCD, 0x96, 0x21, 0x64, 0xAD, 0x46,
  37527. 0xE1, 0xDF, 0x44, 0x79, 0x48, 0x02, 0xF9, 0x71,
  37528. 0x39, 0x35, 0x26, 0xFC, 0x12, 0x0D, 0x88, 0xAC,
  37529. 0xD6, 0xFA, 0x29, 0x74, 0x55, 0x51, 0xE7, 0xAF,
  37530. 0x3D, 0x7E, 0x1E, 0x7E, 0xE0, 0x18, 0xB6, 0x3C,
  37531. 0x4B, 0x99, 0x9D, 0x51, 0x02, 0x51, 0xD8, 0xE9,
  37532. 0xFA, 0x61, 0x88, 0x2E, 0xCF, 0x73, 0x77, 0x65,
  37533. 0x71, 0xAE, 0xAE, 0xD7, 0xA1, 0xF9, 0xE0, 0x7F,
  37534. 0x30, 0x46, 0xCB, 0x20, 0xEC, 0xF4, 0xD2, 0xC1,
  37535. 0x63, 0xF5, 0x6F, 0x8A, 0x72, 0xF9, 0x5B, 0x85,
  37536. 0xD2, 0xCA, 0x6D, 0x35, 0xD1, 0x17, 0xF6, 0x08,
  37537. 0x9E, 0x0A, 0x73, 0xB3, 0xDA, 0x1A, 0x32, 0xBA,
  37538. 0x23, 0x10, 0x4A, 0x5D, 0xD7, 0xAA, 0xB4, 0x68,
  37539. 0x97, 0x59, 0x45, 0xC5, 0x7C, 0x16, 0x6F, 0xE4,
  37540. 0x62, 0x89, 0xF1, 0xD3, 0xB4, 0x03, 0x90, 0x7B,
  37541. 0xA4, 0xA2, 0xCA, 0xA0, 0x5D, 0x69, 0x1B, 0xA9,
  37542. 0xBB, 0xEB, 0xA0, 0xE2, 0xDE, 0xBE, 0x0E, 0xC4,
  37543. 0x9E, 0x21, 0x38, 0x61, 0x92, 0x9B, 0xAB, 0x69,
  37544. 0xAA, 0xD0, 0x1D, 0xF6, 0xC3, 0xEE, 0xA6, 0xC3,
  37545. 0xF3, 0x29, 0x1B, 0xE5, 0x6E, 0x52, 0x89, 0xD0,
  37546. 0xBA, 0xD8, 0x60, 0x27, 0x80, 0x1A, 0xB5, 0x7F,
  37547. 0x7F, 0xB5, 0xC2, 0x5A, 0xC6, 0x83, 0xA4, 0xC0,
  37548. 0x88, 0x39, 0xF3, 0xE7, 0x39, 0xD6, 0x81, 0x1C,
  37549. 0x13, 0x20, 0xFD, 0x93, 0x3D, 0x8E, 0x79, 0x60,
  37550. 0x7C, 0xFF, 0xE4, 0x37, 0x5B, 0x33, 0xA3, 0x9D,
  37551. 0xB7, 0x57, 0xCD, 0x45, 0x0A, 0xB9, 0xE4, 0xF1,
  37552. 0xBC, 0x59, 0x74, 0xE8, 0xB3, 0x06, 0xD0, 0x9F,
  37553. 0x0F, 0xBC, 0x5B, 0x23, 0xB8, 0x6C, 0xD6, 0x4D,
  37554. 0xFA, 0xCC, 0x14, 0xAB, 0x74, 0x61, 0x1A, 0xFC,
  37555. 0x22, 0xA6, 0xED, 0x09, 0x76, 0x91, 0xD8, 0x6E,
  37556. 0x44, 0xB6, 0x00, 0x14, 0xDC, 0x74, 0x2D, 0x90,
  37557. 0xAA, 0x59, 0x98, 0x76, 0x30, 0xC5, 0x44, 0xA4,
  37558. 0x61, 0x43, 0xD6, 0xE2, 0x28, 0x28, 0xA7, 0xBD,
  37559. 0x6E, 0x50, 0x5C, 0xE1, 0x96, 0x7A, 0xF8, 0xA8,
  37560. 0x32, 0x8C, 0xE9, 0xFD, 0x11, 0x37, 0x91, 0xD1,
  37561. 0xAF, 0x3C, 0xD3, 0x1C, 0x1E, 0x88, 0x4D, 0x7E,
  37562. 0x87, 0x84, 0x84, 0x6F, 0x39, 0x0B, 0xFB, 0x2D,
  37563. 0xB3, 0x12, 0x4C, 0x6D, 0x45, 0xDD, 0xCD, 0x7D,
  37564. 0x75, 0xB7, 0xFE, 0x7E, 0x44, 0xCC, 0x29, 0xE5,
  37565. 0xB3, 0x10, 0xEE, 0x23, 0x55, 0x5B, 0xCF, 0xBA,
  37566. 0xBD, 0xA1, 0xBE, 0x64, 0xF8, 0x6E, 0x60, 0x31,
  37567. 0x0A, 0x2D, 0xC9, 0x3B, 0x1D, 0x44, 0xE1, 0x9D,
  37568. 0x60, 0x28, 0x77, 0xEE
  37569. };
  37570. static const byte rnd_65[] = {
  37571. 0x4E, 0x7A, 0x01, 0x7C, 0x15, 0x03, 0x9D, 0xC2,
  37572. 0x00, 0x51, 0xD2, 0x96, 0x0E, 0x5E, 0x15, 0x59,
  37573. 0xCC, 0x27, 0xED, 0x46, 0x87, 0x7C, 0xB9, 0x81,
  37574. 0x16, 0x19, 0x9A, 0x0F, 0x41, 0x05, 0xFE, 0x32
  37575. };
  37576. static const byte sig_65[] = {
  37577. 0xB8, 0x65, 0xB0, 0x0B, 0x21, 0x18, 0xDB, 0xB0,
  37578. 0x0B, 0x70, 0x1C, 0x66, 0x45, 0x65, 0x5E, 0x8A,
  37579. 0xCF, 0xA8, 0x4E, 0xA7, 0x92, 0xB4, 0x48, 0x64,
  37580. 0x2E, 0x18, 0x32, 0xC3, 0x70, 0x7C, 0x87, 0xCF,
  37581. 0x09, 0xFB, 0xE7, 0x72, 0xF1, 0xD4, 0x38, 0x5B,
  37582. 0xFB, 0xE5, 0xE6, 0xCF, 0xBB, 0xE2, 0x6C, 0x10,
  37583. 0xED, 0x6E, 0xB8, 0x65, 0xC8, 0x87, 0xF8, 0x69,
  37584. 0x39, 0x43, 0x9A, 0x9B, 0xF7, 0x68, 0xBF, 0x03,
  37585. 0x9D, 0x73, 0xE3, 0xEA, 0x83, 0xBD, 0xF1, 0x85,
  37586. 0x03, 0xB5, 0xD1, 0xB3, 0x91, 0x79, 0xA8, 0x27,
  37587. 0xB0, 0xD7, 0x80, 0x5F, 0x98, 0x42, 0x8B, 0xD8,
  37588. 0x7C, 0xEA, 0x6B, 0x06, 0x96, 0x0C, 0x78, 0xB4,
  37589. 0xB5, 0x86, 0xFB, 0x0D, 0x5E, 0xDA, 0x9F, 0xAA,
  37590. 0xC0, 0x25, 0x6E, 0x38, 0x82, 0x35, 0x62, 0xA3,
  37591. 0x07, 0x96, 0x61, 0x17, 0x00, 0x5A, 0xA4, 0x2F,
  37592. 0x1B, 0x65, 0x54, 0xA0, 0x48, 0x75, 0xF8, 0x5C,
  37593. 0x2E, 0x3F, 0xAF, 0xA6, 0x52, 0x47, 0x1D, 0x4E,
  37594. 0x98, 0x06, 0x54, 0x82, 0xFC, 0x7D, 0xF4, 0x9B,
  37595. 0x2C, 0x40, 0xD0, 0xE7, 0xB9, 0x82, 0x38, 0xDF,
  37596. 0xBE, 0x85, 0x3D, 0x16, 0xBF, 0x99, 0x92, 0xBB,
  37597. 0x08, 0xC1, 0x92, 0x59, 0xF9, 0xB5, 0x75, 0xEA,
  37598. 0x7A, 0x4A, 0x80, 0x09, 0x3A, 0x64, 0xA9, 0x26,
  37599. 0x71, 0x85, 0x7A, 0x50, 0x89, 0x20, 0xD6, 0x0F,
  37600. 0xF6, 0xFB, 0xF3, 0x83, 0x41, 0xC5, 0x59, 0x01,
  37601. 0x05, 0x63, 0x3A, 0x42, 0x6D, 0x60, 0x2D, 0xAC,
  37602. 0x06, 0x4D, 0xD7, 0xA7, 0xF1, 0x1A, 0x60, 0x21,
  37603. 0x5C, 0x35, 0xB7, 0xB9, 0xC0, 0x0E, 0x9D, 0x84,
  37604. 0x63, 0x98, 0x8C, 0xF4, 0x72, 0xCD, 0x6A, 0xCF,
  37605. 0xB7, 0xF7, 0x22, 0xB8, 0xC4, 0xC6, 0x27, 0x02,
  37606. 0x60, 0x7A, 0x67, 0x48, 0x80, 0xAC, 0xB3, 0xD6,
  37607. 0xC6, 0x25, 0x3E, 0x71, 0x17, 0x5A, 0x05, 0xB3,
  37608. 0x92, 0xCA, 0xB4, 0xBB, 0x14, 0xCE, 0x86, 0xA5,
  37609. 0x98, 0xAB, 0xC7, 0x88, 0xD0, 0xFF, 0x4D, 0x82,
  37610. 0x77, 0x5E, 0x4E, 0xA0, 0xFC, 0x36, 0x36, 0x3C,
  37611. 0xD0, 0xE9, 0x7B, 0x78, 0xA6, 0xAE, 0x4D, 0xA8,
  37612. 0xE9, 0x8C, 0xA6, 0x12, 0x77, 0x2D, 0x56, 0xB5,
  37613. 0x82, 0xF8, 0x2C, 0x07, 0x09, 0xBE, 0xAE, 0x46,
  37614. 0x67, 0x3B, 0xDD, 0x80, 0x42, 0x86, 0x5C, 0xFA,
  37615. 0x95, 0xBF, 0x53, 0x38, 0xCF, 0xEA, 0x60, 0x6A,
  37616. 0x6E, 0xF3, 0x16, 0x38, 0x46, 0xAE, 0x83, 0xB2,
  37617. 0x5E, 0x5F, 0x5B, 0xD3, 0x1C, 0x83, 0xF1, 0x36,
  37618. 0x72, 0x9A, 0x8E, 0xA6, 0x27, 0x4F, 0x99, 0x4F,
  37619. 0xA9, 0x04, 0x5F, 0xA8, 0xA9, 0x0F, 0xF8, 0x54,
  37620. 0xB8, 0x71, 0xCF, 0x82, 0xE2, 0xB7, 0x01, 0xE8,
  37621. 0xF4, 0xAC, 0x04, 0xFE, 0x9E, 0x28, 0x49, 0x1B,
  37622. 0x9A, 0x25, 0xFF, 0x26, 0x3E, 0x2C, 0xF7, 0x54,
  37623. 0x99, 0xE0, 0x09, 0xFD, 0x02, 0x29, 0xFB, 0xF7,
  37624. 0xE5, 0xE4, 0x60, 0x44, 0x34, 0x4B, 0x07, 0xD7,
  37625. 0x22, 0x14, 0xA9, 0xAC, 0xB4, 0xFF, 0x61, 0x02,
  37626. 0xAB, 0xC1, 0x26, 0x2B, 0xC2, 0xE1, 0xCD, 0x24,
  37627. 0x91, 0x60, 0x7A, 0xE7, 0xAA, 0xEC, 0xF4, 0xC3,
  37628. 0x51, 0x75, 0xCF, 0xA4, 0x38, 0x3A, 0xA8, 0x6A,
  37629. 0xF1, 0xE6, 0x2E, 0xD0, 0x63, 0x87, 0xCC, 0x59,
  37630. 0x48, 0x36, 0x46, 0x7F, 0x41, 0xDF, 0xCA, 0x8F,
  37631. 0xA0, 0xCA, 0x71, 0x28, 0x0B, 0xFB, 0x1C, 0x25,
  37632. 0x60, 0xC8, 0x99, 0x55, 0x36, 0xF8, 0x42, 0x74,
  37633. 0x70, 0x45, 0x59, 0x14, 0x53, 0x74, 0x5F, 0x26,
  37634. 0x03, 0x82, 0xE3, 0xDA, 0x50, 0x79, 0x3F, 0xD7,
  37635. 0xCA, 0x76, 0x27, 0x18, 0x5D, 0xBD, 0xCE, 0xDD,
  37636. 0xF6, 0x9B, 0x2D, 0x3E, 0x15, 0x1C, 0x7F, 0x97,
  37637. 0x28, 0x8A, 0x38, 0x2A, 0x92, 0xB0, 0x50, 0xF7,
  37638. 0x91, 0xF9, 0x58, 0x7D, 0x77, 0xC6, 0x4D, 0x8B,
  37639. 0x5D, 0x40, 0xAA, 0x19, 0x9D, 0x49, 0x66, 0xBE,
  37640. 0x2D, 0x52, 0x4F, 0x96, 0x10, 0xF2, 0xFA, 0x02,
  37641. 0xED, 0x23, 0x17, 0x63, 0x69, 0xDB, 0x93, 0x93,
  37642. 0x50, 0xDA, 0x60, 0x1E, 0xA6, 0x67, 0x70, 0x95,
  37643. 0x2E, 0x0F, 0x23, 0xED, 0xA6, 0x8A, 0x73, 0x75,
  37644. 0x6E, 0xFF, 0x61, 0x0E, 0x8D, 0x6A, 0x9F, 0x49,
  37645. 0x34, 0x56, 0x58, 0x54, 0x42, 0x82, 0x45, 0x3B,
  37646. 0x5E, 0x73, 0xA3, 0x22, 0xA0, 0x32, 0x67, 0xC9,
  37647. 0x69, 0xB5, 0x07, 0x34, 0xF2, 0xEC, 0xD4, 0xEC,
  37648. 0x90, 0x55, 0x76, 0x0D, 0x92, 0x86, 0x10, 0xE9,
  37649. 0x4E, 0x0B, 0x16, 0x28, 0xD6, 0xAF, 0x1B, 0x27,
  37650. 0xAB, 0x13, 0x82, 0x9F, 0x7F, 0x8E, 0xF5, 0x0D,
  37651. 0x9E, 0x29, 0x96, 0xFC, 0x64, 0xB0, 0x6A, 0xC8,
  37652. 0x94, 0x61, 0x14, 0x76, 0x6D, 0xAD, 0x8D, 0xFF,
  37653. 0xE6, 0x34, 0xF4, 0x7E, 0x9D, 0x85, 0x69, 0x96,
  37654. 0x6C, 0x6F, 0x69, 0x68, 0x21, 0x8C, 0x5B, 0x86,
  37655. 0x33, 0x61, 0x1B, 0xF4, 0x2B, 0x4F, 0xC0, 0xE7,
  37656. 0x8D, 0x0C, 0x02, 0x9E, 0xAB, 0x85, 0xF2, 0x2F,
  37657. 0x16, 0x17, 0x19, 0x80, 0xCC, 0x65, 0xF2, 0x84,
  37658. 0x45, 0xA1, 0x1A, 0x08, 0x3A, 0xA0, 0x29, 0x77,
  37659. 0xC2, 0xE8, 0x88, 0x6E, 0xD2, 0x70, 0x67, 0x2E,
  37660. 0x51, 0x2A, 0xE8, 0x9C, 0x6A, 0x26, 0xFC, 0xAD,
  37661. 0x1E, 0xC7, 0x2B, 0x9E, 0xCF, 0xA5, 0xA5, 0xEF,
  37662. 0xC7, 0x0F, 0xF0, 0xBA, 0xB2, 0x8F, 0x11, 0x4F,
  37663. 0x4D, 0xA8, 0x17, 0x0F, 0xE8, 0xB6, 0x3C, 0x2E,
  37664. 0x11, 0xBE, 0x7A, 0x35, 0x46, 0x6E, 0x97, 0x9A,
  37665. 0x12, 0x7E, 0xC0, 0xD2, 0x03, 0x23, 0xD5, 0x02,
  37666. 0x73, 0x0A, 0xBC, 0xE6, 0x40, 0xA2, 0x44, 0x1C,
  37667. 0xDD, 0xAB, 0xA3, 0x26, 0xD6, 0x78, 0x3D, 0x01,
  37668. 0x92, 0xDB, 0xA9, 0xE9, 0x3F, 0xE5, 0x07, 0xC6,
  37669. 0xA7, 0x37, 0x67, 0xBE, 0x56, 0xE2, 0x77, 0x65,
  37670. 0x76, 0xEF, 0xEF, 0xF1, 0xCA, 0x17, 0x9D, 0x83,
  37671. 0x34, 0x3E, 0x38, 0xC6, 0xA9, 0xC2, 0xFE, 0x72,
  37672. 0x5D, 0xDE, 0x80, 0x7D, 0x21, 0x72, 0x5E, 0x73,
  37673. 0x08, 0x72, 0xE2, 0xAB, 0x3D, 0x90, 0x11, 0x61,
  37674. 0xF4, 0x55, 0xBC, 0xAD, 0x23, 0xA8, 0x43, 0x3A,
  37675. 0x41, 0x31, 0x51, 0xFD, 0x22, 0x17, 0x14, 0x31,
  37676. 0x0E, 0x4D, 0x0B, 0x6A, 0x1E, 0x1B, 0x2C, 0xAC,
  37677. 0xA4, 0x99, 0xEE, 0xE8, 0x05, 0xA1, 0x64, 0xF2,
  37678. 0x91, 0xD5, 0x07, 0x5E, 0x6B, 0x65, 0xA7, 0x9C,
  37679. 0x2B, 0xCA, 0xD9, 0x17, 0xB1, 0x22, 0xFE, 0x1A,
  37680. 0xC4, 0xFB, 0xB4, 0x10, 0x21, 0x1B, 0xA0, 0xA1,
  37681. 0x99, 0x7A, 0x31, 0x30, 0x7C, 0x01, 0xF0, 0xFE,
  37682. 0xD3, 0xB3, 0x14, 0x3D, 0x28, 0x34, 0x0F, 0xAC,
  37683. 0xF0, 0x93, 0x37, 0xC4, 0xEF, 0x04, 0x74, 0x80,
  37684. 0xA2, 0x90, 0xAE, 0x02, 0xB2, 0xF7, 0xD8, 0x7B,
  37685. 0x8C, 0x29, 0xA0, 0xAE, 0xAE, 0x2E, 0x92, 0xC9,
  37686. 0xC5, 0x44, 0x7D, 0x66, 0xC5, 0x5C, 0x1D, 0x1E,
  37687. 0x25, 0x88, 0x5D, 0x10, 0x37, 0xFB, 0x5F, 0xCC,
  37688. 0x80, 0x15, 0x4F, 0x1D, 0x23, 0xB4, 0xF2, 0x7B,
  37689. 0x5B, 0xAC, 0x89, 0xBE, 0x1C, 0x36, 0x3C, 0xFF,
  37690. 0x8E, 0xA7, 0x58, 0x73, 0xAC, 0x3F, 0x63, 0x33,
  37691. 0xE8, 0x6C, 0x53, 0xEC, 0xA5, 0x5D, 0xBE, 0xD5,
  37692. 0xE1, 0xF1, 0x12, 0x6B, 0x12, 0x78, 0xC7, 0x29,
  37693. 0xC9, 0xA8, 0x4C, 0x4A, 0x1B, 0x7F, 0x15, 0x11,
  37694. 0x93, 0x01, 0xC8, 0x0B, 0xE2, 0x2F, 0xE9, 0xBE,
  37695. 0xBA, 0x17, 0x59, 0x45, 0xB2, 0x61, 0x2B, 0x66,
  37696. 0xDD, 0xCE, 0xDF, 0x9A, 0x2A, 0x4D, 0x5F, 0x24,
  37697. 0xF9, 0x02, 0xBB, 0xA6, 0x8D, 0xA7, 0x5D, 0x95,
  37698. 0x97, 0x2E, 0x28, 0xD6, 0xCB, 0x70, 0x17, 0xCA,
  37699. 0x51, 0xED, 0x58, 0x73, 0xAB, 0x03, 0xDD, 0x2E,
  37700. 0x92, 0x6C, 0x15, 0x64, 0x2C, 0x9D, 0x6E, 0x64,
  37701. 0x27, 0xFC, 0xE8, 0x0F, 0xC3, 0x8B, 0x34, 0xFE,
  37702. 0xB3, 0xC1, 0x55, 0x13, 0xA6, 0x87, 0xC3, 0x5B,
  37703. 0x94, 0xEB, 0x83, 0xE4, 0xAB, 0x3E, 0x18, 0x76,
  37704. 0x67, 0x92, 0x70, 0xF5, 0xA9, 0x8F, 0x18, 0xA6,
  37705. 0x5F, 0x57, 0x41, 0x76, 0x55, 0xFD, 0xA9, 0x99,
  37706. 0x4E, 0x8F, 0xCC, 0x61, 0x6C, 0x6C, 0x60, 0x06,
  37707. 0x10, 0x40, 0x26, 0xD6, 0xCD, 0x7A, 0xA0, 0x56,
  37708. 0x3D, 0x51, 0x07, 0x25, 0x76, 0x00, 0x05, 0xF5,
  37709. 0xFD, 0x39, 0xE7, 0x59, 0x24, 0x90, 0x29, 0xF0,
  37710. 0x3D, 0x9F, 0x00, 0x67, 0x10, 0x3F, 0xA0, 0x45,
  37711. 0x21, 0x14, 0xDF, 0x24, 0x40, 0xE8, 0xC6, 0xDB,
  37712. 0x65, 0xE2, 0x39, 0x56, 0xEB, 0x1B, 0xEE, 0xB2,
  37713. 0xC3, 0x4E, 0x5B, 0x20, 0xAC, 0x31, 0x6A, 0x03,
  37714. 0xA9, 0x54, 0x36, 0x66, 0x62, 0x68, 0xC3, 0xD8,
  37715. 0x22, 0x8F, 0x62, 0xEB, 0x56, 0x67, 0xB3, 0xB6,
  37716. 0xBB, 0x85, 0x7D, 0xD0, 0x73, 0x7B, 0x69, 0x05,
  37717. 0x1E, 0x9F, 0x26, 0xEE, 0x02, 0x36, 0x71, 0xCE,
  37718. 0xAD, 0xFA, 0xCA, 0xF9, 0x49, 0x7F, 0x1A, 0xDE,
  37719. 0x58, 0x7A, 0x69, 0x3E, 0xEF, 0xFB, 0xFC, 0xD5,
  37720. 0x50, 0xEC, 0x20, 0x8C, 0x23, 0x56, 0x91, 0xE8,
  37721. 0xE3, 0x66, 0xD9, 0x65, 0xB6, 0x2B, 0xEC, 0x16,
  37722. 0xA6, 0x61, 0xCD, 0x5D, 0xE2, 0x87, 0x93, 0x22,
  37723. 0x0D, 0x66, 0xF2, 0x64, 0x55, 0x05, 0xB8, 0x52,
  37724. 0x41, 0x2F, 0xAE, 0x7B, 0x9D, 0x98, 0x29, 0xBF,
  37725. 0x61, 0x5F, 0x7C, 0xBD, 0x59, 0xA7, 0xBC, 0x1D,
  37726. 0x03, 0x4E, 0x6A, 0x25, 0x52, 0x9C, 0xFB, 0x48,
  37727. 0x6A, 0xF2, 0x01, 0xDE, 0xB7, 0xEA, 0x95, 0xBA,
  37728. 0x70, 0x8A, 0x31, 0x59, 0x17, 0x16, 0x74, 0x34,
  37729. 0x53, 0x09, 0xDB, 0x81, 0x50, 0xE6, 0x7E, 0xBB,
  37730. 0x30, 0xA7, 0xFF, 0x80, 0xCA, 0xC9, 0xAB, 0x13,
  37731. 0x92, 0x50, 0x0A, 0x83, 0xE6, 0x3B, 0xBF, 0x7C,
  37732. 0x42, 0xEB, 0x94, 0x53, 0xC2, 0xC9, 0xAC, 0xDA,
  37733. 0x02, 0xBE, 0x53, 0x82, 0x34, 0xAA, 0xA7, 0xDB,
  37734. 0x5A, 0x7F, 0x58, 0x8F, 0xC9, 0x1B, 0x90, 0xEE,
  37735. 0x24, 0x77, 0xF2, 0xB6, 0x1C, 0xD1, 0x06, 0x2A,
  37736. 0x7E, 0xF1, 0xE6, 0xE4, 0xDC, 0x54, 0xB3, 0x6D,
  37737. 0x0E, 0x19, 0x93, 0x3E, 0x98, 0x1C, 0xB7, 0x63,
  37738. 0xA9, 0xE1, 0x07, 0xE0, 0x1D, 0xA9, 0x42, 0x0F,
  37739. 0x82, 0xCA, 0x79, 0x35, 0x92, 0xA4, 0x7C, 0x4B,
  37740. 0x97, 0x7F, 0xF2, 0xC8, 0x84, 0x98, 0xDA, 0x95,
  37741. 0xC4, 0x3D, 0x23, 0x2F, 0x42, 0xAF, 0x99, 0x48,
  37742. 0x0B, 0xF0, 0xA4, 0xF8, 0xB7, 0xC4, 0x94, 0x9D,
  37743. 0x1A, 0xE1, 0xD4, 0xFA, 0x8E, 0x1D, 0x1A, 0x8C,
  37744. 0xD0, 0xF9, 0xED, 0x00, 0xDA, 0x59, 0x5E, 0xFD,
  37745. 0x2B, 0x76, 0x6F, 0x0B, 0x79, 0xD4, 0x49, 0x0D,
  37746. 0xB9, 0x28, 0xEC, 0x44, 0xB5, 0x03, 0x0A, 0x74,
  37747. 0xCA, 0x42, 0x81, 0x1A, 0x5B, 0x5A, 0xE5, 0x22,
  37748. 0xC7, 0x76, 0x4D, 0xDF, 0xD9, 0xFD, 0x92, 0xF0,
  37749. 0x06, 0xE9, 0x4B, 0x35, 0xA7, 0xEF, 0x01, 0x42,
  37750. 0xDA, 0x71, 0x78, 0xC2, 0xF5, 0x30, 0x74, 0xD0,
  37751. 0x74, 0x51, 0xB1, 0x55, 0x65, 0xA9, 0xE0, 0xC5,
  37752. 0x7E, 0xA1, 0xB9, 0x4C, 0x88, 0xEA, 0xE7, 0x41,
  37753. 0xB1, 0xF5, 0x01, 0xC4, 0xD3, 0x70, 0x72, 0x7D,
  37754. 0xAD, 0x27, 0x65, 0xF7, 0x95, 0xAD, 0x41, 0x46,
  37755. 0x35, 0x80, 0x0E, 0xC1, 0x94, 0x9D, 0x03, 0x71,
  37756. 0x39, 0xDE, 0x26, 0xAF, 0xCF, 0x93, 0x3D, 0x9A,
  37757. 0x09, 0xC1, 0x27, 0xFC, 0x6B, 0x36, 0xE5, 0x18,
  37758. 0xC6, 0xDE, 0x94, 0x92, 0xBA, 0x70, 0x82, 0x7B,
  37759. 0x68, 0x1C, 0x2D, 0x18, 0xA4, 0x01, 0x23, 0xB6,
  37760. 0xC5, 0xF6, 0x17, 0x37, 0xCB, 0x9D, 0xC6, 0xAA,
  37761. 0x9C, 0xE1, 0x7D, 0x16, 0x8E, 0xBB, 0xDD, 0xD6,
  37762. 0x3C, 0x07, 0x60, 0x19, 0x3C, 0x97, 0x49, 0x33,
  37763. 0xDB, 0x47, 0x4A, 0xA8, 0x9A, 0xF3, 0x0E, 0x16,
  37764. 0x29, 0x38, 0xF6, 0xDB, 0x78, 0x65, 0xDE, 0x23,
  37765. 0x1F, 0x86, 0x16, 0x9C, 0x9E, 0x2A, 0x30, 0x2F,
  37766. 0xC4, 0x1F, 0x1B, 0xE5, 0xF3, 0x6C, 0x55, 0x83,
  37767. 0xFC, 0xD9, 0x1E, 0x21, 0xCB, 0x8A, 0x67, 0x57,
  37768. 0xD3, 0x0A, 0x4B, 0xAC, 0xDB, 0x67, 0xE7, 0xA6,
  37769. 0x1B, 0x0C, 0x8E, 0x21, 0x7E, 0x0C, 0xCB, 0xF5,
  37770. 0x0E, 0xA6, 0x42, 0xCD, 0xE3, 0xFC, 0x74, 0xC7,
  37771. 0xF9, 0xFF, 0xBD, 0xA9, 0xA1, 0xE6, 0x84, 0xBB,
  37772. 0xC9, 0xA8, 0xF7, 0xCD, 0x3F, 0x1B, 0xD0, 0xDB,
  37773. 0x63, 0xDD, 0xDF, 0x4E, 0xA4, 0x79, 0xC2, 0x35,
  37774. 0x65, 0x2C, 0x5D, 0xCB, 0xCA, 0x7B, 0xDD, 0x4E,
  37775. 0x2F, 0x33, 0xE8, 0x71, 0x72, 0xC1, 0x8B, 0x5F,
  37776. 0xF3, 0x90, 0x99, 0x40, 0x8D, 0x27, 0x2F, 0xD0,
  37777. 0xFB, 0x0D, 0x6A, 0x23, 0xB1, 0x43, 0x00, 0xDF,
  37778. 0xC6, 0x4C, 0x02, 0x74, 0x3E, 0x52, 0x36, 0x08,
  37779. 0xE9, 0x73, 0x61, 0x3D, 0xCA, 0xAC, 0x9D, 0x1D,
  37780. 0x14, 0xB3, 0xA6, 0x24, 0x0E, 0xC2, 0xF2, 0x29,
  37781. 0x39, 0x91, 0xF6, 0x90, 0x6A, 0xE3, 0x6C, 0x04,
  37782. 0x69, 0xF3, 0x09, 0x11, 0x34, 0x8E, 0xC1, 0x2D,
  37783. 0xDB, 0xA6, 0xC3, 0xCA, 0x19, 0xBC, 0x69, 0x5F,
  37784. 0xCD, 0x16, 0xE5, 0xAE, 0xF2, 0xAD, 0x7C, 0x73,
  37785. 0x25, 0x15, 0x70, 0xB5, 0xD0, 0x49, 0xA6, 0xC3,
  37786. 0xA5, 0x2F, 0xA3, 0xFC, 0x9E, 0xD5, 0x4E, 0x54,
  37787. 0x97, 0x3A, 0xE7, 0x89, 0xB0, 0xBF, 0xD6, 0xF8,
  37788. 0xCC, 0x26, 0x44, 0xA9, 0xF8, 0x5A, 0xCE, 0x06,
  37789. 0x78, 0xD8, 0x9E, 0xFC, 0x12, 0xB6, 0x11, 0xC3,
  37790. 0xDF, 0xAE, 0x3F, 0x94, 0x50, 0x34, 0xB8, 0x99,
  37791. 0xBE, 0x99, 0xA7, 0x32, 0x88, 0x9F, 0x17, 0xD2,
  37792. 0x08, 0xDC, 0xD7, 0xEE, 0x95, 0x9D, 0x1A, 0xC7,
  37793. 0x61, 0xDB, 0xA4, 0x86, 0x4C, 0x14, 0xB0, 0xA3,
  37794. 0x5E, 0x4C, 0x7B, 0xBD, 0xA0, 0x96, 0xFB, 0x8A,
  37795. 0xB3, 0x22, 0x69, 0x26, 0xC8, 0x9E, 0x7C, 0xDA,
  37796. 0x92, 0x9E, 0xF1, 0x30, 0xC6, 0x92, 0xC9, 0x26,
  37797. 0x59, 0xE6, 0xF4, 0x65, 0x2B, 0xF2, 0x15, 0x63,
  37798. 0x61, 0xC7, 0x7D, 0xBE, 0xEF, 0x5A, 0x06, 0x23,
  37799. 0xA0, 0x67, 0x04, 0x99, 0x0E, 0x19, 0x8A, 0x13,
  37800. 0x67, 0x30, 0x54, 0x32, 0x4B, 0xBB, 0xAA, 0x64,
  37801. 0x36, 0x92, 0xF2, 0x43, 0xD6, 0x7C, 0x1B, 0x4F,
  37802. 0x95, 0xB9, 0x28, 0xAC, 0xF1, 0x68, 0x6F, 0x60,
  37803. 0xC1, 0x44, 0x87, 0xD6, 0xDD, 0x7F, 0x88, 0x01,
  37804. 0xEF, 0x20, 0x93, 0x9E, 0x03, 0xA1, 0xCA, 0x7D,
  37805. 0x74, 0x32, 0xDC, 0xF5, 0x95, 0xF1, 0xE9, 0xED,
  37806. 0xF2, 0xB2, 0x93, 0x57, 0xA1, 0xD4, 0xC7, 0xDA,
  37807. 0x33, 0x51, 0x2C, 0x45, 0x1A, 0x7C, 0x66, 0x04,
  37808. 0x38, 0x2D, 0x90, 0xC3, 0x30, 0x79, 0xD9, 0x57,
  37809. 0x38, 0xE4, 0x71, 0x89, 0xD8, 0x54, 0x9E, 0x43,
  37810. 0xD2, 0x94, 0xE7, 0x3D, 0x1C, 0xA7, 0x48, 0x7B,
  37811. 0x50, 0xD0, 0xED, 0x7C, 0xC6, 0xF9, 0x6B, 0xEE,
  37812. 0xA7, 0x6C, 0xCE, 0xB9, 0x6D, 0x37, 0x92, 0x00,
  37813. 0x4E, 0xB3, 0xE5, 0x49, 0x16, 0x35, 0xA6, 0x7F,
  37814. 0x6F, 0xFA, 0x1F, 0x1D, 0xF6, 0xA1, 0xF2, 0xFD,
  37815. 0xEE, 0x77, 0x84, 0x17, 0x80, 0xAE, 0x08, 0x09,
  37816. 0xD2, 0x92, 0xED, 0x7B, 0x00, 0xF4, 0x2D, 0x80,
  37817. 0x91, 0x19, 0x09, 0xB5, 0x1C, 0x9A, 0x3A, 0xE5,
  37818. 0x4B, 0x7A, 0x6D, 0x7D, 0x29, 0xD2, 0x00, 0x05,
  37819. 0x22, 0xD4, 0xF8, 0x76, 0xE2, 0x5C, 0x0D, 0x6A,
  37820. 0x15, 0x77, 0x22, 0x18, 0x85, 0xFD, 0x30, 0x74,
  37821. 0xF3, 0x3B, 0xDC, 0xD9, 0x6C, 0xDE, 0x80, 0x40,
  37822. 0x4A, 0x37, 0xE1, 0x60, 0x9F, 0x26, 0xCF, 0xBE,
  37823. 0x24, 0xA1, 0xFB, 0xF9, 0x76, 0x2A, 0x1A, 0x23,
  37824. 0x32, 0xE7, 0xA2, 0xD8, 0x2D, 0xF9, 0xD2, 0x0F,
  37825. 0x08, 0x3A, 0xDB, 0x35, 0x35, 0x33, 0x59, 0x0B,
  37826. 0xB1, 0xF9, 0x54, 0x33, 0x49, 0x36, 0x9E, 0x21,
  37827. 0xEC, 0xF5, 0x94, 0xE2, 0x78, 0x07, 0xA5, 0x63,
  37828. 0x50, 0xD6, 0x23, 0x84, 0xDE, 0xAD, 0xA7, 0x89,
  37829. 0xBE, 0x92, 0xF0, 0x12, 0xC1, 0xF8, 0xA7, 0x2D,
  37830. 0x8B, 0xE0, 0x79, 0xF8, 0xD7, 0xBD, 0x04, 0x0B,
  37831. 0xC5, 0xF2, 0x23, 0x36, 0x11, 0x6D, 0x6F, 0x37,
  37832. 0xDB, 0xFB, 0xD2, 0xC7, 0x44, 0xC3, 0xAE, 0x78,
  37833. 0xEC, 0xB4, 0xE0, 0x5A, 0x55, 0xB3, 0xFC, 0xC3,
  37834. 0x1B, 0x8C, 0xA6, 0xDB, 0xE8, 0x95, 0x72, 0x44,
  37835. 0x90, 0x8F, 0x4E, 0xD1, 0xD3, 0x46, 0x6C, 0x9E,
  37836. 0x00, 0xC6, 0xCC, 0xAE, 0xFC, 0x95, 0x4D, 0x85,
  37837. 0x7C, 0x65, 0x5F, 0x74, 0x71, 0xE3, 0x80, 0x88,
  37838. 0xCF, 0x1E, 0xB8, 0xBE, 0xED, 0x8D, 0xC4, 0xFB,
  37839. 0x3E, 0x36, 0xF3, 0xB8, 0x42, 0x1F, 0x37, 0x31,
  37840. 0x8D, 0xA2, 0x35, 0x36, 0x9E, 0x92, 0x3D, 0xD8,
  37841. 0xEA, 0xA7, 0xA2, 0x29, 0x0E, 0x14, 0xBF, 0x59,
  37842. 0x1E, 0x1D, 0x98, 0x27, 0x30, 0x3B, 0xF3, 0x57,
  37843. 0x69, 0x75, 0xCC, 0x3A, 0xB3, 0x49, 0x99, 0x70,
  37844. 0x19, 0x50, 0xAB, 0xF6, 0x7F, 0xF6, 0x55, 0x1A,
  37845. 0xCA, 0x2D, 0xA0, 0x73, 0x50, 0xE0, 0x9C, 0xEE,
  37846. 0x07, 0xEC, 0x37, 0x26, 0x6B, 0xAA, 0xA5, 0x34,
  37847. 0xFD, 0x7B, 0x1A, 0x92, 0x4E, 0xE7, 0x36, 0x1A,
  37848. 0xEB, 0x35, 0xCC, 0x5A, 0x5C, 0x06, 0x7F, 0x77,
  37849. 0xCE, 0x52, 0x33, 0x57, 0x73, 0x9D, 0xEC, 0x2D,
  37850. 0x28, 0x0C, 0xC9, 0xBF, 0x06, 0x9E, 0xA7, 0x7C,
  37851. 0x36, 0xF9, 0x0B, 0xC6, 0x7F, 0x0F, 0x66, 0x24,
  37852. 0x65, 0x2D, 0x30, 0x2B, 0xD7, 0x7F, 0x07, 0xD3,
  37853. 0x57, 0xC8, 0x4B, 0xC3, 0x0C, 0xA3, 0x5B, 0xAA,
  37854. 0xAF, 0xEA, 0xF3, 0xA3, 0x9E, 0x9E, 0xD4, 0x63,
  37855. 0xCD, 0x82, 0x8B, 0xBC, 0x5D, 0xEF, 0xE6, 0x2A,
  37856. 0x4D, 0x5B, 0x95, 0x13, 0x17, 0x98, 0xD3, 0x67,
  37857. 0x66, 0x04, 0x9E, 0x71, 0x71, 0xE6, 0xBD, 0x44,
  37858. 0x15, 0x6B, 0x29, 0x76, 0xE4, 0x62, 0x01, 0x99,
  37859. 0xEB, 0xF4, 0x2E, 0x14, 0x29, 0x0D, 0xBF, 0x8A,
  37860. 0x02, 0x30, 0x4A, 0xE7, 0x0D, 0x25, 0x42, 0x9E,
  37861. 0xD7, 0x0C, 0xAD, 0x30, 0xC6, 0xA3, 0x49, 0xF9,
  37862. 0x90, 0x0C, 0x46, 0x5B, 0x77, 0x67, 0x5F, 0x0B,
  37863. 0xE9, 0xA9, 0xFE, 0xFA, 0xC8, 0x5F, 0x19, 0xF7,
  37864. 0x35, 0x09, 0xF7, 0xB5, 0x6D, 0x51, 0x32, 0x17,
  37865. 0xBE, 0xE6, 0xC3, 0xBE, 0x4A, 0x9A, 0x33, 0xDA,
  37866. 0xC6, 0x90, 0xB7, 0xA7, 0x6F, 0x97, 0x9E, 0xD5,
  37867. 0x80, 0xE5, 0x02, 0x9E, 0x58, 0xD6, 0x45, 0x34,
  37868. 0x4D, 0x61, 0x71, 0x19, 0x07, 0x69, 0x1F, 0xAF,
  37869. 0xFF, 0x9F, 0xDE, 0x97, 0x13, 0xA1, 0xDF, 0x47,
  37870. 0x0E, 0x8B, 0xD6, 0xD0, 0x75, 0x40, 0x08, 0x59,
  37871. 0x7D, 0xFB, 0x74, 0x74, 0xF2, 0x48, 0xF4, 0x23,
  37872. 0x1B, 0x5E, 0x18, 0x4E, 0x2D, 0x2D, 0xC5, 0x40,
  37873. 0xD0, 0x90, 0x4F, 0x95, 0x69, 0xC4, 0xDA, 0xFB,
  37874. 0x39, 0x4B, 0x12, 0x7D, 0x22, 0x1E, 0x9A, 0x68,
  37875. 0x5B, 0x68, 0x2E, 0x47, 0x23, 0xB9, 0x6A, 0xBF,
  37876. 0xF7, 0xE2, 0x56, 0x79, 0xDD, 0x7A, 0x72, 0xF9,
  37877. 0x5F, 0x20, 0x6B, 0x29, 0x56, 0xEE, 0x04, 0x11,
  37878. 0x4C, 0x16, 0x34, 0x04, 0x14, 0x54, 0xB5, 0x21,
  37879. 0xAA, 0x6A, 0x46, 0x40, 0xE4, 0xF1, 0x78, 0x7C,
  37880. 0x50, 0xF3, 0x4D, 0xBC, 0x57, 0x34, 0x7C, 0x6A,
  37881. 0xBD, 0x9B, 0xEF, 0x03, 0x80, 0x7D, 0xAB, 0x20,
  37882. 0x0F, 0x77, 0x87, 0x6F, 0x93, 0xFB, 0x24, 0x20,
  37883. 0x82, 0xC7, 0x7E, 0xFB, 0x43, 0x2D, 0xC6, 0xD4,
  37884. 0xE9, 0x27, 0x8C, 0x66, 0xA8, 0x5A, 0x58, 0xC8,
  37885. 0xD8, 0x9A, 0xA8, 0x50, 0x5F, 0x3A, 0x3D, 0x0B,
  37886. 0xC3, 0x4F, 0xCE, 0x94, 0xE0, 0x0D, 0x16, 0xCB,
  37887. 0x20, 0xE0, 0xF5, 0x1A, 0x13, 0x6E, 0x28, 0xA6,
  37888. 0x42, 0xB2, 0xB1, 0x30, 0x1D, 0x56, 0x28, 0xCD,
  37889. 0xF3, 0x4E, 0xA7, 0x3E, 0x74, 0x04, 0x7D, 0xA5,
  37890. 0x86, 0xD9, 0x1A, 0xDF, 0x07, 0xBC, 0x2C, 0x59,
  37891. 0xB1, 0x91, 0x6D, 0x9B, 0xA2, 0xD0, 0x72, 0xE7,
  37892. 0xA5, 0x56, 0x4A, 0x27, 0x56, 0x1F, 0x65, 0xCD,
  37893. 0x90, 0x7B, 0xB7, 0x5A, 0x51, 0x25, 0x75, 0x1B,
  37894. 0xD9, 0xD4, 0xC7, 0x19, 0x8A, 0xB0, 0x3D, 0x38,
  37895. 0x22, 0x61, 0xCF, 0xD9, 0x66, 0xED, 0xF5, 0xB8,
  37896. 0xF5, 0x86, 0xFF, 0x98, 0x1A, 0xB7, 0xFB, 0x67,
  37897. 0xED, 0x25, 0x52, 0xD9, 0x2F, 0x84, 0xDC, 0x96,
  37898. 0x89, 0x2C, 0x52, 0xCF, 0x5F, 0xA0, 0xEA, 0xD0,
  37899. 0xB3, 0x38, 0x98, 0xFC, 0xD7, 0x50, 0x84, 0xCF,
  37900. 0xA5, 0xE9, 0x53, 0x8B, 0x44, 0x38, 0xB5, 0x7D,
  37901. 0xD8, 0xAD, 0x0A, 0xE5, 0x35, 0x78, 0x29, 0xBF,
  37902. 0x9F, 0x6B, 0x2C, 0xBB, 0x97, 0x9D, 0xD3, 0x64,
  37903. 0x23, 0x2B, 0xA8, 0xA4, 0x71, 0xE3, 0xF1, 0x2F,
  37904. 0x61, 0xC9, 0x68, 0xD2, 0x06, 0xD0, 0x4E, 0x87,
  37905. 0x03, 0x99, 0xCC, 0xB1, 0x83, 0xB6, 0x94, 0x61,
  37906. 0x3C, 0xE9, 0xE0, 0x7D, 0x13, 0xAF, 0xCF, 0xE4,
  37907. 0xA6, 0x42, 0x7F, 0x62, 0x8F, 0xFC, 0x10, 0xF1,
  37908. 0x08, 0x4D, 0x1D, 0xFC, 0x0F, 0x37, 0x11, 0xBE,
  37909. 0xD7, 0xF1, 0x80, 0x46, 0xAF, 0xFA, 0x13, 0x65,
  37910. 0x99, 0xAE, 0xF9, 0xD0, 0x13, 0xA7, 0xC7, 0x3A,
  37911. 0xD2, 0xC1, 0x9B, 0x5A, 0xB8, 0xC3, 0x08, 0x13,
  37912. 0x49, 0x40, 0x33, 0x0D, 0x1F, 0x93, 0x5D, 0x10,
  37913. 0x49, 0x3E, 0x4F, 0x90, 0x34, 0xC5, 0xEA, 0xF7,
  37914. 0x24, 0xFF, 0xF3, 0xC5, 0x95, 0xF7, 0x1F, 0x13,
  37915. 0x9A, 0xE0, 0x0C, 0xCD, 0x61, 0x93, 0x39, 0xE6,
  37916. 0xAF, 0xD5, 0x3E, 0xA9, 0xD8, 0xC4, 0x8F, 0x64,
  37917. 0x05, 0x09, 0x45, 0x2A, 0xEB, 0x12, 0xC5, 0x51,
  37918. 0x58, 0x1C, 0x55, 0x20, 0xE9, 0x29, 0x74, 0xC7,
  37919. 0x10, 0x01, 0xF3, 0xA4, 0x56, 0xB4, 0x14, 0xFE,
  37920. 0x9C, 0x10, 0x2F, 0xF8, 0xBF, 0xB5, 0x9C, 0x6E,
  37921. 0xBB, 0xE6, 0x52, 0xE7, 0xAC, 0xA7, 0xCE, 0x41,
  37922. 0x6E, 0x00, 0x66, 0x0A, 0x2F, 0x46, 0x71, 0xB8,
  37923. 0x8F, 0x45, 0x89, 0x26, 0x68, 0xCD, 0x49, 0xDF,
  37924. 0xCB, 0xCD, 0xD6, 0x66, 0xC6, 0xA7, 0x8E, 0xB3,
  37925. 0xE4, 0x72, 0xEF, 0xBA, 0xA6, 0x6D, 0x7A, 0xB7,
  37926. 0xE9, 0xD9, 0xB2, 0x60, 0xB5, 0x82, 0x77, 0x20,
  37927. 0x2A, 0xFA, 0xE3, 0xCB, 0xF5, 0x30, 0x50, 0x30,
  37928. 0xC6, 0x19, 0x67, 0xA8, 0xB8, 0xFA, 0xFE, 0xB6,
  37929. 0xDA, 0xB6, 0xB6, 0xBF, 0x07, 0x90, 0x40, 0xD8,
  37930. 0x5B, 0x15, 0x48, 0x39, 0xCD, 0x99, 0x0F, 0x3A,
  37931. 0x28, 0xD2, 0x2E, 0xBA, 0xAC, 0x6D, 0xA3, 0xF8,
  37932. 0x53, 0x88, 0xF0, 0x86, 0x87, 0x70, 0xF5, 0x07,
  37933. 0xD2, 0x99, 0xC4, 0xCA, 0xDD, 0xD8, 0x8C, 0xEB,
  37934. 0x00, 0x96, 0xB4, 0x62, 0xA3, 0x7B, 0x79, 0x31,
  37935. 0xB2, 0x85, 0xB0, 0x61, 0x39, 0xF2, 0xBC, 0x1D,
  37936. 0x31, 0xC3, 0x0C, 0x7F, 0x70, 0x9A, 0x63, 0x74,
  37937. 0xC6, 0xCB, 0xD3, 0x93, 0x0D, 0x43, 0x7F, 0x80,
  37938. 0x85, 0x87, 0x72, 0x98, 0xE1, 0x6E, 0x9A, 0x59,
  37939. 0x2E, 0x6C, 0xA8, 0x9E, 0xC2, 0xC0, 0x72, 0xFE,
  37940. 0x26, 0xE8, 0xAF, 0x89, 0x61, 0xCA, 0x0D, 0x15,
  37941. 0xCC, 0xB0, 0xBA, 0x10, 0xB8, 0x9D, 0x77, 0x2C,
  37942. 0x6C, 0x28, 0xCC, 0x70, 0x5B, 0x1F, 0x5D, 0x68,
  37943. 0xD4, 0xC8, 0x1F, 0x0F, 0x67, 0xF5, 0x3E, 0x5C,
  37944. 0x70, 0x50, 0x4B, 0x32, 0x12, 0xE6, 0x1A, 0xCE,
  37945. 0xB8, 0x32, 0x5F, 0x1D, 0xC5, 0xFB, 0x07, 0x77,
  37946. 0xAD, 0x85, 0x45, 0x95, 0x04, 0x0D, 0x94, 0x7A,
  37947. 0x1F, 0xDD, 0x05, 0x74, 0x14, 0xA5, 0x9A, 0x66,
  37948. 0xF4, 0x93, 0xBE, 0xF2, 0xA9, 0x5B, 0xCD, 0xAB,
  37949. 0xC7, 0x82, 0xF7, 0xE7, 0x4A, 0x1C, 0x90, 0x6B,
  37950. 0x9A, 0xBD, 0x93, 0xDD, 0x41, 0x56, 0xDA, 0xA5,
  37951. 0x0F, 0x5D, 0x57, 0x2C, 0xBA, 0x07, 0x07, 0x4B,
  37952. 0x91, 0x33, 0xE6, 0x1B, 0x0E, 0x25, 0x9E, 0x36,
  37953. 0xBF, 0xCA, 0x21, 0xCE, 0xC6, 0x82, 0x33, 0x4D,
  37954. 0x42, 0x4F, 0x2E, 0x71, 0xC2, 0xE7, 0x6F, 0x16,
  37955. 0xF6, 0xB7, 0x30, 0x1C, 0xA1, 0xA8, 0xE3, 0xE7,
  37956. 0xB1, 0x71, 0xDD, 0x9F, 0x90, 0x1F, 0x01, 0x1D,
  37957. 0x0A, 0xBD, 0x2C, 0x4A, 0x22, 0x84, 0x5C, 0xBF,
  37958. 0x61, 0x07, 0x24, 0xC4, 0x0D, 0x23, 0xDB, 0xC6,
  37959. 0x28, 0xB1, 0x27, 0xCB, 0x7E, 0x06, 0xF8, 0x3C,
  37960. 0x42, 0xF9, 0x51, 0x2F, 0x21, 0xC5, 0x80, 0x98,
  37961. 0x08, 0x2F, 0x56, 0x58, 0xD7, 0xE0, 0xDA, 0xC4,
  37962. 0x24, 0x0C, 0xE8, 0xFA, 0x94, 0x23, 0x57, 0xA6,
  37963. 0xD8, 0xE2, 0xC5, 0xCC, 0x16, 0x70, 0x55, 0x57,
  37964. 0xC4, 0x52, 0x2D, 0x94, 0xCE, 0x5B, 0x22, 0x8E,
  37965. 0x6C, 0x3D, 0x8E, 0x74, 0x9D, 0xFD, 0x47, 0xC7,
  37966. 0x42, 0x11, 0x41, 0x9F, 0x6A, 0x0A, 0xF6, 0x16,
  37967. 0x97, 0xB1, 0x24, 0xC4, 0x6C, 0x98, 0xF8, 0x62,
  37968. 0x51, 0xE9, 0x67, 0x6D, 0x39, 0x2B, 0x76, 0x19,
  37969. 0x5F, 0x41, 0xF4, 0x82, 0x51, 0x87, 0xFF, 0xAA,
  37970. 0x87, 0xE3, 0x46, 0x87, 0xC0, 0xC9, 0xBB, 0xB5,
  37971. 0xAC, 0xA0, 0xD1, 0x56, 0x54, 0xC2, 0x2C, 0x59,
  37972. 0x9E, 0x78, 0xF9, 0xA6, 0xBA, 0xCB, 0xE2, 0x45,
  37973. 0x8A, 0xC1, 0xE5, 0xDF, 0xC3, 0x81, 0x91, 0xDB,
  37974. 0xDB, 0x9E, 0xE2, 0x9C, 0xB9, 0x44, 0x5F, 0x5D,
  37975. 0x6D, 0x83, 0x8D, 0x2D, 0x3E, 0x72, 0x2F, 0x98,
  37976. 0xFC, 0xFA, 0x5F, 0xC0, 0xF0, 0x03, 0x4A, 0x42,
  37977. 0x19, 0x67, 0x48, 0x24, 0x70, 0x35, 0xAE, 0x37,
  37978. 0x34, 0x27, 0xAB, 0xD6, 0x92, 0xB8, 0xB4, 0x52,
  37979. 0xC9, 0xD1, 0xF0, 0x5C, 0xAC, 0xFA, 0xB9, 0x2D,
  37980. 0xCE, 0xF2, 0x24, 0xE3, 0x53, 0xF4, 0x2D, 0x65,
  37981. 0x8D, 0xBF, 0x27, 0x3F, 0xAF, 0x62, 0xE0, 0x27,
  37982. 0xBE, 0x12, 0xCB, 0x40, 0xA4, 0x99, 0xAF, 0x47,
  37983. 0x19, 0x5F, 0x68, 0x69, 0x7F, 0x8C, 0xD2, 0x1E,
  37984. 0x4A, 0xA1, 0xA4, 0x3D, 0x5A, 0x62, 0x6F, 0x78,
  37985. 0x87, 0x8E, 0xA0, 0xC0, 0xF3, 0x2C, 0x60, 0xC3,
  37986. 0xCE, 0xDD, 0xED, 0x7C, 0xAF, 0xE0, 0x0B, 0x72,
  37987. 0x9D, 0xBA, 0xC6, 0xEE, 0x00, 0x00, 0x00, 0x00,
  37988. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  37989. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07,
  37990. 0x0B, 0x15, 0x1B, 0x1E, 0x24
  37991. };
  37992. #endif
  37993. #ifndef WOLFSSL_NO_ML_DSA_87
  37994. static const byte sk_87[] = {
  37995. 0xF1, 0x79, 0x16, 0xD9, 0x5C, 0x51, 0x2F, 0xEC,
  37996. 0x0C, 0xEF, 0xA6, 0xA1, 0x5C, 0x9F, 0xB3, 0xBF,
  37997. 0x84, 0xFF, 0x8D, 0x7F, 0xA3, 0x55, 0x22, 0xEB,
  37998. 0x1C, 0x91, 0x5C, 0x4D, 0x25, 0x4E, 0x89, 0x35,
  37999. 0x24, 0x8E, 0x3C, 0x08, 0x58, 0x2B, 0x74, 0x5E,
  38000. 0xB2, 0xFD, 0x13, 0x15, 0x2B, 0x5D, 0xAE, 0xEA,
  38001. 0xB0, 0x72, 0x80, 0x42, 0xB0, 0x08, 0x85, 0xBB,
  38002. 0x92, 0xF8, 0x44, 0xA8, 0x6B, 0x42, 0x62, 0x03,
  38003. 0x5C, 0x9F, 0x44, 0x8A, 0x2B, 0x78, 0xEF, 0x5D,
  38004. 0xB3, 0x47, 0xE0, 0x25, 0x04, 0x15, 0xE1, 0x01,
  38005. 0x5F, 0xBB, 0x34, 0x31, 0x91, 0x24, 0x07, 0xC8,
  38006. 0x5A, 0x2F, 0x36, 0x2A, 0x85, 0xA9, 0xAE, 0x42,
  38007. 0x77, 0x23, 0xBF, 0x62, 0x69, 0x7B, 0x77, 0x99,
  38008. 0x1B, 0x3E, 0x93, 0xA3, 0x81, 0x13, 0x3F, 0x95,
  38009. 0x0D, 0x40, 0xE7, 0xC1, 0xAC, 0xBC, 0x17, 0xE4,
  38010. 0xF1, 0xD1, 0x0C, 0xD1, 0x27, 0x4C, 0x8D, 0x3C,
  38011. 0x84, 0x02, 0x02, 0x0A, 0xC5, 0x10, 0x1C, 0xC3,
  38012. 0x4D, 0xD0, 0x94, 0x70, 0x24, 0xC0, 0x89, 0x94,
  38013. 0x08, 0x4D, 0xC2, 0x30, 0x20, 0x63, 0xC0, 0x24,
  38014. 0xE1, 0x80, 0x40, 0xD0, 0x26, 0x68, 0x10, 0x97,
  38015. 0x01, 0x83, 0xC2, 0x91, 0x5A, 0x90, 0x2D, 0x44,
  38016. 0x94, 0x6D, 0x10, 0x09, 0x50, 0x11, 0xA7, 0x0D,
  38017. 0xE4, 0x04, 0x89, 0x9B, 0x80, 0x8D, 0x40, 0xB8,
  38018. 0x45, 0x4B, 0x86, 0x0D, 0xC8, 0xB6, 0x05, 0xC0,
  38019. 0xC0, 0x71, 0x02, 0x09, 0x06, 0xA2, 0x00, 0x2D,
  38020. 0x0B, 0x24, 0x86, 0xA0, 0x90, 0x11, 0x20, 0x16,
  38021. 0x82, 0x1B, 0x24, 0x42, 0xCB, 0xB6, 0x70, 0x43,
  38022. 0x36, 0x05, 0xDA, 0x16, 0x25, 0x9A, 0x34, 0x6C,
  38023. 0xCB, 0xB4, 0x08, 0xC4, 0x16, 0x90, 0x24, 0x29,
  38024. 0x6C, 0x42, 0x90, 0x04, 0x24, 0x06, 0x46, 0x84,
  38025. 0x12, 0x6D, 0xC2, 0x26, 0x00, 0x88, 0x40, 0x02,
  38026. 0x51, 0xC8, 0x40, 0x9C, 0x16, 0x24, 0x82, 0x18,
  38027. 0x26, 0x21, 0x06, 0x0C, 0x12, 0xC2, 0x71, 0x50,
  38028. 0x98, 0x91, 0x4A, 0x40, 0x28, 0x48, 0x48, 0x21,
  38029. 0x5A, 0x18, 0x49, 0x1B, 0xB7, 0x01, 0x5A, 0xC6,
  38030. 0x48, 0xA1, 0x90, 0x2C, 0x14, 0x18, 0x2D, 0xD2,
  38031. 0x20, 0x62, 0xDC, 0xB6, 0x49, 0x00, 0x09, 0x6D,
  38032. 0x40, 0xA8, 0x4D, 0x24, 0xC8, 0x24, 0x4C, 0x06,
  38033. 0x08, 0x80, 0x40, 0x4E, 0xD3, 0x18, 0x88, 0x12,
  38034. 0x09, 0x91, 0x8B, 0x12, 0x31, 0xC9, 0x16, 0x04,
  38035. 0x64, 0x10, 0x72, 0xDA, 0x84, 0x91, 0x92, 0xC6,
  38036. 0x65, 0x22, 0x10, 0x48, 0x18, 0xC9, 0x00, 0x14,
  38037. 0x44, 0x62, 0x24, 0xC1, 0x60, 0x40, 0xC6, 0x10,
  38038. 0x4A, 0x48, 0x28, 0x9B, 0x44, 0x66, 0x91, 0x10,
  38039. 0x52, 0xD3, 0x26, 0x52, 0xD8, 0xA6, 0x0C, 0x0A,
  38040. 0xA8, 0x44, 0xD8, 0x26, 0x0C, 0x64, 0x86, 0x45,
  38041. 0x44, 0x20, 0x00, 0xD2, 0x48, 0x85, 0xDC, 0x46,
  38042. 0x32, 0xC8, 0x22, 0x45, 0x5B, 0x00, 0x8D, 0x20,
  38043. 0xA5, 0x45, 0x01, 0xC1, 0x91, 0xA2, 0x12, 0x84,
  38044. 0x20, 0x47, 0x0E, 0x98, 0xA8, 0x25, 0xD9, 0xA0,
  38045. 0x4D, 0xA4, 0x06, 0x2D, 0x5B, 0xB0, 0x08, 0x21,
  38046. 0xB0, 0x80, 0x4C, 0x10, 0x2C, 0xC4, 0x98, 0x71,
  38047. 0x99, 0x24, 0x24, 0xA4, 0x36, 0x71, 0x4B, 0xB6,
  38048. 0x49, 0xE1, 0x92, 0x00, 0x09, 0x92, 0x4C, 0x89,
  38049. 0x12, 0x49, 0x1A, 0x39, 0x2A, 0xE0, 0x22, 0x69,
  38050. 0x61, 0xB2, 0x50, 0x40, 0x26, 0x8E, 0xC9, 0xA2,
  38051. 0x08, 0x0A, 0x90, 0x24, 0x13, 0x35, 0x06, 0x21,
  38052. 0x24, 0x62, 0x60, 0xB0, 0x01, 0xE3, 0xC6, 0x29,
  38053. 0x5B, 0x28, 0x89, 0x20, 0x90, 0x70, 0xC4, 0xA4,
  38054. 0x31, 0x08, 0x42, 0x11, 0x10, 0xC0, 0x71, 0x98,
  38055. 0x98, 0x20, 0xC4, 0xA8, 0x29, 0x1A, 0x15, 0x32,
  38056. 0xC4, 0x86, 0x6C, 0x18, 0x14, 0x6A, 0x02, 0x46,
  38057. 0x46, 0xDC, 0xC2, 0x4C, 0x81, 0x02, 0x6D, 0x49,
  38058. 0x16, 0x48, 0x10, 0x94, 0x6C, 0x0A, 0x85, 0x90,
  38059. 0x9C, 0x34, 0x84, 0x54, 0x24, 0x25, 0x49, 0xA8,
  38060. 0x21, 0x04, 0xA6, 0x2C, 0x61, 0x00, 0x01, 0x61,
  38061. 0x46, 0x92, 0xE0, 0xA6, 0x44, 0xE2, 0x00, 0x90,
  38062. 0xC8, 0x06, 0x06, 0x90, 0xB8, 0x2D, 0x0B, 0x85,
  38063. 0x85, 0x20, 0x23, 0x0D, 0x83, 0x94, 0x04, 0x54,
  38064. 0x26, 0x50, 0x41, 0x92, 0x29, 0x09, 0x16, 0x20,
  38065. 0x54, 0xC6, 0x2D, 0x81, 0xC8, 0x8C, 0x09, 0x44,
  38066. 0x44, 0xE2, 0x06, 0x30, 0x13, 0x92, 0x49, 0x0B,
  38067. 0x17, 0x48, 0x93, 0x28, 0x86, 0xD8, 0xA4, 0x50,
  38068. 0xD1, 0x32, 0x91, 0x08, 0xB8, 0x05, 0xA4, 0x02,
  38069. 0x62, 0x01, 0x15, 0x82, 0xE3, 0x18, 0x42, 0x83,
  38070. 0xC6, 0x44, 0x43, 0x02, 0x81, 0x53, 0x88, 0x04,
  38071. 0x04, 0x98, 0x31, 0x19, 0x18, 0x46, 0xDB, 0x02,
  38072. 0x89, 0x10, 0x23, 0x81, 0x03, 0x90, 0x71, 0x83,
  38073. 0x26, 0x89, 0x1A, 0x01, 0x05, 0xCA, 0xB0, 0x01,
  38074. 0x4C, 0x84, 0x09, 0x10, 0x11, 0x84, 0x13, 0xB1,
  38075. 0x20, 0x61, 0xB8, 0x41, 0x1B, 0x02, 0x8C, 0x09,
  38076. 0x98, 0x61, 0x83, 0x18, 0x61, 0x08, 0xC1, 0x6D,
  38077. 0x44, 0x86, 0x09, 0xCB, 0x88, 0x8D, 0x93, 0xB4,
  38078. 0x41, 0x58, 0x90, 0x81, 0x04, 0x31, 0x08, 0xD1,
  38079. 0xC4, 0x04, 0x19, 0xB4, 0x4C, 0x1C, 0x88, 0x20,
  38080. 0xCA, 0x30, 0x72, 0x1C, 0xB5, 0x85, 0x13, 0x27,
  38081. 0x32, 0x84, 0xB4, 0x44, 0x04, 0x42, 0x20, 0x61,
  38082. 0x18, 0x52, 0x50, 0x96, 0x44, 0x03, 0x38, 0x86,
  38083. 0xE3, 0x48, 0x31, 0x02, 0x82, 0x68, 0x98, 0x06,
  38084. 0x90, 0x23, 0x28, 0x04, 0x10, 0x18, 0x0D, 0x10,
  38085. 0x28, 0x45, 0x4C, 0x84, 0x6C, 0x09, 0x36, 0x71,
  38086. 0x82, 0x26, 0x64, 0x18, 0xC6, 0x21, 0x90, 0x18,
  38087. 0x22, 0x0A, 0x37, 0x08, 0xC4, 0x94, 0x28, 0xE2,
  38088. 0x30, 0x2C, 0x92, 0xB4, 0x24, 0x63, 0x46, 0x70,
  38089. 0x52, 0x96, 0x0C, 0x8B, 0xA4, 0x05, 0xD3, 0x02,
  38090. 0x85, 0x09, 0x32, 0x92, 0x49, 0x12, 0x21, 0x18,
  38091. 0x43, 0x28, 0x01, 0x32, 0x45, 0x0B, 0xA5, 0x50,
  38092. 0x14, 0x16, 0x65, 0x91, 0x80, 0x65, 0x0A, 0x44,
  38093. 0x66, 0x13, 0xB6, 0x4C, 0x01, 0x38, 0x71, 0x11,
  38094. 0x49, 0x28, 0x22, 0x43, 0x02, 0x0B, 0x34, 0x04,
  38095. 0x01, 0x16, 0x91, 0x80, 0x14, 0x0E, 0x12, 0x93,
  38096. 0x01, 0x00, 0x11, 0x80, 0xDC, 0x28, 0x51, 0x11,
  38097. 0x87, 0x85, 0xC1, 0x34, 0x28, 0x02, 0xA2, 0x11,
  38098. 0x02, 0x38, 0x44, 0x52, 0x14, 0x64, 0xC2, 0xA0,
  38099. 0x01, 0x1B, 0x42, 0x8C, 0xC2, 0xB2, 0x71, 0xCB,
  38100. 0x16, 0x00, 0xCC, 0x10, 0x21, 0x04, 0x12, 0x52,
  38101. 0x84, 0x24, 0x2A, 0xD3, 0x48, 0x12, 0x08, 0x44,
  38102. 0x08, 0x81, 0x88, 0x44, 0x01, 0x23, 0x50, 0xC0,
  38103. 0xA2, 0x09, 0x81, 0x94, 0x50, 0x02, 0x89, 0x61,
  38104. 0x01, 0x31, 0x88, 0x1B, 0xA2, 0x61, 0x90, 0x94,
  38105. 0x84, 0x91, 0x24, 0x09, 0x03, 0x18, 0x22, 0xA3,
  38106. 0x46, 0x60, 0x10, 0x16, 0x4D, 0x48, 0x84, 0x89,
  38107. 0x11, 0x00, 0x2E, 0xCC, 0xC0, 0x40, 0x8C, 0xC0,
  38108. 0x51, 0xE4, 0x42, 0x62, 0xDA, 0x24, 0x11, 0x13,
  38109. 0x19, 0x46, 0x93, 0x34, 0x4C, 0x42, 0x42, 0x24,
  38110. 0xC4, 0x48, 0x90, 0x00, 0x35, 0x80, 0x1B, 0x98,
  38111. 0x51, 0x0B, 0x41, 0x60, 0x0C, 0x25, 0x46, 0x9A,
  38112. 0xA8, 0x89, 0x12, 0x86, 0x4C, 0xE3, 0x16, 0x09,
  38113. 0x14, 0x27, 0x24, 0x51, 0x26, 0x4D, 0x1B, 0x02,
  38114. 0x10, 0x00, 0x17, 0x28, 0xD4, 0xA8, 0x45, 0x48,
  38115. 0x88, 0x48, 0x01, 0xC7, 0x0D, 0x93, 0xC8, 0x40,
  38116. 0x5B, 0x02, 0x49, 0x51, 0x02, 0x4A, 0x01, 0x42,
  38117. 0x10, 0xE1, 0x08, 0x90, 0x03, 0x85, 0x48, 0x11,
  38118. 0xA8, 0x68, 0x8B, 0x90, 0x08, 0x5A, 0x02, 0x0C,
  38119. 0x5A, 0x18, 0x50, 0x11, 0x87, 0x51, 0x9C, 0x38,
  38120. 0x92, 0xD0, 0x44, 0x82, 0x10, 0x33, 0x21, 0x88,
  38121. 0x44, 0x2D, 0x24, 0x28, 0x0D, 0x22, 0xA3, 0x30,
  38122. 0x49, 0x88, 0x25, 0xA1, 0xB2, 0x01, 0x5C, 0x40,
  38123. 0x20, 0x1C, 0x03, 0x72, 0xCC, 0x96, 0x8C, 0x51,
  38124. 0xA6, 0x88, 0xE3, 0x92, 0x08, 0x13, 0xB0, 0x08,
  38125. 0x5C, 0x38, 0x44, 0x03, 0x47, 0x8E, 0x93, 0x12,
  38126. 0x4A, 0x88, 0x20, 0x48, 0xE0, 0x42, 0x20, 0x81,
  38127. 0x90, 0x09, 0x4B, 0x06, 0x6D, 0xD2, 0x90, 0x10,
  38128. 0x01, 0x82, 0x49, 0x19, 0x28, 0x91, 0xDA, 0x20,
  38129. 0x2A, 0x20, 0x85, 0x40, 0x0A, 0x16, 0x8A, 0x1C,
  38130. 0x83, 0x60, 0xCA, 0x48, 0x4A, 0xA2, 0xC8, 0x50,
  38131. 0xE4, 0x02, 0x31, 0x88, 0x86, 0x88, 0x53, 0x00,
  38132. 0x89, 0x60, 0x08, 0x8A, 0xA2, 0x02, 0x0A, 0x0A,
  38133. 0x34, 0x45, 0x03, 0x04, 0x42, 0x1B, 0x40, 0x09,
  38134. 0x89, 0xA0, 0x69, 0x42, 0x18, 0x49, 0x4A, 0xA8,
  38135. 0x8C, 0x99, 0x90, 0x30, 0xCA, 0x38, 0x91, 0x09,
  38136. 0x31, 0x72, 0x8B, 0x44, 0x29, 0x52, 0xA2, 0x8D,
  38137. 0x08, 0x14, 0x6E, 0xA1, 0x84, 0x50, 0x1C, 0x31,
  38138. 0x46, 0x19, 0xB7, 0x01, 0xCC, 0x06, 0x29, 0x11,
  38139. 0x09, 0x20, 0x4B, 0x40, 0x66, 0x40, 0xC4, 0x49,
  38140. 0x00, 0x13, 0x24, 0xD0, 0xA2, 0x84, 0xCA, 0x16,
  38141. 0x29, 0xD0, 0xC0, 0x84, 0xC8, 0x88, 0x44, 0xE1,
  38142. 0x20, 0x29, 0x1A, 0x97, 0x05, 0x90, 0x42, 0x90,
  38143. 0x04, 0x40, 0x71, 0x9C, 0x32, 0x4E, 0x64, 0x26,
  38144. 0x22, 0x93, 0x36, 0x66, 0xD3, 0x06, 0x49, 0xA3,
  38145. 0x26, 0x51, 0x4C, 0xA6, 0x89, 0x84, 0x36, 0x84,
  38146. 0x93, 0x46, 0x6D, 0x14, 0x07, 0x8D, 0x18, 0x29,
  38147. 0x42, 0x52, 0x34, 0x72, 0x44, 0x10, 0x90, 0x12,
  38148. 0x37, 0x81, 0xD4, 0x10, 0x64, 0x04, 0xA5, 0x08,
  38149. 0x84, 0x24, 0x09, 0x1C, 0x08, 0x8D, 0x02, 0x99,
  38150. 0x6C, 0x1B, 0x30, 0x50, 0x09, 0x89, 0x81, 0x19,
  38151. 0x30, 0x48, 0x5B, 0x14, 0x4D, 0xD9, 0x20, 0x20,
  38152. 0x0C, 0x01, 0x2A, 0x00, 0x90, 0x4D, 0xA1, 0x02,
  38153. 0x64, 0x1C, 0x03, 0x01, 0xC2, 0x26, 0x8C, 0x14,
  38154. 0x08, 0x45, 0xE3, 0x12, 0x48, 0x09, 0x20, 0x09,
  38155. 0x41, 0x40, 0x61, 0x90, 0x44, 0x21, 0x49, 0x06,
  38156. 0x91, 0x4B, 0xC0, 0x84, 0x22, 0x95, 0x51, 0x23,
  38157. 0x38, 0x0E, 0x5C, 0x28, 0x70, 0xC2, 0x40, 0x2C,
  38158. 0x94, 0x18, 0x62, 0x9A, 0x30, 0x4A, 0xE2, 0x86,
  38159. 0x4C, 0x5C, 0x10, 0x8D, 0xC2, 0x12, 0x21, 0x9C,
  38160. 0xC4, 0x4D, 0xD9, 0x96, 0x88, 0x0C, 0x29, 0x45,
  38161. 0x1B, 0x45, 0x6A, 0x1A, 0x00, 0x60, 0x91, 0x30,
  38162. 0x0C, 0x12, 0x00, 0x69, 0xA2, 0xA0, 0x04, 0x81,
  38163. 0x00, 0x65, 0x5C, 0x38, 0x8A, 0x18, 0x05, 0x89,
  38164. 0x48, 0x32, 0x24, 0x81, 0xC6, 0x4D, 0x60, 0x90,
  38165. 0x31, 0x83, 0x22, 0x12, 0xE1, 0xC2, 0x6C, 0x89,
  38166. 0x00, 0x90, 0x14, 0xB4, 0x40, 0xD3, 0xB8, 0x45,
  38167. 0x89, 0x24, 0x70, 0x09, 0x26, 0x6C, 0xD9, 0x32,
  38168. 0x8A, 0x83, 0x44, 0x0E, 0x21, 0x44, 0x61, 0x99,
  38169. 0xA4, 0x20, 0x44, 0x16, 0x2E, 0x1A, 0xC2, 0x08,
  38170. 0x09, 0x98, 0x6C, 0x8C, 0x18, 0x8C, 0x0C, 0x30,
  38171. 0x62, 0x8B, 0x46, 0x45, 0x80, 0x10, 0x21, 0x20,
  38172. 0x33, 0x32, 0x5A, 0x38, 0x4C, 0x98, 0x06, 0x45,
  38173. 0x1A, 0x33, 0x09, 0x82, 0x34, 0x44, 0x02, 0x20,
  38174. 0x09, 0x59, 0x00, 0x41, 0x08, 0x13, 0x08, 0xDC,
  38175. 0x18, 0x68, 0x12, 0x47, 0x86, 0x43, 0xB8, 0x21,
  38176. 0x62, 0x02, 0x8D, 0x5C, 0x10, 0x0D, 0x60, 0x96,
  38177. 0x65, 0xA2, 0x22, 0x4C, 0x83, 0x18, 0x09, 0x41,
  38178. 0x08, 0x41, 0x63, 0xC2, 0x80, 0x13, 0x81, 0x65,
  38179. 0x22, 0x03, 0x92, 0x04, 0xA9, 0x4D, 0x1C, 0xB0,
  38180. 0x44, 0x80, 0xC6, 0x24, 0x00, 0x01, 0x44, 0x22,
  38181. 0x11, 0x80, 0x21, 0x95, 0x64, 0x09, 0x99, 0x8C,
  38182. 0xD3, 0x14, 0x4A, 0xD1, 0x98, 0x2D, 0x19, 0x31,
  38183. 0x4C, 0x0A, 0x92, 0x40, 0x13, 0x98, 0x48, 0x14,
  38184. 0x89, 0x20, 0x23, 0xB3, 0x0D, 0x14, 0x98, 0x6D,
  38185. 0x12, 0x98, 0x05, 0x9B, 0x14, 0x06, 0x5B, 0x26,
  38186. 0x91, 0x0A, 0x38, 0x09, 0x08, 0x98, 0x2C, 0x19,
  38187. 0xA0, 0x45, 0x44, 0x26, 0x00, 0x0A, 0x05, 0x21,
  38188. 0xDB, 0xA0, 0x69, 0x51, 0x42, 0x92, 0x0B, 0x43,
  38189. 0x00, 0xD1, 0x42, 0x0D, 0x81, 0x30, 0x28, 0x13,
  38190. 0xC2, 0x20, 0x03, 0x27, 0x60, 0x10, 0x83, 0x91,
  38191. 0x0A, 0x53, 0x7E, 0xA1, 0x4F, 0x11, 0x54, 0x5E,
  38192. 0x25, 0x4F, 0xCF, 0x28, 0x03, 0x95, 0x2A, 0x58,
  38193. 0x0A, 0x4B, 0x6C, 0x9B, 0x29, 0x10, 0x3D, 0x97,
  38194. 0x43, 0x6C, 0x00, 0x3E, 0x2E, 0xCE, 0xAE, 0x20,
  38195. 0x28, 0x01, 0x7F, 0xF1, 0xD5, 0x18, 0xB0, 0xB5,
  38196. 0xD5, 0xE6, 0x24, 0x26, 0x64, 0xED, 0x33, 0x7C,
  38197. 0xCA, 0x45, 0x26, 0xED, 0x5D, 0xB5, 0xEA, 0xD8,
  38198. 0xBB, 0x31, 0x16, 0x94, 0x1C, 0xD0, 0xC8, 0xF0,
  38199. 0xA7, 0xED, 0x5A, 0x1A, 0x5A, 0x00, 0xB9, 0x8C,
  38200. 0x33, 0x6A, 0x9B, 0xC8, 0xEB, 0x6B, 0x3A, 0x30,
  38201. 0x83, 0x16, 0xF1, 0x17, 0xEA, 0xA8, 0x0D, 0x4B,
  38202. 0x77, 0x56, 0xDD, 0x4A, 0x91, 0xDA, 0xA5, 0x8E,
  38203. 0x80, 0xD7, 0xB5, 0x77, 0x55, 0x83, 0x97, 0xAF,
  38204. 0x90, 0x5B, 0x67, 0xC5, 0x9F, 0x14, 0xE1, 0x2C,
  38205. 0x15, 0x8D, 0x29, 0x2C, 0xA6, 0xB6, 0x41, 0xED,
  38206. 0x0C, 0x75, 0xE3, 0x9A, 0x91, 0x4F, 0xFA, 0x1A,
  38207. 0x9F, 0x24, 0xCA, 0x28, 0xF2, 0x00, 0xC7, 0x48,
  38208. 0xDE, 0x70, 0x9D, 0x15, 0xD7, 0x22, 0xE7, 0xED,
  38209. 0x2C, 0x91, 0x8D, 0xEF, 0x08, 0xCF, 0xAF, 0x9B,
  38210. 0x7E, 0x24, 0xDE, 0xF2, 0xD5, 0x1A, 0x4D, 0x42,
  38211. 0x0E, 0x7E, 0x89, 0x06, 0xFA, 0xCD, 0x9A, 0x5A,
  38212. 0x98, 0xB0, 0xD1, 0xD5, 0x34, 0x5C, 0x8B, 0x9A,
  38213. 0xC0, 0xBB, 0xF4, 0xB1, 0x5E, 0xF0, 0xB4, 0x6A,
  38214. 0x8E, 0x3B, 0x6B, 0xAE, 0x0C, 0x6E, 0x9F, 0x09,
  38215. 0x2E, 0xB3, 0xEF, 0x1D, 0x49, 0x62, 0x0B, 0x65,
  38216. 0xE7, 0xDE, 0xDB, 0xEF, 0x68, 0x7E, 0xBD, 0x0E,
  38217. 0xA0, 0x95, 0x97, 0x2A, 0x56, 0xA0, 0xEA, 0xFB,
  38218. 0x2D, 0x75, 0xF4, 0x32, 0x1B, 0x80, 0xAC, 0xBC,
  38219. 0xA3, 0x2B, 0x1B, 0x11, 0xAA, 0x57, 0x6F, 0xE4,
  38220. 0xE0, 0xCC, 0xCC, 0x20, 0x52, 0x12, 0x65, 0x42,
  38221. 0x96, 0xF0, 0x60, 0x8F, 0xF3, 0x83, 0x69, 0xAF,
  38222. 0x19, 0x80, 0x75, 0x68, 0xDB, 0xE1, 0x71, 0xDB,
  38223. 0x79, 0xEB, 0x8C, 0x1C, 0xB7, 0x6A, 0x8E, 0xB9,
  38224. 0x5B, 0x28, 0x8C, 0x9D, 0xCC, 0x62, 0x0B, 0xEF,
  38225. 0xCE, 0x96, 0x06, 0x0F, 0x45, 0xA6, 0xA2, 0xDA,
  38226. 0xC2, 0x2F, 0x55, 0xE4, 0x7D, 0xC7, 0xBA, 0xB4,
  38227. 0xA7, 0x93, 0xD9, 0x65, 0x8F, 0xE2, 0x7C, 0x66,
  38228. 0x2C, 0xA6, 0x37, 0x00, 0x81, 0x30, 0xF1, 0x00,
  38229. 0xD9, 0x65, 0xB4, 0x78, 0x17, 0x7A, 0xC6, 0xDC,
  38230. 0x35, 0x93, 0x1A, 0x5E, 0xCC, 0x5F, 0x93, 0x31,
  38231. 0x22, 0x40, 0x2C, 0x17, 0x0E, 0xB8, 0xE0, 0xA4,
  38232. 0x1C, 0xB6, 0x3F, 0xE5, 0x60, 0x2F, 0x7B, 0x18,
  38233. 0xE1, 0xDB, 0xB6, 0xDB, 0x30, 0xA7, 0x61, 0x55,
  38234. 0xC6, 0xCF, 0x03, 0x0F, 0x73, 0x8D, 0xC0, 0x91,
  38235. 0x6D, 0xB1, 0x80, 0xF8, 0x3F, 0x02, 0x90, 0x93,
  38236. 0x11, 0xCB, 0x6B, 0x3B, 0x9E, 0x55, 0x3F, 0xAC,
  38237. 0xA0, 0x52, 0x23, 0xB3, 0x3C, 0x69, 0x60, 0x2D,
  38238. 0x0F, 0x05, 0xA0, 0x8B, 0xEB, 0x84, 0x80, 0x96,
  38239. 0x51, 0x99, 0x9A, 0x55, 0x26, 0xE7, 0x76, 0xF3,
  38240. 0xDE, 0x39, 0x30, 0x4A, 0x5F, 0xEF, 0x00, 0x95,
  38241. 0x0A, 0x9A, 0x81, 0x0D, 0x12, 0xE0, 0x1D, 0x15,
  38242. 0xD8, 0x86, 0xDB, 0x26, 0x75, 0xF6, 0x54, 0xCA,
  38243. 0x17, 0xFA, 0xAE, 0xEB, 0xD1, 0xF5, 0x61, 0xF9,
  38244. 0xD1, 0xA9, 0x5E, 0x0B, 0xAD, 0xF7, 0xC3, 0x31,
  38245. 0x5A, 0xFA, 0xBA, 0x8D, 0x4B, 0xEC, 0x1F, 0x05,
  38246. 0x42, 0xA8, 0xF1, 0x0A, 0xC6, 0x66, 0xFD, 0x8D,
  38247. 0x0C, 0x5A, 0xF1, 0xD6, 0x86, 0x7A, 0x9D, 0x82,
  38248. 0x6B, 0xFB, 0x6B, 0x03, 0x0B, 0x58, 0xEC, 0xEF,
  38249. 0x67, 0x78, 0xD2, 0xC5, 0x2B, 0xF6, 0x2C, 0xB3,
  38250. 0x4B, 0x81, 0xFF, 0x93, 0x6D, 0xA3, 0x3E, 0xDA,
  38251. 0xB3, 0x1D, 0xB3, 0x9A, 0xB7, 0x63, 0x66, 0xD0,
  38252. 0x94, 0x36, 0x2F, 0x04, 0x6D, 0x50, 0x78, 0xB4,
  38253. 0x22, 0x35, 0x04, 0xA1, 0x2B, 0xA0, 0xC7, 0xB8,
  38254. 0xE8, 0x83, 0x72, 0x77, 0x18, 0x50, 0x9B, 0xD4,
  38255. 0x7A, 0x69, 0x6E, 0xE9, 0x88, 0x0C, 0xAF, 0xF6,
  38256. 0x63, 0x61, 0x2B, 0x95, 0x86, 0x30, 0x3D, 0x6D,
  38257. 0xE0, 0xD2, 0x1F, 0x9A, 0x21, 0x96, 0x22, 0x78,
  38258. 0xEB, 0xCE, 0x60, 0xA6, 0xD4, 0x68, 0x44, 0x09,
  38259. 0x5C, 0x5F, 0x89, 0x2D, 0xAC, 0xA4, 0x8D, 0x78,
  38260. 0x28, 0x22, 0x45, 0x38, 0x34, 0xB4, 0xE4, 0x2C,
  38261. 0xD3, 0xA1, 0xFE, 0x39, 0x87, 0x35, 0x6E, 0xAB,
  38262. 0x11, 0xEF, 0xB8, 0xEE, 0xCD, 0x8E, 0x9C, 0xC8,
  38263. 0xF3, 0x9A, 0x0F, 0xF1, 0xFF, 0xB8, 0x06, 0x9A,
  38264. 0x44, 0x1F, 0x85, 0x1E, 0xB4, 0x38, 0xE9, 0xC0,
  38265. 0xB5, 0x7E, 0x88, 0x18, 0xA3, 0x22, 0x65, 0x1E,
  38266. 0x60, 0xF4, 0xB6, 0x78, 0x90, 0xE5, 0xED, 0x7A,
  38267. 0x0F, 0xBF, 0x75, 0x36, 0xC3, 0xFD, 0x50, 0xD0,
  38268. 0xB0, 0x65, 0x8D, 0x7C, 0xCF, 0x27, 0x5E, 0x8A,
  38269. 0x9E, 0x9F, 0xBB, 0x99, 0xBE, 0x2E, 0x5F, 0x5E,
  38270. 0x16, 0x7B, 0xE2, 0x90, 0xB7, 0xE9, 0x67, 0x32,
  38271. 0xF8, 0x9E, 0x40, 0xD7, 0x85, 0xAF, 0x25, 0xC1,
  38272. 0xBA, 0x61, 0xA7, 0x78, 0x6D, 0x3E, 0xF2, 0xD0,
  38273. 0xC1, 0x14, 0xD1, 0x04, 0x8E, 0x76, 0x46, 0xDF,
  38274. 0xA3, 0x03, 0x2B, 0xFB, 0x7A, 0x51, 0xA6, 0x36,
  38275. 0x05, 0xDC, 0xE3, 0xE1, 0xD8, 0x98, 0x95, 0x00,
  38276. 0xD6, 0xE5, 0x8E, 0x96, 0x05, 0x19, 0x93, 0x1D,
  38277. 0xAC, 0x9F, 0x14, 0xDD, 0xA4, 0x28, 0xF5, 0xA2,
  38278. 0xC9, 0xC7, 0x4D, 0x91, 0x6D, 0x90, 0x77, 0x07,
  38279. 0xB5, 0x3E, 0xB5, 0x2C, 0x44, 0xAD, 0x71, 0xD7,
  38280. 0x27, 0x82, 0x6E, 0xB2, 0xCA, 0x68, 0x07, 0x0A,
  38281. 0x6F, 0x0E, 0x47, 0xFA, 0x16, 0xE5, 0x2E, 0x96,
  38282. 0x29, 0xB7, 0xAA, 0x82, 0x41, 0xDA, 0xAB, 0xB1,
  38283. 0x94, 0x97, 0xA5, 0x82, 0x4E, 0x58, 0xD7, 0x26,
  38284. 0x75, 0xC3, 0xA6, 0x7E, 0x10, 0xA1, 0x19, 0xB2,
  38285. 0x74, 0xB8, 0x4D, 0x9B, 0xEE, 0x28, 0x71, 0x72,
  38286. 0x8E, 0xD2, 0xF9, 0x4F, 0x85, 0x59, 0xB9, 0x7F,
  38287. 0x97, 0x9A, 0xE8, 0x82, 0xEA, 0x54, 0x99, 0x28,
  38288. 0xD6, 0xB1, 0xA9, 0xA4, 0xE4, 0xA2, 0x29, 0xF6,
  38289. 0xEB, 0x3F, 0xB1, 0xA4, 0x34, 0xA0, 0xFA, 0xED,
  38290. 0xAD, 0x62, 0xB7, 0x03, 0x30, 0xCF, 0xCB, 0x24,
  38291. 0xCB, 0x34, 0x98, 0x80, 0x2A, 0x67, 0x9F, 0x8F,
  38292. 0x54, 0xBF, 0x83, 0xEF, 0x34, 0x47, 0x22, 0x96,
  38293. 0x91, 0x98, 0x31, 0xCA, 0xAD, 0x59, 0xEB, 0xE8,
  38294. 0x30, 0x82, 0xEA, 0xB6, 0x7D, 0x4A, 0xBD, 0x90,
  38295. 0x22, 0x9A, 0x5E, 0x93, 0xA0, 0xB5, 0x80, 0x97,
  38296. 0x7F, 0x08, 0x13, 0xCC, 0xB1, 0x5E, 0xCD, 0x74,
  38297. 0xFF, 0x71, 0x5F, 0xE8, 0xDB, 0x5B, 0x05, 0xCE,
  38298. 0xF3, 0x7D, 0x34, 0x93, 0xBE, 0xDA, 0x27, 0x05,
  38299. 0x84, 0x94, 0x4C, 0x02, 0x09, 0x86, 0x34, 0x51,
  38300. 0x4D, 0xAA, 0xCE, 0x70, 0x47, 0xE4, 0x74, 0x32,
  38301. 0xF9, 0x2A, 0xDC, 0xA4, 0x91, 0xA3, 0xE0, 0x96,
  38302. 0x1A, 0x5D, 0x9F, 0x01, 0x44, 0x85, 0x2E, 0x46,
  38303. 0x32, 0x63, 0x35, 0xE2, 0x15, 0x24, 0x3D, 0xAA,
  38304. 0xE8, 0x37, 0x92, 0x7F, 0xBF, 0xDC, 0xE6, 0x91,
  38305. 0xF4, 0x98, 0x59, 0x26, 0x6E, 0x90, 0x08, 0x16,
  38306. 0x8C, 0x6A, 0x5E, 0x2F, 0x60, 0x9C, 0x80, 0xC6,
  38307. 0x8E, 0x08, 0x20, 0xE7, 0x27, 0x19, 0xE9, 0xB5,
  38308. 0x87, 0x3F, 0xA1, 0x99, 0xE1, 0x97, 0xF9, 0xC4,
  38309. 0x94, 0xAA, 0x8A, 0x3A, 0x65, 0x26, 0x9E, 0x95,
  38310. 0xB7, 0x61, 0xB6, 0x7B, 0xEC, 0x61, 0x13, 0xC1,
  38311. 0x44, 0xA5, 0x69, 0x89, 0xC5, 0x75, 0x0D, 0x45,
  38312. 0x05, 0x42, 0xCC, 0xF8, 0x1B, 0x24, 0x62, 0x09,
  38313. 0x2F, 0x70, 0x71, 0x5D, 0x49, 0x14, 0xEB, 0x2C,
  38314. 0xAA, 0x31, 0x74, 0xBC, 0x9E, 0xEB, 0x20, 0xAA,
  38315. 0xB6, 0xC6, 0x40, 0xF8, 0xB5, 0xD9, 0xC6, 0xA0,
  38316. 0xDC, 0xC6, 0xF0, 0xAE, 0xC9, 0x7B, 0x3A, 0xF6,
  38317. 0x47, 0xEB, 0xF8, 0x00, 0x34, 0xA4, 0x3B, 0xF3,
  38318. 0x19, 0xBF, 0x40, 0xAD, 0xF7, 0x9A, 0xFE, 0xAB,
  38319. 0x58, 0x90, 0xD2, 0x02, 0x3B, 0xAE, 0x02, 0xC9,
  38320. 0xFD, 0x02, 0xC5, 0xBB, 0x65, 0x87, 0x9C, 0x1B,
  38321. 0x5E, 0xA4, 0x06, 0x02, 0x9A, 0xE7, 0x78, 0x45,
  38322. 0xCB, 0x99, 0x4D, 0xB8, 0xC3, 0x52, 0x11, 0xCA,
  38323. 0x1D, 0xC8, 0x81, 0xF7, 0xF2, 0x0A, 0x47, 0x06,
  38324. 0x50, 0x5F, 0x29, 0xD9, 0xCD, 0x19, 0x89, 0xAD,
  38325. 0x42, 0xB0, 0x7E, 0xF5, 0x2D, 0x96, 0x54, 0xE2,
  38326. 0x8E, 0x3D, 0xCB, 0x83, 0x00, 0x08, 0xA1, 0xBE,
  38327. 0x31, 0x99, 0x38, 0x7E, 0x06, 0x6B, 0x28, 0xB3,
  38328. 0x15, 0xCA, 0x19, 0x02, 0xF4, 0xBB, 0x0E, 0xE6,
  38329. 0x3F, 0xDC, 0x4C, 0x93, 0xE1, 0xAB, 0x88, 0x6F,
  38330. 0xD7, 0x42, 0x52, 0x61, 0xC3, 0x7A, 0xC5, 0x87,
  38331. 0x62, 0xD0, 0x3D, 0xB6, 0x07, 0x06, 0x88, 0x7E,
  38332. 0x72, 0xCF, 0x74, 0x5A, 0x44, 0x6D, 0xF6, 0xC6,
  38333. 0x66, 0x2F, 0x53, 0xDD, 0x61, 0x24, 0x71, 0xA4,
  38334. 0x34, 0xAC, 0x56, 0xC4, 0xBE, 0xDB, 0x3C, 0x9F,
  38335. 0x36, 0x47, 0xE6, 0x03, 0x2B, 0x3C, 0xC0, 0x99,
  38336. 0x0A, 0x3A, 0x2E, 0x87, 0x05, 0x2B, 0x36, 0xD4,
  38337. 0xA1, 0x62, 0x42, 0x4E, 0x2D, 0x39, 0x9E, 0x1B,
  38338. 0xC2, 0x37, 0x92, 0x8D, 0x0B, 0xD7, 0x71, 0x58,
  38339. 0x07, 0x9C, 0xCB, 0x20, 0x8B, 0x71, 0x95, 0x07,
  38340. 0x96, 0x55, 0xBD, 0xB7, 0x6C, 0xBA, 0xFF, 0x44,
  38341. 0x7C, 0x34, 0xC5, 0x82, 0x9F, 0xAC, 0x19, 0x9B,
  38342. 0xB0, 0x27, 0xA0, 0x80, 0x06, 0x50, 0x8D, 0x56,
  38343. 0xC8, 0x1D, 0x18, 0x70, 0x90, 0xE7, 0x10, 0x24,
  38344. 0xDB, 0x7F, 0xBF, 0x3A, 0x7D, 0x64, 0xD8, 0xFA,
  38345. 0x48, 0x74, 0xA8, 0xF4, 0x70, 0x37, 0x7B, 0x15,
  38346. 0x38, 0x00, 0x96, 0x82, 0x2F, 0xFE, 0x46, 0x55,
  38347. 0x71, 0xB5, 0x0C, 0x54, 0x05, 0x58, 0xBA, 0x50,
  38348. 0xE9, 0x0E, 0xB8, 0x14, 0x52, 0xF4, 0x12, 0x75,
  38349. 0xC2, 0x51, 0x5B, 0xAE, 0x05, 0x92, 0xD5, 0x3F,
  38350. 0x6A, 0x6A, 0x34, 0xD2, 0xA3, 0x4D, 0x8E, 0xAC,
  38351. 0x6E, 0x7A, 0x03, 0xFB, 0xDB, 0x52, 0x49, 0x4F,
  38352. 0x4B, 0x98, 0x1B, 0x56, 0xC0, 0x96, 0x26, 0x08,
  38353. 0x48, 0x50, 0xC7, 0xCF, 0x96, 0x2F, 0x93, 0x10,
  38354. 0x72, 0x25, 0x15, 0xA6, 0x2A, 0xC0, 0x85, 0xA6,
  38355. 0x18, 0x9A, 0xDD, 0xEA, 0x38, 0x12, 0x91, 0x13,
  38356. 0x57, 0x31, 0xB2, 0xEE, 0x83, 0xA4, 0xF1, 0xEB,
  38357. 0xFA, 0x09, 0xAF, 0x80, 0xA9, 0x12, 0x68, 0xA8,
  38358. 0x76, 0x23, 0xCB, 0x55, 0x7C, 0x9F, 0x66, 0xDE,
  38359. 0xB4, 0x54, 0xFB, 0x2F, 0x4F, 0xC2, 0x64, 0x8F,
  38360. 0x44, 0x41, 0x5A, 0x7B, 0xEF, 0x29, 0x96, 0x2D,
  38361. 0x5F, 0x7C, 0x16, 0xE7, 0x85, 0x79, 0xF5, 0x26,
  38362. 0xDD, 0x20, 0xE9, 0x20, 0x9B, 0x6C, 0xA6, 0xDF,
  38363. 0xD1, 0x30, 0xF9, 0x2E, 0xF7, 0x24, 0x64, 0x5B,
  38364. 0x5B, 0x84, 0xD8, 0x72, 0x4F, 0x3C, 0xF6, 0xF3,
  38365. 0xA3, 0xB2, 0xA9, 0xCF, 0x61, 0x24, 0x7A, 0x54,
  38366. 0xBA, 0x92, 0x8F, 0x53, 0xEA, 0xCB, 0xA7, 0xE6,
  38367. 0xD6, 0xB8, 0x12, 0xC4, 0xCE, 0x21, 0xA1, 0x8B,
  38368. 0xA8, 0xD1, 0x14, 0x50, 0xE7, 0x04, 0x89, 0xBA,
  38369. 0x57, 0x2E, 0x5E, 0xB9, 0xA7, 0x72, 0x2D, 0x9D,
  38370. 0xC6, 0xAA, 0xE4, 0xF9, 0x57, 0x93, 0x60, 0x09,
  38371. 0xE2, 0x6E, 0xB3, 0xE7, 0x4D, 0x9F, 0x99, 0x33,
  38372. 0xF3, 0xDB, 0x4D, 0xA0, 0xA1, 0xF5, 0x44, 0x93,
  38373. 0x99, 0xB5, 0xE1, 0x01, 0x03, 0x11, 0xF8, 0x7D,
  38374. 0x92, 0xC1, 0x87, 0xAD, 0x2E, 0xFA, 0xBB, 0x0A,
  38375. 0x2C, 0x86, 0xB7, 0xD7, 0xF9, 0xA0, 0x72, 0xAB,
  38376. 0xC0, 0xC6, 0x60, 0x6D, 0xBC, 0xD9, 0x20, 0x17,
  38377. 0x7A, 0x22, 0x57, 0x20, 0xA7, 0x05, 0x76, 0xB8,
  38378. 0xE8, 0x2D, 0x7D, 0x53, 0xC1, 0xDF, 0xA4, 0x8E,
  38379. 0xA7, 0x31, 0x81, 0xAF, 0x0A, 0xF0, 0x86, 0xB6,
  38380. 0xAA, 0xF8, 0x0A, 0xB2, 0x49, 0x81, 0xF2, 0x75,
  38381. 0xD6, 0x6D, 0x4F, 0xBD, 0xE2, 0xC5, 0x1A, 0xE8,
  38382. 0xE8, 0xD4, 0x58, 0x33, 0x72, 0x9F, 0x45, 0x03,
  38383. 0x01, 0x30, 0xBC, 0x85, 0xB2, 0xBD, 0x9A, 0x14,
  38384. 0xC8, 0x13, 0xA3, 0x7F, 0x1F, 0xA1, 0x47, 0xF8,
  38385. 0x15, 0x48, 0x8D, 0x7A, 0x17, 0xC0, 0xC0, 0x39,
  38386. 0xEA, 0xF8, 0x66, 0xCE, 0xA7, 0x5F, 0x5B, 0x2E,
  38387. 0xBE, 0x05, 0xEF, 0x31, 0x09, 0x47, 0x2B, 0xA5,
  38388. 0xF7, 0xCF, 0xCE, 0x4C, 0x35, 0x8B, 0x60, 0x80,
  38389. 0x40, 0x0C, 0x5C, 0xC0, 0x85, 0x15, 0x14, 0x92,
  38390. 0xD1, 0x3A, 0x5B, 0x00, 0x96, 0xA0, 0x63, 0x1F,
  38391. 0xAA, 0x30, 0xCB, 0x48, 0xF2, 0xDA, 0x87, 0x3B,
  38392. 0x85, 0x7D, 0xFD, 0xB3, 0x86, 0xD9, 0x33, 0x98,
  38393. 0x18, 0x07, 0x34, 0x92, 0x55, 0x9A, 0x0E, 0xC2,
  38394. 0xDA, 0xF3, 0x73, 0x8E, 0x15, 0x88, 0xB0, 0x98,
  38395. 0x75, 0x1F, 0xF0, 0xFA, 0x1C, 0x87, 0x1B, 0x22,
  38396. 0x23, 0x7E, 0x5C, 0xD1, 0x5B, 0x0E, 0x17, 0x28,
  38397. 0xEA, 0x26, 0x71, 0x66, 0xC3, 0x8A, 0x71, 0x97,
  38398. 0xB6, 0xCC, 0x7D, 0xAD, 0x39, 0x11, 0x6B, 0xE6,
  38399. 0x1D, 0xF4, 0x33, 0x3C, 0xD7, 0xC2, 0xA4, 0x13,
  38400. 0xDB, 0x30, 0x63, 0xD7, 0xF0, 0x22, 0x8C, 0x61,
  38401. 0xFA, 0xDA, 0xC3, 0xF8, 0xC3, 0x31, 0xF4, 0x45,
  38402. 0x09, 0xB4, 0xD6, 0x08, 0x53, 0x1F, 0x99, 0x5D,
  38403. 0x15, 0xFA, 0xB1, 0x19, 0xD8, 0x47, 0xE6, 0xD8,
  38404. 0x54, 0x95, 0x75, 0xB7, 0xD8, 0x50, 0xB2, 0x60,
  38405. 0x0E, 0x4D, 0x13, 0x64, 0x6C, 0xF9, 0x6B, 0x6B,
  38406. 0x9D, 0xA6, 0xC6, 0x2F, 0x2A, 0x80, 0xAE, 0x02,
  38407. 0x58, 0xA8, 0xCD, 0x6E, 0xF4, 0xC5, 0x5E, 0xEA,
  38408. 0x7E, 0x78, 0xD2, 0x0A, 0x46, 0x4A, 0x19, 0x4C,
  38409. 0xEC, 0xBB, 0x01, 0xE7, 0x3F, 0x32, 0x76, 0xD6,
  38410. 0x6E, 0x12, 0xAD, 0x37, 0x74, 0x51, 0xBB, 0xB9,
  38411. 0x4E, 0x5C, 0x94, 0x88, 0x32, 0x59, 0x5F, 0x6B,
  38412. 0x6E, 0x38, 0x2A, 0xD1, 0x42, 0xD9, 0xF1, 0xB8,
  38413. 0x68, 0x97, 0x95, 0xE9, 0xEB, 0xC3, 0x2A, 0x5A,
  38414. 0x10, 0x1E, 0x69, 0x6C, 0xA3, 0x4A, 0xBA, 0x00,
  38415. 0x5B, 0x4C, 0xED, 0xA2, 0x7D, 0x12, 0x00, 0xFE,
  38416. 0x48, 0xFD, 0x82, 0xC1, 0x72, 0x17, 0xE5, 0x08,
  38417. 0xA8, 0x48, 0x4F, 0x03, 0x88, 0x34, 0x5C, 0x9D,
  38418. 0xED, 0xE2, 0xA1, 0x39, 0x28, 0xFA, 0xC3, 0x29,
  38419. 0x21, 0x84, 0x2F, 0x6E, 0x6A, 0xA5, 0xCF, 0xBF,
  38420. 0x57, 0xFA, 0xA2, 0x8F, 0x43, 0xE0, 0x5E, 0x9A,
  38421. 0x45, 0x23, 0x12, 0x50, 0x29, 0x11, 0xEF, 0x9C,
  38422. 0x33, 0xC8, 0x11, 0xEB, 0xE7, 0xCA, 0xD7, 0x30,
  38423. 0x62, 0x3D, 0xB7, 0x04, 0x8E, 0xC2, 0x18, 0xC7,
  38424. 0xEA, 0x9D, 0xFC, 0x6E, 0x19, 0x65, 0xA9, 0x85,
  38425. 0x7E, 0x92, 0x94, 0xC4, 0xE4, 0x7F, 0x4D, 0x96,
  38426. 0x23, 0xCB, 0x74, 0xB6, 0x5F, 0x7B, 0xB5, 0x86,
  38427. 0x22, 0x83, 0x8D, 0xC4, 0x4E, 0x16, 0xD9, 0x15,
  38428. 0xD9, 0x59, 0x65, 0x55, 0xCA, 0x3D, 0x26, 0x1C,
  38429. 0x9C, 0x2A, 0xFC, 0xCB, 0xAF, 0x5A, 0xC0, 0x3D,
  38430. 0xE0, 0x91, 0xF0, 0xDB, 0xEA, 0xE1, 0xB4, 0xA7,
  38431. 0xE3, 0xDE, 0xC4, 0x39, 0x09, 0x89, 0x67, 0x65,
  38432. 0x77, 0xA0, 0x53, 0x68, 0x4F, 0x57, 0x86, 0x8D,
  38433. 0x91, 0xFE, 0x6A, 0x5B, 0x7D, 0x3D, 0x7C, 0x79,
  38434. 0x50, 0x78, 0x9E, 0x89, 0xD8, 0x38, 0x83, 0xBC,
  38435. 0x3D, 0xAE, 0x55, 0xCA, 0x30, 0x78, 0xB0, 0x8D,
  38436. 0x99, 0x18, 0x31, 0xBA, 0x91, 0x50, 0x2A, 0x5A,
  38437. 0x33, 0x54, 0xB8, 0x8E, 0x15, 0x9B, 0x0A, 0xFF,
  38438. 0xD2, 0x5B, 0x0D, 0xBB, 0x72, 0xBC, 0xD6, 0xF4,
  38439. 0x04, 0x65, 0xDD, 0xFC, 0x00, 0xFF, 0x8B, 0x63,
  38440. 0x39, 0xC0, 0x67, 0x09, 0x5D, 0x6C, 0x7C, 0xB0,
  38441. 0x6F, 0x3B, 0xE7, 0x59, 0xC5, 0x27, 0x40, 0x39,
  38442. 0x5D, 0xD1, 0x08, 0x29, 0x6F, 0x2B, 0xBC, 0x2E,
  38443. 0x7A, 0x5D, 0xDD, 0xE3, 0xD1, 0xC3, 0x5D, 0x18,
  38444. 0xBF, 0xBE, 0x39, 0x68, 0xEC, 0x59, 0xAB, 0xF8,
  38445. 0x5C, 0x1B, 0xD2, 0x92, 0x8A, 0xB2, 0xAA, 0x67,
  38446. 0x8A, 0x78, 0x91, 0x74, 0x6E, 0x88, 0xF4, 0x39,
  38447. 0xF8, 0xB4, 0x38, 0x40, 0x31, 0xC3, 0xED, 0xB7,
  38448. 0x31, 0x97, 0xE5, 0x2A, 0x4E, 0x77, 0x3D, 0x2D,
  38449. 0x8B, 0x7B, 0xAD, 0xDC, 0x5D, 0xD0, 0xA7, 0xE4,
  38450. 0x4C, 0x80, 0x8D, 0x73, 0xB8, 0x18, 0x1D, 0x19,
  38451. 0x1C, 0x3C, 0x89, 0xFE, 0x15, 0xEA, 0x90, 0xD7,
  38452. 0x56, 0x7E, 0x89, 0x16, 0xA3, 0x37, 0x83, 0x03,
  38453. 0x05, 0x04, 0x1B, 0x1E, 0x94, 0xB3, 0xB4, 0x06,
  38454. 0xDA, 0x4C, 0x36, 0xBE, 0xF0, 0x5D, 0x91, 0x00,
  38455. 0xAB, 0x99, 0x2A, 0x4D, 0x56, 0x25, 0x33, 0x73,
  38456. 0x0E, 0x0D, 0x8C, 0x05, 0x2B, 0x3A, 0x62, 0xD3,
  38457. 0xF6, 0x9A, 0x83, 0xA0, 0xC9, 0xB2, 0x12, 0x4F,
  38458. 0x12, 0xAE, 0x7D, 0xAC, 0xC9, 0x78, 0xC4, 0xA0,
  38459. 0xAD, 0xCC, 0x2E, 0xBA, 0x2D, 0x80, 0xF4, 0x94,
  38460. 0xAA, 0x16, 0xEC, 0x1E, 0x8E, 0x71, 0xC7, 0x9B,
  38461. 0x02, 0xF3, 0x26, 0x1B, 0x6F, 0x98, 0x68, 0xB8,
  38462. 0xD5, 0x7E, 0x9D, 0x16, 0xF4, 0x2B, 0x7C, 0xC6,
  38463. 0x64, 0x06, 0x54, 0x9A, 0x27, 0x6D, 0x37, 0x14,
  38464. 0x37, 0xDE, 0x88, 0xB7, 0xF3, 0x9E, 0x74, 0x08,
  38465. 0x7C, 0xBB, 0xC5, 0x61, 0x16, 0x80, 0x31, 0x2D,
  38466. 0xE8, 0xF0, 0xC3, 0x68, 0x14, 0xE1, 0x74, 0xF9,
  38467. 0x1E, 0xB6, 0x00, 0xCC, 0x96, 0xE3, 0xCF, 0x51,
  38468. 0xBB, 0x20, 0x25, 0x88, 0x77, 0xA2, 0xAA, 0xEB,
  38469. 0x82, 0x7F, 0x7F, 0x5A, 0xDA, 0x80, 0x78, 0x6B,
  38470. 0x50, 0x84, 0xC8, 0x02, 0xE6, 0x06, 0xDE, 0xF3,
  38471. 0x88, 0xA3, 0x9C, 0xE4, 0xF0, 0xD5, 0xBC, 0x19,
  38472. 0x39, 0x4C, 0xE8, 0x41, 0xE2, 0xD2, 0xAA, 0x74,
  38473. 0x25, 0x23, 0x05, 0x80, 0xFA, 0x66, 0x75, 0xC5,
  38474. 0x17, 0x41, 0xD1, 0x75, 0x87, 0x9B, 0x4D, 0x03,
  38475. 0xC3, 0x90, 0xF6, 0x52, 0xA5, 0x03, 0xA7, 0x51,
  38476. 0x6A, 0x1F, 0x07, 0x5E, 0x30, 0x82, 0xD5, 0x2C,
  38477. 0x60, 0xB8, 0x64, 0x2A, 0x82, 0x40, 0xEE, 0x94,
  38478. 0x4D, 0x5F, 0xB4, 0x27, 0x37, 0x6B, 0x40, 0xB0,
  38479. 0xB2, 0x82, 0xE1, 0x9A, 0xB9, 0x08, 0xCC, 0xF2,
  38480. 0x0C, 0xA9, 0x26, 0x11, 0x64, 0x90, 0xAF, 0xED,
  38481. 0x57, 0xEA, 0xD0, 0xDC, 0x0C, 0x8E, 0x29, 0x6C,
  38482. 0x79, 0xA4, 0x8D, 0x08, 0x8E, 0x83, 0x7A, 0xF0,
  38483. 0x67, 0xDC, 0x02, 0x9E, 0xC6, 0x31, 0xF9, 0x93,
  38484. 0x3E, 0xE4, 0xD2, 0x07, 0x46, 0xE6, 0x4E, 0x5F,
  38485. 0x21, 0x67, 0x55, 0xA1, 0x38, 0x97, 0x4D, 0x30,
  38486. 0x82, 0x93, 0x73, 0x6D, 0xC1, 0x86, 0x04, 0x27,
  38487. 0x6C, 0xC4, 0x18, 0xBA, 0x69, 0xF8, 0x72, 0xB5,
  38488. 0x8E, 0x7F, 0x6E, 0x3A, 0x8B, 0x84, 0x6E, 0xBA,
  38489. 0xAE, 0xB3, 0x83, 0xE7, 0xF8, 0x90, 0xF5, 0x4E,
  38490. 0x77, 0xF5, 0xD7, 0xF5, 0xD4, 0xA5, 0x8D, 0xB7,
  38491. 0x83, 0xEC, 0xA0, 0x49, 0xF1, 0x86, 0x17, 0x12,
  38492. 0x82, 0xBA, 0xC2, 0x60, 0x7D, 0x51, 0xB2, 0x98,
  38493. 0xB1, 0x49, 0x38, 0xEF, 0xB1, 0x92, 0x8F, 0xC8,
  38494. 0xD0, 0x78, 0x06, 0xE8, 0xC3, 0xE7, 0x3B, 0x46,
  38495. 0x46, 0xBC, 0xF1, 0x68, 0x90, 0xCC, 0x13, 0x80,
  38496. 0xE7, 0xB6, 0x33, 0x50, 0x2B, 0x3E, 0xAD, 0xA4,
  38497. 0x47, 0x75, 0x02, 0xE2, 0x46, 0x7C, 0xFD, 0xB9,
  38498. 0xAC, 0xBD, 0x1C, 0x72, 0xBC, 0x6A, 0xEB, 0x4F,
  38499. 0x41, 0xE1, 0xC2, 0x3C, 0x63, 0x68, 0x39, 0xE3,
  38500. 0x57, 0x13, 0x5F, 0x76, 0xBC, 0x39, 0xC4, 0xF9,
  38501. 0xAC, 0x1C, 0xE8, 0xF1, 0xBE, 0xEF, 0xEB, 0xFF,
  38502. 0x87, 0x59, 0xE8, 0xF7, 0x19, 0x65, 0xD4, 0x85,
  38503. 0x4B, 0xEA, 0xAD, 0x0A, 0xFE, 0xDC, 0xA9, 0xD4,
  38504. 0xD6, 0xBD, 0x1E, 0x63, 0xD3, 0x48, 0xA4, 0x2C,
  38505. 0xEE, 0xFF, 0xC1, 0x70, 0xD0, 0xEE, 0x9F, 0x13,
  38506. 0x6F, 0x5B, 0xE9, 0x90, 0x14, 0x66, 0x92, 0x61,
  38507. 0x22, 0xF9, 0x48, 0xBD, 0xDE, 0x2A, 0x91, 0x07,
  38508. 0xD2, 0xA9, 0x8B, 0xA2, 0xDE, 0xA6, 0xD6, 0xF2,
  38509. 0xDA, 0x17, 0x72, 0x47, 0x02, 0xEC, 0x51, 0x8C,
  38510. 0x03, 0x75, 0x3D, 0x51, 0xEA, 0x83, 0x1E, 0x95,
  38511. 0xCB, 0x87, 0x08, 0xD5, 0xDE, 0xC8, 0x22, 0xDB,
  38512. 0x73, 0x7E, 0x44, 0x14, 0x3C, 0x86, 0xF4, 0x71,
  38513. 0x77, 0xD8, 0x5C, 0xD0, 0x98, 0xC2, 0x1B, 0x9B,
  38514. 0xC8, 0x00, 0xDF, 0xA9, 0xDC, 0x26, 0xFD, 0xC2,
  38515. 0x61, 0xE9, 0x21, 0xDE, 0x00, 0x2D, 0x81, 0xC1,
  38516. 0x59, 0xF8, 0xEB, 0x1F, 0xEE, 0x67, 0x67, 0x9D,
  38517. 0x62, 0x1E, 0xCE, 0x6B, 0x36, 0xD0, 0x1C, 0x77,
  38518. 0x5A, 0x16, 0x45, 0xD5, 0x22, 0x92, 0xB4, 0xB2,
  38519. 0xB8, 0x22, 0x73, 0x18, 0x77, 0x2A, 0x80, 0x91,
  38520. 0xE9, 0xEC, 0x01, 0x70, 0x13, 0xB1, 0x95, 0xEB,
  38521. 0xF4, 0xEF, 0x20, 0x1F, 0x4E, 0x88, 0x1C, 0x49,
  38522. 0x36, 0x33, 0xC0, 0x7F, 0x27, 0xC9, 0x79, 0x0D,
  38523. 0xD8, 0xAE, 0xCC, 0x94, 0x49, 0xCF, 0x63, 0xBC,
  38524. 0xB1, 0x19, 0x46, 0x16, 0x9A, 0xCF, 0xF3, 0x95,
  38525. 0x42, 0x26, 0x6B, 0x0C, 0x66, 0x85, 0xBB, 0xB0,
  38526. 0x80, 0xB5, 0x9F, 0x11, 0x7E, 0xEB, 0x2A, 0x73,
  38527. 0x38, 0x2B, 0x3D, 0x18, 0x7C, 0x06, 0x80, 0xC5,
  38528. 0xAE, 0x70, 0x90, 0x70, 0xDF, 0x03, 0xA0, 0x08,
  38529. 0xA7, 0xAD, 0x13, 0x22, 0x6F, 0x3C, 0x37, 0x15,
  38530. 0x39, 0x20, 0x52, 0xF2, 0x44, 0x1B, 0x4A, 0x17,
  38531. 0x8D, 0x7C, 0xF7, 0x05, 0x18, 0x33, 0x9C, 0xFF,
  38532. 0xBB, 0x54, 0xA6, 0xD9, 0xB9, 0xCD, 0xE3, 0xB0,
  38533. 0xB5, 0x7D, 0xBC, 0x79, 0xF4, 0xE4, 0x7A, 0xD6,
  38534. 0x27, 0x4C, 0xE2, 0x18, 0x0C, 0x92, 0xAC, 0x64,
  38535. 0x10, 0xE5, 0x0D, 0x05, 0xF6, 0x66, 0x5A, 0x57,
  38536. 0xD4, 0xD4, 0x47, 0x6C, 0x2C, 0x0E, 0x6E, 0xE0,
  38537. 0x75, 0x7A, 0x3A, 0xFE, 0xA2, 0xB1, 0xBF, 0x86,
  38538. 0xA5, 0x51, 0xEF, 0x98, 0xAA, 0x1D, 0xFC, 0xBA,
  38539. 0x96, 0x31, 0x59, 0x59, 0x45, 0x2B, 0x2B, 0x3A,
  38540. 0x2F, 0xCB, 0xBB, 0x95, 0x5C, 0xB3, 0xFA, 0x1E,
  38541. 0xEB, 0xBB, 0x83, 0xBD, 0x17, 0x87, 0x67, 0xC0,
  38542. 0x2E, 0xFB, 0xBE, 0xFF, 0x6C, 0x7E, 0xEF, 0x94,
  38543. 0xB5, 0x5D, 0xF8, 0x83, 0x1D, 0xDF, 0xB7, 0xB2,
  38544. 0x02, 0xCE, 0x7D, 0xE0, 0x55, 0xEA, 0xF9, 0x92,
  38545. 0x8A, 0xDA, 0xF6, 0xED, 0x0E, 0x31, 0x59, 0xCA,
  38546. 0x56, 0xC4, 0x83, 0xFA, 0x3B, 0xA3, 0xD2, 0x47,
  38547. 0x8C, 0xA3, 0x94, 0x82, 0x4C, 0xEE, 0x6A, 0xBD,
  38548. 0x59, 0x67, 0x09, 0x53, 0xEE, 0x80, 0xD3, 0x83,
  38549. 0xAA, 0xA6, 0x08, 0xE1, 0x58, 0x51, 0x13, 0x5C,
  38550. 0x1C, 0xDE, 0xEE, 0xB5, 0xF6, 0xA8, 0x89, 0x7C,
  38551. 0x3C, 0x9E, 0x06, 0x6A, 0xB4, 0x73, 0x4F, 0xDD,
  38552. 0xFA, 0xBC, 0x3B, 0xC3, 0xBA, 0x12, 0x06, 0xBA,
  38553. 0x54, 0x34, 0xDC, 0xDE, 0xDB, 0x9D, 0x8B, 0x3A,
  38554. 0x81, 0xA2, 0xE6, 0x38, 0x14, 0x6D, 0x83, 0xF1,
  38555. 0x4F, 0x06, 0xE5, 0x60, 0x99, 0xC0, 0xC8, 0xA0,
  38556. 0xFC, 0xCD, 0xB9, 0xEC, 0xF0, 0xF3, 0xD8, 0x8D,
  38557. 0xE3, 0x79, 0x2F, 0x2D, 0x0B, 0x65, 0x1B, 0x61,
  38558. 0x9C, 0x57, 0x1B, 0x69, 0xF4, 0xBF, 0x8E, 0x7C,
  38559. 0xD1, 0x91, 0x0F, 0x26, 0x6A, 0x4D, 0xAD, 0xF8,
  38560. 0xC2, 0xAB, 0xB4, 0xAC, 0x05, 0xBD, 0x1F, 0xBA,
  38561. 0x05, 0x8C, 0x03, 0x94, 0xC0, 0x16, 0xDE, 0xE6,
  38562. 0x0C, 0x66, 0x40, 0x1A, 0x17, 0xD1, 0x34, 0x59,
  38563. 0x54, 0x79, 0x33, 0x38, 0x9A, 0x35, 0x65, 0x69,
  38564. 0xAD, 0xA5, 0x32, 0xC9, 0xF4, 0x87, 0x69, 0x88,
  38565. 0x55, 0xA4, 0xD7, 0xBC, 0xCD, 0x0E, 0xF6, 0x95,
  38566. 0x31, 0x09, 0x4D, 0xA4, 0x08, 0x6F, 0x52, 0xBF,
  38567. 0x98, 0xCD, 0xC9, 0xA4, 0xB0, 0xBC, 0x88, 0x8D,
  38568. 0xC3, 0x89, 0x1A, 0x76, 0x09, 0x6C, 0x7C, 0x48,
  38569. 0x34, 0x90, 0xE9, 0x52, 0x32, 0x6A, 0xE4, 0x02,
  38570. 0xD8, 0xDF, 0xD2, 0xF3, 0xDC, 0xCF, 0x1A, 0xA5,
  38571. 0xD7, 0xBD, 0x69, 0x8E, 0x2A, 0xA8, 0x8D, 0x29,
  38572. 0x48, 0x13, 0xA8, 0x8F, 0xD3, 0x18, 0x66, 0xBC,
  38573. 0xA1, 0x1B, 0x3B, 0x91, 0xC0, 0x09, 0xEE, 0xB6,
  38574. 0x67, 0x60, 0x1C, 0xEE, 0xAF, 0xAF, 0xE9, 0x7C,
  38575. 0x56, 0xFA, 0x33, 0xF9, 0x38, 0x1F, 0x3E, 0x43,
  38576. 0x29, 0x90, 0x1A, 0xC3, 0xB7, 0xEA, 0x70, 0x32,
  38577. 0xC0, 0x19, 0xE5, 0xC8, 0xA8, 0xEF, 0xD7, 0x04,
  38578. 0x4C, 0x97, 0x36, 0x44, 0xAF, 0x2B, 0xE4, 0x20,
  38579. 0xA0, 0x33, 0xC6, 0xC2, 0xC7, 0xCE, 0x0C, 0xEA,
  38580. 0x39, 0x34, 0xDC, 0x18, 0xB4, 0x2A, 0xDF, 0xD7,
  38581. 0xA8, 0x46, 0xF4, 0x2D, 0xD4, 0x06, 0x86, 0x6A,
  38582. 0x39, 0x09, 0x29, 0x02, 0x6A, 0xDE, 0x5C, 0x79,
  38583. 0x1B, 0x5F, 0x61, 0xF9, 0x42, 0xB1, 0x55, 0x07,
  38584. 0x7D, 0x82, 0xF2, 0xAF, 0xCC, 0xFF, 0xF8, 0x5B,
  38585. 0x04, 0x06, 0x64, 0x7A, 0x96, 0x27, 0xE3, 0x69,
  38586. 0x5D, 0x4B, 0xEA, 0x3D, 0x58, 0xA6, 0x3E, 0x17,
  38587. 0x18, 0xD1, 0x84, 0xE4, 0x6B, 0x5F, 0x4B, 0xC8,
  38588. 0x41, 0x03, 0x34, 0xA4, 0x09, 0x5D, 0x0F, 0xAF,
  38589. 0x30, 0x6F, 0xB9, 0xDC, 0x10, 0x94, 0x25, 0xC3,
  38590. 0x16, 0x52, 0xD0, 0x6F, 0xF0, 0x51, 0xA1, 0x62,
  38591. 0xEE, 0x2B, 0x7B, 0x1C, 0x54, 0xD6, 0xC7, 0xDE,
  38592. 0xD6, 0xE3, 0x95, 0xAA, 0xD1, 0xA8, 0x6D, 0x03,
  38593. 0xB1, 0xB6, 0xC8, 0x00, 0x76, 0x7E, 0xC1, 0x44,
  38594. 0x12, 0xEE, 0xCE, 0x13, 0x46, 0x20, 0xA6, 0x1D,
  38595. 0x36, 0x9A, 0xF4, 0x9E, 0x21, 0xB0, 0xD1, 0x4B,
  38596. 0xC4, 0x23, 0x06, 0x49, 0xCD, 0xD3, 0xE9, 0xFD,
  38597. 0x84, 0x7A, 0xE5, 0x0B, 0xE9, 0x62, 0xEF, 0xC8,
  38598. 0xCB, 0x0F, 0x33, 0x9F, 0x9E, 0x6D, 0x32, 0x47,
  38599. 0x53, 0x3B, 0xDE, 0xD8, 0x71, 0x1D, 0x46, 0x1D,
  38600. 0x4A, 0xF2, 0xAE, 0x3F, 0xDD, 0x1D, 0x7D, 0x2A,
  38601. 0x28, 0x9C, 0x78, 0xCB, 0x19, 0xF3, 0xCD, 0xC2,
  38602. 0x14, 0x2B, 0xF5, 0x2B, 0x23, 0xE6, 0xA2, 0x7B,
  38603. 0x39, 0xD6, 0x99, 0x54, 0x3C, 0x3D, 0x63, 0x9B,
  38604. 0x9C, 0x72, 0xCA, 0x80, 0xB3, 0x7E, 0xA2, 0x77,
  38605. 0x5B, 0x5E, 0x26, 0x81, 0xF0, 0xDD, 0x01, 0xDF,
  38606. 0xF0, 0xC0, 0x55, 0x13, 0x36, 0x90, 0x62, 0xFE
  38607. };
  38608. static const byte msg_87[] = {
  38609. 0x9E, 0xFF, 0x34, 0x15, 0x06, 0xD1, 0x8B, 0xCB,
  38610. 0x27, 0xA7, 0xFC, 0x4E, 0xAA, 0xBF, 0x5A, 0x7C,
  38611. 0x4A, 0x59, 0x37, 0x77, 0x19, 0x6F, 0x66, 0x4B,
  38612. 0xCE, 0x31, 0x6C, 0x95, 0x5B, 0x83, 0x5A, 0xD4,
  38613. 0xC9, 0xF5, 0xDE, 0x9A, 0x2B, 0xF8, 0x96, 0x15,
  38614. 0xDA, 0xCB, 0x9C, 0x1E, 0x61, 0x8C, 0x78, 0xE7,
  38615. 0x11, 0x44, 0xCD, 0x4B, 0x70, 0x46, 0xF4, 0x7D,
  38616. 0x9A, 0x60, 0x0E, 0x9C, 0xE6, 0x65, 0x96, 0xC4,
  38617. 0xC5, 0x5E, 0xDA, 0x23, 0xA6, 0x6C, 0xC1, 0x18,
  38618. 0xA4, 0xA7, 0xBD, 0x0D, 0xED, 0x00, 0xAB, 0xDD,
  38619. 0xCE, 0x53, 0xFB, 0xF2, 0x48, 0x20, 0x33, 0xA4,
  38620. 0x18, 0x85, 0x06, 0xEC, 0x11, 0x3B, 0xBD, 0x98,
  38621. 0xD9, 0x89, 0x1F, 0x0D, 0x69, 0x46, 0x3A, 0x0D,
  38622. 0x36, 0x15, 0x6B, 0xA3, 0xEA, 0x0D, 0x02, 0xA1,
  38623. 0x4C, 0x1F, 0xD7, 0xA3, 0xFE, 0x70, 0x4E, 0xE5,
  38624. 0x6B, 0x44, 0x6A, 0xE1, 0x79, 0xF7, 0x2E, 0x10,
  38625. 0x4A, 0xA8, 0x1A, 0xF0, 0xA2, 0xF8, 0xFC, 0xA6,
  38626. 0xF6, 0xF9, 0x62, 0x96, 0x05, 0x9E, 0xE8, 0x82,
  38627. 0x66, 0x80, 0xE4, 0x3F, 0x4B, 0x07, 0x40, 0xF4,
  38628. 0x7A, 0xC1, 0x05, 0x66, 0xED, 0x31, 0x07, 0x99,
  38629. 0xAC, 0x71, 0x41, 0xD3, 0x8F, 0x69, 0x21, 0x31,
  38630. 0x5F, 0x23, 0xAB, 0x3E, 0x64, 0xC8, 0xA7, 0x70,
  38631. 0xAA, 0x57, 0x12, 0x80, 0x90, 0xDB, 0x82, 0x8C,
  38632. 0x7B, 0xAA, 0x59, 0xC3, 0x29, 0x5C, 0xCA, 0xA2,
  38633. 0x38, 0xC7, 0x5F, 0xAC, 0x0F, 0x93, 0xDA, 0x79,
  38634. 0x00, 0x74, 0x1B, 0xCD, 0x94, 0xBB, 0x9F, 0xD3,
  38635. 0x85, 0x2E, 0xC2, 0xB7, 0xD3, 0x3F, 0x60, 0x0B,
  38636. 0x1D, 0x51, 0x66, 0x6A, 0xE2, 0x22, 0xA5, 0x7A,
  38637. 0xF1, 0x40, 0xFA, 0x04, 0x9C, 0x2C, 0x9F, 0x6D,
  38638. 0x0F, 0xE6, 0xC0, 0xF1, 0xE7, 0xA0, 0xDD, 0xE1,
  38639. 0x14, 0x3B, 0xE5, 0xCE, 0xD7, 0xBB, 0xE2, 0x32,
  38640. 0xCB, 0xFB, 0xD8, 0xAE, 0x00, 0xEA, 0x5F, 0xC1,
  38641. 0x65, 0x02, 0x6D, 0x72, 0x9D, 0xB3, 0x0F, 0x6A,
  38642. 0xFD, 0x99, 0x73, 0xB6, 0x72, 0x2C, 0x07, 0xF6,
  38643. 0x00, 0x66, 0x54, 0x41, 0xE3, 0x0B, 0x7C, 0x5F,
  38644. 0xB2, 0x97, 0xB8, 0xAB, 0x96, 0x9C, 0x06, 0x83,
  38645. 0x9D, 0x33, 0x1D, 0xEE, 0x96, 0xDE, 0x48, 0x68,
  38646. 0x7D, 0xC9, 0xDA, 0x53, 0x1A, 0x95, 0xCA, 0x83,
  38647. 0xA7, 0x6F, 0x4B, 0x07, 0x6D, 0xFC, 0xF4, 0x83,
  38648. 0xF0, 0x04, 0x50, 0xE5, 0x1C, 0x8D, 0x34, 0xD8,
  38649. 0xED, 0x8E, 0x4B, 0x3D, 0xAF, 0xAE, 0x66, 0x4B,
  38650. 0x6D, 0xC1, 0x3E, 0xD8, 0x8E, 0x6D, 0x63, 0x02,
  38651. 0x7D, 0xD4, 0x38, 0xCB, 0x74, 0xF4, 0x12, 0xE8,
  38652. 0x70, 0xCC, 0x9D, 0xFD, 0x29, 0xB5, 0x2A, 0xBC,
  38653. 0xA1, 0x69, 0xC1, 0x7E, 0x97, 0x47, 0x58, 0xE0,
  38654. 0x3A, 0xC0, 0xFB, 0x7F, 0xE5, 0x64, 0x50, 0x8E,
  38655. 0x01, 0x7A, 0x9B, 0x47, 0x49, 0xD6, 0x41, 0xAF,
  38656. 0x0D, 0xE3, 0x84, 0x08, 0x8F, 0xA0, 0x0C, 0x69,
  38657. 0x40, 0x23, 0x3D, 0xDE, 0xFB, 0x65, 0x7C, 0x18,
  38658. 0x1C, 0x82, 0xA1, 0xB6, 0xA3, 0x1F, 0xCC, 0xF4,
  38659. 0xD5, 0x2C, 0x9D, 0x35, 0x1E, 0x6B, 0xDF, 0xDF,
  38660. 0x48, 0xBC, 0xE4, 0x14, 0x60, 0x74, 0x62, 0xDB,
  38661. 0x76, 0x9F, 0x9E, 0xB1, 0x59, 0x25, 0xBA, 0x9F,
  38662. 0xAF, 0xBA, 0xB2, 0x29, 0xB5, 0x89, 0x6B, 0xF1,
  38663. 0xF8, 0xE4, 0x7D, 0xF1, 0x7C, 0x82, 0x08, 0xDF,
  38664. 0xD5, 0x96, 0x04, 0xB6, 0x05, 0x2C, 0xD2, 0xCE,
  38665. 0xAB, 0x56, 0x40, 0x0F, 0x11, 0xC4, 0xD9, 0x52,
  38666. 0x1E, 0x1A, 0xB8, 0x27, 0x4A, 0xB5, 0x76, 0x4C,
  38667. 0x73, 0xE9, 0x41, 0x32, 0x42, 0x0E, 0x32, 0xB6,
  38668. 0xAE, 0xB0, 0x76, 0x33, 0x78, 0xD9, 0xBA, 0x68,
  38669. 0xE1, 0xFC, 0xDE, 0x2B, 0xD6, 0xDE, 0xDA, 0x39,
  38670. 0x17, 0xC0, 0x00, 0xAF, 0x39, 0xB7, 0x8F, 0x4C,
  38671. 0xCA, 0x7C, 0x8F, 0xBF, 0x94, 0xB4, 0xCB, 0x8A,
  38672. 0x81, 0x16, 0xEE, 0xEC, 0xFE, 0xF0, 0x13, 0x1E,
  38673. 0xC9, 0xF2, 0xDE, 0xDA, 0x01, 0x40, 0xC9, 0x02,
  38674. 0xA8, 0xD6, 0xE6, 0x0E, 0x98, 0xB3, 0xCD, 0x9D,
  38675. 0x9C, 0x75, 0x24, 0x8B, 0xF8, 0x84, 0x5A, 0xC0,
  38676. 0xD7, 0xE0, 0x6B, 0xA0, 0xE1, 0x83, 0x10, 0xFE,
  38677. 0xCE, 0x98, 0x62, 0x07, 0x54, 0x2C, 0xC1, 0xEE,
  38678. 0x08, 0x88, 0x43, 0xEF, 0x74, 0xA2, 0x6A, 0xEC,
  38679. 0xB6, 0xD0, 0x6F, 0x0F, 0xEF, 0xE1, 0xB7, 0x2C,
  38680. 0xF9, 0x33, 0x06, 0xC3, 0x2E, 0xD2, 0x8A, 0xEC,
  38681. 0xC5, 0x5B, 0xB1, 0x03, 0xA0, 0x84, 0x6D, 0x0C,
  38682. 0x84, 0x13, 0x6D, 0xB0, 0xB0, 0x54, 0xF3, 0xDE,
  38683. 0xA3, 0x9A, 0x72, 0x6C, 0x6F, 0xD6, 0x59, 0x7F,
  38684. 0x9B, 0x03, 0x8C, 0xC2, 0x38, 0x46, 0x01, 0x76,
  38685. 0x38, 0xF4, 0x43, 0x68, 0x81, 0x0D, 0x86, 0x29,
  38686. 0x3D, 0xDF, 0xE5, 0x48, 0x61, 0x53, 0x2F, 0x85,
  38687. 0xF5, 0x3F, 0x09, 0x30, 0x48, 0xC3, 0xE0, 0x09,
  38688. 0xC4, 0x32, 0x11, 0x27, 0xAD, 0xAA, 0xEC, 0x6A,
  38689. 0x5C, 0xCE, 0x03, 0xE0, 0xD9, 0xE9, 0x1D, 0xAC,
  38690. 0xCA, 0xBB, 0x2F, 0x50, 0xE0, 0x1E, 0xB2, 0xAC,
  38691. 0x2B, 0x39, 0x6D, 0x24, 0xB0, 0x5D, 0x45, 0x3B,
  38692. 0xD5, 0x1D, 0x52, 0x9F, 0xBA, 0x51, 0xE4, 0x6D,
  38693. 0x30, 0xC5, 0x66, 0x13, 0x00, 0x5A, 0xBF, 0x62,
  38694. 0x63, 0xB9, 0x8D, 0x8D, 0xFE, 0xB5, 0x26, 0x16,
  38695. 0xD1, 0xCB, 0x78, 0x92, 0x18, 0x1C, 0x2F, 0xC2,
  38696. 0xE2, 0x04, 0x3B, 0x99, 0x4C, 0x81, 0x66, 0x58,
  38697. 0x48, 0x2E, 0x06, 0x06, 0x34, 0x83, 0x78, 0xA3,
  38698. 0xCC, 0x85, 0x40, 0xE0, 0x20, 0x27, 0x3F, 0x10,
  38699. 0xB6, 0x9E, 0x20, 0x21, 0xA9, 0x2D, 0x9C, 0x36,
  38700. 0xCC, 0x9B, 0x97, 0x79, 0xFE, 0x8C, 0xE7, 0xA4,
  38701. 0x99, 0xAE, 0xB5, 0x3E, 0xC6, 0xDD, 0xB4, 0xF2,
  38702. 0xEC, 0x22, 0xBF, 0xB4, 0x52, 0xFC, 0x5E, 0x79,
  38703. 0x7D, 0x3A, 0x25, 0x33, 0x26, 0x00, 0x06, 0xFE,
  38704. 0x6D, 0xCC, 0xE4, 0xE9, 0x76, 0x65, 0xC6, 0x8C,
  38705. 0x39, 0x93, 0xDC, 0x7E, 0xA0, 0xBD, 0x4B, 0xDC,
  38706. 0xD2, 0x47, 0x21, 0xB0, 0x2B, 0x09, 0x02, 0xB1,
  38707. 0x84, 0x0D, 0xDE, 0xC5, 0x18, 0x20, 0x38, 0x76,
  38708. 0x2D, 0x55, 0xFC, 0x11, 0xB9, 0x87, 0x3A, 0x0D,
  38709. 0xD2, 0xEB, 0xBD, 0x55, 0xAD, 0xE3, 0x86, 0x5C,
  38710. 0xFF, 0x3D, 0x54, 0x5F, 0x76, 0x33, 0x53, 0x69,
  38711. 0xDD, 0x9E, 0x70, 0xB0, 0x73, 0x99, 0x77, 0xF6,
  38712. 0xE9, 0x8A, 0x61, 0x27, 0x19, 0x4A, 0x19, 0x26,
  38713. 0xA6, 0x97, 0xE4, 0x7F, 0x73, 0xE0, 0x4F, 0xF5,
  38714. 0xBD, 0x52, 0x5E, 0x8F, 0x17, 0x22, 0x00, 0x8F,
  38715. 0x7C, 0x15, 0x5C, 0xD3, 0xAD, 0xE0, 0xA5, 0xB6,
  38716. 0x6A, 0x31, 0x36, 0xFD, 0xD8, 0x44, 0xAE, 0x5E,
  38717. 0xCD, 0x6C, 0x82, 0x77, 0xC3, 0xD0, 0x7F, 0x39,
  38718. 0x72, 0x1E, 0x91, 0x19, 0x50, 0xE1, 0x28, 0x20,
  38719. 0x88, 0x3A, 0x6B, 0xC8, 0xA9, 0xE7, 0x93, 0x28,
  38720. 0x0F, 0xA7, 0x4F, 0xF2, 0x1A, 0xC2, 0x13, 0x4E,
  38721. 0x6B, 0xAE, 0x71, 0x3F, 0x43, 0x89, 0xC9, 0xE7,
  38722. 0xDD, 0x05, 0xBB, 0x41, 0x09, 0xB5, 0x5E, 0xB9,
  38723. 0x23, 0x51, 0xC0, 0xEB, 0x92, 0x1A, 0x0C, 0x3F,
  38724. 0xAC, 0xC5, 0x00, 0x8C, 0xB8, 0x5C, 0x3F, 0x2D,
  38725. 0x5F, 0x9A, 0xCE, 0xAE, 0x9B, 0x4B, 0x71, 0x48,
  38726. 0x25, 0xFD, 0xE2, 0xB6, 0x26, 0x3F, 0xEE, 0x10,
  38727. 0x33, 0x07, 0x4F, 0x59, 0xF0, 0x73, 0xE9, 0x39,
  38728. 0x5C, 0x0D, 0x8B, 0xB5, 0xD1, 0xEF, 0xE5, 0xBF,
  38729. 0xBB, 0xE1, 0x80, 0xF7, 0xC5, 0x91, 0xC1, 0x72,
  38730. 0xAA, 0xB0, 0x5E, 0x7C, 0x53, 0x69, 0x4C, 0x37,
  38731. 0x7A, 0xD2, 0x7B, 0x9D, 0x1C, 0xFA, 0x0F, 0xE0,
  38732. 0x92, 0x93, 0x40, 0x5D, 0xBE, 0x1C, 0xF8, 0x84,
  38733. 0x7A, 0x35, 0x1F, 0x72, 0x77, 0x68, 0xE2, 0xAF,
  38734. 0xA5, 0x6B, 0x54, 0xFF, 0x53, 0x7C, 0xCD, 0x9D,
  38735. 0x6A, 0x49, 0xD1, 0xCA, 0x74, 0x5F, 0xF5, 0xDB,
  38736. 0x54, 0xF8, 0x60, 0xA7, 0x41, 0x66, 0xDE, 0xFF,
  38737. 0xB0, 0xB2, 0xF9, 0x21, 0x06, 0xB7, 0x81, 0x4C,
  38738. 0x9C, 0xEF, 0xFD, 0x11, 0xD5, 0x63, 0xD8, 0xF3,
  38739. 0x3A, 0x81, 0xC4, 0x9D, 0x1B, 0xA8, 0x37, 0x73,
  38740. 0x57, 0x26, 0x29, 0xF8, 0xB4, 0x7F, 0x9F, 0xA2,
  38741. 0x7D, 0x2A, 0x63, 0x2C, 0x70, 0x08, 0x1E, 0x2E,
  38742. 0xE7, 0xED, 0x73, 0xAB, 0xD2, 0x4C, 0x02, 0x7E,
  38743. 0xF1, 0x15, 0x26, 0xE1, 0x09, 0x5C, 0x29, 0x13,
  38744. 0xDF, 0x69, 0x29, 0x25, 0xE5, 0x68, 0x39, 0x10,
  38745. 0x9B, 0xD0, 0x5E, 0xD8, 0xE2, 0xC9, 0x08, 0x61,
  38746. 0x63, 0xCD, 0xF9, 0x45, 0xBC, 0x16, 0xDC, 0x80,
  38747. 0x4C, 0x0F, 0x61, 0xEE, 0x8F, 0x3B, 0x72, 0xDB,
  38748. 0x02, 0x45, 0xF6, 0x78, 0x69, 0x81, 0xFC, 0xE0,
  38749. 0x32, 0x2F, 0xC2, 0xAF, 0xCD, 0x4E, 0x8E, 0x52,
  38750. 0x03, 0xB5, 0x1C, 0x7C, 0x37, 0x2C, 0x58, 0xD5,
  38751. 0xE2, 0x92, 0xA7, 0xE2, 0x49, 0x6C, 0x3F, 0x5D,
  38752. 0x7F, 0x2B, 0x26, 0x70, 0x1C, 0x0C, 0x16, 0x7F,
  38753. 0x49, 0x30, 0x71, 0x14, 0xEB, 0xBE, 0x13, 0xF4,
  38754. 0xF1, 0xAA, 0x5A, 0xCF, 0x98, 0xF2, 0x07, 0x29,
  38755. 0xB5, 0x12, 0x84, 0x80, 0x01, 0x46, 0x11, 0xA4,
  38756. 0x44, 0xAE, 0x6D, 0xE0, 0x43, 0x7F, 0xFD, 0x5D,
  38757. 0x84, 0xB5, 0x6E, 0x3E, 0x55, 0x0D, 0xE8, 0x66,
  38758. 0x13, 0xA9, 0x28, 0x5A, 0x10, 0x84, 0x0B, 0xED,
  38759. 0x0B, 0x69, 0xF0, 0x19, 0x69, 0x9B, 0x34, 0xB8,
  38760. 0x6F, 0xC6, 0x22, 0xD3, 0x25, 0x26, 0x9D, 0x1A,
  38761. 0x04, 0x6B, 0x53, 0xA4, 0xDF, 0x12, 0x93, 0xA5,
  38762. 0x2C, 0xEE, 0x1C, 0x35, 0xFE, 0x81, 0x6B, 0x67,
  38763. 0x81, 0x92, 0x07, 0xE0, 0x9A, 0x02, 0xC9, 0xD8,
  38764. 0x59, 0x4D, 0x51, 0xE8, 0xB3, 0x14, 0x55, 0x2F,
  38765. 0xDE, 0x26, 0xDB, 0x7C, 0xEB, 0x8D, 0x80, 0x12,
  38766. 0x4A, 0x8A, 0x1C, 0x33, 0x74, 0x8E, 0x05, 0xC1,
  38767. 0xAF, 0xD6, 0xE8, 0x7B, 0x56, 0x7C, 0x41, 0xE0,
  38768. 0xE7, 0x3F, 0x32, 0x5F, 0x25, 0xDD, 0x2F, 0x48,
  38769. 0x21, 0x90, 0xC4, 0x04, 0x42, 0x1A, 0x3D, 0x6A,
  38770. 0x0E, 0x5D, 0x5C, 0xDB, 0xE2, 0xB0, 0x18, 0x8B,
  38771. 0xAC, 0x77, 0xC6, 0xE3, 0x5D, 0x77, 0xC0, 0xA3,
  38772. 0x2B, 0x1D, 0x96, 0x29, 0xF8, 0x8E, 0x70, 0xA7,
  38773. 0x65, 0xFE, 0xE3, 0x8C, 0x1A, 0xB2, 0x39, 0x75,
  38774. 0xB9, 0x45, 0xF2, 0x16, 0x1F, 0x6C, 0xFE, 0x7E,
  38775. 0x68, 0x2A, 0xED, 0x96, 0x84, 0x95, 0x47, 0x05,
  38776. 0x1D, 0xDE, 0xB7, 0x7B, 0x90, 0xF6, 0xAF, 0x00,
  38777. 0x74, 0x7C, 0x47, 0xE0, 0x2E, 0x80, 0xB6, 0x9A,
  38778. 0x0D, 0x4B, 0x78, 0xA4, 0x7D, 0xDD, 0x81, 0xE2,
  38779. 0x99, 0x27, 0x1F, 0xA7, 0x8F, 0xE4, 0x23, 0xAD,
  38780. 0xDF, 0x12, 0x0D, 0xD0, 0x4D, 0x46, 0xC1, 0x32,
  38781. 0xE9, 0x70, 0xF4, 0xA0, 0x4E, 0x97, 0xA5, 0x88,
  38782. 0xD2, 0x7C, 0x7B, 0xA8, 0x43, 0x26, 0x18, 0x2A,
  38783. 0xAE, 0x04, 0xC2, 0x51, 0x28, 0x99, 0x71, 0x69,
  38784. 0x1D, 0x96, 0x78, 0xD4, 0x09, 0x88, 0x16, 0x88,
  38785. 0xF3, 0xBC, 0xCB, 0x95, 0x08, 0x30, 0xE6, 0x5B,
  38786. 0x78, 0x48, 0x41, 0x00, 0x4E, 0x40, 0x44, 0x58,
  38787. 0xE6, 0x16, 0x59, 0x63, 0xCF, 0xB4, 0xEE, 0xB5,
  38788. 0x05, 0xFD, 0xD1, 0x35, 0xF3, 0x1E, 0xD0, 0x14,
  38789. 0x7C, 0xC9, 0xE9, 0x87, 0x7F, 0xFF, 0x41, 0x07,
  38790. 0x68, 0x91, 0x06, 0x17, 0x4E, 0x76, 0x66, 0xEE,
  38791. 0xCB, 0x6C, 0xF2, 0xDA, 0x9C, 0x93, 0x51, 0xDC,
  38792. 0x43, 0x4A, 0x94, 0x49, 0x38, 0x4E, 0xED, 0x7F,
  38793. 0x5F, 0x90, 0x77, 0xB4, 0x2F, 0x0F, 0xC5, 0xD9,
  38794. 0xF0, 0xF5, 0xF7, 0x21, 0x91, 0x32, 0xFF, 0x9A,
  38795. 0x47, 0x09, 0x83, 0xE1, 0x9D, 0x30, 0xA4, 0xF3,
  38796. 0x7D, 0x18, 0x97, 0x44, 0xD8, 0x32, 0xFD, 0x5F,
  38797. 0xB3, 0x97, 0x49, 0x4E, 0x11, 0xAD, 0xF7, 0x4F,
  38798. 0x4E, 0x90, 0x0A, 0x41, 0x87, 0xCF, 0xF5, 0xDA,
  38799. 0x8F, 0x6D, 0x7B, 0x35, 0xAE, 0xA0, 0x16, 0xA8,
  38800. 0xDE, 0x88, 0x62, 0x26, 0x5F, 0x13, 0x69, 0xFB,
  38801. 0x36, 0x7E, 0xF1, 0x86, 0x0C, 0x8E, 0x07, 0xC3,
  38802. 0x3F, 0x32, 0x82, 0xB4, 0xD9, 0x83, 0x7C, 0xDF,
  38803. 0x3E, 0xF6, 0x58, 0x42, 0x2D, 0x34, 0xDE, 0xA4,
  38804. 0x1E, 0x56, 0xDD, 0x18, 0x70, 0x36, 0x81, 0xD0,
  38805. 0x44, 0xE3, 0xC4, 0x03, 0xAF, 0x33, 0xD1, 0xE7,
  38806. 0xAF, 0xA9, 0x6A, 0x8C, 0x44, 0x35, 0xFE, 0xBB,
  38807. 0xA0, 0xD2, 0x5D, 0xE0, 0xE4, 0xAE, 0xDF, 0xFB,
  38808. 0x82, 0xA0, 0xBA, 0xDE, 0x76, 0xB6, 0x6C, 0xA9,
  38809. 0xBE, 0xC7, 0xE9, 0xD7, 0x3F, 0x1C, 0xB2, 0x9C,
  38810. 0xD7, 0x3C, 0xF0, 0x0C, 0x2F, 0x60, 0x44, 0xD8,
  38811. 0x34, 0x53, 0xCE, 0xDD, 0xE0, 0x3F, 0x97, 0x2E,
  38812. 0xBB, 0x03, 0x20, 0x62, 0xD0, 0xA8, 0x23, 0x9F,
  38813. 0xB6, 0x99, 0xEC, 0x89, 0x0D, 0x32, 0x0F, 0x6F,
  38814. 0xAF, 0x3D, 0x20, 0x7B, 0xDC, 0x9A, 0xFE, 0xA2,
  38815. 0x02, 0x8B, 0x86, 0x99, 0x56, 0x23, 0x43, 0xAA,
  38816. 0x50, 0xF7, 0x0A, 0x4E, 0x8C, 0x62, 0xDA, 0xF8,
  38817. 0xB8, 0xCC, 0xA7, 0x2D, 0x02, 0x47, 0x63, 0xBA,
  38818. 0xEC, 0x25, 0x00, 0x23, 0xEA, 0xE8, 0x25, 0xC6,
  38819. 0x51, 0xAC, 0xC4, 0xAA, 0xA0, 0xDB, 0x6C, 0x5E,
  38820. 0xC7, 0xEF, 0xD0, 0x71, 0xED, 0xFB, 0x95, 0xAF,
  38821. 0x61, 0x0B, 0x64, 0x01, 0x61, 0x4F, 0x4F, 0xC6,
  38822. 0x36, 0x27, 0x75, 0xC3, 0x81, 0x0A, 0x9A, 0x21,
  38823. 0x69, 0xF8, 0x4A, 0x21, 0x12, 0x3B, 0x03, 0x1C,
  38824. 0xCE, 0x08, 0x7D, 0x52, 0x0E, 0x99, 0xE2, 0x62,
  38825. 0xE8, 0x81, 0x2E, 0x84, 0x09, 0x8E, 0xBE, 0x9B,
  38826. 0xCE, 0xD6, 0xE6, 0xA4, 0xF7, 0x3B, 0x67, 0x45,
  38827. 0x41, 0xDE, 0x0B, 0xCF, 0x5E, 0x7E, 0x31, 0x8F,
  38828. 0x90, 0x6D, 0x90, 0x1F, 0xEB, 0x1D, 0x9D, 0x1C,
  38829. 0xCB, 0x6C, 0xFF, 0xE8, 0x50, 0xDB, 0xFF, 0x75,
  38830. 0xC8, 0xA8, 0x9F, 0x43, 0xCB, 0x94, 0x89, 0x5F,
  38831. 0x28, 0x69, 0x6F, 0xAB, 0xB6, 0xAD, 0xCE, 0xE7,
  38832. 0x69, 0x7E, 0x60, 0x09, 0x03, 0x87, 0x43, 0x6E,
  38833. 0x19, 0xB1, 0x38, 0x81, 0x9B, 0x90, 0xAE, 0xB1,
  38834. 0x8A, 0xC2, 0x7D, 0x2C, 0x65, 0x9B, 0x0D, 0xF1,
  38835. 0x77, 0x94, 0xA7, 0x2F, 0x8B, 0xB7, 0xCE, 0x03,
  38836. 0xEE, 0x9A, 0x78, 0xFE, 0x8C, 0x8A, 0x37, 0x45,
  38837. 0xD5, 0x05, 0xDE, 0xD8, 0x85, 0x00, 0xF4, 0xCF,
  38838. 0x98, 0xFB, 0x62, 0x85, 0xB0, 0xBD, 0x82, 0xE2,
  38839. 0x7D, 0xED, 0x93, 0x3B, 0xCC, 0x18, 0x73, 0xF8,
  38840. 0x8A, 0xBD, 0x82, 0x8F, 0x60, 0x47, 0xAC, 0xEC,
  38841. 0x47, 0x2D, 0xEA, 0xE8, 0x7D, 0x8A, 0xDE, 0x0A,
  38842. 0xD0, 0x73, 0x48, 0xFF, 0xAF, 0x59, 0xC1, 0x70,
  38843. 0x29, 0xD8, 0x45, 0x38, 0x77, 0x7F, 0x73, 0xBF,
  38844. 0xED, 0x5C, 0x63, 0x63, 0x0B, 0xC4, 0x43, 0xE0,
  38845. 0xFA, 0x12, 0xDE, 0x72, 0x2D, 0xAB, 0xBB, 0xC2,
  38846. 0x25, 0x0A, 0xBA, 0x3F, 0xD8, 0x61, 0x54, 0xEE,
  38847. 0x20, 0x8D, 0x53, 0xA3, 0x27, 0xA7, 0xFF, 0x26,
  38848. 0xA0, 0x17, 0x93, 0x39, 0x4D, 0x04, 0x15, 0x8B,
  38849. 0xB3, 0x20, 0x60, 0x04, 0x47, 0xE2, 0xFD, 0x7D,
  38850. 0x7C, 0x6D, 0xE0, 0x76, 0xA5, 0x13, 0xD6, 0x81,
  38851. 0x95, 0xB0, 0x67, 0x20, 0x4F, 0xF6, 0x00, 0x5B,
  38852. 0x16, 0x25, 0x54, 0x2B, 0x28, 0x37, 0x2F, 0x06,
  38853. 0x80, 0x60, 0x53, 0xAE, 0xE2, 0xEA, 0x9F, 0x88,
  38854. 0xAE, 0xA2, 0x9A, 0x27, 0x02, 0x15, 0x4B, 0xF4,
  38855. 0x43, 0xBC, 0x70, 0x7D, 0x0A, 0x96, 0xEB, 0x06,
  38856. 0xCE, 0x43, 0xEF, 0xE6, 0x6A, 0xAC, 0x1F, 0x16,
  38857. 0x95, 0xE2, 0x8C, 0xF1, 0x07, 0x19, 0x3D, 0x06,
  38858. 0x2E, 0x71, 0xB6, 0x3A, 0xFD, 0xCF, 0x9E, 0x05,
  38859. 0x0B, 0xBE, 0xD7, 0x48, 0x4E, 0xC5, 0xE8, 0x0C,
  38860. 0x51, 0x5A, 0xC8, 0x20, 0xF0, 0xCD, 0xF9, 0x65,
  38861. 0xDD, 0x97, 0xF7, 0xA1, 0x1B, 0x57, 0xB2, 0x1A,
  38862. 0x04, 0xBF, 0x42, 0xF2, 0xA3, 0x3D, 0x61, 0x97,
  38863. 0x64, 0xDF, 0xB3, 0x63, 0x11, 0xFD, 0xAD, 0x8C,
  38864. 0x83, 0xA7, 0x48, 0xBA, 0x34, 0x42, 0xC5, 0x70,
  38865. 0x64, 0x5A, 0x78, 0x5E, 0x67, 0x03, 0xE5, 0xBF,
  38866. 0x22, 0xE8, 0x46, 0xFC, 0x51, 0x6C, 0xB4, 0x99,
  38867. 0x15, 0xFD, 0x63, 0xB6, 0x3E, 0x5D, 0xBF, 0x56,
  38868. 0xF5, 0x5E, 0xA4, 0x01, 0x16, 0xD5, 0x03, 0x4B,
  38869. 0xBB, 0x94, 0x5F, 0x58, 0xD6, 0x76, 0x95, 0xC7,
  38870. 0x96, 0xF1, 0xC1, 0xD0, 0x53, 0xA3, 0xEB, 0x28,
  38871. 0xA9, 0x5E, 0x8F, 0x38, 0x8E, 0x80, 0x04, 0xC3,
  38872. 0xB2, 0x4F, 0xD5, 0xFC, 0xCA, 0x7B, 0xB1, 0xE3,
  38873. 0xB9, 0x9A, 0x9F, 0x3C, 0x94, 0x5E, 0xF8, 0xA5,
  38874. 0x35, 0xF1, 0x37, 0x43, 0x20, 0x71, 0xA5, 0xCA,
  38875. 0x5B, 0x6F, 0x7D, 0xC7, 0xB8, 0xBC, 0xE5, 0x5A,
  38876. 0xD0, 0xF3, 0xB6, 0xCF, 0x1B, 0xCB, 0xB9, 0xCD,
  38877. 0x35, 0xE2, 0x41, 0xF8, 0x6E, 0x46, 0x97, 0x27,
  38878. 0x26, 0x48, 0xF4, 0x73, 0xDB, 0xD5, 0xB7, 0x68,
  38879. 0x1E, 0xF0, 0xC7, 0x84, 0x49, 0xE6, 0xC5, 0xFA,
  38880. 0x93, 0x0D, 0x83, 0x2C, 0x85, 0x1E, 0xED, 0x2A,
  38881. 0x65, 0x12, 0x19, 0xD7, 0xD9, 0xC3, 0xBB, 0x23,
  38882. 0xF3, 0xC6, 0xAD, 0x7E, 0xB7, 0x78, 0x68, 0x54,
  38883. 0x1F, 0x3C, 0xEE, 0x09, 0xF5, 0x1E, 0xE0, 0x4E,
  38884. 0xBA, 0x1B, 0xBC, 0x29, 0x69, 0x8A, 0xED, 0xD3,
  38885. 0xC7, 0xAC, 0xEC, 0x44, 0x29, 0xD7, 0xA4, 0x0C,
  38886. 0xFA, 0xBD, 0xA2, 0x29, 0x34, 0x80, 0x16, 0x4F,
  38887. 0x37, 0xEC, 0xB6, 0x73, 0xF2, 0xB5, 0xD7, 0x51,
  38888. 0x57, 0x43, 0xAF, 0x7E, 0xD0, 0xB6, 0xE0, 0x96,
  38889. 0xF0, 0xE2, 0xFE, 0xCE, 0xC8, 0x9F, 0x40, 0xD6,
  38890. 0xAF, 0xE0, 0xBF, 0xCD, 0x70, 0x37, 0x91, 0x69,
  38891. 0x99, 0x8C, 0xDF, 0x4A, 0x20, 0xDE, 0xB6, 0xC6,
  38892. 0x7A, 0xB4, 0xE3, 0x6A, 0xAD, 0x53, 0xED, 0xB9,
  38893. 0x8A, 0x13, 0x61, 0xC5, 0xE9, 0xB0, 0xDC, 0x16,
  38894. 0x36, 0xD7, 0x51, 0xA8, 0x7B, 0x52, 0x05, 0x3B,
  38895. 0xAD, 0x5C, 0xD2, 0xBD, 0x6F, 0x6B, 0xA9, 0x51,
  38896. 0xA7, 0xE8, 0x7E, 0xA4, 0xB6, 0x77, 0xAE, 0x00,
  38897. 0x89, 0x3A, 0x1F, 0x76, 0x72, 0x3F, 0xC5, 0x6C,
  38898. 0x49, 0x4F, 0xB5, 0xCA, 0x2F, 0x5D, 0xAE, 0xF8,
  38899. 0x58, 0x9A, 0xE2, 0x5B, 0x54, 0x76, 0xF4, 0xAA,
  38900. 0x89, 0xD4, 0x04, 0xAF, 0x1C, 0x26, 0x65, 0xEC,
  38901. 0xA1, 0x81, 0x06, 0x2A, 0x4B, 0x5E, 0xD5, 0x90,
  38902. 0xB8, 0x26, 0x33, 0x64, 0x15, 0x33, 0x25, 0xAC,
  38903. 0x97, 0x9A, 0xCA, 0x1B, 0x64, 0x50, 0x82, 0x8F,
  38904. 0x65, 0x6A, 0xD4, 0x47, 0xCF, 0x7E, 0x93, 0x7D,
  38905. 0xB3, 0xCB, 0xFE, 0x55, 0x0A, 0x46, 0x93, 0x22,
  38906. 0xB5, 0x46, 0xAB, 0xD6, 0x05, 0x59, 0x14, 0x5E,
  38907. 0x1B, 0xD4, 0x2D, 0xAF, 0xA3, 0x18, 0xB7, 0xA0,
  38908. 0xD7, 0x11, 0x70, 0xDE, 0x81, 0x8B, 0xD6, 0x64,
  38909. 0xFD, 0x38, 0xBD, 0x29, 0x92, 0x41, 0x80, 0xC4,
  38910. 0x4A, 0x6D, 0x34, 0x1B, 0xF0, 0x59, 0xA0, 0xD6,
  38911. 0x48, 0x55, 0xD2, 0xA5, 0xE2, 0x91, 0xB6, 0x71,
  38912. 0xF4, 0x90, 0x97, 0x8B, 0x0A, 0xDD, 0x90, 0xEA,
  38913. 0x61, 0x9B, 0x30, 0xA6, 0x2F, 0x5D, 0xB4, 0xEE,
  38914. 0x7A, 0x10, 0x40, 0x59, 0x89, 0xAC, 0x30, 0x6E,
  38915. 0x9C, 0x7B, 0xBC, 0x11, 0x75, 0x38, 0x00, 0x2E,
  38916. 0xDF, 0xED, 0x87, 0x47, 0x30, 0xFB, 0xD4, 0x8A,
  38917. 0xC6, 0xBE, 0xC7, 0x20, 0xC8, 0x3D, 0x51, 0x05,
  38918. 0x67, 0x48, 0xDE, 0xE2, 0xBF, 0x95, 0x5E, 0x7B,
  38919. 0xD7, 0xC7, 0x86, 0xDF, 0x68, 0x57, 0xA9, 0x29,
  38920. 0xBC, 0xF8, 0xE3, 0x81, 0x62, 0x1B, 0x37, 0x58,
  38921. 0xF2, 0xFF, 0xEE, 0xE8, 0x28, 0x08, 0x36, 0x23,
  38922. 0x5B, 0x24, 0x68, 0x1E, 0x62, 0xBD, 0x27, 0xC2,
  38923. 0x6F, 0xE9, 0x63, 0x67, 0x53, 0xC7, 0x8A, 0xB5,
  38924. 0xA7, 0xEF, 0x29, 0xFE, 0x60, 0xAC, 0x29, 0xCF,
  38925. 0x67, 0x40, 0x9F, 0xE6, 0x57, 0xCE, 0x65, 0x3A,
  38926. 0x2F, 0xDA, 0xA7, 0xF2, 0x0C, 0x50, 0x19, 0xE6,
  38927. 0xF7, 0x43, 0x2E, 0x8C, 0xEB, 0x9E, 0x99, 0x92,
  38928. 0xE6, 0x46, 0xB7, 0x8D, 0x43, 0x65, 0xFD, 0x02,
  38929. 0x17, 0x74, 0x6F, 0x7B, 0xA3, 0x1E, 0x06, 0x9D,
  38930. 0x75, 0x4E, 0x05, 0xED, 0x5A, 0x71, 0xFC, 0x5E,
  38931. 0x7D, 0x6D, 0x64, 0x5E, 0xAF, 0x41, 0x44, 0xD6,
  38932. 0xBC, 0x43, 0x05, 0x5E, 0x6C, 0xDB, 0x89, 0x34,
  38933. 0xC7, 0x02, 0x64, 0x08, 0xAE, 0x96, 0x53, 0x5B,
  38934. 0xA2, 0xDE, 0xCD, 0x2F, 0x74, 0x56, 0xD6, 0xEC,
  38935. 0xA4, 0x23, 0x68, 0xCD, 0x9A, 0xC5, 0x05, 0x7B,
  38936. 0x7D, 0x1E, 0x12, 0xF7, 0x7A, 0xA8, 0x7C, 0x43,
  38937. 0x7E, 0x7A, 0x43, 0x31, 0x5D, 0xA0, 0x81, 0xE5,
  38938. 0x3A, 0xFE, 0x23, 0xB5, 0xBC, 0xC2, 0xF4, 0xCE,
  38939. 0x3A, 0x80, 0x06, 0xE8, 0x1E, 0x08, 0xAF, 0x0A,
  38940. 0x33, 0xC1, 0xA9, 0x30, 0x7C, 0x8D, 0x5A, 0xC5,
  38941. 0x93, 0x89, 0xF2, 0x69, 0x24, 0x11, 0x6C, 0xAB,
  38942. 0x0B, 0x87, 0xD5, 0x49, 0xD0, 0x38, 0x3C, 0x27,
  38943. 0x4E, 0x8E, 0x85, 0xD4, 0x6E, 0x0F, 0xCD, 0x70,
  38944. 0xE3, 0x68, 0x42, 0xCA, 0x4C, 0x8D, 0x6D, 0x0F,
  38945. 0x48, 0xF3, 0xED, 0xF9, 0xE9, 0x43, 0x5D, 0xBF,
  38946. 0x55, 0x75, 0xF8, 0xEB, 0x78, 0x93, 0x72, 0x75,
  38947. 0x8B, 0xF5, 0xBD, 0xE9, 0x9D, 0xA2, 0xB9, 0x81,
  38948. 0x83, 0xDB, 0xAC, 0x82, 0xD1, 0xC1, 0x20, 0x03,
  38949. 0x72, 0x4D, 0xDC, 0x42, 0xAE, 0xC8, 0x1C, 0x0C,
  38950. 0x78, 0x22, 0x77, 0x27, 0x91, 0x50, 0x4C, 0x90,
  38951. 0xEA, 0x13, 0x8B, 0x6C, 0x91, 0xDF, 0x5D, 0x25,
  38952. 0x36, 0x9C, 0xC2, 0x06, 0x4F, 0xD5, 0xE2, 0xCC,
  38953. 0x9D, 0x89, 0x3B, 0xC4, 0x23, 0x5D, 0x88, 0x17,
  38954. 0x62, 0x4E, 0xC9, 0xFA, 0xC8, 0xEF, 0x1D, 0x45,
  38955. 0xE1, 0xFB, 0x58, 0xB3, 0x8E, 0xBD, 0x8D, 0xAE,
  38956. 0x12, 0xFF, 0xA0, 0x37, 0xE0, 0x7F, 0x5B, 0x41,
  38957. 0x1D, 0x40, 0x17, 0xAF, 0x95, 0x2D, 0x8C, 0x42,
  38958. 0xC6, 0x1A, 0x2A, 0x1E, 0x8E, 0x70, 0x25, 0xD6,
  38959. 0xD3, 0xA2, 0x85, 0xAA, 0x17, 0xFF, 0x0D, 0xB4,
  38960. 0x39, 0xD0, 0xF2, 0xAF, 0xA0, 0x4F, 0x31, 0x8D,
  38961. 0x6D, 0x57, 0x6A, 0xED, 0xC6, 0xF1, 0xE7, 0x67,
  38962. 0xA6, 0x6F, 0xB3, 0x9B, 0x72, 0xC6, 0x7F, 0x05,
  38963. 0xAF, 0x40, 0x87, 0x12, 0x0D, 0xC8, 0x98, 0x88,
  38964. 0x2D, 0xDE, 0xA1, 0x7C, 0x95, 0x32, 0xB2, 0x7A,
  38965. 0xB5, 0x9D, 0xE4, 0x0D, 0x75, 0xD4, 0x17, 0x5B,
  38966. 0xB4, 0x92, 0x73, 0xAF, 0x87, 0x3A, 0x92, 0xDA,
  38967. 0x4D, 0x87, 0xE2, 0x53, 0xCA, 0xE7, 0x2A, 0x52,
  38968. 0x64, 0xE0, 0xC1, 0xDE, 0x4C, 0x9C, 0xF9, 0x1A,
  38969. 0x1F, 0x3A, 0xD6, 0x05, 0xA0, 0xCC, 0x8D, 0x91,
  38970. 0x93, 0x51, 0xF9, 0x37, 0x1A, 0xFC, 0x68, 0xEF,
  38971. 0xBC, 0xED, 0x19, 0x8E, 0x4C, 0xD1, 0xB5, 0x8C,
  38972. 0xA2, 0x85, 0xDA, 0x02, 0x65, 0xAB, 0xAC, 0xAE,
  38973. 0xCA, 0x8E, 0xAC, 0xF0, 0x2A, 0x4F, 0xC7, 0x67,
  38974. 0x16, 0x2E, 0x24, 0x7F, 0x73, 0xCD, 0xD7, 0x3E,
  38975. 0xE3, 0x27, 0x8A, 0xF9, 0x4A, 0xC4, 0xA8, 0xCB,
  38976. 0x2B, 0x01, 0x55, 0x68, 0x34, 0xA3, 0xC0, 0xB8,
  38977. 0xD0, 0x6D, 0x05, 0xF2, 0x3B, 0x4C, 0x17, 0x47,
  38978. 0xE7, 0x64, 0x53, 0xF4, 0x9D, 0xE0, 0x8D, 0xF8,
  38979. 0xEE, 0x0E, 0xA6, 0x25, 0x64, 0x7D, 0x1B, 0xD0,
  38980. 0x80, 0xE7, 0x3C, 0x41, 0x97, 0xAE, 0xCB, 0x6A,
  38981. 0x23, 0xC2, 0x5F, 0x00, 0xC6, 0xC5, 0x4C, 0x8A,
  38982. 0x4C, 0xEF, 0x76, 0x65, 0x95, 0x28, 0xB3, 0x67,
  38983. 0x42, 0xEC, 0x17, 0xFF, 0x0E, 0xE3, 0x7B, 0x30,
  38984. 0x6D, 0xCC, 0xB8, 0x87, 0xD6, 0x63, 0x36, 0x5D,
  38985. 0xC9, 0xE8, 0x1D, 0x51, 0x47, 0xCF, 0xE5, 0x05,
  38986. 0x0D, 0xB4, 0x09, 0xDF, 0xAD, 0x88, 0x9C, 0x38,
  38987. 0x6F, 0x12, 0xA5, 0xCD, 0x0C, 0x95, 0x53, 0x41,
  38988. 0x13, 0xA6, 0xD0, 0xAB, 0xCB, 0x5A, 0x3F, 0x56,
  38989. 0xCE, 0x23, 0xEE, 0x32, 0x61, 0x22, 0x79, 0xE8,
  38990. 0xBA, 0x23, 0x94, 0x61, 0x25, 0x8E, 0xD6, 0x3E,
  38991. 0x78, 0x83, 0xE1, 0x15, 0xBA, 0x05, 0x81, 0xB8,
  38992. 0x1A, 0x7F, 0x73, 0xC1, 0xB7, 0x9F, 0x29, 0xA1,
  38993. 0x16, 0x2E, 0x6E, 0x84, 0xC7, 0x15, 0xBC, 0x50,
  38994. 0x28, 0x5F, 0xD3, 0x8D, 0x4D, 0x6D, 0xC0, 0x87,
  38995. 0x68, 0x88, 0x4B, 0xF4, 0xFB, 0x55, 0x85, 0x3D,
  38996. 0xA7, 0xB5, 0x47, 0x1E, 0x73, 0xA1, 0x47, 0x8D,
  38997. 0xB1, 0xE1, 0xCF, 0xE6, 0x15, 0x3E, 0xC6, 0xC3,
  38998. 0x78, 0xDD, 0x6A, 0x3F, 0x42, 0x29, 0x6E, 0x61,
  38999. 0x9D, 0xE7, 0x63, 0xFF, 0x2D, 0xDB, 0x83, 0xE5,
  39000. 0x15, 0x84, 0xC2, 0x8D, 0xD8, 0x34, 0x2E, 0x92,
  39001. 0x9E, 0x15, 0xB7, 0xBB, 0xCF, 0x5D, 0x6E, 0xCB,
  39002. 0x87, 0x79, 0xCF, 0x7F, 0x3A, 0x9A, 0xC1, 0x6A,
  39003. 0x43, 0x1F, 0x52, 0xA2, 0x34, 0xE6, 0xA3, 0x69,
  39004. 0x9D, 0x9E, 0x44, 0x84, 0x0A, 0x4D, 0x3D, 0x48,
  39005. 0x5D, 0xA5, 0xD9, 0x03, 0x94, 0xB1, 0x81, 0xEF,
  39006. 0x89, 0x98, 0xE6, 0xD1, 0x44, 0x21, 0x83, 0x59,
  39007. 0x09, 0xCD, 0xDB, 0x16, 0x7C, 0x8C, 0x38, 0x78,
  39008. 0x19, 0x4B, 0x6D, 0x51, 0x4D, 0xF8, 0x63, 0x6D,
  39009. 0x4A, 0x14, 0xA1, 0xBE, 0xF3, 0xCA, 0x38, 0x1E,
  39010. 0x36, 0xCF, 0x2E, 0x6D, 0x5F, 0xBC, 0xB4, 0x0A,
  39011. 0xF0, 0x91, 0x7D, 0x6D, 0xBB, 0x87, 0x5C, 0xFF,
  39012. 0x64, 0xCD, 0xCE, 0xCC, 0xCF, 0xB8, 0xBF, 0xB8,
  39013. 0x05, 0x45, 0x8D, 0xF8, 0x2C, 0x74, 0xEB, 0x86,
  39014. 0x3A, 0x96, 0x9E, 0xD9, 0x8B, 0x9C, 0x46, 0xE7,
  39015. 0x17, 0x3C, 0x09, 0x0D, 0xB0, 0x68, 0xB2, 0xD8,
  39016. 0x0C, 0xCE, 0x32, 0xDE, 0x51, 0x72, 0xB5, 0xD4,
  39017. 0xA8, 0xB9, 0x09, 0xA5, 0xA4, 0xCC, 0x47, 0xFA,
  39018. 0x9F, 0x2E, 0xD6, 0x6E, 0x60, 0x69, 0xCD, 0x96,
  39019. 0xAB, 0x1F, 0x3E, 0x84, 0x8C, 0x68, 0x72, 0x0F,
  39020. 0xEA, 0x32, 0xC5, 0x73, 0x6E, 0x8A, 0xB5, 0x10,
  39021. 0x05, 0xFE, 0x42, 0x58, 0x33, 0xF2, 0x07, 0x56,
  39022. 0xC1, 0x96, 0x76, 0x23, 0x77, 0x9D, 0x0A, 0xD2,
  39023. 0x42, 0xA1, 0x69, 0x06, 0x83, 0xBA, 0xD2, 0xEB,
  39024. 0x12, 0x3D, 0x97, 0xAB, 0x23, 0x08, 0x90, 0x15,
  39025. 0x51, 0x4D, 0x0C, 0x6A, 0x3B, 0x0F, 0x37, 0x15,
  39026. 0x25, 0xC2, 0x3E, 0x5F, 0x53, 0x84, 0x4C, 0x81,
  39027. 0xDD, 0xE8, 0x7C, 0xFE, 0x9F, 0x06, 0x5E, 0x11,
  39028. 0x68, 0x7D, 0x68, 0x6B, 0x07, 0x2C, 0x19, 0x00,
  39029. 0xF5, 0xC9, 0xA7, 0xC3, 0x1F, 0xE8, 0xBA, 0xBE,
  39030. 0x9F, 0x09, 0x0C, 0xE2, 0xCB, 0x3B, 0x68, 0x7B,
  39031. 0xA8, 0x9E, 0xD8, 0x3C, 0x08, 0x85, 0xDF, 0xF9,
  39032. 0x11, 0x2B, 0x52, 0xF6, 0xCE, 0xD7, 0x1E, 0x32,
  39033. 0xA4, 0x0A, 0x9A, 0xBC, 0xFF, 0xF4, 0x20, 0xB6,
  39034. 0x24, 0x85, 0x84, 0x7F, 0xFF, 0x70, 0x3C, 0xBB,
  39035. 0x74, 0x36, 0x42, 0x25, 0x5F, 0xBD, 0x0A, 0x90,
  39036. 0x86, 0xA7, 0xB8, 0x3F, 0x9E, 0xDF, 0x43, 0x24,
  39037. 0x88, 0x0C, 0x52, 0x08, 0xF7, 0xDC, 0xB1, 0xEA,
  39038. 0xC3, 0x38, 0xF9, 0x13, 0x16, 0x65, 0xA0, 0xCA,
  39039. 0x6B, 0xF0, 0xD6, 0x12, 0xFB, 0xA6, 0x3F, 0xF7,
  39040. 0x13, 0x91, 0x99, 0xB1, 0xDE, 0xE4, 0xEE, 0x1E,
  39041. 0x98, 0x9B, 0xE4, 0xA0, 0x3A, 0xA8, 0xAC, 0x4A,
  39042. 0x48, 0x3E, 0xCB, 0x9E, 0xB4, 0x1D, 0x22, 0x1F,
  39043. 0x59, 0x97, 0x24, 0x8C, 0xFE, 0xDC, 0xBF, 0x6C,
  39044. 0xAD, 0x8D, 0xB0, 0xA3, 0x27, 0xFA, 0x28, 0x8F,
  39045. 0xD6, 0xAE, 0x31, 0x39, 0x84, 0xFA, 0x61, 0x8F,
  39046. 0x7D, 0xD4, 0xEE, 0xBB, 0x13, 0xED, 0x85, 0xC4,
  39047. 0x35, 0xC0, 0xAB, 0x07, 0x73, 0xC5, 0xCD, 0xCA,
  39048. 0xD4, 0x69, 0x9B, 0x9C, 0x38, 0x2A, 0x1F, 0x37,
  39049. 0xF9, 0xDF, 0x8C, 0x3A, 0xE1, 0x57, 0xDF, 0x05,
  39050. 0x9F, 0x97, 0x51, 0xCC, 0xA6, 0x93, 0xD5, 0x49,
  39051. 0x2A, 0xE9, 0xCD, 0x46, 0x31, 0x22, 0x6E, 0x62,
  39052. 0xE8, 0x13, 0x90, 0x64, 0xFF, 0x00, 0x27, 0xCF,
  39053. 0xA1, 0x95, 0x4E, 0xE9, 0x36, 0xAF, 0xAD, 0x02,
  39054. 0x06, 0xDD, 0x2A, 0xE2, 0x28, 0xB6, 0xDD, 0x65,
  39055. 0xCD, 0x9A, 0x9D, 0x5F, 0xF9, 0xC0, 0xCC, 0x48,
  39056. 0xC8, 0xC2, 0xE9, 0x8F, 0x5A, 0xE6, 0xE2, 0xC9,
  39057. 0x79, 0x7A, 0x83, 0x84, 0xF8, 0xA3, 0xE3, 0xC7,
  39058. 0x48, 0xC7, 0x06, 0xFE, 0x6A, 0x36, 0x25, 0xD2,
  39059. 0xA2, 0xEB, 0x4A, 0xE2, 0xCA, 0xA0, 0x49, 0x24,
  39060. 0x1A, 0x47, 0x8C, 0x1A, 0x77, 0xF5, 0xC9, 0x0D,
  39061. 0xDC, 0x94, 0x18, 0x4D, 0x89, 0x80, 0x50, 0x18,
  39062. 0x7D, 0x67, 0x00, 0x43, 0xE4, 0xE7, 0x8F, 0x54,
  39063. 0xDC, 0x60, 0x84, 0x24, 0xF3, 0xBF, 0x5E, 0x92,
  39064. 0xC7, 0x0C, 0x05, 0x49, 0xBB, 0x61, 0x2F, 0x48,
  39065. 0x0A, 0xEB, 0xE5, 0xFA, 0x8B, 0x01, 0x33, 0x27,
  39066. 0x10, 0x3E, 0xA1, 0x28, 0x33, 0x11, 0x30, 0x1F,
  39067. 0x91, 0x47, 0x7B, 0xA6, 0x3E, 0xD4, 0xF9, 0xC2,
  39068. 0x8F, 0xA3, 0x4E, 0xBC, 0xA7, 0x61, 0x56, 0x1F,
  39069. 0x90, 0x33, 0x54, 0x15, 0x06, 0x21, 0x9C, 0x57,
  39070. 0x07, 0xC2, 0xF8, 0xED, 0x81, 0xED, 0x36, 0x15,
  39071. 0xC8, 0xAC, 0xAB, 0x12, 0x80, 0xBF, 0x7C, 0x5E,
  39072. 0x00, 0xEC, 0x1B, 0x27, 0x58, 0x3A, 0xE9, 0x09,
  39073. 0x2B, 0x23, 0x16, 0x69, 0x26, 0xF9, 0xCC, 0x3C,
  39074. 0x5A, 0xFB, 0x66, 0xBA, 0x32, 0xF9, 0xAF, 0xAB,
  39075. 0xCB, 0xA7, 0xF7, 0x91, 0x6A, 0x82, 0x42, 0xA7,
  39076. 0x9D, 0x7B, 0x0E, 0xD3, 0x5D, 0xF6, 0x52, 0x6D,
  39077. 0x7D, 0x2B, 0xE6, 0x30, 0x99, 0x01, 0xBD, 0xC0,
  39078. 0x3D, 0x15, 0x95, 0xC2, 0x67, 0x19, 0xD9, 0x0F,
  39079. 0xC0, 0x79, 0x1E, 0xAB, 0xA7, 0x67, 0x35, 0x12,
  39080. 0x53, 0xB0, 0x6A, 0xE4, 0xB9, 0x0A, 0x52, 0xEF,
  39081. 0xBD, 0xCD, 0xD4, 0x0C, 0x09, 0x6F, 0x24, 0xE9,
  39082. 0x52, 0x9F, 0xF8, 0x9F, 0x95, 0x95, 0x57, 0x07,
  39083. 0x5F, 0xC8, 0xDD, 0xAF, 0xE6, 0x10, 0x3A, 0x51,
  39084. 0x38, 0xF0, 0x9F, 0xBD, 0xEB, 0x0F, 0x5F, 0x36,
  39085. 0xB5, 0x2A, 0x57, 0xBE, 0x21, 0x39, 0xD8, 0x9D,
  39086. 0x29, 0x04, 0xBC, 0xE2, 0xB8, 0x6D, 0x03, 0xF2,
  39087. 0x6D, 0x56, 0xF4, 0x18, 0x40, 0x07, 0x1A, 0x15,
  39088. 0x8B, 0xF5, 0x46, 0xE1, 0x0C, 0x4D, 0xED, 0x0E,
  39089. 0x81, 0xB0, 0x0D, 0x98, 0x88, 0xC5, 0x5D, 0x53,
  39090. 0xE1, 0x1D, 0xB7, 0x00, 0x26, 0xC6, 0x46, 0x7E,
  39091. 0xD2, 0xAB, 0x0B, 0xD9, 0x1E, 0xE0, 0xE7, 0xC3,
  39092. 0xC3, 0xE0, 0x83, 0x7F, 0x8C, 0xB9, 0xBA, 0xE0,
  39093. 0x04, 0xE2, 0xA8, 0xFF, 0xEC, 0xD5, 0x9E, 0x79,
  39094. 0x2F, 0x13, 0xF9, 0x27, 0xCA, 0xDD, 0xF5, 0x0F,
  39095. 0x74, 0xD2, 0x9B, 0xC6, 0x2E, 0xF2, 0xF0, 0x2A,
  39096. 0xB0, 0xF9, 0x6E, 0x27, 0x3E, 0x8D, 0x66, 0xDB,
  39097. 0x44, 0x82, 0xDD, 0x1B, 0xD5, 0xBB, 0x51, 0x6E,
  39098. 0x72, 0x3A, 0xCB, 0x0F, 0x0B, 0x97, 0xBC, 0x32,
  39099. 0x07, 0xC1, 0x0C, 0xF3, 0x94, 0xFF, 0x62, 0xE2,
  39100. 0xFD, 0x7D, 0xBB, 0x3D, 0x43, 0x11, 0xB3, 0xFA,
  39101. 0x22, 0x05, 0xBF, 0x87, 0x0F, 0xFD, 0xD1, 0x81,
  39102. 0xC6, 0x30, 0xC6, 0x91, 0xD4, 0xEE, 0xA8, 0x6B,
  39103. 0x37, 0xB2, 0x38, 0xF1, 0x87, 0x89, 0xE0, 0x04,
  39104. 0x09, 0xED, 0x18, 0xA6, 0x3C, 0x18, 0x9E, 0x38,
  39105. 0xCB, 0x9F, 0xFE, 0xB3, 0x03, 0xF4, 0xE4, 0x3F,
  39106. 0xB3, 0x94, 0x7C, 0x74, 0x03, 0x6C, 0xCF, 0x16,
  39107. 0x24, 0xF8, 0x56, 0xE2, 0x4A, 0x7E, 0x9A, 0x21,
  39108. 0xB8, 0xC2, 0x7C, 0xF4, 0x3D, 0x85, 0x15, 0x43,
  39109. 0xA5, 0xCA, 0xFD, 0xA3, 0x05, 0xCC, 0x63, 0x8D,
  39110. 0x94, 0x82, 0x70
  39111. };
  39112. static const byte rnd_87[] = {
  39113. 0x16, 0xB8, 0x2B, 0x9B, 0x0A, 0x90, 0x5B, 0xB3,
  39114. 0xD8, 0x7B, 0x4A, 0x1E, 0x40, 0xAE, 0xAD, 0x3C,
  39115. 0xDE, 0x63, 0xB2, 0x2C, 0xB7, 0x16, 0xBD, 0x46,
  39116. 0x7A, 0x7B, 0xE8, 0x4A, 0xF1, 0x9B, 0x7C, 0xFE
  39117. };
  39118. static const byte sig_87[] = {
  39119. 0xE5, 0x5D, 0x62, 0x56, 0x92, 0x73, 0x72, 0x13,
  39120. 0xDD, 0x3D, 0x7F, 0x51, 0x42, 0xF3, 0xAA, 0x33,
  39121. 0x87, 0x12, 0x2F, 0x20, 0xC9, 0x50, 0x93, 0x0A,
  39122. 0x7E, 0x7C, 0xCC, 0x0C, 0x6D, 0x21, 0xB9, 0x5D,
  39123. 0x62, 0x47, 0xD5, 0xFB, 0x3A, 0xCC, 0xBC, 0xB8,
  39124. 0xA1, 0x5A, 0xDF, 0x97, 0x58, 0xBA, 0x7E, 0x40,
  39125. 0x9A, 0x76, 0xD0, 0x1C, 0xBF, 0x0F, 0x14, 0xC3,
  39126. 0x23, 0x3B, 0x21, 0xB0, 0x5D, 0x11, 0x3B, 0x1F,
  39127. 0x70, 0xCB, 0x21, 0x78, 0x51, 0x68, 0xE2, 0x3A,
  39128. 0x29, 0x4A, 0x0D, 0xD0, 0x32, 0x50, 0xDC, 0xBB,
  39129. 0xD1, 0xCF, 0x80, 0x19, 0x7A, 0xC7, 0xFC, 0x37,
  39130. 0x2D, 0x5A, 0x5A, 0xDF, 0x3E, 0x7E, 0x89, 0x2D,
  39131. 0xC6, 0x0E, 0x75, 0x9A, 0xBB, 0xDF, 0x69, 0x82,
  39132. 0x28, 0xB6, 0xD0, 0xF3, 0xF4, 0xCB, 0x4F, 0xD5,
  39133. 0xDC, 0x5D, 0xFE, 0x8D, 0x01, 0xB4, 0x93, 0x9F,
  39134. 0x89, 0x53, 0x18, 0x74, 0x29, 0x20, 0x36, 0xBF,
  39135. 0x34, 0xCA, 0x71, 0x2B, 0x01, 0x14, 0xFB, 0x66,
  39136. 0x94, 0x28, 0x81, 0xF1, 0xF1, 0x7E, 0x80, 0xB6,
  39137. 0x4E, 0x0E, 0x9E, 0x9E, 0x60, 0xD7, 0x6A, 0xFB,
  39138. 0x59, 0xC7, 0x96, 0x9F, 0xB4, 0x9C, 0x98, 0x72,
  39139. 0x06, 0xC1, 0x6C, 0xAA, 0x8E, 0xC7, 0x48, 0xE6,
  39140. 0xC3, 0xAD, 0x8B, 0x4E, 0xF7, 0x81, 0x92, 0x74,
  39141. 0xC0, 0x5A, 0x2B, 0x54, 0x8D, 0x47, 0x15, 0xAC,
  39142. 0xED, 0x45, 0x69, 0xD0, 0x7C, 0x28, 0x80, 0x18,
  39143. 0xA3, 0x9F, 0xB7, 0x14, 0xC6, 0x51, 0xF9, 0x02,
  39144. 0x70, 0x98, 0xD9, 0xC1, 0x09, 0xC0, 0xD7, 0xCE,
  39145. 0x8B, 0x81, 0x7B, 0x30, 0x99, 0x4C, 0x85, 0x1C,
  39146. 0xFA, 0xAE, 0xBF, 0x05, 0x95, 0xBB, 0x6E, 0x01,
  39147. 0xE4, 0xFC, 0xE7, 0x11, 0x16, 0x90, 0x28, 0xC3,
  39148. 0xC4, 0x36, 0x9F, 0x11, 0xCD, 0xEB, 0xEB, 0x71,
  39149. 0x15, 0x08, 0x1D, 0x43, 0x2B, 0x12, 0xA6, 0x4E,
  39150. 0xB6, 0xF9, 0x35, 0xE4, 0x37, 0x0D, 0xF7, 0x49,
  39151. 0xDF, 0x73, 0x4D, 0xE3, 0x57, 0x33, 0x96, 0x7B,
  39152. 0x72, 0x45, 0x2F, 0x92, 0x70, 0xBB, 0x6F, 0xCD,
  39153. 0x90, 0x82, 0x67, 0xBB, 0x31, 0x9D, 0x9E, 0x38,
  39154. 0x75, 0xCD, 0x5B, 0x55, 0x10, 0x6B, 0xFC, 0x00,
  39155. 0x15, 0xC8, 0xCB, 0xFC, 0xE1, 0x18, 0x41, 0xE8,
  39156. 0x6E, 0x92, 0xEC, 0x1A, 0x26, 0x88, 0x6C, 0xF6,
  39157. 0x2A, 0x5C, 0x05, 0x94, 0xD7, 0xB8, 0xD0, 0x78,
  39158. 0x52, 0x68, 0x8D, 0xC5, 0xBD, 0xD6, 0x29, 0xF8,
  39159. 0x21, 0xDF, 0xB3, 0x28, 0x43, 0x74, 0xC7, 0x0E,
  39160. 0x99, 0xD3, 0x0C, 0xDE, 0xE9, 0x06, 0x44, 0xCD,
  39161. 0x77, 0x13, 0x34, 0x82, 0xBA, 0x36, 0x20, 0x71,
  39162. 0x02, 0xB1, 0x6E, 0xBA, 0xCF, 0x9F, 0x15, 0x36,
  39163. 0xC8, 0xF1, 0x4E, 0x36, 0x30, 0x34, 0x2D, 0x23,
  39164. 0x6C, 0x77, 0xEC, 0xCA, 0xBA, 0x7C, 0x17, 0x4F,
  39165. 0x3F, 0x22, 0x4A, 0x34, 0xA1, 0x5C, 0xB3, 0x8F,
  39166. 0xD8, 0x48, 0xD5, 0x8A, 0x2C, 0x8B, 0x1B, 0xFB,
  39167. 0x87, 0xDA, 0xBC, 0xB6, 0xD9, 0x59, 0xD6, 0x9B,
  39168. 0xF0, 0x6E, 0x8D, 0xB1, 0x52, 0xE1, 0x8A, 0x36,
  39169. 0x31, 0xA7, 0x83, 0xCE, 0xDF, 0x36, 0xEB, 0xBE,
  39170. 0xEA, 0xC3, 0xC6, 0xA6, 0x52, 0x2D, 0x89, 0x0B,
  39171. 0xF9, 0x5B, 0x1D, 0x14, 0xA9, 0xBF, 0x37, 0x31,
  39172. 0xE0, 0x1C, 0xF5, 0x29, 0x95, 0xF0, 0xC0, 0x08,
  39173. 0xE8, 0x97, 0xEE, 0x53, 0x27, 0x85, 0x81, 0x7D,
  39174. 0x47, 0xE5, 0xAC, 0xC5, 0x1B, 0x48, 0xA5, 0x36,
  39175. 0x1E, 0x8A, 0xD7, 0xF5, 0xC9, 0x93, 0x74, 0xCE,
  39176. 0x06, 0xEA, 0xC3, 0x26, 0x45, 0xFF, 0xED, 0x39,
  39177. 0xC1, 0x0B, 0x7A, 0x59, 0x3C, 0x0F, 0xEE, 0x89,
  39178. 0xEF, 0xA4, 0xEC, 0xD0, 0x72, 0x34, 0x95, 0xC9,
  39179. 0xC4, 0x78, 0x47, 0xB6, 0xB7, 0xCE, 0xA4, 0xD9,
  39180. 0xA1, 0xB6, 0x37, 0xC1, 0xF1, 0xFB, 0x4E, 0x4C,
  39181. 0x38, 0xB0, 0x4A, 0xE5, 0x13, 0x63, 0xDC, 0x44,
  39182. 0xC4, 0x7E, 0x86, 0x9C, 0xAD, 0x69, 0x29, 0xFD,
  39183. 0xA1, 0xFE, 0xAD, 0x3B, 0x59, 0x24, 0x2F, 0x70,
  39184. 0xAE, 0x5F, 0x2C, 0x00, 0xFE, 0x01, 0x09, 0xA3,
  39185. 0x10, 0x87, 0xF0, 0xAD, 0xFA, 0x9B, 0x83, 0x8F,
  39186. 0x48, 0x96, 0x8B, 0x9A, 0x35, 0xE7, 0x4D, 0xAA,
  39187. 0xEC, 0xA4, 0xCD, 0x26, 0x7C, 0x3E, 0xAC, 0x93,
  39188. 0x26, 0x9D, 0x6B, 0x83, 0x34, 0xC4, 0x71, 0xE1,
  39189. 0xC8, 0x93, 0x88, 0x09, 0xAF, 0x00, 0xB5, 0x7F,
  39190. 0xD9, 0x5A, 0x8E, 0x36, 0xC1, 0x2E, 0x7E, 0xF1,
  39191. 0x0C, 0xC5, 0x2A, 0xB3, 0xE4, 0x48, 0xDF, 0xFB,
  39192. 0xFF, 0x99, 0xC9, 0x66, 0xD2, 0x28, 0x46, 0x7C,
  39193. 0x43, 0x39, 0x96, 0x69, 0x95, 0x42, 0xAC, 0xE0,
  39194. 0xC2, 0x0C, 0x65, 0x99, 0xC8, 0xB0, 0xAE, 0x76,
  39195. 0xE8, 0x18, 0x3E, 0xA9, 0x1D, 0x44, 0x81, 0x14,
  39196. 0x65, 0xF7, 0xDF, 0xD1, 0xD1, 0x7B, 0x7C, 0x28,
  39197. 0xE0, 0x77, 0x9D, 0x79, 0x9C, 0xE4, 0x1A, 0xF1,
  39198. 0xD0, 0xFF, 0x8E, 0xEA, 0x58, 0x84, 0xB3, 0x47,
  39199. 0xBC, 0xA1, 0x47, 0x48, 0xB7, 0xC3, 0xD5, 0xD1,
  39200. 0xF3, 0xDD, 0xA6, 0x3B, 0x15, 0x4C, 0xB3, 0xB5,
  39201. 0xFD, 0x52, 0x9D, 0x7E, 0xF0, 0xC7, 0x40, 0x2C,
  39202. 0x34, 0xBC, 0xCF, 0x1C, 0x67, 0x30, 0xC0, 0x4D,
  39203. 0xA1, 0xC7, 0x5E, 0xAD, 0xAF, 0xCD, 0xFA, 0x21,
  39204. 0xE4, 0xB5, 0x33, 0x8B, 0x37, 0x2D, 0xCF, 0x4D,
  39205. 0x07, 0x48, 0x61, 0xB0, 0xB6, 0x8B, 0x27, 0x05,
  39206. 0xA0, 0x8C, 0x71, 0x95, 0x84, 0x02, 0xB2, 0x1E,
  39207. 0x59, 0xBC, 0xB6, 0xE2, 0x2C, 0x3C, 0x20, 0x4C,
  39208. 0xDE, 0x1E, 0x35, 0x24, 0xC1, 0x5B, 0x3C, 0xB4,
  39209. 0x2A, 0x8C, 0xA7, 0x2D, 0xE3, 0xDC, 0x45, 0x26,
  39210. 0x6E, 0x29, 0x52, 0x5D, 0x24, 0x8A, 0xC2, 0x16,
  39211. 0x73, 0xDB, 0x80, 0xF2, 0x91, 0xEC, 0x05, 0x3E,
  39212. 0x2E, 0x9E, 0x39, 0x12, 0x5E, 0x11, 0x80, 0x24,
  39213. 0xF5, 0xFC, 0x86, 0x4C, 0xD9, 0xF9, 0x70, 0x59,
  39214. 0xC8, 0xC8, 0x57, 0x5D, 0x0F, 0x68, 0x75, 0x3C,
  39215. 0x7A, 0x3D, 0x1B, 0xF7, 0xD0, 0xDF, 0xE2, 0xF9,
  39216. 0xBD, 0x44, 0xFD, 0x21, 0x75, 0x86, 0x77, 0x25,
  39217. 0xAF, 0xD3, 0x28, 0x55, 0x2A, 0x60, 0x7D, 0x79,
  39218. 0x9C, 0x72, 0x2F, 0x6E, 0xAB, 0x2F, 0x26, 0x44,
  39219. 0x0C, 0xFF, 0x52, 0xBD, 0xA1, 0xA9, 0x07, 0xBD,
  39220. 0x9D, 0x2A, 0x64, 0x2E, 0x0B, 0xA1, 0xB8, 0x78,
  39221. 0xD3, 0xC4, 0x84, 0x9A, 0xE1, 0xDB, 0xB4, 0x4A,
  39222. 0x4C, 0x45, 0x7A, 0x8E, 0xD5, 0xA3, 0x6B, 0x09,
  39223. 0x8D, 0x72, 0x8E, 0x6D, 0x17, 0x34, 0xFF, 0xD6,
  39224. 0xED, 0x24, 0x19, 0x7D, 0xC6, 0x2D, 0x5B, 0x82,
  39225. 0x68, 0xAE, 0x25, 0x33, 0xBB, 0xCB, 0x7D, 0xFD,
  39226. 0x00, 0x15, 0x83, 0xEA, 0xBB, 0xE7, 0x40, 0x3D,
  39227. 0x80, 0xD5, 0x9E, 0x6C, 0xE0, 0x3C, 0x7E, 0x3E,
  39228. 0x12, 0xC7, 0x36, 0x7E, 0x41, 0x84, 0xE8, 0xB4,
  39229. 0x16, 0xCA, 0x4A, 0xB7, 0xEB, 0x16, 0xEC, 0xAB,
  39230. 0x5A, 0x69, 0x24, 0x7F, 0x5E, 0x81, 0x86, 0x7D,
  39231. 0x30, 0x61, 0x4E, 0x0F, 0x75, 0x39, 0xEE, 0xF2,
  39232. 0xF4, 0xDC, 0x5E, 0x23, 0x40, 0xE8, 0x3C, 0xC0,
  39233. 0x10, 0xAD, 0x5E, 0xE6, 0x06, 0x8E, 0x5F, 0x55,
  39234. 0xC5, 0x69, 0x65, 0x5F, 0xA3, 0x6E, 0x73, 0x86,
  39235. 0x82, 0x32, 0x5F, 0x36, 0xA7, 0x6B, 0x2C, 0x26,
  39236. 0xCD, 0x64, 0xC8, 0x57, 0x1F, 0x06, 0x7A, 0xAB,
  39237. 0x8B, 0xA7, 0xDB, 0x53, 0x48, 0x1A, 0x06, 0x8D,
  39238. 0x36, 0xF1, 0x77, 0x74, 0xE6, 0xF5, 0x18, 0x62,
  39239. 0x8E, 0x8A, 0xBF, 0xB7, 0x7F, 0x72, 0x44, 0xAC,
  39240. 0xC8, 0x9A, 0x0E, 0x60, 0x4B, 0xAB, 0xB2, 0x9E,
  39241. 0x95, 0xDF, 0x95, 0x28, 0x98, 0x78, 0xBB, 0xA9,
  39242. 0x5D, 0x8E, 0xEE, 0xB4, 0x84, 0xF5, 0x81, 0x7E,
  39243. 0xA1, 0x53, 0x3E, 0xBB, 0x43, 0xF6, 0xD4, 0xB7,
  39244. 0x60, 0xFD, 0xF4, 0xF8, 0x68, 0xB6, 0x1D, 0x9A,
  39245. 0xF7, 0xDA, 0x77, 0xFA, 0xBB, 0x74, 0x44, 0xDE,
  39246. 0x7C, 0x32, 0x2D, 0x5C, 0x24, 0xD8, 0x4D, 0xBF,
  39247. 0xE0, 0x5C, 0x70, 0x12, 0x3C, 0x43, 0xCC, 0x5F,
  39248. 0x00, 0xD5, 0x1F, 0xEA, 0x5D, 0xC9, 0x3A, 0x5C,
  39249. 0x32, 0xED, 0xE0, 0xF1, 0x59, 0xA0, 0xB7, 0x71,
  39250. 0xDC, 0x65, 0xD2, 0x88, 0x20, 0x20, 0xD8, 0x59,
  39251. 0x53, 0x2D, 0x30, 0x2D, 0xFC, 0xA9, 0xEA, 0x45,
  39252. 0xB0, 0xF3, 0x1E, 0x66, 0x9F, 0xF6, 0xF1, 0x5E,
  39253. 0x9B, 0x67, 0x1D, 0xBF, 0x5E, 0x19, 0xB3, 0x2A,
  39254. 0xE8, 0xCE, 0xE5, 0x90, 0xFE, 0x82, 0x5C, 0x19,
  39255. 0x7B, 0x84, 0x3E, 0x45, 0xFF, 0x5D, 0xC2, 0x2E,
  39256. 0x49, 0x6A, 0xB1, 0x2D, 0x50, 0x2D, 0x21, 0xF7,
  39257. 0x2A, 0xA2, 0x39, 0x47, 0x8D, 0xB5, 0x17, 0x64,
  39258. 0x3E, 0x96, 0x13, 0x90, 0x53, 0xEA, 0x57, 0x4C,
  39259. 0xDB, 0x3D, 0x43, 0xC3, 0xE7, 0xD6, 0x5C, 0x54,
  39260. 0x89, 0xDF, 0x6E, 0xF9, 0xE4, 0xC6, 0x64, 0xF0,
  39261. 0x88, 0x1C, 0xD0, 0xF6, 0x9D, 0x9E, 0xD7, 0xCD,
  39262. 0x2C, 0xFB, 0xCC, 0x54, 0x0E, 0x96, 0xD7, 0x4E,
  39263. 0x05, 0xD2, 0xB3, 0x88, 0x85, 0xD8, 0x60, 0xA4,
  39264. 0xF2, 0xE4, 0xD7, 0xFF, 0xAF, 0x12, 0x2E, 0xBA,
  39265. 0xC4, 0x5A, 0x3A, 0x3E, 0xC5, 0xD7, 0xF3, 0x60,
  39266. 0x4F, 0x27, 0xEF, 0xE0, 0x35, 0xAC, 0x4A, 0x8B,
  39267. 0x14, 0x7D, 0xC4, 0xEF, 0x61, 0x9A, 0x69, 0x2E,
  39268. 0x49, 0x80, 0x04, 0x0C, 0x18, 0xB9, 0x42, 0xC6,
  39269. 0x8C, 0x8A, 0x99, 0x43, 0xA6, 0x5A, 0xCD, 0x72,
  39270. 0x20, 0xAD, 0xFD, 0x9C, 0xC4, 0xAA, 0xDF, 0x6C,
  39271. 0x6C, 0x03, 0xEF, 0x48, 0x3E, 0xFB, 0x4A, 0xBC,
  39272. 0xAA, 0x44, 0xEE, 0xC4, 0x25, 0x8F, 0xF9, 0x8A,
  39273. 0xC2, 0x24, 0x73, 0x15, 0xFA, 0x0E, 0xCB, 0x00,
  39274. 0xEE, 0x9B, 0x39, 0x3F, 0x60, 0x1F, 0x00, 0x95,
  39275. 0xCA, 0xFE, 0xC2, 0x2C, 0x35, 0x5F, 0xD9, 0xD1,
  39276. 0x29, 0xB5, 0x4D, 0xC1, 0x66, 0x51, 0x8F, 0x17,
  39277. 0x3B, 0xF4, 0xF1, 0x49, 0x42, 0x36, 0x0C, 0x5B,
  39278. 0x58, 0xF2, 0x9B, 0x59, 0x01, 0xFB, 0x15, 0x7F,
  39279. 0x21, 0x90, 0x1F, 0x56, 0x69, 0x8B, 0xE2, 0xA5,
  39280. 0x44, 0xCB, 0x84, 0x98, 0x4B, 0x75, 0xA8, 0xCB,
  39281. 0x83, 0x0D, 0xE8, 0x1C, 0x91, 0x7F, 0xE4, 0x57,
  39282. 0x81, 0x16, 0x34, 0x2F, 0xCE, 0x01, 0xAA, 0x62,
  39283. 0x54, 0x44, 0xB7, 0xD6, 0xC7, 0xF1, 0x68, 0x9A,
  39284. 0x00, 0x3B, 0x71, 0x16, 0xF9, 0x96, 0x6A, 0x90,
  39285. 0x6C, 0x2C, 0x4E, 0x58, 0xBC, 0xDD, 0xE9, 0x3B,
  39286. 0x60, 0xB7, 0xA0, 0x97, 0xEE, 0xD6, 0x34, 0xDD,
  39287. 0x49, 0x4A, 0xD9, 0x85, 0xD1, 0xB7, 0x95, 0x14,
  39288. 0xEC, 0x6A, 0x40, 0xE8, 0x31, 0x80, 0xF1, 0xD8,
  39289. 0x5F, 0x75, 0xF6, 0x92, 0x3A, 0x4F, 0xCD, 0x0A,
  39290. 0x6E, 0xBF, 0xA1, 0x27, 0x48, 0x79, 0x27, 0x04,
  39291. 0x76, 0x2C, 0xAB, 0x25, 0x06, 0xEB, 0x43, 0xDD,
  39292. 0x1B, 0x4B, 0x24, 0xFC, 0x93, 0x51, 0x1C, 0x45,
  39293. 0xF6, 0xAE, 0x77, 0xCF, 0xC9, 0xE6, 0x20, 0xE4,
  39294. 0xA5, 0x2B, 0x3D, 0x7D, 0xF0, 0xEB, 0x51, 0x7C,
  39295. 0xCA, 0xFE, 0x58, 0xBA, 0xC4, 0x07, 0x95, 0x75,
  39296. 0x62, 0x0C, 0x50, 0x68, 0x88, 0x1A, 0x8A, 0x0D,
  39297. 0x1B, 0x5C, 0x53, 0x1A, 0x9C, 0xA8, 0x4E, 0xFE,
  39298. 0x63, 0x9B, 0xDB, 0x05, 0x70, 0x01, 0x75, 0xA1,
  39299. 0x3A, 0x08, 0xFA, 0x51, 0xD5, 0xF6, 0x81, 0xDE,
  39300. 0x69, 0xE5, 0x40, 0xB3, 0xF8, 0x7C, 0x46, 0x97,
  39301. 0xA6, 0x4E, 0xA8, 0x51, 0x47, 0x9C, 0xB9, 0x25,
  39302. 0xCD, 0x4E, 0xED, 0xFC, 0xEE, 0x03, 0x6A, 0xCD,
  39303. 0x93, 0x65, 0xB3, 0x68, 0x09, 0x6F, 0xE8, 0x00,
  39304. 0x6A, 0x3F, 0xBF, 0xE8, 0x6F, 0x09, 0xE9, 0xF2,
  39305. 0x6F, 0x44, 0x2E, 0xB1, 0x81, 0x76, 0x04, 0xDD,
  39306. 0x6E, 0xF4, 0x93, 0x61, 0xE5, 0x78, 0xD4, 0xDA,
  39307. 0xBF, 0x05, 0xA1, 0xF4, 0x9D, 0xFD, 0x57, 0x06,
  39308. 0x9C, 0x13, 0x45, 0x97, 0xF2, 0x48, 0xE6, 0x1A,
  39309. 0xB5, 0xAD, 0x09, 0x11, 0x04, 0xBB, 0xA0, 0xA8,
  39310. 0xA3, 0xA3, 0x33, 0xCD, 0x42, 0x2C, 0x66, 0xC2,
  39311. 0x94, 0x80, 0x15, 0x9D, 0x56, 0x74, 0x02, 0xEE,
  39312. 0xA7, 0xE4, 0x90, 0xDD, 0xFB, 0x0B, 0x3B, 0xF0,
  39313. 0x7A, 0x02, 0x44, 0xE8, 0x11, 0xC4, 0x3A, 0xFE,
  39314. 0x73, 0x2A, 0x4C, 0x92, 0x3C, 0x23, 0x37, 0x8B,
  39315. 0x4F, 0x28, 0x8E, 0x1C, 0x4E, 0x7D, 0x0D, 0x6B,
  39316. 0xFD, 0x20, 0xB5, 0x93, 0xB3, 0x75, 0x30, 0x28,
  39317. 0xC7, 0x7E, 0x67, 0xC4, 0xDE, 0xDA, 0x27, 0xA9,
  39318. 0xE3, 0xF2, 0xF5, 0x25, 0x98, 0x5F, 0x6B, 0xBE,
  39319. 0x11, 0x80, 0x23, 0x49, 0x30, 0xC8, 0x8A, 0x63,
  39320. 0xF9, 0xC4, 0x14, 0x77, 0x2A, 0xE2, 0x21, 0x42,
  39321. 0x28, 0x1C, 0xEB, 0x9F, 0x7B, 0x70, 0xA8, 0x2B,
  39322. 0xFB, 0x25, 0x36, 0xA6, 0xAC, 0xFE, 0x8E, 0xFF,
  39323. 0xB6, 0x86, 0x09, 0x15, 0x7E, 0xD9, 0x26, 0x8F,
  39324. 0xDB, 0xF2, 0x2D, 0xC2, 0xFA, 0xAE, 0xDA, 0x50,
  39325. 0xF6, 0x24, 0x53, 0xDB, 0xBF, 0x92, 0x9D, 0x7E,
  39326. 0x48, 0xCC, 0x75, 0xAC, 0xD0, 0xD3, 0x45, 0x09,
  39327. 0x2F, 0x01, 0x60, 0xBB, 0xAE, 0xCB, 0xE6, 0xB3,
  39328. 0x30, 0xDA, 0xD9, 0xB6, 0x12, 0xCD, 0xF5, 0x11,
  39329. 0xCF, 0x2B, 0x2A, 0xC6, 0x61, 0x9A, 0x05, 0x59,
  39330. 0x08, 0x58, 0x64, 0xEC, 0xDB, 0x77, 0xCF, 0x64,
  39331. 0xE2, 0x4B, 0x6E, 0xF4, 0x07, 0x68, 0x5E, 0xE9,
  39332. 0x31, 0xB1, 0x38, 0x67, 0xF9, 0x29, 0x2E, 0x7A,
  39333. 0xD2, 0x03, 0xA6, 0x29, 0x3F, 0x22, 0x58, 0x66,
  39334. 0x6A, 0x07, 0xD8, 0xFD, 0xC5, 0x03, 0xEE, 0x66,
  39335. 0xD4, 0x66, 0x70, 0x6D, 0xA4, 0xC4, 0xA1, 0xEE,
  39336. 0xCD, 0x4D, 0xFA, 0x3C, 0x34, 0x36, 0xC2, 0xC5,
  39337. 0x1E, 0x86, 0xB8, 0x7B, 0x7C, 0xBC, 0x67, 0x16,
  39338. 0xF3, 0x6E, 0xF2, 0xB7, 0xEA, 0x96, 0x1B, 0x0D,
  39339. 0xA2, 0xC8, 0x42, 0xBF, 0x30, 0x09, 0x2A, 0x6D,
  39340. 0x9D, 0x35, 0xB3, 0x92, 0xBA, 0x3E, 0xE2, 0xE9,
  39341. 0xE2, 0xAA, 0x90, 0x70, 0xCE, 0x0F, 0x07, 0xFA,
  39342. 0x7C, 0x3B, 0xF7, 0x66, 0x7F, 0x5C, 0xFE, 0xD9,
  39343. 0x72, 0x1C, 0x4E, 0xFE, 0x7E, 0x86, 0x8E, 0x7F,
  39344. 0x62, 0x8D, 0x41, 0x46, 0x7B, 0x43, 0x17, 0xB9,
  39345. 0x44, 0xED, 0x39, 0x1B, 0x3E, 0xF9, 0x2D, 0xC7,
  39346. 0x5C, 0x9D, 0xAC, 0x05, 0x00, 0xC6, 0x85, 0x4E,
  39347. 0xB8, 0xBC, 0x29, 0xDF, 0x6D, 0x6A, 0xCC, 0xEB,
  39348. 0xD6, 0x44, 0x86, 0xAA, 0xC9, 0x55, 0x49, 0xA1,
  39349. 0x3F, 0x59, 0x5E, 0xAF, 0xD5, 0xC9, 0x96, 0x19,
  39350. 0x84, 0xC0, 0x4D, 0x1B, 0xE5, 0x2C, 0x42, 0x8D,
  39351. 0x2C, 0xC8, 0x83, 0x00, 0x26, 0xBF, 0x46, 0x9F,
  39352. 0x20, 0x97, 0xEC, 0x2C, 0xA9, 0x2C, 0xF0, 0xA7,
  39353. 0x11, 0xED, 0xE2, 0xA2, 0x57, 0x83, 0x40, 0x92,
  39354. 0xF3, 0x58, 0xB7, 0x4E, 0xD6, 0x3A, 0x9D, 0xF0,
  39355. 0xDD, 0xD4, 0x5F, 0x82, 0x58, 0xD3, 0x72, 0x05,
  39356. 0x69, 0xFF, 0x1E, 0xBC, 0x74, 0x90, 0x87, 0xB5,
  39357. 0x7A, 0xEE, 0xF8, 0xCE, 0x3F, 0x59, 0xE1, 0xC0,
  39358. 0x46, 0x24, 0xF8, 0x9D, 0x93, 0x51, 0x4A, 0x44,
  39359. 0xFB, 0xEA, 0x58, 0xA6, 0xAC, 0x9A, 0x7C, 0xA3,
  39360. 0x11, 0xA3, 0x47, 0x44, 0x24, 0x11, 0xF5, 0x56,
  39361. 0x1A, 0x3B, 0xCF, 0xEC, 0xD9, 0x2B, 0x6C, 0xBA,
  39362. 0xA6, 0xA2, 0x67, 0xB9, 0xE0, 0xCB, 0x3F, 0x8D,
  39363. 0xA8, 0xC4, 0x8A, 0x45, 0xAB, 0xE2, 0x10, 0x19,
  39364. 0x10, 0xC9, 0xDB, 0x01, 0x64, 0xC0, 0x0B, 0x6F,
  39365. 0x3B, 0xA1, 0xE9, 0xEB, 0x74, 0x9A, 0x63, 0x93,
  39366. 0xE5, 0x74, 0x3F, 0xD3, 0x7B, 0xEA, 0x8C, 0xD6,
  39367. 0x7D, 0x66, 0xDD, 0x90, 0x6C, 0x69, 0x67, 0x05,
  39368. 0xAD, 0x70, 0xF1, 0xFA, 0x52, 0xBB, 0xD5, 0x3D,
  39369. 0x0E, 0x7E, 0x87, 0xE0, 0x98, 0xAF, 0xA6, 0xE6,
  39370. 0x0E, 0x25, 0x91, 0x70, 0xCA, 0x36, 0xE4, 0xF8,
  39371. 0xF7, 0x95, 0x1C, 0x48, 0xF6, 0x62, 0x9A, 0x4D,
  39372. 0xE4, 0xE7, 0x3A, 0x92, 0xC6, 0x2E, 0xAB, 0x8A,
  39373. 0x75, 0x7C, 0x45, 0xDA, 0x54, 0xB1, 0x6D, 0x2E,
  39374. 0xCC, 0x13, 0x46, 0x67, 0x8F, 0xFF, 0xDA, 0x18,
  39375. 0xE1, 0x4C, 0xE4, 0x6A, 0xB6, 0xAC, 0x65, 0x32,
  39376. 0x0C, 0x63, 0xD5, 0x43, 0xB5, 0x8B, 0xB1, 0x52,
  39377. 0xEE, 0x0C, 0xBB, 0x62, 0x34, 0x30, 0xDB, 0xF7,
  39378. 0x08, 0xC6, 0xE8, 0x5B, 0x07, 0x66, 0x6D, 0x4B,
  39379. 0x39, 0xC6, 0x94, 0x2B, 0x22, 0x9E, 0x3E, 0x45,
  39380. 0x62, 0x3D, 0x05, 0x03, 0x2B, 0x16, 0x71, 0xBB,
  39381. 0x85, 0x1B, 0x6E, 0x84, 0xD3, 0x48, 0x4D, 0x63,
  39382. 0x26, 0x60, 0x97, 0x45, 0xB8, 0xEA, 0x43, 0x96,
  39383. 0x00, 0xFE, 0x0B, 0x85, 0xBD, 0x22, 0x40, 0xA4,
  39384. 0xA7, 0x2F, 0xC1, 0xEB, 0xFD, 0xB5, 0x22, 0xD5,
  39385. 0x1F, 0xB3, 0xEA, 0x7C, 0x6D, 0x20, 0xFB, 0x98,
  39386. 0xA5, 0xF2, 0x84, 0x70, 0xF7, 0xB9, 0x2A, 0x12,
  39387. 0x63, 0x0C, 0x2D, 0x97, 0x6C, 0xC2, 0x76, 0xAC,
  39388. 0x32, 0xE2, 0xB1, 0x3A, 0xB3, 0xAB, 0x9E, 0xBB,
  39389. 0x61, 0xB4, 0x6A, 0x5F, 0x2D, 0x4D, 0xCE, 0x0D,
  39390. 0xFB, 0x97, 0x80, 0x89, 0x4A, 0x81, 0xFB, 0xB2,
  39391. 0x72, 0x37, 0x66, 0xB9, 0x08, 0xBF, 0xCD, 0x9F,
  39392. 0x63, 0xB2, 0xBA, 0x54, 0xF1, 0x9E, 0xEC, 0x11,
  39393. 0x67, 0x26, 0xC7, 0x98, 0xDD, 0xA3, 0xC5, 0x50,
  39394. 0x86, 0x17, 0xD5, 0xCF, 0x51, 0x97, 0x22, 0x65,
  39395. 0x2B, 0x71, 0xF7, 0x34, 0x84, 0x55, 0xC9, 0xD1,
  39396. 0xFE, 0x75, 0x42, 0x0A, 0x5A, 0x31, 0x59, 0xE8,
  39397. 0x8A, 0x0D, 0xE5, 0x77, 0x1C, 0xF5, 0xFD, 0x27,
  39398. 0x05, 0x05, 0xF7, 0x28, 0xDA, 0x54, 0xAB, 0xBD,
  39399. 0xDC, 0x50, 0xB8, 0xDB, 0x2E, 0xB4, 0x28, 0x41,
  39400. 0x30, 0x04, 0x40, 0xD5, 0xF0, 0x12, 0xD7, 0x16,
  39401. 0x3D, 0x8F, 0x41, 0xE7, 0x70, 0x76, 0x82, 0xB9,
  39402. 0xC4, 0xB2, 0x1F, 0x57, 0x10, 0xB6, 0xC4, 0x84,
  39403. 0x0D, 0xB1, 0xB8, 0x21, 0xB2, 0x77, 0x09, 0xF6,
  39404. 0xD5, 0x9C, 0xE4, 0xA2, 0xFA, 0x83, 0x13, 0x56,
  39405. 0x94, 0x3F, 0x37, 0x6D, 0x0D, 0x7C, 0x7E, 0xA0,
  39406. 0xE5, 0xC8, 0xD9, 0x42, 0x0F, 0x35, 0xB1, 0xDC,
  39407. 0xB9, 0x49, 0xD5, 0xED, 0xA8, 0x90, 0x09, 0x14,
  39408. 0xAE, 0x63, 0xB5, 0xEA, 0x62, 0x0D, 0x9E, 0x6D,
  39409. 0x93, 0xBD, 0x3A, 0xEA, 0x24, 0xB5, 0xAC, 0xC9,
  39410. 0xD1, 0x7B, 0xBC, 0xC6, 0xC4, 0xBA, 0x68, 0xB1,
  39411. 0x65, 0xFE, 0xAB, 0x30, 0xD4, 0x92, 0xD9, 0xC1,
  39412. 0x94, 0x84, 0xE1, 0x20, 0x4E, 0x28, 0x7C, 0x3A,
  39413. 0x3E, 0x8B, 0x44, 0x79, 0xC7, 0xB5, 0xA5, 0x95,
  39414. 0xC2, 0xC9, 0xA8, 0x3F, 0x92, 0x67, 0x06, 0x9A,
  39415. 0x12, 0xD3, 0xAE, 0x78, 0x87, 0x0E, 0x31, 0x54,
  39416. 0x26, 0xDF, 0x97, 0xEB, 0x6C, 0xF3, 0xC9, 0x53,
  39417. 0x39, 0xED, 0x50, 0x5A, 0xF9, 0x6A, 0x03, 0x27,
  39418. 0x8E, 0xC6, 0x79, 0x5B, 0xD4, 0xD3, 0x57, 0x97,
  39419. 0xFD, 0xF5, 0xCB, 0x14, 0xDB, 0xBE, 0x39, 0xB9,
  39420. 0x64, 0x8A, 0x75, 0xAA, 0xE3, 0x4A, 0x19, 0x59,
  39421. 0x69, 0x7D, 0xF8, 0x7D, 0x8C, 0xB8, 0x2F, 0x32,
  39422. 0x57, 0xBF, 0x84, 0x9E, 0x45, 0x4E, 0xC4, 0xA0,
  39423. 0x65, 0xA4, 0x0B, 0x73, 0x36, 0xC5, 0xD1, 0x07,
  39424. 0xF8, 0x1C, 0x91, 0x07, 0xB8, 0x0B, 0x4B, 0xE5,
  39425. 0x4F, 0xE6, 0xA1, 0xDF, 0x29, 0x03, 0xE7, 0x68,
  39426. 0xA4, 0x32, 0x8E, 0x21, 0x8F, 0x15, 0x51, 0x57,
  39427. 0x65, 0x16, 0xF0, 0x55, 0x71, 0x8C, 0x28, 0xD8,
  39428. 0x82, 0xDC, 0x8A, 0xC1, 0xE7, 0x5C, 0xF2, 0xD5,
  39429. 0xB8, 0x18, 0x16, 0x9F, 0x63, 0x89, 0x21, 0xF1,
  39430. 0xA6, 0xED, 0x21, 0xDA, 0xC8, 0x0A, 0x10, 0x21,
  39431. 0x18, 0x98, 0xD0, 0xF2, 0x9E, 0xDE, 0x5A, 0xA1,
  39432. 0x51, 0xC9, 0x18, 0x3B, 0x68, 0x79, 0x75, 0xE7,
  39433. 0xF4, 0xF9, 0xBF, 0x5F, 0xBE, 0x61, 0x35, 0xA9,
  39434. 0x02, 0x56, 0x2D, 0x99, 0xD8, 0x95, 0xFA, 0x78,
  39435. 0x8A, 0x67, 0x24, 0x1D, 0xDF, 0x13, 0x14, 0xD0,
  39436. 0xB4, 0xB6, 0x21, 0x11, 0xB7, 0xA4, 0x06, 0x8D,
  39437. 0x1D, 0xF6, 0xD5, 0x50, 0x2A, 0x0A, 0x42, 0x3C,
  39438. 0x7C, 0xF1, 0x1F, 0x15, 0x1C, 0x81, 0x69, 0xDA,
  39439. 0xCC, 0xAC, 0x8F, 0xB9, 0x08, 0x4E, 0xF8, 0x4E,
  39440. 0x3E, 0x77, 0x26, 0x4A, 0x1F, 0x72, 0x89, 0xCA,
  39441. 0x91, 0x77, 0x99, 0xBF, 0x28, 0xD2, 0x31, 0x65,
  39442. 0x30, 0x37, 0x84, 0x66, 0x8A, 0x1C, 0xC6, 0x59,
  39443. 0x7D, 0x48, 0x9B, 0x4D, 0xDC, 0x87, 0x4F, 0xD2,
  39444. 0x04, 0xA0, 0x8B, 0x8B, 0x37, 0x3B, 0x1A, 0xDB,
  39445. 0xCF, 0x63, 0x39, 0x07, 0xF3, 0x37, 0xCF, 0x0E,
  39446. 0x2F, 0xEB, 0xE6, 0x2A, 0xA1, 0x4C, 0xE0, 0x75,
  39447. 0x3F, 0xAB, 0xF7, 0xDE, 0x48, 0x83, 0x79, 0x89,
  39448. 0x30, 0xA7, 0x1B, 0xE8, 0x73, 0x8E, 0x9D, 0x1D,
  39449. 0xF6, 0x5C, 0x91, 0x4F, 0x44, 0x7C, 0x04, 0xA7,
  39450. 0x07, 0xC8, 0xCC, 0x4A, 0x5C, 0x81, 0xAD, 0x48,
  39451. 0x7C, 0xE5, 0x19, 0x5A, 0xC4, 0x29, 0x80, 0x14,
  39452. 0xFA, 0xC2, 0x26, 0x1C, 0x50, 0x28, 0xB9, 0xF6,
  39453. 0x7F, 0x8D, 0x51, 0x9A, 0xDA, 0xBB, 0x8E, 0x90,
  39454. 0xBA, 0x3B, 0xD9, 0x4D, 0x61, 0xBE, 0xFD, 0x33,
  39455. 0xC0, 0xCA, 0x7B, 0x09, 0xFF, 0x36, 0x84, 0x70,
  39456. 0x11, 0xB4, 0xBE, 0x81, 0xFE, 0x71, 0xEE, 0x81,
  39457. 0xD7, 0x61, 0xBB, 0x83, 0xA6, 0xA0, 0xDC, 0x20,
  39458. 0x04, 0x02, 0x4C, 0x1B, 0x4D, 0xED, 0x8A, 0xC1,
  39459. 0x38, 0x70, 0xC3, 0x69, 0xC9, 0x50, 0xC2, 0x17,
  39460. 0x64, 0xAD, 0x9D, 0x44, 0x63, 0x44, 0xE5, 0x32,
  39461. 0x7B, 0x90, 0xE3, 0xEF, 0x45, 0x28, 0xA6, 0x23,
  39462. 0x92, 0xCB, 0xA1, 0xFC, 0xA8, 0xB4, 0x39, 0xF1,
  39463. 0xB1, 0x00, 0x1F, 0x06, 0xD4, 0x91, 0x5D, 0xDB,
  39464. 0xAC, 0x7D, 0x87, 0xD4, 0xEE, 0xCD, 0x4A, 0x06,
  39465. 0x3E, 0xB4, 0x84, 0x65, 0xAA, 0x47, 0x05, 0x41,
  39466. 0x7C, 0x95, 0x47, 0x3A, 0x49, 0x80, 0xC5, 0xAC,
  39467. 0x32, 0x41, 0x6A, 0x3A, 0x2B, 0xB9, 0xD9, 0x21,
  39468. 0x80, 0xC7, 0xC1, 0xD0, 0xC9, 0x95, 0x4B, 0xC3,
  39469. 0xEA, 0x0D, 0x3F, 0x0E, 0xE4, 0x5A, 0xD8, 0xBD,
  39470. 0x11, 0xD0, 0x76, 0x6D, 0x3C, 0xA7, 0x64, 0xD8,
  39471. 0xCA, 0x4C, 0x8F, 0x58, 0x2C, 0xDD, 0x95, 0x1F,
  39472. 0xBB, 0x76, 0x8D, 0x10, 0xFD, 0xAD, 0x45, 0xCE,
  39473. 0x71, 0x6E, 0x27, 0x92, 0xC4, 0xA6, 0x17, 0x46,
  39474. 0x95, 0xDB, 0xD8, 0xEA, 0x9A, 0x5F, 0x0E, 0xE0,
  39475. 0x0A, 0xA2, 0xF5, 0x79, 0xC3, 0x74, 0xA7, 0x70,
  39476. 0x99, 0x3B, 0x23, 0xD7, 0x3E, 0xA4, 0x96, 0xB5,
  39477. 0x54, 0x77, 0x71, 0x8D, 0x78, 0x2E, 0xCC, 0x0A,
  39478. 0x4E, 0xF8, 0xA9, 0x96, 0xEE, 0xB4, 0x4B, 0x5B,
  39479. 0xDC, 0x52, 0x6D, 0xE1, 0x61, 0x36, 0xE1, 0x32,
  39480. 0xD6, 0xA2, 0x7B, 0x2E, 0xCC, 0x78, 0x92, 0xA1,
  39481. 0x81, 0x59, 0xB8, 0xC7, 0x04, 0x11, 0x3D, 0xF0,
  39482. 0xF9, 0xF9, 0x3E, 0x47, 0x3C, 0xEA, 0xD5, 0x30,
  39483. 0x2D, 0xAE, 0xC0, 0x47, 0xC8, 0x61, 0xCC, 0x9C,
  39484. 0x2E, 0xC0, 0x40, 0x16, 0x11, 0x73, 0x13, 0xF3,
  39485. 0x19, 0xAE, 0x72, 0x44, 0x72, 0xC5, 0x59, 0x51,
  39486. 0x2E, 0x9F, 0xE3, 0x07, 0xB0, 0xCA, 0x6B, 0xB0,
  39487. 0x15, 0x20, 0xB4, 0x25, 0x00, 0xED, 0xFD, 0xAC,
  39488. 0xD6, 0x34, 0x8B, 0xCA, 0xE8, 0xC6, 0x3B, 0xFD,
  39489. 0x02, 0x22, 0xE6, 0x91, 0x2B, 0x4B, 0x61, 0xDF,
  39490. 0x63, 0x5C, 0x2B, 0x5F, 0x82, 0x07, 0x23, 0x59,
  39491. 0x82, 0x5E, 0x0E, 0x21, 0xF7, 0x9C, 0x37, 0x1C,
  39492. 0x7E, 0x6F, 0xD4, 0xFA, 0x91, 0x40, 0x8B, 0x98,
  39493. 0x68, 0xBD, 0x60, 0x2F, 0x0A, 0xC8, 0xC8, 0x99,
  39494. 0xA1, 0xC6, 0x10, 0xF1, 0x27, 0x53, 0xD3, 0xFB,
  39495. 0x23, 0x02, 0xE7, 0x8E, 0x95, 0xB1, 0xF0, 0x21,
  39496. 0xCB, 0x90, 0xEE, 0x8D, 0xE0, 0x27, 0x57, 0xDE,
  39497. 0x40, 0xA3, 0xE7, 0x8F, 0x61, 0xC1, 0x8F, 0xC5,
  39498. 0x0C, 0x0F, 0xBA, 0x05, 0xA0, 0x58, 0x8E, 0x86,
  39499. 0x8A, 0xF5, 0x72, 0xE1, 0x34, 0xB4, 0xF6, 0x8E,
  39500. 0x6E, 0xA4, 0x21, 0x75, 0x43, 0x73, 0xE7, 0x32,
  39501. 0x72, 0x80, 0x9B, 0xE7, 0x1D, 0x78, 0x8F, 0x0D,
  39502. 0x06, 0x47, 0x9E, 0x4D, 0xB4, 0xAC, 0x3E, 0x0D,
  39503. 0xB8, 0x11, 0x23, 0xFF, 0xAD, 0xB9, 0x23, 0xE0,
  39504. 0xA4, 0x37, 0xA6, 0x3D, 0xC2, 0x15, 0xF4, 0x64,
  39505. 0x03, 0x1F, 0x0A, 0x68, 0xED, 0x37, 0x37, 0xE8,
  39506. 0x3E, 0x5B, 0x49, 0x78, 0xFC, 0xFC, 0x12, 0x06,
  39507. 0xE8, 0xC7, 0xCD, 0x3A, 0xAF, 0xD4, 0x54, 0xA7,
  39508. 0x04, 0x7B, 0xFC, 0x66, 0xA6, 0xA8, 0x1C, 0x38,
  39509. 0x0C, 0x26, 0x08, 0xE6, 0xEE, 0x47, 0x25, 0x80,
  39510. 0x59, 0xA5, 0x39, 0x81, 0x20, 0xEE, 0x5F, 0x49,
  39511. 0x9A, 0x01, 0x37, 0xE9, 0x96, 0x18, 0xD0, 0x05,
  39512. 0x2D, 0xE3, 0x73, 0xD5, 0x08, 0x3B, 0x18, 0x46,
  39513. 0xFE, 0x9E, 0x67, 0x5B, 0x9E, 0xF8, 0x53, 0x05,
  39514. 0x2F, 0x96, 0x18, 0x9C, 0x09, 0x0D, 0xA6, 0x05,
  39515. 0xB3, 0x9E, 0x2F, 0x0B, 0x5A, 0xF3, 0x93, 0xFF,
  39516. 0x29, 0xF3, 0x4F, 0x62, 0xD5, 0x9A, 0xCE, 0x74,
  39517. 0x64, 0xD0, 0xBC, 0xB3, 0x08, 0xF1, 0xD3, 0x22,
  39518. 0xA5, 0xBE, 0x64, 0x0A, 0xEB, 0xA5, 0xF5, 0x1B,
  39519. 0x7E, 0x0A, 0x44, 0x3B, 0x1D, 0xA9, 0x48, 0x9A,
  39520. 0x2F, 0xED, 0x05, 0x0F, 0x44, 0xB3, 0x6D, 0xAD,
  39521. 0x39, 0x2C, 0xBA, 0x8E, 0x2B, 0xDE, 0x17, 0x38,
  39522. 0xD1, 0x69, 0xEA, 0xAE, 0x4E, 0x97, 0xCD, 0x61,
  39523. 0xBA, 0x75, 0x39, 0xF2, 0x81, 0xBB, 0xA9, 0x0F,
  39524. 0x6F, 0x82, 0xD4, 0xCB, 0xE4, 0x93, 0x82, 0x11,
  39525. 0x72, 0x9A, 0xE9, 0x87, 0xEC, 0xCC, 0x6D, 0xA1,
  39526. 0x7D, 0x47, 0x60, 0x20, 0xB6, 0xEE, 0xC6, 0xAA,
  39527. 0xC0, 0x3C, 0x95, 0x08, 0xA0, 0x8B, 0xFA, 0x04,
  39528. 0xF6, 0x6F, 0x65, 0x48, 0xCA, 0xA7, 0xA3, 0xA8,
  39529. 0xBB, 0x3B, 0x80, 0x91, 0xB6, 0x6D, 0x2F, 0x9D,
  39530. 0x97, 0xBB, 0x52, 0xE6, 0xC4, 0x24, 0x99, 0x97,
  39531. 0x63, 0xAD, 0xD2, 0xFD, 0xB3, 0x94, 0x6D, 0xC1,
  39532. 0xFB, 0xFA, 0x89, 0x45, 0x78, 0x80, 0x3C, 0xAA,
  39533. 0x3F, 0xC0, 0x7E, 0x8D, 0x37, 0x00, 0xA7, 0x70,
  39534. 0xD6, 0x57, 0x2A, 0xD3, 0x17, 0xB1, 0x9E, 0xDF,
  39535. 0x96, 0x98, 0x40, 0xB8, 0x1C, 0xCC, 0xC6, 0xCD,
  39536. 0xCD, 0xB0, 0xF3, 0x23, 0x53, 0xB6, 0x45, 0x78,
  39537. 0xA6, 0xA0, 0x88, 0x61, 0x06, 0x04, 0x8E, 0x1B,
  39538. 0xCD, 0x12, 0x29, 0x50, 0x0F, 0xD2, 0x8C, 0x89,
  39539. 0x51, 0xD1, 0x74, 0x0B, 0xE3, 0xA7, 0x75, 0x8A,
  39540. 0x60, 0x95, 0xEF, 0x6A, 0x98, 0xC7, 0x35, 0xA5,
  39541. 0xC0, 0xFB, 0x4C, 0x88, 0xA1, 0xDA, 0xCE, 0x79,
  39542. 0x3D, 0x4E, 0x4F, 0x91, 0x75, 0x88, 0xE0, 0x5F,
  39543. 0x17, 0xF5, 0xEF, 0xF8, 0x49, 0xFE, 0xB1, 0xDB,
  39544. 0x0D, 0xE8, 0xB2, 0xF7, 0xD4, 0x90, 0xBD, 0xB0,
  39545. 0x6B, 0x3A, 0x1B, 0xB5, 0xC6, 0xFB, 0x93, 0xEF,
  39546. 0xF3, 0xDD, 0x60, 0xEA, 0x67, 0x11, 0xFE, 0x6A,
  39547. 0xCC, 0x2C, 0x64, 0x2A, 0x85, 0x2E, 0x24, 0x39,
  39548. 0x34, 0x6B, 0xBC, 0xF8, 0x89, 0xB3, 0x49, 0x82,
  39549. 0x9C, 0xC0, 0x04, 0x29, 0x6D, 0x25, 0xCB, 0x19,
  39550. 0xE1, 0x53, 0xC6, 0x10, 0x7D, 0x62, 0x07, 0xD2,
  39551. 0x83, 0x8B, 0x89, 0x04, 0x70, 0x06, 0x60, 0x4F,
  39552. 0xB6, 0x10, 0x2B, 0xA0, 0x92, 0xF4, 0x1A, 0x7A,
  39553. 0xD6, 0x4F, 0xDC, 0x6C, 0x6C, 0x27, 0xE5, 0xEC,
  39554. 0x68, 0x1B, 0x95, 0x7C, 0x1C, 0x95, 0x2C, 0xB7,
  39555. 0x0A, 0x8D, 0xC7, 0x57, 0x92, 0x00, 0x4D, 0xC0,
  39556. 0x5F, 0xD4, 0xF4, 0x88, 0x3F, 0x8D, 0x43, 0x12,
  39557. 0x05, 0xE2, 0x14, 0x0E, 0xDD, 0x2C, 0xEC, 0xD5,
  39558. 0x2F, 0x1A, 0xE6, 0x97, 0xDC, 0xFE, 0x96, 0x80,
  39559. 0x67, 0x3B, 0xD4, 0x63, 0x73, 0xFA, 0xC8, 0x4F,
  39560. 0x4C, 0x4F, 0x2D, 0x68, 0x76, 0x44, 0x8E, 0xC2,
  39561. 0x19, 0x99, 0x44, 0xEA, 0xF2, 0x33, 0x23, 0x83,
  39562. 0xC8, 0xB1, 0x7C, 0x27, 0x43, 0x9B, 0x67, 0xF9,
  39563. 0xDE, 0xE1, 0xAE, 0x03, 0xA5, 0xA5, 0x2B, 0x96,
  39564. 0xB2, 0xEC, 0x4A, 0x43, 0xA7, 0x6D, 0xF4, 0xDB,
  39565. 0x32, 0x5B, 0x54, 0xD6, 0x63, 0xEA, 0x65, 0xC2,
  39566. 0xA8, 0x4B, 0x80, 0xCC, 0x65, 0x2D, 0xCE, 0x6F,
  39567. 0x61, 0x2F, 0x58, 0xD1, 0xE5, 0x64, 0x8A, 0x42,
  39568. 0x8D, 0xBA, 0xFA, 0x35, 0x5C, 0x9E, 0xD5, 0x80,
  39569. 0x2D, 0x5C, 0xC3, 0x47, 0xFB, 0x0D, 0x43, 0x20,
  39570. 0x7A, 0xA4, 0x37, 0xB2, 0x2F, 0x0B, 0x43, 0xB9,
  39571. 0x94, 0xD3, 0xD9, 0xC2, 0xD7, 0x02, 0x5D, 0x6A,
  39572. 0x12, 0x99, 0xE7, 0x32, 0x6C, 0xF0, 0x0C, 0x73,
  39573. 0x51, 0x33, 0x84, 0xA9, 0x0C, 0x66, 0xC9, 0x19,
  39574. 0x88, 0x9A, 0xF1, 0xB6, 0xF8, 0x41, 0xB1, 0xDC,
  39575. 0x60, 0xA4, 0x80, 0x73, 0x0B, 0x21, 0xF9, 0xB8,
  39576. 0x01, 0x7E, 0x66, 0x0D, 0xB4, 0x2B, 0x53, 0x8D,
  39577. 0x7D, 0x0B, 0xE1, 0xA3, 0x0C, 0x27, 0xF6, 0x2F,
  39578. 0x27, 0x34, 0x53, 0x75, 0x54, 0xF7, 0x5E, 0x05,
  39579. 0x1C, 0x5A, 0x94, 0x08, 0x14, 0xDE, 0xAA, 0x98,
  39580. 0xD9, 0xA5, 0xA0, 0xBE, 0x80, 0xC1, 0xEB, 0x3C,
  39581. 0xCF, 0x78, 0x88, 0xA4, 0xA2, 0x03, 0xF8, 0x79,
  39582. 0x1F, 0x84, 0x84, 0xA7, 0x0E, 0x95, 0x1A, 0x85,
  39583. 0xEF, 0x4C, 0xBE, 0xA2, 0x99, 0xAB, 0x10, 0xDD,
  39584. 0x85, 0x3F, 0x10, 0x6A, 0x9C, 0xD5, 0xDD, 0x7A,
  39585. 0xFB, 0xF5, 0xD9, 0xD9, 0xAA, 0xDF, 0x03, 0x78,
  39586. 0xAF, 0x1D, 0xEC, 0x18, 0xEB, 0x00, 0xB6, 0x64,
  39587. 0xB5, 0x75, 0xA5, 0x00, 0xDC, 0x36, 0x45, 0xBD,
  39588. 0x0C, 0x66, 0xCE, 0xA9, 0xBB, 0xD1, 0xF7, 0xE4,
  39589. 0x6A, 0xDA, 0x0E, 0x81, 0x0F, 0x6A, 0x71, 0x60,
  39590. 0x5C, 0x41, 0xD2, 0x12, 0x45, 0x14, 0xEF, 0x6F,
  39591. 0xEC, 0x22, 0x73, 0x4C, 0xA7, 0x94, 0xDD, 0x1A,
  39592. 0x42, 0x22, 0x58, 0x14, 0x0C, 0x4E, 0x6D, 0x77,
  39593. 0x7F, 0xF5, 0xC9, 0x69, 0x81, 0xA3, 0xB8, 0x6D,
  39594. 0x1C, 0x39, 0x47, 0xA5, 0xC4, 0x61, 0x1C, 0x91,
  39595. 0x2F, 0x67, 0xC3, 0x5E, 0x87, 0x1A, 0x85, 0x81,
  39596. 0x7D, 0x76, 0xF2, 0xE0, 0xB9, 0xD0, 0x43, 0x33,
  39597. 0xF1, 0xC1, 0xBA, 0x48, 0x6F, 0x48, 0xD5, 0xAE,
  39598. 0xB6, 0xDC, 0xAA, 0xCA, 0xEB, 0x0B, 0x6B, 0xFE,
  39599. 0xF4, 0xF1, 0x6E, 0x5D, 0xE4, 0x90, 0x53, 0xCF,
  39600. 0x9E, 0x13, 0x80, 0xCE, 0xE5, 0xDD, 0xA4, 0x01,
  39601. 0xBC, 0x16, 0x50, 0xD0, 0x78, 0x96, 0x3F, 0x2B,
  39602. 0x7A, 0x71, 0x8E, 0x86, 0xFD, 0x14, 0x21, 0xDF,
  39603. 0x4D, 0xD7, 0xDD, 0x42, 0x59, 0xB3, 0xED, 0x81,
  39604. 0xE3, 0xAF, 0x71, 0x57, 0xE7, 0x04, 0xD2, 0x26,
  39605. 0xA8, 0x83, 0xFC, 0x03, 0x90, 0x8C, 0x88, 0xC4,
  39606. 0xBF, 0x74, 0x54, 0x59, 0xD8, 0x66, 0x9F, 0xE2,
  39607. 0x7A, 0xCE, 0x5B, 0x9C, 0xC4, 0x37, 0xFA, 0xDB,
  39608. 0x40, 0x9A, 0xDD, 0x73, 0x9C, 0x06, 0x5A, 0x21,
  39609. 0x43, 0xFB, 0xFA, 0x1B, 0x41, 0x31, 0x9F, 0xF4,
  39610. 0x24, 0x09, 0x05, 0xFE, 0x56, 0x17, 0x52, 0x9C,
  39611. 0xC7, 0xE2, 0xCA, 0xC9, 0x1F, 0xBE, 0xE2, 0xEB,
  39612. 0x92, 0xEE, 0xD4, 0x76, 0x44, 0x9A, 0xFA, 0xFB,
  39613. 0x07, 0x62, 0x98, 0xEC, 0xA0, 0xCF, 0xBF, 0xFA,
  39614. 0x5E, 0x1B, 0x8B, 0xCD, 0x33, 0xFB, 0x1A, 0x97,
  39615. 0xFE, 0x50, 0x65, 0x22, 0x08, 0x9E, 0xC3, 0x87,
  39616. 0x88, 0xCA, 0xDD, 0x11, 0x5E, 0xA7, 0xCF, 0xF3,
  39617. 0x07, 0x0A, 0x34, 0x0E, 0x30, 0x1B, 0xC5, 0xCE,
  39618. 0xF7, 0xA6, 0xA4, 0x31, 0xB5, 0x40, 0xB8, 0x81,
  39619. 0xAC, 0xAA, 0x07, 0xE0, 0x7D, 0x5E, 0x6A, 0x25,
  39620. 0x85, 0x8D, 0x1D, 0x82, 0x45, 0x82, 0x76, 0xB2,
  39621. 0x65, 0x69, 0x3E, 0x88, 0xFE, 0x21, 0xFE, 0x6A,
  39622. 0x6B, 0x97, 0xD6, 0x70, 0x70, 0x00, 0x83, 0x18,
  39623. 0x39, 0xA6, 0x91, 0x3F, 0xB1, 0xB7, 0xED, 0x11,
  39624. 0xD3, 0xF9, 0x74, 0x31, 0xEC, 0x21, 0xA2, 0xEE,
  39625. 0x69, 0x04, 0xC0, 0xEA, 0x4A, 0x17, 0x1A, 0xF8,
  39626. 0xDA, 0xF1, 0x52, 0xB2, 0x78, 0x69, 0x4F, 0xDF,
  39627. 0xE6, 0xB9, 0xF3, 0xE7, 0x48, 0x8B, 0x09, 0x5F,
  39628. 0x4A, 0x7A, 0x05, 0x8E, 0xA8, 0xF6, 0x69, 0x3D,
  39629. 0x91, 0x7A, 0x6F, 0x6C, 0xAD, 0x03, 0x16, 0xEA,
  39630. 0xE0, 0x04, 0xFE, 0x54, 0x71, 0x50, 0x6D, 0x31,
  39631. 0xE4, 0x37, 0x76, 0xD6, 0x1B, 0xA9, 0xEE, 0x56,
  39632. 0x7A, 0x39, 0x34, 0x24, 0x00, 0x58, 0xE3, 0x2F,
  39633. 0xD4, 0x97, 0x57, 0x6F, 0xD8, 0x0E, 0x8B, 0xD3,
  39634. 0x88, 0x7F, 0xE8, 0x74, 0x72, 0xF7, 0xBA, 0x26,
  39635. 0x25, 0xE4, 0xD5, 0x86, 0xCD, 0xA8, 0x1E, 0x8D,
  39636. 0x49, 0xCF, 0x04, 0x92, 0x5B, 0x50, 0xD0, 0x73,
  39637. 0x3C, 0xC9, 0x17, 0xC3, 0x0E, 0x67, 0x02, 0xC5,
  39638. 0xDE, 0x48, 0x88, 0x0D, 0x2C, 0x0D, 0x68, 0x04,
  39639. 0xD5, 0x51, 0xDF, 0x4F, 0x23, 0x89, 0x7A, 0x29,
  39640. 0x41, 0xB2, 0x7A, 0xCA, 0x86, 0xA5, 0xCC, 0xC4,
  39641. 0xF5, 0xD3, 0xE1, 0xEF, 0xB8, 0xCD, 0x84, 0xB5,
  39642. 0x6D, 0xB6, 0x51, 0x1B, 0x81, 0x26, 0x97, 0xAC,
  39643. 0x00, 0xFC, 0x76, 0x8D, 0x99, 0xD9, 0x35, 0x8E,
  39644. 0x4D, 0x3E, 0xC0, 0xC1, 0x0E, 0x8D, 0x9B, 0xE5,
  39645. 0x79, 0xF3, 0xC7, 0xA0, 0xA4, 0xA6, 0xA2, 0xE9,
  39646. 0x8B, 0xCD, 0x36, 0x79, 0x76, 0xF1, 0x6A, 0xEE,
  39647. 0xCF, 0x91, 0x8D, 0x91, 0xB1, 0xAF, 0xF2, 0xF5,
  39648. 0x43, 0xF6, 0xB2, 0x3A, 0x39, 0x9F, 0xBF, 0xDE,
  39649. 0x16, 0x03, 0x52, 0x18, 0x62, 0x93, 0xB5, 0x09,
  39650. 0xC4, 0xEE, 0x27, 0x9C, 0x56, 0x6F, 0x0C, 0x1C,
  39651. 0x12, 0x42, 0xF0, 0x34, 0xBD, 0x44, 0x52, 0x4C,
  39652. 0x32, 0x7E, 0x64, 0xDF, 0x78, 0x16, 0xD9, 0x9E,
  39653. 0xD7, 0x8A, 0x11, 0x33, 0x65, 0x42, 0xEC, 0x36,
  39654. 0x07, 0xEE, 0x3F, 0x19, 0x97, 0x9B, 0x92, 0x9D,
  39655. 0x3A, 0xE4, 0x98, 0x83, 0xDB, 0x0C, 0x85, 0x39,
  39656. 0xFA, 0x8D, 0x73, 0xF5, 0xBF, 0xE0, 0x75, 0x40,
  39657. 0x50, 0x9B, 0xF2, 0xE6, 0xB6, 0xA5, 0x33, 0xD0,
  39658. 0xC4, 0xD6, 0xAB, 0xFF, 0x16, 0xDE, 0x30, 0x9C,
  39659. 0x68, 0x90, 0xE0, 0x5E, 0xD3, 0xD5, 0xA9, 0xB0,
  39660. 0xD9, 0x6B, 0x0A, 0x43, 0x45, 0x9A, 0x3D, 0xE8,
  39661. 0xB6, 0x66, 0xE4, 0x57, 0x05, 0x8E, 0x5B, 0x72,
  39662. 0xFE, 0x50, 0x44, 0x8C, 0xE4, 0x68, 0x43, 0x51,
  39663. 0x0D, 0x9A, 0xD3, 0x36, 0xA9, 0xC7, 0xF6, 0xCF,
  39664. 0x6D, 0x2C, 0x95, 0x46, 0x98, 0x6D, 0x9E, 0x78,
  39665. 0x90, 0x87, 0x19, 0x64, 0xD5, 0xDE, 0x1D, 0x9B,
  39666. 0x37, 0x4E, 0x52, 0xF5, 0x14, 0xAA, 0xEE, 0x31,
  39667. 0x83, 0x55, 0x7C, 0x38, 0x0F, 0xB3, 0xF6, 0xF2,
  39668. 0x1C, 0x60, 0x71, 0x68, 0x1F, 0x06, 0xBD, 0x99,
  39669. 0xFD, 0x42, 0x12, 0x54, 0x3E, 0xBA, 0x4B, 0x60,
  39670. 0xFB, 0xFB, 0x51, 0x4D, 0x02, 0xCE, 0xE5, 0x9E,
  39671. 0x59, 0xB2, 0xE6, 0x98, 0x67, 0xBB, 0xAB, 0xC8,
  39672. 0x08, 0xE4, 0x08, 0x0D, 0xF5, 0x3B, 0x47, 0x78,
  39673. 0x39, 0x24, 0x56, 0x80, 0xF0, 0x6A, 0x1D, 0x33,
  39674. 0x05, 0x5F, 0xF2, 0xA2, 0x38, 0xAD, 0xDF, 0x5C,
  39675. 0xC5, 0xEA, 0x9C, 0xC7, 0x0A, 0x1B, 0x5B, 0x43,
  39676. 0xE9, 0x59, 0x3D, 0x68, 0x00, 0x23, 0x32, 0x5D,
  39677. 0x25, 0xFD, 0xA7, 0xCA, 0xDA, 0xA1, 0xFD, 0x22,
  39678. 0x4E, 0x34, 0x96, 0xE7, 0x0D, 0xFF, 0x89, 0x3B,
  39679. 0xA6, 0x56, 0x0D, 0x11, 0x13, 0xA6, 0x9D, 0x3B,
  39680. 0xBC, 0x12, 0x97, 0x9A, 0x2B, 0xAA, 0xE9, 0xE2,
  39681. 0xCF, 0xD2, 0xD3, 0xEF, 0x95, 0xFC, 0x40, 0x80,
  39682. 0x94, 0x48, 0x80, 0x5A, 0x3F, 0x4A, 0xD2, 0xB5,
  39683. 0x7D, 0x61, 0xA2, 0x26, 0x7B, 0xDC, 0x32, 0xCB,
  39684. 0x84, 0x2E, 0x9B, 0x29, 0x63, 0x45, 0x74, 0x0D,
  39685. 0x85, 0x54, 0xB2, 0x16, 0x77, 0x9B, 0x47, 0x51,
  39686. 0x63, 0x33, 0xE9, 0x1A, 0x52, 0x9D, 0xEB, 0x26,
  39687. 0x06, 0x7F, 0x97, 0xA0, 0xA1, 0xAA, 0x07, 0x0F,
  39688. 0x1E, 0x23, 0xAB, 0xCC, 0xD5, 0x0F, 0x3E, 0x88,
  39689. 0xAA, 0xC3, 0xED, 0x06, 0x25, 0x3A, 0x4A, 0x62,
  39690. 0x85, 0x9F, 0xA7, 0xD3, 0xF5, 0x1C, 0x9A, 0xCC,
  39691. 0x52, 0x87, 0x9F, 0xB8, 0xC7, 0xDD, 0xF1, 0x50,
  39692. 0x66, 0x70, 0xAC, 0xC6, 0x2C, 0x2E, 0x8C, 0xC9,
  39693. 0xD9, 0xF6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  39694. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  39695. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  39696. 0x00, 0x00, 0x00, 0x06, 0x0D, 0x13, 0x1D, 0x20,
  39697. 0x27, 0x2C, 0x32
  39698. };
  39699. #endif
  39700. byte sig[DILITHIUM_MAX_SIG_SIZE];
  39701. word32 sigLen;
  39702. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  39703. ExpectNotNull(key);
  39704. if (key != NULL) {
  39705. XMEMSET(key, 0, sizeof(*key));
  39706. }
  39707. ExpectIntEQ(wc_dilithium_init_ex(key, NULL, INVALID_DEVID), 0);
  39708. #ifndef WOLFSSL_NO_ML_DSA_44
  39709. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  39710. ExpectIntEQ(wc_dilithium_import_private(sk_44, (word32)sizeof(sk_44), key),
  39711. 0);
  39712. sigLen = PARAMS_ML_DSA_44_SIG_SIZE;
  39713. ExpectIntEQ(wc_dilithium_sign_msg_with_seed(msg_44, (word32)sizeof(msg_44),
  39714. sig, &sigLen, key, rnd_44), 0);
  39715. ExpectIntEQ(sigLen, PARAMS_ML_DSA_44_SIG_SIZE);
  39716. ExpectIntEQ(XMEMCMP(sig, sig_44, sizeof(sig_44)), 0);
  39717. #endif
  39718. #ifndef WOLFSSL_NO_ML_DSA_65
  39719. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  39720. ExpectIntEQ(wc_dilithium_import_private(sk_65, (word32)sizeof(sk_65), key),
  39721. 0);
  39722. sigLen = PARAMS_ML_DSA_65_SIG_SIZE;
  39723. ExpectIntEQ(wc_dilithium_sign_msg_with_seed(msg_65, (word32)sizeof(msg_65),
  39724. sig, &sigLen, key, rnd_65), 0);
  39725. ExpectIntEQ(sigLen, PARAMS_ML_DSA_65_SIG_SIZE);
  39726. ExpectIntEQ(XMEMCMP(sig, sig_65, sizeof(sig_65)), 0);
  39727. #endif
  39728. #ifndef WOLFSSL_NO_ML_DSA_87
  39729. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  39730. ExpectIntEQ(wc_dilithium_import_private(sk_87, (word32)sizeof(sk_87), key),
  39731. 0);
  39732. sigLen = PARAMS_ML_DSA_87_SIG_SIZE;
  39733. ExpectIntEQ(wc_dilithium_sign_msg_with_seed(msg_87, (word32)sizeof(msg_87),
  39734. sig, &sigLen, key, rnd_87), 0);
  39735. ExpectIntEQ(sigLen, PARAMS_ML_DSA_87_SIG_SIZE);
  39736. ExpectIntEQ(XMEMCMP(sig, sig_87, sizeof(sig_87)), 0);
  39737. #endif
  39738. wc_dilithium_free(key);
  39739. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  39740. #endif
  39741. return EXPECT_RESULT();
  39742. }
  39743. static int test_wc_dilithium_verify_kats(void)
  39744. {
  39745. EXPECT_DECLS;
  39746. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  39747. !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  39748. dilithium_key* key;
  39749. int res;
  39750. #ifndef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  39751. #ifndef WOLFSSL_NO_ML_DSA_44
  39752. static const byte pk_44[] = {
  39753. 0x09, 0xB4, 0x88, 0x7D, 0x97, 0xBC, 0xF6, 0x37,
  39754. 0x9C, 0xC5, 0x9B, 0x61, 0x62, 0xC1, 0xE8, 0xBF,
  39755. 0x05, 0x60, 0xBF, 0x44, 0xD6, 0x18, 0x09, 0x17,
  39756. 0x0E, 0x6E, 0x28, 0xF7, 0x06, 0x69, 0xA3, 0xE9,
  39757. 0x49, 0x64, 0x38, 0xE8, 0x91, 0x57, 0x35, 0xAD,
  39758. 0xAE, 0xB4, 0x45, 0xCF, 0xDB, 0x7D, 0x89, 0xB3,
  39759. 0x8C, 0x04, 0x8F, 0x4C, 0x3E, 0x00, 0x58, 0x15,
  39760. 0x14, 0xC5, 0xFD, 0x19, 0x8B, 0x2D, 0x17, 0x39,
  39761. 0xE8, 0x83, 0xB8, 0x78, 0xD5, 0x6B, 0xB4, 0x12,
  39762. 0x64, 0xBE, 0x41, 0xD3, 0xD5, 0x15, 0x65, 0xE2,
  39763. 0xE9, 0xCA, 0xE3, 0x31, 0x84, 0xA8, 0x99, 0xF6,
  39764. 0x2D, 0xD5, 0x7D, 0x07, 0x40, 0x0E, 0x98, 0xE5,
  39765. 0x86, 0x87, 0xA9, 0xB2, 0x2F, 0xA3, 0x17, 0xEE,
  39766. 0xD1, 0x34, 0xCA, 0x72, 0x14, 0xBF, 0xF0, 0x21,
  39767. 0xDD, 0x21, 0x62, 0xB1, 0x83, 0x09, 0x1D, 0x15,
  39768. 0xF2, 0x63, 0xB7, 0x29, 0x82, 0x14, 0x42, 0x3C,
  39769. 0x6B, 0xB6, 0x96, 0xD7, 0x5C, 0x20, 0xD9, 0xEA,
  39770. 0xCD, 0x0A, 0x03, 0xE4, 0x26, 0x2C, 0x4B, 0x08,
  39771. 0xBE, 0x39, 0xFA, 0x21, 0x54, 0xBD, 0x6E, 0x50,
  39772. 0x25, 0xFF, 0x79, 0x1E, 0x88, 0x5F, 0x22, 0x26,
  39773. 0xE3, 0xCF, 0x48, 0xF7, 0xB5, 0xEB, 0x04, 0xFB,
  39774. 0xE9, 0xEC, 0xF7, 0x5B, 0x19, 0xE1, 0xD1, 0x5C,
  39775. 0x30, 0x5E, 0x92, 0x26, 0x0A, 0xB0, 0xD6, 0xAE,
  39776. 0x7D, 0xBA, 0x7B, 0xBE, 0x73, 0xB6, 0xBC, 0x18,
  39777. 0x1C, 0xF9, 0x33, 0x84, 0x0C, 0xC1, 0x0A, 0x00,
  39778. 0x05, 0x02, 0x28, 0xFA, 0x46, 0xA2, 0x63, 0x6D,
  39779. 0xD9, 0xA9, 0x09, 0x47, 0xE9, 0xF1, 0x3A, 0x93,
  39780. 0xEF, 0x4C, 0x62, 0xBE, 0x37, 0x4D, 0x76, 0xD1,
  39781. 0xFD, 0xBB, 0xC5, 0xD8, 0xB5, 0x5E, 0x72, 0x9F,
  39782. 0xA5, 0x86, 0x65, 0xAA, 0x07, 0xB9, 0x0C, 0x8C,
  39783. 0xDD, 0xD6, 0x1C, 0x56, 0x6B, 0x0D, 0x7E, 0xD6,
  39784. 0x57, 0x70, 0x49, 0x2E, 0xA0, 0x71, 0x3E, 0x1E,
  39785. 0xD4, 0x6A, 0xC7, 0xAD, 0x15, 0x03, 0xC5, 0x6D,
  39786. 0x90, 0x52, 0xD2, 0xC9, 0x4D, 0x49, 0xE4, 0x41,
  39787. 0x6A, 0xC9, 0x2B, 0x70, 0x39, 0x6F, 0x76, 0xF6,
  39788. 0xFB, 0x48, 0x10, 0x45, 0x68, 0x17, 0x25, 0xA6,
  39789. 0x8C, 0xB3, 0x56, 0x37, 0x7F, 0xB2, 0x31, 0xAB,
  39790. 0x8F, 0x3E, 0xB9, 0xA4, 0x98, 0x2F, 0xFF, 0x18,
  39791. 0x36, 0x47, 0x3B, 0xCB, 0xDA, 0xB6, 0x87, 0x2D,
  39792. 0x22, 0x94, 0x67, 0xEF, 0xB9, 0x36, 0x62, 0x61,
  39793. 0xFE, 0xB1, 0x48, 0xBA, 0x9B, 0x7D, 0xB9, 0xC4,
  39794. 0xFE, 0x0B, 0xB8, 0x86, 0x12, 0xAB, 0xB8, 0xFD,
  39795. 0x61, 0x09, 0x6F, 0x18, 0x19, 0x60, 0x4D, 0x55,
  39796. 0xDF, 0x60, 0x20, 0x46, 0x4D, 0x3F, 0x09, 0x2C,
  39797. 0xFC, 0xA5, 0x98, 0x12, 0x08, 0x22, 0x18, 0x56,
  39798. 0x68, 0x99, 0xA5, 0x6A, 0x3C, 0x63, 0x3C, 0xC8,
  39799. 0x1F, 0x88, 0xAD, 0xB2, 0xE1, 0x41, 0x4E, 0xF3,
  39800. 0x85, 0x0D, 0x10, 0xBF, 0x5A, 0x77, 0xAC, 0xE7,
  39801. 0x24, 0xD6, 0xC1, 0xF3, 0x88, 0x92, 0x87, 0x44,
  39802. 0xB3, 0xE5, 0x42, 0xAE, 0x49, 0x1C, 0xD5, 0x6A,
  39803. 0x64, 0x21, 0x3F, 0x1D, 0x3C, 0xC9, 0x0B, 0x29,
  39804. 0x10, 0x5F, 0x43, 0xD2, 0x37, 0xC8, 0x3D, 0x5F,
  39805. 0xB8, 0x29, 0x32, 0x5C, 0x83, 0xE6, 0x54, 0x57,
  39806. 0x77, 0x76, 0x39, 0x2F, 0x85, 0x36, 0xAA, 0x9D,
  39807. 0xAE, 0x87, 0x24, 0x07, 0xAB, 0xAA, 0xA9, 0xAC,
  39808. 0xC2, 0x2A, 0x68, 0x12, 0xCE, 0xA7, 0x4C, 0x0B,
  39809. 0xA6, 0x7E, 0xAF, 0x4A, 0x41, 0x01, 0x52, 0x97,
  39810. 0x5E, 0x9A, 0x83, 0xEE, 0x44, 0x69, 0x29, 0x53,
  39811. 0x17, 0xBE, 0xD1, 0x05, 0x51, 0xBA, 0x32, 0xE6,
  39812. 0x5A, 0xFC, 0x8C, 0x8E, 0x68, 0xDD, 0x55, 0x42,
  39813. 0x0C, 0x50, 0x2D, 0x93, 0x7D, 0xAD, 0xD2, 0xEF,
  39814. 0xA2, 0xCB, 0xFD, 0x1F, 0x73, 0x9F, 0xC0, 0xAB,
  39815. 0x2B, 0x26, 0x54, 0xFA, 0xE0, 0x8C, 0x0C, 0x7F,
  39816. 0x8E, 0xDD, 0x43, 0xCF, 0x9F, 0xF0, 0xB0, 0x1D,
  39817. 0x98, 0x4D, 0x49, 0x18, 0x52, 0xA3, 0x72, 0xE9,
  39818. 0xFE, 0xFD, 0xCC, 0x1B, 0xC1, 0x6C, 0xDB, 0x52,
  39819. 0x39, 0xAE, 0x10, 0x01, 0x15, 0x5F, 0x89, 0x56,
  39820. 0x30, 0x51, 0xCE, 0x47, 0x99, 0x6C, 0x5A, 0xEE,
  39821. 0xB2, 0x19, 0x0E, 0xA1, 0x8F, 0x7F, 0x73, 0x40,
  39822. 0x42, 0xDE, 0x68, 0xE9, 0x88, 0x36, 0x7D, 0x89,
  39823. 0x35, 0x5D, 0x9D, 0x83, 0x77, 0xBA, 0xF9, 0x64,
  39824. 0x79, 0x78, 0xEB, 0x2E, 0x49, 0x2A, 0xD0, 0x21,
  39825. 0xC5, 0x69, 0xAE, 0x8B, 0xA6, 0x9B, 0x15, 0xF1,
  39826. 0xFC, 0xF7, 0x03, 0x9A, 0x7E, 0x64, 0xAF, 0x10,
  39827. 0xAB, 0xF3, 0xEA, 0x45, 0xB7, 0x22, 0x2F, 0x96,
  39828. 0x59, 0xE3, 0x33, 0x73, 0x37, 0x2E, 0x1D, 0xB1,
  39829. 0x86, 0xD2, 0xC2, 0xA0, 0xD7, 0x54, 0x51, 0xC4,
  39830. 0x78, 0xAE, 0xF3, 0x3E, 0x59, 0x49, 0xF2, 0x40,
  39831. 0x04, 0x0C, 0x2A, 0xFC, 0x44, 0xB1, 0xD3, 0xA0,
  39832. 0x2A, 0x6D, 0x2F, 0x87, 0x90, 0x2A, 0x28, 0x0E,
  39833. 0x27, 0xA2, 0x0D, 0x4E, 0x57, 0xF8, 0x89, 0x66,
  39834. 0x27, 0x00, 0xDB, 0x8A, 0x9D, 0x24, 0x99, 0x57,
  39835. 0xA7, 0xDB, 0x43, 0x7C, 0xD4, 0x80, 0xDD, 0xC0,
  39836. 0x58, 0x84, 0xFB, 0x23, 0xF8, 0x68, 0x26, 0x8E,
  39837. 0xAC, 0xE3, 0x4E, 0xED, 0x27, 0x4A, 0x92, 0x7D,
  39838. 0x9D, 0x84, 0xF1, 0xEA, 0x57, 0xEA, 0xB1, 0xA8,
  39839. 0x13, 0xB5, 0xE6, 0xAA, 0xBE, 0x9E, 0xD2, 0x61,
  39840. 0x0B, 0xC6, 0xF7, 0x2E, 0x32, 0x0C, 0xDE, 0xC4,
  39841. 0xF9, 0x95, 0x23, 0xF9, 0x3F, 0xA4, 0x48, 0xDC,
  39842. 0x1F, 0xBB, 0xDD, 0x25, 0x9B, 0x10, 0x2F, 0x5D,
  39843. 0xC9, 0x95, 0x5A, 0xFA, 0x0C, 0x41, 0x60, 0x4D,
  39844. 0x83, 0xDD, 0x1C, 0x2D, 0x22, 0x95, 0xEF, 0x44,
  39845. 0x61, 0x45, 0x6B, 0xAE, 0x86, 0x90, 0x5C, 0x4C,
  39846. 0x30, 0xD8, 0xA9, 0xFA, 0x48, 0xC9, 0x0F, 0x37,
  39847. 0xA1, 0x9C, 0x41, 0xA2, 0xD5, 0x98, 0x8F, 0x13,
  39848. 0xD5, 0x13, 0x44, 0xEC, 0x30, 0xA4, 0xA4, 0x62,
  39849. 0x19, 0xFE, 0x84, 0x11, 0x37, 0xD5, 0xAA, 0x1F,
  39850. 0x51, 0xE6, 0xC4, 0x44, 0x16, 0x8A, 0xF3, 0x98,
  39851. 0x90, 0xB6, 0xFA, 0x40, 0x0D, 0x67, 0xF4, 0x80,
  39852. 0x6F, 0x5B, 0xBD, 0x44, 0x47, 0x03, 0x07, 0x4A,
  39853. 0x7A, 0x11, 0x39, 0xC7, 0x17, 0x46, 0xD7, 0xC4,
  39854. 0xCE, 0xB3, 0xC9, 0x11, 0xF5, 0x25, 0x7E, 0x3E,
  39855. 0x53, 0xEB, 0xFA, 0x5A, 0xA8, 0xF2, 0x27, 0x80,
  39856. 0x9D, 0x44, 0xEE, 0x7D, 0xE1, 0x3C, 0x02, 0x79,
  39857. 0x24, 0xDD, 0x60, 0x15, 0x3B, 0x30, 0xAA, 0x76,
  39858. 0xDD, 0x96, 0xA7, 0xC5, 0xAC, 0xC5, 0x9B, 0x62,
  39859. 0x79, 0x19, 0x50, 0x7B, 0xF1, 0x42, 0x57, 0xAE,
  39860. 0x7A, 0x26, 0x24, 0x3C, 0x16, 0x83, 0xB2, 0x8D,
  39861. 0x1B, 0x14, 0xB5, 0x01, 0xAD, 0x05, 0x9B, 0x4D,
  39862. 0x52, 0x2A, 0x57, 0x99, 0x1E, 0x55, 0x39, 0xCE,
  39863. 0xF1, 0x8C, 0xEB, 0x5C, 0x26, 0xD6, 0x60, 0xB8,
  39864. 0x82, 0x24, 0x54, 0xC9, 0xC4, 0x2A, 0x95, 0xE6,
  39865. 0xF7, 0x2B, 0x84, 0xF7, 0x8A, 0xB9, 0x9F, 0x51,
  39866. 0xEC, 0x49, 0x78, 0x9F, 0x9D, 0xB4, 0xC1, 0x28,
  39867. 0xB0, 0x31, 0x8F, 0xFF, 0xC8, 0x2D, 0x95, 0xCA,
  39868. 0xD2, 0x77, 0xF1, 0x1E, 0x14, 0xF1, 0xEF, 0x87,
  39869. 0x14, 0x14, 0x88, 0x11, 0x22, 0xA9, 0xB1, 0x1B,
  39870. 0xDF, 0xAE, 0x4A, 0x7A, 0xBC, 0x8E, 0x75, 0x75,
  39871. 0x5A, 0xB1, 0x37, 0x41, 0xDF, 0xAC, 0xD6, 0x64,
  39872. 0x29, 0x3D, 0x1A, 0x32, 0x6B, 0xF5, 0xED, 0x5A,
  39873. 0xBB, 0xB1, 0x53, 0xEB, 0xE6, 0x99, 0x6D, 0xD6,
  39874. 0x22, 0xF0, 0xA8, 0xCB, 0x47, 0x39, 0x69, 0xA5,
  39875. 0x03, 0x66, 0xBD, 0x0B, 0x01, 0xC5, 0xC7, 0x3A,
  39876. 0x89, 0x2B, 0x8E, 0x26, 0xCE, 0x08, 0xF7, 0x5F,
  39877. 0xF8, 0x01, 0xB6, 0xDE, 0xF0, 0x41, 0xE1, 0x71,
  39878. 0x3B, 0xE6, 0xDF, 0x0E, 0xFB, 0x51, 0x58, 0x7B,
  39879. 0xE5, 0xFB, 0xEA, 0x72, 0x7E, 0x00, 0xD7, 0x17,
  39880. 0x64, 0x7D, 0xD5, 0x39, 0x07, 0x9D, 0xE1, 0x8A,
  39881. 0xE7, 0xBE, 0xD1, 0x2B, 0x91, 0xAF, 0x8D, 0xBB,
  39882. 0x1B, 0x8B, 0x32, 0xD2, 0x86, 0x0B, 0xAF, 0x40,
  39883. 0xAF, 0x8A, 0x0B, 0xBF, 0xE0, 0x28, 0x87, 0xEB,
  39884. 0x5D, 0xBE, 0x7A, 0xB1, 0xAF, 0xC4, 0x1D, 0xA7,
  39885. 0x9B, 0x01, 0x6A, 0xA1, 0x6E, 0xDA, 0x28, 0x13,
  39886. 0x21, 0xCA, 0xA5, 0xDA, 0x64, 0x4F, 0xD8, 0x65,
  39887. 0x8A, 0x7B, 0x70, 0x21, 0x81, 0x00, 0x14, 0x31,
  39888. 0x56, 0x0D, 0xD6, 0x3C, 0xB2, 0x1E, 0x5F, 0xF7,
  39889. 0x5C, 0x3F, 0x72, 0x50, 0x45, 0x6B, 0xE0, 0x8C,
  39890. 0x0D, 0x5E, 0x34, 0xC3, 0xBD, 0xE2, 0xF6, 0x06,
  39891. 0xA2, 0xBF, 0x34, 0x17, 0x76, 0x8D, 0x24, 0xB2,
  39892. 0x37, 0x39, 0xEA, 0x86, 0xCB, 0xEF, 0xDD, 0xA3,
  39893. 0x43, 0x88, 0xBC, 0x1F, 0x91, 0x8F, 0x95, 0x1E,
  39894. 0x15, 0xE4, 0x3B, 0x13, 0x85, 0xA7, 0xBC, 0xC5,
  39895. 0x59, 0xF9, 0x49, 0x2C, 0x72, 0x13, 0xA1, 0x42,
  39896. 0x27, 0xE0, 0x93, 0xE9, 0x29, 0xF3, 0x2D, 0x1E,
  39897. 0xFB, 0xE7, 0xF1, 0xEE, 0x57, 0xC4, 0x9C, 0x90,
  39898. 0x55, 0x62, 0x3E, 0xA4, 0x2E, 0xC6, 0xC7, 0x9D,
  39899. 0x7F, 0xCE, 0x71, 0xFA, 0x74, 0x76, 0x07, 0x56,
  39900. 0x6D, 0xDA, 0x69, 0xF6, 0x9D, 0xAF, 0x68, 0x11,
  39901. 0x59, 0x19, 0xC6, 0x32, 0x2E, 0xBB, 0x42, 0xC8,
  39902. 0xC0, 0x89, 0x33, 0x8C, 0x9E, 0x0C, 0x53, 0x56,
  39903. 0x5B, 0xCB, 0xE7, 0x2F, 0xBE, 0x47, 0x26, 0x68,
  39904. 0x7B, 0x07, 0x87, 0x07, 0x18, 0x06, 0xC5, 0xA6,
  39905. 0xC1, 0x49, 0xC8, 0x2B, 0x66, 0x8A, 0xA6, 0x4A,
  39906. 0x7B, 0xA0, 0xCC, 0xC1, 0xCC, 0x49, 0xA1, 0xEE,
  39907. 0xE9, 0x45, 0x3D, 0x04, 0x33, 0x6E, 0x5D, 0xC8,
  39908. 0x11, 0xE0, 0x38, 0x92, 0xF7, 0xF4, 0x66, 0x88,
  39909. 0xEC, 0xEF, 0xD0, 0x4F, 0x18, 0x76, 0xF7, 0x11,
  39910. 0x17, 0x12, 0xB5, 0x95, 0xED, 0x62, 0xDA, 0x00,
  39911. 0x67, 0x8F, 0x9E, 0x37, 0x86, 0xB5, 0xC1, 0xA5,
  39912. 0x09, 0x5B, 0xE8, 0x71, 0x0D, 0xCF, 0xA4, 0x16,
  39913. 0x52, 0x56, 0x50, 0x9E, 0x00, 0x14, 0x3A, 0x6F,
  39914. 0x11, 0x72, 0xFA, 0xBE, 0x8B, 0xF2, 0x1E, 0x5F,
  39915. 0xCE, 0x7C, 0x79, 0xC1, 0xA4, 0x4B, 0x4B, 0x15,
  39916. 0x25, 0xA0, 0x76, 0xFF, 0xB8, 0xDD, 0x90, 0x66
  39917. };
  39918. static const byte msg_44[] = {
  39919. 0x3A, 0xFD, 0x7F, 0xF8, 0xCA, 0xD3, 0xAC, 0xBD,
  39920. 0xF9, 0x77, 0x31, 0x26, 0x1C, 0x7A, 0x1C, 0x96,
  39921. 0x9D, 0x50, 0x16, 0xF1, 0x7D, 0x3E, 0x7F, 0x83,
  39922. 0xD2, 0x44, 0x1A, 0xF9, 0x01, 0x4B, 0x63, 0x47,
  39923. 0x7B, 0x14, 0xA6, 0x41, 0x31, 0x50, 0xFA, 0xD7,
  39924. 0xC8, 0x44, 0x39, 0xBC, 0x88, 0x66, 0x2C, 0x5E,
  39925. 0x93, 0x1F, 0x06, 0xB9, 0x51, 0x41, 0x90, 0xE1,
  39926. 0x3F, 0xB0, 0x49, 0xC4, 0xAB, 0x74, 0x01, 0x32,
  39927. 0x33, 0xB9, 0x8D, 0x48, 0xD9, 0xAF, 0xB6, 0xA3,
  39928. 0x0A, 0x67, 0x33, 0x0E, 0x1F, 0xBE, 0x33, 0x1B,
  39929. 0x09, 0xC5, 0x6D, 0x03, 0x7E, 0x97, 0x01, 0x08,
  39930. 0x5D, 0x80, 0xF1, 0xE7, 0xF4, 0x04, 0x3E, 0xFB,
  39931. 0x53, 0x58, 0x7A, 0xBB, 0x82, 0x36, 0x24, 0x01,
  39932. 0x23, 0x84, 0x51, 0x52, 0x49, 0xEE, 0x61, 0x30,
  39933. 0x97, 0x3D, 0xC9, 0xEA, 0x6F, 0x55, 0x8B, 0xAE,
  39934. 0x75, 0x10, 0x7E, 0xFD, 0xB1, 0xD9, 0x28, 0x5B
  39935. };
  39936. static const byte sig_44[] = {
  39937. 0x4A, 0x2B, 0x16, 0xCD, 0xB5, 0x52, 0xF9, 0x29,
  39938. 0x7F, 0x8E, 0x39, 0x1A, 0xD8, 0xF5, 0xAD, 0xC8,
  39939. 0xCC, 0x5D, 0x2C, 0x56, 0xC4, 0x6B, 0x80, 0x0F,
  39940. 0x9B, 0x3E, 0xE4, 0xBB, 0xD2, 0xF2, 0xE8, 0xA8,
  39941. 0x9D, 0x59, 0x9D, 0x7B, 0x5C, 0xC2, 0xD8, 0x8C,
  39942. 0x80, 0xF2, 0x71, 0x85, 0x9B, 0xBC, 0x83, 0x04,
  39943. 0x3E, 0xC4, 0xE5, 0x48, 0x12, 0xF5, 0x93, 0x6B,
  39944. 0x44, 0x6C, 0x95, 0x13, 0xC8, 0x55, 0x28, 0x9C,
  39945. 0x94, 0xB1, 0x15, 0x51, 0xA0, 0xC7, 0x65, 0x3E,
  39946. 0x7B, 0xA7, 0x4F, 0xFB, 0x6F, 0x72, 0xD4, 0x65,
  39947. 0x2C, 0x91, 0xD3, 0x8D, 0xD1, 0xF9, 0x0D, 0xFE,
  39948. 0x44, 0x39, 0xBC, 0x21, 0xCA, 0x53, 0xE0, 0xCC,
  39949. 0x7A, 0x7A, 0xA5, 0xB8, 0x75, 0xA5, 0xB9, 0xBA,
  39950. 0x42, 0x36, 0x6E, 0xB8, 0xEC, 0xBA, 0x24, 0x36,
  39951. 0xDA, 0xF0, 0x8A, 0x91, 0x97, 0x8D, 0xD0, 0x93,
  39952. 0xF2, 0x0F, 0x1E, 0xFB, 0x6B, 0x0B, 0xCB, 0x90,
  39953. 0xDA, 0x99, 0xCC, 0xA0, 0x5E, 0x8F, 0x6F, 0x82,
  39954. 0xB8, 0x6D, 0x3C, 0x6E, 0xE2, 0x4B, 0xA5, 0xD5,
  39955. 0x0A, 0xEA, 0x10, 0xB2, 0x30, 0x7F, 0x57, 0xF8,
  39956. 0x9E, 0xD7, 0x8D, 0xB4, 0xA7, 0x4F, 0xBB, 0xF6,
  39957. 0xEB, 0x33, 0x2A, 0xFB, 0x08, 0xD0, 0x74, 0xAC,
  39958. 0xF0, 0xDE, 0x5C, 0xD7, 0xFE, 0xC1, 0x2F, 0x76,
  39959. 0xF3, 0xAB, 0x61, 0x9C, 0x81, 0x5B, 0x9E, 0xDD,
  39960. 0x28, 0x7E, 0xAD, 0x67, 0xF0, 0x4F, 0x14, 0x79,
  39961. 0x7F, 0x8D, 0xCF, 0x2C, 0xDE, 0x9A, 0x87, 0x53,
  39962. 0xB5, 0xAD, 0x0A, 0xFA, 0x12, 0x87, 0x41, 0x97,
  39963. 0xD1, 0x74, 0x40, 0x92, 0x87, 0x25, 0x21, 0xE8,
  39964. 0x68, 0xAF, 0x9E, 0x64, 0x45, 0x23, 0x73, 0xFE,
  39965. 0xB6, 0xFE, 0x25, 0xD5, 0x27, 0x3D, 0x63, 0xC0,
  39966. 0xEB, 0xD6, 0xD3, 0xB1, 0x02, 0x8C, 0x1C, 0xD0,
  39967. 0x6A, 0xF3, 0x2C, 0xEC, 0xA2, 0x62, 0x13, 0x10,
  39968. 0x83, 0x7C, 0x72, 0x78, 0x8C, 0x8A, 0xDA, 0xB5,
  39969. 0xA0, 0xF0, 0x38, 0x17, 0x12, 0x8E, 0xB7, 0xB7,
  39970. 0x66, 0xFA, 0x81, 0x2C, 0x69, 0x6C, 0xF8, 0x86,
  39971. 0xF0, 0x0A, 0x10, 0x44, 0xCD, 0xD0, 0x6B, 0xB2,
  39972. 0x8C, 0xB2, 0xE5, 0x78, 0x0C, 0x8D, 0x8C, 0xC7,
  39973. 0xE6, 0x0A, 0xB6, 0x99, 0xDD, 0x78, 0x66, 0x8B,
  39974. 0xE4, 0xFF, 0x9F, 0x46, 0x90, 0xC6, 0xFC, 0x98,
  39975. 0xAA, 0xC9, 0xC0, 0x2B, 0x66, 0xB9, 0xB9, 0x82,
  39976. 0x6A, 0x30, 0x61, 0xFD, 0x32, 0x22, 0xDA, 0x84,
  39977. 0x82, 0x66, 0x79, 0x60, 0xA3, 0x16, 0x52, 0xEE,
  39978. 0x88, 0xEB, 0x32, 0xB0, 0x46, 0x9A, 0xB7, 0x1C,
  39979. 0xAA, 0x25, 0x19, 0xF2, 0x3D, 0x1A, 0x24, 0x42,
  39980. 0xD5, 0xB1, 0x31, 0x62, 0x62, 0x13, 0x1D, 0xCE,
  39981. 0xC5, 0xF2, 0x87, 0xE3, 0x2F, 0xD3, 0x43, 0xFE,
  39982. 0xB4, 0x42, 0x9E, 0x54, 0x25, 0x8D, 0x69, 0x0D,
  39983. 0x9D, 0x20, 0xA1, 0x0A, 0xBD, 0x75, 0xA5, 0x36,
  39984. 0xDF, 0xF8, 0xCF, 0x1D, 0x6D, 0xDF, 0x19, 0x29,
  39985. 0x1E, 0x27, 0x49, 0xA7, 0xD1, 0x6E, 0xB9, 0x0A,
  39986. 0xB5, 0x09, 0x3B, 0xAD, 0x38, 0xE1, 0x16, 0xA8,
  39987. 0x6B, 0x73, 0x0E, 0x65, 0x57, 0x4C, 0x06, 0x8C,
  39988. 0x38, 0xBA, 0x94, 0x57, 0xC9, 0xD6, 0xD9, 0x13,
  39989. 0xEA, 0xFF, 0x57, 0xFE, 0x23, 0xBF, 0x3D, 0xD2,
  39990. 0x4D, 0x8C, 0xA5, 0x11, 0xEF, 0xA3, 0x76, 0xA5,
  39991. 0xDF, 0x08, 0x46, 0x70, 0x25, 0xFF, 0x51, 0xBE,
  39992. 0xAD, 0x3E, 0xDE, 0x0A, 0x84, 0xED, 0xC5, 0x32,
  39993. 0x16, 0x20, 0x99, 0x80, 0x61, 0xE8, 0xA1, 0xA7,
  39994. 0x3D, 0x67, 0xB7, 0x02, 0x1B, 0x81, 0x0C, 0x78,
  39995. 0x67, 0xFF, 0x39, 0x18, 0x7B, 0x59, 0xD4, 0x03,
  39996. 0xBF, 0x7C, 0x75, 0x06, 0x30, 0x0C, 0x73, 0x45,
  39997. 0xB1, 0xFE, 0x07, 0xC1, 0x12, 0x78, 0xB0, 0xAB,
  39998. 0xA6, 0x1D, 0xBB, 0x4F, 0x2B, 0x8C, 0x43, 0xE7,
  39999. 0x4F, 0xEF, 0xA5, 0x5E, 0xD5, 0x2C, 0x10, 0xA8,
  40000. 0xC4, 0x90, 0x88, 0x2B, 0xBF, 0xE3, 0xE3, 0xB3,
  40001. 0xCE, 0x57, 0x9E, 0x81, 0x16, 0xA9, 0xB6, 0x68,
  40002. 0x6C, 0x1A, 0x10, 0x0A, 0xA1, 0xF6, 0x59, 0x1F,
  40003. 0x19, 0x1F, 0x77, 0x2B, 0x5A, 0x5A, 0x50, 0xDD,
  40004. 0x6C, 0xC1, 0x55, 0xCB, 0x5A, 0x1B, 0xE5, 0xBA,
  40005. 0x12, 0x2E, 0x91, 0xF0, 0x44, 0x42, 0x01, 0x56,
  40006. 0xCD, 0x63, 0x08, 0x0F, 0x0A, 0x45, 0xD6, 0x62,
  40007. 0xE7, 0x6D, 0xD5, 0x7B, 0xD0, 0xF6, 0x89, 0xD0,
  40008. 0xB2, 0x99, 0x04, 0x2B, 0xFF, 0x48, 0x5E, 0x8A,
  40009. 0x38, 0x2D, 0x86, 0x5C, 0x26, 0xCD, 0x46, 0xB4,
  40010. 0xA5, 0x47, 0x28, 0xBD, 0x48, 0x45, 0x83, 0x62,
  40011. 0xD7, 0x9A, 0xC3, 0xEB, 0x75, 0x6F, 0xC6, 0xC5,
  40012. 0x18, 0xC9, 0xE2, 0xF0, 0xE7, 0xD5, 0xA3, 0x03,
  40013. 0xAF, 0x11, 0x59, 0xEE, 0x6D, 0xBE, 0x7D, 0xD5,
  40014. 0x6B, 0xA0, 0x71, 0x28, 0x57, 0xA6, 0x88, 0x36,
  40015. 0xC3, 0xC7, 0x8C, 0x6C, 0x9F, 0x74, 0x88, 0x57,
  40016. 0x28, 0x13, 0xC0, 0xF6, 0xA8, 0x14, 0x70, 0x9D,
  40017. 0x2B, 0xC1, 0x42, 0xFE, 0xF0, 0x25, 0x27, 0xCA,
  40018. 0xE7, 0x71, 0x23, 0x58, 0x37, 0x1C, 0x54, 0x26,
  40019. 0x52, 0x2C, 0xCC, 0x64, 0x30, 0x0C, 0x2C, 0xD9,
  40020. 0xFB, 0xE2, 0x0C, 0x65, 0x62, 0xE3, 0x48, 0x35,
  40021. 0x20, 0x5F, 0xCD, 0xD5, 0xA8, 0x98, 0x2C, 0x92,
  40022. 0x0B, 0xB4, 0x77, 0xFB, 0x88, 0x17, 0x02, 0x82,
  40023. 0x7B, 0x49, 0x11, 0x87, 0x13, 0x94, 0xC0, 0x6B,
  40024. 0x5F, 0xEC, 0xD0, 0xC7, 0x40, 0xAF, 0x7B, 0x27,
  40025. 0x63, 0x7B, 0xAC, 0x1A, 0x0C, 0xBC, 0xA5, 0x37,
  40026. 0xE4, 0x43, 0x3E, 0xA8, 0x47, 0x45, 0x4C, 0x69,
  40027. 0x38, 0x97, 0xA3, 0x2E, 0x4D, 0x18, 0x44, 0x19,
  40028. 0x54, 0x26, 0xA0, 0xC6, 0xAE, 0xD6, 0x74, 0x72,
  40029. 0xBD, 0x2C, 0x4E, 0xEE, 0x17, 0x9F, 0x3F, 0x60,
  40030. 0x84, 0xA3, 0x6A, 0x76, 0x89, 0xF4, 0xCB, 0x1F,
  40031. 0x8E, 0x5D, 0xB2, 0xDD, 0xE5, 0x4A, 0xCC, 0x06,
  40032. 0x66, 0xBA, 0x98, 0x41, 0x54, 0x31, 0xA4, 0xB2,
  40033. 0x02, 0xF4, 0x02, 0xFB, 0x1F, 0x1B, 0xCC, 0xDC,
  40034. 0x23, 0xBF, 0xF1, 0x31, 0x48, 0xC7, 0xB8, 0xF6,
  40035. 0x1F, 0xBF, 0x62, 0x43, 0xB2, 0x96, 0xA7, 0x8E,
  40036. 0xB6, 0x98, 0x18, 0x9D, 0xA9, 0x5B, 0xDA, 0x85,
  40037. 0xDB, 0xC1, 0x1D, 0x15, 0xFF, 0xDC, 0x6B, 0xF4,
  40038. 0x6C, 0x53, 0xF6, 0xE4, 0x72, 0xA8, 0x71, 0x40,
  40039. 0x1E, 0x9A, 0x9A, 0xB7, 0xF9, 0xFB, 0x46, 0x7E,
  40040. 0xB4, 0xEC, 0xB1, 0xF0, 0xDA, 0x7E, 0x63, 0xEE,
  40041. 0x86, 0x19, 0xCB, 0xC4, 0x86, 0xEB, 0xB0, 0xF2,
  40042. 0x12, 0x0A, 0x78, 0x11, 0xBF, 0xB0, 0x55, 0x7D,
  40043. 0x13, 0x93, 0x05, 0x74, 0x29, 0x7C, 0x94, 0x64,
  40044. 0xFC, 0x59, 0x5B, 0x27, 0x56, 0x9A, 0xDF, 0x5F,
  40045. 0x4A, 0x8D, 0xF6, 0x69, 0xC9, 0xEE, 0xA0, 0xA2,
  40046. 0x50, 0xF4, 0xD2, 0x2C, 0x2E, 0x8C, 0x64, 0x1B,
  40047. 0xA3, 0x90, 0x2B, 0xA8, 0x08, 0x00, 0x48, 0x99,
  40048. 0x65, 0xF1, 0x1A, 0xF1, 0xE1, 0xA8, 0x57, 0x17,
  40049. 0xC6, 0x24, 0xE7, 0x42, 0xF1, 0x61, 0x55, 0x08,
  40050. 0x19, 0xD1, 0xF0, 0x37, 0x2C, 0x5C, 0xAE, 0x8B,
  40051. 0xC6, 0x2B, 0x54, 0x9E, 0xFE, 0x87, 0x44, 0x61,
  40052. 0x08, 0x0D, 0x06, 0x34, 0x6E, 0x1F, 0xA6, 0xF0,
  40053. 0x15, 0x14, 0xFB, 0xEC, 0xCB, 0x06, 0xE3, 0x4E,
  40054. 0xE2, 0x71, 0xA0, 0xF0, 0x03, 0x17, 0x90, 0xBD,
  40055. 0xAB, 0xE0, 0xF0, 0x2B, 0xBA, 0x4A, 0xEA, 0x4B,
  40056. 0x73, 0x97, 0xFE, 0x33, 0x33, 0xEB, 0x81, 0x21,
  40057. 0x82, 0x07, 0x57, 0x28, 0x1F, 0x96, 0xA5, 0x83,
  40058. 0x1F, 0x9E, 0x49, 0x03, 0x66, 0x54, 0x9D, 0x16,
  40059. 0x76, 0x3F, 0xF1, 0x9F, 0xF7, 0x73, 0x58, 0x0E,
  40060. 0xD5, 0xE3, 0xE1, 0xE2, 0xAA, 0x3E, 0x38, 0xF8,
  40061. 0x84, 0x74, 0xDE, 0x6D, 0x9B, 0xA6, 0x99, 0x4F,
  40062. 0x8E, 0x62, 0x91, 0x60, 0x48, 0x8C, 0xB4, 0xCD,
  40063. 0x5B, 0x87, 0x8C, 0xDA, 0x37, 0xAA, 0xEC, 0x9B,
  40064. 0x56, 0x36, 0x9A, 0x7E, 0x73, 0xF7, 0x3B, 0x42,
  40065. 0x86, 0x39, 0xA0, 0x5C, 0x13, 0x78, 0x44, 0x8A,
  40066. 0xDB, 0x7F, 0x07, 0x4D, 0xC8, 0x15, 0x4D, 0x92,
  40067. 0xE1, 0x3C, 0x63, 0x56, 0xB5, 0xF4, 0x66, 0xD6,
  40068. 0x64, 0x77, 0x15, 0x9B, 0x2A, 0x94, 0x37, 0x99,
  40069. 0xAD, 0x61, 0x9A, 0x02, 0x9F, 0x30, 0x10, 0xD0,
  40070. 0x37, 0x67, 0x2D, 0xBB, 0x68, 0x20, 0xE5, 0x13,
  40071. 0x23, 0xAD, 0xA9, 0x88, 0x81, 0xC6, 0xDE, 0x85,
  40072. 0x9D, 0xF8, 0x75, 0xAB, 0xAF, 0x11, 0xDA, 0x5D,
  40073. 0xDC, 0xA5, 0xA7, 0x77, 0x62, 0x2B, 0xDA, 0xE8,
  40074. 0xFA, 0xCE, 0x2E, 0x0C, 0xED, 0x3B, 0x6A, 0x77,
  40075. 0xB8, 0x8A, 0x87, 0x29, 0xFB, 0x7C, 0x50, 0x93,
  40076. 0x3D, 0xA6, 0xC5, 0x2E, 0x3F, 0x4D, 0x94, 0x8F,
  40077. 0x9D, 0xC1, 0x53, 0xB5, 0xB1, 0x29, 0x9C, 0xD8,
  40078. 0x62, 0x1D, 0xDF, 0xBA, 0x48, 0xAF, 0x44, 0xE4,
  40079. 0xB6, 0xF6, 0x10, 0x6E, 0xE7, 0x77, 0x95, 0x01,
  40080. 0xDD, 0x5F, 0xB3, 0xC5, 0x78, 0xEA, 0x4D, 0x32,
  40081. 0xC5, 0xC2, 0xF0, 0x36, 0xA7, 0x35, 0x27, 0x03,
  40082. 0xAD, 0xD1, 0x35, 0xAB, 0x84, 0x46, 0x01, 0x62,
  40083. 0x41, 0x7E, 0x50, 0xBF, 0x91, 0xE6, 0x07, 0x97,
  40084. 0xD5, 0x9B, 0x9E, 0x18, 0xD3, 0x24, 0xDA, 0x97,
  40085. 0x1F, 0x4F, 0xF4, 0x28, 0xAE, 0xAF, 0x23, 0xAC,
  40086. 0x0B, 0xA4, 0xE2, 0xE2, 0xFC, 0x7A, 0xBA, 0xA6,
  40087. 0xC8, 0x98, 0x4F, 0xE9, 0xE2, 0xD8, 0x5B, 0x8A,
  40088. 0xDA, 0x40, 0x86, 0xB3, 0xC1, 0x3A, 0xBD, 0x43,
  40089. 0xCF, 0xD1, 0xC7, 0x11, 0xD8, 0x32, 0x6B, 0x18,
  40090. 0xAD, 0xC3, 0x4C, 0xC1, 0x4C, 0xF8, 0x95, 0x7E,
  40091. 0xC3, 0x95, 0x94, 0x98, 0xFC, 0x2A, 0x7B, 0xE0,
  40092. 0x6B, 0xD1, 0x84, 0x0D, 0xE1, 0x70, 0x36, 0x65,
  40093. 0x66, 0xE5, 0x07, 0x41, 0x95, 0x77, 0x63, 0xC2,
  40094. 0xDD, 0x27, 0xAC, 0xF8, 0xC3, 0xF1, 0x02, 0x6F,
  40095. 0xAE, 0xE1, 0xD2, 0x56, 0x2F, 0xA1, 0x05, 0x2E,
  40096. 0x69, 0xAF, 0xDD, 0x42, 0xF4, 0x46, 0xF0, 0x59,
  40097. 0x88, 0x66, 0xD5, 0xD3, 0x06, 0xBF, 0x1B, 0x77,
  40098. 0x50, 0x42, 0xB0, 0x35, 0x92, 0x73, 0x72, 0x82,
  40099. 0x7F, 0x43, 0x86, 0x31, 0x65, 0x34, 0xFA, 0x1B,
  40100. 0x7E, 0xE6, 0x33, 0xBA, 0x95, 0x8C, 0xED, 0x8F,
  40101. 0x0D, 0x24, 0x1D, 0x46, 0x88, 0xE3, 0xC7, 0x91,
  40102. 0x8E, 0x2A, 0x75, 0x62, 0x63, 0x77, 0xC3, 0x42,
  40103. 0xA5, 0x90, 0x69, 0x2B, 0xBF, 0xB8, 0x27, 0xBF,
  40104. 0x90, 0x51, 0x41, 0x82, 0xD4, 0x09, 0x0D, 0xF8,
  40105. 0xD7, 0x32, 0x35, 0x19, 0xA1, 0xAB, 0x6C, 0xD0,
  40106. 0x22, 0x73, 0x67, 0x41, 0x0D, 0xD1, 0x4D, 0x37,
  40107. 0x86, 0xA2, 0x6D, 0xDF, 0x91, 0x72, 0x4F, 0xC8,
  40108. 0x2D, 0x06, 0xA2, 0x5D, 0x5F, 0x56, 0x68, 0x39,
  40109. 0x53, 0xE8, 0xE0, 0xF2, 0x0E, 0x3C, 0x17, 0x71,
  40110. 0xDA, 0xF4, 0x2E, 0x52, 0x02, 0x4C, 0x11, 0x6E,
  40111. 0xD8, 0xA4, 0xC0, 0xA6, 0x11, 0x68, 0x0F, 0x5F,
  40112. 0xE0, 0x0E, 0xD9, 0xB1, 0x48, 0xD1, 0x5F, 0x12,
  40113. 0xAA, 0x95, 0xB9, 0xBD, 0x5A, 0x9F, 0xD8, 0x10,
  40114. 0x16, 0x42, 0xB3, 0x69, 0x11, 0xF3, 0x10, 0xB0,
  40115. 0xDE, 0x18, 0x17, 0x1D, 0x62, 0x37, 0xD9, 0xBE,
  40116. 0x17, 0x25, 0xDC, 0x29, 0x9A, 0x1A, 0x3A, 0xAA,
  40117. 0xE9, 0x85, 0x40, 0xCE, 0xED, 0x26, 0x95, 0x3D,
  40118. 0x10, 0xCE, 0x85, 0x47, 0xF1, 0xC3, 0xE4, 0x6A,
  40119. 0x86, 0x2B, 0xED, 0x42, 0x8D, 0x1E, 0x10, 0x60,
  40120. 0x1B, 0xF3, 0x28, 0xC7, 0x27, 0xFD, 0x95, 0x34,
  40121. 0x3E, 0x2D, 0xB4, 0xD9, 0xAC, 0xD5, 0xD1, 0xCB,
  40122. 0x47, 0x15, 0xF6, 0x00, 0x40, 0x96, 0xED, 0xA0,
  40123. 0x93, 0xD1, 0xB0, 0xA3, 0x3B, 0x1E, 0x56, 0xF1,
  40124. 0x6D, 0x73, 0xAD, 0xB8, 0x73, 0x2C, 0xB4, 0xA3,
  40125. 0x11, 0x60, 0xA4, 0x49, 0x1F, 0xAA, 0x0C, 0x86,
  40126. 0xE6, 0x80, 0xE3, 0xD7, 0xC0, 0x2C, 0xCE, 0xA8,
  40127. 0xFE, 0x92, 0xF1, 0xE0, 0x01, 0x01, 0x6D, 0x22,
  40128. 0x02, 0x21, 0xDD, 0x10, 0xED, 0x62, 0x60, 0x17,
  40129. 0x96, 0x6C, 0x34, 0x50, 0xAD, 0x12, 0x13, 0x65,
  40130. 0x91, 0x8C, 0x93, 0x09, 0x1F, 0x14, 0x71, 0x2B,
  40131. 0xA4, 0x77, 0xCF, 0x2E, 0x26, 0x32, 0x96, 0xC7,
  40132. 0x78, 0xA2, 0xBA, 0xEE, 0xF5, 0x84, 0x94, 0x55,
  40133. 0xFA, 0x35, 0xCB, 0x61, 0x72, 0x51, 0xE0, 0x2A,
  40134. 0x22, 0xDA, 0xF5, 0xC3, 0x3E, 0x5A, 0xAA, 0x9F,
  40135. 0x00, 0xE8, 0xAC, 0xDC, 0x50, 0xEC, 0xF4, 0x7C,
  40136. 0x52, 0x15, 0x03, 0xC5, 0x2F, 0x27, 0xD6, 0xB5,
  40137. 0x7C, 0x8F, 0x2B, 0x3D, 0x8F, 0x12, 0x22, 0x41,
  40138. 0x3E, 0x7F, 0xA4, 0xEC, 0x59, 0x29, 0x63, 0x38,
  40139. 0x09, 0x8C, 0x9A, 0xB5, 0xA1, 0xD8, 0xA5, 0x78,
  40140. 0x84, 0xBD, 0x86, 0x00, 0x41, 0x40, 0x6D, 0x96,
  40141. 0x55, 0xD1, 0x73, 0x82, 0x94, 0x9A, 0x03, 0xD5,
  40142. 0x0F, 0x11, 0x08, 0xD0, 0x5B, 0xDB, 0x31, 0xCA,
  40143. 0x08, 0xE6, 0x6F, 0x2D, 0x8D, 0xE4, 0x80, 0xC6,
  40144. 0x79, 0x35, 0x18, 0xD4, 0x9A, 0x60, 0xD4, 0x76,
  40145. 0x2A, 0x9E, 0xDD, 0xC0, 0x24, 0x9B, 0x42, 0x2E,
  40146. 0x84, 0x02, 0x0E, 0xD5, 0x39, 0xA1, 0x4E, 0x24,
  40147. 0x78, 0xF6, 0x8B, 0xAB, 0x1F, 0x2B, 0x00, 0xE2,
  40148. 0x2A, 0x5C, 0xBB, 0x62, 0x97, 0x9A, 0xC7, 0x44,
  40149. 0xE0, 0x8B, 0x57, 0xD5, 0xB5, 0x78, 0xC4, 0x01,
  40150. 0xA8, 0xD2, 0x6D, 0x9A, 0xDD, 0x15, 0x05, 0x23,
  40151. 0x60, 0x82, 0x86, 0x36, 0x72, 0xD9, 0x11, 0xCF,
  40152. 0x3A, 0x09, 0x66, 0xD3, 0x03, 0xF8, 0x91, 0x70,
  40153. 0x93, 0xBF, 0x97, 0xAF, 0x90, 0xA7, 0xE1, 0xF9,
  40154. 0xD5, 0x9B, 0x09, 0x20, 0x6B, 0x9C, 0xAC, 0x35,
  40155. 0x11, 0x0F, 0xA3, 0x8D, 0x58, 0x90, 0xED, 0x21,
  40156. 0x16, 0x83, 0x5C, 0xE3, 0x73, 0x84, 0xF5, 0x63,
  40157. 0x0F, 0x1C, 0x42, 0x8E, 0x21, 0x36, 0x05, 0x87,
  40158. 0x2E, 0xCF, 0x91, 0x1B, 0x01, 0x4B, 0x91, 0xC2,
  40159. 0xC6, 0x00, 0xE8, 0xA4, 0x07, 0x29, 0xD0, 0x7B,
  40160. 0xF9, 0x18, 0x79, 0x07, 0x42, 0xC9, 0x27, 0x9F,
  40161. 0x31, 0x14, 0xF6, 0x8C, 0xDF, 0x65, 0x94, 0xCD,
  40162. 0xA3, 0xCA, 0x66, 0x94, 0x22, 0x3A, 0x82, 0xF6,
  40163. 0x6C, 0x2B, 0x4B, 0xDF, 0x3E, 0x51, 0xC6, 0xFF,
  40164. 0xDC, 0x55, 0xE0, 0xFF, 0x51, 0xEF, 0xD6, 0xC9,
  40165. 0x34, 0x36, 0x2B, 0xE7, 0xD6, 0xFA, 0xBC, 0x11,
  40166. 0xB8, 0xB0, 0xDA, 0xDD, 0xD5, 0x21, 0x08, 0xFA,
  40167. 0x5F, 0xB5, 0xCA, 0x75, 0x8A, 0x64, 0x37, 0x7D,
  40168. 0x38, 0x6D, 0x45, 0xCE, 0x70, 0x60, 0x5B, 0x46,
  40169. 0x0E, 0x81, 0x57, 0x03, 0x7B, 0x5B, 0x1B, 0x2E,
  40170. 0x0A, 0xED, 0xD1, 0x2A, 0x63, 0x31, 0x15, 0xD6,
  40171. 0xC4, 0x3B, 0xC6, 0xC7, 0xC8, 0x36, 0xFF, 0xF3,
  40172. 0x3E, 0x7D, 0x03, 0x3F, 0x2E, 0x58, 0x00, 0x52,
  40173. 0x71, 0x64, 0xC0, 0xC4, 0x78, 0x1C, 0x37, 0xDF,
  40174. 0x50, 0xB6, 0x6B, 0xBA, 0x5C, 0x81, 0x94, 0x73,
  40175. 0xA1, 0xC5, 0x30, 0x20, 0x83, 0xA1, 0x6F, 0x01,
  40176. 0x43, 0x72, 0x79, 0xD2, 0xF2, 0xDF, 0x14, 0xC8,
  40177. 0x78, 0x26, 0x9A, 0x2F, 0x3F, 0xA4, 0x0C, 0x1C,
  40178. 0x76, 0x1E, 0xD6, 0x15, 0x01, 0xAC, 0x9E, 0xF1,
  40179. 0x41, 0x02, 0x90, 0x38, 0xC8, 0x19, 0x95, 0x40,
  40180. 0x89, 0xB7, 0x38, 0x09, 0x87, 0x08, 0x17, 0x43,
  40181. 0x93, 0xFE, 0xAE, 0xA7, 0xB0, 0x2A, 0xE5, 0xCE,
  40182. 0xF6, 0x7B, 0x3C, 0x8C, 0xE6, 0xA9, 0x70, 0x67,
  40183. 0x5C, 0xA1, 0xB8, 0xC8, 0x56, 0xDC, 0xF5, 0x97,
  40184. 0x25, 0x08, 0xC7, 0xC6, 0xB2, 0x5E, 0xE4, 0xD1,
  40185. 0x2D, 0x82, 0x12, 0xB9, 0x89, 0x40, 0xB4, 0x88,
  40186. 0xEC, 0x40, 0x2A, 0xC7, 0xAE, 0x3C, 0x70, 0xDF,
  40187. 0x93, 0x8D, 0x12, 0x88, 0xCD, 0xA7, 0xA3, 0x19,
  40188. 0xE0, 0x85, 0xBC, 0x73, 0xA4, 0x69, 0xB2, 0xD2,
  40189. 0xA3, 0x30, 0x3B, 0x11, 0xA6, 0x83, 0x10, 0x0A,
  40190. 0xF6, 0xDB, 0x86, 0x93, 0x7B, 0xA1, 0x18, 0x29,
  40191. 0x03, 0x61, 0x6E, 0x3F, 0x03, 0x47, 0xBD, 0x68,
  40192. 0x59, 0x1B, 0x47, 0xBA, 0x65, 0x15, 0x6B, 0x93,
  40193. 0xF2, 0x60, 0xDE, 0x59, 0xB3, 0xAE, 0xB2, 0x89,
  40194. 0xE2, 0xA7, 0x3A, 0x3B, 0xFF, 0x38, 0xC2, 0xF3,
  40195. 0xAD, 0xED, 0xA2, 0x9C, 0x7E, 0x90, 0x28, 0x3A,
  40196. 0xC7, 0xB8, 0x6D, 0x03, 0x6B, 0x47, 0xD5, 0xBA,
  40197. 0x1A, 0x03, 0xEC, 0x78, 0x3D, 0x25, 0x0B, 0xAC,
  40198. 0xAE, 0x58, 0x47, 0xE4, 0x1F, 0x82, 0x9C, 0xB3,
  40199. 0x3D, 0xE0, 0x8D, 0xF8, 0xF7, 0xD6, 0x9C, 0x9A,
  40200. 0xA4, 0xED, 0xE8, 0xD7, 0xAB, 0x96, 0x84, 0x07,
  40201. 0xEE, 0xD3, 0x1A, 0x05, 0x6B, 0xA0, 0xEF, 0x88,
  40202. 0x16, 0xE1, 0x27, 0xAA, 0x90, 0x06, 0x5A, 0x67,
  40203. 0x9E, 0x1C, 0xA9, 0x55, 0x0D, 0xEE, 0xF2, 0x5A,
  40204. 0xC5, 0xB7, 0xA3, 0x4F, 0x70, 0xDC, 0xF2, 0xB1,
  40205. 0x16, 0xCF, 0x35, 0x1F, 0x3B, 0xAD, 0xA9, 0x9F,
  40206. 0x83, 0x6C, 0x73, 0x0D, 0xCC, 0x1A, 0xE0, 0x3F,
  40207. 0x49, 0x6C, 0xF3, 0xF0, 0x38, 0x7A, 0x0C, 0x2C,
  40208. 0x70, 0x2E, 0x2C, 0x13, 0xBD, 0xD9, 0xCF, 0x45,
  40209. 0xA1, 0xCD, 0x53, 0xAB, 0x58, 0x73, 0x11, 0x88,
  40210. 0xB1, 0x8E, 0xA8, 0xBE, 0x48, 0xD5, 0x10, 0xC5,
  40211. 0x81, 0x2E, 0x90, 0xBC, 0xEC, 0xBC, 0x6E, 0x19,
  40212. 0x8E, 0x70, 0x8B, 0x1C, 0x08, 0xC8, 0xF8, 0x64,
  40213. 0xB1, 0x24, 0xBB, 0x4C, 0xC0, 0xBD, 0xBB, 0xDF,
  40214. 0x2C, 0x2F, 0x4E, 0x38, 0x8F, 0xC1, 0x96, 0x60,
  40215. 0xD6, 0x9C, 0xC2, 0xC0, 0xEB, 0xF9, 0x10, 0x08,
  40216. 0xC8, 0x24, 0x3D, 0xB4, 0x2D, 0xDA, 0xF5, 0x7C,
  40217. 0x02, 0x42, 0x51, 0xC4, 0x23, 0x1D, 0xF5, 0x37,
  40218. 0x90, 0xCE, 0x57, 0x56, 0x13, 0xEE, 0x8E, 0x1C,
  40219. 0x7A, 0x33, 0xC1, 0x56, 0x1F, 0x35, 0x04, 0xDE,
  40220. 0xAA, 0xED, 0x1E, 0x84, 0x08, 0x50, 0x06, 0x23,
  40221. 0xEC, 0xA5, 0xAE, 0x5A, 0x28, 0x45, 0x41, 0x17,
  40222. 0x49, 0x93, 0x0D, 0x8E, 0x42, 0x07, 0x8C, 0x03,
  40223. 0x23, 0x49, 0x95, 0x7F, 0xC3, 0x9A, 0x1D, 0xA0,
  40224. 0xEA, 0xF9, 0xE8, 0x7C, 0x31, 0xFF, 0xBF, 0x6A,
  40225. 0xC0, 0xC1, 0x81, 0x1E, 0xB2, 0x8A, 0x41, 0xB1,
  40226. 0xD8, 0x6B, 0xD7, 0xD4, 0x9A, 0xD1, 0xC4, 0x68,
  40227. 0xA4, 0x95, 0x94, 0x95, 0x65, 0x25, 0xA2, 0x0A,
  40228. 0x31, 0x70, 0x0F, 0x12, 0x2F, 0x4C, 0x4B, 0xB2,
  40229. 0x25, 0x2A, 0x2F, 0x3D, 0x5C, 0x5D, 0x68, 0x73,
  40230. 0x83, 0x8C, 0x90, 0x95, 0x97, 0xBB, 0xCA, 0xD8,
  40231. 0xE1, 0x33, 0x3D, 0x5D, 0x61, 0x7C, 0x87, 0xC8,
  40232. 0xEE, 0x0F, 0x1B, 0x22, 0x38, 0x3B, 0x42, 0x4B,
  40233. 0x4C, 0x5C, 0x62, 0x72, 0x98, 0xA3, 0xBE, 0xCC,
  40234. 0x1B, 0x32, 0x47, 0x5C, 0x9D, 0xB6, 0xB9, 0xBD,
  40235. 0xC6, 0xD6, 0xDC, 0xF5, 0x00, 0x00, 0x00, 0x00,
  40236. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  40237. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  40238. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  40239. 0x11, 0x19, 0x28, 0x34
  40240. };
  40241. #endif
  40242. #ifndef WOLFSSL_NO_ML_DSA_65
  40243. static const byte pk_65[] = {
  40244. 0x6C, 0x9E, 0x7A, 0x1E, 0xE3, 0x66, 0x25, 0x76,
  40245. 0x0E, 0x5D, 0x2F, 0x33, 0xDF, 0x29, 0x29, 0xDA,
  40246. 0x56, 0x20, 0x32, 0x34, 0x06, 0x91, 0x60, 0xE5,
  40247. 0xF2, 0xBF, 0x03, 0x9C, 0x11, 0x06, 0x22, 0x73,
  40248. 0x07, 0x3C, 0x23, 0x75, 0x66, 0xCE, 0x05, 0x5D,
  40249. 0x87, 0x1F, 0x38, 0xAC, 0xD1, 0xA9, 0x85, 0x9A,
  40250. 0x82, 0x44, 0x67, 0xF1, 0x9B, 0xE6, 0x8E, 0x4F,
  40251. 0x00, 0x64, 0x5D, 0x22, 0x5C, 0x42, 0xC8, 0x5A,
  40252. 0x55, 0x7D, 0x2C, 0x5E, 0xCB, 0x44, 0x2B, 0x0F,
  40253. 0x02, 0x8A, 0x65, 0x28, 0x89, 0x8E, 0xE2, 0xB6,
  40254. 0x73, 0xD8, 0x63, 0xF3, 0x2E, 0xB9, 0xEC, 0x81,
  40255. 0x64, 0x12, 0x75, 0x41, 0xF3, 0x25, 0x19, 0xBB,
  40256. 0x88, 0xE0, 0x34, 0xA0, 0x3F, 0x46, 0xF7, 0xD1,
  40257. 0x93, 0xCD, 0x3D, 0xFB, 0xAD, 0xF6, 0x35, 0x57,
  40258. 0x92, 0x6C, 0x5C, 0x8F, 0x5B, 0x76, 0x6A, 0x7F,
  40259. 0xC5, 0xEC, 0x8B, 0x3F, 0x94, 0x8B, 0xF7, 0xA8,
  40260. 0x21, 0xB5, 0x4C, 0x94, 0x41, 0xAB, 0x0B, 0xD8,
  40261. 0x33, 0xFD, 0x63, 0x54, 0xCE, 0xC7, 0x06, 0xFA,
  40262. 0xA5, 0x00, 0xAB, 0xB5, 0x28, 0x9B, 0x90, 0xB1,
  40263. 0xBF, 0x91, 0x76, 0x77, 0xA2, 0x9D, 0x11, 0x5F,
  40264. 0x00, 0x94, 0xBD, 0xB4, 0x8D, 0xC7, 0x2E, 0x26,
  40265. 0x1D, 0xBA, 0x12, 0x0B, 0xA6, 0xFF, 0x5E, 0x52,
  40266. 0xA0, 0x1B, 0x17, 0x89, 0x81, 0xDD, 0x82, 0x96,
  40267. 0x44, 0x46, 0x56, 0xD9, 0x44, 0x2D, 0xF9, 0xCB,
  40268. 0xB6, 0xBF, 0xDA, 0xE5, 0x6A, 0x23, 0x0F, 0x6F,
  40269. 0x29, 0xF9, 0x4C, 0xDC, 0xC2, 0x65, 0x57, 0x6A,
  40270. 0xA8, 0x75, 0x2A, 0xCE, 0xD0, 0x7E, 0x99, 0x89,
  40271. 0x5C, 0xAE, 0xF0, 0x16, 0x8B, 0xF8, 0x3D, 0x23,
  40272. 0xFD, 0xAD, 0xFB, 0xB9, 0x28, 0xCB, 0xCD, 0xAB,
  40273. 0xA2, 0x5F, 0xE2, 0xCD, 0x26, 0xAD, 0xDF, 0xB0,
  40274. 0xDA, 0xCD, 0x74, 0x94, 0x0F, 0x35, 0x14, 0x26,
  40275. 0x94, 0x2F, 0x17, 0x6F, 0xFB, 0xC5, 0xF3, 0x45,
  40276. 0x6D, 0xB7, 0xC9, 0x12, 0xAA, 0x16, 0xB8, 0x6D,
  40277. 0x07, 0x45, 0xF8, 0x7C, 0x9F, 0x45, 0x37, 0x0A,
  40278. 0x84, 0x56, 0xA1, 0xAD, 0xB5, 0x1D, 0xB4, 0x05,
  40279. 0x2B, 0x5C, 0x9E, 0xAF, 0x60, 0xAD, 0x7B, 0x80,
  40280. 0xA4, 0x2E, 0xA4, 0xBF, 0x92, 0xC8, 0x41, 0x27,
  40281. 0x3A, 0xD7, 0x61, 0xDE, 0xDB, 0x0D, 0x34, 0xBF,
  40282. 0x57, 0x96, 0x00, 0xB1, 0x49, 0xFC, 0xCD, 0x42,
  40283. 0xAB, 0x15, 0x49, 0xBA, 0x0A, 0xBE, 0xDA, 0x57,
  40284. 0xEF, 0x71, 0xD1, 0xFC, 0xA5, 0x70, 0x2A, 0xAD,
  40285. 0x08, 0x32, 0x99, 0xBB, 0x98, 0x30, 0x01, 0x89,
  40286. 0xC2, 0x5F, 0x3B, 0x27, 0x0A, 0x87, 0x65, 0x8D,
  40287. 0x0B, 0x2E, 0xA5, 0x65, 0x24, 0x14, 0x7F, 0x73,
  40288. 0x9E, 0xB6, 0xC6, 0x76, 0xD7, 0xBE, 0x73, 0xDD,
  40289. 0x3B, 0x95, 0xB1, 0x0C, 0x55, 0xAB, 0x46, 0xFD,
  40290. 0x01, 0x54, 0x9C, 0x51, 0x68, 0xBF, 0x7D, 0xA1,
  40291. 0x3A, 0x49, 0x97, 0x85, 0xF3, 0x5A, 0x1E, 0x3B,
  40292. 0x56, 0xF4, 0xC5, 0x67, 0xF5, 0x4E, 0xA9, 0xAA,
  40293. 0x28, 0x17, 0xA3, 0x36, 0x38, 0x36, 0x43, 0xFA,
  40294. 0x2E, 0xA3, 0x1F, 0xB1, 0xB7, 0x3E, 0x10, 0x24,
  40295. 0x8D, 0xFC, 0xA0, 0x5C, 0x04, 0x13, 0x12, 0x66,
  40296. 0x49, 0x8E, 0x1C, 0x94, 0x91, 0x13, 0x5A, 0x50,
  40297. 0xE6, 0x3D, 0x02, 0xFA, 0xDF, 0x41, 0x65, 0xFC,
  40298. 0x9E, 0x15, 0xE3, 0xE1, 0xB3, 0x2F, 0xAB, 0x83,
  40299. 0x37, 0x68, 0x4C, 0x49, 0x19, 0x3E, 0x1B, 0xC4,
  40300. 0xED, 0xEA, 0xE3, 0x73, 0xA2, 0x67, 0xA7, 0x14,
  40301. 0xAC, 0x1F, 0x90, 0x9C, 0xC6, 0x57, 0xCD, 0x80,
  40302. 0x66, 0x64, 0x63, 0x27, 0xE0, 0xEE, 0xA0, 0x41,
  40303. 0xAC, 0x9F, 0x2A, 0xEF, 0xFC, 0x80, 0x69, 0x1B,
  40304. 0xF6, 0x0D, 0x3C, 0x94, 0xC6, 0x42, 0x55, 0x7E,
  40305. 0x42, 0x99, 0xD3, 0x95, 0x92, 0x22, 0x16, 0xC6,
  40306. 0x5E, 0x75, 0xB7, 0xE1, 0xA5, 0x02, 0x89, 0x60,
  40307. 0x38, 0x4B, 0xF8, 0x16, 0xC9, 0xF7, 0x05, 0x48,
  40308. 0x29, 0xE7, 0x98, 0x5B, 0x58, 0x41, 0xA7, 0x33,
  40309. 0xF3, 0x3F, 0xCE, 0x24, 0x55, 0xEF, 0xC8, 0x9B,
  40310. 0xAE, 0x84, 0xB4, 0x79, 0x90, 0xE8, 0xD0, 0xAF,
  40311. 0xC6, 0x19, 0x3E, 0x4A, 0xF9, 0xBC, 0x68, 0x0A,
  40312. 0xE2, 0x4F, 0xE5, 0x91, 0xE8, 0x8B, 0xA6, 0xA2,
  40313. 0xAE, 0x12, 0xDA, 0x38, 0x58, 0xD2, 0x1F, 0x49,
  40314. 0x2D, 0x24, 0xAB, 0xC4, 0xFE, 0x4F, 0xD5, 0x2D,
  40315. 0x5A, 0xBF, 0x24, 0xBD, 0x25, 0x46, 0x87, 0xB9,
  40316. 0x18, 0x79, 0x2F, 0x0A, 0x00, 0x3A, 0x52, 0x22,
  40317. 0xDF, 0x45, 0x03, 0x86, 0x85, 0xC7, 0x25, 0xCE,
  40318. 0x75, 0x79, 0xE0, 0x2C, 0xB1, 0x68, 0xBB, 0xC6,
  40319. 0x66, 0xAB, 0xF6, 0x69, 0x85, 0x6E, 0x10, 0x53,
  40320. 0x7C, 0x92, 0x91, 0x69, 0x2C, 0x0C, 0xB0, 0xCF,
  40321. 0xA9, 0x06, 0x27, 0x0A, 0xC2, 0xC7, 0xB7, 0xDC,
  40322. 0x31, 0xD4, 0xF9, 0x28, 0x3C, 0xB2, 0xDB, 0x8A,
  40323. 0x46, 0x2A, 0xEC, 0x0B, 0x98, 0x07, 0xBB, 0xF4,
  40324. 0xAB, 0x45, 0x76, 0xFE, 0xC6, 0x22, 0x6B, 0x41,
  40325. 0x79, 0x32, 0x2B, 0x67, 0xAE, 0xA5, 0x3B, 0xDD,
  40326. 0xF9, 0xC9, 0xBE, 0x5E, 0x0D, 0xBC, 0x43, 0xF7,
  40327. 0x87, 0x43, 0x06, 0x8A, 0xB5, 0xBE, 0x49, 0xF0,
  40328. 0xE6, 0x2F, 0x8E, 0x2E, 0xB1, 0xB6, 0xC6, 0x73,
  40329. 0x6C, 0x05, 0xC9, 0x41, 0x3D, 0x06, 0x5C, 0xE0,
  40330. 0xCC, 0xB7, 0x90, 0x54, 0x80, 0x41, 0xD7, 0xE8,
  40331. 0x32, 0x88, 0x1A, 0x83, 0x9B, 0x57, 0x29, 0xAF,
  40332. 0x94, 0xAB, 0x79, 0xFD, 0x8A, 0x16, 0xDF, 0xFF,
  40333. 0x78, 0xCA, 0xAA, 0x14, 0x1D, 0x97, 0xCC, 0x06,
  40334. 0x50, 0xF8, 0x62, 0x62, 0xF2, 0x61, 0x59, 0xBE,
  40335. 0x8B, 0x36, 0x1A, 0x4A, 0x04, 0x1E, 0x9A, 0x0B,
  40336. 0x65, 0x11, 0xBB, 0xE3, 0x35, 0x5A, 0x4B, 0xF5,
  40337. 0x7A, 0xC0, 0x98, 0x48, 0x84, 0x7E, 0xE0, 0x24,
  40338. 0x3C, 0x3B, 0xA7, 0x74, 0x77, 0x6F, 0x7E, 0x9A,
  40339. 0x22, 0x72, 0x75, 0xD7, 0x4E, 0x6E, 0x31, 0x01,
  40340. 0xD3, 0x82, 0x81, 0x87, 0x63, 0xED, 0x1E, 0x13,
  40341. 0x53, 0xAB, 0x9E, 0xEC, 0xCD, 0x92, 0x0C, 0xD2,
  40342. 0x89, 0x22, 0xD5, 0x59, 0xA4, 0x04, 0x8F, 0x40,
  40343. 0xF0, 0x62, 0x16, 0x4C, 0xB6, 0x61, 0xC4, 0xF4,
  40344. 0xAF, 0xA8, 0x1A, 0x3D, 0x55, 0x93, 0x3C, 0x47,
  40345. 0x91, 0xED, 0xDA, 0xA3, 0x93, 0x9E, 0x5A, 0xC3,
  40346. 0x42, 0xB0, 0xAD, 0x1F, 0x43, 0x8A, 0x53, 0x2C,
  40347. 0x6C, 0xE7, 0x86, 0x68, 0x1A, 0x87, 0x0D, 0x94,
  40348. 0xEC, 0x88, 0xA3, 0x34, 0xCC, 0xEF, 0xC6, 0xAC,
  40349. 0xE7, 0xD9, 0x88, 0xA1, 0xA8, 0x2B, 0xC0, 0xAC,
  40350. 0xCE, 0x78, 0x5F, 0x12, 0x3B, 0xE2, 0x3A, 0x7C,
  40351. 0x92, 0xAF, 0x10, 0x8E, 0x5E, 0xD4, 0xF0, 0x86,
  40352. 0x9E, 0x22, 0xDA, 0xE2, 0x73, 0x55, 0x6D, 0x1D,
  40353. 0xE3, 0x86, 0x62, 0x3A, 0x6C, 0x3F, 0x11, 0x5B,
  40354. 0xBD, 0x11, 0x92, 0x71, 0xD3, 0xFB, 0xA7, 0x96,
  40355. 0xF6, 0x18, 0xB5, 0x39, 0x59, 0xFB, 0x98, 0x01,
  40356. 0x2E, 0x7D, 0x5B, 0x9A, 0xC6, 0x88, 0x94, 0x0B,
  40357. 0x87, 0xE2, 0xC9, 0xC0, 0x65, 0x52, 0x4A, 0x00,
  40358. 0xD3, 0xA4, 0xF4, 0xDB, 0xF5, 0x2F, 0x4B, 0x1A,
  40359. 0x63, 0xEF, 0x5C, 0x46, 0x19, 0x3B, 0xAD, 0xF7,
  40360. 0xAD, 0x7F, 0x98, 0x8D, 0x44, 0x64, 0x34, 0x5B,
  40361. 0x2C, 0x3E, 0x54, 0x96, 0x84, 0xF2, 0xF9, 0x05,
  40362. 0xF6, 0xF8, 0x9D, 0xD6, 0x41, 0x47, 0x3E, 0xC0,
  40363. 0x51, 0x08, 0xA5, 0x2D, 0x8D, 0xBB, 0x91, 0x76,
  40364. 0x8C, 0x54, 0x1D, 0xE5, 0x20, 0xB1, 0x76, 0x66,
  40365. 0x97, 0x0A, 0xAE, 0xB5, 0x06, 0xE7, 0x5D, 0x8E,
  40366. 0xE9, 0xF4, 0xB4, 0x45, 0x5B, 0x71, 0xE0, 0x08,
  40367. 0x8A, 0xB2, 0x56, 0x55, 0x21, 0x3B, 0x75, 0x85,
  40368. 0x9D, 0x25, 0xF5, 0x59, 0xD3, 0xC3, 0x24, 0xD2,
  40369. 0x83, 0xD3, 0x97, 0xAB, 0xE6, 0xF0, 0xAA, 0xA3,
  40370. 0x86, 0x81, 0x57, 0x68, 0xD0, 0x33, 0x57, 0xD7,
  40371. 0x75, 0x96, 0x49, 0x02, 0x41, 0x31, 0x53, 0xE3,
  40372. 0x56, 0x0C, 0xCE, 0xF1, 0xFD, 0x44, 0xB6, 0x5F,
  40373. 0xF1, 0xB2, 0x87, 0xA9, 0x2A, 0x96, 0x93, 0xF0,
  40374. 0x34, 0xB7, 0xEE, 0x66, 0x89, 0x34, 0x70, 0x2D,
  40375. 0x75, 0x01, 0xCA, 0xF6, 0xDA, 0x4E, 0xE9, 0x8A,
  40376. 0xF4, 0xE8, 0xE6, 0x4B, 0x03, 0x40, 0xE0, 0xBB,
  40377. 0x8B, 0xDC, 0x53, 0x3B, 0x0E, 0xFE, 0xE1, 0x91,
  40378. 0x5A, 0x4B, 0x68, 0xB9, 0x3C, 0x5E, 0x95, 0x32,
  40379. 0x1E, 0xED, 0xC2, 0x34, 0xAE, 0xFE, 0x71, 0xAE,
  40380. 0x2E, 0x5D, 0xAC, 0xEC, 0x2F, 0x52, 0xF8, 0x37,
  40381. 0x23, 0xA2, 0x39, 0x2A, 0x7F, 0x8E, 0x13, 0xBC,
  40382. 0x03, 0x01, 0xCD, 0x10, 0x4D, 0x85, 0x2E, 0x62,
  40383. 0xA7, 0xF8, 0x28, 0xAD, 0x32, 0x9B, 0x3D, 0x95,
  40384. 0x96, 0xC5, 0x8E, 0x13, 0xFC, 0xC0, 0xED, 0x96,
  40385. 0xC1, 0xC4, 0x8D, 0x82, 0xA2, 0xC0, 0xF4, 0xD9,
  40386. 0xD2, 0x4D, 0xD8, 0x42, 0x1F, 0xDC, 0xCE, 0xFD,
  40387. 0x49, 0x7A, 0x9B, 0x05, 0xFF, 0xC5, 0x09, 0x04,
  40388. 0x77, 0x04, 0x01, 0x37, 0x3F, 0xEE, 0x7D, 0xC7,
  40389. 0x37, 0x73, 0x41, 0x8A, 0xEB, 0x4A, 0x1F, 0x59,
  40390. 0x9A, 0x4B, 0xB3, 0x8E, 0xDE, 0x8D, 0x10, 0xA3,
  40391. 0xCC, 0x83, 0xA1, 0xC7, 0x2D, 0xE9, 0x21, 0x96,
  40392. 0x9E, 0x3C, 0xE3, 0xE8, 0xEF, 0x2F, 0x7D, 0xA8,
  40393. 0x9D, 0x34, 0x4C, 0x80, 0xD6, 0x1C, 0xF9, 0xC5,
  40394. 0xA4, 0x23, 0xB1, 0xA4, 0xF3, 0x56, 0x7D, 0x96,
  40395. 0xDB, 0x2D, 0xA3, 0xDB, 0x9B, 0x5B, 0x5F, 0xA6,
  40396. 0x81, 0x56, 0xBE, 0x74, 0x52, 0xC8, 0xA0, 0x18,
  40397. 0x1B, 0xB9, 0xF0, 0xDC, 0x75, 0xCD, 0x97, 0x50,
  40398. 0x88, 0x3D, 0x0D, 0xDA, 0xE5, 0x3F, 0xC1, 0x56,
  40399. 0xD6, 0x7A, 0x74, 0x20, 0x08, 0x69, 0x04, 0x6B,
  40400. 0x41, 0xDF, 0x4B, 0xC4, 0x39, 0x69, 0x93, 0xC0,
  40401. 0x8A, 0xA4, 0x89, 0x7A, 0x0B, 0xDD, 0xEF, 0xB5,
  40402. 0x5F, 0x69, 0xCC, 0x1C, 0x4D, 0x7B, 0x5F, 0xB1,
  40403. 0x50, 0x40, 0x84, 0x27, 0xB4, 0x16, 0xF7, 0x31,
  40404. 0x83, 0xF2, 0xB3, 0xCC, 0x16, 0xE3, 0xB7, 0xDA,
  40405. 0x63, 0xCE, 0xE1, 0x14, 0x3A, 0xDA, 0x1A, 0x05,
  40406. 0x66, 0x26, 0xA0, 0x77, 0xB6, 0xD2, 0x1C, 0x3D,
  40407. 0xD9, 0x74, 0xED, 0x90, 0x7C, 0x5A, 0x09, 0x40,
  40408. 0x19, 0x22, 0x57, 0x37, 0xEF, 0xB9, 0x33, 0x19,
  40409. 0xAD, 0x3B, 0x40, 0xA4, 0xF4, 0x34, 0xAE, 0x49,
  40410. 0xD2, 0x83, 0x91, 0xC1, 0x7A, 0x99, 0x9C, 0x74,
  40411. 0x4A, 0x68, 0xC5, 0x5A, 0x91, 0xB8, 0x62, 0x72,
  40412. 0x95, 0x83, 0xD3, 0xDA, 0x46, 0xEE, 0x70, 0xC5,
  40413. 0xCC, 0x46, 0x16, 0x94, 0x16, 0x7D, 0x32, 0xD2,
  40414. 0x1D, 0xE7, 0x53, 0x27, 0x73, 0x2C, 0x63, 0xBB,
  40415. 0xFB, 0xD7, 0xB3, 0x0D, 0xBF, 0x20, 0x57, 0xA0,
  40416. 0xD6, 0x81, 0x51, 0x9F, 0x6E, 0x4A, 0xF6, 0x08,
  40417. 0xD4, 0xBC, 0xD0, 0xB4, 0x75, 0x07, 0x26, 0x77,
  40418. 0x0E, 0x15, 0x6A, 0xED, 0xE8, 0x54, 0x17, 0xBD,
  40419. 0x75, 0x9D, 0x5F, 0xFE, 0x40, 0x1C, 0xB2, 0x99,
  40420. 0x6F, 0x34, 0x43, 0x4D, 0xB4, 0x28, 0xD9, 0xA4,
  40421. 0x17, 0x03, 0x72, 0x01, 0xFC, 0xD2, 0x60, 0xFA,
  40422. 0xA9, 0x80, 0x84, 0x50, 0x2E, 0xED, 0x5C, 0x27,
  40423. 0xA8, 0x91, 0x6E, 0x44, 0xF5, 0x92, 0x98, 0x19,
  40424. 0xD2, 0x1A, 0x69, 0xCE, 0x16, 0xBC, 0xDC, 0x3C,
  40425. 0xC8, 0x14, 0x1E, 0x28, 0x5E, 0xF8, 0x97, 0xB1,
  40426. 0x40, 0x2C, 0x15, 0xC9, 0x52, 0x59, 0x01, 0x19,
  40427. 0x05, 0x1E, 0x36, 0x9A, 0x1B, 0x7B, 0xE4, 0x43,
  40428. 0xFE, 0xAE, 0x6E, 0x32, 0xBC, 0x8F, 0x3D, 0x64,
  40429. 0x7F, 0xC5, 0x31, 0x5A, 0x52, 0x00, 0xCD, 0x52,
  40430. 0x38, 0xDC, 0x66, 0x77, 0x46, 0x6E, 0xA8, 0x6E,
  40431. 0xF8, 0xD1, 0x8E, 0x5A, 0x79, 0xF2, 0x62, 0x48,
  40432. 0x3E, 0x89, 0x6B, 0x82, 0x77, 0xC7, 0x41, 0xF5,
  40433. 0x16, 0xFC, 0x04, 0x0C, 0x10, 0x90, 0xF2, 0x49,
  40434. 0x5B, 0xF1, 0x65, 0x0B, 0x02, 0xAF, 0x30, 0x45,
  40435. 0x67, 0x33, 0xA0, 0x71, 0xAF, 0x47, 0xD7, 0xA1,
  40436. 0x5B, 0xD8, 0xE3, 0x2A, 0x49, 0x80, 0x64, 0x55,
  40437. 0xD3, 0xBE, 0xA7, 0x4A, 0xEF, 0x5D, 0x00, 0x90,
  40438. 0x6A, 0xD2, 0xF0, 0xC0, 0x45, 0x35, 0x4E, 0xFD,
  40439. 0xE7, 0xC9, 0xA2, 0x76, 0xE7, 0x3D, 0x9E, 0xDD,
  40440. 0x11, 0xD1, 0xCA, 0x5C, 0x29, 0x7B, 0x9A, 0x68,
  40441. 0x51, 0xE7, 0xF6, 0x7E, 0x21, 0xEB, 0x06, 0x1B,
  40442. 0xB5, 0x5D, 0x9E, 0x67, 0x3C, 0x4A, 0x75, 0xFE,
  40443. 0xB8, 0x4D, 0x52, 0x62, 0x9E, 0xEC, 0xC5, 0x3C,
  40444. 0x24, 0xBE, 0xA9, 0x51, 0x53, 0x05, 0x1A, 0xC2,
  40445. 0x06, 0xC8, 0x7D, 0xF5, 0x54, 0x10, 0xCA, 0x1F,
  40446. 0xE6, 0xCF, 0xC3, 0xF4, 0x03, 0xA6, 0xD9, 0xD4,
  40447. 0x3E, 0xA8, 0x4C, 0x60, 0xC9, 0x45, 0xE6, 0x42,
  40448. 0xB2, 0x83, 0x63, 0x38, 0xB5, 0xAF, 0x9F, 0x69,
  40449. 0xE5, 0x27, 0x08, 0xB2, 0xE2, 0x25, 0x93, 0x3D,
  40450. 0xB3, 0x20, 0xBB, 0x3F, 0x79, 0x0D, 0x39, 0x7F,
  40451. 0x22, 0xD7, 0xB6, 0xF8, 0xA4, 0x33, 0xCD, 0xAC,
  40452. 0xE9, 0x81, 0x0A, 0xA0, 0xE2, 0x7C, 0x69, 0x95,
  40453. 0x55, 0x53, 0x0C, 0x56, 0x2D, 0xBF, 0x75, 0x17,
  40454. 0xA4, 0x16, 0x26, 0x28, 0xBF, 0x10, 0xD1, 0xB6,
  40455. 0xDB, 0xAC, 0xEF, 0x5C, 0x9E, 0xD5, 0x1E, 0x55,
  40456. 0xD9, 0xA8, 0x9D, 0x60, 0xE0, 0xFC, 0x37, 0x8C,
  40457. 0x47, 0xA2, 0x1D, 0x5E, 0x0F, 0x2D, 0xC3, 0xBC,
  40458. 0xEF, 0x5E, 0x05, 0xC6, 0xE0, 0x26, 0x15, 0x30,
  40459. 0xFB, 0x02, 0x7E, 0x50, 0x32, 0x55, 0x8C, 0xA2,
  40460. 0xB4, 0x70, 0x05, 0xBD, 0xDE, 0x99, 0x90, 0x99,
  40461. 0x30, 0x39, 0x1E, 0xAD, 0x7F, 0x3F, 0x0A, 0x96,
  40462. 0xB3, 0xDE, 0xDA, 0x54, 0xA1, 0x11, 0x45, 0xF5,
  40463. 0x30, 0xE5, 0x1D, 0xEF, 0x89, 0x2E, 0x5A, 0xB0,
  40464. 0x20, 0x4D, 0x61, 0x4E, 0x6E, 0x38, 0xAF, 0xE7,
  40465. 0x9C, 0xA9, 0x2C, 0x28, 0x15, 0x8D, 0x57, 0x01,
  40466. 0x20, 0x35, 0x3B, 0x7A, 0x4D, 0xE0, 0x88, 0x98,
  40467. 0x46, 0xD8, 0x35, 0x29, 0x49, 0x39, 0x55, 0x7E,
  40468. 0xD0, 0xAE, 0xDA, 0x27, 0x0D, 0x4D, 0x73, 0xED,
  40469. 0x84, 0xD3, 0xD4, 0x9F, 0x9F, 0x03, 0x2D, 0x43,
  40470. 0x45, 0x7B, 0xF5, 0x9B, 0xB7, 0xD6, 0x63, 0x59,
  40471. 0xDC, 0x53, 0xF9, 0xB4, 0x69, 0x63, 0xB2, 0x17,
  40472. 0x84, 0xB0, 0x6C, 0xBC, 0xF0, 0x4B, 0xEC, 0x1E,
  40473. 0x33, 0xA3, 0x33, 0x71, 0x53, 0x27, 0x16, 0xC9,
  40474. 0xED, 0xB3, 0xFB, 0xED, 0xB8, 0x19, 0x99, 0xB4,
  40475. 0x37, 0x2D, 0x09, 0x45, 0xC1, 0x0A, 0xE8, 0x26,
  40476. 0xC6, 0x0F, 0xFE, 0x93, 0x17, 0x0B, 0x6D, 0x29,
  40477. 0x4B, 0x38, 0x91, 0xB0, 0xD2, 0xA7, 0xB3, 0x5B,
  40478. 0x28, 0xA8, 0x97, 0x18, 0x45, 0xDC, 0x2F, 0xEC,
  40479. 0xE2, 0x37, 0xB8, 0x0F, 0x20, 0xB3, 0x79, 0xCC,
  40480. 0x4D, 0x13, 0x6D, 0xAB, 0x3F, 0xBB, 0x37, 0x92,
  40481. 0xC6, 0x3E, 0xC6, 0x1F, 0x5C, 0x75, 0x5B, 0xC9,
  40482. 0xDB, 0x35, 0x08, 0x6F, 0xBF, 0x46, 0xD2, 0xB7,
  40483. 0x97, 0x0D, 0xCA, 0x2A, 0x85, 0x23, 0xFD, 0xB4,
  40484. 0xC7, 0xA0, 0xB8, 0xE4, 0x2F, 0x8A, 0xF9, 0xAC,
  40485. 0xAD, 0x2A, 0x0E, 0xFC, 0x11, 0x36, 0x02, 0xA4,
  40486. 0xEA, 0x62, 0xE4, 0xEB, 0xB7, 0xD2, 0x69, 0xC3,
  40487. 0xA4, 0x0B, 0xA2, 0xC4, 0x4E, 0xDD, 0x29, 0x56
  40488. };
  40489. static const byte msg_65[] = {
  40490. 0xC4, 0xF5, 0x9F, 0xA2, 0xDE, 0x30, 0xC8, 0x42,
  40491. 0x0A, 0x7E, 0x7F, 0x09, 0x6B, 0xAF, 0x6A, 0xD6,
  40492. 0x9B, 0x1C, 0x15, 0xA5, 0xC6, 0xE6, 0x1C, 0x9D,
  40493. 0x82, 0xAF, 0xCF, 0xDB, 0x6E, 0xB8, 0xF2, 0x75,
  40494. 0xBF, 0x57, 0x87, 0x18, 0x6A, 0xAE, 0x78, 0x1F,
  40495. 0x48, 0x7F, 0x9F, 0x88, 0x75, 0x8C, 0x9C, 0x61,
  40496. 0xF3, 0x5D, 0x50, 0x83, 0xEE, 0x70, 0x42, 0x4B,
  40497. 0x0D, 0x0A, 0x51, 0x57, 0x50, 0x10, 0xC2, 0xA9,
  40498. 0x07, 0xF4, 0x96, 0x08, 0x11, 0x5D, 0x33, 0xEB,
  40499. 0xA0, 0x03, 0x15, 0x09, 0x32, 0x2A, 0xA7, 0xD3,
  40500. 0x06, 0x1F, 0xEC, 0x31, 0x62, 0xF9, 0x6A, 0x56,
  40501. 0x5F, 0x98, 0x76, 0x9E, 0x9A, 0x19, 0x23, 0x5D,
  40502. 0x89, 0xD1, 0xB2, 0x1D, 0x60, 0xA3, 0x81, 0xDF,
  40503. 0x8E, 0xB3, 0x7D, 0x58, 0xC6, 0xA2, 0xE4, 0x83,
  40504. 0xA8, 0xEB, 0x70, 0x73, 0x6E, 0x4B, 0x7B, 0xB9,
  40505. 0x11, 0xF7, 0xAB, 0x92, 0x3D, 0xC2, 0x9F, 0x1E
  40506. };
  40507. static const byte sig_65[] = {
  40508. 0xE8, 0x95, 0xDB, 0x64, 0xC5, 0x7B, 0xC3, 0xC2,
  40509. 0xA9, 0x7F, 0x0E, 0xC9, 0x33, 0x41, 0x0E, 0x98,
  40510. 0xF6, 0x21, 0x61, 0x03, 0xE3, 0x42, 0x3C, 0xAF,
  40511. 0x06, 0xA6, 0x71, 0x96, 0x4C, 0x51, 0x4A, 0x69,
  40512. 0x4E, 0xB6, 0xF6, 0x5C, 0xBD, 0x11, 0x37, 0xCC,
  40513. 0xCF, 0x88, 0x81, 0xFA, 0x40, 0x3C, 0x5F, 0xA0,
  40514. 0xE0, 0xB2, 0xF3, 0x6B, 0x9F, 0x40, 0x09, 0xC3,
  40515. 0x78, 0x21, 0x0D, 0x29, 0xE5, 0x4A, 0x7A, 0x5A,
  40516. 0x9B, 0x79, 0x31, 0x97, 0xCD, 0x6D, 0x2F, 0x38,
  40517. 0xD7, 0xE1, 0xF3, 0xAC, 0xA6, 0x9D, 0x48, 0x88,
  40518. 0x13, 0x89, 0x38, 0x1C, 0x89, 0xFA, 0x67, 0x6D,
  40519. 0xE4, 0x26, 0xD6, 0x34, 0xF9, 0xA1, 0x57, 0x05,
  40520. 0x5F, 0x17, 0x28, 0x3E, 0xCE, 0x82, 0x48, 0xCA,
  40521. 0xF1, 0x4D, 0xCF, 0x11, 0xE2, 0xD5, 0x63, 0x55,
  40522. 0xB0, 0x47, 0xDF, 0x63, 0x2A, 0x18, 0x48, 0x2E,
  40523. 0x79, 0xCB, 0x2D, 0x5A, 0x74, 0x39, 0x66, 0xBA,
  40524. 0xA8, 0xA7, 0x61, 0x21, 0xBB, 0x69, 0xC2, 0xE6,
  40525. 0x81, 0x55, 0xAC, 0xCB, 0x0A, 0x31, 0xDA, 0x6E,
  40526. 0xDC, 0x73, 0xCB, 0x09, 0xA9, 0xE6, 0x60, 0xFE,
  40527. 0xB2, 0x0F, 0x66, 0xC7, 0xBD, 0x96, 0x7A, 0xDE,
  40528. 0x32, 0x14, 0x9C, 0x55, 0x52, 0xEA, 0xEB, 0x2E,
  40529. 0xA1, 0x75, 0xB5, 0x62, 0x33, 0xF3, 0xB3, 0x70,
  40530. 0xED, 0xD8, 0x67, 0x92, 0x69, 0xCE, 0x0D, 0x2B,
  40531. 0x43, 0xF6, 0xB2, 0xF6, 0x5F, 0xE9, 0x57, 0xE7,
  40532. 0xAB, 0x37, 0xB9, 0x82, 0x04, 0x37, 0x54, 0xEA,
  40533. 0xC8, 0xA3, 0x0B, 0x36, 0xC1, 0x00, 0x04, 0xEF,
  40534. 0x13, 0xC6, 0x92, 0xE2, 0x19, 0xAA, 0x7A, 0xF0,
  40535. 0xA4, 0xC5, 0x28, 0x69, 0x10, 0xC7, 0x10, 0x0D,
  40536. 0xA4, 0x1E, 0x17, 0xBB, 0xEF, 0x2D, 0xA2, 0xAB,
  40537. 0x03, 0xAD, 0xF3, 0x07, 0x4B, 0xA1, 0xDA, 0x15,
  40538. 0xBC, 0xC8, 0x48, 0x05, 0xB8, 0x9B, 0x9D, 0xA8,
  40539. 0x8E, 0x9B, 0x40, 0x0A, 0xFB, 0x7E, 0x3B, 0xC8,
  40540. 0x33, 0x8D, 0x35, 0x4D, 0xA9, 0x53, 0xAC, 0x0B,
  40541. 0xAD, 0x82, 0x27, 0x56, 0xCA, 0x92, 0xE5, 0xDD,
  40542. 0x95, 0x07, 0xF4, 0x2B, 0xFE, 0xFC, 0xCB, 0x32,
  40543. 0xB4, 0xB9, 0x1A, 0x2B, 0xE5, 0xEF, 0x34, 0xC2,
  40544. 0xCF, 0x11, 0x77, 0xEA, 0xAF, 0xB2, 0x50, 0xAC,
  40545. 0x9A, 0xDE, 0xC4, 0xBE, 0x71, 0x80, 0x75, 0x89,
  40546. 0xF1, 0x00, 0x32, 0x27, 0xF9, 0xB7, 0x6B, 0x74,
  40547. 0xE0, 0x7B, 0xA6, 0x7A, 0xC6, 0x08, 0x19, 0xB2,
  40548. 0xAF, 0x76, 0x6A, 0x47, 0xFF, 0xFC, 0x7B, 0x76,
  40549. 0xD3, 0xA7, 0xC0, 0x77, 0xF5, 0xEC, 0x69, 0xAE,
  40550. 0xEA, 0x3E, 0x96, 0x38, 0x59, 0xB8, 0x2C, 0x2A,
  40551. 0xDE, 0x58, 0xBE, 0xC2, 0x15, 0x2E, 0xC8, 0x20,
  40552. 0x51, 0x10, 0x97, 0x5D, 0x37, 0xC6, 0x50, 0x5E,
  40553. 0x0D, 0xC7, 0x76, 0xFD, 0xE0, 0x71, 0x09, 0x7E,
  40554. 0x93, 0x01, 0x3D, 0x10, 0x04, 0xF4, 0xE1, 0xA2,
  40555. 0xFD, 0x79, 0xB8, 0x77, 0xED, 0x50, 0x25, 0xF5,
  40556. 0x27, 0xF3, 0xBF, 0xF1, 0x37, 0xF0, 0x41, 0xBB,
  40557. 0x9B, 0xD0, 0x01, 0xE9, 0x49, 0xF0, 0x8B, 0x4C,
  40558. 0xF8, 0x8D, 0xFD, 0x32, 0xFC, 0x7C, 0xDB, 0xCE,
  40559. 0xCC, 0xFD, 0xB0, 0xFA, 0x2D, 0xE7, 0x82, 0x3E,
  40560. 0x11, 0x0B, 0xCF, 0xF5, 0x8A, 0x41, 0x2C, 0xEA,
  40561. 0x27, 0x95, 0x75, 0x3E, 0x9C, 0x89, 0x67, 0x8C,
  40562. 0x3A, 0xE2, 0x42, 0x68, 0xF7, 0x48, 0x9F, 0x72,
  40563. 0x97, 0x4B, 0x69, 0x55, 0xED, 0xD0, 0x4E, 0x19,
  40564. 0x0D, 0x99, 0xBB, 0x0D, 0x7A, 0x25, 0x2F, 0xAD,
  40565. 0x5B, 0xBA, 0x60, 0x6C, 0x1A, 0x1F, 0x3A, 0xCA,
  40566. 0x73, 0x3B, 0xFA, 0xE3, 0x30, 0x9E, 0xA0, 0xA6,
  40567. 0xEB, 0x7D, 0x07, 0xE3, 0x6D, 0x8C, 0xA3, 0x36,
  40568. 0xD2, 0x64, 0x4F, 0xCE, 0x1A, 0x41, 0x89, 0x5D,
  40569. 0x01, 0x4D, 0x1A, 0x60, 0xCB, 0x10, 0x6F, 0x3F,
  40570. 0x80, 0x75, 0xF9, 0x37, 0x84, 0x61, 0x73, 0x8D,
  40571. 0x63, 0xD1, 0x15, 0xD0, 0x0B, 0x02, 0x4C, 0x67,
  40572. 0x78, 0x01, 0x05, 0x0A, 0x1B, 0x0B, 0x50, 0xDE,
  40573. 0x05, 0x7F, 0x85, 0xDB, 0x6A, 0xEB, 0x2C, 0x9D,
  40574. 0x6B, 0xB7, 0x40, 0x2A, 0x66, 0xE3, 0xAB, 0x4D,
  40575. 0xB0, 0x5C, 0x58, 0xBB, 0xDA, 0x12, 0xF6, 0x95,
  40576. 0x95, 0x8B, 0x8A, 0xC7, 0xB4, 0xE4, 0x5E, 0xC6,
  40577. 0xC9, 0x52, 0xF6, 0x79, 0xC1, 0xEE, 0xBD, 0xF8,
  40578. 0x60, 0xE3, 0x48, 0x98, 0x27, 0x79, 0xAA, 0x69,
  40579. 0x88, 0xEF, 0xC2, 0xAD, 0x1D, 0xC1, 0xEA, 0xE2,
  40580. 0x2A, 0x27, 0xA5, 0xB2, 0xC6, 0x1C, 0x97, 0xB3,
  40581. 0xB2, 0x49, 0x3C, 0xB6, 0xC1, 0x3C, 0x5F, 0x6E,
  40582. 0x20, 0xA6, 0x7B, 0x88, 0xD3, 0xC3, 0xAC, 0xCF,
  40583. 0xAF, 0x0A, 0x42, 0x57, 0x42, 0xDF, 0x24, 0x06,
  40584. 0x34, 0xD1, 0xEE, 0x59, 0x38, 0x28, 0xFE, 0x62,
  40585. 0x97, 0x44, 0x6C, 0x07, 0x6F, 0x97, 0x90, 0x55,
  40586. 0x98, 0x8A, 0xB8, 0x34, 0xB2, 0xBD, 0x82, 0xE1,
  40587. 0x4D, 0xC0, 0x86, 0x40, 0x0E, 0x1C, 0x95, 0x6C,
  40588. 0xC0, 0xC3, 0x0C, 0xE7, 0xBF, 0xD9, 0x62, 0x22,
  40589. 0x3D, 0x23, 0xFE, 0x94, 0x94, 0x96, 0x4A, 0x81,
  40590. 0x1B, 0x93, 0xE8, 0xD7, 0xB8, 0xF3, 0x4C, 0x89,
  40591. 0xAA, 0xD4, 0x5D, 0xD4, 0x11, 0x3F, 0x2A, 0xE7,
  40592. 0xBD, 0x94, 0xB5, 0x3F, 0xC8, 0x6E, 0x8B, 0x2A,
  40593. 0xE8, 0x2E, 0x51, 0xEC, 0x6F, 0x3E, 0xA4, 0xC3,
  40594. 0x0D, 0x60, 0xB8, 0x60, 0x72, 0x74, 0x86, 0x12,
  40595. 0xD1, 0x60, 0x70, 0x56, 0xB5, 0xFF, 0x6A, 0x45,
  40596. 0x00, 0xEE, 0xE7, 0x8A, 0x5A, 0x63, 0x9C, 0x7B,
  40597. 0x74, 0x16, 0x97, 0x77, 0x62, 0x68, 0x64, 0xDD,
  40598. 0x9E, 0xAE, 0xF0, 0xE3, 0xAD, 0x84, 0x93, 0xD8,
  40599. 0x31, 0xF7, 0x1D, 0xEA, 0x95, 0xBB, 0xFC, 0xF8,
  40600. 0x14, 0x23, 0xA2, 0x66, 0xDE, 0x56, 0xF3, 0xA8,
  40601. 0xFE, 0x8E, 0x6C, 0x3C, 0x0D, 0x61, 0x2F, 0xB6,
  40602. 0x2B, 0xD6, 0x42, 0x18, 0x8C, 0xA7, 0x1C, 0xB8,
  40603. 0x98, 0x34, 0xF3, 0x0B, 0xCC, 0x28, 0xBD, 0x17,
  40604. 0x88, 0x45, 0xF1, 0xF6, 0xF4, 0x6C, 0x03, 0xD3,
  40605. 0x06, 0xF7, 0xED, 0x4E, 0x68, 0x75, 0x94, 0x27,
  40606. 0xAE, 0xC2, 0x70, 0x11, 0x98, 0xC3, 0xC0, 0x5D,
  40607. 0x38, 0x5D, 0xFA, 0xFD, 0x52, 0x8C, 0xCE, 0x84,
  40608. 0x25, 0xBC, 0x55, 0x14, 0x69, 0xA0, 0xED, 0x68,
  40609. 0x1B, 0xEE, 0x4D, 0x12, 0xA8, 0x43, 0xE3, 0x33,
  40610. 0xB5, 0xA8, 0xE0, 0x51, 0x7F, 0xC6, 0x19, 0x06,
  40611. 0xF9, 0xC4, 0xE7, 0x80, 0x9B, 0xAE, 0xD4, 0xD3,
  40612. 0xD1, 0x6E, 0xB2, 0x2F, 0x1F, 0xA9, 0xAB, 0x40,
  40613. 0x2D, 0x98, 0x8E, 0xD5, 0x9F, 0x9F, 0xED, 0x04,
  40614. 0x55, 0xE9, 0x26, 0x0F, 0xD6, 0x27, 0xA2, 0x4A,
  40615. 0x17, 0xFE, 0x7C, 0xB6, 0x3E, 0x53, 0x0B, 0x48,
  40616. 0xF5, 0xFB, 0x66, 0x87, 0xA2, 0xE8, 0xC4, 0x9D,
  40617. 0xA7, 0x9F, 0xBD, 0x69, 0xA3, 0x40, 0x00, 0x56,
  40618. 0x66, 0x5D, 0xD1, 0x1D, 0x19, 0xA2, 0xBC, 0x4D,
  40619. 0xB1, 0xD3, 0x74, 0xAB, 0x6A, 0x6E, 0x42, 0x47,
  40620. 0x2A, 0x27, 0xAC, 0x6B, 0x98, 0xF6, 0x76, 0xE8,
  40621. 0xED, 0xAA, 0xDD, 0x51, 0x4F, 0x6D, 0x44, 0xDE,
  40622. 0xEC, 0xDA, 0xB5, 0xA6, 0xDF, 0xA0, 0xF8, 0x4F,
  40623. 0x13, 0x9A, 0x80, 0x3A, 0x25, 0x24, 0xBF, 0x33,
  40624. 0x5D, 0xC5, 0x2E, 0xA5, 0x8F, 0xA5, 0x0D, 0x98,
  40625. 0xFB, 0x5C, 0xD5, 0x5D, 0x5D, 0x50, 0xA6, 0x63,
  40626. 0xCF, 0x64, 0x7E, 0xEE, 0x56, 0xFE, 0x8E, 0x66,
  40627. 0x4B, 0x3B, 0xCA, 0xF9, 0xE3, 0x33, 0x97, 0x8A,
  40628. 0x79, 0x46, 0x97, 0x3F, 0xD1, 0x13, 0xE4, 0xFD,
  40629. 0x39, 0x24, 0xE6, 0xC0, 0x9E, 0x60, 0x38, 0x64,
  40630. 0x44, 0x21, 0x4D, 0xFA, 0x7A, 0x4D, 0x67, 0x1F,
  40631. 0xC2, 0x38, 0x90, 0x63, 0x7E, 0xB8, 0x59, 0x13,
  40632. 0x4D, 0x79, 0xE2, 0x65, 0xC5, 0x9C, 0xA3, 0xEC,
  40633. 0xCD, 0xDF, 0xA0, 0x18, 0x22, 0x3C, 0x9B, 0xAE,
  40634. 0x1C, 0xCA, 0x10, 0x39, 0x62, 0x07, 0x8B, 0xC5,
  40635. 0xF0, 0xDD, 0x02, 0x24, 0x6F, 0xA2, 0x83, 0x24,
  40636. 0xF7, 0xCB, 0x2F, 0xCF, 0xAD, 0x07, 0xC2, 0x5B,
  40637. 0x4B, 0xC2, 0xD8, 0x88, 0x06, 0x9B, 0x0C, 0xF5,
  40638. 0xF2, 0x3C, 0x76, 0x1C, 0x0E, 0x47, 0x10, 0x98,
  40639. 0x81, 0xCD, 0x31, 0x45, 0x6A, 0x64, 0xB9, 0x40,
  40640. 0xB4, 0xBB, 0x9B, 0x4C, 0x2C, 0x3B, 0x8E, 0x6B,
  40641. 0xA8, 0x34, 0xAA, 0xAE, 0x69, 0xFD, 0xFC, 0x47,
  40642. 0xD4, 0x4B, 0x3C, 0x96, 0x88, 0x7A, 0xBE, 0xD3,
  40643. 0x60, 0x15, 0xE7, 0xB6, 0x4E, 0x85, 0x42, 0x92,
  40644. 0x8F, 0x27, 0x7C, 0xBD, 0x2D, 0x3C, 0x51, 0x2C,
  40645. 0x24, 0xDE, 0xEF, 0xE5, 0x90, 0xE8, 0x1C, 0x68,
  40646. 0x4E, 0x06, 0x3E, 0x7A, 0xAD, 0xCF, 0x11, 0x7B,
  40647. 0x48, 0x94, 0x3D, 0xB7, 0x71, 0xFC, 0x22, 0x07,
  40648. 0xF5, 0x7A, 0x74, 0x53, 0x57, 0x55, 0x5D, 0x41,
  40649. 0x9C, 0x9C, 0xDC, 0xA3, 0x5C, 0xC1, 0xA7, 0x10,
  40650. 0x0A, 0x69, 0x13, 0xA3, 0xB6, 0xAA, 0xCF, 0x79,
  40651. 0x6F, 0xE3, 0xF9, 0x4D, 0xD2, 0xF8, 0x18, 0x98,
  40652. 0x27, 0x16, 0xCE, 0x03, 0x16, 0x54, 0x2A, 0x1B,
  40653. 0x95, 0x7E, 0x12, 0xDA, 0x43, 0xE2, 0x31, 0x54,
  40654. 0x2C, 0xC1, 0x4F, 0xCC, 0x66, 0xD7, 0x28, 0xA6,
  40655. 0x83, 0x26, 0xB2, 0xBC, 0x31, 0x12, 0x48, 0x33,
  40656. 0x0F, 0x3E, 0x98, 0xF8, 0x1E, 0xA3, 0x8C, 0xA9,
  40657. 0x24, 0xA8, 0xE4, 0xDA, 0x97, 0xCF, 0x67, 0x38,
  40658. 0x42, 0xC7, 0x59, 0xF9, 0x35, 0xBE, 0x88, 0x16,
  40659. 0x3C, 0xE9, 0x7F, 0xE4, 0xD9, 0x45, 0x71, 0x76,
  40660. 0xF5, 0xB8, 0x90, 0x8A, 0xF9, 0x48, 0xF7, 0x4D,
  40661. 0x5D, 0x1D, 0xDB, 0xC5, 0x21, 0x82, 0x5D, 0x93,
  40662. 0x1C, 0x63, 0xCA, 0x8A, 0x8E, 0x12, 0x24, 0x26,
  40663. 0x26, 0x30, 0x5A, 0xB6, 0xA2, 0xE0, 0x62, 0x45,
  40664. 0x64, 0xEE, 0x04, 0x19, 0x83, 0xC1, 0x8C, 0x29,
  40665. 0x52, 0xEC, 0x3D, 0x9D, 0x15, 0x9B, 0xDE, 0x39,
  40666. 0x85, 0xCF, 0x77, 0x89, 0x7E, 0xE2, 0xDC, 0x88,
  40667. 0x81, 0x12, 0x72, 0x1D, 0x48, 0x54, 0xE9, 0x14,
  40668. 0xA5, 0x39, 0x7E, 0x08, 0xB5, 0x4F, 0x4A, 0x54,
  40669. 0x32, 0x3F, 0xF8, 0x20, 0x82, 0x1B, 0xE0, 0x26,
  40670. 0xEA, 0x09, 0x1E, 0xCA, 0x6B, 0x7D, 0x80, 0xD9,
  40671. 0x1E, 0x3D, 0xCA, 0x2E, 0xF7, 0x84, 0x8B, 0x86,
  40672. 0xFC, 0xA6, 0xBB, 0x40, 0xCE, 0x48, 0x27, 0x1E,
  40673. 0x10, 0x08, 0x36, 0x8E, 0x3E, 0xBB, 0x5E, 0x39,
  40674. 0x5E, 0x1C, 0xCD, 0x0D, 0x17, 0x8F, 0x1A, 0x62,
  40675. 0x57, 0xD2, 0x6B, 0x6B, 0xA4, 0xB7, 0xCE, 0x53,
  40676. 0x2C, 0xAA, 0x1E, 0x76, 0xCE, 0x28, 0xFA, 0x4C,
  40677. 0xF9, 0xE0, 0x29, 0xE2, 0x48, 0x2B, 0x94, 0xD3,
  40678. 0xAC, 0xF9, 0x7A, 0x32, 0x6D, 0x23, 0x5D, 0x1B,
  40679. 0xDC, 0x89, 0xF7, 0x00, 0x02, 0x19, 0x84, 0x51,
  40680. 0xD9, 0xF1, 0xF1, 0x2C, 0xCD, 0x5B, 0xCA, 0xEC,
  40681. 0xDD, 0xE9, 0xE1, 0x4A, 0xC8, 0x07, 0x42, 0xEB,
  40682. 0x31, 0xE6, 0x46, 0x4C, 0x83, 0x21, 0x0A, 0x39,
  40683. 0xF3, 0x50, 0x98, 0xBE, 0x03, 0x78, 0xD0, 0x74,
  40684. 0xCE, 0x1C, 0xCD, 0x1E, 0xBC, 0x1C, 0x77, 0x70,
  40685. 0xF7, 0x78, 0xD6, 0x05, 0xF2, 0xBE, 0x59, 0xDB,
  40686. 0x7E, 0xA0, 0x7D, 0x80, 0xCC, 0xDF, 0x55, 0xF1,
  40687. 0x6E, 0x98, 0x5B, 0x14, 0x2F, 0xB7, 0xBD, 0xA0,
  40688. 0x7A, 0xA7, 0xDC, 0xA5, 0xB2, 0x01, 0xE1, 0x95,
  40689. 0x0C, 0xF9, 0xA7, 0x28, 0xF2, 0x1E, 0x9A, 0x9D,
  40690. 0x8A, 0xC4, 0xD1, 0x32, 0x7E, 0x3B, 0xC0, 0xFF,
  40691. 0x33, 0x9A, 0x25, 0x05, 0x22, 0xF6, 0x31, 0xDF,
  40692. 0x2E, 0x75, 0x95, 0x51, 0x54, 0x89, 0x3E, 0x4A,
  40693. 0x1A, 0xAF, 0x98, 0x66, 0xFE, 0xE1, 0x63, 0x7E,
  40694. 0xE1, 0xAA, 0x51, 0x06, 0xD2, 0x44, 0xE9, 0x9E,
  40695. 0x6F, 0x31, 0xFC, 0x56, 0x01, 0xBB, 0x7B, 0x79,
  40696. 0xBA, 0xD8, 0x28, 0x60, 0xB1, 0xD6, 0x05, 0x9D,
  40697. 0x9B, 0x13, 0x2E, 0x02, 0x64, 0x18, 0x02, 0x0D,
  40698. 0xB0, 0x6E, 0xB8, 0x39, 0x1F, 0xA1, 0x5B, 0x7A,
  40699. 0x0F, 0x29, 0xE3, 0x6D, 0x96, 0x6A, 0xBD, 0x3D,
  40700. 0x2A, 0x2F, 0xF3, 0xF2, 0xAA, 0xC3, 0x4C, 0x8B,
  40701. 0x45, 0xC7, 0xD2, 0x35, 0x5E, 0xDB, 0xB8, 0x0B,
  40702. 0x22, 0x4B, 0xC1, 0x06, 0xEB, 0xC6, 0x75, 0x0E,
  40703. 0x55, 0x07, 0x0F, 0x85, 0xA7, 0xCB, 0x60, 0x03,
  40704. 0x39, 0x4E, 0x51, 0x61, 0xAE, 0x26, 0xF5, 0xAB,
  40705. 0xF8, 0x3F, 0x0D, 0xCC, 0xCF, 0x69, 0xB8, 0x61,
  40706. 0x39, 0xAF, 0x86, 0x94, 0xFE, 0x1D, 0xC0, 0x07,
  40707. 0x81, 0xEA, 0xE0, 0x9C, 0xDB, 0x42, 0x18, 0x14,
  40708. 0x87, 0x80, 0x43, 0xDC, 0x9B, 0x05, 0x30, 0xE5,
  40709. 0x54, 0x5A, 0x16, 0x5E, 0x39, 0xA9, 0xB7, 0xDE,
  40710. 0x88, 0xB4, 0xAD, 0x2A, 0xEB, 0x90, 0xD3, 0xC3,
  40711. 0x29, 0x41, 0x2E, 0xD2, 0xFE, 0x1D, 0x97, 0xB7,
  40712. 0x32, 0xC8, 0x43, 0x9D, 0xF4, 0xF8, 0x3D, 0x22,
  40713. 0x88, 0x35, 0xB5, 0x38, 0xDC, 0x27, 0x8F, 0xF0,
  40714. 0xA2, 0xDC, 0x42, 0xF4, 0x1B, 0x00, 0xCE, 0x3A,
  40715. 0xCA, 0x06, 0xB0, 0x5C, 0x48, 0x39, 0xB8, 0x96,
  40716. 0x93, 0x15, 0x15, 0xD7, 0x8E, 0xA3, 0x67, 0x3A,
  40717. 0x37, 0x82, 0x79, 0xF4, 0xE8, 0x9C, 0xE0, 0x8E,
  40718. 0x34, 0x53, 0xFF, 0x2F, 0xB4, 0x53, 0xBE, 0x03,
  40719. 0x1C, 0x63, 0x18, 0x62, 0x8A, 0x73, 0x1D, 0x02,
  40720. 0x9F, 0xC7, 0xBE, 0xA2, 0xBA, 0x5E, 0xAC, 0x49,
  40721. 0x16, 0x27, 0x8B, 0x93, 0x8A, 0x6A, 0x6A, 0xCE,
  40722. 0xF5, 0xBF, 0xE2, 0x15, 0x8F, 0x2A, 0xF4, 0x3D,
  40723. 0x8E, 0x56, 0xA0, 0x64, 0x9D, 0xF2, 0x8A, 0x25,
  40724. 0x0D, 0x2F, 0x25, 0x36, 0xAB, 0xDE, 0x1E, 0x00,
  40725. 0x8E, 0xB6, 0x31, 0xF4, 0xBD, 0x0E, 0xB5, 0x55,
  40726. 0x73, 0xA4, 0x05, 0x39, 0xA6, 0x00, 0x41, 0x81,
  40727. 0xA9, 0xD2, 0xBF, 0x7A, 0x1E, 0x53, 0x50, 0x4F,
  40728. 0x11, 0xE0, 0x14, 0x84, 0x07, 0x33, 0x84, 0x41,
  40729. 0x31, 0xAC, 0x66, 0x89, 0x46, 0xE5, 0xB8, 0x27,
  40730. 0x28, 0x9A, 0xB6, 0xB2, 0x13, 0x66, 0xC5, 0xD0,
  40731. 0xE2, 0x64, 0x92, 0x19, 0xB9, 0x2C, 0x47, 0x60,
  40732. 0xDF, 0xB7, 0x05, 0xF7, 0xF6, 0x1A, 0x96, 0x56,
  40733. 0x4C, 0x9E, 0x84, 0x0D, 0x14, 0xB0, 0xBB, 0x0D,
  40734. 0xA8, 0x2D, 0xA5, 0x0F, 0x8B, 0x8E, 0x75, 0x2B,
  40735. 0xBF, 0xEA, 0x3B, 0x0A, 0x33, 0x7B, 0xE1, 0x24,
  40736. 0xF7, 0x2D, 0x8F, 0x82, 0x49, 0x19, 0x5B, 0xC1,
  40737. 0x9C, 0x3E, 0x0B, 0x62, 0xEA, 0xE4, 0x96, 0xD3,
  40738. 0x8C, 0xF7, 0x50, 0x0B, 0x4F, 0x10, 0x66, 0x5F,
  40739. 0xC2, 0xD2, 0x8B, 0x9E, 0xA9, 0x35, 0xF7, 0xE3,
  40740. 0x16, 0x47, 0x2F, 0x4F, 0xF4, 0x01, 0x26, 0x75,
  40741. 0x41, 0xBD, 0xB6, 0x23, 0x01, 0x55, 0x4B, 0x20,
  40742. 0x09, 0x92, 0x8C, 0x64, 0x45, 0xBB, 0xD0, 0xEF,
  40743. 0x21, 0xD0, 0x99, 0x72, 0xF3, 0x50, 0x81, 0xAB,
  40744. 0xA9, 0x09, 0x1A, 0x6C, 0x23, 0xFE, 0xD2, 0x9F,
  40745. 0x5C, 0xF9, 0xE0, 0x77, 0x9F, 0x7E, 0xFB, 0xAD,
  40746. 0x88, 0xE6, 0x2A, 0x45, 0x44, 0x42, 0xB3, 0x00,
  40747. 0x79, 0xBE, 0x0A, 0xC9, 0xC6, 0x48, 0x26, 0xB9,
  40748. 0x8C, 0x1E, 0x10, 0x01, 0xCB, 0x0F, 0xB0, 0xF0,
  40749. 0xA9, 0x5F, 0x79, 0x65, 0xFE, 0x93, 0x12, 0xBF,
  40750. 0xDA, 0xEC, 0x33, 0xF9, 0x50, 0x65, 0xC8, 0xE5,
  40751. 0x9D, 0x39, 0x50, 0xF8, 0x0A, 0xDC, 0x7F, 0xB3,
  40752. 0x34, 0xF2, 0x02, 0xD3, 0xE5, 0xF8, 0xDA, 0x48,
  40753. 0x1C, 0x9B, 0x54, 0xA7, 0x59, 0x83, 0x93, 0x0F,
  40754. 0xD1, 0xE5, 0xAC, 0xD1, 0x62, 0x84, 0xF0, 0x71,
  40755. 0x93, 0xFB, 0xCB, 0x50, 0xD0, 0xDC, 0x00, 0xEF,
  40756. 0xF8, 0x20, 0x31, 0x44, 0xC1, 0x1E, 0xC6, 0x14,
  40757. 0x20, 0xFC, 0x32, 0xD7, 0x98, 0x2C, 0xE8, 0x96,
  40758. 0x40, 0x6B, 0xE7, 0x69, 0xA7, 0x5D, 0xD8, 0xD3,
  40759. 0xCA, 0xC7, 0x53, 0xAB, 0xE5, 0xA2, 0x78, 0x65,
  40760. 0x5B, 0xF5, 0x4B, 0xE3, 0x3A, 0x1B, 0x83, 0x74,
  40761. 0xEB, 0xEE, 0xFF, 0x21, 0x2C, 0x39, 0xCE, 0x51,
  40762. 0x46, 0x68, 0xF1, 0xC4, 0x56, 0xEA, 0xA2, 0x53,
  40763. 0x28, 0x28, 0xC8, 0x42, 0x93, 0xF1, 0xA5, 0xBC,
  40764. 0x9E, 0xB5, 0xDE, 0xDF, 0x55, 0x8A, 0x9B, 0x4C,
  40765. 0x12, 0x39, 0xF7, 0x72, 0x72, 0xC6, 0x7E, 0x1A,
  40766. 0xB2, 0x8E, 0x1E, 0xFE, 0xC5, 0x89, 0x3E, 0x09,
  40767. 0xC1, 0x06, 0x62, 0xB5, 0x3C, 0x8B, 0x82, 0x55,
  40768. 0xB1, 0xC8, 0xDC, 0x8F, 0x8E, 0x51, 0x20, 0xA2,
  40769. 0x5C, 0x75, 0xEE, 0xFE, 0x79, 0xC4, 0x3F, 0x7A,
  40770. 0x8B, 0x37, 0xDF, 0x9D, 0x1E, 0x4F, 0x32, 0x48,
  40771. 0x69, 0x33, 0xDA, 0x1C, 0xB0, 0x66, 0x4C, 0x5D,
  40772. 0xB3, 0x9E, 0x21, 0xBC, 0x22, 0x7B, 0x0C, 0xDF,
  40773. 0xE7, 0xA5, 0x50, 0x7F, 0x07, 0xF2, 0x18, 0xA7,
  40774. 0xA4, 0x7D, 0xEB, 0xCD, 0x9D, 0xAD, 0x72, 0x47,
  40775. 0xB4, 0xD0, 0x45, 0xA1, 0x3A, 0xD4, 0xF7, 0x5E,
  40776. 0xAD, 0x2D, 0x45, 0xC3, 0x39, 0xD0, 0xDF, 0x04,
  40777. 0x57, 0x7F, 0x2E, 0x0F, 0xDC, 0x78, 0x03, 0x92,
  40778. 0x55, 0x30, 0x33, 0xC7, 0x38, 0x85, 0x2B, 0x1B,
  40779. 0xE4, 0xE6, 0x3E, 0xA3, 0x89, 0x7D, 0x6C, 0x9C,
  40780. 0x4B, 0x11, 0xAD, 0x6B, 0x58, 0xD3, 0xE2, 0xD3,
  40781. 0x42, 0xD3, 0x28, 0x40, 0xF6, 0x49, 0xDD, 0x83,
  40782. 0xE7, 0x59, 0x86, 0x6B, 0x73, 0x81, 0xA8, 0x4C,
  40783. 0x8A, 0xDD, 0xDF, 0x41, 0x3F, 0xAE, 0x18, 0xE6,
  40784. 0x43, 0x1B, 0x1E, 0xEA, 0x73, 0xA5, 0x6C, 0xD8,
  40785. 0x89, 0xB7, 0x6B, 0xC9, 0x78, 0x6B, 0xED, 0xED,
  40786. 0xCA, 0x25, 0x41, 0xE4, 0xC9, 0xB2, 0x4E, 0x28,
  40787. 0xF5, 0x8A, 0xD3, 0x74, 0xC1, 0xD9, 0x3D, 0xF2,
  40788. 0xD3, 0xF2, 0xC3, 0x7E, 0xC5, 0x94, 0xA0, 0x49,
  40789. 0x8C, 0x57, 0x45, 0x79, 0xA7, 0x33, 0x2F, 0x72,
  40790. 0xC0, 0xF9, 0x75, 0x08, 0x77, 0xFA, 0xD5, 0xB9,
  40791. 0x0B, 0x96, 0x8D, 0x88, 0xF1, 0x16, 0x82, 0xC4,
  40792. 0x07, 0x1E, 0x4E, 0xA3, 0x8B, 0x81, 0x6A, 0xEA,
  40793. 0xD6, 0xBE, 0x54, 0xD2, 0xF3, 0x71, 0x32, 0x4F,
  40794. 0x24, 0x75, 0xB8, 0x62, 0xC7, 0x54, 0x24, 0xEC,
  40795. 0xF9, 0x85, 0x8A, 0xA4, 0xE2, 0x00, 0xCF, 0xBA,
  40796. 0x41, 0x2D, 0x7E, 0x3E, 0x6C, 0x30, 0x8D, 0x8D,
  40797. 0xE1, 0x1D, 0xD1, 0x85, 0x33, 0x1A, 0xF9, 0xD4,
  40798. 0x1A, 0xFE, 0x88, 0x79, 0x96, 0x5D, 0x67, 0x46,
  40799. 0xEF, 0x21, 0xFD, 0x98, 0xD3, 0xED, 0x38, 0x06,
  40800. 0xFB, 0x5C, 0x46, 0x19, 0xC9, 0x8E, 0x34, 0x7D,
  40801. 0x76, 0xB8, 0xB8, 0x98, 0x49, 0x39, 0x55, 0x61,
  40802. 0xEE, 0x28, 0x6D, 0xFD, 0xFC, 0x6A, 0x04, 0xE1,
  40803. 0xD4, 0x7E, 0x9F, 0x5B, 0x5B, 0x49, 0x25, 0x77,
  40804. 0x84, 0xC3, 0x93, 0x64, 0xDF, 0xA8, 0x8A, 0xD6,
  40805. 0x30, 0xDF, 0xA5, 0x9C, 0xCA, 0x32, 0x37, 0xF4,
  40806. 0xA2, 0xB1, 0x41, 0xA8, 0x13, 0xD2, 0x2C, 0x6F,
  40807. 0xFE, 0x73, 0xC2, 0xD9, 0x9A, 0xDC, 0x82, 0x4D,
  40808. 0x93, 0xE0, 0x6A, 0x54, 0xB6, 0xDE, 0x62, 0xC3,
  40809. 0x12, 0x5D, 0x94, 0xB4, 0x9E, 0x95, 0x0D, 0xEC,
  40810. 0x36, 0x1F, 0x96, 0x1F, 0x56, 0xD3, 0x67, 0x1C,
  40811. 0x99, 0x25, 0x37, 0x7F, 0x6E, 0x67, 0x06, 0x65,
  40812. 0x32, 0x2B, 0x84, 0x89, 0xE8, 0x33, 0xD3, 0x83,
  40813. 0x0E, 0xCC, 0xDD, 0x0F, 0x53, 0xF4, 0xA4, 0xF9,
  40814. 0xD6, 0x8F, 0x14, 0x45, 0xF3, 0xAE, 0xD5, 0xC9,
  40815. 0xD7, 0x66, 0x40, 0x9B, 0x59, 0xBA, 0xE7, 0xA7,
  40816. 0x29, 0x12, 0xE9, 0x8B, 0x3B, 0xB5, 0x73, 0x42,
  40817. 0xD2, 0x9B, 0x6A, 0xCF, 0xD1, 0x43, 0x36, 0xB7,
  40818. 0xB8, 0xB6, 0xB7, 0x54, 0x9A, 0xF8, 0xCC, 0x88,
  40819. 0x45, 0xE1, 0x0C, 0x28, 0x11, 0x28, 0x72, 0x81,
  40820. 0x98, 0x5D, 0x5D, 0x47, 0x68, 0x5F, 0xC5, 0x89,
  40821. 0xF2, 0x67, 0x8E, 0xD8, 0x93, 0xF5, 0x7B, 0x85,
  40822. 0xAC, 0xED, 0x75, 0x63, 0x2E, 0x50, 0xDE, 0x5E,
  40823. 0x07, 0x4E, 0x6C, 0xED, 0xCF, 0x1A, 0xD4, 0x99,
  40824. 0xBC, 0xE6, 0x7A, 0x7F, 0x49, 0x85, 0x64, 0xDE,
  40825. 0xEC, 0x67, 0x7C, 0x70, 0x83, 0x88, 0xDE, 0x8F,
  40826. 0xD7, 0xB0, 0x99, 0xCF, 0xC1, 0x16, 0x09, 0x6C,
  40827. 0x45, 0xFE, 0x28, 0x89, 0x0B, 0x5E, 0xAF, 0x06,
  40828. 0x16, 0x99, 0x39, 0xFD, 0xA3, 0x5E, 0x12, 0x15,
  40829. 0xF2, 0x38, 0xE8, 0xCD, 0xED, 0xFE, 0x67, 0x00,
  40830. 0x65, 0xF5, 0xDE, 0x32, 0x72, 0xA2, 0x32, 0xFD,
  40831. 0x53, 0xC2, 0x50, 0xF5, 0xD7, 0x79, 0xB3, 0x16,
  40832. 0x94, 0xFB, 0xA9, 0x1B, 0x55, 0x48, 0x03, 0x67,
  40833. 0x6E, 0x4D, 0xEA, 0x28, 0x84, 0x63, 0xFE, 0x10,
  40834. 0x63, 0x00, 0x9E, 0x9C, 0xB7, 0x6C, 0x31, 0x7D,
  40835. 0xB4, 0x00, 0xAC, 0xF4, 0xD2, 0xD2, 0xB6, 0xD1,
  40836. 0x6E, 0xDE, 0xBA, 0x41, 0x08, 0x91, 0x3F, 0x60,
  40837. 0xAE, 0xB2, 0x52, 0xCD, 0xE4, 0x13, 0x69, 0x0C,
  40838. 0xEE, 0xFD, 0xCF, 0xA6, 0x38, 0x96, 0x3D, 0xBD,
  40839. 0x04, 0xF4, 0xCF, 0x21, 0xAD, 0x74, 0xDD, 0xE6,
  40840. 0x5F, 0x0F, 0x1E, 0x7C, 0xE7, 0x0A, 0xF1, 0x01,
  40841. 0xA6, 0xDE, 0x9A, 0x59, 0xDB, 0x21, 0xD3, 0x80,
  40842. 0x27, 0xDB, 0xBF, 0x76, 0x16, 0x78, 0x27, 0x95,
  40843. 0x0B, 0x69, 0x41, 0x82, 0x66, 0xAF, 0xA4, 0x44,
  40844. 0xC7, 0x28, 0xDE, 0x36, 0x24, 0xA1, 0xC8, 0x1E,
  40845. 0x5B, 0x16, 0x41, 0xDB, 0xE8, 0x79, 0xCD, 0x82,
  40846. 0x2F, 0xB2, 0x30, 0x3C, 0xC3, 0xA9, 0xFC, 0xEE,
  40847. 0xFE, 0x3D, 0xDF, 0x7D, 0xBD, 0x0B, 0x70, 0x57,
  40848. 0x24, 0x8A, 0x28, 0xD6, 0x06, 0x2D, 0x76, 0xEB,
  40849. 0x13, 0xB9, 0x2C, 0x9C, 0x9D, 0x00, 0x3B, 0x69,
  40850. 0xE1, 0x84, 0x2A, 0x54, 0xC0, 0x9C, 0xF6, 0xB4,
  40851. 0x84, 0x52, 0x08, 0x15, 0xE2, 0xBB, 0x23, 0x72,
  40852. 0x88, 0xC6, 0x4F, 0xC6, 0x96, 0xFD, 0x3B, 0xC4,
  40853. 0x5D, 0xB3, 0x0C, 0xB8, 0x64, 0x65, 0xDF, 0x11,
  40854. 0x88, 0xBF, 0x47, 0x95, 0x6E, 0x5B, 0x91, 0x6A,
  40855. 0x80, 0x09, 0x71, 0x5C, 0xC9, 0xA9, 0xA6, 0xDC,
  40856. 0xE4, 0x4C, 0x54, 0xF9, 0x28, 0x81, 0x6B, 0x41,
  40857. 0xD0, 0x18, 0xC5, 0xFE, 0x65, 0x2F, 0xFE, 0x4E,
  40858. 0x33, 0xF3, 0x52, 0xD3, 0x83, 0xA9, 0xC1, 0x36,
  40859. 0x5F, 0x02, 0xAB, 0xFD, 0x64, 0x7B, 0xD6, 0xB4,
  40860. 0x2A, 0xD1, 0x63, 0x73, 0x0F, 0x8B, 0xFD, 0xA1,
  40861. 0xE2, 0xBE, 0x5F, 0x61, 0x4D, 0x79, 0x59, 0x78,
  40862. 0x25, 0xBA, 0x09, 0xF4, 0x57, 0xD3, 0xCB, 0xE7,
  40863. 0x56, 0x1E, 0x7E, 0x89, 0xEA, 0xF0, 0x59, 0xE9,
  40864. 0x77, 0xD1, 0xEE, 0x88, 0x84, 0x8B, 0x78, 0x1F,
  40865. 0x21, 0xF7, 0x23, 0x89, 0x0F, 0xF1, 0xF9, 0x87,
  40866. 0x39, 0x28, 0x41, 0x2C, 0x8F, 0x11, 0xEE, 0xDD,
  40867. 0x2C, 0x0C, 0x39, 0xC9, 0x51, 0x27, 0x90, 0x98,
  40868. 0x6A, 0x19, 0xE1, 0x7B, 0x2B, 0x70, 0xA4, 0xD7,
  40869. 0xCF, 0x49, 0xD9, 0xD1, 0x8C, 0xAA, 0x0C, 0x20,
  40870. 0x23, 0x13, 0x4C, 0xAC, 0xD1, 0x69, 0x20, 0x0D,
  40871. 0x88, 0x17, 0xFA, 0x32, 0x1F, 0x04, 0xAC, 0xC9,
  40872. 0x10, 0x61, 0x3D, 0xFF, 0x25, 0x0E, 0xB3, 0x25,
  40873. 0xDB, 0xEF, 0x29, 0xEB, 0x56, 0x11, 0xB2, 0xAD,
  40874. 0x2A, 0x23, 0xED, 0xD5, 0x38, 0x04, 0x9B, 0x3F,
  40875. 0x43, 0xEF, 0xEB, 0x4D, 0x60, 0x98, 0x37, 0x92,
  40876. 0xB4, 0xBF, 0x05, 0x56, 0x79, 0x44, 0xAA, 0xDB,
  40877. 0x7A, 0xC4, 0xD3, 0xA5, 0xD8, 0x0A, 0x1B, 0x9D,
  40878. 0x84, 0x48, 0xB4, 0xC0, 0xC1, 0x15, 0xC3, 0xB5,
  40879. 0xAD, 0x38, 0x85, 0x35, 0x3F, 0x47, 0xD5, 0xFC,
  40880. 0xB9, 0xB7, 0xD6, 0x44, 0x6F, 0x1A, 0x72, 0x10,
  40881. 0xBB, 0xC6, 0x67, 0xFC, 0x41, 0x14, 0x15, 0xF2,
  40882. 0x3C, 0xD4, 0x0A, 0x2A, 0x3D, 0x64, 0x06, 0x1D,
  40883. 0x71, 0xC6, 0x71, 0x91, 0x57, 0x1A, 0x97, 0xD0,
  40884. 0x10, 0x88, 0xA2, 0x4B, 0x67, 0x11, 0x56, 0x7F,
  40885. 0xC8, 0x91, 0x06, 0x73, 0x2D, 0x88, 0x92, 0xFF,
  40886. 0x98, 0x5B, 0x8E, 0x6C, 0xF7, 0x01, 0x63, 0x82,
  40887. 0x9C, 0xC0, 0x85, 0xBE, 0x4E, 0x40, 0x83, 0x15,
  40888. 0x36, 0x1B, 0xB1, 0xB2, 0x00, 0x3D, 0x64, 0x13,
  40889. 0x22, 0x0B, 0x13, 0x45, 0x06, 0xD3, 0xC3, 0x04,
  40890. 0xC0, 0xBB, 0xBA, 0x9C, 0x9C, 0x45, 0xD3, 0x65,
  40891. 0x1E, 0x05, 0x71, 0xB6, 0xB1, 0x15, 0x17, 0x72,
  40892. 0x13, 0xD8, 0x59, 0x5E, 0x14, 0x3D, 0xB9, 0x0B,
  40893. 0xD7, 0x2F, 0x7E, 0xB9, 0x74, 0xD8, 0xD0, 0xA0,
  40894. 0x31, 0x74, 0x09, 0xD6, 0x4D, 0x58, 0x37, 0xEA,
  40895. 0xEC, 0x9B, 0x8D, 0x44, 0xDD, 0x7E, 0xCF, 0xF6,
  40896. 0xCD, 0xA9, 0xF7, 0x29, 0x38, 0x2A, 0x43, 0xB3,
  40897. 0x79, 0xCB, 0xDD, 0x43, 0xFF, 0xB1, 0x8A, 0xEA,
  40898. 0x35, 0xC1, 0xA9, 0x96, 0xCE, 0xF1, 0x48, 0x8D,
  40899. 0x3B, 0x7A, 0x81, 0xEE, 0x7C, 0xFC, 0x0B, 0x96,
  40900. 0x23, 0x41, 0x8A, 0xB3, 0x91, 0x9A, 0x6E, 0xDD,
  40901. 0xB9, 0x9F, 0x22, 0x2F, 0x0D, 0xDD, 0xB2, 0xF3,
  40902. 0x2A, 0x20, 0xC8, 0xF8, 0x4F, 0xBF, 0x4C, 0x49,
  40903. 0xB4, 0xCB, 0x3E, 0xB5, 0x0D, 0x9C, 0x4C, 0xD2,
  40904. 0x5A, 0x6F, 0x71, 0x75, 0x46, 0x70, 0x66, 0xD2,
  40905. 0x5E, 0x64, 0x37, 0xB6, 0x7F, 0x2D, 0xBC, 0x70,
  40906. 0xC2, 0xE6, 0xEB, 0x0B, 0xDE, 0x23, 0x86, 0xD0,
  40907. 0x30, 0x14, 0xA7, 0x89, 0xFB, 0x6D, 0xC0, 0x8E,
  40908. 0xE3, 0x3C, 0x0C, 0x67, 0x95, 0x1D, 0xA9, 0xD7,
  40909. 0x4B, 0x9C, 0x94, 0x84, 0x5D, 0x2A, 0x99, 0x03,
  40910. 0x7E, 0x09, 0x5F, 0xEF, 0x79, 0x19, 0x92, 0x0F,
  40911. 0xE5, 0x26, 0xEB, 0x5D, 0xD0, 0xBA, 0x1F, 0x97,
  40912. 0xDF, 0xBD, 0x2D, 0xDC, 0x31, 0x60, 0x9C, 0x1B,
  40913. 0x7B, 0x45, 0xEC, 0x3A, 0xDB, 0x58, 0x6F, 0xE3,
  40914. 0x03, 0x0A, 0x0C, 0x7A, 0x9D, 0xD0, 0x34, 0xA3,
  40915. 0xC2, 0xE6, 0xF9, 0x84, 0x90, 0x93, 0xCE, 0xE1,
  40916. 0x0A, 0x18, 0x19, 0x53, 0x54, 0x7F, 0x8B, 0xE3,
  40917. 0x28, 0x72, 0x0A, 0x4A, 0x5A, 0x82, 0x90, 0xB5,
  40918. 0xEE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  40919. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  40920. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
  40921. 0x0B, 0x10, 0x18, 0x1A, 0x21
  40922. };
  40923. #endif
  40924. #ifndef WOLFSSL_NO_ML_DSA_87
  40925. static const byte pk_87[] = {
  40926. 0x59, 0xB2, 0x37, 0x1F, 0xE7, 0xBA, 0xCC, 0x20,
  40927. 0x7F, 0xE1, 0xFE, 0xE8, 0x8A, 0x8B, 0x38, 0x05,
  40928. 0xA7, 0x05, 0x28, 0x65, 0x69, 0x17, 0x89, 0xBB,
  40929. 0x90, 0x54, 0x2F, 0xA4, 0x7F, 0x7E, 0xF2, 0xB7,
  40930. 0x5F, 0xCA, 0x13, 0xDB, 0xA5, 0x88, 0x8B, 0xEC,
  40931. 0x32, 0x05, 0x14, 0xDC, 0xB0, 0x5F, 0xD2, 0x6E,
  40932. 0xB5, 0x54, 0x1F, 0x6E, 0x57, 0x2E, 0xCE, 0xA6,
  40933. 0xC4, 0xF1, 0xD3, 0x8A, 0xA7, 0x02, 0x59, 0x09,
  40934. 0x4A, 0xA9, 0x45, 0xF1, 0x9F, 0xED, 0x0D, 0x98,
  40935. 0x0E, 0x65, 0xDB, 0xF6, 0x5D, 0xB8, 0x0F, 0x56,
  40936. 0x4F, 0xE2, 0x9D, 0x83, 0x6C, 0x54, 0x79, 0x28,
  40937. 0x8B, 0x55, 0xCF, 0x07, 0xF4, 0xE0, 0x01, 0x59,
  40938. 0xB6, 0x95, 0x5D, 0xAB, 0xDE, 0xCC, 0x8C, 0x4D,
  40939. 0x66, 0xAE, 0x68, 0x87, 0x28, 0xBA, 0x6D, 0x5C,
  40940. 0x04, 0x42, 0xF3, 0xC1, 0x23, 0x2C, 0x78, 0x2C,
  40941. 0x46, 0x5B, 0x9B, 0x7C, 0x50, 0x14, 0xB1, 0x46,
  40942. 0x40, 0x65, 0xCC, 0xD8, 0xA5, 0x6D, 0x6B, 0x1C,
  40943. 0x16, 0x51, 0x08, 0x69, 0xE0, 0x14, 0xE6, 0x93,
  40944. 0x39, 0x98, 0xEF, 0x72, 0x55, 0x20, 0xB4, 0x00,
  40945. 0x91, 0x3D, 0x93, 0xB0, 0xEC, 0x75, 0xE2, 0xFB,
  40946. 0x72, 0x5D, 0xC1, 0xAE, 0xC0, 0xC0, 0xCC, 0x73,
  40947. 0x43, 0xB9, 0xE5, 0x44, 0xBA, 0xA4, 0xD6, 0x79,
  40948. 0x86, 0x0E, 0x34, 0x7B, 0x2E, 0x94, 0x7D, 0x8D,
  40949. 0x24, 0x36, 0xF0, 0x92, 0x98, 0xA7, 0xBB, 0x83,
  40950. 0x36, 0xB9, 0xDE, 0x9C, 0xFD, 0x5C, 0xDB, 0xCD,
  40951. 0x91, 0xC7, 0x24, 0x92, 0x68, 0xCA, 0x03, 0xEF,
  40952. 0xAC, 0x27, 0x3A, 0xF5, 0x29, 0x68, 0xD5, 0x01,
  40953. 0x40, 0x6C, 0xD9, 0xC9, 0x61, 0x59, 0xD7, 0xC1,
  40954. 0x5A, 0xA2, 0x90, 0x03, 0x30, 0xC1, 0x18, 0x9C,
  40955. 0xFC, 0x2C, 0xD8, 0xB9, 0x12, 0xC4, 0x80, 0xE4,
  40956. 0x58, 0x29, 0x7E, 0xF1, 0x4D, 0xB6, 0x94, 0xA3,
  40957. 0xF1, 0xE7, 0x2C, 0x1D, 0xFA, 0x3A, 0x3D, 0x2A,
  40958. 0x8A, 0x69, 0xE0, 0x11, 0x60, 0x2B, 0x93, 0x02,
  40959. 0x0B, 0xAC, 0xD1, 0xC2, 0xF3, 0xAD, 0x06, 0xC9,
  40960. 0x5A, 0x7F, 0x36, 0xEB, 0xF5, 0x26, 0x1F, 0x6E,
  40961. 0xC1, 0x06, 0x81, 0x6B, 0xB3, 0x30, 0x3C, 0xC0,
  40962. 0x0B, 0xF4, 0xE8, 0x68, 0x8D, 0x2E, 0x85, 0x48,
  40963. 0xF1, 0x04, 0x90, 0xD9, 0xEB, 0x23, 0xC5, 0x67,
  40964. 0x93, 0xB3, 0x4B, 0x84, 0x06, 0xCB, 0xE4, 0x43,
  40965. 0xD8, 0x35, 0x6B, 0xCD, 0x0F, 0x4F, 0x61, 0xD0,
  40966. 0xD0, 0x17, 0xD5, 0x48, 0x31, 0xB9, 0xBA, 0x32,
  40967. 0x9F, 0x89, 0x48, 0xF2, 0x5C, 0x31, 0x22, 0xF9,
  40968. 0xDE, 0xDE, 0x8C, 0xEC, 0xBA, 0x51, 0x56, 0x9E,
  40969. 0xDF, 0xFF, 0x89, 0x5F, 0xA0, 0x20, 0x86, 0x2C,
  40970. 0x5D, 0xF7, 0x9F, 0x86, 0x40, 0x78, 0x48, 0x6B,
  40971. 0x5F, 0xB2, 0x28, 0xFD, 0x78, 0x9C, 0x35, 0xFD,
  40972. 0xE1, 0xC5, 0x4B, 0xFF, 0xBF, 0x4A, 0x02, 0x5A,
  40973. 0x7F, 0xE7, 0xD8, 0xC3, 0x49, 0x0A, 0x5D, 0x4E,
  40974. 0x62, 0xD0, 0x4F, 0x79, 0xF4, 0x18, 0x3C, 0xA6,
  40975. 0x83, 0x79, 0xF4, 0x64, 0x8B, 0xD5, 0xB2, 0x41,
  40976. 0x6D, 0xBE, 0x5B, 0x84, 0x5C, 0x9F, 0x4B, 0x7A,
  40977. 0x7E, 0x23, 0x39, 0xC0, 0x50, 0x6D, 0x58, 0x53,
  40978. 0x9E, 0xAE, 0xA9, 0x45, 0x1C, 0x9B, 0x2F, 0xE2,
  40979. 0xA1, 0x8C, 0x84, 0x9D, 0xCA, 0x7E, 0xED, 0x9D,
  40980. 0xAC, 0xC0, 0x58, 0xD0, 0x05, 0xFB, 0x73, 0x75,
  40981. 0xC4, 0xEF, 0x45, 0xB0, 0x01, 0x54, 0x3F, 0xC6,
  40982. 0x8E, 0x47, 0xDD, 0xB6, 0xD1, 0x4F, 0xF9, 0x37,
  40983. 0xD1, 0xAA, 0x0D, 0x4D, 0x74, 0x89, 0xDF, 0xFA,
  40984. 0x62, 0x10, 0x67, 0x9C, 0xCC, 0xEC, 0xF9, 0xB8,
  40985. 0x55, 0x1D, 0xCF, 0x68, 0x2D, 0x2A, 0xF1, 0xE5,
  40986. 0xBD, 0x86, 0x9F, 0x3E, 0x8D, 0x40, 0x0D, 0x5C,
  40987. 0x86, 0x1A, 0xE5, 0x1F, 0xE7, 0xEB, 0xBB, 0x54,
  40988. 0x57, 0xF2, 0xEA, 0xAF, 0xD0, 0x93, 0xA9, 0x59,
  40989. 0x8E, 0xC7, 0x21, 0xC6, 0x93, 0x27, 0xC5, 0x19,
  40990. 0x30, 0xF4, 0xB9, 0xFF, 0xB2, 0xAA, 0x7F, 0x1A,
  40991. 0x28, 0x43, 0x6B, 0x6D, 0x80, 0x8D, 0x75, 0x39,
  40992. 0x2B, 0xC4, 0x3C, 0x1B, 0x5B, 0x85, 0x9C, 0x66,
  40993. 0xC5, 0x4F, 0xA5, 0x15, 0xC7, 0xA6, 0x15, 0xA6,
  40994. 0x9E, 0x60, 0x92, 0x14, 0x34, 0xAA, 0x9C, 0xF9,
  40995. 0xF9, 0xE0, 0x3C, 0x3C, 0xA3, 0x5B, 0x5E, 0xBC,
  40996. 0x6A, 0x40, 0x9E, 0x82, 0x2F, 0xE7, 0x6E, 0x09,
  40997. 0x24, 0xC6, 0xC0, 0x62, 0xF1, 0x72, 0x4C, 0x38,
  40998. 0x2F, 0xF3, 0xC8, 0xAC, 0xB5, 0xC1, 0x66, 0x6C,
  40999. 0x2E, 0xC2, 0x6B, 0x76, 0x28, 0xE3, 0xD7, 0xC1,
  41000. 0x3D, 0xA8, 0xD7, 0x58, 0x89, 0x0E, 0x6C, 0xC0,
  41001. 0x17, 0xB7, 0x89, 0x25, 0x82, 0xE9, 0x5E, 0xDD,
  41002. 0x04, 0xBA, 0x93, 0x45, 0xDF, 0x70, 0xFA, 0xD5,
  41003. 0x6E, 0xA6, 0x8B, 0xF8, 0x87, 0x5B, 0x93, 0x2C,
  41004. 0x28, 0xB3, 0x28, 0x07, 0xC8, 0x63, 0x71, 0xE1,
  41005. 0x7D, 0xCC, 0x04, 0x72, 0x5C, 0xB5, 0x97, 0xB5,
  41006. 0x24, 0x46, 0x79, 0x63, 0xE1, 0xD4, 0xA6, 0x1B,
  41007. 0x5F, 0xBF, 0x9E, 0xC5, 0x04, 0xD5, 0xDD, 0xB6,
  41008. 0x17, 0x93, 0xDD, 0x4E, 0x34, 0xAE, 0x08, 0x2A,
  41009. 0x59, 0x90, 0xEF, 0xCE, 0x80, 0x1E, 0x93, 0x8C,
  41010. 0xCA, 0xE7, 0x38, 0xE0, 0x2E, 0x90, 0x59, 0x9D,
  41011. 0x97, 0x1C, 0x2D, 0x7C, 0x64, 0xE5, 0xB6, 0xF8,
  41012. 0x63, 0x9F, 0x75, 0x8E, 0xD6, 0x21, 0xC1, 0xF2,
  41013. 0x10, 0x73, 0xC0, 0x3E, 0xDB, 0x78, 0x2C, 0x7A,
  41014. 0x0F, 0x5D, 0x7C, 0x66, 0xF5, 0xCE, 0x16, 0x1D,
  41015. 0xED, 0x55, 0xB3, 0xE9, 0x2D, 0xC2, 0x71, 0x83,
  41016. 0xAB, 0x08, 0x3D, 0xBC, 0x1F, 0x39, 0x30, 0xAE,
  41017. 0x56, 0xED, 0xB8, 0xC5, 0x3E, 0x9A, 0x7E, 0x02,
  41018. 0x0F, 0xFF, 0x0C, 0x40, 0x42, 0xF5, 0x18, 0xB2,
  41019. 0x6F, 0x39, 0x0C, 0x96, 0xC8, 0x18, 0x3B, 0x79,
  41020. 0xB5, 0x3C, 0x7C, 0x7B, 0xC5, 0x15, 0x18, 0x7B,
  41021. 0x3D, 0xE8, 0xCA, 0xB0, 0x87, 0x69, 0xC5, 0xDD,
  41022. 0x6F, 0xF5, 0x49, 0x21, 0x12, 0xE8, 0xB0, 0xF2,
  41023. 0x8D, 0x09, 0xF4, 0x06, 0x7A, 0xDB, 0x04, 0x19,
  41024. 0x4F, 0x60, 0x25, 0x0E, 0x75, 0xAD, 0xE3, 0x31,
  41025. 0xA5, 0xC2, 0x55, 0x93, 0xBC, 0xD9, 0x2A, 0x6D,
  41026. 0x13, 0x50, 0x43, 0x95, 0x85, 0x86, 0x0B, 0xB6,
  41027. 0xFE, 0xED, 0xBD, 0x2F, 0x83, 0x9F, 0x31, 0x7A,
  41028. 0x01, 0x35, 0x88, 0x76, 0xC8, 0x8E, 0x89, 0x8A,
  41029. 0xC0, 0xC8, 0x53, 0x78, 0xF5, 0x72, 0xF2, 0x3C,
  41030. 0xDE, 0x93, 0x1D, 0x47, 0xDE, 0x71, 0xD3, 0x35,
  41031. 0x3D, 0xAB, 0x1F, 0x81, 0x0A, 0x61, 0xB1, 0x8D,
  41032. 0x24, 0xCD, 0x83, 0xDD, 0xAB, 0x8D, 0x53, 0xBA,
  41033. 0x9C, 0x7B, 0x82, 0x74, 0xB0, 0xFE, 0x82, 0xAF,
  41034. 0xF3, 0x0C, 0x57, 0x07, 0x2F, 0x64, 0x37, 0x87,
  41035. 0xCA, 0x1D, 0xF0, 0x3B, 0x99, 0xEB, 0x57, 0xDB,
  41036. 0xDA, 0x8C, 0x8E, 0xE8, 0xEB, 0x20, 0x1F, 0x28,
  41037. 0x47, 0xCB, 0xC9, 0xD3, 0x4F, 0xD8, 0x0C, 0xE6,
  41038. 0xBC, 0x5E, 0x1E, 0x32, 0x8E, 0xB6, 0xEF, 0xC8,
  41039. 0x3C, 0x4B, 0xD9, 0xD5, 0x2F, 0x32, 0x4E, 0x30,
  41040. 0xEE, 0x4B, 0x5E, 0x86, 0x35, 0x1E, 0x5C, 0x8C,
  41041. 0x4C, 0x54, 0x56, 0x83, 0x6D, 0x5A, 0x45, 0x22,
  41042. 0x03, 0xB3, 0xC3, 0x72, 0xC7, 0x87, 0xAE, 0x33,
  41043. 0x32, 0xC8, 0xA5, 0xE9, 0xDC, 0x21, 0x97, 0xD9,
  41044. 0xC3, 0x41, 0xB9, 0x75, 0x6B, 0xB1, 0xE6, 0x3C,
  41045. 0x75, 0xBB, 0xD5, 0xCF, 0x3E, 0x5C, 0xD4, 0xBF,
  41046. 0x47, 0xBD, 0x1F, 0xEB, 0xC3, 0xE3, 0x71, 0x09,
  41047. 0x12, 0xD6, 0x30, 0x32, 0xF6, 0xB9, 0x7D, 0xC1,
  41048. 0x9C, 0x4D, 0xE1, 0x96, 0xAC, 0xD9, 0x15, 0x77,
  41049. 0x15, 0xE2, 0xC1, 0x4E, 0x05, 0x4A, 0x93, 0x17,
  41050. 0xBF, 0x96, 0xA6, 0x84, 0xBB, 0x96, 0xCE, 0xFB,
  41051. 0x7D, 0x8F, 0xDC, 0xA8, 0xAA, 0x47, 0x7A, 0x2A,
  41052. 0xF6, 0xF7, 0x26, 0xD2, 0xCA, 0xC1, 0xA6, 0x03,
  41053. 0xCF, 0x13, 0x60, 0xEC, 0x11, 0xCA, 0x89, 0x7E,
  41054. 0x5B, 0xC7, 0x35, 0xAB, 0x69, 0xB8, 0x64, 0x7F,
  41055. 0x30, 0xCE, 0xD4, 0x94, 0x7B, 0xA9, 0xF6, 0x35,
  41056. 0xD9, 0xCB, 0x2D, 0x82, 0xA6, 0x62, 0xFF, 0x17,
  41057. 0xA0, 0xE1, 0x2D, 0x4D, 0x06, 0xD6, 0x41, 0xEE,
  41058. 0x76, 0xEB, 0x8B, 0x45, 0xC7, 0x1E, 0xDE, 0x38,
  41059. 0xC9, 0x05, 0xC5, 0x2B, 0xE7, 0x6C, 0x61, 0x09,
  41060. 0xF2, 0x61, 0x2F, 0xEE, 0x6C, 0x31, 0x94, 0x46,
  41061. 0x5C, 0x19, 0xBA, 0x5D, 0x3E, 0xBC, 0xF1, 0xF0,
  41062. 0xB5, 0xE5, 0x34, 0xE0, 0xF0, 0xF1, 0xD3, 0x1C,
  41063. 0xB1, 0xE7, 0xA3, 0x6C, 0x43, 0x03, 0xF2, 0x83,
  41064. 0xDB, 0xA8, 0x59, 0x1C, 0xC6, 0x09, 0x31, 0x1A,
  41065. 0x80, 0x9E, 0x44, 0x4E, 0x33, 0xA8, 0x93, 0x88,
  41066. 0x0C, 0xDB, 0xAE, 0x29, 0x11, 0x91, 0x46, 0xA3,
  41067. 0x68, 0xE4, 0xD2, 0xED, 0xD9, 0x1F, 0xE4, 0x71,
  41068. 0x64, 0x7F, 0xFE, 0x82, 0x1A, 0xA6, 0xD3, 0x1C,
  41069. 0x9F, 0xA4, 0x96, 0x95, 0xEB, 0x99, 0x41, 0xB0,
  41070. 0x8F, 0x7B, 0xE3, 0xF0, 0x6C, 0xDD, 0xF2, 0x73,
  41071. 0x9B, 0x8C, 0xAD, 0x2A, 0xB0, 0xDA, 0x4F, 0x5A,
  41072. 0x3C, 0x0A, 0x26, 0xDF, 0x6A, 0x17, 0xB1, 0x37,
  41073. 0xCA, 0xAB, 0x3B, 0x91, 0x9A, 0xB6, 0x36, 0xD6,
  41074. 0xC8, 0x9B, 0xED, 0xA3, 0x05, 0x88, 0x98, 0x62,
  41075. 0x87, 0x21, 0xF2, 0x77, 0x03, 0x15, 0xFE, 0xEE,
  41076. 0x88, 0x15, 0x95, 0xE2, 0x4C, 0xF4, 0x8B, 0x44,
  41077. 0x16, 0x60, 0xD0, 0xB2, 0xE9, 0xD5, 0xB9, 0x09,
  41078. 0x28, 0xC3, 0x81, 0xF2, 0xB0, 0xFA, 0x26, 0x34,
  41079. 0x2E, 0x4C, 0x9B, 0x88, 0xC0, 0x88, 0x7A, 0x46,
  41080. 0x87, 0x12, 0x4C, 0x01, 0x2D, 0x96, 0x9E, 0x1A,
  41081. 0xFD, 0x85, 0x32, 0x75, 0x4B, 0xA1, 0x21, 0x25,
  41082. 0xE9, 0x43, 0x3D, 0xCF, 0x6D, 0x7B, 0xC1, 0xA3,
  41083. 0x6A, 0x83, 0xE6, 0xA1, 0x0B, 0xA1, 0xCB, 0x76,
  41084. 0x52, 0xA8, 0x13, 0x50, 0x89, 0x9C, 0x2D, 0xFC,
  41085. 0x6E, 0x4F, 0xED, 0x38, 0xD0, 0x09, 0xE6, 0xD0,
  41086. 0xF1, 0xD4, 0x4C, 0xCC, 0xB9, 0x5E, 0x55, 0x1B,
  41087. 0x3A, 0xD5, 0x4B, 0x3A, 0xC8, 0x1E, 0x8B, 0xA4,
  41088. 0x66, 0x5E, 0xA4, 0x28, 0xB3, 0xC8, 0x61, 0xE8,
  41089. 0x67, 0x78, 0x90, 0xCF, 0x5F, 0x62, 0x5C, 0x19,
  41090. 0xA7, 0xC5, 0x94, 0x3A, 0x94, 0x01, 0xCB, 0x78,
  41091. 0xE7, 0x02, 0x6B, 0xAE, 0x92, 0xB6, 0x0A, 0x8B,
  41092. 0x68, 0x07, 0xC1, 0x77, 0x45, 0x41, 0x5C, 0xD8,
  41093. 0xE0, 0x30, 0xC6, 0x4C, 0x56, 0xE8, 0x22, 0x13,
  41094. 0x9A, 0x35, 0xDA, 0x42, 0x3F, 0x26, 0x43, 0x36,
  41095. 0xE0, 0xAF, 0xDF, 0x16, 0x74, 0x30, 0xDD, 0x36,
  41096. 0xE0, 0x06, 0x4B, 0x2F, 0x6E, 0x8D, 0x8B, 0xB6,
  41097. 0xBE, 0x99, 0xC5, 0xA9, 0xFB, 0x55, 0x1C, 0xC6,
  41098. 0x3E, 0x50, 0x8D, 0xB6, 0x36, 0x66, 0x7D, 0xDA,
  41099. 0x53, 0xF6, 0x11, 0xF0, 0x2F, 0xCD, 0x1F, 0x99,
  41100. 0x41, 0x0F, 0x1A, 0x7A, 0x82, 0x88, 0x2F, 0x96,
  41101. 0x23, 0xAD, 0xDC, 0x50, 0xEB, 0x01, 0xE1, 0xF3,
  41102. 0x99, 0x78, 0xBF, 0x68, 0x50, 0x6C, 0x71, 0xDB,
  41103. 0xBE, 0xE4, 0x2E, 0x4A, 0x80, 0x06, 0x9B, 0x0E,
  41104. 0x4C, 0x7F, 0xC4, 0xCC, 0x14, 0x71, 0xF4, 0xF1,
  41105. 0x02, 0x8D, 0xB2, 0x5C, 0x46, 0x87, 0xB6, 0x0D,
  41106. 0xF4, 0x25, 0x5D, 0xEC, 0x91, 0x48, 0x19, 0x7A,
  41107. 0x74, 0x79, 0x6E, 0xC7, 0x60, 0xA6, 0x6A, 0xFC,
  41108. 0x78, 0x84, 0x03, 0x86, 0x51, 0x92, 0x09, 0x73,
  41109. 0xA6, 0x9C, 0x20, 0x35, 0x16, 0x22, 0x26, 0x32,
  41110. 0xEC, 0x58, 0x75, 0xEA, 0x6D, 0x83, 0x80, 0x96,
  41111. 0xE7, 0xFE, 0x9B, 0x5B, 0x4F, 0xB6, 0x9C, 0x5E,
  41112. 0x94, 0x07, 0xE7, 0x0D, 0x27, 0xFA, 0x34, 0xB0,
  41113. 0xCD, 0xBD, 0x6E, 0x11, 0x9D, 0x87, 0xCE, 0x38,
  41114. 0x58, 0x1D, 0xF1, 0xD3, 0xE0, 0xDF, 0x3A, 0xE0,
  41115. 0x29, 0x04, 0x2A, 0x3B, 0x20, 0xE9, 0x23, 0xEB,
  41116. 0xCE, 0x19, 0xA4, 0x95, 0x87, 0x55, 0xEE, 0x2F,
  41117. 0x98, 0xFD, 0x23, 0x4C, 0x44, 0x13, 0xE2, 0xDB,
  41118. 0xC9, 0x35, 0x59, 0xA4, 0x28, 0xDC, 0x37, 0xF2,
  41119. 0xD1, 0x23, 0x5B, 0xD4, 0x41, 0x9B, 0x09, 0x9E,
  41120. 0x0F, 0x0D, 0xE5, 0x42, 0xC4, 0x69, 0x35, 0x99,
  41121. 0x1B, 0xE0, 0x69, 0x2A, 0x6D, 0x80, 0xB8, 0xFD,
  41122. 0x98, 0x86, 0xE0, 0xFA, 0x17, 0x69, 0xB4, 0x9E,
  41123. 0x8A, 0xE6, 0x30, 0x7C, 0xB0, 0xBC, 0x1B, 0x49,
  41124. 0x73, 0x2D, 0x26, 0xE2, 0x5C, 0xA1, 0xCD, 0x9D,
  41125. 0x40, 0x7E, 0x0D, 0x88, 0x64, 0x04, 0x09, 0x41,
  41126. 0x61, 0x1F, 0x93, 0x33, 0xB6, 0x36, 0x7E, 0x83,
  41127. 0x00, 0xFD, 0x64, 0x6A, 0xC5, 0xA7, 0x1A, 0xD9,
  41128. 0x13, 0xEE, 0xFD, 0x80, 0x8D, 0x5C, 0xAF, 0xBF,
  41129. 0x15, 0x21, 0xA3, 0x06, 0x2E, 0xC1, 0x84, 0xE5,
  41130. 0x21, 0x65, 0x50, 0x1E, 0x00, 0x55, 0x56, 0xDE,
  41131. 0x4D, 0xEE, 0x46, 0xF9, 0xE5, 0x3D, 0x7D, 0xEF,
  41132. 0x99, 0x09, 0xF3, 0xD5, 0xD9, 0x8C, 0xA8, 0x0D,
  41133. 0x87, 0x70, 0x7F, 0x7B, 0xC0, 0xFF, 0x8D, 0x87,
  41134. 0x9D, 0x65, 0xD4, 0xD7, 0x83, 0xD1, 0x96, 0xF2,
  41135. 0x46, 0x06, 0x93, 0x81, 0x1C, 0xDF, 0x33, 0x35,
  41136. 0x8E, 0x08, 0x2D, 0x81, 0xF4, 0xDB, 0x8F, 0x6C,
  41137. 0x20, 0x48, 0x61, 0x83, 0xA3, 0x6D, 0x4F, 0xBC,
  41138. 0xC8, 0xA1, 0xC6, 0xDA, 0x21, 0xAA, 0x4D, 0xD1,
  41139. 0x36, 0xE1, 0x9F, 0xEF, 0x2E, 0xA9, 0x93, 0x97,
  41140. 0x2B, 0xB9, 0x98, 0x9A, 0xC1, 0xC3, 0x8A, 0x79,
  41141. 0xF3, 0x18, 0x52, 0x17, 0x80, 0x04, 0x12, 0x3C,
  41142. 0x46, 0x27, 0x7D, 0x38, 0xA8, 0x8F, 0xC1, 0x58,
  41143. 0x9F, 0x25, 0x73, 0x32, 0x28, 0x4C, 0xD8, 0xA8,
  41144. 0x73, 0xC2, 0x5A, 0x1A, 0x6D, 0x40, 0x26, 0x5B,
  41145. 0x28, 0x5D, 0xF0, 0x93, 0x70, 0xE8, 0x8F, 0x72,
  41146. 0xFF, 0x70, 0xE4, 0x34, 0xE8, 0xF6, 0x60, 0x84,
  41147. 0xCC, 0xFE, 0xBD, 0xBB, 0xC4, 0xB9, 0x9E, 0xDF,
  41148. 0xBC, 0x75, 0x0C, 0xC5, 0xDE, 0xA6, 0x36, 0x17,
  41149. 0xF6, 0x47, 0xF5, 0xF0, 0x21, 0xD5, 0x7D, 0x64,
  41150. 0xD5, 0xEF, 0xF0, 0x48, 0x63, 0x4D, 0xB2, 0x20,
  41151. 0x9D, 0x7C, 0x8B, 0x82, 0xFB, 0x63, 0xB8, 0x82,
  41152. 0x3E, 0x4C, 0xA0, 0x57, 0x16, 0x8B, 0xAE, 0x88,
  41153. 0xD9, 0x71, 0x52, 0x91, 0x24, 0x0B, 0x37, 0x58,
  41154. 0xD7, 0x68, 0x45, 0x01, 0xF8, 0x61, 0x86, 0x7B,
  41155. 0x7A, 0x24, 0x1C, 0x06, 0x3B, 0x05, 0xD5, 0xE8,
  41156. 0xCA, 0x6B, 0x4C, 0x79, 0xCB, 0x24, 0x35, 0xD7,
  41157. 0xF9, 0x94, 0xCB, 0x76, 0x91, 0x5B, 0x4A, 0x54,
  41158. 0x87, 0x08, 0xB1, 0x1B, 0x29, 0x44, 0x96, 0x85,
  41159. 0x94, 0x1D, 0x43, 0xE6, 0x0A, 0x89, 0x76, 0xF9,
  41160. 0xA9, 0x60, 0x72, 0xF9, 0x10, 0x41, 0xF4, 0xC3,
  41161. 0xDF, 0x7C, 0x73, 0x96, 0x90, 0x12, 0xAE, 0x1B,
  41162. 0x30, 0xE4, 0xB9, 0xC4, 0xE1, 0x33, 0x55, 0x8D,
  41163. 0xAB, 0xC4, 0x6C, 0x10, 0x3C, 0x0C, 0xB1, 0xDF,
  41164. 0xB9, 0x9B, 0x58, 0x53, 0x74, 0xA5, 0x4F, 0x9B,
  41165. 0xA5, 0x6B, 0x72, 0x48, 0xB8, 0xC3, 0xF6, 0x6F,
  41166. 0x1D, 0x55, 0x76, 0x0D, 0x6A, 0xBB, 0x43, 0x03,
  41167. 0x75, 0x77, 0x4D, 0xFB, 0xA2, 0x05, 0x9C, 0x5D,
  41168. 0xDD, 0xB6, 0x59, 0xFD, 0x2E, 0x1D, 0xA9, 0xC3,
  41169. 0xF0, 0xB8, 0x08, 0x68, 0xC9, 0x2B, 0xCA, 0xC1,
  41170. 0x04, 0x03, 0xDC, 0xD1, 0x40, 0xD6, 0xA3, 0xD3,
  41171. 0xF3, 0x5F, 0x8E, 0xF1, 0xA2, 0xDD, 0x98, 0xDE,
  41172. 0x1A, 0x43, 0x34, 0x23, 0x85, 0x99, 0xED, 0xAD,
  41173. 0x92, 0x0D, 0xC0, 0xAA, 0x69, 0x8E, 0x9F, 0xE6,
  41174. 0x10, 0x6A, 0x07, 0x80, 0xC9, 0xC2, 0x45, 0xF2,
  41175. 0xC6, 0x5A, 0x0C, 0x3E, 0x5C, 0xD5, 0x36, 0x61,
  41176. 0x10, 0xB1, 0x76, 0x0F, 0xCD, 0x41, 0x4D, 0x45,
  41177. 0x0D, 0xB9, 0xD7, 0x6A, 0x22, 0xA9, 0xEA, 0xEA,
  41178. 0x0C, 0x9F, 0xB7, 0x2E, 0xD5, 0x43, 0xCE, 0x9F,
  41179. 0xA3, 0x31, 0x4B, 0xAB, 0x17, 0x68, 0x7E, 0x9D,
  41180. 0xE5, 0xAD, 0xAD, 0x75, 0x61, 0xF1, 0xA5, 0xBE,
  41181. 0xC1, 0x63, 0x39, 0x26, 0x9A, 0x87, 0xE0, 0x9A,
  41182. 0xCB, 0x29, 0xE4, 0xC4, 0x39, 0x60, 0x5E, 0x95,
  41183. 0x72, 0xAA, 0x9B, 0x7D, 0x0E, 0x83, 0x71, 0xA3,
  41184. 0x0E, 0x41, 0xA0, 0xA7, 0xBD, 0xC0, 0x2D, 0xA3,
  41185. 0xA6, 0x12, 0x1B, 0xF2, 0x61, 0xEA, 0xA0, 0x16,
  41186. 0xA2, 0x07, 0x4E, 0x44, 0x32, 0xCF, 0x63, 0xAF,
  41187. 0x96, 0xBE, 0x81, 0xCE, 0xB6, 0xE0, 0xC2, 0x67,
  41188. 0x6A, 0x85, 0x45, 0xC6, 0x6D, 0x2F, 0x30, 0xC9,
  41189. 0x8B, 0x54, 0x24, 0xF0, 0xFE, 0xF0, 0x4B, 0x3C,
  41190. 0x6C, 0x70, 0x64, 0xE2, 0xD2, 0xE1, 0x1C, 0xBE,
  41191. 0x60, 0xF8, 0x57, 0x23, 0xFF, 0xC0, 0xB7, 0x70,
  41192. 0xD6, 0x86, 0x6F, 0xFA, 0x58, 0x9E, 0x3F, 0x9B,
  41193. 0x2A, 0xBF, 0x75, 0x10, 0x40, 0x19, 0xAA, 0x69,
  41194. 0xCB, 0x58, 0x89, 0x5B, 0x47, 0x4A, 0x0A, 0xDE,
  41195. 0x2B, 0x60, 0xA4, 0xAB, 0x07, 0x7C, 0x3A, 0x6D,
  41196. 0xF6, 0x15, 0x33, 0x4E, 0xBB, 0xE7, 0x32, 0xE9,
  41197. 0x52, 0x20, 0x21, 0x39, 0x94, 0xD3, 0xBD, 0xC4,
  41198. 0x43, 0xC8, 0xEF, 0x94, 0xAD, 0x51, 0x5F, 0x45,
  41199. 0x41, 0x83, 0x55, 0x18, 0x33, 0x14, 0x48, 0x58,
  41200. 0x57, 0xAC, 0x12, 0xBA, 0x1D, 0x62, 0xCF, 0x4F,
  41201. 0xD4, 0xF4, 0xDE, 0x2A, 0x7F, 0xFF, 0x1E, 0xCF,
  41202. 0x0D, 0x29, 0x0C, 0x4C, 0xDF, 0xFA, 0x88, 0xD8,
  41203. 0xF4, 0x8C, 0x5B, 0x83, 0x7D, 0x3A, 0x94, 0xCD,
  41204. 0x17, 0xB3, 0xD1, 0x69, 0x96, 0x6E, 0xB0, 0x38,
  41205. 0xFE, 0x5A, 0x6E, 0x85, 0xDF, 0xC6, 0x0A, 0x00,
  41206. 0x23, 0x3F, 0x10, 0x73, 0x19, 0x73, 0xDC, 0x47,
  41207. 0x5D, 0x53, 0xBC, 0x7B, 0x9E, 0x60, 0x32, 0x0B,
  41208. 0xA7, 0x90, 0x5D, 0x88, 0x51, 0x9F, 0xA3, 0x25,
  41209. 0xDF, 0x5A, 0xB0, 0x2B, 0x40, 0xF2, 0xAB, 0xBD,
  41210. 0xB3, 0x7D, 0x22, 0x61, 0xCB, 0x81, 0x48, 0x27,
  41211. 0x7B, 0x87, 0xAE, 0x32, 0x97, 0x97, 0x6C, 0x80,
  41212. 0xC3, 0x51, 0x34, 0xE5, 0xF7, 0x86, 0x90, 0x45,
  41213. 0x64, 0xC1, 0x46, 0x99, 0x47, 0xF6, 0x20, 0xFE,
  41214. 0x09, 0xFD, 0xF3, 0x86, 0x2C, 0x40, 0x57, 0xA3,
  41215. 0xBC, 0xEF, 0x70, 0x75, 0x0C, 0xB7, 0x27, 0xF0,
  41216. 0x31, 0x28, 0x3A, 0x18, 0x26, 0xF1, 0x38, 0x1B,
  41217. 0x33, 0x48, 0xE3, 0xEA, 0x46, 0x88, 0x60, 0x9E,
  41218. 0xCB, 0x19, 0x3A, 0xFA, 0xAE, 0xE1, 0xCD, 0x97,
  41219. 0xE4, 0xDD, 0xAA, 0x02, 0xC0, 0xC3, 0x0E, 0x49,
  41220. 0xF1, 0x37, 0xD0, 0x82, 0x85, 0x94, 0x15, 0x28,
  41221. 0x10, 0x17, 0x59, 0xA7, 0x42, 0x2A, 0xA4, 0x99,
  41222. 0xC9, 0x00, 0xA3, 0x79, 0xDD, 0x73, 0xB3, 0x07,
  41223. 0x28, 0x4C, 0xCD, 0xDA, 0xF1, 0xFA, 0x1B, 0x0C,
  41224. 0x4B, 0x28, 0x0E, 0x3F, 0x9F, 0x1D, 0xB6, 0xD3,
  41225. 0x8E, 0xCF, 0x8A, 0x84, 0x1F, 0x9D, 0x4E, 0x40,
  41226. 0xEC, 0xA8, 0x62, 0x47, 0xD6, 0xCD, 0x9B, 0x31,
  41227. 0xEA, 0xCD, 0x6A, 0x46, 0xF0, 0xE3, 0x33, 0xB9,
  41228. 0xE8, 0x3D, 0x69, 0x0D, 0x7E, 0x13, 0x46, 0x76,
  41229. 0x19, 0xB4, 0x6A, 0xF9, 0xAF, 0xCF, 0xDC, 0x4A,
  41230. 0xA9, 0xA0, 0x49, 0xB1, 0x80, 0x26, 0x0D, 0x70,
  41231. 0xD9, 0xEE, 0xDB, 0x8A, 0x53, 0x30, 0x51, 0xAB,
  41232. 0x83, 0x51, 0x7A, 0xAD, 0xC2, 0xCD, 0x90, 0x0B,
  41233. 0x3E, 0xA5, 0x12, 0x60, 0xF4, 0x64, 0xAF, 0xC5,
  41234. 0xD2, 0xDC, 0x41, 0x10, 0x29, 0x77, 0x9B, 0x21,
  41235. 0xCE, 0x2C, 0xBD, 0x16, 0x02, 0x18, 0xDF, 0x41,
  41236. 0xF6, 0x61, 0xDA, 0x1A, 0xD9, 0x5A, 0xD4, 0x0B,
  41237. 0x8C, 0x35, 0x3C, 0x7F, 0x10, 0xFC, 0x23, 0xF8,
  41238. 0x30, 0xD1, 0x17, 0xBC, 0xAE, 0xF8, 0xCE, 0xCE,
  41239. 0xBC, 0xBF, 0xA4, 0x9D, 0x79, 0xD8, 0xD9, 0x39,
  41240. 0x1E, 0x8D, 0x08, 0x28, 0x1F, 0x00, 0x0A, 0x55,
  41241. 0xE9, 0x2D, 0xB3, 0x31, 0xBD, 0xEC, 0xD7, 0x31,
  41242. 0x83, 0xE0, 0x58, 0xFF, 0x3F, 0xE5, 0x83, 0x9A,
  41243. 0xF5, 0x0D, 0x8C, 0x55, 0xF2, 0x2F, 0x6A, 0xFF,
  41244. 0x5A, 0x33, 0xDA, 0x77, 0x4B, 0xA1, 0xB3, 0xE6,
  41245. 0x43, 0xF5, 0x87, 0x7C, 0xF5, 0x49, 0xC4, 0xF9,
  41246. 0x08, 0xEA, 0x64, 0xA3, 0x7D, 0xF3, 0xBF, 0xA4,
  41247. 0xCD, 0x5F, 0x70, 0xF8, 0xCD, 0x15, 0x44, 0x76,
  41248. 0xD3, 0x4B, 0xC8, 0x53, 0xC9, 0xE8, 0xF7, 0x97,
  41249. 0x9E, 0x5F, 0x4E, 0xBB, 0x88, 0x8A, 0xF7, 0x61
  41250. };
  41251. static const byte msg_87[] = {
  41252. 0x4A, 0xC4, 0x67, 0x5C, 0x96, 0xD9, 0x11, 0x7D,
  41253. 0x1E, 0xDE, 0xB8, 0x0D, 0x7C, 0xD2, 0x84, 0xA3,
  41254. 0xE1, 0xE1, 0xFE, 0x03, 0x8E, 0x30, 0x12, 0x05,
  41255. 0xB4, 0xC4, 0x08, 0xEB, 0x96, 0x52, 0x35, 0xAD,
  41256. 0x1C, 0x85, 0xF8, 0xBE, 0x3F, 0x77, 0xCA, 0x48,
  41257. 0x6F, 0xD2, 0x07, 0xF7, 0xC7, 0x5F, 0x41, 0x21,
  41258. 0xCD, 0x3C, 0xA2, 0xB2, 0x3D, 0x6B, 0xCE, 0x43,
  41259. 0x82, 0xA6, 0xD3, 0x61, 0x21, 0x81, 0x50, 0x25,
  41260. 0xD5, 0x80, 0x6C, 0xBE, 0xF4, 0x52, 0xE0, 0x83,
  41261. 0x93, 0x3C, 0x6E, 0x5C, 0x73, 0x94, 0xAC, 0x88,
  41262. 0x26, 0x2A, 0x6D, 0xE7, 0x77, 0x0B, 0x2D, 0x88,
  41263. 0x43, 0xEC, 0x10, 0x1F, 0xFB, 0x5E, 0x84, 0xDE,
  41264. 0x2F, 0x7A, 0x8B, 0x74, 0xE7, 0x67, 0x4B, 0x3B,
  41265. 0x23, 0x19, 0xBD, 0x6B, 0xF4, 0x11, 0x2F, 0x92,
  41266. 0xC5, 0xCF, 0xC0, 0xA5, 0x5F, 0x7F, 0xA0, 0x61,
  41267. 0xF4, 0x53, 0x25, 0x40, 0x8D, 0x03, 0x9D, 0x51
  41268. };
  41269. static const byte sig_87[] = {
  41270. 0x4B, 0x3F, 0x52, 0xF0, 0x81, 0xB3, 0xD9, 0x14,
  41271. 0xBC, 0x7C, 0x6C, 0x07, 0x3B, 0x18, 0x2B, 0x26,
  41272. 0x8A, 0xDF, 0x51, 0x89, 0xE2, 0x98, 0xA8, 0x69,
  41273. 0xBF, 0xB9, 0x91, 0xB1, 0x99, 0x99, 0x3C, 0x10,
  41274. 0x42, 0xDE, 0xF5, 0xB5, 0x92, 0x70, 0xB6, 0xCD,
  41275. 0x3F, 0xF8, 0xF9, 0x07, 0xA1, 0xCB, 0x0D, 0x3B,
  41276. 0x6F, 0xED, 0xCA, 0x14, 0x38, 0x38, 0xF8, 0xF8,
  41277. 0x1E, 0x0C, 0x37, 0x0F, 0xFE, 0xEE, 0x6B, 0x25,
  41278. 0xCD, 0x07, 0x03, 0x56, 0x41, 0xA0, 0x51, 0x94,
  41279. 0x4E, 0xAB, 0x51, 0x6C, 0xFB, 0xB8, 0x01, 0x53,
  41280. 0x6B, 0x4F, 0x26, 0x2B, 0x16, 0x19, 0x8E, 0x7D,
  41281. 0xDB, 0x1D, 0x61, 0xC3, 0x5A, 0x64, 0xD9, 0x0D,
  41282. 0x39, 0x48, 0xCE, 0xAA, 0xC8, 0xEE, 0x58, 0x0D,
  41283. 0xCE, 0xF5, 0x40, 0xED, 0x99, 0xD9, 0x12, 0xBB,
  41284. 0xA2, 0xBC, 0x4F, 0x51, 0x45, 0xBB, 0x94, 0x9C,
  41285. 0x73, 0xCC, 0xBD, 0x58, 0x26, 0x13, 0xB1, 0x0E,
  41286. 0xAA, 0xE8, 0x63, 0xAC, 0xA3, 0x46, 0x83, 0xEB,
  41287. 0x92, 0x2B, 0x3D, 0xAD, 0xFC, 0x74, 0xF7, 0x6F,
  41288. 0x47, 0xE4, 0x97, 0x86, 0x02, 0x59, 0x24, 0x02,
  41289. 0xD9, 0x15, 0x43, 0x94, 0xEB, 0x09, 0xFB, 0xC2,
  41290. 0xEB, 0xCC, 0xC5, 0x94, 0x73, 0x2F, 0x2D, 0x8B,
  41291. 0xC3, 0x83, 0x50, 0xE5, 0x53, 0x5A, 0x44, 0x12,
  41292. 0xA7, 0x7A, 0xDD, 0x79, 0x16, 0x60, 0x45, 0x76,
  41293. 0xFD, 0x6A, 0x36, 0x31, 0xE5, 0x15, 0xBA, 0xF2,
  41294. 0x6A, 0x6F, 0x9C, 0xA4, 0x06, 0x1E, 0xBB, 0xDD,
  41295. 0x3B, 0xEC, 0x71, 0x79, 0xAD, 0x58, 0x55, 0x2A,
  41296. 0x5B, 0x50, 0x8F, 0x31, 0x34, 0x8A, 0x56, 0xAD,
  41297. 0x1A, 0xDA, 0x7A, 0x05, 0x35, 0x2C, 0x72, 0xC0,
  41298. 0x04, 0xB9, 0x4C, 0x47, 0xE7, 0x04, 0x9A, 0x10,
  41299. 0xB3, 0xA5, 0x9B, 0xF2, 0x38, 0xA8, 0xDF, 0xC6,
  41300. 0xC7, 0x01, 0x9A, 0x17, 0xF0, 0x5D, 0x5B, 0xFC,
  41301. 0xB9, 0xD9, 0x3D, 0x9D, 0x1C, 0xCB, 0xCB, 0x47,
  41302. 0xF8, 0xC4, 0x38, 0x09, 0x8F, 0xDB, 0xDF, 0xE2,
  41303. 0x3F, 0x9F, 0x78, 0xBC, 0x28, 0x06, 0x99, 0x08,
  41304. 0xC6, 0xB9, 0x89, 0x8B, 0x43, 0x4C, 0xBF, 0x37,
  41305. 0x78, 0x7E, 0x1A, 0xF6, 0xA6, 0xB8, 0x27, 0xE8,
  41306. 0x30, 0xE9, 0xF7, 0x62, 0x9C, 0xD8, 0xF5, 0x10,
  41307. 0x70, 0xC4, 0xC8, 0xA8, 0xDE, 0xB2, 0x60, 0xD0,
  41308. 0x7C, 0x3E, 0x41, 0xD8, 0x49, 0x04, 0x84, 0x87,
  41309. 0x74, 0x91, 0xB3, 0x9A, 0xA6, 0xD9, 0xE1, 0x0D,
  41310. 0x91, 0x74, 0x8B, 0x64, 0xE3, 0x31, 0x60, 0x62,
  41311. 0x9D, 0x8A, 0xE4, 0x3E, 0xFD, 0x5F, 0x85, 0x78,
  41312. 0x1E, 0x69, 0xF7, 0x6B, 0x68, 0x95, 0xC1, 0x41,
  41313. 0xEB, 0xCD, 0xDF, 0xEE, 0xB4, 0x85, 0xA0, 0x0B,
  41314. 0xDB, 0xA4, 0xF7, 0xC9, 0x91, 0xF5, 0x3F, 0x2F,
  41315. 0x84, 0x93, 0x39, 0x26, 0xAF, 0x39, 0xE6, 0x96,
  41316. 0x4A, 0xBF, 0x2D, 0xFE, 0xBB, 0xC1, 0x9A, 0x7E,
  41317. 0x31, 0xC5, 0x07, 0x97, 0xB8, 0xDA, 0x29, 0x31,
  41318. 0xE1, 0x0F, 0x3D, 0xAC, 0x49, 0x3F, 0x19, 0x8D,
  41319. 0xFD, 0x78, 0x5D, 0x21, 0xAD, 0xB2, 0xC0, 0x62,
  41320. 0xB0, 0x97, 0xE8, 0x89, 0xA2, 0x07, 0x37, 0xF1,
  41321. 0x86, 0x00, 0x8F, 0x29, 0x28, 0xF6, 0xB8, 0x4D,
  41322. 0x6E, 0x09, 0xE9, 0x75, 0xA8, 0xF2, 0xAA, 0xAD,
  41323. 0xC7, 0x85, 0x23, 0x42, 0x34, 0xFD, 0xA0, 0x37,
  41324. 0x03, 0xA7, 0xC2, 0x1F, 0x81, 0x2D, 0x65, 0x0B,
  41325. 0xD2, 0x51, 0x0B, 0x30, 0xF0, 0x55, 0x00, 0x81,
  41326. 0x04, 0x7A, 0x15, 0x5C, 0x84, 0x85, 0x86, 0xA9,
  41327. 0x6F, 0x10, 0x0D, 0x77, 0x4F, 0x3E, 0x39, 0xE0,
  41328. 0x29, 0xB0, 0x77, 0x7C, 0xD3, 0x3E, 0x68, 0x31,
  41329. 0x8A, 0x11, 0xC1, 0x98, 0x02, 0x93, 0xFA, 0xD3,
  41330. 0xE7, 0x87, 0xD2, 0x0D, 0xFE, 0x7E, 0xEE, 0x70,
  41331. 0x53, 0xC0, 0x5E, 0xEB, 0x6A, 0x15, 0x9B, 0xAA,
  41332. 0xD4, 0x02, 0x0B, 0x9E, 0xC3, 0xF5, 0x37, 0xDA,
  41333. 0x4D, 0xAD, 0xAF, 0xB3, 0xB1, 0xBB, 0x1D, 0xBE,
  41334. 0xB2, 0xD5, 0xB8, 0xF9, 0xD0, 0x5A, 0x01, 0x97,
  41335. 0x98, 0xEA, 0xE0, 0xED, 0x09, 0x9D, 0xB0, 0x66,
  41336. 0xD7, 0x3E, 0xE8, 0xE9, 0xA5, 0x6D, 0xE3, 0x68,
  41337. 0xE8, 0x78, 0xA7, 0xFF, 0x39, 0x14, 0x0D, 0x80,
  41338. 0x21, 0xD5, 0x00, 0x85, 0xE6, 0x25, 0x29, 0x41,
  41339. 0xAB, 0x31, 0x53, 0x09, 0xCB, 0x53, 0xAA, 0xA4,
  41340. 0x9E, 0x86, 0x34, 0x7F, 0xBA, 0xD5, 0x4A, 0x1F,
  41341. 0x87, 0x3E, 0x0C, 0xB4, 0xB8, 0x6A, 0x8D, 0x5B,
  41342. 0x1B, 0x2A, 0x95, 0xD4, 0x85, 0xF3, 0x7A, 0x9F,
  41343. 0xB6, 0x10, 0x5D, 0xF8, 0x44, 0x0F, 0xDB, 0x85,
  41344. 0x78, 0xF2, 0x62, 0x4C, 0x07, 0x93, 0x29, 0x56,
  41345. 0x9A, 0x75, 0xF3, 0x6F, 0x2C, 0x55, 0xD8, 0xD0,
  41346. 0x30, 0xFB, 0xFE, 0xAA, 0x88, 0x89, 0xAD, 0x74,
  41347. 0x6C, 0x32, 0x3B, 0x1A, 0xC4, 0xEC, 0x8C, 0x40,
  41348. 0x3E, 0x77, 0x5A, 0x6F, 0xBE, 0x59, 0x6E, 0x7E,
  41349. 0x6A, 0x5A, 0x28, 0x63, 0x57, 0x66, 0x25, 0x14,
  41350. 0x99, 0x40, 0x97, 0x6F, 0x7C, 0xC9, 0x36, 0x17,
  41351. 0xB4, 0x3F, 0xB1, 0x34, 0x89, 0x07, 0x4E, 0xCA,
  41352. 0xC5, 0xBE, 0xB1, 0xA4, 0xDF, 0xE5, 0x8B, 0x9A,
  41353. 0xD2, 0xE0, 0xC6, 0xA1, 0x5B, 0x76, 0xA7, 0xC2,
  41354. 0xD2, 0x08, 0x72, 0x5A, 0x31, 0x23, 0xCA, 0x4E,
  41355. 0x6F, 0x2C, 0x58, 0x47, 0xEE, 0x5F, 0xA8, 0x38,
  41356. 0x49, 0x19, 0xEF, 0x89, 0x01, 0x1D, 0x21, 0x9B,
  41357. 0x25, 0x7B, 0x3E, 0x4D, 0xC4, 0xF2, 0x09, 0x51,
  41358. 0x60, 0x84, 0x4C, 0xAE, 0xEA, 0xFC, 0xF8, 0x57,
  41359. 0x26, 0x0F, 0x1C, 0x63, 0xD3, 0xB0, 0x5A, 0x67,
  41360. 0xD3, 0xD0, 0xF2, 0xB0, 0xEC, 0x9D, 0xCC, 0x27,
  41361. 0x23, 0xF1, 0x37, 0x55, 0x75, 0x0B, 0xAE, 0x62,
  41362. 0xFC, 0xC3, 0x61, 0xCF, 0xB5, 0x84, 0xF7, 0x74,
  41363. 0xC0, 0x9A, 0xDF, 0x9A, 0x04, 0x31, 0xB2, 0x3E,
  41364. 0x48, 0x8C, 0x35, 0x9C, 0x0A, 0xEF, 0x5B, 0x1C,
  41365. 0x97, 0x87, 0xBD, 0x8F, 0x52, 0xB0, 0x83, 0xBC,
  41366. 0x9D, 0xBC, 0xC9, 0xB3, 0x03, 0x9F, 0x77, 0x7C,
  41367. 0x7E, 0x8E, 0xAB, 0xC8, 0x00, 0x78, 0x05, 0x0C,
  41368. 0xE6, 0xD4, 0x9C, 0x3B, 0xB7, 0x01, 0x68, 0xFA,
  41369. 0x21, 0x77, 0x29, 0x8F, 0xB0, 0xA8, 0xF7, 0x2C,
  41370. 0x1C, 0xD2, 0x8D, 0x66, 0x2A, 0x07, 0xDA, 0xE6,
  41371. 0xC7, 0xAC, 0xB7, 0xFB, 0x8E, 0x7F, 0xDD, 0x01,
  41372. 0xDF, 0xB2, 0x7C, 0x62, 0xEE, 0x68, 0x3F, 0x4E,
  41373. 0x5F, 0x88, 0xC7, 0xC1, 0xDD, 0xDD, 0x5E, 0xEC,
  41374. 0xC1, 0xC3, 0xAF, 0x85, 0x3F, 0x1F, 0xF6, 0xB1,
  41375. 0xD9, 0xDE, 0x67, 0x2F, 0x1B, 0xF6, 0x47, 0x3A,
  41376. 0xF0, 0x02, 0x1D, 0x8A, 0x3D, 0x4D, 0xD0, 0x4A,
  41377. 0x2F, 0xCA, 0x23, 0x25, 0xC7, 0x21, 0xCF, 0x1C,
  41378. 0x82, 0x16, 0x76, 0xD0, 0xA0, 0xD5, 0x74, 0x18,
  41379. 0x66, 0x25, 0xDE, 0x83, 0x1C, 0x84, 0x11, 0xF6,
  41380. 0x41, 0x79, 0xF9, 0x16, 0x7F, 0x78, 0xBC, 0xB2,
  41381. 0x2F, 0xB4, 0x1C, 0x2C, 0xDB, 0x63, 0xC4, 0xDB,
  41382. 0x5E, 0x13, 0x87, 0x66, 0xD3, 0x80, 0x35, 0x89,
  41383. 0x59, 0x8F, 0x11, 0x4F, 0x41, 0xBA, 0x42, 0xCD,
  41384. 0xB1, 0x34, 0x10, 0x20, 0x44, 0x9B, 0xA9, 0x96,
  41385. 0x56, 0x11, 0x39, 0x90, 0xB4, 0xE0, 0x22, 0xD8,
  41386. 0xDA, 0x20, 0xD7, 0x44, 0x49, 0x1C, 0x6E, 0xEA,
  41387. 0xB6, 0x7B, 0x91, 0x8E, 0x80, 0xFF, 0xF3, 0x43,
  41388. 0xCC, 0x5B, 0x4C, 0x8E, 0x58, 0xC3, 0x48, 0x4B,
  41389. 0x01, 0x25, 0xA6, 0x0C, 0x36, 0xAE, 0xF7, 0x63,
  41390. 0x89, 0x4D, 0x35, 0x14, 0x8B, 0x57, 0x8F, 0x41,
  41391. 0x7C, 0x3A, 0x98, 0xA1, 0x43, 0xED, 0xFE, 0x9F,
  41392. 0x8C, 0x95, 0xBC, 0xC3, 0x46, 0xC6, 0xF5, 0xEA,
  41393. 0xF9, 0x7A, 0xAD, 0x11, 0xDA, 0xE0, 0x1C, 0x47,
  41394. 0x7C, 0x22, 0x7A, 0x88, 0xD1, 0x0E, 0xCF, 0xDC,
  41395. 0xF4, 0x50, 0xB3, 0x7F, 0x88, 0x19, 0x68, 0x02,
  41396. 0x78, 0x49, 0xD9, 0xB4, 0x3E, 0x2B, 0xFF, 0x90,
  41397. 0xC6, 0xA3, 0x4A, 0xE4, 0x1B, 0x8B, 0xBD, 0x74,
  41398. 0x30, 0x83, 0xD3, 0xC5, 0x87, 0x86, 0xB0, 0x36,
  41399. 0x67, 0x1C, 0xD6, 0xEE, 0xD9, 0x4D, 0xAE, 0x51,
  41400. 0xF7, 0x61, 0x32, 0x47, 0xEF, 0x86, 0x07, 0xAC,
  41401. 0xF7, 0x4A, 0x3C, 0xCE, 0x93, 0x2F, 0x1C, 0x38,
  41402. 0x69, 0xBD, 0xB3, 0x5C, 0xA1, 0x7F, 0xC6, 0xBA,
  41403. 0x9F, 0x9C, 0x95, 0x6F, 0xF1, 0xD4, 0xD8, 0x80,
  41404. 0x94, 0x32, 0x5C, 0xAB, 0xCE, 0x41, 0x23, 0x3F,
  41405. 0xB1, 0xD8, 0x08, 0xEF, 0x41, 0x01, 0x03, 0x96,
  41406. 0xDE, 0xB0, 0xEC, 0xF5, 0x07, 0x34, 0xD8, 0x18,
  41407. 0xDD, 0xAB, 0x70, 0x01, 0x5A, 0x0A, 0xBD, 0xD1,
  41408. 0x92, 0x6D, 0xFA, 0x49, 0x1F, 0x71, 0x1A, 0xA8,
  41409. 0x5D, 0xA2, 0xA8, 0xEC, 0x60, 0xE3, 0x25, 0x5C,
  41410. 0xCF, 0x97, 0x5C, 0x23, 0xCC, 0x4E, 0x8D, 0xAF,
  41411. 0xDD, 0xED, 0x9F, 0xEC, 0x60, 0xA6, 0x46, 0x7C,
  41412. 0x45, 0xB0, 0x3C, 0xA4, 0x76, 0x49, 0x9A, 0xA3,
  41413. 0x31, 0xB0, 0xE3, 0x99, 0x95, 0x76, 0xCE, 0xC3,
  41414. 0x19, 0x1A, 0x9A, 0x62, 0xBC, 0x1B, 0xEA, 0xC1,
  41415. 0xEA, 0xF2, 0x0E, 0x18, 0xCF, 0xC3, 0x21, 0x61,
  41416. 0x27, 0xDE, 0x4A, 0xAE, 0x2E, 0x75, 0x20, 0x1F,
  41417. 0x9E, 0x42, 0x7E, 0x39, 0xBF, 0x92, 0x11, 0x50,
  41418. 0xEA, 0xB9, 0x49, 0x55, 0x9C, 0x02, 0x2D, 0x87,
  41419. 0x6F, 0xA2, 0x42, 0xC2, 0xA8, 0x45, 0xBC, 0xA7,
  41420. 0x23, 0x5F, 0x72, 0x1B, 0x00, 0x56, 0x78, 0x8A,
  41421. 0x44, 0xEC, 0xC3, 0xEB, 0x98, 0xF0, 0xF5, 0x02,
  41422. 0xB8, 0x9F, 0x8E, 0x74, 0x10, 0xEA, 0x56, 0x79,
  41423. 0xAE, 0x7C, 0x04, 0x34, 0xF1, 0x3A, 0xD8, 0x16,
  41424. 0x42, 0x1D, 0x2F, 0xEE, 0x30, 0xCB, 0xCB, 0x2D,
  41425. 0xAA, 0x6B, 0x85, 0x1C, 0xD1, 0xB6, 0xE9, 0x96,
  41426. 0xDA, 0x7A, 0x75, 0x7E, 0x4C, 0x4D, 0x85, 0x72,
  41427. 0xC8, 0xB6, 0x00, 0xDE, 0x85, 0xDD, 0xB6, 0x53,
  41428. 0x20, 0xD1, 0xCB, 0x71, 0xD9, 0x37, 0x83, 0x49,
  41429. 0xC0, 0xC4, 0x01, 0xAD, 0x4F, 0x9E, 0x91, 0x27,
  41430. 0x21, 0x39, 0x22, 0x8A, 0x8D, 0xA2, 0xF4, 0xFD,
  41431. 0x2F, 0x48, 0x89, 0x1A, 0x4D, 0xCB, 0x06, 0x6D,
  41432. 0x50, 0x1D, 0x44, 0x74, 0x83, 0xB6, 0x11, 0xBB,
  41433. 0x3C, 0x80, 0x55, 0x0A, 0x90, 0xEA, 0x0B, 0x73,
  41434. 0x2D, 0x63, 0x9D, 0x8B, 0x39, 0x26, 0xB6, 0xE7,
  41435. 0xC3, 0x54, 0x53, 0xED, 0x3C, 0xC1, 0x10, 0xBA,
  41436. 0xF5, 0x56, 0xCF, 0x46, 0xD8, 0xFC, 0x21, 0x77,
  41437. 0xE7, 0x6F, 0xB2, 0x66, 0x3B, 0x8B, 0xDD, 0x17,
  41438. 0x1E, 0x94, 0xC0, 0xAC, 0xAF, 0x25, 0xB9, 0x15,
  41439. 0x3B, 0x22, 0xBC, 0xA7, 0x49, 0x91, 0x67, 0x56,
  41440. 0xFB, 0x3E, 0xD3, 0x01, 0x8E, 0x09, 0x44, 0xB6,
  41441. 0xC3, 0xB9, 0xB6, 0xBF, 0xA1, 0x5B, 0x9B, 0xE8,
  41442. 0x03, 0xAC, 0x79, 0x33, 0x3C, 0xD2, 0xC3, 0xA2,
  41443. 0x7A, 0x26, 0xBC, 0x17, 0xCD, 0xA2, 0x57, 0x79,
  41444. 0x8A, 0xE1, 0x6B, 0x28, 0xB4, 0x63, 0xB6, 0xDF,
  41445. 0x3F, 0xA8, 0x7C, 0x2D, 0x74, 0x2D, 0x0F, 0x68,
  41446. 0x85, 0xBE, 0xE0, 0xBE, 0xC6, 0xE2, 0x0D, 0x01,
  41447. 0xE5, 0xDA, 0xDC, 0x86, 0x82, 0x3E, 0x92, 0xD6,
  41448. 0x0F, 0xEC, 0x79, 0xB0, 0xD2, 0x40, 0x24, 0x87,
  41449. 0x53, 0xE4, 0x20, 0x48, 0x38, 0x4C, 0x80, 0x42,
  41450. 0x89, 0x60, 0x48, 0x21, 0xA5, 0x7F, 0x4F, 0x9F,
  41451. 0x50, 0xAE, 0x0C, 0x38, 0x52, 0x7F, 0xE5, 0xA3,
  41452. 0x49, 0x38, 0xDD, 0xBC, 0xDC, 0xD9, 0xA1, 0xD0,
  41453. 0x20, 0x83, 0x9B, 0xEB, 0xB6, 0x2F, 0x9F, 0x41,
  41454. 0xFB, 0xA0, 0x80, 0x52, 0xAB, 0xB8, 0x2F, 0xAD,
  41455. 0xA8, 0x84, 0xCB, 0xE5, 0x63, 0x79, 0x11, 0x03,
  41456. 0xAA, 0x58, 0x55, 0x46, 0xEB, 0xFE, 0xB1, 0x12,
  41457. 0x72, 0xCC, 0x2E, 0x87, 0xA3, 0xB7, 0x5B, 0x3C,
  41458. 0x6B, 0xB1, 0x85, 0x3A, 0xE7, 0xF9, 0xCF, 0x55,
  41459. 0x85, 0xB2, 0x65, 0x3C, 0xF5, 0xEE, 0xA2, 0x44,
  41460. 0xD2, 0x04, 0xEB, 0x26, 0x9C, 0x56, 0xA2, 0x09,
  41461. 0x85, 0x16, 0x06, 0x59, 0xCB, 0x07, 0x25, 0xEE,
  41462. 0x13, 0xCE, 0x35, 0xD5, 0x5E, 0xB0, 0x95, 0xA5,
  41463. 0x34, 0x14, 0xF2, 0x32, 0xDF, 0x81, 0x08, 0xB1,
  41464. 0x80, 0x24, 0xEB, 0x0D, 0xBF, 0x34, 0x5E, 0xB5,
  41465. 0xCD, 0xAD, 0x0B, 0xCE, 0x72, 0x63, 0x50, 0x9A,
  41466. 0x34, 0x1D, 0x54, 0xA7, 0xD5, 0x34, 0xE5, 0x53,
  41467. 0xEA, 0xEF, 0xFE, 0x4E, 0x24, 0x2E, 0xA2, 0x3B,
  41468. 0xCF, 0xE5, 0x9A, 0x58, 0xA6, 0x04, 0x25, 0x88,
  41469. 0x2C, 0xB7, 0xE3, 0xB0, 0xC9, 0xE4, 0xAF, 0xE8,
  41470. 0x69, 0x8E, 0x3D, 0xF5, 0x6A, 0xFD, 0x6D, 0x61,
  41471. 0x1E, 0x91, 0x68, 0x74, 0x7D, 0x87, 0x35, 0xCF,
  41472. 0x92, 0x46, 0xD9, 0x4F, 0x21, 0x26, 0xBE, 0x72,
  41473. 0x7F, 0xB4, 0x2B, 0x22, 0x41, 0xA8, 0x3B, 0x34,
  41474. 0xF0, 0xB9, 0xEB, 0x47, 0x93, 0x8D, 0x72, 0x65,
  41475. 0x02, 0xC5, 0x4E, 0x45, 0x72, 0x76, 0x63, 0x31,
  41476. 0x62, 0x8F, 0xA5, 0xCD, 0xA8, 0x93, 0xC3, 0x53,
  41477. 0x76, 0xAB, 0x45, 0x38, 0xFF, 0x87, 0x17, 0xC2,
  41478. 0x79, 0x5B, 0x0F, 0x51, 0xF0, 0x8E, 0x11, 0x37,
  41479. 0x61, 0x2B, 0x89, 0xB0, 0xC1, 0xE2, 0xCD, 0x1F,
  41480. 0x09, 0x9E, 0x88, 0x55, 0x69, 0x23, 0xAE, 0x57,
  41481. 0xA1, 0xDA, 0xD2, 0xAF, 0xB1, 0x23, 0x0B, 0x50,
  41482. 0x94, 0xA1, 0xB2, 0x1B, 0xAD, 0x7D, 0xBB, 0xC3,
  41483. 0x33, 0xA9, 0x7F, 0x17, 0x93, 0x04, 0x71, 0x8F,
  41484. 0x32, 0x89, 0xB6, 0xDE, 0x31, 0x31, 0x5B, 0x74,
  41485. 0xC1, 0xA7, 0x3A, 0xC7, 0x75, 0x6F, 0xAA, 0x4D,
  41486. 0x7E, 0xB5, 0x68, 0xBB, 0xC6, 0xF7, 0xE7, 0x88,
  41487. 0xCD, 0x08, 0x9B, 0x39, 0x55, 0x64, 0xD2, 0x17,
  41488. 0x6B, 0x00, 0x56, 0xDF, 0xFE, 0x95, 0x2C, 0x77,
  41489. 0x48, 0xB0, 0x48, 0x30, 0x67, 0x20, 0xF6, 0x02,
  41490. 0xB6, 0x7E, 0x8F, 0x6A, 0xDC, 0xC9, 0x1F, 0x8E,
  41491. 0x3A, 0xA4, 0xB8, 0xC4, 0xD7, 0xFA, 0xC2, 0x33,
  41492. 0xAA, 0xF9, 0x36, 0x53, 0xAD, 0x22, 0x09, 0xE2,
  41493. 0xFF, 0x92, 0xDA, 0x30, 0xC2, 0xD5, 0x3F, 0xDE,
  41494. 0xF6, 0xF4, 0xC9, 0x0E, 0xAA, 0x0D, 0xE6, 0x0D,
  41495. 0x59, 0x4A, 0xDA, 0x39, 0x15, 0xDB, 0x24, 0x27,
  41496. 0x9D, 0x86, 0x74, 0x76, 0xEA, 0xD7, 0x57, 0xB4,
  41497. 0xC0, 0x26, 0x4A, 0x1D, 0xB8, 0xA1, 0xF5, 0x7A,
  41498. 0x1B, 0x5D, 0x71, 0x73, 0xBB, 0x1A, 0x96, 0x0C,
  41499. 0xE0, 0x2F, 0xDE, 0xFE, 0xF1, 0x60, 0xD5, 0x12,
  41500. 0x66, 0x7D, 0x65, 0x52, 0x68, 0xFC, 0xC3, 0xA1,
  41501. 0x53, 0xA4, 0x31, 0x47, 0x82, 0xA0, 0xEB, 0xFF,
  41502. 0x84, 0xF6, 0x5F, 0x14, 0xA0, 0xE3, 0xE1, 0x2A,
  41503. 0x13, 0x25, 0x0C, 0x07, 0xD0, 0x8C, 0x22, 0x5B,
  41504. 0x11, 0xA6, 0x83, 0x1B, 0xC2, 0x5C, 0x40, 0x46,
  41505. 0x7B, 0x76, 0x80, 0x04, 0xDD, 0xE0, 0xE8, 0x74,
  41506. 0xA5, 0x11, 0x44, 0xC1, 0x89, 0x20, 0xBD, 0xF2,
  41507. 0x86, 0x09, 0x0B, 0x59, 0xF5, 0x15, 0x64, 0xEA,
  41508. 0x40, 0x70, 0xFB, 0xBF, 0x61, 0xE3, 0x69, 0x64,
  41509. 0x35, 0xF2, 0x8F, 0x63, 0x33, 0x2B, 0x64, 0x49,
  41510. 0x6D, 0xF3, 0xEC, 0x8B, 0x65, 0xD5, 0x4E, 0x1C,
  41511. 0xF4, 0x78, 0x9D, 0xDA, 0xB1, 0x22, 0xDA, 0x6B,
  41512. 0x26, 0x4D, 0x31, 0x2A, 0x71, 0x1C, 0x12, 0x9E,
  41513. 0x3B, 0x07, 0xF4, 0xC6, 0xDA, 0x25, 0xA5, 0x61,
  41514. 0x73, 0xAF, 0x58, 0xB9, 0x0A, 0x71, 0xB7, 0xAC,
  41515. 0xFA, 0x31, 0x61, 0xA8, 0x1F, 0x59, 0xD1, 0x79,
  41516. 0x14, 0xC9, 0x9B, 0xBA, 0xC4, 0xF9, 0xA3, 0x14,
  41517. 0x97, 0x7A, 0x89, 0xCE, 0xF7, 0x69, 0x69, 0x43,
  41518. 0x60, 0x9B, 0xB4, 0x82, 0x79, 0x64, 0xFB, 0x29,
  41519. 0x76, 0x40, 0x3B, 0xD4, 0x99, 0x6F, 0x1E, 0x84,
  41520. 0x2B, 0xF5, 0xAA, 0xAE, 0x1E, 0xCC, 0xA1, 0x12,
  41521. 0x55, 0xB9, 0xE6, 0x00, 0x1C, 0x20, 0xF7, 0x2F,
  41522. 0x1F, 0xD5, 0xE3, 0x2C, 0xDA, 0x32, 0xD8, 0xA7,
  41523. 0xAC, 0x5F, 0x62, 0xB0, 0x9A, 0x0E, 0x61, 0x58,
  41524. 0x47, 0xCA, 0x74, 0x6F, 0x48, 0x95, 0x15, 0xCF,
  41525. 0x8F, 0x18, 0x31, 0x62, 0x85, 0x9F, 0x53, 0xB9,
  41526. 0x7E, 0x9E, 0x5C, 0xA8, 0x00, 0xEE, 0x62, 0x4F,
  41527. 0x72, 0x98, 0x43, 0xA0, 0x00, 0x91, 0x64, 0xA4,
  41528. 0xA9, 0xFF, 0x76, 0xEB, 0x34, 0xE4, 0x70, 0x41,
  41529. 0x84, 0x84, 0x8A, 0x13, 0x9A, 0xD9, 0x7D, 0x90,
  41530. 0x9F, 0x7A, 0x7E, 0xD1, 0x14, 0xF0, 0x87, 0xA4,
  41531. 0xB2, 0xE1, 0xB4, 0xA3, 0x03, 0x23, 0x91, 0x16,
  41532. 0x0B, 0x6F, 0x3A, 0x36, 0x49, 0xFF, 0x15, 0xAE,
  41533. 0xA2, 0xB7, 0x10, 0x7A, 0xF8, 0xA3, 0xB5, 0xFC,
  41534. 0xAD, 0x61, 0xD4, 0x3D, 0x60, 0x2E, 0x62, 0x86,
  41535. 0xA9, 0x00, 0x87, 0x0C, 0xC8, 0xCE, 0x24, 0xE3,
  41536. 0x9E, 0x78, 0xF0, 0x39, 0x7A, 0x0D, 0x7E, 0x27,
  41537. 0xE8, 0xE2, 0xD4, 0x77, 0x6A, 0x44, 0xCB, 0xA2,
  41538. 0x18, 0xEB, 0xCD, 0x88, 0xB3, 0xC2, 0x8C, 0x18,
  41539. 0x2A, 0x7C, 0x9F, 0x4D, 0xBB, 0x2D, 0xBB, 0x5E,
  41540. 0x98, 0x15, 0x63, 0xD6, 0x6C, 0xEE, 0xB7, 0x7E,
  41541. 0x7F, 0x90, 0x34, 0xBD, 0x42, 0x9D, 0x27, 0x63,
  41542. 0x7C, 0xF7, 0x97, 0xDE, 0x82, 0xE0, 0x1F, 0xEB,
  41543. 0xBC, 0xE2, 0x17, 0x1E, 0xFD, 0x01, 0x6E, 0x40,
  41544. 0x2A, 0x42, 0xD7, 0x8E, 0xA1, 0xAC, 0xE2, 0xCB,
  41545. 0x37, 0x0E, 0x75, 0xC9, 0x0A, 0xDF, 0xA1, 0xA7,
  41546. 0x93, 0xB2, 0x16, 0x9C, 0xC2, 0x65, 0x22, 0xDB,
  41547. 0x2F, 0x54, 0x6A, 0xC1, 0xDE, 0x34, 0xC9, 0x08,
  41548. 0x71, 0x20, 0xC4, 0x2A, 0x9F, 0x10, 0xC0, 0x0D,
  41549. 0x49, 0x3C, 0x25, 0x73, 0x01, 0x66, 0xF9, 0xD2,
  41550. 0x19, 0xFB, 0xDA, 0xD2, 0x22, 0xC8, 0xB2, 0x81,
  41551. 0x15, 0x54, 0x33, 0x13, 0x21, 0x08, 0x48, 0xFB,
  41552. 0x2F, 0x04, 0xBF, 0xDC, 0xE1, 0x5D, 0x32, 0x0C,
  41553. 0x36, 0x34, 0xA8, 0xE4, 0xD6, 0x37, 0x55, 0x51,
  41554. 0x59, 0x00, 0xC7, 0x5B, 0xFD, 0x09, 0x0A, 0xD7,
  41555. 0x8D, 0xD5, 0x88, 0x65, 0x9F, 0xBF, 0x97, 0xC9,
  41556. 0x6E, 0x0D, 0x0A, 0xCC, 0x8E, 0x81, 0x5E, 0x60,
  41557. 0x8F, 0x9E, 0x86, 0x1D, 0x79, 0xAF, 0x30, 0x51,
  41558. 0xB9, 0x42, 0xB5, 0x25, 0x70, 0xB6, 0x29, 0x2B,
  41559. 0xF4, 0x8C, 0x2B, 0xFA, 0xA9, 0x07, 0x7D, 0xC7,
  41560. 0x6F, 0xE9, 0x02, 0x68, 0x32, 0x17, 0xB8, 0xBF,
  41561. 0x80, 0x9E, 0xD7, 0xA0, 0x05, 0x0A, 0xDD, 0xBB,
  41562. 0x65, 0xFD, 0xDF, 0xBD, 0x24, 0x01, 0x9C, 0x91,
  41563. 0x81, 0xB5, 0xAC, 0x81, 0x56, 0x61, 0x13, 0xD6,
  41564. 0x69, 0x4E, 0xA6, 0x29, 0x1D, 0x7F, 0x4A, 0x7F,
  41565. 0x56, 0xA4, 0x1E, 0xB9, 0x1F, 0x76, 0x36, 0x8D,
  41566. 0xF8, 0x2B, 0x16, 0x4B, 0x48, 0x59, 0x25, 0x9D,
  41567. 0x71, 0x89, 0x24, 0x0F, 0x1D, 0x88, 0x03, 0xF8,
  41568. 0x10, 0x72, 0x96, 0xD3, 0x78, 0xBA, 0xB4, 0xD2,
  41569. 0x4F, 0xE6, 0xD1, 0x0E, 0xF7, 0x88, 0x36, 0x7B,
  41570. 0xCE, 0x16, 0xC5, 0xAB, 0x77, 0xFB, 0xC1, 0x68,
  41571. 0xB8, 0x57, 0xF7, 0xBA, 0x5C, 0xDC, 0xBE, 0x50,
  41572. 0x67, 0xC8, 0x64, 0xF8, 0x79, 0x80, 0x9F, 0xE5,
  41573. 0x21, 0x7D, 0xEF, 0x02, 0x94, 0xBF, 0xAF, 0xDF,
  41574. 0x80, 0x9A, 0xBC, 0xE9, 0x53, 0x2D, 0xD9, 0xDA,
  41575. 0xB3, 0x44, 0x8F, 0x4D, 0xA6, 0x8E, 0xCA, 0x51,
  41576. 0x60, 0x94, 0x76, 0x27, 0x8E, 0xB8, 0xC4, 0xF6,
  41577. 0x9E, 0xA2, 0x96, 0x73, 0xF6, 0x94, 0x18, 0x04,
  41578. 0x1D, 0x26, 0x85, 0x7E, 0xBC, 0x24, 0xA4, 0x87,
  41579. 0xBB, 0x4B, 0x0B, 0xA6, 0x3A, 0xF8, 0x48, 0x54,
  41580. 0x5E, 0xE9, 0xBE, 0x89, 0xF1, 0x39, 0xD5, 0x02,
  41581. 0x09, 0x9B, 0x9D, 0x35, 0xDB, 0x38, 0x07, 0xB9,
  41582. 0x25, 0xCB, 0xA5, 0x76, 0xE2, 0x71, 0x70, 0xEA,
  41583. 0xEC, 0x48, 0xCC, 0x2C, 0xC1, 0x5B, 0x04, 0x36,
  41584. 0x77, 0x82, 0x5D, 0x0E, 0xE8, 0x1E, 0xB2, 0xCE,
  41585. 0xE3, 0xA8, 0xED, 0x14, 0xA7, 0x98, 0xB8, 0x79,
  41586. 0x53, 0x02, 0x20, 0xE5, 0x0C, 0xE8, 0xC0, 0x03,
  41587. 0xA3, 0x05, 0x38, 0x2A, 0x24, 0xD2, 0x3C, 0x27,
  41588. 0x7B, 0x99, 0xD1, 0xF4, 0xC5, 0x4F, 0x9A, 0x8D,
  41589. 0x33, 0xFA, 0x3D, 0x1E, 0x33, 0x7E, 0x18, 0xD7,
  41590. 0xCB, 0xBA, 0x5E, 0x5A, 0x47, 0xF2, 0xD5, 0xE0,
  41591. 0x96, 0xCF, 0x45, 0x51, 0xB2, 0x3B, 0x1B, 0x86,
  41592. 0x43, 0x6E, 0x81, 0xB4, 0xA0, 0x9D, 0x1E, 0x3D,
  41593. 0x38, 0x49, 0x2E, 0xC8, 0xB2, 0xA0, 0x09, 0x67,
  41594. 0x01, 0x6A, 0xB7, 0x6B, 0x9A, 0x9B, 0x18, 0x64,
  41595. 0x67, 0x14, 0x21, 0xDA, 0x56, 0xF5, 0x7D, 0x00,
  41596. 0x8D, 0x5C, 0xE1, 0xB8, 0x92, 0xA7, 0xE9, 0xC1,
  41597. 0xF6, 0x9F, 0x6C, 0x72, 0x2C, 0xF1, 0x09, 0xDB,
  41598. 0x50, 0x0E, 0x53, 0xF6, 0xBC, 0x07, 0x83, 0x7A,
  41599. 0xD1, 0xCD, 0x4C, 0xF4, 0xA6, 0x4D, 0xA7, 0x63,
  41600. 0xB4, 0xA9, 0xC4, 0x92, 0x9B, 0x0D, 0xCD, 0xDF,
  41601. 0x7C, 0x7E, 0x11, 0x86, 0xBE, 0x3F, 0xF0, 0xC3,
  41602. 0x21, 0x15, 0x84, 0x37, 0x82, 0x0C, 0x81, 0xE7,
  41603. 0x4F, 0xF3, 0x16, 0xAE, 0x32, 0x54, 0xE9, 0x72,
  41604. 0xFC, 0x19, 0x7A, 0x7F, 0x0E, 0x62, 0x02, 0x42,
  41605. 0xAC, 0x05, 0xA4, 0xE4, 0x3E, 0x98, 0x7C, 0x2A,
  41606. 0x83, 0x55, 0xB0, 0x35, 0x77, 0x45, 0xCA, 0x79,
  41607. 0xE6, 0xAE, 0x48, 0xAB, 0x29, 0xED, 0x4F, 0xA6,
  41608. 0x3D, 0x3A, 0x1F, 0x19, 0xB9, 0x99, 0xDE, 0x25,
  41609. 0x1F, 0xDE, 0x06, 0x40, 0xDD, 0x87, 0x87, 0x6D,
  41610. 0x55, 0x76, 0x28, 0x78, 0xAD, 0x1D, 0xB1, 0x2D,
  41611. 0x65, 0xBA, 0xFD, 0x14, 0xB6, 0xA9, 0xA7, 0x08,
  41612. 0x1B, 0xF2, 0x3F, 0x9F, 0x06, 0xD9, 0x0C, 0xE2,
  41613. 0x73, 0xC5, 0xA2, 0x6E, 0x01, 0x2C, 0xA9, 0x4D,
  41614. 0xD4, 0x81, 0xD3, 0x2E, 0x10, 0x93, 0x8C, 0x16,
  41615. 0x51, 0x63, 0xE8, 0x9B, 0xE8, 0xA9, 0x3A, 0x63,
  41616. 0x03, 0x4D, 0x34, 0x5B, 0x74, 0xE2, 0xA9, 0x4E,
  41617. 0xF6, 0x43, 0xD0, 0x6A, 0xF9, 0xE1, 0xF5, 0xC9,
  41618. 0xF1, 0x04, 0x93, 0x0D, 0xA0, 0x0E, 0x61, 0xE0,
  41619. 0x61, 0xEE, 0x8C, 0x3B, 0xB1, 0x7C, 0x11, 0xE0,
  41620. 0x5D, 0x45, 0xC1, 0x68, 0x2E, 0x4D, 0x59, 0x3C,
  41621. 0x91, 0x98, 0x23, 0x8D, 0x2B, 0xA2, 0x89, 0x77,
  41622. 0x9E, 0x7D, 0x0F, 0x22, 0x7B, 0xCB, 0x0B, 0x09,
  41623. 0x97, 0x2B, 0x19, 0x77, 0x0F, 0xF0, 0x11, 0xBF,
  41624. 0x6C, 0x60, 0xD9, 0xD1, 0x93, 0xCF, 0xAB, 0x32,
  41625. 0x74, 0x7A, 0x00, 0x95, 0xE1, 0xA4, 0xAD, 0x32,
  41626. 0x51, 0x4C, 0x78, 0x2E, 0xF3, 0xDE, 0x7A, 0x26,
  41627. 0xEA, 0x77, 0x1F, 0x55, 0x30, 0xD9, 0xDE, 0x97,
  41628. 0x36, 0xD0, 0xF6, 0xAE, 0x1A, 0xFB, 0x78, 0xEC,
  41629. 0x7C, 0xE4, 0x88, 0x4A, 0x1B, 0xB4, 0x36, 0xCF,
  41630. 0xCE, 0x45, 0x9C, 0xD9, 0x93, 0x58, 0x26, 0x09,
  41631. 0x06, 0xAA, 0xC9, 0x97, 0x16, 0xA5, 0x36, 0xCC,
  41632. 0x76, 0x87, 0xA0, 0x37, 0x5F, 0xDA, 0x11, 0x00,
  41633. 0x76, 0x18, 0xE5, 0x53, 0x53, 0x4E, 0x54, 0xD5,
  41634. 0xB2, 0x14, 0xF7, 0xAA, 0x6F, 0xC7, 0xDB, 0xE3,
  41635. 0x7C, 0x2B, 0xD2, 0xB6, 0x48, 0x50, 0xAE, 0x46,
  41636. 0x9A, 0x98, 0x58, 0x98, 0x7F, 0x3F, 0xA4, 0xB1,
  41637. 0xFD, 0x26, 0xD9, 0x54, 0xBF, 0xEC, 0x36, 0x5D,
  41638. 0xBE, 0x06, 0xDD, 0xCD, 0x61, 0x5E, 0x1F, 0xED,
  41639. 0x58, 0xA8, 0x86, 0x76, 0x40, 0x2D, 0x1D, 0x6B,
  41640. 0x58, 0x14, 0x85, 0x49, 0x8B, 0x5A, 0xDF, 0xFF,
  41641. 0xC4, 0x2D, 0x47, 0xD6, 0x1D, 0xF9, 0x93, 0x84,
  41642. 0xE2, 0x2C, 0x51, 0x57, 0xF0, 0x17, 0x8A, 0x6F,
  41643. 0xDA, 0xF8, 0xF4, 0xA9, 0x49, 0x1D, 0xAF, 0x29,
  41644. 0x8B, 0x2C, 0x3E, 0xC8, 0x80, 0x85, 0x02, 0x2C,
  41645. 0x0A, 0x7C, 0xF2, 0x45, 0xED, 0x0F, 0xB5, 0xA3,
  41646. 0x8C, 0xD1, 0x6F, 0x30, 0xD3, 0x7D, 0xA5, 0xC4,
  41647. 0x95, 0x9A, 0x55, 0x50, 0x1D, 0xAD, 0x50, 0xF1,
  41648. 0xB4, 0x8B, 0xBB, 0xDD, 0x86, 0xAB, 0x8B, 0xB5,
  41649. 0x22, 0xA9, 0x36, 0xDD, 0xF0, 0x00, 0x3B, 0x81,
  41650. 0xBE, 0x16, 0x23, 0x1A, 0x04, 0xE7, 0xA5, 0x89,
  41651. 0xC5, 0x6F, 0xFF, 0xB5, 0x1B, 0x07, 0x92, 0x7B,
  41652. 0x4A, 0xFA, 0x1D, 0xB7, 0xD4, 0x8B, 0xC6, 0xFB,
  41653. 0xC3, 0xF3, 0x67, 0x56, 0x37, 0x18, 0x4B, 0x7A,
  41654. 0xDB, 0x9B, 0xAD, 0xF4, 0xDE, 0x7C, 0x08, 0x5B,
  41655. 0xCA, 0x1D, 0x42, 0x8D, 0xC9, 0xFC, 0x82, 0x77,
  41656. 0xCB, 0xD8, 0x58, 0x84, 0xA5, 0x92, 0x1B, 0x52,
  41657. 0xBB, 0x05, 0xB7, 0x10, 0x61, 0x55, 0x08, 0x26,
  41658. 0x1B, 0xB4, 0x54, 0x6B, 0xD6, 0xE1, 0xFC, 0x73,
  41659. 0x0D, 0x16, 0xB0, 0x49, 0xEA, 0x12, 0x79, 0x8C,
  41660. 0xE2, 0xE6, 0xDF, 0x43, 0xF5, 0xB8, 0xF3, 0xEF,
  41661. 0x9A, 0xC8, 0xFB, 0xAE, 0x31, 0xB0, 0x11, 0xE1,
  41662. 0x0C, 0x4F, 0xC6, 0x2F, 0xFD, 0x7F, 0x39, 0xD1,
  41663. 0x6E, 0xC3, 0x2C, 0xA8, 0x21, 0x0E, 0xD1, 0x6E,
  41664. 0x04, 0x1D, 0xA4, 0x3D, 0x92, 0x74, 0x22, 0x95,
  41665. 0x14, 0x05, 0x4A, 0x0F, 0x82, 0xD4, 0x62, 0xFE,
  41666. 0x08, 0x0C, 0x6F, 0xFD, 0x7B, 0xBD, 0xBF, 0xBF,
  41667. 0x0B, 0xFF, 0xC6, 0xD5, 0xEC, 0xC4, 0x32, 0xA3,
  41668. 0x25, 0x6C, 0x0B, 0xE0, 0xDD, 0xFD, 0x5D, 0x90,
  41669. 0x80, 0xC6, 0x76, 0xC7, 0x95, 0x5D, 0x66, 0xE4,
  41670. 0x4D, 0x1C, 0xE5, 0x1F, 0xCC, 0x23, 0x82, 0xF8,
  41671. 0x68, 0xD7, 0x32, 0xE8, 0x58, 0x51, 0x72, 0x1B,
  41672. 0x48, 0xA0, 0x1D, 0x08, 0xC6, 0x39, 0x62, 0x6E,
  41673. 0xE0, 0x50, 0x9C, 0xB5, 0x81, 0xEF, 0xF5, 0x62,
  41674. 0x8F, 0xA6, 0xCC, 0xD1, 0x08, 0x9A, 0xC0, 0xE1,
  41675. 0x2D, 0xEB, 0xE0, 0x85, 0x17, 0x82, 0xE6, 0x4C,
  41676. 0x50, 0x49, 0xCB, 0xD6, 0x50, 0x10, 0x13, 0x96,
  41677. 0x5C, 0xC0, 0xCA, 0x25, 0xAC, 0xAB, 0x17, 0x6E,
  41678. 0xF7, 0xCA, 0xB9, 0x29, 0x40, 0x98, 0x5D, 0xDB,
  41679. 0x49, 0x02, 0x1D, 0xF6, 0xC6, 0x0D, 0x6C, 0x4A,
  41680. 0x48, 0x91, 0x16, 0x31, 0x1E, 0x86, 0xBA, 0x19,
  41681. 0xED, 0xF0, 0x0D, 0x74, 0x79, 0x73, 0x58, 0x20,
  41682. 0x7C, 0xDE, 0x50, 0x50, 0x6D, 0x00, 0x7F, 0xE0,
  41683. 0x3C, 0x88, 0x04, 0xC6, 0x64, 0x51, 0xF0, 0x2A,
  41684. 0x01, 0x82, 0xD3, 0x87, 0xB7, 0x59, 0x89, 0x40,
  41685. 0x96, 0xF6, 0x52, 0x32, 0x95, 0x2D, 0x18, 0x3D,
  41686. 0xBA, 0xAA, 0xBB, 0x6B, 0xC0, 0xE1, 0x91, 0xDC,
  41687. 0x2C, 0x3F, 0x75, 0xFC, 0x72, 0xBD, 0x61, 0xBA,
  41688. 0xB2, 0xEF, 0x19, 0xB6, 0x53, 0x2B, 0x23, 0x1C,
  41689. 0x4A, 0xFB, 0x1A, 0x9C, 0x2C, 0xB2, 0xF3, 0xD6,
  41690. 0xC4, 0x51, 0xE8, 0x44, 0x0D, 0x6A, 0x92, 0x3C,
  41691. 0xF7, 0x2A, 0x63, 0xE2, 0xED, 0x85, 0x54, 0x77,
  41692. 0x38, 0x87, 0x91, 0x0C, 0xA5, 0xC6, 0x71, 0xAD,
  41693. 0x4F, 0xD5, 0x92, 0x3C, 0xB9, 0x5E, 0xC7, 0x3F,
  41694. 0xFD, 0xFB, 0xDA, 0x4B, 0x66, 0x55, 0xF5, 0x5D,
  41695. 0xBF, 0xD1, 0x31, 0x7D, 0x02, 0x44, 0x22, 0x30,
  41696. 0x1E, 0xD6, 0x6A, 0x6E, 0x4C, 0x67, 0x20, 0x85,
  41697. 0xCE, 0xD1, 0xF4, 0xC7, 0xB0, 0x50, 0x30, 0xA1,
  41698. 0x00, 0xC4, 0x78, 0x8F, 0xEF, 0x4C, 0xD3, 0xE4,
  41699. 0x94, 0xA8, 0x53, 0xBD, 0xE6, 0x3E, 0x9D, 0x44,
  41700. 0x9A, 0xE3, 0xBB, 0x6B, 0xA1, 0x08, 0x32, 0x38,
  41701. 0xDA, 0x3F, 0x40, 0x90, 0x51, 0x5D, 0x14, 0x3C,
  41702. 0x67, 0xDB, 0xE5, 0x3D, 0x8D, 0x50, 0x7A, 0x52,
  41703. 0x29, 0xFF, 0xEB, 0x20, 0x72, 0xD0, 0xBD, 0x09,
  41704. 0x2F, 0xC9, 0xAE, 0x52, 0xDE, 0xAA, 0xAC, 0xD1,
  41705. 0xF0, 0xF1, 0x4B, 0x5A, 0xC8, 0x47, 0x52, 0xBF,
  41706. 0xD0, 0x02, 0x5E, 0x5F, 0x55, 0xB8, 0x69, 0x35,
  41707. 0x0F, 0x4B, 0x27, 0x19, 0xC5, 0xC0, 0x5A, 0xC1,
  41708. 0x66, 0x9B, 0xB0, 0xFD, 0x3C, 0x61, 0x4A, 0xCE,
  41709. 0x02, 0xA2, 0x70, 0x61, 0x3F, 0xD3, 0x30, 0x97,
  41710. 0x06, 0xDD, 0xCD, 0x5B, 0x1A, 0x6A, 0xD2, 0x6F,
  41711. 0x35, 0x9A, 0xDA, 0x80, 0xB3, 0x0E, 0x50, 0xA7,
  41712. 0xE5, 0x0B, 0xBD, 0x3A, 0xA4, 0x5D, 0x06, 0x54,
  41713. 0xDD, 0x7D, 0x05, 0x8B, 0x0B, 0xBF, 0x4D, 0x0D,
  41714. 0x92, 0x13, 0x51, 0x42, 0x21, 0x4E, 0xE7, 0x05,
  41715. 0x11, 0xF3, 0x67, 0x6A, 0xE6, 0x43, 0xB5, 0xF2,
  41716. 0x45, 0x06, 0x3B, 0x94, 0x19, 0xCF, 0x6B, 0x49,
  41717. 0xFD, 0x64, 0x7F, 0x27, 0xD7, 0xC4, 0x1C, 0x86,
  41718. 0x6E, 0x6C, 0xAD, 0x9D, 0x5E, 0x2E, 0x3E, 0x33,
  41719. 0x1B, 0xF6, 0xB9, 0xF7, 0x2A, 0xCA, 0x32, 0x9B,
  41720. 0xB6, 0x42, 0x59, 0xC3, 0xE7, 0x97, 0x83, 0xA2,
  41721. 0x66, 0x74, 0xB7, 0xD3, 0x8E, 0xBD, 0xE8, 0x31,
  41722. 0x84, 0x11, 0xF4, 0x76, 0x4E, 0xBD, 0xC4, 0xC7,
  41723. 0xE4, 0x1A, 0xCF, 0xF8, 0x5B, 0xBB, 0x30, 0x31,
  41724. 0x8D, 0x59, 0xC4, 0x2C, 0x92, 0x03, 0xAB, 0xD6,
  41725. 0x63, 0x6B, 0xA3, 0xF7, 0x72, 0xB6, 0x72, 0x51,
  41726. 0x21, 0xC0, 0x52, 0xDE, 0x99, 0x91, 0x0D, 0x55,
  41727. 0x15, 0x8C, 0x6F, 0x3E, 0xF8, 0xBB, 0x7F, 0xED,
  41728. 0xE2, 0xF8, 0x1E, 0x58, 0xA7, 0xAE, 0xB2, 0x5E,
  41729. 0x2E, 0x46, 0xFD, 0x72, 0x32, 0x30, 0x2F, 0xAF,
  41730. 0xA8, 0xFC, 0x37, 0xFC, 0x8B, 0x55, 0xD5, 0x94,
  41731. 0xB7, 0x6E, 0xC4, 0xA5, 0x3E, 0xB1, 0x1E, 0xB3,
  41732. 0xFD, 0x63, 0x44, 0x28, 0xAA, 0xA5, 0xD8, 0x6F,
  41733. 0x83, 0x9D, 0x08, 0x9A, 0xBE, 0x2F, 0xEF, 0xE2,
  41734. 0xAE, 0x52, 0x62, 0xFE, 0xFC, 0x73, 0x48, 0xD8,
  41735. 0x36, 0x69, 0x2E, 0xDB, 0x21, 0x5D, 0x6F, 0x8F,
  41736. 0x54, 0x8B, 0x88, 0x52, 0x90, 0xC2, 0x40, 0x3C,
  41737. 0x51, 0xC3, 0xE2, 0x69, 0xD4, 0x93, 0xFB, 0xD3,
  41738. 0x39, 0xB5, 0xDF, 0xB0, 0xA3, 0x8E, 0xED, 0xA7,
  41739. 0x75, 0x4D, 0xAF, 0xFA, 0x16, 0xE5, 0xBC, 0xA5,
  41740. 0xA9, 0xBB, 0xDE, 0x04, 0xB0, 0x14, 0xB7, 0xAE,
  41741. 0xA8, 0x98, 0x8F, 0x37, 0x49, 0xD5, 0x2D, 0x2F,
  41742. 0xC1, 0xC9, 0xF7, 0xC7, 0xB2, 0xC2, 0xD6, 0x92,
  41743. 0xE7, 0x89, 0x6E, 0x4C, 0x34, 0xF5, 0x7C, 0x55,
  41744. 0x8C, 0xFE, 0x83, 0x17, 0xA8, 0x37, 0x44, 0x09,
  41745. 0xD5, 0x66, 0x87, 0x9A, 0x08, 0x62, 0x8F, 0x64,
  41746. 0x4F, 0xB4, 0x5B, 0x81, 0x84, 0x55, 0xBC, 0xA6,
  41747. 0x04, 0x2B, 0x4E, 0x61, 0x87, 0xC1, 0xDD, 0x17,
  41748. 0x7E, 0x9E, 0x51, 0x46, 0x31, 0x99, 0x04, 0xB1,
  41749. 0x50, 0x5F, 0x3E, 0xE0, 0x0C, 0xD7, 0xFE, 0xAF,
  41750. 0x0E, 0x83, 0xC3, 0x02, 0x49, 0x56, 0xF7, 0x76,
  41751. 0x59, 0xAC, 0xC5, 0x6D, 0x8D, 0x91, 0x7A, 0x37,
  41752. 0xE8, 0xFF, 0x7E, 0xB8, 0x87, 0x13, 0xCC, 0xA3,
  41753. 0x34, 0xEA, 0x04, 0xB8, 0xE2, 0x58, 0xC9, 0x34,
  41754. 0x5D, 0xA9, 0xDE, 0x26, 0xA0, 0xA3, 0x66, 0x51,
  41755. 0x94, 0x51, 0xE1, 0x01, 0x2D, 0xE6, 0xAA, 0xBF,
  41756. 0x46, 0x97, 0xC9, 0xDE, 0x82, 0x1D, 0x70, 0x02,
  41757. 0x1C, 0x32, 0x50, 0xA1, 0x06, 0xCF, 0x4C, 0x23,
  41758. 0xA1, 0xB1, 0x78, 0x5F, 0x54, 0x9D, 0x3C, 0x8C,
  41759. 0xD7, 0x1B, 0x05, 0xFE, 0xA7, 0x53, 0xE0, 0x04,
  41760. 0x6A, 0x3A, 0xE0, 0xA9, 0xB1, 0xF4, 0x02, 0x77,
  41761. 0xCF, 0x45, 0x3A, 0x2B, 0xA1, 0x4C, 0xBA, 0x92,
  41762. 0x3C, 0xC6, 0x26, 0x97, 0x06, 0xDF, 0xFF, 0xD5,
  41763. 0x17, 0xC1, 0xE5, 0x93, 0x00, 0x79, 0x91, 0x2E,
  41764. 0x05, 0xA5, 0x57, 0x18, 0x97, 0xA0, 0x68, 0x65,
  41765. 0x51, 0x6C, 0x86, 0x69, 0x9F, 0x70, 0x7E, 0x00,
  41766. 0xCB, 0x38, 0xCE, 0x19, 0x34, 0x90, 0xAE, 0xE3,
  41767. 0x0B, 0xA4, 0x7D, 0xDD, 0xF3, 0xA5, 0xB4, 0xFB,
  41768. 0xCE, 0xBA, 0x73, 0xDC, 0x13, 0xD0, 0xA1, 0x60,
  41769. 0xEA, 0x64, 0x2D, 0x30, 0xD6, 0x3A, 0x02, 0x96,
  41770. 0x4E, 0xDF, 0xDB, 0x2F, 0x29, 0xDC, 0xD3, 0x2C,
  41771. 0xA9, 0x97, 0x4F, 0x89, 0xC3, 0x2D, 0x1F, 0xA9,
  41772. 0xA8, 0x3C, 0x94, 0xA2, 0x77, 0x0F, 0xCF, 0xCF,
  41773. 0x86, 0xE6, 0x46, 0x46, 0x88, 0x2B, 0xD5, 0x50,
  41774. 0xDD, 0xD6, 0x5B, 0x4E, 0x2D, 0x28, 0x7A, 0xF6,
  41775. 0xC1, 0x96, 0xF4, 0x2D, 0xBD, 0x39, 0xB0, 0x20,
  41776. 0xD7, 0xCD, 0xFB, 0xB6, 0xE6, 0xE7, 0x5F, 0xFA,
  41777. 0xAB, 0x26, 0x09, 0x9E, 0xC1, 0xD2, 0x5E, 0x32,
  41778. 0x34, 0xF7, 0x0D, 0xD9, 0x72, 0x28, 0x6A, 0xEA,
  41779. 0x0C, 0x34, 0x36, 0x59, 0x5F, 0xE4, 0x9F, 0xCA,
  41780. 0x89, 0x8B, 0xFA, 0x42, 0x16, 0x04, 0xC8, 0x2D,
  41781. 0x3E, 0x94, 0x85, 0x6D, 0x18, 0x69, 0x05, 0x07,
  41782. 0x6D, 0x18, 0x6C, 0x68, 0x41, 0x74, 0xBF, 0x42,
  41783. 0x90, 0xDF, 0x31, 0x76, 0x9E, 0xDC, 0x97, 0xA1,
  41784. 0xDF, 0x2D, 0xFE, 0xD0, 0x3C, 0xF4, 0x5C, 0xE6,
  41785. 0x78, 0xC8, 0xA1, 0x42, 0x9E, 0xB9, 0x78, 0xD0,
  41786. 0x2A, 0x79, 0xD4, 0xF8, 0xCF, 0x01, 0x68, 0xDA,
  41787. 0xAB, 0x48, 0x2C, 0x6C, 0x61, 0x2F, 0x04, 0xB1,
  41788. 0xC9, 0x36, 0x37, 0xFE, 0x77, 0xB3, 0x02, 0xCE,
  41789. 0xFA, 0x78, 0x8C, 0x11, 0x35, 0x6C, 0x52, 0xC5,
  41790. 0x4F, 0x37, 0xA9, 0xDC, 0xFD, 0xA5, 0x59, 0x27,
  41791. 0xA8, 0xEF, 0x0A, 0x0C, 0xEA, 0x7C, 0xC4, 0xAD,
  41792. 0xCE, 0xE4, 0x59, 0xEB, 0x64, 0xDF, 0x08, 0xED,
  41793. 0x0F, 0xC2, 0x9F, 0xDC, 0x3C, 0x7B, 0x76, 0x2B,
  41794. 0x39, 0x93, 0x32, 0x06, 0x33, 0x40, 0xD4, 0x73,
  41795. 0x96, 0x62, 0x19, 0xBF, 0xC8, 0x7B, 0x4A, 0x3C,
  41796. 0x91, 0xC8, 0x0F, 0x0E, 0x4B, 0xA8, 0x6A, 0xA1,
  41797. 0x87, 0x9C, 0x76, 0x62, 0x5C, 0x86, 0x80, 0xA2,
  41798. 0x27, 0xAB, 0x22, 0x78, 0x06, 0x59, 0xD4, 0xB5,
  41799. 0xD3, 0x0E, 0x0E, 0x9A, 0x0D, 0xCE, 0x09, 0x4D,
  41800. 0xAF, 0x53, 0x76, 0x79, 0x27, 0x3A, 0x9B, 0x27,
  41801. 0x7E, 0xD2, 0xA2, 0xE2, 0x50, 0xEE, 0xA0, 0x93,
  41802. 0x82, 0x04, 0xC9, 0xE9, 0x63, 0xD3, 0x38, 0x52,
  41803. 0x2A, 0x3D, 0x1A, 0x44, 0x40, 0xE2, 0xA1, 0x23,
  41804. 0x97, 0xA5, 0xB9, 0x7D, 0x35, 0x65, 0x73, 0x07,
  41805. 0xBE, 0xC9, 0x4C, 0xC0, 0xC7, 0x2C, 0x5C, 0x6B,
  41806. 0x09, 0xDA, 0xF2, 0xBA, 0xF0, 0x02, 0x0B, 0x7D,
  41807. 0x8C, 0xA5, 0x60, 0xBF, 0x65, 0x96, 0x92, 0x9A,
  41808. 0xC8, 0xD4, 0xE5, 0x46, 0x0F, 0x78, 0x37, 0xB4,
  41809. 0x1B, 0x4A, 0xE6, 0xFF, 0x12, 0x33, 0x9D, 0xB8,
  41810. 0xEB, 0xD7, 0x02, 0x8A, 0xAC, 0xFE, 0x0B, 0x42,
  41811. 0xE0, 0x2C, 0xDE, 0x90, 0x67, 0x83, 0xAB, 0xFF,
  41812. 0x69, 0x4E, 0x7C, 0xBE, 0x08, 0x97, 0xED, 0x6E,
  41813. 0xD4, 0x38, 0xAC, 0xDB, 0x00, 0xA4, 0x70, 0x9C,
  41814. 0xFE, 0xF7, 0x15, 0x0E, 0xBE, 0xB0, 0x8C, 0x8F,
  41815. 0xF6, 0xC1, 0x54, 0x38, 0x15, 0xF4, 0xB8, 0x95,
  41816. 0x1C, 0x3C, 0xAC, 0xE4, 0x99, 0x58, 0x64, 0x58,
  41817. 0xA7, 0x3C, 0x85, 0x72, 0x38, 0x9A, 0xFC, 0x97,
  41818. 0x03, 0xA7, 0xFE, 0xAF, 0x67, 0x34, 0x45, 0xFB,
  41819. 0x4B, 0x0C, 0xCA, 0xA5, 0x11, 0xD4, 0xA2, 0xCF,
  41820. 0x46, 0x3F, 0x57, 0xE3, 0xA6, 0xD7, 0x2D, 0xA0,
  41821. 0x4B, 0x25, 0x66, 0x99, 0xA3, 0x02, 0x12, 0xE7,
  41822. 0xC5, 0x76, 0x8E, 0xFC, 0x15, 0x1B, 0x71, 0x74,
  41823. 0x41, 0x56, 0x57, 0x5A, 0x2E, 0x94, 0x43, 0x31,
  41824. 0x92, 0x32, 0xD1, 0x59, 0xC6, 0xCC, 0x00, 0x6F,
  41825. 0xDB, 0x57, 0xC5, 0x81, 0x73, 0xAD, 0x8D, 0x2C,
  41826. 0x86, 0x6C, 0x88, 0x87, 0x43, 0x7C, 0x22, 0x38,
  41827. 0x88, 0xE2, 0x1E, 0xF6, 0x7E, 0x1A, 0x33, 0x2C,
  41828. 0x1F, 0xDF, 0xCC, 0x15, 0xEF, 0x17, 0x47, 0x6F,
  41829. 0xE0, 0xFB, 0x57, 0xD4, 0x22, 0x98, 0x94, 0x72,
  41830. 0x5E, 0x14, 0x74, 0xC1, 0xBA, 0x12, 0x16, 0x56,
  41831. 0x28, 0x17, 0xF1, 0x6C, 0x53, 0xEC, 0xE0, 0x1C,
  41832. 0x7F, 0x9E, 0x36, 0x64, 0xEE, 0xDB, 0xBA, 0x94,
  41833. 0x95, 0x29, 0x87, 0x43, 0x1A, 0xA2, 0xA5, 0x7D,
  41834. 0x33, 0x0E, 0xB1, 0x1B, 0x28, 0xE6, 0xBF, 0x77,
  41835. 0x0E, 0x34, 0x9E, 0xCE, 0x35, 0x0C, 0x83, 0xE9,
  41836. 0x0D, 0xA6, 0xFE, 0x0D, 0x0A, 0x4A, 0xB9, 0x71,
  41837. 0x5D, 0xB2, 0x8B, 0xDD, 0x39, 0x7F, 0xAF, 0xA1,
  41838. 0x42, 0x83, 0x02, 0x15, 0x1E, 0x1F, 0x22, 0x2B,
  41839. 0x44, 0x69, 0x87, 0x9E, 0xB5, 0xD0, 0xF0, 0x18,
  41840. 0x60, 0x6A, 0x75, 0x94, 0xBF, 0xC8, 0x2C, 0x39,
  41841. 0x4E, 0x91, 0xB9, 0x26, 0x44, 0x95, 0xC9, 0x06,
  41842. 0x3D, 0x50, 0x52, 0x62, 0x79, 0x9B, 0x9F, 0xCB,
  41843. 0xE6, 0x31, 0x6B, 0xBC, 0xC8, 0xD8, 0x09, 0x30,
  41844. 0x53, 0x63, 0x6A, 0x74, 0xD4, 0xFA, 0x00, 0x00,
  41845. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  41846. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  41847. 0x00, 0x00, 0x00, 0x02, 0x0F, 0x16, 0x1B, 0x1F,
  41848. 0x29, 0x2E, 0x36
  41849. };
  41850. #endif
  41851. #else
  41852. #ifndef WOLFSSL_NO_ML_DSA_44
  41853. static const byte pk_44[] = {
  41854. 0x35, 0x07, 0x31, 0x3A, 0xE3, 0x7A, 0xF6, 0x96,
  41855. 0x6C, 0x11, 0xA9, 0xE4, 0x0B, 0xEB, 0xEC, 0xE9,
  41856. 0x2B, 0x67, 0x3F, 0xD2, 0x67, 0x3C, 0x1C, 0x4C,
  41857. 0x08, 0xF0, 0x45, 0xA9, 0xDD, 0x5A, 0xB8, 0x8C,
  41858. 0x0A, 0x51, 0xA9, 0xBA, 0x89, 0x0F, 0x4C, 0xCB,
  41859. 0x9D, 0x0A, 0x41, 0x3F, 0x9C, 0xF4, 0x13, 0x36,
  41860. 0x79, 0x49, 0x00, 0x90, 0xBB, 0x57, 0x3B, 0xBD,
  41861. 0x2E, 0x18, 0xB3, 0xD0, 0xA5, 0x0E, 0x6B, 0x67,
  41862. 0xFF, 0x98, 0x8C, 0xDD, 0x07, 0xE8, 0xA7, 0xA1,
  41863. 0x3F, 0xAE, 0xFB, 0xD6, 0xC0, 0xF8, 0xF3, 0x34,
  41864. 0xA5, 0x17, 0xC2, 0x34, 0x88, 0x92, 0x65, 0xA6,
  41865. 0xE8, 0x66, 0x57, 0xFE, 0x86, 0x08, 0xF7, 0xDF,
  41866. 0xA0, 0x5B, 0x70, 0x3E, 0x91, 0x6C, 0x63, 0xA0,
  41867. 0xA3, 0x75, 0x55, 0xF8, 0xB6, 0xAA, 0xD4, 0x1B,
  41868. 0x78, 0x5E, 0x42, 0x9F, 0x96, 0xE4, 0xA0, 0x50,
  41869. 0xB6, 0x94, 0x2D, 0xC3, 0xE3, 0x36, 0x2B, 0x9D,
  41870. 0x6B, 0x7A, 0xEF, 0xF5, 0x68, 0xF2, 0x11, 0xDF,
  41871. 0x87, 0xA0, 0x9A, 0xC4, 0x61, 0xFB, 0xA4, 0x1C,
  41872. 0x98, 0x3F, 0xC9, 0x52, 0x59, 0x3B, 0x47, 0x4D,
  41873. 0xF5, 0x24, 0xA3, 0xD8, 0x63, 0xE1, 0xED, 0xDC,
  41874. 0xFD, 0xEB, 0x96, 0xFB, 0xF3, 0xE7, 0x50, 0x9C,
  41875. 0x72, 0x61, 0xC7, 0x3C, 0xCE, 0xF2, 0xEB, 0x22,
  41876. 0x55, 0x6B, 0x9F, 0x25, 0xE4, 0x45, 0xE1, 0xFB,
  41877. 0x3E, 0x2E, 0x4E, 0x92, 0x4F, 0x8A, 0x85, 0xEB,
  41878. 0x63, 0x2C, 0x05, 0x0F, 0x9A, 0xEC, 0x0E, 0x9D,
  41879. 0x05, 0x81, 0x46, 0x82, 0xEA, 0x74, 0x91, 0xD5,
  41880. 0x2A, 0xBC, 0xCC, 0xBB, 0xD6, 0x7F, 0x5F, 0x9A,
  41881. 0xD3, 0xBD, 0xEB, 0x14, 0xBA, 0x84, 0x27, 0x13,
  41882. 0x32, 0xB5, 0xF3, 0x71, 0xAC, 0x47, 0x19, 0x6B,
  41883. 0x5E, 0x43, 0x50, 0xC2, 0xA8, 0x82, 0xF5, 0x97,
  41884. 0x9B, 0x27, 0x62, 0xFB, 0xB7, 0xFF, 0x6B, 0xC8,
  41885. 0x52, 0x1E, 0xFB, 0x97, 0x39, 0x1E, 0x7F, 0x01,
  41886. 0xF8, 0x34, 0x47, 0xAA, 0xB2, 0x64, 0xB5, 0x9E,
  41887. 0x28, 0x18, 0xCB, 0x4A, 0x94, 0xBE, 0x6A, 0x43,
  41888. 0x5B, 0xAE, 0x21, 0xA4, 0x63, 0x64, 0x46, 0x0C,
  41889. 0x6B, 0x36, 0x1C, 0x2A, 0x3B, 0x64, 0xFA, 0xA0,
  41890. 0xAB, 0xE3, 0x3B, 0x7D, 0xB0, 0x23, 0x99, 0x21,
  41891. 0x55, 0x59, 0xBF, 0xD6, 0xDB, 0xB8, 0xDB, 0x09,
  41892. 0x5E, 0xBC, 0x32, 0x3C, 0xAC, 0xAB, 0x1A, 0x63,
  41893. 0x32, 0x21, 0x10, 0xD5, 0x8D, 0x7A, 0x5F, 0xCE,
  41894. 0x72, 0x8D, 0x2A, 0xED, 0x1D, 0x30, 0x38, 0x5D,
  41895. 0x3E, 0x62, 0xC2, 0x8E, 0xC9, 0x9F, 0x8C, 0x50,
  41896. 0x3F, 0xC6, 0xCE, 0x86, 0x4D, 0x67, 0x3D, 0x09,
  41897. 0xB6, 0x27, 0x14, 0x57, 0x14, 0xED, 0xC9, 0x8F,
  41898. 0xAC, 0x9E, 0xAC, 0x6F, 0xB5, 0xB2, 0xE6, 0x8D,
  41899. 0x9D, 0x5E, 0xE6, 0x78, 0x77, 0x09, 0x94, 0x35,
  41900. 0x5E, 0x3B, 0x64, 0x04, 0x38, 0xD4, 0x5B, 0x04,
  41901. 0xB8, 0x6C, 0x33, 0x97, 0xE1, 0x58, 0x54, 0x32,
  41902. 0xB3, 0x0F, 0x37, 0x69, 0x39, 0xCE, 0x57, 0x31,
  41903. 0x5C, 0x75, 0xA8, 0x94, 0xD0, 0x39, 0x2D, 0xB4,
  41904. 0x73, 0xA7, 0xA4, 0x7C, 0xBE, 0x34, 0x03, 0x2D,
  41905. 0x99, 0x1D, 0xDF, 0x32, 0x26, 0xB7, 0x45, 0x1B,
  41906. 0x03, 0xCD, 0xEE, 0x9D, 0x58, 0xA8, 0xA7, 0x76,
  41907. 0x1B, 0x17, 0x42, 0xD9, 0x69, 0x0F, 0x26, 0x3A,
  41908. 0x9D, 0x70, 0x9B, 0x4E, 0x81, 0xEB, 0x96, 0x02,
  41909. 0xB5, 0xB3, 0x92, 0x31, 0xFE, 0xBC, 0x38, 0x11,
  41910. 0x5A, 0x47, 0xED, 0x0A, 0x2A, 0xE2, 0xB8, 0x47,
  41911. 0x13, 0x5E, 0x43, 0x97, 0xD5, 0xFA, 0x31, 0x02,
  41912. 0x58, 0xE9, 0x9E, 0xB5, 0x3F, 0x85, 0x92, 0x0E,
  41913. 0xB9, 0xDB, 0xE0, 0xEE, 0x56, 0x76, 0x64, 0x8F,
  41914. 0xF2, 0xE2, 0x47, 0x81, 0xD4, 0xA4, 0x82, 0x43,
  41915. 0x69, 0xAE, 0x8E, 0x48, 0x50, 0x84, 0x93, 0x3B,
  41916. 0x9C, 0x65, 0xD3, 0x6F, 0xCD, 0x90, 0xA0, 0xD8,
  41917. 0xA0, 0xE1, 0x79, 0xCC, 0xD5, 0x1F, 0x71, 0x73,
  41918. 0x93, 0xE7, 0xB2, 0xB0, 0x78, 0x17, 0xD7, 0x79,
  41919. 0xDE, 0xCC, 0x83, 0x7D, 0x5A, 0xF2, 0x0E, 0xA6,
  41920. 0xB1, 0x76, 0x61, 0x15, 0x88, 0x8E, 0xD7, 0xA6,
  41921. 0x51, 0xBF, 0x9C, 0xD1, 0x0A, 0xFC, 0xDA, 0x65,
  41922. 0xA5, 0x65, 0xFE, 0xB2, 0xED, 0x07, 0x74, 0x42,
  41923. 0x4C, 0xF5, 0x42, 0x3D, 0xAF, 0x5F, 0x4D, 0x72,
  41924. 0x51, 0xE6, 0x3F, 0x68, 0xCC, 0xC5, 0x2D, 0x89,
  41925. 0x01, 0xD8, 0x80, 0xB4, 0xFC, 0xEB, 0x3B, 0xBE,
  41926. 0x7C, 0xFA, 0x24, 0x27, 0xE1, 0x05, 0x94, 0x67,
  41927. 0xAD, 0xB3, 0x47, 0x7D, 0x28, 0x18, 0xC1, 0xC9,
  41928. 0xB8, 0xA1, 0x2A, 0x95, 0xBB, 0x5D, 0xC9, 0x42,
  41929. 0x4F, 0x64, 0x94, 0x07, 0x5F, 0x65, 0xD3, 0xA5,
  41930. 0x65, 0xEE, 0x67, 0x2C, 0x10, 0x65, 0x81, 0x4D,
  41931. 0x7F, 0xAF, 0x2E, 0x97, 0x9E, 0x11, 0xA3, 0xF5,
  41932. 0x3E, 0xDE, 0xB1, 0x1D, 0x44, 0x72, 0x90, 0x74,
  41933. 0xFD, 0x47, 0x82, 0xA6, 0x04, 0x3E, 0x28, 0x3C,
  41934. 0x15, 0xDF, 0xC4, 0x7A, 0x7C, 0xF5, 0x5A, 0xC6,
  41935. 0xFB, 0xE4, 0xC2, 0xE0, 0x6E, 0x4C, 0x09, 0x2E,
  41936. 0xE3, 0xE6, 0x3A, 0xEF, 0xF6, 0x54, 0xDC, 0x92,
  41937. 0xBE, 0x8F, 0x24, 0x8E, 0x70, 0x53, 0x90, 0x3D,
  41938. 0x06, 0xA5, 0x0A, 0x72, 0xA0, 0x7B, 0x22, 0x14,
  41939. 0x80, 0x43, 0xAD, 0xDC, 0x11, 0xFC, 0xFF, 0xCF,
  41940. 0x5E, 0xA4, 0x69, 0x1C, 0x09, 0x09, 0xC3, 0x3D,
  41941. 0xF5, 0xE7, 0x05, 0x6F, 0x16, 0x33, 0x75, 0xB4,
  41942. 0x9B, 0x7B, 0x26, 0xDB, 0xE7, 0x27, 0x56, 0xD3,
  41943. 0x91, 0x82, 0x9D, 0xEB, 0x96, 0x3E, 0xE8, 0x40,
  41944. 0xAB, 0x5D, 0x6C, 0xB7, 0xA6, 0x36, 0x07, 0xD4,
  41945. 0xE7, 0x7C, 0xD4, 0x5C, 0x36, 0xE4, 0xFC, 0x7C,
  41946. 0x8A, 0x36, 0x8D, 0x53, 0x43, 0xD4, 0xAC, 0x0B,
  41947. 0x1B, 0xBA, 0x32, 0x88, 0xFA, 0xCE, 0xC1, 0xB9,
  41948. 0x34, 0x3C, 0xAC, 0xA0, 0xF4, 0xF2, 0x83, 0xA8,
  41949. 0xBB, 0x6F, 0x12, 0xC6, 0xB5, 0x3C, 0xDE, 0xA8,
  41950. 0x49, 0x66, 0x97, 0xD7, 0x7E, 0x37, 0xF7, 0xCE,
  41951. 0x7C, 0xF8, 0xC8, 0xBB, 0x8C, 0xB5, 0x3B, 0x3F,
  41952. 0xB9, 0x51, 0x68, 0x00, 0xD7, 0x2E, 0x1C, 0x10,
  41953. 0xAF, 0x9F, 0x3C, 0xD2, 0xAC, 0xE5, 0xBE, 0x94,
  41954. 0xB9, 0x60, 0xF5, 0xB2, 0x70, 0x24, 0xE8, 0x8A,
  41955. 0x2C, 0xD8, 0x95, 0xAF, 0xAA, 0xA9, 0xA5, 0x2B,
  41956. 0xCA, 0xE0, 0x58, 0x44, 0x02, 0x3F, 0xF8, 0x21,
  41957. 0x0C, 0x29, 0xB7, 0xD5, 0x08, 0x9E, 0x69, 0x81,
  41958. 0xD4, 0x6C, 0xC5, 0x0B, 0xF6, 0xEF, 0xAB, 0x01,
  41959. 0xEA, 0xDF, 0x36, 0x2C, 0x5C, 0xFB, 0xEB, 0xC8,
  41960. 0x4F, 0x71, 0x80, 0xD7, 0x00, 0xC9, 0x32, 0x5D,
  41961. 0x02, 0x4F, 0x96, 0x94, 0x71, 0xCD, 0x98, 0xC4,
  41962. 0x25, 0x7A, 0x92, 0xF1, 0x9B, 0xA0, 0x34, 0x30,
  41963. 0x6C, 0x41, 0x59, 0xD5, 0x01, 0x5D, 0xD6, 0x56,
  41964. 0xEA, 0x05, 0xF2, 0xFC, 0xF8, 0x58, 0xFA, 0x12,
  41965. 0x9C, 0x5A, 0x5C, 0xD5, 0x3D, 0xC7, 0x5D, 0x1B,
  41966. 0x99, 0x2A, 0x6A, 0x4C, 0xF9, 0xEA, 0x9D, 0x70,
  41967. 0x53, 0xBC, 0xBE, 0xAD, 0x61, 0xC7, 0x2D, 0x77,
  41968. 0xEF, 0x61, 0xC7, 0xBE, 0x9C, 0x73, 0xC1, 0xD5,
  41969. 0xD4, 0x5C, 0x5F, 0x21, 0x6A, 0x5C, 0xEE, 0x78,
  41970. 0xAA, 0xC6, 0x6C, 0x56, 0xDB, 0x38, 0x5A, 0x94,
  41971. 0x12, 0xB8, 0x73, 0x7C, 0xDF, 0x9A, 0x27, 0xCD,
  41972. 0xC5, 0xD1, 0xD3, 0xCA, 0x0E, 0x37, 0x0A, 0xC1,
  41973. 0x6F, 0xAD, 0xE3, 0x32, 0x94, 0x6C, 0x20, 0xB5,
  41974. 0xED, 0xE6, 0x2D, 0x34, 0x39, 0x58, 0xD2, 0x1E,
  41975. 0x63, 0x8D, 0xFA, 0xFF, 0xB5, 0xE8, 0x40, 0xC8,
  41976. 0x42, 0x38, 0x7A, 0x01, 0x80, 0xFF, 0x52, 0x3F,
  41977. 0xE9, 0x89, 0x63, 0xAD, 0x91, 0x5F, 0xCE, 0x0A,
  41978. 0x47, 0x87, 0xF9, 0x6D, 0xD7, 0x79, 0xEF, 0xCE,
  41979. 0x10, 0x7B, 0x73, 0x43, 0xBE, 0x51, 0xA0, 0xDF,
  41980. 0xE5, 0xEC, 0xA9, 0x63, 0xF6, 0x5E, 0x72, 0x36,
  41981. 0x22, 0x86, 0xEE, 0x4E, 0x4A, 0x76, 0xFD, 0x86,
  41982. 0xBA, 0xE6, 0xD6, 0xC4, 0xD2, 0xE6, 0xFF, 0xB2,
  41983. 0x5B, 0x39, 0xF9, 0xC3, 0x29, 0xA8, 0x61, 0x3A,
  41984. 0x33, 0x34, 0x89, 0xC9, 0x83, 0xF9, 0xB2, 0x70,
  41985. 0x21, 0x54, 0x44, 0x94, 0x70, 0xAD, 0x70, 0x18,
  41986. 0x84, 0x38, 0x91, 0xFB, 0xDE, 0x5E, 0x3D, 0xE3,
  41987. 0xB2, 0xA7, 0x3C, 0x1D, 0x49, 0xA6, 0x66, 0x7C,
  41988. 0x4B, 0xEB, 0xB0, 0xA7, 0x7C, 0xC5, 0xAE, 0x45,
  41989. 0x1F, 0xBE, 0x0E, 0x2F, 0x11, 0xDC, 0x92, 0x08,
  41990. 0xAA, 0x18, 0x38, 0xFE, 0x61, 0xBE, 0x9D, 0xC3,
  41991. 0x3A, 0x1F, 0x2F, 0xB6, 0x6E, 0xB6, 0x54, 0x97,
  41992. 0x74, 0x06, 0xBC, 0x12, 0x2D, 0x64, 0x18, 0x14,
  41993. 0x25, 0x5A, 0xCB, 0x7B, 0xD7, 0x9D, 0xC3, 0x2C,
  41994. 0xC2, 0x0B, 0x19, 0x10, 0xD2, 0x57, 0xF0, 0xDF,
  41995. 0xA4, 0x95, 0xA4, 0x5A, 0xA0, 0x2D, 0x0F, 0xA0,
  41996. 0xBC, 0xF7, 0x60, 0x7F, 0x38, 0xE1, 0x17, 0x0D,
  41997. 0x36, 0x08, 0xF5, 0xF9, 0x75, 0x28, 0x75, 0xAC,
  41998. 0xA9, 0x2B, 0x75, 0xC4, 0x41, 0xE0, 0x0D, 0x5C,
  41999. 0xBC, 0x5F, 0x49, 0x16, 0x25, 0x38, 0x16, 0xE1,
  42000. 0x0C, 0x2C, 0x9C, 0x63, 0xA8, 0x5F, 0x70, 0xF4,
  42001. 0x64, 0xC7, 0x10, 0x19, 0x52, 0x19, 0x6E, 0x9B,
  42002. 0x5C, 0x09, 0x4F, 0xEE, 0xB6, 0x7C, 0x85, 0xC9,
  42003. 0x6E, 0xCB, 0x33, 0x32, 0x42, 0x9D, 0x57, 0x18,
  42004. 0xE6, 0x55, 0x94, 0x74, 0x02, 0xEE, 0xEB, 0xAA,
  42005. 0xF7, 0xD3, 0x45, 0x7A, 0x49, 0x6F, 0x83, 0x89,
  42006. 0x00, 0xE4, 0xAA, 0x20, 0x87, 0x10, 0xAD, 0xC0,
  42007. 0x0E, 0xF5, 0x93, 0x57, 0xE5, 0x45, 0x7A, 0xBD,
  42008. 0x82, 0x87, 0x50, 0x0F, 0xE1, 0x2C, 0x0C, 0x6D,
  42009. 0xEE, 0xC8, 0x94, 0xB8, 0x39, 0xF3, 0x3C, 0xFE,
  42010. 0x7E, 0xC1, 0x0F, 0xB4, 0x67, 0xA2, 0xDF, 0xC6,
  42011. 0x9D, 0xB5, 0x9D, 0xB8, 0x72, 0x50, 0xBD, 0xB3,
  42012. 0xDB, 0xF6, 0x87, 0x5E, 0x26, 0x93, 0xF0, 0xD4,
  42013. 0x0D, 0x68, 0xA4, 0x8B, 0xBD, 0x2C, 0x6E, 0xD8,
  42014. 0x4F, 0x81, 0x5D, 0x0D, 0xAC, 0x72, 0x65, 0xEC,
  42015. 0x4E, 0xF2, 0x4E, 0x5F, 0x67, 0x04, 0xF3, 0x08,
  42016. 0x29, 0x4D, 0xB2, 0xE2, 0xD5, 0x9F, 0xD4, 0xB9,
  42017. 0x13, 0xB4, 0x33, 0x80, 0x27, 0x84, 0x7E, 0xF4
  42018. };
  42019. static const byte msg_44[] = {
  42020. 0x5C, 0x70, 0x7F, 0xBF, 0xF4, 0xFF, 0xE5, 0x9B,
  42021. 0x09, 0xAA, 0xF8, 0xDB, 0x21, 0xAD, 0xBE, 0xBA,
  42022. 0xC6, 0xB2, 0x65, 0x37, 0x9A, 0x9A, 0x43, 0x3A,
  42023. 0xA8, 0x23, 0x2B, 0x13, 0x9B, 0xBD, 0x46, 0x37,
  42024. 0x30, 0x60, 0xA7, 0x5B, 0xC4, 0x48, 0x63, 0x5F,
  42025. 0x41, 0x35, 0x38, 0x69, 0xF9, 0x6F, 0xB5, 0x65,
  42026. 0x26, 0xDB, 0xAE, 0xB7, 0x5C, 0xFE, 0x2C, 0x03,
  42027. 0xCB, 0x43, 0x08, 0x58, 0x5E, 0x27, 0xD1, 0x42,
  42028. 0x14, 0xF2, 0x4B, 0xD7, 0x13, 0xE4, 0x96, 0x74,
  42029. 0x6A, 0xC1, 0x36, 0xC7, 0x9D, 0x0F, 0x7D, 0xB0,
  42030. 0x7B, 0x8A, 0x3A, 0x6D, 0x00, 0x5B, 0x29, 0x7B,
  42031. 0x37, 0xBA, 0x3F, 0x5B, 0xBD, 0xCE, 0x21, 0x77,
  42032. 0xFD, 0xD6, 0x78, 0x77, 0x20, 0x31, 0xF0, 0x60,
  42033. 0x49, 0xAE, 0x12, 0x86, 0x7A, 0x64, 0xBD, 0x0B,
  42034. 0x9E, 0xC6, 0x26, 0x80, 0x9E, 0xCE, 0x19, 0x8D,
  42035. 0x6A, 0x6B, 0x09, 0x03, 0x45, 0xDF, 0x22, 0x7D
  42036. };
  42037. static const byte sig_44[] = {
  42038. 0x08, 0xF0, 0x10, 0xFA, 0x63, 0x3F, 0x2B, 0xA1,
  42039. 0x46, 0x81, 0x34, 0xC4, 0xBC, 0xAB, 0x62, 0x17,
  42040. 0x0B, 0x64, 0xEA, 0x00, 0x2D, 0xD6, 0x8A, 0xE5,
  42041. 0xC2, 0x45, 0x29, 0xB9, 0xEC, 0x6F, 0x3B, 0xF2,
  42042. 0xDC, 0x2F, 0xC7, 0x34, 0x5A, 0x1E, 0xFE, 0x0C,
  42043. 0xCA, 0xB9, 0x6A, 0xD8, 0xDA, 0xBA, 0xAA, 0x80,
  42044. 0x90, 0xDC, 0x8C, 0x6C, 0x22, 0xFF, 0xC4, 0x90,
  42045. 0x9E, 0xE9, 0xA5, 0x45, 0xFC, 0xE8, 0x64, 0x53,
  42046. 0x9E, 0xC4, 0x17, 0xE1, 0xB2, 0x1A, 0x31, 0x40,
  42047. 0x26, 0x9D, 0x5E, 0x03, 0x6A, 0xC6, 0x09, 0x19,
  42048. 0xDD, 0xB3, 0x63, 0xE0, 0x35, 0xCD, 0xB4, 0x2E,
  42049. 0x25, 0x38, 0x6E, 0x6C, 0x76, 0xA9, 0x19, 0x75,
  42050. 0x68, 0x6E, 0xB7, 0xAB, 0xAD, 0x8F, 0x63, 0x64,
  42051. 0x97, 0x4E, 0x56, 0x82, 0x30, 0x45, 0x86, 0x22,
  42052. 0x64, 0xDA, 0xD2, 0xAE, 0x54, 0x70, 0x5C, 0xF1,
  42053. 0xEB, 0xD1, 0x84, 0x8D, 0xFF, 0x86, 0x15, 0xE6,
  42054. 0x20, 0xCE, 0x14, 0x89, 0xEF, 0xFA, 0x2E, 0xF8,
  42055. 0x60, 0xCA, 0x53, 0x52, 0xE4, 0xD5, 0xC8, 0x2E,
  42056. 0x50, 0xD5, 0x9D, 0x90, 0xA6, 0x12, 0xC7, 0xF1,
  42057. 0x70, 0x0D, 0xE2, 0x89, 0x5B, 0x31, 0x6A, 0x21,
  42058. 0x79, 0x9C, 0xBE, 0x77, 0x6E, 0xA6, 0xBF, 0x51,
  42059. 0x05, 0x2A, 0x83, 0x50, 0x7E, 0x86, 0x14, 0xD1,
  42060. 0x50, 0x53, 0x1F, 0x1C, 0x5E, 0x50, 0x24, 0x69,
  42061. 0x6C, 0x91, 0x55, 0x35, 0x19, 0x6F, 0xE0, 0xDC,
  42062. 0xB5, 0xD6, 0x48, 0x7E, 0x78, 0x61, 0x59, 0x2C,
  42063. 0xD0, 0x1B, 0x42, 0x58, 0xAF, 0x7A, 0x39, 0xCA,
  42064. 0x02, 0x1C, 0x50, 0xEF, 0xE9, 0xE1, 0xDE, 0x31,
  42065. 0x8D, 0x09, 0x51, 0xC9, 0xDB, 0x16, 0xF9, 0xB9,
  42066. 0x45, 0x54, 0x81, 0x16, 0xD7, 0x14, 0xD8, 0xBE,
  42067. 0x9C, 0xCA, 0x53, 0xFE, 0x8F, 0x24, 0x99, 0x0D,
  42068. 0xBA, 0x7F, 0x99, 0x42, 0x11, 0x9B, 0x32, 0xDD,
  42069. 0x93, 0x5C, 0xBA, 0x2D, 0xD3, 0xB3, 0xF2, 0x48,
  42070. 0x13, 0x9C, 0x80, 0xBB, 0x8D, 0xF4, 0xC7, 0xAA,
  42071. 0xEB, 0xC6, 0xFD, 0xB8, 0x35, 0x95, 0x87, 0x2B,
  42072. 0x9E, 0xCF, 0x48, 0xF3, 0x2D, 0xFF, 0x70, 0xF4,
  42073. 0xCE, 0x35, 0x68, 0x7E, 0x9D, 0xDF, 0xD5, 0x0C,
  42074. 0xCD, 0xE3, 0x51, 0xB0, 0x90, 0x86, 0xE5, 0xD1,
  42075. 0xF1, 0x3B, 0x72, 0x42, 0x73, 0x07, 0x03, 0xE2,
  42076. 0xFB, 0x40, 0x3F, 0xD4, 0xC8, 0x30, 0xB6, 0x86,
  42077. 0x49, 0x8A, 0x17, 0xDB, 0x8F, 0x46, 0x6C, 0x3A,
  42078. 0xC3, 0x49, 0xCD, 0x59, 0x68, 0x81, 0x66, 0x03,
  42079. 0xD7, 0x24, 0xAF, 0x1F, 0x77, 0xC7, 0xFB, 0xF7,
  42080. 0x83, 0xCD, 0xA2, 0x6D, 0x35, 0x0C, 0x8B, 0xBC,
  42081. 0x29, 0x3A, 0x7F, 0xAC, 0xB9, 0xF9, 0x78, 0x50,
  42082. 0x6A, 0x67, 0xFC, 0xDC, 0x6F, 0x01, 0x65, 0x06,
  42083. 0x82, 0x81, 0xB0, 0x7D, 0x25, 0x5D, 0x74, 0x0B,
  42084. 0x68, 0x5F, 0x51, 0x2C, 0x82, 0xF3, 0x1D, 0x92,
  42085. 0xF6, 0xA9, 0xA9, 0x6A, 0x77, 0x57, 0x58, 0xAA,
  42086. 0x7C, 0xBE, 0x35, 0xF4, 0x56, 0xDE, 0x42, 0x01,
  42087. 0x2D, 0xB8, 0x28, 0x83, 0x7B, 0xA0, 0xA9, 0x7D,
  42088. 0xC3, 0x30, 0x13, 0x52, 0xD0, 0xA1, 0xC8, 0xA1,
  42089. 0x2C, 0x51, 0x49, 0xAE, 0xA8, 0x04, 0xCB, 0xA8,
  42090. 0x66, 0x01, 0x26, 0xDF, 0x2D, 0x1C, 0x21, 0xA2,
  42091. 0x4E, 0xBD, 0xA5, 0x48, 0x2A, 0x2D, 0x56, 0x60,
  42092. 0x20, 0x98, 0x4D, 0x15, 0x7D, 0x02, 0xB6, 0x3A,
  42093. 0xE4, 0x11, 0xAE, 0xF7, 0x3E, 0x5D, 0x56, 0x4F,
  42094. 0x6A, 0xA3, 0x0A, 0xEA, 0xCC, 0x35, 0x8A, 0xB7,
  42095. 0xC4, 0x8F, 0x25, 0x3E, 0x42, 0x41, 0x2B, 0xA5,
  42096. 0x1F, 0xA7, 0x3B, 0x87, 0x22, 0x86, 0x79, 0xD5,
  42097. 0xE5, 0x2A, 0xA2, 0xCD, 0x68, 0xCE, 0xB8, 0x18,
  42098. 0x6D, 0xEF, 0x1C, 0x36, 0x7F, 0x75, 0x50, 0x36,
  42099. 0x1B, 0x58, 0xEB, 0x32, 0xA1, 0xC8, 0xAF, 0x47,
  42100. 0xE1, 0x26, 0x73, 0x1F, 0x5D, 0x73, 0x30, 0x13,
  42101. 0x2F, 0xC7, 0x8B, 0xA3, 0x03, 0xB4, 0xA8, 0x86,
  42102. 0x25, 0x29, 0xD1, 0x75, 0x10, 0xEE, 0x7F, 0x56,
  42103. 0xBC, 0x0D, 0x59, 0xB4, 0xAE, 0xC9, 0x44, 0x0A,
  42104. 0xF7, 0x0D, 0xBF, 0x17, 0x6A, 0x22, 0x9C, 0x75,
  42105. 0x2B, 0x3E, 0x22, 0xB8, 0x2F, 0x4B, 0x68, 0xF1,
  42106. 0x07, 0xE3, 0x47, 0x47, 0x21, 0x9C, 0xA3, 0x5B,
  42107. 0x31, 0x0A, 0x14, 0xD9, 0x7C, 0xA8, 0xC0, 0xC6,
  42108. 0x5C, 0xAD, 0x05, 0xD6, 0x15, 0xD3, 0xEC, 0xEC,
  42109. 0x32, 0xC2, 0xFF, 0xF4, 0x96, 0x9C, 0xC8, 0x65,
  42110. 0xA0, 0xB2, 0xD6, 0xF4, 0x98, 0xBB, 0xB1, 0x4E,
  42111. 0xA5, 0x11, 0x3B, 0x4E, 0xA8, 0xEB, 0x90, 0xAB,
  42112. 0xD8, 0x25, 0x10, 0xE3, 0x66, 0xB5, 0xA5, 0x11,
  42113. 0x60, 0xA0, 0xCB, 0xDF, 0x77, 0x8A, 0x80, 0x4C,
  42114. 0x07, 0x9B, 0x1B, 0x45, 0x95, 0x29, 0x1D, 0x88,
  42115. 0x85, 0xAC, 0x32, 0x94, 0x26, 0x87, 0x12, 0x0A,
  42116. 0x2F, 0x9E, 0xAE, 0x69, 0x79, 0x25, 0x5A, 0x50,
  42117. 0xF4, 0xDB, 0x15, 0x20, 0x9F, 0x7A, 0x7A, 0xF2,
  42118. 0xE5, 0x8A, 0x63, 0x6A, 0xDD, 0xBD, 0x06, 0xCB,
  42119. 0x42, 0xF0, 0x20, 0xA9, 0x3B, 0x52, 0xD8, 0x68,
  42120. 0x37, 0x71, 0x07, 0xB8, 0x5B, 0xFE, 0xA0, 0xEC,
  42121. 0xBD, 0x75, 0xFF, 0x9C, 0x89, 0xDF, 0x01, 0xE7,
  42122. 0x17, 0x7D, 0xA7, 0xE8, 0x27, 0x9E, 0xA2, 0x41,
  42123. 0x66, 0xE6, 0xDB, 0x8B, 0x5A, 0x3F, 0x6C, 0xC9,
  42124. 0xE3, 0x4F, 0x0D, 0xD0, 0x92, 0x1E, 0x27, 0x41,
  42125. 0xF2, 0xB3, 0x08, 0x32, 0x03, 0x6D, 0x2C, 0x4F,
  42126. 0x78, 0xEC, 0x99, 0xB3, 0x94, 0x6C, 0xC1, 0x89,
  42127. 0xD9, 0x34, 0x0F, 0xEF, 0x10, 0xF0, 0xDA, 0xCE,
  42128. 0x09, 0x69, 0x7A, 0x93, 0xC6, 0xFF, 0x19, 0x4F,
  42129. 0xBD, 0xDE, 0xA6, 0x54, 0x8A, 0xE5, 0x81, 0x3F,
  42130. 0x96, 0xD3, 0xA0, 0x77, 0x7C, 0xF2, 0x4B, 0xF1,
  42131. 0x68, 0xA2, 0x23, 0x3D, 0xD4, 0x16, 0xC1, 0x66,
  42132. 0xDA, 0x13, 0x53, 0xE1, 0x9F, 0x9A, 0x36, 0x09,
  42133. 0x4D, 0x72, 0x08, 0x09, 0xEB, 0x87, 0x74, 0x9A,
  42134. 0xB2, 0x8C, 0x60, 0x7F, 0xFB, 0x70, 0x17, 0x51,
  42135. 0xB1, 0xAC, 0x18, 0xDF, 0xCB, 0x43, 0x2A, 0xD3,
  42136. 0x89, 0xDA, 0x78, 0xAE, 0xDC, 0xEA, 0xB2, 0x22,
  42137. 0xCA, 0x2F, 0xF1, 0xE4, 0xA7, 0xCC, 0xAF, 0xB1,
  42138. 0x63, 0x1B, 0x5D, 0xDD, 0xD1, 0x49, 0xB8, 0x90,
  42139. 0x2E, 0xC9, 0xC0, 0x83, 0x0D, 0xAB, 0x88, 0x88,
  42140. 0x4C, 0x74, 0x72, 0x00, 0x7D, 0xFE, 0xF2, 0x46,
  42141. 0x73, 0xFD, 0x99, 0xEC, 0x89, 0x8B, 0x3B, 0x0F,
  42142. 0xCE, 0x35, 0x5A, 0xEA, 0x13, 0x4F, 0x67, 0x67,
  42143. 0xFD, 0x0D, 0x87, 0xFC, 0xB1, 0x36, 0x48, 0x07,
  42144. 0x33, 0x0B, 0xCA, 0xD4, 0xD7, 0xD0, 0xCC, 0xA1,
  42145. 0x8F, 0xF0, 0x3F, 0x01, 0x8B, 0x6B, 0x74, 0x44,
  42146. 0x2F, 0x1B, 0xE0, 0x65, 0x31, 0x1B, 0x4E, 0xDB,
  42147. 0x67, 0x65, 0xA9, 0x34, 0xE8, 0x4D, 0x0C, 0xF3,
  42148. 0x29, 0xED, 0x53, 0xAB, 0x8A, 0x98, 0x07, 0x2B,
  42149. 0xE0, 0xCD, 0xC0, 0x08, 0x82, 0x4A, 0x72, 0x28,
  42150. 0x72, 0xA2, 0xAC, 0xFE, 0xF7, 0xBF, 0x6E, 0x8E,
  42151. 0xF8, 0x3E, 0x04, 0x58, 0xA4, 0x36, 0x46, 0x33,
  42152. 0xAB, 0xDD, 0x0E, 0xBF, 0x01, 0xD2, 0xEF, 0x19,
  42153. 0x5B, 0x78, 0x2B, 0x30, 0x51, 0x25, 0x50, 0xD0,
  42154. 0xB5, 0x82, 0xC7, 0x20, 0x0D, 0xA1, 0x2C, 0x38,
  42155. 0xAF, 0x44, 0xFC, 0xBD, 0x49, 0xB8, 0x7F, 0x89,
  42156. 0xEF, 0xBE, 0x37, 0x5C, 0xCB, 0xA2, 0x11, 0x75,
  42157. 0x7D, 0xDA, 0xA8, 0x7B, 0x3A, 0x3C, 0x10, 0x11,
  42158. 0x4D, 0x9F, 0x99, 0xAB, 0x4B, 0xA2, 0x20, 0x7A,
  42159. 0x5F, 0x96, 0xEF, 0x1C, 0x00, 0xD7, 0x27, 0x17,
  42160. 0x77, 0x7C, 0x51, 0x58, 0x4B, 0x13, 0x97, 0x53,
  42161. 0x2A, 0xC6, 0x86, 0x4D, 0x3B, 0x8E, 0xBB, 0x4F,
  42162. 0xB8, 0xA0, 0x84, 0x87, 0xF6, 0xEF, 0x55, 0x12,
  42163. 0x2B, 0xCF, 0x9E, 0x5C, 0xD0, 0x0E, 0xBC, 0x1E,
  42164. 0x79, 0x53, 0xE7, 0x8C, 0x4D, 0x8B, 0xCB, 0x20,
  42165. 0xF6, 0xEA, 0x72, 0x0A, 0x63, 0x2F, 0x0C, 0xCF,
  42166. 0x57, 0x27, 0x26, 0xF4, 0x3A, 0x95, 0xCA, 0xBE,
  42167. 0xB5, 0x7C, 0x47, 0x60, 0x10, 0xCD, 0x28, 0x9E,
  42168. 0x02, 0x64, 0xC9, 0x8D, 0x82, 0x49, 0xD0, 0xD6,
  42169. 0x60, 0xF8, 0xDC, 0xC8, 0x4B, 0x7D, 0xB5, 0xEF,
  42170. 0x11, 0x17, 0xC7, 0x94, 0x5F, 0x0D, 0x99, 0xBE,
  42171. 0x75, 0x48, 0x49, 0xC6, 0x58, 0x43, 0x64, 0x99,
  42172. 0x1A, 0x5A, 0x41, 0xBA, 0xC2, 0x31, 0xB3, 0xE0,
  42173. 0x45, 0x1B, 0x81, 0xD2, 0x12, 0xBE, 0x90, 0xDB,
  42174. 0xFF, 0xBC, 0xCB, 0x99, 0xA3, 0xF0, 0x74, 0xE8,
  42175. 0x2C, 0x48, 0x58, 0xB3, 0x17, 0xA4, 0x9A, 0xD2,
  42176. 0x22, 0x46, 0xFB, 0xF5, 0x85, 0x8D, 0x07, 0xDF,
  42177. 0xDB, 0x78, 0x07, 0xF4, 0x99, 0xA8, 0x6C, 0xEE,
  42178. 0x6E, 0x96, 0x20, 0xB8, 0xC2, 0xA9, 0xFA, 0x8B,
  42179. 0x6E, 0xA6, 0x79, 0x6D, 0xF9, 0xC3, 0x0C, 0x77,
  42180. 0x74, 0xAE, 0xB0, 0x40, 0xA9, 0xE5, 0xA7, 0x0B,
  42181. 0x30, 0x40, 0x4B, 0x4F, 0xB1, 0x0A, 0x0B, 0x7B,
  42182. 0xEE, 0x1F, 0x69, 0xFA, 0xD0, 0xF0, 0x2D, 0x5D,
  42183. 0x00, 0xB5, 0x4D, 0xEB, 0x32, 0x84, 0xB2, 0xB7,
  42184. 0x60, 0xAA, 0x6C, 0xF9, 0x98, 0x18, 0xB3, 0xD9,
  42185. 0xC1, 0x54, 0x8D, 0xAC, 0x12, 0xB0, 0x3A, 0x26,
  42186. 0xB2, 0x23, 0x2D, 0x9B, 0xF8, 0x20, 0xEE, 0x90,
  42187. 0xE0, 0x6D, 0x31, 0xDE, 0xF5, 0xCA, 0xBA, 0x6A,
  42188. 0x53, 0x40, 0x29, 0x6C, 0x18, 0x62, 0xA5, 0x8A,
  42189. 0xB8, 0x17, 0xA0, 0xAB, 0xCB, 0xDC, 0xE1, 0x3B,
  42190. 0xD6, 0xC6, 0x29, 0xA3, 0x1C, 0x5F, 0x8D, 0x6E,
  42191. 0x73, 0xF6, 0x98, 0x10, 0x0F, 0x9F, 0x7E, 0xCA,
  42192. 0x4C, 0xD8, 0xEB, 0xE4, 0xB8, 0xDF, 0x72, 0x78,
  42193. 0x65, 0xAF, 0x4A, 0x20, 0xFE, 0x7C, 0xB4, 0xCA,
  42194. 0x07, 0x81, 0xFD, 0xC5, 0xC5, 0xFD, 0x33, 0x4D,
  42195. 0xB8, 0x37, 0x37, 0xC4, 0x21, 0x81, 0x66, 0x45,
  42196. 0xAE, 0x81, 0x34, 0x13, 0xA6, 0x40, 0x81, 0x39,
  42197. 0x55, 0x90, 0xE6, 0xF1, 0x42, 0x56, 0x74, 0xFF,
  42198. 0x06, 0x9B, 0x50, 0x1F, 0x0F, 0xDA, 0x6B, 0x31,
  42199. 0xC6, 0x4B, 0xC5, 0xC2, 0x14, 0xE7, 0x01, 0x5E,
  42200. 0xA9, 0xDA, 0x12, 0x2D, 0x6C, 0xE0, 0x8C, 0xEB,
  42201. 0x2D, 0xF6, 0x2C, 0x45, 0xBC, 0x01, 0x73, 0x34,
  42202. 0x6D, 0xAB, 0xBC, 0x15, 0x4C, 0x16, 0x03, 0x35,
  42203. 0x9D, 0xD4, 0xF0, 0xAC, 0x49, 0x84, 0x4A, 0xEE,
  42204. 0x46, 0x47, 0x64, 0x93, 0xF2, 0x49, 0x59, 0x86,
  42205. 0x26, 0xFB, 0x24, 0x6B, 0x99, 0xB3, 0x9A, 0xCB,
  42206. 0xB4, 0x2B, 0x28, 0x4E, 0x0C, 0x2D, 0x3F, 0x9E,
  42207. 0xCE, 0x32, 0x71, 0xC4, 0xD5, 0xE0, 0x6C, 0x48,
  42208. 0x25, 0xEA, 0x1A, 0x8F, 0x08, 0x57, 0x23, 0x85,
  42209. 0x89, 0xCD, 0xC5, 0x48, 0x37, 0x19, 0x8E, 0xD4,
  42210. 0x23, 0x4D, 0xD0, 0x31, 0x73, 0xA8, 0x8E, 0x43,
  42211. 0xEE, 0x95, 0x67, 0xF5, 0x7A, 0x93, 0x27, 0xD3,
  42212. 0x90, 0x36, 0x30, 0x4C, 0xA1, 0xCD, 0xB5, 0xF8,
  42213. 0x65, 0xC5, 0x89, 0x54, 0x57, 0x2C, 0xAE, 0xF8,
  42214. 0x75, 0xF1, 0x2E, 0x14, 0x14, 0x14, 0x0D, 0x97,
  42215. 0x5B, 0x24, 0x52, 0x46, 0x7A, 0x57, 0x6D, 0x9C,
  42216. 0x4C, 0x79, 0xDB, 0x0A, 0xE0, 0x23, 0x69, 0x52,
  42217. 0x9B, 0xF8, 0x1B, 0x54, 0x40, 0x18, 0xDF, 0xE0,
  42218. 0x1E, 0xF0, 0x61, 0xE4, 0x79, 0x81, 0xF9, 0x98,
  42219. 0x9A, 0x8C, 0x48, 0xFF, 0x86, 0x93, 0x0B, 0x68,
  42220. 0x96, 0x78, 0x2F, 0xF1, 0x2D, 0xDC, 0x60, 0x1F,
  42221. 0x8B, 0x1C, 0x04, 0x43, 0x4E, 0x60, 0x96, 0x5B,
  42222. 0x8A, 0xF6, 0x89, 0xCC, 0xC8, 0xB2, 0x9B, 0xBF,
  42223. 0x87, 0x16, 0x2E, 0xA8, 0x6F, 0x9B, 0x4B, 0xFD,
  42224. 0x74, 0x4E, 0x8F, 0x36, 0x33, 0x23, 0xDE, 0x94,
  42225. 0xD2, 0xA1, 0x72, 0x4F, 0xB2, 0xE6, 0x75, 0x3D,
  42226. 0x6E, 0x47, 0x9B, 0xDB, 0x58, 0xE5, 0x4A, 0x0C,
  42227. 0x09, 0x8F, 0x9C, 0x83, 0x63, 0x98, 0x8B, 0xA4,
  42228. 0xF7, 0x3D, 0x01, 0xA6, 0x8B, 0x93, 0x97, 0x48,
  42229. 0x84, 0x75, 0x32, 0xC7, 0xD7, 0x03, 0xDF, 0x7E,
  42230. 0x94, 0x8C, 0x8A, 0xA6, 0x78, 0x1A, 0xAE, 0xDE,
  42231. 0x36, 0x8A, 0xAD, 0x13, 0x7E, 0xF0, 0x16, 0xC2,
  42232. 0x3B, 0xAF, 0xF9, 0xD8, 0x66, 0x12, 0x30, 0x72,
  42233. 0x76, 0x6D, 0x21, 0x4C, 0xF3, 0xEF, 0x0D, 0x8C,
  42234. 0x11, 0xA4, 0x12, 0xBE, 0xF5, 0x7E, 0x8E, 0x6A,
  42235. 0x11, 0x13, 0x48, 0x8D, 0xC2, 0x62, 0xCF, 0x45,
  42236. 0x7C, 0xE3, 0x91, 0x88, 0x59, 0xFF, 0xB0, 0xF1,
  42237. 0xC3, 0xBC, 0x1D, 0x2A, 0x3E, 0x9B, 0x78, 0xF3,
  42238. 0xB1, 0x2E, 0xB0, 0x27, 0xD8, 0x16, 0xF8, 0x9B,
  42239. 0x2A, 0xAF, 0xF1, 0xAB, 0xB0, 0xF1, 0x8C, 0x7F,
  42240. 0x94, 0x31, 0x97, 0x85, 0xDA, 0xF0, 0xF4, 0x27,
  42241. 0x51, 0x3E, 0x5A, 0xE1, 0xDD, 0x6D, 0x9E, 0x98,
  42242. 0x39, 0xBB, 0xDF, 0xA2, 0xBA, 0x2C, 0x08, 0xAD,
  42243. 0x1D, 0x3F, 0x86, 0xF6, 0xC2, 0x1A, 0x8C, 0xAD,
  42244. 0xE0, 0xDC, 0xDD, 0x02, 0x47, 0x4C, 0x7E, 0x2D,
  42245. 0xDA, 0x1D, 0x70, 0x92, 0x39, 0xAA, 0x4E, 0xBA,
  42246. 0x14, 0xC7, 0xEC, 0x26, 0xBD, 0x9D, 0x1F, 0x6D,
  42247. 0x91, 0x58, 0x3C, 0xB5, 0xEF, 0x37, 0xB9, 0x66,
  42248. 0x4E, 0x04, 0x7C, 0x29, 0xCF, 0xD7, 0x8E, 0x47,
  42249. 0x84, 0xF3, 0xD2, 0x21, 0x84, 0xC5, 0xF8, 0xDC,
  42250. 0xC9, 0xF2, 0x52, 0xD5, 0x6A, 0xBF, 0xF1, 0xF1,
  42251. 0xDE, 0x9E, 0x7A, 0xF1, 0xD5, 0x5A, 0xF6, 0xEF,
  42252. 0x94, 0x66, 0xF9, 0x25, 0x44, 0x7F, 0x8D, 0x92,
  42253. 0xA2, 0x25, 0x1C, 0x72, 0x92, 0x30, 0x2A, 0xB7,
  42254. 0xEF, 0x18, 0xF3, 0x8C, 0xEF, 0x69, 0xA5, 0x5C,
  42255. 0x19, 0x3E, 0xC5, 0xBD, 0xEE, 0x2C, 0x2D, 0x71,
  42256. 0xDB, 0x89, 0xD4, 0x11, 0xA6, 0x27, 0x80, 0x8F,
  42257. 0x5A, 0x39, 0x9A, 0x04, 0x28, 0x4F, 0x9F, 0x00,
  42258. 0xBE, 0xF9, 0xF7, 0x9B, 0x46, 0x69, 0xD6, 0xAC,
  42259. 0x12, 0xE9, 0xA7, 0xC2, 0xD1, 0xC8, 0xAD, 0x5D,
  42260. 0xF7, 0xCB, 0x0C, 0x98, 0x78, 0x2D, 0x04, 0x4D,
  42261. 0x2D, 0x41, 0xAB, 0xC6, 0x3F, 0x81, 0x1D, 0xB9,
  42262. 0x2C, 0x1F, 0x3F, 0x59, 0x11, 0xF4, 0x80, 0x4F,
  42263. 0x0B, 0xCA, 0x9F, 0x81, 0x6E, 0x9C, 0xD1, 0xB4,
  42264. 0x74, 0x06, 0x48, 0x0A, 0x87, 0x2C, 0xFD, 0x4D,
  42265. 0x85, 0xD4, 0x21, 0x65, 0x7C, 0x96, 0x69, 0x53,
  42266. 0x51, 0xC0, 0xC4, 0xB0, 0xEB, 0x20, 0xDB, 0xE0,
  42267. 0x41, 0x09, 0xA7, 0x62, 0xB2, 0xF3, 0xC7, 0x6A,
  42268. 0x1D, 0x53, 0xA0, 0x39, 0xBA, 0xCF, 0x78, 0x9E,
  42269. 0xBF, 0x1D, 0xA5, 0x98, 0x09, 0x8E, 0xA7, 0x1A,
  42270. 0xE7, 0x95, 0xFF, 0x10, 0x38, 0xCC, 0x8F, 0x44,
  42271. 0xCB, 0xE7, 0xF6, 0xD6, 0x2C, 0xFF, 0xA8, 0x1C,
  42272. 0xFF, 0xA3, 0x65, 0xE8, 0x4E, 0xAE, 0xC7, 0xEF,
  42273. 0x61, 0xE1, 0x16, 0x4B, 0x8C, 0xA8, 0xC8, 0xFB,
  42274. 0xA5, 0x2C, 0xD1, 0x0A, 0x39, 0xAB, 0x4A, 0xF9,
  42275. 0xEE, 0x0B, 0x9B, 0xB4, 0x33, 0x5E, 0x25, 0x15,
  42276. 0xD0, 0xAA, 0x93, 0xC4, 0x53, 0x42, 0x91, 0xC5,
  42277. 0x98, 0x15, 0x34, 0x9A, 0x22, 0x1D, 0x9A, 0xE7,
  42278. 0x0E, 0x81, 0xF6, 0x99, 0x55, 0xB3, 0xD6, 0x49,
  42279. 0x1B, 0xB8, 0xA8, 0xBE, 0xDF, 0x54, 0xF0, 0x78,
  42280. 0xF7, 0x02, 0x97, 0x74, 0x84, 0x67, 0x6B, 0xAE,
  42281. 0x2F, 0xEC, 0x6E, 0x59, 0x20, 0x68, 0xD8, 0xE3,
  42282. 0x5A, 0x07, 0x48, 0xE1, 0x99, 0x90, 0xEE, 0xCD,
  42283. 0x17, 0x2B, 0xB6, 0xD6, 0xAA, 0x1A, 0xF8, 0x97,
  42284. 0x4E, 0xE0, 0x67, 0x9E, 0x4C, 0x35, 0xFE, 0x68,
  42285. 0x71, 0x54, 0x43, 0x5D, 0x43, 0x59, 0x19, 0xEB,
  42286. 0x58, 0x8E, 0x9A, 0xF6, 0xBD, 0x88, 0x71, 0xEE,
  42287. 0x89, 0xC6, 0xF2, 0x10, 0x04, 0x33, 0x13, 0x88,
  42288. 0xCD, 0x08, 0xB5, 0xE3, 0x5D, 0xA8, 0xBC, 0x43,
  42289. 0xB3, 0x84, 0x5F, 0x70, 0x94, 0xD9, 0xAC, 0xAE,
  42290. 0x74, 0x70, 0x13, 0x1E, 0x21, 0xFB, 0xD5, 0x7F,
  42291. 0xEC, 0x66, 0x2F, 0xA0, 0xB1, 0x1D, 0xE3, 0xF8,
  42292. 0xB9, 0x36, 0x48, 0x25, 0x3D, 0xBA, 0x7D, 0x44,
  42293. 0x08, 0xC5, 0x71, 0x74, 0xDA, 0xD3, 0x4F, 0x97,
  42294. 0x86, 0xF1, 0x16, 0x38, 0xD8, 0xC9, 0xE3, 0x3A,
  42295. 0xA7, 0x2E, 0x06, 0x4D, 0x9D, 0xE8, 0xFC, 0x38,
  42296. 0x58, 0x2A, 0x8D, 0x2D, 0x07, 0x99, 0xEA, 0xDF,
  42297. 0xF3, 0x00, 0x3B, 0xBC, 0x5F, 0x67, 0x1E, 0x4B,
  42298. 0x6C, 0xF1, 0x4A, 0x47, 0xB0, 0x71, 0x90, 0x5A,
  42299. 0x3B, 0x75, 0x93, 0x75, 0x56, 0x50, 0x4C, 0x70,
  42300. 0xF3, 0xC7, 0x95, 0xD5, 0xEA, 0xCB, 0x4C, 0x92,
  42301. 0x4F, 0x22, 0x4F, 0xD9, 0x34, 0x46, 0x76, 0xFB,
  42302. 0x79, 0xD6, 0xBD, 0x4E, 0x84, 0xEE, 0xE7, 0x78,
  42303. 0x7C, 0xB8, 0x92, 0x9F, 0xAD, 0xF2, 0x17, 0x5D,
  42304. 0x38, 0xB1, 0x88, 0x2E, 0xE9, 0x65, 0xAC, 0x4C,
  42305. 0x24, 0x27, 0x1D, 0x7B, 0xA3, 0x69, 0x96, 0x55,
  42306. 0x5C, 0x26, 0x40, 0xAF, 0x04, 0xB1, 0xCE, 0xA8,
  42307. 0x5D, 0x1E, 0x1F, 0xE5, 0x5A, 0xC3, 0xAE, 0xF9,
  42308. 0x14, 0x03, 0x58, 0x10, 0x1C, 0x8B, 0x1F, 0xDB,
  42309. 0x6C, 0x71, 0x68, 0x60, 0x13, 0x32, 0xF1, 0xA9,
  42310. 0x69, 0x45, 0x28, 0x69, 0x7C, 0xE3, 0xC9, 0x56,
  42311. 0xAF, 0xF3, 0xBD, 0x4B, 0x9E, 0x0A, 0x06, 0x6A,
  42312. 0x62, 0x20, 0x40, 0x65, 0xBD, 0xBC, 0xBF, 0xC7,
  42313. 0x0A, 0x2A, 0xCF, 0x56, 0x7C, 0x0E, 0x64, 0xBB,
  42314. 0x64, 0x71, 0x2D, 0x90, 0xBB, 0x32, 0x00, 0x0A,
  42315. 0x4A, 0x45, 0x44, 0x08, 0x75, 0x2C, 0x86, 0x13,
  42316. 0x86, 0x52, 0x8D, 0x3D, 0xFC, 0xF3, 0x5E, 0x5B,
  42317. 0x3F, 0x7A, 0xAA, 0x98, 0x84, 0xCF, 0x92, 0xF9,
  42318. 0x0B, 0x40, 0x8F, 0xC0, 0xA3, 0x71, 0x84, 0xAD,
  42319. 0xEE, 0xDF, 0xC4, 0x91, 0x7E, 0x87, 0x7D, 0x06,
  42320. 0xCA, 0x65, 0x8C, 0xE4, 0x8E, 0x03, 0xF0, 0x59,
  42321. 0x3E, 0xB4, 0x90, 0x4C, 0xEE, 0x88, 0x29, 0xE4,
  42322. 0x26, 0x7D, 0xA6, 0x54, 0x82, 0x49, 0xC1, 0x9D,
  42323. 0x80, 0xAB, 0x6B, 0xD7, 0xBE, 0x7D, 0x09, 0x80,
  42324. 0x5E, 0xB6, 0xD1, 0x1E, 0xD1, 0x1B, 0xE9, 0x8D,
  42325. 0xFC, 0x6E, 0x9C, 0x14, 0x0C, 0x15, 0x02, 0x87,
  42326. 0xF3, 0x9D, 0x21, 0xF8, 0xCB, 0xC8, 0xB9, 0xBD,
  42327. 0xE1, 0x70, 0xEA, 0xE4, 0x86, 0x4C, 0x97, 0xC1,
  42328. 0xEE, 0x4C, 0x18, 0x95, 0xEC, 0xD2, 0x4D, 0x35,
  42329. 0x9F, 0xC6, 0x56, 0x10, 0x3E, 0xC0, 0xB9, 0x7B,
  42330. 0x13, 0x1A, 0x37, 0x3D, 0x40, 0x4C, 0x88, 0x8B,
  42331. 0x9A, 0xA5, 0xB2, 0xB8, 0xB9, 0xC3, 0xEC, 0xF1,
  42332. 0x14, 0x33, 0x63, 0x67, 0x84, 0x98, 0xC8, 0xF4,
  42333. 0x06, 0x0C, 0x0E, 0x0F, 0x10, 0x12, 0x15, 0x16,
  42334. 0x45, 0x4E, 0x55, 0x5A, 0x5F, 0x8A, 0x94, 0x97,
  42335. 0xA8, 0xAF, 0xB2, 0xCC, 0xD4, 0xDC, 0xE7, 0xF1,
  42336. 0xFE, 0xFF, 0x11, 0x24, 0x53, 0x62, 0x94, 0xB7,
  42337. 0xB9, 0xD3, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00,
  42338. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  42339. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  42340. 0x10, 0x18, 0x32, 0x3B
  42341. };
  42342. #endif
  42343. #ifndef WOLFSSL_NO_ML_DSA_65
  42344. static const byte pk_65[] = {
  42345. 0x6C, 0x84, 0x14, 0x38, 0x08, 0x56, 0xCB, 0x52,
  42346. 0xD7, 0x9C, 0x4B, 0x29, 0x13, 0x9F, 0xB1, 0x83,
  42347. 0x9B, 0x86, 0x06, 0xF5, 0x94, 0x8B, 0x9D, 0x72,
  42348. 0xA9, 0x56, 0xDC, 0xF1, 0x01, 0x16, 0xDA, 0x9E,
  42349. 0x2D, 0x79, 0x77, 0x01, 0x86, 0xFC, 0x74, 0xD9,
  42350. 0x42, 0xC0, 0xF4, 0xA3, 0xB5, 0x95, 0xFF, 0x6C,
  42351. 0x19, 0x80, 0x4B, 0x49, 0x90, 0x1C, 0x6A, 0xD5,
  42352. 0xFA, 0xF7, 0x16, 0x01, 0xC2, 0xB6, 0x00, 0x31,
  42353. 0x5E, 0x1F, 0x40, 0xC2, 0x05, 0x47, 0x67, 0xB0,
  42354. 0x09, 0x25, 0xDF, 0x3A, 0xA4, 0x90, 0xE8, 0xC7,
  42355. 0x6F, 0x05, 0xFB, 0xFB, 0x74, 0x91, 0x10, 0x75,
  42356. 0xE6, 0x51, 0x8C, 0x5F, 0x1D, 0x91, 0xB8, 0xA0,
  42357. 0xE5, 0xB5, 0x98, 0x30, 0xD3, 0xDF, 0x39, 0x94,
  42358. 0x76, 0x04, 0x11, 0xEB, 0xB9, 0x11, 0xED, 0x4C,
  42359. 0xC2, 0xC1, 0x60, 0xE3, 0x84, 0x9A, 0x93, 0x76,
  42360. 0x2D, 0xFC, 0xA7, 0xB9, 0x81, 0x2B, 0xC7, 0xAE,
  42361. 0xB2, 0xDD, 0xB2, 0x76, 0x7B, 0xEF, 0x36, 0x50,
  42362. 0x56, 0x05, 0xAE, 0x06, 0x92, 0x60, 0xBC, 0xC8,
  42363. 0xDC, 0x47, 0x87, 0xC4, 0x28, 0xCB, 0x3C, 0x07,
  42364. 0x6E, 0xF2, 0xA6, 0xB9, 0x35, 0x61, 0xD8, 0x94,
  42365. 0x3F, 0x45, 0xCA, 0xBE, 0x8F, 0x05, 0x53, 0xFF,
  42366. 0x2E, 0xA1, 0xAC, 0x95, 0xC1, 0xCE, 0x21, 0x59,
  42367. 0x3A, 0x17, 0x54, 0x59, 0xD7, 0xDF, 0x12, 0xC4,
  42368. 0x07, 0x0A, 0xDB, 0x0E, 0xEE, 0x55, 0xB4, 0xAB,
  42369. 0xAE, 0x59, 0xBE, 0x69, 0xC3, 0xFF, 0x0D, 0xE5,
  42370. 0xA9, 0xB0, 0x27, 0xFC, 0x7D, 0x8E, 0x6E, 0x05,
  42371. 0x7B, 0x71, 0x52, 0xEE, 0x6A, 0xB4, 0x80, 0xD1,
  42372. 0x05, 0xD3, 0x0B, 0x0F, 0x50, 0x51, 0xB6, 0x0C,
  42373. 0x79, 0x01, 0xC5, 0x25, 0xC4, 0x63, 0x5F, 0xE6,
  42374. 0x68, 0xCC, 0x00, 0xE9, 0xD3, 0x09, 0x7D, 0xB9,
  42375. 0x9D, 0x66, 0x32, 0x37, 0x15, 0xCE, 0x4F, 0x0B,
  42376. 0x79, 0xB4, 0x26, 0xB4, 0x54, 0x5E, 0x09, 0xF4,
  42377. 0xDE, 0x39, 0x32, 0x3D, 0xD1, 0x4C, 0xCB, 0x0D,
  42378. 0x17, 0x10, 0x8C, 0xD4, 0x6D, 0xEC, 0x61, 0x38,
  42379. 0xCD, 0xFA, 0x28, 0x72, 0xC1, 0xC4, 0xC8, 0xAE,
  42380. 0xAD, 0x5C, 0x8C, 0xE0, 0x41, 0x57, 0xE5, 0x53,
  42381. 0xA3, 0x75, 0x58, 0xC2, 0x34, 0x6A, 0x06, 0x19,
  42382. 0x4C, 0xB5, 0x0B, 0x49, 0x81, 0xBF, 0x4D, 0x09,
  42383. 0x0C, 0xE4, 0xE8, 0x60, 0x12, 0x6A, 0x82, 0x54,
  42384. 0xA4, 0xD4, 0xC0, 0x84, 0xC3, 0xE2, 0x02, 0x0B,
  42385. 0xC0, 0x75, 0x35, 0x21, 0x04, 0x9B, 0x0F, 0xD8,
  42386. 0x89, 0x97, 0xE0, 0x27, 0xAC, 0x51, 0xE7, 0x5C,
  42387. 0xF1, 0x35, 0x0C, 0x3F, 0x30, 0x3A, 0x0E, 0xCE,
  42388. 0x42, 0x64, 0x87, 0x15, 0x3D, 0xAF, 0x1F, 0xAA,
  42389. 0xD6, 0x80, 0x8B, 0x9D, 0x99, 0x07, 0xDA, 0x9F,
  42390. 0x35, 0x18, 0x5B, 0xD3, 0xBE, 0x8D, 0x9C, 0xEB,
  42391. 0xE9, 0x16, 0xCE, 0xD1, 0xFA, 0x29, 0x28, 0xD8,
  42392. 0x85, 0xA9, 0xCB, 0xA8, 0x81, 0x49, 0x70, 0x3F,
  42393. 0x5E, 0x47, 0x72, 0xE4, 0x85, 0x23, 0x12, 0x5D,
  42394. 0xDD, 0x02, 0x6E, 0x71, 0x4C, 0x49, 0xF4, 0xFB,
  42395. 0x4E, 0x54, 0x4B, 0xBF, 0x61, 0x7A, 0x40, 0xB0,
  42396. 0x0B, 0x68, 0xDF, 0x8F, 0x15, 0x5F, 0x58, 0x80,
  42397. 0xD4, 0x11, 0x87, 0x7E, 0x25, 0xB4, 0x2B, 0x24,
  42398. 0x48, 0xB3, 0x6B, 0xEC, 0x2F, 0x1F, 0x8F, 0x9A,
  42399. 0x77, 0x0C, 0x54, 0x51, 0x50, 0xA0, 0x27, 0x8E,
  42400. 0x9B, 0x72, 0x45, 0x00, 0xAE, 0xAA, 0xEA, 0x47,
  42401. 0x1C, 0x11, 0xCF, 0xF0, 0x4E, 0x30, 0xEA, 0xB2,
  42402. 0xF4, 0x73, 0xBC, 0x04, 0x8E, 0x32, 0xCD, 0x31,
  42403. 0xAE, 0xF2, 0x15, 0x79, 0xB6, 0x99, 0x22, 0x5B,
  42404. 0xF9, 0xE1, 0xB6, 0x70, 0x0C, 0x57, 0xE5, 0x09,
  42405. 0xFC, 0xA1, 0xF2, 0x36, 0x29, 0x4A, 0x59, 0x74,
  42406. 0xDA, 0xA1, 0x5F, 0xBC, 0xAD, 0x62, 0xD4, 0xBD,
  42407. 0xDC, 0x45, 0x32, 0xB2, 0x61, 0x41, 0x44, 0xDB,
  42408. 0xE2, 0x88, 0x07, 0x36, 0x8C, 0x28, 0x1A, 0x77,
  42409. 0x0E, 0xA2, 0x2B, 0x1E, 0x5A, 0x3F, 0xA5, 0xBA,
  42410. 0x14, 0x92, 0x6D, 0xC5, 0x5A, 0x54, 0xF8, 0x4A,
  42411. 0x2A, 0x77, 0xC5, 0xA7, 0x08, 0x41, 0xF0, 0x7B,
  42412. 0xC1, 0xDE, 0xEF, 0x74, 0x03, 0xB2, 0x47, 0xAB,
  42413. 0x42, 0xB8, 0x4A, 0xDF, 0x14, 0x1E, 0x03, 0x0C,
  42414. 0x98, 0x46, 0x84, 0x24, 0xDA, 0xAE, 0xB9, 0x9D,
  42415. 0x25, 0x77, 0xF9, 0x50, 0xC2, 0x37, 0x3C, 0xCA,
  42416. 0x1E, 0x2D, 0xC2, 0x76, 0x1B, 0x8E, 0xDD, 0x6D,
  42417. 0x08, 0xFF, 0x79, 0xE5, 0x28, 0x88, 0x0F, 0xFB,
  42418. 0x51, 0xC3, 0x6E, 0xD4, 0x20, 0xAC, 0x5D, 0x50,
  42419. 0xF2, 0x58, 0x2A, 0xA6, 0x64, 0xE5, 0x4E, 0xA5,
  42420. 0xF4, 0x18, 0x9E, 0xA0, 0x17, 0x6D, 0xAA, 0x61,
  42421. 0x22, 0xF6, 0x23, 0x5A, 0x70, 0xB1, 0x5C, 0xEB,
  42422. 0x4D, 0xDD, 0x65, 0xD3, 0xBE, 0x6E, 0xBF, 0x3D,
  42423. 0xC4, 0x31, 0x89, 0xEE, 0x0A, 0x2E, 0x31, 0x05,
  42424. 0x63, 0x8F, 0x23, 0x87, 0x36, 0x95, 0x28, 0x0F,
  42425. 0x1B, 0x74, 0x27, 0x43, 0x52, 0xD6, 0x0A, 0x48,
  42426. 0xE5, 0xD3, 0xDD, 0x02, 0xFB, 0x7A, 0x5E, 0xD8,
  42427. 0x3F, 0xE2, 0x7A, 0x69, 0x82, 0x51, 0x42, 0x1C,
  42428. 0x8E, 0x9C, 0x98, 0x80, 0x61, 0x02, 0x39, 0x6E,
  42429. 0x53, 0x73, 0x90, 0xAC, 0xFD, 0x8C, 0x1D, 0x0B,
  42430. 0x4F, 0x99, 0xB7, 0x02, 0xA9, 0xEA, 0x65, 0x98,
  42431. 0x78, 0x58, 0x3D, 0x92, 0x75, 0x89, 0x41, 0xB3,
  42432. 0x0E, 0xCE, 0x50, 0x7C, 0x10, 0x4B, 0x2C, 0xE4,
  42433. 0x87, 0x67, 0x9E, 0xCF, 0x68, 0xB4, 0xD8, 0xB9,
  42434. 0x80, 0x69, 0x8A, 0xCF, 0x6A, 0xA6, 0xA5, 0x7E,
  42435. 0x8E, 0xD6, 0xAF, 0x3F, 0xF1, 0x8D, 0x26, 0x68,
  42436. 0x95, 0x04, 0x28, 0xB5, 0x7D, 0x18, 0x2F, 0x73,
  42437. 0xBB, 0x49, 0xB9, 0xB0, 0x38, 0xCC, 0xC8, 0x2D,
  42438. 0x56, 0x12, 0x78, 0xA3, 0x86, 0xD5, 0x66, 0x45,
  42439. 0xEC, 0x3F, 0xAF, 0xFB, 0x41, 0x25, 0xE0, 0xE7,
  42440. 0xF3, 0x6B, 0x48, 0xB1, 0x4B, 0x45, 0x25, 0x47,
  42441. 0xA0, 0xB4, 0x81, 0xAA, 0x6B, 0x33, 0x42, 0x29,
  42442. 0x24, 0x91, 0x53, 0xE4, 0x2E, 0xDF, 0x7E, 0x49,
  42443. 0xDD, 0x6E, 0x76, 0x36, 0xBF, 0xC6, 0x15, 0xA2,
  42444. 0x3A, 0x40, 0x1E, 0xFD, 0x40, 0x34, 0xC8, 0x1B,
  42445. 0x4D, 0xCE, 0xF0, 0x27, 0xD3, 0x44, 0xDD, 0xCC,
  42446. 0xE0, 0xA7, 0x16, 0x18, 0xEB, 0x59, 0x10, 0xCE,
  42447. 0xC6, 0x22, 0x28, 0x81, 0x93, 0x85, 0x03, 0x3E,
  42448. 0x8D, 0x0A, 0xBD, 0x49, 0x3D, 0x98, 0x3E, 0x4F,
  42449. 0xC0, 0x87, 0xD7, 0x2B, 0x45, 0x5E, 0x4D, 0xB6,
  42450. 0x3A, 0x2F, 0x82, 0xCE, 0xFF, 0x65, 0xC1, 0xE6,
  42451. 0x28, 0xEA, 0xE6, 0x30, 0x59, 0x6D, 0xEC, 0x27,
  42452. 0xFB, 0x98, 0xB8, 0x4D, 0xBF, 0xDC, 0xDF, 0xAB,
  42453. 0x40, 0xE4, 0x72, 0x24, 0x49, 0x14, 0xAF, 0xF1,
  42454. 0x79, 0x32, 0x6D, 0x54, 0x2D, 0x40, 0x1A, 0x3C,
  42455. 0xBB, 0x86, 0xE5, 0xFF, 0x83, 0x51, 0xEF, 0xE5,
  42456. 0x3A, 0x73, 0xC5, 0x1A, 0xBB, 0x63, 0xFF, 0x55,
  42457. 0x3E, 0x7D, 0x79, 0x57, 0xEF, 0x89, 0x13, 0x5E,
  42458. 0x0F, 0x5B, 0xB1, 0xBD, 0x0C, 0x24, 0xF9, 0xE4,
  42459. 0x5E, 0x32, 0x36, 0x41, 0x3C, 0x60, 0xE1, 0x39,
  42460. 0x6A, 0x47, 0x56, 0x7C, 0x94, 0x39, 0x51, 0x0F,
  42461. 0x00, 0xD4, 0xA4, 0x3C, 0x14, 0x9A, 0x5C, 0xCC,
  42462. 0x04, 0xF3, 0xD4, 0x7E, 0x67, 0xA8, 0xE2, 0x94,
  42463. 0xA4, 0x61, 0xA5, 0xF6, 0x93, 0xDB, 0x0C, 0xAE,
  42464. 0x22, 0xCF, 0xAC, 0x61, 0xE8, 0x53, 0x47, 0x7D,
  42465. 0x33, 0x9A, 0x4E, 0x45, 0xF7, 0xB1, 0x7C, 0x3C,
  42466. 0x11, 0x6D, 0x56, 0xF3, 0xA0, 0x68, 0xFC, 0x5A,
  42467. 0xDF, 0xEF, 0x38, 0xFF, 0x85, 0x33, 0x2B, 0xD5,
  42468. 0x15, 0x3C, 0x4D, 0x8F, 0xB8, 0xF1, 0x48, 0xF1,
  42469. 0x17, 0x65, 0x9C, 0x2E, 0xA9, 0x4D, 0xB4, 0x2A,
  42470. 0xA0, 0xB0, 0xBE, 0xBB, 0x47, 0x5A, 0x11, 0x04,
  42471. 0x12, 0xF3, 0xCD, 0x33, 0x49, 0xFC, 0x1A, 0xD0,
  42472. 0x41, 0xB7, 0xD5, 0x30, 0x4A, 0x85, 0x93, 0x14,
  42473. 0x4E, 0xFA, 0x3A, 0x36, 0x1D, 0x1B, 0x0C, 0x76,
  42474. 0x13, 0xB8, 0x2C, 0x08, 0x6E, 0xA7, 0x12, 0x6E,
  42475. 0x43, 0xC6, 0x16, 0xCE, 0xE8, 0xF1, 0x44, 0x4E,
  42476. 0x99, 0x56, 0xE8, 0x7F, 0x5C, 0xAB, 0x95, 0xC7,
  42477. 0xC7, 0xFB, 0x17, 0x58, 0xEC, 0x7D, 0x97, 0x01,
  42478. 0x9E, 0x5B, 0xA9, 0x35, 0x43, 0xEF, 0x3B, 0xAC,
  42479. 0x1A, 0x17, 0x42, 0x99, 0xCA, 0x48, 0xBF, 0x78,
  42480. 0x59, 0xDB, 0xFB, 0xDF, 0xF2, 0x43, 0xB1, 0x14,
  42481. 0xF6, 0xBF, 0x42, 0x3C, 0xE9, 0x8B, 0x4D, 0x4D,
  42482. 0x09, 0x1D, 0xA4, 0x4F, 0x32, 0x74, 0xD5, 0x73,
  42483. 0xFD, 0xC9, 0x04, 0xBD, 0x88, 0x5E, 0x35, 0xC9,
  42484. 0x15, 0x2A, 0x65, 0x35, 0x48, 0x88, 0xF1, 0x1E,
  42485. 0xD4, 0xF3, 0xD6, 0x3F, 0x26, 0xA7, 0xBE, 0x2F,
  42486. 0x57, 0x26, 0xEA, 0xDA, 0xF4, 0x85, 0x86, 0x59,
  42487. 0x2B, 0xBD, 0xF6, 0xCE, 0xE2, 0x46, 0x76, 0x9E,
  42488. 0x0E, 0xDA, 0x2A, 0x80, 0x77, 0x1F, 0xED, 0x34,
  42489. 0x7D, 0x67, 0xAF, 0xEE, 0xC6, 0x8B, 0x89, 0x46,
  42490. 0x3F, 0xA0, 0x49, 0x6D, 0xBC, 0x15, 0xC8, 0x9E,
  42491. 0x8D, 0x56, 0x99, 0x83, 0xD1, 0xD6, 0x74, 0x73,
  42492. 0x3F, 0x2B, 0xF9, 0xDF, 0x4A, 0x98, 0x0E, 0xA8,
  42493. 0xC5, 0xE3, 0xAF, 0x15, 0x56, 0x0A, 0x0E, 0x28,
  42494. 0xD6, 0x72, 0xB5, 0x80, 0xAB, 0x65, 0x52, 0xED,
  42495. 0x76, 0xAA, 0xCB, 0x5F, 0x80, 0x26, 0x0B, 0x97,
  42496. 0x03, 0x76, 0x9D, 0x33, 0xF4, 0x13, 0x8A, 0xBC,
  42497. 0x10, 0xBF, 0x5B, 0x05, 0x82, 0xDC, 0xC6, 0x2D,
  42498. 0xBE, 0x58, 0xC8, 0x90, 0xF5, 0x1B, 0x41, 0x00,
  42499. 0x12, 0x77, 0x34, 0xFB, 0x7D, 0xB7, 0x44, 0x7A,
  42500. 0x72, 0x0A, 0xAE, 0x00, 0x9D, 0x00, 0xBE, 0x8C,
  42501. 0x61, 0x07, 0x92, 0xC6, 0x4F, 0x13, 0x1F, 0x2D,
  42502. 0x72, 0x11, 0x5C, 0x7E, 0x05, 0x8E, 0x48, 0xB9,
  42503. 0xDE, 0x64, 0xF5, 0x5B, 0x4D, 0x61, 0x0C, 0x36,
  42504. 0xD1, 0x12, 0x71, 0x6A, 0x31, 0xA3, 0xDF, 0xE2,
  42505. 0x66, 0x99, 0xE9, 0xC2, 0xAB, 0xA0, 0x56, 0x58,
  42506. 0xCE, 0xF1, 0xB2, 0xB0, 0x86, 0x7C, 0xF8, 0xD5,
  42507. 0x23, 0x3D, 0xB7, 0x4F, 0xA8, 0xDC, 0x3A, 0xD1,
  42508. 0x45, 0xF5, 0xD2, 0x85, 0x74, 0x36, 0x0A, 0x85,
  42509. 0xE3, 0xB0, 0xB1, 0x0A, 0xC0, 0xA6, 0x46, 0x7A,
  42510. 0x7B, 0x05, 0x98, 0x46, 0x28, 0xEC, 0xA1, 0x04,
  42511. 0x63, 0xF3, 0x48, 0xA3, 0x11, 0x1E, 0x00, 0x57,
  42512. 0x8D, 0x3C, 0xE5, 0x48, 0x0F, 0x53, 0x75, 0xA1,
  42513. 0xEE, 0x23, 0xEE, 0x82, 0x08, 0x7B, 0xAC, 0x41,
  42514. 0x23, 0x3A, 0x14, 0xAA, 0xA7, 0x24, 0x73, 0x4B,
  42515. 0x18, 0x74, 0xA4, 0xAC, 0xE1, 0x13, 0x37, 0x06,
  42516. 0x25, 0x8F, 0x5F, 0xEA, 0x3A, 0x0C, 0x16, 0x09,
  42517. 0xE3, 0x0C, 0x7F, 0xD2, 0x10, 0xDA, 0x0C, 0x4F,
  42518. 0xDE, 0x91, 0x62, 0xDF, 0x66, 0xFB, 0xAF, 0x79,
  42519. 0x2F, 0xA2, 0xAE, 0xAA, 0x51, 0x2F, 0x0F, 0xF7,
  42520. 0x83, 0x7B, 0x9C, 0xC0, 0x2E, 0xE9, 0xBD, 0x95,
  42521. 0x53, 0x9F, 0x00, 0x1B, 0xBD, 0x60, 0xDD, 0x8B,
  42522. 0x42, 0xD6, 0x16, 0xB2, 0xCA, 0x95, 0xF3, 0x83,
  42523. 0x5F, 0x5E, 0x47, 0xD4, 0x3B, 0x14, 0x34, 0xC4,
  42524. 0x56, 0x3F, 0xD8, 0x1C, 0x15, 0xBE, 0xFA, 0x20,
  42525. 0x2C, 0xF3, 0xD9, 0x54, 0x08, 0x73, 0xF6, 0x84,
  42526. 0xAF, 0xE1, 0x9A, 0xB5, 0xC0, 0x1F, 0xA9, 0x2E,
  42527. 0x95, 0xA8, 0xCD, 0x6F, 0x36, 0x07, 0x30, 0x85,
  42528. 0x6E, 0x59, 0xC9, 0xC6, 0xAB, 0x77, 0x0D, 0x65,
  42529. 0x75, 0x96, 0x2A, 0xF7, 0x58, 0x78, 0x57, 0x2A,
  42530. 0x2A, 0x26, 0x41, 0x3D, 0x01, 0xAB, 0x31, 0x8C,
  42531. 0x10, 0x0D, 0xFC, 0x34, 0xDC, 0x1D, 0xEF, 0xA5,
  42532. 0x92, 0x7C, 0x4B, 0x45, 0x99, 0x25, 0xD7, 0x3E,
  42533. 0x1E, 0xB9, 0x14, 0x70, 0xE3, 0x7A, 0x58, 0x45,
  42534. 0x5C, 0x22, 0xA9, 0x61, 0xFD, 0x53, 0xF7, 0xD9,
  42535. 0x90, 0x26, 0xFF, 0x88, 0x4B, 0xF4, 0xA2, 0x57,
  42536. 0x9F, 0x70, 0x63, 0x35, 0xEF, 0xB6, 0xFB, 0x22,
  42537. 0x50, 0xD5, 0x2A, 0xE5, 0x61, 0x89, 0x8B, 0xA1,
  42538. 0x60, 0x6E, 0x51, 0xE9, 0x6D, 0x37, 0xC9, 0xED,
  42539. 0x3E, 0xC6, 0xCF, 0xCB, 0x33, 0xBF, 0xBE, 0x9C,
  42540. 0x31, 0x43, 0xFD, 0x3B, 0x6B, 0x33, 0x4D, 0x5F,
  42541. 0x61, 0x92, 0x2B, 0x36, 0x9A, 0xFB, 0xB3, 0x1C,
  42542. 0x3E, 0x6E, 0x9B, 0x5F, 0x3A, 0xEB, 0xF9, 0x5C,
  42543. 0xB7, 0x08, 0x34, 0x6F, 0xEC, 0xF7, 0x15, 0x9C,
  42544. 0xAD, 0x94, 0xA9, 0x3D, 0x8C, 0xD4, 0xB8, 0xC4,
  42545. 0x89, 0x41, 0x92, 0xDF, 0xE5, 0x3E, 0xA4, 0x36,
  42546. 0xFB, 0xF3, 0xAF, 0x4E, 0x86, 0x4E, 0x8C, 0x39,
  42547. 0x91, 0xEA, 0x02, 0x0A, 0x81, 0x1F, 0x0A, 0xF5,
  42548. 0x0B, 0x42, 0x57, 0x43, 0x6A, 0x3F, 0xF5, 0x22,
  42549. 0xBE, 0x73, 0x67, 0x39, 0x1D, 0x0F, 0x95, 0x0B,
  42550. 0xA6, 0x45, 0x2F, 0xBF, 0xD8, 0xFD, 0x87, 0x28,
  42551. 0xF4, 0x0B, 0xD2, 0xFC, 0xB8, 0x94, 0x52, 0x99,
  42552. 0x85, 0xB4, 0x32, 0xDF, 0xEF, 0x62, 0x30, 0xEB,
  42553. 0x4D, 0xEE, 0x73, 0x7A, 0x8D, 0x10, 0xA3, 0xBC,
  42554. 0xDF, 0xB7, 0x63, 0xE0, 0x86, 0x9B, 0x22, 0x5C,
  42555. 0x1A, 0x8D, 0x0E, 0x1F, 0xBF, 0x2D, 0x16, 0x1C,
  42556. 0x2C, 0x65, 0xD6, 0xDF, 0xB9, 0x58, 0xE9, 0x82,
  42557. 0xD1, 0x17, 0x77, 0xAC, 0xBE, 0xAD, 0x8D, 0xFB,
  42558. 0x6B, 0x1F, 0x5E, 0xB2, 0x1E, 0xA9, 0x42, 0xF7,
  42559. 0xC4, 0x0D, 0xC2, 0x0D, 0x2E, 0x4E, 0xB3, 0xE7,
  42560. 0x29, 0xB4, 0xE2, 0x9F, 0x75, 0x01, 0xDA, 0x34,
  42561. 0x23, 0x45, 0x61, 0xF6, 0x28, 0x88, 0x12, 0xD6,
  42562. 0x12, 0xD4, 0x1D, 0xFA, 0x83, 0xC5, 0xB8, 0xD9,
  42563. 0x0F, 0xF3, 0x8B, 0xA5, 0x48, 0x20, 0x1B, 0x57,
  42564. 0x5B, 0x52, 0x93, 0xAD, 0x78, 0x12, 0x0D, 0x91,
  42565. 0xCE, 0xC0, 0x59, 0xCA, 0xE2, 0xE7, 0x6A, 0x9A,
  42566. 0xB4, 0x3E, 0xF1, 0x28, 0x1E, 0x2B, 0xEF, 0x3E,
  42567. 0x34, 0x8D, 0x28, 0xF2, 0x19, 0x47, 0xC8, 0x88,
  42568. 0x48, 0x96, 0x04, 0x59, 0x48, 0x97, 0x75, 0x17,
  42569. 0x6F, 0x8E, 0x40, 0xEE, 0x06, 0x42, 0x79, 0x53,
  42570. 0x68, 0x7F, 0xB6, 0x3E, 0x47, 0x0F, 0x7D, 0x59,
  42571. 0xFB, 0x60, 0xDF, 0x56, 0x9F, 0x8A, 0x11, 0xE2,
  42572. 0x8E, 0x09, 0x37, 0x16, 0x2C, 0x46, 0xAF, 0xC7,
  42573. 0xD2, 0x21, 0x0A, 0x88, 0x5F, 0xFA, 0x21, 0xB3,
  42574. 0xDB, 0xF5, 0x35, 0x4B, 0x29, 0x41, 0xF4, 0xED,
  42575. 0x5D, 0x50, 0x79, 0x08, 0x90, 0x84, 0x0C, 0xC3,
  42576. 0xB9, 0x73, 0xD2, 0xC3, 0xD0, 0x26, 0x02, 0xB2,
  42577. 0x9B, 0xAC, 0xCB, 0x6C, 0xE1, 0x7C, 0xED, 0xB9,
  42578. 0x7B, 0x08, 0x5A, 0x2A, 0xB3, 0x10, 0x57, 0x2B,
  42579. 0xA7, 0x37, 0x1D, 0x1F, 0x81, 0x20, 0xFF, 0xE3,
  42580. 0x7D, 0x0B, 0x0F, 0xCA, 0x35, 0xAF, 0xC5, 0xB5,
  42581. 0x62, 0xAA, 0x84, 0x99, 0x71, 0x5A, 0x29, 0x9C,
  42582. 0xE0, 0x59, 0xCC, 0xE3, 0xB0, 0xD1, 0x1C, 0xEF,
  42583. 0x0D, 0x92, 0x38, 0x96, 0x1A, 0xD4, 0xBE, 0x11,
  42584. 0xE9, 0xA6, 0xD1, 0xA4, 0x69, 0x21, 0x77, 0xC8,
  42585. 0xB0, 0xC5, 0x3F, 0x11, 0xA8, 0xED, 0x26, 0x50,
  42586. 0x21, 0x2E, 0x7A, 0x2F, 0x80, 0xEB, 0xFF, 0x6D,
  42587. 0xCF, 0xE4, 0x67, 0x21, 0x03, 0x65, 0x84, 0x34,
  42588. 0xD0, 0x32, 0x7A, 0xDD, 0xCD, 0x66, 0xBC, 0xB6
  42589. };
  42590. static const byte msg_65[] = {
  42591. 0xDB, 0x84, 0x94, 0xBA, 0x19, 0xC4, 0x11, 0x8F,
  42592. 0xB1, 0x5D, 0x0A, 0xCF, 0x42, 0x54, 0xFD, 0x37,
  42593. 0x48, 0x3F, 0xCF, 0x47, 0x48, 0xFD, 0x18, 0x44,
  42594. 0xF7, 0x17, 0xCE, 0x6F, 0x69, 0x58, 0x9E, 0x61,
  42595. 0x77, 0x2C, 0xFE, 0xFA, 0x7F, 0x97, 0x58, 0x65,
  42596. 0x34, 0x09, 0xD4, 0xEE, 0x5A, 0x26, 0x4B, 0x83,
  42597. 0x4E, 0x60, 0xD6, 0xBB, 0x96, 0x49, 0x9E, 0xBE,
  42598. 0xB2, 0xB0, 0x6B, 0x0B, 0xA8, 0x74, 0xBF, 0x31,
  42599. 0xE6, 0x41, 0x39, 0x4C, 0xFA, 0xA6, 0xA2, 0xD3,
  42600. 0x0D, 0xDB, 0x8F, 0x04, 0x58, 0x76, 0x20, 0x8D,
  42601. 0x2F, 0x51, 0xDE, 0x15, 0xE2, 0x05, 0xE8, 0xC9,
  42602. 0x1B, 0x87, 0xEC, 0xEB, 0x05, 0xFF, 0x31, 0x83,
  42603. 0x27, 0x1B, 0x26, 0x49, 0x66, 0x5D, 0xD3, 0xCC,
  42604. 0x49, 0xBF, 0xDB, 0x99, 0x8D, 0x53, 0x9D, 0xA8,
  42605. 0x09, 0x30, 0x55, 0x16, 0xBB, 0xBE, 0x9C, 0x90,
  42606. 0x60, 0x21, 0x19, 0x1C, 0x52, 0x23, 0xE5, 0x25,
  42607. 0xA8, 0xFC, 0x36, 0x16, 0xA1, 0x76, 0x5E, 0xC3,
  42608. 0xF9, 0xC5, 0xDB, 0x53, 0xCC, 0x33, 0x7E, 0x03,
  42609. 0x9F, 0x18, 0x6A, 0xCF, 0xEA, 0x91, 0x14, 0x8E,
  42610. 0xE2, 0xA7, 0x9C, 0xCA, 0x36, 0x89, 0xED, 0xB6,
  42611. 0x2A, 0xAF, 0x28, 0xB5, 0xD7, 0x52, 0xFD, 0xE2,
  42612. 0x65, 0xEE, 0x52, 0x80, 0xB5, 0x19, 0x72, 0x6C,
  42613. 0x1C, 0xA9, 0x80, 0x32, 0x95, 0xC6, 0x74, 0xB7,
  42614. 0xEF, 0xAF, 0xA4, 0xD6, 0x1B, 0x30, 0x6A, 0x79,
  42615. 0xE3, 0xF6, 0xE7, 0xA8, 0x87, 0xC2, 0xFB, 0x53,
  42616. 0x5B, 0x3B, 0x0F, 0xB3, 0xD9, 0xEB, 0xC8, 0x76,
  42617. 0x03, 0xEA, 0xFE, 0xF1, 0x70, 0xC1, 0xF1, 0xD2,
  42618. 0x8E, 0x99, 0xBB
  42619. };
  42620. static const byte sig_65[] = {
  42621. 0xF7, 0x78, 0x9A, 0x45, 0xA3, 0x58, 0x73, 0x30,
  42622. 0xE7, 0xFC, 0xF7, 0x06, 0x95, 0xF7, 0xF6, 0x96,
  42623. 0x88, 0xA2, 0xB8, 0xD0, 0xCE, 0x54, 0xF0, 0x90,
  42624. 0x21, 0x4F, 0x10, 0x9F, 0x56, 0x48, 0x4F, 0x98,
  42625. 0xC3, 0xAD, 0x1A, 0x53, 0xA5, 0x44, 0x1C, 0x2C,
  42626. 0xA7, 0x2A, 0x3B, 0x31, 0x91, 0xBC, 0x04, 0x6F,
  42627. 0x46, 0x37, 0x30, 0x45, 0xB9, 0xE5, 0x40, 0xC7,
  42628. 0x3D, 0xFE, 0x91, 0xB6, 0x1F, 0x05, 0x88, 0xD6,
  42629. 0x13, 0x59, 0x3F, 0xCE, 0x1B, 0x00, 0xEE, 0xF1,
  42630. 0xB2, 0x27, 0x03, 0x4C, 0x6F, 0xD3, 0xB1, 0x8B,
  42631. 0x3F, 0x22, 0x11, 0x10, 0xFB, 0x34, 0x5A, 0xA7,
  42632. 0x86, 0x31, 0xB8, 0xB5, 0x9F, 0xBD, 0xFD, 0xCC,
  42633. 0xDA, 0xE6, 0xA2, 0x4D, 0x25, 0x9D, 0x34, 0xAA,
  42634. 0xBA, 0xD2, 0x18, 0xB3, 0xAE, 0x4E, 0x77, 0x18,
  42635. 0x66, 0x53, 0xB8, 0x56, 0x3A, 0xA6, 0x12, 0x0A,
  42636. 0x0A, 0x53, 0x1A, 0x4E, 0x91, 0x37, 0x30, 0xDC,
  42637. 0x91, 0x4F, 0xE5, 0xE0, 0x08, 0xBE, 0xCE, 0x68,
  42638. 0x69, 0xB0, 0x2B, 0x07, 0xFD, 0xC1, 0x62, 0x14,
  42639. 0x54, 0x0D, 0x31, 0x6C, 0x43, 0xFA, 0x0C, 0x21,
  42640. 0x1B, 0x41, 0xAC, 0x7E, 0x52, 0x65, 0x67, 0x29,
  42641. 0xC7, 0x73, 0xE4, 0xC4, 0xB8, 0x8E, 0xD3, 0x11,
  42642. 0x88, 0x6D, 0xD4, 0xD2, 0x75, 0x41, 0x7D, 0x70,
  42643. 0x19, 0x66, 0x44, 0xEE, 0xD1, 0x5F, 0xA3, 0x15,
  42644. 0x06, 0x60, 0x03, 0xE3, 0x09, 0xF8, 0x32, 0xAF,
  42645. 0x91, 0x26, 0x2C, 0x94, 0x90, 0x11, 0xFC, 0xB0,
  42646. 0xAD, 0x2C, 0xCE, 0x65, 0xDD, 0x9E, 0xFF, 0x56,
  42647. 0x7E, 0xE2, 0x9C, 0xC4, 0x0A, 0x6F, 0xE0, 0x66,
  42648. 0x4E, 0x7D, 0x9F, 0x23, 0x65, 0x68, 0xFC, 0x94,
  42649. 0x29, 0x5D, 0xBB, 0x34, 0x28, 0x82, 0x33, 0xE8,
  42650. 0xC5, 0x11, 0xD2, 0x88, 0x15, 0xEC, 0x72, 0x10,
  42651. 0x32, 0x29, 0x6E, 0x1E, 0xDE, 0xCA, 0x7F, 0x72,
  42652. 0x6A, 0x6E, 0xB0, 0xF7, 0x6C, 0xC5, 0x82, 0x80,
  42653. 0x11, 0xC0, 0xE4, 0x01, 0x3C, 0xC7, 0xEE, 0x43,
  42654. 0x29, 0xB8, 0x1E, 0xCC, 0x0D, 0x52, 0xED, 0x1E,
  42655. 0x49, 0x1D, 0xD6, 0xD5, 0x5C, 0x52, 0x65, 0x66,
  42656. 0x5E, 0xD8, 0xAD, 0x21, 0x9B, 0x89, 0x4F, 0x31,
  42657. 0xC6, 0x8C, 0x61, 0x9A, 0xFC, 0xDB, 0x73, 0x58,
  42658. 0xE5, 0x55, 0x4C, 0x49, 0x5B, 0x8B, 0x6E, 0x33,
  42659. 0x25, 0x68, 0x8F, 0xB8, 0xC1, 0xA2, 0x53, 0x31,
  42660. 0xD5, 0x7B, 0xD3, 0x48, 0xA2, 0x7D, 0x39, 0x09,
  42661. 0x29, 0xBC, 0x46, 0xA1, 0x49, 0x6A, 0xB3, 0x5B,
  42662. 0x46, 0xBA, 0x61, 0xB6, 0xB9, 0xD2, 0x3C, 0xD0,
  42663. 0x63, 0x15, 0xFB, 0x72, 0xC2, 0x47, 0x76, 0x01,
  42664. 0x61, 0x30, 0xAD, 0xB1, 0xCF, 0x2D, 0xC7, 0x29,
  42665. 0x59, 0xEA, 0x9C, 0xAD, 0x96, 0xAF, 0x5D, 0xA9,
  42666. 0x96, 0x12, 0x6C, 0xDD, 0x85, 0xB1, 0x34, 0xCC,
  42667. 0x92, 0x7A, 0x51, 0xFD, 0x23, 0xF8, 0x47, 0x91,
  42668. 0xA3, 0xFC, 0xDA, 0x07, 0x7E, 0x15, 0x99, 0x17,
  42669. 0x48, 0xA0, 0x39, 0x4F, 0x33, 0x4E, 0xB8, 0xBC,
  42670. 0x48, 0xA9, 0x9A, 0xB9, 0xDF, 0xBB, 0x0F, 0x2A,
  42671. 0xAD, 0x6F, 0xBE, 0x48, 0x49, 0x61, 0xD3, 0xA4,
  42672. 0xE8, 0xF8, 0xB2, 0x1A, 0x6A, 0xC0, 0x92, 0xB2,
  42673. 0x26, 0xD6, 0xE1, 0x19, 0xFA, 0xD4, 0x4D, 0x8E,
  42674. 0x57, 0x6F, 0xE9, 0x6C, 0x6C, 0xDB, 0x68, 0x40,
  42675. 0xEA, 0x61, 0x4B, 0xAF, 0xC7, 0x07, 0x86, 0xC5,
  42676. 0x19, 0xE1, 0xD5, 0xDC, 0x0F, 0x98, 0x44, 0x43,
  42677. 0xC8, 0xB1, 0xE5, 0x4F, 0x8E, 0xE1, 0x76, 0xD9,
  42678. 0x8B, 0x2C, 0x70, 0x27, 0xF5, 0x7D, 0x7E, 0x3D,
  42679. 0xE9, 0xB2, 0xA0, 0xA3, 0x69, 0x11, 0xB8, 0xE4,
  42680. 0x71, 0x21, 0xDE, 0x0C, 0x07, 0xEB, 0xBA, 0x5D,
  42681. 0x7B, 0x59, 0x4E, 0xF2, 0x44, 0xC6, 0x83, 0x27,
  42682. 0xEC, 0x6C, 0x6D, 0x1D, 0xD5, 0x01, 0xF4, 0x83,
  42683. 0xFE, 0x9B, 0x95, 0x70, 0x59, 0x7E, 0x70, 0xDF,
  42684. 0x41, 0x3E, 0x7A, 0xF0, 0x38, 0x47, 0xF4, 0x09,
  42685. 0xED, 0x61, 0xE2, 0x84, 0x6E, 0x6C, 0x64, 0x1E,
  42686. 0x6A, 0x7F, 0xFA, 0x79, 0xDE, 0x6B, 0xFA, 0x37,
  42687. 0x3A, 0x06, 0x44, 0xB0, 0x0B, 0xF4, 0x1A, 0x03,
  42688. 0x49, 0x92, 0xA7, 0x94, 0xDA, 0x17, 0xC8, 0x88,
  42689. 0x85, 0x23, 0x90, 0x32, 0xC8, 0x51, 0x76, 0x4E,
  42690. 0x3E, 0x4D, 0xBD, 0xE7, 0xF1, 0x2A, 0x16, 0xC5,
  42691. 0xA2, 0x63, 0xE9, 0x64, 0xC1, 0xE7, 0xFD, 0xD3,
  42692. 0xCC, 0xE5, 0x76, 0xDD, 0x6D, 0x56, 0xB1, 0x81,
  42693. 0x82, 0x84, 0x8B, 0x75, 0x63, 0x64, 0x5D, 0x4E,
  42694. 0x42, 0xFF, 0x22, 0x74, 0x2A, 0x99, 0x67, 0x85,
  42695. 0x16, 0x9D, 0x7F, 0x50, 0x3B, 0x48, 0xA7, 0x15,
  42696. 0x8B, 0x3C, 0xBD, 0x29, 0x93, 0x5E, 0xD3, 0x20,
  42697. 0x49, 0xBE, 0xA1, 0xAD, 0x95, 0x3E, 0xF7, 0x07,
  42698. 0x32, 0x7B, 0x77, 0x8B, 0xFD, 0xDD, 0xFC, 0x60,
  42699. 0x51, 0x1D, 0xA1, 0x13, 0xA3, 0x4F, 0x65, 0x57,
  42700. 0x12, 0xE4, 0xE5, 0x9D, 0x6C, 0xCE, 0x40, 0x4E,
  42701. 0x94, 0xAB, 0xA6, 0x1E, 0x81, 0x35, 0x38, 0x8F,
  42702. 0xC2, 0x1C, 0x8E, 0x41, 0x34, 0x4F, 0x32, 0x4B,
  42703. 0x01, 0xAC, 0x8C, 0x06, 0x9F, 0x92, 0x57, 0x5D,
  42704. 0x34, 0xF8, 0x8B, 0xCA, 0x22, 0xCB, 0x30, 0x7E,
  42705. 0x37, 0x07, 0x00, 0x63, 0x32, 0x02, 0x56, 0xB8,
  42706. 0xBA, 0xD6, 0xEB, 0x7A, 0x81, 0xAF, 0xE9, 0xA2,
  42707. 0x54, 0x01, 0x6E, 0x1C, 0x8A, 0x12, 0x50, 0x89,
  42708. 0xAA, 0xA3, 0xED, 0xE8, 0x4E, 0x5B, 0x6C, 0x2E,
  42709. 0xCF, 0xAE, 0xFA, 0xA5, 0x2B, 0x9F, 0x57, 0x09,
  42710. 0x60, 0x2C, 0x06, 0xAE, 0xA4, 0xA0, 0x38, 0x4E,
  42711. 0x9B, 0x09, 0xE5, 0xB8, 0x81, 0x64, 0xB2, 0x74,
  42712. 0xEA, 0x32, 0x65, 0xFB, 0x51, 0x52, 0x39, 0x7D,
  42713. 0xFF, 0x5A, 0x3A, 0x08, 0x61, 0xE2, 0xBC, 0x12,
  42714. 0xD2, 0x10, 0x92, 0x89, 0x72, 0x97, 0x47, 0xE8,
  42715. 0x3F, 0xDF, 0x24, 0x3A, 0x1D, 0x17, 0xB9, 0x83,
  42716. 0x48, 0x37, 0x98, 0x45, 0xA9, 0xE9, 0x55, 0xE2,
  42717. 0xD6, 0xF9, 0x38, 0xDA, 0xA5, 0x91, 0x8E, 0x2A,
  42718. 0x14, 0xF9, 0x7B, 0xA2, 0xBE, 0x50, 0x1C, 0xCC,
  42719. 0xAF, 0xD6, 0x81, 0x91, 0x0F, 0x4A, 0x4F, 0x06,
  42720. 0x71, 0x5C, 0xE8, 0x40, 0x96, 0xF3, 0x7A, 0x91,
  42721. 0xDC, 0xCA, 0x2A, 0x8A, 0x4B, 0xE8, 0xDA, 0x79,
  42722. 0x21, 0xDB, 0xF8, 0xD3, 0xF4, 0xEF, 0xB9, 0x8C,
  42723. 0x6B, 0x4F, 0x94, 0x0E, 0xCE, 0xF8, 0x32, 0xB5,
  42724. 0x49, 0xD0, 0x68, 0x94, 0x7C, 0x3D, 0xFB, 0x58,
  42725. 0x09, 0xCB, 0x7B, 0x06, 0x0A, 0x3A, 0x0E, 0xF3,
  42726. 0xB2, 0x1C, 0x01, 0x64, 0x50, 0x1D, 0xDE, 0xA7,
  42727. 0xC9, 0xE5, 0xE7, 0x89, 0x7C, 0x6B, 0x1C, 0x46,
  42728. 0x34, 0x8B, 0x2C, 0x3E, 0x80, 0x5F, 0x6F, 0x22,
  42729. 0x87, 0xBA, 0x15, 0x8C, 0xF9, 0x25, 0xA7, 0xBA,
  42730. 0x7F, 0x08, 0x25, 0x49, 0x89, 0xC8, 0x7D, 0x24,
  42731. 0x97, 0x9A, 0xD9, 0x86, 0xAA, 0x97, 0xC5, 0x1B,
  42732. 0x01, 0xF4, 0x5D, 0x4A, 0x1F, 0x24, 0x75, 0x29,
  42733. 0x91, 0xF0, 0x42, 0x05, 0xEB, 0x55, 0x1F, 0xD0,
  42734. 0x2D, 0x41, 0x5F, 0x2D, 0xD1, 0xEF, 0xF1, 0x42,
  42735. 0xB0, 0xD7, 0x04, 0x16, 0xC6, 0xD8, 0x15, 0xEB,
  42736. 0x91, 0x73, 0x2B, 0x26, 0x8F, 0xB2, 0x0D, 0x08,
  42737. 0x67, 0x44, 0x2D, 0x71, 0xDE, 0xC0, 0x57, 0xB2,
  42738. 0x86, 0xCD, 0x93, 0x81, 0x1F, 0xF3, 0xF6, 0x46,
  42739. 0xEB, 0xD5, 0x65, 0xD5, 0x1D, 0x09, 0xA4, 0x2D,
  42740. 0x3A, 0xBA, 0xAC, 0x0F, 0x34, 0xCC, 0x81, 0x7B,
  42741. 0x18, 0x93, 0x8E, 0xCC, 0xBB, 0x1F, 0xEF, 0x05,
  42742. 0xBD, 0x3C, 0x2B, 0x49, 0x4F, 0xA5, 0x29, 0xED,
  42743. 0x4C, 0x63, 0x4C, 0x93, 0x25, 0xA4, 0x81, 0x73,
  42744. 0xF2, 0x0F, 0xFA, 0xC3, 0x2D, 0xC1, 0x01, 0xE6,
  42745. 0xEE, 0x03, 0xB2, 0xFC, 0xBE, 0xC2, 0x46, 0x8D,
  42746. 0xBC, 0x8F, 0x76, 0x75, 0x8C, 0x32, 0x15, 0x47,
  42747. 0x4F, 0x7E, 0xF2, 0x40, 0x65, 0xF7, 0x90, 0x60,
  42748. 0xAC, 0xA3, 0xC8, 0xD5, 0xD7, 0x4A, 0xF7, 0x0F,
  42749. 0x48, 0x30, 0x1D, 0xDB, 0x30, 0xC0, 0x5D, 0xB3,
  42750. 0xEF, 0xA7, 0x26, 0xCF, 0x88, 0x55, 0x59, 0x01,
  42751. 0x84, 0x12, 0x82, 0xAA, 0x08, 0xF6, 0x66, 0xA6,
  42752. 0x53, 0x51, 0xA6, 0xA2, 0x4E, 0xED, 0x6B, 0xE2,
  42753. 0x11, 0x77, 0x31, 0x07, 0xE1, 0x85, 0xE1, 0xB4,
  42754. 0x88, 0xA2, 0xE4, 0x91, 0xB6, 0xC1, 0x41, 0x52,
  42755. 0x84, 0x62, 0xA8, 0x64, 0x94, 0xB5, 0x4F, 0xDC,
  42756. 0xCE, 0xCC, 0xB6, 0xAA, 0x21, 0x25, 0x36, 0x86,
  42757. 0x69, 0x3A, 0xE7, 0x98, 0xC9, 0xCE, 0x9E, 0x0B,
  42758. 0xDD, 0xC6, 0xAE, 0x53, 0xD9, 0xB7, 0x06, 0xDC,
  42759. 0x4F, 0x4D, 0x81, 0xB9, 0xC7, 0x3C, 0x46, 0x1E,
  42760. 0xCD, 0x70, 0x35, 0xC5, 0x17, 0x2E, 0xFA, 0xE5,
  42761. 0x60, 0x2C, 0xAF, 0x88, 0xC6, 0x4E, 0x79, 0xE5,
  42762. 0x32, 0x40, 0x30, 0x55, 0x5D, 0xE2, 0x11, 0xF8,
  42763. 0x9F, 0xD4, 0x24, 0xC3, 0x38, 0xC3, 0x88, 0x3C,
  42764. 0x83, 0xCA, 0x94, 0x05, 0xC2, 0xB5, 0xD1, 0x44,
  42765. 0x5F, 0x7C, 0x98, 0xC4, 0x3E, 0xD3, 0xD2, 0xBE,
  42766. 0xCB, 0xE2, 0x5F, 0x5F, 0x3F, 0x54, 0x4C, 0xCC,
  42767. 0x5B, 0x5A, 0xEA, 0xE4, 0x7D, 0xDF, 0x3F, 0xB5,
  42768. 0x64, 0x9F, 0xF5, 0xD6, 0x1E, 0xAA, 0x02, 0xED,
  42769. 0xEB, 0xC7, 0x5C, 0xE4, 0x78, 0xBA, 0x00, 0x42,
  42770. 0x6C, 0xAF, 0x47, 0x4F, 0xA7, 0x9E, 0x5B, 0x08,
  42771. 0x9E, 0xB1, 0xA8, 0x82, 0xF1, 0x53, 0x54, 0x59,
  42772. 0x26, 0x95, 0x95, 0x2B, 0xA0, 0xA8, 0xEE, 0x91,
  42773. 0xE6, 0x49, 0xE3, 0xF2, 0xC3, 0x82, 0x26, 0x4D,
  42774. 0xAA, 0x30, 0xF6, 0xA6, 0xD2, 0x17, 0xF6, 0x12,
  42775. 0x9C, 0x19, 0x39, 0xB6, 0xDC, 0xAC, 0xCD, 0xA5,
  42776. 0xB6, 0x37, 0x32, 0x6E, 0x8A, 0x83, 0x61, 0xC3,
  42777. 0xB5, 0x6F, 0xCF, 0xFC, 0x48, 0x50, 0x36, 0x86,
  42778. 0x58, 0x22, 0xB9, 0xBB, 0x87, 0xB4, 0x35, 0x10,
  42779. 0xBC, 0xDD, 0x55, 0xBC, 0x35, 0x0D, 0xE7, 0xB2,
  42780. 0xAE, 0x90, 0xA2, 0x1E, 0x9E, 0x19, 0x97, 0x8E,
  42781. 0xDA, 0x10, 0xDF, 0x66, 0x76, 0x14, 0xA4, 0x4F,
  42782. 0xE2, 0xA8, 0x4D, 0x16, 0xBE, 0x04, 0x3E, 0xA8,
  42783. 0x77, 0x36, 0x33, 0xEA, 0x6B, 0xAD, 0xF6, 0x57,
  42784. 0x10, 0x05, 0x2F, 0x34, 0x1F, 0x65, 0xCB, 0xE9,
  42785. 0x28, 0xD3, 0x96, 0x2A, 0x5A, 0x2F, 0xE6, 0x4E,
  42786. 0x46, 0xD6, 0xBF, 0xB8, 0xFD, 0x0D, 0x99, 0x78,
  42787. 0xF0, 0x42, 0x3C, 0xBD, 0x19, 0x5F, 0x72, 0xF3,
  42788. 0xCB, 0x19, 0xD7, 0xEF, 0xD9, 0xEB, 0xE3, 0x3C,
  42789. 0xD2, 0xF5, 0x70, 0x9A, 0x57, 0x80, 0x7D, 0xF9,
  42790. 0x44, 0xEC, 0xE5, 0x68, 0xAA, 0xCA, 0x43, 0x36,
  42791. 0x42, 0x20, 0x83, 0xB0, 0x69, 0x7B, 0x6A, 0xA0,
  42792. 0x05, 0x86, 0xE4, 0xBF, 0x7D, 0xD6, 0x73, 0xA3,
  42793. 0xD5, 0x96, 0xB8, 0x61, 0x8A, 0xC3, 0xB4, 0x06,
  42794. 0x17, 0x50, 0xC6, 0xBE, 0x97, 0xCB, 0x53, 0x75,
  42795. 0x3D, 0x02, 0x39, 0x55, 0x56, 0x07, 0x5A, 0x26,
  42796. 0xF1, 0x40, 0xB9, 0x3F, 0x57, 0x7D, 0xAD, 0x50,
  42797. 0x5E, 0x1C, 0xF2, 0xB5, 0x51, 0xA0, 0x4C, 0x98,
  42798. 0xC7, 0xF0, 0x90, 0x18, 0x31, 0xB3, 0xCA, 0x61,
  42799. 0xD7, 0x5D, 0xA7, 0x93, 0xAC, 0x72, 0xA4, 0x4C,
  42800. 0x7A, 0x07, 0xF7, 0xDB, 0xBA, 0xD6, 0x0A, 0x55,
  42801. 0xF4, 0x9C, 0xBD, 0x79, 0xDE, 0xE4, 0x73, 0x9F,
  42802. 0xFD, 0x36, 0x77, 0x8E, 0xBD, 0x08, 0xEB, 0xDB,
  42803. 0x79, 0xEC, 0x07, 0xA1, 0x62, 0x39, 0xC5, 0xB9,
  42804. 0x21, 0x59, 0x9F, 0xEB, 0xFE, 0xA4, 0x6D, 0xDF,
  42805. 0x96, 0x6A, 0xA4, 0xA0, 0x15, 0x12, 0xE6, 0x10,
  42806. 0x94, 0x3F, 0x5D, 0xC5, 0x4B, 0x4C, 0x76, 0xB7,
  42807. 0x64, 0xB3, 0x80, 0xBF, 0x2F, 0x84, 0xED, 0xE3,
  42808. 0x21, 0x24, 0x91, 0x2F, 0x54, 0xF7, 0xB6, 0xE2,
  42809. 0x07, 0xB7, 0x38, 0x1F, 0x67, 0x0F, 0x7A, 0xA0,
  42810. 0xF3, 0xC3, 0xED, 0x10, 0x15, 0x74, 0x03, 0x84,
  42811. 0xDD, 0x61, 0xA9, 0x76, 0x5E, 0xE4, 0x69, 0x6E,
  42812. 0xAC, 0xF8, 0x2E, 0xA4, 0x10, 0x69, 0x18, 0x05,
  42813. 0xCB, 0x68, 0x89, 0x03, 0x53, 0x5D, 0x70, 0x46,
  42814. 0x10, 0x0D, 0xCC, 0x2B, 0xA7, 0xD8, 0x30, 0x2A,
  42815. 0xCB, 0x04, 0x30, 0xD5, 0x06, 0xCC, 0xC1, 0xC0,
  42816. 0xDD, 0xEA, 0x71, 0x11, 0xA7, 0x6F, 0x45, 0xB4,
  42817. 0x54, 0xE2, 0x5C, 0xDD, 0xFB, 0x63, 0x9B, 0x3D,
  42818. 0x66, 0x4C, 0x36, 0xD8, 0x84, 0x35, 0x13, 0xA3,
  42819. 0xFC, 0xAF, 0x9E, 0x60, 0x57, 0xE9, 0xBC, 0x06,
  42820. 0x82, 0x37, 0xFE, 0x24, 0x19, 0xA2, 0xD2, 0xD9,
  42821. 0x0B, 0x4A, 0x1F, 0xC2, 0xA7, 0x1A, 0x14, 0x6D,
  42822. 0x2B, 0xD0, 0x43, 0x64, 0xC7, 0x9B, 0x8E, 0xBA,
  42823. 0x8E, 0x3E, 0x88, 0xCE, 0x11, 0xE9, 0x16, 0xE4,
  42824. 0xA7, 0x52, 0x84, 0x21, 0x32, 0x8C, 0xF5, 0x4F,
  42825. 0xAA, 0xB2, 0xB1, 0x9F, 0x44, 0x46, 0x87, 0x81,
  42826. 0xF8, 0xAB, 0x84, 0xB7, 0xDD, 0x97, 0x2F, 0xF5,
  42827. 0x61, 0x50, 0x71, 0x43, 0x0A, 0x43, 0x74, 0xDA,
  42828. 0xFC, 0xAE, 0x1E, 0x60, 0x44, 0xAA, 0x98, 0xE9,
  42829. 0x85, 0x94, 0x1B, 0xA6, 0xB9, 0xDB, 0x8C, 0x02,
  42830. 0xF5, 0x89, 0x60, 0x3E, 0xEB, 0x8B, 0xE9, 0x0A,
  42831. 0x70, 0xEF, 0xC0, 0x88, 0xD7, 0x95, 0xE6, 0xDA,
  42832. 0x1F, 0x1F, 0x2E, 0x6E, 0xCE, 0xDD, 0x03, 0x1D,
  42833. 0x81, 0x99, 0xE6, 0x59, 0x12, 0xD4, 0x34, 0xD0,
  42834. 0x9B, 0xFB, 0xE5, 0x94, 0x40, 0x6D, 0xC1, 0x15,
  42835. 0x0E, 0x99, 0x35, 0x8C, 0xEA, 0x7F, 0xAD, 0x2E,
  42836. 0x7C, 0x44, 0xC3, 0x8B, 0x6E, 0x0C, 0xEE, 0xAB,
  42837. 0x9B, 0xDE, 0x0D, 0xB9, 0x7B, 0xCF, 0x5A, 0xC9,
  42838. 0x94, 0x10, 0xC9, 0x47, 0x0E, 0x26, 0x6B, 0x8B,
  42839. 0xE4, 0x5F, 0x66, 0x90, 0x83, 0x1F, 0x41, 0x45,
  42840. 0xE2, 0x63, 0x79, 0xDB, 0x80, 0x7C, 0x26, 0xDD,
  42841. 0xF9, 0x1E, 0x30, 0x9D, 0x4F, 0x4A, 0x3E, 0x7E,
  42842. 0xCA, 0xB7, 0x36, 0x2F, 0x15, 0xD2, 0x0E, 0xA4,
  42843. 0x33, 0xB7, 0xE7, 0x0A, 0x7D, 0xDE, 0x74, 0x16,
  42844. 0xCE, 0xA8, 0x71, 0x49, 0x8B, 0x2C, 0xE3, 0xF5,
  42845. 0x8D, 0x29, 0xD8, 0x62, 0x8C, 0x53, 0x18, 0x40,
  42846. 0xF0, 0x22, 0xDD, 0x3B, 0xD2, 0xF3, 0x80, 0x9B,
  42847. 0x11, 0x68, 0xD3, 0x8E, 0x63, 0xC7, 0xF6, 0x93,
  42848. 0x08, 0xA3, 0x1A, 0x2D, 0x4D, 0x5E, 0xEB, 0x97,
  42849. 0x42, 0x39, 0xB3, 0x4A, 0x62, 0xBC, 0x85, 0xE4,
  42850. 0xEC, 0xF9, 0x0C, 0x33, 0x6A, 0x0C, 0x37, 0xBD,
  42851. 0x9E, 0x0E, 0xF4, 0x26, 0x6B, 0x83, 0x5A, 0xC8,
  42852. 0x90, 0x6A, 0x83, 0xCF, 0x0B, 0x35, 0x13, 0x8A,
  42853. 0x65, 0xE5, 0xD9, 0xA6, 0x1F, 0xCC, 0x9B, 0x2D,
  42854. 0x5A, 0x33, 0x7B, 0x8A, 0xBE, 0xF8, 0x8A, 0x7F,
  42855. 0xB3, 0xC0, 0x94, 0x5D, 0x7C, 0xAF, 0x35, 0x61,
  42856. 0x1A, 0xE0, 0xE4, 0x46, 0x93, 0xA5, 0xBC, 0xE0,
  42857. 0xA6, 0xE2, 0xFE, 0xCA, 0xE9, 0xBD, 0xF4, 0xE3,
  42858. 0x56, 0xD6, 0x53, 0x6B, 0x58, 0x1A, 0x18, 0xF0,
  42859. 0x3A, 0x59, 0x16, 0x4E, 0xD5, 0x44, 0x7C, 0x7E,
  42860. 0xC8, 0xBD, 0x99, 0x7B, 0xE9, 0x53, 0xDE, 0xD9,
  42861. 0x32, 0x53, 0x5B, 0x5F, 0x43, 0x8A, 0x04, 0x31,
  42862. 0x9F, 0x5E, 0x0D, 0x8B, 0x0F, 0xEB, 0xC8, 0xDE,
  42863. 0x81, 0x46, 0x65, 0x8E, 0x52, 0xB9, 0x75, 0x9C,
  42864. 0x73, 0x93, 0x5B, 0x12, 0x0D, 0xC9, 0xB8, 0x54,
  42865. 0xF3, 0xC8, 0xF9, 0x4E, 0xC9, 0x33, 0x90, 0x57,
  42866. 0xD7, 0xD7, 0xCD, 0x91, 0xF7, 0xE0, 0xB9, 0x8D,
  42867. 0x84, 0xEC, 0x7B, 0x2F, 0x92, 0x32, 0x8D, 0x73,
  42868. 0x60, 0x18, 0xB0, 0x31, 0x65, 0xA8, 0x74, 0x5F,
  42869. 0x8E, 0x77, 0xEB, 0x80, 0x29, 0xF9, 0x78, 0x26,
  42870. 0x70, 0xCB, 0xD8, 0x6B, 0x43, 0x16, 0xC7, 0xBE,
  42871. 0x4A, 0x88, 0x03, 0x38, 0xBA, 0xCF, 0xB0, 0x15,
  42872. 0x69, 0x9B, 0xF3, 0x0D, 0x3A, 0x4B, 0x05, 0x32,
  42873. 0x54, 0x35, 0xBA, 0x5F, 0xA3, 0xB9, 0xD2, 0xB2,
  42874. 0xFE, 0x0B, 0x51, 0x9C, 0x2C, 0xB2, 0x46, 0xE5,
  42875. 0x3D, 0x1A, 0x34, 0x3D, 0x66, 0x1A, 0x66, 0x14,
  42876. 0x3C, 0x6F, 0x46, 0x8C, 0x55, 0x38, 0x64, 0x5C,
  42877. 0xC2, 0x6D, 0x4E, 0x2A, 0x87, 0x03, 0xEC, 0x9B,
  42878. 0x10, 0xFC, 0x89, 0xBE, 0x6F, 0x85, 0x99, 0x97,
  42879. 0x70, 0x8F, 0x31, 0x19, 0x4F, 0x0D, 0xFE, 0xE9,
  42880. 0x29, 0x98, 0xB2, 0x5E, 0x93, 0xB9, 0x70, 0x70,
  42881. 0xDE, 0x14, 0x40, 0x9D, 0x5B, 0xA4, 0x3D, 0xF8,
  42882. 0x8D, 0x15, 0xC2, 0xFB, 0xA9, 0x7B, 0xDD, 0xE6,
  42883. 0x18, 0xCC, 0x3F, 0xC0, 0x42, 0xF7, 0x74, 0x81,
  42884. 0x84, 0xBA, 0x9E, 0xC9, 0xCB, 0xA1, 0xB2, 0x00,
  42885. 0x68, 0x81, 0xD0, 0x51, 0x42, 0x64, 0x19, 0x8F,
  42886. 0xB6, 0x91, 0xC5, 0xC0, 0x38, 0xE0, 0x49, 0x50,
  42887. 0xCF, 0x69, 0x09, 0x93, 0x77, 0xFE, 0x66, 0xBA,
  42888. 0x64, 0xE2, 0x19, 0x52, 0xA4, 0x45, 0x81, 0x71,
  42889. 0x96, 0x64, 0xF5, 0xD9, 0x23, 0x97, 0xD2, 0x2A,
  42890. 0xA7, 0x03, 0x2B, 0xF5, 0x89, 0xAF, 0x8A, 0xCA,
  42891. 0x48, 0xDF, 0x6D, 0x14, 0xEB, 0x43, 0xCE, 0xF0,
  42892. 0xA9, 0xC8, 0xA8, 0xF9, 0xAD, 0x32, 0x95, 0x25,
  42893. 0xEF, 0x0A, 0xAA, 0x4F, 0x9E, 0x09, 0xC3, 0x51,
  42894. 0x3C, 0xF0, 0x29, 0xF3, 0xDE, 0xFC, 0xBB, 0x41,
  42895. 0x14, 0xFA, 0x0F, 0x66, 0x8D, 0xB4, 0x72, 0x2F,
  42896. 0xCC, 0xD9, 0xC2, 0x07, 0xB6, 0x6F, 0x10, 0x9E,
  42897. 0xD9, 0x5B, 0x45, 0x4B, 0xB6, 0x19, 0x5D, 0x59,
  42898. 0xC4, 0xA6, 0x78, 0xBA, 0x6F, 0x5A, 0x9B, 0x23,
  42899. 0x41, 0x21, 0xAD, 0x05, 0x16, 0xA1, 0xD4, 0x12,
  42900. 0x3D, 0x38, 0x26, 0xD9, 0x2A, 0x61, 0xB3, 0x5D,
  42901. 0xEB, 0x29, 0x5B, 0xAA, 0x2F, 0xE1, 0xB5, 0xEE,
  42902. 0x25, 0x02, 0x1D, 0xAE, 0xF8, 0x57, 0xB5, 0xDF,
  42903. 0x19, 0x2E, 0x17, 0x5E, 0x3A, 0x2A, 0x0D, 0x3F,
  42904. 0x08, 0x2F, 0x21, 0x1C, 0xB5, 0xBD, 0xC2, 0x36,
  42905. 0x27, 0x4F, 0x86, 0xC5, 0xDC, 0x74, 0xC3, 0x9B,
  42906. 0xE9, 0x7C, 0xCF, 0x5F, 0x57, 0x94, 0xEB, 0x64,
  42907. 0xEC, 0x64, 0x55, 0x45, 0x21, 0x0F, 0xC6, 0x67,
  42908. 0xD1, 0xE0, 0x74, 0x0E, 0x66, 0xCB, 0xED, 0xC2,
  42909. 0x06, 0x48, 0xCA, 0x1F, 0xA7, 0x34, 0x14, 0x59,
  42910. 0x6B, 0xA0, 0x89, 0x17, 0xA1, 0x9A, 0x46, 0x3A,
  42911. 0xD3, 0x02, 0x7C, 0x81, 0x83, 0x6B, 0x8F, 0x4F,
  42912. 0x02, 0xB9, 0x9F, 0xC5, 0x08, 0x3F, 0x06, 0xF3,
  42913. 0x4B, 0xD2, 0x30, 0x9C, 0x23, 0x42, 0xAD, 0x88,
  42914. 0xA8, 0x4F, 0xA9, 0x6E, 0x20, 0x7C, 0x01, 0x08,
  42915. 0xF6, 0x82, 0x54, 0x14, 0x94, 0x4F, 0x26, 0x4E,
  42916. 0xD6, 0xC4, 0x66, 0x7C, 0x78, 0x8D, 0x61, 0xA6,
  42917. 0xBC, 0x2C, 0x45, 0x6A, 0xF6, 0x6C, 0x2F, 0x76,
  42918. 0x9E, 0x16, 0x90, 0x17, 0x06, 0x91, 0x2C, 0xC9,
  42919. 0x0D, 0x4B, 0x6C, 0x90, 0xDC, 0xA1, 0x6C, 0xAC,
  42920. 0x8F, 0xFE, 0xD8, 0x39, 0x70, 0x20, 0xE2, 0x97,
  42921. 0x5E, 0x24, 0xFF, 0x4C, 0x80, 0x7C, 0x8A, 0xB7,
  42922. 0x31, 0xC8, 0x1D, 0x36, 0xCA, 0x84, 0xC9, 0x12,
  42923. 0x1A, 0x85, 0x13, 0xE0, 0xC9, 0xD0, 0xF4, 0x1B,
  42924. 0xC6, 0x8F, 0x88, 0xEA, 0xCA, 0xA3, 0x55, 0x99,
  42925. 0xFA, 0xE3, 0xBB, 0xA6, 0xFC, 0xC6, 0x52, 0x8D,
  42926. 0x47, 0xE4, 0x0C, 0x07, 0x64, 0xCF, 0x9C, 0x83,
  42927. 0x83, 0xB3, 0xA4, 0x45, 0x15, 0xE6, 0x1D, 0x92,
  42928. 0xCD, 0xAE, 0xC9, 0xCB, 0x90, 0x82, 0xB5, 0xA0,
  42929. 0xC0, 0x37, 0x94, 0x60, 0xD9, 0x17, 0x9A, 0x7D,
  42930. 0x9D, 0xF2, 0x9E, 0x0B, 0x4B, 0x6A, 0x41, 0x18,
  42931. 0x28, 0x52, 0x15, 0xE8, 0x7B, 0x6F, 0x11, 0x8E,
  42932. 0x97, 0x31, 0xE4, 0x66, 0xFB, 0x3F, 0xEB, 0xD1,
  42933. 0x95, 0xE1, 0x44, 0xFD, 0x20, 0x37, 0xD1, 0x16,
  42934. 0x62, 0x75, 0x79, 0xAC, 0x55, 0xFE, 0xD5, 0xE3,
  42935. 0x25, 0x85, 0xEC, 0x66, 0x38, 0xA0, 0xDF, 0xBE,
  42936. 0x6E, 0xD6, 0xC5, 0x87, 0x6C, 0xF8, 0x11, 0x4C,
  42937. 0x90, 0x2A, 0xEF, 0xA3, 0x63, 0xF4, 0xC9, 0xB7,
  42938. 0x2E, 0x7D, 0x5C, 0x85, 0x2D, 0xCC, 0x1A, 0xF2,
  42939. 0xB8, 0x85, 0x2A, 0x9D, 0x0F, 0x99, 0x59, 0x38,
  42940. 0x86, 0x50, 0x84, 0xCE, 0x52, 0x13, 0xB3, 0x08,
  42941. 0xA9, 0xCB, 0x37, 0xF6, 0x81, 0x96, 0x0D, 0x84,
  42942. 0xEF, 0xE1, 0xDF, 0x51, 0x34, 0xA5, 0x91, 0x5A,
  42943. 0xE5, 0x87, 0x8B, 0x10, 0xDA, 0x0F, 0xD4, 0xD9,
  42944. 0xAC, 0x2A, 0xEF, 0x0C, 0x7E, 0x01, 0xC2, 0xE9,
  42945. 0xE7, 0xC0, 0x17, 0xE7, 0xBA, 0x74, 0x0C, 0xEE,
  42946. 0x1A, 0x89, 0x94, 0x59, 0xBB, 0x75, 0x03, 0x3E,
  42947. 0xEA, 0xF3, 0x19, 0x0D, 0x67, 0x79, 0xED, 0x9E,
  42948. 0xDD, 0x84, 0x6A, 0x74, 0xE3, 0x21, 0x52, 0x8C,
  42949. 0x03, 0x08, 0x4A, 0x5D, 0x30, 0x87, 0x48, 0x39,
  42950. 0x71, 0x8A, 0x53, 0x54, 0x9B, 0x2E, 0xC6, 0xB2,
  42951. 0xB7, 0x30, 0xAA, 0x93, 0x5C, 0xA6, 0xE1, 0xC4,
  42952. 0xFD, 0x8B, 0xE0, 0x35, 0x7D, 0x93, 0xF6, 0x21,
  42953. 0x74, 0xEE, 0xED, 0xF8, 0xDA, 0xB7, 0x75, 0x5B,
  42954. 0x46, 0x65, 0x7E, 0x59, 0xD7, 0xAA, 0x00, 0xB9,
  42955. 0xF2, 0xF8, 0x5E, 0x4C, 0x0F, 0x77, 0xFA, 0x11,
  42956. 0xA5, 0xD6, 0x9A, 0x23, 0xB1, 0xEF, 0x3A, 0x09,
  42957. 0xF2, 0x19, 0xD8, 0x3B, 0x1F, 0x39, 0x1F, 0x84,
  42958. 0x13, 0x18, 0xEE, 0xF3, 0x5A, 0x32, 0x63, 0x67,
  42959. 0xBF, 0xA2, 0xB1, 0x5F, 0xD7, 0x14, 0x03, 0x20,
  42960. 0x92, 0xB9, 0xD0, 0x2B, 0xF6, 0x13, 0xAF, 0xF7,
  42961. 0x69, 0x6F, 0xAD, 0xF1, 0xDE, 0x2C, 0x81, 0x70,
  42962. 0x77, 0xCB, 0x7C, 0x99, 0x67, 0x76, 0xD6, 0x9E,
  42963. 0xC2, 0x41, 0xA2, 0x42, 0x54, 0xDA, 0x2D, 0x13,
  42964. 0x98, 0x76, 0x91, 0xEA, 0xC7, 0xEB, 0xA8, 0xCD,
  42965. 0x8D, 0xCF, 0xB3, 0x94, 0x7B, 0x1D, 0x99, 0xED,
  42966. 0xF9, 0x62, 0xD2, 0x15, 0xB3, 0x18, 0xBB, 0x5F,
  42967. 0x9A, 0xA0, 0x4D, 0x1C, 0x82, 0x62, 0x6A, 0x41,
  42968. 0x73, 0xD0, 0x2D, 0x41, 0x0C, 0x58, 0x6B, 0xCA,
  42969. 0x4E, 0x51, 0xCA, 0x4F, 0x3E, 0x15, 0x1B, 0x54,
  42970. 0xF1, 0x7A, 0x6B, 0xC9, 0x67, 0x76, 0x09, 0xBB,
  42971. 0xAF, 0x6C, 0x30, 0x38, 0xA6, 0x7C, 0xAD, 0xA6,
  42972. 0x6B, 0x4F, 0xDF, 0xB5, 0x10, 0x29, 0xE0, 0x78,
  42973. 0x07, 0xD7, 0x05, 0x96, 0x9D, 0x96, 0xC9, 0xAB,
  42974. 0xFB, 0x71, 0x62, 0xE4, 0x58, 0x10, 0xA1, 0xDC,
  42975. 0x4B, 0x56, 0xDA, 0x14, 0x77, 0xED, 0x90, 0x0A,
  42976. 0x89, 0xCC, 0xAC, 0x29, 0x8E, 0x17, 0x88, 0x42,
  42977. 0x69, 0xC3, 0x9E, 0x8D, 0x7A, 0xB9, 0x66, 0xF3,
  42978. 0x3D, 0xDA, 0xDB, 0xE5, 0x6A, 0x38, 0x4C, 0xA2,
  42979. 0x0A, 0x7B, 0x18, 0x99, 0xEC, 0x18, 0xE2, 0xAE,
  42980. 0x54, 0x70, 0x00, 0xB9, 0x04, 0xE3, 0x4E, 0x46,
  42981. 0x80, 0x1D, 0x85, 0x74, 0xDB, 0x00, 0x84, 0x17,
  42982. 0xBC, 0xFD, 0xD1, 0xA7, 0x4D, 0xC0, 0x18, 0xE5,
  42983. 0x07, 0xB7, 0x6B, 0x0F, 0xA0, 0x86, 0x26, 0x23,
  42984. 0x5B, 0x1C, 0xE2, 0x4B, 0xCF, 0xC3, 0x20, 0xFA,
  42985. 0xE3, 0x55, 0x1C, 0x1C, 0x92, 0x9B, 0x94, 0xC7,
  42986. 0xC4, 0x96, 0x53, 0x41, 0x82, 0x9D, 0x8A, 0x13,
  42987. 0x47, 0xD6, 0xA7, 0x38, 0x58, 0x03, 0xB0, 0x8B,
  42988. 0xCD, 0xA8, 0x4A, 0x27, 0xEA, 0x5E, 0x49, 0xCA,
  42989. 0x1E, 0x60, 0x06, 0xEA, 0x23, 0x2A, 0x53, 0xEE,
  42990. 0x41, 0x7E, 0xC8, 0x81, 0xD3, 0x32, 0x8A, 0x15,
  42991. 0x63, 0x82, 0xA6, 0xB2, 0x93, 0x89, 0x4D, 0xDF,
  42992. 0x9B, 0x36, 0x9C, 0xDE, 0x6B, 0x2F, 0xF5, 0x9C,
  42993. 0xB6, 0xA5, 0x64, 0xE2, 0x1C, 0x92, 0x79, 0xEC,
  42994. 0xA0, 0x31, 0x1F, 0x5D, 0x80, 0xCE, 0x39, 0xB9,
  42995. 0x8B, 0xF9, 0x0D, 0xB3, 0x27, 0xF7, 0x4D, 0x3F,
  42996. 0x76, 0x2D, 0x11, 0x7D, 0xF5, 0xF9, 0x13, 0x20,
  42997. 0x84, 0xFF, 0xB5, 0x55, 0xA5, 0xD1, 0x47, 0x22,
  42998. 0x1A, 0xF8, 0x63, 0xAB, 0xF7, 0x87, 0x15, 0xB7,
  42999. 0x21, 0x94, 0x52, 0x9A, 0x0E, 0x33, 0x4D, 0x4A,
  43000. 0x19, 0x1D, 0x42, 0xA9, 0x9B, 0xEA, 0x52, 0xAD,
  43001. 0xA2, 0xC7, 0xCC, 0x4A, 0x97, 0x74, 0xD5, 0xCB,
  43002. 0x28, 0xD4, 0xED, 0x82, 0xB6, 0x1F, 0x94, 0xE8,
  43003. 0x9F, 0x60, 0xF0, 0xC8, 0xEA, 0x52, 0xDC, 0x07,
  43004. 0x9D, 0x46, 0x58, 0xBF, 0x8C, 0x85, 0x6D, 0x61,
  43005. 0x52, 0xD9, 0x22, 0x51, 0x94, 0x8B, 0x3B, 0xA0,
  43006. 0x14, 0xD8, 0xBA, 0xF3, 0xDC, 0xD3, 0x6B, 0xC7,
  43007. 0x1F, 0x8E, 0x5B, 0x2C, 0xE6, 0xF5, 0x35, 0xB7,
  43008. 0xB9, 0xAE, 0x13, 0xDA, 0x4A, 0x1E, 0xAF, 0xFC,
  43009. 0x25, 0x3B, 0xE4, 0x3A, 0x9F, 0x60, 0x8E, 0xAC,
  43010. 0xE7, 0x33, 0xCF, 0xCE, 0x52, 0xEA, 0x5C, 0xDA,
  43011. 0x83, 0x59, 0xDB, 0x53, 0xFF, 0x3A, 0xF2, 0xCE,
  43012. 0xFE, 0x87, 0x79, 0xBC, 0xC5, 0x3C, 0x24, 0xA4,
  43013. 0xB1, 0x8D, 0x5E, 0x0D, 0x78, 0x1B, 0xEC, 0xF7,
  43014. 0x5B, 0x54, 0x77, 0x47, 0x3A, 0x20, 0x24, 0xAD,
  43015. 0x56, 0xC5, 0x4A, 0x7F, 0x99, 0x0E, 0xF6, 0xB1,
  43016. 0xDF, 0xAC, 0x50, 0x10, 0x88, 0x50, 0x9D, 0x3A,
  43017. 0x37, 0xF1, 0xC8, 0xD5, 0xC2, 0x64, 0x87, 0xE4,
  43018. 0x20, 0xB7, 0xF4, 0x35, 0x8E, 0x92, 0x69, 0x76,
  43019. 0x1F, 0xF1, 0xFA, 0x3A, 0xFC, 0xBE, 0xCA, 0xEB,
  43020. 0x68, 0xF5, 0xDD, 0xDE, 0x3A, 0xA8, 0xFD, 0x07,
  43021. 0x8C, 0xC4, 0x22, 0x4C, 0xEA, 0x67, 0x13, 0x2D,
  43022. 0x7E, 0xBF, 0x5D, 0x23, 0x2E, 0x43, 0xBA, 0xDD,
  43023. 0x21, 0x8C, 0x0B, 0x4D, 0xBE, 0x1E, 0x16, 0x52,
  43024. 0x98, 0x66, 0xB9, 0xAB, 0x93, 0x58, 0x85, 0xAC,
  43025. 0xB4, 0x15, 0xFB, 0xB1, 0xEE, 0xE6, 0x94, 0x08,
  43026. 0xA5, 0x21, 0xB4, 0x62, 0xEC, 0x59, 0xCD, 0x0D,
  43027. 0x3C, 0x54, 0x96, 0xD9, 0x85, 0xAE, 0xB0, 0xCE,
  43028. 0x37, 0x4F, 0x67, 0x72, 0xA4, 0xE6, 0x39, 0x3A,
  43029. 0x4E, 0xF0, 0x07, 0x43, 0x80, 0x90, 0xA8, 0xA9,
  43030. 0xE5, 0x2D, 0x2F, 0x55, 0x66, 0x6D, 0x70, 0xF0,
  43031. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  43032. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  43033. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
  43034. 0x08, 0x0E, 0x12, 0x19, 0x20
  43035. };
  43036. #endif
  43037. #ifndef WOLFSSL_NO_ML_DSA_87
  43038. static const byte pk_87[] = {
  43039. 0x2D, 0x1E, 0x6B, 0xED, 0x84, 0x52, 0xEB, 0xF1,
  43040. 0x26, 0xED, 0xE7, 0x0C, 0xA0, 0xA2, 0xB5, 0x0D,
  43041. 0x03, 0x34, 0x2D, 0x5B, 0x13, 0xB2, 0xAE, 0x21,
  43042. 0x0F, 0x45, 0x62, 0xA3, 0xBF, 0x67, 0x0C, 0xB1,
  43043. 0x5C, 0xE9, 0x25, 0xFD, 0x22, 0xF2, 0x62, 0x42,
  43044. 0xBA, 0xE3, 0x10, 0xB3, 0xAA, 0x41, 0x3B, 0x6E,
  43045. 0x78, 0xD4, 0x42, 0xD9, 0x35, 0xD1, 0x72, 0x8A,
  43046. 0x32, 0x48, 0xCC, 0x20, 0x5C, 0xCD, 0x8D, 0x3F,
  43047. 0xD8, 0x34, 0x95, 0x55, 0x20, 0xCD, 0xFB, 0x2C,
  43048. 0x73, 0xE9, 0x0E, 0x60, 0x8B, 0x2C, 0x3F, 0xA8,
  43049. 0xB7, 0xD1, 0x79, 0xFD, 0xDC, 0xC8, 0x81, 0x11,
  43050. 0xC9, 0xE8, 0x41, 0x71, 0xE9, 0x70, 0x9B, 0x53,
  43051. 0x59, 0x33, 0xE4, 0x92, 0xB6, 0x81, 0x9C, 0x6A,
  43052. 0x92, 0xED, 0xA2, 0x5A, 0xC4, 0x07, 0x77, 0x1A,
  43053. 0x8F, 0xED, 0xB4, 0xE7, 0x11, 0xFB, 0x89, 0xEB,
  43054. 0x7B, 0xDF, 0xCC, 0xEA, 0xC5, 0x3B, 0x4E, 0xF4,
  43055. 0x6B, 0x6F, 0xBE, 0xE1, 0x32, 0xA9, 0xD7, 0xAD,
  43056. 0xB4, 0x36, 0xE7, 0x4A, 0x6D, 0x67, 0x11, 0x83,
  43057. 0xAF, 0x31, 0x1A, 0x7A, 0x31, 0x42, 0x9B, 0x01,
  43058. 0x21, 0x17, 0x52, 0x75, 0x85, 0xF7, 0x92, 0x0F,
  43059. 0x34, 0x8A, 0x69, 0x11, 0x88, 0x5A, 0x02, 0x08,
  43060. 0xB6, 0x6D, 0xE3, 0x07, 0x93, 0xB1, 0x3F, 0xE1,
  43061. 0xD5, 0x7B, 0xD9, 0x51, 0xF7, 0xAA, 0xC0, 0x34,
  43062. 0x9A, 0x78, 0x5D, 0x26, 0xDB, 0xF1, 0xF0, 0xA9,
  43063. 0x1E, 0x5C, 0x9F, 0x4F, 0xA7, 0x43, 0x5C, 0x44,
  43064. 0xA9, 0x43, 0xF1, 0x38, 0x11, 0x45, 0xED, 0xEB,
  43065. 0x1C, 0x8A, 0x05, 0xEE, 0xFF, 0xAB, 0x20, 0x2C,
  43066. 0xF6, 0x2C, 0xEE, 0x77, 0x42, 0x36, 0x3E, 0xE6,
  43067. 0x9D, 0x8E, 0x45, 0x0F, 0xF6, 0x7C, 0x39, 0x62,
  43068. 0xD6, 0xFF, 0x97, 0xBC, 0x3D, 0x02, 0xD6, 0xDF,
  43069. 0x4A, 0x35, 0xDA, 0x3F, 0x89, 0xA4, 0x88, 0x33,
  43070. 0xCD, 0xF2, 0x90, 0xF0, 0xE9, 0x37, 0x2F, 0x65,
  43071. 0xA5, 0x88, 0x65, 0xFD, 0x40, 0x44, 0xAD, 0x09,
  43072. 0x09, 0x92, 0xAA, 0x15, 0x9E, 0xEE, 0xF7, 0x2B,
  43073. 0x0D, 0xA7, 0xCB, 0x3A, 0x5E, 0x0A, 0xED, 0xD6,
  43074. 0x7D, 0x82, 0x8B, 0xBA, 0xCF, 0xE5, 0x9E, 0xE4,
  43075. 0x62, 0xAB, 0x69, 0x6B, 0xBA, 0xD0, 0xE5, 0xA9,
  43076. 0xBB, 0x1F, 0x5A, 0x51, 0xE0, 0xFA, 0x5D, 0xD4,
  43077. 0x4D, 0x8E, 0xC0, 0xDC, 0x43, 0x06, 0xDF, 0x23,
  43078. 0x67, 0xB2, 0x4A, 0xA2, 0xFB, 0x75, 0x2F, 0x82,
  43079. 0xD8, 0x44, 0xE4, 0xC0, 0xCE, 0x15, 0x9E, 0x3F,
  43080. 0xD6, 0xB4, 0x70, 0x5F, 0x3B, 0xD0, 0x56, 0x3E,
  43081. 0x0A, 0x7A, 0x4B, 0x94, 0xBF, 0xBA, 0x01, 0x2B,
  43082. 0x9C, 0x8B, 0x91, 0x35, 0xF2, 0xDB, 0x4C, 0x8C,
  43083. 0x8D, 0xD6, 0xEE, 0xC8, 0x65, 0x8D, 0xF3, 0x05,
  43084. 0x59, 0xBE, 0x3A, 0x17, 0xA7, 0x72, 0x10, 0x56,
  43085. 0x14, 0xEF, 0xB8, 0xC1, 0xBE, 0x18, 0x11, 0x0B,
  43086. 0xE6, 0x70, 0xF8, 0x39, 0xA5, 0x72, 0x7D, 0xF9,
  43087. 0x47, 0xFB, 0xAC, 0xFD, 0x1F, 0xC3, 0x71, 0x33,
  43088. 0x58, 0x44, 0x15, 0xD3, 0x7C, 0x93, 0x2E, 0x70,
  43089. 0x92, 0xFA, 0xBB, 0xF2, 0xD0, 0x9D, 0x25, 0xC4,
  43090. 0xCF, 0x4A, 0xB8, 0xEC, 0xBE, 0x5D, 0x8B, 0x7F,
  43091. 0xA4, 0x7C, 0xAB, 0xAD, 0xE7, 0x1E, 0x93, 0x83,
  43092. 0x92, 0x86, 0x1E, 0x8D, 0x15, 0xA4, 0x1C, 0x5B,
  43093. 0x42, 0x25, 0xDA, 0x3D, 0x16, 0xD3, 0x93, 0xF2,
  43094. 0x85, 0x50, 0x86, 0x0A, 0x86, 0x35, 0x6B, 0x14,
  43095. 0xAB, 0x5F, 0x22, 0xD0, 0xCF, 0x03, 0x7C, 0xEB,
  43096. 0xB4, 0x0E, 0xAC, 0x87, 0xA2, 0x41, 0x42, 0xA0,
  43097. 0x21, 0x93, 0x00, 0xB6, 0x47, 0x6F, 0x96, 0xD0,
  43098. 0x41, 0xD1, 0xC3, 0x0E, 0x3C, 0x52, 0xD2, 0x45,
  43099. 0xAB, 0x6A, 0xE7, 0xA1, 0xE5, 0xFD, 0x73, 0xC5,
  43100. 0x82, 0x9D, 0x60, 0x62, 0x8B, 0x6D, 0x87, 0xFC,
  43101. 0x88, 0x9C, 0x3E, 0xEF, 0xAE, 0xAA, 0xB6, 0x1C,
  43102. 0x18, 0xEE, 0xD7, 0x51, 0x1A, 0x96, 0xC4, 0x93,
  43103. 0x25, 0x05, 0xD3, 0x83, 0x3D, 0xD8, 0x33, 0x16,
  43104. 0x14, 0x44, 0x88, 0xE2, 0xAF, 0xC4, 0xEC, 0x59,
  43105. 0x18, 0x12, 0xB9, 0x99, 0xC1, 0xC9, 0x5F, 0x31,
  43106. 0x79, 0x00, 0x03, 0xF6, 0xC9, 0x55, 0x14, 0xAA,
  43107. 0x29, 0x08, 0x78, 0x24, 0xAF, 0x1D, 0x99, 0x12,
  43108. 0x36, 0xD9, 0x4A, 0xD9, 0x50, 0xEF, 0x66, 0xFC,
  43109. 0x7F, 0xF4, 0xBC, 0x3B, 0xA0, 0xF6, 0xFD, 0xF2,
  43110. 0x62, 0xCA, 0xA5, 0x9D, 0x2B, 0x55, 0xB8, 0x33,
  43111. 0xBC, 0xA6, 0x7A, 0xA5, 0x1E, 0xE1, 0x14, 0x5F,
  43112. 0x94, 0xE2, 0xDC, 0xF0, 0x5B, 0xBD, 0x43, 0x07,
  43113. 0xD8, 0xB1, 0xE0, 0x81, 0x3F, 0x84, 0x54, 0x90,
  43114. 0xBF, 0x23, 0x59, 0x92, 0x3C, 0xA5, 0x98, 0xAB,
  43115. 0x7D, 0x99, 0xD2, 0xF0, 0xED, 0x8E, 0x0B, 0xC9,
  43116. 0x9F, 0xAF, 0xB0, 0x13, 0xED, 0xC7, 0xDD, 0xB8,
  43117. 0x61, 0x72, 0x07, 0x3D, 0xCC, 0x35, 0x73, 0xA0,
  43118. 0xCF, 0x0C, 0xD9, 0x7E, 0x93, 0xDC, 0x63, 0xB8,
  43119. 0x82, 0xEC, 0xF4, 0x30, 0xCE, 0x43, 0x92, 0xEA,
  43120. 0x5E, 0xD8, 0xC8, 0xA1, 0xEC, 0x79, 0xDC, 0xAE,
  43121. 0x64, 0xD4, 0x33, 0xEB, 0x53, 0x8C, 0xFC, 0x49,
  43122. 0x79, 0xBF, 0x7A, 0x28, 0x65, 0x1E, 0x8C, 0xD5,
  43123. 0x21, 0xB0, 0x8E, 0xCA, 0xAD, 0xF8, 0x96, 0x9A,
  43124. 0x98, 0x10, 0x00, 0x35, 0x6D, 0x58, 0x9A, 0xEF,
  43125. 0x84, 0x84, 0x86, 0x72, 0xBA, 0xCD, 0x38, 0x66,
  43126. 0x96, 0x9B, 0xC2, 0x83, 0xB0, 0x65, 0xC1, 0xAB,
  43127. 0xCF, 0x63, 0x8C, 0x2D, 0xC3, 0x42, 0xB2, 0x7D,
  43128. 0xF6, 0xB8, 0xF0, 0x3D, 0x26, 0x21, 0x8F, 0xAE,
  43129. 0x4E, 0x96, 0xF2, 0x55, 0x66, 0xBC, 0x6F, 0xED,
  43130. 0xE7, 0x19, 0xD3, 0x8D, 0xC0, 0xCD, 0x55, 0x20,
  43131. 0x5F, 0x10, 0xCA, 0xDA, 0x09, 0xED, 0x91, 0x4A,
  43132. 0x43, 0x33, 0xD3, 0x82, 0x11, 0x5C, 0x2F, 0x5D,
  43133. 0xEC, 0xCD, 0x54, 0xF9, 0x6C, 0xE4, 0xE5, 0xF2,
  43134. 0x68, 0xBC, 0xE9, 0x27, 0xB2, 0x1D, 0xCA, 0xB5,
  43135. 0xCD, 0x04, 0x01, 0x1E, 0x92, 0xF5, 0xF6, 0x01,
  43136. 0x86, 0x2B, 0x20, 0x20, 0x9B, 0xB0, 0xF9, 0x56,
  43137. 0xD9, 0x33, 0xD5, 0x0A, 0xEC, 0x1B, 0xF4, 0xCE,
  43138. 0xD2, 0xB2, 0xC2, 0xD4, 0x3F, 0x9A, 0x25, 0x76,
  43139. 0x8E, 0x29, 0x87, 0x52, 0x64, 0x86, 0x4A, 0xA5,
  43140. 0x7B, 0x5A, 0x91, 0x72, 0x6E, 0xBE, 0x6D, 0x73,
  43141. 0x0A, 0x8D, 0x89, 0x53, 0x82, 0x33, 0x70, 0x44,
  43142. 0x20, 0xBE, 0xE0, 0xB0, 0x1B, 0x76, 0x30, 0x43,
  43143. 0xA5, 0x5B, 0x8F, 0xAB, 0x7E, 0xB8, 0x61, 0x5F,
  43144. 0x43, 0x70, 0x1B, 0x1A, 0x71, 0x61, 0x56, 0xF9,
  43145. 0x13, 0x31, 0x2A, 0x64, 0x33, 0x14, 0x00, 0x98,
  43146. 0x72, 0xEC, 0x32, 0x88, 0x09, 0xFB, 0x64, 0x46,
  43147. 0x3D, 0x56, 0x02, 0xD9, 0x76, 0xD3, 0xAA, 0x90,
  43148. 0x0F, 0xBD, 0xF0, 0xF9, 0x96, 0x43, 0x7B, 0x62,
  43149. 0x19, 0x26, 0x22, 0x6A, 0x93, 0x91, 0xEC, 0x07,
  43150. 0x34, 0xF5, 0x22, 0x32, 0xB3, 0x65, 0x66, 0xE0,
  43151. 0x6B, 0x11, 0x7F, 0x97, 0x9F, 0x1A, 0x89, 0x46,
  43152. 0xCE, 0x8F, 0xBD, 0xFD, 0x2F, 0xCC, 0x3D, 0xBF,
  43153. 0xF2, 0x83, 0xA4, 0x30, 0xE1, 0x02, 0x72, 0xF8,
  43154. 0x74, 0xE6, 0x21, 0x96, 0x77, 0xE1, 0x57, 0x8A,
  43155. 0xF7, 0x9E, 0xB3, 0x31, 0xAF, 0xD8, 0xC5, 0xD7,
  43156. 0x20, 0xDC, 0xFD, 0xCF, 0x79, 0x06, 0x0F, 0x1F,
  43157. 0xE5, 0x84, 0x3D, 0x0B, 0x9C, 0xB3, 0xC7, 0xAB,
  43158. 0xB8, 0xF1, 0xC0, 0xD0, 0xB5, 0xC7, 0x01, 0xE2,
  43159. 0x0E, 0x3B, 0xAF, 0x7E, 0xAC, 0x44, 0x5A, 0x75,
  43160. 0x50, 0x0A, 0x76, 0x1C, 0x13, 0xDB, 0x25, 0xD4,
  43161. 0x0D, 0x19, 0x75, 0x4C, 0x02, 0xD9, 0xF3, 0xDF,
  43162. 0x6D, 0xBB, 0xCF, 0x47, 0xA6, 0xAE, 0xF6, 0xD1,
  43163. 0xFB, 0xF4, 0xB4, 0x55, 0xD3, 0xA5, 0x87, 0xA1,
  43164. 0x55, 0xFB, 0xBF, 0xCD, 0xF6, 0xA1, 0x64, 0x57,
  43165. 0x12, 0x75, 0x9A, 0x11, 0xA3, 0xCE, 0x42, 0x70,
  43166. 0x84, 0x54, 0x93, 0x12, 0xE1, 0x3A, 0x0F, 0xFA,
  43167. 0xCA, 0xF2, 0x25, 0x91, 0xF1, 0x4D, 0x8F, 0x84,
  43168. 0xB1, 0xB5, 0x35, 0xAC, 0xE9, 0x81, 0x77, 0x34,
  43169. 0x4D, 0x6F, 0x5D, 0x14, 0x9D, 0xB9, 0xE1, 0xF0,
  43170. 0x3F, 0x3C, 0xE7, 0xAD, 0x48, 0xE6, 0x8C, 0x51,
  43171. 0x86, 0xF4, 0x4A, 0xB4, 0xD0, 0x98, 0xEC, 0x3A,
  43172. 0x4E, 0xAB, 0x58, 0x2F, 0x08, 0x9E, 0x5A, 0x9D,
  43173. 0x45, 0x30, 0xB0, 0x85, 0xDF, 0x4A, 0xE7, 0x92,
  43174. 0xC6, 0xC8, 0x18, 0x93, 0x08, 0xCE, 0x9A, 0x8C,
  43175. 0xE2, 0x91, 0x8D, 0x91, 0x57, 0x7B, 0x37, 0xC8,
  43176. 0x80, 0xA2, 0x31, 0x10, 0x0D, 0x4E, 0xEF, 0x51,
  43177. 0x07, 0x94, 0x8E, 0xF8, 0x3C, 0x3C, 0x2E, 0xD5,
  43178. 0x03, 0x26, 0xB8, 0x72, 0x7F, 0xB9, 0xBC, 0xD7,
  43179. 0x95, 0xC4, 0x31, 0x08, 0xEC, 0x6F, 0xEE, 0x11,
  43180. 0xAF, 0xC0, 0xA2, 0xEC, 0xD7, 0xC8, 0x0B, 0xBE,
  43181. 0x15, 0xAE, 0xC9, 0x17, 0xBE, 0x37, 0xE2, 0x40,
  43182. 0x83, 0x65, 0xDE, 0xB3, 0x4E, 0xB4, 0x15, 0xB3,
  43183. 0x5C, 0x14, 0xF6, 0x5F, 0xA9, 0x1F, 0x70, 0xB5,
  43184. 0x23, 0x93, 0x78, 0xB9, 0x47, 0xF9, 0x1D, 0x2B,
  43185. 0x1E, 0x8D, 0xB1, 0x25, 0x7E, 0xE5, 0x85, 0x3C,
  43186. 0x16, 0x9F, 0xD0, 0xC2, 0x67, 0x8B, 0x0D, 0xD2,
  43187. 0x72, 0x4E, 0x74, 0x30, 0xE1, 0xAF, 0xB8, 0x66,
  43188. 0xCB, 0x53, 0xDF, 0xC4, 0xFB, 0xA5, 0x6D, 0x03,
  43189. 0xF2, 0xAE, 0xEE, 0x90, 0xFE, 0xD7, 0x30, 0xAF,
  43190. 0x33, 0x98, 0x09, 0xEB, 0x75, 0xC7, 0x3E, 0xC8,
  43191. 0x2F, 0xE7, 0x22, 0x5F, 0x2F, 0x0A, 0xBD, 0xA4,
  43192. 0x22, 0x88, 0x28, 0x19, 0x35, 0x83, 0x12, 0x86,
  43193. 0xEE, 0x72, 0xB4, 0x26, 0x89, 0x2F, 0xC7, 0x11,
  43194. 0x6E, 0xDD, 0x14, 0x98, 0x22, 0xE7, 0x73, 0x3E,
  43195. 0xFA, 0x46, 0x75, 0xF9, 0x40, 0xC1, 0x84, 0x22,
  43196. 0xBC, 0x75, 0x36, 0xC7, 0x82, 0xD3, 0xAE, 0x6E,
  43197. 0x0D, 0xBF, 0x6F, 0xC3, 0x4B, 0x67, 0x49, 0x19,
  43198. 0xF3, 0x4B, 0x12, 0xF2, 0x83, 0xFD, 0x39, 0x56,
  43199. 0x44, 0x05, 0x3A, 0x24, 0x6A, 0x35, 0x69, 0x12,
  43200. 0xCF, 0xE4, 0x93, 0xFE, 0x26, 0xCC, 0xD6, 0x01,
  43201. 0xA0, 0x4A, 0x84, 0xA8, 0x1D, 0x85, 0xE6, 0x83,
  43202. 0x0F, 0x3C, 0xE6, 0x6D, 0xD2, 0xCB, 0xB1, 0x14,
  43203. 0x8C, 0xEC, 0x10, 0xB3, 0x63, 0x4B, 0x9C, 0xF5,
  43204. 0x11, 0xE0, 0xF9, 0x86, 0x6F, 0xA7, 0xC0, 0x3B,
  43205. 0x9D, 0x25, 0xD7, 0x54, 0xCA, 0x40, 0x4D, 0x26,
  43206. 0xBA, 0x71, 0x8E, 0x25, 0xF5, 0xA7, 0xE3, 0x9B,
  43207. 0x25, 0x20, 0x7F, 0x29, 0x05, 0xB6, 0x27, 0x14,
  43208. 0x17, 0x67, 0x26, 0x10, 0xAD, 0xA3, 0x06, 0x03,
  43209. 0xFE, 0x82, 0x85, 0x5D, 0x01, 0x04, 0x4D, 0xE0,
  43210. 0x64, 0x38, 0x38, 0x5E, 0x83, 0x1E, 0x21, 0x9A,
  43211. 0x39, 0x02, 0xF8, 0xF9, 0x69, 0x85, 0x52, 0xE5,
  43212. 0xEC, 0x6A, 0xAC, 0x96, 0x86, 0xA7, 0x88, 0x69,
  43213. 0xB5, 0xB5, 0x7E, 0x03, 0x1D, 0xA9, 0x68, 0xCA,
  43214. 0x45, 0x0F, 0xF9, 0x14, 0xD6, 0x7B, 0xCF, 0x9C,
  43215. 0x03, 0x6F, 0xD1, 0xD9, 0x6F, 0x01, 0x3D, 0xF8,
  43216. 0xF3, 0x11, 0xF3, 0x29, 0x17, 0x90, 0xE8, 0x9B,
  43217. 0xED, 0x58, 0x9B, 0xF0, 0xBC, 0xC7, 0xBA, 0xF4,
  43218. 0x60, 0xC8, 0xAA, 0x30, 0xB4, 0x2F, 0x22, 0x8F,
  43219. 0xD3, 0xAC, 0x18, 0xC2, 0xB7, 0xC4, 0x7B, 0x31,
  43220. 0x9E, 0x0F, 0x7E, 0x9D, 0xBF, 0xD4, 0x63, 0xC2,
  43221. 0x8B, 0x1B, 0x58, 0x50, 0x33, 0x53, 0x6D, 0x79,
  43222. 0xBB, 0xF8, 0x0D, 0x91, 0x33, 0xD9, 0x07, 0xE7,
  43223. 0xB0, 0x81, 0xD4, 0xB4, 0x47, 0x61, 0x93, 0xF0,
  43224. 0xFB, 0x68, 0xBC, 0x1B, 0x41, 0xC2, 0xF5, 0x43,
  43225. 0x30, 0x7E, 0x76, 0xF9, 0xB1, 0xA3, 0xD6, 0xD4,
  43226. 0x26, 0xEA, 0x77, 0x75, 0x12, 0x7A, 0xC8, 0x30,
  43227. 0x9B, 0xCF, 0x45, 0xBE, 0x74, 0x7D, 0x8A, 0x8B,
  43228. 0xEC, 0xED, 0x11, 0xE6, 0xA1, 0xD1, 0xB8, 0xF1,
  43229. 0x90, 0xAD, 0x6D, 0x6A, 0xC6, 0x54, 0xE9, 0xDB,
  43230. 0xAD, 0x4C, 0x97, 0x39, 0xC8, 0xD8, 0x44, 0xA9,
  43231. 0x1A, 0x37, 0x16, 0x7E, 0x68, 0x45, 0x0C, 0xBB,
  43232. 0x10, 0xF4, 0xAE, 0x8E, 0x2B, 0x69, 0xFA, 0x95,
  43233. 0x3E, 0xA5, 0xC9, 0x91, 0xD3, 0xF1, 0xA3, 0x89,
  43234. 0x3F, 0x90, 0x86, 0x93, 0x1B, 0xF1, 0xA0, 0x89,
  43235. 0xC7, 0xF2, 0x23, 0x57, 0xD4, 0x8E, 0x2F, 0xD5,
  43236. 0x71, 0xCD, 0x36, 0xF1, 0x90, 0xB3, 0x98, 0x3E,
  43237. 0x19, 0xEA, 0xC8, 0x0F, 0x12, 0x9D, 0xBF, 0x58,
  43238. 0xED, 0xDC, 0x6B, 0x9A, 0x79, 0x84, 0xFC, 0xF0,
  43239. 0x4C, 0xC3, 0xB4, 0x0D, 0xB8, 0x7A, 0x8D, 0xAD,
  43240. 0x75, 0x40, 0xD5, 0xD5, 0xDE, 0xC8, 0xCA, 0x39,
  43241. 0x3E, 0x45, 0xE4, 0xBC, 0xF4, 0x33, 0xEA, 0x64,
  43242. 0xE1, 0x5E, 0x94, 0x42, 0x91, 0xAB, 0xBC, 0x42,
  43243. 0x2A, 0xB3, 0xD0, 0x60, 0x23, 0xCE, 0x57, 0x8E,
  43244. 0xFF, 0xAD, 0xA2, 0x2B, 0x64, 0xD9, 0x94, 0xA0,
  43245. 0x80, 0x0F, 0x8E, 0x50, 0x17, 0x08, 0x1D, 0x16,
  43246. 0xCF, 0x51, 0xD0, 0xB9, 0x28, 0xB6, 0x59, 0xEF,
  43247. 0x78, 0xCC, 0xC9, 0x96, 0xF9, 0xCA, 0x87, 0x7A,
  43248. 0xEE, 0xD9, 0x15, 0x5E, 0xDF, 0x5D, 0xBC, 0xC2,
  43249. 0x58, 0xE6, 0x04, 0xEE, 0x17, 0xDC, 0xB3, 0xF9,
  43250. 0x90, 0xF9, 0x88, 0x32, 0x9E, 0xA1, 0xDB, 0x1C,
  43251. 0x38, 0x56, 0x53, 0x90, 0x30, 0x69, 0x2E, 0x52,
  43252. 0x00, 0x2C, 0xF3, 0x0F, 0xD5, 0x80, 0x2E, 0x02,
  43253. 0x5B, 0x99, 0xBF, 0xCD, 0x11, 0x12, 0x64, 0x5B,
  43254. 0x56, 0xC6, 0x0A, 0xE6, 0x38, 0xE7, 0x4D, 0x21,
  43255. 0xE5, 0x98, 0x78, 0x9D, 0xE6, 0xCB, 0x60, 0xB4,
  43256. 0x2E, 0xE4, 0x98, 0x56, 0xCB, 0xAD, 0xE6, 0xDD,
  43257. 0x53, 0xF4, 0xC5, 0x67, 0xA2, 0x9F, 0xA0, 0x5C,
  43258. 0x7C, 0xFB, 0x24, 0x5A, 0xA7, 0x72, 0xD0, 0xE7,
  43259. 0x63, 0xF2, 0x5D, 0xBF, 0xD8, 0xE9, 0xF1, 0x6B,
  43260. 0xB4, 0x29, 0xA6, 0x28, 0xE6, 0x93, 0xD3, 0x87,
  43261. 0xB6, 0xD9, 0x3C, 0x39, 0x8D, 0xEA, 0x28, 0xC0,
  43262. 0x96, 0x3D, 0xF5, 0xC2, 0x3C, 0x29, 0xF2, 0x80,
  43263. 0x21, 0x8A, 0x03, 0x9D, 0x64, 0xF8, 0xBA, 0x81,
  43264. 0xC1, 0xDD, 0xA2, 0x88, 0x2A, 0x84, 0x2E, 0x3C,
  43265. 0xB5, 0x03, 0x95, 0xED, 0xAA, 0x6E, 0xE2, 0x6F,
  43266. 0x5E, 0x99, 0x3C, 0x63, 0xEE, 0xB8, 0x4F, 0x66,
  43267. 0x32, 0x77, 0x42, 0x23, 0x36, 0x29, 0x89, 0xB0,
  43268. 0xED, 0x5F, 0xF2, 0x5A, 0x65, 0x66, 0x3F, 0xD2,
  43269. 0x8B, 0x48, 0x68, 0x65, 0xDC, 0xE0, 0xB0, 0xC2,
  43270. 0x72, 0x73, 0xF1, 0xA4, 0xC6, 0x56, 0x2C, 0x5D,
  43271. 0xD8, 0xC6, 0x5C, 0x41, 0xCE, 0x30, 0x89, 0x59,
  43272. 0xA9, 0xD6, 0x45, 0x96, 0xD0, 0x8E, 0x7B, 0x25,
  43273. 0xE0, 0x13, 0xFB, 0xFE, 0x7C, 0xEA, 0xF3, 0x67,
  43274. 0x0D, 0xB2, 0x9A, 0x21, 0x3C, 0xCE, 0x99, 0x75,
  43275. 0xA9, 0x13, 0xCE, 0xF4, 0x23, 0x6E, 0x64, 0x00,
  43276. 0x30, 0x87, 0x70, 0x9C, 0xAD, 0x61, 0x81, 0x71,
  43277. 0x0E, 0x95, 0x19, 0x26, 0xCA, 0x55, 0x29, 0x71,
  43278. 0x99, 0xA6, 0x08, 0xAE, 0x54, 0x58, 0x75, 0xCD,
  43279. 0xC3, 0x8F, 0xE3, 0x83, 0xC1, 0x45, 0x62, 0xB4,
  43280. 0x8D, 0xCA, 0x66, 0x02, 0xEA, 0x34, 0x05, 0x5D,
  43281. 0x98, 0x3F, 0x38, 0xE6, 0x1C, 0xCE, 0x53, 0x1A,
  43282. 0xD9, 0x3F, 0x58, 0xEC, 0x16, 0x28, 0x45, 0xF5,
  43283. 0x38, 0xCE, 0x48, 0x43, 0x87, 0x1D, 0x3C, 0x4A,
  43284. 0xDF, 0x05, 0xF3, 0x5E, 0x29, 0x7E, 0xA6, 0x2E,
  43285. 0xFC, 0xDD, 0x5E, 0xF9, 0x40, 0x1B, 0xA0, 0x42,
  43286. 0xA2, 0x35, 0x15, 0x0A, 0x09, 0xD9, 0x47, 0x4A,
  43287. 0x3F, 0xB0, 0x3A, 0xAA, 0x19, 0xE7, 0xE3, 0x7A,
  43288. 0x22, 0x8D, 0x5F, 0x5B, 0x07, 0x41, 0x4C, 0x3D,
  43289. 0xA2, 0xAD, 0x2E, 0x5C, 0x75, 0xEC, 0xF0, 0x4C,
  43290. 0x11, 0x2B, 0x90, 0x76, 0x9E, 0x19, 0x96, 0x0E,
  43291. 0x97, 0x5E, 0x8D, 0x19, 0x17, 0xB3, 0xBF, 0xDA,
  43292. 0x84, 0xFD, 0xC6, 0xD2, 0x32, 0x6F, 0xB8, 0xA3,
  43293. 0xB0, 0x0F, 0x95, 0xD9, 0xC5, 0x26, 0x50, 0x11,
  43294. 0x15, 0x72, 0xBE, 0xC2, 0x1B, 0x12, 0x12, 0x7C,
  43295. 0xA5, 0x70, 0xD8, 0xA9, 0x8A, 0xB9, 0x77, 0xEB,
  43296. 0xD8, 0xD7, 0x9A, 0x59, 0x37, 0x5E, 0xE1, 0x4F,
  43297. 0x64, 0xB5, 0xB0, 0x4F, 0xD9, 0x69, 0xFE, 0xB0,
  43298. 0x3D, 0x0A, 0xF7, 0x34, 0x89, 0xE3, 0xBA, 0xEF,
  43299. 0xE7, 0xC7, 0xBC, 0x8D, 0xC7, 0xE8, 0x54, 0x83,
  43300. 0xEE, 0x62, 0xF0, 0x23, 0x98, 0x58, 0x0F, 0x83,
  43301. 0xB9, 0x6D, 0xD8, 0x44, 0x77, 0xB9, 0xC4, 0x8F,
  43302. 0x0B, 0xB3, 0x9F, 0x54, 0x06, 0xA3, 0x70, 0x36,
  43303. 0xD6, 0xF3, 0x6E, 0x2B, 0x1B, 0x6B, 0x53, 0xFE,
  43304. 0x6F, 0xF6, 0x1C, 0x32, 0x7B, 0x29, 0xD4, 0xE0,
  43305. 0x5D, 0xD2, 0xB8, 0x11, 0x74, 0xC6, 0x0B, 0x59,
  43306. 0xC7, 0x9C, 0xB1, 0x97, 0x6B, 0xC0, 0x6E, 0x7A,
  43307. 0xC3, 0x4D, 0xF3, 0xE3, 0x8F, 0x7D, 0x2C, 0x1C,
  43308. 0x0E, 0x31, 0x51, 0xB7, 0x14, 0x7A, 0xB8, 0x31,
  43309. 0x77, 0x47, 0x70, 0x14, 0x3B, 0x92, 0x7B, 0x5F,
  43310. 0xEC, 0x5D, 0xF7, 0x76, 0xC1, 0xD7, 0x2D, 0xB6,
  43311. 0xBC, 0x99, 0x81, 0xD6, 0x58, 0x67, 0x71, 0x3C,
  43312. 0xF2, 0x97, 0xC8, 0xB0, 0xF1, 0xE9, 0x8D, 0x0E,
  43313. 0x16, 0xF0, 0xCC, 0x22, 0x7A, 0x39, 0xE4, 0x7E,
  43314. 0x50, 0xBA, 0x01, 0x16, 0x15, 0x6D, 0x5B, 0x54,
  43315. 0x67, 0x53, 0x66, 0x04, 0xBE, 0x05, 0xCC, 0x2E,
  43316. 0xF4, 0x0A, 0xBC, 0xE8, 0x52, 0xF1, 0x5D, 0xFA,
  43317. 0x2C, 0xAC, 0xF8, 0x6A, 0x78, 0x9E, 0x5B, 0x7B,
  43318. 0x0E, 0x5B, 0xB4, 0xB7, 0x77, 0xCD, 0x7C, 0xC9,
  43319. 0xF6, 0x54, 0x77, 0x9B, 0x10, 0x2F, 0x78, 0xB5,
  43320. 0xAA, 0x4B, 0x94, 0xC3, 0xB4, 0xFD, 0xE5, 0x5F,
  43321. 0xA7, 0xF7, 0xBF, 0x54, 0xAC, 0x22, 0x5E, 0x1F,
  43322. 0x26, 0x16, 0x5B, 0x65, 0xF1, 0x6D, 0x03, 0x21,
  43323. 0x66, 0x9F, 0xD9, 0xF6, 0xE4, 0x7F, 0xCA, 0x1D,
  43324. 0xD3, 0x47, 0x09, 0x6D, 0xF5, 0xDD, 0xA8, 0x64,
  43325. 0x66, 0xA5, 0x7C, 0x5B, 0x06, 0x8D, 0x9C, 0x67,
  43326. 0xB7, 0x32, 0x03, 0x66, 0xEA, 0x19, 0xC8, 0x99,
  43327. 0x3F, 0xF9, 0x0B, 0xD8, 0xFB, 0x06, 0x93, 0xFB,
  43328. 0xA3, 0x70, 0xE6, 0x6D, 0x2B, 0x20, 0x3B, 0x99,
  43329. 0x70, 0x11, 0xB0, 0xD1, 0x5B, 0x94, 0xE2, 0x8B,
  43330. 0xAA, 0x2E, 0xBF, 0x01, 0x77, 0x4F, 0x7A, 0xE7,
  43331. 0x8F, 0x84, 0xED, 0xBD, 0xAD, 0x9F, 0x65, 0xA4,
  43332. 0x50, 0x42, 0x7A, 0x47, 0x74, 0xC6, 0x0C, 0xC8,
  43333. 0x9A, 0x02, 0x0B, 0x37, 0xDA, 0x21, 0xC7, 0x91,
  43334. 0xDA, 0xC8, 0xF7, 0xA7, 0x45, 0x7E, 0x30, 0xD0,
  43335. 0x8B, 0x01, 0x37, 0x51, 0x60, 0x03, 0x9C, 0x30,
  43336. 0x1B, 0x60, 0x51, 0xA9, 0x65, 0xE8, 0xA7, 0xCC,
  43337. 0xA2, 0xAE, 0xF9, 0x3B, 0xD5, 0x2F, 0x82, 0xC0,
  43338. 0x20, 0xBE, 0xCE, 0x90, 0xA1, 0x29, 0x02, 0x4E,
  43339. 0xFE, 0xA4, 0xB2, 0xFA, 0x21, 0x27, 0x0F, 0x8E,
  43340. 0xB5, 0xED, 0x6A, 0xAA, 0xE5, 0x59, 0x29, 0xAA,
  43341. 0xC5, 0x99, 0xA5, 0x77, 0x97, 0x29, 0x57, 0x66,
  43342. 0x0C, 0xC4, 0x7A, 0xC4, 0xE3, 0xCE, 0x77, 0x2B,
  43343. 0xBF, 0x10, 0x05, 0x2D, 0xE7, 0xED, 0xB1, 0xB8,
  43344. 0xA4, 0x49, 0x41, 0xF8, 0x84, 0xC9, 0xF8, 0xBE,
  43345. 0x13, 0x17, 0x46, 0x69, 0x94, 0x56, 0x29, 0xF4,
  43346. 0x6D, 0xE2, 0x46, 0x74, 0x44, 0xF3, 0x10, 0x6A,
  43347. 0x73, 0xFA, 0x27, 0x9C, 0xF0, 0x2A, 0x80, 0x0A,
  43348. 0x04, 0x7E, 0x20, 0xBD, 0x4D, 0x82, 0x0B, 0x38,
  43349. 0x9C, 0x3B, 0xB6, 0xA8, 0x68, 0xA5, 0x38, 0x4C,
  43350. 0xF5, 0x72, 0x4C, 0x20, 0x4C, 0xEF, 0xB1, 0xA6,
  43351. 0xA1, 0xBE, 0xB9, 0x72, 0x3E, 0x36, 0xDD, 0xDD,
  43352. 0xD9, 0xC7, 0x07, 0xC8, 0xF6, 0x3E, 0x8B, 0xC2,
  43353. 0x66, 0x83, 0xCC, 0x8B, 0x43, 0xC7, 0xDF, 0xDA,
  43354. 0xA4, 0x08, 0xAC, 0x4D, 0xD2, 0xBA, 0x9A, 0xEC,
  43355. 0xBC, 0x3B, 0x6D, 0xDA, 0xED, 0xCE, 0x09, 0x4A,
  43356. 0xAB, 0x58, 0xFF, 0x73, 0x2B, 0x19, 0x66, 0x38,
  43357. 0xD8, 0xB8, 0xEF, 0xC4, 0x28, 0xBB, 0xA9, 0x61,
  43358. 0x57, 0x93, 0xC4, 0xDD, 0x9F, 0x00, 0xF9, 0x0D,
  43359. 0x62, 0xC6, 0x76, 0xD1, 0x27, 0xA0, 0xE1, 0x8C,
  43360. 0x14, 0xC6, 0xEE, 0x9C, 0x99, 0x05, 0x10, 0xB0,
  43361. 0x54, 0xAD, 0xB4, 0xB4, 0x17, 0x0A, 0xC7, 0x12,
  43362. 0x7F, 0x93, 0x17, 0x5C, 0x1E, 0xB2, 0x25, 0x12
  43363. };
  43364. static const byte msg_87[] = {
  43365. 0x14, 0x42, 0x63, 0x34, 0x94, 0x09, 0x60, 0x77,
  43366. 0x3B, 0xFF, 0x65, 0xF0, 0x8D, 0x1D, 0xE4, 0x89,
  43367. 0xC4, 0xC3, 0xED, 0x36
  43368. };
  43369. static const byte sig_87[] = {
  43370. 0x13, 0xE8, 0x99, 0xEE, 0xDC, 0xCC, 0x0F, 0xBA,
  43371. 0x62, 0x91, 0x44, 0xE4, 0xAC, 0x06, 0x79, 0x06,
  43372. 0xB5, 0x32, 0x6B, 0x8F, 0x9A, 0x6C, 0xCB, 0xAB,
  43373. 0xE1, 0x44, 0x4A, 0xDD, 0x46, 0x45, 0x16, 0x0D,
  43374. 0x22, 0x57, 0x82, 0x87, 0x10, 0xD1, 0xEE, 0x10,
  43375. 0x60, 0x21, 0xB5, 0x64, 0x1E, 0x78, 0x81, 0x55,
  43376. 0x75, 0xD4, 0xF0, 0x95, 0xD0, 0x15, 0xD8, 0x46,
  43377. 0x5C, 0x92, 0xD2, 0xDD, 0xF4, 0xAB, 0xDF, 0xBE,
  43378. 0xB1, 0x1E, 0xE5, 0xE0, 0x70, 0xE6, 0xDA, 0x52,
  43379. 0xE5, 0x48, 0xDC, 0x04, 0xFD, 0xEF, 0x54, 0x72,
  43380. 0xE7, 0xE5, 0xF1, 0x82, 0x10, 0xAA, 0xCB, 0xA0,
  43381. 0x4F, 0x4F, 0x18, 0xAE, 0x66, 0x86, 0xB9, 0xAF,
  43382. 0x96, 0x57, 0xE3, 0x8E, 0x3B, 0x9B, 0xDD, 0xB4,
  43383. 0xAA, 0x84, 0xE6, 0x7B, 0x4D, 0x81, 0x92, 0xD0,
  43384. 0x03, 0x87, 0x3D, 0xD3, 0xEE, 0xE7, 0x47, 0x00,
  43385. 0xFB, 0xD8, 0x1E, 0x38, 0x1C, 0x21, 0x98, 0xB7,
  43386. 0xCC, 0xC1, 0x37, 0xC1, 0x71, 0xB2, 0x2F, 0x93,
  43387. 0x53, 0x41, 0x9C, 0x48, 0xC1, 0x4B, 0x8D, 0x63,
  43388. 0x0F, 0x99, 0x63, 0x40, 0x27, 0x5F, 0x6E, 0x60,
  43389. 0x4B, 0x95, 0xC4, 0x35, 0x20, 0x8A, 0xED, 0x2B,
  43390. 0xCA, 0x1B, 0x41, 0x9F, 0x83, 0x63, 0xF0, 0x95,
  43391. 0x0E, 0x24, 0x0D, 0x6F, 0x9E, 0xAB, 0x11, 0x8E,
  43392. 0x4B, 0xD3, 0xDA, 0x0E, 0xC3, 0xA2, 0xBE, 0x26,
  43393. 0xA8, 0xA0, 0x98, 0x57, 0x71, 0x3C, 0x36, 0xDD,
  43394. 0x69, 0xC3, 0x4E, 0xDD, 0x2C, 0x61, 0x9E, 0x88,
  43395. 0x26, 0x70, 0x71, 0xCF, 0x9E, 0xE5, 0xA6, 0x0C,
  43396. 0xA3, 0x14, 0x2D, 0xF1, 0x63, 0xF0, 0x1D, 0x8D,
  43397. 0x79, 0x6A, 0xC8, 0x50, 0xCF, 0xF3, 0x66, 0x60,
  43398. 0x78, 0xB3, 0x18, 0xFB, 0x5B, 0xD1, 0x73, 0x60,
  43399. 0xC8, 0x76, 0xC9, 0xC9, 0x0D, 0x8A, 0x7F, 0x41,
  43400. 0x2C, 0x8A, 0x31, 0x61, 0x6B, 0xE7, 0xA3, 0x74,
  43401. 0x58, 0x71, 0x54, 0x84, 0x86, 0x71, 0x5C, 0x94,
  43402. 0x26, 0x3A, 0x17, 0xB3, 0x6C, 0xA4, 0x99, 0x25,
  43403. 0x45, 0x0C, 0x57, 0x8A, 0xD9, 0xD4, 0xB1, 0xC2,
  43404. 0x00, 0x43, 0xF4, 0x5E, 0x84, 0x31, 0x99, 0x4F,
  43405. 0xA6, 0xD2, 0x6A, 0x14, 0x1B, 0xAD, 0x9E, 0x49,
  43406. 0x6E, 0x00, 0x9E, 0x91, 0x46, 0x16, 0xCA, 0x57,
  43407. 0x0C, 0x09, 0xF6, 0x38, 0xD0, 0x62, 0xBE, 0xC6,
  43408. 0x87, 0x33, 0x3A, 0xC7, 0x28, 0x38, 0x34, 0x53,
  43409. 0x7E, 0xFB, 0x60, 0x42, 0xF3, 0x7D, 0x83, 0xF7,
  43410. 0x29, 0x5D, 0xEA, 0x30, 0xD5, 0x00, 0x90, 0xB6,
  43411. 0x38, 0x4C, 0x17, 0x29, 0xEF, 0x17, 0xA0, 0xD5,
  43412. 0x87, 0x50, 0xC0, 0x03, 0x75, 0x14, 0xE5, 0xE1,
  43413. 0x22, 0x78, 0x53, 0xBC, 0x5A, 0xA3, 0x1E, 0x95,
  43414. 0xBE, 0xEC, 0x37, 0xB1, 0x51, 0x82, 0x69, 0x26,
  43415. 0x2E, 0xA3, 0x5A, 0xDA, 0x4F, 0xDA, 0x77, 0x62,
  43416. 0x7E, 0xED, 0xDA, 0xAF, 0x57, 0x97, 0x1B, 0xA3,
  43417. 0x6D, 0x46, 0x7B, 0x19, 0xA9, 0x0B, 0x99, 0x1C,
  43418. 0xD2, 0x55, 0xDB, 0x79, 0xB0, 0x15, 0x48, 0x86,
  43419. 0x52, 0x30, 0x31, 0xD6, 0xC5, 0xB1, 0xAE, 0x8F,
  43420. 0xCF, 0x9A, 0x43, 0x10, 0xBB, 0xC8, 0x19, 0x74,
  43421. 0x84, 0xB2, 0x92, 0x3B, 0xFE, 0x0B, 0x12, 0x15,
  43422. 0xA1, 0xC4, 0xD8, 0xC6, 0x83, 0x90, 0x89, 0x8A,
  43423. 0xD5, 0x3E, 0x33, 0x69, 0xB7, 0x05, 0x3F, 0xB1,
  43424. 0x8B, 0x0D, 0x87, 0x40, 0x70, 0x90, 0x2A, 0x5D,
  43425. 0x3B, 0x3D, 0x91, 0xD8, 0x1D, 0x4D, 0xF1, 0x08,
  43426. 0x7E, 0xF7, 0xDC, 0x05, 0x84, 0xEB, 0xDC, 0x63,
  43427. 0xD7, 0xBA, 0x3C, 0x0D, 0x31, 0xF8, 0x6D, 0xA6,
  43428. 0xC0, 0xFD, 0x08, 0x11, 0x5C, 0x53, 0xF6, 0xAE,
  43429. 0xFE, 0xC0, 0x82, 0x9A, 0x68, 0xD2, 0xA3, 0x44,
  43430. 0x2E, 0xEE, 0x47, 0x36, 0x70, 0x2D, 0x66, 0x81,
  43431. 0x0D, 0x62, 0x30, 0x8A, 0x8C, 0xC8, 0x2A, 0xA6,
  43432. 0x21, 0x82, 0xF5, 0x98, 0xF4, 0x4E, 0x25, 0x37,
  43433. 0x11, 0xB5, 0xD6, 0x07, 0x88, 0xBD, 0x0D, 0x69,
  43434. 0x0E, 0xF9, 0x8F, 0x9A, 0xD5, 0x93, 0xE0, 0x3C,
  43435. 0xEF, 0x38, 0xB9, 0xC9, 0x77, 0x98, 0x3F, 0x69,
  43436. 0x11, 0xBA, 0x1A, 0xB9, 0xF7, 0x35, 0xE9, 0x28,
  43437. 0xCD, 0xA3, 0x8C, 0x03, 0xE6, 0xAD, 0x83, 0x62,
  43438. 0xF4, 0x60, 0xAE, 0x4C, 0xD0, 0xF4, 0x6E, 0x00,
  43439. 0xEE, 0xEC, 0x74, 0xB6, 0x12, 0x34, 0x98, 0xAB,
  43440. 0x31, 0xE7, 0xA7, 0x9D, 0x33, 0x4D, 0x72, 0xA7,
  43441. 0xA7, 0xEE, 0xF3, 0xB5, 0x51, 0xE7, 0x8D, 0x31,
  43442. 0xBC, 0x2C, 0xAF, 0xFB, 0x13, 0x9C, 0xAC, 0xA4,
  43443. 0xD7, 0x9C, 0x8B, 0xBD, 0x52, 0xBD, 0x78, 0xF4,
  43444. 0x90, 0x65, 0x09, 0xBE, 0x42, 0xE7, 0x76, 0x3A,
  43445. 0xE6, 0xAC, 0xB8, 0x98, 0x28, 0x5E, 0xC9, 0x32,
  43446. 0x3E, 0x68, 0x67, 0x6A, 0x8C, 0xC7, 0x4A, 0x58,
  43447. 0xC8, 0xDA, 0x8B, 0xE9, 0x11, 0xED, 0x6F, 0x51,
  43448. 0x3B, 0x66, 0x08, 0x70, 0x73, 0x10, 0xFB, 0x45,
  43449. 0xCB, 0xD9, 0x7D, 0x5F, 0xF0, 0xD2, 0xAB, 0xA3,
  43450. 0x6F, 0xCE, 0xF7, 0x3D, 0x46, 0xCB, 0x7F, 0x01,
  43451. 0xC2, 0xCF, 0xE3, 0x8E, 0x68, 0xE8, 0x4F, 0x4A,
  43452. 0x30, 0x19, 0x16, 0xD2, 0xF5, 0x10, 0xD8, 0x2B,
  43453. 0x49, 0x69, 0xBE, 0x7A, 0x0E, 0x9C, 0xC6, 0x0E,
  43454. 0xFF, 0x5C, 0x0A, 0x87, 0x17, 0xB8, 0x22, 0x83,
  43455. 0x8C, 0x77, 0xAF, 0x42, 0x06, 0xB1, 0x25, 0x45,
  43456. 0x08, 0x9B, 0xB2, 0xDD, 0x6A, 0x3F, 0xF0, 0x12,
  43457. 0xC8, 0x64, 0x15, 0xBB, 0xA0, 0x4F, 0xD7, 0xD4,
  43458. 0xEC, 0x70, 0x7A, 0xF3, 0xB1, 0x7F, 0x25, 0x57,
  43459. 0x47, 0x66, 0xF1, 0xE9, 0x27, 0x38, 0xE0, 0x62,
  43460. 0x10, 0xF4, 0x8A, 0x5E, 0xF2, 0x55, 0x0E, 0xBD,
  43461. 0xF8, 0x5A, 0x5C, 0xA3, 0x44, 0x97, 0xCF, 0x1D,
  43462. 0x4D, 0x3A, 0x75, 0x86, 0x48, 0xEC, 0x41, 0x17,
  43463. 0x24, 0x43, 0x83, 0x5E, 0x50, 0x91, 0xBE, 0x8F,
  43464. 0x04, 0x78, 0x23, 0xD9, 0x62, 0x0C, 0x2A, 0xD5,
  43465. 0x1C, 0x96, 0x11, 0xAA, 0xEE, 0x39, 0xB2, 0x1E,
  43466. 0x6D, 0x6A, 0xEC, 0x87, 0x0C, 0x89, 0x15, 0xE2,
  43467. 0x66, 0x47, 0x6A, 0x50, 0xEE, 0xCA, 0x59, 0x96,
  43468. 0x22, 0xF7, 0x09, 0x1A, 0x34, 0xC2, 0x3F, 0x14,
  43469. 0xB4, 0x04, 0x29, 0xD9, 0x5E, 0x3E, 0xF9, 0x8F,
  43470. 0xED, 0x3E, 0x74, 0x94, 0x37, 0xF0, 0x4B, 0xB4,
  43471. 0xA3, 0x37, 0x52, 0x2E, 0x68, 0x09, 0xFC, 0x10,
  43472. 0x45, 0x03, 0xE2, 0x53, 0xB4, 0x1C, 0x4F, 0x03,
  43473. 0x01, 0xAF, 0x46, 0x7F, 0x74, 0xD3, 0x31, 0x25,
  43474. 0xFA, 0x83, 0xEF, 0x71, 0x24, 0x45, 0xA1, 0x71,
  43475. 0xFA, 0x40, 0xEB, 0xF4, 0xE6, 0x55, 0x3E, 0x45,
  43476. 0x4A, 0xFE, 0x25, 0x68, 0x02, 0x1D, 0x2B, 0x2A,
  43477. 0x19, 0x8D, 0xEC, 0x9B, 0xF7, 0x20, 0xF9, 0xD7,
  43478. 0x2F, 0x81, 0x52, 0x0B, 0xE8, 0x74, 0x66, 0xAF,
  43479. 0x70, 0xD0, 0x0E, 0x0E, 0x86, 0x0F, 0xF9, 0xAB,
  43480. 0xD0, 0x39, 0x78, 0xC3, 0xE4, 0x29, 0xB5, 0xAA,
  43481. 0x17, 0xB9, 0x7F, 0x9A, 0xE9, 0x34, 0x48, 0x85,
  43482. 0x3D, 0x6E, 0xFD, 0x16, 0x8A, 0x30, 0xC6, 0xCB,
  43483. 0xE8, 0xDE, 0x2D, 0x28, 0x8D, 0x9A, 0x24, 0xEA,
  43484. 0x5D, 0x2A, 0x58, 0x23, 0x33, 0x2B, 0x84, 0xFD,
  43485. 0x2C, 0xE7, 0x93, 0xA2, 0x2B, 0xEC, 0x43, 0x98,
  43486. 0x48, 0xD4, 0xE6, 0x0F, 0x3B, 0xB9, 0xC7, 0x5D,
  43487. 0x7E, 0xB0, 0x87, 0x1E, 0x80, 0x3D, 0x61, 0xB0,
  43488. 0x7E, 0x74, 0x9E, 0xD7, 0x60, 0x72, 0xB2, 0x7C,
  43489. 0x87, 0xB6, 0x9D, 0x6C, 0x01, 0x42, 0x61, 0xF6,
  43490. 0x47, 0xAF, 0xA8, 0x8C, 0x4F, 0x1E, 0xC5, 0x5A,
  43491. 0x75, 0xA5, 0x0F, 0xB4, 0xC7, 0x9D, 0x2C, 0x94,
  43492. 0xC0, 0x50, 0x3D, 0xB2, 0x0D, 0xFD, 0xF7, 0x1F,
  43493. 0x62, 0x88, 0x74, 0x18, 0x8C, 0xDD, 0x73, 0x85,
  43494. 0xC0, 0x33, 0x81, 0xDA, 0xBB, 0x85, 0x4D, 0x4A,
  43495. 0xA9, 0xF4, 0x7B, 0x66, 0x43, 0x8C, 0x43, 0xFF,
  43496. 0x53, 0xEF, 0x5E, 0x78, 0xAB, 0x45, 0x0B, 0x45,
  43497. 0x01, 0x91, 0x27, 0x8A, 0xF6, 0xE2, 0x6A, 0x7B,
  43498. 0x5E, 0x64, 0x61, 0xF5, 0x77, 0xF9, 0x85, 0x2F,
  43499. 0x81, 0xC9, 0x02, 0x03, 0xC7, 0x13, 0xF5, 0xB1,
  43500. 0xF6, 0xC3, 0xEF, 0x55, 0x8C, 0x90, 0x32, 0x51,
  43501. 0x6D, 0x8D, 0x62, 0xFD, 0x5E, 0x24, 0xE4, 0xF0,
  43502. 0xF5, 0x07, 0x18, 0xF5, 0x6B, 0x5A, 0x59, 0xA0,
  43503. 0x09, 0xD5, 0x93, 0x8D, 0xAD, 0x55, 0x91, 0xF6,
  43504. 0x1F, 0x4C, 0x65, 0x9A, 0x76, 0x05, 0x26, 0xEF,
  43505. 0x41, 0x20, 0x2F, 0xA7, 0xE5, 0xF6, 0xC7, 0xD5,
  43506. 0xE0, 0xB0, 0xC0, 0xC4, 0x3B, 0x52, 0x4B, 0x66,
  43507. 0x71, 0x2C, 0x5A, 0x7C, 0x53, 0xC8, 0x4C, 0x50,
  43508. 0xB8, 0x3E, 0xB9, 0xC9, 0x8D, 0x2F, 0xD0, 0x84,
  43509. 0xC9, 0xC5, 0xF2, 0x1F, 0xEE, 0x77, 0x42, 0xE6,
  43510. 0xEF, 0xC8, 0xCB, 0xBE, 0x57, 0x18, 0xB7, 0x0C,
  43511. 0x06, 0x2D, 0x82, 0xE2, 0xF9, 0x86, 0xF3, 0x8D,
  43512. 0xF1, 0xE7, 0x15, 0x89, 0xDC, 0x79, 0x87, 0x24,
  43513. 0x35, 0x62, 0xA2, 0x31, 0x9D, 0x7C, 0x00, 0xB2,
  43514. 0x6E, 0x53, 0x1E, 0x93, 0xC3, 0x84, 0x44, 0x61,
  43515. 0x8C, 0xE7, 0x58, 0x73, 0x4F, 0xDE, 0xCF, 0xD0,
  43516. 0xC6, 0x85, 0x37, 0x28, 0xC6, 0x10, 0x00, 0x78,
  43517. 0x4E, 0xDF, 0xFE, 0xD7, 0xB3, 0x30, 0x86, 0xE1,
  43518. 0x68, 0xD6, 0xCB, 0x63, 0xE3, 0xDA, 0xCA, 0xF3,
  43519. 0x55, 0x2F, 0x88, 0x5B, 0x47, 0x82, 0x62, 0xDE,
  43520. 0x5E, 0x1E, 0x63, 0xCE, 0x7A, 0x4C, 0x66, 0x95,
  43521. 0xD1, 0x19, 0x38, 0x35, 0xE4, 0x5A, 0x67, 0x91,
  43522. 0x8C, 0x42, 0xD3, 0x9B, 0xF8, 0x80, 0x38, 0x53,
  43523. 0x30, 0x31, 0x0F, 0x2C, 0x7B, 0xF9, 0x1E, 0x6C,
  43524. 0x3E, 0x29, 0xB7, 0x81, 0xD0, 0x98, 0x70, 0xC2,
  43525. 0x6D, 0x76, 0xBD, 0x8A, 0xE2, 0x09, 0xC4, 0x2B,
  43526. 0xC7, 0x43, 0x2D, 0xBB, 0x4C, 0x16, 0x52, 0x63,
  43527. 0x57, 0xA5, 0x63, 0x4E, 0xEC, 0xDE, 0x93, 0xC5,
  43528. 0x1D, 0xD4, 0xD6, 0xF0, 0x06, 0x5B, 0x2E, 0xC5,
  43529. 0x7A, 0xD3, 0xB5, 0x82, 0x66, 0x53, 0x95, 0x97,
  43530. 0xC8, 0xF4, 0x2B, 0x55, 0x27, 0x1D, 0x6F, 0x90,
  43531. 0xE9, 0x86, 0xF6, 0x82, 0x8D, 0x95, 0x9E, 0xE8,
  43532. 0x00, 0xDB, 0xEB, 0xCF, 0x48, 0x23, 0x6B, 0xA3,
  43533. 0xDE, 0x25, 0x27, 0xE0, 0xEC, 0xA4, 0xA3, 0xC2,
  43534. 0xA3, 0x4B, 0xBC, 0xDD, 0x6C, 0xBB, 0x3A, 0x9C,
  43535. 0x96, 0xDC, 0x3B, 0xE1, 0x10, 0xD3, 0x49, 0x94,
  43536. 0x66, 0xE2, 0x85, 0x7F, 0xBA, 0x98, 0x12, 0x3A,
  43537. 0x6D, 0xBA, 0x90, 0x14, 0x87, 0x7E, 0x24, 0xEA,
  43538. 0xDC, 0xCA, 0x40, 0xF8, 0xAE, 0x94, 0xB2, 0xFE,
  43539. 0xD2, 0x36, 0xCB, 0xE5, 0xBC, 0xA9, 0xDF, 0xE0,
  43540. 0xCB, 0xA9, 0xA0, 0xF8, 0x62, 0x41, 0x33, 0x18,
  43541. 0x59, 0xF9, 0xD6, 0xC0, 0x87, 0xB2, 0x76, 0xDE,
  43542. 0xC9, 0x35, 0x6F, 0x1F, 0xEF, 0x69, 0xB3, 0x59,
  43543. 0xF9, 0xFB, 0x38, 0x4A, 0x84, 0x02, 0x2D, 0xEC,
  43544. 0xB7, 0x01, 0x08, 0xDA, 0xC8, 0xE9, 0x3B, 0xB6,
  43545. 0xC3, 0x00, 0xC0, 0x34, 0x5F, 0xC6, 0x40, 0xC0,
  43546. 0x06, 0xEA, 0xEB, 0xC1, 0x51, 0x13, 0x81, 0x2F,
  43547. 0xB3, 0x7D, 0xD9, 0x6E, 0x2A, 0x06, 0xA4, 0x63,
  43548. 0xAF, 0xCE, 0x66, 0xC5, 0x9F, 0x8D, 0x71, 0x4A,
  43549. 0xA1, 0xFF, 0x49, 0x4F, 0x08, 0x6F, 0xB9, 0xEA,
  43550. 0xDA, 0x18, 0x45, 0x63, 0xCA, 0x9D, 0x88, 0x08,
  43551. 0xB1, 0x6C, 0x19, 0xA8, 0x24, 0xAD, 0x85, 0x7D,
  43552. 0xDE, 0x51, 0xE5, 0x08, 0xB7, 0x04, 0x12, 0x35,
  43553. 0xF3, 0x00, 0xED, 0x2C, 0x79, 0x9C, 0x18, 0x23,
  43554. 0x05, 0x38, 0x95, 0x76, 0xCF, 0x39, 0x3C, 0xAE,
  43555. 0xB0, 0xD3, 0xBA, 0x3E, 0x4E, 0xE4, 0xB5, 0x77,
  43556. 0xA3, 0xE3, 0x7B, 0x27, 0x5F, 0xD8, 0x05, 0x19,
  43557. 0x42, 0xAE, 0x91, 0x54, 0xE5, 0xBD, 0x7C, 0x35,
  43558. 0xE0, 0xF8, 0x95, 0x52, 0x3A, 0x29, 0xB0, 0xE6,
  43559. 0xB7, 0xAE, 0x20, 0xBE, 0x21, 0xDF, 0xF5, 0x67,
  43560. 0xEC, 0x82, 0x52, 0xFF, 0x5B, 0xD0, 0xAA, 0x14,
  43561. 0x50, 0x15, 0xE1, 0x1C, 0x6A, 0x1B, 0x94, 0x1B,
  43562. 0xCC, 0x76, 0x01, 0xBF, 0x03, 0x94, 0x42, 0xF2,
  43563. 0x00, 0x61, 0x96, 0x58, 0xD9, 0xD0, 0x40, 0x21,
  43564. 0xFA, 0xCE, 0x6B, 0xAB, 0x5D, 0x49, 0xD8, 0xD7,
  43565. 0xBC, 0x9A, 0x66, 0xC2, 0xBA, 0x3F, 0xDC, 0x49,
  43566. 0x0D, 0xA5, 0x5C, 0xB4, 0x67, 0x08, 0x38, 0xEB,
  43567. 0x2D, 0x07, 0x24, 0x5B, 0xB1, 0x22, 0x7B, 0x02,
  43568. 0x4A, 0x8A, 0x53, 0x38, 0xE9, 0x42, 0x8E, 0xA5,
  43569. 0x57, 0x41, 0xD6, 0x71, 0xA7, 0x9D, 0x6A, 0x14,
  43570. 0xD2, 0x7D, 0x13, 0xFB, 0x59, 0xD0, 0xDA, 0xE5,
  43571. 0x23, 0x9E, 0x1B, 0xC4, 0x21, 0x87, 0xBB, 0x78,
  43572. 0xE0, 0x38, 0x01, 0x1D, 0xA0, 0xD1, 0x36, 0x3F,
  43573. 0xD0, 0xA7, 0x8F, 0x86, 0x26, 0x1E, 0xB0, 0x26,
  43574. 0xDE, 0x7E, 0x17, 0x3A, 0x90, 0xFC, 0xC0, 0x17,
  43575. 0xDD, 0x78, 0xF5, 0xA3, 0x2D, 0x3E, 0x29, 0xCE,
  43576. 0x38, 0x45, 0x76, 0xA9, 0x55, 0x11, 0xB6, 0xB4,
  43577. 0xE5, 0x6E, 0xDD, 0x01, 0x4B, 0x16, 0x07, 0x99,
  43578. 0xBD, 0x19, 0x77, 0xF5, 0xD7, 0x9E, 0x39, 0x9E,
  43579. 0xAA, 0x8E, 0x2B, 0x75, 0xC5, 0xEB, 0x33, 0x56,
  43580. 0x6C, 0xD8, 0xB6, 0x3F, 0x3F, 0x4E, 0x81, 0x7E,
  43581. 0x29, 0x0A, 0x68, 0xED, 0x1E, 0x9F, 0xDC, 0x6B,
  43582. 0xFA, 0x18, 0xE3, 0xE5, 0x7D, 0x05, 0x7F, 0x22,
  43583. 0xFA, 0xA2, 0xF6, 0x0F, 0xB6, 0x34, 0x56, 0x72,
  43584. 0x55, 0x16, 0x5E, 0xF4, 0x18, 0xD1, 0x82, 0xFA,
  43585. 0xDD, 0xF7, 0xB8, 0x9F, 0x7D, 0x30, 0x10, 0x69,
  43586. 0xC4, 0x85, 0xD8, 0xE8, 0x34, 0x89, 0xD4, 0x93,
  43587. 0xBE, 0x56, 0xEE, 0xDC, 0x43, 0xD4, 0x82, 0x00,
  43588. 0xFD, 0x1E, 0x2B, 0x06, 0x69, 0x07, 0x1B, 0xBF,
  43589. 0x33, 0x61, 0x39, 0x28, 0xCA, 0x31, 0x91, 0x0B,
  43590. 0xF2, 0xEA, 0x32, 0x8E, 0xA8, 0x64, 0x13, 0x9A,
  43591. 0xEF, 0x79, 0x1A, 0x9A, 0xBE, 0x52, 0x13, 0x32,
  43592. 0x49, 0x93, 0x7D, 0xA8, 0x8C, 0x48, 0xD4, 0xC0,
  43593. 0x1D, 0x10, 0x8A, 0x46, 0x85, 0xAD, 0x29, 0xDF,
  43594. 0x2E, 0xCD, 0x41, 0x83, 0x82, 0x01, 0x28, 0x44,
  43595. 0x0E, 0xE5, 0x37, 0x8D, 0x6B, 0xCA, 0x61, 0x98,
  43596. 0xDE, 0x89, 0xA9, 0x7B, 0xBB, 0x44, 0x48, 0xA2,
  43597. 0x8D, 0x82, 0x3A, 0x57, 0x40, 0x60, 0x7C, 0x6E,
  43598. 0x69, 0x98, 0x98, 0x93, 0xFA, 0x7E, 0x29, 0x9A,
  43599. 0x74, 0x53, 0xD8, 0xDC, 0xB3, 0x4B, 0xDB, 0x7E,
  43600. 0xFE, 0x95, 0xB0, 0xC7, 0x23, 0x14, 0xEF, 0xCB,
  43601. 0x49, 0x3C, 0x09, 0xD7, 0x7B, 0xD0, 0x11, 0x9B,
  43602. 0xAC, 0xF2, 0xC2, 0x2E, 0x7C, 0xCB, 0xCD, 0x59,
  43603. 0x7F, 0x6A, 0x09, 0xFE, 0xFE, 0xDF, 0xA0, 0xA7,
  43604. 0xAC, 0x3C, 0x90, 0xBA, 0x75, 0x19, 0xF4, 0x01,
  43605. 0x60, 0x56, 0xD5, 0xFB, 0x41, 0x2B, 0xA0, 0x2D,
  43606. 0x0D, 0x45, 0xCF, 0xF3, 0xA6, 0x3D, 0x36, 0xEE,
  43607. 0xE1, 0xE4, 0x68, 0xE6, 0xEA, 0x2F, 0x67, 0x3A,
  43608. 0x7A, 0x02, 0x92, 0x6B, 0xB3, 0x18, 0xBA, 0x73,
  43609. 0xEE, 0x1B, 0x2C, 0x13, 0x7D, 0xEF, 0x4A, 0x39,
  43610. 0xE8, 0x03, 0xFF, 0x57, 0x35, 0x53, 0xE9, 0xA5,
  43611. 0xC6, 0xAA, 0x1A, 0x17, 0x21, 0xCA, 0x54, 0x38,
  43612. 0x7C, 0xB1, 0xDF, 0xB8, 0xFA, 0x7D, 0xA7, 0x26,
  43613. 0xB2, 0xAE, 0x7A, 0x05, 0x45, 0x3B, 0x40, 0x0A,
  43614. 0x19, 0xE5, 0x32, 0x52, 0x78, 0x9D, 0xC3, 0x20,
  43615. 0x63, 0x24, 0xB2, 0x58, 0x4B, 0x86, 0x1F, 0x00,
  43616. 0xA2, 0x50, 0xF9, 0x9F, 0xD9, 0xDC, 0x7D, 0x51,
  43617. 0x3D, 0xD7, 0xA6, 0x5A, 0x04, 0x03, 0x4E, 0xB3,
  43618. 0x3D, 0x2D, 0x56, 0xA4, 0x96, 0xB3, 0x6A, 0xBA,
  43619. 0x0A, 0x30, 0x08, 0xE3, 0x0F, 0xC1, 0x38, 0x24,
  43620. 0x88, 0x5D, 0x9E, 0x6F, 0x68, 0x1A, 0x7D, 0xB6,
  43621. 0x2D, 0xDD, 0xE3, 0x50, 0x1B, 0xD4, 0x07, 0x75,
  43622. 0xE2, 0xE2, 0xCC, 0x09, 0xCC, 0x8E, 0x4E, 0x67,
  43623. 0x02, 0x72, 0x02, 0xA8, 0x11, 0x70, 0xA5, 0x7F,
  43624. 0x4A, 0xC1, 0x98, 0xC1, 0x7F, 0xBF, 0x95, 0xBB,
  43625. 0xCE, 0xD3, 0x6D, 0x49, 0x30, 0xB9, 0x50, 0x8C,
  43626. 0xFA, 0x3E, 0x8B, 0xF6, 0xE5, 0x54, 0xE9, 0x1B,
  43627. 0xD7, 0xD6, 0xE5, 0x32, 0x33, 0xBB, 0x91, 0xAD,
  43628. 0xC8, 0x15, 0x76, 0x1A, 0x04, 0x35, 0xDE, 0xCC,
  43629. 0xE1, 0x67, 0x26, 0x4C, 0x2F, 0x4E, 0x34, 0x34,
  43630. 0x3D, 0x1E, 0x5A, 0xF7, 0xBC, 0xE6, 0x0C, 0x9B,
  43631. 0x7B, 0x7E, 0xE5, 0xDF, 0x72, 0x9A, 0x0D, 0xDD,
  43632. 0x4B, 0xE6, 0x6F, 0x82, 0xFB, 0x5E, 0x2C, 0xC0,
  43633. 0x7B, 0x03, 0x85, 0x76, 0x11, 0x0E, 0xFD, 0xC7,
  43634. 0xD5, 0x50, 0x26, 0xBE, 0x75, 0x5E, 0xC1, 0xF0,
  43635. 0x2E, 0x47, 0x62, 0xD6, 0xF1, 0xDA, 0xDF, 0xF4,
  43636. 0x1C, 0xEE, 0x63, 0x52, 0xC4, 0x45, 0x37, 0xE6,
  43637. 0x85, 0xA5, 0x0A, 0x07, 0x54, 0x63, 0x21, 0x7B,
  43638. 0x92, 0xF7, 0x33, 0x0C, 0xD9, 0x29, 0xCF, 0xE3,
  43639. 0xAB, 0xB5, 0xFC, 0xAA, 0x26, 0x20, 0x93, 0x55,
  43640. 0x8A, 0x07, 0x33, 0xB2, 0x7D, 0x95, 0x02, 0x7A,
  43641. 0x76, 0x9E, 0x7D, 0xBB, 0xC1, 0xF3, 0x6E, 0x84,
  43642. 0x10, 0x30, 0x4B, 0x5D, 0x59, 0x73, 0x68, 0xEC,
  43643. 0x2A, 0x63, 0x2D, 0x46, 0xE8, 0xC2, 0xF8, 0xEA,
  43644. 0x2B, 0xC4, 0x4F, 0xA7, 0x6E, 0xF4, 0x74, 0xEB,
  43645. 0x96, 0xA3, 0x64, 0x40, 0x9B, 0x23, 0x63, 0x42,
  43646. 0x4B, 0x8F, 0x85, 0x00, 0x43, 0x04, 0xAD, 0x61,
  43647. 0x76, 0x93, 0xBD, 0xC3, 0x88, 0xC3, 0xFC, 0x29,
  43648. 0x61, 0xBD, 0xB1, 0x5A, 0x1F, 0x5B, 0x20, 0xEF,
  43649. 0x95, 0xED, 0x99, 0x84, 0x96, 0xB2, 0x93, 0x81,
  43650. 0x82, 0xFF, 0xE3, 0xB9, 0x27, 0xEA, 0x9A, 0x23,
  43651. 0xF6, 0x42, 0x8D, 0xD3, 0x5C, 0x86, 0x11, 0xC8,
  43652. 0x39, 0xE3, 0x16, 0xE9, 0xA5, 0x32, 0x7C, 0xC9,
  43653. 0xEA, 0x82, 0x50, 0x9B, 0x21, 0x5C, 0xC9, 0x66,
  43654. 0xBE, 0x1C, 0x78, 0x48, 0xEF, 0x39, 0x2D, 0xA1,
  43655. 0xC6, 0xF3, 0x69, 0xA3, 0x36, 0x25, 0x3A, 0xA1,
  43656. 0x15, 0x2B, 0x6D, 0xCF, 0xDA, 0xA7, 0xCA, 0xDD,
  43657. 0x4D, 0x9A, 0x1D, 0x58, 0x9F, 0x73, 0xD3, 0xEF,
  43658. 0x0F, 0xBF, 0x03, 0x88, 0x2F, 0xDE, 0xB9, 0x44,
  43659. 0xB5, 0xB6, 0xCF, 0xE2, 0x6F, 0x6A, 0xB5, 0x12,
  43660. 0x38, 0x29, 0x55, 0x8C, 0x4C, 0x73, 0x6F, 0x0B,
  43661. 0x68, 0x7A, 0xC7, 0x06, 0x83, 0x80, 0xFE, 0x7F,
  43662. 0x61, 0xBE, 0x6B, 0x40, 0xE3, 0xF0, 0x4D, 0x7B,
  43663. 0x36, 0x82, 0x0F, 0xD8, 0x63, 0x29, 0xB3, 0x10,
  43664. 0x9D, 0x02, 0xEC, 0x63, 0x90, 0xEA, 0xFC, 0x8C,
  43665. 0xA7, 0x30, 0x56, 0x2B, 0x68, 0x08, 0x24, 0x24,
  43666. 0xFD, 0xA9, 0x8D, 0x0B, 0x64, 0xBC, 0x97, 0x34,
  43667. 0xB4, 0x0B, 0x63, 0xF7, 0xE3, 0x7A, 0xF6, 0x89,
  43668. 0x0A, 0xF7, 0xC2, 0xD9, 0x2F, 0x79, 0xEE, 0xA3,
  43669. 0xCC, 0xEA, 0xC6, 0x0A, 0x6F, 0x38, 0x06, 0x92,
  43670. 0xF8, 0x02, 0xB1, 0x55, 0x6A, 0x78, 0xFE, 0x55,
  43671. 0x83, 0xFF, 0x20, 0xA9, 0xC6, 0xA7, 0xBF, 0xCC,
  43672. 0x86, 0x3A, 0x9E, 0x7B, 0x62, 0x01, 0x4D, 0x16,
  43673. 0x05, 0xDE, 0x89, 0x4F, 0xB5, 0x85, 0xE2, 0xD4,
  43674. 0xF9, 0x41, 0x15, 0xE0, 0x29, 0xE5, 0x85, 0x7E,
  43675. 0x6A, 0x0A, 0x73, 0x89, 0x27, 0x5F, 0x53, 0x0D,
  43676. 0x3D, 0x80, 0xCF, 0xAB, 0x1F, 0x22, 0x5D, 0x38,
  43677. 0x33, 0x5D, 0x24, 0x67, 0x91, 0x97, 0xD4, 0x8A,
  43678. 0x01, 0x8A, 0x34, 0x18, 0x7D, 0xE3, 0xBC, 0xCE,
  43679. 0xDE, 0x94, 0xFF, 0x8E, 0xC5, 0x34, 0xC0, 0x2D,
  43680. 0xA7, 0x24, 0xD4, 0x59, 0x8D, 0x66, 0x9E, 0x85,
  43681. 0xA9, 0xC6, 0x0E, 0x45, 0x21, 0x4F, 0xAA, 0x65,
  43682. 0x44, 0xD6, 0xA4, 0x7D, 0x1C, 0x4E, 0xD7, 0x40,
  43683. 0x9D, 0x55, 0xB1, 0xA7, 0xF1, 0x15, 0xAE, 0x15,
  43684. 0x44, 0x3A, 0x1C, 0x31, 0x06, 0x40, 0xD1, 0x16,
  43685. 0x23, 0x84, 0x93, 0xEF, 0x3E, 0xE2, 0x87, 0x9B,
  43686. 0xB8, 0x46, 0x1F, 0x7D, 0x68, 0x73, 0x64, 0x70,
  43687. 0xD4, 0xB5, 0x73, 0xAE, 0x45, 0x49, 0x93, 0xF5,
  43688. 0x32, 0x30, 0x1E, 0x35, 0xCB, 0x9E, 0xEE, 0xDF,
  43689. 0xFE, 0xA8, 0x2F, 0xAC, 0x49, 0x77, 0x53, 0xF7,
  43690. 0x50, 0x19, 0xF2, 0xB3, 0xB0, 0x2C, 0x70, 0xB6,
  43691. 0x4A, 0x57, 0x95, 0x31, 0xC3, 0x26, 0x07, 0x2A,
  43692. 0xCF, 0x1B, 0xD0, 0xAA, 0xA0, 0x9F, 0x0A, 0x97,
  43693. 0x8B, 0x78, 0xAB, 0x22, 0xBD, 0x61, 0x19, 0xF8,
  43694. 0x8D, 0xD2, 0xD5, 0x72, 0xF8, 0x91, 0x9D, 0x47,
  43695. 0x4F, 0x59, 0x1D, 0xAE, 0x9F, 0xCE, 0x47, 0x53,
  43696. 0xC9, 0x85, 0xFB, 0x25, 0x04, 0x25, 0xF2, 0x65,
  43697. 0x61, 0xFF, 0xA9, 0x44, 0x3F, 0x23, 0x76, 0x68,
  43698. 0x9F, 0xEB, 0x48, 0xC4, 0xCE, 0x51, 0x46, 0x04,
  43699. 0x52, 0x6A, 0x10, 0x0A, 0xF3, 0x3F, 0x0D, 0x43,
  43700. 0x37, 0xD1, 0x60, 0x42, 0x22, 0xC4, 0xD9, 0xF9,
  43701. 0x3A, 0x8E, 0x69, 0xE4, 0xCC, 0xD3, 0x66, 0x69,
  43702. 0x09, 0x0C, 0x5D, 0xFB, 0x0E, 0x95, 0x49, 0x42,
  43703. 0x29, 0xFF, 0x9B, 0x20, 0xCC, 0xB1, 0xAC, 0x81,
  43704. 0xB8, 0x1A, 0x36, 0xD6, 0x3A, 0x85, 0x0D, 0xDB,
  43705. 0x33, 0x33, 0x4D, 0xAA, 0x51, 0x46, 0xBF, 0x36,
  43706. 0xFE, 0x18, 0x80, 0x1E, 0x3B, 0xEB, 0xD0, 0xE9,
  43707. 0x1B, 0x5E, 0x1C, 0xFE, 0x7A, 0x98, 0x26, 0x85,
  43708. 0x0A, 0xF4, 0x39, 0x7D, 0x1B, 0x07, 0xD3, 0xB7,
  43709. 0x19, 0xE5, 0x7B, 0xB8, 0x32, 0xAF, 0x42, 0x34,
  43710. 0xC0, 0xCD, 0x9F, 0xD4, 0x0B, 0x88, 0x2F, 0xCE,
  43711. 0xDA, 0x93, 0x7E, 0xF9, 0xA2, 0xDA, 0x24, 0x59,
  43712. 0x2B, 0xCB, 0x5D, 0x1B, 0xE8, 0x3E, 0xC5, 0xF0,
  43713. 0x3D, 0xBD, 0xFB, 0xCB, 0x33, 0x5D, 0x90, 0xD5,
  43714. 0xC8, 0xA0, 0x2E, 0xE5, 0x3D, 0x50, 0x8E, 0xB5,
  43715. 0xDE, 0x4A, 0x96, 0x1B, 0x95, 0x8F, 0x75, 0x1E,
  43716. 0x5F, 0x89, 0xA1, 0xD2, 0x88, 0x95, 0xA3, 0xDB,
  43717. 0x7B, 0x62, 0xEF, 0x4A, 0xE1, 0x6D, 0x28, 0xFB,
  43718. 0x78, 0x9B, 0x32, 0x03, 0xAD, 0x24, 0x63, 0xD6,
  43719. 0xEA, 0xB8, 0x3A, 0x6D, 0x20, 0xCE, 0xA1, 0x31,
  43720. 0x4A, 0xE0, 0x2A, 0x3F, 0xF6, 0xF6, 0x53, 0x15,
  43721. 0x4A, 0xE1, 0x44, 0x23, 0x81, 0x86, 0x21, 0x47,
  43722. 0x41, 0xC2, 0x36, 0x14, 0x81, 0x83, 0xBC, 0x39,
  43723. 0xAE, 0xDF, 0x44, 0xDA, 0x97, 0xF7, 0x31, 0xCE,
  43724. 0x3D, 0xCB, 0x61, 0xA4, 0xCF, 0xE1, 0x4F, 0x9E,
  43725. 0x84, 0xAA, 0x05, 0xAB, 0x1C, 0x1B, 0x95, 0x1D,
  43726. 0x20, 0x15, 0x52, 0x33, 0xFA, 0xFA, 0xF1, 0x6C,
  43727. 0xF1, 0xBD, 0x0B, 0xAF, 0xE1, 0x99, 0xE6, 0x5D,
  43728. 0x56, 0x34, 0x53, 0xBF, 0xE5, 0x5D, 0x5F, 0x47,
  43729. 0x4A, 0xB1, 0x05, 0x94, 0xD7, 0x38, 0xA8, 0xC1,
  43730. 0x06, 0x28, 0x8D, 0x69, 0xD0, 0x7A, 0x16, 0x88,
  43731. 0x60, 0x14, 0x63, 0xF3, 0xBD, 0x21, 0x46, 0x81,
  43732. 0x9C, 0x83, 0x72, 0x6D, 0x14, 0xC6, 0xA8, 0x08,
  43733. 0x39, 0xB8, 0x79, 0x0B, 0x57, 0x16, 0xE7, 0x72,
  43734. 0xF6, 0xC2, 0x4C, 0x2B, 0xEB, 0x7E, 0x2C, 0xF3,
  43735. 0x7B, 0x3F, 0x42, 0xAC, 0xDD, 0x47, 0x3E, 0x8C,
  43736. 0xCD, 0xBE, 0x48, 0x4D, 0x6E, 0x07, 0xB0, 0x73,
  43737. 0xDE, 0xCB, 0x17, 0x4A, 0xC3, 0xB8, 0xBB, 0x2E,
  43738. 0xF5, 0x4E, 0x6D, 0xF9, 0xE0, 0x20, 0x71, 0xFA,
  43739. 0x60, 0x0A, 0xE5, 0x59, 0x67, 0xEB, 0x6F, 0x70,
  43740. 0x2F, 0x71, 0x91, 0x59, 0xF0, 0xEB, 0x06, 0x5C,
  43741. 0xC4, 0x60, 0x48, 0xE8, 0x75, 0xE7, 0xCF, 0x42,
  43742. 0x71, 0xAD, 0x2E, 0xDA, 0xF9, 0x10, 0x82, 0x9A,
  43743. 0xF6, 0x13, 0xBA, 0x89, 0xFC, 0x61, 0x2A, 0x00,
  43744. 0xFD, 0xAE, 0x53, 0x7B, 0x09, 0x3A, 0xE8, 0xCB,
  43745. 0xE6, 0xB7, 0x0D, 0x03, 0x01, 0xFA, 0x2E, 0x13,
  43746. 0xA9, 0x16, 0x38, 0x1C, 0x92, 0xEC, 0xB4, 0x51,
  43747. 0xA3, 0x6E, 0x3F, 0xA8, 0xB7, 0x37, 0x36, 0x20,
  43748. 0xC0, 0x71, 0xA3, 0x05, 0x34, 0xED, 0xCB, 0x4A,
  43749. 0x3F, 0x11, 0x31, 0x17, 0xA5, 0x02, 0xD6, 0xA7,
  43750. 0x2D, 0xE6, 0xC7, 0x7B, 0xBB, 0xF6, 0xAE, 0x99,
  43751. 0x85, 0x9A, 0xAC, 0xE6, 0x4A, 0x92, 0x8C, 0x37,
  43752. 0x4B, 0xD2, 0xC4, 0x65, 0x2A, 0xC9, 0x7E, 0xB7,
  43753. 0x44, 0xD2, 0x9A, 0x70, 0xCE, 0xA9, 0xA1, 0x9D,
  43754. 0x70, 0x13, 0x49, 0x7B, 0xCA, 0xB6, 0x96, 0x31,
  43755. 0x43, 0x3F, 0x9E, 0xD1, 0xFE, 0x20, 0xF8, 0x0B,
  43756. 0x59, 0x83, 0xE1, 0x28, 0x8B, 0xB6, 0xA2, 0xBE,
  43757. 0x91, 0x54, 0x3E, 0xD4, 0x79, 0x28, 0xBB, 0x5E,
  43758. 0x46, 0x2D, 0x01, 0xE9, 0xC0, 0xB7, 0xFF, 0xFA,
  43759. 0xC0, 0x6C, 0x10, 0xF1, 0x52, 0xF4, 0x3C, 0x32,
  43760. 0x9E, 0x89, 0xDF, 0x8A, 0x79, 0x99, 0x6A, 0x09,
  43761. 0x79, 0x8A, 0x36, 0x76, 0x40, 0xBE, 0x9F, 0xB5,
  43762. 0x3D, 0xCE, 0x27, 0xBD, 0x0B, 0xAA, 0x9B, 0xF0,
  43763. 0x21, 0xBF, 0x10, 0xD2, 0xFC, 0xFE, 0x5B, 0x13,
  43764. 0xFD, 0x7D, 0x84, 0xD1, 0xC1, 0xEB, 0xC0, 0xBC,
  43765. 0xEC, 0x26, 0xD0, 0x87, 0x80, 0xD1, 0x3B, 0x99,
  43766. 0x47, 0x67, 0x26, 0x61, 0xE0, 0xFA, 0x5F, 0xAE,
  43767. 0x6F, 0x31, 0x5B, 0x6D, 0xE4, 0x01, 0x68, 0xC2,
  43768. 0x35, 0x1D, 0xE3, 0x1F, 0x41, 0xFF, 0x6C, 0x53,
  43769. 0x32, 0x26, 0xE1, 0xBC, 0xE3, 0xF8, 0xE2, 0x16,
  43770. 0xAF, 0x3B, 0xE6, 0x4C, 0x69, 0x33, 0x72, 0xA0,
  43771. 0x66, 0xB1, 0x75, 0xF7, 0x26, 0xCF, 0xCD, 0x64,
  43772. 0x2B, 0xAE, 0x98, 0x02, 0x92, 0xC1, 0xCB, 0x65,
  43773. 0xE0, 0x1F, 0x07, 0x29, 0x64, 0x0A, 0xB0, 0x09,
  43774. 0xCB, 0x98, 0x89, 0x2D, 0x6C, 0xFE, 0x40, 0x03,
  43775. 0x34, 0x55, 0xDE, 0xE7, 0x30, 0x33, 0xB6, 0xD5,
  43776. 0xE1, 0x9C, 0x59, 0x9F, 0x8A, 0x40, 0x0E, 0xB1,
  43777. 0x41, 0x52, 0x7D, 0xF2, 0xBB, 0xDD, 0xEF, 0x50,
  43778. 0xBB, 0xD5, 0xFB, 0x55, 0xAA, 0x5E, 0xFD, 0xB3,
  43779. 0x5D, 0x08, 0x56, 0x9B, 0x02, 0x97, 0xE2, 0x48,
  43780. 0x14, 0x69, 0xF1, 0x7B, 0x87, 0xB5, 0x08, 0x93,
  43781. 0x6A, 0x9C, 0x5C, 0x11, 0x08, 0x9A, 0xE9, 0xE4,
  43782. 0xB0, 0xCA, 0xC5, 0x74, 0x93, 0x93, 0xC8, 0x03,
  43783. 0xE4, 0x70, 0x39, 0xF5, 0x1B, 0x5C, 0xBD, 0x42,
  43784. 0xA6, 0xC9, 0xE1, 0x9E, 0xC3, 0xF6, 0x3C, 0x23,
  43785. 0x32, 0xE8, 0x77, 0x68, 0xA9, 0x60, 0xFA, 0x02,
  43786. 0x18, 0x6B, 0x7A, 0x2B, 0x02, 0x92, 0x65, 0x09,
  43787. 0x11, 0x46, 0x73, 0x04, 0x63, 0xDF, 0x8B, 0x37,
  43788. 0x5F, 0x24, 0xAA, 0x83, 0xBD, 0xD4, 0x1D, 0x13,
  43789. 0x04, 0xFC, 0x2F, 0xB5, 0x2D, 0xA1, 0x0F, 0x1F,
  43790. 0xED, 0x65, 0x29, 0x08, 0xCF, 0x8C, 0x52, 0x8F,
  43791. 0xB2, 0x62, 0x5F, 0x39, 0x3F, 0xC8, 0xC7, 0xB3,
  43792. 0x3F, 0xAD, 0x45, 0xBA, 0xD4, 0x7D, 0x38, 0x3D,
  43793. 0x2C, 0x04, 0xCF, 0x32, 0xE8, 0x07, 0x42, 0x5F,
  43794. 0x93, 0xD2, 0x35, 0x07, 0x21, 0xB7, 0xB2, 0xF5,
  43795. 0x96, 0x64, 0x8E, 0xB5, 0xE1, 0x38, 0x6B, 0x43,
  43796. 0xD1, 0x2E, 0xFD, 0xDB, 0x8F, 0xE2, 0x43, 0x6A,
  43797. 0xEC, 0x27, 0x8E, 0xE7, 0x68, 0x75, 0xB5, 0x23,
  43798. 0xC5, 0x43, 0x1D, 0x99, 0x48, 0x57, 0x73, 0xD9,
  43799. 0xAD, 0xBC, 0xD0, 0x14, 0xDD, 0x87, 0xBC, 0x68,
  43800. 0xFB, 0x82, 0xEE, 0x47, 0x4B, 0x22, 0xA5, 0x43,
  43801. 0x3A, 0xF9, 0xF9, 0x91, 0xFC, 0x34, 0xB2, 0x58,
  43802. 0x34, 0xDF, 0x13, 0x09, 0x9A, 0x46, 0xF5, 0x68,
  43803. 0xAF, 0xD1, 0x15, 0x5F, 0x32, 0x1B, 0x9D, 0xA9,
  43804. 0xE9, 0xC0, 0x63, 0x47, 0xAB, 0x3C, 0x1F, 0x59,
  43805. 0xF7, 0xEA, 0x0E, 0xD6, 0xCF, 0x47, 0xB3, 0xE9,
  43806. 0xAF, 0x65, 0x7A, 0xA7, 0xAE, 0x9B, 0xF8, 0x26,
  43807. 0x0B, 0x96, 0x9D, 0xE4, 0xAD, 0x24, 0xD3, 0xA8,
  43808. 0xCE, 0x95, 0xE5, 0x77, 0xD0, 0x44, 0x13, 0x05,
  43809. 0x06, 0x4E, 0x07, 0xB9, 0xA2, 0xC7, 0x5C, 0x3C,
  43810. 0x43, 0x80, 0x1F, 0xCE, 0xB7, 0x36, 0xFE, 0x3D,
  43811. 0x27, 0x1B, 0xE1, 0xF3, 0x6B, 0xFF, 0xC8, 0xE4,
  43812. 0x3D, 0xB1, 0x4A, 0x16, 0x24, 0x76, 0xBA, 0xEA,
  43813. 0x9D, 0x34, 0x6B, 0x52, 0x11, 0xAB, 0xD0, 0x06,
  43814. 0x08, 0xB1, 0x5A, 0xF3, 0xB5, 0xE6, 0x3A, 0x00,
  43815. 0xFF, 0x92, 0x8D, 0x1E, 0xA1, 0xA1, 0x8D, 0x75,
  43816. 0xFA, 0x7C, 0x6C, 0x1B, 0x0F, 0xB6, 0x27, 0x2E,
  43817. 0x55, 0xC3, 0xFE, 0x7E, 0x4D, 0x42, 0x05, 0xE5,
  43818. 0xCF, 0x0A, 0x1F, 0x87, 0x18, 0x30, 0x4E, 0x14,
  43819. 0xF2, 0xB4, 0xCC, 0x54, 0x3D, 0x04, 0x37, 0x34,
  43820. 0x1A, 0x4A, 0x31, 0x16, 0x01, 0xA9, 0x2E, 0x92,
  43821. 0x56, 0x6B, 0x7D, 0xFB, 0x42, 0x64, 0xE8, 0x70,
  43822. 0xE1, 0xB3, 0xA8, 0x75, 0xED, 0xBC, 0x00, 0x3A,
  43823. 0x56, 0x19, 0x70, 0xCF, 0x8A, 0x66, 0x9F, 0x3D,
  43824. 0x1B, 0x69, 0x28, 0x8C, 0xC6, 0xE3, 0x59, 0xCE,
  43825. 0x28, 0xCA, 0x65, 0xF9, 0xDA, 0xE8, 0xCE, 0xCA,
  43826. 0x74, 0x3C, 0x1C, 0x8D, 0x9F, 0xFB, 0x55, 0x08,
  43827. 0x82, 0x4A, 0x83, 0x61, 0xE3, 0x3B, 0x43, 0x1A,
  43828. 0x2E, 0x9E, 0x9A, 0x99, 0x78, 0x47, 0xD2, 0xE6,
  43829. 0xE4, 0x3C, 0x83, 0xF0, 0x22, 0x62, 0xE2, 0x94,
  43830. 0x6D, 0xF7, 0x72, 0x6D, 0x54, 0xE3, 0xE6, 0xC9,
  43831. 0xCC, 0xDB, 0x6D, 0x3F, 0x13, 0x63, 0x46, 0xC1,
  43832. 0x1E, 0x59, 0x42, 0xE7, 0xA1, 0xBF, 0x85, 0x0C,
  43833. 0x2E, 0x99, 0xB4, 0xFA, 0xCE, 0x75, 0xFD, 0x40,
  43834. 0x88, 0x69, 0x33, 0x90, 0x7C, 0xCD, 0xFC, 0x0D,
  43835. 0xE1, 0x17, 0x70, 0x20, 0x31, 0x94, 0x1D, 0x00,
  43836. 0x1E, 0x2A, 0x68, 0x3C, 0x55, 0x78, 0xFD, 0x33,
  43837. 0x54, 0x21, 0x2C, 0xEA, 0xD9, 0x69, 0xBF, 0x1C,
  43838. 0x81, 0x23, 0x9E, 0xEC, 0xC7, 0x74, 0xFD, 0x0B,
  43839. 0x88, 0x3D, 0x0E, 0xEE, 0x82, 0x4B, 0x10, 0xB8,
  43840. 0x79, 0xCF, 0x70, 0x7C, 0xB2, 0x68, 0x47, 0x45,
  43841. 0x22, 0x06, 0x1E, 0x92, 0x7B, 0x12, 0x43, 0x24,
  43842. 0x41, 0x15, 0xC6, 0x69, 0xE9, 0xEB, 0x27, 0x2B,
  43843. 0x60, 0xA6, 0x44, 0xF5, 0x19, 0xEF, 0xEC, 0x06,
  43844. 0x34, 0x08, 0xB6, 0x58, 0x47, 0x2E, 0x91, 0x61,
  43845. 0xA1, 0xF7, 0x44, 0xFD, 0x66, 0x16, 0x9F, 0x0C,
  43846. 0xAE, 0x36, 0xB4, 0x2E, 0x23, 0x79, 0xCB, 0xE8,
  43847. 0x1E, 0x6E, 0x51, 0xA0, 0xF5, 0x34, 0x15, 0x18,
  43848. 0x4E, 0xA0, 0x06, 0xB2, 0x27, 0x0B, 0x33, 0xE2,
  43849. 0xCA, 0x36, 0x4C, 0xDB, 0x33, 0xAA, 0xAE, 0x77,
  43850. 0xFF, 0xD9, 0x53, 0xDB, 0x39, 0x70, 0x4D, 0x49,
  43851. 0x0C, 0xE9, 0xAC, 0x6F, 0x2D, 0xD1, 0xC7, 0xA1,
  43852. 0x8E, 0x61, 0x74, 0x19, 0xA9, 0xAA, 0xFB, 0x37,
  43853. 0xE7, 0x23, 0x9B, 0x23, 0x6A, 0x4B, 0x74, 0xCE,
  43854. 0x63, 0xE4, 0xA0, 0xAD, 0xFF, 0x85, 0x5D, 0xCD,
  43855. 0x78, 0xF6, 0x45, 0x8E, 0x76, 0x0B, 0xFD, 0x1D,
  43856. 0x2A, 0xB9, 0x5E, 0x83, 0xC0, 0x3B, 0x6F, 0xAE,
  43857. 0x0C, 0xD3, 0xC5, 0xCE, 0xEE, 0xEE, 0x1C, 0x69,
  43858. 0x51, 0x59, 0x65, 0xA3, 0x35, 0xFC, 0xF7, 0x8E,
  43859. 0x80, 0xAA, 0x73, 0x93, 0x39, 0x54, 0x21, 0x27,
  43860. 0x17, 0x0B, 0x2C, 0x3E, 0xE1, 0x0B, 0x0E, 0xAA,
  43861. 0x09, 0x9A, 0xC7, 0xAD, 0x4C, 0xD7, 0x6E, 0x7F,
  43862. 0xE4, 0xC1, 0x16, 0x4E, 0x62, 0xF4, 0xE5, 0x80,
  43863. 0x7D, 0xC0, 0x06, 0x1F, 0x77, 0xE4, 0xA8, 0xA5,
  43864. 0x28, 0xD7, 0x10, 0x37, 0x59, 0x30, 0xCB, 0x75,
  43865. 0x5B, 0x28, 0xBF, 0xFD, 0x92, 0x8C, 0xB0, 0x7B,
  43866. 0xB4, 0xA1, 0x07, 0xCD, 0xCA, 0xBB, 0x30, 0x8A,
  43867. 0x48, 0x65, 0x0D, 0xA4, 0xE5, 0x74, 0xD9, 0xBF,
  43868. 0x56, 0x07, 0xF5, 0x83, 0xDA, 0xC3, 0x40, 0xD7,
  43869. 0x20, 0x93, 0xEF, 0xB1, 0x2B, 0xBF, 0x93, 0x41,
  43870. 0x0F, 0x1E, 0xF5, 0xC9, 0x51, 0x6C, 0x74, 0x4D,
  43871. 0x23, 0x15, 0xEC, 0x9E, 0x00, 0x0A, 0x8D, 0xC5,
  43872. 0xD1, 0x7A, 0x7B, 0x6F, 0x0D, 0x07, 0x9D, 0x78,
  43873. 0x4B, 0x6D, 0x90, 0x19, 0x3F, 0x6E, 0x3E, 0xE7,
  43874. 0xEA, 0x0E, 0xAB, 0xFC, 0x6F, 0x68, 0xC5, 0x2B,
  43875. 0x37, 0xCB, 0xCE, 0x82, 0x18, 0xAF, 0xA3, 0x67,
  43876. 0x0A, 0x80, 0xBC, 0x17, 0xB9, 0x5D, 0x7B, 0x40,
  43877. 0x53, 0x62, 0x26, 0x35, 0x8F, 0x04, 0xAC, 0xD9,
  43878. 0x2A, 0x1B, 0xE1, 0x5B, 0x26, 0xA4, 0xE5, 0x81,
  43879. 0x7E, 0x62, 0x8B, 0xA6, 0x79, 0xB3, 0x52, 0x72,
  43880. 0x03, 0xCD, 0x36, 0x32, 0x62, 0x8E, 0xC8, 0x3A,
  43881. 0xA4, 0xF2, 0x18, 0x6D, 0x2F, 0x00, 0x5D, 0x5D,
  43882. 0xFE, 0x6F, 0x7F, 0xDB, 0x4F, 0xED, 0xAC, 0x9E,
  43883. 0x89, 0xD6, 0x66, 0xE3, 0x03, 0xBB, 0x56, 0x83,
  43884. 0x06, 0x15, 0x6C, 0x56, 0xF0, 0x95, 0x34, 0xE2,
  43885. 0x5C, 0x61, 0x9A, 0xB3, 0xB9, 0x50, 0x18, 0xF4,
  43886. 0x89, 0x6B, 0xAC, 0xAA, 0x48, 0x34, 0xF6, 0xD2,
  43887. 0xD8, 0xFE, 0x14, 0xA9, 0x38, 0xAA, 0x10, 0xE5,
  43888. 0x30, 0x54, 0xF0, 0x00, 0x84, 0x44, 0xAC, 0x2E,
  43889. 0xEA, 0x25, 0x38, 0xC1, 0x23, 0x0E, 0x6A, 0x18,
  43890. 0xC9, 0x2B, 0x01, 0xD9, 0x14, 0x7F, 0xDC, 0xEF,
  43891. 0xC9, 0xC8, 0xDA, 0xC1, 0xD4, 0xEC, 0xC8, 0xCF,
  43892. 0x1F, 0x96, 0x2E, 0xFA, 0x1B, 0x8C, 0xD3, 0xC9,
  43893. 0x69, 0x00, 0x0B, 0x7E, 0xBA, 0xC5, 0x98, 0xDC,
  43894. 0xA4, 0x5E, 0xB4, 0x0B, 0xCF, 0xB1, 0x98, 0x51,
  43895. 0x48, 0x38, 0x51, 0xCF, 0x34, 0x0F, 0x3E, 0x8C,
  43896. 0x23, 0x7A, 0x9E, 0xFF, 0x1C, 0x9F, 0x21, 0xE4,
  43897. 0x97, 0x55, 0x41, 0xC6, 0x1A, 0x8F, 0xEF, 0x2A,
  43898. 0xC6, 0x05, 0x7F, 0x59, 0xDC, 0xB2, 0x3A, 0x80,
  43899. 0xE8, 0x06, 0x10, 0xCD, 0x85, 0xDB, 0x20, 0x3C,
  43900. 0x35, 0xD2, 0x4B, 0xC8, 0x2B, 0x9C, 0xD7, 0x82,
  43901. 0x46, 0xF5, 0x9F, 0xEB, 0xB2, 0x48, 0x32, 0xD7,
  43902. 0xCD, 0x66, 0x4C, 0x99, 0x51, 0x88, 0xE0, 0x28,
  43903. 0x1C, 0xD7, 0x86, 0x79, 0x00, 0xDC, 0x0D, 0xF4,
  43904. 0x4D, 0x40, 0x90, 0x80, 0x26, 0x8B, 0x79, 0xE9,
  43905. 0x56, 0x82, 0x88, 0x5F, 0x22, 0x87, 0x70, 0x73,
  43906. 0x4F, 0xA5, 0x35, 0x18, 0xEC, 0x80, 0xCE, 0x23,
  43907. 0x06, 0xCE, 0x14, 0x48, 0x52, 0x4E, 0xF0, 0x18,
  43908. 0x43, 0x03, 0xD4, 0x50, 0xC7, 0x6E, 0xA6, 0x3B,
  43909. 0x73, 0x3E, 0xB0, 0xC8, 0xDC, 0x48, 0xBF, 0x12,
  43910. 0x42, 0x3A, 0xD2, 0x38, 0x89, 0xCF, 0xCD, 0xD8,
  43911. 0x91, 0xE5, 0x95, 0x00, 0x47, 0x24, 0x0D, 0xC0,
  43912. 0xC3, 0x8A, 0xB2, 0xDB, 0xC1, 0x65, 0xB8, 0x1E,
  43913. 0x63, 0x10, 0x02, 0xEA, 0x6F, 0x74, 0x11, 0x9E,
  43914. 0x27, 0xF9, 0xF8, 0x60, 0x73, 0xBF, 0x2D, 0xF7,
  43915. 0x10, 0x81, 0x86, 0x76, 0x98, 0x0C, 0x4C, 0xB6,
  43916. 0xBD, 0x53, 0xF9, 0xA5, 0x72, 0x17, 0x78, 0xB8,
  43917. 0x9F, 0x59, 0xC6, 0x8C, 0x89, 0x35, 0xF5, 0x03,
  43918. 0x1C, 0x8A, 0x93, 0x36, 0x7D, 0x71, 0x70, 0x57,
  43919. 0xFD, 0x4D, 0x5E, 0xFA, 0xBE, 0xDE, 0x70, 0x2C,
  43920. 0xC6, 0x45, 0xEF, 0xB6, 0xD7, 0xF4, 0x4C, 0x86,
  43921. 0x0F, 0xFF, 0x76, 0x37, 0xAA, 0xD9, 0x72, 0x24,
  43922. 0x8C, 0x84, 0x4D, 0x15, 0x13, 0x39, 0x20, 0x07,
  43923. 0x38, 0x91, 0xC3, 0x13, 0x5D, 0x29, 0x78, 0x68,
  43924. 0xB7, 0xDA, 0x86, 0xF0, 0x97, 0xD8, 0xFB, 0x39,
  43925. 0xC1, 0x3B, 0xA1, 0x4C, 0x4F, 0x24, 0x75, 0x16,
  43926. 0xAB, 0xA4, 0xC5, 0xF8, 0xCE, 0x38, 0x18, 0x48,
  43927. 0x2C, 0x8F, 0xF6, 0x0C, 0xCA, 0x51, 0xFD, 0xB2,
  43928. 0xCE, 0xE9, 0x6B, 0xC1, 0x13, 0x8D, 0xC0, 0x4A,
  43929. 0x86, 0xF8, 0x57, 0x72, 0x75, 0x91, 0xAA, 0xE6,
  43930. 0xF8, 0x7C, 0x30, 0x05, 0x9B, 0x3E, 0x81, 0xB6,
  43931. 0x80, 0x55, 0xB2, 0x4E, 0xA2, 0xFA, 0x98, 0x36,
  43932. 0x86, 0x49, 0x8B, 0xFC, 0x9D, 0x9E, 0x7D, 0x59,
  43933. 0x50, 0x79, 0xEB, 0x64, 0x6E, 0x85, 0xB2, 0x12,
  43934. 0xCE, 0xDD, 0x21, 0xD0, 0x08, 0x7E, 0x0F, 0x2A,
  43935. 0xF6, 0x63, 0xEB, 0x77, 0x2A, 0x98, 0x47, 0xB1,
  43936. 0xDF, 0x21, 0x97, 0xAF, 0x13, 0x62, 0x6B, 0x89,
  43937. 0x7C, 0x24, 0x63, 0x7A, 0xF5, 0xBF, 0xE8, 0x18,
  43938. 0x16, 0xA8, 0xC9, 0x0D, 0x30, 0x48, 0x37, 0x5B,
  43939. 0x69, 0x94, 0x97, 0x14, 0x3E, 0x57, 0x71, 0x85,
  43940. 0xA7, 0x0E, 0x11, 0x50, 0x58, 0xA3, 0xA9, 0x11,
  43941. 0x2B, 0x2C, 0x43, 0x51, 0xB6, 0xCA, 0xD0, 0x09,
  43942. 0x28, 0x2B, 0x4F, 0x7C, 0xB8, 0xBD, 0xFC, 0x28,
  43943. 0x57, 0x77, 0xD7, 0xDF, 0xE8, 0xF5, 0x00, 0x00,
  43944. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  43945. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  43946. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  43947. 0x00, 0x00, 0x00, 0x03, 0x06, 0x0B, 0x11, 0x17,
  43948. 0x1F, 0x27, 0x2E
  43949. };
  43950. #endif
  43951. #endif
  43952. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  43953. ExpectNotNull(key);
  43954. if (key != NULL) {
  43955. XMEMSET(key, 0, sizeof(*key));
  43956. }
  43957. ExpectIntEQ(wc_dilithium_init_ex(key, NULL, INVALID_DEVID), 0);
  43958. #ifndef WOLFSSL_NO_ML_DSA_44
  43959. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  43960. ExpectIntEQ(wc_dilithium_import_public(pk_44, (word32)sizeof(pk_44), key),
  43961. 0);
  43962. ExpectIntEQ(wc_dilithium_verify_msg(sig_44, (word32)sizeof(sig_44), msg_44,
  43963. (word32)sizeof(msg_44), &res, key), 0);
  43964. ExpectIntEQ(res, 1);
  43965. #endif
  43966. #ifndef WOLFSSL_NO_ML_DSA_65
  43967. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  43968. ExpectIntEQ(wc_dilithium_import_public(pk_65, (word32)sizeof(pk_65), key),
  43969. 0);
  43970. ExpectIntEQ(wc_dilithium_verify_msg(sig_65, (word32)sizeof(sig_65), msg_65,
  43971. (word32)sizeof(msg_65), &res, key), 0);
  43972. ExpectIntEQ(res, 1);
  43973. #endif
  43974. #ifndef WOLFSSL_NO_ML_DSA_87
  43975. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  43976. ExpectIntEQ(wc_dilithium_import_public(pk_87, (word32)sizeof(pk_87), key),
  43977. 0);
  43978. ExpectIntEQ(wc_dilithium_verify_msg(sig_87, (word32)sizeof(sig_87), msg_87,
  43979. (word32)sizeof(msg_87), &res, key), 0);
  43980. ExpectIntEQ(res, 1);
  43981. #endif
  43982. wc_dilithium_free(key);
  43983. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  43984. #endif
  43985. return EXPECT_RESULT();
  43986. }
  43987. /*
  43988. * Testing wc_SetSubjectBuffer
  43989. */
  43990. static int test_wc_SetSubjectBuffer(void)
  43991. {
  43992. EXPECT_DECLS;
  43993. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  43994. Cert cert;
  43995. XFILE file = XBADFILE;
  43996. byte* der = NULL;
  43997. word32 derSz;
  43998. derSz = FOURK_BUF;
  43999. ExpectNotNull(der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  44000. DYNAMIC_TYPE_TMP_BUFFER));
  44001. ExpectTrue((file = XFOPEN("./certs/ca-cert.der", "rb")) != XBADFILE);
  44002. ExpectTrue((derSz = (word32)XFREAD(der, 1, FOURK_BUF, file)) > 0);
  44003. if (file != XBADFILE)
  44004. XFCLOSE(file);
  44005. ExpectIntEQ(wc_InitCert(&cert), 0);
  44006. ExpectIntEQ(wc_SetSubjectBuffer(&cert, der, (int)derSz), 0);
  44007. ExpectIntEQ(wc_SetSubjectBuffer(NULL, der, (int)derSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44008. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44009. #endif
  44010. return EXPECT_RESULT();
  44011. } /* End test_wc_SetSubjectBuffer*/
  44012. /*
  44013. * Testing wc_SetSubjectKeyIdFromPublicKey_ex
  44014. */
  44015. static int test_wc_SetSubjectKeyIdFromPublicKey_ex(void)
  44016. {
  44017. EXPECT_DECLS;
  44018. #if defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)
  44019. WC_RNG rng;
  44020. Cert cert;
  44021. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  44022. RsaKey rsaKey;
  44023. int bits = 2048;
  44024. #endif
  44025. #if defined(HAVE_ECC)
  44026. ecc_key eccKey;
  44027. int ret;
  44028. #endif
  44029. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  44030. ed25519_key ed25519Key;
  44031. #endif
  44032. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  44033. ed448_key ed448Key;
  44034. #endif
  44035. #ifndef HAVE_FIPS
  44036. ExpectIntEQ(wc_InitRng_ex(&rng, HEAP_HINT, testDevId), 0);
  44037. #else
  44038. ExpectIntEQ(wc_InitRng(&rng), 0);
  44039. #endif
  44040. ExpectIntEQ(wc_InitCert(&cert), 0);
  44041. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  44042. /* RSA */
  44043. XMEMSET(&rsaKey, 0, sizeof(RsaKey));
  44044. ExpectIntEQ(wc_InitRsaKey(&rsaKey, HEAP_HINT), 0);
  44045. ExpectIntEQ(MAKE_RSA_KEY(&rsaKey, bits, WC_RSA_EXPONENT, &rng), 0);
  44046. ExpectIntEQ(wc_SetSubjectKeyIdFromPublicKey_ex(&cert, RSA_TYPE, &rsaKey),
  44047. 0);
  44048. DoExpectIntEQ(wc_FreeRsaKey(&rsaKey), 0);
  44049. #endif
  44050. #if defined(HAVE_ECC)
  44051. /* ECC */
  44052. XMEMSET(&eccKey, 0, sizeof(ecc_key));
  44053. ExpectIntEQ(wc_ecc_init(&eccKey), 0);
  44054. ret = wc_ecc_make_key(&rng, KEY14, &eccKey);
  44055. #if defined(WOLFSSL_ASYNC_CRYPT)
  44056. ret = wc_AsyncWait(ret, &eccKey.asyncDev, WC_ASYNC_FLAG_NONE);
  44057. #endif
  44058. ExpectIntEQ(ret, 0);
  44059. ExpectIntEQ(wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ECC_TYPE, &eccKey),
  44060. 0);
  44061. DoExpectIntEQ(wc_ecc_free(&eccKey), 0);
  44062. #endif
  44063. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  44064. /* ED25519 */
  44065. XMEMSET(&ed25519Key, 0, sizeof(ed25519_key));
  44066. ExpectIntEQ(wc_ed25519_init(&ed25519Key), 0);
  44067. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &ed25519Key), 0);
  44068. ExpectIntEQ(wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ED25519_TYPE,
  44069. &ed25519Key), 0);
  44070. wc_ed25519_free(&ed25519Key);
  44071. #endif
  44072. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  44073. /* ED448 */
  44074. XMEMSET(&ed448Key, 0, sizeof(ed448_key));
  44075. ExpectIntEQ(wc_ed448_init(&ed448Key), 0);
  44076. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &ed448Key), 0);
  44077. ExpectIntEQ(wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ED448_TYPE,
  44078. &ed448Key), 0);
  44079. wc_ed448_free(&ed448Key);
  44080. #endif
  44081. wc_FreeRng(&rng);
  44082. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  44083. #endif /* WOLFSSL_CERT_EXT && WOLFSSL_CERT_GEN */
  44084. return EXPECT_RESULT();
  44085. } /* End test_wc_SetSubjectKeyIdFromPublicKey_ex*/
  44086. /*
  44087. * Testing wc_SetAuthKeyIdFromPublicKey_ex
  44088. */
  44089. static int test_wc_SetAuthKeyIdFromPublicKey_ex(void)
  44090. {
  44091. EXPECT_DECLS;
  44092. #if defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)
  44093. WC_RNG rng;
  44094. Cert cert;
  44095. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  44096. RsaKey rsaKey;
  44097. int bits = 2048;
  44098. #endif
  44099. #if defined(HAVE_ECC)
  44100. ecc_key eccKey;
  44101. int ret;
  44102. #endif
  44103. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  44104. ed25519_key ed25519Key;
  44105. #endif
  44106. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  44107. ed448_key ed448Key;
  44108. #endif
  44109. #ifndef HAVE_FIPS
  44110. ExpectIntEQ(wc_InitRng_ex(&rng, HEAP_HINT, testDevId), 0);
  44111. #else
  44112. ExpectIntEQ(wc_InitRng(&rng), 0);
  44113. #endif
  44114. ExpectIntEQ(wc_InitCert(&cert), 0);
  44115. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  44116. /* RSA */
  44117. XMEMSET(&rsaKey, 0, sizeof(RsaKey));
  44118. ExpectIntEQ(wc_InitRsaKey(&rsaKey, HEAP_HINT), 0);
  44119. ExpectIntEQ(MAKE_RSA_KEY(&rsaKey, bits, WC_RSA_EXPONENT, &rng), 0);
  44120. ExpectIntEQ(wc_SetAuthKeyIdFromPublicKey_ex(&cert, RSA_TYPE, &rsaKey), 0);
  44121. DoExpectIntEQ(wc_FreeRsaKey(&rsaKey), 0);
  44122. #endif
  44123. #if defined(HAVE_ECC)
  44124. /* ECC */
  44125. XMEMSET(&eccKey, 0, sizeof(ecc_key));
  44126. ExpectIntEQ(wc_ecc_init(&eccKey), 0);
  44127. ret = wc_ecc_make_key(&rng, KEY14, &eccKey);
  44128. #if defined(WOLFSSL_ASYNC_CRYPT)
  44129. ret = wc_AsyncWait(ret, &eccKey.asyncDev, WC_ASYNC_FLAG_NONE);
  44130. #endif
  44131. ExpectIntEQ(ret, 0);
  44132. ExpectIntEQ(wc_SetAuthKeyIdFromPublicKey_ex(&cert, ECC_TYPE, &eccKey), 0);
  44133. DoExpectIntEQ(wc_ecc_free(&eccKey), 0);
  44134. #endif
  44135. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  44136. /* ED25519 */
  44137. XMEMSET(&ed25519Key, 0, sizeof(ed25519_key));
  44138. ExpectIntEQ(wc_ed25519_init(&ed25519Key), 0);
  44139. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &ed25519Key), 0);
  44140. ExpectIntEQ(wc_SetAuthKeyIdFromPublicKey_ex(&cert, ED25519_TYPE,
  44141. &ed25519Key), 0);
  44142. wc_ed25519_free(&ed25519Key);
  44143. #endif
  44144. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  44145. /* ED448 */
  44146. XMEMSET(&ed448Key, 0, sizeof(ed448_key));
  44147. ExpectIntEQ(wc_ed448_init(&ed448Key), 0);
  44148. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &ed448Key), 0);
  44149. ExpectIntEQ(wc_SetAuthKeyIdFromPublicKey_ex(&cert, ED448_TYPE, &ed448Key),
  44150. 0);
  44151. wc_ed448_free(&ed448Key);
  44152. #endif
  44153. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  44154. #endif /* defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)*/
  44155. return EXPECT_RESULT();
  44156. } /* End test_wc_SetAuthKeyIdFromPublicKey_ex*/
  44157. /*
  44158. * Testing wc_PKCS7_New()
  44159. */
  44160. static int test_wc_PKCS7_New(void)
  44161. {
  44162. EXPECT_DECLS;
  44163. #if defined(HAVE_PKCS7)
  44164. PKCS7* pkcs7 = NULL;
  44165. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, testDevId));
  44166. wc_PKCS7_Free(pkcs7);
  44167. #endif
  44168. return EXPECT_RESULT();
  44169. } /* END test-wc_PKCS7_New */
  44170. /*
  44171. * Testing wc_PKCS7_Init()
  44172. */
  44173. static int test_wc_PKCS7_Init(void)
  44174. {
  44175. EXPECT_DECLS;
  44176. #if defined(HAVE_PKCS7)
  44177. PKCS7* pkcs7 = NULL;
  44178. void* heap = NULL;
  44179. ExpectNotNull(pkcs7 = wc_PKCS7_New(heap, testDevId));
  44180. ExpectIntEQ(wc_PKCS7_Init(pkcs7, heap, testDevId), 0);
  44181. /* Pass in bad args. */
  44182. ExpectIntEQ(wc_PKCS7_Init(NULL, heap, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44183. wc_PKCS7_Free(pkcs7);
  44184. #endif
  44185. return EXPECT_RESULT();
  44186. } /* END test-wc_PKCS7_Init */
  44187. /*
  44188. * Testing wc_PKCS7_InitWithCert()
  44189. */
  44190. static int test_wc_PKCS7_InitWithCert(void)
  44191. {
  44192. EXPECT_DECLS;
  44193. #if defined(HAVE_PKCS7)
  44194. PKCS7* pkcs7 = NULL;
  44195. #ifndef NO_RSA
  44196. #if defined(USE_CERT_BUFFERS_2048)
  44197. unsigned char cert[sizeof(client_cert_der_2048)];
  44198. int certSz = (int)sizeof(cert);
  44199. XMEMSET(cert, 0, certSz);
  44200. XMEMCPY(cert, client_cert_der_2048, sizeof(client_cert_der_2048));
  44201. #elif defined(USE_CERT_BUFFERS_1024)
  44202. unsigned char cert[sizeof(client_cert_der_1024)];
  44203. int certSz = (int)sizeof(cert);
  44204. XMEMSET(cert, 0, certSz);
  44205. XMEMCPY(cert, client_cert_der_1024, sizeof_client_cert_der_1024);
  44206. #else
  44207. unsigned char cert[ONEK_BUF];
  44208. XFILE fp = XBADFILE;
  44209. int certSz;
  44210. ExpectTrue((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) !=
  44211. XBADFILE);
  44212. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_client_cert_der_1024,
  44213. fp), 0);
  44214. if (fp != XBADFILE)
  44215. XFCLOSE(fp);
  44216. #endif
  44217. #elif defined(HAVE_ECC)
  44218. #if defined(USE_CERT_BUFFERS_256)
  44219. unsigned char cert[sizeof(cliecc_cert_der_256)];
  44220. int certSz = (int)sizeof(cert);
  44221. XMEMSET(cert, 0, certSz);
  44222. XMEMCPY(cert, cliecc_cert_der_256, sizeof(cliecc_cert_der_256));
  44223. #else
  44224. unsigned char cert[ONEK_BUF];
  44225. XFILE fp = XBADFILE;
  44226. int certSz;
  44227. ExpectTrue((fp = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  44228. XBADFILE);
  44229. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof(cliecc_cert_der_256),
  44230. fp), 0);
  44231. if (fp != XBADFILE)
  44232. XFCLOSE(fp);
  44233. #endif
  44234. #else
  44235. #error PKCS7 requires ECC or RSA
  44236. #endif
  44237. #ifdef HAVE_ECC
  44238. {
  44239. /* bad test case from ZD 11011, malformed cert gives bad ECC key */
  44240. static unsigned char certWithInvalidEccKey[] = {
  44241. 0x30, 0x82, 0x03, 0x5F, 0x30, 0x82, 0x03, 0x04, 0xA0, 0x03, 0x02, 0x01,
  44242. 0x02, 0x02, 0x14, 0x61, 0xB3, 0x1E, 0x59, 0xF3, 0x68, 0x6C, 0xA4, 0x79,
  44243. 0x42, 0x83, 0x2F, 0x1A, 0x50, 0x71, 0x03, 0xBE, 0x31, 0xAA, 0x2C, 0x30,
  44244. 0x0A, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x02, 0x30,
  44245. 0x81, 0x8D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13,
  44246. 0x02, 0x55, 0x53, 0x31, 0x0F, 0x30, 0x0D, 0x06, 0x03, 0x55, 0x04, 0x08,
  44247. 0x0C, 0x06, 0x4F, 0x72, 0x65, 0x67, 0x6F, 0x6E, 0x31, 0x0E, 0x30, 0x0C,
  44248. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0C, 0x05, 0x53, 0x61, 0x6C, 0x65, 0x6D,
  44249. 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x0A, 0x43,
  44250. 0x6C, 0x69, 0x65, 0x6E, 0x74, 0x20, 0x45, 0x43, 0x43, 0x31, 0x0D, 0x30,
  44251. 0x0B, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x04, 0x46, 0x61, 0x73, 0x74,
  44252. 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x77,
  44253. 0x77, 0x77, 0x2E, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63,
  44254. 0x6F, 0x6D, 0x31, 0x1F, 0x30, 0x1D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86,
  44255. 0xF7, 0x0D, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40,
  44256. 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x30,
  44257. 0x1E, 0x17, 0x0D, 0x32, 0x30, 0x30, 0x36, 0x31, 0x39, 0x31, 0x33, 0x32,
  44258. 0x33, 0x34, 0x31, 0x5A, 0x17, 0x0D, 0x32, 0x33, 0x30, 0x33, 0x31, 0x36,
  44259. 0x31, 0x33, 0x32, 0x33, 0x34, 0x31, 0x5A, 0x30, 0x81, 0x8D, 0x31, 0x0B,
  44260. 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31,
  44261. 0x0F, 0x30, 0x0D, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0C, 0x06, 0x4F, 0x72,
  44262. 0x65, 0x67, 0x6F, 0x6E, 0x31, 0x0E, 0x30, 0x0C, 0x06, 0x03, 0x55, 0x04,
  44263. 0x07, 0x0C, 0x05, 0x53, 0x61, 0x6C, 0x65, 0x6D, 0x31, 0x13, 0x30, 0x11,
  44264. 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x0A, 0x43, 0x6C, 0x69, 0x65, 0x6E,
  44265. 0x74, 0x20, 0x45, 0x43, 0x43, 0x31, 0x0D, 0x30, 0x0B, 0x06, 0x03, 0x55,
  44266. 0x04, 0x0B, 0x0C, 0x04, 0x46, 0x61, 0x73, 0x74, 0x31, 0x18, 0x30, 0x26,
  44267. 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x77, 0x77, 0x77, 0x2E, 0x77,
  44268. 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x31, 0x1F,
  44269. 0x30, 0x1D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09,
  44270. 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40, 0x77, 0x6F, 0x6C, 0x66,
  44271. 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x30, 0x59, 0x30, 0x13, 0x06,
  44272. 0x07, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x02, 0x01, 0x06, 0x08, 0x2A, 0x86,
  44273. 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07, 0x03, 0x02, 0x00, 0x04, 0x55, 0xBF,
  44274. 0xF4, 0x0F, 0x44, 0x50, 0x9A, 0x3D, 0xCE, 0x9B, 0xB7, 0xF0, 0xC5, 0x4D,
  44275. 0xF5, 0x70, 0x7B, 0xD4, 0xEC, 0x24, 0x8E, 0x19, 0x80, 0xEC, 0x5A, 0x4C,
  44276. 0xA2, 0x24, 0x03, 0x62, 0x2C, 0x9B, 0xDA, 0xEF, 0xA2, 0x35, 0x12, 0x43,
  44277. 0x84, 0x76, 0x16, 0xC6, 0x56, 0x95, 0x06, 0xCC, 0x01, 0xA9, 0xBD, 0xF6,
  44278. 0x75, 0x1A, 0x42, 0xF7, 0xBD, 0xA9, 0xB2, 0x36, 0x22, 0x5F, 0xC7, 0x5D,
  44279. 0x7F, 0xB4, 0xA3, 0x82, 0x01, 0x3E, 0x30, 0x82, 0x01, 0x3A, 0x30, 0x1D,
  44280. 0x06, 0x03, 0x55, 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0xEB, 0xD4, 0x4B,
  44281. 0x59, 0x6B, 0x95, 0x61, 0x3F, 0x51, 0x57, 0xB6, 0x04, 0x4D, 0x89, 0x41,
  44282. 0x88, 0x44, 0x5C, 0xAB, 0xF2, 0x30, 0x81, 0xCD, 0x06, 0x03, 0x55, 0x1D,
  44283. 0x23, 0x04, 0x81, 0xC5, 0x30, 0x81, 0xC2, 0x80, 0x14, 0xEB, 0xD4, 0x4B,
  44284. 0x59, 0x72, 0x95, 0x61, 0x3F, 0x51, 0x57, 0xB6, 0x04, 0x4D, 0x89, 0x41,
  44285. 0x88, 0x44, 0x5C, 0xAB, 0xF2, 0xA1, 0x81, 0x93, 0xA4, 0x81, 0x90, 0x30,
  44286. 0x81, 0x8D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13,
  44287. 0x02, 0x55, 0x53, 0x31, 0x0F, 0x30, 0x0D, 0x06, 0x03, 0x55, 0x08, 0x08,
  44288. 0x0C, 0x06, 0x4F, 0x72, 0x65, 0x67, 0x6F, 0x6E, 0x31, 0x0E, 0x30, 0x0C,
  44289. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0C, 0x05, 0x53, 0x61, 0x6C, 0x65, 0x6D,
  44290. 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x0A, 0x43,
  44291. 0x6C, 0x69, 0x65, 0x6E, 0x74, 0x20, 0x45, 0x43, 0x43, 0x31, 0x0D, 0x30,
  44292. 0x0B, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x04, 0x46, 0x61, 0x73, 0x74,
  44293. 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x77,
  44294. 0x77, 0x77, 0x2E, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63,
  44295. 0x6F, 0x6D, 0x30, 0x1F, 0x30, 0x1D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86,
  44296. 0xF7, 0x0D, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40,
  44297. 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x82,
  44298. 0x14, 0x61, 0xB3, 0x1E, 0x59, 0xF3, 0x68, 0x6C, 0xA4, 0x79, 0x42, 0x83,
  44299. 0x2F, 0x1A, 0x50, 0x71, 0x03, 0xBE, 0x32, 0xAA, 0x2C, 0x30, 0x0C, 0x06,
  44300. 0x03, 0x55, 0x1D, 0x13, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xFF, 0x30,
  44301. 0x1C, 0x06, 0x03, 0x55, 0x1D, 0x11, 0x04, 0x15, 0x30, 0x13, 0x82, 0x0B,
  44302. 0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x2E, 0x63, 0x6F, 0x6D, 0x87,
  44303. 0x04, 0x23, 0x00, 0x00, 0x01, 0x30, 0x1D, 0x06, 0x03, 0x55, 0x1D, 0x25,
  44304. 0x04, 0x16, 0x30, 0x14, 0x06, 0x08, 0x2B, 0x06, 0x01, 0x05, 0x05, 0x07,
  44305. 0x03, 0x01, 0x06, 0x08, 0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x02,
  44306. 0x30, 0x0A, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x02,
  44307. 0x03, 0x49, 0x00, 0x30, 0x46, 0x02, 0x21, 0x00, 0xE4, 0xA0, 0x23, 0x26,
  44308. 0x2B, 0x0B, 0x42, 0x0F, 0x97, 0x37, 0x6D, 0xCB, 0x14, 0x23, 0xC3, 0xC3,
  44309. 0xE6, 0x44, 0xCF, 0x5F, 0x4C, 0x26, 0xA3, 0x72, 0x64, 0x7A, 0x9C, 0xCB,
  44310. 0x64, 0xAB, 0xA6, 0xBE, 0x02, 0x21, 0x00, 0xAA, 0xC5, 0xA3, 0x50, 0xF6,
  44311. 0xF1, 0xA5, 0xDB, 0x05, 0xE0, 0x75, 0xD2, 0xF7, 0xBA, 0x49, 0x5F, 0x8F,
  44312. 0x7D, 0x1C, 0x44, 0xB1, 0x6E, 0xDF, 0xC8, 0xDA, 0x10, 0x48, 0x2D, 0x53,
  44313. 0x08, 0xA8, 0xB4
  44314. };
  44315. #endif
  44316. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44317. /* If initialization is not successful, it's free'd in init func. */
  44318. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (byte*)cert, (word32)certSz),
  44319. 0);
  44320. wc_PKCS7_Free(pkcs7);
  44321. pkcs7 = NULL;
  44322. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44323. /* Valid initialization usage. */
  44324. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44325. /* Pass in bad args. No need free for null checks, free at end.*/
  44326. ExpectIntEQ(wc_PKCS7_InitWithCert(NULL, (byte*)cert, (word32)certSz),
  44327. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44328. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, (word32)certSz),
  44329. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44330. #ifdef HAVE_ECC
  44331. ExpectIntLT(wc_PKCS7_InitWithCert(pkcs7, certWithInvalidEccKey,
  44332. sizeof(certWithInvalidEccKey)), 0);
  44333. }
  44334. #endif
  44335. wc_PKCS7_Free(pkcs7);
  44336. #endif
  44337. return EXPECT_RESULT();
  44338. } /* END test_wc_PKCS7_InitWithCert */
  44339. /*
  44340. * Testing wc_PKCS7_EncodeData()
  44341. */
  44342. static int test_wc_PKCS7_EncodeData(void)
  44343. {
  44344. EXPECT_DECLS;
  44345. #if defined(HAVE_PKCS7)
  44346. PKCS7* pkcs7 = NULL;
  44347. byte output[FOURK_BUF];
  44348. byte data[] = "My encoded DER cert.";
  44349. #ifndef NO_RSA
  44350. #if defined(USE_CERT_BUFFERS_2048)
  44351. unsigned char cert[sizeof(client_cert_der_2048)];
  44352. unsigned char key[sizeof(client_key_der_2048)];
  44353. int certSz = (int)sizeof(cert);
  44354. int keySz = (int)sizeof(key);
  44355. XMEMSET(cert, 0, certSz);
  44356. XMEMSET(key, 0, keySz);
  44357. XMEMCPY(cert, client_cert_der_2048, certSz);
  44358. XMEMCPY(key, client_key_der_2048, keySz);
  44359. #elif defined(USE_CERT_BUFFERS_1024)
  44360. unsigned char cert[sizeof(sizeof_client_cert_der_1024)];
  44361. unsigned char key[sizeof_client_key_der_1024];
  44362. int certSz = (int)sizeof(cert);
  44363. int keySz = (int)sizeof(key);
  44364. XMEMSET(cert, 0, certSz);
  44365. XMEMSET(key, 0, keySz);
  44366. XMEMCPY(cert, client_cert_der_1024, certSz);
  44367. XMEMCPY(key, client_key_der_1024, keySz);
  44368. #else
  44369. unsigned char cert[ONEK_BUF];
  44370. unsigned char key[ONEK_BUF];
  44371. XFILE fp = XBADFILE;
  44372. int certSz;
  44373. int keySz;
  44374. ExpectTrue((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) !=
  44375. XBADFILE);
  44376. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_client_cert_der_1024,
  44377. fp), 0);
  44378. if (fp != XBADFILE) {
  44379. XFCLOSE(fp);
  44380. fp = XBADFILE;
  44381. }
  44382. ExpectTrue((fp = XFOPEN("./certs/1024/client-key.der", "rb")) !=
  44383. XBADFILE);
  44384. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_client_key_der_1024, fp),
  44385. 0);
  44386. if (fp != XBADFILE)
  44387. XFCLOSE(fp);
  44388. #endif
  44389. #elif defined(HAVE_ECC)
  44390. #if defined(USE_CERT_BUFFERS_256)
  44391. unsigned char cert[sizeof(cliecc_cert_der_256)];
  44392. unsigned char key[sizeof(ecc_clikey_der_256)];
  44393. int certSz = (int)sizeof(cert);
  44394. int keySz = (int)sizeof(key);
  44395. XMEMSET(cert, 0, certSz);
  44396. XMEMSET(key, 0, keySz);
  44397. XMEMCPY(cert, cliecc_cert_der_256, sizeof_cliecc_cert_der_256);
  44398. XMEMCPY(key, ecc_clikey_der_256, sizeof_ecc_clikey_der_256);
  44399. #else
  44400. unsigned char cert[ONEK_BUF];
  44401. unsigned char key[ONEK_BUF];
  44402. XFILE fp = XBADFILE;
  44403. int certSz, keySz;
  44404. ExpectTrue((fp = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  44405. XBADFILE);
  44406. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_cliecc_cert_der_256,
  44407. fp), 0);
  44408. if (fp != XBADFILE) {
  44409. XFCLOSE(fp);
  44410. fp = XBADFILE;
  44411. }
  44412. ExpectTrue((fp = XFOPEN("./certs/client-ecc-key.der", "rb")) !=
  44413. XBADFILE);
  44414. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_ecc_clikey_der_256, fp),
  44415. 0);
  44416. if (fp != XBADFILE)
  44417. XFCLOSE(fp);
  44418. #endif
  44419. #endif
  44420. XMEMSET(output, 0, sizeof(output));
  44421. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44422. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  44423. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (byte*)cert, (word32)certSz), 0);
  44424. if (pkcs7 != NULL) {
  44425. pkcs7->content = data;
  44426. pkcs7->contentSz = sizeof(data);
  44427. pkcs7->privateKey = key;
  44428. pkcs7->privateKeySz = (word32)keySz;
  44429. }
  44430. ExpectIntGT(wc_PKCS7_EncodeData(pkcs7, output, (word32)sizeof(output)), 0);
  44431. /* Test bad args. */
  44432. ExpectIntEQ(wc_PKCS7_EncodeData(NULL, output, (word32)sizeof(output)),
  44433. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44434. ExpectIntEQ(wc_PKCS7_EncodeData(pkcs7, NULL, (word32)sizeof(output)),
  44435. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44436. ExpectIntEQ(wc_PKCS7_EncodeData(pkcs7, output, 5), WC_NO_ERR_TRACE(BUFFER_E));
  44437. wc_PKCS7_Free(pkcs7);
  44438. #endif
  44439. return EXPECT_RESULT();
  44440. } /* END test_wc_PKCS7_EncodeData */
  44441. #if defined(HAVE_PKCS7) && defined(HAVE_PKCS7_RSA_RAW_SIGN_CALLBACK) && \
  44442. !defined(NO_RSA) && !defined(NO_SHA256)
  44443. /* RSA sign raw digest callback */
  44444. static int rsaSignRawDigestCb(PKCS7* pkcs7, byte* digest, word32 digestSz,
  44445. byte* out, word32 outSz, byte* privateKey,
  44446. word32 privateKeySz, int devid, int hashOID)
  44447. {
  44448. /* specific DigestInfo ASN.1 encoding prefix for a SHA2565 digest */
  44449. byte digInfoEncoding[] = {
  44450. 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
  44451. 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05,
  44452. 0x00, 0x04, 0x20
  44453. };
  44454. int ret;
  44455. byte digestInfo[ONEK_BUF];
  44456. byte sig[FOURK_BUF];
  44457. word32 digestInfoSz = 0;
  44458. word32 idx = 0;
  44459. RsaKey rsa;
  44460. /* SHA-256 required only for this example callback due to above
  44461. * digInfoEncoding[] */
  44462. if (pkcs7 == NULL || digest == NULL || out == NULL ||
  44463. (sizeof(digestInfo) < sizeof(digInfoEncoding) + digestSz) ||
  44464. (hashOID != SHA256h)) {
  44465. return -1;
  44466. }
  44467. /* build DigestInfo */
  44468. XMEMCPY(digestInfo, digInfoEncoding, sizeof(digInfoEncoding));
  44469. digestInfoSz += sizeof(digInfoEncoding);
  44470. XMEMCPY(digestInfo + digestInfoSz, digest, digestSz);
  44471. digestInfoSz += digestSz;
  44472. /* set up RSA key */
  44473. ret = wc_InitRsaKey_ex(&rsa, pkcs7->heap, devid);
  44474. if (ret != 0) {
  44475. return ret;
  44476. }
  44477. ret = wc_RsaPrivateKeyDecode(privateKey, &idx, &rsa, privateKeySz);
  44478. /* sign DigestInfo */
  44479. if (ret == 0) {
  44480. ret = wc_RsaSSL_Sign(digestInfo, digestInfoSz, sig, sizeof(sig),
  44481. &rsa, pkcs7->rng);
  44482. if (ret > 0) {
  44483. if (ret > (int)outSz) {
  44484. /* output buffer too small */
  44485. ret = -1;
  44486. }
  44487. else {
  44488. /* success, ret holds sig size */
  44489. XMEMCPY(out, sig, ret);
  44490. }
  44491. }
  44492. }
  44493. wc_FreeRsaKey(&rsa);
  44494. return ret;
  44495. }
  44496. #endif
  44497. #if defined(HAVE_PKCS7) && defined(ASN_BER_TO_DER)
  44498. typedef struct encodeSignedDataStream {
  44499. byte out[FOURK_BUF*3];
  44500. int idx;
  44501. word32 outIdx;
  44502. } encodeSignedDataStream;
  44503. /* content is 8k of partially created bundle */
  44504. static int GetContentCB(PKCS7* pkcs7, byte** content, void* ctx)
  44505. {
  44506. int ret = 0;
  44507. encodeSignedDataStream* strm = (encodeSignedDataStream*)ctx;
  44508. if (strm->outIdx < pkcs7->contentSz) {
  44509. ret = (pkcs7->contentSz > strm->outIdx + FOURK_BUF)?
  44510. FOURK_BUF : pkcs7->contentSz - strm->outIdx;
  44511. *content = strm->out + strm->outIdx;
  44512. strm->outIdx += ret;
  44513. }
  44514. (void)pkcs7;
  44515. return ret;
  44516. }
  44517. static int StreamOutputCB(PKCS7* pkcs7, const byte* output, word32 outputSz,
  44518. void* ctx)
  44519. {
  44520. encodeSignedDataStream* strm = (encodeSignedDataStream*)ctx;
  44521. XMEMCPY(strm->out + strm->idx, output, outputSz);
  44522. strm->idx += outputSz;
  44523. (void)pkcs7;
  44524. return 0;
  44525. }
  44526. #endif
  44527. /*
  44528. * Testing wc_PKCS7_EncodeSignedData()
  44529. */
  44530. static int test_wc_PKCS7_EncodeSignedData(void)
  44531. {
  44532. EXPECT_DECLS;
  44533. #if defined(HAVE_PKCS7)
  44534. PKCS7* pkcs7 = NULL;
  44535. WC_RNG rng;
  44536. byte output[FOURK_BUF];
  44537. byte badOut[1];
  44538. word32 outputSz = (word32)sizeof(output);
  44539. word32 badOutSz = 0;
  44540. byte data[] = "Test data to encode.";
  44541. #ifndef NO_RSA
  44542. #if defined(USE_CERT_BUFFERS_2048)
  44543. byte key[sizeof(client_key_der_2048)];
  44544. byte cert[sizeof(client_cert_der_2048)];
  44545. word32 keySz = (word32)sizeof(key);
  44546. word32 certSz = (word32)sizeof(cert);
  44547. XMEMSET(key, 0, keySz);
  44548. XMEMSET(cert, 0, certSz);
  44549. XMEMCPY(key, client_key_der_2048, keySz);
  44550. XMEMCPY(cert, client_cert_der_2048, certSz);
  44551. #elif defined(USE_CERT_BUFFERS_1024)
  44552. byte key[sizeof_client_key_der_1024];
  44553. byte cert[sizeof(sizeof_client_cert_der_1024)];
  44554. word32 keySz = (word32)sizeof(key);
  44555. word32 certSz = (word32)sizeof(cert);
  44556. XMEMSET(key, 0, keySz);
  44557. XMEMSET(cert, 0, certSz);
  44558. XMEMCPY(key, client_key_der_1024, keySz);
  44559. XMEMCPY(cert, client_cert_der_1024, certSz);
  44560. #else
  44561. unsigned char cert[ONEK_BUF];
  44562. unsigned char key[ONEK_BUF];
  44563. XFILE fp = XBADFILE;
  44564. int certSz;
  44565. int keySz;
  44566. ExpectTrue((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) !=
  44567. XBADFILE);
  44568. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_client_cert_der_1024,
  44569. fp), 0);
  44570. if (fp != XBADFILE) {
  44571. XFCLOSE(fp);
  44572. fp = XBADFILE;
  44573. }
  44574. ExpectTrue((fp = XFOPEN("./certs/1024/client-key.der", "rb")) !=
  44575. XBADFILE);
  44576. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_client_key_der_1024, fp),
  44577. 0);
  44578. if (fp != XBADFILE)
  44579. XFCLOSE(fp);
  44580. #endif
  44581. #elif defined(HAVE_ECC)
  44582. #if defined(USE_CERT_BUFFERS_256)
  44583. unsigned char cert[sizeof(cliecc_cert_der_256)];
  44584. unsigned char key[sizeof(ecc_clikey_der_256)];
  44585. int certSz = (int)sizeof(cert);
  44586. int keySz = (int)sizeof(key);
  44587. XMEMSET(cert, 0, certSz);
  44588. XMEMSET(key, 0, keySz);
  44589. XMEMCPY(cert, cliecc_cert_der_256, certSz);
  44590. XMEMCPY(key, ecc_clikey_der_256, keySz);
  44591. #else
  44592. unsigned char cert[ONEK_BUF];
  44593. unsigned char key[ONEK_BUF];
  44594. XFILE fp = XBADFILE;
  44595. int certSz;
  44596. int keySz;
  44597. ExpectTrue((fp = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  44598. XBADFILE);
  44599. ExpectIntGT(certSz = (int)XFREAD(cert, 1, ONEK_BUF, fp), 0);
  44600. if (fp != XBADFILE) {
  44601. XFCLOSE(fp);
  44602. fp = XBADFILE;
  44603. }
  44604. ExpectTrue((fp = XFOPEN("./certs/client-ecc-key.der", "rb")) !=
  44605. XBADFILE);
  44606. ExpectIntGT(keySz = (int)XFREAD(key, 1, ONEK_BUF, fp), 0);
  44607. if (fp != XBADFILE)
  44608. XFCLOSE(fp);
  44609. #endif
  44610. #endif
  44611. XMEMSET(&rng, 0, sizeof(WC_RNG));
  44612. XMEMSET(output, 0, outputSz);
  44613. ExpectIntEQ(wc_InitRng(&rng), 0);
  44614. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44615. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  44616. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  44617. if (pkcs7 != NULL) {
  44618. pkcs7->content = data;
  44619. pkcs7->contentSz = (word32)sizeof(data);
  44620. pkcs7->privateKey = key;
  44621. pkcs7->privateKeySz = (word32)sizeof(key);
  44622. pkcs7->encryptOID = RSAk;
  44623. #ifdef NO_SHA
  44624. pkcs7->hashOID = SHA256h;
  44625. #else
  44626. pkcs7->hashOID = SHAh;
  44627. #endif
  44628. pkcs7->rng = &rng;
  44629. }
  44630. ExpectIntGT(wc_PKCS7_EncodeSignedData(pkcs7, output, outputSz), 0);
  44631. wc_PKCS7_Free(pkcs7);
  44632. pkcs7 = NULL;
  44633. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44634. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44635. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  44636. #ifdef ASN_BER_TO_DER
  44637. wc_PKCS7_Free(pkcs7);
  44638. /* reinitialize and test setting stream mode */
  44639. {
  44640. int signedSz = 0;
  44641. encodeSignedDataStream strm;
  44642. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44643. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  44644. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  44645. if (pkcs7 != NULL) {
  44646. pkcs7->content = data;
  44647. pkcs7->contentSz = (word32)sizeof(data);
  44648. pkcs7->privateKey = key;
  44649. pkcs7->privateKeySz = (word32)sizeof(key);
  44650. pkcs7->encryptOID = RSAk;
  44651. #ifdef NO_SHA
  44652. pkcs7->hashOID = SHA256h;
  44653. #else
  44654. pkcs7->hashOID = SHAh;
  44655. #endif
  44656. pkcs7->rng = &rng;
  44657. }
  44658. ExpectIntEQ(wc_PKCS7_GetStreamMode(pkcs7), 0);
  44659. ExpectIntEQ(wc_PKCS7_SetStreamMode(pkcs7, 1, NULL, NULL, NULL), 0);
  44660. ExpectIntEQ(wc_PKCS7_SetStreamMode(NULL, 1, NULL, NULL, NULL),
  44661. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44662. ExpectIntEQ(wc_PKCS7_GetStreamMode(pkcs7), 1);
  44663. ExpectIntGT(signedSz = wc_PKCS7_EncodeSignedData(pkcs7, output,
  44664. outputSz), 0);
  44665. wc_PKCS7_Free(pkcs7);
  44666. pkcs7 = NULL;
  44667. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44668. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44669. /* use exact signed buffer size since BER encoded */
  44670. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, (word32)signedSz), 0);
  44671. wc_PKCS7_Free(pkcs7);
  44672. /* now try with using callbacks for IO */
  44673. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44674. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  44675. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  44676. if (pkcs7 != NULL) {
  44677. pkcs7->contentSz = FOURK_BUF*2;
  44678. pkcs7->privateKey = key;
  44679. pkcs7->privateKeySz = (word32)sizeof(key);
  44680. pkcs7->encryptOID = RSAk;
  44681. #ifdef NO_SHA
  44682. pkcs7->hashOID = SHA256h;
  44683. #else
  44684. pkcs7->hashOID = SHAh;
  44685. #endif
  44686. pkcs7->rng = &rng;
  44687. }
  44688. XMEMSET(&strm, 0, sizeof(strm));
  44689. ExpectIntEQ(wc_PKCS7_SetStreamMode(pkcs7, 1, GetContentCB,
  44690. StreamOutputCB, (void*)&strm), 0);
  44691. ExpectIntGT(signedSz = wc_PKCS7_EncodeSignedData(pkcs7, NULL, 0), 0);
  44692. wc_PKCS7_Free(pkcs7);
  44693. pkcs7 = NULL;
  44694. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44695. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44696. /* use exact signed buffer size since BER encoded */
  44697. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, strm.out, (word32)signedSz), 0);
  44698. }
  44699. #endif
  44700. #ifndef NO_PKCS7_STREAM
  44701. wc_PKCS7_Free(pkcs7);
  44702. pkcs7 = NULL;
  44703. {
  44704. word32 z;
  44705. int ret;
  44706. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44707. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44708. /* test for streaming mode */
  44709. ret = -1;
  44710. for (z = 0; z < outputSz && ret != 0; z++) {
  44711. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  44712. if (ret < 0){
  44713. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  44714. }
  44715. }
  44716. ExpectIntEQ(ret, 0);
  44717. ExpectIntNE(pkcs7->contentSz, 0);
  44718. ExpectNotNull(pkcs7->contentDynamic);
  44719. }
  44720. #endif /* !NO_PKCS7_STREAM */
  44721. /* Pass in bad args. */
  44722. ExpectIntEQ(wc_PKCS7_EncodeSignedData(NULL, output, outputSz),
  44723. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44724. ExpectIntEQ(wc_PKCS7_EncodeSignedData(pkcs7, NULL, outputSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44725. ExpectIntEQ(wc_PKCS7_EncodeSignedData(pkcs7, badOut,
  44726. badOutSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44727. if (pkcs7 != NULL) {
  44728. pkcs7->hashOID = 0; /* bad hashOID */
  44729. }
  44730. ExpectIntEQ(wc_PKCS7_EncodeSignedData(pkcs7, output, outputSz),
  44731. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44732. #if defined(HAVE_PKCS7) && defined(HAVE_PKCS7_RSA_RAW_SIGN_CALLBACK) && \
  44733. !defined(NO_RSA) && !defined(NO_SHA256)
  44734. /* test RSA sign raw digest callback, if using RSA and compiled in.
  44735. * Example callback assumes SHA-256, so only run test if compiled in. */
  44736. wc_PKCS7_Free(pkcs7);
  44737. pkcs7 = NULL;
  44738. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44739. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  44740. if (pkcs7 != NULL) {
  44741. pkcs7->content = data;
  44742. pkcs7->contentSz = (word32)sizeof(data);
  44743. pkcs7->privateKey = key;
  44744. pkcs7->privateKeySz = (word32)sizeof(key);
  44745. pkcs7->encryptOID = RSAk;
  44746. pkcs7->hashOID = SHA256h;
  44747. pkcs7->rng = &rng;
  44748. }
  44749. ExpectIntEQ(wc_PKCS7_SetRsaSignRawDigestCb(pkcs7, rsaSignRawDigestCb), 0);
  44750. ExpectIntGT(wc_PKCS7_EncodeSignedData(pkcs7, output, outputSz), 0);
  44751. #endif
  44752. wc_PKCS7_Free(pkcs7);
  44753. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  44754. #endif
  44755. return EXPECT_RESULT();
  44756. } /* END test_wc_PKCS7_EncodeSignedData */
  44757. /*
  44758. * Testing wc_PKCS7_EncodeSignedData_ex() and wc_PKCS7_VerifySignedData_ex()
  44759. */
  44760. static int test_wc_PKCS7_EncodeSignedData_ex(void)
  44761. {
  44762. EXPECT_DECLS;
  44763. #if defined(HAVE_PKCS7)
  44764. int i;
  44765. PKCS7* pkcs7 = NULL;
  44766. WC_RNG rng;
  44767. byte outputHead[FOURK_BUF/2];
  44768. byte outputFoot[FOURK_BUF/2];
  44769. word32 outputHeadSz = (word32)sizeof(outputHead);
  44770. word32 outputFootSz = (word32)sizeof(outputFoot);
  44771. byte data[FOURK_BUF];
  44772. wc_HashAlg hash;
  44773. #ifdef NO_SHA
  44774. enum wc_HashType hashType = WC_HASH_TYPE_SHA256;
  44775. #else
  44776. enum wc_HashType hashType = WC_HASH_TYPE_SHA;
  44777. #endif
  44778. byte hashBuf[WC_MAX_DIGEST_SIZE];
  44779. word32 hashSz = (word32)wc_HashGetDigestSize(hashType);
  44780. #ifndef NO_RSA
  44781. #if defined(USE_CERT_BUFFERS_2048)
  44782. byte key[sizeof(client_key_der_2048)];
  44783. byte cert[sizeof(client_cert_der_2048)];
  44784. word32 keySz = (word32)sizeof(key);
  44785. word32 certSz = (word32)sizeof(cert);
  44786. XMEMSET(key, 0, keySz);
  44787. XMEMSET(cert, 0, certSz);
  44788. XMEMCPY(key, client_key_der_2048, keySz);
  44789. XMEMCPY(cert, client_cert_der_2048, certSz);
  44790. #elif defined(USE_CERT_BUFFERS_1024)
  44791. byte key[sizeof_client_key_der_1024];
  44792. byte cert[sizeof(sizeof_client_cert_der_1024)];
  44793. word32 keySz = (word32)sizeof(key);
  44794. word32 certSz = (word32)sizeof(cert);
  44795. XMEMSET(key, 0, keySz);
  44796. XMEMSET(cert, 0, certSz);
  44797. XMEMCPY(key, client_key_der_1024, keySz);
  44798. XMEMCPY(cert, client_cert_der_1024, certSz);
  44799. #else
  44800. unsigned char cert[ONEK_BUF];
  44801. unsigned char key[ONEK_BUF];
  44802. XFILE fp = XBADFILE;
  44803. int certSz;
  44804. int keySz;
  44805. ExpectTure((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) !=
  44806. XBADFILE);
  44807. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_client_cert_der_1024,
  44808. fp), 0);
  44809. if (fp != XBADFILE) {
  44810. XFCLOSE(fp);
  44811. fp = XBADFILE;
  44812. }
  44813. ExpectTrue((fp = XFOPEN("./certs/1024/client-key.der", "rb")) !=
  44814. XBADFILE);
  44815. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_client_key_der_1024, fp),
  44816. 0);
  44817. if (fp != XBADFILE)
  44818. XFCLOSE(fp);
  44819. #endif
  44820. #elif defined(HAVE_ECC)
  44821. #if defined(USE_CERT_BUFFERS_256)
  44822. unsigned char cert[sizeof(cliecc_cert_der_256)];
  44823. unsigned char key[sizeof(ecc_clikey_der_256)];
  44824. int certSz = (int)sizeof(cert);
  44825. int keySz = (int)sizeof(key);
  44826. XMEMSET(cert, 0, certSz);
  44827. XMEMSET(key, 0, keySz);
  44828. XMEMCPY(cert, cliecc_cert_der_256, sizeof_cliecc_cert_der_256);
  44829. XMEMCPY(key, ecc_clikey_der_256, sizeof_ecc_clikey_der_256);
  44830. #else
  44831. unsigned char cert[ONEK_BUF];
  44832. unsigned char key[ONEK_BUF];
  44833. XFILE fp = XBADFILE;
  44834. int certSz;
  44835. int keySz;
  44836. ExpectTrue((fp = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  44837. XBADFILE);
  44838. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_cliecc_cert_der_256,
  44839. fp), 0);
  44840. if (fp != XBADFILE) {
  44841. XFCLOSE(fp);
  44842. fp = XBADFILE;
  44843. }
  44844. ExpectTrue((fp = XFOPEN("./certs/client-ecc-key.der", "rb")) !=
  44845. XBADFILE);
  44846. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_ecc_clikey_der_256, fp),
  44847. 0);
  44848. if (fp != XBADFILE)
  44849. XFCLOSE(fp);
  44850. #endif
  44851. #endif
  44852. XMEMSET(&rng, 0, sizeof(WC_RNG));
  44853. /* initialize large data with sequence */
  44854. for (i=0; i<(int)sizeof(data); i++)
  44855. data[i] = i & 0xff;
  44856. XMEMSET(outputHead, 0, outputHeadSz);
  44857. XMEMSET(outputFoot, 0, outputFootSz);
  44858. ExpectIntEQ(wc_InitRng(&rng), 0);
  44859. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44860. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  44861. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  44862. if (pkcs7 != NULL) {
  44863. pkcs7->content = NULL; /* not used for ex */
  44864. pkcs7->contentSz = (word32)sizeof(data);
  44865. pkcs7->privateKey = key;
  44866. pkcs7->privateKeySz = (word32)sizeof(key);
  44867. pkcs7->encryptOID = RSAk;
  44868. #ifdef NO_SHA
  44869. pkcs7->hashOID = SHA256h;
  44870. #else
  44871. pkcs7->hashOID = SHAh;
  44872. #endif
  44873. pkcs7->rng = &rng;
  44874. }
  44875. /* calculate hash for content */
  44876. XMEMSET(&hash, 0, sizeof(wc_HashAlg));
  44877. ExpectIntEQ(wc_HashInit(&hash, hashType), 0);
  44878. ExpectIntEQ(wc_HashUpdate(&hash, hashType, data, sizeof(data)), 0);
  44879. ExpectIntEQ(wc_HashFinal(&hash, hashType, hashBuf), 0);
  44880. DoExpectIntEQ(wc_HashFree(&hash, hashType), 0);
  44881. /* Perform PKCS7 sign using hash directly */
  44882. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz,
  44883. outputHead, &outputHeadSz, outputFoot, &outputFootSz), 0);
  44884. ExpectIntGT(outputHeadSz, 0);
  44885. ExpectIntGT(outputFootSz, 0);
  44886. wc_PKCS7_Free(pkcs7);
  44887. pkcs7 = NULL;
  44888. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44889. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44890. /* required parameter even on verify when using _ex, if using outputHead
  44891. * and outputFoot */
  44892. if (pkcs7 != NULL) {
  44893. pkcs7->contentSz = (word32)sizeof(data);
  44894. }
  44895. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  44896. outputHead, outputHeadSz, outputFoot, outputFootSz), 0);
  44897. wc_PKCS7_Free(pkcs7);
  44898. pkcs7 = NULL;
  44899. /* assembly complete PKCS7 sign and use normal verify */
  44900. {
  44901. byte* output = NULL;
  44902. word32 outputSz = 0;
  44903. #ifndef NO_PKCS7_STREAM
  44904. word32 z;
  44905. int ret;
  44906. #endif /* !NO_PKCS7_STREAM */
  44907. ExpectNotNull(output = (byte*)XMALLOC(
  44908. outputHeadSz + sizeof(data) + outputFootSz, HEAP_HINT,
  44909. DYNAMIC_TYPE_TMP_BUFFER));
  44910. if (output != NULL) {
  44911. XMEMCPY(&output[outputSz], outputHead, outputHeadSz);
  44912. outputSz += outputHeadSz;
  44913. XMEMCPY(&output[outputSz], data, sizeof(data));
  44914. outputSz += sizeof(data);
  44915. XMEMCPY(&output[outputSz], outputFoot, outputFootSz);
  44916. outputSz += outputFootSz;
  44917. }
  44918. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44919. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44920. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  44921. #ifndef NO_PKCS7_STREAM
  44922. wc_PKCS7_Free(pkcs7);
  44923. pkcs7 = NULL;
  44924. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44925. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44926. /* test for streaming mode */
  44927. ret = -1;
  44928. for (z = 0; z < outputSz && ret != 0; z++) {
  44929. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  44930. if (ret < 0){
  44931. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  44932. }
  44933. }
  44934. ExpectIntEQ(ret, 0);
  44935. ExpectIntNE(pkcs7->contentSz, 0);
  44936. ExpectNotNull(pkcs7->contentDynamic);
  44937. wc_PKCS7_Free(pkcs7);
  44938. pkcs7 = NULL;
  44939. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  44940. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  44941. #endif /* !NO_PKCS7_STREAM */
  44942. XFREE(output, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44943. }
  44944. /* Pass in bad args. */
  44945. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(NULL, hashBuf, hashSz, outputHead,
  44946. &outputHeadSz, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44947. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, NULL, hashSz, outputHead,
  44948. &outputHeadSz, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44949. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, 0, outputHead,
  44950. &outputHeadSz, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44951. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz, NULL,
  44952. &outputHeadSz, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44953. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz,
  44954. outputHead, NULL, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44955. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz,
  44956. outputHead, &outputHeadSz, NULL, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44957. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz,
  44958. outputHead, &outputHeadSz, outputFoot, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44959. if (pkcs7 != NULL) {
  44960. pkcs7->hashOID = 0; /* bad hashOID */
  44961. }
  44962. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz,
  44963. outputHead, &outputHeadSz, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44964. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(NULL, hashBuf, hashSz, outputHead,
  44965. outputHeadSz, outputFoot, outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44966. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, NULL, hashSz, outputHead,
  44967. outputHeadSz, outputFoot, outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44968. #ifndef NO_PKCS7_STREAM
  44969. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, 0, outputHead,
  44970. outputHeadSz, outputFoot, outputFootSz), WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  44971. #else
  44972. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, 0, outputHead,
  44973. outputHeadSz, outputFoot, outputFootSz), WC_NO_ERR_TRACE(BUFFER_E));
  44974. #endif
  44975. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz, NULL,
  44976. outputHeadSz, outputFoot, outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44977. #ifndef NO_PKCS7_STREAM
  44978. /* can pass in 0 buffer length with streaming API */
  44979. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  44980. outputHead, 0, outputFoot, outputFootSz), WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  44981. #else
  44982. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  44983. outputHead, 0, outputFoot, outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44984. #endif
  44985. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  44986. outputHead, outputHeadSz, NULL, outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44987. #ifndef NO_PKCS7_STREAM
  44988. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  44989. outputHead, outputHeadSz, outputFoot, 0), WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  44990. #else
  44991. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  44992. outputHead, outputHeadSz, outputFoot, 0), WC_NO_ERR_TRACE(BUFFER_E));
  44993. #endif
  44994. wc_PKCS7_Free(pkcs7);
  44995. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  44996. #endif
  44997. return EXPECT_RESULT();
  44998. } /* END test_wc_PKCS7_EncodeSignedData_ex */
  44999. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM)
  45000. /**
  45001. * Loads certs/keys from files or buffers into the argument buffers,
  45002. * helper function called by CreatePKCS7SignedData().
  45003. *
  45004. * Returns 0 on success, negative on error.
  45005. */
  45006. static int LoadPKCS7SignedDataCerts(
  45007. int useIntermediateCertChain, int pkAlgoType,
  45008. byte* intCARoot, word32* intCARootSz,
  45009. byte* intCA1, word32* intCA1Sz,
  45010. byte* intCA2, word32* intCA2Sz,
  45011. byte* cert, word32* certSz,
  45012. byte* key, word32* keySz)
  45013. {
  45014. EXPECT_DECLS;
  45015. int ret = 0;
  45016. XFILE fp = XBADFILE;
  45017. #ifndef NO_RSA
  45018. const char* intCARootRSA = "./certs/ca-cert.der";
  45019. const char* intCA1RSA = "./certs/intermediate/ca-int-cert.der";
  45020. const char* intCA2RSA = "./certs/intermediate/ca-int2-cert.der";
  45021. const char* intServCertRSA = "./certs/intermediate/server-int-cert.der";
  45022. const char* intServKeyRSA = "./certs/server-key.der";
  45023. #if !defined(USE_CERT_BUFFERS_2048) && !defined(USE_CERT_BUFFERS_1024)
  45024. const char* cli1024Cert = "./certs/1024/client-cert.der";
  45025. const char* cli1024Key = "./certs/1024/client-key.der";
  45026. #endif
  45027. #endif
  45028. #ifdef HAVE_ECC
  45029. const char* intCARootECC = "./certs/ca-ecc-cert.der";
  45030. const char* intCA1ECC = "./certs/intermediate/ca-int-ecc-cert.der";
  45031. const char* intCA2ECC = "./certs/intermediate/ca-int2-ecc-cert.der";
  45032. const char* intServCertECC = "./certs/intermediate/server-int-ecc-cert.der";
  45033. const char* intServKeyECC = "./certs/ecc-key.der";
  45034. #ifndef USE_CERT_BUFFERS_256
  45035. const char* cliEccCert = "./certs/client-ecc-cert.der";
  45036. const char* cliEccKey = "./certs/client-ecc-key.der";
  45037. #endif
  45038. #endif
  45039. if (cert == NULL || certSz == NULL || key == NULL || keySz == NULL ||
  45040. ((useIntermediateCertChain == 1) &&
  45041. (intCARoot == NULL || intCARootSz == NULL || intCA1 == NULL ||
  45042. intCA1Sz == NULL || intCA2 == NULL || intCA2Sz == NULL))) {
  45043. return BAD_FUNC_ARG;
  45044. }
  45045. /* Read/load certs and keys to use for signing based on PK type and chain */
  45046. switch (pkAlgoType) {
  45047. #ifndef NO_RSA
  45048. case RSA_TYPE:
  45049. if (useIntermediateCertChain == 1) {
  45050. ExpectTrue((fp = XFOPEN(intCARootRSA, "rb")) != XBADFILE);
  45051. *intCARootSz = (word32)XFREAD(intCARoot, 1, *intCARootSz, fp);
  45052. if (fp != XBADFILE) {
  45053. XFCLOSE(fp);
  45054. fp = XBADFILE;
  45055. }
  45056. ExpectIntGT(*intCARootSz, 0);
  45057. ExpectTrue((fp = XFOPEN(intCA1RSA, "rb")) != XBADFILE);
  45058. if (fp != XBADFILE) {
  45059. *intCA1Sz = (word32)XFREAD(intCA1, 1, *intCA1Sz, fp);
  45060. XFCLOSE(fp);
  45061. fp = XBADFILE;
  45062. }
  45063. ExpectIntGT(*intCA1Sz, 0);
  45064. ExpectTrue((fp = XFOPEN(intCA2RSA, "rb")) != XBADFILE);
  45065. if (fp != XBADFILE) {
  45066. *intCA2Sz = (word32)XFREAD(intCA2, 1, *intCA2Sz, fp);
  45067. XFCLOSE(fp);
  45068. fp = XBADFILE;
  45069. }
  45070. ExpectIntGT(*intCA2Sz, 0);
  45071. ExpectTrue((fp = XFOPEN(intServCertRSA, "rb")) != XBADFILE);
  45072. if (fp != XBADFILE) {
  45073. *certSz = (word32)XFREAD(cert, 1, *certSz, fp);
  45074. XFCLOSE(fp);
  45075. fp = XBADFILE;
  45076. }
  45077. ExpectIntGT(*certSz, 0);
  45078. ExpectTrue((fp = XFOPEN(intServKeyRSA, "rb")) != XBADFILE);
  45079. if (fp != XBADFILE) {
  45080. *keySz = (word32)XFREAD(key, 1, *keySz, fp);
  45081. XFCLOSE(fp);
  45082. fp = XBADFILE;
  45083. }
  45084. ExpectIntGT(*keySz, 0);
  45085. }
  45086. else {
  45087. #if defined(USE_CERT_BUFFERS_2048)
  45088. *keySz = sizeof_client_key_der_2048;
  45089. *certSz = sizeof_client_cert_der_2048;
  45090. XMEMCPY(key, client_key_der_2048, *keySz);
  45091. XMEMCPY(cert, client_cert_der_2048, *certSz);
  45092. #elif defined(USE_CERT_BUFFERS_1024)
  45093. *keySz = sizeof_client_key_der_1024;
  45094. *certSz = sizeof_client_cert_der_1024;
  45095. XMEMCPY(key, client_key_der_1024, *keySz);
  45096. XMEMCPY(cert, client_cert_der_1024, *certSz);
  45097. #else
  45098. ExpectTrue((fp = XFOPEN(cli1024Key, "rb")) != XBADFILE);
  45099. if (fp != XBADFILE) {
  45100. *keySz = (word32)XFREAD(key, 1, *keySz, fp);
  45101. XFCLOSE(fp);
  45102. fp = XBADFILE;
  45103. }
  45104. ExpectIntGT(*keySz, 0);
  45105. ExpectTrue((fp = XFOPEN(cli1024Cert, "rb")) != XBADFILE);
  45106. if (fp != XBADFILE) {
  45107. *certSz = (word32)XFREAD(cert, 1, *certSz, fp);
  45108. XFCLOSE(fp);
  45109. fp = XBADFILE;
  45110. }
  45111. ExpectIntGT(*certSz, 0);
  45112. #endif /* USE_CERT_BUFFERS_2048 */
  45113. }
  45114. break;
  45115. #endif /* !NO_RSA */
  45116. #ifdef HAVE_ECC
  45117. case ECC_TYPE:
  45118. if (useIntermediateCertChain == 1) {
  45119. ExpectTrue((fp = XFOPEN(intCARootECC, "rb")) != XBADFILE);
  45120. if (fp != XBADFILE) {
  45121. *intCARootSz = (word32)XFREAD(intCARoot, 1, *intCARootSz,
  45122. fp);
  45123. XFCLOSE(fp);
  45124. fp = XBADFILE;
  45125. }
  45126. ExpectIntGT(*intCARootSz, 0);
  45127. ExpectTrue((fp = XFOPEN(intCA1ECC, "rb")) != XBADFILE);
  45128. if (fp != XBADFILE) {
  45129. *intCA1Sz = (word32)XFREAD(intCA1, 1, *intCA1Sz, fp);
  45130. XFCLOSE(fp);
  45131. fp = XBADFILE;
  45132. }
  45133. ExpectIntGT(*intCA1Sz, 0);
  45134. ExpectTrue((fp = XFOPEN(intCA2ECC, "rb")) != XBADFILE);
  45135. if (fp != XBADFILE) {
  45136. *intCA2Sz = (word32)XFREAD(intCA2, 1, *intCA2Sz, fp);
  45137. XFCLOSE(fp);
  45138. fp = XBADFILE;
  45139. }
  45140. ExpectIntGT(*intCA2Sz, 0);
  45141. ExpectTrue((fp = XFOPEN(intServCertECC, "rb")) != XBADFILE);
  45142. if (fp != XBADFILE) {
  45143. *certSz = (word32)XFREAD(cert, 1, *certSz, fp);
  45144. XFCLOSE(fp);
  45145. fp = XBADFILE;
  45146. }
  45147. ExpectIntGT(*certSz, 0);
  45148. ExpectTrue((fp = XFOPEN(intServKeyECC, "rb")) != XBADFILE);
  45149. if (fp != XBADFILE) {
  45150. *keySz = (word32)XFREAD(key, 1, *keySz, fp);
  45151. XFCLOSE(fp);
  45152. fp = XBADFILE;
  45153. }
  45154. ExpectIntGT(*keySz, 0);
  45155. }
  45156. else {
  45157. #if defined(USE_CERT_BUFFERS_256)
  45158. *keySz = sizeof_ecc_clikey_der_256;
  45159. *certSz = sizeof_cliecc_cert_der_256;
  45160. XMEMCPY(key, ecc_clikey_der_256, *keySz);
  45161. XMEMCPY(cert, cliecc_cert_der_256, *certSz);
  45162. #else
  45163. ExpectTrue((fp = XFOPEN(cliEccKey, "rb")) != XBADFILE);
  45164. if (fp != XBADFILE) {
  45165. *keySz = (word32)XFREAD(key, 1, *keySz, fp);
  45166. XFCLOSE(fp);
  45167. fp = XBADFILE;
  45168. }
  45169. ExpectIntGT(*keySz, 0);
  45170. ExpectTrue((fp = XFOPEN(cliEccCert, "rb")) != XBADFILE);
  45171. if (fp != XBADFILE) {
  45172. *certSz = (word32)XFREAD(cert, 1, *certSz, fp);
  45173. XFCLOSE(fp);
  45174. fp = XBADFILE;
  45175. }
  45176. ExpectIntGT(*certSz, 0);
  45177. #endif /* USE_CERT_BUFFERS_256 */
  45178. }
  45179. break;
  45180. #endif /* HAVE_ECC */
  45181. default:
  45182. WOLFSSL_MSG("Unsupported SignedData PK type");
  45183. ret = BAD_FUNC_ARG;
  45184. break;
  45185. }
  45186. if (EXPECT_FAIL() && (ret == 0)) {
  45187. ret = BAD_FUNC_ARG;
  45188. }
  45189. return ret;
  45190. }
  45191. /**
  45192. * Creates a PKCS7/CMS SignedData bundle to use for testing.
  45193. *
  45194. * output output buffer to place SignedData
  45195. * outputSz size of output buffer
  45196. * data data buffer to be signed
  45197. * dataSz size of data buffer
  45198. * withAttribs [1/0] include attributes in SignedData message
  45199. * detachedSig [1/0] create detached signature, no content
  45200. * useIntCertChain [1/0] use certificate chain and include intermediate and
  45201. * root CAs in bundle
  45202. * pkAlgoType RSA_TYPE or ECC_TYPE, choose what key/cert type to use
  45203. *
  45204. * Return size of bundle created on success, negative on error */
  45205. static int CreatePKCS7SignedData(unsigned char* output, int outputSz,
  45206. byte* data, word32 dataSz,
  45207. int withAttribs, int detachedSig,
  45208. int useIntermediateCertChain,
  45209. int pkAlgoType)
  45210. {
  45211. EXPECT_DECLS;
  45212. int ret = 0;
  45213. WC_RNG rng;
  45214. PKCS7* pkcs7 = NULL;
  45215. static byte messageTypeOid[] =
  45216. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  45217. 0x09, 0x02 };
  45218. static byte messageType[] = { 0x13, 2, '1', '9' };
  45219. PKCS7Attrib attribs[] =
  45220. {
  45221. { messageTypeOid, sizeof(messageTypeOid), messageType,
  45222. sizeof(messageType) }
  45223. };
  45224. byte intCARoot[TWOK_BUF];
  45225. byte intCA1[TWOK_BUF];
  45226. byte intCA2[TWOK_BUF];
  45227. byte cert[TWOK_BUF];
  45228. byte key[TWOK_BUF];
  45229. word32 intCARootSz = sizeof(intCARoot);
  45230. word32 intCA1Sz = sizeof(intCA1);
  45231. word32 intCA2Sz = sizeof(intCA2);
  45232. word32 certSz = sizeof(cert);
  45233. word32 keySz = sizeof(key);
  45234. XMEMSET(intCARoot, 0, intCARootSz);
  45235. XMEMSET(intCA1, 0, intCA1Sz);
  45236. XMEMSET(intCA2, 0, intCA2Sz);
  45237. XMEMSET(cert, 0, certSz);
  45238. XMEMSET(key, 0, keySz);
  45239. ret = LoadPKCS7SignedDataCerts(useIntermediateCertChain, pkAlgoType,
  45240. intCARoot, &intCARootSz, intCA1, &intCA1Sz, intCA2, &intCA2Sz,
  45241. cert, &certSz, key, &keySz);
  45242. ExpectIntEQ(ret, 0);
  45243. XMEMSET(output, 0, outputSz);
  45244. ExpectIntEQ(wc_InitRng(&rng), 0);
  45245. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45246. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  45247. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  45248. if (useIntermediateCertChain == 1) {
  45249. /* Add intermediate and root CA certs into SignedData Certs SET */
  45250. ExpectIntEQ(wc_PKCS7_AddCertificate(pkcs7, intCA2, intCA2Sz), 0);
  45251. ExpectIntEQ(wc_PKCS7_AddCertificate(pkcs7, intCA1, intCA1Sz), 0);
  45252. ExpectIntEQ(wc_PKCS7_AddCertificate(pkcs7, intCARoot, intCARootSz), 0);
  45253. }
  45254. if (pkcs7 != NULL) {
  45255. pkcs7->content = data;
  45256. pkcs7->contentSz = dataSz;
  45257. pkcs7->privateKey = key;
  45258. pkcs7->privateKeySz = (word32)sizeof(key);
  45259. if (pkAlgoType == RSA_TYPE) {
  45260. pkcs7->encryptOID = RSAk;
  45261. }
  45262. else {
  45263. pkcs7->encryptOID = ECDSAk;
  45264. }
  45265. #ifdef NO_SHA
  45266. pkcs7->hashOID = SHA256h;
  45267. #else
  45268. pkcs7->hashOID = SHAh;
  45269. #endif
  45270. pkcs7->rng = &rng;
  45271. if (withAttribs) {
  45272. /* include a signed attribute */
  45273. pkcs7->signedAttribs = attribs;
  45274. pkcs7->signedAttribsSz = (sizeof(attribs)/sizeof(PKCS7Attrib));
  45275. }
  45276. }
  45277. if (detachedSig) {
  45278. ExpectIntEQ(wc_PKCS7_SetDetached(pkcs7, 1), 0);
  45279. }
  45280. outputSz = wc_PKCS7_EncodeSignedData(pkcs7, output, (word32)outputSz);
  45281. ExpectIntGT(outputSz, 0);
  45282. wc_PKCS7_Free(pkcs7);
  45283. pkcs7 = NULL;
  45284. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45285. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45286. if (detachedSig && (pkcs7 != NULL)) {
  45287. pkcs7->content = data;
  45288. pkcs7->contentSz = dataSz;
  45289. }
  45290. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, (word32)outputSz), 0);
  45291. wc_PKCS7_Free(pkcs7);
  45292. wc_FreeRng(&rng);
  45293. if (EXPECT_FAIL()) {
  45294. outputSz = 0;
  45295. }
  45296. return outputSz;
  45297. }
  45298. #endif
  45299. /*
  45300. * Testing wc_PKCS_VerifySignedData()
  45301. */
  45302. static int test_wc_PKCS7_VerifySignedData_RSA(void)
  45303. {
  45304. EXPECT_DECLS;
  45305. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  45306. PKCS7* pkcs7 = NULL;
  45307. byte output[6000]; /* Large size needed for bundles with int CA certs */
  45308. word32 outputSz = sizeof(output);
  45309. byte data[] = "Test data to encode.";
  45310. byte badOut[1];
  45311. word32 badOutSz = 0;
  45312. byte badContent[] = "This is different content than was signed";
  45313. wc_HashAlg hash;
  45314. #ifdef NO_SHA
  45315. enum wc_HashType hashType = WC_HASH_TYPE_SHA256;
  45316. #else
  45317. enum wc_HashType hashType = WC_HASH_TYPE_SHA;
  45318. #endif
  45319. byte hashBuf[WC_MAX_DIGEST_SIZE];
  45320. word32 hashSz = (word32)wc_HashGetDigestSize(hashType);
  45321. #ifndef NO_RSA
  45322. PKCS7DecodedAttrib* decodedAttrib = NULL;
  45323. /* contentType OID (1.2.840.113549.1.9.3) */
  45324. static const byte contentTypeOid[] =
  45325. { 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xF7, 0x0d, 0x01, 0x09, 0x03 };
  45326. /* PKCS#7 DATA content type (contentType defaults to DATA) */
  45327. static const byte dataType[] =
  45328. { 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01 };
  45329. /* messageDigest OID (1.2.840.113549.1.9.4) */
  45330. static const byte messageDigestOid[] =
  45331. { 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x04 };
  45332. #ifndef NO_ASN_TIME
  45333. /* signingTime OID () */
  45334. static const byte signingTimeOid[] =
  45335. { 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x05};
  45336. #endif
  45337. #if !defined(NO_ASN) && !defined(NO_ASN_TIME)
  45338. int dateLength = 0;
  45339. byte dateFormat;
  45340. const byte* datePart = NULL;
  45341. struct tm timearg;
  45342. time_t now;
  45343. struct tm* nowTm = NULL;
  45344. #ifdef NEED_TMP_TIME
  45345. struct tm tmpTimeStorage;
  45346. struct tm* tmpTime = &tmpTimeStorage;
  45347. #endif
  45348. #endif /* !NO_ASN && !NO_ASN_TIME */
  45349. #ifndef NO_PKCS7_STREAM
  45350. word32 z;
  45351. int ret;
  45352. #endif /* !NO_PKCS7_STREAM */
  45353. XMEMSET(&hash, 0, sizeof(wc_HashAlg));
  45354. /* Success test with RSA certs/key */
  45355. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  45356. (word32)sizeof(data), 0, 0, 0, RSA_TYPE)), 0);
  45357. /* calculate hash for content, used later */
  45358. ExpectIntEQ(wc_HashInit(&hash, hashType), 0);
  45359. ExpectIntEQ(wc_HashUpdate(&hash, hashType, data, sizeof(data)), 0);
  45360. ExpectIntEQ(wc_HashFinal(&hash, hashType, hashBuf), 0);
  45361. DoExpectIntEQ(wc_HashFree(&hash, hashType), 0);
  45362. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45363. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  45364. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45365. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  45366. #ifndef NO_PKCS7_STREAM
  45367. wc_PKCS7_Free(pkcs7);
  45368. pkcs7 = NULL;
  45369. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45370. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45371. /* test for streaming */
  45372. ret = -1;
  45373. for (z = 0; z < outputSz && ret != 0; z++) {
  45374. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45375. if (ret < 0){
  45376. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45377. }
  45378. }
  45379. ExpectIntEQ(ret, 0);
  45380. ExpectIntNE(pkcs7->contentSz, 0);
  45381. ExpectNotNull(pkcs7->contentDynamic);
  45382. #endif /* !NO_PKCS7_STREAM */
  45383. /* Check that decoded signed attributes are correct */
  45384. /* messageDigest should be first */
  45385. if (pkcs7 != NULL) {
  45386. decodedAttrib = pkcs7->decodedAttrib;
  45387. }
  45388. ExpectNotNull(decodedAttrib);
  45389. ExpectIntEQ(decodedAttrib->oidSz, (word32)sizeof(messageDigestOid));
  45390. ExpectIntEQ(XMEMCMP(decodedAttrib->oid, messageDigestOid,
  45391. decodedAttrib->oidSz), 0);
  45392. /* + 2 for OCTET STRING and length bytes */
  45393. ExpectIntEQ(decodedAttrib->valueSz, hashSz + 2);
  45394. ExpectNotNull(decodedAttrib->value);
  45395. ExpectIntEQ(XMEMCMP(decodedAttrib->value + 2, hashBuf, hashSz), 0);
  45396. #ifndef NO_ASN_TIME
  45397. /* signingTime should be second */
  45398. if (decodedAttrib != NULL) {
  45399. decodedAttrib = decodedAttrib->next;
  45400. }
  45401. ExpectNotNull(decodedAttrib);
  45402. ExpectIntEQ(decodedAttrib->oidSz, (word32)sizeof(signingTimeOid));
  45403. ExpectIntEQ(XMEMCMP(decodedAttrib->oid, signingTimeOid,
  45404. decodedAttrib->oidSz), 0);
  45405. ExpectIntGT(decodedAttrib->valueSz, 0);
  45406. ExpectNotNull(decodedAttrib->value);
  45407. #endif
  45408. /* Verify signingTime if ASN and time are available */
  45409. #if !defined(NO_ASN) && !defined(NO_ASN_TIME)
  45410. ExpectIntEQ(wc_GetDateInfo(decodedAttrib->value, decodedAttrib->valueSz,
  45411. &datePart, &dateFormat, &dateLength), 0);
  45412. ExpectNotNull(datePart);
  45413. ExpectIntGT(dateLength, 0);
  45414. XMEMSET(&timearg, 0, sizeof(timearg));
  45415. ExpectIntEQ(wc_GetDateAsCalendarTime(datePart, dateLength, dateFormat,
  45416. &timearg), 0);
  45417. /* Get current time and compare year/month/day against attribute value */
  45418. ExpectIntEQ(wc_GetTime(&now, sizeof(now)), 0);
  45419. nowTm = (struct tm*)XGMTIME((time_t*)&now, tmpTime);
  45420. ExpectNotNull(nowTm);
  45421. ExpectIntEQ(timearg.tm_year, nowTm->tm_year);
  45422. ExpectIntEQ(timearg.tm_mon, nowTm->tm_mon);
  45423. ExpectIntEQ(timearg.tm_mday, nowTm->tm_mday);
  45424. #endif /* !NO_ASN && !NO_ASN_TIME */
  45425. /* contentType should be third */
  45426. if (decodedAttrib != NULL) {
  45427. decodedAttrib = decodedAttrib->next;
  45428. }
  45429. ExpectNotNull(decodedAttrib);
  45430. ExpectIntEQ(decodedAttrib->oidSz, (word32)sizeof(contentTypeOid));
  45431. ExpectIntEQ(XMEMCMP(decodedAttrib->oid, contentTypeOid,
  45432. decodedAttrib->oidSz), 0);
  45433. ExpectIntEQ(decodedAttrib->valueSz, (int)sizeof(dataType) + 2);
  45434. ExpectNotNull(decodedAttrib->value);
  45435. ExpectIntEQ(XMEMCMP(decodedAttrib->value + 2, dataType, sizeof(dataType)),
  45436. 0);
  45437. #endif /* !NO_RSA */
  45438. /* Test bad args. */
  45439. ExpectIntEQ(wc_PKCS7_VerifySignedData(NULL, output, outputSz),
  45440. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45441. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, NULL, outputSz),
  45442. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45443. #ifndef NO_PKCS7_STREAM
  45444. /* can pass in 0 buffer length with streaming API */
  45445. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, badOut,
  45446. badOutSz), WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45447. #else
  45448. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, badOut,
  45449. badOutSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45450. #endif
  45451. wc_PKCS7_Free(pkcs7);
  45452. pkcs7 = NULL;
  45453. #ifndef NO_RSA
  45454. /* Try RSA certs/key/sig first */
  45455. outputSz = sizeof(output);
  45456. XMEMSET(output, 0, outputSz);
  45457. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  45458. (word32)sizeof(data),
  45459. 1, 1, 0, RSA_TYPE)), 0);
  45460. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45461. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45462. if (pkcs7 != NULL) {
  45463. pkcs7->content = badContent;
  45464. pkcs7->contentSz = sizeof(badContent);
  45465. }
  45466. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz),
  45467. WC_NO_ERR_TRACE(SIG_VERIFY_E));
  45468. wc_PKCS7_Free(pkcs7);
  45469. pkcs7 = NULL;
  45470. #ifndef NO_PKCS7_STREAM
  45471. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45472. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45473. if (pkcs7 != NULL) {
  45474. pkcs7->content = badContent;
  45475. pkcs7->contentSz = sizeof(badContent);
  45476. }
  45477. /* test for streaming */
  45478. ret = -1;
  45479. for (z = 0; z < outputSz && ret != 0; z++) {
  45480. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45481. if (ret == WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)){
  45482. continue;
  45483. }
  45484. else if (ret < 0) {
  45485. break;
  45486. }
  45487. }
  45488. ExpectIntEQ(ret, WC_NO_ERR_TRACE(SIG_VERIFY_E));
  45489. ExpectIntNE(pkcs7->contentSz, 0);
  45490. ExpectNotNull(pkcs7->contentDynamic);
  45491. wc_PKCS7_Free(pkcs7);
  45492. pkcs7 = NULL;
  45493. #endif /* !NO_PKCS7_STREAM */
  45494. /* Test success case with detached signature and valid content */
  45495. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45496. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45497. if (pkcs7 != NULL) {
  45498. pkcs7->content = data;
  45499. pkcs7->contentSz = sizeof(data);
  45500. }
  45501. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  45502. wc_PKCS7_Free(pkcs7);
  45503. pkcs7 = NULL;
  45504. #ifndef NO_PKCS7_STREAM
  45505. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45506. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45507. if (pkcs7 != NULL) {
  45508. pkcs7->content = data;
  45509. pkcs7->contentSz = sizeof(data);
  45510. }
  45511. /* test for streaming */
  45512. ret = -1;
  45513. for (z = 0; z < outputSz && ret != 0; z++) {
  45514. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45515. if (ret < 0){
  45516. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45517. }
  45518. }
  45519. ExpectIntEQ(ret, 0);
  45520. ExpectIntNE(pkcs7->contentSz, 0);
  45521. ExpectNotNull(pkcs7->contentDynamic);
  45522. wc_PKCS7_Free(pkcs7);
  45523. pkcs7 = NULL;
  45524. #endif /* !NO_PKCS7_STREAM */
  45525. /* verify using pre-computed content digest only (no content) */
  45526. {
  45527. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45528. ExpectIntEQ(wc_PKCS7_Init(pkcs7, NULL, 0), 0);
  45529. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  45530. output, outputSz, NULL, 0), 0);
  45531. wc_PKCS7_Free(pkcs7);
  45532. pkcs7 = NULL;
  45533. }
  45534. #endif /* !NO_RSA */
  45535. /* Test verify on signedData containing intermediate/root CA certs */
  45536. #ifndef NO_RSA
  45537. outputSz = sizeof(output);
  45538. XMEMSET(output, 0, outputSz);
  45539. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  45540. (word32)sizeof(data),
  45541. 0, 0, 1, RSA_TYPE)), 0);
  45542. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45543. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45544. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  45545. wc_PKCS7_Free(pkcs7);
  45546. pkcs7 = NULL;
  45547. #ifndef NO_PKCS7_STREAM
  45548. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45549. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45550. /* test for streaming */
  45551. ret = -1;
  45552. for (z = 0; z < outputSz && ret != 0; z++) {
  45553. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45554. if (ret < 0){
  45555. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45556. }
  45557. }
  45558. ExpectIntEQ(ret, 0);
  45559. ExpectIntNE(pkcs7->contentSz, 0);
  45560. ExpectNotNull(pkcs7->contentDynamic);
  45561. wc_PKCS7_Free(pkcs7);
  45562. pkcs7 = NULL;
  45563. #endif /* !NO_PKCS7_STREAM */
  45564. #endif /* !NO_RSA */
  45565. #if defined(ASN_BER_TO_DER) && !defined(NO_PKCS7_STREAM) && \
  45566. !defined(NO_FILESYSTEM)
  45567. {
  45568. XFILE signedBundle = XBADFILE;
  45569. int signedBundleSz = 0;
  45570. int chunkSz = 1;
  45571. int i, rc = 0;
  45572. byte* buf = NULL;
  45573. ExpectTrue((signedBundle = XFOPEN("./certs/test-stream-sign.p7b",
  45574. "rb")) != XBADFILE);
  45575. ExpectTrue(XFSEEK(signedBundle, 0, XSEEK_END) == 0);
  45576. ExpectIntGT(signedBundleSz = (int)XFTELL(signedBundle), 0);
  45577. ExpectTrue(XFSEEK(signedBundle, 0, XSEEK_SET) == 0);
  45578. ExpectNotNull(buf = (byte*)XMALLOC(signedBundleSz, HEAP_HINT,
  45579. DYNAMIC_TYPE_FILE));
  45580. if (buf != NULL) {
  45581. ExpectIntEQ(XFREAD(buf, 1, (size_t)signedBundleSz, signedBundle),
  45582. signedBundleSz);
  45583. }
  45584. if (signedBundle != XBADFILE) {
  45585. XFCLOSE(signedBundle);
  45586. signedBundle = XBADFILE;
  45587. }
  45588. if (buf != NULL) {
  45589. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45590. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45591. for (i = 0; i < signedBundleSz;) {
  45592. int sz = (i + chunkSz > signedBundleSz)? signedBundleSz - i :
  45593. chunkSz;
  45594. rc = wc_PKCS7_VerifySignedData(pkcs7, buf + i, (word32)sz);
  45595. if (rc < 0 ) {
  45596. if (rc == WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)) {
  45597. i += sz;
  45598. continue;
  45599. }
  45600. break;
  45601. }
  45602. else {
  45603. break;
  45604. }
  45605. }
  45606. ExpectIntEQ(rc, WC_NO_ERR_TRACE(PKCS7_SIGNEEDS_CHECK));
  45607. wc_PKCS7_Free(pkcs7);
  45608. pkcs7 = NULL;
  45609. }
  45610. /* now try with malformed bundle */
  45611. if (buf != NULL) {
  45612. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45613. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45614. buf[signedBundleSz - 2] = buf[signedBundleSz - 2] + 1;
  45615. for (i = 0; i < signedBundleSz;) {
  45616. int sz = (i + chunkSz > signedBundleSz)? signedBundleSz - i :
  45617. chunkSz;
  45618. rc = wc_PKCS7_VerifySignedData(pkcs7, buf + i, (word32)sz);
  45619. if (rc < 0 ) {
  45620. if (rc == WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)) {
  45621. i += sz;
  45622. continue;
  45623. }
  45624. break;
  45625. }
  45626. else {
  45627. break;
  45628. }
  45629. }
  45630. ExpectIntEQ(rc, WC_NO_ERR_TRACE(ASN_PARSE_E));
  45631. wc_PKCS7_Free(pkcs7);
  45632. pkcs7 = NULL;
  45633. }
  45634. if (buf != NULL)
  45635. XFREE(buf, HEAP_HINT, DYNAMIC_TYPE_FILE);
  45636. }
  45637. #endif /* BER and stream */
  45638. #endif
  45639. return EXPECT_RESULT();
  45640. } /* END test_wc_PKCS7_VerifySignedData()_RSA */
  45641. /*
  45642. * Testing wc_PKCS_VerifySignedData()
  45643. */
  45644. static int test_wc_PKCS7_VerifySignedData_ECC(void)
  45645. {
  45646. EXPECT_DECLS;
  45647. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && defined(HAVE_ECC)
  45648. PKCS7* pkcs7 = NULL;
  45649. byte output[6000]; /* Large size needed for bundles with int CA certs */
  45650. word32 outputSz = sizeof(output);
  45651. byte data[] = "Test data to encode.";
  45652. byte badContent[] = "This is different content than was signed";
  45653. wc_HashAlg hash;
  45654. #ifndef NO_PKCS7_STREAM
  45655. word32 z;
  45656. int ret;
  45657. #endif /* !NO_PKCS7_STREAM */
  45658. #ifdef NO_SHA
  45659. enum wc_HashType hashType = WC_HASH_TYPE_SHA256;
  45660. #else
  45661. enum wc_HashType hashType = WC_HASH_TYPE_SHA;
  45662. #endif
  45663. byte hashBuf[WC_MAX_DIGEST_SIZE];
  45664. word32 hashSz = (word32)wc_HashGetDigestSize(hashType);
  45665. XMEMSET(&hash, 0, sizeof(wc_HashAlg));
  45666. /* Success test with ECC certs/key */
  45667. outputSz = sizeof(output);
  45668. XMEMSET(output, 0, outputSz);
  45669. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  45670. (word32)sizeof(data), 0, 0, 0, ECC_TYPE)), 0);
  45671. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45672. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  45673. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45674. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  45675. wc_PKCS7_Free(pkcs7);
  45676. pkcs7 = NULL;
  45677. #ifndef NO_PKCS7_STREAM
  45678. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45679. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45680. /* test for streaming */
  45681. ret = -1;
  45682. for (z = 0; z < outputSz && ret != 0; z++) {
  45683. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45684. if (ret < 0){
  45685. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45686. }
  45687. }
  45688. ExpectIntEQ(ret, 0);
  45689. ExpectIntNE(pkcs7->contentSz, 0);
  45690. ExpectNotNull(pkcs7->contentDynamic);
  45691. wc_PKCS7_Free(pkcs7);
  45692. pkcs7 = NULL;
  45693. #endif /* !NO_PKCS7_STREAM */
  45694. /* Invalid content should error, use detached signature so we can
  45695. * easily change content */
  45696. outputSz = sizeof(output);
  45697. XMEMSET(output, 0, outputSz);
  45698. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  45699. (word32)sizeof(data), 1, 1, 0, ECC_TYPE)), 0);
  45700. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45701. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45702. if (pkcs7 != NULL) {
  45703. pkcs7->content = badContent;
  45704. pkcs7->contentSz = sizeof(badContent);
  45705. }
  45706. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz),
  45707. WC_NO_ERR_TRACE(SIG_VERIFY_E));
  45708. wc_PKCS7_Free(pkcs7);
  45709. pkcs7 = NULL;
  45710. #ifndef NO_PKCS7_STREAM
  45711. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45712. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45713. if (pkcs7 != NULL) {
  45714. pkcs7->content = badContent;
  45715. pkcs7->contentSz = sizeof(badContent);
  45716. }
  45717. /* test for streaming */
  45718. ret = -1;
  45719. for (z = 0; z < outputSz && ret != 0; z++) {
  45720. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45721. if (ret == WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)){
  45722. continue;
  45723. }
  45724. else if (ret < 0) {
  45725. break;
  45726. }
  45727. }
  45728. ExpectIntEQ(ret, WC_NO_ERR_TRACE(SIG_VERIFY_E));
  45729. ExpectIntNE(pkcs7->contentSz, 0);
  45730. ExpectNotNull(pkcs7->contentDynamic);
  45731. wc_PKCS7_Free(pkcs7);
  45732. pkcs7 = NULL;
  45733. #endif /* !NO_PKCS7_STREAM */
  45734. /* Test success case with detached signature and valid content */
  45735. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45736. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45737. if (pkcs7 != NULL) {
  45738. pkcs7->content = data;
  45739. pkcs7->contentSz = sizeof(data);
  45740. }
  45741. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  45742. wc_PKCS7_Free(pkcs7);
  45743. pkcs7 = NULL;
  45744. #ifndef NO_PKCS7_STREAM
  45745. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45746. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45747. if (pkcs7 != NULL) {
  45748. pkcs7->content = data;
  45749. pkcs7->contentSz = sizeof(data);
  45750. }
  45751. /* test for streaming */
  45752. ret = -1;
  45753. for (z = 0; z < outputSz && ret != 0; z++) {
  45754. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45755. if (ret < 0){
  45756. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45757. }
  45758. }
  45759. ExpectIntEQ(ret, 0);
  45760. ExpectIntNE(pkcs7->contentSz, 0);
  45761. ExpectNotNull(pkcs7->contentDynamic);
  45762. wc_PKCS7_Free(pkcs7);
  45763. pkcs7 = NULL;
  45764. #endif /* !NO_PKCS7_STREAM */
  45765. /* verify using pre-computed content digest only (no content) */
  45766. {
  45767. /* calculate hash for content */
  45768. ExpectIntEQ(wc_HashInit(&hash, hashType), 0);
  45769. ExpectIntEQ(wc_HashUpdate(&hash, hashType, data, sizeof(data)), 0);
  45770. ExpectIntEQ(wc_HashFinal(&hash, hashType, hashBuf), 0);
  45771. ExpectIntEQ(wc_HashFree(&hash, hashType), 0);
  45772. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45773. ExpectIntEQ(wc_PKCS7_Init(pkcs7, NULL, 0), 0);
  45774. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  45775. output, outputSz, NULL, 0), 0);
  45776. wc_PKCS7_Free(pkcs7);
  45777. pkcs7 = NULL;
  45778. }
  45779. /* Test verify on signedData containing intermediate/root CA certs */
  45780. outputSz = sizeof(output);
  45781. XMEMSET(output, 0, outputSz);
  45782. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  45783. (word32)sizeof(data), 0, 0, 1, ECC_TYPE)), 0);
  45784. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45785. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45786. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  45787. wc_PKCS7_Free(pkcs7);
  45788. pkcs7 = NULL;
  45789. #ifndef NO_PKCS7_STREAM
  45790. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45791. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45792. /* test for streaming */
  45793. ret = -1;
  45794. for (z = 0; z < outputSz && ret != 0; z++) {
  45795. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45796. if (ret < 0){
  45797. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45798. }
  45799. }
  45800. ExpectIntEQ(ret, 0);
  45801. ExpectIntNE(pkcs7->contentSz, 0);
  45802. ExpectNotNull(pkcs7->contentDynamic);
  45803. wc_PKCS7_Free(pkcs7);
  45804. pkcs7 = NULL;
  45805. #endif /* !NO_PKCS7_STREAM */
  45806. #endif
  45807. return EXPECT_RESULT();
  45808. } /* END test_wc_PKCS7_VerifySignedData_ECC() */
  45809. #if defined(HAVE_PKCS7) && !defined(NO_AES) && defined(HAVE_AES_CBC) && \
  45810. !defined(NO_AES_256)
  45811. static const byte defKey[] = {
  45812. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45813. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45814. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45815. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  45816. };
  45817. static byte aesHandle[32]; /* simulated hardware key handle */
  45818. /* return 0 on success */
  45819. static int myDecryptionFunc(PKCS7* pkcs7, int encryptOID, byte* iv, int ivSz,
  45820. byte* aad, word32 aadSz, byte* authTag, word32 authTagSz,
  45821. byte* in, int inSz, byte* out, void* usrCtx)
  45822. {
  45823. int ret;
  45824. Aes aes;
  45825. if (usrCtx == NULL) {
  45826. /* no simulated handle passed in */
  45827. return -1;
  45828. }
  45829. switch (encryptOID) {
  45830. case AES256CBCb:
  45831. if (ivSz != AES_BLOCK_SIZE)
  45832. return BAD_FUNC_ARG;
  45833. break;
  45834. default:
  45835. WOLFSSL_MSG("Unsupported content cipher type for test");
  45836. return ALGO_ID_E;
  45837. };
  45838. /* simulate using handle to get key */
  45839. ret = wc_AesInit(&aes, HEAP_HINT, INVALID_DEVID);
  45840. if (ret == 0) {
  45841. ret = wc_AesSetKey(&aes, (byte*)usrCtx, 32, iv, AES_DECRYPTION);
  45842. if (ret == 0)
  45843. ret = wc_AesCbcDecrypt(&aes, out, in, (word32)inSz);
  45844. wc_AesFree(&aes);
  45845. }
  45846. (void)aad;
  45847. (void)aadSz;
  45848. (void)authTag;
  45849. (void)authTagSz;
  45850. (void)pkcs7;
  45851. return ret;
  45852. }
  45853. /* returns key size on success */
  45854. static int myCEKwrapFunc(PKCS7* pkcs7, byte* cek, word32 cekSz, byte* keyId,
  45855. word32 keyIdSz, byte* orginKey, word32 orginKeySz,
  45856. byte* out, word32 outSz, int keyWrapAlgo, int type, int direction)
  45857. {
  45858. int ret = -1;
  45859. (void)cekSz;
  45860. (void)cek;
  45861. (void)outSz;
  45862. (void)keyIdSz;
  45863. (void)direction;
  45864. (void)orginKey; /* used with KAKRI */
  45865. (void)orginKeySz;
  45866. if (out == NULL)
  45867. return BAD_FUNC_ARG;
  45868. if (keyId[0] != 0x00) {
  45869. return -1;
  45870. }
  45871. if (type != (int)PKCS7_KEKRI) {
  45872. return -1;
  45873. }
  45874. switch (keyWrapAlgo) {
  45875. case AES256_WRAP:
  45876. /* simulate setting a handle for later decryption but use key
  45877. * as handle in the test case here */
  45878. ret = wc_AesKeyUnWrap(defKey, sizeof(defKey), cek, cekSz,
  45879. aesHandle, sizeof(aesHandle), NULL);
  45880. if (ret < 0)
  45881. return ret;
  45882. ret = wc_PKCS7_SetDecodeEncryptedCtx(pkcs7, (void*)aesHandle);
  45883. if (ret < 0)
  45884. return ret;
  45885. /* return key size on success */
  45886. return sizeof(defKey);
  45887. default:
  45888. WOLFSSL_MSG("Unsupported key wrap algorithm in example");
  45889. return BAD_KEYWRAP_ALG_E;
  45890. };
  45891. }
  45892. #endif /* HAVE_PKCS7 && !NO_AES && HAVE_AES_CBC && !NO_AES_256 */
  45893. /*
  45894. * Testing wc_PKCS7_EncodeEnvelopedData()
  45895. */
  45896. static int test_wc_PKCS7_EncodeDecodeEnvelopedData(void)
  45897. {
  45898. EXPECT_DECLS;
  45899. #if defined(HAVE_PKCS7)
  45900. PKCS7* pkcs7 = NULL;
  45901. #ifdef ASN_BER_TO_DER
  45902. int encodedSz = 0;
  45903. #endif
  45904. #ifdef ECC_TIMING_RESISTANT
  45905. WC_RNG rng;
  45906. #endif
  45907. word32 tempWrd32 = 0;
  45908. byte* tmpBytePtr = NULL;
  45909. const char input[] = "Test data to encode.";
  45910. int i;
  45911. int testSz = 0;
  45912. #if !defined(NO_RSA) && (!defined(NO_AES) || (!defined(NO_SHA) || \
  45913. !defined(NO_SHA256) || defined(WOLFSSL_SHA512)))
  45914. byte* rsaCert = NULL;
  45915. byte* rsaPrivKey = NULL;
  45916. word32 rsaCertSz;
  45917. word32 rsaPrivKeySz;
  45918. #if !defined(NO_FILESYSTEM) && (!defined(USE_CERT_BUFFERS_1024) && \
  45919. !defined(USE_CERT_BUFFERS_2048) )
  45920. static const char* rsaClientCert = "./certs/client-cert.der";
  45921. static const char* rsaClientKey = "./certs/client-key.der";
  45922. rsaCertSz = (word32)sizeof(rsaClientCert);
  45923. rsaPrivKeySz = (word32)sizeof(rsaClientKey);
  45924. #endif
  45925. #endif
  45926. #if defined(HAVE_ECC) && (!defined(NO_AES) || (!defined(NO_SHA) ||\
  45927. !defined(NO_SHA256) || defined(WOLFSSL_SHA512)))
  45928. byte* eccCert = NULL;
  45929. byte* eccPrivKey = NULL;
  45930. word32 eccCertSz;
  45931. word32 eccPrivKeySz;
  45932. #if !defined(NO_FILESYSTEM) && !defined(USE_CERT_BUFFERS_256)
  45933. static const char* eccClientCert = "./certs/client-ecc-cert.der";
  45934. static const char* eccClientKey = "./certs/ecc-client-key.der";
  45935. #endif
  45936. #endif
  45937. /* Generic buffer size. */
  45938. byte output[ONEK_BUF];
  45939. byte decoded[sizeof(input)/sizeof(char)];
  45940. int decodedSz = 0;
  45941. #ifndef NO_FILESYSTEM
  45942. XFILE certFile = XBADFILE;
  45943. XFILE keyFile = XBADFILE;
  45944. #endif
  45945. #ifdef ECC_TIMING_RESISTANT
  45946. XMEMSET(&rng, 0, sizeof(WC_RNG));
  45947. #endif
  45948. #if !defined(NO_RSA) && (!defined(NO_AES) || (!defined(NO_SHA) ||\
  45949. !defined(NO_SHA256) || defined(WOLFSSL_SHA512)))
  45950. /* RSA certs and keys. */
  45951. #if defined(USE_CERT_BUFFERS_1024)
  45952. rsaCertSz = (word32)sizeof_client_cert_der_1024;
  45953. /* Allocate buffer space. */
  45954. ExpectNotNull(rsaCert = (byte*)XMALLOC(rsaCertSz, HEAP_HINT,
  45955. DYNAMIC_TYPE_TMP_BUFFER));
  45956. /* Init buffer. */
  45957. if (rsaCert != NULL) {
  45958. XMEMCPY(rsaCert, client_cert_der_1024, rsaCertSz);
  45959. }
  45960. rsaPrivKeySz = (word32)sizeof_client_key_der_1024;
  45961. ExpectNotNull(rsaPrivKey = (byte*)XMALLOC(rsaPrivKeySz, HEAP_HINT,
  45962. DYNAMIC_TYPE_TMP_BUFFER));
  45963. if (rsaPrivKey != NULL) {
  45964. XMEMCPY(rsaPrivKey, client_key_der_1024, rsaPrivKeySz);
  45965. }
  45966. #elif defined(USE_CERT_BUFFERS_2048)
  45967. rsaCertSz = (word32)sizeof_client_cert_der_2048;
  45968. /* Allocate buffer */
  45969. ExpectNotNull(rsaCert = (byte*)XMALLOC(rsaCertSz, HEAP_HINT,
  45970. DYNAMIC_TYPE_TMP_BUFFER));
  45971. /* Init buffer. */
  45972. if (rsaCert != NULL) {
  45973. XMEMCPY(rsaCert, client_cert_der_2048, rsaCertSz);
  45974. }
  45975. rsaPrivKeySz = (word32)sizeof_client_key_der_2048;
  45976. ExpectNotNull(rsaPrivKey = (byte*)XMALLOC(rsaPrivKeySz, HEAP_HINT,
  45977. DYNAMIC_TYPE_TMP_BUFFER));
  45978. if (rsaPrivKey != NULL) {
  45979. XMEMCPY(rsaPrivKey, client_key_der_2048, rsaPrivKeySz);
  45980. }
  45981. #else
  45982. /* File system. */
  45983. ExpectTrue((certFile = XFOPEN(rsaClientCert, "rb")) != XBADFILE);
  45984. rsaCertSz = (word32)FOURK_BUF;
  45985. ExpectNotNull(rsaCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  45986. DYNAMIC_TYPE_TMP_BUFFER));
  45987. ExpectTrue((rsaCertSz = (word32)XFREAD(rsaCert, 1, rsaCertSz,
  45988. certFile)) > 0);
  45989. if (certFile != XBADFILE)
  45990. XFCLOSE(certFile);
  45991. ExpectTrue((keyFile = XFOPEN(rsaClientKey, "rb")) != XBADFILE);
  45992. ExpectNotNull(rsaPrivKey = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  45993. DYNAMIC_TYPE_TMP_BUFFER));
  45994. rsaPrivKeySz = (word32)FOURK_BUF;
  45995. ExpectTrue((rsaPrivKeySz = (word32)XFREAD(rsaPrivKey, 1, rsaPrivKeySz,
  45996. keyFile)) > 0);
  45997. if (keyFile != XBADFILE)
  45998. XFCLOSE(keyFile);
  45999. #endif /* USE_CERT_BUFFERS */
  46000. #endif /* NO_RSA */
  46001. /* ECC */
  46002. #if defined(HAVE_ECC) && (!defined(NO_AES) || (!defined(NO_SHA) ||\
  46003. !defined(NO_SHA256) || defined(WOLFSSL_SHA512)))
  46004. #ifdef USE_CERT_BUFFERS_256
  46005. ExpectNotNull(eccCert = (byte*)XMALLOC(TWOK_BUF, HEAP_HINT,
  46006. DYNAMIC_TYPE_TMP_BUFFER));
  46007. /* Init buffer. */
  46008. eccCertSz = (word32)sizeof_cliecc_cert_der_256;
  46009. if (eccCert != NULL) {
  46010. XMEMCPY(eccCert, cliecc_cert_der_256, eccCertSz);
  46011. }
  46012. ExpectNotNull(eccPrivKey = (byte*)XMALLOC(TWOK_BUF, HEAP_HINT,
  46013. DYNAMIC_TYPE_TMP_BUFFER));
  46014. eccPrivKeySz = (word32)sizeof_ecc_clikey_der_256;
  46015. if (eccPrivKey != NULL) {
  46016. XMEMCPY(eccPrivKey, ecc_clikey_der_256, eccPrivKeySz);
  46017. }
  46018. #else /* File system. */
  46019. ExpectTrue((certFile = XFOPEN(eccClientCert, "rb")) != XBADFILE);
  46020. eccCertSz = (word32)FOURK_BUF;
  46021. ExpectNotNull(eccCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  46022. DYNAMIC_TYPE_TMP_BUFFER));
  46023. ExpectTrue((eccCertSz = (word32)XFREAD(eccCert, 1, eccCertSz,
  46024. certFile)) > 0);
  46025. if (certFile != XBADFILE) {
  46026. XFCLOSE(certFile);
  46027. }
  46028. ExpectTrue((keyFile = XFOPEN(eccClientKey, "rb")) != XBADFILE);
  46029. eccPrivKeySz = (word32)FOURK_BUF;
  46030. ExpectNotNull(eccPrivKey = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  46031. DYNAMIC_TYPE_TMP_BUFFER));
  46032. ExpectTrue((eccPrivKeySz = (word32)XFREAD(eccPrivKey, 1, eccPrivKeySz,
  46033. keyFile)) > 0);
  46034. if (keyFile != XBADFILE) {
  46035. XFCLOSE(keyFile);
  46036. }
  46037. #endif /* USE_CERT_BUFFERS_256 */
  46038. #endif /* END HAVE_ECC */
  46039. #ifndef NO_FILESYSTEM
  46040. /* Silence. */
  46041. (void)keyFile;
  46042. (void)certFile;
  46043. #endif
  46044. {
  46045. const pkcs7EnvelopedVector testVectors[] = {
  46046. /* DATA is a global variable defined in the makefile. */
  46047. #if !defined(NO_RSA)
  46048. #ifndef NO_DES3
  46049. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA, DES3b, 0, 0,
  46050. rsaCert, rsaCertSz, rsaPrivKey, rsaPrivKeySz},
  46051. #endif /* NO_DES3 */
  46052. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  46053. #ifndef NO_AES_128
  46054. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA, AES128CBCb,
  46055. 0, 0, rsaCert, rsaCertSz, rsaPrivKey, rsaPrivKeySz},
  46056. #endif
  46057. #ifndef NO_AES_192
  46058. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA, AES192CBCb,
  46059. 0, 0, rsaCert, rsaCertSz, rsaPrivKey, rsaPrivKeySz},
  46060. #endif
  46061. #ifndef NO_AES_256
  46062. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA, AES256CBCb,
  46063. 0, 0, rsaCert, rsaCertSz, rsaPrivKey, rsaPrivKeySz},
  46064. #endif
  46065. #endif /* NO_AES && HAVE_AES_CBC */
  46066. #endif /* NO_RSA */
  46067. #if defined(HAVE_ECC)
  46068. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  46069. #if !defined(NO_SHA) && !defined(NO_AES_128)
  46070. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA,
  46071. AES128CBCb, AES128_WRAP, dhSinglePass_stdDH_sha1kdf_scheme,
  46072. eccCert, eccCertSz, eccPrivKey, eccPrivKeySz},
  46073. #endif
  46074. #if !defined(NO_SHA256) && !defined(NO_AES_256)
  46075. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA,
  46076. AES256CBCb, AES256_WRAP, dhSinglePass_stdDH_sha256kdf_scheme,
  46077. eccCert, eccCertSz, eccPrivKey, eccPrivKeySz},
  46078. #endif
  46079. #if defined(WOLFSSL_SHA512) && !defined(NO_AES_256)
  46080. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA,
  46081. AES256CBCb, AES256_WRAP, dhSinglePass_stdDH_sha512kdf_scheme,
  46082. eccCert, eccCertSz, eccPrivKey, eccPrivKeySz},
  46083. #endif
  46084. #endif /* NO_AES && HAVE_AES_CBC*/
  46085. #endif /* END HAVE_ECC */
  46086. }; /* END pkcs7EnvelopedVector */
  46087. #ifdef ECC_TIMING_RESISTANT
  46088. ExpectIntEQ(wc_InitRng(&rng), 0);
  46089. #endif
  46090. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46091. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, testDevId), 0);
  46092. testSz = (int)sizeof(testVectors)/(int)sizeof(pkcs7EnvelopedVector);
  46093. for (i = 0; i < testSz; i++) {
  46094. #ifdef ASN_BER_TO_DER
  46095. encodeSignedDataStream strm;
  46096. /* test setting stream mode, the first one using IO callbacks */
  46097. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (testVectors + i)->cert,
  46098. (word32)(testVectors + i)->certSz), 0);
  46099. if (pkcs7 != NULL) {
  46100. #ifdef ECC_TIMING_RESISTANT
  46101. pkcs7->rng = &rng;
  46102. #endif
  46103. if (i != 0)
  46104. pkcs7->content = (byte*)(testVectors + i)->content;
  46105. pkcs7->contentSz = (testVectors + i)->contentSz;
  46106. pkcs7->contentOID = (testVectors + i)->contentOID;
  46107. pkcs7->encryptOID = (testVectors + i)->encryptOID;
  46108. pkcs7->keyWrapOID = (testVectors + i)->keyWrapOID;
  46109. pkcs7->keyAgreeOID = (testVectors + i)->keyAgreeOID;
  46110. pkcs7->privateKey = (testVectors + i)->privateKey;
  46111. pkcs7->privateKeySz = (testVectors + i)->privateKeySz;
  46112. }
  46113. if (i == 0) {
  46114. XMEMSET(&strm, 0, sizeof(strm));
  46115. ExpectIntEQ(wc_PKCS7_SetStreamMode(pkcs7, 1, GetContentCB,
  46116. StreamOutputCB, (void*)&strm), 0);
  46117. encodedSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, NULL, 0);
  46118. }
  46119. else {
  46120. ExpectIntEQ(wc_PKCS7_SetStreamMode(pkcs7, 1, NULL, NULL, NULL), 0);
  46121. encodedSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, output,
  46122. (word32)sizeof(output));
  46123. }
  46124. switch ((testVectors + i)->encryptOID) {
  46125. #ifndef NO_DES3
  46126. case DES3b:
  46127. case DESb:
  46128. ExpectIntEQ(encodedSz, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46129. break;
  46130. #endif
  46131. #ifdef HAVE_AESCCM
  46132. #ifdef WOLFSSL_AES_128
  46133. case AES128CCMb:
  46134. ExpectIntEQ(encodedSz, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46135. break;
  46136. #endif
  46137. #ifdef WOLFSSL_AES_192
  46138. case AES192CCMb:
  46139. ExpectIntEQ(encodedSz, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46140. break;
  46141. #endif
  46142. #ifdef WOLFSSL_AES_256
  46143. case AES256CCMb:
  46144. ExpectIntEQ(encodedSz, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46145. break;
  46146. #endif
  46147. #endif
  46148. default:
  46149. ExpectIntGE(encodedSz, 0);
  46150. }
  46151. if (encodedSz > 0) {
  46152. if (i == 0) {
  46153. decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7,
  46154. strm.out, (word32)encodedSz, decoded,
  46155. (word32)sizeof(decoded));
  46156. }
  46157. else {
  46158. decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  46159. (word32)encodedSz, decoded, (word32)sizeof(decoded));
  46160. }
  46161. ExpectIntGE(decodedSz, 0);
  46162. /* Verify the size of each buffer. */
  46163. ExpectIntEQ((word32)sizeof(input)/sizeof(char), decodedSz);
  46164. }
  46165. wc_PKCS7_Free(pkcs7);
  46166. pkcs7 = NULL;
  46167. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46168. #endif
  46169. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (testVectors + i)->cert,
  46170. (word32)(testVectors + i)->certSz), 0);
  46171. if (pkcs7 != NULL) {
  46172. #ifdef ECC_TIMING_RESISTANT
  46173. pkcs7->rng = &rng;
  46174. #endif
  46175. pkcs7->content = (byte*)(testVectors + i)->content;
  46176. pkcs7->contentSz = (testVectors + i)->contentSz;
  46177. pkcs7->contentOID = (testVectors + i)->contentOID;
  46178. pkcs7->encryptOID = (testVectors + i)->encryptOID;
  46179. pkcs7->keyWrapOID = (testVectors + i)->keyWrapOID;
  46180. pkcs7->keyAgreeOID = (testVectors + i)->keyAgreeOID;
  46181. pkcs7->privateKey = (testVectors + i)->privateKey;
  46182. pkcs7->privateKeySz = (testVectors + i)->privateKeySz;
  46183. }
  46184. #ifdef ASN_BER_TO_DER
  46185. /* test without setting stream mode */
  46186. ExpectIntEQ(wc_PKCS7_GetStreamMode(pkcs7), 0);
  46187. #endif
  46188. ExpectIntGE(wc_PKCS7_EncodeEnvelopedData(pkcs7, output,
  46189. (word32)sizeof(output)), 0);
  46190. decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  46191. (word32)sizeof(output), decoded, (word32)sizeof(decoded));
  46192. ExpectIntGE(decodedSz, 0);
  46193. /* Verify the size of each buffer. */
  46194. ExpectIntEQ((word32)sizeof(input)/sizeof(char), decodedSz);
  46195. /* Don't free the last time through the loop. */
  46196. if (i < testSz - 1) {
  46197. wc_PKCS7_Free(pkcs7);
  46198. pkcs7 = NULL;
  46199. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46200. }
  46201. } /* END test loop. */
  46202. }
  46203. /* Test bad args. */
  46204. ExpectIntEQ(wc_PKCS7_EncodeEnvelopedData(NULL, output,
  46205. (word32)sizeof(output)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46206. ExpectIntEQ(wc_PKCS7_EncodeEnvelopedData(pkcs7, NULL,
  46207. (word32)sizeof(output)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46208. ExpectIntEQ(wc_PKCS7_EncodeEnvelopedData(pkcs7, output, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46209. /* Decode. */
  46210. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(NULL, output,
  46211. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  46212. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46213. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  46214. (word32)sizeof(output), NULL, (word32)sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46215. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  46216. (word32)sizeof(output), decoded, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46217. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, NULL,
  46218. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  46219. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46220. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output, 0, decoded,
  46221. (word32)sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46222. /* Should get a return of BAD_FUNC_ARG with structure data. Order matters.*/
  46223. #if defined(HAVE_ECC) && !defined(NO_AES) && defined(HAVE_AES_CBC)
  46224. /* only a failure for KARI test cases */
  46225. if (pkcs7 != NULL) {
  46226. tempWrd32 = pkcs7->singleCertSz;
  46227. pkcs7->singleCertSz = 0;
  46228. }
  46229. #if defined(WOLFSSL_ASN_TEMPLATE)
  46230. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  46231. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  46232. WC_NO_ERR_TRACE(BUFFER_E));
  46233. #else
  46234. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  46235. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  46236. WC_NO_ERR_TRACE(ASN_PARSE_E));
  46237. #endif
  46238. if (pkcs7 != NULL) {
  46239. pkcs7->singleCertSz = tempWrd32;
  46240. tmpBytePtr = pkcs7->singleCert;
  46241. pkcs7->singleCert = NULL;
  46242. }
  46243. #ifndef NO_RSA
  46244. #if defined(NO_PKCS7_STREAM)
  46245. /* when none streaming mode is used and PKCS7 is in bad state buffer error
  46246. * is returned from kari parse which gets set to bad func arg */
  46247. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  46248. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  46249. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46250. #else
  46251. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  46252. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  46253. WC_NO_ERR_TRACE(ASN_PARSE_E));
  46254. #endif
  46255. #endif /* !NO_RSA */
  46256. if (pkcs7 != NULL) {
  46257. pkcs7->singleCert = tmpBytePtr;
  46258. }
  46259. #endif
  46260. if (pkcs7 != NULL) {
  46261. tempWrd32 = pkcs7->privateKeySz;
  46262. pkcs7->privateKeySz = 0;
  46263. }
  46264. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  46265. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  46266. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46267. if (pkcs7 != NULL) {
  46268. pkcs7->privateKeySz = tempWrd32;
  46269. tmpBytePtr = pkcs7->privateKey;
  46270. pkcs7->privateKey = NULL;
  46271. }
  46272. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  46273. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  46274. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46275. if (pkcs7 != NULL) {
  46276. pkcs7->privateKey = tmpBytePtr;
  46277. }
  46278. wc_PKCS7_Free(pkcs7);
  46279. pkcs7 = NULL;
  46280. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && !defined(NO_AES_256)
  46281. /* test of decrypt callback with KEKRI enveloped data */
  46282. {
  46283. int envelopedSz = 0;
  46284. const byte keyId[] = { 0x00 };
  46285. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46286. if (pkcs7 != NULL) {
  46287. pkcs7->content = (byte*)input;
  46288. pkcs7->contentSz = (word32)(sizeof(input)/sizeof(char));
  46289. pkcs7->contentOID = DATA;
  46290. pkcs7->encryptOID = AES256CBCb;
  46291. }
  46292. ExpectIntGT(wc_PKCS7_AddRecipient_KEKRI(pkcs7, AES256_WRAP,
  46293. (byte*)defKey, sizeof(defKey), (byte*)keyId,
  46294. sizeof(keyId), NULL, NULL, 0, NULL, 0, 0), 0);
  46295. ExpectIntEQ(wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID), 0);
  46296. ExpectIntGT((envelopedSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, output,
  46297. (word32)sizeof(output))), 0);
  46298. wc_PKCS7_Free(pkcs7);
  46299. pkcs7 = NULL;
  46300. /* decode envelopedData */
  46301. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46302. ExpectIntEQ(wc_PKCS7_SetWrapCEKCb(pkcs7, myCEKwrapFunc), 0);
  46303. ExpectIntEQ(wc_PKCS7_SetDecodeEncryptedCb(pkcs7, myDecryptionFunc), 0);
  46304. ExpectIntGT((decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  46305. (word32)envelopedSz, decoded, sizeof(decoded))), 0);
  46306. wc_PKCS7_Free(pkcs7);
  46307. pkcs7 = NULL;
  46308. }
  46309. #endif /* !NO_AES && !NO_AES_256 */
  46310. #ifndef NO_RSA
  46311. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46312. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46313. #endif /* NO_RSA */
  46314. #ifdef HAVE_ECC
  46315. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46316. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46317. #endif /* HAVE_ECC */
  46318. #ifdef ECC_TIMING_RESISTANT
  46319. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  46320. #endif
  46321. #if defined(USE_CERT_BUFFERS_2048) && !defined(NO_DES3) && \
  46322. !defined(NO_RSA) && !defined(NO_SHA)
  46323. {
  46324. byte out[7];
  46325. byte *cms = NULL;
  46326. word32 cmsSz;
  46327. XFILE cmsFile = XBADFILE;
  46328. XMEMSET(out, 0, sizeof(out));
  46329. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46330. ExpectTrue((cmsFile = XFOPEN("./certs/test/ktri-keyid-cms.msg", "rb"))
  46331. != XBADFILE);
  46332. cmsSz = (word32)FOURK_BUF;
  46333. ExpectNotNull(cms = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  46334. DYNAMIC_TYPE_TMP_BUFFER));
  46335. ExpectTrue((cmsSz = (word32)XFREAD(cms, 1, cmsSz, cmsFile)) > 0);
  46336. if (cmsFile != XBADFILE)
  46337. XFCLOSE(cmsFile);
  46338. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (byte*)client_cert_der_2048,
  46339. sizeof_client_cert_der_2048), 0);
  46340. if (pkcs7 != NULL) {
  46341. pkcs7->privateKey = (byte*)client_key_der_2048;
  46342. pkcs7->privateKeySz = sizeof_client_key_der_2048;
  46343. }
  46344. ExpectIntLT(wc_PKCS7_DecodeEnvelopedData(pkcs7, cms, cmsSz, out,
  46345. 2), 0);
  46346. ExpectIntGT(wc_PKCS7_DecodeEnvelopedData(pkcs7, cms, cmsSz, out,
  46347. sizeof(out)), 0);
  46348. XFREE(cms, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46349. ExpectIntEQ(XMEMCMP(out, "test", 4), 0);
  46350. wc_PKCS7_Free(pkcs7);
  46351. pkcs7 = NULL;
  46352. }
  46353. #endif /* USE_CERT_BUFFERS_2048 && !NO_DES3 && !NO_RSA && !NO_SHA */
  46354. #endif /* HAVE_PKCS7 */
  46355. return EXPECT_RESULT();
  46356. } /* END test_wc_PKCS7_EncodeDecodeEnvelopedData() */
  46357. /*
  46358. * Testing wc_PKCS7_EncodeEncryptedData()
  46359. */
  46360. static int test_wc_PKCS7_EncodeEncryptedData(void)
  46361. {
  46362. EXPECT_DECLS;
  46363. #if defined(HAVE_PKCS7) && !defined(NO_PKCS7_ENCRYPTED_DATA)
  46364. PKCS7* pkcs7 = NULL;
  46365. byte* tmpBytePtr = NULL;
  46366. byte encrypted[TWOK_BUF];
  46367. byte decoded[TWOK_BUF];
  46368. word32 tmpWrd32 = 0;
  46369. int tmpInt = 0;
  46370. int decodedSz = 0;
  46371. int encryptedSz = 0;
  46372. int testSz = 0;
  46373. int i = 0;
  46374. const byte data[] = { /* Hello World */
  46375. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  46376. 0x72,0x6c,0x64
  46377. };
  46378. #ifndef NO_DES3
  46379. byte desKey[] = {
  46380. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef
  46381. };
  46382. byte des3Key[] = {
  46383. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  46384. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  46385. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  46386. };
  46387. #endif
  46388. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  46389. #ifndef NO_AES_128
  46390. byte aes128Key[] = {
  46391. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46392. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  46393. };
  46394. #endif
  46395. #ifndef NO_AES_192
  46396. byte aes192Key[] = {
  46397. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46398. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46399. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  46400. };
  46401. #endif
  46402. #ifndef NO_AES_256
  46403. byte aes256Key[] = {
  46404. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46405. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46406. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46407. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  46408. };
  46409. #endif
  46410. #endif /* !NO_AES && HAVE_AES_CBC */
  46411. const pkcs7EncryptedVector testVectors[] =
  46412. {
  46413. #ifndef NO_DES3
  46414. {data, (word32)sizeof(data), DATA, DES3b, des3Key, sizeof(des3Key)},
  46415. {data, (word32)sizeof(data), DATA, DESb, desKey, sizeof(desKey)},
  46416. #endif /* !NO_DES3 */
  46417. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  46418. #ifndef NO_AES_128
  46419. {data, (word32)sizeof(data), DATA, AES128CBCb, aes128Key,
  46420. sizeof(aes128Key)},
  46421. #endif
  46422. #ifndef NO_AES_192
  46423. {data, (word32)sizeof(data), DATA, AES192CBCb, aes192Key,
  46424. sizeof(aes192Key)},
  46425. #endif
  46426. #ifndef NO_AES_256
  46427. {data, (word32)sizeof(data), DATA, AES256CBCb, aes256Key,
  46428. sizeof(aes256Key)},
  46429. #endif
  46430. #endif /* !NO_AES && HAVE_AES_CBC */
  46431. };
  46432. testSz = sizeof(testVectors) / sizeof(pkcs7EncryptedVector);
  46433. for (i = 0; i < testSz; i++) {
  46434. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46435. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, testDevId), 0);
  46436. if (pkcs7 != NULL) {
  46437. pkcs7->content = (byte*)testVectors[i].content;
  46438. pkcs7->contentSz = testVectors[i].contentSz;
  46439. pkcs7->contentOID = testVectors[i].contentOID;
  46440. pkcs7->encryptOID = testVectors[i].encryptOID;
  46441. pkcs7->encryptionKey = testVectors[i].encryptionKey;
  46442. pkcs7->encryptionKeySz = testVectors[i].encryptionKeySz;
  46443. pkcs7->heap = HEAP_HINT;
  46444. }
  46445. /* encode encryptedData */
  46446. ExpectIntGT(encryptedSz = wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  46447. sizeof(encrypted)), 0);
  46448. /* Decode encryptedData */
  46449. ExpectIntGT(decodedSz = wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted,
  46450. (word32)encryptedSz, decoded, sizeof(decoded)), 0);
  46451. ExpectIntEQ(XMEMCMP(decoded, data, decodedSz), 0);
  46452. /* Keep values for last itr. */
  46453. if (i < testSz - 1) {
  46454. wc_PKCS7_Free(pkcs7);
  46455. pkcs7 = NULL;
  46456. }
  46457. }
  46458. if (pkcs7 == NULL || testSz == 0) {
  46459. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46460. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, testDevId), 0);
  46461. }
  46462. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(NULL, encrypted,
  46463. sizeof(encrypted)),WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46464. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, NULL,
  46465. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46466. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  46467. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46468. /* Testing the struct. */
  46469. if (pkcs7 != NULL) {
  46470. tmpBytePtr = pkcs7->content;
  46471. pkcs7->content = NULL;
  46472. }
  46473. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  46474. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46475. if (pkcs7 != NULL) {
  46476. pkcs7->content = tmpBytePtr;
  46477. tmpWrd32 = pkcs7->contentSz;
  46478. pkcs7->contentSz = 0;
  46479. }
  46480. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  46481. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46482. if (pkcs7 != NULL) {
  46483. pkcs7->contentSz = tmpWrd32;
  46484. tmpInt = pkcs7->encryptOID;
  46485. pkcs7->encryptOID = 0;
  46486. }
  46487. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  46488. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46489. if (pkcs7 != NULL) {
  46490. pkcs7->encryptOID = tmpInt;
  46491. tmpBytePtr = pkcs7->encryptionKey;
  46492. pkcs7->encryptionKey = NULL;
  46493. }
  46494. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  46495. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46496. if (pkcs7 != NULL) {
  46497. pkcs7->encryptionKey = tmpBytePtr;
  46498. tmpWrd32 = pkcs7->encryptionKeySz;
  46499. pkcs7->encryptionKeySz = 0;
  46500. }
  46501. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  46502. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46503. if (pkcs7 != NULL) {
  46504. pkcs7->encryptionKeySz = tmpWrd32;
  46505. }
  46506. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(NULL, encrypted, (word32)encryptedSz,
  46507. decoded, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46508. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, NULL, (word32)encryptedSz,
  46509. decoded, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46510. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, 0,
  46511. decoded, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46512. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, (word32)encryptedSz,
  46513. NULL, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46514. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, (word32)encryptedSz,
  46515. decoded, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46516. /* Test struct fields */
  46517. if (pkcs7 != NULL) {
  46518. tmpBytePtr = pkcs7->encryptionKey;
  46519. pkcs7->encryptionKey = NULL;
  46520. }
  46521. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, (word32)encryptedSz,
  46522. decoded, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46523. if (pkcs7 != NULL) {
  46524. pkcs7->encryptionKey = tmpBytePtr;
  46525. pkcs7->encryptionKeySz = 0;
  46526. }
  46527. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, (word32)encryptedSz,
  46528. decoded, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46529. wc_PKCS7_Free(pkcs7);
  46530. #endif
  46531. return EXPECT_RESULT();
  46532. } /* END test_wc_PKCS7_EncodeEncryptedData() */
  46533. /*
  46534. * Testing wc_PKCS7_Degenerate()
  46535. */
  46536. static int test_wc_PKCS7_Degenerate(void)
  46537. {
  46538. EXPECT_DECLS;
  46539. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM)
  46540. PKCS7* pkcs7 = NULL;
  46541. char fName[] = "./certs/test-degenerate.p7b";
  46542. XFILE f = XBADFILE;
  46543. byte der[4096];
  46544. word32 derSz = 0;
  46545. #ifndef NO_PKCS7_STREAM
  46546. word32 z;
  46547. int ret;
  46548. #endif /* !NO_PKCS7_STREAM */
  46549. ExpectTrue((f = XFOPEN(fName, "rb")) != XBADFILE);
  46550. ExpectTrue((derSz = (word32)XFREAD(der, 1, sizeof(der), f)) > 0);
  46551. if (f != XBADFILE)
  46552. XFCLOSE(f);
  46553. /* test degenerate success */
  46554. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46555. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  46556. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46557. #ifndef NO_RSA
  46558. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, der, derSz), 0);
  46559. #ifndef NO_PKCS7_STREAM
  46560. wc_PKCS7_Free(pkcs7);
  46561. pkcs7 = NULL;
  46562. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46563. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  46564. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46565. /* test for streaming */
  46566. ret = -1;
  46567. for (z = 0; z < derSz && ret != 0; z++) {
  46568. ret = wc_PKCS7_VerifySignedData(pkcs7, der + z, 1);
  46569. if (ret < 0){
  46570. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  46571. }
  46572. }
  46573. ExpectIntEQ(ret, 0);
  46574. #endif /* !NO_PKCS7_STREAM */
  46575. #else
  46576. ExpectIntNE(wc_PKCS7_VerifySignedData(pkcs7, der, derSz), 0);
  46577. #endif /* NO_RSA */
  46578. wc_PKCS7_Free(pkcs7);
  46579. pkcs7 = NULL;
  46580. /* test with turning off degenerate cases */
  46581. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46582. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  46583. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46584. wc_PKCS7_AllowDegenerate(pkcs7, 0); /* override allowing degenerate case */
  46585. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, der, derSz),
  46586. WC_NO_ERR_TRACE(PKCS7_NO_SIGNER_E));
  46587. #ifndef NO_PKCS7_STREAM
  46588. wc_PKCS7_Free(pkcs7);
  46589. pkcs7 = NULL;
  46590. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46591. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  46592. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46593. wc_PKCS7_AllowDegenerate(pkcs7, 0); /* override allowing degenerate case */
  46594. /* test for streaming */
  46595. ret = -1;
  46596. for (z = 0; z < derSz && ret != 0; z++) {
  46597. ret = wc_PKCS7_VerifySignedData(pkcs7, der + z, 1);
  46598. if (ret == WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)){
  46599. continue;
  46600. }
  46601. else
  46602. break;
  46603. }
  46604. ExpectIntEQ(ret, WC_NO_ERR_TRACE(PKCS7_NO_SIGNER_E));
  46605. #endif /* !NO_PKCS7_STREAM */
  46606. wc_PKCS7_Free(pkcs7);
  46607. #endif
  46608. return EXPECT_RESULT();
  46609. } /* END test_wc_PKCS7_Degenerate() */
  46610. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && \
  46611. defined(ASN_BER_TO_DER) && !defined(NO_DES3) && !defined(NO_SHA)
  46612. static byte berContent[] = {
  46613. 0x30, 0x80, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86,
  46614. 0xF7, 0x0D, 0x01, 0x07, 0x03, 0xA0, 0x80, 0x30,
  46615. 0x80, 0x02, 0x01, 0x00, 0x31, 0x82, 0x01, 0x48,
  46616. 0x30, 0x82, 0x01, 0x44, 0x02, 0x01, 0x00, 0x30,
  46617. 0x81, 0xAC, 0x30, 0x81, 0x9E, 0x31, 0x0B, 0x30,
  46618. 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,
  46619. 0x55, 0x53, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03,
  46620. 0x55, 0x04, 0x08, 0x0C, 0x07, 0x4D, 0x6F, 0x6E,
  46621. 0x74, 0x61, 0x6E, 0x61, 0x31, 0x10, 0x30, 0x0E,
  46622. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0C, 0x07, 0x42,
  46623. 0x6F, 0x7A, 0x65, 0x6D, 0x61, 0x6E, 0x31, 0x15,
  46624. 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C,
  46625. 0x0C, 0x77, 0x6F, 0x6C, 0x66, 0x53, 0x53, 0x4C,
  46626. 0x5F, 0x31, 0x30, 0x32, 0x34, 0x31, 0x19, 0x30,
  46627. 0x17, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x10,
  46628. 0x50, 0x72, 0x6F, 0x67, 0x72, 0x61, 0x6D, 0x6D,
  46629. 0x69, 0x6E, 0x67, 0x2D, 0x31, 0x30, 0x32, 0x34,
  46630. 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04,
  46631. 0x03, 0x0C, 0x0F, 0x77, 0x77, 0x77, 0x2E, 0x77,
  46632. 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63,
  46633. 0x6F, 0x6D, 0x31, 0x1F, 0x30, 0x1D, 0x06, 0x09,
  46634. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09,
  46635. 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40,
  46636. 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E,
  46637. 0x63, 0x6F, 0x6D, 0x02, 0x09, 0x00, 0xBB, 0xD3,
  46638. 0x10, 0x03, 0xE6, 0x9D, 0x28, 0x03, 0x30, 0x0D,
  46639. 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  46640. 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x81, 0x80,
  46641. 0x2F, 0xF9, 0x77, 0x4F, 0x04, 0x5C, 0x16, 0x62,
  46642. 0xF0, 0x77, 0x8D, 0x95, 0x4C, 0xB1, 0x44, 0x9A,
  46643. 0x8C, 0x3C, 0x8C, 0xE4, 0xD1, 0xC1, 0x14, 0x72,
  46644. 0xD0, 0x4A, 0x1A, 0x94, 0x27, 0x0F, 0xAA, 0xE8,
  46645. 0xD0, 0xA2, 0xE7, 0xED, 0x4C, 0x7F, 0x0F, 0xC7,
  46646. 0x1B, 0xFB, 0x81, 0x0E, 0x76, 0x8F, 0xDD, 0x32,
  46647. 0x11, 0x68, 0xA0, 0x13, 0xD2, 0x8D, 0x95, 0xEF,
  46648. 0x80, 0x53, 0x81, 0x0E, 0x1F, 0xC8, 0xD6, 0x76,
  46649. 0x5C, 0x31, 0xD3, 0x77, 0x33, 0x29, 0xA6, 0x1A,
  46650. 0xD3, 0xC6, 0x14, 0x36, 0xCA, 0x8E, 0x7D, 0x72,
  46651. 0xA0, 0x29, 0x4C, 0xC7, 0x3A, 0xAF, 0xFE, 0xF7,
  46652. 0xFC, 0xD7, 0xE2, 0x8F, 0x6A, 0x20, 0x46, 0x09,
  46653. 0x40, 0x22, 0x2D, 0x79, 0x38, 0x11, 0xB1, 0x4A,
  46654. 0xE3, 0x48, 0xE8, 0x10, 0x37, 0xA0, 0x22, 0xF7,
  46655. 0xB4, 0x79, 0xD1, 0xA9, 0x3D, 0xC2, 0xAB, 0x37,
  46656. 0xAE, 0x82, 0x68, 0x1A, 0x16, 0xEF, 0x33, 0x0C,
  46657. 0x30, 0x80, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86,
  46658. 0xF7, 0x0D, 0x01, 0x07, 0x01, 0x30, 0x14, 0x06,
  46659. 0x08, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x03,
  46660. 0x07, 0x04, 0x08, 0xAD, 0xD0, 0x38, 0x9B, 0x16,
  46661. 0x4B, 0x7F, 0x99, 0xA0, 0x80, 0x04, 0x82, 0x03,
  46662. 0xE8, 0x6D, 0x48, 0xFB, 0x8A, 0xBD, 0xED, 0x6C,
  46663. 0xCD, 0xC6, 0x48, 0xFD, 0xB7, 0xB0, 0x7C, 0x86,
  46664. 0x2C, 0x8D, 0xF0, 0x23, 0x12, 0xD8, 0xA3, 0x2A,
  46665. 0x21, 0x6F, 0x8B, 0x75, 0xBB, 0x47, 0x7F, 0xC9,
  46666. 0xBA, 0xBA, 0xFF, 0x91, 0x09, 0x01, 0x7A, 0x5C,
  46667. 0x96, 0x02, 0xB8, 0x8E, 0xF8, 0x67, 0x7E, 0x8F,
  46668. 0xF9, 0x51, 0x0E, 0xFF, 0x8E, 0xE2, 0x61, 0xC0,
  46669. 0xDF, 0xFA, 0xE2, 0x4C, 0x50, 0x90, 0xAE, 0xA1,
  46670. 0x15, 0x38, 0x3D, 0xBE, 0x88, 0xD7, 0x57, 0xC0,
  46671. 0x11, 0x44, 0xA2, 0x61, 0x05, 0x49, 0x6A, 0x94,
  46672. 0x04, 0x10, 0xD9, 0xC2, 0x2D, 0x15, 0x20, 0x0D,
  46673. 0xBD, 0xA2, 0xEF, 0xE4, 0x68, 0xFA, 0x39, 0x75,
  46674. 0x7E, 0xD8, 0x64, 0x44, 0xCB, 0xE0, 0x00, 0x6D,
  46675. 0x57, 0x4E, 0x8A, 0x17, 0xA9, 0x83, 0x6C, 0x7F,
  46676. 0xFE, 0x01, 0xEE, 0xDE, 0x99, 0x3A, 0xB2, 0xFF,
  46677. 0xD3, 0x72, 0x78, 0xBA, 0xF1, 0x23, 0x54, 0x48,
  46678. 0x02, 0xD8, 0x38, 0xA9, 0x54, 0xE5, 0x4A, 0x81,
  46679. 0xB9, 0xC0, 0x67, 0xB2, 0x7D, 0x3C, 0x6F, 0xCE,
  46680. 0xA4, 0xDD, 0x34, 0x5F, 0x60, 0xB1, 0xA3, 0x7A,
  46681. 0xE4, 0x43, 0xF2, 0x89, 0x64, 0x35, 0x09, 0x32,
  46682. 0x51, 0xFB, 0x5C, 0x67, 0x0C, 0x3B, 0xFC, 0x36,
  46683. 0x6B, 0x37, 0x43, 0x6C, 0x03, 0xCD, 0x44, 0xC7,
  46684. 0x2B, 0x62, 0xD6, 0xD1, 0xF4, 0x07, 0x7B, 0x19,
  46685. 0x91, 0xF0, 0xD7, 0xF5, 0x54, 0xBC, 0x0F, 0x42,
  46686. 0x6B, 0x69, 0xF7, 0xA3, 0xC8, 0xEE, 0xB9, 0x7A,
  46687. 0x9E, 0x3D, 0xDF, 0x53, 0x47, 0xF7, 0x50, 0x67,
  46688. 0x00, 0xCF, 0x2B, 0x3B, 0xE9, 0x85, 0xEE, 0xBD,
  46689. 0x4C, 0x64, 0x66, 0x0B, 0x77, 0x80, 0x9D, 0xEF,
  46690. 0x11, 0x32, 0x77, 0xA8, 0xA4, 0x5F, 0xEE, 0x2D,
  46691. 0xE0, 0x43, 0x87, 0x76, 0x87, 0x53, 0x4E, 0xD7,
  46692. 0x1A, 0x04, 0x7B, 0xE1, 0xD1, 0xE1, 0xF5, 0x87,
  46693. 0x51, 0x13, 0xE0, 0xC2, 0xAA, 0xA3, 0x4B, 0xAA,
  46694. 0x9E, 0xB4, 0xA6, 0x1D, 0x4E, 0x28, 0x57, 0x0B,
  46695. 0x80, 0x90, 0x81, 0x4E, 0x04, 0xF5, 0x30, 0x8D,
  46696. 0x51, 0xCE, 0x57, 0x2F, 0x88, 0xC5, 0x70, 0xC4,
  46697. 0x06, 0x8F, 0xDD, 0x37, 0xC1, 0x34, 0x1E, 0x0E,
  46698. 0x15, 0x32, 0x23, 0x92, 0xAB, 0x40, 0xEA, 0xF7,
  46699. 0x43, 0xE2, 0x1D, 0xE2, 0x4B, 0xC9, 0x91, 0xF4,
  46700. 0x63, 0x21, 0x34, 0xDB, 0xE9, 0x86, 0x83, 0x1A,
  46701. 0xD2, 0x52, 0xEF, 0x7A, 0xA2, 0xEE, 0xA4, 0x11,
  46702. 0x56, 0xD3, 0x6C, 0xF5, 0x6D, 0xE4, 0xA5, 0x2D,
  46703. 0x99, 0x02, 0x10, 0xDF, 0x29, 0xC5, 0xE3, 0x0B,
  46704. 0xC4, 0xA1, 0xEE, 0x5F, 0x4A, 0x10, 0xEE, 0x85,
  46705. 0x73, 0x2A, 0x92, 0x15, 0x2C, 0xC8, 0xF4, 0x8C,
  46706. 0xD7, 0x3D, 0xBC, 0xAD, 0x18, 0xE0, 0x59, 0xD3,
  46707. 0xEE, 0x75, 0x90, 0x1C, 0xCC, 0x76, 0xC6, 0x64,
  46708. 0x17, 0xD2, 0xD0, 0x91, 0xA6, 0xD0, 0xC1, 0x4A,
  46709. 0xAA, 0x58, 0x22, 0xEC, 0x45, 0x98, 0xF2, 0xCC,
  46710. 0x4C, 0xE4, 0xBF, 0xED, 0xF6, 0x44, 0x72, 0x36,
  46711. 0x65, 0x3F, 0xE3, 0xB5, 0x8B, 0x3E, 0x54, 0x9C,
  46712. 0x82, 0x86, 0x5E, 0xB0, 0xF2, 0x12, 0xE5, 0x69,
  46713. 0xFA, 0x46, 0xA2, 0x54, 0xFC, 0xF5, 0x4B, 0xE0,
  46714. 0x24, 0x3B, 0x99, 0x04, 0x1A, 0x7A, 0xF7, 0xD1,
  46715. 0xFF, 0x68, 0x97, 0xB2, 0x85, 0x82, 0x95, 0x27,
  46716. 0x2B, 0xF4, 0xE7, 0x1A, 0x74, 0x19, 0xEC, 0x8C,
  46717. 0x4E, 0xA7, 0x0F, 0xAD, 0x4F, 0x5A, 0x02, 0x80,
  46718. 0xC1, 0x6A, 0x9E, 0x54, 0xE4, 0x8E, 0xA3, 0x41,
  46719. 0x3F, 0x6F, 0x9C, 0x82, 0x9F, 0x83, 0xB0, 0x44,
  46720. 0x01, 0x5F, 0x10, 0x9D, 0xD3, 0xB6, 0x33, 0x5B,
  46721. 0xAF, 0xAC, 0x6B, 0x57, 0x2A, 0x01, 0xED, 0x0E,
  46722. 0x17, 0xB9, 0x80, 0x76, 0x12, 0x1C, 0x51, 0x56,
  46723. 0xDD, 0x6D, 0x94, 0xAB, 0xD2, 0xE5, 0x15, 0x2D,
  46724. 0x3C, 0xC5, 0xE8, 0x62, 0x05, 0x8B, 0x40, 0xB1,
  46725. 0xC2, 0x83, 0xCA, 0xAC, 0x4B, 0x8B, 0x39, 0xF7,
  46726. 0xA0, 0x08, 0x43, 0x5C, 0xF7, 0xE8, 0xED, 0x40,
  46727. 0x72, 0x73, 0xE3, 0x6B, 0x18, 0x67, 0xA0, 0xB6,
  46728. 0x0F, 0xED, 0x8F, 0x9A, 0xE4, 0x27, 0x62, 0x23,
  46729. 0xAA, 0x6D, 0x6C, 0x31, 0xC9, 0x9D, 0x6B, 0xE0,
  46730. 0xBF, 0x9D, 0x7D, 0x2E, 0x76, 0x71, 0x06, 0x39,
  46731. 0xAC, 0x96, 0x1C, 0xAF, 0x30, 0xF2, 0x62, 0x9C,
  46732. 0x84, 0x3F, 0x43, 0x5E, 0x19, 0xA8, 0xE5, 0x3C,
  46733. 0x9D, 0x43, 0x3C, 0x43, 0x41, 0xE8, 0x82, 0xE7,
  46734. 0x5B, 0xF3, 0xE2, 0x15, 0xE3, 0x52, 0x20, 0xFD,
  46735. 0x0D, 0xB2, 0x4D, 0x48, 0xAD, 0x53, 0x7E, 0x0C,
  46736. 0xF0, 0xB9, 0xBE, 0xC9, 0x58, 0x4B, 0xC8, 0xA8,
  46737. 0xA3, 0x36, 0xF1, 0x2C, 0xD2, 0xE1, 0xC8, 0xC4,
  46738. 0x3C, 0x48, 0x70, 0xC2, 0x6D, 0x6C, 0x3D, 0x99,
  46739. 0xAC, 0x43, 0x19, 0x69, 0xCA, 0x67, 0x1A, 0xC9,
  46740. 0xE1, 0x47, 0xFA, 0x0A, 0xE6, 0x5B, 0x6F, 0x61,
  46741. 0xD0, 0x03, 0xE4, 0x03, 0x4B, 0xFD, 0xE2, 0xA5,
  46742. 0x8D, 0x83, 0x01, 0x7E, 0xC0, 0x7B, 0x2E, 0x0B,
  46743. 0x29, 0xDD, 0xD6, 0xDC, 0x71, 0x46, 0xBD, 0x9A,
  46744. 0x40, 0x46, 0x1E, 0x0A, 0xB1, 0x00, 0xE7, 0x71,
  46745. 0x29, 0x77, 0xFC, 0x9A, 0x76, 0x8A, 0x5F, 0x66,
  46746. 0x9B, 0x63, 0x91, 0x12, 0x78, 0xBF, 0x67, 0xAD,
  46747. 0xA1, 0x72, 0x9E, 0xC5, 0x3E, 0xE5, 0xCB, 0xAF,
  46748. 0xD6, 0x5A, 0x0D, 0xB6, 0x9B, 0xA3, 0x78, 0xE8,
  46749. 0xB0, 0x8F, 0x69, 0xED, 0xC1, 0x73, 0xD5, 0xE5,
  46750. 0x1C, 0x18, 0xA0, 0x58, 0x4C, 0x49, 0xBD, 0x91,
  46751. 0xCE, 0x15, 0x0D, 0xAA, 0x5A, 0x07, 0xEA, 0x1C,
  46752. 0xA7, 0x4B, 0x11, 0x31, 0x80, 0xAF, 0xA1, 0x0A,
  46753. 0xED, 0x6C, 0x70, 0xE4, 0xDB, 0x75, 0x86, 0xAE,
  46754. 0xBF, 0x4A, 0x05, 0x72, 0xDE, 0x84, 0x8C, 0x7B,
  46755. 0x59, 0x81, 0x58, 0xE0, 0xC0, 0x15, 0xB5, 0xF3,
  46756. 0xD5, 0x73, 0x78, 0x83, 0x53, 0xDA, 0x92, 0xC1,
  46757. 0xE6, 0x71, 0x74, 0xC7, 0x7E, 0xAA, 0x36, 0x06,
  46758. 0xF0, 0xDF, 0xBA, 0xFB, 0xEF, 0x54, 0xE8, 0x11,
  46759. 0xB2, 0x33, 0xA3, 0x0B, 0x9E, 0x0C, 0x59, 0x75,
  46760. 0x13, 0xFA, 0x7F, 0x88, 0xB9, 0x86, 0xBD, 0x1A,
  46761. 0xDB, 0x52, 0x12, 0xFB, 0x6D, 0x1A, 0xCB, 0x49,
  46762. 0x94, 0x94, 0xC4, 0xA9, 0x99, 0xC0, 0xA4, 0xB6,
  46763. 0x60, 0x36, 0x09, 0x94, 0x2A, 0xD5, 0xC4, 0x26,
  46764. 0xF4, 0xA3, 0x6A, 0x0E, 0x57, 0x8B, 0x7C, 0xA4,
  46765. 0x1D, 0x75, 0xE8, 0x2A, 0xF3, 0xC4, 0x3C, 0x7D,
  46766. 0x45, 0x6D, 0xD8, 0x24, 0xD1, 0x3B, 0xF7, 0xCF,
  46767. 0xE4, 0x45, 0x2A, 0x55, 0xE5, 0xA9, 0x1F, 0x1C,
  46768. 0x8F, 0x55, 0x8D, 0xC1, 0xF7, 0x74, 0xCC, 0x26,
  46769. 0xC7, 0xBA, 0x2E, 0x5C, 0xC1, 0x71, 0x0A, 0xAA,
  46770. 0xD9, 0x6D, 0x76, 0xA7, 0xF9, 0xD1, 0x18, 0xCB,
  46771. 0x5A, 0x52, 0x98, 0xA8, 0x0D, 0x3F, 0x06, 0xFC,
  46772. 0x49, 0x11, 0x21, 0x5F, 0x86, 0x19, 0x33, 0x81,
  46773. 0xB5, 0x7A, 0xDA, 0xA1, 0x47, 0xBF, 0x7C, 0xD7,
  46774. 0x05, 0x96, 0xC7, 0xF5, 0xC1, 0x61, 0xE5, 0x18,
  46775. 0xA5, 0x38, 0x68, 0xED, 0xB4, 0x17, 0x62, 0x0D,
  46776. 0x01, 0x5E, 0xC3, 0x04, 0xA6, 0xBA, 0xB1, 0x01,
  46777. 0x60, 0x5C, 0xC1, 0x3A, 0x34, 0x97, 0xD6, 0xDB,
  46778. 0x67, 0x73, 0x4D, 0x33, 0x96, 0x01, 0x67, 0x44,
  46779. 0xEA, 0x47, 0x5E, 0x44, 0xB5, 0xE5, 0xD1, 0x6C,
  46780. 0x20, 0xA9, 0x6D, 0x4D, 0xBC, 0x02, 0xF0, 0x70,
  46781. 0xE4, 0xDD, 0xE9, 0xD5, 0x5C, 0x28, 0x29, 0x0B,
  46782. 0xB4, 0x60, 0x2A, 0xF1, 0xF7, 0x1A, 0xF0, 0x36,
  46783. 0xAE, 0x51, 0x3A, 0xAE, 0x6E, 0x48, 0x7D, 0xC7,
  46784. 0x5C, 0xF3, 0xDC, 0xF6, 0xED, 0x27, 0x4E, 0x8E,
  46785. 0x48, 0x18, 0x3E, 0x08, 0xF1, 0xD8, 0x3D, 0x0D,
  46786. 0xE7, 0x2F, 0x65, 0x8A, 0x6F, 0xE2, 0x1E, 0x06,
  46787. 0xC1, 0x04, 0x58, 0x7B, 0x4A, 0x75, 0x60, 0x92,
  46788. 0x13, 0xC6, 0x40, 0x2D, 0x3A, 0x8A, 0xD1, 0x03,
  46789. 0x05, 0x1F, 0x28, 0x66, 0xC2, 0x57, 0x2A, 0x4C,
  46790. 0xE1, 0xA3, 0xCB, 0xA1, 0x95, 0x30, 0x10, 0xED,
  46791. 0xDF, 0xAE, 0x70, 0x49, 0x4E, 0xF6, 0xB4, 0x5A,
  46792. 0xB6, 0x22, 0x56, 0x37, 0x05, 0xE7, 0x3E, 0xB2,
  46793. 0xE3, 0x96, 0x62, 0xEC, 0x09, 0x53, 0xC0, 0x50,
  46794. 0x3D, 0xA7, 0xBC, 0x9B, 0x39, 0x02, 0x26, 0x16,
  46795. 0xB5, 0x34, 0x17, 0xD4, 0xCA, 0xFE, 0x1D, 0xE4,
  46796. 0x5A, 0xDA, 0x4C, 0xC2, 0xCA, 0x8E, 0x79, 0xBF,
  46797. 0xD8, 0x4C, 0xBB, 0xFA, 0x30, 0x7B, 0xA9, 0x3E,
  46798. 0x52, 0x19, 0xB1, 0x00, 0x00, 0x00, 0x00, 0x00,
  46799. 0x00, 0x00, 0x00, 0x00, 0x00
  46800. };
  46801. #endif /* HAVE_PKCS7 && !NO_FILESYSTEM && ASN_BER_TO_DER &&
  46802. * !NO_DES3 && !NO_SHA
  46803. */
  46804. /*
  46805. * Testing wc_PKCS7_BER()
  46806. */
  46807. static int test_wc_PKCS7_BER(void)
  46808. {
  46809. EXPECT_DECLS;
  46810. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && \
  46811. !defined(NO_SHA) && defined(ASN_BER_TO_DER)
  46812. PKCS7* pkcs7 = NULL;
  46813. char fName[] = "./certs/test-ber-exp02-05-2022.p7b";
  46814. XFILE f = XBADFILE;
  46815. byte der[4096];
  46816. #ifndef NO_DES3
  46817. byte decoded[2048];
  46818. #endif
  46819. word32 derSz = 0;
  46820. #ifndef NO_PKCS7_STREAM
  46821. word32 z;
  46822. int ret;
  46823. #endif /* !NO_PKCS7_STREAM */
  46824. ExpectTrue((f = XFOPEN(fName, "rb")) != XBADFILE);
  46825. ExpectTrue((derSz = (word32)XFREAD(der, 1, sizeof(der), f)) > 0);
  46826. if (f != XBADFILE) {
  46827. XFCLOSE(f);
  46828. f = XBADFILE;
  46829. }
  46830. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46831. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  46832. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46833. #ifndef NO_RSA
  46834. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, der, derSz), 0);
  46835. #ifndef NO_PKCS7_STREAM
  46836. wc_PKCS7_Free(pkcs7);
  46837. pkcs7 = NULL;
  46838. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46839. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  46840. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46841. /* test for streaming */
  46842. ret = -1;
  46843. for (z = 0; z < derSz && ret != 0; z++) {
  46844. ret = wc_PKCS7_VerifySignedData(pkcs7, der + z, 1);
  46845. if (ret < 0){
  46846. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  46847. }
  46848. }
  46849. ExpectIntEQ(ret, 0);
  46850. #endif /* !NO_PKCS7_STREAM */
  46851. #else
  46852. ExpectIntNE(wc_PKCS7_VerifySignedData(pkcs7, der, derSz), 0);
  46853. #endif
  46854. wc_PKCS7_Free(pkcs7);
  46855. pkcs7 = NULL;
  46856. #ifndef NO_DES3
  46857. /* decode BER content */
  46858. ExpectTrue((f = XFOPEN("./certs/1024/client-cert.der", "rb")) != XBADFILE);
  46859. ExpectTrue((derSz = (word32)XFREAD(der, 1, sizeof(der), f)) > 0);
  46860. if (f != XBADFILE) {
  46861. XFCLOSE(f);
  46862. f = XBADFILE;
  46863. }
  46864. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46865. #ifndef NO_RSA
  46866. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, der, derSz), 0);
  46867. #else
  46868. ExpectIntNE(wc_PKCS7_InitWithCert(pkcs7, der, derSz), 0);
  46869. #endif
  46870. ExpectTrue((f = XFOPEN("./certs/1024/client-key.der", "rb")) != XBADFILE);
  46871. ExpectTrue((derSz = (word32)XFREAD(der, 1, sizeof(der), f)) > 0);
  46872. if (f != XBADFILE) {
  46873. XFCLOSE(f);
  46874. f = XBADFILE;
  46875. }
  46876. if (pkcs7 != NULL) {
  46877. pkcs7->privateKey = der;
  46878. pkcs7->privateKeySz = derSz;
  46879. }
  46880. #ifndef NO_RSA
  46881. #ifdef WOLFSSL_SP_MATH
  46882. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, berContent,
  46883. sizeof(berContent), decoded, sizeof(decoded)), WC_NO_ERR_TRACE(WC_KEY_SIZE_E));
  46884. #else
  46885. ExpectIntGT(wc_PKCS7_DecodeEnvelopedData(pkcs7, berContent,
  46886. sizeof(berContent), decoded, sizeof(decoded)), 0);
  46887. #endif
  46888. #else
  46889. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, berContent,
  46890. sizeof(berContent), decoded, sizeof(decoded)), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  46891. #endif
  46892. wc_PKCS7_Free(pkcs7);
  46893. #endif /* !NO_DES3 */
  46894. #endif
  46895. return EXPECT_RESULT();
  46896. } /* END test_wc_PKCS7_BER() */
  46897. static int test_wc_PKCS7_signed_enveloped(void)
  46898. {
  46899. EXPECT_DECLS;
  46900. #if defined(HAVE_PKCS7) && !defined(NO_RSA) && !defined(NO_AES) && \
  46901. !defined(NO_FILESYSTEM)
  46902. XFILE f = XBADFILE;
  46903. PKCS7* pkcs7 = NULL;
  46904. #ifdef HAVE_AES_CBC
  46905. PKCS7* inner = NULL;
  46906. #endif
  46907. WC_RNG rng;
  46908. unsigned char key[FOURK_BUF/2];
  46909. unsigned char cert[FOURK_BUF/2];
  46910. unsigned char env[FOURK_BUF];
  46911. int envSz = FOURK_BUF;
  46912. int keySz = 0;
  46913. int certSz = 0;
  46914. unsigned char sig[FOURK_BUF * 2];
  46915. int sigSz = FOURK_BUF * 2;
  46916. #ifdef HAVE_AES_CBC
  46917. unsigned char decoded[FOURK_BUF];
  46918. int decodedSz = FOURK_BUF;
  46919. #endif
  46920. #ifndef NO_PKCS7_STREAM
  46921. int z;
  46922. int ret;
  46923. #endif /* !NO_PKCS7_STREAM */
  46924. XMEMSET(&rng, 0, sizeof(WC_RNG));
  46925. /* load cert */
  46926. ExpectTrue((f = XFOPEN(cliCertDerFile, "rb")) != XBADFILE);
  46927. ExpectIntGT((certSz = (int)XFREAD(cert, 1, sizeof(cert), f)), 0);
  46928. if (f != XBADFILE) {
  46929. XFCLOSE(f);
  46930. f = XBADFILE;
  46931. }
  46932. /* load key */
  46933. ExpectTrue((f = XFOPEN(cliKeyFile, "rb")) != XBADFILE);
  46934. ExpectIntGT((keySz = (int)XFREAD(key, 1, sizeof(key), f)), 0);
  46935. if (f != XBADFILE) {
  46936. XFCLOSE(f);
  46937. f = XBADFILE;
  46938. }
  46939. ExpectIntGT(keySz = wolfSSL_KeyPemToDer(key, keySz, key, keySz, NULL), 0);
  46940. /* sign cert for envelope */
  46941. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  46942. ExpectIntEQ(wc_InitRng(&rng), 0);
  46943. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  46944. if (pkcs7 != NULL) {
  46945. pkcs7->content = cert;
  46946. pkcs7->contentSz = (word32)certSz;
  46947. pkcs7->contentOID = DATA;
  46948. pkcs7->privateKey = key;
  46949. pkcs7->privateKeySz = (word32)keySz;
  46950. pkcs7->encryptOID = RSAk;
  46951. pkcs7->hashOID = SHA256h;
  46952. pkcs7->rng = &rng;
  46953. }
  46954. ExpectIntGT((sigSz = wc_PKCS7_EncodeSignedData(pkcs7, sig, (word32)sigSz)), 0);
  46955. wc_PKCS7_Free(pkcs7);
  46956. pkcs7 = NULL;
  46957. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  46958. #ifdef HAVE_AES_CBC
  46959. /* create envelope */
  46960. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  46961. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  46962. if (pkcs7 != NULL) {
  46963. pkcs7->content = sig;
  46964. pkcs7->contentSz = (word32)sigSz;
  46965. pkcs7->contentOID = DATA;
  46966. pkcs7->encryptOID = AES256CBCb;
  46967. pkcs7->privateKey = key;
  46968. pkcs7->privateKeySz = (word32)keySz;
  46969. }
  46970. ExpectIntGT((envSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, env, (word32)envSz)), 0);
  46971. ExpectIntLT(wc_PKCS7_EncodeEnvelopedData(pkcs7, env, 2), 0);
  46972. wc_PKCS7_Free(pkcs7);
  46973. pkcs7 = NULL;
  46974. #endif
  46975. /* create bad signed enveloped data */
  46976. sigSz = FOURK_BUF * 2;
  46977. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  46978. ExpectIntEQ(wc_InitRng(&rng), 0);
  46979. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  46980. if (pkcs7 != NULL) {
  46981. pkcs7->content = env;
  46982. pkcs7->contentSz = (word32)envSz;
  46983. pkcs7->contentOID = DATA;
  46984. pkcs7->privateKey = key;
  46985. pkcs7->privateKeySz = (word32)keySz;
  46986. pkcs7->encryptOID = RSAk;
  46987. pkcs7->hashOID = SHA256h;
  46988. pkcs7->rng = &rng;
  46989. }
  46990. /* Set no certs in bundle for this test. */
  46991. if (pkcs7 != NULL) {
  46992. ExpectIntEQ(wc_PKCS7_SetNoCerts(pkcs7, 1), 0);
  46993. ExpectIntEQ(wc_PKCS7_SetNoCerts(NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46994. ExpectIntEQ(wc_PKCS7_GetNoCerts(pkcs7), 1);
  46995. }
  46996. ExpectIntGT((sigSz = wc_PKCS7_EncodeSignedData(pkcs7, sig, (word32)sigSz)), 0);
  46997. wc_PKCS7_Free(pkcs7);
  46998. pkcs7 = NULL;
  46999. /* check verify fails */
  47000. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47001. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  47002. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, sig, (word32)sigSz),
  47003. WC_NO_ERR_TRACE(PKCS7_SIGNEEDS_CHECK));
  47004. /* try verifying the signature manually */
  47005. {
  47006. RsaKey rKey;
  47007. word32 idx = 0;
  47008. byte digest[MAX_SEQ_SZ + MAX_ALGO_SZ + MAX_OCTET_STR_SZ +
  47009. WC_MAX_DIGEST_SIZE];
  47010. int digestSz = 0;
  47011. ExpectIntEQ(wc_InitRsaKey(&rKey, HEAP_HINT), 0);
  47012. ExpectIntEQ(wc_RsaPrivateKeyDecode(key, &idx, &rKey, (word32)keySz), 0);
  47013. ExpectIntGT(digestSz = wc_RsaSSL_Verify(pkcs7->signature,
  47014. pkcs7->signatureSz, digest, sizeof(digest), &rKey), 0);
  47015. ExpectIntEQ(digestSz, pkcs7->pkcs7DigestSz);
  47016. ExpectIntEQ(XMEMCMP(digest, pkcs7->pkcs7Digest, digestSz), 0);
  47017. ExpectIntEQ(wc_FreeRsaKey(&rKey), 0);
  47018. /* verify was success */
  47019. }
  47020. wc_PKCS7_Free(pkcs7);
  47021. pkcs7 = NULL;
  47022. /* initializing the PKCS7 struct with the signing certificate should pass */
  47023. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47024. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  47025. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, sig, (word32)sigSz), 0);
  47026. #ifndef NO_PKCS7_STREAM
  47027. wc_PKCS7_Free(pkcs7);
  47028. pkcs7 = NULL;
  47029. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47030. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  47031. /* test for streaming */
  47032. ret = -1;
  47033. for (z = 0; z < sigSz && ret != 0; z++) {
  47034. ret = wc_PKCS7_VerifySignedData(pkcs7, sig + z, 1);
  47035. if (ret < 0){
  47036. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  47037. }
  47038. }
  47039. ExpectIntEQ(ret, 0);
  47040. #endif /* !NO_PKCS7_STREAM */
  47041. wc_PKCS7_Free(pkcs7);
  47042. pkcs7 = NULL;
  47043. /* create valid degenerate bundle */
  47044. sigSz = FOURK_BUF * 2;
  47045. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47046. if (pkcs7 != NULL) {
  47047. pkcs7->content = env;
  47048. pkcs7->contentSz = (word32)envSz;
  47049. pkcs7->contentOID = DATA;
  47050. pkcs7->privateKey = key;
  47051. pkcs7->privateKeySz = (word32)keySz;
  47052. pkcs7->encryptOID = RSAk;
  47053. pkcs7->hashOID = SHA256h;
  47054. pkcs7->rng = &rng;
  47055. }
  47056. ExpectIntEQ(wc_PKCS7_SetSignerIdentifierType(pkcs7, DEGENERATE_SID), 0);
  47057. ExpectIntGT((sigSz = wc_PKCS7_EncodeSignedData(pkcs7, sig, (word32)sigSz)), 0);
  47058. wc_PKCS7_Free(pkcs7);
  47059. pkcs7 = NULL;
  47060. wc_FreeRng(&rng);
  47061. /* check verify */
  47062. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47063. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, testDevId), 0);
  47064. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, sig, (word32)sigSz), 0);
  47065. ExpectNotNull(pkcs7->content);
  47066. #ifndef NO_PKCS7_STREAM
  47067. wc_PKCS7_Free(pkcs7);
  47068. pkcs7 = NULL;
  47069. /* create valid degenerate bundle */
  47070. sigSz = FOURK_BUF * 2;
  47071. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47072. if (pkcs7 != NULL) {
  47073. pkcs7->content = env;
  47074. pkcs7->contentSz = (word32)envSz;
  47075. pkcs7->contentOID = DATA;
  47076. pkcs7->privateKey = key;
  47077. pkcs7->privateKeySz = (word32)keySz;
  47078. pkcs7->encryptOID = RSAk;
  47079. pkcs7->hashOID = SHA256h;
  47080. pkcs7->rng = &rng;
  47081. }
  47082. ExpectIntEQ(wc_PKCS7_SetSignerIdentifierType(pkcs7, DEGENERATE_SID), 0);
  47083. ExpectIntGT((sigSz = wc_PKCS7_EncodeSignedData(pkcs7, sig, (word32)sigSz)), 0);
  47084. wc_PKCS7_Free(pkcs7);
  47085. pkcs7 = NULL;
  47086. wc_FreeRng(&rng);
  47087. /* check verify */
  47088. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47089. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, testDevId), 0);
  47090. /* test for streaming */
  47091. ret = -1;
  47092. for (z = 0; z < sigSz && ret != 0; z++) {
  47093. ret = wc_PKCS7_VerifySignedData(pkcs7, sig + z, 1);
  47094. if (ret < 0){
  47095. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  47096. }
  47097. }
  47098. ExpectIntEQ(ret, 0);
  47099. #endif /* !NO_PKCS7_STREAM */
  47100. #ifdef HAVE_AES_CBC
  47101. /* check decode */
  47102. ExpectNotNull(inner = wc_PKCS7_New(NULL, 0));
  47103. ExpectIntEQ(wc_PKCS7_InitWithCert(inner, cert, (word32)certSz), 0);
  47104. if (inner != NULL) {
  47105. inner->privateKey = key;
  47106. inner->privateKeySz = (word32)keySz;
  47107. }
  47108. ExpectIntGT((decodedSz = wc_PKCS7_DecodeEnvelopedData(inner, pkcs7->content,
  47109. pkcs7->contentSz, decoded, (word32)decodedSz)), 0);
  47110. wc_PKCS7_Free(inner);
  47111. inner = NULL;
  47112. #endif
  47113. wc_PKCS7_Free(pkcs7);
  47114. pkcs7 = NULL;
  47115. #ifdef HAVE_AES_CBC
  47116. /* check cert set */
  47117. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47118. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  47119. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, decoded, (word32)decodedSz), 0);
  47120. ExpectNotNull(pkcs7->singleCert);
  47121. ExpectIntNE(pkcs7->singleCertSz, 0);
  47122. wc_PKCS7_Free(pkcs7);
  47123. pkcs7 = NULL;
  47124. #ifndef NO_PKCS7_STREAM
  47125. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47126. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  47127. /* test for streaming */
  47128. ret = -1;
  47129. for (z = 0; z < decodedSz && ret != 0; z++) {
  47130. ret = wc_PKCS7_VerifySignedData(pkcs7, decoded + z, 1);
  47131. if (ret < 0){
  47132. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  47133. }
  47134. }
  47135. ExpectIntEQ(ret, 0);
  47136. ExpectNotNull(pkcs7->singleCert);
  47137. ExpectIntNE(pkcs7->singleCertSz, 0);
  47138. wc_PKCS7_Free(pkcs7);
  47139. pkcs7 = NULL;
  47140. #endif /* !NO_PKCS7_STREAM */
  47141. #endif
  47142. {
  47143. /* arbitrary custom SKID */
  47144. const byte customSKID[] = {
  47145. 0x40, 0x25, 0x77, 0x56
  47146. };
  47147. ExpectIntEQ(wc_InitRng(&rng), 0);
  47148. sigSz = FOURK_BUF * 2;
  47149. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47150. if (pkcs7 != NULL) {
  47151. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  47152. pkcs7->content = cert;
  47153. pkcs7->contentSz = (word32)certSz;
  47154. pkcs7->contentOID = DATA;
  47155. pkcs7->privateKey = key;
  47156. pkcs7->privateKeySz = (word32)keySz;
  47157. pkcs7->encryptOID = RSAk;
  47158. pkcs7->hashOID = SHA256h;
  47159. pkcs7->rng = &rng;
  47160. ExpectIntEQ(wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID), 0);
  47161. ExpectIntEQ(wc_PKCS7_SetCustomSKID(pkcs7, customSKID,
  47162. sizeof(customSKID)), 0);
  47163. ExpectIntGT((sigSz = wc_PKCS7_EncodeSignedData(pkcs7, sig,
  47164. (word32)sigSz)), 0);
  47165. }
  47166. wc_PKCS7_Free(pkcs7);
  47167. pkcs7 = NULL;
  47168. wc_FreeRng(&rng);
  47169. }
  47170. #endif /* HAVE_PKCS7 && !NO_RSA && !NO_AES */
  47171. return EXPECT_RESULT();
  47172. }
  47173. static int test_wc_PKCS7_NoDefaultSignedAttribs(void)
  47174. {
  47175. EXPECT_DECLS;
  47176. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \
  47177. && !defined(NO_AES)
  47178. PKCS7* pkcs7 = NULL;
  47179. void* heap = NULL;
  47180. ExpectNotNull(pkcs7 = wc_PKCS7_New(heap, testDevId));
  47181. ExpectIntEQ(wc_PKCS7_Init(pkcs7, heap, testDevId), 0);
  47182. ExpectIntEQ(wc_PKCS7_NoDefaultSignedAttribs(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47183. ExpectIntEQ(wc_PKCS7_NoDefaultSignedAttribs(pkcs7), 0);
  47184. wc_PKCS7_Free(pkcs7);
  47185. #endif
  47186. return EXPECT_RESULT();
  47187. }
  47188. static int test_wc_PKCS7_SetOriEncryptCtx(void)
  47189. {
  47190. EXPECT_DECLS;
  47191. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \
  47192. && !defined(NO_AES)
  47193. PKCS7* pkcs7 = NULL;
  47194. void* heap = NULL;
  47195. WOLFSSL_CTX* ctx = NULL;
  47196. ExpectNotNull(pkcs7 = wc_PKCS7_New(heap, testDevId));
  47197. ExpectIntEQ(wc_PKCS7_Init(pkcs7, heap, testDevId), 0);
  47198. ExpectIntEQ(wc_PKCS7_SetOriEncryptCtx(NULL, ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47199. ExpectIntEQ(wc_PKCS7_SetOriEncryptCtx(pkcs7, ctx), 0);
  47200. wc_PKCS7_Free(pkcs7);
  47201. #endif
  47202. return EXPECT_RESULT();
  47203. }
  47204. static int test_wc_PKCS7_SetOriDecryptCtx(void)
  47205. {
  47206. EXPECT_DECLS;
  47207. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \
  47208. && !defined(NO_AES)
  47209. PKCS7* pkcs7 = NULL;
  47210. void* heap = NULL;
  47211. WOLFSSL_CTX* ctx = NULL;
  47212. ExpectNotNull(pkcs7 = wc_PKCS7_New(heap, testDevId));
  47213. ExpectIntEQ(wc_PKCS7_Init(pkcs7, heap, testDevId), 0);
  47214. ExpectIntEQ(wc_PKCS7_SetOriDecryptCtx(NULL, ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47215. ExpectIntEQ(wc_PKCS7_SetOriDecryptCtx(pkcs7, ctx), 0);
  47216. wc_PKCS7_Free(pkcs7);
  47217. #endif
  47218. return EXPECT_RESULT();
  47219. }
  47220. static int test_wc_PKCS7_DecodeCompressedData(void)
  47221. {
  47222. EXPECT_DECLS;
  47223. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \
  47224. && !defined(NO_AES) && defined(HAVE_LIBZ)
  47225. PKCS7* pkcs7 = NULL;
  47226. void* heap = NULL;
  47227. byte out[4096];
  47228. byte* decompressed = NULL;
  47229. int outSz;
  47230. int decompressedSz;
  47231. const char* cert = "./certs/client-cert.pem";
  47232. byte* cert_buf = NULL;
  47233. size_t cert_sz = 0;
  47234. ExpectIntEQ(load_file(cert, &cert_buf, &cert_sz), 0);
  47235. ExpectNotNull((decompressed = (byte*)XMALLOC(cert_sz, heap,
  47236. DYNAMIC_TYPE_TMP_BUFFER)));
  47237. decompressedSz = (int)cert_sz;
  47238. ExpectNotNull((pkcs7 = wc_PKCS7_New(heap, testDevId)));
  47239. if (pkcs7 != NULL) {
  47240. pkcs7->content = (byte*)cert_buf;
  47241. pkcs7->contentSz = (word32)cert_sz;
  47242. pkcs7->contentOID = DATA;
  47243. }
  47244. ExpectIntGT((outSz = wc_PKCS7_EncodeCompressedData(pkcs7, out,
  47245. sizeof(out))), 0);
  47246. wc_PKCS7_Free(pkcs7);
  47247. pkcs7 = NULL;
  47248. /* compressed key should be smaller than when started */
  47249. ExpectIntLT(outSz, cert_sz);
  47250. /* test decompression */
  47251. ExpectNotNull((pkcs7 = wc_PKCS7_New(heap, testDevId)));
  47252. ExpectIntEQ(pkcs7->contentOID, 0);
  47253. /* fail case with out buffer too small */
  47254. ExpectIntLT(wc_PKCS7_DecodeCompressedData(pkcs7, out, outSz,
  47255. decompressed, outSz), 0);
  47256. /* success case */
  47257. ExpectIntEQ(wc_PKCS7_DecodeCompressedData(pkcs7, out, outSz,
  47258. decompressed, decompressedSz), cert_sz);
  47259. ExpectIntEQ(pkcs7->contentOID, DATA);
  47260. ExpectIntEQ(XMEMCMP(decompressed, cert_buf, cert_sz), 0);
  47261. XFREE(decompressed, heap, DYNAMIC_TYPE_TMP_BUFFER);
  47262. decompressed = NULL;
  47263. /* test decompression function with different 'max' inputs */
  47264. outSz = sizeof(out);
  47265. ExpectIntGT((outSz = wc_Compress(out, outSz, cert_buf, (word32)cert_sz, 0)),
  47266. 0);
  47267. ExpectIntLT(wc_DeCompressDynamic(&decompressed, 1, DYNAMIC_TYPE_TMP_BUFFER,
  47268. out, outSz, 0, heap), 0);
  47269. ExpectNull(decompressed);
  47270. ExpectIntGT(wc_DeCompressDynamic(&decompressed, -1, DYNAMIC_TYPE_TMP_BUFFER,
  47271. out, outSz, 0, heap), 0);
  47272. ExpectNotNull(decompressed);
  47273. ExpectIntEQ(XMEMCMP(decompressed, cert_buf, cert_sz), 0);
  47274. XFREE(decompressed, heap, DYNAMIC_TYPE_TMP_BUFFER);
  47275. decompressed = NULL;
  47276. ExpectIntGT(wc_DeCompressDynamic(&decompressed, DYNAMIC_TYPE_TMP_BUFFER, 5,
  47277. out, outSz, 0, heap), 0);
  47278. ExpectNotNull(decompressed);
  47279. ExpectIntEQ(XMEMCMP(decompressed, cert_buf, cert_sz), 0);
  47280. XFREE(decompressed, heap, DYNAMIC_TYPE_TMP_BUFFER);
  47281. if (cert_buf != NULL)
  47282. free(cert_buf);
  47283. wc_PKCS7_Free(pkcs7);
  47284. #endif
  47285. return EXPECT_RESULT();
  47286. }
  47287. static int test_wc_i2d_PKCS12(void)
  47288. {
  47289. EXPECT_DECLS;
  47290. #if !defined(NO_ASN) && !defined(NO_PWDBASED) && defined(HAVE_PKCS12) \
  47291. && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \
  47292. && !defined(NO_AES) && !defined(NO_SHA)
  47293. WC_PKCS12* pkcs12 = NULL;
  47294. unsigned char der[FOURK_BUF * 2];
  47295. unsigned char* pt;
  47296. int derSz = 0;
  47297. unsigned char out[FOURK_BUF * 2];
  47298. int outSz = FOURK_BUF * 2;
  47299. const char p12_f[] = "./certs/test-servercert.p12";
  47300. XFILE f = XBADFILE;
  47301. ExpectTrue((f = XFOPEN(p12_f, "rb")) != XBADFILE);
  47302. ExpectIntGT(derSz = (int)XFREAD(der, 1, sizeof(der), f), 0);
  47303. if (f != XBADFILE)
  47304. XFCLOSE(f);
  47305. ExpectNotNull(pkcs12 = wc_PKCS12_new());
  47306. ExpectIntEQ(wc_d2i_PKCS12(der, (word32)derSz, pkcs12), 0);
  47307. ExpectIntEQ(wc_i2d_PKCS12(pkcs12, NULL, &outSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  47308. ExpectIntEQ(outSz, derSz);
  47309. outSz = derSz - 1;
  47310. pt = out;
  47311. ExpectIntLE(wc_i2d_PKCS12(pkcs12, &pt, &outSz), 0);
  47312. outSz = derSz;
  47313. ExpectIntEQ(wc_i2d_PKCS12(pkcs12, &pt, &outSz), derSz);
  47314. ExpectIntEQ((pt == out), 0);
  47315. pt = NULL;
  47316. ExpectIntEQ(wc_i2d_PKCS12(pkcs12, &pt, NULL), derSz);
  47317. XFREE(pt, NULL, DYNAMIC_TYPE_PKCS);
  47318. wc_PKCS12_free(pkcs12);
  47319. pkcs12 = NULL;
  47320. /* Run the same test but use wc_d2i_PKCS12_fp. */
  47321. ExpectNotNull(pkcs12 = wc_PKCS12_new());
  47322. ExpectIntEQ(wc_d2i_PKCS12_fp("./certs/test-servercert.p12", &pkcs12), 0);
  47323. ExpectIntEQ(wc_i2d_PKCS12(pkcs12, NULL, &outSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  47324. ExpectIntEQ(outSz, derSz);
  47325. wc_PKCS12_free(pkcs12);
  47326. pkcs12 = NULL;
  47327. /* wc_d2i_PKCS12_fp can also allocate the PKCS12 object for the caller. */
  47328. ExpectIntEQ(wc_d2i_PKCS12_fp("./certs/test-servercert.p12", &pkcs12), 0);
  47329. ExpectIntEQ(wc_i2d_PKCS12(pkcs12, NULL, &outSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  47330. ExpectIntEQ(outSz, derSz);
  47331. wc_PKCS12_free(pkcs12);
  47332. pkcs12 = NULL;
  47333. #endif
  47334. return EXPECT_RESULT();
  47335. }
  47336. /* Testing wc_SignatureGetSize() for signature type ECC */
  47337. static int test_wc_SignatureGetSize_ecc(void)
  47338. {
  47339. EXPECT_DECLS;
  47340. #if !defined(NO_SIG_WRAPPER) && defined(HAVE_ECC) && !defined(NO_ECC256)
  47341. enum wc_SignatureType sig_type;
  47342. word32 key_len;
  47343. ecc_key ecc;
  47344. const char* qx =
  47345. "fa2737fb93488d19caef11ae7faf6b7f4bcd67b286e3fc54e8a65c2b74aeccb0";
  47346. const char* qy =
  47347. "d4ccd6dae698208aa8c3a6f39e45510d03be09b2f124bfc067856c324f9b4d09";
  47348. const char* d =
  47349. "be34baa8d040a3b991f9075b56ba292f755b90e4b6dc10dad36715c33cfdac25";
  47350. XMEMSET(&ecc, 0, sizeof(ecc_key));
  47351. ExpectIntEQ(wc_ecc_init(&ecc), 0);
  47352. ExpectIntEQ(wc_ecc_import_raw(&ecc, qx, qy, d, "SECP256R1"), 0);
  47353. /* Input for signature type ECC */
  47354. sig_type = WC_SIGNATURE_TYPE_ECC;
  47355. key_len = sizeof(ecc_key);
  47356. ExpectIntGT(wc_SignatureGetSize(sig_type, &ecc, key_len), 0);
  47357. /* Test bad args */
  47358. /* // NOLINTBEGIN(clang-analyzer-optin.core.EnumCastOutOfRange) */
  47359. sig_type = (enum wc_SignatureType) 100;
  47360. /* // NOLINTEND(clang-analyzer-optin.core.EnumCastOutOfRange) */
  47361. ExpectIntEQ(wc_SignatureGetSize(sig_type, &ecc, key_len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47362. sig_type = WC_SIGNATURE_TYPE_ECC;
  47363. ExpectIntEQ(wc_SignatureGetSize(sig_type, NULL, key_len), 0);
  47364. key_len = (word32)0;
  47365. ExpectIntEQ(wc_SignatureGetSize(sig_type, &ecc, key_len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47366. DoExpectIntEQ(wc_ecc_free(&ecc), 0);
  47367. #endif /* !NO_SIG_WRAPPER && HAVE_ECC && !NO_ECC256 */
  47368. return EXPECT_RESULT();
  47369. } /* END test_wc_SignatureGetSize_ecc() */
  47370. /* Testing wc_SignatureGetSize() for signature type rsa */
  47371. static int test_wc_SignatureGetSize_rsa(void)
  47372. {
  47373. EXPECT_DECLS;
  47374. #if !defined(NO_SIG_WRAPPER) && !defined(NO_RSA)
  47375. enum wc_SignatureType sig_type;
  47376. word32 key_len;
  47377. word32 idx = 0;
  47378. RsaKey rsa_key;
  47379. byte* tmp = NULL;
  47380. size_t bytes;
  47381. XMEMSET(&rsa_key, 0, sizeof(RsaKey));
  47382. #ifdef USE_CERT_BUFFERS_1024
  47383. bytes = (size_t)sizeof_client_key_der_1024;
  47384. if (bytes < (size_t)sizeof_client_key_der_1024)
  47385. bytes = (size_t)sizeof_client_cert_der_1024;
  47386. #elif defined(USE_CERT_BUFFERS_2048)
  47387. bytes = (size_t)sizeof_client_key_der_2048;
  47388. if (bytes < (size_t)sizeof_client_cert_der_2048)
  47389. bytes = (size_t)sizeof_client_cert_der_2048;
  47390. #else
  47391. bytes = FOURK_BUF;
  47392. #endif
  47393. ExpectNotNull(tmp = (byte*)XMALLOC(bytes, HEAP_HINT,
  47394. DYNAMIC_TYPE_TMP_BUFFER));
  47395. if (tmp != NULL) {
  47396. #ifdef USE_CERT_BUFFERS_1024
  47397. XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_der_1024);
  47398. #elif defined(USE_CERT_BUFFERS_2048)
  47399. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  47400. #elif !defined(NO_FILESYSTEM)
  47401. XFILE file = XBADFILE;
  47402. ExpectTrue((file = XFOPEN(clientKey, "rb")) != XBADFILE);
  47403. ExpectIntGT(bytes = (size_t)XFREAD(tmp, 1, FOURK_BUF, file), 0);
  47404. if (file != XBADFILE)
  47405. XFCLOSE(file);
  47406. }
  47407. #else
  47408. ExpectFail();
  47409. #endif
  47410. }
  47411. ExpectIntEQ(wc_InitRsaKey_ex(&rsa_key, HEAP_HINT, testDevId), 0);
  47412. ExpectIntEQ(wc_RsaPrivateKeyDecode(tmp, &idx, &rsa_key, (word32)bytes), 0);
  47413. /* Input for signature type RSA */
  47414. sig_type = WC_SIGNATURE_TYPE_RSA;
  47415. key_len = sizeof(RsaKey);
  47416. ExpectIntGT(wc_SignatureGetSize(sig_type, &rsa_key, key_len), 0);
  47417. /* Test bad args */
  47418. /* // NOLINTBEGIN(clang-analyzer-optin.core.EnumCastOutOfRange) */
  47419. sig_type = (enum wc_SignatureType)100;
  47420. /* // NOLINTEND(clang-analyzer-optin.core.EnumCastOutOfRange) */
  47421. ExpectIntEQ(wc_SignatureGetSize(sig_type, &rsa_key, key_len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47422. sig_type = WC_SIGNATURE_TYPE_RSA;
  47423. ExpectIntEQ(wc_SignatureGetSize(sig_type, NULL, key_len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47424. key_len = (word32)0;
  47425. ExpectIntEQ(wc_SignatureGetSize(sig_type, &rsa_key, key_len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47426. DoExpectIntEQ(wc_FreeRsaKey(&rsa_key), 0);
  47427. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47428. #endif /* !NO_SIG_WRAPPER && !NO_RSA */
  47429. return EXPECT_RESULT();
  47430. } /* END test_wc_SignatureGetSize_rsa(void) */
  47431. /*----------------------------------------------------------------------------*
  47432. | hash.h Tests
  47433. *----------------------------------------------------------------------------*/
  47434. static int test_wc_HashInit(void)
  47435. {
  47436. EXPECT_DECLS;
  47437. int i; /* 0 indicates tests passed, 1 indicates failure */
  47438. wc_HashAlg hash;
  47439. /* enum for holding supported algorithms, #ifndef's restrict if disabled */
  47440. enum wc_HashType enumArray[] = {
  47441. #ifndef NO_MD5
  47442. WC_HASH_TYPE_MD5,
  47443. #endif
  47444. #ifndef NO_SHA
  47445. WC_HASH_TYPE_SHA,
  47446. #endif
  47447. #ifdef WOLFSSL_SHA224
  47448. WC_HASH_TYPE_SHA224,
  47449. #endif
  47450. #ifndef NO_SHA256
  47451. WC_HASH_TYPE_SHA256,
  47452. #endif
  47453. #ifdef WOLFSSL_SHA384
  47454. WC_HASH_TYPE_SHA384,
  47455. #endif
  47456. #ifdef WOLFSSL_SHA512
  47457. WC_HASH_TYPE_SHA512,
  47458. #endif
  47459. };
  47460. /* dynamically finds the length */
  47461. int enumlen = (sizeof(enumArray)/sizeof(enum wc_HashType));
  47462. /* For loop to test various arguments... */
  47463. for (i = 0; i < enumlen; i++) {
  47464. /* check for bad args */
  47465. ExpectIntEQ(wc_HashInit(&hash, enumArray[i]), 0);
  47466. wc_HashFree(&hash, enumArray[i]);
  47467. /* check for null ptr */
  47468. ExpectIntEQ(wc_HashInit(NULL, enumArray[i]), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47469. } /* end of for loop */
  47470. return EXPECT_RESULT();
  47471. } /* end of test_wc_HashInit */
  47472. /*
  47473. * Unit test function for wc_HashSetFlags()
  47474. */
  47475. static int test_wc_HashSetFlags(void)
  47476. {
  47477. EXPECT_DECLS;
  47478. #ifdef WOLFSSL_HASH_FLAGS
  47479. wc_HashAlg hash;
  47480. word32 flags = 0;
  47481. int i, j;
  47482. int notSupportedLen;
  47483. /* enum for holding supported algorithms, #ifndef's restrict if disabled */
  47484. enum wc_HashType enumArray[] = {
  47485. #ifndef NO_MD5
  47486. WC_HASH_TYPE_MD5,
  47487. #endif
  47488. #ifndef NO_SHA
  47489. WC_HASH_TYPE_SHA,
  47490. #endif
  47491. #ifdef WOLFSSL_SHA224
  47492. WC_HASH_TYPE_SHA224,
  47493. #endif
  47494. #ifndef NO_SHA256
  47495. WC_HASH_TYPE_SHA256,
  47496. #endif
  47497. #ifdef WOLFSSL_SHA384
  47498. WC_HASH_TYPE_SHA384,
  47499. #endif
  47500. #ifdef WOLFSSL_SHA512
  47501. WC_HASH_TYPE_SHA512,
  47502. #endif
  47503. #ifdef WOLFSSL_SHA3
  47504. WC_HASH_TYPE_SHA3_224,
  47505. #endif
  47506. };
  47507. enum wc_HashType notSupported[] = {
  47508. WC_HASH_TYPE_MD5_SHA,
  47509. WC_HASH_TYPE_MD2,
  47510. WC_HASH_TYPE_MD4,
  47511. WC_HASH_TYPE_BLAKE2B,
  47512. WC_HASH_TYPE_BLAKE2S,
  47513. WC_HASH_TYPE_NONE,
  47514. };
  47515. /* dynamically finds the length */
  47516. int enumlen = (sizeof(enumArray)/sizeof(enum wc_HashType));
  47517. /* For loop to test various arguments... */
  47518. for (i = 0; i < enumlen; i++) {
  47519. ExpectIntEQ(wc_HashInit(&hash, enumArray[i]), 0);
  47520. ExpectIntEQ(wc_HashSetFlags(&hash, enumArray[i], flags), 0);
  47521. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  47522. ExpectIntEQ(wc_HashSetFlags(NULL, enumArray[i], flags), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47523. wc_HashFree(&hash, enumArray[i]);
  47524. }
  47525. /* For loop to test not supported cases */
  47526. notSupportedLen = (sizeof(notSupported)/sizeof(enum wc_HashType));
  47527. for (j = 0; j < notSupportedLen; j++) {
  47528. ExpectIntEQ(wc_HashInit(&hash, notSupported[j]), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47529. ExpectIntEQ(wc_HashSetFlags(&hash, notSupported[j], flags),
  47530. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47531. ExpectIntEQ(wc_HashFree(&hash, notSupported[j]), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47532. }
  47533. #endif
  47534. return EXPECT_RESULT();
  47535. } /* END test_wc_HashSetFlags */
  47536. /*
  47537. * Unit test function for wc_HashGetFlags()
  47538. */
  47539. static int test_wc_HashGetFlags(void)
  47540. {
  47541. EXPECT_DECLS;
  47542. #ifdef WOLFSSL_HASH_FLAGS
  47543. wc_HashAlg hash;
  47544. word32 flags = 0;
  47545. int i, j;
  47546. /* enum for holding supported algorithms, #ifndef's restrict if disabled */
  47547. enum wc_HashType enumArray[] = {
  47548. #ifndef NO_MD5
  47549. WC_HASH_TYPE_MD5,
  47550. #endif
  47551. #ifndef NO_SHA
  47552. WC_HASH_TYPE_SHA,
  47553. #endif
  47554. #ifdef WOLFSSL_SHA224
  47555. WC_HASH_TYPE_SHA224,
  47556. #endif
  47557. #ifndef NO_SHA256
  47558. WC_HASH_TYPE_SHA256,
  47559. #endif
  47560. #ifdef WOLFSSL_SHA384
  47561. WC_HASH_TYPE_SHA384,
  47562. #endif
  47563. #ifdef WOLFSSL_SHA512
  47564. WC_HASH_TYPE_SHA512,
  47565. #endif
  47566. #ifdef WOLFSSL_SHA3
  47567. WC_HASH_TYPE_SHA3_224,
  47568. #endif
  47569. };
  47570. enum wc_HashType notSupported[] = {
  47571. WC_HASH_TYPE_MD5_SHA,
  47572. WC_HASH_TYPE_MD2,
  47573. WC_HASH_TYPE_MD4,
  47574. WC_HASH_TYPE_BLAKE2B,
  47575. WC_HASH_TYPE_BLAKE2S,
  47576. WC_HASH_TYPE_NONE,
  47577. };
  47578. int enumlen = (sizeof(enumArray)/sizeof(enum wc_HashType));
  47579. int notSupportedLen;
  47580. /* For loop to test various arguments... */
  47581. for (i = 0; i < enumlen; i++) {
  47582. ExpectIntEQ(wc_HashInit(&hash, enumArray[i]), 0);
  47583. ExpectIntEQ(wc_HashGetFlags(&hash, enumArray[i], &flags), 0);
  47584. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  47585. ExpectIntEQ(wc_HashGetFlags(NULL, enumArray[i], &flags), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47586. wc_HashFree(&hash, enumArray[i]);
  47587. }
  47588. /* For loop to test not supported cases */
  47589. notSupportedLen = (sizeof(notSupported)/sizeof(enum wc_HashType));
  47590. for (j = 0; j < notSupportedLen; j++) {
  47591. ExpectIntEQ(wc_HashInit(&hash, notSupported[j]), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47592. ExpectIntEQ(wc_HashGetFlags(&hash, notSupported[j], &flags),
  47593. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47594. ExpectIntEQ(wc_HashFree(&hash, notSupported[j]), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47595. }
  47596. #endif
  47597. return EXPECT_RESULT();
  47598. } /* END test_wc_HashGetFlags */
  47599. /*----------------------------------------------------------------------------*
  47600. | Compatibility Tests
  47601. *----------------------------------------------------------------------------*/
  47602. /*----------------------------------------------------------------------------*
  47603. | ASN.1 Tests
  47604. *----------------------------------------------------------------------------*/
  47605. static int test_wolfSSL_ASN1_BIT_STRING(void)
  47606. {
  47607. EXPECT_DECLS;
  47608. #if !defined(NO_CERTS) && defined(OPENSSL_ALL)
  47609. ASN1_BIT_STRING* str = NULL;
  47610. ASN1_BIT_STRING* str2 = NULL;
  47611. unsigned char* der = NULL;
  47612. ExpectNotNull(str = ASN1_BIT_STRING_new());
  47613. /* Empty data testing. */
  47614. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 1), 0);
  47615. ASN1_BIT_STRING_free(str);
  47616. str = NULL;
  47617. ExpectNotNull(str = ASN1_BIT_STRING_new());
  47618. /* Invalid parameter testing. */
  47619. ExpectIntEQ(ASN1_BIT_STRING_set_bit(NULL, 42, 1), 0);
  47620. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, -1, 1), 0);
  47621. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 42, 2), 0);
  47622. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 42, -1), 0);
  47623. /* No bit string - bit is always 0. */
  47624. ExpectIntEQ(ASN1_BIT_STRING_get_bit(NULL, 42), 0);
  47625. ExpectIntEQ(ASN1_BIT_STRING_get_bit(NULL, -1), 0);
  47626. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, -1), 0);
  47627. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 0), 0);
  47628. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 42, 1), 1);
  47629. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 42), 1);
  47630. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 41), 0);
  47631. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, -1), 0);
  47632. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 84, 1), 1);
  47633. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 84), 1);
  47634. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 83), 0);
  47635. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 91, 0), 1);
  47636. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 91), 0);
  47637. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 89, 0), 1);
  47638. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 89), 0);
  47639. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 42, 0), 1);
  47640. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 42), 0);
  47641. ExpectIntEQ(i2d_ASN1_BIT_STRING(str, NULL), 14);
  47642. ExpectIntEQ(i2d_ASN1_BIT_STRING(str, &der), 14);
  47643. #ifdef WOLFSSL_ASN_TEMPLATE
  47644. {
  47645. const unsigned char* tmp = der;
  47646. ExpectNotNull(d2i_ASN1_BIT_STRING(&str2, &tmp, 14));
  47647. }
  47648. #endif
  47649. ASN1_BIT_STRING_free(str);
  47650. ASN1_BIT_STRING_free(str2);
  47651. ASN1_BIT_STRING_free(NULL);
  47652. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  47653. #endif
  47654. return EXPECT_RESULT();
  47655. }
  47656. static int test_wolfSSL_ASN1_INTEGER(void)
  47657. {
  47658. EXPECT_DECLS;
  47659. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  47660. ASN1_INTEGER* a = NULL;
  47661. ASN1_INTEGER* dup = NULL;
  47662. const unsigned char invalidLenDer[] = {
  47663. 0x02, 0x20, 0x00
  47664. };
  47665. const unsigned char longDer[] = {
  47666. 0x02, 0x20,
  47667. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  47668. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  47669. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  47670. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
  47671. };
  47672. const unsigned char* p;
  47673. /* Invalid parameter testing. */
  47674. ASN1_INTEGER_free(NULL);
  47675. ExpectNull(wolfSSL_ASN1_INTEGER_dup(NULL));
  47676. ExpectNotNull(a = ASN1_INTEGER_new());
  47677. ExpectNotNull(dup = wolfSSL_ASN1_INTEGER_dup(a));
  47678. ASN1_INTEGER_free(dup);
  47679. dup = NULL;
  47680. ASN1_INTEGER_free(a);
  47681. a = NULL;
  47682. p = longDer;
  47683. ExpectNull(d2i_ASN1_INTEGER(NULL, &p, sizeof(invalidLenDer)));
  47684. p = longDer;
  47685. ExpectNotNull(a = d2i_ASN1_INTEGER(NULL, &p, sizeof(longDer)));
  47686. ExpectPtrNE(p, longDer);
  47687. ExpectNotNull(dup = wolfSSL_ASN1_INTEGER_dup(a));
  47688. ASN1_INTEGER_free(dup);
  47689. ASN1_INTEGER_free(a);
  47690. #endif
  47691. return EXPECT_RESULT();
  47692. }
  47693. static int test_wolfSSL_ASN1_INTEGER_cmp(void)
  47694. {
  47695. EXPECT_DECLS;
  47696. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  47697. ASN1_INTEGER* a = NULL;
  47698. ASN1_INTEGER* b = NULL;
  47699. ExpectNotNull(a = ASN1_INTEGER_new());
  47700. ExpectNotNull(b = ASN1_INTEGER_new());
  47701. ExpectIntEQ(ASN1_INTEGER_set(a, 1), 1);
  47702. ExpectIntEQ(ASN1_INTEGER_set(b, 1), 1);
  47703. /* Invalid parameter testing. */
  47704. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(NULL, NULL), -1);
  47705. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(a, NULL), -1);
  47706. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(NULL, b), -1);
  47707. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  47708. ExpectIntEQ(ASN1_INTEGER_set(b, -1), 1);
  47709. ExpectIntGT(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  47710. ExpectIntEQ(ASN1_INTEGER_set(a, -2), 1);
  47711. ExpectIntLT(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  47712. ExpectIntEQ(ASN1_INTEGER_set(b, 1), 1);
  47713. ExpectIntLT(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  47714. ExpectIntEQ(ASN1_INTEGER_set(a, 0x01), 1);
  47715. ExpectIntEQ(ASN1_INTEGER_set(b, 0x1000), 1);
  47716. ExpectIntLT(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  47717. ExpectIntGT(wolfSSL_ASN1_INTEGER_cmp(b, a), 0);
  47718. ASN1_INTEGER_free(b);
  47719. ASN1_INTEGER_free(a);
  47720. #endif
  47721. return EXPECT_RESULT();
  47722. }
  47723. static int test_wolfSSL_ASN1_INTEGER_BN(void)
  47724. {
  47725. EXPECT_DECLS;
  47726. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  47727. ASN1_INTEGER* ai = NULL;
  47728. ASN1_INTEGER* ai2 = NULL;
  47729. BIGNUM* bn = NULL;
  47730. BIGNUM* bn2 = NULL;
  47731. ExpectNotNull(ai = ASN1_INTEGER_new());
  47732. ExpectNotNull(bn2 = BN_new());
  47733. /* Invalid parameter testing. */
  47734. ExpectNull(bn = ASN1_INTEGER_to_BN(NULL, NULL));
  47735. ExpectNull(ai2 = BN_to_ASN1_INTEGER(NULL, NULL));
  47736. /* at the moment hard setting since no set function */
  47737. if (ai != NULL) {
  47738. ai->data[0] = 0xff; /* No DER encoding. */
  47739. ai->length = 1;
  47740. }
  47741. #if defined(WOLFSSL_QT) || defined(WOLFSSL_HAPROXY)
  47742. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, NULL));
  47743. BN_free(bn);
  47744. bn = NULL;
  47745. #else
  47746. ExpectNull(ASN1_INTEGER_to_BN(ai, NULL));
  47747. #endif
  47748. if (ai != NULL) {
  47749. ai->data[0] = 0x02; /* tag for ASN_INTEGER */
  47750. ai->data[1] = 0x04; /* bad length of integer */
  47751. ai->data[2] = 0x03;
  47752. ai->length = 3;
  47753. }
  47754. #if defined(WOLFSSL_QT) || defined(WOLFSSL_HAPROXY)
  47755. /* Interpreted as a number 0x020403. */
  47756. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, NULL));
  47757. BN_free(bn);
  47758. bn = NULL;
  47759. #else
  47760. ExpectNull(ASN1_INTEGER_to_BN(ai, NULL));
  47761. #endif
  47762. if (ai != NULL) {
  47763. ai->data[0] = 0x02; /* tag for ASN_INTEGER */
  47764. ai->data[1] = 0x01; /* length of integer */
  47765. ai->data[2] = 0x03;
  47766. ai->length = 3;
  47767. }
  47768. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, NULL));
  47769. ExpectNotNull(ai2 = BN_to_ASN1_INTEGER(bn, NULL));
  47770. ExpectIntEQ(ASN1_INTEGER_cmp(ai, ai2), 0);
  47771. ExpectNotNull(bn2 = ASN1_INTEGER_to_BN(ai2, bn2));
  47772. ExpectIntEQ(BN_cmp(bn, bn2), 0);
  47773. if (ai != NULL) {
  47774. ai->data[0] = 0x02; /* tag for ASN_INTEGER */
  47775. ai->data[1] = 0x02; /* length of integer */
  47776. ai->data[2] = 0x00; /* padding byte to ensure positive */
  47777. ai->data[3] = 0xff;
  47778. ai->length = 4;
  47779. }
  47780. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, bn));
  47781. ExpectNotNull(ai2 = BN_to_ASN1_INTEGER(bn, ai2));
  47782. ExpectIntEQ(ASN1_INTEGER_cmp(ai, ai2), 0);
  47783. ExpectNotNull(bn2 = ASN1_INTEGER_to_BN(ai2, bn2));
  47784. ExpectIntEQ(BN_cmp(bn, bn2), 0);
  47785. if (ai != NULL) {
  47786. ai->data[0] = 0x02; /* tag for ASN_INTEGER */
  47787. ai->data[1] = 0x01; /* length of integer */
  47788. ai->data[2] = 0x00;
  47789. ai->length = 3;
  47790. }
  47791. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, bn));
  47792. ExpectNotNull(ai2 = BN_to_ASN1_INTEGER(bn, ai2));
  47793. ExpectIntEQ(ASN1_INTEGER_cmp(ai, ai2), 0);
  47794. ExpectNotNull(bn2 = ASN1_INTEGER_to_BN(ai2, bn2));
  47795. ExpectIntEQ(BN_cmp(bn, bn2), 0);
  47796. if (ai != NULL) {
  47797. ai->data[0] = 0x02; /* tag for ASN_INTEGER */
  47798. ai->data[1] = 0x01; /* length of integer */
  47799. ai->data[2] = 0x01;
  47800. ai->length = 3;
  47801. ai->negative = 1;
  47802. }
  47803. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, bn));
  47804. ExpectNotNull(ai2 = BN_to_ASN1_INTEGER(bn, ai2));
  47805. ExpectIntEQ(ASN1_INTEGER_cmp(ai, ai2), 0);
  47806. ExpectNotNull(bn2 = ASN1_INTEGER_to_BN(ai2, bn2));
  47807. ExpectIntEQ(BN_cmp(bn, bn2), 0);
  47808. BN_free(bn2);
  47809. BN_free(bn);
  47810. ASN1_INTEGER_free(ai2);
  47811. ASN1_INTEGER_free(ai);
  47812. #endif
  47813. return EXPECT_RESULT();
  47814. }
  47815. static int test_wolfSSL_ASN1_INTEGER_get_set(void)
  47816. {
  47817. EXPECT_DECLS;
  47818. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  47819. ASN1_INTEGER *a = NULL;
  47820. long val;
  47821. ExpectNotNull(a = ASN1_INTEGER_new());
  47822. /* Invalid parameter testing. */
  47823. ExpectIntEQ(ASN1_INTEGER_get(NULL), 0);
  47824. #if defined(WOLFSSL_QT) || defined(WOLFSSL_HAPROXY)
  47825. ExpectIntEQ(ASN1_INTEGER_get(a), 0);
  47826. #else
  47827. ExpectIntEQ(ASN1_INTEGER_get(a), -1);
  47828. #endif
  47829. ASN1_INTEGER_free(a);
  47830. a = NULL;
  47831. ExpectNotNull(a = ASN1_INTEGER_new());
  47832. val = 0;
  47833. ExpectIntEQ(ASN1_INTEGER_set(NULL, val), 0);
  47834. ASN1_INTEGER_free(a);
  47835. a = NULL;
  47836. /* 0 */
  47837. ExpectNotNull(a = ASN1_INTEGER_new());
  47838. val = 0;
  47839. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47840. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47841. ASN1_INTEGER_free(a);
  47842. a = NULL;
  47843. /* 40 */
  47844. ExpectNotNull(a = ASN1_INTEGER_new());
  47845. val = 40;
  47846. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47847. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47848. ASN1_INTEGER_free(a);
  47849. a = NULL;
  47850. /* -40 */
  47851. ExpectNotNull(a = ASN1_INTEGER_new());
  47852. val = -40;
  47853. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47854. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47855. ASN1_INTEGER_free(a);
  47856. a = NULL;
  47857. /* 128 */
  47858. ExpectNotNull(a = ASN1_INTEGER_new());
  47859. val = 128;
  47860. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47861. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47862. ASN1_INTEGER_free(a);
  47863. a = NULL;
  47864. /* -128 */
  47865. ExpectNotNull(a = ASN1_INTEGER_new());
  47866. val = -128;
  47867. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47868. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47869. ASN1_INTEGER_free(a);
  47870. a = NULL;
  47871. /* 200 */
  47872. ExpectNotNull(a = ASN1_INTEGER_new());
  47873. val = 200;
  47874. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47875. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47876. ASN1_INTEGER_free(a);
  47877. a = NULL;
  47878. /* int max (2147483647) */
  47879. ExpectNotNull(a = ASN1_INTEGER_new());
  47880. val = 2147483647;
  47881. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47882. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47883. ASN1_INTEGER_free(a);
  47884. a = NULL;
  47885. /* int min (-2147483648) */
  47886. ExpectNotNull(a = ASN1_INTEGER_new());
  47887. val = -2147483647 - 1;
  47888. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47889. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47890. ASN1_INTEGER_free(a);
  47891. a = NULL;
  47892. /* long max positive */
  47893. ExpectNotNull(a = ASN1_INTEGER_new());
  47894. val = (long)(((unsigned long)-1) >> 1);
  47895. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  47896. ExpectTrue(ASN1_INTEGER_get(a) == val);
  47897. ASN1_INTEGER_free(a);
  47898. #endif
  47899. return EXPECT_RESULT();
  47900. }
  47901. #if defined(OPENSSL_EXTRA)
  47902. typedef struct ASN1IntTestVector {
  47903. const byte* der;
  47904. const size_t derSz;
  47905. const long value;
  47906. } ASN1IntTestVector;
  47907. #endif
  47908. static int test_wolfSSL_d2i_ASN1_INTEGER(void)
  47909. {
  47910. EXPECT_DECLS;
  47911. #if defined(OPENSSL_EXTRA)
  47912. size_t i;
  47913. WOLFSSL_ASN1_INTEGER* a = NULL;
  47914. WOLFSSL_ASN1_INTEGER* b = NULL;
  47915. WOLFSSL_ASN1_INTEGER* c = NULL;
  47916. const byte* p = NULL;
  47917. byte* p2 = NULL;
  47918. byte* reEncoded = NULL;
  47919. int reEncodedSz = 0;
  47920. static const byte zeroDer[] = {
  47921. 0x02, 0x01, 0x00
  47922. };
  47923. static const byte oneDer[] = {
  47924. 0x02, 0x01, 0x01
  47925. };
  47926. static const byte negativeDer[] = {
  47927. 0x02, 0x03, 0xC1, 0x16, 0x0D
  47928. };
  47929. static const byte positiveDer[] = {
  47930. 0x02, 0x03, 0x01, 0x00, 0x01
  47931. };
  47932. static const byte primeDer[] = {
  47933. 0x02, 0x82, 0x01, 0x01, 0x00, 0xc0, 0x95, 0x08, 0xe1, 0x57, 0x41,
  47934. 0xf2, 0x71, 0x6d, 0xb7, 0xd2, 0x45, 0x41, 0x27, 0x01, 0x65, 0xc6,
  47935. 0x45, 0xae, 0xf2, 0xbc, 0x24, 0x30, 0xb8, 0x95, 0xce, 0x2f, 0x4e,
  47936. 0xd6, 0xf6, 0x1c, 0x88, 0xbc, 0x7c, 0x9f, 0xfb, 0xa8, 0x67, 0x7f,
  47937. 0xfe, 0x5c, 0x9c, 0x51, 0x75, 0xf7, 0x8a, 0xca, 0x07, 0xe7, 0x35,
  47938. 0x2f, 0x8f, 0xe1, 0xbd, 0x7b, 0xc0, 0x2f, 0x7c, 0xab, 0x64, 0xa8,
  47939. 0x17, 0xfc, 0xca, 0x5d, 0x7b, 0xba, 0xe0, 0x21, 0xe5, 0x72, 0x2e,
  47940. 0x6f, 0x2e, 0x86, 0xd8, 0x95, 0x73, 0xda, 0xac, 0x1b, 0x53, 0xb9,
  47941. 0x5f, 0x3f, 0xd7, 0x19, 0x0d, 0x25, 0x4f, 0xe1, 0x63, 0x63, 0x51,
  47942. 0x8b, 0x0b, 0x64, 0x3f, 0xad, 0x43, 0xb8, 0xa5, 0x1c, 0x5c, 0x34,
  47943. 0xb3, 0xae, 0x00, 0xa0, 0x63, 0xc5, 0xf6, 0x7f, 0x0b, 0x59, 0x68,
  47944. 0x78, 0x73, 0xa6, 0x8c, 0x18, 0xa9, 0x02, 0x6d, 0xaf, 0xc3, 0x19,
  47945. 0x01, 0x2e, 0xb8, 0x10, 0xe3, 0xc6, 0xcc, 0x40, 0xb4, 0x69, 0xa3,
  47946. 0x46, 0x33, 0x69, 0x87, 0x6e, 0xc4, 0xbb, 0x17, 0xa6, 0xf3, 0xe8,
  47947. 0xdd, 0xad, 0x73, 0xbc, 0x7b, 0x2f, 0x21, 0xb5, 0xfd, 0x66, 0x51,
  47948. 0x0c, 0xbd, 0x54, 0xb3, 0xe1, 0x6d, 0x5f, 0x1c, 0xbc, 0x23, 0x73,
  47949. 0xd1, 0x09, 0x03, 0x89, 0x14, 0xd2, 0x10, 0xb9, 0x64, 0xc3, 0x2a,
  47950. 0xd0, 0xa1, 0x96, 0x4a, 0xbc, 0xe1, 0xd4, 0x1a, 0x5b, 0xc7, 0xa0,
  47951. 0xc0, 0xc1, 0x63, 0x78, 0x0f, 0x44, 0x37, 0x30, 0x32, 0x96, 0x80,
  47952. 0x32, 0x23, 0x95, 0xa1, 0x77, 0xba, 0x13, 0xd2, 0x97, 0x73, 0xe2,
  47953. 0x5d, 0x25, 0xc9, 0x6a, 0x0d, 0xc3, 0x39, 0x60, 0xa4, 0xb4, 0xb0,
  47954. 0x69, 0x42, 0x42, 0x09, 0xe9, 0xd8, 0x08, 0xbc, 0x33, 0x20, 0xb3,
  47955. 0x58, 0x22, 0xa7, 0xaa, 0xeb, 0xc4, 0xe1, 0xe6, 0x61, 0x83, 0xc5,
  47956. 0xd2, 0x96, 0xdf, 0xd9, 0xd0, 0x4f, 0xad, 0xd7
  47957. };
  47958. static const byte garbageDer[] = {0xDE, 0xAD, 0xBE, 0xEF};
  47959. static const ASN1IntTestVector testVectors[] = {
  47960. {zeroDer, sizeof(zeroDer), 0},
  47961. {oneDer, sizeof(oneDer), 1},
  47962. {negativeDer, sizeof(negativeDer), -4123123},
  47963. {positiveDer, sizeof(positiveDer), 65537},
  47964. {primeDer, sizeof(primeDer), 0}
  47965. };
  47966. static const size_t NUM_TEST_VECTORS =
  47967. sizeof(testVectors)/sizeof(testVectors[0]);
  47968. /* Check d2i error conditions */
  47969. /* NULL pointer to input. */
  47970. ExpectNull((a = wolfSSL_d2i_ASN1_INTEGER(&b, NULL, 1)));
  47971. ExpectNull(b);
  47972. /* NULL input. */
  47973. ExpectNull((a = wolfSSL_d2i_ASN1_INTEGER(&b, &p, 1)));
  47974. ExpectNull(b);
  47975. /* 0 length. */
  47976. p = testVectors[0].der;
  47977. ExpectNull((a = wolfSSL_d2i_ASN1_INTEGER(&b, &p, 0)));
  47978. ExpectNull(b);
  47979. /* Negative length. */
  47980. p = testVectors[0].der;
  47981. ExpectNull((a = wolfSSL_d2i_ASN1_INTEGER(&b, &p, -1)));
  47982. ExpectNull(b);
  47983. /* Garbage DER input. */
  47984. p = garbageDer;
  47985. ExpectNull((a = wolfSSL_d2i_ASN1_INTEGER(&b, &p, sizeof(garbageDer))));
  47986. ExpectNull(b);
  47987. /* Check i2d error conditions */
  47988. /* NULL input. */
  47989. ExpectIntLT(wolfSSL_i2d_ASN1_INTEGER(NULL, &p2), 0);
  47990. /* 0 length input data buffer (a->length == 0). */
  47991. ExpectNotNull((a = wolfSSL_ASN1_INTEGER_new()));
  47992. ExpectIntLT(wolfSSL_i2d_ASN1_INTEGER(a, &p2), 0);
  47993. if (a != NULL)
  47994. a->data = NULL;
  47995. /* NULL input data buffer. */
  47996. ExpectIntLT(wolfSSL_i2d_ASN1_INTEGER(a, &p2), 0);
  47997. if (a != NULL) {
  47998. /* Reset a->data. */
  47999. a->data = a->intData;
  48000. }
  48001. /* Set a to valid value. */
  48002. ExpectIntEQ(wolfSSL_ASN1_INTEGER_set(a, 1), WOLFSSL_SUCCESS);
  48003. /* NULL output buffer. */
  48004. ExpectIntEQ(wolfSSL_i2d_ASN1_INTEGER(a, NULL), 3);
  48005. wolfSSL_ASN1_INTEGER_free(a);
  48006. a = NULL;
  48007. for (i = 0; i < NUM_TEST_VECTORS; ++i) {
  48008. p = testVectors[i].der;
  48009. ExpectNotNull(a = wolfSSL_d2i_ASN1_INTEGER(&b, &p,
  48010. testVectors[i].derSz));
  48011. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  48012. if (testVectors[i].derSz <= sizeof(long)) {
  48013. ExpectNotNull(c = wolfSSL_ASN1_INTEGER_new());
  48014. ExpectIntEQ(wolfSSL_ASN1_INTEGER_set(c, testVectors[i].value), 1);
  48015. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(a, c), 0);
  48016. wolfSSL_ASN1_INTEGER_free(c);
  48017. c = NULL;
  48018. }
  48019. /* Convert to DER without a pre-allocated output buffer. */
  48020. ExpectIntGT((reEncodedSz = wolfSSL_i2d_ASN1_INTEGER(a, &reEncoded)), 0);
  48021. ExpectIntEQ(reEncodedSz, testVectors[i].derSz);
  48022. ExpectIntEQ(XMEMCMP(reEncoded, testVectors[i].der, reEncodedSz), 0);
  48023. /* Convert to DER with a pre-allocated output buffer. In this case, the
  48024. * output buffer pointer should be incremented just past the end of the
  48025. * encoded data. */
  48026. p2 = reEncoded;
  48027. ExpectIntGT((reEncodedSz = wolfSSL_i2d_ASN1_INTEGER(a, &p2)), 0);
  48028. ExpectIntEQ(reEncodedSz, testVectors[i].derSz);
  48029. ExpectPtrEq(reEncoded, p2 - reEncodedSz);
  48030. ExpectIntEQ(XMEMCMP(reEncoded, testVectors[i].der, reEncodedSz), 0);
  48031. XFREE(reEncoded, NULL, DYNAMIC_TYPE_ASN1);
  48032. reEncoded = NULL;
  48033. wolfSSL_ASN1_INTEGER_free(a);
  48034. a = NULL;
  48035. }
  48036. #endif /* OPENSSL_EXTRA */
  48037. return EXPECT_RESULT();
  48038. }
  48039. static int test_wolfSSL_a2i_ASN1_INTEGER(void)
  48040. {
  48041. EXPECT_DECLS;
  48042. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  48043. BIO* bio = NULL;
  48044. BIO* out = NULL;
  48045. BIO* fixed = NULL;
  48046. ASN1_INTEGER* ai = NULL;
  48047. char buf[] = "123456\n12345\n1123456789123456\\\n78901234567890 \r\n\n";
  48048. char tmp[1024];
  48049. int tmpSz;
  48050. const char expected1[] = "123456";
  48051. const char expected2[] = "112345678912345678901234567890";
  48052. char longStr[] = "123456781234567812345678123456781234567812345678\n"
  48053. "123456781234567812345678123456781234567812345678\\\n12345678\n";
  48054. ExpectNotNull(out = BIO_new(BIO_s_mem()));
  48055. ExpectNotNull(ai = ASN1_INTEGER_new());
  48056. ExpectNotNull(bio = BIO_new_mem_buf(buf, -1));
  48057. /* Invalid parameter testing. */
  48058. ExpectIntEQ(a2i_ASN1_INTEGER(NULL, NULL, NULL, -1), 0);
  48059. ExpectIntEQ(a2i_ASN1_INTEGER(bio, NULL, NULL, -1), 0);
  48060. ExpectIntEQ(a2i_ASN1_INTEGER(NULL, ai, NULL, -1), 0);
  48061. ExpectIntEQ(a2i_ASN1_INTEGER(NULL, NULL, tmp, -1), 0);
  48062. ExpectIntEQ(a2i_ASN1_INTEGER(NULL, NULL, NULL, 1024), 0);
  48063. ExpectIntEQ(a2i_ASN1_INTEGER(NULL, ai, tmp, 1024), 0);
  48064. ExpectIntEQ(a2i_ASN1_INTEGER(bio, NULL, tmp, 1024), 0);
  48065. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, NULL, 1024), 0);
  48066. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, -1), 0);
  48067. ExpectIntEQ(i2a_ASN1_INTEGER(NULL, NULL), 0);
  48068. ExpectIntEQ(i2a_ASN1_INTEGER(bio, NULL), 0);
  48069. ExpectIntEQ(i2a_ASN1_INTEGER(NULL, ai), 0);
  48070. /* No data to read from BIO. */
  48071. ExpectIntEQ(a2i_ASN1_INTEGER(out, ai, tmp, 1024), 0);
  48072. /* read first line */
  48073. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 1);
  48074. ExpectIntEQ(i2a_ASN1_INTEGER(out, ai), 6);
  48075. XMEMSET(tmp, 0, 1024);
  48076. tmpSz = BIO_read(out, tmp, 1024);
  48077. ExpectIntEQ(tmpSz, 6);
  48078. ExpectIntEQ(XMEMCMP(tmp, expected1, tmpSz), 0);
  48079. /* fail on second line (not % 2) */
  48080. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 0);
  48081. /* read 3rd long line */
  48082. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 1);
  48083. ExpectIntEQ(i2a_ASN1_INTEGER(out, ai), 30);
  48084. XMEMSET(tmp, 0, 1024);
  48085. tmpSz = BIO_read(out, tmp, 1024);
  48086. ExpectIntEQ(tmpSz, 30);
  48087. ExpectIntEQ(XMEMCMP(tmp, expected2, tmpSz), 0);
  48088. /* fail on empty line */
  48089. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 0);
  48090. BIO_free(bio);
  48091. bio = NULL;
  48092. /* Make long integer, requiring dynamic memory, even longer. */
  48093. ExpectNotNull(bio = BIO_new_mem_buf(longStr, -1));
  48094. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 1);
  48095. ExpectIntEQ(i2a_ASN1_INTEGER(out, ai), 48);
  48096. XMEMSET(tmp, 0, 1024);
  48097. tmpSz = BIO_read(out, tmp, 1024);
  48098. ExpectIntEQ(tmpSz, 48);
  48099. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 1);
  48100. ExpectIntEQ(i2a_ASN1_INTEGER(out, ai), 56);
  48101. XMEMSET(tmp, 0, 1024);
  48102. tmpSz = BIO_read(out, tmp, 1024);
  48103. ExpectIntEQ(tmpSz, 56);
  48104. ExpectIntEQ(wolfSSL_ASN1_INTEGER_set(ai, 1), 1);
  48105. BIO_free(bio);
  48106. BIO_free(out);
  48107. ExpectNotNull(fixed = BIO_new(wolfSSL_BIO_s_fixed_mem()));
  48108. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48109. /* Ensure there is 0 bytes available to write into. */
  48110. ExpectIntEQ(BIO_write(fixed, tmp, 1), 1);
  48111. ExpectIntEQ(i2a_ASN1_INTEGER(fixed, ai), 0);
  48112. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48113. ExpectIntEQ(i2a_ASN1_INTEGER(fixed, ai), 0);
  48114. BIO_free(fixed);
  48115. ASN1_INTEGER_free(ai);
  48116. #endif
  48117. return EXPECT_RESULT();
  48118. }
  48119. static int test_wolfSSL_i2c_ASN1_INTEGER(void)
  48120. {
  48121. EXPECT_DECLS;
  48122. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  48123. ASN1_INTEGER *a = NULL;
  48124. unsigned char *pp = NULL,*tpp = NULL;
  48125. int ret = 0;
  48126. ExpectNotNull(a = wolfSSL_ASN1_INTEGER_new());
  48127. /* Invalid parameter testing. */
  48128. /* Set pp to an invalid value. */
  48129. pp = NULL;
  48130. ExpectIntEQ(i2c_ASN1_INTEGER(NULL, &pp), 0);
  48131. ExpectIntEQ(i2c_ASN1_INTEGER(a, &pp), 0);
  48132. ExpectIntEQ(i2c_ASN1_INTEGER(NULL, NULL), 0);
  48133. /* 40 */
  48134. if (a != NULL) {
  48135. a->intData[0] = ASN_INTEGER;
  48136. a->intData[1] = 1;
  48137. a->intData[2] = 40;
  48138. }
  48139. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 1);
  48140. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  48141. DYNAMIC_TYPE_TMP_BUFFER));
  48142. tpp = pp;
  48143. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  48144. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 1);
  48145. tpp--;
  48146. ExpectIntEQ(*tpp, 40);
  48147. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48148. pp = NULL;
  48149. /* 128 */
  48150. if (a != NULL) {
  48151. a->intData[0] = ASN_INTEGER;
  48152. a->intData[1] = 1;
  48153. a->intData[2] = 128;
  48154. }
  48155. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 2);
  48156. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  48157. DYNAMIC_TYPE_TMP_BUFFER));
  48158. tpp = pp;
  48159. if (tpp != NULL) {
  48160. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  48161. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 2);
  48162. tpp--;
  48163. ExpectIntEQ(*(tpp--), 128);
  48164. ExpectIntEQ(*tpp, 0);
  48165. }
  48166. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48167. pp = NULL;
  48168. /* -40 */
  48169. if (a != NULL) {
  48170. a->intData[0] = ASN_INTEGER;
  48171. a->intData[1] = 1;
  48172. a->intData[2] = 40;
  48173. a->negative = 1;
  48174. }
  48175. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 1);
  48176. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  48177. DYNAMIC_TYPE_TMP_BUFFER));
  48178. tpp = pp;
  48179. if (tpp != NULL) {
  48180. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  48181. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 1);
  48182. tpp--;
  48183. ExpectIntEQ(*tpp, 216);
  48184. }
  48185. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48186. pp = NULL;
  48187. /* -128 */
  48188. if (a != NULL) {
  48189. a->intData[0] = ASN_INTEGER;
  48190. a->intData[1] = 1;
  48191. a->intData[2] = 128;
  48192. a->negative = 1;
  48193. }
  48194. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 1);
  48195. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  48196. DYNAMIC_TYPE_TMP_BUFFER));
  48197. tpp = pp;
  48198. if (tpp != NULL) {
  48199. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  48200. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 1);
  48201. tpp--;
  48202. ExpectIntEQ(*tpp, 128);
  48203. }
  48204. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48205. pp = NULL;
  48206. /* -200 */
  48207. if (a != NULL) {
  48208. a->intData[0] = ASN_INTEGER;
  48209. a->intData[1] = 1;
  48210. a->intData[2] = 200;
  48211. a->negative = 1;
  48212. }
  48213. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 2);
  48214. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  48215. DYNAMIC_TYPE_TMP_BUFFER));
  48216. tpp = pp;
  48217. if (tpp != NULL) {
  48218. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  48219. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 2);
  48220. tpp--;
  48221. ExpectIntEQ(*(tpp--), 56);
  48222. ExpectIntEQ(*tpp, 255);
  48223. }
  48224. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48225. pp = NULL;
  48226. /* Empty */
  48227. if (a != NULL) {
  48228. a->intData[0] = ASN_INTEGER;
  48229. a->intData[1] = 0;
  48230. a->negative = 0;
  48231. }
  48232. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 1);
  48233. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  48234. DYNAMIC_TYPE_TMP_BUFFER));
  48235. tpp = pp;
  48236. if (tpp != NULL) {
  48237. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  48238. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 1);
  48239. tpp--;
  48240. ExpectIntEQ(*tpp, 0);
  48241. }
  48242. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48243. pp = NULL;
  48244. /* 0 */
  48245. if (a != NULL) {
  48246. a->intData[0] = ASN_INTEGER;
  48247. a->intData[1] = 1;
  48248. a->intData[2] = 0;
  48249. a->negative = 1;
  48250. }
  48251. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 1);
  48252. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  48253. DYNAMIC_TYPE_TMP_BUFFER));
  48254. if (tpp != NULL) {
  48255. tpp = pp;
  48256. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  48257. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 1);
  48258. tpp--;
  48259. ExpectIntEQ(*tpp, 0);
  48260. }
  48261. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48262. pp = NULL;
  48263. /* 0x100 */
  48264. if (a != NULL) {
  48265. a->intData[0] = ASN_INTEGER;
  48266. a->intData[1] = 2;
  48267. a->intData[2] = 0x01;
  48268. a->intData[3] = 0x00;
  48269. a->negative = 0;
  48270. }
  48271. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 2);
  48272. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  48273. DYNAMIC_TYPE_TMP_BUFFER));
  48274. if (tpp != NULL) {
  48275. tpp = pp;
  48276. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  48277. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 2);
  48278. tpp -= 2;
  48279. ExpectIntEQ(tpp[0], 0x01);
  48280. ExpectIntEQ(tpp[1], 0x00);
  48281. }
  48282. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48283. pp = NULL;
  48284. /* -0x8000 => 0x8000 */
  48285. if (a != NULL) {
  48286. a->intData[0] = ASN_INTEGER;
  48287. a->intData[1] = 2;
  48288. a->intData[2] = 0x80;
  48289. a->intData[3] = 0x00;
  48290. a->negative = 1;
  48291. }
  48292. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 2);
  48293. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  48294. DYNAMIC_TYPE_TMP_BUFFER));
  48295. tpp = pp;
  48296. if (tpp != NULL) {
  48297. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  48298. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 2);
  48299. tpp -= 2;
  48300. ExpectIntEQ(tpp[0], 0x80);
  48301. ExpectIntEQ(tpp[1], 0x00);
  48302. }
  48303. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48304. pp = NULL;
  48305. /* -0x8001 => 0xFF7FFF */
  48306. if (a != NULL) {
  48307. a->intData[0] = ASN_INTEGER;
  48308. a->intData[1] = 2;
  48309. a->intData[2] = 0x80;
  48310. a->intData[3] = 0x01;
  48311. a->negative = 1;
  48312. }
  48313. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 3);
  48314. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  48315. DYNAMIC_TYPE_TMP_BUFFER));
  48316. tpp = pp;
  48317. if (tpp != NULL) {
  48318. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  48319. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 3);
  48320. tpp -= 3;
  48321. ExpectIntEQ(tpp[0], 0xFF);
  48322. ExpectIntEQ(tpp[1], 0x7F);
  48323. ExpectIntEQ(tpp[2], 0xFF);
  48324. }
  48325. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48326. wolfSSL_ASN1_INTEGER_free(a);
  48327. #endif /* OPENSSL_EXTRA && !NO_ASN */
  48328. return EXPECT_RESULT();
  48329. }
  48330. static int test_wolfSSL_ASN1_OBJECT(void)
  48331. {
  48332. EXPECT_DECLS;
  48333. #if defined(OPENSSL_EXTRA)
  48334. ASN1_OBJECT* a = NULL;
  48335. ASN1_OBJECT s;
  48336. const unsigned char der[] = { 0x06, 0x01, 0x00 };
  48337. /* Invalid parameter testing. */
  48338. ASN1_OBJECT_free(NULL);
  48339. ExpectNull(wolfSSL_ASN1_OBJECT_dup(NULL));
  48340. /* Test that a static ASN1_OBJECT can be freed. */
  48341. XMEMSET(&s, 0, sizeof(ASN1_OBJECT));
  48342. ASN1_OBJECT_free(&s);
  48343. ExpectNotNull(a = wolfSSL_ASN1_OBJECT_dup(&s));
  48344. ASN1_OBJECT_free(a);
  48345. a = NULL;
  48346. s.obj = der;
  48347. s.objSz = sizeof(der);
  48348. ExpectNotNull(a = wolfSSL_ASN1_OBJECT_dup(&s));
  48349. ASN1_OBJECT_free(a);
  48350. ASN1_OBJECT_free(&s);
  48351. #endif /* OPENSSL_EXTRA */
  48352. return EXPECT_RESULT();
  48353. }
  48354. static int test_wolfSSL_ASN1_get_object(void)
  48355. {
  48356. EXPECT_DECLS;
  48357. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  48358. const unsigned char* derBuf = cliecc_cert_der_256;
  48359. const unsigned char* nullPtr = NULL;
  48360. const unsigned char objDerInvalidLen[] = { 0x30, 0x81 };
  48361. const unsigned char objDerBadLen[] = { 0x30, 0x04 };
  48362. const unsigned char objDerNotObj[] = { 0x02, 0x01, 0x00 };
  48363. const unsigned char objDerNoData[] = { 0x06, 0x00 };
  48364. const unsigned char* p;
  48365. unsigned char objDer[10];
  48366. unsigned char* der;
  48367. unsigned char* derPtr;
  48368. int len = sizeof_cliecc_cert_der_256;
  48369. long asnLen = 0;
  48370. int tag = 0;
  48371. int cls = 0;
  48372. ASN1_OBJECT* a = NULL;
  48373. ASN1_OBJECT s;
  48374. XMEMSET(&s, 0, sizeof(ASN1_OBJECT));
  48375. /* Invalid encoding at length. */
  48376. p = objDerInvalidLen;
  48377. ExpectIntEQ(ASN1_get_object(&p, &asnLen, &tag, &cls, sizeof(objDerBadLen)),
  48378. 0x80);
  48379. p = objDerBadLen;
  48380. /* Error = 0x80, Constructed = 0x20 */
  48381. ExpectIntEQ(ASN1_get_object(&p, &asnLen, &tag, &cls, sizeof(objDerBadLen)),
  48382. 0x80 | 0x20);
  48383. /* Read a couple TLV triplets and make sure they match the expected values
  48384. */
  48385. /* SEQUENCE */
  48386. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls, len) & 0x80, 0);
  48387. ExpectIntEQ(asnLen, 861);
  48388. ExpectIntEQ(tag, 0x10);
  48389. ExpectIntEQ(cls, 0);
  48390. /* SEQUENCE */
  48391. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls,
  48392. len - (derBuf - cliecc_cert_der_256)) & 0x80, 0);
  48393. ExpectIntEQ(asnLen, 772);
  48394. ExpectIntEQ(tag, 0x10);
  48395. ExpectIntEQ(cls, 0);
  48396. /* [0] */
  48397. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls,
  48398. len - (derBuf - cliecc_cert_der_256)) & 0x80, 0);
  48399. ExpectIntEQ(asnLen, 3);
  48400. ExpectIntEQ(tag, 0);
  48401. ExpectIntEQ(cls, 0x80);
  48402. /* INTEGER */
  48403. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls,
  48404. len - (derBuf - cliecc_cert_der_256)) & 0x80, 0);
  48405. ExpectIntEQ(asnLen, 1);
  48406. ExpectIntEQ(tag, 0x2);
  48407. ExpectIntEQ(cls, 0);
  48408. derBuf += asnLen;
  48409. /* INTEGER */
  48410. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls,
  48411. len - (derBuf - cliecc_cert_der_256)) & 0x80, 0);
  48412. ExpectIntEQ(asnLen, 20);
  48413. ExpectIntEQ(tag, 0x2);
  48414. ExpectIntEQ(cls, 0);
  48415. derBuf += asnLen;
  48416. /* SEQUENCE */
  48417. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls,
  48418. len - (derBuf - cliecc_cert_der_256)) & 0x80, 0);
  48419. ExpectIntEQ(asnLen, 10);
  48420. ExpectIntEQ(tag, 0x10);
  48421. ExpectIntEQ(cls, 0);
  48422. /* Found OBJECT_ID. */
  48423. /* Invalid parameter testing. */
  48424. ExpectIntEQ(ASN1_get_object(NULL, NULL, NULL, NULL, 0), 0x80);
  48425. ExpectIntEQ(ASN1_get_object(&nullPtr, NULL, NULL, NULL, 0), 0x80);
  48426. ExpectIntEQ(ASN1_get_object(NULL, &asnLen, &tag, &cls, len), 0x80);
  48427. ExpectIntEQ(ASN1_get_object(&nullPtr, &asnLen, &tag, &cls, len), 0x80);
  48428. ExpectIntEQ(ASN1_get_object(&derBuf, NULL, &tag, &cls, len), 0x80);
  48429. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, NULL, &cls, len), 0x80);
  48430. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, NULL, len), 0x80);
  48431. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls, 0), 0x80);
  48432. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls, -1), 0x80);
  48433. ExpectNull(d2i_ASN1_OBJECT(NULL, NULL, -1));
  48434. ExpectNull(d2i_ASN1_OBJECT(NULL, &nullPtr, -1));
  48435. ExpectNull(d2i_ASN1_OBJECT(NULL, &derBuf, -1));
  48436. ExpectNull(d2i_ASN1_OBJECT(NULL, NULL, 0));
  48437. ExpectNull(d2i_ASN1_OBJECT(&a, NULL, len));
  48438. ExpectNull(d2i_ASN1_OBJECT(&a, &nullPtr, len));
  48439. ExpectNull(d2i_ASN1_OBJECT(&a, &derBuf, -1));
  48440. ExpectNull(c2i_ASN1_OBJECT(NULL, NULL, -1));
  48441. ExpectNull(c2i_ASN1_OBJECT(NULL, &nullPtr, -1));
  48442. ExpectNull(c2i_ASN1_OBJECT(NULL, &derBuf, -1));
  48443. ExpectNull(c2i_ASN1_OBJECT(NULL, NULL, 1));
  48444. ExpectNull(c2i_ASN1_OBJECT(NULL, &nullPtr, 1));
  48445. /* Invalid encoding at length. */
  48446. p = objDerInvalidLen;
  48447. ExpectNull(d2i_ASN1_OBJECT(&a, &p, sizeof(objDerInvalidLen)));
  48448. p = objDerBadLen;
  48449. ExpectNull(d2i_ASN1_OBJECT(&a, &p, sizeof(objDerBadLen)));
  48450. p = objDerNotObj;
  48451. ExpectNull(d2i_ASN1_OBJECT(&a, &p, sizeof(objDerNotObj)));
  48452. p = objDerNoData;
  48453. ExpectNull(d2i_ASN1_OBJECT(&a, &p, sizeof(objDerNoData)));
  48454. /* Create an ASN OBJECT from content */
  48455. p = derBuf + 2;
  48456. ExpectNotNull(a = c2i_ASN1_OBJECT(NULL, &p, 8));
  48457. ASN1_OBJECT_free(a);
  48458. a = NULL;
  48459. /* Create an ASN OBJECT from DER */
  48460. ExpectNotNull(d2i_ASN1_OBJECT(&a, &derBuf, len));
  48461. /* Invalid parameter testing. */
  48462. ExpectIntEQ(i2d_ASN1_OBJECT(NULL, NULL), 0);
  48463. ExpectIntEQ(i2d_ASN1_OBJECT(&s, NULL), 0);
  48464. ExpectIntEQ(i2d_ASN1_OBJECT(a, NULL), 10);
  48465. der = NULL;
  48466. ExpectIntEQ(i2d_ASN1_OBJECT(a, &der), 10);
  48467. derPtr = objDer;
  48468. ExpectIntEQ(i2d_ASN1_OBJECT(a, &derPtr), 10);
  48469. ExpectPtrNE(derPtr, objDer);
  48470. ExpectIntEQ(XMEMCMP(der, objDer, 10), 0);
  48471. XFREE(der, NULL, DYNAMIC_TYPE_OPENSSL);
  48472. ASN1_OBJECT_free(a);
  48473. #endif /* OPENSSL_EXTRA && HAVE_ECC && USE_CERT_BUFFERS_256 */
  48474. return EXPECT_RESULT();
  48475. }
  48476. static int test_wolfSSL_i2a_ASN1_OBJECT(void)
  48477. {
  48478. EXPECT_DECLS;
  48479. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && !defined(NO_BIO)
  48480. ASN1_OBJECT* obj = NULL;
  48481. ASN1_OBJECT* a = NULL;
  48482. BIO *bio = NULL;
  48483. const unsigned char notObjDer[] = { 0x04, 0x01, 0xff };
  48484. const unsigned char* p;
  48485. ExpectNotNull(obj = OBJ_nid2obj(NID_sha256));
  48486. ExpectTrue((bio = BIO_new(BIO_s_mem())) != NULL);
  48487. ExpectIntGT(wolfSSL_i2a_ASN1_OBJECT(bio, obj), 0);
  48488. ExpectIntGT(wolfSSL_i2a_ASN1_OBJECT(bio, NULL), 0);
  48489. ExpectIntEQ(wolfSSL_i2a_ASN1_OBJECT(NULL, obj), 0);
  48490. /* No DER encoding in ASN1_OBJECT. */
  48491. ExpectNotNull(a = wolfSSL_ASN1_OBJECT_new());
  48492. ExpectIntEQ(wolfSSL_i2a_ASN1_OBJECT(bio, a), 0);
  48493. ASN1_OBJECT_free(a);
  48494. a = NULL;
  48495. /* DER encoding */
  48496. p = notObjDer;
  48497. ExpectNotNull(a = c2i_ASN1_OBJECT(NULL, &p, 3));
  48498. ExpectIntEQ(wolfSSL_i2a_ASN1_OBJECT(bio, a), 5);
  48499. ASN1_OBJECT_free(a);
  48500. BIO_free(bio);
  48501. ASN1_OBJECT_free(obj);
  48502. #endif
  48503. return EXPECT_RESULT();
  48504. }
  48505. static int test_wolfSSL_i2t_ASN1_OBJECT(void)
  48506. {
  48507. EXPECT_DECLS;
  48508. #if defined(OPENSSL_EXTRA) && \
  48509. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)
  48510. char buf[50] = {0};
  48511. ASN1_OBJECT* obj;
  48512. const char* oid = "2.5.29.19";
  48513. const char* ln = "X509v3 Basic Constraints";
  48514. obj = NULL;
  48515. ExpectIntEQ(i2t_ASN1_OBJECT(NULL, sizeof(buf), obj), 0);
  48516. ExpectIntEQ(i2t_ASN1_OBJECT(buf, sizeof(buf), NULL), 0);
  48517. ExpectIntEQ(i2t_ASN1_OBJECT(buf, 0, NULL), 0);
  48518. ExpectNotNull(obj = OBJ_txt2obj(oid, 0));
  48519. XMEMSET(buf, 0, sizeof(buf));
  48520. ExpectIntEQ(i2t_ASN1_OBJECT(buf, sizeof(buf), obj), XSTRLEN(ln));
  48521. ExpectIntEQ(XSTRNCMP(buf, ln, XSTRLEN(ln)), 0);
  48522. ASN1_OBJECT_free(obj);
  48523. #endif /* OPENSSL_EXTRA && WOLFSSL_CERT_EXT && WOLFSSL_CERT_GEN */
  48524. return EXPECT_RESULT();
  48525. }
  48526. static int test_wolfSSL_sk_ASN1_OBJECT(void)
  48527. {
  48528. EXPECT_DECLS;
  48529. #if !defined(NO_ASN) && (defined(OPENSSL_EXTRA) || defined(WOLFSSL_WPAS_SMALL))
  48530. WOLFSSL_STACK* sk = NULL;
  48531. WOLFSSL_ASN1_OBJECT* obj;
  48532. ExpectNotNull(obj = wolfSSL_ASN1_OBJECT_new());
  48533. ExpectNotNull(sk = wolfSSL_sk_new_asn1_obj());
  48534. wolfSSL_sk_ASN1_OBJECT_free(sk);
  48535. sk = NULL;
  48536. ExpectNotNull(sk = wolfSSL_sk_new_asn1_obj());
  48537. ExpectIntEQ(wolfSSL_sk_ASN1_OBJECT_push(NULL, NULL), -1);
  48538. ExpectIntEQ(wolfSSL_sk_ASN1_OBJECT_push(sk, NULL), 0);
  48539. ExpectIntEQ(wolfSSL_sk_ASN1_OBJECT_push(NULL, obj), -1);
  48540. ExpectIntEQ(wolfSSL_sk_ASN1_OBJECT_push(sk, obj), 1);
  48541. wolfSSL_sk_ASN1_OBJECT_pop_free(sk, NULL);
  48542. sk = NULL;
  48543. /* obj freed in pop_free call. */
  48544. ExpectNotNull(obj = wolfSSL_ASN1_OBJECT_new());
  48545. ExpectNotNull(sk = wolfSSL_sk_new_asn1_obj());
  48546. ExpectIntEQ(wolfSSL_sk_ASN1_OBJECT_push(sk, obj), 1);
  48547. ExpectPtrEq(obj, wolfSSL_sk_ASN1_OBJECT_pop(sk));
  48548. wolfSSL_sk_ASN1_OBJECT_free(sk);
  48549. wolfSSL_ASN1_OBJECT_free(obj);
  48550. #endif /* !NO_ASN && (OPENSSL_EXTRA || WOLFSSL_WPAS_SMALL) */
  48551. return EXPECT_RESULT();
  48552. }
  48553. static int test_wolfSSL_ASN1_STRING(void)
  48554. {
  48555. EXPECT_DECLS;
  48556. #if defined(OPENSSL_EXTRA)
  48557. ASN1_STRING* str = NULL;
  48558. ASN1_STRING* c = NULL;
  48559. const char data[] = "hello wolfSSL";
  48560. const char data2[] = "Same len data";
  48561. const char longData[] =
  48562. "This string must be longer than CTC_NAME_SIZE that is defined as 64.";
  48563. ExpectNotNull(str = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  48564. ASN1_STRING_free(str);
  48565. str = NULL;
  48566. ExpectNotNull(str = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  48567. ExpectIntEQ(ASN1_STRING_type(str), V_ASN1_OCTET_STRING);
  48568. ExpectIntEQ(ASN1_STRING_type(NULL), 0);
  48569. /* Check setting to NULL works. */
  48570. ExpectIntEQ(ASN1_STRING_set(str, NULL, 0), 1);
  48571. ExpectIntEQ(ASN1_STRING_set(str, (const void*)data, sizeof(data)), 1);
  48572. ExpectIntEQ(ASN1_STRING_set(str, (const void*)data, -1), 1);
  48573. ExpectIntEQ(ASN1_STRING_set(str, NULL, -1), 0);
  48574. ExpectIntEQ(ASN1_STRING_set(NULL, NULL, 0), 0);
  48575. ExpectIntEQ(wolfSSL_ASN1_STRING_copy(NULL, NULL), 0);
  48576. ExpectIntEQ(wolfSSL_ASN1_STRING_copy(str, NULL), 0);
  48577. ExpectIntEQ(wolfSSL_ASN1_STRING_copy(NULL, str), 0);
  48578. ExpectNull(wolfSSL_ASN1_STRING_dup(NULL));
  48579. ExpectNotNull(c = wolfSSL_ASN1_STRING_dup(str));
  48580. ExpectIntEQ(ASN1_STRING_cmp(NULL, NULL), -1);
  48581. ExpectIntEQ(ASN1_STRING_cmp(str, NULL), -1);
  48582. ExpectIntEQ(ASN1_STRING_cmp(NULL, c), -1);
  48583. ExpectIntEQ(ASN1_STRING_cmp(str, c), 0);
  48584. ExpectIntEQ(ASN1_STRING_set(c, (const void*)data2, -1), 1);
  48585. ExpectIntGT(ASN1_STRING_cmp(str, c), 0);
  48586. ExpectIntEQ(ASN1_STRING_set(str, (const void*)longData, -1), 1);
  48587. ExpectIntEQ(wolfSSL_ASN1_STRING_copy(c, str), 1);
  48588. ExpectIntEQ(ASN1_STRING_cmp(str, c), 0);
  48589. /* Check setting back to smaller size frees dynamic data. */
  48590. ExpectIntEQ(ASN1_STRING_set(str, (const void*)data, -1), 1);
  48591. ExpectIntLT(ASN1_STRING_cmp(str, c), 0);
  48592. ExpectIntGT(ASN1_STRING_cmp(c, str), 0);
  48593. ExpectNull(ASN1_STRING_get0_data(NULL));
  48594. ExpectNotNull(ASN1_STRING_get0_data(str));
  48595. ExpectNull(ASN1_STRING_data(NULL));
  48596. ExpectNotNull(ASN1_STRING_data(str));
  48597. ExpectIntEQ(ASN1_STRING_length(NULL), 0);
  48598. ExpectIntGT(ASN1_STRING_length(str), 0);
  48599. ASN1_STRING_free(c);
  48600. ASN1_STRING_free(str);
  48601. ASN1_STRING_free(NULL);
  48602. #ifndef NO_WOLFSSL_STUB
  48603. ExpectNull(d2i_DISPLAYTEXT(NULL, NULL, 0));
  48604. #endif
  48605. #endif
  48606. return EXPECT_RESULT();
  48607. }
  48608. static int test_wolfSSL_ASN1_STRING_to_UTF8(void)
  48609. {
  48610. EXPECT_DECLS;
  48611. #if defined(OPENSSL_ALL) && !defined(NO_ASN) && !defined(NO_RSA) && \
  48612. !defined(NO_FILESYSTEM)
  48613. WOLFSSL_X509* x509 = NULL;
  48614. WOLFSSL_X509_NAME* subject = NULL;
  48615. WOLFSSL_X509_NAME_ENTRY* e = NULL;
  48616. WOLFSSL_ASN1_STRING* a = NULL;
  48617. FILE* file = XBADFILE;
  48618. int idx = 0;
  48619. char targetOutput[16] = "www.wolfssl.com";
  48620. unsigned char* actual_output = NULL;
  48621. int len = 0;
  48622. ExpectNotNull(file = fopen("./certs/server-cert.pem", "rb"));
  48623. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(file, NULL, NULL, NULL));
  48624. if (file != XBADFILE)
  48625. fclose(file);
  48626. /* wolfSSL_ASN1_STRING_to_UTF8(): NID_commonName */
  48627. ExpectNotNull(subject = wolfSSL_X509_get_subject_name(x509));
  48628. ExpectIntEQ((idx = wolfSSL_X509_NAME_get_index_by_NID(subject,
  48629. NID_commonName, -1)), 5);
  48630. ExpectNotNull(e = wolfSSL_X509_NAME_get_entry(subject, idx));
  48631. ExpectNotNull(a = wolfSSL_X509_NAME_ENTRY_get_data(e));
  48632. ExpectIntEQ((len = wolfSSL_ASN1_STRING_to_UTF8(&actual_output, a)), 15);
  48633. ExpectIntEQ(strncmp((const char*)actual_output, targetOutput, (size_t)len), 0);
  48634. a = NULL;
  48635. /* wolfSSL_ASN1_STRING_to_UTF8(NULL, valid) */
  48636. ExpectIntEQ((len = wolfSSL_ASN1_STRING_to_UTF8(NULL, a)), -1);
  48637. /* wolfSSL_ASN1_STRING_to_UTF8(valid, NULL) */
  48638. ExpectIntEQ((len = wolfSSL_ASN1_STRING_to_UTF8(&actual_output, NULL)), -1);
  48639. /* wolfSSL_ASN1_STRING_to_UTF8(NULL, NULL) */
  48640. ExpectIntEQ((len = wolfSSL_ASN1_STRING_to_UTF8(NULL, NULL)), -1);
  48641. wolfSSL_X509_free(x509);
  48642. XFREE(actual_output, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48643. ExpectNotNull(a = ASN1_STRING_new());
  48644. ExpectIntEQ(wolfSSL_ASN1_STRING_to_UTF8(&actual_output, a), -1);
  48645. ASN1_STRING_free(a);
  48646. #endif
  48647. return EXPECT_RESULT();
  48648. }
  48649. static int test_wolfSSL_i2s_ASN1_STRING(void)
  48650. {
  48651. EXPECT_DECLS;
  48652. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  48653. WOLFSSL_ASN1_STRING* str = NULL;
  48654. const char* data = "test_wolfSSL_i2s_ASN1_STRING";
  48655. char* ret = NULL;
  48656. ExpectNotNull(str = ASN1_STRING_new());
  48657. ExpectNull(ret = wolfSSL_i2s_ASN1_STRING(NULL, NULL));
  48658. XFREE(ret, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48659. ret = NULL;
  48660. /* No data. */
  48661. ExpectNull(ret = wolfSSL_i2s_ASN1_STRING(NULL, str));
  48662. XFREE(ret, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48663. ret = NULL;
  48664. ExpectIntEQ(ASN1_STRING_set(str, data, 0), 1);
  48665. ExpectNotNull(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, -1), 1);
  48669. /* No type. */
  48670. ExpectNotNull(ret = wolfSSL_i2s_ASN1_STRING(NULL, str));
  48671. XFREE(ret, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  48672. ASN1_STRING_free(str);
  48673. #endif
  48674. return EXPECT_RESULT();
  48675. }
  48676. static int test_wolfSSL_ASN1_STRING_canon(void)
  48677. {
  48678. EXPECT_DECLS;
  48679. #if defined(WOLFSSL_TEST_STATIC_BUILD)
  48680. #if !defined(NO_CERTS) && (defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA) || \
  48681. defined(OPENSSL_EXTRA_X509_SMALL))
  48682. WOLFSSL_ASN1_STRING* orig = NULL;
  48683. WOLFSSL_ASN1_STRING* canon = NULL;
  48684. const char* data = "test_wolfSSL_ASN1_STRING_canon";
  48685. const char* whitespaceOnly = "\t\r\n";
  48686. const char* modData = " \x01\f\t\x02\r\n\v\xff\nTt \n";
  48687. const char* canonData = "\x01 \x02 \xff tt";
  48688. const char longData[] =
  48689. "This string must be longer than CTC_NAME_SIZE that is defined as 64.";
  48690. ExpectNotNull(orig = ASN1_STRING_new());
  48691. ExpectNotNull(canon = ASN1_STRING_new());
  48692. /* Invalid parameter testing. */
  48693. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48694. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48695. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(NULL, orig), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48696. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, orig), 1);
  48697. ExpectIntEQ(ASN1_STRING_cmp(orig, canon), 0);
  48698. ExpectIntEQ(ASN1_STRING_set(orig, longData, (int)XSTRLEN(data)), 1);
  48699. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, orig), 1);
  48700. ExpectIntEQ(ASN1_STRING_cmp(orig, canon), 0);
  48701. ExpectIntEQ(ASN1_STRING_set(orig, data, (int)XSTRLEN(data)), 1);
  48702. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, orig), 1);
  48703. ExpectIntEQ(ASN1_STRING_cmp(orig, canon), 0);
  48704. ASN1_STRING_free(orig);
  48705. orig = NULL;
  48706. ExpectNotNull(orig = ASN1_STRING_type_new(MBSTRING_UTF8));
  48707. ExpectIntEQ(ASN1_STRING_set(orig, modData, 15), 1);
  48708. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, orig), 1);
  48709. ExpectIntEQ(ASN1_STRING_set(orig, canonData, 8), 1);
  48710. ExpectIntEQ(ASN1_STRING_cmp(orig, canon), 0);
  48711. ASN1_STRING_free(orig);
  48712. orig = NULL;
  48713. ExpectNotNull(orig = ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING));
  48714. ExpectIntEQ(ASN1_STRING_set(orig, whitespaceOnly, 3), 1);
  48715. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, orig), 1);
  48716. ASN1_STRING_free(orig);
  48717. orig = NULL;
  48718. ExpectNotNull(orig = ASN1_STRING_type_new(MBSTRING_UTF8));
  48719. ExpectIntEQ(ASN1_STRING_cmp(orig, canon), 0);
  48720. ASN1_STRING_free(orig);
  48721. ASN1_STRING_free(canon);
  48722. #endif
  48723. #endif
  48724. return EXPECT_RESULT();
  48725. }
  48726. static int test_wolfSSL_ASN1_STRING_print(void)
  48727. {
  48728. EXPECT_DECLS;
  48729. #if defined(OPENSSL_ALL) && !defined(NO_ASN) && !defined(NO_CERTS) && \
  48730. !defined(NO_BIO)
  48731. ASN1_STRING* asnStr = NULL;
  48732. const char HELLO_DATA[]= \
  48733. {'H','e','l','l','o',' ','w','o','l','f','S','S','L','!'};
  48734. #define MAX_UNPRINTABLE_CHAR 32
  48735. #define MAX_BUF 255
  48736. unsigned char unprintableData[MAX_UNPRINTABLE_CHAR + sizeof(HELLO_DATA)];
  48737. unsigned char expected[sizeof(unprintableData)+1];
  48738. unsigned char rbuf[MAX_BUF];
  48739. BIO *bio = NULL;
  48740. int p_len;
  48741. int i;
  48742. /* setup */
  48743. for (i = 0; i < (int)sizeof(HELLO_DATA); i++) {
  48744. unprintableData[i] = (unsigned char)HELLO_DATA[i];
  48745. expected[i] = (unsigned char)HELLO_DATA[i];
  48746. }
  48747. for (i = 0; i < (int)MAX_UNPRINTABLE_CHAR; i++) {
  48748. unprintableData[sizeof(HELLO_DATA)+i] = i;
  48749. if (i == (int)'\n' || i == (int)'\r')
  48750. expected[sizeof(HELLO_DATA)+i] = i;
  48751. else
  48752. expected[sizeof(HELLO_DATA)+i] = '.';
  48753. }
  48754. unprintableData[sizeof(unprintableData)-1] = '\0';
  48755. expected[sizeof(expected)-1] = '\0';
  48756. XMEMSET(rbuf, 0, MAX_BUF);
  48757. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  48758. ExpectIntEQ(BIO_set_write_buf_size(bio, MAX_BUF), 0);
  48759. ExpectNotNull(asnStr = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  48760. ExpectIntEQ(ASN1_STRING_set(asnStr,(const void*)unprintableData,
  48761. (int)sizeof(unprintableData)), 1);
  48762. /* test */
  48763. ExpectIntEQ(wolfSSL_ASN1_STRING_print(NULL, NULL), 0);
  48764. ExpectIntEQ(wolfSSL_ASN1_STRING_print(bio, NULL), 0);
  48765. ExpectIntEQ(wolfSSL_ASN1_STRING_print(NULL, asnStr), 0);
  48766. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print(bio, asnStr), 46);
  48767. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 46), 46);
  48768. ExpectStrEQ((char*)rbuf, (const char*)expected);
  48769. BIO_free(bio);
  48770. bio = NULL;
  48771. ExpectNotNull(bio = BIO_new(wolfSSL_BIO_s_fixed_mem()));
  48772. ExpectIntEQ(BIO_set_write_buf_size(bio, 1), 1);
  48773. /* Ensure there is 0 bytes available to write into. */
  48774. ExpectIntEQ(BIO_write(bio, rbuf, 1), 1);
  48775. ExpectIntEQ(wolfSSL_ASN1_STRING_print(bio, asnStr), 0);
  48776. ExpectIntEQ(BIO_set_write_buf_size(bio, 1), 1);
  48777. ExpectIntEQ(wolfSSL_ASN1_STRING_print(bio, asnStr), 0);
  48778. ExpectIntEQ(BIO_set_write_buf_size(bio, 45), 1);
  48779. ExpectIntEQ(wolfSSL_ASN1_STRING_print(bio, asnStr), 0);
  48780. BIO_free(bio);
  48781. ASN1_STRING_free(asnStr);
  48782. #endif /* OPENSSL_EXTRA && !NO_ASN && !NO_CERTS && !NO_BIO */
  48783. return EXPECT_RESULT();
  48784. }
  48785. static int test_wolfSSL_ASN1_STRING_print_ex(void)
  48786. {
  48787. EXPECT_DECLS;
  48788. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && !defined(NO_BIO)
  48789. ASN1_STRING* asn_str = NULL;
  48790. const char data[] = "Hello wolfSSL!";
  48791. ASN1_STRING* esc_str = NULL;
  48792. const char esc_data[] = "a+;<>";
  48793. ASN1_STRING* neg_int = NULL;
  48794. const char neg_int_data[] = "\xff";
  48795. ASN1_STRING* neg_enum = NULL;
  48796. const char neg_enum_data[] = "\xff";
  48797. BIO *bio = NULL;
  48798. BIO *fixed = NULL;
  48799. unsigned long flags;
  48800. int p_len;
  48801. unsigned char rbuf[255];
  48802. /* setup */
  48803. XMEMSET(rbuf, 0, 255);
  48804. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  48805. ExpectIntEQ(BIO_set_write_buf_size(bio, 255), 0);
  48806. ExpectNotNull(fixed = BIO_new(wolfSSL_BIO_s_fixed_mem()));
  48807. ExpectNotNull(asn_str = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  48808. ExpectIntEQ(ASN1_STRING_set(asn_str, (const void*)data, sizeof(data)), 1);
  48809. ExpectNotNull(esc_str = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  48810. ExpectIntEQ(ASN1_STRING_set(esc_str, (const void*)esc_data,
  48811. sizeof(esc_data)), 1);
  48812. ExpectNotNull(neg_int = ASN1_STRING_type_new(V_ASN1_NEG_INTEGER));
  48813. ExpectIntEQ(ASN1_STRING_set(neg_int, (const void*)neg_int_data,
  48814. sizeof(neg_int_data) - 1), 1);
  48815. ExpectNotNull(neg_enum = ASN1_STRING_type_new(V_ASN1_NEG_ENUMERATED));
  48816. ExpectIntEQ(ASN1_STRING_set(neg_enum, (const void*)neg_enum_data,
  48817. sizeof(neg_enum_data) - 1), 1);
  48818. /* Invalid parameter testing. */
  48819. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(NULL, NULL, 0), 0);
  48820. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(bio, NULL, 0), 0);
  48821. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(NULL, asn_str, 0), 0);
  48822. /* no flags */
  48823. XMEMSET(rbuf, 0, 255);
  48824. flags = 0;
  48825. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, asn_str, flags), 15);
  48826. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 15), 15);
  48827. ExpectStrEQ((char*)rbuf, "Hello wolfSSL!");
  48828. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48829. /* Ensure there is 0 bytes available to write into. */
  48830. ExpectIntEQ(BIO_write(fixed, rbuf, 1), 1);
  48831. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48832. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48833. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48834. ExpectIntEQ(BIO_set_write_buf_size(fixed, 14), 1);
  48835. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48836. /* RFC2253 Escape */
  48837. XMEMSET(rbuf, 0, 255);
  48838. flags = ASN1_STRFLGS_ESC_2253;
  48839. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, esc_str, flags), 9);
  48840. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 9), 9);
  48841. ExpectStrEQ((char*)rbuf, "a\\+\\;\\<\\>");
  48842. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48843. /* Ensure there is 0 bytes available to write into. */
  48844. ExpectIntEQ(BIO_write(fixed, rbuf, 1), 1);
  48845. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, esc_str, flags), 0);
  48846. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48847. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, esc_str, flags), 0);
  48848. ExpectIntEQ(BIO_set_write_buf_size(fixed, 8), 1);
  48849. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, esc_str, flags), 0);
  48850. /* Show type */
  48851. XMEMSET(rbuf, 0, 255);
  48852. flags = ASN1_STRFLGS_SHOW_TYPE;
  48853. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, asn_str, flags), 28);
  48854. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 28), 28);
  48855. ExpectStrEQ((char*)rbuf, "OCTET STRING:Hello wolfSSL!");
  48856. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48857. /* Ensure there is 0 bytes available to write into. */
  48858. ExpectIntEQ(BIO_write(fixed, rbuf, 1), 1);
  48859. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48860. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48861. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48862. ExpectIntEQ(BIO_set_write_buf_size(fixed, 12), 1);
  48863. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48864. ExpectIntEQ(BIO_set_write_buf_size(fixed, 27), 1);
  48865. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48866. /* Dump All */
  48867. XMEMSET(rbuf, 0, 255);
  48868. flags = ASN1_STRFLGS_DUMP_ALL;
  48869. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, asn_str, flags), 31);
  48870. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 31), 31);
  48871. ExpectStrEQ((char*)rbuf, "#48656C6C6F20776F6C6653534C2100");
  48872. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48873. /* Ensure there is 0 bytes available to write into. */
  48874. ExpectIntEQ(BIO_write(fixed, rbuf, 1), 1);
  48875. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48876. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48877. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48878. ExpectIntEQ(BIO_set_write_buf_size(fixed, 30), 1);
  48879. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48880. /* Dump Der */
  48881. XMEMSET(rbuf, 0, 255);
  48882. flags = ASN1_STRFLGS_DUMP_ALL | ASN1_STRFLGS_DUMP_DER;
  48883. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, asn_str, flags), 35);
  48884. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 35), 35);
  48885. ExpectStrEQ((char*)rbuf, "#040F48656C6C6F20776F6C6653534C2100");
  48886. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48887. /* Ensure there is 0 bytes available to write into. */
  48888. ExpectIntEQ(BIO_write(fixed, rbuf, 1), 1);
  48889. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48890. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  48891. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48892. ExpectIntEQ(BIO_set_write_buf_size(fixed, 2), 1);
  48893. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48894. ExpectIntEQ(BIO_set_write_buf_size(fixed, 30), 1);
  48895. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  48896. /* Dump All + Show type */
  48897. XMEMSET(rbuf, 0, 255);
  48898. flags = ASN1_STRFLGS_DUMP_ALL | ASN1_STRFLGS_SHOW_TYPE;
  48899. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, asn_str, flags), 44);
  48900. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 44), 44);
  48901. ExpectStrEQ((char*)rbuf, "OCTET STRING:#48656C6C6F20776F6C6653534C2100");
  48902. /* Dump All + Show type - Negative Integer. */
  48903. XMEMSET(rbuf, 0, 255);
  48904. flags = ASN1_STRFLGS_DUMP_ALL | ASN1_STRFLGS_SHOW_TYPE;
  48905. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, neg_int, flags), 11);
  48906. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 11), 11);
  48907. ExpectStrEQ((char*)rbuf, "INTEGER:#FF");
  48908. /* Dump All + Show type - Negative Enumerated. */
  48909. XMEMSET(rbuf, 0, 255);
  48910. flags = ASN1_STRFLGS_DUMP_ALL | ASN1_STRFLGS_SHOW_TYPE;
  48911. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, neg_enum, flags), 14);
  48912. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 14), 14);
  48913. ExpectStrEQ((char*)rbuf, "ENUMERATED:#FF");
  48914. BIO_free(fixed);
  48915. BIO_free(bio);
  48916. ASN1_STRING_free(asn_str);
  48917. ASN1_STRING_free(esc_str);
  48918. ASN1_STRING_free(neg_int);
  48919. ASN1_STRING_free(neg_enum);
  48920. ExpectStrEQ(wolfSSL_ASN1_tag2str(-1), "(unknown)");
  48921. ExpectStrEQ(wolfSSL_ASN1_tag2str(31), "(unknown)");
  48922. #endif
  48923. return EXPECT_RESULT();
  48924. }
  48925. static int test_wolfSSL_ASN1_UNIVERSALSTRING_to_string(void)
  48926. {
  48927. EXPECT_DECLS;
  48928. #if defined(OPENSSL_ALL) && !defined(NO_ASN)
  48929. ASN1_STRING* asn1str_test = NULL;
  48930. ASN1_STRING* asn1str_answer = NULL;
  48931. /* Each character is encoded using 4 bytes */
  48932. char input[] = {
  48933. 0, 0, 0, 'T',
  48934. 0, 0, 0, 'e',
  48935. 0, 0, 0, 's',
  48936. 0, 0, 0, 't',
  48937. };
  48938. char output[] = "Test";
  48939. char badInput[] = {
  48940. 1, 0, 0, 'T',
  48941. 0, 1, 0, 'e',
  48942. 0, 0, 1, 's',
  48943. };
  48944. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(NULL), 0);
  48945. /* Test wrong type. */
  48946. ExpectNotNull(asn1str_test = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  48947. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 0);
  48948. ASN1_STRING_free(asn1str_test);
  48949. asn1str_test = NULL;
  48950. ExpectNotNull(asn1str_test = ASN1_STRING_type_new(V_ASN1_UNIVERSALSTRING));
  48951. /* Test bad length. */
  48952. ExpectIntEQ(ASN1_STRING_set(asn1str_test, input, sizeof(input) - 1), 1);
  48953. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 0);
  48954. /* Test bad input. */
  48955. ExpectIntEQ(ASN1_STRING_set(asn1str_test, badInput + 0, 4), 1);
  48956. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 0);
  48957. ExpectIntEQ(ASN1_STRING_set(asn1str_test, badInput + 4, 4), 1);
  48958. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 0);
  48959. ExpectIntEQ(ASN1_STRING_set(asn1str_test, badInput + 8, 4), 1);
  48960. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 0);
  48961. ExpectIntEQ(ASN1_STRING_set(asn1str_test, input, sizeof(input)), 1);
  48962. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 1);
  48963. ExpectNotNull(
  48964. asn1str_answer = ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING));
  48965. ExpectIntEQ(ASN1_STRING_set(asn1str_answer, output, sizeof(output)-1), 1);
  48966. ExpectIntEQ(ASN1_STRING_cmp(asn1str_test, asn1str_answer), 0);
  48967. ASN1_STRING_free(asn1str_test);
  48968. ASN1_STRING_free(asn1str_answer);
  48969. #endif /* OPENSSL_ALL && !NO_ASN */
  48970. return EXPECT_RESULT();
  48971. }
  48972. static int test_wolfSSL_ASN1_GENERALIZEDTIME_free(void)
  48973. {
  48974. EXPECT_DECLS;
  48975. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  48976. WOLFSSL_ASN1_GENERALIZEDTIME* asn1_gtime = NULL;
  48977. ExpectNotNull(asn1_gtime = ASN1_GENERALIZEDTIME_new());
  48978. if (asn1_gtime != NULL)
  48979. XMEMCPY(asn1_gtime->data, "20180504123500Z", ASN_GENERALIZED_TIME_SIZE);
  48980. ASN1_GENERALIZEDTIME_free(asn1_gtime);
  48981. #endif /* OPENSSL_EXTRA && !NO_ASN_TIME */
  48982. return EXPECT_RESULT();
  48983. }
  48984. static int test_wolfSSL_ASN1_GENERALIZEDTIME_print(void)
  48985. {
  48986. EXPECT_DECLS;
  48987. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME) && !defined(NO_BIO)
  48988. WOLFSSL_ASN1_GENERALIZEDTIME* gtime = NULL;
  48989. BIO* bio = NULL;
  48990. unsigned char buf[24];
  48991. int i;
  48992. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  48993. BIO_set_write_buf_size(bio, 24);
  48994. ExpectNotNull(gtime = ASN1_GENERALIZEDTIME_new());
  48995. /* Type not set. */
  48996. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(bio, gtime), 0);
  48997. ExpectIntEQ(wolfSSL_ASN1_TIME_set_string(gtime, "20180504123500Z"), 1);
  48998. /* Invalid parameters testing. */
  48999. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  49000. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(bio, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  49001. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(NULL, gtime), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  49002. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(bio, gtime), 1);
  49003. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 20);
  49004. ExpectIntEQ(XMEMCMP(buf, "May 04 12:35:00 2018", 20), 0);
  49005. BIO_free(bio);
  49006. bio = NULL;
  49007. ExpectNotNull(bio = BIO_new(wolfSSL_BIO_s_fixed_mem()));
  49008. ExpectIntEQ(BIO_set_write_buf_size(bio, 1), 1);
  49009. /* Ensure there is 0 bytes available to write into. */
  49010. ExpectIntEQ(BIO_write(bio, buf, 1), 1);
  49011. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(bio, gtime), 0);
  49012. for (i = 1; i < 20; i++) {
  49013. ExpectIntEQ(BIO_set_write_buf_size(bio, i), 1);
  49014. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(bio, gtime), 0);
  49015. }
  49016. BIO_free(bio);
  49017. wolfSSL_ASN1_GENERALIZEDTIME_free(gtime);
  49018. #endif /* OPENSSL_EXTRA && !NO_ASN_TIME && !NO_BIO */
  49019. return EXPECT_RESULT();
  49020. }
  49021. static int test_wolfSSL_ASN1_TIME(void)
  49022. {
  49023. EXPECT_DECLS;
  49024. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  49025. WOLFSSL_ASN1_TIME* asn_time = NULL;
  49026. unsigned char *data;
  49027. ExpectNotNull(asn_time = ASN1_TIME_new());
  49028. #ifndef NO_WOLFSSL_STUB
  49029. ExpectNotNull(ASN1_TIME_set(asn_time, 1));
  49030. #endif
  49031. ExpectIntEQ(ASN1_TIME_set_string(NULL, NULL), 0);
  49032. ExpectIntEQ(ASN1_TIME_set_string(asn_time, NULL), 0);
  49033. ExpectIntEQ(ASN1_TIME_set_string(NULL,
  49034. "String longer than CTC_DATA_SIZE that is 32 bytes"), 0);
  49035. ExpectIntEQ(ASN1_TIME_set_string(NULL, "101219181011Z"), 1);
  49036. ExpectIntEQ(ASN1_TIME_set_string(asn_time, "101219181011Z"), 1);
  49037. ExpectIntEQ(wolfSSL_ASN1_TIME_get_length(NULL), 0);
  49038. ExpectIntEQ(wolfSSL_ASN1_TIME_get_length(asn_time), ASN_UTC_TIME_SIZE - 1);
  49039. ExpectNull(wolfSSL_ASN1_TIME_get_data(NULL));
  49040. ExpectNotNull(data = wolfSSL_ASN1_TIME_get_data(asn_time));
  49041. ExpectIntEQ(XMEMCMP(data, "101219181011Z", 14), 0);
  49042. ExpectIntEQ(ASN1_TIME_check(NULL), 0);
  49043. ExpectIntEQ(ASN1_TIME_check(asn_time), 1);
  49044. ExpectIntEQ(ASN1_TIME_set_string_X509(asn_time, "101219181011Z"), 1);
  49045. ExpectIntEQ(ASN1_TIME_set_string_X509(asn_time, "101219181011Za"), 0);
  49046. ASN1_TIME_free(asn_time);
  49047. ASN1_TIME_free(NULL);
  49048. #endif
  49049. return EXPECT_RESULT();
  49050. }
  49051. static int test_wolfSSL_ASN1_TIME_to_string(void)
  49052. {
  49053. EXPECT_DECLS;
  49054. #ifndef NO_ASN_TIME
  49055. #if defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(WOLFSSL_NGINX) || \
  49056. defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)
  49057. WOLFSSL_ASN1_TIME* t = NULL;
  49058. char buf[ASN_GENERALIZED_TIME_SIZE];
  49059. ExpectNotNull((t = ASN1_TIME_new()));
  49060. ExpectIntEQ(ASN1_TIME_set_string(t, "030222211515Z"), 1);
  49061. /* Invalid parameter testing. */
  49062. ExpectNull(ASN1_TIME_to_string(NULL, NULL, 4));
  49063. ExpectNull(ASN1_TIME_to_string(t, NULL, 4));
  49064. ExpectNull(ASN1_TIME_to_string(NULL, buf, 4));
  49065. ExpectNull(ASN1_TIME_to_string(NULL, NULL, 5));
  49066. ExpectNull(ASN1_TIME_to_string(NULL, buf, 5));
  49067. ExpectNull(ASN1_TIME_to_string(t, NULL, 5));
  49068. ExpectNull(ASN1_TIME_to_string(t, buf, 4));
  49069. /* Buffer needs to be longer than minimum of 5 characters. */
  49070. ExpectNull(ASN1_TIME_to_string(t, buf, 5));
  49071. ASN1_TIME_free(t);
  49072. #endif
  49073. #endif /* NO_ASN_TIME */
  49074. return EXPECT_RESULT();
  49075. }
  49076. static int test_wolfSSL_ASN1_TIME_diff_compare(void)
  49077. {
  49078. EXPECT_DECLS;
  49079. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  49080. ASN1_TIME* fromTime = NULL;
  49081. ASN1_TIME* closeToTime = NULL;
  49082. ASN1_TIME* toTime = NULL;
  49083. ASN1_TIME* invalidTime = NULL;
  49084. int daysDiff = 0;
  49085. int secsDiff = 0;
  49086. ExpectNotNull((fromTime = ASN1_TIME_new()));
  49087. /* Feb 22, 2003, 21:15:15 */
  49088. ExpectIntEQ(ASN1_TIME_set_string(fromTime, "030222211515Z"), 1);
  49089. ExpectNotNull((closeToTime = ASN1_TIME_new()));
  49090. /* Feb 22, 2003, 21:16:15 */
  49091. ExpectIntEQ(ASN1_TIME_set_string(closeToTime, "030222211615Z"), 1);
  49092. ExpectNotNull((toTime = ASN1_TIME_new()));
  49093. /* Dec 19, 2010, 18:10:11 */
  49094. ExpectIntEQ(ASN1_TIME_set_string(toTime, "101219181011Z"), 1);
  49095. ExpectNotNull((invalidTime = ASN1_TIME_new()));
  49096. /* Dec 19, 2010, 18:10:11 but 'U' instead of 'Z' which is invalid. */
  49097. ExpectIntEQ(ASN1_TIME_set_string(invalidTime, "102519181011U"), 1);
  49098. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, invalidTime), 0);
  49099. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, invalidTime, toTime), 0);
  49100. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, toTime), 1);
  49101. /* Error conditions. */
  49102. ExpectIntEQ(ASN1_TIME_diff(NULL, &secsDiff, fromTime, toTime), 0);
  49103. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, NULL, fromTime, toTime), 0);
  49104. /* If both times are NULL, difference is 0. */
  49105. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, NULL, NULL), 1);
  49106. ExpectIntEQ(daysDiff, 0);
  49107. ExpectIntEQ(secsDiff, 0);
  49108. /* If one time is NULL, it defaults to the current time. */
  49109. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, NULL, toTime), 1);
  49110. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, NULL), 1);
  49111. /* Normal operation. Both times non-NULL. */
  49112. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, toTime), 1);
  49113. ExpectIntEQ(daysDiff, 2856);
  49114. ExpectIntEQ(secsDiff, 75296);
  49115. /* Swapping the times should return negative values. */
  49116. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, toTime, fromTime), 1);
  49117. ExpectIntEQ(daysDiff, -2856);
  49118. ExpectIntEQ(secsDiff, -75296);
  49119. /* Compare with invalid time string. */
  49120. ExpectIntEQ(ASN1_TIME_compare(fromTime, invalidTime), -2);
  49121. ExpectIntEQ(ASN1_TIME_compare(invalidTime, toTime), -2);
  49122. /* Compare with days difference of 0. */
  49123. ExpectIntEQ(ASN1_TIME_compare(fromTime, closeToTime), -1);
  49124. ExpectIntEQ(ASN1_TIME_compare(closeToTime, fromTime), 1);
  49125. /* Days and seconds differences not 0. */
  49126. ExpectIntEQ(ASN1_TIME_compare(fromTime, toTime), -1);
  49127. ExpectIntEQ(ASN1_TIME_compare(toTime, fromTime), 1);
  49128. /* Same time. */
  49129. ExpectIntEQ(ASN1_TIME_compare(fromTime, fromTime), 0);
  49130. /* Compare regression test: No seconds difference, just difference in days.
  49131. */
  49132. ASN1_TIME_set_string(fromTime, "19700101000000Z");
  49133. ASN1_TIME_set_string(toTime, "19800101000000Z");
  49134. ExpectIntEQ(ASN1_TIME_compare(fromTime, toTime), -1);
  49135. ExpectIntEQ(ASN1_TIME_compare(toTime, fromTime), 1);
  49136. ExpectIntEQ(ASN1_TIME_compare(fromTime, fromTime), 0);
  49137. /* Edge case with Unix epoch. */
  49138. ExpectNotNull(ASN1_TIME_set_string(fromTime, "19700101000000Z"));
  49139. ExpectNotNull(ASN1_TIME_set_string(toTime, "19800101000000Z"));
  49140. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, toTime), 1);
  49141. ExpectIntEQ(daysDiff, 3652);
  49142. ExpectIntEQ(secsDiff, 0);
  49143. /* Edge case with year > 2038 (year 2038 problem). */
  49144. ExpectNotNull(ASN1_TIME_set_string(toTime, "99991231235959Z"));
  49145. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, toTime), 1);
  49146. ExpectIntEQ(daysDiff, 2932896);
  49147. ExpectIntEQ(secsDiff, 86399);
  49148. ASN1_TIME_free(fromTime);
  49149. ASN1_TIME_free(closeToTime);
  49150. ASN1_TIME_free(toTime);
  49151. ASN1_TIME_free(invalidTime);
  49152. #endif
  49153. return EXPECT_RESULT();
  49154. }
  49155. static int test_wolfSSL_ASN1_TIME_adj(void)
  49156. {
  49157. EXPECT_DECLS;
  49158. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME) && \
  49159. !defined(USER_TIME) && !defined(TIME_OVERRIDES)
  49160. const int year = 365*24*60*60;
  49161. const int day = 24*60*60;
  49162. const int hour = 60*60;
  49163. const int mini = 60;
  49164. const byte asn_utc_time = ASN_UTC_TIME;
  49165. #if !defined(TIME_T_NOT_64BIT) && !defined(NO_64BIT)
  49166. const byte asn_gen_time = ASN_GENERALIZED_TIME;
  49167. #endif
  49168. WOLFSSL_ASN1_TIME* asn_time = NULL;
  49169. WOLFSSL_ASN1_TIME* s = NULL;
  49170. int offset_day;
  49171. long offset_sec;
  49172. char date_str[CTC_DATE_SIZE + 1];
  49173. time_t t;
  49174. ExpectNotNull(s = wolfSSL_ASN1_TIME_new());
  49175. /* UTC notation test */
  49176. /* 2000/2/15 20:30:00 */
  49177. t = (time_t)30 * year + 45 * day + 20 * hour + 30 * mini + 7 * day;
  49178. offset_day = 7;
  49179. offset_sec = 45 * mini;
  49180. /* offset_sec = -45 * min;*/
  49181. ExpectNotNull(asn_time =
  49182. wolfSSL_ASN1_TIME_adj(s, t, offset_day, offset_sec));
  49183. ExpectTrue(asn_time->type == asn_utc_time);
  49184. ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
  49185. CTC_DATE_SIZE));
  49186. date_str[CTC_DATE_SIZE] = '\0';
  49187. ExpectIntEQ(0, XMEMCMP(date_str, "000222211500Z", 13));
  49188. /* negative offset */
  49189. offset_sec = -45 * mini;
  49190. asn_time = wolfSSL_ASN1_TIME_adj(s, t, offset_day, offset_sec);
  49191. ExpectNotNull(asn_time);
  49192. ExpectTrue(asn_time->type == asn_utc_time);
  49193. ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
  49194. CTC_DATE_SIZE));
  49195. date_str[CTC_DATE_SIZE] = '\0';
  49196. ExpectIntEQ(0, XMEMCMP(date_str, "000222194500Z", 13));
  49197. XFREE(s, NULL, DYNAMIC_TYPE_OPENSSL);
  49198. s = NULL;
  49199. XMEMSET(date_str, 0, sizeof(date_str));
  49200. /* Generalized time will overflow time_t if not long */
  49201. #if !defined(TIME_T_NOT_64BIT) && !defined(NO_64BIT)
  49202. s = (WOLFSSL_ASN1_TIME*)XMALLOC(sizeof(WOLFSSL_ASN1_TIME), NULL,
  49203. DYNAMIC_TYPE_OPENSSL);
  49204. /* GeneralizedTime notation test */
  49205. /* 2055/03/01 09:00:00 */
  49206. t = (time_t)85 * year + 59 * day + 9 * hour + 21 * day;
  49207. offset_day = 12;
  49208. offset_sec = 10 * mini;
  49209. ExpectNotNull(asn_time = wolfSSL_ASN1_TIME_adj(s, t, offset_day,
  49210. offset_sec));
  49211. ExpectTrue(asn_time->type == asn_gen_time);
  49212. ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
  49213. CTC_DATE_SIZE));
  49214. date_str[CTC_DATE_SIZE] = '\0';
  49215. ExpectIntEQ(0, XMEMCMP(date_str, "20550313091000Z", 15));
  49216. XFREE(s, NULL, DYNAMIC_TYPE_OPENSSL);
  49217. s = NULL;
  49218. XMEMSET(date_str, 0, sizeof(date_str));
  49219. #endif /* !TIME_T_NOT_64BIT && !NO_64BIT */
  49220. /* if WOLFSSL_ASN1_TIME struct is not allocated */
  49221. s = NULL;
  49222. t = (time_t)30 * year + 45 * day + 20 * hour + 30 * mini + 15 + 7 * day;
  49223. offset_day = 7;
  49224. offset_sec = 45 * mini;
  49225. ExpectNotNull(asn_time = wolfSSL_ASN1_TIME_adj(s, t, offset_day,
  49226. offset_sec));
  49227. ExpectTrue(asn_time->type == asn_utc_time);
  49228. ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
  49229. CTC_DATE_SIZE));
  49230. date_str[CTC_DATE_SIZE] = '\0';
  49231. ExpectIntEQ(0, XMEMCMP(date_str, "000222211515Z", 13));
  49232. XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
  49233. asn_time = NULL;
  49234. ExpectNotNull(asn_time = wolfSSL_ASN1_TIME_adj(NULL, t, offset_day,
  49235. offset_sec));
  49236. ExpectTrue(asn_time->type == asn_utc_time);
  49237. ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
  49238. CTC_DATE_SIZE));
  49239. date_str[CTC_DATE_SIZE] = '\0';
  49240. ExpectIntEQ(0, XMEMCMP(date_str, "000222211515Z", 13));
  49241. XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
  49242. #endif
  49243. return EXPECT_RESULT();
  49244. }
  49245. static int test_wolfSSL_ASN1_TIME_to_tm(void)
  49246. {
  49247. EXPECT_DECLS;
  49248. #if (defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(WOLFSSL_NGINX) || \
  49249. defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA) || \
  49250. defined(OPENSSL_ALL)) && !defined(NO_ASN_TIME)
  49251. ASN1_TIME asnTime;
  49252. struct tm tm;
  49253. time_t testTime = 1683926567; /* Fri May 12 09:22:47 PM UTC 2023 */
  49254. XMEMSET(&tm, 0, sizeof(struct tm));
  49255. XMEMSET(&asnTime, 0, sizeof(ASN1_TIME));
  49256. ExpectIntEQ(ASN1_TIME_set_string(&asnTime, "000222211515Z"), 1);
  49257. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, NULL), 1);
  49258. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 1);
  49259. ExpectIntEQ(tm.tm_sec, 15);
  49260. ExpectIntEQ(tm.tm_min, 15);
  49261. ExpectIntEQ(tm.tm_hour, 21);
  49262. ExpectIntEQ(tm.tm_mday, 22);
  49263. ExpectIntEQ(tm.tm_mon, 1);
  49264. ExpectIntEQ(tm.tm_year, 100);
  49265. ExpectIntEQ(tm.tm_isdst, 0);
  49266. #ifdef XMKTIME
  49267. ExpectIntEQ(tm.tm_wday, 2);
  49268. ExpectIntEQ(tm.tm_yday, 52);
  49269. #endif
  49270. ExpectIntEQ(ASN1_TIME_set_string(&asnTime, "500222211515Z"), 1);
  49271. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 1);
  49272. ExpectIntEQ(tm.tm_year, 50);
  49273. /* Get current time. */
  49274. ExpectIntEQ(ASN1_TIME_to_tm(NULL, NULL), 0);
  49275. ExpectIntEQ(ASN1_TIME_to_tm(NULL, &tm), 1);
  49276. XMEMSET(&asnTime, 0, sizeof(ASN1_TIME));
  49277. /* 0 length. */
  49278. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  49279. /* No type. */
  49280. asnTime.length = 1;
  49281. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  49282. /* Not UTCTIME length. */
  49283. asnTime.type = V_ASN1_UTCTIME;
  49284. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  49285. /* Not GENERALIZEDTIME length. */
  49286. asnTime.type = V_ASN1_GENERALIZEDTIME;
  49287. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  49288. /* Not Zulu timezone. */
  49289. ExpectIntEQ(ASN1_TIME_set_string(&asnTime, "000222211515U"), 1);
  49290. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  49291. ExpectIntEQ(ASN1_TIME_set_string(&asnTime, "20000222211515U"), 1);
  49292. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  49293. #ifdef XMKTIME
  49294. ExpectNotNull(ASN1_TIME_adj(&asnTime, testTime, 0, 0));
  49295. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 1);
  49296. ExpectIntEQ(tm.tm_sec, 47);
  49297. ExpectIntEQ(tm.tm_min, 22);
  49298. ExpectIntEQ(tm.tm_hour, 21);
  49299. ExpectIntEQ(tm.tm_mday, 12);
  49300. ExpectIntEQ(tm.tm_mon, 4);
  49301. ExpectIntEQ(tm.tm_year, 123);
  49302. ExpectIntEQ(tm.tm_wday, 5);
  49303. ExpectIntEQ(tm.tm_yday, 131);
  49304. /* Confirm that when used with a tm struct from ASN1_TIME_adj, all other
  49305. fields are zeroed out as expected. */
  49306. ExpectIntEQ(tm.tm_isdst, 0);
  49307. #endif
  49308. #endif
  49309. return EXPECT_RESULT();
  49310. }
  49311. static int test_wolfSSL_ASN1_TIME_to_generalizedtime(void)
  49312. {
  49313. EXPECT_DECLS;
  49314. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  49315. WOLFSSL_ASN1_TIME *t = NULL;
  49316. WOLFSSL_ASN1_TIME *out = NULL;
  49317. WOLFSSL_ASN1_TIME *gtime = NULL;
  49318. int tlen = 0;
  49319. unsigned char *data = NULL;
  49320. ExpectNotNull(t = wolfSSL_ASN1_TIME_new());
  49321. ExpectNull(wolfSSL_ASN1_TIME_to_generalizedtime(NULL, &out));
  49322. /* type not set. */
  49323. ExpectNull(wolfSSL_ASN1_TIME_to_generalizedtime(t, &out));
  49324. XFREE(t, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49325. t = NULL;
  49326. /* UTC Time test */
  49327. ExpectNotNull(t = wolfSSL_ASN1_TIME_new());
  49328. if (t != NULL) {
  49329. XMEMSET(t->data, 0, ASN_GENERALIZED_TIME_SIZE);
  49330. t->type = ASN_UTC_TIME;
  49331. t->length = ASN_UTC_TIME_SIZE;
  49332. XMEMCPY(t->data, "050727123456Z", ASN_UTC_TIME_SIZE);
  49333. }
  49334. ExpectIntEQ(tlen = wolfSSL_ASN1_TIME_get_length(t), ASN_UTC_TIME_SIZE);
  49335. ExpectStrEQ((char*)(data = wolfSSL_ASN1_TIME_get_data(t)), "050727123456Z");
  49336. out = NULL;
  49337. ExpectNotNull(gtime = wolfSSL_ASN1_TIME_to_generalizedtime(t, &out));
  49338. wolfSSL_ASN1_TIME_free(gtime);
  49339. gtime = NULL;
  49340. ExpectNotNull(out = wolfSSL_ASN1_TIME_new());
  49341. ExpectNotNull(gtime = wolfSSL_ASN1_TIME_to_generalizedtime(t, &out));
  49342. ExpectPtrEq(gtime, out);
  49343. ExpectIntEQ(gtime->type, ASN_GENERALIZED_TIME);
  49344. ExpectIntEQ(gtime->length, ASN_GENERALIZED_TIME_SIZE);
  49345. ExpectStrEQ((char*)gtime->data, "20050727123456Z");
  49346. /* Generalized Time test */
  49347. ExpectNotNull(XMEMSET(t, 0, ASN_GENERALIZED_TIME_SIZE));
  49348. ExpectNotNull(XMEMSET(out, 0, ASN_GENERALIZED_TIME_SIZE));
  49349. ExpectNotNull(XMEMSET(data, 0, ASN_GENERALIZED_TIME_SIZE));
  49350. if (t != NULL) {
  49351. t->type = ASN_GENERALIZED_TIME;
  49352. t->length = ASN_GENERALIZED_TIME_SIZE;
  49353. XMEMCPY(t->data, "20050727123456Z", ASN_GENERALIZED_TIME_SIZE);
  49354. }
  49355. ExpectIntEQ(tlen = wolfSSL_ASN1_TIME_get_length(t),
  49356. ASN_GENERALIZED_TIME_SIZE);
  49357. ExpectStrEQ((char*)(data = wolfSSL_ASN1_TIME_get_data(t)),
  49358. "20050727123456Z");
  49359. ExpectNotNull(gtime = wolfSSL_ASN1_TIME_to_generalizedtime(t, &out));
  49360. ExpectIntEQ(gtime->type, ASN_GENERALIZED_TIME);
  49361. ExpectIntEQ(gtime->length, ASN_GENERALIZED_TIME_SIZE);
  49362. ExpectStrEQ((char*)gtime->data, "20050727123456Z");
  49363. /* UTC Time to Generalized Time 1900's test */
  49364. ExpectNotNull(XMEMSET(t, 0, ASN_GENERALIZED_TIME_SIZE));
  49365. ExpectNotNull(XMEMSET(out, 0, ASN_GENERALIZED_TIME_SIZE));
  49366. ExpectNotNull(XMEMSET(data, 0, ASN_GENERALIZED_TIME_SIZE));
  49367. if (t != NULL) {
  49368. t->type = ASN_UTC_TIME;
  49369. t->length = ASN_UTC_TIME_SIZE;
  49370. XMEMCPY(t->data, "500727123456Z", ASN_UTC_TIME_SIZE);
  49371. }
  49372. ExpectNotNull(gtime = wolfSSL_ASN1_TIME_to_generalizedtime(t, &out));
  49373. ExpectIntEQ(gtime->type, ASN_GENERALIZED_TIME);
  49374. ExpectIntEQ(gtime->length, ASN_GENERALIZED_TIME_SIZE);
  49375. ExpectStrEQ((char*)gtime->data, "19500727123456Z");
  49376. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49377. /* Null parameter test */
  49378. ExpectNotNull(XMEMSET(t, 0, ASN_GENERALIZED_TIME_SIZE));
  49379. gtime = NULL;
  49380. out = NULL;
  49381. if (t != NULL) {
  49382. t->type = ASN_UTC_TIME;
  49383. t->length = ASN_UTC_TIME_SIZE;
  49384. XMEMCPY(t->data, "050727123456Z", ASN_UTC_TIME_SIZE);
  49385. }
  49386. ExpectNotNull(gtime = wolfSSL_ASN1_TIME_to_generalizedtime(t, NULL));
  49387. ExpectIntEQ(gtime->type, ASN_GENERALIZED_TIME);
  49388. ExpectIntEQ(gtime->length, ASN_GENERALIZED_TIME_SIZE);
  49389. ExpectStrEQ((char*)gtime->data, "20050727123456Z");
  49390. XFREE(gtime, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49391. XFREE(t, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49392. #endif
  49393. return EXPECT_RESULT();
  49394. }
  49395. static int test_wolfSSL_ASN1_TIME_print(void)
  49396. {
  49397. EXPECT_DECLS;
  49398. #if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(NO_BIO) && \
  49399. (defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(WOLFSSL_NGINX) || \
  49400. defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA) || \
  49401. defined(OPENSSL_ALL)) && defined(USE_CERT_BUFFERS_2048) && \
  49402. !defined(NO_ASN_TIME)
  49403. BIO* bio = NULL;
  49404. BIO* fixed = NULL;
  49405. X509* x509 = NULL;
  49406. const unsigned char* der = client_cert_der_2048;
  49407. ASN1_TIME* notAfter = NULL;
  49408. ASN1_TIME* notBefore = NULL;
  49409. unsigned char buf[25];
  49410. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  49411. ExpectNotNull(fixed = BIO_new(wolfSSL_BIO_s_fixed_mem()));
  49412. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(der,
  49413. sizeof_client_cert_der_2048, WOLFSSL_FILETYPE_ASN1));
  49414. ExpectNotNull(notBefore = X509_get_notBefore(x509));
  49415. ExpectIntEQ(ASN1_TIME_print(NULL, NULL), 0);
  49416. ExpectIntEQ(ASN1_TIME_print(bio, NULL), 0);
  49417. ExpectIntEQ(ASN1_TIME_print(NULL, notBefore), 0);
  49418. ExpectIntEQ(ASN1_TIME_print(bio, notBefore), 1);
  49419. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 24);
  49420. ExpectIntEQ(XMEMCMP(buf, "Dec 13 22:19:28 2023 GMT", sizeof(buf) - 1), 0);
  49421. /* Test BIO_write fails. */
  49422. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  49423. /* Ensure there is 0 bytes available to write into. */
  49424. ExpectIntEQ(BIO_write(fixed, buf, 1), 1);
  49425. ExpectIntEQ(ASN1_TIME_print(fixed, notBefore), 0);
  49426. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  49427. ExpectIntEQ(ASN1_TIME_print(fixed, notBefore), 0);
  49428. ExpectIntEQ(BIO_set_write_buf_size(fixed, 23), 1);
  49429. ExpectIntEQ(ASN1_TIME_print(fixed, notBefore), 0);
  49430. /* create a bad time and test results */
  49431. ExpectNotNull(notAfter = X509_get_notAfter(x509));
  49432. ExpectIntEQ(ASN1_TIME_check(notAfter), 1);
  49433. if (EXPECT_SUCCESS()) {
  49434. notAfter->data[8] = 0;
  49435. notAfter->data[3] = 0;
  49436. }
  49437. ExpectIntNE(ASN1_TIME_print(bio, notAfter), 1);
  49438. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 14);
  49439. ExpectIntEQ(XMEMCMP(buf, "Bad time value", 14), 0);
  49440. ExpectIntEQ(ASN1_TIME_check(notAfter), 0);
  49441. BIO_free(bio);
  49442. BIO_free(fixed);
  49443. X509_free(x509);
  49444. #endif
  49445. return EXPECT_RESULT();
  49446. }
  49447. static int test_wolfSSL_ASN1_UTCTIME_print(void)
  49448. {
  49449. EXPECT_DECLS;
  49450. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME) && !defined(NO_BIO)
  49451. BIO* bio = NULL;
  49452. ASN1_UTCTIME* utc = NULL;
  49453. unsigned char buf[25];
  49454. const char* validDate = "190424111501Z"; /* UTC = YYMMDDHHMMSSZ */
  49455. const char* invalidDate = "190424111501X"; /* UTC = YYMMDDHHMMSSZ */
  49456. const char* genDate = "20190424111501Z"; /* GEN = YYYYMMDDHHMMSSZ */
  49457. /* Valid date */
  49458. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  49459. ExpectNotNull(utc = (ASN1_UTCTIME*)XMALLOC(sizeof(ASN1_UTCTIME), NULL,
  49460. DYNAMIC_TYPE_ASN1));
  49461. if (utc != NULL) {
  49462. utc->type = ASN_UTC_TIME;
  49463. utc->length = ASN_UTC_TIME_SIZE;
  49464. XMEMCPY(utc->data, (byte*)validDate, ASN_UTC_TIME_SIZE);
  49465. }
  49466. ExpectIntEQ(ASN1_UTCTIME_print(NULL, NULL), 0);
  49467. ExpectIntEQ(ASN1_UTCTIME_print(bio, NULL), 0);
  49468. ExpectIntEQ(ASN1_UTCTIME_print(NULL, utc), 0);
  49469. ExpectIntEQ(ASN1_UTCTIME_print(bio, utc), 1);
  49470. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 24);
  49471. ExpectIntEQ(XMEMCMP(buf, "Apr 24 11:15:01 2019 GMT", sizeof(buf)-1), 0);
  49472. XMEMSET(buf, 0, sizeof(buf));
  49473. BIO_free(bio);
  49474. bio = NULL;
  49475. /* Invalid format */
  49476. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  49477. if (utc != NULL) {
  49478. utc->type = ASN_UTC_TIME;
  49479. utc->length = ASN_UTC_TIME_SIZE;
  49480. XMEMCPY(utc->data, (byte*)invalidDate, ASN_UTC_TIME_SIZE);
  49481. }
  49482. ExpectIntEQ(ASN1_UTCTIME_print(bio, utc), 0);
  49483. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 14);
  49484. ExpectIntEQ(XMEMCMP(buf, "Bad time value", 14), 0);
  49485. /* Invalid type */
  49486. if (utc != NULL) {
  49487. utc->type = ASN_GENERALIZED_TIME;
  49488. utc->length = ASN_GENERALIZED_TIME_SIZE;
  49489. XMEMCPY(utc->data, (byte*)genDate, ASN_GENERALIZED_TIME_SIZE);
  49490. }
  49491. ExpectIntEQ(ASN1_UTCTIME_print(bio, utc), 0);
  49492. XFREE(utc, NULL, DYNAMIC_TYPE_ASN1);
  49493. BIO_free(bio);
  49494. #endif /* OPENSSL_EXTRA && !NO_ASN_TIME && !NO_BIO */
  49495. return EXPECT_RESULT();
  49496. }
  49497. static int test_wolfSSL_ASN1_TYPE(void)
  49498. {
  49499. EXPECT_DECLS;
  49500. #if defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD) || \
  49501. defined(WOLFSSL_HAPROXY) || defined(WOLFSSL_WPAS)
  49502. WOLFSSL_ASN1_TYPE* t = NULL;
  49503. WOLFSSL_ASN1_OBJECT* obj = NULL;
  49504. #ifndef NO_ASN_TIME
  49505. WOLFSSL_ASN1_TIME* time = NULL;
  49506. #endif
  49507. WOLFSSL_ASN1_STRING* str = NULL;
  49508. unsigned char data[] = { 0x00 };
  49509. ASN1_TYPE_set(NULL, V_ASN1_NULL, NULL);
  49510. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49511. ASN1_TYPE_set(t, V_ASN1_EOC, NULL);
  49512. wolfSSL_ASN1_TYPE_free(t);
  49513. t = NULL;
  49514. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49515. ASN1_TYPE_set(t, V_ASN1_NULL, NULL);
  49516. ASN1_TYPE_set(t, V_ASN1_NULL, data);
  49517. wolfSSL_ASN1_TYPE_free(t);
  49518. t = NULL;
  49519. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49520. ExpectNotNull(obj = wolfSSL_ASN1_OBJECT_new());
  49521. ASN1_TYPE_set(t, V_ASN1_OBJECT, obj);
  49522. wolfSSL_ASN1_TYPE_free(t);
  49523. t = NULL;
  49524. #ifndef NO_ASN_TIME
  49525. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49526. ExpectNotNull(time = wolfSSL_ASN1_TIME_new());
  49527. ASN1_TYPE_set(t, V_ASN1_UTCTIME, time);
  49528. wolfSSL_ASN1_TYPE_free(t);
  49529. t = NULL;
  49530. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49531. ExpectNotNull(time = wolfSSL_ASN1_TIME_new());
  49532. ASN1_TYPE_set(t, V_ASN1_GENERALIZEDTIME, time);
  49533. wolfSSL_ASN1_TYPE_free(t);
  49534. t = NULL;
  49535. #endif
  49536. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49537. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  49538. ASN1_TYPE_set(t, V_ASN1_UTF8STRING, str);
  49539. wolfSSL_ASN1_TYPE_free(t);
  49540. t = NULL;
  49541. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49542. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  49543. ASN1_TYPE_set(t, V_ASN1_PRINTABLESTRING, str);
  49544. wolfSSL_ASN1_TYPE_free(t);
  49545. t = NULL;
  49546. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49547. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  49548. ASN1_TYPE_set(t, V_ASN1_T61STRING, str);
  49549. wolfSSL_ASN1_TYPE_free(t);
  49550. t = NULL;
  49551. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49552. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  49553. ASN1_TYPE_set(t, V_ASN1_IA5STRING, str);
  49554. wolfSSL_ASN1_TYPE_free(t);
  49555. t = NULL;
  49556. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49557. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  49558. ASN1_TYPE_set(t, V_ASN1_UNIVERSALSTRING, str);
  49559. wolfSSL_ASN1_TYPE_free(t);
  49560. t = NULL;
  49561. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  49562. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  49563. ASN1_TYPE_set(t, V_ASN1_SEQUENCE, str);
  49564. wolfSSL_ASN1_TYPE_free(t);
  49565. t = NULL;
  49566. #endif
  49567. return EXPECT_RESULT();
  49568. }
  49569. /* Testing code used in old dpp.c in hostap */
  49570. #if defined(OPENSSL_ALL) && defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  49571. typedef struct {
  49572. /* AlgorithmIdentifier ecPublicKey with optional parameters present
  49573. * as an OID identifying the curve */
  49574. X509_ALGOR *alg;
  49575. /* Compressed format public key per ANSI X9.63 */
  49576. ASN1_BIT_STRING *pub_key;
  49577. } DPP_BOOTSTRAPPING_KEY;
  49578. ASN1_SEQUENCE(DPP_BOOTSTRAPPING_KEY) = {
  49579. ASN1_SIMPLE(DPP_BOOTSTRAPPING_KEY, alg, X509_ALGOR),
  49580. ASN1_SIMPLE(DPP_BOOTSTRAPPING_KEY, pub_key, ASN1_BIT_STRING)
  49581. } ASN1_SEQUENCE_END(DPP_BOOTSTRAPPING_KEY)
  49582. IMPLEMENT_ASN1_FUNCTIONS(DPP_BOOTSTRAPPING_KEY)
  49583. typedef struct {
  49584. int type;
  49585. union {
  49586. ASN1_BIT_STRING *str1;
  49587. ASN1_BIT_STRING *str2;
  49588. ASN1_BIT_STRING *str3;
  49589. } d;
  49590. } ASN1_CHOICE_TEST;
  49591. ASN1_CHOICE(ASN1_CHOICE_TEST) = {
  49592. ASN1_IMP(ASN1_CHOICE_TEST, d.str1, ASN1_BIT_STRING, 1),
  49593. ASN1_IMP(ASN1_CHOICE_TEST, d.str2, ASN1_BIT_STRING, 2),
  49594. ASN1_IMP(ASN1_CHOICE_TEST, d.str3, ASN1_BIT_STRING, 3)
  49595. } ASN1_CHOICE_END(ASN1_CHOICE_TEST)
  49596. IMPLEMENT_ASN1_FUNCTIONS(ASN1_CHOICE_TEST)
  49597. /* Test nested objects */
  49598. typedef struct {
  49599. DPP_BOOTSTRAPPING_KEY* key;
  49600. ASN1_INTEGER* asnNum;
  49601. ASN1_INTEGER* expNum;
  49602. STACK_OF(ASN1_GENERALSTRING) *strList;
  49603. ASN1_CHOICE_TEST* str;
  49604. } TEST_ASN1_NEST1;
  49605. ASN1_SEQUENCE(TEST_ASN1_NEST1) = {
  49606. ASN1_SIMPLE(TEST_ASN1_NEST1, key, DPP_BOOTSTRAPPING_KEY),
  49607. ASN1_SIMPLE(TEST_ASN1_NEST1, asnNum, ASN1_INTEGER),
  49608. ASN1_EXP(TEST_ASN1_NEST1, expNum, ASN1_INTEGER, 0),
  49609. ASN1_EXP_SEQUENCE_OF(TEST_ASN1_NEST1, strList, ASN1_GENERALSTRING, 1),
  49610. ASN1_SIMPLE(TEST_ASN1_NEST1, str, ASN1_CHOICE_TEST)
  49611. } ASN1_SEQUENCE_END(TEST_ASN1_NEST1)
  49612. IMPLEMENT_ASN1_FUNCTIONS(TEST_ASN1_NEST1)
  49613. typedef struct {
  49614. ASN1_INTEGER* num;
  49615. DPP_BOOTSTRAPPING_KEY* key;
  49616. TEST_ASN1_NEST1* asn1_obj;
  49617. } TEST_ASN1_NEST2;
  49618. ASN1_SEQUENCE(TEST_ASN1_NEST2) = {
  49619. ASN1_SIMPLE(TEST_ASN1_NEST2, num, ASN1_INTEGER),
  49620. ASN1_SIMPLE(TEST_ASN1_NEST2, key, DPP_BOOTSTRAPPING_KEY),
  49621. ASN1_SIMPLE(TEST_ASN1_NEST2, asn1_obj, TEST_ASN1_NEST1)
  49622. } ASN1_SEQUENCE_END(TEST_ASN1_NEST2)
  49623. IMPLEMENT_ASN1_FUNCTIONS(TEST_ASN1_NEST2)
  49624. /* End nested objects */
  49625. typedef struct {
  49626. ASN1_INTEGER *integer;
  49627. } TEST_ASN1;
  49628. ASN1_SEQUENCE(TEST_ASN1) = {
  49629. ASN1_SIMPLE(TEST_ASN1, integer, ASN1_INTEGER),
  49630. } ASN1_SEQUENCE_END(TEST_ASN1)
  49631. IMPLEMENT_ASN1_FUNCTIONS(TEST_ASN1)
  49632. typedef STACK_OF(ASN1_INTEGER) TEST_ASN1_ITEM;
  49633. ASN1_ITEM_TEMPLATE(TEST_ASN1_ITEM) =
  49634. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, MemName, ASN1_INTEGER)
  49635. ASN1_ITEM_TEMPLATE_END(TEST_ASN1_ITEM)
  49636. IMPLEMENT_ASN1_FUNCTIONS(TEST_ASN1_ITEM)
  49637. #endif
  49638. static int test_wolfSSL_IMPLEMENT_ASN1_FUNCTIONS(void)
  49639. {
  49640. EXPECT_DECLS;
  49641. /* Testing code used in dpp.c in hostap */
  49642. #if defined(OPENSSL_ALL) && defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  49643. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  49644. EC_KEY *eckey = NULL;
  49645. EVP_PKEY *key = NULL;
  49646. size_t len = 0;
  49647. unsigned char *der = NULL;
  49648. unsigned char *der2 = NULL;
  49649. const unsigned char *tmp = NULL;
  49650. DPP_BOOTSTRAPPING_KEY *bootstrap = NULL, *bootstrap2 = NULL;
  49651. const unsigned char *in = ecc_clikey_der_256;
  49652. WOLFSSL_ASN1_OBJECT* ec_obj = NULL;
  49653. WOLFSSL_ASN1_OBJECT* group_obj = NULL;
  49654. const EC_GROUP *group = NULL;
  49655. const EC_POINT *point = NULL;
  49656. int nid;
  49657. TEST_ASN1 *test_asn1 = NULL;
  49658. TEST_ASN1 *test_asn1_2 = NULL;
  49659. const unsigned char badObjDer[] = { 0x06, 0x00 };
  49660. const unsigned char goodObjDer[] = {
  49661. 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01
  49662. };
  49663. WOLFSSL_ASN1_ITEM emptyTemplate;
  49664. XMEMSET(&emptyTemplate, 0, sizeof(WOLFSSL_ASN1_ITEM));
  49665. ExpectNotNull(bootstrap = DPP_BOOTSTRAPPING_KEY_new());
  49666. der = NULL;
  49667. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(NULL, &der), -1);
  49668. ExpectIntEQ(wolfSSL_ASN1_item_i2d(bootstrap, &der, NULL), -1);
  49669. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap, &der), -1);
  49670. ExpectNotNull(key = d2i_PrivateKey(EVP_PKEY_EC, NULL, &in,
  49671. (long)sizeof_ecc_clikey_der_256));
  49672. ExpectNotNull(eckey = EVP_PKEY_get1_EC_KEY(key));
  49673. ExpectNotNull(group = EC_KEY_get0_group(eckey));
  49674. ExpectNotNull(point = EC_KEY_get0_public_key(eckey));
  49675. nid = EC_GROUP_get_curve_name(group);
  49676. ec_obj = OBJ_nid2obj(EVP_PKEY_EC);
  49677. group_obj = OBJ_nid2obj(nid);
  49678. if ((ec_obj != NULL) && (group_obj != NULL)) {
  49679. ExpectIntEQ(X509_ALGOR_set0(bootstrap->alg, ec_obj, V_ASN1_OBJECT,
  49680. group_obj), 1);
  49681. if (EXPECT_SUCCESS()) {
  49682. ec_obj = NULL;
  49683. group_obj = NULL;
  49684. }
  49685. }
  49686. wolfSSL_ASN1_OBJECT_free(group_obj);
  49687. wolfSSL_ASN1_OBJECT_free(ec_obj);
  49688. ExpectIntEQ(EC_POINT_point2oct(group, point, 0, NULL, 0, NULL), 0);
  49689. #ifdef HAVE_COMP_KEY
  49690. ExpectIntGT((len = EC_POINT_point2oct(
  49691. group, point, POINT_CONVERSION_COMPRESSED,
  49692. NULL, 0, NULL)), 0);
  49693. #else
  49694. ExpectIntGT((len = EC_POINT_point2oct(
  49695. group, point, POINT_CONVERSION_UNCOMPRESSED,
  49696. NULL, 0, NULL)), 0);
  49697. #endif
  49698. ExpectNotNull(der = (unsigned char*)XMALLOC(len, NULL, DYNAMIC_TYPE_ASN1));
  49699. #ifdef HAVE_COMP_KEY
  49700. ExpectIntEQ(EC_POINT_point2oct(group, point, POINT_CONVERSION_COMPRESSED,
  49701. der, len-1, NULL), 0);
  49702. ExpectIntEQ(EC_POINT_point2oct(group, point, POINT_CONVERSION_COMPRESSED,
  49703. der, len, NULL), len);
  49704. #else
  49705. ExpectIntEQ(EC_POINT_point2oct(group, point, POINT_CONVERSION_UNCOMPRESSED,
  49706. der, len-1, NULL), 0);
  49707. ExpectIntEQ(EC_POINT_point2oct(group, point, POINT_CONVERSION_UNCOMPRESSED,
  49708. der, len, NULL), len);
  49709. #endif
  49710. if (EXPECT_SUCCESS()) {
  49711. bootstrap->pub_key->data = der;
  49712. bootstrap->pub_key->length = (int)len;
  49713. /* Not actually used */
  49714. bootstrap->pub_key->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07);
  49715. bootstrap->pub_key->flags |= ASN1_STRING_FLAG_BITS_LEFT;
  49716. }
  49717. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap, NULL), 16+len);
  49718. der = NULL;
  49719. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap, &der), 16+len);
  49720. der2 = NULL;
  49721. #ifdef WOLFSSL_ASN_TEMPLATE
  49722. tmp = der;
  49723. ExpectNotNull(d2i_DPP_BOOTSTRAPPING_KEY(&bootstrap2, &tmp, 16+len));
  49724. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap2, &der2), 16+len);
  49725. ExpectBufEQ(der, der2, 49);
  49726. #endif
  49727. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49728. XFREE(der2, NULL, DYNAMIC_TYPE_ASN1);
  49729. EVP_PKEY_free(key);
  49730. EC_KEY_free(eckey);
  49731. DPP_BOOTSTRAPPING_KEY_free(bootstrap);
  49732. DPP_BOOTSTRAPPING_KEY_free(bootstrap2);
  49733. bootstrap = NULL;
  49734. DPP_BOOTSTRAPPING_KEY_free(NULL);
  49735. /* Create bootstrap key with bad OBJECT_ID DER data, parameter that is
  49736. * a NULL and an empty BIT_STRING. */
  49737. ExpectNotNull(bootstrap = DPP_BOOTSTRAPPING_KEY_new());
  49738. ExpectNotNull(bootstrap->alg->algorithm = wolfSSL_ASN1_OBJECT_new());
  49739. if (EXPECT_SUCCESS()) {
  49740. bootstrap->alg->algorithm->obj = badObjDer;
  49741. bootstrap->alg->algorithm->objSz = (unsigned int)sizeof(badObjDer);
  49742. }
  49743. ExpectNotNull(bootstrap->alg->parameter = wolfSSL_ASN1_TYPE_new());
  49744. if (EXPECT_SUCCESS()) {
  49745. bootstrap->alg->parameter->type = V_ASN1_NULL;
  49746. bootstrap->alg->parameter->value.ptr = NULL;
  49747. bootstrap->pub_key->data = NULL;
  49748. bootstrap->pub_key->length = 0;
  49749. /* Not actually used */
  49750. bootstrap->pub_key->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07);
  49751. bootstrap->pub_key->flags |= ASN1_STRING_FLAG_BITS_LEFT;
  49752. }
  49753. /* Encode with bad OBJECT_ID. */
  49754. der = NULL;
  49755. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap, &der), -1);
  49756. /* Fix OBJECT_ID and encode with empty BIT_STRING. */
  49757. if (EXPECT_SUCCESS()) {
  49758. bootstrap->alg->algorithm->obj = goodObjDer;
  49759. bootstrap->alg->algorithm->objSz = (unsigned int)sizeof(goodObjDer);
  49760. bootstrap->alg->algorithm->grp = 2;
  49761. }
  49762. der = NULL;
  49763. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap, &der), 16);
  49764. ExpectIntEQ(wolfSSL_ASN1_item_i2d(bootstrap, &der, &emptyTemplate), -1);
  49765. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49766. DPP_BOOTSTRAPPING_KEY_free(bootstrap);
  49767. /* Test integer */
  49768. ExpectNotNull(test_asn1 = TEST_ASN1_new());
  49769. der = NULL;
  49770. ExpectIntEQ(ASN1_INTEGER_set(test_asn1->integer, 100), 1);
  49771. ExpectIntEQ(i2d_TEST_ASN1(test_asn1, &der), 5);
  49772. tmp = der;
  49773. ExpectNotNull(d2i_TEST_ASN1(&test_asn1_2, &tmp, 5));
  49774. der2 = NULL;
  49775. ExpectIntEQ(i2d_TEST_ASN1(test_asn1_2, &der2), 5);
  49776. ExpectBufEQ(der, der2, 5);
  49777. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49778. XFREE(der2, NULL, DYNAMIC_TYPE_ASN1);
  49779. TEST_ASN1_free(test_asn1);
  49780. TEST_ASN1_free(test_asn1_2);
  49781. /* Test integer cases. */
  49782. ExpectNull(wolfSSL_ASN1_item_new(NULL));
  49783. TEST_ASN1_free(NULL);
  49784. /* Test nested asn1 objects */
  49785. {
  49786. TEST_ASN1_NEST2 *nested_asn1 = NULL;
  49787. TEST_ASN1_NEST2 *nested_asn1_2 = NULL;
  49788. int i;
  49789. ExpectNotNull(nested_asn1 = TEST_ASN1_NEST2_new());
  49790. /* Populate nested_asn1 with some random data */
  49791. /* nested_asn1->num */
  49792. ExpectIntEQ(ASN1_INTEGER_set(nested_asn1->num, 30003), 1);
  49793. /* nested_asn1->key */
  49794. ec_obj = OBJ_nid2obj(EVP_PKEY_EC);
  49795. group_obj = OBJ_nid2obj(NID_secp256k1);
  49796. ExpectIntEQ(X509_ALGOR_set0(nested_asn1->key->alg, ec_obj,
  49797. V_ASN1_OBJECT, group_obj), 1);
  49798. ec_obj = NULL;
  49799. group_obj = NULL;
  49800. ExpectIntEQ(ASN1_BIT_STRING_set_bit(nested_asn1->key->pub_key, 50, 1),
  49801. 1);
  49802. /* nested_asn1->asn1_obj->key */
  49803. ec_obj = OBJ_nid2obj(EVP_PKEY_EC);
  49804. group_obj = OBJ_nid2obj(NID_secp256k1);
  49805. ExpectIntEQ(X509_ALGOR_set0(nested_asn1->asn1_obj->key->alg, ec_obj,
  49806. V_ASN1_OBJECT, group_obj), 1);
  49807. ec_obj = NULL;
  49808. group_obj = NULL;
  49809. ExpectIntEQ(ASN1_BIT_STRING_set_bit(nested_asn1->asn1_obj->key->pub_key,
  49810. 500, 1), 1);
  49811. /* nested_asn1->asn1_obj->asnNum */
  49812. ExpectIntEQ(ASN1_INTEGER_set(nested_asn1->asn1_obj->asnNum, 666666), 1);
  49813. /* nested_asn1->asn1_obj->expNum */
  49814. ExpectIntEQ(ASN1_INTEGER_set(nested_asn1->asn1_obj->expNum, 22222), 1);
  49815. /* nested_asn1->asn1_obj->strList */
  49816. for (i = 10; i >= 0; i--) {
  49817. ASN1_GENERALSTRING* genStr;
  49818. char fmtStr[20];
  49819. ExpectIntGT(snprintf(fmtStr, sizeof(fmtStr), "Bonjour #%d", i), 0);
  49820. ExpectNotNull(genStr = ASN1_GENERALSTRING_new());
  49821. ExpectIntEQ(ASN1_GENERALSTRING_set(genStr, fmtStr, -1), 1);
  49822. ExpectIntGT(
  49823. sk_ASN1_GENERALSTRING_push(nested_asn1->asn1_obj->strList,
  49824. genStr), 0);
  49825. }
  49826. /* nested_asn1->asn1_obj->str */
  49827. ExpectNotNull(nested_asn1->asn1_obj->str->d.str2
  49828. = ASN1_BIT_STRING_new());
  49829. ExpectIntEQ(ASN1_BIT_STRING_set_bit(nested_asn1->asn1_obj->str->d.str2,
  49830. 150, 1), 1);
  49831. nested_asn1->asn1_obj->str->type = 2;
  49832. der = NULL;
  49833. ExpectIntEQ(i2d_TEST_ASN1_NEST2(nested_asn1, &der), 285);
  49834. #ifdef WOLFSSL_ASN_TEMPLATE
  49835. tmp = der;
  49836. ExpectNotNull(d2i_TEST_ASN1_NEST2(&nested_asn1_2, &tmp, 285));
  49837. der2 = NULL;
  49838. ExpectIntEQ(i2d_TEST_ASN1_NEST2(nested_asn1_2, &der2), 285);
  49839. ExpectBufEQ(der, der2, 285);
  49840. XFREE(der2, NULL, DYNAMIC_TYPE_ASN1);
  49841. #endif
  49842. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49843. TEST_ASN1_NEST2_free(nested_asn1);
  49844. TEST_ASN1_NEST2_free(nested_asn1_2);
  49845. }
  49846. /* Test ASN1_ITEM_TEMPLATE */
  49847. {
  49848. TEST_ASN1_ITEM* asn1_item = NULL;
  49849. TEST_ASN1_ITEM* asn1_item2 = NULL;
  49850. int i;
  49851. ExpectNotNull(asn1_item = TEST_ASN1_ITEM_new());
  49852. for (i = 0; i < 11; i++) {
  49853. ASN1_INTEGER* asn1_num;
  49854. ExpectNotNull(asn1_num = ASN1_INTEGER_new());
  49855. ExpectIntEQ(ASN1_INTEGER_set(asn1_num, i), 1);
  49856. ExpectIntGT(wolfSSL_sk_insert(asn1_item, asn1_num, -1), 0);
  49857. }
  49858. der = NULL;
  49859. ExpectIntEQ(i2d_TEST_ASN1_ITEM(asn1_item, &der), 35);
  49860. tmp = der;
  49861. ExpectNotNull(d2i_TEST_ASN1_ITEM(&asn1_item2, &tmp, 35));
  49862. der2 = NULL;
  49863. ExpectIntEQ(i2d_TEST_ASN1_ITEM(asn1_item2, &der2), 35);
  49864. ExpectBufEQ(der, der2, 35);
  49865. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49866. XFREE(der2, NULL, DYNAMIC_TYPE_ASN1);
  49867. TEST_ASN1_ITEM_free(asn1_item);
  49868. TEST_ASN1_ITEM_free(asn1_item2);
  49869. }
  49870. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  49871. #endif /* OPENSSL_ALL && HAVE_ECC && USE_CERT_BUFFERS_256 */
  49872. return EXPECT_RESULT();
  49873. }
  49874. static int test_wolfSSL_i2d_ASN1_TYPE(void)
  49875. {
  49876. EXPECT_DECLS;
  49877. #if defined(OPENSSL_EXTRA)
  49878. /* Taken from one of sssd's certs othernames */
  49879. unsigned char str_bin[] = {
  49880. 0x04, 0x10, 0xa4, 0x9b, 0xc8, 0xf4, 0x85, 0x8e, 0x89, 0x4d, 0x85, 0x8d,
  49881. 0x27, 0xbd, 0x63, 0xaa, 0x93, 0x93
  49882. };
  49883. ASN1_TYPE* asn1type = NULL;
  49884. unsigned char* der = NULL;
  49885. /* Create ASN1_TYPE manually as we don't have a d2i version yet */
  49886. {
  49887. ASN1_STRING* str = NULL;
  49888. ExpectNotNull(str = ASN1_STRING_type_new(V_ASN1_SEQUENCE));
  49889. ExpectIntEQ(ASN1_STRING_set(str, str_bin, sizeof(str_bin)), 1);
  49890. ExpectNotNull(asn1type = ASN1_TYPE_new());
  49891. ASN1_TYPE_set(asn1type, V_ASN1_SEQUENCE, str);
  49892. }
  49893. ExpectIntEQ(i2d_ASN1_TYPE(asn1type, NULL), sizeof(str_bin));
  49894. ExpectIntEQ(i2d_ASN1_TYPE(asn1type, &der), sizeof(str_bin));
  49895. ExpectBufEQ(der, str_bin, sizeof(str_bin));
  49896. ASN1_TYPE_free(asn1type);
  49897. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49898. #endif
  49899. return EXPECT_RESULT();
  49900. }
  49901. static int test_wolfSSL_i2d_ASN1_SEQUENCE(void)
  49902. {
  49903. EXPECT_DECLS;
  49904. #if defined(OPENSSL_EXTRA)
  49905. /* Taken from one of sssd's certs othernames */
  49906. unsigned char str_bin[] = {
  49907. 0x04, 0x10, 0xa4, 0x9b, 0xc8, 0xf4, 0x85, 0x8e, 0x89, 0x4d, 0x85, 0x8d,
  49908. 0x27, 0xbd, 0x63, 0xaa, 0x93, 0x93
  49909. };
  49910. ASN1_STRING* str = NULL;
  49911. unsigned char* der = NULL;
  49912. ExpectNotNull(str = ASN1_STRING_type_new(V_ASN1_SEQUENCE));
  49913. ExpectIntEQ(ASN1_STRING_set(str, str_bin, sizeof(str_bin)), 1);
  49914. ExpectIntEQ(i2d_ASN1_SEQUENCE(str, NULL), sizeof(str_bin));
  49915. ExpectIntEQ(i2d_ASN1_SEQUENCE(str, &der), sizeof(str_bin));
  49916. ASN1_STRING_free(str);
  49917. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49918. #endif
  49919. return EXPECT_RESULT();
  49920. }
  49921. static int test_ASN1_strings(void)
  49922. {
  49923. EXPECT_DECLS;
  49924. #if defined(OPENSSL_EXTRA)
  49925. char text[] = "\0\0test string";
  49926. unsigned char* der = NULL;
  49927. ASN1_STRING* str = NULL;
  49928. /* Set the length byte */
  49929. text[1] = XSTRLEN(text + 2);
  49930. /* GENERALSTRING */
  49931. {
  49932. const unsigned char* p = (const unsigned char*)text;
  49933. text[0] = ASN_GENERALSTRING;
  49934. ExpectNotNull(d2i_ASN1_GENERALSTRING(&str, &p, sizeof(text)));
  49935. ExpectIntEQ(i2d_ASN1_GENERALSTRING(str, &der), 13);
  49936. ASN1_STRING_free(str);
  49937. str = NULL;
  49938. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49939. der = NULL;
  49940. }
  49941. /* OCTET_STRING */
  49942. {
  49943. const unsigned char* p = (const unsigned char*)text;
  49944. text[0] = ASN_OCTET_STRING;
  49945. ExpectNotNull(d2i_ASN1_OCTET_STRING(&str, &p, sizeof(text)));
  49946. ExpectIntEQ(i2d_ASN1_OCTET_STRING(str, &der), 13);
  49947. ASN1_STRING_free(str);
  49948. str = NULL;
  49949. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49950. der = NULL;
  49951. }
  49952. /* UTF8STRING */
  49953. {
  49954. const unsigned char* p = (const unsigned char*)text;
  49955. text[0] = ASN_UTF8STRING;
  49956. ExpectNotNull(d2i_ASN1_UTF8STRING(&str, &p, sizeof(text)));
  49957. ExpectIntEQ(i2d_ASN1_UTF8STRING(str, &der), 13);
  49958. ASN1_STRING_free(str);
  49959. str = NULL;
  49960. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  49961. der = NULL;
  49962. }
  49963. #endif
  49964. return EXPECT_RESULT();
  49965. }
  49966. static int test_wolfSSL_lhash(void)
  49967. {
  49968. EXPECT_DECLS;
  49969. #ifdef OPENSSL_ALL
  49970. const char testStr[] = "Like a true nature's child\n"
  49971. "We were born\n"
  49972. "Born to be wild";
  49973. #ifdef NO_SHA
  49974. ExpectIntEQ(lh_strhash(testStr), 0xf9dc8a43);
  49975. #else
  49976. ExpectIntEQ(lh_strhash(testStr), 0x5b7541dc);
  49977. #endif
  49978. #endif
  49979. return EXPECT_RESULT();
  49980. }
  49981. static int test_wolfSSL_X509_NAME(void)
  49982. {
  49983. EXPECT_DECLS;
  49984. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)) && \
  49985. !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  49986. !defined(NO_RSA) && defined(WOLFSSL_CERT_GEN) && \
  49987. (defined(WOLFSSL_CERT_REQ) || defined(WOLFSSL_CERT_EXT) || \
  49988. defined(OPENSSL_EXTRA))
  49989. X509* x509 = NULL;
  49990. const unsigned char* c = NULL;
  49991. unsigned char buf[4096];
  49992. int bytes = 0;
  49993. XFILE f = XBADFILE;
  49994. const X509_NAME* a = NULL;
  49995. const X509_NAME* b = NULL;
  49996. X509_NAME* d2i_name = NULL;
  49997. int sz = 0;
  49998. unsigned char* tmp = NULL;
  49999. char file[] = "./certs/ca-cert.der";
  50000. #ifndef OPENSSL_EXTRA_X509_SMALL
  50001. byte empty[] = { /* CN=empty emailAddress= */
  50002. 0x30, 0x21, 0x31, 0x0E, 0x30, 0x0C, 0x06, 0x03,
  50003. 0x55, 0x04, 0x03, 0x0C, 0x05, 0x65, 0x6D, 0x70,
  50004. 0x74, 0x79, 0x31, 0x0F, 0x30, 0x0D, 0x06, 0x09,
  50005. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09,
  50006. 0x01, 0x16, 0x00
  50007. };
  50008. #endif
  50009. #ifndef OPENSSL_EXTRA_X509_SMALL
  50010. /* test compile of deprecated function, returns 0 */
  50011. ExpectIntEQ(CRYPTO_thread_id(), 0);
  50012. #endif
  50013. ExpectNotNull(a = X509_NAME_new());
  50014. X509_NAME_free((X509_NAME*)a);
  50015. a = NULL;
  50016. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  50017. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  50018. if (f != XBADFILE)
  50019. XFCLOSE(f);
  50020. c = buf;
  50021. ExpectNotNull(x509 = wolfSSL_X509_d2i_ex(NULL, c, bytes, HEAP_HINT));
  50022. /* test cmp function */
  50023. ExpectNotNull(a = X509_get_issuer_name(x509));
  50024. ExpectNotNull(b = X509_get_subject_name(x509));
  50025. #ifndef OPENSSL_EXTRA_X509_SMALL
  50026. ExpectIntEQ(X509_NAME_cmp(a, b), 0); /* self signed should be 0 */
  50027. #endif
  50028. tmp = buf;
  50029. ExpectIntGT((sz = i2d_X509_NAME((X509_NAME*)a, &tmp)), 0);
  50030. if (sz > 0 && tmp == buf) {
  50031. fprintf(stderr, "\nERROR - %s line %d failed with:", __FILE__,
  50032. __LINE__);
  50033. fprintf(stderr, " Expected pointer to be incremented\n");
  50034. abort();
  50035. }
  50036. #ifndef OPENSSL_EXTRA_X509_SMALL
  50037. tmp = buf;
  50038. ExpectNotNull(d2i_name = d2i_X509_NAME(NULL, &tmp, sz));
  50039. #endif
  50040. /* if output parameter is NULL, should still return required size. */
  50041. ExpectIntGT((sz = i2d_X509_NAME((X509_NAME*)b, NULL)), 0);
  50042. /* retry but with the function creating a buffer */
  50043. tmp = NULL;
  50044. ExpectIntGT((sz = i2d_X509_NAME((X509_NAME*)b, &tmp)), 0);
  50045. XFREE(tmp, NULL, DYNAMIC_TYPE_OPENSSL);
  50046. tmp = NULL;
  50047. #ifdef WOLFSSL_CERT_NAME_ALL
  50048. /* test for givenName and name */
  50049. {
  50050. WOLFSSL_X509_NAME_ENTRY* entry = NULL;
  50051. const byte gName[] = "test-given-name";
  50052. const byte name[] = "test-name";
  50053. ExpectNotNull(entry = wolfSSL_X509_NAME_ENTRY_create_by_NID(NULL,
  50054. NID_givenName, ASN_UTF8STRING, gName, sizeof(gName)));
  50055. ExpectIntEQ(wolfSSL_X509_NAME_add_entry((X509_NAME*)b, entry, -1, 0),
  50056. 1);
  50057. wolfSSL_X509_NAME_ENTRY_free(entry);
  50058. entry = NULL;
  50059. ExpectNotNull(entry = wolfSSL_X509_NAME_ENTRY_create_by_NID(NULL,
  50060. NID_name, ASN_UTF8STRING, name, sizeof(name)));
  50061. ExpectIntEQ(wolfSSL_X509_NAME_add_entry((X509_NAME*)b, entry, -1, 0),
  50062. 1);
  50063. wolfSSL_X509_NAME_ENTRY_free(entry);
  50064. tmp = NULL;
  50065. ExpectIntGT((sz = i2d_X509_NAME((X509_NAME*)b, &tmp)), 0);
  50066. XFREE(tmp, NULL, DYNAMIC_TYPE_OPENSSL);
  50067. }
  50068. #endif
  50069. b = NULL;
  50070. ExpectNotNull(b = X509_NAME_dup((X509_NAME*)a));
  50071. #ifndef OPENSSL_EXTRA_X509_SMALL
  50072. ExpectIntEQ(X509_NAME_cmp(a, b), 0);
  50073. #endif
  50074. X509_NAME_free((X509_NAME*)b);
  50075. X509_NAME_free(d2i_name);
  50076. d2i_name = NULL;
  50077. X509_free(x509);
  50078. #ifndef OPENSSL_EXTRA_X509_SMALL
  50079. /* test with an empty domain component */
  50080. tmp = empty;
  50081. sz = sizeof(empty);
  50082. ExpectNotNull(d2i_name = d2i_X509_NAME(NULL, &tmp, sz));
  50083. ExpectIntEQ(X509_NAME_entry_count(d2i_name), 2);
  50084. /* size of empty emailAddress will be 0 */
  50085. tmp = buf;
  50086. ExpectIntEQ(X509_NAME_get_text_by_NID(d2i_name, NID_emailAddress,
  50087. (char*)tmp, sizeof(buf)), 0);
  50088. /* should contain no organization name */
  50089. tmp = buf;
  50090. ExpectIntEQ(X509_NAME_get_text_by_NID(d2i_name, NID_organizationName,
  50091. (char*)tmp, sizeof(buf)), -1);
  50092. X509_NAME_free(d2i_name);
  50093. #endif
  50094. #endif
  50095. return EXPECT_RESULT();
  50096. }
  50097. static int test_wolfSSL_X509_NAME_hash(void)
  50098. {
  50099. EXPECT_DECLS;
  50100. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && \
  50101. !defined(NO_RSA) && !defined(NO_SHA) && !defined(NO_BIO)
  50102. BIO* bio = NULL;
  50103. X509* x509 = NULL;
  50104. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  50105. ExpectIntGT(BIO_read_filename(bio, svrCertFile), 0);
  50106. ExpectNotNull(PEM_read_bio_X509(bio, &x509, NULL, NULL));
  50107. ExpectIntEQ(X509_NAME_hash(X509_get_subject_name(x509)), 0x137DC03F);
  50108. ExpectIntEQ(X509_NAME_hash(X509_get_issuer_name(x509)), 0xFDB2DA4);
  50109. X509_free(x509);
  50110. BIO_free(bio);
  50111. #endif
  50112. return EXPECT_RESULT();
  50113. }
  50114. static int test_wolfSSL_X509_NAME_print_ex(void)
  50115. {
  50116. EXPECT_DECLS;
  50117. #if (defined(OPENSSL_ALL) || (defined(OPENSSL_EXTRA) && \
  50118. (defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || \
  50119. defined(HAVE_LIGHTY) || defined(WOLFSSL_HAPROXY) || \
  50120. defined(WOLFSSL_OPENSSH) || defined(HAVE_SBLIM_SFCB)))) && \
  50121. !defined(NO_BIO) && !defined(NO_RSA)
  50122. int memSz = 0;
  50123. byte* mem = NULL;
  50124. BIO* bio = NULL;
  50125. BIO* membio = NULL;
  50126. X509* x509 = NULL;
  50127. X509_NAME* name = NULL;
  50128. const char* expNormal = "C=US, CN=wolfssl.com";
  50129. const char* expEqSpace = "C = US, CN = wolfssl.com";
  50130. const char* expReverse = "CN=wolfssl.com, C=US";
  50131. const char* expNotEscaped = "C= US,+\"\\ , CN=#wolfssl.com<>;";
  50132. const char* expNotEscapedRev = "CN=#wolfssl.com<>;, C= US,+\"\\ ";
  50133. const char* expRFC5523 =
  50134. "CN=\\#wolfssl.com\\<\\>\\;, C=\\ US\\,\\+\\\"\\\\\\ ";
  50135. /* Test with real cert (svrCertFile) first */
  50136. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  50137. ExpectIntGT(BIO_read_filename(bio, svrCertFile), 0);
  50138. ExpectNotNull(PEM_read_bio_X509(bio, &x509, NULL, NULL));
  50139. ExpectNotNull(name = X509_get_subject_name(x509));
  50140. /* Test without flags */
  50141. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  50142. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0, 0), WOLFSSL_SUCCESS);
  50143. BIO_free(membio);
  50144. membio = NULL;
  50145. /* Test flag: XN_FLAG_RFC2253 */
  50146. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  50147. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  50148. XN_FLAG_RFC2253), WOLFSSL_SUCCESS);
  50149. BIO_free(membio);
  50150. membio = NULL;
  50151. /* Test flag: XN_FLAG_RFC2253 | XN_FLAG_DN_REV */
  50152. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  50153. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  50154. XN_FLAG_RFC2253 | XN_FLAG_DN_REV), WOLFSSL_SUCCESS);
  50155. BIO_free(membio);
  50156. membio = NULL;
  50157. X509_free(x509);
  50158. BIO_free(bio);
  50159. name = NULL;
  50160. /* Test normal case without escaped characters */
  50161. {
  50162. /* Create name: "/C=US/CN=wolfssl.com" */
  50163. ExpectNotNull(name = X509_NAME_new());
  50164. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName",
  50165. MBSTRING_UTF8, (byte*)"US", 2, -1, 0),
  50166. WOLFSSL_SUCCESS);
  50167. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName",
  50168. MBSTRING_UTF8, (byte*)"wolfssl.com", 11, -1, 0),
  50169. WOLFSSL_SUCCESS);
  50170. /* Test without flags */
  50171. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  50172. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0, 0), WOLFSSL_SUCCESS);
  50173. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  50174. ExpectIntEQ(memSz, XSTRLEN(expNormal));
  50175. ExpectIntEQ(XSTRNCMP((char*)mem, expNormal, XSTRLEN(expNormal)), 0);
  50176. BIO_free(membio);
  50177. membio = NULL;
  50178. /* Test with XN_FLAG_ONELINE which should enable XN_FLAG_SPC_EQ for
  50179. spaces aroun '=' */
  50180. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  50181. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0, XN_FLAG_ONELINE),
  50182. WOLFSSL_SUCCESS);
  50183. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  50184. ExpectIntEQ(memSz, XSTRLEN(expEqSpace));
  50185. ExpectIntEQ(XSTRNCMP((char*)mem, expEqSpace, XSTRLEN(expEqSpace)), 0);
  50186. BIO_free(membio);
  50187. membio = NULL;
  50188. /* Test flags: XN_FLAG_RFC2253 - should be reversed */
  50189. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  50190. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  50191. XN_FLAG_RFC2253), WOLFSSL_SUCCESS);
  50192. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  50193. ExpectIntEQ(memSz, XSTRLEN(expReverse));
  50194. BIO_free(membio);
  50195. membio = NULL;
  50196. /* Test flags: XN_FLAG_DN_REV - reversed */
  50197. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  50198. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  50199. XN_FLAG_DN_REV), WOLFSSL_SUCCESS);
  50200. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  50201. ExpectIntEQ(memSz, XSTRLEN(expReverse));
  50202. ExpectIntEQ(XSTRNCMP((char*)mem, expReverse, XSTRLEN(expReverse)), 0);
  50203. BIO_free(membio);
  50204. membio = NULL;
  50205. X509_NAME_free(name);
  50206. name = NULL;
  50207. }
  50208. /* Test RFC2253 characters are escaped with backslashes */
  50209. {
  50210. ExpectNotNull(name = X509_NAME_new());
  50211. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName",
  50212. /* space at beginning and end, and: ,+"\ */
  50213. MBSTRING_UTF8, (byte*)" US,+\"\\ ", 8, -1, 0),
  50214. WOLFSSL_SUCCESS);
  50215. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName",
  50216. /* # at beginning, and: <>;*/
  50217. MBSTRING_UTF8, (byte*)"#wolfssl.com<>;", 15, -1, 0),
  50218. WOLFSSL_SUCCESS);
  50219. /* Test without flags */
  50220. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  50221. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0, 0), WOLFSSL_SUCCESS);
  50222. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  50223. ExpectIntEQ(memSz, XSTRLEN(expNotEscaped));
  50224. ExpectIntEQ(XSTRNCMP((char*)mem, expNotEscaped,
  50225. XSTRLEN(expNotEscaped)), 0);
  50226. BIO_free(membio);
  50227. membio = NULL;
  50228. /* Test flags: XN_FLAG_RFC5523 - should be reversed and escaped */
  50229. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  50230. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  50231. XN_FLAG_RFC2253), WOLFSSL_SUCCESS);
  50232. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  50233. ExpectIntEQ(memSz, XSTRLEN(expRFC5523));
  50234. ExpectIntEQ(XSTRNCMP((char*)mem, expRFC5523, XSTRLEN(expRFC5523)), 0);
  50235. BIO_free(membio);
  50236. membio = NULL;
  50237. /* Test flags: XN_FLAG_DN_REV - reversed but not escaped */
  50238. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  50239. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  50240. XN_FLAG_DN_REV), WOLFSSL_SUCCESS);
  50241. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  50242. ExpectIntEQ(memSz, XSTRLEN(expNotEscapedRev));
  50243. ExpectIntEQ(XSTRNCMP((char*)mem, expNotEscapedRev,
  50244. XSTRLEN(expNotEscapedRev)), 0);
  50245. BIO_free(membio);
  50246. X509_NAME_free(name);
  50247. }
  50248. #endif
  50249. return EXPECT_RESULT();
  50250. }
  50251. #ifndef NO_BIO
  50252. static int test_wolfSSL_X509_INFO_multiple_info(void)
  50253. {
  50254. EXPECT_DECLS;
  50255. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  50256. STACK_OF(X509_INFO) *info_stack = NULL;
  50257. X509_INFO *info = NULL;
  50258. int len;
  50259. int i;
  50260. const char* files[] = {
  50261. cliCertFile,
  50262. cliKeyFile,
  50263. /* This needs to be the order as svrCertFile contains the
  50264. * intermediate cert as well. */
  50265. svrKeyFile,
  50266. svrCertFile,
  50267. NULL,
  50268. };
  50269. const char** curFile;
  50270. BIO *fileBIO = NULL;
  50271. BIO *concatBIO = NULL;
  50272. byte tmp[FOURK_BUF];
  50273. /* concatenate the cert and the key file to force PEM_X509_INFO_read_bio
  50274. * to group objects together. */
  50275. ExpectNotNull(concatBIO = BIO_new(BIO_s_mem()));
  50276. for (curFile = files; EXPECT_SUCCESS() && *curFile != NULL; curFile++) {
  50277. int fileLen = 0;
  50278. ExpectNotNull(fileBIO = BIO_new_file(*curFile, "rb"));
  50279. ExpectIntGT(fileLen = wolfSSL_BIO_get_len(fileBIO), 0);
  50280. if (EXPECT_SUCCESS()) {
  50281. while ((len = BIO_read(fileBIO, tmp, sizeof(tmp))) > 0) {
  50282. ExpectIntEQ(BIO_write(concatBIO, tmp, len), len);
  50283. fileLen -= len;
  50284. if (EXPECT_FAIL())
  50285. break;
  50286. }
  50287. /* Make sure we read the entire file */
  50288. ExpectIntEQ(fileLen, 0);
  50289. }
  50290. BIO_free(fileBIO);
  50291. fileBIO = NULL;
  50292. }
  50293. ExpectNotNull(info_stack = PEM_X509_INFO_read_bio(concatBIO, NULL, NULL,
  50294. NULL));
  50295. ExpectIntEQ(sk_X509_INFO_num(info_stack), 3);
  50296. for (i = 0; i < sk_X509_INFO_num(info_stack); i++) {
  50297. ExpectNotNull(info = sk_X509_INFO_value(info_stack, i));
  50298. ExpectNotNull(info->x509);
  50299. ExpectNull(info->crl);
  50300. if (i != 0) {
  50301. ExpectNotNull(info->x_pkey);
  50302. ExpectIntEQ(X509_check_private_key(info->x509,
  50303. info->x_pkey->dec_pkey), 1);
  50304. }
  50305. else {
  50306. ExpectNull(info->x_pkey);
  50307. }
  50308. }
  50309. sk_X509_INFO_pop_free(info_stack, X509_INFO_free);
  50310. BIO_free(concatBIO);
  50311. #endif
  50312. return EXPECT_RESULT();
  50313. }
  50314. #endif
  50315. #ifndef NO_BIO
  50316. static int test_wolfSSL_X509_INFO(void)
  50317. {
  50318. EXPECT_DECLS;
  50319. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  50320. STACK_OF(X509_INFO) *info_stack = NULL;
  50321. X509_INFO *info = NULL;
  50322. BIO *cert = NULL;
  50323. int i;
  50324. /* PEM in hex format to avoid null terminator */
  50325. byte data[] = {
  50326. 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47,
  50327. 0x49, 0x4e, 0x20, 0x43, 0x45, 0x52, 0x54, 0x63, 0x2d, 0x2d, 0x2d, 0x2d,
  50328. 0x2d, 0x0a, 0x4d, 0x49, 0x49, 0x44, 0x4d, 0x54, 0x42, 0x75, 0x51, 0x3d,
  50329. 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, 0x20, 0x2d, 0x2d,
  50330. 0x2d, 0x2d, 0x2d
  50331. };
  50332. /* PEM in hex format to avoid null terminator */
  50333. byte data2[] = {
  50334. 0x41, 0x53, 0x4e, 0x31, 0x20, 0x4f, 0x49, 0x44, 0x3a, 0x20, 0x70, 0x72,
  50335. 0x69, 0x6d, 0x65, 0x32, 0x35, 0x36, 0x76, 0x31, 0x0a, 0x2d, 0x2d, 0x2d,
  50336. 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x45, 0x43, 0x20, 0x50,
  50337. 0x41, 0x52, 0x41, 0x4d, 0x45, 0x54, 0x45, 0x52, 0x53, 0x2d, 0x2d, 0x2d,
  50338. 0x2d, 0x43, 0x65, 0x72, 0x74, 0x69, 0x2d, 0x0a, 0x42, 0x67, 0x67, 0x71,
  50339. 0x68, 0x6b, 0x6a, 0x4f, 0x50, 0x51, 0x4d, 0x42, 0x42, 0x77, 0x3d, 0x3d,
  50340. 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d
  50341. };
  50342. ExpectNotNull(cert = BIO_new_file(cliCertFileExt, "rb"));
  50343. ExpectNotNull(info_stack = PEM_X509_INFO_read_bio(cert, NULL, NULL, NULL));
  50344. for (i = 0; i < sk_X509_INFO_num(info_stack); i++) {
  50345. ExpectNotNull(info = sk_X509_INFO_value(info_stack, i));
  50346. ExpectNotNull(info->x509);
  50347. ExpectNull(info->crl);
  50348. ExpectNull(info->x_pkey);
  50349. }
  50350. sk_X509_INFO_pop_free(info_stack, X509_INFO_free);
  50351. info_stack = NULL;
  50352. BIO_free(cert);
  50353. cert = NULL;
  50354. ExpectNotNull(cert = BIO_new_file(cliCertFileExt, "rb"));
  50355. ExpectNotNull(info_stack = PEM_X509_INFO_read_bio(cert, NULL, NULL, NULL));
  50356. sk_X509_INFO_pop_free(info_stack, X509_INFO_free);
  50357. info_stack = NULL;
  50358. BIO_free(cert);
  50359. cert = NULL;
  50360. /* This case should fail due to invalid input. */
  50361. ExpectNotNull(cert = BIO_new(BIO_s_mem()));
  50362. ExpectIntEQ(BIO_write(cert, data, sizeof(data)), sizeof(data));
  50363. ExpectNull(info_stack = PEM_X509_INFO_read_bio(cert, NULL, NULL, NULL));
  50364. sk_X509_INFO_pop_free(info_stack, X509_INFO_free);
  50365. info_stack = NULL;
  50366. BIO_free(cert);
  50367. cert = NULL;
  50368. ExpectNotNull(cert = BIO_new(BIO_s_mem()));
  50369. ExpectIntEQ(BIO_write(cert, data2, sizeof(data2)), sizeof(data2));
  50370. ExpectNull(info_stack = PEM_X509_INFO_read_bio(cert, NULL, NULL, NULL));
  50371. sk_X509_INFO_pop_free(info_stack, X509_INFO_free);
  50372. BIO_free(cert);
  50373. #endif
  50374. return EXPECT_RESULT();
  50375. }
  50376. #endif
  50377. static int test_wolfSSL_X509_subject_name_hash(void)
  50378. {
  50379. EXPECT_DECLS;
  50380. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  50381. !defined(NO_RSA) && (!defined(NO_SHA) || !defined(NO_SHA256))
  50382. X509* x509 = NULL;
  50383. X509_NAME* subjectName = NULL;
  50384. unsigned long ret1 = 0;
  50385. unsigned long ret2 = 0;
  50386. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  50387. SSL_FILETYPE_PEM));
  50388. ExpectNotNull(subjectName = wolfSSL_X509_get_subject_name(x509));
  50389. /* These two
  50390. * - X509_subject_name_hash(x509)
  50391. * - X509_NAME_hash(X509_get_subject_name(x509))
  50392. * should give the same hash, if !defined(NO_SHA) is true. */
  50393. ret1 = X509_subject_name_hash(x509);
  50394. ExpectIntNE(ret1, 0);
  50395. #if !defined(NO_SHA)
  50396. ret2 = X509_NAME_hash(X509_get_subject_name(x509));
  50397. ExpectIntNE(ret2, 0);
  50398. ExpectIntEQ(ret1, ret2);
  50399. #else
  50400. (void) ret2;
  50401. #endif
  50402. X509_free(x509);
  50403. #endif
  50404. return EXPECT_RESULT();
  50405. }
  50406. static int test_wolfSSL_X509_issuer_name_hash(void)
  50407. {
  50408. EXPECT_DECLS;
  50409. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) \
  50410. && !defined(NO_RSA) && (!defined(NO_SHA) || !defined(NO_SHA256))
  50411. X509* x509 = NULL;
  50412. X509_NAME* issuertName = NULL;
  50413. unsigned long ret1 = 0;
  50414. unsigned long ret2 = 0;
  50415. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  50416. SSL_FILETYPE_PEM));
  50417. ExpectNotNull(issuertName = wolfSSL_X509_get_issuer_name(x509));
  50418. /* These two
  50419. * - X509_issuer_name_hash(x509)
  50420. * - X509_NAME_hash(X509_get_issuer_name(x509))
  50421. * should give the same hash, if !defined(NO_SHA) is true. */
  50422. ret1 = X509_issuer_name_hash(x509);
  50423. ExpectIntNE(ret1, 0);
  50424. #if !defined(NO_SHA)
  50425. ret2 = X509_NAME_hash(X509_get_issuer_name(x509));
  50426. ExpectIntNE(ret2, 0);
  50427. ExpectIntEQ(ret1, ret2);
  50428. #else
  50429. (void) ret2;
  50430. #endif
  50431. X509_free(x509);
  50432. #endif
  50433. return EXPECT_RESULT();
  50434. }
  50435. static int test_wolfSSL_X509_check_host(void)
  50436. {
  50437. EXPECT_DECLS;
  50438. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) \
  50439. && !defined(NO_SHA) && !defined(NO_RSA)
  50440. X509* x509 = NULL;
  50441. const char altName[] = "example.com";
  50442. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  50443. SSL_FILETYPE_PEM));
  50444. ExpectIntEQ(X509_check_host(x509, altName, XSTRLEN(altName), 0, NULL),
  50445. WOLFSSL_SUCCESS);
  50446. ExpectIntEQ(X509_check_host(x509, NULL, 0, 0, NULL),
  50447. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50448. X509_free(x509);
  50449. ExpectIntEQ(X509_check_host(NULL, altName, XSTRLEN(altName), 0, NULL),
  50450. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50451. #endif
  50452. return EXPECT_RESULT();
  50453. }
  50454. static int test_wolfSSL_X509_check_email(void)
  50455. {
  50456. EXPECT_DECLS;
  50457. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && !defined(NO_RSA)
  50458. X509* x509 = NULL;
  50459. const char goodEmail[] = "info@wolfssl.com";
  50460. const char badEmail[] = "disinfo@wolfssl.com";
  50461. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  50462. SSL_FILETYPE_PEM));
  50463. /* Should fail on non-matching email address */
  50464. ExpectIntEQ(wolfSSL_X509_check_email(x509, badEmail, XSTRLEN(badEmail), 0),
  50465. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50466. /* Should succeed on matching email address */
  50467. ExpectIntEQ(wolfSSL_X509_check_email(x509, goodEmail, XSTRLEN(goodEmail), 0),
  50468. WOLFSSL_SUCCESS);
  50469. /* Should compute length internally when not provided */
  50470. ExpectIntEQ(wolfSSL_X509_check_email(x509, goodEmail, 0, 0),
  50471. WOLFSSL_SUCCESS);
  50472. /* Should fail when email address is NULL */
  50473. ExpectIntEQ(wolfSSL_X509_check_email(x509, NULL, 0, 0),
  50474. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50475. X509_free(x509);
  50476. /* Should fail when x509 is NULL */
  50477. ExpectIntEQ(wolfSSL_X509_check_email(NULL, goodEmail, 0, 0),
  50478. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50479. #endif /* OPENSSL_EXTRA && WOLFSSL_CERT_GEN */
  50480. return EXPECT_RESULT();
  50481. }
  50482. static int test_wc_PemToDer(void)
  50483. {
  50484. EXPECT_DECLS;
  50485. #if !defined(NO_CERTS) && defined(WOLFSSL_PEM_TO_DER) && !defined(NO_FILESYSTEM)
  50486. int ret;
  50487. DerBuffer* pDer = NULL;
  50488. const char* ca_cert = "./certs/server-cert.pem";
  50489. byte* cert_buf = NULL;
  50490. size_t cert_sz = 0;
  50491. int eccKey = 0;
  50492. EncryptedInfo info;
  50493. XMEMSET(&info, 0, sizeof(info));
  50494. ExpectIntEQ(ret = load_file(ca_cert, &cert_buf, &cert_sz), 0);
  50495. ExpectIntEQ(ret = wc_PemToDer(cert_buf, (long int)cert_sz, CERT_TYPE, &pDer, NULL,
  50496. &info, &eccKey), 0);
  50497. wc_FreeDer(&pDer);
  50498. pDer = NULL;
  50499. if (cert_buf != NULL) {
  50500. free(cert_buf);
  50501. cert_buf = NULL;
  50502. }
  50503. #ifdef HAVE_ECC
  50504. {
  50505. const char* ecc_private_key = "./certs/ecc-privOnlyKey.pem";
  50506. byte key_buf[256] = {0};
  50507. /* Test fail of loading a key with cert type */
  50508. ExpectIntEQ(load_file(ecc_private_key, &cert_buf, &cert_sz), 0);
  50509. key_buf[0] = '\n';
  50510. ExpectNotNull(XMEMCPY(key_buf + 1, cert_buf, cert_sz));
  50511. ExpectIntNE((ret = wc_PemToDer(key_buf, cert_sz + 1, CERT_TYPE,
  50512. &pDer, NULL, &info, &eccKey)), 0);
  50513. #ifdef OPENSSL_EXTRA
  50514. ExpectIntEQ((ret = wc_PemToDer(key_buf, cert_sz + 1, PRIVATEKEY_TYPE,
  50515. &pDer, NULL, &info, &eccKey)), 0);
  50516. #endif
  50517. wc_FreeDer(&pDer);
  50518. if (cert_buf != NULL)
  50519. free(cert_buf);
  50520. }
  50521. #endif
  50522. #endif
  50523. return EXPECT_RESULT();
  50524. }
  50525. static int test_wc_AllocDer(void)
  50526. {
  50527. EXPECT_DECLS;
  50528. #if !defined(NO_CERTS)
  50529. DerBuffer* pDer = NULL;
  50530. word32 testSize = 1024;
  50531. ExpectIntEQ(wc_AllocDer(NULL, testSize, CERT_TYPE, HEAP_HINT),
  50532. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50533. ExpectIntEQ(wc_AllocDer(&pDer, testSize, CERT_TYPE, HEAP_HINT), 0);
  50534. ExpectNotNull(pDer);
  50535. wc_FreeDer(&pDer);
  50536. #endif
  50537. return EXPECT_RESULT();
  50538. }
  50539. static int test_wc_CertPemToDer(void)
  50540. {
  50541. EXPECT_DECLS;
  50542. #if !defined(NO_CERTS) && defined(WOLFSSL_PEM_TO_DER) && !defined(NO_FILESYSTEM)
  50543. const char* ca_cert = "./certs/ca-cert.pem";
  50544. byte* cert_buf = NULL;
  50545. size_t cert_sz = 0;
  50546. size_t cert_dersz = 0;
  50547. byte* cert_der = NULL;
  50548. ExpectIntEQ(load_file(ca_cert, &cert_buf, &cert_sz), 0);
  50549. cert_dersz = cert_sz; /* DER will be smaller than PEM */
  50550. ExpectNotNull(cert_der = (byte*)malloc(cert_dersz));
  50551. ExpectIntGE(wc_CertPemToDer(cert_buf, (int)cert_sz, cert_der,
  50552. (int)cert_dersz, CERT_TYPE), 0);
  50553. ExpectIntEQ(wc_CertPemToDer(NULL, (int)cert_sz, NULL, -1, CERT_TYPE),
  50554. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50555. ExpectIntEQ(wc_CertPemToDer(cert_buf, (int)cert_sz, NULL, -1, CERT_TYPE),
  50556. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50557. ExpectIntEQ(wc_CertPemToDer(NULL, (int)cert_sz, cert_der, -1, CERT_TYPE),
  50558. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50559. ExpectIntEQ(wc_CertPemToDer(NULL, (int)cert_sz, NULL, (int)cert_dersz,
  50560. CERT_TYPE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50561. ExpectIntEQ(wc_CertPemToDer(NULL, (int)cert_sz, cert_der,
  50562. (int)cert_dersz, CERT_TYPE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50563. ExpectIntEQ(wc_CertPemToDer(cert_buf, (int)cert_sz, NULL,
  50564. (int)cert_dersz, CERT_TYPE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50565. ExpectIntEQ(wc_CertPemToDer(cert_buf, (int)cert_sz, cert_der, -1,
  50566. CERT_TYPE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50567. if (cert_der != NULL)
  50568. free(cert_der);
  50569. if (cert_buf != NULL)
  50570. free(cert_buf);
  50571. #endif
  50572. return EXPECT_RESULT();
  50573. }
  50574. static int test_wc_KeyPemToDer(void)
  50575. {
  50576. EXPECT_DECLS;
  50577. #if defined(WOLFSSL_PEM_TO_DER) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  50578. int ret = 0;
  50579. const byte cert_buf[] = \
  50580. "-----BEGIN PRIVATE KEY-----\n"
  50581. "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDMG5KgWxP002pA\n"
  50582. "QJIdA4H5N0oM1Wf0LrHcos5RYUlrHDkC2b5p2BUpVRPmgDAFD2+8leim98x0BvcB\n"
  50583. "k48TNzrVynuwyVEY664+iQyzEBO5v27HPRydOddprbLCvRO036XINGIjauy1jHFi\n"
  50584. "HaDVx3bexSwgp9aefUGAszFXi4q1J4GacV7Cr2b/wBqUHqWv4ZXPu6R9/UYngTkD\n"
  50585. "UDJL5gLlLfcLzNyyodKPHPCIAKdWn6mSVdcHk8XVpK4y9lgz4E7YDWA6ohKZgWgG\n"
  50586. "2RDha8CMilFMDgYa0G0SiS9g3PQx0qh3AMXJJsKSVhScFCZufAE0kV6KvjP7jAqP\n"
  50587. "XBiSkRGPAgMBAAECggEAW7hmRyY2jRX2UMJThrM9VIs6fRLnYI0dQ0tsEJj536ay\n"
  50588. "nevQjArc05KWW0Yujg+WRDZPcry3RUqd9Djlmhp/F3Si6dpF1b+PMS3wJYVrf9Sd\n"
  50589. "SO5W7faArU4vnyBNe0HnY1Ta5xSVI65lg1RSIs88RTZwsooJwXYDGf0shq0/21CE\n"
  50590. "V8HOb27DDYNcEnm35lzaONjFnMqQQT2Vs9anRrPiSEXNleEvTgLVXZtGTyCGTz6v\n"
  50591. "x86Y8eSWL9YNHvPE1I+mDPuocfSR7eRNgRu7SK3mn94W5mqd7Ns072YKX/2XN1mO\n"
  50592. "66+ZFHO6v4dK1u7cSjuwrU1EhLHpUsgDz6Bna5InyQKBgQDv5l8RPy8UneKSADaf\n"
  50593. "M5L/5675I/5t4nqVjvbnQje00YveLTAEjlJBNR93Biln3sYgnvNamYDCxyEuUZ/I\n"
  50594. "S/vmBL9PoxfGZow4FcsIBOEbIn3E0SYJgCBNWthquUvGpKsYDnThJuhO+1cVmxAJ\n"
  50595. "BUOjLFnJYHM0a+Vmk9GexT2OBwKBgQDZzkUBOK7Im3eiYytFocUJyhqMH30d49X9\n"
  50596. "ujC7kGw4UWAqVe7YCSvlBa8nzWpRWK2kRpu3M0272RU0V4geyWqT+nr/SvRRPtNP\n"
  50597. "F5dY8l3yR7hjtSejqqjOfBcZT6ETJxI4tiG0+Nl5BlfM5M+0nxnkWpRcHuOR3j79\n"
  50598. "YUFERyN+OQKBgQCjlOKeUAc6d65W/+4/AFvsQ378Q57qLtSHxsR1TKHPmlNVXFqx\n"
  50599. "wJo1/JNIBduWCEHxXHF0BdfW+RGXE/FwEt/hKLuLAhrkHmjelX2sKieU6R/5ZOQa\n"
  50600. "9lMQbDHGFDOncAF6leD85hriQGBRSzrT69MDIOrYdfwYcroqCAGX0cb3YQKBgQC8\n"
  50601. "iIFQylj5SyHmjcMSNjKSA8CxFDzAV8yPIdE3Oo+CvGXqn5HsrRuy1hXE9VmXapR8\n"
  50602. "A6ackSszdHiXY0FvrNe1mfdH7wDHJwPQjdIzazCJHS3uGQxj7sDKY7226ie6pXJv\n"
  50603. "ZrCMr2/IBAaSVGm6ppHKCeIsT4ybYm7R85KEYLPHeQKBgBeJOMBinXQfWN/1jT9b\n"
  50604. "6Ywrutvp2zP8hVxQGSZJ0WG4iewZyFLsPUlbWRXOSYNPElHmdD0ZomdLVm+lSpAA\n"
  50605. "XSH5FJ/IFCwqq7Eft6Gf8NFRV+NjPMUny+PnjHe4oFP8YK/Ek22K3ttNG8Hw69Aw\n"
  50606. "AQue5o6oVfhgLiJzMdo/77gw\n"
  50607. "-----END PRIVATE KEY-----\n";
  50608. const int cert_sz = sizeof(cert_buf);
  50609. const char cert_pw[] = "password";
  50610. int cert_dersz = 0;
  50611. byte* cert_der = NULL;
  50612. /* Bad arg: Cert buffer is NULL */
  50613. ExpectIntEQ(wc_KeyPemToDer(NULL, cert_sz, cert_der, cert_dersz, ""),
  50614. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50615. /* Bad arg: Cert DER buffer non-NULL but size zero (or less) */
  50616. ExpectIntEQ(wc_KeyPemToDer(cert_buf, cert_sz, (byte*)&cert_der, 0, ""),
  50617. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50618. /* Test normal operation */
  50619. cert_dersz = cert_sz; /* DER will be smaller than PEM */
  50620. ExpectNotNull(cert_der = (byte*)malloc((size_t)cert_dersz));
  50621. ExpectIntGE(ret = wc_KeyPemToDer(cert_buf, cert_sz, cert_der, cert_dersz,
  50622. cert_pw), 0);
  50623. ExpectIntLE(ret, cert_sz);
  50624. if (cert_der != NULL) {
  50625. free(cert_der);
  50626. cert_der = NULL;
  50627. }
  50628. /* Test NULL for DER buffer to return needed DER buffer size */
  50629. ExpectIntGT(ret = wc_KeyPemToDer(cert_buf, cert_sz, NULL, 0, ""), 0);
  50630. ExpectIntLE(ret, cert_sz);
  50631. if (EXPECT_SUCCESS())
  50632. cert_dersz = ret;
  50633. ExpectNotNull(cert_der = (byte*)malloc((size_t)cert_dersz));
  50634. ExpectIntGE(ret = wc_KeyPemToDer(cert_buf, cert_sz, cert_der, cert_dersz,
  50635. cert_pw), 0);
  50636. ExpectIntLE(ret, cert_sz);
  50637. if (cert_der != NULL)
  50638. free(cert_der);
  50639. #endif
  50640. return EXPECT_RESULT();
  50641. }
  50642. static int test_wc_PubKeyPemToDer(void)
  50643. {
  50644. EXPECT_DECLS;
  50645. #if defined(WOLFSSL_PEM_TO_DER) && !defined(NO_FILESYSTEM) && \
  50646. (defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_PUB_PEM_TO_DER))
  50647. int ret = 0;
  50648. const char* key = "./certs/ecc-client-keyPub.pem";
  50649. byte* cert_buf = NULL;
  50650. size_t cert_sz = 0, cert_dersz = 0;
  50651. byte* cert_der = NULL;
  50652. ExpectIntEQ(wc_PubKeyPemToDer(cert_buf, (int)cert_sz,
  50653. cert_der, (int)cert_dersz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50654. ExpectIntEQ(load_file(key, &cert_buf, &cert_sz), 0);
  50655. cert_dersz = cert_sz; /* DER will be smaller than PEM */
  50656. ExpectNotNull(cert_der = (byte*)malloc(cert_dersz));
  50657. ExpectIntGE(wc_PubKeyPemToDer(cert_buf, (int)cert_sz, cert_der,
  50658. (int)cert_dersz), 0);
  50659. if (cert_der != NULL) {
  50660. free(cert_der);
  50661. cert_der = NULL;
  50662. }
  50663. /* Test NULL for DER buffer to return needed DER buffer size */
  50664. ExpectIntGT(ret = wc_PubKeyPemToDer(cert_buf, (int)cert_sz, NULL, 0), 0);
  50665. ExpectIntLE(ret, cert_sz);
  50666. cert_dersz = (size_t)ret;
  50667. ExpectNotNull(cert_der = (byte*)malloc(cert_dersz));
  50668. ExpectIntGE(wc_PubKeyPemToDer(cert_buf, (int)cert_sz, cert_der,
  50669. (int)cert_dersz), 0);
  50670. if (cert_der != NULL) {
  50671. free(cert_der);
  50672. }
  50673. if (cert_buf != NULL) {
  50674. free(cert_buf);
  50675. }
  50676. #endif
  50677. return EXPECT_RESULT();
  50678. }
  50679. static int test_wc_PemPubKeyToDer(void)
  50680. {
  50681. EXPECT_DECLS;
  50682. #if !defined(NO_FILESYSTEM) && \
  50683. (defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_PUB_PEM_TO_DER))
  50684. const char* key = "./certs/ecc-client-keyPub.pem";
  50685. size_t cert_dersz = 1024;
  50686. byte* cert_der = NULL;
  50687. ExpectIntGE(wc_PemPubKeyToDer(NULL, cert_der, (int)cert_dersz),
  50688. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50689. ExpectNotNull(cert_der = (byte*)malloc(cert_dersz));
  50690. ExpectIntGE(wc_PemPubKeyToDer(key, cert_der, (int)cert_dersz), 0);
  50691. if (cert_der != NULL) {
  50692. free(cert_der);
  50693. }
  50694. #endif
  50695. return EXPECT_RESULT();
  50696. }
  50697. static int test_wc_GetPubKeyDerFromCert(void)
  50698. {
  50699. EXPECT_DECLS;
  50700. #if !defined(NO_RSA) || defined(HAVE_ECC)
  50701. int ret;
  50702. word32 idx = 0;
  50703. byte keyDer[TWOK_BUF]; /* large enough for up to RSA 2048 */
  50704. word32 keyDerSz = (word32)sizeof(keyDer);
  50705. DecodedCert decoded;
  50706. #if !defined(NO_RSA) && defined(WOLFSSL_CERT_REQ) && !defined(NO_FILESYSTEM)
  50707. byte certBuf[6000]; /* for PEM and CSR, client-cert.pem is 5-6kB */
  50708. word32 certBufSz = sizeof(certBuf);
  50709. #endif
  50710. #if ((!defined(USE_CERT_BUFFERS_2048) && !defined(USE_CERT_BUFFERS_1024)) || \
  50711. defined(WOLFSSL_CERT_REQ)) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  50712. XFILE fp = XBADFILE;
  50713. #endif
  50714. #ifndef NO_RSA
  50715. RsaKey rsaKey;
  50716. #if defined(USE_CERT_BUFFERS_2048)
  50717. byte* rsaCertDer = (byte*)client_cert_der_2048;
  50718. word32 rsaCertDerSz = sizeof_client_cert_der_2048;
  50719. #elif defined(USE_CERT_BUFFERS_1024)
  50720. byte* rsaCertDer = (byte*)client_cert_der_1024;
  50721. word32 rsaCertDerSz = sizeof_client_cert_der_1024;
  50722. #else
  50723. unsigned char rsaCertDer[TWOK_BUF];
  50724. word32 rsaCertDerSz;
  50725. #endif
  50726. #endif
  50727. #ifdef HAVE_ECC
  50728. ecc_key eccKey;
  50729. #if defined(USE_CERT_BUFFERS_256)
  50730. byte* eccCert = (byte*)cliecc_cert_der_256;
  50731. word32 eccCertSz = sizeof_cliecc_cert_der_256;
  50732. #else
  50733. unsigned char eccCert[ONEK_BUF];
  50734. word32 eccCertSz;
  50735. XFILE fp2 = XBADFILE;
  50736. #endif
  50737. #endif
  50738. #ifndef NO_RSA
  50739. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  50740. ExpectTrue((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) != XBADFILE);
  50741. ExpectIntGT(rsaCertDerSz = (word32)XFREAD(rsaCertDer, 1, sizeof(rsaCertDer),
  50742. fp), 0);
  50743. if (fp != XBADFILE) {
  50744. XFCLOSE(fp);
  50745. fp = XBADFILE;
  50746. }
  50747. #endif
  50748. /* good test case - RSA DER cert */
  50749. wc_InitDecodedCert(&decoded, rsaCertDer, rsaCertDerSz, NULL);
  50750. ExpectIntEQ(wc_ParseCert(&decoded, CERT_TYPE, NO_VERIFY, NULL), 0);
  50751. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, keyDer, &keyDerSz), 0);
  50752. ExpectIntGT(keyDerSz, 0);
  50753. /* sanity check, verify we can import DER public key */
  50754. ret = wc_InitRsaKey(&rsaKey, HEAP_HINT);
  50755. ExpectIntEQ(ret, 0);
  50756. ExpectIntEQ(wc_RsaPublicKeyDecode(keyDer, &idx, &rsaKey, keyDerSz), 0);
  50757. if (ret == 0) {
  50758. wc_FreeRsaKey(&rsaKey);
  50759. }
  50760. /* test LENGTH_ONLY_E case */
  50761. keyDerSz = 0;
  50762. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, NULL, &keyDerSz),
  50763. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  50764. ExpectIntGT(keyDerSz, 0);
  50765. /* bad args: DecodedCert NULL */
  50766. ExpectIntEQ(wc_GetPubKeyDerFromCert(NULL, keyDer, &keyDerSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50767. /* bad args: output key buff size */
  50768. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, keyDer, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50769. /* bad args: zero size output key buffer */
  50770. keyDerSz = 0;
  50771. ExpectIntEQ(ret = wc_GetPubKeyDerFromCert(&decoded, keyDer, &keyDerSz),
  50772. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50773. wc_FreeDecodedCert(&decoded);
  50774. /* Certificate Request Tests */
  50775. #if defined(WOLFSSL_CERT_REQ) && !defined(NO_FILESYSTEM)
  50776. {
  50777. XMEMSET(certBuf, 0, sizeof(certBuf));
  50778. ExpectTrue((fp = XFOPEN("./certs/csr.signed.der", "rb")) != XBADFILE);
  50779. ExpectIntGT(certBufSz = (word32)XFREAD(certBuf, 1, certBufSz, fp), 0);
  50780. if (fp != XBADFILE) {
  50781. XFCLOSE(fp);
  50782. }
  50783. wc_InitDecodedCert(&decoded, certBuf, certBufSz, NULL);
  50784. ExpectIntEQ(wc_ParseCert(&decoded, CERTREQ_TYPE, VERIFY, NULL), 0);
  50785. /* good test case - RSA DER certificate request */
  50786. keyDerSz = sizeof(keyDer);
  50787. ExpectIntEQ(ret = wc_GetPubKeyDerFromCert(&decoded, keyDer, &keyDerSz),
  50788. 0);
  50789. ExpectIntGT(keyDerSz, 0);
  50790. /* sanity check, verify we can import DER public key */
  50791. ret = wc_InitRsaKey(&rsaKey, HEAP_HINT);
  50792. ExpectIntEQ(ret, 0);
  50793. idx = 0;
  50794. ExpectIntEQ(wc_RsaPublicKeyDecode(keyDer, &idx, &rsaKey, keyDerSz), 0);
  50795. if (ret == 0) {
  50796. wc_FreeRsaKey(&rsaKey);
  50797. }
  50798. wc_FreeDecodedCert(&decoded);
  50799. }
  50800. #endif /* WOLFSSL_CERT_REQ */
  50801. #endif /* NO_RSA */
  50802. #ifdef HAVE_ECC
  50803. #ifndef USE_CERT_BUFFERS_256
  50804. ExpectTrue((fp2 = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  50805. XBADFILE);
  50806. ExpectIntGT(eccCertSz = (word32)XFREAD(eccCert, 1, ONEK_BUF, fp2), 0);
  50807. if (fp2 != XBADFILE) {
  50808. XFCLOSE(fp2);
  50809. }
  50810. #endif
  50811. wc_InitDecodedCert(&decoded, eccCert, eccCertSz, NULL);
  50812. ExpectIntEQ(wc_ParseCert(&decoded, CERT_TYPE, NO_VERIFY, NULL), 0);
  50813. /* good test case - ECC */
  50814. XMEMSET(keyDer, 0, sizeof(keyDer));
  50815. keyDerSz = sizeof(keyDer);
  50816. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, keyDer, &keyDerSz), 0);
  50817. ExpectIntGT(keyDerSz, 0);
  50818. /* sanity check, verify we can import DER public key */
  50819. ret = wc_ecc_init(&eccKey);
  50820. ExpectIntEQ(ret, 0);
  50821. idx = 0; /* reset idx to 0, used above in RSA case */
  50822. ExpectIntEQ(wc_EccPublicKeyDecode(keyDer, &idx, &eccKey, keyDerSz), 0);
  50823. if (ret == 0) {
  50824. wc_ecc_free(&eccKey);
  50825. }
  50826. /* test LENGTH_ONLY_E case */
  50827. keyDerSz = 0;
  50828. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, NULL, &keyDerSz),
  50829. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  50830. ExpectIntGT(keyDerSz, 0);
  50831. wc_FreeDecodedCert(&decoded);
  50832. #endif
  50833. #endif /* !NO_RSA || HAVE_ECC */
  50834. return EXPECT_RESULT();
  50835. }
  50836. static int test_wc_CheckCertSigPubKey(void)
  50837. {
  50838. EXPECT_DECLS;
  50839. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  50840. !defined(NO_RSA) && defined(WOLFSSL_PEM_TO_DER) && defined(HAVE_ECC)
  50841. int ret = 0;
  50842. const char* ca_cert = "./certs/ca-cert.pem";
  50843. byte* cert_buf = NULL;
  50844. size_t cert_sz = 0;
  50845. byte* cert_der = NULL;
  50846. word32 cert_dersz = 0;
  50847. byte keyDer[TWOK_BUF]; /* large enough for up to RSA 2048 */
  50848. word32 keyDerSz = (word32)sizeof(keyDer);
  50849. DecodedCert decoded;
  50850. ExpectIntEQ(load_file(ca_cert, &cert_buf, &cert_sz), 0);
  50851. cert_dersz = (word32)cert_sz; /* DER will be smaller than PEM */
  50852. ExpectNotNull(cert_der = (byte*)malloc(cert_dersz));
  50853. ExpectIntGE(ret = wc_CertPemToDer(cert_buf, (int)cert_sz, cert_der,
  50854. (int)cert_dersz, CERT_TYPE), 0);
  50855. wc_InitDecodedCert(&decoded, cert_der, cert_dersz, NULL);
  50856. ExpectIntEQ(wc_ParseCert(&decoded, CERT_TYPE, NO_VERIFY, NULL), 0);
  50857. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, keyDer, &keyDerSz), 0);
  50858. ExpectIntGT(keyDerSz, 0);
  50859. /* Good test case. */
  50860. ExpectIntEQ(wc_CheckCertSigPubKey(cert_der, cert_dersz, NULL, keyDer,
  50861. keyDerSz, RSAk), 0);
  50862. /* No certificate. */
  50863. ExpectIntEQ(wc_CheckCertSigPubKey(NULL, cert_dersz, NULL, keyDer, keyDerSz,
  50864. ECDSAk), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50865. /* Bad cert size. */
  50866. ExpectIntNE(ret = wc_CheckCertSigPubKey(cert_der, 0, NULL, keyDer, keyDerSz,
  50867. RSAk), 0);
  50868. ExpectTrue(ret == WC_NO_ERR_TRACE(ASN_PARSE_E) || ret == WC_NO_ERR_TRACE(BUFFER_E));
  50869. /* No public key. */
  50870. ExpectIntEQ(wc_CheckCertSigPubKey(cert_der, cert_dersz, NULL, NULL,
  50871. keyDerSz, RSAk), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  50872. /* Bad public key size. */
  50873. ExpectIntEQ(wc_CheckCertSigPubKey(cert_der, cert_dersz, NULL, keyDer, 0,
  50874. RSAk), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50875. /* Wrong aglo. */
  50876. ExpectIntEQ(wc_CheckCertSigPubKey(cert_der, cert_dersz, NULL, keyDer,
  50877. keyDerSz, ECDSAk), WC_NO_ERR_TRACE(ASN_PARSE_E));
  50878. wc_FreeDecodedCert(&decoded);
  50879. if (cert_der != NULL)
  50880. free(cert_der);
  50881. if (cert_buf != NULL)
  50882. free(cert_buf);
  50883. #endif
  50884. return EXPECT_RESULT();
  50885. }
  50886. static int test_wolfSSL_certs(void)
  50887. {
  50888. EXPECT_DECLS;
  50889. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  50890. !defined(NO_RSA)
  50891. X509* x509ext = NULL;
  50892. X509* x509 = NULL;
  50893. #ifdef OPENSSL_ALL
  50894. WOLFSSL_X509_EXTENSION* ext = NULL;
  50895. ASN1_OBJECT* obj = NULL;
  50896. #endif
  50897. WOLFSSL* ssl = NULL;
  50898. WOLFSSL_CTX* ctx = NULL;
  50899. STACK_OF(ASN1_OBJECT)* sk = NULL;
  50900. ASN1_STRING* asn1_str = NULL;
  50901. AUTHORITY_KEYID* akey = NULL;
  50902. BASIC_CONSTRAINTS* bc = NULL;
  50903. int crit = 0;
  50904. #ifndef NO_WOLFSSL_SERVER
  50905. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_server_method()));
  50906. #else
  50907. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_client_method()));
  50908. #endif
  50909. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile, SSL_FILETYPE_PEM));
  50910. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  50911. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, SSL_FILETYPE_PEM));
  50912. #if !defined(NO_CHECK_PRIVATE_KEY)
  50913. ExpectIntEQ(SSL_CTX_check_private_key(ctx), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50914. #endif
  50915. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  50916. #if !defined(NO_CHECK_PRIVATE_KEY)
  50917. ExpectIntEQ(SSL_CTX_check_private_key(ctx), SSL_SUCCESS);
  50918. #endif
  50919. ExpectNotNull(ssl = SSL_new(ctx));
  50920. /* Invalid parameters. */
  50921. ExpectIntEQ(SSL_use_certificate_file(NULL, NULL, WOLFSSL_FILETYPE_PEM),
  50922. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50923. ExpectIntEQ(SSL_use_certificate_file(ssl, NULL, WOLFSSL_FILETYPE_PEM),
  50924. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50925. ExpectIntEQ(SSL_use_certificate_file(NULL, "./certs/server-cert.pem",
  50926. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  50927. #if !defined(NO_CHECK_PRIVATE_KEY)
  50928. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  50929. #endif
  50930. #ifdef HAVE_PK_CALLBACKS
  50931. ExpectIntEQ((int)SSL_set_tlsext_debug_arg(ssl, NULL), WOLFSSL_SUCCESS);
  50932. #endif /* HAVE_PK_CALLBACKS */
  50933. /* Invalid parameters. */
  50934. ExpectNotNull(x509 = wolfSSL_X509_new());
  50935. ExpectIntEQ(SSL_use_certificate(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50936. ExpectIntEQ(SSL_use_certificate(ssl, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50937. ExpectIntEQ(SSL_use_certificate(NULL, x509), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50938. /* No data in certificate. */
  50939. ExpectIntEQ(SSL_use_certificate(ssl, x509), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50940. wolfSSL_X509_free(x509);
  50941. x509 = NULL;
  50942. /* create and use x509 */
  50943. #ifdef OPENSSL_ALL
  50944. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  50945. WOLFSSL_FILETYPE_PEM));
  50946. #endif
  50947. ExpectNotNull(x509ext = wolfSSL_X509_load_certificate_file(cliCertFileExt,
  50948. WOLFSSL_FILETYPE_PEM));
  50949. ExpectIntEQ(SSL_use_certificate(ssl, x509ext), WOLFSSL_SUCCESS);
  50950. #if !defined(NO_CHECK_PRIVATE_KEY)
  50951. /* with loading in a new cert the check on private key should now fail */
  50952. ExpectIntNE(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  50953. #endif
  50954. #if defined(USE_CERT_BUFFERS_2048)
  50955. /* Invalid parameters. */
  50956. ExpectIntEQ(SSL_use_certificate_ASN1(NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50957. ExpectIntEQ(SSL_use_certificate_ASN1(ssl, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50958. ExpectIntEQ(SSL_use_certificate_ASN1(NULL,
  50959. (unsigned char*)server_cert_der_2048, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50960. /* No data. */
  50961. ExpectIntEQ(SSL_use_certificate_ASN1(ssl,
  50962. (unsigned char*)server_cert_der_2048, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50963. ExpectIntEQ(SSL_use_certificate_ASN1(ssl,
  50964. (unsigned char*)server_cert_der_2048,
  50965. sizeof_server_cert_der_2048), WOLFSSL_SUCCESS);
  50966. #endif
  50967. #if !defined(NO_SHA) && !defined(NO_SHA256) && !defined(NO_PWDBASED)
  50968. /************* Get Digest of Certificate ******************/
  50969. {
  50970. byte digest[64]; /* max digest size */
  50971. word32 digestSz;
  50972. XMEMSET(digest, 0, sizeof(digest));
  50973. ExpectIntEQ(X509_digest(x509ext, wolfSSL_EVP_sha1(), digest, &digestSz),
  50974. WOLFSSL_SUCCESS);
  50975. ExpectIntEQ(X509_digest(x509ext, wolfSSL_EVP_sha256(), digest, &digestSz),
  50976. WOLFSSL_SUCCESS);
  50977. ExpectIntEQ(X509_digest(NULL, wolfSSL_EVP_sha1(), digest, &digestSz),
  50978. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  50979. }
  50980. #endif /* !NO_SHA && !NO_SHA256 && !NO_PWDBASED */
  50981. /* test and checkout X509 extensions */
  50982. ExpectNotNull(bc = (BASIC_CONSTRAINTS*)X509_get_ext_d2i(x509ext,
  50983. NID_basic_constraints, &crit, NULL));
  50984. ExpectIntEQ(crit, 0);
  50985. #ifdef OPENSSL_ALL
  50986. ExpectNotNull(ext = X509V3_EXT_i2d(NID_basic_constraints, crit, bc));
  50987. X509_EXTENSION_free(ext);
  50988. ext = NULL;
  50989. ExpectNotNull(ext = X509_EXTENSION_new());
  50990. X509_EXTENSION_set_critical(ext, 1);
  50991. ExpectNotNull(obj = OBJ_nid2obj(NID_basic_constraints));
  50992. ExpectIntEQ(X509_EXTENSION_set_object(ext, obj), SSL_SUCCESS);
  50993. ASN1_OBJECT_free(obj);
  50994. obj = NULL;
  50995. X509_EXTENSION_free(ext);
  50996. ext = NULL;
  50997. ExpectNotNull(ext = X509_EXTENSION_new());
  50998. X509_EXTENSION_set_critical(ext, 0);
  50999. ExpectIntEQ(X509_EXTENSION_set_data(ext, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51000. asn1_str = (ASN1_STRING*)X509_get_ext_d2i(x509ext, NID_key_usage, &crit,
  51001. NULL);
  51002. ExpectIntEQ(X509_EXTENSION_set_data(ext, asn1_str), SSL_SUCCESS);
  51003. ASN1_STRING_free(asn1_str); /* X509_EXTENSION_set_data has made a copy
  51004. * and X509_get_ext_d2i has created new */
  51005. asn1_str = NULL;
  51006. X509_EXTENSION_free(ext);
  51007. ext = NULL;
  51008. #endif
  51009. BASIC_CONSTRAINTS_free(bc);
  51010. bc = NULL;
  51011. ExpectNotNull(asn1_str = (ASN1_STRING*)X509_get_ext_d2i(x509ext,
  51012. NID_key_usage, &crit, NULL));
  51013. ExpectIntEQ(crit, 1);
  51014. ExpectIntEQ(asn1_str->type, NID_key_usage);
  51015. #ifdef OPENSSL_ALL
  51016. ExpectNotNull(ext = X509V3_EXT_i2d(NID_key_usage, crit, asn1_str));
  51017. X509_EXTENSION_free(ext);
  51018. ext = NULL;
  51019. #endif
  51020. ASN1_STRING_free(asn1_str);
  51021. asn1_str = NULL;
  51022. #ifdef OPENSSL_ALL
  51023. ExpectNotNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509,
  51024. NID_ext_key_usage, &crit, NULL));
  51025. ExpectNotNull(ext = X509V3_EXT_i2d(NID_ext_key_usage, crit, sk));
  51026. X509_EXTENSION_free(ext);
  51027. ext = NULL;
  51028. EXTENDED_KEY_USAGE_free(sk);
  51029. sk = NULL;
  51030. #else
  51031. sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext, NID_ext_key_usage,
  51032. &crit, NULL);
  51033. ExpectNull(sk);
  51034. #endif
  51035. ExpectNotNull(akey = (AUTHORITY_KEYID*)X509_get_ext_d2i(x509ext,
  51036. NID_authority_key_identifier, &crit, NULL));
  51037. #ifdef OPENSSL_ALL
  51038. ExpectNotNull(ext = X509V3_EXT_i2d(NID_authority_key_identifier, crit,
  51039. akey));
  51040. X509_EXTENSION_free(ext);
  51041. ext = NULL;
  51042. #endif
  51043. wolfSSL_AUTHORITY_KEYID_free(akey);
  51044. akey = NULL;
  51045. /* NID not yet supported */
  51046. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  51047. NID_private_key_usage_period, &crit, NULL));
  51048. ExpectIntEQ(crit, -1);
  51049. sk_ASN1_OBJECT_free(sk);
  51050. sk = NULL;
  51051. ExpectNotNull(sk = (STACK_OF(GENERAL_NAME)*)X509_get_ext_d2i(x509ext,
  51052. NID_subject_alt_name, &crit, NULL));
  51053. {
  51054. int i;
  51055. for (i = 0; i < sk_GENERAL_NAME_num(sk); i++) {
  51056. GENERAL_NAME* gen = sk_GENERAL_NAME_value(sk, i);
  51057. ExpectIntEQ(gen->type, GEN_DNS);
  51058. ExpectIntEQ(gen->d.dNSName->type, V_ASN1_IA5STRING);
  51059. }
  51060. }
  51061. sk_GENERAL_NAME_free(sk);
  51062. sk = NULL;
  51063. /* NID not yet supported */
  51064. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  51065. NID_issuer_alt_name, &crit, NULL));
  51066. ExpectIntEQ(crit, -1);
  51067. sk_ASN1_OBJECT_free(sk);
  51068. sk = NULL;
  51069. /* NID not yet supported */
  51070. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  51071. NID_info_access, &crit, NULL));
  51072. sk_ASN1_OBJECT_free(sk);
  51073. sk = NULL;
  51074. /* NID not yet supported */
  51075. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  51076. NID_sinfo_access, &crit, NULL));
  51077. ExpectIntEQ(crit, -1);
  51078. sk_ASN1_OBJECT_free(sk);
  51079. sk = NULL;
  51080. /* NID not yet supported */
  51081. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  51082. NID_name_constraints, &crit, NULL));
  51083. ExpectIntEQ(crit, -1);
  51084. sk_ASN1_OBJECT_free(sk);
  51085. sk = NULL;
  51086. /* no cert policy set */
  51087. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  51088. NID_certificate_policies, &crit, NULL));
  51089. sk_ASN1_OBJECT_free(sk);
  51090. sk = NULL;
  51091. /* NID not yet supported */
  51092. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  51093. NID_policy_mappings, &crit, NULL));
  51094. ExpectIntEQ(crit, -1);
  51095. sk_ASN1_OBJECT_free(sk);
  51096. sk = NULL;
  51097. /* NID not yet supported */
  51098. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  51099. NID_policy_constraints, &crit, NULL));
  51100. ExpectIntEQ(crit, -1);
  51101. sk_ASN1_OBJECT_free(sk);
  51102. sk = NULL;
  51103. /* NID not yet supported */
  51104. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  51105. NID_inhibit_any_policy, &crit, NULL));
  51106. ExpectIntEQ(crit, -1);
  51107. sk_ASN1_OBJECT_free(sk);
  51108. sk = NULL;
  51109. /* NID not yet supported */
  51110. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  51111. NID_tlsfeature, &crit, NULL));
  51112. ExpectIntEQ(crit, -1);
  51113. sk_ASN1_OBJECT_free(sk);
  51114. sk = NULL;
  51115. /* test invalid cases */
  51116. crit = 0;
  51117. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext, -1, &crit,
  51118. NULL));
  51119. ExpectIntEQ(crit, -1);
  51120. /* NULL passed for criticality. */
  51121. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(NULL,
  51122. NID_tlsfeature, NULL, NULL));
  51123. ExpectIntEQ(SSL_get_hit(ssl), 0);
  51124. #ifdef OPENSSL_ALL
  51125. X509_free(x509);
  51126. #endif
  51127. X509_free(x509ext);
  51128. SSL_free(ssl);
  51129. SSL_CTX_free(ctx);
  51130. #endif /* OPENSSL_EXTRA && !NO_CERTS */
  51131. return EXPECT_RESULT();
  51132. }
  51133. static int test_wolfSSL_X509_check_private_key(void)
  51134. {
  51135. EXPECT_DECLS;
  51136. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  51137. defined(USE_CERT_BUFFERS_2048) && !defined(NO_CHECK_PRIVATE_KEY)
  51138. X509* x509 = NULL;
  51139. EVP_PKEY* pkey = NULL;
  51140. const byte* key;
  51141. /* Check with correct key */
  51142. ExpectNotNull((x509 = X509_load_certificate_file(cliCertFile,
  51143. SSL_FILETYPE_PEM)));
  51144. key = client_key_der_2048;
  51145. ExpectNotNull(d2i_PrivateKey(EVP_PKEY_RSA, &pkey, &key,
  51146. (long)sizeof_client_key_der_2048));
  51147. ExpectIntEQ(X509_check_private_key(x509, pkey), 1);
  51148. EVP_PKEY_free(pkey);
  51149. pkey = NULL;
  51150. /* Check with wrong key */
  51151. key = server_key_der_2048;
  51152. ExpectNotNull(d2i_PrivateKey(EVP_PKEY_RSA, &pkey, &key,
  51153. (long)sizeof_server_key_der_2048));
  51154. ExpectIntEQ(X509_check_private_key(x509, pkey), 0);
  51155. /* test for incorrect parameter */
  51156. ExpectIntEQ(X509_check_private_key(NULL, pkey), 0);
  51157. ExpectIntEQ(X509_check_private_key(x509, NULL), 0);
  51158. ExpectIntEQ(X509_check_private_key(NULL, NULL), 0);
  51159. EVP_PKEY_free(pkey);
  51160. X509_free(x509);
  51161. #endif
  51162. return EXPECT_RESULT();
  51163. }
  51164. static int test_wolfSSL_private_keys(void)
  51165. {
  51166. EXPECT_DECLS;
  51167. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  51168. !defined(NO_FILESYSTEM)
  51169. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  51170. WOLFSSL* ssl = NULL;
  51171. WOLFSSL_CTX* ctx = NULL;
  51172. EVP_PKEY* pkey = NULL;
  51173. OpenSSL_add_all_digests();
  51174. OpenSSL_add_all_algorithms();
  51175. #ifndef NO_RSA
  51176. #ifndef NO_WOLFSSL_SERVER
  51177. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  51178. #else
  51179. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  51180. #endif
  51181. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  51182. WOLFSSL_FILETYPE_PEM));
  51183. /* Have to load a cert before you can check the private key against that
  51184. * certificates public key! */
  51185. #if !defined(NO_CHECK_PRIVATE_KEY)
  51186. ExpectIntEQ(wolfSSL_CTX_check_private_key(ctx), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51187. #endif
  51188. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  51189. WOLFSSL_FILETYPE_PEM));
  51190. #if !defined(NO_CHECK_PRIVATE_KEY)
  51191. ExpectIntEQ(wolfSSL_CTX_check_private_key(ctx), WOLFSSL_SUCCESS);
  51192. #endif
  51193. ExpectNotNull(ssl = SSL_new(ctx));
  51194. #if !defined(NO_CHECK_PRIVATE_KEY)
  51195. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  51196. #endif
  51197. /* Invalid parameters. */
  51198. ExpectIntEQ(SSL_use_PrivateKey_file(NULL, NULL, WOLFSSL_FILETYPE_PEM),
  51199. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51200. ExpectIntEQ(SSL_use_PrivateKey_file(NULL, svrKeyFile, WOLFSSL_FILETYPE_PEM),
  51201. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51202. ExpectIntEQ(SSL_use_PrivateKey_file(ssl, NULL, WOLFSSL_FILETYPE_PEM),
  51203. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51204. #ifdef USE_CERT_BUFFERS_2048
  51205. {
  51206. const unsigned char* server_key = (const unsigned char*)server_key_der_2048;
  51207. unsigned char buf[FOURK_BUF];
  51208. word32 bufSz;
  51209. /* Invalid parameters. */
  51210. ExpectIntEQ(SSL_use_RSAPrivateKey_ASN1(NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51211. ExpectIntEQ(SSL_use_RSAPrivateKey_ASN1(ssl, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51212. ExpectIntEQ(SSL_use_RSAPrivateKey_ASN1(NULL,
  51213. (unsigned char*)client_key_der_2048, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51214. ExpectIntEQ(SSL_use_PrivateKey_ASN1(0, NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51215. ExpectIntEQ(SSL_use_PrivateKey_ASN1(0, ssl, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51216. ExpectIntEQ(SSL_use_PrivateKey_ASN1(0, NULL, (unsigned char*)server_key, 0),
  51217. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51218. ExpectIntEQ(SSL_CTX_use_PrivateKey_ASN1(0, NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51219. ExpectIntEQ(SSL_CTX_use_PrivateKey_ASN1(0, ctx, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51220. ExpectIntEQ(SSL_CTX_use_PrivateKey_ASN1(0, NULL, (unsigned char*)server_key,
  51221. 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51222. ExpectIntEQ(SSL_use_RSAPrivateKey_ASN1(ssl,
  51223. (unsigned char*)client_key_der_2048,
  51224. sizeof_client_key_der_2048), WOLFSSL_SUCCESS);
  51225. #if !defined(NO_CHECK_PRIVATE_KEY)
  51226. /* Should mismatch now that a different private key loaded */
  51227. ExpectIntNE(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  51228. #endif
  51229. ExpectIntEQ(SSL_use_PrivateKey_ASN1(0, ssl,
  51230. (unsigned char*)server_key,
  51231. sizeof_server_key_der_2048), WOLFSSL_SUCCESS);
  51232. #if !defined(NO_CHECK_PRIVATE_KEY)
  51233. /* After loading back in DER format of original key, should match */
  51234. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  51235. #endif
  51236. /* test loading private key to the WOLFSSL_CTX */
  51237. ExpectIntEQ(SSL_CTX_use_PrivateKey_ASN1(0, ctx,
  51238. (unsigned char*)client_key_der_2048,
  51239. sizeof_client_key_der_2048), WOLFSSL_SUCCESS);
  51240. #if !defined(NO_CHECK_PRIVATE_KEY)
  51241. /* Should mismatch now that a different private key loaded */
  51242. ExpectIntNE(wolfSSL_CTX_check_private_key(ctx), WOLFSSL_SUCCESS);
  51243. #endif
  51244. ExpectIntEQ(SSL_CTX_use_PrivateKey_ASN1(0, ctx,
  51245. (unsigned char*)server_key,
  51246. sizeof_server_key_der_2048), WOLFSSL_SUCCESS);
  51247. #if !defined(NO_CHECK_PRIVATE_KEY)
  51248. /* After loading back in DER format of original key, should match */
  51249. ExpectIntEQ(wolfSSL_CTX_check_private_key(ctx), WOLFSSL_SUCCESS);
  51250. #endif
  51251. /* Invalid parameters. */
  51252. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  51253. ExpectIntEQ(SSL_use_PrivateKey(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51254. ExpectIntEQ(SSL_use_PrivateKey(ssl, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51255. ExpectIntEQ(SSL_use_PrivateKey(NULL, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51256. /* pkey is empty - no key data to use. */
  51257. ExpectIntEQ(SSL_use_PrivateKey(ssl, pkey), WC_NO_ERR_TRACE(ASN_PARSE_E));
  51258. wolfSSL_EVP_PKEY_free(pkey);
  51259. pkey = NULL;
  51260. /* set PKEY and test again */
  51261. ExpectNotNull(wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, &pkey,
  51262. &server_key, (long)sizeof_server_key_der_2048));
  51263. ExpectIntEQ(SSL_use_PrivateKey(ssl, pkey), WOLFSSL_SUCCESS);
  51264. /* reuse PKEY structure and test
  51265. * this should be checked with a memory management sanity checker */
  51266. ExpectFalse(server_key == (const unsigned char*)server_key_der_2048);
  51267. server_key = (const unsigned char*)server_key_der_2048;
  51268. ExpectNotNull(wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, &pkey,
  51269. &server_key, (long)sizeof_server_key_der_2048));
  51270. ExpectIntEQ(SSL_use_PrivateKey(ssl, pkey), WOLFSSL_SUCCESS);
  51271. /* check striping PKCS8 header with wolfSSL_d2i_PrivateKey */
  51272. bufSz = FOURK_BUF;
  51273. ExpectIntGT((bufSz = (word32)wc_CreatePKCS8Key(buf, &bufSz,
  51274. (byte*)server_key_der_2048, sizeof_server_key_der_2048,
  51275. RSAk, NULL, 0)), 0);
  51276. server_key = (const unsigned char*)buf;
  51277. ExpectNotNull(wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, &pkey, &server_key,
  51278. (long)bufSz));
  51279. }
  51280. #endif
  51281. EVP_PKEY_free(pkey);
  51282. pkey = NULL;
  51283. SSL_free(ssl); /* frees x509 also since loaded into ssl */
  51284. ssl = NULL;
  51285. SSL_CTX_free(ctx);
  51286. ctx = NULL;
  51287. #endif /* end of RSA private key match tests */
  51288. #ifdef HAVE_ECC
  51289. #ifndef NO_WOLFSSL_SERVER
  51290. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  51291. #else
  51292. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  51293. #endif
  51294. ExpectTrue(SSL_CTX_use_certificate_file(ctx, eccCertFile,
  51295. WOLFSSL_FILETYPE_PEM));
  51296. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, eccKeyFile,
  51297. WOLFSSL_FILETYPE_PEM));
  51298. ExpectNotNull(ssl = SSL_new(ctx));
  51299. #if !defined(NO_CHECK_PRIVATE_KEY)
  51300. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  51301. #endif
  51302. SSL_free(ssl);
  51303. ssl = NULL;
  51304. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, cliEccKeyFile,
  51305. WOLFSSL_FILETYPE_PEM));
  51306. ExpectNotNull(ssl = SSL_new(ctx));
  51307. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  51308. ExpectIntNE(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  51309. #endif
  51310. SSL_free(ssl);
  51311. ssl = NULL;
  51312. SSL_CTX_free(ctx);
  51313. ctx = NULL;
  51314. #endif /* end of ECC private key match tests */
  51315. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_IMPORT)
  51316. #ifndef NO_WOLFSSL_SERVER
  51317. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  51318. #else
  51319. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  51320. #endif
  51321. ExpectTrue(SSL_CTX_use_certificate_file(ctx, edCertFile,
  51322. WOLFSSL_FILETYPE_PEM));
  51323. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, edKeyFile,
  51324. WOLFSSL_FILETYPE_PEM));
  51325. ExpectNotNull(ssl = SSL_new(ctx));
  51326. #if !defined(NO_CHECK_PRIVATE_KEY)
  51327. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  51328. #endif
  51329. SSL_free(ssl);
  51330. ssl = NULL;
  51331. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, cliEdKeyFile,
  51332. WOLFSSL_FILETYPE_PEM));
  51333. ExpectNotNull(ssl = SSL_new(ctx));
  51334. #if !defined(NO_CHECK_PRIVATE_KEY)
  51335. ExpectIntNE(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  51336. #endif
  51337. SSL_free(ssl);
  51338. ssl = NULL;
  51339. SSL_CTX_free(ctx);
  51340. ctx = NULL;
  51341. #endif /* end of Ed25519 private key match tests */
  51342. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_IMPORT)
  51343. #ifndef NO_WOLFSSL_SERVER
  51344. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  51345. #else
  51346. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  51347. #endif
  51348. ExpectTrue(SSL_CTX_use_certificate_file(ctx, ed448CertFile,
  51349. WOLFSSL_FILETYPE_PEM));
  51350. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, ed448KeyFile,
  51351. WOLFSSL_FILETYPE_PEM));
  51352. ExpectNotNull(ssl = SSL_new(ctx));
  51353. #if !defined(NO_CHECK_PRIVATE_KEY)
  51354. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  51355. #endif
  51356. SSL_free(ssl);
  51357. ssl = NULL;
  51358. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, cliEd448KeyFile,
  51359. WOLFSSL_FILETYPE_PEM));
  51360. ExpectNotNull(ssl = SSL_new(ctx));
  51361. #if !defined(NO_CHECK_PRIVATE_KEY)
  51362. ExpectIntNE(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  51363. #endif
  51364. SSL_free(ssl);
  51365. ssl = NULL;
  51366. SSL_CTX_free(ctx);
  51367. ctx = NULL;
  51368. #endif /* end of Ed448 private key match tests */
  51369. EVP_cleanup();
  51370. /* test existence of no-op macros in wolfssl/openssl/ssl.h */
  51371. CONF_modules_free();
  51372. ENGINE_cleanup();
  51373. CONF_modules_unload();
  51374. (void)ssl;
  51375. (void)ctx;
  51376. (void)pkey;
  51377. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  51378. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) */
  51379. return EXPECT_RESULT();
  51380. }
  51381. static int test_wolfSSL_PEM_def_callback(void)
  51382. {
  51383. EXPECT_DECLS;
  51384. #ifdef OPENSSL_EXTRA
  51385. char buf[10];
  51386. const char* defpwd = "DEF PWD";
  51387. int defpwdLen = (int)XSTRLEN(defpwd);
  51388. int smallLen = 1;
  51389. /* Bad parameters. */
  51390. ExpectIntEQ(wolfSSL_PEM_def_callback(NULL, sizeof(buf), 0, NULL), 0);
  51391. ExpectIntEQ(wolfSSL_PEM_def_callback(NULL, sizeof(buf), 0, (void*)defpwd),
  51392. 0);
  51393. ExpectIntEQ(wolfSSL_PEM_def_callback(buf, sizeof(buf), 0, NULL), 0);
  51394. XMEMSET(buf, 0, sizeof(buf));
  51395. ExpectIntEQ(wolfSSL_PEM_def_callback(buf, sizeof(buf), 0, (void*)defpwd),
  51396. defpwdLen);
  51397. ExpectIntEQ(XMEMCMP(buf, defpwd, defpwdLen), 0);
  51398. ExpectIntEQ(buf[defpwdLen], 0);
  51399. /* Size of buffer is smaller than default password. */
  51400. XMEMSET(buf, 0, sizeof(buf));
  51401. ExpectIntEQ(wolfSSL_PEM_def_callback(buf, smallLen, 0, (void*)defpwd),
  51402. smallLen);
  51403. ExpectIntEQ(XMEMCMP(buf, defpwd, smallLen), 0);
  51404. ExpectIntEQ(buf[smallLen], 0);
  51405. #endif /* OPENSSL_EXTRA */
  51406. return EXPECT_RESULT();
  51407. }
  51408. static int test_wolfSSL_PEM_read_PrivateKey(void)
  51409. {
  51410. EXPECT_DECLS;
  51411. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && (!defined(NO_RSA) || \
  51412. !defined(NO_DSA) || defined(HAVE_ECC) || !defined(NO_DH))
  51413. XFILE file = XBADFILE;
  51414. #if !defined(NO_RSA)
  51415. const char* fname_rsa = "./certs/server-key.pem";
  51416. RSA* rsa = NULL;
  51417. WOLFSSL_EVP_PKEY_CTX* ctx = NULL;
  51418. unsigned char* sig = NULL;
  51419. size_t sigLen = 0;
  51420. const unsigned char tbs[] = {0, 1, 2, 3, 4, 5, 6, 7};
  51421. size_t tbsLen = sizeof(tbs);
  51422. #endif
  51423. #if !defined(NO_DSA)
  51424. const char* fname_dsa = "./certs/dsa2048.pem";
  51425. #endif
  51426. #if defined(HAVE_ECC)
  51427. const char* fname_ec = "./certs/ecc-key.pem";
  51428. #endif
  51429. #if !defined(NO_DH)
  51430. const char* fname_dh = "./certs/dh-priv-2048.pem";
  51431. #endif
  51432. EVP_PKEY* pkey = NULL;
  51433. /* Check error case. */
  51434. ExpectNull(pkey = PEM_read_PrivateKey(NULL, NULL, NULL, NULL));
  51435. /* not a PEM key. */
  51436. ExpectTrue((file = XFOPEN("./certs/ecc-key.der", "rb")) != XBADFILE);
  51437. ExpectNull(PEM_read_PrivateKey(file, NULL, NULL, NULL));
  51438. if (file != XBADFILE)
  51439. XFCLOSE(file);
  51440. file = XBADFILE;
  51441. #ifndef NO_RSA
  51442. /* Read in an RSA key. */
  51443. ExpectTrue((file = XFOPEN(fname_rsa, "rb")) != XBADFILE);
  51444. ExpectNotNull(pkey = PEM_read_PrivateKey(file, NULL, NULL, NULL));
  51445. if (file != XBADFILE)
  51446. XFCLOSE(file);
  51447. file = XBADFILE;
  51448. /* Make sure the key is usable by signing some data with it. */
  51449. ExpectNotNull(rsa = EVP_PKEY_get0_RSA(pkey));
  51450. ExpectIntGT((sigLen = RSA_size(rsa)), 0);
  51451. ExpectNotNull(sig = (unsigned char*)XMALLOC(sigLen, HEAP_HINT,
  51452. DYNAMIC_TYPE_TMP_BUFFER));
  51453. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  51454. ExpectIntEQ(EVP_PKEY_sign_init(ctx), WOLFSSL_SUCCESS);
  51455. ExpectIntEQ(EVP_PKEY_sign(ctx, sig, &sigLen, tbs, tbsLen),
  51456. WOLFSSL_SUCCESS);
  51457. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51458. EVP_PKEY_CTX_free(ctx);
  51459. EVP_PKEY_free(pkey);
  51460. pkey = NULL;
  51461. #endif
  51462. #ifndef NO_DSA
  51463. /* Read in a DSA key. */
  51464. ExpectTrue((file = XFOPEN(fname_dsa, "rb")) != XBADFILE);
  51465. #if defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || defined(WOLFSSL_OPENSSH)
  51466. ExpectNotNull(pkey = PEM_read_PrivateKey(file, NULL, NULL, NULL));
  51467. EVP_PKEY_free(pkey);
  51468. pkey = NULL;
  51469. #else
  51470. ExpectNull(PEM_read_PrivateKey(file, NULL, NULL, NULL));
  51471. #endif
  51472. if (file != XBADFILE)
  51473. XFCLOSE(file);
  51474. file = XBADFILE;
  51475. #endif
  51476. #ifdef HAVE_ECC
  51477. /* Read in an EC key. */
  51478. ExpectTrue((file = XFOPEN(fname_ec, "rb")) != XBADFILE);
  51479. ExpectNotNull(pkey = EVP_PKEY_new());
  51480. ExpectPtrEq(PEM_read_PrivateKey(file, &pkey, NULL, NULL), pkey);
  51481. if (file != XBADFILE)
  51482. XFCLOSE(file);
  51483. file = XBADFILE;
  51484. EVP_PKEY_free(pkey);
  51485. pkey = NULL;
  51486. #endif
  51487. #ifndef NO_DH
  51488. /* Read in a DH key. */
  51489. ExpectTrue((file = XFOPEN(fname_dh, "rb")) != XBADFILE);
  51490. #if (defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || \
  51491. defined(WOLFSSL_OPENSSH)) && (!defined(HAVE_FIPS) || \
  51492. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  51493. ExpectNotNull(pkey = PEM_read_PrivateKey(file, NULL, NULL, NULL));
  51494. EVP_PKEY_free(pkey);
  51495. pkey = NULL;
  51496. #else
  51497. ExpectNull(PEM_read_PrivateKey(file, NULL, NULL, NULL));
  51498. #endif
  51499. if (file != XBADFILE)
  51500. XFCLOSE(file);
  51501. file = XBADFILE;
  51502. #endif
  51503. #endif
  51504. return EXPECT_RESULT();
  51505. }
  51506. static int test_wolfSSL_PEM_read_PUBKEY(void)
  51507. {
  51508. EXPECT_DECLS;
  51509. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) \
  51510. && !defined(NO_FILESYSTEM)
  51511. XFILE file = XBADFILE;
  51512. const char* fname = "./certs/client-keyPub.pem";
  51513. EVP_PKEY* pkey = NULL;
  51514. /* Check error case. */
  51515. ExpectNull(pkey = PEM_read_PUBKEY(NULL, NULL, NULL, NULL));
  51516. /* Read in an RSA key. */
  51517. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  51518. ExpectNotNull(pkey = PEM_read_PUBKEY(file, NULL, NULL, NULL));
  51519. EVP_PKEY_free(pkey);
  51520. pkey = NULL;
  51521. if (file != XBADFILE)
  51522. XFCLOSE(file);
  51523. file = XBADFILE;
  51524. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  51525. ExpectNotNull(pkey = EVP_PKEY_new());
  51526. ExpectPtrEq(PEM_read_PUBKEY(file, &pkey, NULL, NULL), pkey);
  51527. EVP_PKEY_free(pkey);
  51528. if (file != XBADFILE)
  51529. XFCLOSE(file);
  51530. #endif
  51531. return EXPECT_RESULT();
  51532. }
  51533. /* test loading RSA key using BIO */
  51534. static int test_wolfSSL_PEM_PrivateKey_rsa(void)
  51535. {
  51536. EXPECT_DECLS;
  51537. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  51538. defined(USE_CERT_BUFFERS_2048) && !defined(NO_FILESYSTEM) && \
  51539. !defined(NO_BIO)
  51540. BIO* bio = NULL;
  51541. XFILE file = XBADFILE;
  51542. const char* fname = "./certs/server-key.pem";
  51543. const char* fname_rsa_p8 = "./certs/server-keyPkcs8.pem";
  51544. EVP_PKEY* pkey = NULL;
  51545. size_t sz = 0;
  51546. byte* buf = NULL;
  51547. EVP_PKEY* pkey2 = NULL;
  51548. EVP_PKEY* pkey3 = NULL;
  51549. RSA* rsa_key = NULL;
  51550. #if defined(WOLFSSL_KEY_GEN) || defined(WOLFSSL_CERT_GEN)
  51551. unsigned char extra[10];
  51552. int i;
  51553. BIO* pub_bio = NULL;
  51554. const unsigned char* server_key = (const unsigned char*)server_key_der_2048;
  51555. #endif
  51556. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  51557. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  51558. ExpectIntGT(sz = XFTELL(file), 0);
  51559. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  51560. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  51561. if (buf != NULL) {
  51562. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  51563. }
  51564. if (file != XBADFILE) {
  51565. XFCLOSE(file);
  51566. file = XBADFILE;
  51567. }
  51568. /* Test using BIO new mem and loading PEM private key */
  51569. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  51570. ExpectNotNull((pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL)));
  51571. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  51572. buf = NULL;
  51573. BIO_free(bio);
  51574. bio = NULL;
  51575. /* New empty EVP_PKEY */
  51576. ExpectNotNull(pkey2 = EVP_PKEY_new());
  51577. if (pkey2 != NULL) {
  51578. pkey2->type = EVP_PKEY_RSA;
  51579. }
  51580. /* Test parameter copy */
  51581. ExpectIntEQ(EVP_PKEY_copy_parameters(pkey2, pkey), 0);
  51582. EVP_PKEY_free(pkey2);
  51583. EVP_PKEY_free(pkey);
  51584. pkey = NULL;
  51585. /* Qt unit test case : rsa pkcs8 key */
  51586. ExpectTrue((file = XFOPEN(fname_rsa_p8, "rb")) != XBADFILE);
  51587. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  51588. ExpectIntGT(sz = XFTELL(file), 0);
  51589. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  51590. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  51591. if (buf) {
  51592. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  51593. }
  51594. if (file != XBADFILE) {
  51595. XFCLOSE(file);
  51596. file = XBADFILE;
  51597. }
  51598. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  51599. ExpectNotNull((pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL)));
  51600. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  51601. buf = NULL;
  51602. BIO_free(bio);
  51603. bio = NULL;
  51604. ExpectNotNull(pkey3 = EVP_PKEY_new());
  51605. ExpectNotNull(rsa_key = EVP_PKEY_get1_RSA(pkey));
  51606. ExpectIntEQ(EVP_PKEY_set1_RSA(pkey3, rsa_key), WOLFSSL_SUCCESS);
  51607. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  51608. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 1/* match */);
  51609. #else
  51610. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 0);
  51611. #endif
  51612. RSA_free(rsa_key);
  51613. EVP_PKEY_free(pkey3);
  51614. EVP_PKEY_free(pkey);
  51615. pkey = NULL;
  51616. pkey2 = NULL;
  51617. #if defined(WOLFSSL_KEY_GEN) || defined(WOLFSSL_CERT_GEN)
  51618. #define BIO_PEM_TEST_CHAR 'a'
  51619. XMEMSET(extra, BIO_PEM_TEST_CHAR, sizeof(extra));
  51620. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51621. ExpectIntEQ(BIO_set_write_buf_size(bio, 4096), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51622. ExpectNotNull(pub_bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51623. ExpectIntEQ(BIO_set_write_buf_size(pub_bio, 4096), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51624. ExpectNull(d2i_PrivateKey(EVP_PKEY_EC, &pkey, &server_key,
  51625. (long)sizeof_server_key_der_2048));
  51626. ExpectNull(pkey);
  51627. ExpectNotNull(wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, &pkey, &server_key,
  51628. (long)sizeof_server_key_der_2048));
  51629. ExpectIntEQ(PEM_write_bio_PrivateKey(NULL, pkey, NULL, NULL, 0, NULL, NULL),
  51630. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51631. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, NULL, NULL, NULL, 0, NULL, NULL),
  51632. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51633. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  51634. WOLFSSL_SUCCESS);
  51635. ExpectIntGT(BIO_pending(bio), 0);
  51636. ExpectIntEQ(BIO_pending(bio), 1679);
  51637. /* Check if the pubkey API writes only the public key */
  51638. #ifdef WOLFSSL_KEY_GEN
  51639. ExpectIntEQ(PEM_write_bio_PUBKEY(NULL, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51640. ExpectIntEQ(PEM_write_bio_PUBKEY(pub_bio, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51641. ExpectIntEQ(PEM_write_bio_PUBKEY(pub_bio, pkey), WOLFSSL_SUCCESS);
  51642. ExpectIntGT(BIO_pending(pub_bio), 0);
  51643. /* Previously both the private key and the pubkey calls would write
  51644. * out the private key and the PEM header was the only difference.
  51645. * The public PEM should be significantly shorter than the
  51646. * private key versison. */
  51647. ExpectIntEQ(BIO_pending(pub_bio), 451);
  51648. #else
  51649. /* Not supported. */
  51650. ExpectIntEQ(PEM_write_bio_PUBKEY(pub_bio, pkey), 0);
  51651. #endif
  51652. /* test creating new EVP_PKEY with good args */
  51653. ExpectNotNull((pkey2 = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL)));
  51654. if (pkey && pkey->pkey.ptr && pkey2 && pkey2->pkey.ptr) {
  51655. ExpectIntEQ((int)XMEMCMP(pkey->pkey.ptr, pkey2->pkey.ptr,
  51656. pkey->pkey_sz), 0);
  51657. }
  51658. /* test of reuse of EVP_PKEY */
  51659. ExpectNull(PEM_read_bio_PrivateKey(bio, &pkey, NULL, NULL));
  51660. ExpectIntEQ(BIO_pending(bio), 0);
  51661. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  51662. SSL_SUCCESS);
  51663. /* add 10 extra bytes after PEM */
  51664. ExpectIntEQ(BIO_write(bio, extra, 10), 10);
  51665. ExpectNotNull(PEM_read_bio_PrivateKey(bio, &pkey, NULL, NULL));
  51666. ExpectNotNull(pkey);
  51667. if (pkey && pkey->pkey.ptr && pkey2 && pkey2->pkey.ptr) {
  51668. ExpectIntEQ((int)XMEMCMP(pkey->pkey.ptr, pkey2->pkey.ptr,
  51669. pkey->pkey_sz), 0);
  51670. }
  51671. /* check 10 extra bytes still there */
  51672. ExpectIntEQ(BIO_pending(bio), 10);
  51673. ExpectIntEQ(BIO_read(bio, extra, 10), 10);
  51674. for (i = 0; i < 10; i++) {
  51675. ExpectIntEQ(extra[i], BIO_PEM_TEST_CHAR);
  51676. }
  51677. BIO_free(pub_bio);
  51678. BIO_free(bio);
  51679. bio = NULL;
  51680. EVP_PKEY_free(pkey);
  51681. pkey = NULL;
  51682. EVP_PKEY_free(pkey2);
  51683. #endif /* WOLFSSL_KEY_GEN || WOLFSSL_CERT_GEN */
  51684. #endif /* OPENSSL_EXTRA && !NO_CERTS && !NO_RSA && USE_CERT_BUFFERS_2048 &&
  51685. * !NO_FILESYSTEM && !NO_BIO */
  51686. return EXPECT_RESULT();
  51687. }
  51688. /* test loading ECC key using BIO */
  51689. static int test_wolfSSL_PEM_PrivateKey_ecc(void)
  51690. {
  51691. EXPECT_DECLS;
  51692. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && defined(HAVE_ECC) && \
  51693. !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  51694. BIO* bio = NULL;
  51695. EVP_PKEY* pkey = NULL;
  51696. XFILE file = XBADFILE;
  51697. const char* fname = "./certs/ecc-key.pem";
  51698. const char* fname_ecc_p8 = "./certs/ecc-keyPkcs8.pem";
  51699. size_t sz = 0;
  51700. byte* buf = NULL;
  51701. EVP_PKEY* pkey2 = NULL;
  51702. EVP_PKEY* pkey3 = NULL;
  51703. EC_KEY* ec_key = NULL;
  51704. int nid = 0;
  51705. BIO* pub_bio = NULL;
  51706. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  51707. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  51708. ExpectIntGT(sz = XFTELL(file), 0);
  51709. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  51710. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  51711. if (buf) {
  51712. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  51713. }
  51714. if (file != XBADFILE) {
  51715. XFCLOSE(file);
  51716. file = XBADFILE;
  51717. }
  51718. /* Test using BIO new mem and loading PEM private key */
  51719. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  51720. ExpectNotNull((pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL)));
  51721. BIO_free(bio);
  51722. bio = NULL;
  51723. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  51724. buf = NULL;
  51725. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51726. ExpectNotNull(pub_bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51727. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  51728. WOLFSSL_SUCCESS);
  51729. ExpectIntGT(BIO_pending(bio), 0);
  51730. /* No parameters. */
  51731. ExpectIntEQ(BIO_pending(bio), 227);
  51732. /* Check if the pubkey API writes only the public key */
  51733. #ifdef WOLFSSL_KEY_GEN
  51734. ExpectIntEQ(PEM_write_bio_PUBKEY(pub_bio, pkey), WOLFSSL_SUCCESS);
  51735. ExpectIntGT(BIO_pending(pub_bio), 0);
  51736. /* Previously both the private key and the pubkey calls would write
  51737. * out the private key and the PEM header was the only difference.
  51738. * The public PEM should be significantly shorter than the
  51739. * private key versison. */
  51740. ExpectIntEQ(BIO_pending(pub_bio), 178);
  51741. #endif
  51742. BIO_free(pub_bio);
  51743. BIO_free(bio);
  51744. bio = NULL;
  51745. ExpectNotNull(pkey2 = EVP_PKEY_new());
  51746. ExpectNotNull(pkey3 = EVP_PKEY_new());
  51747. if (pkey2 != NULL) {
  51748. pkey2->type = EVP_PKEY_EC;
  51749. }
  51750. /* Test parameter copy */
  51751. ExpectIntEQ(EVP_PKEY_copy_parameters(pkey2, pkey), 1);
  51752. /* Qt unit test case 1*/
  51753. ExpectNotNull(ec_key = EVP_PKEY_get1_EC_KEY(pkey));
  51754. ExpectIntEQ(EVP_PKEY_set1_EC_KEY(pkey3, ec_key), WOLFSSL_SUCCESS);
  51755. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  51756. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 1/* match */);
  51757. #else
  51758. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 0);
  51759. #endif
  51760. /* Test default digest */
  51761. ExpectIntEQ(EVP_PKEY_get_default_digest_nid(pkey, &nid), 1);
  51762. ExpectIntEQ(nid, NID_sha256);
  51763. EC_KEY_free(ec_key);
  51764. ec_key = NULL;
  51765. EVP_PKEY_free(pkey3);
  51766. pkey3 = NULL;
  51767. EVP_PKEY_free(pkey2);
  51768. pkey2 = NULL;
  51769. EVP_PKEY_free(pkey);
  51770. pkey = NULL;
  51771. /* Qt unit test case ec pkcs8 key */
  51772. ExpectTrue((file = XFOPEN(fname_ecc_p8, "rb")) != XBADFILE);
  51773. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  51774. ExpectIntGT(sz = XFTELL(file), 0);
  51775. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  51776. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  51777. if (buf) {
  51778. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  51779. }
  51780. if (file != XBADFILE) {
  51781. XFCLOSE(file);
  51782. file = XBADFILE;
  51783. }
  51784. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  51785. ExpectNotNull((pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL)));
  51786. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  51787. buf = NULL;
  51788. BIO_free(bio);
  51789. bio = NULL;
  51790. ExpectNotNull(pkey3 = EVP_PKEY_new());
  51791. /* Qt unit test case */
  51792. ExpectNotNull(ec_key = EVP_PKEY_get1_EC_KEY(pkey));
  51793. ExpectIntEQ(EVP_PKEY_set1_EC_KEY(pkey3, ec_key), WOLFSSL_SUCCESS);
  51794. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  51795. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 1/* match */);
  51796. #else
  51797. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 0);
  51798. #endif
  51799. EC_KEY_free(ec_key);
  51800. EVP_PKEY_free(pkey3);
  51801. EVP_PKEY_free(pkey);
  51802. pkey = NULL;
  51803. #endif
  51804. return EXPECT_RESULT();
  51805. }
  51806. /* test loading DSA key using BIO */
  51807. static int test_wolfSSL_PEM_PrivateKey_dsa(void)
  51808. {
  51809. EXPECT_DECLS;
  51810. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_DSA) && \
  51811. !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  51812. #if defined(WOLFSSL_QT) || defined(OPENSSL_ALL)
  51813. BIO* bio = NULL;
  51814. EVP_PKEY* pkey = NULL;
  51815. ExpectNotNull(bio = BIO_new_file("./certs/dsa2048.pem", "rb"));
  51816. /* Private DSA EVP_PKEY */
  51817. ExpectNotNull(pkey = wolfSSL_PEM_read_bio_PrivateKey(bio, NULL, NULL,
  51818. NULL));
  51819. BIO_free(bio);
  51820. bio = NULL;
  51821. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51822. #if defined(OPENSSL_ALL) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  51823. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, NULL, NULL, 0, NULL,
  51824. NULL), 0);
  51825. #endif
  51826. #ifdef WOLFSSL_KEY_GEN
  51827. ExpectIntEQ(PEM_write_bio_PUBKEY(bio, pkey), 1);
  51828. ExpectIntEQ(BIO_pending(bio), 1178);
  51829. BIO_reset(bio);
  51830. #endif
  51831. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  51832. 1);
  51833. ExpectIntEQ(BIO_pending(bio), 1196);
  51834. BIO_free(bio);
  51835. bio = NULL;
  51836. EVP_PKEY_free(pkey);
  51837. pkey = NULL;
  51838. #endif
  51839. #endif
  51840. return EXPECT_RESULT();
  51841. }
  51842. /* test loading DH key using BIO */
  51843. static int test_wolfSSL_PEM_PrivateKey_dh(void)
  51844. {
  51845. EXPECT_DECLS;
  51846. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_DH) && \
  51847. !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  51848. #if (defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || \
  51849. defined(WOLFSSL_OPENSSH)) && (!defined(HAVE_FIPS) || \
  51850. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  51851. BIO* bio = NULL;
  51852. EVP_PKEY* pkey = NULL;
  51853. ExpectNotNull(bio = BIO_new_file("./certs/dh-priv-2048.pem", "rb"));
  51854. /* Private DH EVP_PKEY */
  51855. ExpectNotNull(pkey = wolfSSL_PEM_read_bio_PrivateKey(bio, NULL, NULL,
  51856. NULL));
  51857. BIO_free(bio);
  51858. bio = NULL;
  51859. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  51860. #if defined(OPENSSL_ALL) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  51861. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, NULL, NULL, 0, NULL,
  51862. NULL), 0);
  51863. #endif
  51864. #ifdef WOLFSSL_KEY_GEN
  51865. ExpectIntEQ(PEM_write_bio_PUBKEY(bio, pkey), 0);
  51866. #endif
  51867. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  51868. 1);
  51869. ExpectIntEQ(BIO_pending(bio), 806);
  51870. BIO_free(bio);
  51871. bio = NULL;
  51872. EVP_PKEY_free(pkey);
  51873. pkey = NULL;
  51874. #endif
  51875. #endif
  51876. return EXPECT_RESULT();
  51877. }
  51878. static int test_wolfSSL_PEM_PrivateKey(void)
  51879. {
  51880. EXPECT_DECLS;
  51881. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  51882. (!defined(NO_RSA) || defined(HAVE_ECC)) && defined(USE_CERT_BUFFERS_2048)
  51883. #ifndef NO_BIO
  51884. BIO* bio = NULL;
  51885. #endif
  51886. EVP_PKEY* pkey = NULL;
  51887. const unsigned char* server_key = (const unsigned char*)server_key_der_2048;
  51888. #ifndef NO_BIO
  51889. /* test creating new EVP_PKEY with bad arg */
  51890. ExpectNull((pkey = PEM_read_bio_PrivateKey(NULL, NULL, NULL, NULL)));
  51891. /* Test bad EVP_PKEY type. */
  51892. /* New HMAC EVP_PKEY */
  51893. ExpectNotNull(bio = BIO_new_mem_buf("", 1));
  51894. ExpectNotNull(pkey = EVP_PKEY_new());
  51895. if (pkey != NULL) {
  51896. pkey->type = EVP_PKEY_HMAC;
  51897. }
  51898. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  51899. 0);
  51900. #if defined(OPENSSL_ALL) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  51901. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, NULL, NULL, 0, NULL,
  51902. NULL), 0);
  51903. #endif
  51904. #ifdef WOLFSSL_KEY_GEN
  51905. ExpectIntEQ(PEM_write_bio_PUBKEY(bio, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51906. #endif
  51907. EVP_PKEY_free(pkey);
  51908. pkey = NULL;
  51909. BIO_free(bio);
  51910. bio = NULL;
  51911. /* key is DES encrypted */
  51912. #if !defined(NO_DES3) && defined(WOLFSSL_ENCRYPTED_KEYS) && \
  51913. !defined(NO_RSA) && !defined(NO_BIO) && !defined(NO_FILESYSTEM) && \
  51914. !defined(NO_MD5) && defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA)
  51915. {
  51916. XFILE f = XBADFILE;
  51917. wc_pem_password_cb* passwd_cb = NULL;
  51918. void* passwd_cb_userdata;
  51919. SSL_CTX* ctx = NULL;
  51920. char passwd[] = "bad password";
  51921. #ifndef WOLFSSL_NO_TLS12
  51922. #ifndef NO_WOLFSSL_SERVER
  51923. ExpectNotNull(ctx = SSL_CTX_new(TLSv1_2_server_method()));
  51924. #else
  51925. ExpectNotNull(ctx = SSL_CTX_new(TLSv1_2_client_method()));
  51926. #endif
  51927. #else
  51928. #ifndef NO_WOLFSSL_SERVER
  51929. ExpectNotNull(ctx = SSL_CTX_new(wolfTLSv1_3_server_method()));
  51930. #else
  51931. ExpectNotNull(ctx = SSL_CTX_new(wolfTLSv1_3_client_method()));
  51932. #endif
  51933. #endif
  51934. ExpectNotNull(bio = BIO_new_file("./certs/server-keyEnc.pem", "rb"));
  51935. SSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  51936. ExpectNotNull(passwd_cb = SSL_CTX_get_default_passwd_cb(ctx));
  51937. ExpectNull(passwd_cb_userdata =
  51938. SSL_CTX_get_default_passwd_cb_userdata(ctx));
  51939. /* fail case with password call back */
  51940. ExpectNull(pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL,
  51941. (void*)passwd));
  51942. BIO_free(bio);
  51943. ExpectNotNull(bio = BIO_new_file("./certs/server-keyEnc.pem", "rb"));
  51944. ExpectNull(pkey = PEM_read_bio_PrivateKey(bio, NULL, passwd_cb,
  51945. (void*)passwd));
  51946. BIO_free(bio);
  51947. ExpectTrue((f = XFOPEN("./certs/server-keyEnc.pem", "rb")) != XBADFILE);
  51948. ExpectNotNull(bio = BIO_new_fp(f, BIO_CLOSE));
  51949. if ((bio == NULL) && (f != XBADFILE)) {
  51950. XFCLOSE(f);
  51951. }
  51952. /* use callback that works */
  51953. ExpectNotNull(pkey = PEM_read_bio_PrivateKey(bio, NULL, passwd_cb,
  51954. (void*)"yassl123"));
  51955. ExpectIntEQ(SSL_CTX_use_PrivateKey(ctx, pkey), SSL_SUCCESS);
  51956. EVP_PKEY_free(pkey);
  51957. pkey = NULL;
  51958. BIO_free(bio);
  51959. bio = NULL;
  51960. SSL_CTX_free(ctx);
  51961. }
  51962. #endif /* !defined(NO_DES3) */
  51963. #endif /* !NO_BIO */
  51964. #if defined(HAVE_ECC) && !defined(NO_FILESYSTEM)
  51965. {
  51966. unsigned char buf[2048];
  51967. size_t bytes = 0;
  51968. XFILE f = XBADFILE;
  51969. SSL_CTX* ctx = NULL;
  51970. #ifndef WOLFSSL_NO_TLS12
  51971. #ifndef NO_WOLFSSL_SERVER
  51972. ExpectNotNull(ctx = SSL_CTX_new(TLSv1_2_server_method()));
  51973. #else
  51974. ExpectNotNull(ctx = SSL_CTX_new(TLSv1_2_client_method()));
  51975. #endif
  51976. #else
  51977. #ifndef NO_WOLFSSL_SERVER
  51978. ExpectNotNull(ctx = SSL_CTX_new(wolfTLSv1_3_server_method()));
  51979. #else
  51980. ExpectNotNull(ctx = SSL_CTX_new(wolfTLSv1_3_client_method()));
  51981. #endif
  51982. #endif
  51983. ExpectTrue((f = XFOPEN("./certs/ecc-key.der", "rb")) != XBADFILE);
  51984. ExpectIntGT(bytes = (size_t)XFREAD(buf, 1, sizeof(buf), f), 0);
  51985. if (f != XBADFILE)
  51986. XFCLOSE(f);
  51987. server_key = buf;
  51988. pkey = NULL;
  51989. ExpectNull(d2i_PrivateKey(EVP_PKEY_RSA, &pkey, &server_key, (long int)bytes));
  51990. ExpectNull(pkey);
  51991. ExpectNotNull(d2i_PrivateKey(EVP_PKEY_EC, &pkey, &server_key, (long int)bytes));
  51992. ExpectIntEQ(SSL_CTX_use_PrivateKey(ctx, pkey), SSL_SUCCESS);
  51993. EVP_PKEY_free(pkey);
  51994. pkey = NULL;
  51995. SSL_CTX_free(ctx);
  51996. server_key = NULL;
  51997. }
  51998. #endif
  51999. #ifndef NO_BIO
  52000. (void)bio;
  52001. #endif
  52002. (void)pkey;
  52003. (void)server_key;
  52004. #endif /* OPENSSL_EXTRA && !NO_CERTS && !NO_RSA && USE_CERT_BUFFERS_2048 */
  52005. return EXPECT_RESULT();
  52006. }
  52007. static int test_wolfSSL_PEM_file_RSAKey(void)
  52008. {
  52009. EXPECT_DECLS;
  52010. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \
  52011. defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA) && \
  52012. !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
  52013. RSA* rsa = NULL;
  52014. XFILE fp = XBADFILE;
  52015. ExpectTrue((fp = XFOPEN("./certs/rsa-pub-2048.pem", "rb")) != XBADFILE);
  52016. ExpectNotNull((rsa = PEM_read_RSA_PUBKEY(fp, NULL, NULL, NULL)));
  52017. if (fp != XBADFILE)
  52018. XFCLOSE(fp);
  52019. ExpectIntEQ(RSA_size(rsa), 256);
  52020. ExpectIntEQ(PEM_write_RSAPublicKey(XBADFILE, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52021. ExpectIntEQ(PEM_write_RSAPublicKey(stderr, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52022. ExpectIntEQ(PEM_write_RSAPublicKey(stderr, rsa), WOLFSSL_SUCCESS);
  52023. ExpectIntEQ(PEM_write_RSA_PUBKEY(XBADFILE, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52024. ExpectIntEQ(PEM_write_RSA_PUBKEY(stderr, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52025. ExpectIntEQ(PEM_write_RSA_PUBKEY(stderr, rsa), WOLFSSL_SUCCESS);
  52026. RSA_free(rsa);
  52027. #endif /* defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \
  52028. (defined(WOLFSSL_KEY_GEN) || WOLFSSL_CERT_GEN) && \
  52029. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_CERTS) */
  52030. return EXPECT_RESULT();
  52031. }
  52032. static int test_wolfSSL_PEM_file_RSAPrivateKey(void)
  52033. {
  52034. EXPECT_DECLS;
  52035. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN) && \
  52036. !defined(NO_FILESYSTEM) && \
  52037. (defined(WOLFSSL_PEM_TO_DER) || defined(WOLFSSL_DER_TO_PEM))
  52038. RSA* rsa = NULL;
  52039. XFILE f = NULL;
  52040. ExpectTrue((f = XFOPEN(svrKeyFile, "r")) != XBADFILE);
  52041. ExpectNotNull((rsa = PEM_read_RSAPrivateKey(f, NULL, NULL, NULL)));
  52042. ExpectIntEQ(RSA_size(rsa), 256);
  52043. if (f != XBADFILE) {
  52044. XFCLOSE(f);
  52045. f = XBADFILE;
  52046. }
  52047. ExpectIntEQ(PEM_write_RSAPrivateKey(XBADFILE, rsa, NULL, NULL, 0, NULL,
  52048. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52049. ExpectIntEQ(PEM_write_RSAPrivateKey(stderr, NULL, NULL, NULL, 0, NULL,
  52050. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52051. ExpectIntEQ(PEM_write_RSAPrivateKey(stderr, rsa, NULL, NULL, 0, NULL, NULL),
  52052. WOLFSSL_SUCCESS);
  52053. RSA_free(rsa);
  52054. #ifdef HAVE_ECC
  52055. ExpectTrue((f = XFOPEN(eccKeyFile, "r")) != XBADFILE);
  52056. ExpectNull((rsa = PEM_read_RSAPrivateKey(f, NULL, NULL, NULL)));
  52057. if (f != XBADFILE)
  52058. XFCLOSE(f);
  52059. #endif /* HAVE_ECC */
  52060. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) */
  52061. return EXPECT_RESULT();
  52062. }
  52063. static int test_wolfSSL_PEM_read_RSA_PUBKEY(void)
  52064. {
  52065. EXPECT_DECLS;
  52066. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  52067. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  52068. XFILE file = XBADFILE;
  52069. const char* fname = "./certs/client-keyPub.pem";
  52070. RSA *rsa = NULL;
  52071. ExpectNull(wolfSSL_PEM_read_RSA_PUBKEY(XBADFILE, NULL, NULL, NULL));
  52072. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  52073. ExpectNotNull((rsa = PEM_read_RSA_PUBKEY(file, NULL, NULL, NULL)));
  52074. ExpectIntEQ(RSA_size(rsa), 256);
  52075. RSA_free(rsa);
  52076. if (file != XBADFILE)
  52077. XFCLOSE(file);
  52078. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) */
  52079. return EXPECT_RESULT();
  52080. }
  52081. #ifndef NO_BIO
  52082. static int test_wolfSSL_PEM_bio_RSAKey(void)
  52083. {
  52084. EXPECT_DECLS;
  52085. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \
  52086. defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA) && \
  52087. !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
  52088. RSA* rsa = NULL;
  52089. BIO* bio = NULL;
  52090. /* PrivateKey */
  52091. ExpectNotNull(bio = BIO_new_file(svrKeyFile, "rb"));
  52092. ExpectNull((rsa = PEM_read_bio_RSAPrivateKey(NULL, NULL, NULL, NULL)));
  52093. ExpectNotNull(PEM_read_bio_RSAPrivateKey(bio, &rsa, NULL, NULL));
  52094. ExpectNotNull(rsa);
  52095. ExpectIntEQ(RSA_size(rsa), 256);
  52096. ExpectIntEQ(PEM_write_bio_RSAPrivateKey(NULL, NULL, NULL, NULL, 0, NULL, \
  52097. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52098. BIO_free(bio);
  52099. bio = NULL;
  52100. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  52101. ExpectIntEQ(PEM_write_bio_RSAPrivateKey(bio, rsa, NULL, NULL, 0, NULL, \
  52102. NULL), WOLFSSL_SUCCESS);
  52103. BIO_free(bio);
  52104. bio = NULL;
  52105. RSA_free(rsa);
  52106. rsa = NULL;
  52107. /* PUBKEY */
  52108. ExpectNotNull(bio = BIO_new_file("./certs/rsa-pub-2048.pem", "rb"));
  52109. ExpectNull((rsa = PEM_read_bio_RSA_PUBKEY(NULL, NULL, NULL, NULL)));
  52110. ExpectNotNull((rsa = PEM_read_bio_RSA_PUBKEY(bio, NULL, NULL, NULL)));
  52111. ExpectIntEQ(RSA_size(rsa), 256);
  52112. ExpectIntEQ(PEM_write_bio_RSA_PUBKEY(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52113. BIO_free(bio);
  52114. bio = NULL;
  52115. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  52116. ExpectIntEQ(PEM_write_bio_RSA_PUBKEY(bio, rsa), WOLFSSL_SUCCESS);
  52117. BIO_free(bio);
  52118. bio = NULL;
  52119. RSA_free(rsa);
  52120. rsa = NULL;
  52121. /* Ensure that keys beginning with BEGIN RSA PUBLIC KEY can be read, too. */
  52122. ExpectNotNull(bio = BIO_new_file("./certs/server-keyPub.pem", "rb"));
  52123. ExpectNotNull((rsa = PEM_read_bio_RSA_PUBKEY(bio, NULL, NULL, NULL)));
  52124. BIO_free(bio);
  52125. bio = NULL;
  52126. RSA_free(rsa);
  52127. rsa = NULL;
  52128. #ifdef HAVE_ECC
  52129. /* ensure that non-rsa keys do not work */
  52130. ExpectNotNull(bio = BIO_new_file(eccKeyFile, "rb")); /* ecc key */
  52131. ExpectNull((rsa = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, NULL)));
  52132. ExpectNull((rsa = PEM_read_bio_RSA_PUBKEY(bio, NULL, NULL, NULL)));
  52133. BIO_free(bio);
  52134. bio = NULL;
  52135. RSA_free(rsa);
  52136. rsa = NULL;
  52137. #endif /* HAVE_ECC */
  52138. #endif /* defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \
  52139. (defined(WOLFSSL_KEY_GEN) || WOLFSSL_CERT_GEN) && \
  52140. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_CERTS) */
  52141. return EXPECT_RESULT();
  52142. }
  52143. static int test_wolfSSL_PEM_bio_RSAPrivateKey(void)
  52144. {
  52145. EXPECT_DECLS;
  52146. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  52147. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  52148. RSA* rsa = NULL;
  52149. RSA* rsa_dup = NULL;
  52150. BIO* bio = NULL;
  52151. ExpectNotNull(bio = BIO_new_file(svrKeyFile, "rb"));
  52152. ExpectNotNull((rsa = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, NULL)));
  52153. ExpectIntEQ(RSA_size(rsa), 256);
  52154. #if defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA)
  52155. ExpectNull(rsa_dup = RSAPublicKey_dup(NULL));
  52156. /* Test duplicating empty key. */
  52157. ExpectNotNull(rsa_dup = RSA_new());
  52158. ExpectNull(RSAPublicKey_dup(rsa_dup));
  52159. RSA_free(rsa_dup);
  52160. rsa_dup = NULL;
  52161. ExpectNotNull(rsa_dup = RSAPublicKey_dup(rsa));
  52162. ExpectPtrNE(rsa_dup, rsa);
  52163. #endif
  52164. /* test if valgrind complains about unreleased memory */
  52165. RSA_up_ref(rsa);
  52166. RSA_free(rsa);
  52167. BIO_free(bio);
  52168. bio = NULL;
  52169. RSA_free(rsa);
  52170. rsa = NULL;
  52171. RSA_free(rsa_dup);
  52172. rsa_dup = NULL;
  52173. #ifdef HAVE_ECC
  52174. ExpectNotNull(bio = BIO_new_file(eccKeyFile, "rb"));
  52175. ExpectNull((rsa = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, NULL)));
  52176. BIO_free(bio);
  52177. #endif /* HAVE_ECC */
  52178. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) */
  52179. return EXPECT_RESULT();
  52180. }
  52181. static int test_wolfSSL_PEM_bio_DSAKey(void)
  52182. {
  52183. EXPECT_DECLS;
  52184. #ifndef HAVE_SELFTEST
  52185. #if (defined(WOLFSSL_QT) || defined(OPENSSL_ALL)) && !defined(NO_CERTS) && \
  52186. defined(WOLFSSL_KEY_GEN) && !defined(NO_FILESYSTEM) && !defined(NO_DSA)
  52187. DSA* dsa = NULL;
  52188. BIO* bio = NULL;
  52189. /* PrivateKey */
  52190. ExpectNotNull(bio = BIO_new_file("./certs/1024/dsa1024.pem", "rb"));
  52191. ExpectNull((dsa = PEM_read_bio_DSAPrivateKey(NULL, NULL, NULL, NULL)));
  52192. ExpectNotNull((dsa = PEM_read_bio_DSAPrivateKey(bio, NULL, NULL, NULL)));
  52193. ExpectIntEQ(BN_num_bytes(dsa->g), 128);
  52194. ExpectIntEQ(PEM_write_bio_DSAPrivateKey(NULL, NULL, NULL, NULL, 0, NULL,
  52195. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52196. BIO_free(bio);
  52197. bio = NULL;
  52198. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  52199. ExpectIntEQ(PEM_write_bio_DSAPrivateKey(bio, dsa, NULL, NULL, 0, NULL,
  52200. NULL), WOLFSSL_SUCCESS);
  52201. BIO_free(bio);
  52202. bio = NULL;
  52203. DSA_free(dsa);
  52204. dsa = NULL;
  52205. /* PUBKEY */
  52206. ExpectNotNull(bio = BIO_new_file("./certs/1024/dsa-pub-1024.pem", "rb"));
  52207. ExpectNull((dsa = PEM_read_bio_DSA_PUBKEY(NULL, NULL, NULL, NULL)));
  52208. ExpectNotNull((dsa = PEM_read_bio_DSA_PUBKEY(bio, NULL, NULL, NULL)));
  52209. ExpectIntEQ(BN_num_bytes(dsa->g), 128);
  52210. ExpectIntEQ(PEM_write_bio_DSA_PUBKEY(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52211. BIO_free(bio);
  52212. bio = NULL;
  52213. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  52214. ExpectIntEQ(PEM_write_bio_DSA_PUBKEY(bio, dsa), WOLFSSL_SUCCESS);
  52215. BIO_free(bio);
  52216. bio = NULL;
  52217. DSA_free(dsa);
  52218. dsa = NULL;
  52219. #ifdef HAVE_ECC
  52220. /* ensure that non-dsa keys do not work */
  52221. ExpectNotNull(bio = BIO_new_file(eccKeyFile, "rb")); /* ecc key */
  52222. ExpectNull((dsa = PEM_read_bio_DSAPrivateKey(bio, NULL, NULL, NULL)));
  52223. ExpectNull((dsa = PEM_read_bio_DSA_PUBKEY(bio, NULL, NULL, NULL)));
  52224. BIO_free(bio);
  52225. bio = NULL;
  52226. DSA_free(dsa);
  52227. dsa = NULL;
  52228. #endif /* HAVE_ECC */
  52229. #endif /* defined(WOLFSSL_QT) || defined(OPENSSL_ALL)) && \
  52230. !defined(NO_CERTS) && defined(WOLFSSL_KEY_GEN) && \
  52231. !defined(NO_FILESYSTEM) && !defined(NO_DSA) */
  52232. #endif /* HAVE_SELFTEST */
  52233. return EXPECT_RESULT();
  52234. }
  52235. static int test_wolfSSL_PEM_bio_ECKey(void)
  52236. {
  52237. EXPECT_DECLS;
  52238. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \
  52239. defined(WOLFSSL_KEY_GEN) && !defined(NO_FILESYSTEM) && defined(HAVE_ECC)
  52240. EC_KEY* ec = NULL;
  52241. EC_KEY* ec2;
  52242. BIO* bio = NULL;
  52243. #if defined(WOLFSSL_PEM_TO_DER) || defined(WOLFSSL_DER_TO_PEM)
  52244. unsigned char* pem = NULL;
  52245. int pLen;
  52246. #endif
  52247. static char ec_key_bad_1[] = "-----BEGIN PUBLIC KEY-----\n"
  52248. "MAA=\n"
  52249. "-----END PUBLIC KEY-----";
  52250. static char ec_priv_key_bad_1[] = "-----BEGIN EC PRIVATE KEY-----\n"
  52251. "MAA=\n"
  52252. "-----END EC PRIVATE KEY-----";
  52253. /* PrivateKey */
  52254. ExpectNotNull(bio = BIO_new_file("./certs/ecc-key.pem", "rb"));
  52255. ExpectNull((ec = PEM_read_bio_ECPrivateKey(NULL, NULL, NULL, NULL)));
  52256. ec2 = NULL;
  52257. ExpectNotNull((ec = PEM_read_bio_ECPrivateKey(bio, &ec2, NULL, NULL)));
  52258. ExpectIntEQ(ec == ec2, 1);
  52259. ExpectIntEQ(wc_ecc_size((ecc_key*)ec->internal), 32);
  52260. ExpectIntEQ(PEM_write_bio_ECPrivateKey(NULL, NULL, NULL, NULL, 0, NULL,
  52261. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52262. ExpectIntEQ(PEM_write_bio_ECPrivateKey(bio, NULL, NULL, NULL, 0, NULL,
  52263. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52264. ExpectIntEQ(PEM_write_bio_ECPrivateKey(NULL, ec, NULL, NULL, 0, NULL, NULL),
  52265. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52266. BIO_free(bio);
  52267. bio = NULL;
  52268. /* Public key data - fail. */
  52269. ExpectNotNull(bio = BIO_new_file("./certs/ecc-client-keyPub.pem", "rb"));
  52270. ExpectNull(PEM_read_bio_ECPrivateKey(bio, NULL, NULL, NULL));
  52271. BIO_free(bio);
  52272. bio = NULL;
  52273. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  52274. ExpectIntEQ(PEM_write_bio_ECPrivateKey(bio, ec, NULL, NULL, 0, NULL, \
  52275. NULL), WOLFSSL_SUCCESS);
  52276. BIO_free(bio);
  52277. bio = NULL;
  52278. ExpectIntEQ(PEM_write_ECPrivateKey(XBADFILE, NULL, NULL, NULL, 0, NULL,
  52279. NULL),WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52280. ExpectIntEQ(PEM_write_ECPrivateKey(stderr, NULL, NULL, NULL, 0, NULL, NULL),
  52281. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52282. ExpectIntEQ(PEM_write_ECPrivateKey(XBADFILE, ec, NULL, NULL, 0, NULL, NULL),
  52283. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52284. ExpectIntEQ(PEM_write_ECPrivateKey(stderr, ec, NULL, NULL, 0, NULL, NULL),
  52285. WOLFSSL_SUCCESS);
  52286. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(NULL, NULL, NULL, 0, NULL,
  52287. NULL), 0);
  52288. #if defined(WOLFSSL_PEM_TO_DER) || defined(WOLFSSL_DER_TO_PEM)
  52289. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(ec, NULL, NULL, 0, NULL,
  52290. NULL), 0);
  52291. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(NULL, NULL, NULL, 0, &pem,
  52292. NULL), 0);
  52293. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(NULL, NULL, NULL, 0, NULL,
  52294. &pLen), 0);
  52295. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(NULL, NULL, NULL, 0, &pem,
  52296. &pLen), 0);
  52297. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(ec, NULL, NULL, 0, NULL,
  52298. &pLen), 0);
  52299. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(ec, NULL, NULL, 0, &pem,
  52300. NULL), 0);
  52301. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(ec, NULL, NULL, 0, &pem,
  52302. &pLen), 1);
  52303. ExpectIntGT(pLen, 0);
  52304. XFREE(pem, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  52305. #endif
  52306. EC_KEY_free(ec);
  52307. ec = NULL;
  52308. /* PUBKEY */
  52309. ExpectNotNull(bio = BIO_new_file("./certs/ecc-client-keyPub.pem", "rb"));
  52310. ExpectNull((ec = PEM_read_bio_EC_PUBKEY(NULL, NULL, NULL, NULL)));
  52311. ec2 = NULL;
  52312. ExpectNotNull((ec = PEM_read_bio_EC_PUBKEY(bio, &ec2, NULL, NULL)));
  52313. ExpectIntEQ(ec == ec2, 1);
  52314. ExpectIntEQ(wc_ecc_size((ecc_key*)ec->internal), 32);
  52315. ExpectIntEQ(PEM_write_bio_EC_PUBKEY(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52316. BIO_free(bio);
  52317. bio = NULL;
  52318. /* Test 0x30, 0x00 fails. */
  52319. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_key_bad_1,
  52320. sizeof(ec_key_bad_1)));
  52321. ExpectNull(PEM_read_bio_EC_PUBKEY(bio, NULL, NULL, NULL));
  52322. BIO_free(bio);
  52323. bio = NULL;
  52324. /* Private key data - fail. */
  52325. ExpectNotNull(bio = BIO_new_file("./certs/ecc-key.pem", "rb"));
  52326. ExpectNull(PEM_read_bio_EC_PUBKEY(bio, NULL, NULL, NULL));
  52327. BIO_free(bio);
  52328. bio = NULL;
  52329. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  52330. ExpectIntEQ(PEM_write_bio_EC_PUBKEY(bio, ec), WOLFSSL_SUCCESS);
  52331. BIO_free(bio);
  52332. bio = NULL;
  52333. /* Same test as above, but with a file pointer rather than a BIO. */
  52334. ExpectIntEQ(PEM_write_EC_PUBKEY(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52335. ExpectIntEQ(PEM_write_EC_PUBKEY(NULL, ec), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52336. ExpectIntEQ(PEM_write_EC_PUBKEY(stderr, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52337. ExpectIntEQ(PEM_write_EC_PUBKEY(stderr, ec), WOLFSSL_SUCCESS);
  52338. EC_KEY_free(ec);
  52339. ec = NULL;
  52340. #ifndef NO_RSA
  52341. /* ensure that non-ec keys do not work */
  52342. ExpectNotNull(bio = BIO_new_file(svrKeyFile, "rb")); /* rsa key */
  52343. ExpectNull((ec = PEM_read_bio_ECPrivateKey(bio, NULL, NULL, NULL)));
  52344. ExpectNull((ec = PEM_read_bio_EC_PUBKEY(bio, NULL, NULL, NULL)));
  52345. BIO_free(bio);
  52346. bio = NULL;
  52347. EC_KEY_free(ec);
  52348. ec = NULL;
  52349. #endif /* !NO_RSA */
  52350. /* Test 0x30, 0x00 fails. */
  52351. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_priv_key_bad_1,
  52352. sizeof(ec_priv_key_bad_1)));
  52353. ExpectNull(PEM_read_bio_ECPrivateKey(bio, NULL, NULL, NULL));
  52354. BIO_free(bio);
  52355. bio = NULL;
  52356. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) */
  52357. return EXPECT_RESULT();
  52358. }
  52359. static int test_wolfSSL_PEM_PUBKEY(void)
  52360. {
  52361. EXPECT_DECLS;
  52362. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  52363. BIO* bio = NULL;
  52364. EVP_PKEY* pkey = NULL;
  52365. /* test creating new EVP_PKEY with bad arg */
  52366. ExpectNull((pkey = PEM_read_bio_PUBKEY(NULL, NULL, NULL, NULL)));
  52367. /* test loading ECC key using BIO */
  52368. #if defined(HAVE_ECC) && !defined(NO_FILESYSTEM)
  52369. {
  52370. XFILE file = XBADFILE;
  52371. const char* fname = "./certs/ecc-client-keyPub.pem";
  52372. size_t sz = 0;
  52373. byte* buf = NULL;
  52374. EVP_PKEY* pkey2 = NULL;
  52375. EC_KEY* ec_key = NULL;
  52376. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  52377. ExpectIntEQ(XFSEEK(file, 0, XSEEK_END), 0);
  52378. ExpectIntGT(sz = XFTELL(file), 0);
  52379. ExpectIntEQ(XFSEEK(file, 0, XSEEK_SET), 0);
  52380. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  52381. if (buf != NULL) {
  52382. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  52383. }
  52384. if (file != XBADFILE) {
  52385. XFCLOSE(file);
  52386. }
  52387. /* Test using BIO new mem and loading PEM private key */
  52388. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  52389. ExpectNotNull((pkey = PEM_read_bio_PUBKEY(bio, NULL, NULL, NULL)));
  52390. BIO_free(bio);
  52391. bio = NULL;
  52392. EVP_PKEY_free(pkey);
  52393. pkey = NULL;
  52394. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  52395. ExpectNotNull(pkey = EVP_PKEY_new());
  52396. ExpectPtrEq(PEM_read_bio_PUBKEY(bio, &pkey, NULL, NULL), pkey);
  52397. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  52398. BIO_free(bio);
  52399. bio = NULL;
  52400. /* Qt unit test case*/
  52401. ExpectNotNull(pkey2 = EVP_PKEY_new());
  52402. ExpectNotNull(ec_key = EVP_PKEY_get1_EC_KEY(pkey));
  52403. ExpectIntEQ(EVP_PKEY_set1_EC_KEY(pkey2, ec_key), WOLFSSL_SUCCESS);
  52404. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  52405. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey2), 1/* match */);
  52406. #else
  52407. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey2), 0);
  52408. #endif
  52409. EC_KEY_free(ec_key);
  52410. EVP_PKEY_free(pkey2);
  52411. EVP_PKEY_free(pkey);
  52412. pkey = NULL;
  52413. }
  52414. #endif
  52415. (void)bio;
  52416. (void)pkey;
  52417. #endif
  52418. return EXPECT_RESULT();
  52419. }
  52420. #endif /* !NO_BIO */
  52421. static int test_DSA_do_sign_verify(void)
  52422. {
  52423. EXPECT_DECLS;
  52424. #if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  52425. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && \
  52426. !defined(NO_DSA)
  52427. unsigned char digest[WC_SHA_DIGEST_SIZE];
  52428. DSA_SIG* sig = NULL;
  52429. DSA* dsa = NULL;
  52430. word32 bytes;
  52431. byte sigBin[DSA_SIG_SIZE];
  52432. int dsacheck;
  52433. #ifdef USE_CERT_BUFFERS_1024
  52434. byte tmp[ONEK_BUF];
  52435. XMEMSET(tmp, 0, sizeof(tmp));
  52436. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  52437. bytes = sizeof_dsa_key_der_1024;
  52438. #elif defined(USE_CERT_BUFFERS_2048)
  52439. byte tmp[TWOK_BUF];
  52440. XMEMSET(tmp, 0, sizeof(tmp));
  52441. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  52442. bytes = sizeof_dsa_key_der_2048;
  52443. #else
  52444. byte tmp[TWOK_BUF];
  52445. XFILE fp = XBADFILE;
  52446. XMEMSET(tmp, 0, sizeof(tmp));
  52447. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb") != XBADFILE);
  52448. ExpectIntGT(bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), fp), 0);
  52449. if (fp != XBADFILE)
  52450. XFCLOSE(fp);
  52451. #endif /* END USE_CERT_BUFFERS_1024 */
  52452. XMEMSET(digest, 202, sizeof(digest));
  52453. ExpectNotNull(dsa = DSA_new());
  52454. ExpectIntEQ(DSA_LoadDer(dsa, tmp, (int)bytes), 1);
  52455. ExpectIntEQ(wolfSSL_DSA_do_sign(digest, sigBin, dsa), 1);
  52456. ExpectIntEQ(wolfSSL_DSA_do_verify(digest, sigBin, dsa, &dsacheck), 1);
  52457. ExpectNotNull(sig = DSA_do_sign(digest, WC_SHA_DIGEST_SIZE, dsa));
  52458. ExpectIntEQ(DSA_do_verify(digest, WC_SHA_DIGEST_SIZE, sig, dsa), 1);
  52459. DSA_SIG_free(sig);
  52460. DSA_free(dsa);
  52461. #endif
  52462. #endif /* !HAVE_SELFTEST && !HAVE_FIPS */
  52463. return EXPECT_RESULT();
  52464. }
  52465. static int test_wolfSSL_tmp_dh(void)
  52466. {
  52467. EXPECT_DECLS;
  52468. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  52469. !defined(NO_RSA) && !defined(NO_DH) && !defined(NO_BIO)
  52470. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  52471. byte buff[6000];
  52472. static const unsigned char p[] = {
  52473. 0xb0, 0xa1, 0x08, 0x06, 0x9c, 0x08, 0x13, 0xba,
  52474. 0x59, 0x06, 0x3c, 0xbc, 0x30, 0xd5, 0xf5, 0x00,
  52475. 0xc1, 0x4f, 0x44, 0xa7, 0xd6, 0xef, 0x4a, 0xc6,
  52476. 0x25, 0x27, 0x1c, 0xe8, 0xd2, 0x96, 0x53, 0x0a,
  52477. 0x5c, 0x91, 0xdd, 0xa2, 0xc2, 0x94, 0x84, 0xbf,
  52478. 0x7d, 0xb2, 0x44, 0x9f, 0x9b, 0xd2, 0xc1, 0x8a,
  52479. 0xc5, 0xbe, 0x72, 0x5c, 0xa7, 0xe7, 0x91, 0xe6,
  52480. 0xd4, 0x9f, 0x73, 0x07, 0x85, 0x5b, 0x66, 0x48,
  52481. 0xc7, 0x70, 0xfa, 0xb4, 0xee, 0x02, 0xc9, 0x3d,
  52482. 0x9a, 0x4a, 0xda, 0x3d, 0xc1, 0x46, 0x3e, 0x19,
  52483. 0x69, 0xd1, 0x17, 0x46, 0x07, 0xa3, 0x4d, 0x9f,
  52484. 0x2b, 0x96, 0x17, 0x39, 0x6d, 0x30, 0x8d, 0x2a,
  52485. 0xf3, 0x94, 0xd3, 0x75, 0xcf, 0xa0, 0x75, 0xe6,
  52486. 0xf2, 0x92, 0x1f, 0x1a, 0x70, 0x05, 0xaa, 0x04,
  52487. 0x83, 0x57, 0x30, 0xfb, 0xda, 0x76, 0x93, 0x38,
  52488. 0x50, 0xe8, 0x27, 0xfd, 0x63, 0xee, 0x3c, 0xe5,
  52489. 0xb7, 0xc8, 0x09, 0xae, 0x6f, 0x50, 0x35, 0x8e,
  52490. 0x84, 0xce, 0x4a, 0x00, 0xe9, 0x12, 0x7e, 0x5a,
  52491. 0x31, 0xd7, 0x33, 0xfc, 0x21, 0x13, 0x76, 0xcc,
  52492. 0x16, 0x30, 0xdb, 0x0c, 0xfc, 0xc5, 0x62, 0xa7,
  52493. 0x35, 0xb8, 0xef, 0xb7, 0xb0, 0xac, 0xc0, 0x36,
  52494. 0xf6, 0xd9, 0xc9, 0x46, 0x48, 0xf9, 0x40, 0x90,
  52495. 0x00, 0x2b, 0x1b, 0xaa, 0x6c, 0xe3, 0x1a, 0xc3,
  52496. 0x0b, 0x03, 0x9e, 0x1b, 0xc2, 0x46, 0xe4, 0x48,
  52497. 0x4e, 0x22, 0x73, 0x6f, 0xc3, 0x5f, 0xd4, 0x9a,
  52498. 0xd6, 0x30, 0x07, 0x48, 0xd6, 0x8c, 0x90, 0xab,
  52499. 0xd4, 0xf6, 0xf1, 0xe3, 0x48, 0xd3, 0x58, 0x4b,
  52500. 0xa6, 0xb9, 0xcd, 0x29, 0xbf, 0x68, 0x1f, 0x08,
  52501. 0x4b, 0x63, 0x86, 0x2f, 0x5c, 0x6b, 0xd6, 0xb6,
  52502. 0x06, 0x65, 0xf7, 0xa6, 0xdc, 0x00, 0x67, 0x6b,
  52503. 0xbb, 0xc3, 0xa9, 0x41, 0x83, 0xfb, 0xc7, 0xfa,
  52504. 0xc8, 0xe2, 0x1e, 0x7e, 0xaf, 0x00, 0x3f, 0x93
  52505. };
  52506. int pSz = (int)sizeof(p);
  52507. #if !defined(WOLFSSL_OLD_PRIME_CHECK) && !defined(HAVE_FIPS) && \
  52508. !defined(HAVE_SELFTEST)
  52509. static const unsigned char bad_p[] = {
  52510. 0xb0, 0xa1, 0x08, 0x06, 0x9c, 0x08, 0x13, 0xba,
  52511. 0x59, 0x06, 0x3c, 0xbc, 0x30, 0xd5, 0xf5, 0x00,
  52512. 0xc1, 0x4f, 0x44, 0xa7, 0xd6, 0xef, 0x4a, 0xc6,
  52513. 0x25, 0x27, 0x1c, 0xe8, 0xd2, 0x96, 0x53, 0x0a,
  52514. 0x5c, 0x91, 0xdd, 0xa2, 0xc2, 0x94, 0x84, 0xbf,
  52515. 0x7d, 0xb2, 0x44, 0x9f, 0x9b, 0xd2, 0xc1, 0x8a,
  52516. 0xc5, 0xbe, 0x72, 0x5c, 0xa7, 0xe7, 0x91, 0xe6,
  52517. 0xd4, 0x9f, 0x73, 0x07, 0x85, 0x5b, 0x66, 0x48,
  52518. 0xc7, 0x70, 0xfa, 0xb4, 0xee, 0x02, 0xc9, 0x3d,
  52519. 0x9a, 0x4a, 0xda, 0x3d, 0xc1, 0x46, 0x3e, 0x19,
  52520. 0x69, 0xd1, 0x17, 0x46, 0x07, 0xa3, 0x4d, 0x9f,
  52521. 0x2b, 0x96, 0x17, 0x39, 0x6d, 0x30, 0x8d, 0x2a,
  52522. 0xf3, 0x94, 0xd3, 0x75, 0xcf, 0xa0, 0x75, 0xe6,
  52523. 0xf2, 0x92, 0x1f, 0x1a, 0x70, 0x05, 0xaa, 0x04,
  52524. 0x83, 0x57, 0x30, 0xfb, 0xda, 0x76, 0x93, 0x38,
  52525. 0x50, 0xe8, 0x27, 0xfd, 0x63, 0xee, 0x3c, 0xe5,
  52526. 0xb7, 0xc8, 0x09, 0xae, 0x6f, 0x50, 0x35, 0x8e,
  52527. 0x84, 0xce, 0x4a, 0x00, 0xe9, 0x12, 0x7e, 0x5a,
  52528. 0x31, 0xd7, 0x33, 0xfc, 0x21, 0x13, 0x76, 0xcc,
  52529. 0x16, 0x30, 0xdb, 0x0c, 0xfc, 0xc5, 0x62, 0xa7,
  52530. 0x35, 0xb8, 0xef, 0xb7, 0xb0, 0xac, 0xc0, 0x36,
  52531. 0xf6, 0xd9, 0xc9, 0x46, 0x48, 0xf9, 0x40, 0x90,
  52532. 0x00, 0x2b, 0x1b, 0xaa, 0x6c, 0xe3, 0x1a, 0xc3,
  52533. 0x0b, 0x03, 0x9e, 0x1b, 0xc2, 0x46, 0xe4, 0x48,
  52534. 0x4e, 0x22, 0x73, 0x6f, 0xc3, 0x5f, 0xd4, 0x9a,
  52535. 0xd6, 0x30, 0x07, 0x48, 0xd6, 0x8c, 0x90, 0xab,
  52536. 0xd4, 0xf6, 0xf1, 0xe3, 0x48, 0xd3, 0x58, 0x4b,
  52537. 0xa6, 0xb9, 0xcd, 0x29, 0xbf, 0x68, 0x1f, 0x08,
  52538. 0x4b, 0x63, 0x86, 0x2f, 0x5c, 0x6b, 0xd6, 0xb6,
  52539. 0x06, 0x65, 0xf7, 0xa6, 0xdc, 0x00, 0x67, 0x6b,
  52540. 0xbb, 0xc3, 0xa9, 0x41, 0x83, 0xfb, 0xc7, 0xfa,
  52541. 0xc8, 0xe2, 0x1e, 0x7e, 0xaf, 0x00, 0x3f, 0x91
  52542. };
  52543. #endif
  52544. static const unsigned char g[] = { 0x02 };
  52545. int gSz = (int)sizeof(g);
  52546. #if !defined(NO_DSA)
  52547. char file[] = "./certs/dsaparams.pem";
  52548. DSA* dsa = NULL;
  52549. #else
  52550. char file[] = "./certs/dh2048.pem";
  52551. #endif
  52552. XFILE f = XBADFILE;
  52553. int bytes = 0;
  52554. DH* dh = NULL;
  52555. DH* dh2 = NULL;
  52556. BIO* bio = NULL;
  52557. SSL* ssl = NULL;
  52558. SSL_CTX* ctx = NULL;
  52559. #ifndef NO_WOLFSSL_CLIENT
  52560. SSL* ssl_c = NULL;
  52561. SSL_CTX* ctx_c = NULL;
  52562. #endif
  52563. #ifndef NO_WOLFSSL_SERVER
  52564. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  52565. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  52566. WOLFSSL_FILETYPE_PEM));
  52567. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  52568. WOLFSSL_FILETYPE_PEM));
  52569. ExpectNotNull(ssl = SSL_new(ctx));
  52570. #endif
  52571. #ifndef NO_WOLFSSL_CLIENT
  52572. ExpectNotNull(ctx_c = SSL_CTX_new(wolfSSLv23_client_method()));
  52573. ExpectTrue(SSL_CTX_use_certificate_file(ctx_c, svrCertFile,
  52574. WOLFSSL_FILETYPE_PEM));
  52575. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx_c, svrKeyFile,
  52576. WOLFSSL_FILETYPE_PEM));
  52577. ExpectNotNull(ssl_c = SSL_new(ctx_c));
  52578. #ifdef NO_WOLFSSL_SERVER
  52579. ctx = ctx_c;
  52580. ssl = ssl_c;
  52581. #endif
  52582. #endif
  52583. XMEMSET(buff, 0, sizeof(buff));
  52584. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  52585. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  52586. if (f != XBADFILE)
  52587. XFCLOSE(f);
  52588. ExpectNotNull(bio = BIO_new_mem_buf((void*)buff, bytes));
  52589. #if !defined(NO_DSA)
  52590. dsa = wolfSSL_PEM_read_bio_DSAparams(bio, NULL, NULL, NULL);
  52591. ExpectNotNull(dsa);
  52592. dh = wolfSSL_DSA_dup_DH(dsa);
  52593. #else
  52594. dh = wolfSSL_PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
  52595. #endif
  52596. ExpectNotNull(dh);
  52597. #if defined(WOLFSSL_DH_EXTRA) && \
  52598. (defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || defined(WOLFSSL_OPENSSH))
  52599. ExpectNotNull(dh2 = wolfSSL_DH_dup(dh));
  52600. DH_free(dh2);
  52601. dh2 = NULL;
  52602. #endif
  52603. /* Failure cases */
  52604. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(NULL, NULL, 0, NULL, 0),
  52605. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52606. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx , NULL, 0, NULL, 0),
  52607. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52608. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(NULL, p , 0, NULL, 0),
  52609. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52610. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(NULL, NULL, 0, g , 0),
  52611. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52612. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx , p , 0, NULL, 0),
  52613. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52614. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx , NULL, 0, g , 0),
  52615. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52616. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(NULL, p , 0, g , 0),
  52617. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52618. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx , p , 1, g , 1),
  52619. WC_NO_ERR_TRACE(DH_KEY_SIZE_E));
  52620. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx , buff, 6000, g , 1),
  52621. WC_NO_ERR_TRACE(DH_KEY_SIZE_E));
  52622. #if !defined(WOLFSSL_OLD_PRIME_CHECK) && !defined(HAVE_FIPS) && \
  52623. !defined(HAVE_SELFTEST)
  52624. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx, bad_p, pSz, g, gSz),
  52625. WC_NO_ERR_TRACE(DH_CHECK_PUB_E));
  52626. #endif
  52627. ExpectIntEQ((int)wolfSSL_SetTmpDH(NULL, NULL, 0, NULL, 0),
  52628. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52629. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl , NULL, 0, NULL, 0),
  52630. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52631. ExpectIntEQ((int)wolfSSL_SetTmpDH(NULL, p , 0, NULL, 0),
  52632. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52633. ExpectIntEQ((int)wolfSSL_SetTmpDH(NULL, NULL, 0, g , 0),
  52634. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52635. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl , p , 0, NULL, 0),
  52636. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52637. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl , NULL, 0, g , 0),
  52638. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52639. ExpectIntEQ((int)wolfSSL_SetTmpDH(NULL, p , 0, g , 0),
  52640. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52641. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl , p , 1, g , 1),
  52642. WC_NO_ERR_TRACE(DH_KEY_SIZE_E));
  52643. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl , buff, 6000, g , 1),
  52644. WC_NO_ERR_TRACE(DH_KEY_SIZE_E));
  52645. #if !defined(WOLFSSL_OLD_PRIME_CHECK) && !defined(HAVE_FIPS) && \
  52646. !defined(HAVE_SELFTEST)
  52647. #ifndef NO_WOLFSSL_SERVER
  52648. /* Parameters will be tested later so it passes now. */
  52649. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl, bad_p, pSz, g, gSz),
  52650. WOLFSSL_SUCCESS);
  52651. #endif
  52652. #endif
  52653. #ifndef NO_WOLFSSL_CLIENT
  52654. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl_c, p, pSz, g, gSz),
  52655. WC_NO_ERR_TRACE(SIDE_ERROR));
  52656. #endif
  52657. ExpectIntEQ((int)SSL_CTX_set_tmp_dh(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52658. ExpectIntEQ((int)SSL_CTX_set_tmp_dh(ctx , NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52659. ExpectIntEQ((int)SSL_CTX_set_tmp_dh(NULL, dh ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52660. ExpectIntEQ((int)SSL_set_tmp_dh(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52661. ExpectIntEQ((int)SSL_set_tmp_dh(ssl , NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52662. ExpectIntEQ((int)SSL_set_tmp_dh(NULL, dh ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52663. /* No p/g to use. */
  52664. dh2 = wolfSSL_DH_new();
  52665. ExpectIntEQ((int)SSL_CTX_set_tmp_dh(ctx , dh2 ), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  52666. ExpectIntEQ((int)SSL_set_tmp_dh(ssl , dh2 ), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  52667. DH_free(dh2);
  52668. dh2 = NULL;
  52669. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx, p, pSz, g, gSz),
  52670. WOLFSSL_SUCCESS);
  52671. ExpectIntEQ((int)SSL_CTX_set_tmp_dh(ctx, dh), WOLFSSL_SUCCESS);
  52672. #ifndef NO_WOLFSSL_SERVER
  52673. ExpectIntEQ((int)SSL_set_tmp_dh(ssl, dh), WOLFSSL_SUCCESS);
  52674. #else
  52675. ExpectIntEQ((int)SSL_set_tmp_dh(ssl, dh), WC_NO_ERR_TRACE(SIDE_ERROR));
  52676. #endif
  52677. BIO_free(bio);
  52678. #if !defined(NO_DSA)
  52679. DSA_free(dsa);
  52680. #endif
  52681. DH_free(dh);
  52682. dh = NULL;
  52683. #ifndef NO_WOLFSSL_CLIENT
  52684. if (ssl != ssl_c) {
  52685. SSL_free(ssl_c);
  52686. }
  52687. #endif
  52688. SSL_free(ssl);
  52689. #ifndef NO_WOLFSSL_CLIENT
  52690. if (ctx != ctx_c) {
  52691. SSL_CTX_free(ctx_c);
  52692. }
  52693. #endif
  52694. SSL_CTX_free(ctx);
  52695. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  52696. #endif
  52697. return EXPECT_RESULT();
  52698. }
  52699. static int test_wolfSSL_ctrl(void)
  52700. {
  52701. EXPECT_DECLS;
  52702. #if defined (OPENSSL_EXTRA) && !defined(NO_BIO)
  52703. byte buff[6000];
  52704. BIO* bio = NULL;
  52705. int bytes;
  52706. BUF_MEM* ptr = NULL;
  52707. XMEMSET(buff, 0, sizeof(buff));
  52708. bytes = sizeof(buff);
  52709. ExpectNotNull(bio = BIO_new_mem_buf((void*)buff, bytes));
  52710. ExpectNotNull(BIO_s_socket());
  52711. ExpectIntEQ((int)wolfSSL_BIO_get_mem_ptr(bio, &ptr), WOLFSSL_SUCCESS);
  52712. /* needs tested after stubs filled out @TODO
  52713. SSL_ctrl
  52714. SSL_CTX_ctrl
  52715. */
  52716. BIO_free(bio);
  52717. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_BIO) */
  52718. return EXPECT_RESULT();
  52719. }
  52720. static int test_wolfSSL_EVP_PKEY_new_mac_key(void)
  52721. {
  52722. EXPECT_DECLS;
  52723. #ifdef OPENSSL_EXTRA
  52724. static const unsigned char pw[] = "password";
  52725. static const int pwSz = sizeof(pw) - 1;
  52726. size_t checkPwSz = 0;
  52727. const unsigned char* checkPw = NULL;
  52728. WOLFSSL_EVP_PKEY* key = NULL;
  52729. ExpectNull(key = wolfSSL_EVP_PKEY_new_mac_key(0, NULL, pw, pwSz));
  52730. ExpectNull(key = wolfSSL_EVP_PKEY_new_mac_key(0, NULL, NULL, pwSz));
  52731. ExpectNotNull(key = wolfSSL_EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, pw,
  52732. pwSz));
  52733. if (key != NULL) {
  52734. ExpectIntEQ(key->type, EVP_PKEY_HMAC);
  52735. ExpectIntEQ(key->save_type, EVP_PKEY_HMAC);
  52736. ExpectIntEQ(key->pkey_sz, pwSz);
  52737. ExpectIntEQ(XMEMCMP(key->pkey.ptr, pw, pwSz), 0);
  52738. }
  52739. ExpectNotNull(checkPw = wolfSSL_EVP_PKEY_get0_hmac(key, &checkPwSz));
  52740. ExpectIntEQ((int)checkPwSz, pwSz);
  52741. ExpectIntEQ(XMEMCMP(checkPw, pw, pwSz), 0);
  52742. wolfSSL_EVP_PKEY_free(key);
  52743. key = NULL;
  52744. ExpectNotNull(key = wolfSSL_EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, pw,
  52745. 0));
  52746. ExpectIntEQ(key->pkey_sz, 0);
  52747. if (EXPECT_SUCCESS()) {
  52748. /* Allocation for key->pkey.ptr may fail - OK key len is 0 */
  52749. checkPw = wolfSSL_EVP_PKEY_get0_hmac(key, &checkPwSz);
  52750. }
  52751. ExpectTrue((checkPwSz == 0) || (checkPw != NULL));
  52752. ExpectIntEQ((int)checkPwSz, 0);
  52753. wolfSSL_EVP_PKEY_free(key);
  52754. key = NULL;
  52755. ExpectNotNull(key = wolfSSL_EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, NULL,
  52756. 0));
  52757. ExpectIntEQ(key->pkey_sz, 0);
  52758. if (EXPECT_SUCCESS()) {
  52759. /* Allocation for key->pkey.ptr may fail - OK key len is 0 */
  52760. checkPw = wolfSSL_EVP_PKEY_get0_hmac(key, &checkPwSz);
  52761. }
  52762. ExpectTrue((checkPwSz == 0) || (checkPw != NULL));
  52763. ExpectIntEQ((int)checkPwSz, 0);
  52764. wolfSSL_EVP_PKEY_free(key);
  52765. key = NULL;
  52766. #endif /* OPENSSL_EXTRA */
  52767. return EXPECT_RESULT();
  52768. }
  52769. static int test_wolfSSL_EVP_PKEY_new_CMAC_key(void)
  52770. {
  52771. EXPECT_DECLS;
  52772. #ifdef OPENSSL_EXTRA
  52773. #if defined(WOLFSSL_CMAC) && !defined(NO_AES) && defined(WOLFSSL_AES_DIRECT)
  52774. const char *priv = "ABCDEFGHIJKLMNOP";
  52775. const WOLFSSL_EVP_CIPHER* cipher = EVP_aes_128_cbc();
  52776. WOLFSSL_EVP_PKEY* key = NULL;
  52777. ExpectNull(key = wolfSSL_EVP_PKEY_new_CMAC_key(
  52778. NULL, NULL, AES_128_KEY_SIZE, cipher));
  52779. ExpectNull(key = wolfSSL_EVP_PKEY_new_CMAC_key(
  52780. NULL, (const unsigned char *)priv, 0, cipher));
  52781. ExpectNull(key = wolfSSL_EVP_PKEY_new_CMAC_key(
  52782. NULL, (const unsigned char *)priv, AES_128_KEY_SIZE, NULL));
  52783. ExpectNotNull(key = wolfSSL_EVP_PKEY_new_CMAC_key(
  52784. NULL, (const unsigned char *)priv, AES_128_KEY_SIZE, cipher));
  52785. wolfSSL_EVP_PKEY_free(key);
  52786. #endif /* WOLFSSL_CMAC && !NO_AES && WOLFSSL_AES_DIRECT */
  52787. #endif /* OPENSSL_EXTRA */
  52788. return EXPECT_RESULT();
  52789. }
  52790. static int test_wolfSSL_EVP_Digest(void)
  52791. {
  52792. EXPECT_DECLS;
  52793. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA256) && !defined(NO_PWDBASED)
  52794. const char* in = "abc";
  52795. int inLen = (int)XSTRLEN(in);
  52796. byte out[WC_SHA256_DIGEST_SIZE];
  52797. unsigned int outLen;
  52798. const char* expOut =
  52799. "\xBA\x78\x16\xBF\x8F\x01\xCF\xEA\x41\x41\x40\xDE\x5D\xAE\x22"
  52800. "\x23\xB0\x03\x61\xA3\x96\x17\x7A\x9C\xB4\x10\xFF\x61\xF2\x00"
  52801. "\x15\xAD";
  52802. ExpectIntEQ(wolfSSL_EVP_Digest((unsigned char*)in, inLen, out, &outLen,
  52803. "SHA256", NULL), 1);
  52804. ExpectIntEQ(outLen, WC_SHA256_DIGEST_SIZE);
  52805. ExpectIntEQ(XMEMCMP(out, expOut, WC_SHA256_DIGEST_SIZE), 0);
  52806. #endif /* OPEN_EXTRA && ! NO_SHA256 */
  52807. return EXPECT_RESULT();
  52808. }
  52809. static int test_wolfSSL_EVP_Digest_all(void)
  52810. {
  52811. EXPECT_DECLS;
  52812. #ifdef OPENSSL_EXTRA
  52813. const char* digests[] = {
  52814. #ifndef NO_MD5
  52815. "MD5",
  52816. #endif
  52817. #ifndef NO_SHA
  52818. "SHA",
  52819. #endif
  52820. #ifdef WOLFSSL_SHA224
  52821. "SHA224",
  52822. #endif
  52823. #ifndef NO_SHA256
  52824. "SHA256",
  52825. #endif
  52826. #ifdef WOLFSSL_SHA384
  52827. "SHA384",
  52828. #endif
  52829. #ifdef WOLFSSL_SHA512
  52830. "SHA512",
  52831. #endif
  52832. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  52833. "SHA512_224",
  52834. #endif
  52835. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  52836. "SHA512_256",
  52837. #endif
  52838. #ifdef WOLFSSL_SHA3
  52839. #ifndef WOLFSSL_NOSHA3_224
  52840. "SHA3_224",
  52841. #endif
  52842. #ifndef WOLFSSL_NOSHA3_256
  52843. "SHA3_256",
  52844. #endif
  52845. "SHA3_384",
  52846. #ifndef WOLFSSL_NOSHA3_512
  52847. "SHA3_512",
  52848. #endif
  52849. #endif /* WOLFSSL_SHA3 */
  52850. NULL
  52851. };
  52852. const char** d;
  52853. const unsigned char in[] = "abc";
  52854. int inLen = XSTR_SIZEOF(in);
  52855. byte out[WC_MAX_DIGEST_SIZE];
  52856. unsigned int outLen;
  52857. for (d = digests; *d != NULL; d++) {
  52858. ExpectIntEQ(EVP_Digest(in, inLen, out, &outLen, *d, NULL), 1);
  52859. ExpectIntGT(outLen, 0);
  52860. ExpectIntEQ(EVP_MD_size(*d), outLen);
  52861. }
  52862. #endif
  52863. return EXPECT_RESULT();
  52864. }
  52865. static int test_wolfSSL_EVP_MD_size(void)
  52866. {
  52867. EXPECT_DECLS;
  52868. #ifdef OPENSSL_EXTRA
  52869. WOLFSSL_EVP_MD_CTX mdCtx;
  52870. #ifdef WOLFSSL_SHA3
  52871. #ifndef WOLFSSL_NOSHA3_224
  52872. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52873. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA3_224"), 1);
  52874. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA3_224_DIGEST_SIZE);
  52875. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA3_224_BLOCK_SIZE);
  52876. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52877. #endif
  52878. #ifndef WOLFSSL_NOSHA3_256
  52879. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52880. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA3_256"), 1);
  52881. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA3_256_DIGEST_SIZE);
  52882. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA3_256_BLOCK_SIZE);
  52883. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52884. #endif
  52885. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52886. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA3_384"), 1);
  52887. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA3_384_DIGEST_SIZE);
  52888. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA3_384_BLOCK_SIZE);
  52889. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52890. #ifndef WOLFSSL_NOSHA3_512
  52891. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52892. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA3_512"), 1);
  52893. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA3_512_DIGEST_SIZE);
  52894. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA3_512_BLOCK_SIZE);
  52895. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52896. #endif
  52897. #endif /* WOLFSSL_SHA3 */
  52898. #ifndef NO_SHA256
  52899. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52900. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA256"), 1);
  52901. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52902. WC_SHA256_DIGEST_SIZE);
  52903. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52904. WC_SHA256_BLOCK_SIZE);
  52905. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA256_DIGEST_SIZE);
  52906. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA256_BLOCK_SIZE);
  52907. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52908. #endif
  52909. #ifndef NO_MD5
  52910. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52911. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "MD5"), 1);
  52912. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52913. WC_MD5_DIGEST_SIZE);
  52914. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52915. WC_MD5_BLOCK_SIZE);
  52916. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_MD5_DIGEST_SIZE);
  52917. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_MD5_BLOCK_SIZE);
  52918. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52919. #endif
  52920. #ifdef WOLFSSL_SHA224
  52921. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52922. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA224"), 1);
  52923. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52924. WC_SHA224_DIGEST_SIZE);
  52925. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52926. WC_SHA224_BLOCK_SIZE);
  52927. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA224_DIGEST_SIZE);
  52928. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA224_BLOCK_SIZE);
  52929. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52930. #endif
  52931. #ifdef WOLFSSL_SHA384
  52932. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52933. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA384"), 1);
  52934. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52935. WC_SHA384_DIGEST_SIZE);
  52936. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52937. WC_SHA384_BLOCK_SIZE);
  52938. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA384_DIGEST_SIZE);
  52939. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA384_BLOCK_SIZE);
  52940. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52941. #endif
  52942. #ifdef WOLFSSL_SHA512
  52943. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52944. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA512"), 1);
  52945. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52946. WC_SHA512_DIGEST_SIZE);
  52947. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52948. WC_SHA512_BLOCK_SIZE);
  52949. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA512_DIGEST_SIZE);
  52950. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA512_BLOCK_SIZE);
  52951. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52952. #endif
  52953. #ifndef NO_SHA
  52954. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52955. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA"), 1);
  52956. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52957. WC_SHA_DIGEST_SIZE);
  52958. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52959. WC_SHA_BLOCK_SIZE);
  52960. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA_DIGEST_SIZE);
  52961. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA_BLOCK_SIZE);
  52962. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52963. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52964. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA1"), 1);
  52965. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52966. WC_SHA_DIGEST_SIZE);
  52967. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  52968. WC_SHA_BLOCK_SIZE);
  52969. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA_DIGEST_SIZE);
  52970. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA_BLOCK_SIZE);
  52971. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52972. #endif
  52973. /* error case */
  52974. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52975. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, ""), 0);
  52976. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)), 0);
  52977. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), 0);
  52978. /* Cleanup is valid on uninit'ed struct */
  52979. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  52980. #endif /* OPENSSL_EXTRA */
  52981. return EXPECT_RESULT();
  52982. }
  52983. static int test_wolfSSL_EVP_MD_pkey_type(void)
  52984. {
  52985. EXPECT_DECLS;
  52986. #ifdef OPENSSL_EXTRA
  52987. const WOLFSSL_EVP_MD* md;
  52988. #ifndef NO_MD5
  52989. ExpectNotNull(md = EVP_md5());
  52990. ExpectIntEQ(EVP_MD_pkey_type(md), NID_md5WithRSAEncryption);
  52991. #endif
  52992. #ifndef NO_SHA
  52993. ExpectNotNull(md = EVP_sha1());
  52994. ExpectIntEQ(EVP_MD_pkey_type(md), NID_sha1WithRSAEncryption);
  52995. #endif
  52996. #ifdef WOLFSSL_SHA224
  52997. ExpectNotNull(md = EVP_sha224());
  52998. ExpectIntEQ(EVP_MD_pkey_type(md), NID_sha224WithRSAEncryption);
  52999. #endif
  53000. ExpectNotNull(md = EVP_sha256());
  53001. ExpectIntEQ(EVP_MD_pkey_type(md), NID_sha256WithRSAEncryption);
  53002. #ifdef WOLFSSL_SHA384
  53003. ExpectNotNull(md = EVP_sha384());
  53004. ExpectIntEQ(EVP_MD_pkey_type(md), NID_sha384WithRSAEncryption);
  53005. #endif
  53006. #ifdef WOLFSSL_SHA512
  53007. ExpectNotNull(md = EVP_sha512());
  53008. ExpectIntEQ(EVP_MD_pkey_type(md), NID_sha512WithRSAEncryption);
  53009. #endif
  53010. #endif
  53011. return EXPECT_RESULT();
  53012. }
  53013. #ifdef OPENSSL_EXTRA
  53014. static int test_hmac_signing(const WOLFSSL_EVP_MD *type, const byte* testKey,
  53015. size_t testKeySz, const char* testData, size_t testDataSz,
  53016. const byte* testResult, size_t testResultSz)
  53017. {
  53018. EXPECT_DECLS;
  53019. unsigned char check[WC_MAX_DIGEST_SIZE];
  53020. size_t checkSz = -1;
  53021. WOLFSSL_EVP_PKEY* key = NULL;
  53022. WOLFSSL_EVP_MD_CTX mdCtx;
  53023. ExpectNotNull(key = wolfSSL_EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL,
  53024. testKey, (int)testKeySz));
  53025. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53026. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, type, NULL, key), 1);
  53027. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData,
  53028. (unsigned int)testDataSz), 1);
  53029. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  53030. ExpectIntEQ((int)checkSz, (int)testResultSz);
  53031. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  53032. ExpectIntEQ((int)checkSz,(int)testResultSz);
  53033. ExpectIntEQ(XMEMCMP(testResult, check, testResultSz), 0);
  53034. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53035. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, type, NULL, key), 1);
  53036. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData,
  53037. (unsigned int)testDataSz), 1);
  53038. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, testResult, checkSz), 1);
  53039. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53040. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53041. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, type, NULL, key), 1);
  53042. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData, 4), 1);
  53043. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  53044. ExpectIntEQ((int)checkSz, (int)testResultSz);
  53045. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  53046. ExpectIntEQ((int)checkSz,(int)testResultSz);
  53047. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData + 4,
  53048. (unsigned int)testDataSz - 4), 1);
  53049. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  53050. ExpectIntEQ((int)checkSz,(int)testResultSz);
  53051. ExpectIntEQ(XMEMCMP(testResult, check, testResultSz), 0);
  53052. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53053. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, type, NULL, key), 1);
  53054. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData, 4), 1);
  53055. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData + 4,
  53056. (unsigned int)testDataSz - 4), 1);
  53057. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, testResult, checkSz), 1);
  53058. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53059. wolfSSL_EVP_PKEY_free(key);
  53060. return EXPECT_RESULT();
  53061. }
  53062. #endif
  53063. static int test_wolfSSL_EVP_MD_hmac_signing(void)
  53064. {
  53065. EXPECT_DECLS;
  53066. #ifdef OPENSSL_EXTRA
  53067. static const unsigned char testKey[] =
  53068. {
  53069. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  53070. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  53071. 0x0b, 0x0b, 0x0b, 0x0b
  53072. };
  53073. static const char testData[] = "Hi There";
  53074. #ifdef WOLFSSL_SHA224
  53075. static const unsigned char testResultSha224[] =
  53076. {
  53077. 0x89, 0x6f, 0xb1, 0x12, 0x8a, 0xbb, 0xdf, 0x19,
  53078. 0x68, 0x32, 0x10, 0x7c, 0xd4, 0x9d, 0xf3, 0x3f,
  53079. 0x47, 0xb4, 0xb1, 0x16, 0x99, 0x12, 0xba, 0x4f,
  53080. 0x53, 0x68, 0x4b, 0x22
  53081. };
  53082. #endif
  53083. #ifndef NO_SHA256
  53084. static const unsigned char testResultSha256[] =
  53085. {
  53086. 0xb0, 0x34, 0x4c, 0x61, 0xd8, 0xdb, 0x38, 0x53,
  53087. 0x5c, 0xa8, 0xaf, 0xce, 0xaf, 0x0b, 0xf1, 0x2b,
  53088. 0x88, 0x1d, 0xc2, 0x00, 0xc9, 0x83, 0x3d, 0xa7,
  53089. 0x26, 0xe9, 0x37, 0x6c, 0x2e, 0x32, 0xcf, 0xf7
  53090. };
  53091. #endif
  53092. #ifdef WOLFSSL_SHA384
  53093. static const unsigned char testResultSha384[] =
  53094. {
  53095. 0xaf, 0xd0, 0x39, 0x44, 0xd8, 0x48, 0x95, 0x62,
  53096. 0x6b, 0x08, 0x25, 0xf4, 0xab, 0x46, 0x90, 0x7f,
  53097. 0x15, 0xf9, 0xda, 0xdb, 0xe4, 0x10, 0x1e, 0xc6,
  53098. 0x82, 0xaa, 0x03, 0x4c, 0x7c, 0xeb, 0xc5, 0x9c,
  53099. 0xfa, 0xea, 0x9e, 0xa9, 0x07, 0x6e, 0xde, 0x7f,
  53100. 0x4a, 0xf1, 0x52, 0xe8, 0xb2, 0xfa, 0x9c, 0xb6
  53101. };
  53102. #endif
  53103. #ifdef WOLFSSL_SHA512
  53104. static const unsigned char testResultSha512[] =
  53105. {
  53106. 0x87, 0xaa, 0x7c, 0xde, 0xa5, 0xef, 0x61, 0x9d,
  53107. 0x4f, 0xf0, 0xb4, 0x24, 0x1a, 0x1d, 0x6c, 0xb0,
  53108. 0x23, 0x79, 0xf4, 0xe2, 0xce, 0x4e, 0xc2, 0x78,
  53109. 0x7a, 0xd0, 0xb3, 0x05, 0x45, 0xe1, 0x7c, 0xde,
  53110. 0xda, 0xa8, 0x33, 0xb7, 0xd6, 0xb8, 0xa7, 0x02,
  53111. 0x03, 0x8b, 0x27, 0x4e, 0xae, 0xa3, 0xf4, 0xe4,
  53112. 0xbe, 0x9d, 0x91, 0x4e, 0xeb, 0x61, 0xf1, 0x70,
  53113. 0x2e, 0x69, 0x6c, 0x20, 0x3a, 0x12, 0x68, 0x54
  53114. };
  53115. #endif
  53116. #ifdef WOLFSSL_SHA3
  53117. #ifndef WOLFSSL_NOSHA3_224
  53118. static const unsigned char testResultSha3_224[] =
  53119. {
  53120. 0x3b, 0x16, 0x54, 0x6b, 0xbc, 0x7b, 0xe2, 0x70,
  53121. 0x6a, 0x03, 0x1d, 0xca, 0xfd, 0x56, 0x37, 0x3d,
  53122. 0x98, 0x84, 0x36, 0x76, 0x41, 0xd8, 0xc5, 0x9a,
  53123. 0xf3, 0xc8, 0x60, 0xf7
  53124. };
  53125. #endif
  53126. #ifndef WOLFSSL_NOSHA3_256
  53127. static const unsigned char testResultSha3_256[] =
  53128. {
  53129. 0xba, 0x85, 0x19, 0x23, 0x10, 0xdf, 0xfa, 0x96,
  53130. 0xe2, 0xa3, 0xa4, 0x0e, 0x69, 0x77, 0x43, 0x51,
  53131. 0x14, 0x0b, 0xb7, 0x18, 0x5e, 0x12, 0x02, 0xcd,
  53132. 0xcc, 0x91, 0x75, 0x89, 0xf9, 0x5e, 0x16, 0xbb
  53133. };
  53134. #endif
  53135. #ifndef WOLFSSL_NOSHA3_384
  53136. static const unsigned char testResultSha3_384[] =
  53137. {
  53138. 0x68, 0xd2, 0xdc, 0xf7, 0xfd, 0x4d, 0xdd, 0x0a,
  53139. 0x22, 0x40, 0xc8, 0xa4, 0x37, 0x30, 0x5f, 0x61,
  53140. 0xfb, 0x73, 0x34, 0xcf, 0xb5, 0xd0, 0x22, 0x6e,
  53141. 0x1b, 0xc2, 0x7d, 0xc1, 0x0a, 0x2e, 0x72, 0x3a,
  53142. 0x20, 0xd3, 0x70, 0xb4, 0x77, 0x43, 0x13, 0x0e,
  53143. 0x26, 0xac, 0x7e, 0x3d, 0x53, 0x28, 0x86, 0xbd
  53144. };
  53145. #endif
  53146. #ifndef WOLFSSL_NOSHA3_512
  53147. static const unsigned char testResultSha3_512[] =
  53148. {
  53149. 0xeb, 0x3f, 0xbd, 0x4b, 0x2e, 0xaa, 0xb8, 0xf5,
  53150. 0xc5, 0x04, 0xbd, 0x3a, 0x41, 0x46, 0x5a, 0xac,
  53151. 0xec, 0x15, 0x77, 0x0a, 0x7c, 0xab, 0xac, 0x53,
  53152. 0x1e, 0x48, 0x2f, 0x86, 0x0b, 0x5e, 0xc7, 0xba,
  53153. 0x47, 0xcc, 0xb2, 0xc6, 0xf2, 0xaf, 0xce, 0x8f,
  53154. 0x88, 0xd2, 0x2b, 0x6d, 0xc6, 0x13, 0x80, 0xf2,
  53155. 0x3a, 0x66, 0x8f, 0xd3, 0x88, 0x8b, 0xb8, 0x05,
  53156. 0x37, 0xc0, 0xa0, 0xb8, 0x64, 0x07, 0x68, 0x9e
  53157. };
  53158. #endif
  53159. #endif
  53160. #ifndef NO_SHA256
  53161. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha256(), testKey,
  53162. sizeof(testKey), testData, XSTRLEN(testData), testResultSha256,
  53163. sizeof(testResultSha256)), TEST_SUCCESS);
  53164. #endif
  53165. #ifdef WOLFSSL_SHA224
  53166. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha224(), testKey,
  53167. sizeof(testKey), testData, XSTRLEN(testData), testResultSha224,
  53168. sizeof(testResultSha224)), TEST_SUCCESS);
  53169. #endif
  53170. #ifdef WOLFSSL_SHA384
  53171. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha384(), testKey,
  53172. sizeof(testKey), testData, XSTRLEN(testData), testResultSha384,
  53173. sizeof(testResultSha384)), TEST_SUCCESS);
  53174. #endif
  53175. #ifdef WOLFSSL_SHA512
  53176. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha512(), testKey,
  53177. sizeof(testKey), testData, XSTRLEN(testData), testResultSha512,
  53178. sizeof(testResultSha512)), TEST_SUCCESS);
  53179. #endif
  53180. #ifdef WOLFSSL_SHA3
  53181. #ifndef WOLFSSL_NOSHA3_224
  53182. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha3_224(), testKey,
  53183. sizeof(testKey), testData, XSTRLEN(testData), testResultSha3_224,
  53184. sizeof(testResultSha3_224)), TEST_SUCCESS);
  53185. #endif
  53186. #ifndef WOLFSSL_NOSHA3_256
  53187. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha3_256(), testKey,
  53188. sizeof(testKey), testData, XSTRLEN(testData), testResultSha3_256,
  53189. sizeof(testResultSha3_256)), TEST_SUCCESS);
  53190. #endif
  53191. #ifndef WOLFSSL_NOSHA3_384
  53192. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha3_384(), testKey,
  53193. sizeof(testKey), testData, XSTRLEN(testData), testResultSha3_384,
  53194. sizeof(testResultSha3_384)), TEST_SUCCESS);
  53195. #endif
  53196. #ifndef WOLFSSL_NOSHA3_512
  53197. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha3_512(), testKey,
  53198. sizeof(testKey), testData, XSTRLEN(testData), testResultSha3_512,
  53199. sizeof(testResultSha3_512)), TEST_SUCCESS);
  53200. #endif
  53201. #endif
  53202. #endif /* OPENSSL_EXTRA */
  53203. return EXPECT_RESULT();
  53204. }
  53205. static int test_wolfSSL_EVP_MD_rsa_signing(void)
  53206. {
  53207. EXPECT_DECLS;
  53208. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(USE_CERT_BUFFERS_2048)
  53209. WOLFSSL_EVP_PKEY* privKey = NULL;
  53210. WOLFSSL_EVP_PKEY* pubKey = NULL;
  53211. WOLFSSL_EVP_PKEY_CTX* keyCtx = NULL;
  53212. const char testData[] = "Hi There";
  53213. WOLFSSL_EVP_MD_CTX mdCtx;
  53214. WOLFSSL_EVP_MD_CTX mdCtxCopy;
  53215. int ret;
  53216. size_t checkSz = -1;
  53217. int sz = 2048 / 8;
  53218. const unsigned char* cp;
  53219. const unsigned char* p;
  53220. unsigned char check[2048/8];
  53221. size_t i;
  53222. int paddings[] = {
  53223. RSA_PKCS1_PADDING,
  53224. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && defined(WC_RSA_PSS)
  53225. RSA_PKCS1_PSS_PADDING,
  53226. #endif
  53227. };
  53228. cp = client_key_der_2048;
  53229. ExpectNotNull((privKey = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, &cp,
  53230. sizeof_client_key_der_2048)));
  53231. p = client_keypub_der_2048;
  53232. ExpectNotNull((pubKey = wolfSSL_d2i_PUBKEY(NULL, &p,
  53233. sizeof_client_keypub_der_2048)));
  53234. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53235. wolfSSL_EVP_MD_CTX_init(&mdCtxCopy);
  53236. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  53237. NULL, privKey), 1);
  53238. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData,
  53239. (unsigned int)XSTRLEN(testData)), 1);
  53240. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  53241. ExpectIntEQ((int)checkSz, sz);
  53242. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  53243. ExpectIntEQ((int)checkSz,sz);
  53244. ExpectIntEQ(wolfSSL_EVP_MD_CTX_copy_ex(&mdCtxCopy, &mdCtx), 1);
  53245. ExpectIntEQ(wolfSSL_EVP_MD_CTX_copy_ex(&mdCtxCopy, &mdCtx), 1);
  53246. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtxCopy);
  53247. ExpectIntEQ(ret, 1);
  53248. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  53249. ExpectIntEQ(ret, 1);
  53250. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53251. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  53252. NULL, pubKey), 1);
  53253. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData,
  53254. (unsigned int)XSTRLEN(testData)),
  53255. 1);
  53256. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, check, checkSz), 1);
  53257. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  53258. ExpectIntEQ(ret, 1);
  53259. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53260. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  53261. NULL, privKey), 1);
  53262. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData, 4), 1);
  53263. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  53264. ExpectIntEQ((int)checkSz, sz);
  53265. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  53266. ExpectIntEQ((int)checkSz, sz);
  53267. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData + 4,
  53268. (unsigned int)XSTRLEN(testData) - 4), 1);
  53269. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  53270. ExpectIntEQ((int)checkSz, sz);
  53271. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  53272. ExpectIntEQ(ret, 1);
  53273. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53274. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  53275. NULL, pubKey), 1);
  53276. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData, 4), 1);
  53277. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData + 4,
  53278. (unsigned int)XSTRLEN(testData) - 4),
  53279. 1);
  53280. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, check, checkSz), 1);
  53281. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  53282. ExpectIntEQ(ret, 1);
  53283. /* Check all signing padding types */
  53284. for (i = 0; i < sizeof(paddings)/sizeof(int); i++) {
  53285. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53286. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, &keyCtx,
  53287. wolfSSL_EVP_sha256(), NULL, privKey), 1);
  53288. ExpectIntEQ(wolfSSL_EVP_PKEY_CTX_set_rsa_padding(keyCtx,
  53289. paddings[i]), 1);
  53290. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData,
  53291. (unsigned int)XSTRLEN(testData)), 1);
  53292. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  53293. ExpectIntEQ((int)checkSz, sz);
  53294. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  53295. ExpectIntEQ((int)checkSz,sz);
  53296. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  53297. ExpectIntEQ(ret, 1);
  53298. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53299. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, &keyCtx,
  53300. wolfSSL_EVP_sha256(), NULL, pubKey), 1);
  53301. ExpectIntEQ(wolfSSL_EVP_PKEY_CTX_set_rsa_padding(keyCtx,
  53302. paddings[i]), 1);
  53303. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData,
  53304. (unsigned int)XSTRLEN(testData)), 1);
  53305. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, check, checkSz), 1);
  53306. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  53307. ExpectIntEQ(ret, 1);
  53308. }
  53309. wolfSSL_EVP_PKEY_free(pubKey);
  53310. wolfSSL_EVP_PKEY_free(privKey);
  53311. #endif
  53312. return EXPECT_RESULT();
  53313. }
  53314. static int test_wolfSSL_EVP_MD_ecc_signing(void)
  53315. {
  53316. EXPECT_DECLS;
  53317. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  53318. WOLFSSL_EVP_PKEY* privKey = NULL;
  53319. WOLFSSL_EVP_PKEY* pubKey = NULL;
  53320. const char testData[] = "Hi There";
  53321. WOLFSSL_EVP_MD_CTX mdCtx;
  53322. int ret;
  53323. size_t checkSz = -1;
  53324. const unsigned char* cp;
  53325. const unsigned char* p;
  53326. unsigned char check[2048/8];
  53327. cp = ecc_clikey_der_256;
  53328. ExpectNotNull(privKey = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL, &cp,
  53329. sizeof_ecc_clikey_der_256));
  53330. p = ecc_clikeypub_der_256;
  53331. ExpectNotNull((pubKey = wolfSSL_d2i_PUBKEY(NULL, &p,
  53332. sizeof_ecc_clikeypub_der_256)));
  53333. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53334. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  53335. NULL, privKey), 1);
  53336. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData,
  53337. (unsigned int)XSTRLEN(testData)), 1);
  53338. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  53339. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  53340. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  53341. ExpectIntEQ(ret, 1);
  53342. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53343. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  53344. NULL, pubKey), 1);
  53345. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData,
  53346. (unsigned int)XSTRLEN(testData)),
  53347. 1);
  53348. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, check, checkSz), 1);
  53349. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  53350. ExpectIntEQ(ret, 1);
  53351. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53352. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  53353. NULL, privKey), 1);
  53354. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData, 4), 1);
  53355. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  53356. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  53357. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData + 4,
  53358. (unsigned int)XSTRLEN(testData) - 4), 1);
  53359. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  53360. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  53361. ExpectIntEQ(ret, 1);
  53362. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53363. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  53364. NULL, pubKey), 1);
  53365. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData, 4), 1);
  53366. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData + 4,
  53367. (unsigned int)XSTRLEN(testData) - 4),
  53368. 1);
  53369. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, check, checkSz), 1);
  53370. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  53371. ExpectIntEQ(ret, 1);
  53372. wolfSSL_EVP_PKEY_free(pubKey);
  53373. wolfSSL_EVP_PKEY_free(privKey);
  53374. #endif
  53375. return EXPECT_RESULT();
  53376. }
  53377. static int test_wolfSSL_CTX_add_extra_chain_cert(void)
  53378. {
  53379. EXPECT_DECLS;
  53380. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  53381. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_BIO)
  53382. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  53383. char caFile[] = "./certs/client-ca.pem";
  53384. char clientFile[] = "./certs/client-cert.pem";
  53385. SSL_CTX* ctx = NULL;
  53386. X509* x509 = NULL;
  53387. BIO *bio = NULL;
  53388. X509 *cert = NULL;
  53389. X509 *ca = NULL;
  53390. STACK_OF(X509) *chain = NULL;
  53391. STACK_OF(X509) *chain2 = NULL;
  53392. #ifndef NO_WOLFSSL_SERVER
  53393. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  53394. #else
  53395. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  53396. #endif
  53397. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(caFile,
  53398. WOLFSSL_FILETYPE_PEM));
  53399. /* Negative tests. */
  53400. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53401. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53402. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(NULL, x509), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53403. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(ctx, x509), WOLFSSL_SUCCESS);
  53404. ExpectNotNull(x509 = wolfSSL_X509_new());
  53405. /* Empty certificate. */
  53406. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(ctx, x509), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53407. wolfSSL_X509_free(x509);
  53408. x509 = NULL;
  53409. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(clientFile,
  53410. WOLFSSL_FILETYPE_PEM));
  53411. /* additional test of getting EVP_PKEY key size from X509
  53412. * Do not run with user RSA because wolfSSL_RSA_size is not currently
  53413. * allowed with user RSA */
  53414. {
  53415. EVP_PKEY* pkey = NULL;
  53416. #if defined(HAVE_ECC)
  53417. X509* ecX509 = NULL;
  53418. #endif /* HAVE_ECC */
  53419. ExpectNotNull(pkey = X509_get_pubkey(x509));
  53420. /* current RSA key is 2048 bit (256 bytes) */
  53421. ExpectIntEQ(EVP_PKEY_size(pkey), 256);
  53422. EVP_PKEY_free(pkey);
  53423. pkey = NULL;
  53424. #if defined(HAVE_ECC)
  53425. #if defined(USE_CERT_BUFFERS_256)
  53426. ExpectNotNull(ecX509 = wolfSSL_X509_load_certificate_buffer(
  53427. cliecc_cert_der_256, sizeof_cliecc_cert_der_256,
  53428. SSL_FILETYPE_ASN1));
  53429. #else
  53430. ExpectNotNull(ecX509 = wolfSSL_X509_load_certificate_file(
  53431. cliEccCertFile, SSL_FILETYPE_PEM));
  53432. #endif
  53433. pkey = X509_get_pubkey(ecX509);
  53434. ExpectNotNull(pkey);
  53435. /* current ECC key is 256 bit (32 bytes) */
  53436. ExpectIntEQ(EVP_PKEY_size(pkey), 32);
  53437. X509_free(ecX509);
  53438. ecX509 = NULL;
  53439. EVP_PKEY_free(pkey);
  53440. pkey = NULL;
  53441. #endif /* HAVE_ECC */
  53442. }
  53443. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(ctx, x509), SSL_SUCCESS);
  53444. if (EXPECT_SUCCESS()) {
  53445. x509 = NULL;
  53446. }
  53447. #ifdef WOLFSSL_ENCRYPTED_KEYS
  53448. ExpectNull(SSL_CTX_get_default_passwd_cb(ctx));
  53449. ExpectNull(SSL_CTX_get_default_passwd_cb_userdata(ctx));
  53450. #endif
  53451. SSL_CTX_free(ctx);
  53452. ctx = NULL;
  53453. #ifndef NO_WOLFSSL_SERVER
  53454. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  53455. #else
  53456. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  53457. #endif
  53458. /* Test haproxy use case */
  53459. ExpectNotNull(bio = BIO_new_file(svrCertFile, "r"));
  53460. /* Read Certificate */
  53461. ExpectNotNull(cert = PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL));
  53462. ExpectNotNull(ca = PEM_read_bio_X509(bio, NULL, NULL, NULL));
  53463. ExpectNotNull(chain = sk_X509_new_null());
  53464. ExpectIntEQ(sk_X509_push(chain, ca), 1);
  53465. if (EXPECT_SUCCESS()) {
  53466. ca = NULL;
  53467. }
  53468. ExpectNotNull(chain2 = X509_chain_up_ref(chain));
  53469. ExpectNotNull(ca = sk_X509_shift(chain2));
  53470. ExpectIntEQ(SSL_CTX_use_certificate(ctx, cert), 1);
  53471. ExpectIntEQ(SSL_CTX_add_extra_chain_cert(ctx, ca), 1);
  53472. if (EXPECT_SUCCESS()) {
  53473. ca = NULL;
  53474. }
  53475. BIO_free(bio);
  53476. X509_free(cert);
  53477. X509_free(ca);
  53478. X509_free(x509);
  53479. sk_X509_pop_free(chain, X509_free);
  53480. sk_X509_pop_free(chain2, X509_free);
  53481. SSL_CTX_free(ctx);
  53482. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  53483. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  53484. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined (NO_BIO) */
  53485. return EXPECT_RESULT();
  53486. }
  53487. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  53488. static int test_wolfSSL_ERR_peek_last_error_line(void)
  53489. {
  53490. EXPECT_DECLS;
  53491. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  53492. !defined(NO_FILESYSTEM) && defined(DEBUG_WOLFSSL) && \
  53493. !defined(NO_OLD_TLS) && !defined(WOLFSSL_NO_TLS12) && \
  53494. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(NO_ERROR_QUEUE)
  53495. callback_functions client_cb;
  53496. callback_functions server_cb;
  53497. int line = 0;
  53498. int flag = ERR_TXT_STRING;
  53499. const char* file = NULL;
  53500. const char* data = NULL;
  53501. /* create a failed connection and inspect the error */
  53502. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  53503. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  53504. client_cb.method = wolfTLSv1_1_client_method;
  53505. server_cb.method = wolfTLSv1_2_server_method;
  53506. test_wolfSSL_client_server_nofail(&client_cb, &server_cb);
  53507. ExpectIntGT(ERR_get_error_line_data(NULL, NULL, &data, &flag), 0);
  53508. ExpectNotNull(data);
  53509. /* check clearing error state */
  53510. ERR_remove_state(0);
  53511. ExpectIntEQ((int)ERR_peek_last_error_line(NULL, NULL), 0);
  53512. ERR_peek_last_error_line(NULL, &line);
  53513. ExpectIntEQ(line, 0);
  53514. ERR_peek_last_error_line(&file, NULL);
  53515. ExpectNull(file);
  53516. /* retry connection to fill error queue */
  53517. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  53518. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  53519. client_cb.method = wolfTLSv1_1_client_method;
  53520. server_cb.method = wolfTLSv1_2_server_method;
  53521. test_wolfSSL_client_server_nofail(&client_cb, &server_cb);
  53522. /* check that error code was stored */
  53523. ExpectIntNE((int)ERR_peek_last_error_line(NULL, NULL), 0);
  53524. ERR_peek_last_error_line(NULL, &line);
  53525. ExpectIntNE(line, 0);
  53526. ERR_peek_last_error_line(&file, NULL);
  53527. ExpectNotNull(file);
  53528. fprintf(stderr, "\nTesting error print out\n");
  53529. ERR_print_errors_fp(stderr);
  53530. fprintf(stderr, "Done testing print out\n\n");
  53531. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) &&
  53532. * !defined(NO_FILESYSTEM) && !defined(DEBUG_WOLFSSL) */
  53533. return EXPECT_RESULT();
  53534. }
  53535. #endif /* !NO_WOLFSSL_CLIENT && !NO_WOLFSSL_SERVER */
  53536. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  53537. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  53538. static int verify_cb(int ok, X509_STORE_CTX *ctx)
  53539. {
  53540. (void) ok;
  53541. (void) ctx;
  53542. fprintf(stderr, "ENTER verify_cb\n");
  53543. return SSL_SUCCESS;
  53544. }
  53545. #endif
  53546. static int test_wolfSSL_X509_Name_canon(void)
  53547. {
  53548. EXPECT_DECLS;
  53549. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  53550. !defined(NO_FILESYSTEM) && !defined(NO_SHA) && \
  53551. defined(WOLFSSL_CERT_GEN) && \
  53552. (defined(WOLFSSL_CERT_REQ) || defined(WOLFSSL_CERT_EXT)) && !defined(NO_RSA)
  53553. const long ex_hash1 = 0x0fdb2da4;
  53554. const long ex_hash2 = 0x9f3e8c9e;
  53555. X509_NAME *name = NULL;
  53556. X509 *x509 = NULL;
  53557. XFILE file = XBADFILE;
  53558. unsigned long hash = 0;
  53559. byte digest[WC_MAX_DIGEST_SIZE] = {0};
  53560. byte *pbuf = NULL;
  53561. word32 len = 0;
  53562. (void) ex_hash2;
  53563. ExpectTrue((file = XFOPEN(caCertFile, "rb")) != XBADFILE);
  53564. ExpectNotNull(x509 = PEM_read_X509(file, NULL, NULL, NULL));
  53565. ExpectNotNull(name = X509_get_issuer_name(x509));
  53566. /* When output buffer is NULL, should return necessary output buffer
  53567. * length.*/
  53568. ExpectIntGT(wolfSSL_i2d_X509_NAME_canon(name, NULL), 0);
  53569. ExpectIntGT((len = (word32)wolfSSL_i2d_X509_NAME_canon(name, &pbuf)), 0);
  53570. ExpectIntEQ(wc_ShaHash((const byte*)pbuf, (word32)len, digest), 0);
  53571. hash = (((unsigned long)digest[3] << 24) |
  53572. ((unsigned long)digest[2] << 16) |
  53573. ((unsigned long)digest[1] << 8) |
  53574. ((unsigned long)digest[0]));
  53575. ExpectIntEQ(hash, ex_hash1);
  53576. if (file != XBADFILE) {
  53577. XFCLOSE(file);
  53578. file = XBADFILE;
  53579. }
  53580. X509_free(x509);
  53581. x509 = NULL;
  53582. XFREE(pbuf, NULL, DYNAMIC_TYPE_OPENSSL);
  53583. pbuf = NULL;
  53584. ExpectTrue((file = XFOPEN(cliCertFile, "rb")) != XBADFILE);
  53585. ExpectNotNull(x509 = PEM_read_X509(file, NULL, NULL, NULL));
  53586. ExpectNotNull(name = X509_get_issuer_name(x509));
  53587. ExpectIntGT((len = (word32)wolfSSL_i2d_X509_NAME_canon(name, &pbuf)), 0);
  53588. ExpectIntEQ(wc_ShaHash((const byte*)pbuf, (word32)len, digest), 0);
  53589. hash = (((unsigned long)digest[3] << 24) |
  53590. ((unsigned long)digest[2] << 16) |
  53591. ((unsigned long)digest[1] << 8) |
  53592. ((unsigned long)digest[0]));
  53593. ExpectIntEQ(hash, ex_hash2);
  53594. if (file != XBADFILE)
  53595. XFCLOSE(file);
  53596. X509_free(x509);
  53597. XFREE(pbuf, NULL, DYNAMIC_TYPE_OPENSSL);
  53598. #endif
  53599. return EXPECT_RESULT();
  53600. }
  53601. static int test_wolfSSL_X509_LOOKUP_ctrl_hash_dir(void)
  53602. {
  53603. EXPECT_DECLS;
  53604. #if defined(OPENSSL_ALL) && !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_DIR)
  53605. const int MAX_DIR = 4;
  53606. const char paths[][32] = {
  53607. "./certs/ed25519",
  53608. "./certs/ecc",
  53609. "./certs/crl",
  53610. "./certs/",
  53611. };
  53612. char CertCrl_path[MAX_FILENAME_SZ];
  53613. char *p;
  53614. X509_STORE* str = NULL;
  53615. X509_LOOKUP* lookup = NULL;
  53616. WOLFSSL_STACK* sk = NULL;
  53617. int len, total_len, i;
  53618. (void)sk;
  53619. XMEMSET(CertCrl_path, 0, MAX_FILENAME_SZ);
  53620. /* illegal string */
  53621. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  53622. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  53623. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_ADD_DIR, "",
  53624. SSL_FILETYPE_PEM,NULL), 0);
  53625. /* free store */
  53626. X509_STORE_free(str);
  53627. str = NULL;
  53628. /* short folder string */
  53629. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  53630. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  53631. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_ADD_DIR, "./",
  53632. SSL_FILETYPE_PEM,NULL), 1);
  53633. #if defined(WOLFSSL_INT_H)
  53634. /* only available when including internal.h */
  53635. ExpectNotNull(sk = lookup->dirs->dir_entry);
  53636. #endif
  53637. /* free store */
  53638. X509_STORE_free(str);
  53639. str = NULL;
  53640. /* typical function check */
  53641. p = &CertCrl_path[0];
  53642. total_len = 0;
  53643. for (i = MAX_DIR - 1; i>=0 && total_len < MAX_FILENAME_SZ; i--) {
  53644. len = (int)XSTRLEN((const char*)&paths[i]);
  53645. total_len += len;
  53646. XSTRNCPY(p, paths[i], MAX_FILENAME_SZ - total_len);
  53647. p += len;
  53648. if (i != 0) *(p++) = SEPARATOR_CHAR;
  53649. }
  53650. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  53651. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  53652. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_ADD_DIR, CertCrl_path,
  53653. SSL_FILETYPE_PEM,NULL), 1);
  53654. #if defined(WOLFSSL_INT_H)
  53655. /* only available when including internal.h */
  53656. ExpectNotNull(sk = lookup->dirs->dir_entry);
  53657. #endif
  53658. X509_STORE_free(str);
  53659. #endif
  53660. return EXPECT_RESULT();
  53661. }
  53662. static int test_wolfSSL_X509_LOOKUP_ctrl_file(void)
  53663. {
  53664. EXPECT_DECLS;
  53665. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  53666. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && \
  53667. defined(WOLFSSL_SIGNER_DER_CERT)
  53668. X509_STORE_CTX* ctx = NULL;
  53669. X509_STORE* str = NULL;
  53670. X509_LOOKUP* lookup = NULL;
  53671. X509* cert1 = NULL;
  53672. X509* x509Ca = NULL;
  53673. X509* x509Svr = NULL;
  53674. X509* issuer = NULL;
  53675. WOLFSSL_STACK* sk = NULL;
  53676. X509_NAME* caName = NULL;
  53677. X509_NAME* issuerName = NULL;
  53678. XFILE file1 = XBADFILE;
  53679. int i;
  53680. int cert_count = 0;
  53681. int cmp;
  53682. char der[] = "certs/ca-cert.der";
  53683. #ifdef HAVE_CRL
  53684. char pem[][100] = {
  53685. "./certs/crl/crl.pem",
  53686. "./certs/crl/crl2.pem",
  53687. "./certs/crl/caEccCrl.pem",
  53688. "./certs/crl/eccCliCRL.pem",
  53689. "./certs/crl/eccSrvCRL.pem",
  53690. ""
  53691. };
  53692. #endif
  53693. ExpectTrue((file1 = XFOPEN("./certs/ca-cert.pem", "rb")) != XBADFILE);
  53694. ExpectNotNull(cert1 = wolfSSL_PEM_read_X509(file1, NULL, NULL, NULL));
  53695. if (file1 != XBADFILE)
  53696. XFCLOSE(file1);
  53697. ExpectNotNull(ctx = X509_STORE_CTX_new());
  53698. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  53699. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  53700. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_FILE_LOAD, caCertFile,
  53701. SSL_FILETYPE_PEM,NULL), 1);
  53702. ExpectNotNull(sk = wolfSSL_CertManagerGetCerts(str->cm));
  53703. ExpectIntEQ((cert_count = sk_X509_num(sk)), 1);
  53704. /* check if CA cert is loaded into the store */
  53705. for (i = 0; i < cert_count; i++) {
  53706. x509Ca = sk_X509_value(sk, i);
  53707. ExpectIntEQ(0, wolfSSL_X509_cmp(x509Ca, cert1));
  53708. }
  53709. ExpectNotNull((x509Svr =
  53710. wolfSSL_X509_load_certificate_file(svrCertFile, SSL_FILETYPE_PEM)));
  53711. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, x509Svr, NULL), SSL_SUCCESS);
  53712. ExpectNull(X509_STORE_CTX_get0_current_issuer(NULL));
  53713. issuer = X509_STORE_CTX_get0_current_issuer(ctx);
  53714. ExpectNotNull(issuer);
  53715. caName = X509_get_subject_name(x509Ca);
  53716. ExpectNotNull(caName);
  53717. issuerName = X509_get_subject_name(issuer);
  53718. ExpectNotNull(issuerName);
  53719. cmp = X509_NAME_cmp(caName, issuerName);
  53720. ExpectIntEQ(cmp, 0);
  53721. /* load der format */
  53722. X509_free(issuer);
  53723. issuer = NULL;
  53724. X509_STORE_CTX_free(ctx);
  53725. ctx = NULL;
  53726. X509_STORE_free(str);
  53727. str = NULL;
  53728. sk_X509_pop_free(sk, NULL);
  53729. sk = NULL;
  53730. X509_free(x509Svr);
  53731. x509Svr = NULL;
  53732. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  53733. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  53734. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_FILE_LOAD, der,
  53735. SSL_FILETYPE_ASN1,NULL), 1);
  53736. ExpectNotNull(sk = wolfSSL_CertManagerGetCerts(str->cm));
  53737. ExpectIntEQ((cert_count = sk_X509_num(sk)), 1);
  53738. /* check if CA cert is loaded into the store */
  53739. for (i = 0; i < cert_count; i++) {
  53740. x509Ca = sk_X509_value(sk, i);
  53741. ExpectIntEQ(0, wolfSSL_X509_cmp(x509Ca, cert1));
  53742. }
  53743. X509_STORE_free(str);
  53744. str = NULL;
  53745. sk_X509_pop_free(sk, NULL);
  53746. sk = NULL;
  53747. X509_free(cert1);
  53748. cert1 = NULL;
  53749. #ifdef HAVE_CRL
  53750. ExpectNotNull(str = wolfSSL_X509_STORE_new());
  53751. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  53752. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_FILE_LOAD, caCertFile,
  53753. SSL_FILETYPE_PEM,NULL), 1);
  53754. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_FILE_LOAD,
  53755. "certs/server-revoked-cert.pem",
  53756. SSL_FILETYPE_PEM,NULL), 1);
  53757. if (str) {
  53758. ExpectIntEQ(wolfSSL_CertManagerVerify(str->cm, svrCertFile,
  53759. WOLFSSL_FILETYPE_PEM), 1);
  53760. /* since store hasn't yet known the revoked cert*/
  53761. ExpectIntEQ(wolfSSL_CertManagerVerify(str->cm,
  53762. "certs/server-revoked-cert.pem",
  53763. WOLFSSL_FILETYPE_PEM), 1);
  53764. }
  53765. for (i = 0; pem[i][0] != '\0'; i++)
  53766. {
  53767. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_FILE_LOAD, pem[i],
  53768. SSL_FILETYPE_PEM, NULL), 1);
  53769. }
  53770. if (str) {
  53771. /* since store knows crl list */
  53772. ExpectIntEQ(wolfSSL_CertManagerVerify(str->cm,
  53773. "certs/server-revoked-cert.pem",
  53774. WOLFSSL_FILETYPE_PEM ), WC_NO_ERR_TRACE(CRL_CERT_REVOKED));
  53775. }
  53776. ExpectIntEQ(X509_LOOKUP_ctrl(NULL, 0, NULL, 0, NULL), 0);
  53777. X509_STORE_free(str);
  53778. #endif
  53779. #endif
  53780. return EXPECT_RESULT();
  53781. }
  53782. static int test_wolfSSL_X509_STORE_CTX_trusted_stack_cleanup(void)
  53783. {
  53784. int res = TEST_SKIPPED;
  53785. #if defined(OPENSSL_EXTRA)
  53786. X509_STORE_CTX_cleanup(NULL);
  53787. X509_STORE_CTX_trusted_stack(NULL, NULL);
  53788. res = TEST_SUCCESS;
  53789. #endif
  53790. return res;
  53791. }
  53792. static int test_wolfSSL_X509_STORE_CTX_get0_current_issuer(void)
  53793. {
  53794. EXPECT_DECLS;
  53795. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  53796. X509_STORE_CTX* ctx = NULL;
  53797. X509_STORE* str = NULL;
  53798. X509* x509Ca = NULL;
  53799. X509* x509Svr = NULL;
  53800. X509* issuer = NULL;
  53801. X509_NAME* caName = NULL;
  53802. X509_NAME* issuerName = NULL;
  53803. ExpectNotNull(ctx = X509_STORE_CTX_new());
  53804. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  53805. ExpectNotNull((x509Ca =
  53806. wolfSSL_X509_load_certificate_file(caCertFile, SSL_FILETYPE_PEM)));
  53807. ExpectIntEQ(X509_STORE_add_cert(str, x509Ca), SSL_SUCCESS);
  53808. ExpectNotNull((x509Svr =
  53809. wolfSSL_X509_load_certificate_file(svrCertFile, SSL_FILETYPE_PEM)));
  53810. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, x509Svr, NULL), SSL_SUCCESS);
  53811. ExpectNull(X509_STORE_CTX_get0_current_issuer(NULL));
  53812. ExpectNotNull(issuer = X509_STORE_CTX_get0_current_issuer(ctx));
  53813. ExpectNotNull(caName = X509_get_subject_name(x509Ca));
  53814. ExpectNotNull(issuerName = X509_get_subject_name(issuer));
  53815. #ifdef WOLFSSL_SIGNER_DER_CERT
  53816. ExpectIntEQ(X509_NAME_cmp(caName, issuerName), 0);
  53817. #endif
  53818. X509_free(issuer);
  53819. X509_STORE_CTX_free(ctx);
  53820. X509_free(x509Svr);
  53821. X509_STORE_free(str);
  53822. X509_free(x509Ca);
  53823. #endif
  53824. return EXPECT_RESULT();
  53825. }
  53826. static int test_wolfSSL_PKCS7_certs(void)
  53827. {
  53828. EXPECT_DECLS;
  53829. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && !defined(NO_BIO) && \
  53830. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && defined(HAVE_PKCS7)
  53831. STACK_OF(X509)* sk = NULL;
  53832. STACK_OF(X509_INFO)* info_sk = NULL;
  53833. PKCS7 *p7 = NULL;
  53834. BIO* bio = NULL;
  53835. const byte* p = NULL;
  53836. int buflen = 0;
  53837. int i;
  53838. /* Test twice. Once with d2i and once without to test
  53839. * that everything is free'd correctly. */
  53840. for (i = 0; i < 2; i++) {
  53841. ExpectNotNull(p7 = PKCS7_new());
  53842. if (p7 != NULL) {
  53843. p7->version = 1;
  53844. #ifdef NO_SHA
  53845. p7->hashOID = SHA256h;
  53846. #else
  53847. p7->hashOID = SHAh;
  53848. #endif
  53849. }
  53850. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  53851. ExpectIntGT(BIO_read_filename(bio, svrCertFile), 0);
  53852. ExpectNotNull(info_sk = PEM_X509_INFO_read_bio(bio, NULL, NULL, NULL));
  53853. ExpectIntEQ(sk_X509_INFO_num(info_sk), 2);
  53854. ExpectNotNull(sk = sk_X509_new_null());
  53855. while (EXPECT_SUCCESS() && (sk_X509_INFO_num(info_sk) > 0)) {
  53856. X509_INFO* info = NULL;
  53857. ExpectNotNull(info = sk_X509_INFO_shift(info_sk));
  53858. ExpectIntGT(sk_X509_push(sk, info->x509), 0);
  53859. if (EXPECT_SUCCESS() && (info != NULL)) {
  53860. info->x509 = NULL;
  53861. }
  53862. X509_INFO_free(info);
  53863. }
  53864. sk_X509_INFO_pop_free(info_sk, X509_INFO_free);
  53865. info_sk = NULL;
  53866. BIO_free(bio);
  53867. bio = NULL;
  53868. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  53869. ExpectIntEQ(wolfSSL_PKCS7_encode_certs(p7, sk, bio), 1);
  53870. if ((sk != NULL) && ((p7 == NULL) || (bio == NULL))) {
  53871. sk_X509_pop_free(sk, X509_free);
  53872. }
  53873. sk = NULL;
  53874. ExpectIntGT((buflen = BIO_get_mem_data(bio, &p)), 0);
  53875. if (i == 0) {
  53876. PKCS7_free(p7);
  53877. p7 = NULL;
  53878. ExpectNotNull(d2i_PKCS7(&p7, &p, buflen));
  53879. if (p7 != NULL) {
  53880. /* Reset certs to force wolfSSL_PKCS7_to_stack to regenerate
  53881. * them */
  53882. ((WOLFSSL_PKCS7*)p7)->certs = NULL;
  53883. }
  53884. /* PKCS7_free free's the certs */
  53885. ExpectNotNull(wolfSSL_PKCS7_to_stack(p7));
  53886. }
  53887. BIO_free(bio);
  53888. bio = NULL;
  53889. PKCS7_free(p7);
  53890. p7 = NULL;
  53891. }
  53892. #endif /* defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  53893. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && defined(HAVE_PKCS7) */
  53894. return EXPECT_RESULT();
  53895. }
  53896. static int test_wolfSSL_X509_STORE_CTX(void)
  53897. {
  53898. EXPECT_DECLS;
  53899. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  53900. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  53901. X509_STORE_CTX* ctx = NULL;
  53902. X509_STORE* str = NULL;
  53903. X509* x509 = NULL;
  53904. #ifdef OPENSSL_ALL
  53905. X509* x5092 = NULL;
  53906. STACK_OF(X509) *sk = NULL;
  53907. STACK_OF(X509) *sk2 = NULL;
  53908. STACK_OF(X509) *sk3 = NULL;
  53909. #endif
  53910. ExpectNotNull(ctx = X509_STORE_CTX_new());
  53911. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  53912. ExpectNotNull((x509 =
  53913. wolfSSL_X509_load_certificate_file(svrCertFile, SSL_FILETYPE_PEM)));
  53914. ExpectIntEQ(X509_STORE_add_cert(str, x509), SSL_SUCCESS);
  53915. #ifdef OPENSSL_ALL
  53916. /* sk_X509_new only in OPENSSL_ALL */
  53917. sk = sk_X509_new_null();
  53918. ExpectNotNull(sk);
  53919. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, x509, sk), SSL_SUCCESS);
  53920. #else
  53921. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, x509, NULL), SSL_SUCCESS);
  53922. #endif
  53923. ExpectIntEQ(SSL_get_ex_data_X509_STORE_CTX_idx(), 0);
  53924. X509_STORE_CTX_set_error(ctx, -5);
  53925. X509_STORE_CTX_set_error(NULL, -5);
  53926. X509_STORE_CTX_free(ctx);
  53927. ctx = NULL;
  53928. #ifdef OPENSSL_ALL
  53929. sk_X509_pop_free(sk, NULL);
  53930. sk = NULL;
  53931. #endif
  53932. X509_STORE_free(str);
  53933. str = NULL;
  53934. X509_free(x509);
  53935. x509 = NULL;
  53936. ExpectNotNull(ctx = X509_STORE_CTX_new());
  53937. X509_STORE_CTX_set_verify_cb(ctx, verify_cb);
  53938. X509_STORE_CTX_free(ctx);
  53939. ctx = NULL;
  53940. #ifdef OPENSSL_ALL
  53941. /* test X509_STORE_CTX_get(1)_chain */
  53942. ExpectNotNull((x509 = X509_load_certificate_file(svrCertFile,
  53943. SSL_FILETYPE_PEM)));
  53944. ExpectNotNull((x5092 = X509_load_certificate_file(cliCertFile,
  53945. SSL_FILETYPE_PEM)));
  53946. ExpectNotNull((sk = sk_X509_new_null()));
  53947. ExpectIntEQ(sk_X509_push(sk, x509), 1);
  53948. if (EXPECT_FAIL()) {
  53949. X509_free(x509);
  53950. x509 = NULL;
  53951. }
  53952. ExpectNotNull((str = X509_STORE_new()));
  53953. ExpectNotNull((ctx = X509_STORE_CTX_new()));
  53954. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, x5092, sk), 1);
  53955. ExpectNull((sk2 = X509_STORE_CTX_get_chain(NULL)));
  53956. ExpectNotNull((sk2 = X509_STORE_CTX_get_chain(ctx)));
  53957. ExpectIntEQ(sk_num(sk2), 1); /* sanity, make sure chain has 1 cert */
  53958. ExpectNull((sk3 = X509_STORE_CTX_get1_chain(NULL)));
  53959. ExpectNotNull((sk3 = X509_STORE_CTX_get1_chain(ctx)));
  53960. ExpectIntEQ(sk_num(sk3), 1); /* sanity, make sure chain has 1 cert */
  53961. X509_STORE_CTX_free(ctx);
  53962. ctx = NULL;
  53963. X509_STORE_free(str);
  53964. str = NULL;
  53965. /* CTX certs not freed yet */
  53966. X509_free(x5092);
  53967. x5092 = NULL;
  53968. sk_X509_pop_free(sk, NULL);
  53969. sk = NULL;
  53970. /* sk3 is dup so free here */
  53971. sk_X509_pop_free(sk3, NULL);
  53972. sk3 = NULL;
  53973. #endif
  53974. /* test X509_STORE_CTX_get/set_ex_data */
  53975. {
  53976. int i = 0, tmpData = 5;
  53977. void* tmpDataRet;
  53978. ExpectNotNull(ctx = X509_STORE_CTX_new());
  53979. #ifdef HAVE_EX_DATA
  53980. for (i = 0; i < MAX_EX_DATA; i++) {
  53981. ExpectIntEQ(X509_STORE_CTX_set_ex_data(ctx, i, &tmpData),
  53982. WOLFSSL_SUCCESS);
  53983. tmpDataRet = (int*)X509_STORE_CTX_get_ex_data(ctx, i);
  53984. ExpectNotNull(tmpDataRet);
  53985. ExpectIntEQ(tmpData, *(int*)tmpDataRet);
  53986. }
  53987. #else
  53988. ExpectIntEQ(X509_STORE_CTX_set_ex_data(ctx, i, &tmpData),
  53989. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53990. tmpDataRet = (int*)X509_STORE_CTX_get_ex_data(ctx, i);
  53991. ExpectNull(tmpDataRet);
  53992. #endif
  53993. X509_STORE_CTX_free(ctx);
  53994. ctx = NULL;
  53995. }
  53996. /* test X509_STORE_get/set_ex_data */
  53997. {
  53998. int i = 0, tmpData = 99;
  53999. void* tmpDataRet;
  54000. ExpectNotNull(str = X509_STORE_new());
  54001. #ifdef HAVE_EX_DATA
  54002. for (i = 0; i < MAX_EX_DATA; i++) {
  54003. ExpectIntEQ(X509_STORE_set_ex_data(str, i, &tmpData),
  54004. WOLFSSL_SUCCESS);
  54005. tmpDataRet = (int*)X509_STORE_get_ex_data(str, i);
  54006. ExpectNotNull(tmpDataRet);
  54007. ExpectIntEQ(tmpData, *(int*)tmpDataRet);
  54008. }
  54009. #else
  54010. ExpectIntEQ(X509_STORE_set_ex_data(str, i, &tmpData),
  54011. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  54012. tmpDataRet = (int*)X509_STORE_get_ex_data(str, i);
  54013. ExpectNull(tmpDataRet);
  54014. #endif
  54015. X509_STORE_free(str);
  54016. str = NULL;
  54017. }
  54018. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  54019. * !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  54020. return EXPECT_RESULT();
  54021. }
  54022. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  54023. static int test_X509_STORE_untrusted_load_cert_to_stack(const char* filename,
  54024. STACK_OF(X509)* chain)
  54025. {
  54026. EXPECT_DECLS;
  54027. XFILE fp = XBADFILE;
  54028. X509* cert = NULL;
  54029. ExpectTrue((fp = XFOPEN(filename, "rb"))
  54030. != XBADFILE);
  54031. ExpectNotNull(cert = PEM_read_X509(fp, 0, 0, 0 ));
  54032. if (fp != XBADFILE) {
  54033. XFCLOSE(fp);
  54034. fp = XBADFILE;
  54035. }
  54036. ExpectIntGT(sk_X509_push(chain, cert), 0);
  54037. if (EXPECT_FAIL())
  54038. X509_free(cert);
  54039. return EXPECT_RESULT();
  54040. }
  54041. static int test_X509_STORE_untrusted_certs(const char** filenames, int ret,
  54042. int err, int loadCA)
  54043. {
  54044. EXPECT_DECLS;
  54045. X509_STORE_CTX* ctx = NULL;
  54046. X509_STORE* str = NULL;
  54047. XFILE fp = XBADFILE;
  54048. X509* cert = NULL;
  54049. STACK_OF(X509)* untrusted = NULL;
  54050. ExpectTrue((fp = XFOPEN("./certs/intermediate/server-int-cert.pem", "rb"))
  54051. != XBADFILE);
  54052. ExpectNotNull(cert = PEM_read_X509(fp, 0, 0, 0 ));
  54053. if (fp != XBADFILE) {
  54054. XFCLOSE(fp);
  54055. fp = XBADFILE;
  54056. }
  54057. ExpectNotNull(str = X509_STORE_new());
  54058. ExpectNotNull(ctx = X509_STORE_CTX_new());
  54059. ExpectNotNull(untrusted = sk_X509_new_null());
  54060. ExpectIntEQ(X509_STORE_set_flags(str, 0), 1);
  54061. if (loadCA) {
  54062. ExpectIntEQ(X509_STORE_load_locations(str, "./certs/ca-cert.pem", NULL),
  54063. 1);
  54064. }
  54065. for (; *filenames; filenames++) {
  54066. ExpectIntEQ(test_X509_STORE_untrusted_load_cert_to_stack(*filenames,
  54067. untrusted), TEST_SUCCESS);
  54068. }
  54069. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, cert, untrusted), 1);
  54070. ExpectIntEQ(X509_verify_cert(ctx), ret);
  54071. ExpectIntEQ(X509_STORE_CTX_get_error(ctx), err);
  54072. X509_free(cert);
  54073. X509_STORE_free(str);
  54074. X509_STORE_CTX_free(ctx);
  54075. sk_X509_pop_free(untrusted, NULL);
  54076. return EXPECT_RESULT();
  54077. }
  54078. #endif
  54079. static int test_X509_STORE_untrusted(void)
  54080. {
  54081. EXPECT_DECLS;
  54082. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  54083. const char* untrusted1[] = {
  54084. "./certs/intermediate/ca-int2-cert.pem",
  54085. NULL
  54086. };
  54087. const char* untrusted2[] = {
  54088. "./certs/intermediate/ca-int-cert.pem",
  54089. "./certs/intermediate/ca-int2-cert.pem",
  54090. NULL
  54091. };
  54092. const char* untrusted3[] = {
  54093. "./certs/intermediate/ca-int-cert.pem",
  54094. "./certs/intermediate/ca-int2-cert.pem",
  54095. "./certs/ca-cert.pem",
  54096. NULL
  54097. };
  54098. /* Adding unrelated certs that should be ignored */
  54099. const char* untrusted4[] = {
  54100. "./certs/client-ca.pem",
  54101. "./certs/intermediate/ca-int-cert.pem",
  54102. "./certs/server-cert.pem",
  54103. "./certs/intermediate/ca-int2-cert.pem",
  54104. NULL
  54105. };
  54106. /* Only immediate issuer in untrusted chain. Fails since can't build chain
  54107. * to loaded CA. */
  54108. ExpectIntEQ(test_X509_STORE_untrusted_certs(untrusted1, 0,
  54109. X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY, 1), TEST_SUCCESS);
  54110. /* Succeeds because path to loaded CA is available. */
  54111. ExpectIntEQ(test_X509_STORE_untrusted_certs(untrusted2, 1, 0, 1),
  54112. TEST_SUCCESS);
  54113. /* Fails because root CA is in the untrusted stack */
  54114. ExpectIntEQ(test_X509_STORE_untrusted_certs(untrusted3, 0,
  54115. X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY, 0), TEST_SUCCESS);
  54116. /* Succeeds because path to loaded CA is available. */
  54117. ExpectIntEQ(test_X509_STORE_untrusted_certs(untrusted4, 1, 0, 1),
  54118. TEST_SUCCESS);
  54119. #endif
  54120. return EXPECT_RESULT();
  54121. }
  54122. static int test_wolfSSL_X509_STORE_set_flags(void)
  54123. {
  54124. EXPECT_DECLS;
  54125. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  54126. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  54127. X509_STORE* store = NULL;
  54128. X509* x509 = NULL;
  54129. ExpectNotNull((store = wolfSSL_X509_STORE_new()));
  54130. ExpectNotNull((x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  54131. WOLFSSL_FILETYPE_PEM)));
  54132. ExpectIntEQ(X509_STORE_add_cert(store, x509), WOLFSSL_SUCCESS);
  54133. #ifdef HAVE_CRL
  54134. ExpectIntEQ(X509_STORE_set_flags(store, WOLFSSL_CRL_CHECKALL),
  54135. WOLFSSL_SUCCESS);
  54136. #else
  54137. ExpectIntEQ(X509_STORE_set_flags(store, WOLFSSL_CRL_CHECKALL),
  54138. WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  54139. #endif
  54140. wolfSSL_X509_free(x509);
  54141. wolfSSL_X509_STORE_free(store);
  54142. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) &&
  54143. * !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  54144. return EXPECT_RESULT();
  54145. }
  54146. static int test_wolfSSL_X509_LOOKUP_load_file(void)
  54147. {
  54148. EXPECT_DECLS;
  54149. #if defined(OPENSSL_EXTRA) && defined(HAVE_CRL) && \
  54150. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && \
  54151. (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH))
  54152. WOLFSSL_X509_STORE* store = NULL;
  54153. WOLFSSL_X509_LOOKUP* lookup = NULL;
  54154. ExpectNotNull(store = wolfSSL_X509_STORE_new());
  54155. ExpectNotNull(lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()));
  54156. ExpectIntEQ(wolfSSL_X509_LOOKUP_load_file(lookup, "certs/client-ca.pem",
  54157. X509_FILETYPE_PEM), 1);
  54158. ExpectIntEQ(wolfSSL_X509_LOOKUP_load_file(lookup, "certs/crl/crl2.pem",
  54159. X509_FILETYPE_PEM), 1);
  54160. if (store != NULL) {
  54161. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm, cliCertFile,
  54162. WOLFSSL_FILETYPE_PEM), 1);
  54163. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm, svrCertFile,
  54164. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  54165. }
  54166. ExpectIntEQ(wolfSSL_X509_LOOKUP_load_file(lookup, "certs/ca-cert.pem",
  54167. X509_FILETYPE_PEM), 1);
  54168. if (store != NULL) {
  54169. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm, svrCertFile,
  54170. WOLFSSL_FILETYPE_PEM), 1);
  54171. }
  54172. wolfSSL_X509_STORE_free(store);
  54173. #endif /* defined(OPENSSL_EXTRA) && defined(HAVE_CRL) &&
  54174. * !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  54175. return EXPECT_RESULT();
  54176. }
  54177. static int test_wolfSSL_X509_STORE_CTX_set_time(void)
  54178. {
  54179. EXPECT_DECLS;
  54180. #if defined(OPENSSL_EXTRA)
  54181. WOLFSSL_X509_STORE_CTX* ctx = NULL;
  54182. time_t c_time;
  54183. ExpectNotNull(ctx = wolfSSL_X509_STORE_CTX_new());
  54184. c_time = 365*24*60*60;
  54185. wolfSSL_X509_STORE_CTX_set_time(ctx, 0, c_time);
  54186. ExpectTrue((ctx->param->flags & WOLFSSL_USE_CHECK_TIME) ==
  54187. WOLFSSL_USE_CHECK_TIME);
  54188. ExpectTrue(ctx->param->check_time == c_time);
  54189. wolfSSL_X509_STORE_CTX_free(ctx);
  54190. #endif /* OPENSSL_EXTRA */
  54191. return EXPECT_RESULT();
  54192. }
  54193. static int test_wolfSSL_CTX_get0_set1_param(void)
  54194. {
  54195. EXPECT_DECLS;
  54196. #if defined(OPENSSL_EXTRA)
  54197. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  54198. SSL_CTX* ctx = NULL;
  54199. WOLFSSL_X509_VERIFY_PARAM* pParam = NULL;
  54200. WOLFSSL_X509_VERIFY_PARAM* pvpm = NULL;
  54201. char testIPv4[] = "127.0.0.1";
  54202. char testhostName[] = "foo.hoge.com";
  54203. #ifndef NO_WOLFSSL_SERVER
  54204. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  54205. #else
  54206. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  54207. #endif
  54208. ExpectNull(SSL_CTX_get0_param(NULL));
  54209. ExpectNotNull(pParam = SSL_CTX_get0_param(ctx));
  54210. ExpectNotNull(pvpm = (WOLFSSL_X509_VERIFY_PARAM *)XMALLOC(
  54211. sizeof(WOLFSSL_X509_VERIFY_PARAM), NULL, DYNAMIC_TYPE_OPENSSL));
  54212. ExpectNotNull(XMEMSET(pvpm, 0, sizeof(WOLFSSL_X509_VERIFY_PARAM)));
  54213. ExpectIntEQ(wolfSSL_X509_VERIFY_PARAM_set1_host(pvpm, testhostName,
  54214. (int)XSTRLEN(testhostName)), WOLFSSL_SUCCESS);
  54215. ExpectIntEQ(wolfSSL_X509_VERIFY_PARAM_set1_ip_asc(pvpm, testIPv4),
  54216. WOLFSSL_SUCCESS);
  54217. wolfSSL_X509_VERIFY_PARAM_set_hostflags(pvpm, 0x01);
  54218. ExpectIntEQ(SSL_CTX_set1_param(ctx, pvpm), 1);
  54219. ExpectIntEQ(0, XSTRNCMP(pParam->hostName, testhostName,
  54220. (int)XSTRLEN(testhostName)));
  54221. ExpectIntEQ(0x01, pParam->hostFlags);
  54222. ExpectIntEQ(0, XSTRNCMP(pParam->ipasc, testIPv4, WOLFSSL_MAX_IPSTR));
  54223. /* test for incorrect parameter */
  54224. ExpectIntEQ(1,SSL_CTX_set1_param(ctx, NULL));
  54225. ExpectIntEQ(1,SSL_CTX_set1_param(NULL, pvpm));
  54226. ExpectIntEQ(1,SSL_CTX_set1_param(NULL, NULL));
  54227. SSL_CTX_free(ctx);
  54228. XFREE(pvpm, NULL, DYNAMIC_TYPE_OPENSSL);
  54229. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  54230. #endif /* OPENSSL_EXTRA && !defined(NO_RSA)*/
  54231. return EXPECT_RESULT();
  54232. }
  54233. static int test_wolfSSL_get0_param(void)
  54234. {
  54235. EXPECT_DECLS;
  54236. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  54237. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  54238. SSL_CTX* ctx = NULL;
  54239. SSL* ssl = NULL;
  54240. #ifndef NO_WOLFSSL_SERVER
  54241. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  54242. #else
  54243. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  54244. #endif
  54245. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  54246. SSL_FILETYPE_PEM));
  54247. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  54248. ExpectNotNull(ssl = SSL_new(ctx));
  54249. ExpectNotNull(SSL_get0_param(ssl));
  54250. SSL_free(ssl);
  54251. SSL_CTX_free(ctx);
  54252. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  54253. #endif /* OPENSSL_EXTRA && !defined(NO_RSA)*/
  54254. return EXPECT_RESULT();
  54255. }
  54256. static int test_wolfSSL_X509_VERIFY_PARAM_set1_host(void)
  54257. {
  54258. EXPECT_DECLS;
  54259. #if defined(OPENSSL_EXTRA)
  54260. const char host[] = "www.example.com";
  54261. WOLFSSL_X509_VERIFY_PARAM* pParam = NULL;
  54262. ExpectNotNull(pParam = (WOLFSSL_X509_VERIFY_PARAM*)XMALLOC(
  54263. sizeof(WOLFSSL_X509_VERIFY_PARAM), HEAP_HINT, DYNAMIC_TYPE_OPENSSL));
  54264. if (pParam != NULL) {
  54265. XMEMSET(pParam, 0, sizeof(WOLFSSL_X509_VERIFY_PARAM));
  54266. X509_VERIFY_PARAM_set1_host(pParam, host, sizeof(host));
  54267. ExpectIntEQ(XMEMCMP(pParam->hostName, host, sizeof(host)), 0);
  54268. XMEMSET(pParam, 0, sizeof(WOLFSSL_X509_VERIFY_PARAM));
  54269. ExpectIntNE(XMEMCMP(pParam->hostName, host, sizeof(host)), 0);
  54270. XFREE(pParam, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  54271. }
  54272. #endif /* OPENSSL_EXTRA */
  54273. return EXPECT_RESULT();
  54274. }
  54275. static int test_wolfSSL_set1_host(void)
  54276. {
  54277. EXPECT_DECLS;
  54278. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  54279. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  54280. const char host[] = "www.test_wolfSSL_set1_host.com";
  54281. const char emptyStr[] = "";
  54282. SSL_CTX* ctx = NULL;
  54283. SSL* ssl = NULL;
  54284. WOLFSSL_X509_VERIFY_PARAM* pParam = NULL;
  54285. #ifndef NO_WOLFSSL_SERVER
  54286. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  54287. #else
  54288. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  54289. #endif
  54290. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  54291. SSL_FILETYPE_PEM));
  54292. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  54293. ExpectNotNull(ssl = SSL_new(ctx));
  54294. pParam = SSL_get0_param(ssl);
  54295. /* we should get back host string */
  54296. ExpectIntEQ(SSL_set1_host(ssl, host), WOLFSSL_SUCCESS);
  54297. ExpectIntEQ(XMEMCMP(pParam->hostName, host, sizeof(host)), 0);
  54298. /* we should get back empty string */
  54299. ExpectIntEQ(SSL_set1_host(ssl, emptyStr), WOLFSSL_SUCCESS);
  54300. ExpectIntEQ(XMEMCMP(pParam->hostName, emptyStr, sizeof(emptyStr)), 0);
  54301. /* we should get back host string */
  54302. ExpectIntEQ(SSL_set1_host(ssl, host), WOLFSSL_SUCCESS);
  54303. ExpectIntEQ(XMEMCMP(pParam->hostName, host, sizeof(host)), 0);
  54304. /* we should get back empty string */
  54305. ExpectIntEQ(SSL_set1_host(ssl, NULL), WOLFSSL_SUCCESS);
  54306. ExpectIntEQ(XMEMCMP(pParam->hostName, emptyStr, sizeof(emptyStr)), 0);
  54307. SSL_free(ssl);
  54308. SSL_CTX_free(ctx);
  54309. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  54310. #endif /* OPENSSL_EXTRA */
  54311. return EXPECT_RESULT();
  54312. }
  54313. static int test_wolfSSL_X509_VERIFY_PARAM_set1_ip(void)
  54314. {
  54315. EXPECT_DECLS;
  54316. #if defined(OPENSSL_EXTRA)
  54317. unsigned char buf[16] = {0};
  54318. WOLFSSL_X509_VERIFY_PARAM* param = NULL;
  54319. ExpectNotNull(param = X509_VERIFY_PARAM_new());
  54320. /* test 127.0.0.1 */
  54321. buf[0] =0x7f; buf[1] = 0; buf[2] = 0; buf[3] = 1;
  54322. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 4), SSL_SUCCESS);
  54323. ExpectIntEQ(XSTRNCMP(param->ipasc, "127.0.0.1", sizeof(param->ipasc)), 0);
  54324. /* test 2001:db8:3333:4444:5555:6666:7777:8888 */
  54325. buf[0]=32;buf[1]=1;buf[2]=13;buf[3]=184;
  54326. buf[4]=51;buf[5]=51;buf[6]=68;buf[7]=68;
  54327. buf[8]=85;buf[9]=85;buf[10]=102;buf[11]=102;
  54328. buf[12]=119;buf[13]=119;buf[14]=136;buf[15]=136;
  54329. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 16), SSL_SUCCESS);
  54330. ExpectIntEQ(XSTRNCMP(param->ipasc,
  54331. "2001:db8:3333:4444:5555:6666:7777:8888", sizeof(param->ipasc)), 0);
  54332. /* test 2001:db8:: */
  54333. buf[0]=32;buf[1]=1;buf[2]=13;buf[3]=184;
  54334. buf[4]=0;buf[5]=0;buf[6]=0;buf[7]=0;
  54335. buf[8]=0;buf[9]=0;buf[10]=0;buf[11]=0;
  54336. buf[12]=0;buf[13]=0;buf[14]=0;buf[15]=0;
  54337. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 16), SSL_SUCCESS);
  54338. ExpectIntEQ(XSTRNCMP(param->ipasc, "2001:db8::", sizeof(param->ipasc)), 0);
  54339. /* test ::1234:5678 */
  54340. buf[0]=0;buf[1]=0;buf[2]=0;buf[3]=0;
  54341. buf[4]=0;buf[5]=0;buf[6]=0;buf[7]=0;
  54342. buf[8]=0;buf[9]=0;buf[10]=0;buf[11]=0;
  54343. buf[12]=18;buf[13]=52;buf[14]=86;buf[15]=120;
  54344. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 16), SSL_SUCCESS);
  54345. ExpectIntEQ(XSTRNCMP(param->ipasc, "::1234:5678", sizeof(param->ipasc)), 0);
  54346. /* test 2001:db8::1234:5678 */
  54347. buf[0]=32;buf[1]=1;buf[2]=13;buf[3]=184;
  54348. buf[4]=0;buf[5]=0;buf[6]=0;buf[7]=0;
  54349. buf[8]=0;buf[9]=0;buf[10]=0;buf[11]=0;
  54350. buf[12]=18;buf[13]=52;buf[14]=86;buf[15]=120;
  54351. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 16), SSL_SUCCESS);
  54352. ExpectIntEQ(XSTRNCMP(param->ipasc, "2001:db8::1234:5678",
  54353. sizeof(param->ipasc)), 0);
  54354. /* test 2001:0db8:0001:0000:0000:0ab9:c0a8:0102*/
  54355. /* 2001:db8:1::ab9:c0a8:102 */
  54356. buf[0]=32;buf[1]=1;buf[2]=13;buf[3]=184;
  54357. buf[4]=0;buf[5]=1;buf[6]=0;buf[7]=0;
  54358. buf[8]=0;buf[9]=0;buf[10]=10;buf[11]=185;
  54359. buf[12]=192;buf[13]=168;buf[14]=1;buf[15]=2;
  54360. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 16), SSL_SUCCESS);
  54361. ExpectIntEQ(XSTRNCMP(param->ipasc, "2001:db8:1::ab9:c0a8:102",
  54362. sizeof(param->ipasc)), 0);
  54363. XFREE(param, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  54364. #endif /* OPENSSL_EXTRA */
  54365. return EXPECT_RESULT();
  54366. }
  54367. static int test_wolfSSL_X509_STORE_CTX_get0_store(void)
  54368. {
  54369. EXPECT_DECLS;
  54370. #if defined(OPENSSL_EXTRA)
  54371. X509_STORE* store = NULL;
  54372. X509_STORE_CTX* ctx = NULL;
  54373. X509_STORE_CTX* ctx_no_init = NULL;
  54374. ExpectNotNull((store = X509_STORE_new()));
  54375. ExpectNotNull(ctx = X509_STORE_CTX_new());
  54376. ExpectNotNull(ctx_no_init = X509_STORE_CTX_new());
  54377. ExpectIntEQ(X509_STORE_CTX_init(ctx, store, NULL, NULL), SSL_SUCCESS);
  54378. ExpectNull(X509_STORE_CTX_get0_store(NULL));
  54379. /* should return NULL if ctx has not bee initialized */
  54380. ExpectNull(X509_STORE_CTX_get0_store(ctx_no_init));
  54381. ExpectNotNull(X509_STORE_CTX_get0_store(ctx));
  54382. wolfSSL_X509_STORE_CTX_free(ctx);
  54383. wolfSSL_X509_STORE_CTX_free(ctx_no_init);
  54384. X509_STORE_free(store);
  54385. #endif /* OPENSSL_EXTRA */
  54386. return EXPECT_RESULT();
  54387. }
  54388. static int test_wolfSSL_CTX_set_client_CA_list(void)
  54389. {
  54390. EXPECT_DECLS;
  54391. #if defined(OPENSSL_ALL) && !defined(NO_RSA) && !defined(NO_CERTS) && \
  54392. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_BIO)
  54393. WOLFSSL_CTX* ctx = NULL;
  54394. WOLFSSL* ssl = NULL;
  54395. X509_NAME* name = NULL;
  54396. STACK_OF(X509_NAME)* names = NULL;
  54397. STACK_OF(X509_NAME)* ca_list = NULL;
  54398. int names_len = 0;
  54399. int i;
  54400. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  54401. /* Send two X501 names in cert request */
  54402. names = SSL_load_client_CA_file(cliCertFile);
  54403. ExpectNotNull(names);
  54404. ca_list = SSL_load_client_CA_file(caCertFile);
  54405. ExpectNotNull(ca_list);
  54406. ExpectNotNull(name = sk_X509_NAME_value(ca_list, 0));
  54407. ExpectIntEQ(sk_X509_NAME_push(names, name), 2);
  54408. if (EXPECT_FAIL()) {
  54409. wolfSSL_X509_NAME_free(name);
  54410. name = NULL;
  54411. }
  54412. SSL_CTX_set_client_CA_list(ctx, names);
  54413. /* This should only free the stack structure */
  54414. sk_X509_NAME_free(ca_list);
  54415. ca_list = NULL;
  54416. ExpectNotNull(ca_list = SSL_CTX_get_client_CA_list(ctx));
  54417. ExpectIntEQ(sk_X509_NAME_num(ca_list), sk_X509_NAME_num(names));
  54418. ExpectIntGT((names_len = sk_X509_NAME_num(names)), 0);
  54419. for (i = 0; i < names_len; i++) {
  54420. ExpectNotNull(name = sk_X509_NAME_value(names, i));
  54421. ExpectIntEQ(sk_X509_NAME_find(names, name), i);
  54422. }
  54423. /* Needed to be able to create ssl object */
  54424. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  54425. SSL_FILETYPE_PEM));
  54426. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  54427. ExpectNotNull(ssl = wolfSSL_new(ctx));
  54428. /* load again as old names are responsibility of ctx to free*/
  54429. names = SSL_load_client_CA_file(cliCertFile);
  54430. ExpectNotNull(names);
  54431. SSL_set_client_CA_list(ssl, names);
  54432. ExpectNotNull(ca_list = SSL_get_client_CA_list(ssl));
  54433. ExpectIntEQ(sk_X509_NAME_num(ca_list), sk_X509_NAME_num(names));
  54434. ExpectIntGT((names_len = sk_X509_NAME_num(names)), 0);
  54435. for (i = 0; i < names_len; i++) {
  54436. ExpectNotNull(name = sk_X509_NAME_value(names, i));
  54437. ExpectIntEQ(sk_X509_NAME_find(names, name), i);
  54438. }
  54439. #if !defined(SINGLE_THREADED) && defined(SESSION_CERTS)
  54440. {
  54441. tcp_ready ready;
  54442. func_args server_args;
  54443. callback_functions server_cb;
  54444. THREAD_TYPE serverThread;
  54445. WOLFSSL* ssl_client = NULL;
  54446. WOLFSSL_CTX* ctx_client = NULL;
  54447. SOCKET_T sockfd = 0;
  54448. /* wolfSSL_get_client_CA_list() with handshake */
  54449. StartTCP();
  54450. InitTcpReady(&ready);
  54451. XMEMSET(&server_args, 0, sizeof(func_args));
  54452. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  54453. server_args.signal = &ready;
  54454. server_args.callbacks = &server_cb;
  54455. /* we are responsible for free'ing WOLFSSL_CTX */
  54456. server_cb.ctx = ctx;
  54457. server_cb.isSharedCtx = 1;
  54458. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_load_verify_locations(ctx,
  54459. cliCertFile, 0));
  54460. start_thread(test_server_nofail, &server_args, &serverThread);
  54461. wait_tcp_ready(&server_args);
  54462. tcp_connect(&sockfd, wolfSSLIP, server_args.signal->port, 0, 0, NULL);
  54463. ExpectNotNull(ctx_client =
  54464. wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  54465. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_load_verify_locations(
  54466. ctx_client, caCertFile, 0));
  54467. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_certificate_file(
  54468. ctx_client, cliCertFile, SSL_FILETYPE_PEM));
  54469. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_PrivateKey_file(
  54470. ctx_client, cliKeyFile, SSL_FILETYPE_PEM));
  54471. ExpectNotNull(ssl_client = wolfSSL_new(ctx_client));
  54472. ExpectIntEQ(wolfSSL_set_fd(ssl_client, sockfd), WOLFSSL_SUCCESS);
  54473. ExpectIntEQ(wolfSSL_connect(ssl_client), WOLFSSL_SUCCESS);
  54474. ExpectNotNull(ca_list = SSL_get_client_CA_list(ssl_client));
  54475. /* We are expecting two cert names to be sent */
  54476. ExpectIntEQ(sk_X509_NAME_num(ca_list), 2);
  54477. ExpectNotNull(names = SSL_CTX_get_client_CA_list(ctx));
  54478. for (i=0; i<sk_X509_NAME_num(ca_list); i++) {
  54479. ExpectNotNull(name = sk_X509_NAME_value(ca_list, i));
  54480. ExpectIntGE(sk_X509_NAME_find(names, name), 0);
  54481. }
  54482. wolfSSL_shutdown(ssl_client);
  54483. wolfSSL_free(ssl_client);
  54484. wolfSSL_CTX_free(ctx_client);
  54485. CloseSocket(sockfd);
  54486. join_thread(serverThread);
  54487. FreeTcpReady(&ready);
  54488. }
  54489. #endif
  54490. wolfSSL_free(ssl);
  54491. wolfSSL_CTX_free(ctx);
  54492. #endif /* OPENSSL_EXTRA && !NO_RSA && !NO_CERTS && !NO_WOLFSSL_CLIENT &&
  54493. * !NO_BIO */
  54494. return EXPECT_RESULT();
  54495. }
  54496. static int test_wolfSSL_CTX_add_client_CA(void)
  54497. {
  54498. EXPECT_DECLS;
  54499. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_CERTS) && \
  54500. !defined(NO_WOLFSSL_CLIENT)
  54501. WOLFSSL_CTX* ctx = NULL;
  54502. WOLFSSL_X509* x509 = NULL;
  54503. WOLFSSL_X509* x509_a = NULL;
  54504. STACK_OF(X509_NAME)* ca_list = NULL;
  54505. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  54506. /* Add client cert */
  54507. ExpectNotNull(x509 = X509_load_certificate_file(cliCertFile,
  54508. SSL_FILETYPE_PEM));
  54509. ExpectIntEQ(SSL_CTX_add_client_CA(ctx, x509), SSL_SUCCESS);
  54510. ExpectNotNull(ca_list = SSL_CTX_get_client_CA_list(ctx));
  54511. /* Add another client cert */
  54512. ExpectNotNull(x509_a = X509_load_certificate_file(cliCertFile,
  54513. SSL_FILETYPE_PEM));
  54514. ExpectIntEQ(SSL_CTX_add_client_CA(ctx, x509_a), SSL_SUCCESS);
  54515. /* test for incorrect parameter */
  54516. ExpectIntEQ(SSL_CTX_add_client_CA(NULL, x509), 0);
  54517. ExpectIntEQ(SSL_CTX_add_client_CA(ctx, NULL), 0);
  54518. ExpectIntEQ(SSL_CTX_add_client_CA(NULL, NULL), 0);
  54519. X509_free(x509);
  54520. X509_free(x509_a);
  54521. SSL_CTX_free(ctx);
  54522. #endif /* OPENSSL_EXTRA && !NO_RSA && !NO_CERTS && !NO_WOLFSSL_CLIENT */
  54523. return EXPECT_RESULT();
  54524. }
  54525. #if defined(WOLFSSL_TLS13) && defined(HAVE_ECH) && \
  54526. defined(HAVE_IO_TESTS_DEPENDENCIES)
  54527. static THREAD_RETURN WOLFSSL_THREAD server_task_ech(void* args)
  54528. {
  54529. callback_functions* callbacks = ((func_args*)args)->callbacks;
  54530. WOLFSSL_CTX* ctx = callbacks->ctx;
  54531. WOLFSSL* ssl = NULL;
  54532. SOCKET_T sfd = 0;
  54533. SOCKET_T cfd = 0;
  54534. word16 port;
  54535. char input[1024];
  54536. int idx;
  54537. int ret, err = 0;
  54538. const char* privateName = "ech-private-name.com";
  54539. int privateNameLen = (int)XSTRLEN(privateName);
  54540. ((func_args*)args)->return_code = TEST_FAIL;
  54541. port = ((func_args*)args)->signal->port;
  54542. AssertIntEQ(WOLFSSL_SUCCESS,
  54543. wolfSSL_CTX_load_verify_locations(ctx, cliCertFile, 0));
  54544. AssertIntEQ(WOLFSSL_SUCCESS,
  54545. wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  54546. WOLFSSL_FILETYPE_PEM));
  54547. AssertIntEQ(WOLFSSL_SUCCESS,
  54548. wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  54549. WOLFSSL_FILETYPE_PEM));
  54550. if (callbacks->ctx_ready)
  54551. callbacks->ctx_ready(ctx);
  54552. ssl = wolfSSL_new(ctx);
  54553. /* set the sni for the server */
  54554. wolfSSL_UseSNI(ssl, WOLFSSL_SNI_HOST_NAME, privateName, privateNameLen);
  54555. tcp_accept(&sfd, &cfd, (func_args*)args, port, 0, 0, 0, 0, 1, NULL, NULL);
  54556. CloseSocket(sfd);
  54557. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_set_fd(ssl, cfd));
  54558. if (callbacks->ssl_ready)
  54559. callbacks->ssl_ready(ssl);
  54560. do {
  54561. err = 0; /* Reset error */
  54562. ret = wolfSSL_accept(ssl);
  54563. if (ret != WOLFSSL_SUCCESS) {
  54564. err = wolfSSL_get_error(ssl, 0);
  54565. }
  54566. } while (ret != WOLFSSL_SUCCESS && err == WC_NO_ERR_TRACE(WC_PENDING_E));
  54567. if (ret != WOLFSSL_SUCCESS) {
  54568. char buff[WOLFSSL_MAX_ERROR_SZ];
  54569. fprintf(stderr, "error = %d, %s\n", err, wolfSSL_ERR_error_string(err, buff));
  54570. }
  54571. else {
  54572. if (0 < (idx = wolfSSL_read(ssl, input, sizeof(input)-1))) {
  54573. input[idx] = 0;
  54574. fprintf(stderr, "Client message: %s\n", input);
  54575. }
  54576. AssertIntEQ(privateNameLen, wolfSSL_write(ssl, privateName,
  54577. privateNameLen));
  54578. ((func_args*)args)->return_code = TEST_SUCCESS;
  54579. }
  54580. if (callbacks->on_result)
  54581. callbacks->on_result(ssl);
  54582. wolfSSL_shutdown(ssl);
  54583. wolfSSL_free(ssl);
  54584. wolfSSL_CTX_free(ctx);
  54585. CloseSocket(cfd);
  54586. #ifdef FP_ECC
  54587. wc_ecc_fp_free();
  54588. #endif
  54589. WOLFSSL_RETURN_FROM_THREAD(0);
  54590. }
  54591. #endif /* HAVE_ECH && WOLFSSL_TLS13 */
  54592. #if defined(OPENSSL_EXTRA) && defined(HAVE_SECRET_CALLBACK)
  54593. static void keyLog_callback(const WOLFSSL* ssl, const char* line)
  54594. {
  54595. XFILE fp;
  54596. const byte lf = '\n';
  54597. AssertNotNull(ssl);
  54598. AssertNotNull(line);
  54599. fp = XFOPEN("./MyKeyLog.txt", "a");
  54600. XFWRITE(line, 1, XSTRLEN(line), fp);
  54601. XFWRITE((void*)&lf, 1, 1, fp);
  54602. XFFLUSH(fp);
  54603. XFCLOSE(fp);
  54604. }
  54605. #endif /* OPENSSL_EXTRA && HAVE_SECRET_CALLBACK */
  54606. static int test_wolfSSL_CTX_set_keylog_callback(void)
  54607. {
  54608. EXPECT_DECLS;
  54609. #if defined(OPENSSL_EXTRA) && defined(HAVE_SECRET_CALLBACK) && \
  54610. !defined(NO_WOLFSSL_CLIENT)
  54611. SSL_CTX* ctx = NULL;
  54612. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  54613. SSL_CTX_set_keylog_callback(ctx, keyLog_callback );
  54614. SSL_CTX_free(ctx);
  54615. SSL_CTX_set_keylog_callback(NULL, NULL);
  54616. #endif /* OPENSSL_EXTRA && HAVE_SECRET_CALLBACK && !NO_WOLFSSL_CLIENT */
  54617. return EXPECT_RESULT();
  54618. }
  54619. static int test_wolfSSL_CTX_get_keylog_callback(void)
  54620. {
  54621. EXPECT_DECLS;
  54622. #if defined(OPENSSL_EXTRA) && defined(HAVE_SECRET_CALLBACK) && \
  54623. !defined(NO_WOLFSSL_CLIENT)
  54624. SSL_CTX* ctx = NULL;
  54625. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  54626. ExpectPtrEq(SSL_CTX_get_keylog_callback(ctx),NULL);
  54627. SSL_CTX_set_keylog_callback(ctx, keyLog_callback );
  54628. ExpectPtrEq(SSL_CTX_get_keylog_callback(ctx),keyLog_callback);
  54629. SSL_CTX_set_keylog_callback(ctx, NULL );
  54630. ExpectPtrEq(SSL_CTX_get_keylog_callback(ctx),NULL);
  54631. SSL_CTX_free(ctx);
  54632. #endif /* OPENSSL_EXTRA && HAVE_SECRET_CALLBACK && !NO_WOLFSSL_CLIENT */
  54633. return EXPECT_RESULT();
  54634. }
  54635. #if defined(OPENSSL_EXTRA) && defined(HAVE_SECRET_CALLBACK)
  54636. static int test_wolfSSL_Tls12_Key_Logging_client_ctx_ready(WOLFSSL_CTX* ctx)
  54637. {
  54638. /* set keylog callback */
  54639. wolfSSL_CTX_set_keylog_callback(ctx, keyLog_callback);
  54640. return TEST_SUCCESS;
  54641. }
  54642. #endif
  54643. static int test_wolfSSL_Tls12_Key_Logging_test(void)
  54644. {
  54645. EXPECT_DECLS;
  54646. #if defined(OPENSSL_EXTRA) && defined(HAVE_SECRET_CALLBACK)
  54647. /* This test is intended for checking whether keylog callback is called
  54648. * in client during TLS handshake between the client and a server.
  54649. */
  54650. test_ssl_cbf server_cbf;
  54651. test_ssl_cbf client_cbf;
  54652. XFILE fp = XBADFILE;
  54653. char buff[500];
  54654. int found = 0;
  54655. XMEMSET(&server_cbf, 0, sizeof(test_ssl_cbf));
  54656. XMEMSET(&client_cbf, 0, sizeof(test_ssl_cbf));
  54657. server_cbf.method = wolfTLSv1_2_server_method;
  54658. client_cbf.ctx_ready = &test_wolfSSL_Tls12_Key_Logging_client_ctx_ready;
  54659. /* clean up keylog file */
  54660. ExpectTrue((fp = XFOPEN("./MyKeyLog.txt", "w")) != XBADFILE);
  54661. if (fp != XBADFILE) {
  54662. XFFLUSH(fp);
  54663. XFCLOSE(fp);
  54664. fp = XBADFILE;
  54665. }
  54666. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  54667. &server_cbf, NULL), TEST_SUCCESS);
  54668. /* check if the keylog file exists */
  54669. ExpectTrue((fp = XFOPEN("./MyKeyLog.txt", "r")) != XBADFILE);
  54670. XFFLUSH(fp); /* Just to make sure any buffers get flushed */
  54671. XMEMSET(buff, 0, sizeof(buff));
  54672. while (EXPECT_SUCCESS() && XFGETS(buff, (int)sizeof(buff), fp) != NULL) {
  54673. if (0 == strncmp(buff,"CLIENT_RANDOM ", sizeof("CLIENT_RANDOM ")-1)) {
  54674. found = 1;
  54675. break;
  54676. }
  54677. }
  54678. if (fp != XBADFILE) {
  54679. XFCLOSE(fp);
  54680. }
  54681. /* a log starting with "CLIENT_RANDOM " should exit in the file */
  54682. ExpectIntEQ(found, 1);
  54683. /* clean up */
  54684. ExpectIntEQ(rem_file("./MyKeyLog.txt"), 0);
  54685. #endif /* OPENSSL_EXTRA && HAVE_SECRET_CALLBACK */
  54686. return EXPECT_RESULT();
  54687. }
  54688. #if defined(WOLFSSL_TLS13) && defined(OPENSSL_EXTRA) && \
  54689. defined(HAVE_SECRET_CALLBACK)
  54690. static int test_wolfSSL_Tls13_Key_Logging_client_ctx_ready(WOLFSSL_CTX* ctx)
  54691. {
  54692. /* set keylog callback */
  54693. wolfSSL_CTX_set_keylog_callback(ctx, keyLog_callback);
  54694. return TEST_SUCCESS;
  54695. }
  54696. #endif
  54697. static int test_wolfSSL_Tls13_Key_Logging_test(void)
  54698. {
  54699. EXPECT_DECLS;
  54700. #if defined(WOLFSSL_TLS13) && defined(OPENSSL_EXTRA) && \
  54701. defined(HAVE_SECRET_CALLBACK)
  54702. /* This test is intended for checking whether keylog callback is called
  54703. * in client during TLS handshake between the client and a server.
  54704. */
  54705. test_ssl_cbf server_cbf;
  54706. test_ssl_cbf client_cbf;
  54707. XFILE fp = XBADFILE;
  54708. XMEMSET(&server_cbf, 0, sizeof(test_ssl_cbf));
  54709. XMEMSET(&client_cbf, 0, sizeof(test_ssl_cbf));
  54710. server_cbf.method = wolfTLSv1_3_server_method; /* TLS1.3 */
  54711. client_cbf.ctx_ready = &test_wolfSSL_Tls13_Key_Logging_client_ctx_ready;
  54712. /* clean up keylog file */
  54713. ExpectTrue((fp = XFOPEN("./MyKeyLog.txt", "w")) != XBADFILE);
  54714. if (fp != XBADFILE) {
  54715. XFCLOSE(fp);
  54716. fp = XBADFILE;
  54717. }
  54718. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  54719. &server_cbf, NULL), TEST_SUCCESS);
  54720. /* check if the keylog file exists */
  54721. {
  54722. char buff[300] = {0};
  54723. int found[4] = {0};
  54724. int numfnd = 0;
  54725. int i;
  54726. ExpectTrue((fp = XFOPEN("./MyKeyLog.txt", "r")) != XBADFILE);
  54727. while (EXPECT_SUCCESS() &&
  54728. XFGETS(buff, (int)sizeof(buff), fp) != NULL) {
  54729. if (0 == strncmp(buff, "CLIENT_HANDSHAKE_TRAFFIC_SECRET ",
  54730. sizeof("CLIENT_HANDSHAKE_TRAFFIC_SECRET ")-1)) {
  54731. found[0] = 1;
  54732. continue;
  54733. }
  54734. else if (0 == strncmp(buff, "SERVER_HANDSHAKE_TRAFFIC_SECRET ",
  54735. sizeof("SERVER_HANDSHAKE_TRAFFIC_SECRET ")-1)) {
  54736. found[1] = 1;
  54737. continue;
  54738. }
  54739. else if (0 == strncmp(buff, "CLIENT_TRAFFIC_SECRET_0 ",
  54740. sizeof("CLIENT_TRAFFIC_SECRET_0 ")-1)) {
  54741. found[2] = 1;
  54742. continue;
  54743. }
  54744. else if (0 == strncmp(buff, "SERVER_TRAFFIC_SECRET_0 ",
  54745. sizeof("SERVER_TRAFFIC_SECRET_0 ")-1)) {
  54746. found[3] = 1;
  54747. continue;
  54748. }
  54749. }
  54750. if (fp != XBADFILE)
  54751. XFCLOSE(fp);
  54752. for (i = 0; i < 4; i++) {
  54753. if (found[i] != 0)
  54754. numfnd++;
  54755. }
  54756. ExpectIntEQ(numfnd, 4);
  54757. }
  54758. #endif /* OPENSSL_EXTRA && HAVE_SECRET_CALLBACK && WOLFSSL_TLS13 */
  54759. return EXPECT_RESULT();
  54760. }
  54761. #if defined(WOLFSSL_TLS13) && defined(HAVE_ECH) && \
  54762. defined(HAVE_IO_TESTS_DEPENDENCIES)
  54763. static int test_wolfSSL_Tls13_ECH_params(void)
  54764. {
  54765. EXPECT_DECLS;
  54766. #if !defined(NO_WOLFSSL_CLIENT)
  54767. word32 outputLen = 0;
  54768. byte testBuf[72];
  54769. WOLFSSL_CTX *ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method());
  54770. WOLFSSL *ssl = wolfSSL_new(ctx);
  54771. ExpectNotNull(ctx);
  54772. ExpectNotNull(ssl);
  54773. /* invalid ctx */
  54774. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_GenerateEchConfig(NULL,
  54775. "ech-public-name.com", 0, 0, 0));
  54776. /* invalid public name */
  54777. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_GenerateEchConfig(ctx, NULL, 0,
  54778. 0, 0));
  54779. /* invalid algorithms */
  54780. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_GenerateEchConfig(ctx,
  54781. "ech-public-name.com", 1000, 1000, 1000));
  54782. /* invalid ctx */
  54783. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_GetEchConfigs(NULL, NULL,
  54784. &outputLen));
  54785. /* invalid output len */
  54786. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_GetEchConfigs(ctx, NULL, NULL));
  54787. /* invalid ssl */
  54788. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigsBase64(NULL,
  54789. (char*)testBuf, sizeof(testBuf)));
  54790. /* invalid configs64 */
  54791. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigsBase64(ssl, NULL,
  54792. sizeof(testBuf)));
  54793. /* invalid size */
  54794. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigsBase64(ssl,
  54795. (char*)testBuf, 0));
  54796. /* invalid ssl */
  54797. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigs(NULL, testBuf,
  54798. sizeof(testBuf)));
  54799. /* invalid configs */
  54800. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigs(ssl, NULL,
  54801. sizeof(testBuf)));
  54802. /* invalid size */
  54803. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigs(ssl, testBuf, 0));
  54804. /* invalid ssl */
  54805. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_GetEchConfigs(NULL, NULL, &outputLen));
  54806. /* invalid size */
  54807. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_GetEchConfigs(ssl, NULL, NULL));
  54808. wolfSSL_free(ssl);
  54809. wolfSSL_CTX_free(ctx);
  54810. #endif /* !NO_WOLFSSL_CLIENT */
  54811. return EXPECT_RESULT();
  54812. }
  54813. static int test_wolfSSL_Tls13_ECH(void)
  54814. {
  54815. EXPECT_DECLS;
  54816. tcp_ready ready;
  54817. func_args client_args;
  54818. func_args server_args;
  54819. THREAD_TYPE serverThread;
  54820. callback_functions server_cbf;
  54821. callback_functions client_cbf;
  54822. SOCKET_T sockfd = 0;
  54823. WOLFSSL_CTX* ctx = NULL;
  54824. WOLFSSL* ssl = NULL;
  54825. const char* publicName = "ech-public-name.com";
  54826. const char* privateName = "ech-private-name.com";
  54827. int privateNameLen = 20;
  54828. char reply[1024];
  54829. int replyLen = 0;
  54830. byte rawEchConfig[128];
  54831. word32 rawEchConfigLen = sizeof(rawEchConfig);
  54832. InitTcpReady(&ready);
  54833. ready.port = 22222;
  54834. XMEMSET(&client_args, 0, sizeof(func_args));
  54835. XMEMSET(&server_args, 0, sizeof(func_args));
  54836. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  54837. XMEMSET(&client_cbf, 0, sizeof(callback_functions));
  54838. server_cbf.method = wolfTLSv1_3_server_method; /* TLS1.3 */
  54839. /* create the server context here so we can get the ech config */
  54840. ExpectNotNull(server_cbf.ctx =
  54841. wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  54842. /* generate ech config */
  54843. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_GenerateEchConfig(server_cbf.ctx,
  54844. publicName, 0, 0, 0));
  54845. /* get the config for the client to use */
  54846. ExpectIntEQ(WOLFSSL_SUCCESS,
  54847. wolfSSL_CTX_GetEchConfigs(server_cbf.ctx, rawEchConfig,
  54848. &rawEchConfigLen));
  54849. server_args.callbacks = &server_cbf;
  54850. server_args.signal = &ready;
  54851. /* start server task */
  54852. start_thread(server_task_ech, &server_args, &serverThread);
  54853. wait_tcp_ready(&server_args);
  54854. /* run as a TLS1.3 client */
  54855. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  54856. ExpectIntEQ(WOLFSSL_SUCCESS,
  54857. wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0));
  54858. ExpectIntEQ(WOLFSSL_SUCCESS,
  54859. wolfSSL_CTX_use_certificate_file(ctx, cliCertFile, SSL_FILETYPE_PEM));
  54860. ExpectIntEQ(WOLFSSL_SUCCESS,
  54861. wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, SSL_FILETYPE_PEM));
  54862. tcp_connect(&sockfd, wolfSSLIP, server_args.signal->port, 0, 0, NULL);
  54863. /* get connected the server task */
  54864. ExpectNotNull(ssl = wolfSSL_new(ctx));
  54865. /* set the ech configs for the client */
  54866. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigs(ssl, rawEchConfig,
  54867. rawEchConfigLen));
  54868. /* set the sni for the client */
  54869. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSNI(ssl, WOLFSSL_SNI_HOST_NAME,
  54870. privateName, privateNameLen));
  54871. ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS);
  54872. ExpectIntEQ(wolfSSL_connect(ssl), WOLFSSL_SUCCESS);
  54873. ExpectIntEQ(wolfSSL_write(ssl, privateName, privateNameLen),
  54874. privateNameLen);
  54875. ExpectIntGT((replyLen = wolfSSL_read(ssl, reply, sizeof(reply))), 0);
  54876. /* add th null terminator for string compare */
  54877. reply[replyLen] = 0;
  54878. /* check that the server replied with the private name */
  54879. ExpectStrEQ(privateName, reply);
  54880. wolfSSL_free(ssl);
  54881. wolfSSL_CTX_free(ctx);
  54882. CloseSocket(sockfd);
  54883. join_thread(serverThread);
  54884. FreeTcpReady(&ready);
  54885. return EXPECT_RESULT();
  54886. }
  54887. #endif /* HAVE_ECH && WOLFSSL_TLS13 */
  54888. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  54889. defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  54890. defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
  54891. static int post_auth_version_cb(WOLFSSL* ssl)
  54892. {
  54893. EXPECT_DECLS;
  54894. /* do handshake and then test version error */
  54895. ExpectIntEQ(wolfSSL_accept(ssl), WOLFSSL_SUCCESS);
  54896. ExpectStrEQ("TLSv1.2", wolfSSL_get_version(ssl));
  54897. return EXPECT_RESULT();
  54898. }
  54899. static int post_auth_version_client_cb(WOLFSSL* ssl)
  54900. {
  54901. EXPECT_DECLS;
  54902. /* do handshake and then test version error */
  54903. ExpectIntEQ(wolfSSL_connect(ssl), WOLFSSL_SUCCESS);
  54904. ExpectStrEQ("TLSv1.2", wolfSSL_get_version(ssl));
  54905. ExpectIntEQ(wolfSSL_verify_client_post_handshake(ssl), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  54906. #if defined(OPENSSL_ALL) && !defined(NO_ERROR_QUEUE)
  54907. /* check was added to error queue */
  54908. ExpectIntEQ(wolfSSL_ERR_get_error(), -WC_NO_ERR_TRACE(UNSUPPORTED_PROTO_VERSION));
  54909. /* check the string matches expected string */
  54910. #ifndef NO_ERROR_STRINGS
  54911. ExpectStrEQ(wolfSSL_ERR_error_string(-WC_NO_ERR_TRACE(UNSUPPORTED_PROTO_VERSION), NULL),
  54912. "WRONG_SSL_VERSION");
  54913. #endif
  54914. #endif
  54915. return EXPECT_RESULT();
  54916. }
  54917. static int post_auth_cb(WOLFSSL* ssl)
  54918. {
  54919. EXPECT_DECLS;
  54920. WOLFSSL_X509* x509 = NULL;
  54921. /* do handshake and then test version error */
  54922. ExpectIntEQ(wolfSSL_accept(ssl), WOLFSSL_SUCCESS);
  54923. ExpectStrEQ("TLSv1.3", wolfSSL_get_version(ssl));
  54924. ExpectNull(x509 = wolfSSL_get_peer_certificate(ssl));
  54925. wolfSSL_X509_free(x509);
  54926. ExpectIntEQ(wolfSSL_verify_client_post_handshake(ssl), WOLFSSL_SUCCESS);
  54927. return EXPECT_RESULT();
  54928. }
  54929. static int set_post_auth_cb(WOLFSSL* ssl)
  54930. {
  54931. if (!wolfSSL_is_server(ssl)) {
  54932. EXPECT_DECLS;
  54933. ExpectIntEQ(wolfSSL_allow_post_handshake_auth(ssl), 0);
  54934. return EXPECT_RESULT();
  54935. }
  54936. wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_POST_HANDSHAKE, NULL);
  54937. return TEST_SUCCESS;
  54938. }
  54939. #endif
  54940. static int test_wolfSSL_Tls13_postauth(void)
  54941. {
  54942. EXPECT_DECLS;
  54943. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  54944. defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  54945. defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
  54946. test_ssl_cbf server_cbf;
  54947. test_ssl_cbf client_cbf;
  54948. /* test version failure doing post auth with TLS 1.2 connection */
  54949. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  54950. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  54951. server_cbf.method = wolfTLSv1_2_server_method;
  54952. server_cbf.ssl_ready = set_post_auth_cb;
  54953. server_cbf.on_result = post_auth_version_cb;
  54954. client_cbf.ssl_ready = set_post_auth_cb;
  54955. client_cbf.on_result = post_auth_version_client_cb;
  54956. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  54957. &server_cbf, NULL), TEST_SUCCESS);
  54958. /* tests on post auth with TLS 1.3 */
  54959. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  54960. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  54961. server_cbf.method = wolfTLSv1_3_server_method;
  54962. server_cbf.ssl_ready = set_post_auth_cb;
  54963. client_cbf.ssl_ready = set_post_auth_cb;
  54964. server_cbf.on_result = post_auth_cb;
  54965. client_cbf.on_result = NULL;
  54966. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  54967. &server_cbf, NULL), TEST_SUCCESS);
  54968. #endif
  54969. return EXPECT_RESULT();
  54970. }
  54971. static int test_wolfSSL_X509_NID(void)
  54972. {
  54973. EXPECT_DECLS;
  54974. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)) && \
  54975. !defined(NO_RSA) && defined(USE_CERT_BUFFERS_2048) && !defined(NO_ASN)
  54976. int sigType;
  54977. int nameSz;
  54978. X509* cert = NULL;
  54979. EVP_PKEY* pubKeyTmp = NULL;
  54980. X509_NAME* name = NULL;
  54981. char commonName[80];
  54982. char countryName[80];
  54983. char localityName[80];
  54984. char stateName[80];
  54985. char orgName[80];
  54986. char orgUnit[80];
  54987. /* ------ PARSE ORIGINAL SELF-SIGNED CERTIFICATE ------ */
  54988. /* convert cert from DER to internal WOLFSSL_X509 struct */
  54989. ExpectNotNull(cert = wolfSSL_X509_d2i_ex(&cert, client_cert_der_2048,
  54990. sizeof_client_cert_der_2048, HEAP_HINT));
  54991. /* ------ EXTRACT CERTIFICATE ELEMENTS ------ */
  54992. /* extract PUBLIC KEY from cert */
  54993. ExpectNotNull(pubKeyTmp = X509_get_pubkey(cert));
  54994. /* extract signatureType */
  54995. ExpectIntNE((sigType = wolfSSL_X509_get_signature_type(cert)), 0);
  54996. /* extract subjectName info */
  54997. ExpectNotNull(name = X509_get_subject_name(cert));
  54998. ExpectIntEQ(X509_NAME_get_text_by_NID(name, -1, NULL, 0), -1);
  54999. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_commonName,
  55000. NULL, 0)), 0);
  55001. ExpectIntEQ(nameSz, 15);
  55002. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_commonName,
  55003. commonName, sizeof(commonName))), 0);
  55004. ExpectIntEQ(nameSz, 15);
  55005. ExpectIntEQ(XMEMCMP(commonName, "www.wolfssl.com", nameSz), 0);
  55006. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_commonName,
  55007. commonName, 9)), 0);
  55008. ExpectIntEQ(nameSz, 8);
  55009. ExpectIntEQ(XMEMCMP(commonName, "www.wolf", nameSz), 0);
  55010. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_countryName,
  55011. countryName, sizeof(countryName))), 0);
  55012. ExpectIntEQ(XMEMCMP(countryName, "US", nameSz), 0);
  55013. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_localityName,
  55014. localityName, sizeof(localityName))), 0);
  55015. ExpectIntEQ(XMEMCMP(localityName, "Bozeman", nameSz), 0);
  55016. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name,
  55017. NID_stateOrProvinceName, stateName, sizeof(stateName))), 0);
  55018. ExpectIntEQ(XMEMCMP(stateName, "Montana", nameSz), 0);
  55019. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_organizationName,
  55020. orgName, sizeof(orgName))), 0);
  55021. ExpectIntEQ(XMEMCMP(orgName, "wolfSSL_2048", nameSz), 0);
  55022. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name,
  55023. NID_organizationalUnitName, orgUnit, sizeof(orgUnit))), 0);
  55024. ExpectIntEQ(XMEMCMP(orgUnit, "Programming-2048", nameSz), 0);
  55025. EVP_PKEY_free(pubKeyTmp);
  55026. X509_free(cert);
  55027. #endif
  55028. return EXPECT_RESULT();
  55029. }
  55030. static int test_wolfSSL_CTX_set_srp_username(void)
  55031. {
  55032. EXPECT_DECLS;
  55033. #if defined(OPENSSL_EXTRA) && defined(WOLFCRYPT_HAVE_SRP) \
  55034. && !defined(NO_SHA256) && !defined(WC_NO_RNG) && !defined(NO_WOLFSSL_CLIENT)
  55035. WOLFSSL_CTX* ctx = NULL;
  55036. WOLFSSL* ssl = NULL;
  55037. const char *username = "TESTUSER";
  55038. const char *password = "TESTPASSWORD";
  55039. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  55040. ExpectIntEQ(wolfSSL_CTX_set_srp_username(ctx, (char *)username),
  55041. SSL_SUCCESS);
  55042. wolfSSL_CTX_free(ctx);
  55043. ctx = NULL;
  55044. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  55045. ExpectIntEQ(wolfSSL_CTX_set_srp_password(ctx, (char *)password),
  55046. SSL_SUCCESS);
  55047. ExpectIntEQ(wolfSSL_CTX_set_srp_username(ctx, (char *)username),
  55048. SSL_SUCCESS);
  55049. ExpectNotNull(ssl = SSL_new(ctx));
  55050. ExpectNotNull(SSL_get_srp_username(ssl));
  55051. ExpectStrEQ(SSL_get_srp_username(ssl), username);
  55052. wolfSSL_free(ssl);
  55053. wolfSSL_CTX_free(ctx);
  55054. #endif /* OPENSSL_EXTRA && WOLFCRYPT_HAVE_SRP */
  55055. /* && !NO_SHA256 && !WC_NO_RNG && !NO_WOLFSSL_CLIENT */
  55056. return EXPECT_RESULT();
  55057. }
  55058. static int test_wolfSSL_CTX_set_srp_password(void)
  55059. {
  55060. EXPECT_DECLS;
  55061. #if defined(OPENSSL_EXTRA) && defined(WOLFCRYPT_HAVE_SRP) && \
  55062. !defined(NO_SHA256) && !defined(WC_NO_RNG) && !defined(NO_WOLFSSL_CLIENT)
  55063. WOLFSSL_CTX* ctx = NULL;
  55064. const char *username = "TESTUSER";
  55065. const char *password = "TESTPASSWORD";
  55066. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  55067. ExpectIntEQ(wolfSSL_CTX_set_srp_password(ctx, (char *)password),
  55068. SSL_SUCCESS);
  55069. wolfSSL_CTX_free(ctx);
  55070. ctx = NULL;
  55071. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  55072. ExpectIntEQ(wolfSSL_CTX_set_srp_username(ctx, (char *)username),
  55073. SSL_SUCCESS);
  55074. ExpectIntEQ(wolfSSL_CTX_set_srp_password(ctx, (char *)password),
  55075. SSL_SUCCESS);
  55076. wolfSSL_CTX_free(ctx);
  55077. #endif /* OPENSSL_EXTRA && WOLFCRYPT_HAVE_SRP */
  55078. /* && !NO_SHA256 && !WC_NO_RNG && !NO_WOLFSSL_CLIENT */
  55079. return EXPECT_RESULT();
  55080. }
  55081. static int test_wolfSSL_X509_STORE(void)
  55082. {
  55083. EXPECT_DECLS;
  55084. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  55085. X509_STORE *store = NULL;
  55086. #ifdef HAVE_CRL
  55087. X509_STORE_CTX *storeCtx = NULL;
  55088. X509 *ca = NULL;
  55089. X509 *cert = NULL;
  55090. const char srvCert[] = "./certs/server-revoked-cert.pem";
  55091. const char caCert[] = "./certs/ca-cert.pem";
  55092. #ifndef WOLFSSL_CRL_ALLOW_MISSING_CDP
  55093. X509_CRL *crl = NULL;
  55094. const char crlPem[] = "./certs/crl/crl.revoked";
  55095. XFILE fp = XBADFILE;
  55096. #endif /* !WOLFSSL_CRL_ALLOW_MISSING_CDP */
  55097. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  55098. ExpectNotNull((ca = wolfSSL_X509_load_certificate_file(caCert,
  55099. SSL_FILETYPE_PEM)));
  55100. ExpectIntEQ(X509_STORE_add_cert(store, ca), SSL_SUCCESS);
  55101. ExpectNotNull((cert = wolfSSL_X509_load_certificate_file(srvCert,
  55102. SSL_FILETYPE_PEM)));
  55103. ExpectNotNull((storeCtx = X509_STORE_CTX_new()));
  55104. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, cert, NULL), SSL_SUCCESS);
  55105. ExpectIntEQ(X509_verify_cert(storeCtx), SSL_SUCCESS);
  55106. X509_STORE_free(store);
  55107. store = NULL;
  55108. X509_STORE_CTX_free(storeCtx);
  55109. storeCtx = NULL;
  55110. X509_free(cert);
  55111. cert = NULL;
  55112. X509_free(ca);
  55113. ca = NULL;
  55114. #ifndef WOLFSSL_CRL_ALLOW_MISSING_CDP
  55115. /* should fail to verify now after adding in CRL */
  55116. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  55117. ExpectNotNull((ca = wolfSSL_X509_load_certificate_file(caCert,
  55118. SSL_FILETYPE_PEM)));
  55119. ExpectIntEQ(X509_STORE_add_cert(store, ca), SSL_SUCCESS);
  55120. ExpectTrue((fp = XFOPEN(crlPem, "rb")) != XBADFILE);
  55121. ExpectNotNull(crl = (X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  55122. NULL, NULL));
  55123. if (fp != XBADFILE)
  55124. XFCLOSE(fp);
  55125. ExpectIntEQ(X509_STORE_add_crl(store, crl), SSL_SUCCESS);
  55126. ExpectIntEQ(X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK),SSL_SUCCESS);
  55127. ExpectNotNull((storeCtx = X509_STORE_CTX_new()));
  55128. ExpectNotNull((cert = wolfSSL_X509_load_certificate_file(srvCert,
  55129. SSL_FILETYPE_PEM)));
  55130. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, cert, NULL), SSL_SUCCESS);
  55131. ExpectIntNE(X509_verify_cert(storeCtx), SSL_SUCCESS);
  55132. ExpectIntEQ(X509_STORE_CTX_get_error(storeCtx),
  55133. WOLFSSL_X509_V_ERR_CERT_REVOKED);
  55134. X509_CRL_free(crl);
  55135. crl = NULL;
  55136. X509_STORE_free(store);
  55137. store = NULL;
  55138. X509_STORE_CTX_free(storeCtx);
  55139. storeCtx = NULL;
  55140. X509_free(cert);
  55141. cert = NULL;
  55142. X509_free(ca);
  55143. ca = NULL;
  55144. #endif /* !WOLFSSL_CRL_ALLOW_MISSING_CDP */
  55145. #endif /* HAVE_CRL */
  55146. #ifndef WOLFCRYPT_ONLY
  55147. {
  55148. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  55149. SSL_CTX* ctx = NULL;
  55150. SSL* ssl = NULL;
  55151. int i;
  55152. for (i = 0; i < 2; i++) {
  55153. #ifndef NO_WOLFSSL_SERVER
  55154. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  55155. #else
  55156. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  55157. #endif
  55158. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  55159. SSL_CTX_set_cert_store(ctx, store);
  55160. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  55161. SSL_CTX_set_cert_store(ctx, store);
  55162. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  55163. ExpectIntEQ(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  55164. SSL_FILETYPE_PEM), SSL_SUCCESS);
  55165. ExpectIntEQ(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  55166. SSL_FILETYPE_PEM), SSL_SUCCESS);
  55167. ExpectNotNull(ssl = SSL_new(ctx));
  55168. if (i == 0) {
  55169. ExpectIntEQ(SSL_set0_verify_cert_store(ssl, store),
  55170. SSL_SUCCESS);
  55171. }
  55172. else {
  55173. ExpectIntEQ(SSL_set1_verify_cert_store(ssl, store), SSL_SUCCESS);
  55174. #ifdef OPENSSL_ALL
  55175. ExpectIntEQ(SSL_CTX_set1_verify_cert_store(ctx, store), SSL_SUCCESS);
  55176. #endif
  55177. }
  55178. if (EXPECT_FAIL() || (i == 1)) {
  55179. X509_STORE_free(store);
  55180. store = NULL;
  55181. }
  55182. SSL_free(ssl);
  55183. ssl = NULL;
  55184. SSL_CTX_free(ctx);
  55185. ctx = NULL;
  55186. }
  55187. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  55188. }
  55189. #endif
  55190. #endif
  55191. return EXPECT_RESULT();
  55192. }
  55193. static int test_wolfSSL_X509_STORE_load_locations(void)
  55194. {
  55195. EXPECT_DECLS;
  55196. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && \
  55197. !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_DIR) && !defined(NO_RSA)
  55198. SSL_CTX *ctx = NULL;
  55199. X509_STORE *store = NULL;
  55200. const char ca_file[] = "./certs/ca-cert.pem";
  55201. const char client_pem_file[] = "./certs/client-cert.pem";
  55202. const char client_der_file[] = "./certs/client-cert.der";
  55203. const char ecc_file[] = "./certs/ecc-key.pem";
  55204. const char certs_path[] = "./certs/";
  55205. const char bad_path[] = "./bad-path/";
  55206. #ifdef HAVE_CRL
  55207. const char crl_path[] = "./certs/crl/";
  55208. const char crl_file[] = "./certs/crl/crl.pem";
  55209. #endif
  55210. #ifndef NO_WOLFSSL_SERVER
  55211. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_server_method()));
  55212. #else
  55213. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_client_method()));
  55214. #endif
  55215. ExpectNotNull(store = SSL_CTX_get_cert_store(ctx));
  55216. ExpectIntEQ(wolfSSL_CertManagerLoadCA(store->cm, ca_file, NULL),
  55217. WOLFSSL_SUCCESS);
  55218. /* Test bad arguments */
  55219. ExpectIntEQ(X509_STORE_load_locations(NULL, ca_file, NULL),
  55220. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  55221. ExpectIntEQ(X509_STORE_load_locations(store, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  55222. ExpectIntEQ(X509_STORE_load_locations(store, client_der_file, NULL),
  55223. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  55224. ExpectIntEQ(X509_STORE_load_locations(store, ecc_file, NULL),
  55225. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  55226. ExpectIntEQ(X509_STORE_load_locations(store, NULL, bad_path),
  55227. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  55228. #ifdef HAVE_CRL
  55229. /* Test with CRL */
  55230. ExpectIntEQ(X509_STORE_load_locations(store, crl_file, NULL),
  55231. WOLFSSL_SUCCESS);
  55232. ExpectIntEQ(X509_STORE_load_locations(store, NULL, crl_path),
  55233. WOLFSSL_SUCCESS);
  55234. #endif
  55235. /* Test with CA */
  55236. ExpectIntEQ(X509_STORE_load_locations(store, ca_file, NULL),
  55237. WOLFSSL_SUCCESS);
  55238. /* Test with client_cert and certs path */
  55239. ExpectIntEQ(X509_STORE_load_locations(store, client_pem_file, NULL),
  55240. WOLFSSL_SUCCESS);
  55241. ExpectIntEQ(X509_STORE_load_locations(store, NULL, certs_path),
  55242. WOLFSSL_SUCCESS);
  55243. #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
  55244. /* Clear nodes */
  55245. ERR_clear_error();
  55246. #endif
  55247. SSL_CTX_free(ctx);
  55248. #endif
  55249. return EXPECT_RESULT();
  55250. }
  55251. static int test_X509_STORE_get0_objects(void)
  55252. {
  55253. EXPECT_DECLS;
  55254. #if defined(OPENSSL_ALL) && !defined(NO_FILESYSTEM) && \
  55255. !defined(NO_WOLFSSL_DIR) && !defined(NO_RSA)
  55256. X509_STORE *store = NULL;
  55257. X509_STORE *store_cpy = NULL;
  55258. SSL_CTX *ctx = NULL;
  55259. X509_OBJECT *obj = NULL;
  55260. STACK_OF(X509_OBJECT) *objs = NULL;
  55261. int i;
  55262. /* Setup store */
  55263. #ifndef NO_WOLFSSL_SERVER
  55264. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_server_method()));
  55265. #else
  55266. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_client_method()));
  55267. #endif
  55268. ExpectNotNull(store_cpy = X509_STORE_new());
  55269. ExpectNotNull(store = SSL_CTX_get_cert_store(ctx));
  55270. ExpectIntEQ(X509_STORE_load_locations(store, cliCertFile, NULL),
  55271. WOLFSSL_SUCCESS);
  55272. ExpectIntEQ(X509_STORE_load_locations(store, caCertFile, NULL),
  55273. WOLFSSL_SUCCESS);
  55274. ExpectIntEQ(X509_STORE_load_locations(store, svrCertFile, NULL),
  55275. WOLFSSL_SUCCESS);
  55276. #ifdef HAVE_CRL
  55277. ExpectIntEQ(X509_STORE_load_locations(store, NULL, crlPemDir),
  55278. WOLFSSL_SUCCESS);
  55279. #endif
  55280. /* Store ready */
  55281. /* Similar to HaProxy ssl_set_cert_crl_file use case */
  55282. ExpectNotNull(objs = X509_STORE_get0_objects(store));
  55283. #ifdef HAVE_CRL
  55284. #ifdef WOLFSSL_SIGNER_DER_CERT
  55285. ExpectIntEQ(sk_X509_OBJECT_num(objs), 4);
  55286. #else
  55287. ExpectIntEQ(sk_X509_OBJECT_num(objs), 1);
  55288. #endif
  55289. #else
  55290. #ifdef WOLFSSL_SIGNER_DER_CERT
  55291. ExpectIntEQ(sk_X509_OBJECT_num(objs), 3);
  55292. #else
  55293. ExpectIntEQ(sk_X509_OBJECT_num(objs), 0);
  55294. #endif
  55295. #endif
  55296. for (i = 0; i < sk_X509_OBJECT_num(objs); i++) {
  55297. obj = (X509_OBJECT*)sk_X509_OBJECT_value(objs, i);
  55298. switch (X509_OBJECT_get_type(obj)) {
  55299. case X509_LU_X509:
  55300. {
  55301. X509* x509 = NULL;
  55302. X509_NAME *subj_name = NULL;
  55303. ExpectNotNull(x509 = X509_OBJECT_get0_X509(obj));
  55304. ExpectIntEQ(X509_STORE_add_cert(store_cpy, x509), WOLFSSL_SUCCESS);
  55305. ExpectNotNull(subj_name = X509_get_subject_name(x509));
  55306. ExpectPtrEq(obj, X509_OBJECT_retrieve_by_subject(objs, X509_LU_X509,
  55307. subj_name));
  55308. break;
  55309. }
  55310. case X509_LU_CRL:
  55311. #ifdef HAVE_CRL
  55312. {
  55313. X509_CRL* crl = NULL;
  55314. ExpectNotNull(crl = X509_OBJECT_get0_X509_CRL(obj));
  55315. ExpectIntEQ(X509_STORE_add_crl(store_cpy, crl), WOLFSSL_SUCCESS);
  55316. break;
  55317. }
  55318. #endif
  55319. case X509_LU_NONE:
  55320. default:
  55321. Fail(("X509_OBJECT_get_type should return x509 or crl "
  55322. "(when built with crl support)"),
  55323. ("Unrecognized X509_OBJECT type or none"));
  55324. }
  55325. }
  55326. X509_STORE_free(store_cpy);
  55327. SSL_CTX_free(ctx);
  55328. #endif
  55329. return EXPECT_RESULT();
  55330. }
  55331. static int test_wolfSSL_BN_CTX(void)
  55332. {
  55333. EXPECT_DECLS;
  55334. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  55335. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  55336. WOLFSSL_BN_CTX* bn_ctx = NULL;
  55337. WOLFSSL_BIGNUM* t = NULL;
  55338. ExpectNotNull(bn_ctx = wolfSSL_BN_CTX_new());
  55339. /* No implementation. */
  55340. BN_CTX_init(NULL);
  55341. ExpectNotNull(t = BN_CTX_get(NULL));
  55342. BN_free(t);
  55343. ExpectNotNull(t = BN_CTX_get(bn_ctx));
  55344. BN_free(t);
  55345. #ifndef NO_WOLFSSL_STUB
  55346. /* No implementation. */
  55347. BN_CTX_start(NULL);
  55348. BN_CTX_start(bn_ctx);
  55349. #endif
  55350. BN_CTX_free(NULL);
  55351. BN_CTX_free(bn_ctx);
  55352. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  55353. return EXPECT_RESULT();
  55354. }
  55355. static int test_wolfSSL_BN(void)
  55356. {
  55357. EXPECT_DECLS;
  55358. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  55359. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  55360. BIGNUM* a = NULL;
  55361. BIGNUM* b = NULL;
  55362. BIGNUM* c = NULL;
  55363. BIGNUM* d = NULL;
  55364. BIGNUM emptyBN;
  55365. /* Setup */
  55366. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  55367. /* internal not set emptyBN. */
  55368. ExpectNotNull(a = BN_new());
  55369. ExpectNotNull(b = BN_new());
  55370. ExpectNotNull(c = BN_dup(b));
  55371. ExpectNotNull(d = BN_new());
  55372. /* Invalid parameter testing. */
  55373. BN_free(NULL);
  55374. ExpectNull(BN_dup(NULL));
  55375. ExpectNull(BN_dup(&emptyBN));
  55376. ExpectNull(BN_copy(NULL, NULL));
  55377. ExpectNull(BN_copy(b, NULL));
  55378. ExpectNull(BN_copy(NULL, c));
  55379. ExpectNull(BN_copy(b, &emptyBN));
  55380. ExpectNull(BN_copy(&emptyBN, c));
  55381. BN_clear(NULL);
  55382. BN_clear(&emptyBN);
  55383. ExpectIntEQ(BN_num_bytes(NULL), 0);
  55384. ExpectIntEQ(BN_num_bytes(&emptyBN), 0);
  55385. ExpectIntEQ(BN_num_bits(NULL), 0);
  55386. ExpectIntEQ(BN_num_bits(&emptyBN), 0);
  55387. ExpectIntEQ(BN_is_negative(NULL), 0);
  55388. ExpectIntEQ(BN_is_negative(&emptyBN), 0);
  55389. /* END Invalid Parameters */
  55390. ExpectIntEQ(BN_set_word(a, 3), SSL_SUCCESS);
  55391. ExpectIntEQ(BN_set_word(b, 2), SSL_SUCCESS);
  55392. ExpectIntEQ(BN_set_word(c, 5), SSL_SUCCESS);
  55393. ExpectIntEQ(BN_num_bits(a), 2);
  55394. ExpectIntEQ(BN_num_bytes(a), 1);
  55395. #if !defined(WOLFSSL_SP_MATH) && (!defined(WOLFSSL_SP_MATH_ALL) || \
  55396. defined(WOLFSSL_SP_INT_NEGATIVE))
  55397. ExpectIntEQ(BN_set_word(a, 1), SSL_SUCCESS);
  55398. ExpectIntEQ(BN_set_word(b, 5), SSL_SUCCESS);
  55399. ExpectIntEQ(BN_is_word(a, (WOLFSSL_BN_ULONG)BN_get_word(a)), SSL_SUCCESS);
  55400. ExpectIntEQ(BN_is_word(a, 3), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  55401. ExpectIntEQ(BN_sub(c, a, b), SSL_SUCCESS);
  55402. #if defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  55403. {
  55404. /* Do additional tests on negative BN conversions. */
  55405. char* ret = NULL;
  55406. ASN1_INTEGER* asn1 = NULL;
  55407. BIGNUM* tmp = NULL;
  55408. /* Sanity check we have a negative BN. */
  55409. ExpectIntEQ(BN_is_negative(c), 1);
  55410. ExpectNotNull(ret = BN_bn2dec(c));
  55411. ExpectIntEQ(XMEMCMP(ret, "-4", sizeof("-4")), 0);
  55412. XFREE(ret, NULL, DYNAMIC_TYPE_OPENSSL);
  55413. ret = NULL;
  55414. /* Convert to ASN1_INTEGER and back to BN. */
  55415. ExpectNotNull(asn1 = BN_to_ASN1_INTEGER(c, NULL));
  55416. ExpectNotNull(tmp = ASN1_INTEGER_to_BN(asn1, NULL));
  55417. /* After converting back BN should be negative and correct. */
  55418. ExpectIntEQ(BN_is_negative(tmp), 1);
  55419. ExpectNotNull(ret = BN_bn2dec(tmp));
  55420. ExpectIntEQ(XMEMCMP(ret, "-4", sizeof("-4")), 0);
  55421. XFREE(ret, NULL, DYNAMIC_TYPE_OPENSSL);
  55422. ASN1_INTEGER_free(asn1);
  55423. BN_free(tmp);
  55424. }
  55425. #endif
  55426. ExpectIntEQ(BN_get_word(c), 4);
  55427. #endif
  55428. ExpectIntEQ(BN_set_word(a, 3), 1);
  55429. ExpectIntEQ(BN_set_word(b, 3), 1);
  55430. ExpectIntEQ(BN_set_word(c, 4), 1);
  55431. /* NULL == NULL, NULL < num, num > NULL */
  55432. ExpectIntEQ(BN_cmp(NULL, NULL), 0);
  55433. ExpectIntEQ(BN_cmp(&emptyBN, &emptyBN), 0);
  55434. ExpectIntLT(BN_cmp(NULL, b), 0);
  55435. ExpectIntLT(BN_cmp(&emptyBN, b), 0);
  55436. ExpectIntGT(BN_cmp(a, NULL), 0);
  55437. ExpectIntGT(BN_cmp(a, &emptyBN), 0);
  55438. ExpectIntEQ(BN_cmp(a, b), 0);
  55439. ExpectIntLT(BN_cmp(a, c), 0);
  55440. ExpectIntGT(BN_cmp(c, b), 0);
  55441. #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM)
  55442. ExpectIntEQ(BN_print_fp(XBADFILE, NULL), 0);
  55443. ExpectIntEQ(BN_print_fp(XBADFILE, &emptyBN), 0);
  55444. ExpectIntEQ(BN_print_fp(stderr, NULL), 0);
  55445. ExpectIntEQ(BN_print_fp(stderr, &emptyBN), 0);
  55446. ExpectIntEQ(BN_print_fp(XBADFILE, a), 0);
  55447. ExpectIntEQ(BN_print_fp(stderr, a), 1);
  55448. #endif
  55449. BN_clear(a);
  55450. BN_free(a);
  55451. BN_free(b);
  55452. BN_free(c);
  55453. BN_clear_free(d);
  55454. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  55455. return EXPECT_RESULT();
  55456. }
  55457. static int test_wolfSSL_BN_init(void)
  55458. {
  55459. EXPECT_DECLS;
  55460. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  55461. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  55462. #if !defined(USE_INTEGER_HEAP_MATH) && !defined(HAVE_WOLF_BIGINT)
  55463. BIGNUM* ap = NULL;
  55464. BIGNUM bv;
  55465. BIGNUM cv;
  55466. BIGNUM dv;
  55467. ExpectNotNull(ap = BN_new());
  55468. BN_init(NULL);
  55469. XMEMSET(&bv, 0, sizeof(bv));
  55470. ExpectNull(BN_dup(&bv));
  55471. BN_init(&bv);
  55472. BN_init(&cv);
  55473. BN_init(&dv);
  55474. ExpectIntEQ(BN_set_word(ap, 3), SSL_SUCCESS);
  55475. ExpectIntEQ(BN_set_word(&bv, 2), SSL_SUCCESS);
  55476. ExpectIntEQ(BN_set_word(&cv, 5), SSL_SUCCESS);
  55477. /* a^b mod c = */
  55478. ExpectIntEQ(BN_mod_exp(&dv, NULL, &bv, &cv, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  55479. ExpectIntEQ(BN_mod_exp(&dv, ap, &bv, &cv, NULL), WOLFSSL_SUCCESS);
  55480. /* check result 3^2 mod 5 */
  55481. ExpectIntEQ(BN_get_word(&dv), 4);
  55482. /* a*b mod c = */
  55483. ExpectIntEQ(BN_mod_mul(&dv, NULL, &bv, &cv, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  55484. ExpectIntEQ(BN_mod_mul(&dv, ap, &bv, &cv, NULL), SSL_SUCCESS);
  55485. /* check result 3*2 mod 5 */
  55486. ExpectIntEQ(BN_get_word(&dv), 1);
  55487. BN_free(ap);
  55488. #endif
  55489. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  55490. return EXPECT_RESULT();
  55491. }
  55492. static int test_wolfSSL_BN_enc_dec(void)
  55493. {
  55494. EXPECT_DECLS;
  55495. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && !defined(WOLFSSL_SP_MATH)
  55496. BIGNUM* a = NULL;
  55497. BIGNUM* b = NULL;
  55498. BIGNUM* c = NULL;
  55499. BIGNUM emptyBN;
  55500. char* str = NULL;
  55501. const char* emptyStr = "";
  55502. const char* numberStr = "12345";
  55503. const char* badStr = "g12345";
  55504. #if defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  55505. const char* twoStr = "2";
  55506. #endif
  55507. unsigned char binNum[] = { 0x01, 0x02, 0x03, 0x04, 0x05 };
  55508. unsigned char outNum[5];
  55509. /* Setup */
  55510. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  55511. ExpectNotNull(a = BN_new());
  55512. ExpectNotNull(b = BN_new());
  55513. /* Invalid parameters */
  55514. ExpectIntEQ(BN_bn2bin(NULL, NULL), -1);
  55515. ExpectIntEQ(BN_bn2bin(&emptyBN, NULL), -1);
  55516. ExpectIntEQ(BN_bn2bin(NULL, outNum), -1);
  55517. ExpectIntEQ(BN_bn2bin(&emptyBN, outNum), -1);
  55518. ExpectNull(BN_bn2hex(NULL));
  55519. ExpectNull(BN_bn2hex(&emptyBN));
  55520. ExpectNull(BN_bn2dec(NULL));
  55521. ExpectNull(BN_bn2dec(&emptyBN));
  55522. ExpectNotNull(BN_bin2bn(NULL, sizeof(binNum), a));
  55523. BN_free(a);
  55524. ExpectNotNull(a = BN_new());
  55525. ExpectIntEQ(BN_set_word(a, 2), 1);
  55526. ExpectNull(BN_bin2bn(binNum, -1, a));
  55527. ExpectNull(BN_bin2bn(binNum, -1, NULL));
  55528. ExpectNull(BN_bin2bn(binNum, sizeof(binNum), &emptyBN));
  55529. ExpectIntEQ(BN_hex2bn(NULL, NULL), 0);
  55530. ExpectIntEQ(BN_hex2bn(NULL, numberStr), 0);
  55531. ExpectIntEQ(BN_hex2bn(&a, NULL), 0);
  55532. ExpectIntEQ(BN_hex2bn(&a, emptyStr), 0);
  55533. ExpectIntEQ(BN_hex2bn(&a, badStr), 0);
  55534. ExpectIntEQ(BN_hex2bn(&c, badStr), 0);
  55535. ExpectIntEQ(BN_dec2bn(NULL, NULL), 0);
  55536. ExpectIntEQ(BN_dec2bn(NULL, numberStr), 0);
  55537. ExpectIntEQ(BN_dec2bn(&a, NULL), 0);
  55538. ExpectIntEQ(BN_dec2bn(&a, emptyStr), 0);
  55539. ExpectIntEQ(BN_dec2bn(&a, badStr), 0);
  55540. ExpectIntEQ(BN_dec2bn(&c, badStr), 0);
  55541. ExpectIntEQ(BN_set_word(a, 2), 1);
  55542. ExpectIntEQ(BN_bn2bin(a, NULL), 1);
  55543. ExpectIntEQ(BN_bn2bin(a, outNum), 1);
  55544. ExpectNotNull(BN_bin2bn(outNum, 1, b));
  55545. ExpectIntEQ(BN_cmp(a, b), 0);
  55546. ExpectNotNull(BN_bin2bn(binNum, sizeof(binNum), b));
  55547. ExpectIntEQ(BN_cmp(a, b), -1);
  55548. ExpectNotNull(str = BN_bn2hex(a));
  55549. ExpectNotNull(BN_hex2bn(&b, str));
  55550. ExpectIntEQ(BN_cmp(a, b), 0);
  55551. ExpectNotNull(BN_hex2bn(&b, numberStr));
  55552. ExpectIntEQ(BN_cmp(a, b), -1);
  55553. XFREE(str, NULL, DYNAMIC_TYPE_OPENSSL);
  55554. str = NULL;
  55555. #if defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  55556. ExpectNotNull(str = BN_bn2dec(a));
  55557. ExpectStrEQ(str, twoStr);
  55558. XFREE(str, NULL, DYNAMIC_TYPE_OPENSSL);
  55559. str = NULL;
  55560. #ifndef NO_RSA
  55561. ExpectNotNull(str = BN_bn2dec(a));
  55562. ExpectNotNull(BN_dec2bn(&b, str));
  55563. ExpectIntEQ(BN_cmp(a, b), 0);
  55564. ExpectNotNull(BN_dec2bn(&b, numberStr));
  55565. ExpectIntEQ(BN_cmp(a, b), -1);
  55566. XFREE(str, NULL, DYNAMIC_TYPE_OPENSSL);
  55567. str = NULL;
  55568. #else
  55569. /* No implementation - fail with good parameters. */
  55570. ExpectIntEQ(BN_dec2bn(&a, numberStr), 0);
  55571. #endif
  55572. #endif
  55573. BN_free(b);
  55574. BN_free(a);
  55575. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  55576. return EXPECT_RESULT();
  55577. }
  55578. static int test_wolfSSL_BN_word(void)
  55579. {
  55580. EXPECT_DECLS;
  55581. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && !defined(WOLFSSL_SP_MATH)
  55582. BIGNUM* a = NULL;
  55583. BIGNUM* b = NULL;
  55584. BIGNUM* c = NULL;
  55585. BIGNUM av;
  55586. ExpectNotNull(a = BN_new());
  55587. ExpectNotNull(b = BN_new());
  55588. ExpectNotNull(c = BN_new());
  55589. XMEMSET(&av, 0, sizeof(av));
  55590. /* Invalid parameter. */
  55591. ExpectIntEQ(BN_add_word(NULL, 3), 0);
  55592. ExpectIntEQ(BN_add_word(&av, 3), 0);
  55593. ExpectIntEQ(BN_sub_word(NULL, 3), 0);
  55594. ExpectIntEQ(BN_sub_word(&av, 3), 0);
  55595. ExpectIntEQ(BN_set_word(NULL, 3), 0);
  55596. ExpectIntEQ(BN_set_word(&av, 3), 0);
  55597. ExpectIntEQ(BN_get_word(NULL), 0);
  55598. ExpectIntEQ(BN_get_word(&av), 0);
  55599. ExpectIntEQ(BN_is_word(NULL, 3), 0);
  55600. ExpectIntEQ(BN_is_word(&av, 3), 0);
  55601. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_RSA) || !defined(NO_DH) || \
  55602. !defined(NO_DSA))
  55603. ExpectIntEQ(BN_mod_word(NULL, 3), -1);
  55604. ExpectIntEQ(BN_mod_word(&av, 3), -1);
  55605. #endif
  55606. ExpectIntEQ(BN_one(NULL), 0);
  55607. ExpectIntEQ(BN_one(&av), 0);
  55608. BN_zero(NULL);
  55609. BN_zero(&av);
  55610. ExpectIntEQ(BN_is_one(NULL), 0);
  55611. ExpectIntEQ(BN_is_one(&av), 0);
  55612. ExpectIntEQ(BN_is_zero(NULL), 0);
  55613. ExpectIntEQ(BN_is_zero(&av), 0);
  55614. ExpectIntEQ(BN_set_word(a, 3), 1);
  55615. ExpectIntEQ(BN_set_word(b, 2), 1);
  55616. ExpectIntEQ(BN_set_word(c, 5), 1);
  55617. /* a + 3 = */
  55618. ExpectIntEQ(BN_add_word(a, 3), 1);
  55619. /* check result 3 + 3*/
  55620. ExpectIntEQ(BN_get_word(a), 6);
  55621. ExpectIntEQ(BN_is_word(a, 6), 1);
  55622. ExpectIntEQ(BN_is_word(a, 5), 0);
  55623. /* set a back to 3 */
  55624. ExpectIntEQ(BN_set_word(a, 3), 1);
  55625. /* a - 3 = */
  55626. ExpectIntEQ(BN_sub_word(a, 3), 1);
  55627. /* check result 3 - 3*/
  55628. ExpectIntEQ(BN_get_word(a), 0);
  55629. ExpectIntEQ(BN_one(a), 1);
  55630. ExpectIntEQ(BN_is_word(a, 1), 1);
  55631. ExpectIntEQ(BN_is_word(a, 0), 0);
  55632. ExpectIntEQ(BN_is_one(a), 1);
  55633. ExpectIntEQ(BN_is_zero(a), 0);
  55634. BN_zero(a);
  55635. ExpectIntEQ(BN_is_word(a, 0), 1);
  55636. ExpectIntEQ(BN_is_word(a, 1), 0);
  55637. ExpectIntEQ(BN_is_zero(a), 1);
  55638. ExpectIntEQ(BN_is_one(a), 0);
  55639. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_RSA) || !defined(NO_DH) || \
  55640. !defined(NO_DSA))
  55641. ExpectIntEQ(BN_set_word(a, 5), 1);
  55642. ExpectIntEQ(BN_mod_word(a, 3), 2);
  55643. ExpectIntEQ(BN_mod_word(a, 0), -1);
  55644. #endif
  55645. BN_free(c);
  55646. BN_free(b);
  55647. BN_free(a);
  55648. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  55649. return EXPECT_RESULT();
  55650. }
  55651. static int test_wolfSSL_BN_bits(void)
  55652. {
  55653. EXPECT_DECLS;
  55654. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  55655. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  55656. BIGNUM* a = NULL;
  55657. BIGNUM emptyBN;
  55658. /* Setup */
  55659. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  55660. ExpectNotNull(a = BN_new());
  55661. /* Invalid parameters. */
  55662. ExpectIntEQ(BN_set_bit(NULL, 1), 0);
  55663. ExpectIntEQ(BN_set_bit(&emptyBN, 1), 0);
  55664. ExpectIntEQ(BN_set_bit(a, -1), 0);
  55665. ExpectIntEQ(BN_clear_bit(NULL, 1), 0);
  55666. ExpectIntEQ(BN_clear_bit(&emptyBN, 1), 0);
  55667. ExpectIntEQ(BN_clear_bit(a, -1), 0);
  55668. ExpectIntEQ(BN_is_bit_set(NULL, 1), 0);
  55669. ExpectIntEQ(BN_is_bit_set(&emptyBN, 1), 0);
  55670. ExpectIntEQ(BN_is_bit_set(a, -1), 0);
  55671. ExpectIntEQ(BN_is_odd(NULL), 0);
  55672. ExpectIntEQ(BN_is_odd(&emptyBN), 0);
  55673. ExpectIntEQ(BN_set_word(a, 0), 1);
  55674. ExpectIntEQ(BN_is_zero(a), 1);
  55675. ExpectIntEQ(BN_set_bit(a, 0x45), 1);
  55676. ExpectIntEQ(BN_is_zero(a), 0);
  55677. ExpectIntEQ(BN_is_bit_set(a, 0x45), 1);
  55678. ExpectIntEQ(BN_clear_bit(a, 0x45), 1);
  55679. ExpectIntEQ(BN_is_bit_set(a, 0x45), 0);
  55680. ExpectIntEQ(BN_is_zero(a), 1);
  55681. ExpectIntEQ(BN_set_bit(a, 0), 1);
  55682. ExpectIntEQ(BN_is_odd(a), 1);
  55683. ExpectIntEQ(BN_clear_bit(a, 0), 1);
  55684. ExpectIntEQ(BN_is_odd(a), 0);
  55685. ExpectIntEQ(BN_set_bit(a, 1), 1);
  55686. ExpectIntEQ(BN_is_odd(a), 0);
  55687. ExpectIntEQ(BN_set_bit(a, 129), 1);
  55688. ExpectIntEQ(BN_get_word(a), WOLFSSL_BN_MAX_VAL);
  55689. #ifndef NO_WOLFSSL_STUB
  55690. ExpectIntEQ(BN_mask_bits(a, 1), 0);
  55691. #endif
  55692. BN_free(a);
  55693. #endif
  55694. return EXPECT_RESULT();
  55695. }
  55696. static int test_wolfSSL_BN_shift(void)
  55697. {
  55698. EXPECT_DECLS;
  55699. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  55700. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  55701. BIGNUM* a = NULL;
  55702. BIGNUM* b = NULL;
  55703. BIGNUM emptyBN;
  55704. /* Setup */
  55705. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  55706. ExpectNotNull(a = BN_new());
  55707. ExpectNotNull(b = BN_new());
  55708. /* Invalid parameters. */
  55709. ExpectIntEQ(BN_lshift(NULL, NULL, 1), 0);
  55710. ExpectIntEQ(BN_lshift(&emptyBN, NULL, 1), 0);
  55711. ExpectIntEQ(BN_lshift(NULL, &emptyBN, 1), 0);
  55712. ExpectIntEQ(BN_lshift(b, NULL, 1), 0);
  55713. ExpectIntEQ(BN_lshift(b, &emptyBN, 1), 0);
  55714. ExpectIntEQ(BN_lshift(NULL, a, 1), 0);
  55715. ExpectIntEQ(BN_lshift(&emptyBN, a, 1), 0);
  55716. ExpectIntEQ(BN_lshift(b, a, -1), 0);
  55717. ExpectIntEQ(BN_rshift(NULL, NULL, 1), 0);
  55718. ExpectIntEQ(BN_rshift(&emptyBN, NULL, 1), 0);
  55719. ExpectIntEQ(BN_rshift(NULL, &emptyBN, 1), 0);
  55720. ExpectIntEQ(BN_rshift(b, NULL, 1), 0);
  55721. ExpectIntEQ(BN_rshift(b, &emptyBN, 1), 0);
  55722. ExpectIntEQ(BN_rshift(NULL, a, 1), 0);
  55723. ExpectIntEQ(BN_rshift(&emptyBN, a, 1), 0);
  55724. ExpectIntEQ(BN_rshift(b, a, -1), 0);
  55725. ExpectIntEQ(BN_set_word(a, 1), 1);
  55726. ExpectIntEQ(BN_lshift(b, a, 1), 1);
  55727. ExpectIntEQ(BN_is_word(b, 2), 1);
  55728. ExpectIntEQ(BN_lshift(a, a, 1), 1);
  55729. ExpectIntEQ(BN_is_word(a, 2), 1);
  55730. ExpectIntEQ(BN_rshift(b, a, 1), 1);
  55731. ExpectIntEQ(BN_is_word(b, 1), 1);
  55732. ExpectIntEQ(BN_rshift(a, a, 1), 1);
  55733. ExpectIntEQ(BN_is_word(a, 1), 1);
  55734. BN_free(b);
  55735. BN_free(a);
  55736. #endif
  55737. return EXPECT_RESULT();
  55738. }
  55739. static int test_wolfSSL_BN_math(void)
  55740. {
  55741. EXPECT_DECLS;
  55742. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  55743. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  55744. BIGNUM* a = NULL;
  55745. BIGNUM* b = NULL;
  55746. BIGNUM* r = NULL;
  55747. BIGNUM* rem = NULL;
  55748. BIGNUM emptyBN;
  55749. BN_ULONG val1;
  55750. BN_ULONG val2;
  55751. /* Setup */
  55752. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  55753. ExpectNotNull(a = BN_new());
  55754. ExpectNotNull(b = BN_new());
  55755. ExpectNotNull(r = BN_new());
  55756. ExpectNotNull(rem = BN_new());
  55757. /* Invalid parameters. */
  55758. ExpectIntEQ(BN_add(NULL, NULL, NULL), 0);
  55759. ExpectIntEQ(BN_add(r, NULL, NULL), 0);
  55760. ExpectIntEQ(BN_add(NULL, a, NULL), 0);
  55761. ExpectIntEQ(BN_add(NULL, NULL, b), 0);
  55762. ExpectIntEQ(BN_add(r, a, NULL), 0);
  55763. ExpectIntEQ(BN_add(r, NULL, b), 0);
  55764. ExpectIntEQ(BN_add(NULL, a, b), 0);
  55765. ExpectIntEQ(BN_add(&emptyBN, &emptyBN, &emptyBN), 0);
  55766. ExpectIntEQ(BN_add(r, &emptyBN, &emptyBN), 0);
  55767. ExpectIntEQ(BN_add(&emptyBN, a, &emptyBN), 0);
  55768. ExpectIntEQ(BN_add(&emptyBN, &emptyBN, b), 0);
  55769. ExpectIntEQ(BN_add(r, a, &emptyBN), 0);
  55770. ExpectIntEQ(BN_add(r, &emptyBN, b), 0);
  55771. ExpectIntEQ(BN_add(&emptyBN, a, b), 0);
  55772. ExpectIntEQ(BN_sub(NULL, NULL, NULL), 0);
  55773. ExpectIntEQ(BN_sub(r, NULL, NULL), 0);
  55774. ExpectIntEQ(BN_sub(NULL, a, NULL), 0);
  55775. ExpectIntEQ(BN_sub(NULL, NULL, b), 0);
  55776. ExpectIntEQ(BN_sub(r, a, NULL), 0);
  55777. ExpectIntEQ(BN_sub(r, NULL, b), 0);
  55778. ExpectIntEQ(BN_sub(NULL, a, b), 0);
  55779. ExpectIntEQ(BN_sub(&emptyBN, &emptyBN, &emptyBN), 0);
  55780. ExpectIntEQ(BN_sub(r, &emptyBN, &emptyBN), 0);
  55781. ExpectIntEQ(BN_sub(&emptyBN, a, &emptyBN), 0);
  55782. ExpectIntEQ(BN_sub(&emptyBN, &emptyBN, b), 0);
  55783. ExpectIntEQ(BN_sub(r, a, &emptyBN), 0);
  55784. ExpectIntEQ(BN_sub(r, &emptyBN, b), 0);
  55785. ExpectIntEQ(BN_sub(&emptyBN, a, b), 0);
  55786. ExpectIntEQ(BN_mul(NULL, NULL, NULL, NULL), 0);
  55787. ExpectIntEQ(BN_mul(r, NULL, NULL, NULL), 0);
  55788. ExpectIntEQ(BN_mul(NULL, a, NULL, NULL), 0);
  55789. ExpectIntEQ(BN_mul(NULL, NULL, b, NULL), 0);
  55790. ExpectIntEQ(BN_mul(r, a, NULL, NULL), 0);
  55791. ExpectIntEQ(BN_mul(r, NULL, b, NULL), 0);
  55792. ExpectIntEQ(BN_mul(NULL, a, b, NULL), 0);
  55793. ExpectIntEQ(BN_mul(&emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55794. ExpectIntEQ(BN_mul(r, &emptyBN, &emptyBN, NULL), 0);
  55795. ExpectIntEQ(BN_mul(&emptyBN, a, &emptyBN, NULL), 0);
  55796. ExpectIntEQ(BN_mul(&emptyBN, &emptyBN, b, NULL), 0);
  55797. ExpectIntEQ(BN_mul(r, a, &emptyBN, NULL), 0);
  55798. ExpectIntEQ(BN_mul(r, &emptyBN, b, NULL), 0);
  55799. ExpectIntEQ(BN_mul(&emptyBN, a, b, NULL), 0);
  55800. ExpectIntEQ(BN_div(NULL, NULL, NULL, NULL, NULL), 0);
  55801. ExpectIntEQ(BN_div(r, NULL, NULL, NULL, NULL), 0);
  55802. ExpectIntEQ(BN_div(NULL, rem, NULL, NULL, NULL), 0);
  55803. ExpectIntEQ(BN_div(NULL, NULL, a, NULL, NULL), 0);
  55804. ExpectIntEQ(BN_div(NULL, NULL, NULL, b, NULL), 0);
  55805. ExpectIntEQ(BN_div(NULL, rem, a, b, NULL), 0);
  55806. ExpectIntEQ(BN_div(r, NULL, a, b, NULL), 0);
  55807. ExpectIntEQ(BN_div(r, rem, NULL, b, NULL), 0);
  55808. ExpectIntEQ(BN_div(r, rem, a, NULL, NULL), 0);
  55809. ExpectIntEQ(BN_div(&emptyBN, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55810. ExpectIntEQ(BN_div(r, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55811. ExpectIntEQ(BN_div(&emptyBN, rem, &emptyBN, &emptyBN, NULL), 0);
  55812. ExpectIntEQ(BN_div(&emptyBN, &emptyBN, a, &emptyBN, NULL), 0);
  55813. ExpectIntEQ(BN_div(&emptyBN, &emptyBN, &emptyBN, b, NULL), 0);
  55814. ExpectIntEQ(BN_div(&emptyBN, rem, a, b, NULL), 0);
  55815. ExpectIntEQ(BN_div(r, &emptyBN, a, b, NULL), 0);
  55816. ExpectIntEQ(BN_div(r, rem, &emptyBN, b, NULL), 0);
  55817. ExpectIntEQ(BN_div(r, rem, a, &emptyBN, NULL), 0);
  55818. ExpectIntEQ(BN_mod(NULL, NULL, NULL, NULL), 0);
  55819. ExpectIntEQ(BN_mod(r, NULL, NULL, NULL), 0);
  55820. ExpectIntEQ(BN_mod(NULL, a, NULL, NULL), 0);
  55821. ExpectIntEQ(BN_mod(NULL, NULL, b, NULL), 0);
  55822. ExpectIntEQ(BN_mod(r, a, NULL, NULL), 0);
  55823. ExpectIntEQ(BN_mod(r, NULL, b, NULL), 0);
  55824. ExpectIntEQ(BN_mod(NULL, a, b, NULL), 0);
  55825. ExpectIntEQ(BN_mod(&emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55826. ExpectIntEQ(BN_mod(r, &emptyBN, &emptyBN, NULL), 0);
  55827. ExpectIntEQ(BN_mod(&emptyBN, a, &emptyBN, NULL), 0);
  55828. ExpectIntEQ(BN_mod(&emptyBN, &emptyBN, b, NULL), 0);
  55829. ExpectIntEQ(BN_mod(r, a, &emptyBN, NULL), 0);
  55830. ExpectIntEQ(BN_mod(r, &emptyBN, b, NULL), 0);
  55831. ExpectIntEQ(BN_mod(&emptyBN, a, b, NULL), 0);
  55832. /* END Invalid parameters. */
  55833. val1 = 8;
  55834. val2 = 3;
  55835. ExpectIntEQ(BN_set_word(a, val1), 1);
  55836. ExpectIntEQ(BN_set_word(b, val2), 1);
  55837. ExpectIntEQ(BN_add(r, a, b), 1);
  55838. ExpectIntEQ(BN_is_word(r, val1 + val2), 1);
  55839. ExpectIntEQ(BN_sub(r, a, b), 1);
  55840. ExpectIntEQ(BN_is_word(r, val1 - val2), 1);
  55841. ExpectIntEQ(BN_mul(r, a, b, NULL), 1);
  55842. ExpectIntEQ(BN_is_word(r, val1 * val2), 1);
  55843. ExpectIntEQ(BN_div(r, rem, a, b, NULL), 1);
  55844. ExpectIntEQ(BN_is_word(r, val1 / val2), 1);
  55845. ExpectIntEQ(BN_is_word(rem, val1 % val2), 1);
  55846. ExpectIntEQ(BN_mod(r, a, b, NULL), 1);
  55847. ExpectIntEQ(BN_is_word(r, val1 % val2), 1);
  55848. BN_free(rem);
  55849. BN_free(r);
  55850. BN_free(b);
  55851. BN_free(a);
  55852. #endif
  55853. return EXPECT_RESULT();
  55854. }
  55855. static int test_wolfSSL_BN_math_mod(void)
  55856. {
  55857. EXPECT_DECLS;
  55858. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  55859. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  55860. BIGNUM* a = NULL;
  55861. BIGNUM* b = NULL;
  55862. BIGNUM* m = NULL;
  55863. BIGNUM* r = NULL;
  55864. BIGNUM* t = NULL;
  55865. BIGNUM emptyBN;
  55866. BN_ULONG val1;
  55867. BN_ULONG val2;
  55868. BN_ULONG val3;
  55869. /* Setup */
  55870. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  55871. ExpectNotNull(a = BN_new());
  55872. ExpectNotNull(b = BN_new());
  55873. ExpectNotNull(m = BN_new());
  55874. ExpectNotNull(r = BN_new());
  55875. /* Invalid parameters. */
  55876. ExpectIntEQ(BN_mod_add(NULL, NULL, NULL, NULL, NULL), 0);
  55877. ExpectIntEQ(BN_mod_add(r, NULL, NULL, NULL, NULL), 0);
  55878. ExpectIntEQ(BN_mod_add(NULL, a, NULL, NULL, NULL), 0);
  55879. ExpectIntEQ(BN_mod_add(NULL, NULL, b, NULL, NULL), 0);
  55880. ExpectIntEQ(BN_mod_add(NULL, NULL, NULL, m, NULL), 0);
  55881. ExpectIntEQ(BN_mod_add(NULL, a, b, m, NULL), 0);
  55882. ExpectIntEQ(BN_mod_add(r, NULL, b, m, NULL), 0);
  55883. ExpectIntEQ(BN_mod_add(r, a, NULL, m, NULL), 0);
  55884. ExpectIntEQ(BN_mod_add(r, a, m, NULL, NULL), 0);
  55885. ExpectIntEQ(BN_mod_add(&emptyBN, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55886. ExpectIntEQ(BN_mod_add(r, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55887. ExpectIntEQ(BN_mod_add(&emptyBN, a, &emptyBN, &emptyBN, NULL), 0);
  55888. ExpectIntEQ(BN_mod_add(&emptyBN, &emptyBN, b, &emptyBN, NULL), 0);
  55889. ExpectIntEQ(BN_mod_add(&emptyBN, &emptyBN, &emptyBN, m, NULL), 0);
  55890. ExpectIntEQ(BN_mod_add(&emptyBN, a, b, m, NULL), 0);
  55891. ExpectIntEQ(BN_mod_add(r, &emptyBN, b, m, NULL), 0);
  55892. ExpectIntEQ(BN_mod_add(r, a, &emptyBN, m, NULL), 0);
  55893. ExpectIntEQ(BN_mod_add(r, a, m, &emptyBN, NULL), 0);
  55894. ExpectIntEQ(BN_mod_mul(NULL, NULL, NULL, NULL, NULL), 0);
  55895. ExpectIntEQ(BN_mod_mul(r, NULL, NULL, NULL, NULL), 0);
  55896. ExpectIntEQ(BN_mod_mul(NULL, a, NULL, NULL, NULL), 0);
  55897. ExpectIntEQ(BN_mod_mul(NULL, NULL, b, NULL, NULL), 0);
  55898. ExpectIntEQ(BN_mod_mul(NULL, NULL, NULL, m, NULL), 0);
  55899. ExpectIntEQ(BN_mod_mul(NULL, a, b, m, NULL), 0);
  55900. ExpectIntEQ(BN_mod_mul(r, NULL, b, m, NULL), 0);
  55901. ExpectIntEQ(BN_mod_mul(r, a, NULL, m, NULL), 0);
  55902. ExpectIntEQ(BN_mod_mul(r, a, m, NULL, NULL), 0);
  55903. ExpectIntEQ(BN_mod_mul(&emptyBN, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55904. ExpectIntEQ(BN_mod_mul(r, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55905. ExpectIntEQ(BN_mod_mul(&emptyBN, a, &emptyBN, &emptyBN, NULL), 0);
  55906. ExpectIntEQ(BN_mod_mul(&emptyBN, &emptyBN, b, &emptyBN, NULL), 0);
  55907. ExpectIntEQ(BN_mod_mul(&emptyBN, &emptyBN, &emptyBN, m, NULL), 0);
  55908. ExpectIntEQ(BN_mod_mul(&emptyBN, a, b, m, NULL), 0);
  55909. ExpectIntEQ(BN_mod_mul(r, &emptyBN, b, m, NULL), 0);
  55910. ExpectIntEQ(BN_mod_mul(r, a, &emptyBN, m, NULL), 0);
  55911. ExpectIntEQ(BN_mod_mul(r, a, m, &emptyBN, NULL), 0);
  55912. ExpectIntEQ(BN_mod_exp(NULL, NULL, NULL, NULL, NULL), 0);
  55913. ExpectIntEQ(BN_mod_exp(r, NULL, NULL, NULL, NULL), 0);
  55914. ExpectIntEQ(BN_mod_exp(NULL, a, NULL, NULL, NULL), 0);
  55915. ExpectIntEQ(BN_mod_exp(NULL, NULL, b, NULL, NULL), 0);
  55916. ExpectIntEQ(BN_mod_exp(NULL, NULL, NULL, m, NULL), 0);
  55917. ExpectIntEQ(BN_mod_exp(NULL, a, b, m, NULL), 0);
  55918. ExpectIntEQ(BN_mod_exp(r, NULL, b, m, NULL), 0);
  55919. ExpectIntEQ(BN_mod_exp(r, a, NULL, m, NULL), 0);
  55920. ExpectIntEQ(BN_mod_exp(r, a, m, NULL, NULL), 0);
  55921. ExpectIntEQ(BN_mod_exp(&emptyBN, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55922. ExpectIntEQ(BN_mod_exp(r, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  55923. ExpectIntEQ(BN_mod_exp(&emptyBN, a, &emptyBN, &emptyBN, NULL), 0);
  55924. ExpectIntEQ(BN_mod_exp(&emptyBN, &emptyBN, b, &emptyBN, NULL), 0);
  55925. ExpectIntEQ(BN_mod_exp(&emptyBN, &emptyBN, &emptyBN, m, NULL), 0);
  55926. ExpectIntEQ(BN_mod_exp(&emptyBN, a, b, m, NULL), 0);
  55927. ExpectIntEQ(BN_mod_exp(r, &emptyBN, b, m, NULL), 0);
  55928. ExpectIntEQ(BN_mod_exp(r, a, &emptyBN, m, NULL), 0);
  55929. ExpectIntEQ(BN_mod_exp(r, a, m, &emptyBN, NULL), 0);
  55930. ExpectNull(BN_mod_inverse(r, NULL, NULL, NULL));
  55931. ExpectNull(BN_mod_inverse(r, a, NULL, NULL));
  55932. ExpectNull(BN_mod_inverse(r, NULL, m, NULL));
  55933. ExpectNull(BN_mod_inverse(r, NULL, m, NULL));
  55934. ExpectNull(BN_mod_inverse(r, a, NULL, NULL));
  55935. ExpectNull(BN_mod_inverse(&emptyBN, &emptyBN, &emptyBN, NULL));
  55936. ExpectNull(BN_mod_inverse(r, &emptyBN, &emptyBN, NULL));
  55937. ExpectNull(BN_mod_inverse(&emptyBN, a, &emptyBN, NULL));
  55938. ExpectNull(BN_mod_inverse(&emptyBN, &emptyBN, m, NULL));
  55939. ExpectNull(BN_mod_inverse(&emptyBN, a, m, NULL));
  55940. ExpectNull(BN_mod_inverse(r, &emptyBN, m, NULL));
  55941. ExpectNull(BN_mod_inverse(r, a, &emptyBN, NULL));
  55942. /* END Invalid parameters. */
  55943. val1 = 9;
  55944. val2 = 13;
  55945. val3 = 5;
  55946. ExpectIntEQ(BN_set_word(a, val1), 1);
  55947. ExpectIntEQ(BN_set_word(b, val2), 1);
  55948. ExpectIntEQ(BN_set_word(m, val3), 1);
  55949. ExpectIntEQ(BN_mod_add(r, a, b, m, NULL), 1);
  55950. ExpectIntEQ(BN_is_word(r, (val1 + val2) % val3), 1);
  55951. ExpectIntEQ(BN_mod_mul(r, a, b, m, NULL), 1);
  55952. ExpectIntEQ(BN_is_word(r, (val1 * val2) % val3), 1);
  55953. ExpectIntEQ(BN_set_word(a, 2), 1);
  55954. ExpectIntEQ(BN_set_word(b, 3), 1);
  55955. ExpectIntEQ(BN_set_word(m, 5), 1);
  55956. /* (2 ^ 3) % 5 = 8 % 5 = 3 */
  55957. ExpectIntEQ(BN_mod_exp(r, a, b, m, NULL), 1);
  55958. ExpectIntEQ(BN_is_word(r, 3), 1);
  55959. /* (2 * 3) % 5 = 6 % 5 = 1 => inv = 3 */
  55960. ExpectNotNull(BN_mod_inverse(r, a, m, NULL));
  55961. ExpectIntEQ(BN_is_word(r, 3), 1);
  55962. ExpectNotNull(t = BN_mod_inverse(NULL, a, m, NULL));
  55963. ExpectIntEQ(BN_is_word(t, 3), 1);
  55964. BN_free(t);
  55965. /* No inverse case. No inverse when a divides b. */
  55966. ExpectIntEQ(BN_set_word(a, 3), 1);
  55967. ExpectIntEQ(BN_set_word(m, 9), 1);
  55968. ExpectNull(BN_mod_inverse(r, a, m, NULL));
  55969. BN_free(r);
  55970. BN_free(m);
  55971. BN_free(b);
  55972. BN_free(a);
  55973. #endif
  55974. return EXPECT_RESULT();
  55975. }
  55976. static int test_wolfSSL_BN_math_other(void)
  55977. {
  55978. EXPECT_DECLS;
  55979. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  55980. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  55981. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  55982. BIGNUM* a = NULL;
  55983. BIGNUM* b = NULL;
  55984. BIGNUM* r = NULL;
  55985. BIGNUM emptyBN;
  55986. /* Setup */
  55987. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  55988. ExpectNotNull(a = BN_new());
  55989. ExpectNotNull(b = BN_new());
  55990. ExpectNotNull(r = BN_new());
  55991. /* Invalid parameters. */
  55992. ExpectIntEQ(BN_gcd(NULL, NULL, NULL, NULL), 0);
  55993. ExpectIntEQ(BN_gcd(r, NULL, NULL, NULL), 0);
  55994. ExpectIntEQ(BN_gcd(NULL, a, NULL, NULL), 0);
  55995. ExpectIntEQ(BN_gcd(NULL, NULL, b, NULL), 0);
  55996. ExpectIntEQ(BN_gcd(NULL, a, b, NULL), 0);
  55997. ExpectIntEQ(BN_gcd(r, NULL, b, NULL), 0);
  55998. ExpectIntEQ(BN_gcd(r, a, NULL, NULL), 0);
  55999. ExpectIntEQ(BN_gcd(&emptyBN, &emptyBN, &emptyBN, NULL), 0);
  56000. ExpectIntEQ(BN_gcd(r, &emptyBN, &emptyBN, NULL), 0);
  56001. ExpectIntEQ(BN_gcd(&emptyBN, a, &emptyBN, NULL), 0);
  56002. ExpectIntEQ(BN_gcd(&emptyBN, &emptyBN, b, NULL), 0);
  56003. ExpectIntEQ(BN_gcd(&emptyBN, a, b, NULL), 0);
  56004. ExpectIntEQ(BN_gcd(r, &emptyBN, b, NULL), 0);
  56005. ExpectIntEQ(BN_gcd(r, a, &emptyBN, NULL), 0);
  56006. /* END Invalid parameters. */
  56007. /* No common factors between 2 and 3. */
  56008. ExpectIntEQ(BN_set_word(a, 2), 1);
  56009. ExpectIntEQ(BN_set_word(b, 3), 1);
  56010. ExpectIntEQ(BN_gcd(r, a, b, NULL), 1);
  56011. ExpectIntEQ(BN_is_word(r, 1), 1);
  56012. /* 3 is largest value that divides both 6 and 9. */
  56013. ExpectIntEQ(BN_set_word(a, 6), 1);
  56014. ExpectIntEQ(BN_set_word(b, 9), 1);
  56015. ExpectIntEQ(BN_gcd(r, a, b, NULL), 1);
  56016. ExpectIntEQ(BN_is_word(r, 3), 1);
  56017. /* GCD of 0 and 0 is undefined. */
  56018. ExpectIntEQ(BN_set_word(a, 0), 1);
  56019. ExpectIntEQ(BN_set_word(b, 0), 1);
  56020. ExpectIntEQ(BN_gcd(r, a, b, NULL), 0);
  56021. /* Teardown */
  56022. BN_free(r);
  56023. BN_free(b);
  56024. BN_free(a);
  56025. #endif
  56026. #endif
  56027. return EXPECT_RESULT();
  56028. }
  56029. static int test_wolfSSL_BN_rand(void)
  56030. {
  56031. EXPECT_DECLS;
  56032. #if defined(OPENSSL_EXTRA) && !defined(OPENSSL_EXTRA_NO_BN)
  56033. BIGNUM* bn = NULL;
  56034. BIGNUM* range = NULL;
  56035. BIGNUM emptyBN;
  56036. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  56037. ExpectNotNull(bn = BN_new());
  56038. ExpectNotNull(range = BN_new());
  56039. /* Invalid parameters. */
  56040. ExpectIntEQ(BN_rand(NULL, -1, 0, 0), 0);
  56041. ExpectIntEQ(BN_rand(bn, -1, 0, 0), 0);
  56042. ExpectIntEQ(BN_rand(NULL, 1, 0, 0), 0);
  56043. ExpectIntEQ(BN_rand(&emptyBN, -1, 0, 0), 0);
  56044. ExpectIntEQ(BN_rand(bn, -1, 0, 0), 0);
  56045. ExpectIntEQ(BN_rand(&emptyBN, 1, 0, 0), 0);
  56046. ExpectIntEQ(BN_pseudo_rand(NULL, -1, 0, 0), 0);
  56047. ExpectIntEQ(BN_pseudo_rand(bn, -1, 0, 0), 0);
  56048. ExpectIntEQ(BN_pseudo_rand(NULL, 1, 0, 0), 0);
  56049. ExpectIntEQ(BN_pseudo_rand(&emptyBN, -1, 0, 0), 0);
  56050. ExpectIntEQ(BN_pseudo_rand(bn, -1, 0, 0), 0);
  56051. ExpectIntEQ(BN_pseudo_rand(&emptyBN, 1, 0, 0), 0);
  56052. ExpectIntEQ(BN_rand_range(NULL, NULL), 0);
  56053. ExpectIntEQ(BN_rand_range(bn, NULL), 0);
  56054. ExpectIntEQ(BN_rand_range(NULL, range), 0);
  56055. ExpectIntEQ(BN_rand_range(&emptyBN, &emptyBN), 0);
  56056. ExpectIntEQ(BN_rand_range(bn, &emptyBN), 0);
  56057. ExpectIntEQ(BN_rand_range(&emptyBN, range), 0);
  56058. /* 0 bit random value must be 0 and so cannot set bit in any position. */
  56059. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ONE,
  56060. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  56061. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_TWO,
  56062. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  56063. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ANY,
  56064. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  56065. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ONE,
  56066. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  56067. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_TWO,
  56068. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  56069. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ONE,
  56070. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  56071. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_TWO,
  56072. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  56073. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ANY,
  56074. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  56075. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ONE,
  56076. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  56077. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_TWO,
  56078. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  56079. /* 1 bit random value must have no more than one top bit set. */
  56080. ExpectIntEQ(BN_rand(bn, 1, WOLFSSL_BN_RAND_TOP_TWO,
  56081. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  56082. ExpectIntEQ(BN_rand(bn, 1, WOLFSSL_BN_RAND_TOP_TWO,
  56083. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  56084. ExpectIntEQ(BN_pseudo_rand(bn, 1, WOLFSSL_BN_RAND_TOP_TWO,
  56085. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  56086. ExpectIntEQ(BN_pseudo_rand(bn, 1, WOLFSSL_BN_RAND_TOP_TWO,
  56087. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  56088. /* END Invalid parameters. */
  56089. /* 0 bit random: 0. */
  56090. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ANY,
  56091. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56092. ExpectIntEQ(BN_is_zero(bn), 1);
  56093. ExpectIntEQ(BN_set_word(bn, 2), 1); /* Make sure not zero. */
  56094. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ANY,
  56095. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56096. ExpectIntEQ(BN_is_zero(bn), 1);
  56097. /* 1 bit random: 0 or 1. */
  56098. ExpectIntEQ(BN_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ANY,
  56099. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56100. ExpectIntLT(BN_get_word(bn), 2); /* Make sure valid range. */
  56101. ExpectIntEQ(BN_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ONE,
  56102. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56103. ExpectIntEQ(BN_get_word(bn), 1);
  56104. ExpectIntEQ(BN_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ONE,
  56105. WOLFSSL_BN_RAND_BOTTOM_ODD), 1);
  56106. ExpectIntEQ(BN_get_word(bn), 1);
  56107. ExpectIntEQ(BN_pseudo_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ANY,
  56108. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56109. ExpectIntLT(BN_get_word(bn), 2); /* Make sure valid range. */
  56110. ExpectIntEQ(BN_pseudo_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ONE,
  56111. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56112. ExpectIntEQ(BN_get_word(bn), 1);
  56113. ExpectIntEQ(BN_pseudo_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ONE,
  56114. WOLFSSL_BN_RAND_BOTTOM_ODD), 1);
  56115. ExpectIntEQ(BN_get_word(bn), 1);
  56116. ExpectIntEQ(BN_rand(bn, 8, WOLFSSL_BN_RAND_TOP_ONE,
  56117. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56118. ExpectIntEQ(BN_num_bits(bn), 8);
  56119. ExpectIntEQ(BN_is_bit_set(bn, 7), 1);
  56120. ExpectIntEQ(BN_pseudo_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_rand(bn, 8, WOLFSSL_BN_RAND_TOP_TWO,
  56125. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56126. ExpectIntEQ(BN_is_bit_set(bn, 7), 1);
  56127. ExpectIntEQ(BN_is_bit_set(bn, 6), 1);
  56128. ExpectIntEQ(BN_pseudo_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_rand(bn, 8, WOLFSSL_BN_RAND_TOP_ONE,
  56133. WOLFSSL_BN_RAND_BOTTOM_ODD), 1);
  56134. ExpectIntEQ(BN_is_bit_set(bn, 0), 1);
  56135. ExpectIntEQ(BN_pseudo_rand(bn, 8, WOLFSSL_BN_RAND_TOP_ONE,
  56136. WOLFSSL_BN_RAND_BOTTOM_ODD), 1);
  56137. ExpectIntEQ(BN_is_bit_set(bn, 0), 1);
  56138. /* Regression test: Older versions of wolfSSL_BN_rand would round the
  56139. * requested number of bits up to the nearest multiple of 8. E.g. in this
  56140. * case, requesting a 13-bit random number would actually return a 16-bit
  56141. * random number. */
  56142. ExpectIntEQ(BN_rand(bn, 13, WOLFSSL_BN_RAND_TOP_ONE,
  56143. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56144. ExpectIntEQ(BN_num_bits(bn), 13);
  56145. ExpectIntEQ(BN_rand(range, 64, WOLFSSL_BN_RAND_TOP_ONE,
  56146. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  56147. ExpectIntEQ(BN_rand_range(bn, range), 1);
  56148. ExpectIntEQ(BN_set_word(range, 0), 1);
  56149. ExpectIntEQ(BN_rand_range(bn, range), 1);
  56150. ExpectIntEQ(BN_set_word(range, 1), 1);
  56151. ExpectIntEQ(BN_rand_range(bn, range), 1);
  56152. BN_free(bn);
  56153. BN_free(range);
  56154. #endif
  56155. return EXPECT_RESULT();
  56156. }
  56157. static int test_wolfSSL_BN_prime(void)
  56158. {
  56159. EXPECT_DECLS;
  56160. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  56161. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  56162. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_RSA) || !defined(NO_DH) || !defined(NO_DSA))
  56163. BIGNUM* a = NULL;
  56164. BIGNUM* add = NULL;
  56165. BIGNUM* rem = NULL;
  56166. BIGNUM emptyBN;
  56167. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  56168. ExpectNotNull(a = BN_new());
  56169. ExpectNotNull(add = BN_new());
  56170. ExpectNotNull(rem = BN_new());
  56171. /* Invalid parameters. */
  56172. /* BN_generate_prime_ex()
  56173. * prime - must have valid BIGNUM
  56174. * bits - Greater then 0
  56175. * safe - not supported, must be 0
  56176. * add - not supported, must be NULL
  56177. * rem - not supported, must be NULL
  56178. * cb - anything
  56179. */
  56180. ExpectIntEQ(BN_generate_prime_ex(NULL, -1, 1, add, rem, NULL), 0);
  56181. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, -1, 1, add, rem, NULL), 0);
  56182. ExpectIntEQ(BN_generate_prime_ex(a, -1, 1, add, rem, NULL), 0);
  56183. ExpectIntEQ(BN_generate_prime_ex(NULL, 2, 1, add, rem, NULL), 0);
  56184. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, 2, 1, add, rem, NULL), 0);
  56185. ExpectIntEQ(BN_generate_prime_ex(NULL, -1, 0, add, rem, NULL), 0);
  56186. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, -1, 0, add, rem, NULL), 0);
  56187. ExpectIntEQ(BN_generate_prime_ex(NULL, -1, 1, NULL, rem, NULL), 0);
  56188. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, -1, 1, NULL, rem, NULL), 0);
  56189. ExpectIntEQ(BN_generate_prime_ex(NULL, -1, 1, add, NULL, NULL), 0);
  56190. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, -1, 1, add, NULL, NULL), 0);
  56191. ExpectIntEQ(BN_generate_prime_ex(NULL, 2, 0, NULL, NULL, NULL), 0);
  56192. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, 2, 0, NULL, NULL, NULL), 0);
  56193. ExpectIntEQ(BN_generate_prime_ex(a, -1, 0, NULL, NULL, NULL), 0);
  56194. ExpectIntEQ(BN_generate_prime_ex(a, 0, 0, NULL, NULL, NULL), 0);
  56195. ExpectIntEQ(BN_generate_prime_ex(a, 2, 1, NULL, NULL, NULL), 0);
  56196. ExpectIntEQ(BN_generate_prime_ex(a, 2, 0, add, NULL, NULL), 0);
  56197. ExpectIntEQ(BN_generate_prime_ex(a, 2, 0, NULL, rem, NULL), 0);
  56198. ExpectIntEQ(BN_is_prime_ex(NULL, -1, NULL, NULL), -1);
  56199. ExpectIntEQ(BN_is_prime_ex(&emptyBN, -1, NULL, NULL), -1);
  56200. ExpectIntEQ(BN_is_prime_ex(a, -1, NULL, NULL), -1);
  56201. ExpectIntEQ(BN_is_prime_ex(a, 2048, NULL, NULL), -1);
  56202. ExpectIntEQ(BN_is_prime_ex(NULL, 1, NULL, NULL), -1);
  56203. ExpectIntEQ(BN_is_prime_ex(&emptyBN, 1, NULL, NULL), -1);
  56204. /* END Invalid parameters. */
  56205. ExpectIntEQ(BN_generate_prime_ex(a, 512, 0, NULL, NULL, NULL), 1);
  56206. ExpectIntEQ(BN_is_prime_ex(a, 8, NULL, NULL), 1);
  56207. ExpectIntEQ(BN_clear_bit(a, 0), 1);
  56208. ExpectIntEQ(BN_is_prime_ex(a, 8, NULL, NULL), 0);
  56209. BN_free(rem);
  56210. BN_free(add);
  56211. BN_free(a);
  56212. #endif
  56213. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  56214. return EXPECT_RESULT();
  56215. }
  56216. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  56217. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  56218. #define TEST_ARG 0x1234
  56219. static void msg_cb(int write_p, int version, int content_type,
  56220. const void *buf, size_t len, SSL *ssl, void *arg)
  56221. {
  56222. (void)write_p;
  56223. (void)version;
  56224. (void)content_type;
  56225. (void)buf;
  56226. (void)len;
  56227. (void)ssl;
  56228. AssertTrue(arg == (void*)TEST_ARG);
  56229. }
  56230. #endif
  56231. #if defined(OPENSSL_EXTRA) && defined(DEBUG_WOLFSSL) && \
  56232. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  56233. #if defined(SESSION_CERTS)
  56234. #include "wolfssl/internal.h"
  56235. #endif
  56236. static int msgCb(SSL_CTX *ctx, SSL *ssl)
  56237. {
  56238. EXPECT_DECLS;
  56239. #if defined(OPENSSL_ALL) && defined(SESSION_CERTS) && !defined(NO_BIO)
  56240. STACK_OF(X509)* sk = NULL;
  56241. X509* x509 = NULL;
  56242. int i, num;
  56243. BIO* bio = NULL;
  56244. #endif
  56245. ExpectNotNull(ctx);
  56246. ExpectNotNull(ssl);
  56247. fprintf(stderr, "\n===== msgcb called ====\n");
  56248. #if defined(SESSION_CERTS) && defined(TEST_PEER_CERT_CHAIN)
  56249. ExpectTrue(SSL_get_peer_cert_chain(ssl) != NULL);
  56250. ExpectIntEQ(((WOLFSSL_X509_CHAIN *)SSL_get_peer_cert_chain(ssl))->count, 2);
  56251. ExpectNotNull(SSL_get0_verified_chain(ssl));
  56252. #endif
  56253. #if defined(OPENSSL_ALL) && defined(SESSION_CERTS) && !defined(NO_BIO)
  56254. ExpectNotNull(bio = BIO_new_fp(stderr, BIO_NOCLOSE));
  56255. ExpectNotNull(sk = SSL_get_peer_cert_chain(ssl));
  56256. if (sk == NULL) {
  56257. BIO_free(bio);
  56258. return TEST_FAIL;
  56259. }
  56260. num = sk_X509_num(sk);
  56261. ExpectTrue(num > 0);
  56262. for (i = 0; i < num; i++) {
  56263. ExpectNotNull(x509 = sk_X509_value(sk,i));
  56264. if (x509 == NULL)
  56265. break;
  56266. fprintf(stderr, "Certificate at index [%d] = :\n",i);
  56267. X509_print(bio,x509);
  56268. fprintf(stderr, "\n\n");
  56269. }
  56270. BIO_free(bio);
  56271. #endif
  56272. return EXPECT_RESULT();
  56273. }
  56274. #endif
  56275. static int test_wolfSSL_msgCb(void)
  56276. {
  56277. EXPECT_DECLS;
  56278. #if defined(OPENSSL_EXTRA) && defined(DEBUG_WOLFSSL) && \
  56279. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  56280. test_ssl_cbf client_cb;
  56281. test_ssl_cbf server_cb;
  56282. XMEMSET(&client_cb, 0, sizeof(client_cb));
  56283. XMEMSET(&server_cb, 0, sizeof(server_cb));
  56284. #ifndef WOLFSSL_NO_TLS12
  56285. client_cb.method = wolfTLSv1_2_client_method;
  56286. server_cb.method = wolfTLSv1_2_server_method;
  56287. #else
  56288. client_cb.method = wolfTLSv1_3_client_method;
  56289. server_cb.method = wolfTLSv1_3_server_method;
  56290. #endif
  56291. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb,
  56292. &server_cb, msgCb), TEST_SUCCESS);
  56293. #endif
  56294. return EXPECT_RESULT();
  56295. }
  56296. static int test_wolfSSL_either_side(void)
  56297. {
  56298. EXPECT_DECLS;
  56299. #if (defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)) && \
  56300. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  56301. test_ssl_cbf client_cb;
  56302. test_ssl_cbf server_cb;
  56303. XMEMSET(&client_cb, 0, sizeof(client_cb));
  56304. XMEMSET(&server_cb, 0, sizeof(server_cb));
  56305. /* Use different CTX for client and server */
  56306. client_cb.ctx = wolfSSL_CTX_new(wolfSSLv23_method());
  56307. ExpectNotNull(client_cb.ctx);
  56308. server_cb.ctx = wolfSSL_CTX_new(wolfSSLv23_method());
  56309. ExpectNotNull(server_cb.ctx);
  56310. /* we are responsible for free'ing WOLFSSL_CTX */
  56311. server_cb.isSharedCtx = client_cb.isSharedCtx = 1;
  56312. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb,
  56313. &server_cb, NULL), TEST_SUCCESS);
  56314. wolfSSL_CTX_free(client_cb.ctx);
  56315. wolfSSL_CTX_free(server_cb.ctx);
  56316. #endif
  56317. return EXPECT_RESULT();
  56318. }
  56319. static int test_wolfSSL_DTLS_either_side(void)
  56320. {
  56321. EXPECT_DECLS;
  56322. #if (defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)) && \
  56323. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS)
  56324. test_ssl_cbf client_cb;
  56325. test_ssl_cbf server_cb;
  56326. XMEMSET(&client_cb, 0, sizeof(client_cb));
  56327. XMEMSET(&server_cb, 0, sizeof(server_cb));
  56328. /* Use different CTX for client and server */
  56329. client_cb.ctx = wolfSSL_CTX_new(wolfDTLS_method());
  56330. ExpectNotNull(client_cb.ctx);
  56331. server_cb.ctx = wolfSSL_CTX_new(wolfDTLS_method());
  56332. ExpectNotNull(server_cb.ctx);
  56333. /* we are responsible for free'ing WOLFSSL_CTX */
  56334. server_cb.isSharedCtx = client_cb.isSharedCtx = 1;
  56335. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb,
  56336. &server_cb, NULL), TEST_SUCCESS);
  56337. wolfSSL_CTX_free(client_cb.ctx);
  56338. wolfSSL_CTX_free(server_cb.ctx);
  56339. #endif
  56340. return EXPECT_RESULT();
  56341. }
  56342. static int test_generate_cookie(void)
  56343. {
  56344. EXPECT_DECLS;
  56345. #if defined(WOLFSSL_DTLS) && defined(OPENSSL_EXTRA) && defined(USE_WOLFSSL_IO)
  56346. SSL_CTX* ctx = NULL;
  56347. SSL* ssl = NULL;
  56348. byte buf[FOURK_BUF] = {0};
  56349. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLS_method()));
  56350. ExpectNotNull(ssl = SSL_new(ctx));
  56351. /* Test unconnected */
  56352. ExpectIntEQ(EmbedGenerateCookie(ssl, buf, FOURK_BUF, NULL), WC_NO_ERR_TRACE(GEN_COOKIE_E));
  56353. wolfSSL_CTX_SetGenCookie(ctx, EmbedGenerateCookie);
  56354. wolfSSL_SetCookieCtx(ssl, ctx);
  56355. ExpectNotNull(wolfSSL_GetCookieCtx(ssl));
  56356. ExpectNull(wolfSSL_GetCookieCtx(NULL));
  56357. SSL_free(ssl);
  56358. SSL_CTX_free(ctx);
  56359. #endif
  56360. return EXPECT_RESULT();
  56361. }
  56362. static int test_wolfSSL_set_options(void)
  56363. {
  56364. EXPECT_DECLS;
  56365. #if !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  56366. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  56367. WOLFSSL* ssl = NULL;
  56368. WOLFSSL_CTX* ctx = NULL;
  56369. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
  56370. char appData[] = "extra msg";
  56371. #endif
  56372. #ifdef OPENSSL_EXTRA
  56373. unsigned char protos[] = {
  56374. 7, 't', 'l', 's', '/', '1', '.', '2',
  56375. 8, 'h', 't', 't', 'p', '/', '1', '.', '1'
  56376. };
  56377. unsigned int len = sizeof(protos);
  56378. void *arg = (void *)TEST_ARG;
  56379. #endif
  56380. #ifndef NO_WOLFSSL_SERVER
  56381. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  56382. #else
  56383. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  56384. #endif
  56385. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  56386. WOLFSSL_FILETYPE_PEM));
  56387. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  56388. WOLFSSL_FILETYPE_PEM));
  56389. ExpectTrue(wolfSSL_CTX_set_options(ctx, WOLFSSL_OP_NO_TLSv1)
  56390. == WOLFSSL_OP_NO_TLSv1);
  56391. ExpectTrue(wolfSSL_CTX_get_options(ctx) == WOLFSSL_OP_NO_TLSv1);
  56392. ExpectIntGT((int)wolfSSL_CTX_set_options(ctx, (WOLFSSL_OP_COOKIE_EXCHANGE |
  56393. WOLFSSL_OP_NO_SSLv2)), 0);
  56394. ExpectTrue((wolfSSL_CTX_set_options(ctx, WOLFSSL_OP_COOKIE_EXCHANGE) &
  56395. WOLFSSL_OP_COOKIE_EXCHANGE) == WOLFSSL_OP_COOKIE_EXCHANGE);
  56396. ExpectTrue((wolfSSL_CTX_set_options(ctx, WOLFSSL_OP_NO_TLSv1_2) &
  56397. WOLFSSL_OP_NO_TLSv1_2) == WOLFSSL_OP_NO_TLSv1_2);
  56398. ExpectTrue((wolfSSL_CTX_set_options(ctx, WOLFSSL_OP_NO_COMPRESSION) &
  56399. WOLFSSL_OP_NO_COMPRESSION) == WOLFSSL_OP_NO_COMPRESSION);
  56400. ExpectFalse((wolfSSL_CTX_clear_options(ctx, WOLFSSL_OP_NO_COMPRESSION) &
  56401. WOLFSSL_OP_NO_COMPRESSION));
  56402. wolfSSL_CTX_free(ctx);
  56403. ctx = NULL;
  56404. #ifndef NO_WOLFSSL_SERVER
  56405. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  56406. #else
  56407. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  56408. #endif
  56409. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  56410. WOLFSSL_FILETYPE_PEM));
  56411. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  56412. WOLFSSL_FILETYPE_PEM));
  56413. #ifdef OPENSSL_EXTRA
  56414. ExpectTrue(wolfSSL_CTX_set_msg_callback(ctx, msg_cb) == WOLFSSL_SUCCESS);
  56415. #endif
  56416. ExpectNotNull(ssl = wolfSSL_new(ctx));
  56417. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
  56418. #ifdef HAVE_EX_DATA
  56419. ExpectIntEQ(wolfSSL_set_app_data(ssl, (void*)appData), WOLFSSL_SUCCESS);
  56420. ExpectNotNull(wolfSSL_get_app_data((const WOLFSSL*)ssl));
  56421. if (ssl != NULL) {
  56422. ExpectIntEQ(XMEMCMP(wolfSSL_get_app_data((const WOLFSSL*)ssl),
  56423. appData, sizeof(appData)), 0);
  56424. }
  56425. #else
  56426. ExpectIntEQ(wolfSSL_set_app_data(ssl, (void*)appData), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56427. ExpectNull(wolfSSL_get_app_data((const WOLFSSL*)ssl));
  56428. #endif
  56429. #endif
  56430. ExpectTrue(wolfSSL_set_options(ssl, WOLFSSL_OP_NO_TLSv1) ==
  56431. WOLFSSL_OP_NO_TLSv1);
  56432. ExpectTrue(wolfSSL_get_options(ssl) == WOLFSSL_OP_NO_TLSv1);
  56433. ExpectIntGT((int)wolfSSL_set_options(ssl, (WOLFSSL_OP_COOKIE_EXCHANGE |
  56434. WOLFSSL_OP_NO_SSLv2)), 0);
  56435. ExpectTrue((wolfSSL_set_options(ssl, WOLFSSL_OP_COOKIE_EXCHANGE) &
  56436. WOLFSSL_OP_COOKIE_EXCHANGE) == WOLFSSL_OP_COOKIE_EXCHANGE);
  56437. ExpectTrue((wolfSSL_set_options(ssl, WOLFSSL_OP_NO_TLSv1_2) &
  56438. WOLFSSL_OP_NO_TLSv1_2) == WOLFSSL_OP_NO_TLSv1_2);
  56439. ExpectTrue((wolfSSL_set_options(ssl, WOLFSSL_OP_NO_COMPRESSION) &
  56440. WOLFSSL_OP_NO_COMPRESSION) == WOLFSSL_OP_NO_COMPRESSION);
  56441. #ifdef OPENSSL_EXTRA
  56442. ExpectFalse((wolfSSL_clear_options(ssl, WOLFSSL_OP_NO_COMPRESSION) &
  56443. WOLFSSL_OP_NO_COMPRESSION));
  56444. #endif
  56445. #ifdef OPENSSL_EXTRA
  56446. ExpectTrue(wolfSSL_set_msg_callback(ssl, msg_cb) == WOLFSSL_SUCCESS);
  56447. wolfSSL_set_msg_callback_arg(ssl, arg);
  56448. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  56449. ExpectTrue(wolfSSL_CTX_set_alpn_protos(ctx, protos, len) == 0);
  56450. #else
  56451. ExpectTrue(wolfSSL_CTX_set_alpn_protos(ctx, protos, len) == WOLFSSL_SUCCESS);
  56452. #endif
  56453. #endif
  56454. #if defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY) || \
  56455. defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(OPENSSL_ALL) || \
  56456. defined(HAVE_LIGHTY) || defined(HAVE_STUNNEL)
  56457. #if defined(HAVE_ALPN) && !defined(NO_BIO)
  56458. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  56459. ExpectTrue(wolfSSL_set_alpn_protos(ssl, protos, len) == 0);
  56460. #else
  56461. ExpectTrue(wolfSSL_set_alpn_protos(ssl, protos, len) == WOLFSSL_SUCCESS);
  56462. #endif
  56463. #endif /* HAVE_ALPN && !NO_BIO */
  56464. #endif
  56465. wolfSSL_free(ssl);
  56466. wolfSSL_CTX_free(ctx);
  56467. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  56468. #endif /* !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  56469. return EXPECT_RESULT();
  56470. }
  56471. static int test_wolfSSL_sk_SSL_CIPHER(void)
  56472. {
  56473. EXPECT_DECLS;
  56474. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  56475. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  56476. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  56477. SSL* ssl = NULL;
  56478. SSL_CTX* ctx = NULL;
  56479. STACK_OF(SSL_CIPHER) *sk = NULL;
  56480. STACK_OF(SSL_CIPHER) *dupSk = NULL;
  56481. #ifndef NO_WOLFSSL_SERVER
  56482. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  56483. #else
  56484. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  56485. #endif
  56486. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile, SSL_FILETYPE_PEM));
  56487. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  56488. ExpectNotNull(ssl = SSL_new(ctx));
  56489. ExpectNotNull(sk = SSL_get_ciphers(ssl));
  56490. ExpectNotNull(dupSk = sk_SSL_CIPHER_dup(sk));
  56491. ExpectIntGT(sk_SSL_CIPHER_num(sk), 0);
  56492. ExpectIntEQ(sk_SSL_CIPHER_num(sk), sk_SSL_CIPHER_num(dupSk));
  56493. /* error case because connection has not been established yet */
  56494. ExpectIntEQ(sk_SSL_CIPHER_find(sk, SSL_get_current_cipher(ssl)), -1);
  56495. sk_SSL_CIPHER_free(dupSk);
  56496. /* sk is pointer to internal struct that should be free'd in SSL_free */
  56497. SSL_free(ssl);
  56498. SSL_CTX_free(ctx);
  56499. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  56500. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  56501. !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  56502. return EXPECT_RESULT();
  56503. }
  56504. static int test_wolfSSL_set1_curves_list(void)
  56505. {
  56506. EXPECT_DECLS;
  56507. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  56508. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  56509. SSL* ssl = NULL;
  56510. SSL_CTX* ctx = NULL;
  56511. #ifndef NO_WOLFSSL_SERVER
  56512. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  56513. #else
  56514. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  56515. #endif
  56516. ExpectTrue(SSL_CTX_use_certificate_file(ctx, eccCertFile,
  56517. SSL_FILETYPE_PEM));
  56518. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, eccKeyFile, SSL_FILETYPE_PEM));
  56519. ExpectNotNull(ssl = SSL_new(ctx));
  56520. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56521. #ifdef HAVE_ECC
  56522. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "P-25X"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56523. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "P-256"), WOLFSSL_SUCCESS);
  56524. #endif
  56525. #ifdef HAVE_CURVE25519
  56526. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "X25519"), WOLFSSL_SUCCESS);
  56527. #else
  56528. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "X25519"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56529. #endif
  56530. #ifdef HAVE_CURVE448
  56531. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "X448"), WOLFSSL_SUCCESS);
  56532. #else
  56533. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "X448"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56534. #endif
  56535. ExpectIntEQ(SSL_set1_curves_list(ssl, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56536. #ifdef HAVE_ECC
  56537. ExpectIntEQ(SSL_set1_curves_list(ssl, "P-25X"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56538. ExpectIntEQ(SSL_set1_curves_list(ssl, "P-256"), WOLFSSL_SUCCESS);
  56539. #endif
  56540. #ifdef HAVE_CURVE25519
  56541. ExpectIntEQ(SSL_set1_curves_list(ssl, "X25519"), WOLFSSL_SUCCESS);
  56542. #else
  56543. ExpectIntEQ(SSL_set1_curves_list(ssl, "X25519"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56544. #endif
  56545. #ifdef HAVE_CURVE448
  56546. ExpectIntEQ(SSL_set1_curves_list(ssl, "X448"), WOLFSSL_SUCCESS);
  56547. #else
  56548. ExpectIntEQ(SSL_set1_curves_list(ssl, "X448"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56549. #endif
  56550. SSL_free(ssl);
  56551. SSL_CTX_free(ctx);
  56552. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  56553. #endif
  56554. return EXPECT_RESULT();
  56555. }
  56556. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  56557. (defined(OPENSSL_EXTRA) || defined(HAVE_CURL)) && defined(HAVE_ECC)
  56558. static int test_wolfSSL_curves_mismatch_ctx_ready(WOLFSSL_CTX* ctx)
  56559. {
  56560. static int counter = 0;
  56561. EXPECT_DECLS;
  56562. if (counter % 2) {
  56563. ExpectIntEQ(wolfSSL_CTX_set1_curves_list(ctx, "P-256"),
  56564. WOLFSSL_SUCCESS);
  56565. }
  56566. else {
  56567. ExpectIntEQ(wolfSSL_CTX_set1_curves_list(ctx, "P-384"),
  56568. WOLFSSL_SUCCESS);
  56569. }
  56570. /* Ciphersuites that require curves */
  56571. wolfSSL_CTX_set_cipher_list(ctx, "TLS13-AES256-GCM-SHA384:"
  56572. "TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES128-GCM-SHA256:"
  56573. "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:"
  56574. "ECDHE-ECDSA-AES128-GCM-SHA256:"
  56575. "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-CHACHA20-POLY1305:"
  56576. "ECDHE-ECDSA-CHACHA20-POLY1305");
  56577. counter++;
  56578. return EXPECT_RESULT();
  56579. }
  56580. #endif
  56581. static int test_wolfSSL_curves_mismatch(void)
  56582. {
  56583. EXPECT_DECLS;
  56584. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  56585. (defined(OPENSSL_EXTRA) || defined(HAVE_CURL)) && defined(HAVE_ECC)
  56586. test_ssl_cbf func_cb_client;
  56587. test_ssl_cbf func_cb_server;
  56588. size_t i;
  56589. struct {
  56590. method_provider client_meth;
  56591. method_provider server_meth;
  56592. const char* desc;
  56593. int client_last_err;
  56594. int server_last_err;
  56595. } test_params[] = {
  56596. #ifdef WOLFSSL_TLS13
  56597. {wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLS 1.3",
  56598. WC_NO_ERR_TRACE(FATAL_ERROR), WC_NO_ERR_TRACE(BAD_KEY_SHARE_DATA)},
  56599. #endif
  56600. #ifndef WOLFSSL_NO_TLS12
  56601. {wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLS 1.2",
  56602. WC_NO_ERR_TRACE(FATAL_ERROR),
  56603. #ifdef OPENSSL_EXTRA
  56604. WC_NO_ERR_TRACE(WOLFSSL_ERROR_SYSCALL)
  56605. #else
  56606. WC_NO_ERR_TRACE(MATCH_SUITE_ERROR)
  56607. #endif
  56608. },
  56609. #endif
  56610. #ifndef NO_OLD_TLS
  56611. {wolfTLSv1_1_client_method, wolfTLSv1_1_server_method, "TLS 1.1",
  56612. WC_NO_ERR_TRACE(FATAL_ERROR),
  56613. #ifdef OPENSSL_EXTRA
  56614. WC_NO_ERR_TRACE(WOLFSSL_ERROR_SYSCALL)
  56615. #else
  56616. WC_NO_ERR_TRACE(MATCH_SUITE_ERROR)
  56617. #endif
  56618. },
  56619. #endif
  56620. };
  56621. for (i = 0; i < XELEM_CNT(test_params) && !EXPECT_FAIL(); i++) {
  56622. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  56623. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  56624. printf("\tTesting with %s...\n", test_params[i].desc);
  56625. func_cb_client.ctx_ready = &test_wolfSSL_curves_mismatch_ctx_ready;
  56626. func_cb_server.ctx_ready = &test_wolfSSL_curves_mismatch_ctx_ready;
  56627. func_cb_client.method = test_params[i].client_meth;
  56628. func_cb_server.method = test_params[i].server_meth;
  56629. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  56630. &func_cb_server, NULL), -1001);
  56631. ExpectIntEQ(func_cb_client.last_err, test_params[i].client_last_err);
  56632. ExpectIntEQ(func_cb_server.last_err, test_params[i].server_last_err);
  56633. if (!EXPECT_SUCCESS())
  56634. break;
  56635. printf("\t%s passed\n", test_params[i].desc);
  56636. }
  56637. #endif
  56638. return EXPECT_RESULT();
  56639. }
  56640. static int test_wolfSSL_set1_sigalgs_list(void)
  56641. {
  56642. EXPECT_DECLS;
  56643. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  56644. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  56645. SSL* ssl = NULL;
  56646. SSL_CTX* ctx = NULL;
  56647. #ifndef NO_WOLFSSL_SERVER
  56648. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  56649. #else
  56650. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  56651. #endif
  56652. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  56653. SSL_FILETYPE_PEM));
  56654. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  56655. ExpectNotNull(ssl = SSL_new(ctx));
  56656. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56657. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56658. ExpectIntEQ(wolfSSL_set1_sigalgs_list(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56659. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56660. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, ""), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56661. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, ""), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56662. #ifndef NO_RSA
  56663. #ifndef NO_SHA256
  56664. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(NULL, "RSA+SHA256"),
  56665. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56666. ExpectIntEQ(wolfSSL_set1_sigalgs_list(NULL, "RSA+SHA256"),
  56667. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56668. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA+SHA256"),
  56669. WOLFSSL_SUCCESS);
  56670. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA+SHA256"),
  56671. WOLFSSL_SUCCESS);
  56672. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA-SHA256"),
  56673. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56674. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA-SHA256"),
  56675. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56676. #ifdef WC_RSA_PSS
  56677. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA-PSS+SHA256"),
  56678. WOLFSSL_SUCCESS);
  56679. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA-PSS+SHA256"),
  56680. WOLFSSL_SUCCESS);
  56681. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "PSS+SHA256"),
  56682. WOLFSSL_SUCCESS);
  56683. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "PSS+SHA256"),
  56684. WOLFSSL_SUCCESS);
  56685. #endif
  56686. #ifdef WOLFSSL_SHA512
  56687. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx,
  56688. "RSA+SHA256:RSA+SHA512"), WOLFSSL_SUCCESS);
  56689. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl,
  56690. "RSA+SHA256:RSA+SHA512"), WOLFSSL_SUCCESS);
  56691. #elif defined(WOLFSSL_SHA384)
  56692. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx,
  56693. "RSA+SHA256:RSA+SHA384"), WOLFSSL_SUCCESS);
  56694. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl,
  56695. "RSA+SHA256:RSA+SHA384"), WOLFSSL_SUCCESS);
  56696. #endif
  56697. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56698. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56699. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA:RSA+SHA256"),
  56700. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56701. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA:RSA+SHA256"),
  56702. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56703. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA+SHA256+SHA256"),
  56704. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56705. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA+SHA256+RSA"),
  56706. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56707. #endif
  56708. #endif
  56709. #ifdef HAVE_ECC
  56710. #ifndef NO_SHA256
  56711. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "ECDSA+SHA256"),
  56712. WOLFSSL_SUCCESS);
  56713. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "ECDSA+SHA256"),
  56714. WOLFSSL_SUCCESS);
  56715. #ifdef WOLFSSL_SHA512
  56716. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx,
  56717. "ECDSA+SHA256:ECDSA+SHA512"), WOLFSSL_SUCCESS);
  56718. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl,
  56719. "ECDSA+SHA256:ECDSA+SHA512"), WOLFSSL_SUCCESS);
  56720. #elif defined(WOLFSSL_SHA384)
  56721. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx,
  56722. "ECDSA+SHA256:ECDSA+SHA384"), WOLFSSL_SUCCESS);
  56723. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl,
  56724. "ECDSA+SHA256:ECDSA+SHA384"), WOLFSSL_SUCCESS);
  56725. #endif
  56726. #endif
  56727. #endif
  56728. #ifdef HAVE_ED25519
  56729. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "ED25519"), WOLFSSL_SUCCESS);
  56730. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "ED25519"), WOLFSSL_SUCCESS);
  56731. #endif
  56732. #ifdef HAVE_ED448
  56733. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "ED448"), WOLFSSL_SUCCESS);
  56734. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "ED448"), WOLFSSL_SUCCESS);
  56735. #endif
  56736. #ifndef NO_DSA
  56737. #ifndef NO_SHA256
  56738. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "DSA+SHA256"),
  56739. WOLFSSL_SUCCESS);
  56740. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "DSA+SHA256"),
  56741. WOLFSSL_SUCCESS);
  56742. #endif
  56743. #if !defined(NO_SHA) && (!defined(NO_OLD_TLS) || \
  56744. defined(WOLFSSL_ALLOW_TLS_SHA1))
  56745. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "DSA+SHA1"),
  56746. WOLFSSL_SUCCESS);
  56747. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "DSA+SHA1"),
  56748. WOLFSSL_SUCCESS);
  56749. #endif
  56750. #endif
  56751. SSL_free(ssl);
  56752. SSL_CTX_free(ctx);
  56753. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  56754. #endif
  56755. return EXPECT_RESULT();
  56756. }
  56757. /* Testing wolfSSL_set_tlsext_status_type function.
  56758. * PRE: OPENSSL and HAVE_CERTIFICATE_STATUS_REQUEST defined.
  56759. */
  56760. static int test_wolfSSL_set_tlsext_status_type(void)
  56761. {
  56762. EXPECT_DECLS;
  56763. #if defined(OPENSSL_EXTRA) && defined(HAVE_CERTIFICATE_STATUS_REQUEST) && \
  56764. !defined(NO_RSA) && !defined(NO_WOLFSSL_SERVER)
  56765. SSL* ssl = NULL;
  56766. SSL_CTX* ctx = NULL;
  56767. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  56768. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  56769. SSL_FILETYPE_PEM));
  56770. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  56771. ExpectNotNull(ssl = SSL_new(ctx));
  56772. ExpectIntEQ(SSL_set_tlsext_status_type(ssl,TLSEXT_STATUSTYPE_ocsp),
  56773. SSL_SUCCESS);
  56774. ExpectIntEQ(SSL_get_tlsext_status_type(ssl), TLSEXT_STATUSTYPE_ocsp);
  56775. SSL_free(ssl);
  56776. SSL_CTX_free(ctx);
  56777. #endif /* OPENSSL_EXTRA && HAVE_CERTIFICATE_STATUS_REQUEST && !NO_RSA */
  56778. return EXPECT_RESULT();
  56779. }
  56780. #ifndef NO_BIO
  56781. static int test_wolfSSL_PEM_read_bio(void)
  56782. {
  56783. EXPECT_DECLS;
  56784. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  56785. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  56786. byte buff[6000];
  56787. XFILE f = XBADFILE;
  56788. int bytes;
  56789. X509* x509 = NULL;
  56790. BIO* bio = NULL;
  56791. BUF_MEM* buf = NULL;
  56792. ExpectTrue((f = XFOPEN(cliCertFile, "rb")) != XBADFILE);
  56793. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  56794. if (f != XBADFILE)
  56795. XFCLOSE(f);
  56796. ExpectNull(x509 = PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL));
  56797. ExpectNotNull(bio = BIO_new_mem_buf((void*)buff, bytes));
  56798. ExpectIntEQ(BIO_set_mem_eof_return(bio, -0xDEAD), 1);
  56799. ExpectNotNull(x509 = PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL));
  56800. ExpectIntEQ((int)BIO_set_fd(bio, 0, BIO_CLOSE), 1);
  56801. /* BIO should return the set EOF value */
  56802. ExpectIntEQ(BIO_read(bio, buff, sizeof(buff)), -0xDEAD);
  56803. ExpectIntEQ(BIO_set_close(bio, BIO_NOCLOSE), 1);
  56804. ExpectIntEQ(BIO_set_close(NULL, BIO_NOCLOSE), 1);
  56805. ExpectIntEQ(SSL_SUCCESS, BIO_get_mem_ptr(bio, &buf));
  56806. BIO_free(bio);
  56807. BUF_MEM_free(buf);
  56808. X509_free(x509);
  56809. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) &&
  56810. * !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  56811. return EXPECT_RESULT();
  56812. }
  56813. #if defined(OPENSSL_EXTRA)
  56814. static long bioCallback(BIO *bio, int cmd, const char* argp, int argi,
  56815. long argl, long ret)
  56816. {
  56817. (void)bio;
  56818. (void)cmd;
  56819. (void)argp;
  56820. (void)argi;
  56821. (void)argl;
  56822. return ret;
  56823. }
  56824. #endif
  56825. static int test_wolfSSL_BIO(void)
  56826. {
  56827. EXPECT_DECLS;
  56828. #if defined(OPENSSL_EXTRA)
  56829. const unsigned char* p = NULL;
  56830. byte buff[20];
  56831. BIO* bio1 = NULL;
  56832. BIO* bio2 = NULL;
  56833. BIO* bio3 = NULL;
  56834. char* bufPt = NULL;
  56835. int i;
  56836. for (i = 0; i < 20; i++) {
  56837. buff[i] = i;
  56838. }
  56839. /* test BIO_free with NULL */
  56840. ExpectIntEQ(BIO_free(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56841. /* Creating and testing type BIO_s_bio */
  56842. ExpectNotNull(bio1 = BIO_new(BIO_s_bio()));
  56843. ExpectNotNull(bio2 = BIO_new(BIO_s_bio()));
  56844. ExpectNotNull(bio3 = BIO_new(BIO_s_bio()));
  56845. /* read/write before set up */
  56846. ExpectIntEQ(BIO_read(bio1, buff, 2), WOLFSSL_BIO_UNSET);
  56847. ExpectIntEQ(BIO_write(bio1, buff, 2), WOLFSSL_BIO_UNSET);
  56848. ExpectIntEQ(BIO_set_nbio(bio1, 1), 1);
  56849. ExpectIntEQ(BIO_set_write_buf_size(bio1, 20), WOLFSSL_SUCCESS);
  56850. ExpectIntEQ(BIO_set_write_buf_size(bio2, 8), WOLFSSL_SUCCESS);
  56851. ExpectIntEQ(BIO_make_bio_pair(bio1, bio2), WOLFSSL_SUCCESS);
  56852. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 10), 10);
  56853. ExpectNotNull(XMEMCPY(bufPt, buff, 10));
  56854. ExpectIntEQ(BIO_write(bio1, buff + 10, 10), 10);
  56855. /* write buffer full */
  56856. ExpectIntEQ(BIO_write(bio1, buff, 10), WOLFSSL_BIO_ERROR);
  56857. ExpectIntEQ(BIO_flush(bio1), WOLFSSL_SUCCESS);
  56858. ExpectIntEQ((int)BIO_ctrl_pending(bio1), 0);
  56859. /* write the other direction with pair */
  56860. ExpectIntEQ((int)BIO_nwrite(bio2, &bufPt, 10), 8);
  56861. ExpectNotNull(XMEMCPY(bufPt, buff, 8));
  56862. ExpectIntEQ(BIO_write(bio2, buff, 10), WOLFSSL_BIO_ERROR);
  56863. /* try read */
  56864. ExpectIntEQ((int)BIO_ctrl_pending(bio1), 8);
  56865. ExpectIntEQ((int)BIO_ctrl_pending(bio2), 20);
  56866. /* try read using ctrl function */
  56867. ExpectIntEQ((int)BIO_ctrl(bio1, BIO_CTRL_WPENDING, 0, NULL), 8);
  56868. ExpectIntEQ((int)BIO_ctrl(bio1, BIO_CTRL_PENDING, 0, NULL), 8);
  56869. ExpectIntEQ((int)BIO_ctrl(bio2, BIO_CTRL_WPENDING, 0, NULL), 20);
  56870. ExpectIntEQ((int)BIO_ctrl(bio2, BIO_CTRL_PENDING, 0, NULL), 20);
  56871. ExpectIntEQ(BIO_nread(bio2, &bufPt, (int)BIO_ctrl_pending(bio2)), 20);
  56872. for (i = 0; i < 20; i++) {
  56873. ExpectIntEQ((int)bufPt[i], i);
  56874. }
  56875. ExpectIntEQ(BIO_nread(bio2, &bufPt, 1), 0);
  56876. ExpectIntEQ(BIO_nread(bio1, &bufPt, (int)BIO_ctrl_pending(bio1)), 8);
  56877. for (i = 0; i < 8; i++) {
  56878. ExpectIntEQ((int)bufPt[i], i);
  56879. }
  56880. ExpectIntEQ(BIO_nread(bio1, &bufPt, 1), 0);
  56881. ExpectIntEQ(BIO_ctrl_reset_read_request(bio1), 1);
  56882. /* new pair */
  56883. ExpectIntEQ(BIO_make_bio_pair(bio1, bio3), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56884. BIO_free(bio2); /* free bio2 and automatically remove from pair */
  56885. bio2 = NULL;
  56886. ExpectIntEQ(BIO_make_bio_pair(bio1, bio3), WOLFSSL_SUCCESS);
  56887. ExpectIntEQ((int)BIO_ctrl_pending(bio3), 0);
  56888. ExpectIntEQ(BIO_nread(bio3, &bufPt, 10), 0);
  56889. /* test wrap around... */
  56890. ExpectIntEQ(BIO_reset(bio1), 1);
  56891. ExpectIntEQ(BIO_reset(bio3), 1);
  56892. /* fill write buffer, read only small amount then write again */
  56893. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 20), 20);
  56894. ExpectNotNull(XMEMCPY(bufPt, buff, 20));
  56895. ExpectIntEQ(BIO_nread(bio3, &bufPt, 4), 4);
  56896. for (i = 0; i < 4; i++) {
  56897. ExpectIntEQ(bufPt[i], i);
  56898. }
  56899. /* try writing over read index */
  56900. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 5), 4);
  56901. ExpectNotNull(XMEMSET(bufPt, 0, 4));
  56902. ExpectIntEQ((int)BIO_ctrl_pending(bio3), 20);
  56903. /* read and write 0 bytes */
  56904. ExpectIntEQ(BIO_nread(bio3, &bufPt, 0), 0);
  56905. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 0), 0);
  56906. /* should read only to end of write buffer then need to read again */
  56907. ExpectIntEQ(BIO_nread(bio3, &bufPt, 20), 16);
  56908. for (i = 0; i < 16; i++) {
  56909. ExpectIntEQ(bufPt[i], buff[4 + i]);
  56910. }
  56911. ExpectIntEQ(BIO_nread(bio3, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56912. ExpectIntEQ(BIO_nread0(bio3, &bufPt), 4);
  56913. for (i = 0; i < 4; i++) {
  56914. ExpectIntEQ(bufPt[i], 0);
  56915. }
  56916. /* read index should not have advanced with nread0 */
  56917. ExpectIntEQ(BIO_nread(bio3, &bufPt, 5), 4);
  56918. for (i = 0; i < 4; i++) {
  56919. ExpectIntEQ(bufPt[i], 0);
  56920. }
  56921. /* write and fill up buffer checking reset of index state */
  56922. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 20), 20);
  56923. ExpectNotNull(XMEMCPY(bufPt, buff, 20));
  56924. /* test reset on data in bio1 write buffer */
  56925. ExpectIntEQ(BIO_reset(bio1), 1);
  56926. ExpectIntEQ((int)BIO_ctrl_pending(bio3), 0);
  56927. ExpectIntEQ(BIO_nread(bio3, &bufPt, 3), 0);
  56928. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 20), 20);
  56929. ExpectIntEQ((int)BIO_ctrl(bio1, BIO_CTRL_INFO, 0, &p), 20);
  56930. ExpectNotNull(p);
  56931. ExpectNotNull(XMEMCPY(bufPt, buff, 20));
  56932. ExpectIntEQ(BIO_nread(bio3, &bufPt, 6), 6);
  56933. for (i = 0; i < 6; i++) {
  56934. ExpectIntEQ(bufPt[i], i);
  56935. }
  56936. /* test case of writing twice with offset read index */
  56937. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 3), 3);
  56938. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 4), 3); /* try overwriting */
  56939. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 4), WOLFSSL_BIO_ERROR);
  56940. ExpectIntEQ(BIO_nread(bio3, &bufPt, 0), 0);
  56941. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 4), WOLFSSL_BIO_ERROR);
  56942. ExpectIntEQ(BIO_nread(bio3, &bufPt, 1), 1);
  56943. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 4), 1);
  56944. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 4), WOLFSSL_BIO_ERROR);
  56945. BIO_free(bio1);
  56946. bio1 = NULL;
  56947. BIO_free(bio3);
  56948. bio3 = NULL;
  56949. #if defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO)
  56950. {
  56951. BIO* bioA = NULL;
  56952. BIO* bioB = NULL;
  56953. ExpectIntEQ(BIO_new_bio_pair(NULL, 256, NULL, 256), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  56954. ExpectIntEQ(BIO_new_bio_pair(&bioA, 256, &bioB, 256), WOLFSSL_SUCCESS);
  56955. BIO_free(bioA);
  56956. bioA = NULL;
  56957. BIO_free(bioB);
  56958. bioB = NULL;
  56959. }
  56960. #endif /* OPENSSL_ALL || WOLFSSL_ASIO */
  56961. /* BIOs with file pointers */
  56962. #if !defined(NO_FILESYSTEM)
  56963. {
  56964. XFILE f1 = XBADFILE;
  56965. XFILE f2 = XBADFILE;
  56966. BIO* f_bio1 = NULL;
  56967. BIO* f_bio2 = NULL;
  56968. unsigned char cert[300];
  56969. char testFile[] = "tests/bio_write_test.txt";
  56970. char msg[] = "bio_write_test.txt contains the first 300 bytes of certs/server-cert.pem\ncreated by tests/unit.test\n\n";
  56971. ExpectNotNull(f_bio1 = BIO_new(BIO_s_file()));
  56972. ExpectNotNull(f_bio2 = BIO_new(BIO_s_file()));
  56973. /* Failure due to wrong BIO type */
  56974. ExpectIntEQ((int)BIO_set_mem_eof_return(f_bio1, -1), 0);
  56975. ExpectIntEQ((int)BIO_set_mem_eof_return(NULL, -1), 0);
  56976. ExpectTrue((f1 = XFOPEN(svrCertFile, "rwb")) != XBADFILE);
  56977. ExpectIntEQ((int)BIO_set_fp(f_bio1, f1, BIO_CLOSE), WOLFSSL_SUCCESS);
  56978. ExpectIntEQ(BIO_write_filename(f_bio2, testFile),
  56979. WOLFSSL_SUCCESS);
  56980. ExpectIntEQ(BIO_read(f_bio1, cert, sizeof(cert)), sizeof(cert));
  56981. ExpectIntEQ(BIO_tell(f_bio1),sizeof(cert));
  56982. ExpectIntEQ(BIO_write(f_bio2, msg, sizeof(msg)), sizeof(msg));
  56983. ExpectIntEQ(BIO_tell(f_bio2),sizeof(msg));
  56984. ExpectIntEQ(BIO_write(f_bio2, cert, sizeof(cert)), sizeof(cert));
  56985. ExpectIntEQ(BIO_tell(f_bio2),sizeof(cert) + sizeof(msg));
  56986. ExpectIntEQ((int)BIO_get_fp(f_bio2, &f2), WOLFSSL_SUCCESS);
  56987. ExpectIntEQ(BIO_reset(f_bio2), 1);
  56988. ExpectIntEQ(BIO_tell(NULL),-1);
  56989. ExpectIntEQ(BIO_tell(f_bio2),0);
  56990. ExpectIntEQ(BIO_seek(f_bio2, 4), 0);
  56991. ExpectIntEQ(BIO_tell(f_bio2),4);
  56992. BIO_free(f_bio1);
  56993. f_bio1 = NULL;
  56994. BIO_free(f_bio2);
  56995. f_bio2 = NULL;
  56996. ExpectNotNull(f_bio1 = BIO_new_file(svrCertFile, "rwb"));
  56997. ExpectIntEQ((int)BIO_set_mem_eof_return(f_bio1, -1), 0);
  56998. ExpectIntEQ(BIO_read(f_bio1, cert, sizeof(cert)), sizeof(cert));
  56999. BIO_free(f_bio1);
  57000. f_bio1 = NULL;
  57001. }
  57002. #endif /* !defined(NO_FILESYSTEM) */
  57003. /* BIO info callback */
  57004. {
  57005. const char* testArg = "test";
  57006. BIO* cb_bio = NULL;
  57007. ExpectNotNull(cb_bio = BIO_new(BIO_s_mem()));
  57008. BIO_set_callback(cb_bio, bioCallback);
  57009. ExpectNotNull(BIO_get_callback(cb_bio));
  57010. BIO_set_callback(cb_bio, NULL);
  57011. ExpectNull(BIO_get_callback(cb_bio));
  57012. BIO_set_callback_arg(cb_bio, (char*)testArg);
  57013. ExpectStrEQ(BIO_get_callback_arg(cb_bio), testArg);
  57014. ExpectNull(BIO_get_callback_arg(NULL));
  57015. BIO_free(cb_bio);
  57016. cb_bio = NULL;
  57017. }
  57018. /* BIO_vfree */
  57019. ExpectNotNull(bio1 = BIO_new(BIO_s_bio()));
  57020. BIO_vfree(NULL);
  57021. BIO_vfree(bio1);
  57022. #endif
  57023. return EXPECT_RESULT();
  57024. }
  57025. static int test_wolfSSL_BIO_BIO_ring_read(void)
  57026. {
  57027. EXPECT_DECLS;
  57028. #if defined(OPENSSL_ALL)
  57029. BIO* bio1 = NULL;
  57030. BIO* bio2 = NULL;
  57031. byte data[50];
  57032. byte tmp[50];
  57033. XMEMSET(data, 42, sizeof(data));
  57034. ExpectIntEQ(BIO_new_bio_pair(&bio1, sizeof(data), &bio2, sizeof(data)),
  57035. SSL_SUCCESS);
  57036. ExpectIntEQ(BIO_write(bio1, data, 40), 40);
  57037. ExpectIntEQ(BIO_read(bio1, tmp, 20), -1);
  57038. ExpectIntEQ(BIO_read(bio2, tmp, 20), 20);
  57039. ExpectBufEQ(tmp, data, 20);
  57040. ExpectIntEQ(BIO_write(bio1, data, 20), 20);
  57041. ExpectIntEQ(BIO_read(bio2, tmp, 40), 40);
  57042. ExpectBufEQ(tmp, data, 40);
  57043. BIO_free(bio1);
  57044. BIO_free(bio2);
  57045. #endif
  57046. return EXPECT_RESULT();
  57047. }
  57048. #endif /* !NO_BIO */
  57049. static int test_wolfSSL_a2i_IPADDRESS(void)
  57050. {
  57051. EXPECT_DECLS;
  57052. #if defined(OPENSSL_ALL) && !defined(WOLFSSL_USER_IO)
  57053. const unsigned char* data = NULL;
  57054. int dataSz = 0;
  57055. ASN1_OCTET_STRING *st = NULL;
  57056. const unsigned char ipv4_exp[] = {0x7F, 0, 0, 1};
  57057. const unsigned char ipv6_exp[] = {
  57058. 0x20, 0x21, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00,
  57059. 0x00, 0x00, 0xff, 0x00, 0x00, 0x42, 0x77, 0x77
  57060. };
  57061. const unsigned char ipv6_home[] = {
  57062. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  57063. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
  57064. };
  57065. ExpectNull(st = a2i_IPADDRESS("127.0.0.1bad"));
  57066. ExpectNotNull(st = a2i_IPADDRESS("127.0.0.1"));
  57067. ExpectNotNull(data = ASN1_STRING_get0_data(st));
  57068. ExpectIntEQ(dataSz = ASN1_STRING_length(st), WOLFSSL_IP4_ADDR_LEN);
  57069. ExpectIntEQ(XMEMCMP(data, ipv4_exp, dataSz), 0);
  57070. ASN1_STRING_free(st);
  57071. st = NULL;
  57072. ExpectNotNull(st = a2i_IPADDRESS("::1"));
  57073. ExpectNotNull(data = ASN1_STRING_get0_data(st));
  57074. ExpectIntEQ(dataSz = ASN1_STRING_length(st), WOLFSSL_IP6_ADDR_LEN);
  57075. ExpectIntEQ(XMEMCMP(data, ipv6_home, dataSz), 0);
  57076. ASN1_STRING_free(st);
  57077. st = NULL;
  57078. ExpectNotNull(st = a2i_IPADDRESS("2021:db8::ff00:42:7777"));
  57079. ExpectNotNull(data = ASN1_STRING_get0_data(st));
  57080. ExpectIntEQ(dataSz = ASN1_STRING_length(st), WOLFSSL_IP6_ADDR_LEN);
  57081. ExpectIntEQ(XMEMCMP(data, ipv6_exp, dataSz), 0);
  57082. ASN1_STRING_free(st);
  57083. #endif
  57084. return EXPECT_RESULT();
  57085. }
  57086. static int test_wolfSSL_X509_cmp_time(void)
  57087. {
  57088. EXPECT_DECLS;
  57089. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME) \
  57090. && !defined(USER_TIME) && !defined(TIME_OVERRIDES)
  57091. WOLFSSL_ASN1_TIME asn_time;
  57092. time_t t;
  57093. ExpectIntEQ(0, wolfSSL_X509_cmp_time(NULL, &t));
  57094. XMEMSET(&asn_time, 0, sizeof(WOLFSSL_ASN1_TIME));
  57095. ExpectIntEQ(0, wolfSSL_X509_cmp_time(&asn_time, &t));
  57096. ExpectIntEQ(ASN1_TIME_set_string(&asn_time, "000222211515Z"), 1);
  57097. ExpectIntEQ(-1, wolfSSL_X509_cmp_time(&asn_time, NULL));
  57098. #endif
  57099. return EXPECT_RESULT();
  57100. }
  57101. static int test_wolfSSL_X509_time_adj(void)
  57102. {
  57103. EXPECT_DECLS;
  57104. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME) && \
  57105. !defined(USER_TIME) && !defined(TIME_OVERRIDES) && \
  57106. defined(USE_CERT_BUFFERS_2048) && !defined(NO_RSA) && \
  57107. !defined(NO_ASN_TIME)
  57108. X509* x509 = NULL;
  57109. time_t t;
  57110. time_t not_before;
  57111. time_t not_after;
  57112. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(
  57113. client_cert_der_2048, sizeof_client_cert_der_2048,
  57114. WOLFSSL_FILETYPE_ASN1));
  57115. t = 0;
  57116. not_before = wc_Time(0);
  57117. not_after = wc_Time(0) + (60 * 24 * 30); /* 30 days after */
  57118. ExpectNotNull(X509_time_adj(X509_get_notBefore(x509), not_before, &t));
  57119. ExpectNotNull(X509_time_adj(X509_get_notAfter(x509), not_after, &t));
  57120. /* Check X509_gmtime_adj, too. */
  57121. ExpectNotNull(X509_gmtime_adj(X509_get_notAfter(x509), not_after));
  57122. X509_free(x509);
  57123. #endif
  57124. return EXPECT_RESULT();
  57125. }
  57126. static int test_wolfSSL_X509_bad_altname(void)
  57127. {
  57128. EXPECT_DECLS;
  57129. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  57130. const unsigned char malformed_alt_name_cert[] = {
  57131. 0x30, 0x82, 0x02, 0xf9, 0x30, 0x82, 0x01, 0xe1, 0xa0, 0x03, 0x02, 0x01,
  57132. 0x02, 0x02, 0x02, 0x10, 0x21, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48,
  57133. 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x0f, 0x31, 0x0d,
  57134. 0x30, 0x0b, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x04, 0x61, 0x61, 0x31,
  57135. 0x31, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x36, 0x30, 0x32, 0x30, 0x37, 0x31,
  57136. 0x37, 0x32, 0x34, 0x30, 0x30, 0x5a, 0x17, 0x0d, 0x33, 0x34, 0x30, 0x32,
  57137. 0x31, 0x34, 0x30, 0x36, 0x32, 0x36, 0x35, 0x33, 0x5a, 0x30, 0x0f, 0x31,
  57138. 0x0d, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x04, 0x61, 0x61,
  57139. 0x61, 0x61, 0x30, 0x82, 0x01, 0x20, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86,
  57140. 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01,
  57141. 0x0d, 0x00, 0x30, 0x82, 0x01, 0x08, 0x02, 0x82, 0x01, 0x01, 0x00, 0xa8,
  57142. 0x8a, 0x5e, 0x26, 0x23, 0x1b, 0x31, 0xd3, 0x37, 0x1a, 0x70, 0xb2, 0xec,
  57143. 0x3f, 0x74, 0xd4, 0xb4, 0x44, 0xe3, 0x7a, 0xa5, 0xc0, 0xf5, 0xaa, 0x97,
  57144. 0x26, 0x9a, 0x04, 0xff, 0xda, 0xbe, 0xe5, 0x09, 0x03, 0x98, 0x3d, 0xb5,
  57145. 0xbf, 0x01, 0x2c, 0x9a, 0x0a, 0x3a, 0xfb, 0xbc, 0x3c, 0xe7, 0xbe, 0x83,
  57146. 0x5c, 0xb3, 0x70, 0xe8, 0x5c, 0xe3, 0xd1, 0x83, 0xc3, 0x94, 0x08, 0xcd,
  57147. 0x1a, 0x87, 0xe5, 0xe0, 0x5b, 0x9c, 0x5c, 0x6e, 0xb0, 0x7d, 0xe2, 0x58,
  57148. 0x6c, 0xc3, 0xb5, 0xc8, 0x9d, 0x11, 0xf1, 0x5d, 0x96, 0x0d, 0x66, 0x1e,
  57149. 0x56, 0x7f, 0x8f, 0x59, 0xa7, 0xa5, 0xe1, 0xc5, 0xe7, 0x81, 0x4c, 0x09,
  57150. 0x9d, 0x5e, 0x96, 0xf0, 0x9a, 0xc2, 0x8b, 0x70, 0xd5, 0xab, 0x79, 0x58,
  57151. 0x5d, 0xb7, 0x58, 0xaa, 0xfd, 0x75, 0x52, 0xaa, 0x4b, 0xa7, 0x25, 0x68,
  57152. 0x76, 0x59, 0x00, 0xee, 0x78, 0x2b, 0x91, 0xc6, 0x59, 0x91, 0x99, 0x38,
  57153. 0x3e, 0xa1, 0x76, 0xc3, 0xf5, 0x23, 0x6b, 0xe6, 0x07, 0xea, 0x63, 0x1c,
  57154. 0x97, 0x49, 0xef, 0xa0, 0xfe, 0xfd, 0x13, 0xc9, 0xa9, 0x9f, 0xc2, 0x0b,
  57155. 0xe6, 0x87, 0x92, 0x5b, 0xcc, 0xf5, 0x42, 0x95, 0x4a, 0xa4, 0x6d, 0x64,
  57156. 0xba, 0x7d, 0xce, 0xcb, 0x04, 0xd0, 0xf8, 0xe7, 0xe3, 0xda, 0x75, 0x60,
  57157. 0xd3, 0x8b, 0x6a, 0x64, 0xfc, 0x78, 0x56, 0x21, 0x69, 0x5a, 0xe8, 0xa7,
  57158. 0x8f, 0xfb, 0x8f, 0x82, 0xe3, 0xae, 0x36, 0xa2, 0x93, 0x66, 0x92, 0xcb,
  57159. 0x82, 0xa3, 0xbe, 0x84, 0x00, 0x86, 0xdc, 0x7e, 0x6d, 0x53, 0x77, 0x84,
  57160. 0x17, 0xb9, 0x55, 0x43, 0x0d, 0xf1, 0x16, 0x1f, 0xd5, 0x43, 0x75, 0x99,
  57161. 0x66, 0x19, 0x52, 0xd0, 0xac, 0x5f, 0x74, 0xad, 0xb2, 0x90, 0x15, 0x50,
  57162. 0x04, 0x74, 0x43, 0xdf, 0x6c, 0x35, 0xd0, 0xfd, 0x32, 0x37, 0xb3, 0x8d,
  57163. 0xf5, 0xe5, 0x09, 0x02, 0x01, 0x03, 0xa3, 0x61, 0x30, 0x5f, 0x30, 0x0c,
  57164. 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x02, 0x30, 0x00,
  57165. 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, 0x08, 0x30, 0x06, 0x82,
  57166. 0x04, 0x61, 0x2a, 0x00, 0x2a, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e,
  57167. 0x04, 0x16, 0x04, 0x14, 0x92, 0x6a, 0x1e, 0x52, 0x3a, 0x1a, 0x57, 0x9f,
  57168. 0xc9, 0x82, 0x9a, 0xce, 0xc8, 0xc0, 0xa9, 0x51, 0x9d, 0x2f, 0xc7, 0x72,
  57169. 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80,
  57170. 0x14, 0x6b, 0xf9, 0xa4, 0x2d, 0xa5, 0xe9, 0x39, 0x89, 0xa8, 0x24, 0x58,
  57171. 0x79, 0x87, 0x11, 0xfc, 0x6f, 0x07, 0x91, 0xef, 0xa6, 0x30, 0x0d, 0x06,
  57172. 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00,
  57173. 0x03, 0x82, 0x01, 0x01, 0x00, 0x3f, 0xd5, 0x37, 0x2f, 0xc7, 0xf8, 0x8b,
  57174. 0x39, 0x1c, 0xe3, 0xdf, 0x77, 0xee, 0xc6, 0x4b, 0x5f, 0x84, 0xcf, 0xfa,
  57175. 0x33, 0x2c, 0xb2, 0xb5, 0x4b, 0x09, 0xee, 0x56, 0xc0, 0xf2, 0xf0, 0xeb,
  57176. 0xad, 0x1c, 0x02, 0xef, 0xae, 0x09, 0x53, 0xc0, 0x06, 0xad, 0x4e, 0xfd,
  57177. 0x3e, 0x8c, 0x13, 0xb3, 0xbf, 0x80, 0x05, 0x36, 0xb5, 0x3f, 0x2b, 0xc7,
  57178. 0x60, 0x53, 0x14, 0xbf, 0x33, 0x63, 0x47, 0xc3, 0xc6, 0x28, 0xda, 0x10,
  57179. 0x12, 0xe2, 0xc4, 0xeb, 0xc5, 0x64, 0x66, 0xc0, 0xcc, 0x6b, 0x84, 0xda,
  57180. 0x0c, 0xe9, 0xf6, 0xe3, 0xf8, 0x8e, 0x3d, 0x95, 0x5f, 0xba, 0x9f, 0xe1,
  57181. 0xc7, 0xed, 0x6e, 0x97, 0xcc, 0xbd, 0x7d, 0xe5, 0x4e, 0xab, 0xbc, 0x1b,
  57182. 0xf1, 0x3a, 0x09, 0x33, 0x09, 0xe1, 0xcc, 0xec, 0x21, 0x16, 0x8e, 0xb1,
  57183. 0x74, 0x9e, 0xc8, 0x13, 0x7c, 0xdf, 0x07, 0xaa, 0xeb, 0x70, 0xd7, 0x91,
  57184. 0x5c, 0xc4, 0xef, 0x83, 0x88, 0xc3, 0xe4, 0x97, 0xfa, 0xe4, 0xdf, 0xd7,
  57185. 0x0d, 0xff, 0xba, 0x78, 0x22, 0xfc, 0x3f, 0xdc, 0xd8, 0x02, 0x8d, 0x93,
  57186. 0x57, 0xf9, 0x9e, 0x39, 0x3a, 0x77, 0x00, 0xd9, 0x19, 0xaa, 0x68, 0xa1,
  57187. 0xe6, 0x9e, 0x13, 0xeb, 0x37, 0x16, 0xf5, 0x77, 0xa4, 0x0b, 0x40, 0x04,
  57188. 0xd3, 0xa5, 0x49, 0x78, 0x35, 0xfa, 0x3b, 0xf6, 0x02, 0xab, 0x85, 0xee,
  57189. 0xcb, 0x9b, 0x62, 0xda, 0x05, 0x00, 0x22, 0x2f, 0xf8, 0xbd, 0x0b, 0xe5,
  57190. 0x2c, 0xb2, 0x53, 0x78, 0x0a, 0xcb, 0x69, 0xc0, 0xb6, 0x9f, 0x96, 0xff,
  57191. 0x58, 0x22, 0x70, 0x9c, 0x01, 0x2e, 0x56, 0x60, 0x5d, 0x37, 0xe3, 0x40,
  57192. 0x25, 0xc9, 0x90, 0xc8, 0x0f, 0x41, 0x68, 0xb4, 0xfd, 0x10, 0xe2, 0x09,
  57193. 0x99, 0x08, 0x5d, 0x7b, 0xc9, 0xe3, 0x29, 0xd4, 0x5a, 0xcf, 0xc9, 0x34,
  57194. 0x55, 0xa1, 0x40, 0x44, 0xd6, 0x88, 0x16, 0xbb, 0xdd
  57195. };
  57196. X509* x509 = NULL;
  57197. int certSize = (int)sizeof(malformed_alt_name_cert) / sizeof(unsigned char);
  57198. const char *name = "aaaaa";
  57199. int nameLen = (int)XSTRLEN(name);
  57200. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(
  57201. malformed_alt_name_cert, certSize, SSL_FILETYPE_ASN1));
  57202. /* malformed_alt_name_cert has a malformed alternative
  57203. * name of "a*\0*". Ensure that it does not match "aaaaa" */
  57204. ExpectIntNE(wolfSSL_X509_check_host(x509, name, nameLen,
  57205. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), 1);
  57206. X509_free(x509);
  57207. #endif
  57208. return EXPECT_RESULT();
  57209. }
  57210. static int test_wolfSSL_X509_name_match(void)
  57211. {
  57212. EXPECT_DECLS;
  57213. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  57214. /* A certificate with the subject alternative name a* */
  57215. const unsigned char cert_der[] = {
  57216. 0x30, 0x82, 0x03, 0xac, 0x30, 0x82, 0x02, 0x94, 0xa0, 0x03, 0x02, 0x01,
  57217. 0x02, 0x02, 0x14, 0x0f, 0xa5, 0x10, 0x85, 0xef, 0x58, 0x10, 0x59, 0xfc,
  57218. 0x0f, 0x20, 0x1f, 0x53, 0xf5, 0x30, 0x39, 0x34, 0x49, 0x54, 0x05, 0x30,
  57219. 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b,
  57220. 0x05, 0x00, 0x30, 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
  57221. 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55,
  57222. 0x04, 0x08, 0x0c, 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31,
  57223. 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f,
  57224. 0x7a, 0x65, 0x6d, 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55,
  57225. 0x04, 0x0a, 0x0c, 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20,
  57226. 0x49, 0x6e, 0x63, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b,
  57227. 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e,
  57228. 0x67, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f,
  57229. 0x77, 0x77, 0x77, 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e,
  57230. 0x63, 0x6f, 0x6d, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x34, 0x30, 0x35, 0x33,
  57231. 0x30, 0x32, 0x30, 0x31, 0x35, 0x35, 0x38, 0x5a, 0x17, 0x0d, 0x33, 0x34,
  57232. 0x30, 0x35, 0x32, 0x38, 0x32, 0x30, 0x31, 0x35, 0x35, 0x38, 0x5a, 0x30,
  57233. 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,
  57234. 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c,
  57235. 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31, 0x10, 0x30, 0x0e,
  57236. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f, 0x7a, 0x65, 0x6d,
  57237. 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c,
  57238. 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x49, 0x6e, 0x63,
  57239. 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45,
  57240. 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18,
  57241. 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x77, 0x77,
  57242. 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d,
  57243. 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
  57244. 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00,
  57245. 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xf4, 0xca, 0x3d,
  57246. 0xd4, 0xbc, 0x9b, 0xea, 0x74, 0xfe, 0x73, 0xf4, 0x16, 0x23, 0x0b, 0x4a,
  57247. 0x09, 0x54, 0xf6, 0x7b, 0x10, 0x99, 0x11, 0x93, 0xb2, 0xdb, 0x4d, 0x7d,
  57248. 0x23, 0xab, 0xf9, 0xcd, 0xf6, 0x54, 0xd4, 0xf6, 0x39, 0x57, 0xee, 0x97,
  57249. 0xb2, 0xb9, 0xfc, 0x7e, 0x9c, 0xb3, 0xfb, 0x56, 0xb6, 0x84, 0xd6, 0x2d,
  57250. 0x59, 0x1c, 0xed, 0xda, 0x9b, 0x19, 0xf5, 0x8a, 0xa7, 0x8a, 0x89, 0xd6,
  57251. 0xa1, 0xc0, 0xe6, 0x16, 0xad, 0x04, 0xcf, 0x5a, 0x1f, 0xdf, 0x62, 0x6c,
  57252. 0x68, 0x45, 0xe9, 0x55, 0x2e, 0x42, 0xa3, 0x1b, 0x3b, 0x86, 0x23, 0x22,
  57253. 0xa1, 0x20, 0x48, 0xd1, 0x52, 0xc0, 0x8b, 0xab, 0xe2, 0x8a, 0x15, 0x68,
  57254. 0xbd, 0x89, 0x6f, 0x9f, 0x45, 0x75, 0xb4, 0x27, 0xc1, 0x72, 0x41, 0xfd,
  57255. 0x79, 0x89, 0xb0, 0x74, 0xa2, 0xe9, 0x61, 0x48, 0x4c, 0x54, 0xad, 0x6b,
  57256. 0x61, 0xbf, 0x0e, 0x27, 0x58, 0xb4, 0xf6, 0x9c, 0x2c, 0x9f, 0xc2, 0x3e,
  57257. 0x3b, 0xb3, 0x90, 0x41, 0xbc, 0x61, 0xcd, 0x01, 0x57, 0x90, 0x82, 0xec,
  57258. 0x46, 0xba, 0x4f, 0x89, 0x8e, 0x7f, 0x49, 0x4f, 0x46, 0x69, 0x37, 0x8b,
  57259. 0xa0, 0xba, 0x85, 0xe8, 0x42, 0xff, 0x9a, 0xa1, 0x53, 0x81, 0x5c, 0xf3,
  57260. 0x8e, 0x85, 0x1c, 0xd4, 0x90, 0x60, 0xa0, 0x37, 0x59, 0x04, 0x65, 0xa6,
  57261. 0xb5, 0x12, 0x00, 0xc3, 0x04, 0x51, 0xa7, 0x83, 0x96, 0x62, 0x3d, 0x49,
  57262. 0x97, 0xe8, 0x6b, 0x9a, 0x5d, 0x51, 0x24, 0xee, 0xad, 0x45, 0x18, 0x0f,
  57263. 0x3f, 0x97, 0xec, 0xdf, 0xcf, 0x42, 0x8a, 0x96, 0xc7, 0xd8, 0x82, 0x87,
  57264. 0x7f, 0x57, 0x70, 0x22, 0xfb, 0x29, 0x3e, 0x3c, 0xa3, 0xc1, 0xd5, 0x71,
  57265. 0xb3, 0x84, 0x06, 0x53, 0xa3, 0x86, 0x20, 0x35, 0xe3, 0x41, 0xb9, 0xd8,
  57266. 0x00, 0x22, 0x4f, 0x6d, 0xe6, 0xfd, 0xf0, 0xf4, 0xa2, 0x39, 0x0a, 0x1a,
  57267. 0x23, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x30, 0x30, 0x2e, 0x30, 0x0d,
  57268. 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, 0x06, 0x30, 0x04, 0x82, 0x02, 0x61,
  57269. 0x2a, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14,
  57270. 0x45, 0x05, 0xf3, 0x4d, 0x3e, 0x7e, 0x9c, 0xf5, 0x08, 0xee, 0x2c, 0x13,
  57271. 0x32, 0xe3, 0xf2, 0x14, 0xe8, 0x0e, 0x71, 0x21, 0x30, 0x0d, 0x06, 0x09,
  57272. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03,
  57273. 0x82, 0x01, 0x01, 0x00, 0xa8, 0x28, 0xe5, 0x22, 0x65, 0xcf, 0x47, 0xfe,
  57274. 0x82, 0x17, 0x99, 0x20, 0xdb, 0xb1, 0x57, 0xd4, 0x91, 0x1a, 0x83, 0xde,
  57275. 0xc1, 0xaf, 0xc4, 0x1f, 0xfb, 0xa4, 0x6a, 0xad, 0xdc, 0x58, 0x72, 0xd9,
  57276. 0x9b, 0xab, 0xa5, 0xbb, 0xf4, 0x98, 0xd4, 0xdf, 0x36, 0xcb, 0xb5, 0x78,
  57277. 0xce, 0x4b, 0x25, 0x5b, 0x24, 0x92, 0xfe, 0xe8, 0xd4, 0xe4, 0xbd, 0x6f,
  57278. 0x71, 0x1a, 0x81, 0x2a, 0x6f, 0x35, 0x93, 0xf7, 0xcc, 0xed, 0xe5, 0x06,
  57279. 0xd2, 0x96, 0x41, 0xb5, 0xa9, 0x8a, 0xc0, 0xc9, 0x17, 0xe3, 0x13, 0x5e,
  57280. 0x94, 0x5e, 0xfa, 0xfc, 0xf0, 0x00, 0x2e, 0xe1, 0xd8, 0x1b, 0x23, 0x3f,
  57281. 0x7c, 0x4d, 0x9f, 0xfb, 0xb7, 0x95, 0xc1, 0x94, 0x7f, 0x7f, 0xb5, 0x4f,
  57282. 0x93, 0x6d, 0xc3, 0x2b, 0xb2, 0x28, 0x36, 0xd2, 0x7c, 0x01, 0x3c, 0xae,
  57283. 0x35, 0xdb, 0xc8, 0x95, 0x1b, 0x5f, 0x6c, 0x0f, 0x57, 0xb3, 0xcc, 0x97,
  57284. 0x98, 0x80, 0x06, 0xaa, 0xe4, 0x93, 0x1f, 0xb7, 0xa0, 0x54, 0xf1, 0x4f,
  57285. 0x6f, 0x11, 0xdf, 0xab, 0xd3, 0xbf, 0xf0, 0x3a, 0x81, 0x60, 0xaf, 0x7a,
  57286. 0xf7, 0x09, 0xd5, 0xae, 0x0c, 0x7d, 0xae, 0x8d, 0x47, 0x06, 0xbe, 0x11,
  57287. 0x6e, 0xf8, 0x7e, 0x49, 0xf8, 0xac, 0x24, 0x0a, 0x4b, 0xc2, 0xf6, 0xe8,
  57288. 0x2c, 0xec, 0x35, 0xef, 0xa9, 0x13, 0xb8, 0xd2, 0x9c, 0x92, 0x61, 0x91,
  57289. 0xec, 0x7b, 0x0c, 0xea, 0x9a, 0x71, 0x36, 0x15, 0x34, 0x2b, 0x7a, 0x25,
  57290. 0xac, 0xfe, 0xc7, 0x26, 0x89, 0x70, 0x3e, 0x64, 0x68, 0x97, 0x4b, 0xaa,
  57291. 0xc1, 0x24, 0x14, 0xbd, 0x45, 0x2f, 0xe0, 0xfe, 0xf4, 0x2b, 0x8e, 0x08,
  57292. 0x3e, 0xe4, 0xb5, 0x3d, 0x5d, 0xf4, 0xc3, 0xd6, 0x9c, 0xb5, 0x33, 0x1b,
  57293. 0x3b, 0xda, 0x6e, 0x99, 0x7b, 0x09, 0xd1, 0x30, 0x97, 0x23, 0x52, 0x6d,
  57294. 0x1b, 0x71, 0x3a, 0xf4, 0x54, 0xf0, 0xe5, 0x9e
  57295. };
  57296. WOLFSSL_X509* x509 = NULL;
  57297. int certSize = (int)(sizeof(cert_der) / sizeof(unsigned char));
  57298. const char *name1 = "aaaaa";
  57299. int nameLen1 = (int)(XSTRLEN(name1));
  57300. const char *name2 = "a";
  57301. int nameLen2 = (int)(XSTRLEN(name2));
  57302. const char *name3 = "abbbb";
  57303. int nameLen3 = (int)(XSTRLEN(name3));
  57304. const char *name4 = "bbb";
  57305. int nameLen4 = (int)(XSTRLEN(name4));
  57306. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(
  57307. cert_der, certSize, WOLFSSL_FILETYPE_ASN1));
  57308. /* Ensure that "a*" matches "aaaaa" */
  57309. ExpectIntEQ(wolfSSL_X509_check_host(x509, name1, nameLen1,
  57310. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57311. /* Ensure that "a*" matches "a" */
  57312. ExpectIntEQ(wolfSSL_X509_check_host(x509, name2, nameLen2,
  57313. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57314. /* Ensure that "a*" matches "abbbb" */
  57315. ExpectIntEQ(wolfSSL_X509_check_host(x509, name3, nameLen3,
  57316. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57317. /* Ensure that "a*" does not match "bbb" */
  57318. ExpectIntNE(wolfSSL_X509_check_host(x509, name4, nameLen4,
  57319. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), 1);
  57320. wolfSSL_X509_free(x509);
  57321. #endif
  57322. return EXPECT_RESULT();
  57323. }
  57324. static int test_wolfSSL_X509_name_match2(void)
  57325. {
  57326. EXPECT_DECLS;
  57327. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  57328. /* A certificate with the subject alternative name a*b* */
  57329. const unsigned char cert_der[] = {
  57330. 0x30, 0x82, 0x03, 0xae, 0x30, 0x82, 0x02, 0x96, 0xa0, 0x03, 0x02, 0x01,
  57331. 0x02, 0x02, 0x14, 0x41, 0x8c, 0x8b, 0xaa, 0x0e, 0xd8, 0x5a, 0xc0, 0x52,
  57332. 0x46, 0x0e, 0xe5, 0xd8, 0xb9, 0x48, 0x93, 0x7e, 0x8a, 0x7c, 0x65, 0x30,
  57333. 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b,
  57334. 0x05, 0x00, 0x30, 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
  57335. 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55,
  57336. 0x04, 0x08, 0x0c, 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31,
  57337. 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f,
  57338. 0x7a, 0x65, 0x6d, 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55,
  57339. 0x04, 0x0a, 0x0c, 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20,
  57340. 0x49, 0x6e, 0x63, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b,
  57341. 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e,
  57342. 0x67, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f,
  57343. 0x77, 0x77, 0x77, 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e,
  57344. 0x63, 0x6f, 0x6d, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x34, 0x30, 0x35, 0x33,
  57345. 0x30, 0x32, 0x30, 0x34, 0x33, 0x34, 0x30, 0x5a, 0x17, 0x0d, 0x33, 0x34,
  57346. 0x30, 0x35, 0x32, 0x38, 0x32, 0x30, 0x34, 0x33, 0x34, 0x30, 0x5a, 0x30,
  57347. 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,
  57348. 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c,
  57349. 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31, 0x10, 0x30, 0x0e,
  57350. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f, 0x7a, 0x65, 0x6d,
  57351. 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c,
  57352. 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x49, 0x6e, 0x63,
  57353. 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45,
  57354. 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18,
  57355. 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x77, 0x77,
  57356. 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d,
  57357. 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
  57358. 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00,
  57359. 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xa5, 0x60, 0x80,
  57360. 0xf3, 0xee, 0x19, 0xd2, 0xe4, 0x15, 0x94, 0x54, 0x12, 0x88, 0xee, 0xda,
  57361. 0x11, 0x11, 0x87, 0x99, 0x88, 0xb3, 0x71, 0xc7, 0x97, 0x78, 0x1b, 0x57,
  57362. 0x37, 0x1d, 0x0b, 0x1f, 0x2f, 0x2c, 0x35, 0x13, 0x75, 0xd3, 0x31, 0x3e,
  57363. 0x6f, 0x80, 0x21, 0xa5, 0xa3, 0xad, 0x10, 0x81, 0xb6, 0x37, 0xd4, 0x55,
  57364. 0x2e, 0xc1, 0xb8, 0x37, 0xa3, 0x3c, 0xe8, 0x81, 0x03, 0x3c, 0xda, 0x5f,
  57365. 0x6f, 0x45, 0x32, 0x2b, 0x0e, 0x99, 0x27, 0xfd, 0xe5, 0x6c, 0x07, 0xd9,
  57366. 0x4e, 0x0a, 0x8b, 0x23, 0x74, 0x96, 0x25, 0x97, 0xae, 0x6d, 0x19, 0xba,
  57367. 0xbf, 0x0f, 0xc8, 0xa1, 0xe5, 0xea, 0xa8, 0x00, 0x09, 0xc3, 0x9a, 0xef,
  57368. 0x09, 0x33, 0xc1, 0x33, 0x2e, 0x7b, 0x6d, 0xa7, 0x66, 0x87, 0xb6, 0x3a,
  57369. 0xb9, 0xdb, 0x4c, 0x5e, 0xb5, 0x55, 0x69, 0x37, 0x17, 0x92, 0x1f, 0xe3,
  57370. 0x53, 0x1a, 0x2d, 0x25, 0xd0, 0xcf, 0x72, 0x37, 0xc2, 0x89, 0x83, 0x78,
  57371. 0xcf, 0xac, 0x2e, 0x46, 0x92, 0x5c, 0x4a, 0xba, 0x7d, 0xa0, 0x22, 0x34,
  57372. 0xb1, 0x22, 0x26, 0x99, 0xda, 0xe8, 0x97, 0xe2, 0x0c, 0xd3, 0xbc, 0x97,
  57373. 0x7e, 0xa8, 0xb9, 0xe3, 0xe2, 0x7f, 0x56, 0xef, 0x22, 0xee, 0x15, 0x95,
  57374. 0xa6, 0xd1, 0xf4, 0xa7, 0xac, 0x4a, 0xab, 0xc1, 0x1a, 0xda, 0xc5, 0x5f,
  57375. 0xa5, 0x5e, 0x2f, 0x15, 0x9c, 0x36, 0xbe, 0xd3, 0x47, 0xb6, 0x86, 0xb9,
  57376. 0xc6, 0x59, 0x39, 0x36, 0xad, 0x84, 0x53, 0x95, 0x72, 0x91, 0x89, 0x51,
  57377. 0x32, 0x77, 0xf1, 0xa5, 0x93, 0xfe, 0xf0, 0x41, 0x7c, 0x64, 0xf1, 0xb0,
  57378. 0x8b, 0x81, 0x8d, 0x3a, 0x2c, 0x9e, 0xbe, 0x2e, 0x8b, 0xf7, 0x80, 0x63,
  57379. 0x35, 0x32, 0xfa, 0x26, 0xe0, 0x63, 0xbf, 0x5e, 0xaf, 0xf0, 0x08, 0xe0,
  57380. 0x80, 0x65, 0x38, 0xfa, 0x21, 0xaa, 0x91, 0x34, 0x48, 0x3d, 0x32, 0x5c,
  57381. 0xbf, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x32, 0x30, 0x30, 0x30, 0x0f,
  57382. 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, 0x08, 0x30, 0x06, 0x82, 0x04, 0x61,
  57383. 0x2a, 0x62, 0x2a, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16,
  57384. 0x04, 0x14, 0x3d, 0x55, 0x74, 0xf8, 0x3a, 0x26, 0x03, 0x8c, 0x6a, 0x2e,
  57385. 0x91, 0x0e, 0x18, 0x70, 0xb4, 0xa4, 0xcc, 0x04, 0x00, 0xd3, 0x30, 0x0d,
  57386. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05,
  57387. 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x8f, 0x3b, 0xff, 0x46, 0x0c, 0xb5,
  57388. 0x21, 0xdc, 0xcf, 0x61, 0x9a, 0x25, 0x93, 0x99, 0x68, 0x2f, 0x16, 0x71,
  57389. 0x15, 0x00, 0x5f, 0xb0, 0x9b, 0x43, 0x5c, 0x47, 0xe2, 0x8e, 0xc8, 0xea,
  57390. 0xb3, 0x30, 0x4d, 0x87, 0x90, 0xcf, 0x24, 0x37, 0x5c, 0xfd, 0xc8, 0xc6,
  57391. 0x09, 0x36, 0xb2, 0xfb, 0xfd, 0xc1, 0x82, 0x92, 0x77, 0x5b, 0x9d, 0xeb,
  57392. 0xac, 0x47, 0xbc, 0xda, 0x7c, 0x89, 0x19, 0x03, 0x9e, 0xcd, 0x96, 0x2a,
  57393. 0x90, 0x55, 0x23, 0x19, 0xac, 0x9d, 0x49, 0xfb, 0xa0, 0x31, 0x7d, 0x6b,
  57394. 0x1a, 0x16, 0x13, 0xb1, 0xa9, 0xc9, 0xc4, 0xaf, 0xf1, 0xb4, 0xa7, 0x9b,
  57395. 0x08, 0x64, 0x6a, 0x09, 0xcd, 0x4a, 0x03, 0x4c, 0x93, 0xb6, 0xcf, 0x29,
  57396. 0xdb, 0x56, 0x88, 0x8e, 0xed, 0x08, 0x6d, 0x8d, 0x76, 0xa3, 0xd7, 0xc6,
  57397. 0x69, 0xa1, 0xf5, 0xd2, 0xd0, 0x0a, 0x4b, 0xfa, 0x88, 0x66, 0x6c, 0xe5,
  57398. 0x4a, 0xee, 0x13, 0xad, 0xad, 0x22, 0x25, 0x73, 0x39, 0x56, 0x74, 0x0e,
  57399. 0xda, 0xcd, 0x35, 0x67, 0xe3, 0x81, 0x5c, 0xc5, 0xae, 0x3c, 0x4f, 0x47,
  57400. 0x3e, 0x97, 0xde, 0xac, 0xf6, 0xe1, 0x26, 0xe2, 0xe0, 0x66, 0x48, 0x20,
  57401. 0x7c, 0x02, 0x81, 0x3e, 0x7d, 0x34, 0xb7, 0x73, 0x3e, 0x2e, 0xd6, 0x20,
  57402. 0x1c, 0xdf, 0xf1, 0xae, 0x86, 0x8b, 0xb2, 0xc2, 0x9b, 0x68, 0x9c, 0xf6,
  57403. 0x1a, 0x5e, 0x30, 0x06, 0x39, 0x0a, 0x1f, 0x7b, 0xd7, 0x18, 0x4b, 0x06,
  57404. 0x9d, 0xff, 0x84, 0x57, 0xcc, 0x92, 0xad, 0x81, 0x0a, 0x19, 0x11, 0xc4,
  57405. 0xac, 0x59, 0x00, 0xe8, 0x5a, 0x70, 0x78, 0xd6, 0x9f, 0xe0, 0x82, 0x2a,
  57406. 0x1f, 0x09, 0x36, 0x1c, 0x52, 0x98, 0xf7, 0x95, 0x8f, 0xf9, 0x48, 0x4f,
  57407. 0x30, 0x52, 0xb5, 0xf3, 0x8d, 0x13, 0x93, 0x27, 0xbe, 0xb4, 0x75, 0x39,
  57408. 0x65, 0xc6, 0x48, 0x4e, 0x32, 0xd7, 0xf4, 0xc3, 0x26, 0x8d
  57409. };
  57410. WOLFSSL_X509* x509 = NULL;
  57411. int certSize = (int)(sizeof(cert_der) / sizeof(unsigned char));
  57412. const char *name1 = "ab";
  57413. int nameLen1 = (int)(XSTRLEN(name1));
  57414. const char *name2 = "acccbccc";
  57415. int nameLen2 = (int)(XSTRLEN(name2));
  57416. const char *name3 = "accb";
  57417. int nameLen3 = (int)(XSTRLEN(name3));
  57418. const char *name4 = "accda";
  57419. int nameLen4 = (int)(XSTRLEN(name4));
  57420. const char *name5 = "acc\0bcc";
  57421. int nameLen5 = 7;
  57422. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(
  57423. cert_der, certSize, WOLFSSL_FILETYPE_ASN1));
  57424. /* Ensure that "a*b*" matches "ab" */
  57425. ExpectIntEQ(wolfSSL_X509_check_host(x509, name1, nameLen1,
  57426. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57427. /* Ensure that "a*b*" matches "acccbccc" */
  57428. ExpectIntEQ(wolfSSL_X509_check_host(x509, name2, nameLen2,
  57429. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57430. /* Ensure that "a*b*" matches "accb" */
  57431. ExpectIntEQ(wolfSSL_X509_check_host(x509, name3, nameLen3,
  57432. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57433. /* Ensure that "a*b*" does not match "accda" */
  57434. ExpectIntNE(wolfSSL_X509_check_host(x509, name4, nameLen4,
  57435. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57436. /* Ensure that "a*b*" matches "ab", testing openssl behavior replication
  57437. * on check len input handling, 0 for len is OK as it should then use
  57438. * strlen(name1) */
  57439. ExpectIntEQ(wolfSSL_X509_check_host(x509, name1, 0,
  57440. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57441. /* Openssl also allows for len to include NULL terminator */
  57442. ExpectIntEQ(wolfSSL_X509_check_host(x509, name1, nameLen1 + 1,
  57443. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57444. /* Ensure that check string with NULL terminator in middle is
  57445. * rejected */
  57446. ExpectIntNE(wolfSSL_X509_check_host(x509, name5, nameLen5,
  57447. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57448. wolfSSL_X509_free(x509);
  57449. #endif
  57450. return EXPECT_RESULT();
  57451. }
  57452. static int test_wolfSSL_X509_name_match3(void)
  57453. {
  57454. EXPECT_DECLS;
  57455. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  57456. /* A certificate with the subject alternative name *.example.com */
  57457. const unsigned char cert_der[] = {
  57458. 0x30, 0x82, 0x03, 0xb7, 0x30, 0x82, 0x02, 0x9f, 0xa0, 0x03, 0x02, 0x01,
  57459. 0x02, 0x02, 0x14, 0x59, 0xbb, 0xf6, 0xde, 0xb8, 0x3d, 0x0e, 0x8c, 0xe4,
  57460. 0xbd, 0x98, 0xa3, 0xbe, 0x3e, 0x8f, 0xdc, 0xbd, 0x7f, 0xcc, 0xae, 0x30,
  57461. 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b,
  57462. 0x05, 0x00, 0x30, 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
  57463. 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55,
  57464. 0x04, 0x08, 0x0c, 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31,
  57465. 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f,
  57466. 0x7a, 0x65, 0x6d, 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55,
  57467. 0x04, 0x0a, 0x0c, 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20,
  57468. 0x49, 0x6e, 0x63, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b,
  57469. 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e,
  57470. 0x67, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f,
  57471. 0x77, 0x77, 0x77, 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e,
  57472. 0x63, 0x6f, 0x6d, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x34, 0x30, 0x35, 0x33,
  57473. 0x31, 0x30, 0x30, 0x33, 0x37, 0x34, 0x39, 0x5a, 0x17, 0x0d, 0x33, 0x34,
  57474. 0x30, 0x35, 0x32, 0x39, 0x30, 0x30, 0x33, 0x37, 0x34, 0x39, 0x5a, 0x30,
  57475. 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,
  57476. 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c,
  57477. 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31, 0x10, 0x30, 0x0e,
  57478. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f, 0x7a, 0x65, 0x6d,
  57479. 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c,
  57480. 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x49, 0x6e, 0x63,
  57481. 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45,
  57482. 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18,
  57483. 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x77, 0x77,
  57484. 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d,
  57485. 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
  57486. 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00,
  57487. 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xda, 0x78, 0x16,
  57488. 0x05, 0x65, 0xf2, 0x85, 0xf2, 0x61, 0x7f, 0xb1, 0x4d, 0x73, 0xe2, 0x82,
  57489. 0xb5, 0x3d, 0xf7, 0x9d, 0x05, 0x65, 0xed, 0x9d, 0xc3, 0x29, 0x7a, 0x92,
  57490. 0x2c, 0x06, 0x5f, 0xc8, 0x13, 0x55, 0x42, 0x4e, 0xbd, 0xe2, 0x56, 0x2a,
  57491. 0x4b, 0xac, 0xe6, 0x1b, 0x10, 0xc9, 0xdb, 0x9a, 0x45, 0x36, 0xed, 0xf3,
  57492. 0x26, 0x8c, 0x22, 0x88, 0x1e, 0x6d, 0x2b, 0x41, 0xfa, 0x0d, 0x43, 0x88,
  57493. 0x88, 0xde, 0x8d, 0x2e, 0xca, 0x6e, 0x7c, 0x62, 0x66, 0x3e, 0xfa, 0x4e,
  57494. 0x71, 0xea, 0x7d, 0x3b, 0x32, 0x33, 0x5c, 0x7a, 0x7e, 0xea, 0x74, 0xbd,
  57495. 0xb6, 0x8f, 0x4c, 0x1c, 0x7a, 0x79, 0x94, 0xf1, 0xe8, 0x02, 0x67, 0x98,
  57496. 0x25, 0xb4, 0x31, 0x80, 0xc1, 0xae, 0xbf, 0xef, 0xf2, 0x6c, 0x78, 0x42,
  57497. 0xef, 0xb5, 0xc6, 0x01, 0x47, 0x79, 0x8d, 0x92, 0xce, 0xc1, 0xb5, 0x98,
  57498. 0x76, 0xf0, 0x84, 0xa2, 0x53, 0x90, 0xe5, 0x39, 0xc7, 0xbd, 0xf2, 0xbb,
  57499. 0xe3, 0x3f, 0x00, 0xf6, 0xf0, 0x46, 0x86, 0xee, 0x55, 0xbd, 0x2c, 0x1f,
  57500. 0x97, 0x24, 0x7c, 0xbc, 0xda, 0x2f, 0x1b, 0x53, 0xef, 0x26, 0x56, 0xcc,
  57501. 0xb7, 0xd8, 0xca, 0x17, 0x20, 0x4e, 0x62, 0x03, 0x66, 0x32, 0xb3, 0xd1,
  57502. 0x71, 0x26, 0x6c, 0xff, 0xd1, 0x9e, 0x44, 0x86, 0x2a, 0xae, 0xba, 0x43,
  57503. 0x00, 0x13, 0x7e, 0x50, 0xdd, 0x3e, 0x27, 0x39, 0x70, 0x1c, 0x0c, 0x0b,
  57504. 0xe8, 0xa2, 0xae, 0x03, 0x09, 0x2e, 0xd8, 0x71, 0xee, 0x7b, 0x1a, 0x09,
  57505. 0x2d, 0xe1, 0xd5, 0xde, 0xf5, 0xa3, 0x36, 0x77, 0x90, 0x97, 0x99, 0xd7,
  57506. 0x6c, 0xb7, 0x5c, 0x9d, 0xf7, 0x7e, 0x41, 0x89, 0xfe, 0xe4, 0x08, 0xc6,
  57507. 0x0b, 0xe4, 0x9b, 0x5f, 0x51, 0xa6, 0x08, 0xb8, 0x99, 0x81, 0xe9, 0xce,
  57508. 0xb4, 0x2d, 0xb2, 0x92, 0x9f, 0xe5, 0x1a, 0x98, 0x76, 0x20, 0x70, 0x54,
  57509. 0x93, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x3b, 0x30, 0x39, 0x30, 0x18,
  57510. 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, 0x11, 0x30, 0x0f, 0x82, 0x0d, 0x2a,
  57511. 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d,
  57512. 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x60,
  57513. 0xd4, 0x26, 0xbb, 0xcc, 0x7c, 0x29, 0xa2, 0x88, 0x3c, 0x76, 0x7d, 0xb4,
  57514. 0x86, 0x8b, 0x47, 0x64, 0x5b, 0x87, 0xe0, 0x30, 0x0d, 0x06, 0x09, 0x2a,
  57515. 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82,
  57516. 0x01, 0x01, 0x00, 0xc3, 0x0d, 0x03, 0x67, 0xbb, 0x47, 0x8b, 0xf3, 0x20,
  57517. 0xdc, 0x7d, 0x2e, 0xe1, 0xd9, 0xf0, 0x01, 0xc4, 0x66, 0xc2, 0xe1, 0xcd,
  57518. 0xc3, 0x4a, 0x72, 0xf0, 0x6e, 0x38, 0xcf, 0x63, 0x01, 0x96, 0x9e, 0x84,
  57519. 0xb9, 0xce, 0x1d, 0xba, 0x4b, 0xe0, 0x70, 0x86, 0x2b, 0x5a, 0xab, 0xec,
  57520. 0xbf, 0xc2, 0xaa, 0x64, 0xa2, 0x6c, 0xd2, 0x42, 0x52, 0xd4, 0xbe, 0x8a,
  57521. 0xca, 0x9c, 0x03, 0xf3, 0xd6, 0x5f, 0xcd, 0x23, 0x9f, 0xf5, 0xa9, 0x04,
  57522. 0x40, 0x5b, 0x66, 0x78, 0xc0, 0xac, 0xa1, 0xdb, 0x5d, 0xd1, 0x94, 0xfc,
  57523. 0x47, 0x94, 0xf5, 0x45, 0xe3, 0x70, 0x13, 0x3f, 0x66, 0x6d, 0xdd, 0x73,
  57524. 0x68, 0x68, 0xe2, 0xd2, 0x89, 0xcb, 0x7f, 0xc6, 0xca, 0xd6, 0x96, 0x0b,
  57525. 0xcc, 0xdd, 0xa1, 0x74, 0xda, 0x33, 0xe8, 0x9e, 0xda, 0xb7, 0xd9, 0x12,
  57526. 0xab, 0x85, 0x9d, 0x0c, 0xde, 0xa0, 0x7d, 0x7e, 0xa1, 0x91, 0xed, 0xe5,
  57527. 0x32, 0x7c, 0xc5, 0xea, 0x1d, 0x4a, 0xb5, 0x38, 0x63, 0x17, 0xf3, 0x4f,
  57528. 0x2c, 0x4a, 0x58, 0x86, 0x09, 0x33, 0x86, 0xc4, 0xe7, 0x56, 0x6f, 0x32,
  57529. 0x71, 0xb7, 0xd0, 0x83, 0x12, 0x9e, 0x26, 0x0a, 0x3a, 0x45, 0xcb, 0xd7,
  57530. 0x4e, 0xab, 0xa4, 0xc3, 0xee, 0x4c, 0xc0, 0x38, 0xa1, 0xfa, 0xba, 0xfa,
  57531. 0xb7, 0x80, 0x69, 0x67, 0xa3, 0xef, 0x89, 0xba, 0xce, 0x89, 0x91, 0x3d,
  57532. 0x6a, 0x76, 0xe9, 0x3b, 0x32, 0x86, 0x76, 0x85, 0x6b, 0x4f, 0x7f, 0xbc,
  57533. 0x7a, 0x5b, 0x31, 0x92, 0x79, 0x35, 0xf8, 0xb9, 0xb1, 0xd7, 0xdb, 0xa9,
  57534. 0x6a, 0x8a, 0x91, 0x60, 0x65, 0xd4, 0x76, 0x54, 0x55, 0x57, 0xb9, 0x35,
  57535. 0xe0, 0xf5, 0xbb, 0x8f, 0xd4, 0x40, 0x75, 0xbb, 0x47, 0xa8, 0xf9, 0x0f,
  57536. 0xea, 0xc9, 0x6e, 0x84, 0xd5, 0xf5, 0x58, 0x2d, 0xe5, 0x76, 0x7b, 0xdf,
  57537. 0x97, 0x05, 0x5e, 0xaf, 0x50, 0xf5, 0x48
  57538. };
  57539. WOLFSSL_X509* x509 = NULL;
  57540. int certSize = (int)(sizeof(cert_der) / sizeof(unsigned char));
  57541. const char *name1 = "foo.example.com";
  57542. int nameLen1 = (int)(XSTRLEN(name1));
  57543. const char *name2 = "x.y.example.com";
  57544. int nameLen2 = (int)(XSTRLEN(name2));
  57545. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(
  57546. cert_der, certSize, WOLFSSL_FILETYPE_ASN1));
  57547. /* Ensure that "*.example.com" matches "foo.example.com" */
  57548. ExpectIntEQ(wolfSSL_X509_check_host(x509, name1, nameLen1,
  57549. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57550. /* Ensure that "*.example.com" does NOT match "x.y.example.com" */
  57551. ExpectIntNE(wolfSSL_X509_check_host(x509, name2, nameLen2,
  57552. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  57553. wolfSSL_X509_free(x509);
  57554. #endif
  57555. return EXPECT_RESULT();
  57556. }
  57557. static int test_wolfSSL_X509_max_altnames(void)
  57558. {
  57559. EXPECT_DECLS;
  57560. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA)
  57561. /* Only test if max alt names has not been modified */
  57562. #if WOLFSSL_MAX_ALT_NAMES <= 1024
  57563. WOLFSSL_CTX* ctx = NULL;
  57564. /* File contains a certificate encoded with 130 subject alternative names */
  57565. const char* over_max_altnames_cert = \
  57566. "./certs/test/cert-over-max-altnames.pem";
  57567. #ifndef NO_WOLFSSL_SERVER
  57568. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  57569. #else
  57570. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  57571. #endif
  57572. ExpectIntNE(wolfSSL_CTX_load_verify_locations_ex(ctx,
  57573. over_max_altnames_cert, NULL, WOLFSSL_LOAD_FLAG_NONE),
  57574. WOLFSSL_SUCCESS);
  57575. wolfSSL_CTX_free(ctx);
  57576. #endif
  57577. #endif
  57578. return EXPECT_RESULT();
  57579. }
  57580. static int test_wolfSSL_X509_max_name_constraints(void)
  57581. {
  57582. EXPECT_DECLS;
  57583. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  57584. !defined(IGNORE_NAME_CONSTRAINTS)
  57585. /* Only test if max name constraints has not been modified */
  57586. #if WOLFSSL_MAX_NAME_CONSTRAINTS == 128
  57587. WOLFSSL_CTX* ctx = NULL;
  57588. /* File contains a certificate with 130 name constraints */
  57589. const char* over_max_nc = "./certs/test/cert-over-max-nc.pem";
  57590. #ifndef NO_WOLFSSL_SERVER
  57591. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  57592. #else
  57593. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  57594. #endif
  57595. ExpectIntNE(wolfSSL_CTX_load_verify_locations_ex(ctx, over_max_nc,
  57596. NULL, WOLFSSL_LOAD_FLAG_NONE), WOLFSSL_SUCCESS);
  57597. wolfSSL_CTX_free(ctx);
  57598. #endif
  57599. #endif
  57600. return EXPECT_RESULT();
  57601. }
  57602. static int test_wolfSSL_X509(void)
  57603. {
  57604. EXPECT_DECLS;
  57605. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  57606. !defined(NO_RSA)
  57607. X509* x509 = NULL;
  57608. #ifndef NO_BIO
  57609. BIO* bio = NULL;
  57610. X509_STORE_CTX* ctx = NULL;
  57611. X509_STORE* store = NULL;
  57612. #endif
  57613. char der[] = "certs/ca-cert.der";
  57614. XFILE fp = XBADFILE;
  57615. ExpectNotNull(x509 = X509_new());
  57616. X509_free(x509);
  57617. x509 = NULL;
  57618. #ifndef NO_BIO
  57619. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  57620. SSL_FILETYPE_PEM));
  57621. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  57622. #ifdef WOLFSSL_CERT_GEN
  57623. ExpectIntEQ(i2d_X509_bio(bio, x509), SSL_SUCCESS);
  57624. #endif
  57625. ExpectNotNull(ctx = X509_STORE_CTX_new());
  57626. ExpectIntEQ(X509_verify_cert(ctx), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  57627. ExpectNotNull(store = X509_STORE_new());
  57628. ExpectIntEQ(X509_STORE_add_cert(store, x509), SSL_SUCCESS);
  57629. ExpectIntEQ(X509_STORE_CTX_init(ctx, store, x509, NULL), SSL_SUCCESS);
  57630. ExpectIntEQ(X509_verify_cert(ctx), SSL_SUCCESS);
  57631. X509_STORE_CTX_free(ctx);
  57632. X509_STORE_free(store);
  57633. X509_free(x509);
  57634. x509 = NULL;
  57635. BIO_free(bio);
  57636. #endif
  57637. /** d2i_X509_fp test **/
  57638. ExpectTrue((fp = XFOPEN(der, "rb")) != XBADFILE);
  57639. ExpectNotNull(x509 = (X509 *)d2i_X509_fp(fp, (X509 **)NULL));
  57640. ExpectNotNull(x509);
  57641. X509_free(x509);
  57642. x509 = NULL;
  57643. if (fp != XBADFILE) {
  57644. XFCLOSE(fp);
  57645. fp = XBADFILE;
  57646. }
  57647. ExpectTrue((fp = XFOPEN(der, "rb")) != XBADFILE);
  57648. ExpectNotNull((X509 *)d2i_X509_fp(fp, (X509 **)&x509));
  57649. ExpectNotNull(x509);
  57650. X509_free(x509);
  57651. if (fp != XBADFILE)
  57652. XFCLOSE(fp);
  57653. /* X509_up_ref test */
  57654. ExpectIntEQ(X509_up_ref(NULL), 0);
  57655. ExpectNotNull(x509 = X509_new()); /* refCount = 1 */
  57656. ExpectIntEQ(X509_up_ref(x509), 1); /* refCount = 2 */
  57657. ExpectIntEQ(X509_up_ref(x509), 1); /* refCount = 3 */
  57658. X509_free(x509); /* refCount = 2 */
  57659. X509_free(x509); /* refCount = 1 */
  57660. X509_free(x509); /* refCount = 0, free */
  57661. #endif
  57662. return EXPECT_RESULT();
  57663. }
  57664. static int test_wolfSSL_X509_get_ext_count(void)
  57665. {
  57666. EXPECT_DECLS;
  57667. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  57668. !defined(NO_RSA)
  57669. int ret = 0;
  57670. WOLFSSL_X509* x509 = NULL;
  57671. const char ocspRootCaFile[] = "./certs/ocsp/root-ca-cert.pem";
  57672. XFILE f = XBADFILE;
  57673. /* NULL parameter check */
  57674. ExpectIntEQ(X509_get_ext_count(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57675. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  57676. SSL_FILETYPE_PEM));
  57677. ExpectIntEQ(X509_get_ext_count(x509), 5);
  57678. wolfSSL_X509_free(x509);
  57679. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(ocspRootCaFile,
  57680. SSL_FILETYPE_PEM));
  57681. ExpectIntEQ(X509_get_ext_count(x509), 5);
  57682. wolfSSL_X509_free(x509);
  57683. ExpectTrue((f = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  57684. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  57685. if (f != XBADFILE)
  57686. XFCLOSE(f);
  57687. /* wolfSSL_X509_get_ext_count() valid input */
  57688. ExpectIntEQ((ret = wolfSSL_X509_get_ext_count(x509)), 5);
  57689. /* wolfSSL_X509_get_ext_count() NULL argument */
  57690. ExpectIntEQ((ret = wolfSSL_X509_get_ext_count(NULL)), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57691. wolfSSL_X509_free(x509);
  57692. #endif
  57693. return EXPECT_RESULT();
  57694. }
  57695. static int test_wolfSSL_X509_sign2(void)
  57696. {
  57697. EXPECT_DECLS;
  57698. /* test requires WOLFSSL_AKID_NAME to match expected output */
  57699. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_CERTS) && \
  57700. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_ALT_NAMES) && \
  57701. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_AKID_NAME) && \
  57702. (defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || \
  57703. defined(WOLFSSL_IP_ALT_NAME))
  57704. WOLFSSL_X509 *x509 = NULL;
  57705. WOLFSSL_X509 *ca = NULL;
  57706. const unsigned char *der = NULL;
  57707. const unsigned char *pt = NULL;
  57708. WOLFSSL_EVP_PKEY *priv = NULL;
  57709. WOLFSSL_X509_NAME *name = NULL;
  57710. int derSz;
  57711. #ifndef NO_ASN_TIME
  57712. WOLFSSL_ASN1_TIME *notBefore = NULL;
  57713. WOLFSSL_ASN1_TIME *notAfter = NULL;
  57714. const int year = 365*24*60*60;
  57715. const int day = 24*60*60;
  57716. const int hour = 60*60;
  57717. const int mini = 60;
  57718. time_t t;
  57719. #endif
  57720. const unsigned char expected[] = {
  57721. 0x30, 0x82, 0x05, 0x13, 0x30, 0x82, 0x03, 0xFB, 0xA0, 0x03, 0x02, 0x01,
  57722. 0x02, 0x02, 0x14, 0x08, 0xB0, 0x54, 0x7A, 0x03, 0x5A, 0xEC, 0x55, 0x8A,
  57723. 0x12, 0xE8, 0xF9, 0x8E, 0x34, 0xB6, 0x13, 0xD9, 0x59, 0xB8, 0xE8, 0x30,
  57724. 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B,
  57725. 0x05, 0x00, 0x30, 0x81, 0x94, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55,
  57726. 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03,
  57727. 0x55, 0x04, 0x08, 0x0C, 0x07, 0x4D, 0x6F, 0x6E, 0x74, 0x61, 0x6E, 0x61,
  57728. 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0C, 0x07, 0x42,
  57729. 0x6F, 0x7A, 0x65, 0x6D, 0x61, 0x6E, 0x31, 0x11, 0x30, 0x0F, 0x06, 0x03,
  57730. 0x55, 0x04, 0x0A, 0x0C, 0x08, 0x53, 0x61, 0x77, 0x74, 0x6F, 0x6F, 0x74,
  57731. 0x68, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x0A,
  57732. 0x43, 0x6F, 0x6E, 0x73, 0x75, 0x6C, 0x74, 0x69, 0x6E, 0x67, 0x31, 0x18,
  57733. 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x77, 0x77, 0x77,
  57734. 0x2E, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D,
  57735. 0x31, 0x1F, 0x30, 0x1D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  57736. 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40, 0x77, 0x6F,
  57737. 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x30, 0x1E, 0x17,
  57738. 0x0D, 0x30, 0x30, 0x30, 0x32, 0x31, 0x35, 0x32, 0x30, 0x33, 0x30, 0x30,
  57739. 0x30, 0x5A, 0x17, 0x0D, 0x30, 0x31, 0x30, 0x32, 0x31, 0x34, 0x32, 0x30,
  57740. 0x33, 0x30, 0x30, 0x30, 0x5A, 0x30, 0x81, 0x9E, 0x31, 0x0B, 0x30, 0x09,
  57741. 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30,
  57742. 0x0E, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0C, 0x07, 0x4D, 0x6F, 0x6E, 0x74,
  57743. 0x61, 0x6E, 0x61, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x04, 0x07,
  57744. 0x0C, 0x07, 0x42, 0x6F, 0x7A, 0x65, 0x6D, 0x61, 0x6E, 0x31, 0x15, 0x30,
  57745. 0x13, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x0C, 0x77, 0x6F, 0x6C, 0x66,
  57746. 0x53, 0x53, 0x4C, 0x5F, 0x32, 0x30, 0x34, 0x38, 0x31, 0x19, 0x30, 0x17,
  57747. 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x10, 0x50, 0x72, 0x6F, 0x67, 0x72,
  57748. 0x61, 0x6D, 0x6D, 0x69, 0x6E, 0x67, 0x2D, 0x32, 0x30, 0x34, 0x38, 0x31,
  57749. 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x77, 0x77,
  57750. 0x77, 0x2E, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F,
  57751. 0x6D, 0x31, 0x1F, 0x30, 0x1D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7,
  57752. 0x0D, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40, 0x77,
  57753. 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x30, 0x82,
  57754. 0x01, 0x22, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  57755. 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0F, 0x00, 0x30, 0x82,
  57756. 0x01, 0x0A, 0x02, 0x82, 0x01, 0x01, 0x00, 0xC3, 0x03, 0xD1, 0x2B, 0xFE,
  57757. 0x39, 0xA4, 0x32, 0x45, 0x3B, 0x53, 0xC8, 0x84, 0x2B, 0x2A, 0x7C, 0x74,
  57758. 0x9A, 0xBD, 0xAA, 0x2A, 0x52, 0x07, 0x47, 0xD6, 0xA6, 0x36, 0xB2, 0x07,
  57759. 0x32, 0x8E, 0xD0, 0xBA, 0x69, 0x7B, 0xC6, 0xC3, 0x44, 0x9E, 0xD4, 0x81,
  57760. 0x48, 0xFD, 0x2D, 0x68, 0xA2, 0x8B, 0x67, 0xBB, 0xA1, 0x75, 0xC8, 0x36,
  57761. 0x2C, 0x4A, 0xD2, 0x1B, 0xF7, 0x8B, 0xBA, 0xCF, 0x0D, 0xF9, 0xEF, 0xEC,
  57762. 0xF1, 0x81, 0x1E, 0x7B, 0x9B, 0x03, 0x47, 0x9A, 0xBF, 0x65, 0xCC, 0x7F,
  57763. 0x65, 0x24, 0x69, 0xA6, 0xE8, 0x14, 0x89, 0x5B, 0xE4, 0x34, 0xF7, 0xC5,
  57764. 0xB0, 0x14, 0x93, 0xF5, 0x67, 0x7B, 0x3A, 0x7A, 0x78, 0xE1, 0x01, 0x56,
  57765. 0x56, 0x91, 0xA6, 0x13, 0x42, 0x8D, 0xD2, 0x3C, 0x40, 0x9C, 0x4C, 0xEF,
  57766. 0xD1, 0x86, 0xDF, 0x37, 0x51, 0x1B, 0x0C, 0xA1, 0x3B, 0xF5, 0xF1, 0xA3,
  57767. 0x4A, 0x35, 0xE4, 0xE1, 0xCE, 0x96, 0xDF, 0x1B, 0x7E, 0xBF, 0x4E, 0x97,
  57768. 0xD0, 0x10, 0xE8, 0xA8, 0x08, 0x30, 0x81, 0xAF, 0x20, 0x0B, 0x43, 0x14,
  57769. 0xC5, 0x74, 0x67, 0xB4, 0x32, 0x82, 0x6F, 0x8D, 0x86, 0xC2, 0x88, 0x40,
  57770. 0x99, 0x36, 0x83, 0xBA, 0x1E, 0x40, 0x72, 0x22, 0x17, 0xD7, 0x52, 0x65,
  57771. 0x24, 0x73, 0xB0, 0xCE, 0xEF, 0x19, 0xCD, 0xAE, 0xFF, 0x78, 0x6C, 0x7B,
  57772. 0xC0, 0x12, 0x03, 0xD4, 0x4E, 0x72, 0x0D, 0x50, 0x6D, 0x3B, 0xA3, 0x3B,
  57773. 0xA3, 0x99, 0x5E, 0x9D, 0xC8, 0xD9, 0x0C, 0x85, 0xB3, 0xD9, 0x8A, 0xD9,
  57774. 0x54, 0x26, 0xDB, 0x6D, 0xFA, 0xAC, 0xBB, 0xFF, 0x25, 0x4C, 0xC4, 0xD1,
  57775. 0x79, 0xF4, 0x71, 0xD3, 0x86, 0x40, 0x18, 0x13, 0xB0, 0x63, 0xB5, 0x72,
  57776. 0x4E, 0x30, 0xC4, 0x97, 0x84, 0x86, 0x2D, 0x56, 0x2F, 0xD7, 0x15, 0xF7,
  57777. 0x7F, 0xC0, 0xAE, 0xF5, 0xFC, 0x5B, 0xE5, 0xFB, 0xA1, 0xBA, 0xD3, 0x02,
  57778. 0x03, 0x01, 0x00, 0x01, 0xA3, 0x82, 0x01, 0x4F, 0x30, 0x82, 0x01, 0x4B,
  57779. 0x30, 0x0C, 0x06, 0x03, 0x55, 0x1D, 0x13, 0x04, 0x05, 0x30, 0x03, 0x01,
  57780. 0x01, 0xFF, 0x30, 0x1C, 0x06, 0x03, 0x55, 0x1D, 0x11, 0x04, 0x15, 0x30,
  57781. 0x13, 0x82, 0x0B, 0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x2E, 0x63,
  57782. 0x6F, 0x6D, 0x87, 0x04, 0x7F, 0x00, 0x00, 0x01, 0x30, 0x1D, 0x06, 0x03,
  57783. 0x55, 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0x33, 0xD8, 0x45, 0x66, 0xD7,
  57784. 0x68, 0x87, 0x18, 0x7E, 0x54, 0x0D, 0x70, 0x27, 0x91, 0xC7, 0x26, 0xD7,
  57785. 0x85, 0x65, 0xC0, 0x30, 0x81, 0xDE, 0x06, 0x03, 0x55, 0x1D, 0x23, 0x04,
  57786. 0x81, 0xD6, 0x30, 0x81, 0xD3, 0x80, 0x14, 0x33, 0xD8, 0x45, 0x66, 0xD7,
  57787. 0x68, 0x87, 0x18, 0x7E, 0x54, 0x0D, 0x70, 0x27, 0x91, 0xC7, 0x26, 0xD7,
  57788. 0x85, 0x65, 0xC0, 0xA1, 0x81, 0xA4, 0xA4, 0x81, 0xA1, 0x30, 0x81, 0x9E,
  57789. 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55,
  57790. 0x53, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0C, 0x07,
  57791. 0x4D, 0x6F, 0x6E, 0x74, 0x61, 0x6E, 0x61, 0x31, 0x10, 0x30, 0x0E, 0x06,
  57792. 0x03, 0x55, 0x04, 0x07, 0x0C, 0x07, 0x42, 0x6F, 0x7A, 0x65, 0x6D, 0x61,
  57793. 0x6E, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x0C,
  57794. 0x77, 0x6F, 0x6C, 0x66, 0x53, 0x53, 0x4C, 0x5F, 0x32, 0x30, 0x34, 0x38,
  57795. 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x10, 0x50,
  57796. 0x72, 0x6F, 0x67, 0x72, 0x61, 0x6D, 0x6D, 0x69, 0x6E, 0x67, 0x2D, 0x32,
  57797. 0x30, 0x34, 0x38, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03,
  57798. 0x0C, 0x0F, 0x77, 0x77, 0x77, 0x2E, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73,
  57799. 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x31, 0x1F, 0x30, 0x1D, 0x06, 0x09, 0x2A,
  57800. 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6E,
  57801. 0x66, 0x6F, 0x40, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63,
  57802. 0x6F, 0x6D, 0x82, 0x14, 0x08, 0xB0, 0x54, 0x7A, 0x03, 0x5A, 0xEC, 0x55,
  57803. 0x8A, 0x12, 0xE8, 0xF9, 0x8E, 0x34, 0xB6, 0x13, 0xD9, 0x59, 0xB8, 0xE8,
  57804. 0x30, 0x1D, 0x06, 0x03, 0x55, 0x1D, 0x25, 0x04, 0x16, 0x30, 0x14, 0x06,
  57805. 0x08, 0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x01, 0x06, 0x08, 0x2B,
  57806. 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x02, 0x30, 0x0D, 0x06, 0x09, 0x2A,
  57807. 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B, 0x05, 0x00, 0x03, 0x82,
  57808. 0x01, 0x01, 0x00, 0x14, 0xFB, 0xD0, 0xCE, 0x31, 0x7F, 0xA5, 0x59, 0xFA,
  57809. 0x7C, 0x68, 0x26, 0xA7, 0xE8, 0x0D, 0x9F, 0x50, 0x57, 0xFA, 0x1C, 0x7C,
  57810. 0x5E, 0x43, 0xA4, 0x97, 0x47, 0xB6, 0x41, 0xAC, 0x63, 0xD3, 0x61, 0x8C,
  57811. 0x1F, 0x42, 0xEF, 0x53, 0xD0, 0xBA, 0x31, 0x4D, 0x99, 0x74, 0xA4, 0x60,
  57812. 0xDC, 0xC6, 0x6F, 0xCC, 0x1E, 0x25, 0x98, 0xE1, 0xA4, 0xA0, 0x67, 0x69,
  57813. 0x97, 0xE3, 0x97, 0x7C, 0x83, 0x28, 0xF1, 0xF4, 0x7D, 0x03, 0xA8, 0x31,
  57814. 0x77, 0xCC, 0xD1, 0x37, 0xEF, 0x7B, 0x4A, 0x71, 0x2D, 0x11, 0x7E, 0x92,
  57815. 0xF5, 0x67, 0xB7, 0x56, 0xBA, 0x28, 0xF8, 0xD6, 0xCE, 0x2A, 0x71, 0xE3,
  57816. 0x70, 0x6B, 0x09, 0x0F, 0x67, 0x6F, 0x7A, 0xE0, 0x89, 0xF6, 0x5E, 0x23,
  57817. 0x0C, 0x0A, 0x44, 0x4E, 0x65, 0x8E, 0x7B, 0x68, 0xD0, 0xAD, 0x76, 0x3E,
  57818. 0x2A, 0x0E, 0xA2, 0x05, 0x11, 0x74, 0x24, 0x08, 0x60, 0xED, 0x9F, 0x98,
  57819. 0x18, 0xE9, 0x91, 0x58, 0x36, 0xEC, 0xEC, 0x25, 0x6B, 0xBA, 0x9C, 0x87,
  57820. 0x38, 0x68, 0xDC, 0xDC, 0x15, 0x6F, 0x20, 0x68, 0xC4, 0xBF, 0x05, 0x5B,
  57821. 0x4A, 0x0C, 0x44, 0x2B, 0x92, 0x3F, 0x10, 0x99, 0xDC, 0xF6, 0x6C, 0x0E,
  57822. 0x34, 0x26, 0x6E, 0x6D, 0x4E, 0x12, 0xBC, 0x60, 0x8F, 0x27, 0x1D, 0x7A,
  57823. 0x00, 0x50, 0xBE, 0x23, 0xDE, 0x48, 0x47, 0x9F, 0xAD, 0x2F, 0x94, 0x3D,
  57824. 0x16, 0x73, 0x48, 0x6B, 0xC8, 0x97, 0xE6, 0xB4, 0xB3, 0x4B, 0xE1, 0x68,
  57825. 0x08, 0xC3, 0xE5, 0x34, 0x5F, 0x9B, 0xDA, 0xAB, 0xCA, 0x6D, 0x55, 0x32,
  57826. 0xEF, 0x6C, 0xEF, 0x9B, 0x8B, 0x5B, 0xC7, 0xF0, 0xC2, 0x0F, 0x8E, 0x93,
  57827. 0x09, 0x60, 0x3C, 0x0B, 0xDC, 0xBD, 0xDB, 0x4A, 0x2D, 0xD0, 0x98, 0xAA,
  57828. 0xAB, 0x6C, 0x6F, 0x6D, 0x6B, 0x6A, 0x5C, 0x33, 0xAC, 0xAD, 0xA8, 0x1B,
  57829. 0x38, 0x5D, 0x9F, 0xDA, 0xE7, 0x70, 0x07
  57830. };
  57831. pt = ca_key_der_2048;
  57832. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, &pt,
  57833. sizeof_ca_key_der_2048));
  57834. pt = client_cert_der_2048;
  57835. ExpectNotNull(x509 = wolfSSL_d2i_X509(NULL, &pt,
  57836. sizeof_client_cert_der_2048));
  57837. pt = ca_cert_der_2048;
  57838. ExpectNotNull(ca = wolfSSL_d2i_X509(NULL, &pt, sizeof_ca_cert_der_2048));
  57839. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  57840. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  57841. #ifndef NO_ASN_TIME
  57842. t = (time_t)30 * year + 45 * day + 20 * hour + 30 * mini + 7 * day;
  57843. ExpectNotNull(notBefore = wolfSSL_ASN1_TIME_adj(NULL, t, 0, 0));
  57844. ExpectNotNull(notAfter = wolfSSL_ASN1_TIME_adj(NULL, t, 365, 0));
  57845. ExpectIntEQ(notAfter->length, 13);
  57846. ExpectTrue(wolfSSL_X509_set_notBefore(x509, notBefore));
  57847. ExpectTrue(wolfSSL_X509_set_notAfter(x509, notAfter));
  57848. #endif
  57849. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  57850. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  57851. ExpectIntEQ(derSz, sizeof(expected));
  57852. #ifndef NO_ASN_TIME
  57853. ExpectIntEQ(XMEMCMP(der, expected, derSz), 0);
  57854. #endif
  57855. wolfSSL_X509_free(ca);
  57856. wolfSSL_X509_free(x509);
  57857. wolfSSL_EVP_PKEY_free(priv);
  57858. #ifndef NO_ASN_TIME
  57859. wolfSSL_ASN1_TIME_free(notBefore);
  57860. wolfSSL_ASN1_TIME_free(notAfter);
  57861. #endif
  57862. #endif
  57863. return EXPECT_RESULT();
  57864. }
  57865. static int test_wolfSSL_X509_sign(void)
  57866. {
  57867. EXPECT_DECLS;
  57868. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_ASN_TIME) && \
  57869. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && !defined(NO_RSA)
  57870. int ret = 0;
  57871. char *cn = NULL;
  57872. word32 cnSz = 0;
  57873. X509_NAME *name = NULL;
  57874. X509 *x509 = NULL;
  57875. X509 *ca = NULL;
  57876. DecodedCert dCert;
  57877. EVP_PKEY *pub = NULL;
  57878. EVP_PKEY *priv = NULL;
  57879. EVP_MD_CTX *mctx = NULL;
  57880. #if defined(USE_CERT_BUFFERS_1024)
  57881. const unsigned char* rsaPriv = client_key_der_1024;
  57882. const unsigned char* rsaPub = client_keypub_der_1024;
  57883. const unsigned char* certIssuer = client_cert_der_1024;
  57884. long clientKeySz = (long)sizeof_client_key_der_1024;
  57885. long clientPubKeySz = (long)sizeof_client_keypub_der_1024;
  57886. long certIssuerSz = (long)sizeof_client_cert_der_1024;
  57887. #elif defined(USE_CERT_BUFFERS_2048)
  57888. const unsigned char* rsaPriv = client_key_der_2048;
  57889. const unsigned char* rsaPub = client_keypub_der_2048;
  57890. const unsigned char* certIssuer = client_cert_der_2048;
  57891. long clientKeySz = (long)sizeof_client_key_der_2048;
  57892. long clientPubKeySz = (long)sizeof_client_keypub_der_2048;
  57893. long certIssuerSz = (long)sizeof_client_cert_der_2048;
  57894. #endif
  57895. byte sn[16];
  57896. int snSz = sizeof(sn);
  57897. /* Set X509_NAME fields */
  57898. ExpectNotNull(name = X509_NAME_new());
  57899. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  57900. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  57901. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  57902. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  57903. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  57904. (byte*)"support@wolfssl.com", 19, -1, 0), SSL_SUCCESS);
  57905. /* Get private and public keys */
  57906. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, &rsaPriv,
  57907. clientKeySz));
  57908. ExpectNotNull(pub = wolfSSL_d2i_PUBKEY(NULL, &rsaPub, clientPubKeySz));
  57909. ExpectNotNull(x509 = X509_new());
  57910. /* Set version 3 */
  57911. ExpectIntNE(X509_set_version(x509, 2L), 0);
  57912. /* Set subject name, add pubkey, and sign certificate */
  57913. ExpectIntEQ(X509_set_subject_name(x509, name), SSL_SUCCESS);
  57914. X509_NAME_free(name);
  57915. name = NULL;
  57916. ExpectIntEQ(X509_set_pubkey(x509, pub), SSL_SUCCESS);
  57917. #ifdef WOLFSSL_ALT_NAMES
  57918. /* Add some subject alt names */
  57919. ExpectIntNE(wolfSSL_X509_add_altname(NULL,
  57920. "ipsum", ASN_DNS_TYPE), SSL_SUCCESS);
  57921. ExpectIntEQ(wolfSSL_X509_add_altname(x509,
  57922. NULL, ASN_DNS_TYPE), SSL_SUCCESS);
  57923. ExpectIntEQ(wolfSSL_X509_add_altname(x509,
  57924. "sphygmomanometer",
  57925. ASN_DNS_TYPE), SSL_SUCCESS);
  57926. ExpectIntEQ(wolfSSL_X509_add_altname(x509,
  57927. "supercalifragilisticexpialidocious",
  57928. ASN_DNS_TYPE), SSL_SUCCESS);
  57929. ExpectIntEQ(wolfSSL_X509_add_altname(x509,
  57930. "Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch",
  57931. ASN_DNS_TYPE), SSL_SUCCESS);
  57932. #ifdef WOLFSSL_IP_ALT_NAME
  57933. {
  57934. unsigned char ip4_type[] = {127,128,0,255};
  57935. unsigned char ip6_type[] = {0xdd, 0xcc, 0xba, 0xab,
  57936. 0xff, 0xee, 0x99, 0x88,
  57937. 0x77, 0x66, 0x55, 0x44,
  57938. 0x00, 0x33, 0x22, 0x11};
  57939. ExpectIntEQ(wolfSSL_X509_add_altname_ex(x509, (char*)ip4_type,
  57940. sizeof(ip4_type), ASN_IP_TYPE), SSL_SUCCESS);
  57941. ExpectIntEQ(wolfSSL_X509_add_altname_ex(x509, (char*)ip6_type,
  57942. sizeof(ip6_type), ASN_IP_TYPE), SSL_SUCCESS);
  57943. }
  57944. #endif
  57945. #endif /* WOLFSSL_ALT_NAMES */
  57946. {
  57947. ASN1_UTCTIME* infinite_past = NULL;
  57948. ExpectNotNull(infinite_past = ASN1_UTCTIME_set(NULL, 0));
  57949. ExpectIntEQ(X509_set1_notBefore(x509, infinite_past), 1);
  57950. ASN1_UTCTIME_free(infinite_past);
  57951. }
  57952. /* test valid sign case */
  57953. ExpectIntGT(ret = X509_sign(x509, priv, EVP_sha256()), 0);
  57954. /* test valid X509_sign_ctx case */
  57955. ExpectNotNull(mctx = EVP_MD_CTX_new());
  57956. ExpectIntEQ(EVP_DigestSignInit(mctx, NULL, EVP_sha256(), NULL, priv), 1);
  57957. ExpectIntGT(X509_sign_ctx(x509, mctx), 0);
  57958. #if defined(OPENSSL_ALL) && defined(WOLFSSL_ALT_NAMES)
  57959. ExpectIntEQ(X509_get_ext_count(x509), 1);
  57960. #endif
  57961. #if defined(WOLFSSL_ALT_NAMES) && defined(WOLFSSL_IP_ALT_NAME)
  57962. ExpectIntEQ(wolfSSL_X509_check_ip_asc(x509, "127.128.0.255", 0), 1);
  57963. ExpectIntEQ(wolfSSL_X509_check_ip_asc(x509, "DDCC:BAAB:FFEE:9988:7766:5544:0033:2211", 0), 1);
  57964. #endif
  57965. ExpectIntEQ(wolfSSL_X509_get_serial_number(x509, sn, &snSz),
  57966. WOLFSSL_SUCCESS);
  57967. DEBUG_WRITE_CERT_X509(x509, "signed.pem");
  57968. /* Variation in size depends on ASN.1 encoding when MSB is set.
  57969. * WOLFSSL_ASN_TEMPLATE code does not generate a serial number
  57970. * with the MSB set. See GenerateInteger in asn.c */
  57971. #ifndef USE_CERT_BUFFERS_1024
  57972. #ifndef WOLFSSL_ALT_NAMES
  57973. /* Valid case - size should be 781-786 with 16 byte serial number */
  57974. ExpectTrue((781 + snSz <= ret) && (ret <= 781 + 5 + snSz));
  57975. #elif defined(WOLFSSL_IP_ALT_NAME)
  57976. /* Valid case - size should be 955-960 with 16 byte serial number */
  57977. ExpectTrue((939 + snSz <= ret) && (ret <= 939 + 5 + snSz));
  57978. #else
  57979. /* Valid case - size should be 926-931 with 16 byte serial number */
  57980. ExpectTrue((910 + snSz <= ret) && (ret <= 910 + 5 + snSz));
  57981. #endif
  57982. #else
  57983. #ifndef WOLFSSL_ALT_NAMES
  57984. /* Valid case - size should be 537-542 with 16 byte serial number */
  57985. ExpectTrue((521 + snSz <= ret) && (ret <= 521 + 5 + snSz));
  57986. #elif defined(OPENSSL_ALL) || defined(WOLFSSL_IP_ALT_NAME)
  57987. /* Valid case - size should be 695-670 with 16 byte serial number */
  57988. ExpectTrue((679 + snSz <= ret) && (ret <= 679 + 5 + snSz));
  57989. #else
  57990. /* Valid case - size should be 666-671 with 16 byte serial number */
  57991. ExpectTrue((650 + snSz <= ret) && (ret <= 650 + 5 + snSz));
  57992. #endif
  57993. #endif
  57994. /* check that issuer name is as expected after signature */
  57995. InitDecodedCert(&dCert, certIssuer, (word32)certIssuerSz, 0);
  57996. ExpectIntEQ(ParseCert(&dCert, CERT_TYPE, NO_VERIFY, NULL), 0);
  57997. ExpectNotNull(ca = d2i_X509(NULL, &certIssuer, (int)certIssuerSz));
  57998. ExpectNotNull(name = X509_get_subject_name(ca));
  57999. cnSz = X509_NAME_get_sz(name);
  58000. ExpectNotNull(cn = (char*)XMALLOC(cnSz, HEAP_HINT, DYNAMIC_TYPE_OPENSSL));
  58001. ExpectNotNull(cn = X509_NAME_oneline(name, cn, (int)cnSz));
  58002. ExpectIntEQ(0, XSTRNCMP(cn, dCert.subject, XSTRLEN(cn)));
  58003. XFREE(cn, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  58004. cn = NULL;
  58005. #ifdef WOLFSSL_MULTI_ATTRIB
  58006. /* test adding multiple OU's to the signer */
  58007. ExpectNotNull(name = X509_get_subject_name(ca));
  58008. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "OU", MBSTRING_UTF8,
  58009. (byte*)"OU1", 3, -1, 0), SSL_SUCCESS);
  58010. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "OU", MBSTRING_UTF8,
  58011. (byte*)"OU2", 3, -1, 0), SSL_SUCCESS);
  58012. ExpectIntGT(X509_sign(ca, priv, EVP_sha256()), 0);
  58013. #endif
  58014. ExpectNotNull(name = X509_get_subject_name(ca));
  58015. ExpectIntEQ(X509_set_issuer_name(x509, name), SSL_SUCCESS);
  58016. ExpectIntGT(X509_sign(x509, priv, EVP_sha256()), 0);
  58017. ExpectNotNull(name = X509_get_issuer_name(x509));
  58018. cnSz = X509_NAME_get_sz(name);
  58019. ExpectNotNull(cn = (char*)XMALLOC(cnSz, HEAP_HINT, DYNAMIC_TYPE_OPENSSL));
  58020. ExpectNotNull(cn = X509_NAME_oneline(name, cn, (int)cnSz));
  58021. /* compare and don't include the multi-attrib "/OU=OU1/OU=OU2" above */
  58022. ExpectIntEQ(0, XSTRNCMP(cn, dCert.issuer, XSTRLEN(dCert.issuer)));
  58023. XFREE(cn, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  58024. cn = NULL;
  58025. FreeDecodedCert(&dCert);
  58026. /* Test invalid parameters */
  58027. ExpectIntEQ(X509_sign(NULL, priv, EVP_sha256()), 0);
  58028. ExpectIntEQ(X509_sign(x509, NULL, EVP_sha256()), 0);
  58029. ExpectIntEQ(X509_sign(x509, priv, NULL), 0);
  58030. ExpectIntEQ(X509_sign_ctx(NULL, mctx), 0);
  58031. EVP_MD_CTX_free(mctx);
  58032. mctx = NULL;
  58033. ExpectNotNull(mctx = EVP_MD_CTX_new());
  58034. ExpectIntEQ(X509_sign_ctx(x509, mctx), 0);
  58035. ExpectIntEQ(X509_sign_ctx(x509, NULL), 0);
  58036. /* test invalid version number */
  58037. #if defined(OPENSSL_ALL)
  58038. ExpectIntNE(X509_set_version(x509, 6L), 0);
  58039. ExpectIntGT(X509_sign(x509, priv, EVP_sha256()), 0);
  58040. /* uses ParseCert which fails on bad version number */
  58041. ExpectIntEQ(X509_get_ext_count(x509), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  58042. #endif
  58043. EVP_MD_CTX_free(mctx);
  58044. EVP_PKEY_free(priv);
  58045. EVP_PKEY_free(pub);
  58046. X509_free(x509);
  58047. X509_free(ca);
  58048. #endif
  58049. return EXPECT_RESULT();
  58050. }
  58051. static int test_wolfSSL_X509_get0_tbs_sigalg(void)
  58052. {
  58053. EXPECT_DECLS;
  58054. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD))
  58055. X509* x509 = NULL;
  58056. const X509_ALGOR* alg;
  58057. ExpectNotNull(x509 = X509_new());
  58058. ExpectNull(alg = X509_get0_tbs_sigalg(NULL));
  58059. ExpectNotNull(alg = X509_get0_tbs_sigalg(x509));
  58060. X509_free(x509);
  58061. #endif
  58062. return EXPECT_RESULT();
  58063. }
  58064. static int test_wolfSSL_X509_ALGOR_get0(void)
  58065. {
  58066. EXPECT_DECLS;
  58067. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && \
  58068. !defined(NO_SHA256) && !defined(NO_RSA)
  58069. X509* x509 = NULL;
  58070. const ASN1_OBJECT* obj = NULL;
  58071. const X509_ALGOR* alg = NULL;
  58072. X509_ALGOR* alg2 = NULL;
  58073. int pptype = 0;
  58074. const void *ppval = NULL;
  58075. byte* der = NULL;
  58076. const byte* tmp = NULL;
  58077. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  58078. SSL_FILETYPE_PEM));
  58079. ExpectNotNull(alg = X509_get0_tbs_sigalg(x509));
  58080. /* Invalid case */
  58081. X509_ALGOR_get0(&obj, NULL, NULL, NULL);
  58082. ExpectNull(obj);
  58083. /* Valid case */
  58084. X509_ALGOR_get0(&obj, &pptype, &ppval, alg);
  58085. ExpectNotNull(obj);
  58086. ExpectNull(ppval);
  58087. ExpectIntNE(pptype, 0);
  58088. /* Make sure NID of X509_ALGOR is Sha256 with RSA */
  58089. ExpectIntEQ(OBJ_obj2nid(obj), NID_sha256WithRSAEncryption);
  58090. ExpectIntEQ(i2d_X509_ALGOR(alg, &der), 15);
  58091. tmp = der;
  58092. ExpectNotNull(d2i_X509_ALGOR(&alg2, &tmp, 15));
  58093. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  58094. X509_free(x509);
  58095. X509_ALGOR_free(alg2);
  58096. #endif
  58097. return EXPECT_RESULT();
  58098. }
  58099. static int test_wolfSSL_X509_VERIFY_PARAM(void)
  58100. {
  58101. EXPECT_DECLS;
  58102. #if defined(OPENSSL_EXTRA)
  58103. X509_VERIFY_PARAM *paramTo = NULL;
  58104. X509_VERIFY_PARAM *paramFrom = NULL;
  58105. char testIPv4[] = "127.0.0.1";
  58106. char testIPv6[] = "0001:0000:0000:0000:0000:0000:0000:0000/32";
  58107. char testhostName1[] = "foo.hoge.com";
  58108. char testhostName2[] = "foobar.hoge.com";
  58109. ExpectNotNull(paramTo = X509_VERIFY_PARAM_new());
  58110. ExpectNotNull(XMEMSET(paramTo, 0, sizeof(X509_VERIFY_PARAM)));
  58111. ExpectNotNull(paramFrom = X509_VERIFY_PARAM_new());
  58112. ExpectNotNull(XMEMSET(paramFrom, 0, sizeof(X509_VERIFY_PARAM)));
  58113. ExpectIntEQ(X509_VERIFY_PARAM_set1_host(paramFrom, testhostName1,
  58114. (int)XSTRLEN(testhostName1)), 1);
  58115. ExpectIntEQ(0, XSTRNCMP(paramFrom->hostName, testhostName1,
  58116. (int)XSTRLEN(testhostName1)));
  58117. X509_VERIFY_PARAM_set_hostflags(NULL, 0x00);
  58118. X509_VERIFY_PARAM_set_hostflags(paramFrom, 0x01);
  58119. ExpectIntEQ(0x01, paramFrom->hostFlags);
  58120. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(NULL, testIPv4), 0);
  58121. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramFrom, testIPv4), 1);
  58122. ExpectIntEQ(0, XSTRNCMP(paramFrom->ipasc, testIPv4, WOLFSSL_MAX_IPSTR));
  58123. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramFrom, NULL), 1);
  58124. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramFrom, testIPv6), 1);
  58125. ExpectIntEQ(0, XSTRNCMP(paramFrom->ipasc, testIPv6, WOLFSSL_MAX_IPSTR));
  58126. /* null pointer */
  58127. ExpectIntEQ(X509_VERIFY_PARAM_set1(NULL, paramFrom), 0);
  58128. /* in the case of "from" null, returns success */
  58129. ExpectIntEQ(X509_VERIFY_PARAM_set1(paramTo, NULL), 1);
  58130. ExpectIntEQ(X509_VERIFY_PARAM_set1(NULL, NULL), 0);
  58131. /* inherit flags test : VPARAM_DEFAULT */
  58132. ExpectIntEQ(X509_VERIFY_PARAM_set1(paramTo, paramFrom), 1);
  58133. ExpectIntEQ(0, XSTRNCMP(paramTo->hostName, testhostName1,
  58134. (int)XSTRLEN(testhostName1)));
  58135. ExpectIntEQ(0x01, paramTo->hostFlags);
  58136. ExpectIntEQ(0, XSTRNCMP(paramTo->ipasc, testIPv6, WOLFSSL_MAX_IPSTR));
  58137. /* inherit flags test : VPARAM OVERWRITE */
  58138. ExpectIntEQ(X509_VERIFY_PARAM_set1_host(paramTo, testhostName2,
  58139. (int)XSTRLEN(testhostName2)), 1);
  58140. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramTo, testIPv4), 1);
  58141. X509_VERIFY_PARAM_set_hostflags(paramTo, 0x00);
  58142. if (paramTo != NULL) {
  58143. paramTo->inherit_flags = X509_VP_FLAG_OVERWRITE;
  58144. }
  58145. ExpectIntEQ(X509_VERIFY_PARAM_set1(paramTo, paramFrom), 1);
  58146. ExpectIntEQ(0, XSTRNCMP(paramTo->hostName, testhostName1,
  58147. (int)XSTRLEN(testhostName1)));
  58148. ExpectIntEQ(0x01, paramTo->hostFlags);
  58149. ExpectIntEQ(0, XSTRNCMP(paramTo->ipasc, testIPv6, WOLFSSL_MAX_IPSTR));
  58150. /* inherit flags test : VPARAM_RESET_FLAGS */
  58151. ExpectIntEQ(X509_VERIFY_PARAM_set1_host(paramTo, testhostName2,
  58152. (int)XSTRLEN(testhostName2)), 1);
  58153. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramTo, testIPv4), 1);
  58154. X509_VERIFY_PARAM_set_hostflags(paramTo, 0x10);
  58155. if (paramTo != NULL) {
  58156. paramTo->inherit_flags = X509_VP_FLAG_RESET_FLAGS;
  58157. }
  58158. ExpectIntEQ(X509_VERIFY_PARAM_set1(paramTo, paramFrom), 1);
  58159. ExpectIntEQ(0, XSTRNCMP(paramTo->hostName, testhostName1,
  58160. (int)XSTRLEN(testhostName1)));
  58161. ExpectIntEQ(0x01, paramTo->hostFlags);
  58162. ExpectIntEQ(0, XSTRNCMP(paramTo->ipasc, testIPv6, WOLFSSL_MAX_IPSTR));
  58163. /* inherit flags test : VPARAM_LOCKED */
  58164. ExpectIntEQ(X509_VERIFY_PARAM_set1_host(paramTo, testhostName2,
  58165. (int)XSTRLEN(testhostName2)), 1);
  58166. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramTo, testIPv4), 1);
  58167. X509_VERIFY_PARAM_set_hostflags(paramTo, 0x00);
  58168. if (paramTo != NULL) {
  58169. paramTo->inherit_flags = X509_VP_FLAG_LOCKED;
  58170. }
  58171. ExpectIntEQ(X509_VERIFY_PARAM_set1(paramTo, paramFrom), 1);
  58172. ExpectIntEQ(0, XSTRNCMP(paramTo->hostName, testhostName2,
  58173. (int)XSTRLEN(testhostName2)));
  58174. ExpectIntEQ(0x00, paramTo->hostFlags);
  58175. ExpectIntEQ(0, XSTRNCMP(paramTo->ipasc, testIPv4, WOLFSSL_MAX_IPSTR));
  58176. /* test for incorrect parameters */
  58177. ExpectIntEQ(X509_VERIFY_PARAM_set_flags(NULL, X509_V_FLAG_CRL_CHECK_ALL),
  58178. 0);
  58179. ExpectIntEQ(X509_VERIFY_PARAM_set_flags(NULL, 0), 0);
  58180. /* inherit flags test : VPARAM_ONCE, not testable yet */
  58181. ExpectIntEQ(X509_VERIFY_PARAM_set_flags(paramTo, X509_V_FLAG_CRL_CHECK_ALL),
  58182. 1);
  58183. ExpectIntEQ(X509_VERIFY_PARAM_get_flags(paramTo),
  58184. X509_V_FLAG_CRL_CHECK_ALL);
  58185. ExpectIntEQ(X509_VERIFY_PARAM_clear_flags(paramTo,
  58186. X509_V_FLAG_CRL_CHECK_ALL), 1);
  58187. ExpectIntEQ(X509_VERIFY_PARAM_get_flags(paramTo), 0);
  58188. X509_VERIFY_PARAM_free(paramTo);
  58189. X509_VERIFY_PARAM_free(paramFrom);
  58190. X509_VERIFY_PARAM_free(NULL); /* to confirm NULL parameter gives no harm */
  58191. #endif
  58192. return EXPECT_RESULT();
  58193. }
  58194. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  58195. !defined(WOLFSSL_HOSTNAME_VERIFY_ALT_NAME_ONLY)
  58196. static int test_wolfSSL_check_domain_verify_count = 0;
  58197. static WC_INLINE int test_wolfSSL_check_domain_verify_cb(int preverify,
  58198. WOLFSSL_X509_STORE_CTX* store)
  58199. {
  58200. EXPECT_DECLS;
  58201. ExpectIntEQ(X509_STORE_CTX_get_error(store), 0);
  58202. ExpectIntEQ(preverify, 1);
  58203. ExpectIntGT(++test_wolfSSL_check_domain_verify_count, 0);
  58204. return EXPECT_SUCCESS();
  58205. }
  58206. static int test_wolfSSL_check_domain_client_cb(WOLFSSL* ssl)
  58207. {
  58208. EXPECT_DECLS;
  58209. X509_VERIFY_PARAM *param = NULL;
  58210. ExpectNotNull(param = SSL_get0_param(ssl));
  58211. /* Domain check should only be done on the leaf cert */
  58212. X509_VERIFY_PARAM_set_hostflags(param,
  58213. X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS);
  58214. ExpectIntEQ(X509_VERIFY_PARAM_set1_host(param,
  58215. "wolfSSL Server Chain", 0), 1);
  58216. wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_PEER,
  58217. test_wolfSSL_check_domain_verify_cb);
  58218. return EXPECT_RESULT();
  58219. }
  58220. static int test_wolfSSL_check_domain_server_cb(WOLFSSL_CTX* ctx)
  58221. {
  58222. EXPECT_DECLS;
  58223. /* Use a cert with different domains in chain */
  58224. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file(ctx,
  58225. "certs/intermediate/server-chain.pem"), WOLFSSL_SUCCESS);
  58226. return EXPECT_RESULT();
  58227. }
  58228. static int test_wolfSSL_check_domain(void)
  58229. {
  58230. EXPECT_DECLS;
  58231. test_ssl_cbf func_cb_client;
  58232. test_ssl_cbf func_cb_server;
  58233. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  58234. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  58235. func_cb_client.ssl_ready = &test_wolfSSL_check_domain_client_cb;
  58236. func_cb_server.ctx_ready = &test_wolfSSL_check_domain_server_cb;
  58237. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  58238. &func_cb_server, NULL), TEST_SUCCESS);
  58239. /* Should have been called once for each cert in sent chain */
  58240. #ifdef WOLFSSL_VERIFY_CB_ALL_CERTS
  58241. ExpectIntEQ(test_wolfSSL_check_domain_verify_count, 3);
  58242. #else
  58243. ExpectIntEQ(test_wolfSSL_check_domain_verify_count, 1);
  58244. #endif
  58245. return EXPECT_RESULT();
  58246. }
  58247. #else
  58248. static int test_wolfSSL_check_domain(void)
  58249. {
  58250. EXPECT_DECLS;
  58251. return EXPECT_RESULT();
  58252. }
  58253. #endif /* OPENSSL_EXTRA && HAVE_SSL_MEMIO_TESTS_DEPENDENCIES */
  58254. static int test_wolfSSL_X509_get_X509_PUBKEY(void)
  58255. {
  58256. EXPECT_DECLS;
  58257. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD))
  58258. X509* x509 = NULL;
  58259. X509_PUBKEY* pubKey;
  58260. ExpectNotNull(x509 = X509_new());
  58261. ExpectNull(pubKey = wolfSSL_X509_get_X509_PUBKEY(NULL));
  58262. ExpectNotNull(pubKey = wolfSSL_X509_get_X509_PUBKEY(x509));
  58263. X509_free(x509);
  58264. #endif
  58265. return EXPECT_RESULT();
  58266. }
  58267. static int test_wolfSSL_X509_PUBKEY_RSA(void)
  58268. {
  58269. EXPECT_DECLS;
  58270. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && \
  58271. !defined(NO_SHA256) && !defined(NO_RSA)
  58272. X509* x509 = NULL;
  58273. ASN1_OBJECT* obj = NULL;
  58274. const ASN1_OBJECT* pa_oid = NULL;
  58275. X509_PUBKEY* pubKey = NULL;
  58276. X509_PUBKEY* pubKey2 = NULL;
  58277. EVP_PKEY* evpKey = NULL;
  58278. const unsigned char *pk = NULL;
  58279. int ppklen;
  58280. int pptype;
  58281. X509_ALGOR *pa = NULL;
  58282. const void *pval;
  58283. ExpectNotNull(x509 = X509_load_certificate_file(cliCertFile,
  58284. SSL_FILETYPE_PEM));
  58285. ExpectNotNull(pubKey = X509_get_X509_PUBKEY(x509));
  58286. ExpectIntEQ(X509_PUBKEY_get0_param(&obj, &pk, &ppklen, &pa, pubKey), 1);
  58287. ExpectNotNull(pk);
  58288. ExpectNotNull(pa);
  58289. ExpectNotNull(pubKey);
  58290. ExpectIntGT(ppklen, 0);
  58291. ExpectIntEQ(OBJ_obj2nid(obj), NID_rsaEncryption);
  58292. ExpectNotNull(evpKey = X509_PUBKEY_get(pubKey));
  58293. ExpectNotNull(pubKey2 = X509_PUBKEY_new());
  58294. ExpectIntEQ(X509_PUBKEY_set(&pubKey2, evpKey), 1);
  58295. ExpectIntEQ(X509_PUBKEY_get0_param(&obj, &pk, &ppklen, &pa, pubKey2), 1);
  58296. ExpectNotNull(pk);
  58297. ExpectNotNull(pa);
  58298. ExpectIntGT(ppklen, 0);
  58299. X509_ALGOR_get0(&pa_oid, &pptype, &pval, pa);
  58300. ExpectNotNull(pa_oid);
  58301. ExpectNull(pval);
  58302. ExpectIntEQ(pptype, V_ASN1_NULL);
  58303. ExpectIntEQ(OBJ_obj2nid(pa_oid), EVP_PKEY_RSA);
  58304. X509_PUBKEY_free(pubKey2);
  58305. X509_free(x509);
  58306. EVP_PKEY_free(evpKey);
  58307. #endif
  58308. return EXPECT_RESULT();
  58309. }
  58310. static int test_wolfSSL_X509_PUBKEY_EC(void)
  58311. {
  58312. EXPECT_DECLS;
  58313. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && defined(HAVE_ECC)
  58314. X509* x509 = NULL;
  58315. ASN1_OBJECT* obj = NULL;
  58316. ASN1_OBJECT* poid = NULL;
  58317. const ASN1_OBJECT* pa_oid = NULL;
  58318. X509_PUBKEY* pubKey = NULL;
  58319. X509_PUBKEY* pubKey2 = NULL;
  58320. EVP_PKEY* evpKey = NULL;
  58321. const unsigned char *pk = NULL;
  58322. int ppklen;
  58323. int pptype;
  58324. X509_ALGOR *pa = NULL;
  58325. const void *pval;
  58326. char buf[50];
  58327. ExpectNotNull(x509 = X509_load_certificate_file(cliEccCertFile,
  58328. SSL_FILETYPE_PEM));
  58329. ExpectNotNull(pubKey = X509_get_X509_PUBKEY(x509));
  58330. ExpectNotNull(evpKey = X509_PUBKEY_get(pubKey));
  58331. ExpectNotNull(pubKey2 = X509_PUBKEY_new());
  58332. ExpectIntEQ(X509_PUBKEY_set(&pubKey2, evpKey), 1);
  58333. ExpectIntEQ(X509_PUBKEY_get0_param(&obj, &pk, &ppklen, &pa, pubKey2), 1);
  58334. ExpectNotNull(pk);
  58335. ExpectNotNull(pa);
  58336. ExpectIntGT(ppklen, 0);
  58337. X509_ALGOR_get0(&pa_oid, &pptype, &pval, pa);
  58338. ExpectNotNull(pa_oid);
  58339. ExpectNotNull(pval);
  58340. ExpectIntEQ(pptype, V_ASN1_OBJECT);
  58341. ExpectIntEQ(OBJ_obj2nid(pa_oid), EVP_PKEY_EC);
  58342. poid = (ASN1_OBJECT *)pval;
  58343. ExpectIntGT(OBJ_obj2txt(buf, (int)sizeof(buf), poid, 0), 0);
  58344. ExpectIntEQ(OBJ_txt2nid(buf), NID_X9_62_prime256v1);
  58345. X509_PUBKEY_free(pubKey2);
  58346. X509_free(x509);
  58347. EVP_PKEY_free(evpKey);
  58348. #endif
  58349. return EXPECT_RESULT();
  58350. }
  58351. static int test_wolfSSL_X509_PUBKEY_DSA(void)
  58352. {
  58353. EXPECT_DECLS;
  58354. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && !defined(NO_DSA)
  58355. word32 bytes;
  58356. #ifdef USE_CERT_BUFFERS_1024
  58357. byte tmp[ONEK_BUF];
  58358. #elif defined(USE_CERT_BUFFERS_2048)
  58359. byte tmp[TWOK_BUF];
  58360. #else
  58361. byte tmp[TWOK_BUF];
  58362. #endif /* END USE_CERT_BUFFERS_1024 */
  58363. const unsigned char* dsaKeyDer = tmp;
  58364. ASN1_OBJECT* obj = NULL;
  58365. ASN1_STRING* str;
  58366. const ASN1_OBJECT* pa_oid = NULL;
  58367. X509_PUBKEY* pubKey = NULL;
  58368. EVP_PKEY* evpKey = NULL;
  58369. const unsigned char *pk = NULL;
  58370. int ppklen, pptype;
  58371. X509_ALGOR *pa = NULL;
  58372. const void *pval;
  58373. #ifdef USE_CERT_BUFFERS_1024
  58374. XMEMSET(tmp, 0, sizeof(tmp));
  58375. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  58376. bytes = sizeof_dsa_key_der_1024;
  58377. #elif defined(USE_CERT_BUFFERS_2048)
  58378. XMEMSET(tmp, 0, sizeof(tmp));
  58379. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  58380. bytes = sizeof_dsa_key_der_2048;
  58381. #else
  58382. {
  58383. XFILE fp = XBADFILE;
  58384. XMEMSET(tmp, 0, sizeof(tmp));
  58385. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb")) != XBADFILE);
  58386. ExpectIntGT(bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), fp), 0);
  58387. if (fp != XBADFILE)
  58388. XFCLOSE(fp);
  58389. }
  58390. #endif
  58391. /* Initialize pkey with der format dsa key */
  58392. ExpectNotNull(d2i_PrivateKey(EVP_PKEY_DSA, &evpKey, &dsaKeyDer, bytes));
  58393. ExpectNotNull(pubKey = X509_PUBKEY_new());
  58394. ExpectIntEQ(X509_PUBKEY_set(&pubKey, evpKey), 1);
  58395. ExpectIntEQ(X509_PUBKEY_get0_param(&obj, &pk, &ppklen, &pa, pubKey), 1);
  58396. ExpectNotNull(pk);
  58397. ExpectNotNull(pa);
  58398. ExpectIntGT(ppklen, 0);
  58399. X509_ALGOR_get0(&pa_oid, &pptype, &pval, pa);
  58400. ExpectNotNull(pa_oid);
  58401. ExpectNotNull(pval);
  58402. ExpectIntEQ(pptype, V_ASN1_SEQUENCE);
  58403. ExpectIntEQ(OBJ_obj2nid(pa_oid), EVP_PKEY_DSA);
  58404. str = (ASN1_STRING *)pval;
  58405. DEBUG_WRITE_DER(ASN1_STRING_data(str), ASN1_STRING_length(str), "str.der");
  58406. #ifdef USE_CERT_BUFFERS_1024
  58407. ExpectIntEQ(ASN1_STRING_length(str), 291);
  58408. #else
  58409. ExpectIntEQ(ASN1_STRING_length(str), 549);
  58410. #endif /* END USE_CERT_BUFFERS_1024 */
  58411. X509_PUBKEY_free(pubKey);
  58412. EVP_PKEY_free(evpKey);
  58413. #endif
  58414. return EXPECT_RESULT();
  58415. }
  58416. static int test_wolfSSL_BUF(void)
  58417. {
  58418. EXPECT_DECLS;
  58419. #if defined(OPENSSL_EXTRA)
  58420. BUF_MEM* buf = NULL;
  58421. ExpectNotNull(buf = BUF_MEM_new());
  58422. ExpectIntEQ(BUF_MEM_grow(buf, 10), 10);
  58423. ExpectIntEQ(BUF_MEM_grow(buf, -1), 0);
  58424. BUF_MEM_free(buf);
  58425. #endif
  58426. return EXPECT_RESULT();
  58427. }
  58428. #if defined(OPENSSL_EXTRA) && !defined(WOLFSSL_NO_OPENSSL_RAND_CB)
  58429. static int stub_rand_seed(const void *buf, int num)
  58430. {
  58431. (void)buf;
  58432. (void)num;
  58433. return 123;
  58434. }
  58435. static int stub_rand_bytes(unsigned char *buf, int num)
  58436. {
  58437. (void)buf;
  58438. (void)num;
  58439. return 456;
  58440. }
  58441. static byte* was_stub_rand_cleanup_called(void)
  58442. {
  58443. static byte was_called = 0;
  58444. return &was_called;
  58445. }
  58446. static void stub_rand_cleanup(void)
  58447. {
  58448. byte* was_called = was_stub_rand_cleanup_called();
  58449. *was_called = 1;
  58450. return;
  58451. }
  58452. static byte* was_stub_rand_add_called(void)
  58453. {
  58454. static byte was_called = 0;
  58455. return &was_called;
  58456. }
  58457. static int stub_rand_add(const void *buf, int num, double entropy)
  58458. {
  58459. byte* was_called = was_stub_rand_add_called();
  58460. (void)buf;
  58461. (void)num;
  58462. (void)entropy;
  58463. *was_called = 1;
  58464. return 0;
  58465. }
  58466. static int stub_rand_pseudo_bytes(unsigned char *buf, int num)
  58467. {
  58468. (void)buf;
  58469. (void)num;
  58470. return 9876;
  58471. }
  58472. static int stub_rand_status(void)
  58473. {
  58474. return 5432;
  58475. }
  58476. #endif /* OPENSSL_EXTRA && !WOLFSSL_NO_OPENSSL_RAND_CB */
  58477. static int test_wolfSSL_RAND_set_rand_method(void)
  58478. {
  58479. EXPECT_DECLS;
  58480. #if defined(OPENSSL_EXTRA) && !defined(WOLFSSL_NO_OPENSSL_RAND_CB)
  58481. RAND_METHOD rand_methods = {NULL, NULL, NULL, NULL, NULL, NULL};
  58482. unsigned char* buf = NULL;
  58483. int num = 0;
  58484. double entropy = 0;
  58485. int ret;
  58486. byte* was_cleanup_called = was_stub_rand_cleanup_called();
  58487. byte* was_add_called = was_stub_rand_add_called();
  58488. ExpectNotNull(buf = (byte*)XMALLOC(32 * sizeof(byte), NULL,
  58489. DYNAMIC_TYPE_TMP_BUFFER));
  58490. ExpectIntNE(wolfSSL_RAND_status(), 5432);
  58491. ExpectIntEQ(*was_cleanup_called, 0);
  58492. RAND_cleanup();
  58493. ExpectIntEQ(*was_cleanup_called, 0);
  58494. rand_methods.seed = &stub_rand_seed;
  58495. rand_methods.bytes = &stub_rand_bytes;
  58496. rand_methods.cleanup = &stub_rand_cleanup;
  58497. rand_methods.add = &stub_rand_add;
  58498. rand_methods.pseudorand = &stub_rand_pseudo_bytes;
  58499. rand_methods.status = &stub_rand_status;
  58500. ExpectIntEQ(RAND_set_rand_method(&rand_methods), WOLFSSL_SUCCESS);
  58501. ExpectIntEQ(RAND_seed(buf, num), 123);
  58502. ExpectIntEQ(RAND_bytes(buf, num), 456);
  58503. ExpectIntEQ(RAND_pseudo_bytes(buf, num), 9876);
  58504. ExpectIntEQ(RAND_status(), 5432);
  58505. ExpectIntEQ(*was_add_called, 0);
  58506. /* The function pointer for RAND_add returns int, but RAND_add itself
  58507. * returns void. */
  58508. RAND_add(buf, num, entropy);
  58509. ExpectIntEQ(*was_add_called, 1);
  58510. was_add_called = 0;
  58511. ExpectIntEQ(*was_cleanup_called, 0);
  58512. RAND_cleanup();
  58513. ExpectIntEQ(*was_cleanup_called, 1);
  58514. *was_cleanup_called = 0;
  58515. ret = RAND_set_rand_method(NULL);
  58516. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  58517. ExpectIntNE(RAND_status(), 5432);
  58518. ExpectIntEQ(*was_cleanup_called, 0);
  58519. RAND_cleanup();
  58520. ExpectIntEQ(*was_cleanup_called, 0);
  58521. RAND_set_rand_method(NULL);
  58522. XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  58523. #endif /* OPENSSL_EXTRA && !WOLFSSL_NO_OPENSSL_RAND_CB */
  58524. return EXPECT_RESULT();
  58525. }
  58526. static int test_wolfSSL_RAND_bytes(void)
  58527. {
  58528. EXPECT_DECLS;
  58529. #if defined(OPENSSL_EXTRA)
  58530. const int size1 = RNG_MAX_BLOCK_LEN; /* in bytes */
  58531. const int size2 = RNG_MAX_BLOCK_LEN + 1; /* in bytes */
  58532. const int size3 = RNG_MAX_BLOCK_LEN * 2; /* in bytes */
  58533. const int size4 = RNG_MAX_BLOCK_LEN * 4; /* in bytes */
  58534. int max_bufsize;
  58535. byte *my_buf = NULL;
  58536. /* sanity check */
  58537. ExpectIntEQ(RAND_bytes(NULL, 16), 0);
  58538. ExpectIntEQ(RAND_bytes(NULL, 0), 0);
  58539. max_bufsize = size4;
  58540. ExpectNotNull(my_buf = (byte*)XMALLOC(max_bufsize * sizeof(byte), NULL,
  58541. DYNAMIC_TYPE_TMP_BUFFER));
  58542. ExpectIntEQ(RAND_bytes(my_buf, 0), 1);
  58543. ExpectIntEQ(RAND_bytes(my_buf, -1), 0);
  58544. ExpectNotNull(XMEMSET(my_buf, 0, max_bufsize));
  58545. ExpectIntEQ(RAND_bytes(my_buf, size1), 1);
  58546. ExpectIntEQ(RAND_bytes(my_buf, size2), 1);
  58547. ExpectIntEQ(RAND_bytes(my_buf, size3), 1);
  58548. ExpectIntEQ(RAND_bytes(my_buf, size4), 1);
  58549. XFREE(my_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  58550. #endif
  58551. return EXPECT_RESULT();
  58552. }
  58553. static int test_wolfSSL_RAND(void)
  58554. {
  58555. EXPECT_DECLS;
  58556. #if defined(OPENSSL_EXTRA)
  58557. byte seed[16];
  58558. XMEMSET(seed, 0, sizeof(seed));
  58559. /* No global methods set. */
  58560. ExpectIntEQ(RAND_seed(seed, sizeof(seed)), 1);
  58561. ExpectIntEQ(RAND_poll(), 1);
  58562. RAND_cleanup();
  58563. ExpectIntEQ(RAND_egd(NULL), -1);
  58564. #ifndef NO_FILESYSTEM
  58565. {
  58566. char fname[100];
  58567. ExpectNotNull(RAND_file_name(fname, (sizeof(fname) - 1)));
  58568. ExpectIntEQ(RAND_write_file(NULL), 0);
  58569. }
  58570. #endif
  58571. #endif
  58572. return EXPECT_RESULT();
  58573. }
  58574. static int test_wolfSSL_PKCS8_Compat(void)
  58575. {
  58576. EXPECT_DECLS;
  58577. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && defined(HAVE_ECC) && \
  58578. !defined(NO_BIO)
  58579. PKCS8_PRIV_KEY_INFO* pt = NULL;
  58580. BIO* bio = NULL;
  58581. XFILE f = XBADFILE;
  58582. int bytes;
  58583. char pkcs8_buffer[512];
  58584. #if defined(OPENSSL_ALL) || defined(WOLFSSL_WPAS_SMALL)
  58585. EVP_PKEY *pkey = NULL;
  58586. #endif
  58587. /* file from wolfssl/certs/ directory */
  58588. ExpectTrue((f = XFOPEN("./certs/ecc-keyPkcs8.pem", "rb")) != XBADFILE);
  58589. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer), f)),
  58590. 0);
  58591. if (f != XBADFILE)
  58592. XFCLOSE(f);
  58593. ExpectNotNull(bio = BIO_new_mem_buf((void*)pkcs8_buffer, bytes));
  58594. ExpectNotNull(pt = d2i_PKCS8_PRIV_KEY_INFO_bio(bio, NULL));
  58595. #if defined(OPENSSL_ALL) || defined(WOLFSSL_WPAS_SMALL)
  58596. ExpectNotNull(pkey = EVP_PKCS82PKEY(pt));
  58597. ExpectIntEQ(EVP_PKEY_type(pkey->type), EVP_PKEY_EC);
  58598. /* gets PKCS8 pointer to pkey */
  58599. ExpectNotNull(EVP_PKEY2PKCS8(pkey));
  58600. EVP_PKEY_free(pkey);
  58601. #endif
  58602. BIO_free(bio);
  58603. PKCS8_PRIV_KEY_INFO_free(pt);
  58604. #endif
  58605. return EXPECT_RESULT();
  58606. }
  58607. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  58608. static int NoPasswordCallBack(char* passwd, int sz, int rw, void* userdata)
  58609. {
  58610. (void)passwd;
  58611. (void)sz;
  58612. (void)rw;
  58613. (void)userdata;
  58614. return -1;
  58615. }
  58616. #endif
  58617. static int test_wolfSSL_PKCS8_d2i(void)
  58618. {
  58619. EXPECT_DECLS;
  58620. #if !defined(HAVE_FIPS) && defined(OPENSSL_EXTRA)
  58621. /* This test ends up using HMAC as a part of PBKDF2, and HMAC
  58622. * requires a 12 byte password in FIPS mode. This test ends up
  58623. * trying to use an 8 byte password. */
  58624. #ifndef NO_FILESYSTEM
  58625. unsigned char pkcs8_buffer[2048];
  58626. const unsigned char* p = NULL;
  58627. int bytes = 0;
  58628. XFILE file = XBADFILE;
  58629. WOLFSSL_EVP_PKEY* pkey = NULL;
  58630. #ifndef NO_BIO
  58631. BIO* bio = NULL;
  58632. #if defined(OPENSSL_ALL) && \
  58633. ((!defined(NO_RSA) && !defined(NO_DES3)) || \
  58634. defined(HAVE_ECC)) && \
  58635. !defined(NO_BIO) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  58636. WOLFSSL_EVP_PKEY* evpPkey = NULL;
  58637. #endif
  58638. #endif
  58639. #ifndef NO_RSA
  58640. const char rsaDerPkcs8File[] = "./certs/server-keyPkcs8.der";
  58641. const char rsaPemPkcs8File[] = "./certs/server-keyPkcs8.pem";
  58642. #ifndef NO_DES3
  58643. const char rsaDerPkcs8EncFile[] = "./certs/server-keyPkcs8Enc.der";
  58644. #endif
  58645. #endif /* NO_RSA */
  58646. #ifdef HAVE_ECC
  58647. const char ecDerPkcs8File[] = "certs/ecc-keyPkcs8.der";
  58648. const char ecPemPkcs8File[] = "certs/ecc-keyPkcs8.pem";
  58649. #ifndef NO_DES3
  58650. const char ecDerPkcs8EncFile[] = "certs/ecc-keyPkcs8Enc.der";
  58651. #endif
  58652. #endif /* HAVE_ECC */
  58653. #endif /* !NO_FILESYSTEM */
  58654. #if defined(OPENSSL_ALL) && (!defined(NO_RSA) || defined(HAVE_ECC))
  58655. #ifndef NO_RSA
  58656. #ifdef USE_CERT_BUFFERS_1024
  58657. const unsigned char* rsa = (unsigned char*)server_key_der_1024;
  58658. int rsaSz = sizeof_server_key_der_1024;
  58659. #else
  58660. const unsigned char* rsa = (unsigned char*)server_key_der_2048;
  58661. int rsaSz = sizeof_server_key_der_2048;
  58662. #endif
  58663. #endif
  58664. #ifdef HAVE_ECC
  58665. const unsigned char* ec = (unsigned char*)ecc_key_der_256;
  58666. int ecSz = sizeof_ecc_key_der_256;
  58667. #endif
  58668. #endif /* OPENSSL_ALL && (!NO_RSA || HAVE_ECC) */
  58669. #ifndef NO_FILESYSTEM
  58670. (void)pkcs8_buffer;
  58671. (void)p;
  58672. (void)bytes;
  58673. (void)file;
  58674. #ifndef NO_BIO
  58675. (void)bio;
  58676. #endif
  58677. #endif
  58678. #ifdef OPENSSL_ALL
  58679. #ifndef NO_RSA
  58680. /* Try to auto-detect normal RSA private key */
  58681. ExpectNotNull(pkey = d2i_AutoPrivateKey(NULL, &rsa, rsaSz));
  58682. EVP_PKEY_free(pkey);
  58683. pkey = NULL;
  58684. #endif
  58685. #ifdef HAVE_ECC
  58686. /* Try to auto-detect normal EC private key */
  58687. ExpectNotNull(pkey = d2i_AutoPrivateKey(NULL, &ec, ecSz));
  58688. EVP_PKEY_free(pkey);
  58689. pkey = NULL;
  58690. #endif
  58691. #endif /* OPENSSL_ALL */
  58692. #ifndef NO_FILESYSTEM
  58693. #if defined(OPENSSL_ALL) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  58694. ExpectIntEQ(PEM_write_PKCS8PrivateKey(XBADFILE, pkey, NULL, NULL, 0, NULL,
  58695. NULL), 0);
  58696. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, NULL, NULL, NULL, 0, NULL,
  58697. NULL), 0);
  58698. #endif
  58699. #ifndef NO_RSA
  58700. /* Get DER encoded RSA PKCS#8 data. */
  58701. ExpectTrue((file = XFOPEN(rsaDerPkcs8File, "rb")) != XBADFILE);
  58702. ExpectNotNull(XMEMSET(pkcs8_buffer, 0, sizeof(pkcs8_buffer)));
  58703. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  58704. file)), 0);
  58705. if (file != XBADFILE) {
  58706. XFCLOSE(file);
  58707. file = XBADFILE;
  58708. }
  58709. p = pkcs8_buffer;
  58710. #ifdef OPENSSL_ALL
  58711. /* Try to decode - auto-detect key type. */
  58712. ExpectNotNull(pkey = d2i_AutoPrivateKey(NULL, &p, bytes));
  58713. #else
  58714. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_RSA, NULL, &p, bytes));
  58715. #endif
  58716. /* Get PEM encoded RSA PKCS#8 data. */
  58717. ExpectTrue((file = XFOPEN(rsaPemPkcs8File, "rb")) != XBADFILE);
  58718. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  58719. file)), 0);
  58720. if (file != XBADFILE) {
  58721. XFCLOSE(file);
  58722. file = XBADFILE;
  58723. }
  58724. #if defined(OPENSSL_ALL) && \
  58725. !defined(NO_BIO) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  58726. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  58727. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(NULL, pkey, NULL, NULL, 0, NULL,
  58728. NULL), 0);
  58729. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, NULL, NULL, NULL, 0, NULL,
  58730. NULL), 0);
  58731. /* Write PKCS#8 PEM to BIO. */
  58732. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, NULL, NULL, 0, NULL,
  58733. NULL), bytes);
  58734. /* Write PKCS#8 PEM to stderr. */
  58735. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, NULL, NULL, 0, NULL,
  58736. NULL), bytes);
  58737. /* Compare file and written data */
  58738. ExpectIntEQ(BIO_get_mem_data(bio, &p), bytes);
  58739. ExpectIntEQ(XMEMCMP(p, pkcs8_buffer, bytes), 0);
  58740. BIO_free(bio);
  58741. bio = NULL;
  58742. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  58743. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, EVP_aes_128_gcm(),
  58744. NULL, 0, PasswordCallBack, (void*)"yassl123"), 0);
  58745. #endif
  58746. #if !defined(NO_DES3) && !defined(NO_SHA)
  58747. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  58748. /* Write Encrypted PKCS#8 PEM to BIO. */
  58749. bytes = 1834;
  58750. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, EVP_des_ede3_cbc(),
  58751. NULL, 0, PasswordCallBack, (void*)"yassl123"), bytes);
  58752. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, EVP_des_ede3_cbc(),
  58753. NULL, 0, PasswordCallBack, (void*)"yassl123"), bytes);
  58754. ExpectNotNull(evpPkey = PEM_read_bio_PrivateKey(bio, NULL, PasswordCallBack,
  58755. (void*)"yassl123"));
  58756. EVP_PKEY_free(evpPkey);
  58757. evpPkey = NULL;
  58758. BIO_free(bio);
  58759. bio = NULL;
  58760. #endif /* !NO_DES3 && !NO_SHA */
  58761. #endif /* !NO_BIO && !NO_PWDBASED && HAVE_PKCS8 */
  58762. EVP_PKEY_free(pkey);
  58763. pkey = NULL;
  58764. /* PKCS#8 encrypted RSA key */
  58765. #ifndef NO_DES3
  58766. ExpectTrue((file = XFOPEN(rsaDerPkcs8EncFile, "rb")) != XBADFILE);
  58767. ExpectNotNull(XMEMSET(pkcs8_buffer, 0, sizeof(pkcs8_buffer)));
  58768. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  58769. file)), 0);
  58770. if (file != XBADFILE) {
  58771. XFCLOSE(file);
  58772. file = XBADFILE;
  58773. }
  58774. #if defined(OPENSSL_ALL) && \
  58775. !defined(NO_BIO) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  58776. ExpectNotNull(bio = BIO_new_mem_buf((void*)pkcs8_buffer, bytes));
  58777. ExpectNotNull(pkey = d2i_PKCS8PrivateKey_bio(bio, NULL, PasswordCallBack,
  58778. (void*)"yassl123"));
  58779. EVP_PKEY_free(pkey);
  58780. pkey = NULL;
  58781. BIO_free(bio);
  58782. bio = NULL;
  58783. #endif /* OPENSSL_ALL && !NO_BIO && !NO_PWDBASED && HAVE_PKCS8 */
  58784. #endif /* !NO_DES3 */
  58785. #endif /* NO_RSA */
  58786. #ifdef HAVE_ECC
  58787. /* PKCS#8 encode EC key */
  58788. ExpectTrue((file = XFOPEN(ecDerPkcs8File, "rb")) != XBADFILE);
  58789. ExpectNotNull(XMEMSET(pkcs8_buffer, 0, sizeof(pkcs8_buffer)));
  58790. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  58791. file)), 0);
  58792. if (file != XBADFILE) {
  58793. XFCLOSE(file);
  58794. file = XBADFILE;
  58795. }
  58796. p = pkcs8_buffer;
  58797. #ifdef OPENSSL_ALL
  58798. /* Try to decode - auto-detect key type. */
  58799. ExpectNotNull(pkey = d2i_AutoPrivateKey(NULL, &p, bytes));
  58800. #else
  58801. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &p, bytes));
  58802. #endif
  58803. /* Get PEM encoded RSA PKCS#8 data. */
  58804. ExpectTrue((file = XFOPEN(ecPemPkcs8File, "rb")) != XBADFILE);
  58805. ExpectNotNull(XMEMSET(pkcs8_buffer, 0, sizeof(pkcs8_buffer)));
  58806. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  58807. file)), 0);
  58808. if (file != XBADFILE) {
  58809. XFCLOSE(file);
  58810. file = XBADFILE;
  58811. }
  58812. #if defined(OPENSSL_ALL) && \
  58813. !defined(NO_BIO) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8) && \
  58814. defined(HAVE_AES_CBC)
  58815. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  58816. /* Write PKCS#8 PEM to BIO. */
  58817. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, NULL, NULL, 0, NULL,
  58818. NULL), bytes);
  58819. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, NULL, NULL, 0, NULL,
  58820. NULL), bytes);
  58821. /* Compare file and written data */
  58822. ExpectIntEQ(BIO_get_mem_data(bio, &p), bytes);
  58823. ExpectIntEQ(XMEMCMP(p, pkcs8_buffer, bytes), 0);
  58824. BIO_free(bio);
  58825. bio = NULL;
  58826. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  58827. /* Write Encrypted PKCS#8 PEM to BIO. */
  58828. bytes = 379;
  58829. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, EVP_aes_256_cbc(),
  58830. NULL, 0, NoPasswordCallBack, (void*)"yassl123"), 0);
  58831. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, EVP_aes_256_cbc(),
  58832. NULL, 0, PasswordCallBack, (void*)"yassl123"), bytes);
  58833. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, EVP_aes_128_cbc(),
  58834. NULL, 0, PasswordCallBack, (void*)"yassl123"), bytes);
  58835. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, EVP_aes_128_cbc(),
  58836. (char*)"yassl123", 8, PasswordCallBack, NULL), bytes);
  58837. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, EVP_aes_256_cbc(),
  58838. NULL, 0, PasswordCallBack, (void*)"yassl123"), bytes);
  58839. ExpectNotNull(evpPkey = PEM_read_bio_PrivateKey(bio, NULL, PasswordCallBack,
  58840. (void*)"yassl123"));
  58841. EVP_PKEY_free(evpPkey);
  58842. evpPkey = NULL;
  58843. BIO_free(bio);
  58844. bio = NULL;
  58845. #endif /* OPENSSL_ALL && !NO_BIO && !NO_PWDBASED && HAVE_PKCS8 && HAVE_AES_CBC */
  58846. EVP_PKEY_free(pkey);
  58847. pkey = NULL;
  58848. /* PKCS#8 encrypted EC key */
  58849. #ifndef NO_DES3
  58850. ExpectTrue((file = XFOPEN(ecDerPkcs8EncFile, "rb")) != XBADFILE);
  58851. ExpectNotNull(XMEMSET(pkcs8_buffer, 0, sizeof(pkcs8_buffer)));
  58852. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  58853. file)), 0);
  58854. if (file != XBADFILE) {
  58855. XFCLOSE(file);
  58856. file = XBADFILE;
  58857. }
  58858. #if defined(OPENSSL_ALL) && \
  58859. !defined(NO_BIO) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  58860. ExpectNotNull(bio = BIO_new_mem_buf((void*)pkcs8_buffer, bytes));
  58861. ExpectNotNull(pkey = d2i_PKCS8PrivateKey_bio(bio, NULL, PasswordCallBack,
  58862. (void*)"yassl123"));
  58863. EVP_PKEY_free(pkey);
  58864. pkey = NULL;
  58865. BIO_free(bio);
  58866. bio = NULL;
  58867. #endif /* OPENSSL_ALL && !NO_BIO && !NO_PWDBASED && HAVE_PKCS8 */
  58868. #endif /* !NO_DES3 */
  58869. #endif /* HAVE_ECC */
  58870. #endif /* !NO_FILESYSTEM */
  58871. #endif /* HAVE_FIPS && OPENSSL_EXTRA */
  58872. return EXPECT_RESULT();
  58873. }
  58874. #if !defined(SINGLE_THREADED) && defined(ERROR_QUEUE_PER_THREAD) && \
  58875. !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  58876. defined(DEBUG_WOLFSSL)
  58877. #define LOGGING_THREADS 5
  58878. #define ERROR_COUNT 10
  58879. /* copied from logging.c since this is not exposed otherwise */
  58880. #ifndef ERROR_QUEUE_MAX
  58881. #ifdef ERROR_QUEUE_PER_THREAD
  58882. #define ERROR_QUEUE_MAX 16
  58883. #else
  58884. /* this breaks from compat of unlimited error queue size */
  58885. #define ERROR_QUEUE_MAX 100
  58886. #endif
  58887. #endif
  58888. static volatile int loggingThreadsReady;
  58889. static THREAD_RETURN WOLFSSL_THREAD test_logging(void* args)
  58890. {
  58891. const char* file;
  58892. int line;
  58893. unsigned long err;
  58894. int errorCount = 0;
  58895. int i;
  58896. (void)args;
  58897. while (!loggingThreadsReady);
  58898. for (i = 0; i < ERROR_COUNT; i++)
  58899. ERR_put_error(ERR_LIB_PEM, SYS_F_ACCEPT, -990 - i, __FILE__, __LINE__);
  58900. while ((err = ERR_get_error_line(&file, &line))) {
  58901. AssertIntEQ(err, 990 + errorCount);
  58902. errorCount++;
  58903. }
  58904. AssertIntEQ(errorCount, ERROR_COUNT);
  58905. /* test max queue behavior, trying to add an arbitrary 3 errors over */
  58906. ERR_clear_error(); /* ERR_get_error_line() does not remove */
  58907. errorCount = 0;
  58908. for (i = 0; i < ERROR_QUEUE_MAX + 3; i++)
  58909. ERR_put_error(ERR_LIB_PEM, SYS_F_ACCEPT, -990 - i, __FILE__, __LINE__);
  58910. while ((err = ERR_get_error_line(&file, &line))) {
  58911. AssertIntEQ(err, 990 + errorCount);
  58912. errorCount++;
  58913. }
  58914. /* test that the 3 errors over the max were dropped */
  58915. AssertIntEQ(errorCount, ERROR_QUEUE_MAX);
  58916. WOLFSSL_RETURN_FROM_THREAD(0);
  58917. }
  58918. #endif
  58919. static int test_error_queue_per_thread(void)
  58920. {
  58921. int res = TEST_SKIPPED;
  58922. #if !defined(SINGLE_THREADED) && defined(ERROR_QUEUE_PER_THREAD) && \
  58923. !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  58924. defined(DEBUG_WOLFSSL)
  58925. THREAD_TYPE loggingThreads[LOGGING_THREADS];
  58926. int i;
  58927. ERR_clear_error(); /* clear out any error nodes */
  58928. loggingThreadsReady = 0;
  58929. for (i = 0; i < LOGGING_THREADS; i++)
  58930. start_thread(test_logging, NULL, &loggingThreads[i]);
  58931. loggingThreadsReady = 1;
  58932. for (i = 0; i < LOGGING_THREADS; i++)
  58933. join_thread(loggingThreads[i]);
  58934. res = TEST_SUCCESS;
  58935. #endif
  58936. return res;
  58937. }
  58938. static int test_wolfSSL_ERR_put_error(void)
  58939. {
  58940. EXPECT_DECLS;
  58941. #if !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  58942. defined(DEBUG_WOLFSSL)
  58943. const char* file;
  58944. int line;
  58945. ERR_clear_error(); /* clear out any error nodes */
  58946. ERR_put_error(0,SYS_F_ACCEPT, 0, "this file", 0);
  58947. ExpectIntEQ(ERR_get_error_line(&file, &line), 0);
  58948. ERR_put_error(0,SYS_F_BIND, 1, "this file", 1);
  58949. ExpectIntEQ(ERR_get_error_line(&file, &line), 1);
  58950. ERR_put_error(0,SYS_F_CONNECT, 2, "this file", 2);
  58951. ExpectIntEQ(ERR_get_error_line(&file, &line), 2);
  58952. ERR_put_error(0,SYS_F_FOPEN, 3, "this file", 3);
  58953. ExpectIntEQ(ERR_get_error_line(&file, &line), 3);
  58954. ERR_put_error(0,SYS_F_FREAD, 4, "this file", 4);
  58955. ExpectIntEQ(ERR_get_error_line(&file, &line), 4);
  58956. ERR_put_error(0,SYS_F_GETADDRINFO, 5, "this file", 5);
  58957. ExpectIntEQ(ERR_get_error_line(&file, &line), 5);
  58958. ERR_put_error(0,SYS_F_GETSOCKOPT, 6, "this file", 6);
  58959. ExpectIntEQ(ERR_get_error_line(&file, &line), 6);
  58960. ERR_put_error(0,SYS_F_GETSOCKNAME, 7, "this file", 7);
  58961. ExpectIntEQ(ERR_get_error_line(&file, &line), 7);
  58962. ERR_put_error(0,SYS_F_GETHOSTBYNAME, 8, "this file", 8);
  58963. ExpectIntEQ(ERR_get_error_line(&file, &line), 8);
  58964. ERR_put_error(0,SYS_F_GETNAMEINFO, 9, "this file", 9);
  58965. ExpectIntEQ(ERR_get_error_line(&file, &line), 9);
  58966. ERR_put_error(0,SYS_F_GETSERVBYNAME, 10, "this file", 10);
  58967. ExpectIntEQ(ERR_get_error_line(&file, &line), 10);
  58968. ERR_put_error(0,SYS_F_IOCTLSOCKET, 11, "this file", 11);
  58969. ExpectIntEQ(ERR_get_error_line(&file, &line), 11);
  58970. ERR_put_error(0,SYS_F_LISTEN, 12, "this file", 12);
  58971. ExpectIntEQ(ERR_get_error_line(&file, &line), 12);
  58972. ERR_put_error(0,SYS_F_OPENDIR, 13, "this file", 13);
  58973. ExpectIntEQ(ERR_get_error_line(&file, &line), 13);
  58974. ERR_put_error(0,SYS_F_SETSOCKOPT, 14, "this file", 14);
  58975. ExpectIntEQ(ERR_get_error_line(&file, &line), 14);
  58976. ERR_put_error(0,SYS_F_SOCKET, 15, "this file", 15);
  58977. ExpectIntEQ(ERR_get_error_line(&file, &line), 15);
  58978. #if defined(OPENSSL_ALL) && defined(WOLFSSL_PYTHON)
  58979. ERR_put_error(ERR_LIB_ASN1, SYS_F_ACCEPT, ASN1_R_HEADER_TOO_LONG,
  58980. "this file", 100);
  58981. ExpectIntEQ(wolfSSL_ERR_peek_last_error_line(&file, &line),
  58982. (ERR_LIB_ASN1 << 24) | ASN1_R_HEADER_TOO_LONG);
  58983. ExpectIntEQ(line, 100);
  58984. ExpectIntEQ(wolfSSL_ERR_peek_error(),
  58985. (ERR_LIB_ASN1 << 24) | ASN1_R_HEADER_TOO_LONG);
  58986. ExpectIntEQ(ERR_get_error_line(&file, &line), ASN1_R_HEADER_TOO_LONG);
  58987. #endif
  58988. /* try reading past end of error queue */
  58989. file = NULL;
  58990. ExpectIntEQ(ERR_get_error_line(&file, &line), 0);
  58991. ExpectNull(file);
  58992. ExpectIntEQ(ERR_get_error_line_data(&file, &line, NULL, NULL), 0);
  58993. PEMerr(4,4);
  58994. ExpectIntEQ(ERR_get_error(), 4);
  58995. /* Empty and free up all error nodes */
  58996. ERR_clear_error();
  58997. /* Verify all nodes are cleared */
  58998. ERR_put_error(0,SYS_F_ACCEPT, 0, "this file", 0);
  58999. ERR_clear_error();
  59000. ExpectIntEQ(ERR_get_error_line(&file, &line), 0);
  59001. #endif
  59002. return EXPECT_RESULT();
  59003. }
  59004. /*
  59005. * This is a regression test for a bug where the peek/get error functions were
  59006. * drawing from the end of the queue rather than the front.
  59007. */
  59008. static int test_wolfSSL_ERR_get_error_order(void)
  59009. {
  59010. EXPECT_DECLS;
  59011. #if defined(WOLFSSL_HAVE_ERROR_QUEUE) && defined(OPENSSL_EXTRA)
  59012. /* Empty the queue. */
  59013. wolfSSL_ERR_clear_error();
  59014. wolfSSL_ERR_put_error(0, 0, WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), "test", 0);
  59015. wolfSSL_ERR_put_error(0, 0, WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E), "test", 0);
  59016. ExpectIntEQ(wolfSSL_ERR_peek_error(), -WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  59017. ExpectIntEQ(wolfSSL_ERR_get_error(), -WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  59018. ExpectIntEQ(wolfSSL_ERR_peek_error(), -WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E));
  59019. ExpectIntEQ(wolfSSL_ERR_get_error(), -WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E));
  59020. #endif /* WOLFSSL_HAVE_ERROR_QUEUE && OPENSSL_EXTRA */
  59021. return EXPECT_RESULT();
  59022. }
  59023. #ifndef NO_BIO
  59024. static int test_wolfSSL_ERR_print_errors(void)
  59025. {
  59026. EXPECT_DECLS;
  59027. #if !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  59028. defined(DEBUG_WOLFSSL) && !defined(NO_ERROR_STRINGS)
  59029. BIO* bio = NULL;
  59030. char buf[1024];
  59031. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  59032. ERR_clear_error(); /* clear out any error nodes */
  59033. ERR_put_error(0,SYS_F_ACCEPT, -173, "ssl.c", 0);
  59034. /* Choosing -600 as an unused errno. */
  59035. ERR_put_error(0,SYS_F_BIND, -600, "asn.c", 100);
  59036. ERR_print_errors(bio);
  59037. ExpectIntEQ(BIO_gets(bio, buf, sizeof(buf)), 56);
  59038. ExpectIntEQ(XSTRNCMP(
  59039. "error:173:wolfSSL library:Bad function argument:ssl.c:0",
  59040. buf, 55), 0);
  59041. ExpectIntEQ(BIO_gets(bio, buf, sizeof(buf)), 57);
  59042. ExpectIntEQ(XSTRNCMP(
  59043. "error:600:wolfSSL library:unknown error number:asn.c:100",
  59044. buf, 56), 0);
  59045. ExpectIntEQ(BIO_gets(bio, buf, sizeof(buf)), 1);
  59046. ExpectIntEQ(buf[0], '\0');
  59047. ExpectIntEQ(ERR_get_error_line(NULL, NULL), 0);
  59048. BIO_free(bio);
  59049. #endif
  59050. return EXPECT_RESULT();
  59051. }
  59052. #if !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  59053. defined(DEBUG_WOLFSSL)
  59054. static int test_wolfSSL_error_cb(const char *str, size_t len, void *u)
  59055. {
  59056. wolfSSL_BIO_write((BIO*)u, str, (int)len);
  59057. return 0;
  59058. }
  59059. #endif
  59060. static int test_wolfSSL_ERR_print_errors_cb(void)
  59061. {
  59062. EXPECT_DECLS;
  59063. #if !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  59064. defined(DEBUG_WOLFSSL)
  59065. BIO* bio = NULL;
  59066. char buf[1024];
  59067. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  59068. ERR_clear_error(); /* clear out any error nodes */
  59069. ERR_put_error(0,SYS_F_ACCEPT, -173, "ssl.c", 0);
  59070. ERR_put_error(0,SYS_F_BIND, -275, "asn.c", 100);
  59071. ERR_print_errors_cb(test_wolfSSL_error_cb, bio);
  59072. ExpectIntEQ(BIO_gets(bio, buf, sizeof(buf)), 108);
  59073. ExpectIntEQ(XSTRNCMP(
  59074. "wolfSSL error occurred, error = 173 line:0 file:ssl.c",
  59075. buf, 53), 0);
  59076. ExpectIntEQ(XSTRNCMP(
  59077. "wolfSSL error occurred, error = 275 line:100 file:asn.c",
  59078. buf + 53, 55), 0);
  59079. ExpectIntEQ(BIO_gets(bio, buf, sizeof(buf)), 0);
  59080. BIO_free(bio);
  59081. #endif
  59082. return EXPECT_RESULT();
  59083. }
  59084. /*
  59085. * Testing WOLFSSL_ERROR_MSG
  59086. */
  59087. static int test_WOLFSSL_ERROR_MSG(void)
  59088. {
  59089. int res = TEST_SKIPPED;
  59090. #if defined(DEBUG_WOLFSSL) || defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) ||\
  59091. defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA)
  59092. const char* msg = TEST_STRING;
  59093. WOLFSSL_ERROR_MSG(msg);
  59094. res = TEST_SUCCESS;
  59095. #endif
  59096. return res;
  59097. } /* End test_WOLFSSL_ERROR_MSG */
  59098. /*
  59099. * Testing wc_ERR_remove_state
  59100. */
  59101. static int test_wc_ERR_remove_state(void)
  59102. {
  59103. int res = TEST_SKIPPED;
  59104. #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
  59105. wc_ERR_remove_state();
  59106. res = TEST_SUCCESS;
  59107. #endif
  59108. return res;
  59109. } /* End test_wc_ERR_remove_state */
  59110. /*
  59111. * Testing wc_ERR_print_errors_fp
  59112. */
  59113. static int test_wc_ERR_print_errors_fp(void)
  59114. {
  59115. EXPECT_DECLS;
  59116. #if (defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)) && \
  59117. (!defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM))
  59118. long sz;
  59119. XFILE fp = XBADFILE;
  59120. WOLFSSL_ERROR(WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59121. ExpectTrue((fp = XFOPEN("./tests/test-log-dump-to-file.txt", "ar")) !=
  59122. XBADFILE);
  59123. wc_ERR_print_errors_fp(fp);
  59124. #if defined(DEBUG_WOLFSSL)
  59125. ExpectTrue(XFSEEK(fp, 0, XSEEK_END) == 0);
  59126. #ifdef NO_ERROR_QUEUE
  59127. ExpectIntEQ(sz = XFTELL(fp), 0);
  59128. #else
  59129. ExpectIntNE(sz = XFTELL(fp), 0);
  59130. #endif
  59131. #endif
  59132. if (fp != XBADFILE)
  59133. XFCLOSE(fp);
  59134. (void)sz;
  59135. #endif
  59136. return EXPECT_RESULT();
  59137. } /* End test_wc_ERR_print_errors_fp */
  59138. #ifdef DEBUG_WOLFSSL
  59139. static void Logging_cb(const int logLevel, const char *const logMessage)
  59140. {
  59141. (void)logLevel;
  59142. (void)logMessage;
  59143. }
  59144. #endif
  59145. /*
  59146. * Testing wolfSSL_GetLoggingCb
  59147. */
  59148. static int test_wolfSSL_GetLoggingCb(void)
  59149. {
  59150. EXPECT_DECLS;
  59151. #ifdef DEBUG_WOLFSSL
  59152. /* Testing without wolfSSL_SetLoggingCb() */
  59153. ExpectNull(wolfSSL_GetLoggingCb());
  59154. /* Testing with wolfSSL_SetLoggingCb() */
  59155. ExpectIntEQ(wolfSSL_SetLoggingCb(Logging_cb), 0);
  59156. ExpectNotNull(wolfSSL_GetLoggingCb());
  59157. ExpectIntEQ(wolfSSL_SetLoggingCb(NULL), 0);
  59158. #endif
  59159. ExpectNull(wolfSSL_GetLoggingCb());
  59160. return EXPECT_RESULT();
  59161. } /* End test_wolfSSL_GetLoggingCb */
  59162. #endif /* !NO_BIO */
  59163. static int test_wolfSSL_MD4(void)
  59164. {
  59165. EXPECT_DECLS;
  59166. #if defined(OPENSSL_EXTRA) && !defined(NO_MD4)
  59167. MD4_CTX md4;
  59168. unsigned char out[16]; /* MD4_DIGEST_SIZE */
  59169. const char* msg = "12345678901234567890123456789012345678901234567890123456"
  59170. "789012345678901234567890";
  59171. const char* test = "\xe3\x3b\x4d\xdc\x9c\x38\xf2\x19\x9c\x3e\x7b\x16\x4f"
  59172. "\xcc\x05\x36";
  59173. int msgSz = (int)XSTRLEN(msg);
  59174. XMEMSET(out, 0, sizeof(out));
  59175. MD4_Init(&md4);
  59176. MD4_Update(&md4, (const void*)msg, (unsigned long)msgSz);
  59177. MD4_Final(out, &md4);
  59178. ExpectIntEQ(XMEMCMP(out, test, sizeof(out)), 0);
  59179. #endif
  59180. return EXPECT_RESULT();
  59181. }
  59182. static int test_wolfSSL_MD5(void)
  59183. {
  59184. EXPECT_DECLS;
  59185. #if defined(OPENSSL_EXTRA) && !defined(NO_MD5)
  59186. byte input1[] = "";
  59187. byte input2[] = "message digest";
  59188. byte hash[WC_MD5_DIGEST_SIZE];
  59189. unsigned char output1[] =
  59190. "\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\x09\x98\xec\xf8\x42\x7e";
  59191. unsigned char output2[] =
  59192. "\xf9\x6b\x69\x7d\x7c\xb7\x93\x8d\x52\x5a\x2f\x31\xaa\xf1\x61\xd0";
  59193. WOLFSSL_MD5_CTX md5;
  59194. XMEMSET(&md5, 0, sizeof(md5));
  59195. /* Test cases for illegal parameters */
  59196. ExpectIntEQ(MD5_Init(NULL), 0);
  59197. ExpectIntEQ(MD5_Init(&md5), 1);
  59198. ExpectIntEQ(MD5_Update(NULL, input1, 0), 0);
  59199. ExpectIntEQ(MD5_Update(NULL, NULL, 0), 0);
  59200. ExpectIntEQ(MD5_Update(&md5, NULL, 1), 0);
  59201. ExpectIntEQ(MD5_Final(NULL, &md5), 0);
  59202. ExpectIntEQ(MD5_Final(hash, NULL), 0);
  59203. ExpectIntEQ(MD5_Final(NULL, NULL), 0);
  59204. /* Init MD5 CTX */
  59205. ExpectIntEQ(wolfSSL_MD5_Init(&md5), 1);
  59206. ExpectIntEQ(wolfSSL_MD5_Update(&md5, input1, XSTRLEN((const char*)&input1)),
  59207. 1);
  59208. ExpectIntEQ(wolfSSL_MD5_Final(hash, &md5), 1);
  59209. ExpectIntEQ(XMEMCMP(&hash, output1, WC_MD5_DIGEST_SIZE), 0);
  59210. /* Init MD5 CTX */
  59211. ExpectIntEQ(wolfSSL_MD5_Init(&md5), 1);
  59212. ExpectIntEQ(wolfSSL_MD5_Update(&md5, input2,
  59213. (int)XSTRLEN((const char*)input2)), 1);
  59214. ExpectIntEQ(wolfSSL_MD5_Final(hash, &md5), 1);
  59215. ExpectIntEQ(XMEMCMP(&hash, output2, WC_MD5_DIGEST_SIZE), 0);
  59216. #if !defined(NO_OLD_NAMES) && \
  59217. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2)))
  59218. ExpectPtrNE(MD5(NULL, 1, (byte*)&hash), &hash);
  59219. ExpectPtrEq(MD5(input1, 0, (byte*)&hash), &hash);
  59220. ExpectPtrNE(MD5(input1, 1, NULL), NULL);
  59221. ExpectPtrNE(MD5(NULL, 0, NULL), NULL);
  59222. ExpectPtrEq(MD5(input1, (int)XSTRLEN((const char*)&input1), (byte*)&hash),
  59223. &hash);
  59224. ExpectIntEQ(XMEMCMP(&hash, output1, WC_MD5_DIGEST_SIZE), 0);
  59225. ExpectPtrEq(MD5(input2, (int)XSTRLEN((const char*)&input2), (byte*)&hash),
  59226. &hash);
  59227. ExpectIntEQ(XMEMCMP(&hash, output2, WC_MD5_DIGEST_SIZE), 0);
  59228. {
  59229. byte data[] = "Data to be hashed.";
  59230. XMEMSET(hash, 0, WC_MD5_DIGEST_SIZE);
  59231. ExpectNotNull(MD5(data, sizeof(data), NULL));
  59232. ExpectNotNull(MD5(data, sizeof(data), hash));
  59233. ExpectNotNull(MD5(NULL, 0, hash));
  59234. ExpectNull(MD5(NULL, sizeof(data), hash));
  59235. }
  59236. #endif
  59237. #endif
  59238. return EXPECT_RESULT();
  59239. }
  59240. static int test_wolfSSL_MD5_Transform(void)
  59241. {
  59242. EXPECT_DECLS;
  59243. #if defined(OPENSSL_EXTRA) && !defined(NO_MD5)
  59244. byte input1[] = "";
  59245. byte input2[] = "abc";
  59246. byte local[WC_MD5_BLOCK_SIZE];
  59247. word32 sLen = 0;
  59248. #ifdef BIG_ENDIAN_ORDER
  59249. unsigned char output1[] =
  59250. "\x03\x1f\x1d\xac\x6e\xa5\x8e\xd0\x1f\xab\x67\xb7\x74\x31\x77\x91";
  59251. unsigned char output2[] =
  59252. "\xef\xd3\x79\x8d\x67\x17\x25\x90\xa4\x13\x79\xc7\xe3\xa7\x7b\xbc";
  59253. #else
  59254. unsigned char output1[] =
  59255. "\xac\x1d\x1f\x03\xd0\x8e\xa5\x6e\xb7\x67\xab\x1f\x91\x77\x31\x74";
  59256. unsigned char output2[] =
  59257. "\x8d\x79\xd3\xef\x90\x25\x17\x67\xc7\x79\x13\xa4\xbc\x7b\xa7\xe3";
  59258. #endif
  59259. union {
  59260. wc_Md5 native;
  59261. MD5_CTX compat;
  59262. } md5;
  59263. XMEMSET(&md5.compat, 0, sizeof(md5.compat));
  59264. XMEMSET(&local, 0, sizeof(local));
  59265. /* sanity check */
  59266. ExpectIntEQ(MD5_Transform(NULL, NULL), 0);
  59267. ExpectIntEQ(MD5_Transform(NULL, (const byte*)&input1), 0);
  59268. ExpectIntEQ(MD5_Transform(&md5.compat, NULL), 0);
  59269. ExpectIntEQ(wc_Md5Transform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59270. ExpectIntEQ(wc_Md5Transform(NULL, (const byte*)&input1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59271. ExpectIntEQ(wc_Md5Transform(&md5.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59272. /* Init MD5 CTX */
  59273. ExpectIntEQ(wolfSSL_MD5_Init(&md5.compat), 1);
  59274. /* Do Transform*/
  59275. sLen = (word32)XSTRLEN((char*)input1);
  59276. XMEMCPY(local, input1, sLen);
  59277. ExpectIntEQ(MD5_Transform(&md5.compat, (const byte*)&local[0]), 1);
  59278. ExpectIntEQ(XMEMCMP(md5.native.digest, output1, WC_MD5_DIGEST_SIZE), 0);
  59279. /* Init MD5 CTX */
  59280. ExpectIntEQ(MD5_Init(&md5.compat), 1);
  59281. sLen = (word32)XSTRLEN((char*)input2);
  59282. XMEMSET(local, 0, WC_MD5_BLOCK_SIZE);
  59283. XMEMCPY(local, input2, sLen);
  59284. ExpectIntEQ(MD5_Transform(&md5.compat, (const byte*)&local[0]), 1);
  59285. ExpectIntEQ(XMEMCMP(md5.native.digest, output2, WC_MD5_DIGEST_SIZE), 0);
  59286. #endif
  59287. return EXPECT_RESULT();
  59288. }
  59289. static int test_wolfSSL_SHA(void)
  59290. {
  59291. EXPECT_DECLS;
  59292. #if defined(OPENSSL_EXTRA) && !defined(HAVE_SELFTEST)
  59293. #if !defined(NO_SHA) && defined(NO_OLD_SHA_NAMES) && \
  59294. (!defined(HAVE_FIPS) || \
  59295. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2))
  59296. {
  59297. const unsigned char in[] = "abc";
  59298. unsigned char expected[] = "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E"
  59299. "\x25\x71\x78\x50\xC2\x6C\x9C\xD0\xD8\x9D";
  59300. unsigned char out[WC_SHA_DIGEST_SIZE];
  59301. unsigned char* p = NULL;
  59302. WOLFSSL_SHA_CTX sha;
  59303. XMEMSET(out, 0, WC_SHA_DIGEST_SIZE);
  59304. ExpectNotNull(SHA1(in, XSTRLEN((char*)in), out));
  59305. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA_DIGEST_SIZE), 0);
  59306. /* SHA interface test */
  59307. XMEMSET(out, 0, WC_SHA_DIGEST_SIZE);
  59308. ExpectNull(SHA(NULL, XSTRLEN((char*)in), out));
  59309. ExpectNotNull(SHA(in, 0, out));
  59310. ExpectNotNull(SHA(in, XSTRLEN((char*)in), NULL));
  59311. ExpectNotNull(SHA(NULL, 0, out));
  59312. ExpectNotNull(SHA(NULL, 0, NULL));
  59313. ExpectNotNull(SHA(in, XSTRLEN((char*)in), out));
  59314. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA_DIGEST_SIZE), 0);
  59315. ExpectNotNull(p = SHA(in, XSTRLEN((char*)in), NULL));
  59316. ExpectIntEQ(XMEMCMP(p, expected, WC_SHA_DIGEST_SIZE), 0);
  59317. ExpectIntEQ(wolfSSL_SHA_Init(&sha), 1);
  59318. ExpectIntEQ(wolfSSL_SHA_Update(&sha, in, XSTRLEN((char*)in)), 1);
  59319. ExpectIntEQ(wolfSSL_SHA_Final(out, &sha), 1);
  59320. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA_DIGEST_SIZE), 0);
  59321. ExpectIntEQ(wolfSSL_SHA1_Init(&sha), 1);
  59322. ExpectIntEQ(wolfSSL_SHA1_Update(&sha, in, XSTRLEN((char*)in)), 1);
  59323. ExpectIntEQ(wolfSSL_SHA1_Final(out, &sha), 1);
  59324. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA_DIGEST_SIZE), 0);
  59325. }
  59326. #endif
  59327. #if !defined(NO_SHA256)
  59328. {
  59329. const unsigned char in[] = "abc";
  59330. unsigned char expected[] =
  59331. "\xBA\x78\x16\xBF\x8F\x01\xCF\xEA\x41\x41\x40\xDE\x5D\xAE\x22"
  59332. "\x23\xB0\x03\x61\xA3\x96\x17\x7A\x9C\xB4\x10\xFF\x61\xF2\x00"
  59333. "\x15\xAD";
  59334. unsigned char out[WC_SHA256_DIGEST_SIZE];
  59335. unsigned char* p = NULL;
  59336. XMEMSET(out, 0, WC_SHA256_DIGEST_SIZE);
  59337. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  59338. ExpectNotNull(SHA256(in, XSTRLEN((char*)in), out));
  59339. #else
  59340. ExpectNotNull(wolfSSL_SHA256(in, XSTRLEN((char*)in), out));
  59341. #endif
  59342. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA256_DIGEST_SIZE), 0);
  59343. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  59344. ExpectNotNull(p = SHA256(in, XSTRLEN((char*)in), NULL));
  59345. #else
  59346. ExpectNotNull(p = wolfSSL_SHA256(in, XSTRLEN((char*)in), NULL));
  59347. #endif
  59348. ExpectIntEQ(XMEMCMP(p, expected, WC_SHA256_DIGEST_SIZE), 0);
  59349. }
  59350. #endif
  59351. #if defined(WOLFSSL_SHA384)
  59352. {
  59353. const unsigned char in[] = "abc";
  59354. unsigned char expected[] =
  59355. "\xcb\x00\x75\x3f\x45\xa3\x5e\x8b\xb5\xa0\x3d\x69\x9a\xc6\x50"
  59356. "\x07\x27\x2c\x32\xab\x0e\xde\xd1\x63\x1a\x8b\x60\x5a\x43\xff"
  59357. "\x5b\xed\x80\x86\x07\x2b\xa1\xe7\xcc\x23\x58\xba\xec\xa1\x34"
  59358. "\xc8\x25\xa7";
  59359. unsigned char out[WC_SHA384_DIGEST_SIZE];
  59360. unsigned char* p = NULL;
  59361. XMEMSET(out, 0, WC_SHA384_DIGEST_SIZE);
  59362. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  59363. ExpectNotNull(SHA384(in, XSTRLEN((char*)in), out));
  59364. #else
  59365. ExpectNotNull(wolfSSL_SHA384(in, XSTRLEN((char*)in), out));
  59366. #endif
  59367. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA384_DIGEST_SIZE), 0);
  59368. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  59369. ExpectNotNull(p = SHA384(in, XSTRLEN((char*)in), NULL));
  59370. #else
  59371. ExpectNotNull(p = wolfSSL_SHA384(in, XSTRLEN((char*)in), NULL));
  59372. #endif
  59373. ExpectIntEQ(XMEMCMP(p, expected, WC_SHA384_DIGEST_SIZE), 0);
  59374. }
  59375. #endif
  59376. #if defined(WOLFSSL_SHA512)
  59377. {
  59378. const unsigned char in[] = "abc";
  59379. unsigned char expected[] =
  59380. "\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41"
  59381. "\x31\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b\x55"
  59382. "\xd3\x9a\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c\x23\xa3"
  59383. "\xfe\xeb\xbd\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a\x9a\xc9\x4f"
  59384. "\xa5\x4c\xa4\x9f";
  59385. unsigned char out[WC_SHA512_DIGEST_SIZE];
  59386. unsigned char* p = NULL;
  59387. XMEMSET(out, 0, WC_SHA512_DIGEST_SIZE);
  59388. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  59389. ExpectNotNull(SHA512(in, XSTRLEN((char*)in), out));
  59390. #else
  59391. ExpectNotNull(wolfSSL_SHA512(in, XSTRLEN((char*)in), out));
  59392. #endif
  59393. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA512_DIGEST_SIZE), 0);
  59394. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  59395. ExpectNotNull(p = SHA512(in, XSTRLEN((char*)in), NULL));
  59396. #else
  59397. ExpectNotNull(p = wolfSSL_SHA512(in, XSTRLEN((char*)in), NULL));
  59398. #endif
  59399. ExpectIntEQ(XMEMCMP(p, expected, WC_SHA512_DIGEST_SIZE), 0);
  59400. }
  59401. #endif
  59402. #endif
  59403. return EXPECT_RESULT();
  59404. }
  59405. static int test_wolfSSL_SHA_Transform(void)
  59406. {
  59407. EXPECT_DECLS;
  59408. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA)
  59409. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  59410. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  59411. byte input1[] = "";
  59412. byte input2[] = "abc";
  59413. byte local[WC_SHA_BLOCK_SIZE];
  59414. word32 sLen = 0;
  59415. #ifdef BIG_ENDIAN_ORDER
  59416. unsigned char output1[] =
  59417. "\x92\xb4\x04\xe5\x56\x58\x8c\xed\x6c\x1a\xcd\x4e\xbf\x05\x3f\x68"
  59418. "\x09\xf7\x3a\x93";
  59419. unsigned char output2[] =
  59420. "\x97\xb2\x74\x8b\x4f\x5b\xbc\xca\x5b\xc0\xe6\xea\x2d\x40\xb4\xa0"
  59421. "\x7c\x6e\x08\xb8";
  59422. #else
  59423. unsigned char output1[] =
  59424. "\xe5\x04\xb4\x92\xed\x8c\x58\x56\x4e\xcd\x1a\x6c\x68\x3f\x05\xbf"
  59425. "\x93\x3a\xf7\x09";
  59426. unsigned char output2[] =
  59427. "\x8b\x74\xb2\x97\xca\xbc\x5b\x4f\xea\xe6\xc0\x5b\xa0\xb4\x40\x2d"
  59428. "\xb8\x08\x6e\x7c";
  59429. #endif
  59430. union {
  59431. wc_Sha native;
  59432. SHA_CTX compat;
  59433. } sha;
  59434. union {
  59435. wc_Sha native;
  59436. SHA_CTX compat;
  59437. } sha1;
  59438. XMEMSET(&sha.compat, 0, sizeof(sha.compat));
  59439. XMEMSET(&local, 0, sizeof(local));
  59440. /* sanity check */
  59441. ExpectIntEQ(SHA_Transform(NULL, NULL), 0);
  59442. ExpectIntEQ(SHA_Transform(NULL, (const byte*)&input1), 0);
  59443. ExpectIntEQ(SHA_Transform(&sha.compat, NULL), 0);
  59444. ExpectIntEQ(SHA1_Transform(NULL, NULL), 0);
  59445. ExpectIntEQ(SHA1_Transform(NULL, (const byte*)&input1), 0);
  59446. ExpectIntEQ(SHA1_Transform(&sha.compat, NULL), 0);
  59447. ExpectIntEQ(wc_ShaTransform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59448. ExpectIntEQ(wc_ShaTransform(NULL, (const byte*)&input1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59449. ExpectIntEQ(wc_ShaTransform(&sha.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59450. /* Init SHA CTX */
  59451. ExpectIntEQ(SHA_Init(&sha.compat), 1);
  59452. /* Do Transform*/
  59453. sLen = (word32)XSTRLEN((char*)input1);
  59454. XMEMCPY(local, input1, sLen);
  59455. ExpectIntEQ(SHA_Transform(&sha.compat, (const byte*)&local[0]), 1);
  59456. ExpectIntEQ(XMEMCMP(sha.native.digest, output1, WC_SHA_DIGEST_SIZE), 0);
  59457. ExpectIntEQ(SHA_Final(local, &sha.compat), 1); /* frees resources */
  59458. /* Init SHA CTX */
  59459. ExpectIntEQ(SHA_Init(&sha.compat), 1);
  59460. sLen = (word32)XSTRLEN((char*)input2);
  59461. XMEMSET(local, 0, WC_SHA_BLOCK_SIZE);
  59462. XMEMCPY(local, input2, sLen);
  59463. ExpectIntEQ(SHA_Transform(&sha.compat, (const byte*)&local[0]), 1);
  59464. ExpectIntEQ(XMEMCMP(sha.native.digest, output2, WC_SHA_DIGEST_SIZE), 0);
  59465. ExpectIntEQ(SHA_Final(local, &sha.compat), 1); /* frees resources */
  59466. /* SHA1 */
  59467. XMEMSET(local, 0, WC_SHA_BLOCK_SIZE);
  59468. /* Init SHA CTX */
  59469. ExpectIntEQ(SHA1_Init(&sha1.compat), 1);
  59470. /* Do Transform*/
  59471. sLen = (word32)XSTRLEN((char*)input1);
  59472. XMEMCPY(local, input1, sLen);
  59473. ExpectIntEQ(SHA1_Transform(&sha1.compat, (const byte*)&local[0]), 1);
  59474. ExpectIntEQ(XMEMCMP(sha1.native.digest, output1, WC_SHA_DIGEST_SIZE), 0);
  59475. ExpectIntEQ(SHA1_Final(local, &sha1.compat), 1); /* frees resources */
  59476. /* Init SHA CTX */
  59477. ExpectIntEQ(SHA1_Init(&sha1.compat), 1);
  59478. sLen = (word32)XSTRLEN((char*)input2);
  59479. XMEMSET(local, 0, WC_SHA_BLOCK_SIZE);
  59480. XMEMCPY(local, input2, sLen);
  59481. ExpectIntEQ(SHA1_Transform(&sha1.compat, (const byte*)&local[0]), 1);
  59482. ExpectIntEQ(XMEMCMP(sha1.native.digest, output2, WC_SHA_DIGEST_SIZE), 0);
  59483. ExpectIntEQ(SHA_Final(local, &sha1.compat), 1); /* frees resources */
  59484. #endif
  59485. #endif
  59486. return EXPECT_RESULT();
  59487. }
  59488. static int test_wolfSSL_SHA224(void)
  59489. {
  59490. EXPECT_DECLS;
  59491. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA224) && \
  59492. !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  59493. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2))
  59494. unsigned char input[] =
  59495. "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  59496. unsigned char output[] =
  59497. "\x75\x38\x8b\x16\x51\x27\x76\xcc\x5d\xba\x5d\xa1\xfd\x89\x01"
  59498. "\x50\xb0\xc6\x45\x5c\xb4\xf5\x8b\x19\x52\x52\x25\x25";
  59499. size_t inLen;
  59500. byte hash[WC_SHA224_DIGEST_SIZE];
  59501. unsigned char* p;
  59502. inLen = XSTRLEN((char*)input);
  59503. XMEMSET(hash, 0, WC_SHA224_DIGEST_SIZE);
  59504. ExpectNull(SHA224(NULL, inLen, hash));
  59505. ExpectNotNull(SHA224(input, 0, hash));
  59506. ExpectNotNull(SHA224(input, inLen, NULL));
  59507. ExpectNotNull(SHA224(NULL, 0, hash));
  59508. ExpectNotNull(SHA224(NULL, 0, NULL));
  59509. ExpectNotNull(SHA224(input, inLen, hash));
  59510. ExpectIntEQ(XMEMCMP(hash, output, WC_SHA224_DIGEST_SIZE), 0);
  59511. ExpectNotNull(p = SHA224(input, inLen, NULL));
  59512. ExpectIntEQ(XMEMCMP(p, output, WC_SHA224_DIGEST_SIZE), 0);
  59513. #endif
  59514. return EXPECT_RESULT();
  59515. }
  59516. static int test_wolfSSL_SHA256(void)
  59517. {
  59518. EXPECT_DECLS;
  59519. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA256) && \
  59520. defined(NO_OLD_SHA_NAMES) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  59521. unsigned char input[] =
  59522. "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  59523. unsigned char output[] =
  59524. "\x24\x8D\x6A\x61\xD2\x06\x38\xB8\xE5\xC0\x26\x93\x0C\x3E\x60"
  59525. "\x39\xA3\x3C\xE4\x59\x64\xFF\x21\x67\xF6\xEC\xED\xD4\x19\xDB"
  59526. "\x06\xC1";
  59527. size_t inLen;
  59528. byte hash[WC_SHA256_DIGEST_SIZE];
  59529. inLen = XSTRLEN((char*)input);
  59530. XMEMSET(hash, 0, WC_SHA256_DIGEST_SIZE);
  59531. ExpectNotNull(SHA256(input, inLen, hash));
  59532. ExpectIntEQ(XMEMCMP(hash, output, WC_SHA256_DIGEST_SIZE), 0);
  59533. #endif
  59534. return EXPECT_RESULT();
  59535. }
  59536. static int test_wolfSSL_SHA256_Transform(void)
  59537. {
  59538. EXPECT_DECLS;
  59539. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA256)
  59540. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  59541. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) && \
  59542. !defined(WOLFSSL_DEVCRYPTO_HASH) && !defined(WOLFSSL_AFALG_HASH) && \
  59543. !defined(WOLFSSL_KCAPI_HASH)
  59544. byte input1[] = "";
  59545. byte input2[] = "abc";
  59546. byte local[WC_SHA256_BLOCK_SIZE];
  59547. word32 sLen = 0;
  59548. #ifdef BIG_ENDIAN_ORDER
  59549. unsigned char output1[] =
  59550. "\xda\x56\x98\xbe\x17\xb9\xb4\x69\x62\x33\x57\x99\x77\x9f\xbe\xca"
  59551. "\x8c\xe5\xd4\x91\xc0\xd2\x62\x43\xba\xfe\xf9\xea\x18\x37\xa9\xd8";
  59552. unsigned char output2[] =
  59553. "\x1d\x4e\xd4\x67\x67\x7c\x61\x67\x44\x10\x76\x26\x78\x10\xff\xb8"
  59554. "\x40\xc8\x9a\x39\x73\x16\x60\x8c\xa6\x61\xd6\x05\x91\xf2\x8c\x35";
  59555. #else
  59556. unsigned char output1[] =
  59557. "\xbe\x98\x56\xda\x69\xb4\xb9\x17\x99\x57\x33\x62\xca\xbe\x9f\x77"
  59558. "\x91\xd4\xe5\x8c\x43\x62\xd2\xc0\xea\xf9\xfe\xba\xd8\xa9\x37\x18";
  59559. unsigned char output2[] =
  59560. "\x67\xd4\x4e\x1d\x67\x61\x7c\x67\x26\x76\x10\x44\xb8\xff\x10\x78"
  59561. "\x39\x9a\xc8\x40\x8c\x60\x16\x73\x05\xd6\x61\xa6\x35\x8c\xf2\x91";
  59562. #endif
  59563. union {
  59564. wc_Sha256 native;
  59565. SHA256_CTX compat;
  59566. } sha256;
  59567. XMEMSET(&sha256.compat, 0, sizeof(sha256.compat));
  59568. XMEMSET(&local, 0, sizeof(local));
  59569. /* sanity check */
  59570. ExpectIntEQ(SHA256_Transform(NULL, NULL), 0);
  59571. ExpectIntEQ(SHA256_Transform(NULL, (const byte*)&input1), 0);
  59572. ExpectIntEQ(SHA256_Transform(&sha256.compat, NULL), 0);
  59573. ExpectIntEQ(wc_Sha256Transform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59574. ExpectIntEQ(wc_Sha256Transform(NULL, (const byte*)&input1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59575. ExpectIntEQ(wc_Sha256Transform(&sha256.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59576. /* Init SHA256 CTX */
  59577. ExpectIntEQ(SHA256_Init(&sha256.compat), 1);
  59578. /* Do Transform*/
  59579. sLen = (word32)XSTRLEN((char*)input1);
  59580. XMEMCPY(local, input1, sLen);
  59581. ExpectIntEQ(SHA256_Transform(&sha256.compat, (const byte*)&local[0]), 1);
  59582. ExpectIntEQ(XMEMCMP(sha256.native.digest, output1, WC_SHA256_DIGEST_SIZE),
  59583. 0);
  59584. ExpectIntEQ(SHA256_Final(local, &sha256.compat), 1); /* frees resources */
  59585. /* Init SHA256 CTX */
  59586. ExpectIntEQ(SHA256_Init(&sha256.compat), 1);
  59587. sLen = (word32)XSTRLEN((char*)input2);
  59588. XMEMSET(local, 0, WC_SHA256_BLOCK_SIZE);
  59589. XMEMCPY(local, input2, sLen);
  59590. ExpectIntEQ(SHA256_Transform(&sha256.compat, (const byte*)&local[0]), 1);
  59591. ExpectIntEQ(XMEMCMP(sha256.native.digest, output2, WC_SHA256_DIGEST_SIZE),
  59592. 0);
  59593. ExpectIntEQ(SHA256_Final(local, &sha256.compat), 1); /* frees resources */
  59594. #endif
  59595. #endif
  59596. return EXPECT_RESULT();
  59597. }
  59598. static int test_wolfSSL_SHA512_Transform(void)
  59599. {
  59600. EXPECT_DECLS;
  59601. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA512)
  59602. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  59603. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) && \
  59604. !defined(WOLFSSL_KCAPI_HASH)
  59605. byte input1[] = "";
  59606. byte input2[] = "abc";
  59607. byte local[WC_SHA512_BLOCK_SIZE];
  59608. word32 sLen = 0;
  59609. #ifdef BIG_ENDIAN_ORDER
  59610. unsigned char output1[] =
  59611. "\xcf\x78\x81\xd5\x77\x4a\xcb\xe8\x53\x33\x62\xe0\xfb\xc7\x80\x70"
  59612. "\x02\x67\x63\x9d\x87\x46\x0e\xda\x30\x86\xcb\x40\xe8\x59\x31\xb0"
  59613. "\x71\x7d\xc9\x52\x88\xa0\x23\xa3\x96\xba\xb2\xc1\x4c\xe0\xb5\xe0"
  59614. "\x6f\xc4\xfe\x04\xea\xe3\x3e\x0b\x91\xf4\xd8\x0c\xbd\x66\x8b\xee";
  59615. unsigned char output2[] =
  59616. "\x11\x10\x93\x4e\xeb\xa0\xcc\x0d\xfd\x33\x43\x9c\xfb\x04\xc8\x21"
  59617. "\xa9\xb4\x26\x3d\xca\xab\x31\x41\xe2\xc6\xaa\xaf\xe1\x67\xd7\xab"
  59618. "\x31\x8f\x2e\x54\x2c\xba\x4e\x83\xbe\x88\xec\x9d\x8f\x2b\x38\x98"
  59619. "\x14\xd2\x4e\x9d\x53\x8b\x5e\x4d\xde\x68\x6c\x69\xaf\x20\x96\xf0";
  59620. #else
  59621. unsigned char output1[] =
  59622. "\xe8\xcb\x4a\x77\xd5\x81\x78\xcf\x70\x80\xc7\xfb\xe0\x62\x33\x53"
  59623. "\xda\x0e\x46\x87\x9d\x63\x67\x02\xb0\x31\x59\xe8\x40\xcb\x86\x30"
  59624. "\xa3\x23\xa0\x88\x52\xc9\x7d\x71\xe0\xb5\xe0\x4c\xc1\xb2\xba\x96"
  59625. "\x0b\x3e\xe3\xea\x04\xfe\xc4\x6f\xee\x8b\x66\xbd\x0c\xd8\xf4\x91";
  59626. unsigned char output2[] =
  59627. "\x0d\xcc\xa0\xeb\x4e\x93\x10\x11\x21\xc8\x04\xfb\x9c\x43\x33\xfd"
  59628. "\x41\x31\xab\xca\x3d\x26\xb4\xa9\xab\xd7\x67\xe1\xaf\xaa\xc6\xe2"
  59629. "\x83\x4e\xba\x2c\x54\x2e\x8f\x31\x98\x38\x2b\x8f\x9d\xec\x88\xbe"
  59630. "\x4d\x5e\x8b\x53\x9d\x4e\xd2\x14\xf0\x96\x20\xaf\x69\x6c\x68\xde";
  59631. #endif
  59632. union {
  59633. wc_Sha512 native;
  59634. SHA512_CTX compat;
  59635. } sha512;
  59636. XMEMSET(&sha512.compat, 0, sizeof(sha512.compat));
  59637. XMEMSET(&local, 0, sizeof(local));
  59638. /* sanity check */
  59639. ExpectIntEQ(SHA512_Transform(NULL, NULL), 0);
  59640. ExpectIntEQ(SHA512_Transform(NULL, (const byte*)&input1), 0);
  59641. ExpectIntEQ(SHA512_Transform(&sha512.compat, NULL), 0);
  59642. ExpectIntEQ(wc_Sha512Transform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59643. ExpectIntEQ(wc_Sha512Transform(NULL, (const byte*)&input1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59644. ExpectIntEQ(wc_Sha512Transform(&sha512.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59645. /* Init SHA512 CTX */
  59646. ExpectIntEQ(wolfSSL_SHA512_Init(&sha512.compat), 1);
  59647. /* Do Transform*/
  59648. sLen = (word32)XSTRLEN((char*)input1);
  59649. XMEMCPY(local, input1, sLen);
  59650. ExpectIntEQ(SHA512_Transform(&sha512.compat, (const byte*)&local[0]), 1);
  59651. ExpectIntEQ(XMEMCMP(sha512.native.digest, output1,
  59652. WC_SHA512_DIGEST_SIZE), 0);
  59653. ExpectIntEQ(SHA512_Final(local, &sha512.compat), 1); /* frees resources */
  59654. /* Init SHA512 CTX */
  59655. ExpectIntEQ(SHA512_Init(&sha512.compat), 1);
  59656. sLen = (word32)XSTRLEN((char*)input2);
  59657. XMEMSET(local, 0, WC_SHA512_BLOCK_SIZE);
  59658. XMEMCPY(local, input2, sLen);
  59659. ExpectIntEQ(SHA512_Transform(&sha512.compat, (const byte*)&local[0]), 1);
  59660. ExpectIntEQ(XMEMCMP(sha512.native.digest, output2,
  59661. WC_SHA512_DIGEST_SIZE), 0);
  59662. ExpectIntEQ(SHA512_Final(local, &sha512.compat), 1); /* frees resources */
  59663. (void)input1;
  59664. #endif
  59665. #endif
  59666. return EXPECT_RESULT();
  59667. }
  59668. static int test_wolfSSL_SHA512_224_Transform(void)
  59669. {
  59670. EXPECT_DECLS;
  59671. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA512) && \
  59672. !defined(WOLFSSL_NOSHA512_224)
  59673. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  59674. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) && \
  59675. !defined(WOLFSSL_KCAPI_HASH)
  59676. byte input1[] = "";
  59677. byte input2[] = "abc";
  59678. byte local[WC_SHA512_BLOCK_SIZE];
  59679. word32 sLen = 0;
  59680. unsigned char output1[] =
  59681. "\x94\x24\x66\xd4\x60\x3a\xeb\x23\x1d\xa8\x69\x31\x3c\xd2\xde\x11"
  59682. "\x48\x0f\x4a\x5a\xdf\x3a\x8d\x87\xcf\xcd\xbf\xa5\x03\x21\x50\xf1"
  59683. "\x8a\x0d\x0f\x0d\x3c\x07\xba\x52\xe0\xaa\x3c\xbb\xf1\xd3\x3f\xca"
  59684. "\x12\xa7\x61\xf8\x47\xda\x0d\x1b\x79\xc2\x65\x13\x92\xc1\x9c\xa5";
  59685. unsigned char output2[] =
  59686. "\x51\x28\xe7\x0b\xca\x1e\xbc\x5f\xd7\x34\x0b\x48\x30\xd7\xc2\x75"
  59687. "\x6d\x8d\x48\x2c\x1f\xc7\x9e\x2b\x20\x5e\xbb\x0f\x0e\x4d\xb7\x61"
  59688. "\x31\x76\x33\xa0\xb4\x3d\x5f\x93\xc1\x73\xac\xf7\x21\xff\x69\x17"
  59689. "\xce\x66\xe5\x1e\x31\xe7\xf3\x22\x0f\x0b\x34\xd7\x5a\x57\xeb\xbf";
  59690. union {
  59691. wc_Sha512 native;
  59692. SHA512_CTX compat;
  59693. } sha512;
  59694. #ifdef BIG_ENDIAN_ORDER
  59695. ByteReverseWords64((word64*)output1, (word64*)output1, sizeof(output1));
  59696. ByteReverseWords64((word64*)output2, (word64*)output2, sizeof(output2));
  59697. #endif
  59698. XMEMSET(&sha512.compat, 0, sizeof(sha512.compat));
  59699. XMEMSET(&local, 0, sizeof(local));
  59700. /* sanity check */
  59701. ExpectIntEQ(SHA512_224_Transform(NULL, NULL), 0);
  59702. ExpectIntEQ(SHA512_224_Transform(NULL, (const byte*)&input1), 0);
  59703. ExpectIntEQ(SHA512_224_Transform(&sha512.compat, NULL), 0);
  59704. ExpectIntEQ(wc_Sha512_224Transform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59705. ExpectIntEQ(wc_Sha512_224Transform(NULL, (const byte*)&input1),
  59706. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59707. ExpectIntEQ(wc_Sha512_224Transform(&sha512.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59708. /* Init SHA512 CTX */
  59709. ExpectIntEQ(wolfSSL_SHA512_224_Init(&sha512.compat), 1);
  59710. /* Do Transform*/
  59711. sLen = (word32)XSTRLEN((char*)input1);
  59712. XMEMCPY(local, input1, sLen);
  59713. ExpectIntEQ(SHA512_224_Transform(&sha512.compat, (const byte*)&local[0]),
  59714. 1);
  59715. ExpectIntEQ(XMEMCMP(sha512.native.digest, output1,
  59716. WC_SHA512_DIGEST_SIZE), 0);
  59717. /* frees resources */
  59718. ExpectIntEQ(SHA512_224_Final(local, &sha512.compat), 1);
  59719. /* Init SHA512 CTX */
  59720. ExpectIntEQ(SHA512_224_Init(&sha512.compat), 1);
  59721. sLen = (word32)XSTRLEN((char*)input2);
  59722. XMEMSET(local, 0, WC_SHA512_BLOCK_SIZE);
  59723. XMEMCPY(local, input2, sLen);
  59724. ExpectIntEQ(SHA512_224_Transform(&sha512.compat, (const byte*)&local[0]),
  59725. 1);
  59726. ExpectIntEQ(XMEMCMP(sha512.native.digest, output2,
  59727. WC_SHA512_DIGEST_SIZE), 0);
  59728. /* frees resources */
  59729. ExpectIntEQ(SHA512_224_Final(local, &sha512.compat), 1);
  59730. #endif
  59731. #endif
  59732. return EXPECT_RESULT();
  59733. }
  59734. static int test_wolfSSL_SHA512_256_Transform(void)
  59735. {
  59736. EXPECT_DECLS;
  59737. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA512) && \
  59738. !defined(WOLFSSL_NOSHA512_256)
  59739. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  59740. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) && \
  59741. !defined(WOLFSSL_KCAPI_HASH)
  59742. byte input1[] = "";
  59743. byte input2[] = "abc";
  59744. byte local[WC_SHA512_BLOCK_SIZE];
  59745. word32 sLen = 0;
  59746. unsigned char output1[] =
  59747. "\xf8\x37\x37\x5a\xd7\x2e\x56\xec\xe2\x51\xa8\x31\x3a\xa0\x63\x2b"
  59748. "\x7e\x7c\x64\xcc\xd9\xff\x2b\x6b\xeb\xc3\xd4\x4d\x7f\x8a\x3a\xb5"
  59749. "\x61\x85\x0b\x37\x30\x9f\x3b\x08\x5e\x7b\xd3\xbc\x6d\x00\x61\xc0"
  59750. "\x65\x9a\xd7\x73\xda\x40\xbe\xc1\xe5\x2f\xc6\x5d\xb7\x9f\xbe\x60";
  59751. unsigned char output2[] =
  59752. "\x22\xad\xc0\x30\xee\xd4\x6a\xef\x13\xee\x5a\x95\x8b\x1f\xb7\xb6"
  59753. "\xb6\xba\xc0\x44\xb8\x18\x3b\xf0\xf6\x4b\x70\x9f\x03\xba\x64\xa1"
  59754. "\xe1\xe3\x45\x15\x91\x7d\xcb\x0b\x9a\xf0\xd2\x8e\x47\x8b\x37\x78"
  59755. "\x91\x41\xa6\xc4\xb0\x29\x8f\x8b\xdd\x78\x5c\xf2\x73\x3f\x21\x31";
  59756. union {
  59757. wc_Sha512 native;
  59758. SHA512_CTX compat;
  59759. } sha512;
  59760. #ifdef BIG_ENDIAN_ORDER
  59761. ByteReverseWords64((word64*)output1, (word64*)output1, sizeof(output1));
  59762. ByteReverseWords64((word64*)output2, (word64*)output2, sizeof(output2));
  59763. #endif
  59764. XMEMSET(&sha512.compat, 0, sizeof(sha512.compat));
  59765. XMEMSET(&local, 0, sizeof(local));
  59766. /* sanity check */
  59767. ExpectIntEQ(SHA512_256_Transform(NULL, NULL), 0);
  59768. ExpectIntEQ(SHA512_256_Transform(NULL, (const byte*)&input1), 0);
  59769. ExpectIntEQ(SHA512_256_Transform(&sha512.compat, NULL), 0);
  59770. ExpectIntEQ(wc_Sha512_256Transform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59771. ExpectIntEQ(wc_Sha512_256Transform(NULL, (const byte*)&input1),
  59772. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59773. ExpectIntEQ(wc_Sha512_256Transform(&sha512.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  59774. /* Init SHA512 CTX */
  59775. ExpectIntEQ(wolfSSL_SHA512_256_Init(&sha512.compat), 1);
  59776. /* Do Transform*/
  59777. sLen = (word32)XSTRLEN((char*)input1);
  59778. XMEMCPY(local, input1, sLen);
  59779. ExpectIntEQ(SHA512_256_Transform(&sha512.compat, (const byte*)&local[0]),
  59780. 1);
  59781. ExpectIntEQ(XMEMCMP(sha512.native.digest, output1,
  59782. WC_SHA512_DIGEST_SIZE), 0);
  59783. /* frees resources */
  59784. ExpectIntEQ(SHA512_256_Final(local, &sha512.compat), 1);
  59785. /* Init SHA512 CTX */
  59786. ExpectIntEQ(SHA512_256_Init(&sha512.compat), 1);
  59787. sLen = (word32)XSTRLEN((char*)input2);
  59788. XMEMSET(local, 0, WC_SHA512_BLOCK_SIZE);
  59789. XMEMCPY(local, input2, sLen);
  59790. ExpectIntEQ(SHA512_256_Transform(&sha512.compat, (const byte*)&local[0]),
  59791. 1);
  59792. ExpectIntEQ(XMEMCMP(sha512.native.digest, output2,
  59793. WC_SHA512_DIGEST_SIZE), 0);
  59794. /* frees resources */
  59795. ExpectIntEQ(SHA512_256_Final(local, &sha512.compat), 1);
  59796. #endif
  59797. #endif
  59798. return EXPECT_RESULT();
  59799. }
  59800. #if defined(OPENSSL_EXTRA) && !defined(NO_HMAC)
  59801. /* helper function for test_wolfSSL_HMAC_CTX, digest size is expected to be a
  59802. * buffer of 64 bytes.
  59803. *
  59804. * returns the size of the digest buffer on success and a negative value on
  59805. * failure.
  59806. */
  59807. static int test_HMAC_CTX_helper(const EVP_MD* type, unsigned char* digest,
  59808. int* sz)
  59809. {
  59810. EXPECT_DECLS;
  59811. HMAC_CTX ctx1;
  59812. HMAC_CTX ctx2;
  59813. unsigned char key[] = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  59814. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  59815. unsigned char long_key[] =
  59816. "0123456789012345678901234567890123456789"
  59817. "0123456789012345678901234567890123456789"
  59818. "0123456789012345678901234567890123456789"
  59819. "0123456789012345678901234567890123456789";
  59820. unsigned char msg[] = "message to hash";
  59821. unsigned int digestSz = 64;
  59822. int keySz = sizeof(key);
  59823. int long_keySz = sizeof(long_key);
  59824. int msgSz = sizeof(msg);
  59825. unsigned char digest2[64];
  59826. unsigned int digestSz2 = 64;
  59827. HMAC_CTX_init(&ctx1);
  59828. ExpectIntEQ(HMAC_Init(&ctx1, (const void*)key, keySz, type), SSL_SUCCESS);
  59829. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59830. ExpectIntEQ(HMAC_CTX_copy(&ctx2, &ctx1), SSL_SUCCESS);
  59831. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59832. ExpectIntEQ(HMAC_Final(&ctx1, digest, &digestSz), SSL_SUCCESS);
  59833. HMAC_CTX_cleanup(&ctx1);
  59834. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  59835. ExpectIntEQ(HMAC_Final(&ctx2, digest2, &digestSz2), SSL_SUCCESS);
  59836. HMAC_CTX_cleanup(&ctx2);
  59837. ExpectIntEQ(digestSz, digestSz2);
  59838. ExpectIntEQ(XMEMCMP(digest, digest2, digestSz), 0);
  59839. /* test HMAC_Init with NULL key */
  59840. /* init after copy */
  59841. HMAC_CTX_init(&ctx1);
  59842. ExpectIntEQ(HMAC_Init(&ctx1, (const void*)key, keySz, type), SSL_SUCCESS);
  59843. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59844. ExpectIntEQ(HMAC_CTX_copy(&ctx2, &ctx1), SSL_SUCCESS);
  59845. ExpectIntEQ(HMAC_Init(&ctx1, NULL, 0, NULL), SSL_SUCCESS);
  59846. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59847. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59848. ExpectIntEQ(HMAC_Final(&ctx1, digest, &digestSz), SSL_SUCCESS);
  59849. HMAC_CTX_cleanup(&ctx1);
  59850. ExpectIntEQ(HMAC_Init(&ctx2, NULL, 0, NULL), SSL_SUCCESS);
  59851. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  59852. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  59853. ExpectIntEQ(HMAC_Final(&ctx2, digest2, &digestSz), SSL_SUCCESS);
  59854. HMAC_CTX_cleanup(&ctx2);
  59855. ExpectIntEQ(digestSz, digestSz2);
  59856. ExpectIntEQ(XMEMCMP(digest, digest2, digestSz), 0);
  59857. /* long key */
  59858. HMAC_CTX_init(&ctx1);
  59859. ExpectIntEQ(HMAC_Init(&ctx1, (const void*)long_key, long_keySz, type),
  59860. SSL_SUCCESS);
  59861. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59862. ExpectIntEQ(HMAC_CTX_copy(&ctx2, &ctx1), SSL_SUCCESS);
  59863. ExpectIntEQ(HMAC_Init(&ctx1, NULL, 0, NULL), SSL_SUCCESS);
  59864. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59865. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59866. ExpectIntEQ(HMAC_Final(&ctx1, digest, &digestSz), SSL_SUCCESS);
  59867. HMAC_CTX_cleanup(&ctx1);
  59868. ExpectIntEQ(HMAC_Init(&ctx2, NULL, 0, NULL), SSL_SUCCESS);
  59869. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  59870. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  59871. ExpectIntEQ(HMAC_Final(&ctx2, digest2, &digestSz), SSL_SUCCESS);
  59872. HMAC_CTX_cleanup(&ctx2);
  59873. ExpectIntEQ(digestSz, digestSz2);
  59874. ExpectIntEQ(XMEMCMP(digest, digest2, digestSz), 0);
  59875. /* init before copy */
  59876. HMAC_CTX_init(&ctx1);
  59877. ExpectIntEQ(HMAC_Init(&ctx1, (const void*)key, keySz, type), SSL_SUCCESS);
  59878. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59879. ExpectIntEQ(HMAC_Init(&ctx1, NULL, 0, NULL), SSL_SUCCESS);
  59880. ExpectIntEQ(HMAC_CTX_copy(&ctx2, &ctx1), SSL_SUCCESS);
  59881. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59882. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  59883. ExpectIntEQ(HMAC_Final(&ctx1, digest, &digestSz), SSL_SUCCESS);
  59884. HMAC_CTX_cleanup(&ctx1);
  59885. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  59886. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  59887. ExpectIntEQ(HMAC_Final(&ctx2, digest2, &digestSz), SSL_SUCCESS);
  59888. HMAC_CTX_cleanup(&ctx2);
  59889. ExpectIntEQ(digestSz, digestSz2);
  59890. ExpectIntEQ(XMEMCMP(digest, digest2, digestSz), 0);
  59891. *sz = (int)digestSz;
  59892. return EXPECT_RESULT();
  59893. }
  59894. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_HMAC) */
  59895. static int test_wolfSSL_HMAC_CTX(void)
  59896. {
  59897. EXPECT_DECLS;
  59898. #if defined(OPENSSL_EXTRA) && !defined(NO_HMAC)
  59899. unsigned char digest[64];
  59900. int digestSz;
  59901. WOLFSSL_HMAC_CTX* hmac_ctx = NULL;
  59902. WOLFSSL_HMAC_CTX ctx1;
  59903. WOLFSSL_HMAC_CTX ctx2;
  59904. ExpectNotNull(hmac_ctx = wolfSSL_HMAC_CTX_new());
  59905. ExpectIntEQ(wolfSSL_HMAC_CTX_Init(NULL), 1);
  59906. ExpectIntEQ(wolfSSL_HMAC_CTX_Init(hmac_ctx), 1);
  59907. wolfSSL_HMAC_CTX_free(NULL);
  59908. wolfSSL_HMAC_CTX_free(hmac_ctx);
  59909. XMEMSET(&ctx2, 0, sizeof(WOLFSSL_HMAC_CTX));
  59910. ExpectIntEQ(HMAC_CTX_init(NULL), 1);
  59911. ExpectIntEQ(HMAC_CTX_init(&ctx2), 1);
  59912. ExpectIntEQ(HMAC_CTX_copy(NULL, NULL), 0);
  59913. ExpectIntEQ(HMAC_CTX_copy(NULL, &ctx2), 0);
  59914. ExpectIntEQ(HMAC_CTX_copy(&ctx2, NULL), 0);
  59915. #if defined(HAVE_SELFTEST) || (defined(HAVE_FIPS) && \
  59916. ((! defined(HAVE_FIPS_VERSION)) || \
  59917. defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION <= 2)))
  59918. /* Copy object that hasn't had a digest set - MD5. */
  59919. ExpectIntEQ(HMAC_CTX_copy(&ctx1, &ctx2), 1);
  59920. #else
  59921. /* Copy object that hasn't had a digest set. */
  59922. ExpectIntEQ(HMAC_CTX_copy(&ctx1, &ctx2), 0);
  59923. #endif
  59924. HMAC_CTX_cleanup(NULL);
  59925. HMAC_CTX_cleanup(&ctx2);
  59926. ExpectNull(HMAC_CTX_get_md(NULL));
  59927. #ifndef NO_SHA
  59928. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha1(), digest, &digestSz)),
  59929. TEST_SUCCESS);
  59930. ExpectIntEQ(digestSz, 20);
  59931. ExpectIntEQ(XMEMCMP("\xD9\x68\x77\x23\x70\xFB\x53\x70\x53\xBA\x0E\xDC\xDA"
  59932. "\xBF\x03\x98\x31\x19\xB2\xCC", digest, digestSz), 0);
  59933. #endif /* !NO_SHA */
  59934. #ifdef WOLFSSL_SHA224
  59935. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha224(), digest, &digestSz)),
  59936. TEST_SUCCESS);
  59937. ExpectIntEQ(digestSz, 28);
  59938. ExpectIntEQ(XMEMCMP("\x57\xFD\xF4\xE1\x2D\xB0\x79\xD7\x4B\x25\x7E\xB1\x95"
  59939. "\x9C\x11\xAC\x2D\x1E\x78\x94\x4F\x3A\x0F\xED\xF8\xAD"
  59940. "\x02\x0E", digest, digestSz), 0);
  59941. #endif /* WOLFSSL_SHA224 */
  59942. #ifndef NO_SHA256
  59943. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha256(), digest, &digestSz)),
  59944. TEST_SUCCESS);
  59945. ExpectIntEQ(digestSz, 32);
  59946. ExpectIntEQ(XMEMCMP("\x13\xAB\x76\x91\x0C\x37\x86\x8D\xB3\x7E\x30\x0C\xFC"
  59947. "\xB0\x2E\x8E\x4A\xD7\xD4\x25\xCC\x3A\xA9\x0F\xA2\xF2"
  59948. "\x47\x1E\x62\x6F\x5D\xF2", digest, digestSz), 0);
  59949. #endif /* !NO_SHA256 */
  59950. #ifdef WOLFSSL_SHA384
  59951. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha384(), digest, &digestSz)),
  59952. TEST_SUCCESS);
  59953. ExpectIntEQ(digestSz, 48);
  59954. ExpectIntEQ(XMEMCMP("\x9E\xCB\x07\x0C\x11\x76\x3F\x23\xC3\x25\x0E\xC4\xB7"
  59955. "\x28\x77\x95\x99\xD5\x9D\x7A\xBB\x1A\x9F\xB7\xFD\x25"
  59956. "\xC9\x72\x47\x9F\x8F\x86\x76\xD6\x20\x57\x87\xB7\xE7"
  59957. "\xCD\xFB\xC2\xCC\x9F\x2B\xC5\x41\xAB",
  59958. digest, digestSz), 0);
  59959. #endif /* WOLFSSL_SHA384 */
  59960. #ifdef WOLFSSL_SHA512
  59961. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha512(), digest, &digestSz)),
  59962. TEST_SUCCESS);
  59963. ExpectIntEQ(digestSz, 64);
  59964. ExpectIntEQ(XMEMCMP("\xD4\x21\x0C\x8B\x60\x6F\xF4\xBF\x07\x2F\x26\xCC\xAD"
  59965. "\xBC\x06\x0B\x34\x78\x8B\x4F\xD6\xC0\x42\xF1\x33\x10"
  59966. "\x6C\x4F\x1E\x55\x59\xDD\x2A\x9F\x15\x88\x62\xF8\x60"
  59967. "\xA3\x99\x91\xE2\x08\x7B\xF7\x95\x3A\xB0\x92\x48\x60"
  59968. "\x88\x8B\x5B\xB8\x5F\xE9\xB6\xB1\x96\xE3\xB5\xF0",
  59969. digest, digestSz), 0);
  59970. #endif /* WOLFSSL_SHA512 */
  59971. #ifdef WOLFSSL_SHA3
  59972. #ifndef WOLFSSL_NOSHA3_224
  59973. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha3_224(), digest, &digestSz)),
  59974. TEST_SUCCESS);
  59975. ExpectIntEQ(digestSz, 28);
  59976. ExpectIntEQ(XMEMCMP("\xdc\x53\x25\x3f\xc0\x9d\x2b\x0c\x7f\x59\x11\x17\x08"
  59977. "\x5c\xe8\x43\x31\x01\x5a\xb3\xe3\x08\x37\x71\x26\x0b"
  59978. "\x29\x0f", digest, digestSz), 0);
  59979. #endif
  59980. #ifndef WOLFSSL_NOSHA3_256
  59981. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha3_256(), digest, &digestSz)),
  59982. TEST_SUCCESS);
  59983. ExpectIntEQ(digestSz, 32);
  59984. ExpectIntEQ(XMEMCMP("\x0f\x00\x89\x82\x15\xce\xd6\x45\x01\x83\xce\xc8\x35"
  59985. "\xab\x71\x07\xc9\xfe\x61\x22\x38\xf9\x09\xad\x35\x65"
  59986. "\x43\x77\x24\xd4\x1e\xf4", digest, digestSz), 0);
  59987. #endif
  59988. #ifndef WOLFSSL_NOSHA3_384
  59989. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha3_384(), digest, &digestSz)),
  59990. TEST_SUCCESS);
  59991. ExpectIntEQ(digestSz, 48);
  59992. ExpectIntEQ(XMEMCMP("\x0f\x6a\xc0\xfb\xc3\xf2\x80\xb1\xb4\x04\xb6\xc8\x45"
  59993. "\x23\x3b\xb4\xbe\xc6\xea\x85\x07\xca\x8c\x71\xbb\x6e"
  59994. "\x79\xf6\xf9\x2b\x98\xf5\xef\x11\x39\xd4\x5d\xd3\xca"
  59995. "\xc0\xe6\x81\xf7\x73\xf9\x85\x5d\x4f",
  59996. digest, digestSz), 0);
  59997. #endif
  59998. #ifndef WOLFSSL_NOSHA3_512
  59999. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha3_512(), digest, &digestSz)),
  60000. TEST_SUCCESS);
  60001. ExpectIntEQ(digestSz, 64);
  60002. ExpectIntEQ(XMEMCMP("\x3e\x77\xe3\x59\x42\x89\xed\xc3\xa4\x26\x3d\xa4\x75"
  60003. "\xd2\x84\x8c\xb2\xf3\x25\x04\x47\x61\xce\x1c\x42\x86"
  60004. "\xcd\xf4\x56\xaa\x2f\x84\xb1\x3b\x18\xed\xe6\xd6\x48"
  60005. "\x15\xb0\x29\xc5\x9d\x32\xef\xdd\x3e\x09\xf6\xed\x9e"
  60006. "\x70\xbc\x1c\x63\xf7\x3b\x3e\xe1\xdc\x84\x9c\x1c",
  60007. digest, digestSz), 0);
  60008. #endif
  60009. #endif
  60010. #if !defined(NO_MD5) && (!defined(HAVE_FIPS_VERSION) || \
  60011. HAVE_FIPS_VERSION <= 2)
  60012. ExpectIntEQ((test_HMAC_CTX_helper(EVP_md5(), digest, &digestSz)),
  60013. TEST_SUCCESS);
  60014. ExpectIntEQ(digestSz, 16);
  60015. ExpectIntEQ(XMEMCMP("\xB7\x27\xC4\x41\xE5\x2E\x62\xBA\x54\xED\x72\x70\x9F"
  60016. "\xE4\x98\xDD", digest, digestSz), 0);
  60017. #endif /* !NO_MD5 */
  60018. #endif
  60019. return EXPECT_RESULT();
  60020. }
  60021. #if defined(OPENSSL_EXTRA) && (!defined(NO_SHA256) || \
  60022. defined(WOLFSSL_SHA224) || defined(WOLFSSL_SHA384) || \
  60023. defined(WOLFSSL_SHA512) || defined(WOLFSSL_SHA3))
  60024. static int test_openssl_hmac(const WOLFSSL_EVP_MD* md, int md_len)
  60025. {
  60026. EXPECT_DECLS;
  60027. static const unsigned char key[] = "simple test key";
  60028. HMAC_CTX* hmac = NULL;
  60029. ENGINE* e = NULL;
  60030. unsigned char hash[WC_MAX_DIGEST_SIZE];
  60031. unsigned int len;
  60032. ExpectNotNull(hmac = HMAC_CTX_new());
  60033. HMAC_CTX_init(hmac);
  60034. #if defined(HAVE_SELFTEST) || (defined(HAVE_FIPS) && \
  60035. ((! defined(HAVE_FIPS_VERSION)) || \
  60036. defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION <= 2)))
  60037. /* Get size on object that hasn't had a digest set - MD5. */
  60038. ExpectIntEQ(HMAC_size(hmac), 16);
  60039. ExpectIntEQ(HMAC_Init(hmac, NULL, 0, NULL), 1);
  60040. ExpectIntEQ(HMAC_Init(hmac, (void*)key, (int)sizeof(key), NULL), 1);
  60041. ExpectIntEQ(HMAC_Init(hmac, NULL, 0, md), 1);
  60042. #else
  60043. ExpectIntEQ(HMAC_size(hmac), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60044. ExpectIntEQ(HMAC_Init(hmac, NULL, 0, NULL), 0);
  60045. ExpectIntEQ(HMAC_Init(hmac, (void*)key, (int)sizeof(key), NULL), 0);
  60046. ExpectIntEQ(HMAC_Init(hmac, NULL, 0, md), 0);
  60047. #endif
  60048. ExpectIntEQ(HMAC_Init_ex(NULL, (void*)key, (int)sizeof(key), md, e), 0);
  60049. ExpectIntEQ(HMAC_Init_ex(hmac, (void*)key, (int)sizeof(key), md, e), 1);
  60050. /* re-using test key as data to hash */
  60051. ExpectIntEQ(HMAC_Update(NULL, key, (int)sizeof(key)), 0);
  60052. ExpectIntEQ(HMAC_Update(hmac, key, (int)sizeof(key)), 1);
  60053. ExpectIntEQ(HMAC_Update(hmac, key, 0), 1);
  60054. ExpectIntEQ(HMAC_Update(hmac, NULL, 0), 1);
  60055. ExpectIntEQ(HMAC_Update(hmac, NULL, (int)sizeof(key)), 1);
  60056. ExpectIntEQ(HMAC_Final(NULL, NULL, &len), 0);
  60057. ExpectIntEQ(HMAC_Final(hmac, NULL, &len), 0);
  60058. ExpectIntEQ(HMAC_Final(NULL, hash, &len), 0);
  60059. ExpectIntEQ(HMAC_Final(hmac, hash, &len), 1);
  60060. ExpectIntEQ(HMAC_Final(hmac, hash, NULL), 1);
  60061. ExpectIntEQ(len, md_len);
  60062. ExpectIntEQ(HMAC_size(NULL), 0);
  60063. ExpectIntEQ(HMAC_size(hmac), md_len);
  60064. ExpectStrEQ(HMAC_CTX_get_md(hmac), md);
  60065. HMAC_cleanup(NULL);
  60066. HMAC_cleanup(hmac);
  60067. HMAC_CTX_free(hmac);
  60068. len = 0;
  60069. ExpectNull(HMAC(NULL, key, (int)sizeof(key), NULL, 0, hash, &len));
  60070. ExpectNull(HMAC(md, NULL, (int)sizeof(key), NULL, 0, hash, &len));
  60071. ExpectNull(HMAC(md, key, (int)sizeof(key), NULL, 0, NULL, &len));
  60072. ExpectNotNull(HMAC(md, key, (int)sizeof(key), NULL, 0, hash, &len));
  60073. ExpectIntEQ(len, md_len);
  60074. ExpectNotNull(HMAC(md, key, (int)sizeof(key), NULL, 0, hash, NULL));
  60075. /* With data. */
  60076. ExpectNotNull(HMAC(md, key, (int)sizeof(key), key, (int)sizeof(key), hash,
  60077. &len));
  60078. /* With NULL data. */
  60079. ExpectNull(HMAC(md, key, (int)sizeof(key), NULL, (int)sizeof(key), hash,
  60080. &len));
  60081. /* With zero length data. */
  60082. ExpectNotNull(HMAC(md, key, (int)sizeof(key), key, 0, hash, &len));
  60083. return EXPECT_RESULT();
  60084. }
  60085. #endif
  60086. static int test_wolfSSL_HMAC(void)
  60087. {
  60088. EXPECT_DECLS;
  60089. #if defined(OPENSSL_EXTRA) && (!defined(NO_SHA256) || \
  60090. defined(WOLFSSL_SHA224) || defined(WOLFSSL_SHA384) || \
  60091. defined(WOLFSSL_SHA512) || defined(WOLFSSL_SHA3))
  60092. #ifndef NO_SHA256
  60093. ExpectIntEQ(test_openssl_hmac(EVP_sha256(), (int)WC_SHA256_DIGEST_SIZE),
  60094. TEST_SUCCESS);
  60095. #endif
  60096. #ifdef WOLFSSL_SHA224
  60097. ExpectIntEQ(test_openssl_hmac(EVP_sha224(), (int)WC_SHA224_DIGEST_SIZE),
  60098. TEST_SUCCESS);
  60099. #endif
  60100. #ifdef WOLFSSL_SHA384
  60101. ExpectIntEQ(test_openssl_hmac(EVP_sha384(), (int)WC_SHA384_DIGEST_SIZE),
  60102. TEST_SUCCESS);
  60103. #endif
  60104. #ifdef WOLFSSL_SHA512
  60105. ExpectIntEQ(test_openssl_hmac(EVP_sha512(), (int)WC_SHA512_DIGEST_SIZE),
  60106. TEST_SUCCESS);
  60107. #endif
  60108. #ifdef WOLFSSL_SHA3
  60109. #ifndef WOLFSSL_NOSHA3_224
  60110. ExpectIntEQ(test_openssl_hmac(EVP_sha3_224(),
  60111. (int)WC_SHA3_224_DIGEST_SIZE), TEST_SUCCESS);
  60112. #endif
  60113. #ifndef WOLFSSL_NOSHA3_256
  60114. ExpectIntEQ(test_openssl_hmac(EVP_sha3_256(),
  60115. (int)WC_SHA3_256_DIGEST_SIZE), TEST_SUCCESS);
  60116. #endif
  60117. #ifndef WOLFSSL_NOSHA3_384
  60118. ExpectIntEQ(test_openssl_hmac(EVP_sha3_384(),
  60119. (int)WC_SHA3_384_DIGEST_SIZE), TEST_SUCCESS);
  60120. #endif
  60121. #ifndef WOLFSSL_NOSHA3_512
  60122. ExpectIntEQ(test_openssl_hmac(EVP_sha3_512(),
  60123. (int)WC_SHA3_512_DIGEST_SIZE), TEST_SUCCESS);
  60124. #endif
  60125. #endif
  60126. #ifndef NO_SHA
  60127. ExpectIntEQ(test_openssl_hmac(EVP_sha1(), (int)WC_SHA_DIGEST_SIZE),
  60128. TEST_SUCCESS);
  60129. #endif
  60130. #endif
  60131. return EXPECT_RESULT();
  60132. }
  60133. static int test_wolfSSL_CMAC(void)
  60134. {
  60135. EXPECT_DECLS;
  60136. #if defined(WOLFSSL_CMAC) && defined(OPENSSL_EXTRA) && \
  60137. defined(WOLFSSL_AES_DIRECT)
  60138. int i;
  60139. byte key[AES_256_KEY_SIZE];
  60140. CMAC_CTX* cmacCtx = NULL;
  60141. byte out[AES_BLOCK_SIZE];
  60142. size_t outLen = AES_BLOCK_SIZE;
  60143. for (i=0; i < AES_256_KEY_SIZE; ++i) {
  60144. key[i] = i;
  60145. }
  60146. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  60147. /* Check CMAC_CTX_get0_cipher_ctx; return value not used. */
  60148. ExpectNotNull(CMAC_CTX_get0_cipher_ctx(cmacCtx));
  60149. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_128_KEY_SIZE, EVP_aes_128_cbc(),
  60150. NULL), 1);
  60151. /* re-using test key as data to hash */
  60152. ExpectIntEQ(CMAC_Update(cmacCtx, key, AES_128_KEY_SIZE), 1);
  60153. ExpectIntEQ(CMAC_Update(cmacCtx, NULL, 0), 1);
  60154. ExpectIntEQ(CMAC_Final(cmacCtx, out, &outLen), 1);
  60155. ExpectIntEQ(outLen, AES_BLOCK_SIZE);
  60156. /* No Update works. */
  60157. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_128_KEY_SIZE, EVP_aes_128_cbc(),
  60158. NULL), 1);
  60159. ExpectIntEQ(CMAC_Final(cmacCtx, out, NULL), 1);
  60160. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_128_KEY_SIZE, EVP_aes_128_cbc(),
  60161. NULL), 1);
  60162. /* Test parameters with CMAC_Update. */
  60163. ExpectIntEQ(CMAC_Update(NULL, NULL, 0), 0);
  60164. ExpectIntEQ(CMAC_Update(NULL, key, 0), 0);
  60165. ExpectIntEQ(CMAC_Update(NULL, NULL, AES_128_KEY_SIZE), 0);
  60166. ExpectIntEQ(CMAC_Update(NULL, key, AES_128_KEY_SIZE), 0);
  60167. ExpectIntEQ(CMAC_Update(cmacCtx, key, 0), 1);
  60168. ExpectIntEQ(CMAC_Update(cmacCtx, NULL, 0), 1);
  60169. ExpectIntEQ(CMAC_Update(cmacCtx, NULL, AES_128_KEY_SIZE), 1);
  60170. /* Test parameters with CMAC_Final. */
  60171. ExpectIntEQ(CMAC_Final(NULL, NULL, NULL), 0);
  60172. ExpectIntEQ(CMAC_Final(NULL, out, NULL), 0);
  60173. ExpectIntEQ(CMAC_Final(NULL, NULL, &outLen), 0);
  60174. ExpectIntEQ(CMAC_Final(NULL, out, &outLen), 0);
  60175. ExpectIntEQ(CMAC_Final(cmacCtx, NULL, NULL), 1);
  60176. ExpectIntEQ(CMAC_Final(cmacCtx, NULL, &outLen), 1);
  60177. ExpectIntEQ(CMAC_Final(cmacCtx, out, NULL), 1);
  60178. CMAC_CTX_free(cmacCtx);
  60179. /* Test parameters with CMAC Init. */
  60180. cmacCtx = NULL;
  60181. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  60182. ExpectNotNull(CMAC_CTX_get0_cipher_ctx(cmacCtx));
  60183. ExpectIntEQ(CMAC_Init(NULL, NULL, 0, NULL, NULL), 0);
  60184. ExpectIntEQ(CMAC_Init(NULL, key, AES_192_KEY_SIZE, EVP_aes_192_cbc(),
  60185. NULL), 0);
  60186. ExpectIntEQ(CMAC_Init(cmacCtx, NULL, AES_192_KEY_SIZE, EVP_aes_192_cbc(),
  60187. NULL), 0);
  60188. /* give a key too small for the cipher, verify we get failure */
  60189. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_128_KEY_SIZE, EVP_aes_192_cbc(),
  60190. NULL), 0);
  60191. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_192_KEY_SIZE, NULL, NULL), 0);
  60192. #if defined(HAVE_AESGCM) && defined(WOLFSSL_AES_128)
  60193. /* Only AES-CBC supported. */
  60194. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_128_KEY_SIZE, EVP_aes_128_gcm(),
  60195. NULL), 0);
  60196. #endif
  60197. CMAC_CTX_free(cmacCtx);
  60198. ExpectNull(CMAC_CTX_get0_cipher_ctx(NULL));
  60199. cmacCtx = NULL;
  60200. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  60201. /* No Init. */
  60202. ExpectIntEQ(CMAC_Final(cmacCtx, out, &outLen), 0);
  60203. CMAC_CTX_free(cmacCtx);
  60204. /* Test AES-256-CBC */
  60205. cmacCtx = NULL;
  60206. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  60207. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_256_KEY_SIZE, EVP_aes_256_cbc(),
  60208. NULL), 1);
  60209. ExpectIntEQ(CMAC_Update(cmacCtx, key, AES_128_KEY_SIZE), 1);
  60210. ExpectIntEQ(CMAC_Final(cmacCtx, out, NULL), 1);
  60211. CMAC_CTX_free(cmacCtx);
  60212. /* Test AES-192-CBC */
  60213. cmacCtx = NULL;
  60214. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  60215. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_192_KEY_SIZE, EVP_aes_192_cbc(),
  60216. NULL), 1);
  60217. ExpectIntEQ(CMAC_Update(cmacCtx, key, AES_128_KEY_SIZE), 1);
  60218. ExpectIntEQ(CMAC_Final(cmacCtx, out, NULL), 1);
  60219. CMAC_CTX_free(cmacCtx);
  60220. cmacCtx = NULL;
  60221. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  60222. CMAC_CTX_free(cmacCtx);
  60223. #endif /* WOLFSSL_CMAC && OPENSSL_EXTRA && WOLFSSL_AES_DIRECT */
  60224. return EXPECT_RESULT();
  60225. }
  60226. static int test_wolfSSL_DES(void)
  60227. {
  60228. EXPECT_DECLS;
  60229. #if defined(OPENSSL_EXTRA) && !defined(NO_DES3)
  60230. const_DES_cblock myDes;
  60231. DES_cblock iv;
  60232. DES_key_schedule key;
  60233. word32 i = 0;
  60234. DES_LONG dl = 0;
  60235. unsigned char msg[] = "hello wolfssl";
  60236. unsigned char weakKey[][8] = {
  60237. { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
  60238. { 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE },
  60239. { 0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1 },
  60240. { 0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E }
  60241. };
  60242. unsigned char semiWeakKey[][8] = {
  60243. { 0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E },
  60244. { 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01 },
  60245. { 0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1 },
  60246. { 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01 },
  60247. { 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE },
  60248. { 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01 },
  60249. { 0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1 },
  60250. { 0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E },
  60251. { 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE },
  60252. { 0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E },
  60253. { 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE },
  60254. { 0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1 }
  60255. };
  60256. DES_check_key(1);
  60257. DES_set_key(&myDes, &key);
  60258. /* check, check of odd parity */
  60259. XMEMSET(myDes, 4, sizeof(const_DES_cblock));
  60260. myDes[0] = 6; /* set even parity */
  60261. XMEMSET(key, 5, sizeof(DES_key_schedule));
  60262. ExpectIntEQ(DES_set_key_checked(&myDes, &key), -1);
  60263. ExpectIntNE(key[0], myDes[0]); /* should not have copied over key */
  60264. ExpectIntEQ(DES_set_key_checked(NULL, NULL), -2);
  60265. ExpectIntEQ(DES_set_key_checked(&myDes, NULL), -2);
  60266. ExpectIntEQ(DES_set_key_checked(NULL, &key), -2);
  60267. /* set odd parity for success case */
  60268. DES_set_odd_parity(&myDes);
  60269. ExpectIntEQ(DES_check_key_parity(&myDes), 1);
  60270. fprintf(stderr, "%02x %02x %02x %02x", myDes[0], myDes[1], myDes[2],
  60271. myDes[3]);
  60272. ExpectIntEQ(DES_set_key_checked(&myDes, &key), 0);
  60273. for (i = 0; i < sizeof(DES_key_schedule); i++) {
  60274. ExpectIntEQ(key[i], myDes[i]);
  60275. }
  60276. ExpectIntEQ(DES_is_weak_key(&myDes), 0);
  60277. /* check weak key */
  60278. XMEMSET(myDes, 1, sizeof(const_DES_cblock));
  60279. XMEMSET(key, 5, sizeof(DES_key_schedule));
  60280. ExpectIntEQ(DES_set_key_checked(&myDes, &key), -2);
  60281. ExpectIntNE(key[0], myDes[0]); /* should not have copied over key */
  60282. DES_set_key_unchecked(NULL, NULL);
  60283. DES_set_key_unchecked(&myDes, NULL);
  60284. DES_set_key_unchecked(NULL, &key);
  60285. /* compare arrays, should be the same */
  60286. /* now do unchecked copy of a weak key over */
  60287. DES_set_key_unchecked(&myDes, &key);
  60288. /* compare arrays, should be the same */
  60289. for (i = 0; i < sizeof(DES_key_schedule); i++) {
  60290. ExpectIntEQ(key[i], myDes[i]);
  60291. }
  60292. ExpectIntEQ(DES_is_weak_key(&myDes), 1);
  60293. myDes[7] = 2;
  60294. ExpectIntEQ(DES_set_key_checked(&myDes, &key), 0);
  60295. ExpectIntEQ(DES_is_weak_key(&myDes), 0);
  60296. ExpectIntEQ(DES_is_weak_key(NULL), 1);
  60297. /* Test all weak keys. */
  60298. for (i = 0; i < sizeof(weakKey) / sizeof(*weakKey); i++) {
  60299. ExpectIntEQ(DES_set_key_checked(&weakKey[i], &key), -2);
  60300. }
  60301. /* Test all semi-weak keys. */
  60302. for (i = 0; i < sizeof(semiWeakKey) / sizeof(*semiWeakKey); i++) {
  60303. ExpectIntEQ(DES_set_key_checked(&semiWeakKey[i], &key), -2);
  60304. }
  60305. /* check DES_key_sched API */
  60306. XMEMSET(key, 1, sizeof(DES_key_schedule));
  60307. ExpectIntEQ(DES_key_sched(&myDes, NULL), 0);
  60308. ExpectIntEQ(DES_key_sched(NULL, &key), 0);
  60309. ExpectIntEQ(DES_key_sched(&myDes, &key), 0);
  60310. /* compare arrays, should be the same */
  60311. for (i = 0; i < sizeof(DES_key_schedule); i++) {
  60312. ExpectIntEQ(key[i], myDes[i]);
  60313. }
  60314. ExpectIntEQ((DES_cbc_cksum(NULL, NULL, 0, NULL, NULL)), 0);
  60315. ExpectIntEQ((DES_cbc_cksum(msg, NULL, 0, NULL, NULL)), 0);
  60316. ExpectIntEQ((DES_cbc_cksum(NULL, &key, 0, NULL, NULL)), 0);
  60317. ExpectIntEQ((DES_cbc_cksum(NULL, NULL, 0, &myDes, NULL)), 0);
  60318. ExpectIntEQ((DES_cbc_cksum(NULL, NULL, 0, NULL, &iv)), 0);
  60319. ExpectIntEQ((DES_cbc_cksum(NULL, &key, sizeof(msg), &myDes, &iv)), 0);
  60320. ExpectIntEQ((DES_cbc_cksum(msg, NULL, sizeof(msg), &myDes, &iv)), 0);
  60321. ExpectIntEQ((DES_cbc_cksum(msg, &key, sizeof(msg), NULL, &iv)), 0);
  60322. ExpectIntEQ((DES_cbc_cksum(msg, &key, sizeof(msg), &myDes, NULL)), 0);
  60323. /* DES_cbc_cksum should return the last 4 of the last 8 bytes after
  60324. * DES_cbc_encrypt on the input */
  60325. XMEMSET(iv, 0, sizeof(DES_cblock));
  60326. XMEMSET(myDes, 5, sizeof(DES_key_schedule));
  60327. ExpectIntGT((dl = DES_cbc_cksum(msg, &key, sizeof(msg), &myDes, &iv)), 0);
  60328. ExpectIntEQ(dl, 480052723);
  60329. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_DES3) */
  60330. return EXPECT_RESULT();
  60331. }
  60332. static int test_wolfSSL_DES_ncbc(void)
  60333. {
  60334. EXPECT_DECLS;
  60335. #if defined(OPENSSL_EXTRA) && !defined(NO_DES3)
  60336. const_DES_cblock myDes;
  60337. DES_cblock iv = {1};
  60338. DES_key_schedule key = {0};
  60339. unsigned char msg[] = "hello wolfssl";
  60340. unsigned char out[DES_BLOCK_SIZE * 2] = {0};
  60341. unsigned char pln[DES_BLOCK_SIZE * 2] = {0};
  60342. unsigned char exp[] = {0x31, 0x98, 0x2F, 0x3A, 0x55, 0xBF, 0xD8, 0xC4};
  60343. unsigned char exp2[] = {0xC7, 0x45, 0x8B, 0x28, 0x10, 0x53, 0xE0, 0x58};
  60344. /* partial block test */
  60345. DES_set_key(&key, &myDes);
  60346. DES_ncbc_encrypt(msg, out, 3, &myDes, &iv, DES_ENCRYPT);
  60347. ExpectIntEQ(XMEMCMP(exp, out, DES_BLOCK_SIZE), 0);
  60348. ExpectIntEQ(XMEMCMP(exp, iv, DES_BLOCK_SIZE), 0);
  60349. DES_set_key(&key, &myDes);
  60350. XMEMSET((byte*)&iv, 0, DES_BLOCK_SIZE);
  60351. *((byte*)&iv) = 1;
  60352. DES_ncbc_encrypt(out, pln, 3, &myDes, &iv, DES_DECRYPT);
  60353. ExpectIntEQ(XMEMCMP(msg, pln, 3), 0);
  60354. ExpectIntEQ(XMEMCMP(exp, iv, DES_BLOCK_SIZE), 0);
  60355. /* full block test */
  60356. DES_set_key(&key, &myDes);
  60357. XMEMSET(pln, 0, DES_BLOCK_SIZE);
  60358. XMEMSET((byte*)&iv, 0, DES_BLOCK_SIZE);
  60359. *((byte*)&iv) = 1;
  60360. DES_ncbc_encrypt(msg, out, 8, &myDes, &iv, DES_ENCRYPT);
  60361. ExpectIntEQ(XMEMCMP(exp2, out, DES_BLOCK_SIZE), 0);
  60362. ExpectIntEQ(XMEMCMP(exp2, iv, DES_BLOCK_SIZE), 0);
  60363. DES_set_key(&key, &myDes);
  60364. XMEMSET((byte*)&iv, 0, DES_BLOCK_SIZE);
  60365. *((byte*)&iv) = 1;
  60366. DES_ncbc_encrypt(out, pln, 8, &myDes, &iv, DES_DECRYPT);
  60367. ExpectIntEQ(XMEMCMP(msg, pln, 8), 0);
  60368. ExpectIntEQ(XMEMCMP(exp2, iv, DES_BLOCK_SIZE), 0);
  60369. #endif
  60370. return EXPECT_RESULT();
  60371. }
  60372. static int test_wolfSSL_DES_ecb_encrypt(void)
  60373. {
  60374. EXPECT_DECLS;
  60375. #if defined(OPENSSL_EXTRA) && !defined(NO_DES3) && defined(WOLFSSL_DES_ECB)
  60376. WOLFSSL_DES_cblock input1, input2, output1, output2, back1, back2;
  60377. WOLFSSL_DES_key_schedule key;
  60378. XMEMCPY(key, "12345678", sizeof(WOLFSSL_DES_key_schedule));
  60379. XMEMCPY(input1, "Iamhuman", sizeof(WOLFSSL_DES_cblock));
  60380. XMEMCPY(input2, "Whoisit?", sizeof(WOLFSSL_DES_cblock));
  60381. XMEMSET(output1, 0, sizeof(WOLFSSL_DES_cblock));
  60382. XMEMSET(output2, 0, sizeof(WOLFSSL_DES_cblock));
  60383. XMEMSET(back1, 0, sizeof(WOLFSSL_DES_cblock));
  60384. XMEMSET(back2, 0, sizeof(WOLFSSL_DES_cblock));
  60385. wolfSSL_DES_ecb_encrypt(NULL, NULL, NULL, DES_ENCRYPT);
  60386. wolfSSL_DES_ecb_encrypt(&input1, NULL, NULL, DES_ENCRYPT);
  60387. wolfSSL_DES_ecb_encrypt(NULL, &output1, NULL, DES_ENCRYPT);
  60388. wolfSSL_DES_ecb_encrypt(NULL, NULL, &key, DES_ENCRYPT);
  60389. wolfSSL_DES_ecb_encrypt(&input1, &output1, NULL, DES_ENCRYPT);
  60390. wolfSSL_DES_ecb_encrypt(&input1, NULL, &key, DES_ENCRYPT);
  60391. wolfSSL_DES_ecb_encrypt(NULL, &output1, &key, DES_ENCRYPT);
  60392. /* Encrypt messages */
  60393. wolfSSL_DES_ecb_encrypt(&input1, &output1, &key, DES_ENCRYPT);
  60394. wolfSSL_DES_ecb_encrypt(&input2, &output2, &key, DES_ENCRYPT);
  60395. {
  60396. /* Decrypt messages */
  60397. int ret1 = 0;
  60398. int ret2 = 0;
  60399. wolfSSL_DES_ecb_encrypt(&output1, &back1, &key, DES_DECRYPT);
  60400. ExpectIntEQ(ret1 = XMEMCMP((unsigned char *)back1,
  60401. (unsigned char *)input1, sizeof(WOLFSSL_DES_cblock)), 0);
  60402. wolfSSL_DES_ecb_encrypt(&output2, &back2, &key, DES_DECRYPT);
  60403. ExpectIntEQ(ret2 = XMEMCMP((unsigned char *)back2,
  60404. (unsigned char *)input2, sizeof(WOLFSSL_DES_cblock)), 0);
  60405. }
  60406. #endif
  60407. return EXPECT_RESULT();
  60408. }
  60409. static int test_wolfSSL_DES_ede3_cbc_encrypt(void)
  60410. {
  60411. EXPECT_DECLS;
  60412. #if defined(OPENSSL_EXTRA) && !defined(NO_DES3)
  60413. unsigned char input1[8], input2[8];
  60414. unsigned char output1[8], output2[8];
  60415. unsigned char back1[8], back2[8];
  60416. WOLFSSL_DES_cblock iv1, iv2;
  60417. WOLFSSL_DES_key_schedule key1, key2, key3;
  60418. int i;
  60419. XMEMCPY(key1, "12345678", sizeof(WOLFSSL_DES_key_schedule));
  60420. XMEMCPY(key2, "23456781", sizeof(WOLFSSL_DES_key_schedule));
  60421. XMEMCPY(key3, "34567823", sizeof(WOLFSSL_DES_key_schedule));
  60422. XMEMCPY(input1, "Iamhuman", sizeof(input1));
  60423. XMEMCPY(input2, "Whoisit?", sizeof(input2));
  60424. XMEMSET(output1, 0, sizeof(output1));
  60425. XMEMSET(output2, 0, sizeof(output2));
  60426. XMEMSET(back1, 0, sizeof(back1));
  60427. XMEMSET(back2, 0, sizeof(back2));
  60428. XMEMCPY(iv1, "87654321", sizeof(WOLFSSL_DES_cblock));
  60429. XMEMCPY(iv2, "98765432", sizeof(WOLFSSL_DES_cblock));
  60430. /* Encrypt messages */
  60431. wolfSSL_DES_ede3_cbc_encrypt(input1, output1, 8, &key1, &key2, &key3, &iv1,
  60432. DES_ENCRYPT);
  60433. wolfSSL_DES_ede3_cbc_encrypt(input2, output2, 8, &key1, &key2, &key3, &iv2,
  60434. DES_ENCRYPT);
  60435. {
  60436. XMEMCPY(iv1, "87654321", sizeof(WOLFSSL_DES_cblock));
  60437. XMEMCPY(iv2, "98765432", sizeof(WOLFSSL_DES_cblock));
  60438. /* Decrypt messages */
  60439. wolfSSL_DES_ede3_cbc_encrypt(output1, back1, 8, &key1, &key2, &key3,
  60440. &iv1, DES_DECRYPT);
  60441. ExpectIntEQ(XMEMCMP(back1, input1, sizeof(input1)), 0);
  60442. wolfSSL_DES_ede3_cbc_encrypt(output2, back2, 8, &key1, &key2, &key3,
  60443. &iv2, DES_DECRYPT);
  60444. ExpectIntEQ(XMEMCMP(back2, input2, sizeof(input2)), 0);
  60445. }
  60446. for (i = 0; i < 8; i++) {
  60447. XMEMSET(output1, 0, sizeof(output1));
  60448. XMEMSET(output2, 0, sizeof(output2));
  60449. XMEMSET(back1, 0, sizeof(back1));
  60450. XMEMSET(back2, 0, sizeof(back2));
  60451. XMEMCPY(iv1, "87654321", sizeof(WOLFSSL_DES_cblock));
  60452. XMEMCPY(iv2, "98765432", sizeof(WOLFSSL_DES_cblock));
  60453. /* Encrypt partial messages */
  60454. wolfSSL_DES_ede3_cbc_encrypt(input1, output1, i, &key1, &key2, &key3,
  60455. &iv1, DES_ENCRYPT);
  60456. wolfSSL_DES_ede3_cbc_encrypt(input2, output2, i, &key1, &key2, &key3,
  60457. &iv2, DES_ENCRYPT);
  60458. {
  60459. XMEMCPY(iv1, "87654321", sizeof(WOLFSSL_DES_cblock));
  60460. XMEMCPY(iv2, "98765432", sizeof(WOLFSSL_DES_cblock));
  60461. /* Decrypt messages */
  60462. wolfSSL_DES_ede3_cbc_encrypt(output1, back1, i, &key1, &key2,
  60463. &key3, &iv1, DES_DECRYPT);
  60464. ExpectIntEQ(XMEMCMP(back1, input1, i), 0);
  60465. wolfSSL_DES_ede3_cbc_encrypt(output2, back2, i, &key1, &key2,
  60466. &key3, &iv2, DES_DECRYPT);
  60467. ExpectIntEQ(XMEMCMP(back2, input2, i), 0);
  60468. }
  60469. }
  60470. #endif
  60471. return EXPECT_RESULT();
  60472. }
  60473. static int test_wolfSSL_AES_encrypt(void)
  60474. {
  60475. EXPECT_DECLS;
  60476. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AES_ECB) \
  60477. && !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
  60478. AES_KEY enc;
  60479. AES_KEY dec;
  60480. const byte msg[] = {
  60481. 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
  60482. 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a
  60483. };
  60484. const byte exp[] = {
  60485. 0xf3, 0xee, 0xd1, 0xbd, 0xb5, 0xd2, 0xa0, 0x3c,
  60486. 0x06, 0x4b, 0x5a, 0x7e, 0x3d, 0xb1, 0x81, 0xf8,
  60487. };
  60488. const byte key[] = {
  60489. 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
  60490. 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
  60491. 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
  60492. 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4
  60493. };
  60494. byte eout[sizeof(msg)];
  60495. byte dout[sizeof(msg)];
  60496. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &enc), 0);
  60497. ExpectIntEQ(AES_set_decrypt_key(key, sizeof(key)*8, &dec), 0);
  60498. wolfSSL_AES_encrypt(NULL, NULL, NULL);
  60499. wolfSSL_AES_encrypt(msg, NULL, NULL);
  60500. wolfSSL_AES_encrypt(NULL, eout, NULL);
  60501. wolfSSL_AES_encrypt(NULL, NULL, &enc);
  60502. wolfSSL_AES_encrypt(msg, eout, NULL);
  60503. wolfSSL_AES_encrypt(msg, NULL, &enc);
  60504. wolfSSL_AES_encrypt(NULL, eout, &enc);
  60505. wolfSSL_AES_decrypt(NULL, NULL, NULL);
  60506. wolfSSL_AES_decrypt(eout, NULL, NULL);
  60507. wolfSSL_AES_decrypt(NULL, dout, NULL);
  60508. wolfSSL_AES_decrypt(NULL, NULL, &dec);
  60509. wolfSSL_AES_decrypt(eout, dout, NULL);
  60510. wolfSSL_AES_decrypt(eout, NULL, &dec);
  60511. wolfSSL_AES_decrypt(NULL, dout, &dec);
  60512. wolfSSL_AES_encrypt(msg, eout, &enc);
  60513. ExpectIntEQ(XMEMCMP(eout, exp, AES_BLOCK_SIZE), 0);
  60514. wolfSSL_AES_decrypt(eout, dout, &dec);
  60515. ExpectIntEQ(XMEMCMP(dout, msg, AES_BLOCK_SIZE), 0);
  60516. #endif
  60517. return EXPECT_RESULT();
  60518. }
  60519. static int test_wolfSSL_AES_ecb_encrypt(void)
  60520. {
  60521. EXPECT_DECLS;
  60522. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AES_ECB) \
  60523. && !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
  60524. AES_KEY aes;
  60525. const byte msg[] =
  60526. {
  60527. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  60528. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  60529. };
  60530. const byte verify[] =
  60531. {
  60532. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  60533. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  60534. };
  60535. const byte key[] =
  60536. {
  60537. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  60538. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  60539. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  60540. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  60541. };
  60542. byte out[AES_BLOCK_SIZE];
  60543. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &aes), 0);
  60544. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60545. AES_ecb_encrypt(msg, out, &aes, AES_ENCRYPT);
  60546. ExpectIntEQ(XMEMCMP(out, verify, AES_BLOCK_SIZE), 0);
  60547. #ifdef HAVE_AES_DECRYPT
  60548. ExpectIntEQ(AES_set_decrypt_key(key, sizeof(key)*8, &aes), 0);
  60549. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60550. AES_ecb_encrypt(verify, out, &aes, AES_DECRYPT);
  60551. ExpectIntEQ(XMEMCMP(out, msg, AES_BLOCK_SIZE), 0);
  60552. #endif
  60553. /* test bad arguments */
  60554. AES_ecb_encrypt(NULL, out, &aes, AES_DECRYPT);
  60555. AES_ecb_encrypt(verify, NULL, &aes, AES_DECRYPT);
  60556. AES_ecb_encrypt(verify, out, NULL, AES_DECRYPT);
  60557. #endif
  60558. return EXPECT_RESULT();
  60559. }
  60560. static int test_wolfSSL_AES_cbc_encrypt(void)
  60561. {
  60562. EXPECT_DECLS;
  60563. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(OPENSSL_EXTRA) && \
  60564. !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
  60565. AES_KEY aes;
  60566. AES_KEY* aesN = NULL;
  60567. size_t len = 0;
  60568. size_t lenB = 0;
  60569. int keySz0 = 0;
  60570. int keySzN = -1;
  60571. byte out[AES_BLOCK_SIZE] = {0};
  60572. byte* outN = NULL;
  60573. /* Test vectors retrieved from:
  60574. * <begin URL>
  60575. * https://csrc.nist.gov/
  60576. * CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/
  60577. * documents/aes/KAT_AES.zip
  60578. * </end URL>
  60579. */
  60580. const byte* pt128N = NULL;
  60581. byte* key128N = NULL;
  60582. byte* iv128N = NULL;
  60583. byte iv128tmp[AES_BLOCK_SIZE] = {0};
  60584. const byte pt128[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  60585. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
  60586. const byte ct128[] = { 0x87,0x85,0xb1,0xa7,0x5b,0x0f,0x3b,0xd9,
  60587. 0x58,0xdc,0xd0,0xe2,0x93,0x18,0xc5,0x21 };
  60588. const byte iv128[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  60589. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
  60590. byte key128[] = { 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  60591. 0xff,0xff,0xf0,0x00,0x00,0x00,0x00,0x00 };
  60592. len = sizeof(pt128);
  60593. #define STRESS_T(a, b, c, d, e, f, g, h, i) \
  60594. wolfSSL_AES_cbc_encrypt(a, b, c, d, e, f); \
  60595. ExpectIntNE(XMEMCMP(b, g, h), i)
  60596. #define RESET_IV(x, y) XMEMCPY(x, y, AES_BLOCK_SIZE)
  60597. /* Stressing wolfSSL_AES_cbc_encrypt() */
  60598. STRESS_T(pt128N, out, len, &aes, iv128tmp, 1, ct128, AES_BLOCK_SIZE, 0);
  60599. STRESS_T(pt128, out, len, &aes, iv128N, 1, ct128, AES_BLOCK_SIZE, 0);
  60600. wolfSSL_AES_cbc_encrypt(pt128, outN, len, &aes, iv128tmp, AES_ENCRYPT);
  60601. ExpectIntNE(XMEMCMP(out, ct128, AES_BLOCK_SIZE), 0);
  60602. wolfSSL_AES_cbc_encrypt(pt128, out, len, aesN, iv128tmp, AES_ENCRYPT);
  60603. ExpectIntNE(XMEMCMP(out, ct128, AES_BLOCK_SIZE), 0);
  60604. STRESS_T(pt128, out, lenB, &aes, iv128tmp, 1, ct128, AES_BLOCK_SIZE, 0);
  60605. /* Stressing wolfSSL_AES_set_encrypt_key */
  60606. ExpectIntNE(wolfSSL_AES_set_encrypt_key(key128N, sizeof(key128)*8, &aes),0);
  60607. ExpectIntNE(wolfSSL_AES_set_encrypt_key(key128, sizeof(key128)*8, aesN),0);
  60608. ExpectIntNE(wolfSSL_AES_set_encrypt_key(key128, keySz0, &aes), 0);
  60609. ExpectIntNE(wolfSSL_AES_set_encrypt_key(key128, keySzN, &aes), 0);
  60610. /* Stressing wolfSSL_AES_set_decrypt_key */
  60611. ExpectIntNE(wolfSSL_AES_set_decrypt_key(key128N, sizeof(key128)*8, &aes),0);
  60612. ExpectIntNE(wolfSSL_AES_set_decrypt_key(key128N, sizeof(key128)*8, aesN),0);
  60613. ExpectIntNE(wolfSSL_AES_set_decrypt_key(key128, keySz0, &aes), 0);
  60614. ExpectIntNE(wolfSSL_AES_set_decrypt_key(key128, keySzN, &aes), 0);
  60615. #ifdef WOLFSSL_AES_128
  60616. /* wolfSSL_AES_cbc_encrypt() 128-bit */
  60617. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60618. RESET_IV(iv128tmp, iv128);
  60619. ExpectIntEQ(wolfSSL_AES_set_encrypt_key(key128, sizeof(key128)*8, &aes), 0);
  60620. wolfSSL_AES_cbc_encrypt(pt128, out, len, &aes, iv128tmp, AES_ENCRYPT);
  60621. ExpectIntEQ(XMEMCMP(out, ct128, AES_BLOCK_SIZE), 0);
  60622. wc_AesFree((Aes*)&aes);
  60623. #ifdef HAVE_AES_DECRYPT
  60624. /* wolfSSL_AES_cbc_encrypt() 128-bit in decrypt mode */
  60625. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60626. RESET_IV(iv128tmp, iv128);
  60627. len = sizeof(ct128);
  60628. ExpectIntEQ(wolfSSL_AES_set_decrypt_key(key128, sizeof(key128)*8, &aes), 0);
  60629. wolfSSL_AES_cbc_encrypt(ct128, out, len, &aes, iv128tmp, AES_DECRYPT);
  60630. ExpectIntEQ(XMEMCMP(out, pt128, AES_BLOCK_SIZE), 0);
  60631. wc_AesFree((Aes*)&aes);
  60632. #endif
  60633. #endif /* WOLFSSL_AES_128 */
  60634. #ifdef WOLFSSL_AES_192
  60635. {
  60636. /* Test vectors from NIST Special Publication 800-38A, 2001 Edition
  60637. * Appendix F.2.3 */
  60638. byte iv192tmp[AES_BLOCK_SIZE] = {0};
  60639. const byte pt192[] = { 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  60640. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a };
  60641. const byte ct192[] = { 0x4f,0x02,0x1d,0xb2,0x43,0xbc,0x63,0x3d,
  60642. 0x71,0x78,0x18,0x3a,0x9f,0xa0,0x71,0xe8 };
  60643. const byte iv192[] = { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  60644. 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F };
  60645. byte key192[] = { 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  60646. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  60647. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b };
  60648. len = sizeof(pt192);
  60649. /* wolfSSL_AES_cbc_encrypt() 192-bit */
  60650. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60651. RESET_IV(iv192tmp, iv192);
  60652. ExpectIntEQ(wolfSSL_AES_set_encrypt_key(key192, sizeof(key192)*8, &aes), 0);
  60653. wolfSSL_AES_cbc_encrypt(pt192, out, len, &aes, iv192tmp, AES_ENCRYPT);
  60654. ExpectIntEQ(XMEMCMP(out, ct192, AES_BLOCK_SIZE), 0);
  60655. wc_AesFree((Aes*)&aes);
  60656. #ifdef HAVE_AES_DECRYPT
  60657. /* wolfSSL_AES_cbc_encrypt() 192-bit in decrypt mode */
  60658. len = sizeof(ct192);
  60659. RESET_IV(iv192tmp, iv192);
  60660. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60661. ExpectIntEQ(wolfSSL_AES_set_decrypt_key(key192, sizeof(key192)*8, &aes), 0);
  60662. wolfSSL_AES_cbc_encrypt(ct192, out, len, &aes, iv192tmp, AES_DECRYPT);
  60663. ExpectIntEQ(XMEMCMP(out, pt192, AES_BLOCK_SIZE), 0);
  60664. wc_AesFree((Aes*)&aes);
  60665. #endif
  60666. }
  60667. #endif /* WOLFSSL_AES_192 */
  60668. #ifdef WOLFSSL_AES_256
  60669. {
  60670. /* Test vectors from NIST Special Publication 800-38A, 2001 Edition,
  60671. * Appendix F.2.5 */
  60672. byte iv256tmp[AES_BLOCK_SIZE] = {0};
  60673. const byte pt256[] = { 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  60674. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a };
  60675. const byte ct256[] = { 0xf5,0x8c,0x4c,0x04,0xd6,0xe5,0xf1,0xba,
  60676. 0x77,0x9e,0xab,0xfb,0x5f,0x7b,0xfb,0xd6 };
  60677. const byte iv256[] = { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  60678. 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F };
  60679. byte key256[] = { 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  60680. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  60681. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  60682. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4 };
  60683. len = sizeof(pt256);
  60684. /* wolfSSL_AES_cbc_encrypt() 256-bit */
  60685. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60686. RESET_IV(iv256tmp, iv256);
  60687. ExpectIntEQ(wolfSSL_AES_set_encrypt_key(key256, sizeof(key256)*8, &aes), 0);
  60688. wolfSSL_AES_cbc_encrypt(pt256, out, len, &aes, iv256tmp, AES_ENCRYPT);
  60689. ExpectIntEQ(XMEMCMP(out, ct256, AES_BLOCK_SIZE), 0);
  60690. wc_AesFree((Aes*)&aes);
  60691. #ifdef HAVE_AES_DECRYPT
  60692. /* wolfSSL_AES_cbc_encrypt() 256-bit in decrypt mode */
  60693. len = sizeof(ct256);
  60694. RESET_IV(iv256tmp, iv256);
  60695. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60696. ExpectIntEQ(wolfSSL_AES_set_decrypt_key(key256, sizeof(key256)*8, &aes), 0);
  60697. wolfSSL_AES_cbc_encrypt(ct256, out, len, &aes, iv256tmp, AES_DECRYPT);
  60698. ExpectIntEQ(XMEMCMP(out, pt256, AES_BLOCK_SIZE), 0);
  60699. wc_AesFree((Aes*)&aes);
  60700. #endif
  60701. #if defined(HAVE_AES_KEYWRAP) && !defined(HAVE_FIPS) && \
  60702. !defined(HAVE_SELFTEST)
  60703. {
  60704. byte wrapCipher[sizeof(key256) + KEYWRAP_BLOCK_SIZE] = { 0 };
  60705. byte wrapPlain[sizeof(key256)] = { 0 };
  60706. byte wrapIV[KEYWRAP_BLOCK_SIZE] = { 0 };
  60707. /* wolfSSL_AES_wrap_key() 256-bit NULL iv */
  60708. ExpectIntEQ(wolfSSL_AES_set_encrypt_key(key256, sizeof(key256)*8, &aes), 0);
  60709. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, NULL, wrapCipher, key256,
  60710. 15), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  60711. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, NULL, wrapCipher, key256,
  60712. sizeof(key256)), sizeof(wrapCipher));
  60713. wc_AesFree((Aes*)&aes);
  60714. /* wolfSSL_AES_unwrap_key() 256-bit NULL iv */
  60715. ExpectIntEQ(wolfSSL_AES_set_decrypt_key(key256, sizeof(key256)*8, &aes), 0);
  60716. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, NULL, wrapPlain, wrapCipher,
  60717. 23), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  60718. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, NULL, wrapPlain, wrapCipher,
  60719. sizeof(wrapCipher)), sizeof(wrapPlain));
  60720. ExpectIntEQ(XMEMCMP(wrapPlain, key256, sizeof(key256)), 0);
  60721. XMEMSET(wrapCipher, 0, sizeof(wrapCipher));
  60722. XMEMSET(wrapPlain, 0, sizeof(wrapPlain));
  60723. wc_AesFree((Aes*)&aes);
  60724. /* wolfSSL_AES_wrap_key() 256-bit custom iv */
  60725. ExpectIntEQ(wolfSSL_AES_set_encrypt_key(key256, sizeof(key256)*8, &aes), 0);
  60726. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, wrapIV, wrapCipher, key256,
  60727. sizeof(key256)), sizeof(wrapCipher));
  60728. wc_AesFree((Aes*)&aes);
  60729. /* wolfSSL_AES_unwrap_key() 256-bit custom iv */
  60730. ExpectIntEQ(wolfSSL_AES_set_decrypt_key(key256, sizeof(key256)*8, &aes), 0);
  60731. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, wrapIV, wrapPlain, wrapCipher,
  60732. sizeof(wrapCipher)), sizeof(wrapPlain));
  60733. ExpectIntEQ(XMEMCMP(wrapPlain, key256, sizeof(key256)), 0);
  60734. wc_AesFree((Aes*)&aes);
  60735. ExpectIntEQ(wolfSSL_AES_wrap_key(NULL, NULL, NULL, NULL, 0), 0);
  60736. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, NULL, NULL, NULL, 0), 0);
  60737. ExpectIntEQ(wolfSSL_AES_wrap_key(NULL, wrapIV, NULL, NULL, 0), 0);
  60738. ExpectIntEQ(wolfSSL_AES_wrap_key(NULL, NULL, wrapCipher, NULL, 0), 0);
  60739. ExpectIntEQ(wolfSSL_AES_wrap_key(NULL, NULL, NULL, key256, 0), 0);
  60740. ExpectIntEQ(wolfSSL_AES_wrap_key(NULL, wrapIV, wrapCipher, key256, 0), 0);
  60741. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, NULL, wrapCipher, key256, 0), 0);
  60742. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, wrapIV, NULL, key256, 0), 0);
  60743. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, wrapIV, wrapCipher, NULL, 0), 0);
  60744. ExpectIntEQ(wolfSSL_AES_unwrap_key(NULL, NULL, NULL, NULL, 0), 0);
  60745. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, NULL, NULL, NULL, 0), 0);
  60746. ExpectIntEQ(wolfSSL_AES_unwrap_key(NULL, wrapIV, NULL, NULL, 0), 0);
  60747. ExpectIntEQ(wolfSSL_AES_unwrap_key(NULL, NULL, wrapPlain, NULL, 0), 0);
  60748. ExpectIntEQ(wolfSSL_AES_unwrap_key(NULL, NULL, NULL, wrapCipher, 0), 0);
  60749. ExpectIntEQ(wolfSSL_AES_unwrap_key(NULL, wrapIV, wrapPlain, wrapCipher, 0),
  60750. 0);
  60751. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, NULL, wrapPlain, wrapCipher, 0),
  60752. 0);
  60753. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, wrapIV, NULL, wrapCipher, 0), 0);
  60754. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, wrapIV, wrapPlain, NULL, 0), 0);
  60755. }
  60756. #endif /* HAVE_AES_KEYWRAP */
  60757. }
  60758. #endif /* WOLFSSL_AES_256 */
  60759. #endif
  60760. return EXPECT_RESULT();
  60761. }
  60762. static int test_wolfSSL_AES_cfb128_encrypt(void)
  60763. {
  60764. EXPECT_DECLS;
  60765. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(WOLFSSL_AES_CFB) && \
  60766. !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
  60767. AES_KEY aesEnc;
  60768. AES_KEY aesDec;
  60769. const byte msg[] = {
  60770. 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
  60771. 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a
  60772. };
  60773. const byte exp[] = {
  60774. 0x16, 0xc9, 0x90, 0x6c, 0x04, 0x0c, 0xd1, 0x2f,
  60775. 0x84, 0x7b, 0x18, 0xed, 0xed, 0x6a, 0xb5, 0xfd
  60776. };
  60777. const byte key[] = {
  60778. 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
  60779. 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
  60780. 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
  60781. 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4
  60782. };
  60783. const byte ivData[] = {
  60784. 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
  60785. 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
  60786. };
  60787. byte out[AES_BLOCK_SIZE];
  60788. byte iv[AES_BLOCK_SIZE];
  60789. word32 i;
  60790. int num;
  60791. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &aesEnc), 0);
  60792. XMEMCPY(iv, ivData, sizeof(iv));
  60793. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60794. AES_cfb128_encrypt(msg, out, sizeof(msg), &aesEnc, iv, NULL, AES_ENCRYPT);
  60795. ExpectIntEQ(XMEMCMP(out, exp, sizeof(msg)), 0);
  60796. ExpectIntNE(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  60797. #ifdef HAVE_AES_DECRYPT
  60798. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &aesDec), 0);
  60799. XMEMCPY(iv, ivData, sizeof(iv));
  60800. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60801. AES_cfb128_encrypt(exp, out, sizeof(msg), &aesDec, iv, NULL, AES_DECRYPT);
  60802. ExpectIntEQ(XMEMCMP(out, msg, sizeof(msg)), 0);
  60803. ExpectIntNE(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  60804. #endif
  60805. for (i = 0; EXPECT_SUCCESS() && (i <= sizeof(msg)); i++) {
  60806. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &aesEnc), 0);
  60807. XMEMCPY(iv, ivData, sizeof(iv));
  60808. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60809. AES_cfb128_encrypt(msg, out, i, &aesEnc, iv, &num, AES_ENCRYPT);
  60810. ExpectIntEQ(num, i % AES_BLOCK_SIZE);
  60811. ExpectIntEQ(XMEMCMP(out, exp, i), 0);
  60812. if (i == 0) {
  60813. ExpectIntEQ(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  60814. }
  60815. else {
  60816. ExpectIntNE(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  60817. }
  60818. #ifdef HAVE_AES_DECRYPT
  60819. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &aesDec), 0);
  60820. XMEMCPY(iv, ivData, sizeof(iv));
  60821. XMEMSET(out, 0, AES_BLOCK_SIZE);
  60822. AES_cfb128_encrypt(exp, out, i, &aesDec, iv, &num, AES_DECRYPT);
  60823. ExpectIntEQ(num, i % AES_BLOCK_SIZE);
  60824. ExpectIntEQ(XMEMCMP(out, msg, i), 0);
  60825. if (i == 0) {
  60826. ExpectIntEQ(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  60827. }
  60828. else {
  60829. ExpectIntNE(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  60830. }
  60831. #endif
  60832. }
  60833. if (EXPECT_SUCCESS()) {
  60834. /* test bad arguments */
  60835. AES_cfb128_encrypt(NULL, NULL, 0, NULL, NULL, NULL, AES_DECRYPT);
  60836. AES_cfb128_encrypt(msg, NULL, 0, NULL, NULL, NULL, AES_DECRYPT);
  60837. AES_cfb128_encrypt(NULL, out, 0, NULL, NULL, NULL, AES_DECRYPT);
  60838. AES_cfb128_encrypt(NULL, NULL, 0, &aesDec, NULL, NULL, AES_DECRYPT);
  60839. AES_cfb128_encrypt(NULL, NULL, 0, NULL, iv, NULL, AES_DECRYPT);
  60840. AES_cfb128_encrypt(NULL, out, 0, &aesDec, iv, NULL, AES_DECRYPT);
  60841. AES_cfb128_encrypt(msg, NULL, 0, &aesDec, iv, NULL, AES_DECRYPT);
  60842. AES_cfb128_encrypt(msg, out, 0, NULL, iv, NULL, AES_DECRYPT);
  60843. AES_cfb128_encrypt(msg, out, 0, &aesDec, NULL, NULL, AES_DECRYPT);
  60844. }
  60845. #endif
  60846. return EXPECT_RESULT();
  60847. }
  60848. static int test_wolfSSL_CRYPTO_cts128(void)
  60849. {
  60850. EXPECT_DECLS;
  60851. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(OPENSSL_EXTRA) && \
  60852. defined(HAVE_CTS) && !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
  60853. byte tmp[64]; /* Largest vector size */
  60854. /* Test vectors taken form RFC3962 Appendix B */
  60855. const testVector vects[] = {
  60856. {
  60857. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  60858. "\x20",
  60859. "\xc6\x35\x35\x68\xf2\xbf\x8c\xb4\xd8\xa5\x80\x36\x2d\xa7\xff\x7f"
  60860. "\x97",
  60861. 17, 17
  60862. },
  60863. {
  60864. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  60865. "\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20",
  60866. "\xfc\x00\x78\x3e\x0e\xfd\xb2\xc1\xd4\x45\xd4\xc8\xef\xf7\xed\x22"
  60867. "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5",
  60868. 31, 31
  60869. },
  60870. {
  60871. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  60872. "\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20\x43",
  60873. "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5\xa8"
  60874. "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84",
  60875. 32, 32
  60876. },
  60877. {
  60878. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  60879. "\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20\x43"
  60880. "\x68\x69\x63\x6b\x65\x6e\x2c\x20\x70\x6c\x65\x61\x73\x65\x2c",
  60881. "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84"
  60882. "\xb3\xff\xfd\x94\x0c\x16\xa1\x8c\x1b\x55\x49\xd2\xf8\x38\x02\x9e"
  60883. "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5",
  60884. 47, 47
  60885. },
  60886. {
  60887. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  60888. "\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20\x43"
  60889. "\x68\x69\x63\x6b\x65\x6e\x2c\x20\x70\x6c\x65\x61\x73\x65\x2c\x20",
  60890. "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84"
  60891. "\x9d\xad\x8b\xbb\x96\xc4\xcd\xc0\x3b\xc1\x03\xe1\xa1\x94\xbb\xd8"
  60892. "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5\xa8",
  60893. 48, 48
  60894. },
  60895. {
  60896. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  60897. "\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20\x43"
  60898. "\x68\x69\x63\x6b\x65\x6e\x2c\x20\x70\x6c\x65\x61\x73\x65\x2c\x20"
  60899. "\x61\x6e\x64\x20\x77\x6f\x6e\x74\x6f\x6e\x20\x73\x6f\x75\x70\x2e",
  60900. "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84"
  60901. "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5\xa8"
  60902. "\x48\x07\xef\xe8\x36\xee\x89\xa5\x26\x73\x0d\xbc\x2f\x7b\xc8\x40"
  60903. "\x9d\xad\x8b\xbb\x96\xc4\xcd\xc0\x3b\xc1\x03\xe1\xa1\x94\xbb\xd8",
  60904. 64, 64
  60905. }
  60906. };
  60907. byte keyBytes[AES_128_KEY_SIZE] = {
  60908. 0x63, 0x68, 0x69, 0x63, 0x6b, 0x65, 0x6e, 0x20,
  60909. 0x74, 0x65, 0x72, 0x69, 0x79, 0x61, 0x6b, 0x69
  60910. };
  60911. size_t i;
  60912. AES_KEY encKey;
  60913. byte iv[AES_IV_SIZE]; /* All-zero IV for all cases */
  60914. XMEMSET(tmp, 0, sizeof(tmp));
  60915. for (i = 0; i < sizeof(vects)/sizeof(vects[0]); i++) {
  60916. AES_KEY decKey;
  60917. ExpectIntEQ(AES_set_encrypt_key(keyBytes, AES_128_KEY_SIZE * 8,
  60918. &encKey), 0);
  60919. ExpectIntEQ(AES_set_decrypt_key(keyBytes, AES_128_KEY_SIZE * 8,
  60920. &decKey), 0);
  60921. XMEMSET(iv, 0, sizeof(iv));
  60922. ExpectIntEQ(CRYPTO_cts128_encrypt((const unsigned char*)vects[i].input,
  60923. tmp, vects[i].inLen, &encKey, iv, (cbc128_f)AES_cbc_encrypt),
  60924. vects[i].outLen);
  60925. ExpectIntEQ(XMEMCMP(tmp, vects[i].output, vects[i].outLen), 0);
  60926. XMEMSET(iv, 0, sizeof(iv));
  60927. ExpectIntEQ(CRYPTO_cts128_decrypt((const unsigned char*)vects[i].output,
  60928. tmp, vects[i].outLen, &decKey, iv, (cbc128_f)AES_cbc_encrypt),
  60929. vects[i].inLen);
  60930. ExpectIntEQ(XMEMCMP(tmp, vects[i].input, vects[i].inLen), 0);
  60931. }
  60932. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, NULL, 17, NULL, NULL, NULL), 0);
  60933. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, NULL, 17, NULL, NULL, NULL), 0);
  60934. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, tmp, 17, NULL, NULL, NULL), 0);
  60935. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, NULL, 17, &encKey, NULL, NULL), 0);
  60936. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, NULL, 17, NULL, iv, NULL), 0);
  60937. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, NULL, 17, NULL, NULL,
  60938. (cbc128_f)AES_cbc_encrypt), 0);
  60939. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, tmp, 17, &encKey, iv,
  60940. (cbc128_f)AES_cbc_encrypt), 0);
  60941. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, NULL, 17, &encKey, iv,
  60942. (cbc128_f)AES_cbc_encrypt), 0);
  60943. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, tmp, 17, NULL, iv,
  60944. (cbc128_f)AES_cbc_encrypt), 0);
  60945. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, tmp, 17, &encKey, NULL,
  60946. (cbc128_f)AES_cbc_encrypt), 0);
  60947. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, tmp, 17, &encKey, iv, NULL), 0);
  60948. /* Length too small. */
  60949. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, tmp, 0, &encKey, iv,
  60950. (cbc128_f)AES_cbc_encrypt), 0);
  60951. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, NULL, 17, NULL, NULL, NULL), 0);
  60952. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, NULL, 17, NULL, NULL, NULL), 0);
  60953. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, tmp, 17, NULL, NULL, NULL), 0);
  60954. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, NULL, 17, &encKey, NULL, NULL), 0);
  60955. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, NULL, 17, NULL, iv, NULL), 0);
  60956. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, NULL, 17, NULL, NULL,
  60957. (cbc128_f)AES_cbc_encrypt), 0);
  60958. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, tmp, 17, &encKey, iv,
  60959. (cbc128_f)AES_cbc_encrypt), 0);
  60960. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, NULL, 17, &encKey, iv,
  60961. (cbc128_f)AES_cbc_encrypt), 0);
  60962. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, tmp, 17, NULL, iv,
  60963. (cbc128_f)AES_cbc_encrypt), 0);
  60964. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, tmp, 17, &encKey, NULL,
  60965. (cbc128_f)AES_cbc_encrypt), 0);
  60966. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, tmp, 17, &encKey, iv, NULL), 0);
  60967. /* Length too small. */
  60968. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, tmp, 0, &encKey, iv,
  60969. (cbc128_f)AES_cbc_encrypt), 0);
  60970. #endif /* !NO_AES && HAVE_AES_CBC && OPENSSL_EXTRA && HAVE_CTS */
  60971. return EXPECT_RESULT();
  60972. }
  60973. static int test_wolfSSL_RC4(void)
  60974. {
  60975. EXPECT_DECLS;
  60976. #if !defined(NO_RC4) && defined(OPENSSL_EXTRA)
  60977. WOLFSSL_RC4_KEY rc4Key;
  60978. unsigned char key[] = {
  60979. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  60980. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  60981. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  60982. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  60983. };
  60984. unsigned char data[] = {
  60985. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  60986. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  60987. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  60988. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  60989. };
  60990. unsigned char enc[sizeof(data)];
  60991. unsigned char dec[sizeof(data)];
  60992. word32 i;
  60993. word32 j;
  60994. wolfSSL_RC4_set_key(NULL, -1, NULL);
  60995. wolfSSL_RC4_set_key(&rc4Key, -1, NULL);
  60996. wolfSSL_RC4_set_key(NULL, 0, NULL);
  60997. wolfSSL_RC4_set_key(NULL, -1, key);
  60998. wolfSSL_RC4_set_key(&rc4Key, 0, NULL);
  60999. wolfSSL_RC4_set_key(&rc4Key, -1, key);
  61000. wolfSSL_RC4_set_key(NULL, 0, key);
  61001. wolfSSL_RC4(NULL, 0, NULL, NULL);
  61002. wolfSSL_RC4(&rc4Key, 0, NULL, NULL);
  61003. wolfSSL_RC4(NULL, 0, data, NULL);
  61004. wolfSSL_RC4(NULL, 0, NULL, enc);
  61005. wolfSSL_RC4(&rc4Key, 0, data, NULL);
  61006. wolfSSL_RC4(&rc4Key, 0, NULL, enc);
  61007. wolfSSL_RC4(NULL, 0, data, enc);
  61008. ExpectIntEQ(1, 1);
  61009. for (i = 0; EXPECT_SUCCESS() && (i <= sizeof(key)); i++) {
  61010. for (j = 0; EXPECT_SUCCESS() && (j <= sizeof(data)); j++) {
  61011. XMEMSET(enc, 0, sizeof(enc));
  61012. XMEMSET(dec, 0, sizeof(dec));
  61013. /* Encrypt */
  61014. wolfSSL_RC4_set_key(&rc4Key, (int)i, key);
  61015. wolfSSL_RC4(&rc4Key, j, data, enc);
  61016. /* Decrypt */
  61017. wolfSSL_RC4_set_key(&rc4Key, (int)i, key);
  61018. wolfSSL_RC4(&rc4Key, j, enc, dec);
  61019. ExpectIntEQ(XMEMCMP(dec, data, j), 0);
  61020. }
  61021. }
  61022. #endif
  61023. return EXPECT_RESULT();
  61024. }
  61025. static int test_wolfSSL_OBJ(void)
  61026. {
  61027. /* Password "wolfSSL test" is only 12 (96-bit) too short for testing in FIPS
  61028. * mode
  61029. */
  61030. EXPECT_DECLS;
  61031. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA256) && !defined(NO_ASN) && \
  61032. !defined(HAVE_FIPS) && !defined(NO_SHA) && defined(WOLFSSL_CERT_EXT) && \
  61033. defined(WOLFSSL_CERT_GEN) && !defined(NO_BIO) && \
  61034. !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM)
  61035. ASN1_OBJECT *obj = NULL;
  61036. ASN1_OBJECT *obj2 = NULL;
  61037. char buf[50];
  61038. XFILE fp = XBADFILE;
  61039. X509 *x509 = NULL;
  61040. X509_NAME *x509Name = NULL;
  61041. X509_NAME_ENTRY *x509NameEntry = NULL;
  61042. ASN1_OBJECT *asn1Name = NULL;
  61043. int numNames = 0;
  61044. BIO *bio = NULL;
  61045. int nid;
  61046. int i, j;
  61047. const char *f[] = {
  61048. #ifndef NO_RSA
  61049. "./certs/ca-cert.der",
  61050. #endif
  61051. #ifdef HAVE_ECC
  61052. "./certs/ca-ecc-cert.der",
  61053. "./certs/ca-ecc384-cert.der",
  61054. #endif
  61055. NULL};
  61056. ASN1_OBJECT *field_name_obj = NULL;
  61057. int lastpos = -1;
  61058. int tmp = -1;
  61059. ASN1_STRING *asn1 = NULL;
  61060. unsigned char *buf_dyn = NULL;
  61061. ExpectIntEQ(OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  61062. ExpectNotNull(obj = OBJ_nid2obj(NID_any_policy));
  61063. ExpectIntEQ(OBJ_obj2nid(obj), NID_any_policy);
  61064. ExpectIntEQ(OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1), 11);
  61065. ExpectIntGT(OBJ_obj2txt(buf, (int)sizeof(buf), obj, 0), 0);
  61066. ASN1_OBJECT_free(obj);
  61067. obj = NULL;
  61068. ExpectNotNull(obj = OBJ_nid2obj(NID_sha256));
  61069. ExpectIntEQ(OBJ_obj2nid(obj), NID_sha256);
  61070. ExpectIntEQ(OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1), 22);
  61071. #ifdef WOLFSSL_CERT_EXT
  61072. ExpectIntEQ(OBJ_txt2nid(buf), NID_sha256);
  61073. #endif
  61074. ExpectIntGT(OBJ_obj2txt(buf, (int)sizeof(buf), obj, 0), 0);
  61075. ExpectNotNull(obj2 = OBJ_dup(obj));
  61076. ExpectIntEQ(OBJ_cmp(obj, obj2), 0);
  61077. ASN1_OBJECT_free(obj);
  61078. obj = NULL;
  61079. ASN1_OBJECT_free(obj2);
  61080. obj2 = NULL;
  61081. for (i = 0; f[i] != NULL; i++)
  61082. {
  61083. ExpectTrue((fp = XFOPEN(f[i], "rb")) != XBADFILE);
  61084. ExpectNotNull(x509 = d2i_X509_fp(fp, NULL));
  61085. if (fp != XBADFILE) {
  61086. XFCLOSE(fp);
  61087. fp = XBADFILE;
  61088. }
  61089. ExpectNotNull(x509Name = X509_get_issuer_name(x509));
  61090. ExpectIntNE((numNames = X509_NAME_entry_count(x509Name)), 0);
  61091. /* Get the Common Name by using OBJ_txt2obj */
  61092. ExpectNotNull(field_name_obj = OBJ_txt2obj("CN", 0));
  61093. do
  61094. {
  61095. lastpos = tmp;
  61096. tmp = X509_NAME_get_index_by_OBJ(x509Name, field_name_obj, lastpos);
  61097. } while (tmp > -1);
  61098. ExpectIntNE(lastpos, -1);
  61099. ASN1_OBJECT_free(field_name_obj);
  61100. field_name_obj = NULL;
  61101. ExpectNotNull(x509NameEntry = X509_NAME_get_entry(x509Name, lastpos));
  61102. ExpectNotNull(asn1 = X509_NAME_ENTRY_get_data(x509NameEntry));
  61103. ExpectIntGE(ASN1_STRING_to_UTF8(&buf_dyn, asn1), 0);
  61104. /*
  61105. * All Common Names should be www.wolfssl.com
  61106. * This makes testing easier as we can test for the expected value.
  61107. */
  61108. ExpectStrEQ((char*)buf_dyn, "www.wolfssl.com");
  61109. OPENSSL_free(buf_dyn);
  61110. buf_dyn = NULL;
  61111. bio = BIO_new(BIO_s_mem());
  61112. ExpectTrue(bio != NULL);
  61113. for (j = 0; j < numNames; j++)
  61114. {
  61115. ExpectNotNull(x509NameEntry = X509_NAME_get_entry(x509Name, j));
  61116. ExpectNotNull(asn1Name = X509_NAME_ENTRY_get_object(x509NameEntry));
  61117. ExpectTrue((nid = OBJ_obj2nid(asn1Name)) > 0);
  61118. }
  61119. BIO_free(bio);
  61120. bio = NULL;
  61121. X509_free(x509);
  61122. x509 = NULL;
  61123. }
  61124. #ifdef HAVE_PKCS12
  61125. {
  61126. PKCS12 *p12 = NULL;
  61127. int boolRet;
  61128. EVP_PKEY *pkey = NULL;
  61129. const char *p12_f[] = {
  61130. #if !defined(NO_DES3) && !defined(NO_RSA)
  61131. "./certs/test-servercert.p12",
  61132. #endif
  61133. NULL};
  61134. for (i = 0; p12_f[i] != NULL; i++)
  61135. {
  61136. ExpectTrue((fp = XFOPEN(p12_f[i], "rb")) != XBADFILE);
  61137. ExpectNotNull(p12 = d2i_PKCS12_fp(fp, NULL));
  61138. if (fp != XBADFILE) {
  61139. XFCLOSE(fp);
  61140. fp = XBADFILE;
  61141. }
  61142. ExpectTrue((boolRet = PKCS12_parse(p12, "wolfSSL test",
  61143. &pkey, &x509, NULL)) > 0);
  61144. wc_PKCS12_free(p12);
  61145. p12 = NULL;
  61146. EVP_PKEY_free(pkey);
  61147. x509Name = X509_get_issuer_name(x509);
  61148. ExpectNotNull(x509Name);
  61149. ExpectIntNE((numNames = X509_NAME_entry_count(x509Name)), 0);
  61150. ExpectTrue((bio = BIO_new(BIO_s_mem())) != NULL);
  61151. for (j = 0; j < numNames; j++)
  61152. {
  61153. ExpectNotNull(x509NameEntry = X509_NAME_get_entry(x509Name, j));
  61154. ExpectNotNull(asn1Name =
  61155. X509_NAME_ENTRY_get_object(x509NameEntry));
  61156. ExpectTrue((nid = OBJ_obj2nid(asn1Name)) > 0);
  61157. }
  61158. BIO_free(bio);
  61159. bio = NULL;
  61160. X509_free(x509);
  61161. x509 = NULL;
  61162. }
  61163. }
  61164. #endif /* HAVE_PKCS12 */
  61165. #endif
  61166. return EXPECT_RESULT();
  61167. }
  61168. static int test_wolfSSL_OBJ_cmp(void)
  61169. {
  61170. EXPECT_DECLS;
  61171. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA256)
  61172. ASN1_OBJECT *obj = NULL;
  61173. ASN1_OBJECT *obj2 = NULL;
  61174. ExpectNotNull(obj = OBJ_nid2obj(NID_any_policy));
  61175. ExpectNotNull(obj2 = OBJ_nid2obj(NID_sha256));
  61176. ExpectIntEQ(OBJ_cmp(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  61177. ExpectIntEQ(OBJ_cmp(obj, NULL), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  61178. ExpectIntEQ(OBJ_cmp(NULL, obj2), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  61179. ExpectIntEQ(OBJ_cmp(obj, obj2), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  61180. ExpectIntEQ(OBJ_cmp(obj, obj), 0);
  61181. ExpectIntEQ(OBJ_cmp(obj2, obj2), 0);
  61182. ASN1_OBJECT_free(obj);
  61183. ASN1_OBJECT_free(obj2);
  61184. #endif
  61185. return EXPECT_RESULT();
  61186. }
  61187. static int test_wolfSSL_OBJ_txt2nid(void)
  61188. {
  61189. EXPECT_DECLS;
  61190. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
  61191. defined(WOLFSSL_APACHE_HTTPD)
  61192. int i;
  61193. static const struct {
  61194. const char* sn;
  61195. const char* ln;
  61196. const char* oid;
  61197. int nid;
  61198. } testVals[] = {
  61199. #ifdef WOLFSSL_APACHE_HTTPD
  61200. { "tlsfeature", "TLS Feature", "1.3.6.1.5.5.7.1.24", NID_tlsfeature },
  61201. { "id-on-dnsSRV", "SRVName", "1.3.6.1.5.5.7.8.7",
  61202. NID_id_on_dnsSRV },
  61203. { "msUPN", "Microsoft User Principal Name",
  61204. "1.3.6.1.4.1.311.20.2.3", NID_ms_upn },
  61205. #endif
  61206. { NULL, NULL, NULL, NID_undef }
  61207. };
  61208. /* Invalid cases */
  61209. ExpectIntEQ(OBJ_txt2nid(NULL), NID_undef);
  61210. ExpectIntEQ(OBJ_txt2nid("Bad name"), NID_undef);
  61211. /* Valid cases */
  61212. for (i = 0; testVals[i].sn != NULL; i++) {
  61213. ExpectIntEQ(OBJ_txt2nid(testVals[i].sn), testVals[i].nid);
  61214. ExpectIntEQ(OBJ_txt2nid(testVals[i].ln), testVals[i].nid);
  61215. ExpectIntEQ(OBJ_txt2nid(testVals[i].oid), testVals[i].nid);
  61216. }
  61217. #endif
  61218. return EXPECT_RESULT();
  61219. }
  61220. static int test_wolfSSL_OBJ_txt2obj(void)
  61221. {
  61222. EXPECT_DECLS;
  61223. #if defined(WOLFSSL_APACHE_HTTPD) || (defined(OPENSSL_EXTRA) && \
  61224. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN))
  61225. int i;
  61226. char buf[50];
  61227. ASN1_OBJECT* obj = NULL;
  61228. static const struct {
  61229. const char* oidStr;
  61230. const char* sn;
  61231. const char* ln;
  61232. } objs_list[] = {
  61233. #if defined(WOLFSSL_APACHE_HTTPD)
  61234. { "1.3.6.1.5.5.7.1.24", "tlsfeature", "TLS Feature" },
  61235. { "1.3.6.1.5.5.7.8.7", "id-on-dnsSRV", "SRVName" },
  61236. #endif
  61237. { "2.5.29.19", "basicConstraints", "X509v3 Basic Constraints"},
  61238. { NULL, NULL, NULL }
  61239. };
  61240. static const struct {
  61241. const char* numeric;
  61242. const char* name;
  61243. } objs_named[] = {
  61244. /* In dictionary but not in normal list. */
  61245. { "1.3.6.1.5.5.7.3.8", "Time Stamping" },
  61246. /* Made up OID. */
  61247. { "1.3.5.7", "1.3.5.7" },
  61248. { NULL, NULL }
  61249. };
  61250. ExpectNull(obj = OBJ_txt2obj("Bad name", 0));
  61251. ASN1_OBJECT_free(obj);
  61252. obj = NULL;
  61253. ExpectNull(obj = OBJ_txt2obj(NULL, 0));
  61254. ASN1_OBJECT_free(obj);
  61255. obj = NULL;
  61256. for (i = 0; objs_list[i].oidStr != NULL; i++) {
  61257. /* Test numerical value of oid (oidStr) */
  61258. ExpectNotNull(obj = OBJ_txt2obj(objs_list[i].oidStr, 1));
  61259. /* Convert object back to text to confirm oid is correct */
  61260. wolfSSL_OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1);
  61261. ExpectIntEQ(XSTRNCMP(buf, objs_list[i].oidStr, (int)XSTRLEN(buf)), 0);
  61262. ASN1_OBJECT_free(obj);
  61263. obj = NULL;
  61264. XMEMSET(buf, 0, sizeof(buf));
  61265. /* Test short name (sn) */
  61266. ExpectNull(obj = OBJ_txt2obj(objs_list[i].sn, 1));
  61267. ExpectNotNull(obj = OBJ_txt2obj(objs_list[i].sn, 0));
  61268. /* Convert object back to text to confirm oid is correct */
  61269. wolfSSL_OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1);
  61270. ExpectIntEQ(XSTRNCMP(buf, objs_list[i].oidStr, (int)XSTRLEN(buf)), 0);
  61271. ASN1_OBJECT_free(obj);
  61272. obj = NULL;
  61273. XMEMSET(buf, 0, sizeof(buf));
  61274. /* Test long name (ln) - should fail when no_name = 1 */
  61275. ExpectNull(obj = OBJ_txt2obj(objs_list[i].ln, 1));
  61276. ExpectNotNull(obj = OBJ_txt2obj(objs_list[i].ln, 0));
  61277. /* Convert object back to text to confirm oid is correct */
  61278. wolfSSL_OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1);
  61279. ExpectIntEQ(XSTRNCMP(buf, objs_list[i].oidStr, (int)XSTRLEN(buf)), 0);
  61280. ASN1_OBJECT_free(obj);
  61281. obj = NULL;
  61282. XMEMSET(buf, 0, sizeof(buf));
  61283. }
  61284. for (i = 0; objs_named[i].numeric != NULL; i++) {
  61285. ExpectNotNull(obj = OBJ_txt2obj(objs_named[i].numeric, 1));
  61286. wolfSSL_OBJ_obj2txt(buf, (int)sizeof(buf), obj, 0);
  61287. ExpectIntEQ(XSTRNCMP(buf, objs_named[i].name, (int)XSTRLEN(buf)), 0);
  61288. wolfSSL_OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1);
  61289. ExpectIntEQ(XSTRNCMP(buf, objs_named[i].numeric, (int)XSTRLEN(buf)), 0);
  61290. ASN1_OBJECT_free(obj);
  61291. obj = NULL;
  61292. }
  61293. #endif
  61294. return EXPECT_RESULT();
  61295. }
  61296. static int test_wolfSSL_PEM_write_bio_X509(void)
  61297. {
  61298. EXPECT_DECLS;
  61299. #if defined(OPENSSL_EXTRA) && defined(OPENSSL_ALL) && \
  61300. defined(WOLFSSL_AKID_NAME) && defined(WOLFSSL_CERT_EXT) && \
  61301. defined(WOLFSSL_CERT_GEN) && !defined(NO_BIO) && !defined(NO_RSA) && \
  61302. !defined(NO_FILESYSTEM)
  61303. /* This test contains the hard coded expected
  61304. * lengths. Update if necessary */
  61305. XFILE fp = XBADFILE;
  61306. WOLFSSL_EVP_PKEY *priv = NULL;
  61307. BIO* input = NULL;
  61308. BIO* output = NULL;
  61309. X509* x509a = NULL;
  61310. X509* x509b = NULL;
  61311. ASN1_TIME* notBeforeA = NULL;
  61312. ASN1_TIME* notAfterA = NULL;
  61313. #ifndef NO_ASN_TIME
  61314. ASN1_TIME* notBeforeB = NULL;
  61315. ASN1_TIME* notAfterB = NULL;
  61316. #endif
  61317. int expectedLen;
  61318. ExpectTrue((fp = XFOPEN("certs/server-key.pem", "rb")) != XBADFILE);
  61319. ExpectNotNull(priv = wolfSSL_PEM_read_PrivateKey(fp, NULL, NULL, NULL));
  61320. if (fp != XBADFILE) {
  61321. XFCLOSE(fp);
  61322. fp = XBADFILE;
  61323. }
  61324. ExpectNotNull(input = BIO_new_file("certs/test/cert-ext-multiple.pem",
  61325. "rb"));
  61326. ExpectIntEQ(wolfSSL_BIO_get_len(input), 2000);
  61327. /* read PEM into X509 struct, get notBefore / notAfter to verify against */
  61328. ExpectNotNull(PEM_read_bio_X509(input, &x509a, NULL, NULL));
  61329. ExpectNotNull(notBeforeA = X509_get_notBefore(x509a));
  61330. ExpectNotNull(notAfterA = X509_get_notAfter(x509a));
  61331. /* write X509 back to PEM BIO; no need to sign as nothing changed. */
  61332. ExpectNotNull(output = BIO_new(wolfSSL_BIO_s_mem()));
  61333. ExpectIntEQ(PEM_write_bio_X509(output, x509a), WOLFSSL_SUCCESS);
  61334. /* compare length against expected */
  61335. expectedLen = 2000;
  61336. ExpectIntEQ(wolfSSL_BIO_get_len(output), expectedLen);
  61337. #ifndef NO_ASN_TIME
  61338. /* read exported X509 PEM back into struct, sanity check on export,
  61339. * make sure notBefore/notAfter are the same and certs are identical. */
  61340. ExpectNotNull(PEM_read_bio_X509(output, &x509b, NULL, NULL));
  61341. ExpectNotNull(notBeforeB = X509_get_notBefore(x509b));
  61342. ExpectNotNull(notAfterB = X509_get_notAfter(x509b));
  61343. ExpectIntEQ(ASN1_TIME_compare(notBeforeA, notBeforeB), 0);
  61344. ExpectIntEQ(ASN1_TIME_compare(notAfterA, notAfterB), 0);
  61345. ExpectIntEQ(0, wolfSSL_X509_cmp(x509a, x509b));
  61346. X509_free(x509b);
  61347. x509b = NULL;
  61348. #endif
  61349. /* Reset output buffer */
  61350. BIO_free(output);
  61351. output = NULL;
  61352. ExpectNotNull(output = BIO_new(wolfSSL_BIO_s_mem()));
  61353. /* Test forcing the AKID to be generated just from KeyIdentifier */
  61354. if (EXPECT_SUCCESS() && x509a->authKeyIdSrc != NULL) {
  61355. XMEMMOVE(x509a->authKeyIdSrc, x509a->authKeyId, x509a->authKeyIdSz);
  61356. x509a->authKeyId = x509a->authKeyIdSrc;
  61357. x509a->authKeyIdSrc = NULL;
  61358. x509a->authKeyIdSrcSz = 0;
  61359. }
  61360. /* Resign to re-generate the der */
  61361. ExpectIntGT(wolfSSL_X509_sign(x509a, priv, EVP_sha256()), 0);
  61362. ExpectIntEQ(PEM_write_bio_X509(output, x509a), WOLFSSL_SUCCESS);
  61363. /* Check that we generate a smaller output since the AKID will
  61364. * only contain the KeyIdentifier without any additional
  61365. * information */
  61366. /* Here we copy the validity struct from the original */
  61367. expectedLen = 1688;
  61368. ExpectIntEQ(wolfSSL_BIO_get_len(output), expectedLen);
  61369. /* Reset buffers and x509 */
  61370. BIO_free(input);
  61371. input = NULL;
  61372. BIO_free(output);
  61373. output = NULL;
  61374. X509_free(x509a);
  61375. x509a = NULL;
  61376. /* test CA and basicConstSet values are encoded when
  61377. * the cert is a CA */
  61378. ExpectNotNull(input = BIO_new_file("certs/server-cert.pem", "rb"));
  61379. /* read PEM into X509 struct */
  61380. ExpectNotNull(PEM_read_bio_X509(input, &x509a, NULL, NULL));
  61381. /* write X509 back to PEM BIO; no need to sign as nothing changed */
  61382. ExpectNotNull(output = BIO_new(wolfSSL_BIO_s_mem()));
  61383. ExpectIntEQ(PEM_write_bio_X509(output, x509a), WOLFSSL_SUCCESS);
  61384. /* read exported X509 PEM back into struct, ensure isCa and basicConstSet
  61385. * values are maintained and certs are identical.*/
  61386. ExpectNotNull(PEM_read_bio_X509(output, &x509b, NULL, NULL));
  61387. ExpectIntEQ(x509b->isCa, 1);
  61388. ExpectIntEQ(x509b->basicConstSet, 1);
  61389. ExpectIntEQ(0, wolfSSL_X509_cmp(x509a, x509b));
  61390. X509_free(x509a);
  61391. x509a = NULL;
  61392. X509_free(x509b);
  61393. x509b = NULL;
  61394. BIO_free(input);
  61395. input = NULL;
  61396. BIO_free(output);
  61397. output = NULL;
  61398. /* test CA and basicConstSet values are encoded when
  61399. * the cert is not CA */
  61400. ExpectNotNull(input = BIO_new_file("certs/client-uri-cert.pem", "rb"));
  61401. /* read PEM into X509 struct */
  61402. ExpectNotNull(PEM_read_bio_X509(input, &x509a, NULL, NULL));
  61403. /* write X509 back to PEM BIO; no need to sign as nothing changed */
  61404. ExpectNotNull(output = BIO_new(wolfSSL_BIO_s_mem()));
  61405. ExpectIntEQ(PEM_write_bio_X509(output, x509a), WOLFSSL_SUCCESS);
  61406. /* read exported X509 PEM back into struct, ensure isCa and
  61407. * basicConstSet values are maintained and certs are identical */
  61408. ExpectNotNull(PEM_read_bio_X509(output, &x509b, NULL, NULL));
  61409. ExpectIntEQ(x509b->isCa, 0);
  61410. ExpectIntEQ(x509b->basicConstSet, 1);
  61411. ExpectIntEQ(0, wolfSSL_X509_cmp(x509a, x509b));
  61412. wolfSSL_EVP_PKEY_free(priv);
  61413. X509_free(x509a);
  61414. X509_free(x509b);
  61415. BIO_free(input);
  61416. BIO_free(output);
  61417. #endif
  61418. return EXPECT_RESULT();
  61419. }
  61420. static int test_wolfSSL_X509_NAME_ENTRY(void)
  61421. {
  61422. EXPECT_DECLS;
  61423. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  61424. !defined(NO_RSA) && defined(WOLFSSL_CERT_GEN)
  61425. X509* x509 = NULL;
  61426. #ifndef NO_BIO
  61427. BIO* bio = NULL;
  61428. #endif
  61429. X509_NAME* nm = NULL;
  61430. X509_NAME_ENTRY* entry = NULL;
  61431. unsigned char cn[] = "another name to add";
  61432. #ifdef OPENSSL_ALL
  61433. int i;
  61434. int names_len = 0;
  61435. #endif
  61436. ExpectNotNull(x509 =
  61437. wolfSSL_X509_load_certificate_file(cliCertFile, SSL_FILETYPE_PEM));
  61438. #ifndef NO_BIO
  61439. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  61440. ExpectIntEQ(PEM_write_bio_X509_AUX(bio, x509), SSL_SUCCESS);
  61441. #endif
  61442. #ifdef WOLFSSL_CERT_REQ
  61443. {
  61444. X509_REQ* req = NULL;
  61445. #ifndef NO_BIO
  61446. BIO* bReq = NULL;
  61447. #endif
  61448. ExpectNotNull(req =
  61449. wolfSSL_X509_load_certificate_file(cliCertFile, SSL_FILETYPE_PEM));
  61450. #ifndef NO_BIO
  61451. ExpectNotNull(bReq = BIO_new(BIO_s_mem()));
  61452. ExpectIntEQ(PEM_write_bio_X509_REQ(bReq, req), SSL_SUCCESS);
  61453. BIO_free(bReq);
  61454. #endif
  61455. X509_free(req);
  61456. }
  61457. #endif
  61458. ExpectNotNull(nm = X509_get_subject_name(x509));
  61459. /* Test add entry */
  61460. ExpectNotNull(entry = X509_NAME_ENTRY_create_by_NID(NULL, NID_commonName,
  61461. 0x0c, cn, (int)sizeof(cn)));
  61462. ExpectIntEQ(X509_NAME_add_entry(nm, entry, -1, 0), SSL_SUCCESS);
  61463. #ifdef WOLFSSL_CERT_EXT
  61464. ExpectIntEQ(X509_NAME_add_entry_by_txt(nm, "emailAddress", MBSTRING_UTF8,
  61465. (byte*)"support@wolfssl.com", 19, -1,
  61466. 1), WOLFSSL_SUCCESS);
  61467. #endif
  61468. X509_NAME_ENTRY_free(entry);
  61469. entry = NULL;
  61470. #ifdef WOLFSSL_CERT_REQ
  61471. {
  61472. unsigned char srv_pkcs9p[] = "Server";
  61473. unsigned char fvrtDrnk[] = "tequila";
  61474. unsigned char* der = NULL;
  61475. char* subject = NULL;
  61476. ExpectIntEQ(X509_NAME_add_entry_by_NID(nm, NID_pkcs9_contentType,
  61477. MBSTRING_ASC, srv_pkcs9p, -1, -1, 0), SSL_SUCCESS);
  61478. ExpectIntEQ(X509_NAME_add_entry_by_NID(nm, NID_favouriteDrink,
  61479. MBSTRING_ASC, fvrtDrnk, -1, -1, 0), SSL_SUCCESS);
  61480. ExpectIntGT(wolfSSL_i2d_X509_NAME(nm, &der), 0);
  61481. ExpectNotNull(der);
  61482. ExpectNotNull(subject = X509_NAME_oneline(nm, 0, 0));
  61483. ExpectNotNull(XSTRSTR(subject, "favouriteDrink=tequila"));
  61484. ExpectNotNull(XSTRSTR(subject, "contentType=Server"));
  61485. #ifdef DEBUG_WOLFSSL
  61486. if (subject != NULL) {
  61487. fprintf(stderr, "\n\t%s\n", subject);
  61488. }
  61489. #endif
  61490. XFREE(subject, 0, DYNAMIC_TYPE_OPENSSL);
  61491. XFREE(der, NULL, DYNAMIC_TYPE_OPENSSL);
  61492. }
  61493. #endif
  61494. /* Test add entry by text */
  61495. ExpectNotNull(entry = X509_NAME_ENTRY_create_by_txt(NULL, "commonName",
  61496. 0x0c, cn, (int)sizeof(cn)));
  61497. #if defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO) \
  61498. || defined(WOLFSSL_HAPROXY) || defined(WOLFSSL_NGINX)
  61499. ExpectNull(X509_NAME_ENTRY_create_by_txt(&entry, "unknown",
  61500. V_ASN1_UTF8STRING, cn, (int)sizeof(cn)));
  61501. #endif
  61502. ExpectIntEQ(X509_NAME_add_entry(nm, entry, -1, 0), SSL_SUCCESS);
  61503. X509_NAME_ENTRY_free(entry);
  61504. entry = NULL;
  61505. /* Test add entry by NID */
  61506. ExpectIntEQ(X509_NAME_add_entry_by_NID(nm, NID_commonName, MBSTRING_UTF8,
  61507. cn, -1, -1, 0), SSL_SUCCESS);
  61508. #ifdef OPENSSL_ALL
  61509. /* stack of name entry */
  61510. ExpectIntGT((names_len = sk_X509_NAME_ENTRY_num(nm->entries)), 0);
  61511. for (i = 0; i < names_len; i++) {
  61512. ExpectNotNull(entry = sk_X509_NAME_ENTRY_value(nm->entries, i));
  61513. }
  61514. #endif
  61515. #ifndef NO_BIO
  61516. BIO_free(bio);
  61517. #endif
  61518. X509_free(x509); /* free's nm */
  61519. #endif
  61520. return EXPECT_RESULT();
  61521. }
  61522. /* Note the lack of wolfSSL_ prefix...this is a compatibility layer test. */
  61523. static int test_GENERAL_NAME_set0_othername(void) {
  61524. EXPECT_DECLS;
  61525. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  61526. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && \
  61527. defined(WOLFSSL_CUSTOM_OID) && defined(WOLFSSL_ALT_NAMES) && \
  61528. defined(WOLFSSL_CERT_EXT) && !defined(NO_FILESYSTEM) && \
  61529. defined(WOLFSSL_FPKI)
  61530. /* ./configure --enable-opensslall --enable-certgen --enable-certreq
  61531. * --enable-certext --enable-debug 'CPPFLAGS=-DWOLFSSL_CUSTOM_OID
  61532. * -DWOLFSSL_ALT_NAMES -DWOLFSSL_FPKI' */
  61533. const char * cert_fname = "./certs/server-cert.der";
  61534. const char * key_fname = "./certs/server-key.der";
  61535. X509* x509 = NULL;
  61536. GENERAL_NAME* gn = NULL;
  61537. GENERAL_NAMES* gns = NULL;
  61538. ASN1_OBJECT* upn_oid = NULL;
  61539. ASN1_UTF8STRING *utf8str = NULL;
  61540. ASN1_TYPE *value = NULL;
  61541. X509_EXTENSION * ext = NULL;
  61542. byte* pt = NULL;
  61543. byte der[4096];
  61544. int derSz = 0;
  61545. EVP_PKEY* priv = NULL;
  61546. XFILE f = XBADFILE;
  61547. ExpectTrue((f = XFOPEN(cert_fname, "rb")) != XBADFILE);
  61548. ExpectNotNull(x509 = d2i_X509_fp(f, NULL));
  61549. if (f != XBADFILE) {
  61550. XFCLOSE(f);
  61551. f = XBADFILE;
  61552. }
  61553. ExpectNotNull(gn = GENERAL_NAME_new());
  61554. ExpectNotNull(upn_oid = OBJ_txt2obj("1.3.6.1.4.1.311.20.2.3", 1));
  61555. ExpectNotNull(utf8str = ASN1_UTF8STRING_new());
  61556. ExpectIntEQ(ASN1_STRING_set(utf8str, "othername@wolfssl.com", -1), 1);
  61557. ExpectNotNull(value = ASN1_TYPE_new());
  61558. ASN1_TYPE_set(value, V_ASN1_UTF8STRING, utf8str);
  61559. if ((value == NULL) || (value->value.ptr != (char*)utf8str)) {
  61560. wolfSSL_ASN1_STRING_free(utf8str);
  61561. }
  61562. ExpectIntEQ(GENERAL_NAME_set0_othername(gn, upn_oid, value), 1);
  61563. if (EXPECT_FAIL()) {
  61564. ASN1_TYPE_free(value);
  61565. }
  61566. ExpectNotNull(gns = sk_GENERAL_NAME_new(NULL));
  61567. ExpectIntEQ(sk_GENERAL_NAME_push(gns, gn), 1);
  61568. if (EXPECT_FAIL()) {
  61569. GENERAL_NAME_free(gn);
  61570. gn = NULL;
  61571. }
  61572. ExpectNotNull(ext = X509V3_EXT_i2d(NID_subject_alt_name, 0, gns));
  61573. ExpectIntEQ(X509_add_ext(x509, ext, -1), 1);
  61574. ExpectTrue((f = XFOPEN(key_fname, "rb")) != XBADFILE);
  61575. ExpectIntGT(derSz = (int)XFREAD(der, 1, sizeof(der), f), 0);
  61576. if (f != XBADFILE) {
  61577. XFCLOSE(f);
  61578. f = XBADFILE;
  61579. }
  61580. pt = der;
  61581. ExpectNotNull(priv = d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  61582. (const unsigned char**)&pt, derSz));
  61583. ExpectIntGT(X509_sign(x509, priv, EVP_sha256()), 0);
  61584. sk_GENERAL_NAME_pop_free(gns, GENERAL_NAME_free);
  61585. gns = NULL;
  61586. ExpectNotNull(gns = (GENERAL_NAMES*)X509_get_ext_d2i(x509,
  61587. NID_subject_alt_name, NULL, NULL));
  61588. ExpectIntEQ(sk_GENERAL_NAME_num(gns), 3);
  61589. ExpectNotNull(gn = sk_GENERAL_NAME_value(gns, 2));
  61590. ExpectIntEQ(gn->type, 0);
  61591. sk_GENERAL_NAME_pop_free(gns, GENERAL_NAME_free);
  61592. ASN1_OBJECT_free(upn_oid);
  61593. X509_EXTENSION_free(ext);
  61594. X509_free(x509);
  61595. EVP_PKEY_free(priv);
  61596. #endif
  61597. return EXPECT_RESULT();
  61598. }
  61599. /* Note the lack of wolfSSL_ prefix...this is a compatibility layer test. */
  61600. static int test_othername_and_SID_ext(void) {
  61601. EXPECT_DECLS;
  61602. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  61603. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && \
  61604. defined(WOLFSSL_CUSTOM_OID) && defined(WOLFSSL_ALT_NAMES) && \
  61605. defined(WOLFSSL_CERT_EXT) && !defined(NO_FILESYSTEM) && \
  61606. defined(WOLFSSL_FPKI) && defined(WOLFSSL_ASN_TEMPLATE)
  61607. /* ./configure --enable-opensslall --enable-certgen --enable-certreq
  61608. * --enable-certext --enable-debug 'CPPFLAGS=-DWOLFSSL_CUSTOM_OID
  61609. * -DWOLFSSL_ALT_NAMES -DWOLFSSL_FPKI' */
  61610. const char* csr_fname = "./certs/csr.signed.der";
  61611. const char* key_fname = "./certs/server-key.der";
  61612. byte der[4096];
  61613. int derSz = 0;
  61614. X509_REQ* x509 = NULL;
  61615. STACK_OF(X509_EXTENSION) *exts = NULL;
  61616. X509_EXTENSION * san_ext = NULL;
  61617. X509_EXTENSION * ext = NULL;
  61618. GENERAL_NAME* gn = NULL;
  61619. GENERAL_NAMES* gns = NULL;
  61620. ASN1_OBJECT* upn_oid = NULL;
  61621. ASN1_UTF8STRING *utf8str = NULL;
  61622. ASN1_TYPE *value = NULL;
  61623. ASN1_STRING *extval = NULL;
  61624. /* SID extension. SID data format explained here:
  61625. * https://blog.qdsecurity.se/2022/05/27/manually-injecting-a-sid-in-a-certificate/
  61626. */
  61627. byte SidExtension[] = {
  61628. 48, 64, 160, 62, 6, 10, 43, 6, 1, 4, 1, 130, 55, 25, 2, 1, 160,
  61629. 48, 4, 46, 83, 45, 49, 45, 53, 45, 50, 49, 45, 50, 56, 52, 51, 57,
  61630. 48, 55, 52, 49, 56, 45, 51, 57, 50, 54, 50, 55, 55, 52, 50, 49, 45,
  61631. 51, 56, 49, 53, 57, 57, 51, 57, 55, 50, 45, 52, 54, 48, 49};
  61632. byte expectedAltName[] = {
  61633. 0x30, 0x27, 0xA0, 0x25, 0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82,
  61634. 0x37, 0x14, 0x02, 0x03, 0xA0, 0x17, 0x0C, 0x15, 0x6F, 0x74, 0x68, 0x65,
  61635. 0x72, 0x6E, 0x61, 0x6D, 0x65, 0x40, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73,
  61636. 0x6C, 0x2E, 0x63, 0x6F, 0x6D};
  61637. X509_EXTENSION *sid_ext = NULL;
  61638. ASN1_OBJECT* sid_oid = NULL;
  61639. ASN1_OCTET_STRING *sid_data = NULL;
  61640. ASN1_OBJECT* alt_names_oid = NULL;
  61641. EVP_PKEY* priv = NULL;
  61642. XFILE f = XBADFILE;
  61643. byte* pt = NULL;
  61644. BIO* bio = NULL;
  61645. ExpectTrue((f = XFOPEN(csr_fname, "rb")) != XBADFILE);
  61646. ExpectNotNull(x509 = d2i_X509_REQ_fp(f, NULL));
  61647. if (f != XBADFILE) {
  61648. XFCLOSE(f);
  61649. f = XBADFILE;
  61650. }
  61651. ExpectIntEQ(X509_REQ_set_version(x509, 2), 1);
  61652. ExpectNotNull(gn = GENERAL_NAME_new());
  61653. ExpectNotNull(upn_oid = OBJ_txt2obj("1.3.6.1.4.1.311.20.2.3", 1));
  61654. ExpectNotNull(utf8str = ASN1_UTF8STRING_new());
  61655. ExpectIntEQ(ASN1_STRING_set(utf8str, "othername@wolfssl.com", -1), 1);
  61656. ExpectNotNull(value = ASN1_TYPE_new());
  61657. ASN1_TYPE_set(value, V_ASN1_UTF8STRING, utf8str);
  61658. if (EXPECT_FAIL()) {
  61659. ASN1_UTF8STRING_free(utf8str);
  61660. }
  61661. ExpectIntEQ(GENERAL_NAME_set0_othername(gn, upn_oid, value), 1);
  61662. if (EXPECT_FAIL()) {
  61663. ASN1_TYPE_free(value);
  61664. GENERAL_NAME_free(gn);
  61665. gn = NULL;
  61666. }
  61667. ExpectNotNull(gns = sk_GENERAL_NAME_new(NULL));
  61668. ExpectIntEQ(sk_GENERAL_NAME_push(gns, gn), 1);
  61669. if (EXPECT_FAIL()) {
  61670. GENERAL_NAME_free(gn);
  61671. }
  61672. ExpectNotNull(san_ext = X509V3_EXT_i2d(NID_subject_alt_name, 0, gns));
  61673. ExpectNotNull(sid_oid = OBJ_txt2obj("1.3.6.1.4.1.311.25.2", 1));
  61674. ExpectNotNull(sid_data = ASN1_OCTET_STRING_new());
  61675. ASN1_OCTET_STRING_set(sid_data, SidExtension, sizeof(SidExtension));
  61676. ExpectNotNull(sid_ext = X509_EXTENSION_create_by_OBJ(NULL, sid_oid, 0,
  61677. sid_data));
  61678. ExpectNotNull(exts = sk_X509_EXTENSION_new_null());
  61679. /* Ensure an empty stack doesn't raise an error. */
  61680. ExpectIntEQ(X509_REQ_add_extensions(x509, exts), 1);
  61681. ExpectIntEQ(sk_X509_EXTENSION_push(exts, san_ext), 1);
  61682. if (EXPECT_FAIL()) {
  61683. X509_EXTENSION_free(san_ext);
  61684. }
  61685. ExpectIntEQ(sk_X509_EXTENSION_push(exts, sid_ext), 2);
  61686. if (EXPECT_FAIL()) {
  61687. X509_EXTENSION_free(sid_ext);
  61688. }
  61689. ExpectIntEQ(X509_REQ_add_extensions(x509, exts), 1);
  61690. ExpectTrue((f = XFOPEN(key_fname, "rb")) != XBADFILE);
  61691. ExpectIntGT(derSz = (int)XFREAD(der, 1, sizeof(der), f), 0);
  61692. if (f != XBADFILE)
  61693. XFCLOSE(f);
  61694. pt = der;
  61695. ExpectNotNull(priv = d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  61696. (const unsigned char**)&pt, derSz));
  61697. ExpectIntGT(X509_REQ_sign(x509, priv, EVP_sha256()), 0);
  61698. pt = der;
  61699. ExpectIntGT(derSz = i2d_X509_REQ(x509, &pt), 0);
  61700. X509_REQ_free(x509);
  61701. x509 = NULL;
  61702. pt = der;
  61703. ExpectNotNull(d2i_X509_REQ_INFO(&x509, (const unsigned char**)&pt, derSz));
  61704. sk_GENERAL_NAME_pop_free(gns, GENERAL_NAME_free);
  61705. gns = NULL;
  61706. sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
  61707. exts = NULL;
  61708. ASN1_OBJECT_free(upn_oid);
  61709. ASN1_OBJECT_free(sid_oid);
  61710. ASN1_OCTET_STRING_free(sid_data);
  61711. X509_REQ_free(x509);
  61712. EVP_PKEY_free(priv);
  61713. /* At this point everything used to generate what is in der is cleaned up.
  61714. * We now read back from der to confirm the extensions were inserted
  61715. * correctly. */
  61716. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem());
  61717. ExpectNotNull(bio);
  61718. ExpectIntEQ(BIO_write(bio, der, derSz), derSz); /* d2i consumes BIO */
  61719. ExpectNotNull(d2i_X509_REQ_bio(bio, &x509));
  61720. ExpectNotNull(x509);
  61721. BIO_free(bio);
  61722. ExpectNotNull(exts = (STACK_OF(X509_EXTENSION)*)X509_REQ_get_extensions(
  61723. x509));
  61724. ExpectIntEQ(sk_X509_EXTENSION_num(exts), 2);
  61725. /* Check the SID extension. */
  61726. ExpectNotNull(sid_oid = OBJ_txt2obj("1.3.6.1.4.1.311.25.2", 1));
  61727. ExpectNotNull(ext = sk_X509_EXTENSION_value(exts,
  61728. X509_get_ext_by_OBJ(x509, sid_oid, -1)));
  61729. ExpectNotNull(extval = X509_EXTENSION_get_data(ext));
  61730. ExpectIntEQ(extval->length, sizeof(SidExtension));
  61731. ExpectIntEQ(XMEMCMP(SidExtension, extval->data, sizeof(SidExtension)), 0);
  61732. ASN1_OBJECT_free(sid_oid);
  61733. /* Check the AltNames extension. */
  61734. ExpectNotNull(alt_names_oid = OBJ_txt2obj("subjectAltName", 0));
  61735. ExpectNotNull(ext = sk_X509_EXTENSION_value(exts,
  61736. X509_get_ext_by_OBJ(x509, alt_names_oid, -1)));
  61737. ExpectNotNull(extval = X509_EXTENSION_get_data(ext));
  61738. ExpectIntEQ(extval->length, sizeof(expectedAltName));
  61739. ExpectIntEQ(XMEMCMP(expectedAltName, extval->data, sizeof(expectedAltName)),
  61740. 0);
  61741. ASN1_OBJECT_free(alt_names_oid);
  61742. /* Cleanup */
  61743. ExpectNotNull(gns = (GENERAL_NAMES*)X509_get_ext_d2i(x509,
  61744. NID_subject_alt_name, NULL, NULL));
  61745. ExpectIntEQ(sk_GENERAL_NAME_num(gns), 1);
  61746. ExpectNotNull(gn = sk_GENERAL_NAME_value(gns, 0));
  61747. ExpectIntEQ(gn->type, 0);
  61748. sk_GENERAL_NAME_pop_free(gns, GENERAL_NAME_free);
  61749. sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
  61750. X509_REQ_free(x509);
  61751. #endif
  61752. return EXPECT_RESULT();
  61753. }
  61754. static int test_wolfSSL_X509_set_name(void)
  61755. {
  61756. EXPECT_DECLS;
  61757. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  61758. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ)
  61759. X509* x509 = NULL;
  61760. X509_NAME* name = NULL;
  61761. ExpectNotNull(name = X509_NAME_new());
  61762. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  61763. (byte*)"wolfssl.com", 11, 0, 1),
  61764. WOLFSSL_SUCCESS);
  61765. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  61766. (byte*)"support@wolfssl.com", 19, -1,
  61767. 1), WOLFSSL_SUCCESS);
  61768. ExpectNotNull(x509 = X509_new());
  61769. ExpectIntEQ(X509_set_subject_name(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  61770. ExpectIntEQ(X509_set_subject_name(x509, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  61771. ExpectIntEQ(X509_set_subject_name(NULL, name), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  61772. ExpectIntEQ(X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  61773. ExpectIntEQ(X509_set_issuer_name(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  61774. ExpectIntEQ(X509_set_issuer_name(x509, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  61775. ExpectIntEQ(X509_set_issuer_name(NULL, name), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  61776. ExpectIntEQ(X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  61777. X509_free(x509);
  61778. X509_NAME_free(name);
  61779. #endif /* OPENSSL_ALL && !NO_CERTS */
  61780. return EXPECT_RESULT();
  61781. }
  61782. static int test_wolfSSL_X509_set_notAfter(void)
  61783. {
  61784. EXPECT_DECLS;
  61785. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) \
  61786. && !defined(NO_ASN_TIME) && !defined(USER_TIME) && \
  61787. !defined(TIME_OVERRIDES) && !defined(NO_CERTS) && \
  61788. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) &&\
  61789. !defined(TIME_T_NOT_64BIT) && !defined(NO_64BIT) && !defined(NO_BIO)
  61790. /* Generalized time will overflow time_t if not long */
  61791. X509* x = NULL;
  61792. BIO* bio = NULL;
  61793. ASN1_TIME *asn_time = NULL;
  61794. ASN1_TIME *time_check = NULL;
  61795. const int year = 365*24*60*60;
  61796. const int day = 24*60*60;
  61797. const int hour = 60*60;
  61798. const int mini = 60;
  61799. int offset_day;
  61800. unsigned char buf[25];
  61801. time_t t;
  61802. /*
  61803. * Setup asn_time. APACHE HTTPD uses time(NULL)
  61804. */
  61805. t = (time_t)107 * year + 31 * day + 34 * hour + 30 * mini + 7 * day;
  61806. offset_day = 7;
  61807. /*
  61808. * Free these.
  61809. */
  61810. asn_time = wolfSSL_ASN1_TIME_adj(NULL, t, offset_day, 0);
  61811. ExpectNotNull(asn_time);
  61812. ExpectNotNull(x = X509_new());
  61813. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  61814. /*
  61815. * Tests
  61816. */
  61817. ExpectTrue(wolfSSL_X509_set_notAfter(x, asn_time));
  61818. /* time_check is simply (ANS1_TIME*)x->notAfter */
  61819. ExpectNotNull(time_check = X509_get_notAfter(x));
  61820. /* ANS1_TIME_check validates by checking if argument can be parsed */
  61821. ExpectIntEQ(ASN1_TIME_check(time_check), WOLFSSL_SUCCESS);
  61822. /* Convert to human readable format and compare to intended date */
  61823. ExpectIntEQ(ASN1_TIME_print(bio, time_check), 1);
  61824. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 24);
  61825. ExpectIntEQ(XMEMCMP(buf, "Jan 20 10:30:00 2077 GMT", sizeof(buf) - 1), 0);
  61826. ExpectFalse(wolfSSL_X509_set_notAfter(NULL, NULL));
  61827. ExpectFalse(wolfSSL_X509_set_notAfter(x, NULL));
  61828. ExpectFalse(wolfSSL_X509_set_notAfter(NULL, asn_time));
  61829. /*
  61830. * Cleanup
  61831. */
  61832. XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
  61833. X509_free(x);
  61834. BIO_free(bio);
  61835. #endif
  61836. return EXPECT_RESULT();
  61837. }
  61838. static int test_wolfSSL_X509_set_notBefore(void)
  61839. {
  61840. EXPECT_DECLS;
  61841. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) \
  61842. && !defined(NO_ASN_TIME) && !defined(USER_TIME) && \
  61843. !defined(TIME_OVERRIDES) && !defined(NO_CERTS) && \
  61844. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && !defined(NO_BIO)
  61845. X509* x = NULL;
  61846. BIO* bio = NULL;
  61847. ASN1_TIME *asn_time = NULL;
  61848. ASN1_TIME *time_check = NULL;
  61849. const int year = 365*24*60*60;
  61850. const int day = 24*60*60;
  61851. const int hour = 60*60;
  61852. const int mini = 60;
  61853. int offset_day;
  61854. unsigned char buf[25];
  61855. time_t t;
  61856. /*
  61857. * Setup asn_time. APACHE HTTPD uses time(NULL)
  61858. */
  61859. t = (time_t)49 * year + 125 * day + 20 * hour + 30 * mini + 7 * day;
  61860. offset_day = 7;
  61861. /*
  61862. * Free these.
  61863. */
  61864. asn_time = wolfSSL_ASN1_TIME_adj(NULL, t, offset_day, 0);
  61865. ExpectNotNull(asn_time);
  61866. ExpectNotNull(x = X509_new());
  61867. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  61868. ExpectIntEQ(ASN1_TIME_check(asn_time), WOLFSSL_SUCCESS);
  61869. /*
  61870. * Main Tests
  61871. */
  61872. ExpectTrue(wolfSSL_X509_set_notBefore(x, asn_time));
  61873. /* time_check == (ANS1_TIME*)x->notBefore */
  61874. ExpectNotNull(time_check = X509_get_notBefore(x));
  61875. /* ANS1_TIME_check validates by checking if argument can be parsed */
  61876. ExpectIntEQ(ASN1_TIME_check(time_check), WOLFSSL_SUCCESS);
  61877. /* Convert to human readable format and compare to intended date */
  61878. ExpectIntEQ(ASN1_TIME_print(bio, time_check), 1);
  61879. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 24);
  61880. ExpectIntEQ(XMEMCMP(buf, "May 8 20:30:00 2019 GMT", sizeof(buf) - 1), 0);
  61881. ExpectFalse(wolfSSL_X509_set_notBefore(NULL, NULL));
  61882. ExpectFalse(wolfSSL_X509_set_notBefore(x, NULL));
  61883. ExpectFalse(wolfSSL_X509_set_notBefore(NULL, asn_time));
  61884. /*
  61885. * Cleanup
  61886. */
  61887. XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
  61888. X509_free(x);
  61889. BIO_free(bio);
  61890. #endif
  61891. return EXPECT_RESULT();
  61892. }
  61893. static int test_wolfSSL_X509_set_version(void)
  61894. {
  61895. EXPECT_DECLS;
  61896. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && \
  61897. !defined(NO_CERTS) && defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ)
  61898. X509* x509 = NULL;
  61899. long v = 2L;
  61900. long maxInt = INT_MAX;
  61901. ExpectNotNull(x509 = X509_new());
  61902. /* These should pass. */
  61903. ExpectTrue(wolfSSL_X509_set_version(x509, v));
  61904. ExpectIntEQ(v, wolfSSL_X509_get_version(x509));
  61905. /* Fail Case: When v(long) is greater than x509->version(int). */
  61906. v = maxInt+1;
  61907. ExpectFalse(wolfSSL_X509_set_version(x509, v));
  61908. ExpectFalse(wolfSSL_X509_set_version(NULL, 2L));
  61909. ExpectFalse(wolfSSL_X509_set_version(NULL, maxInt+1));
  61910. /* Cleanup */
  61911. X509_free(x509);
  61912. #endif
  61913. return EXPECT_RESULT();
  61914. }
  61915. #ifndef NO_BIO
  61916. static int test_wolfSSL_BIO_gets(void)
  61917. {
  61918. EXPECT_DECLS;
  61919. #if defined(OPENSSL_EXTRA)
  61920. BIO* bio = NULL;
  61921. BIO* bio2 = NULL;
  61922. char msg[] = "\nhello wolfSSL\n security plus\t---...**adf\na...b.c";
  61923. char emp[] = "";
  61924. char bio_buffer[20];
  61925. int bufferSz = 20;
  61926. #ifdef OPENSSL_ALL
  61927. BUF_MEM* emp_bm = NULL;
  61928. BUF_MEM* msg_bm = NULL;
  61929. #endif
  61930. /* try with bad args */
  61931. ExpectNull(bio = BIO_new_mem_buf(NULL, sizeof(msg)));
  61932. #ifdef OPENSSL_ALL
  61933. ExpectIntEQ(BIO_set_mem_buf(bio, NULL, BIO_NOCLOSE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  61934. #endif
  61935. /* try with real msg */
  61936. ExpectNotNull(bio = BIO_new_mem_buf((void*)msg, -1));
  61937. XMEMSET(bio_buffer, 0, bufferSz);
  61938. ExpectNotNull(BIO_push(bio, BIO_new(BIO_s_bio())));
  61939. ExpectNull(bio2 = BIO_find_type(bio, BIO_TYPE_FILE));
  61940. ExpectNotNull(bio2 = BIO_find_type(bio, BIO_TYPE_BIO));
  61941. ExpectFalse(bio2 != BIO_next(bio));
  61942. /* make buffer filled with no terminating characters */
  61943. XMEMSET(bio_buffer, 1, bufferSz);
  61944. /* BIO_gets reads a line of data */
  61945. ExpectIntEQ(BIO_gets(bio, bio_buffer, -3), 0);
  61946. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 1);
  61947. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 14);
  61948. ExpectStrEQ(bio_buffer, "hello wolfSSL\n");
  61949. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 19);
  61950. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 8);
  61951. ExpectIntEQ(BIO_gets(bio, bio_buffer, -1), 0);
  61952. #ifdef OPENSSL_ALL
  61953. /* test setting the mem_buf manually */
  61954. BIO_free(bio);
  61955. ExpectNotNull(bio = BIO_new_mem_buf((void*)msg, -1));
  61956. ExpectNotNull(emp_bm = BUF_MEM_new());
  61957. ExpectNotNull(msg_bm = BUF_MEM_new());
  61958. ExpectIntEQ(BUF_MEM_grow(msg_bm, sizeof(msg)), sizeof(msg));
  61959. if (EXPECT_SUCCESS()) {
  61960. XFREE(msg_bm->data, NULL, DYNAMIC_TYPE_OPENSSL);
  61961. msg_bm->data = NULL;
  61962. }
  61963. /* emp size is 1 for terminator */
  61964. ExpectIntEQ(BUF_MEM_grow(emp_bm, sizeof(emp)), sizeof(emp));
  61965. if (EXPECT_SUCCESS()) {
  61966. XFREE(emp_bm->data, NULL, DYNAMIC_TYPE_OPENSSL);
  61967. emp_bm->data = emp;
  61968. msg_bm->data = msg;
  61969. }
  61970. ExpectIntEQ(BIO_set_mem_buf(bio, emp_bm, BIO_CLOSE), WOLFSSL_SUCCESS);
  61971. /* check reading an empty string */
  61972. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 1); /* just terminator */
  61973. ExpectStrEQ(emp, bio_buffer);
  61974. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 0); /* Nothing to read */
  61975. /* BIO_gets reads a line of data */
  61976. ExpectIntEQ(BIO_set_mem_buf(bio, msg_bm, BIO_NOCLOSE), WOLFSSL_SUCCESS);
  61977. ExpectIntEQ(BIO_gets(bio, bio_buffer, -3), 0);
  61978. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 1);
  61979. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 14);
  61980. ExpectStrEQ(bio_buffer, "hello wolfSSL\n");
  61981. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 19);
  61982. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 8);
  61983. ExpectIntEQ(BIO_gets(bio, bio_buffer, -1), 0);
  61984. if (EXPECT_SUCCESS())
  61985. emp_bm->data = NULL;
  61986. BUF_MEM_free(emp_bm);
  61987. if (EXPECT_SUCCESS())
  61988. msg_bm->data = NULL;
  61989. BUF_MEM_free(msg_bm);
  61990. #endif
  61991. /* check not null terminated string */
  61992. BIO_free(bio);
  61993. bio = NULL;
  61994. msg[0] = 0x33;
  61995. msg[1] = 0x33;
  61996. msg[2] = 0x33;
  61997. ExpectNotNull(bio = BIO_new_mem_buf((void*)msg, 3));
  61998. ExpectIntEQ(BIO_gets(bio, bio_buffer, 3), 2);
  61999. ExpectIntEQ(bio_buffer[0], msg[0]);
  62000. ExpectIntEQ(bio_buffer[1], msg[1]);
  62001. ExpectIntNE(bio_buffer[2], msg[2]);
  62002. BIO_free(bio);
  62003. bio = NULL;
  62004. msg[3] = 0x33;
  62005. bio_buffer[3] = 0x33;
  62006. ExpectNotNull(bio = BIO_new_mem_buf((void*)msg, 3));
  62007. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 3);
  62008. ExpectIntEQ(bio_buffer[0], msg[0]);
  62009. ExpectIntEQ(bio_buffer[1], msg[1]);
  62010. ExpectIntEQ(bio_buffer[2], msg[2]);
  62011. ExpectIntNE(bio_buffer[3], 0x33); /* make sure null terminator was set */
  62012. /* check reading an empty string */
  62013. BIO_free(bio);
  62014. bio = NULL;
  62015. ExpectNotNull(bio = BIO_new_mem_buf((void*)emp, sizeof(emp)));
  62016. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 1); /* just terminator */
  62017. ExpectStrEQ(emp, bio_buffer);
  62018. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 0); /* Nothing to read */
  62019. /* check error cases */
  62020. BIO_free(bio);
  62021. bio = NULL;
  62022. ExpectIntEQ(BIO_gets(NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  62023. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  62024. ExpectIntEQ(BIO_gets(bio, bio_buffer, 2), 0); /* nothing to read */
  62025. #if !defined(NO_FILESYSTEM)
  62026. {
  62027. BIO* f_bio = NULL;
  62028. XFILE f = XBADFILE;
  62029. ExpectNotNull(f_bio = BIO_new(BIO_s_file()));
  62030. ExpectIntLE(BIO_gets(f_bio, bio_buffer, bufferSz), 0);
  62031. ExpectTrue((f = XFOPEN(svrCertFile, "rb")) != XBADFILE);
  62032. ExpectIntEQ((int)BIO_set_fp(f_bio, f, BIO_CLOSE), SSL_SUCCESS);
  62033. if (EXPECT_FAIL() && (f != XBADFILE)) {
  62034. XFCLOSE(f);
  62035. }
  62036. ExpectIntGT(BIO_gets(f_bio, bio_buffer, bufferSz), 0);
  62037. BIO_free(f_bio);
  62038. f_bio = NULL;
  62039. }
  62040. #endif /* NO_FILESYSTEM */
  62041. BIO_free(bio);
  62042. bio = NULL;
  62043. BIO_free(bio2);
  62044. bio2 = NULL;
  62045. /* try with type BIO */
  62046. XMEMCPY(msg, "\nhello wolfSSL\n security plus\t---...**adf\na...b.c",
  62047. sizeof(msg));
  62048. ExpectNotNull(bio = BIO_new(BIO_s_bio()));
  62049. ExpectIntEQ(BIO_gets(bio, bio_buffer, 2), 0); /* nothing to read */
  62050. ExpectNotNull(bio2 = BIO_new(BIO_s_bio()));
  62051. ExpectIntEQ(BIO_set_write_buf_size(bio, 10), SSL_SUCCESS);
  62052. ExpectIntEQ(BIO_set_write_buf_size(bio2, sizeof(msg)), SSL_SUCCESS);
  62053. ExpectIntEQ(BIO_make_bio_pair(bio, bio2), SSL_SUCCESS);
  62054. ExpectIntEQ(BIO_write(bio2, msg, sizeof(msg)), sizeof(msg));
  62055. ExpectIntEQ(BIO_gets(bio, bio_buffer, -3), 0);
  62056. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 1);
  62057. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 14);
  62058. ExpectStrEQ(bio_buffer, "hello wolfSSL\n");
  62059. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 19);
  62060. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 8);
  62061. ExpectIntEQ(BIO_gets(bio, bio_buffer, -1), 0);
  62062. BIO_free(bio);
  62063. bio = NULL;
  62064. BIO_free(bio2);
  62065. bio2 = NULL;
  62066. /* check reading an empty string */
  62067. ExpectNotNull(bio = BIO_new(BIO_s_bio()));
  62068. ExpectIntEQ(BIO_set_write_buf_size(bio, sizeof(emp)), SSL_SUCCESS);
  62069. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 0); /* Nothing to read */
  62070. ExpectStrEQ(emp, bio_buffer);
  62071. BIO_free(bio);
  62072. bio = NULL;
  62073. #endif
  62074. return EXPECT_RESULT();
  62075. }
  62076. static int test_wolfSSL_BIO_puts(void)
  62077. {
  62078. EXPECT_DECLS;
  62079. #if defined(OPENSSL_EXTRA)
  62080. BIO* bio = NULL;
  62081. char input[] = "hello\0world\n.....ok\n\0";
  62082. char output[128];
  62083. XMEMSET(output, 0, sizeof(output));
  62084. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  62085. ExpectIntEQ(BIO_puts(bio, input), 5);
  62086. ExpectIntEQ(BIO_pending(bio), 5);
  62087. ExpectIntEQ(BIO_puts(bio, input + 6), 14);
  62088. ExpectIntEQ(BIO_pending(bio), 19);
  62089. ExpectIntEQ(BIO_gets(bio, output, sizeof(output)), 11);
  62090. ExpectStrEQ(output, "helloworld\n");
  62091. ExpectIntEQ(BIO_pending(bio), 8);
  62092. ExpectIntEQ(BIO_gets(bio, output, sizeof(output)), 8);
  62093. ExpectStrEQ(output, ".....ok\n");
  62094. ExpectIntEQ(BIO_pending(bio), 0);
  62095. ExpectIntEQ(BIO_puts(bio, ""), -1);
  62096. BIO_free(bio);
  62097. #endif
  62098. return EXPECT_RESULT();
  62099. }
  62100. static int test_wolfSSL_BIO_dump(void)
  62101. {
  62102. EXPECT_DECLS;
  62103. #if defined(OPENSSL_EXTRA)
  62104. BIO* bio;
  62105. static const unsigned char data[] = {
  62106. 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2A, 0x86, 0x48, 0xCE,
  62107. 0x3D, 0x02, 0x01, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D,
  62108. 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x55, 0xBF, 0xF4,
  62109. 0x0F, 0x44, 0x50, 0x9A, 0x3D, 0xCE, 0x9B, 0xB7, 0xF0, 0xC5,
  62110. 0x4D, 0xF5, 0x70, 0x7B, 0xD4, 0xEC, 0x24, 0x8E, 0x19, 0x80,
  62111. 0xEC, 0x5A, 0x4C, 0xA2, 0x24, 0x03, 0x62, 0x2C, 0x9B, 0xDA,
  62112. 0xEF, 0xA2, 0x35, 0x12, 0x43, 0x84, 0x76, 0x16, 0xC6, 0x56,
  62113. 0x95, 0x06, 0xCC, 0x01, 0xA9, 0xBD, 0xF6, 0x75, 0x1A, 0x42,
  62114. 0xF7, 0xBD, 0xA9, 0xB2, 0x36, 0x22, 0x5F, 0xC7, 0x5D, 0x7F,
  62115. 0xB4
  62116. };
  62117. /* Generated with OpenSSL. */
  62118. static const char expected[] =
  62119. "0000 - 30 59 30 13 06 07 2a 86-48 ce 3d 02 01 06 08 2a 0Y0...*.H.=....*\n"
  62120. "0010 - 86 48 ce 3d 03 01 07 03-42 00 04 55 bf f4 0f 44 .H.=....B..U...D\n"
  62121. "0020 - 50 9a 3d ce 9b b7 f0 c5-4d f5 70 7b d4 ec 24 8e P.=.....M.p{..$.\n"
  62122. "0030 - 19 80 ec 5a 4c a2 24 03-62 2c 9b da ef a2 35 12 ...ZL.$.b,....5.\n"
  62123. "0040 - 43 84 76 16 c6 56 95 06-cc 01 a9 bd f6 75 1a 42 C.v..V.......u.B\n"
  62124. "0050 - f7 bd a9 b2 36 22 5f c7-5d 7f b4 ....6\"_.]..\n";
  62125. static const char expectedAll[] =
  62126. "0000 - 00 01 02 03 04 05 06 07-08 09 0a 0b 0c 0d 0e 0f ................\n"
  62127. "0010 - 10 11 12 13 14 15 16 17-18 19 1a 1b 1c 1d 1e 1f ................\n"
  62128. "0020 - 20 21 22 23 24 25 26 27-28 29 2a 2b 2c 2d 2e 2f !\"#$%&'()*+,-./\n"
  62129. "0030 - 30 31 32 33 34 35 36 37-38 39 3a 3b 3c 3d 3e 3f 0123456789:;<=>?\n"
  62130. "0040 - 40 41 42 43 44 45 46 47-48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO\n"
  62131. "0050 - 50 51 52 53 54 55 56 57-58 59 5a 5b 5c 5d 5e 5f PQRSTUVWXYZ[\\]^_\n"
  62132. "0060 - 60 61 62 63 64 65 66 67-68 69 6a 6b 6c 6d 6e 6f `abcdefghijklmno\n"
  62133. "0070 - 70 71 72 73 74 75 76 77-78 79 7a 7b 7c 7d 7e 7f pqrstuvwxyz{|}~.\n"
  62134. "0080 - 80 81 82 83 84 85 86 87-88 89 8a 8b 8c 8d 8e 8f ................\n"
  62135. "0090 - 90 91 92 93 94 95 96 97-98 99 9a 9b 9c 9d 9e 9f ................\n"
  62136. "00a0 - a0 a1 a2 a3 a4 a5 a6 a7-a8 a9 aa ab ac ad ae af ................\n"
  62137. "00b0 - b0 b1 b2 b3 b4 b5 b6 b7-b8 b9 ba bb bc bd be bf ................\n"
  62138. "00c0 - c0 c1 c2 c3 c4 c5 c6 c7-c8 c9 ca cb cc cd ce cf ................\n"
  62139. "00d0 - d0 d1 d2 d3 d4 d5 d6 d7-d8 d9 da db dc dd de df ................\n"
  62140. "00e0 - e0 e1 e2 e3 e4 e5 e6 e7-e8 e9 ea eb ec ed ee ef ................\n"
  62141. "00f0 - f0 f1 f2 f3 f4 f5 f6 f7-f8 f9 fa fb fc fd fe ff ................\n";
  62142. char output[16 * 80];
  62143. int i;
  62144. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  62145. /* Example key dumped. */
  62146. ExpectIntEQ(BIO_dump(bio, (const char*)data, (int)sizeof(data)),
  62147. sizeof(expected) - 1);
  62148. ExpectIntEQ(BIO_read(bio, output, sizeof(output)), sizeof(expected) - 1);
  62149. ExpectIntEQ(XMEMCMP(output, expected, sizeof(expected) - 1), 0);
  62150. /* Try every possible value for a character. */
  62151. for (i = 0; i < 256; i++)
  62152. output[i] = i;
  62153. ExpectIntEQ(BIO_dump(bio, output, 256), sizeof(expectedAll) - 1);
  62154. ExpectIntEQ(BIO_read(bio, output, sizeof(output)), sizeof(expectedAll) - 1);
  62155. ExpectIntEQ(XMEMCMP(output, expectedAll, sizeof(expectedAll) - 1), 0);
  62156. BIO_free(bio);
  62157. #endif
  62158. return EXPECT_RESULT();
  62159. }
  62160. #if defined(OPENSSL_ALL) && !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  62161. !defined(NO_RSA) && defined(HAVE_EXT_CACHE) && \
  62162. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(USE_WOLFSSL_IO)
  62163. static int forceWantRead(WOLFSSL *ssl, char *buf, int sz, void *ctx)
  62164. {
  62165. (void)ssl;
  62166. (void)buf;
  62167. (void)sz;
  62168. (void)ctx;
  62169. return WOLFSSL_CBIO_ERR_WANT_READ;
  62170. }
  62171. #endif
  62172. static int test_wolfSSL_BIO_should_retry(void)
  62173. {
  62174. EXPECT_DECLS;
  62175. #if defined(OPENSSL_ALL) && !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  62176. !defined(NO_RSA) && defined(HAVE_EXT_CACHE) && \
  62177. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(USE_WOLFSSL_IO)
  62178. tcp_ready ready;
  62179. func_args server_args;
  62180. THREAD_TYPE serverThread;
  62181. SOCKET_T sockfd = 0;
  62182. WOLFSSL_CTX* ctx = NULL;
  62183. WOLFSSL* ssl = NULL;
  62184. char msg[64] = "hello wolfssl!";
  62185. char reply[1024];
  62186. int msgSz = (int)XSTRLEN(msg);
  62187. int ret;
  62188. BIO* bio = NULL;
  62189. XMEMSET(&server_args, 0, sizeof(func_args));
  62190. #ifdef WOLFSSL_TIRTOS
  62191. fdOpenSession(Task_self());
  62192. #endif
  62193. StartTCP();
  62194. InitTcpReady(&ready);
  62195. #if defined(USE_WINDOWS_API)
  62196. /* use RNG to get random port if using windows */
  62197. ready.port = GetRandomPort();
  62198. #endif
  62199. server_args.signal = &ready;
  62200. start_thread(test_server_nofail, &server_args, &serverThread);
  62201. wait_tcp_ready(&server_args);
  62202. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  62203. #ifdef OPENSSL_COMPATIBLE_DEFAULTS
  62204. ExpectIntEQ(wolfSSL_CTX_clear_mode(ctx, SSL_MODE_AUTO_RETRY), 0);
  62205. #endif
  62206. ExpectIntEQ(WOLFSSL_SUCCESS,
  62207. wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0));
  62208. ExpectIntEQ(WOLFSSL_SUCCESS,
  62209. wolfSSL_CTX_use_certificate_file(ctx, cliCertFile, SSL_FILETYPE_PEM));
  62210. ExpectIntEQ(WOLFSSL_SUCCESS,
  62211. wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, SSL_FILETYPE_PEM));
  62212. tcp_connect(&sockfd, wolfSSLIP, server_args.signal->port, 0, 0, NULL);
  62213. /* force retry */
  62214. ExpectNotNull(bio = wolfSSL_BIO_new_ssl(ctx, 1));
  62215. ExpectIntEQ(BIO_get_ssl(bio, &ssl), 1);
  62216. ExpectNotNull(ssl);
  62217. ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS);
  62218. wolfSSL_SSLSetIORecv(ssl, forceWantRead);
  62219. if (EXPECT_FAIL()) {
  62220. wolfSSL_free(ssl);
  62221. ssl = NULL;
  62222. }
  62223. ExpectIntLE(BIO_write(bio, msg, msgSz), 0);
  62224. ExpectIntNE(BIO_should_retry(bio), 0);
  62225. ExpectIntEQ(BIO_should_read(bio), 0);
  62226. ExpectIntEQ(BIO_should_write(bio), 0);
  62227. /* now perform successful connection */
  62228. wolfSSL_SSLSetIORecv(ssl, EmbedReceive);
  62229. ExpectIntEQ(BIO_write(bio, msg, msgSz), msgSz);
  62230. ExpectIntNE(BIO_read(bio, reply, sizeof(reply)), 0);
  62231. ret = wolfSSL_get_error(ssl, -1);
  62232. if (ret == WOLFSSL_ERROR_WANT_READ || ret == WOLFSSL_ERROR_WANT_WRITE) {
  62233. ExpectIntNE(BIO_should_retry(bio), 0);
  62234. if (ret == WOLFSSL_ERROR_WANT_READ)
  62235. ExpectIntEQ(BIO_should_read(bio), 1);
  62236. else
  62237. ExpectIntEQ(BIO_should_read(bio), 0);
  62238. if (ret == WOLFSSL_ERROR_WANT_WRITE)
  62239. ExpectIntEQ(BIO_should_write(bio), 1);
  62240. else
  62241. ExpectIntEQ(BIO_should_write(bio), 0);
  62242. }
  62243. else {
  62244. ExpectIntEQ(BIO_should_retry(bio), 0);
  62245. ExpectIntEQ(BIO_should_read(bio), 0);
  62246. ExpectIntEQ(BIO_should_write(bio), 0);
  62247. }
  62248. ExpectIntEQ(XMEMCMP(reply, "I hear you fa shizzle!",
  62249. XSTRLEN("I hear you fa shizzle!")), 0);
  62250. BIO_free(bio);
  62251. wolfSSL_CTX_free(ctx);
  62252. CloseSocket(sockfd);
  62253. join_thread(serverThread);
  62254. FreeTcpReady(&ready);
  62255. #ifdef WOLFSSL_TIRTOS
  62256. fdOpenSession(Task_self());
  62257. #endif
  62258. #endif
  62259. return EXPECT_RESULT();
  62260. }
  62261. static int test_wolfSSL_BIO_connect(void)
  62262. {
  62263. EXPECT_DECLS;
  62264. #if defined(OPENSSL_ALL) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  62265. defined(HAVE_HTTP_CLIENT) && !defined(NO_WOLFSSL_CLIENT)
  62266. tcp_ready ready;
  62267. func_args server_args;
  62268. THREAD_TYPE serverThread;
  62269. BIO *tcpBio = NULL;
  62270. BIO *sslBio = NULL;
  62271. SSL_CTX* ctx = NULL;
  62272. SSL *ssl = NULL;
  62273. SSL *sslPtr;
  62274. char msg[] = "hello wolfssl!";
  62275. char reply[30];
  62276. char buff[10] = {0};
  62277. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  62278. ExpectIntEQ(WOLFSSL_SUCCESS,
  62279. wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0));
  62280. ExpectIntEQ(WOLFSSL_SUCCESS,
  62281. wolfSSL_CTX_use_certificate_file(ctx, cliCertFile, SSL_FILETYPE_PEM));
  62282. ExpectIntEQ(WOLFSSL_SUCCESS,
  62283. wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, SSL_FILETYPE_PEM));
  62284. /* Setup server */
  62285. XMEMSET(&server_args, 0, sizeof(func_args));
  62286. StartTCP();
  62287. InitTcpReady(&ready);
  62288. #if defined(USE_WINDOWS_API)
  62289. /* use RNG to get random port if using windows */
  62290. ready.port = GetRandomPort();
  62291. #endif
  62292. server_args.signal = &ready;
  62293. start_thread(test_server_nofail, &server_args, &serverThread);
  62294. wait_tcp_ready(&server_args);
  62295. ExpectIntGT(XSNPRINTF(buff, sizeof(buff), "%d", ready.port), 0);
  62296. /* Start the test proper */
  62297. /* Setup the TCP BIO */
  62298. ExpectNotNull(tcpBio = BIO_new_connect(wolfSSLIP));
  62299. ExpectIntEQ(BIO_set_conn_port(tcpBio, buff), 1);
  62300. /* Setup the SSL object */
  62301. ExpectNotNull(ssl = SSL_new(ctx));
  62302. SSL_set_connect_state(ssl);
  62303. /* Setup the SSL BIO */
  62304. ExpectNotNull(sslBio = BIO_new(BIO_f_ssl()));
  62305. ExpectIntEQ(BIO_set_ssl(sslBio, ssl, BIO_CLOSE), 1);
  62306. if (EXPECT_FAIL()) {
  62307. wolfSSL_free(ssl);
  62308. }
  62309. /* Verify that BIO_get_ssl works. */
  62310. ExpectIntEQ(BIO_get_ssl(sslBio, &sslPtr), 1);
  62311. ExpectPtrEq(ssl, sslPtr);
  62312. /* Link BIO's so that sslBio uses tcpBio for IO */
  62313. ExpectPtrEq(BIO_push(sslBio, tcpBio), sslBio);
  62314. /* Do TCP connect */
  62315. ExpectIntEQ(BIO_do_connect(sslBio), 1);
  62316. /* Do TLS handshake */
  62317. ExpectIntEQ(BIO_do_handshake(sslBio), 1);
  62318. /* Test writing */
  62319. ExpectIntEQ(BIO_write(sslBio, msg, sizeof(msg)), sizeof(msg));
  62320. /* Expect length of default wolfSSL reply */
  62321. ExpectIntEQ(BIO_read(sslBio, reply, sizeof(reply)), 23);
  62322. /* Clean it all up */
  62323. BIO_free_all(sslBio);
  62324. /* Server clean up */
  62325. join_thread(serverThread);
  62326. FreeTcpReady(&ready);
  62327. /* Run the same test, but use BIO_new_ssl_connect and set the IP and port
  62328. * after. */
  62329. XMEMSET(&server_args, 0, sizeof(func_args));
  62330. StartTCP();
  62331. InitTcpReady(&ready);
  62332. #if defined(USE_WINDOWS_API)
  62333. /* use RNG to get random port if using windows */
  62334. ready.port = GetRandomPort();
  62335. #endif
  62336. server_args.signal = &ready;
  62337. start_thread(test_server_nofail, &server_args, &serverThread);
  62338. wait_tcp_ready(&server_args);
  62339. ExpectIntGT(XSNPRINTF(buff, sizeof(buff), "%d", ready.port), 0);
  62340. ExpectNotNull(sslBio = BIO_new_ssl_connect(ctx));
  62341. ExpectIntEQ(BIO_set_conn_hostname(sslBio, (char*)wolfSSLIP), 1);
  62342. ExpectIntEQ(BIO_set_conn_port(sslBio, buff), 1);
  62343. ExpectIntEQ(BIO_do_connect(sslBio), 1);
  62344. ExpectIntEQ(BIO_do_handshake(sslBio), 1);
  62345. ExpectIntEQ(BIO_write(sslBio, msg, sizeof(msg)), sizeof(msg));
  62346. ExpectIntEQ(BIO_read(sslBio, reply, sizeof(reply)), 23);
  62347. /* Attempt to close the TLS connection gracefully. */
  62348. BIO_ssl_shutdown(sslBio);
  62349. BIO_free_all(sslBio);
  62350. join_thread(serverThread);
  62351. FreeTcpReady(&ready);
  62352. SSL_CTX_free(ctx);
  62353. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
  62354. wc_ecc_fp_free(); /* free per thread cache */
  62355. #endif
  62356. #endif
  62357. return EXPECT_RESULT();
  62358. }
  62359. static int test_wolfSSL_BIO_tls(void)
  62360. {
  62361. EXPECT_DECLS;
  62362. #if !defined(NO_BIO) && defined(OPENSSL_EXTRA) && !defined(NO_WOLFSSL_CLIENT)
  62363. SSL_CTX* ctx = NULL;
  62364. SSL *ssl = NULL;
  62365. BIO *readBio = NULL;
  62366. BIO *writeBio = NULL;
  62367. int ret;
  62368. int err = 0;
  62369. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_method()));
  62370. ExpectNotNull(ssl = SSL_new(ctx));
  62371. ExpectNotNull(readBio = BIO_new(BIO_s_mem()));
  62372. ExpectNotNull(writeBio = BIO_new(BIO_s_mem()));
  62373. /* Qt reads data from write-bio,
  62374. * then writes the read data into plain packet.
  62375. * Qt reads data from plain packet,
  62376. * then writes the read data into read-bio.
  62377. */
  62378. SSL_set_bio(ssl, readBio, writeBio);
  62379. do {
  62380. #ifdef WOLFSSL_ASYNC_CRYPT
  62381. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  62382. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  62383. if (ret < 0) { break; } else if (ret == 0) { continue; }
  62384. }
  62385. #endif
  62386. ret = SSL_connect(ssl);
  62387. err = SSL_get_error(ssl, 0);
  62388. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  62389. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  62390. /* in this use case, should return WANT READ
  62391. * so that Qt will read the data from plain packet for next state.
  62392. */
  62393. ExpectIntEQ(err, SSL_ERROR_WANT_READ);
  62394. SSL_free(ssl);
  62395. SSL_CTX_free(ctx);
  62396. #endif
  62397. return EXPECT_RESULT();
  62398. }
  62399. static int test_wolfSSL_BIO_datagram(void)
  62400. {
  62401. EXPECT_DECLS;
  62402. #if !defined(NO_BIO) && defined(WOLFSSL_DTLS) && defined(WOLFSSL_HAVE_BIO_ADDR) && defined(OPENSSL_EXTRA)
  62403. int ret;
  62404. SOCKET_T fd1 = SOCKET_INVALID, fd2 = SOCKET_INVALID;
  62405. WOLFSSL_BIO *bio1 = NULL, *bio2 = NULL;
  62406. WOLFSSL_BIO_ADDR *bio_addr1 = NULL, *bio_addr2 = NULL;
  62407. SOCKADDR_IN sin1, sin2;
  62408. socklen_t slen;
  62409. static const char test_msg[] = "I am a datagram, short and stout.";
  62410. char test_msg_recvd[sizeof(test_msg) + 10];
  62411. #ifdef USE_WINDOWS_API
  62412. static const DWORD timeout = 250; /* ms */
  62413. #else
  62414. static const struct timeval timeout = { 0, 250000 };
  62415. #endif
  62416. StartTCP();
  62417. if (EXPECT_SUCCESS()) {
  62418. fd1 = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  62419. ExpectIntNE(fd1, SOCKET_INVALID);
  62420. }
  62421. if (EXPECT_SUCCESS()) {
  62422. fd2 = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  62423. ExpectIntNE(fd2, SOCKET_INVALID);
  62424. }
  62425. if (EXPECT_SUCCESS()) {
  62426. bio1 = wolfSSL_BIO_new_dgram(fd1, 1 /* closeF */);
  62427. ExpectNotNull(bio1);
  62428. }
  62429. if (EXPECT_SUCCESS()) {
  62430. bio2 = wolfSSL_BIO_new_dgram(fd2, 1 /* closeF */);
  62431. ExpectNotNull(bio2);
  62432. }
  62433. if (EXPECT_SUCCESS()) {
  62434. sin1.sin_family = AF_INET;
  62435. sin1.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  62436. sin1.sin_port = 0;
  62437. slen = (socklen_t)sizeof(sin1);
  62438. ExpectIntEQ(bind(fd1, (const struct sockaddr *)&sin1, slen), 0);
  62439. ExpectIntEQ(setsockopt(fd1, SOL_SOCKET, SO_RCVTIMEO, (const char *)&timeout, sizeof(timeout)), 0);
  62440. ExpectIntEQ(getsockname(fd1, (struct sockaddr *)&sin1, &slen), 0);
  62441. }
  62442. if (EXPECT_SUCCESS()) {
  62443. sin2.sin_family = AF_INET;
  62444. sin2.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  62445. sin2.sin_port = 0;
  62446. slen = (socklen_t)sizeof(sin2);
  62447. ExpectIntEQ(bind(fd2, (const struct sockaddr *)&sin2, slen), 0);
  62448. ExpectIntEQ(setsockopt(fd2, SOL_SOCKET, SO_RCVTIMEO, (const char *)&timeout, sizeof(timeout)), 0);
  62449. ExpectIntEQ(getsockname(fd2, (struct sockaddr *)&sin2, &slen), 0);
  62450. }
  62451. if (EXPECT_SUCCESS()) {
  62452. bio_addr1 = wolfSSL_BIO_ADDR_new();
  62453. ExpectNotNull(bio_addr1);
  62454. }
  62455. if (EXPECT_SUCCESS()) {
  62456. bio_addr2 = wolfSSL_BIO_ADDR_new();
  62457. ExpectNotNull(bio_addr2);
  62458. }
  62459. if (EXPECT_SUCCESS()) {
  62460. /* for OpenSSL compatibility, direct copying of sockaddrs into BIO_ADDRs must work right. */
  62461. XMEMCPY(&bio_addr2->sa_in, &sin2, sizeof(sin2));
  62462. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio1, BIO_CTRL_DGRAM_SET_PEER, 0, bio_addr2), WOLFSSL_SUCCESS);
  62463. wolfSSL_BIO_ADDR_clear(bio_addr2);
  62464. }
  62465. test_msg_recvd[0] = 0;
  62466. ExpectIntEQ(wolfSSL_BIO_write(bio1, test_msg, sizeof(test_msg)), (int)sizeof(test_msg));
  62467. ExpectIntEQ(wolfSSL_BIO_read(bio2, test_msg_recvd, sizeof(test_msg_recvd)), (int)sizeof(test_msg));
  62468. ExpectIntEQ(XMEMCMP(test_msg_recvd, test_msg, sizeof(test_msg)), 0);
  62469. #ifdef WOLFSSL_BIO_HAVE_FLOW_STATS
  62470. ExpectIntEQ(wolfSSL_BIO_number_written(bio1), sizeof(test_msg));
  62471. ExpectIntEQ(wolfSSL_BIO_number_read(bio2), sizeof(test_msg));
  62472. #endif
  62473. /* bio2 should now have bio1's addr stored as its peer_addr, because the
  62474. * BIOs aren't "connected" yet. use it to send a reply.
  62475. */
  62476. test_msg_recvd[0] = 0;
  62477. ExpectIntEQ(wolfSSL_BIO_write(bio2, test_msg, sizeof(test_msg)), (int)sizeof(test_msg));
  62478. ExpectIntEQ(wolfSSL_BIO_read(bio1, test_msg_recvd, sizeof(test_msg_recvd)), (int)sizeof(test_msg));
  62479. ExpectIntEQ(XMEMCMP(test_msg_recvd, test_msg, sizeof(test_msg)), 0);
  62480. ExpectIntEQ(wolfSSL_BIO_read(bio1, test_msg_recvd, sizeof(test_msg_recvd)), WOLFSSL_BIO_ERROR);
  62481. ExpectIntNE(BIO_should_retry(bio1), 0);
  62482. ExpectIntEQ(wolfSSL_BIO_read(bio2, test_msg_recvd, sizeof(test_msg_recvd)), WOLFSSL_BIO_ERROR);
  62483. ExpectIntNE(BIO_should_retry(bio2), 0);
  62484. /* now "connect" the sockets. */
  62485. ExpectIntEQ(connect(fd1, (const struct sockaddr *)&sin2, (socklen_t)sizeof(sin2)), 0);
  62486. ExpectIntEQ(connect(fd2, (const struct sockaddr *)&sin1, (socklen_t)sizeof(sin1)), 0);
  62487. if (EXPECT_SUCCESS()) {
  62488. XMEMCPY(&bio_addr2->sa_in, &sin2, sizeof(sin2));
  62489. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio1, BIO_CTRL_DGRAM_SET_CONNECTED, 0, bio_addr2), WOLFSSL_SUCCESS);
  62490. wolfSSL_BIO_ADDR_clear(bio_addr2);
  62491. }
  62492. if (EXPECT_SUCCESS()) {
  62493. XMEMCPY(&bio_addr1->sa_in, &sin1, sizeof(sin1));
  62494. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio2, BIO_CTRL_DGRAM_SET_CONNECTED, 0, bio_addr1), WOLFSSL_SUCCESS);
  62495. wolfSSL_BIO_ADDR_clear(bio_addr1);
  62496. }
  62497. test_msg_recvd[0] = 0;
  62498. ExpectIntEQ(wolfSSL_BIO_write(bio2, test_msg, sizeof(test_msg)), (int)sizeof(test_msg));
  62499. ExpectIntEQ(wolfSSL_BIO_read(bio1, test_msg_recvd, sizeof(test_msg_recvd)), (int)sizeof(test_msg));
  62500. ExpectIntEQ(XMEMCMP(test_msg_recvd, test_msg, sizeof(test_msg)), 0);
  62501. test_msg_recvd[0] = 0;
  62502. ExpectIntEQ(wolfSSL_BIO_write(bio1, test_msg, sizeof(test_msg)), (int)sizeof(test_msg));
  62503. ExpectIntEQ(wolfSSL_BIO_read(bio2, test_msg_recvd, sizeof(test_msg_recvd)), (int)sizeof(test_msg));
  62504. ExpectIntEQ(XMEMCMP(test_msg_recvd, test_msg, sizeof(test_msg)), 0);
  62505. #ifdef __linux__
  62506. /* now "disconnect" the sockets and attempt transmits expected to fail. */
  62507. sin1.sin_family = AF_UNSPEC;
  62508. ExpectIntEQ(connect(fd1, (const struct sockaddr *)&sin1, (socklen_t)sizeof(sin1)), 0);
  62509. ExpectIntEQ(connect(fd2, (const struct sockaddr *)&sin1, (socklen_t)sizeof(sin1)), 0);
  62510. sin1.sin_family = AF_INET;
  62511. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio1, BIO_CTRL_DGRAM_SET_CONNECTED, 0, NULL), WOLFSSL_SUCCESS);
  62512. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio2, BIO_CTRL_DGRAM_SET_CONNECTED, 0, NULL), WOLFSSL_SUCCESS);
  62513. if (EXPECT_SUCCESS()) {
  62514. sin2.sin_addr.s_addr = htonl(0xc0a8c0a8); /* 192.168.192.168 -- invalid for loopback interface. */
  62515. XMEMCPY(&bio_addr2->sa_in, &sin2, sizeof(sin2));
  62516. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio1, BIO_CTRL_DGRAM_SET_PEER, 0, bio_addr2), WOLFSSL_SUCCESS);
  62517. wolfSSL_BIO_ADDR_clear(bio_addr2);
  62518. }
  62519. test_msg_recvd[0] = 0;
  62520. errno = 0;
  62521. ExpectIntEQ(wolfSSL_BIO_write(bio1, test_msg, sizeof(test_msg)), -1);
  62522. ExpectTrue((errno == EINVAL) || (errno == ENETUNREACH));
  62523. #endif /* __linux__ */
  62524. if (bio1) {
  62525. ret = wolfSSL_BIO_free(bio1);
  62526. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  62527. } else if (fd1 != SOCKET_INVALID)
  62528. CloseSocket(fd1);
  62529. if (bio2) {
  62530. ret = wolfSSL_BIO_free(bio2);
  62531. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  62532. } else if (fd2 != SOCKET_INVALID)
  62533. CloseSocket(fd2);
  62534. if (bio_addr1)
  62535. wolfSSL_BIO_ADDR_free(bio_addr1);
  62536. if (bio_addr2)
  62537. wolfSSL_BIO_ADDR_free(bio_addr2);
  62538. #endif /* !NO_BIO && WOLFSSL_DTLS && WOLFSSL_HAVE_BIO_ADDR && OPENSSL_EXTRA */
  62539. return EXPECT_RESULT();
  62540. }
  62541. #if defined(OPENSSL_ALL) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  62542. defined(HAVE_HTTP_CLIENT)
  62543. static THREAD_RETURN WOLFSSL_THREAD test_wolfSSL_BIO_accept_client(void* args)
  62544. {
  62545. BIO* clientBio;
  62546. SSL* sslClient;
  62547. SSL_CTX* ctx;
  62548. char connectAddr[20]; /* IP + port */;
  62549. (void)args;
  62550. AssertIntGT(snprintf(connectAddr, sizeof(connectAddr), "%s:%d", wolfSSLIP, wolfSSLPort), 0);
  62551. AssertNotNull(clientBio = BIO_new_connect(connectAddr));
  62552. AssertIntEQ(BIO_do_connect(clientBio), 1);
  62553. AssertNotNull(ctx = SSL_CTX_new(SSLv23_method()));
  62554. AssertNotNull(sslClient = SSL_new(ctx));
  62555. AssertIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0), WOLFSSL_SUCCESS);
  62556. SSL_set_bio(sslClient, clientBio, clientBio);
  62557. AssertIntEQ(SSL_connect(sslClient), 1);
  62558. SSL_free(sslClient);
  62559. SSL_CTX_free(ctx);
  62560. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
  62561. wc_ecc_fp_free(); /* free per thread cache */
  62562. #endif
  62563. WOLFSSL_RETURN_FROM_THREAD(0);
  62564. }
  62565. #endif
  62566. static int test_wolfSSL_BIO_accept(void)
  62567. {
  62568. EXPECT_DECLS;
  62569. #if defined(OPENSSL_ALL) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  62570. defined(HAVE_HTTP_CLIENT)
  62571. BIO* serverBindBio = NULL;
  62572. BIO* serverAcceptBio = NULL;
  62573. SSL* sslServer = NULL;
  62574. SSL_CTX* ctx = NULL;
  62575. func_args args;
  62576. THREAD_TYPE thread;
  62577. char port[10]; /* 10 bytes should be enough to store the string
  62578. * representation of the port */
  62579. ExpectIntGT(snprintf(port, sizeof(port), "%d", wolfSSLPort), 0);
  62580. ExpectNotNull(serverBindBio = BIO_new_accept(port));
  62581. /* First BIO_do_accept binds the port */
  62582. ExpectIntEQ(BIO_do_accept(serverBindBio), 1);
  62583. XMEMSET(&args, 0, sizeof(func_args));
  62584. start_thread(test_wolfSSL_BIO_accept_client, &args, &thread);
  62585. ExpectIntEQ(BIO_do_accept(serverBindBio), 1);
  62586. /* Let's plug it into SSL to test */
  62587. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_method()));
  62588. ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  62589. SSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  62590. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  62591. SSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  62592. ExpectNotNull(sslServer = SSL_new(ctx));
  62593. ExpectNotNull(serverAcceptBio = BIO_pop(serverBindBio));
  62594. SSL_set_bio(sslServer, serverAcceptBio, serverAcceptBio);
  62595. ExpectIntEQ(SSL_accept(sslServer), 1);
  62596. join_thread(thread);
  62597. BIO_free(serverBindBio);
  62598. SSL_free(sslServer);
  62599. SSL_CTX_free(ctx);
  62600. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
  62601. wc_ecc_fp_free(); /* free per thread cache */
  62602. #endif
  62603. #endif
  62604. return EXPECT_RESULT();
  62605. }
  62606. static int test_wolfSSL_BIO_write(void)
  62607. {
  62608. EXPECT_DECLS;
  62609. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_ENCODE)
  62610. BIO* bio = NULL;
  62611. BIO* bio64 = NULL;
  62612. BIO* bio_mem = NULL;
  62613. BIO* ptr = NULL;
  62614. int sz;
  62615. char msg[] = "conversion test";
  62616. char out[40];
  62617. char expected[] = "Y29udmVyc2lvbiB0ZXN0AA==\n";
  62618. void* bufPtr = NULL;
  62619. BUF_MEM* buf = NULL;
  62620. ExpectNotNull(bio64 = BIO_new(BIO_f_base64()));
  62621. ExpectNotNull(bio = BIO_push(bio64, BIO_new(BIO_s_mem())));
  62622. if (EXPECT_FAIL()) {
  62623. BIO_free(bio64);
  62624. }
  62625. /* now should convert to base64 then write to memory */
  62626. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), sizeof(msg));
  62627. BIO_flush(bio);
  62628. /* test BIO chain */
  62629. ExpectIntEQ(SSL_SUCCESS, (int)BIO_get_mem_ptr(bio, &buf));
  62630. ExpectNotNull(buf);
  62631. ExpectIntEQ(buf->length, 25);
  62632. ExpectIntEQ(BIO_get_mem_data(bio, &bufPtr), 25);
  62633. ExpectPtrEq(buf->data, bufPtr);
  62634. ExpectNotNull(ptr = BIO_find_type(bio, BIO_TYPE_MEM));
  62635. sz = sizeof(out);
  62636. XMEMSET(out, 0, sz);
  62637. ExpectIntEQ((sz = BIO_read(ptr, out, sz)), 25);
  62638. ExpectIntEQ(XMEMCMP(out, expected, sz), 0);
  62639. /* write then read should return the same message */
  62640. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), sizeof(msg));
  62641. sz = sizeof(out);
  62642. XMEMSET(out, 0, sz);
  62643. ExpectIntEQ(BIO_read(bio, out, sz), 16);
  62644. ExpectIntEQ(XMEMCMP(out, msg, sizeof(msg)), 0);
  62645. /* now try encoding with no line ending */
  62646. BIO_set_flags(bio64, BIO_FLAGS_BASE64_NO_NL);
  62647. #ifdef HAVE_EX_DATA
  62648. BIO_set_ex_data(bio64, 0, (void*) "data");
  62649. ExpectIntEQ(strcmp((const char*)BIO_get_ex_data(bio64, 0), "data"), 0);
  62650. #endif
  62651. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), sizeof(msg));
  62652. BIO_flush(bio);
  62653. sz = sizeof(out);
  62654. XMEMSET(out, 0, sz);
  62655. ExpectIntEQ((sz = BIO_read(ptr, out, sz)), 24);
  62656. ExpectIntEQ(XMEMCMP(out, expected, sz), 0);
  62657. BIO_free_all(bio); /* frees bio64 also */
  62658. bio = NULL;
  62659. /* test with more than one bio64 in list */
  62660. ExpectNotNull(bio64 = BIO_new(BIO_f_base64()));
  62661. ExpectNotNull(bio = BIO_push(BIO_new(BIO_f_base64()), bio64));
  62662. if (EXPECT_FAIL()) {
  62663. BIO_free(bio64);
  62664. bio64 = NULL;
  62665. }
  62666. ExpectNotNull(bio_mem = BIO_new(BIO_s_mem()));
  62667. ExpectNotNull(BIO_push(bio64, bio_mem));
  62668. if (EXPECT_FAIL()) {
  62669. BIO_free(bio_mem);
  62670. }
  62671. /* now should convert to base64 when stored and then decode with read */
  62672. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), 25);
  62673. BIO_flush(bio);
  62674. sz = sizeof(out);
  62675. XMEMSET(out, 0, sz);
  62676. ExpectIntEQ((sz = BIO_read(bio, out, sz)), 16);
  62677. ExpectIntEQ(XMEMCMP(out, msg, sz), 0);
  62678. BIO_clear_flags(bio64, ~0);
  62679. BIO_set_retry_read(bio);
  62680. BIO_free_all(bio); /* frees bio64s also */
  62681. bio = NULL;
  62682. ExpectNotNull(bio = BIO_new_mem_buf(out, 0));
  62683. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), sizeof(msg));
  62684. BIO_free(bio);
  62685. #endif
  62686. return EXPECT_RESULT();
  62687. }
  62688. static int test_wolfSSL_BIO_printf(void)
  62689. {
  62690. EXPECT_DECLS;
  62691. #if defined(OPENSSL_ALL)
  62692. BIO* bio = NULL;
  62693. int sz = 7;
  62694. char msg[] = "TLS 1.3 for the world";
  62695. char out[60];
  62696. char expected[] = "TLS 1.3 for the world : sz = 7";
  62697. XMEMSET(out, 0, sizeof(out));
  62698. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  62699. ExpectIntEQ(BIO_printf(bio, "%s : sz = %d", msg, sz), 30);
  62700. ExpectIntEQ(BIO_printf(NULL, ""), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  62701. ExpectIntEQ(BIO_read(bio, out, sizeof(out)), 30);
  62702. ExpectIntEQ(XSTRNCMP(out, expected, sizeof(expected)), 0);
  62703. BIO_free(bio);
  62704. #endif
  62705. return EXPECT_RESULT();
  62706. }
  62707. static int test_wolfSSL_BIO_f_md(void)
  62708. {
  62709. EXPECT_DECLS;
  62710. #if defined(OPENSSL_ALL) && !defined(NO_SHA256)
  62711. BIO* bio = NULL;
  62712. BIO* mem = NULL;
  62713. char msg[] = "message to hash";
  62714. char out[60];
  62715. EVP_MD_CTX* ctx = NULL;
  62716. const unsigned char testKey[] =
  62717. {
  62718. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  62719. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  62720. 0x0b, 0x0b, 0x0b, 0x0b
  62721. };
  62722. const char testData[] = "Hi There";
  62723. const unsigned char testResult[] =
  62724. {
  62725. 0xb0, 0x34, 0x4c, 0x61, 0xd8, 0xdb, 0x38, 0x53,
  62726. 0x5c, 0xa8, 0xaf, 0xce, 0xaf, 0x0b, 0xf1, 0x2b,
  62727. 0x88, 0x1d, 0xc2, 0x00, 0xc9, 0x83, 0x3d, 0xa7,
  62728. 0x26, 0xe9, 0x37, 0x6c, 0x2e, 0x32, 0xcf, 0xf7
  62729. };
  62730. const unsigned char expectedHash[] =
  62731. {
  62732. 0x66, 0x49, 0x3C, 0xE8, 0x8A, 0x57, 0xB0, 0x60,
  62733. 0xDC, 0x55, 0x7D, 0xFC, 0x1F, 0xA5, 0xE5, 0x07,
  62734. 0x70, 0x5A, 0xF6, 0xD7, 0xC4, 0x1F, 0x1A, 0xE4,
  62735. 0x2D, 0xA6, 0xFD, 0xD1, 0x29, 0x7D, 0x60, 0x0D
  62736. };
  62737. const unsigned char emptyHash[] =
  62738. {
  62739. 0xE3, 0xB0, 0xC4, 0x42, 0x98, 0xFC, 0x1C, 0x14,
  62740. 0x9A, 0xFB, 0xF4, 0xC8, 0x99, 0x6F, 0xB9, 0x24,
  62741. 0x27, 0xAE, 0x41, 0xE4, 0x64, 0x9B, 0x93, 0x4C,
  62742. 0xA4, 0x95, 0x99, 0x1B, 0x78, 0x52, 0xB8, 0x55
  62743. };
  62744. unsigned char check[sizeof(testResult) + 1];
  62745. size_t checkSz = -1;
  62746. EVP_PKEY* key = NULL;
  62747. XMEMSET(out, 0, sizeof(out));
  62748. ExpectNotNull(bio = BIO_new(BIO_f_md()));
  62749. ExpectNotNull(mem = BIO_new(BIO_s_mem()));
  62750. ExpectIntEQ(BIO_get_md_ctx(bio, &ctx), 1);
  62751. ExpectIntEQ(EVP_DigestInit(ctx, EVP_sha256()), 1);
  62752. /* should not be able to write/read yet since just digest wrapper and no
  62753. * data is passing through the bio */
  62754. ExpectIntEQ(BIO_write(bio, msg, 0), 0);
  62755. ExpectIntEQ(BIO_pending(bio), 0);
  62756. ExpectIntEQ(BIO_read(bio, out, sizeof(out)), 0);
  62757. ExpectIntEQ(BIO_gets(bio, out, 3), 0);
  62758. ExpectIntEQ(BIO_gets(bio, out, sizeof(out)), 32);
  62759. ExpectIntEQ(XMEMCMP(emptyHash, out, 32), 0);
  62760. BIO_reset(bio);
  62761. /* append BIO mem to bio in order to read/write */
  62762. ExpectNotNull(bio = BIO_push(bio, mem));
  62763. XMEMSET(out, 0, sizeof(out));
  62764. ExpectIntEQ(BIO_write(mem, msg, sizeof(msg)), 16);
  62765. ExpectIntEQ(BIO_pending(bio), 16);
  62766. /* this just reads the message and does not hash it (gets calls final) */
  62767. ExpectIntEQ(BIO_read(bio, out, sizeof(out)), 16);
  62768. ExpectIntEQ(XMEMCMP(out, msg, sizeof(msg)), 0);
  62769. /* create a message digest using BIO */
  62770. XMEMSET(out, 0, sizeof(out));
  62771. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), 16);
  62772. ExpectIntEQ(BIO_pending(mem), 16);
  62773. ExpectIntEQ(BIO_pending(bio), 16);
  62774. ExpectIntEQ(BIO_gets(bio, out, sizeof(out)), 32);
  62775. ExpectIntEQ(XMEMCMP(expectedHash, out, 32), 0);
  62776. BIO_free(bio);
  62777. bio = NULL;
  62778. BIO_free(mem);
  62779. mem = NULL;
  62780. /* test with HMAC */
  62781. XMEMSET(out, 0, sizeof(out));
  62782. ExpectNotNull(bio = BIO_new(BIO_f_md()));
  62783. ExpectNotNull(mem = BIO_new(BIO_s_mem()));
  62784. BIO_get_md_ctx(bio, &ctx);
  62785. ExpectNotNull(key = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, testKey,
  62786. (int)sizeof(testKey)));
  62787. EVP_DigestSignInit(ctx, NULL, EVP_sha256(), NULL, key);
  62788. ExpectNotNull(bio = BIO_push(bio, mem));
  62789. BIO_write(bio, testData, (int)strlen(testData));
  62790. ExpectIntEQ(EVP_DigestSignFinal(ctx, NULL, &checkSz), 1);
  62791. ExpectIntEQ(EVP_DigestSignFinal(ctx, check, &checkSz), 1);
  62792. ExpectIntEQ(XMEMCMP(check, testResult, sizeof(testResult)), 0);
  62793. EVP_PKEY_free(key);
  62794. BIO_free(bio);
  62795. BIO_free(mem);
  62796. #endif
  62797. return EXPECT_RESULT();
  62798. }
  62799. static int test_wolfSSL_BIO_up_ref(void)
  62800. {
  62801. EXPECT_DECLS;
  62802. #if defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA)
  62803. BIO* bio = NULL;
  62804. ExpectNotNull(bio = BIO_new(BIO_f_md()));
  62805. ExpectIntEQ(BIO_up_ref(NULL), 0);
  62806. ExpectIntEQ(BIO_up_ref(bio), 1);
  62807. BIO_free(bio);
  62808. ExpectIntEQ(BIO_up_ref(bio), 1);
  62809. BIO_free(bio);
  62810. BIO_free(bio);
  62811. #endif
  62812. return EXPECT_RESULT();
  62813. }
  62814. static int test_wolfSSL_BIO_reset(void)
  62815. {
  62816. EXPECT_DECLS;
  62817. #if defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA)
  62818. BIO* bio = NULL;
  62819. byte buf[16];
  62820. ExpectNotNull(bio = BIO_new_mem_buf("secure your data",
  62821. (word32)XSTRLEN("secure your data")));
  62822. ExpectIntEQ(BIO_read(bio, buf, 6), 6);
  62823. ExpectIntEQ(XMEMCMP(buf, "secure", 6), 0);
  62824. XMEMSET(buf, 0, 16);
  62825. ExpectIntEQ(BIO_read(bio, buf, 16), 10);
  62826. ExpectIntEQ(XMEMCMP(buf, " your data", 10), 0);
  62827. /* You cannot write to MEM BIO with read-only mode. */
  62828. ExpectIntEQ(BIO_write(bio, "WriteToReadonly", 15), 0);
  62829. ExpectIntEQ(BIO_read(bio, buf, 16), -1);
  62830. XMEMSET(buf, 0, 16);
  62831. ExpectIntEQ(BIO_reset(bio), 1);
  62832. ExpectIntEQ(BIO_read(bio, buf, 16), 16);
  62833. ExpectIntEQ(XMEMCMP(buf, "secure your data", 16), 0);
  62834. BIO_free(bio);
  62835. #endif
  62836. return EXPECT_RESULT();
  62837. }
  62838. #endif /* !NO_BIO */
  62839. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  62840. /* test that the callback arg is correct */
  62841. static int certCbArg = 0;
  62842. static int certCb(WOLFSSL* ssl, void* arg)
  62843. {
  62844. if (ssl == NULL || arg != &certCbArg)
  62845. return 0;
  62846. if (wolfSSL_is_server(ssl)) {
  62847. if (wolfSSL_use_certificate_file(ssl, svrCertFile,
  62848. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS)
  62849. return 0;
  62850. if (wolfSSL_use_PrivateKey_file(ssl, svrKeyFile,
  62851. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS)
  62852. return 0;
  62853. }
  62854. else {
  62855. if (wolfSSL_use_certificate_file(ssl, cliCertFile,
  62856. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS)
  62857. return 0;
  62858. if (wolfSSL_use_PrivateKey_file(ssl, cliKeyFile,
  62859. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS)
  62860. return 0;
  62861. }
  62862. return 1;
  62863. }
  62864. static int certSetupCb(WOLFSSL_CTX* ctx)
  62865. {
  62866. SSL_CTX_set_cert_cb(ctx, certCb, &certCbArg);
  62867. return TEST_SUCCESS;
  62868. }
  62869. /**
  62870. * This is only done because test_wolfSSL_client_server_nofail_memio has no way
  62871. * to stop certificate and key loading
  62872. */
  62873. static int certClearCb(WOLFSSL* ssl)
  62874. {
  62875. /* Clear the loaded certs to force the callbacks to set them up */
  62876. SSL_certs_clear(ssl);
  62877. return TEST_SUCCESS;
  62878. }
  62879. #endif
  62880. static int test_wolfSSL_cert_cb(void)
  62881. {
  62882. EXPECT_DECLS;
  62883. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  62884. test_ssl_cbf func_cb_client;
  62885. test_ssl_cbf func_cb_server;
  62886. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  62887. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  62888. func_cb_client.ctx_ready = certSetupCb;
  62889. func_cb_client.ssl_ready = certClearCb;
  62890. func_cb_server.ctx_ready = certSetupCb;
  62891. func_cb_server.ssl_ready = certClearCb;
  62892. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  62893. &func_cb_server, NULL), TEST_SUCCESS);
  62894. #endif
  62895. return EXPECT_RESULT();
  62896. }
  62897. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  62898. static const char* test_wolfSSL_cert_cb_dyn_ciphers_client_cipher = NULL;
  62899. static const char* test_wolfSSL_cert_cb_dyn_ciphers_client_sigalgs = NULL;
  62900. static int test_wolfSSL_cert_cb_dyn_ciphers_client_ctx_ready(WOLFSSL_CTX* ctx)
  62901. {
  62902. EXPECT_DECLS;
  62903. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx,
  62904. test_wolfSSL_cert_cb_dyn_ciphers_client_cipher), WOLFSSL_SUCCESS);
  62905. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx,
  62906. test_wolfSSL_cert_cb_dyn_ciphers_client_sigalgs), WOLFSSL_SUCCESS);
  62907. return EXPECT_RESULT();
  62908. }
  62909. static int test_wolfSSL_cert_cb_dyn_ciphers_certCB(WOLFSSL* ssl, void* arg)
  62910. {
  62911. const byte* suites = NULL;
  62912. word16 suiteSz = 0;
  62913. const byte* hashSigAlgo = NULL;
  62914. word16 hashSigAlgoSz = 0;
  62915. word16 idx = 0;
  62916. int haveRSA = 0;
  62917. int haveECC = 0;
  62918. (void)arg;
  62919. if (wolfSSL_get_client_suites_sigalgs(ssl, &suites, &suiteSz, &hashSigAlgo,
  62920. &hashSigAlgoSz) != WOLFSSL_SUCCESS)
  62921. return 0;
  62922. if (suites == NULL || suiteSz == 0 || hashSigAlgo == NULL ||
  62923. hashSigAlgoSz == 0)
  62924. return 0;
  62925. for (idx = 0; idx < suiteSz; idx += 2) {
  62926. WOLFSSL_CIPHERSUITE_INFO info =
  62927. wolfSSL_get_ciphersuite_info(suites[idx], suites[idx+1]);
  62928. if (info.rsaAuth)
  62929. haveRSA = 1;
  62930. else if (info.eccAuth)
  62931. haveECC = 1;
  62932. }
  62933. if (hashSigAlgoSz > 0) {
  62934. /* sigalgs extension takes precedence over ciphersuites */
  62935. haveRSA = 0;
  62936. haveECC = 0;
  62937. }
  62938. for (idx = 0; idx < hashSigAlgoSz; idx += 2) {
  62939. int hashAlgo = 0;
  62940. int sigAlgo = 0;
  62941. if (wolfSSL_get_sigalg_info(hashSigAlgo[idx+0], hashSigAlgo[idx+1],
  62942. &hashAlgo, &sigAlgo) != 0)
  62943. return 0;
  62944. if (sigAlgo == RSAk || sigAlgo == RSAPSSk)
  62945. haveRSA = 1;
  62946. else if (sigAlgo == ECDSAk)
  62947. haveECC = 1;
  62948. }
  62949. if (haveRSA) {
  62950. if (wolfSSL_use_certificate_file(ssl, svrCertFile, WOLFSSL_FILETYPE_PEM)
  62951. != WOLFSSL_SUCCESS)
  62952. return 0;
  62953. if (wolfSSL_use_PrivateKey_file(ssl, svrKeyFile, WOLFSSL_FILETYPE_PEM)
  62954. != WOLFSSL_SUCCESS)
  62955. return 0;
  62956. }
  62957. else if (haveECC) {
  62958. if (wolfSSL_use_certificate_file(ssl, eccCertFile, WOLFSSL_FILETYPE_PEM)
  62959. != WOLFSSL_SUCCESS)
  62960. return 0;
  62961. if (wolfSSL_use_PrivateKey_file(ssl, eccKeyFile, WOLFSSL_FILETYPE_PEM)
  62962. != WOLFSSL_SUCCESS)
  62963. return 0;
  62964. }
  62965. return 1;
  62966. }
  62967. static int test_wolfSSL_cert_cb_dyn_ciphers_server_ctx_ready(WOLFSSL_CTX* ctx)
  62968. {
  62969. SSL_CTX_set_cert_cb(ctx, test_wolfSSL_cert_cb_dyn_ciphers_certCB, NULL);
  62970. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_NONE, NULL);
  62971. return TEST_SUCCESS;
  62972. }
  62973. #endif
  62974. /* Testing dynamic ciphers offered by client */
  62975. static int test_wolfSSL_cert_cb_dyn_ciphers(void)
  62976. {
  62977. EXPECT_DECLS;
  62978. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  62979. test_ssl_cbf func_cb_client;
  62980. test_ssl_cbf func_cb_server;
  62981. struct {
  62982. method_provider client_meth;
  62983. const char* client_ciphers;
  62984. const char* client_sigalgs;
  62985. const char* client_ca;
  62986. method_provider server_meth;
  62987. } test_params[] = {
  62988. #if !defined(NO_SHA256) && defined(HAVE_AESGCM)
  62989. #ifdef WOLFSSL_TLS13
  62990. #if !defined(NO_RSA) && defined(WC_RSA_PSS)
  62991. {wolfTLSv1_3_client_method,
  62992. "TLS13-AES256-GCM-SHA384:TLS13-AES128-GCM-SHA256",
  62993. "RSA-PSS+SHA256", caCertFile, wolfTLSv1_3_server_method},
  62994. #endif
  62995. #ifdef HAVE_ECC
  62996. {wolfTLSv1_3_client_method,
  62997. "TLS13-AES256-GCM-SHA384:TLS13-AES128-GCM-SHA256",
  62998. "ECDSA+SHA256", caEccCertFile, wolfTLSv1_3_server_method},
  62999. #endif
  63000. #endif
  63001. #ifndef WOLFSSL_NO_TLS12
  63002. #if !defined(NO_RSA) && defined(WC_RSA_PSS) && !defined(NO_DH)
  63003. {wolfTLSv1_2_client_method,
  63004. "DHE-RSA-AES128-GCM-SHA256",
  63005. "RSA-PSS+SHA256", caCertFile, wolfTLSv1_2_server_method},
  63006. #endif
  63007. #ifdef HAVE_ECC
  63008. {wolfTLSv1_2_client_method,
  63009. "ECDHE-ECDSA-AES128-GCM-SHA256",
  63010. "ECDSA+SHA256", caEccCertFile, wolfTLSv1_2_server_method},
  63011. #endif
  63012. #endif
  63013. #endif
  63014. };
  63015. size_t i;
  63016. size_t testCount = sizeof(test_params)/sizeof(*test_params);
  63017. if (testCount > 0) {
  63018. for (i = 0; i < testCount; i++) {
  63019. printf("\tTesting %s ciphers with %s sigalgs\n",
  63020. test_params[i].client_ciphers,
  63021. test_params[i].client_sigalgs);
  63022. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  63023. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  63024. test_wolfSSL_cert_cb_dyn_ciphers_client_cipher =
  63025. test_params[i].client_ciphers;
  63026. test_wolfSSL_cert_cb_dyn_ciphers_client_sigalgs =
  63027. test_params[i].client_sigalgs;
  63028. func_cb_client.method = test_params[i].client_meth;
  63029. func_cb_client.caPemFile = test_params[i].client_ca;
  63030. func_cb_client.ctx_ready =
  63031. test_wolfSSL_cert_cb_dyn_ciphers_client_ctx_ready;
  63032. func_cb_server.ctx_ready =
  63033. test_wolfSSL_cert_cb_dyn_ciphers_server_ctx_ready;
  63034. func_cb_server.ssl_ready = certClearCb; /* Reuse from prev test */
  63035. func_cb_server.method = test_params[i].server_meth;
  63036. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  63037. &func_cb_server, NULL), TEST_SUCCESS);
  63038. }
  63039. }
  63040. #endif
  63041. return EXPECT_RESULT();
  63042. }
  63043. static int test_wolfSSL_ciphersuite_auth(void)
  63044. {
  63045. EXPECT_DECLS;
  63046. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EXTRA)
  63047. WOLFSSL_CIPHERSUITE_INFO info;
  63048. (void)info;
  63049. #ifndef WOLFSSL_NO_TLS12
  63050. #ifdef HAVE_CHACHA
  63051. info = wolfSSL_get_ciphersuite_info(CHACHA_BYTE,
  63052. TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256);
  63053. ExpectIntEQ(info.rsaAuth, 1);
  63054. ExpectIntEQ(info.eccAuth, 0);
  63055. ExpectIntEQ(info.eccStatic, 0);
  63056. ExpectIntEQ(info.psk, 0);
  63057. info = wolfSSL_get_ciphersuite_info(CHACHA_BYTE,
  63058. TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256);
  63059. ExpectIntEQ(info.rsaAuth, 0);
  63060. ExpectIntEQ(info.eccAuth, 1);
  63061. ExpectIntEQ(info.eccStatic, 0);
  63062. ExpectIntEQ(info.psk, 0);
  63063. info = wolfSSL_get_ciphersuite_info(CHACHA_BYTE,
  63064. TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256);
  63065. ExpectIntEQ(info.rsaAuth, 0);
  63066. ExpectIntEQ(info.eccAuth, 0);
  63067. ExpectIntEQ(info.eccStatic, 0);
  63068. ExpectIntEQ(info.psk, 1);
  63069. #endif
  63070. #if defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)
  63071. #ifndef NO_RSA
  63072. info = wolfSSL_get_ciphersuite_info(ECC_BYTE,
  63073. TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA);
  63074. ExpectIntEQ(info.rsaAuth, 1);
  63075. ExpectIntEQ(info.eccAuth, 0);
  63076. ExpectIntEQ(info.eccStatic, 0);
  63077. ExpectIntEQ(info.psk, 0);
  63078. info = wolfSSL_get_ciphersuite_info(ECC_BYTE,
  63079. TLS_ECDH_RSA_WITH_AES_128_CBC_SHA);
  63080. ExpectIntEQ(info.rsaAuth, 1);
  63081. ExpectIntEQ(info.eccAuth, 0);
  63082. ExpectIntEQ(info.eccStatic, 1);
  63083. ExpectIntEQ(info.psk, 0);
  63084. info = wolfSSL_get_ciphersuite_info(ECC_BYTE,
  63085. TLS_ECDH_RSA_WITH_AES_256_CBC_SHA);
  63086. ExpectIntEQ(info.rsaAuth, 1);
  63087. ExpectIntEQ(info.eccAuth, 0);
  63088. ExpectIntEQ(info.eccStatic, 1);
  63089. ExpectIntEQ(info.psk, 0);
  63090. #endif
  63091. info = wolfSSL_get_ciphersuite_info(ECC_BYTE,
  63092. TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA);
  63093. ExpectIntEQ(info.rsaAuth, 0);
  63094. ExpectIntEQ(info.eccAuth, 1);
  63095. ExpectIntEQ(info.eccStatic, 0);
  63096. ExpectIntEQ(info.psk, 0);
  63097. info = wolfSSL_get_ciphersuite_info(ECC_BYTE,
  63098. TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA);
  63099. ExpectIntEQ(info.rsaAuth, 0);
  63100. ExpectIntEQ(info.eccAuth, 1);
  63101. ExpectIntEQ(info.eccStatic, 1);
  63102. ExpectIntEQ(info.psk, 0);
  63103. info = wolfSSL_get_ciphersuite_info(ECDHE_PSK_BYTE,
  63104. TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256);
  63105. ExpectIntEQ(info.rsaAuth, 0);
  63106. ExpectIntEQ(info.eccAuth, 0);
  63107. ExpectIntEQ(info.eccStatic, 0);
  63108. ExpectIntEQ(info.psk, 1);
  63109. #endif
  63110. #endif
  63111. #ifdef WOLFSSL_TLS13
  63112. info = wolfSSL_get_ciphersuite_info(TLS13_BYTE,
  63113. TLS_AES_128_GCM_SHA256);
  63114. ExpectIntEQ(info.rsaAuth, 0);
  63115. ExpectIntEQ(info.eccAuth, 0);
  63116. ExpectIntEQ(info.eccStatic, 0);
  63117. ExpectIntEQ(info.psk, 0);
  63118. #endif
  63119. #endif
  63120. return EXPECT_RESULT();
  63121. }
  63122. static int test_wolfSSL_sigalg_info(void)
  63123. {
  63124. EXPECT_DECLS;
  63125. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EXTRA)
  63126. byte hashSigAlgo[WOLFSSL_MAX_SIGALGO];
  63127. word16 len = 0;
  63128. word16 idx = 0;
  63129. int allSigAlgs = SIG_ECDSA | SIG_RSA | SIG_SM2 | SIG_FALCON | SIG_DILITHIUM;
  63130. InitSuitesHashSigAlgo(hashSigAlgo, allSigAlgs, 1, 0xFFFFFFFF, &len);
  63131. for (idx = 0; idx < len; idx += 2) {
  63132. int hashAlgo = 0;
  63133. int sigAlgo = 0;
  63134. ExpectIntEQ(wolfSSL_get_sigalg_info(hashSigAlgo[idx+0],
  63135. hashSigAlgo[idx+1], &hashAlgo, &sigAlgo), 0);
  63136. ExpectIntNE(hashAlgo, 0);
  63137. ExpectIntNE(sigAlgo, 0);
  63138. }
  63139. InitSuitesHashSigAlgo(hashSigAlgo, allSigAlgs | SIG_ANON, 1,
  63140. 0xFFFFFFFF, &len);
  63141. for (idx = 0; idx < len; idx += 2) {
  63142. int hashAlgo = 0;
  63143. int sigAlgo = 0;
  63144. ExpectIntEQ(wolfSSL_get_sigalg_info(hashSigAlgo[idx+0],
  63145. hashSigAlgo[idx+1], &hashAlgo, &sigAlgo), 0);
  63146. ExpectIntNE(hashAlgo, 0);
  63147. }
  63148. #endif
  63149. return EXPECT_RESULT();
  63150. }
  63151. static int test_wolfSSL_SESSION(void)
  63152. {
  63153. EXPECT_DECLS;
  63154. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  63155. !defined(NO_RSA) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  63156. !defined(NO_SESSION_CACHE)
  63157. WOLFSSL* ssl = NULL;
  63158. WOLFSSL_CTX* ctx = NULL;
  63159. WOLFSSL_SESSION* sess = NULL;
  63160. WOLFSSL_SESSION* sess_copy = NULL;
  63161. #ifdef OPENSSL_EXTRA
  63162. #ifdef HAVE_EXT_CACHE
  63163. unsigned char* sessDer = NULL;
  63164. unsigned char* ptr = NULL;
  63165. int sz = 0;
  63166. #endif
  63167. const unsigned char context[] = "user app context";
  63168. unsigned int contextSz = (unsigned int)sizeof(context);
  63169. #endif
  63170. int ret = 0, err = 0;
  63171. SOCKET_T sockfd;
  63172. tcp_ready ready;
  63173. func_args server_args;
  63174. THREAD_TYPE serverThread;
  63175. char msg[80];
  63176. const char* sendGET = "GET";
  63177. /* TLS v1.3 requires session tickets */
  63178. /* CHACHA and POLY1305 required for myTicketEncCb */
  63179. #if !defined(WOLFSSL_NO_TLS12) && (!defined(WOLFSSL_TLS13) || \
  63180. !(defined(HAVE_SESSION_TICKET) && ((defined(HAVE_CHACHA) && \
  63181. defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))))
  63182. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  63183. #else
  63184. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  63185. #endif
  63186. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, cliCertFile,
  63187. WOLFSSL_FILETYPE_PEM));
  63188. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile,
  63189. WOLFSSL_FILETYPE_PEM));
  63190. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0),
  63191. WOLFSSL_SUCCESS);
  63192. #ifdef WOLFSSL_ENCRYPTED_KEYS
  63193. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  63194. #endif
  63195. #ifdef HAVE_SESSION_TICKET
  63196. /* Use session tickets, for ticket tests below */
  63197. ExpectIntEQ(wolfSSL_CTX_UseSessionTicket(ctx), WOLFSSL_SUCCESS);
  63198. #endif
  63199. XMEMSET(&server_args, 0, sizeof(func_args));
  63200. #ifdef WOLFSSL_TIRTOS
  63201. fdOpenSession(Task_self());
  63202. #endif
  63203. StartTCP();
  63204. InitTcpReady(&ready);
  63205. #if defined(USE_WINDOWS_API)
  63206. /* use RNG to get random port if using windows */
  63207. ready.port = GetRandomPort();
  63208. #endif
  63209. server_args.signal = &ready;
  63210. start_thread(test_server_nofail, &server_args, &serverThread);
  63211. wait_tcp_ready(&server_args);
  63212. /* client connection */
  63213. ExpectNotNull(ssl = wolfSSL_new(ctx));
  63214. tcp_connect(&sockfd, wolfSSLIP, ready.port, 0, 0, ssl);
  63215. ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS);
  63216. #ifdef WOLFSSL_ASYNC_CRYPT
  63217. err = 0; /* Reset error */
  63218. #endif
  63219. do {
  63220. #ifdef WOLFSSL_ASYNC_CRYPT
  63221. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  63222. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  63223. if (ret < 0) { break; } else if (ret == 0) { continue; }
  63224. }
  63225. #endif
  63226. ret = wolfSSL_connect(ssl);
  63227. err = wolfSSL_get_error(ssl, 0);
  63228. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  63229. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  63230. #ifdef WOLFSSL_ASYNC_CRYPT
  63231. err = 0; /* Reset error */
  63232. #endif
  63233. do {
  63234. #ifdef WOLFSSL_ASYNC_CRYPT
  63235. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  63236. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  63237. if (ret < 0) { break; } else if (ret == 0) { continue; }
  63238. }
  63239. #endif
  63240. ret = wolfSSL_write(ssl, sendGET, (int)XSTRLEN(sendGET));
  63241. err = wolfSSL_get_error(ssl, 0);
  63242. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  63243. ExpectIntEQ(ret, (int)XSTRLEN(sendGET));
  63244. #ifdef WOLFSSL_ASYNC_CRYPT
  63245. err = 0; /* Reset error */
  63246. #endif
  63247. do {
  63248. #ifdef WOLFSSL_ASYNC_CRYPT
  63249. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  63250. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  63251. if (ret < 0) { break; } else if (ret == 0) { continue; }
  63252. }
  63253. #endif
  63254. ret = wolfSSL_read(ssl, msg, sizeof(msg));
  63255. err = wolfSSL_get_error(ssl, 0);
  63256. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  63257. ExpectIntEQ(ret, 23);
  63258. ExpectPtrNE((sess = wolfSSL_get1_session(ssl)), NULL); /* ref count 1 */
  63259. ExpectPtrNE((sess_copy = wolfSSL_get1_session(ssl)), NULL); /* ref count 2 */
  63260. ExpectIntEQ(wolfSSL_SessionIsSetup(sess), 1);
  63261. #ifdef HAVE_EXT_CACHE
  63262. ExpectPtrEq(sess, sess_copy); /* they should be the same pointer but without
  63263. * HAVE_EXT_CACHE we get new objects each time */
  63264. #endif
  63265. wolfSSL_SESSION_free(sess_copy); sess_copy = NULL;
  63266. wolfSSL_SESSION_free(sess); sess = NULL; /* free session ref */
  63267. sess = wolfSSL_get_session(ssl);
  63268. #ifdef OPENSSL_EXTRA
  63269. ExpectIntEQ(SSL_SESSION_is_resumable(NULL), 0);
  63270. ExpectIntEQ(SSL_SESSION_is_resumable(sess), 1);
  63271. ExpectIntEQ(wolfSSL_SESSION_has_ticket(NULL), 0);
  63272. ExpectIntEQ(wolfSSL_SESSION_get_ticket_lifetime_hint(NULL), 0);
  63273. #ifdef HAVE_SESSION_TICKET
  63274. ExpectIntEQ(wolfSSL_SESSION_has_ticket(sess), 1);
  63275. ExpectIntEQ(wolfSSL_SESSION_get_ticket_lifetime_hint(sess),
  63276. SESSION_TICKET_HINT_DEFAULT);
  63277. #else
  63278. ExpectIntEQ(wolfSSL_SESSION_has_ticket(sess), 0);
  63279. #endif
  63280. #else
  63281. (void)sess;
  63282. #endif /* OPENSSL_EXTRA */
  63283. /* Retain copy of the session for later testing */
  63284. ExpectNotNull(sess = wolfSSL_get1_session(ssl));
  63285. wolfSSL_shutdown(ssl);
  63286. wolfSSL_free(ssl); ssl = NULL;
  63287. CloseSocket(sockfd);
  63288. join_thread(serverThread);
  63289. FreeTcpReady(&ready);
  63290. #ifdef WOLFSSL_TIRTOS
  63291. fdOpenSession(Task_self());
  63292. #endif
  63293. #if defined(SESSION_CERTS) && defined(OPENSSL_EXTRA)
  63294. {
  63295. X509 *x509 = NULL;
  63296. char buf[30];
  63297. int bufSz = 0;
  63298. ExpectNotNull(x509 = SSL_SESSION_get0_peer(sess));
  63299. ExpectIntGT((bufSz = X509_NAME_get_text_by_NID(
  63300. X509_get_subject_name(x509), NID_organizationalUnitName, buf,
  63301. sizeof(buf))), 0);
  63302. ExpectIntNE((bufSz == 7 || bufSz == 16), 0); /* should be one of these*/
  63303. if (bufSz == 7) {
  63304. ExpectIntEQ(XMEMCMP(buf, "Support", bufSz), 0);
  63305. }
  63306. if (bufSz == 16) {
  63307. ExpectIntEQ(XMEMCMP(buf, "Programming-2048", bufSz), 0);
  63308. }
  63309. }
  63310. #endif
  63311. #ifdef HAVE_EXT_CACHE
  63312. ExpectNotNull(sess_copy = wolfSSL_SESSION_dup(sess));
  63313. wolfSSL_SESSION_free(sess_copy); sess_copy = NULL;
  63314. sess_copy = NULL;
  63315. #endif
  63316. #if defined(OPENSSL_EXTRA) && defined(HAVE_EXT_CACHE)
  63317. /* get session from DER and update the timeout */
  63318. ExpectIntEQ(wolfSSL_i2d_SSL_SESSION(NULL, &sessDer), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  63319. ExpectIntGT((sz = wolfSSL_i2d_SSL_SESSION(sess, &sessDer)), 0);
  63320. wolfSSL_SESSION_free(sess); sess = NULL;
  63321. sess = NULL;
  63322. ptr = sessDer;
  63323. ExpectNull(sess = wolfSSL_d2i_SSL_SESSION(NULL, NULL, sz));
  63324. ExpectNotNull(sess = wolfSSL_d2i_SSL_SESSION(NULL,
  63325. (const unsigned char**)&ptr, sz));
  63326. XFREE(sessDer, NULL, DYNAMIC_TYPE_OPENSSL);
  63327. sessDer = NULL;
  63328. ExpectIntGT(wolfSSL_SESSION_get_time(sess), 0);
  63329. ExpectIntEQ(wolfSSL_SSL_SESSION_set_timeout(sess, 500), SSL_SUCCESS);
  63330. #endif
  63331. /* successful set session test */
  63332. ExpectNotNull(ssl = wolfSSL_new(ctx));
  63333. ExpectIntEQ(wolfSSL_set_session(ssl, sess), WOLFSSL_SUCCESS);
  63334. #ifdef HAVE_SESSION_TICKET
  63335. /* Test set/get session ticket */
  63336. {
  63337. const char* ticket = "This is a session ticket";
  63338. char buf[64] = {0};
  63339. word32 bufSz = (word32)sizeof(buf);
  63340. ExpectIntEQ(SSL_SUCCESS,
  63341. wolfSSL_set_SessionTicket(ssl, (byte *)ticket,
  63342. (word32)XSTRLEN(ticket)));
  63343. ExpectIntEQ(SSL_SUCCESS,
  63344. wolfSSL_get_SessionTicket(ssl, (byte *)buf, &bufSz));
  63345. ExpectStrEQ(ticket, buf);
  63346. }
  63347. #endif
  63348. #ifdef OPENSSL_EXTRA
  63349. /* session timeout case */
  63350. /* make the session to be expired */
  63351. ExpectIntEQ(SSL_SESSION_set_timeout(sess,1), SSL_SUCCESS);
  63352. XSLEEP_MS(1200);
  63353. /* SSL_set_session should reject specified session but return success
  63354. * if WOLFSSL_ERROR_CODE_OPENSSL macro is defined for OpenSSL compatibility.
  63355. */
  63356. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  63357. ExpectIntEQ(wolfSSL_set_session(ssl,sess), SSL_SUCCESS);
  63358. #else
  63359. ExpectIntEQ(wolfSSL_set_session(ssl,sess), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63360. #endif
  63361. ExpectIntEQ(wolfSSL_SSL_SESSION_set_timeout(sess, 500), SSL_SUCCESS);
  63362. #ifdef WOLFSSL_SESSION_ID_CTX
  63363. /* fail case with miss match session context IDs (use compatibility API) */
  63364. ExpectIntEQ(SSL_set_session_id_context(ssl, context, contextSz),
  63365. SSL_SUCCESS);
  63366. ExpectIntEQ(wolfSSL_set_session(ssl, sess), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63367. wolfSSL_free(ssl); ssl = NULL;
  63368. ExpectIntEQ(SSL_CTX_set_session_id_context(NULL, context, contextSz),
  63369. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63370. ExpectIntEQ(SSL_CTX_set_session_id_context(ctx, context, contextSz),
  63371. SSL_SUCCESS);
  63372. ExpectNotNull(ssl = wolfSSL_new(ctx));
  63373. ExpectIntEQ(wolfSSL_set_session(ssl, sess), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63374. #endif
  63375. #endif /* OPENSSL_EXTRA */
  63376. wolfSSL_free(ssl);
  63377. wolfSSL_SESSION_free(sess);
  63378. wolfSSL_CTX_free(ctx);
  63379. #endif
  63380. return EXPECT_RESULT();
  63381. }
  63382. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  63383. !defined(NO_RSA) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  63384. !defined(NO_SESSION_CACHE) && defined(OPENSSL_EXTRA) && \
  63385. !defined(WOLFSSL_NO_TLS12)
  63386. static WOLFSSL_SESSION* test_wolfSSL_SESSION_expire_sess = NULL;
  63387. static void test_wolfSSL_SESSION_expire_downgrade_ctx_ready(WOLFSSL_CTX* ctx)
  63388. {
  63389. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  63390. /* returns previous timeout value */
  63391. AssertIntEQ(wolfSSL_CTX_set_timeout(ctx, 1), 500);
  63392. #else
  63393. AssertIntEQ(wolfSSL_CTX_set_timeout(ctx, 1), WOLFSSL_SUCCESS);
  63394. #endif
  63395. }
  63396. /* set the session to timeout in a second */
  63397. static void test_wolfSSL_SESSION_expire_downgrade_ssl_ready(WOLFSSL* ssl)
  63398. {
  63399. AssertIntEQ(wolfSSL_set_timeout(ssl, 2), 1);
  63400. }
  63401. /* store the client side session from the first successful connection */
  63402. static void test_wolfSSL_SESSION_expire_downgrade_ssl_result(WOLFSSL* ssl)
  63403. {
  63404. AssertPtrNE((test_wolfSSL_SESSION_expire_sess = wolfSSL_get1_session(ssl)),
  63405. NULL); /* ref count 1 */
  63406. }
  63407. /* wait till session is expired then set it in the WOLFSSL struct for use */
  63408. static void test_wolfSSL_SESSION_expire_downgrade_ssl_ready_wait(WOLFSSL* ssl)
  63409. {
  63410. AssertIntEQ(wolfSSL_set_timeout(ssl, 1), 1);
  63411. AssertIntEQ(wolfSSL_set_session(ssl, test_wolfSSL_SESSION_expire_sess),
  63412. WOLFSSL_SUCCESS);
  63413. XSLEEP_MS(2000); /* wait 2 seconds for session to expire */
  63414. }
  63415. /* set expired session in the WOLFSSL struct for use */
  63416. static void test_wolfSSL_SESSION_expire_downgrade_ssl_ready_set(WOLFSSL* ssl)
  63417. {
  63418. XSLEEP_MS(1200); /* wait a second for session to expire */
  63419. /* set the expired session, call to set session fails but continuing on
  63420. after failure should be handled here */
  63421. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_ERROR_CODE_OPENSSL)
  63422. AssertIntEQ(wolfSSL_set_session(ssl, test_wolfSSL_SESSION_expire_sess),
  63423. WOLFSSL_SUCCESS);
  63424. #else
  63425. AssertIntNE(wolfSSL_set_session(ssl, test_wolfSSL_SESSION_expire_sess),
  63426. WOLFSSL_SUCCESS);
  63427. #endif
  63428. }
  63429. /* check that the expired session was not reused */
  63430. static void test_wolfSSL_SESSION_expire_downgrade_ssl_result_reuse(WOLFSSL* ssl)
  63431. {
  63432. /* since the session has expired it should not have been reused */
  63433. AssertIntEQ(wolfSSL_session_reused(ssl), 0);
  63434. }
  63435. #endif
  63436. static int test_wolfSSL_SESSION_expire_downgrade(void)
  63437. {
  63438. EXPECT_DECLS;
  63439. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  63440. !defined(NO_RSA) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  63441. !defined(NO_SESSION_CACHE) && defined(OPENSSL_EXTRA) && \
  63442. !defined(WOLFSSL_NO_TLS12)
  63443. WOLFSSL_CTX* ctx = NULL;
  63444. callback_functions server_cbf, client_cbf;
  63445. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  63446. XMEMSET(&client_cbf, 0, sizeof(callback_functions));
  63447. /* force server side to use TLS 1.2 */
  63448. server_cbf.ctx = ctx;
  63449. server_cbf.method = wolfTLSv1_2_server_method;
  63450. client_cbf.method = wolfSSLv23_client_method;
  63451. server_cbf.ctx_ready = test_wolfSSL_SESSION_expire_downgrade_ctx_ready;
  63452. client_cbf.ssl_ready = test_wolfSSL_SESSION_expire_downgrade_ssl_ready;
  63453. client_cbf.on_result = test_wolfSSL_SESSION_expire_downgrade_ssl_result;
  63454. test_wolfSSL_client_server_nofail(&client_cbf, &server_cbf);
  63455. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  63456. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  63457. /* set the previously created session and wait till expired */
  63458. server_cbf.ctx = ctx;
  63459. client_cbf.method = wolfSSLv23_client_method;
  63460. server_cbf.ctx_ready = test_wolfSSL_SESSION_expire_downgrade_ctx_ready;
  63461. client_cbf.ssl_ready = test_wolfSSL_SESSION_expire_downgrade_ssl_ready_wait;
  63462. client_cbf.on_result =
  63463. test_wolfSSL_SESSION_expire_downgrade_ssl_result_reuse;
  63464. test_wolfSSL_client_server_nofail(&client_cbf, &server_cbf);
  63465. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  63466. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  63467. /* set the previously created expired session */
  63468. server_cbf.ctx = ctx;
  63469. client_cbf.method = wolfSSLv23_client_method;
  63470. server_cbf.ctx_ready = test_wolfSSL_SESSION_expire_downgrade_ctx_ready;
  63471. client_cbf.ssl_ready = test_wolfSSL_SESSION_expire_downgrade_ssl_ready_set;
  63472. client_cbf.on_result =
  63473. test_wolfSSL_SESSION_expire_downgrade_ssl_result_reuse;
  63474. test_wolfSSL_client_server_nofail(&client_cbf, &server_cbf);
  63475. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  63476. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  63477. wolfSSL_SESSION_free(test_wolfSSL_SESSION_expire_sess);
  63478. wolfSSL_CTX_free(ctx);
  63479. #endif
  63480. return EXPECT_RESULT();
  63481. }
  63482. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  63483. defined(HAVE_EX_DATA) && !defined(NO_SESSION_CACHE)
  63484. #ifdef WOLFSSL_ATOMIC_OPS
  63485. typedef wolfSSL_Atomic_Int SessRemCounter_t;
  63486. #else
  63487. typedef int SessRemCounter_t;
  63488. #endif
  63489. static SessRemCounter_t clientSessRemCountMalloc;
  63490. static SessRemCounter_t serverSessRemCountMalloc;
  63491. static SessRemCounter_t clientSessRemCountFree;
  63492. static SessRemCounter_t serverSessRemCountFree;
  63493. static WOLFSSL_CTX* serverSessCtx = NULL;
  63494. static WOLFSSL_SESSION* serverSess = NULL;
  63495. #if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \
  63496. !defined(NO_SESSION_CACHE_REF)
  63497. static WOLFSSL_CTX* clientSessCtx = NULL;
  63498. static WOLFSSL_SESSION* clientSess = NULL;
  63499. #endif
  63500. static int serverSessRemIdx = 3;
  63501. static int sessRemCtx_Server = WOLFSSL_SERVER_END;
  63502. static int sessRemCtx_Client = WOLFSSL_CLIENT_END;
  63503. static void SessRemCtxCb(WOLFSSL_CTX *ctx, WOLFSSL_SESSION *sess)
  63504. {
  63505. int* side;
  63506. (void)ctx;
  63507. side = (int*)SSL_SESSION_get_ex_data(sess, serverSessRemIdx);
  63508. if (side != NULL) {
  63509. if (*side == WOLFSSL_CLIENT_END)
  63510. (void)wolfSSL_Atomic_Int_FetchAdd(&clientSessRemCountFree, 1);
  63511. else
  63512. (void)wolfSSL_Atomic_Int_FetchAdd(&serverSessRemCountFree, 1);
  63513. SSL_SESSION_set_ex_data(sess, serverSessRemIdx, NULL);
  63514. }
  63515. }
  63516. static int SessRemCtxSetupCb(WOLFSSL_CTX* ctx)
  63517. {
  63518. SSL_CTX_sess_set_remove_cb(ctx, SessRemCtxCb);
  63519. #if defined(WOLFSSL_TLS13) && !defined(HAVE_SESSION_TICKET) && \
  63520. !defined(NO_SESSION_CACHE_REF)
  63521. {
  63522. EXPECT_DECLS;
  63523. /* Allow downgrade, set min version, and disable TLS 1.3.
  63524. * Do this because without NO_SESSION_CACHE_REF we will want to return a
  63525. * reference to the session cache. But with WOLFSSL_TLS13 and without
  63526. * HAVE_SESSION_TICKET we won't have a session ID to be able to place
  63527. * the session in the cache. In this case we need to downgrade to
  63528. * previous versions to just use the legacy session ID field. */
  63529. ExpectIntEQ(SSL_CTX_set_min_proto_version(ctx, SSL3_VERSION),
  63530. SSL_SUCCESS);
  63531. ExpectIntEQ(SSL_CTX_set_max_proto_version(ctx, TLS1_2_VERSION),
  63532. SSL_SUCCESS);
  63533. return EXPECT_RESULT();
  63534. }
  63535. #else
  63536. return TEST_SUCCESS;
  63537. #endif
  63538. }
  63539. static int SessRemSslSetupCb(WOLFSSL* ssl)
  63540. {
  63541. EXPECT_DECLS;
  63542. int* side;
  63543. if (SSL_is_server(ssl)) {
  63544. side = &sessRemCtx_Server;
  63545. (void)wolfSSL_Atomic_Int_FetchAdd(&serverSessRemCountMalloc, 1);
  63546. ExpectNotNull(serverSess = SSL_get1_session(ssl));
  63547. ExpectIntEQ(SSL_CTX_up_ref(serverSessCtx = SSL_get_SSL_CTX(ssl)),
  63548. SSL_SUCCESS);
  63549. }
  63550. else {
  63551. side = &sessRemCtx_Client;
  63552. (void)wolfSSL_Atomic_Int_FetchAdd(&clientSessRemCountMalloc, 1);
  63553. #if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \
  63554. !defined(NO_SESSION_CACHE_REF)
  63555. ExpectNotNull(clientSess = SSL_get1_session(ssl));
  63556. ExpectIntEQ(SSL_CTX_up_ref(clientSessCtx = SSL_get_SSL_CTX(ssl)),
  63557. SSL_SUCCESS);
  63558. #endif
  63559. }
  63560. ExpectIntEQ(SSL_SESSION_set_ex_data(SSL_get_session(ssl),
  63561. serverSessRemIdx, side), SSL_SUCCESS);
  63562. return EXPECT_RESULT();
  63563. }
  63564. #endif
  63565. static int test_wolfSSL_CTX_sess_set_remove_cb(void)
  63566. {
  63567. EXPECT_DECLS;
  63568. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  63569. defined(HAVE_EX_DATA) && !defined(NO_SESSION_CACHE)
  63570. /* Check that the remove callback gets called for external data in a
  63571. * session object */
  63572. test_ssl_cbf func_cb;
  63573. wolfSSL_Atomic_Int_Init(&clientSessRemCountMalloc, 0);
  63574. wolfSSL_Atomic_Int_Init(&serverSessRemCountMalloc, 0);
  63575. wolfSSL_Atomic_Int_Init(&clientSessRemCountFree, 0);
  63576. wolfSSL_Atomic_Int_Init(&serverSessRemCountFree, 0);
  63577. XMEMSET(&func_cb, 0, sizeof(func_cb));
  63578. func_cb.ctx_ready = SessRemCtxSetupCb;
  63579. func_cb.on_result = SessRemSslSetupCb;
  63580. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb, &func_cb,
  63581. NULL), TEST_SUCCESS);
  63582. /* Both should have been allocated */
  63583. ExpectIntEQ(clientSessRemCountMalloc, 1);
  63584. ExpectIntEQ(serverSessRemCountMalloc, 1);
  63585. /* This should not be called yet. Session wasn't evicted from cache yet. */
  63586. ExpectIntEQ(clientSessRemCountFree, 0);
  63587. #if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \
  63588. !defined(NO_SESSION_CACHE_REF)
  63589. /* Force a cache lookup */
  63590. ExpectNotNull(SSL_SESSION_get_ex_data(clientSess, serverSessRemIdx));
  63591. /* Force a cache update */
  63592. ExpectNotNull(SSL_SESSION_set_ex_data(clientSess, serverSessRemIdx - 1, 0));
  63593. /* This should set the timeout to 0 and call the remove callback from within
  63594. * the session cache. */
  63595. ExpectIntEQ(SSL_CTX_remove_session(clientSessCtx, clientSess), 0);
  63596. ExpectNull(SSL_SESSION_get_ex_data(clientSess, serverSessRemIdx));
  63597. ExpectIntEQ(clientSessRemCountFree, 1);
  63598. #endif
  63599. /* Server session is in the cache so ex_data isn't free'd with the SSL
  63600. * object */
  63601. ExpectIntEQ(serverSessRemCountFree, 0);
  63602. /* Force a cache lookup */
  63603. ExpectNotNull(SSL_SESSION_get_ex_data(serverSess, serverSessRemIdx));
  63604. /* Force a cache update */
  63605. ExpectNotNull(SSL_SESSION_set_ex_data(serverSess, serverSessRemIdx - 1, 0));
  63606. /* This should set the timeout to 0 and call the remove callback from within
  63607. * the session cache. */
  63608. ExpectIntEQ(SSL_CTX_remove_session(serverSessCtx, serverSess), 0);
  63609. ExpectNull(SSL_SESSION_get_ex_data(serverSess, serverSessRemIdx));
  63610. ExpectIntEQ(serverSessRemCountFree, 1);
  63611. /* Need to free the references that we kept */
  63612. SSL_CTX_free(serverSessCtx);
  63613. SSL_SESSION_free(serverSess);
  63614. #if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \
  63615. !defined(NO_SESSION_CACHE_REF)
  63616. SSL_CTX_free(clientSessCtx);
  63617. SSL_SESSION_free(clientSess);
  63618. #endif
  63619. #endif
  63620. return EXPECT_RESULT();
  63621. }
  63622. static int test_wolfSSL_ticket_keys(void)
  63623. {
  63624. EXPECT_DECLS;
  63625. #if defined(HAVE_SESSION_TICKET) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  63626. !defined(NO_WOLFSSL_SERVER)
  63627. WOLFSSL_CTX* ctx = NULL;
  63628. byte keys[WOLFSSL_TICKET_KEYS_SZ];
  63629. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  63630. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(NULL, NULL, 0),
  63631. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63632. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(ctx, NULL, 0),
  63633. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63634. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(ctx, keys, 0),
  63635. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63636. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(NULL, keys, 0),
  63637. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63638. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(NULL, NULL, sizeof(keys)),
  63639. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63640. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(ctx, NULL, sizeof(keys)),
  63641. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63642. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(NULL, keys, sizeof(keys)),
  63643. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63644. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(NULL, NULL, 0),
  63645. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63646. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(ctx, NULL, 0),
  63647. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63648. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(ctx, keys, 0),
  63649. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63650. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(NULL, keys, 0),
  63651. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63652. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(NULL, NULL, sizeof(keys)),
  63653. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63654. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(ctx, NULL, sizeof(keys)),
  63655. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63656. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(NULL, keys, sizeof(keys)),
  63657. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63658. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(ctx, keys, sizeof(keys)),
  63659. WOLFSSL_SUCCESS);
  63660. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(ctx, keys, sizeof(keys)),
  63661. WOLFSSL_SUCCESS);
  63662. wolfSSL_CTX_free(ctx);
  63663. #endif
  63664. return EXPECT_RESULT();
  63665. }
  63666. #ifndef NO_BIO
  63667. static int test_wolfSSL_d2i_PUBKEY(void)
  63668. {
  63669. EXPECT_DECLS;
  63670. #if defined(OPENSSL_EXTRA)
  63671. BIO* bio = NULL;
  63672. EVP_PKEY* pkey = NULL;
  63673. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  63674. ExpectNull(d2i_PUBKEY_bio(NULL, NULL));
  63675. #if defined(USE_CERT_BUFFERS_2048) && !defined(NO_RSA)
  63676. /* RSA PUBKEY test */
  63677. ExpectIntGT(BIO_write(bio, client_keypub_der_2048,
  63678. sizeof_client_keypub_der_2048), 0);
  63679. ExpectNotNull(pkey = d2i_PUBKEY_bio(bio, NULL));
  63680. EVP_PKEY_free(pkey);
  63681. pkey = NULL;
  63682. #endif
  63683. #if defined(USE_CERT_BUFFERS_256) && defined(HAVE_ECC)
  63684. /* ECC PUBKEY test */
  63685. ExpectIntGT(BIO_write(bio, ecc_clikeypub_der_256,
  63686. sizeof_ecc_clikeypub_der_256), 0);
  63687. ExpectNotNull(pkey = d2i_PUBKEY_bio(bio, NULL));
  63688. EVP_PKEY_free(pkey);
  63689. pkey = NULL;
  63690. #endif
  63691. #if defined(USE_CERT_BUFFERS_2048) && !defined(NO_DSA)
  63692. /* DSA PUBKEY test */
  63693. ExpectIntGT(BIO_write(bio, dsa_pub_key_der_2048,
  63694. sizeof_dsa_pub_key_der_2048), 0);
  63695. ExpectNotNull(pkey = d2i_PUBKEY_bio(bio, NULL));
  63696. EVP_PKEY_free(pkey);
  63697. pkey = NULL;
  63698. #endif
  63699. #if defined(USE_CERT_BUFFERS_2048) && !defined(NO_DH) && \
  63700. defined(OPENSSL_EXTRA) && defined(WOLFSSL_DH_EXTRA)
  63701. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  63702. (HAVE_FIPS_VERSION > 2))
  63703. /* DH PUBKEY test */
  63704. ExpectIntGT(BIO_write(bio, dh_pub_key_der_2048,
  63705. sizeof_dh_pub_key_der_2048), 0);
  63706. ExpectNotNull(pkey = d2i_PUBKEY_bio(bio, NULL));
  63707. EVP_PKEY_free(pkey);
  63708. pkey = NULL;
  63709. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  63710. #endif /* USE_CERT_BUFFERS_2048 && !NO_DH && && OPENSSL_EXTRA */
  63711. BIO_free(bio);
  63712. (void)pkey;
  63713. #endif
  63714. return EXPECT_RESULT();
  63715. }
  63716. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO)) && !defined(NO_RSA)
  63717. static int test_wolfSSL_d2i_PrivateKeys_bio(void)
  63718. {
  63719. EXPECT_DECLS;
  63720. BIO* bio = NULL;
  63721. EVP_PKEY* pkey = NULL;
  63722. WOLFSSL_CTX* ctx = NULL;
  63723. #if defined(WOLFSSL_KEY_GEN)
  63724. unsigned char buff[4096];
  63725. unsigned char* bufPtr = buff;
  63726. #endif
  63727. /* test creating new EVP_PKEY with bad arg */
  63728. ExpectNull((pkey = d2i_PrivateKey_bio(NULL, NULL)));
  63729. /* test loading RSA key using BIO */
  63730. #if !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  63731. {
  63732. XFILE file = XBADFILE;
  63733. const char* fname = "./certs/server-key.der";
  63734. size_t sz = 0;
  63735. byte* buf = NULL;
  63736. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  63737. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  63738. ExpectTrue((sz = XFTELL(file)) != 0);
  63739. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  63740. ExpectNotNull(buf = (byte*)XMALLOC(sz, HEAP_HINT, DYNAMIC_TYPE_FILE));
  63741. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  63742. if (file != XBADFILE) {
  63743. XFCLOSE(file);
  63744. }
  63745. /* Test using BIO new mem and loading DER private key */
  63746. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  63747. ExpectNotNull((pkey = d2i_PrivateKey_bio(bio, NULL)));
  63748. XFREE(buf, HEAP_HINT, DYNAMIC_TYPE_FILE);
  63749. BIO_free(bio);
  63750. bio = NULL;
  63751. EVP_PKEY_free(pkey);
  63752. pkey = NULL;
  63753. }
  63754. #endif
  63755. /* test loading ECC key using BIO */
  63756. #if defined(HAVE_ECC) && !defined(NO_FILESYSTEM)
  63757. {
  63758. XFILE file = XBADFILE;
  63759. const char* fname = "./certs/ecc-key.der";
  63760. size_t sz = 0;
  63761. byte* buf = NULL;
  63762. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  63763. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  63764. ExpectTrue((sz = XFTELL(file)) != 0);
  63765. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  63766. ExpectNotNull(buf = (byte*)XMALLOC(sz, HEAP_HINT, DYNAMIC_TYPE_FILE));
  63767. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  63768. if (file != XBADFILE)
  63769. XFCLOSE(file);
  63770. /* Test using BIO new mem and loading DER private key */
  63771. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  63772. ExpectNotNull((pkey = d2i_PrivateKey_bio(bio, NULL)));
  63773. XFREE(buf, HEAP_HINT, DYNAMIC_TYPE_FILE);
  63774. BIO_free(bio);
  63775. bio = NULL;
  63776. EVP_PKEY_free(pkey);
  63777. pkey = NULL;
  63778. }
  63779. #endif
  63780. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  63781. #ifndef NO_WOLFSSL_SERVER
  63782. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  63783. #else
  63784. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  63785. #endif
  63786. #if defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA)
  63787. {
  63788. RSA* rsa = NULL;
  63789. /* Tests bad parameters */
  63790. ExpectNull(d2i_RSAPrivateKey_bio(NULL, NULL));
  63791. /* RSA not set yet, expecting to fail*/
  63792. rsa = wolfSSL_RSA_new();
  63793. ExpectIntEQ(SSL_CTX_use_RSAPrivateKey(ctx, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63794. wolfSSL_RSA_free(rsa);
  63795. rsa = NULL;
  63796. #if defined(USE_CERT_BUFFERS_2048) && defined(WOLFSSL_KEY_GEN)
  63797. /* set RSA using bio*/
  63798. ExpectIntGT(BIO_write(bio, client_key_der_2048,
  63799. sizeof_client_key_der_2048), 0);
  63800. ExpectNotNull(d2i_RSAPrivateKey_bio(bio, &rsa));
  63801. ExpectNotNull(rsa);
  63802. /* Tests bad parameters */
  63803. ExpectIntEQ(SSL_CTX_use_RSAPrivateKey(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  63804. ExpectIntEQ(SSL_CTX_use_RSAPrivateKey(ctx, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  63805. ExpectIntEQ(SSL_CTX_use_RSAPrivateKey(NULL, rsa), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  63806. ExpectIntEQ(SSL_CTX_use_RSAPrivateKey(ctx, rsa), WOLFSSL_SUCCESS);
  63807. /* i2d RSAprivate key tests */
  63808. ExpectIntEQ(wolfSSL_i2d_RSAPrivateKey(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  63809. ExpectIntEQ(wolfSSL_i2d_RSAPrivateKey(rsa, NULL), 1192);
  63810. ExpectIntEQ(wolfSSL_i2d_RSAPrivateKey(rsa, &bufPtr),
  63811. sizeof_client_key_der_2048);
  63812. bufPtr -= sizeof_client_key_der_2048;
  63813. ExpectIntEQ(XMEMCMP(bufPtr, client_key_der_2048,
  63814. sizeof_client_key_der_2048), 0);
  63815. bufPtr = NULL;
  63816. ExpectIntEQ(wolfSSL_i2d_RSAPrivateKey(rsa, &bufPtr),
  63817. sizeof_client_key_der_2048);
  63818. ExpectNotNull(bufPtr);
  63819. ExpectIntEQ(XMEMCMP(bufPtr, client_key_der_2048,
  63820. sizeof_client_key_der_2048), 0);
  63821. XFREE(bufPtr, NULL, DYNAMIC_TYPE_OPENSSL);
  63822. RSA_free(rsa);
  63823. rsa = NULL;
  63824. ExpectIntGT(BIO_write(bio, client_key_der_2048,
  63825. sizeof_client_key_der_2048), 0);
  63826. ExpectNotNull(d2i_RSA_PUBKEY_bio(bio, &rsa));
  63827. (void)BIO_reset(bio);
  63828. RSA_free(rsa);
  63829. rsa = RSA_new();
  63830. ExpectIntEQ(wolfSSL_i2d_RSAPrivateKey(rsa, NULL), 0);
  63831. #endif /* USE_CERT_BUFFERS_2048 WOLFSSL_KEY_GEN */
  63832. RSA_free(rsa);
  63833. }
  63834. #endif /* WOLFSSL_KEY_GEN && !NO_RSA */
  63835. SSL_CTX_free(ctx);
  63836. ctx = NULL;
  63837. BIO_free(bio);
  63838. bio = NULL;
  63839. return EXPECT_RESULT();
  63840. }
  63841. #endif /* OPENSSL_ALL || (WOLFSSL_ASIO && !NO_RSA) */
  63842. #endif /* !NO_BIO */
  63843. static int test_wolfSSL_sk_GENERAL_NAME(void)
  63844. {
  63845. EXPECT_DECLS;
  63846. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  63847. !defined(NO_RSA)
  63848. X509* x509 = NULL;
  63849. GENERAL_NAME* gn = NULL;
  63850. unsigned char buf[4096];
  63851. const unsigned char* bufPt = NULL;
  63852. int bytes = 0;
  63853. int i;
  63854. int j;
  63855. XFILE f = XBADFILE;
  63856. STACK_OF(GENERAL_NAME)* sk = NULL;
  63857. ExpectTrue((f = XFOPEN(cliCertDerFileExt, "rb")) != XBADFILE);
  63858. ExpectIntGT((bytes = (int)XFREAD(buf, 1, sizeof(buf), f)), 0);
  63859. if (f != XBADFILE)
  63860. XFCLOSE(f);
  63861. for (j = 0; j < 2; ++j) {
  63862. bufPt = buf;
  63863. ExpectNotNull(x509 = d2i_X509(NULL, &bufPt, bytes));
  63864. ExpectNotNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509,
  63865. NID_subject_alt_name, NULL, NULL));
  63866. ExpectIntEQ(sk_GENERAL_NAME_num(sk), 1);
  63867. for (i = 0; i < sk_GENERAL_NAME_num(sk); i++) {
  63868. ExpectNotNull(gn = sk_GENERAL_NAME_value(sk, i));
  63869. if (gn != NULL) {
  63870. switch (gn->type) {
  63871. case GEN_DNS:
  63872. fprintf(stderr, "found type GEN_DNS\n");
  63873. break;
  63874. case GEN_EMAIL:
  63875. fprintf(stderr, "found type GEN_EMAIL\n");
  63876. break;
  63877. case GEN_URI:
  63878. fprintf(stderr, "found type GEN_URI\n");
  63879. break;
  63880. }
  63881. }
  63882. }
  63883. X509_free(x509);
  63884. x509 = NULL;
  63885. if (j == 0) {
  63886. sk_GENERAL_NAME_pop_free(sk, GENERAL_NAME_free);
  63887. }
  63888. else {
  63889. /*
  63890. * We had a bug where GENERAL_NAMES_free didn't free all the memory
  63891. * it was supposed to. This is a regression test for that bug.
  63892. */
  63893. GENERAL_NAMES_free(sk);
  63894. }
  63895. sk = NULL;
  63896. }
  63897. #endif
  63898. return EXPECT_RESULT();
  63899. }
  63900. static int test_wolfSSL_GENERAL_NAME_print(void)
  63901. {
  63902. EXPECT_DECLS;
  63903. #if defined(OPENSSL_ALL) && !defined(NO_BIO) && !defined(NO_RSA)
  63904. X509* x509 = NULL;
  63905. GENERAL_NAME* gn = NULL;
  63906. unsigned char buf[4096];
  63907. const unsigned char* bufPt = NULL;
  63908. int bytes;
  63909. XFILE f = XBADFILE;
  63910. STACK_OF(GENERAL_NAME)* sk = NULL;
  63911. BIO* out = NULL;
  63912. unsigned char outbuf[128];
  63913. X509_EXTENSION* ext = NULL;
  63914. AUTHORITY_INFO_ACCESS* aia = NULL;
  63915. ACCESS_DESCRIPTION* ad = NULL;
  63916. ASN1_IA5STRING *dnsname = NULL;
  63917. const unsigned char v4Addr[] = {192,168,53,1};
  63918. const unsigned char v6Addr[] =
  63919. {0x20, 0x21, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00,
  63920. 0x00, 0x00, 0xff, 0x00, 0x00, 0x42, 0x77, 0x77};
  63921. const unsigned char email[] =
  63922. {'i', 'n', 'f', 'o', '@', 'w', 'o', 'l',
  63923. 'f', 's', 's', 'l', '.', 'c', 'o', 'm'};
  63924. const char* dnsStr = "DNS:example.com";
  63925. const char* uriStr = "URI:http://127.0.0.1:22220";
  63926. const char* v4addStr = "IP Address:192.168.53.1";
  63927. const char* v6addStr = "IP Address:2021:DB8:0:0:0:FF00:42:7777";
  63928. const char* emailStr = "email:info@wolfssl.com";
  63929. const char* othrStr = "othername:<unsupported>";
  63930. const char* x400Str = "X400Name:<unsupported>";
  63931. const char* ediStr = "EdiPartyName:<unsupported>";
  63932. /* BIO to output */
  63933. ExpectNotNull(out = BIO_new(BIO_s_mem()));
  63934. /* test for NULL param */
  63935. gn = NULL;
  63936. ExpectIntEQ(GENERAL_NAME_print(NULL, NULL), 0);
  63937. ExpectIntEQ(GENERAL_NAME_print(NULL, gn), 0);
  63938. ExpectIntEQ(GENERAL_NAME_print(out, NULL), 0);
  63939. /* test for GEN_DNS */
  63940. ExpectTrue((f = XFOPEN(cliCertDerFileExt, "rb")) != XBADFILE);
  63941. ExpectIntGT((bytes = (int)XFREAD(buf, 1, sizeof(buf), f)), 0);
  63942. if (f != XBADFILE) {
  63943. XFCLOSE(f);
  63944. f = XBADFILE;
  63945. }
  63946. bufPt = buf;
  63947. ExpectNotNull(x509 = d2i_X509(NULL, &bufPt, bytes));
  63948. ExpectNotNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509,
  63949. NID_subject_alt_name, NULL, NULL));
  63950. ExpectNotNull(gn = sk_GENERAL_NAME_value(sk, 0));
  63951. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  63952. XMEMSET(outbuf, 0, sizeof(outbuf));
  63953. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  63954. ExpectIntEQ(XSTRNCMP((const char*)outbuf, dnsStr, XSTRLEN(dnsStr)), 0);
  63955. sk_GENERAL_NAME_pop_free(sk, GENERAL_NAME_free);
  63956. gn = NULL;
  63957. sk = NULL;
  63958. X509_free(x509);
  63959. x509 = NULL;
  63960. /* Lets test for setting as well. */
  63961. ExpectNotNull(gn = GENERAL_NAME_new());
  63962. ExpectNotNull(dnsname = ASN1_IA5STRING_new());
  63963. ExpectIntEQ(ASN1_STRING_set(dnsname, "example.com", -1), 1);
  63964. GENERAL_NAME_set0_value(gn, GEN_DNS, dnsname);
  63965. dnsname = NULL;
  63966. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  63967. XMEMSET(outbuf, 0, sizeof(outbuf));
  63968. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  63969. ExpectIntEQ(XSTRNCMP((const char*)outbuf, dnsStr, XSTRLEN(dnsStr)), 0);
  63970. GENERAL_NAME_free(gn);
  63971. /* test for GEN_URI */
  63972. ExpectTrue((f = XFOPEN("./certs/ocsp/root-ca-cert.pem", "rb")) != XBADFILE);
  63973. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  63974. if (f != XBADFILE) {
  63975. XFCLOSE(f);
  63976. f = XBADFILE;
  63977. }
  63978. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, 4));
  63979. ExpectNotNull(aia = (WOLFSSL_AUTHORITY_INFO_ACCESS*)wolfSSL_X509V3_EXT_d2i(
  63980. ext));
  63981. ExpectNotNull(ad = (WOLFSSL_ACCESS_DESCRIPTION *)wolfSSL_sk_value(aia, 0));
  63982. if (ad != NULL) {
  63983. gn = ad->location;
  63984. }
  63985. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  63986. gn = NULL;
  63987. XMEMSET(outbuf,0,sizeof(outbuf));
  63988. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  63989. ExpectIntEQ(XSTRNCMP((const char*)outbuf, uriStr, XSTRLEN(uriStr)), 0);
  63990. wolfSSL_sk_ACCESS_DESCRIPTION_pop_free(aia, NULL);
  63991. aia = NULL;
  63992. aia = (AUTHORITY_INFO_ACCESS*)wolfSSL_X509V3_EXT_d2i(ext);
  63993. ExpectNotNull(aia);
  63994. AUTHORITY_INFO_ACCESS_pop_free(aia, NULL);
  63995. aia = NULL;
  63996. X509_free(x509);
  63997. x509 = NULL;
  63998. /* test for GEN_IPADD */
  63999. /* ip v4 address */
  64000. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  64001. if (gn != NULL) {
  64002. gn->type = GEN_IPADD;
  64003. if (gn->d.iPAddress != NULL) {
  64004. gn->d.iPAddress->length = sizeof(v4Addr);
  64005. }
  64006. }
  64007. ExpectIntEQ(wolfSSL_ASN1_STRING_set(gn->d.iPAddress, v4Addr,
  64008. sizeof(v4Addr)), 1);
  64009. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  64010. XMEMSET(outbuf,0,sizeof(outbuf));
  64011. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  64012. ExpectIntEQ(XSTRNCMP((const char*)outbuf, v4addStr, XSTRLEN(v4addStr)), 0);
  64013. GENERAL_NAME_free(gn);
  64014. gn = NULL;
  64015. /* ip v6 address */
  64016. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  64017. if (gn != NULL) {
  64018. gn->type = GEN_IPADD;
  64019. if (gn->d.iPAddress != NULL) {
  64020. gn->d.iPAddress->length = sizeof(v6Addr);
  64021. }
  64022. }
  64023. ExpectIntEQ(wolfSSL_ASN1_STRING_set(gn->d.iPAddress, v6Addr,
  64024. sizeof(v6Addr)), 1);
  64025. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  64026. XMEMSET(outbuf,0,sizeof(outbuf));
  64027. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  64028. ExpectIntEQ(XSTRNCMP((const char*)outbuf, v6addStr, XSTRLEN(v6addStr)), 0);
  64029. GENERAL_NAME_free(gn);
  64030. gn = NULL;
  64031. /* test for GEN_EMAIL */
  64032. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  64033. if (gn != NULL) {
  64034. gn->type = GEN_EMAIL;
  64035. if (gn->d.rfc822Name != NULL) {
  64036. gn->d.rfc822Name->length = sizeof(email);
  64037. }
  64038. }
  64039. ExpectIntEQ(wolfSSL_ASN1_STRING_set(gn->d.rfc822Name, email, sizeof(email)),
  64040. 1);
  64041. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  64042. XMEMSET(outbuf,0,sizeof(outbuf));
  64043. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  64044. ExpectIntEQ(XSTRNCMP((const char*)outbuf, emailStr, XSTRLEN(emailStr)), 0);
  64045. GENERAL_NAME_free(gn);
  64046. gn = NULL;
  64047. /* test for GEN_OTHERNAME */
  64048. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  64049. if (gn != NULL) {
  64050. gn->type = GEN_OTHERNAME;
  64051. }
  64052. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  64053. XMEMSET(outbuf,0,sizeof(outbuf));
  64054. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  64055. ExpectIntEQ(XSTRNCMP((const char*)outbuf, othrStr, XSTRLEN(othrStr)), 0);
  64056. GENERAL_NAME_free(gn);
  64057. gn = NULL;
  64058. /* test for GEN_X400 */
  64059. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  64060. if (gn != NULL) {
  64061. gn->type = GEN_X400;
  64062. }
  64063. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  64064. XMEMSET(outbuf,0,sizeof(outbuf));
  64065. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  64066. ExpectIntEQ(XSTRNCMP((const char*)outbuf, x400Str, XSTRLEN(x400Str)), 0);
  64067. /* Restore to GEN_IA5 (default) to avoid memory leak. */
  64068. if (gn != NULL) {
  64069. gn->type = GEN_IA5;
  64070. }
  64071. GENERAL_NAME_free(gn);
  64072. gn = NULL;
  64073. /* test for GEN_EDIPARTY */
  64074. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  64075. if (gn != NULL) {
  64076. gn->type = GEN_EDIPARTY;
  64077. }
  64078. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  64079. XMEMSET(outbuf,0,sizeof(outbuf));
  64080. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  64081. ExpectIntEQ(XSTRNCMP((const char*)outbuf, ediStr, XSTRLEN(ediStr)), 0);
  64082. /* Restore to GEN_IA5 (default) to avoid memory leak. */
  64083. if (gn != NULL) {
  64084. gn->type = GEN_IA5;
  64085. }
  64086. GENERAL_NAME_free(gn);
  64087. gn = NULL;
  64088. BIO_free(out);
  64089. #endif /* OPENSSL_ALL */
  64090. return EXPECT_RESULT();
  64091. }
  64092. static int test_wolfSSL_sk_DIST_POINT(void)
  64093. {
  64094. EXPECT_DECLS;
  64095. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  64096. !defined(NO_RSA)
  64097. X509* x509 = NULL;
  64098. unsigned char buf[4096];
  64099. const unsigned char* bufPt;
  64100. int bytes = 0;
  64101. int i = 0;
  64102. int j = 0;
  64103. XFILE f = XBADFILE;
  64104. DIST_POINT* dp = NULL;
  64105. DIST_POINT_NAME* dpn = NULL;
  64106. GENERAL_NAME* gn = NULL;
  64107. ASN1_IA5STRING* uri = NULL;
  64108. STACK_OF(DIST_POINT)* dps = NULL;
  64109. STACK_OF(GENERAL_NAME)* gns = NULL;
  64110. const char cliCertDerCrlDistPoint[] = "./certs/client-crl-dist.der";
  64111. ExpectTrue((f = XFOPEN(cliCertDerCrlDistPoint, "rb")) != XBADFILE);
  64112. ExpectIntGT((bytes = (int)XFREAD(buf, 1, sizeof(buf), f)), 0);
  64113. if (f != XBADFILE)
  64114. XFCLOSE(f);
  64115. bufPt = buf;
  64116. ExpectNotNull(x509 = d2i_X509(NULL, &bufPt, bytes));
  64117. ExpectNotNull(dps = (STACK_OF(DIST_POINT)*)X509_get_ext_d2i(x509,
  64118. NID_crl_distribution_points, NULL, NULL));
  64119. ExpectIntEQ(sk_DIST_POINT_num(dps), 1);
  64120. for (i = 0; i < sk_DIST_POINT_num(dps); i++) {
  64121. ExpectNotNull(dp = sk_DIST_POINT_value(dps, i));
  64122. ExpectNotNull(dpn = dp->distpoint);
  64123. /* this should be type 0, fullname */
  64124. ExpectIntEQ(dpn->type, 0);
  64125. ExpectNotNull(gns = dp->distpoint->name.fullname);
  64126. ExpectIntEQ(sk_GENERAL_NAME_num(gns), 1);
  64127. for (j = 0; j < sk_GENERAL_NAME_num(gns); j++) {
  64128. ExpectNotNull(gn = sk_GENERAL_NAME_value(gns, j));
  64129. ExpectIntEQ(gn->type, GEN_URI);
  64130. ExpectNotNull(uri = gn->d.uniformResourceIdentifier);
  64131. ExpectNotNull(uri->data);
  64132. ExpectIntGT(uri->length, 0);
  64133. }
  64134. }
  64135. X509_free(x509);
  64136. CRL_DIST_POINTS_free(dps);
  64137. #endif
  64138. return EXPECT_RESULT();
  64139. }
  64140. static int test_wolfSSL_verify_mode(void)
  64141. {
  64142. EXPECT_DECLS;
  64143. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  64144. WOLFSSL* ssl = NULL;
  64145. WOLFSSL_CTX* ctx = NULL;
  64146. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  64147. ExpectNotNull(ssl = SSL_new(ctx));
  64148. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_CTX_get_verify_mode(ctx));
  64149. SSL_free(ssl);
  64150. ssl = NULL;
  64151. SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, 0);
  64152. ExpectNotNull(ssl = SSL_new(ctx));
  64153. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_CTX_get_verify_mode(ctx));
  64154. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_PEER);
  64155. wolfSSL_set_verify(ssl, SSL_VERIFY_NONE, 0);
  64156. ExpectIntEQ(SSL_CTX_get_verify_mode(ctx), SSL_VERIFY_PEER);
  64157. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_NONE);
  64158. SSL_free(ssl);
  64159. ssl = NULL;
  64160. wolfSSL_CTX_set_verify(ctx,
  64161. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  64162. ExpectNotNull(ssl = SSL_new(ctx));
  64163. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_CTX_get_verify_mode(ctx));
  64164. ExpectIntEQ(SSL_get_verify_mode(ssl),
  64165. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT);
  64166. wolfSSL_set_verify(ssl, SSL_VERIFY_PEER, 0);
  64167. ExpectIntEQ(SSL_CTX_get_verify_mode(ctx),
  64168. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT);
  64169. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_PEER);
  64170. wolfSSL_set_verify(ssl, SSL_VERIFY_NONE, 0);
  64171. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_NONE);
  64172. wolfSSL_set_verify(ssl, SSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  64173. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_FAIL_IF_NO_PEER_CERT);
  64174. wolfSSL_set_verify(ssl, SSL_VERIFY_FAIL_EXCEPT_PSK, 0);
  64175. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_FAIL_EXCEPT_PSK);
  64176. #if defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
  64177. wolfSSL_set_verify(ssl, SSL_VERIFY_POST_HANDSHAKE, 0);
  64178. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_POST_HANDSHAKE);
  64179. #endif
  64180. ExpectIntEQ(SSL_CTX_get_verify_mode(ctx),
  64181. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT);
  64182. SSL_free(ssl);
  64183. SSL_CTX_free(ctx);
  64184. #endif
  64185. return EXPECT_RESULT();
  64186. }
  64187. static int test_wolfSSL_verify_depth(void)
  64188. {
  64189. EXPECT_DECLS;
  64190. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_WOLFSSL_CLIENT)
  64191. WOLFSSL* ssl = NULL;
  64192. WOLFSSL_CTX* ctx = NULL;
  64193. long depth;
  64194. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  64195. ExpectIntGT((depth = SSL_CTX_get_verify_depth(ctx)), 0);
  64196. ExpectNotNull(ssl = SSL_new(ctx));
  64197. ExpectIntEQ(SSL_get_verify_depth(ssl), SSL_CTX_get_verify_depth(ctx));
  64198. SSL_free(ssl);
  64199. ssl = NULL;
  64200. SSL_CTX_set_verify_depth(ctx, -1);
  64201. ExpectIntEQ(depth, SSL_CTX_get_verify_depth(ctx));
  64202. SSL_CTX_set_verify_depth(ctx, 2);
  64203. ExpectIntEQ(2, SSL_CTX_get_verify_depth(ctx));
  64204. ExpectNotNull(ssl = SSL_new(ctx));
  64205. ExpectIntEQ(2, SSL_get_verify_depth(ssl));
  64206. SSL_free(ssl);
  64207. SSL_CTX_free(ctx);
  64208. #endif
  64209. return EXPECT_RESULT();
  64210. }
  64211. static int test_wolfSSL_verify_result(void)
  64212. {
  64213. EXPECT_DECLS;
  64214. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
  64215. defined(OPENSSL_ALL)) && !defined(NO_WOLFSSL_CLIENT)
  64216. WOLFSSL* ssl = NULL;
  64217. WOLFSSL_CTX* ctx = NULL;
  64218. long result = 0xDEADBEEF;
  64219. ExpectIntEQ(WC_NO_ERR_TRACE(WOLFSSL_FAILURE), wolfSSL_get_verify_result(ssl));
  64220. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  64221. ExpectNotNull(ssl = SSL_new(ctx));
  64222. wolfSSL_set_verify_result(ssl, result);
  64223. ExpectIntEQ(result, wolfSSL_get_verify_result(ssl));
  64224. SSL_free(ssl);
  64225. SSL_CTX_free(ctx);
  64226. #endif
  64227. return EXPECT_RESULT();
  64228. }
  64229. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_WOLFSSL_CLIENT)
  64230. static void sslMsgCb(int w, int version, int type, const void* buf,
  64231. size_t sz, SSL* ssl, void* arg)
  64232. {
  64233. int i;
  64234. unsigned char* pt = (unsigned char*)buf;
  64235. fprintf(stderr, "%s %d bytes of version %d , type %d : ",
  64236. (w)?"Writing":"Reading", (int)sz, version, type);
  64237. for (i = 0; i < (int)sz; i++) fprintf(stderr, "%02X", pt[i]);
  64238. fprintf(stderr, "\n");
  64239. (void)ssl;
  64240. (void)arg;
  64241. }
  64242. #endif /* OPENSSL_EXTRA */
  64243. static int test_wolfSSL_msg_callback(void)
  64244. {
  64245. EXPECT_DECLS;
  64246. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_WOLFSSL_CLIENT)
  64247. WOLFSSL* ssl = NULL;
  64248. WOLFSSL_CTX* ctx = NULL;
  64249. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  64250. ExpectNotNull(ssl = SSL_new(ctx));
  64251. ExpectIntEQ(SSL_set_msg_callback(ssl, NULL), SSL_SUCCESS);
  64252. ExpectIntEQ(SSL_set_msg_callback(ssl, &sslMsgCb), SSL_SUCCESS);
  64253. ExpectIntEQ(SSL_set_msg_callback(NULL, &sslMsgCb), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64254. SSL_free(ssl);
  64255. SSL_CTX_free(ctx);
  64256. #endif
  64257. return EXPECT_RESULT();
  64258. }
  64259. /* test_EVP_Cipher_extra, Extra-test on EVP_CipherUpdate/Final. see also test.c */
  64260. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) &&\
  64261. (!defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128))
  64262. static void binary_dump(void *ptr, int size)
  64263. {
  64264. #ifdef WOLFSSL_EVP_PRINT
  64265. int i = 0;
  64266. unsigned char *p = (unsigned char *) ptr;
  64267. fprintf(stderr, "{");
  64268. while ((p != NULL) && (i < size)) {
  64269. if ((i % 8) == 0) {
  64270. fprintf(stderr, "\n");
  64271. fprintf(stderr, " ");
  64272. }
  64273. fprintf(stderr, "0x%02x, ", p[i]);
  64274. i++;
  64275. }
  64276. fprintf(stderr, "\n};\n");
  64277. #else
  64278. (void) ptr;
  64279. (void) size;
  64280. #endif
  64281. }
  64282. static int last_val = 0x0f;
  64283. static int check_result(unsigned char *data, int len)
  64284. {
  64285. int i;
  64286. for ( ; len; ) {
  64287. last_val = (last_val + 1) % 16;
  64288. for (i = 0; i < 16; len--, i++, data++)
  64289. if (*data != last_val) {
  64290. return -1;
  64291. }
  64292. }
  64293. return 0;
  64294. }
  64295. static int r_offset;
  64296. static int w_offset;
  64297. static void init_offset(void)
  64298. {
  64299. r_offset = 0;
  64300. w_offset = 0;
  64301. }
  64302. static void get_record(unsigned char *data, unsigned char *buf, int len)
  64303. {
  64304. XMEMCPY(buf, data+r_offset, len);
  64305. r_offset += len;
  64306. }
  64307. static void set_record(unsigned char *data, unsigned char *buf, int len)
  64308. {
  64309. XMEMCPY(data+w_offset, buf, len);
  64310. w_offset += len;
  64311. }
  64312. static void set_plain(unsigned char *plain, int rec)
  64313. {
  64314. int i, j;
  64315. unsigned char *p = plain;
  64316. #define BLOCKSZ 16
  64317. for (i=0; i<(rec/BLOCKSZ); i++) {
  64318. for (j=0; j<BLOCKSZ; j++)
  64319. *p++ = (i % 16);
  64320. }
  64321. }
  64322. #endif
  64323. static int test_wolfSSL_EVP_Cipher_extra(void)
  64324. {
  64325. EXPECT_DECLS;
  64326. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) &&\
  64327. (!defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128))
  64328. /* aes128-cbc, keylen=16, ivlen=16 */
  64329. byte aes128_cbc_key[] = {
  64330. 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef,
  64331. 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef,
  64332. };
  64333. byte aes128_cbc_iv[] = {
  64334. 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
  64335. 0x99, 0x00, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
  64336. };
  64337. /* teset data size table */
  64338. int test_drive1[] = {8, 3, 5, 512, 8, 3, 8, 512, 0};
  64339. int test_drive2[] = {8, 3, 8, 512, 0};
  64340. int test_drive3[] = {512, 512, 504, 512, 512, 8, 512, 0};
  64341. int *test_drive[] = {test_drive1, test_drive2, test_drive3, NULL};
  64342. int test_drive_len[100];
  64343. int ret = 0;
  64344. EVP_CIPHER_CTX *evp = NULL;
  64345. int ilen = 0;
  64346. int klen = 0;
  64347. int i, j;
  64348. const EVP_CIPHER *type;
  64349. byte *iv;
  64350. byte *key;
  64351. int ivlen;
  64352. int keylen;
  64353. #define RECORDS 16
  64354. #define BUFFSZ 512
  64355. byte plain [BUFFSZ * RECORDS];
  64356. byte cipher[BUFFSZ * RECORDS];
  64357. byte inb[BUFFSZ];
  64358. byte outb[BUFFSZ+16];
  64359. int outl = 0;
  64360. int inl;
  64361. iv = aes128_cbc_iv;
  64362. ivlen = sizeof(aes128_cbc_iv);
  64363. key = aes128_cbc_key;
  64364. keylen = sizeof(aes128_cbc_key);
  64365. type = EVP_aes_128_cbc();
  64366. set_plain(plain, BUFFSZ * RECORDS);
  64367. SSL_library_init();
  64368. ExpectNotNull(evp = EVP_CIPHER_CTX_new());
  64369. ExpectIntNE((ret = EVP_CipherInit(evp, type, NULL, iv, 0)), 0);
  64370. ExpectIntEQ(EVP_CIPHER_CTX_nid(evp), NID_aes_128_cbc);
  64371. klen = EVP_CIPHER_CTX_key_length(evp);
  64372. if (klen > 0 && keylen != klen) {
  64373. ExpectIntNE(EVP_CIPHER_CTX_set_key_length(evp, keylen), 0);
  64374. }
  64375. ilen = EVP_CIPHER_CTX_iv_length(evp);
  64376. if (ilen > 0 && ivlen != ilen) {
  64377. ExpectIntNE(EVP_CIPHER_CTX_set_iv_length(evp, ivlen), 0);
  64378. }
  64379. ExpectIntNE((ret = EVP_CipherInit(evp, NULL, key, iv, 1)), 0);
  64380. for (j = 0; j<RECORDS; j++)
  64381. {
  64382. inl = BUFFSZ;
  64383. get_record(plain, inb, inl);
  64384. ExpectIntNE((ret = EVP_CipherUpdate(evp, outb, &outl, inb, inl)), 0);
  64385. set_record(cipher, outb, outl);
  64386. }
  64387. for (i = 0; test_drive[i]; i++) {
  64388. ExpectIntNE((ret = EVP_CipherInit(evp, NULL, key, iv, 1)), 0);
  64389. init_offset();
  64390. test_drive_len[i] = 0;
  64391. for (j = 0; test_drive[i][j]; j++)
  64392. {
  64393. inl = test_drive[i][j];
  64394. test_drive_len[i] += inl;
  64395. get_record(plain, inb, inl);
  64396. ExpectIntNE((ret = EVP_EncryptUpdate(evp, outb, &outl, inb, inl)),
  64397. 0);
  64398. /* output to cipher buffer, so that following Dec test can detect
  64399. if any error */
  64400. set_record(cipher, outb, outl);
  64401. }
  64402. EVP_CipherFinal(evp, outb, &outl);
  64403. if (outl > 0)
  64404. set_record(cipher, outb, outl);
  64405. }
  64406. for (i = 0; test_drive[i]; i++) {
  64407. last_val = 0x0f;
  64408. ExpectIntNE((ret = EVP_CipherInit(evp, NULL, key, iv, 0)), 0);
  64409. init_offset();
  64410. for (j = 0; test_drive[i][j]; j++) {
  64411. inl = test_drive[i][j];
  64412. get_record(cipher, inb, inl);
  64413. ExpectIntNE((ret = EVP_DecryptUpdate(evp, outb, &outl, inb, inl)),
  64414. 0);
  64415. binary_dump(outb, outl);
  64416. ExpectIntEQ((ret = check_result(outb, outl)), 0);
  64417. ExpectFalse(outl > ((inl/16+1)*16) && outl > 16);
  64418. }
  64419. ret = EVP_CipherFinal(evp, outb, &outl);
  64420. binary_dump(outb, outl);
  64421. ret = (((test_drive_len[i] % 16) != 0) && (ret == 0)) ||
  64422. (((test_drive_len[i] % 16) == 0) && (ret == 1));
  64423. ExpectTrue(ret);
  64424. }
  64425. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(evp), WOLFSSL_SUCCESS);
  64426. EVP_CIPHER_CTX_free(evp);
  64427. evp = NULL;
  64428. /* Do an extra test to verify correct behavior with empty input. */
  64429. ExpectNotNull(evp = EVP_CIPHER_CTX_new());
  64430. ExpectIntNE((ret = EVP_CipherInit(evp, type, NULL, iv, 0)), 0);
  64431. ExpectIntEQ(EVP_CIPHER_CTX_nid(evp), NID_aes_128_cbc);
  64432. klen = EVP_CIPHER_CTX_key_length(evp);
  64433. if (klen > 0 && keylen != klen) {
  64434. ExpectIntNE(EVP_CIPHER_CTX_set_key_length(evp, keylen), 0);
  64435. }
  64436. ilen = EVP_CIPHER_CTX_iv_length(evp);
  64437. if (ilen > 0 && ivlen != ilen) {
  64438. ExpectIntNE(EVP_CIPHER_CTX_set_iv_length(evp, ivlen), 0);
  64439. }
  64440. ExpectIntNE((ret = EVP_CipherInit(evp, NULL, key, iv, 1)), 0);
  64441. /* outl should be set to 0 after passing NULL, 0 for input args. */
  64442. outl = -1;
  64443. ExpectIntNE((ret = EVP_CipherUpdate(evp, outb, &outl, NULL, 0)), 0);
  64444. ExpectIntEQ(outl, 0);
  64445. EVP_CIPHER_CTX_free(evp);
  64446. #endif /* test_EVP_Cipher */
  64447. return EXPECT_RESULT();
  64448. }
  64449. static int test_wolfSSL_PEM_read_DHparams(void)
  64450. {
  64451. EXPECT_DECLS;
  64452. #if defined(OPENSSL_ALL) && !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA) && \
  64453. !defined(NO_FILESYSTEM)
  64454. DH* dh = NULL;
  64455. XFILE fp = XBADFILE;
  64456. unsigned char derOut[300];
  64457. unsigned char* derOutBuf = derOut;
  64458. int derOutSz = 0;
  64459. unsigned char derExpected[300];
  64460. int derExpectedSz = 0;
  64461. XMEMSET(derOut, 0, sizeof(derOut));
  64462. XMEMSET(derExpected, 0, sizeof(derExpected));
  64463. /* open DH param file, read into DH struct */
  64464. ExpectTrue((fp = XFOPEN(dhParamFile, "rb")) != XBADFILE);
  64465. /* bad args */
  64466. ExpectNull(dh = PEM_read_DHparams(NULL, &dh, NULL, NULL));
  64467. ExpectNull(dh = PEM_read_DHparams(NULL, NULL, NULL, NULL));
  64468. /* good args */
  64469. ExpectNotNull(dh = PEM_read_DHparams(fp, &dh, NULL, NULL));
  64470. if (fp != XBADFILE) {
  64471. XFCLOSE(fp);
  64472. fp = XBADFILE;
  64473. }
  64474. /* read in certs/dh2048.der for comparison against exported params */
  64475. ExpectTrue((fp = XFOPEN("./certs/dh2048.der", "rb")) != XBADFILE);
  64476. ExpectIntGT(derExpectedSz = (int)XFREAD(derExpected, 1, sizeof(derExpected),
  64477. fp), 0);
  64478. if (fp != XBADFILE) {
  64479. XFCLOSE(fp);
  64480. fp = XBADFILE;
  64481. }
  64482. /* export DH back to DER and compare */
  64483. derOutSz = wolfSSL_i2d_DHparams(dh, &derOutBuf);
  64484. ExpectIntEQ(derOutSz, derExpectedSz);
  64485. ExpectIntEQ(XMEMCMP(derOut, derExpected, derOutSz), 0);
  64486. DH_free(dh);
  64487. dh = NULL;
  64488. /* Test parsing with X9.42 header */
  64489. ExpectTrue((fp = XFOPEN("./certs/x942dh2048.pem", "rb")) != XBADFILE);
  64490. ExpectNotNull(dh = PEM_read_DHparams(fp, &dh, NULL, NULL));
  64491. if (fp != XBADFILE)
  64492. XFCLOSE(fp);
  64493. DH_free(dh);
  64494. dh = NULL;
  64495. #endif
  64496. return EXPECT_RESULT();
  64497. }
  64498. static int test_wolfSSL_X509_get_serialNumber(void)
  64499. {
  64500. EXPECT_DECLS;
  64501. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  64502. ASN1_INTEGER* a = NULL;
  64503. BIGNUM* bn = NULL;
  64504. X509* x509 = NULL;
  64505. char *serialHex = NULL;
  64506. byte serial[3];
  64507. int serialSz;
  64508. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  64509. SSL_FILETYPE_PEM));
  64510. ExpectNotNull(a = X509_get_serialNumber(x509));
  64511. /* check on value of ASN1 Integer */
  64512. ExpectNotNull(bn = ASN1_INTEGER_to_BN(a, NULL));
  64513. a = NULL;
  64514. /* test setting serial number and then retrieving it */
  64515. ExpectNotNull(a = ASN1_INTEGER_new());
  64516. ExpectIntEQ(ASN1_INTEGER_set(a, 3), 1);
  64517. ExpectIntEQ(X509_set_serialNumber(x509, a), WOLFSSL_SUCCESS);
  64518. serialSz = sizeof(serial);
  64519. ExpectIntEQ(wolfSSL_X509_get_serial_number(x509, serial, &serialSz),
  64520. WOLFSSL_SUCCESS);
  64521. ExpectIntEQ(serialSz, 1);
  64522. ExpectIntEQ(serial[0], 3);
  64523. ASN1_INTEGER_free(a);
  64524. a = NULL;
  64525. /* test setting serial number with 0's in it */
  64526. serial[0] = 0x01;
  64527. serial[1] = 0x00;
  64528. serial[2] = 0x02;
  64529. ExpectNotNull(a = wolfSSL_ASN1_INTEGER_new());
  64530. if (a != NULL) {
  64531. a->data[0] = ASN_INTEGER;
  64532. a->data[1] = sizeof(serial);
  64533. XMEMCPY(&a->data[2], serial, sizeof(serial));
  64534. a->length = sizeof(serial) + 2;
  64535. }
  64536. ExpectIntEQ(X509_set_serialNumber(x509, a), WOLFSSL_SUCCESS);
  64537. XMEMSET(serial, 0, sizeof(serial));
  64538. serialSz = sizeof(serial);
  64539. ExpectIntEQ(wolfSSL_X509_get_serial_number(x509, serial, &serialSz),
  64540. WOLFSSL_SUCCESS);
  64541. ExpectIntEQ(serialSz, 3);
  64542. ExpectIntEQ(serial[0], 0x01);
  64543. ExpectIntEQ(serial[1], 0x00);
  64544. ExpectIntEQ(serial[2], 0x02);
  64545. ASN1_INTEGER_free(a);
  64546. a = NULL;
  64547. X509_free(x509); /* free's a */
  64548. ExpectNotNull(serialHex = BN_bn2hex(bn));
  64549. #ifndef WC_DISABLE_RADIX_ZERO_PAD
  64550. ExpectStrEQ(serialHex, "01");
  64551. #else
  64552. ExpectStrEQ(serialHex, "1");
  64553. #endif
  64554. OPENSSL_free(serialHex);
  64555. ExpectIntEQ(BN_get_word(bn), 1);
  64556. BN_free(bn);
  64557. /* hard test free'ing with dynamic buffer to make sure there is no leaks */
  64558. ExpectNotNull(a = ASN1_INTEGER_new());
  64559. if (a != NULL) {
  64560. ExpectNotNull(a->data = (unsigned char*)XMALLOC(100, NULL,
  64561. DYNAMIC_TYPE_OPENSSL));
  64562. a->isDynamic = 1;
  64563. ASN1_INTEGER_free(a);
  64564. }
  64565. #endif
  64566. return EXPECT_RESULT();
  64567. }
  64568. static int test_wolfSSL_OpenSSL_add_all_algorithms(void)
  64569. {
  64570. EXPECT_DECLS;
  64571. #if defined(OPENSSL_EXTRA)
  64572. ExpectIntEQ(wolfSSL_add_all_algorithms(), WOLFSSL_SUCCESS);
  64573. ExpectIntEQ(wolfSSL_OpenSSL_add_all_algorithms_noconf(), WOLFSSL_SUCCESS);
  64574. ExpectIntEQ(wolfSSL_OpenSSL_add_all_algorithms_conf(), WOLFSSL_SUCCESS);
  64575. #endif
  64576. return EXPECT_RESULT();
  64577. }
  64578. static int test_wolfSSL_OPENSSL_hexstr2buf(void)
  64579. {
  64580. EXPECT_DECLS;
  64581. #if defined(OPENSSL_EXTRA)
  64582. #define MAX_HEXSTR_BUFSZ 9
  64583. #define NUM_CASES 5
  64584. struct Output {
  64585. const unsigned char buffer[MAX_HEXSTR_BUFSZ];
  64586. long ret;
  64587. };
  64588. int i;
  64589. int j;
  64590. const char* inputs[NUM_CASES] = {
  64591. "aabcd1357e",
  64592. "01:12:23:34:a5:b6:c7:d8:e9",
  64593. ":01:02",
  64594. "012",
  64595. ":ab:ac:d"
  64596. };
  64597. struct Output expectedOutputs[NUM_CASES] = {
  64598. {{0xaa, 0xbc, 0xd1, 0x35, 0x7e}, 5},
  64599. {{0x01, 0x12, 0x23, 0x34, 0xa5, 0xb6, 0xc7, 0xd8, 0xe9}, 9},
  64600. {{0x01, 0x02}, 2},
  64601. {{0x00}, 0},
  64602. {{0x00}, 0}
  64603. };
  64604. long len = 0;
  64605. unsigned char* returnedBuf = NULL;
  64606. for (i = 0; i < NUM_CASES && !EXPECT_FAIL(); ++i) {
  64607. returnedBuf = wolfSSL_OPENSSL_hexstr2buf(inputs[i], &len);
  64608. if (returnedBuf == NULL) {
  64609. ExpectIntEQ(expectedOutputs[i].ret, 0);
  64610. continue;
  64611. }
  64612. ExpectIntEQ(expectedOutputs[i].ret, len);
  64613. for (j = 0; j < len; ++j) {
  64614. ExpectIntEQ(expectedOutputs[i].buffer[j], returnedBuf[j]);
  64615. }
  64616. OPENSSL_free(returnedBuf);
  64617. returnedBuf = NULL;
  64618. }
  64619. #endif
  64620. return EXPECT_RESULT();
  64621. }
  64622. static int test_wolfSSL_X509_CA_num(void)
  64623. {
  64624. EXPECT_DECLS;
  64625. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  64626. defined(HAVE_ECC) && !defined(NO_RSA)
  64627. WOLFSSL_X509_STORE *store = NULL;
  64628. WOLFSSL_X509 *x509_1 = NULL;
  64629. WOLFSSL_X509 *x509_2 = NULL;
  64630. int ca_num = 0;
  64631. ExpectNotNull(store = wolfSSL_X509_STORE_new());
  64632. ExpectNotNull(x509_1 = wolfSSL_X509_load_certificate_file(svrCertFile,
  64633. WOLFSSL_FILETYPE_PEM));
  64634. ExpectIntEQ(wolfSSL_X509_STORE_add_cert(store, x509_1), 1);
  64635. ExpectIntEQ(ca_num = wolfSSL_X509_CA_num(store), 1);
  64636. ExpectNotNull(x509_2 = wolfSSL_X509_load_certificate_file(eccCertFile,
  64637. WOLFSSL_FILETYPE_PEM));
  64638. ExpectIntEQ(wolfSSL_X509_STORE_add_cert(store, x509_2), 1);
  64639. ExpectIntEQ(ca_num = wolfSSL_X509_CA_num(store), 2);
  64640. wolfSSL_X509_free(x509_1);
  64641. wolfSSL_X509_free(x509_2);
  64642. wolfSSL_X509_STORE_free(store);
  64643. #endif
  64644. return EXPECT_RESULT();
  64645. }
  64646. static int test_wolfSSL_X509_check_ca(void)
  64647. {
  64648. EXPECT_DECLS;
  64649. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  64650. WOLFSSL_X509 *x509 = NULL;
  64651. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  64652. WOLFSSL_FILETYPE_PEM));
  64653. ExpectIntEQ(wolfSSL_X509_check_ca(x509), 1);
  64654. wolfSSL_X509_free(x509);
  64655. #endif
  64656. return EXPECT_RESULT();
  64657. }
  64658. static int test_wolfSSL_X509_check_ip_asc(void)
  64659. {
  64660. EXPECT_DECLS;
  64661. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  64662. WOLFSSL_X509 *x509 = NULL;
  64663. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  64664. WOLFSSL_FILETYPE_PEM));
  64665. #if 0
  64666. /* TODO: add cert gen for testing positive case */
  64667. ExpectIntEQ(wolfSSL_X509_check_ip_asc(x509, "127.0.0.1", 0), 1);
  64668. #endif
  64669. ExpectIntEQ(wolfSSL_X509_check_ip_asc(x509, "0.0.0.0", 0), 0);
  64670. ExpectIntEQ(wolfSSL_X509_check_ip_asc(x509, NULL, 0), 0);
  64671. wolfSSL_X509_free(x509);
  64672. #endif
  64673. return EXPECT_RESULT();
  64674. }
  64675. static int test_wolfSSL_make_cert(void)
  64676. {
  64677. EXPECT_DECLS;
  64678. #if !defined(NO_RSA) && !defined(NO_ASN_TIME) && defined(WOLFSSL_CERT_GEN) && \
  64679. defined(WOLFSSL_CERT_EXT)
  64680. int ret = 0;
  64681. Cert cert;
  64682. CertName name;
  64683. RsaKey key;
  64684. WC_RNG rng;
  64685. byte der[FOURK_BUF];
  64686. word32 idx = 0;
  64687. const byte mySerial[8] = {1,2,3,4,5,6,7,8};
  64688. #ifdef OPENSSL_EXTRA
  64689. const unsigned char* pt = NULL;
  64690. int certSz = 0;
  64691. X509* x509 = NULL;
  64692. X509_NAME* x509name = NULL;
  64693. X509_NAME_ENTRY* entry = NULL;
  64694. ASN1_STRING* entryValue = NULL;
  64695. #endif
  64696. XMEMSET(&name, 0, sizeof(CertName));
  64697. /* set up cert name */
  64698. XMEMCPY(name.country, "US", sizeof("US"));
  64699. name.countryEnc = CTC_PRINTABLE;
  64700. XMEMCPY(name.state, "Oregon", sizeof("Oregon"));
  64701. name.stateEnc = CTC_UTF8;
  64702. XMEMCPY(name.locality, "Portland", sizeof("Portland"));
  64703. name.localityEnc = CTC_UTF8;
  64704. XMEMCPY(name.sur, "Test", sizeof("Test"));
  64705. name.surEnc = CTC_UTF8;
  64706. XMEMCPY(name.org, "wolfSSL", sizeof("wolfSSL"));
  64707. name.orgEnc = CTC_UTF8;
  64708. XMEMCPY(name.unit, "Development", sizeof("Development"));
  64709. name.unitEnc = CTC_UTF8;
  64710. XMEMCPY(name.commonName, "www.wolfssl.com", sizeof("www.wolfssl.com"));
  64711. name.commonNameEnc = CTC_UTF8;
  64712. XMEMCPY(name.serialDev, "wolfSSL12345", sizeof("wolfSSL12345"));
  64713. name.serialDevEnc = CTC_PRINTABLE;
  64714. XMEMCPY(name.userId, "TestUserID", sizeof("TestUserID"));
  64715. name.userIdEnc = CTC_PRINTABLE;
  64716. #ifdef WOLFSSL_MULTI_ATTRIB
  64717. #if CTC_MAX_ATTRIB > 2
  64718. {
  64719. NameAttrib* n;
  64720. n = &name.name[0];
  64721. n->id = ASN_DOMAIN_COMPONENT;
  64722. n->type = CTC_UTF8;
  64723. n->sz = sizeof("com");
  64724. XMEMCPY(n->value, "com", sizeof("com"));
  64725. n = &name.name[1];
  64726. n->id = ASN_DOMAIN_COMPONENT;
  64727. n->type = CTC_UTF8;
  64728. n->sz = sizeof("wolfssl");
  64729. XMEMCPY(n->value, "wolfssl", sizeof("wolfssl"));
  64730. }
  64731. #endif
  64732. #endif /* WOLFSSL_MULTI_ATTRIB */
  64733. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  64734. #ifndef HAVE_FIPS
  64735. ExpectIntEQ(wc_InitRng_ex(&rng, HEAP_HINT, testDevId), 0);
  64736. #else
  64737. ExpectIntEQ(wc_InitRng(&rng), 0);
  64738. #endif
  64739. /* load test RSA key */
  64740. idx = 0;
  64741. #if defined(USE_CERT_BUFFERS_1024)
  64742. ExpectIntEQ(wc_RsaPrivateKeyDecode(server_key_der_1024, &idx, &key,
  64743. sizeof_server_key_der_1024), 0);
  64744. #elif defined(USE_CERT_BUFFERS_2048)
  64745. ExpectIntEQ(wc_RsaPrivateKeyDecode(server_key_der_2048, &idx, &key,
  64746. sizeof_server_key_der_2048), 0);
  64747. #else
  64748. /* error case, no RSA key loaded, happens later */
  64749. (void)idx;
  64750. #endif
  64751. XMEMSET(&cert, 0 , sizeof(Cert));
  64752. ExpectIntEQ(wc_InitCert(&cert), 0);
  64753. XMEMCPY(&cert.subject, &name, sizeof(CertName));
  64754. XMEMCPY(cert.serial, mySerial, sizeof(mySerial));
  64755. cert.serialSz = (int)sizeof(mySerial);
  64756. cert.isCA = 1;
  64757. #ifndef NO_SHA256
  64758. cert.sigType = CTC_SHA256wRSA;
  64759. #else
  64760. cert.sigType = CTC_SHAwRSA;
  64761. #endif
  64762. /* add SKID from the Public Key */
  64763. ExpectIntEQ(wc_SetSubjectKeyIdFromPublicKey(&cert, &key, NULL), 0);
  64764. /* add AKID from the Public Key */
  64765. ExpectIntEQ(wc_SetAuthKeyIdFromPublicKey(&cert, &key, NULL), 0);
  64766. ret = 0;
  64767. do {
  64768. #if defined(WOLFSSL_ASYNC_CRYPT)
  64769. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  64770. #endif
  64771. if (ret >= 0) {
  64772. ret = wc_MakeSelfCert(&cert, der, FOURK_BUF, &key, &rng);
  64773. }
  64774. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  64775. ExpectIntGT(ret, 0);
  64776. #ifdef OPENSSL_EXTRA
  64777. /* der holds a certificate with DC's now check X509 parsing of it */
  64778. certSz = ret;
  64779. pt = der;
  64780. ExpectNotNull(x509 = d2i_X509(NULL, &pt, certSz));
  64781. ExpectNotNull(x509name = X509_get_subject_name(x509));
  64782. #ifdef WOLFSSL_MULTI_ATTRIB
  64783. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_domainComponent,
  64784. -1)), 5);
  64785. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_domainComponent,
  64786. (int)idx)), 6);
  64787. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_domainComponent,
  64788. (int)idx)), -1);
  64789. #endif /* WOLFSSL_MULTI_ATTRIB */
  64790. /* compare DN at index 0 */
  64791. ExpectNotNull(entry = X509_NAME_get_entry(x509name, 0));
  64792. ExpectNotNull(entryValue = X509_NAME_ENTRY_get_data(entry));
  64793. ExpectIntEQ(ASN1_STRING_length(entryValue), 2);
  64794. ExpectStrEQ((const char*)ASN1_STRING_data(entryValue), "US");
  64795. #ifndef WOLFSSL_MULTI_ATTRIB
  64796. /* compare Serial Number */
  64797. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_serialNumber,
  64798. -1)), 7);
  64799. ExpectNotNull(entry = X509_NAME_get_entry(x509name, idx));
  64800. ExpectNotNull(entryValue = X509_NAME_ENTRY_get_data(entry));
  64801. ExpectIntEQ(ASN1_STRING_length(entryValue), XSTRLEN("wolfSSL12345"));
  64802. ExpectStrEQ((const char*)ASN1_STRING_data(entryValue), "wolfSSL12345");
  64803. #endif
  64804. #ifdef WOLFSSL_MULTI_ATTRIB
  64805. /* get first and second DC and compare result */
  64806. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_domainComponent,
  64807. -1)), 5);
  64808. ExpectNotNull(entry = X509_NAME_get_entry(x509name, (int)idx));
  64809. ExpectNotNull(entryValue = X509_NAME_ENTRY_get_data(entry));
  64810. ExpectStrEQ((const char *)ASN1_STRING_data(entryValue), "com");
  64811. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_domainComponent,
  64812. (int)idx)), 6);
  64813. ExpectNotNull(entry = X509_NAME_get_entry(x509name, (int)idx));
  64814. ExpectNotNull(entryValue = X509_NAME_ENTRY_get_data(entry));
  64815. ExpectStrEQ((const char *)ASN1_STRING_data(entryValue), "wolfssl");
  64816. #endif /* WOLFSSL_MULTI_ATTRIB */
  64817. /* try invalid index locations for regression test and sanity check */
  64818. ExpectNull(entry = X509_NAME_get_entry(x509name, 11));
  64819. ExpectNull(entry = X509_NAME_get_entry(x509name, 20));
  64820. X509_free(x509);
  64821. #endif /* OPENSSL_EXTRA */
  64822. wc_FreeRsaKey(&key);
  64823. wc_FreeRng(&rng);
  64824. #endif
  64825. return EXPECT_RESULT();
  64826. }
  64827. static int test_x509_get_key_id(void)
  64828. {
  64829. EXPECT_DECLS;
  64830. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  64831. X509 *x509 = NULL;
  64832. const ASN1_STRING* str = NULL;
  64833. byte* keyId = NULL;
  64834. ExpectNotNull(x509 = X509_load_certificate_file(cliCertFile,
  64835. WOLFSSL_FILETYPE_PEM));
  64836. ExpectNotNull(str = X509_get0_subject_key_id(x509));
  64837. ExpectNotNull(keyId = wolfSSL_X509_get_subjectKeyID(x509, NULL, NULL));
  64838. ExpectBufEQ(keyId, ASN1_STRING_data((ASN1_STRING*)str),
  64839. ASN1_STRING_length(str));
  64840. X509_free(x509);
  64841. #endif
  64842. return EXPECT_RESULT();
  64843. }
  64844. static int test_wolfSSL_X509_get_version(void)
  64845. {
  64846. EXPECT_DECLS;
  64847. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  64848. WOLFSSL_X509 *x509 = NULL;
  64849. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  64850. WOLFSSL_FILETYPE_PEM));
  64851. ExpectIntEQ((int)wolfSSL_X509_get_version(x509), 2);
  64852. wolfSSL_X509_free(x509);
  64853. #endif
  64854. return EXPECT_RESULT();
  64855. }
  64856. #if defined(OPENSSL_ALL)
  64857. static int test_wolfSSL_sk_CIPHER_description(void)
  64858. {
  64859. EXPECT_DECLS;
  64860. #if !defined(NO_RSA)
  64861. const long flags = SSL_OP_NO_SSLv2 | SSL_OP_NO_COMPRESSION;
  64862. int i;
  64863. int numCiphers = 0;
  64864. const SSL_METHOD *method = NULL;
  64865. const SSL_CIPHER *cipher = NULL;
  64866. STACK_OF(SSL_CIPHER) *supportedCiphers = NULL;
  64867. SSL_CTX *ctx = NULL;
  64868. SSL *ssl = NULL;
  64869. char buf[256];
  64870. char test_str[9] = "0000000";
  64871. const char badStr[] = "unknown";
  64872. const char certPath[] = "./certs/client-cert.pem";
  64873. XMEMSET(buf, 0, sizeof(buf));
  64874. ExpectNotNull(method = TLSv1_2_client_method());
  64875. ExpectNotNull(ctx = SSL_CTX_new(method));
  64876. SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, 0);
  64877. SSL_CTX_set_verify_depth(ctx, 4);
  64878. SSL_CTX_set_options(ctx, flags);
  64879. ExpectIntEQ(SSL_CTX_load_verify_locations(ctx, certPath, NULL),
  64880. WOLFSSL_SUCCESS);
  64881. ExpectNotNull(ssl = SSL_new(ctx));
  64882. /* SSL_get_ciphers returns a stack of all configured ciphers
  64883. * A flag, getCipherAtOffset, is set to later have SSL_CIPHER_description
  64884. */
  64885. ExpectNotNull(supportedCiphers = SSL_get_ciphers(ssl));
  64886. /* loop through the amount of supportedCiphers */
  64887. numCiphers = sk_num(supportedCiphers);
  64888. for (i = 0; i < numCiphers; ++i) {
  64889. int j;
  64890. /* sk_value increments "sk->data.cipher->cipherOffset".
  64891. * wolfSSL_sk_CIPHER_description sets the description for
  64892. * the cipher based on the provided offset.
  64893. */
  64894. if ((cipher = (const WOLFSSL_CIPHER*)sk_value(supportedCiphers, i))) {
  64895. SSL_CIPHER_description(cipher, buf, sizeof(buf));
  64896. }
  64897. /* Search cipher description string for "unknown" descriptor */
  64898. for (j = 0; j < (int)XSTRLEN(buf); j++) {
  64899. int k = 0;
  64900. while ((k < (int)XSTRLEN(badStr)) && (buf[j] == badStr[k])) {
  64901. test_str[k] = badStr[k];
  64902. j++;
  64903. k++;
  64904. }
  64905. }
  64906. /* Fail if test_str == badStr == "unknown" */
  64907. ExpectStrNE(test_str,badStr);
  64908. }
  64909. SSL_free(ssl);
  64910. SSL_CTX_free(ctx);
  64911. #endif
  64912. return EXPECT_RESULT();
  64913. }
  64914. static int test_wolfSSL_get_ciphers_compat(void)
  64915. {
  64916. EXPECT_DECLS;
  64917. #if !defined(NO_RSA)
  64918. const SSL_METHOD *method = NULL;
  64919. const char certPath[] = "./certs/client-cert.pem";
  64920. STACK_OF(SSL_CIPHER) *supportedCiphers = NULL;
  64921. SSL_CTX *ctx = NULL;
  64922. WOLFSSL *ssl = NULL;
  64923. const long flags = SSL_OP_NO_SSLv2 | SSL_OP_NO_COMPRESSION;
  64924. ExpectNotNull(method = SSLv23_client_method());
  64925. ExpectNotNull(ctx = SSL_CTX_new(method));
  64926. SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, 0);
  64927. SSL_CTX_set_verify_depth(ctx, 4);
  64928. SSL_CTX_set_options(ctx, flags);
  64929. ExpectIntEQ(SSL_CTX_load_verify_locations(ctx, certPath, NULL),
  64930. WOLFSSL_SUCCESS);
  64931. ExpectNotNull(ssl = SSL_new(ctx));
  64932. /* Test Bad NULL input */
  64933. ExpectNull(supportedCiphers = SSL_get_ciphers(NULL));
  64934. /* Test for Good input */
  64935. ExpectNotNull(supportedCiphers = SSL_get_ciphers(ssl));
  64936. /* Further usage of SSL_get_ciphers/wolfSSL_get_ciphers_compat is
  64937. * tested in test_wolfSSL_sk_CIPHER_description according to Qt usage */
  64938. SSL_free(ssl);
  64939. SSL_CTX_free(ctx);
  64940. #endif
  64941. return EXPECT_RESULT();
  64942. }
  64943. static int test_wolfSSL_X509_PUBKEY_get(void)
  64944. {
  64945. EXPECT_DECLS;
  64946. WOLFSSL_X509_PUBKEY pubkey;
  64947. WOLFSSL_X509_PUBKEY* key;
  64948. WOLFSSL_EVP_PKEY evpkey ;
  64949. WOLFSSL_EVP_PKEY* evpPkey;
  64950. WOLFSSL_EVP_PKEY* retEvpPkey;
  64951. XMEMSET(&pubkey, 0, sizeof(WOLFSSL_X509_PUBKEY));
  64952. XMEMSET(&evpkey, 0, sizeof(WOLFSSL_EVP_PKEY));
  64953. key = &pubkey;
  64954. evpPkey = &evpkey;
  64955. evpPkey->type = WOLFSSL_SUCCESS;
  64956. key->pkey = evpPkey;
  64957. ExpectNotNull(retEvpPkey = wolfSSL_X509_PUBKEY_get(key));
  64958. ExpectIntEQ(retEvpPkey->type, WOLFSSL_SUCCESS);
  64959. ExpectNull(retEvpPkey = wolfSSL_X509_PUBKEY_get(NULL));
  64960. key->pkey = NULL;
  64961. ExpectNull(retEvpPkey = wolfSSL_X509_PUBKEY_get(key));
  64962. return EXPECT_RESULT();
  64963. }
  64964. static int test_wolfSSL_EVP_PKEY_set1_get1_DSA(void)
  64965. {
  64966. EXPECT_DECLS;
  64967. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  64968. DSA *dsa = NULL;
  64969. DSA *setDsa = NULL;
  64970. EVP_PKEY *pkey = NULL;
  64971. EVP_PKEY *set1Pkey = NULL;
  64972. SHA_CTX sha;
  64973. byte signature[DSA_SIG_SIZE];
  64974. byte hash[WC_SHA_DIGEST_SIZE];
  64975. word32 bytes;
  64976. int answer;
  64977. #ifdef USE_CERT_BUFFERS_1024
  64978. const unsigned char* dsaKeyDer = dsa_key_der_1024;
  64979. int dsaKeySz = sizeof_dsa_key_der_1024;
  64980. byte tmp[ONEK_BUF];
  64981. XMEMSET(tmp, 0, sizeof(tmp));
  64982. XMEMCPY(tmp, dsaKeyDer , dsaKeySz);
  64983. bytes = dsaKeySz;
  64984. #elif defined(USE_CERT_BUFFERS_2048)
  64985. const unsigned char* dsaKeyDer = dsa_key_der_2048;
  64986. int dsaKeySz = sizeof_dsa_key_der_2048;
  64987. byte tmp[TWOK_BUF];
  64988. XMEMSET(tmp, 0, sizeof(tmp));
  64989. XMEMCPY(tmp, dsaKeyDer , dsaKeySz);
  64990. bytes = (word32)dsaKeySz;
  64991. #else
  64992. byte tmp[TWOK_BUF];
  64993. const unsigned char* dsaKeyDer = (const unsigned char*)tmp;
  64994. int dsaKeySz;
  64995. XFILE fp = XBADFILE;
  64996. XMEMSET(tmp, 0, sizeof(tmp));
  64997. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb")) != XBADFILE);
  64998. ExpectIntGT(dsaKeySz = bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), fp), 0);
  64999. if (fp != XBADFILE)
  65000. XFCLOSE(fp);
  65001. #endif /* END USE_CERT_BUFFERS_1024 */
  65002. /* Create hash to later Sign and Verify */
  65003. ExpectIntEQ(SHA1_Init(&sha), WOLFSSL_SUCCESS);
  65004. ExpectIntEQ(SHA1_Update(&sha, tmp, bytes), WOLFSSL_SUCCESS);
  65005. ExpectIntEQ(SHA1_Final(hash,&sha), WOLFSSL_SUCCESS);
  65006. /* Initialize pkey with der format dsa key */
  65007. ExpectNotNull(d2i_PrivateKey(EVP_PKEY_DSA, &pkey, &dsaKeyDer,
  65008. (long)dsaKeySz));
  65009. /* Test wolfSSL_EVP_PKEY_get1_DSA */
  65010. /* Should Fail: NULL argument */
  65011. ExpectNull(dsa = EVP_PKEY_get0_DSA(NULL));
  65012. ExpectNull(dsa = EVP_PKEY_get1_DSA(NULL));
  65013. /* Should Pass: Initialized pkey argument */
  65014. ExpectNotNull(dsa = EVP_PKEY_get0_DSA(pkey));
  65015. ExpectNotNull(dsa = EVP_PKEY_get1_DSA(pkey));
  65016. #ifdef USE_CERT_BUFFERS_1024
  65017. ExpectIntEQ(DSA_bits(dsa), 1024);
  65018. #else
  65019. ExpectIntEQ(DSA_bits(dsa), 2048);
  65020. #endif
  65021. /* Sign */
  65022. ExpectIntEQ(wolfSSL_DSA_do_sign(hash, signature, dsa), WOLFSSL_SUCCESS);
  65023. /* Verify. */
  65024. ExpectIntEQ(wolfSSL_DSA_do_verify(hash, signature, dsa, &answer),
  65025. WOLFSSL_SUCCESS);
  65026. /* Test wolfSSL_EVP_PKEY_set1_DSA */
  65027. /* Should Fail: set1Pkey not initialized */
  65028. ExpectIntNE(EVP_PKEY_set1_DSA(set1Pkey, dsa), WOLFSSL_SUCCESS);
  65029. /* Initialize set1Pkey */
  65030. set1Pkey = EVP_PKEY_new();
  65031. /* Should Fail Verify: setDsa not initialized from set1Pkey */
  65032. ExpectIntNE(wolfSSL_DSA_do_verify(hash,signature,setDsa,&answer),
  65033. WOLFSSL_SUCCESS);
  65034. /* Should Pass: set dsa into set1Pkey */
  65035. ExpectIntEQ(EVP_PKEY_set1_DSA(set1Pkey, dsa), WOLFSSL_SUCCESS);
  65036. DSA_free(dsa);
  65037. DSA_free(setDsa);
  65038. EVP_PKEY_free(pkey);
  65039. EVP_PKEY_free(set1Pkey);
  65040. #endif /* !NO_DSA && !HAVE_SELFTEST && WOLFSSL_KEY_GEN */
  65041. return EXPECT_RESULT();
  65042. } /* END test_EVP_PKEY_set1_get1_DSA */
  65043. static int test_wolfSSL_DSA_generate_parameters(void)
  65044. {
  65045. EXPECT_DECLS;
  65046. #if !defined(NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN) && \
  65047. !defined(HAVE_FIPS)
  65048. DSA *dsa = NULL;
  65049. ExpectNotNull(dsa = DSA_generate_parameters(2048, NULL, 0, NULL, NULL, NULL,
  65050. NULL));
  65051. DSA_free(dsa);
  65052. #endif
  65053. return EXPECT_RESULT();
  65054. }
  65055. static int test_wolfSSL_DSA_SIG(void)
  65056. {
  65057. EXPECT_DECLS;
  65058. #if !defined(NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN) && \
  65059. !defined(HAVE_FIPS)
  65060. DSA *dsa = NULL;
  65061. DSA *dsa2 = NULL;
  65062. DSA_SIG *sig = NULL;
  65063. const BIGNUM *p = NULL;
  65064. const BIGNUM *q = NULL;
  65065. const BIGNUM *g = NULL;
  65066. const BIGNUM *pub = NULL;
  65067. const BIGNUM *priv = NULL;
  65068. BIGNUM *dup_p = NULL;
  65069. BIGNUM *dup_q = NULL;
  65070. BIGNUM *dup_g = NULL;
  65071. BIGNUM *dup_pub = NULL;
  65072. BIGNUM *dup_priv = NULL;
  65073. const byte digest[WC_SHA_DIGEST_SIZE] = {0};
  65074. ExpectNotNull(dsa = DSA_new());
  65075. ExpectIntEQ(DSA_generate_parameters_ex(dsa, 2048, NULL, 0, NULL, NULL,
  65076. NULL), 1);
  65077. ExpectIntEQ(DSA_generate_key(dsa), 1);
  65078. DSA_get0_pqg(dsa, &p, &q, &g);
  65079. DSA_get0_key(dsa, &pub, &priv);
  65080. ExpectNotNull(dup_p = BN_dup(p));
  65081. ExpectNotNull(dup_q = BN_dup(q));
  65082. ExpectNotNull(dup_g = BN_dup(g));
  65083. ExpectNotNull(dup_pub = BN_dup(pub));
  65084. ExpectNotNull(dup_priv = BN_dup(priv));
  65085. ExpectNotNull(sig = DSA_do_sign(digest, sizeof(digest), dsa));
  65086. ExpectNotNull(dsa2 = DSA_new());
  65087. ExpectIntEQ(DSA_set0_pqg(dsa2, dup_p, dup_q, dup_g), 1);
  65088. if (EXPECT_FAIL()) {
  65089. BN_free(dup_p);
  65090. BN_free(dup_q);
  65091. BN_free(dup_g);
  65092. }
  65093. ExpectIntEQ(DSA_set0_key(dsa2, dup_pub, dup_priv), 1);
  65094. if (EXPECT_FAIL()) {
  65095. BN_free(dup_pub);
  65096. BN_free(dup_priv);
  65097. }
  65098. ExpectIntEQ(DSA_do_verify(digest, sizeof(digest), sig, dsa2), 1);
  65099. DSA_free(dsa);
  65100. DSA_free(dsa2);
  65101. DSA_SIG_free(sig);
  65102. #endif
  65103. return EXPECT_RESULT();
  65104. }
  65105. static int test_wolfSSL_EVP_PKEY_set1_get1_EC_KEY (void)
  65106. {
  65107. EXPECT_DECLS;
  65108. #ifdef HAVE_ECC
  65109. WOLFSSL_EC_KEY* ecKey = NULL;
  65110. WOLFSSL_EC_KEY* ecGet1 = NULL;
  65111. EVP_PKEY* pkey = NULL;
  65112. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  65113. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65114. /* Test wolfSSL_EVP_PKEY_set1_EC_KEY */
  65115. ExpectIntEQ(wolfSSL_EVP_PKEY_set1_EC_KEY(NULL, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65116. ExpectIntEQ(wolfSSL_EVP_PKEY_set1_EC_KEY(pkey, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65117. /* Should fail since ecKey is empty */
  65118. ExpectIntEQ(wolfSSL_EVP_PKEY_set1_EC_KEY(pkey, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65119. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  65120. ExpectIntEQ(wolfSSL_EVP_PKEY_set1_EC_KEY(pkey, ecKey), WOLFSSL_SUCCESS);
  65121. /* Test wolfSSL_EVP_PKEY_get1_EC_KEY */
  65122. ExpectNull(wolfSSL_EVP_PKEY_get1_EC_KEY(NULL));
  65123. ExpectNotNull(ecGet1 = wolfSSL_EVP_PKEY_get1_EC_KEY(pkey));
  65124. wolfSSL_EC_KEY_free(ecKey);
  65125. wolfSSL_EC_KEY_free(ecGet1);
  65126. EVP_PKEY_free(pkey);
  65127. #endif /* HAVE_ECC */
  65128. return EXPECT_RESULT();
  65129. } /* END test_EVP_PKEY_set1_get1_EC_KEY */
  65130. static int test_wolfSSL_EVP_PKEY_set1_get1_DH (void)
  65131. {
  65132. EXPECT_DECLS;
  65133. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT) || defined(WOLFSSL_OPENSSH)
  65134. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  65135. #if !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA) && !defined(NO_FILESYSTEM)
  65136. DH *dh = NULL;
  65137. DH *setDh = NULL;
  65138. EVP_PKEY *pkey = NULL;
  65139. XFILE f = XBADFILE;
  65140. unsigned char buf[4096];
  65141. const unsigned char* pt = buf;
  65142. const char* dh2048 = "./certs/dh2048.der";
  65143. long len = 0;
  65144. int code = -1;
  65145. XMEMSET(buf, 0, sizeof(buf));
  65146. ExpectTrue((f = XFOPEN(dh2048, "rb")) != XBADFILE);
  65147. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  65148. if (f != XBADFILE)
  65149. XFCLOSE(f);
  65150. /* Load dh2048.der into DH with internal format */
  65151. ExpectNotNull(setDh = wolfSSL_d2i_DHparams(NULL, &pt, len));
  65152. ExpectIntEQ(wolfSSL_DH_check(setDh, &code), WOLFSSL_SUCCESS);
  65153. ExpectIntEQ(code, 0);
  65154. code = -1;
  65155. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65156. /* Set DH into PKEY */
  65157. ExpectIntEQ(wolfSSL_EVP_PKEY_set1_DH(pkey, setDh), WOLFSSL_SUCCESS);
  65158. /* Get DH from PKEY */
  65159. ExpectNotNull(dh = wolfSSL_EVP_PKEY_get1_DH(pkey));
  65160. ExpectIntEQ(wolfSSL_DH_check(dh, &code), WOLFSSL_SUCCESS);
  65161. ExpectIntEQ(code, 0);
  65162. EVP_PKEY_free(pkey);
  65163. DH_free(setDh);
  65164. setDh = NULL;
  65165. DH_free(dh);
  65166. dh = NULL;
  65167. #endif /* !NO_DH && WOLFSSL_DH_EXTRA && !NO_FILESYSTEM */
  65168. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  65169. #endif /* OPENSSL_ALL || WOLFSSL_QT || WOLFSSL_OPENSSH */
  65170. return EXPECT_RESULT();
  65171. } /* END test_EVP_PKEY_set1_get1_DH */
  65172. static int test_wolfSSL_CTX_ctrl(void)
  65173. {
  65174. EXPECT_DECLS;
  65175. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  65176. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  65177. char caFile[] = "./certs/client-ca.pem";
  65178. char clientFile[] = "./certs/client-cert.pem";
  65179. SSL_CTX* ctx = NULL;
  65180. X509* x509 = NULL;
  65181. #if !defined(NO_DH) && !defined(NO_DSA) && !defined(NO_BIO)
  65182. byte buf[6000];
  65183. char file[] = "./certs/dsaparams.pem";
  65184. XFILE f = XBADFILE;
  65185. int bytes = 0;
  65186. BIO* bio = NULL;
  65187. DSA* dsa = NULL;
  65188. DH* dh = NULL;
  65189. #endif
  65190. #ifdef HAVE_ECC
  65191. WOLFSSL_EC_KEY* ecKey = NULL;
  65192. #endif
  65193. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  65194. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(caFile,
  65195. WOLFSSL_FILETYPE_PEM));
  65196. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(ctx, x509), WOLFSSL_SUCCESS);
  65197. if (EXPECT_FAIL()) {
  65198. wolfSSL_X509_free(x509);
  65199. }
  65200. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(clientFile,
  65201. WOLFSSL_FILETYPE_PEM));
  65202. #if !defined(NO_DH) && !defined(NO_DSA) && !defined(NO_BIO)
  65203. /* Initialize DH */
  65204. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  65205. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  65206. if (f != XBADFILE)
  65207. XFCLOSE(f);
  65208. ExpectNotNull(bio = BIO_new_mem_buf((void*)buf, bytes));
  65209. ExpectNotNull(dsa = wolfSSL_PEM_read_bio_DSAparams(bio, NULL, NULL, NULL));
  65210. ExpectNotNull(dh = wolfSSL_DSA_dup_DH(dsa));
  65211. #endif
  65212. #ifdef HAVE_ECC
  65213. /* Initialize WOLFSSL_EC_KEY */
  65214. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  65215. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  65216. #endif
  65217. /* additional test of getting EVP_PKEY key size from X509
  65218. * Do not run with user RSA because wolfSSL_RSA_size is not currently
  65219. * allowed with user RSA */
  65220. {
  65221. EVP_PKEY* pkey = NULL;
  65222. #if defined(HAVE_ECC)
  65223. X509* ecX509 = NULL;
  65224. #endif /* HAVE_ECC */
  65225. ExpectNotNull(pkey = X509_get_pubkey(x509));
  65226. /* current RSA key is 2048 bit (256 bytes) */
  65227. ExpectIntEQ(EVP_PKEY_size(pkey), 256);
  65228. EVP_PKEY_free(pkey);
  65229. pkey = NULL;
  65230. #if defined(HAVE_ECC)
  65231. #if defined(USE_CERT_BUFFERS_256)
  65232. ExpectNotNull(ecX509 = wolfSSL_X509_load_certificate_buffer(
  65233. cliecc_cert_der_256, sizeof_cliecc_cert_der_256,
  65234. SSL_FILETYPE_ASN1));
  65235. #else
  65236. ExpectNotNull(ecX509 = wolfSSL_X509_load_certificate_file(
  65237. cliEccCertFile, SSL_FILETYPE_PEM));
  65238. #endif
  65239. ExpectNotNull(pkey = X509_get_pubkey(ecX509));
  65240. /* current ECC key is 256 bit (32 bytes) */
  65241. ExpectIntEQ(EVP_PKEY_size(pkey), 32);
  65242. X509_free(ecX509);
  65243. EVP_PKEY_free(pkey);
  65244. #endif /* HAVE_ECC */
  65245. }
  65246. /* Tests should fail with passed in NULL pointer */
  65247. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_EXTRA_CHAIN_CERT, 0, NULL),
  65248. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65249. #if !defined(NO_DH) && !defined(NO_DSA)
  65250. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_TMP_DH, 0, NULL),
  65251. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65252. #endif
  65253. #ifdef HAVE_ECC
  65254. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_TMP_ECDH, 0, NULL),
  65255. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65256. #endif
  65257. /* Test with SSL_CTRL_EXTRA_CHAIN_CERT
  65258. * wolfSSL_CTX_ctrl should succesffuly call SSL_CTX_add_extra_chain_cert
  65259. */
  65260. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_EXTRA_CHAIN_CERT, 0, x509),
  65261. SSL_SUCCESS);
  65262. if (EXPECT_FAIL()) {
  65263. wolfSSL_X509_free(x509);
  65264. }
  65265. /* Test with SSL_CTRL_OPTIONS
  65266. * wolfSSL_CTX_ctrl should succesffuly call SSL_CTX_set_options
  65267. */
  65268. ExpectTrue(wolfSSL_CTX_ctrl(ctx, SSL_CTRL_OPTIONS, SSL_OP_NO_TLSv1,
  65269. NULL) == SSL_OP_NO_TLSv1);
  65270. ExpectTrue(SSL_CTX_get_options(ctx) == SSL_OP_NO_TLSv1);
  65271. /* Test with SSL_CTRL_SET_TMP_DH
  65272. * wolfSSL_CTX_ctrl should succesffuly call wolfSSL_SSL_CTX_set_tmp_dh
  65273. */
  65274. #if !defined(NO_DH) && !defined(NO_DSA) && !defined(NO_BIO)
  65275. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_TMP_DH, 0, dh),
  65276. SSL_SUCCESS);
  65277. #endif
  65278. /* Test with SSL_CTRL_SET_TMP_ECDH
  65279. * wolfSSL_CTX_ctrl should succesffuly call wolfSSL_SSL_CTX_set_tmp_ecdh
  65280. */
  65281. #ifdef HAVE_ECC
  65282. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_TMP_ECDH, 0, ecKey),
  65283. SSL_SUCCESS);
  65284. #endif
  65285. #ifdef WOLFSSL_ENCRYPTED_KEYS
  65286. ExpectNull(SSL_CTX_get_default_passwd_cb(ctx));
  65287. ExpectNull(SSL_CTX_get_default_passwd_cb_userdata(ctx));
  65288. #endif
  65289. /* Test for min/max proto */
  65290. #ifndef WOLFSSL_NO_TLS12
  65291. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_MIN_PROTO_VERSION,
  65292. 0, NULL), SSL_SUCCESS);
  65293. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_MIN_PROTO_VERSION,
  65294. TLS1_2_VERSION, NULL), SSL_SUCCESS);
  65295. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_2_VERSION);
  65296. #endif
  65297. #ifdef WOLFSSL_TLS13
  65298. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_PROTO_VERSION,
  65299. 0, NULL), SSL_SUCCESS);
  65300. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_PROTO_VERSION,
  65301. TLS1_3_VERSION, NULL), SSL_SUCCESS);
  65302. ExpectIntEQ(wolfSSL_CTX_get_max_proto_version(ctx), TLS1_3_VERSION);
  65303. #ifndef WOLFSSL_NO_TLS12
  65304. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_PROTO_VERSION,
  65305. TLS1_2_VERSION, NULL), SSL_SUCCESS);
  65306. ExpectIntEQ(wolfSSL_CTX_get_max_proto_version(ctx), TLS1_2_VERSION);
  65307. #endif
  65308. #endif
  65309. /* Cleanup and Pass */
  65310. #if !defined(NO_DH) && !defined(NO_DSA)
  65311. #ifndef NO_BIO
  65312. BIO_free(bio);
  65313. DSA_free(dsa);
  65314. DH_free(dh);
  65315. dh = NULL;
  65316. #endif
  65317. #endif
  65318. #ifdef HAVE_ECC
  65319. wolfSSL_EC_KEY_free(ecKey);
  65320. #endif
  65321. SSL_CTX_free(ctx);
  65322. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  65323. * !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  65324. return EXPECT_RESULT();
  65325. }
  65326. static int test_wolfSSL_EVP_PKEY_assign(void)
  65327. {
  65328. EXPECT_DECLS;
  65329. #if !defined(NO_RSA) || !defined(NO_DSA) || defined(HAVE_ECC)
  65330. int type;
  65331. WOLFSSL_EVP_PKEY* pkey = NULL;
  65332. #ifndef NO_RSA
  65333. WOLFSSL_RSA* rsa = NULL;
  65334. #endif
  65335. #ifndef NO_DSA
  65336. WOLFSSL_DSA* dsa = NULL;
  65337. #endif
  65338. #ifdef HAVE_ECC
  65339. WOLFSSL_EC_KEY* ecKey = NULL;
  65340. #endif
  65341. #ifndef NO_RSA
  65342. type = EVP_PKEY_RSA;
  65343. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65344. ExpectNotNull(rsa = wolfSSL_RSA_new());
  65345. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(NULL, type, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65346. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65347. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, -1, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65348. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, rsa), WOLFSSL_SUCCESS);
  65349. if (EXPECT_FAIL()) {
  65350. wolfSSL_RSA_free(rsa);
  65351. }
  65352. wolfSSL_EVP_PKEY_free(pkey);
  65353. pkey = NULL;
  65354. #endif /* NO_RSA */
  65355. #ifndef NO_DSA
  65356. type = EVP_PKEY_DSA;
  65357. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65358. ExpectNotNull(dsa = wolfSSL_DSA_new());
  65359. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(NULL, type, dsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65360. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65361. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, -1, dsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65362. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, dsa), WOLFSSL_SUCCESS);
  65363. if (EXPECT_FAIL()) {
  65364. wolfSSL_DSA_free(dsa);
  65365. }
  65366. wolfSSL_EVP_PKEY_free(pkey);
  65367. pkey = NULL;
  65368. #endif /* NO_DSA */
  65369. #ifdef HAVE_ECC
  65370. type = EVP_PKEY_EC;
  65371. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65372. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  65373. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(NULL, type, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65374. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65375. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, -1, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65376. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65377. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  65378. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, ecKey), WOLFSSL_SUCCESS);
  65379. if (EXPECT_FAIL()) {
  65380. wolfSSL_EC_KEY_free(ecKey);
  65381. }
  65382. wolfSSL_EVP_PKEY_free(pkey);
  65383. pkey = NULL;
  65384. #endif /* HAVE_ECC */
  65385. #endif /* !NO_RSA || !NO_DSA || HAVE_ECC */
  65386. return EXPECT_RESULT();
  65387. }
  65388. static int test_wolfSSL_EVP_PKEY_assign_DH(void)
  65389. {
  65390. EXPECT_DECLS;
  65391. #if !defined(NO_DH) && \
  65392. !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  65393. XFILE f = XBADFILE;
  65394. unsigned char buf[4096];
  65395. const unsigned char* pt = buf;
  65396. const char* params1 = "./certs/dh2048.der";
  65397. long len = 0;
  65398. WOLFSSL_DH* dh = NULL;
  65399. WOLFSSL_EVP_PKEY* pkey = NULL;
  65400. XMEMSET(buf, 0, sizeof(buf));
  65401. /* Load DH parameters DER. */
  65402. ExpectTrue((f = XFOPEN(params1, "rb")) != XBADFILE);
  65403. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  65404. if (f != XBADFILE)
  65405. XFCLOSE(f);
  65406. ExpectNotNull(dh = wolfSSL_d2i_DHparams(NULL, &pt, len));
  65407. ExpectIntEQ(DH_generate_key(dh), WOLFSSL_SUCCESS);
  65408. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65409. /* Bad cases */
  65410. ExpectIntEQ(wolfSSL_EVP_PKEY_assign_DH(NULL, dh), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65411. ExpectIntEQ(wolfSSL_EVP_PKEY_assign_DH(pkey, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65412. ExpectIntEQ(wolfSSL_EVP_PKEY_assign_DH(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65413. /* Good case */
  65414. ExpectIntEQ(wolfSSL_EVP_PKEY_assign_DH(pkey, dh), WOLFSSL_SUCCESS);
  65415. if (EXPECT_FAIL()) {
  65416. wolfSSL_DH_free(dh);
  65417. }
  65418. EVP_PKEY_free(pkey);
  65419. #endif
  65420. return EXPECT_RESULT();
  65421. }
  65422. static int test_wolfSSL_EVP_PKEY_base_id(void)
  65423. {
  65424. EXPECT_DECLS;
  65425. WOLFSSL_EVP_PKEY* pkey = NULL;
  65426. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65427. ExpectIntEQ(wolfSSL_EVP_PKEY_base_id(NULL), NID_undef);
  65428. ExpectIntEQ(wolfSSL_EVP_PKEY_base_id(pkey), EVP_PKEY_RSA);
  65429. EVP_PKEY_free(pkey);
  65430. return EXPECT_RESULT();
  65431. }
  65432. static int test_wolfSSL_EVP_PKEY_id(void)
  65433. {
  65434. EXPECT_DECLS;
  65435. WOLFSSL_EVP_PKEY* pkey = NULL;
  65436. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65437. ExpectIntEQ(wolfSSL_EVP_PKEY_id(NULL), 0);
  65438. ExpectIntEQ(wolfSSL_EVP_PKEY_id(pkey), EVP_PKEY_RSA);
  65439. EVP_PKEY_free(pkey);
  65440. return EXPECT_RESULT();
  65441. }
  65442. static int test_wolfSSL_EVP_PKEY_paramgen(void)
  65443. {
  65444. EXPECT_DECLS;
  65445. /* ECC check taken from ecc.c. It is the condition that defines ECC256 */
  65446. #if defined(OPENSSL_ALL) && !defined(NO_ECC_SECP) && \
  65447. ((!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && \
  65448. ECC_MIN_KEY_SZ <= 256)
  65449. EVP_PKEY_CTX* ctx = NULL;
  65450. EVP_PKEY* pkey = NULL;
  65451. /* Test error conditions. */
  65452. ExpectIntEQ(EVP_PKEY_paramgen(NULL, &pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65453. ExpectNotNull(ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL));
  65454. ExpectIntEQ(EVP_PKEY_paramgen(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65455. #ifndef NO_RSA
  65456. EVP_PKEY_CTX_free(ctx);
  65457. /* Parameter generation for RSA not supported yet. */
  65458. ExpectNotNull(ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_RSA, NULL));
  65459. ExpectIntEQ(EVP_PKEY_paramgen(ctx, &pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65460. #endif
  65461. #ifdef HAVE_ECC
  65462. EVP_PKEY_CTX_free(ctx);
  65463. ExpectNotNull(ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL));
  65464. ExpectIntEQ(EVP_PKEY_paramgen_init(ctx), WOLFSSL_SUCCESS);
  65465. ExpectIntEQ(EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx,
  65466. NID_X9_62_prime256v1), WOLFSSL_SUCCESS);
  65467. ExpectIntEQ(EVP_PKEY_paramgen(ctx, &pkey), WOLFSSL_SUCCESS);
  65468. ExpectIntEQ(EVP_PKEY_CTX_set_ec_param_enc(ctx, OPENSSL_EC_NAMED_CURVE),
  65469. WOLFSSL_SUCCESS);
  65470. ExpectIntEQ(EVP_PKEY_keygen_init(ctx), WOLFSSL_SUCCESS);
  65471. ExpectIntEQ(EVP_PKEY_keygen(ctx, &pkey), WOLFSSL_SUCCESS);
  65472. #endif
  65473. EVP_PKEY_CTX_free(ctx);
  65474. EVP_PKEY_free(pkey);
  65475. #endif
  65476. return EXPECT_RESULT();
  65477. }
  65478. static int test_wolfSSL_EVP_PKEY_keygen(void)
  65479. {
  65480. EXPECT_DECLS;
  65481. WOLFSSL_EVP_PKEY* pkey = NULL;
  65482. EVP_PKEY_CTX* ctx = NULL;
  65483. #if !defined(NO_DH) && (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0))
  65484. WOLFSSL_EVP_PKEY* params = NULL;
  65485. DH* dh = NULL;
  65486. const BIGNUM* pubkey = NULL;
  65487. const BIGNUM* privkey = NULL;
  65488. ASN1_INTEGER* asn1int = NULL;
  65489. unsigned int length = 0;
  65490. byte* derBuffer = NULL;
  65491. #endif
  65492. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65493. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  65494. /* Bad cases */
  65495. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen(NULL, &pkey), 0);
  65496. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen(ctx, NULL), 0);
  65497. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen(NULL, NULL), 0);
  65498. /* Good case */
  65499. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen(ctx, &pkey), 0);
  65500. EVP_PKEY_CTX_free(ctx);
  65501. ctx = NULL;
  65502. EVP_PKEY_free(pkey);
  65503. pkey = NULL;
  65504. #if !defined(NO_DH) && (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0))
  65505. /* Test DH keygen */
  65506. {
  65507. ExpectNotNull(params = wolfSSL_EVP_PKEY_new());
  65508. ExpectNotNull(dh = DH_get_2048_256());
  65509. ExpectIntEQ(EVP_PKEY_set1_DH(params, dh), WOLFSSL_SUCCESS);
  65510. ExpectNotNull(ctx = EVP_PKEY_CTX_new(params, NULL));
  65511. ExpectIntEQ(EVP_PKEY_keygen_init(ctx), WOLFSSL_SUCCESS);
  65512. ExpectIntEQ(EVP_PKEY_keygen(ctx, &pkey), WOLFSSL_SUCCESS);
  65513. DH_free(dh);
  65514. dh = NULL;
  65515. EVP_PKEY_CTX_free(ctx);
  65516. EVP_PKEY_free(params);
  65517. /* try exporting generated key to DER, to verify */
  65518. ExpectNotNull(dh = EVP_PKEY_get1_DH(pkey));
  65519. DH_get0_key(dh, &pubkey, &privkey);
  65520. ExpectNotNull(pubkey);
  65521. ExpectNotNull(privkey);
  65522. ExpectNotNull(asn1int = BN_to_ASN1_INTEGER(pubkey, NULL));
  65523. ExpectIntGT((length = i2d_ASN1_INTEGER(asn1int, &derBuffer)), 0);
  65524. ASN1_INTEGER_free(asn1int);
  65525. DH_free(dh);
  65526. dh = NULL;
  65527. XFREE(derBuffer, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  65528. EVP_PKEY_free(pkey);
  65529. }
  65530. #endif
  65531. return EXPECT_RESULT();
  65532. }
  65533. static int test_wolfSSL_EVP_PKEY_keygen_init(void)
  65534. {
  65535. EXPECT_DECLS;
  65536. WOLFSSL_EVP_PKEY* pkey = NULL;
  65537. EVP_PKEY_CTX *ctx = NULL;
  65538. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65539. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  65540. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen_init(ctx), WOLFSSL_SUCCESS);
  65541. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen_init(NULL), WOLFSSL_SUCCESS);
  65542. EVP_PKEY_CTX_free(ctx);
  65543. EVP_PKEY_free(pkey);
  65544. return EXPECT_RESULT();
  65545. }
  65546. static int test_wolfSSL_EVP_PKEY_missing_parameters(void)
  65547. {
  65548. EXPECT_DECLS;
  65549. #if defined(OPENSSL_ALL) && !defined(NO_WOLFSSL_STUB)
  65550. WOLFSSL_EVP_PKEY* pkey = NULL;
  65551. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65552. ExpectIntEQ(wolfSSL_EVP_PKEY_missing_parameters(pkey), 0);
  65553. ExpectIntEQ(wolfSSL_EVP_PKEY_missing_parameters(NULL), 0);
  65554. EVP_PKEY_free(pkey);
  65555. #endif
  65556. return EXPECT_RESULT();
  65557. }
  65558. static int test_wolfSSL_EVP_PKEY_copy_parameters(void)
  65559. {
  65560. EXPECT_DECLS;
  65561. #if defined(OPENSSL_EXTRA) && !defined(NO_DH) && defined(WOLFSSL_KEY_GEN) && \
  65562. !defined(HAVE_SELFTEST) && (defined(OPENSSL_ALL) || defined(WOLFSSL_QT) || \
  65563. defined(WOLFSSL_OPENSSH)) && defined(WOLFSSL_DH_EXTRA) && \
  65564. !defined(NO_FILESYSTEM)
  65565. WOLFSSL_EVP_PKEY* params = NULL;
  65566. WOLFSSL_EVP_PKEY* copy = NULL;
  65567. DH* dh = NULL;
  65568. BIGNUM* p1;
  65569. BIGNUM* g1;
  65570. BIGNUM* q1;
  65571. BIGNUM* p2;
  65572. BIGNUM* g2;
  65573. BIGNUM* q2;
  65574. /* create DH with DH_get_2048_256 params */
  65575. ExpectNotNull(params = wolfSSL_EVP_PKEY_new());
  65576. ExpectNotNull(dh = DH_get_2048_256());
  65577. ExpectIntEQ(EVP_PKEY_set1_DH(params, dh), WOLFSSL_SUCCESS);
  65578. DH_get0_pqg(dh, (const BIGNUM**)&p1,
  65579. (const BIGNUM**)&q1,
  65580. (const BIGNUM**)&g1);
  65581. DH_free(dh);
  65582. dh = NULL;
  65583. /* create DH with random generated DH params */
  65584. ExpectNotNull(copy = wolfSSL_EVP_PKEY_new());
  65585. ExpectNotNull(dh = DH_generate_parameters(2048, 2, NULL, NULL));
  65586. ExpectIntEQ(EVP_PKEY_set1_DH(copy, dh), WOLFSSL_SUCCESS);
  65587. DH_free(dh);
  65588. dh = NULL;
  65589. ExpectIntEQ(EVP_PKEY_copy_parameters(copy, params), WOLFSSL_SUCCESS);
  65590. ExpectNotNull(dh = EVP_PKEY_get1_DH(copy));
  65591. ExpectNotNull(dh->p);
  65592. ExpectNotNull(dh->g);
  65593. ExpectNotNull(dh->q);
  65594. DH_get0_pqg(dh, (const BIGNUM**)&p2,
  65595. (const BIGNUM**)&q2,
  65596. (const BIGNUM**)&g2);
  65597. ExpectIntEQ(BN_cmp(p1, p2), 0);
  65598. ExpectIntEQ(BN_cmp(q1, q2), 0);
  65599. ExpectIntEQ(BN_cmp(g1, g2), 0);
  65600. DH_free(dh);
  65601. dh = NULL;
  65602. EVP_PKEY_free(copy);
  65603. EVP_PKEY_free(params);
  65604. #endif
  65605. return EXPECT_RESULT();
  65606. }
  65607. static int test_wolfSSL_EVP_PKEY_CTX_set_rsa_keygen_bits(void)
  65608. {
  65609. EXPECT_DECLS;
  65610. WOLFSSL_EVP_PKEY* pkey = NULL;
  65611. EVP_PKEY_CTX* ctx = NULL;
  65612. int bits = 2048;
  65613. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  65614. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  65615. ExpectIntEQ(wolfSSL_EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, bits),
  65616. WOLFSSL_SUCCESS);
  65617. EVP_PKEY_CTX_free(ctx);
  65618. EVP_PKEY_free(pkey);
  65619. return EXPECT_RESULT();
  65620. }
  65621. static int test_wolfSSL_EVP_CIPHER_CTX_iv_length(void)
  65622. {
  65623. EXPECT_DECLS;
  65624. /* This is large enough to be used for all key sizes */
  65625. byte key[AES_256_KEY_SIZE] = {0};
  65626. byte iv[AES_BLOCK_SIZE] = {0};
  65627. int i;
  65628. int nids[] = {
  65629. #ifdef HAVE_AES_CBC
  65630. NID_aes_128_cbc,
  65631. #endif
  65632. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  65633. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  65634. #ifdef HAVE_AESGCM
  65635. NID_aes_128_gcm,
  65636. #endif
  65637. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  65638. #ifdef WOLFSSL_AES_COUNTER
  65639. NID_aes_128_ctr,
  65640. #endif
  65641. #ifndef NO_DES3
  65642. NID_des_cbc,
  65643. NID_des_ede3_cbc,
  65644. #endif
  65645. };
  65646. int iv_lengths[] = {
  65647. #ifdef HAVE_AES_CBC
  65648. AES_BLOCK_SIZE,
  65649. #endif
  65650. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  65651. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  65652. #ifdef HAVE_AESGCM
  65653. GCM_NONCE_MID_SZ,
  65654. #endif
  65655. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  65656. #ifdef WOLFSSL_AES_COUNTER
  65657. AES_BLOCK_SIZE,
  65658. #endif
  65659. #ifndef NO_DES3
  65660. DES_BLOCK_SIZE,
  65661. DES_BLOCK_SIZE,
  65662. #endif
  65663. };
  65664. int nidsLen = (sizeof(nids)/sizeof(int));
  65665. for (i = 0; i < nidsLen; i++) {
  65666. const EVP_CIPHER* init = wolfSSL_EVP_get_cipherbynid(nids[i]);
  65667. EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
  65668. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  65669. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  65670. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_iv_length(ctx), iv_lengths[i]);
  65671. EVP_CIPHER_CTX_free(ctx);
  65672. }
  65673. return EXPECT_RESULT();
  65674. }
  65675. static int test_wolfSSL_EVP_CIPHER_CTX_key_length(void)
  65676. {
  65677. EXPECT_DECLS;
  65678. byte key[AES_256_KEY_SIZE] = {0};
  65679. byte iv[AES_BLOCK_SIZE] = {0};
  65680. int i;
  65681. int nids[] = {
  65682. #ifdef HAVE_AES_CBC
  65683. NID_aes_128_cbc,
  65684. NID_aes_256_cbc,
  65685. #endif
  65686. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  65687. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  65688. #ifdef HAVE_AESGCM
  65689. NID_aes_128_gcm,
  65690. NID_aes_256_gcm,
  65691. #endif
  65692. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  65693. #ifdef WOLFSSL_AES_COUNTER
  65694. NID_aes_128_ctr,
  65695. NID_aes_256_ctr,
  65696. #endif
  65697. #ifndef NO_DES3
  65698. NID_des_cbc,
  65699. NID_des_ede3_cbc,
  65700. #endif
  65701. };
  65702. int key_lengths[] = {
  65703. #ifdef HAVE_AES_CBC
  65704. AES_128_KEY_SIZE,
  65705. AES_256_KEY_SIZE,
  65706. #endif
  65707. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  65708. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  65709. #ifdef HAVE_AESGCM
  65710. AES_128_KEY_SIZE,
  65711. AES_256_KEY_SIZE,
  65712. #endif
  65713. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  65714. #ifdef WOLFSSL_AES_COUNTER
  65715. AES_128_KEY_SIZE,
  65716. AES_256_KEY_SIZE,
  65717. #endif
  65718. #ifndef NO_DES3
  65719. DES_KEY_SIZE,
  65720. DES3_KEY_SIZE,
  65721. #endif
  65722. };
  65723. int nidsLen = (sizeof(nids)/sizeof(int));
  65724. for (i = 0; i < nidsLen; i++) {
  65725. const EVP_CIPHER *init = wolfSSL_EVP_get_cipherbynid(nids[i]);
  65726. EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
  65727. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  65728. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  65729. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_key_length(ctx), key_lengths[i]);
  65730. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_key_length(ctx, key_lengths[i]),
  65731. WOLFSSL_SUCCESS);
  65732. EVP_CIPHER_CTX_free(ctx);
  65733. }
  65734. return EXPECT_RESULT();
  65735. }
  65736. static int test_wolfSSL_EVP_CIPHER_CTX_set_iv(void)
  65737. {
  65738. EXPECT_DECLS;
  65739. #if defined(HAVE_AESGCM) && !defined(NO_DES3)
  65740. int ivLen, keyLen;
  65741. EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
  65742. #ifdef HAVE_AESGCM
  65743. byte key[AES_128_KEY_SIZE] = {0};
  65744. byte iv[AES_BLOCK_SIZE] = {0};
  65745. const EVP_CIPHER *init = EVP_aes_128_gcm();
  65746. #else
  65747. byte key[DES3_KEY_SIZE] = {0};
  65748. byte iv[DES_BLOCK_SIZE] = {0};
  65749. const EVP_CIPHER *init = EVP_des_ede3_cbc();
  65750. #endif
  65751. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  65752. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  65753. ivLen = wolfSSL_EVP_CIPHER_CTX_iv_length(ctx);
  65754. keyLen = wolfSSL_EVP_CIPHER_CTX_key_length(ctx);
  65755. /* Bad cases */
  65756. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(NULL, iv, ivLen),
  65757. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65758. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(ctx, NULL, ivLen),
  65759. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65760. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(ctx, iv, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65761. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65762. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(ctx, iv, keyLen),
  65763. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65764. /* Good case */
  65765. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(ctx, iv, ivLen), 1);
  65766. EVP_CIPHER_CTX_free(ctx);
  65767. #endif
  65768. return EXPECT_RESULT();
  65769. }
  65770. static int test_wolfSSL_EVP_PKEY_CTX_new_id(void)
  65771. {
  65772. EXPECT_DECLS;
  65773. WOLFSSL_ENGINE* e = NULL;
  65774. int id = 0;
  65775. EVP_PKEY_CTX *ctx = NULL;
  65776. ExpectNotNull(ctx = wolfSSL_EVP_PKEY_CTX_new_id(id, e));
  65777. EVP_PKEY_CTX_free(ctx);
  65778. return EXPECT_RESULT();
  65779. }
  65780. static int test_wolfSSL_EVP_rc4(void)
  65781. {
  65782. EXPECT_DECLS;
  65783. #if !defined(NO_RC4)
  65784. ExpectNotNull(wolfSSL_EVP_rc4());
  65785. #endif
  65786. return EXPECT_RESULT();
  65787. }
  65788. static int test_wolfSSL_EVP_enc_null(void)
  65789. {
  65790. EXPECT_DECLS;
  65791. ExpectNotNull(wolfSSL_EVP_enc_null());
  65792. return EXPECT_RESULT();
  65793. }
  65794. static int test_wolfSSL_EVP_rc2_cbc(void)
  65795. {
  65796. EXPECT_DECLS;
  65797. #if defined(WOLFSSL_QT) && !defined(NO_WOLFSSL_STUB)
  65798. ExpectNull(wolfSSL_EVP_rc2_cbc());
  65799. #endif
  65800. return EXPECT_RESULT();
  65801. }
  65802. static int test_wolfSSL_EVP_mdc2(void)
  65803. {
  65804. EXPECT_DECLS;
  65805. #if !defined(NO_WOLFSSL_STUB)
  65806. ExpectNull(wolfSSL_EVP_mdc2());
  65807. #endif
  65808. return EXPECT_RESULT();
  65809. }
  65810. static int test_wolfSSL_EVP_md4(void)
  65811. {
  65812. EXPECT_DECLS;
  65813. #if !defined(NO_MD4)
  65814. ExpectNotNull(wolfSSL_EVP_md4());
  65815. #endif
  65816. return EXPECT_RESULT();
  65817. }
  65818. static int test_wolfSSL_EVP_aes_256_gcm(void)
  65819. {
  65820. EXPECT_DECLS;
  65821. #ifdef HAVE_AESGCM
  65822. ExpectNotNull(wolfSSL_EVP_aes_256_gcm());
  65823. #endif
  65824. return EXPECT_RESULT();
  65825. }
  65826. static int test_wolfSSL_EVP_aes_192_gcm(void)
  65827. {
  65828. EXPECT_DECLS;
  65829. #ifdef HAVE_AESGCM
  65830. ExpectNotNull(wolfSSL_EVP_aes_192_gcm());
  65831. #endif
  65832. return EXPECT_RESULT();
  65833. }
  65834. static int test_wolfSSL_EVP_aes_256_ccm(void)
  65835. {
  65836. EXPECT_DECLS;
  65837. #ifdef HAVE_AESCCM
  65838. ExpectNotNull(wolfSSL_EVP_aes_256_ccm());
  65839. #endif
  65840. return EXPECT_RESULT();
  65841. }
  65842. static int test_wolfSSL_EVP_aes_192_ccm(void)
  65843. {
  65844. EXPECT_DECLS;
  65845. #ifdef HAVE_AESCCM
  65846. ExpectNotNull(wolfSSL_EVP_aes_192_ccm());
  65847. #endif
  65848. return EXPECT_RESULT();
  65849. }
  65850. static int test_wolfSSL_EVP_aes_128_ccm(void)
  65851. {
  65852. EXPECT_DECLS;
  65853. #ifdef HAVE_AESCCM
  65854. ExpectNotNull(wolfSSL_EVP_aes_128_ccm());
  65855. #endif
  65856. return EXPECT_RESULT();
  65857. }
  65858. static int test_wolfSSL_EVP_ripemd160(void)
  65859. {
  65860. EXPECT_DECLS;
  65861. #if !defined(NO_WOLFSSL_STUB)
  65862. ExpectNull(wolfSSL_EVP_ripemd160());
  65863. #endif
  65864. return EXPECT_RESULT();
  65865. }
  65866. static int test_wolfSSL_EVP_get_digestbynid(void)
  65867. {
  65868. EXPECT_DECLS;
  65869. #ifndef NO_MD5
  65870. ExpectNotNull(wolfSSL_EVP_get_digestbynid(NID_md5));
  65871. #endif
  65872. #ifndef NO_SHA
  65873. ExpectNotNull(wolfSSL_EVP_get_digestbynid(NID_sha1));
  65874. #endif
  65875. #ifndef NO_SHA256
  65876. ExpectNotNull(wolfSSL_EVP_get_digestbynid(NID_sha256));
  65877. #endif
  65878. ExpectNull(wolfSSL_EVP_get_digestbynid(0));
  65879. return EXPECT_RESULT();
  65880. }
  65881. static int test_wolfSSL_EVP_MD_nid(void)
  65882. {
  65883. EXPECT_DECLS;
  65884. #ifndef NO_MD5
  65885. ExpectIntEQ(EVP_MD_nid(EVP_md5()), NID_md5);
  65886. #endif
  65887. #ifndef NO_SHA
  65888. ExpectIntEQ(EVP_MD_nid(EVP_sha1()), NID_sha1);
  65889. #endif
  65890. #ifndef NO_SHA256
  65891. ExpectIntEQ(EVP_MD_nid(EVP_sha256()), NID_sha256);
  65892. #endif
  65893. ExpectIntEQ(EVP_MD_nid(NULL), NID_undef);
  65894. return EXPECT_RESULT();
  65895. }
  65896. static int test_wolfSSL_EVP_PKEY_get0_EC_KEY(void)
  65897. {
  65898. EXPECT_DECLS;
  65899. #if defined(HAVE_ECC)
  65900. WOLFSSL_EVP_PKEY* pkey = NULL;
  65901. ExpectNull(EVP_PKEY_get0_EC_KEY(NULL));
  65902. ExpectNotNull(pkey = EVP_PKEY_new());
  65903. ExpectNull(EVP_PKEY_get0_EC_KEY(pkey));
  65904. EVP_PKEY_free(pkey);
  65905. #endif
  65906. return EXPECT_RESULT();
  65907. }
  65908. static int test_wolfSSL_EVP_X_STATE(void)
  65909. {
  65910. EXPECT_DECLS;
  65911. #if !defined(NO_DES3) && !defined(NO_RC4)
  65912. byte key[DES3_KEY_SIZE] = {0};
  65913. byte iv[DES_IV_SIZE] = {0};
  65914. EVP_CIPHER_CTX *ctx = NULL;
  65915. const EVP_CIPHER *init = NULL;
  65916. /* Bad test cases */
  65917. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  65918. ExpectNotNull(init = EVP_des_ede3_cbc());
  65919. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  65920. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  65921. ExpectNull(wolfSSL_EVP_X_STATE(NULL));
  65922. ExpectNull(wolfSSL_EVP_X_STATE(ctx));
  65923. EVP_CIPHER_CTX_free(ctx);
  65924. ctx = NULL;
  65925. /* Good test case */
  65926. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  65927. ExpectNotNull(init = wolfSSL_EVP_rc4());
  65928. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  65929. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  65930. ExpectNotNull(wolfSSL_EVP_X_STATE(ctx));
  65931. EVP_CIPHER_CTX_free(ctx);
  65932. #endif
  65933. return EXPECT_RESULT();
  65934. }
  65935. static int test_wolfSSL_EVP_X_STATE_LEN(void)
  65936. {
  65937. EXPECT_DECLS;
  65938. #if !defined(NO_DES3) && !defined(NO_RC4)
  65939. byte key[DES3_KEY_SIZE] = {0};
  65940. byte iv[DES_IV_SIZE] = {0};
  65941. EVP_CIPHER_CTX *ctx = NULL;
  65942. const EVP_CIPHER *init = NULL;
  65943. /* Bad test cases */
  65944. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  65945. ExpectNotNull(init = EVP_des_ede3_cbc());
  65946. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  65947. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  65948. ExpectIntEQ(wolfSSL_EVP_X_STATE_LEN(NULL), 0);
  65949. ExpectIntEQ(wolfSSL_EVP_X_STATE_LEN(ctx), 0);
  65950. EVP_CIPHER_CTX_free(ctx);
  65951. ctx = NULL;
  65952. /* Good test case */
  65953. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  65954. ExpectNotNull(init = wolfSSL_EVP_rc4());
  65955. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  65956. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  65957. ExpectIntEQ(wolfSSL_EVP_X_STATE_LEN(ctx), sizeof(Arc4));
  65958. EVP_CIPHER_CTX_free(ctx);
  65959. #endif
  65960. return EXPECT_RESULT();
  65961. }
  65962. static int test_wolfSSL_EVP_CIPHER_block_size(void)
  65963. {
  65964. EXPECT_DECLS;
  65965. #if defined(HAVE_AES_CBC) || defined(HAVE_AESGCM) || \
  65966. defined(WOLFSSL_AES_COUNTER) || defined(HAVE_AES_ECB) || \
  65967. defined(WOLFSSL_AES_OFB) || !defined(NO_RC4) || \
  65968. (defined(HAVE_CHACHA) && defined(HAVE_POLY1305))
  65969. #ifdef HAVE_AES_CBC
  65970. #ifdef WOLFSSL_AES_128
  65971. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_cbc()), AES_BLOCK_SIZE);
  65972. #endif
  65973. #ifdef WOLFSSL_AES_192
  65974. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_cbc()), AES_BLOCK_SIZE);
  65975. #endif
  65976. #ifdef WOLFSSL_AES_256
  65977. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_cbc()), AES_BLOCK_SIZE);
  65978. #endif
  65979. #endif
  65980. #ifdef HAVE_AESGCM
  65981. #ifdef WOLFSSL_AES_128
  65982. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_gcm()), 1);
  65983. #endif
  65984. #ifdef WOLFSSL_AES_192
  65985. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_gcm()), 1);
  65986. #endif
  65987. #ifdef WOLFSSL_AES_256
  65988. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_gcm()), 1);
  65989. #endif
  65990. #endif
  65991. #ifdef HAVE_AESCCM
  65992. #ifdef WOLFSSL_AES_128
  65993. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_ccm()), 1);
  65994. #endif
  65995. #ifdef WOLFSSL_AES_192
  65996. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_ccm()), 1);
  65997. #endif
  65998. #ifdef WOLFSSL_AES_256
  65999. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_ccm()), 1);
  66000. #endif
  66001. #endif
  66002. #ifdef WOLFSSL_AES_COUNTER
  66003. #ifdef WOLFSSL_AES_128
  66004. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_ctr()), 1);
  66005. #endif
  66006. #ifdef WOLFSSL_AES_192
  66007. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_ctr()), 1);
  66008. #endif
  66009. #ifdef WOLFSSL_AES_256
  66010. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_ctr()), 1);
  66011. #endif
  66012. #endif
  66013. #ifdef HAVE_AES_ECB
  66014. #ifdef WOLFSSL_AES_128
  66015. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_ecb()), AES_BLOCK_SIZE);
  66016. #endif
  66017. #ifdef WOLFSSL_AES_192
  66018. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_ecb()), AES_BLOCK_SIZE);
  66019. #endif
  66020. #ifdef WOLFSSL_AES_256
  66021. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_ecb()), AES_BLOCK_SIZE);
  66022. #endif
  66023. #endif
  66024. #ifdef WOLFSSL_AES_OFB
  66025. #ifdef WOLFSSL_AES_128
  66026. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_ofb()), 1);
  66027. #endif
  66028. #ifdef WOLFSSL_AES_192
  66029. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_ofb()), 1);
  66030. #endif
  66031. #ifdef WOLFSSL_AES_256
  66032. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_ofb()), 1);
  66033. #endif
  66034. #endif
  66035. #ifndef NO_RC4
  66036. ExpectIntEQ(EVP_CIPHER_block_size(wolfSSL_EVP_rc4()), 1);
  66037. #endif
  66038. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  66039. ExpectIntEQ(EVP_CIPHER_block_size(wolfSSL_EVP_chacha20_poly1305()), 1);
  66040. #endif
  66041. #endif
  66042. #ifdef WOLFSSL_SM4_ECB
  66043. ExpectIntEQ(EVP_CIPHER_block_size(EVP_sm4_ecb()), SM4_BLOCK_SIZE);
  66044. #endif
  66045. #ifdef WOLFSSL_SM4_CBC
  66046. ExpectIntEQ(EVP_CIPHER_block_size(EVP_sm4_cbc()), SM4_BLOCK_SIZE);
  66047. #endif
  66048. #ifdef WOLFSSL_SM4_CTR
  66049. ExpectIntEQ(EVP_CIPHER_block_size(EVP_sm4_ctr()), 1);
  66050. #endif
  66051. #ifdef WOLFSSL_SM4_GCM
  66052. ExpectIntEQ(EVP_CIPHER_block_size(EVP_sm4_gcm()), 1);
  66053. #endif
  66054. #ifdef WOLFSSL_SM4_CCM
  66055. ExpectIntEQ(EVP_CIPHER_block_size(EVP_sm4_ccm()), 1);
  66056. #endif
  66057. return EXPECT_RESULT();
  66058. }
  66059. static int test_wolfSSL_EVP_CIPHER_iv_length(void)
  66060. {
  66061. EXPECT_DECLS;
  66062. int nids[] = {
  66063. #if defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT)
  66064. #ifdef WOLFSSL_AES_128
  66065. NID_aes_128_cbc,
  66066. #endif
  66067. #ifdef WOLFSSL_AES_192
  66068. NID_aes_192_cbc,
  66069. #endif
  66070. #ifdef WOLFSSL_AES_256
  66071. NID_aes_256_cbc,
  66072. #endif
  66073. #endif /* HAVE_AES_CBC || WOLFSSL_AES_DIRECT */
  66074. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  66075. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  66076. #ifdef HAVE_AESGCM
  66077. #ifdef WOLFSSL_AES_128
  66078. NID_aes_128_gcm,
  66079. #endif
  66080. #ifdef WOLFSSL_AES_192
  66081. NID_aes_192_gcm,
  66082. #endif
  66083. #ifdef WOLFSSL_AES_256
  66084. NID_aes_256_gcm,
  66085. #endif
  66086. #endif /* HAVE_AESGCM */
  66087. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  66088. #ifdef WOLFSSL_AES_COUNTER
  66089. #ifdef WOLFSSL_AES_128
  66090. NID_aes_128_ctr,
  66091. #endif
  66092. #ifdef WOLFSSL_AES_192
  66093. NID_aes_192_ctr,
  66094. #endif
  66095. #ifdef WOLFSSL_AES_256
  66096. NID_aes_256_ctr,
  66097. #endif
  66098. #endif
  66099. #ifndef NO_DES3
  66100. NID_des_cbc,
  66101. NID_des_ede3_cbc,
  66102. #endif
  66103. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  66104. NID_chacha20_poly1305,
  66105. #endif
  66106. };
  66107. int iv_lengths[] = {
  66108. #if defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT)
  66109. #ifdef WOLFSSL_AES_128
  66110. AES_BLOCK_SIZE,
  66111. #endif
  66112. #ifdef WOLFSSL_AES_192
  66113. AES_BLOCK_SIZE,
  66114. #endif
  66115. #ifdef WOLFSSL_AES_256
  66116. AES_BLOCK_SIZE,
  66117. #endif
  66118. #endif /* HAVE_AES_CBC || WOLFSSL_AES_DIRECT */
  66119. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  66120. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  66121. #ifdef HAVE_AESGCM
  66122. #ifdef WOLFSSL_AES_128
  66123. GCM_NONCE_MID_SZ,
  66124. #endif
  66125. #ifdef WOLFSSL_AES_192
  66126. GCM_NONCE_MID_SZ,
  66127. #endif
  66128. #ifdef WOLFSSL_AES_256
  66129. GCM_NONCE_MID_SZ,
  66130. #endif
  66131. #endif /* HAVE_AESGCM */
  66132. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  66133. #ifdef WOLFSSL_AES_COUNTER
  66134. #ifdef WOLFSSL_AES_128
  66135. AES_BLOCK_SIZE,
  66136. #endif
  66137. #ifdef WOLFSSL_AES_192
  66138. AES_BLOCK_SIZE,
  66139. #endif
  66140. #ifdef WOLFSSL_AES_256
  66141. AES_BLOCK_SIZE,
  66142. #endif
  66143. #endif
  66144. #ifndef NO_DES3
  66145. DES_BLOCK_SIZE,
  66146. DES_BLOCK_SIZE,
  66147. #endif
  66148. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  66149. CHACHA20_POLY1305_AEAD_IV_SIZE,
  66150. #endif
  66151. };
  66152. int i;
  66153. int nidsLen = (sizeof(nids)/sizeof(int));
  66154. for (i = 0; i < nidsLen; i++) {
  66155. const EVP_CIPHER *c = EVP_get_cipherbynid(nids[i]);
  66156. ExpectIntEQ(EVP_CIPHER_iv_length(c), iv_lengths[i]);
  66157. }
  66158. return EXPECT_RESULT();
  66159. }
  66160. static int test_wolfSSL_EVP_SignInit_ex(void)
  66161. {
  66162. EXPECT_DECLS;
  66163. WOLFSSL_EVP_MD_CTX mdCtx;
  66164. WOLFSSL_ENGINE* e = 0;
  66165. const EVP_MD* md = EVP_sha256();
  66166. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  66167. ExpectIntEQ(wolfSSL_EVP_SignInit_ex(&mdCtx, md, e), WOLFSSL_SUCCESS);
  66168. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  66169. return EXPECT_RESULT();
  66170. }
  66171. static int test_wolfSSL_EVP_DigestFinal_ex(void)
  66172. {
  66173. EXPECT_DECLS;
  66174. #if !defined(NO_SHA256)
  66175. WOLFSSL_EVP_MD_CTX mdCtx;
  66176. unsigned int s = 0;
  66177. unsigned char md[WC_SHA256_DIGEST_SIZE];
  66178. unsigned char md2[WC_SHA256_DIGEST_SIZE];
  66179. /* Bad Case */
  66180. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  66181. (HAVE_FIPS_VERSION > 2))
  66182. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  66183. ExpectIntEQ(wolfSSL_EVP_DigestFinal_ex(&mdCtx, md, &s), 0);
  66184. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  66185. #else
  66186. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  66187. ExpectIntEQ(wolfSSL_EVP_DigestFinal_ex(&mdCtx, md, &s), WOLFSSL_SUCCESS);
  66188. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), WOLFSSL_SUCCESS);
  66189. #endif
  66190. /* Good Case */
  66191. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  66192. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, EVP_sha256()), WOLFSSL_SUCCESS);
  66193. ExpectIntEQ(wolfSSL_EVP_DigestFinal_ex(&mdCtx, md2, &s), WOLFSSL_SUCCESS);
  66194. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), WOLFSSL_SUCCESS);
  66195. #endif
  66196. return EXPECT_RESULT();
  66197. }
  66198. static int test_wolfSSL_QT_EVP_PKEY_CTX_free(void)
  66199. {
  66200. EXPECT_DECLS;
  66201. #if defined(OPENSSL_EXTRA)
  66202. EVP_PKEY* pkey = NULL;
  66203. EVP_PKEY_CTX* ctx = NULL;
  66204. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  66205. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  66206. #if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
  66207. /* void */
  66208. EVP_PKEY_CTX_free(ctx);
  66209. #else
  66210. /* int */
  66211. ExpectIntEQ(EVP_PKEY_CTX_free(ctx), WOLFSSL_SUCCESS);
  66212. #endif
  66213. EVP_PKEY_free(pkey);
  66214. #endif
  66215. return EXPECT_RESULT();
  66216. }
  66217. static int test_wolfSSL_EVP_PKEY_param_check(void)
  66218. {
  66219. EXPECT_DECLS;
  66220. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
  66221. #if !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA) && !defined(NO_FILESYSTEM)
  66222. DH *dh = NULL;
  66223. DH *setDh = NULL;
  66224. EVP_PKEY *pkey = NULL;
  66225. EVP_PKEY_CTX* ctx = NULL;
  66226. FILE* f = NULL;
  66227. unsigned char buf[512];
  66228. const unsigned char* pt = buf;
  66229. const char* dh2048 = "./certs/dh2048.der";
  66230. long len = 0;
  66231. int code = -1;
  66232. XMEMSET(buf, 0, sizeof(buf));
  66233. ExpectTrue((f = XFOPEN(dh2048, "rb")) != XBADFILE);
  66234. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  66235. if (f != XBADFILE)
  66236. XFCLOSE(f);
  66237. /* Load dh2048.der into DH with internal format */
  66238. ExpectNotNull(setDh = d2i_DHparams(NULL, &pt, len));
  66239. ExpectIntEQ(DH_check(setDh, &code), WOLFSSL_SUCCESS);
  66240. ExpectIntEQ(code, 0);
  66241. code = -1;
  66242. pkey = wolfSSL_EVP_PKEY_new();
  66243. /* Set DH into PKEY */
  66244. ExpectIntEQ(EVP_PKEY_set1_DH(pkey, setDh), WOLFSSL_SUCCESS);
  66245. /* create ctx from pkey */
  66246. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  66247. ExpectIntEQ(EVP_PKEY_param_check(ctx), 1/* valid */);
  66248. /* TODO: more invalid cases */
  66249. ExpectIntEQ(EVP_PKEY_param_check(NULL), 0);
  66250. EVP_PKEY_CTX_free(ctx);
  66251. EVP_PKEY_free(pkey);
  66252. DH_free(setDh);
  66253. setDh = NULL;
  66254. DH_free(dh);
  66255. dh = NULL;
  66256. #endif
  66257. #endif
  66258. return EXPECT_RESULT();
  66259. }
  66260. static int test_wolfSSL_EVP_BytesToKey(void)
  66261. {
  66262. EXPECT_DECLS;
  66263. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  66264. byte key[AES_BLOCK_SIZE] = {0};
  66265. byte iv[AES_BLOCK_SIZE] = {0};
  66266. int count = 0;
  66267. const EVP_MD* md = EVP_sha256();
  66268. const EVP_CIPHER *type;
  66269. const unsigned char *salt = (unsigned char *)"salt1234";
  66270. int sz = 5;
  66271. const byte data[] = {
  66272. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  66273. 0x72,0x6c,0x64
  66274. };
  66275. type = wolfSSL_EVP_get_cipherbynid(NID_aes_128_cbc);
  66276. /* Bad cases */
  66277. ExpectIntEQ(EVP_BytesToKey(NULL, md, salt, data, sz, count, key, iv),
  66278. 0);
  66279. ExpectIntEQ(EVP_BytesToKey(type, md, salt, NULL, sz, count, key, iv),
  66280. 16);
  66281. md = "2";
  66282. ExpectIntEQ(EVP_BytesToKey(type, md, salt, data, sz, count, key, iv),
  66283. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66284. /* Good case */
  66285. md = EVP_sha256();
  66286. ExpectIntEQ(EVP_BytesToKey(type, md, salt, data, sz, count, key, iv),
  66287. 16);
  66288. #endif
  66289. return EXPECT_RESULT();
  66290. }
  66291. static int test_evp_cipher_aes_gcm(void)
  66292. {
  66293. EXPECT_DECLS;
  66294. #if defined(HAVE_AESGCM) && ((!defined(HAVE_FIPS) && \
  66295. !defined(HAVE_SELFTEST)) || (defined(HAVE_FIPS_VERSION) && \
  66296. (HAVE_FIPS_VERSION >= 2)))
  66297. /*
  66298. * This test checks data at various points in the encrypt/decrypt process
  66299. * against known values produced using the same test with OpenSSL. This
  66300. * interop testing is critical for verifying the correctness of our
  66301. * EVP_Cipher implementation with AES-GCM. Specifically, this test exercises
  66302. * a flow supported by OpenSSL that uses the control command
  66303. * EVP_CTRL_GCM_IV_GEN to increment the IV between cipher operations without
  66304. * the need to call EVP_CipherInit. OpenSSH uses this flow, for example. We
  66305. * had a bug with OpenSSH where wolfSSL OpenSSH servers could only talk to
  66306. * wolfSSL OpenSSH clients because there was a bug in this flow that
  66307. * happened to "cancel out" if both sides of the connection had the bug.
  66308. */
  66309. enum {
  66310. NUM_ENCRYPTIONS = 3,
  66311. AAD_SIZE = 4
  66312. };
  66313. byte plainText1[] = {
  66314. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
  66315. 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  66316. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23
  66317. };
  66318. byte plainText2[] = {
  66319. 0x42, 0x49, 0x3b, 0x27, 0x03, 0x35, 0x59, 0x14, 0x41, 0x47, 0x37, 0x14,
  66320. 0x0e, 0x34, 0x0d, 0x28, 0x63, 0x09, 0x0a, 0x5b, 0x22, 0x57, 0x42, 0x22,
  66321. 0x0f, 0x5c, 0x1e, 0x53, 0x45, 0x15, 0x62, 0x08, 0x60, 0x43, 0x50, 0x2c
  66322. };
  66323. byte plainText3[] = {
  66324. 0x36, 0x0d, 0x2b, 0x09, 0x4a, 0x56, 0x3b, 0x4c, 0x21, 0x22, 0x58, 0x0e,
  66325. 0x5b, 0x57, 0x10
  66326. };
  66327. byte* plainTexts[NUM_ENCRYPTIONS] = {
  66328. plainText1,
  66329. plainText2,
  66330. plainText3
  66331. };
  66332. const int plainTextSzs[NUM_ENCRYPTIONS] = {
  66333. sizeof(plainText1),
  66334. sizeof(plainText2),
  66335. sizeof(plainText3)
  66336. };
  66337. byte aad1[AAD_SIZE] = {
  66338. 0x00, 0x00, 0x00, 0x01
  66339. };
  66340. byte aad2[AAD_SIZE] = {
  66341. 0x00, 0x00, 0x00, 0x10
  66342. };
  66343. byte aad3[AAD_SIZE] = {
  66344. 0x00, 0x00, 0x01, 0x00
  66345. };
  66346. byte* aads[NUM_ENCRYPTIONS] = {
  66347. aad1,
  66348. aad2,
  66349. aad3
  66350. };
  66351. const byte iv[GCM_NONCE_MID_SZ] = {
  66352. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF
  66353. };
  66354. byte currentIv[GCM_NONCE_MID_SZ];
  66355. const byte key[] = {
  66356. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
  66357. 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  66358. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f
  66359. };
  66360. const byte expIvs[NUM_ENCRYPTIONS][GCM_NONCE_MID_SZ] = {
  66361. {
  66362. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE,
  66363. 0xEF
  66364. },
  66365. {
  66366. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE,
  66367. 0xF0
  66368. },
  66369. {
  66370. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE,
  66371. 0xF1
  66372. }
  66373. };
  66374. const byte expTags[NUM_ENCRYPTIONS][AES_BLOCK_SIZE] = {
  66375. {
  66376. 0x65, 0x4F, 0xF7, 0xA0, 0xBB, 0x7B, 0x90, 0xB7, 0x9C, 0xC8, 0x14,
  66377. 0x3D, 0x32, 0x18, 0x34, 0xA9
  66378. },
  66379. {
  66380. 0x50, 0x3A, 0x13, 0x8D, 0x91, 0x1D, 0xEC, 0xBB, 0xBA, 0x5B, 0x57,
  66381. 0xA2, 0xFD, 0x2D, 0x6B, 0x7F
  66382. },
  66383. {
  66384. 0x3B, 0xED, 0x18, 0x9C, 0xB3, 0xE3, 0x61, 0x1E, 0x11, 0xEB, 0x13,
  66385. 0x5B, 0xEC, 0x52, 0x49, 0x32,
  66386. }
  66387. };
  66388. const byte expCipherText1[] = {
  66389. 0xCB, 0x93, 0x4F, 0xC8, 0x22, 0xE2, 0xC0, 0x35, 0xAA, 0x6B, 0x41, 0x15,
  66390. 0x17, 0x30, 0x2F, 0x97, 0x20, 0x74, 0x39, 0x28, 0xF8, 0xEB, 0xC5, 0x51,
  66391. 0x7B, 0xD9, 0x8A, 0x36, 0xB8, 0xDA, 0x24, 0x80, 0xE7, 0x9E, 0x09, 0xDE
  66392. };
  66393. const byte expCipherText2[] = {
  66394. 0xF9, 0x32, 0xE1, 0x87, 0x37, 0x0F, 0x04, 0xC1, 0xB5, 0x59, 0xF0, 0x45,
  66395. 0x3A, 0x0D, 0xA0, 0x26, 0xFF, 0xA6, 0x8D, 0x38, 0xFE, 0xB8, 0xE5, 0xC2,
  66396. 0x2A, 0x98, 0x4A, 0x54, 0x8F, 0x1F, 0xD6, 0x13, 0x03, 0xB2, 0x1B, 0xC0
  66397. };
  66398. const byte expCipherText3[] = {
  66399. 0xD0, 0x37, 0x59, 0x1C, 0x2F, 0x85, 0x39, 0x4D, 0xED, 0xC2, 0x32, 0x5B,
  66400. 0x80, 0x5E, 0x6B,
  66401. };
  66402. const byte* expCipherTexts[NUM_ENCRYPTIONS] = {
  66403. expCipherText1,
  66404. expCipherText2,
  66405. expCipherText3
  66406. };
  66407. byte* cipherText = NULL;
  66408. byte* calcPlainText = NULL;
  66409. byte tag[AES_BLOCK_SIZE];
  66410. EVP_CIPHER_CTX* encCtx = NULL;
  66411. EVP_CIPHER_CTX* decCtx = NULL;
  66412. int i, j, outl;
  66413. /****************************************************/
  66414. for (i = 0; i < 3; ++i) {
  66415. ExpectNotNull(encCtx = EVP_CIPHER_CTX_new());
  66416. ExpectNotNull(decCtx = EVP_CIPHER_CTX_new());
  66417. /* First iteration, set key before IV. */
  66418. if (i == 0) {
  66419. ExpectIntEQ(EVP_CipherInit(encCtx, EVP_aes_256_gcm(), key, NULL, 1),
  66420. SSL_SUCCESS);
  66421. /*
  66422. * The call to EVP_CipherInit below (with NULL key) should clear the
  66423. * authIvGenEnable flag set by EVP_CTRL_GCM_SET_IV_FIXED. As such, a
  66424. * subsequent EVP_CTRL_GCM_IV_GEN should fail. This matches OpenSSL
  66425. * behavior.
  66426. */
  66427. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_SET_IV_FIXED, -1,
  66428. (void*)iv), SSL_SUCCESS);
  66429. ExpectIntEQ(EVP_CipherInit(encCtx, NULL, NULL, iv, 1),
  66430. SSL_SUCCESS);
  66431. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_IV_GEN, -1,
  66432. currentIv), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66433. ExpectIntEQ(EVP_CipherInit(decCtx, EVP_aes_256_gcm(), key, NULL, 0),
  66434. SSL_SUCCESS);
  66435. ExpectIntEQ(EVP_CipherInit(decCtx, NULL, NULL, iv, 0),
  66436. SSL_SUCCESS);
  66437. }
  66438. /* Second iteration, IV before key. */
  66439. else {
  66440. ExpectIntEQ(EVP_CipherInit(encCtx, EVP_aes_256_gcm(), NULL, iv, 1),
  66441. SSL_SUCCESS);
  66442. ExpectIntEQ(EVP_CipherInit(encCtx, NULL, key, NULL, 1),
  66443. SSL_SUCCESS);
  66444. ExpectIntEQ(EVP_CipherInit(decCtx, EVP_aes_256_gcm(), NULL, iv, 0),
  66445. SSL_SUCCESS);
  66446. ExpectIntEQ(EVP_CipherInit(decCtx, NULL, key, NULL, 0),
  66447. SSL_SUCCESS);
  66448. }
  66449. /*
  66450. * EVP_CTRL_GCM_IV_GEN should fail if EVP_CTRL_GCM_SET_IV_FIXED hasn't
  66451. * been issued first.
  66452. */
  66453. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_IV_GEN, -1,
  66454. currentIv), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66455. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_SET_IV_FIXED, -1,
  66456. (void*)iv), SSL_SUCCESS);
  66457. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(decCtx, EVP_CTRL_GCM_SET_IV_FIXED, -1,
  66458. (void*)iv), SSL_SUCCESS);
  66459. for (j = 0; j < NUM_ENCRYPTIONS; ++j) {
  66460. /*************** Encrypt ***************/
  66461. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_IV_GEN, -1,
  66462. currentIv), SSL_SUCCESS);
  66463. /* Check current IV against expected. */
  66464. ExpectIntEQ(XMEMCMP(currentIv, expIvs[j], GCM_NONCE_MID_SZ), 0);
  66465. /* Add AAD. */
  66466. if (i == 2) {
  66467. /* Test streaming API. */
  66468. ExpectIntEQ(EVP_CipherUpdate(encCtx, NULL, &outl, aads[j],
  66469. AAD_SIZE), SSL_SUCCESS);
  66470. }
  66471. else {
  66472. ExpectIntEQ(EVP_Cipher(encCtx, NULL, aads[j], AAD_SIZE),
  66473. AAD_SIZE);
  66474. }
  66475. ExpectNotNull(cipherText = (byte*)XMALLOC(plainTextSzs[j], NULL,
  66476. DYNAMIC_TYPE_TMP_BUFFER));
  66477. /* Encrypt plaintext. */
  66478. if (i == 2) {
  66479. ExpectIntEQ(EVP_CipherUpdate(encCtx, cipherText, &outl,
  66480. plainTexts[j], plainTextSzs[j]),
  66481. SSL_SUCCESS);
  66482. }
  66483. else {
  66484. ExpectIntEQ(EVP_Cipher(encCtx, cipherText, plainTexts[j],
  66485. plainTextSzs[j]), plainTextSzs[j]);
  66486. }
  66487. if (i == 2) {
  66488. ExpectIntEQ(EVP_CipherFinal(encCtx, cipherText, &outl),
  66489. SSL_SUCCESS);
  66490. }
  66491. else {
  66492. /*
  66493. * Calling EVP_Cipher with NULL input and output for AES-GCM is
  66494. * akin to calling EVP_CipherFinal.
  66495. */
  66496. ExpectIntGE(EVP_Cipher(encCtx, NULL, NULL, 0), 0);
  66497. }
  66498. /* Check ciphertext against expected. */
  66499. ExpectIntEQ(XMEMCMP(cipherText, expCipherTexts[j], plainTextSzs[j]),
  66500. 0);
  66501. /* Get and check tag against expected. */
  66502. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_GET_TAG,
  66503. sizeof(tag), tag), SSL_SUCCESS);
  66504. ExpectIntEQ(XMEMCMP(tag, expTags[j], sizeof(tag)), 0);
  66505. /*************** Decrypt ***************/
  66506. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(decCtx, EVP_CTRL_GCM_IV_GEN, -1,
  66507. currentIv), SSL_SUCCESS);
  66508. /* Check current IV against expected. */
  66509. ExpectIntEQ(XMEMCMP(currentIv, expIvs[j], GCM_NONCE_MID_SZ), 0);
  66510. /* Add AAD. */
  66511. if (i == 2) {
  66512. /* Test streaming API. */
  66513. ExpectIntEQ(EVP_CipherUpdate(decCtx, NULL, &outl, aads[j],
  66514. AAD_SIZE), SSL_SUCCESS);
  66515. }
  66516. else {
  66517. ExpectIntEQ(EVP_Cipher(decCtx, NULL, aads[j], AAD_SIZE),
  66518. AAD_SIZE);
  66519. }
  66520. /* Set expected tag. */
  66521. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(decCtx, EVP_CTRL_GCM_SET_TAG,
  66522. sizeof(tag), tag), SSL_SUCCESS);
  66523. /* Decrypt ciphertext. */
  66524. ExpectNotNull(calcPlainText = (byte*)XMALLOC(plainTextSzs[j], NULL,
  66525. DYNAMIC_TYPE_TMP_BUFFER));
  66526. if (i == 2) {
  66527. ExpectIntEQ(EVP_CipherUpdate(decCtx, calcPlainText, &outl,
  66528. cipherText, plainTextSzs[j]),
  66529. SSL_SUCCESS);
  66530. }
  66531. else {
  66532. /* This first EVP_Cipher call will check the tag, too. */
  66533. ExpectIntEQ(EVP_Cipher(decCtx, calcPlainText, cipherText,
  66534. plainTextSzs[j]), plainTextSzs[j]);
  66535. }
  66536. if (i == 2) {
  66537. ExpectIntEQ(EVP_CipherFinal(decCtx, calcPlainText, &outl),
  66538. SSL_SUCCESS);
  66539. }
  66540. else {
  66541. ExpectIntGE(EVP_Cipher(decCtx, NULL, NULL, 0), 0);
  66542. }
  66543. /* Check plaintext against expected. */
  66544. ExpectIntEQ(XMEMCMP(calcPlainText, plainTexts[j], plainTextSzs[j]),
  66545. 0);
  66546. XFREE(cipherText, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  66547. cipherText = NULL;
  66548. XFREE(calcPlainText, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  66549. calcPlainText = NULL;
  66550. }
  66551. EVP_CIPHER_CTX_free(encCtx);
  66552. encCtx = NULL;
  66553. EVP_CIPHER_CTX_free(decCtx);
  66554. decCtx = NULL;
  66555. }
  66556. #endif
  66557. return EXPECT_RESULT();
  66558. }
  66559. static int test_wolfSSL_OBJ_ln(void)
  66560. {
  66561. EXPECT_DECLS;
  66562. const int nid_set[] = {
  66563. NID_commonName,
  66564. NID_serialNumber,
  66565. NID_countryName,
  66566. NID_localityName,
  66567. NID_stateOrProvinceName,
  66568. NID_organizationName,
  66569. NID_organizationalUnitName,
  66570. NID_domainComponent,
  66571. NID_businessCategory,
  66572. NID_jurisdictionCountryName,
  66573. NID_jurisdictionStateOrProvinceName,
  66574. NID_emailAddress
  66575. };
  66576. const char* ln_set[] = {
  66577. "commonName",
  66578. "serialNumber",
  66579. "countryName",
  66580. "localityName",
  66581. "stateOrProvinceName",
  66582. "organizationName",
  66583. "organizationalUnitName",
  66584. "domainComponent",
  66585. "businessCategory",
  66586. "jurisdictionCountryName",
  66587. "jurisdictionStateOrProvinceName",
  66588. "emailAddress",
  66589. };
  66590. size_t i = 0, maxIdx = sizeof(ln_set)/sizeof(char*);
  66591. ExpectIntEQ(OBJ_ln2nid(NULL), NID_undef);
  66592. #ifdef HAVE_ECC
  66593. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  66594. {
  66595. EC_builtin_curve r[27];
  66596. size_t nCurves = sizeof(r) / sizeof(r[0]);
  66597. nCurves = EC_get_builtin_curves(r, nCurves);
  66598. for (i = 0; i < nCurves; i++) {
  66599. /* skip ECC_CURVE_INVALID */
  66600. if (r[i].nid != ECC_CURVE_INVALID) {
  66601. ExpectIntEQ(OBJ_ln2nid(r[i].comment), r[i].nid);
  66602. ExpectStrEQ(OBJ_nid2ln(r[i].nid), r[i].comment);
  66603. }
  66604. }
  66605. }
  66606. #endif
  66607. #endif
  66608. for (i = 0; i < maxIdx; i++) {
  66609. ExpectIntEQ(OBJ_ln2nid(ln_set[i]), nid_set[i]);
  66610. ExpectStrEQ(OBJ_nid2ln(nid_set[i]), ln_set[i]);
  66611. }
  66612. return EXPECT_RESULT();
  66613. }
  66614. static int test_wolfSSL_OBJ_sn(void)
  66615. {
  66616. EXPECT_DECLS;
  66617. int i = 0, maxIdx = 7;
  66618. const int nid_set[] = {NID_commonName,NID_countryName,NID_localityName,
  66619. NID_stateOrProvinceName,NID_organizationName,
  66620. NID_organizationalUnitName,NID_emailAddress};
  66621. const char* sn_open_set[] = {"CN","C","L","ST","O","OU","emailAddress"};
  66622. const char* sn_wolf_set[] = {WOLFSSL_COMMON_NAME,WOLFSSL_COUNTRY_NAME,
  66623. WOLFSSL_LOCALITY_NAME, WOLFSSL_STATE_NAME,
  66624. WOLFSSL_ORG_NAME, WOLFSSL_ORGUNIT_NAME,
  66625. WOLFSSL_EMAIL_ADDR};
  66626. ExpectIntEQ(wolfSSL_OBJ_sn2nid(NULL), NID_undef);
  66627. for (i = 0; i < maxIdx; i++) {
  66628. ExpectIntEQ(wolfSSL_OBJ_sn2nid(sn_wolf_set[i]), nid_set[i]);
  66629. ExpectStrEQ(wolfSSL_OBJ_nid2sn(nid_set[i]), sn_open_set[i]);
  66630. }
  66631. return EXPECT_RESULT();
  66632. }
  66633. #if !defined(NO_BIO)
  66634. static unsigned long TXT_DB_hash(const WOLFSSL_STRING *s)
  66635. {
  66636. return lh_strhash(s[3]);
  66637. }
  66638. static int TXT_DB_cmp(const WOLFSSL_STRING *a, const WOLFSSL_STRING *b)
  66639. {
  66640. return XSTRCMP(a[3], b[3]);
  66641. }
  66642. #endif
  66643. static int test_wolfSSL_TXT_DB(void)
  66644. {
  66645. EXPECT_DECLS;
  66646. #if !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  66647. BIO *bio = NULL;
  66648. TXT_DB *db = NULL;
  66649. const int columns = 6;
  66650. const char *fields[6] = {
  66651. "V",
  66652. "320926161116Z",
  66653. "",
  66654. "12BD",
  66655. "unknown",
  66656. "/CN=rsa doe",
  66657. };
  66658. char** fields_copy = NULL;
  66659. /* Test read */
  66660. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  66661. ExpectIntGT(BIO_read_filename(bio, "./tests/TXT_DB.txt"), 0);
  66662. ExpectNotNull(db = TXT_DB_read(bio, columns));
  66663. ExpectNotNull(fields_copy = (char**)XMALLOC(sizeof(fields), NULL,
  66664. DYNAMIC_TYPE_OPENSSL));
  66665. if (fields_copy != NULL) {
  66666. XMEMCPY(fields_copy, fields, sizeof(fields));
  66667. }
  66668. ExpectIntEQ(TXT_DB_insert(db, fields_copy), 1);
  66669. if (EXPECT_FAIL()) {
  66670. XFREE(fields_copy, NULL, DYNAMIC_TYPE_OPENSSL);
  66671. }
  66672. BIO_free(bio);
  66673. bio = NULL;
  66674. /* Test write */
  66675. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  66676. ExpectIntEQ(TXT_DB_write(bio, db), 1484);
  66677. BIO_free(bio);
  66678. /* Test index */
  66679. ExpectIntEQ(TXT_DB_create_index(db, 3, NULL, (wolf_sk_hash_cb)TXT_DB_hash,
  66680. (wolf_lh_compare_cb)TXT_DB_cmp), 1);
  66681. ExpectNotNull(TXT_DB_get_by_index(db, 3, (WOLFSSL_STRING*)fields));
  66682. fields[3] = "12DA";
  66683. ExpectNotNull(TXT_DB_get_by_index(db, 3, (WOLFSSL_STRING*)fields));
  66684. fields[3] = "FFFF";
  66685. ExpectNull(TXT_DB_get_by_index(db, 3, (WOLFSSL_STRING*)fields));
  66686. fields[3] = "";
  66687. ExpectNull(TXT_DB_get_by_index(db, 3, (WOLFSSL_STRING*)fields));
  66688. TXT_DB_free(db);
  66689. #endif
  66690. return EXPECT_RESULT();
  66691. }
  66692. static int test_wolfSSL_NCONF(void)
  66693. {
  66694. EXPECT_DECLS;
  66695. #if !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  66696. const char* confFile = "./tests/NCONF_test.cnf";
  66697. CONF* conf = NULL;
  66698. long eline = 0;
  66699. long num = 0;
  66700. ExpectNotNull(conf = NCONF_new(NULL));
  66701. ExpectIntEQ(NCONF_load(conf, confFile, &eline), 1);
  66702. ExpectIntEQ(NCONF_get_number(conf, NULL, "port", &num), 1);
  66703. ExpectIntEQ(num, 1234);
  66704. ExpectIntEQ(NCONF_get_number(conf, "section2", "port", &num), 1);
  66705. ExpectIntEQ(num, 4321);
  66706. ExpectStrEQ(NCONF_get_string(conf, NULL, "dir"), "./test-dir");
  66707. ExpectStrEQ(NCONF_get_string(conf, "section1", "file1_copy"),
  66708. "./test-dir/file1");
  66709. ExpectStrEQ(NCONF_get_string(conf, "section2", "file_list"),
  66710. "./test-dir/file1:./test-dir/file2:./section1:file2");
  66711. NCONF_free(conf);
  66712. #endif
  66713. return EXPECT_RESULT();
  66714. }
  66715. #endif /* OPENSSL_ALL */
  66716. static int test_wolfSSL_X509V3_EXT_get(void) {
  66717. EXPECT_DECLS;
  66718. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  66719. XFILE f = XBADFILE;
  66720. int numOfExt =0;
  66721. int extNid = 0;
  66722. int i = 0;
  66723. WOLFSSL_X509* x509 = NULL;
  66724. WOLFSSL_X509_EXTENSION* ext = NULL;
  66725. const WOLFSSL_v3_ext_method* method = NULL;
  66726. ExpectTrue((f = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  66727. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  66728. if (f != XBADFILE)
  66729. XFCLOSE(f);
  66730. /* wolfSSL_X509V3_EXT_get() return struct and nid test */
  66731. ExpectIntEQ((numOfExt = wolfSSL_X509_get_ext_count(x509)), 5);
  66732. for (i = 0; i < numOfExt; i++) {
  66733. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  66734. ExpectIntNE((extNid = ext->obj->nid), NID_undef);
  66735. ExpectNotNull(method = wolfSSL_X509V3_EXT_get(ext));
  66736. ExpectIntEQ(method->ext_nid, extNid);
  66737. }
  66738. /* wolfSSL_X509V3_EXT_get() NULL argument test */
  66739. ExpectNull(method = wolfSSL_X509V3_EXT_get(NULL));
  66740. wolfSSL_X509_free(x509);
  66741. #endif
  66742. return EXPECT_RESULT();
  66743. }
  66744. static int test_wolfSSL_X509V3_EXT_nconf(void)
  66745. {
  66746. EXPECT_DECLS;
  66747. #ifdef OPENSSL_ALL
  66748. const char *ext_names[] = {
  66749. "subjectKeyIdentifier",
  66750. "authorityKeyIdentifier",
  66751. "subjectAltName",
  66752. "keyUsage",
  66753. "extendedKeyUsage",
  66754. };
  66755. size_t ext_names_count = sizeof(ext_names)/sizeof(*ext_names);
  66756. int ext_nids[] = {
  66757. NID_subject_key_identifier,
  66758. NID_authority_key_identifier,
  66759. NID_subject_alt_name,
  66760. NID_key_usage,
  66761. NID_ext_key_usage,
  66762. };
  66763. size_t ext_nids_count = sizeof(ext_nids)/sizeof(*ext_nids);
  66764. const char *ext_values[] = {
  66765. "hash",
  66766. "hash",
  66767. "DNS:example.com, IP:127.0.0.1",
  66768. "digitalSignature,nonRepudiation,keyEncipherment,dataEncipherment,"
  66769. "keyAgreement,keyCertSign,cRLSign,encipherOnly,decipherOnly",
  66770. "serverAuth,clientAuth,codeSigning,emailProtection,timeStamping,"
  66771. "OCSPSigning",
  66772. };
  66773. size_t i;
  66774. X509_EXTENSION* ext = NULL;
  66775. X509* x509 = NULL;
  66776. unsigned int keyUsageFlags;
  66777. unsigned int extKeyUsageFlags;
  66778. ExpectNotNull(x509 = X509_new());
  66779. /* keyUsage / extKeyUsage should match string above */
  66780. keyUsageFlags = KU_DIGITAL_SIGNATURE
  66781. | KU_NON_REPUDIATION
  66782. | KU_KEY_ENCIPHERMENT
  66783. | KU_DATA_ENCIPHERMENT
  66784. | KU_KEY_AGREEMENT
  66785. | KU_KEY_CERT_SIGN
  66786. | KU_CRL_SIGN
  66787. | KU_ENCIPHER_ONLY
  66788. | KU_DECIPHER_ONLY;
  66789. extKeyUsageFlags = XKU_SSL_CLIENT
  66790. | XKU_SSL_SERVER
  66791. | XKU_CODE_SIGN
  66792. | XKU_SMIME
  66793. | XKU_TIMESTAMP
  66794. | XKU_OCSP_SIGN;
  66795. for (i = 0; i < ext_names_count; i++) {
  66796. ExpectNotNull(ext = X509V3_EXT_nconf(NULL, NULL, ext_names[i],
  66797. ext_values[i]));
  66798. X509_EXTENSION_free(ext);
  66799. ext = NULL;
  66800. }
  66801. for (i = 0; i < ext_nids_count; i++) {
  66802. ExpectNotNull(ext = X509V3_EXT_nconf_nid(NULL, NULL, ext_nids[i],
  66803. ext_values[i]));
  66804. X509_EXTENSION_free(ext);
  66805. ext = NULL;
  66806. }
  66807. /* Test adding extension to X509 */
  66808. for (i = 0; i < ext_nids_count; i++) {
  66809. ExpectNotNull(ext = X509V3_EXT_nconf(NULL, NULL, ext_names[i],
  66810. ext_values[i]));
  66811. ExpectIntEQ(X509_add_ext(x509, ext, -1), WOLFSSL_SUCCESS);
  66812. if (ext_nids[i] == NID_key_usage) {
  66813. ExpectIntEQ(X509_get_key_usage(x509), keyUsageFlags);
  66814. }
  66815. else if (ext_nids[i] == NID_ext_key_usage) {
  66816. ExpectIntEQ(X509_get_extended_key_usage(x509), extKeyUsageFlags);
  66817. }
  66818. X509_EXTENSION_free(ext);
  66819. ext = NULL;
  66820. }
  66821. X509_free(x509);
  66822. #endif
  66823. return EXPECT_RESULT();
  66824. }
  66825. static int test_wolfSSL_X509V3_EXT(void) {
  66826. EXPECT_DECLS;
  66827. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  66828. XFILE f = XBADFILE;
  66829. int numOfExt = 0, nid = 0, i = 0, expected, actual = 0;
  66830. char* str = NULL;
  66831. unsigned char* data = NULL;
  66832. const WOLFSSL_v3_ext_method* method = NULL;
  66833. WOLFSSL_X509* x509 = NULL;
  66834. WOLFSSL_X509_EXTENSION* ext = NULL;
  66835. WOLFSSL_X509_EXTENSION* ext2 = NULL;
  66836. WOLFSSL_ASN1_OBJECT *obj = NULL;
  66837. WOLFSSL_ASN1_OBJECT *adObj = NULL;
  66838. WOLFSSL_ASN1_STRING* asn1str = NULL;
  66839. WOLFSSL_AUTHORITY_KEYID* aKeyId = NULL;
  66840. WOLFSSL_AUTHORITY_INFO_ACCESS* aia = NULL;
  66841. WOLFSSL_BASIC_CONSTRAINTS* bc = NULL;
  66842. WOLFSSL_ACCESS_DESCRIPTION* ad = NULL;
  66843. WOLFSSL_GENERAL_NAME* gn = NULL;
  66844. /* Check NULL argument */
  66845. ExpectNull(wolfSSL_X509V3_EXT_d2i(NULL));
  66846. /* Using OCSP cert with X509V3 extensions */
  66847. ExpectTrue((f = XFOPEN("./certs/ocsp/root-ca-cert.pem", "rb")) != XBADFILE);
  66848. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  66849. if (f != XBADFILE)
  66850. XFCLOSE(f);
  66851. ExpectIntEQ((numOfExt = wolfSSL_X509_get_ext_count(x509)), 5);
  66852. /* Basic Constraints */
  66853. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  66854. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(ext));
  66855. ExpectIntEQ((nid = wolfSSL_OBJ_obj2nid(obj)), NID_basic_constraints);
  66856. ExpectNotNull(bc = (WOLFSSL_BASIC_CONSTRAINTS*)wolfSSL_X509V3_EXT_d2i(ext));
  66857. ExpectIntEQ(bc->ca, 1);
  66858. ExpectNull(bc->pathlen);
  66859. wolfSSL_BASIC_CONSTRAINTS_free(bc);
  66860. bc = NULL;
  66861. i++;
  66862. /* Subject Key Identifier */
  66863. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  66864. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(ext));
  66865. ExpectIntEQ((nid = wolfSSL_OBJ_obj2nid(obj)), NID_subject_key_identifier);
  66866. ExpectNotNull(asn1str = (WOLFSSL_ASN1_STRING*)wolfSSL_X509V3_EXT_d2i(ext));
  66867. ExpectNotNull(ext2 = wolfSSL_X509V3_EXT_i2d(NID_subject_key_identifier, 0,
  66868. asn1str));
  66869. X509_EXTENSION_free(ext2);
  66870. ext2 = NULL;
  66871. ExpectNotNull(method = wolfSSL_X509V3_EXT_get(ext));
  66872. ExpectNotNull(method->i2s);
  66873. ExpectNotNull(str = method->i2s((WOLFSSL_v3_ext_method*)method, asn1str));
  66874. wolfSSL_ASN1_STRING_free(asn1str);
  66875. asn1str = NULL;
  66876. if (str != NULL) {
  66877. actual = strcmp(str,
  66878. "73:B0:1C:A4:2F:82:CB:CF:47:A5:38:D7:B0:04:82:3A:7E:72:15:21");
  66879. }
  66880. ExpectIntEQ(actual, 0);
  66881. XFREE(str, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  66882. str = NULL;
  66883. i++;
  66884. /* Authority Key Identifier */
  66885. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  66886. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(ext));
  66887. ExpectIntEQ((nid = wolfSSL_OBJ_obj2nid(obj)), NID_authority_key_identifier);
  66888. ExpectNotNull(aKeyId = (WOLFSSL_AUTHORITY_KEYID*)wolfSSL_X509V3_EXT_d2i(
  66889. ext));
  66890. ExpectNotNull(method = wolfSSL_X509V3_EXT_get(ext));
  66891. ExpectNotNull(asn1str = aKeyId->keyid);
  66892. ExpectNotNull(str = wolfSSL_i2s_ASN1_STRING((WOLFSSL_v3_ext_method*)method,
  66893. asn1str));
  66894. asn1str = NULL;
  66895. if (str != NULL) {
  66896. actual = strcmp(str,
  66897. "73:B0:1C:A4:2F:82:CB:CF:47:A5:38:D7:B0:04:82:3A:7E:72:15:21");
  66898. }
  66899. ExpectIntEQ(actual, 0);
  66900. XFREE(str, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  66901. str = NULL;
  66902. wolfSSL_AUTHORITY_KEYID_free(aKeyId);
  66903. aKeyId = NULL;
  66904. i++;
  66905. /* Key Usage */
  66906. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  66907. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(ext));
  66908. ExpectIntEQ((nid = wolfSSL_OBJ_obj2nid(obj)), NID_key_usage);
  66909. ExpectNotNull(asn1str = (WOLFSSL_ASN1_STRING*)wolfSSL_X509V3_EXT_d2i(ext));
  66910. #if defined(WOLFSSL_QT)
  66911. ExpectNotNull(data = (unsigned char*)ASN1_STRING_get0_data(asn1str));
  66912. #else
  66913. ExpectNotNull(data = wolfSSL_ASN1_STRING_data(asn1str));
  66914. #endif
  66915. expected = KEYUSE_KEY_CERT_SIGN | KEYUSE_CRL_SIGN;
  66916. if (data != NULL) {
  66917. #ifdef BIG_ENDIAN_ORDER
  66918. actual = data[1];
  66919. #else
  66920. actual = data[0];
  66921. #endif
  66922. }
  66923. ExpectIntEQ(actual, expected);
  66924. wolfSSL_ASN1_STRING_free(asn1str);
  66925. asn1str = NULL;
  66926. #if 1
  66927. i++;
  66928. /* Authority Info Access */
  66929. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  66930. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(ext));
  66931. ExpectIntEQ((nid = wolfSSL_OBJ_obj2nid(obj)), NID_info_access);
  66932. ExpectNotNull(aia = (WOLFSSL_AUTHORITY_INFO_ACCESS*)wolfSSL_X509V3_EXT_d2i(
  66933. ext));
  66934. #if defined(WOLFSSL_QT)
  66935. ExpectIntEQ(OPENSSL_sk_num(aia), 1); /* Only one URI entry for this cert */
  66936. #else
  66937. ExpectIntEQ(wolfSSL_sk_num(aia), 1); /* Only one URI entry for this cert */
  66938. #endif
  66939. /* URI entry is an ACCESS_DESCRIPTION type */
  66940. #if defined(WOLFSSL_QT)
  66941. ExpectNotNull(ad = (WOLFSSL_ACCESS_DESCRIPTION*)wolfSSL_sk_value(aia, 0));
  66942. #else
  66943. ExpectNotNull(ad = (WOLFSSL_ACCESS_DESCRIPTION*)OPENSSL_sk_value(aia, 0));
  66944. #endif
  66945. ExpectNotNull(adObj = ad->method);
  66946. /* Make sure nid is OCSP */
  66947. ExpectIntEQ(wolfSSL_OBJ_obj2nid(adObj), NID_ad_OCSP);
  66948. /* GENERAL_NAME stores URI as an ASN1_STRING */
  66949. ExpectNotNull(gn = ad->location);
  66950. ExpectIntEQ(gn->type, GEN_URI); /* Type should always be GEN_URI */
  66951. ExpectNotNull(asn1str = gn->d.uniformResourceIdentifier);
  66952. ExpectIntEQ(wolfSSL_ASN1_STRING_length(asn1str), 22);
  66953. #if defined(WOLFSSL_QT)
  66954. ExpectNotNull(str = (char*)ASN1_STRING_get0_data(asn1str));
  66955. #else
  66956. ExpectNotNull(str = (char*)wolfSSL_ASN1_STRING_data(asn1str));
  66957. #endif
  66958. if (str != NULL) {
  66959. actual = strcmp(str, "http://127.0.0.1:22220");
  66960. }
  66961. ExpectIntEQ(actual, 0);
  66962. wolfSSL_sk_ACCESS_DESCRIPTION_pop_free(aia, NULL);
  66963. aia = NULL;
  66964. #else
  66965. (void) aia; (void) ad; (void) adObj; (void) gn;
  66966. #endif
  66967. wolfSSL_X509_free(x509);
  66968. #endif
  66969. return EXPECT_RESULT();
  66970. }
  66971. static int test_wolfSSL_X509_get_extension_flags(void)
  66972. {
  66973. EXPECT_DECLS;
  66974. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  66975. XFILE f = XBADFILE;
  66976. X509* x509 = NULL;
  66977. unsigned int extFlags;
  66978. unsigned int keyUsageFlags;
  66979. unsigned int extKeyUsageFlags;
  66980. /* client-int-cert.pem has the following extension flags. */
  66981. extFlags = EXFLAG_KUSAGE | EXFLAG_XKUSAGE;
  66982. /* and the following key usage flags. */
  66983. keyUsageFlags = KU_DIGITAL_SIGNATURE
  66984. | KU_NON_REPUDIATION
  66985. | KU_KEY_ENCIPHERMENT;
  66986. /* and the following extended key usage flags. */
  66987. extKeyUsageFlags = XKU_SSL_CLIENT | XKU_SMIME;
  66988. ExpectTrue((f = XFOPEN("./certs/intermediate/client-int-cert.pem", "rb")) !=
  66989. XBADFILE);
  66990. ExpectNotNull(x509 = PEM_read_X509(f, NULL, NULL, NULL));
  66991. if (f != XBADFILE) {
  66992. XFCLOSE(f);
  66993. f = XBADFILE;
  66994. }
  66995. ExpectIntEQ(X509_get_extension_flags(x509), extFlags);
  66996. ExpectIntEQ(X509_get_key_usage(x509), keyUsageFlags);
  66997. ExpectIntEQ(X509_get_extended_key_usage(x509), extKeyUsageFlags);
  66998. X509_free(x509);
  66999. x509 = NULL;
  67000. /* client-cert-ext.pem has the following extension flags. */
  67001. extFlags = EXFLAG_KUSAGE;
  67002. /* and the following key usage flags. */
  67003. keyUsageFlags = KU_DIGITAL_SIGNATURE
  67004. | KU_KEY_CERT_SIGN
  67005. | KU_CRL_SIGN;
  67006. ExpectTrue((f = fopen("./certs/client-cert-ext.pem", "rb")) != XBADFILE);
  67007. ExpectNotNull(x509 = PEM_read_X509(f, NULL, NULL, NULL));
  67008. if (f != XBADFILE)
  67009. XFCLOSE(f);
  67010. ExpectIntEQ(X509_get_extension_flags(x509), extFlags);
  67011. ExpectIntEQ(X509_get_key_usage(x509), keyUsageFlags);
  67012. X509_free(x509);
  67013. #endif /* OPENSSL_ALL */
  67014. return EXPECT_RESULT();
  67015. }
  67016. static int test_wolfSSL_X509_get_ext(void)
  67017. {
  67018. EXPECT_DECLS;
  67019. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  67020. int ret = 0;
  67021. XFILE f = XBADFILE;
  67022. WOLFSSL_X509* x509 = NULL;
  67023. WOLFSSL_X509_EXTENSION* foundExtension;
  67024. ExpectTrue((f = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  67025. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  67026. if (f != XBADFILE)
  67027. XFCLOSE(f);
  67028. ExpectIntEQ((ret = wolfSSL_X509_get_ext_count(x509)), 5);
  67029. /* wolfSSL_X509_get_ext() valid input */
  67030. ExpectNotNull(foundExtension = wolfSSL_X509_get_ext(x509, 0));
  67031. /* wolfSSL_X509_get_ext() valid x509, idx out of bounds */
  67032. ExpectNull(foundExtension = wolfSSL_X509_get_ext(x509, -1));
  67033. ExpectNull(foundExtension = wolfSSL_X509_get_ext(x509, 100));
  67034. /* wolfSSL_X509_get_ext() NULL x509, idx out of bounds */
  67035. ExpectNull(foundExtension = wolfSSL_X509_get_ext(NULL, -1));
  67036. ExpectNull(foundExtension = wolfSSL_X509_get_ext(NULL, 100));
  67037. /* wolfSSL_X509_get_ext() NULL x509, valid idx */
  67038. ExpectNull(foundExtension = wolfSSL_X509_get_ext(NULL, 0));
  67039. wolfSSL_X509_free(x509);
  67040. #endif
  67041. return EXPECT_RESULT();
  67042. }
  67043. static int test_wolfSSL_X509_get_ext_by_NID(void)
  67044. {
  67045. EXPECT_DECLS;
  67046. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  67047. int rc = 0;
  67048. XFILE f = XBADFILE;
  67049. WOLFSSL_X509* x509 = NULL;
  67050. ASN1_OBJECT* obj = NULL;
  67051. ExpectTrue((f = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  67052. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  67053. if (f != XBADFILE)
  67054. XFCLOSE(f);
  67055. ExpectIntGE(rc = wolfSSL_X509_get_ext_by_NID(x509, NID_basic_constraints,
  67056. -1), 0);
  67057. /* Start search from last location (should fail) */
  67058. ExpectIntGE(rc = wolfSSL_X509_get_ext_by_NID(x509, NID_basic_constraints,
  67059. rc), -1);
  67060. ExpectIntGE(rc = wolfSSL_X509_get_ext_by_NID(x509, NID_basic_constraints,
  67061. -2), -1);
  67062. ExpectIntEQ(rc = wolfSSL_X509_get_ext_by_NID(NULL, NID_basic_constraints,
  67063. -1), -1);
  67064. ExpectIntEQ(rc = wolfSSL_X509_get_ext_by_NID(x509, NID_undef, -1), -1);
  67065. /* NID_ext_key_usage, check also its nid and oid */
  67066. ExpectIntGT(rc = wolfSSL_X509_get_ext_by_NID(x509, NID_ext_key_usage, -1),
  67067. -1);
  67068. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(wolfSSL_X509_get_ext(
  67069. x509, rc)));
  67070. ExpectIntEQ(obj->nid, NID_ext_key_usage);
  67071. ExpectIntEQ(obj->type, EXT_KEY_USAGE_OID);
  67072. wolfSSL_X509_free(x509);
  67073. #endif
  67074. return EXPECT_RESULT();
  67075. }
  67076. static int test_wolfSSL_X509_get_ext_subj_alt_name(void)
  67077. {
  67078. EXPECT_DECLS;
  67079. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  67080. int rc = 0;
  67081. XFILE f = XBADFILE;
  67082. WOLFSSL_X509* x509 = NULL;
  67083. WOLFSSL_X509_EXTENSION* ext = NULL;
  67084. WOLFSSL_ASN1_STRING* sanString = NULL;
  67085. byte* sanDer = NULL;
  67086. const byte expectedDer[] = {
  67087. 0x30, 0x13, 0x82, 0x0b, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e,
  67088. 0x63, 0x6f, 0x6d, 0x87, 0x04, 0x7f, 0x00, 0x00, 0x01};
  67089. ExpectTrue((f = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  67090. ExpectNotNull(x509 = PEM_read_X509(f, NULL, NULL, NULL));
  67091. if (f != XBADFILE)
  67092. XFCLOSE(f);
  67093. ExpectIntNE(rc = X509_get_ext_by_NID(x509, NID_subject_alt_name, -1), -1);
  67094. ExpectNotNull(ext = X509_get_ext(x509, rc));
  67095. ExpectNotNull(sanString = X509_EXTENSION_get_data(ext));
  67096. ExpectIntEQ(ASN1_STRING_length(sanString), sizeof(expectedDer));
  67097. ExpectNotNull(sanDer = ASN1_STRING_data(sanString));
  67098. ExpectIntEQ(XMEMCMP(sanDer, expectedDer, sizeof(expectedDer)), 0);
  67099. X509_free(x509);
  67100. #endif
  67101. return EXPECT_RESULT();
  67102. }
  67103. static int test_wolfSSL_X509_EXTENSION_new(void)
  67104. {
  67105. EXPECT_DECLS;
  67106. #if defined (OPENSSL_ALL)
  67107. WOLFSSL_X509_EXTENSION* ext = NULL;
  67108. ExpectNotNull(ext = wolfSSL_X509_EXTENSION_new());
  67109. ExpectNotNull(ext->obj = wolfSSL_ASN1_OBJECT_new());
  67110. wolfSSL_X509_EXTENSION_free(ext);
  67111. #endif
  67112. return EXPECT_RESULT();
  67113. }
  67114. static int test_wolfSSL_X509_EXTENSION_get_object(void)
  67115. {
  67116. EXPECT_DECLS;
  67117. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  67118. WOLFSSL_X509* x509 = NULL;
  67119. WOLFSSL_X509_EXTENSION* ext = NULL;
  67120. WOLFSSL_ASN1_OBJECT* o = NULL;
  67121. XFILE file = XBADFILE;
  67122. ExpectTrue((file = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  67123. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(file, NULL, NULL, NULL));
  67124. if (file != XBADFILE)
  67125. XFCLOSE(file);
  67126. /* wolfSSL_X509_EXTENSION_get_object() testing ext idx 0 */
  67127. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, 0));
  67128. ExpectNull(wolfSSL_X509_EXTENSION_get_object(NULL));
  67129. ExpectNotNull(o = wolfSSL_X509_EXTENSION_get_object(ext));
  67130. ExpectIntEQ(o->nid, 128);
  67131. /* wolfSSL_X509_EXTENSION_get_object() NULL argument */
  67132. ExpectNull(o = wolfSSL_X509_EXTENSION_get_object(NULL));
  67133. wolfSSL_X509_free(x509);
  67134. #endif
  67135. return EXPECT_RESULT();
  67136. }
  67137. static int test_wolfSSL_X509_EXTENSION_get_data(void)
  67138. {
  67139. EXPECT_DECLS;
  67140. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  67141. WOLFSSL_X509* x509 = NULL;
  67142. WOLFSSL_X509_EXTENSION* ext = NULL;
  67143. WOLFSSL_ASN1_STRING* str = NULL;
  67144. XFILE file = XBADFILE;
  67145. ExpectTrue((file = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  67146. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(file, NULL, NULL, NULL));
  67147. if (file != XBADFILE)
  67148. XFCLOSE(file);
  67149. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, 0));
  67150. ExpectNull(str = wolfSSL_X509_EXTENSION_get_data(NULL));
  67151. ExpectNotNull(str = wolfSSL_X509_EXTENSION_get_data(ext));
  67152. wolfSSL_X509_free(x509);
  67153. #endif
  67154. return EXPECT_RESULT();
  67155. }
  67156. static int test_wolfSSL_X509_EXTENSION_get_critical(void)
  67157. {
  67158. EXPECT_DECLS;
  67159. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  67160. WOLFSSL_X509* x509 = NULL;
  67161. WOLFSSL_X509_EXTENSION* ext = NULL;
  67162. XFILE file = XBADFILE;
  67163. int crit = 0;
  67164. ExpectTrue((file = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  67165. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(file, NULL, NULL, NULL));
  67166. if (file != XBADFILE)
  67167. XFCLOSE(file);
  67168. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, 0));
  67169. ExpectIntEQ(crit = wolfSSL_X509_EXTENSION_get_critical(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  67170. ExpectIntEQ(crit = wolfSSL_X509_EXTENSION_get_critical(ext), 0);
  67171. wolfSSL_X509_free(x509);
  67172. #endif
  67173. return EXPECT_RESULT();
  67174. }
  67175. static int test_wolfSSL_X509V3_EXT_print(void)
  67176. {
  67177. EXPECT_DECLS;
  67178. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_BIO) && \
  67179. !defined(NO_RSA)
  67180. {
  67181. XFILE f = XBADFILE;
  67182. WOLFSSL_X509* x509 = NULL;
  67183. X509_EXTENSION * ext = NULL;
  67184. int loc = 0;
  67185. BIO *bio = NULL;
  67186. ExpectTrue((f = XFOPEN(svrCertFile, "rb")) != XBADFILE);
  67187. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  67188. if (f != XBADFILE)
  67189. fclose(f);
  67190. ExpectNotNull(bio = wolfSSL_BIO_new(BIO_s_mem()));
  67191. ExpectIntGT(loc = wolfSSL_X509_get_ext_by_NID(x509,
  67192. NID_basic_constraints, -1), -1);
  67193. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, loc));
  67194. ExpectIntEQ(wolfSSL_X509V3_EXT_print(bio, ext, 0, 0), WOLFSSL_SUCCESS);
  67195. ExpectIntGT(loc = wolfSSL_X509_get_ext_by_NID(x509,
  67196. NID_subject_key_identifier, -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_authority_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. wolfSSL_BIO_free(bio);
  67204. wolfSSL_X509_free(x509);
  67205. }
  67206. {
  67207. X509 *x509 = NULL;
  67208. BIO *bio = NULL;
  67209. X509_EXTENSION *ext = NULL;
  67210. unsigned int i = 0;
  67211. unsigned int idx = 0;
  67212. /* Some NIDs to test with */
  67213. int nids[] = {
  67214. /* NID_key_usage, currently X509_get_ext returns this as a bit
  67215. * string, which messes up X509V3_EXT_print */
  67216. /* NID_ext_key_usage, */
  67217. NID_subject_alt_name,
  67218. };
  67219. int* n = NULL;
  67220. ExpectNotNull(bio = BIO_new_fp(stderr, BIO_NOCLOSE));
  67221. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFileExt,
  67222. WOLFSSL_FILETYPE_PEM));
  67223. ExpectIntGT(fprintf(stderr, "\nPrinting extension values:\n"), 0);
  67224. for (i = 0, n = nids; i<(sizeof(nids)/sizeof(int)); i++, n++) {
  67225. /* X509_get_ext_by_NID should return 3 for now. If that changes then
  67226. * update the index */
  67227. ExpectIntEQ((idx = X509_get_ext_by_NID(x509, *n, -1)), 3);
  67228. ExpectNotNull(ext = X509_get_ext(x509, (int)idx));
  67229. ExpectIntEQ(X509V3_EXT_print(bio, ext, 0, 0), 1);
  67230. ExpectIntGT(fprintf(stderr, "\n"), 0);
  67231. }
  67232. BIO_free(bio);
  67233. X509_free(x509);
  67234. }
  67235. #endif
  67236. return EXPECT_RESULT();
  67237. }
  67238. static int test_wolfSSL_X509_cmp(void)
  67239. {
  67240. EXPECT_DECLS;
  67241. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  67242. XFILE file1 = XBADFILE;
  67243. XFILE file2 = XBADFILE;
  67244. WOLFSSL_X509* cert1 = NULL;
  67245. WOLFSSL_X509* cert2 = NULL;
  67246. ExpectTrue((file1 = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  67247. ExpectTrue((file2 = XFOPEN("./certs/3072/client-cert.pem", "rb")) !=
  67248. XBADFILE);
  67249. ExpectNotNull(cert1 = wolfSSL_PEM_read_X509(file1, NULL, NULL, NULL));
  67250. ExpectNotNull(cert2 = wolfSSL_PEM_read_X509(file2, NULL, NULL, NULL));
  67251. if (file1 != XBADFILE)
  67252. fclose(file1);
  67253. if (file2 != XBADFILE)
  67254. fclose(file2);
  67255. /* wolfSSL_X509_cmp() testing matching certs */
  67256. ExpectIntEQ(0, wolfSSL_X509_cmp(cert1, cert1));
  67257. /* wolfSSL_X509_cmp() testing mismatched certs */
  67258. ExpectIntEQ(-1, wolfSSL_X509_cmp(cert1, cert2));
  67259. /* wolfSSL_X509_cmp() testing NULL, valid args */
  67260. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wolfSSL_X509_cmp(NULL, cert2));
  67261. /* wolfSSL_X509_cmp() testing valid, NULL args */
  67262. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wolfSSL_X509_cmp(cert1, NULL));
  67263. /* wolfSSL_X509_cmp() testing NULL, NULL args */
  67264. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wolfSSL_X509_cmp(NULL, NULL));
  67265. wolfSSL_X509_free(cert1);
  67266. wolfSSL_X509_free(cert2);
  67267. #endif
  67268. return EXPECT_RESULT();
  67269. }
  67270. static int test_wolfSSL_EVP_PKEY_up_ref(void)
  67271. {
  67272. EXPECT_DECLS;
  67273. #if defined(OPENSSL_ALL)
  67274. EVP_PKEY* pkey;
  67275. pkey = EVP_PKEY_new();
  67276. ExpectNotNull(pkey);
  67277. ExpectIntEQ(EVP_PKEY_up_ref(NULL), 0);
  67278. ExpectIntEQ(EVP_PKEY_up_ref(pkey), 1);
  67279. EVP_PKEY_free(pkey);
  67280. ExpectIntEQ(EVP_PKEY_up_ref(pkey), 1);
  67281. EVP_PKEY_free(pkey);
  67282. EVP_PKEY_free(pkey);
  67283. #endif
  67284. return EXPECT_RESULT();
  67285. }
  67286. static int test_wolfSSL_d2i_and_i2d_PublicKey(void)
  67287. {
  67288. EXPECT_DECLS;
  67289. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  67290. EVP_PKEY* pkey = NULL;
  67291. const unsigned char* p;
  67292. unsigned char *der = NULL;
  67293. unsigned char *tmp = NULL;
  67294. int derLen;
  67295. p = client_keypub_der_2048;
  67296. /* Check that key can be successfully decoded. */
  67297. ExpectNotNull(pkey = wolfSSL_d2i_PublicKey(EVP_PKEY_RSA, NULL, &p,
  67298. sizeof_client_keypub_der_2048));
  67299. /* Check that key can be successfully encoded. */
  67300. ExpectIntGE((derLen = wolfSSL_i2d_PublicKey(pkey, &der)), 0);
  67301. /* Ensure that the encoded version matches the original. */
  67302. ExpectIntEQ(derLen, sizeof_client_keypub_der_2048);
  67303. ExpectIntEQ(XMEMCMP(der, client_keypub_der_2048, derLen), 0);
  67304. /* Do same test except with pre-allocated buffer to ensure the der pointer
  67305. * is advanced. */
  67306. tmp = der;
  67307. ExpectIntGE((derLen = wolfSSL_i2d_PublicKey(pkey, &tmp)), 0);
  67308. ExpectIntEQ(derLen, sizeof_client_keypub_der_2048);
  67309. ExpectIntEQ(XMEMCMP(der, client_keypub_der_2048, derLen), 0);
  67310. ExpectTrue(der + derLen == tmp);
  67311. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  67312. EVP_PKEY_free(pkey);
  67313. #endif
  67314. return EXPECT_RESULT();
  67315. }
  67316. static int test_wolfSSL_d2i_and_i2d_PublicKey_ecc(void)
  67317. {
  67318. EXPECT_DECLS;
  67319. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && !defined(NO_CERTS) && \
  67320. !defined(NO_ASN) && !defined(NO_PWDBASED)
  67321. EVP_PKEY* pkey = NULL;
  67322. const unsigned char* p;
  67323. unsigned char *der = NULL;
  67324. unsigned char *tmp = NULL;
  67325. int derLen;
  67326. unsigned char pub_buf[65];
  67327. const int pub_len = 65;
  67328. BN_CTX* ctx;
  67329. EC_GROUP* curve = NULL;
  67330. EC_KEY* ephemeral_key = NULL;
  67331. const EC_POINT* h;
  67332. /* Generate an x963 key pair and get public part into pub_buf */
  67333. ExpectNotNull(ctx = BN_CTX_new());
  67334. ExpectNotNull(curve = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
  67335. ExpectNotNull(ephemeral_key = EC_KEY_new_by_curve_name(
  67336. NID_X9_62_prime256v1));
  67337. ExpectIntEQ(EC_KEY_generate_key(ephemeral_key), 1);
  67338. ExpectNotNull(h = EC_KEY_get0_public_key(ephemeral_key));
  67339. ExpectIntEQ(pub_len, EC_POINT_point2oct(curve, h,
  67340. POINT_CONVERSION_UNCOMPRESSED, pub_buf, pub_len, ctx));
  67341. /* Prepare the EVP_PKEY */
  67342. ExpectNotNull(pkey = EVP_PKEY_new());
  67343. p = pub_buf;
  67344. /* Check that key can be successfully decoded. */
  67345. ExpectNotNull(wolfSSL_d2i_PublicKey(EVP_PKEY_EC, &pkey, &p,
  67346. pub_len));
  67347. /* Check that key can be successfully encoded. */
  67348. ExpectIntGE((derLen = wolfSSL_i2d_PublicKey(pkey, &der)), 0);
  67349. /* Ensure that the encoded version matches the original. */
  67350. ExpectIntEQ(derLen, pub_len);
  67351. ExpectIntEQ(XMEMCMP(der, pub_buf, derLen), 0);
  67352. /* Do same test except with pre-allocated buffer to ensure the der pointer
  67353. * is advanced. */
  67354. tmp = der;
  67355. ExpectIntGE((derLen = wolfSSL_i2d_PublicKey(pkey, &tmp)), 0);
  67356. ExpectIntEQ(derLen, pub_len);
  67357. ExpectIntEQ(XMEMCMP(der, pub_buf, derLen), 0);
  67358. ExpectTrue(der + derLen == tmp);
  67359. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  67360. EVP_PKEY_free(pkey);
  67361. EC_KEY_free(ephemeral_key);
  67362. EC_GROUP_free(curve);
  67363. #endif
  67364. return EXPECT_RESULT();
  67365. }
  67366. static int test_wolfSSL_d2i_and_i2d_DSAparams(void)
  67367. {
  67368. EXPECT_DECLS;
  67369. #if defined(OPENSSL_EXTRA) && !defined(NO_DSA)
  67370. DSA* dsa = NULL;
  67371. byte derIn[] = {
  67372. 0x30, 0x82, 0x01, 0x1f, 0x02, 0x81, 0x81, 0x00,
  67373. 0xcd, 0xde, 0x25, 0x68, 0x80, 0x53, 0x0d, 0xe5,
  67374. 0x77, 0xd6, 0xd2, 0x90, 0x39, 0x3f, 0x90, 0xa2,
  67375. 0x3f, 0x33, 0x94, 0x6e, 0xe8, 0x4f, 0x2b, 0x63,
  67376. 0xab, 0x30, 0xab, 0x15, 0xba, 0x11, 0xea, 0x8a,
  67377. 0x5d, 0x8d, 0xcc, 0xb8, 0xd4, 0xa1, 0xd5, 0xc1,
  67378. 0x47, 0x9d, 0x5a, 0x73, 0x6a, 0x62, 0x49, 0xd1,
  67379. 0x06, 0x07, 0x67, 0xf6, 0x2f, 0xa3, 0x39, 0xbd,
  67380. 0x4e, 0x0d, 0xb4, 0xd3, 0x22, 0x23, 0x84, 0xec,
  67381. 0x93, 0x26, 0x5a, 0x49, 0xee, 0x7c, 0x89, 0x48,
  67382. 0x66, 0x4d, 0xe8, 0xe8, 0xd8, 0x50, 0xfb, 0xa5,
  67383. 0x71, 0x9f, 0x22, 0x18, 0xe5, 0xe6, 0x0b, 0x46,
  67384. 0x87, 0x66, 0xee, 0x52, 0x8f, 0x46, 0x4f, 0xb5,
  67385. 0x03, 0xce, 0xed, 0xe3, 0xbe, 0xe5, 0xb5, 0x81,
  67386. 0xd2, 0x59, 0xe9, 0xc0, 0xad, 0x4d, 0xd0, 0x4d,
  67387. 0x26, 0xf7, 0xba, 0x50, 0xe8, 0xc9, 0x8f, 0xfe,
  67388. 0x24, 0x19, 0x3d, 0x2e, 0xa7, 0x52, 0x3c, 0x6d,
  67389. 0x02, 0x15, 0x00, 0xfb, 0x47, 0xfb, 0xec, 0x81,
  67390. 0x20, 0xc8, 0x1c, 0xe9, 0x4a, 0xba, 0x04, 0x6f,
  67391. 0x19, 0x9b, 0x94, 0xee, 0x82, 0x67, 0xd3, 0x02,
  67392. 0x81, 0x81, 0x00, 0x9b, 0x95, 0xbb, 0x85, 0xc5,
  67393. 0x58, 0x4a, 0x32, 0x9c, 0xaa, 0x44, 0x85, 0xd6,
  67394. 0x68, 0xdc, 0x3e, 0x14, 0xf4, 0xce, 0x6d, 0xa3,
  67395. 0x49, 0x38, 0xea, 0xd6, 0x61, 0x48, 0x92, 0x5a,
  67396. 0x40, 0x95, 0x49, 0x38, 0xaa, 0xe1, 0x39, 0x29,
  67397. 0x68, 0x58, 0x47, 0x8a, 0x4b, 0x01, 0xe1, 0x2e,
  67398. 0x8e, 0x6c, 0x63, 0x6f, 0x40, 0xca, 0x50, 0x3f,
  67399. 0x8c, 0x0b, 0x99, 0xe4, 0x72, 0x42, 0xb8, 0xb1,
  67400. 0xc2, 0x26, 0x48, 0xf1, 0x9c, 0x83, 0xc6, 0x37,
  67401. 0x2e, 0x5a, 0xae, 0x11, 0x09, 0xd9, 0xf3, 0xad,
  67402. 0x1f, 0x6f, 0xad, 0xad, 0x50, 0xe3, 0x78, 0x32,
  67403. 0xe6, 0xde, 0x8e, 0xaa, 0xbf, 0xd1, 0x00, 0x9f,
  67404. 0xb3, 0x02, 0x12, 0x19, 0xa2, 0x15, 0xec, 0x14,
  67405. 0x18, 0x5c, 0x0e, 0x26, 0xce, 0xf9, 0xae, 0xcc,
  67406. 0x7b, 0xb5, 0xd1, 0x26, 0xfc, 0x85, 0xfe, 0x14,
  67407. 0x93, 0xb6, 0x9d, 0x7d, 0x76, 0xe3, 0x35, 0x97,
  67408. 0x1e, 0xde, 0xc4
  67409. };
  67410. int derInLen = sizeof(derIn);
  67411. byte* derOut = NULL;
  67412. int derOutLen;
  67413. byte* p = derIn;
  67414. /* Check that params can be successfully decoded. */
  67415. ExpectNotNull(dsa = d2i_DSAparams(NULL, (const byte**)&p, derInLen));
  67416. /* Check that params can be successfully encoded. */
  67417. ExpectIntGE((derOutLen = i2d_DSAparams(dsa, &derOut)), 0);
  67418. /* Ensure that the encoded version matches the original. */
  67419. ExpectIntEQ(derInLen, derOutLen);
  67420. ExpectIntEQ(XMEMCMP(derIn, derOut, derInLen), 0);
  67421. XFREE(derOut, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  67422. DSA_free(dsa);
  67423. #endif
  67424. return EXPECT_RESULT();
  67425. }
  67426. static int test_wolfSSL_i2d_PrivateKey(void)
  67427. {
  67428. EXPECT_DECLS;
  67429. #if (!defined(NO_RSA) || defined(HAVE_ECC)) && defined(OPENSSL_EXTRA) && \
  67430. !defined(NO_ASN) && !defined(NO_PWDBASED)
  67431. #if !defined(NO_RSA) && defined(USE_CERT_BUFFERS_2048)
  67432. {
  67433. EVP_PKEY* pkey = NULL;
  67434. const unsigned char* server_key =
  67435. (const unsigned char*)server_key_der_2048;
  67436. unsigned char buf[FOURK_BUF];
  67437. unsigned char* pt = NULL;
  67438. int bufSz = 0;
  67439. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_RSA, NULL, &server_key,
  67440. (long)sizeof_server_key_der_2048));
  67441. ExpectIntEQ(i2d_PrivateKey(pkey, NULL), 1193);
  67442. pt = buf;
  67443. ExpectIntEQ((bufSz = i2d_PrivateKey(pkey, &pt)), 1193);
  67444. ExpectIntNE((pt - buf), 0);
  67445. ExpectIntEQ(XMEMCMP(buf, server_key_der_2048, bufSz), 0);
  67446. EVP_PKEY_free(pkey);
  67447. }
  67448. #endif
  67449. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  67450. {
  67451. EVP_PKEY* pkey = NULL;
  67452. const unsigned char* client_key =
  67453. (const unsigned char*)ecc_clikey_der_256;
  67454. unsigned char buf[FOURK_BUF];
  67455. unsigned char* pt = NULL;
  67456. int bufSz = 0;
  67457. ExpectNotNull((pkey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &client_key,
  67458. (long)sizeof_ecc_clikey_der_256)));
  67459. ExpectIntEQ(i2d_PrivateKey(pkey, NULL), 121);
  67460. pt = buf;
  67461. ExpectIntEQ((bufSz = i2d_PrivateKey(pkey, &pt)), 121);
  67462. ExpectIntNE((pt - buf), 0);
  67463. ExpectIntEQ(XMEMCMP(buf, ecc_clikey_der_256, bufSz), 0);
  67464. EVP_PKEY_free(pkey);
  67465. }
  67466. #endif
  67467. #endif
  67468. return EXPECT_RESULT();
  67469. }
  67470. static int test_wolfSSL_OCSP_id_get0_info(void)
  67471. {
  67472. EXPECT_DECLS;
  67473. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_HAPROXY)) && \
  67474. defined(HAVE_OCSP) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  67475. X509* cert = NULL;
  67476. X509* issuer = NULL;
  67477. OCSP_CERTID* id = NULL;
  67478. OCSP_CERTID* id2 = NULL;
  67479. ASN1_STRING* name = NULL;
  67480. ASN1_OBJECT* pmd = NULL;
  67481. ASN1_STRING* keyHash = NULL;
  67482. ASN1_INTEGER* serial = NULL;
  67483. ASN1_INTEGER* x509Int = NULL;
  67484. ExpectNotNull(cert = wolfSSL_X509_load_certificate_file(svrCertFile,
  67485. SSL_FILETYPE_PEM));
  67486. ExpectNotNull(issuer = wolfSSL_X509_load_certificate_file(caCertFile,
  67487. SSL_FILETYPE_PEM));
  67488. ExpectNotNull(id = OCSP_cert_to_id(NULL, cert, issuer));
  67489. ExpectNotNull(id2 = OCSP_cert_to_id(NULL, cert, issuer));
  67490. ExpectIntEQ(OCSP_id_get0_info(NULL, NULL, NULL, NULL, NULL), 0);
  67491. ExpectIntEQ(OCSP_id_get0_info(NULL, NULL, NULL, NULL, id), 1);
  67492. /* name, pmd, keyHash not supported yet, expect failure if not NULL */
  67493. ExpectIntEQ(OCSP_id_get0_info(&name, NULL, NULL, NULL, id), 0);
  67494. ExpectIntEQ(OCSP_id_get0_info(NULL, &pmd, NULL, NULL, id), 0);
  67495. ExpectIntEQ(OCSP_id_get0_info(NULL, NULL, &keyHash, NULL, id), 0);
  67496. ExpectIntEQ(OCSP_id_get0_info(NULL, NULL, NULL, &serial, id), 1);
  67497. ExpectNotNull(serial);
  67498. /* compare serial number to one in cert, should be equal */
  67499. ExpectNotNull(x509Int = X509_get_serialNumber(cert));
  67500. ExpectIntEQ(x509Int->length, serial->length);
  67501. ExpectIntEQ(XMEMCMP(x509Int->data, serial->data, serial->length), 0);
  67502. /* test OCSP_id_cmp */
  67503. ExpectIntNE(OCSP_id_cmp(NULL, NULL), 0);
  67504. ExpectIntNE(OCSP_id_cmp(id, NULL), 0);
  67505. ExpectIntNE(OCSP_id_cmp(NULL, id2), 0);
  67506. ExpectIntEQ(OCSP_id_cmp(id, id2), 0);
  67507. if (id != NULL) {
  67508. id->issuerHash[0] = ~id->issuerHash[0];
  67509. }
  67510. ExpectIntNE(OCSP_id_cmp(id, id2), 0);
  67511. OCSP_CERTID_free(id);
  67512. OCSP_CERTID_free(id2);
  67513. X509_free(cert); /* free's x509Int */
  67514. X509_free(issuer);
  67515. #endif
  67516. return EXPECT_RESULT();
  67517. }
  67518. static int test_wolfSSL_i2d_OCSP_CERTID(void)
  67519. {
  67520. EXPECT_DECLS;
  67521. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_HAPROXY)) && defined(HAVE_OCSP)
  67522. WOLFSSL_OCSP_CERTID certId;
  67523. byte* targetBuffer = NULL;
  67524. byte* p;
  67525. /* OCSP CertID bytes taken from PCAP */
  67526. byte rawCertId[] = {
  67527. 0x30, 0x49, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05,
  67528. 0x00, 0x04, 0x14, 0x80, 0x51, 0x06, 0x01, 0x32, 0xad, 0x9a, 0xc2, 0x7d,
  67529. 0x51, 0x87, 0xa0, 0xe8, 0x87, 0xfb, 0x01, 0x62, 0x01, 0x55, 0xee, 0x04,
  67530. 0x14, 0x03, 0xde, 0x50, 0x35, 0x56, 0xd1, 0x4c, 0xbb, 0x66, 0xf0, 0xa3,
  67531. 0xe2, 0x1b, 0x1b, 0xc3, 0x97, 0xb2, 0x3d, 0xd1, 0x55, 0x02, 0x10, 0x01,
  67532. 0xfd, 0xa3, 0xeb, 0x6e, 0xca, 0x75, 0xc8, 0x88, 0x43, 0x8b, 0x72, 0x4b,
  67533. 0xcf, 0xbc, 0x91
  67534. };
  67535. int ret = 0;
  67536. int i;
  67537. XMEMSET(&certId, 0, sizeof(WOLFSSL_OCSP_CERTID));
  67538. certId.rawCertId = rawCertId;
  67539. certId.rawCertIdSize = sizeof(rawCertId);
  67540. ExpectNotNull(targetBuffer = (byte*)XMALLOC(sizeof(rawCertId), NULL,
  67541. DYNAMIC_TYPE_TMP_BUFFER));
  67542. p = targetBuffer;
  67543. /* Function returns the size of the encoded data. */
  67544. ExpectIntEQ(ret = wolfSSL_i2d_OCSP_CERTID(&certId, &p), sizeof(rawCertId));
  67545. /* If target buffer is not null, function increments targetBuffer to point
  67546. * just past the end of the encoded data. */
  67547. ExpectPtrEq(p, (targetBuffer + sizeof(rawCertId)));
  67548. for (i = 0; EXPECT_SUCCESS() && i < ret; ++i) {
  67549. ExpectIntEQ(targetBuffer[i], rawCertId[i]);
  67550. }
  67551. XFREE(targetBuffer, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  67552. targetBuffer = NULL;
  67553. /* If target buffer is null, function allocates memory for a buffer and
  67554. * copies the encoded data into it. targetBuffer then points to the start of
  67555. * this newly allocate buffer. */
  67556. ExpectIntEQ(ret = wolfSSL_i2d_OCSP_CERTID(&certId, &targetBuffer),
  67557. sizeof(rawCertId));
  67558. for (i = 0; EXPECT_SUCCESS() && i < ret; ++i) {
  67559. ExpectIntEQ(targetBuffer[i], rawCertId[i]);
  67560. }
  67561. XFREE(targetBuffer, NULL, DYNAMIC_TYPE_OPENSSL);
  67562. #endif
  67563. return EXPECT_RESULT();
  67564. }
  67565. static int test_wolfSSL_d2i_OCSP_CERTID(void)
  67566. {
  67567. EXPECT_DECLS;
  67568. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_HAPROXY)) && defined(HAVE_OCSP)
  67569. WOLFSSL_OCSP_CERTID* certId;
  67570. WOLFSSL_OCSP_CERTID* certIdGood;
  67571. WOLFSSL_OCSP_CERTID* certIdBad;
  67572. const unsigned char* rawCertIdPtr;
  67573. const unsigned char rawCertId[] = {
  67574. 0x30, 0x49, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05,
  67575. 0x00, 0x04, 0x14, 0x80, 0x51, 0x06, 0x01, 0x32, 0xad, 0x9a, 0xc2, 0x7d,
  67576. 0x51, 0x87, 0xa0, 0xe8, 0x87, 0xfb, 0x01, 0x62, 0x01, 0x55, 0xee, 0x04,
  67577. 0x14, 0x03, 0xde, 0x50, 0x35, 0x56, 0xd1, 0x4c, 0xbb, 0x66, 0xf0, 0xa3,
  67578. 0xe2, 0x1b, 0x1b, 0xc3, 0x97, 0xb2, 0x3d, 0xd1, 0x55, 0x02, 0x10, 0x01,
  67579. 0xfd, 0xa3, 0xeb, 0x6e, 0xca, 0x75, 0xc8, 0x88, 0x43, 0x8b, 0x72, 0x4b,
  67580. 0xcf, 0xbc, 0x91
  67581. };
  67582. rawCertIdPtr = &rawCertId[0];
  67583. /* If the cert ID is NULL the function should allocate it and copy the
  67584. * data to it. */
  67585. certId = NULL;
  67586. ExpectNotNull(certId = wolfSSL_d2i_OCSP_CERTID(&certId, &rawCertIdPtr,
  67587. sizeof(rawCertId)));
  67588. ExpectIntEQ(certId->rawCertIdSize, sizeof(rawCertId));
  67589. if (certId != NULL) {
  67590. XFREE(certId->rawCertId, NULL, DYNAMIC_TYPE_OPENSSL);
  67591. XFREE(certId, NULL, DYNAMIC_TYPE_OPENSSL);
  67592. }
  67593. /* If the cert ID is not NULL the function will just copy the data to it. */
  67594. ExpectNotNull(certId = (WOLFSSL_OCSP_CERTID*)XMALLOC(sizeof(*certId), NULL,
  67595. DYNAMIC_TYPE_TMP_BUFFER));
  67596. ExpectNotNull(certId);
  67597. ExpectNotNull(XMEMSET(certId, 0, sizeof(*certId)));
  67598. /* Reset rawCertIdPtr since it was push forward in the previous call. */
  67599. rawCertIdPtr = &rawCertId[0];
  67600. ExpectNotNull(certIdGood = wolfSSL_d2i_OCSP_CERTID(&certId, &rawCertIdPtr,
  67601. sizeof(rawCertId)));
  67602. ExpectPtrEq(certIdGood, certId);
  67603. ExpectIntEQ(certId->rawCertIdSize, sizeof(rawCertId));
  67604. if (certId != NULL) {
  67605. XFREE(certId->rawCertId, NULL, DYNAMIC_TYPE_OPENSSL);
  67606. XFREE(certId, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  67607. certId = NULL;
  67608. }
  67609. /* The below tests should fail when passed bad parameters. NULL should
  67610. * always be returned. */
  67611. ExpectNull(certIdBad = wolfSSL_d2i_OCSP_CERTID(NULL, &rawCertIdPtr,
  67612. sizeof(rawCertId)));
  67613. ExpectNull(certIdBad = wolfSSL_d2i_OCSP_CERTID(&certId, NULL,
  67614. sizeof(rawCertId)));
  67615. ExpectNull(certIdBad = wolfSSL_d2i_OCSP_CERTID(&certId, &rawCertIdPtr, 0));
  67616. #endif
  67617. return EXPECT_RESULT();
  67618. }
  67619. static int test_wolfSSL_OCSP_id_cmp(void)
  67620. {
  67621. EXPECT_DECLS;
  67622. #if defined(OPENSSL_ALL) && defined(HAVE_OCSP)
  67623. OCSP_CERTID id1;
  67624. OCSP_CERTID id2;
  67625. XMEMSET(&id1, 0, sizeof(id1));
  67626. XMEMSET(&id2, 0, sizeof(id2));
  67627. ExpectIntEQ(OCSP_id_cmp(&id1, &id2), 0);
  67628. ExpectIntNE(OCSP_id_cmp(NULL, NULL), 0);
  67629. ExpectIntNE(OCSP_id_cmp(&id1, NULL), 0);
  67630. ExpectIntNE(OCSP_id_cmp(NULL, &id2), 0);
  67631. #endif
  67632. return EXPECT_RESULT();
  67633. }
  67634. static int test_wolfSSL_OCSP_SINGLERESP_get0_id(void)
  67635. {
  67636. EXPECT_DECLS;
  67637. #if defined(HAVE_OCSP) && defined(OPENSSL_EXTRA)
  67638. WOLFSSL_OCSP_SINGLERESP single;
  67639. const WOLFSSL_OCSP_CERTID* certId;
  67640. XMEMSET(&single, 0, sizeof(single));
  67641. certId = wolfSSL_OCSP_SINGLERESP_get0_id(&single);
  67642. ExpectPtrEq(&single, certId);
  67643. ExpectNull(wolfSSL_OCSP_SINGLERESP_get0_id(NULL));
  67644. #endif
  67645. return EXPECT_RESULT();
  67646. }
  67647. static int test_wolfSSL_OCSP_single_get0_status(void)
  67648. {
  67649. EXPECT_DECLS;
  67650. #if defined(HAVE_OCSP) && defined(OPENSSL_EXTRA) && \
  67651. defined(WOLFSSL_OCSP_PARSE_STATUS)
  67652. WOLFSSL_OCSP_SINGLERESP single;
  67653. CertStatus certStatus;
  67654. WOLFSSL_ASN1_TIME* thisDate;
  67655. WOLFSSL_ASN1_TIME* nextDate;
  67656. int ret, i;
  67657. XMEMSET(&single, 0, sizeof(WOLFSSL_OCSP_SINGLERESP));
  67658. XMEMSET(&certStatus, 0, sizeof(CertStatus));
  67659. /* Fill the date fields with some dummy data. */
  67660. for (i = 0; i < CTC_DATE_SIZE; ++i) {
  67661. certStatus.thisDateParsed.data[i] = i;
  67662. certStatus.nextDateParsed.data[i] = i;
  67663. }
  67664. certStatus.status = CERT_GOOD;
  67665. single.status = &certStatus;
  67666. ret = wolfSSL_OCSP_single_get0_status(&single, NULL, NULL, &thisDate,
  67667. &nextDate);
  67668. ExpectIntEQ(ret, CERT_GOOD);
  67669. ExpectPtrEq(thisDate, &certStatus.thisDateParsed);
  67670. ExpectPtrEq(nextDate, &certStatus.nextDateParsed);
  67671. ExpectIntEQ(wolfSSL_OCSP_single_get0_status(NULL, NULL, NULL, NULL, NULL),
  67672. CERT_GOOD);
  67673. ExpectIntEQ(wolfSSL_OCSP_single_get0_status(&single, NULL, NULL, NULL,
  67674. NULL), CERT_GOOD);
  67675. #endif
  67676. return EXPECT_RESULT();
  67677. }
  67678. static int test_wolfSSL_OCSP_resp_count(void)
  67679. {
  67680. EXPECT_DECLS;
  67681. #if defined(HAVE_OCSP) && defined(OPENSSL_EXTRA)
  67682. WOLFSSL_OCSP_BASICRESP basicResp;
  67683. WOLFSSL_OCSP_SINGLERESP singleRespOne;
  67684. WOLFSSL_OCSP_SINGLERESP singleRespTwo;
  67685. XMEMSET(&basicResp, 0, sizeof(WOLFSSL_OCSP_BASICRESP));
  67686. XMEMSET(&singleRespOne, 0, sizeof(WOLFSSL_OCSP_SINGLERESP));
  67687. XMEMSET(&singleRespTwo, 0, sizeof(WOLFSSL_OCSP_SINGLERESP));
  67688. ExpectIntEQ(wolfSSL_OCSP_resp_count(&basicResp), 0);
  67689. basicResp.single = &singleRespOne;
  67690. ExpectIntEQ(wolfSSL_OCSP_resp_count(&basicResp), 1);
  67691. singleRespOne.next = &singleRespTwo;
  67692. ExpectIntEQ(wolfSSL_OCSP_resp_count(&basicResp), 2);
  67693. #endif
  67694. return EXPECT_RESULT();
  67695. }
  67696. static int test_wolfSSL_OCSP_resp_get0(void)
  67697. {
  67698. EXPECT_DECLS;
  67699. #if defined(HAVE_OCSP) && defined(OPENSSL_EXTRA)
  67700. WOLFSSL_OCSP_BASICRESP basicResp;
  67701. WOLFSSL_OCSP_SINGLERESP singleRespOne;
  67702. WOLFSSL_OCSP_SINGLERESP singleRespTwo;
  67703. XMEMSET(&basicResp, 0, sizeof(WOLFSSL_OCSP_BASICRESP));
  67704. XMEMSET(&singleRespOne, 0, sizeof(WOLFSSL_OCSP_SINGLERESP));
  67705. XMEMSET(&singleRespTwo, 0, sizeof(WOLFSSL_OCSP_SINGLERESP));
  67706. basicResp.single = &singleRespOne;
  67707. singleRespOne.next = &singleRespTwo;
  67708. ExpectPtrEq(wolfSSL_OCSP_resp_get0(&basicResp, 0), &singleRespOne);
  67709. ExpectPtrEq(wolfSSL_OCSP_resp_get0(&basicResp, 1), &singleRespTwo);
  67710. #endif
  67711. return EXPECT_RESULT();
  67712. }
  67713. static int test_wolfSSL_OCSP_parse_url(void)
  67714. {
  67715. EXPECT_DECLS;
  67716. #if defined(OPENSSL_EXTRA) && defined(HAVE_OCSP)
  67717. #define CK_OPU_OK(u, h, po, pa, s) do { \
  67718. char* host = NULL; \
  67719. char* port = NULL; \
  67720. char* path = NULL; \
  67721. int isSsl = 0; \
  67722. ExpectIntEQ(OCSP_parse_url(u, &host, &port, &path, &isSsl), 1); \
  67723. ExpectStrEQ(host, h); \
  67724. ExpectStrEQ(port, po); \
  67725. ExpectStrEQ(path, pa); \
  67726. ExpectIntEQ(isSsl, s); \
  67727. XFREE(host, NULL, DYNAMIC_TYPE_OPENSSL); \
  67728. XFREE(port, NULL, DYNAMIC_TYPE_OPENSSL); \
  67729. XFREE(path, NULL, DYNAMIC_TYPE_OPENSSL); \
  67730. } while(0)
  67731. #define CK_OPU_FAIL(u) do { \
  67732. char* host = NULL; \
  67733. char* port = NULL; \
  67734. char* path = NULL; \
  67735. int isSsl = 0; \
  67736. ExpectIntEQ(OCSP_parse_url(u, &host, &port, &path, &isSsl), 0); \
  67737. XFREE(host, NULL, DYNAMIC_TYPE_OPENSSL); \
  67738. XFREE(port, NULL, DYNAMIC_TYPE_OPENSSL); \
  67739. XFREE(path, NULL, DYNAMIC_TYPE_OPENSSL); \
  67740. } while(0)
  67741. CK_OPU_OK("http://localhost", "localhost", "80", "/", 0);
  67742. CK_OPU_OK("https://wolfssl.com", "wolfssl.com", "443", "/", 1);
  67743. CK_OPU_OK("https://www.wolfssl.com/fips-140-3-announcement-to-the-world/",
  67744. "www.wolfssl.com", "443", "/fips-140-3-announcement-to-the-world/", 1);
  67745. CK_OPU_OK("http://localhost:1234", "localhost", "1234", "/", 0);
  67746. CK_OPU_OK("https://localhost:1234", "localhost", "1234", "/", 1);
  67747. CK_OPU_FAIL("ftp://localhost");
  67748. /* two strings to cppcheck doesn't mark it as a c++ style comment */
  67749. CK_OPU_FAIL("http/""/localhost");
  67750. CK_OPU_FAIL("http:/localhost");
  67751. CK_OPU_FAIL("https://localhost/path:1234");
  67752. #undef CK_OPU_OK
  67753. #undef CK_OPU_FAIL
  67754. #endif
  67755. return EXPECT_RESULT();
  67756. }
  67757. #if defined(OPENSSL_ALL) && defined(HAVE_OCSP) && \
  67758. defined(WOLFSSL_SIGNER_DER_CERT) && !defined(NO_FILESYSTEM)
  67759. static time_t test_wolfSSL_OCSP_REQ_CTX_time_cb(time_t* t)
  67760. {
  67761. if (t != NULL) {
  67762. *t = 1722006780;
  67763. }
  67764. return 1722006780;
  67765. }
  67766. #endif
  67767. static int test_wolfSSL_OCSP_REQ_CTX(void)
  67768. {
  67769. EXPECT_DECLS;
  67770. #if defined(OPENSSL_ALL) && defined(HAVE_OCSP) && \
  67771. defined(WOLFSSL_SIGNER_DER_CERT) && !defined(NO_FILESYSTEM)
  67772. /* This buffer was taken from the ocsp-stapling.test test case 1. The ocsp
  67773. * response was captured in wireshark. It contains both the http and binary
  67774. * parts. The time test_wolfSSL_OCSP_REQ_CTX_time_cb is set exactly so that
  67775. * the time check passes. */
  67776. unsigned char ocspRespBin[] = {
  67777. 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x30, 0x20, 0x32, 0x30, 0x30,
  67778. 0x20, 0x4f, 0x4b, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74,
  67779. 0x2d, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x69,
  67780. 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x6f, 0x63, 0x73, 0x70, 0x2d,
  67781. 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x0d, 0x0a, 0x43, 0x6f,
  67782. 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68,
  67783. 0x3a, 0x20, 0x31, 0x38, 0x32, 0x31, 0x0d, 0x0a, 0x0d, 0x0a, 0x30, 0x82,
  67784. 0x07, 0x19, 0x0a, 0x01, 0x00, 0xa0, 0x82, 0x07, 0x12, 0x30, 0x82, 0x07,
  67785. 0x0e, 0x06, 0x09, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x01, 0x01,
  67786. 0x04, 0x82, 0x06, 0xff, 0x30, 0x82, 0x06, 0xfb, 0x30, 0x82, 0x01, 0x19,
  67787. 0xa1, 0x81, 0xa1, 0x30, 0x81, 0x9e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03,
  67788. 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x06,
  67789. 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e,
  67790. 0x67, 0x74, 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04,
  67791. 0x07, 0x0c, 0x07, 0x53, 0x65, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10,
  67792. 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x77, 0x6f, 0x6c,
  67793. 0x66, 0x53, 0x53, 0x4c, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04,
  67794. 0x0b, 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69,
  67795. 0x6e, 0x67, 0x31, 0x1f, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c,
  67796. 0x16, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x4f, 0x43, 0x53,
  67797. 0x50, 0x20, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x64, 0x65, 0x72, 0x31,
  67798. 0x1f, 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,
  67799. 0x09, 0x01, 0x16, 0x10, 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c,
  67800. 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x18, 0x0f, 0x32, 0x30,
  67801. 0x32, 0x34, 0x30, 0x37, 0x32, 0x36, 0x31, 0x35, 0x31, 0x32, 0x30, 0x35,
  67802. 0x5a, 0x30, 0x62, 0x30, 0x60, 0x30, 0x38, 0x30, 0x07, 0x06, 0x05, 0x2b,
  67803. 0x0e, 0x03, 0x02, 0x1a, 0x04, 0x14, 0x71, 0x4d, 0x82, 0x23, 0x40, 0x59,
  67804. 0xc0, 0x96, 0xa1, 0x37, 0x43, 0xfa, 0x31, 0xdb, 0xba, 0xb1, 0x43, 0x18,
  67805. 0xda, 0x04, 0x04, 0x14, 0x83, 0xc6, 0x3a, 0x89, 0x2c, 0x81, 0xf4, 0x02,
  67806. 0xd7, 0x9d, 0x4c, 0xe2, 0x2a, 0xc0, 0x71, 0x82, 0x64, 0x44, 0xda, 0x0e,
  67807. 0x02, 0x01, 0x05, 0x80, 0x00, 0x18, 0x0f, 0x32, 0x30, 0x32, 0x34, 0x30,
  67808. 0x37, 0x32, 0x36, 0x31, 0x35, 0x31, 0x32, 0x30, 0x35, 0x5a, 0xa0, 0x11,
  67809. 0x18, 0x0f, 0x32, 0x30, 0x32, 0x34, 0x30, 0x37, 0x32, 0x36, 0x31, 0x35,
  67810. 0x31, 0x33, 0x30, 0x35, 0x5a, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48,
  67811. 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01,
  67812. 0x00, 0x89, 0x7a, 0xe9, 0x6b, 0x66, 0x47, 0x8e, 0x52, 0x16, 0xf9, 0x8a,
  67813. 0x5a, 0x1e, 0x7a, 0x35, 0xbb, 0x1d, 0x6c, 0xd8, 0x31, 0xbb, 0x24, 0xd2,
  67814. 0xd7, 0xa4, 0x30, 0x27, 0x06, 0x17, 0x66, 0xd1, 0xf9, 0x8d, 0x24, 0xb0,
  67815. 0x49, 0x37, 0x62, 0x13, 0x78, 0x5e, 0xa6, 0x6d, 0xea, 0xe3, 0xd0, 0x30,
  67816. 0x82, 0x7d, 0xb6, 0xf6, 0x55, 0x82, 0x11, 0xdc, 0xe7, 0x0f, 0xd6, 0x24,
  67817. 0xb4, 0x80, 0x23, 0x4f, 0xfd, 0xa7, 0x9a, 0x4b, 0xac, 0xf2, 0xd3, 0xde,
  67818. 0x42, 0x10, 0xfb, 0x4b, 0x29, 0x06, 0x02, 0x7b, 0x47, 0x36, 0x70, 0x75,
  67819. 0x45, 0x38, 0x8d, 0x3e, 0x55, 0x9c, 0xce, 0x78, 0xd8, 0x18, 0x45, 0x47,
  67820. 0x2d, 0x2a, 0x46, 0x65, 0x13, 0x93, 0x1a, 0x98, 0x90, 0xc6, 0x2d, 0xd5,
  67821. 0x05, 0x2a, 0xfc, 0xcb, 0xac, 0x53, 0x73, 0x93, 0x42, 0x4e, 0xdb, 0x17,
  67822. 0x91, 0xcb, 0xe1, 0x08, 0x03, 0xd1, 0x33, 0x57, 0x4b, 0x1d, 0xb8, 0x71,
  67823. 0x84, 0x01, 0x04, 0x47, 0x6f, 0x06, 0xfa, 0x76, 0x7d, 0xd9, 0x37, 0x64,
  67824. 0x57, 0x37, 0x3a, 0x8f, 0x4d, 0x88, 0x11, 0xa5, 0xd4, 0xaa, 0xcb, 0x49,
  67825. 0x47, 0x86, 0xdd, 0xcf, 0x46, 0xa6, 0xfa, 0x8e, 0xf2, 0x62, 0x0f, 0xc9,
  67826. 0x25, 0xf2, 0x39, 0x62, 0x3e, 0x2d, 0x35, 0xc4, 0x76, 0x7b, 0xae, 0xd5,
  67827. 0xe8, 0x85, 0xa1, 0xa6, 0x2d, 0x41, 0xd6, 0x8e, 0x3c, 0xfa, 0xdc, 0x6c,
  67828. 0x66, 0xe2, 0x61, 0xe7, 0xe5, 0x90, 0xa1, 0xfd, 0x7f, 0xdb, 0x18, 0xd0,
  67829. 0xeb, 0x6d, 0x73, 0x08, 0x5f, 0x6a, 0x65, 0x44, 0x50, 0xad, 0x38, 0x9d,
  67830. 0xb6, 0xfb, 0xbf, 0x28, 0x55, 0x84, 0x65, 0xfa, 0x0e, 0x34, 0xfc, 0x43,
  67831. 0x19, 0x80, 0x5c, 0x7d, 0x2d, 0x5b, 0xd8, 0x60, 0xec, 0x0e, 0xf9, 0x1e,
  67832. 0x6e, 0x32, 0x3f, 0x35, 0xf7, 0xec, 0x7e, 0x47, 0xba, 0xb5, 0xd2, 0xaa,
  67833. 0x5a, 0x9d, 0x07, 0x2c, 0xc5, 0xa0, 0x82, 0x04, 0xc6, 0x30, 0x82, 0x04,
  67834. 0xc2, 0x30, 0x82, 0x04, 0xbe, 0x30, 0x82, 0x03, 0xa6, 0xa0, 0x03, 0x02,
  67835. 0x01, 0x02, 0x02, 0x01, 0x04, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48,
  67836. 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x81, 0x97, 0x31,
  67837. 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53,
  67838. 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x57,
  67839. 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67, 0x74, 0x6f, 0x6e, 0x31, 0x10, 0x30,
  67840. 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x53, 0x65, 0x61, 0x74,
  67841. 0x74, 0x6c, 0x65, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a,
  67842. 0x0c, 0x07, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x31, 0x14, 0x30,
  67843. 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69,
  67844. 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18, 0x30, 0x16, 0x06,
  67845. 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53,
  67846. 0x4c, 0x20, 0x72, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x31, 0x1f, 0x30,
  67847. 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01,
  67848. 0x16, 0x10, 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, 0x66, 0x73,
  67849. 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x34,
  67850. 0x30, 0x37, 0x32, 0x36, 0x31, 0x35, 0x31, 0x32, 0x30, 0x34, 0x5a, 0x17,
  67851. 0x0d, 0x32, 0x37, 0x30, 0x34, 0x32, 0x32, 0x31, 0x35, 0x31, 0x32, 0x30,
  67852. 0x34, 0x5a, 0x30, 0x81, 0x9e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55,
  67853. 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03,
  67854. 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67,
  67855. 0x74, 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07,
  67856. 0x0c, 0x07, 0x53, 0x65, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10, 0x30,
  67857. 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x77, 0x6f, 0x6c, 0x66,
  67858. 0x53, 0x53, 0x4c, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b,
  67859. 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e,
  67860. 0x67, 0x31, 0x1f, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x16,
  67861. 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x4f, 0x43, 0x53, 0x50,
  67862. 0x20, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x64, 0x65, 0x72, 0x31, 0x1f,
  67863. 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09,
  67864. 0x01, 0x16, 0x10, 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, 0x66,
  67865. 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x82, 0x01, 0x22, 0x30,
  67866. 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  67867. 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02,
  67868. 0x82, 0x01, 0x01, 0x00, 0xb8, 0xba, 0x23, 0xb4, 0xf6, 0xc3, 0x7b, 0x14,
  67869. 0xc3, 0xa4, 0xf5, 0x1d, 0x61, 0xa1, 0xf5, 0x1e, 0x63, 0xb9, 0x85, 0x23,
  67870. 0x34, 0x50, 0x6d, 0xf8, 0x7c, 0xa2, 0x8a, 0x04, 0x8b, 0xd5, 0x75, 0x5c,
  67871. 0x2d, 0xf7, 0x63, 0x88, 0xd1, 0x07, 0x7a, 0xea, 0x0b, 0x45, 0x35, 0x2b,
  67872. 0xeb, 0x1f, 0xb1, 0x22, 0xb4, 0x94, 0x41, 0x38, 0xe2, 0x9d, 0x74, 0xd6,
  67873. 0x8b, 0x30, 0x22, 0x10, 0x51, 0xc5, 0xdb, 0xca, 0x3f, 0x46, 0x2b, 0xfe,
  67874. 0xe5, 0x5a, 0x3f, 0x41, 0x74, 0x67, 0x75, 0x95, 0xa9, 0x94, 0xd5, 0xc3,
  67875. 0xee, 0x42, 0xf8, 0x8d, 0xeb, 0x92, 0x95, 0xe1, 0xd9, 0x65, 0xb7, 0x43,
  67876. 0xc4, 0x18, 0xde, 0x16, 0x80, 0x90, 0xce, 0x24, 0x35, 0x21, 0xc4, 0x55,
  67877. 0xac, 0x5a, 0x51, 0xe0, 0x2e, 0x2d, 0xb3, 0x0a, 0x5a, 0x4f, 0x4a, 0x73,
  67878. 0x31, 0x50, 0xee, 0x4a, 0x16, 0xbd, 0x39, 0x8b, 0xad, 0x05, 0x48, 0x87,
  67879. 0xb1, 0x99, 0xe2, 0x10, 0xa7, 0x06, 0x72, 0x67, 0xca, 0x5c, 0xd1, 0x97,
  67880. 0xbd, 0xc8, 0xf1, 0x76, 0xf8, 0xe0, 0x4a, 0xec, 0xbc, 0x93, 0xf4, 0x66,
  67881. 0x4c, 0x28, 0x71, 0xd1, 0xd8, 0x66, 0x03, 0xb4, 0x90, 0x30, 0xbb, 0x17,
  67882. 0xb0, 0xfe, 0x97, 0xf5, 0x1e, 0xe8, 0xc7, 0x5d, 0x9b, 0x8b, 0x11, 0x19,
  67883. 0x12, 0x3c, 0xab, 0x82, 0x71, 0x78, 0xff, 0xae, 0x3f, 0x32, 0xb2, 0x08,
  67884. 0x71, 0xb2, 0x1b, 0x8c, 0x27, 0xac, 0x11, 0xb8, 0xd8, 0x43, 0x49, 0xcf,
  67885. 0xb0, 0x70, 0xb1, 0xf0, 0x8c, 0xae, 0xda, 0x24, 0x87, 0x17, 0x3b, 0xd8,
  67886. 0x04, 0x65, 0x6c, 0x00, 0x76, 0x50, 0xef, 0x15, 0x08, 0xd7, 0xb4, 0x73,
  67887. 0x68, 0x26, 0x14, 0x87, 0x95, 0xc3, 0x5f, 0x6e, 0x61, 0xb8, 0x87, 0x84,
  67888. 0xfa, 0x80, 0x1a, 0x0a, 0x8b, 0x98, 0xf3, 0xe3, 0xff, 0x4e, 0x44, 0x1c,
  67889. 0x65, 0x74, 0x7c, 0x71, 0x54, 0x65, 0xe5, 0x39, 0x02, 0x03, 0x01, 0x00,
  67890. 0x01, 0xa3, 0x82, 0x01, 0x0a, 0x30, 0x82, 0x01, 0x06, 0x30, 0x09, 0x06,
  67891. 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, 0x00, 0x30, 0x1d, 0x06, 0x03,
  67892. 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x32, 0x67, 0xe1, 0xb1, 0x79,
  67893. 0xd2, 0x81, 0xfc, 0x9f, 0x23, 0x0c, 0x70, 0x40, 0x50, 0xb5, 0x46, 0x56,
  67894. 0xb8, 0x30, 0x36, 0x30, 0x81, 0xc4, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04,
  67895. 0x81, 0xbc, 0x30, 0x81, 0xb9, 0x80, 0x14, 0x73, 0xb0, 0x1c, 0xa4, 0x2f,
  67896. 0x82, 0xcb, 0xcf, 0x47, 0xa5, 0x38, 0xd7, 0xb0, 0x04, 0x82, 0x3a, 0x7e,
  67897. 0x72, 0x15, 0x21, 0xa1, 0x81, 0x9d, 0xa4, 0x81, 0x9a, 0x30, 0x81, 0x97,
  67898. 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55,
  67899. 0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a,
  67900. 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67, 0x74, 0x6f, 0x6e, 0x31, 0x10,
  67901. 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x53, 0x65, 0x61,
  67902. 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04,
  67903. 0x0a, 0x0c, 0x07, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x31, 0x14,
  67904. 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45, 0x6e, 0x67,
  67905. 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18, 0x30, 0x16,
  67906. 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x6f, 0x6c, 0x66, 0x53,
  67907. 0x53, 0x4c, 0x20, 0x72, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x31, 0x1f,
  67908. 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09,
  67909. 0x01, 0x16, 0x10, 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, 0x66,
  67910. 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x82, 0x01, 0x63, 0x30, 0x13,
  67911. 0x06, 0x03, 0x55, 0x1d, 0x25, 0x04, 0x0c, 0x30, 0x0a, 0x06, 0x08, 0x2b,
  67912. 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x09, 0x30, 0x0d, 0x06, 0x09, 0x2a,
  67913. 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82,
  67914. 0x01, 0x01, 0x00, 0x37, 0xb9, 0x66, 0xd3, 0xa1, 0x08, 0xfc, 0x37, 0x58,
  67915. 0x4e, 0xe0, 0x8c, 0xd3, 0x7f, 0xa6, 0x0f, 0x59, 0xd3, 0x14, 0xf7, 0x4b,
  67916. 0x36, 0xf7, 0x2e, 0x98, 0xeb, 0x7c, 0x03, 0x3f, 0x3a, 0xd6, 0x9c, 0xcd,
  67917. 0xb4, 0x9e, 0x8d, 0x5f, 0x92, 0xa6, 0x6f, 0x63, 0x87, 0x34, 0xe8, 0x83,
  67918. 0xfd, 0x6d, 0x34, 0x64, 0xb5, 0xf0, 0x9c, 0x71, 0x02, 0xb8, 0xf6, 0x2f,
  67919. 0x10, 0xa0, 0x92, 0x8f, 0x3f, 0x86, 0x3e, 0xe2, 0x01, 0x5a, 0x56, 0x39,
  67920. 0x0a, 0x8d, 0xb1, 0xbe, 0x03, 0xf7, 0xf8, 0xa7, 0x88, 0x46, 0xef, 0x81,
  67921. 0xa0, 0xad, 0x86, 0xc9, 0xe6, 0x23, 0x89, 0x1d, 0xa6, 0x24, 0x45, 0xf2,
  67922. 0x6a, 0x83, 0x2d, 0x8e, 0x92, 0x17, 0x1e, 0x44, 0x19, 0xfa, 0x0f, 0x47,
  67923. 0x6b, 0x8f, 0x4a, 0xa2, 0xda, 0xab, 0xd5, 0x2b, 0xcd, 0xcb, 0x14, 0xf0,
  67924. 0xb5, 0xcf, 0x7c, 0x76, 0x42, 0x32, 0x90, 0x21, 0xdc, 0xdd, 0x52, 0xfc,
  67925. 0x53, 0x7e, 0xff, 0x7f, 0xd9, 0x58, 0x6b, 0x1f, 0x73, 0xee, 0x83, 0xf4,
  67926. 0x67, 0xfa, 0x4a, 0x4f, 0x24, 0xe4, 0x2b, 0x10, 0x74, 0x89, 0x52, 0x9a,
  67927. 0xf7, 0xa4, 0xe0, 0xaf, 0xf5, 0x63, 0xd7, 0xfa, 0x0b, 0x2c, 0xc9, 0x39,
  67928. 0x5d, 0xbd, 0x44, 0x93, 0x69, 0xa4, 0x1d, 0x01, 0xe2, 0x66, 0xe7, 0xc1,
  67929. 0x11, 0x44, 0x7d, 0x0a, 0x7e, 0x5d, 0x1d, 0x26, 0xc5, 0x4a, 0x26, 0x2e,
  67930. 0xa3, 0x58, 0xc4, 0xf7, 0x10, 0xcb, 0xba, 0xe6, 0x27, 0xfc, 0xdb, 0x54,
  67931. 0xe2, 0x60, 0x08, 0xc2, 0x0e, 0x4b, 0xd4, 0xaa, 0x22, 0x23, 0x93, 0x9f,
  67932. 0xe1, 0xcb, 0x85, 0xa4, 0x41, 0x6f, 0x26, 0xa7, 0x77, 0x8a, 0xef, 0x66,
  67933. 0xd0, 0xf8, 0x33, 0xf6, 0xfd, 0x6d, 0x37, 0x7a, 0x89, 0xcc, 0x88, 0x3b,
  67934. 0x82, 0xd0, 0xa9, 0xdf, 0xf1, 0x3d, 0xdc, 0xb0, 0x06, 0x1c, 0xe4, 0x4b,
  67935. 0x57, 0xb4, 0x0c, 0x65, 0xb9, 0xb4, 0x6c
  67936. };
  67937. OCSP_REQ_CTX *ctx = NULL;
  67938. OCSP_REQUEST *req = NULL;
  67939. OCSP_CERTID *cid = NULL;
  67940. OCSP_RESPONSE *rsp = NULL;
  67941. BIO* bio1 = NULL;
  67942. BIO* bio2 = NULL;
  67943. X509* cert = NULL;
  67944. X509 *issuer = NULL;
  67945. X509_LOOKUP *lookup = NULL;
  67946. X509_STORE *store = NULL;
  67947. STACK_OF(X509_OBJECT) *str_objs = NULL;
  67948. X509_OBJECT *x509_obj = NULL;
  67949. ExpectNotNull(bio1 = BIO_new(BIO_s_bio()));
  67950. ExpectNotNull(bio2 = BIO_new(BIO_s_bio()));
  67951. ExpectIntEQ(BIO_make_bio_pair(bio1, bio2), WOLFSSL_SUCCESS);
  67952. /* Load the leaf cert */
  67953. ExpectNotNull(cert = wolfSSL_X509_load_certificate_file(
  67954. "certs/ocsp/server1-cert.pem", WOLFSSL_FILETYPE_PEM));
  67955. ExpectNotNull(store = X509_STORE_new());
  67956. ExpectNotNull(lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()));
  67957. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/ocsp/server1-cert.pem",
  67958. X509_FILETYPE_PEM), 1);
  67959. ExpectNotNull(str_objs = X509_STORE_get0_objects(store));
  67960. ExpectNotNull(x509_obj = X509_OBJECT_retrieve_by_subject(str_objs,
  67961. X509_LU_X509, X509_get_issuer_name(cert)));
  67962. ExpectNotNull(issuer = X509_OBJECT_get0_X509(x509_obj));
  67963. ExpectNotNull(req = OCSP_REQUEST_new());
  67964. ExpectNotNull(cid = OCSP_cert_to_id(EVP_sha1(), cert, issuer));
  67965. ExpectNotNull(OCSP_request_add0_id(req, cid));
  67966. ExpectIntEQ(OCSP_request_add1_nonce(req, NULL, -1), 1);
  67967. ExpectNotNull(ctx = OCSP_sendreq_new(bio1, "/", NULL, -1));
  67968. ExpectIntEQ(OCSP_REQ_CTX_add1_header(ctx, "Host", "127.0.0.1"), 1);
  67969. ExpectIntEQ(OCSP_REQ_CTX_set1_req(ctx, req), 1);
  67970. ExpectIntEQ(OCSP_sendreq_nbio(&rsp, ctx), -1);
  67971. ExpectIntEQ(BIO_write(bio2, ocspRespBin, sizeof(ocspRespBin)),
  67972. sizeof(ocspRespBin));
  67973. ExpectIntEQ(wc_SetTimeCb(test_wolfSSL_OCSP_REQ_CTX_time_cb), 0);
  67974. ExpectIntEQ(OCSP_sendreq_nbio(&rsp, ctx), 1);
  67975. ExpectIntEQ(wc_SetTimeCb(NULL), 0);
  67976. ExpectNotNull(rsp);
  67977. OCSP_REQ_CTX_free(ctx);
  67978. OCSP_REQUEST_free(req);
  67979. OCSP_RESPONSE_free(rsp);
  67980. BIO_free(bio1);
  67981. BIO_free(bio2);
  67982. X509_free(cert);
  67983. X509_STORE_free(store);
  67984. #endif
  67985. return EXPECT_RESULT();
  67986. }
  67987. static int test_wolfSSL_EVP_PKEY_derive(void)
  67988. {
  67989. EXPECT_DECLS;
  67990. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT) || defined(WOLFSSL_OPENSSH)
  67991. #if (!defined(NO_DH) && defined(WOLFSSL_DH_EXTRA)) || defined(HAVE_ECC)
  67992. EVP_PKEY_CTX *ctx = NULL;
  67993. unsigned char *skey = NULL;
  67994. size_t skeylen;
  67995. EVP_PKEY *pkey = NULL;
  67996. EVP_PKEY *peerkey = NULL;
  67997. const unsigned char* key;
  67998. #if !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA)
  67999. /* DH */
  68000. key = dh_key_der_2048;
  68001. ExpectNotNull((pkey = d2i_PrivateKey(EVP_PKEY_DH, NULL, &key,
  68002. sizeof_dh_key_der_2048)));
  68003. ExpectIntEQ(DH_generate_key(EVP_PKEY_get0_DH(pkey)), 1);
  68004. key = dh_key_der_2048;
  68005. ExpectNotNull((peerkey = d2i_PrivateKey(EVP_PKEY_DH, NULL, &key,
  68006. sizeof_dh_key_der_2048)));
  68007. ExpectIntEQ(DH_generate_key(EVP_PKEY_get0_DH(peerkey)), 1);
  68008. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  68009. ExpectIntEQ(EVP_PKEY_derive_init(ctx), 1);
  68010. ExpectIntEQ(EVP_PKEY_derive_set_peer(ctx, peerkey), 1);
  68011. ExpectIntEQ(EVP_PKEY_derive(ctx, NULL, &skeylen), 1);
  68012. ExpectNotNull(skey = (unsigned char*)XMALLOC(skeylen, NULL,
  68013. DYNAMIC_TYPE_OPENSSL));
  68014. ExpectIntEQ(EVP_PKEY_derive(ctx, skey, &skeylen), 1);
  68015. EVP_PKEY_CTX_free(ctx);
  68016. ctx = NULL;
  68017. EVP_PKEY_free(peerkey);
  68018. peerkey = NULL;
  68019. EVP_PKEY_free(pkey);
  68020. pkey = NULL;
  68021. XFREE(skey, NULL, DYNAMIC_TYPE_OPENSSL);
  68022. skey = NULL;
  68023. #endif
  68024. #ifdef HAVE_ECC
  68025. /* ECDH */
  68026. key = ecc_clikey_der_256;
  68027. ExpectNotNull((pkey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &key,
  68028. sizeof_ecc_clikey_der_256)));
  68029. key = ecc_clikeypub_der_256;
  68030. ExpectNotNull((peerkey = d2i_PUBKEY(NULL, &key,
  68031. sizeof_ecc_clikeypub_der_256)));
  68032. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  68033. ExpectIntEQ(EVP_PKEY_derive_init(ctx), 1);
  68034. ExpectIntEQ(EVP_PKEY_derive_set_peer(ctx, peerkey), 1);
  68035. ExpectIntEQ(EVP_PKEY_derive(ctx, NULL, &skeylen), 1);
  68036. ExpectNotNull(skey = (unsigned char*)XMALLOC(skeylen, NULL,
  68037. DYNAMIC_TYPE_OPENSSL));
  68038. ExpectIntEQ(EVP_PKEY_derive(ctx, skey, &skeylen), 1);
  68039. EVP_PKEY_CTX_free(ctx);
  68040. EVP_PKEY_free(peerkey);
  68041. EVP_PKEY_free(pkey);
  68042. XFREE(skey, NULL, DYNAMIC_TYPE_OPENSSL);
  68043. #endif /* HAVE_ECC */
  68044. #endif /* (!NO_DH && WOLFSSL_DH_EXTRA) || HAVE_ECC */
  68045. #endif /* OPENSSL_ALL || WOLFSSL_QT || WOLFSSL_OPENSSH */
  68046. return EXPECT_RESULT();
  68047. }
  68048. static int test_wolfSSL_EVP_PBE_scrypt(void)
  68049. {
  68050. EXPECT_DECLS;
  68051. #if defined(OPENSSL_EXTRA) && defined(HAVE_SCRYPT) && defined(HAVE_PBKDF2) && \
  68052. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 5))
  68053. #if !defined(NO_PWDBASED) && !defined(NO_SHA256)
  68054. int ret;
  68055. const char pwd[] = {'p','a','s','s','w','o','r','d'};
  68056. int pwdlen = sizeof(pwd);
  68057. const byte salt[] = {'N','a','C','l'};
  68058. int saltlen = sizeof(salt);
  68059. byte key[80];
  68060. word64 numOvr32 = (word64)INT32_MAX + 1;
  68061. /* expected derived key for N:16, r:1, p:1 */
  68062. const byte expectedKey[] = {
  68063. 0xAE, 0xC6, 0xB7, 0x48, 0x3E, 0xD2, 0x6E, 0x08, 0x80, 0x2B,
  68064. 0x41, 0xF4, 0x03, 0x20, 0x86, 0xA0, 0xE8, 0x86, 0xBE, 0x7A,
  68065. 0xC4, 0x8F, 0xCF, 0xD9, 0x2F, 0xF0, 0xCE, 0xF8, 0x10, 0x97,
  68066. 0x52, 0xF4, 0xAC, 0x74, 0xB0, 0x77, 0x26, 0x32, 0x56, 0xA6,
  68067. 0x5A, 0x99, 0x70, 0x1B, 0x7A, 0x30, 0x4D, 0x46, 0x61, 0x1C,
  68068. 0x8A, 0xA3, 0x91, 0xE7, 0x99, 0xCE, 0x10, 0xA2, 0x77, 0x53,
  68069. 0xE7, 0xE9, 0xC0, 0x9A};
  68070. /* N r p mx key keylen */
  68071. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 0, 1, 1, 0, key, 64);
  68072. ExpectIntEQ(ret, 0); /* N must be greater than 1 */
  68073. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 3, 1, 1, 0, key, 64);
  68074. ExpectIntEQ(ret, 0); /* N must be power of 2 */
  68075. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 0, 1, 0, key, 64);
  68076. ExpectIntEQ(ret, 0); /* r must be greater than 0 */
  68077. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 1, 0, 0, key, 64);
  68078. ExpectIntEQ(ret, 0); /* p must be greater than 0 */
  68079. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 1, 1, 0, key, 0);
  68080. ExpectIntEQ(ret, 0); /* keylen must be greater than 0 */
  68081. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 9, 1, 0, key, 64);
  68082. ExpectIntEQ(ret, 0); /* r must be smaller than 9 */
  68083. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 1, 1, 0, NULL, 64);
  68084. ExpectIntEQ(ret, 1); /* should succeed if key is NULL */
  68085. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 1, 1, 0, key, 64);
  68086. ExpectIntEQ(ret, 1); /* should succeed */
  68087. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, numOvr32, 1, 0,
  68088. key, 64);
  68089. ExpectIntEQ(ret, 0); /* should fail since r is greater than INT32_MAC */
  68090. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 1, numOvr32, 0,
  68091. key, 64);
  68092. ExpectIntEQ(ret, 0); /* should fail since p is greater than INT32_MAC */
  68093. ret = EVP_PBE_scrypt(pwd, pwdlen, NULL, 0, 2, 1, 1, 0, key, 64);
  68094. ExpectIntEQ(ret, 1); /* should succeed even if salt is NULL */
  68095. ret = EVP_PBE_scrypt(pwd, pwdlen, NULL, 4, 2, 1, 1, 0, key, 64);
  68096. ExpectIntEQ(ret, 0); /* if salt is NULL, saltlen must be 0, otherwise fail*/
  68097. ret = EVP_PBE_scrypt(NULL, 0, salt, saltlen, 2, 1, 1, 0, key, 64);
  68098. ExpectIntEQ(ret, 1); /* should succeed if pwd is NULL and pwdlen is 0*/
  68099. ret = EVP_PBE_scrypt(NULL, 4, salt, saltlen, 2, 1, 1, 0, key, 64);
  68100. ExpectIntEQ(ret, 0); /* if pwd is NULL, pwdlen must be 0 */
  68101. ret = EVP_PBE_scrypt(NULL, 0, NULL, 0, 2, 1, 1, 0, key, 64);
  68102. ExpectIntEQ(ret, 1); /* should succeed even both pwd and salt are NULL */
  68103. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 16, 1, 1, 0, key, 64);
  68104. ExpectIntEQ(ret, 1);
  68105. ret = XMEMCMP(expectedKey, key, sizeof(expectedKey));
  68106. ExpectIntEQ(ret, 0); /* derived key must be the same as expected-key */
  68107. #endif /* !NO_PWDBASED && !NO_SHA256 */
  68108. #endif /* OPENSSL_EXTRA && HAVE_SCRYPT && HAVE_PBKDF2 */
  68109. return EXPECT_RESULT();
  68110. }
  68111. static int test_no_op_functions(void)
  68112. {
  68113. EXPECT_DECLS;
  68114. #if defined(OPENSSL_EXTRA)
  68115. /* this makes sure wolfSSL can compile and run these no-op functions */
  68116. SSL_load_error_strings();
  68117. ENGINE_load_builtin_engines();
  68118. OpenSSL_add_all_ciphers();
  68119. ExpectIntEQ(CRYPTO_malloc_init(), 0);
  68120. #endif
  68121. return EXPECT_RESULT();
  68122. }
  68123. static int test_wolfSSL_CRYPTO_memcmp(void)
  68124. {
  68125. EXPECT_DECLS;
  68126. #ifdef OPENSSL_EXTRA
  68127. char a[] = "wolfSSL (formerly CyaSSL) is a small, fast, portable "
  68128. "implementation of TLS/SSL for embedded devices to the cloud.";
  68129. char b[] = "wolfSSL (formerly CyaSSL) is a small, fast, portable "
  68130. "implementation of TLS/SSL for embedded devices to the cloud.";
  68131. char c[] = "wolfSSL (formerly CyaSSL) is a small, fast, portable "
  68132. "implementation of TLS/SSL for embedded devices to the cloud!";
  68133. ExpectIntEQ(CRYPTO_memcmp(a, b, sizeof(a)), 0);
  68134. ExpectIntNE(CRYPTO_memcmp(a, c, sizeof(a)), 0);
  68135. #endif
  68136. return EXPECT_RESULT();
  68137. }
  68138. /*----------------------------------------------------------------------------*
  68139. | wolfCrypt ASN
  68140. *----------------------------------------------------------------------------*/
  68141. static int test_wc_CreateEncryptedPKCS8Key(void)
  68142. {
  68143. EXPECT_DECLS;
  68144. #if defined(HAVE_PKCS8) && !defined(NO_PWDBASED) && defined(WOLFSSL_AES_256) \
  68145. && !defined(NO_AES_CBC) && !defined(NO_RSA) && !defined(NO_SHA) && \
  68146. !defined(NO_ASN_CRYPT)
  68147. WC_RNG rng;
  68148. byte* encKey = NULL;
  68149. word32 encKeySz = 0;
  68150. word32 decKeySz = 0;
  68151. const char password[] = "Lorem ipsum dolor sit amet";
  68152. word32 passwordSz = (word32)XSTRLEN(password);
  68153. word32 tradIdx = 0;
  68154. XMEMSET(&rng, 0, sizeof(WC_RNG));
  68155. ExpectIntEQ(wc_InitRng(&rng), 0);
  68156. PRIVATE_KEY_UNLOCK();
  68157. /* Call with NULL for out buffer to get necessary length. */
  68158. ExpectIntEQ(wc_CreateEncryptedPKCS8Key((byte*)server_key_der_2048,
  68159. sizeof_server_key_der_2048, NULL, &encKeySz, password, (int)passwordSz,
  68160. PKCS5, PBES2, AES256CBCb, NULL, 0, WC_PKCS12_ITT_DEFAULT, &rng, NULL),
  68161. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  68162. ExpectNotNull(encKey = (byte*)XMALLOC(encKeySz, HEAP_HINT,
  68163. DYNAMIC_TYPE_TMP_BUFFER));
  68164. /* Call with the allocated out buffer. */
  68165. ExpectIntGT(wc_CreateEncryptedPKCS8Key((byte*)server_key_der_2048,
  68166. sizeof_server_key_der_2048, encKey, &encKeySz, password, (int)passwordSz,
  68167. PKCS5, PBES2, AES256CBCb, NULL, 0, WC_PKCS12_ITT_DEFAULT, &rng, NULL),
  68168. 0);
  68169. /* Decrypt the encrypted PKCS8 key we just made. */
  68170. ExpectIntGT((decKeySz = (word32)wc_DecryptPKCS8Key(encKey, encKeySz, password,
  68171. (int)passwordSz)), 0);
  68172. /* encKey now holds the decrypted key (decrypted in place). */
  68173. ExpectIntGT(wc_GetPkcs8TraditionalOffset(encKey, &tradIdx, decKeySz), 0);
  68174. /* Check that the decrypted key matches the key prior to encryption. */
  68175. ExpectIntEQ(XMEMCMP(encKey + tradIdx, server_key_der_2048,
  68176. sizeof_server_key_der_2048), 0);
  68177. PRIVATE_KEY_LOCK();
  68178. XFREE(encKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  68179. wc_FreeRng(&rng);
  68180. #endif
  68181. return EXPECT_RESULT();
  68182. }
  68183. static int test_wc_GetPkcs8TraditionalOffset(void)
  68184. {
  68185. EXPECT_DECLS;
  68186. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(HAVE_PKCS8)
  68187. int length;
  68188. int derSz = 0;
  68189. word32 inOutIdx;
  68190. const char* path = "./certs/server-keyPkcs8.der";
  68191. const char* pathAttributes = "./certs/ca-key-pkcs8-attribute.der";
  68192. XFILE file = XBADFILE;
  68193. byte der[2048];
  68194. ExpectTrue((file = XFOPEN(path, "rb")) != XBADFILE);
  68195. ExpectIntGT(derSz = (int)XFREAD(der, 1, sizeof(der), file), 0);
  68196. if (file != XBADFILE)
  68197. XFCLOSE(file);
  68198. file = XBADFILE; /* reset file to avoid warning of use after close */
  68199. /* valid case */
  68200. inOutIdx = 0;
  68201. ExpectIntGT(length = wc_GetPkcs8TraditionalOffset(der, &inOutIdx, (word32)derSz),
  68202. 0);
  68203. /* inOutIdx > sz */
  68204. inOutIdx = 4000;
  68205. ExpectIntEQ(length = wc_GetPkcs8TraditionalOffset(der, &inOutIdx, (word32)derSz),
  68206. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  68207. /* null input */
  68208. inOutIdx = 0;
  68209. ExpectIntEQ(length = wc_GetPkcs8TraditionalOffset(NULL, &inOutIdx, 0),
  68210. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  68211. /* invalid input, fill buffer with 1's */
  68212. XMEMSET(der, 1, sizeof(der));
  68213. inOutIdx = 0;
  68214. ExpectIntEQ(length = wc_GetPkcs8TraditionalOffset(der, &inOutIdx, (word32)derSz),
  68215. WC_NO_ERR_TRACE(ASN_PARSE_E));
  68216. /* test parsing with attributes */
  68217. ExpectTrue((file = XFOPEN(pathAttributes, "rb")) != XBADFILE);
  68218. ExpectIntGT(derSz = (int)XFREAD(der, 1, sizeof(der), file), 0);
  68219. if (file != XBADFILE)
  68220. XFCLOSE(file);
  68221. inOutIdx = 0;
  68222. ExpectIntGT(length = wc_GetPkcs8TraditionalOffset(der, &inOutIdx,
  68223. (word32)derSz), 0);
  68224. #endif /* NO_ASN */
  68225. return EXPECT_RESULT();
  68226. }
  68227. static int test_wc_SetSubjectRaw(void)
  68228. {
  68229. EXPECT_DECLS;
  68230. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  68231. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT) && !defined(NO_RSA)
  68232. const char* joiCertFile = "./certs/test/cert-ext-joi.der";
  68233. WOLFSSL_X509* x509 = NULL;
  68234. int peerCertSz;
  68235. const byte* peerCertBuf = NULL;
  68236. Cert forgedCert;
  68237. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(joiCertFile,
  68238. WOLFSSL_FILETYPE_ASN1));
  68239. ExpectNotNull(peerCertBuf = wolfSSL_X509_get_der(x509, &peerCertSz));
  68240. ExpectIntEQ(0, wc_InitCert(&forgedCert));
  68241. ExpectIntEQ(0, wc_SetSubjectRaw(&forgedCert, peerCertBuf, peerCertSz));
  68242. wolfSSL_FreeX509(x509);
  68243. #endif
  68244. return EXPECT_RESULT();
  68245. }
  68246. static int test_wc_GetSubjectRaw(void)
  68247. {
  68248. EXPECT_DECLS;
  68249. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  68250. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT)
  68251. Cert cert;
  68252. byte *subjectRaw;
  68253. ExpectIntEQ(0, wc_InitCert(&cert));
  68254. ExpectIntEQ(0, wc_GetSubjectRaw(&subjectRaw, &cert));
  68255. #endif
  68256. return EXPECT_RESULT();
  68257. }
  68258. static int test_wc_SetIssuerRaw(void)
  68259. {
  68260. EXPECT_DECLS;
  68261. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  68262. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT) && !defined(NO_RSA)
  68263. const char* joiCertFile = "./certs/test/cert-ext-joi.der";
  68264. WOLFSSL_X509* x509 = NULL;
  68265. int peerCertSz;
  68266. const byte* peerCertBuf;
  68267. Cert forgedCert;
  68268. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(joiCertFile,
  68269. WOLFSSL_FILETYPE_ASN1));
  68270. ExpectNotNull(peerCertBuf = wolfSSL_X509_get_der(x509, &peerCertSz));
  68271. ExpectIntEQ(0, wc_InitCert(&forgedCert));
  68272. ExpectIntEQ(0, wc_SetIssuerRaw(&forgedCert, peerCertBuf, peerCertSz));
  68273. wolfSSL_FreeX509(x509);
  68274. #endif
  68275. return EXPECT_RESULT();
  68276. }
  68277. static int test_wc_SetIssueBuffer(void)
  68278. {
  68279. EXPECT_DECLS;
  68280. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  68281. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT) && !defined(NO_RSA)
  68282. const char* joiCertFile = "./certs/test/cert-ext-joi.der";
  68283. WOLFSSL_X509* x509 = NULL;
  68284. int peerCertSz;
  68285. const byte* peerCertBuf;
  68286. Cert forgedCert;
  68287. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(joiCertFile,
  68288. WOLFSSL_FILETYPE_ASN1));
  68289. ExpectNotNull(peerCertBuf = wolfSSL_X509_get_der(x509, &peerCertSz));
  68290. ExpectIntEQ(0, wc_InitCert(&forgedCert));
  68291. ExpectIntEQ(0, wc_SetIssuerBuffer(&forgedCert, peerCertBuf, peerCertSz));
  68292. wolfSSL_FreeX509(x509);
  68293. #endif
  68294. return EXPECT_RESULT();
  68295. }
  68296. /*
  68297. * Testing wc_SetSubjectKeyId
  68298. */
  68299. static int test_wc_SetSubjectKeyId(void)
  68300. {
  68301. EXPECT_DECLS;
  68302. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  68303. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT) && defined(HAVE_ECC)
  68304. Cert cert;
  68305. const char* file = "certs/ecc-client-keyPub.pem";
  68306. ExpectIntEQ(0, wc_InitCert(&cert));
  68307. ExpectIntEQ(0, wc_SetSubjectKeyId(&cert, file));
  68308. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SetSubjectKeyId(NULL, file));
  68309. ExpectIntGT(0, wc_SetSubjectKeyId(&cert, "badfile.name"));
  68310. #endif
  68311. return EXPECT_RESULT();
  68312. } /* END test_wc_SetSubjectKeyId */
  68313. /*
  68314. * Testing wc_SetSubject
  68315. */
  68316. static int test_wc_SetSubject(void)
  68317. {
  68318. EXPECT_DECLS;
  68319. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  68320. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT) && defined(HAVE_ECC)
  68321. Cert cert;
  68322. const char* file = "./certs/ca-ecc-cert.pem";
  68323. ExpectIntEQ(0, wc_InitCert(&cert));
  68324. ExpectIntEQ(0, wc_SetSubject(&cert, file));
  68325. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SetSubject(NULL, file));
  68326. ExpectIntGT(0, wc_SetSubject(&cert, "badfile.name"));
  68327. #endif
  68328. return EXPECT_RESULT();
  68329. } /* END test_wc_SetSubject */
  68330. static int test_CheckCertSignature(void)
  68331. {
  68332. EXPECT_DECLS;
  68333. #if !defined(NO_CERTS) && defined(WOLFSSL_SMALL_CERT_VERIFY)
  68334. WOLFSSL_CERT_MANAGER* cm = NULL;
  68335. #if !defined(NO_FILESYSTEM) && (!defined(NO_RSA) || defined(HAVE_ECC))
  68336. XFILE fp = XBADFILE;
  68337. byte cert[4096];
  68338. int certSz;
  68339. #endif
  68340. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_CheckCertSignature(NULL, 0, NULL, NULL));
  68341. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  68342. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_CheckCertSignature(NULL, 0, NULL, cm));
  68343. #ifndef NO_RSA
  68344. #ifdef USE_CERT_BUFFERS_1024
  68345. ExpectIntEQ(WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), wc_CheckCertSignature(server_cert_der_1024,
  68346. sizeof_server_cert_der_1024, NULL, cm));
  68347. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCABuffer(cm,
  68348. ca_cert_der_1024, sizeof_ca_cert_der_1024,
  68349. WOLFSSL_FILETYPE_ASN1));
  68350. ExpectIntEQ(0, wc_CheckCertSignature(server_cert_der_1024,
  68351. sizeof_server_cert_der_1024, NULL, cm));
  68352. #elif defined(USE_CERT_BUFFERS_2048)
  68353. ExpectIntEQ(WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), wc_CheckCertSignature(server_cert_der_2048,
  68354. sizeof_server_cert_der_2048, NULL, cm));
  68355. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCABuffer(cm,
  68356. ca_cert_der_2048, sizeof_ca_cert_der_2048,
  68357. WOLFSSL_FILETYPE_ASN1));
  68358. ExpectIntEQ(0, wc_CheckCertSignature(server_cert_der_2048,
  68359. sizeof_server_cert_der_2048, NULL, cm));
  68360. #endif
  68361. #endif
  68362. #if defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  68363. ExpectIntEQ(WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), wc_CheckCertSignature(serv_ecc_der_256,
  68364. sizeof_serv_ecc_der_256, NULL, cm));
  68365. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCABuffer(cm,
  68366. ca_ecc_cert_der_256, sizeof_ca_ecc_cert_der_256,
  68367. WOLFSSL_FILETYPE_ASN1));
  68368. ExpectIntEQ(0, wc_CheckCertSignature(serv_ecc_der_256, sizeof_serv_ecc_der_256,
  68369. NULL, cm));
  68370. #endif
  68371. #if !defined(NO_FILESYSTEM)
  68372. wolfSSL_CertManagerFree(cm);
  68373. cm = NULL;
  68374. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  68375. #ifndef NO_RSA
  68376. ExpectTrue((fp = XFOPEN("./certs/server-cert.der", "rb")) != XBADFILE);
  68377. ExpectIntGT((certSz = (int)XFREAD(cert, 1, sizeof(cert), fp)), 0);
  68378. if (fp != XBADFILE) {
  68379. XFCLOSE(fp);
  68380. fp = XBADFILE;
  68381. }
  68382. ExpectIntEQ(WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), wc_CheckCertSignature(cert, certSz, NULL, cm));
  68383. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCA(cm,
  68384. "./certs/ca-cert.pem", NULL));
  68385. ExpectIntEQ(0, wc_CheckCertSignature(cert, certSz, NULL, cm));
  68386. #endif
  68387. #ifdef HAVE_ECC
  68388. ExpectTrue((fp = XFOPEN("./certs/server-ecc.der", "rb")) != XBADFILE);
  68389. ExpectIntGT((certSz = (int)XFREAD(cert, 1, sizeof(cert), fp)), 0);
  68390. if (fp != XBADFILE) {
  68391. XFCLOSE(fp);
  68392. fp = XBADFILE;
  68393. }
  68394. ExpectIntEQ(WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), wc_CheckCertSignature(cert, certSz, NULL, cm));
  68395. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCA(cm,
  68396. "./certs/ca-ecc-cert.pem", NULL));
  68397. ExpectIntEQ(0, wc_CheckCertSignature(cert, certSz, NULL, cm));
  68398. #endif
  68399. #endif
  68400. #if !defined(NO_FILESYSTEM) && (!defined(NO_RSA) || defined(HAVE_ECC))
  68401. (void)fp;
  68402. (void)cert;
  68403. (void)certSz;
  68404. #endif
  68405. wolfSSL_CertManagerFree(cm);
  68406. #endif
  68407. return EXPECT_RESULT();
  68408. }
  68409. static int test_wc_ParseCert(void)
  68410. {
  68411. EXPECT_DECLS;
  68412. #if !defined(NO_CERTS) && !defined(NO_RSA)
  68413. DecodedCert decodedCert;
  68414. const byte* rawCert = client_cert_der_2048;
  68415. const int rawCertSize = sizeof_client_cert_der_2048;
  68416. wc_InitDecodedCert(&decodedCert, rawCert, rawCertSize, NULL);
  68417. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL), 0);
  68418. #ifndef IGNORE_NAME_CONSTRAINTS
  68419. /* check that the subjects emailAddress was not put in the alt name list */
  68420. ExpectNotNull(decodedCert.subjectEmail);
  68421. ExpectNull(decodedCert.altEmailNames);
  68422. #endif
  68423. wc_FreeDecodedCert(&decodedCert);
  68424. #endif
  68425. return EXPECT_RESULT();
  68426. }
  68427. /* Test wc_ParseCert decoding of various encodings and scenarios ensuring that
  68428. * the API safely errors out on badly-formed ASN input.
  68429. * NOTE: Test not compatible with released FIPS implementations!
  68430. */
  68431. static int test_wc_ParseCert_Error(void)
  68432. {
  68433. EXPECT_DECLS;
  68434. #if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(HAVE_SELFTEST) && \
  68435. (!defined(HAVE_FIPS) || \
  68436. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  68437. DecodedCert decodedCert;
  68438. int i;
  68439. /* Certificate data */
  68440. const byte c0[] = { 0x30, 0x04, 0x30, 0x02, 0x02, 0x80, 0x00, 0x00};
  68441. const byte c1[] = { 0x30, 0x04, 0x30, 0x04, 0x02, 0x80, 0x00, 0x00};
  68442. const byte c2[] = { 0x30, 0x06, 0x30, 0x04, 0x02, 0x80, 0x00, 0x00};
  68443. const byte c3[] = { 0x30, 0x07, 0x30, 0x05, 0x02, 0x80, 0x10, 0x00, 0x00};
  68444. const byte c4[] = { 0x02, 0x80, 0x10, 0x00, 0x00};
  68445. /* Test data */
  68446. const struct testStruct {
  68447. const byte* c;
  68448. const int cSz;
  68449. const int expRet;
  68450. } t[] = {
  68451. {c0, sizeof(c0), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Invalid bit-string length */
  68452. {c1, sizeof(c1), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Invalid bit-string length */
  68453. {c2, sizeof(c2), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Invalid integer length (zero) */
  68454. {c3, sizeof(c3), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Valid INTEGER, but buffer too short */
  68455. {c4, sizeof(c4), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Valid INTEGER, but not in bit-string */
  68456. };
  68457. const int tSz = (int)(sizeof(t) / sizeof(struct testStruct));
  68458. for (i = 0; i < tSz; i++) {
  68459. WOLFSSL_MSG_EX("i == %d", i);
  68460. wc_InitDecodedCert(&decodedCert, t[i].c, t[i].cSz, NULL);
  68461. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL), t[i].expRet);
  68462. wc_FreeDecodedCert(&decodedCert);
  68463. }
  68464. #endif
  68465. return EXPECT_RESULT();
  68466. }
  68467. static int test_MakeCertWithPathLen(void)
  68468. {
  68469. EXPECT_DECLS;
  68470. #if defined(WOLFSSL_CERT_REQ) && !defined(NO_ASN_TIME) && \
  68471. defined(WOLFSSL_CERT_GEN) && defined(HAVE_ECC)
  68472. const byte expectedPathLen = 7;
  68473. Cert cert;
  68474. DecodedCert decodedCert;
  68475. byte der[FOURK_BUF];
  68476. int derSize = 0;
  68477. WC_RNG rng;
  68478. ecc_key key;
  68479. int ret;
  68480. XMEMSET(&rng, 0, sizeof(WC_RNG));
  68481. XMEMSET(&key, 0, sizeof(ecc_key));
  68482. XMEMSET(&cert, 0, sizeof(Cert));
  68483. XMEMSET(&decodedCert, 0, sizeof(DecodedCert));
  68484. ExpectIntEQ(wc_InitRng(&rng), 0);
  68485. ExpectIntEQ(wc_ecc_init(&key), 0);
  68486. ExpectIntEQ(wc_ecc_make_key(&rng, 32, &key), 0);
  68487. ExpectIntEQ(wc_InitCert(&cert), 0);
  68488. (void)XSTRNCPY(cert.subject.country, "US", CTC_NAME_SIZE);
  68489. (void)XSTRNCPY(cert.subject.state, "state", CTC_NAME_SIZE);
  68490. (void)XSTRNCPY(cert.subject.locality, "Bozeman", CTC_NAME_SIZE);
  68491. (void)XSTRNCPY(cert.subject.org, "yourOrgNameHere", CTC_NAME_SIZE);
  68492. (void)XSTRNCPY(cert.subject.unit, "yourUnitNameHere", CTC_NAME_SIZE);
  68493. (void)XSTRNCPY(cert.subject.commonName, "www.yourDomain.com",
  68494. CTC_NAME_SIZE);
  68495. (void)XSTRNCPY(cert.subject.email, "yourEmail@yourDomain.com",
  68496. CTC_NAME_SIZE);
  68497. cert.selfSigned = 1;
  68498. cert.isCA = 1;
  68499. cert.pathLen = expectedPathLen;
  68500. cert.pathLenSet = 1;
  68501. cert.sigType = CTC_SHA256wECDSA;
  68502. #ifdef WOLFSSL_CERT_EXT
  68503. cert.keyUsage |= KEYUSE_KEY_CERT_SIGN;
  68504. #endif
  68505. ExpectIntGE(wc_MakeCert(&cert, der, FOURK_BUF, NULL, &key, &rng), 0);
  68506. ExpectIntGE(derSize = wc_SignCert(cert.bodySz, cert.sigType, der,
  68507. FOURK_BUF, NULL, &key, &rng), 0);
  68508. wc_InitDecodedCert(&decodedCert, der, (word32)derSize, NULL);
  68509. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL), 0);
  68510. ExpectIntEQ(decodedCert.pathLength, expectedPathLen);
  68511. wc_FreeDecodedCert(&decodedCert);
  68512. ret = wc_ecc_free(&key);
  68513. ExpectIntEQ(ret, 0);
  68514. ret = wc_FreeRng(&rng);
  68515. ExpectIntEQ(ret, 0);
  68516. #endif
  68517. return EXPECT_RESULT();
  68518. }
  68519. static int test_MakeCertWith0Ser(void)
  68520. {
  68521. EXPECT_DECLS;
  68522. #if defined(WOLFSSL_CERT_REQ) && !defined(NO_ASN_TIME) && \
  68523. defined(WOLFSSL_CERT_GEN) && defined(HAVE_ECC) && \
  68524. defined(WOLFSSL_ASN_TEMPLATE)
  68525. Cert cert;
  68526. DecodedCert decodedCert;
  68527. byte der[FOURK_BUF];
  68528. int derSize = 0;
  68529. WC_RNG rng;
  68530. ecc_key key;
  68531. int ret;
  68532. XMEMSET(&rng, 0, sizeof(WC_RNG));
  68533. XMEMSET(&key, 0, sizeof(ecc_key));
  68534. XMEMSET(&cert, 0, sizeof(Cert));
  68535. XMEMSET(&decodedCert, 0, sizeof(DecodedCert));
  68536. ExpectIntEQ(wc_InitRng(&rng), 0);
  68537. ExpectIntEQ(wc_ecc_init(&key), 0);
  68538. ExpectIntEQ(wc_ecc_make_key(&rng, 32, &key), 0);
  68539. ExpectIntEQ(wc_InitCert(&cert), 0);
  68540. (void)XSTRNCPY(cert.subject.country, "US", CTC_NAME_SIZE);
  68541. (void)XSTRNCPY(cert.subject.state, "state", CTC_NAME_SIZE);
  68542. (void)XSTRNCPY(cert.subject.locality, "Bozeman", CTC_NAME_SIZE);
  68543. (void)XSTRNCPY(cert.subject.org, "yourOrgNameHere", CTC_NAME_SIZE);
  68544. (void)XSTRNCPY(cert.subject.unit, "yourUnitNameHere", CTC_NAME_SIZE);
  68545. (void)XSTRNCPY(cert.subject.commonName, "www.yourDomain.com",
  68546. CTC_NAME_SIZE);
  68547. (void)XSTRNCPY(cert.subject.email, "yourEmail@yourDomain.com",
  68548. CTC_NAME_SIZE);
  68549. cert.selfSigned = 1;
  68550. cert.isCA = 1;
  68551. cert.sigType = CTC_SHA256wECDSA;
  68552. #ifdef WOLFSSL_CERT_EXT
  68553. cert.keyUsage |= KEYUSE_KEY_CERT_SIGN;
  68554. #endif
  68555. /* set serial number to 0 */
  68556. cert.serialSz = 1;
  68557. cert.serial[0] = 0;
  68558. ExpectIntGE(wc_MakeCert(&cert, der, FOURK_BUF, NULL, &key, &rng), 0);
  68559. ExpectIntGE(derSize = wc_SignCert(cert.bodySz, cert.sigType, der,
  68560. FOURK_BUF, NULL, &key, &rng), 0);
  68561. wc_InitDecodedCert(&decodedCert, der, (word32)derSize, NULL);
  68562. #if !defined(WOLFSSL_NO_ASN_STRICT) && !defined(WOLFSSL_PYTHON)
  68563. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL),
  68564. WC_NO_ERR_TRACE(ASN_PARSE_E));
  68565. #else
  68566. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL), 0);
  68567. #endif
  68568. wc_FreeDecodedCert(&decodedCert);
  68569. ret = wc_ecc_free(&key);
  68570. ExpectIntEQ(ret, 0);
  68571. ret = wc_FreeRng(&rng);
  68572. ExpectIntEQ(ret, 0);
  68573. #endif
  68574. return EXPECT_RESULT();
  68575. }
  68576. static int test_MakeCertWithCaFalse(void)
  68577. {
  68578. EXPECT_DECLS;
  68579. #if defined(WOLFSSL_ALLOW_ENCODING_CA_FALSE) && defined(WOLFSSL_CERT_REQ) && \
  68580. !defined(NO_ASN_TIME) && defined(WOLFSSL_CERT_GEN) && defined(HAVE_ECC)
  68581. const byte expectedIsCa = 0;
  68582. Cert cert;
  68583. DecodedCert decodedCert;
  68584. byte der[FOURK_BUF];
  68585. int derSize = 0;
  68586. WC_RNG rng;
  68587. ecc_key key;
  68588. int ret;
  68589. XMEMSET(&rng, 0, sizeof(WC_RNG));
  68590. XMEMSET(&key, 0, sizeof(ecc_key));
  68591. XMEMSET(&cert, 0, sizeof(Cert));
  68592. XMEMSET(&decodedCert, 0, sizeof(DecodedCert));
  68593. ExpectIntEQ(wc_InitRng(&rng), 0);
  68594. ExpectIntEQ(wc_ecc_init(&key), 0);
  68595. ExpectIntEQ(wc_ecc_make_key(&rng, 32, &key), 0);
  68596. ExpectIntEQ(wc_InitCert(&cert), 0);
  68597. (void)XSTRNCPY(cert.subject.country, "US", CTC_NAME_SIZE);
  68598. (void)XSTRNCPY(cert.subject.state, "state", CTC_NAME_SIZE);
  68599. (void)XSTRNCPY(cert.subject.locality, "Bozeman", CTC_NAME_SIZE);
  68600. (void)XSTRNCPY(cert.subject.org, "yourOrgNameHere", CTC_NAME_SIZE);
  68601. (void)XSTRNCPY(cert.subject.unit, "yourUnitNameHere", CTC_NAME_SIZE);
  68602. (void)XSTRNCPY(cert.subject.commonName, "www.yourDomain.com",
  68603. CTC_NAME_SIZE);
  68604. (void)XSTRNCPY(cert.subject.email, "yourEmail@yourDomain.com",
  68605. CTC_NAME_SIZE);
  68606. cert.selfSigned = 1;
  68607. cert.isCA = expectedIsCa;
  68608. cert.isCaSet = 1;
  68609. cert.sigType = CTC_SHA256wECDSA;
  68610. ExpectIntGE(wc_MakeCert(&cert, der, FOURK_BUF, NULL, &key, &rng), 0);
  68611. ExpectIntGE(derSize = wc_SignCert(cert.bodySz, cert.sigType, der,
  68612. FOURK_BUF, NULL, &key, &rng), 0);
  68613. wc_InitDecodedCert(&decodedCert, der, derSize, NULL);
  68614. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL), 0);
  68615. ExpectIntEQ(decodedCert.isCA, expectedIsCa);
  68616. wc_FreeDecodedCert(&decodedCert);
  68617. ret = wc_ecc_free(&key);
  68618. ExpectIntEQ(ret, 0);
  68619. ret = wc_FreeRng(&rng);
  68620. ExpectIntEQ(ret, 0);
  68621. #endif
  68622. return EXPECT_RESULT();
  68623. }
  68624. /*----------------------------------------------------------------------------*
  68625. | wolfCrypt ECC
  68626. *----------------------------------------------------------------------------*/
  68627. static int test_wc_ecc_get_curve_size_from_name(void)
  68628. {
  68629. EXPECT_DECLS;
  68630. #ifdef HAVE_ECC
  68631. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  68632. ExpectIntEQ(wc_ecc_get_curve_size_from_name("SECP256R1"), 32);
  68633. #endif
  68634. /* invalid case */
  68635. ExpectIntEQ(wc_ecc_get_curve_size_from_name("BADCURVE"), -1);
  68636. /* NULL input */
  68637. ExpectIntEQ(wc_ecc_get_curve_size_from_name(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  68638. #endif /* HAVE_ECC */
  68639. return EXPECT_RESULT();
  68640. }
  68641. static int test_wc_ecc_get_curve_id_from_name(void)
  68642. {
  68643. EXPECT_DECLS;
  68644. #ifdef HAVE_ECC
  68645. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  68646. ExpectIntEQ(wc_ecc_get_curve_id_from_name("SECP256R1"),
  68647. ECC_SECP256R1);
  68648. #endif
  68649. /* invalid case */
  68650. ExpectIntEQ(wc_ecc_get_curve_id_from_name("BADCURVE"), -1);
  68651. /* NULL input */
  68652. ExpectIntEQ(wc_ecc_get_curve_id_from_name(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  68653. #endif /* HAVE_ECC */
  68654. return EXPECT_RESULT();
  68655. }
  68656. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && \
  68657. !defined(HAVE_SELFTEST) && \
  68658. !(defined(HAVE_FIPS) || defined(HAVE_FIPS_VERSION))
  68659. static int test_wc_ecc_get_curve_id_from_dp_params(void)
  68660. {
  68661. EXPECT_DECLS;
  68662. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  68663. ecc_key* key;
  68664. const ecc_set_type* params = NULL;
  68665. int ret;
  68666. #endif
  68667. WOLFSSL_EC_KEY *ecKey = NULL;
  68668. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  68669. ExpectIntEQ(wc_ecc_get_curve_id_from_name("SECP256R1"), ECC_SECP256R1);
  68670. ExpectNotNull(ecKey = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  68671. if (EXPECT_SUCCESS()) {
  68672. ret = EC_KEY_generate_key(ecKey);
  68673. } else
  68674. ret = 0;
  68675. if (ret == 1) {
  68676. /* normal test */
  68677. key = (ecc_key*)ecKey->internal;
  68678. if (key != NULL) {
  68679. params = key->dp;
  68680. }
  68681. ExpectIntEQ(wc_ecc_get_curve_id_from_dp_params(params),
  68682. ECC_SECP256R1);
  68683. }
  68684. #endif
  68685. /* invalid case, NULL input*/
  68686. ExpectIntEQ(wc_ecc_get_curve_id_from_dp_params(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  68687. wolfSSL_EC_KEY_free(ecKey);
  68688. return EXPECT_RESULT();
  68689. }
  68690. #endif /* defined(OPENSSL_EXTRA) && defined(HAVE_ECC) */
  68691. static int test_wc_ecc_get_curve_id_from_params(void)
  68692. {
  68693. EXPECT_DECLS;
  68694. #ifdef HAVE_ECC
  68695. const byte prime[] =
  68696. {
  68697. 0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x01,
  68698. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  68699. 0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,
  68700. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
  68701. };
  68702. const byte primeInvalid[] =
  68703. {
  68704. 0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x01,
  68705. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  68706. 0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,
  68707. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,0x01
  68708. };
  68709. const byte Af[] =
  68710. {
  68711. 0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x01,
  68712. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  68713. 0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,
  68714. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC
  68715. };
  68716. const byte Bf[] =
  68717. {
  68718. 0x5A,0xC6,0x35,0xD8,0xAA,0x3A,0x93,0xE7,
  68719. 0xB3,0xEB,0xBD,0x55,0x76,0x98,0x86,0xBC,
  68720. 0x65,0x1D,0x06,0xB0,0xCC,0x53,0xB0,0xF6,
  68721. 0x3B,0xCE,0x3C,0x3E,0x27,0xD2,0x60,0x4B
  68722. };
  68723. const byte order[] =
  68724. {
  68725. 0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,
  68726. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  68727. 0xBC,0xE6,0xFA,0xAD,0xA7,0x17,0x9E,0x84,
  68728. 0xF3,0xB9,0xCA,0xC2,0xFC,0x63,0x25,0x51
  68729. };
  68730. const byte Gx[] =
  68731. {
  68732. 0x6B,0x17,0xD1,0xF2,0xE1,0x2C,0x42,0x47,
  68733. 0xF8,0xBC,0xE6,0xE5,0x63,0xA4,0x40,0xF2,
  68734. 0x77,0x03,0x7D,0x81,0x2D,0xEB,0x33,0xA0,
  68735. 0xF4,0xA1,0x39,0x45,0xD8,0x98,0xC2,0x96
  68736. };
  68737. const byte Gy[] =
  68738. {
  68739. 0x4F,0xE3,0x42,0xE2,0xFE,0x1A,0x7F,0x9B,
  68740. 0x8E,0xE7,0xEB,0x4A,0x7C,0x0F,0x9E,0x16,
  68741. 0x2B,0xCE,0x33,0x57,0x6B,0x31,0x5E,0xCE,
  68742. 0xCB,0xB6,0x40,0x68,0x37,0xBF,0x51,0xF5
  68743. };
  68744. int cofactor = 1;
  68745. int fieldSize = 256;
  68746. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  68747. ExpectIntEQ(wc_ecc_get_curve_id_from_params(fieldSize,
  68748. prime, sizeof(prime), Af, sizeof(Af), Bf, sizeof(Bf),
  68749. order, sizeof(order), Gx, sizeof(Gx), Gy, sizeof(Gy), cofactor),
  68750. ECC_SECP256R1);
  68751. #endif
  68752. /* invalid case, fieldSize = 0 */
  68753. ExpectIntEQ(wc_ecc_get_curve_id_from_params(0, prime, sizeof(prime),
  68754. Af, sizeof(Af), Bf, sizeof(Bf), order, sizeof(order),
  68755. Gx, sizeof(Gx), Gy, sizeof(Gy), cofactor), ECC_CURVE_INVALID);
  68756. /* invalid case, NULL prime */
  68757. ExpectIntEQ(wc_ecc_get_curve_id_from_params(fieldSize, NULL, sizeof(prime),
  68758. Af, sizeof(Af), Bf, sizeof(Bf), order, sizeof(order),
  68759. Gx, sizeof(Gx), Gy, sizeof(Gy), cofactor), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  68760. /* invalid case, invalid prime */
  68761. ExpectIntEQ(wc_ecc_get_curve_id_from_params(fieldSize,
  68762. primeInvalid, sizeof(primeInvalid),
  68763. Af, sizeof(Af), Bf, sizeof(Bf), order, sizeof(order),
  68764. Gx, sizeof(Gx), Gy, sizeof(Gy), cofactor), ECC_CURVE_INVALID);
  68765. #endif
  68766. return EXPECT_RESULT();
  68767. }
  68768. static int test_wolfSSL_EVP_PKEY_encrypt(void)
  68769. {
  68770. EXPECT_DECLS;
  68771. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  68772. WOLFSSL_RSA* rsa = NULL;
  68773. WOLFSSL_EVP_PKEY* pkey = NULL;
  68774. WOLFSSL_EVP_PKEY_CTX* ctx = NULL;
  68775. const char* in = "What is easy to do is easy not to do.";
  68776. size_t inlen = XSTRLEN(in);
  68777. size_t outEncLen = 0;
  68778. byte* outEnc = NULL;
  68779. byte* outDec = NULL;
  68780. size_t outDecLen = 0;
  68781. size_t rsaKeySz = 2048/8; /* Bytes */
  68782. #if !defined(HAVE_FIPS) && defined(WC_RSA_NO_PADDING)
  68783. byte* inTmp = NULL;
  68784. byte* outEncTmp = NULL;
  68785. byte* outDecTmp = NULL;
  68786. #endif
  68787. ExpectNotNull(outEnc = (byte*)XMALLOC(rsaKeySz, HEAP_HINT,
  68788. DYNAMIC_TYPE_TMP_BUFFER));
  68789. if (outEnc != NULL) {
  68790. XMEMSET(outEnc, 0, rsaKeySz);
  68791. }
  68792. ExpectNotNull(outDec = (byte*)XMALLOC(rsaKeySz, HEAP_HINT,
  68793. DYNAMIC_TYPE_TMP_BUFFER));
  68794. if (outDec != NULL) {
  68795. XMEMSET(outDec, 0, rsaKeySz);
  68796. }
  68797. ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  68798. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  68799. ExpectIntEQ(EVP_PKEY_assign_RSA(pkey, rsa), WOLFSSL_SUCCESS);
  68800. if (EXPECT_FAIL()) {
  68801. RSA_free(rsa);
  68802. }
  68803. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  68804. ExpectIntEQ(EVP_PKEY_encrypt_init(ctx), WOLFSSL_SUCCESS);
  68805. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING),
  68806. WOLFSSL_SUCCESS);
  68807. /* Test pkey references count is decremented. pkey shouldn't be destroyed
  68808. since ctx uses it.*/
  68809. ExpectIntEQ(pkey->ref.count, 2);
  68810. EVP_PKEY_free(pkey);
  68811. ExpectIntEQ(pkey->ref.count, 1);
  68812. /* Encrypt data */
  68813. /* Check that we can get the required output buffer length by passing in a
  68814. * NULL output buffer. */
  68815. ExpectIntEQ(EVP_PKEY_encrypt(ctx, NULL, &outEncLen,
  68816. (const unsigned char*)in, inlen), WOLFSSL_SUCCESS);
  68817. ExpectIntEQ(rsaKeySz, outEncLen);
  68818. /* Now do the actual encryption. */
  68819. ExpectIntEQ(EVP_PKEY_encrypt(ctx, outEnc, &outEncLen,
  68820. (const unsigned char*)in, inlen), WOLFSSL_SUCCESS);
  68821. /* Decrypt data */
  68822. ExpectIntEQ(EVP_PKEY_decrypt_init(ctx), WOLFSSL_SUCCESS);
  68823. /* Check that we can get the required output buffer length by passing in a
  68824. * NULL output buffer. */
  68825. ExpectIntEQ(EVP_PKEY_decrypt(ctx, NULL, &outDecLen, outEnc, outEncLen),
  68826. WOLFSSL_SUCCESS);
  68827. ExpectIntEQ(rsaKeySz, outDecLen);
  68828. /* Now do the actual decryption. */
  68829. ExpectIntEQ(EVP_PKEY_decrypt(ctx, outDec, &outDecLen, outEnc, outEncLen),
  68830. WOLFSSL_SUCCESS);
  68831. ExpectIntEQ(XMEMCMP(in, outDec, outDecLen), 0);
  68832. #if !defined(HAVE_FIPS) && defined(WC_RSA_NO_PADDING)
  68833. /* The input length must be the same size as the RSA key.*/
  68834. ExpectNotNull(inTmp = (byte*)XMALLOC(rsaKeySz, HEAP_HINT,
  68835. DYNAMIC_TYPE_TMP_BUFFER));
  68836. if (inTmp != NULL) {
  68837. XMEMSET(inTmp, 9, rsaKeySz);
  68838. }
  68839. ExpectNotNull(outEncTmp = (byte*)XMALLOC(rsaKeySz, HEAP_HINT,
  68840. DYNAMIC_TYPE_TMP_BUFFER));
  68841. if (outEncTmp != NULL) {
  68842. XMEMSET(outEncTmp, 0, rsaKeySz);
  68843. }
  68844. ExpectNotNull(outDecTmp = (byte*)XMALLOC(rsaKeySz, HEAP_HINT,
  68845. DYNAMIC_TYPE_TMP_BUFFER));
  68846. if (outDecTmp != NULL) {
  68847. XMEMSET(outDecTmp, 0, rsaKeySz);
  68848. }
  68849. ExpectIntEQ(EVP_PKEY_encrypt_init(ctx), WOLFSSL_SUCCESS);
  68850. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_NO_PADDING),
  68851. WOLFSSL_SUCCESS);
  68852. ExpectIntEQ(EVP_PKEY_encrypt(ctx, outEncTmp, &outEncLen, inTmp, rsaKeySz),
  68853. WOLFSSL_SUCCESS);
  68854. ExpectIntEQ(EVP_PKEY_decrypt_init(ctx), WOLFSSL_SUCCESS);
  68855. ExpectIntEQ(EVP_PKEY_decrypt(ctx, outDecTmp, &outDecLen, outEncTmp,
  68856. outEncLen), WOLFSSL_SUCCESS);
  68857. ExpectIntEQ(XMEMCMP(inTmp, outDecTmp, outDecLen), 0);
  68858. #endif
  68859. EVP_PKEY_CTX_free(ctx);
  68860. XFREE(outEnc, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  68861. XFREE(outDec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  68862. #if !defined(HAVE_FIPS) && defined(WC_RSA_NO_PADDING)
  68863. XFREE(inTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  68864. XFREE(outEncTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  68865. XFREE(outDecTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  68866. #endif
  68867. #endif
  68868. return EXPECT_RESULT();
  68869. }
  68870. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  68871. !defined(HAVE_SELFTEST)
  68872. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68873. #ifndef TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  68874. #define TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  68875. #endif
  68876. #endif
  68877. #endif
  68878. #if defined(OPENSSL_EXTRA)
  68879. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  68880. #ifndef TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  68881. #define TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  68882. #endif
  68883. #endif
  68884. #endif
  68885. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  68886. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68887. #ifndef TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  68888. #define TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  68889. #endif
  68890. #endif
  68891. #endif
  68892. #ifdef TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  68893. static int test_wolfSSL_EVP_PKEY_sign_verify(int keyType)
  68894. {
  68895. EXPECT_DECLS;
  68896. #if defined(OPENSSL_EXTRA)
  68897. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  68898. !defined(HAVE_SELFTEST)
  68899. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68900. WOLFSSL_RSA* rsa = NULL;
  68901. #endif
  68902. #endif
  68903. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  68904. WOLFSSL_DSA* dsa = NULL;
  68905. #endif /* !NO_DSA && !HAVE_SELFTEST && WOLFSSL_KEY_GEN */
  68906. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  68907. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68908. WOLFSSL_EC_KEY* ecKey = NULL;
  68909. #endif
  68910. #endif
  68911. WOLFSSL_EVP_PKEY* pkey = NULL;
  68912. WOLFSSL_EVP_PKEY_CTX* ctx = NULL;
  68913. WOLFSSL_EVP_PKEY_CTX* ctx_verify = NULL;
  68914. const char* in = "What is easy to do is easy not to do.";
  68915. size_t inlen = XSTRLEN(in);
  68916. byte hash[SHA256_DIGEST_LENGTH] = {0};
  68917. byte zero[SHA256_DIGEST_LENGTH] = {0};
  68918. SHA256_CTX c;
  68919. byte* sig = NULL;
  68920. byte* sigVerify = NULL;
  68921. size_t siglen;
  68922. size_t siglenOnlyLen;
  68923. size_t keySz = 2048/8; /* Bytes */
  68924. ExpectNotNull(sig =
  68925. (byte*)XMALLOC(keySz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER));
  68926. ExpectNotNull(sigVerify =
  68927. (byte*)XMALLOC(keySz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER));
  68928. siglen = keySz;
  68929. ExpectNotNull(XMEMSET(sig, 0, keySz));
  68930. ExpectNotNull(XMEMSET(sigVerify, 0, keySz));
  68931. /* Generate hash */
  68932. SHA256_Init(&c);
  68933. SHA256_Update(&c, in, inlen);
  68934. SHA256_Final(hash, &c);
  68935. #ifdef WOLFSSL_SMALL_STACK_CACHE
  68936. /* workaround for small stack cache case */
  68937. wc_Sha256Free((wc_Sha256*)&c);
  68938. #endif
  68939. /* Generate key */
  68940. ExpectNotNull(pkey = EVP_PKEY_new());
  68941. switch (keyType) {
  68942. case EVP_PKEY_RSA:
  68943. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  68944. !defined(HAVE_SELFTEST)
  68945. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68946. {
  68947. ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  68948. ExpectIntEQ(EVP_PKEY_assign_RSA(pkey, rsa), WOLFSSL_SUCCESS);
  68949. }
  68950. #endif
  68951. #endif
  68952. break;
  68953. case EVP_PKEY_DSA:
  68954. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  68955. ExpectNotNull(dsa = DSA_new());
  68956. ExpectIntEQ(DSA_generate_parameters_ex(dsa, 2048,
  68957. NULL, 0, NULL, NULL, NULL), 1);
  68958. ExpectIntEQ(DSA_generate_key(dsa), 1);
  68959. ExpectIntEQ(EVP_PKEY_set1_DSA(pkey, dsa), WOLFSSL_SUCCESS);
  68960. #endif /* !NO_DSA && !HAVE_SELFTEST && WOLFSSL_KEY_GEN */
  68961. break;
  68962. case EVP_PKEY_EC:
  68963. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  68964. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68965. {
  68966. ExpectNotNull(ecKey = EC_KEY_new());
  68967. ExpectIntEQ(EC_KEY_generate_key(ecKey), 1);
  68968. ExpectIntEQ(
  68969. EVP_PKEY_assign_EC_KEY(pkey, ecKey), WOLFSSL_SUCCESS);
  68970. if (EXPECT_FAIL()) {
  68971. EC_KEY_free(ecKey);
  68972. }
  68973. }
  68974. #endif
  68975. #endif
  68976. break;
  68977. }
  68978. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  68979. ExpectIntEQ(EVP_PKEY_sign_init(ctx), WOLFSSL_SUCCESS);
  68980. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  68981. !defined(HAVE_SELFTEST)
  68982. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  68983. if (keyType == EVP_PKEY_RSA)
  68984. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING),
  68985. WOLFSSL_SUCCESS);
  68986. #endif
  68987. #endif
  68988. /* Check returning only length */
  68989. ExpectIntEQ(EVP_PKEY_sign(ctx, NULL, &siglenOnlyLen, hash,
  68990. SHA256_DIGEST_LENGTH), WOLFSSL_SUCCESS);
  68991. ExpectIntGT(siglenOnlyLen, 0);
  68992. /* Sign data */
  68993. ExpectIntEQ(EVP_PKEY_sign(ctx, sig, &siglen, hash,
  68994. SHA256_DIGEST_LENGTH), WOLFSSL_SUCCESS);
  68995. ExpectIntGE(siglenOnlyLen, siglen);
  68996. /* Verify signature */
  68997. ExpectNotNull(ctx_verify = EVP_PKEY_CTX_new(pkey, NULL));
  68998. ExpectIntEQ(EVP_PKEY_verify_init(ctx_verify), WOLFSSL_SUCCESS);
  68999. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  69000. !defined(HAVE_SELFTEST)
  69001. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  69002. if (keyType == EVP_PKEY_RSA)
  69003. ExpectIntEQ(
  69004. EVP_PKEY_CTX_set_rsa_padding(ctx_verify, RSA_PKCS1_PADDING),
  69005. WOLFSSL_SUCCESS);
  69006. #endif
  69007. #endif
  69008. ExpectIntEQ(EVP_PKEY_verify(
  69009. ctx_verify, sig, siglen, hash, SHA256_DIGEST_LENGTH),
  69010. WOLFSSL_SUCCESS);
  69011. ExpectIntEQ(EVP_PKEY_verify(
  69012. ctx_verify, sig, siglen, zero, SHA256_DIGEST_LENGTH),
  69013. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69014. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  69015. !defined(HAVE_SELFTEST)
  69016. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  69017. if (keyType == EVP_PKEY_RSA) {
  69018. #if defined(WC_RSA_NO_PADDING) || defined(WC_RSA_DIRECT)
  69019. /* Try RSA sign/verify with no padding. */
  69020. ExpectIntEQ(EVP_PKEY_sign_init(ctx), WOLFSSL_SUCCESS);
  69021. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_NO_PADDING),
  69022. WOLFSSL_SUCCESS);
  69023. ExpectIntEQ(EVP_PKEY_sign(ctx, sigVerify, &siglen, sig,
  69024. siglen), WOLFSSL_SUCCESS);
  69025. ExpectIntGE(siglenOnlyLen, siglen);
  69026. ExpectIntEQ(EVP_PKEY_verify_init(ctx_verify), WOLFSSL_SUCCESS);
  69027. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx_verify,
  69028. RSA_NO_PADDING), WOLFSSL_SUCCESS);
  69029. ExpectIntEQ(EVP_PKEY_verify(ctx_verify, sigVerify, siglen, sig,
  69030. siglen), WOLFSSL_SUCCESS);
  69031. #endif
  69032. /* Wrong padding schemes. */
  69033. ExpectIntEQ(EVP_PKEY_sign_init(ctx), WOLFSSL_SUCCESS);
  69034. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx,
  69035. RSA_PKCS1_OAEP_PADDING), WOLFSSL_SUCCESS);
  69036. ExpectIntNE(EVP_PKEY_sign(ctx, sigVerify, &siglen, sig,
  69037. siglen), WOLFSSL_SUCCESS);
  69038. ExpectIntEQ(EVP_PKEY_verify_init(ctx_verify), WOLFSSL_SUCCESS);
  69039. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx_verify,
  69040. RSA_PKCS1_OAEP_PADDING), WOLFSSL_SUCCESS);
  69041. ExpectIntNE(EVP_PKEY_verify(ctx_verify, sigVerify, siglen, sig,
  69042. siglen), WOLFSSL_SUCCESS);
  69043. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING),
  69044. WOLFSSL_SUCCESS);
  69045. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx_verify,
  69046. RSA_PKCS1_PADDING), WOLFSSL_SUCCESS);
  69047. }
  69048. #endif
  69049. #endif
  69050. /* error cases */
  69051. siglen = keySz; /* Reset because sig size may vary slightly */
  69052. ExpectIntNE(EVP_PKEY_sign_init(NULL), WOLFSSL_SUCCESS);
  69053. ExpectIntEQ(EVP_PKEY_sign_init(ctx), WOLFSSL_SUCCESS);
  69054. ExpectIntNE(EVP_PKEY_sign(NULL, sig, &siglen, (byte*)in, inlen),
  69055. WOLFSSL_SUCCESS);
  69056. ExpectIntEQ(EVP_PKEY_sign(ctx, sig, &siglen, (byte*)in, inlen),
  69057. WOLFSSL_SUCCESS);
  69058. EVP_PKEY_free(pkey);
  69059. pkey = NULL;
  69060. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  69061. DSA_free(dsa);
  69062. dsa = NULL;
  69063. #endif /* !NO_DSA && !HAVE_SELFTEST && WOLFSSL_KEY_GEN */
  69064. EVP_PKEY_CTX_free(ctx_verify);
  69065. ctx_verify = NULL;
  69066. EVP_PKEY_CTX_free(ctx);
  69067. ctx = NULL;
  69068. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  69069. XFREE(sigVerify, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  69070. #endif /* OPENSSL_EXTRA */
  69071. return EXPECT_RESULT();
  69072. }
  69073. #endif
  69074. static int test_wolfSSL_EVP_PKEY_sign_verify_rsa(void)
  69075. {
  69076. EXPECT_DECLS;
  69077. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  69078. !defined(HAVE_SELFTEST)
  69079. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  69080. ExpectIntEQ(test_wolfSSL_EVP_PKEY_sign_verify(EVP_PKEY_RSA), TEST_SUCCESS);
  69081. #endif
  69082. #endif
  69083. return EXPECT_RESULT();
  69084. }
  69085. static int test_wolfSSL_EVP_PKEY_sign_verify_dsa(void)
  69086. {
  69087. EXPECT_DECLS;
  69088. #if defined(OPENSSL_EXTRA)
  69089. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  69090. ExpectIntEQ(test_wolfSSL_EVP_PKEY_sign_verify(EVP_PKEY_DSA), TEST_SUCCESS);
  69091. #endif
  69092. #endif
  69093. return EXPECT_RESULT();
  69094. }
  69095. static int test_wolfSSL_EVP_PKEY_sign_verify_ec(void)
  69096. {
  69097. EXPECT_DECLS;
  69098. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  69099. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  69100. ExpectIntEQ(test_wolfSSL_EVP_PKEY_sign_verify(EVP_PKEY_EC), TEST_SUCCESS);
  69101. #endif
  69102. #endif
  69103. return EXPECT_RESULT();
  69104. }
  69105. static int test_EVP_PKEY_rsa(void)
  69106. {
  69107. EXPECT_DECLS;
  69108. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  69109. WOLFSSL_RSA* rsa = NULL;
  69110. WOLFSSL_EVP_PKEY* pkey = NULL;
  69111. ExpectNotNull(rsa = wolfSSL_RSA_new());
  69112. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  69113. ExpectIntEQ(EVP_PKEY_assign_RSA(NULL, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69114. ExpectIntEQ(EVP_PKEY_assign_RSA(pkey, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69115. ExpectIntEQ(EVP_PKEY_assign_RSA(pkey, rsa), WOLFSSL_SUCCESS);
  69116. if (EXPECT_FAIL()) {
  69117. wolfSSL_RSA_free(rsa);
  69118. }
  69119. ExpectPtrEq(EVP_PKEY_get0_RSA(pkey), rsa);
  69120. wolfSSL_EVP_PKEY_free(pkey);
  69121. #endif
  69122. return EXPECT_RESULT();
  69123. }
  69124. static int test_EVP_PKEY_ec(void)
  69125. {
  69126. EXPECT_DECLS;
  69127. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  69128. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  69129. WOLFSSL_EC_KEY* ecKey = NULL;
  69130. WOLFSSL_EVP_PKEY* pkey = NULL;
  69131. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  69132. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  69133. ExpectIntEQ(EVP_PKEY_assign_EC_KEY(NULL, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69134. ExpectIntEQ(EVP_PKEY_assign_EC_KEY(pkey, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69135. /* Should fail since ecKey is empty */
  69136. ExpectIntEQ(EVP_PKEY_assign_EC_KEY(pkey, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69137. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  69138. ExpectIntEQ(EVP_PKEY_assign_EC_KEY(pkey, ecKey), WOLFSSL_SUCCESS);
  69139. if (EXPECT_FAIL()) {
  69140. wolfSSL_EC_KEY_free(ecKey);
  69141. }
  69142. wolfSSL_EVP_PKEY_free(pkey);
  69143. #endif
  69144. #endif
  69145. return EXPECT_RESULT();
  69146. }
  69147. static int test_EVP_PKEY_cmp(void)
  69148. {
  69149. EXPECT_DECLS;
  69150. #if defined(OPENSSL_EXTRA)
  69151. EVP_PKEY *a = NULL;
  69152. EVP_PKEY *b = NULL;
  69153. const unsigned char *in;
  69154. #if !defined(NO_RSA) && defined(USE_CERT_BUFFERS_2048)
  69155. in = client_key_der_2048;
  69156. ExpectNotNull(a = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  69157. &in, (long)sizeof_client_key_der_2048));
  69158. in = client_key_der_2048;
  69159. ExpectNotNull(b = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  69160. &in, (long)sizeof_client_key_der_2048));
  69161. /* Test success case RSA */
  69162. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  69163. ExpectIntEQ(EVP_PKEY_cmp(a, b), 1);
  69164. #else
  69165. ExpectIntEQ(EVP_PKEY_cmp(a, b), 0);
  69166. #endif /* WOLFSSL_ERROR_CODE_OPENSSL */
  69167. EVP_PKEY_free(b);
  69168. b = NULL;
  69169. EVP_PKEY_free(a);
  69170. a = NULL;
  69171. #endif
  69172. #if defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  69173. in = ecc_clikey_der_256;
  69174. ExpectNotNull(a = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL,
  69175. &in, (long)sizeof_ecc_clikey_der_256));
  69176. in = ecc_clikey_der_256;
  69177. ExpectNotNull(b = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL,
  69178. &in, (long)sizeof_ecc_clikey_der_256));
  69179. /* Test success case ECC */
  69180. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  69181. ExpectIntEQ(EVP_PKEY_cmp(a, b), 1);
  69182. #else
  69183. ExpectIntEQ(EVP_PKEY_cmp(a, b), 0);
  69184. #endif /* WOLFSSL_ERROR_CODE_OPENSSL */
  69185. EVP_PKEY_free(b);
  69186. b = NULL;
  69187. EVP_PKEY_free(a);
  69188. a = NULL;
  69189. #endif
  69190. /* Test failure cases */
  69191. #if !defined(NO_RSA) && defined(USE_CERT_BUFFERS_2048) && \
  69192. defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  69193. in = client_key_der_2048;
  69194. ExpectNotNull(a = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  69195. &in, (long)sizeof_client_key_der_2048));
  69196. in = ecc_clikey_der_256;
  69197. ExpectNotNull(b = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL,
  69198. &in, (long)sizeof_ecc_clikey_der_256));
  69199. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  69200. ExpectIntEQ(EVP_PKEY_cmp(a, b), -1);
  69201. #else
  69202. ExpectIntNE(EVP_PKEY_cmp(a, b), 0);
  69203. #endif /* WOLFSSL_ERROR_CODE_OPENSSL */
  69204. EVP_PKEY_free(b);
  69205. b = NULL;
  69206. EVP_PKEY_free(a);
  69207. a = NULL;
  69208. #endif
  69209. /* invalid or empty failure cases */
  69210. a = EVP_PKEY_new();
  69211. b = EVP_PKEY_new();
  69212. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  69213. ExpectIntEQ(EVP_PKEY_cmp(NULL, NULL), 0);
  69214. ExpectIntEQ(EVP_PKEY_cmp(a, NULL), 0);
  69215. ExpectIntEQ(EVP_PKEY_cmp(NULL, b), 0);
  69216. #ifdef NO_RSA
  69217. /* Type check will fail since RSA is the default EVP key type */
  69218. ExpectIntEQ(EVP_PKEY_cmp(a, b), -2);
  69219. #else
  69220. ExpectIntEQ(EVP_PKEY_cmp(a, b), 0);
  69221. #endif
  69222. #else
  69223. ExpectIntNE(EVP_PKEY_cmp(NULL, NULL), 0);
  69224. ExpectIntNE(EVP_PKEY_cmp(a, NULL), 0);
  69225. ExpectIntNE(EVP_PKEY_cmp(NULL, b), 0);
  69226. ExpectIntNE(EVP_PKEY_cmp(a, b), 0);
  69227. #endif
  69228. EVP_PKEY_free(b);
  69229. EVP_PKEY_free(a);
  69230. (void)in;
  69231. #endif
  69232. return EXPECT_RESULT();
  69233. }
  69234. static int test_ERR_load_crypto_strings(void)
  69235. {
  69236. #if defined(OPENSSL_ALL)
  69237. ERR_load_crypto_strings();
  69238. return TEST_SUCCESS;
  69239. #else
  69240. return TEST_SKIPPED;
  69241. #endif
  69242. }
  69243. #if defined(OPENSSL_ALL) && !defined(NO_CERTS)
  69244. static void free_x509(X509* x)
  69245. {
  69246. AssertIntEQ((x == (X509*)1 || x == (X509*)2), 1);
  69247. }
  69248. #endif
  69249. static int test_sk_X509(void)
  69250. {
  69251. EXPECT_DECLS;
  69252. #if defined(OPENSSL_ALL) && !defined(NO_CERTS)
  69253. {
  69254. STACK_OF(X509)* s = NULL;
  69255. ExpectNotNull(s = sk_X509_new_null());
  69256. ExpectIntEQ(sk_X509_num(s), 0);
  69257. sk_X509_pop_free(s, NULL);
  69258. ExpectNotNull(s = sk_X509_new_null());
  69259. ExpectIntEQ(sk_X509_num(s), 0);
  69260. sk_X509_pop_free(s, NULL);
  69261. ExpectNotNull(s = sk_X509_new_null());
  69262. sk_X509_push(s, (X509*)1);
  69263. ExpectIntEQ(sk_X509_num(s), 1);
  69264. ExpectIntEQ((sk_X509_value(s, 0) == (X509*)1), 1);
  69265. sk_X509_push(s, (X509*)2);
  69266. ExpectIntEQ(sk_X509_num(s), 2);
  69267. ExpectIntEQ((sk_X509_value(s, 0) == (X509*)2), 1);
  69268. ExpectIntEQ((sk_X509_value(s, 1) == (X509*)1), 1);
  69269. sk_X509_push(s, (X509*)2);
  69270. sk_X509_pop_free(s, free_x509);
  69271. }
  69272. {
  69273. /* Push a list of 10 X509s onto stack, then verify that
  69274. * value(), push(), shift(), and pop() behave as expected. */
  69275. STACK_OF(X509)* s = NULL;
  69276. X509* xList[10];
  69277. int i = 0;
  69278. const int len = (sizeof(xList) / sizeof(xList[0]));
  69279. for (i = 0; i < len; ++i) {
  69280. xList[i] = NULL;
  69281. ExpectNotNull(xList[i] = X509_new());
  69282. }
  69283. /* test push, pop, and free */
  69284. ExpectNotNull(s = sk_X509_new_null());
  69285. for (i = 0; i < len; ++i) {
  69286. sk_X509_push(s, xList[i]);
  69287. ExpectIntEQ(sk_X509_num(s), i + 1);
  69288. ExpectIntEQ((sk_X509_value(s, 0) == xList[i]), 1);
  69289. ExpectIntEQ((sk_X509_value(s, i) == xList[0]), 1);
  69290. }
  69291. /* pop returns and removes last pushed on stack, which is index 0
  69292. * in sk_x509_value */
  69293. for (i = 0; i < len; ++i) {
  69294. X509 * x = sk_X509_value(s, 0);
  69295. X509 * y = sk_X509_pop(s);
  69296. X509 * z = xList[len - 1 - i];
  69297. ExpectIntEQ((x == y), 1);
  69298. ExpectIntEQ((x == z), 1);
  69299. ExpectIntEQ(sk_X509_num(s), len - 1 - i);
  69300. }
  69301. sk_free(s);
  69302. s = NULL;
  69303. /* test push, shift, and free */
  69304. ExpectNotNull(s = sk_X509_new_null());
  69305. for (i = 0; i < len; ++i) {
  69306. sk_X509_push(s, xList[i]);
  69307. ExpectIntEQ(sk_X509_num(s), i + 1);
  69308. ExpectIntEQ((sk_X509_value(s, 0) == xList[i]), 1);
  69309. ExpectIntEQ((sk_X509_value(s, i) == xList[0]), 1);
  69310. }
  69311. /* shift returns and removes first pushed on stack, which is index i
  69312. * in sk_x509_value() */
  69313. for (i = 0; i < len; ++i) {
  69314. X509 * x = sk_X509_value(s, len - 1 - i);
  69315. X509 * y = sk_X509_shift(s);
  69316. X509 * z = xList[i];
  69317. ExpectIntEQ((x == y), 1);
  69318. ExpectIntEQ((x == z), 1);
  69319. ExpectIntEQ(sk_X509_num(s), len - 1 - i);
  69320. }
  69321. sk_free(s);
  69322. for (i = 0; i < len; ++i)
  69323. X509_free(xList[i]);
  69324. }
  69325. #endif
  69326. return EXPECT_RESULT();
  69327. }
  69328. static int test_sk_X509_CRL(void)
  69329. {
  69330. EXPECT_DECLS;
  69331. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && defined(HAVE_CRL)
  69332. X509_CRL* crl = NULL;
  69333. XFILE fp = XBADFILE;
  69334. STACK_OF(X509_CRL)* s = NULL;
  69335. ExpectTrue((fp = XFOPEN("./certs/crl/crl.pem", "rb")) != XBADFILE);
  69336. ExpectNotNull(crl = (X509_CRL*)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  69337. NULL, NULL));
  69338. if (fp != XBADFILE)
  69339. XFCLOSE(fp);
  69340. ExpectNotNull(s = sk_X509_CRL_new());
  69341. ExpectIntEQ(sk_X509_CRL_num(s), 0);
  69342. ExpectIntEQ(sk_X509_CRL_push(s, crl), 1);
  69343. if (EXPECT_FAIL()) {
  69344. X509_CRL_free(crl);
  69345. }
  69346. ExpectIntEQ(sk_X509_CRL_num(s), 1);
  69347. ExpectPtrEq(sk_X509_CRL_value(s, 0), crl);
  69348. sk_X509_CRL_free(s);
  69349. #endif
  69350. return EXPECT_RESULT();
  69351. }
  69352. static int test_X509_get_signature_nid(void)
  69353. {
  69354. EXPECT_DECLS;
  69355. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  69356. X509* x509 = NULL;
  69357. ExpectIntEQ(X509_get_signature_nid(NULL), 0);
  69358. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  69359. SSL_FILETYPE_PEM));
  69360. ExpectIntEQ(X509_get_signature_nid(x509), NID_sha256WithRSAEncryption);
  69361. X509_free(x509);
  69362. #endif
  69363. return EXPECT_RESULT();
  69364. }
  69365. static int test_X509_REQ(void)
  69366. {
  69367. EXPECT_DECLS;
  69368. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  69369. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && !defined(NO_BIO)
  69370. X509_NAME* name = NULL;
  69371. #ifndef NO_RSA
  69372. X509_NAME* subject = NULL;
  69373. #endif
  69374. #if !defined(NO_RSA) || defined(HAVE_ECC)
  69375. X509_REQ* req = NULL;
  69376. EVP_PKEY* priv = NULL;
  69377. EVP_PKEY* pub = NULL;
  69378. unsigned char* der = NULL;
  69379. int len;
  69380. #endif
  69381. #ifndef NO_RSA
  69382. EVP_MD_CTX *mctx = NULL;
  69383. EVP_PKEY_CTX *pkctx = NULL;
  69384. #ifdef USE_CERT_BUFFERS_1024
  69385. const unsigned char* rsaPriv = (const unsigned char*)client_key_der_1024;
  69386. const unsigned char* rsaPub = (unsigned char*)client_keypub_der_1024;
  69387. #elif defined(USE_CERT_BUFFERS_2048)
  69388. const unsigned char* rsaPriv = (const unsigned char*)client_key_der_2048;
  69389. const unsigned char* rsaPub = (unsigned char*)client_keypub_der_2048;
  69390. #endif
  69391. #endif
  69392. #ifdef HAVE_ECC
  69393. const unsigned char* ecPriv = (const unsigned char*)ecc_clikey_der_256;
  69394. const unsigned char* ecPub = (unsigned char*)ecc_clikeypub_der_256;
  69395. #endif
  69396. ExpectNotNull(name = X509_NAME_new());
  69397. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  69398. (byte*)"wolfssl.com", 11, 0, 1), WOLFSSL_SUCCESS);
  69399. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  69400. (byte*)"support@wolfssl.com", 19, -1, 1), WOLFSSL_SUCCESS);
  69401. #ifndef NO_RSA
  69402. ExpectNotNull(priv = d2i_PrivateKey(EVP_PKEY_RSA, NULL, &rsaPriv,
  69403. (long)sizeof_client_key_der_2048));
  69404. ExpectNotNull(pub = d2i_PUBKEY(NULL, &rsaPub,
  69405. (long)sizeof_client_keypub_der_2048));
  69406. ExpectNotNull(req = X509_REQ_new());
  69407. ExpectIntEQ(X509_REQ_set_subject_name(NULL, name), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69408. ExpectIntEQ(X509_REQ_set_subject_name(req, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69409. ExpectIntEQ(X509_REQ_set_subject_name(req, name), WOLFSSL_SUCCESS);
  69410. ExpectIntEQ(X509_REQ_set_pubkey(NULL, pub), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69411. ExpectIntEQ(X509_REQ_set_pubkey(req, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69412. ExpectIntEQ(X509_REQ_set_pubkey(req, pub), WOLFSSL_SUCCESS);
  69413. ExpectIntEQ(X509_REQ_sign(NULL, priv, EVP_sha256()), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69414. ExpectIntEQ(X509_REQ_sign(req, NULL, EVP_sha256()), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69415. ExpectIntEQ(X509_REQ_sign(req, priv, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69416. ExpectIntEQ(X509_REQ_sign(req, priv, EVP_sha256()), WOLFSSL_SUCCESS);
  69417. len = i2d_X509_REQ(req, &der);
  69418. DEBUG_WRITE_DER(der, len, "req.der");
  69419. #ifdef USE_CERT_BUFFERS_1024
  69420. ExpectIntEQ(len, 381);
  69421. #else
  69422. ExpectIntEQ(len, 643);
  69423. #endif
  69424. XFREE(der, NULL, DYNAMIC_TYPE_OPENSSL);
  69425. der = NULL;
  69426. mctx = EVP_MD_CTX_new();
  69427. ExpectIntEQ(EVP_DigestSignInit(mctx, &pkctx, EVP_sha256(), NULL, priv),
  69428. WOLFSSL_SUCCESS);
  69429. ExpectIntEQ(X509_REQ_sign_ctx(req, mctx), WOLFSSL_SUCCESS);
  69430. EVP_MD_CTX_free(mctx);
  69431. mctx = NULL;
  69432. X509_REQ_free(NULL);
  69433. X509_REQ_free(req);
  69434. req = NULL;
  69435. /* Test getting the subject from a newly created X509_REQ */
  69436. ExpectNotNull(req = X509_REQ_new());
  69437. ExpectNotNull(subject = X509_REQ_get_subject_name(req));
  69438. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_commonName,
  69439. MBSTRING_UTF8, (unsigned char*)"www.wolfssl.com", -1, -1, 0), 1);
  69440. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_countryName,
  69441. MBSTRING_UTF8, (unsigned char*)"US", -1, -1, 0), 1);
  69442. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_localityName,
  69443. MBSTRING_UTF8, (unsigned char*)"Bozeman", -1, -1, 0), 1);
  69444. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_stateOrProvinceName,
  69445. MBSTRING_UTF8, (unsigned char*)"Montana", -1, -1, 0), 1);
  69446. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_organizationName,
  69447. MBSTRING_UTF8, (unsigned char*)"wolfSSL", -1, -1, 0), 1);
  69448. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_organizationalUnitName,
  69449. MBSTRING_UTF8, (unsigned char*)"Testing", -1, -1, 0), 1);
  69450. ExpectIntEQ(X509_REQ_set_pubkey(req, pub), WOLFSSL_SUCCESS);
  69451. ExpectIntEQ(X509_REQ_sign(req, priv, EVP_sha256()), WOLFSSL_SUCCESS);
  69452. len = i2d_X509_REQ(req, &der);
  69453. DEBUG_WRITE_DER(der, len, "req2.der");
  69454. #ifdef USE_CERT_BUFFERS_1024
  69455. ExpectIntEQ(len, 435);
  69456. #else
  69457. ExpectIntEQ(len, 696);
  69458. #endif
  69459. XFREE(der, NULL, DYNAMIC_TYPE_OPENSSL);
  69460. der = NULL;
  69461. EVP_PKEY_free(pub);
  69462. pub = NULL;
  69463. EVP_PKEY_free(priv);
  69464. priv = NULL;
  69465. X509_REQ_free(req);
  69466. req = NULL;
  69467. #endif
  69468. #ifdef HAVE_ECC
  69469. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL, &ecPriv,
  69470. sizeof_ecc_clikey_der_256));
  69471. ExpectNotNull(pub = wolfSSL_d2i_PUBKEY(NULL, &ecPub,
  69472. sizeof_ecc_clikeypub_der_256));
  69473. ExpectNotNull(req = X509_REQ_new());
  69474. ExpectIntEQ(X509_REQ_set_subject_name(req, name), WOLFSSL_SUCCESS);
  69475. ExpectIntEQ(X509_REQ_set_pubkey(req, pub), WOLFSSL_SUCCESS);
  69476. ExpectIntEQ(X509_REQ_sign(req, priv, EVP_sha256()), WOLFSSL_SUCCESS);
  69477. /* Signature is random and may be shorter or longer. */
  69478. ExpectIntGE((len = i2d_X509_REQ(req, &der)), 245);
  69479. ExpectIntLE(len, 253);
  69480. XFREE(der, NULL, DYNAMIC_TYPE_OPENSSL);
  69481. X509_REQ_free(req);
  69482. EVP_PKEY_free(pub);
  69483. EVP_PKEY_free(priv);
  69484. #ifdef FP_ECC
  69485. wc_ecc_fp_free();
  69486. #endif
  69487. #endif /* HAVE_ECC */
  69488. X509_NAME_free(name);
  69489. #endif
  69490. return EXPECT_RESULT();
  69491. }
  69492. static int test_wolfssl_PKCS7(void)
  69493. {
  69494. EXPECT_DECLS;
  69495. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7) && !defined(NO_BIO) && \
  69496. !defined(NO_RSA)
  69497. PKCS7* pkcs7 = NULL;
  69498. byte data[FOURK_BUF];
  69499. word32 len = sizeof(data);
  69500. const byte* p = data;
  69501. byte content[] = "Test data to encode.";
  69502. #if !defined(NO_RSA) & defined(USE_CERT_BUFFERS_2048)
  69503. BIO* bio = NULL;
  69504. byte key[sizeof(client_key_der_2048)];
  69505. word32 keySz = (word32)sizeof(key);
  69506. byte* out = NULL;
  69507. #endif
  69508. ExpectIntGT((len = (word32)CreatePKCS7SignedData(data, (int)len, content,
  69509. (word32)sizeof(content), 0, 0, 0, RSA_TYPE)), 0);
  69510. ExpectNull(pkcs7 = d2i_PKCS7(NULL, NULL, (int)len));
  69511. ExpectNull(pkcs7 = d2i_PKCS7(NULL, &p, 0));
  69512. ExpectNotNull(pkcs7 = d2i_PKCS7(NULL, &p, (int)len));
  69513. ExpectIntEQ(wolfSSL_PKCS7_verify(NULL, NULL, NULL, NULL, NULL,
  69514. PKCS7_NOVERIFY), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69515. PKCS7_free(pkcs7);
  69516. pkcs7 = NULL;
  69517. /* fail case, without PKCS7_NOVERIFY */
  69518. p = data;
  69519. ExpectNotNull(pkcs7 = d2i_PKCS7(NULL, &p, (int)len));
  69520. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, NULL, NULL,
  69521. 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69522. PKCS7_free(pkcs7);
  69523. pkcs7 = NULL;
  69524. /* success case, with PKCS7_NOVERIFY */
  69525. p = data;
  69526. ExpectNotNull(pkcs7 = d2i_PKCS7(NULL, &p, (int)len));
  69527. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, NULL, NULL,
  69528. PKCS7_NOVERIFY), WOLFSSL_SUCCESS);
  69529. #if !defined(NO_RSA) & defined(USE_CERT_BUFFERS_2048)
  69530. /* test i2d */
  69531. XMEMCPY(key, client_key_der_2048, keySz);
  69532. if (pkcs7 != NULL) {
  69533. pkcs7->privateKey = key;
  69534. pkcs7->privateKeySz = (word32)sizeof(key);
  69535. pkcs7->encryptOID = RSAk;
  69536. #ifdef NO_SHA
  69537. pkcs7->hashOID = SHA256h;
  69538. #else
  69539. pkcs7->hashOID = SHAh;
  69540. #endif
  69541. }
  69542. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  69543. ExpectIntEQ(i2d_PKCS7_bio(bio, pkcs7), 1);
  69544. #ifndef NO_ASN_TIME
  69545. ExpectIntEQ(i2d_PKCS7(pkcs7, &out), 655);
  69546. #else
  69547. ExpectIntEQ(i2d_PKCS7(pkcs7, &out), 625);
  69548. #endif
  69549. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  69550. BIO_free(bio);
  69551. #endif
  69552. PKCS7_free(NULL);
  69553. PKCS7_free(pkcs7);
  69554. #endif
  69555. return EXPECT_RESULT();
  69556. }
  69557. static int test_wolfSSL_PKCS7_sign(void)
  69558. {
  69559. EXPECT_DECLS;
  69560. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7) && !defined(NO_BIO) && \
  69561. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  69562. PKCS7* p7 = NULL;
  69563. PKCS7* p7Ver = NULL;
  69564. byte* out = NULL;
  69565. byte* tmpPtr = NULL;
  69566. int outLen = 0;
  69567. int flags = 0;
  69568. byte data[] = "Test data to encode.";
  69569. const char* cert = "./certs/server-cert.pem";
  69570. const char* key = "./certs/server-key.pem";
  69571. const char* ca = "./certs/ca-cert.pem";
  69572. WOLFSSL_BIO* certBio = NULL;
  69573. WOLFSSL_BIO* keyBio = NULL;
  69574. WOLFSSL_BIO* caBio = NULL;
  69575. WOLFSSL_BIO* inBio = NULL;
  69576. X509* signCert = NULL;
  69577. EVP_PKEY* signKey = NULL;
  69578. X509* caCert = NULL;
  69579. X509_STORE* store = NULL;
  69580. #ifndef NO_PKCS7_STREAM
  69581. int z;
  69582. int ret;
  69583. #endif /* !NO_PKCS7_STREAM */
  69584. /* read signer cert/key into BIO */
  69585. ExpectNotNull(certBio = BIO_new_file(cert, "r"));
  69586. ExpectNotNull(keyBio = BIO_new_file(key, "r"));
  69587. ExpectNotNull(signCert = PEM_read_bio_X509(certBio, NULL, 0, NULL));
  69588. ExpectNotNull(signKey = PEM_read_bio_PrivateKey(keyBio, NULL, 0, NULL));
  69589. /* read CA cert into store (for verify) */
  69590. ExpectNotNull(caBio = BIO_new_file(ca, "r"));
  69591. ExpectNotNull(caCert = PEM_read_bio_X509(caBio, NULL, 0, NULL));
  69592. ExpectNotNull(store = X509_STORE_new());
  69593. ExpectIntEQ(X509_STORE_add_cert(store, caCert), 1);
  69594. /* data to be signed into BIO */
  69595. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  69596. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  69597. /* PKCS7_sign, bad args: signer NULL */
  69598. ExpectNull(p7 = PKCS7_sign(NULL, signKey, NULL, inBio, 0));
  69599. /* PKCS7_sign, bad args: signer key NULL */
  69600. ExpectNull(p7 = PKCS7_sign(signCert, NULL, NULL, inBio, 0));
  69601. /* PKCS7_sign, bad args: in data NULL without PKCS7_STREAM */
  69602. ExpectNull(p7 = PKCS7_sign(signCert, signKey, NULL, NULL, 0));
  69603. /* PKCS7_sign, bad args: PKCS7_NOCERTS flag not supported */
  69604. ExpectNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, PKCS7_NOCERTS));
  69605. /* PKCS7_sign, bad args: PKCS7_PARTIAL flag not supported */
  69606. ExpectNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, PKCS7_PARTIAL));
  69607. /* TEST SUCCESS: Not detached, not streaming, not MIME */
  69608. {
  69609. flags = PKCS7_BINARY;
  69610. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  69611. ExpectIntGT((outLen = i2d_PKCS7(p7, &out)), 0);
  69612. /* verify with d2i_PKCS7 */
  69613. tmpPtr = out;
  69614. ExpectNotNull(p7Ver = d2i_PKCS7(NULL, (const byte**)&tmpPtr, outLen));
  69615. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, NULL, NULL, flags), 1);
  69616. PKCS7_free(p7Ver);
  69617. p7Ver = NULL;
  69618. /* verify with wc_PKCS7_VerifySignedData */
  69619. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  69620. ExpectIntEQ(wc_PKCS7_Init(p7Ver, HEAP_HINT, INVALID_DEVID), 0);
  69621. ExpectIntEQ(wc_PKCS7_VerifySignedData(p7Ver, out, (word32)outLen), 0);
  69622. #ifndef NO_PKCS7_STREAM
  69623. /* verify with wc_PKCS7_VerifySignedData streaming */
  69624. wc_PKCS7_Free(p7Ver);
  69625. p7Ver = NULL;
  69626. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  69627. ExpectIntEQ(wc_PKCS7_Init(p7Ver, HEAP_HINT, INVALID_DEVID), 0);
  69628. /* test for streaming */
  69629. ret = -1;
  69630. for (z = 0; z < outLen && ret != 0; z++) {
  69631. ret = wc_PKCS7_VerifySignedData(p7Ver, out + z, 1);
  69632. if (ret < 0){
  69633. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  69634. }
  69635. }
  69636. ExpectIntEQ(ret, 0);
  69637. #endif /* !NO_PKCS7_STREAM */
  69638. /* compare the signer found to expected signer */
  69639. ExpectIntNE(p7Ver->verifyCertSz, 0);
  69640. tmpPtr = NULL;
  69641. ExpectIntEQ(i2d_X509(signCert, &tmpPtr), p7Ver->verifyCertSz);
  69642. ExpectIntEQ(XMEMCMP(tmpPtr, p7Ver->verifyCert, p7Ver->verifyCertSz), 0);
  69643. XFREE(tmpPtr, NULL, DYNAMIC_TYPE_OPENSSL);
  69644. tmpPtr = NULL;
  69645. wc_PKCS7_Free(p7Ver);
  69646. p7Ver = NULL;
  69647. ExpectNotNull(out);
  69648. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  69649. out = NULL;
  69650. PKCS7_free(p7);
  69651. p7 = NULL;
  69652. }
  69653. /* TEST SUCCESS: Not detached, streaming, not MIME. Also bad arg
  69654. * tests for PKCS7_final() while we have a PKCS7 pointer to use */
  69655. {
  69656. /* re-populate input BIO, may have been consumed */
  69657. BIO_free(inBio);
  69658. inBio = NULL;
  69659. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  69660. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  69661. flags = PKCS7_BINARY | PKCS7_STREAM;
  69662. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  69663. ExpectIntEQ(PKCS7_final(p7, inBio, flags), 1);
  69664. ExpectIntGT((outLen = i2d_PKCS7(p7, &out)), 0);
  69665. /* PKCS7_final, bad args: PKCS7 null */
  69666. ExpectIntEQ(PKCS7_final(NULL, inBio, 0), 0);
  69667. /* PKCS7_final, bad args: PKCS7 null */
  69668. ExpectIntEQ(PKCS7_final(p7, NULL, 0), 0);
  69669. tmpPtr = out;
  69670. ExpectNotNull(p7Ver = d2i_PKCS7(NULL, (const byte**)&tmpPtr, outLen));
  69671. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, NULL, NULL, flags), 1);
  69672. PKCS7_free(p7Ver);
  69673. p7Ver = NULL;
  69674. ExpectNotNull(out);
  69675. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  69676. out = NULL;
  69677. PKCS7_free(p7);
  69678. p7 = NULL;
  69679. }
  69680. /* TEST SUCCESS: Detached, not streaming, not MIME */
  69681. {
  69682. /* re-populate input BIO, may have been consumed */
  69683. BIO_free(inBio);
  69684. inBio = NULL;
  69685. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  69686. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  69687. flags = PKCS7_BINARY | PKCS7_DETACHED;
  69688. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  69689. ExpectIntGT((outLen = i2d_PKCS7(p7, &out)), 0);
  69690. /* verify with wolfCrypt, d2i_PKCS7 does not support detached content */
  69691. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  69692. if (p7Ver != NULL) {
  69693. p7Ver->content = data;
  69694. p7Ver->contentSz = sizeof(data);
  69695. }
  69696. ExpectIntEQ(wc_PKCS7_VerifySignedData(p7Ver, out, (word32)outLen), 0);
  69697. wc_PKCS7_Free(p7Ver);
  69698. p7Ver = NULL;
  69699. #ifndef NO_PKCS7_STREAM
  69700. /* verify with wc_PKCS7_VerifySignedData streaming */
  69701. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  69702. if (p7Ver != NULL) {
  69703. p7Ver->content = data;
  69704. p7Ver->contentSz = sizeof(data);
  69705. }
  69706. /* test for streaming */
  69707. ret = -1;
  69708. for (z = 0; z < outLen && ret != 0; z++) {
  69709. ret = wc_PKCS7_VerifySignedData(p7Ver, out + z, 1);
  69710. if (ret < 0){
  69711. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  69712. }
  69713. }
  69714. ExpectIntEQ(ret, 0);
  69715. wc_PKCS7_Free(p7Ver);
  69716. p7Ver = NULL;
  69717. #endif /* !NO_PKCS7_STREAM */
  69718. /* verify expected failure (NULL return) from d2i_PKCS7, it does not
  69719. * yet support detached content */
  69720. tmpPtr = out;
  69721. ExpectNull(p7Ver = d2i_PKCS7(NULL, (const byte**)&tmpPtr, outLen));
  69722. PKCS7_free(p7Ver);
  69723. p7Ver = NULL;
  69724. ExpectNotNull(out);
  69725. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  69726. out = NULL;
  69727. PKCS7_free(p7);
  69728. p7 = NULL;
  69729. }
  69730. /* TEST SUCCESS: Detached, streaming, not MIME */
  69731. {
  69732. /* re-populate input BIO, may have been consumed */
  69733. BIO_free(inBio);
  69734. inBio = NULL;
  69735. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  69736. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  69737. flags = PKCS7_BINARY | PKCS7_DETACHED | PKCS7_STREAM;
  69738. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  69739. ExpectIntEQ(PKCS7_final(p7, inBio, flags), 1);
  69740. ExpectIntGT((outLen = i2d_PKCS7(p7, &out)), 0);
  69741. /* verify with wolfCrypt, d2i_PKCS7 does not support detached content */
  69742. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  69743. if (p7Ver != NULL) {
  69744. p7Ver->content = data;
  69745. p7Ver->contentSz = sizeof(data);
  69746. }
  69747. ExpectIntEQ(wc_PKCS7_VerifySignedData(p7Ver, out, (word32)outLen), 0);
  69748. wc_PKCS7_Free(p7Ver);
  69749. p7Ver = NULL;
  69750. ExpectNotNull(out);
  69751. #ifndef NO_PKCS7_STREAM
  69752. /* verify with wc_PKCS7_VerifySignedData streaming */
  69753. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  69754. if (p7Ver != NULL) {
  69755. p7Ver->content = data;
  69756. p7Ver->contentSz = sizeof(data);
  69757. }
  69758. /* test for streaming */
  69759. ret = -1;
  69760. for (z = 0; z < outLen && ret != 0; z++) {
  69761. ret = wc_PKCS7_VerifySignedData(p7Ver, out + z, 1);
  69762. if (ret < 0){
  69763. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  69764. }
  69765. }
  69766. ExpectIntEQ(ret, 0);
  69767. ExpectNotNull(out);
  69768. wc_PKCS7_Free(p7Ver);
  69769. p7Ver = NULL;
  69770. #endif /* !NO_PKCS7_STREAM */
  69771. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  69772. PKCS7_free(p7);
  69773. p7 = NULL;
  69774. }
  69775. X509_STORE_free(store);
  69776. X509_free(caCert);
  69777. X509_free(signCert);
  69778. EVP_PKEY_free(signKey);
  69779. BIO_free(inBio);
  69780. BIO_free(keyBio);
  69781. BIO_free(certBio);
  69782. BIO_free(caBio);
  69783. #endif
  69784. return EXPECT_RESULT();
  69785. }
  69786. static int test_wolfSSL_PKCS7_SIGNED_new(void)
  69787. {
  69788. EXPECT_DECLS;
  69789. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7)
  69790. PKCS7_SIGNED* pkcs7 = NULL;
  69791. ExpectNotNull(pkcs7 = PKCS7_SIGNED_new());
  69792. ExpectIntEQ(pkcs7->contentOID, SIGNED_DATA);
  69793. PKCS7_SIGNED_free(pkcs7);
  69794. #endif
  69795. return EXPECT_RESULT();
  69796. }
  69797. #ifndef NO_BIO
  69798. static int test_wolfSSL_PEM_write_bio_PKCS7(void)
  69799. {
  69800. EXPECT_DECLS;
  69801. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM)
  69802. PKCS7* pkcs7 = NULL;
  69803. BIO* bio = NULL;
  69804. const byte* cert_buf = NULL;
  69805. int ret = 0;
  69806. WC_RNG rng;
  69807. const byte data[] = { /* Hello World */
  69808. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  69809. 0x72,0x6c,0x64
  69810. };
  69811. #ifndef NO_RSA
  69812. #if defined(USE_CERT_BUFFERS_2048)
  69813. byte key[sizeof(client_key_der_2048)];
  69814. byte cert[sizeof(client_cert_der_2048)];
  69815. word32 keySz = (word32)sizeof(key);
  69816. word32 certSz = (word32)sizeof(cert);
  69817. XMEMSET(key, 0, keySz);
  69818. XMEMSET(cert, 0, certSz);
  69819. XMEMCPY(key, client_key_der_2048, keySz);
  69820. XMEMCPY(cert, client_cert_der_2048, certSz);
  69821. #elif defined(USE_CERT_BUFFERS_1024)
  69822. byte key[sizeof_client_key_der_1024];
  69823. byte cert[sizeof(sizeof_client_cert_der_1024)];
  69824. word32 keySz = (word32)sizeof(key);
  69825. word32 certSz = (word32)sizeof(cert);
  69826. XMEMSET(key, 0, keySz);
  69827. XMEMSET(cert, 0, certSz);
  69828. XMEMCPY(key, client_key_der_1024, keySz);
  69829. XMEMCPY(cert, client_cert_der_1024, certSz);
  69830. #else
  69831. unsigned char cert[ONEK_BUF];
  69832. unsigned char key[ONEK_BUF];
  69833. XFILE fp = XBADFILE;
  69834. int certSz;
  69835. int keySz;
  69836. ExpectTrue((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) !=
  69837. XBADFILE);
  69838. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_client_cert_der_1024,
  69839. fp), 0);
  69840. if (fp != XBADFILE) {
  69841. XFCLOSE(fp);
  69842. fp = XBADFILE;
  69843. }
  69844. ExpectTrue((fp = XFOPEN("./certs/1024/client-key.der", "rb")) !=
  69845. XBADFILE);
  69846. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_client_key_der_1024, fp),
  69847. 0);
  69848. if (fp != XBADFILE) {
  69849. XFCLOSE(fp);
  69850. fp = XBADFILE;
  69851. }
  69852. #endif
  69853. #elif defined(HAVE_ECC)
  69854. #if defined(USE_CERT_BUFFERS_256)
  69855. unsigned char cert[sizeof(cliecc_cert_der_256)];
  69856. unsigned char key[sizeof(ecc_clikey_der_256)];
  69857. int certSz = (int)sizeof(cert);
  69858. int keySz = (int)sizeof(key);
  69859. XMEMSET(cert, 0, certSz);
  69860. XMEMSET(key, 0, keySz);
  69861. XMEMCPY(cert, cliecc_cert_der_256, sizeof_cliecc_cert_der_256);
  69862. XMEMCPY(key, ecc_clikey_der_256, sizeof_ecc_clikey_der_256);
  69863. #else
  69864. unsigned char cert[ONEK_BUF];
  69865. unsigned char key[ONEK_BUF];
  69866. XFILE fp = XBADFILE;
  69867. int certSz, keySz;
  69868. ExpectTrue((fp = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  69869. XBADFILE);
  69870. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_cliecc_cert_der_256,
  69871. fp), 0);
  69872. if (fp != XBADFILE) {
  69873. XFCLOSE(fp);
  69874. fp = XBADFILE;
  69875. }
  69876. ExpectTrue((fp = XFOPEN("./certs/client-ecc-key.der", "rb")) !=
  69877. XBADFILE);
  69878. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_ecc_clikey_der_256, fp),
  69879. 0);
  69880. if (fp != XBADFILE) {
  69881. XFCLOSE(fp);
  69882. fp = XBADFILE;
  69883. }
  69884. #endif
  69885. #else
  69886. #error PKCS7 requires ECC or RSA
  69887. #endif
  69888. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  69889. /* initialize with DER encoded cert */
  69890. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (byte*)cert, (word32)certSz), 0);
  69891. /* init rng */
  69892. XMEMSET(&rng, 0, sizeof(WC_RNG));
  69893. ExpectIntEQ(wc_InitRng(&rng), 0);
  69894. if (pkcs7 != NULL) {
  69895. pkcs7->rng = &rng;
  69896. pkcs7->content = (byte*)data; /* not used for ex */
  69897. pkcs7->contentSz = (word32)sizeof(data);
  69898. pkcs7->contentOID = SIGNED_DATA;
  69899. pkcs7->privateKey = key;
  69900. pkcs7->privateKeySz = (word32)sizeof(key);
  69901. pkcs7->encryptOID = RSAk;
  69902. #ifdef NO_SHA
  69903. pkcs7->hashOID = SHA256h;
  69904. #else
  69905. pkcs7->hashOID = SHAh;
  69906. #endif
  69907. pkcs7->signedAttribs = NULL;
  69908. pkcs7->signedAttribsSz = 0;
  69909. }
  69910. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  69911. /* Write PKCS#7 PEM to BIO, the function converts the DER to PEM cert*/
  69912. ExpectIntEQ(PEM_write_bio_PKCS7(bio, pkcs7), WOLFSSL_SUCCESS);
  69913. /* Read PKCS#7 PEM from BIO */
  69914. ret = wolfSSL_BIO_get_mem_data(bio, &cert_buf);
  69915. ExpectIntGE(ret, 0);
  69916. BIO_free(bio);
  69917. wc_PKCS7_Free(pkcs7);
  69918. wc_FreeRng(&rng);
  69919. #endif
  69920. return EXPECT_RESULT();
  69921. }
  69922. #ifdef HAVE_SMIME
  69923. /* // NOLINTBEGIN(clang-analyzer-unix.Stream) */
  69924. static int test_wolfSSL_SMIME_read_PKCS7(void)
  69925. {
  69926. EXPECT_DECLS;
  69927. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && \
  69928. !defined(NO_RSA)
  69929. PKCS7* pkcs7 = NULL;
  69930. BIO* bio = NULL;
  69931. BIO* bcont = NULL;
  69932. BIO* out = NULL;
  69933. const byte* outBuf = NULL;
  69934. int outBufLen = 0;
  69935. static const char contTypeText[] = "Content-Type: text/plain\r\n\r\n";
  69936. XFILE smimeTestFile = XBADFILE;
  69937. ExpectTrue((smimeTestFile = XFOPEN("./certs/test/smime-test.p7s", "r")) !=
  69938. XBADFILE);
  69939. /* smime-test.p7s */
  69940. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_file());
  69941. ExpectNotNull(bio);
  69942. ExpectIntEQ(wolfSSL_BIO_set_fp(bio, smimeTestFile, BIO_CLOSE), SSL_SUCCESS);
  69943. pkcs7 = wolfSSL_SMIME_read_PKCS7(bio, &bcont);
  69944. ExpectNotNull(pkcs7);
  69945. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, bcont, NULL,
  69946. PKCS7_NOVERIFY), SSL_SUCCESS);
  69947. if (smimeTestFile != XBADFILE) {
  69948. XFCLOSE(smimeTestFile);
  69949. smimeTestFile = XBADFILE;
  69950. }
  69951. if (bcont) BIO_free(bcont);
  69952. bcont = NULL;
  69953. wolfSSL_PKCS7_free(pkcs7);
  69954. pkcs7 = NULL;
  69955. /* smime-test-multipart.p7s */
  69956. smimeTestFile = XFOPEN("./certs/test/smime-test-multipart.p7s", "r");
  69957. ExpectFalse(smimeTestFile == XBADFILE);
  69958. ExpectIntEQ(wolfSSL_BIO_set_fp(bio, smimeTestFile, BIO_CLOSE), SSL_SUCCESS);
  69959. pkcs7 = wolfSSL_SMIME_read_PKCS7(bio, &bcont);
  69960. ExpectNotNull(pkcs7);
  69961. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, bcont, NULL,
  69962. PKCS7_NOVERIFY), SSL_SUCCESS);
  69963. if (smimeTestFile != XBADFILE) {
  69964. XFCLOSE(smimeTestFile);
  69965. smimeTestFile = XBADFILE;
  69966. }
  69967. if (bcont) BIO_free(bcont);
  69968. bcont = NULL;
  69969. wolfSSL_PKCS7_free(pkcs7);
  69970. pkcs7 = NULL;
  69971. /* smime-test-multipart-badsig.p7s */
  69972. smimeTestFile = XFOPEN("./certs/test/smime-test-multipart-badsig.p7s", "r");
  69973. ExpectFalse(smimeTestFile == XBADFILE);
  69974. ExpectIntEQ(wolfSSL_BIO_set_fp(bio, smimeTestFile, BIO_CLOSE), SSL_SUCCESS);
  69975. pkcs7 = wolfSSL_SMIME_read_PKCS7(bio, &bcont);
  69976. ExpectNotNull(pkcs7); /* can read in the unverified smime bundle */
  69977. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, bcont, NULL,
  69978. PKCS7_NOVERIFY), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  69979. if (smimeTestFile != XBADFILE) {
  69980. XFCLOSE(smimeTestFile);
  69981. smimeTestFile = XBADFILE;
  69982. }
  69983. if (bcont) BIO_free(bcont);
  69984. bcont = NULL;
  69985. wolfSSL_PKCS7_free(pkcs7);
  69986. pkcs7 = NULL;
  69987. /* smime-test-canon.p7s */
  69988. smimeTestFile = XFOPEN("./certs/test/smime-test-canon.p7s", "r");
  69989. ExpectFalse(smimeTestFile == XBADFILE);
  69990. ExpectIntEQ(wolfSSL_BIO_set_fp(bio, smimeTestFile, BIO_CLOSE), SSL_SUCCESS);
  69991. pkcs7 = wolfSSL_SMIME_read_PKCS7(bio, &bcont);
  69992. ExpectNotNull(pkcs7);
  69993. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, bcont, NULL,
  69994. PKCS7_NOVERIFY), SSL_SUCCESS);
  69995. if (smimeTestFile != XBADFILE) {
  69996. XFCLOSE(smimeTestFile);
  69997. smimeTestFile = XBADFILE;
  69998. }
  69999. if (bcont) BIO_free(bcont);
  70000. bcont = NULL;
  70001. wolfSSL_PKCS7_free(pkcs7);
  70002. pkcs7 = NULL;
  70003. /* Test PKCS7_TEXT, PKCS7_verify() should remove Content-Type: text/plain */
  70004. smimeTestFile = XFOPEN("./certs/test/smime-test-canon.p7s", "r");
  70005. ExpectFalse(smimeTestFile == XBADFILE);
  70006. ExpectIntEQ(wolfSSL_BIO_set_fp(bio, smimeTestFile, BIO_CLOSE), SSL_SUCCESS);
  70007. pkcs7 = wolfSSL_SMIME_read_PKCS7(bio, &bcont);
  70008. ExpectNotNull(pkcs7);
  70009. out = wolfSSL_BIO_new(BIO_s_mem());
  70010. ExpectNotNull(out);
  70011. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, bcont, out,
  70012. PKCS7_NOVERIFY | PKCS7_TEXT), SSL_SUCCESS);
  70013. ExpectIntGT((outBufLen = BIO_get_mem_data(out, &outBuf)), 0);
  70014. /* Content-Type should not show up at beginning of output buffer */
  70015. ExpectIntGT(outBufLen, XSTRLEN(contTypeText));
  70016. ExpectIntGT(XMEMCMP(outBuf, contTypeText, XSTRLEN(contTypeText)), 0);
  70017. BIO_free(out);
  70018. BIO_free(bio);
  70019. if (bcont) BIO_free(bcont);
  70020. wolfSSL_PKCS7_free(pkcs7);
  70021. #endif
  70022. return EXPECT_RESULT();
  70023. }
  70024. /* // NOLINTEND(clang-analyzer-unix.Stream) */
  70025. static int test_wolfSSL_SMIME_write_PKCS7(void)
  70026. {
  70027. EXPECT_DECLS;
  70028. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7) && !defined(NO_RSA)
  70029. PKCS7* p7 = NULL;
  70030. PKCS7* p7Ver = NULL;
  70031. int flags = 0;
  70032. byte data[] = "Test data to encode.";
  70033. const char* cert = "./certs/server-cert.pem";
  70034. const char* key = "./certs/server-key.pem";
  70035. const char* ca = "./certs/ca-cert.pem";
  70036. WOLFSSL_BIO* certBio = NULL;
  70037. WOLFSSL_BIO* keyBio = NULL;
  70038. WOLFSSL_BIO* caBio = NULL;
  70039. WOLFSSL_BIO* inBio = NULL;
  70040. WOLFSSL_BIO* outBio = NULL;
  70041. WOLFSSL_BIO* content = NULL;
  70042. X509* signCert = NULL;
  70043. EVP_PKEY* signKey = NULL;
  70044. X509* caCert = NULL;
  70045. X509_STORE* store = NULL;
  70046. /* read signer cert/key into BIO */
  70047. ExpectNotNull(certBio = BIO_new_file(cert, "r"));
  70048. ExpectNotNull(keyBio = BIO_new_file(key, "r"));
  70049. ExpectNotNull(signCert = PEM_read_bio_X509(certBio, NULL, 0, NULL));
  70050. ExpectNotNull(signKey = PEM_read_bio_PrivateKey(keyBio, NULL, 0, NULL));
  70051. /* read CA cert into store (for verify) */
  70052. ExpectNotNull(caBio = BIO_new_file(ca, "r"));
  70053. ExpectNotNull(caCert = PEM_read_bio_X509(caBio, NULL, 0, NULL));
  70054. ExpectNotNull(store = X509_STORE_new());
  70055. ExpectIntEQ(X509_STORE_add_cert(store, caCert), 1);
  70056. /* generate and verify SMIME: not detached */
  70057. {
  70058. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  70059. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  70060. flags = PKCS7_STREAM;
  70061. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  70062. ExpectNotNull(outBio = BIO_new(BIO_s_mem()));
  70063. ExpectIntEQ(SMIME_write_PKCS7(outBio, p7, inBio, flags), 1);
  70064. /* bad arg: out NULL */
  70065. ExpectIntEQ(SMIME_write_PKCS7(NULL, p7, inBio, flags), 0);
  70066. /* bad arg: pkcs7 NULL */
  70067. ExpectIntEQ(SMIME_write_PKCS7(outBio, NULL, inBio, flags), 0);
  70068. ExpectNotNull(p7Ver = SMIME_read_PKCS7(outBio, &content));
  70069. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, NULL, NULL, flags), 1);
  70070. BIO_free(content);
  70071. content = NULL;
  70072. BIO_free(inBio);
  70073. inBio = NULL;
  70074. BIO_free(outBio);
  70075. outBio = NULL;
  70076. PKCS7_free(p7Ver);
  70077. p7Ver = NULL;
  70078. PKCS7_free(p7);
  70079. p7 = NULL;
  70080. }
  70081. /* generate and verify SMIME: not detached, add Content-Type */
  70082. {
  70083. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  70084. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  70085. flags = PKCS7_STREAM | PKCS7_TEXT;
  70086. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  70087. ExpectNotNull(outBio = BIO_new(BIO_s_mem()));
  70088. ExpectIntEQ(SMIME_write_PKCS7(outBio, p7, inBio, flags), 1);
  70089. ExpectNotNull(p7Ver = SMIME_read_PKCS7(outBio, &content));
  70090. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, NULL, NULL, flags), 1);
  70091. BIO_free(content);
  70092. content = NULL;
  70093. BIO_free(inBio);
  70094. inBio = NULL;
  70095. BIO_free(outBio);
  70096. outBio = NULL;
  70097. PKCS7_free(p7Ver);
  70098. p7Ver = NULL;
  70099. PKCS7_free(p7);
  70100. p7 = NULL;
  70101. }
  70102. /* generate and verify SMIME: detached */
  70103. {
  70104. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  70105. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  70106. flags = PKCS7_DETACHED | PKCS7_STREAM;
  70107. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  70108. ExpectNotNull(outBio = BIO_new(BIO_s_mem()));
  70109. ExpectIntEQ(SMIME_write_PKCS7(outBio, p7, inBio, flags), 1);
  70110. ExpectNotNull(p7Ver = SMIME_read_PKCS7(outBio, &content));
  70111. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, content, NULL, flags), 1);
  70112. BIO_free(content);
  70113. content = NULL;
  70114. BIO_free(inBio);
  70115. inBio = NULL;
  70116. BIO_free(outBio);
  70117. outBio = NULL;
  70118. PKCS7_free(p7Ver);
  70119. p7Ver = NULL;
  70120. PKCS7_free(p7);
  70121. p7 = NULL;
  70122. }
  70123. /* generate and verify SMIME: PKCS7_TEXT to add Content-Type header */
  70124. {
  70125. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  70126. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  70127. flags = PKCS7_STREAM | PKCS7_DETACHED | PKCS7_TEXT;
  70128. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  70129. ExpectNotNull(outBio = BIO_new(BIO_s_mem()));
  70130. ExpectIntEQ(SMIME_write_PKCS7(outBio, p7, inBio, flags), 1);
  70131. ExpectNotNull(p7Ver = SMIME_read_PKCS7(outBio, &content));
  70132. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, content, NULL, flags), 1);
  70133. BIO_free(content);
  70134. content = NULL;
  70135. BIO_free(inBio);
  70136. inBio = NULL;
  70137. BIO_free(outBio);
  70138. outBio = NULL;
  70139. PKCS7_free(p7Ver);
  70140. p7Ver = NULL;
  70141. PKCS7_free(p7);
  70142. p7 = NULL;
  70143. }
  70144. X509_STORE_free(store);
  70145. X509_free(caCert);
  70146. X509_free(signCert);
  70147. EVP_PKEY_free(signKey);
  70148. BIO_free(keyBio);
  70149. BIO_free(certBio);
  70150. BIO_free(caBio);
  70151. #endif
  70152. return EXPECT_RESULT();
  70153. }
  70154. #endif /* HAVE_SMIME */
  70155. #endif /* !NO_BIO */
  70156. /* Test of X509 store use outside of SSL context w/ CRL lookup (ALWAYS
  70157. * returns 0) */
  70158. static int test_X509_STORE_No_SSL_CTX(void)
  70159. {
  70160. EXPECT_DECLS;
  70161. #if defined(OPENSSL_ALL) && defined(WOLFSSL_CERT_GEN) && \
  70162. (defined(WOLFSSL_CERT_REQ) || defined(WOLFSSL_CERT_EXT)) && \
  70163. !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_DIR) && \
  70164. (defined(OPENSSL_EXTRA) || defined(WOLFSSL_WPAS_SMALL)) && \
  70165. defined(HAVE_CRL) && !defined(NO_RSA)
  70166. X509_STORE * store = NULL;
  70167. X509_STORE_CTX * storeCtx = NULL;
  70168. X509_CRL * crl = NULL;
  70169. X509 * ca = NULL;
  70170. X509 * cert = NULL;
  70171. const char cliCrlPem[] = "./certs/crl/cliCrl.pem";
  70172. const char srvCert[] = "./certs/server-cert.pem";
  70173. const char caCert[] = "./certs/ca-cert.pem";
  70174. const char caDir[] = "./certs/crl/hash_pem";
  70175. XFILE fp = XBADFILE;
  70176. X509_LOOKUP * lookup = NULL;
  70177. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  70178. /* Set up store with CA */
  70179. ExpectNotNull((ca = wolfSSL_X509_load_certificate_file(caCert,
  70180. SSL_FILETYPE_PEM)));
  70181. ExpectIntEQ(X509_STORE_add_cert(store, ca), SSL_SUCCESS);
  70182. /* Add CRL lookup directory to store
  70183. * NOTE: test uses ./certs/crl/hash_pem/0fdb2da4.r0, which is a copy
  70184. * of crl.pem */
  70185. ExpectNotNull((lookup = X509_STORE_add_lookup(store,
  70186. X509_LOOKUP_hash_dir())));
  70187. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_ADD_DIR, caDir,
  70188. X509_FILETYPE_PEM, NULL), SSL_SUCCESS);
  70189. ExpectIntEQ(X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK),
  70190. SSL_SUCCESS);
  70191. /* Add CRL to store NOT containing the verified certificate, which
  70192. * forces use of the CRL lookup directory */
  70193. ExpectTrue((fp = XFOPEN(cliCrlPem, "rb")) != XBADFILE);
  70194. ExpectNotNull(crl = (X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  70195. NULL, NULL));
  70196. if (fp != XBADFILE)
  70197. XFCLOSE(fp);
  70198. ExpectIntEQ(X509_STORE_add_crl(store, crl), SSL_SUCCESS);
  70199. /* Create verification context outside of an SSL session */
  70200. ExpectNotNull((storeCtx = X509_STORE_CTX_new()));
  70201. ExpectNotNull((cert = wolfSSL_X509_load_certificate_file(srvCert,
  70202. SSL_FILETYPE_PEM)));
  70203. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, cert, NULL), SSL_SUCCESS);
  70204. /* Perform verification, which should NOT indicate CRL missing due to the
  70205. * store CM's X509 store pointer being NULL */
  70206. ExpectIntNE(X509_verify_cert(storeCtx), WC_NO_ERR_TRACE(CRL_MISSING));
  70207. X509_CRL_free(crl);
  70208. X509_STORE_free(store);
  70209. X509_STORE_CTX_free(storeCtx);
  70210. X509_free(cert);
  70211. X509_free(ca);
  70212. #endif
  70213. return EXPECT_RESULT();
  70214. }
  70215. /* Test of X509 store use outside of SSL context w/ CRL lookup, but
  70216. * with X509_LOOKUP_add_dir and X509_FILETYPE_ASN1. */
  70217. static int test_X509_LOOKUP_add_dir(void)
  70218. {
  70219. EXPECT_DECLS;
  70220. #if defined(OPENSSL_ALL) && defined(WOLFSSL_CERT_GEN) && \
  70221. (defined(WOLFSSL_CERT_REQ) || defined(WOLFSSL_CERT_EXT)) && \
  70222. !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_DIR) && \
  70223. (defined(OPENSSL_EXTRA) || defined(WOLFSSL_WPAS_SMALL)) && \
  70224. defined(HAVE_CRL) && !defined(NO_RSA)
  70225. X509_STORE * store = NULL;
  70226. X509_STORE_CTX * storeCtx = NULL;
  70227. X509_CRL * crl = NULL;
  70228. X509 * ca = NULL;
  70229. X509 * cert = NULL;
  70230. const char cliCrlPem[] = "./certs/crl/cliCrl.pem";
  70231. const char srvCert[] = "./certs/server-cert.pem";
  70232. const char caCert[] = "./certs/ca-cert.pem";
  70233. const char caDir[] = "./certs/crl/hash_der";
  70234. XFILE fp = XBADFILE;
  70235. X509_LOOKUP * lookup = NULL;
  70236. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  70237. /* Set up store with CA */
  70238. ExpectNotNull((ca = wolfSSL_X509_load_certificate_file(caCert,
  70239. SSL_FILETYPE_PEM)));
  70240. ExpectIntEQ(X509_STORE_add_cert(store, ca), SSL_SUCCESS);
  70241. /* Add CRL lookup directory to store.
  70242. * Test uses ./certs/crl/hash_der/0fdb2da4.r0, which is a copy
  70243. * of crl.der */
  70244. ExpectNotNull((lookup = X509_STORE_add_lookup(store,
  70245. X509_LOOKUP_hash_dir())));
  70246. ExpectIntEQ(X509_LOOKUP_add_dir(lookup, caDir, X509_FILETYPE_ASN1),
  70247. SSL_SUCCESS);
  70248. ExpectIntEQ(X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK),
  70249. SSL_SUCCESS);
  70250. /* Add CRL to store NOT containing the verified certificate, which
  70251. * forces use of the CRL lookup directory */
  70252. ExpectTrue((fp = XFOPEN(cliCrlPem, "rb")) != XBADFILE);
  70253. ExpectNotNull(crl = (X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  70254. NULL, NULL));
  70255. if (fp != XBADFILE) {
  70256. XFCLOSE(fp);
  70257. fp = XBADFILE;
  70258. }
  70259. ExpectIntEQ(X509_STORE_add_crl(store, crl), SSL_SUCCESS);
  70260. /* Create verification context outside of an SSL session */
  70261. ExpectNotNull((storeCtx = X509_STORE_CTX_new()));
  70262. ExpectNotNull((cert = wolfSSL_X509_load_certificate_file(srvCert,
  70263. SSL_FILETYPE_PEM)));
  70264. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, cert, NULL), SSL_SUCCESS);
  70265. /* Perform verification, which should NOT return CRL missing */
  70266. ExpectIntNE(X509_verify_cert(storeCtx), WC_NO_ERR_TRACE(CRL_MISSING));
  70267. X509_CRL_free(crl);
  70268. crl = NULL;
  70269. X509_STORE_free(store);
  70270. store = NULL;
  70271. X509_STORE_CTX_free(storeCtx);
  70272. storeCtx = NULL;
  70273. X509_free(cert);
  70274. cert = NULL;
  70275. X509_free(ca);
  70276. ca = NULL;
  70277. /* Now repeat the same, but look for X509_FILETYPE_PEM.
  70278. * We should get CRL_MISSING at the end, because the lookup
  70279. * dir has only ASN1 CRLs. */
  70280. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  70281. ExpectNotNull((ca = wolfSSL_X509_load_certificate_file(caCert,
  70282. SSL_FILETYPE_PEM)));
  70283. ExpectIntEQ(X509_STORE_add_cert(store, ca), SSL_SUCCESS);
  70284. ExpectNotNull((lookup = X509_STORE_add_lookup(store,
  70285. X509_LOOKUP_hash_dir())));
  70286. ExpectIntEQ(X509_LOOKUP_add_dir(lookup, caDir, X509_FILETYPE_PEM),
  70287. SSL_SUCCESS);
  70288. ExpectIntEQ(X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK),
  70289. SSL_SUCCESS);
  70290. ExpectTrue((fp = XFOPEN(cliCrlPem, "rb")) != XBADFILE);
  70291. ExpectNotNull(crl = (X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  70292. NULL, NULL));
  70293. if (fp != XBADFILE) {
  70294. XFCLOSE(fp);
  70295. fp = XBADFILE;
  70296. }
  70297. ExpectIntEQ(X509_STORE_add_crl(store, crl), SSL_SUCCESS);
  70298. ExpectNotNull((storeCtx = X509_STORE_CTX_new()));
  70299. ExpectNotNull((cert = wolfSSL_X509_load_certificate_file(srvCert,
  70300. SSL_FILETYPE_PEM)));
  70301. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, cert, NULL), SSL_SUCCESS);
  70302. /* Now we SHOULD get CRL_MISSING, because we looked for PEM
  70303. * in dir containing only ASN1/DER. */
  70304. ExpectIntEQ(X509_verify_cert(storeCtx), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70305. ExpectIntEQ(X509_STORE_CTX_get_error(storeCtx),
  70306. X509_V_ERR_UNABLE_TO_GET_CRL);
  70307. X509_CRL_free(crl);
  70308. X509_STORE_free(store);
  70309. X509_STORE_CTX_free(storeCtx);
  70310. X509_free(cert);
  70311. X509_free(ca);
  70312. #endif
  70313. return EXPECT_RESULT();
  70314. }
  70315. /*----------------------------------------------------------------------------*
  70316. | Certificate Failure Checks
  70317. *----------------------------------------------------------------------------*/
  70318. #if !defined(NO_CERTS) && (!defined(NO_WOLFSSL_CLIENT) || \
  70319. !defined(WOLFSSL_NO_CLIENT_AUTH)) && !defined(NO_FILESYSTEM)
  70320. #if !defined(NO_RSA) || defined(HAVE_ECC)
  70321. /* Use the Cert Manager(CM) API to generate the error ASN_SIG_CONFIRM_E */
  70322. static int verify_sig_cm(const char* ca, byte* cert_buf, size_t cert_sz,
  70323. int type)
  70324. {
  70325. int ret;
  70326. WOLFSSL_CERT_MANAGER* cm = NULL;
  70327. switch (type) {
  70328. case TESTING_RSA:
  70329. #ifdef NO_RSA
  70330. fprintf(stderr, "RSA disabled, skipping test\n");
  70331. return ASN_SIG_CONFIRM_E;
  70332. #else
  70333. break;
  70334. #endif
  70335. case TESTING_ECC:
  70336. #ifndef HAVE_ECC
  70337. fprintf(stderr, "ECC disabled, skipping test\n");
  70338. return ASN_SIG_CONFIRM_E;
  70339. #else
  70340. break;
  70341. #endif
  70342. default:
  70343. fprintf(stderr, "Bad function argument\n");
  70344. return BAD_FUNC_ARG;
  70345. }
  70346. cm = wolfSSL_CertManagerNew();
  70347. if (cm == NULL) {
  70348. fprintf(stderr, "wolfSSL_CertManagerNew failed\n");
  70349. return -1;
  70350. }
  70351. #ifndef NO_FILESYSTEM
  70352. ret = wolfSSL_CertManagerLoadCA(cm, ca, 0);
  70353. if (ret != WOLFSSL_SUCCESS) {
  70354. fprintf(stderr, "wolfSSL_CertManagerLoadCA failed\n");
  70355. wolfSSL_CertManagerFree(cm);
  70356. return ret;
  70357. }
  70358. #else
  70359. (void)ca;
  70360. #endif
  70361. ret = wolfSSL_CertManagerVerifyBuffer(cm, cert_buf, (long int)cert_sz,
  70362. WOLFSSL_FILETYPE_ASN1);
  70363. /* Let ExpectIntEQ handle return code */
  70364. wolfSSL_CertManagerFree(cm);
  70365. return ret;
  70366. }
  70367. #endif
  70368. #if !defined(NO_FILESYSTEM)
  70369. static int test_RsaSigFailure_cm(void)
  70370. {
  70371. EXPECT_DECLS;
  70372. #ifndef NO_RSA
  70373. const char* ca_cert = "./certs/ca-cert.pem";
  70374. const char* server_cert = "./certs/server-cert.der";
  70375. byte* cert_buf = NULL;
  70376. size_t cert_sz = 0;
  70377. ExpectIntEQ(load_file(server_cert, &cert_buf, &cert_sz), 0);
  70378. if ((cert_buf != NULL) && (cert_sz > 0)) {
  70379. /* corrupt DER - invert last byte, which is signature */
  70380. cert_buf[cert_sz-1] = ~cert_buf[cert_sz-1];
  70381. /* test bad cert */
  70382. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  70383. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_RSA),
  70384. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  70385. #elif defined(NO_ASN_CRYPT)
  70386. /* RSA verify is not called when ASN crypt support is disabled */
  70387. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_RSA),
  70388. WOLFSSL_SUCCESS);
  70389. #else
  70390. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_RSA),
  70391. WC_NO_ERR_TRACE(ASN_SIG_CONFIRM_E));
  70392. #endif
  70393. }
  70394. /* load_file() uses malloc. */
  70395. if (cert_buf != NULL) {
  70396. free(cert_buf);
  70397. }
  70398. #endif /* !NO_RSA */
  70399. return EXPECT_RESULT();
  70400. }
  70401. static int test_EccSigFailure_cm(void)
  70402. {
  70403. EXPECT_DECLS;
  70404. #ifdef HAVE_ECC
  70405. /* self-signed ECC cert, so use server cert as CA */
  70406. const char* ca_cert = "./certs/ca-ecc-cert.pem";
  70407. const char* server_cert = "./certs/server-ecc.der";
  70408. byte* cert_buf = NULL;
  70409. size_t cert_sz = 0;
  70410. ExpectIntEQ(load_file(server_cert, &cert_buf, &cert_sz), 0);
  70411. if (cert_buf != NULL && cert_sz > 0) {
  70412. /* corrupt DER - invert last byte, which is signature */
  70413. cert_buf[cert_sz-1] = ~cert_buf[cert_sz-1];
  70414. /* test bad cert */
  70415. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  70416. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_ECC),
  70417. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  70418. #elif defined(NO_ASN_CRYPT)
  70419. /* ECC verify is not called when ASN crypt support is disabled */
  70420. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_ECC),
  70421. WOLFSSL_SUCCESS);
  70422. #else
  70423. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_ECC),
  70424. WC_NO_ERR_TRACE(ASN_SIG_CONFIRM_E));
  70425. #endif
  70426. }
  70427. /* load_file() uses malloc. */
  70428. if (cert_buf != NULL) {
  70429. free(cert_buf);
  70430. }
  70431. #ifdef FP_ECC
  70432. wc_ecc_fp_free();
  70433. #endif
  70434. #endif /* HAVE_ECC */
  70435. return EXPECT_RESULT();
  70436. }
  70437. #endif /* !NO_FILESYSTEM */
  70438. #endif /* NO_CERTS */
  70439. #ifdef WOLFSSL_TLS13
  70440. #if defined(WOLFSSL_SEND_HRR_COOKIE) && !defined(NO_WOLFSSL_SERVER)
  70441. #ifdef WC_SHA384_DIGEST_SIZE
  70442. static byte fixedKey[WC_SHA384_DIGEST_SIZE] = { 0, };
  70443. #else
  70444. static byte fixedKey[WC_SHA256_DIGEST_SIZE] = { 0, };
  70445. #endif
  70446. #endif
  70447. #ifdef WOLFSSL_EARLY_DATA
  70448. static const char earlyData[] = "Early Data";
  70449. static char earlyDataBuffer[1];
  70450. #endif
  70451. static int test_tls13_apis(void)
  70452. {
  70453. EXPECT_DECLS;
  70454. int ret;
  70455. #ifndef WOLFSSL_NO_TLS12
  70456. #ifndef NO_WOLFSSL_CLIENT
  70457. WOLFSSL_CTX* clientTls12Ctx = NULL;
  70458. WOLFSSL* clientTls12Ssl = NULL;
  70459. #endif
  70460. #ifndef NO_WOLFSSL_SERVER
  70461. WOLFSSL_CTX* serverTls12Ctx = NULL;
  70462. WOLFSSL* serverTls12Ssl = NULL;
  70463. #endif
  70464. #endif
  70465. #ifndef NO_WOLFSSL_CLIENT
  70466. WOLFSSL_CTX* clientCtx = NULL;
  70467. WOLFSSL* clientSsl = NULL;
  70468. #endif
  70469. #ifndef NO_WOLFSSL_SERVER
  70470. WOLFSSL_CTX* serverCtx = NULL;
  70471. WOLFSSL* serverSsl = NULL;
  70472. #if !defined(NO_CERTS) && !defined(NO_FILESYSTEM)
  70473. const char* ourCert = svrCertFile;
  70474. const char* ourKey = svrKeyFile;
  70475. #endif
  70476. #endif
  70477. int required;
  70478. #ifdef WOLFSSL_EARLY_DATA
  70479. int outSz;
  70480. #endif
  70481. #if defined(HAVE_ECC) && defined(HAVE_SUPPORTED_CURVES)
  70482. int groups[2] = { WOLFSSL_ECC_SECP256R1,
  70483. #ifdef WOLFSSL_HAVE_KYBER
  70484. #ifndef WOLFSSL_NO_KYBER512
  70485. WOLFSSL_KYBER_LEVEL1
  70486. #elif !defined(WOLFSSL_NO_KYBER768)
  70487. WOLFSSL_KYBER_LEVEL3
  70488. #else
  70489. WOLFSSL_KYBER_LEVEL5
  70490. #endif
  70491. #else
  70492. WOLFSSL_ECC_SECP256R1
  70493. #endif
  70494. };
  70495. #if !defined(NO_WOLFSSL_SERVER) || !defined(NO_WOLFSSL_CLIENT)
  70496. int bad_groups[2] = { 0xDEAD, 0xBEEF };
  70497. #endif /* !NO_WOLFSSL_SERVER || !NO_WOLFSSL_CLIENT */
  70498. int numGroups = 2;
  70499. #endif
  70500. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  70501. char groupList[] =
  70502. #ifdef HAVE_CURVE25519
  70503. "X25519:"
  70504. #endif
  70505. #ifdef HAVE_CURVE448
  70506. "X448:"
  70507. #endif
  70508. #ifndef NO_ECC_SECP
  70509. #if (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 521
  70510. "P-521:secp521r1:"
  70511. #endif
  70512. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 384
  70513. "P-384:secp384r1:"
  70514. #endif
  70515. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  70516. "P-256:secp256r1"
  70517. #if defined(WOLFSSL_HAVE_KYBER)
  70518. #ifndef WOLFSSL_NO_KYBER512
  70519. ":P256_KYBER_LEVEL1"
  70520. #elif !defined(WOLFSSL_NO_KYBER768)
  70521. ":P256_KYBER_LEVEL3"
  70522. #else
  70523. ":P256_KYBER_LEVEL5"
  70524. #endif
  70525. #endif
  70526. #endif
  70527. #endif /* !defined(NO_ECC_SECP) */
  70528. #if defined(WOLFSSL_HAVE_KYBER)
  70529. #ifndef WOLFSSL_NO_KYBER512
  70530. ":KYBER_LEVEL1"
  70531. #elif !defined(WOLFSSL_NO_KYBER768)
  70532. ":KYBER_LEVEL3"
  70533. #else
  70534. ":KYBER_LEVEL5"
  70535. #endif
  70536. #endif
  70537. "";
  70538. #endif /* defined(OPENSSL_EXTRA) && defined(HAVE_ECC) */
  70539. #if defined(WOLFSSL_HAVE_KYBER)
  70540. int kyberLevel;
  70541. #endif
  70542. (void)ret;
  70543. #ifndef WOLFSSL_NO_TLS12
  70544. #ifndef NO_WOLFSSL_CLIENT
  70545. clientTls12Ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method());
  70546. clientTls12Ssl = wolfSSL_new(clientTls12Ctx);
  70547. #endif
  70548. #ifndef NO_WOLFSSL_SERVER
  70549. serverTls12Ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method());
  70550. #if !defined(NO_CERTS) && !defined(NO_FILESYSTEM)
  70551. wolfSSL_CTX_use_certificate_chain_file(serverTls12Ctx, ourCert);
  70552. wolfSSL_CTX_use_PrivateKey_file(serverTls12Ctx, ourKey,
  70553. WOLFSSL_FILETYPE_PEM);
  70554. #endif
  70555. serverTls12Ssl = wolfSSL_new(serverTls12Ctx);
  70556. #endif
  70557. #endif
  70558. #ifndef NO_WOLFSSL_CLIENT
  70559. clientCtx = wolfSSL_CTX_new(wolfTLSv1_3_client_method());
  70560. clientSsl = wolfSSL_new(clientCtx);
  70561. #endif
  70562. #ifndef NO_WOLFSSL_SERVER
  70563. serverCtx = wolfSSL_CTX_new(wolfTLSv1_3_server_method());
  70564. #if !defined(NO_CERTS) && !defined(NO_FILESYSTEM)
  70565. wolfSSL_CTX_use_certificate_chain_file(serverCtx, ourCert);
  70566. wolfSSL_CTX_use_PrivateKey_file(serverCtx, ourKey, WOLFSSL_FILETYPE_PEM);
  70567. #endif
  70568. serverSsl = wolfSSL_new(serverCtx);
  70569. ExpectNotNull(serverSsl);
  70570. #endif
  70571. #ifdef WOLFSSL_SEND_HRR_COOKIE
  70572. ExpectIntEQ(wolfSSL_send_hrr_cookie(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70573. #ifndef NO_WOLFSSL_CLIENT
  70574. ExpectIntEQ(wolfSSL_send_hrr_cookie(clientSsl, NULL, 0), WC_NO_ERR_TRACE(SIDE_ERROR));
  70575. #endif
  70576. #ifndef NO_WOLFSSL_SERVER
  70577. #ifndef WOLFSSL_NO_TLS12
  70578. ExpectIntEQ(wolfSSL_send_hrr_cookie(serverTls12Ssl, NULL, 0),
  70579. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70580. #endif
  70581. ExpectIntEQ(wolfSSL_send_hrr_cookie(serverSsl, NULL, 0), WOLFSSL_SUCCESS);
  70582. ExpectIntEQ(wolfSSL_send_hrr_cookie(serverSsl, fixedKey, sizeof(fixedKey)),
  70583. WOLFSSL_SUCCESS);
  70584. #endif
  70585. #endif
  70586. #ifdef HAVE_SUPPORTED_CURVES
  70587. #ifdef HAVE_ECC
  70588. ExpectIntEQ(wolfSSL_UseKeyShare(NULL, WOLFSSL_ECC_SECP256R1),
  70589. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70590. #ifndef NO_WOLFSSL_SERVER
  70591. do {
  70592. ret = wolfSSL_UseKeyShare(serverSsl, WOLFSSL_ECC_SECP256R1);
  70593. #ifdef WOLFSSL_ASYNC_CRYPT
  70594. if (ret == WC_NO_ERR_TRACE(WC_PENDING_E))
  70595. wolfSSL_AsyncPoll(serverSsl, WOLF_POLL_FLAG_CHECK_HW);
  70596. #endif
  70597. }
  70598. while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  70599. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  70600. #endif
  70601. #ifndef NO_WOLFSSL_CLIENT
  70602. #ifndef WOLFSSL_NO_TLS12
  70603. do {
  70604. ret = wolfSSL_UseKeyShare(clientTls12Ssl, WOLFSSL_ECC_SECP256R1);
  70605. #ifdef WOLFSSL_ASYNC_CRYPT
  70606. if (ret == WC_NO_ERR_TRACE(WC_PENDING_E))
  70607. wolfSSL_AsyncPoll(clientTls12Ssl, WOLF_POLL_FLAG_CHECK_HW);
  70608. #endif
  70609. }
  70610. while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  70611. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  70612. #endif
  70613. do {
  70614. ret = wolfSSL_UseKeyShare(clientSsl, WOLFSSL_ECC_SECP256R1);
  70615. #ifdef WOLFSSL_ASYNC_CRYPT
  70616. if (ret == WC_NO_ERR_TRACE(WC_PENDING_E))
  70617. wolfSSL_AsyncPoll(clientSsl, WOLF_POLL_FLAG_CHECK_HW);
  70618. #endif
  70619. }
  70620. while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  70621. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  70622. #endif
  70623. #elif defined(HAVE_CURVE25519)
  70624. ExpectIntEQ(wolfSSL_UseKeyShare(NULL, WOLFSSL_ECC_X25519), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70625. #ifndef NO_WOLFSSL_SERVER
  70626. ExpectIntEQ(wolfSSL_UseKeyShare(serverSsl, WOLFSSL_ECC_X25519),
  70627. WOLFSSL_SUCCESS);
  70628. #endif
  70629. #ifndef NO_WOLFSSL_CLIENT
  70630. #ifndef WOLFSSL_NO_TLS12
  70631. ExpectIntEQ(wolfSSL_UseKeyShare(clientTls12Ssl, WOLFSSL_ECC_X25519),
  70632. WOLFSSL_SUCCESS);
  70633. #endif
  70634. ExpectIntEQ(wolfSSL_UseKeyShare(clientSsl, WOLFSSL_ECC_X25519),
  70635. WOLFSSL_SUCCESS);
  70636. #endif
  70637. #elif defined(HAVE_CURVE448)
  70638. ExpectIntEQ(wolfSSL_UseKeyShare(NULL, WOLFSSL_ECC_X448), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70639. #ifndef NO_WOLFSSL_SERVER
  70640. ExpectIntEQ(wolfSSL_UseKeyShare(serverSsl, WOLFSSL_ECC_X448),
  70641. WOLFSSL_SUCCESS);
  70642. #endif
  70643. #ifndef NO_WOLFSSL_CLIENT
  70644. #ifndef WOLFSSL_NO_TLS12
  70645. ExpectIntEQ(wolfSSL_UseKeyShare(clientTls12Ssl, WOLFSSL_ECC_X448),
  70646. WOLFSSL_SUCCESS);
  70647. #endif
  70648. ExpectIntEQ(wolfSSL_UseKeyShare(clientSsl, WOLFSSL_ECC_X448),
  70649. WOLFSSL_SUCCESS);
  70650. #endif
  70651. #else
  70652. ExpectIntEQ(wolfSSL_UseKeyShare(NULL, WOLFSSL_ECC_SECP256R1),
  70653. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70654. #ifndef NO_WOLFSSL_CLIENT
  70655. #ifndef WOLFSSL_NO_TLS12
  70656. ExpectIntEQ(wolfSSL_UseKeyShare(clientTls12Ssl, WOLFSSL_ECC_SECP256R1),
  70657. WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  70658. #endif
  70659. ExpectIntEQ(wolfSSL_UseKeyShare(clientSsl, WOLFSSL_ECC_SECP256R1),
  70660. WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  70661. #endif
  70662. #endif
  70663. #if defined(WOLFSSL_HAVE_KYBER)
  70664. #ifndef WOLFSSL_NO_KYBER768
  70665. kyberLevel = WOLFSSL_KYBER_LEVEL3;
  70666. #elif !defined(WOLFSSL_NO_KYBER1024)
  70667. kyberLevel = WOLFSSL_KYBER_LEVEL5;
  70668. #else
  70669. kyberLevel = WOLFSSL_KYBER_LEVEL1;
  70670. #endif
  70671. ExpectIntEQ(wolfSSL_UseKeyShare(NULL, kyberLevel), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70672. #ifndef NO_WOLFSSL_SERVER
  70673. ExpectIntEQ(wolfSSL_UseKeyShare(serverSsl, kyberLevel),
  70674. WOLFSSL_SUCCESS);
  70675. #endif
  70676. #ifndef NO_WOLFSSL_CLIENT
  70677. #ifndef WOLFSSL_NO_TLS12
  70678. ExpectIntEQ(wolfSSL_UseKeyShare(clientTls12Ssl, kyberLevel),
  70679. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70680. #endif
  70681. ExpectIntEQ(wolfSSL_UseKeyShare(clientSsl, kyberLevel),
  70682. WOLFSSL_SUCCESS);
  70683. #endif
  70684. #endif
  70685. ExpectIntEQ(wolfSSL_NoKeyShares(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70686. #ifndef NO_WOLFSSL_SERVER
  70687. ExpectIntEQ(wolfSSL_NoKeyShares(serverSsl), WC_NO_ERR_TRACE(SIDE_ERROR));
  70688. #endif
  70689. #ifndef NO_WOLFSSL_CLIENT
  70690. #ifndef WOLFSSL_NO_TLS12
  70691. ExpectIntEQ(wolfSSL_NoKeyShares(clientTls12Ssl), WOLFSSL_SUCCESS);
  70692. #endif
  70693. ExpectIntEQ(wolfSSL_NoKeyShares(clientSsl), WOLFSSL_SUCCESS);
  70694. #endif
  70695. #endif /* HAVE_SUPPORTED_CURVES */
  70696. ExpectIntEQ(wolfSSL_CTX_no_ticket_TLSv13(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70697. #ifndef NO_WOLFSSL_CLIENT
  70698. ExpectIntEQ(wolfSSL_CTX_no_ticket_TLSv13(clientCtx), WC_NO_ERR_TRACE(SIDE_ERROR));
  70699. #endif
  70700. #ifndef NO_WOLFSSL_SERVER
  70701. #ifndef WOLFSSL_NO_TLS12
  70702. ExpectIntEQ(wolfSSL_CTX_no_ticket_TLSv13(serverTls12Ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70703. #endif
  70704. ExpectIntEQ(wolfSSL_CTX_no_ticket_TLSv13(serverCtx), 0);
  70705. #endif
  70706. ExpectIntEQ(wolfSSL_no_ticket_TLSv13(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70707. #ifndef NO_WOLFSSL_CLIENT
  70708. ExpectIntEQ(wolfSSL_no_ticket_TLSv13(clientSsl), WC_NO_ERR_TRACE(SIDE_ERROR));
  70709. #endif
  70710. #ifndef NO_WOLFSSL_SERVER
  70711. #ifndef WOLFSSL_NO_TLS12
  70712. ExpectIntEQ(wolfSSL_no_ticket_TLSv13(serverTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70713. #endif
  70714. ExpectIntEQ(wolfSSL_no_ticket_TLSv13(serverSsl), 0);
  70715. #endif
  70716. ExpectIntEQ(wolfSSL_CTX_no_dhe_psk(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70717. #ifndef NO_WOLFSSL_CLIENT
  70718. #ifndef WOLFSSL_NO_TLS12
  70719. ExpectIntEQ(wolfSSL_CTX_no_dhe_psk(clientTls12Ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70720. #endif
  70721. ExpectIntEQ(wolfSSL_CTX_no_dhe_psk(clientCtx), 0);
  70722. #endif
  70723. #ifndef NO_WOLFSSL_SERVER
  70724. ExpectIntEQ(wolfSSL_CTX_no_dhe_psk(serverCtx), 0);
  70725. #endif
  70726. ExpectIntEQ(wolfSSL_no_dhe_psk(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70727. #ifndef NO_WOLFSSL_CLIENT
  70728. #ifndef WOLFSSL_NO_TLS12
  70729. ExpectIntEQ(wolfSSL_no_dhe_psk(clientTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70730. #endif
  70731. ExpectIntEQ(wolfSSL_no_dhe_psk(clientSsl), 0);
  70732. #endif
  70733. #ifndef NO_WOLFSSL_SERVER
  70734. ExpectIntEQ(wolfSSL_no_dhe_psk(serverSsl), 0);
  70735. #endif
  70736. ExpectIntEQ(wolfSSL_update_keys(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70737. #ifndef NO_WOLFSSL_CLIENT
  70738. #ifndef WOLFSSL_NO_TLS12
  70739. ExpectIntEQ(wolfSSL_update_keys(clientTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70740. #endif
  70741. ExpectIntEQ(wolfSSL_update_keys(clientSsl), WC_NO_ERR_TRACE(BUILD_MSG_ERROR));
  70742. #endif
  70743. #ifndef NO_WOLFSSL_SERVER
  70744. ExpectIntEQ(wolfSSL_update_keys(serverSsl), WC_NO_ERR_TRACE(BUILD_MSG_ERROR));
  70745. #endif
  70746. ExpectIntEQ(wolfSSL_key_update_response(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70747. ExpectIntEQ(wolfSSL_key_update_response(NULL, &required), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70748. #ifndef NO_WOLFSSL_CLIENT
  70749. #ifndef WOLFSSL_NO_TLS12
  70750. ExpectIntEQ(wolfSSL_key_update_response(clientTls12Ssl, &required),
  70751. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70752. #endif
  70753. ExpectIntEQ(wolfSSL_key_update_response(clientSsl, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70754. #endif
  70755. #ifndef NO_WOLFSSL_SERVER
  70756. ExpectIntEQ(wolfSSL_key_update_response(serverSsl, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70757. #endif
  70758. #if !defined(NO_CERTS) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
  70759. ExpectIntEQ(wolfSSL_CTX_allow_post_handshake_auth(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70760. #ifndef NO_WOLFSSL_SERVER
  70761. ExpectIntEQ(wolfSSL_CTX_allow_post_handshake_auth(serverCtx), WC_NO_ERR_TRACE(SIDE_ERROR));
  70762. #endif
  70763. #ifndef NO_WOLFSSL_CLIENT
  70764. #ifndef WOLFSSL_NO_TLS12
  70765. ExpectIntEQ(wolfSSL_CTX_allow_post_handshake_auth(clientTls12Ctx),
  70766. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70767. #endif
  70768. ExpectIntEQ(wolfSSL_CTX_allow_post_handshake_auth(clientCtx), 0);
  70769. #endif
  70770. ExpectIntEQ(wolfSSL_allow_post_handshake_auth(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70771. #ifndef NO_WOLFSSL_SERVER
  70772. ExpectIntEQ(wolfSSL_allow_post_handshake_auth(serverSsl), WC_NO_ERR_TRACE(SIDE_ERROR));
  70773. #endif
  70774. #ifndef NO_WOLFSSL_CLIENT
  70775. #ifndef WOLFSSL_NO_TLS12
  70776. ExpectIntEQ(wolfSSL_allow_post_handshake_auth(clientTls12Ssl),
  70777. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70778. #endif
  70779. ExpectIntEQ(wolfSSL_allow_post_handshake_auth(clientSsl), 0);
  70780. #endif
  70781. ExpectIntEQ(wolfSSL_request_certificate(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70782. #ifndef NO_WOLFSSL_CLIENT
  70783. ExpectIntEQ(wolfSSL_request_certificate(clientSsl), WC_NO_ERR_TRACE(SIDE_ERROR));
  70784. #endif
  70785. #ifndef NO_WOLFSSL_SERVER
  70786. #ifndef WOLFSSL_NO_TLS12
  70787. ExpectIntEQ(wolfSSL_request_certificate(serverTls12Ssl),
  70788. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70789. #endif
  70790. ExpectIntEQ(wolfSSL_request_certificate(serverSsl), WC_NO_ERR_TRACE(NOT_READY_ERROR));
  70791. #endif
  70792. #endif
  70793. #ifdef HAVE_ECC
  70794. #ifndef WOLFSSL_NO_SERVER_GROUPS_EXT
  70795. ExpectIntEQ(wolfSSL_preferred_group(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70796. #ifndef NO_WOLFSSL_SERVER
  70797. ExpectIntEQ(wolfSSL_preferred_group(serverSsl), WC_NO_ERR_TRACE(SIDE_ERROR));
  70798. #endif
  70799. #ifndef NO_WOLFSSL_CLIENT
  70800. #ifndef WOLFSSL_NO_TLS12
  70801. ExpectIntEQ(wolfSSL_preferred_group(clientTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70802. #endif
  70803. ExpectIntEQ(wolfSSL_preferred_group(clientSsl), WC_NO_ERR_TRACE(NOT_READY_ERROR));
  70804. #endif
  70805. #endif
  70806. #ifdef HAVE_SUPPORTED_CURVES
  70807. ExpectIntEQ(wolfSSL_CTX_set_groups(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70808. #ifndef NO_WOLFSSL_CLIENT
  70809. ExpectIntEQ(wolfSSL_CTX_set_groups(clientCtx, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70810. #endif
  70811. ExpectIntEQ(wolfSSL_CTX_set_groups(NULL, groups, numGroups), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70812. #ifndef NO_WOLFSSL_CLIENT
  70813. #ifndef WOLFSSL_NO_TLS12
  70814. ExpectIntEQ(wolfSSL_CTX_set_groups(clientTls12Ctx, groups, numGroups),
  70815. WOLFSSL_SUCCESS);
  70816. #endif
  70817. ExpectIntEQ(wolfSSL_CTX_set_groups(clientCtx, groups,
  70818. WOLFSSL_MAX_GROUP_COUNT + 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70819. ExpectIntEQ(wolfSSL_CTX_set_groups(clientCtx, groups, numGroups),
  70820. WOLFSSL_SUCCESS);
  70821. ExpectIntEQ(wolfSSL_CTX_set_groups(clientCtx, bad_groups, numGroups),
  70822. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70823. #endif
  70824. #ifndef NO_WOLFSSL_SERVER
  70825. ExpectIntEQ(wolfSSL_CTX_set_groups(serverCtx, groups, numGroups),
  70826. WOLFSSL_SUCCESS);
  70827. ExpectIntEQ(wolfSSL_CTX_set_groups(serverCtx, bad_groups, numGroups),
  70828. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70829. #endif
  70830. ExpectIntEQ(wolfSSL_set_groups(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70831. #ifndef NO_WOLFSSL_CLIENT
  70832. ExpectIntEQ(wolfSSL_set_groups(clientSsl, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70833. #endif
  70834. ExpectIntEQ(wolfSSL_set_groups(NULL, groups, numGroups), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70835. #ifndef NO_WOLFSSL_CLIENT
  70836. #ifndef WOLFSSL_NO_TLS12
  70837. ExpectIntEQ(wolfSSL_set_groups(clientTls12Ssl, groups, numGroups),
  70838. WOLFSSL_SUCCESS);
  70839. #endif
  70840. ExpectIntEQ(wolfSSL_set_groups(clientSsl, groups,
  70841. WOLFSSL_MAX_GROUP_COUNT + 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70842. ExpectIntEQ(wolfSSL_set_groups(clientSsl, groups, numGroups),
  70843. WOLFSSL_SUCCESS);
  70844. ExpectIntEQ(wolfSSL_set_groups(clientSsl, bad_groups, numGroups),
  70845. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70846. #endif
  70847. #ifndef NO_WOLFSSL_SERVER
  70848. ExpectIntEQ(wolfSSL_set_groups(serverSsl, groups, numGroups),
  70849. WOLFSSL_SUCCESS);
  70850. ExpectIntEQ(wolfSSL_set_groups(serverSsl, bad_groups, numGroups),
  70851. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70852. #endif
  70853. #ifdef OPENSSL_EXTRA
  70854. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70855. #ifndef NO_WOLFSSL_CLIENT
  70856. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(clientCtx, NULL),
  70857. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70858. #endif
  70859. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(NULL, groupList),
  70860. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70861. #ifndef NO_WOLFSSL_CLIENT
  70862. #ifndef WOLFSSL_NO_TLS12
  70863. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(clientTls12Ctx, groupList),
  70864. WOLFSSL_SUCCESS);
  70865. #endif
  70866. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(clientCtx, groupList),
  70867. WOLFSSL_SUCCESS);
  70868. #endif
  70869. #ifndef NO_WOLFSSL_SERVER
  70870. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(serverCtx, groupList),
  70871. WOLFSSL_SUCCESS);
  70872. #endif
  70873. ExpectIntEQ(wolfSSL_set1_groups_list(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70874. #ifndef NO_WOLFSSL_CLIENT
  70875. ExpectIntEQ(wolfSSL_set1_groups_list(clientSsl, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70876. #endif
  70877. ExpectIntEQ(wolfSSL_set1_groups_list(NULL, groupList), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70878. #ifndef NO_WOLFSSL_CLIENT
  70879. #ifndef WOLFSSL_NO_TLS12
  70880. ExpectIntEQ(wolfSSL_set1_groups_list(clientTls12Ssl, groupList),
  70881. WOLFSSL_SUCCESS);
  70882. #endif
  70883. ExpectIntEQ(wolfSSL_set1_groups_list(clientSsl, groupList),
  70884. WOLFSSL_SUCCESS);
  70885. #endif
  70886. #ifndef NO_WOLFSSL_SERVER
  70887. ExpectIntEQ(wolfSSL_set1_groups_list(serverSsl, groupList),
  70888. WOLFSSL_SUCCESS);
  70889. #endif
  70890. #endif /* OPENSSL_EXTRA */
  70891. #endif /* HAVE_SUPPORTED_CURVES */
  70892. #endif /* HAVE_ECC */
  70893. #ifdef WOLFSSL_EARLY_DATA
  70894. #ifndef OPENSSL_EXTRA
  70895. ExpectIntEQ(wolfSSL_CTX_set_max_early_data(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70896. ExpectIntEQ(wolfSSL_CTX_get_max_early_data(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70897. #else
  70898. ExpectIntEQ(SSL_CTX_set_max_early_data(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70899. ExpectIntEQ(SSL_CTX_get_max_early_data(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70900. #endif
  70901. #ifndef NO_WOLFSSL_CLIENT
  70902. #ifndef OPENSSL_EXTRA
  70903. ExpectIntEQ(wolfSSL_CTX_set_max_early_data(clientCtx, 0), WC_NO_ERR_TRACE(SIDE_ERROR));
  70904. ExpectIntEQ(wolfSSL_CTX_get_max_early_data(clientCtx), WC_NO_ERR_TRACE(SIDE_ERROR));
  70905. #else
  70906. ExpectIntEQ(SSL_CTX_set_max_early_data(clientCtx, 0), WC_NO_ERR_TRACE(SIDE_ERROR));
  70907. ExpectIntEQ(SSL_CTX_get_max_early_data(clientCtx), WC_NO_ERR_TRACE(SIDE_ERROR));
  70908. #endif
  70909. #endif
  70910. #ifndef NO_WOLFSSL_SERVER
  70911. #ifndef WOLFSSL_NO_TLS12
  70912. #ifndef OPENSSL_EXTRA
  70913. ExpectIntEQ(wolfSSL_CTX_set_max_early_data(serverTls12Ctx, 0),
  70914. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70915. ExpectIntEQ(wolfSSL_CTX_get_max_early_data(serverTls12Ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70916. #else
  70917. ExpectIntEQ(SSL_CTX_set_max_early_data(serverTls12Ctx, 0),
  70918. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70919. ExpectIntEQ(SSL_CTX_get_max_early_data(serverTls12Ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70920. #endif
  70921. #endif
  70922. #ifndef OPENSSL_EXTRA
  70923. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  70924. ExpectIntEQ(wolfSSL_CTX_set_max_early_data(serverCtx, 32),
  70925. WOLFSSL_SUCCESS);
  70926. #else
  70927. ExpectIntEQ(wolfSSL_CTX_set_max_early_data(serverCtx, 32), 0);
  70928. #endif
  70929. ExpectIntEQ(wolfSSL_CTX_get_max_early_data(serverCtx), 32);
  70930. #else
  70931. ExpectIntEQ(SSL_CTX_set_max_early_data(serverCtx, 32), 1);
  70932. ExpectIntEQ(SSL_CTX_get_max_early_data(serverCtx), 32);
  70933. #endif
  70934. #endif
  70935. #ifndef OPENSSL_EXTRA
  70936. ExpectIntEQ(wolfSSL_set_max_early_data(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70937. ExpectIntEQ(wolfSSL_get_max_early_data(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70938. #else
  70939. ExpectIntEQ(SSL_set_max_early_data(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70940. ExpectIntEQ(SSL_get_max_early_data(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70941. #endif
  70942. #ifndef NO_WOLFSSL_CLIENT
  70943. #ifndef OPENSSL_EXTRA
  70944. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  70945. ExpectIntEQ(wolfSSL_set_max_early_data(clientSsl, 17), WOLFSSL_SUCCESS);
  70946. #else
  70947. ExpectIntEQ(wolfSSL_set_max_early_data(clientSsl, 17), 0);
  70948. #endif
  70949. ExpectIntEQ(wolfSSL_get_max_early_data(clientSsl), 17);
  70950. #else
  70951. ExpectIntEQ(SSL_set_max_early_data(clientSsl, 17), WOLFSSL_SUCCESS);
  70952. ExpectIntEQ(SSL_get_max_early_data(clientSsl), 17);
  70953. #endif
  70954. #endif
  70955. #ifndef NO_WOLFSSL_SERVER
  70956. #ifndef WOLFSSL_NO_TLS12
  70957. #ifndef OPENSSL_EXTRA
  70958. ExpectIntEQ(wolfSSL_set_max_early_data(serverTls12Ssl, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70959. ExpectIntEQ(wolfSSL_get_max_early_data(serverTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70960. #else
  70961. ExpectIntEQ(SSL_set_max_early_data(serverTls12Ssl, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70962. ExpectIntEQ(SSL_get_max_early_data(serverTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70963. #endif
  70964. #endif
  70965. #ifndef OPENSSL_EXTRA
  70966. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  70967. ExpectIntEQ(wolfSSL_set_max_early_data(serverSsl, 16), WOLFSSL_SUCCESS);
  70968. #else
  70969. ExpectIntEQ(wolfSSL_set_max_early_data(serverSsl, 16), 0);
  70970. #endif
  70971. ExpectIntEQ(wolfSSL_get_max_early_data(serverSsl), 16);
  70972. #else
  70973. ExpectIntEQ(SSL_set_max_early_data(serverSsl, 16), 1);
  70974. ExpectIntEQ(SSL_get_max_early_data(serverSsl), 16);
  70975. #endif
  70976. #endif
  70977. ExpectIntEQ(wolfSSL_write_early_data(NULL, earlyData, sizeof(earlyData),
  70978. &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70979. #ifndef NO_WOLFSSL_CLIENT
  70980. ExpectIntEQ(wolfSSL_write_early_data(clientSsl, NULL, sizeof(earlyData),
  70981. &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70982. ExpectIntEQ(wolfSSL_write_early_data(clientSsl, earlyData, -1, &outSz),
  70983. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70984. ExpectIntEQ(wolfSSL_write_early_data(clientSsl, earlyData,
  70985. sizeof(earlyData), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70986. #endif
  70987. #ifndef NO_WOLFSSL_SERVER
  70988. ExpectIntEQ(wolfSSL_write_early_data(serverSsl, earlyData,
  70989. sizeof(earlyData), &outSz), WC_NO_ERR_TRACE(SIDE_ERROR));
  70990. #endif
  70991. #ifndef NO_WOLFSSL_CLIENT
  70992. #ifndef WOLFSSL_NO_TLS12
  70993. ExpectIntEQ(wolfSSL_write_early_data(clientTls12Ssl, earlyData,
  70994. sizeof(earlyData), &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  70995. #endif
  70996. ExpectIntEQ(wolfSSL_write_early_data(clientSsl, earlyData,
  70997. sizeof(earlyData), &outSz), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  70998. #endif
  70999. ExpectIntEQ(wolfSSL_read_early_data(NULL, earlyDataBuffer,
  71000. sizeof(earlyDataBuffer), &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71001. #ifndef NO_WOLFSSL_SERVER
  71002. ExpectIntEQ(wolfSSL_read_early_data(serverSsl, NULL,
  71003. sizeof(earlyDataBuffer), &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71004. ExpectIntEQ(wolfSSL_read_early_data(serverSsl, earlyDataBuffer, -1,
  71005. &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71006. ExpectIntEQ(wolfSSL_read_early_data(serverSsl, earlyDataBuffer,
  71007. sizeof(earlyDataBuffer), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71008. #endif
  71009. #ifndef NO_WOLFSSL_CLIENT
  71010. ExpectIntEQ(wolfSSL_read_early_data(clientSsl, earlyDataBuffer,
  71011. sizeof(earlyDataBuffer), &outSz), WC_NO_ERR_TRACE(SIDE_ERROR));
  71012. #endif
  71013. #ifndef NO_WOLFSSL_SERVER
  71014. #ifndef WOLFSSL_NO_TLS12
  71015. ExpectIntEQ(wolfSSL_read_early_data(serverTls12Ssl, earlyDataBuffer,
  71016. sizeof(earlyDataBuffer), &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71017. #endif
  71018. ExpectIntEQ(wolfSSL_read_early_data(serverSsl, earlyDataBuffer,
  71019. sizeof(earlyDataBuffer), &outSz), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  71020. #endif
  71021. #endif
  71022. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_EARLY_DATA)
  71023. ExpectIntLT(SSL_get_early_data_status(NULL), 0);
  71024. #endif
  71025. #ifndef NO_WOLFSSL_SERVER
  71026. wolfSSL_free(serverSsl);
  71027. wolfSSL_CTX_free(serverCtx);
  71028. #endif
  71029. #ifndef NO_WOLFSSL_CLIENT
  71030. wolfSSL_free(clientSsl);
  71031. wolfSSL_CTX_free(clientCtx);
  71032. #endif
  71033. #ifndef WOLFSSL_NO_TLS12
  71034. #ifndef NO_WOLFSSL_SERVER
  71035. wolfSSL_free(serverTls12Ssl);
  71036. wolfSSL_CTX_free(serverTls12Ctx);
  71037. #endif
  71038. #ifndef NO_WOLFSSL_CLIENT
  71039. wolfSSL_free(clientTls12Ssl);
  71040. wolfSSL_CTX_free(clientTls12Ctx);
  71041. #endif
  71042. #endif
  71043. return EXPECT_RESULT();
  71044. }
  71045. #if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_SERVER) && \
  71046. defined(HAVE_ECC) && defined(BUILD_TLS_AES_128_GCM_SHA256) && \
  71047. defined(BUILD_TLS_AES_256_GCM_SHA384)
  71048. /* Called when writing. */
  71049. static int CsSend(WOLFSSL* ssl, char* buf, int sz, void* ctx)
  71050. {
  71051. (void)ssl;
  71052. (void)buf;
  71053. (void)sz;
  71054. (void)ctx;
  71055. /* Force error return from wolfSSL_accept_TLSv13(). */
  71056. return WANT_WRITE;
  71057. }
  71058. /* Called when reading. */
  71059. static int CsRecv(WOLFSSL* ssl, char* buf, int sz, void* ctx)
  71060. {
  71061. WOLFSSL_BUFFER_INFO* msg = (WOLFSSL_BUFFER_INFO*)ctx;
  71062. int len = (int)msg->length;
  71063. (void)ssl;
  71064. (void)sz;
  71065. /* Pass back as much of message as will fit in buffer. */
  71066. if (len > sz)
  71067. len = sz;
  71068. XMEMCPY(buf, msg->buffer, len);
  71069. /* Move over returned data. */
  71070. msg->buffer += len;
  71071. msg->length -= len;
  71072. /* Amount actually copied. */
  71073. return len;
  71074. }
  71075. #endif
  71076. static int test_tls13_cipher_suites(void)
  71077. {
  71078. EXPECT_DECLS;
  71079. #if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_SERVER) && \
  71080. defined(HAVE_ECC) && defined(BUILD_TLS_AES_128_GCM_SHA256) && \
  71081. defined(BUILD_TLS_AES_256_GCM_SHA384)
  71082. WOLFSSL_CTX* ctx = NULL;
  71083. WOLFSSL *ssl = NULL;
  71084. int i;
  71085. byte clientHello[] = {
  71086. 0x16, 0x03, 0x03, 0x01, 0x9b, 0x01, 0x00, 0x01,
  71087. 0x97, 0x03, 0x03, 0xf4, 0x65, 0xbd, 0x22, 0xfe,
  71088. 0x6e, 0xab, 0x66, 0xdd, 0xcf, 0xe9, 0x65, 0x55,
  71089. 0xe8, 0xdf, 0xc3, 0x8e, 0x4b, 0x00, 0xbc, 0xf8,
  71090. 0x23, 0x57, 0x1b, 0xa0, 0xc8, 0xa9, 0xe2, 0x8c,
  71091. 0x91, 0x6e, 0xf9, 0x20, 0xf7, 0x5c, 0xc5, 0x5b,
  71092. 0x75, 0x8c, 0x47, 0x0a, 0x0e, 0xc4, 0x1a, 0xda,
  71093. 0xef, 0x75, 0xe5, 0x21, 0x00, 0x00, 0x00, 0x00,
  71094. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  71095. 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
  71096. /* Cipher suites: 0x13, 0x01 = TLS13-AES128-GCM-SHA256, twice. */
  71097. 0x13, 0x01,
  71098. 0x13, 0x01, 0x01, 0x00, 0x01, 0x4a, 0x00, 0x2d,
  71099. 0x00, 0x03, 0x02, 0x00, 0x01, 0x00, 0x33, 0x00,
  71100. 0x47, 0x00, 0x45, 0x00, 0x17, 0x00, 0x41, 0x04,
  71101. 0x90, 0xfc, 0xe2, 0x97, 0x05, 0x7c, 0xb5, 0x23,
  71102. 0x5d, 0x5f, 0x5b, 0xcd, 0x0c, 0x1e, 0xe0, 0xe9,
  71103. 0xab, 0x38, 0x6b, 0x1e, 0x20, 0x5c, 0x1c, 0x90,
  71104. 0x2a, 0x9e, 0x68, 0x8e, 0x70, 0x05, 0x10, 0xa8,
  71105. 0x02, 0x1b, 0xf9, 0x5c, 0xef, 0xc9, 0xaf, 0xca,
  71106. 0x1a, 0x3b, 0x16, 0x8b, 0xe4, 0x1b, 0x3c, 0x15,
  71107. 0xb8, 0x0d, 0xbd, 0xaf, 0x62, 0x8d, 0xa7, 0x13,
  71108. 0xa0, 0x7c, 0xe0, 0x59, 0x0c, 0x4f, 0x8a, 0x6d,
  71109. 0x00, 0x2b, 0x00, 0x03, 0x02, 0x03, 0x04, 0x00,
  71110. 0x0d, 0x00, 0x20, 0x00, 0x1e, 0x06, 0x03, 0x05,
  71111. 0x03, 0x04, 0x03, 0x02, 0x03, 0x08, 0x06, 0x08,
  71112. 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08,
  71113. 0x09, 0x06, 0x01, 0x05, 0x01, 0x04, 0x01, 0x03,
  71114. 0x01, 0x02, 0x01, 0x00, 0x0a, 0x00, 0x04, 0x00,
  71115. 0x02, 0x00, 0x17, 0x00, 0x16, 0x00, 0x00, 0x00,
  71116. 0x23, 0x00, 0x00, 0x00, 0x29, 0x00, 0xb9, 0x00,
  71117. 0x94, 0x00, 0x8e, 0x0f, 0x12, 0xfa, 0x84, 0x1f,
  71118. 0x76, 0x94, 0xd7, 0x09, 0x5e, 0xad, 0x08, 0x51,
  71119. 0xb6, 0x80, 0x28, 0x31, 0x8b, 0xfd, 0xc6, 0xbd,
  71120. 0x9e, 0xf5, 0x3b, 0x4d, 0x02, 0xbe, 0x1d, 0x73,
  71121. 0xea, 0x13, 0x68, 0x00, 0x4c, 0xfd, 0x3d, 0x48,
  71122. 0x51, 0xf9, 0x06, 0xbb, 0x92, 0xed, 0x42, 0x9f,
  71123. 0x7f, 0x2c, 0x73, 0x9f, 0xd9, 0xb4, 0xef, 0x05,
  71124. 0x26, 0x5b, 0x60, 0x5c, 0x0a, 0xfc, 0xa3, 0xbd,
  71125. 0x2d, 0x2d, 0x8b, 0xf9, 0xaa, 0x5c, 0x96, 0x3a,
  71126. 0xf2, 0xec, 0xfa, 0xe5, 0x57, 0x2e, 0x87, 0xbe,
  71127. 0x27, 0xc5, 0x3d, 0x4f, 0x5d, 0xdd, 0xde, 0x1c,
  71128. 0x1b, 0xb3, 0xcc, 0x27, 0x27, 0x57, 0x5a, 0xd9,
  71129. 0xea, 0x99, 0x27, 0x23, 0xa6, 0x0e, 0xea, 0x9c,
  71130. 0x0d, 0x85, 0xcb, 0x72, 0xeb, 0xd7, 0x93, 0xe3,
  71131. 0xfe, 0xf7, 0x5c, 0xc5, 0x5b, 0x75, 0x8c, 0x47,
  71132. 0x0a, 0x0e, 0xc4, 0x1a, 0xda, 0xef, 0x75, 0xe5,
  71133. 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  71134. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  71135. 0x00, 0xfb, 0x92, 0xce, 0xaa, 0x00, 0x21, 0x20,
  71136. 0xcb, 0x73, 0x25, 0x80, 0x46, 0x78, 0x4f, 0xe5,
  71137. 0x34, 0xf6, 0x91, 0x13, 0x7f, 0xc8, 0x8d, 0xdc,
  71138. 0x81, 0x04, 0xb7, 0x0d, 0x49, 0x85, 0x2e, 0x12,
  71139. 0x7a, 0x07, 0x23, 0xe9, 0x13, 0xa4, 0x6d, 0x8c
  71140. };
  71141. WOLFSSL_BUFFER_INFO msg;
  71142. /* Offset into ClientHello message data of first cipher suite. */
  71143. const int csOff = 78;
  71144. /* Server cipher list. */
  71145. const char* serverCs = "TLS13-AES256-GCM-SHA384:TLS13-AES128-GCM-SHA256";
  71146. /* Suite list with duplicates. */
  71147. const char* dupCs = "TLS13-AES128-GCM-SHA256:"
  71148. "TLS13-AES128-GCM-SHA256:"
  71149. "TLS13-AES256-GCM-SHA384:"
  71150. "TLS13-AES256-GCM-SHA384:"
  71151. "TLS13-AES128-GCM-SHA256";
  71152. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_SET_CIPHER_BYTES)
  71153. const byte dupCsBytes[] = { TLS13_BYTE, TLS_AES_256_GCM_SHA384,
  71154. TLS13_BYTE, TLS_AES_256_GCM_SHA384,
  71155. TLS13_BYTE, TLS_AES_128_GCM_SHA256,
  71156. TLS13_BYTE, TLS_AES_128_GCM_SHA256,
  71157. TLS13_BYTE, TLS_AES_256_GCM_SHA384 };
  71158. #endif
  71159. /* Set up wolfSSL context. */
  71160. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  71161. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, eccCertFile,
  71162. WOLFSSL_FILETYPE_PEM));
  71163. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, eccKeyFile,
  71164. WOLFSSL_FILETYPE_PEM));
  71165. /* Read from 'msg'. */
  71166. wolfSSL_SetIORecv(ctx, CsRecv);
  71167. /* No where to send to - dummy sender. */
  71168. wolfSSL_SetIOSend(ctx, CsSend);
  71169. /* Test cipher suite list with many copies of a cipher suite. */
  71170. ExpectNotNull(ssl = wolfSSL_new(ctx));
  71171. msg.buffer = clientHello;
  71172. msg.length = (unsigned int)sizeof(clientHello);
  71173. wolfSSL_SetIOReadCtx(ssl, &msg);
  71174. /* Force server to have as many occurrences of same cipher suite as
  71175. * possible. */
  71176. if (ssl != NULL) {
  71177. Suites* suites = (Suites*)WOLFSSL_SUITES(ssl);
  71178. suites->suiteSz = WOLFSSL_MAX_SUITE_SZ;
  71179. for (i = 0; i < suites->suiteSz; i += 2) {
  71180. suites->suites[i + 0] = TLS13_BYTE;
  71181. suites->suites[i + 1] = TLS_AES_128_GCM_SHA256;
  71182. }
  71183. }
  71184. /* Test multiple occurrences of same cipher suite. */
  71185. ExpectIntEQ(wolfSSL_accept_TLSv13(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  71186. wolfSSL_free(ssl);
  71187. ssl = NULL;
  71188. /* Set client order opposite to server order:
  71189. * TLS13-AES128-GCM-SHA256:TLS13-AES256-GCM-SHA384 */
  71190. clientHello[csOff + 0] = TLS13_BYTE;
  71191. clientHello[csOff + 1] = TLS_AES_128_GCM_SHA256;
  71192. clientHello[csOff + 2] = TLS13_BYTE;
  71193. clientHello[csOff + 3] = TLS_AES_256_GCM_SHA384;
  71194. /* Test server order negotiation. */
  71195. ExpectNotNull(ssl = wolfSSL_new(ctx));
  71196. msg.buffer = clientHello;
  71197. msg.length = (unsigned int)sizeof(clientHello);
  71198. wolfSSL_SetIOReadCtx(ssl, &msg);
  71199. /* Server order: TLS13-AES256-GCM-SHA384:TLS13-AES128-GCM-SHA256 */
  71200. ExpectIntEQ(wolfSSL_set_cipher_list(ssl, serverCs), WOLFSSL_SUCCESS);
  71201. /* Negotiate cipher suites in server order: TLS13-AES256-GCM-SHA384 */
  71202. ExpectIntEQ(wolfSSL_accept_TLSv13(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  71203. /* Check refined order - server order. */
  71204. ExpectIntEQ(ssl->suites->suiteSz, 4);
  71205. ExpectIntEQ(ssl->suites->suites[0], TLS13_BYTE);
  71206. ExpectIntEQ(ssl->suites->suites[1], TLS_AES_256_GCM_SHA384);
  71207. ExpectIntEQ(ssl->suites->suites[2], TLS13_BYTE);
  71208. ExpectIntEQ(ssl->suites->suites[3], TLS_AES_128_GCM_SHA256);
  71209. wolfSSL_free(ssl);
  71210. ssl = NULL;
  71211. /* Test client order negotiation. */
  71212. ExpectNotNull(ssl = wolfSSL_new(ctx));
  71213. msg.buffer = clientHello;
  71214. msg.length = (unsigned int)sizeof(clientHello);
  71215. wolfSSL_SetIOReadCtx(ssl, &msg);
  71216. /* Server order: TLS13-AES256-GCM-SHA384:TLS13-AES128-GCM-SHA256 */
  71217. ExpectIntEQ(wolfSSL_set_cipher_list(ssl, serverCs), WOLFSSL_SUCCESS);
  71218. ExpectIntEQ(wolfSSL_UseClientSuites(ssl), 0);
  71219. /* Negotiate cipher suites in client order: TLS13-AES128-GCM-SHA256 */
  71220. ExpectIntEQ(wolfSSL_accept_TLSv13(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  71221. /* Check refined order - client order. */
  71222. ExpectIntEQ(ssl->suites->suiteSz, 4);
  71223. ExpectIntEQ(ssl->suites->suites[0], TLS13_BYTE);
  71224. ExpectIntEQ(ssl->suites->suites[1], TLS_AES_128_GCM_SHA256);
  71225. ExpectIntEQ(ssl->suites->suites[2], TLS13_BYTE);
  71226. ExpectIntEQ(ssl->suites->suites[3], TLS_AES_256_GCM_SHA384);
  71227. wolfSSL_free(ssl);
  71228. ssl = NULL;
  71229. /* Check duplicate detection is working. */
  71230. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx, dupCs), WOLFSSL_SUCCESS);
  71231. ExpectIntEQ(ctx->suites->suiteSz, 4);
  71232. ExpectIntEQ(ctx->suites->suites[0], TLS13_BYTE);
  71233. ExpectIntEQ(ctx->suites->suites[1], TLS_AES_128_GCM_SHA256);
  71234. ExpectIntEQ(ctx->suites->suites[2], TLS13_BYTE);
  71235. ExpectIntEQ(ctx->suites->suites[3], TLS_AES_256_GCM_SHA384);
  71236. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_SET_CIPHER_BYTES)
  71237. ExpectIntEQ(wolfSSL_CTX_set_cipher_list_bytes(ctx, dupCsBytes,
  71238. sizeof(dupCsBytes)), WOLFSSL_SUCCESS);
  71239. ExpectIntEQ(ctx->suites->suiteSz, 4);
  71240. ExpectIntEQ(ctx->suites->suites[0], TLS13_BYTE);
  71241. ExpectIntEQ(ctx->suites->suites[1], TLS_AES_256_GCM_SHA384);
  71242. ExpectIntEQ(ctx->suites->suites[2], TLS13_BYTE);
  71243. ExpectIntEQ(ctx->suites->suites[3], TLS_AES_128_GCM_SHA256);
  71244. #endif
  71245. wolfSSL_CTX_free(ctx);
  71246. #endif
  71247. return EXPECT_RESULT();
  71248. }
  71249. #endif
  71250. #if defined(HAVE_PK_CALLBACKS) && !defined(WOLFSSL_NO_TLS12)
  71251. #if !defined(NO_FILESYSTEM) && !defined(NO_DH) && \
  71252. !defined(NO_AES) && defined(HAVE_AES_CBC) && \
  71253. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  71254. static int my_DhCallback(WOLFSSL* ssl, struct DhKey* key,
  71255. const unsigned char* priv, unsigned int privSz,
  71256. const unsigned char* pubKeyDer, unsigned int pubKeySz,
  71257. unsigned char* out, unsigned int* outlen,
  71258. void* ctx)
  71259. {
  71260. int result;
  71261. /* Test fail when context associated with WOLFSSL is NULL */
  71262. if (ctx == NULL) {
  71263. return -1;
  71264. }
  71265. (void)ssl;
  71266. /* return 0 on success */
  71267. PRIVATE_KEY_UNLOCK();
  71268. result = wc_DhAgree(key, out, outlen, priv, privSz, pubKeyDer, pubKeySz);
  71269. PRIVATE_KEY_LOCK();
  71270. return result;
  71271. }
  71272. static int test_dh_ctx_setup(WOLFSSL_CTX* ctx) {
  71273. EXPECT_DECLS;
  71274. wolfSSL_CTX_SetDhAgreeCb(ctx, my_DhCallback);
  71275. #if defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  71276. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx, "DHE-RSA-AES128-SHA256"),
  71277. WOLFSSL_SUCCESS);
  71278. #endif
  71279. #if defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256)
  71280. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx, "DHE-RSA-AES256-SHA256"),
  71281. WOLFSSL_SUCCESS);
  71282. #endif
  71283. return EXPECT_RESULT();
  71284. }
  71285. static int test_dh_ssl_setup(WOLFSSL* ssl)
  71286. {
  71287. EXPECT_DECLS;
  71288. static int dh_test_ctx = 1;
  71289. int ret;
  71290. wolfSSL_SetDhAgreeCtx(ssl, &dh_test_ctx);
  71291. ExpectIntEQ(*((int*)wolfSSL_GetDhAgreeCtx(ssl)), dh_test_ctx);
  71292. ret = wolfSSL_SetTmpDH_file(ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  71293. if (ret != WOLFSSL_SUCCESS && ret != WC_NO_ERR_TRACE(SIDE_ERROR)) {
  71294. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  71295. }
  71296. return EXPECT_RESULT();
  71297. }
  71298. static int test_dh_ssl_setup_fail(WOLFSSL* ssl)
  71299. {
  71300. EXPECT_DECLS;
  71301. int ret;
  71302. wolfSSL_SetDhAgreeCtx(ssl, NULL);
  71303. ExpectNull(wolfSSL_GetDhAgreeCtx(ssl));
  71304. ret = wolfSSL_SetTmpDH_file(ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  71305. if (ret != WOLFSSL_SUCCESS && ret != WC_NO_ERR_TRACE(SIDE_ERROR)) {
  71306. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  71307. }
  71308. return EXPECT_RESULT();
  71309. }
  71310. #endif
  71311. static int test_DhCallbacks(void)
  71312. {
  71313. EXPECT_DECLS;
  71314. #if !defined(NO_FILESYSTEM) && !defined(NO_DH) && \
  71315. !defined(NO_AES) && defined(HAVE_AES_CBC) && \
  71316. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  71317. WOLFSSL_CTX *ctx = NULL;
  71318. WOLFSSL *ssl = NULL;
  71319. int test;
  71320. test_ssl_cbf func_cb_client;
  71321. test_ssl_cbf func_cb_server;
  71322. /* Test that DH callback APIs work. */
  71323. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  71324. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(NULL, "NONE"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71325. wolfSSL_CTX_SetDhAgreeCb(ctx, &my_DhCallback);
  71326. /* load client ca cert */
  71327. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0),
  71328. WOLFSSL_SUCCESS);
  71329. /* test with NULL arguments */
  71330. wolfSSL_SetDhAgreeCtx(NULL, &test);
  71331. ExpectNull(wolfSSL_GetDhAgreeCtx(NULL));
  71332. /* test success case */
  71333. test = 1;
  71334. ExpectNotNull(ssl = wolfSSL_new(ctx));
  71335. wolfSSL_SetDhAgreeCtx(ssl, &test);
  71336. ExpectIntEQ(*((int*)wolfSSL_GetDhAgreeCtx(ssl)), test);
  71337. wolfSSL_free(ssl);
  71338. wolfSSL_CTX_free(ctx);
  71339. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  71340. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  71341. /* set callbacks to use DH functions */
  71342. func_cb_client.ctx_ready = &test_dh_ctx_setup;
  71343. func_cb_client.ssl_ready = &test_dh_ssl_setup;
  71344. func_cb_client.method = wolfTLSv1_2_client_method;
  71345. func_cb_server.ctx_ready = &test_dh_ctx_setup;
  71346. func_cb_server.ssl_ready = &test_dh_ssl_setup;
  71347. func_cb_server.method = wolfTLSv1_2_server_method;
  71348. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  71349. &func_cb_server, NULL), TEST_SUCCESS);
  71350. /* Test fail */
  71351. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  71352. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  71353. /* set callbacks to use DH functions */
  71354. func_cb_client.ctx_ready = &test_dh_ctx_setup;
  71355. func_cb_client.ssl_ready = &test_dh_ssl_setup_fail;
  71356. func_cb_client.method = wolfTLSv1_2_client_method;
  71357. func_cb_server.ctx_ready = &test_dh_ctx_setup;
  71358. func_cb_server.ssl_ready = &test_dh_ssl_setup_fail;
  71359. func_cb_server.method = wolfTLSv1_2_server_method;
  71360. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  71361. &func_cb_server, NULL), -1001);
  71362. #endif
  71363. return EXPECT_RESULT();
  71364. }
  71365. #endif /* HAVE_PK_CALLBACKS */
  71366. #ifdef HAVE_HASHDRBG
  71367. #ifdef TEST_RESEED_INTERVAL
  71368. static int test_wc_RNG_GenerateBlock_Reseed(void)
  71369. {
  71370. EXPECT_DECLS;
  71371. int i;
  71372. WC_RNG rng;
  71373. byte key[32];
  71374. XMEMSET(&rng, 0, sizeof(WC_RNG));
  71375. ExpectIntEQ(wc_InitRng(&rng), 0);
  71376. for (i = 0; i < WC_RESEED_INTERVAL + 10; i++) {
  71377. ExpectIntEQ(wc_RNG_GenerateBlock(&rng, key, sizeof(key)), 0);
  71378. }
  71379. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  71380. return EXPECT_RESULT();
  71381. }
  71382. #endif /* TEST_RESEED_INTERVAL */
  71383. static int test_wc_RNG_GenerateBlock(void)
  71384. {
  71385. EXPECT_DECLS;
  71386. int i;
  71387. WC_RNG rng;
  71388. byte key[32];
  71389. XMEMSET(&rng, 0, sizeof(WC_RNG));
  71390. ExpectIntEQ(wc_InitRng(&rng), 0);
  71391. for (i = 0; i < 10; i++) {
  71392. ExpectIntEQ(wc_RNG_GenerateBlock(&rng, key, sizeof(key)), 0);
  71393. }
  71394. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  71395. return EXPECT_RESULT();
  71396. }
  71397. #endif /* HAVE_HASHDRBG */
  71398. /*
  71399. * Testing get_rand_digit
  71400. */
  71401. static int test_get_rand_digit(void)
  71402. {
  71403. EXPECT_DECLS;
  71404. #if !defined(WC_NO_RNG) && defined(WOLFSSL_PUBLIC_MP)
  71405. WC_RNG rng;
  71406. mp_digit d;
  71407. XMEMSET(&rng, 0, sizeof(WC_RNG));
  71408. ExpectIntEQ(wc_InitRng(&rng), 0);
  71409. ExpectIntEQ(get_rand_digit(&rng, &d), 0);
  71410. ExpectIntEQ(get_rand_digit(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71411. ExpectIntEQ(get_rand_digit(NULL, &d), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71412. ExpectIntEQ(get_rand_digit(&rng, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71413. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  71414. #endif
  71415. return EXPECT_RESULT();
  71416. } /* End test_get_rand_digit*/
  71417. /*
  71418. * Testing get_digit_count
  71419. */
  71420. static int test_get_digit_count(void)
  71421. {
  71422. EXPECT_DECLS;
  71423. #if !defined(WOLFSSL_SP_MATH) && defined(WOLFSSL_PUBLIC_MP)
  71424. mp_int a;
  71425. XMEMSET(&a, 0, sizeof(mp_int));
  71426. ExpectIntEQ(mp_init(&a), 0);
  71427. ExpectIntEQ(get_digit_count(NULL), 0);
  71428. ExpectIntEQ(get_digit_count(&a), 0);
  71429. mp_clear(&a);
  71430. #endif
  71431. return EXPECT_RESULT();
  71432. } /* End test_get_digit_count*/
  71433. /*
  71434. * Testing mp_cond_copy
  71435. */
  71436. static int test_mp_cond_copy(void)
  71437. {
  71438. EXPECT_DECLS;
  71439. #if (defined(HAVE_ECC) || defined(WOLFSSL_MP_COND_COPY)) && \
  71440. defined(WOLFSSL_PUBLIC_MP)
  71441. mp_int a;
  71442. mp_int b;
  71443. int copy = 0;
  71444. XMEMSET(&a, 0, sizeof(mp_int));
  71445. XMEMSET(&b, 0, sizeof(mp_int));
  71446. ExpectIntEQ(mp_init(&a), MP_OKAY);
  71447. ExpectIntEQ(mp_init(&b), MP_OKAY);
  71448. ExpectIntEQ(mp_cond_copy(NULL, copy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71449. ExpectIntEQ(mp_cond_copy(NULL, copy, &b), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71450. ExpectIntEQ(mp_cond_copy(&a, copy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71451. ExpectIntEQ(mp_cond_copy(&a, copy, &b), 0);
  71452. mp_clear(&a);
  71453. mp_clear(&b);
  71454. #endif
  71455. return EXPECT_RESULT();
  71456. } /* End test_mp_cond_copy*/
  71457. /*
  71458. * Testing mp_rand
  71459. */
  71460. static int test_mp_rand(void)
  71461. {
  71462. EXPECT_DECLS;
  71463. #if defined(WC_RSA_BLINDING) && defined(WOLFSSL_PUBLIC_MP)
  71464. mp_int a;
  71465. WC_RNG rng;
  71466. int digits = 1;
  71467. XMEMSET(&a, 0, sizeof(mp_int));
  71468. XMEMSET(&rng, 0, sizeof(WC_RNG));
  71469. ExpectIntEQ(mp_init(&a), MP_OKAY);
  71470. ExpectIntEQ(wc_InitRng(&rng), 0);
  71471. ExpectIntEQ(mp_rand(&a, digits, NULL), WC_NO_ERR_TRACE(MISSING_RNG_E));
  71472. ExpectIntEQ(mp_rand(NULL, digits, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71473. ExpectIntEQ(mp_rand(&a, 0, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71474. ExpectIntEQ(mp_rand(&a, digits, &rng), 0);
  71475. mp_clear(&a);
  71476. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  71477. #endif
  71478. return EXPECT_RESULT();
  71479. } /* End test_mp_rand*/
  71480. /*
  71481. * Testing get_digit
  71482. */
  71483. static int test_get_digit(void)
  71484. {
  71485. EXPECT_DECLS;
  71486. #if defined(WOLFSSL_PUBLIC_MP)
  71487. mp_int a;
  71488. int n = 0;
  71489. XMEMSET(&a, 0, sizeof(mp_int));
  71490. ExpectIntEQ(mp_init(&a), MP_OKAY);
  71491. ExpectIntEQ(get_digit(NULL, n), 0);
  71492. ExpectIntEQ(get_digit(&a, n), 0);
  71493. mp_clear(&a);
  71494. #endif
  71495. return EXPECT_RESULT();
  71496. } /* End test_get_digit*/
  71497. /*
  71498. * Testing wc_export_int
  71499. */
  71500. static int test_wc_export_int(void)
  71501. {
  71502. EXPECT_DECLS;
  71503. #if (defined(HAVE_ECC) || defined(WOLFSSL_EXPORT_INT)) && \
  71504. defined(WOLFSSL_PUBLIC_MP)
  71505. mp_int mp;
  71506. byte buf[32];
  71507. word32 keySz = (word32)sizeof(buf);
  71508. word32 len = (word32)sizeof(buf);
  71509. XMEMSET(&mp, 0, sizeof(mp_int));
  71510. ExpectIntEQ(mp_init(&mp), MP_OKAY);
  71511. ExpectIntEQ(mp_set(&mp, 1234), 0);
  71512. ExpectIntEQ(wc_export_int(NULL, buf, &len, keySz, WC_TYPE_UNSIGNED_BIN),
  71513. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71514. len = sizeof(buf)-1;
  71515. ExpectIntEQ(wc_export_int(&mp, buf, &len, keySz, WC_TYPE_UNSIGNED_BIN),
  71516. WC_NO_ERR_TRACE(BUFFER_E));
  71517. len = sizeof(buf);
  71518. ExpectIntEQ(wc_export_int(&mp, buf, &len, keySz, WC_TYPE_UNSIGNED_BIN), 0);
  71519. len = 4; /* test input too small */
  71520. ExpectIntEQ(wc_export_int(&mp, buf, &len, 0, WC_TYPE_HEX_STR), WC_NO_ERR_TRACE(BUFFER_E));
  71521. len = sizeof(buf);
  71522. ExpectIntEQ(wc_export_int(&mp, buf, &len, 0, WC_TYPE_HEX_STR), 0);
  71523. /* hex version of 1234 is 04D2 and should be 4 digits + 1 null */
  71524. ExpectIntEQ(len, 5);
  71525. mp_clear(&mp);
  71526. #endif
  71527. return EXPECT_RESULT();
  71528. } /* End test_wc_export_int*/
  71529. static int test_wc_InitRngNonce(void)
  71530. {
  71531. EXPECT_DECLS;
  71532. #if !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST) && \
  71533. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  71534. HAVE_FIPS_VERSION >= 2))
  71535. WC_RNG rng;
  71536. byte nonce[] = "\x0D\x74\xDB\x42\xA9\x10\x77\xDE"
  71537. "\x45\xAC\x13\x7A\xE1\x48\xAF\x16";
  71538. word32 nonceSz = sizeof(nonce);
  71539. ExpectIntEQ(wc_InitRngNonce(&rng, nonce, nonceSz), 0);
  71540. ExpectIntEQ(wc_FreeRng(&rng), 0);
  71541. #endif
  71542. return EXPECT_RESULT();
  71543. } /* End test_wc_InitRngNonce*/
  71544. /*
  71545. * Testing wc_InitRngNonce_ex
  71546. */
  71547. static int test_wc_InitRngNonce_ex(void)
  71548. {
  71549. EXPECT_DECLS;
  71550. #if !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST) && \
  71551. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  71552. HAVE_FIPS_VERSION >= 2))
  71553. WC_RNG rng;
  71554. byte nonce[] = "\x0D\x74\xDB\x42\xA9\x10\x77\xDE"
  71555. "\x45\xAC\x13\x7A\xE1\x48\xAF\x16";
  71556. word32 nonceSz = sizeof(nonce);
  71557. ExpectIntEQ(wc_InitRngNonce_ex(&rng, nonce, nonceSz, HEAP_HINT, testDevId),
  71558. 0);
  71559. ExpectIntEQ(wc_FreeRng(&rng), 0);
  71560. #endif
  71561. return EXPECT_RESULT();
  71562. } /* End test_wc_InitRngNonce_ex */
  71563. static int test_wolfSSL_X509_CRL(void)
  71564. {
  71565. EXPECT_DECLS;
  71566. #if defined(OPENSSL_EXTRA) && defined(HAVE_CRL)
  71567. X509_CRL *crl = NULL;
  71568. char pem[][100] = {
  71569. "./certs/crl/crl.pem",
  71570. "./certs/crl/crl2.pem",
  71571. "./certs/crl/caEccCrl.pem",
  71572. "./certs/crl/eccCliCRL.pem",
  71573. "./certs/crl/eccSrvCRL.pem",
  71574. ""
  71575. };
  71576. #ifndef NO_BIO
  71577. BIO *bio = NULL;
  71578. #endif
  71579. #ifdef HAVE_TEST_d2i_X509_CRL_fp
  71580. char der[][100] = {
  71581. "./certs/crl/crl.der",
  71582. "./certs/crl/crl2.der",
  71583. ""};
  71584. #endif
  71585. XFILE fp = XBADFILE;
  71586. int i;
  71587. for (i = 0; pem[i][0] != '\0'; i++)
  71588. {
  71589. ExpectTrue((fp = XFOPEN(pem[i], "rb")) != XBADFILE);
  71590. ExpectNotNull(crl = (X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  71591. NULL, NULL));
  71592. ExpectNotNull(crl);
  71593. X509_CRL_free(crl);
  71594. if (fp != XBADFILE) {
  71595. XFCLOSE(fp);
  71596. fp = XBADFILE;
  71597. }
  71598. ExpectTrue((fp = XFOPEN(pem[i], "rb")) != XBADFILE);
  71599. ExpectNotNull((X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)&crl, NULL,
  71600. NULL));
  71601. if (EXPECT_FAIL()) {
  71602. crl = NULL;
  71603. }
  71604. ExpectNotNull(crl);
  71605. X509_CRL_free(crl);
  71606. crl = NULL;
  71607. if (fp != XBADFILE) {
  71608. XFCLOSE(fp);
  71609. fp = XBADFILE;
  71610. }
  71611. }
  71612. #ifndef NO_BIO
  71613. for (i = 0; pem[i][0] != '\0'; i++)
  71614. {
  71615. ExpectNotNull(bio = BIO_new_file(pem[i], "rb"));
  71616. ExpectNotNull(crl = PEM_read_bio_X509_CRL(bio, NULL, NULL, NULL));
  71617. X509_CRL_free(crl);
  71618. crl = NULL;
  71619. BIO_free(bio);
  71620. bio = NULL;
  71621. }
  71622. #endif
  71623. #ifdef HAVE_TEST_d2i_X509_CRL_fp
  71624. for (i = 0; der[i][0] != '\0'; i++) {
  71625. ExpectTrue((fp = XFOPEN(der[i], "rb")) != XBADFILE);
  71626. ExpectTrue((fp != XBADFILE));
  71627. ExpectNotNull(crl = (X509_CRL *)d2i_X509_CRL_fp((fp, X509_CRL **)NULL));
  71628. ExpectNotNull(crl);
  71629. X509_CRL_free(crl);
  71630. if (fp != XBADFILE) {
  71631. XFCLOSE(fp);
  71632. fp = XBADFILE;
  71633. }
  71634. fp = XFOPEN(der[i], "rb");
  71635. ExpectTrue((fp != XBADFILE));
  71636. ExpectNotNull((X509_CRL *)d2i_X509_CRL_fp(fp, (X509_CRL **)&crl));
  71637. if (EXPECT_FAIL()) {
  71638. crl = NULL;
  71639. }
  71640. ExpectNotNull(crl);
  71641. X509_CRL_free(crl);
  71642. crl = NULL;
  71643. if (fp != XBADFILE) {
  71644. XFCLOSE(fp);
  71645. fp = XBADFILE;
  71646. }
  71647. }
  71648. #endif
  71649. #endif
  71650. return EXPECT_RESULT();
  71651. }
  71652. static int test_wolfSSL_X509_load_crl_file(void)
  71653. {
  71654. EXPECT_DECLS;
  71655. #if defined(OPENSSL_EXTRA) && defined(HAVE_CRL) && !defined(NO_FILESYSTEM) && \
  71656. !defined(NO_STDIO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_BIO) && \
  71657. !defined(WOLFSSL_CRL_ALLOW_MISSING_CDP)
  71658. int i;
  71659. char pem[][100] = {
  71660. "./certs/crl/crl.pem",
  71661. "./certs/crl/crl2.pem",
  71662. "./certs/crl/caEccCrl.pem",
  71663. "./certs/crl/eccCliCRL.pem",
  71664. "./certs/crl/eccSrvCRL.pem",
  71665. #ifdef WC_RSA_PSS
  71666. "./certs/crl/crl_rsapss.pem",
  71667. #endif
  71668. ""
  71669. };
  71670. char der[][100] = {
  71671. "./certs/crl/crl.der",
  71672. "./certs/crl/crl2.der",
  71673. ""
  71674. };
  71675. WOLFSSL_X509_STORE* store = NULL;
  71676. WOLFSSL_X509_LOOKUP* lookup = NULL;
  71677. ExpectNotNull(store = wolfSSL_X509_STORE_new());
  71678. ExpectNotNull(lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()));
  71679. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/ca-cert.pem",
  71680. X509_FILETYPE_PEM), 1);
  71681. #ifdef WC_RSA_PSS
  71682. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/rsapss/ca-rsapss.pem",
  71683. X509_FILETYPE_PEM), 1);
  71684. #endif
  71685. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/server-revoked-cert.pem",
  71686. X509_FILETYPE_PEM), 1);
  71687. if (store) {
  71688. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm, svrCertFile,
  71689. WOLFSSL_FILETYPE_PEM), 1);
  71690. /* since store hasn't yet known the revoked cert*/
  71691. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm,
  71692. "certs/server-revoked-cert.pem", WOLFSSL_FILETYPE_PEM), 1);
  71693. }
  71694. for (i = 0; pem[i][0] != '\0'; i++) {
  71695. ExpectIntEQ(X509_load_crl_file(lookup, pem[i], WOLFSSL_FILETYPE_PEM),
  71696. 1);
  71697. }
  71698. if (store) {
  71699. /* since store knows crl list */
  71700. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm,
  71701. "certs/server-revoked-cert.pem", WOLFSSL_FILETYPE_PEM),
  71702. WC_NO_ERR_TRACE(CRL_CERT_REVOKED));
  71703. #ifdef WC_RSA_PSS
  71704. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm,
  71705. "certs/rsapss/server-rsapss-cert.pem", WOLFSSL_FILETYPE_PEM),
  71706. WC_NO_ERR_TRACE(CRL_CERT_REVOKED));
  71707. #endif
  71708. }
  71709. /* once feeing store */
  71710. X509_STORE_free(store);
  71711. store = NULL;
  71712. ExpectNotNull(store = wolfSSL_X509_STORE_new());
  71713. ExpectNotNull(lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()));
  71714. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/ca-cert.pem",
  71715. X509_FILETYPE_PEM), 1);
  71716. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/server-revoked-cert.pem",
  71717. X509_FILETYPE_PEM), 1);
  71718. if (store) {
  71719. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm, svrCertFile,
  71720. WOLFSSL_FILETYPE_PEM), 1);
  71721. /* since store hasn't yet known the revoked cert*/
  71722. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm,
  71723. "certs/server-revoked-cert.pem", WOLFSSL_FILETYPE_PEM), 1);
  71724. }
  71725. for (i = 0; der[i][0] != '\0'; i++) {
  71726. ExpectIntEQ(X509_load_crl_file(lookup, der[i], WOLFSSL_FILETYPE_ASN1),
  71727. 1);
  71728. }
  71729. if (store) {
  71730. /* since store knows crl list */
  71731. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm,
  71732. "certs/server-revoked-cert.pem", WOLFSSL_FILETYPE_PEM),
  71733. WC_NO_ERR_TRACE(CRL_CERT_REVOKED));
  71734. }
  71735. /* test for incorrect parameter */
  71736. ExpectIntEQ(X509_load_crl_file(NULL, pem[0], 0), 0);
  71737. ExpectIntEQ(X509_load_crl_file(lookup, NULL, 0), 0);
  71738. ExpectIntEQ(X509_load_crl_file(NULL, NULL, 0), 0);
  71739. X509_STORE_free(store);
  71740. store = NULL;
  71741. #endif
  71742. return EXPECT_RESULT();
  71743. }
  71744. static int test_wolfSSL_i2d_X509(void)
  71745. {
  71746. EXPECT_DECLS;
  71747. #if defined(OPENSSL_EXTRA) && defined(USE_CERT_BUFFERS_2048) && !defined(NO_RSA)
  71748. const unsigned char* cert_buf = server_cert_der_2048;
  71749. unsigned char* out = NULL;
  71750. unsigned char* tmp = NULL;
  71751. X509* cert = NULL;
  71752. ExpectNotNull(d2i_X509(&cert, &cert_buf, sizeof_server_cert_der_2048));
  71753. /* Pointer should be advanced */
  71754. ExpectPtrGT(cert_buf, server_cert_der_2048);
  71755. ExpectIntGT(i2d_X509(cert, &out), 0);
  71756. ExpectNotNull(out);
  71757. tmp = out;
  71758. ExpectIntGT(i2d_X509(cert, &tmp), 0);
  71759. ExpectPtrGT(tmp, out);
  71760. if (out != NULL)
  71761. XFREE(out, NULL, DYNAMIC_TYPE_OPENSSL);
  71762. X509_free(cert);
  71763. #endif
  71764. return EXPECT_RESULT();
  71765. }
  71766. static int test_wolfSSL_d2i_X509_REQ(void)
  71767. {
  71768. EXPECT_DECLS;
  71769. #if defined(WOLFSSL_CERT_REQ) && !defined(NO_RSA) && !defined(NO_BIO) && \
  71770. (defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA)) && \
  71771. !defined(WOLFSSL_SP_MATH)
  71772. /* ./certs/csr.signed.der, ./certs/csr.ext.der, and ./certs/csr.attr.der
  71773. * were generated by libest
  71774. * ./certs/csr.attr.der contains sample attributes
  71775. * ./certs/csr.ext.der contains sample extensions */
  71776. const char* csrFile = "./certs/csr.signed.der";
  71777. const char* csrPopFile = "./certs/csr.attr.der";
  71778. const char* csrExtFile = "./certs/csr.ext.der";
  71779. /* ./certs/csr.dsa.pem is generated using
  71780. * openssl req -newkey dsa:certs/dsaparams.pem \
  71781. * -keyout certs/csr.dsa.key.pem -keyform PEM -out certs/csr.dsa.pem \
  71782. * -outform PEM
  71783. * with the passphrase "wolfSSL"
  71784. */
  71785. #if !defined(NO_DSA) && !defined(HAVE_SELFTEST)
  71786. const char* csrDsaFile = "./certs/csr.dsa.pem";
  71787. XFILE f = XBADFILE;
  71788. #endif
  71789. BIO* bio = NULL;
  71790. X509* req = NULL;
  71791. EVP_PKEY *pub_key = NULL;
  71792. {
  71793. ExpectNotNull(bio = BIO_new_file(csrFile, "rb"));
  71794. ExpectNotNull(d2i_X509_REQ_bio(bio, &req));
  71795. /*
  71796. * Extract the public key from the CSR
  71797. */
  71798. ExpectNotNull(pub_key = X509_REQ_get_pubkey(req));
  71799. /*
  71800. * Verify the signature in the CSR
  71801. */
  71802. ExpectIntEQ(X509_REQ_verify(req, pub_key), 1);
  71803. X509_free(req);
  71804. req = NULL;
  71805. BIO_free(bio);
  71806. bio = NULL;
  71807. EVP_PKEY_free(pub_key);
  71808. pub_key = NULL;
  71809. }
  71810. {
  71811. #ifdef OPENSSL_ALL
  71812. X509_ATTRIBUTE* attr = NULL;
  71813. ASN1_TYPE *at = NULL;
  71814. #endif
  71815. ExpectNotNull(bio = BIO_new_file(csrPopFile, "rb"));
  71816. ExpectNotNull(d2i_X509_REQ_bio(bio, &req));
  71817. /*
  71818. * Extract the public key from the CSR
  71819. */
  71820. ExpectNotNull(pub_key = X509_REQ_get_pubkey(req));
  71821. /*
  71822. * Verify the signature in the CSR
  71823. */
  71824. ExpectIntEQ(X509_REQ_verify(req, pub_key), 1);
  71825. #ifdef OPENSSL_ALL
  71826. /*
  71827. * Obtain the challenge password from the CSR
  71828. */
  71829. ExpectIntEQ(X509_REQ_get_attr_by_NID(req, NID_pkcs9_challengePassword,
  71830. -1), 1);
  71831. ExpectNotNull(attr = X509_REQ_get_attr(req, 1));
  71832. ExpectNotNull(at = X509_ATTRIBUTE_get0_type(attr, 0));
  71833. ExpectNotNull(at->value.asn1_string);
  71834. ExpectStrEQ((char*)ASN1_STRING_data(at->value.asn1_string),
  71835. "2xIE+qqp/rhyTXP+");
  71836. ExpectIntEQ(X509_get_ext_by_NID(req, NID_subject_alt_name, -1), -1);
  71837. #endif
  71838. X509_free(req);
  71839. req = NULL;
  71840. BIO_free(bio);
  71841. bio = NULL;
  71842. EVP_PKEY_free(pub_key);
  71843. pub_key = NULL;
  71844. }
  71845. {
  71846. #ifdef OPENSSL_ALL
  71847. X509_ATTRIBUTE* attr = NULL;
  71848. ASN1_TYPE *at = NULL;
  71849. STACK_OF(X509_EXTENSION) *exts = NULL;
  71850. #endif
  71851. ExpectNotNull(bio = BIO_new_file(csrExtFile, "rb"));
  71852. /* This CSR contains an Extension Request attribute so
  71853. * we test extension parsing in a CSR attribute here. */
  71854. ExpectNotNull(d2i_X509_REQ_bio(bio, &req));
  71855. /*
  71856. * Extract the public key from the CSR
  71857. */
  71858. ExpectNotNull(pub_key = X509_REQ_get_pubkey(req));
  71859. /*
  71860. * Verify the signature in the CSR
  71861. */
  71862. ExpectIntEQ(X509_REQ_verify(req, pub_key), 1);
  71863. #ifdef OPENSSL_ALL
  71864. ExpectNotNull(exts = (STACK_OF(X509_EXTENSION)*)X509_REQ_get_extensions(
  71865. req));
  71866. ExpectIntEQ(sk_X509_EXTENSION_num(exts), 2);
  71867. sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
  71868. /*
  71869. * Obtain the challenge password from the CSR
  71870. */
  71871. ExpectIntEQ(X509_REQ_get_attr_by_NID(req, NID_pkcs9_challengePassword,
  71872. -1), 0);
  71873. ExpectNotNull(attr = X509_REQ_get_attr(req, 0));
  71874. ExpectNotNull(at = X509_ATTRIBUTE_get0_type(attr, 0));
  71875. ExpectNotNull(at->value.asn1_string);
  71876. ExpectStrEQ((char*)ASN1_STRING_data(at->value.asn1_string), "IGCu/xNL4/0/wOgo");
  71877. ExpectIntGE(X509_get_ext_by_NID(req, NID_key_usage, -1), 0);
  71878. ExpectIntGE(X509_get_ext_by_NID(req, NID_subject_alt_name, -1), 0);
  71879. #endif
  71880. X509_free(req);
  71881. req = NULL;
  71882. BIO_free(bio);
  71883. bio = NULL;
  71884. EVP_PKEY_free(pub_key);
  71885. pub_key = NULL;
  71886. }
  71887. #if !defined(NO_DSA) && !defined(HAVE_SELFTEST)
  71888. {
  71889. ExpectNotNull(bio = BIO_new_file(csrDsaFile, "rb"));
  71890. ExpectNotNull(PEM_read_bio_X509_REQ(bio, &req, NULL, NULL));
  71891. /*
  71892. * Extract the public key from the CSR
  71893. */
  71894. ExpectNotNull(pub_key = X509_REQ_get_pubkey(req));
  71895. /*
  71896. * Verify the signature in the CSR
  71897. */
  71898. ExpectIntEQ(X509_REQ_verify(req, pub_key), 1);
  71899. X509_free(req);
  71900. req = NULL;
  71901. BIO_free(bio);
  71902. /* Run the same test, but with a file pointer instead of a BIO.
  71903. * (PEM_read_X509_REQ)*/
  71904. ExpectTrue((f = XFOPEN(csrDsaFile, "rb")) != XBADFILE);
  71905. ExpectNotNull(PEM_read_X509_REQ(f, &req, NULL, NULL));
  71906. ExpectIntEQ(X509_REQ_verify(req, pub_key), 1);
  71907. X509_free(req);
  71908. EVP_PKEY_free(pub_key);
  71909. }
  71910. #endif /* !NO_DSA && !HAVE_SELFTEST */
  71911. #endif /* WOLFSSL_CERT_REQ && (OPENSSL_ALL || OPENSSL_EXTRA) */
  71912. return EXPECT_RESULT();
  71913. }
  71914. static int test_wolfSSL_PEM_read_X509(void)
  71915. {
  71916. EXPECT_DECLS;
  71917. #if defined(OPENSSL_EXTRA) && defined(HAVE_CRL) && !defined(NO_FILESYSTEM) && \
  71918. !defined(NO_RSA)
  71919. X509 *x509 = NULL;
  71920. XFILE fp = XBADFILE;
  71921. ExpectTrue((fp = XFOPEN(svrCertFile, "rb")) != XBADFILE);
  71922. ExpectNotNull(x509 = (X509 *)PEM_read_X509(fp, (X509 **)NULL, NULL, NULL));
  71923. X509_free(x509);
  71924. if (fp != XBADFILE)
  71925. XFCLOSE(fp);
  71926. #endif
  71927. return EXPECT_RESULT();
  71928. }
  71929. static int test_wolfSSL_PEM_read(void)
  71930. {
  71931. EXPECT_DECLS;
  71932. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  71933. const char* filename = "./certs/server-keyEnc.pem";
  71934. XFILE fp = XBADFILE;
  71935. char* name = NULL;
  71936. char* header = NULL;
  71937. byte* data = NULL;
  71938. long len;
  71939. EVP_CIPHER_INFO cipher;
  71940. WOLFSSL_BIO* bio = NULL;
  71941. byte* fileData = NULL;
  71942. size_t fileDataSz = 0;
  71943. byte* out;
  71944. ExpectNotNull(bio = BIO_new_file(filename, "rb"));
  71945. ExpectIntEQ(PEM_read_bio(bio, NULL, &header, &data, &len), 0);
  71946. ExpectIntEQ(PEM_read_bio(bio, &name, NULL, &data, &len), 0);
  71947. ExpectIntEQ(PEM_read_bio(bio, &name, &header, NULL, &len), 0);
  71948. ExpectIntEQ(PEM_read_bio(bio, &name, &header, &data, NULL), 0);
  71949. ExpectIntEQ(PEM_read_bio(bio, &name, &header, &data, &len), 1);
  71950. ExpectIntEQ(XSTRNCMP(name, "RSA PRIVATE KEY", 15), 0);
  71951. ExpectIntGT(XSTRLEN(header), 0);
  71952. ExpectIntGT(len, 0);
  71953. XFREE(name, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71954. name = NULL;
  71955. XFREE(header, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71956. header = NULL;
  71957. XFREE(data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71958. data = NULL;
  71959. BIO_free(bio);
  71960. bio = NULL;
  71961. ExpectTrue((fp = XFOPEN(filename, "rb")) != XBADFILE);
  71962. /* Fail cases. */
  71963. ExpectIntEQ(PEM_read(fp, NULL, &header, &data, &len), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71964. ExpectIntEQ(PEM_read(fp, &name, NULL, &data, &len), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71965. ExpectIntEQ(PEM_read(fp, &name, &header, NULL, &len), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71966. ExpectIntEQ(PEM_read(fp, &name, &header, &data, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71967. ExpectIntEQ(PEM_read(fp, &name, &header, &data, &len), WOLFSSL_SUCCESS);
  71968. ExpectIntEQ(XSTRNCMP(name, "RSA PRIVATE KEY", 15), 0);
  71969. ExpectIntGT(XSTRLEN(header), 0);
  71970. ExpectIntGT(len, 0);
  71971. ExpectIntEQ(XFSEEK(fp, 0, SEEK_END), 0);
  71972. ExpectIntGT((fileDataSz = XFTELL(fp)), 0);
  71973. ExpectIntEQ(XFSEEK(fp, 0, SEEK_SET), 0);
  71974. ExpectNotNull(fileData = (unsigned char*)XMALLOC(fileDataSz, NULL,
  71975. DYNAMIC_TYPE_TMP_BUFFER));
  71976. ExpectIntEQ(XFREAD(fileData, 1, fileDataSz, fp), fileDataSz);
  71977. if (fp != XBADFILE) {
  71978. XFCLOSE(fp);
  71979. fp = XBADFILE;
  71980. }
  71981. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  71982. /* Fail cases. */
  71983. ExpectIntEQ(PEM_write_bio(NULL, name, header, data, len), 0);
  71984. ExpectIntEQ(PEM_write_bio(bio, NULL, header, data, len), 0);
  71985. ExpectIntEQ(PEM_write_bio(bio, name, NULL, data, len), 0);
  71986. ExpectIntEQ(PEM_write_bio(bio, name, header, NULL, len), 0);
  71987. ExpectIntEQ(PEM_write_bio(bio, name, header, data, len), fileDataSz);
  71988. ExpectIntEQ(wolfSSL_BIO_get_mem_data(bio, &out), fileDataSz);
  71989. ExpectIntEQ(XMEMCMP(out, fileData, fileDataSz), 0);
  71990. /* Fail cases. */
  71991. ExpectIntEQ(PEM_write(XBADFILE, name, header, data, len), 0);
  71992. ExpectIntEQ(PEM_write(stderr, NULL, header, data, len), 0);
  71993. ExpectIntEQ(PEM_write(stderr, name, NULL, data, len), 0);
  71994. ExpectIntEQ(PEM_write(stderr, name, header, NULL, len), 0);
  71995. /* Pass case */
  71996. ExpectIntEQ(PEM_write(stderr, name, header, data, len), fileDataSz);
  71997. XFREE(name, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  71998. name = NULL;
  71999. XFREE(header, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72000. header = NULL;
  72001. XFREE(data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72002. data = NULL;
  72003. /* Read out of a fixed buffer BIO - forces malloc in PEM_read_bio. */
  72004. ExpectIntEQ(PEM_read_bio(bio, &name, &header, &data, &len), 1);
  72005. ExpectIntEQ(XSTRNCMP(name, "RSA PRIVATE KEY", 15), 0);
  72006. ExpectIntGT(XSTRLEN(header), 0);
  72007. ExpectIntGT(len, 0);
  72008. /* Fail cases. */
  72009. ExpectIntEQ(PEM_get_EVP_CIPHER_INFO(NULL, &cipher), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72010. ExpectIntEQ(PEM_get_EVP_CIPHER_INFO(header, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72011. ExpectIntEQ(PEM_get_EVP_CIPHER_INFO((char*)"", &cipher), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72012. #ifndef NO_DES3
  72013. ExpectIntEQ(PEM_get_EVP_CIPHER_INFO(header, &cipher), WOLFSSL_SUCCESS);
  72014. #endif
  72015. /* Fail cases. */
  72016. ExpectIntEQ(PEM_do_header(NULL, data, &len, PasswordCallBack,
  72017. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72018. ExpectIntEQ(PEM_do_header(&cipher, NULL, &len, PasswordCallBack,
  72019. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72020. ExpectIntEQ(PEM_do_header(&cipher, data, NULL, PasswordCallBack,
  72021. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72022. ExpectIntEQ(PEM_do_header(&cipher, data, &len, NULL,
  72023. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72024. ExpectIntEQ(PEM_do_header(&cipher, data, &len, NoPasswordCallBack,
  72025. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72026. #if !defined(NO_DES3) && !defined(NO_MD5)
  72027. ExpectIntEQ(PEM_do_header(&cipher, data, &len, PasswordCallBack,
  72028. (void*)"yassl123"), WOLFSSL_SUCCESS);
  72029. #else
  72030. ExpectIntEQ(PEM_do_header(&cipher, data, &len, PasswordCallBack,
  72031. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72032. #endif
  72033. BIO_free(bio);
  72034. bio = NULL;
  72035. XFREE(fileData, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72036. fileData = NULL;
  72037. XFREE(name, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72038. XFREE(header, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72039. XFREE(data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72040. name = NULL;
  72041. header = NULL;
  72042. data = NULL;
  72043. ExpectTrue((fp = XFOPEN(svrKeyFile, "rb")) != XBADFILE);
  72044. ExpectIntEQ(PEM_read(fp, &name, &header, &data, &len), WOLFSSL_SUCCESS);
  72045. ExpectIntEQ(XSTRNCMP(name, "RSA PRIVATE KEY", 15), 0);
  72046. ExpectIntEQ(XSTRLEN(header), 0);
  72047. ExpectIntGT(len, 0);
  72048. ExpectIntEQ(XFSEEK(fp, 0, SEEK_END), 0);
  72049. ExpectIntGT((fileDataSz = XFTELL(fp)), 0);
  72050. ExpectIntEQ(XFSEEK(fp, 0, SEEK_SET), 0);
  72051. ExpectNotNull(fileData = (unsigned char*)XMALLOC(fileDataSz, NULL,
  72052. DYNAMIC_TYPE_TMP_BUFFER));
  72053. ExpectIntEQ(XFREAD(fileData, 1, fileDataSz, fp), fileDataSz);
  72054. if (fp != XBADFILE)
  72055. XFCLOSE(fp);
  72056. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  72057. ExpectIntEQ(PEM_write_bio(bio, name, header, data, len), fileDataSz);
  72058. ExpectIntEQ(wolfSSL_BIO_get_mem_data(bio, &out), fileDataSz);
  72059. ExpectIntEQ(XMEMCMP(out, fileData, fileDataSz), 0);
  72060. BIO_free(bio);
  72061. XFREE(fileData, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72062. XFREE(name, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72063. XFREE(header, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72064. XFREE(data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72065. #endif
  72066. return EXPECT_RESULT();
  72067. }
  72068. static int test_wolfssl_EVP_aes_gcm_AAD_2_parts(void)
  72069. {
  72070. EXPECT_DECLS;
  72071. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AESGCM) && \
  72072. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  72073. const byte iv[12] = { 0 };
  72074. const byte key[16] = { 0 };
  72075. const byte cleartext[16] = { 0 };
  72076. const byte aad[] = {
  72077. 0x01, 0x10, 0x00, 0x2a, 0x08, 0x00, 0x04, 0x00,
  72078. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
  72079. 0x00, 0x00, 0xdc, 0x4d, 0xad, 0x6b, 0x06, 0x93,
  72080. 0x4f
  72081. };
  72082. byte out1Part[16];
  72083. byte outTag1Part[16];
  72084. byte out2Part[16];
  72085. byte outTag2Part[16];
  72086. byte decryptBuf[16];
  72087. int len = 0;
  72088. int tlen;
  72089. EVP_CIPHER_CTX* ctx = NULL;
  72090. /* ENCRYPT */
  72091. /* Send AAD and data in 1 part */
  72092. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  72093. tlen = 0;
  72094. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_aes_128_gcm(), NULL, NULL, NULL),
  72095. 1);
  72096. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), 1);
  72097. ExpectIntEQ(EVP_EncryptUpdate(ctx, NULL, &len, aad, sizeof(aad)), 1);
  72098. ExpectIntEQ(EVP_EncryptUpdate(ctx, out1Part, &len, cleartext,
  72099. sizeof(cleartext)), 1);
  72100. tlen += len;
  72101. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, out1Part, &len), 1);
  72102. tlen += len;
  72103. ExpectIntEQ(tlen, sizeof(cleartext));
  72104. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, 16,
  72105. outTag1Part), 1);
  72106. EVP_CIPHER_CTX_free(ctx);
  72107. ctx = NULL;
  72108. /* DECRYPT */
  72109. /* Send AAD and data in 1 part */
  72110. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  72111. tlen = 0;
  72112. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_aes_128_gcm(), NULL, NULL, NULL),
  72113. 1);
  72114. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), 1);
  72115. ExpectIntEQ(EVP_DecryptUpdate(ctx, NULL, &len, aad, sizeof(aad)), 1);
  72116. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptBuf, &len, out1Part,
  72117. sizeof(cleartext)), 1);
  72118. tlen += len;
  72119. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, 16,
  72120. outTag1Part), 1);
  72121. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptBuf, &len), 1);
  72122. tlen += len;
  72123. ExpectIntEQ(tlen, sizeof(cleartext));
  72124. EVP_CIPHER_CTX_free(ctx);
  72125. ctx = NULL;
  72126. ExpectIntEQ(XMEMCMP(decryptBuf, cleartext, len), 0);
  72127. /* ENCRYPT */
  72128. /* Send AAD and data in 2 parts */
  72129. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  72130. tlen = 0;
  72131. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_aes_128_gcm(), NULL, NULL, NULL),
  72132. 1);
  72133. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), 1);
  72134. ExpectIntEQ(EVP_EncryptUpdate(ctx, NULL, &len, aad, 1), 1);
  72135. ExpectIntEQ(EVP_EncryptUpdate(ctx, NULL, &len, aad + 1, sizeof(aad) - 1),
  72136. 1);
  72137. ExpectIntEQ(EVP_EncryptUpdate(ctx, out2Part, &len, cleartext, 1), 1);
  72138. tlen += len;
  72139. ExpectIntEQ(EVP_EncryptUpdate(ctx, out2Part + tlen, &len, cleartext + 1,
  72140. sizeof(cleartext) - 1), 1);
  72141. tlen += len;
  72142. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, out2Part + tlen, &len), 1);
  72143. tlen += len;
  72144. ExpectIntEQ(tlen, sizeof(cleartext));
  72145. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, 16,
  72146. outTag2Part), 1);
  72147. ExpectIntEQ(XMEMCMP(out1Part, out2Part, sizeof(out1Part)), 0);
  72148. ExpectIntEQ(XMEMCMP(outTag1Part, outTag2Part, sizeof(outTag1Part)), 0);
  72149. EVP_CIPHER_CTX_free(ctx);
  72150. ctx = NULL;
  72151. /* DECRYPT */
  72152. /* Send AAD and data in 2 parts */
  72153. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  72154. tlen = 0;
  72155. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_aes_128_gcm(), NULL, NULL, NULL),
  72156. 1);
  72157. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), 1);
  72158. ExpectIntEQ(EVP_DecryptUpdate(ctx, NULL, &len, aad, 1), 1);
  72159. ExpectIntEQ(EVP_DecryptUpdate(ctx, NULL, &len, aad + 1, sizeof(aad) - 1),
  72160. 1);
  72161. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptBuf, &len, out1Part, 1), 1);
  72162. tlen += len;
  72163. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptBuf + tlen, &len, out1Part + 1,
  72164. sizeof(cleartext) - 1), 1);
  72165. tlen += len;
  72166. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, 16,
  72167. outTag1Part), 1);
  72168. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptBuf + tlen, &len), 1);
  72169. tlen += len;
  72170. ExpectIntEQ(tlen, sizeof(cleartext));
  72171. ExpectIntEQ(XMEMCMP(decryptBuf, cleartext, len), 0);
  72172. /* Test AAD reuse */
  72173. EVP_CIPHER_CTX_free(ctx);
  72174. #endif
  72175. return EXPECT_RESULT();
  72176. }
  72177. static int test_wolfssl_EVP_aes_gcm_zeroLen(void)
  72178. {
  72179. EXPECT_DECLS;
  72180. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AESGCM) && \
  72181. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  72182. /* Zero length plain text */
  72183. byte key[] = {
  72184. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72185. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72186. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72187. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  72188. }; /* align */
  72189. byte iv[] = {
  72190. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  72191. }; /* align */
  72192. byte plaintxt[1];
  72193. int ivSz = 12;
  72194. int plaintxtSz = 0;
  72195. unsigned char tag[16];
  72196. unsigned char tag_kat[] = {
  72197. 0x53,0x0f,0x8a,0xfb,0xc7,0x45,0x36,0xb9,
  72198. 0xa9,0x63,0xb4,0xf1,0xc4,0xcb,0x73,0x8b
  72199. };
  72200. byte ciphertxt[AES_BLOCK_SIZE * 4] = {0};
  72201. byte decryptedtxt[AES_BLOCK_SIZE * 4] = {0};
  72202. int ciphertxtSz = 0;
  72203. int decryptedtxtSz = 0;
  72204. int len = 0;
  72205. EVP_CIPHER_CTX *en = EVP_CIPHER_CTX_new();
  72206. EVP_CIPHER_CTX *de = EVP_CIPHER_CTX_new();
  72207. ExpectIntEQ(1, EVP_EncryptInit_ex(en, EVP_aes_256_gcm(), NULL, key, iv));
  72208. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  72209. ExpectIntEQ(1, EVP_EncryptUpdate(en, ciphertxt, &ciphertxtSz , plaintxt,
  72210. plaintxtSz));
  72211. ExpectIntEQ(1, EVP_EncryptFinal_ex(en, ciphertxt, &len));
  72212. ciphertxtSz += len;
  72213. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_GCM_GET_TAG, 16, tag));
  72214. ExpectIntEQ(1, EVP_CIPHER_CTX_cleanup(en));
  72215. ExpectIntEQ(0, ciphertxtSz);
  72216. ExpectIntEQ(0, XMEMCMP(tag, tag_kat, sizeof(tag)));
  72217. EVP_CIPHER_CTX_init(de);
  72218. ExpectIntEQ(1, EVP_DecryptInit_ex(de, EVP_aes_256_gcm(), NULL, key, iv));
  72219. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  72220. ExpectIntEQ(1, EVP_DecryptUpdate(de, NULL, &len, ciphertxt, len));
  72221. decryptedtxtSz = len;
  72222. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_GCM_SET_TAG, 16, tag));
  72223. ExpectIntEQ(1, EVP_DecryptFinal_ex(de, decryptedtxt, &len));
  72224. decryptedtxtSz += len;
  72225. ExpectIntEQ(0, decryptedtxtSz);
  72226. EVP_CIPHER_CTX_free(en);
  72227. EVP_CIPHER_CTX_free(de);
  72228. #endif
  72229. return EXPECT_RESULT();
  72230. }
  72231. static int test_wolfssl_EVP_aes_gcm(void)
  72232. {
  72233. EXPECT_DECLS;
  72234. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AESGCM) && \
  72235. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  72236. /* A 256 bit key, AES_128 will use the first 128 bit*/
  72237. byte *key = (byte*)"01234567890123456789012345678901";
  72238. /* A 128 bit IV */
  72239. byte *iv = (byte*)"0123456789012345";
  72240. int ivSz = AES_BLOCK_SIZE;
  72241. /* Message to be encrypted */
  72242. byte *plaintxt = (byte*)"for things to change you have to change";
  72243. /* Additional non-confidential data */
  72244. byte *aad = (byte*)"Don't spend major time on minor things.";
  72245. unsigned char tag[AES_BLOCK_SIZE] = {0};
  72246. int plaintxtSz = (int)XSTRLEN((char*)plaintxt);
  72247. int aadSz = (int)XSTRLEN((char*)aad);
  72248. byte ciphertxt[AES_BLOCK_SIZE * 4] = {0};
  72249. byte decryptedtxt[AES_BLOCK_SIZE * 4] = {0};
  72250. int ciphertxtSz = 0;
  72251. int decryptedtxtSz = 0;
  72252. int len = 0;
  72253. int i = 0;
  72254. EVP_CIPHER_CTX en[2];
  72255. EVP_CIPHER_CTX de[2];
  72256. for (i = 0; i < 2; i++) {
  72257. EVP_CIPHER_CTX_init(&en[i]);
  72258. if (i == 0) {
  72259. /* Default uses 96-bits IV length */
  72260. #ifdef WOLFSSL_AES_128
  72261. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_128_gcm(), NULL,
  72262. key, iv));
  72263. #elif defined(WOLFSSL_AES_192)
  72264. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_192_gcm(), NULL,
  72265. key, iv));
  72266. #elif defined(WOLFSSL_AES_256)
  72267. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_256_gcm(), NULL,
  72268. key, iv));
  72269. #endif
  72270. }
  72271. else {
  72272. #ifdef WOLFSSL_AES_128
  72273. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_128_gcm(), NULL,
  72274. NULL, NULL));
  72275. #elif defined(WOLFSSL_AES_192)
  72276. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_192_gcm(), NULL,
  72277. NULL, NULL));
  72278. #elif defined(WOLFSSL_AES_256)
  72279. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_256_gcm(), NULL,
  72280. NULL, NULL));
  72281. #endif
  72282. /* non-default must to set the IV length first */
  72283. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_SET_IVLEN,
  72284. ivSz, NULL));
  72285. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  72286. }
  72287. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], NULL, &len, aad, aadSz));
  72288. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], ciphertxt, &len, plaintxt,
  72289. plaintxtSz));
  72290. ciphertxtSz = len;
  72291. ExpectIntEQ(1, EVP_EncryptFinal_ex(&en[i], ciphertxt, &len));
  72292. ciphertxtSz += len;
  72293. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_GET_TAG,
  72294. AES_BLOCK_SIZE, tag));
  72295. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&en[i]), 1);
  72296. EVP_CIPHER_CTX_init(&de[i]);
  72297. if (i == 0) {
  72298. /* Default uses 96-bits IV length */
  72299. #ifdef WOLFSSL_AES_128
  72300. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_gcm(), NULL,
  72301. key, iv));
  72302. #elif defined(WOLFSSL_AES_192)
  72303. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_gcm(), NULL,
  72304. key, iv));
  72305. #elif defined(WOLFSSL_AES_256)
  72306. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_gcm(), NULL,
  72307. key, iv));
  72308. #endif
  72309. }
  72310. else {
  72311. #ifdef WOLFSSL_AES_128
  72312. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_gcm(), NULL,
  72313. NULL, NULL));
  72314. #elif defined(WOLFSSL_AES_192)
  72315. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_gcm(), NULL,
  72316. NULL, NULL));
  72317. #elif defined(WOLFSSL_AES_256)
  72318. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_gcm(), NULL,
  72319. NULL, NULL));
  72320. #endif
  72321. /* non-default must to set the IV length first */
  72322. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN,
  72323. ivSz, NULL));
  72324. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  72325. }
  72326. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  72327. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  72328. ciphertxtSz));
  72329. decryptedtxtSz = len;
  72330. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG,
  72331. AES_BLOCK_SIZE, tag));
  72332. ExpectIntEQ(1, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  72333. decryptedtxtSz += len;
  72334. ExpectIntEQ(ciphertxtSz, decryptedtxtSz);
  72335. ExpectIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
  72336. /* modify tag*/
  72337. if (i == 0) {
  72338. /* Default uses 96-bits IV length */
  72339. #ifdef WOLFSSL_AES_128
  72340. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_gcm(), NULL,
  72341. key, iv));
  72342. #elif defined(WOLFSSL_AES_192)
  72343. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_gcm(), NULL,
  72344. key, iv));
  72345. #elif defined(WOLFSSL_AES_256)
  72346. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_gcm(), NULL,
  72347. key, iv));
  72348. #endif
  72349. }
  72350. else {
  72351. #ifdef WOLFSSL_AES_128
  72352. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_gcm(), NULL,
  72353. NULL, NULL));
  72354. #elif defined(WOLFSSL_AES_192)
  72355. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_gcm(), NULL,
  72356. NULL, NULL));
  72357. #elif defined(WOLFSSL_AES_256)
  72358. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_gcm(), NULL,
  72359. NULL, NULL));
  72360. #endif
  72361. /* non-default must to set the IV length first */
  72362. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN,
  72363. ivSz, NULL));
  72364. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  72365. }
  72366. tag[AES_BLOCK_SIZE-1]+=0xBB;
  72367. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  72368. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG,
  72369. AES_BLOCK_SIZE, tag));
  72370. /* fail due to wrong tag */
  72371. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  72372. ciphertxtSz));
  72373. ExpectIntEQ(0, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  72374. ExpectIntEQ(0, len);
  72375. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&de[i]), 1);
  72376. }
  72377. #endif /* OPENSSL_EXTRA && !NO_AES && HAVE_AESGCM */
  72378. return EXPECT_RESULT();
  72379. }
  72380. static int test_wolfssl_EVP_aria_gcm(void)
  72381. {
  72382. int res = TEST_SKIPPED;
  72383. #if defined(OPENSSL_EXTRA) && defined(HAVE_ARIA) && \
  72384. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  72385. /* A 256 bit key, AES_128 will use the first 128 bit*/
  72386. byte *key = (byte*)"01234567890123456789012345678901";
  72387. /* A 128 bit IV */
  72388. byte *iv = (byte*)"0123456789012345";
  72389. int ivSz = ARIA_BLOCK_SIZE;
  72390. /* Message to be encrypted */
  72391. const int plaintxtSz = 40;
  72392. byte plaintxt[WC_ARIA_GCM_GET_CIPHERTEXT_SIZE(plaintxtSz)];
  72393. XMEMCPY(plaintxt,"for things to change you have to change",plaintxtSz);
  72394. /* Additional non-confidential data */
  72395. byte *aad = (byte*)"Don't spend major time on minor things.";
  72396. unsigned char tag[ARIA_BLOCK_SIZE] = {0};
  72397. int aadSz = (int)XSTRLEN((char*)aad);
  72398. byte ciphertxt[WC_ARIA_GCM_GET_CIPHERTEXT_SIZE(plaintxtSz)];
  72399. byte decryptedtxt[plaintxtSz];
  72400. int ciphertxtSz = 0;
  72401. int decryptedtxtSz = 0;
  72402. int len = 0;
  72403. int i = 0;
  72404. #define TEST_ARIA_GCM_COUNT 6
  72405. EVP_CIPHER_CTX en[TEST_ARIA_GCM_COUNT];
  72406. EVP_CIPHER_CTX de[TEST_ARIA_GCM_COUNT];
  72407. for (i = 0; i < TEST_ARIA_GCM_COUNT; i++) {
  72408. EVP_CIPHER_CTX_init(&en[i]);
  72409. switch (i) {
  72410. case 0:
  72411. /* Default uses 96-bits IV length */
  72412. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_128_gcm(), NULL, key, iv));
  72413. break;
  72414. case 1:
  72415. /* Default uses 96-bits IV length */
  72416. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_192_gcm(), NULL, key, iv));
  72417. break;
  72418. case 2:
  72419. /* Default uses 96-bits IV length */
  72420. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_256_gcm(), NULL, key, iv));
  72421. break;
  72422. case 3:
  72423. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_128_gcm(), NULL, NULL, NULL));
  72424. /* non-default must to set the IV length first */
  72425. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  72426. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  72427. break;
  72428. case 4:
  72429. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_192_gcm(), NULL, NULL, NULL));
  72430. /* non-default must to set the IV length first */
  72431. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  72432. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  72433. break;
  72434. case 5:
  72435. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_256_gcm(), NULL, NULL, NULL));
  72436. /* non-default must to set the IV length first */
  72437. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  72438. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  72439. break;
  72440. }
  72441. XMEMSET(ciphertxt,0,sizeof(ciphertxt));
  72442. AssertIntEQ(1, EVP_EncryptUpdate(&en[i], NULL, &len, aad, aadSz));
  72443. AssertIntEQ(1, EVP_EncryptUpdate(&en[i], ciphertxt, &len, plaintxt, plaintxtSz));
  72444. ciphertxtSz = len;
  72445. AssertIntEQ(1, EVP_EncryptFinal_ex(&en[i], ciphertxt, &len));
  72446. AssertIntNE(0, XMEMCMP(plaintxt, ciphertxt, plaintxtSz));
  72447. ciphertxtSz += len;
  72448. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_GET_TAG, ARIA_BLOCK_SIZE, tag));
  72449. AssertIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&en[i]), 1);
  72450. EVP_CIPHER_CTX_init(&de[i]);
  72451. switch (i) {
  72452. case 0:
  72453. /* Default uses 96-bits IV length */
  72454. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_128_gcm(), NULL, key, iv));
  72455. break;
  72456. case 1:
  72457. /* Default uses 96-bits IV length */
  72458. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_192_gcm(), NULL, key, iv));
  72459. break;
  72460. case 2:
  72461. /* Default uses 96-bits IV length */
  72462. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_256_gcm(), NULL, key, iv));
  72463. break;
  72464. case 3:
  72465. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_128_gcm(), NULL, NULL, NULL));
  72466. /* non-default must to set the IV length first */
  72467. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  72468. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  72469. break;
  72470. case 4:
  72471. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_192_gcm(), NULL, NULL, NULL));
  72472. /* non-default must to set the IV length first */
  72473. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  72474. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  72475. break;
  72476. case 5:
  72477. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_256_gcm(), NULL, NULL, NULL));
  72478. /* non-default must to set the IV length first */
  72479. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  72480. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  72481. break;
  72482. }
  72483. XMEMSET(decryptedtxt,0,sizeof(decryptedtxt));
  72484. AssertIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  72485. AssertIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt, ciphertxtSz));
  72486. decryptedtxtSz = len;
  72487. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG, ARIA_BLOCK_SIZE, tag));
  72488. AssertIntEQ(1, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  72489. decryptedtxtSz += len;
  72490. AssertIntEQ(plaintxtSz, decryptedtxtSz);
  72491. AssertIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
  72492. XMEMSET(decryptedtxt,0,sizeof(decryptedtxt));
  72493. /* modify tag*/
  72494. tag[AES_BLOCK_SIZE-1]+=0xBB;
  72495. AssertIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  72496. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG, ARIA_BLOCK_SIZE, tag));
  72497. /* fail due to wrong tag */
  72498. AssertIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt, ciphertxtSz));
  72499. AssertIntEQ(0, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  72500. AssertIntEQ(0, len);
  72501. AssertIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&de[i]), 1);
  72502. }
  72503. res = TEST_RES_CHECK(1);
  72504. #endif /* OPENSSL_EXTRA && !NO_AES && HAVE_AESGCM */
  72505. return res;
  72506. }
  72507. static int test_wolfssl_EVP_aes_ccm_zeroLen(void)
  72508. {
  72509. EXPECT_DECLS;
  72510. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AESCCM) && \
  72511. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  72512. /* Zero length plain text */
  72513. byte key[] = {
  72514. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72515. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72516. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72517. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  72518. }; /* align */
  72519. byte iv[] = {
  72520. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  72521. }; /* align */
  72522. byte plaintxt[1];
  72523. int ivSz = 12;
  72524. int plaintxtSz = 0;
  72525. unsigned char tag[16];
  72526. byte ciphertxt[AES_BLOCK_SIZE * 4] = {0};
  72527. byte decryptedtxt[AES_BLOCK_SIZE * 4] = {0};
  72528. int ciphertxtSz = 0;
  72529. int decryptedtxtSz = 0;
  72530. int len = 0;
  72531. EVP_CIPHER_CTX *en = EVP_CIPHER_CTX_new();
  72532. EVP_CIPHER_CTX *de = EVP_CIPHER_CTX_new();
  72533. ExpectIntEQ(1, EVP_EncryptInit_ex(en, EVP_aes_256_ccm(), NULL, key, iv));
  72534. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_CCM_SET_IVLEN, ivSz, NULL));
  72535. ExpectIntEQ(1, EVP_EncryptUpdate(en, ciphertxt, &ciphertxtSz , plaintxt,
  72536. plaintxtSz));
  72537. ExpectIntEQ(1, EVP_EncryptFinal_ex(en, ciphertxt, &len));
  72538. ciphertxtSz += len;
  72539. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_CCM_GET_TAG, 16, tag));
  72540. ExpectIntEQ(1, EVP_CIPHER_CTX_cleanup(en));
  72541. ExpectIntEQ(0, ciphertxtSz);
  72542. EVP_CIPHER_CTX_init(de);
  72543. ExpectIntEQ(1, EVP_DecryptInit_ex(de, EVP_aes_256_ccm(), NULL, key, iv));
  72544. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_CCM_SET_IVLEN, ivSz, NULL));
  72545. ExpectIntEQ(1, EVP_DecryptUpdate(de, NULL, &len, ciphertxt, len));
  72546. decryptedtxtSz = len;
  72547. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_CCM_SET_TAG, 16, tag));
  72548. ExpectIntEQ(1, EVP_DecryptFinal_ex(de, decryptedtxt, &len));
  72549. decryptedtxtSz += len;
  72550. ExpectIntEQ(0, decryptedtxtSz);
  72551. EVP_CIPHER_CTX_free(en);
  72552. EVP_CIPHER_CTX_free(de);
  72553. #endif
  72554. return EXPECT_RESULT();
  72555. }
  72556. static int test_wolfssl_EVP_aes_ccm(void)
  72557. {
  72558. EXPECT_DECLS;
  72559. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AESCCM) && \
  72560. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  72561. /* A 256 bit key, AES_128 will use the first 128 bit*/
  72562. byte *key = (byte*)"01234567890123456789012345678901";
  72563. /* A 128 bit IV */
  72564. byte *iv = (byte*)"0123456789012";
  72565. int ivSz = (int)XSTRLEN((char*)iv);
  72566. /* Message to be encrypted */
  72567. byte *plaintxt = (byte*)"for things to change you have to change";
  72568. /* Additional non-confidential data */
  72569. byte *aad = (byte*)"Don't spend major time on minor things.";
  72570. unsigned char tag[AES_BLOCK_SIZE] = {0};
  72571. int plaintxtSz = (int)XSTRLEN((char*)plaintxt);
  72572. int aadSz = (int)XSTRLEN((char*)aad);
  72573. byte ciphertxt[AES_BLOCK_SIZE * 4] = {0};
  72574. byte decryptedtxt[AES_BLOCK_SIZE * 4] = {0};
  72575. int ciphertxtSz = 0;
  72576. int decryptedtxtSz = 0;
  72577. int len = 0;
  72578. int i = 0;
  72579. int ret;
  72580. EVP_CIPHER_CTX en[2];
  72581. EVP_CIPHER_CTX de[2];
  72582. for (i = 0; i < 2; i++) {
  72583. EVP_CIPHER_CTX_init(&en[i]);
  72584. if (i == 0) {
  72585. /* Default uses 96-bits IV length */
  72586. #ifdef WOLFSSL_AES_128
  72587. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_128_ccm(), NULL,
  72588. key, iv));
  72589. #elif defined(WOLFSSL_AES_192)
  72590. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_192_ccm(), NULL,
  72591. key, iv));
  72592. #elif defined(WOLFSSL_AES_256)
  72593. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_256_ccm(), NULL,
  72594. key, iv));
  72595. #endif
  72596. }
  72597. else {
  72598. #ifdef WOLFSSL_AES_128
  72599. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_128_ccm(), NULL,
  72600. NULL, NULL));
  72601. #elif defined(WOLFSSL_AES_192)
  72602. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_192_ccm(), NULL,
  72603. NULL, NULL));
  72604. #elif defined(WOLFSSL_AES_256)
  72605. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_256_ccm(), NULL,
  72606. NULL, NULL));
  72607. #endif
  72608. /* non-default must to set the IV length first */
  72609. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_CCM_SET_IVLEN,
  72610. ivSz, NULL));
  72611. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  72612. }
  72613. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], NULL, &len, aad, aadSz));
  72614. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], ciphertxt, &len, plaintxt,
  72615. plaintxtSz));
  72616. ciphertxtSz = len;
  72617. ExpectIntEQ(1, EVP_EncryptFinal_ex(&en[i], ciphertxt, &len));
  72618. ciphertxtSz += len;
  72619. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_CCM_GET_TAG,
  72620. AES_BLOCK_SIZE, tag));
  72621. ret = wolfSSL_EVP_CIPHER_CTX_cleanup(&en[i]);
  72622. ExpectIntEQ(ret, 1);
  72623. EVP_CIPHER_CTX_init(&de[i]);
  72624. if (i == 0) {
  72625. /* Default uses 96-bits IV length */
  72626. #ifdef WOLFSSL_AES_128
  72627. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_ccm(), NULL,
  72628. key, iv));
  72629. #elif defined(WOLFSSL_AES_192)
  72630. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_ccm(), NULL,
  72631. key, iv));
  72632. #elif defined(WOLFSSL_AES_256)
  72633. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_ccm(), NULL,
  72634. key, iv));
  72635. #endif
  72636. }
  72637. else {
  72638. #ifdef WOLFSSL_AES_128
  72639. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_ccm(), NULL,
  72640. NULL, NULL));
  72641. #elif defined(WOLFSSL_AES_192)
  72642. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_ccm(), NULL,
  72643. NULL, NULL));
  72644. #elif defined(WOLFSSL_AES_256)
  72645. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_ccm(), NULL,
  72646. NULL, NULL));
  72647. #endif
  72648. /* non-default must to set the IV length first */
  72649. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_IVLEN,
  72650. ivSz, NULL));
  72651. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  72652. }
  72653. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  72654. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  72655. ciphertxtSz));
  72656. decryptedtxtSz = len;
  72657. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_TAG,
  72658. AES_BLOCK_SIZE, tag));
  72659. ExpectIntEQ(1, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  72660. decryptedtxtSz += len;
  72661. ExpectIntEQ(ciphertxtSz, decryptedtxtSz);
  72662. ExpectIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
  72663. /* modify tag*/
  72664. tag[AES_BLOCK_SIZE-1]+=0xBB;
  72665. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  72666. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_TAG,
  72667. AES_BLOCK_SIZE, tag));
  72668. /* fail due to wrong tag */
  72669. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  72670. ciphertxtSz));
  72671. ExpectIntEQ(0, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  72672. ExpectIntEQ(0, len);
  72673. ret = wolfSSL_EVP_CIPHER_CTX_cleanup(&de[i]);
  72674. ExpectIntEQ(ret, 1);
  72675. }
  72676. #endif /* OPENSSL_EXTRA && !NO_AES && HAVE_AESCCM */
  72677. return EXPECT_RESULT();
  72678. }
  72679. static int test_wolfssl_EVP_chacha20_poly1305(void)
  72680. {
  72681. EXPECT_DECLS;
  72682. #if defined(OPENSSL_EXTRA) && defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  72683. byte key[CHACHA20_POLY1305_AEAD_KEYSIZE];
  72684. byte iv [CHACHA20_POLY1305_AEAD_IV_SIZE];
  72685. byte plainText[] = {0xDE, 0xAD, 0xBE, 0xEF};
  72686. byte aad[] = {0xAA, 0XBB, 0xCC, 0xDD, 0xEE, 0xFF};
  72687. byte cipherText[sizeof(plainText)];
  72688. byte decryptedText[sizeof(plainText)];
  72689. byte tag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE];
  72690. EVP_CIPHER_CTX* ctx = NULL;
  72691. int outSz;
  72692. XMEMSET(key, 0, sizeof(key));
  72693. XMEMSET(iv, 0, sizeof(iv));
  72694. /* Encrypt. */
  72695. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72696. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_chacha20_poly1305(), NULL, NULL,
  72697. NULL), WOLFSSL_SUCCESS);
  72698. /* Invalid IV length. */
  72699. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN,
  72700. CHACHA20_POLY1305_AEAD_IV_SIZE-1, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72701. /* Valid IV length. */
  72702. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN,
  72703. CHACHA20_POLY1305_AEAD_IV_SIZE, NULL), WOLFSSL_SUCCESS);
  72704. /* Invalid tag length. */
  72705. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
  72706. CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE-1, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72707. /* Valid tag length. */
  72708. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
  72709. CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, NULL), WOLFSSL_SUCCESS);
  72710. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  72711. ExpectIntEQ(EVP_EncryptUpdate(ctx, NULL, &outSz, aad, sizeof(aad)),
  72712. WOLFSSL_SUCCESS);
  72713. ExpectIntEQ(outSz, sizeof(aad));
  72714. ExpectIntEQ(EVP_EncryptUpdate(ctx, cipherText, &outSz, plainText,
  72715. sizeof(plainText)), WOLFSSL_SUCCESS);
  72716. ExpectIntEQ(outSz, sizeof(plainText));
  72717. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, cipherText, &outSz), WOLFSSL_SUCCESS);
  72718. ExpectIntEQ(outSz, 0);
  72719. /* Invalid tag length. */
  72720. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG,
  72721. CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE-1, tag), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72722. /* Valid tag length. */
  72723. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG,
  72724. CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, tag), WOLFSSL_SUCCESS);
  72725. EVP_CIPHER_CTX_free(ctx);
  72726. ctx = NULL;
  72727. /* Decrypt. */
  72728. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72729. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_chacha20_poly1305(), NULL, NULL,
  72730. NULL), WOLFSSL_SUCCESS);
  72731. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN,
  72732. CHACHA20_POLY1305_AEAD_IV_SIZE, NULL), WOLFSSL_SUCCESS);
  72733. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
  72734. CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, tag), WOLFSSL_SUCCESS);
  72735. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  72736. ExpectIntEQ(EVP_DecryptUpdate(ctx, NULL, &outSz, aad, sizeof(aad)),
  72737. WOLFSSL_SUCCESS);
  72738. ExpectIntEQ(outSz, sizeof(aad));
  72739. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72740. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72741. ExpectIntEQ(outSz, sizeof(cipherText));
  72742. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  72743. WOLFSSL_SUCCESS);
  72744. ExpectIntEQ(outSz, 0);
  72745. EVP_CIPHER_CTX_free(ctx);
  72746. ctx = NULL;
  72747. /* Test partial Inits. CipherInit() allow setting of key and iv
  72748. * in separate calls. */
  72749. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72750. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, EVP_chacha20_poly1305(),
  72751. key, NULL, 1), WOLFSSL_SUCCESS);
  72752. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, NULL, NULL, iv, 1),
  72753. WOLFSSL_SUCCESS);
  72754. ExpectIntEQ(wolfSSL_EVP_CipherUpdate(ctx, NULL, &outSz,
  72755. aad, sizeof(aad)), WOLFSSL_SUCCESS);
  72756. ExpectIntEQ(outSz, sizeof(aad));
  72757. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72758. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72759. ExpectIntEQ(outSz, sizeof(cipherText));
  72760. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  72761. WOLFSSL_SUCCESS);
  72762. ExpectIntEQ(outSz, 0);
  72763. EVP_CIPHER_CTX_free(ctx);
  72764. #endif
  72765. return EXPECT_RESULT();
  72766. }
  72767. static int test_wolfssl_EVP_chacha20(void)
  72768. {
  72769. EXPECT_DECLS;
  72770. #if defined(OPENSSL_EXTRA) && defined(HAVE_CHACHA)
  72771. byte key[CHACHA_MAX_KEY_SZ];
  72772. byte iv [WOLFSSL_EVP_CHACHA_IV_BYTES];
  72773. byte plainText[] = {0xDE, 0xAD, 0xBE, 0xEF};
  72774. byte cipherText[sizeof(plainText)];
  72775. byte decryptedText[sizeof(plainText)];
  72776. EVP_CIPHER_CTX* ctx = NULL;
  72777. int outSz;
  72778. XMEMSET(key, 0, sizeof(key));
  72779. XMEMSET(iv, 0, sizeof(iv));
  72780. /* Encrypt. */
  72781. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72782. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_chacha20(), NULL, NULL,
  72783. NULL), WOLFSSL_SUCCESS);
  72784. /* Any tag length must fail - not an AEAD cipher. */
  72785. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
  72786. 16, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72787. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  72788. ExpectIntEQ(EVP_EncryptUpdate(ctx, cipherText, &outSz, plainText,
  72789. sizeof(plainText)), WOLFSSL_SUCCESS);
  72790. ExpectIntEQ(outSz, sizeof(plainText));
  72791. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, cipherText, &outSz), WOLFSSL_SUCCESS);
  72792. ExpectIntEQ(outSz, 0);
  72793. EVP_CIPHER_CTX_free(ctx);
  72794. ctx = NULL;
  72795. /* Decrypt. */
  72796. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72797. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_chacha20(), NULL, NULL,
  72798. NULL), WOLFSSL_SUCCESS);
  72799. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  72800. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72801. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72802. ExpectIntEQ(outSz, sizeof(cipherText));
  72803. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  72804. WOLFSSL_SUCCESS);
  72805. ExpectIntEQ(outSz, 0);
  72806. EVP_CIPHER_CTX_free(ctx);
  72807. ctx = NULL;
  72808. /* Test partial Inits. CipherInit() allow setting of key and iv
  72809. * in separate calls. */
  72810. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72811. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, EVP_chacha20(),
  72812. key, NULL, 1), WOLFSSL_SUCCESS);
  72813. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, NULL, NULL, iv, 1),
  72814. WOLFSSL_SUCCESS);
  72815. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72816. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72817. ExpectIntEQ(outSz, sizeof(cipherText));
  72818. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  72819. WOLFSSL_SUCCESS);
  72820. ExpectIntEQ(outSz, 0);
  72821. EVP_CIPHER_CTX_free(ctx);
  72822. #endif
  72823. return EXPECT_RESULT();
  72824. }
  72825. static int test_wolfssl_EVP_sm4_ecb(void)
  72826. {
  72827. int res = TEST_SKIPPED;
  72828. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_ECB)
  72829. EXPECT_DECLS;
  72830. byte key[SM4_KEY_SIZE];
  72831. byte plainText[SM4_BLOCK_SIZE] = {
  72832. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF,
  72833. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF
  72834. };
  72835. byte cipherText[sizeof(plainText) + SM4_BLOCK_SIZE];
  72836. byte decryptedText[sizeof(plainText) + SM4_BLOCK_SIZE];
  72837. EVP_CIPHER_CTX* ctx;
  72838. int outSz;
  72839. XMEMSET(key, 0, sizeof(key));
  72840. /* Encrypt. */
  72841. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72842. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_sm4_ecb(), NULL, NULL, NULL),
  72843. WOLFSSL_SUCCESS);
  72844. /* Any tag length must fail - not an AEAD cipher. */
  72845. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, 16, NULL),
  72846. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72847. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, NULL),
  72848. WOLFSSL_SUCCESS);
  72849. ExpectIntEQ(EVP_EncryptUpdate(ctx, cipherText, &outSz, plainText,
  72850. sizeof(plainText)), WOLFSSL_SUCCESS);
  72851. ExpectIntEQ(outSz, sizeof(plainText));
  72852. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, cipherText + outSz, &outSz),
  72853. WOLFSSL_SUCCESS);
  72854. ExpectIntEQ(outSz, SM4_BLOCK_SIZE);
  72855. ExpectBufNE(cipherText, plainText, sizeof(plainText));
  72856. EVP_CIPHER_CTX_free(ctx);
  72857. /* Decrypt. */
  72858. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72859. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_sm4_ecb(), NULL, NULL, NULL),
  72860. WOLFSSL_SUCCESS);
  72861. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, NULL),
  72862. WOLFSSL_SUCCESS);
  72863. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72864. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72865. ExpectIntEQ(outSz, sizeof(plainText));
  72866. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText + outSz, &outSz),
  72867. WOLFSSL_SUCCESS);
  72868. ExpectIntEQ(outSz, 0);
  72869. ExpectBufEQ(decryptedText, plainText, sizeof(plainText));
  72870. EVP_CIPHER_CTX_free(ctx);
  72871. res = EXPECT_RESULT();
  72872. #endif
  72873. return res;
  72874. }
  72875. static int test_wolfssl_EVP_sm4_cbc(void)
  72876. {
  72877. int res = TEST_SKIPPED;
  72878. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_CBC)
  72879. EXPECT_DECLS;
  72880. byte key[SM4_KEY_SIZE];
  72881. byte iv[SM4_BLOCK_SIZE];
  72882. byte plainText[SM4_BLOCK_SIZE] = {
  72883. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF,
  72884. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF
  72885. };
  72886. byte cipherText[sizeof(plainText) + SM4_BLOCK_SIZE];
  72887. byte decryptedText[sizeof(plainText) + SM4_BLOCK_SIZE];
  72888. EVP_CIPHER_CTX* ctx;
  72889. int outSz;
  72890. XMEMSET(key, 0, sizeof(key));
  72891. XMEMSET(iv, 0, sizeof(iv));
  72892. /* Encrypt. */
  72893. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72894. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_sm4_cbc(), NULL, NULL, NULL),
  72895. WOLFSSL_SUCCESS);
  72896. /* Any tag length must fail - not an AEAD cipher. */
  72897. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, 16, NULL),
  72898. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72899. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  72900. ExpectIntEQ(EVP_EncryptUpdate(ctx, cipherText, &outSz, plainText,
  72901. sizeof(plainText)), WOLFSSL_SUCCESS);
  72902. ExpectIntEQ(outSz, sizeof(plainText));
  72903. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, cipherText + outSz, &outSz),
  72904. WOLFSSL_SUCCESS);
  72905. ExpectIntEQ(outSz, SM4_BLOCK_SIZE);
  72906. ExpectBufNE(cipherText, plainText, sizeof(plainText));
  72907. EVP_CIPHER_CTX_free(ctx);
  72908. /* Decrypt. */
  72909. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72910. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_sm4_cbc(), NULL, NULL, NULL),
  72911. WOLFSSL_SUCCESS);
  72912. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  72913. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72914. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72915. ExpectIntEQ(outSz, sizeof(plainText));
  72916. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText + outSz, &outSz),
  72917. WOLFSSL_SUCCESS);
  72918. ExpectIntEQ(outSz, 0);
  72919. ExpectBufEQ(decryptedText, plainText, sizeof(plainText));
  72920. EVP_CIPHER_CTX_free(ctx);
  72921. /* Test partial Inits. CipherInit() allow setting of key and iv
  72922. * in separate calls. */
  72923. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72924. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, EVP_sm4_cbc(), key, NULL, 0),
  72925. WOLFSSL_SUCCESS);
  72926. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, NULL, NULL, iv, 0),
  72927. WOLFSSL_SUCCESS);
  72928. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72929. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72930. ExpectIntEQ(outSz, sizeof(plainText));
  72931. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText + outSz, &outSz),
  72932. WOLFSSL_SUCCESS);
  72933. ExpectIntEQ(outSz, 0);
  72934. ExpectBufEQ(decryptedText, plainText, sizeof(plainText));
  72935. EVP_CIPHER_CTX_free(ctx);
  72936. res = EXPECT_RESULT();
  72937. #endif
  72938. return res;
  72939. }
  72940. static int test_wolfssl_EVP_sm4_ctr(void)
  72941. {
  72942. int res = TEST_SKIPPED;
  72943. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_CTR)
  72944. EXPECT_DECLS;
  72945. byte key[SM4_KEY_SIZE];
  72946. byte iv[SM4_BLOCK_SIZE];
  72947. byte plainText[] = {0xDE, 0xAD, 0xBE, 0xEF};
  72948. byte cipherText[sizeof(plainText)];
  72949. byte decryptedText[sizeof(plainText)];
  72950. EVP_CIPHER_CTX* ctx;
  72951. int outSz;
  72952. XMEMSET(key, 0, sizeof(key));
  72953. XMEMSET(iv, 0, sizeof(iv));
  72954. /* Encrypt. */
  72955. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72956. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_sm4_ctr(), NULL, NULL, NULL),
  72957. WOLFSSL_SUCCESS);
  72958. /* Any tag length must fail - not an AEAD cipher. */
  72959. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, 16, NULL),
  72960. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72961. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  72962. ExpectIntEQ(EVP_EncryptUpdate(ctx, cipherText, &outSz, plainText,
  72963. sizeof(plainText)), WOLFSSL_SUCCESS);
  72964. ExpectIntEQ(outSz, sizeof(plainText));
  72965. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, cipherText, &outSz), WOLFSSL_SUCCESS);
  72966. ExpectIntEQ(outSz, 0);
  72967. ExpectBufNE(cipherText, plainText, sizeof(plainText));
  72968. EVP_CIPHER_CTX_free(ctx);
  72969. /* Decrypt. */
  72970. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72971. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_sm4_ctr(), NULL, NULL, NULL),
  72972. WOLFSSL_SUCCESS);
  72973. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  72974. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72975. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72976. ExpectIntEQ(outSz, sizeof(cipherText));
  72977. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  72978. WOLFSSL_SUCCESS);
  72979. ExpectIntEQ(outSz, 0);
  72980. ExpectBufEQ(decryptedText, plainText, sizeof(plainText));
  72981. EVP_CIPHER_CTX_free(ctx);
  72982. /* Test partial Inits. CipherInit() allow setting of key and iv
  72983. * in separate calls. */
  72984. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  72985. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, EVP_sm4_ctr(), key, NULL, 1),
  72986. WOLFSSL_SUCCESS);
  72987. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, NULL, NULL, iv, 1),
  72988. WOLFSSL_SUCCESS);
  72989. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  72990. sizeof(cipherText)), WOLFSSL_SUCCESS);
  72991. ExpectIntEQ(outSz, sizeof(cipherText));
  72992. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  72993. WOLFSSL_SUCCESS);
  72994. ExpectIntEQ(outSz, 0);
  72995. ExpectBufEQ(decryptedText, plainText, sizeof(plainText));
  72996. EVP_CIPHER_CTX_free(ctx);
  72997. res = EXPECT_RESULT();
  72998. #endif
  72999. return res;
  73000. }
  73001. static int test_wolfssl_EVP_sm4_gcm_zeroLen(void)
  73002. {
  73003. int res = TEST_SKIPPED;
  73004. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_GCM)
  73005. /* Zero length plain text */
  73006. EXPECT_DECLS;
  73007. byte key[] = {
  73008. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73009. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73010. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73011. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  73012. }; /* align */
  73013. byte iv[] = {
  73014. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  73015. }; /* align */
  73016. byte plaintxt[1];
  73017. int ivSz = 12;
  73018. int plaintxtSz = 0;
  73019. unsigned char tag[16];
  73020. unsigned char tag_kat[16] = {
  73021. 0x23,0x2f,0x0c,0xfe,0x30,0x8b,0x49,0xea,
  73022. 0x6f,0xc8,0x82,0x29,0xb5,0xdc,0x85,0x8d
  73023. };
  73024. byte ciphertxt[SM4_BLOCK_SIZE * 4] = {0};
  73025. byte decryptedtxt[SM4_BLOCK_SIZE * 4] = {0};
  73026. int ciphertxtSz = 0;
  73027. int decryptedtxtSz = 0;
  73028. int len = 0;
  73029. EVP_CIPHER_CTX *en = EVP_CIPHER_CTX_new();
  73030. EVP_CIPHER_CTX *de = EVP_CIPHER_CTX_new();
  73031. ExpectIntEQ(1, EVP_EncryptInit_ex(en, EVP_sm4_gcm(), NULL, key, iv));
  73032. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  73033. ExpectIntEQ(1, EVP_EncryptUpdate(en, ciphertxt, &ciphertxtSz , plaintxt,
  73034. plaintxtSz));
  73035. ExpectIntEQ(1, EVP_EncryptFinal_ex(en, ciphertxt, &len));
  73036. ciphertxtSz += len;
  73037. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_GCM_GET_TAG, 16, tag));
  73038. ExpectIntEQ(1, EVP_CIPHER_CTX_cleanup(en));
  73039. ExpectIntEQ(0, ciphertxtSz);
  73040. ExpectIntEQ(0, XMEMCMP(tag, tag_kat, sizeof(tag)));
  73041. EVP_CIPHER_CTX_init(de);
  73042. ExpectIntEQ(1, EVP_DecryptInit_ex(de, EVP_sm4_gcm(), NULL, key, iv));
  73043. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  73044. ExpectIntEQ(1, EVP_DecryptUpdate(de, NULL, &len, ciphertxt, len));
  73045. decryptedtxtSz = len;
  73046. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_GCM_SET_TAG, 16, tag));
  73047. ExpectIntEQ(1, EVP_DecryptFinal_ex(de, decryptedtxt, &len));
  73048. decryptedtxtSz += len;
  73049. ExpectIntEQ(0, decryptedtxtSz);
  73050. EVP_CIPHER_CTX_free(en);
  73051. EVP_CIPHER_CTX_free(de);
  73052. res = EXPECT_RESULT();
  73053. #endif /* OPENSSL_EXTRA && WOLFSSL_SM4_GCM */
  73054. return res;
  73055. }
  73056. static int test_wolfssl_EVP_sm4_gcm(void)
  73057. {
  73058. int res = TEST_SKIPPED;
  73059. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_GCM)
  73060. EXPECT_DECLS;
  73061. byte *key = (byte*)"0123456789012345";
  73062. /* A 128 bit IV */
  73063. byte *iv = (byte*)"0123456789012345";
  73064. int ivSz = SM4_BLOCK_SIZE;
  73065. /* Message to be encrypted */
  73066. byte *plaintxt = (byte*)"for things to change you have to change";
  73067. /* Additional non-confidential data */
  73068. byte *aad = (byte*)"Don't spend major time on minor things.";
  73069. unsigned char tag[SM4_BLOCK_SIZE] = {0};
  73070. int plaintxtSz = (int)XSTRLEN((char*)plaintxt);
  73071. int aadSz = (int)XSTRLEN((char*)aad);
  73072. byte ciphertxt[SM4_BLOCK_SIZE * 4] = {0};
  73073. byte decryptedtxt[SM4_BLOCK_SIZE * 4] = {0};
  73074. int ciphertxtSz = 0;
  73075. int decryptedtxtSz = 0;
  73076. int len = 0;
  73077. int i = 0;
  73078. EVP_CIPHER_CTX en[2];
  73079. EVP_CIPHER_CTX de[2];
  73080. for (i = 0; i < 2; i++) {
  73081. EVP_CIPHER_CTX_init(&en[i]);
  73082. if (i == 0) {
  73083. /* Default uses 96-bits IV length */
  73084. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_sm4_gcm(), NULL, key,
  73085. iv));
  73086. }
  73087. else {
  73088. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_sm4_gcm(), NULL, NULL,
  73089. NULL));
  73090. /* non-default must to set the IV length first */
  73091. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_SET_IVLEN,
  73092. ivSz, NULL));
  73093. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  73094. }
  73095. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], NULL, &len, aad, aadSz));
  73096. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], ciphertxt, &len, plaintxt,
  73097. plaintxtSz));
  73098. ciphertxtSz = len;
  73099. ExpectIntEQ(1, EVP_EncryptFinal_ex(&en[i], ciphertxt, &len));
  73100. ciphertxtSz += len;
  73101. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_GET_TAG,
  73102. SM4_BLOCK_SIZE, tag));
  73103. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&en[i]), 1);
  73104. EVP_CIPHER_CTX_init(&de[i]);
  73105. if (i == 0) {
  73106. /* Default uses 96-bits IV length */
  73107. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_sm4_gcm(), NULL, key,
  73108. iv));
  73109. }
  73110. else {
  73111. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_sm4_gcm(), NULL, NULL,
  73112. NULL));
  73113. /* non-default must to set the IV length first */
  73114. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN,
  73115. ivSz, NULL));
  73116. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  73117. }
  73118. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  73119. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  73120. ciphertxtSz));
  73121. decryptedtxtSz = len;
  73122. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG,
  73123. SM4_BLOCK_SIZE, tag));
  73124. ExpectIntEQ(1, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  73125. decryptedtxtSz += len;
  73126. ExpectIntEQ(ciphertxtSz, decryptedtxtSz);
  73127. ExpectIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
  73128. /* modify tag*/
  73129. tag[SM4_BLOCK_SIZE-1]+=0xBB;
  73130. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  73131. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG,
  73132. SM4_BLOCK_SIZE, tag));
  73133. /* fail due to wrong tag */
  73134. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  73135. ciphertxtSz));
  73136. ExpectIntEQ(0, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  73137. ExpectIntEQ(0, len);
  73138. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&de[i]), 1);
  73139. }
  73140. res = EXPECT_RESULT();
  73141. #endif /* OPENSSL_EXTRA && WOLFSSL_SM4_GCM */
  73142. return res;
  73143. }
  73144. static int test_wolfssl_EVP_sm4_ccm_zeroLen(void)
  73145. {
  73146. int res = TEST_SKIPPED;
  73147. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_CCM)
  73148. /* Zero length plain text */
  73149. EXPECT_DECLS;
  73150. byte key[] = {
  73151. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73152. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73153. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73154. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  73155. }; /* align */
  73156. byte iv[] = {
  73157. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  73158. }; /* align */
  73159. byte plaintxt[1];
  73160. int ivSz = 12;
  73161. int plaintxtSz = 0;
  73162. unsigned char tag[16];
  73163. byte ciphertxt[SM4_BLOCK_SIZE * 4] = {0};
  73164. byte decryptedtxt[SM4_BLOCK_SIZE * 4] = {0};
  73165. int ciphertxtSz = 0;
  73166. int decryptedtxtSz = 0;
  73167. int len = 0;
  73168. EVP_CIPHER_CTX *en = EVP_CIPHER_CTX_new();
  73169. EVP_CIPHER_CTX *de = EVP_CIPHER_CTX_new();
  73170. ExpectIntEQ(1, EVP_EncryptInit_ex(en, EVP_sm4_ccm(), NULL, key, iv));
  73171. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_CCM_SET_IVLEN, ivSz, NULL));
  73172. ExpectIntEQ(1, EVP_EncryptUpdate(en, ciphertxt, &ciphertxtSz , plaintxt,
  73173. plaintxtSz));
  73174. ExpectIntEQ(1, EVP_EncryptFinal_ex(en, ciphertxt, &len));
  73175. ciphertxtSz += len;
  73176. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_CCM_GET_TAG, 16, tag));
  73177. ExpectIntEQ(1, EVP_CIPHER_CTX_cleanup(en));
  73178. ExpectIntEQ(0, ciphertxtSz);
  73179. EVP_CIPHER_CTX_init(de);
  73180. ExpectIntEQ(1, EVP_DecryptInit_ex(de, EVP_sm4_ccm(), NULL, key, iv));
  73181. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_CCM_SET_IVLEN, ivSz, NULL));
  73182. ExpectIntEQ(1, EVP_DecryptUpdate(de, NULL, &len, ciphertxt, len));
  73183. decryptedtxtSz = len;
  73184. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_CCM_SET_TAG, 16, tag));
  73185. ExpectIntEQ(1, EVP_DecryptFinal_ex(de, decryptedtxt, &len));
  73186. decryptedtxtSz += len;
  73187. ExpectIntEQ(0, decryptedtxtSz);
  73188. EVP_CIPHER_CTX_free(en);
  73189. EVP_CIPHER_CTX_free(de);
  73190. res = EXPECT_RESULT();
  73191. #endif /* OPENSSL_EXTRA && WOLFSSL_SM4_CCM */
  73192. return res;
  73193. }
  73194. static int test_wolfssl_EVP_sm4_ccm(void)
  73195. {
  73196. int res = TEST_SKIPPED;
  73197. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_CCM)
  73198. EXPECT_DECLS;
  73199. byte *key = (byte*)"0123456789012345";
  73200. byte *iv = (byte*)"0123456789012";
  73201. int ivSz = (int)XSTRLEN((char*)iv);
  73202. /* Message to be encrypted */
  73203. byte *plaintxt = (byte*)"for things to change you have to change";
  73204. /* Additional non-confidential data */
  73205. byte *aad = (byte*)"Don't spend major time on minor things.";
  73206. unsigned char tag[SM4_BLOCK_SIZE] = {0};
  73207. int plaintxtSz = (int)XSTRLEN((char*)plaintxt);
  73208. int aadSz = (int)XSTRLEN((char*)aad);
  73209. byte ciphertxt[SM4_BLOCK_SIZE * 4] = {0};
  73210. byte decryptedtxt[SM4_BLOCK_SIZE * 4] = {0};
  73211. int ciphertxtSz = 0;
  73212. int decryptedtxtSz = 0;
  73213. int len = 0;
  73214. int i = 0;
  73215. EVP_CIPHER_CTX en[2];
  73216. EVP_CIPHER_CTX de[2];
  73217. for (i = 0; i < 2; i++) {
  73218. EVP_CIPHER_CTX_init(&en[i]);
  73219. if (i == 0) {
  73220. /* Default uses 96-bits IV length */
  73221. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_sm4_ccm(), NULL, key,
  73222. iv));
  73223. }
  73224. else {
  73225. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_sm4_ccm(), NULL, NULL,
  73226. NULL));
  73227. /* non-default must to set the IV length first */
  73228. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_CCM_SET_IVLEN,
  73229. ivSz, NULL));
  73230. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  73231. }
  73232. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], NULL, &len, aad, aadSz));
  73233. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], ciphertxt, &len, plaintxt,
  73234. plaintxtSz));
  73235. ciphertxtSz = len;
  73236. ExpectIntEQ(1, EVP_EncryptFinal_ex(&en[i], ciphertxt, &len));
  73237. ciphertxtSz += len;
  73238. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_CCM_GET_TAG,
  73239. SM4_BLOCK_SIZE, tag));
  73240. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&en[i]), 1);
  73241. EVP_CIPHER_CTX_init(&de[i]);
  73242. if (i == 0) {
  73243. /* Default uses 96-bits IV length */
  73244. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_sm4_ccm(), NULL, key,
  73245. iv));
  73246. }
  73247. else {
  73248. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_sm4_ccm(), NULL, NULL,
  73249. NULL));
  73250. /* non-default must to set the IV length first */
  73251. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_IVLEN,
  73252. ivSz, NULL));
  73253. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  73254. }
  73255. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  73256. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  73257. ciphertxtSz));
  73258. decryptedtxtSz = len;
  73259. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_TAG,
  73260. SM4_BLOCK_SIZE, tag));
  73261. ExpectIntEQ(1, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  73262. decryptedtxtSz += len;
  73263. ExpectIntEQ(ciphertxtSz, decryptedtxtSz);
  73264. ExpectIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
  73265. /* modify tag*/
  73266. tag[SM4_BLOCK_SIZE-1]+=0xBB;
  73267. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  73268. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_TAG,
  73269. SM4_BLOCK_SIZE, tag));
  73270. /* fail due to wrong tag */
  73271. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  73272. ciphertxtSz));
  73273. ExpectIntEQ(0, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  73274. ExpectIntEQ(0, len);
  73275. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&de[i]), 1);
  73276. }
  73277. res = EXPECT_RESULT();
  73278. #endif /* OPENSSL_EXTRA && WOLFSSL_SM4_CCM */
  73279. return res;
  73280. }
  73281. static int test_wolfSSL_EVP_PKEY_hkdf(void)
  73282. {
  73283. EXPECT_DECLS;
  73284. #if defined(OPENSSL_EXTRA) && defined(HAVE_HKDF)
  73285. EVP_PKEY_CTX* ctx = NULL;
  73286. byte salt[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  73287. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
  73288. byte key[] = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  73289. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
  73290. byte info[] = {0X01, 0x02, 0x03, 0x04, 0x05};
  73291. byte info2[] = {0X06, 0x07, 0x08, 0x09, 0x0A};
  73292. byte outKey[34];
  73293. size_t outKeySz = sizeof(outKey);
  73294. /* These expected outputs were gathered by running the same test below using
  73295. * OpenSSL. */
  73296. const byte extractAndExpand[] = {
  73297. 0x8B, 0xEB, 0x90, 0xA9, 0x04, 0xFF, 0x05, 0x10, 0xE4, 0xB5, 0xB1, 0x10,
  73298. 0x31, 0x34, 0xFF, 0x07, 0x5B, 0xE3, 0xC6, 0x93, 0xD4, 0xF8, 0xC7, 0xEE,
  73299. 0x96, 0xDA, 0x78, 0x7A, 0xE2, 0x9A, 0x2D, 0x05, 0x4B, 0xF6
  73300. };
  73301. const byte extractOnly[] = {
  73302. 0xE7, 0x6B, 0x9E, 0x0F, 0xE4, 0x02, 0x1D, 0x62, 0xEA, 0x97, 0x74, 0x5E,
  73303. 0xF4, 0x3C, 0x65, 0x4D, 0xC1, 0x46, 0x98, 0xAA, 0x79, 0x9A, 0xCB, 0x9C,
  73304. 0xCC, 0x3E, 0x7F, 0x2A, 0x2B, 0x41, 0xA1, 0x9E
  73305. };
  73306. const byte expandOnly[] = {
  73307. 0xFF, 0x29, 0x29, 0x56, 0x9E, 0xA7, 0x66, 0x02, 0xDB, 0x4F, 0xDB, 0x53,
  73308. 0x7D, 0x21, 0x67, 0x52, 0xC3, 0x0E, 0xF3, 0xFC, 0x71, 0xCE, 0x67, 0x2B,
  73309. 0xEA, 0x3B, 0xE9, 0xFC, 0xDD, 0xC8, 0xCC, 0xB7, 0x42, 0x74
  73310. };
  73311. const byte extractAndExpandAddInfo[] = {
  73312. 0x5A, 0x74, 0x79, 0x83, 0xA3, 0xA4, 0x2E, 0xB7, 0xD4, 0x08, 0xC2, 0x6A,
  73313. 0x2F, 0xA5, 0xE3, 0x4E, 0xF1, 0xF4, 0x87, 0x3E, 0xA6, 0xC7, 0x88, 0x45,
  73314. 0xD7, 0xE2, 0x15, 0xBC, 0xB8, 0x10, 0xEF, 0x6C, 0x4D, 0x7A
  73315. };
  73316. ExpectNotNull((ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL)));
  73317. ExpectIntEQ(EVP_PKEY_derive_init(ctx), WOLFSSL_SUCCESS);
  73318. /* NULL ctx. */
  73319. ExpectIntEQ(EVP_PKEY_CTX_set_hkdf_md(NULL, EVP_sha256()), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73320. /* NULL md. */
  73321. ExpectIntEQ(EVP_PKEY_CTX_set_hkdf_md(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73322. ExpectIntEQ(EVP_PKEY_CTX_set_hkdf_md(ctx, EVP_sha256()), WOLFSSL_SUCCESS);
  73323. /* NULL ctx. */
  73324. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_salt(NULL, salt, sizeof(salt)),
  73325. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73326. /* NULL salt is ok. */
  73327. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_salt(ctx, NULL, sizeof(salt)),
  73328. WOLFSSL_SUCCESS);
  73329. /* Salt length <= 0. */
  73330. /* Length 0 salt is ok. */
  73331. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_salt(ctx, salt, 0), WOLFSSL_SUCCESS);
  73332. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_salt(ctx, salt, -1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73333. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_salt(ctx, salt, sizeof(salt)),
  73334. WOLFSSL_SUCCESS);
  73335. /* NULL ctx. */
  73336. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_key(NULL, key, sizeof(key)),
  73337. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73338. /* NULL key. */
  73339. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_key(ctx, NULL, sizeof(key)),
  73340. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73341. /* Key length <= 0 */
  73342. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_key(ctx, key, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73343. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_key(ctx, key, -1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73344. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_key(ctx, key, sizeof(key)),
  73345. WOLFSSL_SUCCESS);
  73346. /* NULL ctx. */
  73347. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(NULL, info, sizeof(info)),
  73348. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73349. /* NULL info is ok. */
  73350. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(ctx, NULL, sizeof(info)),
  73351. WOLFSSL_SUCCESS);
  73352. /* Info length <= 0 */
  73353. /* Length 0 info is ok. */
  73354. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(ctx, info, 0), WOLFSSL_SUCCESS);
  73355. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(ctx, info, -1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73356. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(ctx, info, sizeof(info)),
  73357. WOLFSSL_SUCCESS);
  73358. /* NULL ctx. */
  73359. ExpectIntEQ(EVP_PKEY_CTX_hkdf_mode(NULL, EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY),
  73360. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73361. /* Extract and expand (default). */
  73362. ExpectIntEQ(EVP_PKEY_derive(ctx, outKey, &outKeySz), WOLFSSL_SUCCESS);
  73363. ExpectIntEQ(outKeySz, sizeof(extractAndExpand));
  73364. ExpectIntEQ(XMEMCMP(outKey, extractAndExpand, outKeySz), 0);
  73365. /* Extract only. */
  73366. ExpectIntEQ(EVP_PKEY_CTX_hkdf_mode(ctx, EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY),
  73367. WOLFSSL_SUCCESS);
  73368. ExpectIntEQ(EVP_PKEY_derive(ctx, outKey, &outKeySz), WOLFSSL_SUCCESS);
  73369. ExpectIntEQ(outKeySz, sizeof(extractOnly));
  73370. ExpectIntEQ(XMEMCMP(outKey, extractOnly, outKeySz), 0);
  73371. outKeySz = sizeof(outKey);
  73372. /* Expand only. */
  73373. ExpectIntEQ(EVP_PKEY_CTX_hkdf_mode(ctx, EVP_PKEY_HKDEF_MODE_EXPAND_ONLY),
  73374. WOLFSSL_SUCCESS);
  73375. ExpectIntEQ(EVP_PKEY_derive(ctx, outKey, &outKeySz), WOLFSSL_SUCCESS);
  73376. ExpectIntEQ(outKeySz, sizeof(expandOnly));
  73377. ExpectIntEQ(XMEMCMP(outKey, expandOnly, outKeySz), 0);
  73378. outKeySz = sizeof(outKey);
  73379. /* Extract and expand with appended additional info. */
  73380. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(ctx, info2, sizeof(info2)),
  73381. WOLFSSL_SUCCESS);
  73382. ExpectIntEQ(EVP_PKEY_CTX_hkdf_mode(ctx,
  73383. EVP_PKEY_HKDEF_MODE_EXTRACT_AND_EXPAND), WOLFSSL_SUCCESS);
  73384. ExpectIntEQ(EVP_PKEY_derive(ctx, outKey, &outKeySz), WOLFSSL_SUCCESS);
  73385. ExpectIntEQ(outKeySz, sizeof(extractAndExpandAddInfo));
  73386. ExpectIntEQ(XMEMCMP(outKey, extractAndExpandAddInfo, outKeySz), 0);
  73387. EVP_PKEY_CTX_free(ctx);
  73388. #endif /* OPENSSL_EXTRA && HAVE_HKDF */
  73389. return EXPECT_RESULT();
  73390. }
  73391. #ifndef NO_BIO
  73392. static int test_wolfSSL_PEM_X509_INFO_read_bio(void)
  73393. {
  73394. EXPECT_DECLS;
  73395. #if defined(OPENSSL_ALL) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  73396. BIO* bio = NULL;
  73397. X509_INFO* info = NULL;
  73398. STACK_OF(X509_INFO)* sk = NULL;
  73399. char* subject = NULL;
  73400. char exp1[] = "/C=US/ST=Montana/L=Bozeman/O=Sawtooth/OU=Consulting/"
  73401. "CN=www.wolfssl.com/emailAddress=info@wolfssl.com";
  73402. char exp2[] = "/C=US/ST=Montana/L=Bozeman/O=wolfSSL/OU=Support/"
  73403. "CN=www.wolfssl.com/emailAddress=info@wolfssl.com";
  73404. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  73405. ExpectIntGT(BIO_read_filename(bio, svrCertFile), 0);
  73406. ExpectNotNull(sk = PEM_X509_INFO_read_bio(bio, NULL, NULL, NULL));
  73407. ExpectIntEQ(sk_X509_INFO_num(sk), 2);
  73408. /* using dereference to maintain testing for Apache port*/
  73409. ExpectNotNull(info = sk_X509_INFO_pop(sk));
  73410. ExpectNotNull(subject = X509_NAME_oneline(X509_get_subject_name(info->x509),
  73411. 0, 0));
  73412. ExpectIntEQ(0, XSTRNCMP(subject, exp1, sizeof(exp1)));
  73413. XFREE(subject, 0, DYNAMIC_TYPE_OPENSSL);
  73414. X509_INFO_free(info);
  73415. info = NULL;
  73416. ExpectNotNull(info = sk_X509_INFO_pop(sk));
  73417. ExpectNotNull(subject = X509_NAME_oneline(X509_get_subject_name(info->x509),
  73418. 0, 0));
  73419. ExpectIntEQ(0, XSTRNCMP(subject, exp2, sizeof(exp2)));
  73420. XFREE(subject, 0, DYNAMIC_TYPE_OPENSSL);
  73421. X509_INFO_free(info);
  73422. ExpectNull(info = sk_X509_INFO_pop(sk));
  73423. sk_X509_INFO_pop_free(sk, X509_INFO_free);
  73424. BIO_free(bio);
  73425. #endif
  73426. return EXPECT_RESULT();
  73427. }
  73428. #endif /* !NO_BIO */
  73429. static int test_wolfSSL_X509_NAME_ENTRY_get_object(void)
  73430. {
  73431. EXPECT_DECLS;
  73432. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  73433. X509 *x509 = NULL;
  73434. X509_NAME* name = NULL;
  73435. int idx = 0;
  73436. X509_NAME_ENTRY *ne = NULL;
  73437. ASN1_OBJECT *object = NULL;
  73438. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  73439. WOLFSSL_FILETYPE_PEM));
  73440. ExpectNotNull(name = X509_get_subject_name(x509));
  73441. ExpectIntGE(idx = X509_NAME_get_index_by_NID(name, NID_commonName, -1), 0);
  73442. ExpectNotNull(ne = X509_NAME_get_entry(name, idx));
  73443. ExpectNotNull(object = X509_NAME_ENTRY_get_object(ne));
  73444. X509_free(x509);
  73445. #endif
  73446. return EXPECT_RESULT();
  73447. }
  73448. static int test_wolfSSL_X509_STORE_get1_certs(void)
  73449. {
  73450. EXPECT_DECLS;
  73451. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SIGNER_DER_CERT) && \
  73452. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  73453. X509_STORE_CTX *storeCtx = NULL;
  73454. X509_STORE *store = NULL;
  73455. X509 *caX509 = NULL;
  73456. X509 *svrX509 = NULL;
  73457. X509_NAME *subject = NULL;
  73458. WOLF_STACK_OF(WOLFSSL_X509) *certs = NULL;
  73459. ExpectNotNull(caX509 = X509_load_certificate_file(caCertFile,
  73460. SSL_FILETYPE_PEM));
  73461. ExpectNotNull((svrX509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  73462. SSL_FILETYPE_PEM)));
  73463. ExpectNotNull(storeCtx = X509_STORE_CTX_new());
  73464. ExpectNotNull(store = X509_STORE_new());
  73465. ExpectNotNull(subject = X509_get_subject_name(caX509));
  73466. /* Errors */
  73467. ExpectNull(X509_STORE_get1_certs(storeCtx, subject));
  73468. ExpectNull(X509_STORE_get1_certs(NULL, subject));
  73469. ExpectNull(X509_STORE_get1_certs(storeCtx, NULL));
  73470. ExpectIntEQ(X509_STORE_add_cert(store, caX509), SSL_SUCCESS);
  73471. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, caX509, NULL),
  73472. SSL_SUCCESS);
  73473. /* Should find the cert */
  73474. ExpectNotNull(certs = X509_STORE_get1_certs(storeCtx, subject));
  73475. ExpectIntEQ(1, wolfSSL_sk_X509_num(certs));
  73476. sk_X509_pop_free(certs, NULL);
  73477. certs = NULL;
  73478. /* Should not find the cert */
  73479. ExpectNotNull(subject = X509_get_subject_name(svrX509));
  73480. ExpectNotNull(certs = X509_STORE_get1_certs(storeCtx, subject));
  73481. ExpectIntEQ(0, wolfSSL_sk_X509_num(certs));
  73482. sk_X509_pop_free(certs, NULL);
  73483. certs = NULL;
  73484. X509_STORE_free(store);
  73485. X509_STORE_CTX_free(storeCtx);
  73486. X509_free(svrX509);
  73487. X509_free(caX509);
  73488. #endif /* OPENSSL_EXTRA && WOLFSSL_SIGNER_DER_CERT && !NO_FILESYSTEM */
  73489. return EXPECT_RESULT();
  73490. }
  73491. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  73492. defined(WOLFSSL_LOCAL_X509_STORE) && \
  73493. (defined(OPENSSL_ALL) || defined(WOLFSSL_QT)) && defined(HAVE_CRL)
  73494. static int test_wolfSSL_X509_STORE_set_get_crl_provider(X509_STORE_CTX* ctx,
  73495. X509_CRL** crl_out, X509* cert) {
  73496. X509_CRL *crl = NULL;
  73497. XFILE fp = XBADFILE;
  73498. char* cert_issuer = X509_NAME_oneline(X509_get_issuer_name(cert), NULL, 0);
  73499. int ret = 0;
  73500. (void)ctx;
  73501. if (cert_issuer == NULL)
  73502. return 0;
  73503. if ((fp = XFOPEN("certs/crl/crl.pem", "rb")) != XBADFILE) {
  73504. PEM_read_X509_CRL(fp, &crl, NULL, NULL);
  73505. XFCLOSE(fp);
  73506. if (crl != NULL) {
  73507. char* crl_issuer = X509_NAME_oneline(
  73508. X509_CRL_get_issuer(crl), NULL, 0);
  73509. if ((crl_issuer != NULL) &&
  73510. (XSTRCMP(cert_issuer, crl_issuer) == 0)) {
  73511. *crl_out = X509_CRL_dup(crl);
  73512. if (*crl_out != NULL)
  73513. ret = 1;
  73514. }
  73515. OPENSSL_free(crl_issuer);
  73516. }
  73517. }
  73518. X509_CRL_free(crl);
  73519. OPENSSL_free(cert_issuer);
  73520. return ret;
  73521. }
  73522. static int test_wolfSSL_X509_STORE_set_get_crl_provider2(X509_STORE_CTX* ctx,
  73523. X509_CRL** crl_out, X509* cert) {
  73524. (void)ctx;
  73525. (void)cert;
  73526. *crl_out = NULL;
  73527. return 1;
  73528. }
  73529. #ifndef NO_WOLFSSL_STUB
  73530. static int test_wolfSSL_X509_STORE_set_get_crl_check(X509_STORE_CTX* ctx,
  73531. X509_CRL* crl) {
  73532. (void)ctx;
  73533. (void)crl;
  73534. return 1;
  73535. }
  73536. #endif
  73537. static int test_wolfSSL_X509_STORE_set_get_crl_verify(int ok,
  73538. X509_STORE_CTX* ctx) {
  73539. int cert_error = X509_STORE_CTX_get_error(ctx);
  73540. X509_VERIFY_PARAM* param = X509_STORE_CTX_get0_param(ctx);
  73541. int flags = X509_VERIFY_PARAM_get_flags(param);
  73542. if ((flags & (X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL)) !=
  73543. (X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL)) {
  73544. /* Make sure the flags are set */
  73545. return 0;
  73546. }
  73547. /* Ignore CRL missing error */
  73548. #ifndef OPENSSL_COMPATIBLE_DEFAULTS
  73549. if (cert_error == WC_NO_ERR_TRACE(CRL_MISSING))
  73550. #else
  73551. if (cert_error == X509_V_ERR_UNABLE_TO_GET_CRL)
  73552. #endif
  73553. return 1;
  73554. return ok;
  73555. }
  73556. static int test_wolfSSL_X509_STORE_set_get_crl_ctx_ready(WOLFSSL_CTX* ctx)
  73557. {
  73558. EXPECT_DECLS;
  73559. X509_STORE* cert_store = NULL;
  73560. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL),
  73561. WOLFSSL_SUCCESS);
  73562. ExpectNotNull(cert_store = SSL_CTX_get_cert_store(ctx));
  73563. X509_STORE_set_get_crl(cert_store,
  73564. test_wolfSSL_X509_STORE_set_get_crl_provider);
  73565. #ifndef NO_WOLFSSL_STUB
  73566. X509_STORE_set_check_crl(cert_store,
  73567. test_wolfSSL_X509_STORE_set_get_crl_check);
  73568. #endif
  73569. return EXPECT_RESULT();
  73570. }
  73571. static int test_wolfSSL_X509_STORE_set_get_crl_ctx_ready2(WOLFSSL_CTX* ctx)
  73572. {
  73573. EXPECT_DECLS;
  73574. X509_STORE* cert_store = NULL;
  73575. X509_VERIFY_PARAM* param = NULL;
  73576. SSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  73577. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL),
  73578. WOLFSSL_SUCCESS);
  73579. ExpectNotNull(cert_store = SSL_CTX_get_cert_store(ctx));
  73580. X509_STORE_set_get_crl(cert_store,
  73581. test_wolfSSL_X509_STORE_set_get_crl_provider2);
  73582. #ifndef NO_WOLFSSL_STUB
  73583. X509_STORE_set_check_crl(cert_store,
  73584. test_wolfSSL_X509_STORE_set_get_crl_check);
  73585. #endif
  73586. X509_STORE_set_verify_cb(cert_store,
  73587. test_wolfSSL_X509_STORE_set_get_crl_verify);
  73588. ExpectNotNull(X509_STORE_get0_param(cert_store));
  73589. ExpectNotNull(param = X509_VERIFY_PARAM_new());
  73590. ExpectIntEQ(X509_VERIFY_PARAM_inherit(param,
  73591. X509_STORE_get0_param(cert_store)), 1);
  73592. ExpectIntEQ(X509_VERIFY_PARAM_set_flags(
  73593. param, X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL), 1);
  73594. ExpectIntEQ(X509_STORE_set1_param(cert_store, param), 1);
  73595. ExpectIntEQ(X509_STORE_set_flags(cert_store,
  73596. X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL), 1);
  73597. X509_VERIFY_PARAM_free(param);
  73598. return EXPECT_RESULT();
  73599. }
  73600. #endif
  73601. /* This test mimics the usage of the CRL provider in gRPC */
  73602. static int test_wolfSSL_X509_STORE_set_get_crl(void)
  73603. {
  73604. EXPECT_DECLS;
  73605. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  73606. defined(WOLFSSL_LOCAL_X509_STORE) && \
  73607. (defined(OPENSSL_ALL) || defined(WOLFSSL_QT)) && defined(HAVE_CRL)
  73608. test_ssl_cbf func_cb_client;
  73609. test_ssl_cbf func_cb_server;
  73610. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  73611. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  73612. func_cb_client.ctx_ready = test_wolfSSL_X509_STORE_set_get_crl_ctx_ready;
  73613. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  73614. &func_cb_server, NULL), TEST_SUCCESS);
  73615. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  73616. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  73617. func_cb_client.ctx_ready = test_wolfSSL_X509_STORE_set_get_crl_ctx_ready2;
  73618. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  73619. &func_cb_server, NULL), TEST_SUCCESS);
  73620. #endif
  73621. return EXPECT_RESULT();
  73622. }
  73623. static int test_wolfSSL_dup_CA_list(void)
  73624. {
  73625. int res = TEST_SKIPPED;
  73626. #if defined(OPENSSL_ALL)
  73627. EXPECT_DECLS;
  73628. STACK_OF(X509_NAME) *originalStack = NULL;
  73629. STACK_OF(X509_NAME) *copyStack = NULL;
  73630. int originalCount = 0;
  73631. int copyCount = 0;
  73632. X509_NAME *name = NULL;
  73633. int i;
  73634. originalStack = sk_X509_NAME_new_null();
  73635. ExpectNotNull(originalStack);
  73636. for (i = 0; i < 3; i++) {
  73637. name = X509_NAME_new();
  73638. ExpectNotNull(name);
  73639. ExpectIntEQ(sk_X509_NAME_push(originalStack, name), i+1);
  73640. if (EXPECT_FAIL()) {
  73641. X509_NAME_free(name);
  73642. }
  73643. }
  73644. copyStack = SSL_dup_CA_list(originalStack);
  73645. ExpectNotNull(copyStack);
  73646. originalCount = sk_X509_NAME_num(originalStack);
  73647. copyCount = sk_X509_NAME_num(copyStack);
  73648. ExpectIntEQ(originalCount, copyCount);
  73649. sk_X509_NAME_pop_free(originalStack, X509_NAME_free);
  73650. sk_X509_NAME_pop_free(copyStack, X509_NAME_free);
  73651. originalStack = NULL;
  73652. copyStack = NULL;
  73653. res = EXPECT_RESULT();
  73654. #endif /* OPENSSL_ALL */
  73655. return res;
  73656. }
  73657. static int test_ForceZero(void)
  73658. {
  73659. EXPECT_DECLS;
  73660. unsigned char data[32];
  73661. unsigned int i, j, len;
  73662. /* Test case with 0 length */
  73663. ForceZero(data, 0);
  73664. /* Test ForceZero */
  73665. for (i = 0; i < sizeof(data); i++) {
  73666. for (len = 1; len < sizeof(data) - i; len++) {
  73667. for (j = 0; j < sizeof(data); j++)
  73668. data[j] = j + 1;
  73669. ForceZero(data + i, len);
  73670. for (j = 0; j < sizeof(data); j++) {
  73671. if (j < i || j >= i + len) {
  73672. ExpectIntNE(data[j], 0x00);
  73673. }
  73674. else {
  73675. ExpectIntEQ(data[j], 0x00);
  73676. }
  73677. }
  73678. }
  73679. }
  73680. return EXPECT_RESULT();
  73681. }
  73682. #ifndef NO_BIO
  73683. static int test_wolfSSL_X509_print(void)
  73684. {
  73685. EXPECT_DECLS;
  73686. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && \
  73687. !defined(NO_RSA) && defined(XSNPRINTF)
  73688. X509 *x509 = NULL;
  73689. BIO *bio = NULL;
  73690. #if defined(OPENSSL_ALL) && !defined(NO_WOLFSSL_DIR)
  73691. const X509_ALGOR *cert_sig_alg = NULL;
  73692. #endif
  73693. ExpectNotNull(x509 = X509_load_certificate_file(svrCertFile,
  73694. WOLFSSL_FILETYPE_PEM));
  73695. /* print to memory */
  73696. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  73697. ExpectIntEQ(X509_print(bio, x509), SSL_SUCCESS);
  73698. #if defined(OPENSSL_ALL) || defined(WOLFSSL_IP_ALT_NAME)
  73699. #if defined(WC_DISABLE_RADIX_ZERO_PAD)
  73700. /* Will print IP address subject alt name. */
  73701. ExpectIntEQ(BIO_get_mem_data(bio, NULL), 3349);
  73702. #elif defined(NO_ASN_TIME)
  73703. /* Will print IP address subject alt name but not Validity. */
  73704. ExpectIntEQ(BIO_get_mem_data(bio, NULL), 3235);
  73705. #else
  73706. /* Will print IP address subject alt name. */
  73707. ExpectIntEQ(BIO_get_mem_data(bio, NULL), 3350);
  73708. #endif
  73709. #elif defined(NO_ASN_TIME)
  73710. /* With NO_ASN_TIME defined, X509_print skips printing Validity. */
  73711. ExpectIntEQ(BIO_get_mem_data(bio, NULL), 3213);
  73712. #else
  73713. ExpectIntEQ(BIO_get_mem_data(bio, NULL), 3328);
  73714. #endif
  73715. BIO_free(bio);
  73716. bio = NULL;
  73717. ExpectNotNull(bio = BIO_new_fd(STDERR_FILENO, BIO_NOCLOSE));
  73718. #if defined(OPENSSL_ALL) && !defined(NO_WOLFSSL_DIR)
  73719. /* Print signature */
  73720. ExpectNotNull(cert_sig_alg = X509_get0_tbs_sigalg(x509));
  73721. ExpectIntEQ(X509_signature_print(bio, cert_sig_alg, NULL), SSL_SUCCESS);
  73722. #endif
  73723. /* print to stderr */
  73724. #if !defined(NO_WOLFSSL_DIR)
  73725. ExpectIntEQ(X509_print(bio, x509), SSL_SUCCESS);
  73726. #endif
  73727. /* print again */
  73728. ExpectIntEQ(X509_print_fp(stderr, x509), SSL_SUCCESS);
  73729. X509_free(x509);
  73730. BIO_free(bio);
  73731. #endif
  73732. return EXPECT_RESULT();
  73733. }
  73734. static int test_wolfSSL_X509_CRL_print(void)
  73735. {
  73736. EXPECT_DECLS;
  73737. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && defined(HAVE_CRL)\
  73738. && !defined(NO_FILESYSTEM) && defined(XSNPRINTF)
  73739. X509_CRL* crl = NULL;
  73740. BIO *bio = NULL;
  73741. XFILE fp = XBADFILE;
  73742. ExpectTrue((fp = XFOPEN("./certs/crl/crl.pem", "rb")) != XBADFILE);
  73743. ExpectNotNull(crl = (X509_CRL*)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  73744. NULL, NULL));
  73745. if (fp != XBADFILE)
  73746. XFCLOSE(fp);
  73747. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  73748. ExpectIntEQ(X509_CRL_print(bio, crl), SSL_SUCCESS);
  73749. X509_CRL_free(crl);
  73750. BIO_free(bio);
  73751. #endif
  73752. return EXPECT_RESULT();
  73753. }
  73754. static int test_wolfSSL_BIO_get_len(void)
  73755. {
  73756. EXPECT_DECLS;
  73757. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  73758. BIO *bio = NULL;
  73759. const char txt[] = "Some example text to push to the BIO.";
  73760. ExpectIntEQ(wolfSSL_BIO_get_len(bio), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  73761. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  73762. ExpectIntEQ(wolfSSL_BIO_write(bio, txt, sizeof(txt)), sizeof(txt));
  73763. ExpectIntEQ(wolfSSL_BIO_get_len(bio), sizeof(txt));
  73764. BIO_free(bio);
  73765. bio = NULL;
  73766. ExpectNotNull(bio = BIO_new_fd(STDERR_FILENO, BIO_NOCLOSE));
  73767. ExpectIntEQ(wolfSSL_BIO_get_len(bio), WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE));
  73768. BIO_free(bio);
  73769. #endif
  73770. return EXPECT_RESULT();
  73771. }
  73772. #endif /* !NO_BIO */
  73773. static int test_wolfSSL_RSA(void)
  73774. {
  73775. EXPECT_DECLS;
  73776. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  73777. RSA* rsa = NULL;
  73778. const BIGNUM *n = NULL;
  73779. const BIGNUM *e = NULL;
  73780. const BIGNUM *d = NULL;
  73781. const BIGNUM *p = NULL;
  73782. const BIGNUM *q = NULL;
  73783. const BIGNUM *dmp1 = NULL;
  73784. const BIGNUM *dmq1 = NULL;
  73785. const BIGNUM *iqmp = NULL;
  73786. ExpectNotNull(rsa = RSA_new());
  73787. ExpectIntEQ(RSA_size(NULL), 0);
  73788. ExpectIntEQ(RSA_size(rsa), 0);
  73789. ExpectIntEQ(RSA_set0_key(rsa, NULL, NULL, NULL), 0);
  73790. ExpectIntEQ(RSA_set0_crt_params(rsa, NULL, NULL, NULL), 0);
  73791. ExpectIntEQ(RSA_set0_factors(rsa, NULL, NULL), 0);
  73792. #ifdef WOLFSSL_RSA_KEY_CHECK
  73793. ExpectIntEQ(RSA_check_key(rsa), 0);
  73794. #endif
  73795. RSA_free(rsa);
  73796. rsa = NULL;
  73797. ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  73798. ExpectIntEQ(RSA_size(rsa), 256);
  73799. #if (!defined(HAVE_FIPS) || FIPS_VERSION3_GT(6,0,0)) && !defined(HAVE_SELFTEST)
  73800. {
  73801. /* Test setting only subset of parameters */
  73802. RSA *rsa2 = NULL;
  73803. unsigned char hash[SHA256_DIGEST_LENGTH];
  73804. unsigned char signature[2048/8];
  73805. unsigned int signatureLen = 0;
  73806. XMEMSET(hash, 0, sizeof(hash));
  73807. RSA_get0_key(rsa, &n, &e, &d);
  73808. RSA_get0_factors(rsa, &p, &q);
  73809. RSA_get0_crt_params(rsa, &dmp1, &dmq1, &iqmp);
  73810. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  73811. &signatureLen, rsa), 1);
  73812. /* Quick sanity check */
  73813. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  73814. signatureLen, rsa), 1);
  73815. /* Verifying */
  73816. ExpectNotNull(rsa2 = RSA_new());
  73817. ExpectIntEQ(RSA_set0_key(rsa2, BN_dup(n), BN_dup(e), NULL), 1);
  73818. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  73819. signatureLen, rsa2), 1);
  73820. ExpectIntEQ(RSA_set0_factors(rsa2, BN_dup(p), BN_dup(q)), 1);
  73821. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  73822. signatureLen, rsa2), 1);
  73823. ExpectIntEQ(RSA_set0_crt_params(rsa2, BN_dup(dmp1), BN_dup(dmq1),
  73824. BN_dup(iqmp)), 1);
  73825. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  73826. signatureLen, rsa2), 1);
  73827. RSA_free(rsa2);
  73828. rsa2 = NULL;
  73829. /* Signing */
  73830. XMEMSET(signature, 0, sizeof(signature));
  73831. ExpectNotNull(rsa2 = RSA_new());
  73832. ExpectIntEQ(RSA_set0_key(rsa2, BN_dup(n), BN_dup(e), BN_dup(d)), 1);
  73833. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  73834. &signatureLen, rsa2), 1);
  73835. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  73836. signatureLen, rsa), 1);
  73837. ExpectIntEQ(RSA_set0_factors(rsa2, BN_dup(p), BN_dup(q)), 1);
  73838. XMEMSET(signature, 0, sizeof(signature));
  73839. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  73840. &signatureLen, rsa2), 1);
  73841. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  73842. signatureLen, rsa), 1);
  73843. ExpectIntEQ(RSA_set0_crt_params(rsa2, BN_dup(dmp1), BN_dup(dmq1),
  73844. BN_dup(iqmp)), 1);
  73845. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  73846. &signatureLen, rsa2), 1);
  73847. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  73848. signatureLen, rsa), 1);
  73849. RSA_free(rsa2);
  73850. rsa2 = NULL;
  73851. }
  73852. #endif
  73853. #ifdef WOLFSSL_RSA_KEY_CHECK
  73854. ExpectIntEQ(RSA_check_key(NULL), 0);
  73855. ExpectIntEQ(RSA_check_key(rsa), 1);
  73856. #endif
  73857. /* sanity check */
  73858. ExpectIntEQ(RSA_bits(NULL), 0);
  73859. /* key */
  73860. ExpectIntEQ(RSA_bits(rsa), 2048);
  73861. RSA_get0_key(rsa, &n, &e, &d);
  73862. ExpectPtrEq(rsa->n, n);
  73863. ExpectPtrEq(rsa->e, e);
  73864. ExpectPtrEq(rsa->d, d);
  73865. n = NULL;
  73866. e = NULL;
  73867. d = NULL;
  73868. ExpectNotNull(n = BN_new());
  73869. ExpectNotNull(e = BN_new());
  73870. ExpectNotNull(d = BN_new());
  73871. ExpectIntEQ(RSA_set0_key(rsa, (BIGNUM*)n, (BIGNUM*)e, (BIGNUM*)d), 1);
  73872. if (EXPECT_FAIL()) {
  73873. BN_free((BIGNUM*)n);
  73874. BN_free((BIGNUM*)e);
  73875. BN_free((BIGNUM*)d);
  73876. }
  73877. ExpectPtrEq(rsa->n, n);
  73878. ExpectPtrEq(rsa->e, e);
  73879. ExpectPtrEq(rsa->d, d);
  73880. ExpectIntEQ(RSA_set0_key(rsa, NULL, NULL, NULL), 1);
  73881. ExpectIntEQ(RSA_set0_key(NULL, (BIGNUM*)n, (BIGNUM*)e, (BIGNUM*)d), 0);
  73882. /* crt_params */
  73883. RSA_get0_crt_params(rsa, &dmp1, &dmq1, &iqmp);
  73884. ExpectPtrEq(rsa->dmp1, dmp1);
  73885. ExpectPtrEq(rsa->dmq1, dmq1);
  73886. ExpectPtrEq(rsa->iqmp, iqmp);
  73887. dmp1 = NULL;
  73888. dmq1 = NULL;
  73889. iqmp = NULL;
  73890. ExpectNotNull(dmp1 = BN_new());
  73891. ExpectNotNull(dmq1 = BN_new());
  73892. ExpectNotNull(iqmp = BN_new());
  73893. ExpectIntEQ(RSA_set0_crt_params(rsa, (BIGNUM*)dmp1, (BIGNUM*)dmq1,
  73894. (BIGNUM*)iqmp), 1);
  73895. if (EXPECT_FAIL()) {
  73896. BN_free((BIGNUM*)dmp1);
  73897. BN_free((BIGNUM*)dmq1);
  73898. BN_free((BIGNUM*)iqmp);
  73899. }
  73900. ExpectPtrEq(rsa->dmp1, dmp1);
  73901. ExpectPtrEq(rsa->dmq1, dmq1);
  73902. ExpectPtrEq(rsa->iqmp, iqmp);
  73903. ExpectIntEQ(RSA_set0_crt_params(rsa, NULL, NULL, NULL), 1);
  73904. ExpectIntEQ(RSA_set0_crt_params(NULL, (BIGNUM*)dmp1, (BIGNUM*)dmq1,
  73905. (BIGNUM*)iqmp), 0);
  73906. RSA_get0_crt_params(NULL, NULL, NULL, NULL);
  73907. RSA_get0_crt_params(rsa, NULL, NULL, NULL);
  73908. RSA_get0_crt_params(NULL, &dmp1, &dmq1, &iqmp);
  73909. ExpectNull(dmp1);
  73910. ExpectNull(dmq1);
  73911. ExpectNull(iqmp);
  73912. /* factors */
  73913. RSA_get0_factors(rsa, NULL, NULL);
  73914. RSA_get0_factors(rsa, &p, &q);
  73915. ExpectPtrEq(rsa->p, p);
  73916. ExpectPtrEq(rsa->q, q);
  73917. p = NULL;
  73918. q = NULL;
  73919. ExpectNotNull(p = BN_new());
  73920. ExpectNotNull(q = BN_new());
  73921. ExpectIntEQ(RSA_set0_factors(rsa, (BIGNUM*)p, (BIGNUM*)q), 1);
  73922. if (EXPECT_FAIL()) {
  73923. BN_free((BIGNUM*)p);
  73924. BN_free((BIGNUM*)q);
  73925. }
  73926. ExpectPtrEq(rsa->p, p);
  73927. ExpectPtrEq(rsa->q, q);
  73928. ExpectIntEQ(RSA_set0_factors(rsa, NULL, NULL), 1);
  73929. ExpectIntEQ(RSA_set0_factors(NULL, (BIGNUM*)p, (BIGNUM*)q), 0);
  73930. RSA_get0_factors(NULL, NULL, NULL);
  73931. RSA_get0_factors(NULL, &p, &q);
  73932. ExpectNull(p);
  73933. ExpectNull(q);
  73934. ExpectIntEQ(BN_hex2bn(&rsa->n, "1FFFFF"), 1);
  73935. ExpectIntEQ(RSA_bits(rsa), 21);
  73936. RSA_free(rsa);
  73937. rsa = NULL;
  73938. #if !defined(USE_FAST_MATH) || (FP_MAX_BITS >= (3072*2))
  73939. ExpectNotNull(rsa = RSA_generate_key(3072, 17, NULL, NULL));
  73940. ExpectIntEQ(RSA_size(rsa), 384);
  73941. ExpectIntEQ(RSA_bits(rsa), 3072);
  73942. RSA_free(rsa);
  73943. rsa = NULL;
  73944. #endif
  73945. /* remove for now with odd key size until adjusting rsa key size check with
  73946. wc_MakeRsaKey()
  73947. ExpectNotNull(rsa = RSA_generate_key(2999, 65537, NULL, NULL));
  73948. RSA_free(rsa);
  73949. rsa = NULL;
  73950. */
  73951. ExpectNull(RSA_generate_key(-1, 3, NULL, NULL));
  73952. ExpectNull(RSA_generate_key(RSA_MIN_SIZE - 1, 3, NULL, NULL));
  73953. ExpectNull(RSA_generate_key(RSA_MAX_SIZE + 1, 3, NULL, NULL));
  73954. ExpectNull(RSA_generate_key(2048, 0, NULL, NULL));
  73955. #if !defined(NO_FILESYSTEM) && !defined(NO_ASN)
  73956. {
  73957. byte buff[FOURK_BUF];
  73958. byte der[FOURK_BUF];
  73959. const char PrivKeyPemFile[] = "certs/client-keyEnc.pem";
  73960. XFILE f = XBADFILE;
  73961. int bytes = 0;
  73962. /* test loading encrypted RSA private pem w/o password */
  73963. ExpectTrue((f = XFOPEN(PrivKeyPemFile, "rb")) != XBADFILE);
  73964. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  73965. if (f != XBADFILE)
  73966. XFCLOSE(f);
  73967. XMEMSET(der, 0, sizeof(der));
  73968. /* test that error value is returned with no password */
  73969. ExpectIntLT(wc_KeyPemToDer(buff, bytes, der, (word32)sizeof(der), ""),
  73970. 0);
  73971. }
  73972. #endif
  73973. #endif
  73974. return EXPECT_RESULT();
  73975. }
  73976. static int test_wolfSSL_RSA_DER(void)
  73977. {
  73978. EXPECT_DECLS;
  73979. #if defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA) && defined(OPENSSL_EXTRA)
  73980. RSA *rsa = NULL;
  73981. int i;
  73982. const unsigned char *buff = NULL;
  73983. unsigned char *newBuff = NULL;
  73984. struct tbl_s
  73985. {
  73986. const unsigned char *der;
  73987. int sz;
  73988. } tbl[] = {
  73989. #ifdef USE_CERT_BUFFERS_1024
  73990. {client_key_der_1024, sizeof_client_key_der_1024},
  73991. {server_key_der_1024, sizeof_server_key_der_1024},
  73992. #endif
  73993. #ifdef USE_CERT_BUFFERS_2048
  73994. {client_key_der_2048, sizeof_client_key_der_2048},
  73995. {server_key_der_2048, sizeof_server_key_der_2048},
  73996. #endif
  73997. {NULL, 0}
  73998. };
  73999. /* Public Key DER */
  74000. struct tbl_s pub[] = {
  74001. #ifdef USE_CERT_BUFFERS_1024
  74002. {client_keypub_der_1024, sizeof_client_keypub_der_1024},
  74003. #endif
  74004. #ifdef USE_CERT_BUFFERS_2048
  74005. {client_keypub_der_2048, sizeof_client_keypub_der_2048},
  74006. #endif
  74007. {NULL, 0}
  74008. };
  74009. ExpectNull(d2i_RSAPublicKey(&rsa, NULL, pub[0].sz));
  74010. buff = pub[0].der;
  74011. ExpectNull(d2i_RSAPublicKey(&rsa, &buff, 1));
  74012. ExpectNull(d2i_RSAPrivateKey(&rsa, NULL, tbl[0].sz));
  74013. buff = tbl[0].der;
  74014. ExpectNull(d2i_RSAPrivateKey(&rsa, &buff, 1));
  74015. ExpectIntEQ(i2d_RSAPublicKey(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  74016. rsa = RSA_new();
  74017. ExpectIntEQ(i2d_RSAPublicKey(rsa, NULL), 0);
  74018. RSA_free(rsa);
  74019. rsa = NULL;
  74020. for (i = 0; tbl[i].der != NULL; i++)
  74021. {
  74022. /* Passing in pointer results in pointer moving. */
  74023. buff = tbl[i].der;
  74024. ExpectNotNull(d2i_RSAPublicKey(&rsa, &buff, tbl[i].sz));
  74025. ExpectNotNull(rsa);
  74026. RSA_free(rsa);
  74027. rsa = NULL;
  74028. }
  74029. for (i = 0; tbl[i].der != NULL; i++)
  74030. {
  74031. /* Passing in pointer results in pointer moving. */
  74032. buff = tbl[i].der;
  74033. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &buff, tbl[i].sz));
  74034. ExpectNotNull(rsa);
  74035. RSA_free(rsa);
  74036. rsa = NULL;
  74037. }
  74038. for (i = 0; pub[i].der != NULL; i++)
  74039. {
  74040. buff = pub[i].der;
  74041. ExpectNotNull(d2i_RSAPublicKey(&rsa, &buff, pub[i].sz));
  74042. ExpectNotNull(rsa);
  74043. ExpectIntEQ(i2d_RSAPublicKey(rsa, NULL), pub[i].sz);
  74044. newBuff = NULL;
  74045. ExpectIntEQ(i2d_RSAPublicKey(rsa, &newBuff), pub[i].sz);
  74046. ExpectNotNull(newBuff);
  74047. ExpectIntEQ(XMEMCMP((void *)newBuff, (void *)pub[i].der, pub[i].sz), 0);
  74048. XFREE((void *)newBuff, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  74049. RSA_free(rsa);
  74050. rsa = NULL;
  74051. }
  74052. #endif
  74053. return EXPECT_RESULT();
  74054. }
  74055. static int test_wolfSSL_RSA_print(void)
  74056. {
  74057. EXPECT_DECLS;
  74058. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && \
  74059. !defined(NO_STDIO_FILESYSTEM) && \
  74060. !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  74061. !defined(NO_BIO) && defined(XFPRINTF)
  74062. BIO *bio = NULL;
  74063. WOLFSSL_RSA* rsa = NULL;
  74064. ExpectNotNull(bio = BIO_new_fd(STDERR_FILENO, BIO_NOCLOSE));
  74065. ExpectNotNull(rsa = RSA_new());
  74066. ExpectIntEQ(RSA_print(NULL, rsa, 0), -1);
  74067. ExpectIntEQ(RSA_print_fp(XBADFILE, rsa, 0), 0);
  74068. ExpectIntEQ(RSA_print(bio, NULL, 0), -1);
  74069. ExpectIntEQ(RSA_print_fp(stderr, NULL, 0), 0);
  74070. /* Some very large number of indent spaces. */
  74071. ExpectIntEQ(RSA_print(bio, rsa, 128), -1);
  74072. /* RSA is empty. */
  74073. ExpectIntEQ(RSA_print(bio, rsa, 0), 0);
  74074. ExpectIntEQ(RSA_print_fp(stderr, rsa, 0), 0);
  74075. RSA_free(rsa);
  74076. rsa = NULL;
  74077. ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  74078. ExpectIntEQ(RSA_print(bio, rsa, 0), 1);
  74079. ExpectIntEQ(RSA_print(bio, rsa, 4), 1);
  74080. ExpectIntEQ(RSA_print(bio, rsa, -1), 1);
  74081. ExpectIntEQ(RSA_print_fp(stderr, rsa, 0), 1);
  74082. ExpectIntEQ(RSA_print_fp(stderr, rsa, 4), 1);
  74083. ExpectIntEQ(RSA_print_fp(stderr, rsa, -1), 1);
  74084. BIO_free(bio);
  74085. RSA_free(rsa);
  74086. #endif
  74087. return EXPECT_RESULT();
  74088. }
  74089. static int test_wolfSSL_RSA_padding_add_PKCS1_PSS(void)
  74090. {
  74091. EXPECT_DECLS;
  74092. #ifndef NO_RSA
  74093. #if defined(OPENSSL_ALL) && defined(WC_RSA_PSS) && !defined(WC_NO_RNG)
  74094. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  74095. RSA *rsa = NULL;
  74096. const unsigned char *derBuf = client_key_der_2048;
  74097. unsigned char em[256] = {0}; /* len = 2048/8 */
  74098. /* Random data simulating a hash */
  74099. const unsigned char mHash[WC_SHA256_DIGEST_SIZE] = {
  74100. 0x28, 0x6e, 0xfd, 0xf8, 0x76, 0xc7, 0x00, 0x3d, 0x91, 0x4e, 0x59, 0xe4,
  74101. 0x8e, 0xb7, 0x40, 0x7b, 0xd1, 0x0c, 0x98, 0x4b, 0xe3, 0x3d, 0xb3, 0xeb,
  74102. 0x6f, 0x8a, 0x3c, 0x42, 0xab, 0x21, 0xad, 0x28
  74103. };
  74104. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &derBuf, sizeof_client_key_der_2048));
  74105. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(NULL, em, mHash, EVP_sha256(),
  74106. RSA_PSS_SALTLEN_DIGEST), 0);
  74107. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, NULL, mHash, EVP_sha256(),
  74108. RSA_PSS_SALTLEN_DIGEST), 0);
  74109. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, NULL, EVP_sha256(),
  74110. RSA_PSS_SALTLEN_DIGEST), 0);
  74111. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, NULL,
  74112. RSA_PSS_SALTLEN_DIGEST), 0);
  74113. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, EVP_sha256(), -5), 0);
  74114. ExpectIntEQ(RSA_verify_PKCS1_PSS(NULL, mHash, EVP_sha256(), em,
  74115. RSA_PSS_SALTLEN_MAX_SIGN), 0);
  74116. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, NULL, EVP_sha256(), em,
  74117. RSA_PSS_SALTLEN_MAX_SIGN), 0);
  74118. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, NULL, em,
  74119. RSA_PSS_SALTLEN_MAX_SIGN), 0);
  74120. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), NULL,
  74121. RSA_PSS_SALTLEN_MAX_SIGN), 0);
  74122. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em,
  74123. RSA_PSS_SALTLEN_MAX_SIGN), 0);
  74124. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em, -5), 0);
  74125. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, EVP_sha256(),
  74126. RSA_PSS_SALTLEN_DIGEST), 1);
  74127. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em,
  74128. RSA_PSS_SALTLEN_DIGEST), 1);
  74129. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, EVP_sha256(),
  74130. RSA_PSS_SALTLEN_MAX_SIGN), 1);
  74131. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em,
  74132. RSA_PSS_SALTLEN_MAX_SIGN), 1);
  74133. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, EVP_sha256(),
  74134. RSA_PSS_SALTLEN_MAX), 1);
  74135. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em,
  74136. RSA_PSS_SALTLEN_MAX), 1);
  74137. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, EVP_sha256(), 10), 1);
  74138. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em, 10), 1);
  74139. RSA_free(rsa);
  74140. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  74141. #endif /* OPENSSL_ALL && WC_RSA_PSS && !WC_NO_RNG*/
  74142. #endif
  74143. return EXPECT_RESULT();
  74144. }
  74145. static int test_wolfSSL_RSA_sign_sha3(void)
  74146. {
  74147. EXPECT_DECLS;
  74148. #if !defined(NO_RSA) && defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  74149. #if defined(OPENSSL_ALL) && defined(WC_RSA_PSS) && !defined(WC_NO_RNG)
  74150. RSA* rsa = NULL;
  74151. const unsigned char *derBuf = client_key_der_2048;
  74152. unsigned char sigRet[256] = {0};
  74153. unsigned int sigLen = sizeof(sigRet);
  74154. /* Random data simulating a hash */
  74155. const unsigned char mHash[WC_SHA3_256_DIGEST_SIZE] = {
  74156. 0x28, 0x6e, 0xfd, 0xf8, 0x76, 0xc7, 0x00, 0x3d, 0x91, 0x4e, 0x59, 0xe4,
  74157. 0x8e, 0xb7, 0x40, 0x7b, 0xd1, 0x0c, 0x98, 0x4b, 0xe3, 0x3d, 0xb3, 0xeb,
  74158. 0x6f, 0x8a, 0x3c, 0x42, 0xab, 0x21, 0xad, 0x28
  74159. };
  74160. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &derBuf, sizeof_client_key_der_2048));
  74161. ExpectIntEQ(RSA_sign(NID_sha3_256, mHash, sizeof(mHash), sigRet, &sigLen,
  74162. rsa), 1);
  74163. RSA_free(rsa);
  74164. #endif /* OPENSSL_ALL && WC_RSA_PSS && !WC_NO_RNG*/
  74165. #endif /* !NO_RSA && WOLFSSL_SHA3 && !WOLFSSL_NOSHA3_256*/
  74166. return EXPECT_RESULT();
  74167. }
  74168. static int test_wolfSSL_RSA_get0_key(void)
  74169. {
  74170. EXPECT_DECLS;
  74171. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74172. RSA *rsa = NULL;
  74173. const BIGNUM* n = NULL;
  74174. const BIGNUM* e = NULL;
  74175. const BIGNUM* d = NULL;
  74176. const unsigned char* der;
  74177. int derSz;
  74178. #ifdef USE_CERT_BUFFERS_1024
  74179. der = client_key_der_1024;
  74180. derSz = sizeof_client_key_der_1024;
  74181. #elif defined(USE_CERT_BUFFERS_2048)
  74182. der = client_key_der_2048;
  74183. derSz = sizeof_client_key_der_2048;
  74184. #else
  74185. der = NULL;
  74186. derSz = 0;
  74187. #endif
  74188. if (der != NULL) {
  74189. RSA_get0_key(NULL, NULL, NULL, NULL);
  74190. RSA_get0_key(rsa, NULL, NULL, NULL);
  74191. RSA_get0_key(NULL, &n, &e, &d);
  74192. ExpectNull(n);
  74193. ExpectNull(e);
  74194. ExpectNull(d);
  74195. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, derSz));
  74196. ExpectNotNull(rsa);
  74197. RSA_get0_key(rsa, NULL, NULL, NULL);
  74198. RSA_get0_key(rsa, &n, NULL, NULL);
  74199. ExpectNotNull(n);
  74200. RSA_get0_key(rsa, NULL, &e, NULL);
  74201. ExpectNotNull(e);
  74202. RSA_get0_key(rsa, NULL, NULL, &d);
  74203. ExpectNotNull(d);
  74204. RSA_get0_key(rsa, &n, &e, &d);
  74205. ExpectNotNull(n);
  74206. ExpectNotNull(e);
  74207. ExpectNotNull(d);
  74208. RSA_free(rsa);
  74209. }
  74210. #endif
  74211. return EXPECT_RESULT();
  74212. }
  74213. static int test_wolfSSL_RSA_meth(void)
  74214. {
  74215. EXPECT_DECLS;
  74216. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74217. RSA *rsa = NULL;
  74218. RSA_METHOD *rsa_meth = NULL;
  74219. #ifdef WOLFSSL_KEY_GEN
  74220. ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  74221. RSA_free(rsa);
  74222. rsa = NULL;
  74223. #else
  74224. ExpectNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  74225. #endif
  74226. ExpectNotNull(RSA_get_default_method());
  74227. wolfSSL_RSA_meth_free(NULL);
  74228. ExpectNull(wolfSSL_RSA_meth_new(NULL, 0));
  74229. ExpectNotNull(rsa_meth = RSA_meth_new("placeholder RSA method",
  74230. RSA_METHOD_FLAG_NO_CHECK));
  74231. #ifndef NO_WOLFSSL_STUB
  74232. ExpectIntEQ(RSA_meth_set_pub_enc(rsa_meth, NULL), 1);
  74233. ExpectIntEQ(RSA_meth_set_pub_dec(rsa_meth, NULL), 1);
  74234. ExpectIntEQ(RSA_meth_set_priv_enc(rsa_meth, NULL), 1);
  74235. ExpectIntEQ(RSA_meth_set_priv_dec(rsa_meth, NULL), 1);
  74236. ExpectIntEQ(RSA_meth_set_init(rsa_meth, NULL), 1);
  74237. ExpectIntEQ(RSA_meth_set_finish(rsa_meth, NULL), 1);
  74238. ExpectIntEQ(RSA_meth_set0_app_data(rsa_meth, NULL), 1);
  74239. #endif
  74240. ExpectIntEQ(RSA_flags(NULL), 0);
  74241. RSA_set_flags(NULL, RSA_FLAG_CACHE_PUBLIC);
  74242. RSA_clear_flags(NULL, RSA_FLAG_CACHE_PUBLIC);
  74243. ExpectIntEQ(RSA_test_flags(NULL, RSA_FLAG_CACHE_PUBLIC), 0);
  74244. ExpectNotNull(rsa = RSA_new());
  74245. /* No method set. */
  74246. ExpectIntEQ(RSA_flags(rsa), 0);
  74247. RSA_set_flags(rsa, RSA_FLAG_CACHE_PUBLIC);
  74248. RSA_clear_flags(rsa, RSA_FLAG_CACHE_PUBLIC);
  74249. ExpectIntEQ(RSA_test_flags(rsa, RSA_FLAG_CACHE_PUBLIC), 0);
  74250. ExpectIntEQ(RSA_set_method(NULL, rsa_meth), 1);
  74251. ExpectIntEQ(RSA_set_method(rsa, rsa_meth), 1);
  74252. if (EXPECT_FAIL()) {
  74253. wolfSSL_RSA_meth_free(rsa_meth);
  74254. }
  74255. ExpectNull(RSA_get_method(NULL));
  74256. ExpectPtrEq(RSA_get_method(rsa), rsa_meth);
  74257. ExpectIntEQ(RSA_flags(rsa), RSA_METHOD_FLAG_NO_CHECK);
  74258. RSA_set_flags(rsa, RSA_FLAG_CACHE_PUBLIC);
  74259. ExpectIntNE(RSA_test_flags(rsa, RSA_FLAG_CACHE_PUBLIC), 0);
  74260. ExpectIntEQ(RSA_flags(rsa), RSA_FLAG_CACHE_PUBLIC |
  74261. RSA_METHOD_FLAG_NO_CHECK);
  74262. RSA_clear_flags(rsa, RSA_FLAG_CACHE_PUBLIC);
  74263. ExpectIntEQ(RSA_test_flags(rsa, RSA_FLAG_CACHE_PUBLIC), 0);
  74264. ExpectIntNE(RSA_flags(rsa), RSA_FLAG_CACHE_PUBLIC);
  74265. /* rsa_meth is freed here */
  74266. RSA_free(rsa);
  74267. #endif
  74268. return EXPECT_RESULT();
  74269. }
  74270. static int test_wolfSSL_RSA_verify(void)
  74271. {
  74272. EXPECT_DECLS;
  74273. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  74274. #ifndef NO_BIO
  74275. XFILE fp = XBADFILE;
  74276. RSA *pKey = NULL;
  74277. RSA *pubKey = NULL;
  74278. X509 *cert = NULL;
  74279. const char *text = "Hello wolfSSL !";
  74280. unsigned char hash[SHA256_DIGEST_LENGTH];
  74281. unsigned char signature[2048/8];
  74282. unsigned int signatureLength;
  74283. byte *buf = NULL;
  74284. BIO *bio = NULL;
  74285. SHA256_CTX c;
  74286. EVP_PKEY *evpPkey = NULL;
  74287. EVP_PKEY *evpPubkey = NULL;
  74288. size_t sz;
  74289. /* generate hash */
  74290. SHA256_Init(&c);
  74291. SHA256_Update(&c, text, strlen(text));
  74292. SHA256_Final(hash, &c);
  74293. #ifdef WOLFSSL_SMALL_STACK_CACHE
  74294. /* workaround for small stack cache case */
  74295. wc_Sha256Free((wc_Sha256*)&c);
  74296. #endif
  74297. /* read privete key file */
  74298. ExpectTrue((fp = XFOPEN(svrKeyFile, "rb")) != XBADFILE);
  74299. ExpectIntEQ(XFSEEK(fp, 0, XSEEK_END), 0);
  74300. ExpectTrue((sz = XFTELL(fp)) > 0);
  74301. ExpectIntEQ(XFSEEK(fp, 0, XSEEK_SET), 0);
  74302. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  74303. ExpectIntEQ(XFREAD(buf, 1, sz, fp), sz);
  74304. if (fp != XBADFILE) {
  74305. XFCLOSE(fp);
  74306. fp = XBADFILE;
  74307. }
  74308. /* read private key and sign hash data */
  74309. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  74310. ExpectNotNull(evpPkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL));
  74311. ExpectNotNull(pKey = EVP_PKEY_get1_RSA(evpPkey));
  74312. ExpectIntEQ(RSA_sign(NID_sha256, hash, SHA256_DIGEST_LENGTH,
  74313. signature, &signatureLength, pKey), SSL_SUCCESS);
  74314. /* read public key and verify signed data */
  74315. ExpectTrue((fp = XFOPEN(svrCertFile,"rb")) != XBADFILE);
  74316. ExpectNotNull(cert = PEM_read_X509(fp, 0, 0, 0 ));
  74317. if (fp != XBADFILE)
  74318. XFCLOSE(fp);
  74319. ExpectNotNull(evpPubkey = X509_get_pubkey(cert));
  74320. ExpectNotNull(pubKey = EVP_PKEY_get1_RSA(evpPubkey));
  74321. ExpectIntEQ(RSA_verify(NID_sha256, hash, SHA256_DIGEST_LENGTH, signature,
  74322. signatureLength, pubKey), SSL_SUCCESS);
  74323. ExpectIntEQ(RSA_verify(NID_sha256, NULL, SHA256_DIGEST_LENGTH, NULL,
  74324. signatureLength, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74325. ExpectIntEQ(RSA_verify(NID_sha256, NULL, SHA256_DIGEST_LENGTH, signature,
  74326. signatureLength, pubKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74327. ExpectIntEQ(RSA_verify(NID_sha256, hash, SHA256_DIGEST_LENGTH, NULL,
  74328. signatureLength, pubKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74329. ExpectIntEQ(RSA_verify(NID_sha256, hash, SHA256_DIGEST_LENGTH, signature,
  74330. signatureLength, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74331. RSA_free(pKey);
  74332. EVP_PKEY_free(evpPkey);
  74333. RSA_free(pubKey);
  74334. EVP_PKEY_free(evpPubkey);
  74335. X509_free(cert);
  74336. BIO_free(bio);
  74337. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  74338. #endif
  74339. #endif
  74340. return EXPECT_RESULT();
  74341. }
  74342. static int test_wolfSSL_RSA_sign(void)
  74343. {
  74344. EXPECT_DECLS;
  74345. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74346. RSA *rsa;
  74347. unsigned char hash[SHA256_DIGEST_LENGTH];
  74348. #ifdef USE_CERT_BUFFERS_1024
  74349. const unsigned char* privDer = client_key_der_1024;
  74350. size_t privDerSz = sizeof_client_key_der_1024;
  74351. const unsigned char* pubDer = client_keypub_der_1024;
  74352. size_t pubDerSz = sizeof_client_keypub_der_1024;
  74353. unsigned char signature[1024/8];
  74354. #else
  74355. const unsigned char* privDer = client_key_der_2048;
  74356. size_t privDerSz = sizeof_client_key_der_2048;
  74357. const unsigned char* pubDer = client_keypub_der_2048;
  74358. size_t pubDerSz = sizeof_client_keypub_der_2048;
  74359. unsigned char signature[2048/8];
  74360. #endif
  74361. unsigned int signatureLen;
  74362. const unsigned char* der;
  74363. XMEMSET(hash, 0, sizeof(hash));
  74364. der = privDer;
  74365. rsa = NULL;
  74366. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  74367. /* Invalid parameters. */
  74368. ExpectIntEQ(RSA_sign(NID_rsaEncryption, NULL, 0, NULL, NULL, NULL), 0);
  74369. ExpectIntEQ(RSA_sign(NID_rsaEncryption, hash, sizeof(hash), signature,
  74370. &signatureLen, rsa), 0);
  74371. ExpectIntEQ(RSA_sign(NID_sha256, NULL, sizeof(hash), signature,
  74372. &signatureLen, rsa), 0);
  74373. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), NULL,
  74374. &signatureLen, rsa), 0);
  74375. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  74376. NULL, rsa), 0);
  74377. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  74378. &signatureLen, NULL), 0);
  74379. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  74380. &signatureLen, rsa), 1);
  74381. RSA_free(rsa);
  74382. der = pubDer;
  74383. rsa = NULL;
  74384. ExpectNotNull(d2i_RSAPublicKey(&rsa, &der, pubDerSz));
  74385. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  74386. signatureLen, rsa), 1);
  74387. RSA_free(rsa);
  74388. #endif
  74389. return EXPECT_RESULT();
  74390. }
  74391. static int test_wolfSSL_RSA_sign_ex(void)
  74392. {
  74393. EXPECT_DECLS;
  74394. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74395. RSA *rsa = NULL;
  74396. unsigned char hash[SHA256_DIGEST_LENGTH];
  74397. #ifdef USE_CERT_BUFFERS_1024
  74398. const unsigned char* privDer = client_key_der_1024;
  74399. size_t privDerSz = sizeof_client_key_der_1024;
  74400. const unsigned char* pubDer = client_keypub_der_1024;
  74401. size_t pubDerSz = sizeof_client_keypub_der_1024;
  74402. unsigned char signature[1024/8];
  74403. #else
  74404. const unsigned char* privDer = client_key_der_2048;
  74405. size_t privDerSz = sizeof_client_key_der_2048;
  74406. const unsigned char* pubDer = client_keypub_der_2048;
  74407. size_t pubDerSz = sizeof_client_keypub_der_2048;
  74408. unsigned char signature[2048/8];
  74409. #endif
  74410. unsigned int signatureLen;
  74411. const unsigned char* der;
  74412. unsigned char encodedHash[51];
  74413. unsigned int encodedHashLen;
  74414. const unsigned char expEncHash[] = {
  74415. 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
  74416. 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05,
  74417. 0x00, 0x04, 0x20,
  74418. /* Hash data */
  74419. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  74420. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  74421. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  74422. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  74423. };
  74424. XMEMSET(hash, 0, sizeof(hash));
  74425. ExpectNotNull(rsa = wolfSSL_RSA_new());
  74426. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  74427. &signatureLen, rsa, 1), 0);
  74428. wolfSSL_RSA_free(rsa);
  74429. der = privDer;
  74430. rsa = NULL;
  74431. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  74432. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_rsaEncryption,NULL, 0, NULL, NULL, NULL,
  74433. -1), 0);
  74434. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_rsaEncryption, hash, sizeof(hash),
  74435. signature, &signatureLen, rsa, 1), 0);
  74436. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, NULL, sizeof(hash), signature,
  74437. &signatureLen, rsa, 1), 0);
  74438. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), NULL,
  74439. &signatureLen, rsa, 1), 0);
  74440. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  74441. NULL, rsa, 1), 0);
  74442. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  74443. &signatureLen, NULL, 1), 0);
  74444. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  74445. &signatureLen, rsa, -1), 0);
  74446. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, NULL, sizeof(hash), signature,
  74447. &signatureLen, rsa, 0), 0);
  74448. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), NULL,
  74449. &signatureLen, rsa, 0), 0);
  74450. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  74451. NULL, rsa, 0), 0);
  74452. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  74453. &signatureLen, rsa, 1), 1);
  74454. /* Test returning encoded hash. */
  74455. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), encodedHash,
  74456. &encodedHashLen, rsa, 0), 1);
  74457. ExpectIntEQ(encodedHashLen, sizeof(expEncHash));
  74458. ExpectIntEQ(XMEMCMP(encodedHash, expEncHash, sizeof(expEncHash)), 0);
  74459. RSA_free(rsa);
  74460. der = pubDer;
  74461. rsa = NULL;
  74462. ExpectNotNull(d2i_RSAPublicKey(&rsa, &der, pubDerSz));
  74463. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  74464. signatureLen, rsa), 1);
  74465. RSA_free(rsa);
  74466. #endif
  74467. return EXPECT_RESULT();
  74468. }
  74469. static int test_wolfSSL_RSA_public_decrypt(void)
  74470. {
  74471. EXPECT_DECLS;
  74472. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74473. RSA *rsa;
  74474. unsigned char msg[SHA256_DIGEST_LENGTH];
  74475. #ifdef USE_CERT_BUFFERS_1024
  74476. const unsigned char* pubDer = client_keypub_der_1024;
  74477. size_t pubDerSz = sizeof_client_keypub_der_1024;
  74478. unsigned char decMsg[1024/8];
  74479. const unsigned char encMsg[] = {
  74480. 0x45, 0x8e, 0x6e, 0x7a, 0x9c, 0xe1, 0x67, 0x36,
  74481. 0x72, 0xfc, 0x9d, 0x05, 0xdf, 0xc2, 0xaf, 0x54,
  74482. 0xc5, 0x2f, 0x94, 0xb8, 0xc7, 0x82, 0x40, 0xfa,
  74483. 0xa7, 0x8c, 0xb1, 0x89, 0x40, 0xc3, 0x59, 0x5a,
  74484. 0x77, 0x08, 0x54, 0x93, 0x43, 0x7f, 0xc4, 0xb7,
  74485. 0xc4, 0x78, 0xf1, 0xf8, 0xab, 0xbf, 0xc2, 0x81,
  74486. 0x5d, 0x97, 0xea, 0x7a, 0x60, 0x90, 0x51, 0xb7,
  74487. 0x47, 0x78, 0x48, 0x1e, 0x88, 0x6b, 0x89, 0xde,
  74488. 0xce, 0x41, 0x41, 0xae, 0x49, 0xf6, 0xfd, 0x2d,
  74489. 0x2d, 0x9c, 0x70, 0x7d, 0xf9, 0xcf, 0x77, 0x5f,
  74490. 0x06, 0xc7, 0x20, 0xe3, 0x57, 0xd4, 0xd8, 0x1a,
  74491. 0x96, 0xa2, 0x39, 0xb0, 0x6e, 0x8e, 0x68, 0xf8,
  74492. 0x57, 0x7b, 0x26, 0x88, 0x17, 0xc4, 0xb7, 0xf1,
  74493. 0x59, 0xfa, 0xb6, 0x95, 0xdd, 0x1e, 0xe8, 0xd8,
  74494. 0x4e, 0xbd, 0xcd, 0x41, 0xad, 0xc7, 0xe2, 0x39,
  74495. 0xb8, 0x00, 0xca, 0xf5, 0x59, 0xdf, 0xf8, 0x43
  74496. };
  74497. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  74498. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2)) && \
  74499. defined(WC_RSA_NO_PADDING)
  74500. const unsigned char encMsgNoPad[] = {
  74501. 0x0d, 0x41, 0x5a, 0xc7, 0x60, 0xd7, 0xbe, 0xb6,
  74502. 0x42, 0xd1, 0x65, 0xb1, 0x7e, 0x59, 0x54, 0xcc,
  74503. 0x76, 0x62, 0xd0, 0x2f, 0x4d, 0xe3, 0x23, 0x62,
  74504. 0xc8, 0x14, 0xfe, 0x5e, 0xa1, 0xc7, 0x05, 0xee,
  74505. 0x9e, 0x28, 0x2e, 0xf5, 0xfd, 0xa4, 0xc0, 0x43,
  74506. 0x55, 0xa2, 0x6b, 0x6b, 0x16, 0xa7, 0x63, 0x06,
  74507. 0xa7, 0x78, 0x4f, 0xda, 0xae, 0x10, 0x6d, 0xd1,
  74508. 0x2e, 0x1d, 0xbb, 0xbc, 0xc4, 0x1d, 0x82, 0xe4,
  74509. 0xc6, 0x76, 0x77, 0xa6, 0x0a, 0xef, 0xd2, 0x89,
  74510. 0xff, 0x30, 0x85, 0x22, 0xa0, 0x68, 0x88, 0x54,
  74511. 0xa3, 0xd1, 0x92, 0xd1, 0x3f, 0x57, 0xe4, 0xc7,
  74512. 0x43, 0x5a, 0x8b, 0xb3, 0x86, 0xaf, 0xd5, 0x6d,
  74513. 0x07, 0xe1, 0xa0, 0x5f, 0xe1, 0x9a, 0x06, 0xba,
  74514. 0x56, 0xd2, 0xb0, 0x73, 0xf5, 0xb3, 0xd0, 0x5f,
  74515. 0xc0, 0xbf, 0x22, 0x4c, 0x54, 0x4e, 0x11, 0xe2,
  74516. 0xc5, 0xf8, 0x66, 0x39, 0x9d, 0x70, 0x90, 0x31
  74517. };
  74518. #endif
  74519. #else
  74520. const unsigned char* pubDer = client_keypub_der_2048;
  74521. size_t pubDerSz = sizeof_client_keypub_der_2048;
  74522. unsigned char decMsg[2048/8];
  74523. const unsigned char encMsg[] = {
  74524. 0x16, 0x5d, 0xbb, 0x00, 0x38, 0x73, 0x01, 0x34,
  74525. 0xca, 0x59, 0xc6, 0x8b, 0x64, 0x70, 0x89, 0xf5,
  74526. 0x50, 0x2d, 0x1d, 0x69, 0x1f, 0x07, 0x1e, 0x31,
  74527. 0xae, 0x9b, 0xa6, 0x6e, 0xee, 0x80, 0xd9, 0x9e,
  74528. 0x59, 0x33, 0x70, 0x30, 0x28, 0x42, 0x7d, 0x24,
  74529. 0x36, 0x95, 0x6b, 0xf9, 0x0a, 0x23, 0xcb, 0xce,
  74530. 0x66, 0xa5, 0x07, 0x5e, 0x11, 0xa7, 0xdc, 0xfb,
  74531. 0xd9, 0xc2, 0x51, 0xf0, 0x05, 0xc9, 0x39, 0xb3,
  74532. 0xae, 0xff, 0xfb, 0xe9, 0xb1, 0x9a, 0x54, 0xac,
  74533. 0x1d, 0xca, 0x42, 0x1a, 0xfd, 0x7c, 0x97, 0xa0,
  74534. 0x60, 0x2b, 0xcd, 0xb6, 0x36, 0x33, 0xfc, 0x44,
  74535. 0x69, 0xf7, 0x2e, 0x8c, 0x3b, 0x5f, 0xb4, 0x9f,
  74536. 0xa7, 0x02, 0x8f, 0x6d, 0x6b, 0x79, 0x10, 0x32,
  74537. 0x7d, 0xf4, 0x5d, 0xa1, 0x63, 0x22, 0x59, 0xc4,
  74538. 0x44, 0x8e, 0x44, 0x24, 0x8b, 0x14, 0x9d, 0x2b,
  74539. 0xb5, 0xd3, 0xad, 0x9a, 0x87, 0x0d, 0xe7, 0x70,
  74540. 0x6d, 0xe9, 0xae, 0xaa, 0x52, 0xbf, 0x1a, 0x9b,
  74541. 0xc8, 0x3d, 0x45, 0x7c, 0xd1, 0x90, 0xe3, 0xd9,
  74542. 0x57, 0xcf, 0xc3, 0x29, 0x69, 0x05, 0x07, 0x96,
  74543. 0x2e, 0x46, 0x74, 0x0a, 0xa7, 0x76, 0x8b, 0xc0,
  74544. 0x1c, 0x04, 0x80, 0x08, 0xa0, 0x94, 0x7e, 0xbb,
  74545. 0x2d, 0x99, 0xe9, 0xab, 0x18, 0x4d, 0x48, 0x2d,
  74546. 0x94, 0x5e, 0x50, 0x21, 0x42, 0xdf, 0xf5, 0x61,
  74547. 0x42, 0x7d, 0x86, 0x5d, 0x9e, 0x89, 0xc9, 0x5b,
  74548. 0x24, 0xab, 0xa1, 0xd8, 0x20, 0x45, 0xcb, 0x81,
  74549. 0xcf, 0xc5, 0x25, 0x7d, 0x11, 0x6e, 0xbd, 0x80,
  74550. 0xac, 0xba, 0xdc, 0xef, 0xb9, 0x05, 0x9c, 0xd5,
  74551. 0xc2, 0x26, 0x57, 0x69, 0x8b, 0x08, 0x27, 0xc7,
  74552. 0xea, 0xbe, 0xaf, 0x52, 0x21, 0x95, 0x9f, 0xa0,
  74553. 0x2f, 0x2f, 0x53, 0x7c, 0x2f, 0xa3, 0x0b, 0x79,
  74554. 0x39, 0x01, 0xa3, 0x37, 0x46, 0xa8, 0xc4, 0x34,
  74555. 0x41, 0x20, 0x7c, 0x3f, 0x70, 0x9a, 0x47, 0xe8
  74556. };
  74557. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  74558. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2)) && \
  74559. defined(WC_RSA_NO_PADDING)
  74560. const unsigned char encMsgNoPad[] = {
  74561. 0x79, 0x69, 0xdc, 0x0d, 0xff, 0x09, 0xeb, 0x91,
  74562. 0xbc, 0xda, 0xe4, 0xd3, 0xcd, 0xd5, 0xd3, 0x1c,
  74563. 0xb9, 0x66, 0xa8, 0x02, 0xf3, 0x75, 0x40, 0xf1,
  74564. 0x38, 0x4a, 0x37, 0x7b, 0x19, 0xc8, 0xcd, 0xea,
  74565. 0x79, 0xa8, 0x51, 0x32, 0x00, 0x3f, 0x4c, 0xde,
  74566. 0xaa, 0xe5, 0xe2, 0x7c, 0x10, 0xcd, 0x6e, 0x00,
  74567. 0xc6, 0xc4, 0x63, 0x98, 0x58, 0x9b, 0x38, 0xca,
  74568. 0xf0, 0x5d, 0xc8, 0xf0, 0x57, 0xf6, 0x21, 0x50,
  74569. 0x3f, 0x63, 0x05, 0x9f, 0xbf, 0xb6, 0x3b, 0x50,
  74570. 0x85, 0x06, 0x34, 0x08, 0x57, 0xb9, 0x44, 0xce,
  74571. 0xe4, 0x66, 0xbf, 0x0c, 0xfe, 0x36, 0xa4, 0x5b,
  74572. 0xed, 0x2d, 0x7d, 0xed, 0xf1, 0xbd, 0xda, 0x3e,
  74573. 0x19, 0x1f, 0x99, 0xc8, 0xe4, 0xc2, 0xbb, 0xb5,
  74574. 0x6c, 0x83, 0x22, 0xd1, 0xe7, 0x57, 0xcf, 0x1b,
  74575. 0x91, 0x0c, 0xa5, 0x47, 0x06, 0x71, 0x8f, 0x93,
  74576. 0xf3, 0xad, 0xdb, 0xe3, 0xf8, 0xa0, 0x0b, 0xcd,
  74577. 0x89, 0x4e, 0xa5, 0xb5, 0x03, 0x68, 0x61, 0x89,
  74578. 0x0b, 0xe2, 0x03, 0x8b, 0x1f, 0x54, 0xae, 0x0f,
  74579. 0xfa, 0xf0, 0xb7, 0x0f, 0x8c, 0x84, 0x35, 0x13,
  74580. 0x8d, 0x65, 0x1f, 0x2c, 0xd5, 0xce, 0xc4, 0x6c,
  74581. 0x98, 0x67, 0xe4, 0x1a, 0x85, 0x67, 0x69, 0x17,
  74582. 0x17, 0x5a, 0x5d, 0xfd, 0x23, 0xdd, 0x03, 0x3f,
  74583. 0x6d, 0x7a, 0xb6, 0x8b, 0x99, 0xc0, 0xb6, 0x70,
  74584. 0x86, 0xac, 0xf6, 0x02, 0xc2, 0x28, 0x42, 0xed,
  74585. 0x06, 0xcf, 0xca, 0x3d, 0x07, 0x16, 0xf0, 0x0e,
  74586. 0x04, 0x55, 0x1e, 0x59, 0x3f, 0x32, 0xc7, 0x12,
  74587. 0xc5, 0x0d, 0x9d, 0x64, 0x7d, 0x2e, 0xd4, 0xbc,
  74588. 0x8c, 0x24, 0x42, 0x94, 0x2b, 0xf6, 0x11, 0x7f,
  74589. 0xb1, 0x1c, 0x09, 0x12, 0x6f, 0x5e, 0x2e, 0x7a,
  74590. 0xc6, 0x01, 0xe0, 0x98, 0x31, 0xb7, 0x13, 0x03,
  74591. 0xce, 0x29, 0xe1, 0xef, 0x9d, 0xdf, 0x9b, 0xa5,
  74592. 0xba, 0x0b, 0xad, 0xf2, 0xeb, 0x2f, 0xf9, 0xd1
  74593. };
  74594. #endif
  74595. #endif
  74596. const unsigned char* der;
  74597. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  74598. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2)) && \
  74599. defined(WC_RSA_NO_PADDING)
  74600. int i;
  74601. #endif
  74602. XMEMSET(msg, 0, sizeof(msg));
  74603. der = pubDer;
  74604. rsa = NULL;
  74605. ExpectNotNull(d2i_RSAPublicKey(&rsa, &der, pubDerSz));
  74606. ExpectIntEQ(RSA_public_decrypt(0, NULL, NULL, NULL, 0), -1);
  74607. ExpectIntEQ(RSA_public_decrypt(-1, encMsg, decMsg, rsa,
  74608. RSA_PKCS1_PADDING), -1);
  74609. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsg), NULL, decMsg, rsa,
  74610. RSA_PKCS1_PADDING), -1);
  74611. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsg), encMsg, NULL, rsa,
  74612. RSA_PKCS1_PADDING), -1);
  74613. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsg), encMsg, decMsg, NULL,
  74614. RSA_PKCS1_PADDING), -1);
  74615. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsg), encMsg, decMsg, rsa,
  74616. RSA_PKCS1_PSS_PADDING), -1);
  74617. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsg), encMsg, decMsg, rsa,
  74618. RSA_PKCS1_PADDING), 32);
  74619. ExpectIntEQ(XMEMCMP(decMsg, msg, sizeof(msg)), 0);
  74620. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  74621. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2)) && \
  74622. defined(WC_RSA_NO_PADDING)
  74623. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsgNoPad), encMsgNoPad, decMsg,
  74624. rsa, RSA_NO_PADDING), sizeof(decMsg));
  74625. /* Zeros before actual data. */
  74626. for (i = 0; i < (int)(sizeof(decMsg) - sizeof(msg)); i += sizeof(msg)) {
  74627. ExpectIntEQ(XMEMCMP(decMsg + i, msg, sizeof(msg)), 0);
  74628. }
  74629. /* Check actual data. */
  74630. XMEMSET(msg, 0x01, sizeof(msg));
  74631. ExpectIntEQ(XMEMCMP(decMsg + i, msg, sizeof(msg)), 0);
  74632. #endif
  74633. RSA_free(rsa);
  74634. #endif
  74635. return EXPECT_RESULT();
  74636. }
  74637. static int test_wolfSSL_RSA_private_encrypt(void)
  74638. {
  74639. EXPECT_DECLS;
  74640. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74641. RSA *rsa;
  74642. unsigned char msg[SHA256_DIGEST_LENGTH];
  74643. #ifdef USE_CERT_BUFFERS_1024
  74644. const unsigned char* privDer = client_key_der_1024;
  74645. size_t privDerSz = sizeof_client_key_der_1024;
  74646. unsigned char encMsg[1024/8];
  74647. const unsigned char expEncMsg[] = {
  74648. 0x45, 0x8e, 0x6e, 0x7a, 0x9c, 0xe1, 0x67, 0x36,
  74649. 0x72, 0xfc, 0x9d, 0x05, 0xdf, 0xc2, 0xaf, 0x54,
  74650. 0xc5, 0x2f, 0x94, 0xb8, 0xc7, 0x82, 0x40, 0xfa,
  74651. 0xa7, 0x8c, 0xb1, 0x89, 0x40, 0xc3, 0x59, 0x5a,
  74652. 0x77, 0x08, 0x54, 0x93, 0x43, 0x7f, 0xc4, 0xb7,
  74653. 0xc4, 0x78, 0xf1, 0xf8, 0xab, 0xbf, 0xc2, 0x81,
  74654. 0x5d, 0x97, 0xea, 0x7a, 0x60, 0x90, 0x51, 0xb7,
  74655. 0x47, 0x78, 0x48, 0x1e, 0x88, 0x6b, 0x89, 0xde,
  74656. 0xce, 0x41, 0x41, 0xae, 0x49, 0xf6, 0xfd, 0x2d,
  74657. 0x2d, 0x9c, 0x70, 0x7d, 0xf9, 0xcf, 0x77, 0x5f,
  74658. 0x06, 0xc7, 0x20, 0xe3, 0x57, 0xd4, 0xd8, 0x1a,
  74659. 0x96, 0xa2, 0x39, 0xb0, 0x6e, 0x8e, 0x68, 0xf8,
  74660. 0x57, 0x7b, 0x26, 0x88, 0x17, 0xc4, 0xb7, 0xf1,
  74661. 0x59, 0xfa, 0xb6, 0x95, 0xdd, 0x1e, 0xe8, 0xd8,
  74662. 0x4e, 0xbd, 0xcd, 0x41, 0xad, 0xc7, 0xe2, 0x39,
  74663. 0xb8, 0x00, 0xca, 0xf5, 0x59, 0xdf, 0xf8, 0x43
  74664. };
  74665. #ifdef WC_RSA_NO_PADDING
  74666. const unsigned char expEncMsgNoPad[] = {
  74667. 0x0d, 0x41, 0x5a, 0xc7, 0x60, 0xd7, 0xbe, 0xb6,
  74668. 0x42, 0xd1, 0x65, 0xb1, 0x7e, 0x59, 0x54, 0xcc,
  74669. 0x76, 0x62, 0xd0, 0x2f, 0x4d, 0xe3, 0x23, 0x62,
  74670. 0xc8, 0x14, 0xfe, 0x5e, 0xa1, 0xc7, 0x05, 0xee,
  74671. 0x9e, 0x28, 0x2e, 0xf5, 0xfd, 0xa4, 0xc0, 0x43,
  74672. 0x55, 0xa2, 0x6b, 0x6b, 0x16, 0xa7, 0x63, 0x06,
  74673. 0xa7, 0x78, 0x4f, 0xda, 0xae, 0x10, 0x6d, 0xd1,
  74674. 0x2e, 0x1d, 0xbb, 0xbc, 0xc4, 0x1d, 0x82, 0xe4,
  74675. 0xc6, 0x76, 0x77, 0xa6, 0x0a, 0xef, 0xd2, 0x89,
  74676. 0xff, 0x30, 0x85, 0x22, 0xa0, 0x68, 0x88, 0x54,
  74677. 0xa3, 0xd1, 0x92, 0xd1, 0x3f, 0x57, 0xe4, 0xc7,
  74678. 0x43, 0x5a, 0x8b, 0xb3, 0x86, 0xaf, 0xd5, 0x6d,
  74679. 0x07, 0xe1, 0xa0, 0x5f, 0xe1, 0x9a, 0x06, 0xba,
  74680. 0x56, 0xd2, 0xb0, 0x73, 0xf5, 0xb3, 0xd0, 0x5f,
  74681. 0xc0, 0xbf, 0x22, 0x4c, 0x54, 0x4e, 0x11, 0xe2,
  74682. 0xc5, 0xf8, 0x66, 0x39, 0x9d, 0x70, 0x90, 0x31
  74683. };
  74684. #endif
  74685. #else
  74686. const unsigned char* privDer = client_key_der_2048;
  74687. size_t privDerSz = sizeof_client_key_der_2048;
  74688. unsigned char encMsg[2048/8];
  74689. const unsigned char expEncMsg[] = {
  74690. 0x16, 0x5d, 0xbb, 0x00, 0x38, 0x73, 0x01, 0x34,
  74691. 0xca, 0x59, 0xc6, 0x8b, 0x64, 0x70, 0x89, 0xf5,
  74692. 0x50, 0x2d, 0x1d, 0x69, 0x1f, 0x07, 0x1e, 0x31,
  74693. 0xae, 0x9b, 0xa6, 0x6e, 0xee, 0x80, 0xd9, 0x9e,
  74694. 0x59, 0x33, 0x70, 0x30, 0x28, 0x42, 0x7d, 0x24,
  74695. 0x36, 0x95, 0x6b, 0xf9, 0x0a, 0x23, 0xcb, 0xce,
  74696. 0x66, 0xa5, 0x07, 0x5e, 0x11, 0xa7, 0xdc, 0xfb,
  74697. 0xd9, 0xc2, 0x51, 0xf0, 0x05, 0xc9, 0x39, 0xb3,
  74698. 0xae, 0xff, 0xfb, 0xe9, 0xb1, 0x9a, 0x54, 0xac,
  74699. 0x1d, 0xca, 0x42, 0x1a, 0xfd, 0x7c, 0x97, 0xa0,
  74700. 0x60, 0x2b, 0xcd, 0xb6, 0x36, 0x33, 0xfc, 0x44,
  74701. 0x69, 0xf7, 0x2e, 0x8c, 0x3b, 0x5f, 0xb4, 0x9f,
  74702. 0xa7, 0x02, 0x8f, 0x6d, 0x6b, 0x79, 0x10, 0x32,
  74703. 0x7d, 0xf4, 0x5d, 0xa1, 0x63, 0x22, 0x59, 0xc4,
  74704. 0x44, 0x8e, 0x44, 0x24, 0x8b, 0x14, 0x9d, 0x2b,
  74705. 0xb5, 0xd3, 0xad, 0x9a, 0x87, 0x0d, 0xe7, 0x70,
  74706. 0x6d, 0xe9, 0xae, 0xaa, 0x52, 0xbf, 0x1a, 0x9b,
  74707. 0xc8, 0x3d, 0x45, 0x7c, 0xd1, 0x90, 0xe3, 0xd9,
  74708. 0x57, 0xcf, 0xc3, 0x29, 0x69, 0x05, 0x07, 0x96,
  74709. 0x2e, 0x46, 0x74, 0x0a, 0xa7, 0x76, 0x8b, 0xc0,
  74710. 0x1c, 0x04, 0x80, 0x08, 0xa0, 0x94, 0x7e, 0xbb,
  74711. 0x2d, 0x99, 0xe9, 0xab, 0x18, 0x4d, 0x48, 0x2d,
  74712. 0x94, 0x5e, 0x50, 0x21, 0x42, 0xdf, 0xf5, 0x61,
  74713. 0x42, 0x7d, 0x86, 0x5d, 0x9e, 0x89, 0xc9, 0x5b,
  74714. 0x24, 0xab, 0xa1, 0xd8, 0x20, 0x45, 0xcb, 0x81,
  74715. 0xcf, 0xc5, 0x25, 0x7d, 0x11, 0x6e, 0xbd, 0x80,
  74716. 0xac, 0xba, 0xdc, 0xef, 0xb9, 0x05, 0x9c, 0xd5,
  74717. 0xc2, 0x26, 0x57, 0x69, 0x8b, 0x08, 0x27, 0xc7,
  74718. 0xea, 0xbe, 0xaf, 0x52, 0x21, 0x95, 0x9f, 0xa0,
  74719. 0x2f, 0x2f, 0x53, 0x7c, 0x2f, 0xa3, 0x0b, 0x79,
  74720. 0x39, 0x01, 0xa3, 0x37, 0x46, 0xa8, 0xc4, 0x34,
  74721. 0x41, 0x20, 0x7c, 0x3f, 0x70, 0x9a, 0x47, 0xe8
  74722. };
  74723. #ifdef WC_RSA_NO_PADDING
  74724. const unsigned char expEncMsgNoPad[] = {
  74725. 0x79, 0x69, 0xdc, 0x0d, 0xff, 0x09, 0xeb, 0x91,
  74726. 0xbc, 0xda, 0xe4, 0xd3, 0xcd, 0xd5, 0xd3, 0x1c,
  74727. 0xb9, 0x66, 0xa8, 0x02, 0xf3, 0x75, 0x40, 0xf1,
  74728. 0x38, 0x4a, 0x37, 0x7b, 0x19, 0xc8, 0xcd, 0xea,
  74729. 0x79, 0xa8, 0x51, 0x32, 0x00, 0x3f, 0x4c, 0xde,
  74730. 0xaa, 0xe5, 0xe2, 0x7c, 0x10, 0xcd, 0x6e, 0x00,
  74731. 0xc6, 0xc4, 0x63, 0x98, 0x58, 0x9b, 0x38, 0xca,
  74732. 0xf0, 0x5d, 0xc8, 0xf0, 0x57, 0xf6, 0x21, 0x50,
  74733. 0x3f, 0x63, 0x05, 0x9f, 0xbf, 0xb6, 0x3b, 0x50,
  74734. 0x85, 0x06, 0x34, 0x08, 0x57, 0xb9, 0x44, 0xce,
  74735. 0xe4, 0x66, 0xbf, 0x0c, 0xfe, 0x36, 0xa4, 0x5b,
  74736. 0xed, 0x2d, 0x7d, 0xed, 0xf1, 0xbd, 0xda, 0x3e,
  74737. 0x19, 0x1f, 0x99, 0xc8, 0xe4, 0xc2, 0xbb, 0xb5,
  74738. 0x6c, 0x83, 0x22, 0xd1, 0xe7, 0x57, 0xcf, 0x1b,
  74739. 0x91, 0x0c, 0xa5, 0x47, 0x06, 0x71, 0x8f, 0x93,
  74740. 0xf3, 0xad, 0xdb, 0xe3, 0xf8, 0xa0, 0x0b, 0xcd,
  74741. 0x89, 0x4e, 0xa5, 0xb5, 0x03, 0x68, 0x61, 0x89,
  74742. 0x0b, 0xe2, 0x03, 0x8b, 0x1f, 0x54, 0xae, 0x0f,
  74743. 0xfa, 0xf0, 0xb7, 0x0f, 0x8c, 0x84, 0x35, 0x13,
  74744. 0x8d, 0x65, 0x1f, 0x2c, 0xd5, 0xce, 0xc4, 0x6c,
  74745. 0x98, 0x67, 0xe4, 0x1a, 0x85, 0x67, 0x69, 0x17,
  74746. 0x17, 0x5a, 0x5d, 0xfd, 0x23, 0xdd, 0x03, 0x3f,
  74747. 0x6d, 0x7a, 0xb6, 0x8b, 0x99, 0xc0, 0xb6, 0x70,
  74748. 0x86, 0xac, 0xf6, 0x02, 0xc2, 0x28, 0x42, 0xed,
  74749. 0x06, 0xcf, 0xca, 0x3d, 0x07, 0x16, 0xf0, 0x0e,
  74750. 0x04, 0x55, 0x1e, 0x59, 0x3f, 0x32, 0xc7, 0x12,
  74751. 0xc5, 0x0d, 0x9d, 0x64, 0x7d, 0x2e, 0xd4, 0xbc,
  74752. 0x8c, 0x24, 0x42, 0x94, 0x2b, 0xf6, 0x11, 0x7f,
  74753. 0xb1, 0x1c, 0x09, 0x12, 0x6f, 0x5e, 0x2e, 0x7a,
  74754. 0xc6, 0x01, 0xe0, 0x98, 0x31, 0xb7, 0x13, 0x03,
  74755. 0xce, 0x29, 0xe1, 0xef, 0x9d, 0xdf, 0x9b, 0xa5,
  74756. 0xba, 0x0b, 0xad, 0xf2, 0xeb, 0x2f, 0xf9, 0xd1
  74757. };
  74758. #endif
  74759. #endif
  74760. const unsigned char* der;
  74761. XMEMSET(msg, 0x00, sizeof(msg));
  74762. der = privDer;
  74763. rsa = NULL;
  74764. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  74765. ExpectIntEQ(RSA_private_encrypt(0, NULL, NULL, NULL, 0), -1);
  74766. ExpectIntEQ(RSA_private_encrypt(0, msg, encMsg, rsa, RSA_PKCS1_PADDING),
  74767. -1);
  74768. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), NULL, encMsg, rsa,
  74769. RSA_PKCS1_PADDING), -1);
  74770. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), msg, NULL, rsa,
  74771. RSA_PKCS1_PADDING), -1);
  74772. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), msg, encMsg, NULL,
  74773. RSA_PKCS1_PADDING), -1);
  74774. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), msg, encMsg, rsa,
  74775. RSA_PKCS1_PSS_PADDING), -1);
  74776. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), msg, encMsg, rsa,
  74777. RSA_PKCS1_PADDING), sizeof(encMsg));
  74778. ExpectIntEQ(XMEMCMP(encMsg, expEncMsg, sizeof(expEncMsg)), 0);
  74779. #ifdef WC_RSA_NO_PADDING
  74780. /* Non-zero message. */
  74781. XMEMSET(msg, 0x01, sizeof(msg));
  74782. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), msg, encMsg, rsa,
  74783. RSA_NO_PADDING), sizeof(encMsg));
  74784. ExpectIntEQ(XMEMCMP(encMsg, expEncMsgNoPad, sizeof(expEncMsgNoPad)), 0);
  74785. #endif
  74786. RSA_free(rsa);
  74787. #endif
  74788. return EXPECT_RESULT();
  74789. }
  74790. static int test_wolfSSL_RSA_public_encrypt(void)
  74791. {
  74792. EXPECT_DECLS;
  74793. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74794. RSA* rsa = NULL;
  74795. const unsigned char msg[2048/8] = { 0 };
  74796. unsigned char encMsg[2048/8];
  74797. ExpectNotNull(rsa = RSA_new());
  74798. ExpectIntEQ(RSA_public_encrypt(-1, msg, encMsg, rsa,
  74799. RSA_PKCS1_PADDING), -1);
  74800. ExpectIntEQ(RSA_public_encrypt(sizeof(msg), NULL, encMsg, rsa,
  74801. RSA_PKCS1_PADDING), -1);
  74802. ExpectIntEQ(RSA_public_encrypt(sizeof(msg), msg, NULL, rsa,
  74803. RSA_PKCS1_PADDING), -1);
  74804. ExpectIntEQ(RSA_public_encrypt(sizeof(msg), msg, encMsg, NULL,
  74805. RSA_PKCS1_PADDING), -1);
  74806. ExpectIntEQ(RSA_public_encrypt(sizeof(msg), msg, encMsg, rsa,
  74807. RSA_PKCS1_PSS_PADDING), -1);
  74808. /* Empty RSA key. */
  74809. ExpectIntEQ(RSA_public_encrypt(sizeof(msg), msg, encMsg, rsa,
  74810. RSA_PKCS1_PADDING), -1);
  74811. RSA_free(rsa);
  74812. #endif
  74813. return EXPECT_RESULT();
  74814. }
  74815. static int test_wolfSSL_RSA_private_decrypt(void)
  74816. {
  74817. EXPECT_DECLS;
  74818. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74819. RSA* rsa = NULL;
  74820. unsigned char msg[2048/8];
  74821. const unsigned char encMsg[2048/8] = { 0 };
  74822. ExpectNotNull(rsa = RSA_new());
  74823. ExpectIntEQ(RSA_private_decrypt(-1, encMsg, msg, rsa,
  74824. RSA_PKCS1_PADDING), -1);
  74825. ExpectIntEQ(RSA_private_decrypt(sizeof(encMsg), NULL, msg, rsa,
  74826. RSA_PKCS1_PADDING), -1);
  74827. ExpectIntEQ(RSA_private_decrypt(sizeof(encMsg), encMsg, NULL, rsa,
  74828. RSA_PKCS1_PADDING), -1);
  74829. ExpectIntEQ(RSA_private_decrypt(sizeof(encMsg), encMsg, msg, NULL,
  74830. RSA_PKCS1_PADDING), -1);
  74831. ExpectIntEQ(RSA_private_decrypt(sizeof(encMsg), encMsg, msg, rsa,
  74832. RSA_PKCS1_PSS_PADDING), -1);
  74833. /* Empty RSA key. */
  74834. ExpectIntEQ(RSA_private_decrypt(sizeof(encMsg), encMsg, msg, rsa,
  74835. RSA_PKCS1_PADDING), -1);
  74836. RSA_free(rsa);
  74837. #endif
  74838. return EXPECT_RESULT();
  74839. }
  74840. static int test_wolfSSL_RSA_GenAdd(void)
  74841. {
  74842. EXPECT_DECLS;
  74843. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74844. RSA *rsa;
  74845. #ifdef USE_CERT_BUFFERS_1024
  74846. const unsigned char* privDer = client_key_der_1024;
  74847. size_t privDerSz = sizeof_client_key_der_1024;
  74848. const unsigned char* pubDer = client_keypub_der_1024;
  74849. size_t pubDerSz = sizeof_client_keypub_der_1024;
  74850. #else
  74851. const unsigned char* privDer = client_key_der_2048;
  74852. size_t privDerSz = sizeof_client_key_der_2048;
  74853. const unsigned char* pubDer = client_keypub_der_2048;
  74854. size_t pubDerSz = sizeof_client_keypub_der_2048;
  74855. #endif
  74856. const unsigned char* der;
  74857. der = privDer;
  74858. rsa = NULL;
  74859. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  74860. ExpectIntEQ(wolfSSL_RSA_GenAdd(NULL), -1);
  74861. #ifndef RSA_LOW_MEM
  74862. ExpectIntEQ(wolfSSL_RSA_GenAdd(rsa), 1);
  74863. #else
  74864. /* dmp1 and dmq1 are not set (allocated) when RSA_LOW_MEM. */
  74865. ExpectIntEQ(wolfSSL_RSA_GenAdd(rsa), -1);
  74866. #endif
  74867. RSA_free(rsa);
  74868. der = pubDer;
  74869. rsa = NULL;
  74870. ExpectNotNull(d2i_RSAPublicKey(&rsa, &der, pubDerSz));
  74871. /* Need private values. */
  74872. ExpectIntEQ(wolfSSL_RSA_GenAdd(rsa), -1);
  74873. RSA_free(rsa);
  74874. #endif
  74875. return EXPECT_RESULT();
  74876. }
  74877. static int test_wolfSSL_RSA_blinding_on(void)
  74878. {
  74879. EXPECT_DECLS;
  74880. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_WOLFSSL_STUB)
  74881. RSA *rsa;
  74882. WOLFSSL_BN_CTX *bnCtx = NULL;
  74883. #ifdef USE_CERT_BUFFERS_1024
  74884. const unsigned char* privDer = client_key_der_1024;
  74885. size_t privDerSz = sizeof_client_key_der_1024;
  74886. #else
  74887. const unsigned char* privDer = client_key_der_2048;
  74888. size_t privDerSz = sizeof_client_key_der_2048;
  74889. #endif
  74890. const unsigned char* der;
  74891. der = privDer;
  74892. rsa = NULL;
  74893. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  74894. ExpectNotNull(bnCtx = wolfSSL_BN_CTX_new());
  74895. /* Does nothing so all parameters are valid. */
  74896. ExpectIntEQ(wolfSSL_RSA_blinding_on(NULL, NULL), 1);
  74897. ExpectIntEQ(wolfSSL_RSA_blinding_on(rsa, NULL), 1);
  74898. ExpectIntEQ(wolfSSL_RSA_blinding_on(NULL, bnCtx), 1);
  74899. ExpectIntEQ(wolfSSL_RSA_blinding_on(rsa, bnCtx), 1);
  74900. wolfSSL_BN_CTX_free(bnCtx);
  74901. RSA_free(rsa);
  74902. #endif
  74903. return EXPECT_RESULT();
  74904. }
  74905. static int test_wolfSSL_RSA_ex_data(void)
  74906. {
  74907. EXPECT_DECLS;
  74908. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA)
  74909. RSA* rsa = NULL;
  74910. unsigned char data[1];
  74911. ExpectNotNull(rsa = RSA_new());
  74912. ExpectNull(wolfSSL_RSA_get_ex_data(NULL, 0));
  74913. ExpectNull(wolfSSL_RSA_get_ex_data(rsa, 0));
  74914. #ifdef MAX_EX_DATA
  74915. ExpectNull(wolfSSL_RSA_get_ex_data(rsa, MAX_EX_DATA));
  74916. ExpectIntEQ(wolfSSL_RSA_set_ex_data(rsa, MAX_EX_DATA, data), 0);
  74917. #endif
  74918. ExpectIntEQ(wolfSSL_RSA_set_ex_data(NULL, 0, NULL), 0);
  74919. ExpectIntEQ(wolfSSL_RSA_set_ex_data(NULL, 0, data), 0);
  74920. #ifdef HAVE_EX_DATA
  74921. ExpectIntEQ(wolfSSL_RSA_set_ex_data(rsa, 0, NULL), 1);
  74922. ExpectIntEQ(wolfSSL_RSA_set_ex_data(rsa, 0, data), 1);
  74923. ExpectPtrEq(wolfSSL_RSA_get_ex_data(rsa, 0), data);
  74924. #else
  74925. ExpectIntEQ(wolfSSL_RSA_set_ex_data(rsa, 0, NULL), 0);
  74926. ExpectIntEQ(wolfSSL_RSA_set_ex_data(rsa, 0, data), 0);
  74927. ExpectNull(wolfSSL_RSA_get_ex_data(rsa, 0));
  74928. #endif
  74929. RSA_free(rsa);
  74930. #endif /* !NO_RSA && OPENSSL_EXTRA */
  74931. return EXPECT_RESULT();
  74932. }
  74933. static int test_wolfSSL_RSA_LoadDer(void)
  74934. {
  74935. EXPECT_DECLS;
  74936. #if !defined(NO_RSA) && (defined(OPENSSL_EXTRA) || \
  74937. defined(OPENSSL_EXTRA_X509_SMALL))
  74938. RSA *rsa = NULL;
  74939. #ifdef USE_CERT_BUFFERS_1024
  74940. const unsigned char* privDer = client_key_der_1024;
  74941. size_t privDerSz = sizeof_client_key_der_1024;
  74942. #else
  74943. const unsigned char* privDer = client_key_der_2048;
  74944. size_t privDerSz = sizeof_client_key_der_2048;
  74945. #endif
  74946. ExpectNotNull(rsa = RSA_new());
  74947. ExpectIntEQ(wolfSSL_RSA_LoadDer(NULL, privDer, (int)privDerSz), -1);
  74948. ExpectIntEQ(wolfSSL_RSA_LoadDer(rsa, NULL, (int)privDerSz), -1);
  74949. ExpectIntEQ(wolfSSL_RSA_LoadDer(rsa, privDer, 0), -1);
  74950. ExpectIntEQ(wolfSSL_RSA_LoadDer(rsa, privDer, (int)privDerSz), 1);
  74951. RSA_free(rsa);
  74952. #endif /* !NO_RSA && OPENSSL_EXTRA */
  74953. return EXPECT_RESULT();
  74954. }
  74955. /* Local API. */
  74956. static int test_wolfSSL_RSA_To_Der(void)
  74957. {
  74958. EXPECT_DECLS;
  74959. #ifdef WOLFSSL_TEST_STATIC_BUILD
  74960. #if defined(WOLFSSL_KEY_GEN) && defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  74961. RSA* rsa;
  74962. #ifdef USE_CERT_BUFFERS_1024
  74963. const unsigned char* privDer = client_key_der_1024;
  74964. size_t privDerSz = sizeof_client_key_der_1024;
  74965. const unsigned char* pubDer = client_keypub_der_1024;
  74966. size_t pubDerSz = sizeof_client_keypub_der_1024;
  74967. unsigned char out[sizeof(client_key_der_1024)];
  74968. #else
  74969. const unsigned char* privDer = client_key_der_2048;
  74970. size_t privDerSz = sizeof_client_key_der_2048;
  74971. const unsigned char* pubDer = client_keypub_der_2048;
  74972. size_t pubDerSz = sizeof_client_keypub_der_2048;
  74973. unsigned char out[sizeof(client_key_der_2048)];
  74974. #endif
  74975. const unsigned char* der;
  74976. unsigned char* outDer = NULL;
  74977. der = privDer;
  74978. rsa = NULL;
  74979. ExpectNotNull(wolfSSL_d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  74980. ExpectIntEQ(wolfSSL_RSA_To_Der(NULL, &outDer, 0, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  74981. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 2, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  74982. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, NULL, 0, HEAP_HINT), privDerSz);
  74983. outDer = out;
  74984. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 0, HEAP_HINT), privDerSz);
  74985. ExpectIntEQ(XMEMCMP(out, privDer, privDerSz), 0);
  74986. outDer = NULL;
  74987. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 0, HEAP_HINT), privDerSz);
  74988. ExpectNotNull(outDer);
  74989. ExpectIntEQ(XMEMCMP(outDer, privDer, privDerSz), 0);
  74990. XFREE(outDer, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  74991. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, NULL, 1, HEAP_HINT), pubDerSz);
  74992. outDer = out;
  74993. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 1, HEAP_HINT), pubDerSz);
  74994. ExpectIntEQ(XMEMCMP(out, pubDer, pubDerSz), 0);
  74995. RSA_free(rsa);
  74996. ExpectNotNull(rsa = RSA_new());
  74997. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 0, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  74998. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 1, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  74999. RSA_free(rsa);
  75000. der = pubDer;
  75001. rsa = NULL;
  75002. ExpectNotNull(wolfSSL_d2i_RSAPublicKey(&rsa, &der, pubDerSz));
  75003. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 0, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  75004. RSA_free(rsa);
  75005. #endif
  75006. #endif
  75007. return EXPECT_RESULT();
  75008. }
  75009. /* wolfSSL_PEM_read_RSAPublicKey is a stub function. */
  75010. static int test_wolfSSL_PEM_read_RSAPublicKey(void)
  75011. {
  75012. EXPECT_DECLS;
  75013. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM)
  75014. XFILE file = XBADFILE;
  75015. const char* fname = "./certs/server-keyPub.pem";
  75016. RSA *rsa = NULL;
  75017. ExpectNull(wolfSSL_PEM_read_RSAPublicKey(XBADFILE, NULL, NULL, NULL));
  75018. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  75019. ExpectNotNull(rsa = PEM_read_RSA_PUBKEY(file, NULL, NULL, NULL));
  75020. ExpectIntEQ(RSA_size(rsa), 256);
  75021. RSA_free(rsa);
  75022. if (file != XBADFILE)
  75023. XFCLOSE(file);
  75024. #endif
  75025. return EXPECT_RESULT();
  75026. }
  75027. /* wolfSSL_PEM_read_RSAPublicKey is a stub function. */
  75028. static int test_wolfSSL_PEM_write_RSA_PUBKEY(void)
  75029. {
  75030. EXPECT_DECLS;
  75031. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && \
  75032. defined(WOLFSSL_KEY_GEN)
  75033. RSA* rsa = NULL;
  75034. ExpectIntEQ(wolfSSL_PEM_write_RSA_PUBKEY(XBADFILE, NULL), 0);
  75035. ExpectIntEQ(wolfSSL_PEM_write_RSA_PUBKEY(stderr, NULL), 0);
  75036. /* Valid but stub so returns 0. */
  75037. ExpectIntEQ(wolfSSL_PEM_write_RSA_PUBKEY(stderr, rsa), 0);
  75038. #endif
  75039. return EXPECT_RESULT();
  75040. }
  75041. static int test_wolfSSL_PEM_write_RSAPrivateKey(void)
  75042. {
  75043. EXPECT_DECLS;
  75044. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN) && \
  75045. (defined(WOLFSSL_PEM_TO_DER) || \
  75046. defined(WOLFSSL_DER_TO_PEM)) && !defined(NO_FILESYSTEM)
  75047. RSA* rsa = NULL;
  75048. #ifdef USE_CERT_BUFFERS_1024
  75049. const unsigned char* privDer = client_key_der_1024;
  75050. size_t privDerSz = sizeof_client_key_der_1024;
  75051. #else
  75052. const unsigned char* privDer = client_key_der_2048;
  75053. size_t privDerSz = sizeof_client_key_der_2048;
  75054. #endif
  75055. const unsigned char* der;
  75056. #ifndef NO_AES
  75057. unsigned char passwd[] = "password";
  75058. #endif
  75059. ExpectNotNull(rsa = RSA_new());
  75060. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(stderr, rsa, NULL, NULL, 0,
  75061. NULL, NULL), 0);
  75062. RSA_free(rsa);
  75063. der = privDer;
  75064. rsa = NULL;
  75065. ExpectNotNull(wolfSSL_d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  75066. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(XBADFILE, rsa, NULL, NULL, 0,
  75067. NULL, NULL), 0);
  75068. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(stderr, NULL, NULL, NULL, 0,
  75069. NULL, NULL), 0);
  75070. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(stderr, rsa, NULL, NULL, 0,
  75071. NULL, NULL), 1);
  75072. #ifndef NO_AES
  75073. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(stderr, rsa, EVP_aes_128_cbc(),
  75074. NULL, 0, NULL, NULL), 1);
  75075. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(stderr, rsa, EVP_aes_128_cbc(),
  75076. passwd, sizeof(passwd) - 1, NULL, NULL), 1);
  75077. #endif
  75078. RSA_free(rsa);
  75079. #endif
  75080. return EXPECT_RESULT();
  75081. }
  75082. static int test_wolfSSL_PEM_write_mem_RSAPrivateKey(void)
  75083. {
  75084. EXPECT_DECLS;
  75085. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN) && \
  75086. (defined(WOLFSSL_PEM_TO_DER) || defined(WOLFSSL_DER_TO_PEM))
  75087. RSA* rsa = NULL;
  75088. #ifdef USE_CERT_BUFFERS_1024
  75089. const unsigned char* privDer = client_key_der_1024;
  75090. size_t privDerSz = sizeof_client_key_der_1024;
  75091. #else
  75092. const unsigned char* privDer = client_key_der_2048;
  75093. size_t privDerSz = sizeof_client_key_der_2048;
  75094. #endif
  75095. const unsigned char* der;
  75096. #ifndef NO_AES
  75097. unsigned char passwd[] = "password";
  75098. #endif
  75099. unsigned char* pem = NULL;
  75100. int plen;
  75101. ExpectNotNull(rsa = RSA_new());
  75102. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, NULL, NULL, 0, &pem,
  75103. &plen), 0);
  75104. RSA_free(rsa);
  75105. der = privDer;
  75106. rsa = NULL;
  75107. ExpectNotNull(wolfSSL_d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  75108. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(NULL, NULL, NULL, 0, &pem,
  75109. &plen), 0);
  75110. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, NULL, NULL, 0, NULL,
  75111. &plen), 0);
  75112. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, NULL, NULL, 0, &pem,
  75113. NULL), 0);
  75114. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, NULL, NULL, 0, &pem,
  75115. &plen), 1);
  75116. XFREE(pem, NULL, DYNAMIC_TYPE_KEY);
  75117. pem = NULL;
  75118. #ifndef NO_AES
  75119. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, EVP_aes_128_cbc(),
  75120. NULL, 0, &pem, &plen), 1);
  75121. XFREE(pem, NULL, DYNAMIC_TYPE_KEY);
  75122. pem = NULL;
  75123. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, EVP_aes_128_cbc(),
  75124. passwd, sizeof(passwd) - 1, &pem, &plen), 1);
  75125. XFREE(pem, NULL, DYNAMIC_TYPE_KEY);
  75126. #endif
  75127. RSA_free(rsa);
  75128. #endif
  75129. return EXPECT_RESULT();
  75130. }
  75131. static int test_wolfSSL_DH(void)
  75132. {
  75133. EXPECT_DECLS;
  75134. #if defined(OPENSSL_EXTRA) && !defined(NO_DH)
  75135. DH *dh = NULL;
  75136. BIGNUM* p;
  75137. BIGNUM* q;
  75138. BIGNUM* g;
  75139. BIGNUM* pub = NULL;
  75140. BIGNUM* priv = NULL;
  75141. #if defined(OPENSSL_ALL)
  75142. #if !defined(HAVE_FIPS) || \
  75143. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  75144. FILE* f = NULL;
  75145. unsigned char buf[268];
  75146. const unsigned char* pt = buf;
  75147. long len = 0;
  75148. dh = NULL;
  75149. XMEMSET(buf, 0, sizeof(buf));
  75150. /* Test 2048 bit parameters */
  75151. ExpectTrue((f = XFOPEN("./certs/dh2048.der", "rb")) != XBADFILE);
  75152. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  75153. if (f != XBADFILE)
  75154. XFCLOSE(f);
  75155. ExpectNotNull(dh = d2i_DHparams(NULL, &pt, len));
  75156. ExpectNotNull(dh->p);
  75157. ExpectNotNull(dh->g);
  75158. ExpectTrue(pt == buf);
  75159. ExpectIntEQ(DH_generate_key(dh), 1);
  75160. /* first, test for expected successful key agreement. */
  75161. if (EXPECT_SUCCESS()) {
  75162. DH *dh2 = NULL;
  75163. unsigned char buf2[268];
  75164. int sz1 = 0, sz2 = 0;
  75165. ExpectNotNull(dh2 = d2i_DHparams(NULL, &pt, len));
  75166. ExpectIntEQ(DH_generate_key(dh2), 1);
  75167. ExpectIntGT(sz1=DH_compute_key(buf, dh2->pub_key, dh), 0);
  75168. ExpectIntGT(sz2=DH_compute_key(buf2, dh->pub_key, dh2), 0);
  75169. ExpectIntEQ(sz1, sz2);
  75170. ExpectIntEQ(XMEMCMP(buf, buf2, (size_t)sz1), 0);
  75171. ExpectIntNE(sz1 = DH_size(dh), 0);
  75172. ExpectIntEQ(DH_compute_key_padded(buf, dh2->pub_key, dh), sz1);
  75173. ExpectIntEQ(DH_compute_key_padded(buf2, dh->pub_key, dh2), sz1);
  75174. ExpectIntEQ(XMEMCMP(buf, buf2, (size_t)sz1), 0);
  75175. if (dh2 != NULL)
  75176. DH_free(dh2);
  75177. }
  75178. ExpectIntEQ(DH_generate_key(dh), 1);
  75179. ExpectIntEQ(DH_compute_key(NULL, NULL, NULL), -1);
  75180. ExpectNotNull(pub = BN_new());
  75181. ExpectIntEQ(BN_set_word(pub, 1), 1);
  75182. ExpectIntEQ(DH_compute_key(buf, NULL, NULL), -1);
  75183. ExpectIntEQ(DH_compute_key(NULL, pub, NULL), -1);
  75184. ExpectIntEQ(DH_compute_key(NULL, NULL, dh), -1);
  75185. ExpectIntEQ(DH_compute_key(buf, pub, NULL), -1);
  75186. ExpectIntEQ(DH_compute_key(buf, NULL, dh), -1);
  75187. ExpectIntEQ(DH_compute_key(NULL, pub, dh), -1);
  75188. ExpectIntEQ(DH_compute_key(buf, pub, dh), -1);
  75189. BN_free(pub);
  75190. pub = NULL;
  75191. DH_get0_pqg(dh, (const BIGNUM**)&p,
  75192. (const BIGNUM**)&q,
  75193. (const BIGNUM**)&g);
  75194. ExpectPtrEq(p, dh->p);
  75195. ExpectPtrEq(q, dh->q);
  75196. ExpectPtrEq(g, dh->g);
  75197. DH_get0_key(NULL, (const BIGNUM**)&pub, (const BIGNUM**)&priv);
  75198. DH_get0_key(dh, (const BIGNUM**)&pub, (const BIGNUM**)&priv);
  75199. ExpectPtrEq(pub, dh->pub_key);
  75200. ExpectPtrEq(priv, dh->priv_key);
  75201. DH_get0_key(dh, (const BIGNUM**)&pub, NULL);
  75202. ExpectPtrEq(pub, dh->pub_key);
  75203. DH_get0_key(dh, NULL, (const BIGNUM**)&priv);
  75204. ExpectPtrEq(priv, dh->priv_key);
  75205. pub = NULL;
  75206. priv = NULL;
  75207. ExpectNotNull(pub = BN_new());
  75208. ExpectNotNull(priv = BN_new());
  75209. ExpectIntEQ(DH_set0_key(NULL, pub, priv), 0);
  75210. ExpectIntEQ(DH_set0_key(dh, pub, priv), 1);
  75211. if (EXPECT_FAIL()) {
  75212. BN_free(pub);
  75213. BN_free(priv);
  75214. }
  75215. pub = NULL;
  75216. priv = NULL;
  75217. ExpectNotNull(pub = BN_new());
  75218. ExpectIntEQ(DH_set0_key(dh, pub, NULL), 1);
  75219. if (EXPECT_FAIL()) {
  75220. BN_free(pub);
  75221. }
  75222. ExpectNotNull(priv = BN_new());
  75223. ExpectIntEQ(DH_set0_key(dh, NULL, priv), 1);
  75224. if (EXPECT_FAIL()) {
  75225. BN_free(priv);
  75226. }
  75227. ExpectPtrEq(pub, dh->pub_key);
  75228. ExpectPtrEq(priv, dh->priv_key);
  75229. pub = NULL;
  75230. priv = NULL;
  75231. DH_free(dh);
  75232. dh = NULL;
  75233. ExpectNotNull(dh = DH_new());
  75234. p = NULL;
  75235. ExpectNotNull(p = BN_new());
  75236. ExpectIntEQ(BN_set_word(p, 1), 1);
  75237. ExpectIntEQ(DH_compute_key(buf, p, dh), -1);
  75238. ExpectNotNull(pub = BN_new());
  75239. ExpectNotNull(priv = BN_new());
  75240. ExpectIntEQ(DH_set0_key(dh, pub, priv), 1);
  75241. if (EXPECT_FAIL()) {
  75242. BN_free(pub);
  75243. BN_free(priv);
  75244. }
  75245. pub = NULL;
  75246. priv = NULL;
  75247. ExpectIntEQ(DH_compute_key(buf, p, dh), -1);
  75248. BN_free(p);
  75249. p = NULL;
  75250. DH_free(dh);
  75251. dh = NULL;
  75252. #ifdef WOLFSSL_KEY_GEN
  75253. ExpectNotNull(dh = DH_generate_parameters(2048, 2, NULL, NULL));
  75254. ExpectIntEQ(wolfSSL_DH_generate_parameters_ex(NULL, 2048, 2, NULL), 0);
  75255. DH_free(dh);
  75256. dh = NULL;
  75257. #endif
  75258. #endif /* !HAVE_FIPS || (HAVE_FIPS_VERSION && HAVE_FIPS_VERSION > 2) */
  75259. #endif /* OPENSSL_ALL */
  75260. (void)dh;
  75261. (void)p;
  75262. (void)q;
  75263. (void)g;
  75264. (void)pub;
  75265. (void)priv;
  75266. ExpectNotNull(dh = wolfSSL_DH_new());
  75267. /* invalid parameters test */
  75268. DH_get0_pqg(NULL, (const BIGNUM**)&p,
  75269. (const BIGNUM**)&q,
  75270. (const BIGNUM**)&g);
  75271. DH_get0_pqg(dh, NULL,
  75272. (const BIGNUM**)&q,
  75273. (const BIGNUM**)&g);
  75274. DH_get0_pqg(dh, NULL, NULL, (const BIGNUM**)&g);
  75275. DH_get0_pqg(dh, NULL, NULL, NULL);
  75276. DH_get0_pqg(dh, (const BIGNUM**)&p,
  75277. (const BIGNUM**)&q,
  75278. (const BIGNUM**)&g);
  75279. ExpectPtrEq(p, NULL);
  75280. ExpectPtrEq(q, NULL);
  75281. ExpectPtrEq(g, NULL);
  75282. DH_free(dh);
  75283. dh = NULL;
  75284. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS) && !defined(WOLFSSL_DH_EXTRA)) \
  75285. || (defined(HAVE_FIPS_VERSION) && FIPS_VERSION_GT(2,0))
  75286. #if defined(OPENSSL_ALL) || \
  75287. defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
  75288. dh = wolfSSL_DH_new();
  75289. ExpectNotNull(dh);
  75290. p = wolfSSL_BN_new();
  75291. ExpectNotNull(p);
  75292. ExpectIntEQ(BN_set_word(p, 11), 1);
  75293. g = wolfSSL_BN_new();
  75294. ExpectNotNull(g);
  75295. ExpectIntEQ(BN_set_word(g, 2), 1);
  75296. q = wolfSSL_BN_new();
  75297. ExpectNotNull(q);
  75298. ExpectIntEQ(BN_set_word(q, 5), 1);
  75299. ExpectIntEQ(wolfSSL_DH_set0_pqg(NULL, NULL, NULL, NULL), 0);
  75300. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, NULL, NULL, NULL), 0);
  75301. ExpectIntEQ(wolfSSL_DH_set0_pqg(NULL, p, NULL, NULL), 0);
  75302. ExpectIntEQ(wolfSSL_DH_set0_pqg(NULL, NULL, q, NULL), 0);
  75303. ExpectIntEQ(wolfSSL_DH_set0_pqg(NULL, NULL, NULL, g), 0);
  75304. ExpectIntEQ(wolfSSL_DH_set0_pqg(NULL, p, q, g), 0);
  75305. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, NULL, q, g), 0);
  75306. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, q, NULL), 0);
  75307. /* Don't need q. */
  75308. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, NULL, g), 1);
  75309. if (EXPECT_FAIL()) {
  75310. BN_free(p);
  75311. BN_free(g);
  75312. }
  75313. p = NULL;
  75314. g = NULL;
  75315. /* Setting again will free the p and g. */
  75316. wolfSSL_BN_free(q);
  75317. q = NULL;
  75318. DH_free(dh);
  75319. dh = NULL;
  75320. dh = wolfSSL_DH_new();
  75321. ExpectNotNull(dh);
  75322. p = wolfSSL_BN_new();
  75323. ExpectNotNull(p);
  75324. ExpectIntEQ(BN_set_word(p, 11), 1);
  75325. g = wolfSSL_BN_new();
  75326. ExpectNotNull(g);
  75327. ExpectIntEQ(BN_set_word(g, 2), 1);
  75328. q = wolfSSL_BN_new();
  75329. ExpectNotNull(q);
  75330. ExpectIntEQ(BN_set_word(q, 5), 1);
  75331. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, q, g), 1);
  75332. /* p, q and g are now owned by dh - don't free. */
  75333. if (EXPECT_FAIL()) {
  75334. BN_free(p);
  75335. BN_free(q);
  75336. BN_free(g);
  75337. }
  75338. p = NULL;
  75339. q = NULL;
  75340. g = NULL;
  75341. p = wolfSSL_BN_new();
  75342. ExpectNotNull(p);
  75343. ExpectIntEQ(BN_set_word(p, 11), 1);
  75344. g = wolfSSL_BN_new();
  75345. ExpectNotNull(g);
  75346. ExpectIntEQ(BN_set_word(g, 2), 1);
  75347. q = wolfSSL_BN_new();
  75348. ExpectNotNull(q);
  75349. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, NULL, NULL), 1);
  75350. if (EXPECT_FAIL()) {
  75351. BN_free(p);
  75352. }
  75353. p = NULL;
  75354. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, NULL, q, NULL), 1);
  75355. if (EXPECT_FAIL()) {
  75356. BN_free(q);
  75357. }
  75358. q = NULL;
  75359. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, NULL, NULL, g), 1);
  75360. if (EXPECT_FAIL()) {
  75361. BN_free(g);
  75362. }
  75363. g = NULL;
  75364. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, NULL, NULL, NULL), 1);
  75365. /* p, q and g are now owned by dh - don't free. */
  75366. DH_free(dh);
  75367. dh = NULL;
  75368. ExpectIntEQ(DH_generate_key(NULL), 0);
  75369. ExpectNotNull(dh = DH_new());
  75370. ExpectIntEQ(DH_generate_key(dh), 0);
  75371. p = wolfSSL_BN_new();
  75372. ExpectNotNull(p);
  75373. ExpectIntEQ(BN_set_word(p, 0), 1);
  75374. g = wolfSSL_BN_new();
  75375. ExpectNotNull(g);
  75376. ExpectIntEQ(BN_set_word(g, 2), 1);
  75377. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, NULL, g), 1);
  75378. if (EXPECT_FAIL()) {
  75379. BN_free(p);
  75380. BN_free(g);
  75381. }
  75382. p = NULL;
  75383. g = NULL;
  75384. ExpectIntEQ(DH_generate_key(dh), 0);
  75385. DH_free(dh);
  75386. dh = NULL;
  75387. #endif
  75388. #endif
  75389. /* Test DH_up_ref() */
  75390. dh = wolfSSL_DH_new();
  75391. ExpectNotNull(dh);
  75392. ExpectIntEQ(wolfSSL_DH_up_ref(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  75393. ExpectIntEQ(wolfSSL_DH_up_ref(dh), WOLFSSL_SUCCESS);
  75394. DH_free(dh); /* decrease ref count */
  75395. DH_free(dh); /* free WOLFSSL_DH */
  75396. dh = NULL;
  75397. q = NULL;
  75398. ExpectNull((dh = DH_new_by_nid(NID_sha1)));
  75399. #if (defined(HAVE_PUBLIC_FFDHE) || (defined(HAVE_FIPS) && \
  75400. FIPS_VERSION_EQ(2,0))) || (!defined(HAVE_PUBLIC_FFDHE) && \
  75401. (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0)))
  75402. #ifdef HAVE_FFDHE_2048
  75403. ExpectNotNull((dh = DH_new_by_nid(NID_ffdhe2048)));
  75404. DH_free(dh);
  75405. dh = NULL;
  75406. q = NULL;
  75407. #endif
  75408. #ifdef HAVE_FFDHE_3072
  75409. ExpectNotNull((dh = DH_new_by_nid(NID_ffdhe3072)));
  75410. DH_free(dh);
  75411. dh = NULL;
  75412. q = NULL;
  75413. #endif
  75414. #ifdef HAVE_FFDHE_4096
  75415. ExpectNotNull((dh = DH_new_by_nid(NID_ffdhe4096)));
  75416. DH_free(dh);
  75417. dh = NULL;
  75418. q = NULL;
  75419. #endif
  75420. #else
  75421. ExpectNull((dh = DH_new_by_nid(NID_ffdhe2048)));
  75422. #endif /* (HAVE_PUBLIC_FFDHE || (HAVE_FIPS && HAVE_FIPS_VERSION == 2)) ||
  75423. * (!HAVE_PUBLIC_FFDHE && (!HAVE_FIPS || HAVE_FIPS_VERSION > 2))*/
  75424. ExpectIntEQ(wolfSSL_DH_size(NULL), -1);
  75425. #endif /* OPENSSL_EXTRA && !NO_DH */
  75426. return EXPECT_RESULT();
  75427. }
  75428. static int test_wolfSSL_DH_dup(void)
  75429. {
  75430. EXPECT_DECLS;
  75431. #if !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA)
  75432. #if defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || defined(WOLFSSL_OPENSSH) || \
  75433. defined(OPENSSL_EXTRA)
  75434. DH *dh = NULL;
  75435. DH *dhDup = NULL;
  75436. ExpectNotNull(dh = wolfSSL_DH_new());
  75437. ExpectNull(dhDup = wolfSSL_DH_dup(NULL));
  75438. ExpectNull(dhDup = wolfSSL_DH_dup(dh));
  75439. #if defined(OPENSSL_ALL) || \
  75440. defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
  75441. {
  75442. WOLFSSL_BIGNUM* p = NULL;
  75443. WOLFSSL_BIGNUM* g = NULL;
  75444. ExpectNotNull(p = wolfSSL_BN_new());
  75445. ExpectNotNull(g = wolfSSL_BN_new());
  75446. ExpectIntEQ(wolfSSL_BN_set_word(p, 11), WOLFSSL_SUCCESS);
  75447. ExpectIntEQ(wolfSSL_BN_set_word(g, 2), WOLFSSL_SUCCESS);
  75448. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, NULL, g), 1);
  75449. if (EXPECT_FAIL()) {
  75450. wolfSSL_BN_free(p);
  75451. wolfSSL_BN_free(g);
  75452. }
  75453. ExpectNotNull(dhDup = wolfSSL_DH_dup(dh));
  75454. wolfSSL_DH_free(dhDup);
  75455. }
  75456. #endif
  75457. wolfSSL_DH_free(dh);
  75458. #endif
  75459. #endif
  75460. return EXPECT_RESULT();
  75461. }
  75462. static int test_wolfSSL_DH_check(void)
  75463. {
  75464. EXPECT_DECLS;
  75465. #ifdef OPENSSL_ALL
  75466. #ifndef NO_DH
  75467. #ifndef NO_BIO
  75468. #ifndef NO_DSA
  75469. byte buf[6000];
  75470. char file[] = "./certs/dsaparams.pem";
  75471. XFILE f = XBADFILE;
  75472. int bytes;
  75473. BIO* bio = NULL;
  75474. DSA* dsa = NULL;
  75475. #elif !defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0)
  75476. static const byte dh2048[] = {
  75477. 0x30, 0x82, 0x01, 0x08, 0x02, 0x82, 0x01, 0x01,
  75478. 0x00, 0xb0, 0xa1, 0x08, 0x06, 0x9c, 0x08, 0x13,
  75479. 0xba, 0x59, 0x06, 0x3c, 0xbc, 0x30, 0xd5, 0xf5,
  75480. 0x00, 0xc1, 0x4f, 0x44, 0xa7, 0xd6, 0xef, 0x4a,
  75481. 0xc6, 0x25, 0x27, 0x1c, 0xe8, 0xd2, 0x96, 0x53,
  75482. 0x0a, 0x5c, 0x91, 0xdd, 0xa2, 0xc2, 0x94, 0x84,
  75483. 0xbf, 0x7d, 0xb2, 0x44, 0x9f, 0x9b, 0xd2, 0xc1,
  75484. 0x8a, 0xc5, 0xbe, 0x72, 0x5c, 0xa7, 0xe7, 0x91,
  75485. 0xe6, 0xd4, 0x9f, 0x73, 0x07, 0x85, 0x5b, 0x66,
  75486. 0x48, 0xc7, 0x70, 0xfa, 0xb4, 0xee, 0x02, 0xc9,
  75487. 0x3d, 0x9a, 0x4a, 0xda, 0x3d, 0xc1, 0x46, 0x3e,
  75488. 0x19, 0x69, 0xd1, 0x17, 0x46, 0x07, 0xa3, 0x4d,
  75489. 0x9f, 0x2b, 0x96, 0x17, 0x39, 0x6d, 0x30, 0x8d,
  75490. 0x2a, 0xf3, 0x94, 0xd3, 0x75, 0xcf, 0xa0, 0x75,
  75491. 0xe6, 0xf2, 0x92, 0x1f, 0x1a, 0x70, 0x05, 0xaa,
  75492. 0x04, 0x83, 0x57, 0x30, 0xfb, 0xda, 0x76, 0x93,
  75493. 0x38, 0x50, 0xe8, 0x27, 0xfd, 0x63, 0xee, 0x3c,
  75494. 0xe5, 0xb7, 0xc8, 0x09, 0xae, 0x6f, 0x50, 0x35,
  75495. 0x8e, 0x84, 0xce, 0x4a, 0x00, 0xe9, 0x12, 0x7e,
  75496. 0x5a, 0x31, 0xd7, 0x33, 0xfc, 0x21, 0x13, 0x76,
  75497. 0xcc, 0x16, 0x30, 0xdb, 0x0c, 0xfc, 0xc5, 0x62,
  75498. 0xa7, 0x35, 0xb8, 0xef, 0xb7, 0xb0, 0xac, 0xc0,
  75499. 0x36, 0xf6, 0xd9, 0xc9, 0x46, 0x48, 0xf9, 0x40,
  75500. 0x90, 0x00, 0x2b, 0x1b, 0xaa, 0x6c, 0xe3, 0x1a,
  75501. 0xc3, 0x0b, 0x03, 0x9e, 0x1b, 0xc2, 0x46, 0xe4,
  75502. 0x48, 0x4e, 0x22, 0x73, 0x6f, 0xc3, 0x5f, 0xd4,
  75503. 0x9a, 0xd6, 0x30, 0x07, 0x48, 0xd6, 0x8c, 0x90,
  75504. 0xab, 0xd4, 0xf6, 0xf1, 0xe3, 0x48, 0xd3, 0x58,
  75505. 0x4b, 0xa6, 0xb9, 0xcd, 0x29, 0xbf, 0x68, 0x1f,
  75506. 0x08, 0x4b, 0x63, 0x86, 0x2f, 0x5c, 0x6b, 0xd6,
  75507. 0xb6, 0x06, 0x65, 0xf7, 0xa6, 0xdc, 0x00, 0x67,
  75508. 0x6b, 0xbb, 0xc3, 0xa9, 0x41, 0x83, 0xfb, 0xc7,
  75509. 0xfa, 0xc8, 0xe2, 0x1e, 0x7e, 0xaf, 0x00, 0x3f,
  75510. 0x93, 0x02, 0x01, 0x02
  75511. };
  75512. const byte* params;
  75513. #endif
  75514. DH* dh = NULL;
  75515. WOLFSSL_BIGNUM* p = NULL;
  75516. WOLFSSL_BIGNUM* g = NULL;
  75517. WOLFSSL_BIGNUM* pTmp = NULL;
  75518. WOLFSSL_BIGNUM* gTmp = NULL;
  75519. int codes = -1;
  75520. #ifndef NO_DSA
  75521. /* Initialize DH */
  75522. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  75523. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  75524. if (f != XBADFILE)
  75525. XFCLOSE(f);
  75526. ExpectNotNull(bio = BIO_new_mem_buf((void*)buf, bytes));
  75527. ExpectNotNull(dsa = wolfSSL_PEM_read_bio_DSAparams(bio, NULL, NULL, NULL));
  75528. ExpectNotNull(dh = wolfSSL_DSA_dup_DH(dsa));
  75529. ExpectNotNull(dh);
  75530. BIO_free(bio);
  75531. DSA_free(dsa);
  75532. #elif !defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0)
  75533. params = dh2048;
  75534. ExpectNotNull(dh = wolfSSL_d2i_DHparams(NULL, &params,
  75535. (long)sizeof(dh2048)));
  75536. #else
  75537. ExpectNotNull(dh = wolfSSL_DH_new_by_nid(NID_ffdhe2048));
  75538. #endif
  75539. /* Test assumed to be valid dh.
  75540. * Should return WOLFSSL_SUCCESS
  75541. * codes should be 0
  75542. * Invalid codes = {DH_NOT_SUITABLE_GENERATOR, DH_CHECK_P_NOT_PRIME}
  75543. */
  75544. ExpectIntEQ(wolfSSL_DH_check(dh, &codes), 1);
  75545. ExpectIntEQ(codes, 0);
  75546. /* Test NULL dh: expected BAD_FUNC_ARG */
  75547. ExpectIntEQ(wolfSSL_DH_check(NULL, &codes), 0);
  75548. /* Break dh prime to test if codes = DH_CHECK_P_NOT_PRIME */
  75549. if (dh != NULL) {
  75550. pTmp = dh->p;
  75551. dh->p = NULL;
  75552. }
  75553. ExpectIntEQ(wolfSSL_DH_check(dh, &codes), 1);
  75554. ExpectIntEQ(wolfSSL_DH_check(dh, NULL), 0);
  75555. ExpectIntEQ(codes, DH_CHECK_P_NOT_PRIME);
  75556. /* set dh->p back to normal so it won't fail on next tests */
  75557. if (dh != NULL) {
  75558. dh->p = pTmp;
  75559. pTmp = NULL;
  75560. }
  75561. /* Break dh generator to test if codes = DH_NOT_SUITABLE_GENERATOR */
  75562. if (dh != NULL) {
  75563. gTmp = dh->g;
  75564. dh->g = NULL;
  75565. }
  75566. ExpectIntEQ(wolfSSL_DH_check(dh, &codes), 1);
  75567. ExpectIntEQ(wolfSSL_DH_check(dh, NULL), 0);
  75568. ExpectIntEQ(codes, DH_NOT_SUITABLE_GENERATOR);
  75569. if (dh != NULL) {
  75570. dh->g = gTmp;
  75571. gTmp = NULL;
  75572. }
  75573. /* Cleanup */
  75574. DH_free(dh);
  75575. dh = NULL;
  75576. dh = DH_new();
  75577. ExpectNotNull(dh);
  75578. /* Check empty DH. */
  75579. ExpectIntEQ(wolfSSL_DH_check(dh, &codes), 1);
  75580. ExpectIntEQ(wolfSSL_DH_check(dh, NULL), 0);
  75581. ExpectIntEQ(codes, DH_NOT_SUITABLE_GENERATOR | DH_CHECK_P_NOT_PRIME);
  75582. /* Check non-prime valued p. */
  75583. ExpectNotNull(p = BN_new());
  75584. ExpectIntEQ(BN_set_word(p, 4), 1);
  75585. ExpectNotNull(g = BN_new());
  75586. ExpectIntEQ(BN_set_word(g, 2), 1);
  75587. ExpectIntEQ(DH_set0_pqg(dh, p, NULL, g), 1);
  75588. if (EXPECT_FAIL()) {
  75589. wolfSSL_BN_free(p);
  75590. wolfSSL_BN_free(g);
  75591. }
  75592. ExpectIntEQ(wolfSSL_DH_check(dh, &codes), 1);
  75593. ExpectIntEQ(wolfSSL_DH_check(dh, NULL), 0);
  75594. ExpectIntEQ(codes, DH_CHECK_P_NOT_PRIME);
  75595. DH_free(dh);
  75596. dh = NULL;
  75597. #endif
  75598. #endif /* !NO_DH && !NO_DSA */
  75599. #endif
  75600. return EXPECT_RESULT();
  75601. }
  75602. static int test_wolfSSL_DH_prime(void)
  75603. {
  75604. EXPECT_DECLS;
  75605. #if defined(OPENSSL_EXTRA) && !defined(NO_DH)
  75606. WOLFSSL_BIGNUM* bn = NULL;
  75607. #if WOLFSSL_MAX_BN_BITS >= 768
  75608. WOLFSSL_BIGNUM* bn2 = NULL;
  75609. #endif
  75610. bn = wolfSSL_DH_768_prime(NULL);
  75611. #if WOLFSSL_MAX_BN_BITS >= 768
  75612. ExpectNotNull(bn);
  75613. bn2 = wolfSSL_DH_768_prime(bn);
  75614. ExpectNotNull(bn2);
  75615. ExpectTrue(bn == bn2);
  75616. wolfSSL_BN_free(bn);
  75617. bn = NULL;
  75618. #else
  75619. ExpectNull(bn);
  75620. #endif
  75621. bn = wolfSSL_DH_1024_prime(NULL);
  75622. #if WOLFSSL_MAX_BN_BITS >= 1024
  75623. ExpectNotNull(bn);
  75624. wolfSSL_BN_free(bn);
  75625. bn = NULL;
  75626. #else
  75627. ExpectNull(bn);
  75628. #endif
  75629. bn = wolfSSL_DH_2048_prime(NULL);
  75630. #if WOLFSSL_MAX_BN_BITS >= 2048
  75631. ExpectNotNull(bn);
  75632. wolfSSL_BN_free(bn);
  75633. bn = NULL;
  75634. #else
  75635. ExpectNull(bn);
  75636. #endif
  75637. bn = wolfSSL_DH_3072_prime(NULL);
  75638. #if WOLFSSL_MAX_BN_BITS >= 3072
  75639. ExpectNotNull(bn);
  75640. wolfSSL_BN_free(bn);
  75641. bn = NULL;
  75642. #else
  75643. ExpectNull(bn);
  75644. #endif
  75645. bn = wolfSSL_DH_4096_prime(NULL);
  75646. #if WOLFSSL_MAX_BN_BITS >= 4096
  75647. ExpectNotNull(bn);
  75648. wolfSSL_BN_free(bn);
  75649. bn = NULL;
  75650. #else
  75651. ExpectNull(bn);
  75652. #endif
  75653. bn = wolfSSL_DH_6144_prime(NULL);
  75654. #if WOLFSSL_MAX_BN_BITS >= 6144
  75655. ExpectNotNull(bn);
  75656. wolfSSL_BN_free(bn);
  75657. bn = NULL;
  75658. #else
  75659. ExpectNull(bn);
  75660. #endif
  75661. bn = wolfSSL_DH_8192_prime(NULL);
  75662. #if WOLFSSL_MAX_BN_BITS >= 8192
  75663. ExpectNotNull(bn);
  75664. wolfSSL_BN_free(bn);
  75665. bn = NULL;
  75666. #else
  75667. ExpectNull(bn);
  75668. #endif
  75669. #endif
  75670. return EXPECT_RESULT();
  75671. }
  75672. static int test_wolfSSL_DH_1536_prime(void)
  75673. {
  75674. EXPECT_DECLS;
  75675. #if defined(OPENSSL_EXTRA) && !defined(NO_DH)
  75676. BIGNUM* bn = NULL;
  75677. unsigned char bits[200];
  75678. int sz = 192; /* known binary size */
  75679. const byte expected[] = {
  75680. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  75681. 0xC9,0x0F,0xDA,0xA2,0x21,0x68,0xC2,0x34,
  75682. 0xC4,0xC6,0x62,0x8B,0x80,0xDC,0x1C,0xD1,
  75683. 0x29,0x02,0x4E,0x08,0x8A,0x67,0xCC,0x74,
  75684. 0x02,0x0B,0xBE,0xA6,0x3B,0x13,0x9B,0x22,
  75685. 0x51,0x4A,0x08,0x79,0x8E,0x34,0x04,0xDD,
  75686. 0xEF,0x95,0x19,0xB3,0xCD,0x3A,0x43,0x1B,
  75687. 0x30,0x2B,0x0A,0x6D,0xF2,0x5F,0x14,0x37,
  75688. 0x4F,0xE1,0x35,0x6D,0x6D,0x51,0xC2,0x45,
  75689. 0xE4,0x85,0xB5,0x76,0x62,0x5E,0x7E,0xC6,
  75690. 0xF4,0x4C,0x42,0xE9,0xA6,0x37,0xED,0x6B,
  75691. 0x0B,0xFF,0x5C,0xB6,0xF4,0x06,0xB7,0xED,
  75692. 0xEE,0x38,0x6B,0xFB,0x5A,0x89,0x9F,0xA5,
  75693. 0xAE,0x9F,0x24,0x11,0x7C,0x4B,0x1F,0xE6,
  75694. 0x49,0x28,0x66,0x51,0xEC,0xE4,0x5B,0x3D,
  75695. 0xC2,0x00,0x7C,0xB8,0xA1,0x63,0xBF,0x05,
  75696. 0x98,0xDA,0x48,0x36,0x1C,0x55,0xD3,0x9A,
  75697. 0x69,0x16,0x3F,0xA8,0xFD,0x24,0xCF,0x5F,
  75698. 0x83,0x65,0x5D,0x23,0xDC,0xA3,0xAD,0x96,
  75699. 0x1C,0x62,0xF3,0x56,0x20,0x85,0x52,0xBB,
  75700. 0x9E,0xD5,0x29,0x07,0x70,0x96,0x96,0x6D,
  75701. 0x67,0x0C,0x35,0x4E,0x4A,0xBC,0x98,0x04,
  75702. 0xF1,0x74,0x6C,0x08,0xCA,0x23,0x73,0x27,
  75703. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  75704. };
  75705. ExpectNotNull(bn = get_rfc3526_prime_1536(NULL));
  75706. ExpectIntEQ(sz, BN_bn2bin((const BIGNUM*)bn, bits));
  75707. ExpectIntEQ(0, XMEMCMP(expected, bits, sz));
  75708. BN_free(bn);
  75709. #endif
  75710. return EXPECT_RESULT();
  75711. }
  75712. static int test_wolfSSL_DH_get_2048_256(void)
  75713. {
  75714. EXPECT_DECLS;
  75715. #if defined(OPENSSL_EXTRA) && !defined(NO_DH)
  75716. WOLFSSL_DH* dh = NULL;
  75717. const WOLFSSL_BIGNUM* pBn;
  75718. const WOLFSSL_BIGNUM* gBn;
  75719. const WOLFSSL_BIGNUM* qBn;
  75720. const byte pExpected[] = {
  75721. 0x87, 0xA8, 0xE6, 0x1D, 0xB4, 0xB6, 0x66, 0x3C, 0xFF, 0xBB, 0xD1, 0x9C,
  75722. 0x65, 0x19, 0x59, 0x99, 0x8C, 0xEE, 0xF6, 0x08, 0x66, 0x0D, 0xD0, 0xF2,
  75723. 0x5D, 0x2C, 0xEE, 0xD4, 0x43, 0x5E, 0x3B, 0x00, 0xE0, 0x0D, 0xF8, 0xF1,
  75724. 0xD6, 0x19, 0x57, 0xD4, 0xFA, 0xF7, 0xDF, 0x45, 0x61, 0xB2, 0xAA, 0x30,
  75725. 0x16, 0xC3, 0xD9, 0x11, 0x34, 0x09, 0x6F, 0xAA, 0x3B, 0xF4, 0x29, 0x6D,
  75726. 0x83, 0x0E, 0x9A, 0x7C, 0x20, 0x9E, 0x0C, 0x64, 0x97, 0x51, 0x7A, 0xBD,
  75727. 0x5A, 0x8A, 0x9D, 0x30, 0x6B, 0xCF, 0x67, 0xED, 0x91, 0xF9, 0xE6, 0x72,
  75728. 0x5B, 0x47, 0x58, 0xC0, 0x22, 0xE0, 0xB1, 0xEF, 0x42, 0x75, 0xBF, 0x7B,
  75729. 0x6C, 0x5B, 0xFC, 0x11, 0xD4, 0x5F, 0x90, 0x88, 0xB9, 0x41, 0xF5, 0x4E,
  75730. 0xB1, 0xE5, 0x9B, 0xB8, 0xBC, 0x39, 0xA0, 0xBF, 0x12, 0x30, 0x7F, 0x5C,
  75731. 0x4F, 0xDB, 0x70, 0xC5, 0x81, 0xB2, 0x3F, 0x76, 0xB6, 0x3A, 0xCA, 0xE1,
  75732. 0xCA, 0xA6, 0xB7, 0x90, 0x2D, 0x52, 0x52, 0x67, 0x35, 0x48, 0x8A, 0x0E,
  75733. 0xF1, 0x3C, 0x6D, 0x9A, 0x51, 0xBF, 0xA4, 0xAB, 0x3A, 0xD8, 0x34, 0x77,
  75734. 0x96, 0x52, 0x4D, 0x8E, 0xF6, 0xA1, 0x67, 0xB5, 0xA4, 0x18, 0x25, 0xD9,
  75735. 0x67, 0xE1, 0x44, 0xE5, 0x14, 0x05, 0x64, 0x25, 0x1C, 0xCA, 0xCB, 0x83,
  75736. 0xE6, 0xB4, 0x86, 0xF6, 0xB3, 0xCA, 0x3F, 0x79, 0x71, 0x50, 0x60, 0x26,
  75737. 0xC0, 0xB8, 0x57, 0xF6, 0x89, 0x96, 0x28, 0x56, 0xDE, 0xD4, 0x01, 0x0A,
  75738. 0xBD, 0x0B, 0xE6, 0x21, 0xC3, 0xA3, 0x96, 0x0A, 0x54, 0xE7, 0x10, 0xC3,
  75739. 0x75, 0xF2, 0x63, 0x75, 0xD7, 0x01, 0x41, 0x03, 0xA4, 0xB5, 0x43, 0x30,
  75740. 0xC1, 0x98, 0xAF, 0x12, 0x61, 0x16, 0xD2, 0x27, 0x6E, 0x11, 0x71, 0x5F,
  75741. 0x69, 0x38, 0x77, 0xFA, 0xD7, 0xEF, 0x09, 0xCA, 0xDB, 0x09, 0x4A, 0xE9,
  75742. 0x1E, 0x1A, 0x15, 0x97
  75743. };
  75744. const byte gExpected[] = {
  75745. 0x3F, 0xB3, 0x2C, 0x9B, 0x73, 0x13, 0x4D, 0x0B, 0x2E, 0x77, 0x50, 0x66,
  75746. 0x60, 0xED, 0xBD, 0x48, 0x4C, 0xA7, 0xB1, 0x8F, 0x21, 0xEF, 0x20, 0x54,
  75747. 0x07, 0xF4, 0x79, 0x3A, 0x1A, 0x0B, 0xA1, 0x25, 0x10, 0xDB, 0xC1, 0x50,
  75748. 0x77, 0xBE, 0x46, 0x3F, 0xFF, 0x4F, 0xED, 0x4A, 0xAC, 0x0B, 0xB5, 0x55,
  75749. 0xBE, 0x3A, 0x6C, 0x1B, 0x0C, 0x6B, 0x47, 0xB1, 0xBC, 0x37, 0x73, 0xBF,
  75750. 0x7E, 0x8C, 0x6F, 0x62, 0x90, 0x12, 0x28, 0xF8, 0xC2, 0x8C, 0xBB, 0x18,
  75751. 0xA5, 0x5A, 0xE3, 0x13, 0x41, 0x00, 0x0A, 0x65, 0x01, 0x96, 0xF9, 0x31,
  75752. 0xC7, 0x7A, 0x57, 0xF2, 0xDD, 0xF4, 0x63, 0xE5, 0xE9, 0xEC, 0x14, 0x4B,
  75753. 0x77, 0x7D, 0xE6, 0x2A, 0xAA, 0xB8, 0xA8, 0x62, 0x8A, 0xC3, 0x76, 0xD2,
  75754. 0x82, 0xD6, 0xED, 0x38, 0x64, 0xE6, 0x79, 0x82, 0x42, 0x8E, 0xBC, 0x83,
  75755. 0x1D, 0x14, 0x34, 0x8F, 0x6F, 0x2F, 0x91, 0x93, 0xB5, 0x04, 0x5A, 0xF2,
  75756. 0x76, 0x71, 0x64, 0xE1, 0xDF, 0xC9, 0x67, 0xC1, 0xFB, 0x3F, 0x2E, 0x55,
  75757. 0xA4, 0xBD, 0x1B, 0xFF, 0xE8, 0x3B, 0x9C, 0x80, 0xD0, 0x52, 0xB9, 0x85,
  75758. 0xD1, 0x82, 0xEA, 0x0A, 0xDB, 0x2A, 0x3B, 0x73, 0x13, 0xD3, 0xFE, 0x14,
  75759. 0xC8, 0x48, 0x4B, 0x1E, 0x05, 0x25, 0x88, 0xB9, 0xB7, 0xD2, 0xBB, 0xD2,
  75760. 0xDF, 0x01, 0x61, 0x99, 0xEC, 0xD0, 0x6E, 0x15, 0x57, 0xCD, 0x09, 0x15,
  75761. 0xB3, 0x35, 0x3B, 0xBB, 0x64, 0xE0, 0xEC, 0x37, 0x7F, 0xD0, 0x28, 0x37,
  75762. 0x0D, 0xF9, 0x2B, 0x52, 0xC7, 0x89, 0x14, 0x28, 0xCD, 0xC6, 0x7E, 0xB6,
  75763. 0x18, 0x4B, 0x52, 0x3D, 0x1D, 0xB2, 0x46, 0xC3, 0x2F, 0x63, 0x07, 0x84,
  75764. 0x90, 0xF0, 0x0E, 0xF8, 0xD6, 0x47, 0xD1, 0x48, 0xD4, 0x79, 0x54, 0x51,
  75765. 0x5E, 0x23, 0x27, 0xCF, 0xEF, 0x98, 0xC5, 0x82, 0x66, 0x4B, 0x4C, 0x0F,
  75766. 0x6C, 0xC4, 0x16, 0x59
  75767. };
  75768. const byte qExpected[] = {
  75769. 0x8C, 0xF8, 0x36, 0x42, 0xA7, 0x09, 0xA0, 0x97, 0xB4, 0x47, 0x99, 0x76,
  75770. 0x40, 0x12, 0x9D, 0xA2, 0x99, 0xB1, 0xA4, 0x7D, 0x1E, 0xB3, 0x75, 0x0B,
  75771. 0xA3, 0x08, 0xB0, 0xFE, 0x64, 0xF5, 0xFB, 0xD3
  75772. };
  75773. int pSz = 0;
  75774. int qSz = 0;
  75775. int gSz = 0;
  75776. byte* pReturned = NULL;
  75777. byte* qReturned = NULL;
  75778. byte* gReturned = NULL;
  75779. ExpectNotNull((dh = wolfSSL_DH_get_2048_256()));
  75780. wolfSSL_DH_get0_pqg(dh, &pBn, &qBn, &gBn);
  75781. ExpectIntGT((pSz = wolfSSL_BN_num_bytes(pBn)), 0);
  75782. ExpectNotNull(pReturned = (byte*)XMALLOC(pSz, NULL,
  75783. DYNAMIC_TYPE_TMP_BUFFER));
  75784. ExpectIntGT((pSz = wolfSSL_BN_bn2bin(pBn, pReturned)), 0);
  75785. ExpectIntEQ(pSz, sizeof(pExpected));
  75786. ExpectIntEQ(XMEMCMP(pExpected, pReturned, pSz), 0);
  75787. ExpectIntGT((qSz = wolfSSL_BN_num_bytes(qBn)), 0);
  75788. ExpectNotNull(qReturned = (byte*)XMALLOC(qSz, NULL,
  75789. DYNAMIC_TYPE_TMP_BUFFER));
  75790. ExpectIntGT((qSz = wolfSSL_BN_bn2bin(qBn, qReturned)), 0);
  75791. ExpectIntEQ(qSz, sizeof(qExpected));
  75792. ExpectIntEQ(XMEMCMP(qExpected, qReturned, qSz), 0);
  75793. ExpectIntGT((gSz = wolfSSL_BN_num_bytes(gBn)), 0);
  75794. ExpectNotNull(gReturned = (byte*)XMALLOC(gSz, NULL,
  75795. DYNAMIC_TYPE_TMP_BUFFER));
  75796. ExpectIntGT((gSz = wolfSSL_BN_bn2bin(gBn, gReturned)), 0);
  75797. ExpectIntEQ(gSz, sizeof(gExpected));
  75798. ExpectIntEQ(XMEMCMP(gExpected, gReturned, gSz), 0);
  75799. wolfSSL_DH_free(dh);
  75800. XFREE(pReturned, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  75801. XFREE(gReturned, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  75802. XFREE(qReturned, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  75803. #endif
  75804. return EXPECT_RESULT();
  75805. }
  75806. static int test_wolfSSL_PEM_write_DHparams(void)
  75807. {
  75808. EXPECT_DECLS;
  75809. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO) && \
  75810. !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA) && !defined(NO_FILESYSTEM)
  75811. DH* dh = NULL;
  75812. BIO* bio = NULL;
  75813. XFILE fp = XBADFILE;
  75814. byte pem[2048];
  75815. int pemSz = 0;
  75816. const char expected[] =
  75817. "-----BEGIN DH PARAMETERS-----\n"
  75818. "MIIBCAKCAQEAsKEIBpwIE7pZBjy8MNX1AMFPRKfW70rGJScc6NKWUwpckd2iwpSE\n"
  75819. "v32yRJ+b0sGKxb5yXKfnkebUn3MHhVtmSMdw+rTuAsk9mkraPcFGPhlp0RdGB6NN\n"
  75820. "nyuWFzltMI0q85TTdc+gdebykh8acAWqBINXMPvadpM4UOgn/WPuPOW3yAmub1A1\n"
  75821. "joTOSgDpEn5aMdcz/CETdswWMNsM/MVipzW477ewrMA29tnJRkj5QJAAKxuqbOMa\n"
  75822. "wwsDnhvCRuRITiJzb8Nf1JrWMAdI1oyQq9T28eNI01hLprnNKb9oHwhLY4YvXGvW\n"
  75823. "tgZl96bcAGdru8OpQYP7x/rI4h5+rwA/kwIBAg==\n"
  75824. "-----END DH PARAMETERS-----\n";
  75825. const char badPem[] =
  75826. "-----BEGIN DH PARAMETERS-----\n"
  75827. "-----END DH PARAMETERS-----\n";
  75828. const char emptySeqPem[] =
  75829. "-----BEGIN DH PARAMETERS-----\n"
  75830. "MAA=\n"
  75831. "-----END DH PARAMETERS-----\n";
  75832. ExpectTrue((fp = XFOPEN(dhParamFile, "rb")) != XBADFILE);
  75833. ExpectIntGT((pemSz = (int)XFREAD(pem, 1, sizeof(pem), fp)), 0);
  75834. if (fp != XBADFILE) {
  75835. XFCLOSE(fp);
  75836. fp = XBADFILE;
  75837. }
  75838. ExpectNull(PEM_read_bio_DHparams(NULL, NULL, NULL, NULL));
  75839. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  75840. ExpectNull(dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL));
  75841. ExpectIntEQ(BIO_write(bio, badPem, (int)sizeof(badPem)),
  75842. (int)sizeof(badPem));
  75843. ExpectNull(dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL));
  75844. BIO_free(bio);
  75845. bio = NULL;
  75846. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  75847. ExpectNull(dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL));
  75848. ExpectIntEQ(BIO_write(bio, emptySeqPem, (int)sizeof(emptySeqPem)),
  75849. (int)sizeof(emptySeqPem));
  75850. ExpectNull(dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL));
  75851. BIO_free(bio);
  75852. bio = NULL;
  75853. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  75854. ExpectIntEQ(BIO_write(bio, pem, pemSz), pemSz);
  75855. ExpectNotNull(dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL));
  75856. BIO_free(bio);
  75857. bio = NULL;
  75858. ExpectNotNull(fp = XFOPEN("./test-write-dhparams.pem", "wb"));
  75859. ExpectIntEQ(PEM_write_DHparams(fp, dh), WOLFSSL_SUCCESS);
  75860. ExpectIntEQ(PEM_write_DHparams(fp, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  75861. DH_free(dh);
  75862. dh = NULL;
  75863. dh = wolfSSL_DH_new();
  75864. ExpectIntEQ(PEM_write_DHparams(fp, dh), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  75865. if (fp != XBADFILE) {
  75866. XFCLOSE(fp);
  75867. fp = XBADFILE;
  75868. }
  75869. wolfSSL_DH_free(dh);
  75870. dh = NULL;
  75871. /* check results */
  75872. XMEMSET(pem, 0, sizeof(pem));
  75873. ExpectTrue((fp = XFOPEN("./test-write-dhparams.pem", "rb")) != XBADFILE);
  75874. ExpectIntGT((pemSz = (int)XFREAD(pem, 1, sizeof(pem), fp)), 0);
  75875. ExpectIntEQ(XMEMCMP(pem, expected, pemSz), 0);
  75876. if (fp != XBADFILE)
  75877. XFCLOSE(fp);
  75878. #endif
  75879. return EXPECT_RESULT();
  75880. }
  75881. static int test_wolfSSL_d2i_DHparams(void)
  75882. {
  75883. EXPECT_DECLS;
  75884. #ifdef OPENSSL_ALL
  75885. #if !defined(NO_DH) && (defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072))
  75886. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  75887. XFILE f = XBADFILE;
  75888. unsigned char buf[4096];
  75889. const unsigned char* pt = buf;
  75890. #ifdef HAVE_FFDHE_2048
  75891. const char* params1 = "./certs/dh2048.der";
  75892. #endif
  75893. #ifdef HAVE_FFDHE_3072
  75894. const char* params2 = "./certs/dh3072.der";
  75895. #endif
  75896. long len = 0;
  75897. WOLFSSL_DH* dh = NULL;
  75898. XMEMSET(buf, 0, sizeof(buf));
  75899. /* Test 2048 bit parameters */
  75900. #ifdef HAVE_FFDHE_2048
  75901. ExpectTrue((f = XFOPEN(params1, "rb")) != XBADFILE);
  75902. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  75903. if (f != XBADFILE) {
  75904. XFCLOSE(f);
  75905. f = XBADFILE;
  75906. }
  75907. /* Valid case */
  75908. ExpectNotNull(dh = wolfSSL_d2i_DHparams(NULL, &pt, len));
  75909. ExpectNotNull(dh->p);
  75910. ExpectNotNull(dh->g);
  75911. ExpectTrue(pt == buf);
  75912. ExpectIntEQ(DH_set_length(NULL, BN_num_bits(dh->p)), 0);
  75913. ExpectIntEQ(DH_set_length(dh, BN_num_bits(dh->p)), 1);
  75914. ExpectIntEQ(DH_generate_key(dh), WOLFSSL_SUCCESS);
  75915. /* Invalid cases */
  75916. ExpectNull(wolfSSL_d2i_DHparams(NULL, NULL, len));
  75917. ExpectNull(wolfSSL_d2i_DHparams(NULL, &pt, -1));
  75918. ExpectNull(wolfSSL_d2i_DHparams(NULL, &pt, 10));
  75919. DH_free(dh);
  75920. dh = NULL;
  75921. *buf = 0;
  75922. pt = buf;
  75923. #endif /* HAVE_FFDHE_2048 */
  75924. /* Test 3072 bit parameters */
  75925. #ifdef HAVE_FFDHE_3072
  75926. ExpectTrue((f = XFOPEN(params2, "rb")) != XBADFILE);
  75927. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  75928. if (f != XBADFILE) {
  75929. XFCLOSE(f);
  75930. f = XBADFILE;
  75931. }
  75932. /* Valid case */
  75933. ExpectNotNull(dh = wolfSSL_d2i_DHparams(&dh, &pt, len));
  75934. ExpectNotNull(dh->p);
  75935. ExpectNotNull(dh->g);
  75936. ExpectTrue(pt != buf);
  75937. ExpectIntEQ(DH_generate_key(dh), 1);
  75938. /* Invalid cases */
  75939. ExpectNull(wolfSSL_d2i_DHparams(NULL, NULL, len));
  75940. ExpectNull(wolfSSL_d2i_DHparams(NULL, &pt, -1));
  75941. DH_free(dh);
  75942. dh = NULL;
  75943. #endif /* HAVE_FFDHE_3072 */
  75944. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  75945. #endif /* !NO_DH */
  75946. #endif
  75947. return EXPECT_RESULT();
  75948. }
  75949. static int test_wolfSSL_DH_LoadDer(void)
  75950. {
  75951. EXPECT_DECLS;
  75952. #if !defined(NO_DH) && (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0)) && \
  75953. defined(OPENSSL_EXTRA)
  75954. static const byte dh2048[] = {
  75955. 0x30, 0x82, 0x01, 0x08, 0x02, 0x82, 0x01, 0x01,
  75956. 0x00, 0xb0, 0xa1, 0x08, 0x06, 0x9c, 0x08, 0x13,
  75957. 0xba, 0x59, 0x06, 0x3c, 0xbc, 0x30, 0xd5, 0xf5,
  75958. 0x00, 0xc1, 0x4f, 0x44, 0xa7, 0xd6, 0xef, 0x4a,
  75959. 0xc6, 0x25, 0x27, 0x1c, 0xe8, 0xd2, 0x96, 0x53,
  75960. 0x0a, 0x5c, 0x91, 0xdd, 0xa2, 0xc2, 0x94, 0x84,
  75961. 0xbf, 0x7d, 0xb2, 0x44, 0x9f, 0x9b, 0xd2, 0xc1,
  75962. 0x8a, 0xc5, 0xbe, 0x72, 0x5c, 0xa7, 0xe7, 0x91,
  75963. 0xe6, 0xd4, 0x9f, 0x73, 0x07, 0x85, 0x5b, 0x66,
  75964. 0x48, 0xc7, 0x70, 0xfa, 0xb4, 0xee, 0x02, 0xc9,
  75965. 0x3d, 0x9a, 0x4a, 0xda, 0x3d, 0xc1, 0x46, 0x3e,
  75966. 0x19, 0x69, 0xd1, 0x17, 0x46, 0x07, 0xa3, 0x4d,
  75967. 0x9f, 0x2b, 0x96, 0x17, 0x39, 0x6d, 0x30, 0x8d,
  75968. 0x2a, 0xf3, 0x94, 0xd3, 0x75, 0xcf, 0xa0, 0x75,
  75969. 0xe6, 0xf2, 0x92, 0x1f, 0x1a, 0x70, 0x05, 0xaa,
  75970. 0x04, 0x83, 0x57, 0x30, 0xfb, 0xda, 0x76, 0x93,
  75971. 0x38, 0x50, 0xe8, 0x27, 0xfd, 0x63, 0xee, 0x3c,
  75972. 0xe5, 0xb7, 0xc8, 0x09, 0xae, 0x6f, 0x50, 0x35,
  75973. 0x8e, 0x84, 0xce, 0x4a, 0x00, 0xe9, 0x12, 0x7e,
  75974. 0x5a, 0x31, 0xd7, 0x33, 0xfc, 0x21, 0x13, 0x76,
  75975. 0xcc, 0x16, 0x30, 0xdb, 0x0c, 0xfc, 0xc5, 0x62,
  75976. 0xa7, 0x35, 0xb8, 0xef, 0xb7, 0xb0, 0xac, 0xc0,
  75977. 0x36, 0xf6, 0xd9, 0xc9, 0x46, 0x48, 0xf9, 0x40,
  75978. 0x90, 0x00, 0x2b, 0x1b, 0xaa, 0x6c, 0xe3, 0x1a,
  75979. 0xc3, 0x0b, 0x03, 0x9e, 0x1b, 0xc2, 0x46, 0xe4,
  75980. 0x48, 0x4e, 0x22, 0x73, 0x6f, 0xc3, 0x5f, 0xd4,
  75981. 0x9a, 0xd6, 0x30, 0x07, 0x48, 0xd6, 0x8c, 0x90,
  75982. 0xab, 0xd4, 0xf6, 0xf1, 0xe3, 0x48, 0xd3, 0x58,
  75983. 0x4b, 0xa6, 0xb9, 0xcd, 0x29, 0xbf, 0x68, 0x1f,
  75984. 0x08, 0x4b, 0x63, 0x86, 0x2f, 0x5c, 0x6b, 0xd6,
  75985. 0xb6, 0x06, 0x65, 0xf7, 0xa6, 0xdc, 0x00, 0x67,
  75986. 0x6b, 0xbb, 0xc3, 0xa9, 0x41, 0x83, 0xfb, 0xc7,
  75987. 0xfa, 0xc8, 0xe2, 0x1e, 0x7e, 0xaf, 0x00, 0x3f,
  75988. 0x93, 0x02, 0x01, 0x02
  75989. };
  75990. WOLFSSL_DH* dh = NULL;
  75991. ExpectNotNull(dh = wolfSSL_DH_new());
  75992. ExpectIntEQ(wolfSSL_DH_LoadDer(NULL, NULL, 0), -1);
  75993. ExpectIntEQ(wolfSSL_DH_LoadDer(dh, NULL, 0), -1);
  75994. ExpectIntEQ(wolfSSL_DH_LoadDer(NULL, dh2048, sizeof(dh2048)), -1);
  75995. ExpectIntEQ(wolfSSL_DH_LoadDer(dh, dh2048, sizeof(dh2048)), 1);
  75996. wolfSSL_DH_free(dh);
  75997. #endif
  75998. return EXPECT_RESULT();
  75999. }
  76000. static int test_wolfSSL_i2d_DHparams(void)
  76001. {
  76002. EXPECT_DECLS;
  76003. #ifdef OPENSSL_ALL
  76004. #if !defined(NO_DH) && (defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072))
  76005. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  76006. XFILE f = XBADFILE;
  76007. unsigned char buf[4096];
  76008. const unsigned char* pt;
  76009. unsigned char* pt2;
  76010. #ifdef HAVE_FFDHE_2048
  76011. const char* params1 = "./certs/dh2048.der";
  76012. #endif
  76013. #ifdef HAVE_FFDHE_3072
  76014. const char* params2 = "./certs/dh3072.der";
  76015. #endif
  76016. long len = 0;
  76017. WOLFSSL_DH* dh = NULL;
  76018. /* Test 2048 bit parameters */
  76019. #ifdef HAVE_FFDHE_2048
  76020. pt = buf;
  76021. pt2 = buf;
  76022. ExpectTrue((f = XFOPEN(params1, "rb")) != XBADFILE);
  76023. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  76024. if (f != XBADFILE) {
  76025. XFCLOSE(f);
  76026. f = XBADFILE;
  76027. }
  76028. /* Valid case */
  76029. ExpectNotNull(dh = wolfSSL_d2i_DHparams(NULL, &pt, len));
  76030. ExpectTrue(pt == buf);
  76031. ExpectIntEQ(DH_generate_key(dh), 1);
  76032. ExpectIntEQ(wolfSSL_i2d_DHparams(dh, &pt2), 268);
  76033. /* Invalid case */
  76034. ExpectIntEQ(wolfSSL_i2d_DHparams(NULL, &pt2), 0);
  76035. /* Return length only */
  76036. ExpectIntEQ(wolfSSL_i2d_DHparams(dh, NULL), 268);
  76037. DH_free(dh);
  76038. dh = NULL;
  76039. *buf = 0;
  76040. #endif
  76041. /* Test 3072 bit parameters */
  76042. #ifdef HAVE_FFDHE_3072
  76043. pt = buf;
  76044. pt2 = buf;
  76045. ExpectTrue((f = XFOPEN(params2, "rb")) != XBADFILE);
  76046. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  76047. if (f != XBADFILE) {
  76048. XFCLOSE(f);
  76049. f = XBADFILE;
  76050. }
  76051. /* Valid case */
  76052. ExpectNotNull(dh = wolfSSL_d2i_DHparams(NULL, &pt, len));
  76053. ExpectTrue(pt == buf);
  76054. ExpectIntEQ(DH_generate_key(dh), 1);
  76055. ExpectIntEQ(wolfSSL_i2d_DHparams(dh, &pt2), 396);
  76056. /* Invalid case */
  76057. ExpectIntEQ(wolfSSL_i2d_DHparams(NULL, &pt2), 0);
  76058. /* Return length only */
  76059. ExpectIntEQ(wolfSSL_i2d_DHparams(dh, NULL), 396);
  76060. DH_free(dh);
  76061. dh = NULL;
  76062. #endif
  76063. dh = DH_new();
  76064. ExpectNotNull(dh);
  76065. pt2 = buf;
  76066. ExpectIntEQ(wolfSSL_i2d_DHparams(dh, &pt2), 0);
  76067. DH_free(dh);
  76068. dh = NULL;
  76069. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  76070. #endif /* !NO_DH && (HAVE_FFDHE_2048 || HAVE_FFDHE_3072) */
  76071. #endif
  76072. return EXPECT_RESULT();
  76073. }
  76074. #if defined(HAVE_ECC) && !defined(OPENSSL_NO_PK)
  76075. /*----------------------------------------------------------------------------*
  76076. | EC
  76077. *----------------------------------------------------------------------------*/
  76078. static int test_wolfSSL_EC_GROUP(void)
  76079. {
  76080. EXPECT_DECLS;
  76081. #ifdef OPENSSL_EXTRA
  76082. EC_GROUP *group = NULL;
  76083. EC_GROUP *group2 = NULL;
  76084. EC_GROUP *group3 = NULL;
  76085. #ifndef HAVE_ECC_BRAINPOOL
  76086. EC_GROUP *group4 = NULL;
  76087. #endif
  76088. WOLFSSL_BIGNUM* order = NULL;
  76089. int group_bits;
  76090. int i;
  76091. static const int knownEccNids[] = {
  76092. NID_X9_62_prime192v1,
  76093. NID_X9_62_prime192v2,
  76094. NID_X9_62_prime192v3,
  76095. NID_X9_62_prime239v1,
  76096. NID_X9_62_prime239v2,
  76097. NID_X9_62_prime239v3,
  76098. NID_X9_62_prime256v1,
  76099. NID_secp112r1,
  76100. NID_secp112r2,
  76101. NID_secp128r1,
  76102. NID_secp128r2,
  76103. NID_secp160r1,
  76104. NID_secp160r2,
  76105. NID_secp224r1,
  76106. NID_secp384r1,
  76107. NID_secp521r1,
  76108. NID_secp160k1,
  76109. NID_secp192k1,
  76110. NID_secp224k1,
  76111. NID_secp256k1,
  76112. NID_brainpoolP160r1,
  76113. NID_brainpoolP192r1,
  76114. NID_brainpoolP224r1,
  76115. NID_brainpoolP256r1,
  76116. NID_brainpoolP320r1,
  76117. NID_brainpoolP384r1,
  76118. NID_brainpoolP512r1,
  76119. };
  76120. int knowEccNidsLen = (int)(sizeof(knownEccNids) / sizeof(*knownEccNids));
  76121. static const int knownEccEnums[] = {
  76122. ECC_SECP192R1,
  76123. ECC_PRIME192V2,
  76124. ECC_PRIME192V3,
  76125. ECC_PRIME239V1,
  76126. ECC_PRIME239V2,
  76127. ECC_PRIME239V3,
  76128. ECC_SECP256R1,
  76129. ECC_SECP112R1,
  76130. ECC_SECP112R2,
  76131. ECC_SECP128R1,
  76132. ECC_SECP128R2,
  76133. ECC_SECP160R1,
  76134. ECC_SECP160R2,
  76135. ECC_SECP224R1,
  76136. ECC_SECP384R1,
  76137. ECC_SECP521R1,
  76138. ECC_SECP160K1,
  76139. ECC_SECP192K1,
  76140. ECC_SECP224K1,
  76141. ECC_SECP256K1,
  76142. ECC_BRAINPOOLP160R1,
  76143. ECC_BRAINPOOLP192R1,
  76144. ECC_BRAINPOOLP224R1,
  76145. ECC_BRAINPOOLP256R1,
  76146. ECC_BRAINPOOLP320R1,
  76147. ECC_BRAINPOOLP384R1,
  76148. ECC_BRAINPOOLP512R1,
  76149. };
  76150. int knowEccEnumsLen = (int)(sizeof(knownEccEnums) / sizeof(*knownEccEnums));
  76151. ExpectNotNull(group = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
  76152. ExpectNotNull(group2 = EC_GROUP_dup(group));
  76153. ExpectNotNull(group3 = wolfSSL_EC_GROUP_new_by_curve_name(NID_secp384r1));
  76154. #ifndef HAVE_ECC_BRAINPOOL
  76155. ExpectNotNull(group4 = wolfSSL_EC_GROUP_new_by_curve_name(
  76156. NID_brainpoolP256r1));
  76157. #endif
  76158. ExpectNull(EC_GROUP_dup(NULL));
  76159. ExpectIntEQ(wolfSSL_EC_GROUP_get_curve_name(NULL), 0);
  76160. ExpectIntEQ(wolfSSL_EC_GROUP_get_curve_name(group), NID_X9_62_prime256v1);
  76161. ExpectIntEQ((group_bits = EC_GROUP_order_bits(NULL)), 0);
  76162. ExpectIntEQ((group_bits = EC_GROUP_order_bits(group)), 256);
  76163. #ifndef HAVE_ECC_BRAINPOOL
  76164. ExpectIntEQ((group_bits = EC_GROUP_order_bits(group4)), 0);
  76165. #endif
  76166. ExpectIntEQ(wolfSSL_EC_GROUP_get_degree(NULL), 0);
  76167. ExpectIntEQ(wolfSSL_EC_GROUP_get_degree(group), 256);
  76168. ExpectNotNull(order = BN_new());
  76169. ExpectIntEQ(wolfSSL_EC_GROUP_get_order(NULL, NULL, NULL), 0);
  76170. ExpectIntEQ(wolfSSL_EC_GROUP_get_order(group, NULL, NULL), 0);
  76171. ExpectIntEQ(wolfSSL_EC_GROUP_get_order(NULL, order, NULL), 0);
  76172. ExpectIntEQ(wolfSSL_EC_GROUP_get_order(group, order, NULL), 1);
  76173. wolfSSL_BN_free(order);
  76174. ExpectNotNull(EC_GROUP_method_of(group));
  76175. ExpectIntEQ(EC_METHOD_get_field_type(NULL), 0);
  76176. ExpectIntEQ(EC_METHOD_get_field_type(EC_GROUP_method_of(group)),
  76177. NID_X9_62_prime_field);
  76178. ExpectIntEQ(wolfSSL_EC_GROUP_cmp(NULL, NULL, NULL), -1);
  76179. ExpectIntEQ(wolfSSL_EC_GROUP_cmp(group, NULL, NULL), -1);
  76180. ExpectIntEQ(wolfSSL_EC_GROUP_cmp(NULL, group, NULL), -1);
  76181. ExpectIntEQ(wolfSSL_EC_GROUP_cmp(group, group3, NULL), 1);
  76182. #ifndef NO_WOLFSSL_STUB
  76183. wolfSSL_EC_GROUP_set_asn1_flag(group, OPENSSL_EC_NAMED_CURVE);
  76184. #endif
  76185. #ifndef HAVE_ECC_BRAINPOOL
  76186. EC_GROUP_free(group4);
  76187. #endif
  76188. EC_GROUP_free(group3);
  76189. EC_GROUP_free(group2);
  76190. EC_GROUP_free(group);
  76191. for (i = 0; i < knowEccNidsLen; i++) {
  76192. group = NULL;
  76193. ExpectNotNull(group = EC_GROUP_new_by_curve_name(knownEccNids[i]));
  76194. ExpectIntGT(wolfSSL_EC_GROUP_get_degree(group), 0);
  76195. EC_GROUP_free(group);
  76196. }
  76197. for (i = 0; i < knowEccEnumsLen; i++) {
  76198. group = NULL;
  76199. ExpectNotNull(group = EC_GROUP_new_by_curve_name(knownEccEnums[i]));
  76200. ExpectIntEQ(wolfSSL_EC_GROUP_get_curve_name(group), knownEccNids[i]);
  76201. EC_GROUP_free(group);
  76202. }
  76203. #endif
  76204. return EXPECT_RESULT();
  76205. }
  76206. static int test_wolfSSL_PEM_read_bio_ECPKParameters(void)
  76207. {
  76208. EXPECT_DECLS;
  76209. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  76210. EC_GROUP *group = NULL;
  76211. BIO* bio = NULL;
  76212. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && \
  76213. ECC_MIN_KEY_SZ <= 384 && !defined(NO_ECC_SECP)
  76214. EC_GROUP *ret = NULL;
  76215. static char ec_nc_p384[] = "-----BEGIN EC PARAMETERS-----\n"
  76216. "BgUrgQQAIg==\n"
  76217. "-----END EC PARAMETERS-----";
  76218. #endif
  76219. static char ec_nc_bad_1[] = "-----BEGIN EC PARAMETERS-----\n"
  76220. "MAA=\n"
  76221. "-----END EC PARAMETERS-----";
  76222. static char ec_nc_bad_2[] = "-----BEGIN EC PARAMETERS-----\n"
  76223. "BgA=\n"
  76224. "-----END EC PARAMETERS-----";
  76225. static char ec_nc_bad_3[] = "-----BEGIN EC PARAMETERS-----\n"
  76226. "BgE=\n"
  76227. "-----END EC PARAMETERS-----";
  76228. static char ec_nc_bad_4[] = "-----BEGIN EC PARAMETERS-----\n"
  76229. "BgE*\n"
  76230. "-----END EC PARAMETERS-----";
  76231. /* Test that first parameter, bio, being NULL fails. */
  76232. ExpectNull(PEM_read_bio_ECPKParameters(NULL, NULL, NULL, NULL));
  76233. /* Test that reading named parameters works. */
  76234. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  76235. ExpectIntEQ(BIO_read_filename(bio, eccKeyFile), WOLFSSL_SUCCESS);
  76236. ExpectNotNull(group = PEM_read_bio_ECPKParameters(bio, NULL, NULL, NULL));
  76237. ExpectIntEQ(EC_GROUP_get_curve_name(group), NID_X9_62_prime256v1);
  76238. BIO_free(bio);
  76239. bio = NULL;
  76240. EC_GROUP_free(group);
  76241. group = NULL;
  76242. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && \
  76243. ECC_MIN_KEY_SZ <= 384 && !defined(NO_ECC_SECP)
  76244. /* Test that reusing group works. */
  76245. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_p384,
  76246. sizeof(ec_nc_p384)));
  76247. ExpectNotNull(group = PEM_read_bio_ECPKParameters(bio, &group, NULL, NULL));
  76248. ExpectIntEQ(EC_GROUP_get_curve_name(group), NID_secp384r1);
  76249. BIO_free(bio);
  76250. bio = NULL;
  76251. EC_GROUP_free(group);
  76252. group = NULL;
  76253. /* Test that returning through group works. */
  76254. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_p384,
  76255. sizeof(ec_nc_p384)));
  76256. ExpectNotNull(ret = PEM_read_bio_ECPKParameters(bio, &group, NULL, NULL));
  76257. ExpectIntEQ(group == ret, 1);
  76258. ExpectIntEQ(EC_GROUP_get_curve_name(group), NID_secp384r1);
  76259. BIO_free(bio);
  76260. bio = NULL;
  76261. EC_GROUP_free(group);
  76262. group = NULL;
  76263. #endif
  76264. /* Test 0x30, 0x00 (not and object id) fails. */
  76265. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_bad_1,
  76266. sizeof(ec_nc_bad_1)));
  76267. ExpectNull(PEM_read_bio_ECPKParameters(bio, NULL, NULL, NULL));
  76268. BIO_free(bio);
  76269. bio = NULL;
  76270. /* Test 0x06, 0x00 (empty object id) fails. */
  76271. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_bad_2,
  76272. sizeof(ec_nc_bad_2)));
  76273. ExpectNull(PEM_read_bio_ECPKParameters(bio, NULL, NULL, NULL));
  76274. BIO_free(bio);
  76275. bio = NULL;
  76276. /* Test 0x06, 0x01 (badly formed object id) fails. */
  76277. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_bad_3,
  76278. sizeof(ec_nc_bad_3)));
  76279. ExpectNull(PEM_read_bio_ECPKParameters(bio, NULL, NULL, NULL));
  76280. BIO_free(bio);
  76281. bio = NULL;
  76282. /* Test invalid PEM encoding - invalid character. */
  76283. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_bad_4,
  76284. sizeof(ec_nc_bad_4)));
  76285. ExpectNull(PEM_read_bio_ECPKParameters(bio, NULL, NULL, NULL));
  76286. BIO_free(bio);
  76287. #endif
  76288. return EXPECT_RESULT();
  76289. }
  76290. static int test_wolfSSL_EC_POINT(void)
  76291. {
  76292. EXPECT_DECLS;
  76293. #if !defined(WOLFSSL_SP_MATH) && \
  76294. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2)))
  76295. #ifdef OPENSSL_EXTRA
  76296. BN_CTX* ctx = NULL;
  76297. EC_GROUP* group = NULL;
  76298. #ifndef HAVE_ECC_BRAINPOOL
  76299. EC_GROUP* group2 = NULL;
  76300. #endif
  76301. EC_POINT* Gxy = NULL;
  76302. EC_POINT* new_point = NULL;
  76303. EC_POINT* set_point = NULL;
  76304. EC_POINT* get_point = NULL;
  76305. EC_POINT* infinity = NULL;
  76306. BIGNUM* k = NULL;
  76307. BIGNUM* Gx = NULL;
  76308. BIGNUM* Gy = NULL;
  76309. BIGNUM* Gz = NULL;
  76310. BIGNUM* X = NULL;
  76311. BIGNUM* Y = NULL;
  76312. BIGNUM* set_point_bn = NULL;
  76313. char* hexStr = NULL;
  76314. const char* kTest = "F4F8338AFCC562C5C3F3E1E46A7EFECD"
  76315. "17AF381913FF7A96314EA47055EA0FD0";
  76316. /* NISTP256R1 Gx/Gy */
  76317. const char* kGx = "6B17D1F2E12C4247F8BCE6E563A440F2"
  76318. "77037D812DEB33A0F4A13945D898C296";
  76319. const char* kGy = "4FE342E2FE1A7F9B8EE7EB4A7C0F9E16"
  76320. "2BCE33576B315ECECBB6406837BF51F5";
  76321. const char* uncompG
  76322. = "046B17D1F2E12C4247F8BCE6E563A440F2"
  76323. "77037D812DEB33A0F4A13945D898C296"
  76324. "4FE342E2FE1A7F9B8EE7EB4A7C0F9E16"
  76325. "2BCE33576B315ECECBB6406837BF51F5";
  76326. const char* compG
  76327. = "036B17D1F2E12C4247F8BCE6E563A440F2"
  76328. "77037D812DEB33A0F4A13945D898C296";
  76329. #ifndef HAVE_SELFTEST
  76330. EC_POINT *tmp = NULL;
  76331. size_t bin_len;
  76332. unsigned int blen = 0;
  76333. unsigned char* buf = NULL;
  76334. unsigned char bufInf[1] = { 0x00 };
  76335. const unsigned char binUncompG[] = {
  76336. 0x04, 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc,
  76337. 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2, 0x77, 0x03, 0x7d, 0x81, 0x2d,
  76338. 0xeb, 0x33, 0xa0, 0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
  76339. 0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b, 0x8e, 0xe7, 0xeb,
  76340. 0x4a, 0x7c, 0x0f, 0x9e, 0x16, 0x2b, 0xce, 0x33, 0x57, 0x6b, 0x31,
  76341. 0x5e, 0xce, 0xcb, 0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf5,
  76342. };
  76343. const unsigned char binUncompGBad[] = {
  76344. 0x09, 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc,
  76345. 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2, 0x77, 0x03, 0x7d, 0x81, 0x2d,
  76346. 0xeb, 0x33, 0xa0, 0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
  76347. 0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b, 0x8e, 0xe7, 0xeb,
  76348. 0x4a, 0x7c, 0x0f, 0x9e, 0x16, 0x2b, 0xce, 0x33, 0x57, 0x6b, 0x31,
  76349. 0x5e, 0xce, 0xcb, 0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf5,
  76350. };
  76351. #ifdef HAVE_COMP_KEY
  76352. const unsigned char binCompG[] = {
  76353. 0x03, 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc,
  76354. 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2, 0x77, 0x03, 0x7d, 0x81, 0x2d,
  76355. 0xeb, 0x33, 0xa0, 0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
  76356. };
  76357. #endif
  76358. #endif
  76359. ExpectNotNull(ctx = BN_CTX_new());
  76360. ExpectNotNull(group = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
  76361. #ifndef HAVE_ECC_BRAINPOOL
  76362. /* Used to make groups curve_idx == -1. */
  76363. ExpectNotNull(group2 = EC_GROUP_new_by_curve_name(NID_brainpoolP256r1));
  76364. #endif
  76365. ExpectNull(EC_POINT_new(NULL));
  76366. ExpectNotNull(Gxy = EC_POINT_new(group));
  76367. ExpectNotNull(new_point = EC_POINT_new(group));
  76368. ExpectNotNull(set_point = EC_POINT_new(group));
  76369. ExpectNotNull(X = BN_new());
  76370. ExpectNotNull(Y = BN_new());
  76371. ExpectNotNull(set_point_bn = BN_new());
  76372. ExpectNotNull(infinity = EC_POINT_new(group));
  76373. /* load test values */
  76374. ExpectIntEQ(BN_hex2bn(&k, kTest), WOLFSSL_SUCCESS);
  76375. ExpectIntEQ(BN_hex2bn(&Gx, kGx), WOLFSSL_SUCCESS);
  76376. ExpectIntEQ(BN_hex2bn(&Gy, kGy), WOLFSSL_SUCCESS);
  76377. ExpectIntEQ(BN_hex2bn(&Gz, "1"), WOLFSSL_SUCCESS);
  76378. /* populate coordinates for input point */
  76379. if (Gxy != NULL) {
  76380. Gxy->X = Gx;
  76381. Gxy->Y = Gy;
  76382. Gxy->Z = Gz;
  76383. }
  76384. /* Test handling of NULL point. */
  76385. EC_POINT_clear_free(NULL);
  76386. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(NULL, NULL,
  76387. NULL, NULL, ctx), 0);
  76388. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(group, NULL,
  76389. NULL, NULL, ctx), 0);
  76390. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(NULL, Gxy,
  76391. NULL, NULL, ctx), 0);
  76392. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(NULL, NULL,
  76393. X, NULL, ctx), 0);
  76394. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(NULL, NULL,
  76395. NULL, Y, ctx), 0);
  76396. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(NULL, Gxy,
  76397. X, Y, ctx), 0);
  76398. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(group, NULL,
  76399. X, Y, ctx), 0);
  76400. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(group, Gxy,
  76401. NULL, Y, ctx), 0);
  76402. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(group, Gxy,
  76403. X, NULL, ctx), 0);
  76404. /* Getting point at infinity returns an error. */
  76405. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(group, infinity,
  76406. X, Y, ctx), 0);
  76407. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  76408. !defined(HAVE_SELFTEST) && !defined(WOLFSSL_SP_MATH) && \
  76409. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  76410. ExpectIntEQ(EC_POINT_add(NULL, NULL, NULL, NULL, ctx), 0);
  76411. ExpectIntEQ(EC_POINT_add(group, NULL, NULL, NULL, ctx), 0);
  76412. ExpectIntEQ(EC_POINT_add(NULL, new_point, NULL, NULL, ctx), 0);
  76413. ExpectIntEQ(EC_POINT_add(NULL, NULL, new_point, NULL, ctx), 0);
  76414. ExpectIntEQ(EC_POINT_add(NULL, NULL, NULL, Gxy, ctx), 0);
  76415. ExpectIntEQ(EC_POINT_add(NULL, new_point, new_point, Gxy, ctx), 0);
  76416. ExpectIntEQ(EC_POINT_add(group, NULL, new_point, Gxy, ctx), 0);
  76417. ExpectIntEQ(EC_POINT_add(group, new_point, NULL, Gxy, ctx), 0);
  76418. ExpectIntEQ(EC_POINT_add(group, new_point, new_point, NULL, ctx), 0);
  76419. ExpectIntEQ(EC_POINT_mul(NULL, NULL, Gx, Gxy, k, ctx), 0);
  76420. ExpectIntEQ(EC_POINT_mul(NULL, new_point, Gx, Gxy, k, ctx), 0);
  76421. ExpectIntEQ(EC_POINT_mul(group, NULL, Gx, Gxy, k, ctx), 0);
  76422. ExpectIntEQ(EC_POINT_add(group, new_point, new_point, Gxy, ctx), 1);
  76423. /* perform point multiplication */
  76424. ExpectIntEQ(EC_POINT_mul(group, new_point, Gx, Gxy, k, ctx), 1);
  76425. ExpectIntEQ(BN_is_zero(new_point->X), 0);
  76426. ExpectIntEQ(BN_is_zero(new_point->Y), 0);
  76427. ExpectIntEQ(BN_is_zero(new_point->Z), 0);
  76428. ExpectIntEQ(EC_POINT_mul(group, new_point, NULL, 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, Gx, NULL, NULL, 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, NULL, NULL, NULL, ctx), 1);
  76437. ExpectIntEQ(BN_is_zero(new_point->X), 1);
  76438. ExpectIntEQ(BN_is_zero(new_point->Y), 1);
  76439. ExpectIntEQ(BN_is_zero(new_point->Z), 1);
  76440. /* Set point to something. */
  76441. ExpectIntEQ(EC_POINT_add(group, new_point, Gxy, Gxy, ctx), 1);
  76442. #else
  76443. ExpectIntEQ(EC_POINT_set_affine_coordinates_GFp(group, new_point, Gx, Gy,
  76444. ctx), 1);
  76445. ExpectIntEQ(BN_is_zero(new_point->X), 0);
  76446. ExpectIntEQ(BN_is_zero(new_point->Y), 0);
  76447. ExpectIntEQ(BN_is_zero(new_point->Z), 0);
  76448. #endif
  76449. /* check if point X coordinate is zero */
  76450. ExpectIntEQ(BN_is_zero(new_point->X), 0);
  76451. #if defined(USE_ECC_B_PARAM) && !defined(HAVE_SELFTEST) && \
  76452. (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0))
  76453. ExpectIntEQ(EC_POINT_is_on_curve(group, new_point, ctx), 1);
  76454. #endif
  76455. /* extract the coordinates from point */
  76456. ExpectIntEQ(EC_POINT_get_affine_coordinates_GFp(group, new_point, X, Y,
  76457. ctx), WOLFSSL_SUCCESS);
  76458. /* check if point X coordinate is zero */
  76459. ExpectIntEQ(BN_is_zero(X), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  76460. /* set the same X and Y points in another object */
  76461. ExpectIntEQ(EC_POINT_set_affine_coordinates_GFp(group, set_point, X, Y,
  76462. ctx), WOLFSSL_SUCCESS);
  76463. /* compare points as they should be the same */
  76464. ExpectIntEQ(EC_POINT_cmp(NULL, NULL, NULL, ctx), -1);
  76465. ExpectIntEQ(EC_POINT_cmp(group, NULL, NULL, ctx), -1);
  76466. ExpectIntEQ(EC_POINT_cmp(NULL, new_point, NULL, ctx), -1);
  76467. ExpectIntEQ(EC_POINT_cmp(NULL, NULL, set_point, ctx), -1);
  76468. ExpectIntEQ(EC_POINT_cmp(NULL, new_point, set_point, ctx), -1);
  76469. ExpectIntEQ(EC_POINT_cmp(group, NULL, set_point, ctx), -1);
  76470. ExpectIntEQ(EC_POINT_cmp(group, new_point, NULL, ctx), -1);
  76471. ExpectIntEQ(EC_POINT_cmp(group, new_point, set_point, ctx), 0);
  76472. /* Test copying */
  76473. ExpectIntEQ(EC_POINT_copy(NULL, NULL), 0);
  76474. ExpectIntEQ(EC_POINT_copy(NULL, set_point), 0);
  76475. ExpectIntEQ(EC_POINT_copy(new_point, NULL), 0);
  76476. ExpectIntEQ(EC_POINT_copy(new_point, set_point), 1);
  76477. /* Test inverting */
  76478. ExpectIntEQ(EC_POINT_invert(NULL, NULL, ctx), 0);
  76479. ExpectIntEQ(EC_POINT_invert(NULL, new_point, ctx), 0);
  76480. ExpectIntEQ(EC_POINT_invert(group, NULL, ctx), 0);
  76481. ExpectIntEQ(EC_POINT_invert(group, new_point, ctx), 1);
  76482. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  76483. !defined(HAVE_SELFTEST) && !defined(WOLFSSL_SP_MATH) && \
  76484. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  76485. {
  76486. EC_POINT* orig_point = NULL;
  76487. ExpectNotNull(orig_point = EC_POINT_new(group));
  76488. ExpectIntEQ(EC_POINT_add(group, orig_point, set_point, set_point, NULL),
  76489. 1);
  76490. /* new_point should be set_point inverted so adding it will revert
  76491. * the point back to set_point */
  76492. ExpectIntEQ(EC_POINT_add(group, orig_point, orig_point, new_point,
  76493. NULL), 1);
  76494. ExpectIntEQ(EC_POINT_cmp(group, orig_point, set_point, NULL), 0);
  76495. EC_POINT_free(orig_point);
  76496. }
  76497. #endif
  76498. /* Test getting affine converts from projective. */
  76499. ExpectIntEQ(EC_POINT_copy(set_point, new_point), 1);
  76500. /* Force non-affine coordinates */
  76501. ExpectIntEQ(BN_add(new_point->Z, (WOLFSSL_BIGNUM*)BN_value_one(),
  76502. (WOLFSSL_BIGNUM*)BN_value_one()), 1);
  76503. if (new_point != NULL) {
  76504. new_point->inSet = 0;
  76505. }
  76506. /* extract the coordinates from point */
  76507. ExpectIntEQ(EC_POINT_get_affine_coordinates_GFp(group, new_point, X, Y,
  76508. ctx), WOLFSSL_SUCCESS);
  76509. /* check if point ordinates have changed. */
  76510. ExpectIntNE(BN_cmp(X, set_point->X), 0);
  76511. ExpectIntNE(BN_cmp(Y, set_point->Y), 0);
  76512. /* Test check for infinity */
  76513. #ifndef WOLF_CRYPTO_CB_ONLY_ECC
  76514. ExpectIntEQ(EC_POINT_is_at_infinity(NULL, NULL), 0);
  76515. ExpectIntEQ(EC_POINT_is_at_infinity(NULL, infinity), 0);
  76516. ExpectIntEQ(EC_POINT_is_at_infinity(group, NULL), 0);
  76517. ExpectIntEQ(EC_POINT_is_at_infinity(group, infinity), 1);
  76518. ExpectIntEQ(EC_POINT_is_at_infinity(group, Gxy), 0);
  76519. #else
  76520. ExpectIntEQ(EC_POINT_is_at_infinity(group, infinity), 0);
  76521. #endif
  76522. ExpectPtrEq(EC_POINT_point2bn(group, set_point,
  76523. POINT_CONVERSION_UNCOMPRESSED, set_point_bn, ctx), set_point_bn);
  76524. /* check bn2hex */
  76525. hexStr = BN_bn2hex(k);
  76526. ExpectStrEQ(hexStr, kTest);
  76527. #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM) && \
  76528. defined(XFPRINTF)
  76529. BN_print_fp(stderr, k);
  76530. fprintf(stderr, "\n");
  76531. #endif
  76532. XFREE(hexStr, NULL, DYNAMIC_TYPE_ECC);
  76533. hexStr = BN_bn2hex(Gx);
  76534. ExpectStrEQ(hexStr, kGx);
  76535. #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM) && \
  76536. defined(XFPRINTF)
  76537. BN_print_fp(stderr, Gx);
  76538. fprintf(stderr, "\n");
  76539. #endif
  76540. XFREE(hexStr, NULL, DYNAMIC_TYPE_ECC);
  76541. hexStr = BN_bn2hex(Gy);
  76542. ExpectStrEQ(hexStr, kGy);
  76543. #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM) && \
  76544. defined(XFPRINTF)
  76545. BN_print_fp(stderr, Gy);
  76546. fprintf(stderr, "\n");
  76547. #endif
  76548. XFREE(hexStr, NULL, DYNAMIC_TYPE_ECC);
  76549. /* Test point to hex */
  76550. ExpectNull(EC_POINT_point2hex(NULL, NULL, POINT_CONVERSION_UNCOMPRESSED,
  76551. ctx));
  76552. ExpectNull(EC_POINT_point2hex(NULL, Gxy, POINT_CONVERSION_UNCOMPRESSED,
  76553. ctx));
  76554. ExpectNull(EC_POINT_point2hex(group, NULL, POINT_CONVERSION_UNCOMPRESSED,
  76555. ctx));
  76556. #ifndef HAVE_ECC_BRAINPOOL
  76557. /* Group not supported in wolfCrypt. */
  76558. ExpectNull(EC_POINT_point2hex(group2, Gxy, POINT_CONVERSION_UNCOMPRESSED,
  76559. ctx));
  76560. #endif
  76561. hexStr = EC_POINT_point2hex(group, Gxy, POINT_CONVERSION_UNCOMPRESSED, ctx);
  76562. ExpectNotNull(hexStr);
  76563. ExpectStrEQ(hexStr, uncompG);
  76564. ExpectNotNull(get_point = EC_POINT_hex2point(group, hexStr, NULL, ctx));
  76565. ExpectIntEQ(EC_POINT_cmp(group, Gxy, get_point, ctx), 0);
  76566. XFREE(hexStr, NULL, DYNAMIC_TYPE_ECC);
  76567. hexStr = EC_POINT_point2hex(group, Gxy, POINT_CONVERSION_COMPRESSED, ctx);
  76568. ExpectNotNull(hexStr);
  76569. ExpectStrEQ(hexStr, compG);
  76570. #ifdef HAVE_COMP_KEY
  76571. ExpectNotNull(get_point = EC_POINT_hex2point
  76572. (group, hexStr, get_point, ctx));
  76573. ExpectIntEQ(EC_POINT_cmp(group, Gxy, get_point, ctx), 0);
  76574. #endif
  76575. XFREE(hexStr, NULL, DYNAMIC_TYPE_ECC);
  76576. EC_POINT_free(get_point);
  76577. #ifndef HAVE_SELFTEST
  76578. /* Test point to oct */
  76579. ExpectIntEQ(EC_POINT_point2oct(NULL, NULL, POINT_CONVERSION_UNCOMPRESSED,
  76580. NULL, 0, ctx), 0);
  76581. ExpectIntEQ(EC_POINT_point2oct(NULL, Gxy, POINT_CONVERSION_UNCOMPRESSED,
  76582. NULL, 0, ctx), 0);
  76583. ExpectIntEQ(EC_POINT_point2oct(group, NULL, POINT_CONVERSION_UNCOMPRESSED,
  76584. NULL, 0, ctx), 0);
  76585. bin_len = EC_POINT_point2oct(group, Gxy, POINT_CONVERSION_UNCOMPRESSED,
  76586. NULL, 0, ctx);
  76587. ExpectIntEQ(bin_len, sizeof(binUncompG));
  76588. ExpectNotNull(buf = (unsigned char*)XMALLOC(bin_len, NULL,
  76589. DYNAMIC_TYPE_ECC));
  76590. ExpectIntEQ(EC_POINT_point2oct(group, Gxy, POINT_CONVERSION_UNCOMPRESSED,
  76591. buf, bin_len, ctx), bin_len);
  76592. ExpectIntEQ(XMEMCMP(buf, binUncompG, sizeof(binUncompG)), 0);
  76593. XFREE(buf, NULL, DYNAMIC_TYPE_ECC);
  76594. /* Infinity (x=0, y=0) encodes as '0x00'. */
  76595. ExpectIntEQ(EC_POINT_point2oct(group, infinity,
  76596. POINT_CONVERSION_UNCOMPRESSED, NULL, 0, ctx), 1);
  76597. ExpectIntEQ(EC_POINT_point2oct(group, infinity,
  76598. POINT_CONVERSION_UNCOMPRESSED, bufInf, 0, ctx), 0);
  76599. ExpectIntEQ(EC_POINT_point2oct(group, infinity,
  76600. POINT_CONVERSION_UNCOMPRESSED, bufInf, 1, ctx), 1);
  76601. ExpectIntEQ(bufInf[0], 0);
  76602. wolfSSL_EC_POINT_dump(NULL, NULL);
  76603. /* Test point i2d */
  76604. ExpectIntEQ(ECPoint_i2d(NULL, NULL, NULL, &blen), 0);
  76605. ExpectIntEQ(ECPoint_i2d(NULL, Gxy, NULL, &blen), 0);
  76606. ExpectIntEQ(ECPoint_i2d(group, NULL, NULL, &blen), 0);
  76607. ExpectIntEQ(ECPoint_i2d(group, Gxy, NULL, NULL), 0);
  76608. ExpectIntEQ(ECPoint_i2d(group, Gxy, NULL, &blen), 1);
  76609. ExpectIntEQ(blen, sizeof(binUncompG));
  76610. ExpectNotNull(buf = (unsigned char*)XMALLOC(blen, NULL, DYNAMIC_TYPE_ECC));
  76611. blen -= 1;
  76612. ExpectIntEQ(ECPoint_i2d(group, Gxy, buf, &blen), 0);
  76613. blen += 1;
  76614. ExpectIntEQ(ECPoint_i2d(group, Gxy, buf, &blen), 1);
  76615. ExpectIntEQ(XMEMCMP(buf, binUncompG, sizeof(binUncompG)), 0);
  76616. XFREE(buf, NULL, DYNAMIC_TYPE_ECC);
  76617. #ifdef HAVE_COMP_KEY
  76618. /* Test point to oct compressed */
  76619. bin_len = EC_POINT_point2oct(group, Gxy, POINT_CONVERSION_COMPRESSED, NULL,
  76620. 0, ctx);
  76621. ExpectIntEQ(bin_len, sizeof(binCompG));
  76622. ExpectNotNull(buf = (unsigned char*)XMALLOC(bin_len, NULL,
  76623. DYNAMIC_TYPE_ECC));
  76624. ExpectIntEQ(EC_POINT_point2oct(group, Gxy, POINT_CONVERSION_COMPRESSED, buf,
  76625. bin_len, ctx), bin_len);
  76626. ExpectIntEQ(XMEMCMP(buf, binCompG, sizeof(binCompG)), 0);
  76627. XFREE(buf, NULL, DYNAMIC_TYPE_ECC);
  76628. #endif
  76629. /* Test point BN */
  76630. ExpectNull(wolfSSL_EC_POINT_point2bn(NULL, NULL,
  76631. POINT_CONVERSION_UNCOMPRESSED, NULL, ctx));
  76632. ExpectNull(wolfSSL_EC_POINT_point2bn(NULL, Gxy,
  76633. POINT_CONVERSION_UNCOMPRESSED, NULL, ctx));
  76634. ExpectNull(wolfSSL_EC_POINT_point2bn(group, NULL,
  76635. POINT_CONVERSION_UNCOMPRESSED, NULL, ctx));
  76636. ExpectNull(wolfSSL_EC_POINT_point2bn(group, Gxy, 0, NULL, ctx));
  76637. /* Test oct to point */
  76638. ExpectNotNull(tmp = EC_POINT_new(group));
  76639. ExpectIntEQ(EC_POINT_oct2point(NULL, NULL, binUncompG, sizeof(binUncompG),
  76640. ctx), 0);
  76641. ExpectIntEQ(EC_POINT_oct2point(NULL, tmp, binUncompG, sizeof(binUncompG),
  76642. ctx), 0);
  76643. ExpectIntEQ(EC_POINT_oct2point(group, NULL, binUncompG, sizeof(binUncompG),
  76644. ctx), 0);
  76645. ExpectIntEQ(EC_POINT_oct2point(group, tmp, binUncompGBad,
  76646. sizeof(binUncompGBad), ctx), 0);
  76647. ExpectIntEQ(EC_POINT_oct2point(group, tmp, binUncompG, sizeof(binUncompG),
  76648. ctx), 1);
  76649. ExpectIntEQ(EC_POINT_cmp(group, tmp, Gxy, ctx), 0);
  76650. EC_POINT_free(tmp);
  76651. tmp = NULL;
  76652. /* Test setting BN ordinates. */
  76653. ExpectNotNull(tmp = EC_POINT_new(group));
  76654. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(NULL, NULL, NULL,
  76655. NULL, ctx), 0);
  76656. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(group, NULL, NULL,
  76657. NULL, ctx), 0);
  76658. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(NULL, tmp, NULL,
  76659. NULL, ctx), 0);
  76660. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(NULL, NULL, Gx,
  76661. NULL, ctx), 0);
  76662. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(NULL, NULL, NULL,
  76663. Gy, ctx), 0);
  76664. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(NULL, tmp, Gx, Gy,
  76665. ctx), 0);
  76666. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(group, NULL, Gx, Gy,
  76667. ctx), 0);
  76668. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(group, tmp, NULL,
  76669. Gy, ctx), 0);
  76670. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(group, tmp, Gx,
  76671. NULL, ctx), 0);
  76672. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(group, tmp, Gx, Gy,
  76673. ctx), 1);
  76674. EC_POINT_free(tmp);
  76675. tmp = NULL;
  76676. /* Test point d2i */
  76677. ExpectNotNull(tmp = EC_POINT_new(group));
  76678. ExpectIntEQ(ECPoint_d2i(NULL, sizeof(binUncompG), NULL, NULL), 0);
  76679. ExpectIntEQ(ECPoint_d2i(binUncompG, sizeof(binUncompG), NULL, NULL), 0);
  76680. ExpectIntEQ(ECPoint_d2i(NULL, sizeof(binUncompG), group, NULL), 0);
  76681. ExpectIntEQ(ECPoint_d2i(NULL, sizeof(binUncompG), NULL, tmp), 0);
  76682. ExpectIntEQ(ECPoint_d2i(NULL, sizeof(binUncompG), group, tmp), 0);
  76683. ExpectIntEQ(ECPoint_d2i(binUncompG, sizeof(binUncompG), NULL, tmp), 0);
  76684. ExpectIntEQ(ECPoint_d2i(binUncompG, sizeof(binUncompG), group, NULL), 0);
  76685. ExpectIntEQ(ECPoint_d2i(binUncompGBad, sizeof(binUncompG), group, tmp), 0);
  76686. ExpectIntEQ(ECPoint_d2i(binUncompG, sizeof(binUncompG), group, tmp), 1);
  76687. ExpectIntEQ(EC_POINT_cmp(group, tmp, Gxy, ctx), 0);
  76688. EC_POINT_free(tmp);
  76689. tmp = NULL;
  76690. #ifdef HAVE_COMP_KEY
  76691. /* Test oct compressed to point */
  76692. ExpectNotNull(tmp = EC_POINT_new(group));
  76693. ExpectIntEQ(EC_POINT_oct2point(group, tmp, binCompG, sizeof(binCompG), ctx),
  76694. 1);
  76695. ExpectIntEQ(EC_POINT_cmp(group, tmp, Gxy, ctx), 0);
  76696. EC_POINT_free(tmp);
  76697. tmp = NULL;
  76698. /* Test point d2i - compressed */
  76699. ExpectNotNull(tmp = EC_POINT_new(group));
  76700. ExpectIntEQ(ECPoint_d2i(binCompG, sizeof(binCompG), group, tmp), 1);
  76701. ExpectIntEQ(EC_POINT_cmp(group, tmp, Gxy, ctx), 0);
  76702. EC_POINT_free(tmp);
  76703. tmp = NULL;
  76704. #endif
  76705. #endif
  76706. /* test BN_mod_add */
  76707. ExpectIntEQ(BN_mod_add(new_point->Z, (WOLFSSL_BIGNUM*)BN_value_one(),
  76708. (WOLFSSL_BIGNUM*)BN_value_one(), (WOLFSSL_BIGNUM*)BN_value_one(), NULL),
  76709. 1);
  76710. ExpectIntEQ(BN_is_zero(new_point->Z), 1);
  76711. /* cleanup */
  76712. BN_free(X);
  76713. BN_free(Y);
  76714. BN_free(k);
  76715. BN_free(set_point_bn);
  76716. EC_POINT_free(infinity);
  76717. EC_POINT_free(new_point);
  76718. EC_POINT_free(set_point);
  76719. EC_POINT_clear_free(Gxy);
  76720. #ifndef HAVE_ECC_BRAINPOOL
  76721. EC_GROUP_free(group2);
  76722. #endif
  76723. EC_GROUP_free(group);
  76724. BN_CTX_free(ctx);
  76725. #endif
  76726. #endif /* !WOLFSSL_SP_MATH && ( !HAVE_FIPS || HAVE_FIPS_VERSION > 2) */
  76727. return EXPECT_RESULT();
  76728. }
  76729. static int test_wolfSSL_SPAKE(void)
  76730. {
  76731. EXPECT_DECLS;
  76732. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && !defined(WOLFSSL_ATECC508A) \
  76733. && !defined(WOLFSSL_ATECC608A) && !defined(HAVE_SELFTEST) && \
  76734. !defined(WOLFSSL_SP_MATH) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  76735. BIGNUM* x = NULL; /* kdc priv */
  76736. BIGNUM* y = NULL; /* client priv */
  76737. BIGNUM* w = NULL; /* shared value */
  76738. byte M_bytes[] = {
  76739. /* uncompressed */
  76740. 0x04,
  76741. /* x */
  76742. 0x88, 0x6e, 0x2f, 0x97, 0xac, 0xe4, 0x6e, 0x55, 0xba, 0x9d, 0xd7, 0x24,
  76743. 0x25, 0x79, 0xf2, 0x99, 0x3b, 0x64, 0xe1, 0x6e, 0xf3, 0xdc, 0xab, 0x95,
  76744. 0xaf, 0xd4, 0x97, 0x33, 0x3d, 0x8f, 0xa1, 0x2f,
  76745. /* y */
  76746. 0x5f, 0xf3, 0x55, 0x16, 0x3e, 0x43, 0xce, 0x22, 0x4e, 0x0b, 0x0e, 0x65,
  76747. 0xff, 0x02, 0xac, 0x8e, 0x5c, 0x7b, 0xe0, 0x94, 0x19, 0xc7, 0x85, 0xe0,
  76748. 0xca, 0x54, 0x7d, 0x55, 0xa1, 0x2e, 0x2d, 0x20
  76749. };
  76750. EC_POINT* M = NULL; /* shared value */
  76751. byte N_bytes[] = {
  76752. /* uncompressed */
  76753. 0x04,
  76754. /* x */
  76755. 0xd8, 0xbb, 0xd6, 0xc6, 0x39, 0xc6, 0x29, 0x37, 0xb0, 0x4d, 0x99, 0x7f,
  76756. 0x38, 0xc3, 0x77, 0x07, 0x19, 0xc6, 0x29, 0xd7, 0x01, 0x4d, 0x49, 0xa2,
  76757. 0x4b, 0x4f, 0x98, 0xba, 0xa1, 0x29, 0x2b, 0x49,
  76758. /* y */
  76759. 0x07, 0xd6, 0x0a, 0xa6, 0xbf, 0xad, 0xe4, 0x50, 0x08, 0xa6, 0x36, 0x33,
  76760. 0x7f, 0x51, 0x68, 0xc6, 0x4d, 0x9b, 0xd3, 0x60, 0x34, 0x80, 0x8c, 0xd5,
  76761. 0x64, 0x49, 0x0b, 0x1e, 0x65, 0x6e, 0xdb, 0xe7
  76762. };
  76763. EC_POINT* N = NULL; /* shared value */
  76764. EC_POINT* T = NULL; /* kdc pub */
  76765. EC_POINT* tmp1 = NULL; /* kdc pub */
  76766. EC_POINT* tmp2 = NULL; /* kdc pub */
  76767. EC_POINT* S = NULL; /* client pub */
  76768. EC_POINT* client_secret = NULL;
  76769. EC_POINT* kdc_secret = NULL;
  76770. EC_GROUP* group = NULL;
  76771. BN_CTX* bn_ctx = NULL;
  76772. /* Values taken from a test run of Kerberos 5 */
  76773. ExpectNotNull(group = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
  76774. ExpectNotNull(bn_ctx = BN_CTX_new());
  76775. ExpectNotNull(M = EC_POINT_new(group));
  76776. ExpectNotNull(N = EC_POINT_new(group));
  76777. ExpectNotNull(T = EC_POINT_new(group));
  76778. ExpectNotNull(tmp1 = EC_POINT_new(group));
  76779. ExpectNotNull(tmp2 = EC_POINT_new(group));
  76780. ExpectNotNull(S = EC_POINT_new(group));
  76781. ExpectNotNull(client_secret = EC_POINT_new(group));
  76782. ExpectNotNull(kdc_secret = EC_POINT_new(group));
  76783. ExpectIntEQ(BN_hex2bn(&x, "DAC3027CD692B4BDF0EDFE9B7D0E4E7"
  76784. "E5D8768A725EAEEA6FC68EC239A17C0"), 1);
  76785. ExpectIntEQ(BN_hex2bn(&y, "6F6A1D394E26B1655A54B26DCE30D49"
  76786. "90CC47EBE08F809EF3FF7F6AEAABBB5"), 1);
  76787. ExpectIntEQ(BN_hex2bn(&w, "1D992AB8BA851B9BA05353453D81EE9"
  76788. "506AB395478F0AAB647752CF117B36250"), 1);
  76789. ExpectIntEQ(EC_POINT_oct2point(group, M, M_bytes, sizeof(M_bytes), bn_ctx),
  76790. 1);
  76791. ExpectIntEQ(EC_POINT_oct2point(group, N, N_bytes, sizeof(N_bytes), bn_ctx),
  76792. 1);
  76793. /* Function pattern similar to ossl_keygen and ossl_result in krb5 */
  76794. /* kdc */
  76795. /* T=x*P+w*M */
  76796. /* All in one function call */
  76797. ExpectIntEQ(EC_POINT_mul(group, T, x, M, w, bn_ctx), 1);
  76798. /* Spread into separate calls */
  76799. ExpectIntEQ(EC_POINT_mul(group, tmp1, x, NULL, NULL, bn_ctx), 1);
  76800. ExpectIntEQ(EC_POINT_mul(group, tmp2, NULL, M, w, bn_ctx), 1);
  76801. ExpectIntEQ(EC_POINT_add(group, tmp1, tmp1, tmp2, bn_ctx),
  76802. 1);
  76803. ExpectIntEQ(EC_POINT_cmp(group, T, tmp1, bn_ctx), 0);
  76804. /* client */
  76805. /* S=y*P+w*N */
  76806. /* All in one function call */
  76807. ExpectIntEQ(EC_POINT_mul(group, S, y, N, w, bn_ctx), 1);
  76808. /* Spread into separate calls */
  76809. ExpectIntEQ(EC_POINT_mul(group, tmp1, y, NULL, NULL, bn_ctx), 1);
  76810. ExpectIntEQ(EC_POINT_mul(group, tmp2, NULL, N, w, bn_ctx), 1);
  76811. ExpectIntEQ(EC_POINT_add(group, tmp1, tmp1, tmp2, bn_ctx),
  76812. 1);
  76813. ExpectIntEQ(EC_POINT_cmp(group, S, tmp1, bn_ctx), 0);
  76814. /* K=y*(T-w*M) */
  76815. ExpectIntEQ(EC_POINT_mul(group, client_secret, NULL, M, w, bn_ctx), 1);
  76816. ExpectIntEQ(EC_POINT_invert(group, client_secret, bn_ctx), 1);
  76817. ExpectIntEQ(EC_POINT_add(group, client_secret, T, client_secret, bn_ctx),
  76818. 1);
  76819. ExpectIntEQ(EC_POINT_mul(group, client_secret, NULL, client_secret, y,
  76820. bn_ctx), 1);
  76821. /* kdc */
  76822. /* K=x*(S-w*N) */
  76823. ExpectIntEQ(EC_POINT_mul(group, kdc_secret, NULL, N, w, bn_ctx), 1);
  76824. ExpectIntEQ(EC_POINT_invert(group, kdc_secret, bn_ctx), 1);
  76825. ExpectIntEQ(EC_POINT_add(group, kdc_secret, S, kdc_secret, bn_ctx),
  76826. 1);
  76827. ExpectIntEQ(EC_POINT_mul(group, kdc_secret, NULL, kdc_secret, x, bn_ctx),
  76828. 1);
  76829. /* kdc_secret == client_secret */
  76830. ExpectIntEQ(EC_POINT_cmp(group, client_secret, kdc_secret, bn_ctx), 0);
  76831. BN_free(x);
  76832. BN_free(y);
  76833. BN_free(w);
  76834. EC_POINT_free(M);
  76835. EC_POINT_free(N);
  76836. EC_POINT_free(T);
  76837. EC_POINT_free(tmp1);
  76838. EC_POINT_free(tmp2);
  76839. EC_POINT_free(S);
  76840. EC_POINT_free(client_secret);
  76841. EC_POINT_free(kdc_secret);
  76842. EC_GROUP_free(group);
  76843. BN_CTX_free(bn_ctx);
  76844. #endif
  76845. return EXPECT_RESULT();
  76846. }
  76847. static int test_wolfSSL_EC_KEY_generate(void)
  76848. {
  76849. EXPECT_DECLS;
  76850. #ifdef OPENSSL_EXTRA
  76851. WOLFSSL_EC_KEY* key = NULL;
  76852. #ifndef HAVE_ECC_BRAINPOOL
  76853. WOLFSSL_EC_GROUP* group = NULL;
  76854. #endif
  76855. ExpectNotNull(key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  76856. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(NULL), 0);
  76857. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(key), 1);
  76858. wolfSSL_EC_KEY_free(key);
  76859. key = NULL;
  76860. #ifndef HAVE_ECC_BRAINPOOL
  76861. ExpectNotNull(group = wolfSSL_EC_GROUP_new_by_curve_name(
  76862. NID_brainpoolP256r1));
  76863. ExpectNotNull(key = wolfSSL_EC_KEY_new());
  76864. ExpectIntEQ(wolfSSL_EC_KEY_set_group(key, group), 1);
  76865. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(key), 0);
  76866. wolfSSL_EC_KEY_free(key);
  76867. wolfSSL_EC_GROUP_free(group);
  76868. #endif
  76869. #endif
  76870. return EXPECT_RESULT();
  76871. }
  76872. static int test_EC_i2d(void)
  76873. {
  76874. EXPECT_DECLS;
  76875. #if defined(OPENSSL_EXTRA) && !defined(HAVE_FIPS)
  76876. EC_KEY *key = NULL;
  76877. EC_KEY *copy = NULL;
  76878. int len = 0;
  76879. unsigned char *buf = NULL;
  76880. unsigned char *p = NULL;
  76881. const unsigned char *tmp = NULL;
  76882. const unsigned char octBad[] = {
  76883. 0x09, 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc,
  76884. 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2, 0x77, 0x03, 0x7d, 0x81, 0x2d,
  76885. 0xeb, 0x33, 0xa0, 0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
  76886. 0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b, 0x8e, 0xe7, 0xeb,
  76887. 0x4a, 0x7c, 0x0f, 0x9e, 0x16, 0x2b, 0xce, 0x33, 0x57, 0x6b, 0x31,
  76888. 0x5e, 0xce, 0xcb, 0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf5,
  76889. };
  76890. ExpectNotNull(key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  76891. ExpectIntEQ(EC_KEY_generate_key(key), 1);
  76892. ExpectIntGT((len = i2d_EC_PUBKEY(key, NULL)), 0);
  76893. ExpectNotNull(buf = (unsigned char*)XMALLOC(len, NULL,
  76894. DYNAMIC_TYPE_TMP_BUFFER));
  76895. p = buf;
  76896. ExpectIntEQ(i2d_EC_PUBKEY(key, &p), len);
  76897. ExpectNull(o2i_ECPublicKey(NULL, NULL, -1));
  76898. ExpectNull(o2i_ECPublicKey(&copy, NULL, -1));
  76899. ExpectNull(o2i_ECPublicKey(&key, NULL, -1));
  76900. ExpectNull(o2i_ECPublicKey(NULL, &tmp, -1));
  76901. ExpectNull(o2i_ECPublicKey(NULL, NULL, 0));
  76902. ExpectNull(o2i_ECPublicKey(&key, NULL, 0));
  76903. ExpectNull(o2i_ECPublicKey(&key, &tmp, 0));
  76904. tmp = buf;
  76905. ExpectNull(o2i_ECPublicKey(NULL, &tmp, 0));
  76906. ExpectNull(o2i_ECPublicKey(&copy, &tmp, 0));
  76907. ExpectNull(o2i_ECPublicKey(NULL, &tmp, -1));
  76908. ExpectNull(o2i_ECPublicKey(&key, &tmp, -1));
  76909. ExpectIntEQ(i2o_ECPublicKey(NULL, NULL), 0);
  76910. ExpectIntEQ(i2o_ECPublicKey(NULL, &buf), 0);
  76911. tmp = buf;
  76912. ExpectNull(d2i_ECPrivateKey(NULL, &tmp, 0));
  76913. ExpectNull(d2i_ECPrivateKey(NULL, &tmp, 1));
  76914. ExpectNull(d2i_ECPrivateKey(&copy, &tmp, 0));
  76915. ExpectNull(d2i_ECPrivateKey(&copy, &tmp, 1));
  76916. ExpectNull(d2i_ECPrivateKey(&key, &tmp, 0));
  76917. {
  76918. EC_KEY *pubkey = NULL;
  76919. BIO* bio = NULL;
  76920. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  76921. ExpectIntGT(BIO_write(bio, buf, len), 0);
  76922. ExpectNotNull(d2i_EC_PUBKEY_bio(bio, &pubkey));
  76923. BIO_free(bio);
  76924. EC_KEY_free(pubkey);
  76925. }
  76926. ExpectIntEQ(i2d_ECPrivateKey(NULL, &p), 0);
  76927. ExpectIntEQ(i2d_ECPrivateKey(NULL, NULL), 0);
  76928. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer(NULL, NULL, -1), -1);
  76929. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(NULL, NULL, -1, 0), -1);
  76930. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, NULL, -1, 0), -1);
  76931. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(NULL, buf, -1, 0), -1);
  76932. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(NULL, NULL, 0, 0), -1);
  76933. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(NULL, NULL, -1,
  76934. WOLFSSL_EC_KEY_LOAD_PUBLIC), -1);
  76935. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(NULL, buf, len,
  76936. WOLFSSL_EC_KEY_LOAD_PUBLIC), -1);
  76937. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, NULL, len,
  76938. WOLFSSL_EC_KEY_LOAD_PUBLIC), -1);
  76939. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, buf, -1,
  76940. WOLFSSL_EC_KEY_LOAD_PUBLIC), -1);
  76941. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, buf, len, 0), -1);
  76942. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, buf, len,
  76943. WOLFSSL_EC_KEY_LOAD_PRIVATE), -1);
  76944. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, octBad, sizeof(octBad),
  76945. WOLFSSL_EC_KEY_LOAD_PRIVATE), -1);
  76946. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, octBad, sizeof(octBad),
  76947. WOLFSSL_EC_KEY_LOAD_PUBLIC), -1);
  76948. XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  76949. buf = NULL;
  76950. buf = NULL;
  76951. ExpectIntGT((len = i2d_ECPrivateKey(key, NULL)), 0);
  76952. ExpectNotNull(buf = (unsigned char*)XMALLOC(len, NULL,
  76953. DYNAMIC_TYPE_TMP_BUFFER));
  76954. p = buf;
  76955. ExpectIntEQ(i2d_ECPrivateKey(key, &p), len);
  76956. p = NULL;
  76957. ExpectIntEQ(i2d_ECPrivateKey(key, &p), len);
  76958. XFREE(p, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  76959. p = NULL;
  76960. /* Bad point is also an invalid private key. */
  76961. tmp = octBad;
  76962. ExpectNull(d2i_ECPrivateKey(&copy, &tmp, sizeof(octBad)));
  76963. tmp = buf;
  76964. ExpectNotNull(d2i_ECPrivateKey(&copy, &tmp, len));
  76965. XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  76966. buf = NULL;
  76967. buf = NULL;
  76968. ExpectIntGT((len = i2o_ECPublicKey(key, NULL)), 0);
  76969. ExpectNotNull(buf = (unsigned char*)XMALLOC(len, NULL,
  76970. DYNAMIC_TYPE_TMP_BUFFER));
  76971. p = buf;
  76972. ExpectIntGT((len = i2o_ECPublicKey(key, &p)), 0);
  76973. p = NULL;
  76974. ExpectIntGT((len = i2o_ECPublicKey(key, &p)), 0);
  76975. tmp = buf;
  76976. ExpectNotNull(o2i_ECPublicKey(&copy, &tmp, len));
  76977. tmp = octBad;
  76978. ExpectNull(o2i_ECPublicKey(&key, &tmp, sizeof(octBad)));
  76979. ExpectIntEQ(EC_KEY_check_key(NULL), 0);
  76980. ExpectIntEQ(EC_KEY_check_key(key), 1);
  76981. XFREE(p, NULL, DYNAMIC_TYPE_OPENSSL);
  76982. XFREE(buf, NULL, DYNAMIC_TYPE_OPENSSL);
  76983. EC_KEY_free(key);
  76984. EC_KEY_free(copy);
  76985. #endif
  76986. return EXPECT_RESULT();
  76987. }
  76988. static int test_wolfSSL_EC_curve(void)
  76989. {
  76990. EXPECT_DECLS;
  76991. #if defined(OPENSSL_EXTRA)
  76992. int nid = NID_secp160k1;
  76993. const char* nid_name = NULL;
  76994. ExpectNull(EC_curve_nid2nist(NID_sha256));
  76995. ExpectNotNull(nid_name = EC_curve_nid2nist(nid));
  76996. ExpectIntEQ(XMEMCMP(nid_name, "K-160", XSTRLEN("K-160")), 0);
  76997. ExpectIntEQ(EC_curve_nist2nid("INVALID"), 0);
  76998. ExpectIntEQ(EC_curve_nist2nid(nid_name), nid);
  76999. #endif
  77000. return EXPECT_RESULT();
  77001. }
  77002. static int test_wolfSSL_EC_KEY_dup(void)
  77003. {
  77004. EXPECT_DECLS;
  77005. #if defined(OPENSSL_ALL) && !defined(NO_CERTS)
  77006. WOLFSSL_EC_KEY* ecKey = NULL;
  77007. WOLFSSL_EC_KEY* dupKey = NULL;
  77008. ecc_key* srcKey = NULL;
  77009. ecc_key* destKey = NULL;
  77010. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  77011. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  77012. /* Valid cases */
  77013. ExpectNotNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  77014. ExpectIntEQ(EC_KEY_check_key(dupKey), 1);
  77015. /* Compare pubkey */
  77016. if (ecKey != NULL) {
  77017. srcKey = (ecc_key*)ecKey->internal;
  77018. }
  77019. if (dupKey != NULL) {
  77020. destKey = (ecc_key*)dupKey->internal;
  77021. }
  77022. ExpectIntEQ(wc_ecc_cmp_point(&srcKey->pubkey, &destKey->pubkey), 0);
  77023. /* compare EC_GROUP */
  77024. ExpectIntEQ(wolfSSL_EC_GROUP_cmp(ecKey->group, dupKey->group, NULL), MP_EQ);
  77025. /* compare EC_POINT */
  77026. ExpectIntEQ(wolfSSL_EC_POINT_cmp(ecKey->group, ecKey->pub_key, \
  77027. dupKey->pub_key, NULL), MP_EQ);
  77028. /* compare BIGNUM */
  77029. ExpectIntEQ(wolfSSL_BN_cmp(ecKey->priv_key, dupKey->priv_key), MP_EQ);
  77030. wolfSSL_EC_KEY_free(dupKey);
  77031. dupKey = NULL;
  77032. /* Invalid cases */
  77033. /* NULL key */
  77034. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(NULL));
  77035. /* NULL ecc_key */
  77036. if (ecKey != NULL) {
  77037. wc_ecc_free((ecc_key*)ecKey->internal);
  77038. XFREE(ecKey->internal, NULL, DYNAMIC_TYPE_ECC);
  77039. ecKey->internal = NULL; /* Set ecc_key to NULL */
  77040. }
  77041. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  77042. wolfSSL_EC_KEY_free(ecKey);
  77043. ecKey = NULL;
  77044. wolfSSL_EC_KEY_free(dupKey);
  77045. dupKey = NULL;
  77046. /* NULL Group */
  77047. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  77048. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  77049. if (ecKey != NULL) {
  77050. wolfSSL_EC_GROUP_free(ecKey->group);
  77051. ecKey->group = NULL; /* Set group to NULL */
  77052. }
  77053. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  77054. wolfSSL_EC_KEY_free(ecKey);
  77055. ecKey = NULL;
  77056. wolfSSL_EC_KEY_free(dupKey);
  77057. dupKey = NULL;
  77058. /* NULL public key */
  77059. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  77060. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  77061. if (ecKey != NULL) {
  77062. wc_ecc_del_point((ecc_point*)ecKey->pub_key->internal);
  77063. ecKey->pub_key->internal = NULL; /* Set ecc_point to NULL */
  77064. }
  77065. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  77066. if (ecKey != NULL) {
  77067. wolfSSL_EC_POINT_free(ecKey->pub_key);
  77068. ecKey->pub_key = NULL; /* Set pub_key to NULL */
  77069. }
  77070. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  77071. wolfSSL_EC_KEY_free(ecKey);
  77072. ecKey = NULL;
  77073. wolfSSL_EC_KEY_free(dupKey);
  77074. dupKey = NULL;
  77075. /* NULL private key */
  77076. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  77077. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  77078. if (ecKey != NULL) {
  77079. wolfSSL_BN_free(ecKey->priv_key);
  77080. ecKey->priv_key = NULL; /* Set priv_key to NULL */
  77081. }
  77082. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  77083. wolfSSL_EC_KEY_free(ecKey);
  77084. ecKey = NULL;
  77085. wolfSSL_EC_KEY_free(dupKey);
  77086. dupKey = NULL;
  77087. /* Test EC_KEY_up_ref */
  77088. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  77089. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), WOLFSSL_SUCCESS);
  77090. ExpectIntEQ(wolfSSL_EC_KEY_up_ref(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  77091. ExpectIntEQ(wolfSSL_EC_KEY_up_ref(ecKey), WOLFSSL_SUCCESS);
  77092. /* reference count doesn't follow duplicate */
  77093. ExpectNotNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  77094. ExpectIntEQ(wolfSSL_EC_KEY_up_ref(dupKey), WOLFSSL_SUCCESS); /* +1 */
  77095. ExpectIntEQ(wolfSSL_EC_KEY_up_ref(dupKey), WOLFSSL_SUCCESS); /* +2 */
  77096. wolfSSL_EC_KEY_free(dupKey); /* 3 */
  77097. wolfSSL_EC_KEY_free(dupKey); /* 2 */
  77098. wolfSSL_EC_KEY_free(dupKey); /* 1, free */
  77099. wolfSSL_EC_KEY_free(ecKey); /* 2 */
  77100. wolfSSL_EC_KEY_free(ecKey); /* 1, free */
  77101. #endif
  77102. return EXPECT_RESULT();
  77103. }
  77104. static int test_wolfSSL_EC_KEY_set_group(void)
  77105. {
  77106. EXPECT_DECLS;
  77107. #if defined(HAVE_ECC) && !defined(NO_ECC256) && !defined(NO_ECC_SECP) && \
  77108. defined(OPENSSL_EXTRA)
  77109. EC_KEY *key = NULL;
  77110. EC_GROUP *group = NULL;
  77111. const EC_GROUP *group2 = NULL;
  77112. ExpectNotNull(group = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
  77113. ExpectNotNull(key = EC_KEY_new());
  77114. ExpectNull(EC_KEY_get0_group(NULL));
  77115. ExpectIntEQ(EC_KEY_set_group(NULL, NULL), 0);
  77116. ExpectIntEQ(EC_KEY_set_group(key, NULL), 0);
  77117. ExpectIntEQ(EC_KEY_set_group(NULL, group), 0);
  77118. ExpectIntEQ(EC_KEY_set_group(key, group), WOLFSSL_SUCCESS);
  77119. ExpectNotNull(group2 = EC_KEY_get0_group(key));
  77120. ExpectIntEQ(EC_GROUP_cmp(group2, group, NULL), 0);
  77121. EC_GROUP_free(group);
  77122. EC_KEY_free(key);
  77123. #endif
  77124. return EXPECT_RESULT();
  77125. }
  77126. static int test_wolfSSL_EC_KEY_set_conv_form(void)
  77127. {
  77128. EXPECT_DECLS;
  77129. #if defined(HAVE_ECC) && defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  77130. BIO* bio = NULL;
  77131. EC_KEY* key = NULL;
  77132. /* Error condition: NULL key. */
  77133. ExpectIntLT(EC_KEY_get_conv_form(NULL), 0);
  77134. ExpectNotNull(bio = BIO_new_file("./certs/ecc-keyPub.pem", "rb"));
  77135. ExpectNotNull(key = PEM_read_bio_EC_PUBKEY(bio, NULL, NULL, NULL));
  77136. /* Conversion form defaults to uncompressed. */
  77137. ExpectIntEQ(EC_KEY_get_conv_form(key), POINT_CONVERSION_UNCOMPRESSED);
  77138. #ifdef HAVE_COMP_KEY
  77139. /* Explicitly set to compressed. */
  77140. EC_KEY_set_conv_form(key, POINT_CONVERSION_COMPRESSED);
  77141. ExpectIntEQ(EC_KEY_get_conv_form(key), POINT_CONVERSION_COMPRESSED);
  77142. #else
  77143. /* Will still work just won't change anything. */
  77144. EC_KEY_set_conv_form(key, POINT_CONVERSION_COMPRESSED);
  77145. ExpectIntEQ(EC_KEY_get_conv_form(key), POINT_CONVERSION_UNCOMPRESSED);
  77146. EC_KEY_set_conv_form(key, POINT_CONVERSION_UNCOMPRESSED);
  77147. ExpectIntEQ(EC_KEY_get_conv_form(key), POINT_CONVERSION_UNCOMPRESSED);
  77148. #endif
  77149. EC_KEY_set_conv_form(NULL, POINT_CONVERSION_UNCOMPRESSED);
  77150. BIO_free(bio);
  77151. EC_KEY_free(key);
  77152. #endif
  77153. return EXPECT_RESULT();
  77154. }
  77155. static int test_wolfSSL_EC_KEY_private_key(void)
  77156. {
  77157. EXPECT_DECLS;
  77158. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  77159. WOLFSSL_EC_KEY* key = NULL;
  77160. WOLFSSL_BIGNUM* priv = NULL;
  77161. WOLFSSL_BIGNUM* priv2 = NULL;
  77162. WOLFSSL_BIGNUM* bn;
  77163. ExpectNotNull(key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  77164. ExpectNotNull(priv = wolfSSL_BN_new());
  77165. ExpectNotNull(priv2 = wolfSSL_BN_new());
  77166. ExpectIntNE(BN_set_word(priv, 2), 0);
  77167. ExpectIntNE(BN_set_word(priv2, 2), 0);
  77168. ExpectNull(wolfSSL_EC_KEY_get0_private_key(NULL));
  77169. /* No private key set. */
  77170. ExpectNull(wolfSSL_EC_KEY_get0_private_key(key));
  77171. ExpectIntEQ(wolfSSL_EC_KEY_set_private_key(NULL, NULL), 0);
  77172. ExpectIntEQ(wolfSSL_EC_KEY_set_private_key(key, NULL), 0);
  77173. ExpectIntEQ(wolfSSL_EC_KEY_set_private_key(NULL, priv), 0);
  77174. ExpectIntEQ(wolfSSL_EC_KEY_set_private_key(key, priv), 1);
  77175. ExpectNotNull(bn = wolfSSL_EC_KEY_get0_private_key(key));
  77176. ExpectPtrNE(bn, priv);
  77177. ExpectIntEQ(wolfSSL_EC_KEY_set_private_key(key, priv2), 1);
  77178. ExpectNotNull(bn = wolfSSL_EC_KEY_get0_private_key(key));
  77179. ExpectPtrNE(bn, priv2);
  77180. wolfSSL_BN_free(priv2);
  77181. wolfSSL_BN_free(priv);
  77182. wolfSSL_EC_KEY_free(key);
  77183. #endif
  77184. return EXPECT_RESULT();
  77185. }
  77186. static int test_wolfSSL_EC_KEY_public_key(void)
  77187. {
  77188. EXPECT_DECLS;
  77189. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  77190. WOLFSSL_EC_KEY* key = NULL;
  77191. WOLFSSL_EC_POINT* pub = NULL;
  77192. WOLFSSL_EC_POINT* point = NULL;
  77193. ExpectNotNull(key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  77194. ExpectNull(wolfSSL_EC_KEY_get0_public_key(NULL));
  77195. ExpectNotNull(wolfSSL_EC_KEY_get0_public_key(key));
  77196. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(key), 1);
  77197. ExpectNotNull(pub = wolfSSL_EC_KEY_get0_public_key(key));
  77198. ExpectIntEQ(wolfSSL_EC_KEY_set_public_key(NULL, NULL), 0);
  77199. ExpectIntEQ(wolfSSL_EC_KEY_set_public_key(key, NULL), 0);
  77200. ExpectIntEQ(wolfSSL_EC_KEY_set_public_key(NULL, pub), 0);
  77201. ExpectIntEQ(wolfSSL_EC_KEY_set_public_key(key, pub), 1);
  77202. ExpectNotNull(point = wolfSSL_EC_KEY_get0_public_key(key));
  77203. ExpectPtrEq(point, pub);
  77204. wolfSSL_EC_KEY_free(key);
  77205. #endif
  77206. return EXPECT_RESULT();
  77207. }
  77208. static int test_wolfSSL_EC_KEY_print_fp(void)
  77209. {
  77210. EXPECT_DECLS;
  77211. #if defined(HAVE_ECC) && ((defined(HAVE_ECC224) && defined(HAVE_ECC256)) || \
  77212. defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 224 && \
  77213. defined(OPENSSL_EXTRA) && defined(XFPRINTF) && !defined(NO_FILESYSTEM) && \
  77214. !defined(NO_STDIO_FILESYSTEM)
  77215. EC_KEY* key = NULL;
  77216. /* Bad file pointer. */
  77217. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(NULL, key, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  77218. /* NULL key. */
  77219. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(stderr, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  77220. ExpectNotNull((key = wolfSSL_EC_KEY_new_by_curve_name(NID_secp224r1)));
  77221. /* Negative indent. */
  77222. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(stderr, key, -1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  77223. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(stderr, key, 4), WOLFSSL_SUCCESS);
  77224. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(key), WOLFSSL_SUCCESS);
  77225. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(stderr, key, 4), WOLFSSL_SUCCESS);
  77226. wolfSSL_EC_KEY_free(key);
  77227. ExpectNotNull((key = wolfSSL_EC_KEY_new_by_curve_name(
  77228. NID_X9_62_prime256v1)));
  77229. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(key), WOLFSSL_SUCCESS);
  77230. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(stderr, key, 4), WOLFSSL_SUCCESS);
  77231. wolfSSL_EC_KEY_free(key);
  77232. #endif
  77233. return EXPECT_RESULT();
  77234. }
  77235. static int test_wolfSSL_EC_get_builtin_curves(void)
  77236. {
  77237. EXPECT_DECLS;
  77238. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)
  77239. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  77240. EC_builtin_curve* curves = NULL;
  77241. size_t crv_len = 0;
  77242. size_t i = 0;
  77243. ExpectIntGT((crv_len = EC_get_builtin_curves(NULL, 0)), 0);
  77244. ExpectNotNull(curves = (EC_builtin_curve*)XMALLOC(
  77245. sizeof(EC_builtin_curve) * crv_len, NULL, DYNAMIC_TYPE_TMP_BUFFER));
  77246. ExpectIntEQ((EC_get_builtin_curves(curves, 0)), crv_len);
  77247. ExpectIntEQ(EC_get_builtin_curves(curves, crv_len), crv_len);
  77248. for (i = 0; EXPECT_SUCCESS() && (i < crv_len); i++) {
  77249. if (curves[i].comment != NULL) {
  77250. ExpectStrEQ(OBJ_nid2sn(curves[i].nid), curves[i].comment);
  77251. }
  77252. }
  77253. if (crv_len > 1) {
  77254. ExpectIntEQ(EC_get_builtin_curves(curves, crv_len - 1), crv_len - 1);
  77255. }
  77256. XFREE(curves, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  77257. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  77258. #endif /* OPENSSL_EXTRA || OPENSSL_ALL */
  77259. return EXPECT_RESULT();
  77260. }
  77261. static int test_wolfSSL_ECDSA_SIG(void)
  77262. {
  77263. EXPECT_DECLS;
  77264. #ifdef OPENSSL_EXTRA
  77265. WOLFSSL_ECDSA_SIG* sig = NULL;
  77266. WOLFSSL_ECDSA_SIG* sig2 = NULL;
  77267. WOLFSSL_BIGNUM* r = NULL;
  77268. WOLFSSL_BIGNUM* s = NULL;
  77269. const WOLFSSL_BIGNUM* r2 = NULL;
  77270. const WOLFSSL_BIGNUM* s2 = NULL;
  77271. const unsigned char* cp = NULL;
  77272. unsigned char* p = NULL;
  77273. unsigned char outSig[8];
  77274. unsigned char sigData[8] =
  77275. { 0x30, 0x06, 0x02, 0x01, 0x01, 0x02, 0x01, 0x01 };
  77276. unsigned char sigDataBad[8] =
  77277. { 0x30, 0x07, 0x02, 0x01, 0x01, 0x02, 0x01, 0x01 };
  77278. wolfSSL_ECDSA_SIG_free(NULL);
  77279. ExpectNotNull(sig = wolfSSL_ECDSA_SIG_new());
  77280. ExpectNotNull(r = wolfSSL_BN_new());
  77281. ExpectNotNull(s = wolfSSL_BN_new());
  77282. ExpectIntEQ(wolfSSL_BN_set_word(r, 1), 1);
  77283. ExpectIntEQ(wolfSSL_BN_set_word(s, 1), 1);
  77284. wolfSSL_ECDSA_SIG_get0(NULL, NULL, NULL);
  77285. wolfSSL_ECDSA_SIG_get0(NULL, &r2, NULL);
  77286. wolfSSL_ECDSA_SIG_get0(NULL, NULL, &s2);
  77287. wolfSSL_ECDSA_SIG_get0(NULL, &r2, &s2);
  77288. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(NULL, NULL, NULL), 0);
  77289. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(sig, NULL, NULL), 0);
  77290. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(NULL, r, NULL), 0);
  77291. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(NULL, NULL, s), 0);
  77292. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(NULL, r, s), 0);
  77293. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(sig, NULL, s), 0);
  77294. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(sig, r, NULL), 0);
  77295. r2 = NULL;
  77296. s2 = NULL;
  77297. wolfSSL_ECDSA_SIG_get0(NULL, &r2, &s2);
  77298. ExpectNull(r2);
  77299. ExpectNull(s2);
  77300. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(sig, r, s), 1);
  77301. if (EXPECT_FAIL()) {
  77302. wolfSSL_BN_free(r);
  77303. wolfSSL_BN_free(s);
  77304. }
  77305. wolfSSL_ECDSA_SIG_get0(sig, &r2, &s2);
  77306. ExpectPtrEq(r2, r);
  77307. ExpectPtrEq(s2, s);
  77308. r2 = NULL;
  77309. wolfSSL_ECDSA_SIG_get0(sig, &r2, NULL);
  77310. ExpectPtrEq(r2, r);
  77311. s2 = NULL;
  77312. wolfSSL_ECDSA_SIG_get0(sig, NULL, &s2);
  77313. ExpectPtrEq(s2, s);
  77314. /* r and s are freed when sig is freed. */
  77315. wolfSSL_ECDSA_SIG_free(sig);
  77316. sig = NULL;
  77317. ExpectNull(wolfSSL_d2i_ECDSA_SIG(NULL, NULL, sizeof(sigData)));
  77318. cp = sigDataBad;
  77319. ExpectNull(wolfSSL_d2i_ECDSA_SIG(NULL, &cp, sizeof(sigDataBad)));
  77320. cp = sigData;
  77321. ExpectNotNull((sig = wolfSSL_d2i_ECDSA_SIG(NULL, &cp, sizeof(sigData))));
  77322. ExpectIntEQ((cp == sigData + 8), 1);
  77323. cp = sigData;
  77324. ExpectNull(wolfSSL_d2i_ECDSA_SIG(&sig, NULL, sizeof(sigData)));
  77325. ExpectNotNull((sig2 = wolfSSL_d2i_ECDSA_SIG(&sig, &cp, sizeof(sigData))));
  77326. ExpectIntEQ((sig == sig2), 1);
  77327. cp = outSig;
  77328. p = outSig;
  77329. ExpectIntEQ(wolfSSL_i2d_ECDSA_SIG(NULL, &p), 0);
  77330. ExpectIntEQ(wolfSSL_i2d_ECDSA_SIG(NULL, NULL), 0);
  77331. ExpectIntEQ(wolfSSL_i2d_ECDSA_SIG(sig, NULL), 8);
  77332. ExpectIntEQ(wolfSSL_i2d_ECDSA_SIG(sig, &p), sizeof(sigData));
  77333. ExpectIntEQ((p == outSig + 8), 1);
  77334. ExpectIntEQ(XMEMCMP(sigData, outSig, 8), 0);
  77335. p = NULL;
  77336. ExpectIntEQ(wolfSSL_i2d_ECDSA_SIG(sig, &p), 8);
  77337. #ifndef WOLFSSL_I2D_ECDSA_SIG_ALLOC
  77338. ExpectNull(p);
  77339. #else
  77340. ExpectNotNull(p);
  77341. ExpectIntEQ(XMEMCMP(p, outSig, 8), 0);
  77342. XFREE(p, NULL, DYNAMIC_TYPE_OPENSSL);
  77343. #endif
  77344. wolfSSL_ECDSA_SIG_free(sig);
  77345. #endif
  77346. return EXPECT_RESULT();
  77347. }
  77348. static int test_ECDSA_size_sign(void)
  77349. {
  77350. EXPECT_DECLS;
  77351. #if defined(OPENSSL_EXTRA) && !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  77352. EC_KEY* key = NULL;
  77353. ECDSA_SIG* ecdsaSig = NULL;
  77354. int id;
  77355. byte hash[WC_MAX_DIGEST_SIZE];
  77356. byte hash2[WC_MAX_DIGEST_SIZE];
  77357. byte sig[ECC_MAX_SIG_SIZE];
  77358. unsigned int sigSz = sizeof(sig);
  77359. XMEMSET(hash, 123, sizeof(hash));
  77360. XMEMSET(hash2, 234, sizeof(hash2));
  77361. id = wc_ecc_get_curve_id_from_name("SECP256R1");
  77362. ExpectIntEQ(id, ECC_SECP256R1);
  77363. ExpectNotNull(key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  77364. ExpectIntEQ(EC_KEY_generate_key(key), 1);
  77365. ExpectIntGE(ECDSA_size(NULL), 0);
  77366. ExpectIntEQ(ECDSA_sign(0, hash, sizeof(hash), sig, &sigSz, NULL), 0);
  77367. ExpectIntEQ(ECDSA_sign(0, NULL, sizeof(hash), sig, &sigSz, key), 0);
  77368. ExpectIntEQ(ECDSA_sign(0, hash, sizeof(hash), NULL, &sigSz, key), 0);
  77369. ExpectIntEQ(ECDSA_verify(0, hash, sizeof(hash), sig, (int)sigSz, NULL), 0);
  77370. ExpectIntEQ(ECDSA_verify(0, NULL, sizeof(hash), sig, (int)sigSz, key), 0);
  77371. ExpectIntEQ(ECDSA_verify(0, hash, sizeof(hash), NULL, (int)sigSz, key), 0);
  77372. ExpectIntEQ(ECDSA_sign(0, hash, sizeof(hash), sig, &sigSz, key), 1);
  77373. ExpectIntGE(ECDSA_size(key), sigSz);
  77374. ExpectIntEQ(ECDSA_verify(0, hash, sizeof(hash), sig, (int)sigSz, key), 1);
  77375. ExpectIntEQ(ECDSA_verify(0, hash2, sizeof(hash2), sig, (int)sigSz, key), 0);
  77376. ExpectNull(ECDSA_do_sign(NULL, sizeof(hash), NULL));
  77377. ExpectNull(ECDSA_do_sign(NULL, sizeof(hash), key));
  77378. ExpectNull(ECDSA_do_sign(hash, sizeof(hash), NULL));
  77379. ExpectNotNull(ecdsaSig = ECDSA_do_sign(hash, sizeof(hash), key));
  77380. ExpectIntEQ(ECDSA_do_verify(NULL, sizeof(hash), NULL, NULL), -1);
  77381. ExpectIntEQ(ECDSA_do_verify(hash, sizeof(hash), NULL, NULL), -1);
  77382. ExpectIntEQ(ECDSA_do_verify(NULL, sizeof(hash), ecdsaSig, NULL), -1);
  77383. ExpectIntEQ(ECDSA_do_verify(NULL, sizeof(hash), NULL, key), -1);
  77384. ExpectIntEQ(ECDSA_do_verify(NULL, sizeof(hash), ecdsaSig, key), -1);
  77385. ExpectIntEQ(ECDSA_do_verify(hash, sizeof(hash), NULL, key), -1);
  77386. ExpectIntEQ(ECDSA_do_verify(hash, sizeof(hash), ecdsaSig, NULL), -1);
  77387. ExpectIntEQ(ECDSA_do_verify(hash, sizeof(hash), ecdsaSig, key), 1);
  77388. ExpectIntEQ(ECDSA_do_verify(hash2, sizeof(hash2), ecdsaSig, key), 0);
  77389. ECDSA_SIG_free(ecdsaSig);
  77390. EC_KEY_free(key);
  77391. #endif /* OPENSSL_EXTRA && !NO_ECC256 && !NO_ECC_SECP */
  77392. return EXPECT_RESULT();
  77393. }
  77394. static int test_ECDH_compute_key(void)
  77395. {
  77396. EXPECT_DECLS;
  77397. #if defined(OPENSSL_EXTRA) && !defined(NO_ECC256) && !defined(NO_ECC_SECP) && \
  77398. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  77399. EC_KEY* key1 = NULL;
  77400. EC_KEY* key2 = NULL;
  77401. EC_POINT* pub1 = NULL;
  77402. EC_POINT* pub2 = NULL;
  77403. byte secret1[32];
  77404. byte secret2[32];
  77405. int i;
  77406. ExpectNotNull(key1 = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  77407. ExpectIntEQ(EC_KEY_generate_key(key1), 1);
  77408. ExpectNotNull(pub1 = wolfSSL_EC_KEY_get0_public_key(key1));
  77409. ExpectNotNull(key2 = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  77410. ExpectIntEQ(EC_KEY_generate_key(key2), 1);
  77411. ExpectNotNull(pub2 = wolfSSL_EC_KEY_get0_public_key(key2));
  77412. ExpectIntEQ(ECDH_compute_key(NULL, sizeof(secret1), NULL, NULL, NULL), 0);
  77413. ExpectIntEQ(ECDH_compute_key(secret1, sizeof(secret1), NULL, NULL, NULL),
  77414. 0);
  77415. ExpectIntEQ(ECDH_compute_key(NULL, sizeof(secret1), pub2, NULL, NULL), 0);
  77416. ExpectIntEQ(ECDH_compute_key(NULL, sizeof(secret1), NULL, key1, NULL), 0);
  77417. ExpectIntEQ(ECDH_compute_key(NULL, sizeof(secret1), pub2, key1, NULL), 0);
  77418. ExpectIntEQ(ECDH_compute_key(secret1, sizeof(secret1), NULL, key1, NULL),
  77419. 0);
  77420. ExpectIntEQ(ECDH_compute_key(secret1, sizeof(secret1), pub2, NULL, NULL),
  77421. 0);
  77422. ExpectIntEQ(ECDH_compute_key(secret1, sizeof(secret1) - 16, pub2, key1,
  77423. NULL), 0);
  77424. ExpectIntEQ(ECDH_compute_key(secret1, sizeof(secret1), pub2, key1, NULL),
  77425. sizeof(secret1));
  77426. ExpectIntEQ(ECDH_compute_key(secret2, sizeof(secret2), pub1, key2, NULL),
  77427. sizeof(secret2));
  77428. for (i = 0; i < (int)sizeof(secret1); i++) {
  77429. ExpectIntEQ(secret1[i], secret2[i]);
  77430. }
  77431. EC_KEY_free(key2);
  77432. EC_KEY_free(key1);
  77433. #endif /* OPENSSL_EXTRA && !NO_ECC256 && !NO_ECC_SECP &&
  77434. * !WOLF_CRYPTO_CB_ONLY_ECC */
  77435. return EXPECT_RESULT();
  77436. }
  77437. #endif /* HAVE_ECC && !OPENSSL_NO_PK */
  77438. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  77439. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && \
  77440. !defined(NO_ASN_TIME)
  77441. static int test_openssl_make_self_signed_certificate(EVP_PKEY* pkey,
  77442. int expectedDerSz)
  77443. {
  77444. EXPECT_DECLS;
  77445. X509* x509 = NULL;
  77446. BIGNUM* serial_number = NULL;
  77447. X509_NAME* name = NULL;
  77448. time_t epoch_off = 0;
  77449. ASN1_INTEGER* asn1_serial_number;
  77450. long not_before, not_after;
  77451. int derSz;
  77452. ExpectNotNull(x509 = X509_new());
  77453. ExpectIntNE(X509_set_pubkey(x509, pkey), 0);
  77454. ExpectNotNull(serial_number = BN_new());
  77455. ExpectIntNE(BN_pseudo_rand(serial_number, 64, 0, 0), 0);
  77456. ExpectNotNull(asn1_serial_number = X509_get_serialNumber(x509));
  77457. ExpectNotNull(BN_to_ASN1_INTEGER(serial_number, asn1_serial_number));
  77458. /* version 3 */
  77459. ExpectIntNE(X509_set_version(x509, 2L), 0);
  77460. ExpectNotNull(name = X509_NAME_new());
  77461. ExpectIntNE(X509_NAME_add_entry_by_NID(name, NID_commonName, MBSTRING_UTF8,
  77462. (unsigned char*)"www.wolfssl.com", -1, -1, 0), 0);
  77463. ExpectIntNE(X509_NAME_add_entry_by_NID(name, NID_pkcs9_contentType,
  77464. MBSTRING_UTF8,(unsigned char*)"Server", -1, -1, 0), 0);
  77465. ExpectIntNE(X509_set_subject_name(x509, name), 0);
  77466. ExpectIntNE(X509_set_issuer_name(x509, name), 0);
  77467. not_before = (long)wc_Time(NULL);
  77468. not_after = not_before + (365 * 24 * 60 * 60);
  77469. ExpectNotNull(X509_time_adj(X509_get_notBefore(x509), not_before,
  77470. &epoch_off));
  77471. ExpectNotNull(X509_time_adj(X509_get_notAfter(x509), not_after,
  77472. &epoch_off));
  77473. ExpectIntNE(X509_sign(x509, pkey, EVP_sha256()), 0);
  77474. ExpectNotNull(wolfSSL_X509_get_der(x509, &derSz));
  77475. ExpectIntGE(derSz, expectedDerSz);
  77476. BN_free(serial_number);
  77477. X509_NAME_free(name);
  77478. X509_free(x509);
  77479. return EXPECT_RESULT();
  77480. }
  77481. #endif
  77482. static int test_openssl_generate_key_and_cert(void)
  77483. {
  77484. EXPECT_DECLS;
  77485. #if defined(OPENSSL_EXTRA)
  77486. int expectedDerSz;
  77487. EVP_PKEY* pkey = NULL;
  77488. #ifdef HAVE_ECC
  77489. EC_KEY* ec_key = NULL;
  77490. #endif
  77491. #if !defined(NO_RSA)
  77492. int key_length = 2048;
  77493. BIGNUM* exponent = NULL;
  77494. RSA* rsa = NULL;
  77495. ExpectNotNull(pkey = EVP_PKEY_new());
  77496. ExpectNotNull(exponent = BN_new());
  77497. ExpectNotNull(rsa = RSA_new());
  77498. ExpectIntNE(BN_set_word(exponent, WC_RSA_EXPONENT), 0);
  77499. #ifndef WOLFSSL_KEY_GEN
  77500. ExpectIntEQ(RSA_generate_key_ex(rsa, key_length, exponent, NULL), 0);
  77501. #if defined(USE_CERT_BUFFERS_1024)
  77502. ExpectIntNE(wolfSSL_RSA_LoadDer_ex(rsa, server_key_der_1024,
  77503. sizeof_server_key_der_1024, WOLFSSL_RSA_LOAD_PRIVATE), 0);
  77504. key_length = 1024;
  77505. #elif defined(USE_CERT_BUFFERS_2048)
  77506. ExpectIntNE(wolfSSL_RSA_LoadDer_ex(rsa, server_key_der_2048,
  77507. sizeof_server_key_der_2048, WOLFSSL_RSA_LOAD_PRIVATE), 0);
  77508. #else
  77509. RSA_free(rsa);
  77510. rsa = NULL;
  77511. #endif
  77512. #else
  77513. ExpectIntEQ(RSA_generate_key_ex(NULL, key_length, exponent, NULL), 0);
  77514. ExpectIntEQ(RSA_generate_key_ex(rsa, 0, exponent, NULL), 0);
  77515. ExpectIntEQ(RSA_generate_key_ex(rsa, key_length, NULL, NULL), 0);
  77516. ExpectIntNE(RSA_generate_key_ex(rsa, key_length, exponent, NULL), 0);
  77517. #endif
  77518. if (rsa) {
  77519. ExpectIntNE(EVP_PKEY_assign_RSA(pkey, rsa), 0);
  77520. if (EXPECT_FAIL()) {
  77521. RSA_free(rsa);
  77522. }
  77523. #if !defined(NO_CERTS) && defined(WOLFSSL_CERT_GEN) && \
  77524. defined(WOLFSSL_CERT_REQ) && !defined(NO_ASN_TIME)
  77525. expectedDerSz = 743;
  77526. ExpectIntEQ(test_openssl_make_self_signed_certificate(pkey,
  77527. expectedDerSz), TEST_SUCCESS);
  77528. #endif
  77529. }
  77530. EVP_PKEY_free(pkey);
  77531. pkey = NULL;
  77532. BN_free(exponent);
  77533. #endif /* !NO_RSA */
  77534. #ifdef HAVE_ECC
  77535. ExpectNotNull(pkey = EVP_PKEY_new());
  77536. ExpectNotNull(ec_key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  77537. #ifndef NO_WOLFSSL_STUB
  77538. EC_KEY_set_asn1_flag(ec_key, OPENSSL_EC_NAMED_CURVE);
  77539. #endif
  77540. ExpectIntNE(EC_KEY_generate_key(ec_key), 0);
  77541. ExpectIntNE(EVP_PKEY_assign_EC_KEY(pkey, ec_key), 0);
  77542. if (EXPECT_FAIL()) {
  77543. EC_KEY_free(ec_key);
  77544. }
  77545. #if !defined(NO_CERTS) && defined(WOLFSSL_CERT_GEN) && \
  77546. defined(WOLFSSL_CERT_REQ) && !defined(NO_ASN_TIME)
  77547. expectedDerSz = 344;
  77548. ExpectIntEQ(test_openssl_make_self_signed_certificate(pkey, expectedDerSz),
  77549. TEST_SUCCESS);
  77550. #endif
  77551. EVP_PKEY_free(pkey);
  77552. #endif /* HAVE_ECC */
  77553. (void)pkey;
  77554. (void)expectedDerSz;
  77555. #endif /* OPENSSL_EXTRA */
  77556. return EXPECT_RESULT();
  77557. }
  77558. static int test_stubs_are_stubs(void)
  77559. {
  77560. EXPECT_DECLS;
  77561. #if defined(OPENSSL_EXTRA) && !defined(NO_WOLFSSL_STUB) && \
  77562. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  77563. WOLFSSL_CTX* ctx = NULL;
  77564. WOLFSSL_CTX* ctxN = NULL;
  77565. #ifndef NO_WOLFSSL_CLIENT
  77566. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  77567. #elif !defined(NO_WOLFSSL_SERVER)
  77568. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  77569. #endif
  77570. #define CHECKZERO_RET(x, y, z) ExpectIntEQ((int) x(y), 0); \
  77571. ExpectIntEQ((int) x(z), 0)
  77572. /* test logic, all stubs return same result regardless of ctx being NULL
  77573. * as there are no sanity checks, it's just a stub! If at some
  77574. * point a stub is not a stub it should begin to return BAD_FUNC_ARG
  77575. * if invalid inputs are supplied. Test calling both
  77576. * with and without valid inputs, if a stub functionality remains unchanged.
  77577. */
  77578. CHECKZERO_RET(wolfSSL_CTX_sess_accept, ctx, ctxN);
  77579. CHECKZERO_RET(wolfSSL_CTX_sess_connect, ctx, ctxN);
  77580. CHECKZERO_RET(wolfSSL_CTX_sess_accept_good, ctx, ctxN);
  77581. CHECKZERO_RET(wolfSSL_CTX_sess_connect_good, ctx, ctxN);
  77582. CHECKZERO_RET(wolfSSL_CTX_sess_accept_renegotiate, ctx, ctxN);
  77583. CHECKZERO_RET(wolfSSL_CTX_sess_connect_renegotiate, ctx, ctxN);
  77584. CHECKZERO_RET(wolfSSL_CTX_sess_hits, ctx, ctxN);
  77585. CHECKZERO_RET(wolfSSL_CTX_sess_cb_hits, ctx, ctxN);
  77586. CHECKZERO_RET(wolfSSL_CTX_sess_cache_full, ctx, ctxN);
  77587. CHECKZERO_RET(wolfSSL_CTX_sess_misses, ctx, ctxN);
  77588. CHECKZERO_RET(wolfSSL_CTX_sess_timeouts, ctx, ctxN);
  77589. /* when implemented this should take WOLFSSL object instead, right now
  77590. * always returns 0 */
  77591. ExpectPtrEq(SSL_get_current_expansion(NULL), NULL);
  77592. wolfSSL_CTX_free(ctx);
  77593. ctx = NULL;
  77594. ExpectStrEQ(SSL_COMP_get_name(NULL), "not supported");
  77595. ExpectPtrEq(SSL_get_current_expansion(NULL), NULL);
  77596. #endif /* OPENSSL_EXTRA && !NO_WOLFSSL_STUB && (!NO_WOLFSSL_CLIENT ||
  77597. * !NO_WOLFSSL_SERVER) */
  77598. return EXPECT_RESULT();
  77599. }
  77600. static int test_CONF_modules_xxx(void)
  77601. {
  77602. int res = TEST_SKIPPED;
  77603. #if defined(OPENSSL_EXTRA)
  77604. CONF_modules_free();
  77605. CONF_modules_unload(0);
  77606. CONF_modules_unload(1);
  77607. CONF_modules_unload(-1);
  77608. res = TEST_SUCCESS;
  77609. #endif /* OPENSSL_EXTRA */
  77610. return res;
  77611. }
  77612. static int test_CRYPTO_set_dynlock_xxx(void)
  77613. {
  77614. int res = TEST_SKIPPED;
  77615. #if defined(OPENSSL_EXTRA)
  77616. CRYPTO_set_dynlock_create_callback(
  77617. (struct CRYPTO_dynlock_value *(*)(const char*, int))NULL);
  77618. CRYPTO_set_dynlock_create_callback(
  77619. (struct CRYPTO_dynlock_value *(*)(const char*, int))1);
  77620. CRYPTO_set_dynlock_destroy_callback(
  77621. (void (*)(struct CRYPTO_dynlock_value*, const char*, int))NULL);
  77622. CRYPTO_set_dynlock_destroy_callback(
  77623. (void (*)(struct CRYPTO_dynlock_value*, const char*, int))1);
  77624. CRYPTO_set_dynlock_lock_callback(
  77625. (void (*)(int, struct CRYPTO_dynlock_value *, const char*, int))NULL);
  77626. CRYPTO_set_dynlock_lock_callback(
  77627. (void (*)(int, struct CRYPTO_dynlock_value *, const char*, int))1);
  77628. res = TEST_SUCCESS;
  77629. #endif /* OPENSSL_EXTRA */
  77630. return res;
  77631. }
  77632. static int test_CRYPTO_THREADID_xxx(void)
  77633. {
  77634. EXPECT_DECLS;
  77635. #if defined(OPENSSL_EXTRA)
  77636. CRYPTO_THREADID_current((CRYPTO_THREADID*)NULL);
  77637. CRYPTO_THREADID_current((CRYPTO_THREADID*)1);
  77638. ExpectIntEQ(CRYPTO_THREADID_hash((const CRYPTO_THREADID*)NULL), 0);
  77639. #endif /* OPENSSL_EXTRA */
  77640. return EXPECT_RESULT();
  77641. }
  77642. static int test_ENGINE_cleanup(void)
  77643. {
  77644. int res = TEST_SKIPPED;
  77645. #if defined(OPENSSL_EXTRA)
  77646. ENGINE_cleanup();
  77647. res = TEST_SUCCESS;
  77648. #endif /* OPENSSL_EXTRA */
  77649. return res;
  77650. }
  77651. static int test_wolfSSL_CTX_LoadCRL(void)
  77652. {
  77653. EXPECT_DECLS;
  77654. #if defined(HAVE_CRL) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) && \
  77655. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  77656. WOLFSSL_CTX* ctx = NULL;
  77657. WOLFSSL* ssl = NULL;
  77658. const char* badPath = "dummypath";
  77659. const char* validPath = "./certs/crl";
  77660. const char* validFilePath = "./certs/crl/cliCrl.pem";
  77661. const char* issuerCert = "./certs/client-cert.pem";
  77662. int derType = WOLFSSL_FILETYPE_ASN1;
  77663. int pemType = WOLFSSL_FILETYPE_PEM;
  77664. #ifdef HAVE_CRL_MONITOR
  77665. int monitor = WOLFSSL_CRL_MONITOR;
  77666. #else
  77667. int monitor = 0;
  77668. #endif
  77669. WOLFSSL_CERT_MANAGER* cm = NULL;
  77670. #define FAIL_T1(x, y, z, p, d) ExpectIntEQ((int) x(y, z, p, d), \
  77671. WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  77672. #define FAIL_T2(x, y, z, p, d) ExpectIntEQ((int) x(y, z, p, d), \
  77673. WC_NO_ERR_TRACE(NOT_COMPILED_IN))
  77674. #define SUCC_T(x, y, z, p, d) ExpectIntEQ((int) x(y, z, p, d), \
  77675. WOLFSSL_SUCCESS)
  77676. #ifndef NO_WOLFSSL_CLIENT
  77677. #define NEW_CTX(ctx) ExpectNotNull( \
  77678. (ctx) = wolfSSL_CTX_new(wolfSSLv23_client_method()))
  77679. #elif !defined(NO_WOLFSSL_SERVER)
  77680. #define NEW_CTX(ctx) ExpectNotNull( \
  77681. (ctx) = wolfSSL_CTX_new(wolfSSLv23_server_method()))
  77682. #else
  77683. #define NEW_CTX(ctx) return
  77684. #endif
  77685. FAIL_T1(wolfSSL_CTX_LoadCRL, ctx, validPath, pemType, monitor);
  77686. NEW_CTX(ctx);
  77687. #ifndef HAVE_CRL_MONITOR
  77688. FAIL_T2(wolfSSL_CTX_LoadCRL, ctx, validPath, pemType, WOLFSSL_CRL_MONITOR);
  77689. wolfSSL_CTX_free(ctx);
  77690. NEW_CTX(ctx);
  77691. #endif
  77692. SUCC_T (wolfSSL_CTX_LoadCRL, ctx, validPath, pemType, monitor);
  77693. SUCC_T (wolfSSL_CTX_LoadCRL, ctx, badPath, pemType, monitor);
  77694. SUCC_T (wolfSSL_CTX_LoadCRL, ctx, badPath, derType, monitor);
  77695. wolfSSL_CTX_free(ctx);
  77696. ctx = NULL;
  77697. NEW_CTX(ctx);
  77698. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, issuerCert, NULL),
  77699. WOLFSSL_SUCCESS);
  77700. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx, validFilePath, pemType), WOLFSSL_SUCCESS);
  77701. wolfSSL_CTX_free(ctx);
  77702. ctx = NULL;
  77703. NEW_CTX(ctx);
  77704. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, issuerCert, NULL),
  77705. WOLFSSL_SUCCESS);
  77706. ExpectNotNull(ssl = wolfSSL_new(ctx));
  77707. ExpectIntEQ(wolfSSL_LoadCRLFile(ssl, validFilePath, pemType), WOLFSSL_SUCCESS);
  77708. wolfSSL_free(ssl);
  77709. ssl = NULL;
  77710. wolfSSL_CTX_free(ctx);
  77711. ctx = NULL;
  77712. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  77713. ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, issuerCert, NULL),
  77714. WOLFSSL_SUCCESS);
  77715. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, validFilePath, pemType),
  77716. WOLFSSL_SUCCESS);
  77717. wolfSSL_CertManagerFree(cm);
  77718. #endif
  77719. return EXPECT_RESULT();
  77720. }
  77721. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_CRL) && \
  77722. !defined(WOLFSSL_CRL_ALLOW_MISSING_CDP)
  77723. static int test_multiple_crls_same_issuer_ctx_ready(WOLFSSL_CTX* ctx)
  77724. {
  77725. EXPECT_DECLS;
  77726. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  77727. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx, "./certs/crl/crl.pem",
  77728. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  77729. return EXPECT_RESULT();
  77730. }
  77731. #endif
  77732. static int test_multiple_crls_same_issuer(void)
  77733. {
  77734. EXPECT_DECLS;
  77735. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_CRL) && \
  77736. !defined(WOLFSSL_CRL_ALLOW_MISSING_CDP)
  77737. test_ssl_cbf client_cbs, server_cbs;
  77738. struct {
  77739. const char* server_cert;
  77740. const char* server_key;
  77741. } test_params[] = {
  77742. { "./certs/server-cert.pem", "./certs/server-key.pem" },
  77743. { "./certs/server-revoked-cert.pem", "./certs/server-revoked-key.pem" }
  77744. };
  77745. size_t i;
  77746. for (i = 0; i < (sizeof(test_params)/sizeof(*test_params)); i++) {
  77747. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  77748. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  77749. server_cbs.certPemFile = test_params[i].server_cert;
  77750. server_cbs.keyPemFile = test_params[i].server_key;
  77751. client_cbs.crlPemFile = "./certs/crl/extra-crls/general-server-crl.pem";
  77752. client_cbs.ctx_ready = test_multiple_crls_same_issuer_ctx_ready;
  77753. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  77754. &server_cbs, NULL), -1001);
  77755. }
  77756. #endif
  77757. return EXPECT_RESULT();
  77758. }
  77759. static int test_SetTmpEC_DHE_Sz(void)
  77760. {
  77761. EXPECT_DECLS;
  77762. #if defined(HAVE_ECC) && !defined(NO_WOLFSSL_CLIENT)
  77763. WOLFSSL_CTX *ctx = NULL;
  77764. WOLFSSL *ssl = NULL;
  77765. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  77766. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpEC_DHE_Sz(ctx, 32));
  77767. ExpectNotNull(ssl = wolfSSL_new(ctx));
  77768. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpEC_DHE_Sz(ssl, 32));
  77769. wolfSSL_free(ssl);
  77770. wolfSSL_CTX_free(ctx);
  77771. #endif
  77772. return EXPECT_RESULT();
  77773. }
  77774. static int test_wolfSSL_CTX_get0_privatekey(void)
  77775. {
  77776. EXPECT_DECLS;
  77777. #ifdef OPENSSL_ALL
  77778. WOLFSSL_CTX* ctx = NULL;
  77779. (void)ctx;
  77780. #ifndef NO_RSA
  77781. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_method()));
  77782. ExpectNull(SSL_CTX_get0_privatekey(ctx));
  77783. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  77784. WOLFSSL_FILETYPE_PEM));
  77785. ExpectNull(SSL_CTX_get0_privatekey(ctx));
  77786. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  77787. WOLFSSL_FILETYPE_PEM));
  77788. ExpectNotNull(SSL_CTX_get0_privatekey(ctx));
  77789. wolfSSL_CTX_free(ctx);
  77790. ctx = NULL;
  77791. #endif
  77792. #ifdef HAVE_ECC
  77793. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_method()));
  77794. ExpectNull(SSL_CTX_get0_privatekey(ctx));
  77795. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, eccCertFile,
  77796. WOLFSSL_FILETYPE_PEM));
  77797. ExpectNull(SSL_CTX_get0_privatekey(ctx));
  77798. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, eccKeyFile,
  77799. WOLFSSL_FILETYPE_PEM));
  77800. ExpectNotNull(SSL_CTX_get0_privatekey(ctx));
  77801. wolfSSL_CTX_free(ctx);
  77802. #endif
  77803. #endif
  77804. return EXPECT_RESULT();
  77805. }
  77806. static int test_wolfSSL_dtls_set_mtu(void)
  77807. {
  77808. EXPECT_DECLS;
  77809. #if (defined(WOLFSSL_DTLS_MTU) || defined(WOLFSSL_SCTP)) && \
  77810. !defined(NO_WOLFSSL_SERVER) && defined(WOLFSSL_DTLS) && \
  77811. !defined(WOLFSSL_NO_TLS12)
  77812. WOLFSSL_CTX* ctx = NULL;
  77813. WOLFSSL* ssl = NULL;
  77814. const char* testCertFile;
  77815. const char* testKeyFile;
  77816. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method()));
  77817. #ifndef NO_RSA
  77818. testCertFile = svrCertFile;
  77819. testKeyFile = svrKeyFile;
  77820. #elif defined(HAVE_ECC)
  77821. testCertFile = eccCertFile;
  77822. testKeyFile = eccKeyFile;
  77823. #endif
  77824. if (testCertFile != NULL && testKeyFile != NULL) {
  77825. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  77826. WOLFSSL_FILETYPE_PEM));
  77827. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  77828. WOLFSSL_FILETYPE_PEM));
  77829. }
  77830. ExpectNotNull(ssl = wolfSSL_new(ctx));
  77831. ExpectIntEQ(wolfSSL_CTX_dtls_set_mtu(NULL, 1488), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  77832. ExpectIntEQ(wolfSSL_dtls_set_mtu(NULL, 1488), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  77833. ExpectIntEQ(wolfSSL_CTX_dtls_set_mtu(ctx, 20000), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  77834. ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl, 20000), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  77835. ExpectIntEQ(wolfSSL_get_error(ssl, WC_NO_ERR_TRACE(WOLFSSL_FAILURE)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  77836. ExpectIntEQ(wolfSSL_CTX_dtls_set_mtu(ctx, 1488), WOLFSSL_SUCCESS);
  77837. ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl, 1488), WOLFSSL_SUCCESS);
  77838. wolfSSL_free(ssl);
  77839. wolfSSL_CTX_free(ctx);
  77840. #endif
  77841. return EXPECT_RESULT();
  77842. }
  77843. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(SINGLE_THREADED) && \
  77844. defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12)
  77845. static WC_INLINE void generateDTLSMsg(byte* out, int outSz, word32 seq,
  77846. enum HandShakeType hsType, word16 length)
  77847. {
  77848. size_t idx = 0;
  77849. byte* l;
  77850. /* record layer */
  77851. /* handshake type */
  77852. out[idx++] = handshake;
  77853. /* protocol version */
  77854. out[idx++] = 0xfe;
  77855. out[idx++] = 0xfd; /* DTLS 1.2 */
  77856. /* epoch 0 */
  77857. XMEMSET(out + idx, 0, 2);
  77858. idx += 2;
  77859. /* sequence number */
  77860. XMEMSET(out + idx, 0, 6);
  77861. c32toa(seq, out + idx + 2);
  77862. idx += 6;
  77863. /* length in BE */
  77864. if (length)
  77865. c16toa(length, out + idx);
  77866. else
  77867. c16toa(outSz - idx - 2, out + idx);
  77868. idx += 2;
  77869. /* handshake layer */
  77870. /* handshake type */
  77871. out[idx++] = (byte)hsType;
  77872. /* length */
  77873. l = out + idx;
  77874. idx += 3;
  77875. /* message seq */
  77876. c16toa(0, out + idx);
  77877. idx += 2;
  77878. /* frag offset */
  77879. c32to24(0, out + idx);
  77880. idx += 3;
  77881. /* frag length */
  77882. c32to24((word32)outSz - (word32)idx - 3, l);
  77883. c32to24((word32)outSz - (word32)idx - 3, out + idx);
  77884. idx += 3;
  77885. XMEMSET(out + idx, 0, outSz - idx);
  77886. }
  77887. static void test_wolfSSL_dtls_plaintext_server(WOLFSSL* ssl)
  77888. {
  77889. byte msg[] = "This is a msg for the client";
  77890. byte reply[40];
  77891. AssertIntGT(wolfSSL_read(ssl, reply, sizeof(reply)),0);
  77892. reply[sizeof(reply) - 1] = '\0';
  77893. fprintf(stderr, "Client message: %s\n", reply);
  77894. AssertIntEQ(wolfSSL_write(ssl, msg, sizeof(msg)), sizeof(msg));
  77895. }
  77896. static void test_wolfSSL_dtls_plaintext_client(WOLFSSL* ssl)
  77897. {
  77898. byte ch[50];
  77899. int fd = wolfSSL_get_fd(ssl);
  77900. byte msg[] = "This is a msg for the server";
  77901. byte reply[40];
  77902. generateDTLSMsg(ch, sizeof(ch), 20, client_hello, 0);
  77903. /* Server should ignore this datagram */
  77904. AssertIntEQ(send(fd, ch, sizeof(ch), 0), sizeof(ch));
  77905. generateDTLSMsg(ch, sizeof(ch), 20, client_hello, 10000);
  77906. /* Server should ignore this datagram */
  77907. AssertIntEQ(send(fd, ch, sizeof(ch), 0), sizeof(ch));
  77908. AssertIntEQ(wolfSSL_write(ssl, msg, sizeof(msg)), sizeof(msg));
  77909. AssertIntGT(wolfSSL_read(ssl, reply, sizeof(reply)),0);
  77910. reply[sizeof(reply) - 1] = '\0';
  77911. fprintf(stderr, "Server response: %s\n", reply);
  77912. }
  77913. static int test_wolfSSL_dtls_plaintext(void)
  77914. {
  77915. callback_functions func_cb_client;
  77916. callback_functions func_cb_server;
  77917. size_t i;
  77918. struct test_params {
  77919. method_provider client_meth;
  77920. method_provider server_meth;
  77921. ssl_callback on_result_server;
  77922. ssl_callback on_result_client;
  77923. } params[] = {
  77924. {wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method,
  77925. test_wolfSSL_dtls_plaintext_server,
  77926. test_wolfSSL_dtls_plaintext_client},
  77927. };
  77928. for (i = 0; i < sizeof(params)/sizeof(*params); i++) {
  77929. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  77930. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  77931. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  77932. func_cb_server.method = params[i].server_meth;
  77933. func_cb_client.method = params[i].client_meth;
  77934. func_cb_client.on_result = params[i].on_result_client;
  77935. func_cb_server.on_result = params[i].on_result_server;
  77936. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  77937. if (!func_cb_client.return_code)
  77938. return TEST_FAIL;
  77939. if (!func_cb_server.return_code)
  77940. return TEST_FAIL;
  77941. }
  77942. return TEST_RES_CHECK(1);
  77943. }
  77944. #else
  77945. static int test_wolfSSL_dtls_plaintext(void) {
  77946. return TEST_SKIPPED;
  77947. }
  77948. #endif
  77949. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(SINGLE_THREADED) && \
  77950. defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12)
  77951. static void test_wolfSSL_dtls12_fragments_spammer(WOLFSSL* ssl)
  77952. {
  77953. byte b[1100]; /* buffer for the messages to send */
  77954. size_t idx = 0;
  77955. size_t seq_offset = 0;
  77956. size_t msg_offset = 0;
  77957. int i;
  77958. int fd = wolfSSL_get_fd(ssl);
  77959. int ret = wolfSSL_connect_cert(ssl); /* This gets us past the cookie */
  77960. word32 seq_number = 100; /* start high so server definitely reads this */
  77961. word16 msg_number = 50; /* start high so server has to buffer this */
  77962. AssertIntEQ(ret, 1);
  77963. /* Now let's start spamming the peer with fragments it needs to store */
  77964. XMEMSET(b, -1, sizeof(b));
  77965. /* record layer */
  77966. /* handshake type */
  77967. b[idx++] = 22;
  77968. /* protocol version */
  77969. b[idx++] = 0xfe;
  77970. b[idx++] = 0xfd; /* DTLS 1.2 */
  77971. /* epoch 0 */
  77972. XMEMSET(b + idx, 0, 2);
  77973. idx += 2;
  77974. /* sequence number */
  77975. XMEMSET(b + idx, 0, 6);
  77976. seq_offset = idx + 2; /* increment only the low 32 bits */
  77977. idx += 6;
  77978. /* static length in BE */
  77979. c16toa(42, b + idx);
  77980. idx += 2;
  77981. /* handshake layer */
  77982. /* cert type */
  77983. b[idx++] = 11;
  77984. /* length */
  77985. c32to24(1000, b + idx);
  77986. idx += 3;
  77987. /* message seq */
  77988. c16toa(0, b + idx);
  77989. msg_offset = idx;
  77990. idx += 2;
  77991. /* frag offset */
  77992. c32to24(500, b + idx);
  77993. idx += 3;
  77994. /* frag length */
  77995. c32to24(30, b + idx);
  77996. idx += 3;
  77997. (void)idx; /* inhibit clang-analyzer-deadcode.DeadStores */
  77998. for (i = 0; i < DTLS_POOL_SZ * 2 && ret > 0;
  77999. seq_number++, msg_number++, i++) {
  78000. struct timespec delay;
  78001. XMEMSET(&delay, 0, sizeof(delay));
  78002. delay.tv_nsec = 10000000; /* wait 0.01 seconds */
  78003. c32toa(seq_number, b + seq_offset);
  78004. c16toa(msg_number, b + msg_offset);
  78005. ret = (int)send(fd, b, 55, 0);
  78006. nanosleep(&delay, NULL);
  78007. }
  78008. }
  78009. #ifdef WOLFSSL_DTLS13
  78010. static void test_wolfSSL_dtls13_fragments_spammer(WOLFSSL* ssl)
  78011. {
  78012. const word16 sendCountMax = 100;
  78013. byte b[150]; /* buffer for the messages to send */
  78014. size_t idx = 0;
  78015. size_t msg_offset = 0;
  78016. int fd = wolfSSL_get_fd(ssl);
  78017. word16 msg_number = 10; /* start high so server has to buffer this */
  78018. int ret = wolfSSL_connect_cert(ssl); /* This gets us past the cookie */
  78019. AssertIntEQ(ret, 1);
  78020. /* Now let's start spamming the peer with fragments it needs to store */
  78021. XMEMSET(b, -1, sizeof(b));
  78022. /* handshake type */
  78023. b[idx++] = 11;
  78024. /* length */
  78025. c32to24(10000, b + idx);
  78026. idx += 3;
  78027. /* message_seq */
  78028. msg_offset = idx;
  78029. idx += 2;
  78030. /* fragment_offset */
  78031. c32to24(5000, b + idx);
  78032. idx += 3;
  78033. /* fragment_length */
  78034. c32to24(100, b + idx);
  78035. idx += 3;
  78036. /* fragment contents */
  78037. idx += 100;
  78038. for (; ret > 0 && msg_number < sendCountMax; msg_number++) {
  78039. byte sendBuf[150];
  78040. int sendSz = sizeof(sendBuf);
  78041. struct timespec delay;
  78042. XMEMSET(&delay, 0, sizeof(delay));
  78043. delay.tv_nsec = 10000000; /* wait 0.01 seconds */
  78044. c16toa(msg_number, b + msg_offset);
  78045. sendSz = BuildTls13Message(ssl, sendBuf, sendSz, b,
  78046. (int)idx, handshake, 0, 0, 0);
  78047. ret = (int)send(fd, sendBuf, (size_t)sendSz, 0);
  78048. nanosleep(&delay, NULL);
  78049. }
  78050. }
  78051. #endif
  78052. static int test_wolfSSL_dtls_fragments(void)
  78053. {
  78054. EXPECT_DECLS;
  78055. callback_functions func_cb_client;
  78056. callback_functions func_cb_server;
  78057. size_t i;
  78058. struct test_params {
  78059. method_provider client_meth;
  78060. method_provider server_meth;
  78061. ssl_callback spammer;
  78062. } params[] = {
  78063. #if !defined(WOLFSSL_NO_TLS12)
  78064. {wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method,
  78065. test_wolfSSL_dtls12_fragments_spammer},
  78066. #endif
  78067. #ifdef WOLFSSL_DTLS13
  78068. {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method,
  78069. test_wolfSSL_dtls13_fragments_spammer},
  78070. #endif
  78071. };
  78072. for (i = 0; i < sizeof(params)/sizeof(*params); i++) {
  78073. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  78074. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  78075. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  78076. func_cb_server.method = params[i].server_meth;
  78077. func_cb_client.method = params[i].client_meth;
  78078. func_cb_client.ssl_ready = params[i].spammer;
  78079. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  78080. ExpectFalse(func_cb_client.return_code);
  78081. ExpectFalse(func_cb_server.return_code);
  78082. /* The socket should be closed by the server resulting in a
  78083. * socket error, fatal error or reading a close notify alert */
  78084. if (func_cb_client.last_err != WC_NO_ERR_TRACE(SOCKET_ERROR_E) &&
  78085. func_cb_client.last_err != WOLFSSL_ERROR_ZERO_RETURN &&
  78086. func_cb_client.last_err != WC_NO_ERR_TRACE(FATAL_ERROR)) {
  78087. ExpectIntEQ(func_cb_client.last_err, WC_NO_ERR_TRACE(SOCKET_ERROR_E));
  78088. }
  78089. /* Check the server returned an error indicating the msg buffer
  78090. * was full */
  78091. ExpectIntEQ(func_cb_server.last_err, WC_NO_ERR_TRACE(DTLS_TOO_MANY_FRAGMENTS_E));
  78092. if (EXPECT_FAIL())
  78093. break;
  78094. }
  78095. return EXPECT_RESULT();
  78096. }
  78097. static void test_wolfSSL_dtls_send_alert(WOLFSSL* ssl)
  78098. {
  78099. int fd, ret;
  78100. byte alert_msg[] = {
  78101. 0x15, /* alert type */
  78102. 0xfe, 0xfd, /* version */
  78103. 0x00, 0x00, /* epoch */
  78104. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, /* seq number */
  78105. 0x00, 0x02, /* length */
  78106. 0x02, /* level: fatal */
  78107. 0x46 /* protocol version */
  78108. };
  78109. fd = wolfSSL_get_fd(ssl);
  78110. ret = (int)send(fd, alert_msg, sizeof(alert_msg), 0);
  78111. AssertIntGT(ret, 0);
  78112. }
  78113. static int _test_wolfSSL_ignore_alert_before_cookie(byte version12)
  78114. {
  78115. callback_functions client_cbs, server_cbs;
  78116. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  78117. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  78118. client_cbs.doUdp = server_cbs.doUdp = 1;
  78119. if (version12) {
  78120. #if !defined(WOLFSSL_NO_TLS12)
  78121. client_cbs.method = wolfDTLSv1_2_client_method;
  78122. server_cbs.method = wolfDTLSv1_2_server_method;
  78123. #else
  78124. return TEST_SKIPPED;
  78125. #endif
  78126. }
  78127. else
  78128. {
  78129. #ifdef WOLFSSL_DTLS13
  78130. client_cbs.method = wolfDTLSv1_3_client_method;
  78131. server_cbs.method = wolfDTLSv1_3_server_method;
  78132. #else
  78133. return TEST_SKIPPED;
  78134. #endif /* WOLFSSL_DTLS13 */
  78135. }
  78136. client_cbs.ssl_ready = test_wolfSSL_dtls_send_alert;
  78137. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  78138. if (!client_cbs.return_code)
  78139. return TEST_FAIL;
  78140. if (!server_cbs.return_code)
  78141. return TEST_FAIL;
  78142. return TEST_SUCCESS;
  78143. }
  78144. static int test_wolfSSL_ignore_alert_before_cookie(void)
  78145. {
  78146. int ret;
  78147. ret =_test_wolfSSL_ignore_alert_before_cookie(0);
  78148. if (ret != 0)
  78149. return ret;
  78150. ret =_test_wolfSSL_ignore_alert_before_cookie(1);
  78151. if (ret != 0)
  78152. return ret;
  78153. return 0;
  78154. }
  78155. static void test_wolfSSL_send_bad_record(WOLFSSL* ssl)
  78156. {
  78157. int ret;
  78158. int fd;
  78159. byte bad_msg[] = {
  78160. 0x17, /* app data */
  78161. 0xaa, 0xfd, /* bad version */
  78162. 0x00, 0x01, /* epoch 1 */
  78163. 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, /* not seen seq number */
  78164. 0x00, 0x26, /* length: 38 bytes */
  78165. 0xae, 0x30, 0x31, 0xb1, 0xf1, 0xb9, 0x6f, 0xda, 0x17, 0x19, 0xd9, 0x57,
  78166. 0xa9, 0x9d, 0x5c, 0x51, 0x9b, 0x53, 0x63, 0xa5, 0x24, 0x70, 0xa1,
  78167. 0xae, 0xdf, 0x1c, 0xb9, 0xfc, 0xe3, 0xd7, 0x77, 0x6d, 0xb6, 0x89, 0x0f,
  78168. 0x03, 0x18, 0x72
  78169. };
  78170. fd = wolfSSL_get_fd(ssl);
  78171. AssertIntGE(fd, 0);
  78172. ret = (int)send(fd, bad_msg, sizeof(bad_msg), 0);
  78173. AssertIntEQ(ret, sizeof(bad_msg));
  78174. ret = wolfSSL_write(ssl, "badrecordtest", sizeof("badrecordtest"));
  78175. AssertIntEQ(ret, sizeof("badrecordtest"));
  78176. }
  78177. static void test_wolfSSL_read_string(WOLFSSL* ssl)
  78178. {
  78179. byte buf[100];
  78180. int ret;
  78181. ret = wolfSSL_read(ssl, buf, sizeof(buf));
  78182. AssertIntGT(ret, 0);
  78183. AssertIntEQ(strcmp((char*)buf, "badrecordtest"), 0);
  78184. }
  78185. static int _test_wolfSSL_dtls_bad_record(
  78186. method_provider client_method, method_provider server_method)
  78187. {
  78188. callback_functions client_cbs, server_cbs;
  78189. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  78190. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  78191. client_cbs.doUdp = server_cbs.doUdp = 1;
  78192. client_cbs.method = client_method;
  78193. server_cbs.method = server_method;
  78194. client_cbs.on_result = test_wolfSSL_send_bad_record;
  78195. server_cbs.on_result = test_wolfSSL_read_string;
  78196. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  78197. if (!client_cbs.return_code)
  78198. return TEST_FAIL;
  78199. if (!server_cbs.return_code)
  78200. return TEST_FAIL;
  78201. return TEST_SUCCESS;
  78202. }
  78203. static int test_wolfSSL_dtls_bad_record(void)
  78204. {
  78205. int ret = TEST_SUCCESS;
  78206. #if !defined(WOLFSSL_NO_TLS12)
  78207. ret = _test_wolfSSL_dtls_bad_record(wolfDTLSv1_2_client_method,
  78208. wolfDTLSv1_2_server_method);
  78209. #endif
  78210. #ifdef WOLFSSL_DTLS13
  78211. if (ret == TEST_SUCCESS) {
  78212. ret = _test_wolfSSL_dtls_bad_record(wolfDTLSv1_3_client_method,
  78213. wolfDTLSv1_3_server_method);
  78214. }
  78215. #endif /* WOLFSSL_DTLS13 */
  78216. return ret;
  78217. }
  78218. #else
  78219. static int test_wolfSSL_dtls_fragments(void) {
  78220. return TEST_SKIPPED;
  78221. }
  78222. static int test_wolfSSL_ignore_alert_before_cookie(void) {
  78223. return TEST_SKIPPED;
  78224. }
  78225. static int test_wolfSSL_dtls_bad_record(void) {
  78226. return TEST_SKIPPED;
  78227. }
  78228. #endif
  78229. #if defined(WOLFSSL_DTLS13) && !defined(WOLFSSL_TLS13_IGNORE_AEAD_LIMITS) && \
  78230. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  78231. defined(HAVE_IO_TESTS_DEPENDENCIES)
  78232. static byte test_AEAD_fail_decryption = 0;
  78233. static byte test_AEAD_seq_num = 0;
  78234. static byte test_AEAD_done = 0;
  78235. static int test_AEAD_cbiorecv(WOLFSSL *ssl, char *buf, int sz, void *ctx)
  78236. {
  78237. int ret = (int)recv(wolfSSL_get_fd(ssl), buf, sz, 0);
  78238. if (ret > 0) {
  78239. if (test_AEAD_fail_decryption) {
  78240. /* Modify the packet to trigger a decryption failure */
  78241. buf[ret/2] ^= 0xFF;
  78242. if (test_AEAD_fail_decryption == 1)
  78243. test_AEAD_fail_decryption = 0;
  78244. }
  78245. }
  78246. (void)ctx;
  78247. return ret;
  78248. }
  78249. static void test_AEAD_get_limits(WOLFSSL* ssl, w64wrapper* hardLimit,
  78250. w64wrapper* keyUpdateLimit, w64wrapper* sendLimit)
  78251. {
  78252. if (sendLimit)
  78253. w64Zero(sendLimit);
  78254. switch (ssl->specs.bulk_cipher_algorithm) {
  78255. case wolfssl_aes_gcm:
  78256. if (sendLimit)
  78257. *sendLimit = AEAD_AES_LIMIT;
  78258. FALL_THROUGH;
  78259. case wolfssl_chacha:
  78260. if (hardLimit)
  78261. *hardLimit = DTLS_AEAD_AES_GCM_CHACHA_FAIL_LIMIT;
  78262. if (keyUpdateLimit)
  78263. *keyUpdateLimit = DTLS_AEAD_AES_GCM_CHACHA_FAIL_KU_LIMIT;
  78264. break;
  78265. case wolfssl_aes_ccm:
  78266. if (sendLimit)
  78267. *sendLimit = DTLS_AEAD_AES_CCM_LIMIT;
  78268. if (ssl->specs.aead_mac_size == AES_CCM_8_AUTH_SZ) {
  78269. if (hardLimit)
  78270. *hardLimit = DTLS_AEAD_AES_CCM_8_FAIL_LIMIT;
  78271. if (keyUpdateLimit)
  78272. *keyUpdateLimit = DTLS_AEAD_AES_CCM_8_FAIL_KU_LIMIT;
  78273. }
  78274. else {
  78275. if (hardLimit)
  78276. *hardLimit = DTLS_AEAD_AES_CCM_FAIL_LIMIT;
  78277. if (keyUpdateLimit)
  78278. *keyUpdateLimit = DTLS_AEAD_AES_CCM_FAIL_KU_LIMIT;
  78279. }
  78280. break;
  78281. default:
  78282. fprintf(stderr, "Unrecognized bulk cipher");
  78283. AssertFalse(1);
  78284. break;
  78285. }
  78286. }
  78287. static void test_AEAD_limit_client(WOLFSSL* ssl)
  78288. {
  78289. int ret;
  78290. int i;
  78291. int didReKey = 0;
  78292. char msgBuf[20];
  78293. w64wrapper hardLimit;
  78294. w64wrapper keyUpdateLimit;
  78295. w64wrapper counter;
  78296. w64wrapper sendLimit;
  78297. test_AEAD_get_limits(ssl, &hardLimit, &keyUpdateLimit, &sendLimit);
  78298. w64Zero(&counter);
  78299. AssertTrue(w64Equal(Dtls13GetEpoch(ssl, ssl->dtls13Epoch)->dropCount, counter));
  78300. wolfSSL_SSLSetIORecv(ssl, test_AEAD_cbiorecv);
  78301. for (i = 0; i < 10; i++) {
  78302. /* Test some failed decryptions */
  78303. test_AEAD_fail_decryption = 1;
  78304. w64Increment(&counter);
  78305. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  78306. /* Should succeed since decryption failures are dropped */
  78307. AssertIntGT(ret, 0);
  78308. AssertTrue(w64Equal(Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount, counter));
  78309. }
  78310. test_AEAD_fail_decryption = 1;
  78311. Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount = keyUpdateLimit;
  78312. w64Increment(&Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount);
  78313. /* 100 read calls should be enough to complete the key update */
  78314. w64Zero(&counter);
  78315. for (i = 0; i < 100; i++) {
  78316. /* Key update should be sent and negotiated */
  78317. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  78318. AssertIntGT(ret, 0);
  78319. /* Epoch after one key update is 4 */
  78320. if (w64Equal(ssl->dtls13PeerEpoch, w64From32(0, 4)) &&
  78321. w64Equal(Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount, counter)) {
  78322. didReKey = 1;
  78323. break;
  78324. }
  78325. }
  78326. AssertTrue(didReKey);
  78327. if (!w64IsZero(sendLimit)) {
  78328. /* Test the sending limit for AEAD ciphers */
  78329. Dtls13GetEpoch(ssl, ssl->dtls13Epoch)->nextSeqNumber = sendLimit;
  78330. test_AEAD_seq_num = 1;
  78331. ret = wolfSSL_write(ssl, msgBuf, sizeof(msgBuf));
  78332. AssertIntGT(ret, 0);
  78333. didReKey = 0;
  78334. w64Zero(&counter);
  78335. /* 100 read calls should be enough to complete the key update */
  78336. for (i = 0; i < 100; i++) {
  78337. /* Key update should be sent and negotiated */
  78338. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  78339. AssertIntGT(ret, 0);
  78340. /* Epoch after another key update is 5 */
  78341. if (w64Equal(ssl->dtls13Epoch, w64From32(0, 5)) &&
  78342. w64Equal(Dtls13GetEpoch(ssl, ssl->dtls13Epoch)->dropCount, counter)) {
  78343. didReKey = 1;
  78344. break;
  78345. }
  78346. }
  78347. AssertTrue(didReKey);
  78348. }
  78349. test_AEAD_fail_decryption = 2;
  78350. Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount = hardLimit;
  78351. w64Decrement(&Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount);
  78352. /* Connection should fail with a DECRYPT_ERROR */
  78353. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  78354. AssertIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  78355. AssertIntEQ(wolfSSL_get_error(ssl, ret), WC_NO_ERR_TRACE(DECRYPT_ERROR));
  78356. test_AEAD_done = 1;
  78357. }
  78358. int counter = 0;
  78359. static void test_AEAD_limit_server(WOLFSSL* ssl)
  78360. {
  78361. char msgBuf[] = "Sending data";
  78362. int ret = WOLFSSL_SUCCESS;
  78363. w64wrapper sendLimit;
  78364. SOCKET_T fd = wolfSSL_get_fd(ssl);
  78365. struct timespec delay;
  78366. XMEMSET(&delay, 0, sizeof(delay));
  78367. delay.tv_nsec = 100000000; /* wait 0.1 seconds */
  78368. tcp_set_nonblocking(&fd); /* So that read doesn't block */
  78369. wolfSSL_dtls_set_using_nonblock(ssl, 1);
  78370. test_AEAD_get_limits(ssl, NULL, NULL, &sendLimit);
  78371. while (!test_AEAD_done && ret > 0) {
  78372. counter++;
  78373. if (test_AEAD_seq_num) {
  78374. /* We need to update the seq number so that we can understand the
  78375. * peer. Otherwise we will incorrectly interpret the seq number. */
  78376. Dtls13Epoch* e = Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch);
  78377. AssertNotNull(e);
  78378. e->nextPeerSeqNumber = sendLimit;
  78379. test_AEAD_seq_num = 0;
  78380. }
  78381. (void)wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  78382. ret = wolfSSL_write(ssl, msgBuf, sizeof(msgBuf));
  78383. nanosleep(&delay, NULL);
  78384. }
  78385. }
  78386. static int test_wolfSSL_dtls_AEAD_limit(void)
  78387. {
  78388. callback_functions func_cb_client;
  78389. callback_functions func_cb_server;
  78390. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  78391. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  78392. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  78393. func_cb_server.method = wolfDTLSv1_3_server_method;
  78394. func_cb_client.method = wolfDTLSv1_3_client_method;
  78395. func_cb_server.on_result = test_AEAD_limit_server;
  78396. func_cb_client.on_result = test_AEAD_limit_client;
  78397. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  78398. if (!func_cb_client.return_code)
  78399. return TEST_FAIL;
  78400. if (!func_cb_server.return_code)
  78401. return TEST_FAIL;
  78402. return TEST_SUCCESS;
  78403. }
  78404. #else
  78405. static int test_wolfSSL_dtls_AEAD_limit(void)
  78406. {
  78407. return TEST_SKIPPED;
  78408. }
  78409. #endif
  78410. #if defined(WOLFSSL_DTLS) && \
  78411. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(SINGLE_THREADED) && \
  78412. !defined(DEBUG_VECTOR_REGISTER_ACCESS_FUZZING)
  78413. static void test_wolfSSL_dtls_send_ch(WOLFSSL* ssl)
  78414. {
  78415. int fd, ret;
  78416. byte ch_msg[] = {
  78417. 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  78418. 0xfa, 0x01, 0x00, 0x01, 0xee, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  78419. 0xee, 0xfe, 0xfd, 0xc0, 0xca, 0xb5, 0x6f, 0x3d, 0x23, 0xcc, 0x53, 0x9a,
  78420. 0x67, 0x17, 0x70, 0xd3, 0xfb, 0x23, 0x16, 0x9e, 0x4e, 0xd6, 0x7e, 0x29,
  78421. 0xab, 0xfa, 0x4c, 0xa5, 0x84, 0x95, 0xc3, 0xdb, 0x21, 0x9a, 0x52, 0x00,
  78422. 0x00, 0x00, 0x36, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0,
  78423. 0x2b, 0xc0, 0x30, 0xc0, 0x2f, 0x00, 0x9f, 0x00, 0x9e, 0xcc, 0xa9, 0xcc,
  78424. 0xa8, 0xcc, 0xaa, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x28, 0xc0, 0x24, 0xc0,
  78425. 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x6b, 0x00, 0x67, 0x00,
  78426. 0x39, 0x00, 0x33, 0xcc, 0x14, 0xcc, 0x13, 0xcc, 0x15, 0x01, 0x00, 0x01,
  78427. 0x8e, 0x00, 0x2b, 0x00, 0x03, 0x02, 0xfe, 0xfc, 0x00, 0x0d, 0x00, 0x20,
  78428. 0x00, 0x1e, 0x06, 0x03, 0x05, 0x03, 0x04, 0x03, 0x02, 0x03, 0x08, 0x06,
  78429. 0x08, 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08, 0x09, 0x06, 0x01,
  78430. 0x05, 0x01, 0x04, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, 0x0a, 0x00, 0x0c,
  78431. 0x00, 0x0a, 0x00, 0x19, 0x00, 0x18, 0x00, 0x17, 0x00, 0x15, 0x01, 0x00,
  78432. 0x00, 0x16, 0x00, 0x00, 0x00, 0x33, 0x01, 0x4b, 0x01, 0x49, 0x00, 0x17,
  78433. 0x00, 0x41, 0x04, 0x96, 0xcb, 0x2e, 0x4e, 0xd9, 0x88, 0x71, 0xc7, 0xf3,
  78434. 0x1a, 0x16, 0xdd, 0x7a, 0x7c, 0xf7, 0x67, 0x8a, 0x5d, 0x9a, 0x55, 0xa6,
  78435. 0x4a, 0x90, 0xd9, 0xfb, 0xc7, 0xfb, 0xbe, 0x09, 0xa9, 0x8a, 0xb5, 0x7a,
  78436. 0xd1, 0xde, 0x83, 0x74, 0x27, 0x31, 0x1c, 0xaa, 0xae, 0xef, 0x58, 0x43,
  78437. 0x13, 0x7d, 0x15, 0x4d, 0x7f, 0x68, 0xf6, 0x8a, 0x38, 0xef, 0x0e, 0xb3,
  78438. 0xcf, 0xb8, 0x4a, 0xa9, 0xb4, 0xd7, 0xcb, 0x01, 0x00, 0x01, 0x00, 0x1d,
  78439. 0x0a, 0x22, 0x8a, 0xd1, 0x78, 0x85, 0x1e, 0x5a, 0xe1, 0x1d, 0x1e, 0xb7,
  78440. 0x2d, 0xbc, 0x5f, 0x52, 0xbc, 0x97, 0x5d, 0x8b, 0x6a, 0x8b, 0x9d, 0x1e,
  78441. 0xb1, 0xfc, 0x8a, 0xb2, 0x56, 0xcd, 0xed, 0x4b, 0xfb, 0x66, 0x3f, 0x59,
  78442. 0x3f, 0x15, 0x5d, 0x09, 0x9e, 0x2f, 0x60, 0x5b, 0x31, 0x81, 0x27, 0xf0,
  78443. 0x1c, 0xda, 0xcd, 0x48, 0x66, 0xc6, 0xbb, 0x25, 0xf0, 0x5f, 0xda, 0x4c,
  78444. 0xcf, 0x1d, 0x88, 0xc8, 0xda, 0x1b, 0x53, 0xea, 0xbd, 0xce, 0x6d, 0xf6,
  78445. 0x4a, 0x76, 0xdb, 0x75, 0x99, 0xaf, 0xcf, 0x76, 0x4a, 0xfb, 0xe3, 0xef,
  78446. 0xb2, 0xcb, 0xae, 0x4a, 0xc0, 0xe8, 0x63, 0x1f, 0xd6, 0xe8, 0xe6, 0x45,
  78447. 0xf9, 0xea, 0x0d, 0x06, 0x19, 0xfc, 0xb1, 0xfd, 0x5d, 0x92, 0x89, 0x7b,
  78448. 0xc7, 0x9f, 0x1a, 0xb3, 0x2b, 0xc7, 0xad, 0x0e, 0xfb, 0x13, 0x41, 0x83,
  78449. 0x84, 0x58, 0x3a, 0x25, 0xb9, 0x49, 0x35, 0x1c, 0x23, 0xcb, 0xd6, 0xe7,
  78450. 0xc2, 0x8c, 0x4b, 0x2a, 0x73, 0xa1, 0xdf, 0x4f, 0x73, 0x9b, 0xb3, 0xd2,
  78451. 0xb2, 0x95, 0x00, 0x3c, 0x26, 0x09, 0x89, 0x71, 0x05, 0x39, 0xc8, 0x98,
  78452. 0x8f, 0xed, 0x32, 0x15, 0x78, 0xcd, 0xd3, 0x7e, 0xfb, 0x5a, 0x78, 0x2a,
  78453. 0xdc, 0xca, 0x20, 0x09, 0xb5, 0x14, 0xf9, 0xd4, 0x58, 0xf6, 0x69, 0xf8,
  78454. 0x65, 0x9f, 0xb7, 0xe4, 0x93, 0xf1, 0xa3, 0x84, 0x7e, 0x1b, 0x23, 0x5d,
  78455. 0xea, 0x59, 0x3e, 0x4d, 0xca, 0xfd, 0xa5, 0x55, 0xdd, 0x99, 0xb5, 0x02,
  78456. 0xf8, 0x0d, 0xe5, 0xf4, 0x06, 0xb0, 0x43, 0x9e, 0x2e, 0xbf, 0x05, 0x33,
  78457. 0x65, 0x7b, 0x13, 0x8c, 0xf9, 0x16, 0x4d, 0xc5, 0x15, 0x0b, 0x40, 0x2f,
  78458. 0x66, 0x94, 0xf2, 0x43, 0x95, 0xe7, 0xa9, 0xb6, 0x39, 0x99, 0x73, 0xb3,
  78459. 0xb0, 0x06, 0xfe, 0x52, 0x9e, 0x57, 0xba, 0x75, 0xfd, 0x76, 0x7b, 0x20,
  78460. 0x31, 0x68, 0x4c
  78461. };
  78462. fd = wolfSSL_get_fd(ssl);
  78463. ret = (int)send(fd, ch_msg, sizeof(ch_msg), 0);
  78464. AssertIntGT(ret, 0);
  78465. /* consume the HRR otherwise handshake will fail */
  78466. ret = (int)recv(fd, ch_msg, sizeof(ch_msg), 0);
  78467. AssertIntGT(ret, 0);
  78468. }
  78469. #if defined(WOLFSSL_DTLS13) && defined(WOLFSSL_SEND_HRR_COOKIE)
  78470. static void test_wolfSSL_dtls_send_ch_with_invalid_cookie(WOLFSSL* ssl)
  78471. {
  78472. int fd, ret;
  78473. byte ch_msh_invalid_cookie[] = {
  78474. 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02,
  78475. 0x4e, 0x01, 0x00, 0x02, 0x42, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02,
  78476. 0x42, 0xfe, 0xfd, 0x69, 0xca, 0x77, 0x60, 0x6f, 0xfc, 0xd1, 0x5b, 0x60,
  78477. 0x5d, 0xf1, 0xa6, 0x5c, 0x44, 0x71, 0xae, 0xca, 0x62, 0x19, 0x0c, 0xb6,
  78478. 0xf7, 0x2c, 0xa6, 0xd5, 0xd2, 0x99, 0x9d, 0x18, 0xae, 0xac, 0x11, 0x00,
  78479. 0x00, 0x00, 0x36, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0,
  78480. 0x2b, 0xc0, 0x30, 0xc0, 0x2f, 0x00, 0x9f, 0x00, 0x9e, 0xcc, 0xa9, 0xcc,
  78481. 0xa8, 0xcc, 0xaa, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x28, 0xc0, 0x24, 0xc0,
  78482. 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x6b, 0x00, 0x67, 0x00,
  78483. 0x39, 0x00, 0x33, 0xcc, 0x14, 0xcc, 0x13, 0xcc, 0x15, 0x01, 0x00, 0x01,
  78484. 0xe2, 0x00, 0x2b, 0x00, 0x03, 0x02, 0xfe, 0xfc, 0x00, 0x0d, 0x00, 0x20,
  78485. 0x00, 0x1e, 0x06, 0x03, 0x05, 0x03, 0x04, 0x03, 0x02, 0x03, 0x08, 0x06,
  78486. 0x08, 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08, 0x09, 0x06, 0x01,
  78487. 0x05, 0x01, 0x04, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, 0x2c, 0x00, 0x45,
  78488. 0x00, 0x43, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  78489. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  78490. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  78491. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  78492. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  78493. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x2d, 0x00,
  78494. 0x03, 0x02, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x0c, 0x00, 0x0a, 0x00, 0x19,
  78495. 0x00, 0x18, 0x00, 0x17, 0x00, 0x15, 0x01, 0x00, 0x00, 0x16, 0x00, 0x00,
  78496. 0x00, 0x33, 0x01, 0x4b, 0x01, 0x49, 0x00, 0x17, 0x00, 0x41, 0x04, 0x7c,
  78497. 0x5a, 0xc2, 0x5a, 0xfd, 0xcd, 0x2b, 0x08, 0xb2, 0xeb, 0x8e, 0xc0, 0x02,
  78498. 0x03, 0x9d, 0xb1, 0xc1, 0x0d, 0x7b, 0x7f, 0x46, 0x43, 0xdf, 0xf3, 0xee,
  78499. 0x2b, 0x78, 0x0e, 0x29, 0x8c, 0x42, 0x11, 0x2c, 0xde, 0xd7, 0x41, 0x0f,
  78500. 0x28, 0x94, 0x80, 0x41, 0x70, 0xc4, 0x17, 0xfd, 0x6d, 0xfa, 0xee, 0x9a,
  78501. 0xf2, 0xc4, 0x15, 0x4c, 0x5f, 0x54, 0xb6, 0x78, 0x6e, 0xf9, 0x63, 0x27,
  78502. 0x33, 0xb8, 0x7b, 0x01, 0x00, 0x01, 0x00, 0xd4, 0x46, 0x62, 0x9c, 0xbf,
  78503. 0x8f, 0x1b, 0x65, 0x9b, 0xf0, 0x29, 0x64, 0xd8, 0x50, 0x0e, 0x74, 0xf1,
  78504. 0x58, 0x10, 0xc9, 0xd9, 0x82, 0x5b, 0xd9, 0xbe, 0x14, 0xdf, 0xde, 0x86,
  78505. 0xb4, 0x2e, 0x15, 0xee, 0x4f, 0xf6, 0x74, 0x9e, 0x59, 0x11, 0x36, 0x2d,
  78506. 0xb9, 0x67, 0xaa, 0x5a, 0x09, 0x9b, 0x45, 0xf1, 0x01, 0x4c, 0x4e, 0xf6,
  78507. 0xda, 0x6a, 0xae, 0xa7, 0x73, 0x7b, 0x2e, 0xb6, 0x24, 0x89, 0x99, 0xb7,
  78508. 0x52, 0x16, 0x62, 0x0a, 0xab, 0x58, 0xf8, 0x3f, 0x10, 0x5b, 0x83, 0xfd,
  78509. 0x7b, 0x81, 0x77, 0x81, 0x8d, 0xef, 0x24, 0x56, 0x6d, 0xba, 0x49, 0xd4,
  78510. 0x8b, 0xb5, 0xa0, 0xb1, 0xc9, 0x8c, 0x32, 0x95, 0x1c, 0x5e, 0x0a, 0x4b,
  78511. 0xf6, 0x00, 0x50, 0x0a, 0x87, 0x99, 0x59, 0xcf, 0x6f, 0x9d, 0x02, 0xd0,
  78512. 0x1b, 0xa1, 0x96, 0x45, 0x28, 0x76, 0x40, 0x33, 0x28, 0xc9, 0xa1, 0xfd,
  78513. 0x46, 0xab, 0x2c, 0x9e, 0x5e, 0xc6, 0x74, 0x19, 0x9a, 0xf5, 0x9b, 0x51,
  78514. 0x11, 0x4f, 0xc8, 0xb9, 0x99, 0x6b, 0x4e, 0x3e, 0x31, 0x64, 0xb4, 0x92,
  78515. 0xf4, 0x0d, 0x41, 0x4b, 0x2c, 0x65, 0x23, 0xf7, 0x47, 0xe3, 0xa5, 0x2e,
  78516. 0xe4, 0x9c, 0x2b, 0xc9, 0x41, 0x22, 0x83, 0x8a, 0x23, 0xef, 0x29, 0x7e,
  78517. 0x4f, 0x3f, 0xa3, 0xbf, 0x73, 0x2b, 0xd7, 0xcc, 0xc8, 0xc6, 0xe9, 0xbc,
  78518. 0x01, 0xb7, 0x32, 0x63, 0xd4, 0x7e, 0x7f, 0x9a, 0xaf, 0x5f, 0x05, 0x31,
  78519. 0x53, 0xd6, 0x1f, 0xa2, 0xd0, 0xdf, 0x67, 0x56, 0xf1, 0x9c, 0x4a, 0x9d,
  78520. 0x83, 0xb4, 0xef, 0xb3, 0xf2, 0xcc, 0xf1, 0x91, 0x6c, 0x47, 0xc3, 0x8b,
  78521. 0xd0, 0x92, 0x79, 0x3d, 0xa0, 0xc0, 0x3a, 0x57, 0x26, 0x6d, 0x0a, 0xad,
  78522. 0x5f, 0xad, 0xb4, 0x74, 0x48, 0x4a, 0x51, 0xe1, 0xb5, 0x82, 0x0a, 0x4c,
  78523. 0x4f, 0x9d, 0xaf, 0xee, 0x5a, 0xa2, 0x4d, 0x4d, 0x5f, 0xe0, 0x17, 0x00,
  78524. 0x23, 0x00, 0x00
  78525. };
  78526. byte alert_reply[50];
  78527. byte expected_alert_reply[] = {
  78528. 0x15, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
  78529. 0x02, 0x02, 0x2f
  78530. };
  78531. fd = wolfSSL_get_fd(ssl);
  78532. ret = (int)send(fd, ch_msh_invalid_cookie, sizeof(ch_msh_invalid_cookie), 0);
  78533. AssertIntGT(ret, 0);
  78534. /* should reply with an illegal_parameter reply */
  78535. ret = (int)recv(fd, alert_reply, sizeof(alert_reply), 0);
  78536. AssertIntEQ(ret, sizeof(expected_alert_reply));
  78537. AssertIntEQ(XMEMCMP(alert_reply, expected_alert_reply, sizeof(expected_alert_reply)), 0);
  78538. }
  78539. #endif
  78540. static word32 test_wolfSSL_dtls_stateless_HashWOLFSSL(const WOLFSSL* ssl)
  78541. {
  78542. #ifndef NO_MD5
  78543. enum wc_HashType hashType = WC_HASH_TYPE_MD5;
  78544. #elif !defined(NO_SHA)
  78545. enum wc_HashType hashType = WC_HASH_TYPE_SHA;
  78546. #elif !defined(NO_SHA256)
  78547. enum wc_HashType hashType = WC_HASH_TYPE_SHA256;
  78548. #else
  78549. #error "We need a digest to hash the WOLFSSL object"
  78550. #endif
  78551. byte hashBuf[WC_MAX_DIGEST_SIZE];
  78552. wc_HashAlg hash;
  78553. const TLSX* exts = ssl->extensions;
  78554. WOLFSSL sslCopy; /* Use a copy to omit certain fields */
  78555. HS_Hashes* hsHashes = ssl->hsHashes; /* Is re-allocated in
  78556. * InitHandshakeHashes */
  78557. XMEMCPY(&sslCopy, ssl, sizeof(*ssl));
  78558. XMEMSET(hashBuf, 0, sizeof(hashBuf));
  78559. /* Following fields are not important to compare */
  78560. XMEMSET(sslCopy.buffers.inputBuffer.staticBuffer, 0, STATIC_BUFFER_LEN);
  78561. sslCopy.buffers.inputBuffer.buffer = NULL;
  78562. sslCopy.buffers.inputBuffer.bufferSize = 0;
  78563. sslCopy.buffers.inputBuffer.dynamicFlag = 0;
  78564. sslCopy.buffers.inputBuffer.offset = 0;
  78565. XMEMSET(sslCopy.buffers.outputBuffer.staticBuffer, 0, STATIC_BUFFER_LEN);
  78566. sslCopy.buffers.outputBuffer.buffer = NULL;
  78567. sslCopy.buffers.outputBuffer.bufferSize = 0;
  78568. sslCopy.buffers.outputBuffer.dynamicFlag = 0;
  78569. sslCopy.buffers.outputBuffer.offset = 0;
  78570. sslCopy.error = 0;
  78571. sslCopy.curSize = 0;
  78572. sslCopy.curStartIdx = 0;
  78573. sslCopy.keys.curSeq_lo = 0;
  78574. XMEMSET(&sslCopy.curRL, 0, sizeof(sslCopy.curRL));
  78575. #ifdef WOLFSSL_DTLS13
  78576. XMEMSET(&sslCopy.keys.curSeq, 0, sizeof(sslCopy.keys.curSeq));
  78577. sslCopy.dtls13FastTimeout = 0;
  78578. #endif
  78579. sslCopy.keys.dtls_peer_handshake_number = 0;
  78580. XMEMSET(&sslCopy.alert_history, 0, sizeof(sslCopy.alert_history));
  78581. sslCopy.hsHashes = NULL;
  78582. #ifdef WOLFSSL_ASYNC_IO
  78583. #ifdef WOLFSSL_ASYNC_CRYPT
  78584. sslCopy.asyncDev = NULL;
  78585. #endif
  78586. sslCopy.async = NULL;
  78587. #endif
  78588. AssertIntEQ(wc_HashInit(&hash, hashType), 0);
  78589. AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)&sslCopy, sizeof(sslCopy)), 0);
  78590. /* hash extension list */
  78591. while (exts != NULL) {
  78592. AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)exts, sizeof(*exts)), 0);
  78593. exts = exts->next;
  78594. }
  78595. /* Hash suites */
  78596. if (sslCopy.suites != NULL) {
  78597. AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)sslCopy.suites,
  78598. sizeof(struct Suites)), 0);
  78599. }
  78600. /* Hash hsHashes */
  78601. AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)hsHashes,
  78602. sizeof(*hsHashes)), 0);
  78603. AssertIntEQ(wc_HashFinal(&hash, hashType, hashBuf), 0);
  78604. AssertIntEQ(wc_HashFree(&hash, hashType), 0);
  78605. return MakeWordFromHash(hashBuf);
  78606. }
  78607. static CallbackIORecv test_wolfSSL_dtls_compare_stateless_cb;
  78608. static int test_wolfSSL_dtls_compare_stateless_cb_call_once;
  78609. static int test_wolfSSL_dtls_compare_stateless_read_cb_once(WOLFSSL *ssl,
  78610. char *buf, int sz, void *ctx)
  78611. {
  78612. if (test_wolfSSL_dtls_compare_stateless_cb_call_once) {
  78613. test_wolfSSL_dtls_compare_stateless_cb_call_once = 0;
  78614. return test_wolfSSL_dtls_compare_stateless_cb(ssl, buf, sz, ctx);
  78615. }
  78616. else {
  78617. return WOLFSSL_CBIO_ERR_WANT_READ;
  78618. }
  78619. }
  78620. static void test_wolfSSL_dtls_compare_stateless(WOLFSSL* ssl)
  78621. {
  78622. /* Compare the ssl object before and after one ClientHello msg */
  78623. SOCKET_T fd = wolfSSL_get_fd(ssl);
  78624. int res;
  78625. int err;
  78626. word32 initHash;
  78627. test_wolfSSL_dtls_compare_stateless_cb = ssl->CBIORecv;
  78628. test_wolfSSL_dtls_compare_stateless_cb_call_once = 1;
  78629. wolfSSL_dtls_set_using_nonblock(ssl, 1);
  78630. ssl->CBIORecv = test_wolfSSL_dtls_compare_stateless_read_cb_once;
  78631. initHash = test_wolfSSL_dtls_stateless_HashWOLFSSL(ssl);
  78632. (void)initHash;
  78633. res = tcp_select(fd, 5);
  78634. /* We are expecting a msg. A timeout indicates failure. */
  78635. AssertIntEQ(res, TEST_RECV_READY);
  78636. res = wolfSSL_accept(ssl);
  78637. err = wolfSSL_get_error(ssl, res);
  78638. AssertIntEQ(res, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  78639. AssertIntEQ(err, WOLFSSL_ERROR_WANT_READ);
  78640. AssertIntEQ(initHash, test_wolfSSL_dtls_stateless_HashWOLFSSL(ssl));
  78641. wolfSSL_dtls_set_using_nonblock(ssl, 0);
  78642. ssl->CBIORecv = test_wolfSSL_dtls_compare_stateless_cb;
  78643. }
  78644. #if defined(WOLFSSL_DTLS13) && defined(WOLFSSL_SEND_HRR_COOKIE)
  78645. static void test_wolfSSL_dtls_enable_hrrcookie(WOLFSSL* ssl)
  78646. {
  78647. int ret;
  78648. ret = wolfSSL_send_hrr_cookie(ssl, NULL, 0);
  78649. AssertIntEQ(ret, WOLFSSL_SUCCESS);
  78650. test_wolfSSL_dtls_compare_stateless(ssl);
  78651. }
  78652. #endif
  78653. static int test_wolfSSL_dtls_stateless(void)
  78654. {
  78655. callback_functions client_cbs, server_cbs;
  78656. size_t i;
  78657. struct {
  78658. method_provider client_meth;
  78659. method_provider server_meth;
  78660. ssl_callback client_ssl_ready;
  78661. ssl_callback server_ssl_ready;
  78662. } test_params[] = {
  78663. #if !defined(WOLFSSL_NO_TLS12)
  78664. {wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method,
  78665. test_wolfSSL_dtls_send_ch, test_wolfSSL_dtls_compare_stateless},
  78666. #endif
  78667. #if defined(WOLFSSL_DTLS13) && defined(WOLFSSL_SEND_HRR_COOKIE)
  78668. {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method,
  78669. test_wolfSSL_dtls_send_ch, test_wolfSSL_dtls_enable_hrrcookie},
  78670. {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method,
  78671. test_wolfSSL_dtls_send_ch_with_invalid_cookie, test_wolfSSL_dtls_enable_hrrcookie},
  78672. #endif
  78673. };
  78674. if (0 == sizeof(test_params)){
  78675. return TEST_SKIPPED;
  78676. }
  78677. for (i = 0; i < sizeof(test_params)/sizeof(*test_params); i++) {
  78678. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  78679. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  78680. client_cbs.doUdp = server_cbs.doUdp = 1;
  78681. client_cbs.method = test_params[i].client_meth;
  78682. server_cbs.method = test_params[i].server_meth;
  78683. client_cbs.ssl_ready = test_params[i].client_ssl_ready;
  78684. server_cbs.ssl_ready = test_params[i].server_ssl_ready;
  78685. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  78686. if (!client_cbs.return_code)
  78687. return TEST_FAIL;
  78688. if (!server_cbs.return_code)
  78689. return TEST_FAIL;
  78690. }
  78691. return TEST_SUCCESS;
  78692. }
  78693. #else
  78694. static int test_wolfSSL_dtls_stateless(void)
  78695. {
  78696. return TEST_SKIPPED;
  78697. }
  78698. #endif /* WOLFSSL_DTLS13 && WOLFSSL_SEND_HRR_COOKIE &&
  78699. * HAVE_IO_TESTS_DEPENDENCIES && !SINGLE_THREADED */
  78700. #ifdef HAVE_CERT_CHAIN_VALIDATION
  78701. static int load_ca_into_cm(WOLFSSL_CERT_MANAGER* cm, char* certA)
  78702. {
  78703. int ret;
  78704. if ((ret = wolfSSL_CertManagerLoadCA(cm, certA, 0)) != WOLFSSL_SUCCESS) {
  78705. fprintf(stderr, "loading cert %s failed\n", certA);
  78706. fprintf(stderr, "Error: (%d): %s\n", ret,
  78707. wolfSSL_ERR_reason_error_string(ret));
  78708. return -1;
  78709. }
  78710. return 0;
  78711. }
  78712. static int verify_cert_with_cm(WOLFSSL_CERT_MANAGER* cm, char* certA)
  78713. {
  78714. int ret;
  78715. if ((ret = wolfSSL_CertManagerVerify(cm, certA, WOLFSSL_FILETYPE_PEM))
  78716. != WOLFSSL_SUCCESS) {
  78717. fprintf(stderr, "could not verify the cert: %s\n", certA);
  78718. fprintf(stderr, "Error: (%d): %s\n", ret,
  78719. wolfSSL_ERR_reason_error_string(ret));
  78720. return -1;
  78721. }
  78722. else {
  78723. fprintf(stderr, "successfully verified: %s\n", certA);
  78724. }
  78725. return 0;
  78726. }
  78727. #define LOAD_ONE_CA(a, b, c, d) \
  78728. do { \
  78729. (a) = load_ca_into_cm(c, d); \
  78730. if ((a) != 0) \
  78731. return (b); \
  78732. else \
  78733. (b)--; \
  78734. } while(0)
  78735. #define VERIFY_ONE_CERT(a, b, c, d) \
  78736. do { \
  78737. (a) = verify_cert_with_cm(c, d);\
  78738. if ((a) != 0) \
  78739. return (b); \
  78740. else \
  78741. (b)--; \
  78742. } while(0)
  78743. static int test_chainG(WOLFSSL_CERT_MANAGER* cm)
  78744. {
  78745. int ret;
  78746. int i = -1;
  78747. /* Chain G is a valid chain per RFC 5280 section 4.2.1.9 */
  78748. char chainGArr[9][50] = {"certs/ca-cert.pem",
  78749. "certs/test-pathlen/chainG-ICA7-pathlen100.pem",
  78750. "certs/test-pathlen/chainG-ICA6-pathlen10.pem",
  78751. "certs/test-pathlen/chainG-ICA5-pathlen20.pem",
  78752. "certs/test-pathlen/chainG-ICA4-pathlen5.pem",
  78753. "certs/test-pathlen/chainG-ICA3-pathlen99.pem",
  78754. "certs/test-pathlen/chainG-ICA2-pathlen1.pem",
  78755. "certs/test-pathlen/chainG-ICA1-pathlen0.pem",
  78756. "certs/test-pathlen/chainG-entity.pem"};
  78757. LOAD_ONE_CA(ret, i, cm, chainGArr[0]); /* if failure, i = -1 here */
  78758. LOAD_ONE_CA(ret, i, cm, chainGArr[1]); /* if failure, i = -2 here */
  78759. LOAD_ONE_CA(ret, i, cm, chainGArr[2]); /* if failure, i = -3 here */
  78760. LOAD_ONE_CA(ret, i, cm, chainGArr[3]); /* if failure, i = -4 here */
  78761. LOAD_ONE_CA(ret, i, cm, chainGArr[4]); /* if failure, i = -5 here */
  78762. LOAD_ONE_CA(ret, i, cm, chainGArr[5]); /* if failure, i = -6 here */
  78763. LOAD_ONE_CA(ret, i, cm, chainGArr[6]); /* if failure, i = -7 here */
  78764. LOAD_ONE_CA(ret, i, cm, chainGArr[7]); /* if failure, i = -8 here */
  78765. VERIFY_ONE_CERT(ret, i, cm, chainGArr[1]); /* if failure, i = -9 here */
  78766. VERIFY_ONE_CERT(ret, i, cm, chainGArr[2]); /* if failure, i = -10 here */
  78767. VERIFY_ONE_CERT(ret, i, cm, chainGArr[3]); /* if failure, i = -11 here */
  78768. VERIFY_ONE_CERT(ret, i, cm, chainGArr[4]); /* if failure, i = -12 here */
  78769. VERIFY_ONE_CERT(ret, i, cm, chainGArr[5]); /* if failure, i = -13 here */
  78770. VERIFY_ONE_CERT(ret, i, cm, chainGArr[6]); /* if failure, i = -14 here */
  78771. VERIFY_ONE_CERT(ret, i, cm, chainGArr[7]); /* if failure, i = -15 here */
  78772. VERIFY_ONE_CERT(ret, i, cm, chainGArr[8]); /* if failure, i = -16 here */
  78773. /* test validating the entity twice, should have no effect on pathLen since
  78774. * entity/leaf cert */
  78775. VERIFY_ONE_CERT(ret, i, cm, chainGArr[8]); /* if failure, i = -17 here */
  78776. return ret;
  78777. }
  78778. static int test_chainH(WOLFSSL_CERT_MANAGER* cm)
  78779. {
  78780. int ret;
  78781. int i = -1;
  78782. /* Chain H is NOT a valid chain per RFC5280 section 4.2.1.9:
  78783. * ICA4-pathlen of 2 signing ICA3-pathlen of 2 (reduce max path len to 2)
  78784. * ICA3-pathlen of 2 signing ICA2-pathlen of 2 (reduce max path len to 1)
  78785. * ICA2-pathlen of 2 signing ICA1-pathlen of 0 (reduce max path len to 0)
  78786. * ICA1-pathlen of 0 signing entity (pathlen is already 0, ERROR)
  78787. * Test should successfully verify ICA4, ICA3, ICA2 and then fail on ICA1
  78788. */
  78789. char chainHArr[6][50] = {"certs/ca-cert.pem",
  78790. "certs/test-pathlen/chainH-ICA4-pathlen2.pem",
  78791. "certs/test-pathlen/chainH-ICA3-pathlen2.pem",
  78792. "certs/test-pathlen/chainH-ICA2-pathlen2.pem",
  78793. "certs/test-pathlen/chainH-ICA1-pathlen0.pem",
  78794. "certs/test-pathlen/chainH-entity.pem"};
  78795. LOAD_ONE_CA(ret, i, cm, chainHArr[0]); /* if failure, i = -1 here */
  78796. LOAD_ONE_CA(ret, i, cm, chainHArr[1]); /* if failure, i = -2 here */
  78797. LOAD_ONE_CA(ret, i, cm, chainHArr[2]); /* if failure, i = -3 here */
  78798. LOAD_ONE_CA(ret, i, cm, chainHArr[3]); /* if failure, i = -4 here */
  78799. LOAD_ONE_CA(ret, i, cm, chainHArr[4]); /* if failure, i = -5 here */
  78800. VERIFY_ONE_CERT(ret, i, cm, chainHArr[1]); /* if failure, i = -6 here */
  78801. VERIFY_ONE_CERT(ret, i, cm, chainHArr[2]); /* if failure, i = -7 here */
  78802. VERIFY_ONE_CERT(ret, i, cm, chainHArr[3]); /* if failure, i = -8 here */
  78803. VERIFY_ONE_CERT(ret, i, cm, chainHArr[4]); /* if failure, i = -9 here */
  78804. VERIFY_ONE_CERT(ret, i, cm, chainHArr[5]); /* if failure, i = -10 here */
  78805. return ret;
  78806. }
  78807. static int test_chainI(WOLFSSL_CERT_MANAGER* cm)
  78808. {
  78809. int ret;
  78810. int i = -1;
  78811. /* Chain I is a valid chain per RFC5280 section 4.2.1.9:
  78812. * ICA3-pathlen of 2 signing ICA2 without a pathlen (reduce maxPathLen to 2)
  78813. * ICA2-no_pathlen signing ICA1-no_pathlen (reduce maxPathLen to 1)
  78814. * ICA1-no_pathlen signing entity (reduce maxPathLen to 0)
  78815. * Test should successfully verify ICA4, ICA3, ICA2 and then fail on ICA1
  78816. */
  78817. char chainIArr[5][50] = {"certs/ca-cert.pem",
  78818. "certs/test-pathlen/chainI-ICA3-pathlen2.pem",
  78819. "certs/test-pathlen/chainI-ICA2-no_pathlen.pem",
  78820. "certs/test-pathlen/chainI-ICA1-no_pathlen.pem",
  78821. "certs/test-pathlen/chainI-entity.pem"};
  78822. LOAD_ONE_CA(ret, i, cm, chainIArr[0]); /* if failure, i = -1 here */
  78823. LOAD_ONE_CA(ret, i, cm, chainIArr[1]); /* if failure, i = -2 here */
  78824. LOAD_ONE_CA(ret, i, cm, chainIArr[2]); /* if failure, i = -3 here */
  78825. LOAD_ONE_CA(ret, i, cm, chainIArr[3]); /* if failure, i = -4 here */
  78826. VERIFY_ONE_CERT(ret, i, cm, chainIArr[1]); /* if failure, i = -5 here */
  78827. VERIFY_ONE_CERT(ret, i, cm, chainIArr[2]); /* if failure, i = -6 here */
  78828. VERIFY_ONE_CERT(ret, i, cm, chainIArr[3]); /* if failure, i = -7 here */
  78829. VERIFY_ONE_CERT(ret, i, cm, chainIArr[4]); /* if failure, i = -8 here */
  78830. return ret;
  78831. }
  78832. static int test_chainJ(WOLFSSL_CERT_MANAGER* cm)
  78833. {
  78834. int ret;
  78835. int i = -1;
  78836. /* Chain J is NOT a valid chain per RFC5280 section 4.2.1.9:
  78837. * ICA4-pathlen of 2 signing ICA3 without a pathlen (reduce maxPathLen to 2)
  78838. * ICA3-pathlen of 2 signing ICA2 without a pathlen (reduce maxPathLen to 1)
  78839. * ICA2-no_pathlen signing ICA1-no_pathlen (reduce maxPathLen to 0)
  78840. * ICA1-no_pathlen signing entity (ERROR, pathlen zero and non-leaf cert)
  78841. */
  78842. char chainJArr[6][50] = {"certs/ca-cert.pem",
  78843. "certs/test-pathlen/chainJ-ICA4-pathlen2.pem",
  78844. "certs/test-pathlen/chainJ-ICA3-no_pathlen.pem",
  78845. "certs/test-pathlen/chainJ-ICA2-no_pathlen.pem",
  78846. "certs/test-pathlen/chainJ-ICA1-no_pathlen.pem",
  78847. "certs/test-pathlen/chainJ-entity.pem"};
  78848. LOAD_ONE_CA(ret, i, cm, chainJArr[0]); /* if failure, i = -1 here */
  78849. LOAD_ONE_CA(ret, i, cm, chainJArr[1]); /* if failure, i = -2 here */
  78850. LOAD_ONE_CA(ret, i, cm, chainJArr[2]); /* if failure, i = -3 here */
  78851. LOAD_ONE_CA(ret, i, cm, chainJArr[3]); /* if failure, i = -4 here */
  78852. LOAD_ONE_CA(ret, i, cm, chainJArr[4]); /* if failure, i = -5 here */
  78853. VERIFY_ONE_CERT(ret, i, cm, chainJArr[1]); /* if failure, i = -6 here */
  78854. VERIFY_ONE_CERT(ret, i, cm, chainJArr[2]); /* if failure, i = -7 here */
  78855. VERIFY_ONE_CERT(ret, i, cm, chainJArr[3]); /* if failure, i = -8 here */
  78856. VERIFY_ONE_CERT(ret, i, cm, chainJArr[4]); /* if failure, i = -9 here */
  78857. VERIFY_ONE_CERT(ret, i, cm, chainJArr[5]); /* if failure, i = -10 here */
  78858. return ret;
  78859. }
  78860. static int test_various_pathlen_chains(void)
  78861. {
  78862. EXPECT_DECLS;
  78863. WOLFSSL_CERT_MANAGER* cm = NULL;
  78864. /* Test chain G (large chain with varying pathLens) */
  78865. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  78866. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  78867. ExpectIntEQ(test_chainG(cm), -1);
  78868. #else
  78869. ExpectIntEQ(test_chainG(cm), 0);
  78870. #endif /* NO_WOLFSSL_CLIENT && NO_WOLFSSL_SERVER */
  78871. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  78872. wolfSSL_CertManagerFree(cm);
  78873. /* end test chain G */
  78874. /* Test chain H (5 chain with same pathLens) */
  78875. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  78876. ExpectIntLT(test_chainH(cm), 0);
  78877. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  78878. wolfSSL_CertManagerFree(cm);
  78879. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  78880. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  78881. wolfSSL_CertManagerFree(cm);
  78882. /* end test chain H */
  78883. /* Test chain I (only first ICA has pathLen set and it's set to 2,
  78884. * followed by 2 ICA's, should pass) */
  78885. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  78886. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  78887. ExpectIntEQ(test_chainI(cm), -1);
  78888. #else
  78889. ExpectIntEQ(test_chainI(cm), 0);
  78890. #endif /* NO_WOLFSSL_CLIENT && NO_WOLFSSL_SERVER */
  78891. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  78892. wolfSSL_CertManagerFree(cm);
  78893. cm = NULL;
  78894. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  78895. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  78896. wolfSSL_CertManagerFree(cm);
  78897. cm = NULL;
  78898. /* Test chain J (Again only first ICA has pathLen set and it's set to 2,
  78899. * this time followed by 3 ICA's, should fail */
  78900. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  78901. ExpectIntLT(test_chainJ(cm), 0);
  78902. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  78903. wolfSSL_CertManagerFree(cm);
  78904. cm = NULL;
  78905. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  78906. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  78907. wolfSSL_CertManagerFree(cm);
  78908. return EXPECT_RESULT();
  78909. }
  78910. #endif /* !NO_RSA && !NO_SHA && !NO_FILESYSTEM && !NO_CERTS */
  78911. #if defined(HAVE_KEYING_MATERIAL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  78912. static int test_export_keying_material_cb(WOLFSSL_CTX *ctx, WOLFSSL *ssl)
  78913. {
  78914. EXPECT_DECLS;
  78915. byte ekm[100] = {0};
  78916. (void)ctx;
  78917. /* Success Cases */
  78918. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  78919. "Test label", XSTR_SIZEOF("Test label"), NULL, 0, 0), 1);
  78920. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  78921. "Test label", XSTR_SIZEOF("Test label"), NULL, 0, 1), 1);
  78922. /* Use some random context */
  78923. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  78924. "Test label", XSTR_SIZEOF("Test label"), ekm, 10, 1), 1);
  78925. /* Failure cases */
  78926. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  78927. "client finished", XSTR_SIZEOF("client finished"), NULL, 0, 0), 0);
  78928. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  78929. "server finished", XSTR_SIZEOF("server finished"), NULL, 0, 0), 0);
  78930. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  78931. "master secret", XSTR_SIZEOF("master secret"), NULL, 0, 0), 0);
  78932. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  78933. "extended master secret", XSTR_SIZEOF("extended master secret"),
  78934. NULL, 0, 0), 0);
  78935. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  78936. "key expansion", XSTR_SIZEOF("key expansion"), NULL, 0, 0), 0);
  78937. return EXPECT_RESULT();
  78938. }
  78939. static int test_export_keying_material_ssl_cb(WOLFSSL* ssl)
  78940. {
  78941. wolfSSL_KeepArrays(ssl);
  78942. return TEST_SUCCESS;
  78943. }
  78944. static int test_export_keying_material(void)
  78945. {
  78946. EXPECT_DECLS;
  78947. test_ssl_cbf serverCb;
  78948. test_ssl_cbf clientCb;
  78949. XMEMSET(&serverCb, 0, sizeof(serverCb));
  78950. XMEMSET(&clientCb, 0, sizeof(clientCb));
  78951. clientCb.ssl_ready = test_export_keying_material_ssl_cb;
  78952. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&clientCb,
  78953. &serverCb, test_export_keying_material_cb), TEST_SUCCESS);
  78954. return EXPECT_RESULT();
  78955. }
  78956. #endif /* HAVE_KEYING_MATERIAL */
  78957. static int test_wolfSSL_THREADID_hash(void)
  78958. {
  78959. EXPECT_DECLS;
  78960. #if defined(OPENSSL_EXTRA)
  78961. CRYPTO_THREADID id;
  78962. CRYPTO_THREADID_current(NULL);
  78963. /* Hash result is unsigned long. */
  78964. ExpectTrue(CRYPTO_THREADID_hash(NULL) == 0UL);
  78965. XMEMSET(&id, 0, sizeof(id));
  78966. ExpectTrue(CRYPTO_THREADID_hash(&id) == 0UL);
  78967. #endif /* OPENSSL_EXTRA */
  78968. return EXPECT_RESULT();
  78969. }
  78970. static int test_wolfSSL_set_ecdh_auto(void)
  78971. {
  78972. EXPECT_DECLS;
  78973. #if defined(OPENSSL_EXTRA)
  78974. WOLFSSL* ssl = NULL;
  78975. ExpectIntEQ(SSL_set_ecdh_auto(NULL,0), 1);
  78976. ExpectIntEQ(SSL_set_ecdh_auto(NULL,1), 1);
  78977. ExpectIntEQ(SSL_set_ecdh_auto(ssl,0), 1);
  78978. ExpectIntEQ(SSL_set_ecdh_auto(ssl,1), 1);
  78979. #endif /* OPENSSL_EXTRA */
  78980. return EXPECT_RESULT();
  78981. }
  78982. static int test_wolfSSL_CTX_set_ecdh_auto(void)
  78983. {
  78984. EXPECT_DECLS;
  78985. #if defined(OPENSSL_EXTRA)
  78986. WOLFSSL_CTX* ctx = NULL;
  78987. ExpectIntEQ(SSL_CTX_set_ecdh_auto(NULL,0), 1);
  78988. ExpectIntEQ(SSL_CTX_set_ecdh_auto(NULL,1), 1);
  78989. ExpectIntEQ(SSL_CTX_set_ecdh_auto(ctx,0), 1);
  78990. ExpectIntEQ(SSL_CTX_set_ecdh_auto(ctx,1), 1);
  78991. #endif /* OPENSSL_EXTRA */
  78992. return EXPECT_RESULT();
  78993. }
  78994. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_ERROR_CODE_OPENSSL) && \
  78995. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  78996. static THREAD_RETURN WOLFSSL_THREAD SSL_read_test_server_thread(void* args)
  78997. {
  78998. EXPECT_DECLS;
  78999. callback_functions* callbacks = NULL;
  79000. WOLFSSL_CTX* ctx = NULL;
  79001. WOLFSSL* ssl = NULL;
  79002. SOCKET_T sfd = 0;
  79003. SOCKET_T cfd = 0;
  79004. word16 port;
  79005. char msg[] = "I hear you fa shizzle!";
  79006. int len = (int) XSTRLEN(msg);
  79007. char input[1024];
  79008. int ret = 0;
  79009. int err = 0;
  79010. if (!args)
  79011. WOLFSSL_RETURN_FROM_THREAD(0);
  79012. ((func_args*)args)->return_code = TEST_FAIL;
  79013. callbacks = ((func_args*)args)->callbacks;
  79014. ctx = wolfSSL_CTX_new(callbacks->method());
  79015. #if defined(USE_WINDOWS_API)
  79016. port = ((func_args*)args)->signal->port;
  79017. #else
  79018. /* Let tcp_listen assign port */
  79019. port = 0;
  79020. #endif
  79021. #ifdef WOLFSSL_TIRTOS
  79022. fdOpenSession(Task_self());
  79023. #endif
  79024. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_load_verify_locations(ctx,
  79025. caCertFile, 0));
  79026. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_certificate_file(ctx,
  79027. svrCertFile, WOLFSSL_FILETYPE_PEM));
  79028. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_PrivateKey_file(ctx,
  79029. svrKeyFile, WOLFSSL_FILETYPE_PEM));
  79030. #if !defined(NO_FILESYSTEM) && !defined(NO_DH)
  79031. ExpectIntEQ(wolfSSL_CTX_SetTmpDH_file(ctx, dhParamFile,
  79032. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  79033. #elif !defined(NO_DH)
  79034. SetDHCtx(ctx); /* will repick suites with DHE, higher priority than PSK */
  79035. #endif
  79036. if (callbacks->ctx_ready)
  79037. callbacks->ctx_ready(ctx);
  79038. ssl = wolfSSL_new(ctx);
  79039. ExpectNotNull(ssl);
  79040. /* listen and accept */
  79041. tcp_accept(&sfd, &cfd, (func_args*)args, port, 0, 0, 0, 0, 1, 0, 0);
  79042. CloseSocket(sfd);
  79043. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_set_fd(ssl, cfd));
  79044. if (callbacks->ssl_ready)
  79045. callbacks->ssl_ready(ssl);
  79046. if (EXPECT_SUCCESS()) {
  79047. do {
  79048. err = 0; /* Reset error */
  79049. ret = wolfSSL_accept(ssl);
  79050. if (ret != WOLFSSL_SUCCESS) {
  79051. err = wolfSSL_get_error(ssl, 0);
  79052. }
  79053. } while (ret != WOLFSSL_SUCCESS && err == WC_NO_ERR_TRACE(WC_PENDING_E));
  79054. }
  79055. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  79056. /* read and write data */
  79057. XMEMSET(input, 0, sizeof(input));
  79058. while (EXPECT_SUCCESS()) {
  79059. ret = wolfSSL_read(ssl, input, sizeof(input));
  79060. if (ret > 0) {
  79061. break;
  79062. }
  79063. else {
  79064. err = wolfSSL_get_error(ssl,ret);
  79065. if (err == WOLFSSL_ERROR_WANT_READ) {
  79066. continue;
  79067. }
  79068. break;
  79069. }
  79070. }
  79071. if (EXPECT_SUCCESS() && (err == WOLFSSL_ERROR_ZERO_RETURN)) {
  79072. do {
  79073. ret = wolfSSL_write(ssl, msg, len);
  79074. if (ret > 0) {
  79075. break;
  79076. }
  79077. } while (ret < 0);
  79078. }
  79079. /* bidirectional shutdown */
  79080. while (EXPECT_SUCCESS()) {
  79081. ret = wolfSSL_shutdown(ssl);
  79082. ExpectIntNE(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  79083. if (ret == WOLFSSL_SUCCESS) {
  79084. break;
  79085. }
  79086. }
  79087. if (EXPECT_SUCCESS()) {
  79088. /* wait for the peer to disconnect the tcp connection */
  79089. do {
  79090. ret = wolfSSL_read(ssl, input, sizeof(input));
  79091. err = wolfSSL_get_error(ssl, ret);
  79092. } while (ret > 0 || err != WOLFSSL_ERROR_ZERO_RETURN);
  79093. }
  79094. /* detect TCP disconnect */
  79095. ExpectIntLE(ret,WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79096. ExpectIntEQ(wolfSSL_get_error(ssl, ret), WOLFSSL_ERROR_ZERO_RETURN);
  79097. ((func_args*)args)->return_code = EXPECT_RESULT();
  79098. wolfSSL_free(ssl);
  79099. wolfSSL_CTX_free(ctx);
  79100. CloseSocket(cfd);
  79101. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
  79102. wc_ecc_fp_free(); /* free per thread cache */
  79103. #endif
  79104. WOLFSSL_RETURN_FROM_THREAD(0);
  79105. }
  79106. static THREAD_RETURN WOLFSSL_THREAD SSL_read_test_client_thread(void* args)
  79107. {
  79108. EXPECT_DECLS;
  79109. callback_functions* callbacks = NULL;
  79110. WOLFSSL_CTX* ctx = NULL;
  79111. WOLFSSL* ssl = NULL;
  79112. SOCKET_T sfd = 0;
  79113. char msg[] = "hello wolfssl server!";
  79114. int len = (int) XSTRLEN(msg);
  79115. char input[1024];
  79116. int idx;
  79117. int ret, err;
  79118. if (!args)
  79119. WOLFSSL_RETURN_FROM_THREAD(0);
  79120. ((func_args*)args)->return_code = TEST_FAIL;
  79121. callbacks = ((func_args*)args)->callbacks;
  79122. ctx = wolfSSL_CTX_new(callbacks->method());
  79123. #ifdef WOLFSSL_TIRTOS
  79124. fdOpenSession(Task_self());
  79125. #endif
  79126. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_load_verify_locations(ctx,
  79127. caCertFile, 0));
  79128. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_certificate_file(ctx,
  79129. cliCertFile, WOLFSSL_FILETYPE_PEM));
  79130. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_PrivateKey_file(ctx,
  79131. cliKeyFile, WOLFSSL_FILETYPE_PEM));
  79132. ExpectNotNull((ssl = wolfSSL_new(ctx)));
  79133. tcp_connect(&sfd, wolfSSLIP, ((func_args*)args)->signal->port, 0, 0, ssl);
  79134. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_set_fd(ssl, sfd));
  79135. if (EXPECT_SUCCESS()) {
  79136. do {
  79137. err = 0; /* Reset error */
  79138. ret = wolfSSL_connect(ssl);
  79139. if (ret != WOLFSSL_SUCCESS) {
  79140. err = wolfSSL_get_error(ssl, 0);
  79141. }
  79142. } while (ret != WOLFSSL_SUCCESS && err == WC_NO_ERR_TRACE(WC_PENDING_E));
  79143. }
  79144. ExpectIntGE(wolfSSL_write(ssl, msg, len), 0);
  79145. if (EXPECT_SUCCESS()) {
  79146. if (0 < (idx = wolfSSL_read(ssl, input, sizeof(input)-1))) {
  79147. input[idx] = 0;
  79148. }
  79149. }
  79150. if (EXPECT_SUCCESS()) {
  79151. ret = wolfSSL_shutdown(ssl);
  79152. if (ret == WOLFSSL_SHUTDOWN_NOT_DONE) {
  79153. ret = wolfSSL_shutdown(ssl);
  79154. }
  79155. }
  79156. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  79157. ((func_args*)args)->return_code = EXPECT_RESULT();
  79158. wolfSSL_free(ssl);
  79159. wolfSSL_CTX_free(ctx);
  79160. CloseSocket(sfd);
  79161. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
  79162. wc_ecc_fp_free(); /* free per thread cache */
  79163. #endif
  79164. WOLFSSL_RETURN_FROM_THREAD(0);
  79165. }
  79166. #endif /* OPENSSL_EXTRA && WOLFSSL_ERROR_CODE_OPENSSL &&
  79167. HAVE_IO_TESTS_DEPENDENCIES && !WOLFSSL_NO_TLS12 */
  79168. /* This test is to check wolfSSL_read behaves as same as
  79169. * openSSL when it is called after SSL_shutdown completes.
  79170. */
  79171. static int test_wolfSSL_read_detect_TCP_disconnect(void)
  79172. {
  79173. EXPECT_DECLS;
  79174. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_ERROR_CODE_OPENSSL) && \
  79175. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  79176. tcp_ready ready;
  79177. func_args client_args;
  79178. func_args server_args;
  79179. THREAD_TYPE serverThread;
  79180. THREAD_TYPE clientThread;
  79181. callback_functions server_cbf;
  79182. callback_functions client_cbf;
  79183. #ifdef WOLFSSL_TIRTOS
  79184. fdOpenSession(Task_self());
  79185. #endif
  79186. StartTCP();
  79187. InitTcpReady(&ready);
  79188. #if defined(USE_WINDOWS_API)
  79189. /* use RNG to get random port if using windows */
  79190. ready.port = GetRandomPort();
  79191. #endif
  79192. XMEMSET(&client_args, 0, sizeof(func_args));
  79193. XMEMSET(&server_args, 0, sizeof(func_args));
  79194. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  79195. XMEMSET(&client_cbf, 0, sizeof(callback_functions));
  79196. server_cbf.method = wolfTLSv1_2_server_method;
  79197. client_cbf.method = wolfTLSv1_2_client_method;
  79198. server_args.callbacks = &server_cbf;
  79199. client_args.callbacks = &client_cbf;
  79200. server_args.signal = &ready;
  79201. client_args.signal = &ready;
  79202. start_thread(SSL_read_test_server_thread, &server_args, &serverThread);
  79203. wait_tcp_ready(&server_args);
  79204. start_thread(SSL_read_test_client_thread, &client_args, &clientThread);
  79205. join_thread(clientThread);
  79206. join_thread(serverThread);
  79207. ExpectTrue(client_args.return_code);
  79208. ExpectTrue(server_args.return_code);
  79209. FreeTcpReady(&ready);
  79210. #endif
  79211. return EXPECT_RESULT();
  79212. }
  79213. static int test_wolfSSL_CTX_get_min_proto_version(void)
  79214. {
  79215. EXPECT_DECLS;
  79216. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)
  79217. WOLFSSL_CTX *ctx = NULL;
  79218. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_method()));
  79219. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, SSL3_VERSION),
  79220. WOLFSSL_SUCCESS);
  79221. #ifdef WOLFSSL_ALLOW_SSLV3
  79222. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), SSL3_VERSION);
  79223. #else
  79224. ExpectIntGT(wolfSSL_CTX_get_min_proto_version(ctx), SSL3_VERSION);
  79225. #endif
  79226. wolfSSL_CTX_free(ctx);
  79227. ctx = NULL;
  79228. #ifndef NO_OLD_TLS
  79229. #ifdef WOLFSSL_ALLOW_TLSV10
  79230. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_method()));
  79231. #else
  79232. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_method()));
  79233. #endif
  79234. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, TLS1_VERSION),
  79235. WOLFSSL_SUCCESS);
  79236. #ifdef WOLFSSL_ALLOW_TLSV10
  79237. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_VERSION);
  79238. #else
  79239. ExpectIntGT(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_VERSION);
  79240. #endif
  79241. wolfSSL_CTX_free(ctx);
  79242. ctx = NULL;
  79243. #endif
  79244. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_method()));
  79245. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, TLS1_1_VERSION),
  79246. WOLFSSL_SUCCESS);
  79247. #ifndef NO_OLD_TLS
  79248. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_1_VERSION);
  79249. #else
  79250. ExpectIntGT(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_1_VERSION);
  79251. #endif
  79252. wolfSSL_CTX_free(ctx);
  79253. ctx = NULL;
  79254. #ifndef WOLFSSL_NO_TLS12
  79255. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_method()));
  79256. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, TLS1_2_VERSION),
  79257. WOLFSSL_SUCCESS);
  79258. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_2_VERSION);
  79259. wolfSSL_CTX_free(ctx);
  79260. ctx = NULL;
  79261. #endif
  79262. #ifdef WOLFSSL_TLS13
  79263. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_method()));
  79264. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, TLS1_3_VERSION),
  79265. WOLFSSL_SUCCESS);
  79266. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_3_VERSION);
  79267. wolfSSL_CTX_free(ctx);
  79268. ctx = NULL;
  79269. #endif
  79270. #endif /* defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL) */
  79271. return EXPECT_RESULT();
  79272. }
  79273. #if defined(OPENSSL_ALL) || (defined(OPENSSL_EXTRA) && \
  79274. (defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || \
  79275. defined(HAVE_LIGHTY) || defined(WOLFSSL_HAPROXY) || \
  79276. defined(WOLFSSL_OPENSSH) || defined(HAVE_SBLIM_SFCB)))
  79277. static int test_wolfSSL_set_SSL_CTX(void)
  79278. {
  79279. EXPECT_DECLS;
  79280. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) \
  79281. && !defined(WOLFSSL_NO_TLS12) && defined(WOLFSSL_TLS13) && \
  79282. !defined(NO_RSA)
  79283. WOLFSSL_CTX *ctx1 = NULL;
  79284. WOLFSSL_CTX *ctx2 = NULL;
  79285. WOLFSSL *ssl = NULL;
  79286. const byte *session_id1 = (const byte *)"CTX1";
  79287. const byte *session_id2 = (const byte *)"CTX2";
  79288. ExpectNotNull(ctx1 = wolfSSL_CTX_new(wolfTLS_server_method()));
  79289. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx1, svrCertFile,
  79290. WOLFSSL_FILETYPE_PEM));
  79291. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx1, svrKeyFile,
  79292. WOLFSSL_FILETYPE_PEM));
  79293. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx1, TLS1_2_VERSION),
  79294. WOLFSSL_SUCCESS);
  79295. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx1), TLS1_2_VERSION);
  79296. ExpectIntEQ(wolfSSL_CTX_get_max_proto_version(ctx1), TLS1_3_VERSION);
  79297. ExpectIntEQ(wolfSSL_CTX_set_session_id_context(ctx1, session_id1, 4),
  79298. WOLFSSL_SUCCESS);
  79299. ExpectNotNull(ctx2 = wolfSSL_CTX_new(wolfTLS_server_method()));
  79300. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx2, svrCertFile,
  79301. WOLFSSL_FILETYPE_PEM));
  79302. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx2, svrKeyFile,
  79303. WOLFSSL_FILETYPE_PEM));
  79304. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx2, TLS1_2_VERSION),
  79305. WOLFSSL_SUCCESS);
  79306. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(ctx2, TLS1_2_VERSION),
  79307. WOLFSSL_SUCCESS);
  79308. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx2), TLS1_2_VERSION);
  79309. ExpectIntEQ(wolfSSL_CTX_get_max_proto_version(ctx2), TLS1_2_VERSION);
  79310. ExpectIntEQ(wolfSSL_CTX_set_session_id_context(ctx2, session_id2, 4),
  79311. WOLFSSL_SUCCESS);
  79312. #ifdef HAVE_SESSION_TICKET
  79313. ExpectIntEQ((wolfSSL_CTX_get_options(ctx1) & SSL_OP_NO_TICKET), 0);
  79314. wolfSSL_CTX_set_options(ctx2, SSL_OP_NO_TICKET);
  79315. ExpectIntNE((wolfSSL_CTX_get_options(ctx2) & SSL_OP_NO_TICKET), 0);
  79316. #endif
  79317. ExpectNotNull(ssl = wolfSSL_new(ctx2));
  79318. ExpectIntNE((wolfSSL_get_options(ssl) & WOLFSSL_OP_NO_TLSv1_3), 0);
  79319. #ifdef WOLFSSL_INT_H
  79320. #ifdef WOLFSSL_SESSION_ID_CTX
  79321. ExpectIntEQ(XMEMCMP(ssl->sessionCtx, session_id2, 4), 0);
  79322. #endif
  79323. #ifdef WOLFSSL_COPY_CERT
  79324. if (ctx2 != NULL && ctx2->certificate != NULL) {
  79325. ExpectFalse(ssl->buffers.certificate == ctx2->certificate);
  79326. }
  79327. if (ctx2 != NULL && ctx2->certChain != NULL) {
  79328. ExpectFalse(ssl->buffers.certChain == ctx2->certChain);
  79329. }
  79330. #else
  79331. ExpectTrue(ssl->buffers.certificate == ctx2->certificate);
  79332. ExpectTrue(ssl->buffers.certChain == ctx2->certChain);
  79333. #endif
  79334. #endif
  79335. #ifdef HAVE_SESSION_TICKET
  79336. ExpectIntNE((wolfSSL_get_options(ssl) & SSL_OP_NO_TICKET), 0);
  79337. #endif
  79338. /* Set the ctx1 that has TLSv1.3 as max proto version */
  79339. ExpectNotNull(wolfSSL_set_SSL_CTX(ssl, ctx1));
  79340. /* MUST not change proto versions of ssl */
  79341. ExpectIntNE((wolfSSL_get_options(ssl) & WOLFSSL_OP_NO_TLSv1_3), 0);
  79342. #ifdef HAVE_SESSION_TICKET
  79343. /* MUST not change */
  79344. ExpectIntNE((wolfSSL_get_options(ssl) & SSL_OP_NO_TICKET), 0);
  79345. #endif
  79346. /* MUST change */
  79347. #ifdef WOLFSSL_INT_H
  79348. #ifdef WOLFSSL_COPY_CERT
  79349. if (ctx1 != NULL && ctx1->certificate != NULL) {
  79350. ExpectFalse(ssl->buffers.certificate == ctx1->certificate);
  79351. }
  79352. if (ctx1 != NULL && ctx1->certChain != NULL) {
  79353. ExpectFalse(ssl->buffers.certChain == ctx1->certChain);
  79354. }
  79355. #else
  79356. ExpectTrue(ssl->buffers.certificate == ctx1->certificate);
  79357. ExpectTrue(ssl->buffers.certChain == ctx1->certChain);
  79358. #endif
  79359. #ifdef WOLFSSL_SESSION_ID_CTX
  79360. ExpectIntEQ(XMEMCMP(ssl->sessionCtx, session_id1, 4), 0);
  79361. #endif
  79362. #endif
  79363. wolfSSL_free(ssl);
  79364. wolfSSL_CTX_free(ctx1);
  79365. wolfSSL_CTX_free(ctx2);
  79366. #endif /* defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL) */
  79367. return EXPECT_RESULT();
  79368. }
  79369. #endif /* defined(OPENSSL_ALL) || (defined(OPENSSL_EXTRA) && \
  79370. (defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || \
  79371. defined(HAVE_LIGHTY) || defined(WOLFSSL_HAPROXY) || \
  79372. defined(WOLFSSL_OPENSSH) || defined(HAVE_SBLIM_SFCB))) */
  79373. static int test_wolfSSL_security_level(void)
  79374. {
  79375. EXPECT_DECLS;
  79376. #if defined(OPENSSL_EXTRA)
  79377. SSL_CTX *ctx = NULL;
  79378. #ifdef WOLFSSL_TLS13
  79379. #ifdef NO_WOLFSSL_SERVER
  79380. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  79381. #else
  79382. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  79383. #endif
  79384. SSL_CTX_set_security_level(NULL, 1);
  79385. SSL_CTX_set_security_level(ctx, 1);
  79386. ExpectIntEQ(SSL_CTX_get_security_level(NULL), 0);
  79387. /* Stub so nothing happens. */
  79388. ExpectIntEQ(SSL_CTX_get_security_level(ctx), 0);
  79389. SSL_CTX_free(ctx);
  79390. #else
  79391. (void)ctx;
  79392. #endif
  79393. #endif
  79394. return EXPECT_RESULT();
  79395. }
  79396. static int test_wolfSSL_SSL_in_init(void)
  79397. {
  79398. EXPECT_DECLS;
  79399. #if defined(OPENSSL_ALL) && !defined(NO_BIO)
  79400. SSL_CTX* ctx = NULL;
  79401. SSL* ssl = NULL;
  79402. const char* testCertFile;
  79403. const char* testKeyFile;
  79404. #ifdef WOLFSSL_TLS13
  79405. #ifdef NO_WOLFSSL_SERVER
  79406. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  79407. #else
  79408. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  79409. #endif
  79410. #else
  79411. #ifdef NO_WOLFSSL_SERVER
  79412. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  79413. #else
  79414. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  79415. #endif
  79416. #endif
  79417. #ifndef NO_RSA
  79418. testCertFile = svrCertFile;
  79419. testKeyFile = svrKeyFile;
  79420. #elif defined(HAVE_ECC)
  79421. testCertFile = eccCertFile;
  79422. testKeyFile = eccKeyFile;
  79423. #else
  79424. testCertFile = NULL;
  79425. testKeyFile = NULL;
  79426. #endif
  79427. if ((testCertFile != NULL) && (testKeyFile != NULL)) {
  79428. ExpectTrue(SSL_CTX_use_certificate_file(ctx, testCertFile,
  79429. SSL_FILETYPE_PEM));
  79430. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  79431. SSL_FILETYPE_PEM));
  79432. }
  79433. ExpectNotNull(ssl = SSL_new(ctx));
  79434. ExpectIntEQ(SSL_in_init(ssl), 1);
  79435. SSL_CTX_free(ctx);
  79436. SSL_free(ssl);
  79437. #endif
  79438. return EXPECT_RESULT();
  79439. }
  79440. static int test_wolfSSL_CTX_set_timeout(void)
  79441. {
  79442. EXPECT_DECLS;
  79443. #if !defined(NO_WOLFSSL_SERVER) && !defined(NO_SESSION_CACHE)
  79444. int timeout;
  79445. WOLFSSL_CTX* ctx = NULL;
  79446. (void)timeout;
  79447. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  79448. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  79449. /* in WOLFSSL_ERROR_CODE_OPENSSL macro guard,
  79450. * wolfSSL_CTX_set_timeout returns previous timeout value on success.
  79451. */
  79452. ExpectIntEQ(wolfSSL_CTX_set_timeout(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  79453. /* giving 0 as timeout value sets default timeout */
  79454. timeout = wolfSSL_CTX_set_timeout(ctx, 0);
  79455. ExpectIntEQ(wolfSSL_CTX_set_timeout(ctx, 20), timeout);
  79456. ExpectIntEQ(wolfSSL_CTX_set_timeout(ctx, 30), 20);
  79457. #else
  79458. ExpectIntEQ(wolfSSL_CTX_set_timeout(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  79459. ExpectIntEQ(wolfSSL_CTX_set_timeout(ctx, 100), 1);
  79460. ExpectIntEQ(wolfSSL_CTX_set_timeout(ctx, 0), 1);
  79461. #endif
  79462. wolfSSL_CTX_free(ctx);
  79463. #endif /* !NO_WOLFSSL_SERVER && !NO_SESSION_CACHE*/
  79464. return EXPECT_RESULT();
  79465. }
  79466. static int test_wolfSSL_OpenSSL_version(void)
  79467. {
  79468. EXPECT_DECLS;
  79469. #if defined(OPENSSL_EXTRA)
  79470. const char* ver;
  79471. #if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
  79472. ExpectNotNull(ver = OpenSSL_version(0));
  79473. #else
  79474. ExpectNotNull(ver = OpenSSL_version());
  79475. #endif
  79476. ExpectIntEQ(XMEMCMP(ver, "wolfSSL " LIBWOLFSSL_VERSION_STRING,
  79477. XSTRLEN("wolfSSL " LIBWOLFSSL_VERSION_STRING)), 0);
  79478. #endif
  79479. return EXPECT_RESULT();
  79480. }
  79481. static int test_CONF_CTX_CMDLINE(void)
  79482. {
  79483. EXPECT_DECLS;
  79484. #if defined(OPENSSL_ALL)
  79485. SSL_CTX* ctx = NULL;
  79486. SSL_CONF_CTX* cctx = NULL;
  79487. ExpectNotNull(cctx = SSL_CONF_CTX_new());
  79488. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  79489. SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
  79490. /* set flags */
  79491. ExpectIntEQ(SSL_CONF_CTX_set_flags(cctx, WOLFSSL_CONF_FLAG_CMDLINE),
  79492. WOLFSSL_CONF_FLAG_CMDLINE);
  79493. ExpectIntEQ(SSL_CONF_CTX_set_flags(cctx, WOLFSSL_CONF_FLAG_CERTIFICATE),
  79494. WOLFSSL_CONF_FLAG_CMDLINE | WOLFSSL_CONF_FLAG_CERTIFICATE);
  79495. /* cmd invalid command */
  79496. ExpectIntEQ(SSL_CONF_cmd(cctx, "foo", "foobar"), -2);
  79497. ExpectIntEQ(SSL_CONF_cmd(cctx, "foo", NULL), -2);
  79498. ExpectIntEQ(SSL_CONF_cmd(cctx, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79499. ExpectIntEQ(SSL_CONF_cmd(cctx, NULL, "foobar"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79500. ExpectIntEQ(SSL_CONF_cmd(NULL, "-curves", "foobar"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79501. /* cmd Certificate and Private Key*/
  79502. {
  79503. #if !defined(NO_CERTS) && !defined(NO_RSA)
  79504. const char* ourCert = svrCertFile;
  79505. const char* ourKey = svrKeyFile;
  79506. ExpectIntEQ(SSL_CONF_cmd(cctx, "-cert", NULL), -3);
  79507. ExpectIntEQ(SSL_CONF_cmd(cctx, "-cert", ourCert), WOLFSSL_SUCCESS);
  79508. ExpectIntEQ(SSL_CONF_cmd(cctx, "-key", NULL), -3);
  79509. ExpectIntEQ(SSL_CONF_cmd(cctx, "-key", ourKey), WOLFSSL_SUCCESS);
  79510. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  79511. #endif
  79512. }
  79513. /* cmd curves */
  79514. {
  79515. #if defined(HAVE_ECC)
  79516. const char* curve = "secp256r1";
  79517. ExpectIntEQ(SSL_CONF_cmd(cctx, "-curves", NULL), -3);
  79518. ExpectIntEQ(SSL_CONF_cmd(cctx, "-curves", curve), WOLFSSL_SUCCESS);
  79519. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  79520. #endif
  79521. }
  79522. /* cmd CipherString */
  79523. {
  79524. char* cipher = wolfSSL_get_cipher_list(0/*top priority*/);
  79525. ExpectIntEQ(SSL_CONF_cmd(cctx, "-cipher", NULL), -3);
  79526. ExpectIntEQ(SSL_CONF_cmd(cctx, "-cipher", cipher), WOLFSSL_SUCCESS);
  79527. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  79528. }
  79529. /* cmd DH parameter */
  79530. {
  79531. #if !defined(NO_DH) && !defined(NO_BIO)
  79532. const char* ourdhcert = "./certs/dh2048.pem";
  79533. ExpectIntEQ(SSL_CONF_cmd(cctx, "-dhparam", NULL), -3);
  79534. ExpectIntEQ(SSL_CONF_cmd(cctx, "-dhparam", ourdhcert), WOLFSSL_SUCCESS);
  79535. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  79536. #endif
  79537. }
  79538. SSL_CTX_free(ctx);
  79539. SSL_CONF_CTX_free(cctx);
  79540. #endif /* OPENSSL_EXTRA */
  79541. return EXPECT_RESULT();
  79542. }
  79543. static int test_CONF_CTX_FILE(void)
  79544. {
  79545. EXPECT_DECLS;
  79546. #if defined(OPENSSL_ALL)
  79547. SSL_CTX* ctx = NULL;
  79548. SSL_CONF_CTX* cctx = NULL;
  79549. ExpectNotNull(cctx = SSL_CONF_CTX_new());
  79550. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  79551. SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
  79552. /* set flags */
  79553. ExpectIntEQ(SSL_CONF_CTX_set_flags(cctx, WOLFSSL_CONF_FLAG_FILE),
  79554. WOLFSSL_CONF_FLAG_FILE);
  79555. ExpectIntEQ(SSL_CONF_CTX_set_flags(cctx, WOLFSSL_CONF_FLAG_CERTIFICATE),
  79556. WOLFSSL_CONF_FLAG_FILE | WOLFSSL_CONF_FLAG_CERTIFICATE);
  79557. /* sanity check */
  79558. ExpectIntEQ(SSL_CONF_cmd(cctx, "foo", "foobar"), -2);
  79559. ExpectIntEQ(SSL_CONF_cmd(cctx, "foo", NULL), -2);
  79560. ExpectIntEQ(SSL_CONF_cmd(cctx, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79561. ExpectIntEQ(SSL_CONF_cmd(cctx, NULL, "foobar"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79562. ExpectIntEQ(SSL_CONF_cmd(NULL, "-curves", "foobar"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79563. /* cmd Certificate and Private Key*/
  79564. {
  79565. #if !defined(NO_CERTS) && !defined(NO_RSA)
  79566. const char* ourCert = svrCertFile;
  79567. const char* ourKey = svrKeyFile;
  79568. ExpectIntEQ(SSL_CONF_cmd(cctx, "Certificate", NULL), -3);
  79569. ExpectIntEQ(SSL_CONF_cmd(cctx, "PrivateKey", NULL), -3);
  79570. ExpectIntEQ(SSL_CONF_cmd(cctx, "Certificate", ourCert),
  79571. WOLFSSL_SUCCESS);
  79572. ExpectIntEQ(SSL_CONF_cmd(cctx, "PrivateKey", ourKey), WOLFSSL_SUCCESS);
  79573. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  79574. #endif
  79575. }
  79576. /* cmd curves */
  79577. {
  79578. #if defined(HAVE_ECC)
  79579. const char* curve = "secp256r1";
  79580. ExpectIntEQ(SSL_CONF_cmd(cctx, "Curves", NULL), -3);
  79581. ExpectIntEQ(SSL_CONF_cmd(cctx, "Curves", curve), WOLFSSL_SUCCESS);
  79582. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  79583. #endif
  79584. }
  79585. /* cmd CipherString */
  79586. {
  79587. char* cipher = wolfSSL_get_cipher_list(0/*top priority*/);
  79588. ExpectIntEQ(SSL_CONF_cmd(cctx, "CipherString", NULL), -3);
  79589. ExpectIntEQ(SSL_CONF_cmd(cctx, "CipherString", cipher),
  79590. WOLFSSL_SUCCESS);
  79591. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  79592. }
  79593. /* cmd DH parameter */
  79594. {
  79595. #if !defined(NO_DH) && !defined(NO_BIO) && defined(HAVE_FFDHE_3072)
  79596. const char* ourdhcert = "./certs/dh3072.pem";
  79597. ExpectIntEQ(SSL_CONF_cmd(cctx, "DHParameters", NULL), -3);
  79598. ExpectIntEQ(SSL_CONF_cmd(cctx, "DHParameters", ourdhcert),
  79599. WOLFSSL_SUCCESS);
  79600. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  79601. #endif
  79602. }
  79603. SSL_CTX_free(ctx);
  79604. SSL_CONF_CTX_free(cctx);
  79605. #endif /* OPENSSL_EXTRA */
  79606. return EXPECT_RESULT();
  79607. }
  79608. static int test_wolfSSL_CRYPTO_get_ex_new_index(void)
  79609. {
  79610. EXPECT_DECLS;
  79611. #ifdef HAVE_EX_DATA
  79612. int idx1, idx2;
  79613. /* test for unsupported class index */
  79614. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_X509_STORE,
  79615. 0,NULL, NULL, NULL, NULL ), -1);
  79616. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(
  79617. WOLF_CRYPTO_EX_INDEX_X509_STORE_CTX,
  79618. 0,NULL, NULL, NULL, NULL ), -1);
  79619. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_DH,
  79620. 0,NULL, NULL, NULL, NULL ), -1);
  79621. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_DSA,
  79622. 0,NULL, NULL, NULL, NULL ), -1);
  79623. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_EC_KEY,
  79624. 0,NULL, NULL, NULL, NULL ), -1);
  79625. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_RSA,
  79626. 0,NULL, NULL, NULL, NULL ), -1);
  79627. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_ENGINE,
  79628. 0,NULL, NULL, NULL, NULL ), -1);
  79629. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_UI,
  79630. 0,NULL, NULL, NULL, NULL ), -1);
  79631. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_BIO,
  79632. 0,NULL, NULL, NULL, NULL ), -1);
  79633. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_APP,
  79634. 0,NULL, NULL, NULL, NULL ), -1);
  79635. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_UI_METHOD,
  79636. 0,NULL, NULL, NULL, NULL ), -1);
  79637. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_DRBG,
  79638. 0,NULL, NULL, NULL, NULL ), -1);
  79639. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(20,
  79640. 0,NULL, NULL, NULL, NULL ), -1);
  79641. /* test for supported class index */
  79642. idx1 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL,
  79643. 0,NULL, NULL, NULL, NULL );
  79644. idx2 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL,
  79645. 0,NULL, NULL, NULL, NULL );
  79646. ExpectIntNE(idx1, -1);
  79647. ExpectIntNE(idx2, -1);
  79648. ExpectIntNE(idx1, idx2);
  79649. idx1 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL_CTX,
  79650. 0,NULL, NULL, NULL, NULL );
  79651. idx2 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL_CTX,
  79652. 0,NULL, NULL, NULL, NULL );
  79653. ExpectIntNE(idx1, -1);
  79654. ExpectIntNE(idx2, -1);
  79655. ExpectIntNE(idx1, idx2);
  79656. idx1 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_X509,
  79657. 0,NULL, NULL, NULL, NULL );
  79658. idx2 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_X509,
  79659. 0,NULL, NULL, NULL, NULL );
  79660. ExpectIntNE(idx1, -1);
  79661. ExpectIntNE(idx2, -1);
  79662. ExpectIntNE(idx1, idx2);
  79663. idx1 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL_SESSION,
  79664. 0,NULL, NULL, NULL, NULL );
  79665. idx2 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL_SESSION,
  79666. 0,NULL, NULL, NULL, NULL );
  79667. ExpectIntNE(idx1, -1);
  79668. ExpectIntNE(idx2, -1);
  79669. ExpectIntNE(idx1, idx2);
  79670. #endif /* HAVE_EX_DATA */
  79671. return EXPECT_RESULT();
  79672. }
  79673. #if defined(HAVE_EX_DATA) && defined(HAVE_EXT_CACHE) && \
  79674. (defined(OPENSSL_ALL) || (defined(OPENSSL_EXTRA) && \
  79675. (defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || \
  79676. defined(HAVE_LIGHTY) || defined(WOLFSSL_HAPROXY) || \
  79677. defined(WOLFSSL_OPENSSH) || defined(HAVE_SBLIM_SFCB))))
  79678. #define SESSION_NEW_IDX_LONG 0xDEADBEEF
  79679. #define SESSION_NEW_IDX_VAL ((void*)0xAEADAEAD)
  79680. #define SESSION_DUP_IDX_VAL ((void*)0xDEDEDEDE)
  79681. #define SESSION_NEW_IDX_PTR "Testing"
  79682. static void test_wolfSSL_SESSION_get_ex_new_index_new_cb(void* p, void* ptr,
  79683. CRYPTO_EX_DATA* a, int idx, long argValue, void* arg)
  79684. {
  79685. AssertNotNull(p);
  79686. AssertNull(ptr);
  79687. AssertIntEQ(CRYPTO_set_ex_data(a, idx, SESSION_NEW_IDX_VAL), SSL_SUCCESS);
  79688. AssertIntEQ(argValue, SESSION_NEW_IDX_LONG);
  79689. AssertStrEQ(arg, SESSION_NEW_IDX_PTR);
  79690. }
  79691. static int test_wolfSSL_SESSION_get_ex_new_index_dup_cb(CRYPTO_EX_DATA* out,
  79692. const CRYPTO_EX_DATA* in, void* inPtr, int idx, long argV,
  79693. void* arg)
  79694. {
  79695. EXPECT_DECLS;
  79696. ExpectNotNull(out);
  79697. ExpectNotNull(in);
  79698. ExpectPtrEq(*(void**)inPtr, SESSION_NEW_IDX_VAL);
  79699. ExpectPtrEq(CRYPTO_get_ex_data(in, idx), SESSION_NEW_IDX_VAL);
  79700. ExpectPtrEq(CRYPTO_get_ex_data(out, idx), SESSION_NEW_IDX_VAL);
  79701. ExpectIntEQ(argV, SESSION_NEW_IDX_LONG);
  79702. ExpectStrEQ(arg, SESSION_NEW_IDX_PTR);
  79703. *(void**)inPtr = SESSION_DUP_IDX_VAL;
  79704. if (EXPECT_SUCCESS()) {
  79705. return SSL_SUCCESS;
  79706. }
  79707. else {
  79708. return SSL_FAILURE;
  79709. }
  79710. }
  79711. static int test_wolfSSL_SESSION_get_ex_new_index_free_cb_called = 0;
  79712. static void test_wolfSSL_SESSION_get_ex_new_index_free_cb(void* p, void* ptr,
  79713. CRYPTO_EX_DATA* a, int idx, long argValue, void* arg)
  79714. {
  79715. EXPECT_DECLS;
  79716. ExpectNotNull(p);
  79717. ExpectNull(ptr);
  79718. ExpectPtrNE(CRYPTO_get_ex_data(a, idx), 0);
  79719. ExpectIntEQ(argValue, SESSION_NEW_IDX_LONG);
  79720. ExpectStrEQ(arg, SESSION_NEW_IDX_PTR);
  79721. if (EXPECT_SUCCESS()) {
  79722. test_wolfSSL_SESSION_get_ex_new_index_free_cb_called++;
  79723. }
  79724. }
  79725. static int test_wolfSSL_SESSION_get_ex_new_index(void)
  79726. {
  79727. EXPECT_DECLS;
  79728. int idx = SSL_SESSION_get_ex_new_index(SESSION_NEW_IDX_LONG,
  79729. (void*)SESSION_NEW_IDX_PTR,
  79730. test_wolfSSL_SESSION_get_ex_new_index_new_cb,
  79731. test_wolfSSL_SESSION_get_ex_new_index_dup_cb,
  79732. test_wolfSSL_SESSION_get_ex_new_index_free_cb);
  79733. SSL_SESSION* s = SSL_SESSION_new();
  79734. SSL_SESSION* d = NULL;
  79735. ExpectNotNull(s);
  79736. ExpectPtrEq(SSL_SESSION_get_ex_data(s, idx), SESSION_NEW_IDX_VAL);
  79737. ExpectNotNull(d = SSL_SESSION_dup(s));
  79738. ExpectPtrEq(SSL_SESSION_get_ex_data(d, idx), SESSION_DUP_IDX_VAL);
  79739. SSL_SESSION_free(s);
  79740. ExpectIntEQ(test_wolfSSL_SESSION_get_ex_new_index_free_cb_called, 1);
  79741. SSL_SESSION_free(d);
  79742. ExpectIntEQ(test_wolfSSL_SESSION_get_ex_new_index_free_cb_called, 2);
  79743. crypto_ex_cb_free(crypto_ex_cb_ctx_session);
  79744. crypto_ex_cb_ctx_session = NULL;
  79745. return EXPECT_RESULT();
  79746. }
  79747. #else
  79748. static int test_wolfSSL_SESSION_get_ex_new_index(void)
  79749. {
  79750. return TEST_SKIPPED;
  79751. }
  79752. #endif
  79753. static int test_wolfSSL_set_psk_use_session_callback(void)
  79754. {
  79755. EXPECT_DECLS;
  79756. #if defined(OPENSSL_EXTRA) && !defined(NO_PSK)
  79757. SSL_CTX* ctx = NULL;
  79758. SSL* ssl = NULL;
  79759. const char* testCertFile;
  79760. const char* testKeyFile;
  79761. #ifdef WOLFSSL_TLS13
  79762. #ifdef NO_WOLFSSL_SERVER
  79763. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  79764. #else
  79765. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  79766. #endif
  79767. #else
  79768. #ifdef NO_WOLFSSL_SERVER
  79769. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  79770. #else
  79771. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  79772. #endif
  79773. #endif
  79774. #ifndef NO_RSA
  79775. testCertFile = svrCertFile;
  79776. testKeyFile = svrKeyFile;
  79777. #elif defined(HAVE_ECC)
  79778. testCertFile = eccCertFile;
  79779. testKeyFile = eccKeyFile;
  79780. #else
  79781. testCertFile = NULL;
  79782. testKeyFile = NULL;
  79783. #endif
  79784. if ((testCertFile != NULL) && (testKeyFile != NULL)) {
  79785. ExpectTrue(SSL_CTX_use_certificate_file(ctx, testCertFile,
  79786. SSL_FILETYPE_PEM));
  79787. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  79788. SSL_FILETYPE_PEM));
  79789. }
  79790. ExpectNotNull(ssl = SSL_new(ctx));
  79791. SSL_set_psk_use_session_callback(ssl, my_psk_use_session_cb);
  79792. SSL_CTX_free(ctx);
  79793. SSL_free(ssl);
  79794. #endif
  79795. return EXPECT_RESULT();
  79796. }
  79797. /* similar to error_test() in wolfcrypt/test/test.c, but adding error codes from
  79798. * TLS layer.
  79799. */
  79800. static int error_test(void)
  79801. {
  79802. EXPECT_DECLS;
  79803. const char* errStr;
  79804. const char* unknownStr = wc_GetErrorString(0);
  79805. #ifdef NO_ERROR_STRINGS
  79806. /* Ensure a valid error code's string matches an invalid code's.
  79807. * The string is that error strings are not available.
  79808. */
  79809. errStr = wc_GetErrorString(OPEN_RAN_E);
  79810. ExpectIntEQ(XSTRCMP(errStr, unknownStr), 0);
  79811. if (EXPECT_FAIL())
  79812. return OPEN_RAN_E;
  79813. #else
  79814. int i;
  79815. int j = 0;
  79816. /* Values that are not or no longer error codes. */
  79817. static const struct {
  79818. int first;
  79819. int last;
  79820. } missing[] = {
  79821. #ifndef OPENSSL_EXTRA
  79822. { 0, 0 },
  79823. #endif
  79824. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
  79825. defined(HAVE_WEBSERVER) || defined(HAVE_MEMCACHED)
  79826. { -11, -12 },
  79827. { -15, -17 },
  79828. { -19, -19 },
  79829. { -26, -27 },
  79830. { -30, WC_FIRST_E+1 },
  79831. #else
  79832. { -9, WC_FIRST_E+1 },
  79833. #endif
  79834. { -124, -124 },
  79835. { -166, -169 },
  79836. { -300, -300 },
  79837. { -334, -336 },
  79838. { -346, -349 },
  79839. { -356, -356 },
  79840. { -358, -358 },
  79841. { -372, -372 },
  79842. { -384, -384 },
  79843. { -466, -499 },
  79844. { WOLFSSL_LAST_E-1, WOLFSSL_LAST_E-1 }
  79845. };
  79846. /* Check that all errors have a string and it's the same through the two
  79847. * APIs. Check that the values that are not errors map to the unknown
  79848. * string.
  79849. */
  79850. for (i = 0; i >= WOLFSSL_LAST_E-1; i--) {
  79851. int this_missing = 0;
  79852. for (j = 0; j < (int)XELEM_CNT(missing); ++j) {
  79853. if ((i <= missing[j].first) && (i >= missing[j].last)) {
  79854. this_missing = 1;
  79855. break;
  79856. }
  79857. }
  79858. errStr = wolfSSL_ERR_reason_error_string(i);
  79859. if (! this_missing) {
  79860. ExpectIntNE(XSTRCMP(errStr, unknownStr), 0);
  79861. if (EXPECT_FAIL()) {
  79862. return i;
  79863. }
  79864. ExpectTrue(XSTRLEN(errStr) < WOLFSSL_MAX_ERROR_SZ);
  79865. if (EXPECT_FAIL()) {
  79866. return i;
  79867. }
  79868. }
  79869. else {
  79870. j++;
  79871. ExpectIntEQ(XSTRCMP(errStr, unknownStr), 0);
  79872. if (EXPECT_FAIL()) {
  79873. return i;
  79874. }
  79875. }
  79876. }
  79877. #endif
  79878. return 1;
  79879. }
  79880. static int test_wolfSSL_ERR_strings(void)
  79881. {
  79882. EXPECT_DECLS;
  79883. #if !defined(NO_ERROR_STRINGS)
  79884. const char* err1 = "unsupported cipher suite";
  79885. const char* err2 = "wolfSSL PEM routines";
  79886. const char* err = NULL;
  79887. (void)err;
  79888. (void)err1;
  79889. (void)err2;
  79890. #if defined(OPENSSL_EXTRA)
  79891. ExpectNotNull(err = ERR_reason_error_string(WC_NO_ERR_TRACE(UNSUPPORTED_SUITE)));
  79892. ExpectIntEQ(XSTRNCMP(err, err1, XSTRLEN(err1)), 0);
  79893. ExpectNotNull(err = ERR_func_error_string(WC_NO_ERR_TRACE(UNSUPPORTED_SUITE)));
  79894. ExpectIntEQ((*err == '\0'), 1);
  79895. ExpectNotNull(err = ERR_lib_error_string(PEM_R_PROBLEMS_GETTING_PASSWORD));
  79896. ExpectIntEQ(XSTRNCMP(err, err2, XSTRLEN(err2)), 0);
  79897. #else
  79898. ExpectNotNull(err = wolfSSL_ERR_reason_error_string(WC_NO_ERR_TRACE(UNSUPPORTED_SUITE)));
  79899. ExpectIntEQ(XSTRNCMP(err, err1, XSTRLEN(err1)), 0);
  79900. ExpectNotNull(err = wolfSSL_ERR_func_error_string(WC_NO_ERR_TRACE(UNSUPPORTED_SUITE)));
  79901. ExpectIntEQ((*err == '\0'), 1);
  79902. /* The value -MIN_CODE_E+2 is PEM_R_PROBLEMS_GETTING_PASSWORD. */
  79903. ExpectNotNull(err = wolfSSL_ERR_lib_error_string(-MIN_CODE_E+2));
  79904. ExpectIntEQ((*err == '\0'), 1);
  79905. #endif
  79906. #endif
  79907. ExpectIntEQ(error_test(), 1);
  79908. return EXPECT_RESULT();
  79909. }
  79910. static int test_wolfSSL_EVP_shake128(void)
  79911. {
  79912. EXPECT_DECLS;
  79913. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA3) && \
  79914. defined(WOLFSSL_SHAKE128)
  79915. const EVP_MD* md = NULL;
  79916. ExpectNotNull(md = EVP_shake128());
  79917. ExpectIntEQ(XSTRNCMP(md, "SHAKE128", XSTRLEN("SHAKE128")), 0);
  79918. #endif
  79919. return EXPECT_RESULT();
  79920. }
  79921. static int test_wolfSSL_EVP_shake256(void)
  79922. {
  79923. EXPECT_DECLS;
  79924. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA3) && \
  79925. defined(WOLFSSL_SHAKE256)
  79926. const EVP_MD* md = NULL;
  79927. ExpectNotNull(md = EVP_shake256());
  79928. ExpectIntEQ(XSTRNCMP(md, "SHAKE256", XSTRLEN("SHAKE256")), 0);
  79929. #endif
  79930. return EXPECT_RESULT();
  79931. }
  79932. /*
  79933. * Testing EVP digest API with SM3
  79934. */
  79935. static int test_wolfSSL_EVP_sm3(void)
  79936. {
  79937. int res = TEST_SKIPPED;
  79938. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM3)
  79939. EXPECT_DECLS;
  79940. const EVP_MD* md = NULL;
  79941. EVP_MD_CTX* mdCtx = NULL;
  79942. byte data[WC_SM3_BLOCK_SIZE * 4];
  79943. byte hash[WC_SM3_DIGEST_SIZE];
  79944. byte calcHash[WC_SM3_DIGEST_SIZE];
  79945. byte expHash[WC_SM3_DIGEST_SIZE] = {
  79946. 0x38, 0x48, 0x15, 0xa7, 0x0e, 0xae, 0x0b, 0x27,
  79947. 0x5c, 0xde, 0x9d, 0xa5, 0xd1, 0xa4, 0x30, 0xa1,
  79948. 0xca, 0xd4, 0x54, 0x58, 0x44, 0xa2, 0x96, 0x1b,
  79949. 0xd7, 0x14, 0x80, 0x3f, 0x80, 0x1a, 0x07, 0xb6
  79950. };
  79951. word32 chunk;
  79952. word32 i;
  79953. unsigned int sz;
  79954. int ret;
  79955. XMEMSET(data, 0, sizeof(data));
  79956. md = EVP_sm3();
  79957. ExpectTrue(md != NULL);
  79958. ExpectIntEQ(XSTRNCMP(md, "SM3", XSTRLEN("SM3")), 0);
  79959. mdCtx = EVP_MD_CTX_new();
  79960. ExpectTrue(mdCtx != NULL);
  79961. /* Invalid Parameters */
  79962. ExpectIntEQ(EVP_DigestInit(NULL, md), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79963. /* Valid Parameters */
  79964. ExpectIntEQ(EVP_DigestInit(mdCtx, md), WOLFSSL_SUCCESS);
  79965. ExpectIntEQ(EVP_DigestUpdate(NULL, NULL, 1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79966. ExpectIntEQ(EVP_DigestUpdate(mdCtx, NULL, 1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79967. ExpectIntEQ(EVP_DigestUpdate(NULL, data, 1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79968. /* Valid Parameters */
  79969. ExpectIntEQ(EVP_DigestUpdate(mdCtx, NULL, 0), WOLFSSL_SUCCESS);
  79970. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, 1), WOLFSSL_SUCCESS);
  79971. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, 1), WOLFSSL_SUCCESS);
  79972. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, WC_SM3_BLOCK_SIZE),
  79973. WOLFSSL_SUCCESS);
  79974. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, WC_SM3_BLOCK_SIZE - 2),
  79975. WOLFSSL_SUCCESS);
  79976. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, WC_SM3_BLOCK_SIZE * 2),
  79977. WOLFSSL_SUCCESS);
  79978. /* Ensure too many bytes for lengths. */
  79979. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, WC_SM3_PAD_SIZE),
  79980. WOLFSSL_SUCCESS);
  79981. /* Invalid Parameters */
  79982. ExpectIntEQ(EVP_DigestFinal(NULL, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79983. ExpectIntEQ(EVP_DigestFinal(mdCtx, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79984. ExpectIntEQ(EVP_DigestFinal(NULL, hash, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79985. ExpectIntEQ(EVP_DigestFinal(NULL, hash, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79986. ExpectIntEQ(EVP_DigestFinal(mdCtx, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  79987. /* Valid Parameters */
  79988. ExpectIntEQ(EVP_DigestFinal(mdCtx, hash, NULL), WOLFSSL_SUCCESS);
  79989. ExpectBufEQ(hash, expHash, WC_SM3_DIGEST_SIZE);
  79990. /* Chunk tests. */
  79991. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, sizeof(data)), WOLFSSL_SUCCESS);
  79992. ExpectIntEQ(EVP_DigestFinal(mdCtx, calcHash, &sz), WOLFSSL_SUCCESS);
  79993. ExpectIntEQ(sz, WC_SM3_DIGEST_SIZE);
  79994. for (chunk = 1; chunk <= WC_SM3_BLOCK_SIZE + 1; chunk++) {
  79995. for (i = 0; i + chunk <= (word32)sizeof(data); i += chunk) {
  79996. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data + i, chunk),
  79997. WOLFSSL_SUCCESS);
  79998. }
  79999. if (i < (word32)sizeof(data)) {
  80000. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data + i,
  80001. (word32)sizeof(data) - i), WOLFSSL_SUCCESS);
  80002. }
  80003. ExpectIntEQ(EVP_DigestFinal(mdCtx, hash, NULL), WOLFSSL_SUCCESS);
  80004. ExpectBufEQ(hash, calcHash, WC_SM3_DIGEST_SIZE);
  80005. }
  80006. /* Not testing when the low 32-bit length overflows. */
  80007. ret = EVP_MD_CTX_cleanup(mdCtx);
  80008. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  80009. wolfSSL_EVP_MD_CTX_free(mdCtx);
  80010. res = EXPECT_RESULT();
  80011. #endif
  80012. return res;
  80013. } /* END test_EVP_sm3 */
  80014. static int test_EVP_blake2(void)
  80015. {
  80016. EXPECT_DECLS;
  80017. #if defined(OPENSSL_EXTRA) && (defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S))
  80018. const EVP_MD* md = NULL;
  80019. (void)md;
  80020. #if defined(HAVE_BLAKE2)
  80021. ExpectNotNull(md = EVP_blake2b512());
  80022. ExpectIntEQ(XSTRNCMP(md, "BLAKE2B512", XSTRLEN("BLAKE2B512")), 0);
  80023. #endif
  80024. #if defined(HAVE_BLAKE2S)
  80025. ExpectNotNull(md = EVP_blake2s256());
  80026. ExpectIntEQ(XSTRNCMP(md, "BLAKE2S256", XSTRLEN("BLAKE2S256")), 0);
  80027. #endif
  80028. #endif
  80029. return EXPECT_RESULT();
  80030. }
  80031. #if defined(OPENSSL_EXTRA)
  80032. static void list_md_fn(const EVP_MD* m, const char* from,
  80033. const char* to, void* arg)
  80034. {
  80035. const char* mn;
  80036. BIO *bio;
  80037. (void) from;
  80038. (void) to;
  80039. (void) arg;
  80040. (void) mn;
  80041. (void) bio;
  80042. if (!m) {
  80043. /* alias */
  80044. AssertNull(m);
  80045. AssertNotNull(to);
  80046. }
  80047. else {
  80048. AssertNotNull(m);
  80049. AssertNull(to);
  80050. }
  80051. AssertNotNull(from);
  80052. #if !defined(NO_FILESYSTEM) && defined(DEBUG_WOLFSSL_VERBOSE)
  80053. mn = EVP_get_digestbyname(from);
  80054. /* print to stderr */
  80055. AssertNotNull(arg);
  80056. bio = BIO_new(BIO_s_file());
  80057. BIO_set_fp(bio, arg, BIO_NOCLOSE);
  80058. BIO_printf(bio, "Use %s message digest algorithm\n", mn);
  80059. BIO_free(bio);
  80060. #endif
  80061. }
  80062. #endif
  80063. static int test_EVP_MD_do_all(void)
  80064. {
  80065. int res = TEST_SKIPPED;
  80066. #if defined(OPENSSL_EXTRA)
  80067. EVP_MD_do_all(NULL, stderr);
  80068. EVP_MD_do_all(list_md_fn, stderr);
  80069. res = TEST_SUCCESS;
  80070. #endif
  80071. return res;
  80072. }
  80073. #if defined(OPENSSL_EXTRA)
  80074. static void obj_name_t(const OBJ_NAME* nm, void* arg)
  80075. {
  80076. (void)arg;
  80077. (void)nm;
  80078. AssertIntGT(nm->type, OBJ_NAME_TYPE_UNDEF);
  80079. #if !defined(NO_FILESYSTEM) && defined(DEBUG_WOLFSSL_VERBOSE)
  80080. /* print to stderr */
  80081. AssertNotNull(arg);
  80082. BIO *bio = BIO_new(BIO_s_file());
  80083. BIO_set_fp(bio, arg, BIO_NOCLOSE);
  80084. BIO_printf(bio, "%s\n", nm);
  80085. BIO_free(bio);
  80086. #endif
  80087. }
  80088. #endif
  80089. static int test_OBJ_NAME_do_all(void)
  80090. {
  80091. int res = TEST_SKIPPED;
  80092. #if defined(OPENSSL_EXTRA)
  80093. OBJ_NAME_do_all(OBJ_NAME_TYPE_MD_METH, NULL, NULL);
  80094. OBJ_NAME_do_all(OBJ_NAME_TYPE_CIPHER_METH, NULL, stderr);
  80095. OBJ_NAME_do_all(OBJ_NAME_TYPE_MD_METH, obj_name_t, stderr);
  80096. OBJ_NAME_do_all(OBJ_NAME_TYPE_PKEY_METH, obj_name_t, stderr);
  80097. OBJ_NAME_do_all(OBJ_NAME_TYPE_COMP_METH, obj_name_t, stderr);
  80098. OBJ_NAME_do_all(OBJ_NAME_TYPE_NUM, obj_name_t, stderr);
  80099. OBJ_NAME_do_all(OBJ_NAME_TYPE_UNDEF, obj_name_t, stderr);
  80100. OBJ_NAME_do_all(OBJ_NAME_TYPE_CIPHER_METH, obj_name_t, stderr);
  80101. OBJ_NAME_do_all(-1, obj_name_t, stderr);
  80102. res = TEST_SUCCESS;
  80103. #endif
  80104. return res;
  80105. }
  80106. static int test_SSL_CIPHER_get_xxx(void)
  80107. {
  80108. EXPECT_DECLS;
  80109. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  80110. !defined(NO_FILESYSTEM)
  80111. const SSL_CIPHER* cipher = NULL;
  80112. STACK_OF(SSL_CIPHER) *supportedCiphers = NULL;
  80113. int i, numCiphers = 0;
  80114. SSL_CTX* ctx = NULL;
  80115. SSL* ssl = NULL;
  80116. const char* testCertFile;
  80117. const char* testKeyFile;
  80118. char buf[256] = {0};
  80119. const char* cipher_id = NULL;
  80120. int expect_nid1 = NID_undef;
  80121. int expect_nid2 = NID_undef;
  80122. int expect_nid3 = NID_undef;
  80123. int expect_nid4 = NID_undef;
  80124. int expect_nid5 = 0;
  80125. const char* cipher_id2 = NULL;
  80126. int expect_nid21 = NID_undef;
  80127. int expect_nid22 = NID_undef;
  80128. int expect_nid23 = NID_undef;
  80129. int expect_nid24 = NID_undef;
  80130. int expect_nid25 = 0;
  80131. (void)cipher;
  80132. (void)supportedCiphers;
  80133. (void)i;
  80134. (void)numCiphers;
  80135. (void)ctx;
  80136. (void)ssl;
  80137. (void)testCertFile;
  80138. (void)testKeyFile;
  80139. #if defined(WOLFSSL_TLS13)
  80140. cipher_id = "TLS13-AES128-GCM-SHA256";
  80141. expect_nid1 = NID_auth_rsa;
  80142. expect_nid2 = NID_aes_128_gcm;
  80143. expect_nid3 = NID_sha256;
  80144. expect_nid4 = NID_kx_any;
  80145. expect_nid5 = 1;
  80146. #if !defined(WOLFSSL_NO_TLS12)
  80147. cipher_id2 = "ECDHE-RSA-AES256-GCM-SHA384";
  80148. expect_nid21 = NID_auth_rsa;
  80149. expect_nid22 = NID_aes_256_gcm;
  80150. expect_nid23 = NID_sha384;
  80151. expect_nid24 = NID_kx_ecdhe;
  80152. expect_nid25 = 1;
  80153. #endif
  80154. #endif
  80155. #ifdef NO_WOLFSSL_SERVER
  80156. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  80157. #else
  80158. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  80159. #endif
  80160. if (cipher_id) {
  80161. #ifndef NO_RSA
  80162. testCertFile = svrCertFile;
  80163. testKeyFile = svrKeyFile;
  80164. #elif defined(HAVE_ECC)
  80165. testCertFile = eccCertFile;
  80166. testKeyFile = eccKeyFile;
  80167. #else
  80168. testCertFile = NULL;
  80169. testKeyFile = NULL;
  80170. #endif
  80171. if (testCertFile != NULL && testKeyFile != NULL) {
  80172. ExpectTrue(SSL_CTX_use_certificate_file(ctx, testCertFile,
  80173. SSL_FILETYPE_PEM));
  80174. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  80175. SSL_FILETYPE_PEM));
  80176. }
  80177. ExpectNotNull(ssl = SSL_new(ctx));
  80178. ExpectIntEQ(SSL_in_init(ssl), 1);
  80179. supportedCiphers = SSL_get_ciphers(ssl);
  80180. numCiphers = sk_num(supportedCiphers);
  80181. for (i = 0; i < numCiphers; ++i) {
  80182. if ((cipher = (const WOLFSSL_CIPHER*)sk_value(supportedCiphers, i))) {
  80183. SSL_CIPHER_description(cipher, buf, sizeof(buf));
  80184. }
  80185. if (XMEMCMP(cipher_id, buf, XSTRLEN(cipher_id)) == 0) {
  80186. break;
  80187. }
  80188. }
  80189. /* test case for */
  80190. if (i != numCiphers) {
  80191. ExpectIntEQ(wolfSSL_CIPHER_get_auth_nid(cipher), expect_nid1);
  80192. ExpectIntEQ(wolfSSL_CIPHER_get_cipher_nid(cipher), expect_nid2);
  80193. ExpectIntEQ(wolfSSL_CIPHER_get_digest_nid(cipher), expect_nid3);
  80194. ExpectIntEQ(wolfSSL_CIPHER_get_kx_nid(cipher), expect_nid4);
  80195. ExpectIntEQ(wolfSSL_CIPHER_is_aead(cipher), expect_nid5);
  80196. }
  80197. if (cipher_id2) {
  80198. for (i = 0; i < numCiphers; ++i) {
  80199. if ((cipher = (const WOLFSSL_CIPHER*)sk_value(supportedCiphers, i))) {
  80200. SSL_CIPHER_description(cipher, buf, sizeof(buf));
  80201. }
  80202. if (XMEMCMP(cipher_id2, buf, XSTRLEN(cipher_id2)) == 0) {
  80203. break;
  80204. }
  80205. }
  80206. /* test case for */
  80207. if (i != numCiphers) {
  80208. ExpectIntEQ(wolfSSL_CIPHER_get_auth_nid(cipher), expect_nid21);
  80209. ExpectIntEQ(wolfSSL_CIPHER_get_cipher_nid(cipher), expect_nid22);
  80210. ExpectIntEQ(wolfSSL_CIPHER_get_digest_nid(cipher), expect_nid23);
  80211. ExpectIntEQ(wolfSSL_CIPHER_get_kx_nid(cipher), expect_nid24);
  80212. ExpectIntEQ(wolfSSL_CIPHER_is_aead(cipher), expect_nid25);
  80213. }
  80214. }
  80215. }
  80216. SSL_CTX_free(ctx);
  80217. SSL_free(ssl);
  80218. #endif
  80219. return EXPECT_RESULT();
  80220. }
  80221. #if defined(WOLF_CRYPTO_CB) && defined(HAVE_IO_TESTS_DEPENDENCIES)
  80222. static int load_pem_key_file_as_der(const char* privKeyFile, DerBuffer** pDer,
  80223. int* keyFormat)
  80224. {
  80225. int ret;
  80226. byte* key_buf = NULL;
  80227. size_t key_sz = 0;
  80228. EncryptedInfo encInfo;
  80229. XMEMSET(&encInfo, 0, sizeof(encInfo));
  80230. ret = load_file(privKeyFile, &key_buf, &key_sz);
  80231. if (ret == 0) {
  80232. ret = wc_PemToDer(key_buf, key_sz, PRIVATEKEY_TYPE, pDer,
  80233. NULL, &encInfo, keyFormat);
  80234. }
  80235. if (key_buf != NULL) {
  80236. free(key_buf); key_buf = NULL;
  80237. }
  80238. (void)encInfo; /* not used in this test */
  80239. #ifdef DEBUG_WOLFSSL
  80240. fprintf(stderr, "%s (%d): Loading PEM %s (len %d) to DER (len %d)\n",
  80241. (ret == 0) ? "Success" : "Failure", ret, privKeyFile, (int)key_sz,
  80242. (*pDer)->length);
  80243. #endif
  80244. return ret;
  80245. }
  80246. static int test_CryptoCb_Func(int thisDevId, wc_CryptoInfo* info, void* ctx)
  80247. {
  80248. int ret = WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE);
  80249. const char* privKeyFile = (const char*)ctx;
  80250. DerBuffer* pDer = NULL;
  80251. int keyFormat = 0;
  80252. if (info->algo_type == WC_ALGO_TYPE_PK) {
  80253. #ifdef DEBUG_WOLFSSL
  80254. fprintf(stderr, "test_CryptoCb_Func: Pk Type %d\n", info->pk.type);
  80255. #endif
  80256. #ifndef NO_RSA
  80257. if (info->pk.type == WC_PK_TYPE_RSA) {
  80258. switch (info->pk.rsa.type) {
  80259. case RSA_PUBLIC_ENCRYPT:
  80260. case RSA_PUBLIC_DECRYPT:
  80261. /* perform software based RSA public op */
  80262. ret = WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE); /* fallback to software */
  80263. break;
  80264. case RSA_PRIVATE_ENCRYPT:
  80265. case RSA_PRIVATE_DECRYPT:
  80266. {
  80267. RsaKey key;
  80268. /* perform software based RSA private op */
  80269. #ifdef DEBUG_WOLFSSL
  80270. fprintf(stderr, "test_CryptoCb_Func: RSA Priv\n");
  80271. #endif
  80272. ret = load_pem_key_file_as_der(privKeyFile, &pDer,
  80273. &keyFormat);
  80274. if (ret != 0) {
  80275. return ret;
  80276. }
  80277. ret = wc_InitRsaKey(&key, HEAP_HINT);
  80278. if (ret == 0) {
  80279. word32 keyIdx = 0;
  80280. /* load RSA private key and perform private transform */
  80281. ret = wc_RsaPrivateKeyDecode(pDer->buffer, &keyIdx,
  80282. &key, pDer->length);
  80283. if (ret == 0) {
  80284. ret = wc_RsaFunction(
  80285. info->pk.rsa.in, info->pk.rsa.inLen,
  80286. info->pk.rsa.out, info->pk.rsa.outLen,
  80287. info->pk.rsa.type, &key, info->pk.rsa.rng);
  80288. }
  80289. else {
  80290. /* if decode fails, then fall-back to software based crypto */
  80291. fprintf(stderr, "test_CryptoCb_Func: RSA private "
  80292. "key decode failed %d, falling back to "
  80293. "software\n", ret);
  80294. ret = CRYPTOCB_UNAVAILABLE;
  80295. }
  80296. wc_FreeRsaKey(&key);
  80297. }
  80298. wc_FreeDer(&pDer); pDer = NULL;
  80299. break;
  80300. }
  80301. }
  80302. #ifdef DEBUG_WOLFSSL
  80303. fprintf(stderr, "test_CryptoCb_Func: RSA Type %d, Ret %d, Out %d\n",
  80304. info->pk.rsa.type, ret, *info->pk.rsa.outLen);
  80305. #endif
  80306. }
  80307. #ifdef WOLF_CRYPTO_CB_RSA_PAD
  80308. else if (info->pk.type == WC_PK_TYPE_RSA_PKCS ||
  80309. info->pk.type == WC_PK_TYPE_RSA_PSS ||
  80310. info->pk.type == WC_PK_TYPE_RSA_OAEP) {
  80311. RsaKey key;
  80312. if (info->pk.rsa.type == RSA_PUBLIC_ENCRYPT ||
  80313. info->pk.rsa.type == RSA_PUBLIC_DECRYPT) {
  80314. /* Have all public key ops fall back to SW */
  80315. return CRYPTOCB_UNAVAILABLE;
  80316. }
  80317. if (info->pk.rsa.padding == NULL) {
  80318. return BAD_FUNC_ARG;
  80319. }
  80320. /* Initialize key */
  80321. ret = load_pem_key_file_as_der(privKeyFile, &pDer,
  80322. &keyFormat);
  80323. if (ret != 0) {
  80324. return ret;
  80325. }
  80326. ret = wc_InitRsaKey(&key, HEAP_HINT);
  80327. if (ret == 0) {
  80328. word32 keyIdx = 0;
  80329. /* load RSA private key and perform private transform */
  80330. ret = wc_RsaPrivateKeyDecode(pDer->buffer, &keyIdx,
  80331. &key, pDer->length);
  80332. }
  80333. /* Perform RSA operation */
  80334. if ((ret == 0) && (info->pk.type == WC_PK_TYPE_RSA_PKCS)) {
  80335. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  80336. ret = wc_RsaSSL_Sign(info->pk.rsa.in, info->pk.rsa.inLen,
  80337. info->pk.rsa.out, *info->pk.rsa.outLen, &key,
  80338. info->pk.rsa.rng);
  80339. #else
  80340. ret = CRYPTOCB_UNAVAILABLE;
  80341. #endif
  80342. }
  80343. if ((ret == 0) && (info->pk.type == WC_PK_TYPE_RSA_PSS)) {
  80344. #ifdef WC_RSA_PSS
  80345. ret = wc_RsaPSS_Sign_ex(info->pk.rsa.in, info->pk.rsa.inLen,
  80346. info->pk.rsa.out, *info->pk.rsa.outLen,
  80347. info->pk.rsa.padding->hash, info->pk.rsa.padding->mgf,
  80348. info->pk.rsa.padding->saltLen, &key, info->pk.rsa.rng);
  80349. #else
  80350. ret = CRYPTOCB_UNAVAILABLE;
  80351. #endif
  80352. }
  80353. if ((ret == 0) && (info->pk.type == WC_PK_TYPE_RSA_OAEP)) {
  80354. #if !defined(WC_NO_RSA_OAEP) || defined(WC_RSA_NO_PADDING)
  80355. ret = wc_RsaPrivateDecrypt_ex(
  80356. info->pk.rsa.in, info->pk.rsa.inLen,
  80357. info->pk.rsa.out, *info->pk.rsa.outLen,
  80358. &key, WC_RSA_OAEP_PAD, info->pk.rsa.padding->hash,
  80359. info->pk.rsa.padding->mgf, info->pk.rsa.padding->label,
  80360. info->pk.rsa.padding->labelSz);
  80361. #else
  80362. ret = CRYPTOCB_UNAVAILABLE;
  80363. #endif
  80364. }
  80365. if (ret > 0) {
  80366. *info->pk.rsa.outLen = ret;
  80367. }
  80368. wc_FreeRsaKey(&key);
  80369. wc_FreeDer(&pDer); pDer = NULL;
  80370. }
  80371. #endif /* ifdef WOLF_CRYPTO_CB_RSA_PAD */
  80372. #endif /* !NO_RSA */
  80373. #ifdef HAVE_ECC
  80374. if (info->pk.type == WC_PK_TYPE_EC_KEYGEN) {
  80375. /* mark this key as ephemeral */
  80376. if (info->pk.eckg.key != NULL) {
  80377. XSTRNCPY(info->pk.eckg.key->label, "ephemeral",
  80378. sizeof(info->pk.eckg.key->label));
  80379. info->pk.eckg.key->labelLen = (int)XSTRLEN(info->pk.eckg.key->label);
  80380. }
  80381. }
  80382. else if (info->pk.type == WC_PK_TYPE_ECDSA_SIGN) {
  80383. ecc_key key;
  80384. /* perform software based ECC sign */
  80385. #ifdef DEBUG_WOLFSSL
  80386. fprintf(stderr, "test_CryptoCb_Func: ECC Sign\n");
  80387. #endif
  80388. if (info->pk.eccsign.key != NULL &&
  80389. XSTRCMP(info->pk.eccsign.key->label, "ephemeral") == 0) {
  80390. /* this is an empheral key */
  80391. #ifdef DEBUG_WOLFSSL
  80392. fprintf(stderr, "test_CryptoCb_Func: skipping signing op on "
  80393. "ephemeral key\n");
  80394. #endif
  80395. return CRYPTOCB_UNAVAILABLE;
  80396. }
  80397. ret = load_pem_key_file_as_der(privKeyFile, &pDer, &keyFormat);
  80398. if (ret != 0) {
  80399. return ret;
  80400. }
  80401. ret = wc_ecc_init(&key);
  80402. if (ret == 0) {
  80403. word32 keyIdx = 0;
  80404. /* load ECC private key and perform private transform */
  80405. ret = wc_EccPrivateKeyDecode(pDer->buffer, &keyIdx,
  80406. &key, pDer->length);
  80407. if (ret == 0) {
  80408. ret = wc_ecc_sign_hash(
  80409. info->pk.eccsign.in, info->pk.eccsign.inlen,
  80410. info->pk.eccsign.out, info->pk.eccsign.outlen,
  80411. info->pk.eccsign.rng, &key);
  80412. }
  80413. else {
  80414. /* if decode fails, then fall-back to software based crypto */
  80415. fprintf(stderr, "test_CryptoCb_Func: ECC private key "
  80416. "decode failed %d, falling back to software\n", ret);
  80417. ret = CRYPTOCB_UNAVAILABLE;
  80418. }
  80419. wc_ecc_free(&key);
  80420. }
  80421. wc_FreeDer(&pDer); pDer = NULL;
  80422. #ifdef DEBUG_WOLFSSL
  80423. fprintf(stderr, "test_CryptoCb_Func: ECC Ret %d, Out %d\n",
  80424. ret, *info->pk.eccsign.outlen);
  80425. #endif
  80426. }
  80427. #endif /* HAVE_ECC */
  80428. #ifdef HAVE_ED25519
  80429. if (info->pk.type == WC_PK_TYPE_ED25519_SIGN) {
  80430. ed25519_key key;
  80431. /* perform software based ED25519 sign */
  80432. #ifdef DEBUG_WOLFSSL
  80433. fprintf(stderr, "test_CryptoCb_Func: ED25519 Sign\n");
  80434. #endif
  80435. ret = load_pem_key_file_as_der(privKeyFile, &pDer, &keyFormat);
  80436. if (ret != 0) {
  80437. return ret;
  80438. }
  80439. ret = wc_ed25519_init(&key);
  80440. if (ret == 0) {
  80441. word32 keyIdx = 0;
  80442. /* load ED25519 private key and perform private transform */
  80443. ret = wc_Ed25519PrivateKeyDecode(pDer->buffer, &keyIdx,
  80444. &key, pDer->length);
  80445. if (ret == 0) {
  80446. /* calculate public key */
  80447. ret = wc_ed25519_make_public(&key, key.p, ED25519_PUB_KEY_SIZE);
  80448. if (ret == 0) {
  80449. key.pubKeySet = 1;
  80450. ret = wc_ed25519_sign_msg_ex(
  80451. info->pk.ed25519sign.in, info->pk.ed25519sign.inLen,
  80452. info->pk.ed25519sign.out, info->pk.ed25519sign.outLen,
  80453. &key, info->pk.ed25519sign.type,
  80454. info->pk.ed25519sign.context,
  80455. info->pk.ed25519sign.contextLen);
  80456. }
  80457. }
  80458. else {
  80459. /* if decode fails, then fall-back to software based crypto */
  80460. fprintf(stderr, "test_CryptoCb_Func: ED25519 private key "
  80461. "decode failed %d, falling back to software\n", ret);
  80462. ret = CRYPTOCB_UNAVAILABLE;
  80463. }
  80464. wc_ed25519_free(&key);
  80465. }
  80466. wc_FreeDer(&pDer); pDer = NULL;
  80467. #ifdef DEBUG_WOLFSSL
  80468. fprintf(stderr, "test_CryptoCb_Func: ED25519 Ret %d, Out %d\n",
  80469. ret, *info->pk.ed25519sign.outLen);
  80470. #endif
  80471. }
  80472. #endif /* HAVE_ED25519 */
  80473. }
  80474. (void)thisDevId;
  80475. (void)keyFormat;
  80476. return ret;
  80477. }
  80478. /* tlsVer: WOLFSSL_TLSV1_2 or WOLFSSL_TLSV1_3 */
  80479. static int test_wc_CryptoCb_TLS(int tlsVer,
  80480. const char* cliCaPemFile, const char* cliCertPemFile,
  80481. const char* cliPrivKeyPemFile, const char* cliPubKeyPemFile,
  80482. const char* svrCaPemFile, const char* svrCertPemFile,
  80483. const char* svrPrivKeyPemFile, const char* svrPubKeyPemFile)
  80484. {
  80485. EXPECT_DECLS;
  80486. callback_functions client_cbf;
  80487. callback_functions server_cbf;
  80488. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  80489. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  80490. if (tlsVer == WOLFSSL_TLSV1_3) {
  80491. #ifdef WOLFSSL_TLS13
  80492. server_cbf.method = wolfTLSv1_3_server_method;
  80493. client_cbf.method = wolfTLSv1_3_client_method;
  80494. #endif
  80495. }
  80496. else if (tlsVer == WOLFSSL_TLSV1_2) {
  80497. #ifndef WOLFSSL_NO_TLS12
  80498. server_cbf.method = wolfTLSv1_2_server_method;
  80499. client_cbf.method = wolfTLSv1_2_client_method;
  80500. #endif
  80501. }
  80502. else if (tlsVer == WOLFSSL_TLSV1_1) {
  80503. #ifndef NO_OLD_TLS
  80504. server_cbf.method = wolfTLSv1_1_server_method;
  80505. client_cbf.method = wolfTLSv1_1_client_method;
  80506. #endif
  80507. }
  80508. else if (tlsVer == WOLFSSL_TLSV1) {
  80509. #if !defined(NO_OLD_TLS) && defined(WOLFSSL_ALLOW_TLSV10)
  80510. server_cbf.method = wolfTLSv1_server_method;
  80511. client_cbf.method = wolfTLSv1_client_method;
  80512. #endif
  80513. }
  80514. else if (tlsVer == WOLFSSL_SSLV3) {
  80515. #if !defined(NO_OLD_TLS) && defined(WOLFSSL_ALLOW_SSLV3) && \
  80516. defined(WOLFSSL_STATIC_RSA)
  80517. server_cbf.method = wolfSSLv3_server_method;
  80518. client_cbf.method = wolfSSLv3_client_method;
  80519. #endif
  80520. }
  80521. else if (tlsVer == WOLFSSL_DTLSV1_2) {
  80522. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12)
  80523. server_cbf.method = wolfDTLSv1_2_server_method;
  80524. client_cbf.method = wolfDTLSv1_2_client_method;
  80525. #endif
  80526. }
  80527. else if (tlsVer == WOLFSSL_DTLSV1) {
  80528. #if defined(WOLFSSL_DTLS) && !defined(NO_OLD_TLS)
  80529. server_cbf.method = wolfDTLSv1_server_method;
  80530. client_cbf.method = wolfDTLSv1_client_method;
  80531. #endif
  80532. }
  80533. if (server_cbf.method == NULL) {
  80534. /* not enabled */
  80535. return TEST_SUCCESS;
  80536. }
  80537. /* Setup the keys for the TLS test */
  80538. client_cbf.certPemFile = cliCertPemFile;
  80539. client_cbf.keyPemFile = cliPubKeyPemFile;
  80540. client_cbf.caPemFile = cliCaPemFile;
  80541. server_cbf.certPemFile = svrCertPemFile;
  80542. server_cbf.keyPemFile = svrPubKeyPemFile;
  80543. server_cbf.caPemFile = svrCaPemFile;
  80544. /* Setup a crypto callback with pointer to private key file for testing */
  80545. client_cbf.devId = 1;
  80546. wc_CryptoCb_RegisterDevice(client_cbf.devId, test_CryptoCb_Func,
  80547. (void*)cliPrivKeyPemFile);
  80548. server_cbf.devId = 2;
  80549. wc_CryptoCb_RegisterDevice(server_cbf.devId, test_CryptoCb_Func,
  80550. (void*)svrPrivKeyPemFile);
  80551. /* Perform TLS server and client test */
  80552. /* First test is at WOLFSSL_CTX level */
  80553. test_wolfSSL_client_server(&client_cbf, &server_cbf);
  80554. /* Check for success */
  80555. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  80556. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  80557. if (EXPECT_SUCCESS()) {
  80558. /* Second test is a WOLFSSL object level */
  80559. client_cbf.loadToSSL = 1; server_cbf.loadToSSL = 1;
  80560. test_wolfSSL_client_server(&client_cbf, &server_cbf);
  80561. }
  80562. /* Check for success */
  80563. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  80564. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  80565. /* Un register the devId's */
  80566. wc_CryptoCb_UnRegisterDevice(client_cbf.devId);
  80567. client_cbf.devId = INVALID_DEVID;
  80568. wc_CryptoCb_UnRegisterDevice(server_cbf.devId);
  80569. server_cbf.devId = INVALID_DEVID;
  80570. return EXPECT_RESULT();
  80571. }
  80572. #endif /* WOLF_CRYPTO_CB && HAVE_IO_TESTS_DEPENDENCIES */
  80573. static int test_wc_CryptoCb(void)
  80574. {
  80575. EXPECT_DECLS;
  80576. #ifdef WOLF_CRYPTO_CB
  80577. /* TODO: Add crypto callback API tests */
  80578. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  80579. #if !defined(NO_RSA) || defined(HAVE_ECC) || defined(HAVE_ED25519)
  80580. int tlsVer;
  80581. #endif
  80582. #ifndef NO_RSA
  80583. for (tlsVer = WOLFSSL_SSLV3; tlsVer <= WOLFSSL_DTLSV1; tlsVer++) {
  80584. ExpectIntEQ(test_wc_CryptoCb_TLS(tlsVer,
  80585. svrCertFile, cliCertFile, cliKeyFile, cliKeyPubFile,
  80586. cliCertFile, svrCertFile, svrKeyFile, svrKeyPubFile),
  80587. TEST_SUCCESS);
  80588. }
  80589. #endif
  80590. #ifdef HAVE_ECC
  80591. for (tlsVer = WOLFSSL_TLSV1; tlsVer <= WOLFSSL_DTLSV1; tlsVer++) {
  80592. ExpectIntEQ(test_wc_CryptoCb_TLS(tlsVer,
  80593. caEccCertFile, cliEccCertFile, cliEccKeyFile, cliEccKeyPubFile,
  80594. cliEccCertFile, eccCertFile, eccKeyFile, eccKeyPubFile),
  80595. TEST_SUCCESS);
  80596. }
  80597. #endif
  80598. #ifdef HAVE_ED25519
  80599. for (tlsVer = WOLFSSL_TLSV1_2; tlsVer <= WOLFSSL_DTLSV1_2; tlsVer++) {
  80600. if (tlsVer == WOLFSSL_DTLSV1) continue;
  80601. ExpectIntEQ(test_wc_CryptoCb_TLS(tlsVer,
  80602. caEdCertFile, cliEdCertFile, cliEdKeyFile, cliEdKeyPubFile,
  80603. cliEdCertFile, edCertFile, edKeyFile, edKeyPubFile),
  80604. TEST_SUCCESS);
  80605. }
  80606. #endif
  80607. #endif /* HAVE_IO_TESTS_DEPENDENCIES */
  80608. #endif /* WOLF_CRYPTO_CB */
  80609. return EXPECT_RESULT();
  80610. }
  80611. #if defined(WOLFSSL_STATIC_MEMORY) && defined(HAVE_IO_TESTS_DEPENDENCIES)
  80612. /* tlsVer: Example: WOLFSSL_TLSV1_2 or WOLFSSL_TLSV1_3 */
  80613. static int test_wolfSSL_CTX_StaticMemory_TLS(int tlsVer,
  80614. const char* cliCaPemFile, const char* cliCertPemFile,
  80615. const char* cliPrivKeyPemFile,
  80616. const char* svrCaPemFile, const char* svrCertPemFile,
  80617. const char* svrPrivKeyPemFile,
  80618. byte* cliMem, word32 cliMemSz, byte* svrMem, word32 svrMemSz)
  80619. {
  80620. EXPECT_DECLS;
  80621. callback_functions client_cbf;
  80622. callback_functions server_cbf;
  80623. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  80624. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  80625. if (tlsVer == WOLFSSL_TLSV1_3) {
  80626. #ifdef WOLFSSL_TLS13
  80627. server_cbf.method_ex = wolfTLSv1_3_server_method_ex;
  80628. client_cbf.method_ex = wolfTLSv1_3_client_method_ex;
  80629. #endif
  80630. }
  80631. else if (tlsVer == WOLFSSL_TLSV1_2) {
  80632. #ifndef WOLFSSL_NO_TLS12
  80633. server_cbf.method_ex = wolfTLSv1_2_server_method_ex;
  80634. client_cbf.method_ex = wolfTLSv1_2_client_method_ex;
  80635. #endif
  80636. }
  80637. else if (tlsVer == WOLFSSL_TLSV1_1) {
  80638. #ifndef NO_OLD_TLS
  80639. server_cbf.method_ex = wolfTLSv1_1_server_method_ex;
  80640. client_cbf.method_ex = wolfTLSv1_1_client_method_ex;
  80641. #endif
  80642. }
  80643. else if (tlsVer == WOLFSSL_TLSV1) {
  80644. #if !defined(NO_OLD_TLS) && defined(WOLFSSL_ALLOW_TLSV10)
  80645. server_cbf.method_ex = wolfTLSv1_server_method_ex;
  80646. client_cbf.method_ex = wolfTLSv1_client_method_ex;
  80647. #endif
  80648. }
  80649. else if (tlsVer == WOLFSSL_SSLV3) {
  80650. #if !defined(NO_OLD_TLS) && defined(WOLFSSL_ALLOW_SSLV3) && \
  80651. defined(WOLFSSL_STATIC_RSA)
  80652. server_cbf.method_ex = wolfSSLv3_server_method_ex;
  80653. client_cbf.method_ex = wolfSSLv3_client_method_ex;
  80654. #endif
  80655. }
  80656. else if (tlsVer == WOLFSSL_DTLSV1_2) {
  80657. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12)
  80658. server_cbf.method_ex = wolfDTLSv1_2_server_method_ex;
  80659. client_cbf.method_ex = wolfDTLSv1_2_client_method_ex;
  80660. #endif
  80661. }
  80662. else if (tlsVer == WOLFSSL_DTLSV1) {
  80663. #if defined(WOLFSSL_DTLS) && !defined(NO_OLD_TLS)
  80664. server_cbf.method_ex = wolfDTLSv1_server_method_ex;
  80665. client_cbf.method_ex = wolfDTLSv1_client_method_ex;
  80666. #endif
  80667. }
  80668. if (server_cbf.method_ex == NULL) {
  80669. /* not enabled */
  80670. return TEST_SUCCESS;
  80671. }
  80672. /* Setup the keys for the TLS test */
  80673. client_cbf.certPemFile = cliCertPemFile;
  80674. client_cbf.keyPemFile = cliPrivKeyPemFile;
  80675. client_cbf.caPemFile = cliCaPemFile;
  80676. server_cbf.certPemFile = svrCertPemFile;
  80677. server_cbf.keyPemFile = svrPrivKeyPemFile;
  80678. server_cbf.caPemFile = svrCaPemFile;
  80679. client_cbf.mem = cliMem;
  80680. client_cbf.memSz = cliMemSz;
  80681. server_cbf.mem = svrMem;
  80682. server_cbf.memSz = svrMemSz;
  80683. client_cbf.devId = INVALID_DEVID;
  80684. server_cbf.devId = INVALID_DEVID;
  80685. /* Perform TLS server and client test */
  80686. /* First test is at WOLFSSL_CTX level */
  80687. test_wolfSSL_client_server(&client_cbf, &server_cbf);
  80688. /* Check for success */
  80689. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  80690. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  80691. if (EXPECT_SUCCESS()) {
  80692. /* Second test is a WOLFSSL object level */
  80693. client_cbf.loadToSSL = 1; server_cbf.loadToSSL = 1;
  80694. test_wolfSSL_client_server(&client_cbf, &server_cbf);
  80695. }
  80696. /* Check for success */
  80697. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  80698. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  80699. return EXPECT_RESULT();
  80700. }
  80701. #endif /* WOLFSSL_STATIC_MEMORY && HAVE_IO_TESTS_DEPENDENCIES */
  80702. #if defined(WOLFSSL_STATIC_MEMORY) && !defined(WOLFCRYPT_ONLY)
  80703. static int test_wolfSSL_CTX_StaticMemory_SSL(WOLFSSL_CTX* ctx)
  80704. {
  80705. EXPECT_DECLS;
  80706. WOLFSSL *ssl1 = NULL, *ssl2 = NULL, *ssl3 = NULL;
  80707. WOLFSSL_MEM_STATS mem_stats;
  80708. WOLFSSL_MEM_CONN_STATS ssl_stats;
  80709. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA)
  80710. ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  80711. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  80712. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  80713. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  80714. #endif
  80715. ExpectNotNull((ssl1 = wolfSSL_new(ctx)));
  80716. ExpectNotNull((ssl2 = wolfSSL_new(ctx)));
  80717. #ifndef WOLFSSL_STATIC_MEMORY_LEAN
  80718. /* this should fail because kMaxCtxClients == 2 */
  80719. ExpectNull((ssl3 = wolfSSL_new(ctx)));
  80720. #else
  80721. (void)ssl3;
  80722. #endif
  80723. if (wolfSSL_is_static_memory(ssl1, &ssl_stats) == 1) {
  80724. #if defined(DEBUG_WOLFSSL) && !defined(WOLFSSL_STATIC_MEMORY_LEAN)
  80725. wolfSSL_PrintStatsConn(&ssl_stats);
  80726. #endif
  80727. (void)ssl_stats;
  80728. }
  80729. /* display collected statistics */
  80730. if (wolfSSL_CTX_is_static_memory(ctx, &mem_stats) == 1) {
  80731. #if defined(DEBUG_WOLFSSL) && !defined(WOLFSSL_STATIC_MEMORY_LEAN)
  80732. wolfSSL_PrintStats(&mem_stats);
  80733. #endif
  80734. (void)mem_stats;
  80735. }
  80736. wolfSSL_free(ssl1);
  80737. wolfSSL_free(ssl2);
  80738. return EXPECT_RESULT();
  80739. }
  80740. #endif /* WOLFSSL_STATIC_MEMORY && !WOLFCRYPT_ONLY */
  80741. static int test_wolfSSL_CTX_StaticMemory(void)
  80742. {
  80743. EXPECT_DECLS;
  80744. #if defined(WOLFSSL_STATIC_MEMORY) && !defined(WOLFCRYPT_ONLY)
  80745. wolfSSL_method_func method_func;
  80746. WOLFSSL_CTX* ctx;
  80747. const int kMaxCtxClients = 2;
  80748. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  80749. #if !defined(NO_RSA) || defined(HAVE_ECC) || defined(HAVE_ED25519)
  80750. int tlsVer;
  80751. byte cliMem[TEST_TLS_STATIC_MEMSZ];
  80752. #endif
  80753. #endif
  80754. byte svrMem[TEST_TLS_STATIC_MEMSZ];
  80755. #ifndef NO_WOLFSSL_SERVER
  80756. #ifndef WOLFSSL_NO_TLS12
  80757. method_func = wolfTLSv1_2_server_method_ex;
  80758. #else
  80759. method_func = wolfTLSv1_3_server_method_ex;
  80760. #endif
  80761. #else
  80762. #ifndef WOLFSSL_NO_TLS12
  80763. method_func = wolfTLSv1_2_client_method_ex;
  80764. #else
  80765. method_func = wolfTLSv1_3_client_method_ex;
  80766. #endif
  80767. #endif
  80768. /* Test creating CTX directly from static memory pool */
  80769. ctx = NULL;
  80770. ExpectIntEQ(wolfSSL_CTX_load_static_memory(&ctx, method_func, svrMem,
  80771. sizeof(svrMem), 0, kMaxCtxClients), WOLFSSL_SUCCESS);
  80772. ExpectIntEQ(test_wolfSSL_CTX_StaticMemory_SSL(ctx), TEST_SUCCESS);
  80773. wolfSSL_CTX_free(ctx);
  80774. ctx = NULL;
  80775. /* Test for heap allocated CTX, then assigning static pool to it */
  80776. ExpectNotNull(ctx = wolfSSL_CTX_new(method_func(NULL)));
  80777. ExpectIntEQ(wolfSSL_CTX_load_static_memory(&ctx, NULL, svrMem,
  80778. sizeof(svrMem), 0, kMaxCtxClients), WOLFSSL_SUCCESS);
  80779. ExpectIntEQ(test_wolfSSL_CTX_StaticMemory_SSL(ctx), TEST_SUCCESS);
  80780. wolfSSL_CTX_free(ctx);
  80781. /* TLS Level Tests using static memory */
  80782. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  80783. #ifndef NO_RSA
  80784. for (tlsVer = WOLFSSL_SSLV3; tlsVer <= WOLFSSL_DTLSV1; tlsVer++) {
  80785. ExpectIntEQ(test_wolfSSL_CTX_StaticMemory_TLS(tlsVer,
  80786. svrCertFile, cliCertFile, cliKeyFile,
  80787. cliCertFile, svrCertFile, svrKeyFile,
  80788. cliMem, (word32)sizeof(cliMem), svrMem, (word32)sizeof(svrMem)),
  80789. TEST_SUCCESS);
  80790. }
  80791. #endif
  80792. #ifdef HAVE_ECC
  80793. for (tlsVer = WOLFSSL_TLSV1; tlsVer <= WOLFSSL_DTLSV1; tlsVer++) {
  80794. ExpectIntEQ(test_wolfSSL_CTX_StaticMemory_TLS(tlsVer,
  80795. caEccCertFile, cliEccCertFile, cliEccKeyFile,
  80796. cliEccCertFile, eccCertFile, eccKeyFile,
  80797. cliMem, (word32)sizeof(cliMem), svrMem, (word32)sizeof(svrMem)),
  80798. TEST_SUCCESS);
  80799. }
  80800. #endif
  80801. #ifdef HAVE_ED25519
  80802. for (tlsVer = WOLFSSL_TLSV1_2; tlsVer <= WOLFSSL_DTLSV1_2; tlsVer++) {
  80803. if (tlsVer == WOLFSSL_DTLSV1) continue;
  80804. ExpectIntEQ(test_wolfSSL_CTX_StaticMemory_TLS(tlsVer,
  80805. caEdCertFile, cliEdCertFile, cliEdKeyFile,
  80806. cliEdCertFile, edCertFile, edKeyFile,
  80807. cliMem, (word32)sizeof(cliMem), svrMem, (word32)sizeof(svrMem)),
  80808. TEST_SUCCESS);
  80809. }
  80810. #endif
  80811. #endif /* HAVE_IO_TESTS_DEPENDENCIES */
  80812. #endif /* WOLFSSL_STATIC_MEMORY && !WOLFCRYPT_ONLY */
  80813. return EXPECT_RESULT();
  80814. }
  80815. static int test_openssl_FIPS_drbg(void)
  80816. {
  80817. EXPECT_DECLS;
  80818. #if defined(OPENSSL_EXTRA) && !defined(WC_NO_RNG) && defined(HAVE_HASHDRBG)
  80819. DRBG_CTX* dctx = NULL;
  80820. byte data1[32], data2[32], zeroData[32];
  80821. byte testSeed[16];
  80822. size_t dlen = sizeof(data1);
  80823. int i;
  80824. XMEMSET(data1, 0, dlen);
  80825. XMEMSET(data2, 0, dlen);
  80826. XMEMSET(zeroData, 0, sizeof(zeroData));
  80827. for (i = 0; i < (int)sizeof(testSeed); i++) {
  80828. testSeed[i] = (byte)i;
  80829. }
  80830. ExpectNotNull(dctx = FIPS_get_default_drbg());
  80831. ExpectIntEQ(FIPS_drbg_init(dctx, 0, 0), WOLFSSL_SUCCESS);
  80832. ExpectIntEQ(FIPS_drbg_set_callbacks(dctx, NULL, NULL, 20, NULL, NULL),
  80833. WOLFSSL_SUCCESS);
  80834. ExpectIntEQ(FIPS_drbg_instantiate(dctx, NULL, 0), WOLFSSL_SUCCESS);
  80835. ExpectIntEQ(FIPS_drbg_generate(dctx, data1, dlen, 0, NULL, 0),
  80836. WOLFSSL_SUCCESS);
  80837. ExpectIntNE(XMEMCMP(data1, zeroData, dlen), 0);
  80838. ExpectIntEQ(FIPS_drbg_reseed(dctx, testSeed, sizeof(testSeed)),
  80839. WOLFSSL_SUCCESS);
  80840. ExpectIntEQ(FIPS_drbg_generate(dctx, data2, dlen, 0, NULL, 0),
  80841. WOLFSSL_SUCCESS);
  80842. ExpectIntNE(XMEMCMP(data1, zeroData, dlen), 0);
  80843. ExpectIntNE(XMEMCMP(data1, data2, dlen), 0);
  80844. ExpectIntEQ(FIPS_drbg_uninstantiate(dctx), WOLFSSL_SUCCESS);
  80845. #ifndef HAVE_GLOBAL_RNG
  80846. /* gets freed by wolfSSL_Cleanup() when HAVE_GLOBAL_RNG defined */
  80847. wolfSSL_FIPS_drbg_free(dctx);
  80848. #endif
  80849. #endif
  80850. return EXPECT_RESULT();
  80851. }
  80852. static int test_wolfSSL_FIPS_mode(void)
  80853. {
  80854. EXPECT_DECLS;
  80855. #if defined(OPENSSL_ALL)
  80856. #ifdef HAVE_FIPS
  80857. ExpectIntEQ(wolfSSL_FIPS_mode(), 1);
  80858. ExpectIntEQ(wolfSSL_FIPS_mode_set(0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80859. ExpectIntEQ(wolfSSL_FIPS_mode_set(1), WOLFSSL_SUCCESS);
  80860. #else
  80861. ExpectIntEQ(wolfSSL_FIPS_mode(), 0);
  80862. ExpectIntEQ(wolfSSL_FIPS_mode_set(0), WOLFSSL_SUCCESS);
  80863. ExpectIntEQ(wolfSSL_FIPS_mode_set(1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80864. #endif
  80865. #endif
  80866. return EXPECT_RESULT();
  80867. }
  80868. #ifdef WOLFSSL_DTLS
  80869. /* Prints out the current window */
  80870. static void DUW_TEST_print_window_binary(word32 h, word32 l, word32* w) {
  80871. #ifdef WOLFSSL_DEBUG_DTLS_WINDOW
  80872. int i;
  80873. for (i = WOLFSSL_DTLS_WINDOW_WORDS - 1; i >= 0; i--) {
  80874. word32 b = w[i];
  80875. int j;
  80876. /* Prints out a 32 bit binary number in big endian order */
  80877. for (j = 0; j < 32; j++, b <<= 1) {
  80878. if (b & (((word32)1) << 31))
  80879. fprintf(stderr, "1");
  80880. else
  80881. fprintf(stderr, "0");
  80882. }
  80883. fprintf(stderr, " ");
  80884. }
  80885. fprintf(stderr, "cur_hi %u cur_lo %u\n", h, l);
  80886. #else
  80887. (void)h;
  80888. (void)l;
  80889. (void)w;
  80890. #endif
  80891. }
  80892. /* a - cur_hi
  80893. * b - cur_lo
  80894. * c - next_hi
  80895. * d - next_lo
  80896. * e - window
  80897. * f - expected next_hi
  80898. * g - expected next_lo
  80899. * h - expected window[1]
  80900. * i - expected window[0]
  80901. */
  80902. #define DUW_TEST(a,b,c,d,e,f,g,h,i) do { \
  80903. ExpectIntEQ(wolfSSL_DtlsUpdateWindow((a), (b), &(c), &(d), (e)), 1); \
  80904. DUW_TEST_print_window_binary((a), (b), (e)); \
  80905. ExpectIntEQ((c), (f)); \
  80906. ExpectIntEQ((d), (g)); \
  80907. ExpectIntEQ((e)[1], (h)); \
  80908. ExpectIntEQ((e)[0], (i)); \
  80909. } while (0)
  80910. static int test_wolfSSL_DtlsUpdateWindow(void)
  80911. {
  80912. EXPECT_DECLS;
  80913. word32 window[WOLFSSL_DTLS_WINDOW_WORDS];
  80914. word32 next_lo = 0;
  80915. word16 next_hi = 0;
  80916. #ifdef WOLFSSL_DEBUG_DTLS_WINDOW
  80917. fprintf(stderr, "\n");
  80918. #endif
  80919. XMEMSET(window, 0, sizeof window);
  80920. DUW_TEST(0, 0, next_hi, next_lo, window, 0, 1, 0, 0x01);
  80921. DUW_TEST(0, 1, next_hi, next_lo, window, 0, 2, 0, 0x03);
  80922. DUW_TEST(0, 5, next_hi, next_lo, window, 0, 6, 0, 0x31);
  80923. DUW_TEST(0, 4, next_hi, next_lo, window, 0, 6, 0, 0x33);
  80924. DUW_TEST(0, 100, next_hi, next_lo, window, 0, 101, 0, 0x01);
  80925. DUW_TEST(0, 101, next_hi, next_lo, window, 0, 102, 0, 0x03);
  80926. DUW_TEST(0, 133, next_hi, next_lo, window, 0, 134, 0x03, 0x01);
  80927. DUW_TEST(0, 200, next_hi, next_lo, window, 0, 201, 0, 0x01);
  80928. DUW_TEST(0, 264, next_hi, next_lo, window, 0, 265, 0, 0x01);
  80929. DUW_TEST(0, 0xFFFFFFFF, next_hi, next_lo, window, 1, 0, 0, 0x01);
  80930. DUW_TEST(0, 0xFFFFFFFD, next_hi, next_lo, window, 1, 0, 0, 0x05);
  80931. DUW_TEST(0, 0xFFFFFFFE, next_hi, next_lo, window, 1, 0, 0, 0x07);
  80932. DUW_TEST(1, 3, next_hi, next_lo, window, 1, 4, 0, 0x71);
  80933. DUW_TEST(1, 0, next_hi, next_lo, window, 1, 4, 0, 0x79);
  80934. DUW_TEST(1, 0xFFFFFFFF, next_hi, next_lo, window, 2, 0, 0, 0x01);
  80935. DUW_TEST(2, 3, next_hi, next_lo, window, 2, 4, 0, 0x11);
  80936. DUW_TEST(2, 0, next_hi, next_lo, window, 2, 4, 0, 0x19);
  80937. DUW_TEST(2, 25, next_hi, next_lo, window, 2, 26, 0, 0x6400001);
  80938. DUW_TEST(2, 27, next_hi, next_lo, window, 2, 28, 0, 0x19000005);
  80939. DUW_TEST(2, 29, next_hi, next_lo, window, 2, 30, 0, 0x64000015);
  80940. DUW_TEST(2, 33, next_hi, next_lo, window, 2, 34, 6, 0x40000151);
  80941. DUW_TEST(2, 60, next_hi, next_lo, window, 2, 61, 0x3200000A, 0x88000001);
  80942. DUW_TEST(1, 0xFFFFFFF0, next_hi, next_lo, window, 2, 61, 0x3200000A, 0x88000001);
  80943. DUW_TEST(2, 0xFFFFFFFD, next_hi, next_lo, window, 2, 0xFFFFFFFE, 0, 0x01);
  80944. DUW_TEST(3, 1, next_hi, next_lo, window, 3, 2, 0, 0x11);
  80945. DUW_TEST(99, 66, next_hi, next_lo, window, 99, 67, 0, 0x01);
  80946. DUW_TEST(50, 66, next_hi, next_lo, window, 99, 67, 0, 0x01);
  80947. DUW_TEST(100, 68, next_hi, next_lo, window, 100, 69, 0, 0x01);
  80948. DUW_TEST(99, 50, next_hi, next_lo, window, 100, 69, 0, 0x01);
  80949. DUW_TEST(99, 0xFFFFFFFF, next_hi, next_lo, window, 100, 69, 0, 0x01);
  80950. DUW_TEST(150, 0xFFFFFFFF, next_hi, next_lo, window, 151, 0, 0, 0x01);
  80951. DUW_TEST(152, 0xFFFFFFFF, next_hi, next_lo, window, 153, 0, 0, 0x01);
  80952. return EXPECT_RESULT();
  80953. }
  80954. #endif /* WOLFSSL_DTLS */
  80955. #ifdef WOLFSSL_DTLS
  80956. static int DFB_TEST(WOLFSSL* ssl, word32 seq, word32 len, word32 f_offset,
  80957. word32 f_len, word32 f_count, byte ready, word32 bytesReceived)
  80958. {
  80959. DtlsMsg* cur;
  80960. static byte msg[100];
  80961. static byte msgInit = 0;
  80962. if (!msgInit) {
  80963. int i;
  80964. for (i = 0; i < 100; i++)
  80965. msg[i] = i + 1;
  80966. msgInit = 1;
  80967. }
  80968. /* Sanitize test parameters */
  80969. if (len > sizeof(msg))
  80970. return -1;
  80971. if (f_offset + f_len > sizeof(msg))
  80972. return -1;
  80973. DtlsMsgStore(ssl, 0, seq, msg + f_offset, len, certificate, f_offset, f_len, NULL);
  80974. if (ssl->dtls_rx_msg_list == NULL)
  80975. return -100;
  80976. if ((cur = DtlsMsgFind(ssl->dtls_rx_msg_list, 0, seq)) == NULL)
  80977. return -200;
  80978. if (cur->fragBucketListCount != f_count)
  80979. return -300;
  80980. if (cur->ready != ready)
  80981. return -400;
  80982. if (cur->bytesReceived != bytesReceived)
  80983. return -500;
  80984. if (ready) {
  80985. if (cur->fragBucketList != NULL)
  80986. return -600;
  80987. if (XMEMCMP(cur->fullMsg, msg, cur->sz) != 0)
  80988. return -700;
  80989. }
  80990. else {
  80991. DtlsFragBucket* fb;
  80992. if (cur->fragBucketList == NULL)
  80993. return -800;
  80994. for (fb = cur->fragBucketList; fb != NULL; fb = fb->m.m.next) {
  80995. if (XMEMCMP(fb->buf, msg + fb->m.m.offset, fb->m.m.sz) != 0)
  80996. return -900;
  80997. }
  80998. }
  80999. return 0;
  81000. }
  81001. static int test_wolfSSL_DTLS_fragment_buckets(void)
  81002. {
  81003. EXPECT_DECLS;
  81004. WOLFSSL ssl[1];
  81005. XMEMSET(ssl, 0, sizeof(*ssl));
  81006. ExpectIntEQ(DFB_TEST(ssl, 0, 100, 0, 100, 0, 1, 100), 0); /* 0-100 */
  81007. ExpectIntEQ(DFB_TEST(ssl, 1, 100, 0, 20, 1, 0, 20), 0); /* 0-20 */
  81008. ExpectIntEQ(DFB_TEST(ssl, 1, 100, 20, 20, 1, 0, 40), 0); /* 20-40 */
  81009. ExpectIntEQ(DFB_TEST(ssl, 1, 100, 40, 20, 1, 0, 60), 0); /* 40-60 */
  81010. ExpectIntEQ(DFB_TEST(ssl, 1, 100, 60, 20, 1, 0, 80), 0); /* 60-80 */
  81011. ExpectIntEQ(DFB_TEST(ssl, 1, 100, 80, 20, 0, 1, 100), 0); /* 80-100 */
  81012. /* Test all permutations of 3 regions */
  81013. /* 1 2 3 */
  81014. ExpectIntEQ(DFB_TEST(ssl, 2, 100, 0, 30, 1, 0, 30), 0); /* 0-30 */
  81015. ExpectIntEQ(DFB_TEST(ssl, 2, 100, 30, 30, 1, 0, 60), 0); /* 30-60 */
  81016. ExpectIntEQ(DFB_TEST(ssl, 2, 100, 60, 40, 0, 1, 100), 0); /* 60-100 */
  81017. /* 1 3 2 */
  81018. ExpectIntEQ(DFB_TEST(ssl, 3, 100, 0, 30, 1, 0, 30), 0); /* 0-30 */
  81019. ExpectIntEQ(DFB_TEST(ssl, 3, 100, 60, 40, 2, 0, 70), 0); /* 60-100 */
  81020. ExpectIntEQ(DFB_TEST(ssl, 3, 100, 30, 30, 0, 1, 100), 0); /* 30-60 */
  81021. /* 2 1 3 */
  81022. ExpectIntEQ(DFB_TEST(ssl, 4, 100, 30, 30, 1, 0, 30), 0); /* 30-60 */
  81023. ExpectIntEQ(DFB_TEST(ssl, 4, 100, 0, 30, 1, 0, 60), 0); /* 0-30 */
  81024. ExpectIntEQ(DFB_TEST(ssl, 4, 100, 60, 40, 0, 1, 100), 0); /* 60-100 */
  81025. /* 2 3 1 */
  81026. ExpectIntEQ(DFB_TEST(ssl, 5, 100, 30, 30, 1, 0, 30), 0); /* 30-60 */
  81027. ExpectIntEQ(DFB_TEST(ssl, 5, 100, 60, 40, 1, 0, 70), 0); /* 60-100 */
  81028. ExpectIntEQ(DFB_TEST(ssl, 5, 100, 0, 30, 0, 1, 100), 0); /* 0-30 */
  81029. /* 3 1 2 */
  81030. ExpectIntEQ(DFB_TEST(ssl, 6, 100, 60, 40, 1, 0, 40), 0); /* 60-100 */
  81031. ExpectIntEQ(DFB_TEST(ssl, 6, 100, 0, 30, 2, 0, 70), 0); /* 0-30 */
  81032. ExpectIntEQ(DFB_TEST(ssl, 6, 100, 30, 30, 0, 1, 100), 0); /* 30-60 */
  81033. /* 3 2 1 */
  81034. ExpectIntEQ(DFB_TEST(ssl, 7, 100, 60, 40, 1, 0, 40), 0); /* 60-100 */
  81035. ExpectIntEQ(DFB_TEST(ssl, 7, 100, 30, 30, 1, 0, 70), 0); /* 30-60 */
  81036. ExpectIntEQ(DFB_TEST(ssl, 7, 100, 0, 30, 0, 1, 100), 0); /* 0-30 */
  81037. /* Test overlapping regions */
  81038. ExpectIntEQ(DFB_TEST(ssl, 8, 100, 0, 30, 1, 0, 30), 0); /* 0-30 */
  81039. ExpectIntEQ(DFB_TEST(ssl, 8, 100, 20, 10, 1, 0, 30), 0); /* 20-30 */
  81040. ExpectIntEQ(DFB_TEST(ssl, 8, 100, 70, 10, 2, 0, 40), 0); /* 70-80 */
  81041. ExpectIntEQ(DFB_TEST(ssl, 8, 100, 20, 30, 2, 0, 60), 0); /* 20-50 */
  81042. ExpectIntEQ(DFB_TEST(ssl, 8, 100, 40, 60, 0, 1, 100), 0); /* 40-100 */
  81043. /* Test overlapping multiple regions */
  81044. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 0, 20, 1, 0, 20), 0); /* 0-20 */
  81045. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 30, 5, 2, 0, 25), 0); /* 30-35 */
  81046. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 40, 5, 3, 0, 30), 0); /* 40-45 */
  81047. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 50, 5, 4, 0, 35), 0); /* 50-55 */
  81048. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 60, 5, 5, 0, 40), 0); /* 60-65 */
  81049. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 70, 5, 6, 0, 45), 0); /* 70-75 */
  81050. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 30, 25, 4, 0, 55), 0); /* 30-55 */
  81051. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 55, 15, 2, 0, 65), 0); /* 55-70 */
  81052. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 75, 25, 2, 0, 90), 0); /* 75-100 */
  81053. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 10, 25, 0, 1, 100), 0); /* 10-35 */
  81054. ExpectIntEQ(DFB_TEST(ssl, 10, 100, 0, 20, 1, 0, 20), 0); /* 0-20 */
  81055. ExpectIntEQ(DFB_TEST(ssl, 10, 100, 30, 20, 2, 0, 40), 0); /* 30-50 */
  81056. ExpectIntEQ(DFB_TEST(ssl, 10, 100, 0, 40, 1, 0, 50), 0); /* 0-40 */
  81057. ExpectIntEQ(DFB_TEST(ssl, 10, 100, 50, 50, 0, 1, 100), 0); /* 10-35 */
  81058. DtlsMsgListDelete(ssl->dtls_rx_msg_list, ssl->heap);
  81059. ssl->dtls_rx_msg_list = NULL;
  81060. ssl->dtls_rx_msg_list_sz = 0;
  81061. return EXPECT_RESULT();
  81062. }
  81063. #endif
  81064. #if !defined(NO_FILESYSTEM) && \
  81065. defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  81066. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  81067. static int test_wolfSSL_dtls_stateless2(void)
  81068. {
  81069. EXPECT_DECLS;
  81070. WOLFSSL *ssl_c = NULL;
  81071. WOLFSSL *ssl_c2 = NULL;
  81072. WOLFSSL *ssl_s = NULL;
  81073. struct test_memio_ctx test_ctx;
  81074. WOLFSSL_CTX *ctx_c = NULL;
  81075. WOLFSSL_CTX *ctx_s = NULL;
  81076. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81077. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  81078. wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  81079. ExpectNotNull(ssl_c2 = wolfSSL_new(ctx_c));
  81080. wolfSSL_SetIOWriteCtx(ssl_c2, &test_ctx);
  81081. wolfSSL_SetIOReadCtx(ssl_c2, &test_ctx);
  81082. /* send CH */
  81083. ExpectTrue((wolfSSL_connect(ssl_c2) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81084. (ssl_c2->error == WC_NO_ERR_TRACE(WANT_READ)));
  81085. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81086. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  81087. ExpectIntNE(test_ctx.c_len, 0);
  81088. /* consume HRR */
  81089. test_ctx.c_len = 0;
  81090. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  81091. wolfSSL_free(ssl_c2);
  81092. wolfSSL_free(ssl_c);
  81093. wolfSSL_free(ssl_s);
  81094. wolfSSL_CTX_free(ctx_c);
  81095. wolfSSL_CTX_free(ctx_s);
  81096. return EXPECT_RESULT();
  81097. }
  81098. #ifdef HAVE_MAX_FRAGMENT
  81099. static int test_wolfSSL_dtls_stateless_maxfrag(void)
  81100. {
  81101. EXPECT_DECLS;
  81102. WOLFSSL *ssl_c = NULL;
  81103. WOLFSSL *ssl_c2 = NULL;
  81104. WOLFSSL *ssl_s = NULL;
  81105. struct test_memio_ctx test_ctx;
  81106. WOLFSSL_CTX *ctx_c = NULL;
  81107. WOLFSSL_CTX *ctx_s = NULL;
  81108. word16 max_fragment = 0;
  81109. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81110. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  81111. wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  81112. ExpectNotNull(ssl_c2 = wolfSSL_new(ctx_c));
  81113. ExpectIntEQ(wolfSSL_UseMaxFragment(ssl_c2, WOLFSSL_MFL_2_8),
  81114. WOLFSSL_SUCCESS);
  81115. wolfSSL_SetIOWriteCtx(ssl_c2, &test_ctx);
  81116. wolfSSL_SetIOReadCtx(ssl_c2, &test_ctx);
  81117. if (ssl_s != NULL) {
  81118. max_fragment = ssl_s->max_fragment;
  81119. }
  81120. /* send CH */
  81121. ExpectTrue((wolfSSL_connect(ssl_c2) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81122. (ssl_c2->error == WC_NO_ERR_TRACE(WANT_READ)));
  81123. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81124. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  81125. /* CH without cookie shouldn't change state */
  81126. ExpectIntEQ(ssl_s->max_fragment, max_fragment);
  81127. ExpectIntNE(test_ctx.c_len, 0);
  81128. /* consume HRR from buffer */
  81129. test_ctx.c_len = 0;
  81130. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  81131. wolfSSL_free(ssl_c2);
  81132. wolfSSL_free(ssl_c);
  81133. wolfSSL_free(ssl_s);
  81134. wolfSSL_CTX_free(ctx_c);
  81135. wolfSSL_CTX_free(ctx_s);
  81136. return EXPECT_RESULT();
  81137. }
  81138. #endif /* HAVE_MAX_FRAGMENT */
  81139. #if defined(WOLFSSL_DTLS_NO_HVR_ON_RESUME)
  81140. #define ROUNDS_WITH_HVR 4
  81141. #define ROUNDS_WITHOUT_HVR 2
  81142. #define HANDSHAKE_TYPE_OFFSET DTLS_RECORD_HEADER_SZ
  81143. static int buf_is_hvr(const byte *data, int len)
  81144. {
  81145. if (len < DTLS_RECORD_HEADER_SZ + DTLS_HANDSHAKE_HEADER_SZ)
  81146. return 0;
  81147. return data[HANDSHAKE_TYPE_OFFSET] == hello_verify_request;
  81148. }
  81149. static int _test_wolfSSL_dtls_stateless_resume(byte useticket, byte bad)
  81150. {
  81151. EXPECT_DECLS;
  81152. struct test_memio_ctx test_ctx;
  81153. WOLFSSL_CTX *ctx_c = NULL;
  81154. WOLFSSL_CTX *ctx_s = NULL;
  81155. WOLFSSL *ssl_c = NULL;
  81156. WOLFSSL *ssl_s = NULL;
  81157. WOLFSSL_SESSION *sess = NULL;
  81158. int round_trips;
  81159. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81160. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c,
  81161. &ssl_s, wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  81162. #ifdef HAVE_SESSION_TICKET
  81163. if (useticket) {
  81164. ExpectIntEQ(wolfSSL_UseSessionTicket(ssl_c), WOLFSSL_SUCCESS);
  81165. }
  81166. #endif
  81167. round_trips = ROUNDS_WITH_HVR;
  81168. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, round_trips,
  81169. &round_trips), 0);
  81170. ExpectIntEQ(round_trips, ROUNDS_WITH_HVR);
  81171. ExpectNotNull(sess = wolfSSL_get1_session(ssl_c));
  81172. wolfSSL_shutdown(ssl_c);
  81173. wolfSSL_shutdown(ssl_s);
  81174. wolfSSL_free(ssl_c);
  81175. ssl_c = NULL;
  81176. wolfSSL_free(ssl_s);
  81177. ssl_s = NULL;
  81178. test_ctx.c_len = test_ctx.s_len = 0;
  81179. /* make resumption invalid */
  81180. if (bad && (sess != NULL)) {
  81181. if (useticket) {
  81182. #ifdef HAVE_SESSION_TICKET
  81183. if (sess->ticket != NULL) {
  81184. sess->ticket[0] = !sess->ticket[0];
  81185. }
  81186. #endif /* HAVE_SESSION_TICKET */
  81187. }
  81188. else {
  81189. sess->sessionID[0] = !sess->sessionID[0];
  81190. }
  81191. }
  81192. ExpectNotNull(ssl_c = wolfSSL_new(ctx_c));
  81193. ExpectNotNull(ssl_s = wolfSSL_new(ctx_s));
  81194. wolfSSL_SetIOWriteCtx(ssl_c, &test_ctx);
  81195. wolfSSL_SetIOReadCtx(ssl_c, &test_ctx);
  81196. wolfSSL_SetIOWriteCtx(ssl_s, &test_ctx);
  81197. wolfSSL_SetIOReadCtx(ssl_s, &test_ctx);
  81198. ExpectIntEQ(wolfSSL_set_session(ssl_c, sess), WOLFSSL_SUCCESS);
  81199. ExpectTrue((wolfSSL_connect(ssl_c) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81200. (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ)));
  81201. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81202. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  81203. ExpectFalse(bad && !buf_is_hvr(test_ctx.c_buff, test_ctx.c_len));
  81204. ExpectFalse(!bad && buf_is_hvr(test_ctx.c_buff, test_ctx.c_len));
  81205. if (!useticket) {
  81206. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, &round_trips), 0);
  81207. ExpectFalse(bad && round_trips != ROUNDS_WITH_HVR - 1);
  81208. ExpectFalse(!bad && round_trips != ROUNDS_WITHOUT_HVR - 1);
  81209. }
  81210. wolfSSL_SESSION_free(sess);
  81211. wolfSSL_free(ssl_c);
  81212. wolfSSL_free(ssl_s);
  81213. wolfSSL_CTX_free(ctx_c);
  81214. wolfSSL_CTX_free(ctx_s);
  81215. return EXPECT_RESULT();
  81216. }
  81217. static int test_wolfSSL_dtls_stateless_resume(void)
  81218. {
  81219. EXPECT_DECLS;
  81220. #ifdef HAVE_SESSION_TICKET
  81221. ExpectIntEQ(_test_wolfSSL_dtls_stateless_resume(1, 0), TEST_SUCCESS);
  81222. ExpectIntEQ(_test_wolfSSL_dtls_stateless_resume(1, 1), TEST_SUCCESS);
  81223. #endif /* HAVE_SESION_TICKET */
  81224. ExpectIntEQ(_test_wolfSSL_dtls_stateless_resume(0, 0), TEST_SUCCESS);
  81225. ExpectIntEQ(_test_wolfSSL_dtls_stateless_resume(0, 1), TEST_SUCCESS);
  81226. return EXPECT_RESULT();
  81227. }
  81228. #endif /* WOLFSSL_DTLS_NO_HVR_ON_RESUME */
  81229. #if !defined(NO_OLD_TLS)
  81230. static int test_wolfSSL_dtls_stateless_downgrade(void)
  81231. {
  81232. EXPECT_DECLS;
  81233. WOLFSSL_CTX *ctx_c = NULL;
  81234. WOLFSSL_CTX *ctx_c2 = NULL;
  81235. WOLFSSL_CTX *ctx_s = NULL;
  81236. WOLFSSL *ssl_c = NULL;
  81237. WOLFSSL *ssl_c2 = NULL;
  81238. WOLFSSL *ssl_s = NULL;
  81239. struct test_memio_ctx test_ctx;
  81240. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81241. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  81242. wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  81243. ExpectIntEQ(wolfSSL_CTX_SetMinVersion(ctx_s, WOLFSSL_DTLSV1),
  81244. WOLFSSL_SUCCESS);
  81245. ExpectNotNull(ctx_c2 = wolfSSL_CTX_new(wolfDTLSv1_client_method()));
  81246. wolfSSL_SetIORecv(ctx_c2, test_memio_read_cb);
  81247. wolfSSL_SetIOSend(ctx_c2, test_memio_write_cb);
  81248. ExpectNotNull(ssl_c2 = wolfSSL_new(ctx_c2));
  81249. wolfSSL_SetIOWriteCtx(ssl_c2, &test_ctx);
  81250. wolfSSL_SetIOReadCtx(ssl_c2, &test_ctx);
  81251. /* send CH */
  81252. ExpectTrue((wolfSSL_connect(ssl_c2) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81253. (ssl_c2->error == WC_NO_ERR_TRACE(WANT_READ)));
  81254. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81255. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  81256. ExpectIntNE(test_ctx.c_len, 0);
  81257. /* consume HRR */
  81258. test_ctx.c_len = 0;
  81259. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  81260. wolfSSL_free(ssl_c2);
  81261. wolfSSL_free(ssl_c);
  81262. wolfSSL_free(ssl_s);
  81263. wolfSSL_CTX_free(ctx_c);
  81264. wolfSSL_CTX_free(ctx_c2);
  81265. wolfSSL_CTX_free(ctx_s);
  81266. return EXPECT_RESULT();
  81267. }
  81268. #endif /* !defined(NO_OLD_TLS) */
  81269. #endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  81270. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)*/
  81271. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  81272. !defined(NO_OLD_TLS) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  81273. static int test_WOLFSSL_dtls_version_alert(void)
  81274. {
  81275. EXPECT_DECLS;
  81276. struct test_memio_ctx test_ctx;
  81277. WOLFSSL_CTX *ctx_c = NULL;
  81278. WOLFSSL_CTX *ctx_s = NULL;
  81279. WOLFSSL *ssl_c = NULL;
  81280. WOLFSSL *ssl_s = NULL;
  81281. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81282. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  81283. wolfDTLSv1_2_client_method, wolfDTLSv1_server_method), 0);
  81284. /* client hello */
  81285. ExpectTrue((wolfSSL_connect(ssl_c) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81286. (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ)));
  81287. /* hrr */
  81288. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81289. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  81290. /* client hello 1 */
  81291. ExpectTrue((wolfSSL_connect(ssl_c) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81292. (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ)));
  81293. /* server hello */
  81294. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81295. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  81296. /* should fail */
  81297. ExpectTrue((wolfSSL_connect(ssl_c) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81298. (ssl_c->error == WC_NO_ERR_TRACE(VERSION_ERROR)));
  81299. /* shuould fail */
  81300. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81301. (ssl_s->error == WC_NO_ERR_TRACE(VERSION_ERROR) || ssl_s->error == WC_NO_ERR_TRACE(FATAL_ERROR)));
  81302. wolfSSL_free(ssl_c);
  81303. wolfSSL_free(ssl_s);
  81304. wolfSSL_CTX_free(ctx_c);
  81305. wolfSSL_CTX_free(ctx_s);
  81306. return EXPECT_RESULT();
  81307. }
  81308. #else
  81309. static int test_WOLFSSL_dtls_version_alert(void)
  81310. {
  81311. return TEST_SKIPPED;
  81312. }
  81313. #endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) &&
  81314. * !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) &&
  81315. * !defined(NO_OLD_TLS) && !defined(NO_RSA)
  81316. */
  81317. #if defined(WOLFSSL_TICKET_NONCE_MALLOC) && defined(HAVE_SESSION_TICKET) \
  81318. && defined(WOLFSSL_TLS13) && \
  81319. (!defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))\
  81320. && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  81321. static int send_new_session_ticket(WOLFSSL *ssl, byte nonceLength, byte filler)
  81322. {
  81323. struct test_memio_ctx *test_ctx;
  81324. byte buf[2048];
  81325. int idx, sz;
  81326. word32 tmp;
  81327. int ret;
  81328. idx = 5; /* space for record header */
  81329. buf[idx] = session_ticket; /* type */
  81330. idx++;
  81331. tmp = OPAQUE32_LEN +
  81332. OPAQUE32_LEN +
  81333. OPAQUE8_LEN + nonceLength +
  81334. OPAQUE16_LEN + OPAQUE8_LEN + OPAQUE16_LEN;
  81335. c32to24(tmp, buf + idx);
  81336. idx += OPAQUE24_LEN;
  81337. c32toa((word32)12345, buf+idx); /* lifetime */
  81338. idx += OPAQUE32_LEN;
  81339. c32toa((word32)12345, buf+idx); /* add */
  81340. idx += OPAQUE32_LEN;
  81341. buf[idx] = nonceLength; /* nonce length */
  81342. idx++;
  81343. XMEMSET(&buf[idx], filler, nonceLength); /* nonce */
  81344. idx += nonceLength;
  81345. tmp = 1; /* ticket len */
  81346. c16toa((word16)tmp, buf+idx);
  81347. idx += 2;
  81348. buf[idx] = 0xFF; /* ticket */
  81349. idx++;
  81350. tmp = 0; /* ext len */
  81351. c16toa((word16)tmp, buf+idx);
  81352. idx += 2;
  81353. sz = BuildTls13Message(ssl, buf, 2048, buf+5, idx - 5,
  81354. handshake, 0, 0, 0);
  81355. AssertIntGT(sz, 0);
  81356. test_ctx = (struct test_memio_ctx*)wolfSSL_GetIOWriteCtx(ssl);
  81357. AssertNotNull(test_ctx);
  81358. ret = test_memio_write_cb(ssl, (char*)buf, sz, test_ctx);
  81359. return !(ret == sz);
  81360. }
  81361. static int test_ticket_nonce_check(WOLFSSL_SESSION *sess, byte len)
  81362. {
  81363. int ret = 0;
  81364. if ((sess == NULL) || (sess->ticketNonce.len != len)) {
  81365. ret = -1;
  81366. }
  81367. else {
  81368. int i;
  81369. for (i = 0; i < len; i++) {
  81370. if (sess->ticketNonce.data[i] != len) {
  81371. ret = -1;
  81372. break;
  81373. }
  81374. }
  81375. }
  81376. return ret;
  81377. }
  81378. static int test_ticket_nonce_malloc_do(WOLFSSL *ssl_s, WOLFSSL *ssl_c, byte len)
  81379. {
  81380. EXPECT_DECLS;
  81381. char *buf[1024];
  81382. ExpectIntEQ(send_new_session_ticket(ssl_s, len, len), 0);
  81383. ExpectTrue((wolfSSL_recv(ssl_c, buf, 1024, 0) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  81384. (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ)));
  81385. ExpectIntEQ(test_ticket_nonce_check(ssl_c->session, len), 0);
  81386. return EXPECT_RESULT();
  81387. }
  81388. static int test_ticket_nonce_cache(WOLFSSL *ssl_s, WOLFSSL *ssl_c, byte len)
  81389. {
  81390. EXPECT_DECLS;
  81391. WOLFSSL_SESSION *sess = NULL;
  81392. WOLFSSL_SESSION *cached = NULL;
  81393. WOLFSSL_CTX *ctx = ssl_c->ctx;
  81394. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, len), TEST_SUCCESS);
  81395. ExpectNotNull(sess = wolfSSL_get1_session(ssl_c));
  81396. ExpectIntEQ(AddSessionToCache(ctx, sess, sess->sessionID, sess->sessionIDSz,
  81397. NULL, ssl_c->options.side, 1,NULL), 0);
  81398. ExpectNotNull(cached = wolfSSL_SESSION_new());
  81399. ExpectIntEQ(wolfSSL_GetSessionFromCache(ssl_c, cached), WOLFSSL_SUCCESS);
  81400. ExpectIntEQ(test_ticket_nonce_check(cached, len), 0);
  81401. wolfSSL_SESSION_free(cached);
  81402. wolfSSL_SESSION_free(sess);
  81403. return EXPECT_RESULT();
  81404. }
  81405. static int test_ticket_nonce_malloc(void)
  81406. {
  81407. EXPECT_DECLS;
  81408. struct test_memio_ctx test_ctx;
  81409. WOLFSSL_CTX *ctx_c = NULL;
  81410. WOLFSSL_CTX *ctx_s = NULL;
  81411. WOLFSSL *ssl_c = NULL;
  81412. WOLFSSL *ssl_s = NULL;
  81413. byte small;
  81414. byte medium;
  81415. byte big;
  81416. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81417. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  81418. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  81419. /* will send ticket manually */
  81420. ExpectIntEQ(wolfSSL_no_ticket_TLSv13(ssl_s), 0);
  81421. wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_NONE, 0);
  81422. wolfSSL_set_verify(ssl_c, WOLFSSL_VERIFY_NONE, 0);
  81423. while (EXPECT_SUCCESS() && (ssl_c->options.handShakeDone == 0) &&
  81424. (ssl_s->options.handShakeDone == 0)) {
  81425. ExpectTrue((wolfSSL_connect(ssl_c) == WOLFSSL_SUCCESS) ||
  81426. (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ)));
  81427. ExpectTrue((wolfSSL_accept(ssl_s) == WOLFSSL_SUCCESS) ||
  81428. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  81429. }
  81430. small = TLS13_TICKET_NONCE_STATIC_SZ;
  81431. #if TLS13_TICKET_NONCE_STATIC_SZ + 20 <= 255
  81432. medium = small + 20;
  81433. #else
  81434. medium = 255;
  81435. #endif
  81436. #if TLS13_TICKET_NONCE_STATIC_SZ + 20 + 20 <= 255
  81437. big = small + 20;
  81438. #else
  81439. big = 255;
  81440. #endif
  81441. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, small), TEST_SUCCESS);
  81442. ExpectPtrEq(ssl_c->session->ticketNonce.data,
  81443. ssl_c->session->ticketNonce.dataStatic);
  81444. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, medium),
  81445. TEST_SUCCESS);
  81446. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, big), TEST_SUCCESS);
  81447. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, medium),
  81448. TEST_SUCCESS);
  81449. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, small), TEST_SUCCESS);
  81450. ExpectIntEQ(test_ticket_nonce_cache(ssl_s, ssl_c, small), TEST_SUCCESS);
  81451. ExpectIntEQ(test_ticket_nonce_cache(ssl_s, ssl_c, medium), TEST_SUCCESS);
  81452. ExpectIntEQ(test_ticket_nonce_cache(ssl_s, ssl_c, big), TEST_SUCCESS);
  81453. ExpectIntEQ(test_ticket_nonce_cache(ssl_s, ssl_c, medium), TEST_SUCCESS);
  81454. ExpectIntEQ(test_ticket_nonce_cache(ssl_s, ssl_c, small), TEST_SUCCESS);
  81455. wolfSSL_free(ssl_c);
  81456. wolfSSL_free(ssl_s);
  81457. wolfSSL_CTX_free(ctx_c);
  81458. wolfSSL_CTX_free(ctx_s);
  81459. return EXPECT_RESULT();
  81460. }
  81461. #endif /* WOLFSSL_TICKET_NONCE_MALLOC */
  81462. #if defined(HAVE_SESSION_TICKET) && !defined(WOLFSSL_NO_TLS12) && \
  81463. !defined(WOLFSSL_TICKET_DECRYPT_NO_CREATE) && \
  81464. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  81465. !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && !defined(NO_RSA) && \
  81466. defined(HAVE_ECC) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  81467. static int test_ticket_ret_create(void)
  81468. {
  81469. EXPECT_DECLS;
  81470. WOLFSSL_CTX *ctx_c = NULL;
  81471. WOLFSSL_CTX *ctx_s = NULL;
  81472. WOLFSSL *ssl_c = NULL;
  81473. WOLFSSL *ssl_s = NULL;
  81474. byte ticket[SESSION_TICKET_LEN];
  81475. struct test_memio_ctx test_ctx;
  81476. WOLFSSL_SESSION *sess = NULL;
  81477. word16 ticketLen = 0;
  81478. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81479. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  81480. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  81481. wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_NONE, 0);
  81482. wolfSSL_set_verify(ssl_c, WOLFSSL_VERIFY_NONE, 0);
  81483. ExpectIntEQ(wolfSSL_CTX_UseSessionTicket(ctx_c), WOLFSSL_SUCCESS);
  81484. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  81485. ExpectNotNull(sess = wolfSSL_get1_session(ssl_c));
  81486. ExpectIntLE(sess->ticketLen, SESSION_TICKET_LEN);
  81487. if (sess != NULL) {
  81488. ticketLen = sess->ticketLen;
  81489. XMEMCPY(ticket, sess->ticket, sess->ticketLen);
  81490. }
  81491. wolfSSL_free(ssl_c);
  81492. ssl_c = NULL;
  81493. wolfSSL_free(ssl_s);
  81494. ssl_s = NULL;
  81495. ExpectNotNull(ssl_s = wolfSSL_new(ctx_s));
  81496. wolfSSL_SetIOWriteCtx(ssl_s, &test_ctx);
  81497. wolfSSL_SetIOReadCtx(ssl_s, &test_ctx);
  81498. ExpectNotNull(ssl_c = wolfSSL_new(ctx_c));
  81499. wolfSSL_SetIOWriteCtx(ssl_c, &test_ctx);
  81500. wolfSSL_SetIOReadCtx(ssl_c, &test_ctx);
  81501. ExpectIntEQ(wolfSSL_set_session(ssl_c, sess), WOLFSSL_SUCCESS);
  81502. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  81503. ExpectIntLE(ssl_c->session->ticketLen, SESSION_TICKET_LEN);
  81504. ExpectIntEQ(ssl_c->session->ticketLen, ticketLen);
  81505. ExpectTrue(XMEMCMP(ssl_c->session->ticket, ticket, ticketLen) != 0);
  81506. wolfSSL_SESSION_free(sess);
  81507. wolfSSL_free(ssl_c);
  81508. wolfSSL_free(ssl_s);
  81509. wolfSSL_CTX_free(ctx_c);
  81510. wolfSSL_CTX_free(ctx_s);
  81511. return EXPECT_RESULT();
  81512. }
  81513. #else
  81514. static int test_ticket_ret_create(void)
  81515. {
  81516. return TEST_SKIPPED;
  81517. }
  81518. #endif
  81519. #if defined(WOLFSSL_TLS13) && !defined(NO_PSK) && \
  81520. defined(HAVE_SESSION_TICKET) && defined(OPENSSL_EXTRA) && \
  81521. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_AESGCM) && \
  81522. !defined(NO_SHA256) && defined(WOLFSSL_AES_128) && \
  81523. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  81524. static void test_ticket_and_psk_mixing_on_result(WOLFSSL* ssl)
  81525. {
  81526. int ret;
  81527. WOLFSSL_SESSION* session = NULL;
  81528. AssertIntEQ(wolfSSL_get_current_cipher_suite(ssl), 0x1301);
  81529. if (!wolfSSL_is_server(ssl)) {
  81530. session = wolfSSL_SESSION_dup(wolfSSL_get_session(ssl));
  81531. AssertNotNull(session);
  81532. }
  81533. do {
  81534. ret = wolfSSL_shutdown(ssl);
  81535. } while (ret == WOLFSSL_SHUTDOWN_NOT_DONE);
  81536. AssertIntEQ(wolfSSL_clear(ssl), WOLFSSL_SUCCESS);
  81537. wolfSSL_set_psk_callback_ctx(ssl, (void*)"TLS13-AES256-GCM-SHA384");
  81538. #ifndef OPENSSL_COMPATIBLE_DEFAULTS
  81539. /* OpenSSL considers PSK to be verified. We error out with NO_PEER_CERT. */
  81540. wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_NONE, NULL);
  81541. #endif
  81542. if (!wolfSSL_is_server(ssl)) {
  81543. /* client */
  81544. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384:"
  81545. "TLS13-AES128-GCM-SHA256"), WOLFSSL_SUCCESS);
  81546. wolfSSL_set_session(ssl, session);
  81547. wolfSSL_SESSION_free(session);
  81548. wolfSSL_set_psk_client_tls13_callback(ssl, my_psk_client_tls13_cb);
  81549. AssertIntEQ(wolfSSL_connect(ssl), WOLFSSL_SUCCESS);
  81550. }
  81551. else {
  81552. /* server */
  81553. /* Different ciphersuite so that the ticket will be invalidated based on
  81554. * the ciphersuite */
  81555. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384"),
  81556. WOLFSSL_SUCCESS);
  81557. wolfSSL_set_psk_server_tls13_callback(ssl, my_psk_server_tls13_cb);
  81558. AssertIntEQ(wolfSSL_accept(ssl), WOLFSSL_SUCCESS);
  81559. }
  81560. }
  81561. static void test_ticket_and_psk_mixing_ssl_ready(WOLFSSL* ssl)
  81562. {
  81563. AssertIntEQ(wolfSSL_UseSessionTicket(ssl), WOLFSSL_SUCCESS);
  81564. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES128-GCM-SHA256"),
  81565. WOLFSSL_SUCCESS);
  81566. }
  81567. static int test_ticket_and_psk_mixing(void)
  81568. {
  81569. EXPECT_DECLS;
  81570. /* Test mixing tickets and regular PSK */
  81571. callback_functions client_cbs, server_cbs;
  81572. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  81573. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  81574. client_cbs.method = wolfTLSv1_3_client_method;
  81575. server_cbs.method = wolfTLSv1_3_server_method;
  81576. client_cbs.ssl_ready = test_ticket_and_psk_mixing_ssl_ready;
  81577. client_cbs.on_result = test_ticket_and_psk_mixing_on_result;
  81578. server_cbs.on_result = test_ticket_and_psk_mixing_on_result;
  81579. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  81580. ExpectIntEQ(client_cbs.return_code, TEST_SUCCESS);
  81581. ExpectIntEQ(server_cbs.return_code, TEST_SUCCESS);
  81582. return EXPECT_RESULT();
  81583. }
  81584. #else
  81585. static int test_ticket_and_psk_mixing(void)
  81586. {
  81587. return TEST_SKIPPED;
  81588. }
  81589. #endif
  81590. #if defined(WOLFSSL_TLS13) && !defined(NO_PSK) && defined(HAVE_SESSION_TICKET) \
  81591. && defined(OPENSSL_EXTRA) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  81592. defined(HAVE_AESGCM) && !defined(NO_SHA256) && defined(WOLFSSL_AES_128) && \
  81593. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  81594. static int test_prioritize_psk_cb_called = FALSE;
  81595. static unsigned int test_prioritize_psk_cb(WOLFSSL* ssl,
  81596. const char* identity, unsigned char* key, unsigned int key_max_len,
  81597. const char** ciphersuite)
  81598. {
  81599. test_prioritize_psk_cb_called = TRUE;
  81600. return my_psk_server_tls13_cb(ssl, identity, key, key_max_len, ciphersuite);
  81601. }
  81602. static void test_prioritize_psk_on_result(WOLFSSL* ssl)
  81603. {
  81604. int ret;
  81605. WOLFSSL_SESSION* session = NULL;
  81606. AssertIntEQ(wolfSSL_get_current_cipher_suite(ssl), 0x1301);
  81607. if (!wolfSSL_is_server(ssl)) {
  81608. session = wolfSSL_SESSION_dup(wolfSSL_get_session(ssl));
  81609. AssertNotNull(session);
  81610. }
  81611. do {
  81612. ret = wolfSSL_shutdown(ssl);
  81613. } while (ret == WOLFSSL_SHUTDOWN_NOT_DONE);
  81614. AssertIntEQ(wolfSSL_clear(ssl), WOLFSSL_SUCCESS);
  81615. wolfSSL_set_psk_callback_ctx(ssl, (void*)"TLS13-AES256-GCM-SHA384");
  81616. /* Previous connection was made with TLS13-AES128-GCM-SHA256. Order is
  81617. * important. */
  81618. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384:"
  81619. "TLS13-AES128-GCM-SHA256"), WOLFSSL_SUCCESS);
  81620. #ifndef OPENSSL_COMPATIBLE_DEFAULTS
  81621. /* OpenSSL considers PSK to be verified. We error out with NO_PEER_CERT. */
  81622. wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_NONE, NULL);
  81623. #endif
  81624. if (!wolfSSL_is_server(ssl)) {
  81625. /* client */
  81626. wolfSSL_set_psk_client_tls13_callback(ssl, my_psk_client_tls13_cb);
  81627. wolfSSL_set_session(ssl, session);
  81628. wolfSSL_SESSION_free(session);
  81629. AssertIntEQ(wolfSSL_connect(ssl), WOLFSSL_SUCCESS);
  81630. }
  81631. else {
  81632. /* server */
  81633. wolfSSL_set_psk_server_tls13_callback(ssl, test_prioritize_psk_cb);
  81634. AssertIntEQ(wolfSSL_accept(ssl), WOLFSSL_SUCCESS);
  81635. #ifdef WOLFSSL_PRIORITIZE_PSK
  81636. /* The ticket should be first tried with all ciphersuites and chosen */
  81637. AssertFalse(test_prioritize_psk_cb_called);
  81638. #else
  81639. /* Ciphersuites should be tried with each PSK. This triggers the PSK
  81640. * callback that sets this var. */
  81641. AssertTrue(test_prioritize_psk_cb_called);
  81642. #endif
  81643. }
  81644. }
  81645. static void test_prioritize_psk_ssl_ready(WOLFSSL* ssl)
  81646. {
  81647. if (!wolfSSL_is_server(ssl))
  81648. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES128-GCM-SHA256"),
  81649. WOLFSSL_SUCCESS);
  81650. else
  81651. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384:"
  81652. "TLS13-AES128-GCM-SHA256"), WOLFSSL_SUCCESS);
  81653. }
  81654. static int test_prioritize_psk(void)
  81655. {
  81656. EXPECT_DECLS;
  81657. /* We always send the ticket first. With WOLFSSL_PRIORITIZE_PSK the order
  81658. * of the PSK's will be followed instead of the ciphersuite. */
  81659. callback_functions client_cbs, server_cbs;
  81660. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  81661. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  81662. client_cbs.method = wolfTLSv1_3_client_method;
  81663. server_cbs.method = wolfTLSv1_3_server_method;
  81664. client_cbs.ssl_ready = test_prioritize_psk_ssl_ready;
  81665. server_cbs.ssl_ready = test_prioritize_psk_ssl_ready;
  81666. client_cbs.on_result = test_prioritize_psk_on_result;
  81667. server_cbs.on_result = test_prioritize_psk_on_result;
  81668. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  81669. ExpectIntEQ(client_cbs.return_code, TEST_SUCCESS);
  81670. ExpectIntEQ(server_cbs.return_code, TEST_SUCCESS);
  81671. return EXPECT_RESULT();
  81672. }
  81673. #else
  81674. static int test_prioritize_psk(void)
  81675. {
  81676. return TEST_SKIPPED;
  81677. }
  81678. #endif
  81679. #if defined(WOLFSSL_TLS13) && defined(OPENSSL_EXTRA) && \
  81680. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_AESGCM) && \
  81681. !defined(NO_SHA256) && defined(WOLFSSL_AES_128) && \
  81682. !defined(WOLFSSL_NO_TLS12)
  81683. static int test_wolfSSL_CTX_set_ciphersuites_ctx_ready_server(WOLFSSL_CTX* ctx)
  81684. {
  81685. EXPECT_DECLS;
  81686. ExpectTrue(SSL_CTX_set_cipher_list(ctx, "DEFAULT"));
  81687. /* Set TLS 1.3 specific suite */
  81688. ExpectTrue(SSL_CTX_set_ciphersuites(ctx, "TLS13-AES128-GCM-SHA256"));
  81689. return EXPECT_RESULT();
  81690. }
  81691. static int test_wolfSSL_CTX_set_ciphersuites(void)
  81692. {
  81693. EXPECT_DECLS;
  81694. /* Test using SSL_CTX_set_cipher_list and SSL_CTX_set_ciphersuites and then
  81695. * do a 1.2 connection. */
  81696. test_ssl_cbf client_cbs, server_cbs;
  81697. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  81698. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  81699. client_cbs.method = wolfTLSv1_2_client_method;
  81700. server_cbs.method = wolfTLS_server_method; /* Allow downgrade */
  81701. server_cbs.ctx_ready = test_wolfSSL_CTX_set_ciphersuites_ctx_ready_server;
  81702. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  81703. &server_cbs, NULL), TEST_SUCCESS);
  81704. return EXPECT_RESULT();
  81705. }
  81706. #else
  81707. static int test_wolfSSL_CTX_set_ciphersuites(void)
  81708. {
  81709. return TEST_SKIPPED;
  81710. }
  81711. #endif
  81712. #if defined(HAVE_CRL) && defined(WOLFSSL_CHECK_ALERT_ON_ERR) && \
  81713. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  81714. static int test_wolfSSL_CRL_CERT_REVOKED_alert_ctx_ready(WOLFSSL_CTX* ctx)
  81715. {
  81716. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  81717. return TEST_SUCCESS;
  81718. }
  81719. static int test_wolfSSL_CRL_CERT_REVOKED_alert_on_cleanup(WOLFSSL* ssl)
  81720. {
  81721. EXPECT_DECLS;
  81722. WOLFSSL_ALERT_HISTORY h;
  81723. ExpectIntEQ(wolfSSL_get_alert_history(ssl, &h), WOLFSSL_SUCCESS);
  81724. ExpectIntEQ(h.last_rx.level, alert_fatal);
  81725. ExpectIntEQ(h.last_rx.code, certificate_revoked);
  81726. return EXPECT_RESULT();
  81727. }
  81728. static int test_wolfSSL_CRL_CERT_REVOKED_alert(void)
  81729. {
  81730. EXPECT_DECLS;
  81731. test_ssl_cbf client_cbs, server_cbs;
  81732. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  81733. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  81734. server_cbs.certPemFile = "./certs/server-revoked-cert.pem";
  81735. server_cbs.keyPemFile = "./certs/server-revoked-key.pem";
  81736. client_cbs.crlPemFile = "./certs/crl/crl.revoked";
  81737. client_cbs.ctx_ready = test_wolfSSL_CRL_CERT_REVOKED_alert_ctx_ready;
  81738. server_cbs.on_cleanup = test_wolfSSL_CRL_CERT_REVOKED_alert_on_cleanup;
  81739. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  81740. &server_cbs, NULL), -1001);
  81741. return EXPECT_RESULT();
  81742. }
  81743. #else
  81744. static int test_wolfSSL_CRL_CERT_REVOKED_alert(void)
  81745. {
  81746. return TEST_SKIPPED;
  81747. }
  81748. #endif
  81749. #if defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET) \
  81750. && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_AESGCM) && \
  81751. !defined(NO_SHA256) && defined(WOLFSSL_AES_128) && \
  81752. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256) && \
  81753. !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  81754. static WOLFSSL_CTX* test_TLS_13_ticket_different_ciphers_ctx = NULL;
  81755. static WOLFSSL_SESSION* test_TLS_13_ticket_different_ciphers_session = NULL;
  81756. static int test_TLS_13_ticket_different_ciphers_run = 0;
  81757. static int test_TLS_13_ticket_different_ciphers_ssl_ready(WOLFSSL* ssl)
  81758. {
  81759. EXPECT_DECLS;
  81760. switch (test_TLS_13_ticket_different_ciphers_run) {
  81761. case 0:
  81762. /* First run */
  81763. ExpectIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES128-GCM-SHA256"),
  81764. WOLFSSL_SUCCESS);
  81765. if (wolfSSL_is_server(ssl)) {
  81766. ExpectNotNull(test_TLS_13_ticket_different_ciphers_ctx =
  81767. wolfSSL_get_SSL_CTX(ssl));
  81768. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_up_ref(
  81769. test_TLS_13_ticket_different_ciphers_ctx));
  81770. }
  81771. break;
  81772. case 1:
  81773. /* Second run */
  81774. ExpectIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384:"
  81775. "TLS13-AES128-GCM-SHA256"),
  81776. WOLFSSL_SUCCESS);
  81777. if (!wolfSSL_is_server(ssl)) {
  81778. ExpectIntEQ(wolfSSL_set_session(ssl,
  81779. test_TLS_13_ticket_different_ciphers_session),
  81780. WOLFSSL_SUCCESS);
  81781. }
  81782. break;
  81783. default:
  81784. /* Bad state? */
  81785. Fail(("Should not enter here"), ("Should not enter here"));
  81786. }
  81787. return EXPECT_RESULT();
  81788. }
  81789. static int test_TLS_13_ticket_different_ciphers_on_result(WOLFSSL* ssl)
  81790. {
  81791. EXPECT_DECLS;
  81792. switch (test_TLS_13_ticket_different_ciphers_run) {
  81793. case 0:
  81794. /* First run */
  81795. ExpectNotNull(test_TLS_13_ticket_different_ciphers_session =
  81796. wolfSSL_get1_session(ssl));
  81797. break;
  81798. case 1:
  81799. /* Second run */
  81800. ExpectTrue(wolfSSL_session_reused(ssl));
  81801. break;
  81802. default:
  81803. /* Bad state? */
  81804. Fail(("Should not enter here"), ("Should not enter here"));
  81805. }
  81806. return EXPECT_RESULT();
  81807. }
  81808. static int test_TLS_13_ticket_different_ciphers(void)
  81809. {
  81810. EXPECT_DECLS;
  81811. /* Check that we handle the connection when the ticket doesn't match
  81812. * the first ciphersuite. */
  81813. test_ssl_cbf client_cbs, server_cbs;
  81814. struct test_params {
  81815. method_provider client_meth;
  81816. method_provider server_meth;
  81817. int doUdp;
  81818. } params[] = {
  81819. #ifdef WOLFSSL_DTLS13
  81820. /* Test that the stateless code handles sessions correctly */
  81821. {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, 1},
  81822. #endif
  81823. {wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, 0},
  81824. };
  81825. size_t i;
  81826. for (i = 0; i < sizeof(params)/sizeof(*params); i++) {
  81827. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  81828. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  81829. test_TLS_13_ticket_different_ciphers_run = 0;
  81830. client_cbs.doUdp = server_cbs.doUdp = params[i].doUdp;
  81831. client_cbs.method = params[i].client_meth;
  81832. server_cbs.method = params[i].server_meth;
  81833. client_cbs.ssl_ready = test_TLS_13_ticket_different_ciphers_ssl_ready;
  81834. server_cbs.ssl_ready = test_TLS_13_ticket_different_ciphers_ssl_ready;
  81835. client_cbs.on_result = test_TLS_13_ticket_different_ciphers_on_result;
  81836. server_cbs.ticNoInit = 1;
  81837. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  81838. &server_cbs, NULL), TEST_SUCCESS);
  81839. test_TLS_13_ticket_different_ciphers_run++;
  81840. server_cbs.ctx = test_TLS_13_ticket_different_ciphers_ctx;
  81841. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  81842. &server_cbs, NULL), TEST_SUCCESS);
  81843. wolfSSL_SESSION_free(test_TLS_13_ticket_different_ciphers_session);
  81844. test_TLS_13_ticket_different_ciphers_session = NULL;
  81845. wolfSSL_CTX_free(test_TLS_13_ticket_different_ciphers_ctx);
  81846. test_TLS_13_ticket_different_ciphers_ctx = NULL;
  81847. }
  81848. return EXPECT_RESULT();
  81849. }
  81850. #else
  81851. static int test_TLS_13_ticket_different_ciphers(void)
  81852. {
  81853. return TEST_SKIPPED;
  81854. }
  81855. #endif
  81856. #if defined(WOLFSSL_EXTRA_ALERTS) && !defined(WOLFSSL_NO_TLS12) && \
  81857. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  81858. #define TEST_WRONG_CS_CLIENT "DHE-RSA-AES128-SHA"
  81859. /* AKA TLS_DHE_RSA_WITH_AES_128_CBC_SHA */
  81860. byte test_extra_alerts_wrong_cs_sh[] = {
  81861. 0x16, 0x03, 0x03, 0x00, 0x56, 0x02, 0x00, 0x00, 0x52, 0x03, 0x03, 0xef,
  81862. 0x0c, 0x30, 0x98, 0xa2, 0xac, 0xfa, 0x68, 0xe9, 0x3e, 0xaa, 0x5c, 0xcf,
  81863. 0xa7, 0x42, 0x72, 0xaf, 0xa0, 0xe8, 0x39, 0x2b, 0x3e, 0x81, 0xa7, 0x7a,
  81864. 0xa5, 0x62, 0x8a, 0x0e, 0x41, 0xba, 0xda, 0x20, 0x18, 0x9f, 0xe1, 0x8c,
  81865. 0x1d, 0xc0, 0x37, 0x9c, 0xf4, 0x90, 0x5d, 0x8d, 0xa0, 0x79, 0xa7, 0x4b,
  81866. 0xa8, 0x79, 0xdf, 0xcd, 0x8d, 0xf5, 0xb5, 0x50, 0x5f, 0xf1, 0xdb, 0x4d,
  81867. 0xbb, 0x07, 0x54, 0x1c,
  81868. 0x00, 0x02, /* TLS_RSA_WITH_NULL_SHA */
  81869. 0x00, 0x00, 0x0a, 0x00, 0x0b, 0x00,
  81870. 0x02, 0x01, 0x00, 0x00, 0x17, 0x00, 0x00
  81871. };
  81872. static int test_extra_alerts_wrong_cs(void)
  81873. {
  81874. EXPECT_DECLS;
  81875. #ifdef BUILD_TLS_DHE_RSA_WITH_AES_128_CBC_SHA
  81876. struct test_memio_ctx test_ctx;
  81877. WOLFSSL_CTX *ctx_c = NULL;
  81878. WOLFSSL_ALERT_HISTORY h;
  81879. WOLFSSL *ssl_c = NULL;
  81880. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81881. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
  81882. wolfTLSv1_2_client_method, NULL), 0);
  81883. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_c, TEST_WRONG_CS_CLIENT),
  81884. WOLFSSL_SUCCESS);
  81885. /* CH */
  81886. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  81887. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81888. WOLFSSL_ERROR_WANT_READ);
  81889. /* consume CH */
  81890. test_ctx.s_len = 0;
  81891. /* inject SH */
  81892. XMEMCPY(test_ctx.c_buff, test_extra_alerts_wrong_cs_sh,
  81893. sizeof(test_extra_alerts_wrong_cs_sh));
  81894. test_ctx.c_len = sizeof(test_extra_alerts_wrong_cs_sh);
  81895. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  81896. ExpectIntNE(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81897. WOLFSSL_ERROR_WANT_READ);
  81898. ExpectIntEQ(wolfSSL_get_alert_history(ssl_c, &h), WOLFSSL_SUCCESS);
  81899. ExpectIntEQ(h.last_tx.code, handshake_failure);
  81900. ExpectIntEQ(h.last_tx.level, alert_fatal);
  81901. wolfSSL_free(ssl_c);
  81902. wolfSSL_CTX_free(ctx_c);
  81903. #endif
  81904. return EXPECT_RESULT();
  81905. }
  81906. #else
  81907. static int test_extra_alerts_wrong_cs(void)
  81908. {
  81909. return TEST_SKIPPED;
  81910. }
  81911. #endif
  81912. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_TLS12) && \
  81913. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  81914. #define TEST_CS_DOWNGRADE_CLIENT "ECDHE-RSA-AES256-GCM-SHA384"
  81915. byte test_wrong_cs_downgrade_sh[] = {
  81916. 0x16, 0x03, 0x03, 0x00, 0x56, 0x02, 0x00, 0x00, 0x52, 0x03, 0x03, 0x10,
  81917. 0x2c, 0x88, 0xd9, 0x7a, 0x23, 0xc9, 0xbd, 0x11, 0x3b, 0x64, 0x24, 0xab,
  81918. 0x5b, 0x45, 0x33, 0xf6, 0x2c, 0x34, 0xe4, 0xcf, 0xf4, 0x78, 0xc8, 0x62,
  81919. 0x06, 0xc7, 0xe5, 0x30, 0x39, 0xbf, 0xa1, 0x20, 0xa3, 0x06, 0x74, 0xc3,
  81920. 0xa9, 0x74, 0x52, 0x8a, 0xfb, 0xae, 0xf0, 0xd8, 0x6f, 0xb2, 0x9d, 0xfe,
  81921. 0x78, 0xf0, 0x3f, 0x51, 0x8f, 0x9c, 0xcf, 0xbe, 0x61, 0x43, 0x9d, 0xf8,
  81922. 0x85, 0xe5, 0x2f, 0x54,
  81923. 0xc0, 0x2f, /* ECDHE-RSA-AES128-GCM-SHA256 */
  81924. 0x00, 0x00, 0x0a, 0x00, 0x0b, 0x00,
  81925. 0x02, 0x01, 0x00, 0x00, 0x17, 0x00, 0x00
  81926. };
  81927. static int test_wrong_cs_downgrade(void)
  81928. {
  81929. EXPECT_DECLS;
  81930. #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
  81931. struct test_memio_ctx test_ctx;
  81932. WOLFSSL_CTX *ctx_c = NULL;
  81933. WOLFSSL *ssl_c = NULL;
  81934. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  81935. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
  81936. wolfSSLv23_client_method, NULL), 0);
  81937. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_c, TEST_CS_DOWNGRADE_CLIENT),
  81938. WOLFSSL_SUCCESS);
  81939. /* CH */
  81940. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  81941. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81942. WOLFSSL_ERROR_WANT_READ);
  81943. /* consume CH */
  81944. test_ctx.s_len = 0;
  81945. /* inject SH */
  81946. XMEMCPY(test_ctx.c_buff, test_wrong_cs_downgrade_sh,
  81947. sizeof(test_wrong_cs_downgrade_sh));
  81948. test_ctx.c_len = sizeof(test_wrong_cs_downgrade_sh);
  81949. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  81950. #ifdef OPENSSL_EXTRA
  81951. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81952. WC_NO_ERR_TRACE(WOLFSSL_ERROR_SYSCALL));
  81953. #else
  81954. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  81955. WC_NO_ERR_TRACE(MATCH_SUITE_ERROR));
  81956. #endif /* OPENSSL_EXTRA */
  81957. wolfSSL_free(ssl_c);
  81958. wolfSSL_CTX_free(ctx_c);
  81959. #endif
  81960. return EXPECT_RESULT();
  81961. }
  81962. #else
  81963. static int test_wrong_cs_downgrade(void)
  81964. {
  81965. return TEST_SKIPPED;
  81966. }
  81967. #endif
  81968. #if !defined(WOLFSSL_NO_TLS12) && defined(WOLFSSL_EXTRA_ALERTS) && \
  81969. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_SP_MATH)
  81970. static void test_remove_msg(byte *msg, int tail_len, int *len, int msg_length)
  81971. {
  81972. tail_len -= msg_length;
  81973. XMEMMOVE(msg, msg + msg_length, tail_len);
  81974. *len = *len - msg_length;
  81975. }
  81976. static int test_remove_hs_msg_from_buffer(byte *buf, int *len, byte type,
  81977. byte *found)
  81978. {
  81979. const unsigned int _HANDSHAKE_HEADER_SZ = 4;
  81980. const unsigned int _RECORD_HEADER_SZ = 5;
  81981. const int _change_cipher_hs = 55;
  81982. const int _change_cipher = 20;
  81983. const int _handshake = 22;
  81984. unsigned int tail_len;
  81985. byte *idx, *curr;
  81986. word8 currType;
  81987. word16 rLength;
  81988. word32 hLength;
  81989. idx = buf;
  81990. tail_len = (unsigned int)*len;
  81991. *found = 0;
  81992. while (tail_len > _RECORD_HEADER_SZ) {
  81993. curr = idx;
  81994. currType = *idx;
  81995. ato16(idx + 3, &rLength);
  81996. idx += _RECORD_HEADER_SZ;
  81997. tail_len -= _RECORD_HEADER_SZ;
  81998. if (tail_len < rLength)
  81999. return -1;
  82000. if (type == _change_cipher_hs && currType == _change_cipher) {
  82001. if (rLength != 1)
  82002. return -1;
  82003. /* match */
  82004. test_remove_msg(curr, *len - (int)(curr - buf),
  82005. len, _RECORD_HEADER_SZ + 1);
  82006. *found = 1;
  82007. return 0;
  82008. }
  82009. if (currType != _handshake) {
  82010. idx += rLength;
  82011. tail_len -= rLength;
  82012. continue;
  82013. }
  82014. if (rLength < _HANDSHAKE_HEADER_SZ)
  82015. return -1;
  82016. currType = *idx;
  82017. ato24(idx+1, &hLength);
  82018. hLength += _HANDSHAKE_HEADER_SZ;
  82019. if (tail_len < hLength)
  82020. return -1;
  82021. if (currType != type) {
  82022. idx += hLength;
  82023. tail_len -= hLength;
  82024. continue;
  82025. }
  82026. /* match */
  82027. test_remove_msg(curr, *len - (int)(curr - buf), len,
  82028. hLength + _RECORD_HEADER_SZ);
  82029. *found = 1;
  82030. return 0;
  82031. }
  82032. /* not found */
  82033. return 0;
  82034. }
  82035. static int test_remove_hs_message(byte hs_message_type,
  82036. int extra_round, byte alert_type)
  82037. {
  82038. EXPECT_DECLS;
  82039. WOLFSSL_CTX *ctx_c = NULL;
  82040. WOLFSSL_CTX *ctx_s = NULL;
  82041. WOLFSSL *ssl_c = NULL;
  82042. WOLFSSL *ssl_s = NULL;
  82043. struct test_memio_ctx test_ctx;
  82044. WOLFSSL_ALERT_HISTORY h;
  82045. byte found = 0;
  82046. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82047. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82048. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  82049. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  82050. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82051. WOLFSSL_ERROR_WANT_READ);
  82052. ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  82053. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82054. WOLFSSL_ERROR_WANT_READ);
  82055. if (extra_round) {
  82056. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  82057. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82058. WOLFSSL_ERROR_WANT_READ);
  82059. /* this will complete handshake from server side */
  82060. ExpectIntEQ(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  82061. }
  82062. ExpectIntEQ(test_remove_hs_msg_from_buffer(test_ctx.c_buff,
  82063. &test_ctx.c_len, hs_message_type, &found), 0);
  82064. if (!found) {
  82065. wolfSSL_free(ssl_c);
  82066. wolfSSL_CTX_free(ctx_c);
  82067. wolfSSL_free(ssl_s);
  82068. wolfSSL_CTX_free(ctx_s);
  82069. return TEST_SKIPPED;
  82070. }
  82071. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  82072. ExpectIntNE(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82073. WOLFSSL_ERROR_WANT_READ);
  82074. ExpectIntEQ(wolfSSL_get_alert_history(ssl_c, &h), WOLFSSL_SUCCESS);
  82075. ExpectTrue(alert_type == 0xff || h.last_tx.code == alert_type);
  82076. ExpectIntEQ(h.last_tx.level, alert_fatal);
  82077. wolfSSL_free(ssl_c);
  82078. wolfSSL_CTX_free(ctx_c);
  82079. wolfSSL_free(ssl_s);
  82080. wolfSSL_CTX_free(ctx_s);
  82081. return EXPECT_RESULT();
  82082. }
  82083. static int test_extra_alerts_skip_hs(void)
  82084. {
  82085. EXPECT_DECLS;
  82086. const byte _server_key_exchange = 12;
  82087. const byte _server_hello = 2;
  82088. const byte _certificate = 11;
  82089. /* server_hello */
  82090. ExpectIntNE(test_remove_hs_message(_server_hello, 0,
  82091. unexpected_message), TEST_FAIL);
  82092. ExpectIntNE(test_remove_hs_message(_certificate, 0,
  82093. 0xff), TEST_FAIL);
  82094. ExpectIntNE(test_remove_hs_message(_server_key_exchange, 0,
  82095. unexpected_message), TEST_FAIL);
  82096. return EXPECT_RESULT();
  82097. }
  82098. #else
  82099. static int test_extra_alerts_skip_hs(void)
  82100. {
  82101. return TEST_SKIPPED;
  82102. }
  82103. #endif
  82104. #if !defined(WOLFSSL_NO_TLS12) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)\
  82105. && defined(WOLFSSL_EXTRA_ALERTS) && !defined(NO_PSK) && !defined(NO_DH)
  82106. static unsigned int test_server_psk_cb(WOLFSSL* ssl, const char* id,
  82107. unsigned char* key, unsigned int key_max_len)
  82108. {
  82109. (void)ssl;
  82110. (void)id;
  82111. (void)key_max_len;
  82112. /* zero means error */
  82113. key[0] = 0x10;
  82114. return 1;
  82115. }
  82116. static int test_extra_alerts_bad_psk(void)
  82117. {
  82118. EXPECT_DECLS;
  82119. WOLFSSL_CTX *ctx_c = NULL;
  82120. WOLFSSL_CTX *ctx_s = NULL;
  82121. WOLFSSL *ssl_c = NULL;
  82122. WOLFSSL *ssl_s = NULL;
  82123. struct test_memio_ctx test_ctx;
  82124. WOLFSSL_ALERT_HISTORY h;
  82125. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82126. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82127. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  82128. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_c, "DHE-PSK-AES128-GCM-SHA256"),
  82129. WOLFSSL_SUCCESS);
  82130. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_s, "DHE-PSK-AES128-GCM-SHA256"),
  82131. WOLFSSL_SUCCESS);
  82132. wolfSSL_set_psk_server_callback(ssl_s, test_server_psk_cb);
  82133. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  82134. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82135. WOLFSSL_ERROR_WANT_READ);
  82136. ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  82137. ExpectIntEQ(wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82138. WOLFSSL_ERROR_WANT_READ);
  82139. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  82140. ExpectIntNE(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82141. WOLFSSL_ERROR_WANT_READ);
  82142. ExpectIntEQ(wolfSSL_get_alert_history(ssl_c, &h), WOLFSSL_SUCCESS);
  82143. ExpectIntEQ(h.last_tx.code, handshake_failure);
  82144. ExpectIntEQ(h.last_tx.level, alert_fatal);
  82145. wolfSSL_free(ssl_c);
  82146. wolfSSL_CTX_free(ctx_c);
  82147. wolfSSL_free(ssl_s);
  82148. wolfSSL_CTX_free(ctx_s);
  82149. return EXPECT_RESULT();
  82150. }
  82151. #else
  82152. static int test_extra_alerts_bad_psk(void)
  82153. {
  82154. return TEST_SKIPPED;
  82155. }
  82156. #endif
  82157. #if defined(OPENSSL_EXTRA) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  82158. /*
  82159. * Emulates wolfSSL_shutdown that goes on EAGAIN,
  82160. * by returning on output WOLFSSL_ERROR_WANT_WRITE.*/
  82161. static int custom_wolfSSL_shutdown(WOLFSSL *ssl, char *buf,
  82162. int sz, void *ctx)
  82163. {
  82164. (void)ssl;
  82165. (void)buf;
  82166. (void)ctx;
  82167. (void)sz;
  82168. return WOLFSSL_CBIO_ERR_WANT_WRITE;
  82169. }
  82170. static int test_multiple_alerts_EAGAIN(void)
  82171. {
  82172. EXPECT_DECLS;
  82173. size_t size_of_last_packet = 0;
  82174. /* declare wolfSSL objects */
  82175. struct test_memio_ctx test_ctx;
  82176. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  82177. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  82178. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82179. /* Create and initialize WOLFSSL_CTX and WOLFSSL objects */
  82180. #ifdef USE_TLSV13
  82181. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82182. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  82183. #else
  82184. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82185. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  82186. #endif
  82187. ExpectNotNull(ctx_c);
  82188. ExpectNotNull(ssl_c);
  82189. ExpectNotNull(ctx_s);
  82190. ExpectNotNull(ssl_s);
  82191. /* Load client certificates into WOLFSSL_CTX */
  82192. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx_c, "./certs/ca-cert.pem", NULL), WOLFSSL_SUCCESS);
  82193. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  82194. /*
  82195. * We set the custom callback for the IO to emulate multiple EAGAINs
  82196. * on shutdown, so we can check that we don't send multiple packets.
  82197. * */
  82198. wolfSSL_SSLSetIOSend(ssl_c, custom_wolfSSL_shutdown);
  82199. /*
  82200. * We call wolfSSL_shutdown multiple times to reproduce the behaviour,
  82201. * to check that it doesn't add the CLOSE_NOTIFY packet multiple times
  82202. * on the output buffer.
  82203. * */
  82204. wolfSSL_shutdown(ssl_c);
  82205. wolfSSL_shutdown(ssl_c);
  82206. if (ssl_c != NULL) {
  82207. size_of_last_packet = ssl_c->buffers.outputBuffer.length;
  82208. }
  82209. wolfSSL_shutdown(ssl_c);
  82210. /*
  82211. * Finally we check the length of the output buffer.
  82212. * */
  82213. ExpectIntEQ((ssl_c->buffers.outputBuffer.length - size_of_last_packet), 0);
  82214. /* Cleanup and return */
  82215. wolfSSL_CTX_free(ctx_c);
  82216. wolfSSL_free(ssl_c);
  82217. wolfSSL_CTX_free(ctx_s);
  82218. wolfSSL_free(ssl_s);
  82219. return EXPECT_RESULT();
  82220. }
  82221. #else
  82222. static int test_multiple_alerts_EAGAIN(void)
  82223. {
  82224. return TEST_SKIPPED;
  82225. }
  82226. #endif
  82227. #if defined(WOLFSSL_TLS13) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)\
  82228. && !defined(NO_PSK)
  82229. static unsigned int test_tls13_bad_psk_binder_client_cb(WOLFSSL* ssl,
  82230. const char* hint, char* identity, unsigned int id_max_len,
  82231. unsigned char* key, unsigned int key_max_len)
  82232. {
  82233. (void)ssl;
  82234. (void)hint;
  82235. (void)key_max_len;
  82236. /* see internal.h MAX_PSK_ID_LEN for PSK identity limit */
  82237. XSTRNCPY(identity, "Client_identity", id_max_len);
  82238. key[0] = 0x20;
  82239. return 1;
  82240. }
  82241. static unsigned int test_tls13_bad_psk_binder_server_cb(WOLFSSL* ssl,
  82242. const char* id, unsigned char* key, unsigned int key_max_len)
  82243. {
  82244. (void)ssl;
  82245. (void)id;
  82246. (void)key_max_len;
  82247. /* zero means error */
  82248. key[0] = 0x10;
  82249. return 1;
  82250. }
  82251. #endif
  82252. static int test_tls13_bad_psk_binder(void)
  82253. {
  82254. EXPECT_DECLS;
  82255. #if defined(WOLFSSL_TLS13) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)\
  82256. && !defined(NO_PSK)
  82257. WOLFSSL_CTX *ctx_c = NULL;
  82258. WOLFSSL_CTX *ctx_s = NULL;
  82259. WOLFSSL *ssl_c = NULL;
  82260. WOLFSSL *ssl_s = NULL;
  82261. struct test_memio_ctx test_ctx;
  82262. WOLFSSL_ALERT_HISTORY h;
  82263. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82264. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82265. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  82266. wolfSSL_set_psk_client_callback(ssl_c, test_tls13_bad_psk_binder_client_cb);
  82267. wolfSSL_set_psk_server_callback(ssl_s, test_tls13_bad_psk_binder_server_cb);
  82268. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  82269. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82270. WOLFSSL_ERROR_WANT_READ);
  82271. ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  82272. ExpectIntEQ( wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82273. WC_NO_ERR_TRACE(BAD_BINDER));
  82274. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  82275. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82276. WC_NO_ERR_TRACE(FATAL_ERROR));
  82277. ExpectIntEQ(wolfSSL_get_alert_history(ssl_c, &h), WOLFSSL_SUCCESS);
  82278. ExpectIntEQ(h.last_rx.code, illegal_parameter);
  82279. ExpectIntEQ(h.last_rx.level, alert_fatal);
  82280. wolfSSL_free(ssl_c);
  82281. wolfSSL_CTX_free(ctx_c);
  82282. wolfSSL_free(ssl_s);
  82283. wolfSSL_CTX_free(ctx_s);
  82284. #endif
  82285. return EXPECT_RESULT();
  82286. }
  82287. #if defined(WOLFSSL_HARDEN_TLS) && !defined(WOLFSSL_NO_TLS12) && \
  82288. defined(HAVE_IO_TESTS_DEPENDENCIES)
  82289. static int test_harden_no_secure_renegotiation_io_cb(WOLFSSL *ssl, char *buf,
  82290. int sz, void *ctx)
  82291. {
  82292. static int sentServerHello = FALSE;
  82293. if (!sentServerHello) {
  82294. byte renegExt[] = { 0xFF, 0x01, 0x00, 0x01, 0x00 };
  82295. size_t i;
  82296. if (sz < (int)sizeof(renegExt))
  82297. return WOLFSSL_CBIO_ERR_GENERAL;
  82298. /* Remove SCR from ServerHello */
  82299. for (i = 0; i < sz - sizeof(renegExt); i++) {
  82300. if (XMEMCMP(buf + i, renegExt, sizeof(renegExt)) == 0) {
  82301. /* Found the extension. Change it to something unrecognized. */
  82302. buf[i+1] = 0x11;
  82303. break;
  82304. }
  82305. }
  82306. sentServerHello = TRUE;
  82307. }
  82308. return EmbedSend(ssl, buf, sz, ctx);
  82309. }
  82310. static void test_harden_no_secure_renegotiation_ssl_ready(WOLFSSL* ssl)
  82311. {
  82312. wolfSSL_SSLSetIOSend(ssl, test_harden_no_secure_renegotiation_io_cb);
  82313. }
  82314. static void test_harden_no_secure_renegotiation_on_cleanup(WOLFSSL* ssl)
  82315. {
  82316. WOLFSSL_ALERT_HISTORY h;
  82317. AssertIntEQ(wolfSSL_get_alert_history(ssl, &h), WOLFSSL_SUCCESS);
  82318. AssertIntEQ(h.last_rx.code, handshake_failure);
  82319. AssertIntEQ(h.last_rx.level, alert_fatal);
  82320. }
  82321. static int test_harden_no_secure_renegotiation(void)
  82322. {
  82323. EXPECT_DECLS;
  82324. callback_functions client_cbs, server_cbs;
  82325. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  82326. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  82327. client_cbs.method = wolfTLSv1_2_client_method;
  82328. server_cbs.method = wolfTLSv1_2_server_method;
  82329. server_cbs.ssl_ready = test_harden_no_secure_renegotiation_ssl_ready;
  82330. server_cbs.on_cleanup = test_harden_no_secure_renegotiation_on_cleanup;
  82331. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  82332. ExpectIntEQ(client_cbs.return_code, TEST_FAIL);
  82333. ExpectIntEQ(client_cbs.last_err, WC_NO_ERR_TRACE(SECURE_RENEGOTIATION_E));
  82334. ExpectIntEQ(server_cbs.return_code, TEST_FAIL);
  82335. ExpectTrue(server_cbs.last_err == WC_NO_ERR_TRACE(SOCKET_ERROR_E) ||
  82336. server_cbs.last_err == WC_NO_ERR_TRACE(FATAL_ERROR));
  82337. return EXPECT_RESULT();
  82338. }
  82339. #else
  82340. static int test_harden_no_secure_renegotiation(void)
  82341. {
  82342. return TEST_SKIPPED;
  82343. }
  82344. #endif
  82345. #if defined(HAVE_OCSP) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  82346. static int test_override_alt_cert_chain_cert_cb(int preverify,
  82347. WOLFSSL_X509_STORE_CTX* store)
  82348. {
  82349. fprintf(stderr, "preverify: %d\n", preverify);
  82350. fprintf(stderr, "store->error: %d\n", store->error);
  82351. fprintf(stderr, "error reason: %s\n", wolfSSL_ERR_reason_error_string(store->error));
  82352. if (store->error == WC_NO_ERR_TRACE(OCSP_INVALID_STATUS)) {
  82353. fprintf(stderr, "Overriding OCSP error\n");
  82354. return 1;
  82355. }
  82356. #ifndef WOLFSSL_ALT_CERT_CHAINS
  82357. else if ((store->error == WC_NO_ERR_TRACE(ASN_NO_SIGNER_E) ||
  82358. store->error == WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E)
  82359. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
  82360. defined(HAVE_WEBSERVER)
  82361. || store->error == WOLFSSL_X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY
  82362. #endif
  82363. ) && store->error_depth == store->totalCerts - 1) {
  82364. fprintf(stderr, "Overriding no signer error only for root cert\n");
  82365. return 1;
  82366. }
  82367. #endif
  82368. else
  82369. return preverify;
  82370. }
  82371. static int test_override_alt_cert_chain_ocsp_cb(void* ioCtx, const char* url,
  82372. int urlSz, unsigned char* request, int requestSz,
  82373. unsigned char** response)
  82374. {
  82375. (void)ioCtx;
  82376. (void)url;
  82377. (void)urlSz;
  82378. (void)request;
  82379. (void)requestSz;
  82380. (void)response;
  82381. return -1;
  82382. }
  82383. static int test_override_alt_cert_chain_client_ctx_ready(WOLFSSL_CTX* ctx)
  82384. {
  82385. EXPECT_DECLS;
  82386. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER,
  82387. test_override_alt_cert_chain_cert_cb);
  82388. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, WOLFSSL_OCSP_CHECKALL |
  82389. WOLFSSL_OCSP_URL_OVERRIDE), WOLFSSL_SUCCESS);
  82390. ExpectIntEQ(wolfSSL_CTX_SetOCSP_Cb(ctx,
  82391. test_override_alt_cert_chain_ocsp_cb, NULL, NULL), WOLFSSL_SUCCESS);
  82392. ExpectIntEQ(wolfSSL_CTX_SetOCSP_OverrideURL(ctx, "not a url"),
  82393. WOLFSSL_SUCCESS);
  82394. return EXPECT_RESULT();
  82395. }
  82396. static int test_override_alt_cert_chain_client_ctx_ready2(WOLFSSL_CTX* ctx)
  82397. {
  82398. EXPECT_DECLS;
  82399. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  82400. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, WOLFSSL_OCSP_CHECKALL |
  82401. WOLFSSL_OCSP_URL_OVERRIDE), WOLFSSL_SUCCESS);
  82402. ExpectIntEQ(wolfSSL_CTX_SetOCSP_Cb(ctx,
  82403. test_override_alt_cert_chain_ocsp_cb, NULL, NULL), WOLFSSL_SUCCESS);
  82404. ExpectIntEQ(wolfSSL_CTX_SetOCSP_OverrideURL(ctx, "not a url"),
  82405. WOLFSSL_SUCCESS);
  82406. return EXPECT_RESULT();
  82407. }
  82408. static int test_override_alt_cert_chain_server_ctx_ready(WOLFSSL_CTX* ctx)
  82409. {
  82410. EXPECT_DECLS;
  82411. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file(ctx,
  82412. "./certs/intermediate/server-chain-alt.pem"), WOLFSSL_SUCCESS);
  82413. return EXPECT_RESULT();
  82414. }
  82415. static int test_override_alt_cert_chain(void)
  82416. {
  82417. EXPECT_DECLS;
  82418. size_t i;
  82419. struct test_params {
  82420. ctx_cb client_ctx_cb;
  82421. ctx_cb server_ctx_cb;
  82422. int result;
  82423. } params[] = {
  82424. {test_override_alt_cert_chain_client_ctx_ready,
  82425. test_override_alt_cert_chain_server_ctx_ready, TEST_SUCCESS},
  82426. {test_override_alt_cert_chain_client_ctx_ready2,
  82427. test_override_alt_cert_chain_server_ctx_ready, -1001},
  82428. };
  82429. for (i = 0; i < sizeof(params)/sizeof(*params); i++) {
  82430. test_ssl_cbf client_cbs, server_cbs;
  82431. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  82432. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  82433. fprintf(stderr, "test config: %d\n", (int)i);
  82434. client_cbs.ctx_ready = params[i].client_ctx_cb;
  82435. server_cbs.ctx_ready = params[i].server_ctx_cb;
  82436. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  82437. &server_cbs, NULL), params[i].result);
  82438. ExpectIntEQ(client_cbs.return_code,
  82439. params[i].result <= 0 ? -1000 : TEST_SUCCESS);
  82440. ExpectIntEQ(server_cbs.return_code,
  82441. params[i].result <= 0 ? -1000 : TEST_SUCCESS);
  82442. }
  82443. return EXPECT_RESULT();
  82444. }
  82445. #else
  82446. static int test_override_alt_cert_chain(void)
  82447. {
  82448. return TEST_SKIPPED;
  82449. }
  82450. #endif
  82451. #if defined(HAVE_RPK)
  82452. #define svrRpkCertFile "./certs/rpk/server-cert-rpk.der"
  82453. #define clntRpkCertFile "./certs/rpk/client-cert-rpk.der"
  82454. #if defined(WOLFSSL_ALWAYS_VERIFY_CB) && defined(WOLFSSL_TLS13)
  82455. static int MyRpkVerifyCb(int mode, WOLFSSL_X509_STORE_CTX* strctx)
  82456. {
  82457. int ret = WOLFSSL_SUCCESS;
  82458. (void)mode;
  82459. (void)strctx;
  82460. WOLFSSL_ENTER("MyRpkVerifyCb");
  82461. return ret;
  82462. }
  82463. #endif /* WOLFSSL_ALWAYS_VERIFY_CB && WOLFSSL_TLS13 */
  82464. static WC_INLINE int test_rpk_memio_setup(
  82465. struct test_memio_ctx *ctx,
  82466. WOLFSSL_CTX **ctx_c,
  82467. WOLFSSL_CTX **ctx_s,
  82468. WOLFSSL **ssl_c,
  82469. WOLFSSL **ssl_s,
  82470. method_provider method_c,
  82471. method_provider method_s,
  82472. const char* certfile_c, int fmt_cc, /* client cert file path and format */
  82473. const char* certfile_s, int fmt_cs, /* server cert file path and format */
  82474. const char* pkey_c, int fmt_kc, /* client private key and format */
  82475. const char* pkey_s, int fmt_ks /* server private key and format */
  82476. )
  82477. {
  82478. int ret;
  82479. if (ctx_c != NULL && *ctx_c == NULL) {
  82480. *ctx_c = wolfSSL_CTX_new(method_c());
  82481. if (*ctx_c == NULL) {
  82482. return -1;
  82483. }
  82484. wolfSSL_CTX_set_verify(*ctx_c, WOLFSSL_VERIFY_PEER, NULL);
  82485. ret = wolfSSL_CTX_load_verify_locations(*ctx_c, caCertFile, 0);
  82486. if (ret != WOLFSSL_SUCCESS) {
  82487. return -1;
  82488. }
  82489. wolfSSL_SetIORecv(*ctx_c, test_memio_read_cb);
  82490. wolfSSL_SetIOSend(*ctx_c, test_memio_write_cb);
  82491. ret = wolfSSL_CTX_use_certificate_file(*ctx_c, certfile_c, fmt_cc);
  82492. if (ret != WOLFSSL_SUCCESS) {
  82493. return -1;
  82494. }
  82495. ret = wolfSSL_CTX_use_PrivateKey_file(*ctx_c, pkey_c, fmt_kc);
  82496. if (ret != WOLFSSL_SUCCESS) {
  82497. return -1;
  82498. }
  82499. }
  82500. if (ctx_s != NULL && *ctx_s == NULL) {
  82501. *ctx_s = wolfSSL_CTX_new(method_s());
  82502. if (*ctx_s == NULL) {
  82503. return -1;
  82504. }
  82505. wolfSSL_CTX_set_verify(*ctx_s, WOLFSSL_VERIFY_PEER, NULL);
  82506. ret = wolfSSL_CTX_load_verify_locations(*ctx_s, cliCertFile, 0);
  82507. if (ret != WOLFSSL_SUCCESS) {
  82508. return -1;
  82509. }
  82510. ret = wolfSSL_CTX_use_PrivateKey_file(*ctx_s, pkey_s, fmt_ks);
  82511. if (ret != WOLFSSL_SUCCESS) {
  82512. return -1;
  82513. }
  82514. ret = wolfSSL_CTX_use_certificate_file(*ctx_s, certfile_s, fmt_cs);
  82515. if (ret != WOLFSSL_SUCCESS) {
  82516. return -1;
  82517. }
  82518. wolfSSL_SetIORecv(*ctx_s, test_memio_read_cb);
  82519. wolfSSL_SetIOSend(*ctx_s, test_memio_write_cb);
  82520. if (ctx->s_ciphers != NULL) {
  82521. ret = wolfSSL_CTX_set_cipher_list(*ctx_s, ctx->s_ciphers);
  82522. if (ret != WOLFSSL_SUCCESS) {
  82523. return -1;
  82524. }
  82525. }
  82526. }
  82527. if (ctx_c != NULL && ssl_c != NULL) {
  82528. *ssl_c = wolfSSL_new(*ctx_c);
  82529. if (*ssl_c == NULL) {
  82530. return -1;
  82531. }
  82532. wolfSSL_SetIOWriteCtx(*ssl_c, ctx);
  82533. wolfSSL_SetIOReadCtx(*ssl_c, ctx);
  82534. }
  82535. if (ctx_s != NULL && ssl_s != NULL) {
  82536. *ssl_s = wolfSSL_new(*ctx_s);
  82537. if (*ssl_s == NULL) {
  82538. return -1;
  82539. }
  82540. wolfSSL_SetIOWriteCtx(*ssl_s, ctx);
  82541. wolfSSL_SetIOReadCtx(*ssl_s, ctx);
  82542. #if !defined(NO_DH)
  82543. SetDH(*ssl_s);
  82544. #endif
  82545. }
  82546. return 0;
  82547. }
  82548. #endif /* HAVE_RPK */
  82549. static int test_rpk_set_xxx_cert_type(void)
  82550. {
  82551. EXPECT_DECLS;
  82552. #if defined(HAVE_RPK)
  82553. char ctype[MAX_CLIENT_CERT_TYPE_CNT + 1]; /* prepare bigger buffer */
  82554. WOLFSSL_CTX* ctx = NULL;
  82555. WOLFSSL* ssl = NULL;
  82556. int tp;
  82557. ctx = wolfSSL_CTX_new(wolfTLS_client_method());
  82558. ExpectNotNull(ctx);
  82559. ssl = wolfSSL_new(ctx);
  82560. ExpectNotNull(ssl);
  82561. /*--------------------------------------------*/
  82562. /* tests for wolfSSL_CTX_set_client_cert_type */
  82563. /*--------------------------------------------*/
  82564. /* illegal parameter test caces */
  82565. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(NULL, ctype,
  82566. MAX_CLIENT_CERT_TYPE_CNT),
  82567. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82568. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  82569. sizeof(ctype)),
  82570. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82571. ctype[0] = WOLFSSL_CERT_TYPE_RPK; /* set an identical cert type */
  82572. ctype[1] = WOLFSSL_CERT_TYPE_RPK;
  82573. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  82574. MAX_CLIENT_CERT_TYPE_CNT),
  82575. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82576. ctype[0] = WOLFSSL_CERT_TYPE_X509;
  82577. ctype[1] = 10; /* set unknown cert type */
  82578. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  82579. MAX_CLIENT_CERT_TYPE_CNT),
  82580. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82581. /* pass larger type count */
  82582. ctype[0] = WOLFSSL_CERT_TYPE_RPK;
  82583. ctype[1] = WOLFSSL_CERT_TYPE_X509;
  82584. ctype[2] = 1; /* pass unacceptable type count */
  82585. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  82586. MAX_CLIENT_CERT_TYPE_CNT + 1),
  82587. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82588. /* should accept NULL for type buffer */
  82589. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, NULL,
  82590. MAX_CLIENT_CERT_TYPE_CNT),
  82591. WOLFSSL_SUCCESS);
  82592. /* should accept zero for type count */
  82593. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  82594. 0),
  82595. WOLFSSL_SUCCESS);
  82596. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  82597. MAX_CLIENT_CERT_TYPE_CNT),
  82598. WOLFSSL_SUCCESS);
  82599. /*--------------------------------------------*/
  82600. /* tests for wolfSSL_CTX_set_server_cert_type */
  82601. /*--------------------------------------------*/
  82602. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(NULL, ctype,
  82603. MAX_SERVER_CERT_TYPE_CNT),
  82604. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82605. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  82606. sizeof(ctype)),
  82607. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82608. ctype[0] = WOLFSSL_CERT_TYPE_RPK; /* set an identical cert type */
  82609. ctype[1] = WOLFSSL_CERT_TYPE_RPK;
  82610. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  82611. MAX_SERVER_CERT_TYPE_CNT),
  82612. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82613. ctype[0] = WOLFSSL_CERT_TYPE_X509;
  82614. ctype[1] = 10; /* set unknown cert type */
  82615. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  82616. MAX_SERVER_CERT_TYPE_CNT),
  82617. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82618. /* pass larger type count */
  82619. ctype[0] = WOLFSSL_CERT_TYPE_RPK;
  82620. ctype[1] = WOLFSSL_CERT_TYPE_X509;
  82621. ctype[2] = 1; /* pass unacceptable type count */
  82622. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  82623. MAX_SERVER_CERT_TYPE_CNT + 1),
  82624. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82625. /* should accept NULL for type buffer */
  82626. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, NULL,
  82627. MAX_SERVER_CERT_TYPE_CNT),
  82628. WOLFSSL_SUCCESS);
  82629. /* should accept zero for type count */
  82630. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  82631. 0),
  82632. WOLFSSL_SUCCESS);
  82633. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  82634. MAX_CLIENT_CERT_TYPE_CNT),
  82635. WOLFSSL_SUCCESS);
  82636. /*--------------------------------------------*/
  82637. /* tests for wolfSSL_set_client_cert_type */
  82638. /*--------------------------------------------*/
  82639. ExpectIntEQ(wolfSSL_set_client_cert_type(NULL, ctype,
  82640. MAX_CLIENT_CERT_TYPE_CNT),
  82641. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82642. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  82643. sizeof(ctype)),
  82644. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82645. ctype[0] = WOLFSSL_CERT_TYPE_RPK; /* set an identical cert type */
  82646. ctype[1] = WOLFSSL_CERT_TYPE_RPK;
  82647. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  82648. MAX_CLIENT_CERT_TYPE_CNT),
  82649. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82650. ctype[0] = WOLFSSL_CERT_TYPE_X509;
  82651. ctype[1] = 10; /* set unknown cert type */
  82652. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  82653. MAX_CLIENT_CERT_TYPE_CNT),
  82654. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82655. /* pass larger type count */
  82656. ctype[0] = WOLFSSL_CERT_TYPE_RPK;
  82657. ctype[1] = WOLFSSL_CERT_TYPE_X509;
  82658. ctype[2] = 1; /* pass unacceptable type count */
  82659. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  82660. MAX_CLIENT_CERT_TYPE_CNT + 1),
  82661. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82662. /* should accept NULL for type buffer */
  82663. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, NULL,
  82664. MAX_CLIENT_CERT_TYPE_CNT),
  82665. WOLFSSL_SUCCESS);
  82666. /* should accept zero for type count */
  82667. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  82668. 0),
  82669. WOLFSSL_SUCCESS);
  82670. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  82671. MAX_CLIENT_CERT_TYPE_CNT),
  82672. WOLFSSL_SUCCESS);
  82673. /*--------------------------------------------*/
  82674. /* tests for wolfSSL_CTX_set_server_cert_type */
  82675. /*--------------------------------------------*/
  82676. ExpectIntEQ(wolfSSL_set_server_cert_type(NULL, ctype,
  82677. MAX_SERVER_CERT_TYPE_CNT),
  82678. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82679. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  82680. sizeof(ctype)),
  82681. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82682. ctype[0] = WOLFSSL_CERT_TYPE_RPK; /* set an identical cert type */
  82683. ctype[1] = WOLFSSL_CERT_TYPE_RPK;
  82684. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  82685. MAX_SERVER_CERT_TYPE_CNT),
  82686. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82687. ctype[0] = WOLFSSL_CERT_TYPE_X509;
  82688. ctype[1] = 10; /* set unknown cert type */
  82689. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  82690. MAX_SERVER_CERT_TYPE_CNT),
  82691. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82692. /* pass larger type count */
  82693. ctype[0] = WOLFSSL_CERT_TYPE_RPK;
  82694. ctype[1] = WOLFSSL_CERT_TYPE_X509;
  82695. ctype[2] = 1; /* pass unacceptable type count */
  82696. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  82697. MAX_SERVER_CERT_TYPE_CNT + 1),
  82698. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82699. /* should accept NULL for type buffer */
  82700. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, NULL,
  82701. MAX_SERVER_CERT_TYPE_CNT),
  82702. WOLFSSL_SUCCESS);
  82703. /* should accept zero for type count */
  82704. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  82705. 0),
  82706. WOLFSSL_SUCCESS);
  82707. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  82708. MAX_SERVER_CERT_TYPE_CNT),
  82709. WOLFSSL_SUCCESS);
  82710. /*------------------------------------------------*/
  82711. /* tests for wolfSSL_get_negotiated_xxx_cert_type */
  82712. /*------------------------------------------------*/
  82713. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(NULL, &tp),
  82714. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82715. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl, NULL),
  82716. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82717. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(NULL, &tp),
  82718. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82719. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl, NULL),
  82720. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  82721. /* clean up */
  82722. wolfSSL_free(ssl);
  82723. wolfSSL_CTX_free(ctx);
  82724. #endif
  82725. return EXPECT_RESULT();
  82726. }
  82727. static int test_tls13_rpk_handshake(void)
  82728. {
  82729. EXPECT_DECLS;
  82730. #if defined(HAVE_RPK) && (!defined(WOLFSSL_NO_TLS12) || defined(WOLFSSL_TLS13))
  82731. #ifdef WOLFSSL_TLS13
  82732. int ret = 0;
  82733. #endif
  82734. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  82735. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  82736. struct test_memio_ctx test_ctx;
  82737. int err;
  82738. char certType_c[MAX_CLIENT_CERT_TYPE_CNT];
  82739. char certType_s[MAX_CLIENT_CERT_TYPE_CNT];
  82740. int typeCnt_c;
  82741. int typeCnt_s;
  82742. int tp = 0;
  82743. #if defined(WOLFSSL_ALWAYS_VERIFY_CB) && defined(WOLFSSL_TLS13)
  82744. int isServer;
  82745. #endif
  82746. (void)err;
  82747. (void)typeCnt_c;
  82748. (void)typeCnt_s;
  82749. (void)certType_c;
  82750. (void)certType_s;
  82751. #ifndef WOLFSSL_NO_TLS12
  82752. /* TLS1.2
  82753. * Both client and server load x509 cert and start handshaking.
  82754. * Check no negotiation occurred.
  82755. */
  82756. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82757. ExpectIntEQ(
  82758. test_rpk_memio_setup(
  82759. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82760. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method,
  82761. cliCertFile, WOLFSSL_FILETYPE_PEM,
  82762. svrCertFile, WOLFSSL_FILETYPE_PEM,
  82763. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  82764. svrKeyFile, WOLFSSL_FILETYPE_PEM)
  82765. , 0);
  82766. /* set client certificate type in client end */
  82767. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  82768. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  82769. typeCnt_c = 2;
  82770. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  82771. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  82772. typeCnt_s = 2;
  82773. /* both client and server do not call client/server_cert_type APIs,
  82774. * expecting default settings works and no negotiation performed.
  82775. */
  82776. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  82777. return TEST_FAIL;
  82778. /* confirm no negotiation occurred */
  82779. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  82780. WOLFSSL_SUCCESS);
  82781. ExpectIntEQ((int)tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82782. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  82783. WOLFSSL_SUCCESS);
  82784. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82785. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  82786. WOLFSSL_SUCCESS);
  82787. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82788. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  82789. WOLFSSL_SUCCESS);
  82790. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82791. (void)typeCnt_c;
  82792. (void)typeCnt_s;
  82793. wolfSSL_free(ssl_c);
  82794. wolfSSL_CTX_free(ctx_c);
  82795. wolfSSL_free(ssl_s);
  82796. wolfSSL_CTX_free(ctx_s);
  82797. ssl_c = ssl_s = NULL;
  82798. ctx_c = ctx_s = NULL;
  82799. #endif
  82800. #ifdef WOLFSSL_TLS13
  82801. /* Both client and server load x509 cert and start handshaking.
  82802. * Check no negotiation occurred.
  82803. */
  82804. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82805. ExpectIntEQ(
  82806. test_rpk_memio_setup(
  82807. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82808. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  82809. cliCertFile, WOLFSSL_FILETYPE_PEM,
  82810. svrCertFile, WOLFSSL_FILETYPE_PEM,
  82811. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  82812. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  82813. , 0);
  82814. /* set client certificate type in client end */
  82815. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  82816. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  82817. typeCnt_c = 2;
  82818. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  82819. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  82820. typeCnt_s = 2;
  82821. /* both client and server do not call client/server_cert_type APIs,
  82822. * expecting default settings works and no negotiation performed.
  82823. */
  82824. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  82825. return TEST_FAIL;
  82826. /* confirm no negotiation occurred */
  82827. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  82828. WOLFSSL_SUCCESS);
  82829. ExpectIntEQ((int)tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82830. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  82831. WOLFSSL_SUCCESS);
  82832. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82833. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  82834. WOLFSSL_SUCCESS);
  82835. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82836. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  82837. WOLFSSL_SUCCESS);
  82838. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  82839. (void)typeCnt_c;
  82840. (void)typeCnt_s;
  82841. wolfSSL_free(ssl_c);
  82842. wolfSSL_CTX_free(ctx_c);
  82843. wolfSSL_free(ssl_s);
  82844. wolfSSL_CTX_free(ctx_s);
  82845. ssl_c = ssl_s = NULL;
  82846. ctx_c = ctx_s = NULL;
  82847. /* Both client and server load RPK cert and start handshaking.
  82848. * Confirm negotiated cert types match as expected.
  82849. */
  82850. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82851. ExpectIntEQ(
  82852. test_rpk_memio_setup(
  82853. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82854. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  82855. clntRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  82856. svrRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  82857. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  82858. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  82859. , 0);
  82860. /* set client certificate type in client end */
  82861. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  82862. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  82863. typeCnt_c = 2;
  82864. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  82865. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  82866. typeCnt_s = 2;
  82867. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  82868. WOLFSSL_SUCCESS);
  82869. /* set server certificate type in client end */
  82870. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  82871. WOLFSSL_SUCCESS);
  82872. /* set client certificate type in server end */
  82873. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  82874. WOLFSSL_SUCCESS);
  82875. /* set server certificate type in server end */
  82876. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  82877. WOLFSSL_SUCCESS);
  82878. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  82879. return TEST_FAIL;
  82880. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  82881. WOLFSSL_SUCCESS);
  82882. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82883. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  82884. WOLFSSL_SUCCESS);
  82885. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82886. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  82887. WOLFSSL_SUCCESS);
  82888. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82889. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  82890. WOLFSSL_SUCCESS);
  82891. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82892. wolfSSL_free(ssl_c);
  82893. wolfSSL_CTX_free(ctx_c);
  82894. wolfSSL_free(ssl_s);
  82895. wolfSSL_CTX_free(ctx_s);
  82896. ssl_c = ssl_s = NULL;
  82897. ctx_c = ctx_s = NULL;
  82898. #endif
  82899. #ifndef WOLFSSL_NO_TLS12
  82900. /* TLS1.2
  82901. * Both client and server load RPK cert and start handshaking.
  82902. * Confirm negotiated cert types match as expected.
  82903. */
  82904. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82905. ExpectIntEQ(
  82906. test_rpk_memio_setup(
  82907. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82908. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method,
  82909. clntRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  82910. svrRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  82911. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  82912. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  82913. , 0);
  82914. /* set client certificate type in client end */
  82915. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  82916. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  82917. typeCnt_c = 2;
  82918. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  82919. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  82920. typeCnt_s = 2;
  82921. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  82922. WOLFSSL_SUCCESS);
  82923. /* set server certificate type in client end */
  82924. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  82925. WOLFSSL_SUCCESS);
  82926. /* set client certificate type in server end */
  82927. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  82928. WOLFSSL_SUCCESS);
  82929. /* set server certificate type in server end */
  82930. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  82931. WOLFSSL_SUCCESS);
  82932. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  82933. return TEST_FAIL;
  82934. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  82935. WOLFSSL_SUCCESS);
  82936. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82937. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  82938. WOLFSSL_SUCCESS);
  82939. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82940. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  82941. WOLFSSL_SUCCESS);
  82942. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82943. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  82944. WOLFSSL_SUCCESS);
  82945. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  82946. wolfSSL_free(ssl_c);
  82947. wolfSSL_CTX_free(ctx_c);
  82948. wolfSSL_free(ssl_s);
  82949. wolfSSL_CTX_free(ctx_s);
  82950. ssl_c = ssl_s = NULL;
  82951. ctx_c = ctx_s = NULL;
  82952. #endif
  82953. #ifdef WOLFSSL_TLS13
  82954. /* Both client and server load x509 cert.
  82955. * Have client call set_client_cert_type with both RPK and x509.
  82956. * This doesn't makes client add client cert type extension to ClientHello,
  82957. * since it does not load RPK cert actually.
  82958. */
  82959. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82960. ExpectIntEQ(
  82961. test_rpk_memio_setup(
  82962. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82963. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  82964. cliCertFile, WOLFSSL_FILETYPE_PEM,
  82965. svrCertFile, WOLFSSL_FILETYPE_PEM,
  82966. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  82967. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  82968. , 0);
  82969. /* set client certificate type in client end
  82970. *
  82971. * client indicates both RPK and x509 certs are available but loaded RPK
  82972. * cert only. It does not have client add client-cert-type extension in CH.
  82973. */
  82974. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  82975. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  82976. typeCnt_c = 2;
  82977. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  82978. WOLFSSL_SUCCESS);
  82979. /* client indicates both RPK and x509 certs are acceptable */
  82980. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  82981. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  82982. typeCnt_s = 2;
  82983. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  82984. WOLFSSL_SUCCESS);
  82985. /* server indicates both RPK and x509 certs are acceptable */
  82986. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  82987. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  82988. typeCnt_c = 2;
  82989. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  82990. WOLFSSL_SUCCESS);
  82991. /* server should indicate only RPK cert is available */
  82992. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  82993. certType_s[1] = -1;
  82994. typeCnt_s = 1;
  82995. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  82996. WOLFSSL_SUCCESS);
  82997. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  82998. return TEST_FAIL;
  82999. /* Negotiation for client-cert-type should NOT happen. Therefore -1 should
  83000. * be returned as cert type.
  83001. */
  83002. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  83003. WOLFSSL_SUCCESS);
  83004. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  83005. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  83006. WOLFSSL_SUCCESS);
  83007. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  83008. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  83009. WOLFSSL_SUCCESS);
  83010. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  83011. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  83012. WOLFSSL_SUCCESS);
  83013. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  83014. wolfSSL_free(ssl_c);
  83015. wolfSSL_CTX_free(ctx_c);
  83016. wolfSSL_free(ssl_s);
  83017. wolfSSL_CTX_free(ctx_s);
  83018. ssl_c = ssl_s = NULL;
  83019. ctx_c = ctx_s = NULL;
  83020. /* Have client load RPK cert and have server load x509 cert.
  83021. * Check the negotiation result from both ends.
  83022. */
  83023. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83024. ExpectIntEQ(
  83025. test_rpk_memio_setup(
  83026. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83027. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  83028. clntRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  83029. svrCertFile, WOLFSSL_FILETYPE_PEM,
  83030. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  83031. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  83032. , 0);
  83033. /* have client tell to use RPK cert */
  83034. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  83035. certType_c[1] = -1;
  83036. typeCnt_c = 1;
  83037. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  83038. WOLFSSL_SUCCESS);
  83039. /* have client tell to accept both RPK and x509 cert */
  83040. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  83041. certType_s[1] = WOLFSSL_CERT_TYPE_RPK;
  83042. typeCnt_s = 2;
  83043. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  83044. WOLFSSL_SUCCESS);
  83045. /* have server accept to both RPK and x509 cert */
  83046. certType_c[0] = WOLFSSL_CERT_TYPE_X509;
  83047. certType_c[1] = WOLFSSL_CERT_TYPE_RPK;
  83048. typeCnt_c = 2;
  83049. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  83050. WOLFSSL_SUCCESS);
  83051. /* does not call wolfSSL_set_server_cert_type intentionally in sesrver
  83052. * end, expecting the default setting works.
  83053. */
  83054. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  83055. return TEST_FAIL;
  83056. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  83057. WOLFSSL_SUCCESS);
  83058. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83059. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  83060. WOLFSSL_SUCCESS);
  83061. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  83062. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  83063. WOLFSSL_SUCCESS);
  83064. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83065. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  83066. WOLFSSL_SUCCESS);
  83067. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  83068. wolfSSL_free(ssl_c);
  83069. wolfSSL_CTX_free(ctx_c);
  83070. wolfSSL_free(ssl_s);
  83071. wolfSSL_CTX_free(ctx_s);
  83072. ssl_c = ssl_s = NULL;
  83073. ctx_c = ctx_s = NULL;
  83074. /* Have both client and server load RPK cert, however, have server
  83075. * indicate its cert type x509.
  83076. * Client is expected to detect the cert type mismatch then to send alert
  83077. * with "unsupported_certificate".
  83078. */
  83079. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83080. ExpectIntEQ(
  83081. test_rpk_memio_setup(
  83082. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83083. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  83084. clntRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  83085. svrRpkCertFile, WOLFSSL_FILETYPE_ASN1, /* server sends RPK cert */
  83086. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  83087. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  83088. , 0);
  83089. /* have client tell to use RPK cert */
  83090. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  83091. certType_c[1] = -1;
  83092. typeCnt_c = 1;
  83093. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  83094. WOLFSSL_SUCCESS);
  83095. /* have client tell to accept both RPK and x509 cert */
  83096. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  83097. certType_s[1] = WOLFSSL_CERT_TYPE_RPK;
  83098. typeCnt_s = 2;
  83099. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  83100. WOLFSSL_SUCCESS);
  83101. /* have server accept to both RPK and x509 cert */
  83102. certType_c[0] = WOLFSSL_CERT_TYPE_X509;
  83103. certType_c[1] = WOLFSSL_CERT_TYPE_RPK;
  83104. typeCnt_c = 2;
  83105. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  83106. WOLFSSL_SUCCESS);
  83107. /* have server tell to use x509 cert intentionally. This will bring
  83108. * certificate type mismatch in client side.
  83109. */
  83110. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  83111. certType_s[1] = -1;
  83112. typeCnt_s = 1;
  83113. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  83114. WOLFSSL_SUCCESS);
  83115. /* expect client detect cert type mismatch then send Alert */
  83116. ret = test_memio_do_handshake(ssl_c, ssl_s, 10, NULL);
  83117. if (ret != -1)
  83118. return TEST_FAIL;
  83119. ExpectIntEQ(wolfSSL_get_error(ssl_c, ret), WC_NO_ERR_TRACE(UNSUPPORTED_CERTIFICATE));
  83120. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  83121. WOLFSSL_SUCCESS);
  83122. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83123. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  83124. WOLFSSL_SUCCESS);
  83125. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  83126. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  83127. WOLFSSL_SUCCESS);
  83128. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83129. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  83130. WOLFSSL_SUCCESS);
  83131. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  83132. wolfSSL_free(ssl_c);
  83133. wolfSSL_CTX_free(ctx_c);
  83134. wolfSSL_free(ssl_s);
  83135. wolfSSL_CTX_free(ctx_s);
  83136. ssl_c = ssl_s = NULL;
  83137. ctx_c = ctx_s = NULL;
  83138. /* Have client load x509 cert and server load RPK cert,
  83139. * however, have client indicate its cert type RPK.
  83140. * Server is expected to detect the cert type mismatch then to send alert
  83141. * with "unsupported_certificate".
  83142. */
  83143. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83144. ExpectIntEQ(
  83145. test_rpk_memio_setup(
  83146. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83147. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  83148. cliCertFile, WOLFSSL_FILETYPE_PEM,
  83149. svrRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  83150. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  83151. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  83152. , 0);
  83153. /* have client tell to use RPK cert intentionally */
  83154. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  83155. certType_c[1] = -1;
  83156. typeCnt_c = 1;
  83157. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  83158. WOLFSSL_SUCCESS);
  83159. /* have client tell to accept both RPK and x509 cert */
  83160. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  83161. certType_s[1] = WOLFSSL_CERT_TYPE_RPK;
  83162. typeCnt_s = 2;
  83163. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  83164. WOLFSSL_SUCCESS);
  83165. /* have server accept to both RPK and x509 cert */
  83166. certType_c[0] = WOLFSSL_CERT_TYPE_X509;
  83167. certType_c[1] = WOLFSSL_CERT_TYPE_RPK;
  83168. typeCnt_c = 2;
  83169. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  83170. WOLFSSL_SUCCESS);
  83171. /* have server tell to use x509 cert intentionally. This will bring
  83172. * certificate type mismatch in client side.
  83173. */
  83174. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  83175. certType_s[1] = -1;
  83176. typeCnt_s = 1;
  83177. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  83178. WOLFSSL_SUCCESS);
  83179. ret = test_memio_do_handshake(ssl_c, ssl_s, 10, NULL);
  83180. /* expect server detect cert type mismatch then send Alert */
  83181. ExpectIntNE(ret, 0);
  83182. err = wolfSSL_get_error(ssl_c, ret);
  83183. ExpectIntEQ(err, WC_NO_ERR_TRACE(UNSUPPORTED_CERTIFICATE));
  83184. /* client did not load RPK cert actually, so negotiation did not happen */
  83185. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  83186. WOLFSSL_SUCCESS);
  83187. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  83188. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  83189. WOLFSSL_SUCCESS);
  83190. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  83191. /* client did not load RPK cert actually, so negotiation did not happen */
  83192. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  83193. WOLFSSL_SUCCESS);
  83194. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  83195. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  83196. WOLFSSL_SUCCESS);
  83197. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  83198. wolfSSL_free(ssl_c);
  83199. wolfSSL_CTX_free(ctx_c);
  83200. wolfSSL_free(ssl_s);
  83201. wolfSSL_CTX_free(ctx_s);
  83202. ssl_c = ssl_s = NULL;
  83203. ctx_c = ctx_s = NULL;
  83204. #if defined(WOLFSSL_ALWAYS_VERIFY_CB)
  83205. /* Both client and server load RPK cert and set certificate verify
  83206. * callbacks then start handshaking.
  83207. * Confirm both side can refer the peer's cert.
  83208. */
  83209. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83210. ExpectIntEQ(
  83211. test_rpk_memio_setup(
  83212. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83213. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  83214. clntRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  83215. svrRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  83216. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  83217. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  83218. , 0);
  83219. /* set client certificate type in client end */
  83220. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  83221. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  83222. typeCnt_c = 2;
  83223. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  83224. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  83225. typeCnt_s = 2;
  83226. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  83227. WOLFSSL_SUCCESS);
  83228. /* set server certificate type in client end */
  83229. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  83230. WOLFSSL_SUCCESS);
  83231. /* set client certificate type in server end */
  83232. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  83233. WOLFSSL_SUCCESS);
  83234. /* set server certificate type in server end */
  83235. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  83236. WOLFSSL_SUCCESS);
  83237. /* set certificate verify callback to both client and server */
  83238. isServer = 0;
  83239. wolfSSL_SetCertCbCtx(ssl_c, &isServer);
  83240. wolfSSL_set_verify(ssl_c, SSL_VERIFY_PEER, MyRpkVerifyCb);
  83241. isServer = 1;
  83242. wolfSSL_SetCertCbCtx(ssl_c, &isServer);
  83243. wolfSSL_set_verify(ssl_s, SSL_VERIFY_PEER, MyRpkVerifyCb);
  83244. ret = test_memio_do_handshake(ssl_c, ssl_s, 10, NULL);
  83245. if (ret != 0)
  83246. return TEST_FAIL;
  83247. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  83248. WOLFSSL_SUCCESS);
  83249. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83250. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  83251. WOLFSSL_SUCCESS);
  83252. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83253. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  83254. WOLFSSL_SUCCESS);
  83255. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83256. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  83257. WOLFSSL_SUCCESS);
  83258. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83259. wolfSSL_free(ssl_c);
  83260. wolfSSL_CTX_free(ctx_c);
  83261. wolfSSL_free(ssl_s);
  83262. wolfSSL_CTX_free(ctx_s);
  83263. ssl_c = ssl_s = NULL;
  83264. ctx_c = ctx_s = NULL;
  83265. #endif /* WOLFSSL_ALWAYS_VERIFY_CB */
  83266. #endif /* WOLFSSL_TLS13 */
  83267. #endif /* HAVE_RPK && (!WOLFSSL_NO_TLS12 || WOLFSSL_TLS13) */
  83268. return EXPECT_RESULT();
  83269. }
  83270. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13)
  83271. static int test_dtls13_bad_epoch_ch(void)
  83272. {
  83273. EXPECT_DECLS;
  83274. WOLFSSL_CTX *ctx_c = NULL;
  83275. WOLFSSL_CTX *ctx_s = NULL;
  83276. WOLFSSL *ssl_c = NULL;
  83277. WOLFSSL *ssl_s = NULL;
  83278. struct test_memio_ctx test_ctx;
  83279. const int EPOCH_OFF = 3;
  83280. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83281. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83282. wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0);
  83283. /* disable hrr cookie so we can later check msgsReceived.got_client_hello
  83284. * with just one message */
  83285. ExpectIntEQ(wolfSSL_disable_hrr_cookie(ssl_s), WOLFSSL_SUCCESS);
  83286. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  83287. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83288. WOLFSSL_ERROR_WANT_READ);
  83289. ExpectIntGE(test_ctx.s_len, EPOCH_OFF + 2);
  83290. /* first CH should use epoch 0x0 */
  83291. ExpectTrue((test_ctx.s_buff[EPOCH_OFF] == 0x0) &&
  83292. (test_ctx.s_buff[EPOCH_OFF + 1] == 0x0));
  83293. /* change epoch to 2 */
  83294. test_ctx.s_buff[EPOCH_OFF + 1] = 0x2;
  83295. ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  83296. ExpectIntEQ(wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83297. WOLFSSL_ERROR_WANT_READ);
  83298. ExpectIntNE(ssl_s->msgsReceived.got_client_hello, 1);
  83299. /* resend the CH */
  83300. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  83301. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  83302. wolfSSL_free(ssl_c);
  83303. wolfSSL_CTX_free(ctx_c);
  83304. wolfSSL_free(ssl_s);
  83305. wolfSSL_CTX_free(ctx_s);
  83306. return EXPECT_RESULT();
  83307. }
  83308. #else
  83309. static int test_dtls13_bad_epoch_ch(void)
  83310. {
  83311. return TEST_SKIPPED;
  83312. }
  83313. #endif
  83314. #if ((defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  83315. defined(HAVE_SESSION_TICKET) && defined(WOLFSSL_TICKET_HAVE_ID) && \
  83316. !defined(WOLFSSL_TLS13_MIDDLEBOX_COMPAT)) || \
  83317. (!defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \
  83318. !defined(NO_DES3))) || !defined(WOLFSSL_NO_TLS12)) && \
  83319. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  83320. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && !defined(NO_SESSION_CACHE)
  83321. static int test_short_session_id_ssl_ready(WOLFSSL* ssl)
  83322. {
  83323. EXPECT_DECLS;
  83324. WOLFSSL_SESSION *sess = NULL;
  83325. /* Setup the session to avoid errors */
  83326. ssl->session->timeout = -1;
  83327. ssl->session->side = WOLFSSL_CLIENT_END;
  83328. #if defined(SESSION_CERTS) || (defined(WOLFSSL_TLS13) && \
  83329. defined(HAVE_SESSION_TICKET))
  83330. ssl->session->version = ssl->version;
  83331. #endif
  83332. /* Force a short session ID to be sent */
  83333. ssl->session->sessionIDSz = 4;
  83334. #ifndef NO_SESSION_CACHE_REF
  83335. /* Allow the client cache to be used */
  83336. ssl->session->idLen = 4;
  83337. #endif
  83338. ssl->session->isSetup = 1;
  83339. ExpectNotNull(sess = wolfSSL_get_session(ssl));
  83340. ExpectIntEQ(wolfSSL_set_session(ssl, sess), WOLFSSL_SUCCESS);
  83341. return EXPECT_RESULT();
  83342. }
  83343. static int test_short_session_id(void)
  83344. {
  83345. EXPECT_DECLS;
  83346. test_ssl_cbf client_cbf;
  83347. test_ssl_cbf server_cbf;
  83348. size_t i;
  83349. struct {
  83350. method_provider client_meth;
  83351. method_provider server_meth;
  83352. const char* tls_version;
  83353. } params[] = {
  83354. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  83355. defined(HAVE_SESSION_TICKET) && defined(WOLFSSL_TICKET_HAVE_ID) && \
  83356. !defined(WOLFSSL_TLS13_MIDDLEBOX_COMPAT)
  83357. /* With WOLFSSL_TLS13_MIDDLEBOX_COMPAT a short ID will result in an error */
  83358. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLSv1_3" },
  83359. #ifdef WOLFSSL_DTLS13
  83360. { wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, "DTLSv1_3" },
  83361. #endif
  83362. #endif
  83363. #ifndef WOLFSSL_NO_TLS12
  83364. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLSv1_2" },
  83365. #ifdef WOLFSSL_DTLS
  83366. { wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, "DTLSv1_2" },
  83367. #endif
  83368. #endif
  83369. #if !defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \
  83370. !defined(NO_DES3))
  83371. { wolfTLSv1_1_client_method, wolfTLSv1_1_server_method, "TLSv1_1" },
  83372. #ifdef WOLFSSL_DTLS
  83373. { wolfDTLSv1_client_method, wolfDTLSv1_server_method, "DTLSv1_0" },
  83374. #endif
  83375. #endif
  83376. };
  83377. fprintf(stderr, "\n");
  83378. for (i = 0; i < sizeof(params)/sizeof(*params) && !EXPECT_FAIL(); i++) {
  83379. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  83380. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  83381. fprintf(stderr, "\tTesting short ID with %s\n", params[i].tls_version);
  83382. client_cbf.ssl_ready = test_short_session_id_ssl_ready;
  83383. client_cbf.method = params[i].client_meth;
  83384. server_cbf.method = params[i].server_meth;
  83385. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  83386. &server_cbf, NULL), TEST_SUCCESS);
  83387. }
  83388. return EXPECT_RESULT();
  83389. }
  83390. #else
  83391. static int test_short_session_id(void)
  83392. {
  83393. return TEST_SKIPPED;
  83394. }
  83395. #endif
  83396. #if defined(HAVE_NULL_CIPHER) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) \
  83397. && defined(WOLFSSL_DTLS13)
  83398. static byte* test_find_string(const char *string,
  83399. byte *buf, int buf_size)
  83400. {
  83401. int string_size, i;
  83402. string_size = (int)XSTRLEN(string);
  83403. for (i = 0; i < buf_size - string_size - 1; i++) {
  83404. if (XSTRCMP((char*)&buf[i], string) == 0)
  83405. return &buf[i];
  83406. }
  83407. return NULL;
  83408. }
  83409. static int test_wolfSSL_dtls13_null_cipher(void)
  83410. {
  83411. EXPECT_DECLS;
  83412. WOLFSSL_CTX *ctx_c = NULL;
  83413. WOLFSSL_CTX *ctx_s = NULL;
  83414. WOLFSSL *ssl_c = NULL;
  83415. WOLFSSL *ssl_s = NULL;
  83416. struct test_memio_ctx test_ctx;
  83417. const char *test_str = "test";
  83418. int test_str_size;
  83419. byte buf[255], *ptr = NULL;
  83420. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83421. test_ctx.c_ciphers = test_ctx.s_ciphers = "TLS13-SHA256-SHA256";
  83422. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83423. wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0);
  83424. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  83425. test_str_size = XSTRLEN("test") + 1;
  83426. ExpectIntEQ(wolfSSL_write(ssl_c, test_str, test_str_size), test_str_size);
  83427. ExpectIntEQ(wolfSSL_read(ssl_s, buf, sizeof(buf)), test_str_size);
  83428. ExpectIntEQ(XSTRCMP((char*)buf, test_str), 0);
  83429. ExpectIntEQ(wolfSSL_write(ssl_c, test_str, test_str_size), test_str_size);
  83430. /* check that the packet was sent cleartext */
  83431. ExpectNotNull(ptr = test_find_string(test_str, test_ctx.s_buff,
  83432. test_ctx.s_len));
  83433. if (ptr != NULL) {
  83434. /* modify the message */
  83435. *ptr = 'H';
  83436. /* bad messages should be ignored in DTLS */
  83437. ExpectIntEQ(wolfSSL_read(ssl_s, buf, sizeof(buf)), -1);
  83438. ExpectIntEQ(ssl_s->error, WC_NO_ERR_TRACE(WANT_READ));
  83439. }
  83440. wolfSSL_free(ssl_c);
  83441. wolfSSL_free(ssl_s);
  83442. wolfSSL_CTX_free(ctx_c);
  83443. wolfSSL_CTX_free(ctx_s);
  83444. return TEST_SUCCESS;
  83445. }
  83446. #else
  83447. static int test_wolfSSL_dtls13_null_cipher(void)
  83448. {
  83449. return TEST_SKIPPED;
  83450. }
  83451. #endif
  83452. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  83453. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  83454. !defined(SINGLE_THREADED) && !defined(NO_RSA)
  83455. static int test_dtls_msg_get_connected_port(int fd, word16 *port)
  83456. {
  83457. SOCKADDR_S peer;
  83458. XSOCKLENT len;
  83459. int ret;
  83460. XMEMSET((byte*)&peer, 0, sizeof(peer));
  83461. len = sizeof(peer);
  83462. ret = getpeername(fd, (SOCKADDR*)&peer, &len);
  83463. if (ret != 0 || len > (XSOCKLENT)sizeof(peer))
  83464. return -1;
  83465. switch (peer.ss_family) {
  83466. #ifdef WOLFSSL_IPV6
  83467. case WOLFSSL_IP6: {
  83468. *port = ntohs(((SOCKADDR_IN6*)&peer)->sin6_port);
  83469. break;
  83470. }
  83471. #endif /* WOLFSSL_IPV6 */
  83472. case WOLFSSL_IP4:
  83473. *port = ntohs(((SOCKADDR_IN*)&peer)->sin_port);
  83474. break;
  83475. default:
  83476. return -1;
  83477. }
  83478. return 0;
  83479. }
  83480. static int test_dtls_msg_from_other_peer_cb(WOLFSSL_CTX *ctx, WOLFSSL *ssl)
  83481. {
  83482. char buf[1] = {'t'};
  83483. SOCKADDR_IN_T addr;
  83484. int sock_fd;
  83485. word16 port;
  83486. int err;
  83487. (void)ssl;
  83488. (void)ctx;
  83489. if (ssl == NULL)
  83490. return -1;
  83491. err = test_dtls_msg_get_connected_port(wolfSSL_get_fd(ssl), &port);
  83492. if (err != 0)
  83493. return -1;
  83494. sock_fd = socket(AF_INET_V, SOCK_DGRAM, 0);
  83495. if (sock_fd == -1)
  83496. return -1;
  83497. build_addr(&addr, wolfSSLIP, port, 1, 0);
  83498. /* send a packet to the server. Being another socket, the kernel will ensure
  83499. * the source port will be different. */
  83500. err = (int)sendto(sock_fd, buf, sizeof(buf), 0, (SOCKADDR*)&addr,
  83501. sizeof(addr));
  83502. close(sock_fd);
  83503. if (err == -1)
  83504. return -1;
  83505. return 0;
  83506. }
  83507. /* setup a SSL session but just after the handshake send a packet to the server
  83508. * with a source address different than the one of the connected client. The I/O
  83509. * callback EmbedRecvFrom should just ignore the packet. Sending of the packet
  83510. * is done in test_dtls_msg_from_other_peer_cb */
  83511. static int test_dtls_msg_from_other_peer(void)
  83512. {
  83513. EXPECT_DECLS;
  83514. callback_functions client_cbs;
  83515. callback_functions server_cbs;
  83516. XMEMSET((byte*)&client_cbs, 0, sizeof(client_cbs));
  83517. XMEMSET((byte*)&server_cbs, 0, sizeof(server_cbs));
  83518. client_cbs.method = wolfDTLSv1_2_client_method;
  83519. server_cbs.method = wolfDTLSv1_2_server_method;
  83520. client_cbs.doUdp = 1;
  83521. server_cbs.doUdp = 1;
  83522. test_wolfSSL_client_server_nofail_ex(&client_cbs, &server_cbs,
  83523. test_dtls_msg_from_other_peer_cb);
  83524. ExpectIntEQ(client_cbs.return_code, WOLFSSL_SUCCESS);
  83525. ExpectIntEQ(server_cbs.return_code, WOLFSSL_SUCCESS);
  83526. return EXPECT_RESULT();
  83527. }
  83528. #else
  83529. static int test_dtls_msg_from_other_peer(void)
  83530. {
  83531. return TEST_SKIPPED;
  83532. }
  83533. #endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  83534. * !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  83535. * !defined(SINGLE_THREADED) && !defined(NO_RSA) */
  83536. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_IPV6) && \
  83537. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  83538. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  83539. static int test_dtls_ipv6_check(void)
  83540. {
  83541. EXPECT_DECLS;
  83542. WOLFSSL_CTX *ctx_c = NULL;
  83543. WOLFSSL_CTX *ctx_s = NULL;
  83544. WOLFSSL *ssl_c = NULL;
  83545. WOLFSSL *ssl_s = NULL;
  83546. SOCKADDR_IN fake_addr6;
  83547. int sockfd = -1;
  83548. ExpectNotNull(ctx_c = wolfSSL_CTX_new(wolfDTLSv1_2_client_method()));
  83549. ExpectNotNull(ssl_c = wolfSSL_new(ctx_c));
  83550. ExpectNotNull(ctx_s = wolfSSL_CTX_new(wolfDTLSv1_2_server_method()));
  83551. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx_s, svrKeyFile,
  83552. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  83553. ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx_s, svrCertFile,
  83554. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  83555. ExpectNotNull(ssl_s = wolfSSL_new(ctx_s));
  83556. XMEMSET((byte*)&fake_addr6, 0, sizeof(fake_addr6));
  83557. /* mimic a sockaddr_in6 struct, this way we can't test without
  83558. * WOLFSSL_IPV6 */
  83559. fake_addr6.sin_family = WOLFSSL_IP6;
  83560. ExpectIntNE(sockfd = socket(AF_INET, SOCK_DGRAM, 0), -1);
  83561. ExpectIntEQ(wolfSSL_set_fd(ssl_c, sockfd), WOLFSSL_SUCCESS);
  83562. /* can't return error here, as the peer is opaque for wolfssl library at
  83563. * this point */
  83564. ExpectIntEQ(wolfSSL_dtls_set_peer(ssl_c, &fake_addr6, sizeof(fake_addr6)),
  83565. WOLFSSL_SUCCESS);
  83566. ExpectIntNE(fcntl(sockfd, F_SETFL, O_NONBLOCK), -1);
  83567. wolfSSL_dtls_set_using_nonblock(ssl_c, 1);
  83568. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  83569. ExpectIntEQ(ssl_c->error, WC_NO_ERR_TRACE(SOCKET_ERROR_E));
  83570. ExpectIntEQ(wolfSSL_dtls_set_peer(ssl_s, &fake_addr6, sizeof(fake_addr6)),
  83571. WOLFSSL_SUCCESS);
  83572. /* reuse the socket */
  83573. ExpectIntEQ(wolfSSL_set_fd(ssl_c, sockfd), WOLFSSL_SUCCESS);
  83574. wolfSSL_dtls_set_using_nonblock(ssl_s, 1);
  83575. ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  83576. ExpectIntEQ(ssl_s->error, WC_NO_ERR_TRACE(SOCKET_ERROR_E));
  83577. if (sockfd != -1)
  83578. close(sockfd);
  83579. wolfSSL_free(ssl_c);
  83580. wolfSSL_CTX_free(ctx_c);
  83581. wolfSSL_free(ssl_s);
  83582. wolfSSL_CTX_free(ctx_s);
  83583. return EXPECT_RESULT();
  83584. }
  83585. #else
  83586. static int test_dtls_ipv6_check(void)
  83587. {
  83588. return TEST_SKIPPED;
  83589. }
  83590. #endif
  83591. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  83592. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_SECURE_RENEGOTIATION)
  83593. static WOLFSSL_SESSION* test_wolfSSL_SCR_after_resumption_session = NULL;
  83594. static void test_wolfSSL_SCR_after_resumption_ctx_ready(WOLFSSL_CTX* ctx)
  83595. {
  83596. AssertIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS);
  83597. }
  83598. static void test_wolfSSL_SCR_after_resumption_on_result(WOLFSSL* ssl)
  83599. {
  83600. if (test_wolfSSL_SCR_after_resumption_session == NULL) {
  83601. test_wolfSSL_SCR_after_resumption_session = wolfSSL_get1_session(ssl);
  83602. AssertNotNull(test_wolfSSL_SCR_after_resumption_session);
  83603. }
  83604. else {
  83605. char testMsg[] = "Message after SCR";
  83606. char msgBuf[sizeof(testMsg)];
  83607. int ret;
  83608. if (!wolfSSL_is_server(ssl)) {
  83609. AssertIntEQ(WOLFSSL_SUCCESS,
  83610. wolfSSL_set_session(ssl,
  83611. test_wolfSSL_SCR_after_resumption_session));
  83612. }
  83613. AssertIntEQ(wolfSSL_Rehandshake(ssl), WOLFSSL_SUCCESS);
  83614. AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)),
  83615. sizeof(testMsg));
  83616. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  83617. if (ret != sizeof(msgBuf)) /* Possibly APP_DATA_READY error. Retry. */
  83618. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  83619. AssertIntEQ(ret, sizeof(msgBuf));
  83620. }
  83621. }
  83622. static void test_wolfSSL_SCR_after_resumption_ssl_ready(WOLFSSL* ssl)
  83623. {
  83624. AssertIntEQ(WOLFSSL_SUCCESS,
  83625. wolfSSL_set_session(ssl, test_wolfSSL_SCR_after_resumption_session));
  83626. }
  83627. static int test_wolfSSL_SCR_after_resumption(void)
  83628. {
  83629. EXPECT_DECLS;
  83630. callback_functions func_cb_client;
  83631. callback_functions func_cb_server;
  83632. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  83633. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  83634. func_cb_client.method = wolfTLSv1_2_client_method;
  83635. func_cb_client.ctx_ready = test_wolfSSL_SCR_after_resumption_ctx_ready;
  83636. func_cb_client.on_result = test_wolfSSL_SCR_after_resumption_on_result;
  83637. func_cb_server.method = wolfTLSv1_2_server_method;
  83638. func_cb_server.ctx_ready = test_wolfSSL_SCR_after_resumption_ctx_ready;
  83639. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  83640. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  83641. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  83642. func_cb_client.ssl_ready = test_wolfSSL_SCR_after_resumption_ssl_ready;
  83643. func_cb_server.on_result = test_wolfSSL_SCR_after_resumption_on_result;
  83644. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  83645. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  83646. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  83647. wolfSSL_SESSION_free(test_wolfSSL_SCR_after_resumption_session);
  83648. return EXPECT_RESULT();
  83649. }
  83650. #else
  83651. static int test_wolfSSL_SCR_after_resumption(void)
  83652. {
  83653. return TEST_SKIPPED;
  83654. }
  83655. #endif
  83656. static int test_wolfSSL_configure_args(void)
  83657. {
  83658. EXPECT_DECLS;
  83659. #if defined(LIBWOLFSSL_CONFIGURE_ARGS) && defined(HAVE_WC_INTROSPECTION)
  83660. ExpectNotNull(wolfSSL_configure_args());
  83661. #endif
  83662. return EXPECT_RESULT();
  83663. }
  83664. static int test_dtls_no_extensions(void)
  83665. {
  83666. EXPECT_DECLS;
  83667. #if defined(WOLFSSL_DTLS) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
  83668. !defined(WOLFSSL_NO_TLS12)
  83669. WOLFSSL *ssl_s = NULL;
  83670. WOLFSSL_CTX *ctx_s = NULL;
  83671. struct test_memio_ctx test_ctx;
  83672. const byte chNoExtensions[] = {
  83673. /* Handshake type */
  83674. 0x16,
  83675. /* Version */
  83676. 0xfe, 0xff,
  83677. /* Epoch */
  83678. 0x00, 0x00,
  83679. /* Seq number */
  83680. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  83681. /* Length */
  83682. 0x00, 0x40,
  83683. /* CH type */
  83684. 0x01,
  83685. /* Length */
  83686. 0x00, 0x00, 0x34,
  83687. /* Msg Seq */
  83688. 0x00, 0x00,
  83689. /* Frag offset */
  83690. 0x00, 0x00, 0x00,
  83691. /* Frag length */
  83692. 0x00, 0x00, 0x34,
  83693. /* Version */
  83694. 0xfe, 0xff,
  83695. /* Random */
  83696. 0x62, 0xfe, 0xbc, 0xfe, 0x2b, 0xfe, 0x3f, 0xeb, 0x03, 0xc4, 0xea, 0x37,
  83697. 0xe7, 0x47, 0x7e, 0x8a, 0xd9, 0xbf, 0x77, 0x0f, 0x6c, 0xb6, 0x77, 0x0b,
  83698. 0x03, 0x3f, 0x82, 0x2b, 0x21, 0x64, 0x57, 0x1d,
  83699. /* Session Length */
  83700. 0x00,
  83701. /* Cookie Length */
  83702. 0x00,
  83703. /* CS Length */
  83704. 0x00, 0x0c,
  83705. /* CS */
  83706. 0xc0, 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x39, 0x00, 0x33,
  83707. /* Comp Meths Length */
  83708. 0x01,
  83709. /* Comp Meths */
  83710. 0x00
  83711. /* And finally... no extensions */
  83712. };
  83713. int i;
  83714. #ifdef OPENSSL_EXTRA
  83715. int repeats = 2;
  83716. #else
  83717. int repeats = 1;
  83718. #endif
  83719. for (i = 0; i < repeats; i++) {
  83720. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83721. ssl_s = NULL;
  83722. ctx_s = NULL;
  83723. ExpectIntEQ(test_memio_setup(&test_ctx, NULL, &ctx_s, NULL, &ssl_s,
  83724. NULL, wolfDTLS_server_method), 0);
  83725. XMEMCPY(test_ctx.s_buff, chNoExtensions, sizeof(chNoExtensions));
  83726. test_ctx.s_len = sizeof(chNoExtensions);
  83727. #ifdef OPENSSL_EXTRA
  83728. if (i > 0) {
  83729. ExpectIntEQ(wolfSSL_set_max_proto_version(ssl_s, DTLS1_2_VERSION),
  83730. WOLFSSL_SUCCESS);
  83731. }
  83732. #endif
  83733. ExpectIntEQ(wolfSSL_accept(ssl_s), -1);
  83734. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  83735. /* Expecting a handshake msg. Either HVR or SH. */
  83736. ExpectIntGT(test_ctx.c_len, 0);
  83737. ExpectIntEQ(test_ctx.c_buff[0], 0x16);
  83738. wolfSSL_free(ssl_s);
  83739. wolfSSL_CTX_free(ctx_s);
  83740. }
  83741. #endif
  83742. return EXPECT_RESULT();
  83743. }
  83744. static int test_tls_alert_no_server_hello(void)
  83745. {
  83746. EXPECT_DECLS;
  83747. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  83748. WOLFSSL *ssl_c = NULL;
  83749. WOLFSSL_CTX *ctx_c = NULL;
  83750. struct test_memio_ctx test_ctx;
  83751. unsigned char alert_msg[] = { 0x15, 0x03, 0x01, 0x00, 0x02, 0x02, 0x28 };
  83752. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83753. ssl_c = NULL;
  83754. ctx_c = NULL;
  83755. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
  83756. wolfTLSv1_2_client_method, NULL), 0);
  83757. XMEMCPY(test_ctx.c_buff, alert_msg, sizeof(alert_msg));
  83758. test_ctx.c_len = sizeof(alert_msg);
  83759. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  83760. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WC_NO_ERR_TRACE(FATAL_ERROR));
  83761. wolfSSL_free(ssl_c);
  83762. wolfSSL_CTX_free(ctx_c);
  83763. #endif
  83764. return EXPECT_RESULT();
  83765. }
  83766. static int test_TLSX_CA_NAMES_bad_extension(void)
  83767. {
  83768. EXPECT_DECLS;
  83769. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_TLS13) && \
  83770. !defined(NO_CERTS) && !defined(WOLFSSL_NO_CA_NAMES) && \
  83771. defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA384) && \
  83772. defined(HAVE_NULL_CIPHER)
  83773. /* This test should only fail (with BUFFER_ERROR) when we actually try to
  83774. * parse the CA Names extension. Otherwise it will return other non-related
  83775. * errors. If CA Names will be parsed in more configurations, that should
  83776. * be reflected in the macro guard above. */
  83777. WOLFSSL *ssl_c = NULL;
  83778. WOLFSSL_CTX *ctx_c = NULL;
  83779. struct test_memio_ctx test_ctx;
  83780. /* HRR + SH using TLS_DHE_PSK_WITH_NULL_SHA384 */
  83781. const byte shBadCaNamesExt[] = {
  83782. 0x16, 0x03, 0x04, 0x00, 0x3f, 0x02, 0x00, 0x00, 0x3b, 0x03, 0x03, 0xcf,
  83783. 0x21, 0xad, 0x74, 0xe5, 0x9a, 0x61, 0x11, 0xbe, 0x1d, 0x8c, 0x02, 0x1e,
  83784. 0x65, 0xb8, 0x91, 0xc2, 0xa2, 0x11, 0x16, 0x7a, 0xbb, 0x8c, 0x5e, 0x07,
  83785. 0x9e, 0x09, 0xe2, 0xc8, 0xa8, 0x33, 0x9c, 0x00, 0x13, 0x03, 0x00, 0x00,
  83786. 0x13, 0x94, 0x7e, 0x00, 0x03, 0x0b, 0xf7, 0x03, 0x00, 0x2b, 0x00, 0x02,
  83787. 0x03, 0x04, 0x00, 0x33, 0x00, 0x02, 0x00, 0x19, 0x16, 0x03, 0x03, 0x00,
  83788. 0x5c, 0x02, 0x00, 0x00, 0x3b, 0x03, 0x03, 0x03, 0xcf, 0x21, 0xad, 0x74,
  83789. 0x00, 0x00, 0x83, 0x3f, 0x3b, 0x80, 0x01, 0xac, 0x65, 0x8c, 0x19, 0x2a,
  83790. 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x02, 0x00, 0x9e, 0x09, 0x1c, 0xe8,
  83791. 0xa8, 0x09, 0x9c, 0x00, 0xc0, 0xb5, 0x00, 0x00, 0x11, 0x8f, 0x00, 0x00,
  83792. 0x03, 0x3f, 0x00, 0x0c, 0x00, 0x2b, 0x00, 0x02, 0x03, 0x04, 0x13, 0x05,
  83793. 0x00, 0x00, 0x08, 0x00, 0x00, 0x06, 0x00, 0x04, 0x00, 0x09, 0x00, 0x00,
  83794. 0x0d, 0x00, 0x00, 0x11, 0x00, 0x00, 0x0d, 0x00, 0x2f, 0x00, 0x01, 0xff,
  83795. 0xff, 0xff, 0xff, 0xfa, 0x0d, 0x00, 0x00, 0x00, 0xad, 0x02
  83796. };
  83797. const byte shBadCaNamesExt2[] = {
  83798. 0x16, 0x03, 0x04, 0x00, 0x3f, 0x02, 0x00, 0x00, 0x3b, 0x03, 0x03, 0xcf,
  83799. 0x21, 0xad, 0x74, 0xe5, 0x9a, 0x61, 0x11, 0xbe, 0x1d, 0x8c, 0x02, 0x1e,
  83800. 0x65, 0xb8, 0x91, 0xc2, 0xa2, 0x11, 0x16, 0x7a, 0xbb, 0x8c, 0x5e, 0x07,
  83801. 0x9e, 0x09, 0xe2, 0xc8, 0xa8, 0x33, 0x9c, 0x00, 0x13, 0x03, 0x00, 0x00,
  83802. 0x13, 0x94, 0x7e, 0x00, 0x03, 0x0b, 0xf7, 0x03, 0x00, 0x2b, 0x00, 0x02,
  83803. 0x03, 0x04, 0x00, 0x33, 0x00, 0x02, 0x00, 0x19, 0x16, 0x03, 0x03, 0x00,
  83804. 0x5e, 0x02, 0x00, 0x00, 0x3b, 0x03, 0x03, 0x7f, 0xd0, 0x2d, 0xea, 0x6e,
  83805. 0x53, 0xa1, 0x6a, 0xc9, 0xc8, 0x54, 0xef, 0x75, 0xe4, 0xd9, 0xc6, 0x3e,
  83806. 0x74, 0xcb, 0x30, 0x80, 0xcc, 0x83, 0x3a, 0x00, 0x00, 0x00, 0x00, 0x00,
  83807. 0x00, 0xc0, 0x5a, 0x00, 0xc0, 0xb5, 0x00, 0x00, 0x11, 0x8f, 0x00, 0x00,
  83808. 0x03, 0x03, 0x00, 0x0c, 0x00, 0x2b, 0x00, 0x02, 0x03, 0x04, 0x53, 0x25,
  83809. 0x00, 0x00, 0x08, 0x00, 0x00, 0x06, 0x00, 0x04, 0x02, 0x05, 0x00, 0x00,
  83810. 0x0d, 0x00, 0x00, 0x11, 0x00, 0x00, 0x0d, 0x00, 0x2f, 0x00, 0x06, 0x00,
  83811. 0x04, 0x00, 0x03, 0x30, 0x00, 0x13, 0x94, 0x00, 0x06, 0x00, 0x04, 0x02
  83812. };
  83813. int i = 0;
  83814. for (i = 0; i < 2; i++) {
  83815. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83816. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
  83817. wolfTLSv1_3_client_method, NULL), 0);
  83818. switch (i) {
  83819. case 0:
  83820. XMEMCPY(test_ctx.c_buff, shBadCaNamesExt,
  83821. sizeof(shBadCaNamesExt));
  83822. test_ctx.c_len = sizeof(shBadCaNamesExt);
  83823. break;
  83824. case 1:
  83825. XMEMCPY(test_ctx.c_buff, shBadCaNamesExt2,
  83826. sizeof(shBadCaNamesExt2));
  83827. test_ctx.c_len = sizeof(shBadCaNamesExt2);
  83828. break;
  83829. }
  83830. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  83831. #ifndef WOLFSSL_DISABLE_EARLY_SANITY_CHECKS
  83832. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WC_NO_ERR_TRACE(OUT_OF_ORDER_E));
  83833. #else
  83834. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WC_NO_ERR_TRACE(BUFFER_ERROR));
  83835. #endif
  83836. wolfSSL_free(ssl_c);
  83837. ssl_c = NULL;
  83838. wolfSSL_CTX_free(ctx_c);
  83839. ctx_c = NULL;
  83840. }
  83841. #endif
  83842. return EXPECT_RESULT();
  83843. }
  83844. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  83845. defined(HAVE_IO_TESTS_DEPENDENCIES)
  83846. static void test_dtls_1_0_hvr_downgrade_ctx_ready(WOLFSSL_CTX* ctx)
  83847. {
  83848. AssertIntEQ(wolfSSL_CTX_SetMinVersion(ctx, WOLFSSL_DTLSV1_2),
  83849. WOLFSSL_SUCCESS);
  83850. }
  83851. static int test_dtls_1_0_hvr_downgrade(void)
  83852. {
  83853. EXPECT_DECLS;
  83854. callback_functions func_cb_client;
  83855. callback_functions func_cb_server;
  83856. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  83857. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  83858. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  83859. func_cb_client.method = wolfDTLS_client_method;
  83860. func_cb_server.method = wolfDTLSv1_2_server_method;
  83861. func_cb_client.ctx_ready = test_dtls_1_0_hvr_downgrade_ctx_ready;
  83862. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  83863. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  83864. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  83865. return EXPECT_RESULT();
  83866. }
  83867. #else
  83868. static int test_dtls_1_0_hvr_downgrade(void)
  83869. {
  83870. EXPECT_DECLS;
  83871. return EXPECT_RESULT();
  83872. }
  83873. #endif
  83874. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12) && \
  83875. defined(HAVE_SESSION_TICKET)
  83876. static WOLFSSL_SESSION* test_session_ticket_no_id_session = NULL;
  83877. static void test_session_ticket_no_id_on_result(WOLFSSL* ssl)
  83878. {
  83879. test_session_ticket_no_id_session = wolfSSL_get1_session(ssl);
  83880. AssertNotNull(test_session_ticket_no_id_session);
  83881. }
  83882. static void test_session_ticket_no_id_ctx_ready(WOLFSSL_CTX* ctx)
  83883. {
  83884. AssertIntEQ(wolfSSL_CTX_UseSessionTicket(ctx), WOLFSSL_SUCCESS);
  83885. }
  83886. static void test_session_ticket_no_id_ssl_ready(WOLFSSL* ssl)
  83887. {
  83888. test_session_ticket_no_id_session->sessionIDSz = 0;
  83889. AssertIntEQ(WOLFSSL_SUCCESS,
  83890. wolfSSL_set_session(ssl, test_session_ticket_no_id_session));
  83891. }
  83892. static int test_session_ticket_no_id(void)
  83893. {
  83894. /* We are testing an expired (invalid crypto context in out case since the
  83895. * ctx changes) session ticket being sent with the session ID being 0
  83896. * length. */
  83897. EXPECT_DECLS;
  83898. callback_functions func_cb_client;
  83899. callback_functions func_cb_server;
  83900. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  83901. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  83902. func_cb_client.method = wolfTLSv1_2_client_method;
  83903. func_cb_client.ctx_ready = test_session_ticket_no_id_ctx_ready;
  83904. func_cb_client.on_result = test_session_ticket_no_id_on_result;
  83905. func_cb_server.method = wolfTLSv1_2_server_method;
  83906. func_cb_server.ctx_ready = test_session_ticket_no_id_ctx_ready;
  83907. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  83908. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  83909. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  83910. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  83911. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  83912. func_cb_client.method = wolfTLSv1_2_client_method;
  83913. func_cb_client.ctx_ready = test_session_ticket_no_id_ctx_ready;
  83914. func_cb_client.ssl_ready = test_session_ticket_no_id_ssl_ready;
  83915. func_cb_server.method = wolfTLSv1_2_server_method;
  83916. func_cb_server.ctx_ready = test_session_ticket_no_id_ctx_ready;
  83917. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  83918. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  83919. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  83920. wolfSSL_SESSION_free(test_session_ticket_no_id_session);
  83921. return EXPECT_RESULT();
  83922. }
  83923. #else
  83924. static int test_session_ticket_no_id(void)
  83925. {
  83926. EXPECT_DECLS;
  83927. return EXPECT_RESULT();
  83928. }
  83929. #endif
  83930. static int test_session_ticket_hs_update(void)
  83931. {
  83932. EXPECT_DECLS;
  83933. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_TLS13) && \
  83934. defined(HAVE_SESSION_TICKET) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  83935. struct test_memio_ctx test_ctx;
  83936. struct test_memio_ctx test_ctx2;
  83937. struct test_memio_ctx test_ctx3;
  83938. WOLFSSL_CTX *ctx_c = NULL;
  83939. WOLFSSL_CTX *ctx_s = NULL;
  83940. WOLFSSL *ssl_c = NULL;
  83941. WOLFSSL *ssl_c2 = NULL;
  83942. WOLFSSL *ssl_c3 = NULL;
  83943. WOLFSSL *ssl_s = NULL;
  83944. WOLFSSL *ssl_s2 = NULL;
  83945. WOLFSSL *ssl_s3 = NULL;
  83946. WOLFSSL_SESSION *sess = NULL;
  83947. byte read_data[1];
  83948. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83949. XMEMSET(&test_ctx2, 0, sizeof(test_ctx2));
  83950. XMEMSET(&test_ctx3, 0, sizeof(test_ctx3));
  83951. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83952. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  83953. /* Generate tickets */
  83954. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  83955. wolfSSL_SetLoggingPrefix("client");
  83956. /* Read the ticket msg */
  83957. ExpectIntEQ(wolfSSL_read(ssl_c, read_data, sizeof(read_data)),
  83958. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  83959. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83960. WOLFSSL_ERROR_WANT_READ);
  83961. wolfSSL_SetLoggingPrefix(NULL);
  83962. ExpectIntEQ(test_memio_setup(&test_ctx2, &ctx_c, &ctx_s, &ssl_c2, &ssl_s2,
  83963. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  83964. ExpectIntEQ(test_memio_setup(&test_ctx3, &ctx_c, &ctx_s, &ssl_c3, &ssl_s3,
  83965. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  83966. ExpectNotNull(sess = wolfSSL_get1_session(ssl_c));
  83967. ExpectIntEQ(wolfSSL_set_session(ssl_c2, sess), WOLFSSL_SUCCESS);
  83968. ExpectIntEQ(wolfSSL_set_session(ssl_c3, sess), WOLFSSL_SUCCESS);
  83969. wolfSSL_SetLoggingPrefix("client");
  83970. /* Exchange initial flights for the second connection */
  83971. ExpectIntEQ(wolfSSL_connect(ssl_c2), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  83972. ExpectIntEQ(wolfSSL_get_error(ssl_c2, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83973. WOLFSSL_ERROR_WANT_READ);
  83974. wolfSSL_SetLoggingPrefix(NULL);
  83975. wolfSSL_SetLoggingPrefix("server");
  83976. ExpectIntEQ(wolfSSL_accept(ssl_s2), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  83977. ExpectIntEQ(wolfSSL_get_error(ssl_s2, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83978. WOLFSSL_ERROR_WANT_READ);
  83979. wolfSSL_SetLoggingPrefix(NULL);
  83980. /* Complete third connection so that new tickets are exchanged */
  83981. ExpectIntEQ(test_memio_do_handshake(ssl_c3, ssl_s3, 10, NULL), 0);
  83982. /* Read the ticket msg */
  83983. wolfSSL_SetLoggingPrefix("client");
  83984. ExpectIntEQ(wolfSSL_read(ssl_c3, read_data, sizeof(read_data)),
  83985. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  83986. ExpectIntEQ(wolfSSL_get_error(ssl_c3, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83987. WOLFSSL_ERROR_WANT_READ);
  83988. wolfSSL_SetLoggingPrefix(NULL);
  83989. /* Complete second connection */
  83990. ExpectIntEQ(test_memio_do_handshake(ssl_c2, ssl_s2, 10, NULL), 0);
  83991. ExpectIntEQ(wolfSSL_session_reused(ssl_c2), 1);
  83992. ExpectIntEQ(wolfSSL_session_reused(ssl_c3), 1);
  83993. wolfSSL_free(ssl_c);
  83994. wolfSSL_free(ssl_c2);
  83995. wolfSSL_free(ssl_c3);
  83996. wolfSSL_free(ssl_s);
  83997. wolfSSL_free(ssl_s2);
  83998. wolfSSL_free(ssl_s3);
  83999. wolfSSL_CTX_free(ctx_c);
  84000. wolfSSL_CTX_free(ctx_s);
  84001. wolfSSL_SESSION_free(sess);
  84002. #endif
  84003. return EXPECT_RESULT();
  84004. }
  84005. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  84006. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_SECURE_RENEGOTIATION)
  84007. static void test_dtls_downgrade_scr_server_ctx_ready_server(WOLFSSL_CTX* ctx)
  84008. {
  84009. AssertIntEQ(wolfSSL_CTX_SetMinVersion(ctx, WOLFSSL_DTLSV1_2),
  84010. WOLFSSL_SUCCESS);
  84011. AssertIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS);
  84012. }
  84013. static void test_dtls_downgrade_scr_server_ctx_ready(WOLFSSL_CTX* ctx)
  84014. {
  84015. AssertIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS);
  84016. }
  84017. static void test_dtls_downgrade_scr_server_on_result(WOLFSSL* ssl)
  84018. {
  84019. char testMsg[] = "Message after SCR";
  84020. char msgBuf[sizeof(testMsg)];
  84021. if (wolfSSL_is_server(ssl)) {
  84022. AssertIntEQ(wolfSSL_Rehandshake(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  84023. AssertIntEQ(wolfSSL_get_error(ssl, -1), WC_NO_ERR_TRACE(APP_DATA_READY));
  84024. AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf));
  84025. AssertIntEQ(wolfSSL_Rehandshake(ssl), WOLFSSL_SUCCESS);
  84026. AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)),
  84027. sizeof(testMsg));
  84028. }
  84029. else {
  84030. AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)),
  84031. sizeof(testMsg));
  84032. AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf));
  84033. }
  84034. }
  84035. static int test_dtls_downgrade_scr_server(void)
  84036. {
  84037. EXPECT_DECLS;
  84038. callback_functions func_cb_client;
  84039. callback_functions func_cb_server;
  84040. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  84041. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  84042. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  84043. func_cb_client.method = wolfDTLSv1_2_client_method;
  84044. func_cb_server.method = wolfDTLS_server_method;
  84045. func_cb_client.ctx_ready = test_dtls_downgrade_scr_server_ctx_ready;
  84046. func_cb_server.ctx_ready = test_dtls_downgrade_scr_server_ctx_ready_server;
  84047. func_cb_client.on_result = test_dtls_downgrade_scr_server_on_result;
  84048. func_cb_server.on_result = test_dtls_downgrade_scr_server_on_result;
  84049. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  84050. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  84051. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  84052. return EXPECT_RESULT();
  84053. }
  84054. #else
  84055. static int test_dtls_downgrade_scr_server(void)
  84056. {
  84057. EXPECT_DECLS;
  84058. return EXPECT_RESULT();
  84059. }
  84060. #endif
  84061. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  84062. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_SECURE_RENEGOTIATION)
  84063. static void test_dtls_downgrade_scr_ctx_ready(WOLFSSL_CTX* ctx)
  84064. {
  84065. AssertIntEQ(wolfSSL_CTX_SetMinVersion(ctx, WOLFSSL_DTLSV1_2),
  84066. WOLFSSL_SUCCESS);
  84067. AssertIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS);
  84068. }
  84069. static void test_dtls_downgrade_scr_on_result(WOLFSSL* ssl)
  84070. {
  84071. char testMsg[] = "Message after SCR";
  84072. char msgBuf[sizeof(testMsg)];
  84073. if (wolfSSL_is_server(ssl)) {
  84074. AssertIntEQ(wolfSSL_Rehandshake(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  84075. AssertIntEQ(wolfSSL_get_error(ssl, -1), WC_NO_ERR_TRACE(APP_DATA_READY));
  84076. AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf));
  84077. AssertIntEQ(wolfSSL_Rehandshake(ssl), WOLFSSL_SUCCESS);
  84078. AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)),
  84079. sizeof(testMsg));
  84080. }
  84081. else {
  84082. AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)),
  84083. sizeof(testMsg));
  84084. AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf));
  84085. }
  84086. }
  84087. static int test_dtls_downgrade_scr(void)
  84088. {
  84089. EXPECT_DECLS;
  84090. callback_functions func_cb_client;
  84091. callback_functions func_cb_server;
  84092. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  84093. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  84094. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  84095. func_cb_client.method = wolfDTLS_client_method;
  84096. func_cb_server.method = wolfDTLSv1_2_server_method;
  84097. func_cb_client.ctx_ready = test_dtls_downgrade_scr_ctx_ready;
  84098. func_cb_client.on_result = test_dtls_downgrade_scr_on_result;
  84099. func_cb_server.on_result = test_dtls_downgrade_scr_on_result;
  84100. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  84101. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  84102. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  84103. return EXPECT_RESULT();
  84104. }
  84105. #else
  84106. static int test_dtls_downgrade_scr(void)
  84107. {
  84108. EXPECT_DECLS;
  84109. return EXPECT_RESULT();
  84110. }
  84111. #endif
  84112. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \
  84113. && !defined(WOLFSSL_NO_TLS12)
  84114. static int test_dtls_client_hello_timeout_downgrade_read_cb(WOLFSSL *ssl,
  84115. char *data, int sz, void *ctx)
  84116. {
  84117. static int call_counter = 0;
  84118. call_counter++;
  84119. (void)ssl;
  84120. (void)data;
  84121. (void)sz;
  84122. (void)ctx;
  84123. switch (call_counter) {
  84124. case 1:
  84125. case 2:
  84126. return WOLFSSL_CBIO_ERR_TIMEOUT;
  84127. case 3:
  84128. return WOLFSSL_CBIO_ERR_WANT_READ;
  84129. default:
  84130. AssertIntLE(call_counter, 3);
  84131. return -1;
  84132. }
  84133. }
  84134. #endif
  84135. /* Make sure we don't send acks before getting a server hello */
  84136. static int test_dtls_client_hello_timeout_downgrade(void)
  84137. {
  84138. EXPECT_DECLS;
  84139. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \
  84140. && !defined(WOLFSSL_NO_TLS12)
  84141. WOLFSSL_CTX *ctx_c = NULL;
  84142. WOLFSSL_CTX *ctx_s = NULL;
  84143. WOLFSSL *ssl_c = NULL;
  84144. WOLFSSL *ssl_s = NULL;
  84145. struct test_memio_ctx test_ctx;
  84146. DtlsRecordLayerHeader* dtlsRH;
  84147. size_t len;
  84148. byte sequence_number[8];
  84149. int i;
  84150. for (i = 0; i < 2; i++) {
  84151. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84152. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84153. wolfDTLS_client_method, wolfDTLSv1_2_server_method), 0);
  84154. if (i == 0) {
  84155. /* First time simulate timeout in IO layer */
  84156. /* CH1 */
  84157. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84158. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84159. /* HVR */
  84160. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84161. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84162. /* CH2 */
  84163. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84164. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84165. /* SH flight */
  84166. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84167. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84168. /* Drop the SH */
  84169. dtlsRH = (DtlsRecordLayerHeader*)(test_ctx.c_buff);
  84170. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  84171. XMEMMOVE(test_ctx.c_buff, test_ctx.c_buff +
  84172. sizeof(DtlsRecordLayerHeader) + len, test_ctx.c_len -
  84173. (sizeof(DtlsRecordLayerHeader) + len));
  84174. test_ctx.c_len -= sizeof(DtlsRecordLayerHeader) + len;
  84175. /* Read the remainder of the flight */
  84176. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84177. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84178. wolfSSL_SSLSetIORecv(ssl_c,
  84179. test_dtls_client_hello_timeout_downgrade_read_cb);
  84180. /* CH3 */
  84181. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84182. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84183. wolfSSL_SSLSetIORecv(ssl_c, test_memio_read_cb);
  84184. }
  84185. else {
  84186. /* Second time call wolfSSL_dtls_got_timeout */
  84187. /* CH1 */
  84188. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84189. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84190. /* HVR */
  84191. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84192. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84193. /* CH2 */
  84194. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84195. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84196. /* SH flight */
  84197. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84198. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84199. /* Drop the SH */
  84200. dtlsRH = (DtlsRecordLayerHeader*)(test_ctx.c_buff);
  84201. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  84202. XMEMMOVE(test_ctx.c_buff, test_ctx.c_buff +
  84203. sizeof(DtlsRecordLayerHeader) + len, test_ctx.c_len -
  84204. (sizeof(DtlsRecordLayerHeader) + len));
  84205. test_ctx.c_len -= sizeof(DtlsRecordLayerHeader) + len;
  84206. /* Read the remainder of the flight */
  84207. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84208. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84209. /* Quick timeout should be set as we received at least one msg */
  84210. ExpectIntEQ(wolfSSL_dtls13_use_quick_timeout(ssl_c), 1);
  84211. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  84212. /* Quick timeout should be cleared after a quick timeout */
  84213. /* CH3 */
  84214. ExpectIntEQ(wolfSSL_dtls13_use_quick_timeout(ssl_c), 0);
  84215. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  84216. }
  84217. /* Parse out to make sure we got exactly one ClientHello message */
  84218. XMEMSET(&sequence_number, 0, sizeof(sequence_number));
  84219. /* Second ClientHello after HVR */
  84220. sequence_number[7] = 2;
  84221. dtlsRH = (DtlsRecordLayerHeader*)test_ctx.s_buff;
  84222. ExpectIntEQ(dtlsRH->type, handshake);
  84223. ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR);
  84224. ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR);
  84225. ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number,
  84226. sizeof(sequence_number)), 0);
  84227. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  84228. ExpectIntEQ(sizeof(DtlsRecordLayerHeader) + len, test_ctx.s_len);
  84229. /* Connection should be able to continue */
  84230. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  84231. wolfSSL_free(ssl_c);
  84232. wolfSSL_free(ssl_s);
  84233. wolfSSL_CTX_free(ctx_c);
  84234. wolfSSL_CTX_free(ctx_s);
  84235. ssl_c = NULL;
  84236. ssl_s = NULL;
  84237. ctx_c = NULL;
  84238. ctx_s = NULL;
  84239. if (!EXPECT_SUCCESS())
  84240. break;
  84241. }
  84242. #endif
  84243. return EXPECT_RESULT();
  84244. }
  84245. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13)
  84246. static int test_dtls_client_hello_timeout_read_cb(WOLFSSL *ssl, char *data,
  84247. int sz, void *ctx)
  84248. {
  84249. static int call_counter = 0;
  84250. call_counter++;
  84251. (void)ssl;
  84252. (void)data;
  84253. (void)sz;
  84254. (void)ctx;
  84255. switch (call_counter) {
  84256. case 1:
  84257. return WOLFSSL_CBIO_ERR_TIMEOUT;
  84258. case 2:
  84259. return WOLFSSL_CBIO_ERR_WANT_READ;
  84260. default:
  84261. AssertIntLE(call_counter, 2);
  84262. return -1;
  84263. }
  84264. }
  84265. #endif
  84266. /* Make sure we don't send acks before getting a server hello */
  84267. static int test_dtls_client_hello_timeout(void)
  84268. {
  84269. EXPECT_DECLS;
  84270. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13)
  84271. WOLFSSL *ssl_c = NULL;
  84272. WOLFSSL_CTX *ctx_c = NULL;
  84273. struct test_memio_ctx test_ctx;
  84274. DtlsRecordLayerHeader* dtlsRH;
  84275. size_t idx;
  84276. size_t len;
  84277. byte sequence_number[8];
  84278. int i;
  84279. for (i = 0; i < 2; i++) {
  84280. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84281. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
  84282. wolfDTLSv1_3_client_method, NULL), 0);
  84283. if (i == 0) {
  84284. /* First time simulate timeout in IO layer */
  84285. wolfSSL_SSLSetIORecv(ssl_c, test_dtls_client_hello_timeout_read_cb);
  84286. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  84287. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84288. }
  84289. else {
  84290. /* Second time call wolfSSL_dtls_got_timeout */
  84291. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  84292. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84293. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  84294. }
  84295. /* Parse out to make sure we got exactly two ClientHello messages */
  84296. idx = 0;
  84297. XMEMSET(&sequence_number, 0, sizeof(sequence_number));
  84298. /* First ClientHello */
  84299. dtlsRH = (DtlsRecordLayerHeader*)(test_ctx.s_buff + idx);
  84300. ExpectIntEQ(dtlsRH->type, handshake);
  84301. ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR);
  84302. ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR);
  84303. ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number,
  84304. sizeof(sequence_number)), 0);
  84305. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  84306. ExpectIntLT(idx + sizeof(DtlsRecordLayerHeader) + len, test_ctx.s_len);
  84307. idx += sizeof(DtlsRecordLayerHeader) + len;
  84308. /* Second ClientHello */
  84309. sequence_number[7] = 1;
  84310. dtlsRH = (DtlsRecordLayerHeader*)(test_ctx.s_buff + idx);
  84311. ExpectIntEQ(dtlsRH->type, handshake);
  84312. ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR);
  84313. ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR);
  84314. ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number,
  84315. sizeof(sequence_number)), 0);
  84316. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  84317. ExpectIntEQ(idx + sizeof(DtlsRecordLayerHeader) + len, test_ctx.s_len);
  84318. wolfSSL_free(ssl_c);
  84319. wolfSSL_CTX_free(ctx_c);
  84320. ssl_c = NULL;
  84321. ctx_c = NULL;
  84322. if (!EXPECT_SUCCESS())
  84323. break;
  84324. }
  84325. #endif
  84326. return EXPECT_RESULT();
  84327. }
  84328. /* DTLS test when dropping the changed cipher spec message */
  84329. static int test_dtls_dropped_ccs(void)
  84330. {
  84331. EXPECT_DECLS;
  84332. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) \
  84333. && !defined(WOLFSSL_NO_TLS12)
  84334. WOLFSSL_CTX *ctx_c = NULL;
  84335. WOLFSSL_CTX *ctx_s = NULL;
  84336. WOLFSSL *ssl_c = NULL;
  84337. WOLFSSL *ssl_s = NULL;
  84338. struct test_memio_ctx test_ctx;
  84339. DtlsRecordLayerHeader* dtlsRH;
  84340. size_t len;
  84341. byte data[1];
  84342. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84343. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84344. wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  84345. /* CH1 */
  84346. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84347. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84348. /* HVR */
  84349. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84350. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84351. /* CH2 */
  84352. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84353. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84354. /* Server first flight */
  84355. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84356. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84357. /* Client flight */
  84358. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84359. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84360. /* Server ccs + finished */
  84361. ExpectIntEQ(wolfSSL_negotiate(ssl_s), 1);
  84362. /* Drop the ccs */
  84363. dtlsRH = (DtlsRecordLayerHeader*)test_ctx.c_buff;
  84364. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  84365. ExpectIntEQ(len, 1);
  84366. ExpectIntEQ(dtlsRH->type, change_cipher_spec);
  84367. if (EXPECT_SUCCESS()) {
  84368. XMEMMOVE(test_ctx.c_buff, test_ctx.c_buff +
  84369. sizeof(DtlsRecordLayerHeader) + len, test_ctx.c_len -
  84370. (sizeof(DtlsRecordLayerHeader) + len));
  84371. }
  84372. test_ctx.c_len -= sizeof(DtlsRecordLayerHeader) + len;
  84373. /* Client rtx flight */
  84374. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84375. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84376. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  84377. /* Server ccs + finished rtx */
  84378. ExpectIntEQ(wolfSSL_read(ssl_s, data, sizeof(data)), -1);
  84379. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84380. /* Client processes finished */
  84381. ExpectIntEQ(wolfSSL_negotiate(ssl_c), 1);
  84382. wolfSSL_free(ssl_c);
  84383. wolfSSL_free(ssl_s);
  84384. wolfSSL_CTX_free(ctx_c);
  84385. wolfSSL_CTX_free(ctx_s);
  84386. #endif
  84387. return EXPECT_RESULT();
  84388. }
  84389. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) \
  84390. && !defined(WOLFSSL_NO_TLS12)
  84391. static int test_dtls_seq_num_downgrade_check_num(byte* ioBuf, int ioBufLen,
  84392. byte seq_num)
  84393. {
  84394. EXPECT_DECLS;
  84395. DtlsRecordLayerHeader* dtlsRH;
  84396. byte sequence_number[8];
  84397. XMEMSET(&sequence_number, 0, sizeof(sequence_number));
  84398. ExpectIntGE(ioBufLen, sizeof(*dtlsRH));
  84399. dtlsRH = (DtlsRecordLayerHeader*)ioBuf;
  84400. ExpectIntEQ(dtlsRH->type, handshake);
  84401. ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR);
  84402. ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR);
  84403. sequence_number[7] = seq_num;
  84404. ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number,
  84405. sizeof(sequence_number)), 0);
  84406. return EXPECT_RESULT();
  84407. }
  84408. #endif
  84409. /*
  84410. * Make sure that we send the correct sequence number after a HelloVerifyRequest
  84411. * and after a HelloRetryRequest. This is testing the server side as it is
  84412. * operating statelessly and should copy the sequence number of the ClientHello.
  84413. */
  84414. static int test_dtls_seq_num_downgrade(void)
  84415. {
  84416. EXPECT_DECLS;
  84417. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) \
  84418. && !defined(WOLFSSL_NO_TLS12)
  84419. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  84420. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  84421. struct test_memio_ctx test_ctx;
  84422. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84423. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84424. wolfDTLSv1_2_client_method, wolfDTLS_server_method), 0);
  84425. /* CH1 */
  84426. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84427. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84428. ExpectIntEQ(test_dtls_seq_num_downgrade_check_num(test_ctx.s_buff,
  84429. test_ctx.s_len, 0), TEST_SUCCESS);
  84430. /* HVR */
  84431. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84432. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84433. ExpectIntEQ(test_dtls_seq_num_downgrade_check_num(test_ctx.c_buff,
  84434. test_ctx.c_len, 0), TEST_SUCCESS);
  84435. /* CH2 */
  84436. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84437. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84438. ExpectIntEQ(test_dtls_seq_num_downgrade_check_num(test_ctx.s_buff,
  84439. test_ctx.s_len, 1), TEST_SUCCESS);
  84440. /* Server first flight */
  84441. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84442. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84443. ExpectIntEQ(test_dtls_seq_num_downgrade_check_num(test_ctx.c_buff,
  84444. test_ctx.c_len, 1), TEST_SUCCESS);
  84445. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  84446. wolfSSL_free(ssl_c);
  84447. wolfSSL_CTX_free(ctx_c);
  84448. wolfSSL_free(ssl_s);
  84449. wolfSSL_CTX_free(ctx_s);
  84450. #endif
  84451. return EXPECT_RESULT();
  84452. }
  84453. /**
  84454. * Make sure we don't send RSA Signature Hash Algorithms in the
  84455. * CertificateRequest when we don't have any such ciphers set.
  84456. * @return EXPECT_RESULT()
  84457. */
  84458. static int test_certreq_sighash_algos(void)
  84459. {
  84460. EXPECT_DECLS;
  84461. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
  84462. !defined(WOLFSSL_MAX_STRENGTH) && defined(HAVE_ECC) && \
  84463. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256) && \
  84464. defined(HAVE_AES_CBC) && !defined(WOLFSSL_NO_TLS12)
  84465. WOLFSSL_CTX *ctx_c = NULL;
  84466. WOLFSSL_CTX *ctx_s = NULL;
  84467. WOLFSSL *ssl_c = NULL;
  84468. WOLFSSL *ssl_s = NULL;
  84469. struct test_memio_ctx test_ctx;
  84470. int idx = 0;
  84471. int maxIdx = 0;
  84472. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84473. test_ctx.c_ciphers = test_ctx.s_ciphers =
  84474. "ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA384";
  84475. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84476. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  84477. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx_c,
  84478. "./certs/ca-ecc-cert.pem", NULL), WOLFSSL_SUCCESS);
  84479. wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_PEER, NULL);
  84480. ExpectIntEQ(wolfSSL_use_PrivateKey_file(ssl_s, "./certs/ecc-key.pem",
  84481. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  84482. ExpectIntEQ(wolfSSL_use_certificate_file(ssl_s, "./certs/server-ecc.pem",
  84483. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  84484. ExpectIntEQ(wolfSSL_connect(ssl_c), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  84485. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  84486. WOLFSSL_ERROR_WANT_READ);
  84487. ExpectIntEQ(wolfSSL_accept(ssl_s), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  84488. ExpectIntEQ(wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  84489. WOLFSSL_ERROR_WANT_READ);
  84490. /* Find the CertificateRequest message */
  84491. for (idx = 0; idx < test_ctx.c_len && EXPECT_SUCCESS();) {
  84492. word16 len;
  84493. ExpectIntEQ(test_ctx.c_buff[idx++], handshake);
  84494. ExpectIntEQ(test_ctx.c_buff[idx++], SSLv3_MAJOR);
  84495. ExpectIntEQ(test_ctx.c_buff[idx++], TLSv1_2_MINOR);
  84496. ato16(test_ctx.c_buff + idx, &len);
  84497. idx += OPAQUE16_LEN;
  84498. if (test_ctx.c_buff[idx] == certificate_request) {
  84499. idx++;
  84500. /* length */
  84501. idx += OPAQUE24_LEN;
  84502. /* cert types */
  84503. idx += 1 + test_ctx.c_buff[idx];
  84504. /* Sig algos */
  84505. ato16(test_ctx.c_buff + idx, &len);
  84506. idx += OPAQUE16_LEN;
  84507. maxIdx = idx + (int)len;
  84508. for (; idx < maxIdx && EXPECT_SUCCESS(); idx += OPAQUE16_LEN) {
  84509. if (test_ctx.c_buff[idx+1] == ED25519_SA_MINOR ||
  84510. test_ctx.c_buff[idx+1] == ED448_SA_MINOR)
  84511. ExpectIntEQ(test_ctx.c_buff[idx], NEW_SA_MAJOR);
  84512. else
  84513. ExpectIntEQ(test_ctx.c_buff[idx+1], ecc_dsa_sa_algo);
  84514. }
  84515. break;
  84516. }
  84517. else {
  84518. idx += (int)len;
  84519. }
  84520. }
  84521. ExpectIntLT(idx, test_ctx.c_len);
  84522. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  84523. wolfSSL_free(ssl_c);
  84524. wolfSSL_free(ssl_s);
  84525. wolfSSL_CTX_free(ctx_c);
  84526. wolfSSL_CTX_free(ctx_s);
  84527. #endif
  84528. return EXPECT_RESULT();
  84529. }
  84530. #if defined(HAVE_CRL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  84531. !defined(WOLFSSL_CRL_ALLOW_MISSING_CDP)
  84532. static int test_revoked_loaded_int_cert_ctx_ready1(WOLFSSL_CTX* ctx)
  84533. {
  84534. EXPECT_DECLS;
  84535. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, myVerify);
  84536. myVerifyAction = VERIFY_USE_PREVERFIY;
  84537. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  84538. "./certs/ca-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  84539. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  84540. "./certs/intermediate/ca-int-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  84541. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL),
  84542. WOLFSSL_SUCCESS);
  84543. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  84544. "./certs/crl/extra-crls/ca-int-cert-revoked.pem",
  84545. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  84546. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  84547. "./certs/crl/ca-int.pem",
  84548. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  84549. return EXPECT_RESULT();
  84550. }
  84551. static int test_revoked_loaded_int_cert_ctx_ready2(WOLFSSL_CTX* ctx)
  84552. {
  84553. EXPECT_DECLS;
  84554. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, myVerify);
  84555. myVerifyAction = VERIFY_USE_PREVERFIY;
  84556. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  84557. "./certs/ca-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  84558. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  84559. "./certs/intermediate/ca-int-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  84560. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  84561. "./certs/intermediate/ca-int2-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  84562. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL),
  84563. WOLFSSL_SUCCESS);
  84564. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  84565. "./certs/crl/ca-int2.pem",
  84566. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  84567. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  84568. "./certs/crl/extra-crls/ca-int-cert-revoked.pem",
  84569. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  84570. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  84571. "./certs/crl/ca-int.pem",
  84572. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  84573. return EXPECT_RESULT();
  84574. }
  84575. static int test_revoked_loaded_int_cert_ctx_ready3_crl_missing_cb(int ret,
  84576. WOLFSSL_CRL* crl, WOLFSSL_CERT_MANAGER* cm, void* ctx)
  84577. {
  84578. (void)crl;
  84579. (void)cm;
  84580. (void)ctx;
  84581. if (ret == WC_NO_ERR_TRACE(CRL_MISSING))
  84582. return 1;
  84583. return 0;
  84584. }
  84585. /* Here we are allowing missing CRL's but want to error out when its revoked */
  84586. static int test_revoked_loaded_int_cert_ctx_ready3(WOLFSSL_CTX* ctx)
  84587. {
  84588. EXPECT_DECLS;
  84589. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, myVerify);
  84590. myVerifyAction = VERIFY_USE_PREVERFIY;
  84591. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  84592. "./certs/ca-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  84593. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  84594. "./certs/intermediate/ca-int-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  84595. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  84596. "./certs/intermediate/ca-int2-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  84597. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL),
  84598. WOLFSSL_SUCCESS);
  84599. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  84600. "./certs/crl/extra-crls/ca-int-cert-revoked.pem",
  84601. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  84602. ExpectIntEQ(wolfSSL_CTX_SetCRL_ErrorCb(ctx,
  84603. test_revoked_loaded_int_cert_ctx_ready3_crl_missing_cb, NULL),
  84604. WOLFSSL_SUCCESS);
  84605. return EXPECT_RESULT();
  84606. }
  84607. #endif
  84608. static int test_revoked_loaded_int_cert(void)
  84609. {
  84610. EXPECT_DECLS;
  84611. #if defined(HAVE_CRL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  84612. !defined(WOLFSSL_CRL_ALLOW_MISSING_CDP)
  84613. test_ssl_cbf client_cbf;
  84614. test_ssl_cbf server_cbf;
  84615. struct {
  84616. const char* certPemFile;
  84617. const char* keyPemFile;
  84618. ctx_cb client_ctx_ready;
  84619. } test_params[] = {
  84620. {"./certs/intermediate/ca-int2-cert.pem",
  84621. "./certs/intermediate/ca-int2-key.pem",
  84622. test_revoked_loaded_int_cert_ctx_ready1},
  84623. {"./certs/intermediate/server-chain.pem",
  84624. "./certs/server-key.pem", test_revoked_loaded_int_cert_ctx_ready2},
  84625. {"./certs/intermediate/server-chain-short.pem",
  84626. "./certs/server-key.pem", test_revoked_loaded_int_cert_ctx_ready2},
  84627. {"./certs/intermediate/server-chain-short.pem",
  84628. "./certs/server-key.pem", test_revoked_loaded_int_cert_ctx_ready3},
  84629. };
  84630. size_t i;
  84631. printf("\n");
  84632. for (i = 0; i < XELEM_CNT(test_params); i++) {
  84633. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  84634. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  84635. printf("\tTesting with %s...\n", test_params[i].certPemFile);
  84636. server_cbf.certPemFile = test_params[i].certPemFile;
  84637. server_cbf.keyPemFile = test_params[i].keyPemFile;
  84638. client_cbf.ctx_ready = test_params[i].client_ctx_ready;
  84639. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  84640. &server_cbf, NULL), -1001);
  84641. ExpectIntEQ(client_cbf.last_err, WC_NO_ERR_TRACE(CRL_CERT_REVOKED));
  84642. ExpectIntEQ(server_cbf.last_err, WC_NO_ERR_TRACE(FATAL_ERROR));
  84643. if (!EXPECT_SUCCESS())
  84644. break;
  84645. printf("\t%s passed\n", test_params[i].certPemFile);
  84646. }
  84647. #endif
  84648. return EXPECT_RESULT();
  84649. }
  84650. static int test_dtls13_frag_ch_pq(void)
  84651. {
  84652. EXPECT_DECLS;
  84653. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \
  84654. && defined(WOLFSSL_DTLS_CH_FRAG) && defined(HAVE_LIBOQS)
  84655. WOLFSSL_CTX *ctx_c = NULL;
  84656. WOLFSSL_CTX *ctx_s = NULL;
  84657. WOLFSSL *ssl_c = NULL;
  84658. WOLFSSL *ssl_s = NULL;
  84659. struct test_memio_ctx test_ctx;
  84660. const char *test_str = "test";
  84661. int test_str_size;
  84662. byte buf[255];
  84663. int group = WOLFSSL_KYBER_LEVEL5;
  84664. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84665. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84666. wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0);
  84667. /* Add in a large post-quantum key share to make the CH long. */
  84668. ExpectIntEQ(wolfSSL_set_groups(ssl_c, &group, 1), WOLFSSL_SUCCESS);
  84669. ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, group), WOLFSSL_SUCCESS);
  84670. ExpectIntEQ(wolfSSL_dtls13_allow_ch_frag(ssl_s, 1), WOLFSSL_SUCCESS);
  84671. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  84672. ExpectStrEQ(wolfSSL_get_curve_name(ssl_c), "KYBER_LEVEL5");
  84673. ExpectStrEQ(wolfSSL_get_curve_name(ssl_s), "KYBER_LEVEL5");
  84674. test_str_size = XSTRLEN("test") + 1;
  84675. ExpectIntEQ(wolfSSL_write(ssl_c, test_str, test_str_size), test_str_size);
  84676. ExpectIntEQ(wolfSSL_read(ssl_s, buf, sizeof(buf)), test_str_size);
  84677. ExpectIntEQ(XSTRCMP((char*)buf, test_str), 0);
  84678. ExpectIntEQ(wolfSSL_write(ssl_c, test_str, test_str_size), test_str_size);
  84679. wolfSSL_free(ssl_c);
  84680. wolfSSL_free(ssl_s);
  84681. wolfSSL_CTX_free(ctx_c);
  84682. wolfSSL_CTX_free(ctx_s);
  84683. #endif
  84684. return EXPECT_RESULT();
  84685. }
  84686. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) \
  84687. && defined(WOLFSSL_DTLS_MTU) && defined(WOLFSSL_DTLS_CH_FRAG)
  84688. static int test_dtls_frag_ch_count_records(byte* b, int len)
  84689. {
  84690. DtlsRecordLayerHeader* dtlsRH;
  84691. int records = 0;
  84692. size_t recordLen;
  84693. while (len > 0) {
  84694. records++;
  84695. dtlsRH = (DtlsRecordLayerHeader*)b;
  84696. recordLen = (dtlsRH->length[0] << 8) | dtlsRH->length[1];
  84697. b += sizeof(DtlsRecordLayerHeader) + recordLen;
  84698. len -= sizeof(DtlsRecordLayerHeader) + recordLen;
  84699. }
  84700. return records;
  84701. }
  84702. #endif
  84703. static int test_dtls_frag_ch(void)
  84704. {
  84705. EXPECT_DECLS;
  84706. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \
  84707. && defined(WOLFSSL_DTLS_MTU) && defined(WOLFSSL_DTLS_CH_FRAG)
  84708. WOLFSSL_CTX *ctx_c = NULL;
  84709. WOLFSSL_CTX *ctx_s = NULL;
  84710. WOLFSSL *ssl_c = NULL;
  84711. WOLFSSL *ssl_s = NULL;
  84712. struct test_memio_ctx test_ctx;
  84713. static unsigned int DUMMY_MTU = 256;
  84714. unsigned char four_frag_CH[] = {
  84715. 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  84716. 0xda, 0x01, 0x00, 0x02, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  84717. 0xce, 0xfe, 0xfd, 0xf3, 0x94, 0x01, 0x33, 0x2c, 0xcf, 0x2c, 0x47, 0xb1,
  84718. 0xe5, 0xa1, 0x7b, 0x19, 0x3e, 0xac, 0x68, 0xdd, 0xe6, 0x17, 0x6b, 0x85,
  84719. 0xad, 0x5f, 0xfc, 0x7f, 0x6e, 0xf0, 0xb9, 0xe0, 0x2e, 0xca, 0x47, 0x00,
  84720. 0x00, 0x00, 0x36, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0,
  84721. 0x2b, 0xc0, 0x30, 0xc0, 0x2f, 0x00, 0x9f, 0x00, 0x9e, 0xcc, 0xa9, 0xcc,
  84722. 0xa8, 0xcc, 0xaa, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x28, 0xc0, 0x24, 0xc0,
  84723. 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x6b, 0x00, 0x67, 0x00,
  84724. 0x39, 0x00, 0x33, 0xcc, 0x14, 0xcc, 0x13, 0xcc, 0x15, 0x01, 0x00, 0x02,
  84725. 0x7c, 0x00, 0x2b, 0x00, 0x03, 0x02, 0xfe, 0xfc, 0x00, 0x0d, 0x00, 0x20,
  84726. 0x00, 0x1e, 0x06, 0x03, 0x05, 0x03, 0x04, 0x03, 0x02, 0x03, 0x08, 0x06,
  84727. 0x08, 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08, 0x09, 0x06, 0x01,
  84728. 0x05, 0x01, 0x04, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, 0x0a, 0x00, 0x0c,
  84729. 0x00, 0x0a, 0x00, 0x19, 0x00, 0x18, 0x00, 0x17, 0x00, 0x15, 0x01, 0x00,
  84730. 0x00, 0x16, 0x00, 0x00, 0x00, 0x33, 0x02, 0x39, 0x02, 0x37, 0x00, 0x17,
  84731. 0x00, 0x41, 0x04, 0x94, 0xdf, 0x36, 0xd7, 0xb3, 0x90, 0x6d, 0x01, 0xa1,
  84732. 0xe6, 0xed, 0x67, 0xf4, 0xd9, 0x9d, 0x2c, 0xac, 0x57, 0x74, 0xff, 0x19,
  84733. 0xbe, 0x5a, 0xc9, 0x30, 0x11, 0xb7, 0x2b, 0x59, 0x47, 0x80, 0x7c, 0xa9,
  84734. 0xb7, 0x31, 0x8c, 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  84735. 0x00, 0x01, 0x00, 0xda, 0x01, 0x00, 0x02, 0xdc, 0x00, 0x00, 0x00, 0x00,
  84736. 0xce, 0x00, 0x00, 0xce, 0x9e, 0x13, 0x74, 0x3b, 0x86, 0xba, 0x69, 0x1f,
  84737. 0x12, 0xf7, 0xcd, 0x78, 0x53, 0xe8, 0x50, 0x4d, 0x71, 0x3f, 0x4b, 0x4e,
  84738. 0xeb, 0x3e, 0xe5, 0x43, 0x54, 0x78, 0x17, 0x6d, 0x00, 0x18, 0x00, 0x61,
  84739. 0x04, 0xd1, 0x99, 0x66, 0x4f, 0xda, 0xc7, 0x12, 0x3b, 0xff, 0xb2, 0xd6,
  84740. 0x2f, 0x35, 0xb6, 0x17, 0x1f, 0xb3, 0xd0, 0xb6, 0x52, 0xff, 0x97, 0x8b,
  84741. 0x01, 0xe8, 0xd9, 0x68, 0x71, 0x40, 0x02, 0xd5, 0x68, 0x3a, 0x58, 0xb2,
  84742. 0x5d, 0xee, 0xa4, 0xe9, 0x5f, 0xf4, 0xaf, 0x3e, 0x30, 0x9c, 0x3e, 0x2b,
  84743. 0xda, 0x61, 0x43, 0x99, 0x02, 0x35, 0x33, 0x9f, 0xcf, 0xb5, 0xd3, 0x28,
  84744. 0x19, 0x9d, 0x1c, 0xbe, 0x69, 0x07, 0x9e, 0xfc, 0xe4, 0x8e, 0xcd, 0x86,
  84745. 0x4a, 0x1b, 0xf0, 0xfc, 0x17, 0x94, 0x66, 0x53, 0xda, 0x24, 0x5e, 0xaf,
  84746. 0xce, 0xec, 0x62, 0x4c, 0x06, 0xb4, 0x52, 0x94, 0xb1, 0x4a, 0x7a, 0x8c,
  84747. 0x4f, 0x00, 0x19, 0x00, 0x85, 0x04, 0x00, 0x27, 0xeb, 0x99, 0x49, 0x7f,
  84748. 0xcb, 0x2c, 0x46, 0x54, 0x2d, 0x93, 0x5d, 0x25, 0x92, 0x58, 0x5e, 0x06,
  84749. 0xc3, 0x7c, 0xfb, 0x9a, 0xa7, 0xec, 0xcd, 0x9f, 0xe1, 0x6b, 0x2d, 0x78,
  84750. 0xf5, 0x16, 0xa9, 0x20, 0x52, 0x48, 0x19, 0x0f, 0x1a, 0xd0, 0xce, 0xd8,
  84751. 0x68, 0xb1, 0x4e, 0x7f, 0x33, 0x03, 0x7d, 0x0c, 0x39, 0xdb, 0x9c, 0x4b,
  84752. 0xf4, 0xe7, 0xc2, 0xf5, 0xdd, 0x51, 0x9b, 0x03, 0xa8, 0x53, 0x2b, 0xe6,
  84753. 0x00, 0x15, 0x4b, 0xff, 0xd2, 0xa0, 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00,
  84754. 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xda, 0x01, 0x00, 0x02, 0xdc, 0x00,
  84755. 0x00, 0x00, 0x01, 0x9c, 0x00, 0x00, 0xce, 0x58, 0x30, 0x10, 0x3d, 0x46,
  84756. 0xcc, 0xca, 0x1a, 0x44, 0xc8, 0x58, 0x9b, 0x27, 0x17, 0x67, 0x31, 0x96,
  84757. 0x8a, 0x66, 0x39, 0xf4, 0xcc, 0xc1, 0x9f, 0x12, 0x1f, 0x01, 0x30, 0x50,
  84758. 0x16, 0xd6, 0x89, 0x97, 0xa3, 0x66, 0xd7, 0x99, 0x50, 0x09, 0x6e, 0x80,
  84759. 0x87, 0xe4, 0xa2, 0x88, 0xae, 0xb4, 0x23, 0x57, 0x2f, 0x12, 0x60, 0xe7,
  84760. 0x7d, 0x44, 0x2d, 0xad, 0xbe, 0xe9, 0x0d, 0x01, 0x00, 0x01, 0x00, 0xd5,
  84761. 0xdd, 0x62, 0xee, 0xf3, 0x0e, 0xd9, 0x30, 0x0e, 0x38, 0xf3, 0x48, 0xf4,
  84762. 0xc9, 0x8f, 0x8c, 0x20, 0xf7, 0xd3, 0xa8, 0xb3, 0x87, 0x3c, 0x98, 0x5d,
  84763. 0x70, 0xc5, 0x03, 0x76, 0xb7, 0xd5, 0x0b, 0x7b, 0x23, 0x97, 0x6b, 0xe3,
  84764. 0xb5, 0x18, 0xeb, 0x64, 0x55, 0x18, 0xb2, 0x8a, 0x90, 0x1a, 0x8f, 0x0e,
  84765. 0x15, 0xda, 0xb1, 0x8e, 0x7f, 0xee, 0x1f, 0xe0, 0x3b, 0xb9, 0xed, 0xfc,
  84766. 0x4e, 0x3f, 0x78, 0x16, 0x39, 0x95, 0x5f, 0xb7, 0xcb, 0x65, 0x55, 0x72,
  84767. 0x7b, 0x7d, 0x86, 0x2f, 0x8a, 0xe5, 0xee, 0xf7, 0x57, 0x40, 0xf3, 0xc4,
  84768. 0x96, 0x4f, 0x11, 0x4d, 0x85, 0xf9, 0x56, 0xfa, 0x3d, 0xf0, 0xc9, 0xa4,
  84769. 0xec, 0x1e, 0xaa, 0x47, 0x90, 0x53, 0xdf, 0xe1, 0xb7, 0x78, 0x18, 0xeb,
  84770. 0xdd, 0x0d, 0x89, 0xb7, 0xf6, 0x15, 0x0e, 0x55, 0x12, 0xb3, 0x23, 0x17,
  84771. 0x0b, 0x59, 0x6f, 0x83, 0x05, 0x6b, 0xa6, 0xf8, 0x6c, 0x3a, 0x9b, 0x1b,
  84772. 0x50, 0x93, 0x51, 0xea, 0x95, 0x2d, 0x99, 0x96, 0x38, 0x16, 0xfe, 0xfd,
  84773. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x7e, 0x01, 0x00,
  84774. 0x02, 0xdc, 0x00, 0x00, 0x00, 0x02, 0x6a, 0x00, 0x00, 0x72, 0x2d, 0x66,
  84775. 0x3e, 0xf2, 0x36, 0x5a, 0xf2, 0x23, 0x8f, 0x28, 0x09, 0xa9, 0x55, 0x8c,
  84776. 0x8f, 0xc0, 0x0d, 0x61, 0x98, 0x33, 0x56, 0x87, 0x7a, 0xfd, 0xa7, 0x50,
  84777. 0x71, 0x84, 0x2e, 0x41, 0x58, 0x00, 0x87, 0xd9, 0x27, 0xe5, 0x7b, 0xf4,
  84778. 0x6d, 0x84, 0x4e, 0x2e, 0x0c, 0x80, 0x0c, 0xf3, 0x8a, 0x02, 0x4b, 0x99,
  84779. 0x3a, 0x1f, 0x9f, 0x18, 0x7d, 0x1c, 0xec, 0xad, 0x60, 0x54, 0xa6, 0xa3,
  84780. 0x2c, 0x82, 0x5e, 0xf8, 0x8f, 0xae, 0xe1, 0xc4, 0x82, 0x7e, 0x43, 0x43,
  84781. 0xc5, 0x99, 0x49, 0x05, 0xd3, 0xf6, 0xdf, 0xa1, 0xb5, 0x2d, 0x0c, 0x13,
  84782. 0x2f, 0x1e, 0xb6, 0x28, 0x7c, 0x5c, 0xa1, 0x02, 0x6b, 0x8d, 0xa3, 0xeb,
  84783. 0xd4, 0x58, 0xe6, 0xa0, 0x7e, 0x6b, 0xaa, 0x09, 0x43, 0x67, 0x71, 0x87,
  84784. 0xa5, 0xcb, 0x68, 0xf3
  84785. };
  84786. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84787. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84788. wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0);
  84789. /* Fragment msgs */
  84790. ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl_c, DUMMY_MTU), WOLFSSL_SUCCESS);
  84791. ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl_s, DUMMY_MTU), WOLFSSL_SUCCESS);
  84792. /* Add in some key shares to make the CH long */
  84793. ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_ECC_SECP256R1),
  84794. WOLFSSL_SUCCESS);
  84795. ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_ECC_SECP384R1),
  84796. WOLFSSL_SUCCESS);
  84797. ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_ECC_SECP521R1),
  84798. WOLFSSL_SUCCESS);
  84799. ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_FFDHE_2048),
  84800. WOLFSSL_SUCCESS);
  84801. ExpectIntEQ(wolfSSL_dtls13_allow_ch_frag(ssl_s, 1), WOLFSSL_SUCCESS);
  84802. /* Reject fragmented first CH */
  84803. ExpectIntEQ(test_dtls_frag_ch_count_records(four_frag_CH,
  84804. sizeof(four_frag_CH)), 4);
  84805. XMEMCPY(test_ctx.s_buff, four_frag_CH, sizeof(four_frag_CH));
  84806. test_ctx.s_len = sizeof(four_frag_CH);
  84807. while (test_ctx.s_len > 0 && EXPECT_SUCCESS()) {
  84808. int s_len = test_ctx.s_len;
  84809. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84810. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84811. /* Fail if we didn't advance the buffer to avoid infinite loops */
  84812. ExpectIntLT(test_ctx.s_len, s_len);
  84813. }
  84814. /* Expect all fragments read */
  84815. ExpectIntEQ(test_ctx.s_len, 0);
  84816. /* Expect quietly dropping fragmented first CH */
  84817. ExpectIntEQ(test_ctx.c_len, 0);
  84818. #if defined(WOLFSSL_TLS13) && defined(HAVE_ECH)
  84819. /* Disable ECH as it pushes it over our MTU */
  84820. wolfSSL_SetEchEnable(ssl_c, 0);
  84821. #endif
  84822. /* Limit options to make the CH a fixed length */
  84823. /* See wolfSSL_parse_cipher_list for reason why we provide 1.3 AND 1.2
  84824. * ciphersuite. This is only necessary when building with OPENSSL_EXTRA. */
  84825. ExpectTrue(wolfSSL_set_cipher_list(ssl_c, "TLS13-AES256-GCM-SHA384"
  84826. #ifdef OPENSSL_EXTRA
  84827. ":DHE-RSA-AES256-GCM-SHA384"
  84828. #endif
  84829. ));
  84830. /* CH1 */
  84831. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84832. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84833. /* Count records. Expect 1 unfragmented CH */
  84834. ExpectIntEQ(test_dtls_frag_ch_count_records(test_ctx.s_buff,
  84835. test_ctx.s_len), 1);
  84836. /* HRR */
  84837. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84838. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84839. /* CH2 */
  84840. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84841. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84842. /* Count records. Expect fragmented CH */
  84843. ExpectIntGT(test_dtls_frag_ch_count_records(test_ctx.s_buff,
  84844. test_ctx.s_len), 1);
  84845. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  84846. wolfSSL_free(ssl_c);
  84847. wolfSSL_free(ssl_s);
  84848. wolfSSL_CTX_free(ctx_c);
  84849. wolfSSL_CTX_free(ctx_s);
  84850. ssl_c = ssl_s = NULL;
  84851. ctx_c = ctx_s = NULL;
  84852. #endif
  84853. return EXPECT_RESULT();
  84854. }
  84855. static int test_dtls_empty_keyshare_with_cookie(void)
  84856. {
  84857. EXPECT_DECLS;
  84858. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13)
  84859. WOLFSSL_CTX *ctx_s = NULL;
  84860. WOLFSSL *ssl_s = NULL;
  84861. struct test_memio_ctx test_ctx;
  84862. unsigned char ch_empty_keyshare_with_cookie[] = {
  84863. 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
  84864. 0x12, 0x01, 0x00, 0x01, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01,
  84865. 0x06, 0xfe, 0xfd, 0xfb, 0x8c, 0x9b, 0x28, 0xae, 0x50, 0x1c, 0x4d, 0xf3,
  84866. 0xb8, 0xcf, 0x4d, 0xd8, 0x7e, 0x93, 0x13, 0x7b, 0x9e, 0xd9, 0xeb, 0xe9,
  84867. 0x13, 0x4b, 0x0d, 0x7f, 0x2e, 0x43, 0x62, 0x8c, 0xe4, 0x57, 0x79, 0x00,
  84868. 0x00, 0x00, 0x36, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0,
  84869. 0x2b, 0xc0, 0x30, 0xc0, 0x2f, 0x00, 0x9f, 0x00, 0x9e, 0xcc, 0xa9, 0xcc,
  84870. 0xa8, 0xcc, 0xaa, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x28, 0xc0, 0x24, 0xc0,
  84871. 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x6b, 0x00, 0x67, 0x00,
  84872. 0x39, 0x00, 0x33, 0xcc, 0x14, 0xcc, 0x13, 0xcc, 0x15, 0x01, 0x00, 0x00,
  84873. 0xa6, 0x00, 0x2b, 0x00, 0x03, 0x02, 0xfe, 0xfc, 0x00, 0x2c, 0x00, 0x47,
  84874. 0x00, 0x45, 0x20, 0xee, 0x4b, 0x17, 0x70, 0x63, 0xa0, 0x4c, 0x82, 0xbf,
  84875. 0x43, 0x01, 0x7d, 0x8d, 0xc1, 0x1b, 0x4e, 0x9b, 0xa0, 0x3c, 0x53, 0x1f,
  84876. 0xb7, 0xd1, 0x10, 0x81, 0xa8, 0xdf, 0xdf, 0x8c, 0x7f, 0xf3, 0x11, 0x13,
  84877. 0x01, 0x02, 0x3d, 0x3b, 0x7d, 0x14, 0x2c, 0x31, 0xb3, 0x60, 0x72, 0x4d,
  84878. 0xe5, 0x1a, 0xb2, 0xa3, 0x61, 0x77, 0x73, 0x03, 0x40, 0x0e, 0x5f, 0xc5,
  84879. 0x61, 0x38, 0x43, 0x56, 0x21, 0x4a, 0x95, 0xd5, 0x35, 0xa8, 0x0d, 0x00,
  84880. 0x0d, 0x00, 0x2a, 0x00, 0x28, 0x06, 0x03, 0x05, 0x03, 0x04, 0x03, 0x02,
  84881. 0x03, 0xfe, 0x0b, 0xfe, 0x0e, 0xfe, 0xa0, 0xfe, 0xa3, 0xfe, 0xa5, 0x08,
  84882. 0x06, 0x08, 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08, 0x09, 0x06,
  84883. 0x01, 0x05, 0x01, 0x04, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, 0x0a, 0x00,
  84884. 0x18, 0x00, 0x16, 0x00, 0x19, 0x00, 0x18, 0x00, 0x17, 0x00, 0x15, 0x01,
  84885. 0x00, 0x02, 0x3a, 0x02, 0x3c, 0x02, 0x3d, 0x2f, 0x3a, 0x2f, 0x3c, 0x2f,
  84886. 0x3d, 0x00, 0x16, 0x00, 0x00, 0x00, 0x33, 0x00, 0x02, 0x00, 0x00
  84887. };
  84888. DtlsRecordLayerHeader* dtlsRH;
  84889. byte sequence_number[8];
  84890. XMEMSET(&sequence_number, 0, sizeof(sequence_number));
  84891. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84892. XMEMCPY(test_ctx.s_buff, ch_empty_keyshare_with_cookie,
  84893. sizeof(ch_empty_keyshare_with_cookie));
  84894. test_ctx.s_len = sizeof(ch_empty_keyshare_with_cookie);
  84895. ExpectIntEQ(test_memio_setup(&test_ctx, NULL, &ctx_s, NULL, &ssl_s,
  84896. NULL, wolfDTLSv1_3_server_method), 0);
  84897. /* CH1 */
  84898. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84899. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84900. /* Expect an alert. A plaintext alert should be exactly 15 bytes. */
  84901. ExpectIntEQ(test_ctx.c_len, 15);
  84902. dtlsRH = (DtlsRecordLayerHeader*)test_ctx.c_buff;
  84903. ExpectIntEQ(dtlsRH->type, alert);
  84904. ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR);
  84905. ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR);
  84906. sequence_number[7] = 1;
  84907. ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number,
  84908. sizeof(sequence_number)), 0);
  84909. ExpectIntEQ(dtlsRH->length[0], 0);
  84910. ExpectIntEQ(dtlsRH->length[1], 2);
  84911. ExpectIntEQ(test_ctx.c_buff[13], alert_fatal);
  84912. ExpectIntEQ(test_ctx.c_buff[14], illegal_parameter);
  84913. wolfSSL_free(ssl_s);
  84914. wolfSSL_CTX_free(ctx_s);
  84915. #endif
  84916. return EXPECT_RESULT();
  84917. }
  84918. static int test_dtls_old_seq_number(void)
  84919. {
  84920. EXPECT_DECLS;
  84921. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS)
  84922. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  84923. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  84924. struct test_memio_ctx test_ctx;
  84925. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84926. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84927. wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  84928. /* CH1 */
  84929. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84930. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84931. /* HVR */
  84932. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84933. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84934. /* CH2 */
  84935. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84936. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84937. /* Server first flight */
  84938. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84939. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84940. /* Client second flight */
  84941. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  84942. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  84943. /* Modify the sequence number */
  84944. {
  84945. DtlsRecordLayerHeader* dtlsRH = (DtlsRecordLayerHeader*)test_ctx.s_buff;
  84946. XMEMSET(dtlsRH->sequence_number, 0, sizeof(dtlsRH->sequence_number));
  84947. }
  84948. /* Server second flight */
  84949. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  84950. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84951. /* Server should not do anything as a pkt was dropped */
  84952. ExpectIntEQ(test_ctx.c_len, 0);
  84953. ExpectIntEQ(test_ctx.s_len, 0);
  84954. /* Trigger rtx */
  84955. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  84956. /* Complete connection */
  84957. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  84958. wolfSSL_free(ssl_c);
  84959. wolfSSL_CTX_free(ctx_c);
  84960. wolfSSL_free(ssl_s);
  84961. wolfSSL_CTX_free(ctx_s);
  84962. #endif
  84963. return EXPECT_RESULT();
  84964. }
  84965. static int test_dtls13_basic_connection_id(void)
  84966. {
  84967. EXPECT_DECLS;
  84968. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \
  84969. && defined(WOLFSSL_DTLS_CID)
  84970. unsigned char client_cid[] = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
  84971. unsigned char server_cid[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  84972. unsigned char readBuf[30];
  84973. const char* params[] = {
  84974. #ifndef NO_SHA256
  84975. #ifdef WOLFSSL_AES_128
  84976. #ifdef HAVE_AESGCM
  84977. "TLS13-AES128-GCM-SHA256",
  84978. #endif
  84979. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  84980. "TLS13-CHACHA20-POLY1305-SHA256",
  84981. #endif
  84982. #ifdef HAVE_AESCCM
  84983. "TLS13-AES128-CCM-8-SHA256",
  84984. "TLS13-AES128-CCM-SHA256",
  84985. #endif
  84986. #endif
  84987. #ifdef HAVE_NULL_CIPHER
  84988. "TLS13-SHA256-SHA256",
  84989. #endif
  84990. #endif
  84991. };
  84992. size_t i;
  84993. /* We check if the side included the CID in their output */
  84994. #define CLIENT_CID() mymemmem(test_ctx.s_buff, test_ctx.s_len, \
  84995. client_cid, sizeof(client_cid))
  84996. #define SERVER_CID() mymemmem(test_ctx.c_buff, test_ctx.c_len, \
  84997. server_cid, sizeof(server_cid))
  84998. printf("\n");
  84999. for (i = 0; i < XELEM_CNT(params) && EXPECT_SUCCESS(); i++) {
  85000. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  85001. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  85002. struct test_memio_ctx test_ctx;
  85003. printf("Testing %s ... ", params[i]);
  85004. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85005. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  85006. wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0);
  85007. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_c, params[i]), WOLFSSL_SUCCESS);
  85008. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_s, params[i]), WOLFSSL_SUCCESS);
  85009. ExpectIntEQ(wolfSSL_dtls_cid_use(ssl_c), 1);
  85010. ExpectIntEQ(wolfSSL_dtls_cid_set(ssl_c, server_cid, sizeof(server_cid)),
  85011. 1);
  85012. ExpectIntEQ(wolfSSL_dtls_cid_use(ssl_s), 1);
  85013. ExpectIntEQ(wolfSSL_dtls_cid_set(ssl_s, client_cid, sizeof(client_cid)),
  85014. 1);
  85015. /* CH1 */
  85016. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85017. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85018. ExpectNull(CLIENT_CID());
  85019. /* HRR */
  85020. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  85021. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85022. ExpectNull(SERVER_CID());
  85023. /* CH2 */
  85024. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85025. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85026. ExpectNull(CLIENT_CID());
  85027. /* Server first flight */
  85028. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  85029. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85030. ExpectNotNull(SERVER_CID());
  85031. /* Client second flight */
  85032. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85033. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85034. ExpectNotNull(CLIENT_CID());
  85035. /* Server process flight */
  85036. ExpectIntEQ(wolfSSL_negotiate(ssl_s), 1);
  85037. /* Client process flight */
  85038. ExpectIntEQ(wolfSSL_negotiate(ssl_c), 1);
  85039. /* Write some data */
  85040. ExpectIntEQ(wolfSSL_write(ssl_c, params[i], XSTRLEN(params[i])),
  85041. XSTRLEN(params[i]));
  85042. ExpectNotNull(CLIENT_CID());
  85043. ExpectIntEQ(wolfSSL_write(ssl_s, params[i], XSTRLEN(params[i])),
  85044. XSTRLEN(params[i]));
  85045. ExpectNotNull(SERVER_CID());
  85046. /* Read the data */
  85047. XMEMSET(readBuf, 0, sizeof(readBuf));
  85048. ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)),
  85049. XSTRLEN(params[i]));
  85050. ExpectStrEQ(readBuf, params[i]);
  85051. XMEMSET(readBuf, 0, sizeof(readBuf));
  85052. ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)),
  85053. XSTRLEN(params[i]));
  85054. ExpectStrEQ(readBuf, params[i]);
  85055. /* Write short data */
  85056. ExpectIntEQ(wolfSSL_write(ssl_c, params[i], 1), 1);
  85057. ExpectNotNull(CLIENT_CID());
  85058. ExpectIntEQ(wolfSSL_write(ssl_s, params[i], 1), 1);
  85059. ExpectNotNull(SERVER_CID());
  85060. /* Read the short data */
  85061. XMEMSET(readBuf, 0, sizeof(readBuf));
  85062. ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)), 1);
  85063. ExpectIntEQ(readBuf[0], params[i][0]);
  85064. XMEMSET(readBuf, 0, sizeof(readBuf));
  85065. ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)), 1);
  85066. ExpectIntEQ(readBuf[0], params[i][0]);
  85067. /* Close connection */
  85068. ExpectIntEQ(wolfSSL_shutdown(ssl_c), WOLFSSL_SHUTDOWN_NOT_DONE);
  85069. ExpectNotNull(CLIENT_CID());
  85070. ExpectIntEQ(wolfSSL_shutdown(ssl_s), WOLFSSL_SHUTDOWN_NOT_DONE);
  85071. ExpectNotNull(SERVER_CID());
  85072. ExpectIntEQ(wolfSSL_shutdown(ssl_c), 1);
  85073. ExpectIntEQ(wolfSSL_shutdown(ssl_s), 1);
  85074. if (EXPECT_SUCCESS())
  85075. printf("ok\n");
  85076. else
  85077. printf("failed\n");
  85078. wolfSSL_free(ssl_c);
  85079. wolfSSL_CTX_free(ctx_c);
  85080. wolfSSL_free(ssl_s);
  85081. wolfSSL_CTX_free(ctx_s);
  85082. }
  85083. #undef CLIENT_CID
  85084. #undef SERVER_CID
  85085. #endif
  85086. return EXPECT_RESULT();
  85087. }
  85088. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(WOLFSSL_TLS13) && \
  85089. defined(HAVE_LIBOQS)
  85090. static void test_tls13_pq_groups_ctx_ready(WOLFSSL_CTX* ctx)
  85091. {
  85092. int group = WOLFSSL_KYBER_LEVEL5;
  85093. AssertIntEQ(wolfSSL_CTX_set_groups(ctx, &group, 1), WOLFSSL_SUCCESS);
  85094. }
  85095. static void test_tls13_pq_groups_on_result(WOLFSSL* ssl)
  85096. {
  85097. AssertStrEQ(wolfSSL_get_curve_name(ssl), "KYBER_LEVEL5");
  85098. }
  85099. #endif
  85100. static int test_tls13_pq_groups(void)
  85101. {
  85102. EXPECT_DECLS;
  85103. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(WOLFSSL_TLS13) && \
  85104. defined(HAVE_LIBOQS)
  85105. callback_functions func_cb_client;
  85106. callback_functions func_cb_server;
  85107. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  85108. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  85109. func_cb_client.method = wolfTLSv1_3_client_method;
  85110. func_cb_server.method = wolfTLSv1_3_server_method;
  85111. func_cb_client.ctx_ready = test_tls13_pq_groups_ctx_ready;
  85112. func_cb_client.on_result = test_tls13_pq_groups_on_result;
  85113. func_cb_server.on_result = test_tls13_pq_groups_on_result;
  85114. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  85115. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  85116. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  85117. #endif
  85118. return EXPECT_RESULT();
  85119. }
  85120. static int test_tls13_early_data(void)
  85121. {
  85122. EXPECT_DECLS;
  85123. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
  85124. defined(WOLFSSL_EARLY_DATA) && defined(HAVE_SESSION_TICKET)
  85125. int written = 0;
  85126. int read = 0;
  85127. size_t i;
  85128. int splitEarlyData;
  85129. char msg[] = "This is early data";
  85130. char msg2[] = "This is client data";
  85131. char msg3[] = "This is server data";
  85132. char msg4[] = "This is server immediate data";
  85133. char msgBuf[50];
  85134. struct {
  85135. method_provider client_meth;
  85136. method_provider server_meth;
  85137. const char* tls_version;
  85138. int isUdp;
  85139. } params[] = {
  85140. #ifdef WOLFSSL_TLS13
  85141. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  85142. "TLS 1.3", 0 },
  85143. #endif
  85144. #ifdef WOLFSSL_DTLS13
  85145. { wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method,
  85146. "DTLS 1.3", 1 },
  85147. #endif
  85148. };
  85149. for (i = 0; i < sizeof(params)/sizeof(*params) && !EXPECT_FAIL(); i++) {
  85150. for (splitEarlyData = 0; splitEarlyData < 2; splitEarlyData++) {
  85151. struct test_memio_ctx test_ctx;
  85152. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  85153. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  85154. WOLFSSL_SESSION *sess = NULL;
  85155. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85156. fprintf(stderr, "\tEarly data with %s\n", params[i].tls_version);
  85157. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c,
  85158. &ssl_s, params[i].client_meth, params[i].server_meth), 0);
  85159. /* Get a ticket so that we can do 0-RTT on the next connection */
  85160. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  85161. /* Make sure we read the ticket */
  85162. ExpectIntEQ(wolfSSL_read(ssl_c, msgBuf, sizeof(msgBuf)), -1);
  85163. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85164. ExpectNotNull(sess = wolfSSL_get1_session(ssl_c));
  85165. wolfSSL_free(ssl_c);
  85166. ssl_c = NULL;
  85167. wolfSSL_free(ssl_s);
  85168. ssl_s = NULL;
  85169. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85170. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  85171. params[i].client_meth, params[i].server_meth), 0);
  85172. ExpectIntEQ(wolfSSL_set_session(ssl_c, sess), WOLFSSL_SUCCESS);
  85173. #ifdef WOLFSSL_DTLS13
  85174. if (params[i].isUdp) {
  85175. #ifdef WOLFSSL_DTLS13_NO_HRR_ON_RESUME
  85176. ExpectIntEQ(wolfSSL_dtls13_no_hrr_on_resume(ssl_s, 1), WOLFSSL_SUCCESS);
  85177. #else
  85178. /* Let's test this but we generally don't recommend turning off the
  85179. * cookie exchange */
  85180. ExpectIntEQ(wolfSSL_disable_hrr_cookie(ssl_s), WOLFSSL_SUCCESS);
  85181. #endif
  85182. }
  85183. #endif
  85184. /* Test 0-RTT data */
  85185. ExpectIntEQ(wolfSSL_write_early_data(ssl_c, msg, sizeof(msg),
  85186. &written), sizeof(msg));
  85187. ExpectIntEQ(written, sizeof(msg));
  85188. if (splitEarlyData) {
  85189. ExpectIntEQ(wolfSSL_write_early_data(ssl_c, msg, sizeof(msg),
  85190. &written), sizeof(msg));
  85191. ExpectIntEQ(written, sizeof(msg));
  85192. }
  85193. /* Read first 0-RTT data (if split otherwise entire data) */
  85194. ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf, sizeof(msgBuf),
  85195. &read), sizeof(msg));
  85196. ExpectIntEQ(read, sizeof(msg));
  85197. ExpectStrEQ(msg, msgBuf);
  85198. /* Test 0.5-RTT data */
  85199. ExpectIntEQ(wolfSSL_write(ssl_s, msg4, sizeof(msg4)), sizeof(msg4));
  85200. if (splitEarlyData) {
  85201. /* Read second 0-RTT data */
  85202. ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf, sizeof(msgBuf),
  85203. &read), sizeof(msg));
  85204. ExpectIntEQ(read, sizeof(msg));
  85205. ExpectStrEQ(msg, msgBuf);
  85206. }
  85207. if (params[i].isUdp) {
  85208. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  85209. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WC_NO_ERR_TRACE(APP_DATA_READY));
  85210. /* Read server 0.5-RTT data */
  85211. ExpectIntEQ(wolfSSL_read(ssl_c, msgBuf, sizeof(msgBuf)), sizeof(msg4));
  85212. ExpectStrEQ(msg4, msgBuf);
  85213. /* Complete handshake */
  85214. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  85215. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85216. /* Use wolfSSL_is_init_finished to check if handshake is complete. Normally
  85217. * a user would loop until it is true but here we control both sides so we
  85218. * just assert the expected value. wolfSSL_read_early_data does not provide
  85219. * handshake status to us with non-blocking IO and we can't use
  85220. * wolfSSL_accept as TLS layer may return ZERO_RETURN due to early data
  85221. * parsing logic. */
  85222. ExpectFalse(wolfSSL_is_init_finished(ssl_s));
  85223. ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf, sizeof(msgBuf),
  85224. &read), 0);
  85225. ExpectIntEQ(read, 0);
  85226. ExpectTrue(wolfSSL_is_init_finished(ssl_s));
  85227. ExpectIntEQ(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  85228. }
  85229. else {
  85230. ExpectIntEQ(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  85231. ExpectFalse(wolfSSL_is_init_finished(ssl_s));
  85232. ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf, sizeof(msgBuf),
  85233. &read), 0);
  85234. ExpectIntEQ(read, 0);
  85235. ExpectTrue(wolfSSL_is_init_finished(ssl_s));
  85236. /* Read server 0.5-RTT data */
  85237. ExpectIntEQ(wolfSSL_read(ssl_c, msgBuf, sizeof(msgBuf)), sizeof(msg4));
  85238. ExpectStrEQ(msg4, msgBuf);
  85239. }
  85240. /* Test bi-directional write */
  85241. ExpectIntEQ(wolfSSL_write(ssl_c, msg2, sizeof(msg2)), sizeof(msg2));
  85242. ExpectIntEQ(wolfSSL_read(ssl_s, msgBuf, sizeof(msgBuf)), sizeof(msg2));
  85243. ExpectStrEQ(msg2, msgBuf);
  85244. ExpectIntEQ(wolfSSL_write(ssl_s, msg3, sizeof(msg3)), sizeof(msg3));
  85245. ExpectIntEQ(wolfSSL_read(ssl_c, msgBuf, sizeof(msgBuf)), sizeof(msg3));
  85246. ExpectStrEQ(msg3, msgBuf);
  85247. ExpectTrue(wolfSSL_session_reused(ssl_c));
  85248. ExpectTrue(wolfSSL_session_reused(ssl_s));
  85249. wolfSSL_SESSION_free(sess);
  85250. wolfSSL_free(ssl_c);
  85251. wolfSSL_free(ssl_s);
  85252. wolfSSL_CTX_free(ctx_c);
  85253. wolfSSL_CTX_free(ctx_s);
  85254. }
  85255. }
  85256. #endif
  85257. return EXPECT_RESULT();
  85258. }
  85259. #ifdef HAVE_CERTIFICATE_STATUS_REQUEST
  85260. static int test_self_signed_stapling_client_v1_ctx_ready(WOLFSSL_CTX* ctx)
  85261. {
  85262. EXPECT_DECLS;
  85263. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), 1);
  85264. ExpectIntEQ(wolfSSL_CTX_UseOCSPStapling(ctx, WOLFSSL_CSR_OCSP,
  85265. WOLFSSL_CSR_OCSP_USE_NONCE), 1);
  85266. return EXPECT_RESULT();
  85267. }
  85268. #endif
  85269. #ifdef HAVE_CERTIFICATE_STATUS_REQUEST_V2
  85270. static int test_self_signed_stapling_client_v2_ctx_ready(WOLFSSL_CTX* ctx)
  85271. {
  85272. EXPECT_DECLS;
  85273. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), 1);
  85274. ExpectIntEQ(wolfSSL_CTX_UseOCSPStaplingV2(ctx, WOLFSSL_CSR2_OCSP,
  85275. WOLFSSL_CSR2_OCSP_USE_NONCE), 1);
  85276. return EXPECT_RESULT();
  85277. }
  85278. static int test_self_signed_stapling_client_v2_multi_ctx_ready(WOLFSSL_CTX* ctx)
  85279. {
  85280. EXPECT_DECLS;
  85281. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), 1);
  85282. ExpectIntEQ(wolfSSL_CTX_UseOCSPStaplingV2(ctx, WOLFSSL_CSR2_OCSP_MULTI,
  85283. 0), 1);
  85284. return EXPECT_RESULT();
  85285. }
  85286. #endif
  85287. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) \
  85288. || defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  85289. static int test_self_signed_stapling_server_ctx_ready(WOLFSSL_CTX* ctx)
  85290. {
  85291. EXPECT_DECLS;
  85292. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), 1);
  85293. return EXPECT_RESULT();
  85294. }
  85295. #endif
  85296. static int test_self_signed_stapling(void)
  85297. {
  85298. EXPECT_DECLS;
  85299. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) \
  85300. || defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  85301. test_ssl_cbf client_cbf;
  85302. test_ssl_cbf server_cbf;
  85303. size_t i;
  85304. struct {
  85305. method_provider client_meth;
  85306. method_provider server_meth;
  85307. ctx_cb client_ctx;
  85308. const char* tls_version;
  85309. } params[] = {
  85310. #if defined(WOLFSSL_TLS13) && defined(HAVE_CERTIFICATE_STATUS_REQUEST)
  85311. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  85312. test_self_signed_stapling_client_v1_ctx_ready, "TLSv1_3 v1" },
  85313. #endif
  85314. #ifndef WOLFSSL_NO_TLS12
  85315. #ifdef HAVE_CERTIFICATE_STATUS_REQUEST
  85316. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method,
  85317. test_self_signed_stapling_client_v1_ctx_ready, "TLSv1_2 v1" },
  85318. #endif
  85319. #ifdef HAVE_CERTIFICATE_STATUS_REQUEST_V2
  85320. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method,
  85321. test_self_signed_stapling_client_v2_ctx_ready, "TLSv1_2 v2" },
  85322. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method,
  85323. test_self_signed_stapling_client_v2_multi_ctx_ready,
  85324. "TLSv1_2 v2 multi" },
  85325. #endif
  85326. #endif
  85327. };
  85328. for (i = 0; i < sizeof(params)/sizeof(*params) && !EXPECT_FAIL(); i++) {
  85329. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  85330. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  85331. printf("\nTesting self-signed cert with status request: %s\n",
  85332. params[i].tls_version);
  85333. client_cbf.method = params[i].client_meth;
  85334. client_cbf.ctx_ready = params[i].client_ctx;
  85335. server_cbf.method = params[i].server_meth;
  85336. server_cbf.certPemFile = "certs/ca-cert.pem";
  85337. server_cbf.keyPemFile = "certs/ca-key.pem";
  85338. server_cbf.ctx_ready = test_self_signed_stapling_server_ctx_ready;
  85339. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  85340. &server_cbf, NULL), TEST_SUCCESS);
  85341. }
  85342. #endif
  85343. return EXPECT_RESULT();
  85344. }
  85345. static int test_tls_multi_handshakes_one_record(void)
  85346. {
  85347. EXPECT_DECLS;
  85348. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  85349. struct test_memio_ctx test_ctx;
  85350. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  85351. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  85352. RecordLayerHeader* rh = NULL;
  85353. byte *len ;
  85354. int newRecIdx = RECORD_HEADER_SZ;
  85355. int idx = 0;
  85356. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85357. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  85358. wolfTLS_client_method, wolfTLSv1_2_server_method), 0);
  85359. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  85360. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85361. ExpectIntEQ(wolfSSL_accept(ssl_s), -1);
  85362. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85363. /* Combine server handshake msgs into one record */
  85364. while (idx < test_ctx.c_len) {
  85365. word16 recLen;
  85366. rh = (RecordLayerHeader*)(test_ctx.c_buff + idx);
  85367. len = &rh->length[0];
  85368. ato16((const byte*)len, &recLen);
  85369. idx += RECORD_HEADER_SZ;
  85370. XMEMMOVE(test_ctx.c_buff + newRecIdx, test_ctx.c_buff + idx,
  85371. (size_t)recLen);
  85372. newRecIdx += recLen;
  85373. idx += recLen;
  85374. }
  85375. rh = (RecordLayerHeader*)(test_ctx.c_buff);
  85376. len = &rh->length[0];
  85377. c16toa(newRecIdx - RECORD_HEADER_SZ, len);
  85378. test_ctx.c_len = newRecIdx;
  85379. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  85380. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85381. wolfSSL_free(ssl_c);
  85382. wolfSSL_free(ssl_s);
  85383. wolfSSL_CTX_free(ctx_c);
  85384. wolfSSL_CTX_free(ctx_s);
  85385. #endif
  85386. return EXPECT_RESULT();
  85387. }
  85388. static int test_write_dup(void)
  85389. {
  85390. EXPECT_DECLS;
  85391. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_WRITE_DUP)
  85392. size_t i, j;
  85393. char hiWorld[] = "dup message";
  85394. char readData[sizeof(hiWorld) + 5];
  85395. struct {
  85396. method_provider client_meth;
  85397. method_provider server_meth;
  85398. const char* version_name;
  85399. int version;
  85400. } methods[] = {
  85401. #ifndef WOLFSSL_NO_TLS12
  85402. {wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLS 1.2", WOLFSSL_TLSV1_2},
  85403. #endif
  85404. #ifdef WOLFSSL_TLS13
  85405. {wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLS 1.3", WOLFSSL_TLSV1_3},
  85406. #endif
  85407. };
  85408. struct {
  85409. const char* cipher;
  85410. int version;
  85411. } ciphers[] = {
  85412. /* For simplicity the macros are copied from internal.h */
  85413. /* TLS 1.2 */
  85414. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) && !defined(NO_SHA256)
  85415. #if defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)
  85416. #ifndef NO_RSA
  85417. {"ECDHE-RSA-CHACHA20-POLY1305", WOLFSSL_TLSV1_2},
  85418. #endif
  85419. #endif
  85420. #if !defined(NO_DH) && !defined(NO_RSA) && !defined(NO_TLS_DH)
  85421. {"DHE-RSA-CHACHA20-POLY1305", WOLFSSL_TLSV1_2},
  85422. #endif
  85423. #endif
  85424. #if !defined(NO_DH) && !defined(NO_AES) && !defined(NO_TLS) && \
  85425. !defined(NO_RSA) && defined(HAVE_AESGCM) && !defined(NO_TLS_DH)
  85426. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
  85427. {"DHE-RSA-AES128-GCM-SHA256", WOLFSSL_TLSV1_2},
  85428. #endif
  85429. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  85430. {"DHE-RSA-AES256-GCM-SHA384", WOLFSSL_TLSV1_2},
  85431. #endif
  85432. #endif
  85433. #if (defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)) \
  85434. && !defined(NO_TLS) && !defined(NO_AES)
  85435. #ifdef HAVE_AESGCM
  85436. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
  85437. #ifndef NO_RSA
  85438. {"ECDHE-RSA-AES128-GCM-SHA256", WOLFSSL_TLSV1_2},
  85439. #endif
  85440. #endif
  85441. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  85442. #ifndef NO_RSA
  85443. {"ECDHE-RSA-AES256-GCM-SHA384", WOLFSSL_TLSV1_2},
  85444. #endif
  85445. #endif
  85446. #endif
  85447. #endif
  85448. /* TLS 1.3 */
  85449. #ifdef WOLFSSL_TLS13
  85450. #ifdef HAVE_AESGCM
  85451. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
  85452. {"TLS13-AES128-GCM-SHA256", WOLFSSL_TLSV1_3},
  85453. #endif
  85454. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  85455. {"TLS13-AES256-GCM-SHA384", WOLFSSL_TLSV1_3},
  85456. #endif
  85457. #endif
  85458. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  85459. #ifndef NO_SHA256
  85460. {"TLS13-CHACHA20-POLY1305-SHA256", WOLFSSL_TLSV1_3},
  85461. #endif
  85462. #endif
  85463. #ifdef HAVE_AESCCM
  85464. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
  85465. {"TLS13-AES128-CCM-SHA256", WOLFSSL_TLSV1_3},
  85466. #endif
  85467. #endif
  85468. #endif
  85469. };
  85470. for (i = 0; i < XELEM_CNT(methods); i++) {
  85471. for (j = 0; j < XELEM_CNT(ciphers) && !EXPECT_FAIL(); j++) {
  85472. struct test_memio_ctx test_ctx;
  85473. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  85474. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  85475. WOLFSSL *ssl_c2 = NULL;
  85476. if (methods[i].version != ciphers[j].version)
  85477. continue;
  85478. if (i == 0 && j == 0)
  85479. printf("\n");
  85480. printf("Testing %s with %s... ", methods[i].version_name,
  85481. ciphers[j].cipher);
  85482. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85483. test_ctx.c_ciphers = test_ctx.s_ciphers = ciphers[j].cipher;
  85484. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  85485. methods[i].client_meth, methods[i].server_meth), 0);
  85486. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  85487. ExpectNotNull(ssl_c2 = wolfSSL_write_dup(ssl_c));
  85488. ExpectIntEQ(wolfSSL_write(ssl_c, hiWorld, sizeof(hiWorld)),
  85489. WC_NO_ERR_TRACE(WRITE_DUP_WRITE_E));
  85490. ExpectIntEQ(wolfSSL_write(ssl_c2, hiWorld, sizeof(hiWorld)),
  85491. sizeof(hiWorld));
  85492. ExpectIntEQ(wolfSSL_read(ssl_s, readData, sizeof(readData)),
  85493. sizeof(hiWorld));
  85494. ExpectIntEQ(wolfSSL_write(ssl_s, hiWorld, sizeof(hiWorld)),
  85495. sizeof(hiWorld));
  85496. ExpectIntEQ(wolfSSL_read(ssl_c2, readData, sizeof(readData)),
  85497. WC_NO_ERR_TRACE(WRITE_DUP_READ_E));
  85498. ExpectIntEQ(wolfSSL_read(ssl_c, readData, sizeof(readData)),
  85499. sizeof(hiWorld));
  85500. if (EXPECT_SUCCESS())
  85501. printf("ok\n");
  85502. else
  85503. printf("failed\n");
  85504. wolfSSL_free(ssl_c);
  85505. wolfSSL_free(ssl_c2);
  85506. wolfSSL_free(ssl_s);
  85507. wolfSSL_CTX_free(ctx_c);
  85508. wolfSSL_CTX_free(ctx_s);
  85509. }
  85510. }
  85511. #endif
  85512. return EXPECT_RESULT();
  85513. }
  85514. static int test_read_write_hs(void)
  85515. {
  85516. EXPECT_DECLS;
  85517. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  85518. WOLFSSL_CTX *ctx_s = NULL, *ctx_c = NULL;
  85519. WOLFSSL *ssl_s = NULL, *ssl_c = NULL;
  85520. struct test_memio_ctx test_ctx;
  85521. byte test_buffer[16];
  85522. unsigned int test;
  85523. /* test == 0 : client writes, server reads */
  85524. /* test == 1 : server writes, client reads */
  85525. for (test = 0; test < 2; test++) {
  85526. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85527. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  85528. wolfTLSv1_2_client_method,
  85529. wolfTLSv1_2_server_method), 0);
  85530. ExpectIntEQ(wolfSSL_set_group_messages(ssl_s), WOLFSSL_SUCCESS);
  85531. /* CH -> */
  85532. if (test == 0) {
  85533. ExpectIntEQ(wolfSSL_write(ssl_c, "hello", 5), -1);
  85534. } else {
  85535. ExpectIntEQ(wolfSSL_read(ssl_c, test_buffer,
  85536. sizeof(test_buffer)), -1);
  85537. }
  85538. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85539. /* <- SH + SKE + SHD */
  85540. if (test == 0) {
  85541. ExpectIntEQ(wolfSSL_read(ssl_s, test_buffer,
  85542. sizeof(test_buffer)), -1);
  85543. } else {
  85544. ExpectIntEQ(wolfSSL_write(ssl_s, "hello", 5), -1);
  85545. }
  85546. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85547. /* -> CKE + CLIENT FINISHED */
  85548. if (test == 0) {
  85549. ExpectIntEQ(wolfSSL_write(ssl_c, "hello", 5), -1);
  85550. } else {
  85551. ExpectIntEQ(wolfSSL_read(ssl_c, test_buffer,
  85552. sizeof(test_buffer)), -1);
  85553. }
  85554. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85555. /* abide clang static analyzer */
  85556. if (ssl_s != NULL) {
  85557. /* disable group message to separate sending of ChangeCipherspec
  85558. * from Finished */
  85559. ssl_s->options.groupMessages = 0;
  85560. }
  85561. /* allow writing of CS, but not FINISHED */
  85562. test_ctx.c_len = TEST_MEMIO_BUF_SZ - 6;
  85563. /* <- CS */
  85564. if (test == 0) {
  85565. ExpectIntEQ(wolfSSL_read(ssl_s, test_buffer,
  85566. sizeof(test_buffer)), -1);
  85567. } else {
  85568. ExpectIntEQ(wolfSSL_write(ssl_s, "hello", 5), -1);
  85569. }
  85570. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_WRITE);
  85571. /* move CS message where the client can read it */
  85572. memmove(test_ctx.c_buff,
  85573. (test_ctx.c_buff + TEST_MEMIO_BUF_SZ - 6), 6);
  85574. test_ctx.c_len = 6;
  85575. /* read CS */
  85576. if (test == 0) {
  85577. ExpectIntEQ(wolfSSL_write(ssl_c, "hello", 5), -1);
  85578. } else {
  85579. ExpectIntEQ(wolfSSL_read(ssl_c, test_buffer,
  85580. sizeof(test_buffer)), -1);
  85581. }
  85582. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85583. ExpectIntEQ(test_ctx.c_len, 0);
  85584. if (test == 0) {
  85585. /* send SERVER FINISHED */
  85586. ExpectIntEQ(wolfSSL_read(ssl_s, test_buffer,
  85587. sizeof(test_buffer)), -1);
  85588. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1),
  85589. WOLFSSL_ERROR_WANT_READ);
  85590. } else {
  85591. /* send SERVER FINISHED + App Data */
  85592. ExpectIntEQ(wolfSSL_write(ssl_s, "hello", 5), 5);
  85593. }
  85594. ExpectIntGT(test_ctx.c_len, 0);
  85595. /* Send and receive the data */
  85596. if (test == 0) {
  85597. ExpectIntEQ(wolfSSL_write(ssl_c, "hello", 5), 5);
  85598. ExpectIntEQ(wolfSSL_read(ssl_s, test_buffer,
  85599. sizeof(test_buffer)), 5);
  85600. } else {
  85601. ExpectIntEQ(wolfSSL_read(ssl_c, test_buffer,
  85602. sizeof(test_buffer)), 5);
  85603. }
  85604. ExpectBufEQ(test_buffer, "hello", 5);
  85605. wolfSSL_free(ssl_c);
  85606. wolfSSL_free(ssl_s);
  85607. wolfSSL_CTX_free(ctx_c);
  85608. wolfSSL_CTX_free(ctx_s);
  85609. ssl_c = ssl_s = NULL;
  85610. ctx_c = ctx_s = NULL;
  85611. }
  85612. #endif
  85613. return EXPECT_RESULT();
  85614. }
  85615. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(OPENSSL_EXTRA)
  85616. static const char* test_get_signature_nid_siglag;
  85617. static int test_get_signature_nid_sig;
  85618. static int test_get_signature_nid_hash;
  85619. static int test_get_signature_nid_ssl_ready(WOLFSSL* ssl)
  85620. {
  85621. EXPECT_DECLS;
  85622. ExpectIntEQ(wolfSSL_set_cipher_list(ssl, "ALL"), WOLFSSL_SUCCESS);
  85623. if (!wolfSSL_is_server(ssl)) {
  85624. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl,
  85625. test_get_signature_nid_siglag), WOLFSSL_SUCCESS);
  85626. }
  85627. return EXPECT_RESULT();
  85628. }
  85629. static int test_get_signature_nid_on_hs_client(WOLFSSL_CTX **ctx, WOLFSSL **ssl)
  85630. {
  85631. EXPECT_DECLS;
  85632. int nid = 0;
  85633. (void)ctx;
  85634. if (XSTRSTR(wolfSSL_get_cipher(*ssl), "TLS_RSA_") == NULL) {
  85635. ExpectIntEQ(SSL_get_peer_signature_type_nid(*ssl, &nid), WOLFSSL_SUCCESS);
  85636. ExpectIntEQ(nid, test_get_signature_nid_sig);
  85637. ExpectIntEQ(SSL_get_peer_signature_nid(*ssl, &nid), WOLFSSL_SUCCESS);
  85638. ExpectIntEQ(nid, test_get_signature_nid_hash);
  85639. }
  85640. else /* No sigalg info on static ciphersuite */
  85641. return TEST_SUCCESS;
  85642. return EXPECT_RESULT();
  85643. }
  85644. static int test_get_signature_nid_on_hs_server(WOLFSSL_CTX **ctx, WOLFSSL **ssl)
  85645. {
  85646. EXPECT_DECLS;
  85647. int nid = 0;
  85648. (void)ctx;
  85649. ExpectIntEQ(SSL_get_signature_type_nid(*ssl, &nid), WOLFSSL_SUCCESS);
  85650. ExpectIntEQ(nid, test_get_signature_nid_sig);
  85651. ExpectIntEQ(SSL_get_signature_nid(*ssl, &nid), WOLFSSL_SUCCESS);
  85652. ExpectIntEQ(nid, test_get_signature_nid_hash);
  85653. return EXPECT_RESULT();
  85654. }
  85655. #endif
  85656. static int test_get_signature_nid(void)
  85657. {
  85658. EXPECT_DECLS;
  85659. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(OPENSSL_EXTRA)
  85660. test_ssl_cbf client_cbf;
  85661. test_ssl_cbf server_cbf;
  85662. size_t i;
  85663. #define TGSN_TLS12_RSA(sigalg, sig_nid, hash_nid) \
  85664. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_2, svrCertFile, svrKeyFile, \
  85665. caCertFile }
  85666. #define TGSN_TLS12_ECDSA(sigalg, sig_nid, hash_nid) \
  85667. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_2, eccCertFile, eccKeyFile, \
  85668. caEccCertFile }
  85669. #define TGSN_TLS13_RSA(sigalg, sig_nid, hash_nid) \
  85670. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_3, svrCertFile, svrKeyFile, \
  85671. caCertFile }
  85672. #define TGSN_TLS13_ECDSA(sigalg, sig_nid, hash_nid) \
  85673. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_3, eccCertFile, eccKeyFile, \
  85674. caEccCertFile }
  85675. #define TGSN_TLS13_ED25519(sigalg, sig_nid, hash_nid) \
  85676. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_3, edCertFile, edKeyFile, \
  85677. caEdCertFile }
  85678. #define TGSN_TLS13_ED448(sigalg, sig_nid, hash_nid) \
  85679. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_3, ed448CertFile, ed448KeyFile, \
  85680. caEd448CertFile }
  85681. struct {
  85682. const char* siglag;
  85683. int sig_nid;
  85684. int hash_nid;
  85685. int tls_ver;
  85686. const char* server_cert;
  85687. const char* server_key;
  85688. const char* client_ca;
  85689. } params[] = {
  85690. #ifndef NO_RSA
  85691. #ifndef NO_SHA256
  85692. TGSN_TLS12_RSA("RSA+SHA256", NID_rsaEncryption, NID_sha256),
  85693. #ifdef WC_RSA_PSS
  85694. TGSN_TLS12_RSA("RSA-PSS+SHA256", NID_rsassaPss, NID_sha256),
  85695. TGSN_TLS13_RSA("RSA-PSS+SHA256", NID_rsassaPss, NID_sha256),
  85696. #endif
  85697. #endif
  85698. #ifdef WOLFSSL_SHA512
  85699. TGSN_TLS12_RSA("RSA+SHA512", NID_rsaEncryption, NID_sha512),
  85700. #ifdef WC_RSA_PSS
  85701. TGSN_TLS12_RSA("RSA-PSS+SHA512", NID_rsassaPss, NID_sha512),
  85702. TGSN_TLS13_RSA("RSA-PSS+SHA512", NID_rsassaPss, NID_sha512),
  85703. #endif
  85704. #endif
  85705. #endif
  85706. #ifdef HAVE_ECC
  85707. #ifndef NO_SHA256
  85708. TGSN_TLS12_ECDSA("ECDSA+SHA256", NID_X9_62_id_ecPublicKey, NID_sha256),
  85709. TGSN_TLS13_ECDSA("ECDSA+SHA256", NID_X9_62_id_ecPublicKey, NID_sha256),
  85710. #endif
  85711. #endif
  85712. #ifdef HAVE_ED25519
  85713. TGSN_TLS13_ED25519("ED25519", NID_ED25519, NID_sha512),
  85714. #endif
  85715. #ifdef HAVE_ED448
  85716. TGSN_TLS13_ED448("ED448", NID_ED448, NID_sha512),
  85717. #endif
  85718. };
  85719. printf("\n");
  85720. for (i = 0; i < XELEM_CNT(params) && !EXPECT_FAIL(); i++) {
  85721. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  85722. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  85723. printf("Testing %s with %s...", tls_desc[params[i].tls_ver],
  85724. params[i].siglag);
  85725. switch (params[i].tls_ver) {
  85726. #ifndef WOLFSSL_NO_TLS12
  85727. case WOLFSSL_TLSV1_2:
  85728. client_cbf.method = wolfTLSv1_2_client_method;
  85729. server_cbf.method = wolfTLSv1_2_server_method;
  85730. break;
  85731. #endif
  85732. #ifdef WOLFSSL_TLS13
  85733. case WOLFSSL_TLSV1_3:
  85734. client_cbf.method = wolfTLSv1_3_client_method;
  85735. server_cbf.method = wolfTLSv1_3_server_method;
  85736. break;
  85737. #endif
  85738. default:
  85739. printf("skipping\n");
  85740. continue;
  85741. }
  85742. test_get_signature_nid_siglag = params[i].siglag;
  85743. test_get_signature_nid_sig = params[i].sig_nid;
  85744. test_get_signature_nid_hash = params[i].hash_nid;
  85745. client_cbf.ssl_ready = test_get_signature_nid_ssl_ready;
  85746. server_cbf.ssl_ready = test_get_signature_nid_ssl_ready;
  85747. client_cbf.on_handshake = test_get_signature_nid_on_hs_client;
  85748. server_cbf.on_handshake = test_get_signature_nid_on_hs_server;
  85749. server_cbf.certPemFile = params[i].server_cert;
  85750. server_cbf.keyPemFile = params[i].server_key;
  85751. client_cbf.caPemFile = params[i].client_ca;
  85752. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  85753. &server_cbf, NULL), TEST_SUCCESS);
  85754. if (EXPECT_SUCCESS())
  85755. printf("passed\n");
  85756. }
  85757. #endif
  85758. return EXPECT_RESULT();
  85759. }
  85760. #if !defined(NO_CERTS) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  85761. static word32 test_tls_cert_store_unchanged_HashCaTable(Signer** caTable)
  85762. {
  85763. #ifndef NO_MD5
  85764. enum wc_HashType hashType = WC_HASH_TYPE_MD5;
  85765. #elif !defined(NO_SHA)
  85766. enum wc_HashType hashType = WC_HASH_TYPE_SHA;
  85767. #elif !defined(NO_SHA256)
  85768. enum wc_HashType hashType = WC_HASH_TYPE_SHA256;
  85769. #else
  85770. #error "We need a digest to hash the Signer object"
  85771. #endif
  85772. byte hashBuf[WC_MAX_DIGEST_SIZE];
  85773. wc_HashAlg hash;
  85774. size_t i;
  85775. AssertIntEQ(wc_HashInit(&hash, hashType), 0);
  85776. for (i = 0; i < CA_TABLE_SIZE; i++) {
  85777. Signer* cur;
  85778. for (cur = caTable[i]; cur != NULL; cur = cur->next)
  85779. AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)cur,
  85780. sizeof(*cur)), 0);
  85781. }
  85782. AssertIntEQ(wc_HashFinal(&hash, hashType, hashBuf), 0);
  85783. AssertIntEQ(wc_HashFree(&hash, hashType), 0);
  85784. return MakeWordFromHash(hashBuf);
  85785. }
  85786. static word32 test_tls_cert_store_unchanged_before_hashes[2];
  85787. static size_t test_tls_cert_store_unchanged_before_hashes_idx;
  85788. static word32 test_tls_cert_store_unchanged_after_hashes[2];
  85789. static size_t test_tls_cert_store_unchanged_after_hashes_idx;
  85790. static int test_tls_cert_store_unchanged_ctx_ready(WOLFSSL_CTX* ctx)
  85791. {
  85792. EXPECT_DECLS;
  85793. ExpectIntNE(test_tls_cert_store_unchanged_before_hashes
  85794. [test_tls_cert_store_unchanged_before_hashes_idx++] =
  85795. test_tls_cert_store_unchanged_HashCaTable(ctx->cm->caTable), 0);
  85796. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER |
  85797. WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  85798. return EXPECT_RESULT();
  85799. }
  85800. static int test_tls_cert_store_unchanged_ctx_cleanup(WOLFSSL_CTX* ctx)
  85801. {
  85802. EXPECT_DECLS;
  85803. ExpectIntEQ(wolfSSL_CTX_UnloadIntermediateCerts(ctx), WOLFSSL_SUCCESS);
  85804. ExpectIntNE(test_tls_cert_store_unchanged_after_hashes
  85805. [test_tls_cert_store_unchanged_after_hashes_idx++] =
  85806. test_tls_cert_store_unchanged_HashCaTable(ctx->cm->caTable), 0);
  85807. return EXPECT_RESULT();
  85808. }
  85809. static int test_tls_cert_store_unchanged_on_hs(WOLFSSL_CTX **ctx, WOLFSSL **ssl)
  85810. {
  85811. EXPECT_DECLS;
  85812. WOLFSSL_CERT_MANAGER* cm;
  85813. (void)ssl;
  85814. /* WARNING: this approach bypasses the reference counter check in
  85815. * wolfSSL_CTX_UnloadIntermediateCerts. It is not recommended as it may
  85816. * cause unexpected behaviour when other active connections try accessing
  85817. * the caTable. */
  85818. ExpectNotNull(cm = wolfSSL_CTX_GetCertManager(*ctx));
  85819. ExpectIntEQ(wolfSSL_CertManagerUnloadIntermediateCerts(cm),
  85820. WOLFSSL_SUCCESS);
  85821. ExpectIntNE(test_tls_cert_store_unchanged_after_hashes
  85822. [test_tls_cert_store_unchanged_after_hashes_idx++] =
  85823. test_tls_cert_store_unchanged_HashCaTable((*ctx)->cm->caTable), 0);
  85824. return EXPECT_RESULT();
  85825. }
  85826. static int test_tls_cert_store_unchanged_ssl_ready(WOLFSSL* ssl)
  85827. {
  85828. EXPECT_DECLS;
  85829. WOLFSSL_CTX* ctx;
  85830. ExpectNotNull(ctx = wolfSSL_get_SSL_CTX(ssl));
  85831. return EXPECT_RESULT();
  85832. }
  85833. #endif
  85834. static int test_tls_cert_store_unchanged(void)
  85835. {
  85836. EXPECT_DECLS;
  85837. #if !defined(NO_CERTS) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  85838. test_ssl_cbf client_cbf;
  85839. test_ssl_cbf server_cbf;
  85840. int i;
  85841. for (i = 0; i < 2; i++) {
  85842. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  85843. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  85844. test_tls_cert_store_unchanged_before_hashes_idx = 0;
  85845. XMEMSET(test_tls_cert_store_unchanged_before_hashes, 0,
  85846. sizeof(test_tls_cert_store_unchanged_before_hashes));
  85847. test_tls_cert_store_unchanged_after_hashes_idx = 0;
  85848. XMEMSET(test_tls_cert_store_unchanged_after_hashes, 0,
  85849. sizeof(test_tls_cert_store_unchanged_after_hashes));
  85850. client_cbf.ctx_ready = test_tls_cert_store_unchanged_ctx_ready;
  85851. server_cbf.ctx_ready = test_tls_cert_store_unchanged_ctx_ready;
  85852. client_cbf.ssl_ready = test_tls_cert_store_unchanged_ssl_ready;
  85853. server_cbf.ssl_ready = test_tls_cert_store_unchanged_ssl_ready;
  85854. switch (i) {
  85855. case 0:
  85856. client_cbf.on_ctx_cleanup =
  85857. test_tls_cert_store_unchanged_ctx_cleanup;
  85858. server_cbf.on_ctx_cleanup =
  85859. test_tls_cert_store_unchanged_ctx_cleanup;
  85860. break;
  85861. case 1:
  85862. client_cbf.on_handshake = test_tls_cert_store_unchanged_on_hs;
  85863. server_cbf.on_handshake = test_tls_cert_store_unchanged_on_hs;
  85864. break;
  85865. default:
  85866. Fail(("Should not enter here"), ("Entered here"));
  85867. }
  85868. client_cbf.certPemFile = "certs/intermediate/client-chain.pem";
  85869. server_cbf.certPemFile = "certs/intermediate/server-chain.pem";
  85870. server_cbf.caPemFile = caCertFile;
  85871. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  85872. &server_cbf, NULL), TEST_SUCCESS);
  85873. ExpectBufEQ(test_tls_cert_store_unchanged_before_hashes,
  85874. test_tls_cert_store_unchanged_after_hashes,
  85875. sizeof(test_tls_cert_store_unchanged_after_hashes));
  85876. }
  85877. #endif
  85878. return EXPECT_RESULT();
  85879. }
  85880. static int test_wolfSSL_SendUserCanceled(void)
  85881. {
  85882. EXPECT_DECLS;
  85883. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  85884. size_t i;
  85885. struct {
  85886. method_provider client_meth;
  85887. method_provider server_meth;
  85888. const char* tls_version;
  85889. } params[] = {
  85890. #if defined(WOLFSSL_TLS13)
  85891. /* With WOLFSSL_TLS13_MIDDLEBOX_COMPAT a short ID will result in an error */
  85892. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLSv1_3" },
  85893. #ifdef WOLFSSL_DTLS13
  85894. { wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, "DTLSv1_3" },
  85895. #endif
  85896. #endif
  85897. #ifndef WOLFSSL_NO_TLS12
  85898. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLSv1_2" },
  85899. #ifdef WOLFSSL_DTLS
  85900. { wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, "DTLSv1_2" },
  85901. #endif
  85902. #endif
  85903. #if !defined(NO_OLD_TLS)
  85904. { wolfTLSv1_1_client_method, wolfTLSv1_1_server_method, "TLSv1_1" },
  85905. #ifdef WOLFSSL_DTLS
  85906. { wolfDTLSv1_client_method, wolfDTLSv1_server_method, "DTLSv1_0" },
  85907. #endif
  85908. #endif
  85909. };
  85910. for (i = 0; i < sizeof(params)/sizeof(*params) && !EXPECT_FAIL(); i++) {
  85911. WOLFSSL_CTX *ctx_c = NULL;
  85912. WOLFSSL_CTX *ctx_s = NULL;
  85913. WOLFSSL *ssl_c = NULL;
  85914. WOLFSSL *ssl_s = NULL;
  85915. struct test_memio_ctx test_ctx;
  85916. WOLFSSL_ALERT_HISTORY h;
  85917. printf("Testing %s\n", params[i].tls_version);
  85918. XMEMSET(&h, 0, sizeof(h));
  85919. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85920. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  85921. params[i].client_meth, params[i].server_meth), 0);
  85922. /* CH1 */
  85923. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85924. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85925. ExpectIntEQ(wolfSSL_SendUserCanceled(ssl_s), WOLFSSL_SHUTDOWN_NOT_DONE);
  85926. /* Alert closed connection */
  85927. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85928. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_ZERO_RETURN);
  85929. /* Last alert will be close notify because user_canceled should be
  85930. * followed by a close_notify */
  85931. ExpectIntEQ(wolfSSL_get_alert_history(ssl_c, &h), WOLFSSL_SUCCESS);
  85932. ExpectIntEQ(h.last_rx.code, close_notify);
  85933. ExpectIntEQ(h.last_rx.level, alert_warning);
  85934. wolfSSL_free(ssl_c);
  85935. wolfSSL_free(ssl_s);
  85936. wolfSSL_CTX_free(ctx_c);
  85937. wolfSSL_CTX_free(ctx_s);
  85938. }
  85939. #endif
  85940. return EXPECT_RESULT();
  85941. }
  85942. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
  85943. defined(HAVE_OCSP) && \
  85944. defined(HAVE_CERTIFICATE_STATUS_REQUEST) && \
  85945. !defined(WOLFSSL_NO_TLS12)
  85946. static int test_ocsp_callback_fails_cb(void* ctx, const char* url, int urlSz,
  85947. byte* ocspReqBuf, int ocspReqSz, byte** ocspRespBuf)
  85948. {
  85949. (void)ctx;
  85950. (void)url;
  85951. (void)urlSz;
  85952. (void)ocspReqBuf;
  85953. (void)ocspReqSz;
  85954. (void)ocspRespBuf;
  85955. return -1;
  85956. }
  85957. static int test_ocsp_callback_fails(void)
  85958. {
  85959. WOLFSSL_CTX *ctx_c = NULL;
  85960. WOLFSSL_CTX *ctx_s = NULL;
  85961. WOLFSSL *ssl_c = NULL;
  85962. WOLFSSL *ssl_s = NULL;
  85963. struct test_memio_ctx test_ctx;
  85964. EXPECT_DECLS;
  85965. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85966. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  85967. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  85968. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx_c), WOLFSSL_SUCCESS);
  85969. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx_s), WOLFSSL_SUCCESS);
  85970. ExpectIntEQ(wolfSSL_UseOCSPStapling(ssl_c, WOLFSSL_CSR_OCSP,0), WOLFSSL_SUCCESS);
  85971. /* override URL to avoid exing from SendCertificateStatus because of no AuthInfo on the certificate */
  85972. ExpectIntEQ(wolfSSL_CTX_SetOCSP_OverrideURL(ctx_s, "http://dummy.test"), WOLFSSL_SUCCESS);
  85973. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx_s, WOLFSSL_OCSP_NO_NONCE | WOLFSSL_OCSP_URL_OVERRIDE), WOLFSSL_SUCCESS);
  85974. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx_s, caCertFile, 0), WOLFSSL_SUCCESS);
  85975. ExpectIntEQ(wolfSSL_SetOCSP_Cb(ssl_s, test_ocsp_callback_fails_cb, NULL, NULL), WOLFSSL_SUCCESS);
  85976. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), -1);
  85977. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WC_NO_ERR_TRACE(OCSP_INVALID_STATUS));
  85978. wolfSSL_free(ssl_c);
  85979. wolfSSL_free(ssl_s);
  85980. wolfSSL_CTX_free(ctx_c);
  85981. wolfSSL_CTX_free(ctx_s);
  85982. return EXPECT_RESULT();
  85983. }
  85984. #else
  85985. static int test_ocsp_callback_fails(void)
  85986. {
  85987. return TEST_SKIPPED;
  85988. }
  85989. #endif /* defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
  85990. defined(HAVE_OCSP) && \
  85991. defined(HAVE_CERTIFICATE_STATUS_REQUEST) */
  85992. /*----------------------------------------------------------------------------*
  85993. | Main
  85994. *----------------------------------------------------------------------------*/
  85995. typedef int (*TEST_FUNC)(void);
  85996. typedef struct {
  85997. const char *name;
  85998. TEST_FUNC func;
  85999. byte run:1;
  86000. byte fail:1;
  86001. } TEST_CASE;
  86002. #define TEST_DECL(func) { #func, func, 0, 0 }
  86003. int testAll = 1;
  86004. TEST_CASE testCases[] = {
  86005. TEST_DECL(test_fileAccess),
  86006. /*********************************
  86007. * wolfcrypt
  86008. *********************************/
  86009. TEST_DECL(test_ForceZero),
  86010. TEST_DECL(test_wolfCrypt_Init),
  86011. TEST_DECL(test_wc_LoadStaticMemory_ex),
  86012. /* Locking with Compat Mutex */
  86013. TEST_DECL(test_wc_SetMutexCb),
  86014. TEST_DECL(test_wc_LockMutex_ex),
  86015. /* Digests */
  86016. TEST_DECL(test_wc_InitMd5),
  86017. TEST_DECL(test_wc_Md5Update),
  86018. TEST_DECL(test_wc_Md5Final),
  86019. TEST_DECL(test_wc_InitSha),
  86020. TEST_DECL(test_wc_ShaUpdate),
  86021. TEST_DECL(test_wc_ShaFinal),
  86022. TEST_DECL(test_wc_InitSha256),
  86023. TEST_DECL(test_wc_Sha256Update),
  86024. TEST_DECL(test_wc_Sha256Final),
  86025. TEST_DECL(test_wc_Sha256FinalRaw),
  86026. TEST_DECL(test_wc_Sha256GetFlags),
  86027. TEST_DECL(test_wc_Sha256Free),
  86028. TEST_DECL(test_wc_Sha256GetHash),
  86029. TEST_DECL(test_wc_Sha256Copy),
  86030. TEST_DECL(test_wc_InitSha224),
  86031. TEST_DECL(test_wc_Sha224Update),
  86032. TEST_DECL(test_wc_Sha224Final),
  86033. TEST_DECL(test_wc_Sha224SetFlags),
  86034. TEST_DECL(test_wc_Sha224GetFlags),
  86035. TEST_DECL(test_wc_Sha224Free),
  86036. TEST_DECL(test_wc_Sha224GetHash),
  86037. TEST_DECL(test_wc_Sha224Copy),
  86038. TEST_DECL(test_wc_InitSha512),
  86039. TEST_DECL(test_wc_Sha512Update),
  86040. TEST_DECL(test_wc_Sha512Final),
  86041. TEST_DECL(test_wc_Sha512GetFlags),
  86042. TEST_DECL(test_wc_Sha512FinalRaw),
  86043. TEST_DECL(test_wc_Sha512Free),
  86044. TEST_DECL(test_wc_Sha512GetHash),
  86045. TEST_DECL(test_wc_Sha512Copy),
  86046. TEST_DECL(test_wc_InitSha512_224),
  86047. TEST_DECL(test_wc_Sha512_224Update),
  86048. TEST_DECL(test_wc_Sha512_224Final),
  86049. TEST_DECL(test_wc_Sha512_224GetFlags),
  86050. TEST_DECL(test_wc_Sha512_224FinalRaw),
  86051. TEST_DECL(test_wc_Sha512_224Free),
  86052. TEST_DECL(test_wc_Sha512_224GetHash),
  86053. TEST_DECL(test_wc_Sha512_224Copy),
  86054. TEST_DECL(test_wc_InitSha512_256),
  86055. TEST_DECL(test_wc_Sha512_256Update),
  86056. TEST_DECL(test_wc_Sha512_256Final),
  86057. TEST_DECL(test_wc_Sha512_256GetFlags),
  86058. TEST_DECL(test_wc_Sha512_256FinalRaw),
  86059. TEST_DECL(test_wc_Sha512_256Free),
  86060. TEST_DECL(test_wc_Sha512_256GetHash),
  86061. TEST_DECL(test_wc_Sha512_256Copy),
  86062. TEST_DECL(test_wc_InitSha384),
  86063. TEST_DECL(test_wc_Sha384Update),
  86064. TEST_DECL(test_wc_Sha384Final),
  86065. TEST_DECL(test_wc_Sha384GetFlags),
  86066. TEST_DECL(test_wc_Sha384FinalRaw),
  86067. TEST_DECL(test_wc_Sha384Free),
  86068. TEST_DECL(test_wc_Sha384GetHash),
  86069. TEST_DECL(test_wc_Sha384Copy),
  86070. TEST_DECL(test_wc_InitBlake2b),
  86071. TEST_DECL(test_wc_InitBlake2b_WithKey),
  86072. TEST_DECL(test_wc_InitBlake2s_WithKey),
  86073. TEST_DECL(test_wc_InitRipeMd),
  86074. TEST_DECL(test_wc_RipeMdUpdate),
  86075. TEST_DECL(test_wc_RipeMdFinal),
  86076. TEST_DECL(test_wc_InitSha3),
  86077. TEST_DECL(testing_wc_Sha3_Update),
  86078. TEST_DECL(test_wc_Sha3_224_Final),
  86079. TEST_DECL(test_wc_Sha3_256_Final),
  86080. TEST_DECL(test_wc_Sha3_384_Final),
  86081. TEST_DECL(test_wc_Sha3_512_Final),
  86082. TEST_DECL(test_wc_Sha3_224_Copy),
  86083. TEST_DECL(test_wc_Sha3_256_Copy),
  86084. TEST_DECL(test_wc_Sha3_384_Copy),
  86085. TEST_DECL(test_wc_Sha3_512_Copy),
  86086. TEST_DECL(test_wc_Sha3_GetFlags),
  86087. TEST_DECL(test_wc_InitShake256),
  86088. TEST_DECL(testing_wc_Shake256_Update),
  86089. TEST_DECL(test_wc_Shake256_Final),
  86090. TEST_DECL(test_wc_Shake256_Copy),
  86091. TEST_DECL(test_wc_Shake256Hash),
  86092. /* SM3 Digest */
  86093. TEST_DECL(test_wc_InitSm3Free),
  86094. TEST_DECL(test_wc_Sm3UpdateFinal),
  86095. TEST_DECL(test_wc_Sm3GetHash),
  86096. TEST_DECL(test_wc_Sm3Copy),
  86097. TEST_DECL(test_wc_Sm3FinalRaw),
  86098. TEST_DECL(test_wc_Sm3GetSetFlags),
  86099. TEST_DECL(test_wc_Sm3Hash),
  86100. TEST_DECL(test_wc_HashInit),
  86101. TEST_DECL(test_wc_HashSetFlags),
  86102. TEST_DECL(test_wc_HashGetFlags),
  86103. /* HMAC */
  86104. TEST_DECL(test_wc_Md5HmacSetKey),
  86105. TEST_DECL(test_wc_Md5HmacUpdate),
  86106. TEST_DECL(test_wc_Md5HmacFinal),
  86107. TEST_DECL(test_wc_ShaHmacSetKey),
  86108. TEST_DECL(test_wc_ShaHmacUpdate),
  86109. TEST_DECL(test_wc_ShaHmacFinal),
  86110. TEST_DECL(test_wc_Sha224HmacSetKey),
  86111. TEST_DECL(test_wc_Sha224HmacUpdate),
  86112. TEST_DECL(test_wc_Sha224HmacFinal),
  86113. TEST_DECL(test_wc_Sha256HmacSetKey),
  86114. TEST_DECL(test_wc_Sha256HmacUpdate),
  86115. TEST_DECL(test_wc_Sha256HmacFinal),
  86116. TEST_DECL(test_wc_Sha384HmacSetKey),
  86117. TEST_DECL(test_wc_Sha384HmacUpdate),
  86118. TEST_DECL(test_wc_Sha384HmacFinal),
  86119. /* CMAC */
  86120. TEST_DECL(test_wc_InitCmac),
  86121. TEST_DECL(test_wc_CmacUpdate),
  86122. TEST_DECL(test_wc_CmacFinal),
  86123. TEST_DECL(test_wc_AesCmacGenerate),
  86124. /* Cipher */
  86125. TEST_DECL(test_wc_AesGcmStream),
  86126. TEST_DECL(test_wc_Des3_SetIV),
  86127. TEST_DECL(test_wc_Des3_SetKey),
  86128. TEST_DECL(test_wc_Des3_CbcEncryptDecrypt),
  86129. TEST_DECL(test_wc_Des3_CbcEncryptDecryptWithKey),
  86130. TEST_DECL(test_wc_Des3_EcbEncrypt),
  86131. TEST_DECL(test_wc_Chacha_SetKey),
  86132. TEST_DECL(test_wc_Chacha_Process),
  86133. TEST_DECL(test_wc_ChaCha20Poly1305_aead),
  86134. TEST_DECL(test_wc_Poly1305SetKey),
  86135. TEST_DECL(test_wc_CamelliaSetKey),
  86136. TEST_DECL(test_wc_CamelliaSetIV),
  86137. TEST_DECL(test_wc_CamelliaEncryptDecryptDirect),
  86138. TEST_DECL(test_wc_CamelliaCbcEncryptDecrypt),
  86139. TEST_DECL(test_wc_Arc4SetKey),
  86140. TEST_DECL(test_wc_Arc4Process),
  86141. TEST_DECL(test_wc_Rc2SetKey),
  86142. TEST_DECL(test_wc_Rc2SetIV),
  86143. TEST_DECL(test_wc_Rc2EcbEncryptDecrypt),
  86144. TEST_DECL(test_wc_Rc2CbcEncryptDecrypt),
  86145. /* AES cipher and GMAC. */
  86146. TEST_DECL(test_wc_AesSetKey),
  86147. TEST_DECL(test_wc_AesSetIV),
  86148. TEST_DECL(test_wc_AesCbcEncryptDecrypt),
  86149. TEST_DECL(test_wc_AesCtrEncryptDecrypt),
  86150. TEST_DECL(test_wc_AesGcmSetKey),
  86151. TEST_DECL(test_wc_AesGcmEncryptDecrypt),
  86152. TEST_DECL(test_wc_AesGcmMixedEncDecLongIV),
  86153. TEST_DECL(test_wc_GmacSetKey),
  86154. TEST_DECL(test_wc_GmacUpdate),
  86155. TEST_DECL(test_wc_AesCcmSetKey),
  86156. TEST_DECL(test_wc_AesCcmEncryptDecrypt),
  86157. #if defined(WOLFSSL_AES_EAX) && \
  86158. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  86159. TEST_DECL(test_wc_AesEaxVectors),
  86160. TEST_DECL(test_wc_AesEaxEncryptAuth),
  86161. TEST_DECL(test_wc_AesEaxDecryptAuth),
  86162. #endif /* WOLFSSL_AES_EAX */
  86163. /* SM4 cipher */
  86164. TEST_DECL(test_wc_Sm4),
  86165. TEST_DECL(test_wc_Sm4Ecb),
  86166. TEST_DECL(test_wc_Sm4Cbc),
  86167. TEST_DECL(test_wc_Sm4Ctr),
  86168. TEST_DECL(test_wc_Sm4Gcm),
  86169. TEST_DECL(test_wc_Sm4Ccm),
  86170. /* RNG tests */
  86171. #ifdef HAVE_HASHDRBG
  86172. #ifdef TEST_RESEED_INTERVAL
  86173. TEST_DECL(test_wc_RNG_GenerateBlock_Reseed),
  86174. #endif
  86175. TEST_DECL(test_wc_RNG_GenerateBlock),
  86176. #endif
  86177. TEST_DECL(test_get_rand_digit),
  86178. TEST_DECL(test_wc_InitRngNonce),
  86179. TEST_DECL(test_wc_InitRngNonce_ex),
  86180. /* MP API tests */
  86181. TEST_DECL(test_get_digit_count),
  86182. TEST_DECL(test_mp_cond_copy),
  86183. TEST_DECL(test_mp_rand),
  86184. TEST_DECL(test_get_digit),
  86185. TEST_DECL(test_wc_export_int),
  86186. /* RSA */
  86187. TEST_DECL(test_wc_InitRsaKey),
  86188. TEST_DECL(test_wc_RsaPrivateKeyDecode),
  86189. TEST_DECL(test_wc_RsaPublicKeyDecode),
  86190. TEST_DECL(test_wc_RsaPublicKeyDecodeRaw),
  86191. TEST_DECL(test_wc_RsaPrivateKeyDecodeRaw),
  86192. TEST_DECL(test_wc_MakeRsaKey),
  86193. TEST_DECL(test_wc_CheckProbablePrime),
  86194. TEST_DECL(test_wc_RsaPSS_Verify),
  86195. TEST_DECL(test_wc_RsaPSS_VerifyCheck),
  86196. TEST_DECL(test_wc_RsaPSS_VerifyCheckInline),
  86197. TEST_DECL(test_wc_RsaKeyToDer),
  86198. TEST_DECL(test_wc_RsaKeyToPublicDer),
  86199. TEST_DECL(test_wc_RsaPublicEncryptDecrypt),
  86200. TEST_DECL(test_wc_RsaPublicEncryptDecrypt_ex),
  86201. TEST_DECL(test_wc_RsaEncryptSize),
  86202. TEST_DECL(test_wc_RsaSSL_SignVerify),
  86203. TEST_DECL(test_wc_RsaFlattenPublicKey),
  86204. TEST_DECL(test_RsaDecryptBoundsCheck),
  86205. /* DSA */
  86206. TEST_DECL(test_wc_InitDsaKey),
  86207. TEST_DECL(test_wc_DsaSignVerify),
  86208. TEST_DECL(test_wc_DsaPublicPrivateKeyDecode),
  86209. TEST_DECL(test_wc_MakeDsaKey),
  86210. TEST_DECL(test_wc_DsaKeyToDer),
  86211. TEST_DECL(test_wc_DsaKeyToPublicDer),
  86212. TEST_DECL(test_wc_DsaImportParamsRaw),
  86213. TEST_DECL(test_wc_DsaImportParamsRawCheck),
  86214. TEST_DECL(test_wc_DsaExportParamsRaw),
  86215. TEST_DECL(test_wc_DsaExportKeyRaw),
  86216. /* DH */
  86217. TEST_DECL(test_wc_DhPublicKeyDecode),
  86218. /* wolfCrypt ECC tests */
  86219. TEST_DECL(test_wc_ecc_get_curve_size_from_name),
  86220. TEST_DECL(test_wc_ecc_get_curve_id_from_name),
  86221. TEST_DECL(test_wc_ecc_get_curve_id_from_params),
  86222. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && \
  86223. !defined(HAVE_SELFTEST) && \
  86224. !(defined(HAVE_FIPS) || defined(HAVE_FIPS_VERSION))
  86225. TEST_DECL(test_wc_ecc_get_curve_id_from_dp_params),
  86226. #endif
  86227. TEST_DECL(test_wc_ecc_make_key),
  86228. TEST_DECL(test_wc_ecc_init),
  86229. TEST_DECL(test_wc_ecc_check_key),
  86230. TEST_DECL(test_wc_ecc_get_generator),
  86231. TEST_DECL(test_wc_ecc_size),
  86232. TEST_DECL(test_wc_ecc_params),
  86233. TEST_DECL(test_wc_ecc_signVerify_hash),
  86234. TEST_DECL(test_wc_ecc_shared_secret),
  86235. TEST_DECL(test_wc_ecc_export_x963),
  86236. TEST_DECL(test_wc_ecc_export_x963_ex),
  86237. TEST_DECL(test_wc_ecc_import_x963),
  86238. TEST_DECL(test_wc_ecc_import_private_key),
  86239. TEST_DECL(test_wc_ecc_export_private_only),
  86240. TEST_DECL(test_wc_ecc_rs_to_sig),
  86241. TEST_DECL(test_wc_ecc_import_raw),
  86242. TEST_DECL(test_wc_ecc_import_unsigned),
  86243. TEST_DECL(test_wc_ecc_sig_size),
  86244. TEST_DECL(test_wc_ecc_ctx_new),
  86245. TEST_DECL(test_wc_ecc_ctx_reset),
  86246. TEST_DECL(test_wc_ecc_ctx_set_peer_salt),
  86247. TEST_DECL(test_wc_ecc_ctx_set_info),
  86248. TEST_DECL(test_wc_ecc_encryptDecrypt),
  86249. TEST_DECL(test_wc_ecc_del_point),
  86250. TEST_DECL(test_wc_ecc_pointFns),
  86251. TEST_DECL(test_wc_ecc_shared_secret_ssh),
  86252. TEST_DECL(test_wc_ecc_verify_hash_ex),
  86253. TEST_DECL(test_wc_ecc_mulmod),
  86254. TEST_DECL(test_wc_ecc_is_valid_idx),
  86255. TEST_DECL(test_wc_ecc_get_curve_id_from_oid),
  86256. TEST_DECL(test_wc_ecc_sig_size_calc),
  86257. TEST_DECL(test_wc_EccPrivateKeyToDer),
  86258. /* SM2 elliptic curve */
  86259. TEST_DECL(test_wc_ecc_sm2_make_key),
  86260. TEST_DECL(test_wc_ecc_sm2_shared_secret),
  86261. TEST_DECL(test_wc_ecc_sm2_create_digest),
  86262. TEST_DECL(test_wc_ecc_sm2_verify_hash_ex),
  86263. TEST_DECL(test_wc_ecc_sm2_verify_hash),
  86264. TEST_DECL(test_wc_ecc_sm2_sign_hash_ex),
  86265. TEST_DECL(test_wc_ecc_sm2_sign_hash),
  86266. /* Curve25519 */
  86267. TEST_DECL(test_wc_curve25519_init),
  86268. TEST_DECL(test_wc_curve25519_size),
  86269. TEST_DECL(test_wc_curve25519_export_key_raw),
  86270. TEST_DECL(test_wc_curve25519_export_key_raw_ex),
  86271. TEST_DECL(test_wc_curve25519_make_key),
  86272. TEST_DECL(test_wc_curve25519_shared_secret_ex),
  86273. TEST_DECL(test_wc_curve25519_make_pub),
  86274. TEST_DECL(test_wc_curve25519_export_public_ex),
  86275. TEST_DECL(test_wc_curve25519_export_private_raw_ex),
  86276. TEST_DECL(test_wc_curve25519_import_private_raw_ex),
  86277. TEST_DECL(test_wc_curve25519_import_private),
  86278. /* ED25519 */
  86279. TEST_DECL(test_wc_ed25519_make_key),
  86280. TEST_DECL(test_wc_ed25519_init),
  86281. TEST_DECL(test_wc_ed25519_sign_msg),
  86282. TEST_DECL(test_wc_ed25519_import_public),
  86283. TEST_DECL(test_wc_ed25519_import_private_key),
  86284. TEST_DECL(test_wc_ed25519_export),
  86285. TEST_DECL(test_wc_ed25519_size),
  86286. TEST_DECL(test_wc_ed25519_exportKey),
  86287. TEST_DECL(test_wc_Ed25519PublicKeyToDer),
  86288. TEST_DECL(test_wc_Ed25519KeyToDer),
  86289. TEST_DECL(test_wc_Ed25519PrivateKeyToDer),
  86290. /* Curve448 */
  86291. TEST_DECL(test_wc_curve448_make_key),
  86292. TEST_DECL(test_wc_curve448_shared_secret_ex),
  86293. TEST_DECL(test_wc_curve448_export_public_ex),
  86294. TEST_DECL(test_wc_curve448_export_private_raw_ex),
  86295. TEST_DECL(test_wc_curve448_export_key_raw),
  86296. TEST_DECL(test_wc_curve448_import_private_raw_ex),
  86297. TEST_DECL(test_wc_curve448_import_private),
  86298. TEST_DECL(test_wc_curve448_init),
  86299. TEST_DECL(test_wc_curve448_size),
  86300. /* Ed448 */
  86301. TEST_DECL(test_wc_ed448_make_key),
  86302. TEST_DECL(test_wc_ed448_init),
  86303. TEST_DECL(test_wc_ed448_sign_msg),
  86304. TEST_DECL(test_wc_ed448_import_public),
  86305. TEST_DECL(test_wc_ed448_import_private_key),
  86306. TEST_DECL(test_wc_ed448_export),
  86307. TEST_DECL(test_wc_ed448_size),
  86308. TEST_DECL(test_wc_ed448_exportKey),
  86309. TEST_DECL(test_wc_Ed448PublicKeyToDer),
  86310. TEST_DECL(test_wc_Ed448KeyToDer),
  86311. TEST_DECL(test_wc_Ed448PrivateKeyToDer),
  86312. TEST_DECL(test_wc_Curve448PrivateKeyToDer),
  86313. /* Kyber */
  86314. TEST_DECL(test_wc_kyber_make_key_kats),
  86315. TEST_DECL(test_wc_kyber_encapsulate_kats),
  86316. TEST_DECL(test_wc_kyber_decapsulate_kats),
  86317. /* Dilithium */
  86318. TEST_DECL(test_wc_dilithium),
  86319. TEST_DECL(test_wc_dilithium_make_key),
  86320. TEST_DECL(test_wc_dilithium_sign),
  86321. TEST_DECL(test_wc_dilithium_verify),
  86322. TEST_DECL(test_wc_dilithium_sign_vfy),
  86323. TEST_DECL(test_wc_dilithium_check_key),
  86324. TEST_DECL(test_wc_dilithium_public_der_decode),
  86325. TEST_DECL(test_wc_dilithium_der),
  86326. TEST_DECL(test_wc_dilithium_make_key_from_seed),
  86327. TEST_DECL(test_wc_dilithium_sig_kats),
  86328. TEST_DECL(test_wc_dilithium_verify_kats),
  86329. /* Signature API */
  86330. TEST_DECL(test_wc_SignatureGetSize_ecc),
  86331. TEST_DECL(test_wc_SignatureGetSize_rsa),
  86332. /* PEM and DER APIs. */
  86333. TEST_DECL(test_wc_PemToDer),
  86334. TEST_DECL(test_wc_AllocDer),
  86335. TEST_DECL(test_wc_CertPemToDer),
  86336. TEST_DECL(test_wc_KeyPemToDer),
  86337. TEST_DECL(test_wc_PubKeyPemToDer),
  86338. TEST_DECL(test_wc_PemPubKeyToDer),
  86339. TEST_DECL(test_wc_GetPubKeyDerFromCert),
  86340. TEST_DECL(test_wc_CheckCertSigPubKey),
  86341. /* wolfCrypt ASN tests */
  86342. TEST_DECL(test_ToTraditional),
  86343. TEST_DECL(test_wc_CreateEncryptedPKCS8Key),
  86344. TEST_DECL(test_wc_GetPkcs8TraditionalOffset),
  86345. /* Certificate */
  86346. TEST_DECL(test_wc_SetSubjectRaw),
  86347. TEST_DECL(test_wc_GetSubjectRaw),
  86348. TEST_DECL(test_wc_SetIssuerRaw),
  86349. TEST_DECL(test_wc_SetIssueBuffer),
  86350. TEST_DECL(test_wc_SetSubjectKeyId),
  86351. TEST_DECL(test_wc_SetSubject),
  86352. TEST_DECL(test_CheckCertSignature),
  86353. TEST_DECL(test_wc_ParseCert),
  86354. TEST_DECL(test_wc_ParseCert_Error),
  86355. TEST_DECL(test_MakeCertWithPathLen),
  86356. TEST_DECL(test_MakeCertWith0Ser),
  86357. TEST_DECL(test_MakeCertWithCaFalse),
  86358. TEST_DECL(test_wc_SetKeyUsage),
  86359. TEST_DECL(test_wc_SetAuthKeyIdFromPublicKey_ex),
  86360. TEST_DECL(test_wc_SetSubjectBuffer),
  86361. TEST_DECL(test_wc_SetSubjectKeyIdFromPublicKey_ex),
  86362. /* wolfcrypt PKCS#7 */
  86363. TEST_DECL(test_wc_PKCS7_New),
  86364. TEST_DECL(test_wc_PKCS7_Init),
  86365. TEST_DECL(test_wc_PKCS7_InitWithCert),
  86366. TEST_DECL(test_wc_PKCS7_EncodeData),
  86367. TEST_DECL(test_wc_PKCS7_EncodeSignedData),
  86368. TEST_DECL(test_wc_PKCS7_EncodeSignedData_ex),
  86369. TEST_DECL(test_wc_PKCS7_VerifySignedData_RSA),
  86370. TEST_DECL(test_wc_PKCS7_VerifySignedData_ECC),
  86371. TEST_DECL(test_wc_PKCS7_EncodeDecodeEnvelopedData),
  86372. TEST_DECL(test_wc_PKCS7_EncodeEncryptedData),
  86373. TEST_DECL(test_wc_PKCS7_Degenerate),
  86374. TEST_DECL(test_wc_PKCS7_BER),
  86375. TEST_DECL(test_wc_PKCS7_signed_enveloped),
  86376. TEST_DECL(test_wc_PKCS7_NoDefaultSignedAttribs),
  86377. TEST_DECL(test_wc_PKCS7_SetOriEncryptCtx),
  86378. TEST_DECL(test_wc_PKCS7_SetOriDecryptCtx),
  86379. TEST_DECL(test_wc_PKCS7_DecodeCompressedData),
  86380. /* wolfCrypt PKCS#12 */
  86381. TEST_DECL(test_wc_i2d_PKCS12),
  86382. /*
  86383. * test_wolfCrypt_Cleanup needs to come after the above wolfCrypt tests to
  86384. * avoid memory leaks.
  86385. */
  86386. TEST_DECL(test_wolfCrypt_Cleanup),
  86387. TEST_DECL(test_wolfSSL_Init),
  86388. TEST_DECL(test_dual_alg_support),
  86389. /*********************************
  86390. * OpenSSL compatibility API tests
  86391. *********************************/
  86392. /* If at some point a stub get implemented this test should fail indicating
  86393. * a need to implement a new test case
  86394. */
  86395. TEST_DECL(test_stubs_are_stubs),
  86396. /* ASN.1 compatibility API tests */
  86397. TEST_DECL(test_wolfSSL_ASN1_BIT_STRING),
  86398. TEST_DECL(test_wolfSSL_ASN1_INTEGER),
  86399. TEST_DECL(test_wolfSSL_ASN1_INTEGER_cmp),
  86400. TEST_DECL(test_wolfSSL_ASN1_INTEGER_BN),
  86401. TEST_DECL(test_wolfSSL_ASN1_INTEGER_get_set),
  86402. TEST_DECL(test_wolfSSL_d2i_ASN1_INTEGER),
  86403. TEST_DECL(test_wolfSSL_a2i_ASN1_INTEGER),
  86404. TEST_DECL(test_wolfSSL_i2c_ASN1_INTEGER),
  86405. TEST_DECL(test_wolfSSL_ASN1_OBJECT),
  86406. TEST_DECL(test_wolfSSL_ASN1_get_object),
  86407. TEST_DECL(test_wolfSSL_i2a_ASN1_OBJECT),
  86408. TEST_DECL(test_wolfSSL_i2t_ASN1_OBJECT),
  86409. TEST_DECL(test_wolfSSL_sk_ASN1_OBJECT),
  86410. TEST_DECL(test_wolfSSL_ASN1_STRING),
  86411. TEST_DECL(test_wolfSSL_ASN1_STRING_to_UTF8),
  86412. TEST_DECL(test_wolfSSL_i2s_ASN1_STRING),
  86413. TEST_DECL(test_wolfSSL_ASN1_STRING_canon),
  86414. TEST_DECL(test_wolfSSL_ASN1_STRING_print),
  86415. TEST_DECL(test_wolfSSL_ASN1_STRING_print_ex),
  86416. TEST_DECL(test_wolfSSL_ASN1_UNIVERSALSTRING_to_string),
  86417. TEST_DECL(test_wolfSSL_ASN1_GENERALIZEDTIME_free),
  86418. TEST_DECL(test_wolfSSL_ASN1_GENERALIZEDTIME_print),
  86419. TEST_DECL(test_wolfSSL_ASN1_TIME),
  86420. TEST_DECL(test_wolfSSL_ASN1_TIME_to_string),
  86421. TEST_DECL(test_wolfSSL_ASN1_TIME_diff_compare),
  86422. TEST_DECL(test_wolfSSL_ASN1_TIME_adj),
  86423. TEST_DECL(test_wolfSSL_ASN1_TIME_to_tm),
  86424. TEST_DECL(test_wolfSSL_ASN1_TIME_to_generalizedtime),
  86425. TEST_DECL(test_wolfSSL_ASN1_TIME_print),
  86426. TEST_DECL(test_wolfSSL_ASN1_UTCTIME_print),
  86427. TEST_DECL(test_wolfSSL_ASN1_TYPE),
  86428. TEST_DECL(test_wolfSSL_IMPLEMENT_ASN1_FUNCTIONS),
  86429. TEST_DECL(test_wolfSSL_i2d_ASN1_TYPE),
  86430. TEST_DECL(test_wolfSSL_i2d_ASN1_SEQUENCE),
  86431. TEST_DECL(test_ASN1_strings),
  86432. TEST_DECL(test_wolfSSL_lhash),
  86433. TEST_DECL(test_wolfSSL_certs),
  86434. TEST_DECL(test_wolfSSL_private_keys),
  86435. TEST_DECL(test_wolfSSL_PEM_def_callback),
  86436. TEST_DECL(test_wolfSSL_PEM_read_PrivateKey),
  86437. TEST_DECL(test_wolfSSL_PEM_read_RSA_PUBKEY),
  86438. TEST_DECL(test_wolfSSL_PEM_read_PUBKEY),
  86439. TEST_DECL(test_wolfSSL_PEM_PrivateKey_rsa),
  86440. TEST_DECL(test_wolfSSL_PEM_PrivateKey_ecc),
  86441. TEST_DECL(test_wolfSSL_PEM_PrivateKey_dsa),
  86442. TEST_DECL(test_wolfSSL_PEM_PrivateKey_dh),
  86443. TEST_DECL(test_wolfSSL_PEM_PrivateKey),
  86444. TEST_DECL(test_wolfSSL_PEM_file_RSAKey),
  86445. TEST_DECL(test_wolfSSL_PEM_file_RSAPrivateKey),
  86446. #ifndef NO_BIO
  86447. TEST_DECL(test_wolfSSL_BIO),
  86448. TEST_DECL(test_wolfSSL_BIO_BIO_ring_read),
  86449. TEST_DECL(test_wolfSSL_PEM_read_bio),
  86450. TEST_DECL(test_wolfSSL_PEM_bio_RSAKey),
  86451. TEST_DECL(test_wolfSSL_PEM_bio_DSAKey),
  86452. TEST_DECL(test_wolfSSL_PEM_bio_ECKey),
  86453. TEST_DECL(test_wolfSSL_PEM_bio_RSAPrivateKey),
  86454. TEST_DECL(test_wolfSSL_PEM_PUBKEY),
  86455. #endif
  86456. /* EVP API testing */
  86457. TEST_DECL(test_wolfSSL_EVP_ENCODE_CTX_new),
  86458. TEST_DECL(test_wolfSSL_EVP_ENCODE_CTX_free),
  86459. TEST_DECL(test_wolfSSL_EVP_EncodeInit),
  86460. TEST_DECL(test_wolfSSL_EVP_EncodeUpdate),
  86461. TEST_DECL(test_wolfSSL_EVP_EncodeFinal),
  86462. TEST_DECL(test_wolfSSL_EVP_DecodeInit),
  86463. TEST_DECL(test_wolfSSL_EVP_DecodeUpdate),
  86464. TEST_DECL(test_wolfSSL_EVP_DecodeFinal),
  86465. TEST_DECL(test_wolfSSL_EVP_shake128),
  86466. TEST_DECL(test_wolfSSL_EVP_shake256),
  86467. TEST_DECL(test_wolfSSL_EVP_sm3),
  86468. TEST_DECL(test_EVP_blake2),
  86469. #ifdef OPENSSL_ALL
  86470. TEST_DECL(test_wolfSSL_EVP_md4),
  86471. TEST_DECL(test_wolfSSL_EVP_ripemd160),
  86472. TEST_DECL(test_wolfSSL_EVP_get_digestbynid),
  86473. TEST_DECL(test_wolfSSL_EVP_MD_nid),
  86474. TEST_DECL(test_wolfSSL_EVP_DigestFinal_ex),
  86475. #endif
  86476. TEST_DECL(test_EVP_MD_do_all),
  86477. TEST_DECL(test_wolfSSL_EVP_MD_size),
  86478. TEST_DECL(test_wolfSSL_EVP_MD_pkey_type),
  86479. TEST_DECL(test_wolfSSL_EVP_Digest),
  86480. TEST_DECL(test_wolfSSL_EVP_Digest_all),
  86481. TEST_DECL(test_wolfSSL_EVP_MD_hmac_signing),
  86482. TEST_DECL(test_wolfSSL_EVP_MD_rsa_signing),
  86483. TEST_DECL(test_wolfSSL_EVP_MD_ecc_signing),
  86484. TEST_DECL(test_wolfssl_EVP_aes_gcm),
  86485. TEST_DECL(test_wolfssl_EVP_aes_gcm_AAD_2_parts),
  86486. TEST_DECL(test_wolfssl_EVP_aes_gcm_zeroLen),
  86487. TEST_DECL(test_wolfssl_EVP_aes_ccm),
  86488. TEST_DECL(test_wolfssl_EVP_aes_ccm_zeroLen),
  86489. TEST_DECL(test_wolfssl_EVP_chacha20),
  86490. TEST_DECL(test_wolfssl_EVP_chacha20_poly1305),
  86491. TEST_DECL(test_wolfssl_EVP_sm4_ecb),
  86492. TEST_DECL(test_wolfssl_EVP_sm4_cbc),
  86493. TEST_DECL(test_wolfssl_EVP_sm4_ctr),
  86494. TEST_DECL(test_wolfssl_EVP_sm4_gcm_zeroLen),
  86495. TEST_DECL(test_wolfssl_EVP_sm4_gcm),
  86496. TEST_DECL(test_wolfssl_EVP_sm4_ccm_zeroLen),
  86497. TEST_DECL(test_wolfssl_EVP_sm4_ccm),
  86498. #ifdef OPENSSL_ALL
  86499. TEST_DECL(test_wolfSSL_EVP_aes_256_gcm),
  86500. TEST_DECL(test_wolfSSL_EVP_aes_192_gcm),
  86501. TEST_DECL(test_wolfSSL_EVP_aes_256_ccm),
  86502. TEST_DECL(test_wolfSSL_EVP_aes_192_ccm),
  86503. TEST_DECL(test_wolfSSL_EVP_aes_128_ccm),
  86504. TEST_DECL(test_wolfSSL_EVP_rc4),
  86505. TEST_DECL(test_wolfSSL_EVP_enc_null),
  86506. TEST_DECL(test_wolfSSL_EVP_rc2_cbc),
  86507. TEST_DECL(test_wolfSSL_EVP_mdc2),
  86508. TEST_DECL(test_evp_cipher_aes_gcm),
  86509. #endif
  86510. TEST_DECL(test_wolfssl_EVP_aria_gcm),
  86511. TEST_DECL(test_wolfSSL_EVP_Cipher_extra),
  86512. #ifdef OPENSSL_EXTRA
  86513. TEST_DECL(test_wolfSSL_EVP_get_cipherbynid),
  86514. TEST_DECL(test_wolfSSL_EVP_CIPHER_CTX),
  86515. #endif
  86516. #ifdef OPENSSL_ALL
  86517. TEST_DECL(test_wolfSSL_EVP_CIPHER_CTX_iv_length),
  86518. TEST_DECL(test_wolfSSL_EVP_CIPHER_CTX_key_length),
  86519. TEST_DECL(test_wolfSSL_EVP_CIPHER_CTX_set_iv),
  86520. TEST_DECL(test_wolfSSL_EVP_CIPHER_block_size),
  86521. TEST_DECL(test_wolfSSL_EVP_CIPHER_iv_length),
  86522. TEST_DECL(test_wolfSSL_EVP_X_STATE),
  86523. TEST_DECL(test_wolfSSL_EVP_X_STATE_LEN),
  86524. TEST_DECL(test_wolfSSL_EVP_BytesToKey),
  86525. #endif
  86526. TEST_DECL(test_wolfSSL_EVP_PKEY_print_public),
  86527. TEST_DECL(test_wolfSSL_EVP_PKEY_new_mac_key),
  86528. TEST_DECL(test_wolfSSL_EVP_PKEY_new_CMAC_key),
  86529. TEST_DECL(test_wolfSSL_EVP_PKEY_up_ref),
  86530. TEST_DECL(test_wolfSSL_EVP_PKEY_hkdf),
  86531. TEST_DECL(test_wolfSSL_EVP_PKEY_derive),
  86532. TEST_DECL(test_wolfSSL_d2i_and_i2d_PublicKey),
  86533. TEST_DECL(test_wolfSSL_d2i_and_i2d_PublicKey_ecc),
  86534. #ifndef NO_BIO
  86535. TEST_DECL(test_wolfSSL_d2i_PUBKEY),
  86536. #endif
  86537. TEST_DECL(test_wolfSSL_d2i_and_i2d_DSAparams),
  86538. TEST_DECL(test_wolfSSL_i2d_PrivateKey),
  86539. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO)) && !defined(NO_RSA)
  86540. #ifndef NO_BIO
  86541. TEST_DECL(test_wolfSSL_d2i_PrivateKeys_bio),
  86542. #endif /* !NO_BIO */
  86543. #endif
  86544. #ifdef OPENSSL_ALL
  86545. TEST_DECL(test_wolfSSL_EVP_PKEY_set1_get1_DSA),
  86546. TEST_DECL(test_wolfSSL_EVP_PKEY_set1_get1_EC_KEY),
  86547. TEST_DECL(test_wolfSSL_EVP_PKEY_set1_get1_DH),
  86548. TEST_DECL(test_wolfSSL_EVP_PKEY_assign),
  86549. TEST_DECL(test_wolfSSL_EVP_PKEY_assign_DH),
  86550. TEST_DECL(test_wolfSSL_EVP_PKEY_base_id),
  86551. TEST_DECL(test_wolfSSL_EVP_PKEY_id),
  86552. TEST_DECL(test_wolfSSL_EVP_PKEY_paramgen),
  86553. TEST_DECL(test_wolfSSL_EVP_PKEY_keygen),
  86554. TEST_DECL(test_wolfSSL_EVP_PKEY_keygen_init),
  86555. TEST_DECL(test_wolfSSL_EVP_PKEY_missing_parameters),
  86556. TEST_DECL(test_wolfSSL_EVP_PKEY_copy_parameters),
  86557. TEST_DECL(test_wolfSSL_EVP_PKEY_CTX_set_rsa_keygen_bits),
  86558. TEST_DECL(test_wolfSSL_EVP_PKEY_CTX_new_id),
  86559. TEST_DECL(test_wolfSSL_EVP_PKEY_get0_EC_KEY),
  86560. #endif
  86561. TEST_DECL(test_EVP_PKEY_rsa),
  86562. TEST_DECL(test_EVP_PKEY_ec),
  86563. TEST_DECL(test_wolfSSL_EVP_PKEY_encrypt),
  86564. TEST_DECL(test_wolfSSL_EVP_PKEY_sign_verify_rsa),
  86565. TEST_DECL(test_wolfSSL_EVP_PKEY_sign_verify_dsa),
  86566. TEST_DECL(test_wolfSSL_EVP_PKEY_sign_verify_ec),
  86567. TEST_DECL(test_EVP_PKEY_cmp),
  86568. #ifdef OPENSSL_ALL
  86569. TEST_DECL(test_wolfSSL_EVP_SignInit_ex),
  86570. TEST_DECL(test_wolfSSL_EVP_PKEY_param_check),
  86571. TEST_DECL(test_wolfSSL_QT_EVP_PKEY_CTX_free),
  86572. #endif
  86573. TEST_DECL(test_wolfSSL_EVP_PBE_scrypt),
  86574. TEST_DECL(test_wolfSSL_CTX_add_extra_chain_cert),
  86575. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  86576. TEST_DECL(test_wolfSSL_ERR_peek_last_error_line),
  86577. #endif
  86578. #ifndef NO_BIO
  86579. TEST_DECL(test_wolfSSL_ERR_print_errors_cb),
  86580. TEST_DECL(test_wolfSSL_GetLoggingCb),
  86581. TEST_DECL(test_WOLFSSL_ERROR_MSG),
  86582. TEST_DECL(test_wc_ERR_remove_state),
  86583. TEST_DECL(test_wc_ERR_print_errors_fp),
  86584. #endif
  86585. TEST_DECL(test_wolfSSL_configure_args),
  86586. TEST_DECL(test_wolfSSL_sk_SSL_CIPHER),
  86587. TEST_DECL(test_wolfSSL_set1_curves_list),
  86588. TEST_DECL(test_wolfSSL_curves_mismatch),
  86589. TEST_DECL(test_wolfSSL_set1_sigalgs_list),
  86590. TEST_DECL(test_wolfSSL_OtherName),
  86591. TEST_DECL(test_wolfSSL_FPKI),
  86592. TEST_DECL(test_wolfSSL_URI),
  86593. TEST_DECL(test_wolfSSL_TBS),
  86594. TEST_DECL(test_wolfSSL_X509_STORE_CTX),
  86595. TEST_DECL(test_X509_STORE_untrusted),
  86596. TEST_DECL(test_wolfSSL_X509_STORE_CTX_trusted_stack_cleanup),
  86597. TEST_DECL(test_wolfSSL_X509_STORE_CTX_get0_current_issuer),
  86598. TEST_DECL(test_wolfSSL_X509_STORE_set_flags),
  86599. TEST_DECL(test_wolfSSL_X509_LOOKUP_load_file),
  86600. TEST_DECL(test_wolfSSL_X509_Name_canon),
  86601. TEST_DECL(test_wolfSSL_X509_LOOKUP_ctrl_file),
  86602. TEST_DECL(test_wolfSSL_X509_LOOKUP_ctrl_hash_dir),
  86603. TEST_DECL(test_wolfSSL_X509_NID),
  86604. TEST_DECL(test_wolfSSL_X509_STORE_CTX_set_time),
  86605. TEST_DECL(test_wolfSSL_get0_param),
  86606. TEST_DECL(test_wolfSSL_X509_VERIFY_PARAM_set1_host),
  86607. TEST_DECL(test_wolfSSL_set1_host),
  86608. TEST_DECL(test_wolfSSL_X509_VERIFY_PARAM_set1_ip),
  86609. TEST_DECL(test_wolfSSL_X509_STORE_CTX_get0_store),
  86610. TEST_DECL(test_wolfSSL_X509_STORE),
  86611. TEST_DECL(test_wolfSSL_X509_STORE_load_locations),
  86612. TEST_DECL(test_X509_STORE_get0_objects),
  86613. TEST_DECL(test_wolfSSL_X509_load_crl_file),
  86614. TEST_DECL(test_wolfSSL_X509_STORE_get1_certs),
  86615. TEST_DECL(test_wolfSSL_X509_STORE_set_get_crl),
  86616. TEST_DECL(test_wolfSSL_X509_NAME_ENTRY_get_object),
  86617. TEST_DECL(test_wolfSSL_X509_cmp_time),
  86618. TEST_DECL(test_wolfSSL_X509_time_adj),
  86619. /* X509 tests */
  86620. TEST_DECL(test_wolfSSL_X509_subject_name_hash),
  86621. TEST_DECL(test_wolfSSL_X509_issuer_name_hash),
  86622. TEST_DECL(test_wolfSSL_X509_check_host),
  86623. TEST_DECL(test_wolfSSL_X509_check_email),
  86624. TEST_DECL(test_wolfSSL_X509_check_private_key),
  86625. TEST_DECL(test_wolfSSL_X509),
  86626. TEST_DECL(test_wolfSSL_X509_VERIFY_PARAM),
  86627. TEST_DECL(test_wolfSSL_X509_sign),
  86628. TEST_DECL(test_wolfSSL_X509_sign2),
  86629. TEST_DECL(test_wolfSSL_X509_verify),
  86630. TEST_DECL(test_wolfSSL_X509_get0_tbs_sigalg),
  86631. TEST_DECL(test_wolfSSL_X509_ALGOR_get0),
  86632. TEST_DECL(test_wolfSSL_X509_get_X509_PUBKEY),
  86633. TEST_DECL(test_wolfSSL_X509_PUBKEY_RSA),
  86634. TEST_DECL(test_wolfSSL_X509_PUBKEY_EC),
  86635. TEST_DECL(test_wolfSSL_X509_PUBKEY_DSA),
  86636. TEST_DECL(test_wolfSSL_PEM_write_bio_X509),
  86637. TEST_DECL(test_wolfSSL_X509_NAME_get_entry),
  86638. TEST_DECL(test_wolfSSL_X509_NAME),
  86639. TEST_DECL(test_wolfSSL_X509_NAME_hash),
  86640. TEST_DECL(test_wolfSSL_X509_NAME_print_ex),
  86641. TEST_DECL(test_wolfSSL_X509_NAME_ENTRY),
  86642. TEST_DECL(test_wolfSSL_X509_set_name),
  86643. TEST_DECL(test_wolfSSL_X509_set_notAfter),
  86644. TEST_DECL(test_wolfSSL_X509_set_notBefore),
  86645. TEST_DECL(test_wolfSSL_X509_set_version),
  86646. TEST_DECL(test_wolfSSL_X509_get_serialNumber),
  86647. TEST_DECL(test_wolfSSL_X509_CRL),
  86648. TEST_DECL(test_wolfSSL_i2d_X509),
  86649. TEST_DECL(test_wolfSSL_d2i_X509_REQ),
  86650. TEST_DECL(test_wolfSSL_PEM_read_X509),
  86651. TEST_DECL(test_wolfSSL_X509_check_ca),
  86652. TEST_DECL(test_wolfSSL_X509_check_ip_asc),
  86653. TEST_DECL(test_wolfSSL_X509_bad_altname),
  86654. TEST_DECL(test_wolfSSL_X509_name_match),
  86655. TEST_DECL(test_wolfSSL_X509_name_match2),
  86656. TEST_DECL(test_wolfSSL_X509_name_match3),
  86657. TEST_DECL(test_wolfSSL_X509_max_altnames),
  86658. TEST_DECL(test_wolfSSL_X509_max_name_constraints),
  86659. TEST_DECL(test_wolfSSL_make_cert),
  86660. /* X509 ACERT tests */
  86661. TEST_DECL(test_wolfSSL_X509_ACERT_verify),
  86662. TEST_DECL(test_wolfSSL_X509_ACERT_misc_api),
  86663. #ifndef NO_BIO
  86664. TEST_DECL(test_wolfSSL_X509_INFO_multiple_info),
  86665. TEST_DECL(test_wolfSSL_X509_INFO),
  86666. TEST_DECL(test_wolfSSL_PEM_X509_INFO_read_bio),
  86667. #endif
  86668. #ifdef OPENSSL_ALL
  86669. TEST_DECL(test_wolfSSL_X509_PUBKEY_get),
  86670. #endif
  86671. TEST_DECL(test_wolfSSL_X509_CA_num),
  86672. TEST_DECL(test_x509_get_key_id),
  86673. TEST_DECL(test_wolfSSL_X509_get_version),
  86674. #ifndef NO_BIO
  86675. TEST_DECL(test_wolfSSL_X509_print),
  86676. TEST_DECL(test_wolfSSL_X509_CRL_print),
  86677. #endif
  86678. TEST_DECL(test_X509_get_signature_nid),
  86679. /* X509 extension testing. */
  86680. TEST_DECL(test_wolfSSL_X509_get_extension_flags),
  86681. TEST_DECL(test_wolfSSL_X509_get_ext),
  86682. TEST_DECL(test_wolfSSL_X509_get_ext_by_NID),
  86683. TEST_DECL(test_wolfSSL_X509_get_ext_subj_alt_name),
  86684. TEST_DECL(test_wolfSSL_X509_get_ext_count),
  86685. TEST_DECL(test_wolfSSL_X509_EXTENSION_new),
  86686. TEST_DECL(test_wolfSSL_X509_EXTENSION_get_object),
  86687. TEST_DECL(test_wolfSSL_X509_EXTENSION_get_data),
  86688. TEST_DECL(test_wolfSSL_X509_EXTENSION_get_critical),
  86689. TEST_DECL(test_wolfSSL_X509V3_EXT_get),
  86690. TEST_DECL(test_wolfSSL_X509V3_EXT_nconf),
  86691. TEST_DECL(test_wolfSSL_X509V3_EXT),
  86692. TEST_DECL(test_wolfSSL_X509V3_EXT_print),
  86693. TEST_DECL(test_wolfSSL_X509_cmp),
  86694. TEST_DECL(test_GENERAL_NAME_set0_othername),
  86695. TEST_DECL(test_othername_and_SID_ext),
  86696. TEST_DECL(test_wolfSSL_dup_CA_list),
  86697. /* OpenSSL sk_X509 API test */
  86698. TEST_DECL(test_sk_X509),
  86699. /* OpenSSL sk_X509_CRL API test */
  86700. TEST_DECL(test_sk_X509_CRL),
  86701. /* OpenSSL X509 REQ API test */
  86702. TEST_DECL(test_X509_REQ),
  86703. /* OpenSSL compatibility outside SSL context w/ CRL lookup directory */
  86704. TEST_DECL(test_X509_STORE_No_SSL_CTX),
  86705. TEST_DECL(test_X509_LOOKUP_add_dir),
  86706. /* RAND compatibility API */
  86707. TEST_DECL(test_wolfSSL_RAND_set_rand_method),
  86708. TEST_DECL(test_wolfSSL_RAND_bytes),
  86709. TEST_DECL(test_wolfSSL_RAND),
  86710. /* BN compatibility API */
  86711. TEST_DECL(test_wolfSSL_BN_CTX),
  86712. TEST_DECL(test_wolfSSL_BN),
  86713. TEST_DECL(test_wolfSSL_BN_init),
  86714. TEST_DECL(test_wolfSSL_BN_enc_dec),
  86715. TEST_DECL(test_wolfSSL_BN_word),
  86716. TEST_DECL(test_wolfSSL_BN_bits),
  86717. TEST_DECL(test_wolfSSL_BN_shift),
  86718. TEST_DECL(test_wolfSSL_BN_math),
  86719. TEST_DECL(test_wolfSSL_BN_math_mod),
  86720. TEST_DECL(test_wolfSSL_BN_math_other),
  86721. TEST_DECL(test_wolfSSL_BN_rand),
  86722. TEST_DECL(test_wolfSSL_BN_prime),
  86723. /* OpenSSL PKCS5 API test */
  86724. TEST_DECL(test_wolfSSL_PKCS5),
  86725. /* OpenSSL PKCS8 API test */
  86726. TEST_DECL(test_wolfSSL_PKCS8_Compat),
  86727. TEST_DECL(test_wolfSSL_PKCS8_d2i),
  86728. /* OpenSSL PKCS7 API test */
  86729. TEST_DECL(test_wolfssl_PKCS7),
  86730. TEST_DECL(test_wolfSSL_PKCS7_certs),
  86731. TEST_DECL(test_wolfSSL_PKCS7_sign),
  86732. TEST_DECL(test_wolfSSL_PKCS7_SIGNED_new),
  86733. #ifndef NO_BIO
  86734. TEST_DECL(test_wolfSSL_PEM_write_bio_PKCS7),
  86735. #ifdef HAVE_SMIME
  86736. TEST_DECL(test_wolfSSL_SMIME_read_PKCS7),
  86737. TEST_DECL(test_wolfSSL_SMIME_write_PKCS7),
  86738. #endif /* HAVE_SMIME */
  86739. #endif /* !NO_BIO */
  86740. /* OpenSSL PKCS12 API test */
  86741. TEST_DECL(test_wolfSSL_PKCS12),
  86742. /* Can't memory test as callbacks use Assert. */
  86743. TEST_DECL(test_error_queue_per_thread),
  86744. TEST_DECL(test_wolfSSL_ERR_put_error),
  86745. TEST_DECL(test_wolfSSL_ERR_get_error_order),
  86746. #ifndef NO_BIO
  86747. TEST_DECL(test_wolfSSL_ERR_print_errors),
  86748. #endif
  86749. TEST_DECL(test_OBJ_NAME_do_all),
  86750. TEST_DECL(test_wolfSSL_OBJ),
  86751. TEST_DECL(test_wolfSSL_OBJ_cmp),
  86752. TEST_DECL(test_wolfSSL_OBJ_txt2nid),
  86753. TEST_DECL(test_wolfSSL_OBJ_txt2obj),
  86754. #ifdef OPENSSL_ALL
  86755. TEST_DECL(test_wolfSSL_OBJ_ln),
  86756. TEST_DECL(test_wolfSSL_OBJ_sn),
  86757. #endif
  86758. #ifndef NO_BIO
  86759. TEST_DECL(test_wolfSSL_BIO_gets),
  86760. TEST_DECL(test_wolfSSL_BIO_puts),
  86761. TEST_DECL(test_wolfSSL_BIO_dump),
  86762. /* Can't memory test as server hangs. */
  86763. TEST_DECL(test_wolfSSL_BIO_should_retry),
  86764. TEST_DECL(test_wolfSSL_BIO_write),
  86765. TEST_DECL(test_wolfSSL_BIO_printf),
  86766. TEST_DECL(test_wolfSSL_BIO_f_md),
  86767. TEST_DECL(test_wolfSSL_BIO_up_ref),
  86768. TEST_DECL(test_wolfSSL_BIO_reset),
  86769. TEST_DECL(test_wolfSSL_BIO_get_len),
  86770. #endif
  86771. TEST_DECL(test_wolfSSL_check_domain),
  86772. TEST_DECL(test_wolfSSL_cert_cb),
  86773. TEST_DECL(test_wolfSSL_cert_cb_dyn_ciphers),
  86774. TEST_DECL(test_wolfSSL_ciphersuite_auth),
  86775. TEST_DECL(test_wolfSSL_sigalg_info),
  86776. /* Can't memory test as tcp_connect aborts. */
  86777. TEST_DECL(test_wolfSSL_SESSION),
  86778. TEST_DECL(test_wolfSSL_SESSION_expire_downgrade),
  86779. TEST_DECL(test_wolfSSL_CTX_sess_set_remove_cb),
  86780. TEST_DECL(test_wolfSSL_ticket_keys),
  86781. TEST_DECL(test_wolfSSL_sk_GENERAL_NAME),
  86782. TEST_DECL(test_wolfSSL_GENERAL_NAME_print),
  86783. TEST_DECL(test_wolfSSL_sk_DIST_POINT),
  86784. TEST_DECL(test_wolfSSL_verify_mode),
  86785. TEST_DECL(test_wolfSSL_verify_depth),
  86786. TEST_DECL(test_wolfSSL_verify_result),
  86787. TEST_DECL(test_wolfSSL_msg_callback),
  86788. TEST_DECL(test_wolfSSL_OCSP_id_get0_info),
  86789. TEST_DECL(test_wolfSSL_i2d_OCSP_CERTID),
  86790. TEST_DECL(test_wolfSSL_d2i_OCSP_CERTID),
  86791. TEST_DECL(test_wolfSSL_OCSP_id_cmp),
  86792. TEST_DECL(test_wolfSSL_OCSP_SINGLERESP_get0_id),
  86793. TEST_DECL(test_wolfSSL_OCSP_single_get0_status),
  86794. TEST_DECL(test_wolfSSL_OCSP_resp_count),
  86795. TEST_DECL(test_wolfSSL_OCSP_resp_get0),
  86796. TEST_DECL(test_wolfSSL_OCSP_parse_url),
  86797. TEST_DECL(test_wolfSSL_OCSP_REQ_CTX),
  86798. TEST_DECL(test_wolfSSL_PEM_read),
  86799. TEST_DECL(test_wolfSSL_OpenSSL_version),
  86800. TEST_DECL(test_wolfSSL_OpenSSL_add_all_algorithms),
  86801. TEST_DECL(test_wolfSSL_OPENSSL_hexstr2buf),
  86802. TEST_DECL(test_CONF_modules_xxx),
  86803. #ifdef OPENSSL_ALL
  86804. TEST_DECL(test_wolfSSL_TXT_DB),
  86805. TEST_DECL(test_wolfSSL_NCONF),
  86806. #endif
  86807. TEST_DECL(test_wolfSSL_CRYPTO_memcmp),
  86808. TEST_DECL(test_wolfSSL_CRYPTO_get_ex_new_index),
  86809. TEST_DECL(test_wolfSSL_SESSION_get_ex_new_index),
  86810. TEST_DECL(test_CRYPTO_set_dynlock_xxx),
  86811. TEST_DECL(test_CRYPTO_THREADID_xxx),
  86812. TEST_DECL(test_ENGINE_cleanup),
  86813. /* test the no op functions for compatibility */
  86814. TEST_DECL(test_no_op_functions),
  86815. /* OpenSSL error API tests */
  86816. TEST_DECL(test_ERR_load_crypto_strings),
  86817. #ifdef OPENSSL_ALL
  86818. TEST_DECL(test_wolfSSL_sk_CIPHER_description),
  86819. TEST_DECL(test_wolfSSL_get_ciphers_compat),
  86820. TEST_DECL(test_wolfSSL_CTX_ctrl),
  86821. #endif /* OPENSSL_ALL */
  86822. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO)) && !defined(NO_RSA)
  86823. TEST_DECL(test_wolfSSL_CTX_use_certificate_ASN1),
  86824. #endif /* (OPENSSL_ALL || WOLFSSL_ASIO) && !NO_RSA */
  86825. /*********************************
  86826. * Crypto API tests
  86827. *********************************/
  86828. TEST_DECL(test_wolfSSL_MD4),
  86829. TEST_DECL(test_wolfSSL_MD5),
  86830. TEST_DECL(test_wolfSSL_MD5_Transform),
  86831. TEST_DECL(test_wolfSSL_SHA),
  86832. TEST_DECL(test_wolfSSL_SHA_Transform),
  86833. TEST_DECL(test_wolfSSL_SHA224),
  86834. TEST_DECL(test_wolfSSL_SHA256),
  86835. TEST_DECL(test_wolfSSL_SHA256_Transform),
  86836. TEST_DECL(test_wolfSSL_SHA512_Transform),
  86837. TEST_DECL(test_wolfSSL_SHA512_224_Transform),
  86838. TEST_DECL(test_wolfSSL_SHA512_256_Transform),
  86839. TEST_DECL(test_wolfSSL_HMAC_CTX),
  86840. TEST_DECL(test_wolfSSL_HMAC),
  86841. TEST_DECL(test_wolfSSL_CMAC),
  86842. TEST_DECL(test_wolfSSL_DES),
  86843. TEST_DECL(test_wolfSSL_DES_ncbc),
  86844. TEST_DECL(test_wolfSSL_DES_ecb_encrypt),
  86845. TEST_DECL(test_wolfSSL_DES_ede3_cbc_encrypt),
  86846. TEST_DECL(test_wolfSSL_AES_encrypt),
  86847. TEST_DECL(test_wolfSSL_AES_ecb_encrypt),
  86848. TEST_DECL(test_wolfSSL_AES_cbc_encrypt),
  86849. TEST_DECL(test_wolfSSL_AES_cfb128_encrypt),
  86850. TEST_DECL(test_wolfSSL_CRYPTO_cts128),
  86851. TEST_DECL(test_wolfSSL_RC4),
  86852. TEST_DECL(test_wolfSSL_RSA),
  86853. TEST_DECL(test_wolfSSL_RSA_DER),
  86854. TEST_DECL(test_wolfSSL_RSA_print),
  86855. TEST_DECL(test_wolfSSL_RSA_padding_add_PKCS1_PSS),
  86856. TEST_DECL(test_wolfSSL_RSA_sign_sha3),
  86857. TEST_DECL(test_wolfSSL_RSA_get0_key),
  86858. TEST_DECL(test_wolfSSL_RSA_meth),
  86859. TEST_DECL(test_wolfSSL_RSA_verify),
  86860. TEST_DECL(test_wolfSSL_RSA_sign),
  86861. TEST_DECL(test_wolfSSL_RSA_sign_ex),
  86862. TEST_DECL(test_wolfSSL_RSA_public_decrypt),
  86863. TEST_DECL(test_wolfSSL_RSA_private_encrypt),
  86864. TEST_DECL(test_wolfSSL_RSA_public_encrypt),
  86865. TEST_DECL(test_wolfSSL_RSA_private_decrypt),
  86866. TEST_DECL(test_wolfSSL_RSA_GenAdd),
  86867. TEST_DECL(test_wolfSSL_RSA_blinding_on),
  86868. TEST_DECL(test_wolfSSL_RSA_ex_data),
  86869. TEST_DECL(test_wolfSSL_RSA_LoadDer),
  86870. TEST_DECL(test_wolfSSL_RSA_To_Der),
  86871. TEST_DECL(test_wolfSSL_PEM_read_RSAPublicKey),
  86872. TEST_DECL(test_wolfSSL_PEM_write_RSA_PUBKEY),
  86873. TEST_DECL(test_wolfSSL_PEM_write_RSAPrivateKey),
  86874. TEST_DECL(test_wolfSSL_PEM_write_mem_RSAPrivateKey),
  86875. TEST_DECL(test_wolfSSL_DH),
  86876. TEST_DECL(test_wolfSSL_DH_dup),
  86877. TEST_DECL(test_wolfSSL_DH_check),
  86878. TEST_DECL(test_wolfSSL_DH_prime),
  86879. TEST_DECL(test_wolfSSL_DH_1536_prime),
  86880. TEST_DECL(test_wolfSSL_DH_get_2048_256),
  86881. TEST_DECL(test_wolfSSL_PEM_write_DHparams),
  86882. TEST_DECL(test_wolfSSL_PEM_read_DHparams),
  86883. TEST_DECL(test_wolfSSL_d2i_DHparams),
  86884. TEST_DECL(test_wolfSSL_DH_LoadDer),
  86885. TEST_DECL(test_wolfSSL_i2d_DHparams),
  86886. #if defined(HAVE_ECC) && !defined(OPENSSL_NO_PK)
  86887. TEST_DECL(test_wolfSSL_EC_GROUP),
  86888. TEST_DECL(test_wolfSSL_PEM_read_bio_ECPKParameters),
  86889. TEST_DECL(test_wolfSSL_EC_POINT),
  86890. TEST_DECL(test_wolfSSL_SPAKE),
  86891. TEST_DECL(test_wolfSSL_EC_KEY_generate),
  86892. TEST_DECL(test_EC_i2d),
  86893. TEST_DECL(test_wolfSSL_EC_curve),
  86894. TEST_DECL(test_wolfSSL_EC_KEY_dup),
  86895. TEST_DECL(test_wolfSSL_EC_KEY_set_group),
  86896. TEST_DECL(test_wolfSSL_EC_KEY_set_conv_form),
  86897. TEST_DECL(test_wolfSSL_EC_KEY_private_key),
  86898. TEST_DECL(test_wolfSSL_EC_KEY_public_key),
  86899. TEST_DECL(test_wolfSSL_EC_KEY_print_fp),
  86900. TEST_DECL(test_wolfSSL_EC_get_builtin_curves),
  86901. TEST_DECL(test_wolfSSL_ECDSA_SIG),
  86902. TEST_DECL(test_ECDSA_size_sign),
  86903. TEST_DECL(test_ECDH_compute_key),
  86904. #endif
  86905. #ifdef OPENSSL_EXTRA
  86906. TEST_DECL(test_EC25519),
  86907. TEST_DECL(test_ED25519),
  86908. TEST_DECL(test_EC448),
  86909. TEST_DECL(test_ED448),
  86910. #endif
  86911. TEST_DECL(test_DSA_do_sign_verify),
  86912. #ifdef OPENSSL_ALL
  86913. TEST_DECL(test_wolfSSL_DSA_generate_parameters),
  86914. TEST_DECL(test_wolfSSL_DSA_SIG),
  86915. #endif
  86916. TEST_DECL(test_openssl_generate_key_and_cert),
  86917. TEST_DECL(test_wolfSSL_FIPS_mode),
  86918. TEST_DECL(test_openssl_FIPS_drbg),
  86919. /*********************************
  86920. * CertManager API tests
  86921. *********************************/
  86922. TEST_DECL(test_wolfSSL_CertManagerAPI),
  86923. TEST_DECL(test_wolfSSL_CertManagerLoadCABuffer),
  86924. TEST_DECL(test_wolfSSL_CertManagerLoadCABuffer_ex),
  86925. TEST_DECL(test_wolfSSL_CertManagerGetCerts),
  86926. TEST_DECL(test_wolfSSL_CertManagerSetVerify),
  86927. TEST_DECL(test_wolfSSL_CertManagerNameConstraint),
  86928. TEST_DECL(test_wolfSSL_CertManagerNameConstraint2),
  86929. TEST_DECL(test_wolfSSL_CertManagerNameConstraint3),
  86930. TEST_DECL(test_wolfSSL_CertManagerNameConstraint4),
  86931. TEST_DECL(test_wolfSSL_CertManagerNameConstraint5),
  86932. TEST_DECL(test_wolfSSL_CertManagerCRL),
  86933. TEST_DECL(test_wolfSSL_CertManagerCheckOCSPResponse),
  86934. TEST_DECL(test_wolfSSL_CheckOCSPResponse),
  86935. #ifdef HAVE_CERT_CHAIN_VALIDATION
  86936. TEST_DECL(test_various_pathlen_chains),
  86937. #endif
  86938. /*********************************
  86939. * SSL/TLS API tests
  86940. *********************************/
  86941. TEST_DECL(test_wolfSSL_Method_Allocators),
  86942. #ifndef NO_WOLFSSL_SERVER
  86943. TEST_DECL(test_wolfSSL_CTX_new),
  86944. #endif
  86945. TEST_DECL(test_server_wolfSSL_new),
  86946. TEST_DECL(test_client_wolfSSL_new),
  86947. #if (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)) && \
  86948. (!defined(NO_RSA) || defined(HAVE_ECC)) && !defined(NO_FILESYSTEM)
  86949. TEST_DECL(test_for_double_Free),
  86950. #endif
  86951. TEST_DECL(test_wolfSSL_set_options),
  86952. #ifdef WOLFSSL_TLS13
  86953. /* TLS v1.3 API tests */
  86954. TEST_DECL(test_tls13_apis),
  86955. TEST_DECL(test_tls13_cipher_suites),
  86956. #endif
  86957. TEST_DECL(test_wolfSSL_tmp_dh),
  86958. TEST_DECL(test_wolfSSL_ctrl),
  86959. #if defined(OPENSSL_ALL) || (defined(OPENSSL_EXTRA) && \
  86960. (defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || \
  86961. defined(HAVE_LIGHTY) || defined(WOLFSSL_HAPROXY) || \
  86962. defined(WOLFSSL_OPENSSH) || defined(HAVE_SBLIM_SFCB)))
  86963. TEST_DECL(test_wolfSSL_set_SSL_CTX),
  86964. #endif
  86965. TEST_DECL(test_wolfSSL_CTX_get_min_proto_version),
  86966. TEST_DECL(test_wolfSSL_security_level),
  86967. TEST_DECL(test_wolfSSL_SSL_in_init),
  86968. TEST_DECL(test_wolfSSL_CTX_set_timeout),
  86969. TEST_DECL(test_wolfSSL_set_psk_use_session_callback),
  86970. TEST_DECL(test_CONF_CTX_FILE),
  86971. TEST_DECL(test_CONF_CTX_CMDLINE),
  86972. #if !defined(NO_CERTS) && (!defined(NO_WOLFSSL_CLIENT) || \
  86973. !defined(WOLFSSL_NO_CLIENT_AUTH)) && !defined(NO_FILESYSTEM)
  86974. /* Use the Cert Manager(CM) API to generate the error ASN_SIG_CONFIRM_E */
  86975. /* Bad certificate signature tests */
  86976. TEST_DECL(test_EccSigFailure_cm),
  86977. TEST_DECL(test_RsaSigFailure_cm),
  86978. #endif /* NO_CERTS */
  86979. /* PKCS8 testing */
  86980. TEST_DECL(test_wolfSSL_no_password_cb),
  86981. TEST_DECL(test_wolfSSL_PKCS8),
  86982. TEST_DECL(test_wolfSSL_PKCS8_ED25519),
  86983. TEST_DECL(test_wolfSSL_PKCS8_ED448),
  86984. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  86985. TEST_DECL(test_wolfSSL_get_finished),
  86986. /* Uses Assert in handshake callback. */
  86987. TEST_DECL(test_wolfSSL_CTX_add_session),
  86988. /* Large number of memory allocations. */
  86989. TEST_DECL(test_wolfSSL_CTX_add_session_ext_tls13),
  86990. /* Large number of memory allocations. */
  86991. TEST_DECL(test_wolfSSL_CTX_add_session_ext_dtls13),
  86992. /* Large number of memory allocations. */
  86993. TEST_DECL(test_wolfSSL_CTX_add_session_ext_tls12),
  86994. /* Large number of memory allocations. */
  86995. TEST_DECL(test_wolfSSL_CTX_add_session_ext_dtls12),
  86996. /* Large number of memory allocations. */
  86997. TEST_DECL(test_wolfSSL_CTX_add_session_ext_tls11),
  86998. /* Large number of memory allocations. */
  86999. TEST_DECL(test_wolfSSL_CTX_add_session_ext_dtls1),
  87000. #endif
  87001. TEST_DECL(test_SSL_CIPHER_get_xxx),
  87002. TEST_DECL(test_wolfSSL_ERR_strings),
  87003. TEST_DECL(test_wolfSSL_CTX_set_cipher_list_bytes),
  87004. TEST_DECL(test_wolfSSL_CTX_use_certificate),
  87005. TEST_DECL(test_wolfSSL_CTX_use_certificate_file),
  87006. TEST_DECL(test_wolfSSL_CTX_use_certificate_buffer),
  87007. TEST_DECL(test_wolfSSL_use_certificate_buffer),
  87008. TEST_DECL(test_wolfSSL_CTX_use_PrivateKey_file),
  87009. TEST_DECL(test_wolfSSL_CTX_use_RSAPrivateKey_file),
  87010. TEST_DECL(test_wolfSSL_use_RSAPrivateKey_file),
  87011. TEST_DECL(test_wolfSSL_CTX_use_PrivateKey),
  87012. TEST_DECL(test_wolfSSL_CTX_load_verify_locations),
  87013. /* Large number of memory allocations. */
  87014. TEST_DECL(test_wolfSSL_CTX_load_system_CA_certs),
  87015. #ifdef HAVE_CERT_CHAIN_VALIDATION
  87016. TEST_DECL(test_wolfSSL_CertRsaPss),
  87017. #endif
  87018. TEST_DECL(test_wolfSSL_CTX_load_verify_locations_ex),
  87019. TEST_DECL(test_wolfSSL_CTX_load_verify_buffer_ex),
  87020. TEST_DECL(test_wolfSSL_CTX_load_verify_chain_buffer_format),
  87021. TEST_DECL(test_wolfSSL_CTX_add1_chain_cert),
  87022. TEST_DECL(test_wolfSSL_CTX_use_certificate_chain_buffer_format),
  87023. TEST_DECL(test_wolfSSL_CTX_use_certificate_chain_file_format),
  87024. TEST_DECL(test_wolfSSL_use_certificate_chain_file),
  87025. TEST_DECL(test_wolfSSL_CTX_trust_peer_cert),
  87026. TEST_DECL(test_wolfSSL_CTX_LoadCRL),
  87027. TEST_DECL(test_multiple_crls_same_issuer),
  87028. TEST_DECL(test_wolfSSL_CTX_SetTmpDH_file),
  87029. TEST_DECL(test_wolfSSL_CTX_SetTmpDH_buffer),
  87030. TEST_DECL(test_wolfSSL_CTX_SetMinMaxDhKey_Sz),
  87031. TEST_DECL(test_wolfSSL_CTX_der_load_verify_locations),
  87032. TEST_DECL(test_wolfSSL_CTX_enable_disable),
  87033. TEST_DECL(test_wolfSSL_CTX_ticket_API),
  87034. TEST_DECL(test_wolfSSL_SetTmpDH_file),
  87035. TEST_DECL(test_wolfSSL_SetTmpDH_buffer),
  87036. TEST_DECL(test_wolfSSL_SetMinMaxDhKey_Sz),
  87037. TEST_DECL(test_SetTmpEC_DHE_Sz),
  87038. TEST_DECL(test_wolfSSL_CTX_get0_privatekey),
  87039. #ifdef WOLFSSL_DTLS
  87040. TEST_DECL(test_wolfSSL_DtlsUpdateWindow),
  87041. TEST_DECL(test_wolfSSL_DTLS_fragment_buckets),
  87042. #endif
  87043. TEST_DECL(test_wolfSSL_dtls_set_mtu),
  87044. /* Uses Assert in handshake callback. */
  87045. TEST_DECL(test_wolfSSL_dtls_plaintext),
  87046. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  87047. defined(HAVE_IO_TESTS_DEPENDENCIES)
  87048. TEST_DECL(test_wolfSSL_read_write),
  87049. /* Can't memory test as server hangs if client fails before second connect.
  87050. */
  87051. TEST_DECL(test_wolfSSL_reuse_WOLFSSLobj),
  87052. TEST_DECL(test_wolfSSL_CTX_verifyDepth_ServerClient_1),
  87053. TEST_DECL(test_wolfSSL_CTX_verifyDepth_ServerClient_2),
  87054. TEST_DECL(test_wolfSSL_CTX_verifyDepth_ServerClient_3),
  87055. TEST_DECL(test_wolfSSL_CTX_set_cipher_list),
  87056. /* Can't memory test as server hangs. */
  87057. TEST_DECL(test_wolfSSL_dtls_export),
  87058. /* Uses Assert in handshake callback. */
  87059. TEST_DECL(test_wolfSSL_tls_export),
  87060. #endif
  87061. TEST_DECL(test_wolfSSL_dtls_export_peers),
  87062. TEST_DECL(test_wolfSSL_SetMinVersion),
  87063. TEST_DECL(test_wolfSSL_CTX_SetMinVersion),
  87064. /* wolfSSL handshake APIs. */
  87065. TEST_DECL(test_wolfSSL_CTX_get0_set1_param),
  87066. TEST_DECL(test_wolfSSL_a2i_IPADDRESS),
  87067. TEST_DECL(test_wolfSSL_BUF),
  87068. TEST_DECL(test_wolfSSL_set_tlsext_status_type),
  87069. /* Can't memory test as server hangs. */
  87070. TEST_DECL(test_wolfSSL_CTX_set_client_CA_list),
  87071. TEST_DECL(test_wolfSSL_CTX_add_client_CA),
  87072. TEST_DECL(test_wolfSSL_CTX_set_srp_username),
  87073. TEST_DECL(test_wolfSSL_CTX_set_srp_password),
  87074. TEST_DECL(test_wolfSSL_CTX_set_keylog_callback),
  87075. TEST_DECL(test_wolfSSL_CTX_get_keylog_callback),
  87076. TEST_DECL(test_wolfSSL_Tls12_Key_Logging_test),
  87077. /* Can't memory test as server hangs. */
  87078. TEST_DECL(test_wolfSSL_Tls13_Key_Logging_test),
  87079. TEST_DECL(test_wolfSSL_Tls13_postauth),
  87080. TEST_DECL(test_wolfSSL_set_ecdh_auto),
  87081. TEST_DECL(test_wolfSSL_CTX_set_ecdh_auto),
  87082. TEST_DECL(test_wolfSSL_set_minmax_proto_version),
  87083. TEST_DECL(test_wolfSSL_CTX_set_max_proto_version),
  87084. TEST_DECL(test_wolfSSL_THREADID_hash),
  87085. /* TLS extensions tests */
  87086. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  87087. #ifdef HAVE_SNI
  87088. TEST_DECL(test_wolfSSL_UseSNI_params),
  87089. /* Uses Assert in handshake callback. */
  87090. TEST_DECL(test_wolfSSL_UseSNI_connection),
  87091. TEST_DECL(test_wolfSSL_SNI_GetFromBuffer),
  87092. #endif /* HAVE_SNI */
  87093. #endif
  87094. TEST_DECL(test_wolfSSL_UseTrustedCA),
  87095. TEST_DECL(test_wolfSSL_UseMaxFragment),
  87096. TEST_DECL(test_wolfSSL_UseTruncatedHMAC),
  87097. TEST_DECL(test_wolfSSL_UseSupportedCurve),
  87098. #if defined(HAVE_ALPN) && defined(HAVE_IO_TESTS_DEPENDENCIES)
  87099. /* Uses Assert in handshake callback. */
  87100. TEST_DECL(test_wolfSSL_UseALPN_connection),
  87101. TEST_DECL(test_wolfSSL_UseALPN_params),
  87102. #endif
  87103. #ifdef HAVE_ALPN_PROTOS_SUPPORT
  87104. /* Uses Assert in handshake callback. */
  87105. TEST_DECL(test_wolfSSL_set_alpn_protos),
  87106. #endif
  87107. TEST_DECL(test_wolfSSL_DisableExtendedMasterSecret),
  87108. TEST_DECL(test_wolfSSL_wolfSSL_UseSecureRenegotiation),
  87109. TEST_DECL(test_wolfSSL_SCR_Reconnect),
  87110. TEST_DECL(test_tls_ext_duplicate),
  87111. #if defined(WOLFSSL_TLS13) && defined(HAVE_ECH) && \
  87112. defined(HAVE_IO_TESTS_DEPENDENCIES)
  87113. TEST_DECL(test_wolfSSL_Tls13_ECH_params),
  87114. /* Uses Assert in handshake callback. */
  87115. TEST_DECL(test_wolfSSL_Tls13_ECH),
  87116. #endif
  87117. TEST_DECL(test_wolfSSL_X509_TLS_version_test_1),
  87118. TEST_DECL(test_wolfSSL_X509_TLS_version_test_2),
  87119. /* OCSP Stapling */
  87120. TEST_DECL(test_wolfSSL_UseOCSPStapling),
  87121. TEST_DECL(test_wolfSSL_UseOCSPStaplingV2),
  87122. TEST_DECL(test_self_signed_stapling),
  87123. TEST_DECL(test_ocsp_callback_fails),
  87124. /* Multicast */
  87125. TEST_DECL(test_wolfSSL_mcast),
  87126. TEST_DECL(test_wolfSSL_read_detect_TCP_disconnect),
  87127. TEST_DECL(test_wolfSSL_msgCb),
  87128. TEST_DECL(test_wolfSSL_either_side),
  87129. TEST_DECL(test_wolfSSL_DTLS_either_side),
  87130. /* Uses Assert in handshake callback. */
  87131. TEST_DECL(test_wolfSSL_dtls_fragments),
  87132. /* Uses Assert in handshake callback. */
  87133. TEST_DECL(test_wolfSSL_dtls_AEAD_limit),
  87134. /* Uses Assert in handshake callback. */
  87135. TEST_DECL(test_wolfSSL_ignore_alert_before_cookie),
  87136. /* Uses Assert in handshake callback. */
  87137. TEST_DECL(test_wolfSSL_dtls_bad_record),
  87138. /* Uses Assert in handshake callback. */
  87139. TEST_DECL(test_wolfSSL_dtls_stateless),
  87140. TEST_DECL(test_generate_cookie),
  87141. #ifndef NO_BIO
  87142. /* Can't memory test as server hangs. */
  87143. TEST_DECL(test_wolfSSL_BIO_connect),
  87144. /* Can't memory test as server Asserts in thread. */
  87145. TEST_DECL(test_wolfSSL_BIO_accept),
  87146. TEST_DECL(test_wolfSSL_BIO_tls),
  87147. TEST_DECL(test_wolfSSL_BIO_datagram),
  87148. #endif
  87149. #if defined(HAVE_PK_CALLBACKS) && !defined(WOLFSSL_NO_TLS12)
  87150. TEST_DECL(test_DhCallbacks),
  87151. #endif
  87152. #if defined(HAVE_KEYING_MATERIAL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  87153. TEST_DECL(test_export_keying_material),
  87154. #endif
  87155. /* Can't memory test as client/server Asserts in thread. */
  87156. TEST_DECL(test_ticket_and_psk_mixing),
  87157. /* Can't memory test as client/server Asserts in thread. */
  87158. TEST_DECL(test_prioritize_psk),
  87159. /* Can't memory test as client/server hangs. */
  87160. TEST_DECL(test_wc_CryptoCb),
  87161. /* Can't memory test as client/server hangs. */
  87162. TEST_DECL(test_wolfSSL_CTX_StaticMemory),
  87163. #if !defined(NO_FILESYSTEM) && \
  87164. defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  87165. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  87166. #ifdef WOLFSSL_DTLS_NO_HVR_ON_RESUME
  87167. TEST_DECL(test_wolfSSL_dtls_stateless_resume),
  87168. #endif /* WOLFSSL_DTLS_NO_HVR_ON_RESUME */
  87169. #ifdef HAVE_MAX_FRAGMENT
  87170. TEST_DECL(test_wolfSSL_dtls_stateless_maxfrag),
  87171. #endif /* HAVE_MAX_FRAGMENT */
  87172. #ifndef NO_RSA
  87173. TEST_DECL(test_wolfSSL_dtls_stateless2),
  87174. #if !defined(NO_OLD_TLS)
  87175. TEST_DECL(test_wolfSSL_dtls_stateless_downgrade),
  87176. #endif /* !defined(NO_OLD_TLS) */
  87177. #endif /* ! NO_RSA */
  87178. #endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  87179. * !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) */
  87180. TEST_DECL(test_wolfSSL_CTX_set_ciphersuites),
  87181. TEST_DECL(test_wolfSSL_CRL_CERT_REVOKED_alert),
  87182. TEST_DECL(test_TLS_13_ticket_different_ciphers),
  87183. TEST_DECL(test_WOLFSSL_dtls_version_alert),
  87184. #if defined(WOLFSSL_TICKET_NONCE_MALLOC) && defined(HAVE_SESSION_TICKET) \
  87185. && defined(WOLFSSL_TLS13) && \
  87186. (!defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))
  87187. TEST_DECL(test_ticket_nonce_malloc),
  87188. #endif
  87189. TEST_DECL(test_ticket_ret_create),
  87190. TEST_DECL(test_wrong_cs_downgrade),
  87191. TEST_DECL(test_extra_alerts_wrong_cs),
  87192. TEST_DECL(test_extra_alerts_skip_hs),
  87193. TEST_DECL(test_extra_alerts_bad_psk),
  87194. TEST_DECL(test_multiple_alerts_EAGAIN),
  87195. TEST_DECL(test_tls13_bad_psk_binder),
  87196. /* Can't memory test as client/server Asserts. */
  87197. TEST_DECL(test_harden_no_secure_renegotiation),
  87198. TEST_DECL(test_override_alt_cert_chain),
  87199. TEST_DECL(test_rpk_set_xxx_cert_type),
  87200. TEST_DECL(test_tls13_rpk_handshake),
  87201. TEST_DECL(test_dtls13_bad_epoch_ch),
  87202. TEST_DECL(test_short_session_id),
  87203. TEST_DECL(test_wolfSSL_dtls13_null_cipher),
  87204. /* Can't memory test as client/server hangs. */
  87205. TEST_DECL(test_dtls_msg_from_other_peer),
  87206. TEST_DECL(test_dtls_ipv6_check),
  87207. TEST_DECL(test_wolfSSL_SCR_after_resumption),
  87208. TEST_DECL(test_dtls_no_extensions),
  87209. TEST_DECL(test_tls_alert_no_server_hello),
  87210. TEST_DECL(test_TLSX_CA_NAMES_bad_extension),
  87211. TEST_DECL(test_dtls_1_0_hvr_downgrade),
  87212. TEST_DECL(test_session_ticket_no_id),
  87213. TEST_DECL(test_session_ticket_hs_update),
  87214. TEST_DECL(test_dtls_downgrade_scr_server),
  87215. TEST_DECL(test_dtls_downgrade_scr),
  87216. TEST_DECL(test_dtls_client_hello_timeout_downgrade),
  87217. TEST_DECL(test_dtls_client_hello_timeout),
  87218. TEST_DECL(test_dtls_dropped_ccs),
  87219. TEST_DECL(test_dtls_seq_num_downgrade),
  87220. TEST_DECL(test_certreq_sighash_algos),
  87221. TEST_DECL(test_revoked_loaded_int_cert),
  87222. TEST_DECL(test_dtls_frag_ch),
  87223. TEST_DECL(test_dtls13_frag_ch_pq),
  87224. TEST_DECL(test_dtls_empty_keyshare_with_cookie),
  87225. TEST_DECL(test_dtls_old_seq_number),
  87226. TEST_DECL(test_dtls13_basic_connection_id),
  87227. TEST_DECL(test_tls13_pq_groups),
  87228. TEST_DECL(test_tls13_early_data),
  87229. TEST_DECL(test_tls_multi_handshakes_one_record),
  87230. TEST_DECL(test_write_dup),
  87231. TEST_DECL(test_read_write_hs),
  87232. TEST_DECL(test_get_signature_nid),
  87233. TEST_DECL(test_tls_cert_store_unchanged),
  87234. TEST_DECL(test_wolfSSL_SendUserCanceled),
  87235. /* This test needs to stay at the end to clean up any caches allocated. */
  87236. TEST_DECL(test_wolfSSL_Cleanup)
  87237. };
  87238. #define TEST_CASE_CNT (int)(sizeof(testCases) / sizeof(*testCases))
  87239. static void TestSetup(void)
  87240. {
  87241. /* Stub, for now. Add common test setup code here. */
  87242. }
  87243. static void TestCleanup(void)
  87244. {
  87245. #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
  87246. /* Clear any errors added to the error queue during the test run. */
  87247. wolfSSL_ERR_clear_error();
  87248. #endif /* OPENSSL_EXTRA || DEBUG_WOLFSSL_VERBOSE */
  87249. }
  87250. /* Print out all API test cases with numeric identifier.
  87251. */
  87252. void ApiTest_PrintTestCases(void)
  87253. {
  87254. int i;
  87255. printf("All Test Cases:\n");
  87256. for (i = 0; i < TEST_CASE_CNT; i++) {
  87257. printf("%3d: %s\n", i + 1, testCases[i].name);
  87258. }
  87259. }
  87260. /* Add test case with index to the list to run.
  87261. *
  87262. * @param [in] idx Index of test case to run starting at 1.
  87263. * @return 0 on success.
  87264. * @return BAD_FUNC_ARG when index is out of range of test case identifiers.
  87265. */
  87266. int ApiTest_RunIdx(int idx)
  87267. {
  87268. if (idx < 1 || idx > TEST_CASE_CNT) {
  87269. printf("Index out of range (1 - %d): %d\n", TEST_CASE_CNT, idx);
  87270. return BAD_FUNC_ARG;
  87271. }
  87272. testAll = 0;
  87273. testCases[idx-1].run = 1;
  87274. return 0;
  87275. }
  87276. /* Add test case with name to the list to run.
  87277. *
  87278. * @param [in] name Name of test case to run.
  87279. * @return 0 on success.
  87280. * @return BAD_FUNC_ARG when name is not a known test case name.
  87281. */
  87282. int ApiTest_RunName(char* name)
  87283. {
  87284. int i;
  87285. for (i = 0; i < TEST_CASE_CNT; i++) {
  87286. if (XSTRCMP(testCases[i].name, name) == 0) {
  87287. testAll = 0;
  87288. testCases[i].run = 1;
  87289. return 0;
  87290. }
  87291. }
  87292. printf("Test case name not found: %s\n", name);
  87293. printf("Use --list to see all test case names.\n");
  87294. return BAD_FUNC_ARG;
  87295. }
  87296. /* Converts the result code to a string.
  87297. *
  87298. * @param [in] res Test result code.
  87299. * @return String describing test result.
  87300. */
  87301. static const char* apitest_res_string(int res)
  87302. {
  87303. const char* str = "invalid result";
  87304. switch (res) {
  87305. case TEST_SUCCESS:
  87306. str = "passed";
  87307. break;
  87308. case TEST_FAIL:
  87309. str = "failed";
  87310. break;
  87311. case TEST_SKIPPED:
  87312. str = "skipped";
  87313. break;
  87314. }
  87315. return str;
  87316. }
  87317. #ifndef WOLFSSL_UNIT_TEST_NO_TIMING
  87318. static double gettime_secs(void)
  87319. #if defined(_MSC_VER) && defined(_WIN32)
  87320. {
  87321. /* there's no gettimeofday for Windows, so we'll use system time */
  87322. #define EPOCH_DIFF 11644473600LL
  87323. FILETIME currentFileTime;
  87324. GetSystemTimePreciseAsFileTime(&currentFileTime);
  87325. ULARGE_INTEGER uli = { 0, 0 };
  87326. uli.LowPart = currentFileTime.dwLowDateTime;
  87327. uli.HighPart = currentFileTime.dwHighDateTime;
  87328. /* Convert to seconds since Unix epoch */
  87329. return (double)((uli.QuadPart - (EPOCH_DIFF * 10000000)) / 10000000.0);
  87330. }
  87331. #else
  87332. {
  87333. struct timeval tv;
  87334. LIBCALL_CHECK_RET(gettimeofday(&tv, 0));
  87335. return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
  87336. }
  87337. #endif
  87338. #endif
  87339. int ApiTest(void)
  87340. {
  87341. int i;
  87342. int ret;
  87343. int res = 0;
  87344. #ifndef WOLFSSL_UNIT_TEST_NO_TIMING
  87345. double timeDiff;
  87346. #endif
  87347. printf(" Begin API Tests\n");
  87348. fflush(stdout);
  87349. /* we must perform init and cleanup if not all tests are running */
  87350. if (!testAll) {
  87351. #ifdef WOLFCRYPT_ONLY
  87352. if (wolfCrypt_Init() != 0) {
  87353. printf("wolfCrypt Initialization failed\n");
  87354. res = 1;
  87355. }
  87356. #else
  87357. if (wolfSSL_Init() != WOLFSSL_SUCCESS) {
  87358. printf("wolfSSL Initialization failed\n");
  87359. res = 1;
  87360. }
  87361. #endif
  87362. }
  87363. #ifdef WOLFSSL_DUMP_MEMIO_STREAM
  87364. if (res == 0) {
  87365. if (create_tmp_dir(tmpDirName, sizeof(tmpDirName) - 1) == NULL) {
  87366. printf("failed to create tmp dir\n");
  87367. res = 1;
  87368. }
  87369. else {
  87370. tmpDirNameSet = 1;
  87371. }
  87372. }
  87373. #endif
  87374. if (res == 0) {
  87375. for (i = 0; i < TEST_CASE_CNT; ++i) {
  87376. EXPECT_DECLS;
  87377. #ifdef WOLFSSL_DUMP_MEMIO_STREAM
  87378. currentTestName = testCases[i].name;
  87379. #endif
  87380. /* When not testing all cases then skip if not marked for running.
  87381. */
  87382. if (!testAll && !testCases[i].run) {
  87383. continue;
  87384. }
  87385. TestSetup();
  87386. printf(" %3d: %-52s:", i + 1, testCases[i].name);
  87387. fflush(stdout);
  87388. #ifndef WOLFSSL_UNIT_TEST_NO_TIMING
  87389. timeDiff = gettime_secs();
  87390. #endif
  87391. ret = testCases[i].func();
  87392. #ifndef WOLFSSL_UNIT_TEST_NO_TIMING
  87393. timeDiff = gettime_secs() - timeDiff;
  87394. #endif
  87395. #ifndef WOLFSSL_UNIT_TEST_NO_TIMING
  87396. if (ret != TEST_SKIPPED) {
  87397. printf(" %s (%9.5lf)\n", apitest_res_string(ret), timeDiff);
  87398. }
  87399. else
  87400. #endif
  87401. {
  87402. printf(" %s\n", apitest_res_string(ret));
  87403. }
  87404. fflush(stdout);
  87405. /* if return code is < 0 and not skipped then assert error */
  87406. Expect((ret > 0 || ret == TEST_SKIPPED),
  87407. ("Test failed\n"),
  87408. ("ret %d", ret));
  87409. testCases[i].fail = ((ret <= 0) && (ret != TEST_SKIPPED));
  87410. res |= ((ret <= 0) && (ret != TEST_SKIPPED));
  87411. TestCleanup();
  87412. }
  87413. }
  87414. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS) \
  87415. && (defined(NO_MAIN_DRIVER) || defined(HAVE_STACK_SIZE))
  87416. wc_ecc_fp_free(); /* free per thread cache */
  87417. #endif
  87418. if (!testAll) {
  87419. #ifdef WOLFCRYPT_ONLY
  87420. wolfCrypt_Cleanup();
  87421. #else
  87422. wolfSSL_Cleanup();
  87423. #endif
  87424. }
  87425. (void)testDevId;
  87426. if (res != 0) {
  87427. printf("\nFAILURES:\n");
  87428. for (i = 0; i < TEST_CASE_CNT; ++i) {
  87429. if (testCases[i].fail) {
  87430. printf(" %3d: %s\n", i + 1, testCases[i].name);
  87431. }
  87432. }
  87433. printf("\n");
  87434. fflush(stdout);
  87435. }
  87436. #ifdef WOLFSSL_DUMP_MEMIO_STREAM
  87437. if (tmpDirNameSet) {
  87438. printf("\nBinary dumps of the memio streams can be found in the\n"
  87439. "%s directory. This can be imported into\n"
  87440. "Wireshark by transforming the file with\n"
  87441. "\tod -Ax -tx1 -v stream.dump > stream.dump.hex\n"
  87442. "And then loading test_output.dump.hex into Wireshark using\n"
  87443. "the \"Import from Hex Dump...\" option and selecting the\n"
  87444. "TCP encapsulation option.\n", tmpDirName);
  87445. }
  87446. #endif
  87447. printf(" End API Tests\n");
  87448. fflush(stdout);
  87449. return res;
  87450. }