api.c 3.7 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403494044940549406494074940849409494104941149412494134941449415494164941749418494194942049421494224942349424494254942649427494284942949430494314943249433494344943549436494374943849439494404944149442494434944449445494464944749448494494945049451494524945349454494554945649457494584945949460494614946249463494644946549466494674946849469494704947149472494734947449475494764947749478494794948049481494824948349484494854948649487494884948949490494914949249493494944949549496494974949849499495004950149502495034950449505495064950749508495094951049511495124951349514495154951649517495184951949520495214952249523495244952549526495274952849529495304953149532495334953449535495364953749538495394954049541495424954349544495454954649547495484954949550495514955249553495544955549556495574955849559495604956149562495634956449565495664956749568495694957049571495724957349574495754957649577495784957949580495814958249583495844958549586495874958849589495904959149592495934959449595495964959749598495994960049601496024960349604496054960649607496084960949610496114961249613496144961549616496174961849619496204962149622496234962449625496264962749628496294963049631496324963349634496354963649637496384963949640496414964249643496444964549646496474964849649496504965149652496534965449655496564965749658496594966049661496624966349664496654966649667496684966949670496714967249673496744967549676496774967849679496804968149682496834968449685496864968749688496894969049691496924969349694496954969649697496984969949700497014970249703497044970549706497074970849709497104971149712497134971449715497164971749718497194972049721497224972349724497254972649727497284972949730497314973249733497344973549736497374973849739497404974149742497434974449745497464974749748497494975049751497524975349754497554975649757497584975949760497614976249763497644976549766497674976849769497704977149772497734977449775497764977749778497794978049781497824978349784497854978649787497884978949790497914979249793497944979549796497974979849799498004980149802498034980449805498064980749808498094981049811498124981349814498154981649817498184981949820498214982249823498244982549826498274982849829498304983149832498334983449835498364983749838498394984049841498424984349844498454984649847498484984949850498514985249853498544985549856498574985849859498604986149862498634986449865498664986749868498694987049871498724987349874498754987649877498784987949880498814988249883498844988549886498874988849889498904989149892498934989449895498964989749898498994990049901499024990349904499054990649907499084990949910499114991249913499144991549916499174991849919499204992149922499234992449925499264992749928499294993049931499324993349934499354993649937499384993949940499414994249943499444994549946499474994849949499504995149952499534995449955499564995749958499594996049961499624996349964499654996649967499684996949970499714997249973499744997549976499774997849979499804998149982499834998449985499864998749988499894999049991499924999349994499954999649997499984999950000500015000250003500045000550006500075000850009500105001150012500135001450015500165001750018500195002050021500225002350024500255002650027500285002950030500315003250033500345003550036500375003850039500405004150042500435004450045500465004750048500495005050051500525005350054500555005650057500585005950060500615006250063500645006550066500675006850069500705007150072500735007450075500765007750078500795008050081500825008350084500855008650087500885008950090500915009250093500945009550096500975009850099501005010150102501035010450105501065010750108501095011050111501125011350114501155011650117501185011950120501215012250123501245012550126501275012850129501305013150132501335013450135501365013750138501395014050141501425014350144501455014650147501485014950150501515015250153501545015550156501575015850159501605016150162501635016450165501665016750168501695017050171501725017350174501755017650177501785017950180501815018250183501845018550186501875018850189501905019150192501935019450195501965019750198501995020050201502025020350204502055020650207502085020950210502115021250213502145021550216502175021850219502205022150222502235022450225502265022750228502295023050231502325023350234502355023650237502385023950240502415024250243502445024550246502475024850249502505025150252502535025450255502565025750258502595026050261502625026350264502655026650267502685026950270502715027250273502745027550276502775027850279502805028150282502835028450285502865028750288502895029050291502925029350294502955029650297502985029950300503015030250303503045030550306503075030850309503105031150312503135031450315503165031750318503195032050321503225032350324503255032650327503285032950330503315033250333503345033550336503375033850339503405034150342503435034450345503465034750348503495035050351503525035350354503555035650357503585035950360503615036250363503645036550366503675036850369503705037150372503735037450375503765037750378503795038050381503825038350384503855038650387503885038950390503915039250393503945039550396503975039850399504005040150402504035040450405504065040750408504095041050411504125041350414504155041650417504185041950420504215042250423504245042550426504275042850429504305043150432504335043450435504365043750438504395044050441504425044350444504455044650447504485044950450504515045250453504545045550456504575045850459504605046150462504635046450465504665046750468504695047050471504725047350474504755047650477504785047950480504815048250483504845048550486504875048850489504905049150492504935049450495504965049750498504995050050501505025050350504505055050650507505085050950510505115051250513505145051550516505175051850519505205052150522505235052450525505265052750528505295053050531505325053350534505355053650537505385053950540505415054250543505445054550546505475054850549505505055150552505535055450555505565055750558505595056050561505625056350564505655056650567505685056950570505715057250573505745057550576505775057850579505805058150582505835058450585505865058750588505895059050591505925059350594505955059650597505985059950600506015060250603506045060550606506075060850609506105061150612506135061450615506165061750618506195062050621506225062350624506255062650627506285062950630506315063250633506345063550636506375063850639506405064150642506435064450645506465064750648506495065050651506525065350654506555065650657506585065950660506615066250663506645066550666506675066850669506705067150672506735067450675506765067750678506795068050681506825068350684506855068650687506885068950690506915069250693506945069550696506975069850699507005070150702507035070450705507065070750708507095071050711507125071350714507155071650717507185071950720507215072250723507245072550726507275072850729507305073150732507335073450735507365073750738507395074050741507425074350744507455074650747507485074950750507515075250753507545075550756507575075850759507605076150762507635076450765507665076750768507695077050771507725077350774507755077650777507785077950780507815078250783507845078550786507875078850789507905079150792507935079450795507965079750798507995080050801508025080350804508055080650807508085080950810508115081250813508145081550816508175081850819508205082150822508235082450825508265082750828508295083050831508325083350834508355083650837508385083950840508415084250843508445084550846508475084850849508505085150852508535085450855508565085750858508595086050861508625086350864508655086650867508685086950870508715087250873508745087550876508775087850879508805088150882508835088450885508865088750888508895089050891508925089350894508955089650897508985089950900509015090250903509045090550906509075090850909509105091150912509135091450915509165091750918509195092050921509225092350924509255092650927509285092950930509315093250933509345093550936509375093850939509405094150942509435094450945509465094750948509495095050951509525095350954509555095650957509585095950960509615096250963509645096550966509675096850969509705097150972509735097450975509765097750978509795098050981509825098350984509855098650987509885098950990509915099250993509945099550996509975099850999510005100151002510035100451005510065100751008510095101051011510125101351014510155101651017510185101951020510215102251023510245102551026510275102851029510305103151032510335103451035510365103751038510395104051041510425104351044510455104651047510485104951050510515105251053510545105551056510575105851059510605106151062510635106451065510665106751068510695107051071510725107351074510755107651077510785107951080510815108251083510845108551086510875108851089510905109151092510935109451095510965109751098510995110051101511025110351104511055110651107511085110951110511115111251113511145111551116511175111851119511205112151122511235112451125511265112751128511295113051131511325113351134511355113651137511385113951140511415114251143511445114551146511475114851149511505115151152511535115451155511565115751158511595116051161511625116351164511655116651167511685116951170511715117251173511745117551176511775117851179511805118151182511835118451185511865118751188511895119051191511925119351194511955119651197511985119951200512015120251203512045120551206512075120851209512105121151212512135121451215512165121751218512195122051221512225122351224512255122651227512285122951230512315123251233512345123551236512375123851239512405124151242512435124451245512465124751248512495125051251512525125351254512555125651257512585125951260512615126251263512645126551266512675126851269512705127151272512735127451275512765127751278512795128051281512825128351284512855128651287512885128951290512915129251293512945129551296512975129851299513005130151302513035130451305513065130751308513095131051311513125131351314513155131651317513185131951320513215132251323513245132551326513275132851329513305133151332513335133451335513365133751338513395134051341513425134351344513455134651347513485134951350513515135251353513545135551356513575135851359513605136151362513635136451365513665136751368513695137051371513725137351374513755137651377513785137951380513815138251383513845138551386513875138851389513905139151392513935139451395513965139751398513995140051401514025140351404514055140651407514085140951410514115141251413514145141551416514175141851419514205142151422514235142451425514265142751428514295143051431514325143351434514355143651437514385143951440514415144251443514445144551446514475144851449514505145151452514535145451455514565145751458514595146051461514625146351464514655146651467514685146951470514715147251473514745147551476514775147851479514805148151482514835148451485514865148751488514895149051491514925149351494514955149651497514985149951500515015150251503515045150551506515075150851509515105151151512515135151451515515165151751518515195152051521515225152351524515255152651527515285152951530515315153251533515345153551536515375153851539515405154151542515435154451545515465154751548515495155051551515525155351554515555155651557515585155951560515615156251563515645156551566515675156851569515705157151572515735157451575515765157751578515795158051581515825158351584515855158651587515885158951590515915159251593515945159551596515975159851599516005160151602516035160451605516065160751608516095161051611516125161351614516155161651617516185161951620516215162251623516245162551626516275162851629516305163151632516335163451635516365163751638516395164051641516425164351644516455164651647516485164951650516515165251653516545165551656516575165851659516605166151662516635166451665516665166751668516695167051671516725167351674516755167651677516785167951680516815168251683516845168551686516875168851689516905169151692516935169451695516965169751698516995170051701517025170351704517055170651707517085170951710517115171251713517145171551716517175171851719517205172151722517235172451725517265172751728517295173051731517325173351734517355173651737517385173951740517415174251743517445174551746517475174851749517505175151752517535175451755517565175751758517595176051761517625176351764517655176651767517685176951770517715177251773517745177551776517775177851779517805178151782517835178451785517865178751788517895179051791517925179351794517955179651797517985179951800518015180251803518045180551806518075180851809518105181151812518135181451815518165181751818518195182051821518225182351824518255182651827518285182951830518315183251833518345183551836518375183851839518405184151842518435184451845518465184751848518495185051851518525185351854518555185651857518585185951860518615186251863518645186551866518675186851869518705187151872518735187451875518765187751878518795188051881518825188351884518855188651887518885188951890518915189251893518945189551896518975189851899519005190151902519035190451905519065190751908519095191051911519125191351914519155191651917519185191951920519215192251923519245192551926519275192851929519305193151932519335193451935519365193751938519395194051941519425194351944519455194651947519485194951950519515195251953519545195551956519575195851959519605196151962519635196451965519665196751968519695197051971519725197351974519755197651977519785197951980519815198251983519845198551986519875198851989519905199151992519935199451995519965199751998519995200052001520025200352004520055200652007520085200952010520115201252013520145201552016520175201852019520205202152022520235202452025520265202752028520295203052031520325203352034520355203652037520385203952040520415204252043520445204552046520475204852049520505205152052520535205452055520565205752058520595206052061520625206352064520655206652067520685206952070520715207252073520745207552076520775207852079520805208152082520835208452085520865208752088520895209052091520925209352094520955209652097520985209952100521015210252103521045210552106521075210852109521105211152112521135211452115521165211752118521195212052121521225212352124521255212652127521285212952130521315213252133521345213552136521375213852139521405214152142521435214452145521465214752148521495215052151521525215352154521555215652157521585215952160521615216252163521645216552166521675216852169521705217152172521735217452175521765217752178521795218052181521825218352184521855218652187521885218952190521915219252193521945219552196521975219852199522005220152202522035220452205522065220752208522095221052211522125221352214522155221652217522185221952220522215222252223522245222552226522275222852229522305223152232522335223452235522365223752238522395224052241522425224352244522455224652247522485224952250522515225252253522545225552256522575225852259522605226152262522635226452265522665226752268522695227052271522725227352274522755227652277522785227952280522815228252283522845228552286522875228852289522905229152292522935229452295522965229752298522995230052301523025230352304523055230652307523085230952310523115231252313523145231552316523175231852319523205232152322523235232452325523265232752328523295233052331523325233352334523355233652337523385233952340523415234252343523445234552346523475234852349523505235152352523535235452355523565235752358523595236052361523625236352364523655236652367523685236952370523715237252373523745237552376523775237852379523805238152382523835238452385523865238752388523895239052391523925239352394523955239652397523985239952400524015240252403524045240552406524075240852409524105241152412524135241452415524165241752418524195242052421524225242352424524255242652427524285242952430524315243252433524345243552436524375243852439524405244152442524435244452445524465244752448524495245052451524525245352454524555245652457524585245952460524615246252463524645246552466524675246852469524705247152472524735247452475524765247752478524795248052481524825248352484524855248652487524885248952490524915249252493524945249552496524975249852499525005250152502525035250452505525065250752508525095251052511525125251352514525155251652517525185251952520525215252252523525245252552526525275252852529525305253152532525335253452535525365253752538525395254052541525425254352544525455254652547525485254952550525515255252553525545255552556525575255852559525605256152562525635256452565525665256752568525695257052571525725257352574525755257652577525785257952580525815258252583525845258552586525875258852589525905259152592525935259452595525965259752598525995260052601526025260352604526055260652607526085260952610526115261252613526145261552616526175261852619526205262152622526235262452625526265262752628526295263052631526325263352634526355263652637526385263952640526415264252643526445264552646526475264852649526505265152652526535265452655526565265752658526595266052661526625266352664526655266652667526685266952670526715267252673526745267552676526775267852679526805268152682526835268452685526865268752688526895269052691526925269352694526955269652697526985269952700527015270252703527045270552706527075270852709527105271152712527135271452715527165271752718527195272052721527225272352724527255272652727527285272952730527315273252733527345273552736527375273852739527405274152742527435274452745527465274752748527495275052751527525275352754527555275652757527585275952760527615276252763527645276552766527675276852769527705277152772527735277452775527765277752778527795278052781527825278352784527855278652787527885278952790527915279252793527945279552796527975279852799528005280152802528035280452805528065280752808528095281052811528125281352814528155281652817528185281952820528215282252823528245282552826528275282852829528305283152832528335283452835528365283752838528395284052841528425284352844528455284652847528485284952850528515285252853528545285552856528575285852859528605286152862528635286452865528665286752868528695287052871528725287352874528755287652877528785287952880528815288252883528845288552886528875288852889528905289152892528935289452895528965289752898528995290052901529025290352904529055290652907529085290952910529115291252913529145291552916529175291852919529205292152922529235292452925529265292752928529295293052931529325293352934529355293652937529385293952940529415294252943529445294552946529475294852949529505295152952529535295452955529565295752958529595296052961529625296352964529655296652967529685296952970529715297252973529745297552976529775297852979529805298152982529835298452985529865298752988529895299052991529925299352994529955299652997529985299953000530015300253003530045300553006530075300853009530105301153012530135301453015530165301753018530195302053021530225302353024530255302653027530285302953030530315303253033530345303553036530375303853039530405304153042530435304453045530465304753048530495305053051530525305353054530555305653057530585305953060530615306253063530645306553066530675306853069530705307153072530735307453075530765307753078530795308053081530825308353084530855308653087530885308953090530915309253093530945309553096530975309853099531005310153102531035310453105531065310753108531095311053111531125311353114531155311653117531185311953120531215312253123531245312553126531275312853129531305313153132531335313453135531365313753138531395314053141531425314353144531455314653147531485314953150531515315253153531545315553156531575315853159531605316153162531635316453165531665316753168531695317053171531725317353174531755317653177531785317953180531815318253183531845318553186531875318853189531905319153192531935319453195531965319753198531995320053201532025320353204532055320653207532085320953210532115321253213532145321553216532175321853219532205322153222532235322453225532265322753228532295323053231532325323353234532355323653237532385323953240532415324253243532445324553246532475324853249532505325153252532535325453255532565325753258532595326053261532625326353264532655326653267532685326953270532715327253273532745327553276532775327853279532805328153282532835328453285532865328753288532895329053291532925329353294532955329653297532985329953300533015330253303533045330553306533075330853309533105331153312533135331453315533165331753318533195332053321533225332353324533255332653327533285332953330533315333253333533345333553336533375333853339533405334153342533435334453345533465334753348533495335053351533525335353354533555335653357533585335953360533615336253363533645336553366533675336853369533705337153372533735337453375533765337753378533795338053381533825338353384533855338653387533885338953390533915339253393533945339553396533975339853399534005340153402534035340453405534065340753408534095341053411534125341353414534155341653417534185341953420534215342253423534245342553426534275342853429534305343153432534335343453435534365343753438534395344053441534425344353444534455344653447534485344953450534515345253453534545345553456534575345853459534605346153462534635346453465534665346753468534695347053471534725347353474534755347653477534785347953480534815348253483534845348553486534875348853489534905349153492534935349453495534965349753498534995350053501535025350353504535055350653507535085350953510535115351253513535145351553516535175351853519535205352153522535235352453525535265352753528535295353053531535325353353534535355353653537535385353953540535415354253543535445354553546535475354853549535505355153552535535355453555535565355753558535595356053561535625356353564535655356653567535685356953570535715357253573535745357553576535775357853579535805358153582535835358453585535865358753588535895359053591535925359353594535955359653597535985359953600536015360253603536045360553606536075360853609536105361153612536135361453615536165361753618536195362053621536225362353624536255362653627536285362953630536315363253633536345363553636536375363853639536405364153642536435364453645536465364753648536495365053651536525365353654536555365653657536585365953660536615366253663536645366553666536675366853669536705367153672536735367453675536765367753678536795368053681536825368353684536855368653687536885368953690536915369253693536945369553696536975369853699537005370153702537035370453705537065370753708537095371053711537125371353714537155371653717537185371953720537215372253723537245372553726537275372853729537305373153732537335373453735537365373753738537395374053741537425374353744537455374653747537485374953750537515375253753537545375553756537575375853759537605376153762537635376453765537665376753768537695377053771537725377353774537755377653777537785377953780537815378253783537845378553786537875378853789537905379153792537935379453795537965379753798537995380053801538025380353804538055380653807538085380953810538115381253813538145381553816538175381853819538205382153822538235382453825538265382753828538295383053831538325383353834538355383653837538385383953840538415384253843538445384553846538475384853849538505385153852538535385453855538565385753858538595386053861538625386353864538655386653867538685386953870538715387253873538745387553876538775387853879538805388153882538835388453885538865388753888538895389053891538925389353894538955389653897538985389953900539015390253903539045390553906539075390853909539105391153912539135391453915539165391753918539195392053921539225392353924539255392653927539285392953930539315393253933539345393553936539375393853939539405394153942539435394453945539465394753948539495395053951539525395353954539555395653957539585395953960539615396253963539645396553966539675396853969539705397153972539735397453975539765397753978539795398053981539825398353984539855398653987539885398953990539915399253993539945399553996539975399853999540005400154002540035400454005540065400754008540095401054011540125401354014540155401654017540185401954020540215402254023540245402554026540275402854029540305403154032540335403454035540365403754038540395404054041540425404354044540455404654047540485404954050540515405254053540545405554056540575405854059540605406154062540635406454065540665406754068540695407054071540725407354074540755407654077540785407954080540815408254083540845408554086540875408854089540905409154092540935409454095540965409754098540995410054101541025410354104541055410654107541085410954110541115411254113541145411554116541175411854119541205412154122541235412454125541265412754128541295413054131541325413354134541355413654137541385413954140541415414254143541445414554146541475414854149541505415154152541535415454155541565415754158541595416054161541625416354164541655416654167541685416954170541715417254173541745417554176541775417854179541805418154182541835418454185541865418754188541895419054191541925419354194541955419654197541985419954200542015420254203542045420554206542075420854209542105421154212542135421454215542165421754218542195422054221542225422354224542255422654227542285422954230542315423254233542345423554236542375423854239542405424154242542435424454245542465424754248542495425054251542525425354254542555425654257542585425954260542615426254263542645426554266542675426854269542705427154272542735427454275542765427754278542795428054281542825428354284542855428654287542885428954290542915429254293542945429554296542975429854299543005430154302543035430454305543065430754308543095431054311543125431354314543155431654317543185431954320543215432254323543245432554326543275432854329543305433154332543335433454335543365433754338543395434054341543425434354344543455434654347543485434954350543515435254353543545435554356543575435854359543605436154362543635436454365543665436754368543695437054371543725437354374543755437654377543785437954380543815438254383543845438554386543875438854389543905439154392543935439454395543965439754398543995440054401544025440354404544055440654407544085440954410544115441254413544145441554416544175441854419544205442154422544235442454425544265442754428544295443054431544325443354434544355443654437544385443954440544415444254443544445444554446544475444854449544505445154452544535445454455544565445754458544595446054461544625446354464544655446654467544685446954470544715447254473544745447554476544775447854479544805448154482544835448454485544865448754488544895449054491544925449354494544955449654497544985449954500545015450254503545045450554506545075450854509545105451154512545135451454515545165451754518545195452054521545225452354524545255452654527545285452954530545315453254533545345453554536545375453854539545405454154542545435454454545545465454754548545495455054551545525455354554545555455654557545585455954560545615456254563545645456554566545675456854569545705457154572545735457454575545765457754578545795458054581545825458354584545855458654587545885458954590545915459254593545945459554596545975459854599546005460154602546035460454605546065460754608546095461054611546125461354614546155461654617546185461954620546215462254623546245462554626546275462854629546305463154632546335463454635546365463754638546395464054641546425464354644546455464654647546485464954650546515465254653546545465554656546575465854659546605466154662546635466454665546665466754668546695467054671546725467354674546755467654677546785467954680546815468254683546845468554686546875468854689546905469154692546935469454695546965469754698546995470054701547025470354704547055470654707547085470954710547115471254713547145471554716547175471854719547205472154722547235472454725547265472754728547295473054731547325473354734547355473654737547385473954740547415474254743547445474554746547475474854749547505475154752547535475454755547565475754758547595476054761547625476354764547655476654767547685476954770547715477254773547745477554776547775477854779547805478154782547835478454785547865478754788547895479054791547925479354794547955479654797547985479954800548015480254803548045480554806548075480854809548105481154812548135481454815548165481754818548195482054821548225482354824548255482654827548285482954830548315483254833548345483554836548375483854839548405484154842548435484454845548465484754848548495485054851548525485354854548555485654857548585485954860548615486254863548645486554866548675486854869548705487154872548735487454875548765487754878548795488054881548825488354884548855488654887548885488954890548915489254893548945489554896548975489854899549005490154902549035490454905549065490754908549095491054911549125491354914549155491654917549185491954920549215492254923549245492554926549275492854929549305493154932549335493454935549365493754938549395494054941549425494354944549455494654947549485494954950549515495254953549545495554956549575495854959549605496154962549635496454965549665496754968549695497054971549725497354974549755497654977549785497954980549815498254983549845498554986549875498854989549905499154992549935499454995549965499754998549995500055001550025500355004550055500655007550085500955010550115501255013550145501555016550175501855019550205502155022550235502455025550265502755028550295503055031550325503355034550355503655037550385503955040550415504255043550445504555046550475504855049550505505155052550535505455055550565505755058550595506055061550625506355064550655506655067550685506955070550715507255073550745507555076550775507855079550805508155082550835508455085550865508755088550895509055091550925509355094550955509655097550985509955100551015510255103551045510555106551075510855109551105511155112551135511455115551165511755118551195512055121551225512355124551255512655127551285512955130551315513255133551345513555136551375513855139551405514155142551435514455145551465514755148551495515055151551525515355154551555515655157551585515955160551615516255163551645516555166551675516855169551705517155172551735517455175551765517755178551795518055181551825518355184551855518655187551885518955190551915519255193551945519555196551975519855199552005520155202552035520455205552065520755208552095521055211552125521355214552155521655217552185521955220552215522255223552245522555226552275522855229552305523155232552335523455235552365523755238552395524055241552425524355244552455524655247552485524955250552515525255253552545525555256552575525855259552605526155262552635526455265552665526755268552695527055271552725527355274552755527655277552785527955280552815528255283552845528555286552875528855289552905529155292552935529455295552965529755298552995530055301553025530355304553055530655307553085530955310553115531255313553145531555316553175531855319553205532155322553235532455325553265532755328553295533055331553325533355334553355533655337553385533955340553415534255343553445534555346553475534855349553505535155352553535535455355553565535755358553595536055361553625536355364553655536655367553685536955370553715537255373553745537555376553775537855379553805538155382553835538455385553865538755388553895539055391553925539355394553955539655397553985539955400554015540255403554045540555406554075540855409554105541155412554135541455415554165541755418554195542055421554225542355424554255542655427554285542955430554315543255433554345543555436554375543855439554405544155442554435544455445554465544755448554495545055451554525545355454554555545655457554585545955460554615546255463554645546555466554675546855469554705547155472554735547455475554765547755478554795548055481554825548355484554855548655487554885548955490554915549255493554945549555496554975549855499555005550155502555035550455505555065550755508555095551055511555125551355514555155551655517555185551955520555215552255523555245552555526555275552855529555305553155532555335553455535555365553755538555395554055541555425554355544555455554655547555485554955550555515555255553555545555555556555575555855559555605556155562555635556455565555665556755568555695557055571555725557355574555755557655577555785557955580555815558255583555845558555586555875558855589555905559155592555935559455595555965559755598555995560055601556025560355604556055560655607556085560955610556115561255613556145561555616556175561855619556205562155622556235562455625556265562755628556295563055631556325563355634556355563655637556385563955640556415564255643556445564555646556475564855649556505565155652556535565455655556565565755658556595566055661556625566355664556655566655667556685566955670556715567255673556745567555676556775567855679556805568155682556835568455685556865568755688556895569055691556925569355694556955569655697556985569955700557015570255703557045570555706557075570855709557105571155712557135571455715557165571755718557195572055721557225572355724557255572655727557285572955730557315573255733557345573555736557375573855739557405574155742557435574455745557465574755748557495575055751557525575355754557555575655757557585575955760557615576255763557645576555766557675576855769557705577155772557735577455775557765577755778557795578055781557825578355784557855578655787557885578955790557915579255793557945579555796557975579855799558005580155802558035580455805558065580755808558095581055811558125581355814558155581655817558185581955820558215582255823558245582555826558275582855829558305583155832558335583455835558365583755838558395584055841558425584355844558455584655847558485584955850558515585255853558545585555856558575585855859558605586155862558635586455865558665586755868558695587055871558725587355874558755587655877558785587955880558815588255883558845588555886558875588855889558905589155892558935589455895558965589755898558995590055901559025590355904559055590655907559085590955910559115591255913559145591555916559175591855919559205592155922559235592455925559265592755928559295593055931559325593355934559355593655937559385593955940559415594255943559445594555946559475594855949559505595155952559535595455955559565595755958559595596055961559625596355964559655596655967559685596955970559715597255973559745597555976559775597855979559805598155982559835598455985559865598755988559895599055991559925599355994559955599655997559985599956000560015600256003560045600556006560075600856009560105601156012560135601456015560165601756018560195602056021560225602356024560255602656027560285602956030560315603256033560345603556036560375603856039560405604156042560435604456045560465604756048560495605056051560525605356054560555605656057560585605956060560615606256063560645606556066560675606856069560705607156072560735607456075560765607756078560795608056081560825608356084560855608656087560885608956090560915609256093560945609556096560975609856099561005610156102561035610456105561065610756108561095611056111561125611356114561155611656117561185611956120561215612256123561245612556126561275612856129561305613156132561335613456135561365613756138561395614056141561425614356144561455614656147561485614956150561515615256153561545615556156561575615856159561605616156162561635616456165561665616756168561695617056171561725617356174561755617656177561785617956180561815618256183561845618556186561875618856189561905619156192561935619456195561965619756198561995620056201562025620356204562055620656207562085620956210562115621256213562145621556216562175621856219562205622156222562235622456225562265622756228562295623056231562325623356234562355623656237562385623956240562415624256243562445624556246562475624856249562505625156252562535625456255562565625756258562595626056261562625626356264562655626656267562685626956270562715627256273562745627556276562775627856279562805628156282562835628456285562865628756288562895629056291562925629356294562955629656297562985629956300563015630256303563045630556306563075630856309563105631156312563135631456315563165631756318563195632056321563225632356324563255632656327563285632956330563315633256333563345633556336563375633856339563405634156342563435634456345563465634756348563495635056351563525635356354563555635656357563585635956360563615636256363563645636556366563675636856369563705637156372563735637456375563765637756378563795638056381563825638356384563855638656387563885638956390563915639256393563945639556396563975639856399564005640156402564035640456405564065640756408564095641056411564125641356414564155641656417564185641956420564215642256423564245642556426564275642856429564305643156432564335643456435564365643756438564395644056441564425644356444564455644656447564485644956450564515645256453564545645556456564575645856459564605646156462564635646456465564665646756468564695647056471564725647356474564755647656477564785647956480564815648256483564845648556486564875648856489564905649156492564935649456495564965649756498564995650056501565025650356504565055650656507565085650956510565115651256513565145651556516565175651856519565205652156522565235652456525565265652756528565295653056531565325653356534565355653656537565385653956540565415654256543565445654556546565475654856549565505655156552565535655456555565565655756558565595656056561565625656356564565655656656567565685656956570565715657256573565745657556576565775657856579565805658156582565835658456585565865658756588565895659056591565925659356594565955659656597565985659956600566015660256603566045660556606566075660856609566105661156612566135661456615566165661756618566195662056621566225662356624566255662656627566285662956630566315663256633566345663556636566375663856639566405664156642566435664456645566465664756648566495665056651566525665356654566555665656657566585665956660566615666256663566645666556666566675666856669566705667156672566735667456675566765667756678566795668056681566825668356684566855668656687566885668956690566915669256693566945669556696566975669856699567005670156702567035670456705567065670756708567095671056711567125671356714567155671656717567185671956720567215672256723567245672556726567275672856729567305673156732567335673456735567365673756738567395674056741567425674356744567455674656747567485674956750567515675256753567545675556756567575675856759567605676156762567635676456765567665676756768567695677056771567725677356774567755677656777567785677956780567815678256783567845678556786567875678856789567905679156792567935679456795567965679756798567995680056801568025680356804568055680656807568085680956810568115681256813568145681556816568175681856819568205682156822568235682456825568265682756828568295683056831568325683356834568355683656837568385683956840568415684256843568445684556846568475684856849568505685156852568535685456855568565685756858568595686056861568625686356864568655686656867568685686956870568715687256873568745687556876568775687856879568805688156882568835688456885568865688756888568895689056891568925689356894568955689656897568985689956900569015690256903569045690556906569075690856909569105691156912569135691456915569165691756918569195692056921569225692356924569255692656927569285692956930569315693256933569345693556936569375693856939569405694156942569435694456945569465694756948569495695056951569525695356954569555695656957569585695956960569615696256963569645696556966569675696856969569705697156972569735697456975569765697756978569795698056981569825698356984569855698656987569885698956990569915699256993569945699556996569975699856999570005700157002570035700457005570065700757008570095701057011570125701357014570155701657017570185701957020570215702257023570245702557026570275702857029570305703157032570335703457035570365703757038570395704057041570425704357044570455704657047570485704957050570515705257053570545705557056570575705857059570605706157062570635706457065570665706757068570695707057071570725707357074570755707657077570785707957080570815708257083570845708557086570875708857089570905709157092570935709457095570965709757098570995710057101571025710357104571055710657107571085710957110571115711257113571145711557116571175711857119571205712157122571235712457125571265712757128571295713057131571325713357134571355713657137571385713957140571415714257143571445714557146571475714857149571505715157152571535715457155571565715757158571595716057161571625716357164571655716657167571685716957170571715717257173571745717557176571775717857179571805718157182571835718457185571865718757188571895719057191571925719357194571955719657197571985719957200572015720257203572045720557206572075720857209572105721157212572135721457215572165721757218572195722057221572225722357224572255722657227572285722957230572315723257233572345723557236572375723857239572405724157242572435724457245572465724757248572495725057251572525725357254572555725657257572585725957260572615726257263572645726557266572675726857269572705727157272572735727457275572765727757278572795728057281572825728357284572855728657287572885728957290572915729257293572945729557296572975729857299573005730157302573035730457305573065730757308573095731057311573125731357314573155731657317573185731957320573215732257323573245732557326573275732857329573305733157332573335733457335573365733757338573395734057341573425734357344573455734657347573485734957350573515735257353573545735557356573575735857359573605736157362573635736457365573665736757368573695737057371573725737357374573755737657377573785737957380573815738257383573845738557386573875738857389573905739157392573935739457395573965739757398573995740057401574025740357404574055740657407574085740957410574115741257413574145741557416574175741857419574205742157422574235742457425574265742757428574295743057431574325743357434574355743657437574385743957440574415744257443574445744557446574475744857449574505745157452574535745457455574565745757458574595746057461574625746357464574655746657467574685746957470574715747257473574745747557476574775747857479574805748157482574835748457485574865748757488574895749057491574925749357494574955749657497574985749957500575015750257503575045750557506575075750857509575105751157512575135751457515575165751757518575195752057521575225752357524575255752657527575285752957530575315753257533575345753557536575375753857539575405754157542575435754457545575465754757548575495755057551575525755357554575555755657557575585755957560575615756257563575645756557566575675756857569575705757157572575735757457575575765757757578575795758057581575825758357584575855758657587575885758957590575915759257593575945759557596575975759857599576005760157602576035760457605576065760757608576095761057611576125761357614576155761657617576185761957620576215762257623576245762557626576275762857629576305763157632576335763457635576365763757638576395764057641576425764357644576455764657647576485764957650576515765257653576545765557656576575765857659576605766157662576635766457665576665766757668576695767057671576725767357674576755767657677576785767957680576815768257683576845768557686576875768857689576905769157692576935769457695576965769757698576995770057701577025770357704577055770657707577085770957710577115771257713577145771557716577175771857719577205772157722577235772457725577265772757728577295773057731577325773357734577355773657737577385773957740577415774257743577445774557746577475774857749577505775157752577535775457755577565775757758577595776057761577625776357764577655776657767577685776957770577715777257773577745777557776577775777857779577805778157782577835778457785577865778757788577895779057791577925779357794577955779657797577985779957800578015780257803578045780557806578075780857809578105781157812578135781457815578165781757818578195782057821578225782357824578255782657827578285782957830578315783257833578345783557836578375783857839578405784157842578435784457845578465784757848578495785057851578525785357854578555785657857578585785957860578615786257863578645786557866578675786857869578705787157872578735787457875578765787757878578795788057881578825788357884578855788657887578885788957890578915789257893578945789557896578975789857899579005790157902579035790457905579065790757908579095791057911579125791357914579155791657917579185791957920579215792257923579245792557926579275792857929579305793157932579335793457935579365793757938579395794057941579425794357944579455794657947579485794957950579515795257953579545795557956579575795857959579605796157962579635796457965579665796757968579695797057971579725797357974579755797657977579785797957980579815798257983579845798557986579875798857989579905799157992579935799457995579965799757998579995800058001580025800358004580055800658007580085800958010580115801258013580145801558016580175801858019580205802158022580235802458025580265802758028580295803058031580325803358034580355803658037580385803958040580415804258043580445804558046580475804858049580505805158052580535805458055580565805758058580595806058061580625806358064580655806658067580685806958070580715807258073580745807558076580775807858079580805808158082580835808458085580865808758088580895809058091580925809358094580955809658097580985809958100581015810258103581045810558106581075810858109581105811158112581135811458115581165811758118581195812058121581225812358124581255812658127581285812958130581315813258133581345813558136581375813858139581405814158142581435814458145581465814758148581495815058151581525815358154581555815658157581585815958160581615816258163581645816558166581675816858169581705817158172581735817458175581765817758178581795818058181581825818358184581855818658187581885818958190581915819258193581945819558196581975819858199582005820158202582035820458205582065820758208582095821058211582125821358214582155821658217582185821958220582215822258223582245822558226582275822858229582305823158232582335823458235582365823758238582395824058241582425824358244582455824658247582485824958250582515825258253582545825558256582575825858259582605826158262582635826458265582665826758268582695827058271582725827358274582755827658277582785827958280582815828258283582845828558286582875828858289582905829158292582935829458295582965829758298582995830058301583025830358304583055830658307583085830958310583115831258313583145831558316583175831858319583205832158322583235832458325583265832758328583295833058331583325833358334583355833658337583385833958340583415834258343583445834558346583475834858349583505835158352583535835458355583565835758358583595836058361583625836358364583655836658367583685836958370583715837258373583745837558376583775837858379583805838158382583835838458385583865838758388583895839058391583925839358394583955839658397583985839958400584015840258403584045840558406584075840858409584105841158412584135841458415584165841758418584195842058421584225842358424584255842658427584285842958430584315843258433584345843558436584375843858439584405844158442584435844458445584465844758448584495845058451584525845358454584555845658457584585845958460584615846258463584645846558466584675846858469584705847158472584735847458475584765847758478584795848058481584825848358484584855848658487584885848958490584915849258493584945849558496584975849858499585005850158502585035850458505585065850758508585095851058511585125851358514585155851658517585185851958520585215852258523585245852558526585275852858529585305853158532585335853458535585365853758538585395854058541585425854358544585455854658547585485854958550585515855258553585545855558556585575855858559585605856158562585635856458565585665856758568585695857058571585725857358574585755857658577585785857958580585815858258583585845858558586585875858858589585905859158592585935859458595585965859758598585995860058601586025860358604586055860658607586085860958610586115861258613586145861558616586175861858619586205862158622586235862458625586265862758628586295863058631586325863358634586355863658637586385863958640586415864258643586445864558646586475864858649586505865158652586535865458655586565865758658586595866058661586625866358664586655866658667586685866958670586715867258673586745867558676586775867858679586805868158682586835868458685586865868758688586895869058691586925869358694586955869658697586985869958700587015870258703587045870558706587075870858709587105871158712587135871458715587165871758718587195872058721587225872358724587255872658727587285872958730587315873258733587345873558736587375873858739587405874158742587435874458745587465874758748587495875058751587525875358754587555875658757587585875958760587615876258763587645876558766587675876858769587705877158772587735877458775587765877758778587795878058781587825878358784587855878658787587885878958790587915879258793587945879558796587975879858799588005880158802588035880458805588065880758808588095881058811588125881358814588155881658817588185881958820588215882258823588245882558826588275882858829588305883158832588335883458835588365883758838588395884058841588425884358844588455884658847588485884958850588515885258853588545885558856588575885858859588605886158862588635886458865588665886758868588695887058871588725887358874588755887658877588785887958880588815888258883588845888558886588875888858889588905889158892588935889458895588965889758898588995890058901589025890358904589055890658907589085890958910589115891258913589145891558916589175891858919589205892158922589235892458925589265892758928589295893058931589325893358934589355893658937589385893958940589415894258943589445894558946589475894858949589505895158952589535895458955589565895758958589595896058961589625896358964589655896658967589685896958970589715897258973589745897558976589775897858979589805898158982589835898458985589865898758988589895899058991589925899358994589955899658997589985899959000590015900259003590045900559006590075900859009590105901159012590135901459015590165901759018590195902059021590225902359024590255902659027590285902959030590315903259033590345903559036590375903859039590405904159042590435904459045590465904759048590495905059051590525905359054590555905659057590585905959060590615906259063590645906559066590675906859069590705907159072590735907459075590765907759078590795908059081590825908359084590855908659087590885908959090590915909259093590945909559096590975909859099591005910159102591035910459105591065910759108591095911059111591125911359114591155911659117591185911959120591215912259123591245912559126591275912859129591305913159132591335913459135591365913759138591395914059141591425914359144591455914659147591485914959150591515915259153591545915559156591575915859159591605916159162591635916459165591665916759168591695917059171591725917359174591755917659177591785917959180591815918259183591845918559186591875918859189591905919159192591935919459195591965919759198591995920059201592025920359204592055920659207592085920959210592115921259213592145921559216592175921859219592205922159222592235922459225592265922759228592295923059231592325923359234592355923659237592385923959240592415924259243592445924559246592475924859249592505925159252592535925459255592565925759258592595926059261592625926359264592655926659267592685926959270592715927259273592745927559276592775927859279592805928159282592835928459285592865928759288592895929059291592925929359294592955929659297592985929959300593015930259303593045930559306593075930859309593105931159312593135931459315593165931759318593195932059321593225932359324593255932659327593285932959330593315933259333593345933559336593375933859339593405934159342593435934459345593465934759348593495935059351593525935359354593555935659357593585935959360593615936259363593645936559366593675936859369593705937159372593735937459375593765937759378593795938059381593825938359384593855938659387593885938959390593915939259393593945939559396593975939859399594005940159402594035940459405594065940759408594095941059411594125941359414594155941659417594185941959420594215942259423594245942559426594275942859429594305943159432594335943459435594365943759438594395944059441594425944359444594455944659447594485944959450594515945259453594545945559456594575945859459594605946159462594635946459465594665946759468594695947059471594725947359474594755947659477594785947959480594815948259483594845948559486594875948859489594905949159492594935949459495594965949759498594995950059501595025950359504595055950659507595085950959510595115951259513595145951559516595175951859519595205952159522595235952459525595265952759528595295953059531595325953359534595355953659537595385953959540595415954259543595445954559546595475954859549595505955159552595535955459555595565955759558595595956059561595625956359564595655956659567595685956959570595715957259573595745957559576595775957859579595805958159582595835958459585595865958759588595895959059591595925959359594595955959659597595985959959600596015960259603596045960559606596075960859609596105961159612596135961459615596165961759618596195962059621596225962359624596255962659627596285962959630596315963259633596345963559636596375963859639596405964159642596435964459645596465964759648596495965059651596525965359654596555965659657596585965959660596615966259663596645966559666596675966859669596705967159672596735967459675596765967759678596795968059681596825968359684596855968659687596885968959690596915969259693596945969559696596975969859699597005970159702597035970459705597065970759708597095971059711597125971359714597155971659717597185971959720597215972259723597245972559726597275972859729597305973159732597335973459735597365973759738597395974059741597425974359744597455974659747597485974959750597515975259753597545975559756597575975859759597605976159762597635976459765597665976759768597695977059771597725977359774597755977659777597785977959780597815978259783597845978559786597875978859789597905979159792597935979459795597965979759798597995980059801598025980359804598055980659807598085980959810598115981259813598145981559816598175981859819598205982159822598235982459825598265982759828598295983059831598325983359834598355983659837598385983959840598415984259843598445984559846598475984859849598505985159852598535985459855598565985759858598595986059861598625986359864598655986659867598685986959870598715987259873598745987559876598775987859879598805988159882598835988459885598865988759888598895989059891598925989359894598955989659897598985989959900599015990259903599045990559906599075990859909599105991159912599135991459915599165991759918599195992059921599225992359924599255992659927599285992959930599315993259933599345993559936599375993859939599405994159942599435994459945599465994759948599495995059951599525995359954599555995659957599585995959960599615996259963599645996559966599675996859969599705997159972599735997459975599765997759978599795998059981599825998359984599855998659987599885998959990599915999259993599945999559996599975999859999600006000160002600036000460005600066000760008600096001060011600126001360014600156001660017600186001960020600216002260023600246002560026600276002860029600306003160032600336003460035600366003760038600396004060041600426004360044600456004660047600486004960050600516005260053600546005560056600576005860059600606006160062600636006460065600666006760068600696007060071600726007360074600756007660077600786007960080600816008260083600846008560086600876008860089600906009160092600936009460095600966009760098600996010060101601026010360104601056010660107601086010960110601116011260113601146011560116601176011860119601206012160122601236012460125601266012760128601296013060131601326013360134601356013660137601386013960140601416014260143601446014560146601476014860149601506015160152601536015460155601566015760158601596016060161601626016360164601656016660167601686016960170601716017260173601746017560176601776017860179601806018160182601836018460185601866018760188601896019060191601926019360194601956019660197601986019960200602016020260203602046020560206602076020860209602106021160212602136021460215602166021760218602196022060221602226022360224602256022660227602286022960230602316023260233602346023560236602376023860239602406024160242602436024460245602466024760248602496025060251602526025360254602556025660257602586025960260602616026260263602646026560266602676026860269602706027160272602736027460275602766027760278602796028060281602826028360284602856028660287602886028960290602916029260293602946029560296602976029860299603006030160302603036030460305603066030760308603096031060311603126031360314603156031660317603186031960320603216032260323603246032560326603276032860329603306033160332603336033460335603366033760338603396034060341603426034360344603456034660347603486034960350603516035260353603546035560356603576035860359603606036160362603636036460365603666036760368603696037060371603726037360374603756037660377603786037960380603816038260383603846038560386603876038860389603906039160392603936039460395603966039760398603996040060401604026040360404604056040660407604086040960410604116041260413604146041560416604176041860419604206042160422604236042460425604266042760428604296043060431604326043360434604356043660437604386043960440604416044260443604446044560446604476044860449604506045160452604536045460455604566045760458604596046060461604626046360464604656046660467604686046960470604716047260473604746047560476604776047860479604806048160482604836048460485604866048760488604896049060491604926049360494604956049660497604986049960500605016050260503605046050560506605076050860509605106051160512605136051460515605166051760518605196052060521605226052360524605256052660527605286052960530605316053260533605346053560536605376053860539605406054160542605436054460545605466054760548605496055060551605526055360554605556055660557605586055960560605616056260563605646056560566605676056860569605706057160572605736057460575605766057760578605796058060581605826058360584605856058660587605886058960590605916059260593605946059560596605976059860599606006060160602606036060460605606066060760608606096061060611606126061360614606156061660617606186061960620606216062260623606246062560626606276062860629606306063160632606336063460635606366063760638606396064060641606426064360644606456064660647606486064960650606516065260653606546065560656606576065860659606606066160662606636066460665606666066760668606696067060671606726067360674606756067660677606786067960680606816068260683606846068560686606876068860689606906069160692606936069460695606966069760698606996070060701607026070360704607056070660707607086070960710607116071260713607146071560716607176071860719607206072160722607236072460725607266072760728607296073060731607326073360734607356073660737607386073960740607416074260743607446074560746607476074860749607506075160752607536075460755607566075760758607596076060761607626076360764607656076660767607686076960770607716077260773607746077560776607776077860779607806078160782607836078460785607866078760788607896079060791607926079360794607956079660797607986079960800608016080260803608046080560806608076080860809608106081160812608136081460815608166081760818608196082060821608226082360824608256082660827608286082960830608316083260833608346083560836608376083860839608406084160842608436084460845608466084760848608496085060851608526085360854608556085660857608586085960860608616086260863608646086560866608676086860869608706087160872608736087460875608766087760878608796088060881608826088360884608856088660887608886088960890608916089260893608946089560896608976089860899609006090160902609036090460905609066090760908609096091060911609126091360914609156091660917609186091960920609216092260923609246092560926609276092860929609306093160932609336093460935609366093760938609396094060941609426094360944609456094660947609486094960950609516095260953609546095560956609576095860959609606096160962609636096460965609666096760968609696097060971609726097360974609756097660977609786097960980609816098260983609846098560986609876098860989609906099160992609936099460995609966099760998609996100061001610026100361004610056100661007610086100961010610116101261013610146101561016610176101861019610206102161022610236102461025610266102761028610296103061031610326103361034610356103661037610386103961040610416104261043610446104561046610476104861049610506105161052610536105461055610566105761058610596106061061610626106361064610656106661067610686106961070610716107261073610746107561076610776107861079610806108161082610836108461085610866108761088610896109061091610926109361094610956109661097610986109961100611016110261103611046110561106611076110861109611106111161112611136111461115611166111761118611196112061121611226112361124611256112661127611286112961130611316113261133611346113561136611376113861139611406114161142611436114461145611466114761148611496115061151611526115361154611556115661157611586115961160611616116261163611646116561166611676116861169611706117161172611736117461175611766117761178611796118061181611826118361184611856118661187611886118961190611916119261193611946119561196611976119861199612006120161202612036120461205612066120761208612096121061211612126121361214612156121661217612186121961220612216122261223612246122561226612276122861229612306123161232612336123461235612366123761238612396124061241612426124361244612456124661247612486124961250612516125261253612546125561256612576125861259612606126161262612636126461265612666126761268612696127061271612726127361274612756127661277612786127961280612816128261283612846128561286612876128861289612906129161292612936129461295612966129761298612996130061301613026130361304613056130661307613086130961310613116131261313613146131561316613176131861319613206132161322613236132461325613266132761328613296133061331613326133361334613356133661337613386133961340613416134261343613446134561346613476134861349613506135161352613536135461355613566135761358613596136061361613626136361364613656136661367613686136961370613716137261373613746137561376613776137861379613806138161382613836138461385613866138761388613896139061391613926139361394613956139661397613986139961400614016140261403614046140561406614076140861409614106141161412614136141461415614166141761418614196142061421614226142361424614256142661427614286142961430614316143261433614346143561436614376143861439614406144161442614436144461445614466144761448614496145061451614526145361454614556145661457614586145961460614616146261463614646146561466614676146861469614706147161472614736147461475614766147761478614796148061481614826148361484614856148661487614886148961490614916149261493614946149561496614976149861499615006150161502615036150461505615066150761508615096151061511615126151361514615156151661517615186151961520615216152261523615246152561526615276152861529615306153161532615336153461535615366153761538615396154061541615426154361544615456154661547615486154961550615516155261553615546155561556615576155861559615606156161562615636156461565615666156761568615696157061571615726157361574615756157661577615786157961580615816158261583615846158561586615876158861589615906159161592615936159461595615966159761598615996160061601616026160361604616056160661607616086160961610616116161261613616146161561616616176161861619616206162161622616236162461625616266162761628616296163061631616326163361634616356163661637616386163961640616416164261643616446164561646616476164861649616506165161652616536165461655616566165761658616596166061661616626166361664616656166661667616686166961670616716167261673616746167561676616776167861679616806168161682616836168461685616866168761688616896169061691616926169361694616956169661697616986169961700617016170261703617046170561706617076170861709617106171161712617136171461715617166171761718617196172061721617226172361724617256172661727617286172961730617316173261733617346173561736617376173861739617406174161742617436174461745617466174761748617496175061751617526175361754617556175661757617586175961760617616176261763617646176561766617676176861769617706177161772617736177461775617766177761778617796178061781617826178361784617856178661787617886178961790617916179261793617946179561796617976179861799618006180161802618036180461805618066180761808618096181061811618126181361814618156181661817618186181961820618216182261823618246182561826618276182861829618306183161832618336183461835618366183761838618396184061841618426184361844618456184661847618486184961850618516185261853618546185561856618576185861859618606186161862618636186461865618666186761868618696187061871618726187361874618756187661877618786187961880618816188261883618846188561886618876188861889618906189161892618936189461895618966189761898618996190061901619026190361904619056190661907619086190961910619116191261913619146191561916619176191861919619206192161922619236192461925619266192761928619296193061931619326193361934619356193661937619386193961940619416194261943619446194561946619476194861949619506195161952619536195461955619566195761958619596196061961619626196361964619656196661967619686196961970619716197261973619746197561976619776197861979619806198161982619836198461985619866198761988619896199061991619926199361994619956199661997619986199962000620016200262003620046200562006620076200862009620106201162012620136201462015620166201762018620196202062021620226202362024620256202662027620286202962030620316203262033620346203562036620376203862039620406204162042620436204462045620466204762048620496205062051620526205362054620556205662057620586205962060620616206262063620646206562066620676206862069620706207162072620736207462075620766207762078620796208062081620826208362084620856208662087620886208962090620916209262093620946209562096620976209862099621006210162102621036210462105621066210762108621096211062111621126211362114621156211662117621186211962120621216212262123621246212562126621276212862129621306213162132621336213462135621366213762138621396214062141621426214362144621456214662147621486214962150621516215262153621546215562156621576215862159621606216162162621636216462165621666216762168621696217062171621726217362174621756217662177621786217962180621816218262183621846218562186621876218862189621906219162192621936219462195621966219762198621996220062201622026220362204622056220662207622086220962210622116221262213622146221562216622176221862219622206222162222622236222462225622266222762228622296223062231622326223362234622356223662237622386223962240622416224262243622446224562246622476224862249622506225162252622536225462255622566225762258622596226062261622626226362264622656226662267622686226962270622716227262273622746227562276622776227862279622806228162282622836228462285622866228762288622896229062291622926229362294622956229662297622986229962300623016230262303623046230562306623076230862309623106231162312623136231462315623166231762318623196232062321623226232362324623256232662327623286232962330623316233262333623346233562336623376233862339623406234162342623436234462345623466234762348623496235062351623526235362354623556235662357623586235962360623616236262363623646236562366623676236862369623706237162372623736237462375623766237762378623796238062381623826238362384623856238662387623886238962390623916239262393623946239562396623976239862399624006240162402624036240462405624066240762408624096241062411624126241362414624156241662417624186241962420624216242262423624246242562426624276242862429624306243162432624336243462435624366243762438624396244062441624426244362444624456244662447624486244962450624516245262453624546245562456624576245862459624606246162462624636246462465624666246762468624696247062471624726247362474624756247662477624786247962480624816248262483624846248562486624876248862489624906249162492624936249462495624966249762498624996250062501625026250362504625056250662507625086250962510625116251262513625146251562516625176251862519625206252162522625236252462525625266252762528625296253062531625326253362534625356253662537625386253962540625416254262543625446254562546625476254862549625506255162552625536255462555625566255762558625596256062561625626256362564625656256662567625686256962570625716257262573625746257562576625776257862579625806258162582625836258462585625866258762588625896259062591625926259362594625956259662597625986259962600626016260262603626046260562606626076260862609626106261162612626136261462615626166261762618626196262062621626226262362624626256262662627626286262962630626316263262633626346263562636626376263862639626406264162642626436264462645626466264762648626496265062651626526265362654626556265662657626586265962660626616266262663626646266562666626676266862669626706267162672626736267462675626766267762678626796268062681626826268362684626856268662687626886268962690626916269262693626946269562696626976269862699627006270162702627036270462705627066270762708627096271062711627126271362714627156271662717627186271962720627216272262723627246272562726627276272862729627306273162732627336273462735627366273762738627396274062741627426274362744627456274662747627486274962750627516275262753627546275562756627576275862759627606276162762627636276462765627666276762768627696277062771627726277362774627756277662777627786277962780627816278262783627846278562786627876278862789627906279162792627936279462795627966279762798627996280062801628026280362804628056280662807628086280962810628116281262813628146281562816628176281862819628206282162822628236282462825628266282762828628296283062831628326283362834628356283662837628386283962840628416284262843628446284562846628476284862849628506285162852628536285462855628566285762858628596286062861628626286362864628656286662867628686286962870628716287262873628746287562876628776287862879628806288162882628836288462885628866288762888628896289062891628926289362894628956289662897628986289962900629016290262903629046290562906629076290862909629106291162912629136291462915629166291762918629196292062921629226292362924629256292662927629286292962930629316293262933629346293562936629376293862939629406294162942629436294462945629466294762948629496295062951629526295362954629556295662957629586295962960629616296262963629646296562966629676296862969629706297162972629736297462975629766297762978629796298062981629826298362984629856298662987629886298962990629916299262993629946299562996629976299862999630006300163002630036300463005630066300763008630096301063011630126301363014630156301663017630186301963020630216302263023630246302563026630276302863029630306303163032630336303463035630366303763038630396304063041630426304363044630456304663047630486304963050630516305263053630546305563056630576305863059630606306163062630636306463065630666306763068630696307063071630726307363074630756307663077630786307963080630816308263083630846308563086630876308863089630906309163092630936309463095630966309763098630996310063101631026310363104631056310663107631086310963110631116311263113631146311563116631176311863119631206312163122631236312463125631266312763128631296313063131631326313363134631356313663137631386313963140631416314263143631446314563146631476314863149631506315163152631536315463155631566315763158631596316063161631626316363164631656316663167631686316963170631716317263173631746317563176631776317863179631806318163182631836318463185631866318763188631896319063191631926319363194631956319663197631986319963200632016320263203632046320563206632076320863209632106321163212632136321463215632166321763218632196322063221632226322363224632256322663227632286322963230632316323263233632346323563236632376323863239632406324163242632436324463245632466324763248632496325063251632526325363254632556325663257632586325963260632616326263263632646326563266632676326863269632706327163272632736327463275632766327763278632796328063281632826328363284632856328663287632886328963290632916329263293632946329563296632976329863299633006330163302633036330463305633066330763308633096331063311633126331363314633156331663317633186331963320633216332263323633246332563326633276332863329633306333163332633336333463335633366333763338633396334063341633426334363344633456334663347633486334963350633516335263353633546335563356633576335863359633606336163362633636336463365633666336763368633696337063371633726337363374633756337663377633786337963380633816338263383633846338563386633876338863389633906339163392633936339463395633966339763398633996340063401634026340363404634056340663407634086340963410634116341263413634146341563416634176341863419634206342163422634236342463425634266342763428634296343063431634326343363434634356343663437634386343963440634416344263443634446344563446634476344863449634506345163452634536345463455634566345763458634596346063461634626346363464634656346663467634686346963470634716347263473634746347563476634776347863479634806348163482634836348463485634866348763488634896349063491634926349363494634956349663497634986349963500635016350263503635046350563506635076350863509635106351163512635136351463515635166351763518635196352063521635226352363524635256352663527635286352963530635316353263533635346353563536635376353863539635406354163542635436354463545635466354763548635496355063551635526355363554635556355663557635586355963560635616356263563635646356563566635676356863569635706357163572635736357463575635766357763578635796358063581635826358363584635856358663587635886358963590635916359263593635946359563596635976359863599636006360163602636036360463605636066360763608636096361063611636126361363614636156361663617636186361963620636216362263623636246362563626636276362863629636306363163632636336363463635636366363763638636396364063641636426364363644636456364663647636486364963650636516365263653636546365563656636576365863659636606366163662636636366463665636666366763668636696367063671636726367363674636756367663677636786367963680636816368263683636846368563686636876368863689636906369163692636936369463695636966369763698636996370063701637026370363704637056370663707637086370963710637116371263713637146371563716637176371863719637206372163722637236372463725637266372763728637296373063731637326373363734637356373663737637386373963740637416374263743637446374563746637476374863749637506375163752637536375463755637566375763758637596376063761637626376363764637656376663767637686376963770637716377263773637746377563776637776377863779637806378163782637836378463785637866378763788637896379063791637926379363794637956379663797637986379963800638016380263803638046380563806638076380863809638106381163812638136381463815638166381763818638196382063821638226382363824638256382663827638286382963830638316383263833638346383563836638376383863839638406384163842638436384463845638466384763848638496385063851638526385363854638556385663857638586385963860638616386263863638646386563866638676386863869638706387163872638736387463875638766387763878638796388063881638826388363884638856388663887638886388963890638916389263893638946389563896638976389863899639006390163902639036390463905639066390763908639096391063911639126391363914639156391663917639186391963920639216392263923639246392563926639276392863929639306393163932639336393463935639366393763938639396394063941639426394363944639456394663947639486394963950639516395263953639546395563956639576395863959639606396163962639636396463965639666396763968639696397063971639726397363974639756397663977639786397963980639816398263983639846398563986639876398863989639906399163992639936399463995639966399763998639996400064001640026400364004640056400664007640086400964010640116401264013640146401564016640176401864019640206402164022640236402464025640266402764028640296403064031640326403364034640356403664037640386403964040640416404264043640446404564046640476404864049640506405164052640536405464055640566405764058640596406064061640626406364064640656406664067640686406964070640716407264073640746407564076640776407864079640806408164082640836408464085640866408764088640896409064091640926409364094640956409664097640986409964100641016410264103641046410564106641076410864109641106411164112641136411464115641166411764118641196412064121641226412364124641256412664127641286412964130641316413264133641346413564136641376413864139641406414164142641436414464145641466414764148641496415064151641526415364154641556415664157641586415964160641616416264163641646416564166641676416864169641706417164172641736417464175641766417764178641796418064181641826418364184641856418664187641886418964190641916419264193641946419564196641976419864199642006420164202642036420464205642066420764208642096421064211642126421364214642156421664217642186421964220642216422264223642246422564226642276422864229642306423164232642336423464235642366423764238642396424064241642426424364244642456424664247642486424964250642516425264253642546425564256642576425864259642606426164262642636426464265642666426764268642696427064271642726427364274642756427664277642786427964280642816428264283642846428564286642876428864289642906429164292642936429464295642966429764298642996430064301643026430364304643056430664307643086430964310643116431264313643146431564316643176431864319643206432164322643236432464325643266432764328643296433064331643326433364334643356433664337643386433964340643416434264343643446434564346643476434864349643506435164352643536435464355643566435764358643596436064361643626436364364643656436664367643686436964370643716437264373643746437564376643776437864379643806438164382643836438464385643866438764388643896439064391643926439364394643956439664397643986439964400644016440264403644046440564406644076440864409644106441164412644136441464415644166441764418644196442064421644226442364424644256442664427644286442964430644316443264433644346443564436644376443864439644406444164442644436444464445644466444764448644496445064451644526445364454644556445664457644586445964460644616446264463644646446564466644676446864469644706447164472644736447464475644766447764478644796448064481644826448364484644856448664487644886448964490644916449264493644946449564496644976449864499645006450164502645036450464505645066450764508645096451064511645126451364514645156451664517645186451964520645216452264523645246452564526645276452864529645306453164532645336453464535645366453764538645396454064541645426454364544645456454664547645486454964550645516455264553645546455564556645576455864559645606456164562645636456464565645666456764568645696457064571645726457364574645756457664577645786457964580645816458264583645846458564586645876458864589645906459164592645936459464595645966459764598645996460064601646026460364604646056460664607646086460964610646116461264613646146461564616646176461864619646206462164622646236462464625646266462764628646296463064631646326463364634646356463664637646386463964640646416464264643646446464564646646476464864649646506465164652646536465464655646566465764658646596466064661646626466364664646656466664667646686466964670646716467264673646746467564676646776467864679646806468164682646836468464685646866468764688646896469064691646926469364694646956469664697646986469964700647016470264703647046470564706647076470864709647106471164712647136471464715647166471764718647196472064721647226472364724647256472664727647286472964730647316473264733647346473564736647376473864739647406474164742647436474464745647466474764748647496475064751647526475364754647556475664757647586475964760647616476264763647646476564766647676476864769647706477164772647736477464775647766477764778647796478064781647826478364784647856478664787647886478964790647916479264793647946479564796647976479864799648006480164802648036480464805648066480764808648096481064811648126481364814648156481664817648186481964820648216482264823648246482564826648276482864829648306483164832648336483464835648366483764838648396484064841648426484364844648456484664847648486484964850648516485264853648546485564856648576485864859648606486164862648636486464865648666486764868648696487064871648726487364874648756487664877648786487964880648816488264883648846488564886648876488864889648906489164892648936489464895648966489764898648996490064901649026490364904649056490664907649086490964910649116491264913649146491564916649176491864919649206492164922649236492464925649266492764928649296493064931649326493364934649356493664937649386493964940649416494264943649446494564946649476494864949649506495164952649536495464955649566495764958649596496064961649626496364964649656496664967649686496964970649716497264973649746497564976649776497864979649806498164982649836498464985649866498764988649896499064991649926499364994649956499664997649986499965000650016500265003650046500565006650076500865009650106501165012650136501465015650166501765018650196502065021650226502365024650256502665027650286502965030650316503265033650346503565036650376503865039650406504165042650436504465045650466504765048650496505065051650526505365054650556505665057650586505965060650616506265063650646506565066650676506865069650706507165072650736507465075650766507765078650796508065081650826508365084650856508665087650886508965090650916509265093650946509565096650976509865099651006510165102651036510465105651066510765108651096511065111651126511365114651156511665117651186511965120651216512265123651246512565126651276512865129651306513165132651336513465135651366513765138651396514065141651426514365144651456514665147651486514965150651516515265153651546515565156651576515865159651606516165162651636516465165651666516765168651696517065171651726517365174651756517665177651786517965180651816518265183651846518565186651876518865189651906519165192651936519465195651966519765198651996520065201652026520365204652056520665207652086520965210652116521265213652146521565216652176521865219652206522165222652236522465225652266522765228652296523065231652326523365234652356523665237652386523965240652416524265243652446524565246652476524865249652506525165252652536525465255652566525765258652596526065261652626526365264652656526665267652686526965270652716527265273652746527565276652776527865279652806528165282652836528465285652866528765288652896529065291652926529365294652956529665297652986529965300653016530265303653046530565306653076530865309653106531165312653136531465315653166531765318653196532065321653226532365324653256532665327653286532965330653316533265333653346533565336653376533865339653406534165342653436534465345653466534765348653496535065351653526535365354653556535665357653586535965360653616536265363653646536565366653676536865369653706537165372653736537465375653766537765378653796538065381653826538365384653856538665387653886538965390653916539265393653946539565396653976539865399654006540165402654036540465405654066540765408654096541065411654126541365414654156541665417654186541965420654216542265423654246542565426654276542865429654306543165432654336543465435654366543765438654396544065441654426544365444654456544665447654486544965450654516545265453654546545565456654576545865459654606546165462654636546465465654666546765468654696547065471654726547365474654756547665477654786547965480654816548265483654846548565486654876548865489654906549165492654936549465495654966549765498654996550065501655026550365504655056550665507655086550965510655116551265513655146551565516655176551865519655206552165522655236552465525655266552765528655296553065531655326553365534655356553665537655386553965540655416554265543655446554565546655476554865549655506555165552655536555465555655566555765558655596556065561655626556365564655656556665567655686556965570655716557265573655746557565576655776557865579655806558165582655836558465585655866558765588655896559065591655926559365594655956559665597655986559965600656016560265603656046560565606656076560865609656106561165612656136561465615656166561765618656196562065621656226562365624656256562665627656286562965630656316563265633656346563565636656376563865639656406564165642656436564465645656466564765648656496565065651656526565365654656556565665657656586565965660656616566265663656646566565666656676566865669656706567165672656736567465675656766567765678656796568065681656826568365684656856568665687656886568965690656916569265693656946569565696656976569865699657006570165702657036570465705657066570765708657096571065711657126571365714657156571665717657186571965720657216572265723657246572565726657276572865729657306573165732657336573465735657366573765738657396574065741657426574365744657456574665747657486574965750657516575265753657546575565756657576575865759657606576165762657636576465765657666576765768657696577065771657726577365774657756577665777657786577965780657816578265783657846578565786657876578865789657906579165792657936579465795657966579765798657996580065801658026580365804658056580665807658086580965810658116581265813658146581565816658176581865819658206582165822658236582465825658266582765828658296583065831658326583365834658356583665837658386583965840658416584265843658446584565846658476584865849658506585165852658536585465855658566585765858658596586065861658626586365864658656586665867658686586965870658716587265873658746587565876658776587865879658806588165882658836588465885658866588765888658896589065891658926589365894658956589665897658986589965900659016590265903659046590565906659076590865909659106591165912659136591465915659166591765918659196592065921659226592365924659256592665927659286592965930659316593265933659346593565936659376593865939659406594165942659436594465945659466594765948659496595065951659526595365954659556595665957659586595965960659616596265963659646596565966659676596865969659706597165972659736597465975659766597765978659796598065981659826598365984659856598665987659886598965990659916599265993659946599565996659976599865999660006600166002660036600466005660066600766008660096601066011660126601366014660156601666017660186601966020660216602266023660246602566026660276602866029660306603166032660336603466035660366603766038660396604066041660426604366044660456604666047660486604966050660516605266053660546605566056660576605866059660606606166062660636606466065660666606766068660696607066071660726607366074660756607666077660786607966080660816608266083660846608566086660876608866089660906609166092660936609466095660966609766098660996610066101661026610366104661056610666107661086610966110661116611266113661146611566116661176611866119661206612166122661236612466125661266612766128661296613066131661326613366134661356613666137661386613966140661416614266143661446614566146661476614866149661506615166152661536615466155661566615766158661596616066161661626616366164661656616666167661686616966170661716617266173661746617566176661776617866179661806618166182661836618466185661866618766188661896619066191661926619366194661956619666197661986619966200662016620266203662046620566206662076620866209662106621166212662136621466215662166621766218662196622066221662226622366224662256622666227662286622966230662316623266233662346623566236662376623866239662406624166242662436624466245662466624766248662496625066251662526625366254662556625666257662586625966260662616626266263662646626566266662676626866269662706627166272662736627466275662766627766278662796628066281662826628366284662856628666287662886628966290662916629266293662946629566296662976629866299663006630166302663036630466305663066630766308663096631066311663126631366314663156631666317663186631966320663216632266323663246632566326663276632866329663306633166332663336633466335663366633766338663396634066341663426634366344663456634666347663486634966350663516635266353663546635566356663576635866359663606636166362663636636466365663666636766368663696637066371663726637366374663756637666377663786637966380663816638266383663846638566386663876638866389663906639166392663936639466395663966639766398663996640066401664026640366404664056640666407664086640966410664116641266413664146641566416664176641866419664206642166422664236642466425664266642766428664296643066431664326643366434664356643666437664386643966440664416644266443664446644566446664476644866449664506645166452664536645466455664566645766458664596646066461664626646366464664656646666467664686646966470664716647266473664746647566476664776647866479664806648166482664836648466485664866648766488664896649066491664926649366494664956649666497664986649966500665016650266503665046650566506665076650866509665106651166512665136651466515665166651766518665196652066521665226652366524665256652666527665286652966530665316653266533665346653566536665376653866539665406654166542665436654466545665466654766548665496655066551665526655366554665556655666557665586655966560665616656266563665646656566566665676656866569665706657166572665736657466575665766657766578665796658066581665826658366584665856658666587665886658966590665916659266593665946659566596665976659866599666006660166602666036660466605666066660766608666096661066611666126661366614666156661666617666186661966620666216662266623666246662566626666276662866629666306663166632666336663466635666366663766638666396664066641666426664366644666456664666647666486664966650666516665266653666546665566656666576665866659666606666166662666636666466665666666666766668666696667066671666726667366674666756667666677666786667966680666816668266683666846668566686666876668866689666906669166692666936669466695666966669766698666996670066701667026670366704667056670666707667086670966710667116671266713667146671566716667176671866719667206672166722667236672466725667266672766728667296673066731667326673366734667356673666737667386673966740667416674266743667446674566746667476674866749667506675166752667536675466755667566675766758667596676066761667626676366764667656676666767667686676966770667716677266773667746677566776667776677866779667806678166782667836678466785667866678766788667896679066791667926679366794667956679666797667986679966800668016680266803668046680566806668076680866809668106681166812668136681466815668166681766818668196682066821668226682366824668256682666827668286682966830668316683266833668346683566836668376683866839668406684166842668436684466845668466684766848668496685066851668526685366854668556685666857668586685966860668616686266863668646686566866668676686866869668706687166872668736687466875668766687766878668796688066881668826688366884668856688666887668886688966890668916689266893668946689566896668976689866899669006690166902669036690466905669066690766908669096691066911669126691366914669156691666917669186691966920669216692266923669246692566926669276692866929669306693166932669336693466935669366693766938669396694066941669426694366944669456694666947669486694966950669516695266953669546695566956669576695866959669606696166962669636696466965669666696766968669696697066971669726697366974669756697666977669786697966980669816698266983669846698566986669876698866989669906699166992669936699466995669966699766998669996700067001670026700367004670056700667007670086700967010670116701267013670146701567016670176701867019670206702167022670236702467025670266702767028670296703067031670326703367034670356703667037670386703967040670416704267043670446704567046670476704867049670506705167052670536705467055670566705767058670596706067061670626706367064670656706667067670686706967070670716707267073670746707567076670776707867079670806708167082670836708467085670866708767088670896709067091670926709367094670956709667097670986709967100671016710267103671046710567106671076710867109671106711167112671136711467115671166711767118671196712067121671226712367124671256712667127671286712967130671316713267133671346713567136671376713867139671406714167142671436714467145671466714767148671496715067151671526715367154671556715667157671586715967160671616716267163671646716567166671676716867169671706717167172671736717467175671766717767178671796718067181671826718367184671856718667187671886718967190671916719267193671946719567196671976719867199672006720167202672036720467205672066720767208672096721067211672126721367214672156721667217672186721967220672216722267223672246722567226672276722867229672306723167232672336723467235672366723767238672396724067241672426724367244672456724667247672486724967250672516725267253672546725567256672576725867259672606726167262672636726467265672666726767268672696727067271672726727367274672756727667277672786727967280672816728267283672846728567286672876728867289672906729167292672936729467295672966729767298672996730067301673026730367304673056730667307673086730967310673116731267313673146731567316673176731867319673206732167322673236732467325673266732767328673296733067331673326733367334673356733667337673386733967340673416734267343673446734567346673476734867349673506735167352673536735467355673566735767358673596736067361673626736367364673656736667367673686736967370673716737267373673746737567376673776737867379673806738167382673836738467385673866738767388673896739067391673926739367394673956739667397673986739967400674016740267403674046740567406674076740867409674106741167412674136741467415674166741767418674196742067421674226742367424674256742667427674286742967430674316743267433674346743567436674376743867439674406744167442674436744467445674466744767448674496745067451674526745367454674556745667457674586745967460674616746267463674646746567466674676746867469674706747167472674736747467475674766747767478674796748067481674826748367484674856748667487674886748967490674916749267493674946749567496674976749867499675006750167502675036750467505675066750767508675096751067511675126751367514675156751667517675186751967520675216752267523675246752567526675276752867529675306753167532675336753467535675366753767538675396754067541675426754367544675456754667547675486754967550675516755267553675546755567556675576755867559675606756167562675636756467565675666756767568675696757067571675726757367574675756757667577675786757967580675816758267583675846758567586675876758867589675906759167592675936759467595675966759767598675996760067601676026760367604676056760667607676086760967610676116761267613676146761567616676176761867619676206762167622676236762467625676266762767628676296763067631676326763367634676356763667637676386763967640676416764267643676446764567646676476764867649676506765167652676536765467655676566765767658676596766067661676626766367664676656766667667676686766967670676716767267673676746767567676676776767867679676806768167682676836768467685676866768767688676896769067691676926769367694676956769667697676986769967700677016770267703677046770567706677076770867709677106771167712677136771467715677166771767718677196772067721677226772367724677256772667727677286772967730677316773267733677346773567736677376773867739677406774167742677436774467745677466774767748677496775067751677526775367754677556775667757677586775967760677616776267763677646776567766677676776867769677706777167772677736777467775677766777767778677796778067781677826778367784677856778667787677886778967790677916779267793677946779567796677976779867799678006780167802678036780467805678066780767808678096781067811678126781367814678156781667817678186781967820678216782267823678246782567826678276782867829678306783167832678336783467835678366783767838678396784067841678426784367844678456784667847678486784967850678516785267853678546785567856678576785867859678606786167862678636786467865678666786767868678696787067871678726787367874678756787667877678786787967880678816788267883678846788567886678876788867889678906789167892678936789467895678966789767898678996790067901679026790367904679056790667907679086790967910679116791267913679146791567916679176791867919679206792167922679236792467925679266792767928679296793067931679326793367934679356793667937679386793967940679416794267943679446794567946679476794867949679506795167952679536795467955679566795767958679596796067961679626796367964679656796667967679686796967970679716797267973679746797567976679776797867979679806798167982679836798467985679866798767988679896799067991679926799367994679956799667997679986799968000680016800268003680046800568006680076800868009680106801168012680136801468015680166801768018680196802068021680226802368024680256802668027680286802968030680316803268033680346803568036680376803868039680406804168042680436804468045680466804768048680496805068051680526805368054680556805668057680586805968060680616806268063680646806568066680676806868069680706807168072680736807468075680766807768078680796808068081680826808368084680856808668087680886808968090680916809268093680946809568096680976809868099681006810168102681036810468105681066810768108681096811068111681126811368114681156811668117681186811968120681216812268123681246812568126681276812868129681306813168132681336813468135681366813768138681396814068141681426814368144681456814668147681486814968150681516815268153681546815568156681576815868159681606816168162681636816468165681666816768168681696817068171681726817368174681756817668177681786817968180681816818268183681846818568186681876818868189681906819168192681936819468195681966819768198681996820068201682026820368204682056820668207682086820968210682116821268213682146821568216682176821868219682206822168222682236822468225682266822768228682296823068231682326823368234682356823668237682386823968240682416824268243682446824568246682476824868249682506825168252682536825468255682566825768258682596826068261682626826368264682656826668267682686826968270682716827268273682746827568276682776827868279682806828168282682836828468285682866828768288682896829068291682926829368294682956829668297682986829968300683016830268303683046830568306683076830868309683106831168312683136831468315683166831768318683196832068321683226832368324683256832668327683286832968330683316833268333683346833568336683376833868339683406834168342683436834468345683466834768348683496835068351683526835368354683556835668357683586835968360683616836268363683646836568366683676836868369683706837168372683736837468375683766837768378683796838068381683826838368384683856838668387683886838968390683916839268393683946839568396683976839868399684006840168402684036840468405684066840768408684096841068411684126841368414684156841668417684186841968420684216842268423684246842568426684276842868429684306843168432684336843468435684366843768438684396844068441684426844368444684456844668447684486844968450684516845268453684546845568456684576845868459684606846168462684636846468465684666846768468684696847068471684726847368474684756847668477684786847968480684816848268483684846848568486684876848868489684906849168492684936849468495684966849768498684996850068501685026850368504685056850668507685086850968510685116851268513685146851568516685176851868519685206852168522685236852468525685266852768528685296853068531685326853368534685356853668537685386853968540685416854268543685446854568546685476854868549685506855168552685536855468555685566855768558685596856068561685626856368564685656856668567685686856968570685716857268573685746857568576685776857868579685806858168582685836858468585685866858768588685896859068591685926859368594685956859668597685986859968600686016860268603686046860568606686076860868609686106861168612686136861468615686166861768618686196862068621686226862368624686256862668627686286862968630686316863268633686346863568636686376863868639686406864168642686436864468645686466864768648686496865068651686526865368654686556865668657686586865968660686616866268663686646866568666686676866868669686706867168672686736867468675686766867768678686796868068681686826868368684686856868668687686886868968690686916869268693686946869568696686976869868699687006870168702687036870468705687066870768708687096871068711687126871368714687156871668717687186871968720687216872268723687246872568726687276872868729687306873168732687336873468735687366873768738687396874068741687426874368744687456874668747687486874968750687516875268753687546875568756687576875868759687606876168762687636876468765687666876768768687696877068771687726877368774687756877668777687786877968780687816878268783687846878568786687876878868789687906879168792687936879468795687966879768798687996880068801688026880368804688056880668807688086880968810688116881268813688146881568816688176881868819688206882168822688236882468825688266882768828688296883068831688326883368834688356883668837688386883968840688416884268843688446884568846688476884868849688506885168852688536885468855688566885768858688596886068861688626886368864688656886668867688686886968870688716887268873688746887568876688776887868879688806888168882688836888468885688866888768888688896889068891688926889368894688956889668897688986889968900689016890268903689046890568906689076890868909689106891168912689136891468915689166891768918689196892068921689226892368924689256892668927689286892968930689316893268933689346893568936689376893868939689406894168942689436894468945689466894768948689496895068951689526895368954689556895668957689586895968960689616896268963689646896568966689676896868969689706897168972689736897468975689766897768978689796898068981689826898368984689856898668987689886898968990689916899268993689946899568996689976899868999690006900169002690036900469005690066900769008690096901069011690126901369014690156901669017690186901969020690216902269023690246902569026690276902869029690306903169032690336903469035690366903769038690396904069041690426904369044690456904669047690486904969050690516905269053690546905569056690576905869059690606906169062690636906469065690666906769068690696907069071690726907369074690756907669077690786907969080690816908269083690846908569086690876908869089690906909169092690936909469095690966909769098690996910069101691026910369104691056910669107691086910969110691116911269113691146911569116691176911869119691206912169122691236912469125691266912769128691296913069131691326913369134691356913669137691386913969140691416914269143691446914569146691476914869149691506915169152691536915469155691566915769158691596916069161691626916369164691656916669167691686916969170691716917269173691746917569176691776917869179691806918169182691836918469185691866918769188691896919069191691926919369194691956919669197691986919969200692016920269203692046920569206692076920869209692106921169212692136921469215692166921769218692196922069221692226922369224692256922669227692286922969230692316923269233692346923569236692376923869239692406924169242692436924469245692466924769248692496925069251692526925369254692556925669257692586925969260692616926269263692646926569266692676926869269692706927169272692736927469275692766927769278692796928069281692826928369284692856928669287692886928969290692916929269293692946929569296692976929869299693006930169302693036930469305693066930769308693096931069311693126931369314693156931669317693186931969320693216932269323693246932569326693276932869329693306933169332693336933469335693366933769338693396934069341693426934369344693456934669347693486934969350693516935269353693546935569356693576935869359693606936169362693636936469365693666936769368693696937069371693726937369374693756937669377693786937969380693816938269383693846938569386693876938869389693906939169392693936939469395693966939769398693996940069401694026940369404694056940669407694086940969410694116941269413694146941569416694176941869419694206942169422694236942469425694266942769428694296943069431694326943369434694356943669437694386943969440694416944269443694446944569446694476944869449694506945169452694536945469455694566945769458694596946069461694626946369464694656946669467694686946969470694716947269473694746947569476694776947869479694806948169482694836948469485694866948769488694896949069491694926949369494694956949669497694986949969500695016950269503695046950569506695076950869509695106951169512695136951469515695166951769518695196952069521695226952369524695256952669527695286952969530695316953269533695346953569536695376953869539695406954169542695436954469545695466954769548695496955069551695526955369554695556955669557695586955969560695616956269563695646956569566695676956869569695706957169572695736957469575695766957769578695796958069581695826958369584695856958669587695886958969590695916959269593695946959569596695976959869599696006960169602696036960469605696066960769608696096961069611696126961369614696156961669617696186961969620696216962269623696246962569626696276962869629696306963169632696336963469635696366963769638696396964069641696426964369644696456964669647696486964969650696516965269653696546965569656696576965869659696606966169662696636966469665696666966769668696696967069671696726967369674696756967669677696786967969680696816968269683696846968569686696876968869689696906969169692696936969469695696966969769698696996970069701697026970369704697056970669707697086970969710697116971269713697146971569716697176971869719697206972169722697236972469725697266972769728697296973069731697326973369734697356973669737697386973969740697416974269743697446974569746697476974869749697506975169752697536975469755697566975769758697596976069761697626976369764697656976669767697686976969770697716977269773697746977569776697776977869779697806978169782697836978469785697866978769788697896979069791697926979369794697956979669797697986979969800698016980269803698046980569806698076980869809698106981169812698136981469815698166981769818698196982069821698226982369824698256982669827698286982969830698316983269833698346983569836698376983869839698406984169842698436984469845698466984769848698496985069851698526985369854698556985669857698586985969860698616986269863698646986569866698676986869869698706987169872698736987469875698766987769878698796988069881698826988369884698856988669887698886988969890698916989269893698946989569896698976989869899699006990169902699036990469905699066990769908699096991069911699126991369914699156991669917699186991969920699216992269923699246992569926699276992869929699306993169932699336993469935699366993769938699396994069941699426994369944699456994669947699486994969950699516995269953699546995569956699576995869959699606996169962699636996469965699666996769968699696997069971699726997369974699756997669977699786997969980699816998269983699846998569986699876998869989699906999169992699936999469995699966999769998699997000070001700027000370004700057000670007700087000970010700117001270013700147001570016700177001870019700207002170022700237002470025700267002770028700297003070031700327003370034700357003670037700387003970040700417004270043700447004570046700477004870049700507005170052700537005470055700567005770058700597006070061700627006370064700657006670067700687006970070700717007270073700747007570076700777007870079700807008170082700837008470085700867008770088700897009070091700927009370094700957009670097700987009970100701017010270103701047010570106701077010870109701107011170112701137011470115701167011770118701197012070121701227012370124701257012670127701287012970130701317013270133701347013570136701377013870139701407014170142701437014470145701467014770148701497015070151701527015370154701557015670157701587015970160701617016270163701647016570166701677016870169701707017170172701737017470175701767017770178701797018070181701827018370184701857018670187701887018970190701917019270193701947019570196701977019870199702007020170202702037020470205702067020770208702097021070211702127021370214702157021670217702187021970220702217022270223702247022570226702277022870229702307023170232702337023470235702367023770238702397024070241702427024370244702457024670247702487024970250702517025270253702547025570256702577025870259702607026170262702637026470265702667026770268702697027070271702727027370274702757027670277702787027970280702817028270283702847028570286702877028870289702907029170292702937029470295702967029770298702997030070301703027030370304703057030670307703087030970310703117031270313703147031570316703177031870319703207032170322703237032470325703267032770328703297033070331703327033370334703357033670337703387033970340703417034270343703447034570346703477034870349703507035170352703537035470355703567035770358703597036070361703627036370364703657036670367703687036970370703717037270373703747037570376703777037870379703807038170382703837038470385703867038770388703897039070391703927039370394703957039670397703987039970400704017040270403704047040570406704077040870409704107041170412704137041470415704167041770418704197042070421704227042370424704257042670427704287042970430704317043270433704347043570436704377043870439704407044170442704437044470445704467044770448704497045070451704527045370454704557045670457704587045970460704617046270463704647046570466704677046870469704707047170472704737047470475704767047770478704797048070481704827048370484704857048670487704887048970490704917049270493704947049570496704977049870499705007050170502705037050470505705067050770508705097051070511705127051370514705157051670517705187051970520705217052270523705247052570526705277052870529705307053170532705337053470535705367053770538705397054070541705427054370544705457054670547705487054970550705517055270553705547055570556705577055870559705607056170562705637056470565705667056770568705697057070571705727057370574705757057670577705787057970580705817058270583705847058570586705877058870589705907059170592705937059470595705967059770598705997060070601706027060370604706057060670607706087060970610706117061270613706147061570616706177061870619706207062170622706237062470625706267062770628706297063070631706327063370634706357063670637706387063970640706417064270643706447064570646706477064870649706507065170652706537065470655706567065770658706597066070661706627066370664706657066670667706687066970670706717067270673706747067570676706777067870679706807068170682706837068470685706867068770688706897069070691706927069370694706957069670697706987069970700707017070270703707047070570706707077070870709707107071170712707137071470715707167071770718707197072070721707227072370724707257072670727707287072970730707317073270733707347073570736707377073870739707407074170742707437074470745707467074770748707497075070751707527075370754707557075670757707587075970760707617076270763707647076570766707677076870769707707077170772707737077470775707767077770778707797078070781707827078370784707857078670787707887078970790707917079270793707947079570796707977079870799708007080170802708037080470805708067080770808708097081070811708127081370814708157081670817708187081970820708217082270823708247082570826708277082870829708307083170832708337083470835708367083770838708397084070841708427084370844708457084670847708487084970850708517085270853708547085570856708577085870859708607086170862708637086470865708667086770868708697087070871708727087370874708757087670877708787087970880708817088270883708847088570886708877088870889708907089170892708937089470895708967089770898708997090070901709027090370904709057090670907709087090970910709117091270913709147091570916709177091870919709207092170922709237092470925709267092770928709297093070931709327093370934709357093670937709387093970940709417094270943709447094570946709477094870949709507095170952709537095470955709567095770958709597096070961709627096370964709657096670967709687096970970709717097270973709747097570976709777097870979709807098170982709837098470985709867098770988709897099070991709927099370994709957099670997709987099971000710017100271003710047100571006710077100871009710107101171012710137101471015710167101771018710197102071021710227102371024710257102671027710287102971030710317103271033710347103571036710377103871039710407104171042710437104471045710467104771048710497105071051710527105371054710557105671057710587105971060710617106271063710647106571066710677106871069710707107171072710737107471075710767107771078710797108071081710827108371084710857108671087710887108971090710917109271093710947109571096710977109871099711007110171102711037110471105711067110771108711097111071111711127111371114711157111671117711187111971120711217112271123711247112571126711277112871129711307113171132711337113471135711367113771138711397114071141711427114371144711457114671147711487114971150711517115271153711547115571156711577115871159711607116171162711637116471165711667116771168711697117071171711727117371174711757117671177711787117971180711817118271183711847118571186711877118871189711907119171192711937119471195711967119771198711997120071201712027120371204712057120671207712087120971210712117121271213712147121571216712177121871219712207122171222712237122471225712267122771228712297123071231712327123371234712357123671237712387123971240712417124271243712447124571246712477124871249712507125171252712537125471255712567125771258712597126071261712627126371264712657126671267712687126971270712717127271273712747127571276712777127871279712807128171282712837128471285712867128771288712897129071291712927129371294712957129671297712987129971300713017130271303713047130571306713077130871309713107131171312713137131471315713167131771318713197132071321713227132371324713257132671327713287132971330713317133271333713347133571336713377133871339713407134171342713437134471345713467134771348713497135071351713527135371354713557135671357713587135971360713617136271363713647136571366713677136871369713707137171372713737137471375713767137771378713797138071381713827138371384713857138671387713887138971390713917139271393713947139571396713977139871399714007140171402714037140471405714067140771408714097141071411714127141371414714157141671417714187141971420714217142271423714247142571426714277142871429714307143171432714337143471435714367143771438714397144071441714427144371444714457144671447714487144971450714517145271453714547145571456714577145871459714607146171462714637146471465714667146771468714697147071471714727147371474714757147671477714787147971480714817148271483714847148571486714877148871489714907149171492714937149471495714967149771498714997150071501715027150371504715057150671507715087150971510715117151271513715147151571516715177151871519715207152171522715237152471525715267152771528715297153071531715327153371534715357153671537715387153971540715417154271543715447154571546715477154871549715507155171552715537155471555715567155771558715597156071561715627156371564715657156671567715687156971570715717157271573715747157571576715777157871579715807158171582715837158471585715867158771588715897159071591715927159371594715957159671597715987159971600716017160271603716047160571606716077160871609716107161171612716137161471615716167161771618716197162071621716227162371624716257162671627716287162971630716317163271633716347163571636716377163871639716407164171642716437164471645716467164771648716497165071651716527165371654716557165671657716587165971660716617166271663716647166571666716677166871669716707167171672716737167471675716767167771678716797168071681716827168371684716857168671687716887168971690716917169271693716947169571696716977169871699717007170171702717037170471705717067170771708717097171071711717127171371714717157171671717717187171971720717217172271723717247172571726717277172871729717307173171732717337173471735717367173771738717397174071741717427174371744717457174671747717487174971750717517175271753717547175571756717577175871759717607176171762717637176471765717667176771768717697177071771717727177371774717757177671777717787177971780717817178271783717847178571786717877178871789717907179171792717937179471795717967179771798717997180071801718027180371804718057180671807718087180971810718117181271813718147181571816718177181871819718207182171822718237182471825718267182771828718297183071831718327183371834718357183671837718387183971840718417184271843718447184571846718477184871849718507185171852718537185471855718567185771858718597186071861718627186371864718657186671867718687186971870718717187271873718747187571876718777187871879718807188171882718837188471885718867188771888718897189071891718927189371894718957189671897718987189971900719017190271903719047190571906719077190871909719107191171912719137191471915719167191771918719197192071921719227192371924719257192671927719287192971930719317193271933719347193571936719377193871939719407194171942719437194471945719467194771948719497195071951719527195371954719557195671957719587195971960719617196271963719647196571966719677196871969719707197171972719737197471975719767197771978719797198071981719827198371984719857198671987719887198971990719917199271993719947199571996719977199871999720007200172002720037200472005720067200772008720097201072011720127201372014720157201672017720187201972020720217202272023720247202572026720277202872029720307203172032720337203472035720367203772038720397204072041720427204372044720457204672047720487204972050720517205272053720547205572056720577205872059720607206172062720637206472065720667206772068720697207072071720727207372074720757207672077720787207972080720817208272083720847208572086720877208872089720907209172092720937209472095720967209772098720997210072101721027210372104721057210672107721087210972110721117211272113721147211572116721177211872119721207212172122721237212472125721267212772128721297213072131721327213372134721357213672137721387213972140721417214272143721447214572146721477214872149721507215172152721537215472155721567215772158721597216072161721627216372164721657216672167721687216972170721717217272173721747217572176721777217872179721807218172182721837218472185721867218772188721897219072191721927219372194721957219672197721987219972200722017220272203722047220572206722077220872209722107221172212722137221472215722167221772218722197222072221722227222372224722257222672227722287222972230722317223272233722347223572236722377223872239722407224172242722437224472245722467224772248722497225072251722527225372254722557225672257722587225972260722617226272263722647226572266722677226872269722707227172272722737227472275722767227772278722797228072281722827228372284722857228672287722887228972290722917229272293722947229572296722977229872299723007230172302723037230472305723067230772308723097231072311723127231372314723157231672317723187231972320723217232272323723247232572326723277232872329723307233172332723337233472335723367233772338723397234072341723427234372344723457234672347723487234972350723517235272353723547235572356723577235872359723607236172362723637236472365723667236772368723697237072371723727237372374723757237672377723787237972380723817238272383723847238572386723877238872389723907239172392723937239472395723967239772398723997240072401724027240372404724057240672407724087240972410724117241272413724147241572416724177241872419724207242172422724237242472425724267242772428724297243072431724327243372434724357243672437724387243972440724417244272443724447244572446724477244872449724507245172452724537245472455724567245772458724597246072461724627246372464724657246672467724687246972470724717247272473724747247572476724777247872479724807248172482724837248472485724867248772488724897249072491724927249372494724957249672497724987249972500725017250272503725047250572506725077250872509725107251172512725137251472515725167251772518725197252072521725227252372524725257252672527725287252972530725317253272533725347253572536725377253872539725407254172542725437254472545725467254772548725497255072551725527255372554725557255672557725587255972560725617256272563725647256572566725677256872569725707257172572725737257472575725767257772578725797258072581725827258372584725857258672587725887258972590725917259272593725947259572596725977259872599726007260172602726037260472605726067260772608726097261072611726127261372614726157261672617726187261972620726217262272623726247262572626726277262872629726307263172632726337263472635726367263772638726397264072641726427264372644726457264672647726487264972650726517265272653726547265572656726577265872659726607266172662726637266472665726667266772668726697267072671726727267372674726757267672677726787267972680726817268272683726847268572686726877268872689726907269172692726937269472695726967269772698726997270072701727027270372704727057270672707727087270972710727117271272713727147271572716727177271872719727207272172722727237272472725727267272772728727297273072731727327273372734727357273672737727387273972740727417274272743727447274572746727477274872749727507275172752727537275472755727567275772758727597276072761727627276372764727657276672767727687276972770727717277272773727747277572776727777277872779727807278172782727837278472785727867278772788727897279072791727927279372794727957279672797727987279972800728017280272803728047280572806728077280872809728107281172812728137281472815728167281772818728197282072821728227282372824728257282672827728287282972830728317283272833728347283572836728377283872839728407284172842728437284472845728467284772848728497285072851728527285372854728557285672857728587285972860728617286272863728647286572866728677286872869728707287172872728737287472875728767287772878728797288072881728827288372884728857288672887728887288972890728917289272893728947289572896728977289872899729007290172902729037290472905729067290772908729097291072911729127291372914729157291672917729187291972920729217292272923729247292572926729277292872929729307293172932729337293472935729367293772938729397294072941729427294372944729457294672947729487294972950729517295272953729547295572956729577295872959729607296172962729637296472965729667296772968729697297072971729727297372974729757297672977729787297972980729817298272983729847298572986729877298872989729907299172992729937299472995729967299772998729997300073001730027300373004730057300673007730087300973010730117301273013730147301573016730177301873019730207302173022730237302473025730267302773028730297303073031730327303373034730357303673037730387303973040730417304273043730447304573046730477304873049730507305173052730537305473055730567305773058730597306073061730627306373064730657306673067730687306973070730717307273073730747307573076730777307873079730807308173082730837308473085730867308773088730897309073091730927309373094730957309673097730987309973100731017310273103731047310573106731077310873109731107311173112731137311473115731167311773118731197312073121731227312373124731257312673127731287312973130731317313273133731347313573136731377313873139731407314173142731437314473145731467314773148731497315073151731527315373154731557315673157731587315973160731617316273163731647316573166731677316873169731707317173172731737317473175731767317773178731797318073181731827318373184731857318673187731887318973190731917319273193731947319573196731977319873199732007320173202732037320473205732067320773208732097321073211732127321373214732157321673217732187321973220732217322273223732247322573226732277322873229732307323173232732337323473235732367323773238732397324073241732427324373244732457324673247732487324973250732517325273253732547325573256732577325873259732607326173262732637326473265732667326773268732697327073271732727327373274732757327673277732787327973280732817328273283732847328573286732877328873289732907329173292732937329473295732967329773298732997330073301733027330373304733057330673307733087330973310733117331273313733147331573316733177331873319733207332173322733237332473325733267332773328733297333073331733327333373334733357333673337733387333973340733417334273343733447334573346733477334873349733507335173352733537335473355733567335773358733597336073361733627336373364733657336673367733687336973370733717337273373733747337573376733777337873379733807338173382733837338473385733867338773388733897339073391733927339373394733957339673397733987339973400734017340273403734047340573406734077340873409734107341173412734137341473415734167341773418734197342073421734227342373424734257342673427734287342973430734317343273433734347343573436734377343873439734407344173442734437344473445734467344773448734497345073451734527345373454734557345673457734587345973460734617346273463734647346573466734677346873469734707347173472734737347473475734767347773478734797348073481734827348373484734857348673487734887348973490734917349273493734947349573496734977349873499735007350173502735037350473505735067350773508735097351073511735127351373514735157351673517735187351973520735217352273523735247352573526735277352873529735307353173532735337353473535735367353773538735397354073541735427354373544735457354673547735487354973550735517355273553735547355573556735577355873559735607356173562735637356473565735667356773568735697357073571735727357373574735757357673577735787357973580735817358273583735847358573586735877358873589735907359173592735937359473595735967359773598735997360073601736027360373604736057360673607736087360973610736117361273613736147361573616736177361873619736207362173622736237362473625736267362773628736297363073631736327363373634736357363673637736387363973640736417364273643736447364573646736477364873649736507365173652736537365473655736567365773658736597366073661736627366373664736657366673667736687366973670736717367273673736747367573676736777367873679736807368173682736837368473685736867368773688736897369073691736927369373694736957369673697736987369973700737017370273703737047370573706737077370873709737107371173712737137371473715737167371773718737197372073721737227372373724737257372673727737287372973730737317373273733737347373573736737377373873739737407374173742737437374473745737467374773748737497375073751737527375373754737557375673757737587375973760737617376273763737647376573766737677376873769737707377173772737737377473775737767377773778737797378073781737827378373784737857378673787737887378973790737917379273793737947379573796737977379873799738007380173802738037380473805738067380773808738097381073811738127381373814738157381673817738187381973820738217382273823738247382573826738277382873829738307383173832738337383473835738367383773838738397384073841738427384373844738457384673847738487384973850738517385273853738547385573856738577385873859738607386173862738637386473865738667386773868738697387073871738727387373874738757387673877738787387973880738817388273883738847388573886738877388873889738907389173892738937389473895738967389773898738997390073901739027390373904739057390673907739087390973910739117391273913739147391573916739177391873919739207392173922739237392473925739267392773928739297393073931739327393373934739357393673937739387393973940739417394273943739447394573946739477394873949739507395173952739537395473955739567395773958739597396073961739627396373964739657396673967739687396973970739717397273973739747397573976739777397873979739807398173982739837398473985739867398773988739897399073991739927399373994739957399673997739987399974000740017400274003740047400574006740077400874009740107401174012740137401474015740167401774018740197402074021740227402374024740257402674027740287402974030740317403274033740347403574036740377403874039740407404174042740437404474045740467404774048740497405074051740527405374054740557405674057740587405974060740617406274063740647406574066740677406874069740707407174072740737407474075740767407774078740797408074081740827408374084740857408674087740887408974090740917409274093740947409574096740977409874099741007410174102741037410474105741067410774108741097411074111741127411374114741157411674117741187411974120741217412274123741247412574126741277412874129741307413174132741337413474135741367413774138741397414074141741427414374144741457414674147741487414974150741517415274153741547415574156741577415874159741607416174162741637416474165741667416774168741697417074171741727417374174741757417674177741787417974180741817418274183741847418574186741877418874189741907419174192741937419474195741967419774198741997420074201742027420374204742057420674207742087420974210742117421274213742147421574216742177421874219742207422174222742237422474225742267422774228742297423074231742327423374234742357423674237742387423974240742417424274243742447424574246742477424874249742507425174252742537425474255742567425774258742597426074261742627426374264742657426674267742687426974270742717427274273742747427574276742777427874279742807428174282742837428474285742867428774288742897429074291742927429374294742957429674297742987429974300743017430274303743047430574306743077430874309743107431174312743137431474315743167431774318743197432074321743227432374324743257432674327743287432974330743317433274333743347433574336743377433874339743407434174342743437434474345743467434774348743497435074351743527435374354743557435674357743587435974360743617436274363743647436574366743677436874369743707437174372743737437474375743767437774378743797438074381743827438374384743857438674387743887438974390743917439274393743947439574396743977439874399744007440174402744037440474405744067440774408744097441074411744127441374414744157441674417744187441974420744217442274423744247442574426744277442874429744307443174432744337443474435744367443774438744397444074441744427444374444744457444674447744487444974450744517445274453744547445574456744577445874459744607446174462744637446474465744667446774468744697447074471744727447374474744757447674477744787447974480744817448274483744847448574486744877448874489744907449174492744937449474495744967449774498744997450074501745027450374504745057450674507745087450974510745117451274513745147451574516745177451874519745207452174522745237452474525745267452774528745297453074531745327453374534745357453674537745387453974540745417454274543745447454574546745477454874549745507455174552745537455474555745567455774558745597456074561745627456374564745657456674567745687456974570745717457274573745747457574576745777457874579745807458174582745837458474585745867458774588745897459074591745927459374594745957459674597745987459974600746017460274603746047460574606746077460874609746107461174612746137461474615746167461774618746197462074621746227462374624746257462674627746287462974630746317463274633746347463574636746377463874639746407464174642746437464474645746467464774648746497465074651746527465374654746557465674657746587465974660746617466274663746647466574666746677466874669746707467174672746737467474675746767467774678746797468074681746827468374684746857468674687746887468974690746917469274693746947469574696746977469874699747007470174702747037470474705747067470774708747097471074711747127471374714747157471674717747187471974720747217472274723747247472574726747277472874729747307473174732747337473474735747367473774738747397474074741747427474374744747457474674747747487474974750747517475274753747547475574756747577475874759747607476174762747637476474765747667476774768747697477074771747727477374774747757477674777747787477974780747817478274783747847478574786747877478874789747907479174792747937479474795747967479774798747997480074801748027480374804748057480674807748087480974810748117481274813748147481574816748177481874819748207482174822748237482474825748267482774828748297483074831748327483374834748357483674837748387483974840748417484274843748447484574846748477484874849748507485174852748537485474855748567485774858748597486074861748627486374864748657486674867748687486974870748717487274873748747487574876748777487874879748807488174882748837488474885748867488774888748897489074891748927489374894748957489674897748987489974900749017490274903749047490574906749077490874909749107491174912749137491474915749167491774918749197492074921749227492374924749257492674927749287492974930749317493274933749347493574936749377493874939749407494174942749437494474945749467494774948749497495074951749527495374954749557495674957749587495974960749617496274963749647496574966749677496874969749707497174972749737497474975749767497774978749797498074981749827498374984749857498674987749887498974990749917499274993749947499574996749977499874999750007500175002750037500475005750067500775008750097501075011750127501375014750157501675017750187501975020750217502275023750247502575026750277502875029750307503175032750337503475035750367503775038750397504075041750427504375044750457504675047750487504975050750517505275053750547505575056750577505875059750607506175062750637506475065750667506775068750697507075071750727507375074750757507675077750787507975080750817508275083750847508575086750877508875089750907509175092750937509475095750967509775098750997510075101751027510375104751057510675107751087510975110751117511275113751147511575116751177511875119751207512175122751237512475125751267512775128751297513075131751327513375134751357513675137751387513975140751417514275143751447514575146751477514875149751507515175152751537515475155751567515775158751597516075161751627516375164751657516675167751687516975170751717517275173751747517575176751777517875179751807518175182751837518475185751867518775188751897519075191751927519375194751957519675197751987519975200752017520275203752047520575206752077520875209752107521175212752137521475215752167521775218752197522075221752227522375224752257522675227752287522975230752317523275233752347523575236752377523875239752407524175242752437524475245752467524775248752497525075251752527525375254752557525675257752587525975260752617526275263752647526575266752677526875269752707527175272752737527475275752767527775278752797528075281752827528375284752857528675287752887528975290752917529275293752947529575296752977529875299753007530175302753037530475305753067530775308753097531075311753127531375314753157531675317753187531975320753217532275323753247532575326753277532875329753307533175332753337533475335753367533775338753397534075341753427534375344753457534675347753487534975350753517535275353753547535575356753577535875359753607536175362753637536475365753667536775368753697537075371753727537375374753757537675377753787537975380753817538275383753847538575386753877538875389753907539175392753937539475395753967539775398753997540075401754027540375404754057540675407754087540975410754117541275413754147541575416754177541875419754207542175422754237542475425754267542775428754297543075431754327543375434754357543675437754387543975440754417544275443754447544575446754477544875449754507545175452754537545475455754567545775458754597546075461754627546375464754657546675467754687546975470754717547275473754747547575476754777547875479754807548175482754837548475485754867548775488754897549075491754927549375494754957549675497754987549975500755017550275503755047550575506755077550875509755107551175512755137551475515755167551775518755197552075521755227552375524755257552675527755287552975530755317553275533755347553575536755377553875539755407554175542755437554475545755467554775548755497555075551755527555375554755557555675557755587555975560755617556275563755647556575566755677556875569755707557175572755737557475575755767557775578755797558075581755827558375584755857558675587755887558975590755917559275593755947559575596755977559875599756007560175602756037560475605756067560775608756097561075611756127561375614756157561675617756187561975620756217562275623756247562575626756277562875629756307563175632756337563475635756367563775638756397564075641756427564375644756457564675647756487564975650756517565275653756547565575656756577565875659756607566175662756637566475665756667566775668756697567075671756727567375674756757567675677756787567975680756817568275683756847568575686756877568875689756907569175692756937569475695756967569775698756997570075701757027570375704757057570675707757087570975710757117571275713757147571575716757177571875719757207572175722757237572475725757267572775728757297573075731757327573375734757357573675737757387573975740757417574275743757447574575746757477574875749757507575175752757537575475755757567575775758757597576075761757627576375764757657576675767757687576975770757717577275773757747577575776757777577875779757807578175782757837578475785757867578775788757897579075791757927579375794757957579675797757987579975800758017580275803758047580575806758077580875809758107581175812758137581475815758167581775818758197582075821758227582375824758257582675827758287582975830758317583275833758347583575836758377583875839758407584175842758437584475845758467584775848758497585075851758527585375854758557585675857758587585975860758617586275863758647586575866758677586875869758707587175872758737587475875758767587775878758797588075881758827588375884758857588675887758887588975890758917589275893758947589575896758977589875899759007590175902759037590475905759067590775908759097591075911759127591375914759157591675917759187591975920759217592275923759247592575926759277592875929759307593175932759337593475935759367593775938759397594075941759427594375944759457594675947759487594975950759517595275953759547595575956759577595875959759607596175962759637596475965759667596775968759697597075971759727597375974759757597675977759787597975980759817598275983759847598575986759877598875989759907599175992759937599475995759967599775998759997600076001760027600376004760057600676007760087600976010760117601276013760147601576016760177601876019760207602176022760237602476025760267602776028760297603076031760327603376034760357603676037760387603976040760417604276043760447604576046760477604876049760507605176052760537605476055760567605776058760597606076061760627606376064760657606676067760687606976070760717607276073760747607576076760777607876079760807608176082760837608476085760867608776088760897609076091760927609376094760957609676097760987609976100761017610276103761047610576106761077610876109761107611176112761137611476115761167611776118761197612076121761227612376124761257612676127761287612976130761317613276133761347613576136761377613876139761407614176142761437614476145761467614776148761497615076151761527615376154761557615676157761587615976160761617616276163761647616576166761677616876169761707617176172761737617476175761767617776178761797618076181761827618376184761857618676187761887618976190761917619276193761947619576196761977619876199762007620176202762037620476205762067620776208762097621076211762127621376214762157621676217762187621976220762217622276223762247622576226762277622876229762307623176232762337623476235762367623776238762397624076241762427624376244762457624676247762487624976250762517625276253762547625576256762577625876259762607626176262762637626476265762667626776268762697627076271762727627376274762757627676277762787627976280762817628276283762847628576286762877628876289762907629176292762937629476295762967629776298762997630076301763027630376304763057630676307763087630976310763117631276313763147631576316763177631876319763207632176322763237632476325763267632776328763297633076331763327633376334763357633676337763387633976340763417634276343763447634576346763477634876349763507635176352763537635476355763567635776358763597636076361763627636376364763657636676367763687636976370763717637276373763747637576376763777637876379763807638176382763837638476385763867638776388763897639076391763927639376394763957639676397763987639976400764017640276403764047640576406764077640876409764107641176412764137641476415764167641776418764197642076421764227642376424764257642676427764287642976430764317643276433764347643576436764377643876439764407644176442764437644476445764467644776448764497645076451764527645376454764557645676457764587645976460764617646276463764647646576466764677646876469764707647176472764737647476475764767647776478764797648076481764827648376484764857648676487764887648976490764917649276493764947649576496764977649876499765007650176502765037650476505765067650776508765097651076511765127651376514765157651676517765187651976520765217652276523765247652576526765277652876529765307653176532765337653476535765367653776538765397654076541765427654376544765457654676547765487654976550765517655276553765547655576556765577655876559765607656176562765637656476565765667656776568765697657076571765727657376574765757657676577765787657976580765817658276583765847658576586765877658876589765907659176592765937659476595765967659776598765997660076601766027660376604766057660676607766087660976610766117661276613766147661576616766177661876619766207662176622766237662476625766267662776628766297663076631766327663376634766357663676637766387663976640766417664276643766447664576646766477664876649766507665176652766537665476655766567665776658766597666076661766627666376664766657666676667766687666976670766717667276673766747667576676766777667876679766807668176682766837668476685766867668776688766897669076691766927669376694766957669676697766987669976700767017670276703767047670576706767077670876709767107671176712767137671476715767167671776718767197672076721767227672376724767257672676727767287672976730767317673276733767347673576736767377673876739767407674176742767437674476745767467674776748767497675076751767527675376754767557675676757767587675976760767617676276763767647676576766767677676876769767707677176772767737677476775767767677776778767797678076781767827678376784767857678676787767887678976790767917679276793767947679576796767977679876799768007680176802768037680476805768067680776808768097681076811768127681376814768157681676817768187681976820768217682276823768247682576826768277682876829768307683176832768337683476835768367683776838768397684076841768427684376844768457684676847768487684976850768517685276853768547685576856768577685876859768607686176862768637686476865768667686776868768697687076871768727687376874768757687676877768787687976880768817688276883768847688576886768877688876889768907689176892768937689476895768967689776898768997690076901769027690376904769057690676907769087690976910769117691276913769147691576916769177691876919769207692176922769237692476925769267692776928769297693076931769327693376934769357693676937769387693976940769417694276943769447694576946769477694876949769507695176952769537695476955769567695776958769597696076961769627696376964769657696676967769687696976970769717697276973769747697576976769777697876979769807698176982769837698476985769867698776988769897699076991769927699376994769957699676997769987699977000770017700277003770047700577006770077700877009770107701177012770137701477015770167701777018770197702077021770227702377024770257702677027770287702977030770317703277033770347703577036770377703877039770407704177042770437704477045770467704777048770497705077051770527705377054770557705677057770587705977060770617706277063770647706577066770677706877069770707707177072770737707477075770767707777078770797708077081770827708377084770857708677087770887708977090770917709277093770947709577096770977709877099771007710177102771037710477105771067710777108771097711077111771127711377114771157711677117771187711977120771217712277123771247712577126771277712877129771307713177132771337713477135771367713777138771397714077141771427714377144771457714677147771487714977150771517715277153771547715577156771577715877159771607716177162771637716477165771667716777168771697717077171771727717377174771757717677177771787717977180771817718277183771847718577186771877718877189771907719177192771937719477195771967719777198771997720077201772027720377204772057720677207772087720977210772117721277213772147721577216772177721877219772207722177222772237722477225772267722777228772297723077231772327723377234772357723677237772387723977240772417724277243772447724577246772477724877249772507725177252772537725477255772567725777258772597726077261772627726377264772657726677267772687726977270772717727277273772747727577276772777727877279772807728177282772837728477285772867728777288772897729077291772927729377294772957729677297772987729977300773017730277303773047730577306773077730877309773107731177312773137731477315773167731777318773197732077321773227732377324773257732677327773287732977330773317733277333773347733577336773377733877339773407734177342773437734477345773467734777348773497735077351773527735377354773557735677357773587735977360773617736277363773647736577366773677736877369773707737177372773737737477375773767737777378773797738077381773827738377384773857738677387773887738977390773917739277393773947739577396773977739877399774007740177402774037740477405774067740777408774097741077411774127741377414774157741677417774187741977420774217742277423774247742577426774277742877429774307743177432774337743477435774367743777438774397744077441774427744377444774457744677447774487744977450774517745277453774547745577456774577745877459774607746177462774637746477465774667746777468774697747077471774727747377474774757747677477774787747977480774817748277483774847748577486774877748877489774907749177492774937749477495774967749777498774997750077501775027750377504775057750677507775087750977510775117751277513775147751577516775177751877519775207752177522775237752477525775267752777528775297753077531775327753377534775357753677537775387753977540775417754277543775447754577546775477754877549775507755177552775537755477555775567755777558775597756077561775627756377564775657756677567775687756977570775717757277573775747757577576775777757877579775807758177582775837758477585775867758777588775897759077591775927759377594775957759677597775987759977600776017760277603776047760577606776077760877609776107761177612776137761477615776167761777618776197762077621776227762377624776257762677627776287762977630776317763277633776347763577636776377763877639776407764177642776437764477645776467764777648776497765077651776527765377654776557765677657776587765977660776617766277663776647766577666776677766877669776707767177672776737767477675776767767777678776797768077681776827768377684776857768677687776887768977690776917769277693776947769577696776977769877699777007770177702777037770477705777067770777708777097771077711777127771377714777157771677717777187771977720777217772277723777247772577726777277772877729777307773177732777337773477735777367773777738777397774077741777427774377744777457774677747777487774977750777517775277753777547775577756777577775877759777607776177762777637776477765777667776777768777697777077771777727777377774777757777677777777787777977780777817778277783777847778577786777877778877789777907779177792777937779477795777967779777798777997780077801778027780377804778057780677807778087780977810778117781277813778147781577816778177781877819778207782177822778237782477825778267782777828778297783077831778327783377834778357783677837778387783977840778417784277843778447784577846778477784877849778507785177852778537785477855778567785777858778597786077861778627786377864778657786677867778687786977870778717787277873778747787577876778777787877879778807788177882778837788477885778867788777888778897789077891778927789377894778957789677897778987789977900779017790277903779047790577906779077790877909779107791177912779137791477915779167791777918779197792077921779227792377924779257792677927779287792977930779317793277933779347793577936779377793877939779407794177942779437794477945779467794777948779497795077951779527795377954779557795677957779587795977960779617796277963779647796577966779677796877969779707797177972779737797477975779767797777978779797798077981779827798377984779857798677987779887798977990779917799277993779947799577996779977799877999780007800178002780037800478005780067800778008780097801078011780127801378014780157801678017780187801978020780217802278023780247802578026780277802878029780307803178032780337803478035780367803778038780397804078041780427804378044780457804678047780487804978050780517805278053780547805578056780577805878059780607806178062780637806478065780667806778068780697807078071780727807378074780757807678077780787807978080780817808278083780847808578086780877808878089780907809178092780937809478095780967809778098780997810078101781027810378104781057810678107781087810978110781117811278113781147811578116781177811878119781207812178122781237812478125781267812778128781297813078131781327813378134781357813678137781387813978140781417814278143781447814578146781477814878149781507815178152781537815478155781567815778158781597816078161781627816378164781657816678167781687816978170781717817278173781747817578176781777817878179781807818178182781837818478185781867818778188781897819078191781927819378194781957819678197781987819978200782017820278203782047820578206782077820878209782107821178212782137821478215782167821778218782197822078221782227822378224782257822678227782287822978230782317823278233782347823578236782377823878239782407824178242782437824478245782467824778248782497825078251782527825378254782557825678257782587825978260782617826278263782647826578266782677826878269782707827178272782737827478275782767827778278782797828078281782827828378284782857828678287782887828978290782917829278293782947829578296782977829878299783007830178302783037830478305783067830778308783097831078311783127831378314783157831678317783187831978320783217832278323783247832578326783277832878329783307833178332783337833478335783367833778338783397834078341783427834378344783457834678347783487834978350783517835278353783547835578356783577835878359783607836178362783637836478365783667836778368783697837078371783727837378374783757837678377783787837978380783817838278383783847838578386783877838878389783907839178392783937839478395783967839778398783997840078401784027840378404784057840678407784087840978410784117841278413784147841578416784177841878419784207842178422784237842478425784267842778428784297843078431784327843378434784357843678437784387843978440784417844278443784447844578446784477844878449784507845178452784537845478455784567845778458784597846078461784627846378464784657846678467784687846978470784717847278473784747847578476784777847878479784807848178482784837848478485784867848778488784897849078491784927849378494784957849678497784987849978500785017850278503785047850578506785077850878509785107851178512785137851478515785167851778518785197852078521785227852378524785257852678527785287852978530785317853278533785347853578536785377853878539785407854178542785437854478545785467854778548785497855078551785527855378554785557855678557785587855978560785617856278563785647856578566785677856878569785707857178572785737857478575785767857778578785797858078581785827858378584785857858678587785887858978590785917859278593785947859578596785977859878599786007860178602786037860478605786067860778608786097861078611786127861378614786157861678617786187861978620786217862278623786247862578626786277862878629786307863178632786337863478635786367863778638786397864078641786427864378644786457864678647786487864978650786517865278653786547865578656786577865878659786607866178662786637866478665786667866778668786697867078671786727867378674786757867678677786787867978680786817868278683786847868578686786877868878689786907869178692786937869478695786967869778698786997870078701787027870378704787057870678707787087870978710787117871278713787147871578716787177871878719787207872178722787237872478725787267872778728787297873078731787327873378734787357873678737787387873978740787417874278743787447874578746787477874878749787507875178752787537875478755787567875778758787597876078761787627876378764787657876678767787687876978770787717877278773787747877578776787777877878779787807878178782787837878478785787867878778788787897879078791787927879378794787957879678797787987879978800788017880278803788047880578806788077880878809788107881178812788137881478815788167881778818788197882078821788227882378824788257882678827788287882978830788317883278833788347883578836788377883878839788407884178842788437884478845788467884778848788497885078851788527885378854788557885678857788587885978860788617886278863788647886578866788677886878869788707887178872788737887478875788767887778878788797888078881788827888378884788857888678887788887888978890788917889278893788947889578896788977889878899789007890178902789037890478905789067890778908789097891078911789127891378914789157891678917789187891978920789217892278923789247892578926789277892878929789307893178932789337893478935789367893778938789397894078941789427894378944789457894678947789487894978950789517895278953789547895578956789577895878959789607896178962789637896478965789667896778968789697897078971789727897378974789757897678977789787897978980789817898278983789847898578986789877898878989789907899178992789937899478995789967899778998789997900079001790027900379004790057900679007790087900979010790117901279013790147901579016790177901879019790207902179022790237902479025790267902779028790297903079031790327903379034790357903679037790387903979040790417904279043790447904579046790477904879049790507905179052790537905479055790567905779058790597906079061790627906379064790657906679067790687906979070790717907279073790747907579076790777907879079790807908179082790837908479085790867908779088790897909079091790927909379094790957909679097790987909979100791017910279103791047910579106791077910879109791107911179112791137911479115791167911779118791197912079121791227912379124791257912679127791287912979130791317913279133791347913579136791377913879139791407914179142791437914479145791467914779148791497915079151791527915379154791557915679157791587915979160791617916279163791647916579166791677916879169791707917179172791737917479175791767917779178791797918079181791827918379184791857918679187791887918979190791917919279193791947919579196791977919879199792007920179202792037920479205792067920779208792097921079211792127921379214792157921679217792187921979220792217922279223792247922579226792277922879229792307923179232792337923479235792367923779238792397924079241792427924379244792457924679247792487924979250792517925279253792547925579256792577925879259792607926179262792637926479265792667926779268792697927079271792727927379274792757927679277792787927979280792817928279283792847928579286792877928879289792907929179292792937929479295792967929779298792997930079301793027930379304793057930679307793087930979310793117931279313793147931579316793177931879319793207932179322793237932479325793267932779328793297933079331793327933379334793357933679337793387933979340793417934279343793447934579346793477934879349793507935179352793537935479355793567935779358793597936079361793627936379364793657936679367793687936979370793717937279373793747937579376793777937879379793807938179382793837938479385793867938779388793897939079391793927939379394793957939679397793987939979400794017940279403794047940579406794077940879409794107941179412794137941479415794167941779418794197942079421794227942379424794257942679427794287942979430794317943279433794347943579436794377943879439794407944179442794437944479445794467944779448794497945079451794527945379454794557945679457794587945979460794617946279463794647946579466794677946879469794707947179472794737947479475794767947779478794797948079481794827948379484794857948679487794887948979490794917949279493794947949579496794977949879499795007950179502795037950479505795067950779508795097951079511795127951379514795157951679517795187951979520795217952279523795247952579526795277952879529795307953179532795337953479535795367953779538795397954079541795427954379544795457954679547795487954979550795517955279553795547955579556795577955879559795607956179562795637956479565795667956779568795697957079571795727957379574795757957679577795787957979580795817958279583795847958579586795877958879589795907959179592795937959479595795967959779598795997960079601796027960379604796057960679607796087960979610796117961279613796147961579616796177961879619796207962179622796237962479625796267962779628796297963079631796327963379634796357963679637796387963979640796417964279643796447964579646796477964879649796507965179652796537965479655796567965779658796597966079661796627966379664796657966679667796687966979670796717967279673796747967579676796777967879679796807968179682796837968479685796867968779688796897969079691796927969379694796957969679697796987969979700797017970279703797047970579706797077970879709797107971179712797137971479715797167971779718797197972079721797227972379724797257972679727797287972979730797317973279733797347973579736797377973879739797407974179742797437974479745797467974779748797497975079751797527975379754797557975679757797587975979760797617976279763797647976579766797677976879769797707977179772797737977479775797767977779778797797978079781797827978379784797857978679787797887978979790797917979279793797947979579796797977979879799798007980179802798037980479805798067980779808798097981079811798127981379814798157981679817798187981979820798217982279823798247982579826798277982879829798307983179832798337983479835798367983779838798397984079841798427984379844798457984679847798487984979850798517985279853798547985579856798577985879859798607986179862798637986479865798667986779868798697987079871798727987379874798757987679877798787987979880798817988279883798847988579886798877988879889798907989179892798937989479895798967989779898798997990079901799027990379904799057990679907799087990979910799117991279913799147991579916799177991879919799207992179922799237992479925799267992779928799297993079931799327993379934799357993679937799387993979940799417994279943799447994579946799477994879949799507995179952799537995479955799567995779958799597996079961799627996379964799657996679967799687996979970799717997279973799747997579976799777997879979799807998179982799837998479985799867998779988799897999079991799927999379994799957999679997799987999980000800018000280003800048000580006800078000880009800108001180012800138001480015800168001780018800198002080021800228002380024800258002680027800288002980030800318003280033800348003580036800378003880039800408004180042800438004480045800468004780048800498005080051800528005380054800558005680057800588005980060800618006280063800648006580066800678006880069800708007180072800738007480075800768007780078800798008080081800828008380084800858008680087800888008980090800918009280093800948009580096800978009880099801008010180102801038010480105801068010780108801098011080111801128011380114801158011680117801188011980120801218012280123801248012580126801278012880129801308013180132801338013480135801368013780138801398014080141801428014380144801458014680147801488014980150801518015280153801548015580156801578015880159801608016180162801638016480165801668016780168801698017080171801728017380174801758017680177801788017980180801818018280183801848018580186801878018880189801908019180192801938019480195801968019780198801998020080201802028020380204802058020680207802088020980210802118021280213802148021580216802178021880219802208022180222802238022480225802268022780228802298023080231802328023380234802358023680237802388023980240802418024280243802448024580246802478024880249802508025180252802538025480255802568025780258802598026080261802628026380264802658026680267802688026980270802718027280273802748027580276802778027880279802808028180282802838028480285802868028780288802898029080291802928029380294802958029680297802988029980300803018030280303803048030580306803078030880309803108031180312803138031480315803168031780318803198032080321803228032380324803258032680327803288032980330803318033280333803348033580336803378033880339803408034180342803438034480345803468034780348803498035080351803528035380354803558035680357803588035980360803618036280363803648036580366803678036880369803708037180372803738037480375803768037780378803798038080381803828038380384803858038680387803888038980390803918039280393803948039580396803978039880399804008040180402804038040480405804068040780408804098041080411804128041380414804158041680417804188041980420804218042280423804248042580426804278042880429804308043180432804338043480435804368043780438804398044080441804428044380444804458044680447804488044980450804518045280453804548045580456804578045880459804608046180462804638046480465804668046780468804698047080471804728047380474804758047680477804788047980480804818048280483804848048580486804878048880489804908049180492804938049480495804968049780498804998050080501805028050380504805058050680507805088050980510805118051280513805148051580516805178051880519805208052180522805238052480525805268052780528805298053080531805328053380534805358053680537805388053980540805418054280543805448054580546805478054880549805508055180552805538055480555805568055780558805598056080561805628056380564805658056680567805688056980570805718057280573805748057580576805778057880579805808058180582805838058480585805868058780588805898059080591805928059380594805958059680597805988059980600806018060280603806048060580606806078060880609806108061180612806138061480615806168061780618806198062080621806228062380624806258062680627806288062980630806318063280633806348063580636806378063880639806408064180642806438064480645806468064780648806498065080651806528065380654806558065680657806588065980660806618066280663806648066580666806678066880669806708067180672806738067480675806768067780678806798068080681806828068380684806858068680687806888068980690806918069280693806948069580696806978069880699807008070180702807038070480705807068070780708807098071080711807128071380714807158071680717807188071980720807218072280723807248072580726807278072880729807308073180732807338073480735807368073780738807398074080741807428074380744807458074680747807488074980750807518075280753807548075580756807578075880759807608076180762807638076480765807668076780768807698077080771807728077380774807758077680777807788077980780807818078280783807848078580786807878078880789807908079180792807938079480795807968079780798807998080080801808028080380804808058080680807808088080980810808118081280813808148081580816808178081880819808208082180822808238082480825808268082780828808298083080831808328083380834808358083680837808388083980840808418084280843808448084580846808478084880849808508085180852808538085480855808568085780858808598086080861808628086380864808658086680867808688086980870808718087280873808748087580876808778087880879808808088180882808838088480885808868088780888808898089080891808928089380894808958089680897808988089980900809018090280903809048090580906809078090880909809108091180912809138091480915809168091780918809198092080921809228092380924809258092680927809288092980930809318093280933809348093580936809378093880939809408094180942809438094480945809468094780948809498095080951809528095380954809558095680957809588095980960809618096280963809648096580966809678096880969809708097180972809738097480975809768097780978809798098080981809828098380984809858098680987809888098980990809918099280993809948099580996809978099880999810008100181002810038100481005810068100781008810098101081011810128101381014810158101681017810188101981020810218102281023810248102581026810278102881029810308103181032810338103481035810368103781038810398104081041810428104381044810458104681047810488104981050810518105281053810548105581056810578105881059810608106181062810638106481065810668106781068810698107081071810728107381074810758107681077810788107981080810818108281083810848108581086810878108881089810908109181092810938109481095810968109781098810998110081101811028110381104811058110681107811088110981110811118111281113811148111581116811178111881119811208112181122811238112481125811268112781128811298113081131811328113381134811358113681137811388113981140811418114281143811448114581146811478114881149811508115181152811538115481155811568115781158811598116081161811628116381164811658116681167811688116981170811718117281173811748117581176811778117881179811808118181182811838118481185811868118781188811898119081191811928119381194811958119681197811988119981200812018120281203812048120581206812078120881209812108121181212812138121481215812168121781218812198122081221812228122381224812258122681227812288122981230812318123281233812348123581236812378123881239812408124181242812438124481245812468124781248812498125081251812528125381254812558125681257812588125981260812618126281263812648126581266812678126881269812708127181272812738127481275812768127781278812798128081281812828128381284812858128681287812888128981290812918129281293812948129581296812978129881299813008130181302813038130481305813068130781308813098131081311813128131381314813158131681317813188131981320813218132281323813248132581326813278132881329813308133181332813338133481335813368133781338813398134081341813428134381344813458134681347813488134981350813518135281353813548135581356813578135881359813608136181362813638136481365813668136781368813698137081371813728137381374813758137681377813788137981380813818138281383813848138581386813878138881389813908139181392813938139481395813968139781398813998140081401814028140381404814058140681407814088140981410814118141281413814148141581416814178141881419814208142181422814238142481425814268142781428814298143081431814328143381434814358143681437814388143981440814418144281443814448144581446814478144881449814508145181452814538145481455814568145781458814598146081461814628146381464814658146681467814688146981470814718147281473814748147581476814778147881479814808148181482814838148481485814868148781488814898149081491814928149381494814958149681497814988149981500815018150281503815048150581506815078150881509815108151181512815138151481515815168151781518815198152081521815228152381524815258152681527815288152981530815318153281533815348153581536815378153881539815408154181542815438154481545815468154781548815498155081551815528155381554815558155681557815588155981560815618156281563815648156581566815678156881569815708157181572815738157481575815768157781578815798158081581815828158381584815858158681587815888158981590815918159281593815948159581596815978159881599816008160181602816038160481605816068160781608816098161081611816128161381614816158161681617816188161981620816218162281623816248162581626816278162881629816308163181632816338163481635816368163781638816398164081641816428164381644816458164681647816488164981650816518165281653816548165581656816578165881659816608166181662816638166481665816668166781668816698167081671816728167381674816758167681677816788167981680816818168281683816848168581686816878168881689816908169181692816938169481695816968169781698816998170081701817028170381704817058170681707817088170981710817118171281713817148171581716817178171881719817208172181722817238172481725817268172781728817298173081731817328173381734817358173681737817388173981740817418174281743817448174581746817478174881749817508175181752817538175481755817568175781758817598176081761817628176381764817658176681767817688176981770817718177281773817748177581776817778177881779817808178181782817838178481785817868178781788817898179081791817928179381794817958179681797817988179981800818018180281803818048180581806818078180881809818108181181812818138181481815818168181781818818198182081821818228182381824818258182681827818288182981830818318183281833818348183581836818378183881839818408184181842818438184481845818468184781848818498185081851818528185381854818558185681857818588185981860818618186281863818648186581866818678186881869818708187181872818738187481875818768187781878818798188081881818828188381884818858188681887818888188981890818918189281893818948189581896818978189881899819008190181902819038190481905819068190781908819098191081911819128191381914819158191681917819188191981920819218192281923819248192581926819278192881929819308193181932819338193481935819368193781938819398194081941819428194381944819458194681947819488194981950819518195281953819548195581956819578195881959819608196181962819638196481965819668196781968819698197081971819728197381974819758197681977819788197981980819818198281983819848198581986819878198881989819908199181992819938199481995819968199781998819998200082001820028200382004820058200682007820088200982010820118201282013820148201582016820178201882019820208202182022820238202482025820268202782028820298203082031820328203382034820358203682037820388203982040820418204282043820448204582046820478204882049820508205182052820538205482055820568205782058820598206082061820628206382064820658206682067820688206982070820718207282073820748207582076820778207882079820808208182082820838208482085820868208782088820898209082091820928209382094820958209682097820988209982100821018210282103821048210582106821078210882109821108211182112821138211482115821168211782118821198212082121821228212382124821258212682127821288212982130821318213282133821348213582136821378213882139821408214182142821438214482145821468214782148821498215082151821528215382154821558215682157821588215982160821618216282163821648216582166821678216882169821708217182172821738217482175821768217782178821798218082181821828218382184821858218682187821888218982190821918219282193821948219582196821978219882199822008220182202822038220482205822068220782208822098221082211822128221382214822158221682217822188221982220822218222282223822248222582226822278222882229822308223182232822338223482235822368223782238822398224082241822428224382244822458224682247822488224982250822518225282253822548225582256822578225882259822608226182262822638226482265822668226782268822698227082271822728227382274822758227682277822788227982280822818228282283822848228582286822878228882289822908229182292822938229482295822968229782298822998230082301823028230382304823058230682307823088230982310823118231282313823148231582316823178231882319823208232182322823238232482325823268232782328823298233082331823328233382334823358233682337823388233982340823418234282343823448234582346823478234882349823508235182352823538235482355823568235782358823598236082361823628236382364823658236682367823688236982370823718237282373823748237582376823778237882379823808238182382823838238482385823868238782388823898239082391823928239382394823958239682397823988239982400824018240282403824048240582406824078240882409824108241182412824138241482415824168241782418824198242082421824228242382424824258242682427824288242982430824318243282433824348243582436824378243882439824408244182442824438244482445824468244782448824498245082451824528245382454824558245682457824588245982460824618246282463824648246582466824678246882469824708247182472824738247482475824768247782478824798248082481824828248382484824858248682487824888248982490824918249282493824948249582496824978249882499825008250182502825038250482505825068250782508825098251082511825128251382514825158251682517825188251982520825218252282523825248252582526825278252882529825308253182532825338253482535825368253782538825398254082541825428254382544825458254682547825488254982550825518255282553825548255582556825578255882559825608256182562825638256482565825668256782568825698257082571825728257382574825758257682577825788257982580825818258282583825848258582586825878258882589825908259182592825938259482595825968259782598825998260082601826028260382604826058260682607826088260982610826118261282613826148261582616826178261882619826208262182622826238262482625826268262782628826298263082631826328263382634826358263682637826388263982640826418264282643826448264582646826478264882649826508265182652826538265482655826568265782658826598266082661826628266382664826658266682667826688266982670826718267282673826748267582676826778267882679826808268182682826838268482685826868268782688826898269082691826928269382694826958269682697826988269982700827018270282703827048270582706827078270882709827108271182712827138271482715827168271782718827198272082721827228272382724827258272682727827288272982730827318273282733827348273582736827378273882739827408274182742827438274482745827468274782748827498275082751827528275382754827558275682757827588275982760827618276282763827648276582766827678276882769827708277182772827738277482775827768277782778827798278082781827828278382784827858278682787827888278982790827918279282793827948279582796827978279882799828008280182802828038280482805828068280782808828098281082811828128281382814828158281682817828188281982820828218282282823828248282582826828278282882829828308283182832828338283482835828368283782838828398284082841828428284382844828458284682847828488284982850828518285282853828548285582856828578285882859828608286182862828638286482865828668286782868828698287082871828728287382874828758287682877828788287982880828818288282883828848288582886828878288882889828908289182892828938289482895828968289782898828998290082901829028290382904829058290682907829088290982910829118291282913829148291582916829178291882919829208292182922829238292482925829268292782928829298293082931829328293382934829358293682937829388293982940829418294282943829448294582946829478294882949829508295182952829538295482955829568295782958829598296082961829628296382964829658296682967829688296982970829718297282973829748297582976829778297882979829808298182982829838298482985829868298782988829898299082991829928299382994829958299682997829988299983000830018300283003830048300583006830078300883009830108301183012830138301483015830168301783018830198302083021830228302383024830258302683027830288302983030830318303283033830348303583036830378303883039830408304183042830438304483045830468304783048830498305083051830528305383054830558305683057830588305983060830618306283063830648306583066830678306883069830708307183072830738307483075830768307783078830798308083081830828308383084830858308683087830888308983090830918309283093830948309583096830978309883099831008310183102831038310483105831068310783108831098311083111831128311383114831158311683117831188311983120831218312283123831248312583126831278312883129831308313183132831338313483135831368313783138831398314083141831428314383144831458314683147831488314983150831518315283153831548315583156831578315883159831608316183162831638316483165831668316783168831698317083171831728317383174831758317683177831788317983180831818318283183831848318583186831878318883189831908319183192831938319483195831968319783198831998320083201832028320383204832058320683207832088320983210832118321283213832148321583216832178321883219832208322183222832238322483225832268322783228832298323083231832328323383234832358323683237832388323983240832418324283243832448324583246832478324883249832508325183252832538325483255832568325783258832598326083261832628326383264832658326683267832688326983270832718327283273832748327583276832778327883279832808328183282832838328483285832868328783288832898329083291832928329383294832958329683297832988329983300833018330283303833048330583306833078330883309833108331183312833138331483315833168331783318833198332083321833228332383324833258332683327833288332983330833318333283333833348333583336833378333883339833408334183342833438334483345833468334783348833498335083351833528335383354833558335683357833588335983360833618336283363833648336583366833678336883369833708337183372833738337483375833768337783378833798338083381833828338383384833858338683387833888338983390833918339283393833948339583396833978339883399834008340183402834038340483405834068340783408834098341083411834128341383414834158341683417834188341983420834218342283423834248342583426834278342883429834308343183432834338343483435834368343783438834398344083441834428344383444834458344683447834488344983450834518345283453834548345583456834578345883459834608346183462834638346483465834668346783468834698347083471834728347383474834758347683477834788347983480834818348283483834848348583486834878348883489834908349183492834938349483495834968349783498834998350083501835028350383504835058350683507835088350983510835118351283513835148351583516835178351883519835208352183522835238352483525835268352783528835298353083531835328353383534835358353683537835388353983540835418354283543835448354583546835478354883549835508355183552835538355483555835568355783558835598356083561835628356383564835658356683567835688356983570835718357283573835748357583576835778357883579835808358183582835838358483585835868358783588835898359083591835928359383594835958359683597835988359983600836018360283603836048360583606836078360883609836108361183612836138361483615836168361783618836198362083621836228362383624836258362683627836288362983630836318363283633836348363583636836378363883639836408364183642836438364483645836468364783648836498365083651836528365383654836558365683657836588365983660836618366283663836648366583666836678366883669836708367183672836738367483675836768367783678836798368083681836828368383684836858368683687836888368983690836918369283693836948369583696836978369883699837008370183702837038370483705837068370783708837098371083711837128371383714837158371683717837188371983720837218372283723837248372583726837278372883729837308373183732837338373483735837368373783738837398374083741837428374383744837458374683747837488374983750837518375283753837548375583756837578375883759837608376183762837638376483765837668376783768837698377083771837728377383774837758377683777837788377983780837818378283783837848378583786837878378883789837908379183792837938379483795837968379783798837998380083801838028380383804838058380683807838088380983810838118381283813838148381583816838178381883819838208382183822838238382483825838268382783828838298383083831838328383383834838358383683837838388383983840838418384283843838448384583846838478384883849838508385183852838538385483855838568385783858838598386083861838628386383864838658386683867838688386983870838718387283873838748387583876838778387883879838808388183882838838388483885838868388783888838898389083891838928389383894838958389683897838988389983900839018390283903839048390583906839078390883909839108391183912839138391483915839168391783918839198392083921839228392383924839258392683927839288392983930839318393283933839348393583936839378393883939839408394183942839438394483945839468394783948839498395083951839528395383954839558395683957839588395983960839618396283963839648396583966839678396883969839708397183972839738397483975839768397783978839798398083981839828398383984839858398683987839888398983990839918399283993839948399583996839978399883999840008400184002840038400484005840068400784008840098401084011840128401384014840158401684017840188401984020840218402284023840248402584026840278402884029840308403184032840338403484035840368403784038840398404084041840428404384044840458404684047840488404984050840518405284053840548405584056840578405884059840608406184062840638406484065840668406784068840698407084071840728407384074840758407684077840788407984080840818408284083840848408584086840878408884089840908409184092840938409484095840968409784098840998410084101841028410384104841058410684107841088410984110841118411284113841148411584116841178411884119841208412184122841238412484125841268412784128841298413084131841328413384134841358413684137841388413984140841418414284143841448414584146841478414884149841508415184152841538415484155841568415784158841598416084161841628416384164841658416684167841688416984170841718417284173841748417584176841778417884179841808418184182841838418484185841868418784188841898419084191841928419384194841958419684197841988419984200842018420284203842048420584206842078420884209842108421184212842138421484215842168421784218842198422084221842228422384224842258422684227842288422984230842318423284233842348423584236842378423884239842408424184242842438424484245842468424784248842498425084251842528425384254842558425684257842588425984260842618426284263842648426584266842678426884269842708427184272842738427484275842768427784278842798428084281842828428384284842858428684287842888428984290842918429284293842948429584296842978429884299843008430184302843038430484305843068430784308843098431084311843128431384314843158431684317843188431984320843218432284323843248432584326843278432884329843308433184332843338433484335843368433784338843398434084341843428434384344843458434684347843488434984350843518435284353843548435584356843578435884359843608436184362843638436484365843668436784368843698437084371843728437384374843758437684377843788437984380843818438284383843848438584386843878438884389843908439184392843938439484395843968439784398843998440084401844028440384404844058440684407844088440984410844118441284413844148441584416844178441884419844208442184422844238442484425844268442784428844298443084431844328443384434844358443684437844388443984440844418444284443844448444584446844478444884449844508445184452844538445484455844568445784458844598446084461844628446384464844658446684467844688446984470844718447284473844748447584476844778447884479844808448184482844838448484485844868448784488844898449084491844928449384494844958449684497844988449984500845018450284503845048450584506845078450884509845108451184512845138451484515845168451784518845198452084521845228452384524845258452684527845288452984530845318453284533845348453584536845378453884539845408454184542845438454484545845468454784548845498455084551845528455384554845558455684557845588455984560845618456284563845648456584566845678456884569845708457184572845738457484575845768457784578845798458084581845828458384584845858458684587845888458984590845918459284593845948459584596845978459884599846008460184602846038460484605846068460784608846098461084611846128461384614846158461684617846188461984620846218462284623846248462584626846278462884629846308463184632846338463484635846368463784638846398464084641846428464384644846458464684647846488464984650846518465284653846548465584656846578465884659846608466184662846638466484665846668466784668846698467084671846728467384674846758467684677846788467984680846818468284683846848468584686846878468884689846908469184692846938469484695846968469784698846998470084701847028470384704847058470684707847088470984710847118471284713847148471584716847178471884719847208472184722847238472484725847268472784728847298473084731847328473384734847358473684737847388473984740847418474284743847448474584746847478474884749847508475184752847538475484755847568475784758847598476084761847628476384764847658476684767847688476984770847718477284773847748477584776847778477884779847808478184782847838478484785847868478784788847898479084791847928479384794847958479684797847988479984800848018480284803848048480584806848078480884809848108481184812848138481484815848168481784818848198482084821848228482384824848258482684827848288482984830848318483284833848348483584836848378483884839848408484184842848438484484845848468484784848848498485084851848528485384854848558485684857848588485984860848618486284863848648486584866848678486884869848708487184872848738487484875848768487784878848798488084881848828488384884848858488684887848888488984890848918489284893848948489584896848978489884899849008490184902849038490484905849068490784908849098491084911849128491384914849158491684917849188491984920849218492284923849248492584926849278492884929849308493184932849338493484935849368493784938849398494084941849428494384944849458494684947849488494984950849518495284953849548495584956849578495884959849608496184962849638496484965849668496784968849698497084971849728497384974849758497684977849788497984980849818498284983849848498584986849878498884989849908499184992849938499484995849968499784998849998500085001850028500385004850058500685007850088500985010850118501285013850148501585016850178501885019850208502185022850238502485025850268502785028850298503085031850328503385034850358503685037850388503985040850418504285043850448504585046850478504885049850508505185052850538505485055850568505785058850598506085061850628506385064850658506685067850688506985070850718507285073850748507585076850778507885079850808508185082850838508485085850868508785088850898509085091850928509385094850958509685097850988509985100851018510285103851048510585106851078510885109851108511185112851138511485115851168511785118851198512085121851228512385124851258512685127851288512985130851318513285133851348513585136851378513885139851408514185142851438514485145851468514785148851498515085151851528515385154851558515685157851588515985160851618516285163851648516585166851678516885169851708517185172851738517485175851768517785178851798518085181851828518385184851858518685187851888518985190851918519285193851948519585196851978519885199852008520185202852038520485205852068520785208852098521085211852128521385214852158521685217852188521985220852218522285223852248522585226852278522885229852308523185232852338523485235852368523785238852398524085241852428524385244852458524685247852488524985250852518525285253852548525585256852578525885259852608526185262852638526485265852668526785268852698527085271852728527385274852758527685277852788527985280852818528285283852848528585286852878528885289852908529185292852938529485295852968529785298852998530085301853028530385304853058530685307853088530985310853118531285313853148531585316853178531885319853208532185322853238532485325853268532785328853298533085331853328533385334853358533685337853388533985340853418534285343853448534585346853478534885349853508535185352853538535485355853568535785358853598536085361853628536385364853658536685367853688536985370853718537285373853748537585376853778537885379853808538185382853838538485385853868538785388853898539085391853928539385394853958539685397853988539985400854018540285403854048540585406854078540885409854108541185412854138541485415854168541785418854198542085421854228542385424854258542685427854288542985430854318543285433854348543585436854378543885439854408544185442854438544485445854468544785448854498545085451854528545385454854558545685457854588545985460854618546285463854648546585466854678546885469854708547185472854738547485475854768547785478854798548085481854828548385484854858548685487854888548985490854918549285493854948549585496854978549885499855008550185502855038550485505855068550785508855098551085511855128551385514855158551685517855188551985520855218552285523855248552585526855278552885529855308553185532855338553485535855368553785538855398554085541855428554385544855458554685547855488554985550855518555285553855548555585556855578555885559855608556185562855638556485565855668556785568855698557085571855728557385574855758557685577855788557985580855818558285583855848558585586855878558885589855908559185592855938559485595855968559785598855998560085601856028560385604856058560685607856088560985610856118561285613856148561585616856178561885619856208562185622856238562485625856268562785628856298563085631856328563385634856358563685637856388563985640856418564285643856448564585646856478564885649856508565185652856538565485655856568565785658856598566085661856628566385664856658566685667856688566985670856718567285673856748567585676856778567885679856808568185682856838568485685856868568785688856898569085691856928569385694856958569685697856988569985700857018570285703857048570585706857078570885709857108571185712857138571485715857168571785718857198572085721857228572385724857258572685727857288572985730857318573285733857348573585736857378573885739857408574185742857438574485745857468574785748857498575085751857528575385754857558575685757857588575985760857618576285763857648576585766857678576885769857708577185772857738577485775857768577785778857798578085781857828578385784857858578685787857888578985790857918579285793857948579585796857978579885799858008580185802858038580485805858068580785808858098581085811858128581385814858158581685817858188581985820858218582285823858248582585826858278582885829858308583185832858338583485835858368583785838858398584085841858428584385844858458584685847858488584985850858518585285853858548585585856858578585885859858608586185862858638586485865858668586785868858698587085871858728587385874858758587685877858788587985880858818588285883858848588585886858878588885889858908589185892858938589485895858968589785898858998590085901859028590385904859058590685907859088590985910859118591285913859148591585916859178591885919859208592185922859238592485925859268592785928859298593085931859328593385934859358593685937859388593985940859418594285943859448594585946859478594885949859508595185952859538595485955859568595785958859598596085961859628596385964859658596685967859688596985970859718597285973859748597585976859778597885979859808598185982859838598485985859868598785988859898599085991859928599385994859958599685997859988599986000860018600286003860048600586006860078600886009860108601186012860138601486015860168601786018860198602086021860228602386024860258602686027860288602986030860318603286033860348603586036860378603886039860408604186042860438604486045860468604786048860498605086051860528605386054860558605686057860588605986060860618606286063860648606586066860678606886069860708607186072860738607486075860768607786078860798608086081860828608386084860858608686087860888608986090860918609286093860948609586096860978609886099861008610186102861038610486105861068610786108861098611086111861128611386114861158611686117861188611986120861218612286123861248612586126861278612886129861308613186132861338613486135861368613786138861398614086141861428614386144861458614686147861488614986150861518615286153861548615586156861578615886159861608616186162861638616486165861668616786168861698617086171861728617386174861758617686177861788617986180861818618286183861848618586186861878618886189861908619186192861938619486195861968619786198861998620086201862028620386204862058620686207862088620986210862118621286213862148621586216862178621886219862208622186222862238622486225862268622786228862298623086231862328623386234862358623686237862388623986240862418624286243862448624586246862478624886249862508625186252862538625486255862568625786258862598626086261862628626386264862658626686267862688626986270862718627286273862748627586276862778627886279862808628186282862838628486285862868628786288862898629086291862928629386294862958629686297862988629986300863018630286303863048630586306863078630886309863108631186312863138631486315863168631786318863198632086321863228632386324863258632686327863288632986330863318633286333863348633586336863378633886339863408634186342863438634486345863468634786348863498635086351863528635386354863558635686357863588635986360863618636286363863648636586366863678636886369863708637186372863738637486375863768637786378863798638086381863828638386384863858638686387863888638986390863918639286393863948639586396863978639886399864008640186402864038640486405864068640786408864098641086411864128641386414864158641686417864188641986420864218642286423864248642586426864278642886429864308643186432864338643486435864368643786438864398644086441864428644386444864458644686447864488644986450864518645286453864548645586456864578645886459864608646186462864638646486465864668646786468864698647086471864728647386474864758647686477864788647986480864818648286483864848648586486864878648886489864908649186492864938649486495864968649786498864998650086501865028650386504865058650686507865088650986510865118651286513865148651586516865178651886519865208652186522865238652486525865268652786528865298653086531865328653386534865358653686537865388653986540865418654286543865448654586546865478654886549865508655186552865538655486555865568655786558865598656086561865628656386564865658656686567865688656986570865718657286573865748657586576865778657886579865808658186582865838658486585865868658786588865898659086591865928659386594865958659686597865988659986600866018660286603866048660586606866078660886609866108661186612866138661486615866168661786618866198662086621866228662386624866258662686627866288662986630866318663286633866348663586636866378663886639866408664186642866438664486645866468664786648866498665086651866528665386654866558665686657866588665986660866618666286663866648666586666866678666886669866708667186672866738667486675866768667786678866798668086681866828668386684866858668686687866888668986690866918669286693866948669586696866978669886699867008670186702867038670486705867068670786708867098671086711867128671386714867158671686717867188671986720867218672286723867248672586726867278672886729867308673186732867338673486735867368673786738867398674086741867428674386744867458674686747867488674986750867518675286753867548675586756867578675886759867608676186762867638676486765867668676786768867698677086771867728677386774867758677686777867788677986780867818678286783867848678586786867878678886789867908679186792867938679486795867968679786798867998680086801868028680386804868058680686807868088680986810868118681286813868148681586816868178681886819868208682186822868238682486825868268682786828868298683086831868328683386834868358683686837868388683986840868418684286843868448684586846868478684886849868508685186852868538685486855868568685786858868598686086861868628686386864868658686686867868688686986870868718687286873868748687586876868778687886879868808688186882868838688486885868868688786888868898689086891868928689386894868958689686897868988689986900869018690286903869048690586906869078690886909869108691186912869138691486915869168691786918869198692086921869228692386924869258692686927869288692986930869318693286933869348693586936869378693886939869408694186942869438694486945869468694786948869498695086951869528695386954869558695686957869588695986960869618696286963869648696586966869678696886969869708697186972869738697486975869768697786978869798698086981869828698386984869858698686987869888698986990869918699286993869948699586996869978699886999870008700187002870038700487005870068700787008870098701087011870128701387014870158701687017870188701987020870218702287023870248702587026870278702887029870308703187032870338703487035870368703787038870398704087041870428704387044870458704687047870488704987050870518705287053870548705587056870578705887059870608706187062870638706487065870668706787068870698707087071870728707387074870758707687077870788707987080870818708287083870848708587086870878708887089870908709187092870938709487095870968709787098870998710087101871028710387104871058710687107871088710987110871118711287113871148711587116871178711887119871208712187122871238712487125871268712787128871298713087131871328713387134871358713687137871388713987140871418714287143871448714587146871478714887149871508715187152871538715487155871568715787158871598716087161871628716387164871658716687167871688716987170871718717287173871748717587176871778717887179871808718187182871838718487185871868718787188871898719087191871928719387194871958719687197871988719987200872018720287203872048720587206872078720887209872108721187212872138721487215872168721787218872198722087221872228722387224872258722687227872288722987230872318723287233872348723587236872378723887239872408724187242872438724487245872468724787248872498725087251872528725387254872558725687257872588725987260872618726287263872648726587266872678726887269872708727187272872738727487275872768727787278872798728087281872828728387284872858728687287872888728987290872918729287293872948729587296872978729887299873008730187302873038730487305873068730787308873098731087311873128731387314873158731687317873188731987320873218732287323873248732587326873278732887329873308733187332873338733487335873368733787338873398734087341873428734387344873458734687347873488734987350873518735287353873548735587356873578735887359873608736187362873638736487365873668736787368873698737087371873728737387374873758737687377873788737987380873818738287383873848738587386873878738887389873908739187392873938739487395873968739787398873998740087401874028740387404874058740687407874088740987410874118741287413874148741587416874178741887419874208742187422874238742487425874268742787428874298743087431874328743387434874358743687437874388743987440874418744287443874448744587446874478744887449874508745187452874538745487455874568745787458874598746087461874628746387464874658746687467874688746987470874718747287473874748747587476874778747887479874808748187482874838748487485874868748787488874898749087491874928749387494874958749687497874988749987500875018750287503875048750587506875078750887509875108751187512875138751487515875168751787518875198752087521875228752387524875258752687527875288752987530875318753287533875348753587536875378753887539875408754187542875438754487545875468754787548875498755087551875528755387554875558755687557875588755987560875618756287563875648756587566875678756887569875708757187572875738757487575875768757787578875798758087581875828758387584875858758687587875888758987590875918759287593875948759587596875978759887599876008760187602876038760487605876068760787608876098761087611876128761387614876158761687617876188761987620876218762287623876248762587626876278762887629876308763187632876338763487635876368763787638876398764087641876428764387644876458764687647876488764987650876518765287653876548765587656876578765887659876608766187662876638766487665876668766787668876698767087671876728767387674876758767687677876788767987680876818768287683876848768587686876878768887689876908769187692876938769487695876968769787698876998770087701877028770387704877058770687707877088770987710877118771287713877148771587716877178771887719877208772187722877238772487725877268772787728877298773087731877328773387734877358773687737877388773987740877418774287743877448774587746877478774887749877508775187752877538775487755877568775787758877598776087761877628776387764877658776687767877688776987770877718777287773877748777587776877778777887779877808778187782877838778487785877868778787788877898779087791877928779387794877958779687797877988779987800878018780287803878048780587806878078780887809878108781187812878138781487815878168781787818878198782087821878228782387824878258782687827878288782987830878318783287833878348783587836878378783887839878408784187842878438784487845878468784787848878498785087851878528785387854878558785687857878588785987860878618786287863878648786587866878678786887869878708787187872878738787487875878768787787878878798788087881878828788387884878858788687887878888788987890878918789287893878948789587896878978789887899879008790187902879038790487905879068790787908879098791087911879128791387914879158791687917879188791987920879218792287923879248792587926879278792887929879308793187932879338793487935879368793787938879398794087941879428794387944879458794687947879488794987950879518795287953879548795587956879578795887959879608796187962879638796487965879668796787968879698797087971879728797387974879758797687977879788797987980879818798287983879848798587986879878798887989879908799187992879938799487995879968799787998879998800088001880028800388004880058800688007880088800988010880118801288013880148801588016880178801888019880208802188022880238802488025880268802788028880298803088031880328803388034880358803688037880388803988040880418804288043880448804588046880478804888049880508805188052880538805488055880568805788058880598806088061880628806388064880658806688067880688806988070880718807288073880748807588076880778807888079880808808188082880838808488085880868808788088880898809088091880928809388094880958809688097880988809988100881018810288103881048810588106881078810888109881108811188112881138811488115881168811788118881198812088121881228812388124881258812688127881288812988130881318813288133881348813588136881378813888139881408814188142881438814488145881468814788148881498815088151881528815388154881558815688157881588815988160881618816288163881648816588166881678816888169881708817188172881738817488175881768817788178881798818088181881828818388184881858818688187881888818988190881918819288193881948819588196881978819888199882008820188202882038820488205882068820788208882098821088211882128821388214882158821688217882188821988220882218822288223882248822588226882278822888229882308823188232882338823488235882368823788238882398824088241882428824388244882458824688247882488824988250882518825288253882548825588256882578825888259882608826188262882638826488265882668826788268882698827088271882728827388274882758827688277882788827988280882818828288283882848828588286882878828888289882908829188292882938829488295882968829788298882998830088301883028830388304883058830688307883088830988310883118831288313883148831588316883178831888319883208832188322883238832488325883268832788328883298833088331883328833388334883358833688337883388833988340883418834288343883448834588346883478834888349883508835188352883538835488355883568835788358883598836088361883628836388364883658836688367883688836988370883718837288373883748837588376883778837888379883808838188382883838838488385883868838788388883898839088391883928839388394883958839688397883988839988400884018840288403884048840588406884078840888409884108841188412884138841488415884168841788418884198842088421884228842388424884258842688427884288842988430884318843288433884348843588436884378843888439884408844188442884438844488445884468844788448884498845088451884528845388454884558845688457884588845988460884618846288463884648846588466884678846888469884708847188472884738847488475884768847788478884798848088481884828848388484884858848688487884888848988490884918849288493884948849588496884978849888499885008850188502885038850488505885068850788508885098851088511885128851388514885158851688517885188851988520885218852288523885248852588526885278852888529885308853188532885338853488535885368853788538885398854088541885428854388544885458854688547885488854988550885518855288553885548855588556885578855888559885608856188562885638856488565885668856788568885698857088571885728857388574885758857688577885788857988580885818858288583885848858588586885878858888589885908859188592885938859488595885968859788598885998860088601886028860388604886058860688607886088860988610886118861288613886148861588616886178861888619886208862188622886238862488625886268862788628886298863088631886328863388634886358863688637886388863988640886418864288643886448864588646886478864888649886508865188652886538865488655886568865788658886598866088661886628866388664886658866688667886688866988670886718867288673886748867588676886778867888679886808868188682886838868488685886868868788688886898869088691886928869388694886958869688697886988869988700887018870288703887048870588706887078870888709887108871188712887138871488715887168871788718887198872088721887228872388724887258872688727887288872988730887318873288733887348873588736887378873888739887408874188742887438874488745887468874788748887498875088751887528875388754887558875688757887588875988760887618876288763887648876588766887678876888769887708877188772887738877488775887768877788778887798878088781887828878388784887858878688787887888878988790887918879288793887948879588796887978879888799888008880188802888038880488805888068880788808888098881088811888128881388814888158881688817888188881988820888218882288823888248882588826888278882888829888308883188832888338883488835888368883788838888398884088841888428884388844888458884688847888488884988850888518885288853888548885588856888578885888859888608886188862888638886488865888668886788868888698887088871888728887388874888758887688877888788887988880888818888288883888848888588886888878888888889888908889188892888938889488895888968889788898888998890088901889028890388904889058890688907889088890988910889118891288913889148891588916889178891888919889208892188922889238892488925889268892788928889298893088931889328893388934889358893688937889388893988940889418894288943889448894588946889478894888949889508895188952889538895488955889568895788958889598896088961889628896388964889658896688967889688896988970889718897288973889748897588976889778897888979889808898188982889838898488985889868898788988889898899088991889928899388994889958899688997889988899989000890018900289003890048900589006890078900889009890108901189012890138901489015890168901789018890198902089021890228902389024890258902689027890288902989030890318903289033890348903589036890378903889039890408904189042890438904489045890468904789048890498905089051890528905389054890558905689057890588905989060890618906289063890648906589066890678906889069890708907189072890738907489075890768907789078890798908089081890828908389084890858908689087890888908989090890918909289093890948909589096890978909889099891008910189102891038910489105891068910789108891098911089111891128911389114891158911689117891188911989120891218912289123891248912589126891278912889129891308913189132891338913489135891368913789138891398914089141891428914389144891458914689147891488914989150891518915289153891548915589156891578915889159891608916189162891638916489165891668916789168891698917089171891728917389174891758917689177891788917989180891818918289183891848918589186891878918889189891908919189192891938919489195891968919789198891998920089201892028920389204892058920689207892088920989210892118921289213892148921589216892178921889219892208922189222892238922489225892268922789228892298923089231892328923389234892358923689237892388923989240892418924289243892448924589246892478924889249892508925189252892538925489255892568925789258892598926089261892628926389264892658926689267892688926989270892718927289273892748927589276892778927889279892808928189282892838928489285892868928789288892898929089291892928929389294892958929689297892988929989300893018930289303893048930589306893078930889309893108931189312893138931489315893168931789318893198932089321893228932389324893258932689327893288932989330893318933289333893348933589336893378933889339893408934189342893438934489345893468934789348893498935089351893528935389354893558935689357893588935989360893618936289363893648936589366893678936889369893708937189372893738937489375893768937789378893798938089381893828938389384893858938689387893888938989390893918939289393893948939589396893978939889399894008940189402894038940489405894068940789408894098941089411894128941389414894158941689417894188941989420894218942289423894248942589426894278942889429894308943189432894338943489435894368943789438894398944089441894428944389444894458944689447894488944989450894518945289453894548945589456894578945889459894608946189462894638946489465894668946789468894698947089471894728947389474894758947689477894788947989480894818948289483894848948589486894878948889489894908949189492894938949489495894968949789498894998950089501895028950389504895058950689507895088950989510895118951289513895148951589516895178951889519895208952189522895238952489525895268952789528895298953089531895328953389534895358953689537895388953989540895418954289543895448954589546895478954889549895508955189552895538955489555895568955789558895598956089561895628956389564895658956689567895688956989570895718957289573895748957589576895778957889579895808958189582895838958489585895868958789588895898959089591895928959389594895958959689597895988959989600896018960289603896048960589606896078960889609896108961189612896138961489615896168961789618896198962089621896228962389624896258962689627896288962989630896318963289633896348963589636896378963889639896408964189642896438964489645896468964789648896498965089651896528965389654896558965689657896588965989660896618966289663896648966589666896678966889669896708967189672896738967489675896768967789678896798968089681896828968389684896858968689687896888968989690896918969289693896948969589696896978969889699897008970189702897038970489705897068970789708897098971089711897128971389714897158971689717897188971989720897218972289723897248972589726897278972889729897308973189732897338973489735897368973789738897398974089741897428974389744897458974689747897488974989750897518975289753897548975589756897578975889759897608976189762897638976489765897668976789768897698977089771897728977389774897758977689777897788977989780897818978289783897848978589786897878978889789897908979189792897938979489795897968979789798897998980089801898028980389804898058980689807898088980989810898118981289813898148981589816898178981889819898208982189822898238982489825898268982789828898298983089831898328983389834898358983689837898388983989840898418984289843898448984589846898478984889849898508985189852898538985489855898568985789858898598986089861898628986389864898658986689867898688986989870898718987289873898748987589876898778987889879898808988189882898838988489885898868988789888898898989089891898928989389894898958989689897898988989989900899018990289903899048990589906899078990889909899108991189912899138991489915899168991789918899198992089921899228992389924899258992689927899288992989930899318993289933899348993589936899378993889939899408994189942899438994489945899468994789948899498995089951899528995389954899558995689957899588995989960899618996289963899648996589966899678996889969899708997189972899738997489975899768997789978899798998089981899828998389984899858998689987899888998989990899918999289993899948999589996899978999889999900009000190002900039000490005900069000790008900099001090011900129001390014900159001690017900189001990020900219002290023900249002590026900279002890029900309003190032900339003490035900369003790038900399004090041900429004390044900459004690047900489004990050900519005290053900549005590056900579005890059900609006190062900639006490065900669006790068900699007090071900729007390074900759007690077900789007990080900819008290083900849008590086900879008890089900909009190092900939009490095900969009790098900999010090101901029010390104901059010690107901089010990110901119011290113901149011590116901179011890119901209012190122901239012490125901269012790128901299013090131901329013390134901359013690137901389013990140901419014290143901449014590146901479014890149901509015190152901539015490155901569015790158901599016090161901629016390164901659016690167901689016990170901719017290173901749017590176901779017890179901809018190182901839018490185901869018790188901899019090191901929019390194901959019690197901989019990200902019020290203902049020590206902079020890209902109021190212902139021490215902169021790218902199022090221902229022390224902259022690227902289022990230902319023290233902349023590236902379023890239902409024190242902439024490245902469024790248902499025090251902529025390254902559025690257902589025990260902619026290263902649026590266902679026890269902709027190272902739027490275902769027790278902799028090281902829028390284902859028690287902889028990290902919029290293902949029590296902979029890299903009030190302903039030490305903069030790308903099031090311903129031390314903159031690317903189031990320903219032290323903249032590326903279032890329903309033190332903339033490335903369033790338903399034090341903429034390344903459034690347903489034990350903519035290353903549035590356903579035890359903609036190362903639036490365903669036790368903699037090371903729037390374903759037690377903789037990380903819038290383903849038590386903879038890389903909039190392903939039490395903969039790398903999040090401904029040390404904059040690407904089040990410904119041290413904149041590416904179041890419904209042190422904239042490425904269042790428904299043090431904329043390434904359043690437904389043990440904419044290443904449044590446904479044890449904509045190452904539045490455904569045790458904599046090461904629046390464904659046690467904689046990470904719047290473904749047590476904779047890479904809048190482904839048490485904869048790488904899049090491904929049390494904959049690497904989049990500905019050290503905049050590506905079050890509905109051190512905139051490515905169051790518905199052090521905229052390524905259052690527905289052990530905319053290533905349053590536905379053890539905409054190542905439054490545905469054790548905499055090551905529055390554905559055690557905589055990560905619056290563905649056590566905679056890569905709057190572905739057490575905769057790578905799058090581905829058390584905859058690587905889058990590905919059290593905949059590596905979059890599906009060190602906039060490605906069060790608906099061090611906129061390614906159061690617906189061990620906219062290623906249062590626906279062890629906309063190632906339063490635906369063790638906399064090641906429064390644906459064690647906489064990650906519065290653906549065590656906579065890659906609066190662906639066490665906669066790668906699067090671906729067390674906759067690677906789067990680906819068290683906849068590686906879068890689906909069190692906939069490695906969069790698906999070090701907029070390704907059070690707907089070990710907119071290713907149071590716907179071890719907209072190722907239072490725907269072790728907299073090731907329073390734907359073690737907389073990740907419074290743907449074590746907479074890749907509075190752907539075490755907569075790758907599076090761907629076390764907659076690767907689076990770907719077290773907749077590776907779077890779907809078190782907839078490785907869078790788907899079090791907929079390794907959079690797907989079990800908019080290803908049080590806908079080890809908109081190812908139081490815908169081790818908199082090821908229082390824908259082690827908289082990830908319083290833908349083590836908379083890839908409084190842908439084490845908469084790848908499085090851908529085390854908559085690857908589085990860908619086290863908649086590866908679086890869908709087190872908739087490875908769087790878908799088090881908829088390884908859088690887908889088990890908919089290893908949089590896908979089890899909009090190902909039090490905909069090790908909099091090911909129091390914909159091690917909189091990920909219092290923909249092590926909279092890929909309093190932909339093490935909369093790938909399094090941909429094390944909459094690947909489094990950909519095290953909549095590956909579095890959909609096190962909639096490965909669096790968909699097090971909729097390974909759097690977909789097990980909819098290983909849098590986909879098890989909909099190992909939099490995909969099790998909999100091001910029100391004910059100691007910089100991010910119101291013910149101591016910179101891019910209102191022910239102491025910269102791028910299103091031910329103391034910359103691037910389103991040910419104291043910449104591046910479104891049910509105191052910539105491055910569105791058910599106091061910629106391064910659106691067910689106991070910719107291073910749107591076910779107891079910809108191082910839108491085910869108791088910899109091091910929109391094910959109691097910989109991100911019110291103911049110591106911079110891109911109111191112911139111491115911169111791118911199112091121911229112391124911259112691127911289112991130911319113291133911349113591136911379113891139911409114191142911439114491145911469114791148911499115091151911529115391154911559115691157911589115991160911619116291163911649116591166911679116891169911709117191172911739117491175911769117791178911799118091181911829118391184911859118691187911889118991190911919119291193911949119591196911979119891199912009120191202912039120491205912069120791208912099121091211912129121391214912159121691217912189121991220912219122291223912249122591226912279122891229912309123191232912339123491235912369123791238912399124091241912429124391244912459124691247912489124991250912519125291253912549125591256912579125891259912609126191262912639126491265912669126791268912699127091271912729127391274912759127691277912789127991280912819128291283912849128591286912879128891289912909129191292912939129491295912969129791298912999130091301913029130391304913059130691307913089130991310913119131291313913149131591316913179131891319913209132191322913239132491325913269132791328913299133091331913329133391334913359133691337913389133991340913419134291343913449134591346913479134891349913509135191352913539135491355913569135791358913599136091361913629136391364913659136691367913689136991370913719137291373913749137591376913779137891379913809138191382913839138491385913869138791388913899139091391913929139391394913959139691397913989139991400914019140291403914049140591406914079140891409914109141191412914139141491415914169141791418914199142091421914229142391424914259142691427914289142991430914319143291433914349143591436914379143891439914409144191442914439144491445914469144791448914499145091451914529145391454914559145691457914589145991460914619146291463914649146591466914679146891469914709147191472914739147491475914769147791478914799148091481914829148391484914859148691487914889148991490914919149291493914949149591496914979149891499915009150191502915039150491505915069150791508915099151091511915129151391514915159151691517915189151991520915219152291523915249152591526915279152891529915309153191532915339153491535915369153791538915399154091541915429154391544915459154691547915489154991550915519155291553915549155591556915579155891559915609156191562915639156491565915669156791568915699157091571915729157391574915759157691577915789157991580915819158291583915849158591586915879158891589915909159191592915939159491595915969159791598915999160091601916029160391604916059160691607916089160991610916119161291613916149161591616916179161891619916209162191622916239162491625916269162791628916299163091631916329163391634916359163691637916389163991640916419164291643916449164591646916479164891649916509165191652916539165491655916569165791658916599166091661916629166391664916659166691667916689166991670916719167291673916749167591676916779167891679916809168191682916839168491685916869168791688916899169091691916929169391694916959169691697916989169991700917019170291703917049170591706917079170891709917109171191712917139171491715917169171791718917199172091721917229172391724917259172691727917289172991730917319173291733917349173591736917379173891739917409174191742917439174491745917469174791748917499175091751917529175391754917559175691757917589175991760917619176291763917649176591766917679176891769917709177191772917739177491775917769177791778917799178091781917829178391784917859178691787917889178991790917919179291793917949179591796917979179891799918009180191802918039180491805918069180791808918099181091811918129181391814918159181691817918189181991820918219182291823918249182591826918279182891829918309183191832918339183491835918369183791838918399184091841918429184391844918459184691847918489184991850918519185291853918549185591856918579185891859918609186191862918639186491865918669186791868918699187091871918729187391874918759187691877918789187991880918819188291883918849188591886918879188891889918909189191892918939189491895918969189791898918999190091901919029190391904919059190691907919089190991910919119191291913919149191591916919179191891919919209192191922919239192491925919269192791928919299193091931919329193391934919359193691937919389193991940919419194291943919449194591946919479194891949919509195191952919539195491955919569195791958919599196091961919629196391964919659196691967919689196991970919719197291973919749197591976919779197891979919809198191982919839198491985919869198791988919899199091991919929199391994919959199691997919989199992000920019200292003920049200592006920079200892009920109201192012920139201492015920169201792018920199202092021920229202392024920259202692027920289202992030920319203292033920349203592036920379203892039920409204192042920439204492045920469204792048920499205092051920529205392054920559205692057920589205992060920619206292063920649206592066920679206892069920709207192072920739207492075920769207792078920799208092081920829208392084920859208692087920889208992090920919209292093920949209592096920979209892099921009210192102921039210492105921069210792108921099211092111921129211392114921159211692117921189211992120921219212292123921249212592126921279212892129921309213192132921339213492135921369213792138921399214092141921429214392144921459214692147921489214992150921519215292153921549215592156921579215892159921609216192162921639216492165921669216792168921699217092171921729217392174921759217692177921789217992180921819218292183921849218592186921879218892189921909219192192921939219492195921969219792198921999220092201922029220392204922059220692207922089220992210922119221292213922149221592216922179221892219922209222192222922239222492225922269222792228922299223092231922329223392234922359223692237922389223992240922419224292243922449224592246922479224892249922509225192252922539225492255922569225792258922599226092261922629226392264922659226692267922689226992270922719227292273922749227592276922779227892279922809228192282922839228492285922869228792288922899229092291922929229392294922959229692297922989229992300923019230292303923049230592306923079230892309923109231192312923139231492315923169231792318923199232092321923229232392324923259232692327923289232992330923319233292333923349233592336923379233892339923409234192342923439234492345923469234792348923499235092351923529235392354923559235692357923589235992360923619236292363923649236592366923679236892369923709237192372923739237492375923769237792378923799238092381923829238392384923859238692387923889238992390923919239292393923949239592396923979239892399924009240192402924039240492405924069240792408924099241092411924129241392414924159241692417924189241992420924219242292423924249242592426924279242892429924309243192432924339243492435924369243792438924399244092441924429244392444924459244692447924489244992450924519245292453924549245592456924579245892459924609246192462924639246492465924669246792468924699247092471924729247392474924759247692477924789247992480924819248292483924849248592486924879248892489924909249192492924939249492495924969249792498924999250092501925029250392504925059250692507925089250992510925119251292513925149251592516925179251892519925209252192522925239252492525925269252792528925299253092531925329253392534925359253692537925389253992540925419254292543925449254592546925479254892549925509255192552925539255492555925569255792558925599256092561925629256392564925659256692567925689256992570925719257292573925749257592576925779257892579925809258192582925839258492585925869258792588925899259092591925929259392594925959259692597925989259992600926019260292603926049260592606926079260892609926109261192612926139261492615926169261792618926199262092621926229262392624926259262692627926289262992630926319263292633926349263592636926379263892639926409264192642926439264492645926469264792648926499265092651926529265392654926559265692657926589265992660926619266292663926649266592666926679266892669926709267192672926739267492675926769267792678926799268092681926829268392684926859268692687926889268992690926919269292693926949269592696926979269892699927009270192702927039270492705927069270792708927099271092711927129271392714927159271692717927189271992720927219272292723927249272592726927279272892729927309273192732927339273492735927369273792738927399274092741927429274392744927459274692747927489274992750927519275292753927549275592756927579275892759927609276192762927639276492765927669276792768927699277092771927729277392774927759277692777927789277992780927819278292783927849278592786927879278892789927909279192792927939279492795927969279792798927999280092801928029280392804928059280692807928089280992810928119281292813928149281592816928179281892819928209282192822928239282492825928269282792828928299283092831928329283392834928359283692837928389283992840928419284292843928449284592846928479284892849928509285192852928539285492855928569285792858928599286092861928629286392864928659286692867928689286992870928719287292873928749287592876928779287892879928809288192882928839288492885928869288792888928899289092891928929289392894928959289692897928989289992900929019290292903929049290592906929079290892909929109291192912929139291492915929169291792918929199292092921929229292392924929259292692927929289292992930929319293292933929349293592936929379293892939929409294192942929439294492945929469294792948929499295092951929529295392954929559295692957929589295992960929619296292963929649296592966929679296892969929709297192972929739297492975929769297792978929799298092981929829298392984929859298692987929889298992990929919299292993929949299592996929979299892999930009300193002930039300493005930069300793008930099301093011930129301393014930159301693017930189301993020930219302293023930249302593026930279302893029930309303193032930339303493035930369303793038930399304093041930429304393044930459304693047930489304993050930519305293053930549305593056930579305893059930609306193062930639306493065930669306793068930699307093071930729307393074930759307693077930789307993080930819308293083930849308593086930879308893089930909309193092930939309493095930969309793098930999310093101931029310393104931059310693107931089310993110931119311293113931149311593116931179311893119931209312193122931239312493125931269312793128931299313093131931329313393134931359313693137931389313993140931419314293143931449314593146931479314893149931509315193152931539315493155931569315793158931599316093161931629316393164931659316693167931689316993170931719317293173931749317593176931779317893179931809318193182931839318493185931869318793188931899319093191931929319393194931959319693197931989319993200932019320293203932049320593206932079320893209932109321193212932139321493215932169321793218932199322093221932229322393224932259322693227932289322993230932319323293233932349323593236932379323893239932409324193242932439324493245932469324793248932499325093251932529325393254932559325693257932589325993260932619326293263932649326593266932679326893269932709327193272932739327493275932769327793278932799328093281932829328393284932859328693287932889328993290932919329293293932949329593296932979329893299933009330193302933039330493305933069330793308933099331093311933129331393314933159331693317933189331993320933219332293323933249332593326933279332893329933309333193332933339333493335933369333793338933399334093341933429334393344933459334693347933489334993350933519335293353933549335593356933579335893359933609336193362933639336493365933669336793368933699337093371933729337393374933759337693377933789337993380933819338293383933849338593386933879338893389933909339193392933939339493395933969339793398933999340093401934029340393404934059340693407934089340993410934119341293413934149341593416934179341893419934209342193422934239342493425934269342793428934299343093431934329343393434934359343693437934389343993440934419344293443934449344593446934479344893449934509345193452934539345493455934569345793458934599346093461934629346393464934659346693467934689346993470934719347293473934749347593476934779347893479934809348193482934839348493485934869348793488934899349093491934929349393494934959349693497934989349993500935019350293503935049350593506935079350893509935109351193512935139351493515935169351793518935199352093521935229352393524935259352693527935289352993530935319353293533935349353593536935379353893539935409354193542935439354493545935469354793548935499355093551935529355393554935559355693557935589355993560935619356293563935649356593566935679356893569935709357193572935739357493575935769357793578935799358093581935829358393584935859358693587935889358993590935919359293593935949359593596935979359893599936009360193602936039360493605936069360793608936099361093611936129361393614936159361693617936189361993620936219362293623936249362593626936279362893629936309363193632936339363493635936369363793638936399364093641936429364393644936459364693647936489364993650936519365293653936549365593656936579365893659936609366193662936639366493665936669366793668936699367093671936729367393674936759367693677936789367993680936819368293683936849368593686936879368893689936909369193692936939369493695936969369793698936999370093701937029370393704937059370693707937089370993710937119371293713937149371593716937179371893719937209372193722937239372493725937269372793728937299373093731937329373393734937359373693737937389373993740937419374293743937449374593746937479374893749937509375193752937539375493755937569375793758937599376093761937629376393764937659376693767937689376993770937719377293773937749377593776937779377893779937809378193782937839378493785937869378793788937899379093791937929379393794937959379693797937989379993800938019380293803938049380593806938079380893809938109381193812938139381493815938169381793818938199382093821938229382393824938259382693827938289382993830938319383293833938349383593836938379383893839938409384193842938439384493845938469384793848938499385093851938529385393854938559385693857938589385993860938619386293863938649386593866938679386893869938709387193872938739387493875938769387793878938799388093881938829388393884938859388693887938889388993890938919389293893938949389593896938979389893899939009390193902939039390493905939069390793908939099391093911939129391393914939159391693917939189391993920939219392293923939249392593926939279392893929939309393193932939339393493935939369393793938939399394093941939429394393944939459394693947939489394993950939519395293953939549395593956939579395893959939609396193962939639396493965939669396793968939699397093971939729397393974939759397693977939789397993980939819398293983939849398593986939879398893989939909399193992939939399493995939969399793998939999400094001940029400394004940059400694007940089400994010940119401294013940149401594016940179401894019940209402194022940239402494025940269402794028940299403094031940329403394034940359403694037940389403994040940419404294043940449404594046940479404894049940509405194052940539405494055940569405794058940599406094061940629406394064940659406694067940689406994070940719407294073940749407594076940779407894079940809408194082940839408494085940869408794088940899409094091940929409394094940959409694097940989409994100941019410294103941049410594106941079410894109941109411194112941139411494115941169411794118941199412094121941229412394124941259412694127941289412994130941319413294133941349413594136941379413894139941409414194142941439414494145941469414794148941499415094151941529415394154941559415694157941589415994160941619416294163941649416594166941679416894169941709417194172941739417494175941769417794178941799418094181941829418394184941859418694187941889418994190941919419294193941949419594196941979419894199942009420194202942039420494205942069420794208942099421094211942129421394214942159421694217942189421994220942219422294223942249422594226942279422894229942309423194232942339423494235942369423794238942399424094241942429424394244942459424694247942489424994250942519425294253942549425594256942579425894259942609426194262942639426494265942669426794268942699427094271942729427394274942759427694277942789427994280942819428294283942849428594286942879428894289942909429194292942939429494295942969429794298942999430094301943029430394304943059430694307943089430994310943119431294313943149431594316943179431894319943209432194322943239432494325943269432794328943299433094331943329433394334943359433694337943389433994340943419434294343943449434594346943479434894349943509435194352943539435494355943569435794358943599436094361943629436394364943659436694367943689436994370943719437294373943749437594376943779437894379943809438194382943839438494385943869438794388943899439094391943929439394394943959439694397943989439994400944019440294403944049440594406944079440894409944109441194412944139441494415944169441794418944199442094421944229442394424944259442694427944289442994430944319443294433944349443594436944379443894439944409444194442944439444494445944469444794448944499445094451944529445394454944559445694457944589445994460944619446294463944649446594466944679446894469944709447194472944739447494475944769447794478944799448094481944829448394484944859448694487944889448994490944919449294493944949449594496944979449894499945009450194502945039450494505945069450794508945099451094511945129451394514945159451694517945189451994520945219452294523945249452594526945279452894529945309453194532945339453494535945369453794538945399454094541945429454394544945459454694547945489454994550945519455294553945549455594556945579455894559945609456194562945639456494565945669456794568945699457094571945729457394574945759457694577945789457994580945819458294583945849458594586945879458894589945909459194592945939459494595945969459794598945999460094601946029460394604946059460694607946089460994610946119461294613946149461594616946179461894619946209462194622946239462494625946269462794628946299463094631946329463394634946359463694637946389463994640946419464294643946449464594646946479464894649946509465194652946539465494655946569465794658946599466094661946629466394664946659466694667946689466994670946719467294673946749467594676946779467894679946809468194682946839468494685946869468794688946899469094691946929469394694946959469694697946989469994700947019470294703947049470594706947079470894709947109471194712947139471494715947169471794718947199472094721947229472394724947259472694727947289472994730947319473294733947349473594736947379473894739947409474194742947439474494745947469474794748947499475094751947529475394754947559475694757947589475994760947619476294763947649476594766947679476894769947709477194772947739477494775947769477794778947799478094781947829478394784947859478694787947889478994790947919479294793947949479594796947979479894799948009480194802948039480494805948069480794808948099481094811948129481394814948159481694817948189481994820948219482294823948249482594826948279482894829948309483194832948339483494835948369483794838948399484094841948429484394844948459484694847948489484994850948519485294853948549485594856948579485894859948609486194862948639486494865948669486794868948699487094871948729487394874948759487694877948789487994880948819488294883948849488594886948879488894889948909489194892948939489494895948969489794898948999490094901949029490394904949059490694907949089490994910949119491294913949149491594916949179491894919949209492194922949239492494925949269492794928949299493094931949329493394934949359493694937949389493994940949419494294943949449494594946949479494894949949509495194952949539495494955949569495794958949599496094961949629496394964949659496694967949689496994970949719497294973949749497594976949779497894979949809498194982949839498494985949869498794988949899499094991949929499394994949959499694997949989499995000950019500295003950049500595006950079500895009950109501195012950139501495015950169501795018950199502095021950229502395024950259502695027950289502995030950319503295033950349503595036950379503895039950409504195042950439504495045950469504795048950499505095051950529505395054950559505695057950589505995060950619506295063950649506595066950679506895069950709507195072950739507495075950769507795078950799508095081950829508395084950859508695087950889508995090950919509295093950949509595096950979509895099951009510195102951039510495105951069510795108951099511095111951129511395114951159511695117951189511995120951219512295123951249512595126951279512895129951309513195132951339513495135951369513795138951399514095141951429514395144951459514695147951489514995150951519515295153951549515595156951579515895159951609516195162951639516495165951669516795168951699517095171951729517395174951759517695177951789517995180951819518295183951849518595186951879518895189951909519195192951939519495195951969519795198951999520095201952029520395204952059520695207952089520995210952119521295213952149521595216952179521895219952209522195222952239522495225952269522795228952299523095231952329523395234952359523695237952389523995240952419524295243952449524595246952479524895249952509525195252952539525495255952569525795258952599526095261952629526395264952659526695267952689526995270952719527295273952749527595276952779527895279952809528195282952839528495285952869528795288952899529095291952929529395294952959529695297952989529995300953019530295303953049530595306953079530895309953109531195312953139531495315953169531795318953199532095321953229532395324953259532695327953289532995330953319533295333953349533595336953379533895339953409534195342953439534495345953469534795348953499535095351953529535395354953559535695357953589535995360953619536295363953649536595366953679536895369953709537195372953739537495375953769537795378953799538095381953829538395384953859538695387953889538995390953919539295393953949539595396953979539895399954009540195402954039540495405954069540795408954099541095411954129541395414954159541695417954189541995420954219542295423954249542595426954279542895429954309543195432954339543495435954369543795438954399544095441954429544395444954459544695447954489544995450954519545295453954549545595456954579545895459954609546195462954639546495465954669546795468954699547095471954729547395474954759547695477954789547995480954819548295483954849548595486954879548895489954909549195492954939549495495954969549795498954999550095501955029550395504955059550695507955089550995510955119551295513955149551595516955179551895519955209552195522955239552495525955269552795528955299553095531955329553395534955359553695537955389553995540955419554295543955449554595546955479554895549955509555195552955539555495555955569555795558955599556095561955629556395564955659556695567955689556995570955719557295573955749557595576955779557895579955809558195582955839558495585955869558795588955899559095591955929559395594955959559695597955989559995600956019560295603956049560595606956079560895609956109561195612956139561495615956169561795618956199562095621956229562395624956259562695627956289562995630956319563295633956349563595636956379563895639956409564195642956439564495645956469564795648956499565095651956529565395654956559565695657956589565995660956619566295663956649566595666956679566895669956709567195672956739567495675956769567795678956799568095681956829568395684956859568695687956889568995690956919569295693956949569595696956979569895699957009570195702957039570495705957069570795708957099571095711957129571395714957159571695717957189571995720957219572295723957249572595726957279572895729957309573195732957339573495735957369573795738957399574095741957429574395744957459574695747957489574995750957519575295753957549575595756957579575895759957609576195762957639576495765957669576795768957699577095771957729577395774957759577695777957789577995780957819578295783957849578595786957879578895789957909579195792957939579495795957969579795798957999580095801958029580395804958059580695807958089580995810958119581295813958149581595816958179581895819958209582195822958239582495825958269582795828958299583095831958329583395834958359583695837958389583995840958419584295843958449584595846958479584895849958509585195852958539585495855958569585795858958599586095861958629586395864958659586695867958689586995870958719587295873958749587595876958779587895879958809588195882958839588495885958869588795888958899589095891958929589395894958959589695897958989589995900959019590295903959049590595906959079590895909959109591195912959139591495915959169591795918959199592095921959229592395924959259592695927959289592995930959319593295933959349593595936959379593895939959409594195942959439594495945959469594795948959499595095951959529595395954959559595695957959589595995960959619596295963959649596595966959679596895969959709597195972959739597495975959769597795978959799598095981959829598395984959859598695987959889598995990959919599295993959949599595996959979599895999960009600196002960039600496005960069600796008960099601096011960129601396014960159601696017960189601996020960219602296023960249602596026960279602896029960309603196032960339603496035960369603796038960399604096041960429604396044960459604696047960489604996050960519605296053960549605596056960579605896059960609606196062960639606496065960669606796068960699607096071960729607396074960759607696077960789607996080960819608296083960849608596086960879608896089960909609196092960939609496095960969609796098960999610096101961029610396104961059610696107961089610996110961119611296113961149611596116961179611896119961209612196122961239612496125961269612796128961299613096131961329613396134961359613696137961389613996140961419614296143961449614596146961479614896149961509615196152961539615496155961569615796158961599616096161961629616396164961659616696167961689616996170961719617296173961749617596176961779617896179961809618196182961839618496185961869618796188961899619096191961929619396194961959619696197961989619996200962019620296203962049620596206962079620896209962109621196212962139621496215962169621796218962199622096221962229622396224962259622696227962289622996230962319623296233962349623596236962379623896239962409624196242962439624496245962469624796248962499625096251962529625396254962559625696257962589625996260962619626296263962649626596266962679626896269962709627196272962739627496275962769627796278962799628096281962829628396284962859628696287962889628996290962919629296293962949629596296962979629896299963009630196302963039630496305963069630796308963099631096311963129631396314963159631696317963189631996320963219632296323963249632596326963279632896329963309633196332963339633496335963369633796338963399634096341963429634396344963459634696347963489634996350963519635296353963549635596356963579635896359963609636196362963639636496365963669636796368963699637096371963729637396374963759637696377963789637996380963819638296383963849638596386963879638896389963909639196392963939639496395963969639796398963999640096401964029640396404964059640696407964089640996410964119641296413964149641596416964179641896419964209642196422964239642496425964269642796428964299643096431964329643396434964359643696437964389643996440964419644296443964449644596446964479644896449964509645196452964539645496455964569645796458964599646096461964629646396464964659646696467964689646996470964719647296473964749647596476964779647896479964809648196482964839648496485964869648796488964899649096491964929649396494964959649696497964989649996500965019650296503965049650596506965079650896509965109651196512965139651496515965169651796518965199652096521965229652396524965259652696527965289652996530965319653296533965349653596536965379653896539965409654196542965439654496545965469654796548965499655096551965529655396554965559655696557965589655996560965619656296563965649656596566965679656896569965709657196572965739657496575965769657796578965799658096581965829658396584965859658696587965889658996590965919659296593965949659596596965979659896599966009660196602966039660496605966069660796608966099661096611966129661396614966159661696617966189661996620966219662296623966249662596626966279662896629966309663196632966339663496635966369663796638966399664096641966429664396644966459664696647966489664996650966519665296653966549665596656966579665896659966609666196662966639666496665966669666796668966699667096671966729667396674966759667696677966789667996680966819668296683966849668596686966879668896689966909669196692966939669496695966969669796698966999670096701967029670396704967059670696707967089670996710967119671296713967149671596716967179671896719967209672196722967239672496725967269672796728967299673096731967329673396734967359673696737967389673996740967419674296743967449674596746967479674896749967509675196752967539675496755967569675796758967599676096761967629676396764967659676696767967689676996770967719677296773967749677596776967779677896779967809678196782967839678496785967869678796788967899679096791967929679396794967959679696797967989679996800968019680296803968049680596806968079680896809968109681196812968139681496815968169681796818968199682096821968229682396824968259682696827968289682996830968319683296833968349683596836968379683896839968409684196842968439684496845968469684796848968499685096851968529685396854968559685696857968589685996860968619686296863968649686596866968679686896869968709687196872968739687496875968769687796878968799688096881968829688396884968859688696887968889688996890968919689296893968949689596896968979689896899969009690196902969039690496905969069690796908969099691096911969129691396914969159691696917969189691996920969219692296923969249692596926969279692896929969309693196932969339693496935969369693796938969399694096941969429694396944969459694696947969489694996950969519695296953969549695596956969579695896959969609696196962969639696496965969669696796968969699697096971969729697396974969759697696977969789697996980969819698296983969849698596986969879698896989969909699196992969939699496995969969699796998969999700097001970029700397004970059700697007970089700997010970119701297013970149701597016970179701897019970209702197022970239702497025970269702797028970299703097031970329703397034970359703697037970389703997040970419704297043970449704597046970479704897049970509705197052970539705497055970569705797058970599706097061970629706397064970659706697067970689706997070970719707297073970749707597076970779707897079970809708197082970839708497085970869708797088970899709097091970929709397094970959709697097970989709997100971019710297103971049710597106971079710897109971109711197112971139711497115971169711797118971199712097121971229712397124971259712697127971289712997130971319713297133971349713597136971379713897139971409714197142971439714497145971469714797148971499715097151971529715397154971559715697157971589715997160971619716297163971649716597166971679716897169971709717197172971739717497175971769717797178971799718097181971829718397184971859718697187971889718997190971919719297193971949719597196971979719897199972009720197202972039720497205972069720797208972099721097211972129721397214972159721697217972189721997220972219722297223972249722597226972279722897229972309723197232972339723497235972369723797238972399724097241972429724397244972459724697247972489724997250972519725297253972549725597256972579725897259972609726197262972639726497265972669726797268972699727097271972729727397274972759727697277972789727997280972819728297283972849728597286972879728897289972909729197292972939729497295972969729797298972999730097301973029730397304973059730697307973089730997310973119731297313973149731597316973179731897319973209732197322973239732497325973269732797328973299733097331973329733397334973359733697337973389733997340973419734297343973449734597346973479734897349973509735197352973539735497355973569735797358973599736097361973629736397364973659736697367973689736997370973719737297373973749737597376973779737897379973809738197382973839738497385973869738797388973899739097391973929739397394973959739697397973989739997400974019740297403974049740597406974079740897409974109741197412974139741497415974169741797418974199742097421974229742397424974259742697427974289742997430974319743297433974349743597436974379743897439974409744197442974439744497445974469744797448974499745097451974529745397454974559745697457974589745997460974619746297463974649746597466974679746897469974709747197472974739747497475974769747797478974799748097481974829748397484974859748697487974889748997490974919749297493974949749597496974979749897499975009750197502975039750497505975069750797508975099751097511975129751397514975159751697517975189751997520975219752297523975249752597526975279752897529975309753197532975339753497535975369753797538975399754097541975429754397544975459754697547975489754997550975519755297553975549755597556975579755897559975609756197562975639756497565975669756797568975699757097571975729757397574975759757697577975789757997580975819758297583975849758597586975879758897589975909759197592975939759497595975969759797598975999760097601976029760397604976059760697607976089760997610976119761297613976149761597616976179761897619976209762197622976239762497625976269762797628976299763097631976329763397634976359763697637976389763997640976419764297643976449764597646976479764897649976509765197652976539765497655976569765797658976599766097661976629766397664976659766697667976689766997670976719767297673976749767597676976779767897679976809768197682976839768497685976869768797688976899769097691976929769397694976959769697697976989769997700977019770297703977049770597706977079770897709977109771197712977139771497715977169771797718977199772097721977229772397724977259772697727977289772997730977319773297733977349773597736977379773897739977409774197742977439774497745977469774797748977499775097751977529775397754977559775697757977589775997760977619776297763977649776597766977679776897769977709777197772977739777497775977769777797778977799778097781977829778397784977859778697787977889778997790977919779297793977949779597796977979779897799978009780197802978039780497805978069780797808978099781097811978129781397814978159781697817978189781997820978219782297823978249782597826978279782897829978309783197832978339783497835978369783797838978399784097841978429784397844978459784697847978489784997850978519785297853978549785597856978579785897859978609786197862978639786497865978669786797868978699787097871978729787397874978759787697877978789787997880978819788297883978849788597886978879788897889978909789197892978939789497895978969789797898978999790097901979029790397904979059790697907979089790997910979119791297913979149791597916979179791897919979209792197922979239792497925979269792797928979299793097931979329793397934979359793697937979389793997940979419794297943979449794597946979479794897949979509795197952979539795497955979569795797958979599796097961979629796397964979659796697967979689796997970979719797297973979749797597976979779797897979979809798197982979839798497985979869798797988979899799097991979929799397994979959799697997979989799998000980019800298003980049800598006980079800898009980109801198012980139801498015980169801798018980199802098021980229802398024980259802698027980289802998030980319803298033980349803598036980379803898039980409804198042980439804498045980469804798048980499805098051980529805398054980559805698057980589805998060980619806298063980649806598066980679806898069980709807198072980739807498075980769807798078980799808098081980829808398084980859808698087980889808998090980919809298093980949809598096980979809898099981009810198102981039810498105981069810798108981099811098111981129811398114981159811698117981189811998120981219812298123981249812598126981279812898129981309813198132981339813498135981369813798138981399814098141981429814398144981459814698147981489814998150981519815298153981549815598156981579815898159981609816198162981639816498165981669816798168981699817098171981729817398174981759817698177981789817998180981819818298183981849818598186981879818898189981909819198192981939819498195981969819798198981999820098201982029820398204982059820698207982089820998210982119821298213982149821598216982179821898219982209822198222982239822498225982269822798228982299823098231982329823398234982359823698237982389823998240982419824298243982449824598246982479824898249982509825198252982539825498255982569825798258982599826098261982629826398264982659826698267982689826998270982719827298273982749827598276982779827898279982809828198282982839828498285982869828798288982899829098291982929829398294982959829698297982989829998300983019830298303983049830598306983079830898309983109831198312983139831498315983169831798318983199832098321983229832398324983259832698327983289832998330983319833298333983349833598336983379833898339983409834198342983439834498345983469834798348983499835098351983529835398354
  1. /* api.c API unit tests
  2. *
  3. * Copyright (C) 2006-2024 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. /* For AES-CBC, input lengths can optionally be validated to be a
  22. * multiple of the block size, by defining WOLFSSL_AES_CBC_LENGTH_CHECKS,
  23. * also available via the configure option --enable-aescbc-length-checks.
  24. */
  25. /*----------------------------------------------------------------------------*
  26. | Includes
  27. *----------------------------------------------------------------------------*/
  28. #ifdef HAVE_CONFIG_H
  29. #include <config.h>
  30. #endif
  31. #include <wolfssl/wolfcrypt/settings.h>
  32. #undef TEST_OPENSSL_COEXIST /* can't use this option with this example */
  33. #include <wolfssl/wolfcrypt/logging.h>
  34. #include <wolfssl/wolfcrypt/hash.h>
  35. #if defined(WOLFSSL_STATIC_MEMORY)
  36. #include <wolfssl/wolfcrypt/memory.h>
  37. #endif
  38. #ifdef WOLFSSL_ASNC_CRYPT
  39. #include <wolfssl/wolfcrypt/async.h>
  40. #endif
  41. #ifdef HAVE_ECC
  42. #include <wolfssl/wolfcrypt/ecc.h> /* wc_ecc_fp_free */
  43. #ifdef WOLFSSL_SM2
  44. #include <wolfssl/wolfcrypt/sm2.h>
  45. #endif
  46. #endif
  47. #ifndef NO_ASN
  48. #include <wolfssl/wolfcrypt/asn_public.h>
  49. #endif
  50. #include <stdlib.h>
  51. #include <wolfssl/ssl.h> /* compatibility layer */
  52. #include <wolfssl/error-ssl.h>
  53. #include <wolfssl/test.h>
  54. #include <tests/unit.h>
  55. #include <tests/utils.h>
  56. /* for testing compatibility layer callbacks */
  57. #include "examples/server/server.h"
  58. #ifndef NO_MD5
  59. #include <wolfssl/wolfcrypt/md5.h>
  60. #endif
  61. #ifndef NO_SHA
  62. #include <wolfssl/wolfcrypt/sha.h>
  63. #endif
  64. #ifndef NO_SHA256
  65. #include <wolfssl/wolfcrypt/sha256.h>
  66. #endif
  67. #ifdef WOLFSSL_SHA512
  68. #include <wolfssl/wolfcrypt/sha512.h>
  69. #endif
  70. #ifdef WOLFSSL_SHA384
  71. #include <wolfssl/wolfcrypt/sha512.h>
  72. #endif
  73. #ifdef WOLFSSL_SHA3
  74. #include <wolfssl/wolfcrypt/sha3.h>
  75. #endif
  76. #ifdef WOLFSSL_SM3
  77. #include <wolfssl/wolfcrypt/sm3.h>
  78. #endif
  79. #ifndef NO_AES
  80. #include <wolfssl/wolfcrypt/aes.h>
  81. #ifdef HAVE_AES_DECRYPT
  82. #include <wolfssl/wolfcrypt/wc_encrypt.h>
  83. #endif
  84. #endif
  85. #ifdef WOLFSSL_SM4
  86. #include <wolfssl/wolfcrypt/sm4.h>
  87. #endif
  88. #ifdef WOLFSSL_RIPEMD
  89. #include <wolfssl/wolfcrypt/ripemd.h>
  90. #endif
  91. #ifndef NO_DES3
  92. #include <wolfssl/wolfcrypt/des3.h>
  93. #include <wolfssl/wolfcrypt/wc_encrypt.h>
  94. #endif
  95. #ifdef WC_RC2
  96. #include <wolfssl/wolfcrypt/rc2.h>
  97. #endif
  98. #ifndef NO_HMAC
  99. #include <wolfssl/wolfcrypt/hmac.h>
  100. #endif
  101. #ifdef HAVE_CHACHA
  102. #include <wolfssl/wolfcrypt/chacha.h>
  103. #endif
  104. #ifdef HAVE_POLY1305
  105. #include <wolfssl/wolfcrypt/poly1305.h>
  106. #endif
  107. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  108. #include <wolfssl/wolfcrypt/chacha20_poly1305.h>
  109. #endif
  110. #ifdef HAVE_CAMELLIA
  111. #include <wolfssl/wolfcrypt/camellia.h>
  112. #endif
  113. #ifndef NO_RC4
  114. #include <wolfssl/wolfcrypt/arc4.h>
  115. #endif
  116. #ifdef HAVE_BLAKE2
  117. #include <wolfssl/wolfcrypt/blake2.h>
  118. #endif
  119. #ifndef NO_RSA
  120. #include <wolfssl/wolfcrypt/rsa.h>
  121. #endif
  122. #ifndef NO_SIG_WRAPPER
  123. #include <wolfssl/wolfcrypt/signature.h>
  124. #endif
  125. #ifdef HAVE_AESCCM
  126. #include <wolfssl/wolfcrypt/aes.h>
  127. #endif
  128. #ifdef HAVE_PKCS7
  129. #include <wolfssl/wolfcrypt/pkcs7.h>
  130. #include <wolfssl/wolfcrypt/asn.h>
  131. #ifdef HAVE_LIBZ
  132. #include <wolfssl/wolfcrypt/compress.h>
  133. #endif
  134. #endif
  135. #ifdef WOLFSSL_SMALL_CERT_VERIFY
  136. #include <wolfssl/wolfcrypt/asn.h>
  137. #endif
  138. #ifndef NO_DSA
  139. #include <wolfssl/wolfcrypt/dsa.h>
  140. #endif
  141. #ifdef WOLFSSL_CMAC
  142. #include <wolfssl/wolfcrypt/cmac.h>
  143. #endif
  144. #ifdef HAVE_ED25519
  145. #include <wolfssl/wolfcrypt/ed25519.h>
  146. #endif
  147. #ifdef HAVE_CURVE25519
  148. #include <wolfssl/wolfcrypt/curve25519.h>
  149. #endif
  150. #ifdef HAVE_ED448
  151. #include <wolfssl/wolfcrypt/ed448.h>
  152. #endif
  153. #ifdef HAVE_CURVE448
  154. #include <wolfssl/wolfcrypt/curve448.h>
  155. #endif
  156. #ifdef WOLFSSL_HAVE_KYBER
  157. #include <wolfssl/wolfcrypt/kyber.h>
  158. #ifdef WOLFSSL_WC_KYBER
  159. #include <wolfssl/wolfcrypt/wc_kyber.h>
  160. #endif
  161. #endif
  162. #ifdef HAVE_DILITHIUM
  163. #include <wolfssl/wolfcrypt/dilithium.h>
  164. #endif
  165. #ifdef HAVE_PKCS12
  166. #include <wolfssl/wolfcrypt/pkcs12.h>
  167. #endif
  168. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
  169. defined(OPENSSL_ALL)
  170. #include <wolfssl/openssl/ssl.h>
  171. #ifndef NO_ASN
  172. /* for ASN_COMMON_NAME DN_tags enum */
  173. #include <wolfssl/wolfcrypt/asn.h>
  174. #endif
  175. #ifdef HAVE_OCSP
  176. #include <wolfssl/openssl/ocsp.h>
  177. #endif
  178. #endif
  179. #ifdef OPENSSL_EXTRA
  180. #include <wolfssl/openssl/cmac.h>
  181. #include <wolfssl/openssl/x509v3.h>
  182. #include <wolfssl/openssl/asn1.h>
  183. #include <wolfssl/openssl/crypto.h>
  184. #include <wolfssl/openssl/pkcs12.h>
  185. #include <wolfssl/openssl/evp.h>
  186. #include <wolfssl/openssl/dh.h>
  187. #include <wolfssl/openssl/bn.h>
  188. #include <wolfssl/openssl/buffer.h>
  189. #include <wolfssl/openssl/pem.h>
  190. #include <wolfssl/openssl/ec.h>
  191. #include <wolfssl/openssl/ecdh.h>
  192. #include <wolfssl/openssl/engine.h>
  193. #include <wolfssl/openssl/hmac.h>
  194. #include <wolfssl/openssl/objects.h>
  195. #include <wolfssl/openssl/rand.h>
  196. #include <wolfssl/openssl/modes.h>
  197. #include <wolfssl/openssl/fips_rand.h>
  198. #include <wolfssl/openssl/kdf.h>
  199. #ifdef OPENSSL_ALL
  200. #include <wolfssl/openssl/txt_db.h>
  201. #include <wolfssl/openssl/lhash.h>
  202. #endif
  203. #ifndef NO_AES
  204. #include <wolfssl/openssl/aes.h>
  205. #endif
  206. #ifndef NO_DES3
  207. #include <wolfssl/openssl/des.h>
  208. #endif
  209. #ifndef NO_RC4
  210. #include <wolfssl/openssl/rc4.h>
  211. #endif
  212. #ifdef HAVE_ECC
  213. #include <wolfssl/openssl/ecdsa.h>
  214. #endif
  215. #ifdef HAVE_PKCS7
  216. #include <wolfssl/openssl/pkcs7.h>
  217. #endif
  218. #ifdef HAVE_CURVE25519
  219. #include <wolfssl/openssl/ec25519.h>
  220. #endif
  221. #ifdef HAVE_ED25519
  222. #include <wolfssl/openssl/ed25519.h>
  223. #endif
  224. #ifdef HAVE_CURVE448
  225. #include <wolfssl/openssl/ec448.h>
  226. #endif
  227. #ifdef HAVE_ED448
  228. #include <wolfssl/openssl/ed448.h>
  229. #endif
  230. #endif /* OPENSSL_EXTRA */
  231. #if defined(OPENSSL_EXTRA) && defined(WOLFCRYPT_HAVE_SRP) && \
  232. !defined(NO_SHA256) && !defined(RC_NO_RNG)
  233. #include <wolfssl/wolfcrypt/srp.h>
  234. #endif
  235. #if (defined(SESSION_CERTS) && defined(TEST_PEER_CERT_CHAIN)) || \
  236. defined(HAVE_SESSION_TICKET) || (defined(OPENSSL_EXTRA) && \
  237. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)) || \
  238. defined(WOLFSSL_TEST_STATIC_BUILD) || defined(WOLFSSL_DTLS) || \
  239. defined(HAVE_ECH) || defined(HAVE_EX_DATA) || !defined(NO_SESSION_CACHE) \
  240. || !defined(WOLFSSL_NO_TLS12) || defined(WOLFSSL_TLS13)
  241. /* for testing SSL_get_peer_cert_chain, or SESSION_TICKET_HINT_DEFAULT,
  242. * for setting authKeyIdSrc in WOLFSSL_X509, or testing DTLS sequence
  243. * number tracking */
  244. #include "wolfssl/internal.h"
  245. #endif
  246. /* force enable test buffers */
  247. #ifndef USE_CERT_BUFFERS_2048
  248. #define USE_CERT_BUFFERS_2048
  249. #endif
  250. #ifndef USE_CERT_BUFFERS_256
  251. #define USE_CERT_BUFFERS_256
  252. #endif
  253. #include <wolfssl/certs_test.h>
  254. /* include misc.c here regardless of NO_INLINE, because misc.c implementations
  255. * have default (hidden) visibility, and in the absence of visibility, it's
  256. * benign to mask out the library implementation.
  257. */
  258. #define WOLFSSL_MISC_INCLUDED
  259. #include <wolfcrypt/src/misc.c>
  260. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  261. !defined(NO_RSA) && !defined(SINGLE_THREADED) && \
  262. !defined(NO_WOLFSSL_SERVER) && !defined(NO_WOLFSSL_CLIENT)
  263. #define HAVE_IO_TESTS_DEPENDENCIES
  264. #endif
  265. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  266. !defined(NO_WOLFSSL_SERVER) && !defined(NO_WOLFSSL_CLIENT) && \
  267. !defined(WOLFSSL_TIRTOS)
  268. #define HAVE_SSL_MEMIO_TESTS_DEPENDENCIES
  269. #endif
  270. #if !defined(NO_RSA) && !defined(NO_SHA) && !defined(NO_FILESYSTEM) && \
  271. !defined(NO_CERTS) && (!defined(NO_WOLFSSL_CLIENT) || \
  272. !defined(WOLFSSL_NO_CLIENT_AUTH))
  273. #define HAVE_CERT_CHAIN_VALIDATION
  274. #endif
  275. #ifndef WOLFSSL_HAVE_ECC_KEY_GET_PRIV
  276. /* FIPS build has replaced ecc.h. */
  277. #define wc_ecc_key_get_priv(key) (&((key)->k))
  278. #define WOLFSSL_HAVE_ECC_KEY_GET_PRIV
  279. #endif
  280. #if defined(WOLFSSL_STATIC_MEMORY) && !defined(WOLFCRYPT_ONLY)
  281. #if (defined(HAVE_ECC) && !defined(ALT_ECC_SIZE)) || defined(SESSION_CERTS)
  282. #ifdef OPENSSL_EXTRA
  283. #define TEST_TLS_STATIC_MEMSZ (400000)
  284. #else
  285. #define TEST_TLS_STATIC_MEMSZ (320000)
  286. #endif
  287. #else
  288. #define TEST_TLS_STATIC_MEMSZ (80000)
  289. #endif
  290. #endif
  291. #ifdef HAVE_ECC
  292. #ifndef ECC_ASN963_MAX_BUF_SZ
  293. #define ECC_ASN963_MAX_BUF_SZ 133
  294. #endif
  295. #ifndef ECC_PRIV_KEY_BUF
  296. #define ECC_PRIV_KEY_BUF 66 /* For non user defined curves. */
  297. #endif
  298. /* ecc key sizes: 14, 16, 20, 24, 28, 30, 32, 40, 48, 64 */
  299. /* logic to choose right key ECC size */
  300. #if (defined(HAVE_ECC112) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 112
  301. #define KEY14 14
  302. #else
  303. #define KEY14 32
  304. #endif
  305. #if (defined(HAVE_ECC128) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 128
  306. #define KEY16 16
  307. #else
  308. #define KEY16 32
  309. #endif
  310. #if (defined(HAVE_ECC160) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 160
  311. #define KEY20 20
  312. #else
  313. #define KEY20 32
  314. #endif
  315. #if (defined(HAVE_ECC192) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 192
  316. #define KEY24 24
  317. #else
  318. #define KEY24 32
  319. #endif
  320. #if defined(HAVE_ECC224) || defined(HAVE_ALL_CURVES)
  321. #define KEY28 28
  322. #else
  323. #define KEY28 32
  324. #endif
  325. #if defined(HAVE_ECC239) || defined(HAVE_ALL_CURVES)
  326. #define KEY30 30
  327. #else
  328. #define KEY30 32
  329. #endif
  330. #define KEY32 32
  331. #if defined(HAVE_ECC320) || defined(HAVE_ALL_CURVES)
  332. #define KEY40 40
  333. #else
  334. #define KEY40 32
  335. #endif
  336. #if defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)
  337. #define KEY48 48
  338. #else
  339. #define KEY48 32
  340. #endif
  341. #if defined(HAVE_ECC512) || defined(HAVE_ALL_CURVES)
  342. #define KEY64 64
  343. #else
  344. #define KEY64 32
  345. #endif
  346. #if !defined(HAVE_COMP_KEY)
  347. #if !defined(NOCOMP)
  348. #define NOCOMP 0
  349. #endif
  350. #else
  351. #if !defined(COMP)
  352. #define COMP 1
  353. #endif
  354. #endif
  355. #if !defined(DER_SZ)
  356. #define DER_SZ(ks) ((ks) * 2 + 1)
  357. #endif
  358. #endif /* HAVE_ECC */
  359. #ifndef NO_DSA
  360. #ifndef DSA_SIG_SIZE
  361. #define DSA_SIG_SIZE 40
  362. #endif
  363. #ifndef MAX_DSA_PARAM_SIZE
  364. #define MAX_DSA_PARAM_SIZE 256
  365. #endif
  366. #endif
  367. #ifndef NO_RSA
  368. #define GEN_BUF 294
  369. #endif
  370. #ifndef ONEK_BUF
  371. #define ONEK_BUF 1024
  372. #endif
  373. #ifndef TWOK_BUF
  374. #define TWOK_BUF 2048
  375. #endif
  376. #ifndef FOURK_BUF
  377. #define FOURK_BUF 4096
  378. #endif
  379. #ifndef HEAP_HINT
  380. #define HEAP_HINT NULL
  381. #endif
  382. typedef struct testVector {
  383. const char* input;
  384. const char* output;
  385. size_t inLen;
  386. size_t outLen;
  387. } testVector;
  388. #if defined(HAVE_PKCS7)
  389. typedef struct {
  390. const byte* content;
  391. word32 contentSz;
  392. int contentOID;
  393. int encryptOID;
  394. int keyWrapOID;
  395. int keyAgreeOID;
  396. byte* cert;
  397. size_t certSz;
  398. byte* privateKey;
  399. word32 privateKeySz;
  400. } pkcs7EnvelopedVector;
  401. #ifndef NO_PKCS7_ENCRYPTED_DATA
  402. typedef struct {
  403. const byte* content;
  404. word32 contentSz;
  405. int contentOID;
  406. int encryptOID;
  407. byte* encryptionKey;
  408. word32 encryptionKeySz;
  409. } pkcs7EncryptedVector;
  410. #endif
  411. #endif /* HAVE_PKCS7 */
  412. typedef int (*ctx_cb)(WOLFSSL_CTX* ctx);
  413. typedef int (*ssl_cb)(WOLFSSL* ssl);
  414. typedef int (*test_cbType)(WOLFSSL_CTX *ctx, WOLFSSL *ssl);
  415. typedef int (*hs_cb)(WOLFSSL_CTX **ctx, WOLFSSL **ssl);
  416. typedef struct test_ssl_cbf {
  417. method_provider method;
  418. ctx_cb ctx_ready;
  419. ssl_cb ssl_ready;
  420. ssl_cb on_result;
  421. ctx_cb on_ctx_cleanup;
  422. ssl_cb on_cleanup;
  423. hs_cb on_handshake;
  424. WOLFSSL_CTX* ctx;
  425. const char* caPemFile;
  426. const char* certPemFile;
  427. const char* keyPemFile;
  428. const char* crlPemFile;
  429. #ifdef WOLFSSL_STATIC_MEMORY
  430. byte* mem;
  431. word32 memSz;
  432. wolfSSL_method_func method_ex;
  433. #endif
  434. int devId;
  435. int return_code;
  436. int last_err;
  437. unsigned char isSharedCtx:1;
  438. unsigned char loadToSSL:1;
  439. unsigned char ticNoInit:1;
  440. unsigned char doUdp:1;
  441. } test_ssl_cbf;
  442. #define TEST_SSL_MEMIO_BUF_SZ (64 * 1024)
  443. typedef struct test_ssl_memio_ctx {
  444. WOLFSSL_CTX* s_ctx;
  445. WOLFSSL_CTX* c_ctx;
  446. WOLFSSL* s_ssl;
  447. WOLFSSL* c_ssl;
  448. const char* c_ciphers;
  449. const char* s_ciphers;
  450. char* c_msg;
  451. int c_msglen;
  452. char* s_msg;
  453. int s_msglen;
  454. test_ssl_cbf s_cb;
  455. test_ssl_cbf c_cb;
  456. byte c_buff[TEST_SSL_MEMIO_BUF_SZ];
  457. int c_len;
  458. byte s_buff[TEST_SSL_MEMIO_BUF_SZ];
  459. int s_len;
  460. } test_ssl_memio_ctx;
  461. int test_wolfSSL_client_server_nofail_memio(test_ssl_cbf* client_cb,
  462. test_ssl_cbf* server_cb, test_cbType client_on_handshake);
  463. #ifdef WOLFSSL_DUMP_MEMIO_STREAM
  464. const char* currentTestName;
  465. char tmpDirName[16];
  466. int tmpDirNameSet = 0;
  467. #endif
  468. /*----------------------------------------------------------------------------*
  469. | Constants
  470. *----------------------------------------------------------------------------*/
  471. /* Returns the result based on whether check is true.
  472. *
  473. * @param [in] check Condition for success.
  474. * @return When condition is true: TEST_SUCCESS.
  475. * @return When condition is false: TEST_FAIL.
  476. */
  477. #ifdef DEBUG_WOLFSSL_VERBOSE
  478. #define XSTRINGIFY(s) STRINGIFY(s)
  479. #define STRINGIFY(s) #s
  480. #define TEST_RES_CHECK(check) ({ \
  481. int _ret = (check) ? TEST_SUCCESS : TEST_FAIL; \
  482. if (_ret == TEST_FAIL) { \
  483. fprintf(stderr, " check \"%s\" at %d ", \
  484. XSTRINGIFY(check), __LINE__); \
  485. } \
  486. _ret; })
  487. #else
  488. #define TEST_RES_CHECK(check) \
  489. ((check) ? TEST_SUCCESS : TEST_FAIL)
  490. #endif /* DEBUG_WOLFSSL_VERBOSE */
  491. #define TEST_STRING "Everyone gets Friday off."
  492. #define TEST_STRING_SZ 25
  493. #ifndef NO_RSA
  494. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  495. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4)) && \
  496. (defined(RSA_MIN_SIZE) && (RSA_MIN_SIZE <= 1024))
  497. #define TEST_RSA_BITS 1024
  498. #else
  499. #define TEST_RSA_BITS 2048
  500. #endif
  501. #define TEST_RSA_BYTES (TEST_RSA_BITS/8)
  502. #endif /* !NO_RSA */
  503. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  504. (!defined(NO_WOLFSSL_SERVER) || !defined(NO_WOLFSSL_CLIENT))
  505. static const char* bogusFile =
  506. #ifdef _WIN32
  507. "NUL"
  508. #else
  509. "/dev/null"
  510. #endif
  511. ;
  512. #endif /* !NO_FILESYSTEM && !NO_CERTS && (!NO_WOLFSSL_SERVER || !NO_WOLFSSL_CLIENT) */
  513. enum {
  514. TESTING_RSA = 1,
  515. TESTING_ECC = 2
  516. };
  517. #ifdef WOLFSSL_QNX_CAAM
  518. #include <wolfssl/wolfcrypt/port/caam/wolfcaam.h>
  519. static int testDevId = WOLFSSL_CAAM_DEVID;
  520. #else
  521. static int testDevId = INVALID_DEVID;
  522. #endif
  523. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  524. !defined(NO_WOLFSSL_SERVER) && !defined(NO_WOLFSSL_CLIENT)
  525. /* This set of memio functions allows for more fine tuned control of the TLS
  526. * connection operations. For new tests, try to use ssl_memio first. */
  527. /* To dump the memory in gdb use
  528. * dump memory client.bin test_ctx.c_buff test_ctx.c_buff+test_ctx.c_len
  529. * dump memory server.bin test_ctx.s_buff test_ctx.s_buff+test_ctx.s_len
  530. * This can be imported into Wireshark by transforming the file with
  531. * od -Ax -tx1 -v client.bin > client.bin.hex
  532. * od -Ax -tx1 -v server.bin > server.bin.hex
  533. * And then loading test_output.dump.hex into Wireshark using the
  534. * "Import from Hex Dump..." option ion and selecting the TCP
  535. * encapsulation option.
  536. */
  537. #define HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES
  538. static WC_INLINE int test_memio_write_cb(WOLFSSL *ssl, char *data, int sz,
  539. void *ctx)
  540. {
  541. struct test_memio_ctx *test_ctx;
  542. byte *buf;
  543. int *len;
  544. test_ctx = (struct test_memio_ctx*)ctx;
  545. if (wolfSSL_GetSide(ssl) == WOLFSSL_SERVER_END) {
  546. buf = test_ctx->c_buff;
  547. len = &test_ctx->c_len;
  548. }
  549. else {
  550. buf = test_ctx->s_buff;
  551. len = &test_ctx->s_len;
  552. }
  553. if ((unsigned)(*len + sz) > TEST_MEMIO_BUF_SZ)
  554. return WOLFSSL_CBIO_ERR_WANT_WRITE;
  555. #ifdef WOLFSSL_DUMP_MEMIO_STREAM
  556. {
  557. char dump_file_name[64];
  558. WOLFSSL_BIO *dump_file;
  559. sprintf(dump_file_name, "%s/%s.dump", tmpDirName, currentTestName);
  560. dump_file = wolfSSL_BIO_new_file(dump_file_name, "a");
  561. if (dump_file != NULL) {
  562. (void)wolfSSL_BIO_write(dump_file, data, sz);
  563. wolfSSL_BIO_free(dump_file);
  564. }
  565. }
  566. #endif
  567. XMEMCPY(buf + *len, data, (size_t)sz);
  568. *len += sz;
  569. return sz;
  570. }
  571. static WC_INLINE int test_memio_read_cb(WOLFSSL *ssl, char *data, int sz,
  572. void *ctx)
  573. {
  574. struct test_memio_ctx *test_ctx;
  575. int read_sz;
  576. byte *buf;
  577. int *len;
  578. test_ctx = (struct test_memio_ctx*)ctx;
  579. if (wolfSSL_GetSide(ssl) == WOLFSSL_SERVER_END) {
  580. buf = test_ctx->s_buff;
  581. len = &test_ctx->s_len;
  582. }
  583. else {
  584. buf = test_ctx->c_buff;
  585. len = &test_ctx->c_len;
  586. }
  587. if (*len == 0)
  588. return WOLFSSL_CBIO_ERR_WANT_READ;
  589. read_sz = sz < *len ? sz : *len;
  590. XMEMCPY(data, buf, (size_t)read_sz);
  591. XMEMMOVE(buf, buf + read_sz,(size_t) (*len - read_sz));
  592. *len -= read_sz;
  593. return read_sz;
  594. }
  595. int test_memio_do_handshake(WOLFSSL *ssl_c, WOLFSSL *ssl_s,
  596. int max_rounds, int *rounds)
  597. {
  598. byte handshake_complete = 0, hs_c = 0, hs_s = 0;
  599. int ret, err;
  600. if (rounds != NULL)
  601. *rounds = 0;
  602. while (!handshake_complete && max_rounds > 0) {
  603. if (!hs_c) {
  604. wolfSSL_SetLoggingPrefix("client");
  605. ret = wolfSSL_connect(ssl_c);
  606. wolfSSL_SetLoggingPrefix(NULL);
  607. if (ret == WOLFSSL_SUCCESS) {
  608. hs_c = 1;
  609. }
  610. else {
  611. err = wolfSSL_get_error(ssl_c, ret);
  612. if (err != WOLFSSL_ERROR_WANT_READ &&
  613. err != WOLFSSL_ERROR_WANT_WRITE)
  614. return -1;
  615. }
  616. }
  617. if (!hs_s) {
  618. wolfSSL_SetLoggingPrefix("server");
  619. ret = wolfSSL_accept(ssl_s);
  620. wolfSSL_SetLoggingPrefix(NULL);
  621. if (ret == WOLFSSL_SUCCESS) {
  622. hs_s = 1;
  623. }
  624. else {
  625. err = wolfSSL_get_error(ssl_s, ret);
  626. if (err != WOLFSSL_ERROR_WANT_READ &&
  627. err != WOLFSSL_ERROR_WANT_WRITE)
  628. return -1;
  629. }
  630. }
  631. handshake_complete = hs_c && hs_s;
  632. max_rounds--;
  633. if (rounds != NULL)
  634. *rounds = *rounds + 1;
  635. }
  636. if (!handshake_complete)
  637. return -1;
  638. return 0;
  639. }
  640. int test_memio_setup_ex(struct test_memio_ctx *ctx,
  641. WOLFSSL_CTX **ctx_c, WOLFSSL_CTX **ctx_s, WOLFSSL **ssl_c, WOLFSSL **ssl_s,
  642. method_provider method_c, method_provider method_s,
  643. byte *caCert, int caCertSz, byte *serverCert, int serverCertSz,
  644. byte *serverKey, int serverKeySz)
  645. {
  646. int ret;
  647. (void)caCert;
  648. (void)caCertSz;
  649. (void)serverCert;
  650. (void)serverCertSz;
  651. (void)serverKey;
  652. (void)serverKeySz;
  653. if (ctx_c != NULL && *ctx_c == NULL) {
  654. *ctx_c = wolfSSL_CTX_new(method_c());
  655. if (*ctx_c == NULL)
  656. return -1;
  657. #ifndef NO_CERTS
  658. if (caCert == NULL) {
  659. ret = wolfSSL_CTX_load_verify_locations(*ctx_c, caCertFile, 0);
  660. }
  661. else {
  662. ret = wolfSSL_CTX_load_verify_buffer(*ctx_c, caCert, (long)caCertSz,
  663. WOLFSSL_FILETYPE_ASN1);
  664. }
  665. if (ret != WOLFSSL_SUCCESS)
  666. return -1;
  667. #endif /* NO_CERTS */
  668. wolfSSL_SetIORecv(*ctx_c, test_memio_read_cb);
  669. wolfSSL_SetIOSend(*ctx_c, test_memio_write_cb);
  670. if (ctx->c_ciphers != NULL) {
  671. ret = wolfSSL_CTX_set_cipher_list(*ctx_c, ctx->c_ciphers);
  672. if (ret != WOLFSSL_SUCCESS)
  673. return -1;
  674. }
  675. }
  676. if (ctx_s != NULL && *ctx_s == NULL) {
  677. *ctx_s = wolfSSL_CTX_new(method_s());
  678. if (*ctx_s == NULL)
  679. return -1;
  680. #ifndef NO_CERTS
  681. if (serverKey == NULL) {
  682. ret = wolfSSL_CTX_use_PrivateKey_file(*ctx_s, svrKeyFile,
  683. WOLFSSL_FILETYPE_PEM);
  684. }
  685. else {
  686. ret = wolfSSL_CTX_use_PrivateKey_buffer(*ctx_s, serverKey,
  687. (long)serverKeySz, WOLFSSL_FILETYPE_ASN1);
  688. }
  689. if (ret != WOLFSSL_SUCCESS)
  690. return- -1;
  691. if (serverCert == NULL) {
  692. ret = wolfSSL_CTX_use_certificate_file(*ctx_s, svrCertFile,
  693. WOLFSSL_FILETYPE_PEM);
  694. }
  695. else {
  696. ret = wolfSSL_CTX_use_certificate_chain_buffer_format(*ctx_s,
  697. serverCert, (long)serverCertSz, WOLFSSL_FILETYPE_ASN1);
  698. }
  699. if (ret != WOLFSSL_SUCCESS)
  700. return -1;
  701. #endif /* NO_CERTS */
  702. wolfSSL_SetIORecv(*ctx_s, test_memio_read_cb);
  703. wolfSSL_SetIOSend(*ctx_s, test_memio_write_cb);
  704. if (ctx->s_ciphers != NULL) {
  705. ret = wolfSSL_CTX_set_cipher_list(*ctx_s, ctx->s_ciphers);
  706. if (ret != WOLFSSL_SUCCESS)
  707. return -1;
  708. }
  709. }
  710. if (ctx_c != NULL && ssl_c != NULL) {
  711. *ssl_c = wolfSSL_new(*ctx_c);
  712. if (*ssl_c == NULL)
  713. return -1;
  714. wolfSSL_SetIOWriteCtx(*ssl_c, ctx);
  715. wolfSSL_SetIOReadCtx(*ssl_c, ctx);
  716. }
  717. if (ctx_s != NULL && ssl_s != NULL) {
  718. *ssl_s = wolfSSL_new(*ctx_s);
  719. if (*ssl_s == NULL)
  720. return -1;
  721. wolfSSL_SetIOWriteCtx(*ssl_s, ctx);
  722. wolfSSL_SetIOReadCtx(*ssl_s, ctx);
  723. #if !defined(NO_DH)
  724. SetDH(*ssl_s);
  725. #endif
  726. }
  727. return 0;
  728. }
  729. int test_memio_setup(struct test_memio_ctx *ctx,
  730. WOLFSSL_CTX **ctx_c, WOLFSSL_CTX **ctx_s, WOLFSSL **ssl_c, WOLFSSL **ssl_s,
  731. method_provider method_c, method_provider method_s)
  732. {
  733. return test_memio_setup_ex(ctx, ctx_c, ctx_s, ssl_c, ssl_s, method_c,
  734. method_s, NULL, 0, NULL, 0, NULL, 0);
  735. }
  736. #endif
  737. /*----------------------------------------------------------------------------*
  738. | BIO with fixed read/write size
  739. *----------------------------------------------------------------------------*/
  740. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  741. static int wolfssl_bio_s_fixed_mem_write(WOLFSSL_BIO* bio, const char* data,
  742. int len)
  743. {
  744. if ((bio == NULL) || (bio->ptr.mem_buf_data == NULL) || (data == NULL)) {
  745. len = 0;
  746. }
  747. else {
  748. if (bio->wrSz - bio->wrIdx < len) {
  749. len = bio->wrSz - bio->wrIdx;
  750. }
  751. XMEMCPY(bio->ptr.mem_buf_data + bio->wrIdx, data, len);
  752. bio->wrIdx += len;
  753. }
  754. return len;
  755. }
  756. static int wolfssl_bio_s_fixed_mem_read(WOLFSSL_BIO* bio, char* data, int len)
  757. {
  758. if ((bio == NULL) || (bio->ptr.mem_buf_data == NULL) || (data == NULL)) {
  759. len = 0;
  760. }
  761. else {
  762. if (bio->wrSz - bio->rdIdx < len) {
  763. len = bio->wrSz - bio->rdIdx;
  764. }
  765. XMEMCPY(data, bio->ptr.mem_buf_data + bio->rdIdx, len);
  766. bio->rdIdx += len;
  767. }
  768. return len;
  769. }
  770. static WOLFSSL_BIO_METHOD* wolfSSL_BIO_s_fixed_mem(void)
  771. {
  772. static WOLFSSL_BIO_METHOD meth;
  773. meth.type = WOLFSSL_BIO_BIO;
  774. XMEMCPY(meth.name, "Fixed Memory Size", 18);
  775. meth.writeCb = wolfssl_bio_s_fixed_mem_write;
  776. meth.readCb = wolfssl_bio_s_fixed_mem_read;
  777. return &meth;
  778. }
  779. #endif
  780. /*----------------------------------------------------------------------------*
  781. | Setup
  782. *----------------------------------------------------------------------------*/
  783. static int test_wolfSSL_Init(void)
  784. {
  785. EXPECT_DECLS;
  786. ExpectIntEQ(wolfSSL_Init(), WOLFSSL_SUCCESS);
  787. return EXPECT_RESULT();
  788. }
  789. static int test_wolfSSL_Cleanup(void)
  790. {
  791. EXPECT_DECLS;
  792. ExpectIntEQ(wolfSSL_Cleanup(), WOLFSSL_SUCCESS);
  793. return EXPECT_RESULT();
  794. }
  795. /* Initialize the wolfCrypt state.
  796. * POST: 0 success.
  797. */
  798. static int test_wolfCrypt_Init(void)
  799. {
  800. EXPECT_DECLS;
  801. ExpectIntEQ(wolfCrypt_Init(), 0);
  802. return EXPECT_RESULT();
  803. } /* END test_wolfCrypt_Init */
  804. static int test_wolfCrypt_Cleanup(void)
  805. {
  806. EXPECT_DECLS;
  807. ExpectIntEQ(wolfCrypt_Cleanup(), 0);
  808. return EXPECT_RESULT();
  809. }
  810. #ifdef WOLFSSL_STATIC_MEMORY
  811. #define TEST_LSM_STATIC_SIZE 440000
  812. /* Create new bucket list, using the default list, adding
  813. * one dang large buffer size. */
  814. #define TEST_LSM_DEF_BUCKETS (WOLFMEM_DEF_BUCKETS+1)
  815. #define TEST_LSM_BUCKETS WOLFMEM_BUCKETS,(LARGEST_MEM_BUCKET*2)
  816. #define TEST_LSM_DIST WOLFMEM_DIST,1
  817. #endif
  818. static int test_wc_LoadStaticMemory_ex(void)
  819. {
  820. EXPECT_DECLS;
  821. #ifdef WOLFSSL_STATIC_MEMORY
  822. byte staticMemory[TEST_LSM_STATIC_SIZE];
  823. word32 sizeList[TEST_LSM_DEF_BUCKETS] = { TEST_LSM_BUCKETS };
  824. word32 distList[TEST_LSM_DEF_BUCKETS] = { TEST_LSM_DIST };
  825. WOLFSSL_HEAP_HINT* heap;
  826. /* For this test, the size and dist lists will be the ones configured
  827. * for the build, or default. The value of WOLFMEM_DEF_BUCKETS is 9,
  828. * so these lists are 10 long. For most tests, the value of
  829. * WOLFMEM_DEF_BUCKETS is used. There's a test case where one is added
  830. * to that, to make sure the list size is larger than
  831. * WOLFMEM_MAX_BUCKETS. */
  832. /* Pass in zero everything. */
  833. ExpectIntEQ(wc_LoadStaticMemory_ex(NULL, 0, NULL, NULL, NULL, 0, 0, 0),
  834. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  835. /* Set the heap pointer to NULL. */
  836. ExpectIntEQ(wc_LoadStaticMemory_ex(NULL,
  837. WOLFMEM_DEF_BUCKETS, sizeList, distList,
  838. staticMemory, (word32)sizeof(staticMemory),
  839. 0, 1),
  840. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  841. /* Set other pointer values to NULL one at a time. */
  842. heap = NULL;
  843. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  844. WOLFMEM_DEF_BUCKETS, NULL, distList,
  845. staticMemory, (word32)sizeof(staticMemory),
  846. 0, 1),
  847. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  848. heap = NULL;
  849. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  850. WOLFMEM_DEF_BUCKETS, sizeList, NULL,
  851. staticMemory, (word32)sizeof(staticMemory),
  852. 0, 1),
  853. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  854. heap = NULL;
  855. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  856. WOLFMEM_DEF_BUCKETS, sizeList, distList,
  857. NULL, (word32)sizeof(staticMemory),
  858. 0, 1),
  859. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  860. /* Set the size of the static buffer to 0. */
  861. heap = NULL;
  862. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  863. WOLFMEM_DEF_BUCKETS, sizeList, distList,
  864. staticMemory, 0,
  865. 0, 1),
  866. WC_NO_ERR_TRACE(BUFFER_E));
  867. /* Set the size of the static buffer to one less than minimum allowed. */
  868. heap = NULL;
  869. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  870. WOLFMEM_DEF_BUCKETS, sizeList, distList,
  871. staticMemory,
  872. (word32)(sizeof(WOLFSSL_HEAP) + sizeof(WOLFSSL_HEAP_HINT)) - 1,
  873. 0, 1),
  874. WC_NO_ERR_TRACE(BUFFER_E));
  875. /* Set the size of the static buffer to exactly the minimum size. */
  876. heap = NULL;
  877. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  878. WOLFMEM_DEF_BUCKETS, sizeList, distList,
  879. staticMemory,
  880. (word32)(sizeof(WOLFSSL_HEAP) + sizeof(WOLFSSL_HEAP_HINT)),
  881. 0, 1),
  882. 0);
  883. wc_UnloadStaticMemory(heap);
  884. /* Use more buckets than able. Success case. */
  885. heap = NULL;
  886. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  887. WOLFMEM_DEF_BUCKETS*2, sizeList, distList,
  888. staticMemory, (word32)sizeof(staticMemory),
  889. 0, 1),
  890. 0);
  891. wc_UnloadStaticMemory(heap);
  892. /* Success case. */
  893. heap = NULL;
  894. ExpectIntEQ(wc_LoadStaticMemory_ex(&heap,
  895. WOLFMEM_DEF_BUCKETS, sizeList, distList,
  896. staticMemory, (word32)sizeof(staticMemory),
  897. 0, 1),
  898. 0);
  899. wc_UnloadStaticMemory(heap);
  900. #endif /* WOLFSSL_STATIC_MEMORY */
  901. return EXPECT_RESULT();
  902. }
  903. /*----------------------------------------------------------------------------*
  904. | Platform dependent function test
  905. *----------------------------------------------------------------------------*/
  906. static int test_fileAccess(void)
  907. {
  908. EXPECT_DECLS;
  909. #if defined(WOLFSSL_TEST_PLATFORMDEPEND) && !defined(NO_FILESYSTEM)
  910. const char *fname[] = {
  911. svrCertFile, svrKeyFile, caCertFile,
  912. eccCertFile, eccKeyFile, eccRsaCertFile,
  913. cliCertFile, cliCertDerFile, cliKeyFile,
  914. dhParamFile,
  915. cliEccKeyFile, cliEccCertFile, caEccCertFile, edCertFile, edKeyFile,
  916. cliEdCertFile, cliEdKeyFile, caEdCertFile,
  917. NULL
  918. };
  919. const char derfile[] = "./certs/server-cert.der";
  920. XFILE f = XBADFILE;
  921. size_t sz;
  922. byte *buff = NULL;
  923. int i;
  924. ExpectTrue(XFOPEN("badfilename", "rb") == XBADFILE);
  925. for (i=0; EXPECT_SUCCESS() && fname[i] != NULL ; i++) {
  926. ExpectTrue((f = XFOPEN(fname[i], "rb")) != XBADFILE);
  927. XFCLOSE(f);
  928. }
  929. ExpectTrue((f = XFOPEN(derfile, "rb")) != XBADFILE);
  930. ExpectTrue(XFSEEK(f, 0, XSEEK_END) == 0);
  931. ExpectIntGE(sz = (size_t) XFTELL(f), sizeof_server_cert_der_2048);
  932. ExpectTrue(XFSEEK(f, 0, XSEEK_SET) == 0);
  933. ExpectTrue((buff = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE)) != NULL);
  934. ExpectTrue(XFREAD(buff, 1, sz, f) == sz);
  935. ExpectIntEQ(XMEMCMP(server_cert_der_2048, buff, sz), 0);
  936. XFREE(buff, NULL, DYNAMIC_TYPE_FILE);
  937. XFCLOSE(f);
  938. #endif
  939. return EXPECT_RESULT();
  940. }
  941. /*----------------------------------------------------------------------------*
  942. | Method Allocators
  943. *----------------------------------------------------------------------------*/
  944. static int test_wolfSSL_Method_Allocators(void)
  945. {
  946. EXPECT_DECLS;
  947. #define TEST_METHOD_ALLOCATOR(allocator, condition) \
  948. do { \
  949. WOLFSSL_METHOD *method = NULL; \
  950. condition(method = allocator()); \
  951. XFREE(method, 0, DYNAMIC_TYPE_METHOD); \
  952. } while (0)
  953. #define TEST_VALID_METHOD_ALLOCATOR(a) \
  954. TEST_METHOD_ALLOCATOR(a, ExpectNotNull)
  955. #define TEST_INVALID_METHOD_ALLOCATOR(a) \
  956. TEST_METHOD_ALLOCATOR(a, ExpectNull)
  957. #ifndef NO_OLD_TLS
  958. #ifdef WOLFSSL_ALLOW_SSLV3
  959. #ifndef NO_WOLFSSL_SERVER
  960. TEST_VALID_METHOD_ALLOCATOR(wolfSSLv3_server_method);
  961. #endif
  962. #ifndef NO_WOLFSSL_CLIENT
  963. TEST_VALID_METHOD_ALLOCATOR(wolfSSLv3_client_method);
  964. #endif
  965. #endif
  966. #ifdef WOLFSSL_ALLOW_TLSV10
  967. #ifndef NO_WOLFSSL_SERVER
  968. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_server_method);
  969. #endif
  970. #ifndef NO_WOLFSSL_CLIENT
  971. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_client_method);
  972. #endif
  973. #endif
  974. #ifndef NO_WOLFSSL_SERVER
  975. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_1_server_method);
  976. #endif
  977. #ifndef NO_WOLFSSL_CLIENT
  978. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_1_client_method);
  979. #endif
  980. #endif /* !NO_OLD_TLS */
  981. #ifndef WOLFSSL_NO_TLS12
  982. #ifndef NO_WOLFSSL_SERVER
  983. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_2_server_method);
  984. #endif
  985. #ifndef NO_WOLFSSL_CLIENT
  986. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_2_client_method);
  987. #endif
  988. #endif /* !WOLFSSL_NO_TLS12 */
  989. #ifdef WOLFSSL_TLS13
  990. #ifndef NO_WOLFSSL_SERVER
  991. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_3_server_method);
  992. #endif
  993. #ifndef NO_WOLFSSL_CLIENT
  994. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_3_client_method);
  995. #endif
  996. #endif /* WOLFSSL_TLS13 */
  997. #ifndef NO_WOLFSSL_SERVER
  998. TEST_VALID_METHOD_ALLOCATOR(wolfSSLv23_server_method);
  999. #endif
  1000. #ifndef NO_WOLFSSL_CLIENT
  1001. TEST_VALID_METHOD_ALLOCATOR(wolfSSLv23_client_method);
  1002. #endif
  1003. #ifdef WOLFSSL_DTLS
  1004. #ifndef NO_OLD_TLS
  1005. #ifndef NO_WOLFSSL_SERVER
  1006. TEST_VALID_METHOD_ALLOCATOR(wolfDTLSv1_server_method);
  1007. #endif
  1008. #ifndef NO_WOLFSSL_CLIENT
  1009. TEST_VALID_METHOD_ALLOCATOR(wolfDTLSv1_client_method);
  1010. #endif
  1011. #endif
  1012. #ifndef WOLFSSL_NO_TLS12
  1013. #ifndef NO_WOLFSSL_SERVER
  1014. TEST_VALID_METHOD_ALLOCATOR(wolfDTLSv1_2_server_method);
  1015. #endif
  1016. #ifndef NO_WOLFSSL_CLIENT
  1017. TEST_VALID_METHOD_ALLOCATOR(wolfDTLSv1_2_client_method);
  1018. #endif
  1019. #endif
  1020. #endif /* WOLFSSL_DTLS */
  1021. #if !defined(NO_OLD_TLS) && defined(OPENSSL_EXTRA)
  1022. /* Stubs */
  1023. #ifndef NO_WOLFSSL_SERVER
  1024. TEST_INVALID_METHOD_ALLOCATOR(wolfSSLv2_server_method);
  1025. #endif
  1026. #ifndef NO_WOLFSSL_CLIENT
  1027. TEST_INVALID_METHOD_ALLOCATOR(wolfSSLv2_client_method);
  1028. #endif
  1029. #endif
  1030. /* Test Either Method (client or server) */
  1031. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  1032. TEST_VALID_METHOD_ALLOCATOR(wolfSSLv23_method);
  1033. #ifndef NO_OLD_TLS
  1034. #ifdef WOLFSSL_ALLOW_TLSV10
  1035. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_method);
  1036. #endif
  1037. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_1_method);
  1038. #endif /* !NO_OLD_TLS */
  1039. #ifndef WOLFSSL_NO_TLS12
  1040. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_2_method);
  1041. #endif /* !WOLFSSL_NO_TLS12 */
  1042. #ifdef WOLFSSL_TLS13
  1043. TEST_VALID_METHOD_ALLOCATOR(wolfTLSv1_3_method);
  1044. #endif /* WOLFSSL_TLS13 */
  1045. #ifdef WOLFSSL_DTLS
  1046. TEST_VALID_METHOD_ALLOCATOR(wolfDTLS_method);
  1047. #ifndef NO_OLD_TLS
  1048. TEST_VALID_METHOD_ALLOCATOR(wolfDTLSv1_method);
  1049. #endif /* !NO_OLD_TLS */
  1050. #ifndef WOLFSSL_NO_TLS12
  1051. TEST_VALID_METHOD_ALLOCATOR(wolfDTLSv1_2_method);
  1052. #endif /* !WOLFSSL_NO_TLS12 */
  1053. #ifdef WOLFSSL_DTLS13
  1054. TEST_VALID_METHOD_ALLOCATOR(wolfDTLSv1_3_method);
  1055. #endif /* WOLFSSL_DTLS13 */
  1056. #endif /* WOLFSSL_DTLS */
  1057. #endif /* OPENSSL_EXTRA || WOLFSSL_EITHER_SIDE */
  1058. return EXPECT_RESULT();
  1059. }
  1060. #if defined(WOLFSSL_DUAL_ALG_CERTS) && !defined(NO_FILESYSTEM)
  1061. /*----------------------------------------------------------------------------*
  1062. | Dual algorithm Certificate Tests
  1063. *----------------------------------------------------------------------------*/
  1064. #define LARGE_TEMP_SZ 4096
  1065. /* To better understand this, please see the X9.146 example in wolfssl-examples
  1066. * repo. */
  1067. static int do_dual_alg_root_certgen(byte **out, char *caKeyFile,
  1068. char *sapkiFile, char *altPrivFile)
  1069. {
  1070. EXPECT_DECLS;
  1071. FILE* file = NULL;
  1072. Cert newCert;
  1073. DecodedCert preTBS;
  1074. byte caKeyBuf[LARGE_TEMP_SZ];
  1075. word32 caKeySz = LARGE_TEMP_SZ;
  1076. byte sapkiBuf[LARGE_TEMP_SZ];
  1077. word32 sapkiSz = LARGE_TEMP_SZ;
  1078. byte altPrivBuf[LARGE_TEMP_SZ];
  1079. word32 altPrivSz = LARGE_TEMP_SZ;
  1080. byte altSigAlgBuf[LARGE_TEMP_SZ];
  1081. word32 altSigAlgSz = LARGE_TEMP_SZ;
  1082. byte scratchBuf[LARGE_TEMP_SZ];
  1083. word32 scratchSz = LARGE_TEMP_SZ;
  1084. byte preTbsBuf[LARGE_TEMP_SZ];
  1085. word32 preTbsSz = LARGE_TEMP_SZ;
  1086. byte altSigValBuf[LARGE_TEMP_SZ];
  1087. word32 altSigValSz = LARGE_TEMP_SZ;
  1088. byte *outBuf = NULL;
  1089. word32 outSz = LARGE_TEMP_SZ;
  1090. WC_RNG rng;
  1091. RsaKey caKey;
  1092. ecc_key altCaKey;
  1093. word32 idx = 0;
  1094. XMEMSET(&rng, 0, sizeof(WC_RNG));
  1095. XMEMSET(&caKey, 0, sizeof(RsaKey));
  1096. XMEMSET(&altCaKey, 0, sizeof(ecc_key));
  1097. ExpectNotNull(outBuf = (byte*)XMALLOC(outSz, NULL,
  1098. DYNAMIC_TYPE_TMP_BUFFER));
  1099. ExpectIntEQ(wc_InitRng(&rng), 0);
  1100. XMEMSET(caKeyBuf, 0, caKeySz);
  1101. ExpectNotNull(file = fopen(caKeyFile, "rb"));
  1102. ExpectIntGT(caKeySz = (word32)fread(caKeyBuf, 1, caKeySz, file), 0);
  1103. if (file) {
  1104. fclose(file);
  1105. file = NULL;
  1106. }
  1107. ExpectIntEQ(wc_InitRsaKey_ex(&caKey, NULL, INVALID_DEVID), 0);
  1108. idx = 0;
  1109. ExpectIntEQ(wc_RsaPrivateKeyDecode(caKeyBuf, &idx, &caKey, caKeySz),
  1110. 0);
  1111. XMEMSET(sapkiBuf, 0, sapkiSz);
  1112. ExpectNotNull(file = fopen(sapkiFile, "rb"));
  1113. ExpectIntGT(sapkiSz = (word32)fread(sapkiBuf, 1, sapkiSz, file), 0);
  1114. if (file) {
  1115. fclose(file);
  1116. file = NULL;
  1117. }
  1118. XMEMSET(altPrivBuf, 0, altPrivSz);
  1119. ExpectNotNull(file = fopen(altPrivFile, "rb"));
  1120. ExpectIntGT(altPrivSz = (word32)fread(altPrivBuf, 1, altPrivSz, file), 0);
  1121. if (file) {
  1122. fclose(file);
  1123. file = NULL;
  1124. }
  1125. wc_ecc_init(&altCaKey);
  1126. idx = 0;
  1127. ExpectIntEQ(wc_EccPrivateKeyDecode(altPrivBuf, &idx, &altCaKey,
  1128. (word32)altPrivSz), 0);
  1129. XMEMSET(altSigAlgBuf, 0, altSigAlgSz);
  1130. ExpectIntGT(altSigAlgSz = SetAlgoID(CTC_SHA256wECDSA, altSigAlgBuf,
  1131. oidSigType, 0), 0);
  1132. wc_InitCert(&newCert);
  1133. strncpy(newCert.subject.country, "US", CTC_NAME_SIZE);
  1134. strncpy(newCert.subject.state, "MT", CTC_NAME_SIZE);
  1135. strncpy(newCert.subject.locality, "Bozeman", CTC_NAME_SIZE);
  1136. strncpy(newCert.subject.org, "wolfSSL", CTC_NAME_SIZE);
  1137. strncpy(newCert.subject.unit, "Engineering", CTC_NAME_SIZE);
  1138. strncpy(newCert.subject.commonName, "www.wolfssl.com", CTC_NAME_SIZE);
  1139. strncpy(newCert.subject.email, "root@wolfssl.com", CTC_NAME_SIZE);
  1140. newCert.sigType = CTC_SHA256wRSA;
  1141. newCert.isCA = 1;
  1142. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "1.2.3.4.5",
  1143. (const byte *)"This is NOT a critical extension", 32), 0);
  1144. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.72", sapkiBuf,
  1145. sapkiSz), 0);
  1146. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.73", altSigAlgBuf,
  1147. altSigAlgSz), 0);
  1148. XMEMSET(scratchBuf, 0, scratchSz);
  1149. ExpectIntGT(scratchSz = wc_MakeSelfCert(&newCert, scratchBuf, scratchSz,
  1150. &caKey, &rng), 0);
  1151. wc_InitDecodedCert(&preTBS, scratchBuf, scratchSz, 0);
  1152. ExpectIntEQ(wc_ParseCert(&preTBS, CERT_TYPE, NO_VERIFY, NULL), 0);
  1153. XMEMSET(preTbsBuf, 0, preTbsSz);
  1154. ExpectIntGT(preTbsSz = wc_GeneratePreTBS(&preTBS, preTbsBuf, preTbsSz), 0);
  1155. XMEMSET(altSigValBuf, 0, altSigValSz);
  1156. ExpectIntGT(altSigValSz = wc_MakeSigWithBitStr(altSigValBuf, altSigValSz,
  1157. CTC_SHA256wECDSA, preTbsBuf, preTbsSz, ECC_TYPE, &altCaKey,
  1158. &rng), 0);
  1159. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.74", altSigValBuf,
  1160. altSigValSz), 0);
  1161. /* Finally, generate the new certificate. */
  1162. if (outBuf != NULL) {
  1163. XMEMSET(outBuf, 0, outSz);
  1164. }
  1165. ExpectIntGT(outSz = wc_MakeSelfCert(&newCert, outBuf, outSz, &caKey, &rng),
  1166. 0);
  1167. *out = outBuf;
  1168. wc_FreeRsaKey(&caKey);
  1169. wc_FreeRng(&rng);
  1170. wc_FreeDecodedCert(&preTBS);
  1171. return outSz;
  1172. }
  1173. static int do_dual_alg_server_certgen(byte **out, char *caKeyFile,
  1174. char *sapkiFile, char *altPrivFile,
  1175. char *serverKeyFile,
  1176. byte *caCertBuf, int caCertSz)
  1177. {
  1178. EXPECT_DECLS;
  1179. FILE* file = NULL;
  1180. Cert newCert;
  1181. DecodedCert preTBS;
  1182. byte serverKeyBuf[LARGE_TEMP_SZ];
  1183. word32 serverKeySz = LARGE_TEMP_SZ;
  1184. byte caKeyBuf[LARGE_TEMP_SZ];
  1185. word32 caKeySz = LARGE_TEMP_SZ;
  1186. byte sapkiBuf[LARGE_TEMP_SZ];
  1187. word32 sapkiSz = LARGE_TEMP_SZ;
  1188. byte altPrivBuf[LARGE_TEMP_SZ];
  1189. word32 altPrivSz = LARGE_TEMP_SZ;
  1190. byte altSigAlgBuf[LARGE_TEMP_SZ];
  1191. word32 altSigAlgSz = LARGE_TEMP_SZ;
  1192. byte scratchBuf[LARGE_TEMP_SZ];
  1193. word32 scratchSz = LARGE_TEMP_SZ;
  1194. byte preTbsBuf[LARGE_TEMP_SZ];
  1195. word32 preTbsSz = LARGE_TEMP_SZ;
  1196. byte altSigValBuf[LARGE_TEMP_SZ];
  1197. word32 altSigValSz = LARGE_TEMP_SZ;
  1198. byte *outBuf = NULL;
  1199. word32 outSz = LARGE_TEMP_SZ;
  1200. WC_RNG rng;
  1201. RsaKey caKey;
  1202. RsaKey serverKey;
  1203. ecc_key altCaKey;
  1204. word32 idx = 0;
  1205. XMEMSET(&rng, 0, sizeof(WC_RNG));
  1206. XMEMSET(&caKey, 0, sizeof(RsaKey));
  1207. XMEMSET(&serverKey, 0, sizeof(RsaKey));
  1208. XMEMSET(&altCaKey, 0, sizeof(ecc_key));
  1209. ExpectNotNull(outBuf = (byte*)XMALLOC(outSz, NULL,
  1210. DYNAMIC_TYPE_TMP_BUFFER));
  1211. ExpectIntEQ(wc_InitRng(&rng), 0);
  1212. XMEMSET(serverKeyBuf, 0, serverKeySz);
  1213. ExpectNotNull(file = fopen(serverKeyFile, "rb"));
  1214. ExpectIntGT(serverKeySz = (word32)fread(serverKeyBuf, 1, serverKeySz, file),
  1215. 0);
  1216. if (file) {
  1217. fclose(file);
  1218. file = NULL;
  1219. }
  1220. ExpectIntEQ(wc_InitRsaKey_ex(&serverKey, NULL, INVALID_DEVID), 0);
  1221. idx = 0;
  1222. ExpectIntEQ(wc_RsaPrivateKeyDecode(serverKeyBuf, &idx, &serverKey,
  1223. (word32)serverKeySz), 0);
  1224. XMEMSET(caKeyBuf, 0, caKeySz);
  1225. ExpectNotNull(file = fopen(caKeyFile, "rb"));
  1226. ExpectIntGT(caKeySz = (word32)fread(caKeyBuf, 1, caKeySz, file), 0);
  1227. if (file) {
  1228. fclose(file);
  1229. file = NULL;
  1230. }
  1231. ExpectIntEQ(wc_InitRsaKey_ex(&caKey, NULL, INVALID_DEVID), 0);
  1232. idx = 0;
  1233. ExpectIntEQ(wc_RsaPrivateKeyDecode(caKeyBuf, &idx, &caKey,
  1234. (word32)caKeySz), 0);
  1235. XMEMSET(sapkiBuf, 0, sapkiSz);
  1236. ExpectNotNull(file = fopen(sapkiFile, "rb"));
  1237. ExpectIntGT(sapkiSz = (word32)fread(sapkiBuf, 1, sapkiSz, file), 0);
  1238. if (file) {
  1239. fclose(file);
  1240. file = NULL;
  1241. }
  1242. XMEMSET(altPrivBuf, 0, altPrivSz);
  1243. ExpectNotNull(file = fopen(altPrivFile, "rb"));
  1244. ExpectIntGT(altPrivSz = (word32)fread(altPrivBuf, 1, altPrivSz, file), 0);
  1245. if (file) {
  1246. fclose(file);
  1247. file = NULL;
  1248. }
  1249. wc_ecc_init(&altCaKey);
  1250. idx = 0;
  1251. ExpectIntEQ(wc_EccPrivateKeyDecode(altPrivBuf, &idx, &altCaKey,
  1252. (word32)altPrivSz), 0);
  1253. XMEMSET(altSigAlgBuf, 0, altSigAlgSz);
  1254. ExpectIntGT(altSigAlgSz = SetAlgoID(CTC_SHA256wECDSA, altSigAlgBuf,
  1255. oidSigType, 0), 0);
  1256. wc_InitCert(&newCert);
  1257. strncpy(newCert.subject.country, "US", CTC_NAME_SIZE);
  1258. strncpy(newCert.subject.state, "MT", CTC_NAME_SIZE);
  1259. strncpy(newCert.subject.locality, "Bozeman", CTC_NAME_SIZE);
  1260. strncpy(newCert.subject.org, "wolfSSL", CTC_NAME_SIZE);
  1261. strncpy(newCert.subject.unit, "Engineering", CTC_NAME_SIZE);
  1262. strncpy(newCert.subject.commonName, "www.wolfssl.com", CTC_NAME_SIZE);
  1263. strncpy(newCert.subject.email, "server@wolfssl.com", CTC_NAME_SIZE);
  1264. newCert.sigType = CTC_SHA256wRSA;
  1265. newCert.isCA = 0;
  1266. ExpectIntEQ(wc_SetIssuerBuffer(&newCert, caCertBuf, caCertSz), 0);
  1267. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.72", sapkiBuf,
  1268. sapkiSz), 0);
  1269. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.73", altSigAlgBuf,
  1270. altSigAlgSz), 0);
  1271. XMEMSET(scratchBuf, 0, scratchSz);
  1272. ExpectIntGT(wc_MakeCert(&newCert, scratchBuf, scratchSz, &serverKey, NULL,
  1273. &rng), 0);
  1274. ExpectIntGT(scratchSz = wc_SignCert(newCert.bodySz, newCert.sigType,
  1275. scratchBuf, scratchSz, &caKey, NULL, &rng), 0);
  1276. wc_InitDecodedCert(&preTBS, scratchBuf, scratchSz, 0);
  1277. ExpectIntEQ(wc_ParseCert(&preTBS, CERT_TYPE, NO_VERIFY, NULL), 0);
  1278. XMEMSET(preTbsBuf, 0, preTbsSz);
  1279. ExpectIntGT(preTbsSz = wc_GeneratePreTBS(&preTBS, preTbsBuf, preTbsSz), 0);
  1280. XMEMSET(altSigValBuf, 0, altSigValSz);
  1281. ExpectIntGT(altSigValSz = wc_MakeSigWithBitStr(altSigValBuf, altSigValSz,
  1282. CTC_SHA256wECDSA, preTbsBuf, preTbsSz, ECC_TYPE, &altCaKey,
  1283. &rng), 0);
  1284. ExpectIntEQ(wc_SetCustomExtension(&newCert, 0, "2.5.29.74",
  1285. altSigValBuf, altSigValSz), 0);
  1286. /* Finally, generate the new certificate. */
  1287. if (outBuf != NULL) {
  1288. XMEMSET(outBuf, 0, outSz);
  1289. }
  1290. ExpectIntGT(wc_MakeCert(&newCert, outBuf, outSz, &serverKey, NULL, &rng),
  1291. 0);
  1292. ExpectIntGT(outSz = wc_SignCert(newCert.bodySz, newCert.sigType, outBuf,
  1293. outSz, &caKey, NULL, &rng), 0);
  1294. *out = outBuf;
  1295. wc_FreeRsaKey(&caKey);
  1296. wc_FreeRsaKey(&serverKey);
  1297. wc_FreeRng(&rng);
  1298. wc_FreeDecodedCert(&preTBS);
  1299. return outSz;
  1300. }
  1301. static int do_dual_alg_tls13_connection(byte *caCert, word32 caCertSz,
  1302. byte *serverCert, word32 serverCertSz,
  1303. byte *serverKey, word32 serverKeySz,
  1304. int negative_test)
  1305. {
  1306. EXPECT_DECLS;
  1307. WOLFSSL_CTX *ctx_c = NULL;
  1308. WOLFSSL_CTX *ctx_s = NULL;
  1309. WOLFSSL *ssl_c = NULL;
  1310. WOLFSSL *ssl_s = NULL;
  1311. struct test_memio_ctx test_ctx;
  1312. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  1313. ExpectIntEQ(test_memio_setup_ex(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  1314. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  1315. caCert, caCertSz, serverCert, serverCertSz,
  1316. serverKey, serverKeySz), 0);
  1317. if (negative_test) {
  1318. ExpectTrue(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0);
  1319. }
  1320. else {
  1321. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  1322. }
  1323. wolfSSL_free(ssl_c);
  1324. wolfSSL_free(ssl_s);
  1325. wolfSSL_CTX_free(ctx_c);
  1326. wolfSSL_CTX_free(ctx_s);
  1327. return EXPECT_RESULT();
  1328. }
  1329. static int test_dual_alg_support(void)
  1330. {
  1331. EXPECT_DECLS;
  1332. /* Root CA and server keys will be the same. This is only appropriate for
  1333. * testing. */
  1334. char keyFile[] = "./certs/ca-key.der";
  1335. char sapkiFile[] = "./certs/ecc-keyPub.der";
  1336. char altPrivFile[] = "./certs/ecc-key.der";
  1337. char wrongPrivFile[] = "./certs/ecc-client-key.der";
  1338. byte *serverKey = NULL;
  1339. size_t serverKeySz = 0;
  1340. byte *root = NULL;
  1341. int rootSz = 0;
  1342. byte *server = NULL;
  1343. int serverSz = 0;
  1344. ExpectIntEQ(load_file(keyFile, &serverKey, &serverKeySz), 0);
  1345. /* Base normal case. */
  1346. if (EXPECT_SUCCESS()) {
  1347. rootSz = do_dual_alg_root_certgen(&root, keyFile, sapkiFile,
  1348. altPrivFile);
  1349. }
  1350. ExpectNotNull(root);
  1351. ExpectIntGT(rootSz, 0);
  1352. if (EXPECT_SUCCESS()) {
  1353. serverSz = do_dual_alg_server_certgen(&server, keyFile, sapkiFile,
  1354. altPrivFile, keyFile, root, rootSz);
  1355. }
  1356. ExpectNotNull(server);
  1357. ExpectIntGT(serverSz, 0);
  1358. ExpectIntEQ(do_dual_alg_tls13_connection(root, rootSz,
  1359. server, serverSz, serverKey, (word32)serverKeySz, 0),
  1360. TEST_SUCCESS);
  1361. XFREE(root, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  1362. root = NULL;
  1363. XFREE(server, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  1364. server = NULL;
  1365. /* Now we try a negative case. Note that we use wrongPrivFile to generate
  1366. * the alternative signature and then set negative_test to true for the
  1367. * call to do_dual_alg_tls13_connection(). Its expecting a failed connection
  1368. * because the signature won't verify. The exception is if
  1369. * WOLFSSL_TRUST_PEER_CERT is defined. In that case, no verification happens
  1370. * and this is no longer a negative test. */
  1371. if (EXPECT_SUCCESS()) {
  1372. rootSz = do_dual_alg_root_certgen(&root, keyFile, sapkiFile,
  1373. wrongPrivFile);
  1374. }
  1375. ExpectNotNull(root);
  1376. ExpectIntGT(rootSz, 0);
  1377. if (EXPECT_SUCCESS()) {
  1378. serverSz = do_dual_alg_server_certgen(&server, keyFile, sapkiFile,
  1379. wrongPrivFile, keyFile, root, rootSz);
  1380. }
  1381. ExpectNotNull(server);
  1382. ExpectIntGT(serverSz, 0);
  1383. #ifdef WOLFSSL_TRUST_PEER_CERT
  1384. ExpectIntEQ(do_dual_alg_tls13_connection(root, rootSz,
  1385. server, serverSz, serverKey, (word32)serverKeySz, 0),
  1386. TEST_SUCCESS);
  1387. #else
  1388. ExpectIntEQ(do_dual_alg_tls13_connection(root, rootSz,
  1389. server, serverSz, serverKey, (word32)serverKeySz, 1),
  1390. TEST_SUCCESS);
  1391. #endif
  1392. XFREE(root, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  1393. XFREE(server, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  1394. free(serverKey);
  1395. return EXPECT_RESULT();
  1396. }
  1397. #else
  1398. static int test_dual_alg_support(void)
  1399. {
  1400. return TEST_SKIPPED;
  1401. }
  1402. #endif /* WOLFSSL_DUAL_ALG_CERTS && !NO_FILESYSTEM */
  1403. /*----------------------------------------------------------------------------*
  1404. | Context
  1405. *----------------------------------------------------------------------------*/
  1406. #ifndef NO_WOLFSSL_SERVER
  1407. static int test_wolfSSL_CTX_new(void)
  1408. {
  1409. EXPECT_DECLS;
  1410. WOLFSSL_CTX *ctx;
  1411. WOLFSSL_METHOD* method = NULL;
  1412. ExpectNull(ctx = wolfSSL_CTX_new(NULL));
  1413. ExpectNotNull(method = wolfSSLv23_server_method());
  1414. if (method != NULL)
  1415. ExpectNotNull(ctx = wolfSSL_CTX_new(method));
  1416. wolfSSL_CTX_free(ctx);
  1417. return EXPECT_RESULT();
  1418. }
  1419. #endif
  1420. #if (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)) && \
  1421. (!defined(NO_RSA) || defined(HAVE_ECC)) && !defined(NO_FILESYSTEM)
  1422. static int test_for_double_Free(void)
  1423. {
  1424. EXPECT_DECLS;
  1425. WOLFSSL_CTX* ctx = NULL;
  1426. WOLFSSL* ssl = NULL;
  1427. int skipTest = 0;
  1428. const char* testCertFile;
  1429. const char* testKeyFile;
  1430. char optionsCiphers[] = "RC4-SHA:RC4-MD5:DES-CBC3-SHA:AES128-SHA:AES256-SHA"
  1431. ":NULL-SHA:NULL-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:DHE-PSK-AES256-GCM"
  1432. "-SHA384:DHE-PSK-AES128-GCM-SHA256:PSK-AES256-GCM-SHA384:PSK-AES128-GCM-SHA256:"
  1433. "DHE-PSK-AES256-CBC-SHA384:DHE-PSK-AES128-CBC-SHA256:PSK-AES256-CBC-SHA384:PSK-"
  1434. "AES128-CBC-SHA256:PSK-AES128-CBC-SHA:PSK-AES256-CBC-SHA:DHE-PSK-AES128-CCM:DHE"
  1435. "-PSK-AES256-CCM:PSK-AES128-CCM:PSK-AES256-CCM:PSK-AES128-CCM-8:PSK-AES256-CCM-"
  1436. "8:DHE-PSK-NULL-SHA384:DHE-PSK-NULL-SHA256:PSK-NULL-SHA384:PSK-NULL-SHA256:PSK-"
  1437. "NULL-SHA:AES128-CCM-8:AES256-CCM-8:ECDHE-ECDSA-"
  1438. "AES128-CCM:ECDHE-ECDSA-AES128-CCM-8:ECDHE-ECDSA-AES256-CCM-8:ECDHE-RSA-AES128-"
  1439. "SHA:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA:ECDHE-R"
  1440. "SA-RC4-SHA:ECDHE-RSA-DES-CBC3-SHA:ECDHE-ECDSA-RC4-SHA:ECDHE-ECDSA-DES-CBC3-SHA"
  1441. ":AES128-SHA256:AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA256:ECDH-"
  1442. "RSA-AES128-SHA:ECDH-RSA-AES256-SHA:ECDH-ECDSA-AES128-SHA:ECDH-ECDSA-AES256-SHA"
  1443. ":ECDH-RSA-RC4-SHA:ECDH-RSA-DES-CBC3-SHA:ECDH-ECDSA-RC4-SHA:ECDH-ECDSA-DES-CBC3"
  1444. "-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES"
  1445. "256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-E"
  1446. "CDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDH-RSA-AES128-GCM-SHA25"
  1447. "6:ECDH-RSA-AES256-GCM-SHA384:ECDH-ECDSA-AES128-GCM-SHA256:ECDH-ECDSA-AES256-GC"
  1448. "M-SHA384:CAMELLIA128-SHA:DHE-RSA-CAMELLIA128-SHA:CAMELLIA256-SHA:DHE-RSA-CAMEL"
  1449. "LIA256-SHA:CAMELLIA128-SHA256:DHE-RSA-CAMELLIA128-SHA256:CAMELLIA256-SHA256:DH"
  1450. "E-RSA-CAMELLIA256-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECD"
  1451. "H-RSA-AES128-SHA256:ECDH-ECDSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-ECD"
  1452. "SA-AES256-SHA384:ECDH-RSA-AES256-SHA384:ECDH-ECDSA-AES256-SHA384:ECDHE-RSA-CHA"
  1453. "CHA20-POLY1305:ECDHE-ECDSA-CHACHA20-POLY1305:DHE-RSA-CHACHA20-POLY1305:ECDHE-R"
  1454. "SA-CHACHA20-POLY1305-OLD:ECDHE-ECDSA-CHACHA20-POLY1305-OLD:DHE-RSA-CHACHA20-PO"
  1455. "LY1305-OLD:ECDHE-ECDSA-NULL-SHA:ECDHE-PSK-NULL-SHA256:ECDHE-PSK-A"
  1456. "ES128-CBC-SHA256:PSK-CHACHA20-POLY1305:ECDHE-PSK-CHACHA20-POLY1305:DHE-PSK-CHA"
  1457. "CHA20-POLY1305:EDH-RSA-DES-CBC3-SHA:TLS13-AES128-GCM-SHA256:TLS13-AES256-GCM-S"
  1458. "HA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES128-CCM-SHA256:TLS13-AES128-CCM-"
  1459. "8-SHA256:TLS13-SHA256-SHA256:TLS13-SHA384-SHA384";
  1460. /* OpenVPN uses a "blacklist" method to specify which ciphers NOT to use */
  1461. #ifdef OPENSSL_EXTRA
  1462. char openvpnCiphers[] = "DEFAULT:!EXP:!LOW:!MEDIUM:!kDH:!kECDH:!DSS:!PSK:"
  1463. "!SRP:!kRSA:!aNULL:!eNULL";
  1464. #endif
  1465. #ifndef NO_RSA
  1466. testCertFile = svrCertFile;
  1467. testKeyFile = svrKeyFile;
  1468. #elif defined(HAVE_ECC)
  1469. testCertFile = eccCertFile;
  1470. testKeyFile = eccKeyFile;
  1471. #else
  1472. skipTest = 1;
  1473. #endif
  1474. if (skipTest != 1) {
  1475. #ifndef NO_WOLFSSL_SERVER
  1476. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1477. #else
  1478. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1479. #endif
  1480. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  1481. WOLFSSL_FILETYPE_PEM));
  1482. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  1483. WOLFSSL_FILETYPE_PEM));
  1484. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1485. /* First test freeing SSL, then CTX */
  1486. wolfSSL_free(ssl);
  1487. ssl = NULL;
  1488. wolfSSL_CTX_free(ctx);
  1489. ctx = NULL;
  1490. #ifndef NO_WOLFSSL_CLIENT
  1491. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1492. #else
  1493. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1494. #endif
  1495. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  1496. WOLFSSL_FILETYPE_PEM));
  1497. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  1498. WOLFSSL_FILETYPE_PEM));
  1499. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1500. /* Next test freeing CTX then SSL */
  1501. wolfSSL_CTX_free(ctx);
  1502. ctx = NULL;
  1503. wolfSSL_free(ssl);
  1504. ssl = NULL;
  1505. #ifndef NO_WOLFSSL_SERVER
  1506. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1507. #else
  1508. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1509. #endif
  1510. /* Test setting ciphers at ctx level */
  1511. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  1512. WOLFSSL_FILETYPE_PEM));
  1513. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  1514. WOLFSSL_FILETYPE_PEM));
  1515. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx, optionsCiphers));
  1516. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_TLS13) && defined(HAVE_AESGCM) && \
  1517. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  1518. /* only update TLSv13 suites */
  1519. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx, "TLS13-AES256-GCM-SHA384"));
  1520. #endif
  1521. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && defined(HAVE_AESGCM) && \
  1522. !defined(NO_SHA256) && !defined(WOLFSSL_NO_TLS12) && \
  1523. defined(WOLFSSL_AES_128) && !defined(NO_RSA)
  1524. /* only update pre-TLSv13 suites */
  1525. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx,
  1526. "ECDHE-RSA-AES128-GCM-SHA256"));
  1527. #endif
  1528. #ifdef OPENSSL_EXTRA
  1529. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx, openvpnCiphers));
  1530. #endif
  1531. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1532. wolfSSL_CTX_free(ctx);
  1533. ctx = NULL;
  1534. wolfSSL_free(ssl);
  1535. ssl = NULL;
  1536. #ifndef NO_WOLFSSL_CLIENT
  1537. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1538. #else
  1539. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1540. #endif
  1541. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  1542. WOLFSSL_FILETYPE_PEM));
  1543. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  1544. WOLFSSL_FILETYPE_PEM));
  1545. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1546. /* test setting ciphers at SSL level */
  1547. ExpectTrue(wolfSSL_set_cipher_list(ssl, optionsCiphers));
  1548. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_TLS13) && defined(HAVE_AESGCM) && \
  1549. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  1550. /* only update TLSv13 suites */
  1551. ExpectTrue(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384"));
  1552. #endif
  1553. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && defined(HAVE_AESGCM) && \
  1554. !defined(NO_SHA256) && !defined(WOLFSSL_NO_TLS12) && \
  1555. defined(WOLFSSL_AES_128) && !defined(NO_RSA)
  1556. /* only update pre-TLSv13 suites */
  1557. ExpectTrue(wolfSSL_set_cipher_list(ssl, "ECDHE-RSA-AES128-GCM-SHA256"));
  1558. #endif
  1559. wolfSSL_CTX_free(ctx);
  1560. ctx = NULL;
  1561. wolfSSL_free(ssl);
  1562. ssl = NULL;
  1563. }
  1564. return EXPECT_RESULT();
  1565. }
  1566. #endif
  1567. static int test_wolfSSL_CTX_set_cipher_list_bytes(void)
  1568. {
  1569. EXPECT_DECLS;
  1570. #if (defined(OPENSSL_EXTRA) || defined(WOLFSSL_SET_CIPHER_BYTES)) && \
  1571. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)) && \
  1572. (!defined(NO_RSA) || defined(HAVE_ECC)) && !defined(NO_FILESYSTEM)
  1573. const char* testCertFile;
  1574. const char* testKeyFile;
  1575. WOLFSSL_CTX* ctx = NULL;
  1576. WOLFSSL* ssl = NULL;
  1577. const byte cipherList[] =
  1578. {
  1579. /* TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA */ 0x00, 0x16,
  1580. /* TLS_DHE_RSA_WITH_AES_256_CBC_SHA */ 0x00, 0x39,
  1581. /* TLS_DHE_RSA_WITH_AES_128_CBC_SHA */ 0x00, 0x33,
  1582. /* TLS_DH_anon_WITH_AES_128_CBC_SHA */ 0x00, 0x34,
  1583. /* TLS_RSA_WITH_AES_256_CBC_SHA */ 0x00, 0x35,
  1584. /* TLS_RSA_WITH_AES_128_CBC_SHA */ 0x00, 0x2F,
  1585. /* TLS_RSA_WITH_NULL_MD5 */ 0x00, 0x01,
  1586. /* TLS_RSA_WITH_NULL_SHA */ 0x00, 0x02,
  1587. /* TLS_PSK_WITH_AES_256_CBC_SHA */ 0x00, 0x8d,
  1588. /* TLS_PSK_WITH_AES_128_CBC_SHA256 */ 0x00, 0xae,
  1589. /* TLS_PSK_WITH_AES_256_CBC_SHA384 */ 0x00, 0xaf,
  1590. /* TLS_PSK_WITH_AES_128_CBC_SHA */ 0x00, 0x8c,
  1591. /* TLS_PSK_WITH_NULL_SHA256 */ 0x00, 0xb0,
  1592. /* TLS_PSK_WITH_NULL_SHA384 */ 0x00, 0xb1,
  1593. /* TLS_PSK_WITH_NULL_SHA */ 0x00, 0x2c,
  1594. /* SSL_RSA_WITH_RC4_128_SHA */ 0x00, 0x05,
  1595. /* SSL_RSA_WITH_RC4_128_MD5 */ 0x00, 0x04,
  1596. /* SSL_RSA_WITH_3DES_EDE_CBC_SHA */ 0x00, 0x0A,
  1597. /* ECC suites, first byte is 0xC0 (ECC_BYTE) */
  1598. /* TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA */ 0xC0, 0x14,
  1599. /* TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA */ 0xC0, 0x13,
  1600. /* TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA */ 0xC0, 0x0A,
  1601. /* TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA */ 0xC0, 0x09,
  1602. /* TLS_ECDHE_RSA_WITH_RC4_128_SHA */ 0xC0, 0x11,
  1603. /* TLS_ECDHE_ECDSA_WITH_RC4_128_SHA */ 0xC0, 0x07,
  1604. /* TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA */ 0xC0, 0x12,
  1605. /* TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA */ 0xC0, 0x08,
  1606. /* TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 */ 0xC0, 0x27,
  1607. /* TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256*/ 0xC0, 0x23,
  1608. /* TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 */ 0xC0, 0x28,
  1609. /* TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384*/ 0xC0, 0x24,
  1610. /* TLS_ECDHE_ECDSA_WITH_NULL_SHA */ 0xC0, 0x06,
  1611. /* TLS_ECDHE_PSK_WITH_NULL_SHA256 */ 0xC0, 0x3a,
  1612. /* TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 */ 0xC0, 0x37,
  1613. /* static ECDH, first byte is 0xC0 (ECC_BYTE) */
  1614. /* TLS_ECDH_RSA_WITH_AES_256_CBC_SHA */ 0xC0, 0x0F,
  1615. /* TLS_ECDH_RSA_WITH_AES_128_CBC_SHA */ 0xC0, 0x0E,
  1616. /* TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA */ 0xC0, 0x05,
  1617. /* TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA */ 0xC0, 0x04,
  1618. /* TLS_ECDH_RSA_WITH_RC4_128_SHA */ 0xC0, 0x0C,
  1619. /* TLS_ECDH_ECDSA_WITH_RC4_128_SHA */ 0xC0, 0x02,
  1620. /* TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA */ 0xC0, 0x0D,
  1621. /* TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA */ 0xC0, 0x03,
  1622. /* TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 */ 0xC0, 0x29,
  1623. /* TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 */ 0xC0, 0x25,
  1624. /* TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 */ 0xC0, 0x2A,
  1625. /* TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 */ 0xC0, 0x26,
  1626. /* WDM_WITH_NULL_SHA256 */ 0x00, 0xFE, /* wolfSSL DTLS Multicast */
  1627. /* SHA256 */
  1628. /* TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 */ 0x00, 0x6b,
  1629. /* TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 */ 0x00, 0x67,
  1630. /* TLS_RSA_WITH_AES_256_CBC_SHA256 */ 0x00, 0x3d,
  1631. /* TLS_RSA_WITH_AES_128_CBC_SHA256 */ 0x00, 0x3c,
  1632. /* TLS_RSA_WITH_NULL_SHA256 */ 0x00, 0x3b,
  1633. /* TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 */ 0x00, 0xb2,
  1634. /* TLS_DHE_PSK_WITH_NULL_SHA256 */ 0x00, 0xb4,
  1635. /* SHA384 */
  1636. /* TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 */ 0x00, 0xb3,
  1637. /* TLS_DHE_PSK_WITH_NULL_SHA384 */ 0x00, 0xb5,
  1638. /* AES-GCM */
  1639. /* TLS_RSA_WITH_AES_128_GCM_SHA256 */ 0x00, 0x9c,
  1640. /* TLS_RSA_WITH_AES_256_GCM_SHA384 */ 0x00, 0x9d,
  1641. /* TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 */ 0x00, 0x9e,
  1642. /* TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 */ 0x00, 0x9f,
  1643. /* TLS_DH_anon_WITH_AES_256_GCM_SHA384 */ 0x00, 0xa7,
  1644. /* TLS_PSK_WITH_AES_128_GCM_SHA256 */ 0x00, 0xa8,
  1645. /* TLS_PSK_WITH_AES_256_GCM_SHA384 */ 0x00, 0xa9,
  1646. /* TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 */ 0x00, 0xaa,
  1647. /* TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 */ 0x00, 0xab,
  1648. /* ECC AES-GCM, first byte is 0xC0 (ECC_BYTE) */
  1649. /* TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 */ 0xC0, 0x2b,
  1650. /* TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 */ 0xC0, 0x2c,
  1651. /* TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 */ 0xC0, 0x2d,
  1652. /* TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 */ 0xC0, 0x2e,
  1653. /* TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 */ 0xC0, 0x2f,
  1654. /* TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 */ 0xC0, 0x30,
  1655. /* TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 */ 0xC0, 0x31,
  1656. /* TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 */ 0xC0, 0x32,
  1657. /* AES-CCM, first byte is 0xC0 but isn't ECC,
  1658. * also, in some of the other AES-CCM suites
  1659. * there will be second byte number conflicts
  1660. * with non-ECC AES-GCM */
  1661. /* TLS_RSA_WITH_AES_128_CCM_8 */ 0xC0, 0xa0,
  1662. /* TLS_RSA_WITH_AES_256_CCM_8 */ 0xC0, 0xa1,
  1663. /* TLS_ECDHE_ECDSA_WITH_AES_128_CCM */ 0xC0, 0xac,
  1664. /* TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 */ 0xC0, 0xae,
  1665. /* TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 */ 0xC0, 0xaf,
  1666. /* TLS_PSK_WITH_AES_128_CCM */ 0xC0, 0xa4,
  1667. /* TLS_PSK_WITH_AES_256_CCM */ 0xC0, 0xa5,
  1668. /* TLS_PSK_WITH_AES_128_CCM_8 */ 0xC0, 0xa8,
  1669. /* TLS_PSK_WITH_AES_256_CCM_8 */ 0xC0, 0xa9,
  1670. /* TLS_DHE_PSK_WITH_AES_128_CCM */ 0xC0, 0xa6,
  1671. /* TLS_DHE_PSK_WITH_AES_256_CCM */ 0xC0, 0xa7,
  1672. /* Camellia */
  1673. /* TLS_RSA_WITH_CAMELLIA_128_CBC_SHA */ 0x00, 0x41,
  1674. /* TLS_RSA_WITH_CAMELLIA_256_CBC_SHA */ 0x00, 0x84,
  1675. /* TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 */ 0x00, 0xba,
  1676. /* TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 */ 0x00, 0xc0,
  1677. /* TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA */ 0x00, 0x45,
  1678. /* TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA */ 0x00, 0x88,
  1679. /* TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 */ 0x00, 0xbe,
  1680. /* TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 */ 0x00, 0xc4,
  1681. /* chacha20-poly1305 suites first byte is 0xCC (CHACHA_BYTE) */
  1682. /* TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xa8,
  1683. /* TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xa9,
  1684. /* TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xaa,
  1685. /* TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xac,
  1686. /* TLS_PSK_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xab,
  1687. /* TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256 */ 0xCC, 0xad,
  1688. /* chacha20-poly1305 earlier version of nonce and padding (CHACHA_BYTE) */
  1689. /* TLS_ECDHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256 */ 0xCC, 0x13,
  1690. /* TLS_ECDHE_ECDSA_WITH_CHACHA20_OLD_POLY1305_SHA256 */ 0xCC, 0x14,
  1691. /* TLS_DHE_RSA_WITH_CHACHA20_OLD_POLY1305_SHA256 */ 0xCC, 0x15,
  1692. /* ECDHE_PSK RFC8442, first byte is 0xD0 (ECDHE_PSK_BYTE) */
  1693. /* TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256 */ 0xD0, 0x01,
  1694. /* TLS v1.3 cipher suites */
  1695. /* TLS_AES_128_GCM_SHA256 */ 0x13, 0x01,
  1696. /* TLS_AES_256_GCM_SHA384 */ 0x13, 0x02,
  1697. /* TLS_CHACHA20_POLY1305_SHA256 */ 0x13, 0x03,
  1698. /* TLS_AES_128_CCM_SHA256 */ 0x13, 0x04,
  1699. /* TLS_AES_128_CCM_8_SHA256 */ 0x13, 0x05,
  1700. /* TLS v1.3 Integrity only cipher suites - 0xC0 (ECC) first byte */
  1701. /* TLS_SHA256_SHA256 */ 0xC0, 0xB4,
  1702. /* TLS_SHA384_SHA384 */ 0xC0, 0xB5
  1703. };
  1704. #ifndef NO_RSA
  1705. testCertFile = svrCertFile;
  1706. testKeyFile = svrKeyFile;
  1707. #elif defined(HAVE_ECC)
  1708. testCertFile = eccCertFile;
  1709. testKeyFile = eccKeyFile;
  1710. #endif
  1711. #ifndef NO_WOLFSSL_SERVER
  1712. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1713. #else
  1714. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1715. #endif
  1716. ExpectTrue(wolfSSL_CTX_set_cipher_list_bytes(ctx, &cipherList[0U],
  1717. sizeof(cipherList)));
  1718. wolfSSL_CTX_free(ctx);
  1719. ctx = NULL;
  1720. #ifndef NO_WOLFSSL_SERVER
  1721. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1722. #else
  1723. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1724. #endif
  1725. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  1726. WOLFSSL_FILETYPE_PEM));
  1727. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  1728. WOLFSSL_FILETYPE_PEM));
  1729. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1730. ExpectTrue(wolfSSL_set_cipher_list_bytes(ssl, &cipherList[0U],
  1731. sizeof(cipherList)));
  1732. wolfSSL_free(ssl);
  1733. wolfSSL_CTX_free(ctx);
  1734. #endif /* (OPENSSL_EXTRA || WOLFSSL_SET_CIPHER_BYTES) &&
  1735. (!NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER) && (!NO_RSA || HAVE_ECC) */
  1736. return EXPECT_RESULT();
  1737. }
  1738. static int test_wolfSSL_CTX_use_certificate(void)
  1739. {
  1740. EXPECT_DECLS;
  1741. #if defined(OPENSSL_EXTRA) || defined(HAVE_LIGHTY) || \
  1742. defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(HAVE_STUNNEL) || \
  1743. defined(WOLFSSL_NGINX) || defined(HAVE_POCO_LIB) || \
  1744. defined(WOLFSSL_HAPROXY)
  1745. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  1746. WOLFSSL_CTX* ctx = NULL;
  1747. X509* x509 = NULL;
  1748. #ifndef NO_WOLFSSL_SERVER
  1749. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1750. #else
  1751. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1752. #endif
  1753. ExpectNotNull(x509 = wolfSSL_X509_new());
  1754. /* Negative tests. */
  1755. ExpectIntEQ(SSL_CTX_use_certificate(NULL, NULL), 0);
  1756. ExpectIntEQ(SSL_CTX_use_certificate(ctx, NULL), 0);
  1757. ExpectIntEQ(SSL_CTX_use_certificate(NULL, x509), 0);
  1758. /* Empty certificate */
  1759. ExpectIntEQ(SSL_CTX_use_certificate(ctx, x509), 0);
  1760. wolfSSL_X509_free(x509);
  1761. wolfSSL_CTX_free(ctx);
  1762. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  1763. #endif
  1764. return EXPECT_RESULT();
  1765. }
  1766. static int test_wolfSSL_CTX_use_certificate_file(void)
  1767. {
  1768. EXPECT_DECLS;
  1769. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_WOLFSSL_SERVER)
  1770. WOLFSSL_CTX *ctx = NULL;
  1771. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1772. /* invalid context */
  1773. ExpectFalse(wolfSSL_CTX_use_certificate_file(NULL, svrCertFile,
  1774. WOLFSSL_FILETYPE_PEM));
  1775. /* invalid cert file */
  1776. ExpectFalse(wolfSSL_CTX_use_certificate_file(ctx, bogusFile,
  1777. WOLFSSL_FILETYPE_PEM));
  1778. /* invalid cert type */
  1779. ExpectFalse(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, 9999));
  1780. #ifdef NO_RSA
  1781. /* rsa needed */
  1782. ExpectFalse(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  1783. WOLFSSL_FILETYPE_PEM));
  1784. #else
  1785. /* success */
  1786. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  1787. WOLFSSL_FILETYPE_PEM));
  1788. #endif
  1789. wolfSSL_CTX_free(ctx);
  1790. #endif
  1791. return EXPECT_RESULT();
  1792. }
  1793. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO)) && !defined(NO_RSA)
  1794. static int test_wolfSSL_CTX_use_certificate_ASN1(void)
  1795. {
  1796. EXPECT_DECLS;
  1797. #if !defined(NO_CERTS) && !defined(NO_WOLFSSL_SERVER) && !defined(NO_ASN)
  1798. WOLFSSL_CTX* ctx = NULL;
  1799. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1800. /* Failure cases. */
  1801. ExpectIntEQ(SSL_CTX_use_certificate_ASN1(NULL, 0, NULL ),
  1802. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1803. ExpectIntEQ(SSL_CTX_use_certificate_ASN1(ctx , 0, NULL ),
  1804. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1805. ExpectIntEQ(SSL_CTX_use_certificate_ASN1(NULL, 0, server_cert_der_2048),
  1806. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1807. ExpectIntEQ(SSL_CTX_use_certificate_ASN1(ctx , 0, server_cert_der_2048),
  1808. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1809. ExpectIntEQ(SSL_CTX_use_certificate_ASN1(ctx, sizeof_server_cert_der_2048,
  1810. server_cert_der_2048), WOLFSSL_SUCCESS);
  1811. wolfSSL_CTX_free(ctx);
  1812. #endif
  1813. return EXPECT_RESULT();
  1814. }
  1815. #endif /* (OPENSSL_ALL || WOLFSSL_ASIO) && !NO_RSA */
  1816. /* Test function for wolfSSL_CTX_use_certificate_buffer. Load cert into
  1817. * context using buffer.
  1818. * PRE: NO_CERTS not defined; USE_CERT_BUFFERS_2048 defined; compile with
  1819. * --enable-testcert flag.
  1820. */
  1821. static int test_wolfSSL_CTX_use_certificate_buffer(void)
  1822. {
  1823. EXPECT_DECLS;
  1824. #if !defined(NO_CERTS) && defined(USE_CERT_BUFFERS_2048) && \
  1825. !defined(NO_RSA) && !defined(NO_WOLFSSL_SERVER)
  1826. WOLFSSL_CTX* ctx = NULL;
  1827. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1828. /* Invalid parameters. */
  1829. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(NULL, NULL, 0,
  1830. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1831. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(ctx, NULL, 0,
  1832. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  1833. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(NULL, server_cert_der_2048,
  1834. 0, WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1835. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(ctx, server_cert_der_2048, 0,
  1836. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  1837. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(ctx,
  1838. server_cert_der_2048, sizeof_server_cert_der_2048,
  1839. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  1840. wolfSSL_CTX_free(ctx);
  1841. #endif
  1842. return EXPECT_RESULT();
  1843. } /* END test_wolfSSL_CTX_use_certificate_buffer */
  1844. static int test_wolfSSL_use_certificate_buffer(void)
  1845. {
  1846. EXPECT_DECLS;
  1847. #if !defined(NO_CERTS) && defined(USE_CERT_BUFFERS_2048) && \
  1848. !defined(NO_RSA) && !defined(NO_WOLFSSL_CLIENT)
  1849. WOLFSSL_CTX* ctx = NULL;
  1850. WOLFSSL* ssl = NULL;
  1851. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1852. ExpectNotNull(ssl = wolfSSL_new(ctx));
  1853. /* Invalid parameters. */
  1854. ExpectIntEQ(wolfSSL_use_certificate_buffer(NULL, NULL, 0,
  1855. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1856. ExpectIntEQ(wolfSSL_use_certificate_buffer(ssl, NULL, 0,
  1857. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  1858. ExpectIntEQ(wolfSSL_use_certificate_buffer(NULL, client_cert_der_2048, 0,
  1859. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1860. ExpectIntEQ(wolfSSL_use_certificate_buffer(ssl, client_cert_der_2048, 0,
  1861. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  1862. ExpectIntEQ(wolfSSL_use_certificate_buffer(ssl,
  1863. client_cert_der_2048, sizeof_client_cert_der_2048,
  1864. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  1865. wolfSSL_free(ssl);
  1866. wolfSSL_CTX_free(ctx);
  1867. #endif
  1868. return EXPECT_RESULT();
  1869. }
  1870. static int test_wolfSSL_CTX_use_PrivateKey_file(void)
  1871. {
  1872. EXPECT_DECLS;
  1873. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_WOLFSSL_SERVER)
  1874. WOLFSSL_CTX *ctx = NULL;
  1875. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1876. /* invalid context */
  1877. ExpectFalse(wolfSSL_CTX_use_PrivateKey_file(NULL, svrKeyFile,
  1878. WOLFSSL_FILETYPE_PEM));
  1879. /* invalid key file */
  1880. ExpectFalse(wolfSSL_CTX_use_PrivateKey_file(ctx, bogusFile,
  1881. WOLFSSL_FILETYPE_PEM));
  1882. /* invalid key type */
  1883. ExpectFalse(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, 9999));
  1884. /* success */
  1885. #ifdef NO_RSA
  1886. /* rsa needed */
  1887. ExpectFalse(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  1888. WOLFSSL_FILETYPE_PEM));
  1889. #else
  1890. /* success */
  1891. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  1892. WOLFSSL_FILETYPE_PEM));
  1893. #endif
  1894. wolfSSL_CTX_free(ctx);
  1895. #endif
  1896. return EXPECT_RESULT();
  1897. }
  1898. static int test_wolfSSL_CTX_use_RSAPrivateKey_file(void)
  1899. {
  1900. EXPECT_DECLS;
  1901. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  1902. !defined(NO_WOLFSSL_SERVER) && defined(OPENSSL_EXTRA)
  1903. WOLFSSL_CTX *ctx = NULL;
  1904. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1905. /* invalid context */
  1906. ExpectIntEQ(wolfSSL_CTX_use_RSAPrivateKey_file(NULL, svrKeyFile,
  1907. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1908. /* invalid key file */
  1909. ExpectIntEQ(wolfSSL_CTX_use_RSAPrivateKey_file(ctx, bogusFile,
  1910. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1911. /* invalid key type */
  1912. ExpectIntEQ(wolfSSL_CTX_use_RSAPrivateKey_file(ctx, svrKeyFile, 9999),
  1913. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1914. /* success */
  1915. #ifdef NO_RSA
  1916. /* rsa needed */
  1917. ExpectIntEQ(wolfSSL_CTX_use_RSAPrivateKey_file(ctx, svrKeyFile,
  1918. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1919. #else
  1920. /* success */
  1921. ExpectIntEQ(wolfSSL_CTX_use_RSAPrivateKey_file(ctx, svrKeyFile,
  1922. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  1923. #endif
  1924. wolfSSL_CTX_free(ctx);
  1925. #endif
  1926. return EXPECT_RESULT();
  1927. }
  1928. static int test_wolfSSL_use_RSAPrivateKey_file(void)
  1929. {
  1930. EXPECT_DECLS;
  1931. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  1932. !defined(NO_WOLFSSL_CLIENT) && defined(OPENSSL_EXTRA)
  1933. WOLFSSL_CTX* ctx = NULL;
  1934. WOLFSSL* ssl = NULL;
  1935. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  1936. ExpectNotNull(ssl = SSL_new(ctx));
  1937. /* invalid context */
  1938. ExpectIntEQ(wolfSSL_use_RSAPrivateKey_file(NULL, svrKeyFile,
  1939. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  1940. /* invalid key file */
  1941. ExpectIntEQ(wolfSSL_use_RSAPrivateKey_file(ssl, bogusFile,
  1942. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1943. /* invalid key type */
  1944. ExpectIntEQ(wolfSSL_use_RSAPrivateKey_file(ssl, svrKeyFile, 9999),
  1945. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1946. /* success */
  1947. #ifdef NO_RSA
  1948. /* rsa needed */
  1949. ExpectIntEQ(wolfSSL_use_RSAPrivateKey_file(ssl, svrKeyFile,
  1950. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1951. #else
  1952. /* success */
  1953. ExpectIntEQ(wolfSSL_use_RSAPrivateKey_file(ssl, svrKeyFile,
  1954. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  1955. #endif
  1956. wolfSSL_free(ssl);
  1957. wolfSSL_CTX_free(ctx);
  1958. #endif
  1959. return EXPECT_RESULT();
  1960. }
  1961. static int test_wolfSSL_CTX_use_PrivateKey(void)
  1962. {
  1963. EXPECT_DECLS;
  1964. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  1965. !defined(NO_WOLFSSL_SERVER) && defined(OPENSSL_EXTRA)
  1966. WOLFSSL_CTX *ctx = NULL;
  1967. WOLFSSL_EVP_PKEY* pkey = NULL;
  1968. const unsigned char* p;
  1969. (void)p;
  1970. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  1971. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  1972. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1973. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1974. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(NULL, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1975. /* No data. */
  1976. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1977. wolfSSL_EVP_PKEY_free(pkey);
  1978. pkey = NULL;
  1979. #if defined(USE_CERT_BUFFERS_2048)
  1980. #if !defined(NO_RSA)
  1981. p = client_key_der_2048;
  1982. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_RSA, NULL, &p,
  1983. sizeof_client_key_der_2048));
  1984. #if defined(WOLFSSL_KEY_GEN)
  1985. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WOLFSSL_SUCCESS);
  1986. #else
  1987. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  1988. #endif
  1989. wolfSSL_EVP_PKEY_free(pkey);
  1990. pkey = NULL;
  1991. #endif
  1992. #if defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || defined(WOLFSSL_OPENSSH)
  1993. #ifndef NO_DSA
  1994. p = dsa_key_der_2048;
  1995. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_DSA, NULL, &p,
  1996. sizeof_dsa_key_der_2048));
  1997. #if !defined(HAVE_SELFTEST) && (defined(WOLFSSL_KEY_GEN) || \
  1998. defined(WOLFSSL_CERT_GEN))
  1999. /* Not supported in ProcessBuffer. */
  2000. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE));
  2001. #else
  2002. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  2003. #endif
  2004. wolfSSL_EVP_PKEY_free(pkey);
  2005. pkey = NULL;
  2006. #endif
  2007. #endif /* WOLFSSL_QT || OPENSSL_ALL || WOLFSSL_OPENSSH */
  2008. #if !defined(NO_DH) && defined(OPENSSL_ALL) && \
  2009. (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0))
  2010. p = dh_ffdhe_statickey_der_2048;
  2011. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_DH, NULL, &p,
  2012. sizeof_dh_ffdhe_statickey_der_2048));
  2013. /* Not supported. */
  2014. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  2015. wolfSSL_EVP_PKEY_free(pkey);
  2016. pkey = NULL;
  2017. #endif
  2018. #endif /* USE_CERT_BUFFERS_2048 */
  2019. #if defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  2020. p = ecc_clikey_der_256;
  2021. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &p,
  2022. sizeof_ecc_clikey_der_256));
  2023. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WOLFSSL_SUCCESS);
  2024. wolfSSL_EVP_PKEY_free(pkey);
  2025. pkey = NULL;
  2026. #endif
  2027. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL,
  2028. (unsigned char*)"01234567012345670123456701234567", 32));
  2029. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey(ctx, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  2030. wolfSSL_EVP_PKEY_free(pkey);
  2031. pkey = NULL;
  2032. wolfSSL_CTX_free(ctx);
  2033. #endif
  2034. return EXPECT_RESULT();
  2035. }
  2036. /* test both file and buffer versions along with unloading trusted peer certs */
  2037. static int test_wolfSSL_CTX_trust_peer_cert(void)
  2038. {
  2039. EXPECT_DECLS;
  2040. #if !defined(NO_CERTS) && defined(WOLFSSL_TRUST_PEER_CERT) && \
  2041. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_RSA)
  2042. WOLFSSL_CTX *ctx = NULL;
  2043. WOLFSSL* ssl = NULL;
  2044. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  2045. ExpectNotNull(ssl = wolfSSL_new(ctx));
  2046. #if !defined(NO_FILESYSTEM)
  2047. /* invalid file */
  2048. ExpectIntNE(wolfSSL_CTX_trust_peer_cert(ctx, NULL,
  2049. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  2050. ExpectIntNE(wolfSSL_CTX_trust_peer_cert(ctx, bogusFile,
  2051. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  2052. ExpectIntNE(wolfSSL_CTX_trust_peer_cert(ctx, cliCertFile,
  2053. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2054. /* success */
  2055. ExpectIntEQ(wolfSSL_CTX_trust_peer_cert(ctx, cliCertFile,
  2056. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  2057. /* unload cert */
  2058. ExpectIntNE(wolfSSL_CTX_Unload_trust_peers(NULL), WOLFSSL_SUCCESS);
  2059. ExpectIntEQ(wolfSSL_CTX_Unload_trust_peers(ctx), WOLFSSL_SUCCESS);
  2060. /* invalid file */
  2061. ExpectIntNE(wolfSSL_trust_peer_cert(ssl, NULL,
  2062. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  2063. ExpectIntNE(wolfSSL_trust_peer_cert(ssl, bogusFile,
  2064. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  2065. ExpectIntNE(wolfSSL_trust_peer_cert(ssl, cliCertFile,
  2066. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2067. /* success */
  2068. ExpectIntEQ(wolfSSL_trust_peer_cert(ssl, cliCertFile,
  2069. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  2070. #ifdef WOLFSSL_LOCAL_X509_STORE
  2071. /* unload cert */
  2072. ExpectIntNE(wolfSSL_Unload_trust_peers(NULL), WOLFSSL_SUCCESS);
  2073. ExpectIntEQ(wolfSSL_Unload_trust_peers(ssl), WOLFSSL_SUCCESS);
  2074. #endif
  2075. #endif
  2076. /* Test of loading certs from buffers */
  2077. /* invalid buffer */
  2078. ExpectIntNE(wolfSSL_CTX_trust_peer_buffer(ctx, NULL, -1,
  2079. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2080. /* success */
  2081. #ifdef USE_CERT_BUFFERS_1024
  2082. ExpectIntEQ(wolfSSL_CTX_trust_peer_buffer(ctx, client_cert_der_1024,
  2083. sizeof_client_cert_der_1024, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2084. #endif
  2085. #ifdef USE_CERT_BUFFERS_2048
  2086. ExpectIntEQ(wolfSSL_CTX_trust_peer_buffer(ctx, client_cert_der_2048,
  2087. sizeof_client_cert_der_2048, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2088. #endif
  2089. /* unload cert */
  2090. ExpectIntNE(wolfSSL_CTX_Unload_trust_peers(NULL), WOLFSSL_SUCCESS);
  2091. ExpectIntEQ(wolfSSL_CTX_Unload_trust_peers(ctx), WOLFSSL_SUCCESS);
  2092. wolfSSL_free(ssl);
  2093. wolfSSL_CTX_free(ctx);
  2094. #endif
  2095. return EXPECT_RESULT();
  2096. }
  2097. static int test_wolfSSL_CTX_load_verify_locations(void)
  2098. {
  2099. EXPECT_DECLS;
  2100. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_WOLFSSL_CLIENT)
  2101. WOLFSSL_CTX *ctx = NULL;
  2102. #ifndef NO_RSA
  2103. WOLFSSL_CERT_MANAGER* cm = NULL;
  2104. #ifdef PERSIST_CERT_CACHE
  2105. int cacheSz = 0;
  2106. unsigned char* cache = NULL;
  2107. int used = 0;
  2108. #ifndef NO_FILESYSTEM
  2109. const char* cacheFile = "./tests/cert_cache.tmp";
  2110. #endif
  2111. int i;
  2112. int t;
  2113. int* p;
  2114. #endif
  2115. #endif
  2116. #if !defined(NO_WOLFSSL_DIR) && !defined(WOLFSSL_TIRTOS)
  2117. const char* load_certs_path = "./certs/external";
  2118. const char* load_no_certs_path = "./examples";
  2119. const char* load_expired_path = "./certs/test/expired";
  2120. #endif
  2121. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  2122. /* invalid arguments */
  2123. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(NULL, caCertFile, NULL),
  2124. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  2125. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, NULL, NULL),
  2126. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  2127. /* invalid ca file */
  2128. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, bogusFile, NULL),
  2129. WS_RETURN_CODE(WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE),
  2130. WC_NO_ERR_TRACE(WOLFSSL_FAILURE)));
  2131. #if !defined(NO_WOLFSSL_DIR) && !defined(WOLFSSL_TIRTOS) && \
  2132. ((defined(WOLFSSL_QT) || defined(WOLFSSL_IGNORE_BAD_CERT_PATH)) && \
  2133. !(WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS & WOLFSSL_LOAD_FLAG_IGNORE_BAD_PATH_ERR))
  2134. /* invalid path */
  2135. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, NULL, bogusFile),
  2136. WS_RETURN_CODE(WC_NO_ERR_TRACE(BAD_PATH_ERROR),WC_NO_ERR_TRACE(WOLFSSL_FAILURE)));
  2137. #endif
  2138. #if defined(WOLFSSL_QT) || defined(WOLFSSL_IGNORE_BAD_CERT_PATH)
  2139. /* test ignoring the invalid path */
  2140. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL, bogusFile,
  2141. WOLFSSL_LOAD_FLAG_IGNORE_BAD_PATH_ERR), WOLFSSL_SUCCESS);
  2142. #endif
  2143. /* load ca cert */
  2144. #ifdef NO_RSA
  2145. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, NULL),
  2146. WS_RETURN_CODE(WC_NO_ERR_TRACE(ASN_UNKNOWN_OID_E),WC_NO_ERR_TRACE(WOLFSSL_FAILURE)));
  2147. #else /* Skip the following test without RSA certs. */
  2148. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, NULL),
  2149. WOLFSSL_SUCCESS);
  2150. #ifdef PERSIST_CERT_CACHE
  2151. /* Get cert cache size */
  2152. ExpectIntGT(cacheSz = wolfSSL_CTX_get_cert_cache_memsize(ctx), 0);
  2153. ExpectNotNull(cache = (byte*)XMALLOC(cacheSz, NULL,
  2154. DYNAMIC_TYPE_TMP_BUFFER));
  2155. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(NULL, NULL, -1, NULL),
  2156. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2157. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, NULL, -1, NULL),
  2158. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2159. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(NULL, cache, -1, NULL),
  2160. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2161. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(NULL, NULL, cacheSz, NULL),
  2162. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2163. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(NULL, NULL, -1, &used),
  2164. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2165. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(NULL, cache, cacheSz, &used),
  2166. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2167. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, NULL, cacheSz, &used),
  2168. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2169. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, cache, -1, &used),
  2170. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2171. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, cache, cacheSz, NULL),
  2172. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2173. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, cache, cacheSz - 10, &used),
  2174. WC_NO_ERR_TRACE(BUFFER_E));
  2175. ExpectIntEQ(wolfSSL_CTX_memsave_cert_cache(ctx, cache, cacheSz, &used), 1);
  2176. ExpectIntEQ(cacheSz, used);
  2177. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(NULL, NULL, -1),
  2178. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2179. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, NULL, -1),
  2180. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2181. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(NULL, cache, -1),
  2182. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2183. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(NULL, NULL, cacheSz),
  2184. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2185. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(NULL, cache, cacheSz),
  2186. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2187. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, NULL, cacheSz),
  2188. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2189. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, -1),
  2190. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2191. /* Smaller than header. */
  2192. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, 1), WC_NO_ERR_TRACE(BUFFER_E));
  2193. for (i = 1; i < cacheSz; i++) {
  2194. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz - i),
  2195. WC_NO_ERR_TRACE(BUFFER_E));
  2196. }
  2197. if (EXPECT_SUCCESS()) {
  2198. /* Modify header for bad results! */
  2199. p = (int*)cache;
  2200. /* version */
  2201. t = p[0]; p[0] = 0xff;
  2202. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz),
  2203. WC_NO_ERR_TRACE(CACHE_MATCH_ERROR));
  2204. p[0] = t; p++;
  2205. /* rows */
  2206. t = p[0]; p[0] = 0xff;
  2207. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz),
  2208. WC_NO_ERR_TRACE(CACHE_MATCH_ERROR));
  2209. p[0] = t; p++;
  2210. /* columns[0] */
  2211. t = p[0]; p[0] = -1;
  2212. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz),
  2213. WC_NO_ERR_TRACE(PARSE_ERROR));
  2214. p[0] = t; p += CA_TABLE_SIZE;
  2215. /* signerSz*/
  2216. t = p[0]; p[0] = 0xff;
  2217. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz),
  2218. WC_NO_ERR_TRACE(CACHE_MATCH_ERROR));
  2219. p[0] = t;
  2220. }
  2221. ExpectIntEQ(wolfSSL_CTX_memrestore_cert_cache(ctx, cache, cacheSz), 1);
  2222. ExpectIntEQ(cacheSz = wolfSSL_CTX_get_cert_cache_memsize(ctx), used);
  2223. #ifndef NO_FILESYSTEM
  2224. ExpectIntEQ(wolfSSL_CTX_save_cert_cache(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2225. ExpectIntEQ(wolfSSL_CTX_save_cert_cache(ctx, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2226. ExpectIntEQ(wolfSSL_CTX_save_cert_cache(NULL, cacheFile), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2227. ExpectIntEQ(wolfSSL_CTX_save_cert_cache(ctx, cacheFile), 1);
  2228. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2229. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(ctx, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2230. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(NULL, cacheFile), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2231. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(ctx, "no-file"),
  2232. WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE));
  2233. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(ctx, cacheFile), 1);
  2234. /* File contents is not a cache. */
  2235. ExpectIntEQ(wolfSSL_CTX_restore_cert_cache(ctx, "./certs/ca-cert.pem"),
  2236. WC_NO_ERR_TRACE(CACHE_MATCH_ERROR));
  2237. #endif
  2238. XFREE(cache, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  2239. #endif
  2240. /* Test unloading CA's */
  2241. ExpectIntEQ(wolfSSL_CTX_UnloadCAs(ctx), WOLFSSL_SUCCESS);
  2242. #ifdef PERSIST_CERT_CACHE
  2243. /* Verify no certs (result is less than cacheSz) */
  2244. ExpectIntGT(cacheSz, wolfSSL_CTX_get_cert_cache_memsize(ctx));
  2245. #endif
  2246. /* load ca cert again */
  2247. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, NULL),
  2248. WOLFSSL_SUCCESS);
  2249. /* Test getting CERT_MANAGER */
  2250. ExpectNotNull(cm = wolfSSL_CTX_GetCertManager(ctx));
  2251. /* Test unloading CA's using CM */
  2252. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  2253. #ifdef PERSIST_CERT_CACHE
  2254. /* Verify no certs (result is less than cacheSz) */
  2255. ExpectIntGT(cacheSz, wolfSSL_CTX_get_cert_cache_memsize(ctx));
  2256. #endif
  2257. #endif
  2258. #if !defined(NO_WOLFSSL_DIR) && !defined(WOLFSSL_TIRTOS)
  2259. /* Test loading CA certificates using a path */
  2260. #ifdef NO_RSA
  2261. /* failure here okay since certs in external directory are RSA */
  2262. ExpectIntNE(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL, load_certs_path,
  2263. WOLFSSL_LOAD_FLAG_PEM_CA_ONLY), WOLFSSL_SUCCESS);
  2264. #else
  2265. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL, load_certs_path,
  2266. WOLFSSL_LOAD_FLAG_PEM_CA_ONLY), WOLFSSL_SUCCESS);
  2267. #endif
  2268. /* Test loading path with no files */
  2269. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL,
  2270. load_no_certs_path, WOLFSSL_LOAD_FLAG_PEM_CA_ONLY),
  2271. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  2272. /* Test loading expired CA certificates */
  2273. #ifdef NO_RSA
  2274. ExpectIntNE(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL,
  2275. load_expired_path,
  2276. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY | WOLFSSL_LOAD_FLAG_PEM_CA_ONLY),
  2277. WOLFSSL_SUCCESS);
  2278. #else
  2279. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL,
  2280. load_expired_path,
  2281. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY | WOLFSSL_LOAD_FLAG_PEM_CA_ONLY),
  2282. WOLFSSL_SUCCESS);
  2283. #endif
  2284. /* Test loading CA certificates and ignoring all errors */
  2285. #ifdef NO_RSA
  2286. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL, load_certs_path,
  2287. WOLFSSL_LOAD_FLAG_IGNORE_ERR), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  2288. #else
  2289. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, NULL, load_certs_path,
  2290. WOLFSSL_LOAD_FLAG_IGNORE_ERR), WOLFSSL_SUCCESS);
  2291. #endif
  2292. #endif
  2293. wolfSSL_CTX_free(ctx);
  2294. #endif
  2295. return EXPECT_RESULT();
  2296. }
  2297. static int test_wolfSSL_CTX_load_system_CA_certs(void)
  2298. {
  2299. int res = TEST_SKIPPED;
  2300. #if defined(WOLFSSL_SYS_CA_CERTS) && !defined(NO_WOLFSSL_CLIENT) && \
  2301. (!defined(NO_RSA) || defined(HAVE_ECC))
  2302. WOLFSSL_CTX* ctx;
  2303. byte dirValid = 0;
  2304. int ret = 0;
  2305. ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  2306. if (ctx == NULL) {
  2307. fprintf(stderr, "wolfSSL_CTX_new failed.\n");
  2308. ret = -1;
  2309. }
  2310. if (ret == 0) {
  2311. #if defined(USE_WINDOWS_API) || defined(__APPLE__)
  2312. dirValid = 1;
  2313. #else
  2314. word32 numDirs;
  2315. const char** caDirs = wolfSSL_get_system_CA_dirs(&numDirs);
  2316. if (caDirs == NULL || numDirs == 0) {
  2317. fprintf(stderr, "wolfSSL_get_system_CA_dirs failed.\n");
  2318. ret = -1;
  2319. }
  2320. else {
  2321. ReadDirCtx dirCtx;
  2322. word32 i;
  2323. for (i = 0; i < numDirs; ++i) {
  2324. if (wc_ReadDirFirst(&dirCtx, caDirs[i], NULL) == 0) {
  2325. /* Directory isn't empty. */
  2326. dirValid = 1;
  2327. wc_ReadDirClose(&dirCtx);
  2328. break;
  2329. }
  2330. }
  2331. }
  2332. #endif
  2333. }
  2334. /*
  2335. * If the directory isn't empty, we should be able to load CA
  2336. * certs from it. On Windows/Mac, we assume the CA cert stores are
  2337. * usable.
  2338. */
  2339. if (ret == 0 && dirValid && wolfSSL_CTX_load_system_CA_certs(ctx) !=
  2340. WOLFSSL_SUCCESS) {
  2341. fprintf(stderr, "wolfSSL_CTX_load_system_CA_certs failed.\n");
  2342. ret = -1;
  2343. }
  2344. #ifdef OPENSSL_EXTRA
  2345. if (ret == 0 &&
  2346. wolfSSL_CTX_set_default_verify_paths(ctx) != WOLFSSL_SUCCESS) {
  2347. fprintf(stderr, "wolfSSL_CTX_set_default_verify_paths failed.\n");
  2348. ret = -1;
  2349. }
  2350. #endif /* OPENSSL_EXTRA */
  2351. wolfSSL_CTX_free(ctx);
  2352. res = TEST_RES_CHECK(ret == 0);
  2353. #endif /* WOLFSSL_SYS_CA_CERTS && !NO_WOLFSSL_CLIENT */
  2354. return res;
  2355. }
  2356. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
  2357. static int test_cm_load_ca_buffer(const byte* cert_buf, size_t cert_sz,
  2358. int file_type)
  2359. {
  2360. int ret;
  2361. WOLFSSL_CERT_MANAGER* cm;
  2362. cm = wolfSSL_CertManagerNew();
  2363. if (cm == NULL) {
  2364. fprintf(stderr, "test_cm_load_ca failed\n");
  2365. return -1;
  2366. }
  2367. ret = wolfSSL_CertManagerLoadCABuffer(cm, cert_buf, (sword32)cert_sz, file_type);
  2368. wolfSSL_CertManagerFree(cm);
  2369. return ret;
  2370. }
  2371. static int test_cm_load_ca_file(const char* ca_cert_file)
  2372. {
  2373. int ret = 0;
  2374. byte* cert_buf = NULL;
  2375. size_t cert_sz = 0;
  2376. #if defined(WOLFSSL_PEM_TO_DER)
  2377. DerBuffer* pDer = NULL;
  2378. #endif
  2379. ret = load_file(ca_cert_file, &cert_buf, &cert_sz);
  2380. if (ret == 0) {
  2381. /* normal test */
  2382. ret = test_cm_load_ca_buffer(cert_buf, cert_sz, WOLFSSL_FILETYPE_PEM);
  2383. if (ret == WOLFSSL_SUCCESS) {
  2384. /* test including null terminator in length */
  2385. byte* tmp = (byte*)realloc(cert_buf, cert_sz+1);
  2386. if (tmp == NULL) {
  2387. ret = MEMORY_E;
  2388. }
  2389. else {
  2390. cert_buf = tmp;
  2391. cert_buf[cert_sz] = '\0';
  2392. ret = test_cm_load_ca_buffer(cert_buf, cert_sz+1,
  2393. WOLFSSL_FILETYPE_PEM);
  2394. }
  2395. }
  2396. #if defined(WOLFSSL_PEM_TO_DER)
  2397. if (ret == WOLFSSL_SUCCESS) {
  2398. /* test loading DER */
  2399. ret = wc_PemToDer(cert_buf, (sword32)cert_sz, CA_TYPE, &pDer,
  2400. NULL, NULL, NULL);
  2401. if (ret == 0 && pDer != NULL) {
  2402. ret = test_cm_load_ca_buffer(pDer->buffer, pDer->length,
  2403. WOLFSSL_FILETYPE_ASN1);
  2404. wc_FreeDer(&pDer);
  2405. }
  2406. }
  2407. #endif
  2408. }
  2409. free(cert_buf);
  2410. return ret;
  2411. }
  2412. static int test_cm_load_ca_buffer_ex(const byte* cert_buf, size_t cert_sz,
  2413. int file_type, word32 flags)
  2414. {
  2415. int ret;
  2416. WOLFSSL_CERT_MANAGER* cm;
  2417. cm = wolfSSL_CertManagerNew();
  2418. if (cm == NULL) {
  2419. fprintf(stderr, "test_cm_load_ca failed\n");
  2420. return -1;
  2421. }
  2422. ret = wolfSSL_CertManagerLoadCABuffer_ex(cm, cert_buf, (sword32)cert_sz, file_type,
  2423. 0, flags);
  2424. wolfSSL_CertManagerFree(cm);
  2425. return ret;
  2426. }
  2427. static int test_cm_load_ca_file_ex(const char* ca_cert_file, word32 flags)
  2428. {
  2429. int ret = 0;
  2430. byte* cert_buf = NULL;
  2431. size_t cert_sz = 0;
  2432. #if defined(WOLFSSL_PEM_TO_DER)
  2433. DerBuffer* pDer = NULL;
  2434. #endif
  2435. ret = load_file(ca_cert_file, &cert_buf, &cert_sz);
  2436. if (ret == 0) {
  2437. /* normal test */
  2438. ret = test_cm_load_ca_buffer_ex(cert_buf, cert_sz,
  2439. WOLFSSL_FILETYPE_PEM, flags);
  2440. if (ret == WOLFSSL_SUCCESS) {
  2441. /* test including null terminator in length */
  2442. byte* tmp = (byte*)realloc(cert_buf, cert_sz+1);
  2443. if (tmp == NULL) {
  2444. ret = MEMORY_E;
  2445. }
  2446. else {
  2447. cert_buf = tmp;
  2448. cert_buf[cert_sz] = '\0';
  2449. ret = test_cm_load_ca_buffer_ex(cert_buf, cert_sz+1,
  2450. WOLFSSL_FILETYPE_PEM, flags);
  2451. }
  2452. }
  2453. #if defined(WOLFSSL_PEM_TO_DER)
  2454. if (ret == WOLFSSL_SUCCESS) {
  2455. /* test loading DER */
  2456. ret = wc_PemToDer(cert_buf, (sword32)cert_sz, CA_TYPE, &pDer,
  2457. NULL, NULL, NULL);
  2458. if (ret == 0 && pDer != NULL) {
  2459. ret = test_cm_load_ca_buffer_ex(pDer->buffer, pDer->length,
  2460. WOLFSSL_FILETYPE_ASN1, flags);
  2461. wc_FreeDer(&pDer);
  2462. }
  2463. }
  2464. #endif
  2465. }
  2466. free(cert_buf);
  2467. return ret;
  2468. }
  2469. #endif /* !NO_FILESYSTEM && !NO_CERTS */
  2470. static int test_wolfSSL_CertManagerAPI(void)
  2471. {
  2472. EXPECT_DECLS;
  2473. #ifndef NO_CERTS
  2474. WOLFSSL_CERT_MANAGER* cm = NULL;
  2475. unsigned char c;
  2476. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  2477. wolfSSL_CertManagerFree(NULL);
  2478. ExpectIntEQ(wolfSSL_CertManager_up_ref(NULL), 0);
  2479. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2480. #ifdef WOLFSSL_TRUST_PEER_CERT
  2481. ExpectIntEQ(wolfSSL_CertManagerUnload_trust_peers(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2482. #endif
  2483. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer_ex(NULL, &c, 1,
  2484. WOLFSSL_FILETYPE_ASN1, 0, 0), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2485. #if !defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)
  2486. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(NULL, NULL, -1,
  2487. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2488. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, NULL, -1,
  2489. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2490. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(NULL, &c, -1,
  2491. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2492. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(NULL, NULL, 1,
  2493. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2494. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(NULL, &c, 1,
  2495. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2496. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, NULL, 1,
  2497. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2498. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, &c, -1,
  2499. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2500. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, &c, 1, -1),
  2501. WC_NO_ERR_TRACE(WOLFSSL_BAD_FILETYPE));
  2502. #endif
  2503. #if !defined(NO_FILESYSTEM)
  2504. {
  2505. const char* ca_cert = "./certs/ca-cert.pem";
  2506. #if !defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)
  2507. const char* ca_cert_der = "./certs/ca-cert.der";
  2508. #endif
  2509. const char* ca_path = "./certs";
  2510. #if !defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH)
  2511. ExpectIntEQ(wolfSSL_CertManagerVerify(NULL, NULL, -1),
  2512. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2513. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, NULL, WOLFSSL_FILETYPE_ASN1),
  2514. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2515. ExpectIntEQ(wolfSSL_CertManagerVerify(NULL, ca_cert,
  2516. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2517. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, ca_cert, -1),
  2518. WC_NO_ERR_TRACE(WOLFSSL_BAD_FILETYPE));
  2519. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, "no-file",
  2520. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE));
  2521. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, ca_cert_der,
  2522. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  2523. #endif
  2524. ExpectIntEQ(wolfSSL_CertManagerLoadCA(NULL, NULL, NULL),
  2525. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2526. ExpectIntEQ(wolfSSL_CertManagerLoadCA(NULL, ca_cert, NULL),
  2527. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2528. ExpectIntEQ(wolfSSL_CertManagerLoadCA(NULL, NULL, ca_path),
  2529. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2530. ExpectIntEQ(wolfSSL_CertManagerLoadCA(NULL, ca_cert, ca_path),
  2531. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2532. }
  2533. #endif
  2534. #ifdef OPENSSL_COMPATIBLE_DEFAULTS
  2535. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, 0), 1);
  2536. #elif !defined(HAVE_CRL)
  2537. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, 0), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  2538. #endif
  2539. ExpectIntEQ(wolfSSL_CertManagerDisableCRL(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2540. ExpectIntEQ(wolfSSL_CertManagerDisableCRL(cm), 1);
  2541. #ifdef HAVE_CRL
  2542. /* Test APIs when CRL is disabled. */
  2543. #ifdef HAVE_CRL_IO
  2544. ExpectIntEQ(wolfSSL_CertManagerSetCRL_IOCb(cm, NULL), 1);
  2545. #endif
  2546. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048,
  2547. sizeof_server_cert_der_2048), 1);
  2548. ExpectIntEQ(wolfSSL_CertManagerFreeCRL(cm), 1);
  2549. #endif
  2550. /* OCSP */
  2551. ExpectIntEQ(wolfSSL_CertManagerEnableOCSP(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2552. ExpectIntEQ(wolfSSL_CertManagerDisableOCSP(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2553. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPStapling(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2554. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPStapling(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2555. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPMustStaple(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2556. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPMustStaple(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2557. #if !defined(HAVE_CERTIFICATE_STATUS_REQUEST) && \
  2558. !defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  2559. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPStapling(cm), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  2560. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPMustStaple(cm), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  2561. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPMustStaple(cm), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  2562. #endif
  2563. #ifdef HAVE_OCSP
  2564. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(NULL, NULL, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2565. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, NULL, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2566. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(NULL, &c, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2567. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2568. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(NULL, &c, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2569. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2570. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, &c, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2571. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(NULL, NULL, 0,
  2572. NULL, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2573. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, NULL, 1,
  2574. NULL, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2575. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(NULL, &c, 1,
  2576. NULL, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2577. ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(NULL, NULL),
  2578. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2579. ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(NULL, ""),
  2580. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2581. ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(cm, NULL), 1);
  2582. ExpectIntEQ(wolfSSL_CertManagerSetOCSP_Cb(NULL, NULL, NULL, NULL),
  2583. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  2584. ExpectIntEQ(wolfSSL_CertManagerSetOCSP_Cb(cm, NULL, NULL, NULL), 1);
  2585. ExpectIntEQ(wolfSSL_CertManagerDisableOCSP(cm), 1);
  2586. /* Test APIs when OCSP is disabled. */
  2587. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, &c, 1,
  2588. NULL, NULL, NULL, NULL), 1);
  2589. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, &c, 1), 1);
  2590. #endif
  2591. ExpectIntEQ(wolfSSL_CertManager_up_ref(cm), 1);
  2592. if (EXPECT_SUCCESS()) {
  2593. wolfSSL_CertManagerFree(cm);
  2594. }
  2595. wolfSSL_CertManagerFree(cm);
  2596. cm = NULL;
  2597. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  2598. #ifdef HAVE_OCSP
  2599. ExpectIntEQ(wolfSSL_CertManagerEnableOCSP(cm, WOLFSSL_OCSP_URL_OVERRIDE |
  2600. WOLFSSL_OCSP_CHECKALL), 1);
  2601. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) || \
  2602. defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  2603. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPStapling(cm), 1);
  2604. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPStapling(cm), 1);
  2605. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPStapling(cm), 1);
  2606. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPStapling(cm), 1);
  2607. ExpectIntEQ(wolfSSL_CertManagerEnableOCSPMustStaple(cm), 1);
  2608. ExpectIntEQ(wolfSSL_CertManagerDisableOCSPMustStaple(cm), 1);
  2609. #endif
  2610. ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(cm, ""), 1);
  2611. ExpectIntEQ(wolfSSL_CertManagerSetOCSPOverrideURL(cm, ""), 1);
  2612. #endif
  2613. #ifdef WOLFSSL_TRUST_PEER_CERT
  2614. ExpectIntEQ(wolfSSL_CertManagerUnload_trust_peers(cm), 1);
  2615. #endif
  2616. wolfSSL_CertManagerFree(cm);
  2617. #endif
  2618. return EXPECT_RESULT();
  2619. }
  2620. static int test_wolfSSL_CertManagerLoadCABuffer(void)
  2621. {
  2622. EXPECT_DECLS;
  2623. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
  2624. const char* ca_cert = "./certs/ca-cert.pem";
  2625. const char* ca_expired_cert = "./certs/test/expired/expired-ca.pem";
  2626. int ret;
  2627. ExpectIntLE(ret = test_cm_load_ca_file(ca_cert), 1);
  2628. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  2629. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2630. #elif defined(NO_RSA)
  2631. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_UNKNOWN_OID_E));
  2632. #else
  2633. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  2634. #endif
  2635. ExpectIntLE(ret = test_cm_load_ca_file(ca_expired_cert), 1);
  2636. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  2637. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2638. #elif defined(NO_RSA)
  2639. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_UNKNOWN_OID_E));
  2640. #elif !(WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS & WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY) && \
  2641. !defined(NO_ASN_TIME)
  2642. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_AFTER_DATE_E));
  2643. #else
  2644. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  2645. #endif
  2646. #endif
  2647. return EXPECT_RESULT();
  2648. }
  2649. static int test_wolfSSL_CertManagerLoadCABuffer_ex(void)
  2650. {
  2651. EXPECT_DECLS;
  2652. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
  2653. const char* ca_cert = "./certs/ca-cert.pem";
  2654. const char* ca_expired_cert = "./certs/test/expired/expired-ca.pem";
  2655. int ret;
  2656. ExpectIntLE(ret = test_cm_load_ca_file_ex(ca_cert, WOLFSSL_LOAD_FLAG_NONE),
  2657. 1);
  2658. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  2659. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2660. #elif defined(NO_RSA)
  2661. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_UNKNOWN_OID_E));
  2662. #else
  2663. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  2664. #endif
  2665. ExpectIntLE(ret = test_cm_load_ca_file_ex(ca_expired_cert,
  2666. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), 1);
  2667. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  2668. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  2669. #elif defined(NO_RSA)
  2670. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_UNKNOWN_OID_E));
  2671. #elif !(WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS & WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY) && \
  2672. !defined(NO_ASN_TIME) && defined(WOLFSSL_TRUST_PEER_CERT) && \
  2673. defined(OPENSSL_COMPATIBLE_DEFAULTS)
  2674. ExpectIntEQ(ret, WC_NO_ERR_TRACE(ASN_AFTER_DATE_E));
  2675. #else
  2676. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  2677. #endif
  2678. #endif
  2679. return EXPECT_RESULT();
  2680. }
  2681. static int test_wolfSSL_CertManagerGetCerts(void)
  2682. {
  2683. EXPECT_DECLS;
  2684. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  2685. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && \
  2686. defined(WOLFSSL_SIGNER_DER_CERT)
  2687. WOLFSSL_CERT_MANAGER* cm = NULL;
  2688. WOLFSSL_STACK* sk = NULL;
  2689. X509* x509 = NULL;
  2690. X509* cert1 = NULL;
  2691. FILE* file1 = NULL;
  2692. #ifdef DEBUG_WOLFSSL_VERBOSE
  2693. WOLFSSL_BIO* bio = NULL;
  2694. #endif
  2695. int i = 0;
  2696. int ret = 0;
  2697. const byte* der = NULL;
  2698. int derSz = 0;
  2699. ExpectNotNull(file1 = fopen("./certs/ca-cert.pem", "rb"));
  2700. ExpectNotNull(cert1 = wolfSSL_PEM_read_X509(file1, NULL, NULL, NULL));
  2701. if (file1 != NULL) {
  2702. fclose(file1);
  2703. }
  2704. ExpectNull(sk = wolfSSL_CertManagerGetCerts(NULL));
  2705. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  2706. ExpectNull(sk = wolfSSL_CertManagerGetCerts(cm));
  2707. ExpectNotNull(der = wolfSSL_X509_get_der(cert1, &derSz));
  2708. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
  2709. /* Check that ASN_SELF_SIGNED_E is returned for a self-signed cert for QT
  2710. * and full OpenSSL compatibility */
  2711. ExpectIntEQ(ret = wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2712. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E));
  2713. #else
  2714. ExpectIntEQ(ret = wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2715. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  2716. #endif
  2717. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCA(cm,
  2718. "./certs/ca-cert.pem", NULL));
  2719. ExpectNotNull(sk = wolfSSL_CertManagerGetCerts(cm));
  2720. for (i = 0; EXPECT_SUCCESS() && i < sk_X509_num(sk); i++) {
  2721. ExpectNotNull(x509 = sk_X509_value(sk, i));
  2722. ExpectIntEQ(0, wolfSSL_X509_cmp(x509, cert1));
  2723. #ifdef DEBUG_WOLFSSL_VERBOSE
  2724. bio = BIO_new(wolfSSL_BIO_s_file());
  2725. if (bio != NULL) {
  2726. BIO_set_fp(bio, stderr, BIO_NOCLOSE);
  2727. X509_print(bio, x509);
  2728. BIO_free(bio);
  2729. }
  2730. #endif /* DEBUG_WOLFSSL_VERBOSE */
  2731. }
  2732. wolfSSL_X509_free(cert1);
  2733. sk_X509_pop_free(sk, NULL);
  2734. wolfSSL_CertManagerFree(cm);
  2735. #endif /* defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  2736. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && \
  2737. defined(WOLFSSL_SIGNER_DER_CERT) */
  2738. return EXPECT_RESULT();
  2739. }
  2740. static int test_wolfSSL_CertManagerSetVerify(void)
  2741. {
  2742. EXPECT_DECLS;
  2743. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  2744. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  2745. (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH))
  2746. WOLFSSL_CERT_MANAGER* cm = NULL;
  2747. int tmp = myVerifyAction;
  2748. const char* ca_cert = "./certs/ca-cert.pem";
  2749. const char* expiredCert = "./certs/test/expired/expired-cert.pem";
  2750. wolfSSL_CertManagerSetVerify(NULL, NULL);
  2751. wolfSSL_CertManagerSetVerify(NULL, myVerify);
  2752. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  2753. wolfSSL_CertManagerSetVerify(cm, myVerify);
  2754. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  2755. ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL), -1);
  2756. #else
  2757. ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL),
  2758. WOLFSSL_SUCCESS);
  2759. #endif
  2760. /* Use the test CB that always accepts certs */
  2761. myVerifyAction = VERIFY_OVERRIDE_ERROR;
  2762. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, expiredCert,
  2763. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  2764. #ifdef WOLFSSL_ALWAYS_VERIFY_CB
  2765. {
  2766. const char* verifyCert = "./certs/server-cert.der";
  2767. /* Use the test CB that always fails certs */
  2768. myVerifyAction = VERIFY_FORCE_FAIL;
  2769. ExpectIntEQ(wolfSSL_CertManagerVerify(cm, verifyCert,
  2770. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(VERIFY_CERT_ERROR));
  2771. }
  2772. #endif
  2773. wolfSSL_CertManagerFree(cm);
  2774. myVerifyAction = tmp;
  2775. #endif
  2776. return EXPECT_RESULT();
  2777. }
  2778. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  2779. defined(DEBUG_UNIT_TEST_CERTS)
  2780. /* Used when debugging name constraint tests. Not static to allow use in
  2781. * multiple locations with complex define guards. */
  2782. void DEBUG_WRITE_CERT_X509(WOLFSSL_X509* x509, const char* fileName)
  2783. {
  2784. BIO* out = BIO_new_file(fileName, "wb");
  2785. if (out != NULL) {
  2786. PEM_write_bio_X509(out, x509);
  2787. BIO_free(out);
  2788. }
  2789. }
  2790. void DEBUG_WRITE_DER(const byte* der, int derSz, const char* fileName)
  2791. {
  2792. BIO* out = BIO_new_file(fileName, "wb");
  2793. if (out != NULL) {
  2794. BIO_write(out, der, derSz);
  2795. BIO_free(out);
  2796. }
  2797. }
  2798. #else
  2799. #define DEBUG_WRITE_CERT_X509(x509, fileName) WC_DO_NOTHING
  2800. #define DEBUG_WRITE_DER(der, derSz, fileName) WC_DO_NOTHING
  2801. #endif
  2802. static int test_wolfSSL_CertManagerNameConstraint(void)
  2803. {
  2804. EXPECT_DECLS;
  2805. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  2806. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  2807. defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && \
  2808. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ALT_NAMES) && \
  2809. !defined(NO_SHA256)
  2810. WOLFSSL_CERT_MANAGER* cm = NULL;
  2811. WOLFSSL_EVP_PKEY *priv = NULL;
  2812. WOLFSSL_X509_NAME* name = NULL;
  2813. const char* ca_cert = "./certs/test/cert-ext-nc.der";
  2814. const char* server_cert = "./certs/test/server-goodcn.pem";
  2815. int i = 0;
  2816. static const byte extNameConsOid[] = {85, 29, 30};
  2817. RsaKey key;
  2818. WC_RNG rng;
  2819. byte *der = NULL;
  2820. int derSz = 0;
  2821. word32 idx = 0;
  2822. byte *pt;
  2823. WOLFSSL_X509 *x509 = NULL;
  2824. WOLFSSL_X509 *ca = NULL;
  2825. wc_InitRng(&rng);
  2826. /* load in CA private key for signing */
  2827. ExpectIntEQ(wc_InitRsaKey_ex(&key, HEAP_HINT, testDevId), 0);
  2828. ExpectIntEQ(wc_RsaPrivateKeyDecode(server_key_der_2048, &idx, &key,
  2829. sizeof_server_key_der_2048), 0);
  2830. /* get ca certificate then alter it */
  2831. ExpectNotNull(der =
  2832. (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER));
  2833. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(ca_cert,
  2834. WOLFSSL_FILETYPE_ASN1));
  2835. ExpectNotNull(pt = (byte*)wolfSSL_X509_get_tbs(x509, &derSz));
  2836. if (EXPECT_SUCCESS() && (der != NULL)) {
  2837. XMEMCPY(der, pt, derSz);
  2838. /* find the name constraint extension and alter it */
  2839. pt = der;
  2840. for (i = 0; i < derSz - 3; i++) {
  2841. if (XMEMCMP(pt, extNameConsOid, 3) == 0) {
  2842. pt += 3;
  2843. break;
  2844. }
  2845. pt++;
  2846. }
  2847. ExpectIntNE(i, derSz - 3); /* did not find OID if this case is hit */
  2848. /* go to the length value and set it to 0 */
  2849. while (i < derSz && *pt != 0x81) {
  2850. pt++;
  2851. i++;
  2852. }
  2853. ExpectIntNE(i, derSz); /* did not place to alter */
  2854. pt++;
  2855. *pt = 0x00;
  2856. }
  2857. /* resign the altered certificate */
  2858. ExpectIntGT((derSz = wc_SignCert(derSz, CTC_SHA256wRSA, der,
  2859. FOURK_BUF, &key, NULL, &rng)), 0);
  2860. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  2861. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  2862. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  2863. wolfSSL_CertManagerFree(cm);
  2864. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  2865. wolfSSL_X509_free(x509);
  2866. wc_FreeRsaKey(&key);
  2867. wc_FreeRng(&rng);
  2868. /* add email alt name to satisfy constraint */
  2869. pt = (byte*)server_key_der_2048;
  2870. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  2871. (const unsigned char**)&pt, sizeof_server_key_der_2048));
  2872. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  2873. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert,
  2874. WOLFSSL_FILETYPE_ASN1));
  2875. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz)));
  2876. DEBUG_WRITE_DER(der, derSz, "ca.der");
  2877. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  2878. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2879. /* Good cert test with proper alt email name */
  2880. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  2881. WOLFSSL_FILETYPE_PEM));
  2882. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  2883. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  2884. name = NULL;
  2885. ExpectNotNull(name = X509_NAME_new());
  2886. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  2887. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  2888. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  2889. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  2890. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  2891. (byte*)"support@info.wolfssl.com", 24, -1, 0), SSL_SUCCESS);
  2892. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  2893. X509_NAME_free(name);
  2894. name = NULL;
  2895. wolfSSL_X509_add_altname(x509, "wolfssl@info.wolfssl.com", ASN_RFC822_TYPE);
  2896. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  2897. DEBUG_WRITE_CERT_X509(x509, "good-cert.pem");
  2898. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  2899. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2900. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2901. wolfSSL_X509_free(x509);
  2902. x509 = NULL;
  2903. /* Cert with bad alt name list */
  2904. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  2905. WOLFSSL_FILETYPE_PEM));
  2906. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  2907. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  2908. name = NULL;
  2909. ExpectNotNull(name = X509_NAME_new());
  2910. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  2911. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  2912. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  2913. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  2914. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  2915. (byte*)"support@info.wolfssl.com", 24, -1, 0), SSL_SUCCESS);
  2916. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  2917. X509_NAME_free(name);
  2918. wolfSSL_X509_add_altname(x509, "wolfssl@info.com", ASN_RFC822_TYPE);
  2919. wolfSSL_X509_add_altname(x509, "wolfssl@info.wolfssl.com", ASN_RFC822_TYPE);
  2920. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  2921. DEBUG_WRITE_CERT_X509(x509, "bad-cert.pem");
  2922. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  2923. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2924. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  2925. wolfSSL_CertManagerFree(cm);
  2926. wolfSSL_X509_free(x509);
  2927. wolfSSL_X509_free(ca);
  2928. wolfSSL_EVP_PKEY_free(priv);
  2929. #endif
  2930. return EXPECT_RESULT();
  2931. }
  2932. static int test_wolfSSL_CertManagerNameConstraint2(void)
  2933. {
  2934. EXPECT_DECLS;
  2935. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  2936. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  2937. defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && \
  2938. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ALT_NAMES)
  2939. const char* ca_cert = "./certs/test/cert-ext-ndir.der";
  2940. const char* ca_cert2 = "./certs/test/cert-ext-ndir-exc.der";
  2941. const char* server_cert = "./certs/server-cert.pem";
  2942. WOLFSSL_CERT_MANAGER* cm = NULL;
  2943. WOLFSSL_X509 *x509 = NULL;
  2944. WOLFSSL_X509 *ca = NULL;
  2945. const unsigned char *der = NULL;
  2946. const unsigned char *pt;
  2947. WOLFSSL_EVP_PKEY *priv = NULL;
  2948. WOLFSSL_X509_NAME* name = NULL;
  2949. int derSz = 0;
  2950. /* C=US*/
  2951. char altName[] = {
  2952. 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09,
  2953. 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53
  2954. };
  2955. /* C=ID */
  2956. char altNameFail[] = {
  2957. 0x30, 0x0D, 0x31, 0x0B, 0x30, 0x09,
  2958. 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x49, 0x44
  2959. };
  2960. /* C=US ST=California*/
  2961. char altNameExc[] = {
  2962. 0x30, 0x22,
  2963. 0x31, 0x0B,
  2964. 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53,
  2965. 0x31, 0x13,
  2966. 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0C, 0x0A,
  2967. 0x43, 0x61, 0x6c, 0x69, 0x66, 0x6f, 0x72, 0x6e, 0x69, 0x61
  2968. };
  2969. /* load in CA private key for signing */
  2970. pt = ca_key_der_2048;
  2971. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, &pt,
  2972. sizeof_ca_key_der_2048));
  2973. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  2974. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert,
  2975. WOLFSSL_FILETYPE_ASN1));
  2976. ExpectNotNull((der = wolfSSL_X509_get_der(ca, &derSz)));
  2977. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  2978. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2979. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  2980. WOLFSSL_FILETYPE_PEM));
  2981. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  2982. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  2983. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  2984. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  2985. #else
  2986. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  2987. #endif
  2988. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  2989. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  2990. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  2991. /* add in matching DIR alt name and resign */
  2992. wolfSSL_X509_add_altname_ex(x509, altName, sizeof(altName), ASN_DIR_TYPE);
  2993. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  2994. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  2995. #else
  2996. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  2997. #endif
  2998. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  2999. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3000. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3001. wolfSSL_X509_free(x509);
  3002. x509 = NULL;
  3003. /* check verify fail */
  3004. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3005. WOLFSSL_FILETYPE_PEM));
  3006. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3007. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3008. /* add in miss matching DIR alt name and resign */
  3009. wolfSSL_X509_add_altname_ex(x509, altNameFail, sizeof(altNameFail),
  3010. ASN_DIR_TYPE);
  3011. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  3012. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  3013. #else
  3014. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  3015. #endif
  3016. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  3017. #ifndef WOLFSSL_NO_ASN_STRICT
  3018. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3019. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3020. #else
  3021. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3022. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3023. #endif
  3024. /* check that it still fails if one bad altname and one good altname is in
  3025. * the certificate */
  3026. wolfSSL_X509_free(x509);
  3027. x509 = NULL;
  3028. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3029. WOLFSSL_FILETYPE_PEM));
  3030. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3031. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3032. wolfSSL_X509_add_altname_ex(x509, altName, sizeof(altName), ASN_DIR_TYPE);
  3033. wolfSSL_X509_add_altname_ex(x509, altNameFail, sizeof(altNameFail),
  3034. ASN_DIR_TYPE);
  3035. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  3036. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  3037. #else
  3038. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  3039. #endif
  3040. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  3041. #ifndef WOLFSSL_NO_ASN_STRICT
  3042. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3043. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3044. #else
  3045. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3046. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3047. #endif
  3048. /* check it fails with switching position of bad altname */
  3049. wolfSSL_X509_free(x509);
  3050. x509 = NULL;
  3051. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3052. WOLFSSL_FILETYPE_PEM));
  3053. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3054. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3055. wolfSSL_X509_add_altname_ex(x509, altNameFail, sizeof(altNameFail),
  3056. ASN_DIR_TYPE);
  3057. wolfSSL_X509_add_altname_ex(x509, altName, sizeof(altName), ASN_DIR_TYPE);
  3058. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  3059. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  3060. #else
  3061. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  3062. #endif
  3063. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  3064. #ifndef WOLFSSL_NO_ASN_STRICT
  3065. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3066. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3067. #else
  3068. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3069. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3070. #endif
  3071. wolfSSL_CertManagerFree(cm);
  3072. wolfSSL_X509_free(x509);
  3073. x509 = NULL;
  3074. wolfSSL_X509_free(ca);
  3075. ca = NULL;
  3076. /* now test with excluded name constraint */
  3077. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  3078. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert2,
  3079. WOLFSSL_FILETYPE_ASN1));
  3080. ExpectNotNull((der = wolfSSL_X509_get_der(ca, &derSz)));
  3081. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  3082. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3083. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3084. WOLFSSL_FILETYPE_PEM));
  3085. wolfSSL_X509_add_altname_ex(x509, altNameExc, sizeof(altNameExc),
  3086. ASN_DIR_TYPE);
  3087. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3088. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3089. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  3090. wolfSSL_X509_sign(x509, priv, EVP_sha3_256());
  3091. #else
  3092. wolfSSL_X509_sign(x509, priv, EVP_sha256());
  3093. #endif
  3094. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  3095. #ifndef WOLFSSL_NO_ASN_STRICT
  3096. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3097. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3098. #else
  3099. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3100. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3101. #endif
  3102. wolfSSL_CertManagerFree(cm);
  3103. wolfSSL_X509_free(x509);
  3104. wolfSSL_X509_free(ca);
  3105. wolfSSL_EVP_PKEY_free(priv);
  3106. #endif
  3107. return EXPECT_RESULT();
  3108. }
  3109. static int test_wolfSSL_CertManagerNameConstraint3(void)
  3110. {
  3111. EXPECT_DECLS;
  3112. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  3113. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  3114. defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && \
  3115. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ALT_NAMES) && \
  3116. !defined(NO_SHA256)
  3117. WOLFSSL_CERT_MANAGER* cm = NULL;
  3118. WOLFSSL_EVP_PKEY *priv = NULL;
  3119. WOLFSSL_X509_NAME* name = NULL;
  3120. const char* ca_cert = "./certs/test/cert-ext-mnc.der";
  3121. const char* server_cert = "./certs/test/server-goodcn.pem";
  3122. byte *der = NULL;
  3123. int derSz = 0;
  3124. byte *pt;
  3125. WOLFSSL_X509 *x509 = NULL;
  3126. WOLFSSL_X509 *ca = NULL;
  3127. pt = (byte*)server_key_der_2048;
  3128. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  3129. (const unsigned char**)&pt, sizeof_server_key_der_2048));
  3130. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  3131. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert,
  3132. WOLFSSL_FILETYPE_ASN1));
  3133. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz)));
  3134. DEBUG_WRITE_DER(der, derSz, "ca.der");
  3135. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  3136. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3137. /* check satisfying .wolfssl.com constraint passes */
  3138. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3139. WOLFSSL_FILETYPE_PEM));
  3140. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3141. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3142. name = NULL;
  3143. ExpectNotNull(name = X509_NAME_new());
  3144. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3145. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3146. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3147. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3148. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  3149. (byte*)"support@info.wolfssl.com", 24, -1, 0), SSL_SUCCESS);
  3150. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3151. X509_NAME_free(name);
  3152. name = NULL;
  3153. wolfSSL_X509_add_altname(x509, "wolfssl@info.wolfssl.com", ASN_RFC822_TYPE);
  3154. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3155. DEBUG_WRITE_CERT_X509(x509, "good-1st-constraint-cert.pem");
  3156. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3157. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3158. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3159. wolfSSL_X509_free(x509);
  3160. x509 = NULL;
  3161. /* check satisfying .random.com constraint passes */
  3162. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3163. WOLFSSL_FILETYPE_PEM));
  3164. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3165. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3166. name = NULL;
  3167. ExpectNotNull(name = X509_NAME_new());
  3168. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3169. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3170. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3171. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3172. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  3173. (byte*)"support@info.example.com", 24, -1, 0), SSL_SUCCESS);
  3174. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3175. X509_NAME_free(name);
  3176. name = NULL;
  3177. wolfSSL_X509_add_altname(x509, "wolfssl@info.example.com", ASN_RFC822_TYPE);
  3178. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3179. DEBUG_WRITE_CERT_X509(x509, "good-2nd-constraint-cert.pem");
  3180. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3181. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3182. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3183. wolfSSL_X509_free(x509);
  3184. x509 = NULL;
  3185. /* check fail case when neither constraint is matched */
  3186. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3187. WOLFSSL_FILETYPE_PEM));
  3188. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3189. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3190. name = NULL;
  3191. ExpectNotNull(name = X509_NAME_new());
  3192. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3193. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3194. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3195. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3196. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  3197. (byte*)"support@info.com", 16, -1, 0), SSL_SUCCESS);
  3198. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3199. X509_NAME_free(name);
  3200. wolfSSL_X509_add_altname(x509, "wolfssl@info.com", ASN_RFC822_TYPE);
  3201. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3202. DEBUG_WRITE_CERT_X509(x509, "bad-cert.pem");
  3203. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3204. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3205. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3206. wolfSSL_CertManagerFree(cm);
  3207. wolfSSL_X509_free(x509);
  3208. wolfSSL_X509_free(ca);
  3209. wolfSSL_EVP_PKEY_free(priv);
  3210. #endif
  3211. return EXPECT_RESULT();
  3212. }
  3213. static int test_wolfSSL_CertManagerNameConstraint4(void)
  3214. {
  3215. EXPECT_DECLS;
  3216. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  3217. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  3218. defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && \
  3219. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ALT_NAMES) && \
  3220. !defined(NO_SHA256)
  3221. WOLFSSL_CERT_MANAGER* cm = NULL;
  3222. WOLFSSL_EVP_PKEY *priv = NULL;
  3223. WOLFSSL_X509_NAME* name = NULL;
  3224. const char* ca_cert = "./certs/test/cert-ext-ncdns.der";
  3225. const char* server_cert = "./certs/test/server-goodcn.pem";
  3226. byte *der = NULL;
  3227. int derSz;
  3228. byte *pt;
  3229. WOLFSSL_X509 *x509 = NULL;
  3230. WOLFSSL_X509 *ca = NULL;
  3231. pt = (byte*)server_key_der_2048;
  3232. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  3233. (const unsigned char**)&pt, sizeof_server_key_der_2048));
  3234. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  3235. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert,
  3236. WOLFSSL_FILETYPE_ASN1));
  3237. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz)));
  3238. DEBUG_WRITE_DER(der, derSz, "ca.der");
  3239. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  3240. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3241. /* check satisfying wolfssl.com constraint passes */
  3242. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3243. WOLFSSL_FILETYPE_PEM));
  3244. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3245. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3246. name = NULL;
  3247. ExpectNotNull(name = X509_NAME_new());
  3248. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3249. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3250. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3251. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3252. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3253. X509_NAME_free(name);
  3254. name = NULL;
  3255. wolfSSL_X509_add_altname(x509, "www.wolfssl.com", ASN_DNS_TYPE);
  3256. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3257. DEBUG_WRITE_CERT_X509(x509, "good-1st-constraint-cert.pem");
  3258. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3259. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3260. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3261. wolfSSL_X509_free(x509);
  3262. x509 = NULL;
  3263. /* check satisfying example.com constraint passes */
  3264. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3265. WOLFSSL_FILETYPE_PEM));
  3266. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3267. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3268. name = NULL;
  3269. ExpectNotNull(name = X509_NAME_new());
  3270. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3271. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3272. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3273. (byte*)"example.com", 11, -1, 0), SSL_SUCCESS);
  3274. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3275. X509_NAME_free(name);
  3276. name = NULL;
  3277. wolfSSL_X509_add_altname(x509, "www.example.com", ASN_DNS_TYPE);
  3278. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3279. DEBUG_WRITE_CERT_X509(x509, "good-2nd-constraint-cert.pem");
  3280. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3281. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3282. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3283. wolfSSL_X509_free(x509);
  3284. x509 = NULL;
  3285. /* check satisfying wolfssl.com constraint passes with list of DNS's */
  3286. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3287. WOLFSSL_FILETYPE_PEM));
  3288. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3289. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3290. name = NULL;
  3291. ExpectNotNull(name = X509_NAME_new());
  3292. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3293. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3294. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3295. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3296. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3297. X509_NAME_free(name);
  3298. name = NULL;
  3299. wolfSSL_X509_add_altname(x509, "www.wolfssl.com", ASN_DNS_TYPE);
  3300. wolfSSL_X509_add_altname(x509, "www.info.wolfssl.com", ASN_DNS_TYPE);
  3301. wolfSSL_X509_add_altname(x509, "extra.wolfssl.com", ASN_DNS_TYPE);
  3302. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3303. DEBUG_WRITE_CERT_X509(x509, "good-multiple-constraint-cert.pem");
  3304. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3305. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3306. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3307. wolfSSL_X509_free(x509);
  3308. x509 = NULL;
  3309. /* check fail when one DNS in the list is bad */
  3310. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3311. WOLFSSL_FILETYPE_PEM));
  3312. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3313. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3314. name = NULL;
  3315. ExpectNotNull(name = X509_NAME_new());
  3316. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3317. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3318. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3319. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3320. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3321. X509_NAME_free(name);
  3322. name = NULL;
  3323. wolfSSL_X509_add_altname(x509, "www.wolfssl.com", ASN_DNS_TYPE);
  3324. wolfSSL_X509_add_altname(x509, "www.nomatch.com", ASN_DNS_TYPE);
  3325. wolfSSL_X509_add_altname(x509, "www.info.wolfssl.com", ASN_DNS_TYPE);
  3326. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3327. DEBUG_WRITE_CERT_X509(x509, "bad-multiple-constraint-cert.pem");
  3328. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3329. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3330. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3331. wolfSSL_X509_free(x509);
  3332. x509 = NULL;
  3333. /* check fail case when neither constraint is matched */
  3334. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3335. WOLFSSL_FILETYPE_PEM));
  3336. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3337. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3338. name = NULL;
  3339. ExpectNotNull(name = X509_NAME_new());
  3340. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3341. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3342. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3343. (byte*)"common", 6, -1, 0), SSL_SUCCESS);
  3344. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3345. X509_NAME_free(name);
  3346. wolfSSL_X509_add_altname(x509, "www.random.com", ASN_DNS_TYPE);
  3347. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3348. DEBUG_WRITE_CERT_X509(x509, "bad-cert.pem");
  3349. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3350. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3351. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3352. wolfSSL_CertManagerFree(cm);
  3353. wolfSSL_X509_free(x509);
  3354. wolfSSL_X509_free(ca);
  3355. wolfSSL_EVP_PKEY_free(priv);
  3356. #endif
  3357. return EXPECT_RESULT();
  3358. }
  3359. static int test_wolfSSL_CertManagerNameConstraint5(void)
  3360. {
  3361. EXPECT_DECLS;
  3362. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  3363. !defined(NO_WOLFSSL_CM_VERIFY) && !defined(NO_RSA) && \
  3364. defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && \
  3365. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_ALT_NAMES) && \
  3366. !defined(NO_SHA256)
  3367. WOLFSSL_CERT_MANAGER* cm = NULL;
  3368. WOLFSSL_EVP_PKEY *priv = NULL;
  3369. WOLFSSL_X509_NAME* name = NULL;
  3370. const char* ca_cert = "./certs/test/cert-ext-ncmixed.der";
  3371. const char* server_cert = "./certs/test/server-goodcn.pem";
  3372. byte *der = NULL;
  3373. int derSz;
  3374. byte *pt;
  3375. WOLFSSL_X509 *x509 = NULL;
  3376. WOLFSSL_X509 *ca = NULL;
  3377. pt = (byte*)server_key_der_2048;
  3378. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  3379. (const unsigned char**)&pt, sizeof_server_key_der_2048));
  3380. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  3381. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(ca_cert,
  3382. WOLFSSL_FILETYPE_ASN1));
  3383. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(ca, &derSz)));
  3384. DEBUG_WRITE_DER(der, derSz, "ca.der");
  3385. ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, der, derSz,
  3386. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3387. /* check satisfying wolfssl.com constraint passes */
  3388. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3389. WOLFSSL_FILETYPE_PEM));
  3390. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3391. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3392. name = NULL;
  3393. ExpectNotNull(name = X509_NAME_new());
  3394. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3395. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3396. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3397. (byte*)"example", 7, -1, 0), SSL_SUCCESS);
  3398. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3399. X509_NAME_free(name);
  3400. name = NULL;
  3401. wolfSSL_X509_add_altname(x509, "good.example", ASN_DNS_TYPE);
  3402. wolfSSL_X509_add_altname(x509, "facts@into.wolfssl.com", ASN_RFC822_TYPE);
  3403. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3404. DEBUG_WRITE_CERT_X509(x509, "good-cert.pem");
  3405. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3406. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3407. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3408. wolfSSL_X509_free(x509);
  3409. x509 = NULL;
  3410. /* fail with DNS check because of common name */
  3411. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3412. WOLFSSL_FILETYPE_PEM));
  3413. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3414. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3415. name = NULL;
  3416. ExpectNotNull(name = X509_NAME_new());
  3417. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3418. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3419. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  3420. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  3421. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3422. X509_NAME_free(name);
  3423. name = NULL;
  3424. wolfSSL_X509_add_altname(x509, "example", ASN_DNS_TYPE);
  3425. wolfSSL_X509_add_altname(x509, "facts@wolfssl.com", ASN_RFC822_TYPE);
  3426. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3427. DEBUG_WRITE_CERT_X509(x509, "bad-cn-cert.pem");
  3428. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3429. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3430. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3431. wolfSSL_X509_free(x509);
  3432. x509 = NULL;
  3433. /* fail on permitted DNS name constraint */
  3434. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3435. WOLFSSL_FILETYPE_PEM));
  3436. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3437. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3438. name = NULL;
  3439. ExpectNotNull(name = X509_NAME_new());
  3440. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3441. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3442. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3443. X509_NAME_free(name);
  3444. name = NULL;
  3445. wolfSSL_X509_add_altname(x509, "www.example", ASN_DNS_TYPE);
  3446. wolfSSL_X509_add_altname(x509, "www.wolfssl", ASN_DNS_TYPE);
  3447. wolfSSL_X509_add_altname(x509, "info@wolfssl.com", ASN_RFC822_TYPE);
  3448. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3449. DEBUG_WRITE_CERT_X509(x509, "bad-1st-constraint-cert.pem");
  3450. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3451. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3452. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3453. wolfSSL_X509_free(x509);
  3454. x509 = NULL;
  3455. /* fail on permitted email name constraint */
  3456. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3457. WOLFSSL_FILETYPE_PEM));
  3458. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3459. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3460. name = NULL;
  3461. ExpectNotNull(name = X509_NAME_new());
  3462. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3463. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3464. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3465. X509_NAME_free(name);
  3466. name = NULL;
  3467. wolfSSL_X509_add_altname(x509, "example", ASN_DNS_TYPE);
  3468. wolfSSL_X509_add_altname(x509, "info@wolfssl.com", ASN_RFC822_TYPE);
  3469. wolfSSL_X509_add_altname(x509, "info@example.com", ASN_RFC822_TYPE);
  3470. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3471. DEBUG_WRITE_CERT_X509(x509, "bad-2nd-constraint-cert.pem");
  3472. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3473. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3474. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_NAME_INVALID_E));
  3475. wolfSSL_X509_free(x509);
  3476. x509 = NULL;
  3477. /* success with empty email name */
  3478. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(server_cert,
  3479. WOLFSSL_FILETYPE_PEM));
  3480. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  3481. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  3482. name = NULL;
  3483. ExpectNotNull(name = X509_NAME_new());
  3484. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  3485. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  3486. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  3487. X509_NAME_free(name);
  3488. wolfSSL_X509_add_altname(x509, "example", ASN_DNS_TYPE);
  3489. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  3490. DEBUG_WRITE_CERT_X509(x509, "good-missing-constraint-cert.pem");
  3491. ExpectNotNull((der = (byte*)wolfSSL_X509_get_der(x509, &derSz)));
  3492. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, der, derSz,
  3493. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  3494. wolfSSL_X509_free(x509);
  3495. wolfSSL_CertManagerFree(cm);
  3496. wolfSSL_X509_free(ca);
  3497. wolfSSL_EVP_PKEY_free(priv);
  3498. #endif
  3499. return EXPECT_RESULT();
  3500. }
  3501. static int test_wolfSSL_CertManagerCRL(void)
  3502. {
  3503. EXPECT_DECLS;
  3504. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && defined(HAVE_CRL) && \
  3505. !defined(NO_RSA)
  3506. const char* ca_cert = "./certs/ca-cert.pem";
  3507. const char* crl1 = "./certs/crl/crl.pem";
  3508. const char* crl2 = "./certs/crl/crl2.pem";
  3509. #ifdef WC_RSA_PSS
  3510. const char* crl_rsapss = "./certs/crl/crl_rsapss.pem";
  3511. const char* ca_rsapss = "./certs/rsapss/ca-rsapss.pem";
  3512. #endif
  3513. const unsigned char crl_buff[] = {
  3514. 0x30, 0x82, 0x02, 0x04, 0x30, 0x81, 0xed, 0x02,
  3515. 0x01, 0x01, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86,
  3516. 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05,
  3517. 0x00, 0x30, 0x81, 0x94, 0x31, 0x0b, 0x30, 0x09,
  3518. 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55,
  3519. 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55,
  3520. 0x04, 0x08, 0x0c, 0x07, 0x4d, 0x6f, 0x6e, 0x74,
  3521. 0x61, 0x6e, 0x61, 0x31, 0x10, 0x30, 0x0e, 0x06,
  3522. 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f,
  3523. 0x7a, 0x65, 0x6d, 0x61, 0x6e, 0x31, 0x11, 0x30,
  3524. 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08,
  3525. 0x53, 0x61, 0x77, 0x74, 0x6f, 0x6f, 0x74, 0x68,
  3526. 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04,
  3527. 0x0b, 0x0c, 0x0a, 0x43, 0x6f, 0x6e, 0x73, 0x75,
  3528. 0x6c, 0x74, 0x69, 0x6e, 0x67, 0x31, 0x18, 0x30,
  3529. 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f,
  3530. 0x77, 0x77, 0x77, 0x2e, 0x77, 0x6f, 0x6c, 0x66,
  3531. 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x31,
  3532. 0x1f, 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48,
  3533. 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x10,
  3534. 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c,
  3535. 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d,
  3536. 0x17, 0x0d, 0x32, 0x32, 0x31, 0x32, 0x31, 0x36,
  3537. 0x32, 0x31, 0x31, 0x37, 0x35, 0x30, 0x5a, 0x17,
  3538. 0x0d, 0x32, 0x35, 0x30, 0x39, 0x31, 0x31, 0x32,
  3539. 0x31, 0x31, 0x37, 0x35, 0x30, 0x5a, 0x30, 0x14,
  3540. 0x30, 0x12, 0x02, 0x01, 0x02, 0x17, 0x0d, 0x32,
  3541. 0x32, 0x31, 0x32, 0x31, 0x36, 0x32, 0x31, 0x31,
  3542. 0x37, 0x35, 0x30, 0x5a, 0xa0, 0x0e, 0x30, 0x0c,
  3543. 0x30, 0x0a, 0x06, 0x03, 0x55, 0x1d, 0x14, 0x04,
  3544. 0x03, 0x02, 0x01, 0x02, 0x30, 0x0d, 0x06, 0x09,
  3545. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
  3546. 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00,
  3547. 0x39, 0x44, 0xff, 0x39, 0xf4, 0x04, 0x45, 0x79,
  3548. 0x7e, 0x73, 0xe2, 0x42, 0x48, 0xdb, 0x85, 0x66,
  3549. 0xfd, 0x99, 0x76, 0x94, 0x7c, 0xb5, 0x79, 0x5d,
  3550. 0x15, 0x71, 0x36, 0xa9, 0x87, 0xf0, 0x73, 0x05,
  3551. 0x50, 0x08, 0x6b, 0x1c, 0x6e, 0xde, 0x96, 0x45,
  3552. 0x31, 0xc3, 0xc0, 0xba, 0xba, 0xf5, 0x08, 0x1d,
  3553. 0x05, 0x4a, 0x52, 0x39, 0xe9, 0x03, 0xef, 0x59,
  3554. 0xc8, 0x1d, 0x4a, 0xf2, 0x86, 0x05, 0x99, 0x7b,
  3555. 0x4b, 0x74, 0xf6, 0xd3, 0x75, 0x8d, 0xb2, 0x57,
  3556. 0xba, 0xac, 0xa7, 0x11, 0x14, 0xd6, 0x6c, 0x71,
  3557. 0xc4, 0x4c, 0x1c, 0x68, 0xbc, 0x49, 0x78, 0xf0,
  3558. 0xc9, 0x52, 0x8a, 0xe7, 0x8b, 0x54, 0xe6, 0x20,
  3559. 0x58, 0x20, 0x60, 0x66, 0xf5, 0x14, 0xd8, 0xcb,
  3560. 0xff, 0xe0, 0xa0, 0x45, 0xbc, 0xb4, 0x81, 0xad,
  3561. 0x1d, 0xbc, 0xcf, 0xf8, 0x8e, 0xa8, 0x87, 0x24,
  3562. 0x55, 0x99, 0xd9, 0xce, 0x47, 0xf7, 0x5b, 0x4a,
  3563. 0x33, 0x6d, 0xdb, 0xbf, 0x93, 0x64, 0x1a, 0xa6,
  3564. 0x46, 0x5f, 0x27, 0xdc, 0xd8, 0xd4, 0xf9, 0xc2,
  3565. 0x42, 0x2a, 0x7e, 0xb2, 0x7c, 0xdd, 0x98, 0x77,
  3566. 0xf5, 0x88, 0x7d, 0x15, 0x25, 0x08, 0xbc, 0xe0,
  3567. 0xd0, 0x8d, 0xf4, 0xc3, 0xc3, 0x04, 0x41, 0xa4,
  3568. 0xd1, 0xb1, 0x39, 0x4a, 0x6b, 0x2c, 0xb5, 0x2e,
  3569. 0x9a, 0x65, 0x43, 0x0d, 0x0e, 0x73, 0xf4, 0x06,
  3570. 0xe1, 0xb3, 0x49, 0x34, 0x94, 0xb0, 0xb7, 0xff,
  3571. 0xc0, 0x27, 0xc1, 0xb5, 0xea, 0x06, 0xf7, 0x71,
  3572. 0x71, 0x97, 0xbb, 0xbc, 0xc7, 0x1a, 0x9f, 0xeb,
  3573. 0xf6, 0x3d, 0xa5, 0x7b, 0x55, 0xa7, 0xbf, 0xdd,
  3574. 0xd7, 0xee, 0x97, 0xb8, 0x9d, 0xdc, 0xcd, 0xe3,
  3575. 0x06, 0xdb, 0x9a, 0x2c, 0x60, 0xbf, 0x70, 0x84,
  3576. 0xfa, 0x6b, 0x8d, 0x70, 0x7d, 0xde, 0xe8, 0xb7,
  3577. 0xab, 0xb0, 0x38, 0x68, 0x6c, 0xc0, 0xb1, 0xe1,
  3578. 0xba, 0x45, 0xe0, 0xd7, 0x12, 0x3d, 0x71, 0x5b
  3579. };
  3580. WOLFSSL_CERT_MANAGER* cm = NULL;
  3581. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  3582. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3583. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), 1);
  3584. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECK), 1);
  3585. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm,
  3586. WOLFSSL_CRL_CHECK | WOLFSSL_CRL_CHECKALL), 1);
  3587. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, 16), 1);
  3588. ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL), 1);
  3589. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(NULL, NULL, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3590. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, NULL, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3591. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(NULL, server_cert_der_2048, -1),
  3592. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3593. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3594. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(NULL, server_cert_der_2048, 1),
  3595. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3596. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3597. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048, -1),
  3598. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3599. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048,
  3600. sizeof_server_cert_der_2048), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  3601. ExpectIntEQ(wolfSSL_CertManagerSetCRL_Cb(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3602. ExpectIntEQ(wolfSSL_CertManagerSetCRL_Cb(cm, NULL), 1);
  3603. #ifdef HAVE_CRL_IO
  3604. ExpectIntEQ(wolfSSL_CertManagerSetCRL_IOCb(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3605. ExpectIntEQ(wolfSSL_CertManagerSetCRL_IOCb(cm, NULL), 1);
  3606. #endif
  3607. #ifndef NO_FILESYSTEM
  3608. ExpectIntEQ(wolfSSL_CertManagerLoadCRL(NULL, NULL, WOLFSSL_FILETYPE_ASN1,
  3609. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3610. ExpectIntEQ(wolfSSL_CertManagerLoadCRL(cm, NULL, WOLFSSL_FILETYPE_ASN1,
  3611. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3612. /* -1 seen as !WOLFSSL_FILETYPE_PEM */
  3613. ExpectIntEQ(wolfSSL_CertManagerLoadCRL(cm, "./certs/crl", -1, 0), 1);
  3614. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(NULL, NULL,
  3615. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3616. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, NULL, WOLFSSL_FILETYPE_ASN1),
  3617. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3618. /* -1 seen as !WOLFSSL_FILETYPE_PEM */
  3619. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, "./certs/crl/crl.pem", -1),
  3620. WC_NO_ERR_TRACE(ASN_PARSE_E));
  3621. #endif
  3622. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(NULL, NULL, -1,
  3623. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3624. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, NULL, -1,
  3625. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3626. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(NULL, crl_buff, -1,
  3627. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3628. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(NULL, NULL, 1,
  3629. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3630. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(NULL, crl_buff, 1,
  3631. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3632. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, NULL, 1,
  3633. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3634. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_buff, -1,
  3635. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3636. ExpectIntEQ(wolfSSL_CertManagerFreeCRL(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  3637. DoExpectIntEQ(wolfSSL_CertManagerFreeCRL(cm), 1);
  3638. ExpectIntEQ(WOLFSSL_SUCCESS,
  3639. wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL));
  3640. ExpectIntEQ(WOLFSSL_SUCCESS,
  3641. wolfSSL_CertManagerLoadCRL(cm, crl1, WOLFSSL_FILETYPE_PEM, 0));
  3642. ExpectIntEQ(WOLFSSL_SUCCESS,
  3643. wolfSSL_CertManagerLoadCRL(cm, crl2, WOLFSSL_FILETYPE_PEM, 0));
  3644. wolfSSL_CertManagerFreeCRL(cm);
  3645. #ifndef WOLFSSL_CRL_ALLOW_MISSING_CDP
  3646. ExpectIntEQ(WOLFSSL_SUCCESS,
  3647. wolfSSL_CertManagerLoadCRL(cm, crl1, WOLFSSL_FILETYPE_PEM, 0));
  3648. ExpectIntEQ(WOLFSSL_SUCCESS,
  3649. wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL));
  3650. ExpectIntEQ(wolfSSL_CertManagerCheckCRL(cm, server_cert_der_2048,
  3651. sizeof_server_cert_der_2048), WC_NO_ERR_TRACE(CRL_MISSING));
  3652. ExpectIntEQ(wolfSSL_CertManagerVerifyBuffer(cm, server_cert_der_2048,
  3653. sizeof_server_cert_der_2048, WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(CRL_MISSING));
  3654. #endif /* !WOLFSSL_CRL_ALLOW_MISSING_CDP */
  3655. ExpectIntEQ(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_buff, sizeof(crl_buff),
  3656. WOLFSSL_FILETYPE_ASN1), 1);
  3657. #if !defined(NO_FILESYSTEM) && defined(WC_RSA_PSS)
  3658. /* loading should fail without the CA set */
  3659. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, crl_rsapss,
  3660. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(ASN_CRL_NO_SIGNER_E));
  3661. /* now successfully load the RSA-PSS crl once loading in it's CA */
  3662. ExpectIntEQ(WOLFSSL_SUCCESS,
  3663. wolfSSL_CertManagerLoadCA(cm, ca_rsapss, NULL));
  3664. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, crl_rsapss,
  3665. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  3666. #endif
  3667. wolfSSL_CertManagerFree(cm);
  3668. #endif
  3669. return EXPECT_RESULT();
  3670. }
  3671. static int test_wolfSSL_CertManagerCheckOCSPResponse(void)
  3672. {
  3673. EXPECT_DECLS;
  3674. #if defined(HAVE_OCSP) && !defined(NO_RSA) && !defined(NO_SHA)
  3675. /* Need one of these for wolfSSL_OCSP_REQUEST_new. */
  3676. #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \
  3677. defined(WOLFSSL_HAPROXY) || defined(WOLFSSL_APACHE_HTTPD) || \
  3678. defined(HAVE_LIGHTY)
  3679. WOLFSSL_CERT_MANAGER* cm = NULL;
  3680. /* Raw OCSP response bytes captured using the following setup:
  3681. * - Run responder with
  3682. * openssl ocsp -port 9999 -ndays 9999
  3683. * -index certs/ocsp/index-intermediate1-ca-issued-certs.txt
  3684. * -rsigner certs/ocsp/ocsp-responder-cert.pem
  3685. * -rkey certs/ocsp/ocsp-responder-key.pem
  3686. * -CA certs/ocsp/intermediate1-ca-cert.pem
  3687. * - Run client with
  3688. * openssl ocsp -host 127.0.0.1:9999 -respout resp.out
  3689. * -issuer certs/ocsp/intermediate1-ca-cert.pem
  3690. * -cert certs/ocsp/server1-cert.pem
  3691. * -CAfile certs/ocsp/root-ca-cert.pem -noverify
  3692. * - Select the response packet in Wireshark, and export it using
  3693. * "File->Export Packet Dissection->As "C" Arrays". Select "Selected
  3694. * packets only". After importing into the editor, remove the initial
  3695. * ~148 bytes of header, ending with the Content-Length and the \r\n\r\n.
  3696. */
  3697. static const byte response[] = {
  3698. 0x30, 0x82, 0x07, 0x40, /* ....0..@ */
  3699. 0x0a, 0x01, 0x00, 0xa0, 0x82, 0x07, 0x39, 0x30, /* ......90 */
  3700. 0x82, 0x07, 0x35, 0x06, 0x09, 0x2b, 0x06, 0x01, /* ..5..+.. */
  3701. 0x05, 0x05, 0x07, 0x30, 0x01, 0x01, 0x04, 0x82, /* ...0.... */
  3702. 0x07, 0x26, 0x30, 0x82, 0x07, 0x22, 0x30, 0x82, /* .&0.."0. */
  3703. 0x01, 0x40, 0xa1, 0x81, 0xa1, 0x30, 0x81, 0x9e, /* .@...0.. */
  3704. 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, /* 1.0...U. */
  3705. 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, /* ...US1.0 */
  3706. 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a, /* ...U.... */
  3707. 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67, 0x74, /* Washingt */
  3708. 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, /* on1.0... */
  3709. 0x55, 0x04, 0x07, 0x0c, 0x07, 0x53, 0x65, 0x61, /* U....Sea */
  3710. 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10, 0x30, 0x0e, /* ttle1.0. */
  3711. 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x77, /* ..U....w */
  3712. 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x31, 0x14, /* olfSSL1. */
  3713. 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, /* 0...U... */
  3714. 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, /* .Enginee */
  3715. 0x72, 0x69, 0x6e, 0x67, 0x31, 0x1f, 0x30, 0x1d, /* ring1.0. */
  3716. 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x16, 0x77, /* ..U....w */
  3717. 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x4f, /* olfSSL O */
  3718. 0x43, 0x53, 0x50, 0x20, 0x52, 0x65, 0x73, 0x70, /* CSP Resp */
  3719. 0x6f, 0x6e, 0x64, 0x65, 0x72, 0x31, 0x1f, 0x30, /* onder1.0 */
  3720. 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, /* ...*.H.. */
  3721. 0x0d, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6e, /* ......in */
  3722. 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, 0x66, 0x73, /* fo@wolfs */
  3723. 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x18, 0x0f, /* sl.com.. */
  3724. 0x32, 0x30, 0x32, 0x33, 0x31, 0x31, 0x30, 0x38, /* 20231108 */
  3725. 0x30, 0x30, 0x32, 0x36, 0x33, 0x37, 0x5a, 0x30, /* 002637Z0 */
  3726. 0x64, 0x30, 0x62, 0x30, 0x3a, 0x30, 0x09, 0x06, /* d0b0:0.. */
  3727. 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, /* .+...... */
  3728. 0x04, 0x14, 0x71, 0x4d, 0x82, 0x23, 0x40, 0x59, /* ..qM.#@Y */
  3729. 0xc0, 0x96, 0xa1, 0x37, 0x43, 0xfa, 0x31, 0xdb, /* ...7C.1. */
  3730. 0xba, 0xb1, 0x43, 0x18, 0xda, 0x04, 0x04, 0x14, /* ..C..... */
  3731. 0x83, 0xc6, 0x3a, 0x89, 0x2c, 0x81, 0xf4, 0x02, /* ..:.,... */
  3732. 0xd7, 0x9d, 0x4c, 0xe2, 0x2a, 0xc0, 0x71, 0x82, /* ..L.*.q. */
  3733. 0x64, 0x44, 0xda, 0x0e, 0x02, 0x01, 0x05, 0x80, /* dD...... */
  3734. 0x00, 0x18, 0x0f, 0x32, 0x30, 0x32, 0x33, 0x31, /* ...20231 */
  3735. 0x31, 0x30, 0x38, 0x30, 0x30, 0x32, 0x36, 0x33, /* 10800263 */
  3736. 0x37, 0x5a, 0xa0, 0x11, 0x18, 0x0f, 0x32, 0x30, /* 7Z....20 */
  3737. 0x35, 0x31, 0x30, 0x33, 0x32, 0x35, 0x30, 0x30, /* 51032500 */
  3738. 0x32, 0x36, 0x33, 0x37, 0x5a, 0xa1, 0x23, 0x30, /* 2637Z.#0 */
  3739. 0x21, 0x30, 0x1f, 0x06, 0x09, 0x2b, 0x06, 0x01, /* !0...+.. */
  3740. 0x05, 0x05, 0x07, 0x30, 0x01, 0x02, 0x04, 0x12, /* ...0.... */
  3741. 0x04, 0x10, 0xdb, 0xbc, 0x2a, 0x76, 0xa0, 0xb4, /* ....*v.. */
  3742. 0x1e, 0x5d, 0xf6, 0x2b, 0x8e, 0x38, 0x62, 0xdb, /* .].+.8b. */
  3743. 0x90, 0xed, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, /* ..0...*. */
  3744. 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, /* H....... */
  3745. 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x87, 0xde, /* ........ */
  3746. 0xfb, 0xf9, 0x3a, 0x90, 0x1f, 0x90, 0xde, 0xcf, /* ..:..... */
  3747. 0xfe, 0xad, 0x64, 0x19, 0x34, 0x17, 0xf8, 0x15, /* ..d.4... */
  3748. 0x01, 0x22, 0x5f, 0x67, 0x41, 0xa4, 0x18, 0xf7, /* ."_gA... */
  3749. 0x16, 0xb7, 0xc9, 0xf3, 0xe1, 0x9f, 0xcd, 0x40, /* .......@ */
  3750. 0x56, 0x77, 0x6e, 0x6a, 0xfb, 0x92, 0x6a, 0x6f, /* Vwnj..jo */
  3751. 0x28, 0x3e, 0x22, 0x48, 0xa1, 0xc2, 0xd8, 0x1d, /* (>"H.... */
  3752. 0xc7, 0xe6, 0x78, 0x7f, 0xb6, 0x09, 0xfe, 0x2c, /* ..x...., */
  3753. 0xb5, 0xef, 0x29, 0x7c, 0xc5, 0x51, 0x16, 0x7b, /* ..)|.Q.{ */
  3754. 0x8f, 0xfb, 0x44, 0xa8, 0xcd, 0xf5, 0x5c, 0x0f, /* ..D...\. */
  3755. 0x46, 0x0e, 0xb1, 0xa4, 0xeb, 0x5b, 0xf5, 0x86, /* F....[.. */
  3756. 0x11, 0x0f, 0xcd, 0xe2, 0xe5, 0x3c, 0x91, 0x72, /* .....<.r */
  3757. 0x0d, 0x6a, 0xcb, 0x95, 0x99, 0x39, 0x91, 0x48, /* .j...9.H */
  3758. 0x65, 0x97, 0xb9, 0x78, 0xb5, 0x88, 0x7f, 0x76, /* e..x...v */
  3759. 0xa1, 0x43, 0x2f, 0xf6, 0x1f, 0x49, 0xb7, 0x08, /* .C/..I.. */
  3760. 0x36, 0xe4, 0x2e, 0x34, 0x25, 0xda, 0x16, 0x74, /* 6..4%..t */
  3761. 0x47, 0x62, 0x56, 0xff, 0x2f, 0x02, 0x03, 0x44, /* GbV./..D */
  3762. 0x89, 0x04, 0xe7, 0xb8, 0xde, 0x0a, 0x35, 0x43, /* ......5C */
  3763. 0xae, 0xd7, 0x54, 0xbe, 0xc3, 0x7c, 0x95, 0xa5, /* ..T..|.. */
  3764. 0xc8, 0xe0, 0x2e, 0x52, 0xb6, 0xea, 0x99, 0x45, /* ...R...E */
  3765. 0xfd, 0xda, 0x4b, 0xd5, 0x79, 0x07, 0x64, 0xca, /* ..K.y.d. */
  3766. 0x64, 0xba, 0x52, 0x12, 0x62, 0x8c, 0x08, 0x9a, /* d.R.b... */
  3767. 0x32, 0xeb, 0x85, 0x65, 0x05, 0x39, 0x07, 0x5d, /* 2..e.9.] */
  3768. 0x39, 0x4a, 0xcf, 0xa5, 0x30, 0xf6, 0xd1, 0xf7, /* 9J..0... */
  3769. 0x29, 0xaa, 0x23, 0x42, 0xc6, 0x85, 0x16, 0x7f, /* ).#B.... */
  3770. 0x64, 0x16, 0xb1, 0xb0, 0x5d, 0xcd, 0x88, 0x2d, /* d...]..- */
  3771. 0x06, 0xb0, 0xa9, 0xdf, 0xa3, 0x9f, 0x25, 0x41, /* ......%A */
  3772. 0x89, 0x9a, 0x19, 0xe1, 0xaa, 0xcd, 0xdf, 0x51, /* .......Q */
  3773. 0xcb, 0xa9, 0xc3, 0x7e, 0x27, 0xbc, 0x7d, 0x9b, /* ...~'.}. */
  3774. 0x6f, 0x4d, 0x79, 0x87, 0x09, 0x3f, 0xac, 0xd2, /* oMy..?.. */
  3775. 0x4a, 0x3b, 0xbe, 0xf8, 0x7a, 0xa4, 0x93, 0x45, /* J;..z..E */
  3776. 0x11, 0x64, 0x40, 0xc5, 0x03, 0xc9, 0x24, 0x5b, /* .d@...$[ */
  3777. 0xe9, 0x6d, 0xfc, 0x94, 0x08, 0xbe, 0xa0, 0x82, /* .m...... */
  3778. 0x04, 0xc6, 0x30, 0x82, 0x04, 0xc2, 0x30, 0x82, /* ..0...0. */
  3779. 0x04, 0xbe, 0x30, 0x82, 0x03, 0xa6, 0xa0, 0x03, /* ..0..... */
  3780. 0x02, 0x01, 0x02, 0x02, 0x01, 0x04, 0x30, 0x0d, /* ......0. */
  3781. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, /* ..*.H... */
  3782. 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x81, 0x97, /* .....0.. */
  3783. 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, /* 1.0...U. */
  3784. 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, /* ...US1.0 */
  3785. 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a, /* ...U.... */
  3786. 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67, 0x74, /* Washingt */
  3787. 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, /* on1.0... */
  3788. 0x55, 0x04, 0x07, 0x0c, 0x07, 0x53, 0x65, 0x61, /* U....Sea */
  3789. 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10, 0x30, 0x0e, /* ttle1.0. */
  3790. 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x77, /* ..U....w */
  3791. 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x31, 0x14, /* olfSSL1. */
  3792. 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, /* 0...U... */
  3793. 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, /* .Enginee */
  3794. 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18, 0x30, 0x16, /* ring1.0. */
  3795. 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, /* ..U....w */
  3796. 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x72, /* olfSSL r */
  3797. 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x31, 0x1f, /* oot CA1. */
  3798. 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, /* 0...*.H. */
  3799. 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, /* .......i */
  3800. 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, 0x66, /* nfo@wolf */
  3801. 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x30, /* ssl.com0 */
  3802. 0x1e, 0x17, 0x0d, 0x32, 0x32, 0x31, 0x32, 0x31, /* ...22121 */
  3803. 0x36, 0x32, 0x31, 0x31, 0x37, 0x35, 0x30, 0x5a, /* 6211750Z */
  3804. 0x17, 0x0d, 0x32, 0x35, 0x30, 0x39, 0x31, 0x31, /* ..250911 */
  3805. 0x32, 0x31, 0x31, 0x37, 0x35, 0x30, 0x5a, 0x30, /* 211750Z0 */
  3806. 0x81, 0x9e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, /* ..1.0... */
  3807. 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, /* U....US1 */
  3808. 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, /* .0...U.. */
  3809. 0x0c, 0x0a, 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e, /* ..Washin */
  3810. 0x67, 0x74, 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, /* gton1.0. */
  3811. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x53, /* ..U....S */
  3812. 0x65, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10, /* eattle1. */
  3813. 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, /* 0...U... */
  3814. 0x07, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, /* .wolfSSL */
  3815. 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, /* 1.0...U. */
  3816. 0x0b, 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, /* ...Engin */
  3817. 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x1f, /* eering1. */
  3818. 0x30, 0x1d, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, /* 0...U... */
  3819. 0x16, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, /* .wolfSSL */
  3820. 0x20, 0x4f, 0x43, 0x53, 0x50, 0x20, 0x52, 0x65, /* OCSP Re */
  3821. 0x73, 0x70, 0x6f, 0x6e, 0x64, 0x65, 0x72, 0x31, /* sponder1 */
  3822. 0x1f, 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, /* .0...*.H */
  3823. 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x10, /* ........ */
  3824. 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, /* info@wol */
  3825. 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, /* fssl.com */
  3826. 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, /* 0.."0... */
  3827. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, /* *.H..... */
  3828. 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, /* ........ */
  3829. 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, /* 0....... */
  3830. 0x00, 0xb8, 0xba, 0x23, 0xb4, 0xf6, 0xc3, 0x7b, /* ...#...{ */
  3831. 0x14, 0xc3, 0xa4, 0xf5, 0x1d, 0x61, 0xa1, 0xf5, /* .....a.. */
  3832. 0x1e, 0x63, 0xb9, 0x85, 0x23, 0x34, 0x50, 0x6d, /* .c..#4Pm */
  3833. 0xf8, 0x7c, 0xa2, 0x8a, 0x04, 0x8b, 0xd5, 0x75, /* .|.....u */
  3834. 0x5c, 0x2d, 0xf7, 0x63, 0x88, 0xd1, 0x07, 0x7a, /* \-.c...z */
  3835. 0xea, 0x0b, 0x45, 0x35, 0x2b, 0xeb, 0x1f, 0xb1, /* ..E5+... */
  3836. 0x22, 0xb4, 0x94, 0x41, 0x38, 0xe2, 0x9d, 0x74, /* "..A8..t */
  3837. 0xd6, 0x8b, 0x30, 0x22, 0x10, 0x51, 0xc5, 0xdb, /* ..0".Q.. */
  3838. 0xca, 0x3f, 0x46, 0x2b, 0xfe, 0xe5, 0x5a, 0x3f, /* .?F+..Z? */
  3839. 0x41, 0x74, 0x67, 0x75, 0x95, 0xa9, 0x94, 0xd5, /* Atgu.... */
  3840. 0xc3, 0xee, 0x42, 0xf8, 0x8d, 0xeb, 0x92, 0x95, /* ..B..... */
  3841. 0xe1, 0xd9, 0x65, 0xb7, 0x43, 0xc4, 0x18, 0xde, /* ..e.C... */
  3842. 0x16, 0x80, 0x90, 0xce, 0x24, 0x35, 0x21, 0xc4, /* ....$5!. */
  3843. 0x55, 0xac, 0x5a, 0x51, 0xe0, 0x2e, 0x2d, 0xb3, /* U.ZQ..-. */
  3844. 0x0a, 0x5a, 0x4f, 0x4a, 0x73, 0x31, 0x50, 0xee, /* .ZOJs1P. */
  3845. 0x4a, 0x16, 0xbd, 0x39, 0x8b, 0xad, 0x05, 0x48, /* J..9...H */
  3846. 0x87, 0xb1, 0x99, 0xe2, 0x10, 0xa7, 0x06, 0x72, /* .......r */
  3847. 0x67, 0xca, 0x5c, 0xd1, 0x97, 0xbd, 0xc8, 0xf1, /* g.\..... */
  3848. 0x76, 0xf8, 0xe0, 0x4a, 0xec, 0xbc, 0x93, 0xf4, /* v..J.... */
  3849. 0x66, 0x4c, 0x28, 0x71, 0xd1, 0xd8, 0x66, 0x03, /* fL(q..f. */
  3850. 0xb4, 0x90, 0x30, 0xbb, 0x17, 0xb0, 0xfe, 0x97, /* ..0..... */
  3851. 0xf5, 0x1e, 0xe8, 0xc7, 0x5d, 0x9b, 0x8b, 0x11, /* ....]... */
  3852. 0x19, 0x12, 0x3c, 0xab, 0x82, 0x71, 0x78, 0xff, /* ..<..qx. */
  3853. 0xae, 0x3f, 0x32, 0xb2, 0x08, 0x71, 0xb2, 0x1b, /* .?2..q.. */
  3854. 0x8c, 0x27, 0xac, 0x11, 0xb8, 0xd8, 0x43, 0x49, /* .'....CI */
  3855. 0xcf, 0xb0, 0x70, 0xb1, 0xf0, 0x8c, 0xae, 0xda, /* ..p..... */
  3856. 0x24, 0x87, 0x17, 0x3b, 0xd8, 0x04, 0x65, 0x6c, /* $..;..el */
  3857. 0x00, 0x76, 0x50, 0xef, 0x15, 0x08, 0xd7, 0xb4, /* .vP..... */
  3858. 0x73, 0x68, 0x26, 0x14, 0x87, 0x95, 0xc3, 0x5f, /* sh&...._ */
  3859. 0x6e, 0x61, 0xb8, 0x87, 0x84, 0xfa, 0x80, 0x1a, /* na...... */
  3860. 0x0a, 0x8b, 0x98, 0xf3, 0xe3, 0xff, 0x4e, 0x44, /* ......ND */
  3861. 0x1c, 0x65, 0x74, 0x7c, 0x71, 0x54, 0x65, 0xe5, /* .et|qTe. */
  3862. 0x39, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x82, /* 9....... */
  3863. 0x01, 0x0a, 0x30, 0x82, 0x01, 0x06, 0x30, 0x09, /* ..0...0. */
  3864. 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, /* ..U....0 */
  3865. 0x00, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, /* .0...U.. */
  3866. 0x04, 0x16, 0x04, 0x14, 0x32, 0x67, 0xe1, 0xb1, /* ....2g.. */
  3867. 0x79, 0xd2, 0x81, 0xfc, 0x9f, 0x23, 0x0c, 0x70, /* y....#.p */
  3868. 0x40, 0x50, 0xb5, 0x46, 0x56, 0xb8, 0x30, 0x36, /* @P.FV.06 */
  3869. 0x30, 0x81, 0xc4, 0x06, 0x03, 0x55, 0x1d, 0x23, /* 0....U.# */
  3870. 0x04, 0x81, 0xbc, 0x30, 0x81, 0xb9, 0x80, 0x14, /* ...0.... */
  3871. 0x73, 0xb0, 0x1c, 0xa4, 0x2f, 0x82, 0xcb, 0xcf, /* s.../... */
  3872. 0x47, 0xa5, 0x38, 0xd7, 0xb0, 0x04, 0x82, 0x3a, /* G.8....: */
  3873. 0x7e, 0x72, 0x15, 0x21, 0xa1, 0x81, 0x9d, 0xa4, /* ~r.!.... */
  3874. 0x81, 0x9a, 0x30, 0x81, 0x97, 0x31, 0x0b, 0x30, /* ..0..1.0 */
  3875. 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, /* ...U.... */
  3876. 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, /* US1.0... */
  3877. 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x57, 0x61, 0x73, /* U....Was */
  3878. 0x68, 0x69, 0x6e, 0x67, 0x74, 0x6f, 0x6e, 0x31, /* hington1 */
  3879. 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, /* .0...U.. */
  3880. 0x0c, 0x07, 0x53, 0x65, 0x61, 0x74, 0x74, 0x6c, /* ..Seattl */
  3881. 0x65, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, /* e1.0...U */
  3882. 0x04, 0x0a, 0x0c, 0x07, 0x77, 0x6f, 0x6c, 0x66, /* ....wolf */
  3883. 0x53, 0x53, 0x4c, 0x31, 0x14, 0x30, 0x12, 0x06, /* SSL1.0.. */
  3884. 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45, 0x6e, /* .U....En */
  3885. 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, /* gineerin */
  3886. 0x67, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, /* g1.0...U */
  3887. 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x6f, 0x6c, 0x66, /* ....wolf */
  3888. 0x53, 0x53, 0x4c, 0x20, 0x72, 0x6f, 0x6f, 0x74, /* SSL root */
  3889. 0x20, 0x43, 0x41, 0x31, 0x1f, 0x30, 0x1d, 0x06, /* CA1.0.. */
  3890. 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, /* .*.H.... */
  3891. 0x09, 0x01, 0x16, 0x10, 0x69, 0x6e, 0x66, 0x6f, /* ....info */
  3892. 0x40, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, /* @wolfssl */
  3893. 0x2e, 0x63, 0x6f, 0x6d, 0x82, 0x01, 0x63, 0x30, /* .com..c0 */
  3894. 0x13, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x04, 0x0c, /* ...U.%.. */
  3895. 0x30, 0x0a, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, /* 0...+... */
  3896. 0x05, 0x07, 0x03, 0x09, 0x30, 0x0d, 0x06, 0x09, /* ....0... */
  3897. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, /* *.H..... */
  3898. 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, /* ........ */
  3899. 0x2f, 0xb7, 0x6b, 0xec, 0xb7, 0x12, 0x63, 0xb9, /* /.k...c. */
  3900. 0x57, 0xdc, 0x04, 0x4d, 0x9c, 0x67, 0x74, 0x98, /* W..M.gt. */
  3901. 0x06, 0x28, 0x68, 0x37, 0x34, 0xc2, 0x50, 0xe9, /* .(h74.P. */
  3902. 0x2a, 0xd4, 0x1a, 0xb2, 0x32, 0x1a, 0x9d, 0x2b, /* *...2..+ */
  3903. 0x4f, 0x23, 0x50, 0xea, 0xb4, 0x95, 0x86, 0xc3, /* O#P..... */
  3904. 0xb9, 0x5f, 0x34, 0x3e, 0x99, 0x91, 0xa7, 0x80, /* ._4>.... */
  3905. 0x5f, 0x6e, 0x1b, 0x6e, 0xdb, 0xe9, 0x02, 0x38, /* _n.n...8 */
  3906. 0x6f, 0xdf, 0xc5, 0x9b, 0x0d, 0xa3, 0x1c, 0xa9, /* o....... */
  3907. 0x15, 0x76, 0x16, 0x66, 0xa8, 0x4e, 0xfb, 0xd3, /* .v.f.N.. */
  3908. 0x43, 0x76, 0xf1, 0x72, 0xb7, 0xd1, 0xfa, 0xee, /* Cv.r.... */
  3909. 0x39, 0xa6, 0x96, 0xc1, 0xa2, 0x93, 0xa4, 0x9b, /* 9....... */
  3910. 0x1e, 0x9f, 0xba, 0x71, 0x8f, 0xba, 0xbd, 0x67, /* ...q...g */
  3911. 0x6a, 0xf2, 0x15, 0x5f, 0xf1, 0x64, 0xe7, 0xcf, /* j.._.d.. */
  3912. 0x26, 0xb8, 0x4c, 0xc0, 0xeb, 0x85, 0x04, 0x58, /* &.L....X */
  3913. 0xd9, 0x4a, 0x6b, 0xd9, 0x86, 0xf5, 0x80, 0x21, /* .Jk....! */
  3914. 0xbf, 0x91, 0xc8, 0x4b, 0x9f, 0x04, 0xed, 0x57, /* ...K...W */
  3915. 0x7a, 0xd2, 0x58, 0xac, 0x5b, 0x47, 0xaf, 0x4d, /* z.X.[G.M */
  3916. 0x7f, 0x5b, 0x1d, 0x6d, 0x68, 0x9b, 0x84, 0x98, /* .[.mh... */
  3917. 0x2a, 0x31, 0x02, 0x2c, 0xe9, 0x1b, 0xaf, 0x11, /* *1.,.... */
  3918. 0x0b, 0x78, 0x49, 0xbe, 0x68, 0x68, 0xcb, 0x9c, /* .xI.hh.. */
  3919. 0x41, 0x56, 0xe8, 0xb5, 0x59, 0xda, 0xff, 0xca, /* AV..Y... */
  3920. 0x59, 0x99, 0x17, 0x3e, 0x11, 0x0a, 0x8f, 0x49, /* Y..>...I */
  3921. 0x24, 0x0b, 0x81, 0x42, 0x63, 0xcd, 0x4f, 0xf6, /* $..Bc.O. */
  3922. 0x2b, 0x9d, 0xd1, 0x79, 0x75, 0xd7, 0x4a, 0xcc, /* +..yu.J. */
  3923. 0x4c, 0xb7, 0x2b, 0xd7, 0xe8, 0xe7, 0xd4, 0x48, /* L.+....H */
  3924. 0x3c, 0x14, 0x3b, 0x1c, 0x28, 0xe8, 0x46, 0x7a, /* <.;.(.Fz */
  3925. 0xdc, 0x11, 0x9d, 0x7f, 0x1c, 0xab, 0x10, 0x95, /* ........ */
  3926. 0x17, 0xb2, 0xc7, 0x7a, 0xbb, 0x17, 0x44, 0x59, /* ...z..DY */
  3927. 0x69, 0x8e, 0x16, 0x05, 0x94, 0x8c, 0x88, 0xd9, /* i....... */
  3928. 0xdc, 0x9a, 0xfd, 0xf2, 0x93, 0xbe, 0x68, 0xba, /* ......h. */
  3929. 0x3c, 0xd6, 0x2b, 0x61, 0x3a, 0x8b, 0xf7, 0x66, /* <.+a:..f */
  3930. 0xcb, 0x54, 0xe8, 0xe4, 0xdb, 0x9f, 0xcc, 0x9e /* .T...... */
  3931. };
  3932. OcspEntry entry[1];
  3933. CertStatus status[1];
  3934. OcspRequest* request = NULL;
  3935. #ifndef NO_FILESYSTEM
  3936. const char* ca_cert = "./certs/ca-cert.pem";
  3937. #endif
  3938. byte serial[] = {0x05};
  3939. byte issuerHash[] = {0x71, 0x4d, 0x82, 0x23, 0x40, 0x59, 0xc0, 0x96, 0xa1, 0x37, 0x43, 0xfa, 0x31, 0xdb, 0xba, 0xb1, 0x43, 0x18, 0xda, 0x04};
  3940. byte issuerKeyHash[] = {0x83, 0xc6, 0x3a, 0x89, 0x2c, 0x81, 0xf4, 0x02, 0xd7, 0x9d, 0x4c, 0xe2, 0x2a, 0xc0, 0x71, 0x82, 0x64, 0x44, 0xda, 0x0e};
  3941. XMEMSET(entry, 0, sizeof(OcspEntry));
  3942. XMEMSET(status, 0, sizeof(CertStatus));
  3943. ExpectNotNull(request = wolfSSL_OCSP_REQUEST_new());
  3944. ExpectNotNull(request->serial = (byte*)XMALLOC(sizeof(serial), NULL,
  3945. DYNAMIC_TYPE_OCSP_REQUEST));
  3946. if ((request != NULL) && (request->serial != NULL)) {
  3947. request->serialSz = sizeof(serial);
  3948. XMEMCPY(request->serial, serial, sizeof(serial));
  3949. XMEMCPY(request->issuerHash, issuerHash, sizeof(issuerHash));
  3950. XMEMCPY(request->issuerKeyHash, issuerKeyHash, sizeof(issuerKeyHash));
  3951. }
  3952. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  3953. ExpectIntEQ(wolfSSL_CertManagerEnableOCSP(cm, 0), WOLFSSL_SUCCESS);
  3954. ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm,
  3955. "./certs/ocsp/intermediate1-ca-cert.pem", NULL), WOLFSSL_SUCCESS);
  3956. /* Response should be valid. */
  3957. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, (byte *)response,
  3958. sizeof(response), NULL, status, entry, request), WOLFSSL_SUCCESS);
  3959. /* Flip a byte in the request serial number, response should be invalid
  3960. * now. */
  3961. if ((request != NULL) && (request->serial != NULL))
  3962. request->serial[0] ^= request->serial[0];
  3963. ExpectIntNE(wolfSSL_CertManagerCheckOCSPResponse(cm, (byte *)response,
  3964. sizeof(response), NULL, status, entry, request), WOLFSSL_SUCCESS);
  3965. #ifndef NO_FILESYSTEM
  3966. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, server_cert_der_2048,
  3967. sizeof(server_cert_der_2048)), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  3968. ExpectIntEQ(WOLFSSL_SUCCESS,
  3969. wolfSSL_CertManagerLoadCA(cm, ca_cert, NULL));
  3970. ExpectIntEQ(wolfSSL_CertManagerCheckOCSP(cm, server_cert_der_2048,
  3971. sizeof(server_cert_der_2048)), 1);
  3972. #endif
  3973. wolfSSL_OCSP_REQUEST_free(request);
  3974. wolfSSL_CertManagerFree(cm);
  3975. #endif /* OPENSSL_ALL || WOLFSSL_NGINX || WOLFSSL_HAPROXY ||
  3976. * WOLFSSL_APACHE_HTTPD || HAVE_LIGHTY */
  3977. #endif /* HAVE_OCSP */
  3978. return EXPECT_RESULT();
  3979. }
  3980. static int test_wolfSSL_CheckOCSPResponse(void)
  3981. {
  3982. EXPECT_DECLS;
  3983. #if defined(HAVE_OCSP) && defined(OPENSSL_EXTRA) && \
  3984. !defined(NO_RSA) && !defined(NO_SHA)
  3985. const char* responseFile = "./certs/ocsp/test-response.der";
  3986. const char* responseMultiFile = "./certs/ocsp/test-multi-response.der";
  3987. const char* responseNoInternFile =
  3988. "./certs/ocsp/test-response-nointern.der";
  3989. const char* caFile = "./certs/ocsp/root-ca-cert.pem";
  3990. OcspResponse* res = NULL;
  3991. byte data[4096];
  3992. const unsigned char* pt;
  3993. int dataSz = 0; /* initialize to mitigate spurious maybe-uninitialized from
  3994. * gcc sanitizer with --enable-heapmath.
  3995. */
  3996. XFILE f = XBADFILE;
  3997. WOLFSSL_OCSP_BASICRESP* bs = NULL;
  3998. WOLFSSL_X509_STORE* st = NULL;
  3999. WOLFSSL_X509* issuer = NULL;
  4000. ExpectTrue((f = XFOPEN(responseFile, "rb")) != XBADFILE);
  4001. ExpectIntGT(dataSz = (word32)XFREAD(data, 1, sizeof(data), f), 0);
  4002. if (f != XBADFILE) {
  4003. XFCLOSE(f);
  4004. f = XBADFILE;
  4005. }
  4006. pt = data;
  4007. ExpectNotNull(res = wolfSSL_d2i_OCSP_RESPONSE(NULL, &pt, dataSz));
  4008. ExpectNotNull(issuer = wolfSSL_X509_load_certificate_file(caFile,
  4009. SSL_FILETYPE_PEM));
  4010. ExpectNotNull(st = wolfSSL_X509_STORE_new());
  4011. ExpectIntEQ(wolfSSL_X509_STORE_add_cert(st, issuer), WOLFSSL_SUCCESS);
  4012. ExpectNotNull(bs = wolfSSL_OCSP_response_get1_basic(res));
  4013. ExpectIntEQ(wolfSSL_OCSP_basic_verify(bs, NULL, st, 0), WOLFSSL_SUCCESS);
  4014. wolfSSL_OCSP_BASICRESP_free(bs);
  4015. bs = NULL;
  4016. wolfSSL_OCSP_RESPONSE_free(res);
  4017. res = NULL;
  4018. wolfSSL_X509_STORE_free(st);
  4019. st = NULL;
  4020. wolfSSL_X509_free(issuer);
  4021. issuer = NULL;
  4022. /* check loading a response with optional certs */
  4023. ExpectTrue((f = XFOPEN(responseNoInternFile, "rb")) != XBADFILE);
  4024. ExpectIntGT(dataSz = (word32)XFREAD(data, 1, sizeof(data), f), 0);
  4025. if (f != XBADFILE)
  4026. XFCLOSE(f);
  4027. f = XBADFILE;
  4028. pt = data;
  4029. ExpectNotNull(res = wolfSSL_d2i_OCSP_RESPONSE(NULL, &pt, dataSz));
  4030. wolfSSL_OCSP_RESPONSE_free(res);
  4031. res = NULL;
  4032. /* check loading a response with multiple certs */
  4033. {
  4034. WOLFSSL_CERT_MANAGER* cm = NULL;
  4035. OcspEntry *entry = NULL;
  4036. CertStatus* status = NULL;
  4037. OcspRequest* request = NULL;
  4038. byte serial1[] = {0x01};
  4039. byte serial[] = {0x02};
  4040. byte issuerHash[] = {
  4041. 0x44, 0xA8, 0xDB, 0xD1, 0xBC, 0x97, 0x0A, 0x83,
  4042. 0x3B, 0x5B, 0x31, 0x9A, 0x4C, 0xB8, 0xD2, 0x52,
  4043. 0x37, 0x15, 0x8A, 0x88
  4044. };
  4045. byte issuerKeyHash[] = {
  4046. 0x73, 0xB0, 0x1C, 0xA4, 0x2F, 0x82, 0xCB, 0xCF,
  4047. 0x47, 0xA5, 0x38, 0xD7, 0xB0, 0x04, 0x82, 0x3A,
  4048. 0x7E, 0x72, 0x15, 0x21
  4049. };
  4050. ExpectNotNull(entry = (OcspEntry*)XMALLOC(sizeof(OcspEntry), NULL,
  4051. DYNAMIC_TYPE_OPENSSL));
  4052. ExpectNotNull(status = (CertStatus*)XMALLOC(sizeof(CertStatus), NULL,
  4053. DYNAMIC_TYPE_OPENSSL));
  4054. if (entry != NULL)
  4055. XMEMSET(entry, 0, sizeof(OcspEntry));
  4056. if (status != NULL)
  4057. XMEMSET(status, 0, sizeof(CertStatus));
  4058. ExpectNotNull(request = wolfSSL_OCSP_REQUEST_new());
  4059. ExpectNotNull(request->serial = (byte*)XMALLOC(sizeof(serial), NULL,
  4060. DYNAMIC_TYPE_OCSP_REQUEST));
  4061. if (request != NULL && request->serial != NULL) {
  4062. request->serialSz = sizeof(serial);
  4063. XMEMCPY(request->serial, serial, sizeof(serial));
  4064. XMEMCPY(request->issuerHash, issuerHash, sizeof(issuerHash));
  4065. XMEMCPY(request->issuerKeyHash, issuerKeyHash,
  4066. sizeof(issuerKeyHash));
  4067. }
  4068. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  4069. ExpectIntEQ(wolfSSL_CertManagerEnableOCSP(cm, 0), WOLFSSL_SUCCESS);
  4070. ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, caFile, NULL),
  4071. WOLFSSL_SUCCESS);
  4072. ExpectTrue((f = XFOPEN(responseMultiFile, "rb")) != XBADFILE);
  4073. ExpectIntGT(dataSz = (word32)XFREAD(data, 1, sizeof(data), f), 0);
  4074. if (f != XBADFILE)
  4075. XFCLOSE(f);
  4076. f = XBADFILE;
  4077. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, data,
  4078. dataSz, NULL, status, entry, request), WOLFSSL_SUCCESS);
  4079. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, data,
  4080. dataSz, NULL, entry->status, entry, request), WOLFSSL_SUCCESS);
  4081. ExpectNotNull(entry->status);
  4082. if (request != NULL && request->serial != NULL)
  4083. XMEMCPY(request->serial, serial1, sizeof(serial1));
  4084. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, data,
  4085. dataSz, NULL, status, entry, request), WOLFSSL_SUCCESS);
  4086. /* store both status's in the entry to check that "next" is not
  4087. * overwritten */
  4088. if (EXPECT_SUCCESS() && status != NULL && entry != NULL) {
  4089. status->next = entry->status;
  4090. entry->status = status;
  4091. }
  4092. if (request != NULL && request->serial != NULL)
  4093. XMEMCPY(request->serial, serial, sizeof(serial));
  4094. ExpectIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, data,
  4095. dataSz, NULL, entry->status, entry, request), WOLFSSL_SUCCESS);
  4096. ExpectNotNull(entry->status->next);
  4097. /* compare the status found */
  4098. ExpectIntEQ(status->serialSz, entry->status->serialSz);
  4099. ExpectIntEQ(XMEMCMP(status->serial, entry->status->serial,
  4100. status->serialSz), 0);
  4101. if (status != NULL && entry != NULL && entry->status != status) {
  4102. XFREE(status, NULL, DYNAMIC_TYPE_OPENSSL);
  4103. }
  4104. wolfSSL_OCSP_CERTID_free(entry);
  4105. wolfSSL_OCSP_REQUEST_free(request);
  4106. wolfSSL_CertManagerFree(cm);
  4107. }
  4108. #if defined(WC_RSA_PSS)
  4109. {
  4110. const char* responsePssFile = "./certs/ocsp/test-response-rsapss.der";
  4111. /* check loading a response with RSA-PSS signature */
  4112. ExpectTrue((f = XFOPEN(responsePssFile, "rb")) != XBADFILE);
  4113. ExpectIntGT(dataSz = (word32)XFREAD(data, 1, sizeof(data), f), 0);
  4114. if (f != XBADFILE)
  4115. XFCLOSE(f);
  4116. pt = data;
  4117. ExpectNotNull(res = wolfSSL_d2i_OCSP_RESPONSE(NULL, &pt, dataSz));
  4118. /* try to verify the response */
  4119. ExpectNotNull(issuer = wolfSSL_X509_load_certificate_file(caFile,
  4120. SSL_FILETYPE_PEM));
  4121. ExpectNotNull(st = wolfSSL_X509_STORE_new());
  4122. ExpectIntEQ(wolfSSL_X509_STORE_add_cert(st, issuer), WOLFSSL_SUCCESS);
  4123. ExpectNotNull(bs = wolfSSL_OCSP_response_get1_basic(res));
  4124. ExpectIntEQ(wolfSSL_OCSP_basic_verify(bs, NULL, st, 0),
  4125. WOLFSSL_SUCCESS);
  4126. wolfSSL_OCSP_BASICRESP_free(bs);
  4127. wolfSSL_OCSP_RESPONSE_free(res);
  4128. wolfSSL_X509_STORE_free(st);
  4129. wolfSSL_X509_free(issuer);
  4130. }
  4131. #endif
  4132. #endif /* HAVE_OCSP */
  4133. return EXPECT_RESULT();
  4134. }
  4135. static int test_wolfSSL_FPKI(void)
  4136. {
  4137. EXPECT_DECLS;
  4138. #if defined(WOLFSSL_FPKI) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  4139. XFILE f = XBADFILE;
  4140. const char* fpkiCert = "./certs/fpki-cert.der";
  4141. DecodedCert cert;
  4142. byte buf[4096];
  4143. byte* uuid = NULL;
  4144. byte* fascn = NULL;
  4145. word32 fascnSz;
  4146. word32 uuidSz;
  4147. int bytes = 0;
  4148. ExpectTrue((f = XFOPEN(fpkiCert, "rb")) != XBADFILE);
  4149. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  4150. if (f != XBADFILE)
  4151. XFCLOSE(f);
  4152. wc_InitDecodedCert(&cert, buf, (word32)bytes, NULL);
  4153. ExpectIntEQ(wc_ParseCert(&cert, CERT_TYPE, 0, NULL), 0);
  4154. ExpectIntEQ(wc_GetFASCNFromCert(&cert, NULL, &fascnSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  4155. ExpectNotNull(fascn = (byte*)XMALLOC(fascnSz, NULL,
  4156. DYNAMIC_TYPE_TMP_BUFFER));
  4157. ExpectIntEQ(wc_GetFASCNFromCert(&cert, fascn, &fascnSz), 0);
  4158. XFREE(fascn, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  4159. ExpectIntEQ(wc_GetUUIDFromCert(&cert, NULL, &uuidSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  4160. ExpectNotNull(uuid = (byte*)XMALLOC(uuidSz, NULL, DYNAMIC_TYPE_TMP_BUFFER));
  4161. ExpectIntEQ(wc_GetUUIDFromCert(&cert, uuid, &uuidSz), 0);
  4162. XFREE(uuid, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  4163. wc_FreeDecodedCert(&cert);
  4164. #endif
  4165. return EXPECT_RESULT();
  4166. }
  4167. /* use RID in confuncture with other names to test parsing of unknown other
  4168. * names */
  4169. static int test_wolfSSL_OtherName(void)
  4170. {
  4171. EXPECT_DECLS;
  4172. #if !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  4173. XFILE f = XBADFILE;
  4174. const char* ridCert = "./certs/rid-cert.der";
  4175. DecodedCert cert;
  4176. byte buf[4096];
  4177. int bytes = 0;
  4178. ExpectTrue((f = XFOPEN(ridCert, "rb")) != XBADFILE);
  4179. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  4180. if (f != XBADFILE)
  4181. XFCLOSE(f);
  4182. wc_InitDecodedCert(&cert, buf, (word32)bytes, NULL);
  4183. ExpectIntEQ(wc_ParseCert(&cert, CERT_TYPE, 0, NULL), 0);
  4184. wc_FreeDecodedCert(&cert);
  4185. #endif
  4186. return EXPECT_RESULT();
  4187. }
  4188. #ifdef HAVE_CERT_CHAIN_VALIDATION
  4189. static int test_wolfSSL_CertRsaPss(void)
  4190. {
  4191. EXPECT_DECLS;
  4192. /* FIPS v2 and below don't support long salts. */
  4193. #if !defined(NO_RSA) && defined(WC_RSA_PSS) && !defined(NO_FILESYSTEM) && \
  4194. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  4195. (HAVE_FIPS_VERSION > 2))) && (!defined(HAVE_SELFTEST) || \
  4196. (defined(HAVE_SELFTEST_VERSION) && (HAVE_SELFTEST_VERSION > 2)))
  4197. XFILE f = XBADFILE;
  4198. const char* rsaPssSha256Cert = "./certs/rsapss/ca-rsapss.der";
  4199. const char* rsaPssRootSha256Cert = "./certs/rsapss/root-rsapss.pem";
  4200. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_PSS_LONG_SALT) && \
  4201. RSA_MAX_SIZE >= 3072
  4202. const char* rsaPssSha384Cert = "./certs/rsapss/ca-3072-rsapss.der";
  4203. #endif
  4204. #if defined(WOLFSSL_SHA384) && RSA_MAX_SIZE >= 3072
  4205. const char* rsaPssRootSha384Cert = "./certs/rsapss/root-3072-rsapss.pem";
  4206. #endif
  4207. DecodedCert cert;
  4208. byte buf[4096];
  4209. int bytes = 0;
  4210. WOLFSSL_CERT_MANAGER* cm = NULL;
  4211. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  4212. ExpectIntEQ(WOLFSSL_SUCCESS,
  4213. wolfSSL_CertManagerLoadCA(cm, rsaPssRootSha256Cert, NULL));
  4214. #if defined(WOLFSSL_SHA384) && RSA_MAX_SIZE >= 3072
  4215. ExpectIntEQ(WOLFSSL_SUCCESS,
  4216. wolfSSL_CertManagerLoadCA(cm, rsaPssRootSha384Cert, NULL));
  4217. #endif
  4218. ExpectTrue((f = XFOPEN(rsaPssSha256Cert, "rb")) != XBADFILE);
  4219. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  4220. if (f != XBADFILE) {
  4221. XFCLOSE(f);
  4222. f = XBADFILE;
  4223. }
  4224. wc_InitDecodedCert(&cert, buf, (word32)bytes, NULL);
  4225. ExpectIntEQ(wc_ParseCert(&cert, CERT_TYPE, VERIFY, cm), 0);
  4226. wc_FreeDecodedCert(&cert);
  4227. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_PSS_LONG_SALT) && \
  4228. RSA_MAX_SIZE >= 3072
  4229. ExpectTrue((f = XFOPEN(rsaPssSha384Cert, "rb")) != XBADFILE);
  4230. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  4231. if (f != XBADFILE)
  4232. XFCLOSE(f);
  4233. wc_InitDecodedCert(&cert, buf, (word32)bytes, NULL);
  4234. ExpectIntEQ(wc_ParseCert(&cert, CERT_TYPE, VERIFY, cm), 0);
  4235. wc_FreeDecodedCert(&cert);
  4236. #endif
  4237. wolfSSL_CertManagerFree(cm);
  4238. #endif
  4239. return EXPECT_RESULT();
  4240. }
  4241. #endif
  4242. static int test_wolfSSL_CTX_load_verify_locations_ex(void)
  4243. {
  4244. EXPECT_DECLS;
  4245. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4246. !defined(NO_WOLFSSL_CLIENT)
  4247. WOLFSSL_CTX* ctx = NULL;
  4248. const char* ca_cert = "./certs/ca-cert.pem";
  4249. const char* ca_expired_cert = "./certs/test/expired/expired-ca.pem";
  4250. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4251. /* test good CA */
  4252. ExpectTrue(WOLFSSL_SUCCESS ==
  4253. wolfSSL_CTX_load_verify_locations_ex(ctx, ca_cert, NULL,
  4254. WOLFSSL_LOAD_FLAG_NONE));
  4255. /* test expired CA */
  4256. #if !defined(OPENSSL_COMPATIBLE_DEFAULTS) && !defined(NO_ASN_TIME)
  4257. ExpectIntNE(wolfSSL_CTX_load_verify_locations_ex(ctx, ca_expired_cert, NULL,
  4258. WOLFSSL_LOAD_FLAG_NONE), WOLFSSL_SUCCESS);
  4259. #else
  4260. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, ca_expired_cert, NULL,
  4261. WOLFSSL_LOAD_FLAG_NONE), WOLFSSL_SUCCESS);
  4262. #endif
  4263. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx, ca_expired_cert, NULL,
  4264. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), WOLFSSL_SUCCESS);
  4265. wolfSSL_CTX_free(ctx);
  4266. #endif
  4267. return EXPECT_RESULT();
  4268. }
  4269. static int test_wolfSSL_CTX_load_verify_buffer_ex(void)
  4270. {
  4271. EXPECT_DECLS;
  4272. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA)
  4273. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  4274. WOLFSSL_CTX* ctx;
  4275. const char* ca_expired_cert_file = "./certs/test/expired/expired-ca.der";
  4276. byte ca_expired_cert[TWOK_BUF];
  4277. word32 sizeof_ca_expired_cert = 0;
  4278. XFILE fp = XBADFILE;
  4279. #ifndef NO_WOLFSSL_CLIENT
  4280. ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  4281. #else
  4282. ctx = wolfSSL_CTX_new(wolfSSLv23_server_method());
  4283. #endif
  4284. ExpectNotNull(ctx);
  4285. #if defined(USE_CERT_BUFFERS_2048)
  4286. /* test good CA */
  4287. ExpectTrue(WOLFSSL_SUCCESS ==
  4288. wolfSSL_CTX_load_verify_buffer_ex(ctx, ca_cert_der_2048,
  4289. sizeof_ca_cert_der_2048, WOLFSSL_FILETYPE_ASN1, 0,
  4290. WOLFSSL_LOAD_FLAG_NONE));
  4291. #endif
  4292. /* load expired CA */
  4293. XMEMSET(ca_expired_cert, 0, sizeof(ca_expired_cert));
  4294. ExpectTrue((fp = XFOPEN(ca_expired_cert_file, "rb")) != XBADFILE);
  4295. ExpectIntGT(sizeof_ca_expired_cert = (word32)XFREAD(ca_expired_cert, 1,
  4296. sizeof(ca_expired_cert), fp), 0);
  4297. if (fp != XBADFILE)
  4298. XFCLOSE(fp);
  4299. /* test expired CA failure */
  4300. #if !defined(OPENSSL_COMPATIBLE_DEFAULTS) && !defined(NO_ASN_TIME)
  4301. ExpectIntNE(wolfSSL_CTX_load_verify_buffer_ex(ctx, ca_expired_cert,
  4302. sizeof_ca_expired_cert, WOLFSSL_FILETYPE_ASN1, 0,
  4303. WOLFSSL_LOAD_FLAG_NONE), WOLFSSL_SUCCESS);
  4304. #else
  4305. ExpectIntEQ(wolfSSL_CTX_load_verify_buffer_ex(ctx, ca_expired_cert,
  4306. sizeof_ca_expired_cert, WOLFSSL_FILETYPE_ASN1, 0,
  4307. WOLFSSL_LOAD_FLAG_NONE), WOLFSSL_SUCCESS);
  4308. #endif
  4309. /* test expired CA success */
  4310. ExpectIntEQ(wolfSSL_CTX_load_verify_buffer_ex(ctx, ca_expired_cert,
  4311. sizeof_ca_expired_cert, WOLFSSL_FILETYPE_ASN1, 0,
  4312. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), WOLFSSL_SUCCESS);
  4313. /* Fail when ctx is NULL. */
  4314. ExpectIntEQ(wolfSSL_CTX_load_verify_buffer_ex(NULL, ca_expired_cert,
  4315. sizeof_ca_expired_cert, WOLFSSL_FILETYPE_ASN1, 0,
  4316. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4317. /* Load as modified cert - bad initial length. */
  4318. ca_expired_cert[2] = 0x7f;
  4319. ExpectIntEQ(wolfSSL_CTX_load_verify_buffer_ex(ctx, ca_expired_cert,
  4320. sizeof_ca_expired_cert, WOLFSSL_FILETYPE_ASN1, 1,
  4321. WOLFSSL_LOAD_FLAG_DATE_ERR_OKAY), WC_NO_ERR_TRACE(ASN_PARSE_E));
  4322. wolfSSL_CTX_free(ctx);
  4323. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  4324. #endif
  4325. return EXPECT_RESULT();
  4326. }
  4327. static int test_wolfSSL_CTX_load_verify_chain_buffer_format(void)
  4328. {
  4329. EXPECT_DECLS;
  4330. #if !defined(NO_CERTS) && !defined(NO_RSA) && defined(OPENSSL_EXTRA) && \
  4331. defined(USE_CERT_BUFFERS_2048) && (WOLFSSL_MIN_RSA_BITS <= 1024) && \
  4332. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4333. WOLFSSL_CTX* ctx = NULL;
  4334. #ifndef NO_WOLFSSL_CLIENT
  4335. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4336. #else
  4337. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4338. #endif
  4339. /* Public key 140 bytes??? */
  4340. ExpectIntEQ(wolfSSL_CTX_load_verify_chain_buffer_format(ctx,
  4341. ca_cert_chain_der, sizeof_ca_cert_chain_der, WOLFSSL_FILETYPE_ASN1),
  4342. WOLFSSL_SUCCESS);
  4343. wolfSSL_CTX_free(ctx);
  4344. #endif
  4345. return EXPECT_RESULT();
  4346. }
  4347. static int test_wolfSSL_CTX_add1_chain_cert(void)
  4348. {
  4349. EXPECT_DECLS;
  4350. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && defined(OPENSSL_EXTRA) && \
  4351. defined(KEEP_OUR_CERT) && !defined(NO_RSA) && !defined(NO_WOLFSSL_CLIENT)
  4352. WOLFSSL_CTX* ctx;
  4353. WOLFSSL* ssl = NULL;
  4354. const char *certChain[] = {
  4355. "./certs/intermediate/client-int-cert.pem",
  4356. "./certs/intermediate/ca-int2-cert.pem",
  4357. "./certs/intermediate/ca-int-cert.pem",
  4358. "./certs/ca-cert.pem",
  4359. NULL
  4360. };
  4361. const char** cert;
  4362. WOLFSSL_X509* x509 = NULL;
  4363. WOLF_STACK_OF(X509)* chain = NULL;
  4364. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4365. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4366. ExpectNotNull(x509 = wolfSSL_X509_new());
  4367. ExpectIntEQ(SSL_CTX_add1_chain_cert(ctx, x509), 0);
  4368. ExpectIntEQ(SSL_CTX_add0_chain_cert(ctx, x509), 0);
  4369. ExpectIntEQ(SSL_add1_chain_cert(ssl, x509), 0);
  4370. ExpectIntEQ(SSL_add0_chain_cert(ssl, x509), 0);
  4371. wolfSSL_X509_free(x509);
  4372. x509 = NULL;
  4373. for (cert = certChain; EXPECT_SUCCESS() && *cert != NULL; cert++) {
  4374. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(*cert,
  4375. WOLFSSL_FILETYPE_PEM));
  4376. /* Do negative tests once */
  4377. if (cert == certChain) {
  4378. /* Negative tests. */
  4379. ExpectIntEQ(SSL_CTX_add1_chain_cert(NULL, NULL), 0);
  4380. ExpectIntEQ(SSL_CTX_add1_chain_cert(ctx, NULL), 0);
  4381. ExpectIntEQ(SSL_CTX_add1_chain_cert(NULL, x509), 0);
  4382. ExpectIntEQ(SSL_CTX_add0_chain_cert(NULL, NULL), 0);
  4383. ExpectIntEQ(SSL_CTX_add0_chain_cert(ctx, NULL), 0);
  4384. ExpectIntEQ(SSL_CTX_add0_chain_cert(NULL, x509), 0);
  4385. }
  4386. ExpectIntEQ(SSL_CTX_add1_chain_cert(ctx, x509), 1);
  4387. X509_free(x509);
  4388. x509 = NULL;
  4389. }
  4390. for (cert = certChain; EXPECT_SUCCESS() && *cert != NULL; cert++) {
  4391. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(*cert,
  4392. WOLFSSL_FILETYPE_PEM));
  4393. /* Do negative tests once */
  4394. if (cert == certChain) {
  4395. /* Negative tests. */
  4396. ExpectIntEQ(SSL_add1_chain_cert(NULL, NULL), 0);
  4397. ExpectIntEQ(SSL_add1_chain_cert(ssl, NULL), 0);
  4398. ExpectIntEQ(SSL_add1_chain_cert(NULL, x509), 0);
  4399. ExpectIntEQ(SSL_add0_chain_cert(NULL, NULL), 0);
  4400. ExpectIntEQ(SSL_add0_chain_cert(ssl, NULL), 0);
  4401. ExpectIntEQ(SSL_add0_chain_cert(NULL, x509), 0);
  4402. }
  4403. ExpectIntEQ(SSL_add1_chain_cert(ssl, x509), 1);
  4404. X509_free(x509);
  4405. x509 = NULL;
  4406. }
  4407. ExpectIntEQ(SSL_CTX_get0_chain_certs(ctx, &chain), 1);
  4408. ExpectIntEQ(sk_X509_num(chain), 3);
  4409. ExpectIntEQ(SSL_get0_chain_certs(ssl, &chain), 1);
  4410. ExpectIntEQ(sk_X509_num(chain), 3);
  4411. SSL_free(ssl);
  4412. SSL_CTX_free(ctx);
  4413. #endif
  4414. return EXPECT_RESULT();
  4415. }
  4416. static int test_wolfSSL_CTX_use_certificate_chain_buffer_format(void)
  4417. {
  4418. EXPECT_DECLS;
  4419. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4420. !defined(NO_WOLFSSL_CLIENT) && defined(USE_CERT_BUFFERS_2048)
  4421. WOLFSSL_CTX* ctx = NULL;
  4422. WOLFSSL* ssl = NULL;
  4423. const char* cert = "./certs/server-cert.pem";
  4424. unsigned char* buf = NULL;
  4425. size_t len;
  4426. ExpectIntEQ(load_file(cert, &buf, &len), 0);
  4427. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4428. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4429. /* Invalid parameters. */
  4430. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer_format(NULL,
  4431. NULL, 0, WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4432. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer_format(ctx,
  4433. NULL, 0, WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(ASN_PARSE_E));
  4434. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer_format(NULL,
  4435. server_cert_der_2048, sizeof_server_cert_der_2048,
  4436. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4437. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(NULL, NULL, 0),
  4438. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4439. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(ctx, NULL, 0),
  4440. WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  4441. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(NULL, buf, (sword32)len),
  4442. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4443. ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(NULL, NULL, 0),
  4444. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4445. ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(ssl, NULL, 0),
  4446. WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  4447. ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(NULL, buf, (sword32)len),
  4448. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4449. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer_format(ctx,
  4450. server_cert_der_2048, sizeof_server_cert_der_2048,
  4451. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  4452. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer_format(ctx, buf,
  4453. (sword32)len, WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  4454. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(ctx, buf, (sword32)len),
  4455. WOLFSSL_SUCCESS);
  4456. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_buffer(ctx,
  4457. server_cert_der_2048, sizeof_server_cert_der_2048), WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  4458. ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(ssl, buf, (sword32)len),
  4459. WOLFSSL_SUCCESS);
  4460. ExpectIntEQ(wolfSSL_use_certificate_chain_buffer(ssl, server_cert_der_2048,
  4461. sizeof_server_cert_der_2048), WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  4462. wolfSSL_free(ssl);
  4463. wolfSSL_CTX_free(ctx);
  4464. if (buf != NULL) {
  4465. free(buf);
  4466. }
  4467. #endif
  4468. return EXPECT_RESULT();
  4469. }
  4470. static int test_wolfSSL_CTX_use_certificate_chain_file_format(void)
  4471. {
  4472. EXPECT_DECLS;
  4473. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4474. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4475. const char* server_chain_der = "./certs/server-cert-chain.der";
  4476. const char* client_single_pem = "./certs/client-cert.pem";
  4477. WOLFSSL_CTX* ctx = NULL;
  4478. (void)server_chain_der;
  4479. (void)client_single_pem;
  4480. (void)ctx;
  4481. #ifndef NO_WOLFSSL_CLIENT
  4482. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4483. #else
  4484. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4485. #endif
  4486. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file_format(ctx,
  4487. server_chain_der, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  4488. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file_format(ctx,
  4489. client_single_pem, WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  4490. wolfSSL_CTX_free(ctx);
  4491. #endif
  4492. return EXPECT_RESULT();
  4493. }
  4494. static int test_wolfSSL_use_certificate_chain_file(void)
  4495. {
  4496. EXPECT_DECLS;
  4497. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4498. !defined(NO_WOLFSSL_CLIENT)
  4499. const char* server_chain_der = "./certs/server-cert-chain.der";
  4500. const char* client_single_pem = "./certs/client-cert.pem";
  4501. WOLFSSL_CTX* ctx = NULL;
  4502. WOLFSSL* ssl = NULL;
  4503. (void)server_chain_der;
  4504. (void)client_single_pem;
  4505. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4506. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4507. /* Invalid parameters. */
  4508. ExpectIntEQ(wolfSSL_use_certificate_chain_file_format(NULL, NULL,
  4509. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4510. ExpectIntEQ(wolfSSL_use_certificate_chain_file_format(ssl, NULL,
  4511. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4512. ExpectIntEQ(wolfSSL_use_certificate_chain_file_format(NULL,
  4513. server_chain_der, WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4514. ExpectIntEQ(wolfSSL_use_certificate_chain_file(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4515. ExpectIntEQ(wolfSSL_use_certificate_chain_file(ssl, NULL),
  4516. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4517. ExpectIntEQ(wolfSSL_use_certificate_chain_file(NULL, client_single_pem),
  4518. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4519. ExpectIntEQ(wolfSSL_use_certificate_chain_file(ssl, server_chain_der),
  4520. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4521. ExpectIntEQ(wolfSSL_use_certificate_chain_file_format(ssl,
  4522. server_chain_der, WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  4523. ExpectIntEQ(wolfSSL_use_certificate_chain_file_format(ssl,
  4524. client_single_pem, WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  4525. ExpectIntEQ(wolfSSL_use_certificate_chain_file(ssl, client_single_pem),
  4526. WOLFSSL_SUCCESS);
  4527. wolfSSL_free(ssl);
  4528. wolfSSL_CTX_free(ctx);
  4529. #endif
  4530. return EXPECT_RESULT();
  4531. }
  4532. static int test_wolfSSL_CTX_SetTmpDH_file(void)
  4533. {
  4534. EXPECT_DECLS;
  4535. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_DH) && \
  4536. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4537. WOLFSSL_CTX *ctx = NULL;
  4538. #if defined(WOLFSSL_WPAS) && !defined(NO_DSA)
  4539. const char* dsaParamFile = "./certs/dsaparams.pem";
  4540. #endif
  4541. (void)ctx;
  4542. #ifndef NO_WOLFSSL_CLIENT
  4543. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4544. #else
  4545. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4546. #endif
  4547. /* invalid context */
  4548. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(NULL,
  4549. dhParamFile, WOLFSSL_FILETYPE_PEM));
  4550. /* invalid dhParamFile file */
  4551. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(ctx,
  4552. NULL, WOLFSSL_FILETYPE_PEM));
  4553. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(ctx,
  4554. bogusFile, WOLFSSL_FILETYPE_PEM));
  4555. /* success */
  4556. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(ctx, dhParamFile,
  4557. WOLFSSL_FILETYPE_PEM));
  4558. #if defined(WOLFSSL_WPAS) && !defined(NO_DSA)
  4559. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(ctx, dsaParamFile,
  4560. WOLFSSL_FILETYPE_PEM));
  4561. #endif
  4562. wolfSSL_CTX_free(ctx);
  4563. #endif
  4564. return EXPECT_RESULT();
  4565. }
  4566. static int test_wolfSSL_CTX_SetTmpDH_buffer(void)
  4567. {
  4568. EXPECT_DECLS;
  4569. #if !defined(NO_CERTS) && !defined(NO_DH) && \
  4570. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4571. WOLFSSL_CTX *ctx = NULL;
  4572. #ifndef NO_WOLFSSL_CLIENT
  4573. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4574. #else
  4575. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4576. #endif
  4577. /* invalid context */
  4578. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(NULL,
  4579. dh_key_der_2048, sizeof_dh_key_der_2048,
  4580. WOLFSSL_FILETYPE_ASN1));
  4581. /* invalid dhParamFile file */
  4582. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(NULL, NULL,
  4583. 0, WOLFSSL_FILETYPE_ASN1));
  4584. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx, NULL,
  4585. 0, WOLFSSL_FILETYPE_ASN1));
  4586. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4587. dsa_key_der_2048, sizeof_dsa_key_der_2048,
  4588. WOLFSSL_FILETYPE_ASN1));
  4589. /* invalid file format */
  4590. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4591. dh_key_der_2048, sizeof_dh_key_der_2048, -1));
  4592. /* success */
  4593. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4594. dh_key_der_2048, sizeof_dh_key_der_2048,
  4595. WOLFSSL_FILETYPE_ASN1));
  4596. wolfSSL_CTX_free(ctx);
  4597. #endif
  4598. return EXPECT_RESULT();
  4599. }
  4600. static int test_wolfSSL_CTX_SetMinMaxDhKey_Sz(void)
  4601. {
  4602. EXPECT_DECLS;
  4603. #if !defined(NO_CERTS) && !defined(NO_DH) && \
  4604. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4605. WOLFSSL_CTX *ctx;
  4606. (void)ctx;
  4607. #ifndef NO_WOLFSSL_CLIENT
  4608. ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  4609. #else
  4610. ctx = wolfSSL_CTX_new(wolfSSLv23_server_method());
  4611. #endif
  4612. ExpectNotNull(ctx);
  4613. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMinDhKey_Sz(ctx, 3072));
  4614. ExpectIntEQ(WC_NO_ERR_TRACE(DH_KEY_SIZE_E), wolfSSL_CTX_SetTmpDH_buffer(ctx, dh_key_der_2048,
  4615. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4616. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMinDhKey_Sz(ctx, 2048));
  4617. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4618. dh_key_der_2048, sizeof_dh_key_der_2048,
  4619. WOLFSSL_FILETYPE_ASN1));
  4620. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMaxDhKey_Sz(ctx, 1024));
  4621. ExpectIntEQ(WC_NO_ERR_TRACE(DH_KEY_SIZE_E), wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4622. dh_key_der_2048, sizeof_dh_key_der_2048,
  4623. WOLFSSL_FILETYPE_ASN1));
  4624. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMaxDhKey_Sz(ctx, 2048));
  4625. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_buffer(ctx,
  4626. dh_key_der_2048, sizeof_dh_key_der_2048,
  4627. WOLFSSL_FILETYPE_ASN1));
  4628. wolfSSL_CTX_free(ctx);
  4629. #endif
  4630. return EXPECT_RESULT();
  4631. }
  4632. static int test_wolfSSL_CTX_der_load_verify_locations(void)
  4633. {
  4634. EXPECT_DECLS;
  4635. #if !defined(NO_FILESYSTEM) && defined(WOLFSSL_DER_LOAD) && \
  4636. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  4637. WOLFSSL_CTX* ctx = NULL;
  4638. const char* derCert = "./certs/server-cert.der";
  4639. const char* nullPath = NULL;
  4640. const char* invalidPath = "./certs/this-cert-does-not-exist.der";
  4641. const char* emptyPath = "";
  4642. /* der load Case 1 ctx NULL */
  4643. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, derCert,
  4644. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4645. #ifndef NO_WOLFSSL_CLIENT
  4646. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4647. #else
  4648. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4649. #endif
  4650. /* Case 2 filePath NULL */
  4651. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, nullPath,
  4652. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4653. /* Case 3 invalid format */
  4654. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, derCert,
  4655. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4656. /* Case 4 filePath not valid */
  4657. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, invalidPath,
  4658. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4659. /* Case 5 filePath empty */
  4660. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, emptyPath,
  4661. WOLFSSL_FILETYPE_ASN1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4662. #ifndef NO_RSA
  4663. /* Case 6 success case */
  4664. ExpectIntEQ(wolfSSL_CTX_der_load_verify_locations(ctx, derCert,
  4665. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  4666. #endif
  4667. wolfSSL_CTX_free(ctx);
  4668. #endif
  4669. return EXPECT_RESULT();
  4670. }
  4671. static int test_wolfSSL_CTX_enable_disable(void)
  4672. {
  4673. EXPECT_DECLS;
  4674. #ifndef NO_CERTS
  4675. WOLFSSL_CTX* ctx = NULL;
  4676. #ifdef HAVE_CRL
  4677. ExpectIntEQ(wolfSSL_CTX_DisableCRL(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4678. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4679. #endif
  4680. #ifdef HAVE_OCSP
  4681. ExpectIntEQ(wolfSSL_CTX_DisableOCSP(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4682. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4683. #endif
  4684. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) || \
  4685. defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  4686. ExpectIntEQ(wolfSSL_CTX_DisableOCSPStapling(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4687. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4688. ExpectIntEQ(wolfSSL_CTX_DisableOCSPMustStaple(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4689. ExpectIntEQ(wolfSSL_CTX_EnableOCSPMustStaple(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4690. #endif
  4691. #ifndef NO_WOLFSSL_CLIENT
  4692. #ifdef HAVE_EXTENDED_MASTER
  4693. ExpectIntEQ(wolfSSL_CTX_DisableExtendedMasterSecret(ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  4694. #endif
  4695. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4696. #ifdef HAVE_EXTENDED_MASTER
  4697. ExpectIntEQ(wolfSSL_CTX_DisableExtendedMasterSecret(ctx), WOLFSSL_SUCCESS);
  4698. #endif
  4699. #elif !defined(NO_WOLFSSL_SERVER)
  4700. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4701. #endif
  4702. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  4703. #ifdef HAVE_CRL
  4704. ExpectIntEQ(wolfSSL_CTX_DisableCRL(ctx), WOLFSSL_SUCCESS);
  4705. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, 0), WOLFSSL_SUCCESS);
  4706. #endif
  4707. #ifdef HAVE_OCSP
  4708. ExpectIntEQ(wolfSSL_CTX_DisableOCSP(ctx), WOLFSSL_SUCCESS);
  4709. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, WOLFSSL_OCSP_URL_OVERRIDE),
  4710. WOLFSSL_SUCCESS);
  4711. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, WOLFSSL_OCSP_NO_NONCE),
  4712. WOLFSSL_SUCCESS);
  4713. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, WOLFSSL_OCSP_CHECKALL),
  4714. WOLFSSL_SUCCESS);
  4715. #endif
  4716. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) || \
  4717. defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  4718. ExpectIntEQ(wolfSSL_CTX_DisableOCSPStapling(ctx), WOLFSSL_SUCCESS);
  4719. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), WOLFSSL_SUCCESS);
  4720. ExpectIntEQ(wolfSSL_CTX_DisableOCSPMustStaple(ctx), WOLFSSL_SUCCESS);
  4721. ExpectIntEQ(wolfSSL_CTX_DisableOCSPMustStaple(ctx), WOLFSSL_SUCCESS);
  4722. #endif
  4723. wolfSSL_CTX_free(ctx);
  4724. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  4725. #endif /* NO_CERTS */
  4726. return EXPECT_RESULT();
  4727. }
  4728. static int test_wolfSSL_CTX_ticket_API(void)
  4729. {
  4730. EXPECT_DECLS;
  4731. #if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_SERVER)
  4732. WOLFSSL_CTX* ctx = NULL;
  4733. void *userCtx = (void*)"this is my ctx";
  4734. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4735. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_set_TicketEncCtx(ctx, userCtx));
  4736. ExpectTrue(userCtx == wolfSSL_CTX_get_TicketEncCtx(ctx));
  4737. wolfSSL_CTX_free(ctx);
  4738. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_set_TicketEncCtx(NULL, userCtx));
  4739. ExpectNull(wolfSSL_CTX_get_TicketEncCtx(NULL));
  4740. #endif /* HAVE_SESSION_TICKET && !NO_WOLFSSL_SERVER */
  4741. return EXPECT_RESULT();
  4742. }
  4743. static int test_wolfSSL_set_minmax_proto_version(void)
  4744. {
  4745. EXPECT_DECLS;
  4746. #ifdef OPENSSL_EXTRA
  4747. WOLFSSL_CTX *ctx = NULL;
  4748. WOLFSSL *ssl = NULL;
  4749. (void)ssl;
  4750. #ifndef NO_WOLFSSL_CLIENT
  4751. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4752. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4753. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4754. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4755. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, 0), SSL_SUCCESS);
  4756. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(ctx, 0), SSL_SUCCESS);
  4757. ExpectIntEQ(wolfSSL_set_min_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4758. ExpectIntEQ(wolfSSL_set_min_proto_version(ssl, 0), SSL_SUCCESS);
  4759. ExpectIntEQ(wolfSSL_set_max_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4760. ExpectIntEQ(wolfSSL_set_max_proto_version(ssl, 0), SSL_SUCCESS);
  4761. wolfSSL_free(ssl);
  4762. wolfSSL_CTX_free(ctx);
  4763. ctx = NULL;
  4764. #endif
  4765. #ifndef NO_WOLFSSL_SERVER
  4766. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4767. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4768. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  4769. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, 0), SSL_SUCCESS);
  4770. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(ctx, 0), SSL_SUCCESS);
  4771. wolfSSL_CTX_free(ctx);
  4772. #endif
  4773. #endif
  4774. return EXPECT_RESULT();
  4775. }
  4776. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_TLS12) && \
  4777. defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  4778. static int test_wolfSSL_CTX_set_max_proto_version_on_result(WOLFSSL* ssl)
  4779. {
  4780. EXPECT_DECLS;
  4781. ExpectStrEQ(wolfSSL_get_version(ssl), "TLSv1.2");
  4782. return EXPECT_RESULT();
  4783. }
  4784. static int test_wolfSSL_CTX_set_max_proto_version_ctx_ready(WOLFSSL_CTX* ctx)
  4785. {
  4786. EXPECT_DECLS;
  4787. /* Set TLS 1.2 */
  4788. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(ctx, TLS1_2_VERSION),
  4789. WOLFSSL_SUCCESS);
  4790. return EXPECT_RESULT();
  4791. }
  4792. /* Test using wolfSSL_CTX_set_max_proto_version to limit the version below
  4793. * what was set at ctx creation. */
  4794. static int test_wolfSSL_CTX_set_max_proto_version(void)
  4795. {
  4796. EXPECT_DECLS;
  4797. test_ssl_cbf client_cbs;
  4798. test_ssl_cbf server_cbs;
  4799. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  4800. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  4801. client_cbs.method = wolfTLS_client_method;
  4802. server_cbs.method = wolfTLS_server_method;
  4803. server_cbs.ctx_ready = test_wolfSSL_CTX_set_max_proto_version_ctx_ready;
  4804. client_cbs.on_result = test_wolfSSL_CTX_set_max_proto_version_on_result;
  4805. server_cbs.on_result = test_wolfSSL_CTX_set_max_proto_version_on_result;
  4806. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  4807. &server_cbs, NULL), TEST_SUCCESS);
  4808. return EXPECT_RESULT();
  4809. }
  4810. #else
  4811. static int test_wolfSSL_CTX_set_max_proto_version(void)
  4812. {
  4813. return TEST_SKIPPED;
  4814. }
  4815. #endif
  4816. /*----------------------------------------------------------------------------*
  4817. | SSL
  4818. *----------------------------------------------------------------------------*/
  4819. static int test_server_wolfSSL_new(void)
  4820. {
  4821. EXPECT_DECLS;
  4822. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4823. !defined(NO_WOLFSSL_SERVER)
  4824. WOLFSSL_CTX *ctx = NULL;
  4825. WOLFSSL_CTX *ctx_nocert = NULL;
  4826. WOLFSSL *ssl = NULL;
  4827. ExpectNotNull(ctx_nocert = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4828. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4829. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  4830. WOLFSSL_FILETYPE_PEM));
  4831. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  4832. WOLFSSL_FILETYPE_PEM));
  4833. /* invalid context */
  4834. ExpectNull(ssl = wolfSSL_new(NULL));
  4835. #if !defined(WOLFSSL_SESSION_EXPORT) && !defined(WOLFSSL_QT) && \
  4836. !defined(OPENSSL_EXTRA) && !defined(WOLFSSL_NO_INIT_CTX_KEY)
  4837. ExpectNull(ssl = wolfSSL_new(ctx_nocert));
  4838. #endif
  4839. /* success */
  4840. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4841. wolfSSL_free(ssl);
  4842. wolfSSL_CTX_free(ctx);
  4843. wolfSSL_CTX_free(ctx_nocert);
  4844. #endif
  4845. return EXPECT_RESULT();
  4846. }
  4847. static int test_client_wolfSSL_new(void)
  4848. {
  4849. EXPECT_DECLS;
  4850. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  4851. !defined(NO_WOLFSSL_CLIENT)
  4852. WOLFSSL_CTX *ctx = NULL;
  4853. WOLFSSL_CTX *ctx_nocert = NULL;
  4854. WOLFSSL *ssl = NULL;
  4855. ExpectNotNull(ctx_nocert = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4856. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  4857. ExpectTrue(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0));
  4858. /* invalid context */
  4859. ExpectNull(ssl = wolfSSL_new(NULL));
  4860. /* success */
  4861. ExpectNotNull(ssl = wolfSSL_new(ctx_nocert));
  4862. wolfSSL_free(ssl);
  4863. ssl = NULL;
  4864. /* success */
  4865. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4866. wolfSSL_free(ssl);
  4867. wolfSSL_CTX_free(ctx);
  4868. wolfSSL_CTX_free(ctx_nocert);
  4869. #endif
  4870. return EXPECT_RESULT();
  4871. }
  4872. static int test_wolfSSL_SetTmpDH_file(void)
  4873. {
  4874. EXPECT_DECLS;
  4875. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_DH) && \
  4876. !defined(NO_WOLFSSL_SERVER)
  4877. WOLFSSL_CTX *ctx = NULL;
  4878. WOLFSSL *ssl = NULL;
  4879. const char* dhX942ParamFile = "./certs/x942dh2048.pem";
  4880. #if defined(WOLFSSL_WPAS) && !defined(NO_DSA)
  4881. const char* dsaParamFile = "./certs/dsaparams.pem";
  4882. #endif
  4883. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4884. #ifndef NO_RSA
  4885. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  4886. WOLFSSL_FILETYPE_PEM));
  4887. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  4888. WOLFSSL_FILETYPE_PEM));
  4889. #elif defined(HAVE_ECC)
  4890. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, eccCertFile,
  4891. WOLFSSL_FILETYPE_PEM));
  4892. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, eccKeyFile,
  4893. WOLFSSL_FILETYPE_PEM));
  4894. #elif defined(HAVE_ED25519)
  4895. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, edCertFile,
  4896. WOLFSSL_FILETYPE_PEM));
  4897. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, edKeyFile,
  4898. WOLFSSL_FILETYPE_PEM));
  4899. #elif defined(HAVE_ED448)
  4900. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, ed448CertFile,
  4901. WOLFSSL_FILETYPE_PEM));
  4902. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, ed448KeyFile,
  4903. WOLFSSL_FILETYPE_PEM));
  4904. #endif
  4905. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4906. /* invalid ssl */
  4907. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_file(NULL,
  4908. dhParamFile, WOLFSSL_FILETYPE_PEM));
  4909. /* invalid dhParamFile file */
  4910. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_file(ssl,
  4911. NULL, WOLFSSL_FILETYPE_PEM));
  4912. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_file(ssl,
  4913. bogusFile, WOLFSSL_FILETYPE_PEM));
  4914. /* success */
  4915. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_file(ssl, dhParamFile,
  4916. WOLFSSL_FILETYPE_PEM));
  4917. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_file(ssl, dhX942ParamFile,
  4918. WOLFSSL_FILETYPE_PEM));
  4919. #if defined(WOLFSSL_WPAS) && !defined(NO_DSA)
  4920. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpDH_file(ctx, dsaParamFile,
  4921. WOLFSSL_FILETYPE_PEM));
  4922. #endif
  4923. wolfSSL_free(ssl);
  4924. wolfSSL_CTX_free(ctx);
  4925. #endif
  4926. return EXPECT_RESULT();
  4927. }
  4928. static int test_wolfSSL_SetTmpDH_buffer(void)
  4929. {
  4930. EXPECT_DECLS;
  4931. #if !defined(NO_CERTS) && !defined(NO_DH) && !defined(NO_WOLFSSL_SERVER)
  4932. WOLFSSL_CTX *ctx = NULL;
  4933. WOLFSSL *ssl = NULL;
  4934. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4935. ExpectTrue(wolfSSL_CTX_use_certificate_buffer(ctx, server_cert_der_2048,
  4936. sizeof_server_cert_der_2048, WOLFSSL_FILETYPE_ASN1));
  4937. ExpectTrue(wolfSSL_CTX_use_PrivateKey_buffer(ctx, server_key_der_2048,
  4938. sizeof_server_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4939. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4940. /* invalid ssl */
  4941. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(NULL, dh_key_der_2048,
  4942. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4943. /* invalid dhParamFile file */
  4944. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(NULL, NULL,
  4945. 0, WOLFSSL_FILETYPE_ASN1));
  4946. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl, NULL, 0,
  4947. WOLFSSL_FILETYPE_ASN1));
  4948. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl, dsa_key_der_2048,
  4949. sizeof_dsa_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4950. /* success */
  4951. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl, dh_key_der_2048,
  4952. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4953. wolfSSL_free(ssl);
  4954. wolfSSL_CTX_free(ctx);
  4955. #endif
  4956. return EXPECT_RESULT();
  4957. }
  4958. static int test_wolfSSL_SetMinMaxDhKey_Sz(void)
  4959. {
  4960. EXPECT_DECLS;
  4961. #if !defined(NO_CERTS) && !defined(NO_DH) && !defined(NO_WOLFSSL_SERVER)
  4962. WOLFSSL_CTX *ctx = NULL;
  4963. WOLFSSL_CTX *ctx2 = NULL;
  4964. WOLFSSL *ssl = NULL;
  4965. WOLFSSL *ssl2 = NULL;
  4966. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4967. ExpectTrue(wolfSSL_CTX_use_certificate_buffer(ctx, server_cert_der_2048,
  4968. sizeof_server_cert_der_2048, WOLFSSL_FILETYPE_ASN1));
  4969. ExpectTrue(wolfSSL_CTX_use_PrivateKey_buffer(ctx, server_key_der_2048,
  4970. sizeof_server_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4971. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMinDhKey_Sz(ctx, 3072));
  4972. ExpectNotNull(ssl = wolfSSL_new(ctx));
  4973. ExpectNotNull(ctx2 = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  4974. ExpectTrue(wolfSSL_CTX_use_certificate_buffer(ctx2, server_cert_der_2048,
  4975. sizeof_server_cert_der_2048, WOLFSSL_FILETYPE_ASN1));
  4976. ExpectTrue(wolfSSL_CTX_use_PrivateKey_buffer(ctx2, server_key_der_2048,
  4977. sizeof_server_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4978. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetMaxDhKey_Sz(ctx, 1024));
  4979. ExpectNotNull(ssl2 = wolfSSL_new(ctx2));
  4980. ExpectIntEQ(WC_NO_ERR_TRACE(DH_KEY_SIZE_E), wolfSSL_SetTmpDH_buffer(ssl, dh_key_der_2048,
  4981. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4982. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetMinDhKey_Sz(ssl, 2048));
  4983. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl, dh_key_der_2048,
  4984. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4985. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetMinDhKey_Sz(ssl, 3072));
  4986. ExpectIntEQ(WC_NO_ERR_TRACE(DH_KEY_SIZE_E), wolfSSL_SetTmpDH_buffer(ssl, dh_key_der_2048,
  4987. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4988. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl2, dh_key_der_2048,
  4989. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4990. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetMaxDhKey_Sz(ssl2, 2048));
  4991. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpDH_buffer(ssl2, dh_key_der_2048,
  4992. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4993. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetMaxDhKey_Sz(ssl2, 1024));
  4994. ExpectIntEQ(WC_NO_ERR_TRACE(DH_KEY_SIZE_E), wolfSSL_SetTmpDH_buffer(ssl, dh_key_der_2048,
  4995. sizeof_dh_key_der_2048, WOLFSSL_FILETYPE_ASN1));
  4996. wolfSSL_free(ssl2);
  4997. wolfSSL_CTX_free(ctx2);
  4998. wolfSSL_free(ssl);
  4999. wolfSSL_CTX_free(ctx);
  5000. #endif
  5001. return EXPECT_RESULT();
  5002. }
  5003. /* Test function for wolfSSL_SetMinVersion. Sets the minimum downgrade version
  5004. * allowed.
  5005. * POST: return 1 on success.
  5006. */
  5007. static int test_wolfSSL_SetMinVersion(void)
  5008. {
  5009. int res = TEST_SKIPPED;
  5010. #ifndef NO_WOLFSSL_CLIENT
  5011. int failFlag = WOLFSSL_SUCCESS;
  5012. WOLFSSL_CTX* ctx = NULL;
  5013. WOLFSSL* ssl = NULL;
  5014. int itr;
  5015. #ifndef NO_OLD_TLS
  5016. const int versions[] = {
  5017. #ifdef WOLFSSL_ALLOW_TLSV10
  5018. WOLFSSL_TLSV1,
  5019. #endif
  5020. WOLFSSL_TLSV1_1,
  5021. WOLFSSL_TLSV1_2};
  5022. #elif !defined(WOLFSSL_NO_TLS12)
  5023. const int versions[] = { WOLFSSL_TLSV1_2 };
  5024. #else
  5025. const int versions[] = { WOLFSSL_TLSV1_3 };
  5026. #endif
  5027. ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  5028. ssl = wolfSSL_new(ctx);
  5029. for (itr = 0; itr < (int)(sizeof(versions)/sizeof(int)); itr++) {
  5030. if (wolfSSL_SetMinVersion(ssl, *(versions + itr)) != WOLFSSL_SUCCESS) {
  5031. failFlag = WOLFSSL_FAILURE;
  5032. }
  5033. }
  5034. wolfSSL_free(ssl);
  5035. wolfSSL_CTX_free(ctx);
  5036. res = TEST_RES_CHECK(failFlag == WOLFSSL_SUCCESS);
  5037. #endif
  5038. return res;
  5039. } /* END test_wolfSSL_SetMinVersion */
  5040. #ifdef OPENSSL_EXTRA
  5041. static int test_EC25519(void)
  5042. {
  5043. EXPECT_DECLS;
  5044. #if defined(HAVE_CURVE25519) && defined(WOLFSSL_KEY_GEN)
  5045. byte priv[CURVE25519_KEYSIZE];
  5046. unsigned int privSz = CURVE25519_KEYSIZE;
  5047. byte pub[CURVE25519_KEYSIZE];
  5048. unsigned int pubSz = CURVE25519_KEYSIZE;
  5049. byte priv2[CURVE25519_KEYSIZE];
  5050. unsigned int priv2Sz = CURVE25519_KEYSIZE;
  5051. byte pub2[CURVE25519_KEYSIZE];
  5052. unsigned int pub2Sz = CURVE25519_KEYSIZE;
  5053. byte shared[CURVE25519_KEYSIZE];
  5054. unsigned int sharedSz = CURVE25519_KEYSIZE;
  5055. byte shared2[CURVE25519_KEYSIZE];
  5056. unsigned int shared2Sz = CURVE25519_KEYSIZE;
  5057. /* Bad parameter testing of key generation. */
  5058. ExpectIntEQ(wolfSSL_EC25519_generate_key(NULL, NULL, NULL, NULL), 0);
  5059. ExpectIntEQ(wolfSSL_EC25519_generate_key(NULL, &privSz, NULL, &pubSz), 0);
  5060. ExpectIntEQ(wolfSSL_EC25519_generate_key(NULL, &privSz, pub, &pubSz), 0);
  5061. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, NULL, pub, &pubSz), 0);
  5062. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, &privSz, NULL, &pubSz), 0);
  5063. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, &privSz, pub, NULL), 0);
  5064. /* Bad length */
  5065. privSz = 1;
  5066. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, &privSz, pub, &pubSz), 0);
  5067. privSz = CURVE25519_KEYSIZE;
  5068. pubSz = 1;
  5069. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, &privSz, pub, &pubSz), 0);
  5070. pubSz = CURVE25519_KEYSIZE;
  5071. /* Good case of generating key. */
  5072. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv, &privSz, pub, &pubSz), 1);
  5073. ExpectIntEQ(wolfSSL_EC25519_generate_key(priv2, &priv2Sz, pub2, &pub2Sz),
  5074. 1);
  5075. ExpectIntEQ(privSz, CURVE25519_KEYSIZE);
  5076. ExpectIntEQ(pubSz, CURVE25519_KEYSIZE);
  5077. /* Bad parameter testing of shared key. */
  5078. ExpectIntEQ(wolfSSL_EC25519_shared_key( NULL, NULL, NULL, privSz,
  5079. NULL, pubSz), 0);
  5080. ExpectIntEQ(wolfSSL_EC25519_shared_key( NULL, &sharedSz, NULL, privSz,
  5081. NULL, pubSz), 0);
  5082. ExpectIntEQ(wolfSSL_EC25519_shared_key( NULL, &sharedSz, priv, privSz,
  5083. pub, pubSz), 0);
  5084. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, NULL, privSz,
  5085. pub, pubSz), 0);
  5086. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  5087. NULL, pubSz), 0);
  5088. ExpectIntEQ(wolfSSL_EC25519_shared_key( NULL, &sharedSz, priv, privSz,
  5089. pub, pubSz), 0);
  5090. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, NULL, priv, privSz,
  5091. pub, pubSz), 0);
  5092. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, NULL, privSz,
  5093. pub, pubSz), 0);
  5094. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  5095. NULL, pubSz), 0);
  5096. /* Bad length. */
  5097. sharedSz = 1;
  5098. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  5099. pub, pubSz), 0);
  5100. sharedSz = CURVE25519_KEYSIZE;
  5101. privSz = 1;
  5102. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  5103. pub, pubSz), 0);
  5104. privSz = CURVE25519_KEYSIZE;
  5105. pubSz = 1;
  5106. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  5107. pub, pubSz), 0);
  5108. pubSz = CURVE25519_KEYSIZE;
  5109. /* Good case of shared key. */
  5110. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared, &sharedSz, priv, privSz,
  5111. pub2, pub2Sz), 1);
  5112. ExpectIntEQ(wolfSSL_EC25519_shared_key(shared2, &shared2Sz, priv2, priv2Sz,
  5113. pub, pubSz), 1);
  5114. ExpectIntEQ(sharedSz, CURVE25519_KEYSIZE);
  5115. ExpectIntEQ(shared2Sz, CURVE25519_KEYSIZE);
  5116. ExpectIntEQ(XMEMCMP(shared, shared2, sharedSz), 0);
  5117. #endif /* HAVE_CURVE25519 && WOLFSSL_KEY_GEN */
  5118. return EXPECT_RESULT();
  5119. }
  5120. static int test_ED25519(void)
  5121. {
  5122. EXPECT_DECLS;
  5123. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT) && \
  5124. defined(WOLFSSL_KEY_GEN)
  5125. byte priv[ED25519_PRV_KEY_SIZE];
  5126. unsigned int privSz = (unsigned int)sizeof(priv);
  5127. byte pub[ED25519_PUB_KEY_SIZE];
  5128. unsigned int pubSz = (unsigned int)sizeof(pub);
  5129. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_IMPORT)
  5130. const char* msg = TEST_STRING;
  5131. unsigned int msglen = (unsigned int)TEST_STRING_SZ;
  5132. byte sig[ED25519_SIG_SIZE];
  5133. unsigned int sigSz = (unsigned int)sizeof(sig);
  5134. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_IMPORT */
  5135. /* Bad parameter testing of key generation. */
  5136. ExpectIntEQ(wolfSSL_ED25519_generate_key(NULL, NULL, NULL, NULL), 0);
  5137. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, NULL, NULL, NULL), 0);
  5138. ExpectIntEQ(wolfSSL_ED25519_generate_key(NULL, &privSz, NULL, NULL), 0);
  5139. ExpectIntEQ(wolfSSL_ED25519_generate_key(NULL, NULL, pub, NULL), 0);
  5140. ExpectIntEQ(wolfSSL_ED25519_generate_key(NULL, NULL, NULL, &pubSz), 0);
  5141. ExpectIntEQ(wolfSSL_ED25519_generate_key(NULL, &privSz, pub, &pubSz), 0);
  5142. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, NULL, pub, &pubSz), 0);
  5143. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, &privSz, NULL, &pubSz), 0);
  5144. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, &privSz, pub, NULL), 0);
  5145. /* Bad length. */
  5146. privSz = 1;
  5147. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, &privSz, pub, &pubSz), 0);
  5148. privSz = ED25519_PRV_KEY_SIZE;
  5149. pubSz = 1;
  5150. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, &privSz, pub, &pubSz), 0);
  5151. pubSz = ED25519_PUB_KEY_SIZE;
  5152. /* Good case of generating key. */
  5153. ExpectIntEQ(wolfSSL_ED25519_generate_key(priv, &privSz, pub, &pubSz),
  5154. 1);
  5155. ExpectIntEQ(privSz, ED25519_PRV_KEY_SIZE);
  5156. ExpectIntEQ(pubSz, ED25519_PUB_KEY_SIZE);
  5157. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_IMPORT)
  5158. /* Bad parameter testing of signing. */
  5159. ExpectIntEQ(wolfSSL_ED25519_sign( NULL, msglen, NULL, privSz, NULL,
  5160. NULL), 0);
  5161. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, NULL, privSz, NULL,
  5162. NULL), 0);
  5163. ExpectIntEQ(wolfSSL_ED25519_sign( NULL, msglen, priv, privSz, NULL,
  5164. NULL), 0);
  5165. ExpectIntEQ(wolfSSL_ED25519_sign( NULL, msglen, NULL, privSz, sig,
  5166. NULL), 0);
  5167. ExpectIntEQ(wolfSSL_ED25519_sign( NULL, msglen, NULL, privSz, NULL,
  5168. &sigSz), 0);
  5169. ExpectIntEQ(wolfSSL_ED25519_sign( NULL, msglen, priv, privSz, sig,
  5170. &sigSz), 0);
  5171. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, NULL, privSz, sig,
  5172. &sigSz), 0);
  5173. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, priv, privSz, NULL,
  5174. &sigSz), 0);
  5175. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, priv, privSz, sig,
  5176. NULL), 0);
  5177. /* Bad length. */
  5178. privSz = 1;
  5179. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, priv, privSz, sig,
  5180. &sigSz), 0);
  5181. privSz = ED25519_PRV_KEY_SIZE;
  5182. sigSz = 1;
  5183. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, priv, privSz, sig,
  5184. &sigSz), 0);
  5185. sigSz = ED25519_SIG_SIZE;
  5186. /* Good case of signing. */
  5187. ExpectIntEQ(wolfSSL_ED25519_sign((byte*)msg, msglen, priv, privSz, sig,
  5188. &sigSz), 1);
  5189. ExpectIntEQ(sigSz, ED25519_SIG_SIZE);
  5190. #ifdef HAVE_ED25519_VERIFY
  5191. /* Bad parameter testing of verification. */
  5192. ExpectIntEQ(wolfSSL_ED25519_verify( NULL, msglen, NULL, pubSz, NULL,
  5193. sigSz), 0);
  5194. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, NULL, pubSz, NULL,
  5195. sigSz), 0);
  5196. ExpectIntEQ(wolfSSL_ED25519_verify( NULL, msglen, pub, pubSz, NULL,
  5197. sigSz), 0);
  5198. ExpectIntEQ(wolfSSL_ED25519_verify( NULL, msglen, NULL, pubSz, sig,
  5199. sigSz), 0);
  5200. ExpectIntEQ(wolfSSL_ED25519_verify( NULL, msglen, pub, pubSz, sig,
  5201. sigSz), 0);
  5202. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, NULL, pubSz, sig,
  5203. sigSz), 0);
  5204. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, pub, pubSz, NULL,
  5205. sigSz), 0);
  5206. /* Bad length. */
  5207. pubSz = 1;
  5208. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, pub, pubSz, sig,
  5209. sigSz), 0);
  5210. pubSz = ED25519_PUB_KEY_SIZE;
  5211. sigSz = 1;
  5212. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, pub, pubSz, sig,
  5213. sigSz), 0);
  5214. sigSz = ED25519_SIG_SIZE;
  5215. /* Good case of verification. */
  5216. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, pub, pubSz, sig,
  5217. sigSz), 1);
  5218. /* Bad signature. */
  5219. if (EXPECT_SUCCESS()) {
  5220. sig[1] ^= 0x80;
  5221. }
  5222. ExpectIntEQ(wolfSSL_ED25519_verify((byte*)msg, msglen, pub, pubSz, sig,
  5223. sigSz), 0);
  5224. #endif /* HAVE_ED25519_VERIFY */
  5225. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_IMPORT */
  5226. #endif /* HAVE_ED25519 && HAVE_ED25519_KEY_EXPORT && WOLFSSL_KEY_GEN */
  5227. return EXPECT_RESULT();
  5228. }
  5229. static int test_EC448(void)
  5230. {
  5231. EXPECT_DECLS;
  5232. #if defined(HAVE_CURVE448) && defined(WOLFSSL_KEY_GEN)
  5233. byte priv[CURVE448_KEY_SIZE];
  5234. unsigned int privSz = CURVE448_KEY_SIZE;
  5235. byte pub[CURVE448_KEY_SIZE];
  5236. unsigned int pubSz = CURVE448_KEY_SIZE;
  5237. byte priv2[CURVE448_KEY_SIZE];
  5238. unsigned int priv2Sz = CURVE448_KEY_SIZE;
  5239. byte pub2[CURVE448_KEY_SIZE];
  5240. unsigned int pub2Sz = CURVE448_KEY_SIZE;
  5241. byte shared[CURVE448_KEY_SIZE];
  5242. unsigned int sharedSz = CURVE448_KEY_SIZE;
  5243. byte shared2[CURVE448_KEY_SIZE];
  5244. unsigned int shared2Sz = CURVE448_KEY_SIZE;
  5245. /* Bad parameter testing of key generation. */
  5246. ExpectIntEQ(wolfSSL_EC448_generate_key(NULL, NULL, NULL, NULL), 0);
  5247. ExpectIntEQ(wolfSSL_EC448_generate_key(NULL, &privSz, NULL, &pubSz), 0);
  5248. ExpectIntEQ(wolfSSL_EC448_generate_key(NULL, &privSz, pub, &pubSz), 0);
  5249. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, NULL, pub, &pubSz), 0);
  5250. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, &privSz, NULL, &pubSz), 0);
  5251. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, &privSz, pub, NULL), 0);
  5252. /* Bad length. */
  5253. privSz = 1;
  5254. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, &privSz, pub, &pubSz), 0);
  5255. privSz = CURVE448_KEY_SIZE;
  5256. pubSz = 1;
  5257. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, &privSz, pub, &pubSz), 0);
  5258. pubSz = CURVE448_KEY_SIZE;
  5259. /* Good case of generating key. */
  5260. ExpectIntEQ(wolfSSL_EC448_generate_key(priv, &privSz, pub, &pubSz), 1);
  5261. ExpectIntEQ(wolfSSL_EC448_generate_key(priv2, &priv2Sz, pub2, &pub2Sz), 1);
  5262. ExpectIntEQ(privSz, CURVE448_KEY_SIZE);
  5263. ExpectIntEQ(pubSz, CURVE448_KEY_SIZE);
  5264. /* Bad parameter testing of shared key. */
  5265. ExpectIntEQ(wolfSSL_EC448_shared_key( NULL, NULL, NULL, privSz,
  5266. NULL, pubSz), 0);
  5267. ExpectIntEQ(wolfSSL_EC448_shared_key( NULL, &sharedSz, NULL, privSz,
  5268. NULL, pubSz), 0);
  5269. ExpectIntEQ(wolfSSL_EC448_shared_key( NULL, &sharedSz, priv, privSz,
  5270. pub, pubSz), 0);
  5271. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, NULL, privSz,
  5272. pub, pubSz), 0);
  5273. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5274. NULL, pubSz), 0);
  5275. ExpectIntEQ(wolfSSL_EC448_shared_key( NULL, &sharedSz, priv, privSz,
  5276. pub, pubSz), 0);
  5277. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, NULL, priv, privSz,
  5278. pub, pubSz), 0);
  5279. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, NULL, privSz,
  5280. pub, pubSz), 0);
  5281. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5282. NULL, pubSz), 0);
  5283. /* Bad length. */
  5284. sharedSz = 1;
  5285. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5286. pub, pubSz), 0);
  5287. sharedSz = CURVE448_KEY_SIZE;
  5288. privSz = 1;
  5289. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5290. pub, pubSz), 0);
  5291. privSz = CURVE448_KEY_SIZE;
  5292. pubSz = 1;
  5293. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5294. pub, pubSz), 0);
  5295. pubSz = CURVE448_KEY_SIZE;
  5296. /* Good case of shared key. */
  5297. ExpectIntEQ(wolfSSL_EC448_shared_key(shared, &sharedSz, priv, privSz,
  5298. pub2, pub2Sz), 1);
  5299. ExpectIntEQ(wolfSSL_EC448_shared_key(shared2, &shared2Sz, priv2, priv2Sz,
  5300. pub, pubSz), 1);
  5301. ExpectIntEQ(sharedSz, CURVE448_KEY_SIZE);
  5302. ExpectIntEQ(shared2Sz, CURVE448_KEY_SIZE);
  5303. ExpectIntEQ(XMEMCMP(shared, shared2, sharedSz), 0);
  5304. #endif /* HAVE_CURVE448 && WOLFSSL_KEY_GEN */
  5305. return EXPECT_RESULT();
  5306. }
  5307. static int test_ED448(void)
  5308. {
  5309. EXPECT_DECLS;
  5310. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT) && \
  5311. defined(WOLFSSL_KEY_GEN)
  5312. byte priv[ED448_PRV_KEY_SIZE];
  5313. unsigned int privSz = (unsigned int)sizeof(priv);
  5314. byte pub[ED448_PUB_KEY_SIZE];
  5315. unsigned int pubSz = (unsigned int)sizeof(pub);
  5316. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_IMPORT)
  5317. const char* msg = TEST_STRING;
  5318. unsigned int msglen = (unsigned int)TEST_STRING_SZ;
  5319. byte sig[ED448_SIG_SIZE];
  5320. unsigned int sigSz = (unsigned int)sizeof(sig);
  5321. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_IMPORT */
  5322. /* Bad parameter testing of key generation. */
  5323. ExpectIntEQ(wolfSSL_ED448_generate_key(NULL, NULL, NULL, NULL), 0);
  5324. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, NULL, NULL, NULL), 0);
  5325. ExpectIntEQ(wolfSSL_ED448_generate_key(NULL, &privSz, NULL, NULL), 0);
  5326. ExpectIntEQ(wolfSSL_ED448_generate_key(NULL, NULL, pub, NULL), 0);
  5327. ExpectIntEQ(wolfSSL_ED448_generate_key(NULL, NULL, NULL, &pubSz), 0);
  5328. ExpectIntEQ(wolfSSL_ED448_generate_key(NULL, &privSz, pub, &pubSz), 0);
  5329. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, NULL, pub, &pubSz), 0);
  5330. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, &privSz, NULL, &pubSz), 0);
  5331. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, &privSz, pub, NULL), 0);
  5332. /* Bad length. */
  5333. privSz = 1;
  5334. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, &privSz, pub, &pubSz), 0);
  5335. privSz = ED448_PRV_KEY_SIZE;
  5336. pubSz = 1;
  5337. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, &privSz, pub, &pubSz), 0);
  5338. pubSz = ED448_PUB_KEY_SIZE;
  5339. /* Good case of generating key. */
  5340. ExpectIntEQ(wolfSSL_ED448_generate_key(priv, &privSz, pub, &pubSz), 1);
  5341. ExpectIntEQ(privSz, ED448_PRV_KEY_SIZE);
  5342. ExpectIntEQ(pubSz, ED448_PUB_KEY_SIZE);
  5343. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_IMPORT)
  5344. /* Bad parameter testing of signing. */
  5345. ExpectIntEQ(wolfSSL_ED448_sign( NULL, msglen, NULL, privSz, NULL,
  5346. NULL), 0);
  5347. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, NULL, privSz, NULL,
  5348. NULL), 0);
  5349. ExpectIntEQ(wolfSSL_ED448_sign( NULL, msglen, priv, privSz, NULL,
  5350. NULL), 0);
  5351. ExpectIntEQ(wolfSSL_ED448_sign( NULL, msglen, NULL, privSz, sig,
  5352. NULL), 0);
  5353. ExpectIntEQ(wolfSSL_ED448_sign( NULL, msglen, NULL, privSz, NULL,
  5354. &sigSz), 0);
  5355. ExpectIntEQ(wolfSSL_ED448_sign( NULL, msglen, priv, privSz, sig,
  5356. &sigSz), 0);
  5357. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, NULL, privSz, sig,
  5358. &sigSz), 0);
  5359. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, priv, privSz, NULL,
  5360. &sigSz), 0);
  5361. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, priv, privSz, sig,
  5362. NULL), 0);
  5363. /* Bad length. */
  5364. privSz = 1;
  5365. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, priv, privSz, sig,
  5366. &sigSz), 0);
  5367. privSz = ED448_PRV_KEY_SIZE;
  5368. sigSz = 1;
  5369. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, priv, privSz, sig,
  5370. &sigSz), 0);
  5371. sigSz = ED448_SIG_SIZE;
  5372. /* Good case of signing. */
  5373. ExpectIntEQ(wolfSSL_ED448_sign((byte*)msg, msglen, priv, privSz, sig,
  5374. &sigSz), 1);
  5375. ExpectIntEQ(sigSz, ED448_SIG_SIZE);
  5376. #ifdef HAVE_ED448_VERIFY
  5377. /* Bad parameter testing of verification. */
  5378. ExpectIntEQ(wolfSSL_ED448_verify( NULL, msglen, NULL, pubSz, NULL,
  5379. sigSz), 0);
  5380. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, NULL, pubSz, NULL,
  5381. sigSz), 0);
  5382. ExpectIntEQ(wolfSSL_ED448_verify( NULL, msglen, pub, pubSz, NULL,
  5383. sigSz), 0);
  5384. ExpectIntEQ(wolfSSL_ED448_verify( NULL, msglen, NULL, pubSz, sig,
  5385. sigSz), 0);
  5386. ExpectIntEQ(wolfSSL_ED448_verify( NULL, msglen, pub, pubSz, sig,
  5387. sigSz), 0);
  5388. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, NULL, pubSz, sig,
  5389. sigSz), 0);
  5390. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, pub, pubSz, NULL,
  5391. sigSz), 0);
  5392. /* Bad length. */
  5393. pubSz = 1;
  5394. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, pub, pubSz, sig,
  5395. sigSz), 0);
  5396. pubSz = ED448_PUB_KEY_SIZE;
  5397. sigSz = 1;
  5398. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, pub, pubSz, sig,
  5399. sigSz), 0);
  5400. sigSz = ED448_SIG_SIZE;
  5401. /* Good case of verification. */
  5402. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, pub, pubSz, sig,
  5403. sigSz), 1);
  5404. /* Bad signature. */
  5405. if (EXPECT_SUCCESS()) {
  5406. sig[1] ^= 0x80;
  5407. }
  5408. ExpectIntEQ(wolfSSL_ED448_verify((byte*)msg, msglen, pub, pubSz, sig,
  5409. sigSz), 0);
  5410. #endif /* HAVE_ED448_VERIFY */
  5411. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_IMPORT */
  5412. #endif /* HAVE_ED448 && HAVE_ED448_KEY_EXPORT && WOLFSSL_KEY_GEN */
  5413. return EXPECT_RESULT();
  5414. }
  5415. #endif /* OPENSSL_EXTRA */
  5416. #include <wolfssl/openssl/pem.h>
  5417. /*----------------------------------------------------------------------------*
  5418. | EVP
  5419. *----------------------------------------------------------------------------*/
  5420. static int test_wolfSSL_EVP_PKEY_print_public(void)
  5421. {
  5422. EXPECT_DECLS;
  5423. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  5424. WOLFSSL_BIO* rbio = NULL;
  5425. WOLFSSL_BIO* wbio = NULL;
  5426. WOLFSSL_EVP_PKEY* pkey = NULL;
  5427. char line[256] = { 0 };
  5428. char line1[256] = { 0 };
  5429. int i = 0;
  5430. /* test error cases */
  5431. ExpectIntEQ( EVP_PKEY_print_public(NULL,NULL,0,NULL),0L);
  5432. /*
  5433. * test RSA public key print
  5434. * in this test, pass '3' for indent
  5435. */
  5436. #if !defined(NO_RSA) && defined(USE_CERT_BUFFERS_1024)
  5437. ExpectNotNull(rbio = BIO_new_mem_buf( client_keypub_der_1024,
  5438. sizeof_client_keypub_der_1024));
  5439. ExpectNotNull(wolfSSL_d2i_PUBKEY_bio(rbio, &pkey));
  5440. ExpectNotNull(wbio = BIO_new(BIO_s_mem()));
  5441. ExpectIntEQ(EVP_PKEY_print_public(wbio, pkey,3,NULL),1);
  5442. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5443. strcpy(line1, " RSA Public-Key: (1024 bit)\n");
  5444. ExpectIntEQ(XSTRNCMP(line, line1, XSTRLEN(line1)), 0);
  5445. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5446. strcpy(line1, " Modulus:\n");
  5447. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5448. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5449. strcpy(line1, " 00:bc:73:0e:a8:49:f3:74:a2:a9:ef:18:a5:da:55:\n");
  5450. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5451. /* skip to the end of modulus element*/
  5452. for (i = 0; i < 8 ;i++) {
  5453. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5454. }
  5455. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5456. strcpy(line1, " Exponent: 65537 (0x010001)\n");
  5457. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5458. /* should reach EOF */
  5459. ExpectIntLE(BIO_gets(wbio, line, sizeof(line)), 0);
  5460. EVP_PKEY_free(pkey);
  5461. pkey = NULL;
  5462. BIO_free(rbio);
  5463. BIO_free(wbio);
  5464. rbio = NULL;
  5465. wbio = NULL;
  5466. #endif /* !NO_RSA && USE_CERT_BUFFERS_1024*/
  5467. /*
  5468. * test DSA public key print
  5469. */
  5470. #if !defined(NO_DSA) && defined(USE_CERT_BUFFERS_2048)
  5471. ExpectNotNull(rbio = BIO_new_mem_buf( dsa_pub_key_der_2048,
  5472. sizeof_dsa_pub_key_der_2048));
  5473. ExpectNotNull(wolfSSL_d2i_PUBKEY_bio(rbio, &pkey));
  5474. ExpectNotNull(wbio = BIO_new(BIO_s_mem()));
  5475. ExpectIntEQ(EVP_PKEY_print_public(wbio, pkey,0,NULL),1);
  5476. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5477. strcpy(line1, "DSA Public-Key: (2048 bit)\n");
  5478. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5479. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5480. strcpy(line1, "pub:\n");
  5481. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5482. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5483. strcpy(line1,
  5484. " 00:C2:35:2D:EC:83:83:6C:73:13:9E:52:7C:74:C8:\n");
  5485. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5486. /* skip to the end of pub element*/
  5487. for (i = 0; i < 17 ;i++) {
  5488. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5489. }
  5490. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5491. strcpy(line1, "P:\n");
  5492. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5493. /* skip to the end of P element*/
  5494. for (i = 0; i < 18 ;i++) {
  5495. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5496. }
  5497. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5498. strcpy(line1, "Q:\n");
  5499. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5500. /* skip to the end of Q element*/
  5501. for (i = 0; i < 3 ;i++) {
  5502. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5503. }
  5504. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5505. strcpy(line1, "G:\n");
  5506. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5507. /* skip to the end of G element*/
  5508. for (i = 0; i < 18 ;i++) {
  5509. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5510. }
  5511. /* should reach EOF */
  5512. ExpectIntLE(BIO_gets(wbio, line, sizeof(line)), 0);
  5513. EVP_PKEY_free(pkey);
  5514. pkey = NULL;
  5515. BIO_free(rbio);
  5516. BIO_free(wbio);
  5517. rbio = NULL;
  5518. wbio = NULL;
  5519. #endif /* !NO_DSA && USE_CERT_BUFFERS_2048 */
  5520. /*
  5521. * test ECC public key print
  5522. */
  5523. #if defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  5524. ExpectNotNull(rbio = BIO_new_mem_buf( ecc_clikeypub_der_256,
  5525. sizeof_ecc_clikeypub_der_256));
  5526. ExpectNotNull(wolfSSL_d2i_PUBKEY_bio(rbio, &pkey));
  5527. ExpectNotNull(wbio = BIO_new(BIO_s_mem()));
  5528. ExpectIntEQ(EVP_PKEY_print_public(wbio, pkey,0,NULL),1);
  5529. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5530. strcpy(line1, "Public-Key: (256 bit)\n");
  5531. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5532. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5533. strcpy(line1, "pub:\n");
  5534. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5535. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5536. strcpy(line1,
  5537. " 04:55:BF:F4:0F:44:50:9A:3D:CE:9B:B7:F0:C5:4D:\n");
  5538. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5539. /* skip to the end of pub element*/
  5540. for (i = 0; i < 4 ;i++) {
  5541. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5542. }
  5543. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5544. strcpy(line1, "ASN1 OID: prime256v1\n");
  5545. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5546. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5547. strcpy(line1, "NIST CURVE: P-256\n");
  5548. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5549. /* should reach EOF */
  5550. ExpectIntLE(BIO_gets(wbio, line, sizeof(line)), 0);
  5551. EVP_PKEY_free(pkey);
  5552. pkey = NULL;
  5553. BIO_free(rbio);
  5554. BIO_free(wbio);
  5555. rbio = NULL;
  5556. wbio = NULL;
  5557. #endif /* HAVE_ECC && USE_CERT_BUFFERS_256 */
  5558. /*
  5559. * test DH public key print
  5560. */
  5561. #if defined(WOLFSSL_DH_EXTRA) && defined(USE_CERT_BUFFERS_2048)
  5562. ExpectNotNull(rbio = BIO_new_mem_buf( dh_pub_key_der_2048,
  5563. sizeof_dh_pub_key_der_2048));
  5564. ExpectNotNull(wolfSSL_d2i_PUBKEY_bio(rbio, &pkey));
  5565. ExpectNotNull(wbio = BIO_new(BIO_s_mem()));
  5566. ExpectIntEQ(EVP_PKEY_print_public(wbio, pkey,0,NULL), 1);
  5567. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5568. strcpy(line1, "DH Public-Key: (2048 bit)\n");
  5569. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5570. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5571. strcpy(line1, "public-key:\n");
  5572. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5573. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5574. strcpy(line1,
  5575. " 34:41:BF:E9:F2:11:BF:05:DB:B2:72:A8:29:CC:BD:\n");
  5576. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5577. /* skip to the end of public-key element*/
  5578. for (i = 0; i < 17 ;i++) {
  5579. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5580. }
  5581. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5582. strcpy(line1, "prime:\n");
  5583. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5584. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5585. strcpy(line1,
  5586. " 00:D3:B2:99:84:5C:0A:4C:E7:37:CC:FC:18:37:01:\n");
  5587. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5588. /* skip to the end of prime element*/
  5589. for (i = 0; i < 17 ;i++) {
  5590. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5591. }
  5592. ExpectIntGT(BIO_gets(wbio, line, sizeof(line)), 0);
  5593. strcpy(line1, "generator: 2 (0x02)\n");
  5594. ExpectIntEQ(XSTRNCMP( line, line1, XSTRLEN(line1)), 0);
  5595. /* should reach EOF */
  5596. ExpectIntLE(BIO_gets(wbio, line, sizeof(line)), 0);
  5597. EVP_PKEY_free(pkey);
  5598. pkey = NULL;
  5599. BIO_free(rbio);
  5600. BIO_free(wbio);
  5601. rbio = NULL;
  5602. wbio = NULL;
  5603. #endif /* WOLFSSL_DH_EXTRA && USE_CERT_BUFFERS_2048 */
  5604. /* to prevent "unused variable" warning */
  5605. (void)pkey;
  5606. (void)wbio;
  5607. (void)rbio;
  5608. (void)line;
  5609. (void)line1;
  5610. (void)i;
  5611. #endif /* OPENSSL_EXTRA */
  5612. return EXPECT_RESULT();
  5613. }
  5614. /* Test functions for base64 encode/decode */
  5615. static int test_wolfSSL_EVP_ENCODE_CTX_new(void)
  5616. {
  5617. EXPECT_DECLS;
  5618. #if defined(OPENSSL_EXTRA) && \
  5619. ( defined(WOLFSSL_BASE64_ENCODE) || defined(WOLFSSL_BASE64_DECODE))
  5620. EVP_ENCODE_CTX* ctx = NULL;
  5621. ExpectNotNull(ctx = EVP_ENCODE_CTX_new());
  5622. ExpectIntEQ(ctx->remaining,0);
  5623. ExpectIntEQ(ctx->data[0],0);
  5624. ExpectIntEQ(ctx->data[sizeof(ctx->data) -1],0);
  5625. EVP_ENCODE_CTX_free(ctx);
  5626. #endif /* OPENSSL_EXTRA && (WOLFSSL_BASE64_ENCODE || WOLFSSL_BASE64_DECODE) */
  5627. return EXPECT_RESULT();
  5628. }
  5629. static int test_wolfSSL_EVP_ENCODE_CTX_free(void)
  5630. {
  5631. EXPECT_DECLS;
  5632. #if defined(OPENSSL_EXTRA) && \
  5633. ( defined(WOLFSSL_BASE64_ENCODE) || defined(WOLFSSL_BASE64_DECODE))
  5634. EVP_ENCODE_CTX* ctx = NULL;
  5635. ExpectNotNull(ctx = EVP_ENCODE_CTX_new());
  5636. EVP_ENCODE_CTX_free(ctx);
  5637. #endif /* OPENSSL_EXTRA && (WOLFSSL_BASE64_ENCODE || WOLFSSL_BASE64_DECODE) */
  5638. return EXPECT_RESULT();
  5639. }
  5640. static int test_wolfSSL_EVP_EncodeInit(void)
  5641. {
  5642. EXPECT_DECLS;
  5643. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_ENCODE)
  5644. EVP_ENCODE_CTX* ctx = NULL;
  5645. ExpectNotNull(ctx = EVP_ENCODE_CTX_new());
  5646. ExpectIntEQ(ctx->remaining, 0);
  5647. ExpectIntEQ(ctx->data[0], 0);
  5648. ExpectIntEQ(ctx->data[sizeof(ctx->data) -1], 0);
  5649. if (ctx != NULL) {
  5650. /* make ctx dirty */
  5651. ctx->remaining = 10;
  5652. XMEMSET(ctx->data, 0x77, sizeof(ctx->data));
  5653. }
  5654. EVP_EncodeInit(ctx);
  5655. ExpectIntEQ(ctx->remaining, 0);
  5656. ExpectIntEQ(ctx->data[0], 0);
  5657. ExpectIntEQ(ctx->data[sizeof(ctx->data) -1], 0);
  5658. EVP_ENCODE_CTX_free(ctx);
  5659. #endif /* OPENSSL_EXTRA && WOLFSSL_BASE64_ENCODE*/
  5660. return EXPECT_RESULT();
  5661. }
  5662. static int test_wolfSSL_EVP_EncodeUpdate(void)
  5663. {
  5664. EXPECT_DECLS;
  5665. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_ENCODE)
  5666. int outl;
  5667. int total;
  5668. const unsigned char plain0[] = {"Th"};
  5669. const unsigned char plain1[] = {"This is a base64 encodeing test."};
  5670. const unsigned char plain2[] = {"This is additional data."};
  5671. const unsigned char encBlock0[] = {"VGg="};
  5672. const unsigned char enc0[] = {"VGg=\n"};
  5673. /* expected encoded result for the first output 64 chars plus trailing LF*/
  5674. const unsigned char enc1[] = {"VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVpbmcgdGVzdC5UaGlzIGlzIGFkZGl0aW9u\n"};
  5675. const unsigned char enc2[] =
  5676. {"VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVpbmcgdGVzdC5UaGlzIGlzIGFkZGl0aW9u\nYWwgZGF0YS4=\n"};
  5677. unsigned char encOutBuff[300];
  5678. EVP_ENCODE_CTX* ctx = NULL;
  5679. ExpectNotNull(ctx = EVP_ENCODE_CTX_new());
  5680. EVP_EncodeInit(ctx);
  5681. /* illegal parameter test */
  5682. ExpectIntEQ(
  5683. EVP_EncodeUpdate(
  5684. NULL, /* pass NULL as ctx */
  5685. encOutBuff,
  5686. &outl,
  5687. plain1,
  5688. sizeof(plain1)-1),
  5689. 0 /* expected result code 0: fail */
  5690. );
  5691. ExpectIntEQ(
  5692. EVP_EncodeUpdate(
  5693. ctx,
  5694. NULL, /* pass NULL as out buff */
  5695. &outl,
  5696. plain1,
  5697. sizeof(plain1)-1),
  5698. 0 /* expected result code 0: fail */
  5699. );
  5700. ExpectIntEQ(
  5701. EVP_EncodeUpdate(
  5702. ctx,
  5703. encOutBuff,
  5704. NULL, /* pass NULL as outl */
  5705. plain1,
  5706. sizeof(plain1)-1),
  5707. 0 /* expected result code 0: fail */
  5708. );
  5709. ExpectIntEQ(
  5710. EVP_EncodeUpdate(
  5711. ctx,
  5712. encOutBuff,
  5713. &outl,
  5714. NULL, /* pass NULL as in */
  5715. sizeof(plain1)-1),
  5716. 0 /* expected result code 0: fail */
  5717. );
  5718. ExpectIntEQ(EVP_EncodeBlock(NULL, NULL, 0), -1);
  5719. /* meaningless parameter test */
  5720. ExpectIntEQ(
  5721. EVP_EncodeUpdate(
  5722. ctx,
  5723. encOutBuff,
  5724. &outl,
  5725. plain1,
  5726. 0), /* pass zero input */
  5727. 1 /* expected result code 1: success */
  5728. );
  5729. /* very small data encoding test */
  5730. EVP_EncodeInit(ctx);
  5731. ExpectIntEQ(
  5732. EVP_EncodeUpdate(
  5733. ctx,
  5734. encOutBuff,
  5735. &outl,
  5736. plain0,
  5737. sizeof(plain0)-1),
  5738. 1 /* expected result code 1: success */
  5739. );
  5740. ExpectIntEQ(outl,0);
  5741. if (EXPECT_SUCCESS()) {
  5742. EVP_EncodeFinal(
  5743. ctx,
  5744. encOutBuff + outl,
  5745. &outl);
  5746. }
  5747. ExpectIntEQ( outl, sizeof(enc0)-1);
  5748. ExpectIntEQ(
  5749. XSTRNCMP(
  5750. (const char*)encOutBuff,
  5751. (const char*)enc0,sizeof(enc0) ),
  5752. 0);
  5753. XMEMSET( encOutBuff,0, sizeof(encOutBuff));
  5754. ExpectIntEQ(EVP_EncodeBlock(encOutBuff, plain0, sizeof(plain0)-1),
  5755. sizeof(encBlock0)-1);
  5756. ExpectStrEQ(encOutBuff, encBlock0);
  5757. /* pass small size( < 48bytes ) input, then make sure they are not
  5758. * encoded and just stored in ctx
  5759. */
  5760. EVP_EncodeInit(ctx);
  5761. total = 0;
  5762. outl = 0;
  5763. XMEMSET( encOutBuff,0, sizeof(encOutBuff));
  5764. ExpectIntEQ(
  5765. EVP_EncodeUpdate(
  5766. ctx,
  5767. encOutBuff, /* buffer for output */
  5768. &outl, /* size of output */
  5769. plain1, /* input */
  5770. sizeof(plain1)-1), /* size of input */
  5771. 1); /* expected result code 1:success */
  5772. total += outl;
  5773. ExpectIntEQ(outl, 0); /* no output expected */
  5774. ExpectIntEQ(ctx->remaining, sizeof(plain1) -1);
  5775. ExpectTrue(
  5776. XSTRNCMP((const char*)(ctx->data),
  5777. (const char*)plain1,
  5778. ctx->remaining) ==0 );
  5779. ExpectTrue(encOutBuff[0] == 0);
  5780. /* call wolfSSL_EVP_EncodeUpdate again to make it encode
  5781. * the stored data and the new input together
  5782. */
  5783. ExpectIntEQ(
  5784. EVP_EncodeUpdate(
  5785. ctx,
  5786. encOutBuff + outl, /* buffer for output */
  5787. &outl, /* size of output */
  5788. plain2, /* additional input */
  5789. sizeof(plain2) -1), /* size of additional input */
  5790. 1); /* expected result code 1:success */
  5791. total += outl;
  5792. ExpectIntNE(outl, 0); /* some output is expected this time*/
  5793. ExpectIntEQ(outl, BASE64_ENCODE_RESULT_BLOCK_SIZE +1); /* 64 bytes and LF */
  5794. ExpectIntEQ(
  5795. XSTRNCMP((const char*)encOutBuff,(const char*)enc1,sizeof(enc1) ),0);
  5796. /* call wolfSSL_EVP_EncodeFinal to flush all the unprocessed input */
  5797. EVP_EncodeFinal(
  5798. ctx,
  5799. encOutBuff + outl,
  5800. &outl);
  5801. total += outl;
  5802. ExpectIntNE(total,0);
  5803. ExpectIntNE(outl,0);
  5804. ExpectIntEQ(XSTRNCMP(
  5805. (const char*)encOutBuff,(const char*)enc2,sizeof(enc2) ),0);
  5806. /* test with illeagal parameters */
  5807. outl = 1;
  5808. EVP_EncodeFinal(NULL, encOutBuff + outl, &outl);
  5809. ExpectIntEQ(outl, 0);
  5810. outl = 1;
  5811. EVP_EncodeFinal(ctx, NULL, &outl);
  5812. ExpectIntEQ(outl, 0);
  5813. EVP_EncodeFinal(ctx, encOutBuff + outl, NULL);
  5814. EVP_EncodeFinal(NULL, NULL, NULL);
  5815. EVP_ENCODE_CTX_free(ctx);
  5816. #endif /* OPENSSL_EXTRA && WOLFSSL_BASE64_ENCODE*/
  5817. return EXPECT_RESULT();
  5818. }
  5819. static int test_wolfSSL_EVP_EncodeFinal(void)
  5820. {
  5821. int res = TEST_SKIPPED;
  5822. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_ENCODE)
  5823. /* tests for wolfSSL_EVP_EncodeFinal are included in
  5824. * test_wolfSSL_EVP_EncodeUpdate
  5825. */
  5826. res = TEST_SUCCESS;
  5827. #endif /* OPENSSL_EXTRA && WOLFSSL_BASE64_ENCODE*/
  5828. return res;
  5829. }
  5830. static int test_wolfSSL_EVP_DecodeInit(void)
  5831. {
  5832. EXPECT_DECLS;
  5833. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_DECODE)
  5834. EVP_ENCODE_CTX* ctx = NULL;
  5835. ExpectNotNull( ctx = EVP_ENCODE_CTX_new());
  5836. ExpectIntEQ( ctx->remaining,0);
  5837. ExpectIntEQ( ctx->data[0],0);
  5838. ExpectIntEQ( ctx->data[sizeof(ctx->data) -1],0);
  5839. if (ctx != NULL) {
  5840. /* make ctx dirty */
  5841. ctx->remaining = 10;
  5842. XMEMSET( ctx->data, 0x77, sizeof(ctx->data));
  5843. }
  5844. EVP_DecodeInit(ctx);
  5845. ExpectIntEQ( ctx->remaining,0);
  5846. ExpectIntEQ( ctx->data[0],0);
  5847. ExpectIntEQ( ctx->data[sizeof(ctx->data) -1],0);
  5848. EVP_ENCODE_CTX_free(ctx);
  5849. #endif /* OPENSSL && WOLFSSL_BASE_DECODE */
  5850. return EXPECT_RESULT();
  5851. }
  5852. static int test_wolfSSL_EVP_DecodeUpdate(void)
  5853. {
  5854. EXPECT_DECLS;
  5855. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_DECODE)
  5856. int outl;
  5857. unsigned char decOutBuff[300];
  5858. EVP_ENCODE_CTX* ctx = NULL;
  5859. static const unsigned char enc1[] =
  5860. {"VGhpcyBpcyBhIGJhc2U2NCBkZWNvZGluZyB0ZXN0Lg==\n"};
  5861. /* const unsigned char plain1[] =
  5862. {"This is a base64 decoding test."} */
  5863. ExpectNotNull(ctx = EVP_ENCODE_CTX_new());
  5864. EVP_DecodeInit(ctx);
  5865. /* illegal parameter tests */
  5866. /* pass NULL as ctx */
  5867. ExpectIntEQ(
  5868. EVP_DecodeUpdate(
  5869. NULL, /* pass NULL as ctx */
  5870. decOutBuff,
  5871. &outl,
  5872. enc1,
  5873. sizeof(enc1)-1),
  5874. -1 /* expected result code -1: fail */
  5875. );
  5876. ExpectIntEQ( outl, 0);
  5877. /* pass NULL as output */
  5878. ExpectIntEQ(
  5879. EVP_DecodeUpdate(
  5880. ctx,
  5881. NULL, /* pass NULL as out buff */
  5882. &outl,
  5883. enc1,
  5884. sizeof(enc1)-1),
  5885. -1 /* expected result code -1: fail */
  5886. );
  5887. ExpectIntEQ( outl, 0);
  5888. /* pass NULL as outl */
  5889. ExpectIntEQ(
  5890. EVP_DecodeUpdate(
  5891. ctx,
  5892. decOutBuff,
  5893. NULL, /* pass NULL as outl */
  5894. enc1,
  5895. sizeof(enc1)-1),
  5896. -1 /* expected result code -1: fail */
  5897. );
  5898. /* pass NULL as input */
  5899. ExpectIntEQ(
  5900. EVP_DecodeUpdate(
  5901. ctx,
  5902. decOutBuff,
  5903. &outl,
  5904. NULL, /* pass NULL as in */
  5905. sizeof(enc1)-1),
  5906. -1 /* expected result code -1: fail */
  5907. );
  5908. ExpectIntEQ( outl, 0);
  5909. ExpectIntEQ(EVP_DecodeBlock(NULL, NULL, 0), -1);
  5910. /* pass zero length input */
  5911. ExpectIntEQ(
  5912. EVP_DecodeUpdate(
  5913. ctx,
  5914. decOutBuff,
  5915. &outl,
  5916. enc1,
  5917. 0), /* pass zero as input len */
  5918. 1 /* expected result code 1: success */
  5919. );
  5920. /* decode correct base64 string */
  5921. {
  5922. static const unsigned char enc2[] =
  5923. {"VGhpcyBpcyBhIGJhc2U2NCBkZWNvZGluZyB0ZXN0Lg==\n"};
  5924. static const unsigned char plain2[] =
  5925. {"This is a base64 decoding test."};
  5926. EVP_EncodeInit(ctx);
  5927. ExpectIntEQ(
  5928. EVP_DecodeUpdate(
  5929. ctx,
  5930. decOutBuff,
  5931. &outl,
  5932. enc2,
  5933. sizeof(enc2)-1),
  5934. 0 /* expected result code 0: success */
  5935. );
  5936. ExpectIntEQ(outl,sizeof(plain2) -1);
  5937. ExpectIntEQ(
  5938. EVP_DecodeFinal(
  5939. ctx,
  5940. decOutBuff + outl,
  5941. &outl),
  5942. 1 /* expected result code 1: success */
  5943. );
  5944. ExpectIntEQ(outl, 0); /* expected DecodeFinal output no data */
  5945. ExpectIntEQ(XSTRNCMP( (const char*)plain2,(const char*)decOutBuff,
  5946. sizeof(plain2) -1 ),0);
  5947. ExpectIntEQ(EVP_DecodeBlock(decOutBuff, enc2, sizeof(enc2)),
  5948. sizeof(plain2)-1);
  5949. ExpectIntEQ(XSTRNCMP( (const char*)plain2,(const char*)decOutBuff,
  5950. sizeof(plain2) -1 ),0);
  5951. }
  5952. /* decode correct base64 string which does not have '\n' in its last*/
  5953. {
  5954. static const unsigned char enc3[] =
  5955. {"VGhpcyBpcyBhIGJhc2U2NCBkZWNvZGluZyB0ZXN0Lg=="}; /* 44 chars */
  5956. static const unsigned char plain3[] =
  5957. {"This is a base64 decoding test."}; /* 31 chars */
  5958. EVP_EncodeInit(ctx);
  5959. ExpectIntEQ(
  5960. EVP_DecodeUpdate(
  5961. ctx,
  5962. decOutBuff,
  5963. &outl,
  5964. enc3,
  5965. sizeof(enc3)-1),
  5966. 0 /* expected result code 0: success */
  5967. );
  5968. ExpectIntEQ(outl,sizeof(plain3)-1); /* 31 chars should be output */
  5969. ExpectIntEQ(XSTRNCMP( (const char*)plain3,(const char*)decOutBuff,
  5970. sizeof(plain3) -1 ),0);
  5971. ExpectIntEQ(
  5972. EVP_DecodeFinal(
  5973. ctx,
  5974. decOutBuff + outl,
  5975. &outl),
  5976. 1 /* expected result code 1: success */
  5977. );
  5978. ExpectIntEQ(outl,0 );
  5979. ExpectIntEQ(EVP_DecodeBlock(decOutBuff, enc3, sizeof(enc3)-1),
  5980. sizeof(plain3)-1);
  5981. ExpectIntEQ(XSTRNCMP( (const char*)plain3,(const char*)decOutBuff,
  5982. sizeof(plain3) -1 ),0);
  5983. }
  5984. /* decode string which has a padding char ('=') in the illegal position*/
  5985. {
  5986. static const unsigned char enc4[] =
  5987. {"VGhpcyBpcyBhIGJhc2U2N=CBkZWNvZGluZyB0ZXN0Lg==\n"};
  5988. EVP_EncodeInit(ctx);
  5989. ExpectIntEQ(
  5990. EVP_DecodeUpdate(
  5991. ctx,
  5992. decOutBuff,
  5993. &outl,
  5994. enc4,
  5995. sizeof(enc4)-1),
  5996. -1 /* expected result code -1: error */
  5997. );
  5998. ExpectIntEQ(outl,0);
  5999. ExpectIntEQ(EVP_DecodeBlock(decOutBuff, enc4, sizeof(enc4)-1), -1);
  6000. }
  6001. /* small data decode test */
  6002. {
  6003. static const unsigned char enc00[] = {"VG"};
  6004. static const unsigned char enc01[] = {"g=\n"};
  6005. static const unsigned char plain4[] = {"Th"};
  6006. EVP_EncodeInit(ctx);
  6007. ExpectIntEQ(
  6008. EVP_DecodeUpdate(
  6009. ctx,
  6010. decOutBuff,
  6011. &outl,
  6012. enc00,
  6013. sizeof(enc00)-1),
  6014. 1 /* expected result code 1: success */
  6015. );
  6016. ExpectIntEQ(outl,0);
  6017. ExpectIntEQ(
  6018. EVP_DecodeUpdate(
  6019. ctx,
  6020. decOutBuff + outl,
  6021. &outl,
  6022. enc01,
  6023. sizeof(enc01)-1),
  6024. 0 /* expected result code 0: success */
  6025. );
  6026. ExpectIntEQ(outl,sizeof(plain4)-1);
  6027. /* test with illegal parameters */
  6028. ExpectIntEQ(EVP_DecodeFinal(NULL,decOutBuff + outl,&outl), -1);
  6029. ExpectIntEQ(EVP_DecodeFinal(ctx,NULL,&outl), -1);
  6030. ExpectIntEQ(EVP_DecodeFinal(ctx,decOutBuff + outl, NULL), -1);
  6031. ExpectIntEQ(EVP_DecodeFinal(NULL,NULL, NULL), -1);
  6032. if (EXPECT_SUCCESS()) {
  6033. EVP_DecodeFinal(
  6034. ctx,
  6035. decOutBuff + outl,
  6036. &outl);
  6037. }
  6038. ExpectIntEQ( outl, 0);
  6039. ExpectIntEQ(
  6040. XSTRNCMP(
  6041. (const char*)decOutBuff,
  6042. (const char*)plain4,sizeof(plain4)-1 ),
  6043. 0);
  6044. }
  6045. EVP_ENCODE_CTX_free(ctx);
  6046. #endif /* OPENSSL && WOLFSSL_BASE_DECODE */
  6047. return EXPECT_RESULT();
  6048. }
  6049. static int test_wolfSSL_EVP_DecodeFinal(void)
  6050. {
  6051. int res = TEST_SKIPPED;
  6052. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_DECODE)
  6053. /* tests for wolfSSL_EVP_DecodeFinal are included in
  6054. * test_wolfSSL_EVP_DecodeUpdate
  6055. */
  6056. res = TEST_SUCCESS;
  6057. #endif /* OPENSSL && WOLFSSL_BASE_DECODE */
  6058. return res;
  6059. }
  6060. /* Test function for wolfSSL_EVP_get_cipherbynid.
  6061. */
  6062. #ifdef OPENSSL_EXTRA
  6063. static int test_wolfSSL_EVP_get_cipherbynid(void)
  6064. {
  6065. EXPECT_DECLS;
  6066. #ifndef NO_AES
  6067. const WOLFSSL_EVP_CIPHER* c;
  6068. c = wolfSSL_EVP_get_cipherbynid(419);
  6069. #if (defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT)) && \
  6070. defined(WOLFSSL_AES_128)
  6071. ExpectNotNull(c);
  6072. ExpectNotNull(XSTRCMP("EVP_AES_128_CBC", c));
  6073. #else
  6074. ExpectNull(c);
  6075. #endif
  6076. c = wolfSSL_EVP_get_cipherbynid(423);
  6077. #if (defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT)) && \
  6078. defined(WOLFSSL_AES_192)
  6079. ExpectNotNull(c);
  6080. ExpectNotNull(XSTRCMP("EVP_AES_192_CBC", c));
  6081. #else
  6082. ExpectNull(c);
  6083. #endif
  6084. c = wolfSSL_EVP_get_cipherbynid(427);
  6085. #if (defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT)) && \
  6086. defined(WOLFSSL_AES_256)
  6087. ExpectNotNull(c);
  6088. ExpectNotNull(XSTRCMP("EVP_AES_256_CBC", c));
  6089. #else
  6090. ExpectNull(c);
  6091. #endif
  6092. c = wolfSSL_EVP_get_cipherbynid(904);
  6093. #if defined(WOLFSSL_AES_COUNTER) && defined(WOLFSSL_AES_128)
  6094. ExpectNotNull(c);
  6095. ExpectNotNull(XSTRCMP("EVP_AES_128_CTR", c));
  6096. #else
  6097. ExpectNull(c);
  6098. #endif
  6099. c = wolfSSL_EVP_get_cipherbynid(905);
  6100. #if defined(WOLFSSL_AES_COUNTER) && defined(WOLFSSL_AES_192)
  6101. ExpectNotNull(c);
  6102. ExpectNotNull(XSTRCMP("EVP_AES_192_CTR", c));
  6103. #else
  6104. ExpectNull(c);
  6105. #endif
  6106. c = wolfSSL_EVP_get_cipherbynid(906);
  6107. #if defined(WOLFSSL_AES_COUNTER) && defined(WOLFSSL_AES_256)
  6108. ExpectNotNull(c);
  6109. ExpectNotNull(XSTRCMP("EVP_AES_256_CTR", c));
  6110. #else
  6111. ExpectNull(c);
  6112. #endif
  6113. c = wolfSSL_EVP_get_cipherbynid(418);
  6114. #if defined(HAVE_AES_ECB) && defined(WOLFSSL_AES_128)
  6115. ExpectNotNull(c);
  6116. ExpectNotNull(XSTRCMP("EVP_AES_128_ECB", c));
  6117. #else
  6118. ExpectNull(c);
  6119. #endif
  6120. c = wolfSSL_EVP_get_cipherbynid(422);
  6121. #if defined(HAVE_AES_ECB) && defined(WOLFSSL_AES_192)
  6122. ExpectNotNull(c);
  6123. ExpectNotNull(XSTRCMP("EVP_AES_192_ECB", c));
  6124. #else
  6125. ExpectNull(c);
  6126. #endif
  6127. c = wolfSSL_EVP_get_cipherbynid(426);
  6128. #if defined(HAVE_AES_ECB) && defined(WOLFSSL_AES_256)
  6129. ExpectNotNull(c);
  6130. ExpectNotNull(XSTRCMP("EVP_AES_256_ECB", c));
  6131. #else
  6132. ExpectNull(c);
  6133. #endif
  6134. #endif /* !NO_AES */
  6135. #ifndef NO_DES3
  6136. ExpectNotNull(XSTRCMP("EVP_DES_CBC", wolfSSL_EVP_get_cipherbynid(31)));
  6137. #ifdef WOLFSSL_DES_ECB
  6138. ExpectNotNull(XSTRCMP("EVP_DES_ECB", wolfSSL_EVP_get_cipherbynid(29)));
  6139. #endif
  6140. ExpectNotNull(XSTRCMP("EVP_DES_EDE3_CBC", wolfSSL_EVP_get_cipherbynid(44)));
  6141. #ifdef WOLFSSL_DES_ECB
  6142. ExpectNotNull(XSTRCMP("EVP_DES_EDE3_ECB", wolfSSL_EVP_get_cipherbynid(33)));
  6143. #endif
  6144. #endif /* !NO_DES3 */
  6145. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  6146. ExpectNotNull(XSTRCMP("EVP_CHACHA20_POLY13O5", EVP_get_cipherbynid(1018)));
  6147. #endif
  6148. /* test for nid is out of range */
  6149. ExpectNull(wolfSSL_EVP_get_cipherbynid(1));
  6150. return EXPECT_RESULT();
  6151. }
  6152. static int test_wolfSSL_EVP_CIPHER_CTX(void)
  6153. {
  6154. EXPECT_DECLS;
  6155. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  6156. EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
  6157. const EVP_CIPHER *init = EVP_aes_128_cbc();
  6158. const EVP_CIPHER *test;
  6159. byte key[AES_BLOCK_SIZE] = {0};
  6160. byte iv[AES_BLOCK_SIZE] = {0};
  6161. ExpectNotNull(ctx);
  6162. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  6163. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  6164. test = EVP_CIPHER_CTX_cipher(ctx);
  6165. ExpectTrue(init == test);
  6166. ExpectIntEQ(EVP_CIPHER_nid(test), NID_aes_128_cbc);
  6167. ExpectIntEQ(EVP_CIPHER_CTX_reset(ctx), WOLFSSL_SUCCESS);
  6168. ExpectIntEQ(EVP_CIPHER_CTX_reset(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  6169. EVP_CIPHER_CTX_free(ctx);
  6170. /* test EVP_CIPHER_CTX_cleanup with NULL */
  6171. ExpectIntEQ(EVP_CIPHER_CTX_cleanup(NULL), WOLFSSL_SUCCESS);
  6172. #endif /* !NO_AES && HAVE_AES_CBC && WOLFSSL_AES_128 */
  6173. return EXPECT_RESULT();
  6174. }
  6175. #endif /* OPENSSL_EXTRA */
  6176. /*----------------------------------------------------------------------------*
  6177. | IO
  6178. *----------------------------------------------------------------------------*/
  6179. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) || \
  6180. defined(HAVE_IO_TESTS_DEPENDENCIES)
  6181. #ifdef WOLFSSL_HAVE_TLS_UNIQUE
  6182. #ifdef WC_SHA512_DIGEST_SIZE
  6183. #define MD_MAX_SIZE WC_SHA512_DIGEST_SIZE
  6184. #else
  6185. #define MD_MAX_SIZE WC_SHA256_DIGEST_SIZE
  6186. #endif
  6187. byte server_side_msg1[MD_MAX_SIZE] = {0};/* msg sent by server */
  6188. byte server_side_msg2[MD_MAX_SIZE] = {0};/* msg received from client */
  6189. byte client_side_msg1[MD_MAX_SIZE] = {0};/* msg sent by client */
  6190. byte client_side_msg2[MD_MAX_SIZE] = {0};/* msg received from server */
  6191. #endif /* WOLFSSL_HAVE_TLS_UNIQUE */
  6192. /* TODO: Expand and enable this when EVP_chacha20_poly1305 is supported */
  6193. #if defined(HAVE_SESSION_TICKET) && defined(OPENSSL_EXTRA) && \
  6194. defined(HAVE_AES_CBC)
  6195. typedef struct openssl_key_ctx {
  6196. byte name[WOLFSSL_TICKET_NAME_SZ]; /* server name */
  6197. byte key[WOLFSSL_TICKET_KEY_SZ]; /* cipher key */
  6198. byte hmacKey[WOLFSSL_TICKET_NAME_SZ]; /* hmac key */
  6199. byte iv[WOLFSSL_TICKET_IV_SZ]; /* cipher iv */
  6200. } openssl_key_ctx;
  6201. static THREAD_LS_T openssl_key_ctx myOpenSSLKey_ctx;
  6202. static THREAD_LS_T WC_RNG myOpenSSLKey_rng;
  6203. static WC_INLINE int OpenSSLTicketInit(void)
  6204. {
  6205. int ret = wc_InitRng(&myOpenSSLKey_rng);
  6206. if (ret != 0) return ret;
  6207. ret = wc_RNG_GenerateBlock(&myOpenSSLKey_rng, myOpenSSLKey_ctx.name,
  6208. sizeof(myOpenSSLKey_ctx.name));
  6209. if (ret != 0) return ret;
  6210. ret = wc_RNG_GenerateBlock(&myOpenSSLKey_rng, myOpenSSLKey_ctx.key,
  6211. sizeof(myOpenSSLKey_ctx.key));
  6212. if (ret != 0) return ret;
  6213. ret = wc_RNG_GenerateBlock(&myOpenSSLKey_rng, myOpenSSLKey_ctx.hmacKey,
  6214. sizeof(myOpenSSLKey_ctx.hmacKey));
  6215. if (ret != 0) return ret;
  6216. ret = wc_RNG_GenerateBlock(&myOpenSSLKey_rng, myOpenSSLKey_ctx.iv,
  6217. sizeof(myOpenSSLKey_ctx.iv));
  6218. if (ret != 0) return ret;
  6219. return 0;
  6220. }
  6221. static int myTicketEncCbOpenSSL(WOLFSSL* ssl,
  6222. byte name[WOLFSSL_TICKET_NAME_SZ],
  6223. byte iv[WOLFSSL_TICKET_IV_SZ],
  6224. WOLFSSL_EVP_CIPHER_CTX *ectx,
  6225. WOLFSSL_HMAC_CTX *hctx, int enc) {
  6226. (void)ssl;
  6227. if (enc) {
  6228. XMEMCPY(name, myOpenSSLKey_ctx.name, sizeof(myOpenSSLKey_ctx.name));
  6229. XMEMCPY(iv, myOpenSSLKey_ctx.iv, sizeof(myOpenSSLKey_ctx.iv));
  6230. }
  6231. else if (XMEMCMP(name, myOpenSSLKey_ctx.name,
  6232. sizeof(myOpenSSLKey_ctx.name)) != 0 ||
  6233. XMEMCMP(iv, myOpenSSLKey_ctx.iv,
  6234. sizeof(myOpenSSLKey_ctx.iv)) != 0) {
  6235. return 0;
  6236. }
  6237. HMAC_Init_ex(hctx, myOpenSSLKey_ctx.hmacKey, WOLFSSL_TICKET_NAME_SZ, EVP_sha256(), NULL);
  6238. if (enc)
  6239. EVP_EncryptInit_ex(ectx, EVP_aes_256_cbc(), NULL, myOpenSSLKey_ctx.key, iv);
  6240. else
  6241. EVP_DecryptInit_ex(ectx, EVP_aes_256_cbc(), NULL, myOpenSSLKey_ctx.key, iv);
  6242. return 1;
  6243. }
  6244. static WC_INLINE void OpenSSLTicketCleanup(void)
  6245. {
  6246. wc_FreeRng(&myOpenSSLKey_rng);
  6247. }
  6248. #endif
  6249. #endif
  6250. /* helper functions */
  6251. #ifdef HAVE_SSL_MEMIO_TESTS_DEPENDENCIES
  6252. static WC_INLINE int test_ssl_memio_write_cb(WOLFSSL *ssl, char *data, int sz,
  6253. void *ctx)
  6254. {
  6255. struct test_ssl_memio_ctx *test_ctx;
  6256. byte *buf;
  6257. int *len;
  6258. test_ctx = (struct test_ssl_memio_ctx*)ctx;
  6259. if (wolfSSL_GetSide(ssl) == WOLFSSL_SERVER_END) {
  6260. buf = test_ctx->c_buff;
  6261. len = &test_ctx->c_len;
  6262. }
  6263. else {
  6264. buf = test_ctx->s_buff;
  6265. len = &test_ctx->s_len;
  6266. }
  6267. if ((unsigned)(*len + sz) > TEST_SSL_MEMIO_BUF_SZ)
  6268. return WOLFSSL_CBIO_ERR_WANT_WRITE;
  6269. XMEMCPY(buf + *len, data, sz);
  6270. *len += sz;
  6271. #ifdef WOLFSSL_DUMP_MEMIO_STREAM
  6272. {
  6273. /* This can be imported into Wireshark by transforming the file with
  6274. * od -Ax -tx1 -v test_output.dump > test_output.dump.hex
  6275. * And then loading test_output.dump.hex into Wireshark using the
  6276. * "Import from Hex Dump..." option ion and selecting the TCP
  6277. * encapsulation option. */
  6278. char dump_file_name[64];
  6279. WOLFSSL_BIO *dump_file;
  6280. sprintf(dump_file_name, "%s/%s.dump", tmpDirName, currentTestName);
  6281. dump_file = wolfSSL_BIO_new_file(dump_file_name, "a");
  6282. if (dump_file != NULL) {
  6283. (void)wolfSSL_BIO_write(dump_file, data, sz);
  6284. wolfSSL_BIO_free(dump_file);
  6285. }
  6286. }
  6287. #endif
  6288. return sz;
  6289. }
  6290. static WC_INLINE int test_ssl_memio_read_cb(WOLFSSL *ssl, char *data, int sz,
  6291. void *ctx)
  6292. {
  6293. struct test_ssl_memio_ctx *test_ctx;
  6294. int read_sz;
  6295. byte *buf;
  6296. int *len;
  6297. test_ctx = (struct test_ssl_memio_ctx*)ctx;
  6298. if (wolfSSL_GetSide(ssl) == WOLFSSL_SERVER_END) {
  6299. buf = test_ctx->s_buff;
  6300. len = &test_ctx->s_len;
  6301. }
  6302. else {
  6303. buf = test_ctx->c_buff;
  6304. len = &test_ctx->c_len;
  6305. }
  6306. if (*len == 0)
  6307. return WOLFSSL_CBIO_ERR_WANT_READ;
  6308. read_sz = sz < *len ? sz : *len;
  6309. XMEMCPY(data, buf, read_sz);
  6310. XMEMMOVE(buf, buf + read_sz, *len - read_sz);
  6311. *len -= read_sz;
  6312. return read_sz;
  6313. }
  6314. static WC_INLINE int test_ssl_memio_setup(test_ssl_memio_ctx *ctx)
  6315. {
  6316. EXPECT_DECLS_NO_MSGS(-2000);
  6317. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6318. int c_sharedCtx = 0;
  6319. int s_sharedCtx = 0;
  6320. #endif
  6321. const char* clientCertFile = cliCertFile;
  6322. const char* clientKeyFile = cliKeyFile;
  6323. const char* serverCertFile = svrCertFile;
  6324. const char* serverKeyFile = svrKeyFile;
  6325. /********************************
  6326. * Create WOLFSSL_CTX for client.
  6327. ********************************/
  6328. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6329. if (ctx->c_ctx != NULL) {
  6330. c_sharedCtx = ctx->c_cb.isSharedCtx;
  6331. }
  6332. else
  6333. #endif
  6334. {
  6335. WOLFSSL_METHOD* method = NULL;
  6336. if (ctx->c_cb.method != NULL) {
  6337. method = ctx->c_cb.method();
  6338. }
  6339. else {
  6340. method = wolfSSLv23_client_method();
  6341. }
  6342. ExpectNotNull(ctx->c_ctx = wolfSSL_CTX_new(method));
  6343. }
  6344. wolfSSL_SetIORecv(ctx->c_ctx, test_ssl_memio_read_cb);
  6345. wolfSSL_SetIOSend(ctx->c_ctx, test_ssl_memio_write_cb);
  6346. #ifdef WOLFSSL_ENCRYPTED_KEYS
  6347. wolfSSL_CTX_set_default_passwd_cb(ctx->c_ctx, PasswordCallBack);
  6348. #endif
  6349. if (ctx->c_cb.caPemFile != NULL)
  6350. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx->c_ctx,
  6351. ctx->c_cb.caPemFile, 0), WOLFSSL_SUCCESS);
  6352. else
  6353. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx->c_ctx,
  6354. caCertFile, 0), WOLFSSL_SUCCESS);
  6355. if (ctx->c_cb.certPemFile != NULL) {
  6356. clientCertFile = ctx->c_cb.certPemFile;
  6357. }
  6358. if (ctx->c_cb.keyPemFile != NULL) {
  6359. clientKeyFile = ctx->c_cb.keyPemFile;
  6360. }
  6361. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6362. if (!c_sharedCtx)
  6363. #endif
  6364. {
  6365. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file(ctx->c_ctx,
  6366. clientCertFile), WOLFSSL_SUCCESS);
  6367. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx->c_ctx, clientKeyFile,
  6368. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  6369. }
  6370. #ifdef HAVE_CRL
  6371. if (ctx->c_cb.crlPemFile != NULL) {
  6372. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx->c_ctx, WOLFSSL_CRL_CHECKALL),
  6373. WOLFSSL_SUCCESS);
  6374. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx->c_ctx, ctx->c_cb.crlPemFile,
  6375. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  6376. }
  6377. #endif
  6378. if (ctx->c_ciphers != NULL) {
  6379. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx->c_ctx, ctx->c_ciphers),
  6380. WOLFSSL_SUCCESS);
  6381. }
  6382. if (ctx->c_cb.ctx_ready != NULL) {
  6383. ExpectIntEQ(ctx->c_cb.ctx_ready(ctx->c_ctx), TEST_SUCCESS);
  6384. }
  6385. /********************************
  6386. * Create WOLFSSL_CTX for server.
  6387. ********************************/
  6388. if (ctx->s_ctx != NULL) {
  6389. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6390. s_sharedCtx = 1;
  6391. #endif
  6392. ctx->s_cb.isSharedCtx = 1;
  6393. }
  6394. else
  6395. {
  6396. WOLFSSL_METHOD* method = NULL;
  6397. if (ctx->s_cb.method != NULL) {
  6398. method = ctx->s_cb.method();
  6399. }
  6400. else {
  6401. method = wolfSSLv23_server_method();
  6402. }
  6403. ExpectNotNull(ctx->s_ctx = wolfSSL_CTX_new(method));
  6404. ctx->s_cb.isSharedCtx = 0;
  6405. }
  6406. if (!ctx->s_cb.ticNoInit && (ctx->s_ctx != NULL)) {
  6407. #if defined(HAVE_SESSION_TICKET) && \
  6408. ((defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))
  6409. #if defined(OPENSSL_EXTRA) && defined(HAVE_AES_CBC)
  6410. OpenSSLTicketInit();
  6411. wolfSSL_CTX_set_tlsext_ticket_key_cb(ctx->s_ctx, myTicketEncCbOpenSSL);
  6412. #elif defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  6413. TicketInit();
  6414. wolfSSL_CTX_set_TicketEncCb(ctx->s_ctx, myTicketEncCb);
  6415. #endif
  6416. #endif
  6417. }
  6418. wolfSSL_SetIORecv(ctx->s_ctx, test_ssl_memio_read_cb);
  6419. wolfSSL_SetIOSend(ctx->s_ctx, test_ssl_memio_write_cb);
  6420. wolfSSL_CTX_set_verify(ctx->s_ctx, WOLFSSL_VERIFY_PEER |
  6421. WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  6422. if (ctx->s_cb.caPemFile != NULL)
  6423. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx->s_ctx,
  6424. ctx->s_cb.caPemFile, 0), WOLFSSL_SUCCESS);
  6425. else
  6426. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx->s_ctx,
  6427. cliCertFile, 0), WOLFSSL_SUCCESS);
  6428. #ifdef WOLFSSL_ENCRYPTED_KEYS
  6429. wolfSSL_CTX_set_default_passwd_cb(ctx->s_ctx, PasswordCallBack);
  6430. #endif
  6431. if (ctx->s_cb.certPemFile != NULL) {
  6432. serverCertFile = ctx->s_cb.certPemFile;
  6433. }
  6434. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6435. if (!s_sharedCtx)
  6436. #endif
  6437. {
  6438. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file(ctx->s_ctx,
  6439. serverCertFile), WOLFSSL_SUCCESS);
  6440. }
  6441. if (ctx->s_cb.keyPemFile != NULL) {
  6442. serverKeyFile = ctx->s_cb.keyPemFile;
  6443. }
  6444. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6445. if (!s_sharedCtx)
  6446. #endif
  6447. {
  6448. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx->s_ctx, serverKeyFile,
  6449. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  6450. }
  6451. if (ctx->s_ciphers != NULL) {
  6452. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx->s_ctx, ctx->s_ciphers),
  6453. WOLFSSL_SUCCESS);
  6454. }
  6455. if (ctx->s_cb.ctx_ready != NULL) {
  6456. ExpectIntEQ(ctx->s_cb.ctx_ready(ctx->s_ctx), TEST_SUCCESS);
  6457. }
  6458. /****************************
  6459. * Create WOLFSSL for client.
  6460. ****************************/
  6461. ExpectNotNull(ctx->c_ssl = wolfSSL_new(ctx->c_ctx));
  6462. wolfSSL_SetIOWriteCtx(ctx->c_ssl, ctx);
  6463. wolfSSL_SetIOReadCtx(ctx->c_ssl, ctx);
  6464. if (0
  6465. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6466. || c_sharedCtx
  6467. #endif
  6468. )
  6469. {
  6470. ExpectIntEQ(wolfSSL_use_certificate_chain_file(ctx->c_ssl,
  6471. clientCertFile), WOLFSSL_SUCCESS);
  6472. ExpectIntEQ(wolfSSL_use_PrivateKey_file(ctx->c_ssl, clientKeyFile,
  6473. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  6474. }
  6475. if (ctx->c_cb.ssl_ready != NULL) {
  6476. ExpectIntEQ(ctx->c_cb.ssl_ready(ctx->c_ssl), TEST_SUCCESS);
  6477. }
  6478. /****************************
  6479. * Create WOLFSSL for server.
  6480. ****************************/
  6481. ExpectNotNull(ctx->s_ssl = wolfSSL_new(ctx->s_ctx));
  6482. wolfSSL_SetIOWriteCtx(ctx->s_ssl, ctx);
  6483. wolfSSL_SetIOReadCtx(ctx->s_ssl, ctx);
  6484. if (0
  6485. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6486. || s_sharedCtx
  6487. #endif
  6488. )
  6489. {
  6490. ExpectIntEQ(wolfSSL_use_certificate_chain_file(ctx->s_ssl,
  6491. serverCertFile), WOLFSSL_SUCCESS);
  6492. ExpectIntEQ(wolfSSL_use_PrivateKey_file(ctx->s_ssl, serverKeyFile,
  6493. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  6494. }
  6495. #if !defined(NO_FILESYSTEM) && !defined(NO_DH)
  6496. wolfSSL_SetTmpDH_file(ctx->s_ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  6497. #elif !defined(NO_DH)
  6498. /* will repick suites with DHE, higher priority than PSK */
  6499. SetDH(ctx->s_ssl);
  6500. #endif
  6501. if (ctx->s_cb.ssl_ready != NULL) {
  6502. ExpectIntEQ(ctx->s_cb.ssl_ready(ctx->s_ssl), TEST_SUCCESS);
  6503. }
  6504. return EXPECT_RESULT();
  6505. }
  6506. static int test_ssl_memio_do_handshake(test_ssl_memio_ctx* ctx, int max_rounds,
  6507. int* rounds)
  6508. {
  6509. int handshake_complete = 0;
  6510. int hs_c = 0;
  6511. int hs_s = 0;
  6512. int failing_s = 0;
  6513. int failing_c = 0;
  6514. int ret;
  6515. int err;
  6516. if (rounds != NULL) {
  6517. *rounds = 0;
  6518. }
  6519. while ((!handshake_complete) && (max_rounds > 0)) {
  6520. if (!hs_c) {
  6521. wolfSSL_SetLoggingPrefix("client");
  6522. ret = wolfSSL_connect(ctx->c_ssl);
  6523. wolfSSL_SetLoggingPrefix(NULL);
  6524. if (ret == WOLFSSL_SUCCESS) {
  6525. hs_c = 1;
  6526. }
  6527. else {
  6528. err = wolfSSL_get_error(ctx->c_ssl, ret);
  6529. if (err != WOLFSSL_ERROR_WANT_READ &&
  6530. err != WOLFSSL_ERROR_WANT_WRITE) {
  6531. char buff[WOLFSSL_MAX_ERROR_SZ];
  6532. fprintf(stderr, "error = %d, %s\n", err,
  6533. wolfSSL_ERR_error_string((word32)err, buff));
  6534. failing_c = 1;
  6535. hs_c = 1;
  6536. if (failing_c && failing_s) {
  6537. break;
  6538. }
  6539. }
  6540. }
  6541. }
  6542. if (!hs_s) {
  6543. wolfSSL_SetLoggingPrefix("server");
  6544. ret = wolfSSL_accept(ctx->s_ssl);
  6545. wolfSSL_SetLoggingPrefix(NULL);
  6546. if (ret == WOLFSSL_SUCCESS) {
  6547. hs_s = 1;
  6548. }
  6549. else {
  6550. err = wolfSSL_get_error(ctx->s_ssl, ret);
  6551. if (err != WOLFSSL_ERROR_WANT_READ &&
  6552. err != WOLFSSL_ERROR_WANT_WRITE) {
  6553. char buff[WOLFSSL_MAX_ERROR_SZ];
  6554. fprintf(stderr, "error = %d, %s\n", err,
  6555. wolfSSL_ERR_error_string((word32)err, buff));
  6556. failing_s = 1;
  6557. hs_s = 1;
  6558. if (failing_c && failing_s) {
  6559. break;
  6560. }
  6561. }
  6562. }
  6563. }
  6564. handshake_complete = hs_c && hs_s;
  6565. max_rounds--;
  6566. if (rounds != NULL) {
  6567. *rounds += 1;
  6568. }
  6569. }
  6570. if (!handshake_complete || failing_c || failing_s) {
  6571. return TEST_FAIL;
  6572. }
  6573. return TEST_SUCCESS;
  6574. }
  6575. static int test_ssl_memio_read_write(test_ssl_memio_ctx* ctx)
  6576. {
  6577. EXPECT_DECLS_NO_MSGS(-3000);
  6578. char input[1024];
  6579. int idx = 0;
  6580. const char* msg_c = "hello wolfssl!";
  6581. int msglen_c = (int)XSTRLEN(msg_c);
  6582. const char* msg_s = "I hear you fa shizzle!";
  6583. int msglen_s = (int)XSTRLEN(msg_s);
  6584. if (ctx->c_msg != NULL) {
  6585. msg_c = ctx->c_msg;
  6586. msglen_c = ctx->c_msglen;
  6587. }
  6588. if (ctx->s_msg != NULL) {
  6589. msg_s = ctx->s_msg;
  6590. msglen_s = ctx->s_msglen;
  6591. }
  6592. wolfSSL_SetLoggingPrefix("client");
  6593. ExpectIntEQ(wolfSSL_write(ctx->c_ssl, msg_c, msglen_c), msglen_c);
  6594. wolfSSL_SetLoggingPrefix("server");
  6595. ExpectIntGT(idx = wolfSSL_read(ctx->s_ssl, input, sizeof(input) - 1), 0);
  6596. if (idx >= 0) {
  6597. input[idx] = '\0';
  6598. }
  6599. ExpectIntGT(fprintf(stderr, "Client message: %s\n", input), 0);
  6600. ExpectIntEQ(wolfSSL_write(ctx->s_ssl, msg_s, msglen_s), msglen_s);
  6601. ctx->s_cb.return_code = EXPECT_RESULT();
  6602. wolfSSL_SetLoggingPrefix("client");
  6603. ExpectIntGT(idx = wolfSSL_read(ctx->c_ssl, input, sizeof(input) - 1), 0);
  6604. wolfSSL_SetLoggingPrefix(NULL);
  6605. if (idx >= 0) {
  6606. input[idx] = '\0';
  6607. }
  6608. ExpectIntGT(fprintf(stderr, "Server response: %s\n", input), 0);
  6609. ctx->c_cb.return_code = EXPECT_RESULT();
  6610. if (ctx->c_cb.on_result != NULL) {
  6611. ExpectIntEQ(ctx->c_cb.on_result(ctx->c_ssl), TEST_SUCCESS);
  6612. }
  6613. if (ctx->s_cb.on_result != NULL) {
  6614. ExpectIntEQ(ctx->s_cb.on_result(ctx->s_ssl), TEST_SUCCESS);
  6615. }
  6616. return EXPECT_RESULT();
  6617. }
  6618. static void test_ssl_memio_cleanup(test_ssl_memio_ctx* ctx)
  6619. {
  6620. ctx->c_cb.last_err = wolfSSL_get_error(ctx->c_ssl, 0);
  6621. ctx->s_cb.last_err = wolfSSL_get_error(ctx->s_ssl, 0);
  6622. if (ctx->c_cb.on_cleanup != NULL) {
  6623. ctx->c_cb.on_cleanup(ctx->c_ssl);
  6624. }
  6625. if (ctx->s_cb.on_cleanup != NULL) {
  6626. ctx->s_cb.on_cleanup(ctx->s_ssl);
  6627. }
  6628. wolfSSL_shutdown(ctx->s_ssl);
  6629. wolfSSL_shutdown(ctx->c_ssl);
  6630. wolfSSL_free(ctx->s_ssl);
  6631. wolfSSL_free(ctx->c_ssl);
  6632. if (ctx->c_cb.on_ctx_cleanup != NULL) {
  6633. ctx->c_cb.on_ctx_cleanup(ctx->c_ctx);
  6634. }
  6635. if (!ctx->c_cb.isSharedCtx) {
  6636. wolfSSL_CTX_free(ctx->c_ctx);
  6637. ctx->c_ctx = NULL;
  6638. }
  6639. if (ctx->s_cb.on_ctx_cleanup != NULL) {
  6640. ctx->s_cb.on_ctx_cleanup(ctx->s_ctx);
  6641. }
  6642. if (!ctx->s_cb.isSharedCtx) {
  6643. wolfSSL_CTX_free(ctx->s_ctx);
  6644. ctx->s_ctx = NULL;
  6645. }
  6646. if (!ctx->s_cb.ticNoInit) {
  6647. #if defined(HAVE_SESSION_TICKET) && \
  6648. ((defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))
  6649. #if defined(OPENSSL_EXTRA) && defined(HAVE_AES_CBC)
  6650. OpenSSLTicketCleanup();
  6651. #elif defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  6652. TicketCleanup();
  6653. #endif
  6654. #endif
  6655. }
  6656. }
  6657. int test_wolfSSL_client_server_nofail_memio(test_ssl_cbf* client_cb,
  6658. test_ssl_cbf* server_cb, cbType client_on_handshake)
  6659. {
  6660. /* We use EXPECT_DECLS_NO_MSGS() here because this helper routine is used
  6661. * for numerous but varied expected-to-fail scenarios that should not emit
  6662. * error messages on the expected failures. Instead, we return a distinct
  6663. * code for each failure point, allowing the caller to assert on a
  6664. * particular mode of expected failure. On success, the usual TEST_SUCCESS
  6665. * is returned.
  6666. */
  6667. EXPECT_DECLS_NO_MSGS(-1000);
  6668. struct test_ssl_memio_ctx test_ctx;
  6669. #ifdef WOLFSSL_HAVE_TLS_UNIQUE
  6670. size_t msg_len;
  6671. #endif /* WOLFSSL_HAVE_TLS_UNIQUE */
  6672. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  6673. XMEMCPY(&test_ctx.c_cb, client_cb, sizeof(test_ssl_cbf));
  6674. XMEMCPY(&test_ctx.s_cb, server_cb, sizeof(test_ssl_cbf));
  6675. test_ctx.c_ctx = client_cb->ctx;
  6676. test_ctx.s_ctx = server_cb->ctx;
  6677. test_ctx.c_cb.return_code = EXPECT_FAILURE_CODEPOINT_ID;
  6678. test_ctx.s_cb.return_code = EXPECT_FAILURE_CODEPOINT_ID;
  6679. ExpectIntEQ(test_ssl_memio_setup(&test_ctx), TEST_SUCCESS);
  6680. ExpectIntEQ(test_ssl_memio_do_handshake(&test_ctx, 10, NULL), TEST_SUCCESS);
  6681. if (client_on_handshake != NULL) {
  6682. ExpectIntEQ(client_on_handshake(test_ctx.c_ctx, test_ctx.c_ssl),
  6683. TEST_SUCCESS);
  6684. }
  6685. if (client_cb->on_handshake != NULL) {
  6686. ExpectIntEQ(client_cb->on_handshake(&test_ctx.c_ctx, &test_ctx.c_ssl),
  6687. TEST_SUCCESS);
  6688. }
  6689. if (server_cb->on_handshake != NULL) {
  6690. ExpectIntEQ(server_cb->on_handshake(&test_ctx.s_ctx, &test_ctx.s_ssl),
  6691. TEST_SUCCESS);
  6692. }
  6693. #ifdef WOLFSSL_HAVE_TLS_UNIQUE
  6694. XMEMSET(server_side_msg2, 0, MD_MAX_SIZE);
  6695. msg_len = wolfSSL_get_peer_finished(test_ctx.s_ssl, server_side_msg2,
  6696. MD_MAX_SIZE);
  6697. ExpectIntGE(msg_len, 0);
  6698. XMEMSET(server_side_msg1, 0, MD_MAX_SIZE);
  6699. msg_len = wolfSSL_get_finished(test_ctx.s_ssl, server_side_msg1,
  6700. MD_MAX_SIZE);
  6701. ExpectIntGE(msg_len, 0);
  6702. #endif /* WOLFSSL_HAVE_TLS_UNIQUE */
  6703. ExpectIntEQ(test_ssl_memio_read_write(&test_ctx), TEST_SUCCESS);
  6704. test_ssl_memio_cleanup(&test_ctx);
  6705. client_cb->return_code = test_ctx.c_cb.return_code;
  6706. client_cb->last_err = test_ctx.c_cb.last_err;
  6707. server_cb->return_code = test_ctx.s_cb.return_code;
  6708. server_cb->last_err = test_ctx.s_cb.last_err;
  6709. return EXPECT_RESULT();
  6710. }
  6711. #endif
  6712. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  6713. #ifdef WOLFSSL_SESSION_EXPORT
  6714. #ifdef WOLFSSL_DTLS
  6715. /* set up function for sending session information */
  6716. static int test_export(WOLFSSL* inSsl, byte* buf, word32 sz, void* userCtx)
  6717. {
  6718. WOLFSSL_CTX* ctx = NULL;
  6719. WOLFSSL* ssl = NULL;
  6720. AssertNotNull(inSsl);
  6721. AssertNotNull(buf);
  6722. AssertIntNE(0, sz);
  6723. /* Set ctx to DTLS 1.2 */
  6724. ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method());
  6725. AssertNotNull(ctx);
  6726. ssl = wolfSSL_new(ctx);
  6727. AssertNotNull(ssl);
  6728. AssertIntGE(wolfSSL_dtls_import(ssl, buf, sz), 0);
  6729. wolfSSL_free(ssl);
  6730. wolfSSL_CTX_free(ctx);
  6731. (void)userCtx;
  6732. return 0;
  6733. }
  6734. #endif
  6735. /* returns negative value on fail and positive (including 0) on success */
  6736. static int nonblocking_accept_read(void* args, WOLFSSL* ssl, SOCKET_T* sockfd)
  6737. {
  6738. int ret, err, loop_count, count, timeout = 10;
  6739. char msg[] = "I hear you fa shizzle!";
  6740. char input[1024];
  6741. loop_count = ((func_args*)args)->argc;
  6742. #ifdef WOLFSSL_ASYNC_CRYPT
  6743. err = 0; /* Reset error */
  6744. #endif
  6745. do {
  6746. #ifdef WOLFSSL_ASYNC_CRYPT
  6747. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  6748. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  6749. if (ret < 0) { break; } else if (ret == 0) { continue; }
  6750. }
  6751. #endif
  6752. ret = wolfSSL_accept(ssl);
  6753. err = wolfSSL_get_error(ssl, 0);
  6754. if (err == WOLFSSL_ERROR_WANT_READ ||
  6755. err == WOLFSSL_ERROR_WANT_WRITE) {
  6756. int select_ret;
  6757. err = WC_PENDING_E;
  6758. select_ret = tcp_select(*sockfd, timeout);
  6759. if (select_ret == TEST_TIMEOUT) {
  6760. return WOLFSSL_FATAL_ERROR;
  6761. }
  6762. }
  6763. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  6764. if (ret != WOLFSSL_SUCCESS) {
  6765. char buff[WOLFSSL_MAX_ERROR_SZ];
  6766. fprintf(stderr, "error = %d, %s\n", err,
  6767. wolfSSL_ERR_error_string(err, buff));
  6768. return ret;
  6769. }
  6770. for (count = 0; count < loop_count; count++) {
  6771. int select_ret;
  6772. select_ret = tcp_select(*sockfd, timeout);
  6773. if (select_ret == TEST_TIMEOUT) {
  6774. ret = WOLFSSL_FATAL_ERROR;
  6775. break;
  6776. }
  6777. do {
  6778. ret = wolfSSL_read(ssl, input, sizeof(input)-1);
  6779. if (ret > 0) {
  6780. input[ret] = '\0';
  6781. fprintf(stderr, "Client message: %s\n", input);
  6782. }
  6783. } while (err == WOLFSSL_ERROR_WANT_READ && ret != WOLFSSL_SUCCESS);
  6784. do {
  6785. if ((ret = wolfSSL_write(ssl, msg, sizeof(msg))) != sizeof(msg)) {
  6786. return WOLFSSL_FATAL_ERROR;
  6787. }
  6788. err = wolfSSL_get_error(ssl, ret);
  6789. } while (err == WOLFSSL_ERROR_WANT_READ && ret != WOLFSSL_SUCCESS);
  6790. }
  6791. return ret;
  6792. }
  6793. #endif /* WOLFSSL_SESSION_EXPORT */
  6794. static THREAD_RETURN WOLFSSL_THREAD test_server_nofail(void* args)
  6795. {
  6796. SOCKET_T sockfd = 0;
  6797. SOCKET_T clientfd = 0;
  6798. word16 port;
  6799. callback_functions* cbf;
  6800. WOLFSSL_CTX* ctx = NULL;
  6801. WOLFSSL* ssl = NULL;
  6802. func_args* opts = (func_args*)args;
  6803. char msg[] = "I hear you fa shizzle!";
  6804. char input[1024];
  6805. int idx;
  6806. int ret, err = 0;
  6807. int sharedCtx = 0;
  6808. int doUdp = 0;
  6809. SOCKADDR_IN_T cliAddr;
  6810. socklen_t cliLen;
  6811. const char* certFile = svrCertFile;
  6812. const char* keyFile = svrKeyFile;
  6813. #ifdef WOLFSSL_HAVE_TLS_UNIQUE
  6814. size_t msg_len = 0;
  6815. #endif
  6816. wolfSSL_SetLoggingPrefix("server");
  6817. #ifdef WOLFSSL_TIRTOS
  6818. fdOpenSession(Task_self());
  6819. #endif
  6820. opts->return_code = TEST_FAIL;
  6821. cbf = opts->callbacks;
  6822. if (cbf != NULL && cbf->ctx) {
  6823. ctx = cbf->ctx;
  6824. sharedCtx = 1;
  6825. }
  6826. else
  6827. {
  6828. WOLFSSL_METHOD* method = NULL;
  6829. if (cbf != NULL && cbf->method != NULL) {
  6830. method = cbf->method();
  6831. }
  6832. else {
  6833. method = wolfSSLv23_server_method();
  6834. }
  6835. ctx = wolfSSL_CTX_new(method);
  6836. }
  6837. if (ctx == NULL) {
  6838. /* Release the wait for TCP ready. */
  6839. signal_ready(opts->signal);
  6840. goto done;
  6841. }
  6842. if (cbf == NULL || !cbf->ticNoInit) {
  6843. #if defined(HAVE_SESSION_TICKET) && \
  6844. ((defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))
  6845. #if defined(OPENSSL_EXTRA) && defined(HAVE_AES_CBC)
  6846. OpenSSLTicketInit();
  6847. wolfSSL_CTX_set_tlsext_ticket_key_cb(ctx, myTicketEncCbOpenSSL);
  6848. #elif defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  6849. TicketInit();
  6850. wolfSSL_CTX_set_TicketEncCb(ctx, myTicketEncCb);
  6851. #endif
  6852. #endif
  6853. }
  6854. #if defined(USE_WINDOWS_API)
  6855. port = opts->signal->port;
  6856. #elif defined(NO_MAIN_DRIVER) && !defined(WOLFSSL_SNIFFER) && \
  6857. !defined(WOLFSSL_MDK_SHELL) && !defined(WOLFSSL_TIRTOS)
  6858. /* Let tcp_listen assign port */
  6859. port = 0;
  6860. #else
  6861. /* Use default port */
  6862. port = wolfSSLPort;
  6863. #endif
  6864. if (cbf != NULL)
  6865. doUdp = cbf->doUdp;
  6866. /* do it here to detect failure */
  6867. tcp_accept(
  6868. &sockfd, &clientfd, opts, port, 0, doUdp, 0, 0, 1, 0, 0);
  6869. if (doUdp) {
  6870. cliLen = sizeof(cliAddr);
  6871. idx = (int)recvfrom(sockfd, input, sizeof(input), MSG_PEEK,
  6872. (struct sockaddr*)&cliAddr, &cliLen);
  6873. AssertIntGT(idx, 0);
  6874. }
  6875. else {
  6876. CloseSocket(sockfd);
  6877. }
  6878. wolfSSL_CTX_set_verify(ctx,
  6879. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  6880. #ifdef WOLFSSL_ENCRYPTED_KEYS
  6881. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  6882. #endif
  6883. if (wolfSSL_CTX_load_verify_locations(ctx, cliCertFile, 0)
  6884. != WOLFSSL_SUCCESS) {
  6885. /*err_sys("can't load ca file, Please run from wolfSSL home dir");*/
  6886. goto done;
  6887. }
  6888. if (cbf != NULL && cbf->certPemFile != NULL)
  6889. certFile = cbf->certPemFile;
  6890. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6891. if (!sharedCtx && wolfSSL_CTX_use_certificate_file(ctx, certFile,
  6892. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6893. #else
  6894. if (wolfSSL_CTX_use_certificate_file(ctx, certFile,
  6895. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6896. #endif
  6897. /*err_sys("can't load server cert chain file, "
  6898. "Please run from wolfSSL home dir");*/
  6899. goto done;
  6900. }
  6901. if (cbf != NULL && cbf->keyPemFile != NULL)
  6902. keyFile = cbf->keyPemFile;
  6903. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6904. if (!sharedCtx && wolfSSL_CTX_use_PrivateKey_file(ctx, keyFile,
  6905. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6906. #else
  6907. if (wolfSSL_CTX_use_PrivateKey_file(ctx, keyFile,
  6908. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6909. #endif
  6910. /*err_sys("can't load server key file, "
  6911. "Please run from wolfSSL home dir");*/
  6912. goto done;
  6913. }
  6914. #ifdef HAVE_CRL
  6915. if (cbf != NULL && cbf->crlPemFile != NULL) {
  6916. if (wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL) != WOLFSSL_SUCCESS)
  6917. goto done;
  6918. if (wolfSSL_CTX_LoadCRLFile(ctx, cbf->crlPemFile, WOLFSSL_FILETYPE_PEM)
  6919. != WOLFSSL_SUCCESS)
  6920. goto done;
  6921. }
  6922. #endif
  6923. /* call ctx setup callback */
  6924. if (cbf != NULL && cbf->ctx_ready != NULL) {
  6925. cbf->ctx_ready(ctx);
  6926. }
  6927. ssl = wolfSSL_new(ctx);
  6928. if (ssl == NULL) {
  6929. goto done;
  6930. }
  6931. if (doUdp) {
  6932. err = wolfSSL_dtls_set_peer(ssl, &cliAddr, cliLen);
  6933. if (err != WOLFSSL_SUCCESS)
  6934. goto done;
  6935. }
  6936. #ifdef WOLFSSL_SESSION_EXPORT
  6937. /* only add in more complex nonblocking case with session export tests */
  6938. if (args && opts->argc > 0) {
  6939. /* set as nonblock and time out for waiting on read/write */
  6940. tcp_set_nonblocking(&clientfd);
  6941. wolfSSL_dtls_set_using_nonblock(ssl, 1);
  6942. }
  6943. #endif
  6944. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6945. if (sharedCtx && wolfSSL_use_certificate_file(ssl, certFile,
  6946. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6947. #else
  6948. if (wolfSSL_use_certificate_file(ssl, certFile,
  6949. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6950. #endif
  6951. /*err_sys("can't load server cert chain file, "
  6952. "Please run from wolfSSL home dir");*/
  6953. goto done;
  6954. }
  6955. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  6956. if (sharedCtx && wolfSSL_use_PrivateKey_file(ssl, keyFile,
  6957. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6958. #else
  6959. if (wolfSSL_use_PrivateKey_file(ssl, keyFile,
  6960. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  6961. #endif
  6962. /*err_sys("can't load server key file, "
  6963. "Please run from wolfSSL home dir");*/
  6964. goto done;
  6965. }
  6966. if (wolfSSL_set_fd(ssl, clientfd) != WOLFSSL_SUCCESS) {
  6967. /*err_sys("SSL_set_fd failed");*/
  6968. goto done;
  6969. }
  6970. #if !defined(NO_FILESYSTEM) && !defined(NO_DH)
  6971. wolfSSL_SetTmpDH_file(ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  6972. #elif !defined(NO_DH)
  6973. SetDH(ssl); /* will repick suites with DHE, higher priority than PSK */
  6974. #endif
  6975. /* call ssl setup callback */
  6976. if (cbf != NULL && cbf->ssl_ready != NULL) {
  6977. cbf->ssl_ready(ssl);
  6978. }
  6979. #ifdef WOLFSSL_SESSION_EXPORT
  6980. /* only add in more complex nonblocking case with session export tests */
  6981. if (opts->argc > 0) {
  6982. ret = nonblocking_accept_read(args, ssl, &clientfd);
  6983. if (ret >= 0) {
  6984. opts->return_code = TEST_SUCCESS;
  6985. }
  6986. #ifdef WOLFSSL_TIRTOS
  6987. Task_yield();
  6988. #endif
  6989. goto done;
  6990. }
  6991. #endif
  6992. #ifdef WOLFSSL_ASYNC_CRYPT
  6993. err = 0; /* Reset error */
  6994. #endif
  6995. do {
  6996. #ifdef WOLFSSL_ASYNC_CRYPT
  6997. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  6998. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  6999. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7000. }
  7001. #endif
  7002. ret = wolfSSL_negotiate(ssl);
  7003. err = wolfSSL_get_error(ssl, 0);
  7004. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7005. if (ret != WOLFSSL_SUCCESS) {
  7006. char buff[WOLFSSL_MAX_ERROR_SZ];
  7007. fprintf(stderr, "error = %d, %s\n", err,
  7008. wolfSSL_ERR_error_string((word32)err, buff));
  7009. /*err_sys("SSL_accept failed");*/
  7010. goto done;
  7011. }
  7012. #ifdef WOLFSSL_HAVE_TLS_UNIQUE
  7013. XMEMSET(server_side_msg2, 0, MD_MAX_SIZE);
  7014. msg_len = wolfSSL_get_peer_finished(ssl, server_side_msg2, MD_MAX_SIZE);
  7015. AssertIntGE(msg_len, 0);
  7016. XMEMSET(server_side_msg1, 0, MD_MAX_SIZE);
  7017. msg_len = wolfSSL_get_finished(ssl, server_side_msg1, MD_MAX_SIZE);
  7018. AssertIntGE(msg_len, 0);
  7019. #endif /* WOLFSSL_HAVE_TLS_UNIQUE */
  7020. idx = wolfSSL_read(ssl, input, sizeof(input)-1);
  7021. if (idx > 0) {
  7022. input[idx] = '\0';
  7023. fprintf(stderr, "Client message: %s\n", input);
  7024. }
  7025. else if (idx < 0) {
  7026. goto done;
  7027. }
  7028. if (wolfSSL_write(ssl, msg, sizeof(msg)) != sizeof(msg)) {
  7029. /*err_sys("SSL_write failed");*/
  7030. goto done;
  7031. }
  7032. if (cbf != NULL && cbf->on_result != NULL)
  7033. cbf->on_result(ssl);
  7034. #ifdef WOLFSSL_TIRTOS
  7035. Task_yield();
  7036. #endif
  7037. opts->return_code = TEST_SUCCESS;
  7038. done:
  7039. if (cbf != NULL)
  7040. cbf->last_err = err;
  7041. if (cbf != NULL && cbf->on_cleanup != NULL)
  7042. cbf->on_cleanup(ssl);
  7043. wolfSSL_shutdown(ssl);
  7044. wolfSSL_free(ssl);
  7045. if (!sharedCtx)
  7046. wolfSSL_CTX_free(ctx);
  7047. CloseSocket(clientfd);
  7048. #ifdef WOLFSSL_TIRTOS
  7049. fdCloseSession(Task_self());
  7050. #endif
  7051. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  7052. && defined(HAVE_THREAD_LS)
  7053. wc_ecc_fp_free(); /* free per thread cache */
  7054. #endif
  7055. if (cbf == NULL || !cbf->ticNoInit) {
  7056. #if defined(HAVE_SESSION_TICKET) && \
  7057. ((defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))
  7058. #if defined(OPENSSL_EXTRA) && defined(HAVE_AES_CBC)
  7059. OpenSSLTicketCleanup();
  7060. #elif defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  7061. TicketCleanup();
  7062. #endif
  7063. #endif
  7064. }
  7065. wolfSSL_SetLoggingPrefix(NULL);
  7066. WOLFSSL_RETURN_FROM_THREAD(0);
  7067. }
  7068. #if defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) && \
  7069. !defined(WOLFSSL_NO_TLS12)
  7070. static THREAD_RETURN WOLFSSL_THREAD test_server_loop(void* args)
  7071. {
  7072. SOCKET_T sockfd;
  7073. SOCKET_T clientfd = -1;
  7074. word16 port;
  7075. callback_functions* cbf;
  7076. WOLFSSL_CTX* ctx = 0;
  7077. WOLFSSL* ssl = 0;
  7078. char msg[] = "I hear you fa shizzle!";
  7079. char input[1024];
  7080. int idx;
  7081. int ret, err = 0;
  7082. int sharedCtx = 0;
  7083. func_args* opts = (func_args*)args;
  7084. int loop_count = opts->argc;
  7085. int count = 0;
  7086. #ifdef WOLFSSL_TIRTOS
  7087. fdOpenSession(Task_self());
  7088. #endif
  7089. opts->return_code = TEST_FAIL;
  7090. cbf = opts->callbacks;
  7091. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7092. if (cbf != NULL && cbf->ctx) {
  7093. ctx = cbf->ctx;
  7094. sharedCtx = 1;
  7095. }
  7096. else
  7097. #endif
  7098. {
  7099. WOLFSSL_METHOD* method = NULL;
  7100. if (cbf != NULL && cbf->method != NULL) {
  7101. method = cbf->method();
  7102. }
  7103. else {
  7104. method = wolfSSLv23_server_method();
  7105. }
  7106. ctx = wolfSSL_CTX_new(method);
  7107. }
  7108. #if defined(USE_WINDOWS_API)
  7109. port = opts->signal->port;
  7110. #elif defined(NO_MAIN_DRIVER) && !defined(WOLFSSL_SNIFFER) && \
  7111. !defined(WOLFSSL_MDK_SHELL) && !defined(WOLFSSL_TIRTOS)
  7112. /* Let tcp_listen assign port */
  7113. port = 0;
  7114. #else
  7115. /* Use default port */
  7116. port = wolfSSLPort;
  7117. #endif
  7118. wolfSSL_CTX_set_verify(ctx,
  7119. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  7120. #ifdef WOLFSSL_ENCRYPTED_KEYS
  7121. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  7122. #endif
  7123. if (wolfSSL_CTX_load_verify_locations(ctx, cliCertFile, 0)
  7124. != WOLFSSL_SUCCESS) {
  7125. /*err_sys("can't load ca file, Please run from wolfSSL home dir");*/
  7126. /* Release the wait for TCP ready. */
  7127. signal_ready(opts->signal);
  7128. goto done;
  7129. }
  7130. if (!sharedCtx && wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  7131. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7132. /*err_sys("can't load server cert chain file, "
  7133. "Please run from wolfSSL home dir");*/
  7134. /* Release the wait for TCP ready. */
  7135. signal_ready(opts->signal);
  7136. goto done;
  7137. }
  7138. if (!sharedCtx && wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  7139. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7140. /*err_sys("can't load server key file, "
  7141. "Please run from wolfSSL home dir");*/
  7142. /* Release the wait for TCP ready. */
  7143. signal_ready(opts->signal);
  7144. goto done;
  7145. }
  7146. /* call ctx setup callback */
  7147. if (cbf != NULL && cbf->ctx_ready != NULL) {
  7148. cbf->ctx_ready(ctx);
  7149. }
  7150. while (count != loop_count) {
  7151. ssl = wolfSSL_new(ctx);
  7152. if (ssl == NULL) {
  7153. signal_ready(opts->signal);
  7154. goto done;
  7155. }
  7156. if (sharedCtx && wolfSSL_use_certificate_file(ssl, svrCertFile,
  7157. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7158. /*err_sys("can't load server cert chain file, "
  7159. "Please run from wolfSSL home dir");*/
  7160. /* Release the wait for TCP ready. */
  7161. signal_ready(opts->signal);
  7162. goto done;
  7163. }
  7164. if (sharedCtx && wolfSSL_use_PrivateKey_file(ssl, svrKeyFile,
  7165. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7166. /*err_sys("can't load server key file, "
  7167. "Please run from wolfSSL home dir");*/
  7168. /* Release the wait for TCP ready. */
  7169. signal_ready(opts->signal);
  7170. goto done;
  7171. }
  7172. #if !defined(NO_FILESYSTEM) && !defined(NO_DH)
  7173. wolfSSL_SetTmpDH_file(ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  7174. #elif !defined(NO_DH)
  7175. SetDH(ssl); /* will repick suites with DHE, higher priority than PSK */
  7176. #endif
  7177. /* call ssl setup callback */
  7178. if (cbf != NULL && cbf->ssl_ready != NULL) {
  7179. cbf->ssl_ready(ssl);
  7180. }
  7181. /* do it here to detect failure */
  7182. tcp_accept(&sockfd, &clientfd, (func_args*)args, port, 0, 0, 0, 0, 1, 0,
  7183. 0);
  7184. CloseSocket(sockfd);
  7185. if (wolfSSL_set_fd(ssl, clientfd) != WOLFSSL_SUCCESS) {
  7186. /*err_sys("SSL_set_fd failed");*/
  7187. goto done;
  7188. }
  7189. #ifdef WOLFSSL_ASYNC_CRYPT
  7190. err = 0; /* Reset error */
  7191. #endif
  7192. do {
  7193. #ifdef WOLFSSL_ASYNC_CRYPT
  7194. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7195. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7196. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7197. }
  7198. #endif
  7199. ret = wolfSSL_accept(ssl);
  7200. err = wolfSSL_get_error(ssl, 0);
  7201. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7202. if (ret != WOLFSSL_SUCCESS) {
  7203. char buff[WOLFSSL_MAX_ERROR_SZ];
  7204. fprintf(stderr, "error = %d, %s\n", err,
  7205. wolfSSL_ERR_error_string(err, buff));
  7206. /*err_sys("SSL_accept failed");*/
  7207. goto done;
  7208. }
  7209. idx = wolfSSL_read(ssl, input, sizeof(input)-1);
  7210. if (idx > 0) {
  7211. input[idx] = '\0';
  7212. fprintf(stderr, "Client message: %s\n", input);
  7213. }
  7214. if (wolfSSL_write(ssl, msg, sizeof(msg)) != sizeof(msg)) {
  7215. /*err_sys("SSL_write failed");*/
  7216. goto done;
  7217. }
  7218. /* free ssl for this connection */
  7219. wolfSSL_shutdown(ssl);
  7220. wolfSSL_free(ssl); ssl = NULL;
  7221. CloseSocket(clientfd);
  7222. clientfd = -1;
  7223. count++;
  7224. }
  7225. #ifdef WOLFSSL_TIRTOS
  7226. Task_yield();
  7227. #endif
  7228. opts->return_code = TEST_SUCCESS;
  7229. done:
  7230. if (ssl != NULL) {
  7231. wolfSSL_shutdown(ssl);
  7232. wolfSSL_free(ssl);
  7233. }
  7234. if (!sharedCtx)
  7235. wolfSSL_CTX_free(ctx);
  7236. if (clientfd >= 0)
  7237. CloseSocket(clientfd);
  7238. #ifdef WOLFSSL_TIRTOS
  7239. fdCloseSession(Task_self());
  7240. #endif
  7241. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  7242. && defined(HAVE_THREAD_LS)
  7243. wc_ecc_fp_free(); /* free per thread cache */
  7244. #endif
  7245. WOLFSSL_RETURN_FROM_THREAD(0);
  7246. }
  7247. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) && !defined(WOLFSSL_TLS13) */
  7248. static int test_client_nofail(void* args, cbType cb)
  7249. {
  7250. #if !defined(NO_WOLFSSL_CLIENT)
  7251. SOCKET_T sockfd = 0;
  7252. callback_functions* cbf;
  7253. WOLFSSL_CTX* ctx = 0;
  7254. WOLFSSL* ssl = 0;
  7255. WOLFSSL_CIPHER* cipher;
  7256. char msg[64] = "hello wolfssl!";
  7257. char reply[1024];
  7258. int input;
  7259. int msgSz = (int)XSTRLEN(msg);
  7260. int ret, err = 0;
  7261. int cipherSuite;
  7262. int sharedCtx = 0;
  7263. int doUdp = 0;
  7264. const char* cipherName1, *cipherName2;
  7265. wolfSSL_SetLoggingPrefix("client");
  7266. #ifdef WOLFSSL_TIRTOS
  7267. fdOpenSession(Task_self());
  7268. #endif
  7269. ((func_args*)args)->return_code = TEST_FAIL;
  7270. cbf = ((func_args*)args)->callbacks;
  7271. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7272. if (cbf != NULL && cbf->ctx) {
  7273. ctx = cbf->ctx;
  7274. sharedCtx = cbf->isSharedCtx;
  7275. }
  7276. else
  7277. #endif
  7278. {
  7279. WOLFSSL_METHOD* method = NULL;
  7280. if (cbf != NULL && cbf->method != NULL) {
  7281. method = cbf->method();
  7282. }
  7283. else {
  7284. method = wolfSSLv23_client_method();
  7285. }
  7286. ctx = wolfSSL_CTX_new(method);
  7287. }
  7288. if (cbf != NULL)
  7289. doUdp = cbf->doUdp;
  7290. #ifdef WOLFSSL_ENCRYPTED_KEYS
  7291. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  7292. #endif
  7293. /* Do connect here so server detects failures */
  7294. tcp_connect(&sockfd, wolfSSLIP, ((func_args*)args)->signal->port,
  7295. doUdp, 0, NULL);
  7296. /* Connect the socket so that we don't have to set the peer later on */
  7297. if (doUdp)
  7298. udp_connect(&sockfd, wolfSSLIP, ((func_args*)args)->signal->port);
  7299. if (wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0) != WOLFSSL_SUCCESS)
  7300. {
  7301. /* err_sys("can't load ca file, Please run from wolfSSL home dir");*/
  7302. goto done;
  7303. }
  7304. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7305. if (!sharedCtx && wolfSSL_CTX_use_certificate_file(ctx, cliCertFile,
  7306. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7307. #else
  7308. if (wolfSSL_CTX_use_certificate_file(ctx, cliCertFile,
  7309. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7310. #endif
  7311. /*err_sys("can't load client cert file, "
  7312. "Please run from wolfSSL home dir");*/
  7313. goto done;
  7314. }
  7315. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7316. if (!sharedCtx && wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile,
  7317. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7318. #else
  7319. if (wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile,
  7320. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7321. #endif
  7322. /*err_sys("can't load client key file, "
  7323. "Please run from wolfSSL home dir");*/
  7324. goto done;
  7325. }
  7326. #ifdef HAVE_CRL
  7327. if (cbf != NULL && cbf->crlPemFile != NULL) {
  7328. if (wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL) != WOLFSSL_SUCCESS)
  7329. goto done;
  7330. if (wolfSSL_CTX_LoadCRLFile(ctx, cbf->crlPemFile, WOLFSSL_FILETYPE_PEM)
  7331. != WOLFSSL_SUCCESS)
  7332. goto done;
  7333. }
  7334. #endif
  7335. /* call ctx setup callback */
  7336. if (cbf != NULL && cbf->ctx_ready != NULL) {
  7337. cbf->ctx_ready(ctx);
  7338. }
  7339. ssl = wolfSSL_new(ctx);
  7340. if (ssl == NULL) {
  7341. goto done;
  7342. }
  7343. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7344. if (sharedCtx && wolfSSL_use_certificate_file(ssl, cliCertFile,
  7345. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7346. #else
  7347. if (wolfSSL_use_certificate_file(ssl, cliCertFile,
  7348. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7349. #endif
  7350. /*err_sys("can't load client cert file, "
  7351. "Please run from wolfSSL home dir");*/
  7352. goto done;
  7353. }
  7354. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7355. if (sharedCtx && wolfSSL_use_PrivateKey_file(ssl, cliKeyFile,
  7356. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7357. #else
  7358. if (wolfSSL_use_PrivateKey_file(ssl, cliKeyFile,
  7359. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7360. #endif
  7361. /*err_sys("can't load client key file, "
  7362. "Please run from wolfSSL home dir");*/
  7363. goto done;
  7364. }
  7365. if (!doUdp) {
  7366. if (wolfSSL_set_fd(ssl, sockfd) != WOLFSSL_SUCCESS) {
  7367. /*err_sys("SSL_set_fd failed");*/
  7368. goto done;
  7369. }
  7370. }
  7371. else {
  7372. #ifdef WOLFSSL_DTLS
  7373. if (wolfSSL_set_dtls_fd_connected(ssl, sockfd) != WOLFSSL_SUCCESS) {
  7374. /*err_sys("SSL_set_fd failed");*/
  7375. goto done;
  7376. }
  7377. #else
  7378. goto done;
  7379. #endif
  7380. }
  7381. /* call ssl setup callback */
  7382. if (cbf != NULL && cbf->ssl_ready != NULL) {
  7383. cbf->ssl_ready(ssl);
  7384. }
  7385. #ifdef WOLFSSL_ASYNC_CRYPT
  7386. err = 0; /* Reset error */
  7387. #endif
  7388. do {
  7389. #ifdef WOLFSSL_ASYNC_CRYPT
  7390. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7391. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7392. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7393. }
  7394. #endif
  7395. ret = wolfSSL_negotiate(ssl);
  7396. err = wolfSSL_get_error(ssl, 0);
  7397. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7398. if (ret != WOLFSSL_SUCCESS) {
  7399. char buff[WOLFSSL_MAX_ERROR_SZ];
  7400. fprintf(stderr, "error = %d, %s\n", err,
  7401. wolfSSL_ERR_error_string((word32)err, buff));
  7402. /*err_sys("SSL_connect failed");*/
  7403. goto done;
  7404. }
  7405. /* test the various get cipher methods */
  7406. /* Internal cipher suite names */
  7407. cipherSuite = wolfSSL_get_current_cipher_suite(ssl);
  7408. cipherName1 = wolfSSL_get_cipher_name(ssl);
  7409. cipherName2 = wolfSSL_get_cipher_name_from_suite(
  7410. (byte)(cipherSuite >> 8), cipherSuite & 0xFF);
  7411. AssertStrEQ(cipherName1, cipherName2);
  7412. /* IANA Cipher Suites Names */
  7413. /* Unless WOLFSSL_CIPHER_INTERNALNAME or NO_ERROR_STRINGS,
  7414. then it's the internal cipher suite name */
  7415. cipher = wolfSSL_get_current_cipher(ssl);
  7416. cipherName1 = wolfSSL_CIPHER_get_name(cipher);
  7417. cipherName2 = wolfSSL_get_cipher(ssl);
  7418. AssertStrEQ(cipherName1, cipherName2);
  7419. #if !defined(WOLFSSL_CIPHER_INTERNALNAME) && !defined(NO_ERROR_STRINGS) && \
  7420. !defined(WOLFSSL_QT)
  7421. cipherName1 = wolfSSL_get_cipher_name_iana_from_suite(
  7422. (byte)(cipherSuite >> 8), cipherSuite & 0xFF);
  7423. AssertStrEQ(cipherName1, cipherName2);
  7424. #endif
  7425. if (cb != NULL)
  7426. (cb)(ctx, ssl);
  7427. if (wolfSSL_write(ssl, msg, msgSz) != msgSz) {
  7428. /*err_sys("SSL_write failed");*/
  7429. goto done;
  7430. }
  7431. input = wolfSSL_read(ssl, reply, sizeof(reply)-1);
  7432. if (input > 0) {
  7433. reply[input] = '\0';
  7434. fprintf(stderr, "Server response: %s\n", reply);
  7435. }
  7436. if (cbf != NULL && cbf->on_result != NULL)
  7437. cbf->on_result(ssl);
  7438. ((func_args*)args)->return_code = TEST_SUCCESS;
  7439. done:
  7440. if (cbf != NULL)
  7441. cbf->last_err = err;
  7442. if (cbf != NULL && cbf->on_cleanup != NULL)
  7443. cbf->on_cleanup(ssl);
  7444. wolfSSL_free(ssl);
  7445. if (!sharedCtx)
  7446. wolfSSL_CTX_free(ctx);
  7447. CloseSocket(sockfd);
  7448. #ifdef WOLFSSL_TIRTOS
  7449. fdCloseSession(Task_self());
  7450. #endif
  7451. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  7452. && defined(HAVE_THREAD_LS)
  7453. wc_ecc_fp_free(); /* free per thread cache */
  7454. #endif
  7455. #else
  7456. (void)args;
  7457. (void)cb;
  7458. #endif /* !NO_WOLFSSL_CLIENT */
  7459. wolfSSL_SetLoggingPrefix(NULL);
  7460. return 0;
  7461. }
  7462. void test_wolfSSL_client_server_nofail_ex(callback_functions* client_cb,
  7463. callback_functions* server_cb, cbType client_on_handshake)
  7464. {
  7465. func_args client_args;
  7466. func_args server_args;
  7467. tcp_ready ready;
  7468. THREAD_TYPE serverThread;
  7469. XMEMSET(&client_args, 0, sizeof(func_args));
  7470. XMEMSET(&server_args, 0, sizeof(func_args));
  7471. #ifdef WOLFSSL_TIRTOS
  7472. fdOpenSession(Task_self());
  7473. #endif
  7474. StartTCP();
  7475. InitTcpReady(&ready);
  7476. #if defined(USE_WINDOWS_API)
  7477. /* use RNG to get random port if using windows */
  7478. ready.port = GetRandomPort();
  7479. #endif
  7480. server_args.signal = &ready;
  7481. server_args.callbacks = server_cb;
  7482. client_args.signal = &ready;
  7483. client_args.callbacks = client_cb;
  7484. start_thread(test_server_nofail, &server_args, &serverThread);
  7485. wait_tcp_ready(&server_args);
  7486. test_client_nofail(&client_args, client_on_handshake);
  7487. join_thread(serverThread);
  7488. client_cb->return_code = client_args.return_code;
  7489. server_cb->return_code = server_args.return_code;
  7490. FreeTcpReady(&ready);
  7491. #ifdef WOLFSSL_TIRTOS
  7492. fdOpenSession(Task_self());
  7493. #endif
  7494. }
  7495. void test_wolfSSL_client_server_nofail(callback_functions* client_cb,
  7496. callback_functions* server_cb)
  7497. {
  7498. test_wolfSSL_client_server_nofail_ex(client_cb, server_cb, NULL);
  7499. }
  7500. #if defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) && \
  7501. !defined(WOLFSSL_NO_TLS12) && !defined(NO_WOLFSSL_CLIENT)
  7502. static void test_client_reuse_WOLFSSLobj(void* args, cbType cb,
  7503. void* server_args)
  7504. {
  7505. SOCKET_T sockfd = 0;
  7506. callback_functions* cbf;
  7507. WOLFSSL_CTX* ctx = 0;
  7508. WOLFSSL* ssl = 0;
  7509. WOLFSSL_SESSION* session = NULL;
  7510. char msg[64] = "hello wolfssl!";
  7511. char reply[1024];
  7512. int input;
  7513. int msgSz = (int)XSTRLEN(msg);
  7514. int ret, err = 0;
  7515. int sharedCtx = 0;
  7516. #ifdef WOLFSSL_TIRTOS
  7517. fdOpenSession(Task_self());
  7518. #endif
  7519. ((func_args*)args)->return_code = TEST_FAIL;
  7520. cbf = ((func_args*)args)->callbacks;
  7521. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)
  7522. if (cbf != NULL && cbf->ctx) {
  7523. ctx = cbf->ctx;
  7524. sharedCtx = 1;
  7525. }
  7526. else
  7527. #endif
  7528. {
  7529. WOLFSSL_METHOD* method = NULL;
  7530. if (cbf != NULL && cbf->method != NULL) {
  7531. method = cbf->method();
  7532. }
  7533. else {
  7534. method = wolfSSLv23_client_method();
  7535. }
  7536. ctx = wolfSSL_CTX_new(method);
  7537. }
  7538. #ifdef WOLFSSL_ENCRYPTED_KEYS
  7539. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  7540. #endif
  7541. /* Do connect here so server detects failures */
  7542. tcp_connect(&sockfd, wolfSSLIP, ((func_args*)args)->signal->port,
  7543. 0, 0, NULL);
  7544. if (wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0) !=
  7545. WOLFSSL_SUCCESS) {
  7546. /* err_sys("can't load ca file, Please run from wolfSSL home dir");*/
  7547. goto done;
  7548. }
  7549. if (!sharedCtx && wolfSSL_CTX_use_certificate_file(ctx, cliCertFile,
  7550. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7551. /*err_sys("can't load client cert file, "
  7552. "Please run from wolfSSL home dir");*/
  7553. goto done;
  7554. }
  7555. if (!sharedCtx && wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile,
  7556. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7557. /*err_sys("can't load client key file, "
  7558. "Please run from wolfSSL home dir");*/
  7559. goto done;
  7560. }
  7561. /* call ctx setup callback */
  7562. if (cbf != NULL && cbf->ctx_ready != NULL) {
  7563. cbf->ctx_ready(ctx);
  7564. }
  7565. ssl = wolfSSL_new(ctx);
  7566. if (ssl == NULL) {
  7567. goto done;
  7568. }
  7569. /* keep handshake resources for re-using WOLFSSL obj */
  7570. wolfSSL_KeepArrays(ssl);
  7571. if (wolfSSL_KeepHandshakeResources(ssl)) {
  7572. /* err_sys("SSL_KeepHandshakeResources failed"); */
  7573. goto done;
  7574. }
  7575. if (sharedCtx && wolfSSL_use_certificate_file(ssl, cliCertFile,
  7576. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7577. /*err_sys("can't load client cert file, "
  7578. "Please run from wolfSSL home dir");*/
  7579. goto done;
  7580. }
  7581. if (sharedCtx && wolfSSL_use_PrivateKey_file(ssl, cliKeyFile,
  7582. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7583. /*err_sys("can't load client key file, "
  7584. "Please run from wolfSSL home dir");*/
  7585. goto done;
  7586. }
  7587. if (wolfSSL_set_fd(ssl, sockfd) != WOLFSSL_SUCCESS) {
  7588. /*err_sys("SSL_set_fd failed");*/
  7589. goto done;
  7590. }
  7591. /* call ssl setup callback */
  7592. if (cbf != NULL && cbf->ssl_ready != NULL) {
  7593. cbf->ssl_ready(ssl);
  7594. }
  7595. #ifdef WOLFSSL_ASYNC_CRYPT
  7596. err = 0; /* Reset error */
  7597. #endif
  7598. do {
  7599. #ifdef WOLFSSL_ASYNC_CRYPT
  7600. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7601. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7602. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7603. }
  7604. #endif
  7605. ret = wolfSSL_connect(ssl);
  7606. err = wolfSSL_get_error(ssl, 0);
  7607. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7608. if (ret != WOLFSSL_SUCCESS) {
  7609. char buff[WOLFSSL_MAX_ERROR_SZ];
  7610. fprintf(stderr, "error = %d, %s\n", err,
  7611. wolfSSL_ERR_error_string(err, buff));
  7612. /*err_sys("SSL_connect failed");*/
  7613. goto done;
  7614. }
  7615. /* Build first session */
  7616. if (cb != NULL)
  7617. cb(ctx, ssl);
  7618. if (wolfSSL_write(ssl, msg, msgSz) != msgSz) {
  7619. /*err_sys("SSL_write failed");*/
  7620. goto done;
  7621. }
  7622. input = wolfSSL_read(ssl, reply, sizeof(reply)-1);
  7623. if (input > 0) {
  7624. reply[input] = '\0';
  7625. fprintf(stderr, "Server response: %s\n", reply);
  7626. }
  7627. /* Session Resumption by re-using WOLFSSL object */
  7628. wolfSSL_set_quiet_shutdown(ssl, 1);
  7629. if (wolfSSL_shutdown(ssl) != WOLFSSL_SUCCESS) {
  7630. /* err_sys ("SSL shutdown failed"); */
  7631. goto done;
  7632. }
  7633. session = wolfSSL_get1_session(ssl);
  7634. if (wolfSSL_clear(ssl) != WOLFSSL_SUCCESS) {
  7635. wolfSSL_SESSION_free(session);
  7636. /* err_sys ("SSL_clear failed"); */
  7637. goto done;
  7638. }
  7639. wolfSSL_set_session(ssl, session);
  7640. wolfSSL_SESSION_free(session);
  7641. session = NULL;
  7642. /* close socket once */
  7643. CloseSocket(sockfd);
  7644. sockfd = 0;
  7645. /* wait until server ready */
  7646. wait_tcp_ready((func_args*)server_args);
  7647. fprintf(stderr, "session resumption\n");
  7648. /* Do re-connect */
  7649. tcp_connect(&sockfd, wolfSSLIP, ((func_args*)args)->signal->port,
  7650. 0, 0, NULL);
  7651. if (wolfSSL_set_fd(ssl, sockfd) != WOLFSSL_SUCCESS) {
  7652. /*err_sys("SSL_set_fd failed");*/
  7653. goto done;
  7654. }
  7655. #ifdef WOLFSSL_ASYNC_CRYPT
  7656. err = 0; /* Reset error */
  7657. #endif
  7658. do {
  7659. #ifdef WOLFSSL_ASYNC_CRYPT
  7660. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7661. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7662. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7663. }
  7664. #endif
  7665. ret = wolfSSL_connect(ssl);
  7666. err = wolfSSL_get_error(ssl, 0);
  7667. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7668. if (ret != WOLFSSL_SUCCESS) {
  7669. char buff[WOLFSSL_MAX_ERROR_SZ];
  7670. fprintf(stderr, "error = %d, %s\n", err,
  7671. wolfSSL_ERR_error_string(err, buff));
  7672. /*err_sys("SSL_connect failed");*/
  7673. goto done;
  7674. }
  7675. /* Build first session */
  7676. if (cb != NULL)
  7677. cb(ctx, ssl);
  7678. if (wolfSSL_write(ssl, msg, msgSz) != msgSz) {
  7679. /*err_sys("SSL_write failed");*/
  7680. goto done;
  7681. }
  7682. input = wolfSSL_read(ssl, reply, sizeof(reply)-1);
  7683. if (input > 0) {
  7684. reply[input] = '\0';
  7685. fprintf(stderr, "Server response: %s\n", reply);
  7686. }
  7687. ((func_args*)args)->return_code = TEST_SUCCESS;
  7688. done:
  7689. wolfSSL_free(ssl);
  7690. if (!sharedCtx)
  7691. wolfSSL_CTX_free(ctx);
  7692. CloseSocket(sockfd);
  7693. #ifdef WOLFSSL_TIRTOS
  7694. fdCloseSession(Task_self());
  7695. #endif
  7696. return;
  7697. }
  7698. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) &&
  7699. !defined(WOLFSSL_TLS13) && !defined(NO_WOLFSSL_CLIENT) */
  7700. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \
  7701. defined(WOLFSSL_HAPROXY) || defined(HAVE_LIGHTY)) && \
  7702. defined(HAVE_ALPN) && defined(HAVE_SNI) && \
  7703. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(NO_BIO)
  7704. #define HAVE_ALPN_PROTOS_SUPPORT
  7705. #endif
  7706. /* Generic TLS client / server with callbacks for API unit tests
  7707. * Used by SNI / ALPN / crypto callback helper functions */
  7708. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  7709. (defined(HAVE_SNI) || defined(HAVE_ALPN) || defined(WOLF_CRYPTO_CB) || \
  7710. defined(HAVE_ALPN_PROTOS_SUPPORT)) || defined(WOLFSSL_STATIC_MEMORY)
  7711. #define ENABLE_TLS_CALLBACK_TEST
  7712. #endif
  7713. #if defined(ENABLE_TLS_CALLBACK_TEST) || \
  7714. (defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT))
  7715. /* TLS server for API unit testing - generic */
  7716. static THREAD_RETURN WOLFSSL_THREAD run_wolfssl_server(void* args)
  7717. {
  7718. callback_functions* callbacks = ((func_args*)args)->callbacks;
  7719. WOLFSSL_CTX* ctx = NULL;
  7720. WOLFSSL* ssl = NULL;
  7721. SOCKET_T sfd = 0;
  7722. SOCKET_T cfd = 0;
  7723. word16 port;
  7724. char msg[] = "I hear you fa shizzle!";
  7725. int len = (int) XSTRLEN(msg);
  7726. char input[1024];
  7727. int idx;
  7728. int ret, err = 0;
  7729. ((func_args*)args)->return_code = TEST_FAIL;
  7730. #if defined(USE_WINDOWS_API)
  7731. port = ((func_args*)args)->signal->port;
  7732. #elif defined(NO_MAIN_DRIVER) && !defined(WOLFSSL_SNIFFER) && \
  7733. !defined(WOLFSSL_MDK_SHELL) && !defined(WOLFSSL_TIRTOS)
  7734. /* Let tcp_listen assign port */
  7735. port = 0;
  7736. #else
  7737. /* Use default port */
  7738. port = wolfSSLPort;
  7739. #endif
  7740. #ifdef WOLFSSL_DTLS
  7741. if (callbacks->method == wolfDTLS_server_method
  7742. #ifdef WOLFSSL_STATIC_MEMORY
  7743. || callbacks->method_ex == wolfDTLS_server_method_ex
  7744. #endif
  7745. #ifndef NO_OLD_TLS
  7746. || callbacks->method == wolfDTLSv1_server_method
  7747. #ifdef WOLFSSL_STATIC_MEMORY
  7748. || callbacks->method_ex == wolfDTLSv1_server_method_ex
  7749. #endif
  7750. #endif
  7751. #ifndef WOLFSSL_NO_TLS12
  7752. || callbacks->method == wolfDTLSv1_2_server_method
  7753. #ifdef WOLFSSL_STATIC_MEMORY
  7754. || callbacks->method_ex == wolfDTLSv1_2_server_method_ex
  7755. #endif
  7756. #endif
  7757. #ifdef WOLFSSL_DTLS13
  7758. || callbacks->method == wolfDTLSv1_3_server_method
  7759. #ifdef WOLFSSL_STATIC_MEMORY
  7760. || callbacks->method_ex == wolfDTLSv1_3_server_method_ex
  7761. #endif
  7762. #endif
  7763. ) {
  7764. tcp_accept(&sfd, &cfd, (func_args*)args, port, 0, 1, 0, 0, 0, 0, 0);
  7765. }
  7766. else
  7767. #endif
  7768. {
  7769. tcp_accept(&sfd, &cfd, (func_args*)args, port, 0, 0, 0, 0, 1, 0, 0);
  7770. }
  7771. #ifdef WOLFSSL_STATIC_MEMORY
  7772. if (callbacks->method_ex != NULL && callbacks->mem != NULL &&
  7773. callbacks->memSz > 0) {
  7774. ret = wolfSSL_CTX_load_static_memory(&ctx, callbacks->method_ex,
  7775. callbacks->mem, callbacks->memSz, 0, 1);
  7776. if (ret != WOLFSSL_SUCCESS) {
  7777. fprintf(stderr, "CTX static new failed %d\n", ret);
  7778. goto cleanup;
  7779. }
  7780. }
  7781. #else
  7782. ctx = wolfSSL_CTX_new(callbacks->method());
  7783. #endif
  7784. if (ctx == NULL) {
  7785. fprintf(stderr, "CTX new failed\n");
  7786. goto cleanup;
  7787. }
  7788. /* set defaults */
  7789. if (callbacks->caPemFile == NULL)
  7790. callbacks->caPemFile = cliCertFile;
  7791. if (callbacks->certPemFile == NULL)
  7792. callbacks->certPemFile = svrCertFile;
  7793. if (callbacks->keyPemFile == NULL)
  7794. callbacks->keyPemFile = svrKeyFile;
  7795. #ifdef WOLFSSL_TIRTOS
  7796. fdOpenSession(Task_self());
  7797. #endif
  7798. wolfSSL_CTX_SetDevId(ctx, callbacks->devId);
  7799. wolfSSL_CTX_set_verify(ctx,
  7800. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  7801. #ifdef WOLFSSL_ENCRYPTED_KEYS
  7802. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  7803. #endif
  7804. #if defined(WOLFSSL_SESSION_EXPORT) && defined(WOLFSSL_DTLS)
  7805. if (callbacks->method == wolfDTLSv1_2_server_method) {
  7806. if (wolfSSL_CTX_dtls_set_export(ctx, test_export) != WOLFSSL_SUCCESS)
  7807. goto cleanup;
  7808. }
  7809. #endif
  7810. if (wolfSSL_CTX_load_verify_locations(ctx, callbacks->caPemFile, 0) !=
  7811. WOLFSSL_SUCCESS) {
  7812. goto cleanup;
  7813. }
  7814. if (wolfSSL_CTX_use_certificate_file(ctx, callbacks->certPemFile,
  7815. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7816. goto cleanup;
  7817. }
  7818. if (wolfSSL_CTX_use_PrivateKey_file(ctx, callbacks->keyPemFile,
  7819. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7820. goto cleanup;
  7821. }
  7822. #ifdef HAVE_CRL
  7823. if (callbacks->crlPemFile != NULL) {
  7824. if (wolfSSL_CTX_LoadCRLFile(ctx, callbacks->crlPemFile,
  7825. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7826. goto cleanup;
  7827. }
  7828. }
  7829. #endif
  7830. if (callbacks->ctx_ready)
  7831. callbacks->ctx_ready(ctx);
  7832. ssl = wolfSSL_new(ctx);
  7833. if (ssl == NULL) {
  7834. fprintf(stderr, "SSL new failed\n");
  7835. goto cleanup;
  7836. }
  7837. if (wolfSSL_dtls(ssl)) {
  7838. SOCKADDR_IN_T cliAddr;
  7839. socklen_t cliLen;
  7840. cliLen = sizeof(cliAddr);
  7841. idx = (int)recvfrom(sfd, input, sizeof(input), MSG_PEEK,
  7842. (struct sockaddr*)&cliAddr, &cliLen);
  7843. if (idx <= 0) {
  7844. goto cleanup;
  7845. }
  7846. wolfSSL_dtls_set_peer(ssl, &cliAddr, cliLen);
  7847. }
  7848. else {
  7849. CloseSocket(sfd);
  7850. }
  7851. if (wolfSSL_set_fd(ssl, cfd) != WOLFSSL_SUCCESS) {
  7852. goto cleanup;
  7853. }
  7854. if (callbacks->loadToSSL) {
  7855. wolfSSL_SetDevId(ssl, callbacks->devId);
  7856. if (wolfSSL_use_certificate_file(ssl, callbacks->certPemFile,
  7857. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7858. goto cleanup;
  7859. }
  7860. if (wolfSSL_use_PrivateKey_file(ssl, callbacks->keyPemFile,
  7861. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  7862. goto cleanup;
  7863. }
  7864. }
  7865. #ifdef NO_PSK
  7866. #if !defined(NO_FILESYSTEM) && !defined(NO_DH)
  7867. wolfSSL_SetTmpDH_file(ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  7868. #elif !defined(NO_DH)
  7869. SetDH(ssl); /* will repick suites with DHE, higher priority than PSK */
  7870. #endif
  7871. #endif
  7872. if (callbacks->ssl_ready)
  7873. callbacks->ssl_ready(ssl);
  7874. #ifdef WOLFSSL_ASYNC_CRYPT
  7875. err = 0; /* Reset error */
  7876. #endif
  7877. do {
  7878. #ifdef WOLFSSL_ASYNC_CRYPT
  7879. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7880. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7881. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7882. }
  7883. #endif
  7884. ret = wolfSSL_accept(ssl);
  7885. err = wolfSSL_get_error(ssl, ret);
  7886. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7887. if (ret != WOLFSSL_SUCCESS) {
  7888. char buff[WOLFSSL_MAX_ERROR_SZ];
  7889. fprintf(stderr, "accept error = %d, %s\n", err,
  7890. wolfSSL_ERR_error_string((word32)err, buff));
  7891. /*err_sys("SSL_accept failed");*/
  7892. }
  7893. else {
  7894. #ifdef WOLFSSL_ASYNC_CRYPT
  7895. err = 0; /* Reset error */
  7896. #endif
  7897. do {
  7898. #ifdef WOLFSSL_ASYNC_CRYPT
  7899. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7900. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7901. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7902. }
  7903. #endif
  7904. idx = wolfSSL_read(ssl, input, sizeof(input)-1);
  7905. err = wolfSSL_get_error(ssl, idx);
  7906. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7907. if (idx > 0) {
  7908. input[idx] = 0;
  7909. fprintf(stderr, "Client message: %s\n", input);
  7910. }
  7911. #ifdef WOLFSSL_ASYNC_CRYPT
  7912. err = 0; /* Reset error */
  7913. #endif
  7914. do {
  7915. #ifdef WOLFSSL_ASYNC_CRYPT
  7916. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  7917. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  7918. if (ret < 0) { break; } else if (ret == 0) { continue; }
  7919. }
  7920. #endif
  7921. ret = wolfSSL_write(ssl, msg, len);
  7922. err = wolfSSL_get_error(ssl, ret);
  7923. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  7924. if (len != ret) {
  7925. goto cleanup;
  7926. }
  7927. #if defined(WOLFSSL_SESSION_EXPORT) && !defined(HAVE_IO_POOL) && \
  7928. defined(WOLFSSL_DTLS)
  7929. if (wolfSSL_dtls(ssl)) {
  7930. byte* import;
  7931. word32 sz;
  7932. wolfSSL_dtls_export(ssl, NULL, &sz);
  7933. import = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  7934. if (import == NULL) {
  7935. goto cleanup;
  7936. }
  7937. idx = wolfSSL_dtls_export(ssl, import, &sz);
  7938. if (idx < 0) {
  7939. goto cleanup;
  7940. }
  7941. if (wolfSSL_dtls_import(ssl, import, idx) < 0) {
  7942. goto cleanup;
  7943. }
  7944. XFREE(import, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  7945. }
  7946. #endif
  7947. #ifdef WOLFSSL_TIRTOS
  7948. Task_yield();
  7949. #endif
  7950. ((func_args*)args)->return_code = TEST_SUCCESS;
  7951. }
  7952. if (callbacks->on_result)
  7953. callbacks->on_result(ssl);
  7954. wolfSSL_shutdown(ssl);
  7955. cleanup:
  7956. wolfSSL_free(ssl);
  7957. wolfSSL_CTX_free(ctx);
  7958. CloseSocket(cfd);
  7959. #ifdef WOLFSSL_TIRTOS
  7960. fdCloseSession(Task_self());
  7961. #endif
  7962. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  7963. && defined(HAVE_THREAD_LS)
  7964. wc_ecc_fp_free(); /* free per thread cache */
  7965. #endif
  7966. WOLFSSL_RETURN_FROM_THREAD(0);
  7967. }
  7968. /* TLS Client for API unit testing - generic */
  7969. static void run_wolfssl_client(void* args)
  7970. {
  7971. callback_functions* callbacks = ((func_args*)args)->callbacks;
  7972. WOLFSSL_CTX* ctx = NULL;
  7973. WOLFSSL* ssl = NULL;
  7974. SOCKET_T sfd = 0;
  7975. char msg[] = "hello wolfssl server!";
  7976. int len = (int) XSTRLEN(msg);
  7977. char input[1024];
  7978. int ret, err = 0;
  7979. ((func_args*)args)->return_code = TEST_FAIL;
  7980. /* set defaults */
  7981. if (callbacks->caPemFile == NULL)
  7982. callbacks->caPemFile = caCertFile;
  7983. if (callbacks->certPemFile == NULL)
  7984. callbacks->certPemFile = cliCertFile;
  7985. if (callbacks->keyPemFile == NULL)
  7986. callbacks->keyPemFile = cliKeyFile;
  7987. #ifdef WOLFSSL_STATIC_MEMORY
  7988. if (callbacks->method_ex != NULL && callbacks->mem != NULL &&
  7989. callbacks->memSz > 0) {
  7990. ret = wolfSSL_CTX_load_static_memory(&ctx, callbacks->method_ex,
  7991. callbacks->mem, callbacks->memSz, 0, 1);
  7992. if (ret != WOLFSSL_SUCCESS) {
  7993. fprintf(stderr, "CTX static new failed %d\n", ret);
  7994. goto cleanup;
  7995. }
  7996. }
  7997. #else
  7998. ctx = wolfSSL_CTX_new(callbacks->method());
  7999. #endif
  8000. if (ctx == NULL) {
  8001. fprintf(stderr, "CTX new failed\n");
  8002. goto cleanup;
  8003. }
  8004. #ifdef WOLFSSL_TIRTOS
  8005. fdOpenSession(Task_self());
  8006. #endif
  8007. if (!callbacks->loadToSSL) {
  8008. wolfSSL_CTX_SetDevId(ctx, callbacks->devId);
  8009. }
  8010. #ifdef WOLFSSL_ENCRYPTED_KEYS
  8011. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  8012. #endif
  8013. if (wolfSSL_CTX_load_verify_locations(ctx, callbacks->caPemFile, 0) !=
  8014. WOLFSSL_SUCCESS) {
  8015. goto cleanup;
  8016. }
  8017. if (!callbacks->loadToSSL) {
  8018. if (wolfSSL_CTX_use_certificate_file(ctx, callbacks->certPemFile,
  8019. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  8020. goto cleanup;
  8021. }
  8022. if (wolfSSL_CTX_use_PrivateKey_file(ctx, callbacks->keyPemFile,
  8023. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  8024. goto cleanup;
  8025. }
  8026. }
  8027. #ifdef HAVE_CRL
  8028. if (callbacks->crlPemFile != NULL) {
  8029. if (wolfSSL_CTX_LoadCRLFile(ctx, callbacks->crlPemFile,
  8030. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  8031. goto cleanup;
  8032. }
  8033. }
  8034. #endif
  8035. if (callbacks->ctx_ready)
  8036. callbacks->ctx_ready(ctx);
  8037. ssl = wolfSSL_new(ctx);
  8038. if (wolfSSL_dtls(ssl)) {
  8039. tcp_connect(&sfd, wolfSSLIP, ((func_args*)args)->signal->port,
  8040. 1, 0, ssl);
  8041. }
  8042. else {
  8043. tcp_connect(&sfd, wolfSSLIP, ((func_args*)args)->signal->port,
  8044. 0, 0, ssl);
  8045. }
  8046. if (wolfSSL_set_fd(ssl, sfd) != WOLFSSL_SUCCESS) {
  8047. goto cleanup;
  8048. }
  8049. if (callbacks->loadToSSL) {
  8050. wolfSSL_SetDevId(ssl, callbacks->devId);
  8051. if (wolfSSL_use_certificate_file(ssl, callbacks->certPemFile,
  8052. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  8053. goto cleanup;
  8054. }
  8055. if (wolfSSL_use_PrivateKey_file(ssl, callbacks->keyPemFile,
  8056. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) {
  8057. goto cleanup;
  8058. }
  8059. }
  8060. if (callbacks->ssl_ready)
  8061. callbacks->ssl_ready(ssl);
  8062. #ifdef WOLFSSL_ASYNC_CRYPT
  8063. err = 0; /* Reset error */
  8064. #endif
  8065. do {
  8066. #ifdef WOLFSSL_ASYNC_CRYPT
  8067. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  8068. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  8069. if (ret < 0) { break; } else if (ret == 0) { continue; }
  8070. }
  8071. #endif
  8072. ret = wolfSSL_connect(ssl);
  8073. err = wolfSSL_get_error(ssl, ret);
  8074. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  8075. if (ret != WOLFSSL_SUCCESS) {
  8076. char buff[WOLFSSL_MAX_ERROR_SZ];
  8077. fprintf(stderr, "error = %d, %s\n", err,
  8078. wolfSSL_ERR_error_string((word32)err, buff));
  8079. /*err_sys("SSL_connect failed");*/
  8080. }
  8081. else {
  8082. #ifdef WOLFSSL_ASYNC_CRYPT
  8083. err = 0; /* Reset error */
  8084. #endif
  8085. do {
  8086. #ifdef WOLFSSL_ASYNC_CRYPT
  8087. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  8088. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  8089. if (ret < 0) { break; } else if (ret == 0) { continue; }
  8090. }
  8091. #endif
  8092. ret = wolfSSL_write(ssl, msg, len);
  8093. err = wolfSSL_get_error(ssl, ret);
  8094. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  8095. if (len != ret)
  8096. goto cleanup;
  8097. #ifdef WOLFSSL_ASYNC_CRYPT
  8098. err = 0; /* Reset error */
  8099. #endif
  8100. do {
  8101. #ifdef WOLFSSL_ASYNC_CRYPT
  8102. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  8103. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  8104. if (ret < 0) { break; } else if (ret == 0) { continue; }
  8105. }
  8106. #endif
  8107. ret = wolfSSL_read(ssl, input, sizeof(input)-1);
  8108. err = wolfSSL_get_error(ssl, ret);
  8109. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  8110. if (ret > 0) {
  8111. input[ret] = '\0'; /* null term */
  8112. fprintf(stderr, "Server response: %s\n", input);
  8113. }
  8114. ((func_args*)args)->return_code = TEST_SUCCESS;
  8115. }
  8116. if (callbacks->on_result)
  8117. callbacks->on_result(ssl);
  8118. cleanup:
  8119. wolfSSL_free(ssl);
  8120. wolfSSL_CTX_free(ctx);
  8121. CloseSocket(sfd);
  8122. #ifdef WOLFSSL_TIRTOS
  8123. fdCloseSession(Task_self());
  8124. #endif
  8125. }
  8126. #endif /* ENABLE_TLS_CALLBACK_TEST */
  8127. static int test_wolfSSL_read_write(void)
  8128. {
  8129. /* The unit testing for read and write shall happen simultaneously, since
  8130. * one can't do anything with one without the other. (Except for a failure
  8131. * test case.) This function will call all the others that will set up,
  8132. * execute, and report their test findings.
  8133. *
  8134. * Set up the success case first. This function will become the template
  8135. * for the other tests. This should eventually be renamed
  8136. *
  8137. * The success case isn't interesting, how can this fail?
  8138. * - Do not give the client context a CA certificate. The connect should
  8139. * fail. Do not need server for this?
  8140. * - Using NULL for the ssl object on server. Do not need client for this.
  8141. * - Using NULL for the ssl object on client. Do not need server for this.
  8142. * - Good ssl objects for client and server. Client write() without server
  8143. * read().
  8144. * - Good ssl objects for client and server. Server write() without client
  8145. * read().
  8146. * - Forgetting the password callback?
  8147. */
  8148. tcp_ready ready;
  8149. func_args client_args;
  8150. func_args server_args;
  8151. THREAD_TYPE serverThread;
  8152. EXPECT_DECLS;
  8153. XMEMSET(&client_args, 0, sizeof(func_args));
  8154. XMEMSET(&server_args, 0, sizeof(func_args));
  8155. #ifdef WOLFSSL_TIRTOS
  8156. fdOpenSession(Task_self());
  8157. #endif
  8158. StartTCP();
  8159. InitTcpReady(&ready);
  8160. #if defined(USE_WINDOWS_API)
  8161. /* use RNG to get random port if using windows */
  8162. ready.port = GetRandomPort();
  8163. #endif
  8164. server_args.signal = &ready;
  8165. client_args.signal = &ready;
  8166. start_thread(test_server_nofail, &server_args, &serverThread);
  8167. wait_tcp_ready(&server_args);
  8168. test_client_nofail(&client_args, NULL);
  8169. join_thread(serverThread);
  8170. ExpectTrue(client_args.return_code);
  8171. ExpectTrue(server_args.return_code);
  8172. FreeTcpReady(&ready);
  8173. #ifdef WOLFSSL_TIRTOS
  8174. fdOpenSession(Task_self());
  8175. #endif
  8176. return EXPECT_RESULT();
  8177. }
  8178. static int test_wolfSSL_reuse_WOLFSSLobj(void)
  8179. {
  8180. EXPECT_DECLS;
  8181. #if defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) && \
  8182. !defined(WOLFSSL_NO_TLS12)
  8183. /* The unit test for session resumption by re-using WOLFSSL object.
  8184. * WOLFSSL object is not cleared after first session. It reuse the object
  8185. * for second connection.
  8186. */
  8187. tcp_ready ready;
  8188. func_args client_args;
  8189. func_args server_args;
  8190. THREAD_TYPE serverThread;
  8191. callback_functions client_cbf;
  8192. callback_functions server_cbf;
  8193. XMEMSET(&client_args, 0, sizeof(func_args));
  8194. XMEMSET(&server_args, 0, sizeof(func_args));
  8195. XMEMSET(&client_cbf, 0, sizeof(callback_functions));
  8196. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  8197. #ifdef WOLFSSL_TIRTOS
  8198. fdOpenSession(Task_self());
  8199. #endif
  8200. StartTCP();
  8201. InitTcpReady(&ready);
  8202. #if defined(USE_WINDOWS_API)
  8203. /* use RNG to get random port if using windows */
  8204. ready.port = GetRandomPort();
  8205. #endif
  8206. client_cbf.method = wolfTLSv1_2_client_method;
  8207. server_cbf.method = wolfTLSv1_2_server_method;
  8208. client_args.callbacks = &client_cbf;
  8209. server_args.callbacks = &server_cbf;
  8210. server_args.signal = &ready;
  8211. client_args.signal = &ready;
  8212. /* the var is used for loop number */
  8213. server_args.argc = 2;
  8214. start_thread(test_server_loop, &server_args, &serverThread);
  8215. wait_tcp_ready(&server_args);
  8216. test_client_reuse_WOLFSSLobj(&client_args, NULL, &server_args);
  8217. join_thread(serverThread);
  8218. ExpectTrue(client_args.return_code);
  8219. ExpectTrue(server_args.return_code);
  8220. FreeTcpReady(&ready);
  8221. #ifdef WOLFSSL_TIRTOS
  8222. fdOpenSession(Task_self());
  8223. #endif
  8224. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) &&
  8225. * !defined(WOLFSSL_TLS13) */
  8226. return EXPECT_RESULT();
  8227. }
  8228. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8229. static int test_wolfSSL_CTX_verifyDepth_ServerClient_1_ctx_ready(
  8230. WOLFSSL_CTX* ctx)
  8231. {
  8232. wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, myVerify);
  8233. myVerifyAction = VERIFY_USE_PREVERFIY;
  8234. wolfSSL_CTX_set_verify_depth(ctx, 2);
  8235. return TEST_SUCCESS;
  8236. }
  8237. #endif
  8238. static int test_wolfSSL_CTX_verifyDepth_ServerClient_1(void)
  8239. {
  8240. EXPECT_DECLS;
  8241. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8242. test_ssl_cbf client_cbf;
  8243. test_ssl_cbf server_cbf;
  8244. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  8245. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  8246. #ifdef WOLFSSL_TLS13
  8247. client_cbf.method = wolfTLSv1_3_client_method;
  8248. #endif /* WOLFSSL_TLS13 */
  8249. client_cbf.ctx_ready =
  8250. test_wolfSSL_CTX_verifyDepth_ServerClient_1_ctx_ready;
  8251. /* test case 1 verify depth is equal to peer chain */
  8252. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  8253. &server_cbf, NULL), TEST_SUCCESS);
  8254. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  8255. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  8256. #endif /* OPENSSL_EXTRA && HAVE_SSL_MEMIO_TESTS_DEPENDENCIES */
  8257. return EXPECT_RESULT();
  8258. }
  8259. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8260. static int test_wolfSSL_CTX_verifyDepth_ServerClient_2_ctx_ready(
  8261. WOLFSSL_CTX* ctx)
  8262. {
  8263. wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, myVerify);
  8264. myVerifyAction = VERIFY_OVERRIDE_ERROR;
  8265. wolfSSL_CTX_set_verify_depth(ctx, 0);
  8266. return TEST_SUCCESS;
  8267. }
  8268. #endif
  8269. static int test_wolfSSL_CTX_verifyDepth_ServerClient_2(void)
  8270. {
  8271. EXPECT_DECLS;
  8272. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8273. test_ssl_cbf client_cbf;
  8274. test_ssl_cbf server_cbf;
  8275. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  8276. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  8277. #ifdef WOLFSSL_TLS13
  8278. client_cbf.method = wolfTLSv1_3_client_method;
  8279. #endif /* WOLFSSL_TLS13 */
  8280. client_cbf.ctx_ready =
  8281. test_wolfSSL_CTX_verifyDepth_ServerClient_2_ctx_ready;
  8282. /* test case 2
  8283. * verify depth is zero, number of peer's chain is 2.
  8284. * verify result becomes MAX_CHAIN_ERROR, but it is overridden in
  8285. * callback.
  8286. */
  8287. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  8288. &server_cbf, NULL), TEST_SUCCESS);
  8289. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  8290. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  8291. #endif /* OPENSSL_EXTRA && HAVE_SSL_MEMIO_TESTS_DEPENDENCIES */
  8292. return EXPECT_RESULT();
  8293. }
  8294. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8295. static int test_wolfSSL_CTX_verifyDepth_ServerClient_3_ctx_ready(
  8296. WOLFSSL_CTX* ctx)
  8297. {
  8298. wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, myVerify);
  8299. myVerifyAction = VERIFY_USE_PREVERFIY;
  8300. wolfSSL_CTX_set_verify_depth(ctx, 0);
  8301. return TEST_SUCCESS;
  8302. }
  8303. #endif
  8304. static int test_wolfSSL_CTX_verifyDepth_ServerClient_3(void)
  8305. {
  8306. EXPECT_DECLS;
  8307. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  8308. test_ssl_cbf client_cbf;
  8309. test_ssl_cbf server_cbf;
  8310. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  8311. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  8312. #ifdef WOLFSSL_TLS13
  8313. client_cbf.method = wolfTLSv1_3_client_method;
  8314. #endif /* WOLFSSL_TLS13 */
  8315. client_cbf.ctx_ready =
  8316. test_wolfSSL_CTX_verifyDepth_ServerClient_3_ctx_ready;
  8317. /* test case 3
  8318. * verify depth is zero, number of peer's chain is 2
  8319. * verify result becomes MAX_CHAIN_ERRO. call-back returns failure.
  8320. * therefore, handshake becomes failure.
  8321. */
  8322. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  8323. &server_cbf, NULL), -1001);
  8324. ExpectIntEQ(client_cbf.return_code, -1000);
  8325. ExpectIntEQ(server_cbf.return_code, -1000);
  8326. ExpectIntEQ(client_cbf.last_err, WC_NO_ERR_TRACE(MAX_CHAIN_ERROR));
  8327. ExpectIntEQ(server_cbf.last_err, WC_NO_ERR_TRACE(FATAL_ERROR));
  8328. #endif /* OPENSSL_EXTRA && HAVE_SSL_MEMIO_TESTS_DEPENDENCIES */
  8329. return EXPECT_RESULT();
  8330. }
  8331. #if defined(OPENSSL_ALL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  8332. !defined(WOLFSSL_NO_TLS12) && \
  8333. defined(HAVE_ECC) && !defined(NO_AES) && !defined(NO_SHA256)
  8334. static int test_wolfSSL_CTX_set_cipher_list_server_ctx_ready(WOLFSSL_CTX* ctx)
  8335. {
  8336. EXPECT_DECLS;
  8337. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx, "DEFAULT:!NULL"));
  8338. return EXPECT_RESULT();
  8339. }
  8340. static int test_wolfSSL_CTX_set_cipher_list_client_ctx_ready(WOLFSSL_CTX* ctx)
  8341. {
  8342. EXPECT_DECLS;
  8343. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctx, "ECDHE-RSA-AES128-SHA256"));
  8344. return EXPECT_RESULT();
  8345. }
  8346. #endif
  8347. static int test_wolfSSL_CTX_set_cipher_list(void)
  8348. {
  8349. EXPECT_DECLS;
  8350. #if defined(OPENSSL_ALL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  8351. defined(HAVE_ECC) && !defined(NO_AES) && !defined(NO_SHA256)
  8352. #if !defined(WOLFSSL_NO_TLS12)
  8353. WOLFSSL_CTX* ctxClient = NULL;
  8354. WOLFSSL* sslClient = NULL;
  8355. test_ssl_cbf client_cbf;
  8356. test_ssl_cbf server_cbf;
  8357. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  8358. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  8359. server_cbf.method = wolfTLSv1_2_server_method;
  8360. server_cbf.ctx_ready = test_wolfSSL_CTX_set_cipher_list_server_ctx_ready;
  8361. client_cbf.method = wolfTLSv1_2_client_method;
  8362. client_cbf.ctx_ready = test_wolfSSL_CTX_set_cipher_list_client_ctx_ready;
  8363. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  8364. &server_cbf, NULL), TEST_SUCCESS);
  8365. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  8366. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  8367. /* check with cipher string that has '+' */
  8368. ExpectNotNull((ctxClient = wolfSSL_CTX_new(wolfTLSv1_2_client_method())));
  8369. /* Use trailing : with nothing to test for ASAN */
  8370. ExpectTrue(wolfSSL_CTX_set_cipher_list(ctxClient, "ECDHE+AESGCM:"));
  8371. ExpectNotNull((sslClient = wolfSSL_new(ctxClient)));
  8372. /* check for the existence of an ECDHE ECDSA cipher suite */
  8373. if (EXPECT_SUCCESS()) {
  8374. int i = 0;
  8375. int found = 0;
  8376. const char* suite;
  8377. WOLF_STACK_OF(WOLFSSL_CIPHER)* sk = NULL;
  8378. WOLFSSL_CIPHER* current;
  8379. ExpectNotNull((sk = wolfSSL_get_ciphers_compat(sslClient)));
  8380. do {
  8381. current = wolfSSL_sk_SSL_CIPHER_value(sk, i++);
  8382. if (current) {
  8383. suite = wolfSSL_CIPHER_get_name(current);
  8384. if (suite && XSTRSTR(suite, "ECDSA")) {
  8385. found = 1;
  8386. break;
  8387. }
  8388. }
  8389. } while (current);
  8390. ExpectIntEQ(found, 1);
  8391. }
  8392. wolfSSL_free(sslClient);
  8393. wolfSSL_CTX_free(ctxClient);
  8394. #endif /* !WOLFSSL_NO_TLS12 */
  8395. #endif
  8396. return EXPECT_RESULT();
  8397. }
  8398. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  8399. defined(WOLFSSL_HAVE_TLS_UNIQUE)
  8400. static int test_wolfSSL_get_finished_client_on_handshake(WOLFSSL_CTX* ctx,
  8401. WOLFSSL* ssl)
  8402. {
  8403. EXPECT_DECLS;
  8404. size_t msg_len;
  8405. (void)ctx;
  8406. /* get_finished test */
  8407. /* 1. get own sent message */
  8408. XMEMSET(client_side_msg1, 0, MD_MAX_SIZE);
  8409. msg_len = wolfSSL_get_finished(ssl, client_side_msg1, MD_MAX_SIZE);
  8410. ExpectIntGE(msg_len, 0);
  8411. /* 2. get peer message */
  8412. XMEMSET(client_side_msg2, 0, MD_MAX_SIZE);
  8413. msg_len = wolfSSL_get_peer_finished(ssl, client_side_msg2, MD_MAX_SIZE);
  8414. ExpectIntGE(msg_len, 0);
  8415. return EXPECT_RESULT();
  8416. }
  8417. #endif
  8418. static int test_wolfSSL_get_finished(void)
  8419. {
  8420. EXPECT_DECLS;
  8421. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  8422. defined(WOLFSSL_HAVE_TLS_UNIQUE)
  8423. test_ssl_cbf client_cbf;
  8424. test_ssl_cbf server_cbf;
  8425. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  8426. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  8427. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  8428. &server_cbf, test_wolfSSL_get_finished_client_on_handshake),
  8429. TEST_SUCCESS);
  8430. /* test received msg vs sent msg */
  8431. ExpectIntEQ(0, XMEMCMP(client_side_msg1, server_side_msg2, MD_MAX_SIZE));
  8432. ExpectIntEQ(0, XMEMCMP(client_side_msg2, server_side_msg1, MD_MAX_SIZE));
  8433. #endif /* HAVE_SSL_MEMIO_TESTS_DEPENDENCIES && WOLFSSL_HAVE_TLS_UNIQUE */
  8434. return EXPECT_RESULT();
  8435. }
  8436. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  8437. !defined(SINGLE_THREADED) && defined(WOLFSSL_TLS13) && \
  8438. !defined(NO_SESSION_CACHE)
  8439. /* Sessions to restore/store */
  8440. static WOLFSSL_SESSION* test_wolfSSL_CTX_add_session_client_sess;
  8441. static WOLFSSL_SESSION* test_wolfSSL_CTX_add_session_server_sess;
  8442. static WOLFSSL_CTX* test_wolfSSL_CTX_add_session_server_ctx;
  8443. static void test_wolfSSL_CTX_add_session_ctx_ready(WOLFSSL_CTX* ctx)
  8444. {
  8445. /* Don't store sessions. Lookup is still enabled. */
  8446. AssertIntEQ(wolfSSL_CTX_set_session_cache_mode(ctx,
  8447. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE), WOLFSSL_SUCCESS);
  8448. #ifdef OPENSSL_EXTRA
  8449. AssertIntEQ(wolfSSL_CTX_get_session_cache_mode(ctx) &
  8450. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE,
  8451. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE);
  8452. #endif
  8453. /* Require both peers to provide certs */
  8454. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8455. }
  8456. static void test_wolfSSL_CTX_add_session_on_result(WOLFSSL* ssl)
  8457. {
  8458. WOLFSSL_SESSION** sess;
  8459. if (wolfSSL_is_server(ssl))
  8460. sess = &test_wolfSSL_CTX_add_session_server_sess;
  8461. else
  8462. sess = &test_wolfSSL_CTX_add_session_client_sess;
  8463. if (*sess == NULL) {
  8464. #ifdef NO_SESSION_CACHE_REF
  8465. AssertNotNull(*sess = wolfSSL_get1_session(ssl));
  8466. #else
  8467. /* Test for backwards compatibility */
  8468. if (wolfSSL_is_server(ssl)) {
  8469. AssertNotNull(*sess = wolfSSL_get1_session(ssl));
  8470. }
  8471. else {
  8472. AssertNotNull(*sess = wolfSSL_get_session(ssl));
  8473. }
  8474. #endif
  8475. /* Now save the session in the internal store to make it available
  8476. * for lookup. For TLS 1.3, we can't save the session without
  8477. * WOLFSSL_TICKET_HAVE_ID because there is no way to retrieve the
  8478. * session from cache. */
  8479. if (wolfSSL_is_server(ssl)
  8480. #ifndef WOLFSSL_TICKET_HAVE_ID
  8481. && wolfSSL_version(ssl) != TLS1_3_VERSION
  8482. #endif
  8483. )
  8484. AssertIntEQ(wolfSSL_CTX_add_session(wolfSSL_get_SSL_CTX(ssl),
  8485. *sess), WOLFSSL_SUCCESS);
  8486. }
  8487. else {
  8488. /* If we have a session retrieved then remaining connections should be
  8489. * resuming on that session */
  8490. AssertIntEQ(wolfSSL_session_reused(ssl), 1);
  8491. }
  8492. /* Save CTX to be able to decrypt tickets */
  8493. if (wolfSSL_is_server(ssl) &&
  8494. test_wolfSSL_CTX_add_session_server_ctx == NULL) {
  8495. AssertNotNull(test_wolfSSL_CTX_add_session_server_ctx
  8496. = wolfSSL_get_SSL_CTX(ssl));
  8497. AssertIntEQ(wolfSSL_CTX_up_ref(wolfSSL_get_SSL_CTX(ssl)),
  8498. WOLFSSL_SUCCESS);
  8499. }
  8500. #ifdef SESSION_CERTS
  8501. #ifndef WOLFSSL_TICKET_HAVE_ID
  8502. if (wolfSSL_version(ssl) != TLS1_3_VERSION &&
  8503. wolfSSL_session_reused(ssl))
  8504. #endif
  8505. {
  8506. /* With WOLFSSL_TICKET_HAVE_ID the peer certs should be available
  8507. * for all connections. TLS 1.3 only has tickets so if we don't
  8508. * include the session id in the ticket then the certificates
  8509. * will not be available on resumption. */
  8510. WOLFSSL_X509* peer = wolfSSL_get_peer_certificate(ssl);
  8511. AssertNotNull(peer);
  8512. wolfSSL_X509_free(peer);
  8513. AssertNotNull(wolfSSL_SESSION_get_peer_chain(*sess));
  8514. #ifdef OPENSSL_EXTRA
  8515. AssertNotNull(SSL_SESSION_get0_peer(*sess));
  8516. #endif
  8517. }
  8518. #endif /* SESSION_CERTS */
  8519. }
  8520. static void test_wolfSSL_CTX_add_session_ssl_ready(WOLFSSL* ssl)
  8521. {
  8522. /* Set the session to reuse for the client */
  8523. AssertIntEQ(wolfSSL_set_session(ssl,
  8524. test_wolfSSL_CTX_add_session_client_sess), WOLFSSL_SUCCESS);
  8525. }
  8526. #endif
  8527. static int test_wolfSSL_CTX_add_session(void)
  8528. {
  8529. EXPECT_DECLS;
  8530. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  8531. !defined(SINGLE_THREADED) && defined(WOLFSSL_TLS13) && \
  8532. !defined(NO_SESSION_CACHE)
  8533. tcp_ready ready;
  8534. func_args client_args;
  8535. func_args server_args;
  8536. THREAD_TYPE serverThread;
  8537. callback_functions client_cb;
  8538. callback_functions server_cb;
  8539. method_provider methods[][2] = {
  8540. #if !defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \
  8541. !defined(NO_DES3))
  8542. /* Without AES there are almost no ciphersuites available. This leads
  8543. * to no ciphersuites being available and an error. */
  8544. { wolfTLSv1_1_client_method, wolfTLSv1_1_server_method },
  8545. #endif
  8546. #ifndef WOLFSSL_NO_TLS12
  8547. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method },
  8548. #endif
  8549. /* Needs the default ticket callback since it is tied to the
  8550. * connection context and this makes it easy to carry over the ticket
  8551. * crypto context between connections */
  8552. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  8553. defined(HAVE_SESSION_TICKET)
  8554. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method },
  8555. #endif
  8556. };
  8557. const size_t methodsLen = sizeof(methods)/sizeof(*methods);
  8558. size_t i, j;
  8559. for (i = 0; i < methodsLen; i++) {
  8560. /* First run creates a connection while the second+ run will attempt
  8561. * to resume the connection. The trick is that the internal cache
  8562. * is turned off. wolfSSL_CTX_add_session should put the session in
  8563. * the cache anyway. */
  8564. test_wolfSSL_CTX_add_session_client_sess = NULL;
  8565. test_wolfSSL_CTX_add_session_server_sess = NULL;
  8566. test_wolfSSL_CTX_add_session_server_ctx = NULL;
  8567. #ifdef NO_SESSION_CACHE_REF
  8568. for (j = 0; j < 4; j++) {
  8569. #else
  8570. /* The session may be overwritten in this case. Do only one resumption
  8571. * to stop this test from failing intermittently. */
  8572. for (j = 0; j < 2; j++) {
  8573. #endif
  8574. #ifdef WOLFSSL_TIRTOS
  8575. fdOpenSession(Task_self());
  8576. #endif
  8577. StartTCP();
  8578. InitTcpReady(&ready);
  8579. XMEMSET(&client_args, 0, sizeof(func_args));
  8580. XMEMSET(&server_args, 0, sizeof(func_args));
  8581. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  8582. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  8583. client_cb.method = methods[i][0];
  8584. server_cb.method = methods[i][1];
  8585. server_args.signal = &ready;
  8586. server_args.callbacks = &server_cb;
  8587. client_args.signal = &ready;
  8588. client_args.callbacks = &client_cb;
  8589. if (test_wolfSSL_CTX_add_session_server_ctx != NULL) {
  8590. server_cb.ctx = test_wolfSSL_CTX_add_session_server_ctx;
  8591. server_cb.isSharedCtx = 1;
  8592. }
  8593. server_cb.ctx_ready = test_wolfSSL_CTX_add_session_ctx_ready;
  8594. client_cb.ctx_ready = test_wolfSSL_CTX_add_session_ctx_ready;
  8595. if (j != 0)
  8596. client_cb.ssl_ready = test_wolfSSL_CTX_add_session_ssl_ready;
  8597. server_cb.on_result = test_wolfSSL_CTX_add_session_on_result;
  8598. client_cb.on_result = test_wolfSSL_CTX_add_session_on_result;
  8599. server_cb.ticNoInit = 1; /* Use default builtin */
  8600. start_thread(test_server_nofail, &server_args, &serverThread);
  8601. wait_tcp_ready(&server_args);
  8602. test_client_nofail(&client_args, NULL);
  8603. join_thread(serverThread);
  8604. ExpectTrue(client_args.return_code);
  8605. ExpectTrue(server_args.return_code);
  8606. FreeTcpReady(&ready);
  8607. if (EXPECT_FAIL())
  8608. break;
  8609. }
  8610. wolfSSL_SESSION_free(test_wolfSSL_CTX_add_session_client_sess);
  8611. wolfSSL_SESSION_free(test_wolfSSL_CTX_add_session_server_sess);
  8612. wolfSSL_CTX_free(test_wolfSSL_CTX_add_session_server_ctx);
  8613. if (EXPECT_FAIL())
  8614. break;
  8615. }
  8616. #endif
  8617. return EXPECT_RESULT();
  8618. }
  8619. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  8620. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  8621. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  8622. defined(HAVE_SESSION_TICKET) && \
  8623. !defined(TITAN_SESSION_CACHE) && \
  8624. !defined(HUGE_SESSION_CACHE) && \
  8625. !defined(BIG_SESSION_CACHE) && \
  8626. !defined(MEDIUM_SESSION_CACHE)
  8627. /* twcase - prefix for test_wolfSSL_CTX_add_session_ext */
  8628. /* Sessions to restore/store */
  8629. static WOLFSSL_SESSION* twcase_server_first_session_ptr;
  8630. static WOLFSSL_SESSION* twcase_client_first_session_ptr;
  8631. static WOLFSSL_CTX* twcase_server_current_ctx_ptr;
  8632. static int twcase_new_session_called = 0;
  8633. static int twcase_remove_session_called = 0;
  8634. static int twcase_get_session_called = 0;
  8635. /* Test default, SESSIONS_PER_ROW*SESSION_ROWS = 3*11, see ssl.c */
  8636. #define SESSION_CACHE_SIZE 33
  8637. typedef struct {
  8638. const byte* key; /* key, altSessionID, session ID, NULL if empty */
  8639. WOLFSSL_SESSION* value;
  8640. } hashTable_entry;
  8641. typedef struct {
  8642. hashTable_entry entries[SESSION_CACHE_SIZE]; /* hash slots */
  8643. size_t capacity; /* size of entries */
  8644. size_t length; /* number of items in the hash table */
  8645. wolfSSL_Mutex htLock; /* lock */
  8646. }hashTable;
  8647. static hashTable server_sessionCache;
  8648. static int twcase_new_sessionCb(WOLFSSL *ssl, WOLFSSL_SESSION *sess)
  8649. {
  8650. int i;
  8651. unsigned int len;
  8652. (void)ssl;
  8653. /*
  8654. * This example uses a hash table.
  8655. * Steps you should take for a non-demo code:
  8656. * - acquire a lock for the file named according to the session id
  8657. * - open the file
  8658. * - encrypt and write the SSL_SESSION object to the file
  8659. * - release the lock
  8660. *
  8661. * Return:
  8662. * 0: The callback does not wish to hold a reference of the sess
  8663. * 1: The callback wants to hold a reference of the sess. The callback is
  8664. * now also responsible for calling wolfSSL_SESSION_free() on sess.
  8665. */
  8666. if (sess == NULL)
  8667. return 0;
  8668. if (wc_LockMutex(&server_sessionCache.htLock) != 0) {
  8669. return 0;
  8670. }
  8671. for (i = 0; i < SESSION_CACHE_SIZE; i++) {
  8672. if (server_sessionCache.entries[i].value == NULL) {
  8673. server_sessionCache.entries[i].key = SSL_SESSION_get_id(sess, &len);
  8674. server_sessionCache.entries[i].value = sess;
  8675. server_sessionCache.length++;
  8676. break;
  8677. }
  8678. }
  8679. ++twcase_new_session_called;
  8680. wc_UnLockMutex(&server_sessionCache.htLock);
  8681. fprintf(stderr, "\t\ttwcase_new_session_called %d\n",
  8682. twcase_new_session_called);
  8683. return 1;
  8684. }
  8685. static void twcase_remove_sessionCb(WOLFSSL_CTX *ctx, WOLFSSL_SESSION *sess)
  8686. {
  8687. int i;
  8688. (void)ctx;
  8689. (void)sess;
  8690. if (sess == NULL)
  8691. return;
  8692. /*
  8693. * This example uses a hash table.
  8694. * Steps you should take for a non-demo code:
  8695. * - acquire a lock for the file named according to the session id
  8696. * - remove the file
  8697. * - release the lock
  8698. */
  8699. if (wc_LockMutex(&server_sessionCache.htLock) != 0) {
  8700. return;
  8701. }
  8702. for (i = 0; i < SESSION_CACHE_SIZE; i++) {
  8703. if (server_sessionCache.entries[i].key != NULL &&
  8704. XMEMCMP(server_sessionCache.entries[i].key,
  8705. sess->sessionID, SSL_MAX_SSL_SESSION_ID_LENGTH) == 0) {
  8706. wolfSSL_SESSION_free(server_sessionCache.entries[i].value);
  8707. server_sessionCache.entries[i].value = NULL;
  8708. server_sessionCache.entries[i].key = NULL;
  8709. server_sessionCache.length--;
  8710. break;
  8711. }
  8712. }
  8713. ++twcase_remove_session_called;
  8714. wc_UnLockMutex(&server_sessionCache.htLock);
  8715. fprintf(stderr, "\t\ttwcase_remove_session_called %d\n",
  8716. twcase_remove_session_called);
  8717. }
  8718. static WOLFSSL_SESSION *twcase_get_sessionCb(WOLFSSL *ssl,
  8719. const unsigned char *id, int len, int *ref)
  8720. {
  8721. int i;
  8722. (void)ssl;
  8723. (void)id;
  8724. (void)len;
  8725. /*
  8726. * This example uses a hash table.
  8727. * Steps you should take for a non-demo code:
  8728. * - acquire a lock for the file named according to the session id in the
  8729. * 2nd arg
  8730. * - read and decrypt contents of file and create a new SSL_SESSION
  8731. * - object release the lock
  8732. * - return the new session object
  8733. */
  8734. fprintf(stderr, "\t\ttwcase_get_session_called %d\n",
  8735. ++twcase_get_session_called);
  8736. /* This callback want to retain a copy of the object. If we want wolfSSL to
  8737. * be responsible for the pointer then set to 0. */
  8738. *ref = 1;
  8739. for (i = 0; i < SESSION_CACHE_SIZE; i++) {
  8740. if (server_sessionCache.entries[i].key != NULL &&
  8741. XMEMCMP(server_sessionCache.entries[i].key, id,
  8742. SSL_MAX_SSL_SESSION_ID_LENGTH) == 0) {
  8743. return server_sessionCache.entries[i].value;
  8744. }
  8745. }
  8746. return NULL;
  8747. }
  8748. static int twcase_get_sessionCb_cleanup(void)
  8749. {
  8750. int i;
  8751. int cnt = 0;
  8752. /* If twcase_get_sessionCb sets *ref = 1, the application is responsible
  8753. * for freeing sessions */
  8754. for (i = 0; i < SESSION_CACHE_SIZE; i++) {
  8755. if (server_sessionCache.entries[i].value != NULL) {
  8756. wolfSSL_SESSION_free(server_sessionCache.entries[i].value);
  8757. cnt++;
  8758. }
  8759. }
  8760. fprintf(stderr, "\t\ttwcase_get_sessionCb_cleanup freed %d sessions\n",
  8761. cnt);
  8762. return TEST_SUCCESS;
  8763. }
  8764. static int twcase_cache_intOff_extOff(WOLFSSL_CTX* ctx)
  8765. {
  8766. EXPECT_DECLS;
  8767. /* off - Disable internal cache */
  8768. ExpectIntEQ(wolfSSL_CTX_set_session_cache_mode(ctx,
  8769. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE), WOLFSSL_SUCCESS);
  8770. #ifdef OPENSSL_EXTRA
  8771. ExpectIntEQ(wolfSSL_CTX_get_session_cache_mode(ctx) &
  8772. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE,
  8773. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE);
  8774. #endif
  8775. /* off - Do not setup external cache */
  8776. /* Require both peers to provide certs */
  8777. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8778. return EXPECT_RESULT();
  8779. }
  8780. static int twcase_cache_intOn_extOff(WOLFSSL_CTX* ctx)
  8781. {
  8782. /* on - internal cache is on by default */
  8783. /* off - Do not setup external cache */
  8784. /* Require both peers to provide certs */
  8785. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8786. return TEST_SUCCESS;
  8787. }
  8788. static int twcase_cache_intOff_extOn(WOLFSSL_CTX* ctx)
  8789. {
  8790. EXPECT_DECLS;
  8791. /* off - Disable internal cache */
  8792. ExpectIntEQ(wolfSSL_CTX_set_session_cache_mode(ctx,
  8793. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE), WOLFSSL_SUCCESS);
  8794. #ifdef OPENSSL_EXTRA
  8795. ExpectIntEQ(wolfSSL_CTX_get_session_cache_mode(ctx) &
  8796. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE,
  8797. WOLFSSL_SESS_CACHE_NO_INTERNAL_STORE);
  8798. #endif
  8799. /* on - Enable external cache */
  8800. wolfSSL_CTX_sess_set_new_cb(ctx, twcase_new_sessionCb);
  8801. wolfSSL_CTX_sess_set_remove_cb(ctx, twcase_remove_sessionCb);
  8802. wolfSSL_CTX_sess_set_get_cb(ctx, twcase_get_sessionCb);
  8803. /* Require both peers to provide certs */
  8804. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8805. return EXPECT_RESULT();
  8806. }
  8807. static int twcase_cache_intOn_extOn(WOLFSSL_CTX* ctx)
  8808. {
  8809. /* on - internal cache is on by default */
  8810. /* on - Enable external cache */
  8811. wolfSSL_CTX_sess_set_new_cb(ctx, twcase_new_sessionCb);
  8812. wolfSSL_CTX_sess_set_remove_cb(ctx, twcase_remove_sessionCb);
  8813. wolfSSL_CTX_sess_set_get_cb(ctx, twcase_get_sessionCb);
  8814. /* Require both peers to provide certs */
  8815. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8816. return TEST_SUCCESS;
  8817. }
  8818. static int twcase_cache_intOn_extOn_noTicket(WOLFSSL_CTX* ctx)
  8819. {
  8820. /* on - internal cache is on by default */
  8821. /* on - Enable external cache */
  8822. wolfSSL_CTX_sess_set_new_cb(ctx, twcase_new_sessionCb);
  8823. wolfSSL_CTX_sess_set_remove_cb(ctx, twcase_remove_sessionCb);
  8824. wolfSSL_CTX_sess_set_get_cb(ctx, twcase_get_sessionCb);
  8825. wolfSSL_CTX_set_options(ctx, WOLFSSL_OP_NO_TICKET);
  8826. /* Require both peers to provide certs */
  8827. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  8828. return TEST_SUCCESS;
  8829. }
  8830. static int twcase_server_sess_ctx_pre_shutdown(WOLFSSL* ssl)
  8831. {
  8832. EXPECT_DECLS;
  8833. WOLFSSL_SESSION** sess;
  8834. if (wolfSSL_is_server(ssl))
  8835. sess = &twcase_server_first_session_ptr;
  8836. else
  8837. return TEST_SUCCESS;
  8838. if (*sess == NULL) {
  8839. ExpectNotNull(*sess = wolfSSL_get1_session(ssl));
  8840. /* Now save the session in the internal store to make it available
  8841. * for lookup. For TLS 1.3, we can't save the session without
  8842. * WOLFSSL_TICKET_HAVE_ID because there is no way to retrieve the
  8843. * session from cache. */
  8844. if (wolfSSL_is_server(ssl)
  8845. #ifndef WOLFSSL_TICKET_HAVE_ID
  8846. && wolfSSL_version(ssl) != TLS1_3_VERSION
  8847. && wolfSSL_version(ssl) != DTLS1_3_VERSION
  8848. #endif
  8849. ) {
  8850. ExpectIntEQ(wolfSSL_CTX_add_session(wolfSSL_get_SSL_CTX(ssl),
  8851. *sess), WOLFSSL_SUCCESS);
  8852. }
  8853. }
  8854. /* Save CTX to be able to decrypt tickets */
  8855. if (twcase_server_current_ctx_ptr == NULL) {
  8856. ExpectNotNull(twcase_server_current_ctx_ptr = wolfSSL_get_SSL_CTX(ssl));
  8857. ExpectIntEQ(wolfSSL_CTX_up_ref(wolfSSL_get_SSL_CTX(ssl)),
  8858. WOLFSSL_SUCCESS);
  8859. }
  8860. #ifdef SESSION_CERTS
  8861. #ifndef WOLFSSL_TICKET_HAVE_ID
  8862. if (wolfSSL_version(ssl) != TLS1_3_VERSION &&
  8863. wolfSSL_session_reused(ssl))
  8864. #endif
  8865. {
  8866. /* With WOLFSSL_TICKET_HAVE_ID the peer certs should be available
  8867. * for all connections. TLS 1.3 only has tickets so if we don't
  8868. * include the session id in the ticket then the certificates
  8869. * will not be available on resumption. */
  8870. WOLFSSL_X509* peer = NULL;
  8871. ExpectNotNull(peer = wolfSSL_get_peer_certificate(ssl));
  8872. wolfSSL_X509_free(peer);
  8873. ExpectNotNull(wolfSSL_SESSION_get_peer_chain(*sess));
  8874. }
  8875. #endif
  8876. return EXPECT_RESULT();
  8877. }
  8878. static int twcase_client_sess_ctx_pre_shutdown(WOLFSSL* ssl)
  8879. {
  8880. EXPECT_DECLS;
  8881. WOLFSSL_SESSION** sess;
  8882. sess = &twcase_client_first_session_ptr;
  8883. if (*sess == NULL) {
  8884. ExpectNotNull(*sess = wolfSSL_get1_session(ssl));
  8885. }
  8886. else {
  8887. /* If we have a session retrieved then remaining connections should be
  8888. * resuming on that session */
  8889. ExpectIntEQ(wolfSSL_session_reused(ssl), 1);
  8890. }
  8891. #ifdef SESSION_CERTS
  8892. #ifndef WOLFSSL_TICKET_HAVE_ID
  8893. if (wolfSSL_version(ssl) != TLS1_3_VERSION &&
  8894. wolfSSL_session_reused(ssl))
  8895. #endif
  8896. {
  8897. WOLFSSL_X509* peer = wolfSSL_get_peer_certificate(ssl);
  8898. ExpectNotNull(peer);
  8899. wolfSSL_X509_free(peer);
  8900. ExpectNotNull(wolfSSL_SESSION_get_peer_chain(*sess));
  8901. #ifdef OPENSSL_EXTRA
  8902. ExpectNotNull(wolfSSL_SESSION_get0_peer(*sess));
  8903. #endif
  8904. }
  8905. #endif
  8906. return EXPECT_RESULT();
  8907. }
  8908. static int twcase_client_set_sess_ssl_ready(WOLFSSL* ssl)
  8909. {
  8910. EXPECT_DECLS;
  8911. /* Set the session to reuse for the client */
  8912. ExpectNotNull(ssl);
  8913. ExpectNotNull(twcase_client_first_session_ptr);
  8914. ExpectIntEQ(wolfSSL_set_session(ssl,twcase_client_first_session_ptr),
  8915. WOLFSSL_SUCCESS);
  8916. return EXPECT_RESULT();
  8917. }
  8918. struct test_add_session_ext_params {
  8919. method_provider client_meth;
  8920. method_provider server_meth;
  8921. const char* tls_version;
  8922. };
  8923. static int test_wolfSSL_CTX_add_session_ext(
  8924. struct test_add_session_ext_params* param)
  8925. {
  8926. EXPECT_DECLS;
  8927. /* Test the default 33 sessions */
  8928. int j;
  8929. /* Clear cache before starting */
  8930. wolfSSL_CTX_flush_sessions(NULL, -1);
  8931. XMEMSET(&server_sessionCache, 0, sizeof(hashTable));
  8932. if (wc_InitMutex(&server_sessionCache.htLock) != 0)
  8933. return BAD_MUTEX_E;
  8934. server_sessionCache.capacity = SESSION_CACHE_SIZE;
  8935. fprintf(stderr, "\tBegin %s\n", param->tls_version);
  8936. for (j = 0; j < 5; j++) {
  8937. int tls13 = XSTRSTR(param->tls_version, "TLSv1_3") != NULL;
  8938. int dtls = XSTRSTR(param->tls_version, "DTLS") != NULL;
  8939. test_ssl_cbf client_cb;
  8940. test_ssl_cbf server_cb;
  8941. (void)dtls;
  8942. /* Test five cache configurations */
  8943. twcase_client_first_session_ptr = NULL;
  8944. twcase_server_first_session_ptr = NULL;
  8945. twcase_server_current_ctx_ptr = NULL;
  8946. twcase_new_session_called = 0;
  8947. twcase_remove_session_called = 0;
  8948. twcase_get_session_called = 0;
  8949. /* connection 1 - first connection */
  8950. fprintf(stderr, "\tconnect: %s: j=%d\n", param->tls_version, j);
  8951. XMEMSET(&client_cb, 0, sizeof(client_cb));
  8952. XMEMSET(&server_cb, 0, sizeof(server_cb));
  8953. client_cb.method = param->client_meth;
  8954. server_cb.method = param->server_meth;
  8955. if (dtls)
  8956. client_cb.doUdp = server_cb.doUdp = 1;
  8957. /* Setup internal and external cache */
  8958. switch (j) {
  8959. case 0:
  8960. /* SSL_OP_NO_TICKET stateful ticket case */
  8961. server_cb.ctx_ready = twcase_cache_intOn_extOn_noTicket;
  8962. break;
  8963. case 1:
  8964. server_cb.ctx_ready = twcase_cache_intOn_extOn;
  8965. break;
  8966. case 2:
  8967. server_cb.ctx_ready = twcase_cache_intOff_extOn;
  8968. break;
  8969. case 3:
  8970. server_cb.ctx_ready = twcase_cache_intOn_extOff;
  8971. break;
  8972. case 4:
  8973. server_cb.ctx_ready = twcase_cache_intOff_extOff;
  8974. break;
  8975. }
  8976. client_cb.ctx_ready = twcase_cache_intOff_extOff;
  8977. /* Add session to internal cache and save SSL session for testing */
  8978. server_cb.on_result = twcase_server_sess_ctx_pre_shutdown;
  8979. /* Save client SSL session for testing */
  8980. client_cb.on_result = twcase_client_sess_ctx_pre_shutdown;
  8981. server_cb.ticNoInit = 1; /* Use default builtin */
  8982. /* Don't free/release ctx */
  8983. server_cb.ctx = twcase_server_current_ctx_ptr;
  8984. server_cb.isSharedCtx = 1;
  8985. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb,
  8986. &server_cb, NULL), TEST_SUCCESS);
  8987. ExpectIntEQ(twcase_get_session_called, 0);
  8988. if (EXPECT_FAIL()) {
  8989. wolfSSL_SESSION_free(twcase_client_first_session_ptr);
  8990. wolfSSL_SESSION_free(twcase_server_first_session_ptr);
  8991. wolfSSL_CTX_free(twcase_server_current_ctx_ptr);
  8992. break;
  8993. }
  8994. switch (j) {
  8995. case 0:
  8996. case 1:
  8997. case 2:
  8998. /* cache cannot be searched with out a connection */
  8999. /* Add a new session */
  9000. ExpectIntEQ(twcase_new_session_called, 1);
  9001. /* In twcase_server_sess_ctx_pre_shutdown
  9002. * wolfSSL_CTX_add_session which evicts the existing session
  9003. * in cache and adds it back in */
  9004. ExpectIntLE(twcase_remove_session_called, 1);
  9005. break;
  9006. case 3:
  9007. case 4:
  9008. /* no external cache */
  9009. ExpectIntEQ(twcase_new_session_called, 0);
  9010. ExpectIntEQ(twcase_remove_session_called, 0);
  9011. break;
  9012. }
  9013. /* connection 2 - session resume */
  9014. fprintf(stderr, "\tresume: %s: j=%d\n", param->tls_version, j);
  9015. twcase_new_session_called = 0;
  9016. twcase_remove_session_called = 0;
  9017. twcase_get_session_called = 0;
  9018. server_cb.on_result = 0;
  9019. client_cb.on_result = 0;
  9020. server_cb.ticNoInit = 1; /* Use default builtin */
  9021. server_cb.ctx = twcase_server_current_ctx_ptr;
  9022. /* try session resumption */
  9023. client_cb.ssl_ready = twcase_client_set_sess_ssl_ready;
  9024. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb,
  9025. &server_cb, NULL), TEST_SUCCESS);
  9026. /* Clear cache before checking */
  9027. wolfSSL_CTX_flush_sessions(NULL, -1);
  9028. switch (j) {
  9029. case 0:
  9030. if (tls13) {
  9031. /* (D)TLSv1.3 stateful case */
  9032. /* cache hit */
  9033. /* DTLS accesses cache once for stateless parsing and
  9034. * once for stateful parsing */
  9035. ExpectIntEQ(twcase_get_session_called, !dtls ? 1 : 2);
  9036. /* (D)TLSv1.3 creates a new ticket,
  9037. * updates both internal and external cache */
  9038. ExpectIntEQ(twcase_new_session_called, 1);
  9039. /* A new session ID is created for a new ticket */
  9040. ExpectIntEQ(twcase_remove_session_called, 2);
  9041. }
  9042. else {
  9043. /* non (D)TLSv1.3 case, no update */
  9044. /* DTLS accesses cache once for stateless parsing and
  9045. * once for stateful parsing */
  9046. #ifdef WOLFSSL_DTLS_NO_HVR_ON_RESUME
  9047. ExpectIntEQ(twcase_get_session_called, !dtls ? 1 : 2);
  9048. #else
  9049. ExpectIntEQ(twcase_get_session_called, 1);
  9050. #endif
  9051. ExpectIntEQ(twcase_new_session_called, 0);
  9052. /* Called on session added in
  9053. * twcase_server_sess_ctx_pre_shutdown */
  9054. ExpectIntEQ(twcase_remove_session_called, 1);
  9055. }
  9056. break;
  9057. case 1:
  9058. if (tls13) {
  9059. /* (D)TLSv1.3 case */
  9060. /* cache hit */
  9061. ExpectIntEQ(twcase_get_session_called, 1);
  9062. /* (D)TLSv1.3 creates a new ticket,
  9063. * updates both internal and external cache */
  9064. ExpectIntEQ(twcase_new_session_called, 1);
  9065. /* Called on session added in
  9066. * twcase_server_sess_ctx_pre_shutdown and by wolfSSL */
  9067. ExpectIntEQ(twcase_remove_session_called, 1);
  9068. }
  9069. else {
  9070. /* non (D)TLSv1.3 case */
  9071. /* cache hit */
  9072. /* DTLS accesses cache once for stateless parsing and
  9073. * once for stateful parsing */
  9074. #ifdef WOLFSSL_DTLS_NO_HVR_ON_RESUME
  9075. ExpectIntEQ(twcase_get_session_called, !dtls ? 1 : 2);
  9076. #else
  9077. ExpectIntEQ(twcase_get_session_called, 1);
  9078. #endif
  9079. ExpectIntEQ(twcase_new_session_called, 0);
  9080. /* Called on session added in
  9081. * twcase_server_sess_ctx_pre_shutdown */
  9082. ExpectIntEQ(twcase_remove_session_called, 1);
  9083. }
  9084. break;
  9085. case 2:
  9086. if (tls13) {
  9087. /* (D)TLSv1.3 case */
  9088. /* cache hit */
  9089. ExpectIntEQ(twcase_get_session_called, 1);
  9090. /* (D)TLSv1.3 creates a new ticket,
  9091. * updates both internal and external cache */
  9092. ExpectIntEQ(twcase_new_session_called, 1);
  9093. /* Called on session added in
  9094. * twcase_server_sess_ctx_pre_shutdown and by wolfSSL */
  9095. ExpectIntEQ(twcase_remove_session_called, 1);
  9096. }
  9097. else {
  9098. /* non (D)TLSv1.3 case */
  9099. /* cache hit */
  9100. /* DTLS accesses cache once for stateless parsing and
  9101. * once for stateful parsing */
  9102. #ifdef WOLFSSL_DTLS_NO_HVR_ON_RESUME
  9103. ExpectIntEQ(twcase_get_session_called, !dtls ? 1 : 2);
  9104. #else
  9105. ExpectIntEQ(twcase_get_session_called, 1);
  9106. #endif
  9107. ExpectIntEQ(twcase_new_session_called, 0);
  9108. /* Called on session added in
  9109. * twcase_server_sess_ctx_pre_shutdown */
  9110. ExpectIntEQ(twcase_remove_session_called, 1);
  9111. }
  9112. break;
  9113. case 3:
  9114. case 4:
  9115. /* no external cache */
  9116. ExpectIntEQ(twcase_get_session_called, 0);
  9117. ExpectIntEQ(twcase_new_session_called, 0);
  9118. ExpectIntEQ(twcase_remove_session_called, 0);
  9119. break;
  9120. }
  9121. wolfSSL_SESSION_free(twcase_client_first_session_ptr);
  9122. wolfSSL_SESSION_free(twcase_server_first_session_ptr);
  9123. wolfSSL_CTX_free(twcase_server_current_ctx_ptr);
  9124. if (EXPECT_FAIL())
  9125. break;
  9126. }
  9127. twcase_get_sessionCb_cleanup();
  9128. XMEMSET(&server_sessionCache.entries, 0,
  9129. sizeof(server_sessionCache.entries));
  9130. fprintf(stderr, "\tEnd %s\n", param->tls_version);
  9131. wc_FreeMutex(&server_sessionCache.htLock);
  9132. return EXPECT_RESULT();
  9133. }
  9134. #endif
  9135. static int test_wolfSSL_CTX_add_session_ext_tls13(void)
  9136. {
  9137. EXPECT_DECLS;
  9138. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  9139. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  9140. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  9141. defined(HAVE_SESSION_TICKET) && \
  9142. !defined(TITAN_SESSION_CACHE) && \
  9143. !defined(HUGE_SESSION_CACHE) && \
  9144. !defined(BIG_SESSION_CACHE) && \
  9145. !defined(MEDIUM_SESSION_CACHE)
  9146. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  9147. defined(HAVE_SESSION_TICKET) && defined(WOLFSSL_TICKET_HAVE_ID)
  9148. struct test_add_session_ext_params param[1] = {
  9149. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLSv1_3" }
  9150. };
  9151. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  9152. #endif
  9153. #endif
  9154. return EXPECT_RESULT();
  9155. }
  9156. static int test_wolfSSL_CTX_add_session_ext_dtls13(void)
  9157. {
  9158. EXPECT_DECLS;
  9159. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  9160. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  9161. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  9162. defined(HAVE_SESSION_TICKET) && \
  9163. !defined(TITAN_SESSION_CACHE) && \
  9164. !defined(HUGE_SESSION_CACHE) && \
  9165. !defined(BIG_SESSION_CACHE) && \
  9166. !defined(MEDIUM_SESSION_CACHE)
  9167. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  9168. defined(HAVE_SESSION_TICKET) && defined(WOLFSSL_TICKET_HAVE_ID)
  9169. #ifdef WOLFSSL_DTLS13
  9170. struct test_add_session_ext_params param[1] = {
  9171. { wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, "DTLSv1_3" }
  9172. };
  9173. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  9174. #endif
  9175. #endif
  9176. #endif
  9177. return EXPECT_RESULT();
  9178. }
  9179. static int test_wolfSSL_CTX_add_session_ext_tls12(void)
  9180. {
  9181. EXPECT_DECLS;
  9182. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  9183. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  9184. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  9185. defined(HAVE_SESSION_TICKET) && \
  9186. !defined(TITAN_SESSION_CACHE) && \
  9187. !defined(HUGE_SESSION_CACHE) && \
  9188. !defined(BIG_SESSION_CACHE) && \
  9189. !defined(MEDIUM_SESSION_CACHE)
  9190. #ifndef WOLFSSL_NO_TLS12
  9191. struct test_add_session_ext_params param[1] = {
  9192. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLSv1_2" }
  9193. };
  9194. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  9195. #endif
  9196. #endif
  9197. return EXPECT_RESULT();
  9198. }
  9199. static int test_wolfSSL_CTX_add_session_ext_dtls12(void)
  9200. {
  9201. EXPECT_DECLS;
  9202. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  9203. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  9204. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  9205. defined(HAVE_SESSION_TICKET) && \
  9206. !defined(TITAN_SESSION_CACHE) && \
  9207. !defined(HUGE_SESSION_CACHE) && \
  9208. !defined(BIG_SESSION_CACHE) && \
  9209. !defined(MEDIUM_SESSION_CACHE)
  9210. #ifndef WOLFSSL_NO_TLS12
  9211. #ifdef WOLFSSL_DTLS
  9212. struct test_add_session_ext_params param[1] = {
  9213. { wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, "DTLSv1_2" }
  9214. };
  9215. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  9216. #endif
  9217. #endif
  9218. #endif
  9219. return EXPECT_RESULT();
  9220. }
  9221. static int test_wolfSSL_CTX_add_session_ext_tls11(void)
  9222. {
  9223. EXPECT_DECLS;
  9224. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  9225. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  9226. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  9227. defined(HAVE_SESSION_TICKET) && \
  9228. !defined(TITAN_SESSION_CACHE) && \
  9229. !defined(HUGE_SESSION_CACHE) && \
  9230. !defined(BIG_SESSION_CACHE) && \
  9231. !defined(MEDIUM_SESSION_CACHE)
  9232. #if !defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \
  9233. !defined(NO_DES3))
  9234. struct test_add_session_ext_params param[1] = {
  9235. { wolfTLSv1_1_client_method, wolfTLSv1_1_server_method, "TLSv1_1" }
  9236. };
  9237. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  9238. #endif
  9239. #endif
  9240. return EXPECT_RESULT();
  9241. }
  9242. static int test_wolfSSL_CTX_add_session_ext_dtls1(void)
  9243. {
  9244. EXPECT_DECLS;
  9245. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_EXT_CACHE) && \
  9246. defined(WOLFSSL_TLS13) && !defined(NO_SESSION_CACHE) && \
  9247. defined(OPENSSL_EXTRA) && defined(SESSION_CERTS) && \
  9248. defined(HAVE_SESSION_TICKET) && \
  9249. !defined(TITAN_SESSION_CACHE) && \
  9250. !defined(HUGE_SESSION_CACHE) && \
  9251. !defined(BIG_SESSION_CACHE) && \
  9252. !defined(MEDIUM_SESSION_CACHE)
  9253. #if !defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \
  9254. !defined(NO_DES3))
  9255. #ifdef WOLFSSL_DTLS
  9256. struct test_add_session_ext_params param[1] = {
  9257. { wolfDTLSv1_client_method, wolfDTLSv1_server_method, "DTLSv1_0" }
  9258. };
  9259. ExpectIntEQ(test_wolfSSL_CTX_add_session_ext(param), TEST_SUCCESS);
  9260. #endif
  9261. #endif
  9262. #endif
  9263. return EXPECT_RESULT();
  9264. }
  9265. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT)
  9266. /* canned export of a session using older version 3 */
  9267. static unsigned char version_3[] = {
  9268. 0xA5, 0xA3, 0x01, 0x88, 0x00, 0x3c, 0x00, 0x01,
  9269. 0x00, 0x00, 0x00, 0x80, 0x0C, 0x00, 0x00, 0x00,
  9270. 0x00, 0x80, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00,
  9271. 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
  9272. 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  9273. 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9274. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x30,
  9275. 0x05, 0x09, 0x0A, 0x01, 0x01, 0x00, 0x0D, 0x05,
  9276. 0xFE, 0xFD, 0x01, 0x25, 0x00, 0x00, 0x00, 0x00,
  9277. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9278. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
  9279. 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00,
  9280. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9281. 0x00, 0x06, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00,
  9282. 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
  9283. 0x00, 0x06, 0x00, 0x01, 0x00, 0x07, 0x00, 0x00,
  9284. 0x00, 0x30, 0x00, 0x00, 0x00, 0x10, 0x01, 0x01,
  9285. 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
  9286. 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x3F,
  9287. 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00,
  9288. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9289. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9290. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9291. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9292. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9293. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9294. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9295. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9296. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9297. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9298. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9299. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x05,
  9300. 0x12, 0xCF, 0x22, 0xA1, 0x9F, 0x1C, 0x39, 0x1D,
  9301. 0x31, 0x11, 0x12, 0x1D, 0x11, 0x18, 0x0D, 0x0B,
  9302. 0xF3, 0xE1, 0x4D, 0xDC, 0xB1, 0xF1, 0x39, 0x98,
  9303. 0x91, 0x6C, 0x48, 0xE5, 0xED, 0x11, 0x12, 0xA0,
  9304. 0x00, 0xF2, 0x25, 0x4C, 0x09, 0x26, 0xD1, 0x74,
  9305. 0xDF, 0x23, 0x40, 0x15, 0x6A, 0x42, 0x2A, 0x26,
  9306. 0xA5, 0xAC, 0x56, 0xD5, 0x4A, 0x20, 0xB7, 0xE9,
  9307. 0xEF, 0xEB, 0xAF, 0xA8, 0x1E, 0x23, 0x7C, 0x04,
  9308. 0xAA, 0xA1, 0x6D, 0x92, 0x79, 0x7B, 0xFA, 0x80,
  9309. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  9310. 0x0C, 0x79, 0x7B, 0xFA, 0x80, 0x00, 0x00, 0x00,
  9311. 0x00, 0x00, 0x00, 0x00, 0x00, 0xAA, 0xA1, 0x6D,
  9312. 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9313. 0x00, 0x00, 0x10, 0x00, 0x20, 0x00, 0x04, 0x00,
  9314. 0x10, 0x00, 0x10, 0x08, 0x02, 0x05, 0x08, 0x01,
  9315. 0x30, 0x28, 0x00, 0x00, 0x0F, 0x00, 0x02, 0x00,
  9316. 0x09, 0x31, 0x32, 0x37, 0x2E, 0x30, 0x2E, 0x30,
  9317. 0x2E, 0x31, 0xED, 0x4F
  9318. };
  9319. #endif /* defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT) */
  9320. static int test_wolfSSL_dtls_export(void)
  9321. {
  9322. EXPECT_DECLS;
  9323. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT)
  9324. tcp_ready ready;
  9325. func_args client_args;
  9326. func_args server_args;
  9327. THREAD_TYPE serverThread;
  9328. callback_functions server_cbf;
  9329. callback_functions client_cbf;
  9330. #ifdef WOLFSSL_TIRTOS
  9331. fdOpenSession(Task_self());
  9332. #endif
  9333. InitTcpReady(&ready);
  9334. #if defined(USE_WINDOWS_API)
  9335. /* use RNG to get random port if using windows */
  9336. ready.port = GetRandomPort();
  9337. #endif
  9338. /* set using dtls */
  9339. XMEMSET(&client_args, 0, sizeof(func_args));
  9340. XMEMSET(&server_args, 0, sizeof(func_args));
  9341. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  9342. XMEMSET(&client_cbf, 0, sizeof(callback_functions));
  9343. server_cbf.method = wolfDTLSv1_2_server_method;
  9344. client_cbf.method = wolfDTLSv1_2_client_method;
  9345. server_args.callbacks = &server_cbf;
  9346. client_args.callbacks = &client_cbf;
  9347. server_args.signal = &ready;
  9348. client_args.signal = &ready;
  9349. start_thread(run_wolfssl_server, &server_args, &serverThread);
  9350. wait_tcp_ready(&server_args);
  9351. run_wolfssl_client(&client_args);
  9352. join_thread(serverThread);
  9353. ExpectTrue(client_args.return_code);
  9354. ExpectTrue(server_args.return_code);
  9355. FreeTcpReady(&ready);
  9356. #ifdef WOLFSSL_TIRTOS
  9357. fdOpenSession(Task_self());
  9358. #endif
  9359. if (EXPECT_SUCCESS()) {
  9360. SOCKET_T sockfd = 0;
  9361. WOLFSSL_CTX* ctx = NULL;
  9362. WOLFSSL* ssl = NULL;
  9363. char msg[64] = "hello wolfssl!";
  9364. char reply[1024];
  9365. int msgSz = (int)XSTRLEN(msg);
  9366. byte *session, *window;
  9367. unsigned int sessionSz = 0;
  9368. unsigned int windowSz = 0;
  9369. #ifndef TEST_IPV6
  9370. struct sockaddr_in peerAddr;
  9371. #else
  9372. struct sockaddr_in6 peerAddr;
  9373. #endif /* TEST_IPV6 */
  9374. int i;
  9375. /* Set ctx to DTLS 1.2 */
  9376. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method()));
  9377. ExpectNotNull(ssl = wolfSSL_new(ctx));
  9378. /* test importing version 3 */
  9379. ExpectIntGE(wolfSSL_dtls_import(ssl, version_3, sizeof(version_3)), 0);
  9380. /* test importing bad length and bad version */
  9381. version_3[2] += 1;
  9382. ExpectIntLT(wolfSSL_dtls_import(ssl, version_3, sizeof(version_3)), 0);
  9383. version_3[2] -= 1; version_3[1] = 0XA0;
  9384. ExpectIntLT(wolfSSL_dtls_import(ssl, version_3, sizeof(version_3)), 0);
  9385. wolfSSL_free(ssl);
  9386. wolfSSL_CTX_free(ctx);
  9387. /* check storing client state after connection and storing window only */
  9388. #ifdef WOLFSSL_TIRTOS
  9389. fdOpenSession(Task_self());
  9390. #endif
  9391. InitTcpReady(&ready);
  9392. #if defined(USE_WINDOWS_API)
  9393. /* use RNG to get random port if using windows */
  9394. ready.port = GetRandomPort();
  9395. #endif
  9396. /* set using dtls */
  9397. XMEMSET(&server_args, 0, sizeof(func_args));
  9398. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  9399. server_cbf.method = wolfDTLSv1_2_server_method;
  9400. server_cbf.doUdp = 1;
  9401. server_args.callbacks = &server_cbf;
  9402. server_args.argc = 3; /* set loop_count to 3 */
  9403. server_args.signal = &ready;
  9404. start_thread(test_server_nofail, &server_args, &serverThread);
  9405. wait_tcp_ready(&server_args);
  9406. /* create and connect with client */
  9407. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_2_client_method()));
  9408. ExpectIntEQ(WOLFSSL_SUCCESS,
  9409. wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0));
  9410. ExpectIntEQ(WOLFSSL_SUCCESS,
  9411. wolfSSL_CTX_use_certificate_file(ctx, cliCertFile, SSL_FILETYPE_PEM));
  9412. ExpectIntEQ(WOLFSSL_SUCCESS,
  9413. wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, SSL_FILETYPE_PEM));
  9414. tcp_connect(&sockfd, wolfSSLIP, server_args.signal->port, 1, 0, NULL);
  9415. ExpectNotNull(ssl = wolfSSL_new(ctx));
  9416. ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS);
  9417. /* store server information connected too */
  9418. XMEMSET(&peerAddr, 0, sizeof(peerAddr));
  9419. #ifndef TEST_IPV6
  9420. peerAddr.sin_family = AF_INET;
  9421. ExpectIntEQ(XINET_PTON(AF_INET, wolfSSLIP, &peerAddr.sin_addr),1);
  9422. peerAddr.sin_port = XHTONS(server_args.signal->port);
  9423. #else
  9424. peerAddr.sin6_family = AF_INET6;
  9425. ExpectIntEQ(
  9426. XINET_PTON(AF_INET6, wolfSSLIP, &peerAddr.sin6_addr),1);
  9427. peerAddr.sin6_port = XHTONS(server_args.signal->port);
  9428. #endif
  9429. ExpectIntEQ(wolfSSL_dtls_set_peer(ssl, &peerAddr, sizeof(peerAddr)),
  9430. WOLFSSL_SUCCESS);
  9431. ExpectIntEQ(wolfSSL_connect(ssl), WOLFSSL_SUCCESS);
  9432. ExpectIntEQ(wolfSSL_dtls_export(ssl, NULL, &sessionSz), 0);
  9433. session = (byte*)XMALLOC(sessionSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9434. ExpectIntGT(wolfSSL_dtls_export(ssl, session, &sessionSz), 0);
  9435. ExpectIntEQ(wolfSSL_write(ssl, msg, msgSz), msgSz);
  9436. ExpectIntGT(wolfSSL_read(ssl, reply, sizeof(reply)), 0);
  9437. ExpectIntEQ(wolfSSL_dtls_export_state_only(ssl, NULL, &windowSz), 0);
  9438. window = (byte*)XMALLOC(windowSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9439. ExpectIntGT(wolfSSL_dtls_export_state_only(ssl, window, &windowSz), 0);
  9440. wolfSSL_free(ssl);
  9441. for (i = 1; EXPECT_SUCCESS() && i < server_args.argc; i++) {
  9442. /* restore state */
  9443. ExpectNotNull(ssl = wolfSSL_new(ctx));
  9444. ExpectIntGT(wolfSSL_dtls_import(ssl, session, sessionSz), 0);
  9445. ExpectIntGT(wolfSSL_dtls_import(ssl, window, windowSz), 0);
  9446. ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS);
  9447. ExpectIntEQ(wolfSSL_dtls_set_peer(ssl, &peerAddr, sizeof(peerAddr)),
  9448. WOLFSSL_SUCCESS);
  9449. ExpectIntEQ(wolfSSL_write(ssl, msg, msgSz), msgSz);
  9450. ExpectIntGE(wolfSSL_read(ssl, reply, sizeof(reply)), 0);
  9451. ExpectIntGT(wolfSSL_dtls_export_state_only(ssl, window, &windowSz), 0);
  9452. wolfSSL_free(ssl);
  9453. }
  9454. XFREE(session, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9455. XFREE(window, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9456. wolfSSL_CTX_free(ctx);
  9457. fprintf(stderr, "done and waiting for server\n");
  9458. join_thread(serverThread);
  9459. ExpectIntEQ(server_args.return_code, TEST_SUCCESS);
  9460. FreeTcpReady(&ready);
  9461. #ifdef WOLFSSL_TIRTOS
  9462. fdOpenSession(Task_self());
  9463. #endif
  9464. }
  9465. #endif
  9466. return EXPECT_RESULT();
  9467. }
  9468. #if defined(WOLFSSL_SESSION_EXPORT) && !defined(WOLFSSL_NO_TLS12)
  9469. #ifdef WOLFSSL_TLS13
  9470. static const byte canned_client_tls13_session[] = {
  9471. 0xA7, 0xA4, 0x01, 0x18, 0x00, 0x41, 0x00, 0x00,
  9472. 0x01, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x00,
  9473. 0x00, 0x80, 0x00, 0x1C, 0x01, 0x00, 0x00, 0x01,
  9474. 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
  9475. 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
  9476. 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  9477. 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13,
  9478. 0x01, 0x0A, 0x0F, 0x10, 0x01, 0x02, 0x09, 0x00,
  9479. 0x05, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00,
  9480. 0xB7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9481. 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9482. 0x01, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00,
  9483. 0x11, 0x01, 0x01, 0x00, 0x20, 0x84, 0x4F, 0x18,
  9484. 0xD8, 0xC1, 0x24, 0xD8, 0xBB, 0x17, 0x9E, 0x31,
  9485. 0xA3, 0xF8, 0xA7, 0x3C, 0xBA, 0xEC, 0xFA, 0xB4,
  9486. 0x7F, 0xC5, 0x78, 0xEB, 0x6D, 0xE3, 0x2B, 0x7B,
  9487. 0x94, 0xBE, 0x20, 0x11, 0x7E, 0x17, 0x10, 0xA7,
  9488. 0x10, 0x19, 0xEC, 0x62, 0xCC, 0xBE, 0xF5, 0x01,
  9489. 0x35, 0x3C, 0xEA, 0xEF, 0x44, 0x3C, 0x40, 0xA2,
  9490. 0xBC, 0x18, 0x43, 0xA1, 0xA1, 0x65, 0x5C, 0x48,
  9491. 0xE2, 0xF9, 0x38, 0xEB, 0x11, 0x10, 0x72, 0x7C,
  9492. 0x78, 0x22, 0x13, 0x3B, 0x19, 0x40, 0xF0, 0x73,
  9493. 0xBE, 0x96, 0x14, 0x78, 0x26, 0xB9, 0x6B, 0x2E,
  9494. 0x72, 0x22, 0x0D, 0x90, 0x94, 0xDD, 0x78, 0x77,
  9495. 0xFC, 0x0C, 0x2E, 0x63, 0x6E, 0xF0, 0x0C, 0x35,
  9496. 0x41, 0xCD, 0xF3, 0x49, 0x31, 0x08, 0xD0, 0x6F,
  9497. 0x02, 0x3D, 0xC1, 0xD3, 0xB7, 0xEE, 0x3A, 0xA0,
  9498. 0x8E, 0xA1, 0x4D, 0xC3, 0x2E, 0x5E, 0x06, 0x00,
  9499. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
  9500. 0x35, 0x41, 0xCD, 0xF3, 0x49, 0x31, 0x08, 0xD0,
  9501. 0x6F, 0x02, 0x3D, 0xC1, 0xD3, 0xB7, 0xEE, 0x3A,
  9502. 0xA0, 0x8E, 0xA1, 0x4D, 0xC3, 0x2E, 0x5E, 0x06,
  9503. 0x00, 0x10, 0x00, 0x10, 0x00, 0x0C, 0x00, 0x10,
  9504. 0x00, 0x10, 0x07, 0x02, 0x04, 0x00, 0x00, 0x20,
  9505. 0x28, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
  9506. 0x00, 0x03
  9507. };
  9508. static const byte canned_server_tls13_session[] = {
  9509. 0xA7, 0xA4, 0x01, 0x18, 0x00, 0x41, 0x01, 0x00,
  9510. 0x01, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x00,
  9511. 0x00, 0x80, 0x00, 0x1C, 0x01, 0x00, 0x00, 0x00,
  9512. 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
  9513. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9514. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  9515. 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13,
  9516. 0x01, 0x0A, 0x0F, 0x10, 0x01, 0x02, 0x00, 0x0F,
  9517. 0x05, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x00,
  9518. 0xB7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9519. 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9520. 0x02, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00,
  9521. 0x11, 0x01, 0x01, 0x00, 0x20, 0x84, 0x4F, 0x18,
  9522. 0xD8, 0xC1, 0x24, 0xD8, 0xBB, 0x17, 0x9E, 0x31,
  9523. 0xA3, 0xF8, 0xA7, 0x3C, 0xBA, 0xEC, 0xFA, 0xB4,
  9524. 0x7F, 0xC5, 0x78, 0xEB, 0x6D, 0xE3, 0x2B, 0x7B,
  9525. 0x94, 0xBE, 0x20, 0x11, 0x7E, 0x17, 0x10, 0xA7,
  9526. 0x10, 0x19, 0xEC, 0x62, 0xCC, 0xBE, 0xF5, 0x01,
  9527. 0x35, 0x3C, 0xEA, 0xEF, 0x44, 0x3C, 0x40, 0xA2,
  9528. 0xBC, 0x18, 0x43, 0xA1, 0xA1, 0x65, 0x5C, 0x48,
  9529. 0xE2, 0xF9, 0x38, 0xEB, 0x11, 0x10, 0x72, 0x7C,
  9530. 0x78, 0x22, 0x13, 0x3B, 0x19, 0x40, 0xF0, 0x73,
  9531. 0xBE, 0x96, 0x14, 0x78, 0x26, 0xB9, 0x6B, 0x2E,
  9532. 0x72, 0x22, 0x0D, 0x90, 0x94, 0xDD, 0x78, 0x77,
  9533. 0xFC, 0x0C, 0x2E, 0x63, 0x6E, 0xF0, 0x0C, 0x35,
  9534. 0x41, 0xCD, 0xF3, 0x49, 0x31, 0x08, 0xD0, 0x6F,
  9535. 0x02, 0x3D, 0xC1, 0xD3, 0xB7, 0xEE, 0x3A, 0xA0,
  9536. 0x8E, 0xA1, 0x4D, 0xC3, 0x2E, 0x5E, 0x06, 0x00,
  9537. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
  9538. 0xD3, 0xB7, 0xEE, 0x3A, 0xA0, 0x8E, 0xA1, 0x4D,
  9539. 0xC3, 0x2E, 0x5E, 0x06, 0x35, 0x41, 0xCD, 0xF3,
  9540. 0x49, 0x31, 0x08, 0xD0, 0x6F, 0x02, 0x3D, 0xC1,
  9541. 0x00, 0x10, 0x00, 0x10, 0x00, 0x0C, 0x00, 0x10,
  9542. 0x00, 0x10, 0x07, 0x02, 0x04, 0x00, 0x00, 0x20,
  9543. 0x28, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
  9544. 0x00, 0x04
  9545. };
  9546. #endif /* WOLFSSL_TLS13 */
  9547. static const byte canned_client_session[] = {
  9548. 0xA7, 0xA4, 0x01, 0x40, 0x00, 0x41, 0x00, 0x00,
  9549. 0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x00,
  9550. 0x00, 0x80, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x01,
  9551. 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
  9552. 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
  9553. 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9554. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0,
  9555. 0x27, 0x0A, 0x0D, 0x10, 0x01, 0x01, 0x0A, 0x00,
  9556. 0x05, 0x00, 0x01, 0x01, 0x01, 0x03, 0x03, 0x00,
  9557. 0xBF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9558. 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9559. 0x02, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00,
  9560. 0x0A, 0x01, 0x01, 0x00, 0x20, 0x69, 0x11, 0x6D,
  9561. 0x97, 0x15, 0x6E, 0x52, 0x27, 0xD6, 0x1D, 0x1D,
  9562. 0xF5, 0x0D, 0x59, 0xA5, 0xAC, 0x2E, 0x8C, 0x0E,
  9563. 0xCB, 0x26, 0x1E, 0xE2, 0xCE, 0xBB, 0xCE, 0xE1,
  9564. 0x7D, 0xD7, 0xEF, 0xA5, 0x44, 0x80, 0x2A, 0xDE,
  9565. 0xBB, 0x75, 0xB0, 0x1D, 0x75, 0x17, 0x20, 0x4C,
  9566. 0x08, 0x05, 0x1B, 0xBA, 0x60, 0x1F, 0x6C, 0x91,
  9567. 0x8C, 0xAA, 0xBB, 0xE5, 0xA3, 0x0B, 0x12, 0x3E,
  9568. 0xC0, 0x35, 0x43, 0x1D, 0xE2, 0x10, 0xE2, 0x02,
  9569. 0x92, 0x4B, 0x8F, 0x05, 0xA9, 0x4B, 0xCC, 0x90,
  9570. 0xC3, 0x0E, 0xC2, 0x0F, 0xE9, 0x33, 0x85, 0x9B,
  9571. 0x3C, 0x19, 0x21, 0xD5, 0x62, 0xE5, 0xE1, 0x17,
  9572. 0x8F, 0x8C, 0x19, 0x52, 0xD8, 0x59, 0x10, 0x2D,
  9573. 0x20, 0x6F, 0xBA, 0xC1, 0x1C, 0xD1, 0x82, 0xC7,
  9574. 0x32, 0x1B, 0xBB, 0xCC, 0x30, 0x03, 0xD7, 0x3A,
  9575. 0xC8, 0x18, 0xED, 0x58, 0xC8, 0x11, 0xFE, 0x71,
  9576. 0x9C, 0x71, 0xD8, 0x6B, 0xE0, 0x25, 0x64, 0x00,
  9577. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
  9578. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9579. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9580. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9581. 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10,
  9582. 0x00, 0x00, 0x06, 0x01, 0x04, 0x08, 0x01, 0x20,
  9583. 0x28, 0x00, 0x09, 0xE1, 0x50, 0x70, 0x02, 0x2F,
  9584. 0x7E, 0xDA, 0xBD, 0x40, 0xC5, 0x58, 0x87, 0xCE,
  9585. 0x43, 0xF3, 0xC5, 0x8F, 0xA1, 0x59, 0x93, 0xEF,
  9586. 0x7E, 0xD3, 0xD0, 0xB5, 0x87, 0x1D, 0x81, 0x54,
  9587. 0x14, 0x63, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
  9588. 0x00, 0x03
  9589. };
  9590. static const byte canned_server_session[] = {
  9591. 0xA7, 0xA4, 0x01, 0x40, 0x00, 0x41, 0x00, 0x00,
  9592. 0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x00,
  9593. 0x00, 0x80, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00,
  9594. 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
  9595. 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  9596. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9597. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0,
  9598. 0x27, 0x08, 0x0F, 0x10, 0x01, 0x01, 0x00, 0x11,
  9599. 0x05, 0x00, 0x01, 0x01, 0x01, 0x03, 0x03, 0x00,
  9600. 0xBF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9601. 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9602. 0x02, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
  9603. 0x0A, 0x01, 0x01, 0x00, 0x20, 0x69, 0x11, 0x6D,
  9604. 0x97, 0x15, 0x6E, 0x52, 0x27, 0xD6, 0x1D, 0x1D,
  9605. 0xF5, 0x0D, 0x59, 0xA5, 0xAC, 0x2E, 0x8C, 0x0E,
  9606. 0xCB, 0x26, 0x1E, 0xE2, 0xCE, 0xBB, 0xCE, 0xE1,
  9607. 0x7D, 0xD7, 0xEF, 0xA5, 0x44, 0x80, 0x2A, 0xDE,
  9608. 0xBB, 0x75, 0xB0, 0x1D, 0x75, 0x17, 0x20, 0x4C,
  9609. 0x08, 0x05, 0x1B, 0xBA, 0x60, 0x1F, 0x6C, 0x91,
  9610. 0x8C, 0xAA, 0xBB, 0xE5, 0xA3, 0x0B, 0x12, 0x3E,
  9611. 0xC0, 0x35, 0x43, 0x1D, 0xE2, 0x10, 0xE2, 0x02,
  9612. 0x92, 0x4B, 0x8F, 0x05, 0xA9, 0x4B, 0xCC, 0x90,
  9613. 0xC3, 0x0E, 0xC2, 0x0F, 0xE9, 0x33, 0x85, 0x9B,
  9614. 0x3C, 0x19, 0x21, 0xD5, 0x62, 0xE5, 0xE1, 0x17,
  9615. 0x8F, 0x8C, 0x19, 0x52, 0xD8, 0x59, 0x10, 0x2D,
  9616. 0x20, 0x6F, 0xBA, 0xC1, 0x1C, 0xD1, 0x82, 0xC7,
  9617. 0x32, 0x1B, 0xBB, 0xCC, 0x30, 0x03, 0xD7, 0x3A,
  9618. 0xC8, 0x18, 0xED, 0x58, 0xC8, 0x11, 0xFE, 0x71,
  9619. 0x9C, 0x71, 0xD8, 0x6B, 0xE0, 0x25, 0x64, 0x00,
  9620. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
  9621. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9622. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9623. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  9624. 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10,
  9625. 0x00, 0x00, 0x06, 0x01, 0x04, 0x08, 0x01, 0x20,
  9626. 0x28, 0x00, 0xC5, 0x8F, 0xA1, 0x59, 0x93, 0xEF,
  9627. 0x7E, 0xD3, 0xD0, 0xB5, 0x87, 0x1D, 0x81, 0x54,
  9628. 0x14, 0x63, 0x09, 0xE1, 0x50, 0x70, 0x02, 0x2F,
  9629. 0x7E, 0xDA, 0xBD, 0x40, 0xC5, 0x58, 0x87, 0xCE,
  9630. 0x43, 0xF3, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
  9631. 0x00, 0x04
  9632. };
  9633. static THREAD_RETURN WOLFSSL_THREAD tls_export_server(void* args)
  9634. {
  9635. SOCKET_T sockfd = 0;
  9636. SOCKET_T clientfd = 0;
  9637. word16 port;
  9638. callback_functions* cbf;
  9639. WOLFSSL_CTX* ctx = 0;
  9640. WOLFSSL* ssl = 0;
  9641. char msg[] = "I hear you fa shizzle!";
  9642. char input[1024];
  9643. int idx;
  9644. #ifdef WOLFSSL_TIRTOS
  9645. fdOpenSession(Task_self());
  9646. #endif
  9647. ((func_args*)args)->return_code = TEST_FAIL;
  9648. cbf = ((func_args*)args)->callbacks;
  9649. #if defined(USE_WINDOWS_API)
  9650. port = ((func_args*)args)->signal->port;
  9651. #elif defined(NO_MAIN_DRIVER) && !defined(WOLFSSL_SNIFFER) && \
  9652. !defined(WOLFSSL_MDK_SHELL) && !defined(WOLFSSL_TIRTOS)
  9653. /* Let tcp_listen assign port */
  9654. port = 0;
  9655. #else
  9656. /* Use default port */
  9657. port = wolfSSLPort;
  9658. #endif
  9659. /* do it here to detect failure */
  9660. tcp_accept(&sockfd, &clientfd, (func_args*)args, port, 0, 0, 0, 0, 1, 0, 0);
  9661. CloseSocket(sockfd);
  9662. {
  9663. WOLFSSL_METHOD* method = NULL;
  9664. if (cbf != NULL && cbf->method != NULL) {
  9665. method = cbf->method();
  9666. }
  9667. else {
  9668. method = wolfTLSv1_2_server_method();
  9669. }
  9670. ctx = wolfSSL_CTX_new(method);
  9671. }
  9672. if (ctx == NULL) {
  9673. goto done;
  9674. }
  9675. wolfSSL_CTX_set_cipher_list(ctx, "ECDHE-RSA-AES128-SHA256");
  9676. /* call ctx setup callback */
  9677. if (cbf != NULL && cbf->ctx_ready != NULL) {
  9678. cbf->ctx_ready(ctx);
  9679. }
  9680. ssl = wolfSSL_new(ctx);
  9681. if (ssl == NULL) {
  9682. goto done;
  9683. }
  9684. wolfSSL_set_fd(ssl, clientfd);
  9685. /* call ssl setup callback */
  9686. if (cbf != NULL && cbf->ssl_ready != NULL) {
  9687. cbf->ssl_ready(ssl);
  9688. }
  9689. idx = wolfSSL_read(ssl, input, sizeof(input)-1);
  9690. if (idx > 0) {
  9691. input[idx] = '\0';
  9692. fprintf(stderr, "Client message export/import: %s\n", input);
  9693. }
  9694. else {
  9695. fprintf(stderr, "ret = %d error = %d\n", idx,
  9696. wolfSSL_get_error(ssl, idx));
  9697. goto done;
  9698. }
  9699. if (wolfSSL_write(ssl, msg, sizeof(msg)) != sizeof(msg)) {
  9700. /*err_sys("SSL_write failed");*/
  9701. WOLFSSL_RETURN_FROM_THREAD(0);
  9702. }
  9703. #ifdef WOLFSSL_TIRTOS
  9704. Task_yield();
  9705. #endif
  9706. ((func_args*)args)->return_code = TEST_SUCCESS;
  9707. done:
  9708. wolfSSL_shutdown(ssl);
  9709. wolfSSL_free(ssl);
  9710. wolfSSL_CTX_free(ctx);
  9711. CloseSocket(clientfd);
  9712. #ifdef WOLFSSL_TIRTOS
  9713. fdCloseSession(Task_self());
  9714. #endif
  9715. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  9716. && defined(HAVE_THREAD_LS)
  9717. wc_ecc_fp_free(); /* free per thread cache */
  9718. #endif
  9719. #if defined(HAVE_SESSION_TICKET) && \
  9720. ((defined(HAVE_CHACHA) && defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))
  9721. #if defined(OPENSSL_EXTRA) && defined(HAVE_AESGCM)
  9722. OpenSSLTicketCleanup();
  9723. #elif defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  9724. TicketCleanup();
  9725. #endif
  9726. #endif
  9727. WOLFSSL_RETURN_FROM_THREAD(0);
  9728. }
  9729. static void load_tls12_canned_server(WOLFSSL* ssl)
  9730. {
  9731. int clientfd = wolfSSL_get_fd(ssl);
  9732. AssertIntEQ(wolfSSL_tls_import(ssl, canned_server_session,
  9733. sizeof(canned_server_session)), sizeof(canned_server_session));
  9734. wolfSSL_set_fd(ssl, clientfd);
  9735. }
  9736. #ifdef WOLFSSL_TLS13
  9737. static void load_tls13_canned_server(WOLFSSL* ssl)
  9738. {
  9739. int clientfd = wolfSSL_get_fd(ssl);
  9740. AssertIntEQ(wolfSSL_tls_import(ssl, canned_server_tls13_session,
  9741. sizeof(canned_server_tls13_session)),
  9742. sizeof(canned_server_tls13_session));
  9743. wolfSSL_set_fd(ssl, clientfd);
  9744. }
  9745. #endif
  9746. /* v is for version WOLFSSL_TLSV1_2 or WOLFSSL_TLSV1_3 */
  9747. static int test_wolfSSL_tls_export_run(int v)
  9748. {
  9749. EXPECT_DECLS;
  9750. SOCKET_T sockfd = 0;
  9751. WOLFSSL_CTX* ctx = 0;
  9752. WOLFSSL* ssl = 0;
  9753. char msg[64] = "hello wolfssl!";
  9754. char reply[1024];
  9755. word32 replySz;
  9756. int msgSz = (int)XSTRLEN(msg);
  9757. const byte* clientSession = NULL;
  9758. int clientSessionSz = 0;
  9759. tcp_ready ready;
  9760. func_args server_args;
  9761. THREAD_TYPE serverThread;
  9762. callback_functions server_cbf;
  9763. #ifdef WOLFSSL_TIRTOS
  9764. fdOpenSession(Task_self());
  9765. #endif
  9766. InitTcpReady(&ready);
  9767. #if defined(USE_WINDOWS_API)
  9768. /* use RNG to get random port if using windows */
  9769. ready.port = GetRandomPort();
  9770. #endif
  9771. XMEMSET(&server_args, 0, sizeof(func_args));
  9772. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  9773. switch (v) {
  9774. case WOLFSSL_TLSV1_2:
  9775. server_cbf.method = wolfTLSv1_2_server_method;
  9776. server_cbf.ssl_ready = load_tls12_canned_server;
  9777. /* setup the client side */
  9778. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  9779. wolfSSL_CTX_set_cipher_list(ctx, "ECDHE-RSA-AES128-SHA256");
  9780. clientSession = canned_client_session;
  9781. clientSessionSz = sizeof(canned_client_session);
  9782. break;
  9783. #ifdef WOLFSSL_TLS13
  9784. case WOLFSSL_TLSV1_3:
  9785. server_cbf.method = wolfTLSv1_3_server_method;
  9786. server_cbf.ssl_ready = load_tls13_canned_server;
  9787. /* setup the client side */
  9788. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  9789. clientSession = canned_client_tls13_session;
  9790. clientSessionSz = sizeof(canned_client_tls13_session);
  9791. break;
  9792. #endif
  9793. }
  9794. server_args.callbacks = &server_cbf;
  9795. server_args.signal = &ready;
  9796. start_thread(tls_export_server, &server_args, &serverThread);
  9797. wait_tcp_ready(&server_args);
  9798. #ifdef WOLFSSL_TIRTOS
  9799. fdOpenSession(Task_self());
  9800. #endif
  9801. ExpectNotNull(ssl = wolfSSL_new(ctx));
  9802. tcp_connect(&sockfd, wolfSSLIP, ready.port, 0, 0, ssl);
  9803. ExpectIntEQ(wolfSSL_tls_import(ssl, clientSession, clientSessionSz),
  9804. clientSessionSz);
  9805. replySz = sizeof(reply);
  9806. ExpectIntGT(wolfSSL_tls_export(ssl, (byte*)reply, &replySz), 0);
  9807. #if !defined(NO_PSK) && defined(HAVE_ANON)
  9808. /* index 20 has is setting if PSK was on and 49 is if anon is allowed */
  9809. ExpectIntEQ(XMEMCMP(reply, clientSession, replySz), 0);
  9810. #endif
  9811. wolfSSL_set_fd(ssl, sockfd);
  9812. ExpectIntEQ(wolfSSL_write(ssl, msg, msgSz), msgSz);
  9813. ExpectIntGT(wolfSSL_read(ssl, reply, sizeof(reply)-1), 0);
  9814. wolfSSL_free(ssl);
  9815. wolfSSL_CTX_free(ctx);
  9816. CloseSocket(sockfd);
  9817. #ifdef WOLFSSL_TIRTOS
  9818. fdCloseSession(Task_self());
  9819. #endif
  9820. #if defined(NO_MAIN_DRIVER) && defined(HAVE_ECC) && defined(FP_ECC) \
  9821. && defined(HAVE_THREAD_LS)
  9822. wc_ecc_fp_free(); /* free per thread cache */
  9823. #endif
  9824. join_thread(serverThread);
  9825. ExpectIntEQ(server_args.return_code, TEST_SUCCESS);
  9826. FreeTcpReady(&ready);
  9827. #ifdef WOLFSSL_TIRTOS
  9828. fdOpenSession(Task_self());
  9829. #endif
  9830. return EXPECT_RESULT();
  9831. }
  9832. #endif
  9833. static int test_wolfSSL_tls_export(void)
  9834. {
  9835. int res = TEST_SKIPPED;
  9836. #if defined(WOLFSSL_SESSION_EXPORT) && !defined(WOLFSSL_NO_TLS12)
  9837. test_wolfSSL_tls_export_run(WOLFSSL_TLSV1_2);
  9838. #ifdef WOLFSSL_TLS13
  9839. test_wolfSSL_tls_export_run(WOLFSSL_TLSV1_3);
  9840. #endif
  9841. res = TEST_RES_CHECK(1);
  9842. #endif
  9843. return res;
  9844. }
  9845. /*----------------------------------------------------------------------------*
  9846. | TLS extensions tests
  9847. *----------------------------------------------------------------------------*/
  9848. #ifdef ENABLE_TLS_CALLBACK_TEST
  9849. /* Connection test runner - generic */
  9850. static void test_wolfSSL_client_server(callback_functions* client_callbacks,
  9851. callback_functions* server_callbacks)
  9852. {
  9853. tcp_ready ready;
  9854. func_args client_args;
  9855. func_args server_args;
  9856. THREAD_TYPE serverThread;
  9857. XMEMSET(&client_args, 0, sizeof(func_args));
  9858. XMEMSET(&server_args, 0, sizeof(func_args));
  9859. StartTCP();
  9860. client_args.callbacks = client_callbacks;
  9861. server_args.callbacks = server_callbacks;
  9862. #ifdef WOLFSSL_TIRTOS
  9863. fdOpenSession(Task_self());
  9864. #endif
  9865. /* RUN Server side */
  9866. InitTcpReady(&ready);
  9867. #if defined(USE_WINDOWS_API)
  9868. /* use RNG to get random port if using windows */
  9869. ready.port = GetRandomPort();
  9870. #endif
  9871. server_args.signal = &ready;
  9872. client_args.signal = &ready;
  9873. start_thread(run_wolfssl_server, &server_args, &serverThread);
  9874. wait_tcp_ready(&server_args);
  9875. /* RUN Client side */
  9876. run_wolfssl_client(&client_args);
  9877. join_thread(serverThread);
  9878. FreeTcpReady(&ready);
  9879. #ifdef WOLFSSL_TIRTOS
  9880. fdCloseSession(Task_self());
  9881. #endif
  9882. client_callbacks->return_code = client_args.return_code;
  9883. server_callbacks->return_code = server_args.return_code;
  9884. }
  9885. #endif /* ENABLE_TLS_CALLBACK_TEST */
  9886. #ifdef HAVE_SNI
  9887. static int test_wolfSSL_UseSNI_params(void)
  9888. {
  9889. EXPECT_DECLS;
  9890. #if !defined(NO_WOLFSSL_CLIENT)
  9891. WOLFSSL_CTX *ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  9892. WOLFSSL *ssl = wolfSSL_new(ctx);
  9893. ExpectNotNull(ctx);
  9894. ExpectNotNull(ssl);
  9895. /* invalid [ctx|ssl] */
  9896. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(NULL, 0, "ctx", 3));
  9897. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSNI( NULL, 0, "ssl", 3));
  9898. /* invalid type */
  9899. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(ctx, (byte)-1, "ctx", 3));
  9900. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSNI( ssl, (byte)-1, "ssl", 3));
  9901. /* invalid data */
  9902. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(ctx, 0, NULL, 3));
  9903. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSNI( ssl, 0, NULL, 3));
  9904. /* success case */
  9905. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSNI(ctx, 0, "ctx", 3));
  9906. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSNI( ssl, 0, "ssl", 3));
  9907. wolfSSL_free(ssl);
  9908. wolfSSL_CTX_free(ctx);
  9909. #endif /* !NO_WOLFSSL_CLIENT */
  9910. return EXPECT_RESULT();
  9911. }
  9912. /* BEGIN of connection tests callbacks */
  9913. static void use_SNI_at_ctx(WOLFSSL_CTX* ctx)
  9914. {
  9915. AssertIntEQ(WOLFSSL_SUCCESS,
  9916. wolfSSL_CTX_UseSNI(ctx, WOLFSSL_SNI_HOST_NAME, "www.wolfssl.com", 15));
  9917. }
  9918. static void use_SNI_at_ssl(WOLFSSL* ssl)
  9919. {
  9920. AssertIntEQ(WOLFSSL_SUCCESS,
  9921. wolfSSL_UseSNI(ssl, WOLFSSL_SNI_HOST_NAME, "www.wolfssl.com", 15));
  9922. }
  9923. static void different_SNI_at_ssl(WOLFSSL* ssl)
  9924. {
  9925. AssertIntEQ(WOLFSSL_SUCCESS,
  9926. wolfSSL_UseSNI(ssl, WOLFSSL_SNI_HOST_NAME, "ww2.wolfssl.com", 15));
  9927. }
  9928. static void use_SNI_WITH_CONTINUE_at_ssl(WOLFSSL* ssl)
  9929. {
  9930. use_SNI_at_ssl(ssl);
  9931. wolfSSL_SNI_SetOptions(ssl, WOLFSSL_SNI_HOST_NAME,
  9932. WOLFSSL_SNI_CONTINUE_ON_MISMATCH);
  9933. }
  9934. static void use_SNI_WITH_FAKE_ANSWER_at_ssl(WOLFSSL* ssl)
  9935. {
  9936. use_SNI_at_ssl(ssl);
  9937. wolfSSL_SNI_SetOptions(ssl, WOLFSSL_SNI_HOST_NAME,
  9938. WOLFSSL_SNI_ANSWER_ON_MISMATCH);
  9939. }
  9940. static void use_MANDATORY_SNI_at_ctx(WOLFSSL_CTX* ctx)
  9941. {
  9942. use_SNI_at_ctx(ctx);
  9943. wolfSSL_CTX_SNI_SetOptions(ctx, WOLFSSL_SNI_HOST_NAME,
  9944. WOLFSSL_SNI_ABORT_ON_ABSENCE);
  9945. }
  9946. static void use_MANDATORY_SNI_at_ssl(WOLFSSL* ssl)
  9947. {
  9948. use_SNI_at_ssl(ssl);
  9949. wolfSSL_SNI_SetOptions(ssl, WOLFSSL_SNI_HOST_NAME,
  9950. WOLFSSL_SNI_ABORT_ON_ABSENCE);
  9951. }
  9952. static void use_PSEUDO_MANDATORY_SNI_at_ctx(WOLFSSL_CTX* ctx)
  9953. {
  9954. use_SNI_at_ctx(ctx);
  9955. wolfSSL_CTX_SNI_SetOptions(ctx, WOLFSSL_SNI_HOST_NAME,
  9956. WOLFSSL_SNI_ANSWER_ON_MISMATCH | WOLFSSL_SNI_ABORT_ON_ABSENCE);
  9957. }
  9958. static void verify_UNKNOWN_SNI_on_server(WOLFSSL* ssl)
  9959. {
  9960. AssertIntEQ(WC_NO_ERR_TRACE(UNKNOWN_SNI_HOST_NAME_E),
  9961. wolfSSL_get_error(ssl, 0));
  9962. }
  9963. static void verify_SNI_ABSENT_on_server(WOLFSSL* ssl)
  9964. {
  9965. AssertIntEQ(WC_NO_ERR_TRACE(SNI_ABSENT_ERROR), wolfSSL_get_error(ssl, 0));
  9966. }
  9967. static void verify_SNI_no_matching(WOLFSSL* ssl)
  9968. {
  9969. byte type = WOLFSSL_SNI_HOST_NAME;
  9970. void* request = (void*) &type; /* to be overwritten */
  9971. AssertIntEQ(WOLFSSL_SNI_NO_MATCH, wolfSSL_SNI_Status(ssl, type));
  9972. AssertNotNull(request);
  9973. AssertIntEQ(0, wolfSSL_SNI_GetRequest(ssl, type, &request));
  9974. AssertNull(request);
  9975. }
  9976. static void verify_SNI_real_matching(WOLFSSL* ssl)
  9977. {
  9978. byte type = WOLFSSL_SNI_HOST_NAME;
  9979. void* request = NULL;
  9980. AssertIntEQ(WOLFSSL_SNI_REAL_MATCH, wolfSSL_SNI_Status(ssl, type));
  9981. AssertIntEQ(15, wolfSSL_SNI_GetRequest(ssl, type, &request));
  9982. AssertNotNull(request);
  9983. AssertStrEQ("www.wolfssl.com", (char*)request);
  9984. }
  9985. static void verify_SNI_fake_matching(WOLFSSL* ssl)
  9986. {
  9987. byte type = WOLFSSL_SNI_HOST_NAME;
  9988. void* request = NULL;
  9989. AssertIntEQ(WOLFSSL_SNI_FAKE_MATCH, wolfSSL_SNI_Status(ssl, type));
  9990. AssertIntEQ(15, wolfSSL_SNI_GetRequest(ssl, type, &request));
  9991. AssertNotNull(request);
  9992. AssertStrEQ("ww2.wolfssl.com", (char*)request);
  9993. }
  9994. static void verify_FATAL_ERROR_on_client(WOLFSSL* ssl)
  9995. {
  9996. AssertIntEQ(WC_NO_ERR_TRACE(FATAL_ERROR), wolfSSL_get_error(ssl, 0));
  9997. }
  9998. /* END of connection tests callbacks */
  9999. static int test_wolfSSL_UseSNI_connection(void)
  10000. {
  10001. int res = TEST_SKIPPED;
  10002. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  10003. callback_functions client_cb;
  10004. callback_functions server_cb;
  10005. size_t i;
  10006. #ifdef WOLFSSL_STATIC_MEMORY
  10007. byte cliMem[TEST_TLS_STATIC_MEMSZ];
  10008. byte svrMem[TEST_TLS_STATIC_MEMSZ];
  10009. #endif
  10010. struct {
  10011. method_provider client_meth;
  10012. method_provider server_meth;
  10013. #ifdef WOLFSSL_STATIC_MEMORY
  10014. wolfSSL_method_func client_meth_ex;
  10015. wolfSSL_method_func server_meth_ex;
  10016. #endif
  10017. } methods[] = {
  10018. #if defined(WOLFSSL_NO_TLS12) && !defined(WOLFSSL_TLS13)
  10019. {wolfSSLv23_client_method, wolfSSLv23_server_method
  10020. #ifdef WOLFSSL_STATIC_MEMORY
  10021. ,wolfSSLv23_client_method_ex, wolfSSLv23_server_method_ex
  10022. #endif
  10023. },
  10024. #endif
  10025. #ifndef WOLFSSL_NO_TLS12
  10026. {wolfTLSv1_2_client_method, wolfTLSv1_2_server_method
  10027. #ifdef WOLFSSL_STATIC_MEMORY
  10028. ,wolfTLSv1_2_client_method_ex, wolfTLSv1_2_server_method_ex
  10029. #endif
  10030. },
  10031. #endif
  10032. #ifdef WOLFSSL_TLS13
  10033. {wolfTLSv1_3_client_method, wolfTLSv1_3_server_method
  10034. #ifdef WOLFSSL_STATIC_MEMORY
  10035. ,wolfTLSv1_3_client_method_ex, wolfTLSv1_3_server_method_ex
  10036. #endif
  10037. },
  10038. #endif
  10039. };
  10040. size_t methodsSz = sizeof(methods) / sizeof(*methods);
  10041. for (i = 0; i < methodsSz; i++) {
  10042. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  10043. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  10044. client_cb.method = methods[i].client_meth;
  10045. server_cb.method = methods[i].server_meth;
  10046. client_cb.devId = testDevId;
  10047. server_cb.devId = testDevId;
  10048. #ifdef WOLFSSL_STATIC_MEMORY
  10049. client_cb.method_ex = methods[i].client_meth_ex;
  10050. server_cb.method_ex = methods[i].server_meth_ex;
  10051. client_cb.mem = cliMem;
  10052. client_cb.memSz = (word32)sizeof(cliMem);
  10053. server_cb.mem = svrMem;
  10054. server_cb.memSz = (word32)sizeof(svrMem);;
  10055. #endif
  10056. /* success case at ctx */
  10057. fprintf(stderr, "\n\tsuccess case at ctx\n");
  10058. client_cb.ctx_ready = use_SNI_at_ctx; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
  10059. server_cb.ctx_ready = use_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_real_matching;
  10060. test_wolfSSL_client_server(&client_cb, &server_cb);
  10061. /* success case at ssl */
  10062. fprintf(stderr, "\tsuccess case at ssl\n");
  10063. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_SNI_at_ssl; client_cb.on_result = verify_SNI_real_matching;
  10064. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_at_ssl; server_cb.on_result = verify_SNI_real_matching;
  10065. test_wolfSSL_client_server(&client_cb, &server_cb);
  10066. /* default mismatch behavior */
  10067. fprintf(stderr, "\tdefault mismatch behavior\n");
  10068. client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = verify_FATAL_ERROR_on_client;
  10069. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_at_ssl; server_cb.on_result = verify_UNKNOWN_SNI_on_server;
  10070. test_wolfSSL_client_server(&client_cb, &server_cb);
  10071. /* continue on mismatch */
  10072. fprintf(stderr, "\tcontinue on mismatch\n");
  10073. client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = NULL;
  10074. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_WITH_CONTINUE_at_ssl; server_cb.on_result = verify_SNI_no_matching;
  10075. test_wolfSSL_client_server(&client_cb, &server_cb);
  10076. /* fake answer on mismatch */
  10077. fprintf(stderr, "\tfake answer on mismatch\n");
  10078. client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = NULL;
  10079. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_SNI_WITH_FAKE_ANSWER_at_ssl; server_cb.on_result = verify_SNI_fake_matching;
  10080. test_wolfSSL_client_server(&client_cb, &server_cb);
  10081. /* sni abort - success */
  10082. fprintf(stderr, "\tsni abort - success\n");
  10083. client_cb.ctx_ready = use_SNI_at_ctx; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
  10084. server_cb.ctx_ready = use_MANDATORY_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_real_matching;
  10085. test_wolfSSL_client_server(&client_cb, &server_cb);
  10086. /* sni abort - abort when absent (ctx) */
  10087. fprintf(stderr, "\tsni abort - abort when absent (ctx)\n");
  10088. client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = verify_FATAL_ERROR_on_client;
  10089. server_cb.ctx_ready = use_MANDATORY_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_ABSENT_on_server;
  10090. test_wolfSSL_client_server(&client_cb, &server_cb);
  10091. /* sni abort - abort when absent (ssl) */
  10092. fprintf(stderr, "\tsni abort - abort when absent (ssl)\n");
  10093. client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = verify_FATAL_ERROR_on_client;
  10094. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_MANDATORY_SNI_at_ssl; server_cb.on_result = verify_SNI_ABSENT_on_server;
  10095. test_wolfSSL_client_server(&client_cb, &server_cb);
  10096. /* sni abort - success when overwritten */
  10097. fprintf(stderr, "\tsni abort - success when overwritten\n");
  10098. client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
  10099. server_cb.ctx_ready = use_MANDATORY_SNI_at_ctx; server_cb.ssl_ready = use_SNI_at_ssl; server_cb.on_result = verify_SNI_no_matching;
  10100. test_wolfSSL_client_server(&client_cb, &server_cb);
  10101. /* sni abort - success when allowing mismatches */
  10102. fprintf(stderr, "\tsni abort - success when allowing mismatches\n");
  10103. client_cb.ctx_ready = NULL; client_cb.ssl_ready = different_SNI_at_ssl; client_cb.on_result = NULL;
  10104. server_cb.ctx_ready = use_PSEUDO_MANDATORY_SNI_at_ctx; server_cb.ssl_ready = NULL; server_cb.on_result = verify_SNI_fake_matching;
  10105. test_wolfSSL_client_server(&client_cb, &server_cb);
  10106. }
  10107. res = TEST_RES_CHECK(1);
  10108. #endif /* !NO_WOLFSSL_CLIENT && !NO_WOLFSSL_SERVER */
  10109. return res;
  10110. }
  10111. static int test_wolfSSL_SNI_GetFromBuffer(void)
  10112. {
  10113. EXPECT_DECLS;
  10114. byte buff[] = { /* www.paypal.com */
  10115. 0x00, 0x00, 0x00, 0x00, 0xff, 0x01, 0x00, 0x00, 0x60, 0x03, 0x03, 0x5c,
  10116. 0xc4, 0xb3, 0x8c, 0x87, 0xef, 0xa4, 0x09, 0xe0, 0x02, 0xab, 0x86, 0xca,
  10117. 0x76, 0xf0, 0x9e, 0x01, 0x65, 0xf6, 0xa6, 0x06, 0x13, 0x1d, 0x0f, 0xa5,
  10118. 0x79, 0xb0, 0xd4, 0x77, 0x22, 0xeb, 0x1a, 0x00, 0x00, 0x16, 0x00, 0x6b,
  10119. 0x00, 0x67, 0x00, 0x39, 0x00, 0x33, 0x00, 0x3d, 0x00, 0x3c, 0x00, 0x35,
  10120. 0x00, 0x2f, 0x00, 0x05, 0x00, 0x04, 0x00, 0x0a, 0x01, 0x00, 0x00, 0x21,
  10121. 0x00, 0x00, 0x00, 0x13, 0x00, 0x11, 0x00, 0x00, 0x0e, 0x77, 0x77, 0x77,
  10122. 0x2e, 0x70, 0x61, 0x79, 0x70, 0x61, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x00,
  10123. 0x0d, 0x00, 0x06, 0x00, 0x04, 0x04, 0x01, 0x02, 0x01
  10124. };
  10125. byte buff2[] = { /* api.textmate.org */
  10126. 0x16, 0x03, 0x01, 0x00, 0xc6, 0x01, 0x00, 0x00, 0xc2, 0x03, 0x03, 0x52,
  10127. 0x8b, 0x7b, 0xca, 0x69, 0xec, 0x97, 0xd5, 0x08, 0x03, 0x50, 0xfe, 0x3b,
  10128. 0x99, 0xc3, 0x20, 0xce, 0xa5, 0xf6, 0x99, 0xa5, 0x71, 0xf9, 0x57, 0x7f,
  10129. 0x04, 0x38, 0xf6, 0x11, 0x0b, 0xb8, 0xd3, 0x00, 0x00, 0x5e, 0x00, 0xff,
  10130. 0xc0, 0x24, 0xc0, 0x23, 0xc0, 0x0a, 0xc0, 0x09, 0xc0, 0x07, 0xc0, 0x08,
  10131. 0xc0, 0x28, 0xc0, 0x27, 0xc0, 0x14, 0xc0, 0x13, 0xc0, 0x11, 0xc0, 0x12,
  10132. 0xc0, 0x26, 0xc0, 0x25, 0xc0, 0x2a, 0xc0, 0x29, 0xc0, 0x05, 0xc0, 0x04,
  10133. 0xc0, 0x02, 0xc0, 0x03, 0xc0, 0x0f, 0xc0, 0x0e, 0xc0, 0x0c, 0xc0, 0x0d,
  10134. 0x00, 0x3d, 0x00, 0x3c, 0x00, 0x2f, 0x00, 0x05, 0x00, 0x04, 0x00, 0x35,
  10135. 0x00, 0x0a, 0x00, 0x67, 0x00, 0x6b, 0x00, 0x33, 0x00, 0x39, 0x00, 0x16,
  10136. 0x00, 0xaf, 0x00, 0xae, 0x00, 0x8d, 0x00, 0x8c, 0x00, 0x8a, 0x00, 0x8b,
  10137. 0x00, 0xb1, 0x00, 0xb0, 0x00, 0x2c, 0x00, 0x3b, 0x01, 0x00, 0x00, 0x3b,
  10138. 0x00, 0x00, 0x00, 0x15, 0x00, 0x13, 0x00, 0x00, 0x10, 0x61, 0x70, 0x69,
  10139. 0x2e, 0x74, 0x65, 0x78, 0x74, 0x6d, 0x61, 0x74, 0x65, 0x2e, 0x6f, 0x72,
  10140. 0x67, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x06, 0x00, 0x17, 0x00, 0x18, 0x00,
  10141. 0x19, 0x00, 0x0b, 0x00, 0x02, 0x01, 0x00, 0x00, 0x0d, 0x00, 0x0c, 0x00,
  10142. 0x0a, 0x05, 0x01, 0x04, 0x01, 0x02, 0x01, 0x04, 0x03, 0x02, 0x03
  10143. };
  10144. byte buff3[] = { /* no sni extension */
  10145. 0x16, 0x03, 0x03, 0x00, 0x4d, 0x01, 0x00, 0x00, 0x49, 0x03, 0x03, 0xea,
  10146. 0xa1, 0x9f, 0x60, 0xdd, 0x52, 0x12, 0x13, 0xbd, 0x84, 0x34, 0xd5, 0x1c,
  10147. 0x38, 0x25, 0xa8, 0x97, 0xd2, 0xd5, 0xc6, 0x45, 0xaf, 0x1b, 0x08, 0xe4,
  10148. 0x1e, 0xbb, 0xdf, 0x9d, 0x39, 0xf0, 0x65, 0x00, 0x00, 0x16, 0x00, 0x6b,
  10149. 0x00, 0x67, 0x00, 0x39, 0x00, 0x33, 0x00, 0x3d, 0x00, 0x3c, 0x00, 0x35,
  10150. 0x00, 0x2f, 0x00, 0x05, 0x00, 0x04, 0x00, 0x0a, 0x01, 0x00, 0x00, 0x0a,
  10151. 0x00, 0x0d, 0x00, 0x06, 0x00, 0x04, 0x04, 0x01, 0x02, 0x01
  10152. };
  10153. byte buff4[] = { /* last extension has zero size */
  10154. 0x16, 0x03, 0x01, 0x00, 0xba, 0x01, 0x00, 0x00,
  10155. 0xb6, 0x03, 0x03, 0x83, 0xa3, 0xe6, 0xdc, 0x16, 0xa1, 0x43, 0xe9, 0x45,
  10156. 0x15, 0xbd, 0x64, 0xa9, 0xb6, 0x07, 0xb4, 0x50, 0xc6, 0xdd, 0xff, 0xc2,
  10157. 0xd3, 0x0d, 0x4f, 0x36, 0xb4, 0x41, 0x51, 0x61, 0xc1, 0xa5, 0x9e, 0x00,
  10158. 0x00, 0x28, 0xcc, 0x14, 0xcc, 0x13, 0xc0, 0x2b, 0xc0, 0x2f, 0x00, 0x9e,
  10159. 0xc0, 0x0a, 0xc0, 0x09, 0xc0, 0x13, 0xc0, 0x14, 0xc0, 0x07, 0xc0, 0x11,
  10160. 0x00, 0x33, 0x00, 0x32, 0x00, 0x39, 0x00, 0x9c, 0x00, 0x2f, 0x00, 0x35,
  10161. 0x00, 0x0a, 0x00, 0x05, 0x00, 0x04, 0x01, 0x00, 0x00, 0x65, 0xff, 0x01,
  10162. 0x00, 0x01, 0x00, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x06, 0x00, 0x17, 0x00,
  10163. 0x18, 0x00, 0x19, 0x00, 0x0b, 0x00, 0x02, 0x01, 0x00, 0x00, 0x23, 0x00,
  10164. 0x00, 0x33, 0x74, 0x00, 0x00, 0x00, 0x10, 0x00, 0x1b, 0x00, 0x19, 0x06,
  10165. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x33, 0x08, 0x73, 0x70, 0x64, 0x79, 0x2f,
  10166. 0x33, 0x2e, 0x31, 0x08, 0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31,
  10167. 0x75, 0x50, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x01, 0x00, 0x00, 0x00,
  10168. 0x00, 0x00, 0x0d, 0x00, 0x12, 0x00, 0x10, 0x04, 0x01, 0x05, 0x01, 0x02,
  10169. 0x01, 0x04, 0x03, 0x05, 0x03, 0x02, 0x03, 0x04, 0x02, 0x02, 0x02, 0x00,
  10170. 0x12, 0x00, 0x00
  10171. };
  10172. byte buff5[] = { /* SSL v2.0 client hello */
  10173. 0x00, 0x2b, 0x01, 0x03, 0x01, 0x00, 0x09, 0x00, 0x00,
  10174. /* dummy bytes below, just to pass size check */
  10175. 0xb6, 0x03, 0x03, 0x83, 0xa3, 0xe6, 0xdc, 0x16, 0xa1, 0x43, 0xe9, 0x45,
  10176. 0x15, 0xbd, 0x64, 0xa9, 0xb6, 0x07, 0xb4, 0x50, 0xc6, 0xdd, 0xff, 0xc2,
  10177. 0xd3, 0x0d, 0x4f, 0x36, 0xb4, 0x41, 0x51, 0x61, 0xc1, 0xa5, 0x9e, 0x00,
  10178. };
  10179. byte result[32] = {0};
  10180. word32 length = 32;
  10181. ExpectIntEQ(0, wolfSSL_SNI_GetFromBuffer(buff4, sizeof(buff4),
  10182. 0, result, &length));
  10183. ExpectIntEQ(0, wolfSSL_SNI_GetFromBuffer(buff3, sizeof(buff3),
  10184. 0, result, &length));
  10185. ExpectIntEQ(0, wolfSSL_SNI_GetFromBuffer(buff2, sizeof(buff2),
  10186. 1, result, &length));
  10187. ExpectIntEQ(WC_NO_ERR_TRACE(BUFFER_ERROR), wolfSSL_SNI_GetFromBuffer(buff, sizeof(buff),
  10188. 0, result, &length));
  10189. buff[0] = 0x16;
  10190. ExpectIntEQ(WC_NO_ERR_TRACE(BUFFER_ERROR), wolfSSL_SNI_GetFromBuffer(buff, sizeof(buff),
  10191. 0, result, &length));
  10192. buff[1] = 0x03;
  10193. ExpectIntEQ(WC_NO_ERR_TRACE(SNI_UNSUPPORTED), wolfSSL_SNI_GetFromBuffer(buff,
  10194. sizeof(buff), 0, result, &length));
  10195. buff[2] = 0x03;
  10196. ExpectIntEQ(WC_NO_ERR_TRACE(INCOMPLETE_DATA), wolfSSL_SNI_GetFromBuffer(buff,
  10197. sizeof(buff), 0, result, &length));
  10198. buff[4] = 0x64;
  10199. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SNI_GetFromBuffer(buff, sizeof(buff),
  10200. 0, result, &length));
  10201. if (EXPECT_SUCCESS())
  10202. result[length] = 0;
  10203. ExpectStrEQ("www.paypal.com", (const char*) result);
  10204. length = 32;
  10205. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SNI_GetFromBuffer(buff2, sizeof(buff2),
  10206. 0, result, &length));
  10207. if (EXPECT_SUCCESS())
  10208. result[length] = 0;
  10209. ExpectStrEQ("api.textmate.org", (const char*) result);
  10210. /* SSL v2.0 tests */
  10211. ExpectIntEQ(WC_NO_ERR_TRACE(SNI_UNSUPPORTED), wolfSSL_SNI_GetFromBuffer(buff5,
  10212. sizeof(buff5), 0, result, &length));
  10213. buff5[2] = 0x02;
  10214. ExpectIntEQ(WC_NO_ERR_TRACE(BUFFER_ERROR), wolfSSL_SNI_GetFromBuffer(buff5,
  10215. sizeof(buff5), 0, result, &length));
  10216. buff5[2] = 0x01; buff5[6] = 0x08;
  10217. ExpectIntEQ(WC_NO_ERR_TRACE(BUFFER_ERROR), wolfSSL_SNI_GetFromBuffer(buff5,
  10218. sizeof(buff5), 0, result, &length));
  10219. buff5[6] = 0x09; buff5[8] = 0x01;
  10220. ExpectIntEQ(WC_NO_ERR_TRACE(BUFFER_ERROR), wolfSSL_SNI_GetFromBuffer(buff5,
  10221. sizeof(buff5), 0, result, &length));
  10222. return EXPECT_RESULT();
  10223. }
  10224. #endif /* HAVE_SNI */
  10225. #endif /* HAVE_IO_TESTS_DEPENDENCIES */
  10226. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT) && \
  10227. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  10228. /* Dummy peer functions to satisfy the exporter/importer */
  10229. static int test_wolfSSL_dtls_export_peers_get_peer(WOLFSSL* ssl, char* ip,
  10230. int* ipSz, unsigned short* port, int* fam)
  10231. {
  10232. (void)ssl;
  10233. ip[0] = -1;
  10234. *ipSz = 1;
  10235. *port = 1;
  10236. *fam = 2;
  10237. return 1;
  10238. }
  10239. static int test_wolfSSL_dtls_export_peers_set_peer(WOLFSSL* ssl, char* ip,
  10240. int ipSz, unsigned short port, int fam)
  10241. {
  10242. (void)ssl;
  10243. if (ip[0] != -1 || ipSz != 1 || port != 1 || fam != 2)
  10244. return 0;
  10245. return 1;
  10246. }
  10247. static int test_wolfSSL_dtls_export_peers_on_handshake(WOLFSSL_CTX **ctx,
  10248. WOLFSSL **ssl)
  10249. {
  10250. EXPECT_DECLS;
  10251. unsigned char* sessionBuf = NULL;
  10252. unsigned int sessionSz = 0;
  10253. void* ioWriteCtx = wolfSSL_GetIOWriteCtx(*ssl);
  10254. void* ioReadCtx = wolfSSL_GetIOReadCtx(*ssl);
  10255. wolfSSL_CTX_SetIOGetPeer(*ctx, test_wolfSSL_dtls_export_peers_get_peer);
  10256. wolfSSL_CTX_SetIOSetPeer(*ctx, test_wolfSSL_dtls_export_peers_set_peer);
  10257. ExpectIntGE(wolfSSL_dtls_export(*ssl, NULL, &sessionSz), 0);
  10258. ExpectNotNull(sessionBuf =
  10259. (unsigned char*)XMALLOC(sessionSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER));
  10260. ExpectIntGE(wolfSSL_dtls_export(*ssl, sessionBuf, &sessionSz), 0);
  10261. wolfSSL_free(*ssl);
  10262. *ssl = NULL;
  10263. ExpectNotNull(*ssl = wolfSSL_new(*ctx));
  10264. ExpectIntGE(wolfSSL_dtls_import(*ssl, sessionBuf, sessionSz), 0);
  10265. wolfSSL_SetIOWriteCtx(*ssl, ioWriteCtx);
  10266. wolfSSL_SetIOReadCtx(*ssl, ioReadCtx);
  10267. XFREE(sessionBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10268. return EXPECT_RESULT();
  10269. }
  10270. #endif
  10271. static int test_wolfSSL_dtls_export_peers(void)
  10272. {
  10273. EXPECT_DECLS;
  10274. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_SESSION_EXPORT) && \
  10275. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  10276. test_ssl_cbf client_cbf;
  10277. test_ssl_cbf server_cbf;
  10278. size_t i, j;
  10279. struct test_params {
  10280. method_provider client_meth;
  10281. method_provider server_meth;
  10282. const char* dtls_version;
  10283. } params[] = {
  10284. #ifndef NO_OLD_TLS
  10285. {wolfDTLSv1_client_method, wolfDTLSv1_server_method, "1.0"},
  10286. #endif
  10287. {wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, "1.2"},
  10288. /* TODO DTLS 1.3 exporting not supported
  10289. #ifdef WOLFSSL_DTLS13
  10290. {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, "1.3"},
  10291. #endif
  10292. */
  10293. };
  10294. for (i = 0; i < sizeof(params)/sizeof(*params); i++) {
  10295. for (j = 0; j <= 0b11; j++) {
  10296. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  10297. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  10298. printf("\n\tTesting DTLS %s connection;", params[i].dtls_version);
  10299. client_cbf.method = params[i].client_meth;
  10300. server_cbf.method = params[i].server_meth;
  10301. if (j & 0b01) {
  10302. client_cbf.on_handshake =
  10303. test_wolfSSL_dtls_export_peers_on_handshake;
  10304. printf(" With client export;");
  10305. }
  10306. if (j & 0b10) {
  10307. server_cbf.on_handshake =
  10308. test_wolfSSL_dtls_export_peers_on_handshake;
  10309. printf(" With server export;");
  10310. }
  10311. printf("\n");
  10312. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  10313. &server_cbf, NULL), TEST_SUCCESS);
  10314. if (!EXPECT_SUCCESS())
  10315. break;
  10316. }
  10317. }
  10318. #endif
  10319. return EXPECT_RESULT();
  10320. }
  10321. static int test_wolfSSL_UseTrustedCA(void)
  10322. {
  10323. EXPECT_DECLS;
  10324. #if defined(HAVE_TRUSTED_CA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) \
  10325. && !defined(NO_RSA)
  10326. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  10327. WOLFSSL_CTX *ctx = NULL;
  10328. WOLFSSL *ssl = NULL;
  10329. byte id[20];
  10330. #ifndef NO_WOLFSSL_SERVER
  10331. ExpectNotNull((ctx = wolfSSL_CTX_new(wolfSSLv23_server_method())));
  10332. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, WOLFSSL_FILETYPE_PEM));
  10333. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, WOLFSSL_FILETYPE_PEM));
  10334. #else
  10335. ExpectNotNull((ctx = wolfSSL_CTX_new(wolfSSLv23_client_method())));
  10336. #endif
  10337. ExpectNotNull((ssl = wolfSSL_new(ctx)));
  10338. XMEMSET(id, 0, sizeof(id));
  10339. /* error cases */
  10340. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(NULL, 0, NULL, 0));
  10341. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10342. WOLFSSL_TRUSTED_CA_CERT_SHA1+1, NULL, 0));
  10343. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10344. WOLFSSL_TRUSTED_CA_CERT_SHA1, NULL, 0));
  10345. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10346. WOLFSSL_TRUSTED_CA_CERT_SHA1, id, 5));
  10347. #ifdef NO_SHA
  10348. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10349. WOLFSSL_TRUSTED_CA_KEY_SHA1, id, sizeof(id)));
  10350. #endif
  10351. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10352. WOLFSSL_TRUSTED_CA_X509_NAME, id, 0));
  10353. /* success cases */
  10354. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10355. WOLFSSL_TRUSTED_CA_PRE_AGREED, NULL, 0));
  10356. #ifndef NO_SHA
  10357. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10358. WOLFSSL_TRUSTED_CA_KEY_SHA1, id, sizeof(id)));
  10359. #endif
  10360. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseTrustedCA(ssl,
  10361. WOLFSSL_TRUSTED_CA_X509_NAME, id, 5));
  10362. wolfSSL_free(ssl);
  10363. wolfSSL_CTX_free(ctx);
  10364. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  10365. #endif /* HAVE_TRUSTED_CA */
  10366. return EXPECT_RESULT();
  10367. }
  10368. static int test_wolfSSL_UseMaxFragment(void)
  10369. {
  10370. EXPECT_DECLS;
  10371. #if defined(HAVE_MAX_FRAGMENT) && !defined(NO_CERTS) && \
  10372. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  10373. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  10374. #ifndef NO_WOLFSSL_SERVER
  10375. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfSSLv23_server_method());
  10376. #else
  10377. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10378. #endif
  10379. WOLFSSL *ssl = NULL;
  10380. #ifdef OPENSSL_EXTRA
  10381. int (*UseMaxFragment)(SSL *s, unsigned char mode);
  10382. int (*CTX_UseMaxFragment)(SSL_CTX *c, unsigned char mode);
  10383. #else
  10384. int (*UseMaxFragment)(WOLFSSL *s, unsigned char mode);
  10385. int (*CTX_UseMaxFragment)(WOLFSSL_CTX *c, unsigned char mode);
  10386. #endif
  10387. #ifndef NO_WOLFSSL_SERVER
  10388. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, WOLFSSL_FILETYPE_PEM));
  10389. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, WOLFSSL_FILETYPE_PEM));
  10390. #endif
  10391. ExpectNotNull(ctx);
  10392. ExpectNotNull(ssl = wolfSSL_new(ctx));
  10393. #ifdef OPENSSL_EXTRA
  10394. CTX_UseMaxFragment = SSL_CTX_set_tlsext_max_fragment_length;
  10395. UseMaxFragment = SSL_set_tlsext_max_fragment_length;
  10396. #else
  10397. UseMaxFragment = wolfSSL_UseMaxFragment;
  10398. CTX_UseMaxFragment = wolfSSL_CTX_UseMaxFragment;
  10399. #endif
  10400. /* error cases */
  10401. ExpectIntNE(WOLFSSL_SUCCESS, CTX_UseMaxFragment(NULL, WOLFSSL_MFL_2_9));
  10402. ExpectIntNE(WOLFSSL_SUCCESS, UseMaxFragment( NULL, WOLFSSL_MFL_2_9));
  10403. ExpectIntNE(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_MIN-1));
  10404. ExpectIntNE(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_MAX+1));
  10405. ExpectIntNE(WOLFSSL_SUCCESS, UseMaxFragment(ssl, WOLFSSL_MFL_MIN-1));
  10406. ExpectIntNE(WOLFSSL_SUCCESS, UseMaxFragment(ssl, WOLFSSL_MFL_MAX+1));
  10407. /* success case */
  10408. #ifdef OPENSSL_EXTRA
  10409. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_8));
  10410. #else
  10411. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_8));
  10412. #endif
  10413. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_9));
  10414. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_10));
  10415. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_11));
  10416. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_12));
  10417. #ifdef OPENSSL_EXTRA
  10418. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_13));
  10419. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), UseMaxFragment( ssl, WOLFSSL_MFL_2_8));
  10420. #else
  10421. ExpectIntEQ(WOLFSSL_SUCCESS, CTX_UseMaxFragment(ctx, WOLFSSL_MFL_2_13));
  10422. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_8));
  10423. #endif
  10424. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_9));
  10425. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_10));
  10426. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_11));
  10427. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_12));
  10428. #ifdef OPENSSL_EXTRA
  10429. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), UseMaxFragment( ssl, WOLFSSL_MFL_2_13));
  10430. #else
  10431. ExpectIntEQ(WOLFSSL_SUCCESS, UseMaxFragment( ssl, WOLFSSL_MFL_2_13));
  10432. #endif
  10433. wolfSSL_free(ssl);
  10434. wolfSSL_CTX_free(ctx);
  10435. #if defined(OPENSSL_EXTRA) && defined(HAVE_MAX_FRAGMENT) && \
  10436. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  10437. /* check negotiated max fragment size */
  10438. {
  10439. WOLFSSL *ssl_c = NULL;
  10440. WOLFSSL *ssl_s = NULL;
  10441. struct test_memio_ctx test_ctx;
  10442. WOLFSSL_CTX *ctx_c = NULL;
  10443. WOLFSSL_CTX *ctx_s = NULL;
  10444. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  10445. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  10446. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  10447. ExpectIntEQ(wolfSSL_UseMaxFragment(ssl_c, WOLFSSL_MFL_2_8),
  10448. WOLFSSL_SUCCESS);
  10449. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  10450. #ifndef NO_SESSION_CACHE
  10451. ExpectIntEQ(SSL_SESSION_get_max_fragment_length(
  10452. wolfSSL_get_session(ssl_c)), WOLFSSL_MFL_2_8);
  10453. #endif
  10454. wolfSSL_free(ssl_c);
  10455. wolfSSL_free(ssl_s);
  10456. wolfSSL_CTX_free(ctx_c);
  10457. wolfSSL_CTX_free(ctx_s);
  10458. }
  10459. #endif
  10460. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  10461. #endif
  10462. return EXPECT_RESULT();
  10463. }
  10464. static int test_wolfSSL_UseTruncatedHMAC(void)
  10465. {
  10466. EXPECT_DECLS;
  10467. #if defined(HAVE_TRUNCATED_HMAC) && !defined(NO_CERTS) && \
  10468. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  10469. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  10470. #ifndef NO_WOLFSSL_SERVER
  10471. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfSSLv23_server_method());
  10472. #else
  10473. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10474. #endif
  10475. WOLFSSL *ssl = NULL;
  10476. ExpectNotNull(ctx);
  10477. #ifndef NO_WOLFSSL_SERVER
  10478. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile, WOLFSSL_FILETYPE_PEM));
  10479. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, WOLFSSL_FILETYPE_PEM));
  10480. #endif
  10481. ExpectNotNull(ssl = wolfSSL_new(ctx));
  10482. /* error cases */
  10483. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseTruncatedHMAC(NULL));
  10484. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseTruncatedHMAC(NULL));
  10485. /* success case */
  10486. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseTruncatedHMAC(ctx));
  10487. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseTruncatedHMAC(ssl));
  10488. wolfSSL_free(ssl);
  10489. wolfSSL_CTX_free(ctx);
  10490. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  10491. #endif
  10492. return EXPECT_RESULT();
  10493. }
  10494. static int test_wolfSSL_UseSupportedCurve(void)
  10495. {
  10496. EXPECT_DECLS;
  10497. #if defined(HAVE_SUPPORTED_CURVES) && !defined(NO_WOLFSSL_CLIENT) && \
  10498. !defined(NO_TLS)
  10499. WOLFSSL_CTX* ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10500. WOLFSSL *ssl = wolfSSL_new(ctx);
  10501. ExpectNotNull(ctx);
  10502. ExpectNotNull(ssl);
  10503. /* error cases */
  10504. ExpectIntNE(WOLFSSL_SUCCESS,
  10505. wolfSSL_CTX_UseSupportedCurve(NULL, WOLFSSL_ECC_SECP256R1));
  10506. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSupportedCurve(ctx, 0));
  10507. ExpectIntNE(WOLFSSL_SUCCESS,
  10508. wolfSSL_UseSupportedCurve(NULL, WOLFSSL_ECC_SECP256R1));
  10509. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSupportedCurve(ssl, 0));
  10510. /* success case */
  10511. ExpectIntEQ(WOLFSSL_SUCCESS,
  10512. wolfSSL_CTX_UseSupportedCurve(ctx, WOLFSSL_ECC_SECP256R1));
  10513. ExpectIntEQ(WOLFSSL_SUCCESS,
  10514. wolfSSL_UseSupportedCurve(ssl, WOLFSSL_ECC_SECP256R1));
  10515. wolfSSL_free(ssl);
  10516. wolfSSL_CTX_free(ctx);
  10517. #endif
  10518. return EXPECT_RESULT();
  10519. }
  10520. #if defined(HAVE_ALPN) && defined(HAVE_IO_TESTS_DEPENDENCIES)
  10521. static void verify_ALPN_FATAL_ERROR_on_client(WOLFSSL* ssl)
  10522. {
  10523. AssertIntEQ(WC_NO_ERR_TRACE(UNKNOWN_ALPN_PROTOCOL_NAME_E), wolfSSL_get_error(ssl, 0));
  10524. }
  10525. static void use_ALPN_all(WOLFSSL* ssl)
  10526. {
  10527. /* http/1.1,spdy/1,spdy/2,spdy/3 */
  10528. char alpn_list[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31, 0x2c,
  10529. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x31, 0x2c,
  10530. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x32, 0x2c,
  10531. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10532. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, alpn_list, sizeof(alpn_list),
  10533. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10534. }
  10535. static void use_ALPN_all_continue(WOLFSSL* ssl)
  10536. {
  10537. /* http/1.1,spdy/1,spdy/2,spdy/3 */
  10538. char alpn_list[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31, 0x2c,
  10539. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x31, 0x2c,
  10540. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x32, 0x2c,
  10541. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10542. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, alpn_list, sizeof(alpn_list),
  10543. WOLFSSL_ALPN_CONTINUE_ON_MISMATCH));
  10544. }
  10545. static void use_ALPN_one(WOLFSSL* ssl)
  10546. {
  10547. /* spdy/2 */
  10548. char proto[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x32};
  10549. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, proto, sizeof(proto),
  10550. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10551. }
  10552. static void use_ALPN_unknown(WOLFSSL* ssl)
  10553. {
  10554. /* http/2.0 */
  10555. char proto[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x32, 0x2e, 0x30};
  10556. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, proto, sizeof(proto),
  10557. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10558. }
  10559. static void use_ALPN_unknown_continue(WOLFSSL* ssl)
  10560. {
  10561. /* http/2.0 */
  10562. char proto[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x32, 0x2e, 0x30};
  10563. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, proto, sizeof(proto),
  10564. WOLFSSL_ALPN_CONTINUE_ON_MISMATCH));
  10565. }
  10566. static void verify_ALPN_not_matching_spdy3(WOLFSSL* ssl)
  10567. {
  10568. /* spdy/3 */
  10569. char nego_proto[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10570. char *proto = NULL;
  10571. word16 protoSz = 0;
  10572. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_ALPN_GetProtocol(ssl, &proto, &protoSz));
  10573. /* check value */
  10574. AssertIntNE(1, sizeof(nego_proto) == protoSz);
  10575. if (proto) {
  10576. AssertIntNE(0, XMEMCMP(nego_proto, proto, sizeof(nego_proto)));
  10577. }
  10578. }
  10579. static void verify_ALPN_not_matching_continue(WOLFSSL* ssl)
  10580. {
  10581. char *proto = NULL;
  10582. word16 protoSz = 0;
  10583. AssertIntEQ(WC_NO_ERR_TRACE(WOLFSSL_ALPN_NOT_FOUND),
  10584. wolfSSL_ALPN_GetProtocol(ssl, &proto, &protoSz));
  10585. /* check value */
  10586. AssertIntEQ(1, (0 == protoSz));
  10587. AssertIntEQ(1, (NULL == proto));
  10588. }
  10589. static void verify_ALPN_matching_http1(WOLFSSL* ssl)
  10590. {
  10591. /* http/1.1 */
  10592. char nego_proto[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31};
  10593. char *proto;
  10594. word16 protoSz = 0;
  10595. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_ALPN_GetProtocol(ssl, &proto, &protoSz));
  10596. /* check value */
  10597. AssertIntEQ(1, sizeof(nego_proto) == protoSz);
  10598. AssertIntEQ(0, XMEMCMP(nego_proto, proto, protoSz));
  10599. }
  10600. static void verify_ALPN_matching_spdy2(WOLFSSL* ssl)
  10601. {
  10602. /* spdy/2 */
  10603. char nego_proto[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x32};
  10604. char *proto;
  10605. word16 protoSz = 0;
  10606. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_ALPN_GetProtocol(ssl, &proto, &protoSz));
  10607. /* check value */
  10608. AssertIntEQ(1, sizeof(nego_proto) == protoSz);
  10609. AssertIntEQ(0, XMEMCMP(nego_proto, proto, protoSz));
  10610. }
  10611. static void verify_ALPN_client_list(WOLFSSL* ssl)
  10612. {
  10613. /* http/1.1,spdy/1,spdy/2,spdy/3 */
  10614. char alpn_list[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31, 0x2c,
  10615. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x31, 0x2c,
  10616. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x32, 0x2c,
  10617. 0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10618. char *clist = NULL;
  10619. word16 clistSz = 0;
  10620. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_ALPN_GetPeerProtocol(ssl, &clist,
  10621. &clistSz));
  10622. /* check value */
  10623. AssertIntEQ(1, sizeof(alpn_list) == clistSz);
  10624. AssertIntEQ(0, XMEMCMP(alpn_list, clist, clistSz));
  10625. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_ALPN_FreePeerProtocol(ssl, &clist));
  10626. }
  10627. #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \
  10628. defined(WOLFSSL_HAPROXY) || defined(HAVE_LIGHTY)
  10629. /* ALPN select callback, success with spdy/2 */
  10630. static int select_ALPN_spdy2(WOLFSSL *ssl, const unsigned char **out,
  10631. unsigned char *outlen, const unsigned char *in,
  10632. unsigned int inlen, void *arg)
  10633. {
  10634. /* spdy/2 */
  10635. const char proto[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x32};
  10636. (void)ssl;
  10637. (void)arg;
  10638. /* adding +1 since LEN byte comes first */
  10639. if (inlen < sizeof(proto) + 1) {
  10640. return SSL_TLSEXT_ERR_ALERT_FATAL;
  10641. }
  10642. if (XMEMCMP(in + 1, proto, sizeof(proto)) == 0) {
  10643. *out = in + 1;
  10644. *outlen = (unsigned char)sizeof(proto);
  10645. return SSL_TLSEXT_ERR_OK;
  10646. }
  10647. return SSL_TLSEXT_ERR_ALERT_FATAL;
  10648. }
  10649. /* ALPN select callback, force failure */
  10650. static int select_ALPN_failure(WOLFSSL *ssl, const unsigned char **out,
  10651. unsigned char *outlen, const unsigned char *in,
  10652. unsigned int inlen, void *arg)
  10653. {
  10654. (void)ssl;
  10655. (void)out;
  10656. (void)outlen;
  10657. (void)in;
  10658. (void)inlen;
  10659. (void)arg;
  10660. return SSL_TLSEXT_ERR_ALERT_FATAL;
  10661. }
  10662. static void use_ALPN_spdy2_callback(WOLFSSL* ssl)
  10663. {
  10664. wolfSSL_set_alpn_select_cb(ssl, select_ALPN_spdy2, NULL);
  10665. }
  10666. static void use_ALPN_failure_callback(WOLFSSL* ssl)
  10667. {
  10668. wolfSSL_set_alpn_select_cb(ssl, select_ALPN_failure, NULL);
  10669. }
  10670. #endif /* OPENSSL_ALL | NGINX | HAPROXY | LIGHTY | QUIC */
  10671. static int test_wolfSSL_UseALPN_connection(void)
  10672. {
  10673. int res = TEST_SKIPPED;
  10674. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  10675. callback_functions client_cb;
  10676. callback_functions server_cb;
  10677. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  10678. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  10679. client_cb.method = wolfSSLv23_client_method;
  10680. server_cb.method = wolfSSLv23_server_method;
  10681. client_cb.devId = testDevId;
  10682. server_cb.devId = testDevId;
  10683. /* success case same list */
  10684. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all; client_cb.on_result = NULL;
  10685. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_all; server_cb.on_result = verify_ALPN_matching_http1;
  10686. test_wolfSSL_client_server(&client_cb, &server_cb);
  10687. /* success case only one for server */
  10688. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all; client_cb.on_result = NULL;
  10689. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_one; server_cb.on_result = verify_ALPN_matching_spdy2;
  10690. test_wolfSSL_client_server(&client_cb, &server_cb);
  10691. /* success case only one for client */
  10692. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_one; client_cb.on_result = NULL;
  10693. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_all; server_cb.on_result = verify_ALPN_matching_spdy2;
  10694. test_wolfSSL_client_server(&client_cb, &server_cb);
  10695. /* success case none for client */
  10696. client_cb.ctx_ready = NULL; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
  10697. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_all; server_cb.on_result = NULL;
  10698. test_wolfSSL_client_server(&client_cb, &server_cb);
  10699. /* success case mismatch behavior but option 'continue' set */
  10700. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all_continue; client_cb.on_result = verify_ALPN_not_matching_continue;
  10701. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_unknown_continue; server_cb.on_result = NULL;
  10702. test_wolfSSL_client_server(&client_cb, &server_cb);
  10703. /* success case read protocol send by client */
  10704. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all; client_cb.on_result = NULL;
  10705. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_one; server_cb.on_result = verify_ALPN_client_list;
  10706. test_wolfSSL_client_server(&client_cb, &server_cb);
  10707. /* mismatch behavior with same list
  10708. * the first and only this one must be taken */
  10709. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all; client_cb.on_result = NULL;
  10710. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_all; server_cb.on_result = verify_ALPN_not_matching_spdy3;
  10711. test_wolfSSL_client_server(&client_cb, &server_cb);
  10712. /* default mismatch behavior */
  10713. client_cb.ctx_ready = NULL; client_cb.ssl_ready = use_ALPN_all; client_cb.on_result = NULL;
  10714. server_cb.ctx_ready = NULL; server_cb.ssl_ready = use_ALPN_unknown; server_cb.on_result = verify_ALPN_FATAL_ERROR_on_client;
  10715. test_wolfSSL_client_server(&client_cb, &server_cb);
  10716. #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \
  10717. defined(WOLFSSL_HAPROXY) || defined(HAVE_LIGHTY)
  10718. /* WOLFSSL-level ALPN select callback tests */
  10719. /* Callback: success (one protocol, spdy/2) */
  10720. client_cb.ctx_ready = NULL;
  10721. client_cb.ssl_ready = use_ALPN_one;
  10722. client_cb.on_result = verify_ALPN_matching_spdy2;
  10723. server_cb.ctx_ready = NULL;
  10724. server_cb.ssl_ready = use_ALPN_spdy2_callback;
  10725. server_cb.on_result = verify_ALPN_matching_spdy2;
  10726. test_wolfSSL_client_server(&client_cb, &server_cb);
  10727. /* Callback: failure (one client protocol, spdy/2) */
  10728. client_cb.ctx_ready = NULL;
  10729. client_cb.ssl_ready = use_ALPN_one;
  10730. client_cb.on_result = NULL;
  10731. server_cb.ctx_ready = NULL;
  10732. server_cb.ssl_ready = use_ALPN_failure_callback;
  10733. server_cb.on_result = verify_ALPN_FATAL_ERROR_on_client;
  10734. test_wolfSSL_client_server(&client_cb, &server_cb);
  10735. #endif /* OPENSSL_ALL | NGINX | HAPROXY | LIGHTY */
  10736. res = TEST_RES_CHECK(1);
  10737. #endif /* !NO_WOLFSSL_CLIENT && !NO_WOLFSSL_SERVER */
  10738. return res;
  10739. }
  10740. static int test_wolfSSL_UseALPN_params(void)
  10741. {
  10742. EXPECT_DECLS;
  10743. #ifndef NO_WOLFSSL_CLIENT
  10744. /* "http/1.1" */
  10745. char http1[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31};
  10746. /* "spdy/1" */
  10747. char spdy1[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x31};
  10748. /* "spdy/2" */
  10749. char spdy2[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x32};
  10750. /* "spdy/3" */
  10751. char spdy3[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10752. char buff[256];
  10753. word32 idx;
  10754. WOLFSSL_CTX *ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10755. WOLFSSL *ssl = wolfSSL_new(ctx);
  10756. ExpectNotNull(ctx);
  10757. ExpectNotNull(ssl);
  10758. /* error cases */
  10759. ExpectIntNE(WOLFSSL_SUCCESS,
  10760. wolfSSL_UseALPN(NULL, http1, sizeof(http1),
  10761. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10762. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, NULL, 0,
  10763. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10764. /* success case */
  10765. /* http1 only */
  10766. ExpectIntEQ(WOLFSSL_SUCCESS,
  10767. wolfSSL_UseALPN(ssl, http1, sizeof(http1),
  10768. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10769. /* http1, spdy1 */
  10770. XMEMCPY(buff, http1, sizeof(http1));
  10771. idx = sizeof(http1);
  10772. buff[idx++] = ',';
  10773. XMEMCPY(buff+idx, spdy1, sizeof(spdy1));
  10774. idx += sizeof(spdy1);
  10775. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, buff, idx,
  10776. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10777. /* http1, spdy2, spdy1 */
  10778. XMEMCPY(buff, http1, sizeof(http1));
  10779. idx = sizeof(http1);
  10780. buff[idx++] = ',';
  10781. XMEMCPY(buff+idx, spdy2, sizeof(spdy2));
  10782. idx += sizeof(spdy2);
  10783. buff[idx++] = ',';
  10784. XMEMCPY(buff+idx, spdy1, sizeof(spdy1));
  10785. idx += sizeof(spdy1);
  10786. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, buff, idx,
  10787. WOLFSSL_ALPN_FAILED_ON_MISMATCH));
  10788. /* spdy3, http1, spdy2, spdy1 */
  10789. XMEMCPY(buff, spdy3, sizeof(spdy3));
  10790. idx = sizeof(spdy3);
  10791. buff[idx++] = ',';
  10792. XMEMCPY(buff+idx, http1, sizeof(http1));
  10793. idx += sizeof(http1);
  10794. buff[idx++] = ',';
  10795. XMEMCPY(buff+idx, spdy2, sizeof(spdy2));
  10796. idx += sizeof(spdy2);
  10797. buff[idx++] = ',';
  10798. XMEMCPY(buff+idx, spdy1, sizeof(spdy1));
  10799. idx += sizeof(spdy1);
  10800. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseALPN(ssl, buff, idx,
  10801. WOLFSSL_ALPN_CONTINUE_ON_MISMATCH));
  10802. wolfSSL_free(ssl);
  10803. wolfSSL_CTX_free(ctx);
  10804. #endif
  10805. return EXPECT_RESULT();
  10806. }
  10807. #endif /* HAVE_ALPN */
  10808. #ifdef HAVE_ALPN_PROTOS_SUPPORT
  10809. static void CTX_set_alpn_protos(SSL_CTX *ctx)
  10810. {
  10811. unsigned char p[] = {
  10812. 8, 'h', 't', 't', 'p', '/', '1', '.', '1',
  10813. 6, 's', 'p', 'd', 'y', '/', '2',
  10814. 6, 's', 'p', 'd', 'y', '/', '1',
  10815. };
  10816. unsigned char p_len = sizeof(p);
  10817. int ret;
  10818. ret = SSL_CTX_set_alpn_protos(ctx, p, p_len);
  10819. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  10820. AssertIntEQ(ret, 0);
  10821. #else
  10822. AssertIntEQ(ret, SSL_SUCCESS);
  10823. #endif
  10824. }
  10825. static void set_alpn_protos(SSL* ssl)
  10826. {
  10827. unsigned char p[] = {
  10828. 6, 's', 'p', 'd', 'y', '/', '3',
  10829. 8, 'h', 't', 't', 'p', '/', '1', '.', '1',
  10830. 6, 's', 'p', 'd', 'y', '/', '2',
  10831. 6, 's', 'p', 'd', 'y', '/', '1',
  10832. };
  10833. unsigned char p_len = sizeof(p);
  10834. int ret;
  10835. ret = SSL_set_alpn_protos(ssl, p, p_len);
  10836. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  10837. AssertIntEQ(ret, 0);
  10838. #else
  10839. AssertIntEQ(ret, SSL_SUCCESS);
  10840. #endif
  10841. }
  10842. static void verify_alpn_matching_spdy3(WOLFSSL* ssl)
  10843. {
  10844. /* "spdy/3" */
  10845. char nego_proto[] = {0x73, 0x70, 0x64, 0x79, 0x2f, 0x33};
  10846. const unsigned char *proto;
  10847. unsigned int protoSz = 0;
  10848. SSL_get0_alpn_selected(ssl, &proto, &protoSz);
  10849. /* check value */
  10850. AssertIntEQ(1, sizeof(nego_proto) == protoSz);
  10851. AssertIntEQ(0, XMEMCMP(nego_proto, proto, protoSz));
  10852. }
  10853. static void verify_alpn_matching_http1(WOLFSSL* ssl)
  10854. {
  10855. /* "http/1.1" */
  10856. char nego_proto[] = {0x68, 0x74, 0x74, 0x70, 0x2f, 0x31, 0x2e, 0x31};
  10857. const unsigned char *proto;
  10858. unsigned int protoSz = 0;
  10859. SSL_get0_alpn_selected(ssl, &proto, &protoSz);
  10860. /* check value */
  10861. AssertIntEQ(1, sizeof(nego_proto) == protoSz);
  10862. AssertIntEQ(0, XMEMCMP(nego_proto, proto, protoSz));
  10863. }
  10864. static int test_wolfSSL_set_alpn_protos(void)
  10865. {
  10866. int res = TEST_SKIPPED;
  10867. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  10868. callback_functions client_cb;
  10869. callback_functions server_cb;
  10870. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  10871. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  10872. client_cb.method = wolfSSLv23_client_method;
  10873. server_cb.method = wolfSSLv23_server_method;
  10874. client_cb.devId = testDevId;
  10875. server_cb.devId = testDevId;
  10876. /* use CTX_alpn_protos */
  10877. client_cb.ctx_ready = CTX_set_alpn_protos; client_cb.ssl_ready = NULL; client_cb.on_result = NULL;
  10878. server_cb.ctx_ready = CTX_set_alpn_protos; server_cb.ssl_ready = NULL; server_cb.on_result = verify_alpn_matching_http1;
  10879. test_wolfSSL_client_server(&client_cb, &server_cb);
  10880. /* use set_alpn_protos */
  10881. client_cb.ctx_ready = NULL; client_cb.ssl_ready = set_alpn_protos; client_cb.on_result = NULL;
  10882. server_cb.ctx_ready = NULL; server_cb.ssl_ready = set_alpn_protos; server_cb.on_result = verify_alpn_matching_spdy3;
  10883. test_wolfSSL_client_server(&client_cb, &server_cb);
  10884. res = TEST_SUCCESS;
  10885. #endif /* !NO_WOLFSSL_CLIENT && !NO_WOLFSSL_SERVER */
  10886. return res;
  10887. }
  10888. #endif /* HAVE_ALPN_PROTOS_SUPPORT */
  10889. static int test_wolfSSL_DisableExtendedMasterSecret(void)
  10890. {
  10891. EXPECT_DECLS;
  10892. #if defined(HAVE_EXTENDED_MASTER) && !defined(NO_WOLFSSL_CLIENT)
  10893. WOLFSSL_CTX *ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10894. WOLFSSL *ssl = wolfSSL_new(ctx);
  10895. ExpectNotNull(ctx);
  10896. ExpectNotNull(ssl);
  10897. /* error cases */
  10898. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_DisableExtendedMasterSecret(NULL));
  10899. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_DisableExtendedMasterSecret(NULL));
  10900. /* success cases */
  10901. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_DisableExtendedMasterSecret(ctx));
  10902. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_DisableExtendedMasterSecret(ssl));
  10903. wolfSSL_free(ssl);
  10904. wolfSSL_CTX_free(ctx);
  10905. #endif
  10906. return EXPECT_RESULT();
  10907. }
  10908. static int test_wolfSSL_wolfSSL_UseSecureRenegotiation(void)
  10909. {
  10910. EXPECT_DECLS;
  10911. #if defined(HAVE_SECURE_RENEGOTIATION) && !defined(NO_WOLFSSL_CLIENT)
  10912. WOLFSSL_CTX *ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  10913. WOLFSSL *ssl = wolfSSL_new(ctx);
  10914. ExpectNotNull(ctx);
  10915. ExpectNotNull(ssl);
  10916. /* error cases */
  10917. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSecureRenegotiation(NULL));
  10918. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_UseSecureRenegotiation(NULL));
  10919. /* success cases */
  10920. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSecureRenegotiation(ctx));
  10921. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSecureRenegotiation(ssl));
  10922. wolfSSL_free(ssl);
  10923. wolfSSL_CTX_free(ctx);
  10924. #endif
  10925. return EXPECT_RESULT();
  10926. }
  10927. /* Test reconnecting with a different ciphersuite after a renegotiation. */
  10928. static int test_wolfSSL_SCR_Reconnect(void)
  10929. {
  10930. EXPECT_DECLS;
  10931. #if defined(HAVE_SECURE_RENEGOTIATION) && \
  10932. defined(BUILD_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) && \
  10933. defined(BUILD_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256) && \
  10934. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  10935. struct test_memio_ctx test_ctx;
  10936. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  10937. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  10938. byte data;
  10939. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  10940. test_ctx.c_ciphers = "ECDHE-RSA-AES256-GCM-SHA384";
  10941. test_ctx.s_ciphers =
  10942. "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-CHACHA20-POLY1305";
  10943. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  10944. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  10945. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSecureRenegotiation(ctx_c));
  10946. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_UseSecureRenegotiation(ctx_s));
  10947. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSecureRenegotiation(ssl_c));
  10948. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSecureRenegotiation(ssl_s));
  10949. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  10950. /* WOLFSSL_FATAL_ERROR since it will block */
  10951. ExpectIntEQ(wolfSSL_Rehandshake(ssl_s), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  10952. ExpectIntEQ(wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  10953. WOLFSSL_ERROR_WANT_READ);
  10954. ExpectIntEQ(wolfSSL_read(ssl_c, &data, 1), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  10955. ExpectIntEQ(wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  10956. WOLFSSL_ERROR_WANT_READ);
  10957. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  10958. wolfSSL_free(ssl_c);
  10959. ssl_c = NULL;
  10960. wolfSSL_free(ssl_s);
  10961. ssl_s = NULL;
  10962. wolfSSL_CTX_free(ctx_c);
  10963. ctx_c = NULL;
  10964. test_ctx.c_ciphers = "ECDHE-RSA-CHACHA20-POLY1305";
  10965. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  10966. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  10967. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  10968. wolfSSL_free(ssl_s);
  10969. wolfSSL_free(ssl_c);
  10970. wolfSSL_CTX_free(ctx_s);
  10971. wolfSSL_CTX_free(ctx_c);
  10972. #endif
  10973. return EXPECT_RESULT();
  10974. }
  10975. #if !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_SERVER) && \
  10976. (!defined(NO_RSA) || defined(HAVE_ECC))
  10977. /* Called when writing. */
  10978. static int DummySend(WOLFSSL* ssl, char* buf, int sz, void* ctx)
  10979. {
  10980. (void)ssl;
  10981. (void)buf;
  10982. (void)sz;
  10983. (void)ctx;
  10984. /* Force error return from wolfSSL_accept_TLSv13(). */
  10985. return WANT_WRITE;
  10986. }
  10987. /* Called when reading. */
  10988. static int BufferInfoRecv(WOLFSSL* ssl, char* buf, int sz, void* ctx)
  10989. {
  10990. WOLFSSL_BUFFER_INFO* msg = (WOLFSSL_BUFFER_INFO*)ctx;
  10991. int len = (int)msg->length;
  10992. (void)ssl;
  10993. (void)sz;
  10994. /* Pass back as much of message as will fit in buffer. */
  10995. if (len > sz)
  10996. len = sz;
  10997. XMEMCPY(buf, msg->buffer, len);
  10998. /* Move over returned data. */
  10999. msg->buffer += len;
  11000. msg->length -= (word32)len;
  11001. /* Amount actually copied. */
  11002. return len;
  11003. }
  11004. #endif
  11005. /* Test the detection of duplicate known TLS extensions.
  11006. * Specifically in a ClientHello.
  11007. */
  11008. static int test_tls_ext_duplicate(void)
  11009. {
  11010. EXPECT_DECLS;
  11011. #if !defined(NO_WOLFSSL_SERVER) && (!defined(NO_RSA) || defined(HAVE_ECC)) && \
  11012. !defined(NO_FILESYSTEM)
  11013. const unsigned char clientHelloDupTlsExt[] = {
  11014. 0x16, 0x03, 0x03, 0x00, 0x6a, 0x01, 0x00, 0x00,
  11015. 0x66, 0x03, 0x03, 0xf4, 0x65, 0xbd, 0x22, 0xfe,
  11016. 0x6e, 0xab, 0x66, 0xdd, 0xcf, 0xe9, 0x65, 0x55,
  11017. 0xe8, 0xdf, 0xc3, 0x8e, 0x4b, 0x00, 0xbc, 0xf8,
  11018. 0x23, 0x57, 0x1b, 0xa0, 0xc8, 0xa9, 0xe2, 0x8c,
  11019. 0x91, 0x6e, 0xf9, 0x20, 0xf7, 0x5c, 0xc5, 0x5b,
  11020. 0x75, 0x8c, 0x47, 0x0a, 0x0e, 0xc4, 0x1a, 0xda,
  11021. 0xef, 0x75, 0xe5, 0x21, 0x00, 0x00, 0x00, 0x00,
  11022. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  11023. 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x13, 0x01,
  11024. 0x00, 0x9e, 0x01, 0x00,
  11025. /* Extensions - duplicate signature algorithms. */
  11026. 0x00, 0x19, 0x00, 0x0d,
  11027. 0x00, 0x04, 0x00, 0x02, 0x04, 0x01, 0x00, 0x0d,
  11028. 0x00, 0x04, 0x00, 0x02, 0x04, 0x01,
  11029. /* Supported Versions extension for TLS 1.3. */
  11030. 0x00, 0x2b,
  11031. 0x00, 0x05, 0x04, 0x03, 0x04, 0x03, 0x03
  11032. };
  11033. WOLFSSL_BUFFER_INFO msg;
  11034. const char* testCertFile;
  11035. const char* testKeyFile;
  11036. WOLFSSL_CTX *ctx = NULL;
  11037. WOLFSSL *ssl = NULL;
  11038. #ifndef NO_RSA
  11039. testCertFile = svrCertFile;
  11040. testKeyFile = svrKeyFile;
  11041. #elif defined(HAVE_ECC)
  11042. testCertFile = eccCertFile;
  11043. testKeyFile = eccKeyFile;
  11044. #endif
  11045. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  11046. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  11047. WOLFSSL_FILETYPE_PEM));
  11048. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  11049. WOLFSSL_FILETYPE_PEM));
  11050. /* Read from 'msg'. */
  11051. wolfSSL_SetIORecv(ctx, BufferInfoRecv);
  11052. /* No where to send to - dummy sender. */
  11053. wolfSSL_SetIOSend(ctx, DummySend);
  11054. ssl = wolfSSL_new(ctx);
  11055. ExpectNotNull(ssl);
  11056. msg.buffer = (unsigned char*)clientHelloDupTlsExt;
  11057. msg.length = (unsigned int)sizeof(clientHelloDupTlsExt);
  11058. wolfSSL_SetIOReadCtx(ssl, &msg);
  11059. ExpectIntNE(wolfSSL_accept(ssl), WOLFSSL_SUCCESS);
  11060. /* can return duplicate ext error or socket error if the peer closed down
  11061. * while sending alert */
  11062. if (wolfSSL_get_error(ssl, 0) != WC_NO_ERR_TRACE(SOCKET_ERROR_E)) {
  11063. ExpectIntEQ(wolfSSL_get_error(ssl, 0), WC_NO_ERR_TRACE(DUPLICATE_TLS_EXT_E));
  11064. }
  11065. wolfSSL_free(ssl);
  11066. wolfSSL_CTX_free(ctx);
  11067. #endif
  11068. return EXPECT_RESULT();
  11069. }
  11070. /*----------------------------------------------------------------------------*
  11071. | X509 Tests
  11072. *----------------------------------------------------------------------------*/
  11073. static int test_wolfSSL_X509_NAME_get_entry(void)
  11074. {
  11075. EXPECT_DECLS;
  11076. #if !defined(NO_CERTS) && !defined(NO_RSA)
  11077. #if defined(OPENSSL_ALL) || \
  11078. (defined(OPENSSL_EXTRA) && \
  11079. (defined(KEEP_PEER_CERT) || defined(SESSION_CERTS)))
  11080. /* use openssl like name to test mapping */
  11081. X509_NAME_ENTRY* ne = NULL;
  11082. X509_NAME* name = NULL;
  11083. X509* x509 = NULL;
  11084. #ifndef NO_FILESYSTEM
  11085. ASN1_STRING* asn = NULL;
  11086. char* subCN = NULL;
  11087. #endif
  11088. int idx = 0;
  11089. ASN1_OBJECT *object = NULL;
  11090. #if defined(WOLFSSL_APACHE_HTTPD) || defined(OPENSSL_ALL) || \
  11091. defined(WOLFSSL_NGINX)
  11092. #ifndef NO_BIO
  11093. BIO* bio = NULL;
  11094. #endif
  11095. #endif
  11096. #ifndef NO_FILESYSTEM
  11097. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  11098. WOLFSSL_FILETYPE_PEM));
  11099. ExpectNotNull(name = X509_get_subject_name(x509));
  11100. ExpectIntGE(idx = X509_NAME_get_index_by_NID(name, NID_commonName, -1), 0);
  11101. ExpectNotNull(ne = X509_NAME_get_entry(name, idx));
  11102. ExpectNotNull(asn = X509_NAME_ENTRY_get_data(ne));
  11103. ExpectNotNull(subCN = (char*)ASN1_STRING_data(asn));
  11104. wolfSSL_FreeX509(x509);
  11105. x509 = NULL;
  11106. #endif
  11107. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  11108. WOLFSSL_FILETYPE_PEM));
  11109. ExpectNotNull(name = X509_get_subject_name(x509));
  11110. ExpectIntGE(idx = X509_NAME_get_index_by_NID(name, NID_commonName, -1), 0);
  11111. #if defined(WOLFSSL_APACHE_HTTPD) || defined(OPENSSL_ALL) || \
  11112. defined(WOLFSSL_NGINX)
  11113. #ifndef NO_BIO
  11114. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  11115. ExpectIntEQ(X509_NAME_print_ex(bio, name, 4,
  11116. (XN_FLAG_RFC2253 & ~XN_FLAG_DN_REV)), WOLFSSL_SUCCESS);
  11117. ExpectIntEQ(X509_NAME_print_ex_fp(stderr, name, 4,
  11118. (XN_FLAG_RFC2253 & ~XN_FLAG_DN_REV)), WOLFSSL_SUCCESS);
  11119. BIO_free(bio);
  11120. #endif
  11121. #endif
  11122. ExpectNotNull(ne = X509_NAME_get_entry(name, idx));
  11123. ExpectNotNull(object = X509_NAME_ENTRY_get_object(ne));
  11124. wolfSSL_FreeX509(x509);
  11125. #endif /* OPENSSL_ALL || (OPENSSL_EXTRA && (KEEP_PEER_CERT || SESSION_CERTS) */
  11126. #endif /* !NO_CERTS && !NO_RSA */
  11127. return EXPECT_RESULT();
  11128. }
  11129. /* Testing functions dealing with PKCS12 parsing out X509 certs */
  11130. static int test_wolfSSL_PKCS12(void)
  11131. {
  11132. EXPECT_DECLS;
  11133. /* .p12 file is encrypted with DES3 */
  11134. #ifndef HAVE_FIPS /* Password used in cert "wolfSSL test" is only 12-bytes
  11135. * (96-bit) FIPS mode requires Minimum of 14-byte (112-bit)
  11136. * Password Key
  11137. */
  11138. #if defined(OPENSSL_EXTRA) && !defined(NO_DES3) && !defined(NO_FILESYSTEM) && \
  11139. !defined(NO_STDIO_FILESYSTEM) && \
  11140. !defined(NO_ASN) && !defined(NO_PWDBASED) && !defined(NO_RSA) && \
  11141. !defined(NO_SHA) && defined(HAVE_PKCS12) && !defined(NO_BIO)
  11142. byte buf[6000];
  11143. char file[] = "./certs/test-servercert.p12";
  11144. char order[] = "./certs/ecc-rsa-server.p12";
  11145. #ifdef WC_RC2
  11146. char rc2p12[] = "./certs/test-servercert-rc2.p12";
  11147. #endif
  11148. char pass[] = "a password";
  11149. const char goodPsw[] = "wolfSSL test";
  11150. const char badPsw[] = "bad";
  11151. #ifdef HAVE_ECC
  11152. WOLFSSL_X509_NAME *subject = NULL;
  11153. WOLFSSL_X509 *x509 = NULL;
  11154. #endif
  11155. XFILE f = XBADFILE;
  11156. int bytes = 0, ret = 0, goodPswLen = 0, badPswLen = 0;
  11157. WOLFSSL_BIO *bio = NULL;
  11158. WOLFSSL_EVP_PKEY *pkey = NULL;
  11159. WC_PKCS12 *pkcs12 = NULL;
  11160. WC_PKCS12 *pkcs12_2 = NULL;
  11161. WOLFSSL_X509 *cert = NULL;
  11162. WOLFSSL_X509 *tmp = NULL;
  11163. WOLF_STACK_OF(WOLFSSL_X509) *ca = NULL;
  11164. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO) || defined(WOLFSSL_HAPROXY) \
  11165. || defined(WOLFSSL_NGINX)) && defined(SESSION_CERTS)
  11166. WOLFSSL_CTX *ctx = NULL;
  11167. WOLFSSL *ssl = NULL;
  11168. WOLF_STACK_OF(WOLFSSL_X509) *tmp_ca = NULL;
  11169. #endif
  11170. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  11171. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  11172. if (f != XBADFILE) {
  11173. XFCLOSE(f);
  11174. f = XBADFILE;
  11175. }
  11176. goodPswLen = (int)XSTRLEN(goodPsw);
  11177. badPswLen = (int)XSTRLEN(badPsw);
  11178. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  11179. ExpectIntEQ(BIO_write(bio, buf, bytes), bytes); /* d2i consumes BIO */
  11180. ExpectNotNull(d2i_PKCS12_bio(bio, &pkcs12));
  11181. ExpectNotNull(pkcs12);
  11182. BIO_free(bio);
  11183. bio = NULL;
  11184. /* check verify MAC directly */
  11185. ExpectIntEQ(ret = PKCS12_verify_mac(pkcs12, goodPsw, goodPswLen), 1);
  11186. /* check verify MAC fail case directly */
  11187. ExpectIntEQ(ret = PKCS12_verify_mac(pkcs12, badPsw, badPswLen), 0);
  11188. /* check verify MAC fail case */
  11189. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "bad", &pkey, &cert, NULL), 0);
  11190. ExpectNull(pkey);
  11191. ExpectNull(cert);
  11192. /* check parse with no extra certs kept */
  11193. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, NULL),
  11194. 1);
  11195. ExpectNotNull(pkey);
  11196. ExpectNotNull(cert);
  11197. wolfSSL_EVP_PKEY_free(pkey);
  11198. pkey = NULL;
  11199. wolfSSL_X509_free(cert);
  11200. cert = NULL;
  11201. /* check parse with extra certs kept */
  11202. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, &ca),
  11203. 1);
  11204. ExpectNotNull(pkey);
  11205. ExpectNotNull(cert);
  11206. ExpectNotNull(ca);
  11207. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO) || defined(WOLFSSL_HAPROXY) \
  11208. || defined(WOLFSSL_NGINX)) && defined(SESSION_CERTS)
  11209. /* Check that SSL_CTX_set0_chain correctly sets the certChain buffer */
  11210. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  11211. #if !defined(NO_WOLFSSL_CLIENT) && defined(SESSION_CERTS)
  11212. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  11213. #else
  11214. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  11215. #endif
  11216. /* Copy stack structure */
  11217. ExpectNotNull(tmp_ca = X509_chain_up_ref(ca));
  11218. ExpectIntEQ(SSL_CTX_set0_chain(ctx, tmp_ca), 1);
  11219. /* CTX now owns the tmp_ca stack structure */
  11220. tmp_ca = NULL;
  11221. ExpectIntEQ(wolfSSL_CTX_get_extra_chain_certs(ctx, &tmp_ca), 1);
  11222. ExpectNotNull(tmp_ca);
  11223. ExpectIntEQ(sk_X509_num(tmp_ca), sk_X509_num(ca));
  11224. /* Check that the main cert is also set */
  11225. ExpectNotNull(SSL_CTX_get0_certificate(ctx));
  11226. ExpectNotNull(ssl = SSL_new(ctx));
  11227. ExpectNotNull(SSL_get_certificate(ssl));
  11228. SSL_free(ssl);
  11229. SSL_CTX_free(ctx);
  11230. ctx = NULL;
  11231. #endif
  11232. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  11233. /* should be 2 other certs on stack */
  11234. ExpectNotNull(tmp = sk_X509_pop(ca));
  11235. X509_free(tmp);
  11236. ExpectNotNull(tmp = sk_X509_pop(ca));
  11237. X509_free(tmp);
  11238. ExpectNull(sk_X509_pop(ca));
  11239. EVP_PKEY_free(pkey);
  11240. pkey = NULL;
  11241. X509_free(cert);
  11242. cert = NULL;
  11243. sk_X509_pop_free(ca, X509_free);
  11244. ca = NULL;
  11245. /* check PKCS12_create */
  11246. ExpectNull(PKCS12_create(pass, NULL, NULL, NULL, NULL, -1, -1, -1, -1,0));
  11247. ExpectIntEQ(PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, &ca),
  11248. SSL_SUCCESS);
  11249. ExpectNotNull((pkcs12_2 = PKCS12_create(pass, NULL, pkey, cert, ca,
  11250. -1, -1, 100, -1, 0)));
  11251. EVP_PKEY_free(pkey);
  11252. pkey = NULL;
  11253. X509_free(cert);
  11254. cert = NULL;
  11255. sk_X509_pop_free(ca, NULL);
  11256. ca = NULL;
  11257. ExpectIntEQ(PKCS12_parse(pkcs12_2, "a password", &pkey, &cert, &ca),
  11258. SSL_SUCCESS);
  11259. PKCS12_free(pkcs12_2);
  11260. pkcs12_2 = NULL;
  11261. ExpectNotNull((pkcs12_2 = PKCS12_create(pass, NULL, pkey, cert, ca,
  11262. NID_pbe_WithSHA1And3_Key_TripleDES_CBC,
  11263. NID_pbe_WithSHA1And3_Key_TripleDES_CBC,
  11264. 2000, 1, 0)));
  11265. EVP_PKEY_free(pkey);
  11266. pkey = NULL;
  11267. X509_free(cert);
  11268. cert = NULL;
  11269. sk_X509_pop_free(ca, NULL);
  11270. ca = NULL;
  11271. /* convert to DER then back and parse */
  11272. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  11273. ExpectIntEQ(i2d_PKCS12_bio(bio, pkcs12_2), SSL_SUCCESS);
  11274. PKCS12_free(pkcs12_2);
  11275. pkcs12_2 = NULL;
  11276. ExpectNotNull(pkcs12_2 = d2i_PKCS12_bio(bio, NULL));
  11277. BIO_free(bio);
  11278. bio = NULL;
  11279. ExpectIntEQ(PKCS12_parse(pkcs12_2, "a password", &pkey, &cert, &ca),
  11280. SSL_SUCCESS);
  11281. /* should be 2 other certs on stack */
  11282. ExpectNotNull(tmp = sk_X509_pop(ca));
  11283. X509_free(tmp);
  11284. ExpectNotNull(tmp = sk_X509_pop(ca));
  11285. X509_free(tmp);
  11286. ExpectNull(sk_X509_pop(ca));
  11287. #ifndef NO_RC4
  11288. PKCS12_free(pkcs12_2);
  11289. pkcs12_2 = NULL;
  11290. ExpectNotNull((pkcs12_2 = PKCS12_create(pass, NULL, pkey, cert, NULL,
  11291. NID_pbe_WithSHA1And128BitRC4,
  11292. NID_pbe_WithSHA1And128BitRC4,
  11293. 2000, 1, 0)));
  11294. EVP_PKEY_free(pkey);
  11295. pkey = NULL;
  11296. X509_free(cert);
  11297. cert = NULL;
  11298. sk_X509_pop_free(ca, NULL);
  11299. ca = NULL;
  11300. ExpectIntEQ(PKCS12_parse(pkcs12_2, "a password", &pkey, &cert, &ca),
  11301. SSL_SUCCESS);
  11302. #endif /* NO_RC4 */
  11303. EVP_PKEY_free(pkey);
  11304. pkey = NULL;
  11305. X509_free(cert);
  11306. cert = NULL;
  11307. PKCS12_free(pkcs12);
  11308. pkcs12 = NULL;
  11309. PKCS12_free(pkcs12_2);
  11310. pkcs12_2 = NULL;
  11311. sk_X509_pop_free(ca, NULL);
  11312. ca = NULL;
  11313. #ifdef HAVE_ECC
  11314. /* test order of parsing */
  11315. ExpectTrue((f = XFOPEN(order, "rb")) != XBADFILE);
  11316. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  11317. if (f != XBADFILE) {
  11318. XFCLOSE(f);
  11319. f = XBADFILE;
  11320. }
  11321. ExpectNotNull(bio = BIO_new_mem_buf((void*)buf, bytes));
  11322. ExpectNotNull(pkcs12 = d2i_PKCS12_bio(bio, NULL));
  11323. ExpectIntEQ((ret = PKCS12_parse(pkcs12, "", &pkey, &cert, &ca)),
  11324. WOLFSSL_SUCCESS);
  11325. /* check use of pkey after parse */
  11326. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO) || defined(WOLFSSL_HAPROXY) \
  11327. || defined(WOLFSSL_NGINX)) && defined(SESSION_CERTS)
  11328. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  11329. #if !defined(NO_WOLFSSL_CLIENT) && defined(SESSION_CERTS)
  11330. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  11331. #else
  11332. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  11333. #endif
  11334. ExpectIntEQ(SSL_CTX_use_PrivateKey(ctx, pkey), WOLFSSL_SUCCESS);
  11335. SSL_CTX_free(ctx);
  11336. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  11337. #endif
  11338. ExpectNotNull(pkey);
  11339. ExpectNotNull(cert);
  11340. ExpectNotNull(ca);
  11341. /* compare subject lines of certificates */
  11342. ExpectNotNull(subject = wolfSSL_X509_get_subject_name(cert));
  11343. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(eccRsaCertFile,
  11344. SSL_FILETYPE_PEM));
  11345. ExpectIntEQ(wolfSSL_X509_NAME_cmp((const WOLFSSL_X509_NAME*)subject,
  11346. (const WOLFSSL_X509_NAME*)wolfSSL_X509_get_subject_name(x509)), 0);
  11347. X509_free(x509);
  11348. x509 = NULL;
  11349. /* test expected fail case */
  11350. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(eccCertFile,
  11351. SSL_FILETYPE_PEM));
  11352. ExpectIntNE(wolfSSL_X509_NAME_cmp((const WOLFSSL_X509_NAME*)subject,
  11353. (const WOLFSSL_X509_NAME*)wolfSSL_X509_get_subject_name(x509)), 0);
  11354. X509_free(x509);
  11355. x509 = NULL;
  11356. X509_free(cert);
  11357. cert = NULL;
  11358. /* get subject line from ca stack */
  11359. ExpectNotNull(cert = sk_X509_pop(ca));
  11360. ExpectNotNull(subject = wolfSSL_X509_get_subject_name(cert));
  11361. /* compare subject from certificate in ca to expected */
  11362. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(eccCertFile,
  11363. SSL_FILETYPE_PEM));
  11364. ExpectIntEQ(wolfSSL_X509_NAME_cmp((const WOLFSSL_X509_NAME*)subject,
  11365. (const WOLFSSL_X509_NAME*)wolfSSL_X509_get_subject_name(x509)), 0);
  11366. /* modify case and compare subject from certificate in ca to expected.
  11367. * The first bit of the name is:
  11368. * /C=US/ST=Washington
  11369. * So we'll change subject->name[1] to 'c' (lower case) */
  11370. if (subject != NULL) {
  11371. subject->name[1] = 'c';
  11372. ExpectIntEQ(wolfSSL_X509_NAME_cmp((const WOLFSSL_X509_NAME*)subject,
  11373. (const WOLFSSL_X509_NAME*)wolfSSL_X509_get_subject_name(x509)), 0);
  11374. }
  11375. EVP_PKEY_free(pkey);
  11376. pkey = NULL;
  11377. X509_free(x509);
  11378. x509 = NULL;
  11379. X509_free(cert);
  11380. cert = NULL;
  11381. BIO_free(bio);
  11382. bio = NULL;
  11383. PKCS12_free(pkcs12);
  11384. pkcs12 = NULL;
  11385. sk_X509_pop_free(ca, NULL); /* TEST d2i_PKCS12_fp */
  11386. ca = NULL;
  11387. /* test order of parsing */
  11388. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  11389. ExpectNotNull(pkcs12 = d2i_PKCS12_fp(f, NULL));
  11390. if (f != XBADFILE) {
  11391. XFCLOSE(f);
  11392. f = XBADFILE;
  11393. }
  11394. /* check verify MAC fail case */
  11395. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "bad", &pkey, &cert, NULL), 0);
  11396. ExpectNull(pkey);
  11397. ExpectNull(cert);
  11398. /* check parse with no extra certs kept */
  11399. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, NULL),
  11400. 1);
  11401. ExpectNotNull(pkey);
  11402. ExpectNotNull(cert);
  11403. wolfSSL_EVP_PKEY_free(pkey);
  11404. pkey = NULL;
  11405. wolfSSL_X509_free(cert);
  11406. cert = NULL;
  11407. /* check parse with extra certs kept */
  11408. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, &ca),
  11409. 1);
  11410. ExpectNotNull(pkey);
  11411. ExpectNotNull(cert);
  11412. ExpectNotNull(ca);
  11413. wolfSSL_EVP_PKEY_free(pkey);
  11414. pkey = NULL;
  11415. wolfSSL_X509_free(cert);
  11416. cert = NULL;
  11417. sk_X509_pop_free(ca, NULL);
  11418. ca = NULL;
  11419. PKCS12_free(pkcs12);
  11420. pkcs12 = NULL;
  11421. #endif /* HAVE_ECC */
  11422. #ifdef WC_RC2
  11423. /* test PKCS#12 with RC2 encryption */
  11424. ExpectTrue((f = XFOPEN(rc2p12, "rb")) != XBADFILE);
  11425. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  11426. if (f != XBADFILE) {
  11427. XFCLOSE(f);
  11428. f = XBADFILE;
  11429. }
  11430. ExpectNotNull(bio = BIO_new_mem_buf((void*)buf, bytes));
  11431. ExpectNotNull(pkcs12 = d2i_PKCS12_bio(bio, NULL));
  11432. /* check verify MAC fail case */
  11433. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "bad", &pkey, &cert, NULL), 0);
  11434. ExpectNull(pkey);
  11435. ExpectNull(cert);
  11436. /* check parse with not extra certs kept */
  11437. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, NULL),
  11438. WOLFSSL_SUCCESS);
  11439. ExpectNotNull(pkey);
  11440. ExpectNotNull(cert);
  11441. wolfSSL_EVP_PKEY_free(pkey);
  11442. pkey = NULL;
  11443. wolfSSL_X509_free(cert);
  11444. cert = NULL;
  11445. /* check parse with extra certs kept */
  11446. ExpectIntEQ(ret = PKCS12_parse(pkcs12, "wolfSSL test", &pkey, &cert, &ca),
  11447. WOLFSSL_SUCCESS);
  11448. ExpectNotNull(pkey);
  11449. ExpectNotNull(cert);
  11450. ExpectNotNull(ca);
  11451. wolfSSL_EVP_PKEY_free(pkey);
  11452. wolfSSL_X509_free(cert);
  11453. sk_X509_pop_free(ca, NULL);
  11454. BIO_free(bio);
  11455. bio = NULL;
  11456. PKCS12_free(pkcs12);
  11457. pkcs12 = NULL;
  11458. #endif /* WC_RC2 */
  11459. /* Test i2d_PKCS12_bio */
  11460. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  11461. ExpectNotNull(pkcs12 = d2i_PKCS12_fp(f, NULL));
  11462. if (f != XBADFILE)
  11463. XFCLOSE(f);
  11464. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  11465. ExpectIntEQ(ret = i2d_PKCS12_bio(bio, pkcs12), 1);
  11466. ExpectIntEQ(ret = i2d_PKCS12_bio(NULL, pkcs12), 0);
  11467. ExpectIntEQ(ret = i2d_PKCS12_bio(bio, NULL), 0);
  11468. PKCS12_free(pkcs12);
  11469. BIO_free(bio);
  11470. (void)order;
  11471. #endif /* OPENSSL_EXTRA */
  11472. #endif /* HAVE_FIPS */
  11473. return EXPECT_RESULT();
  11474. }
  11475. #if !defined(NO_FILESYSTEM) && !defined(NO_ASN) && defined(HAVE_PKCS8) && \
  11476. defined(WOLFSSL_ENCRYPTED_KEYS) && !defined(NO_DES3) && !defined(NO_PWDBASED) && \
  11477. (!defined(NO_RSA) || defined(HAVE_ECC)) && !defined(NO_MD5)
  11478. #define TEST_PKCS8_ENC
  11479. #endif
  11480. #if !defined(NO_FILESYSTEM) && !defined(NO_ASN) && defined(HAVE_PKCS8) \
  11481. && defined(HAVE_ECC) && defined(WOLFSSL_ENCRYPTED_KEYS)
  11482. /* used to keep track if FailTestCallback was called */
  11483. static int failTestCallbackCalled = 0;
  11484. static WC_INLINE int FailTestCallBack(char* passwd, int sz, int rw, void* userdata)
  11485. {
  11486. (void)passwd;
  11487. (void)sz;
  11488. (void)rw;
  11489. (void)userdata;
  11490. /* mark called, test_wolfSSL_no_password_cb() will check and fail if set */
  11491. failTestCallbackCalled = 1;
  11492. return -1;
  11493. }
  11494. #endif
  11495. static int test_wolfSSL_no_password_cb(void)
  11496. {
  11497. EXPECT_DECLS;
  11498. #if !defined(NO_FILESYSTEM) && !defined(NO_ASN) && defined(HAVE_PKCS8) \
  11499. && defined(HAVE_ECC) && defined(WOLFSSL_ENCRYPTED_KEYS)
  11500. WOLFSSL_CTX* ctx = NULL;
  11501. byte buff[FOURK_BUF];
  11502. const char eccPkcs8PrivKeyDerFile[] = "./certs/ecc-privkeyPkcs8.der";
  11503. const char eccPkcs8PrivKeyPemFile[] = "./certs/ecc-privkeyPkcs8.pem";
  11504. XFILE f = XBADFILE;
  11505. int bytes = 0;
  11506. #ifndef NO_WOLFSSL_CLIENT
  11507. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLS_client_method()));
  11508. #else
  11509. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLS_server_method()));
  11510. #endif
  11511. wolfSSL_CTX_set_default_passwd_cb(ctx, FailTestCallBack);
  11512. ExpectTrue((f = XFOPEN(eccPkcs8PrivKeyDerFile, "rb")) != XBADFILE);
  11513. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11514. if (f != XBADFILE) {
  11515. XFCLOSE(f);
  11516. f = XBADFILE;
  11517. }
  11518. ExpectIntLE(bytes, sizeof(buff));
  11519. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11520. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11521. ExpectTrue((f = XFOPEN(eccPkcs8PrivKeyPemFile, "rb")) != XBADFILE);
  11522. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11523. if (f != XBADFILE)
  11524. XFCLOSE(f);
  11525. ExpectIntLE(bytes, sizeof(buff));
  11526. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11527. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11528. wolfSSL_CTX_free(ctx);
  11529. /* Password callback should not be called by default */
  11530. ExpectIntEQ(failTestCallbackCalled, 0);
  11531. #endif
  11532. return EXPECT_RESULT();
  11533. }
  11534. #ifdef TEST_PKCS8_ENC
  11535. /* for PKCS8 test case */
  11536. static int PKCS8TestCallBack(char* passwd, int sz, int rw, void* userdata)
  11537. {
  11538. int flag = 0;
  11539. (void)rw;
  11540. if (userdata != NULL) {
  11541. flag = *((int*)userdata); /* user set data */
  11542. }
  11543. switch (flag) {
  11544. case 1: /* flag set for specific WOLFSSL_CTX structure, note userdata
  11545. * can be anything the user wishes to be passed to the callback
  11546. * associated with the WOLFSSL_CTX */
  11547. XSTRNCPY(passwd, "yassl123", sz);
  11548. return 8;
  11549. default:
  11550. return BAD_FUNC_ARG;
  11551. }
  11552. }
  11553. #endif /* TEST_PKCS8_ENC */
  11554. /* Testing functions dealing with PKCS8 */
  11555. static int test_wolfSSL_PKCS8(void)
  11556. {
  11557. EXPECT_DECLS;
  11558. #if !defined(NO_FILESYSTEM) && !defined(NO_ASN) && defined(HAVE_PKCS8) && \
  11559. !defined(WOLFCRYPT_ONLY)
  11560. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  11561. byte buff[FOURK_BUF];
  11562. byte der[FOURK_BUF];
  11563. #ifndef NO_RSA
  11564. const char serverKeyPkcs8PemFile[] = "./certs/server-keyPkcs8.pem";
  11565. const char serverKeyPkcs8DerFile[] = "./certs/server-keyPkcs8.der";
  11566. #endif
  11567. const char eccPkcs8PrivKeyPemFile[] = "./certs/ecc-privkeyPkcs8.pem";
  11568. #ifdef HAVE_ECC
  11569. const char eccPkcs8PrivKeyDerFile[] = "./certs/ecc-privkeyPkcs8.der";
  11570. #endif
  11571. XFILE f = XBADFILE;
  11572. int bytes = 0;
  11573. WOLFSSL_CTX* ctx = NULL;
  11574. #if defined(HAVE_ECC) && !defined(NO_CODING) && !defined(WOLFSSL_NO_PEM)
  11575. int ret;
  11576. ecc_key key;
  11577. word32 x = 0;
  11578. #endif
  11579. #ifdef TEST_PKCS8_ENC
  11580. #if !defined(NO_RSA) && !defined(NO_SHA)
  11581. const char serverKeyPkcs8EncPemFile[] = "./certs/server-keyPkcs8Enc.pem";
  11582. const char serverKeyPkcs8EncDerFile[] = "./certs/server-keyPkcs8Enc.der";
  11583. #endif
  11584. #if defined(HAVE_ECC) && !defined(NO_SHA)
  11585. const char eccPkcs8EncPrivKeyPemFile[] = "./certs/ecc-keyPkcs8Enc.pem";
  11586. const char eccPkcs8EncPrivKeyDerFile[] = "./certs/ecc-keyPkcs8Enc.der";
  11587. #endif
  11588. int flag;
  11589. #endif
  11590. (void)der;
  11591. #ifndef NO_WOLFSSL_CLIENT
  11592. #ifndef WOLFSSL_NO_TLS12
  11593. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  11594. #else
  11595. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  11596. #endif
  11597. #else
  11598. #ifndef WOLFSSL_NO_TLS12
  11599. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method()));
  11600. #else
  11601. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  11602. #endif
  11603. #endif
  11604. #ifdef TEST_PKCS8_ENC
  11605. wolfSSL_CTX_set_default_passwd_cb(ctx, PKCS8TestCallBack);
  11606. wolfSSL_CTX_set_default_passwd_cb_userdata(ctx, (void*)&flag);
  11607. flag = 1; /* used by password callback as return code */
  11608. #if !defined(NO_RSA) && !defined(NO_SHA)
  11609. /* test loading PEM PKCS8 encrypted file */
  11610. ExpectTrue((f = XFOPEN(serverKeyPkcs8EncPemFile, "rb")) != XBADFILE);
  11611. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11612. if (f != XBADFILE) {
  11613. XFCLOSE(f);
  11614. f = XBADFILE;
  11615. }
  11616. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11617. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11618. /* this next case should fail because of password callback return code */
  11619. flag = 0; /* used by password callback as return code */
  11620. ExpectIntNE(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11621. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11622. /* decrypt PKCS8 PEM to key in DER format with not using WOLFSSL_CTX */
  11623. ExpectIntGT(wc_KeyPemToDer(buff, bytes, der, (word32)sizeof(der),
  11624. "yassl123"), 0);
  11625. /* test that error value is returned with a bad password */
  11626. ExpectIntLT(wc_KeyPemToDer(buff, bytes, der, (word32)sizeof(der),
  11627. "bad"), 0);
  11628. /* test loading PEM PKCS8 encrypted file */
  11629. ExpectTrue((f = XFOPEN(serverKeyPkcs8EncDerFile, "rb")) != XBADFILE);
  11630. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11631. if (f != XBADFILE) {
  11632. XFCLOSE(f);
  11633. f = XBADFILE;
  11634. }
  11635. flag = 1; /* used by password callback as return code */
  11636. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11637. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11638. /* this next case should fail because of password callback return code */
  11639. flag = 0; /* used by password callback as return code */
  11640. ExpectIntNE(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11641. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11642. #endif /* !NO_RSA && !NO_SHA */
  11643. #if defined(HAVE_ECC) && !defined(NO_SHA)
  11644. /* test loading PEM PKCS8 encrypted ECC Key file */
  11645. ExpectTrue((f = XFOPEN(eccPkcs8EncPrivKeyPemFile, "rb")) != XBADFILE);
  11646. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11647. if (f != XBADFILE) {
  11648. XFCLOSE(f);
  11649. f = XBADFILE;
  11650. }
  11651. flag = 1; /* used by password callback as return code */
  11652. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11653. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11654. /* this next case should fail because of password callback return code */
  11655. flag = 0; /* used by password callback as return code */
  11656. ExpectIntNE(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11657. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11658. /* decrypt PKCS8 PEM to key in DER format with not using WOLFSSL_CTX */
  11659. ExpectIntGT(wc_KeyPemToDer(buff, bytes, der, (word32)sizeof(der),
  11660. "yassl123"), 0);
  11661. /* test that error value is returned with a bad password */
  11662. ExpectIntLT(wc_KeyPemToDer(buff, bytes, der, (word32)sizeof(der),
  11663. "bad"), 0);
  11664. /* test loading DER PKCS8 encrypted ECC Key file */
  11665. ExpectTrue((f = XFOPEN(eccPkcs8EncPrivKeyDerFile, "rb")) != XBADFILE);
  11666. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11667. if (f != XBADFILE) {
  11668. XFCLOSE(f);
  11669. f = XBADFILE;
  11670. }
  11671. flag = 1; /* used by password callback as return code */
  11672. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11673. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11674. /* this next case should fail because of password callback return code */
  11675. flag = 0; /* used by password callback as return code */
  11676. ExpectIntNE(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11677. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11678. /* leave flag as "okay" */
  11679. flag = 1;
  11680. #endif /* HAVE_ECC && !NO_SHA */
  11681. #endif /* TEST_PKCS8_ENC */
  11682. #ifndef NO_RSA
  11683. /* test loading ASN.1 (DER) PKCS8 private key file (not encrypted) */
  11684. ExpectTrue((f = XFOPEN(serverKeyPkcs8DerFile, "rb")) != XBADFILE);
  11685. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11686. if (f != XBADFILE) {
  11687. XFCLOSE(f);
  11688. f = XBADFILE;
  11689. }
  11690. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11691. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11692. /* test loading PEM PKCS8 private key file (not encrypted) */
  11693. ExpectTrue((f = XFOPEN(serverKeyPkcs8PemFile, "rb")) != XBADFILE);
  11694. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11695. if (f != XBADFILE) {
  11696. XFCLOSE(f);
  11697. f = XBADFILE;
  11698. }
  11699. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11700. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11701. #endif /* !NO_RSA */
  11702. /* Test PKCS8 PEM ECC key no crypt */
  11703. ExpectTrue((f = XFOPEN(eccPkcs8PrivKeyPemFile, "rb")) != XBADFILE);
  11704. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11705. if (f != XBADFILE) {
  11706. XFCLOSE(f);
  11707. f = XBADFILE;
  11708. }
  11709. #ifdef HAVE_ECC
  11710. /* Test PKCS8 PEM ECC key no crypt */
  11711. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11712. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  11713. #if !defined(NO_CODING) && !defined(WOLFSSL_NO_PEM)
  11714. /* decrypt PKCS8 PEM to key in DER format */
  11715. ExpectIntGT((bytes = wc_KeyPemToDer(buff, bytes, der,
  11716. (word32)sizeof(der), NULL)), 0);
  11717. ret = wc_ecc_init(&key);
  11718. if (ret == 0) {
  11719. ret = wc_EccPrivateKeyDecode(der, &x, &key, (word32)bytes);
  11720. wc_ecc_free(&key);
  11721. }
  11722. ExpectIntEQ(ret, 0);
  11723. #endif
  11724. /* Test PKCS8 DER ECC key no crypt */
  11725. ExpectTrue((f = XFOPEN(eccPkcs8PrivKeyDerFile, "rb")) != XBADFILE);
  11726. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  11727. if (f != XBADFILE)
  11728. XFCLOSE(f);
  11729. /* Test using a PKCS8 ECC PEM */
  11730. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, buff, bytes,
  11731. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11732. #else
  11733. /* if HAVE_ECC is not defined then BEGIN EC PRIVATE KEY is not found */
  11734. ExpectIntEQ((bytes = wc_KeyPemToDer(buff, bytes, der,
  11735. (word32)sizeof(der), NULL)), WC_NO_ERR_TRACE(ASN_NO_PEM_HEADER));
  11736. #endif /* HAVE_ECC */
  11737. wolfSSL_CTX_free(ctx);
  11738. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  11739. #endif /* !NO_FILESYSTEM && !NO_ASN && HAVE_PKCS8 */
  11740. return EXPECT_RESULT();
  11741. }
  11742. static int test_wolfSSL_PKCS8_ED25519(void)
  11743. {
  11744. EXPECT_DECLS;
  11745. #if !defined(NO_ASN) && defined(HAVE_PKCS8) && defined(HAVE_AES_CBC) && \
  11746. defined(WOLFSSL_ENCRYPTED_KEYS) && defined(HAVE_ED25519) && \
  11747. defined(HAVE_ED25519_KEY_IMPORT)
  11748. const byte encPrivKey[] = \
  11749. "-----BEGIN ENCRYPTED PRIVATE KEY-----\n"
  11750. "MIGbMFcGCSqGSIb3DQEFDTBKMCkGCSqGSIb3DQEFDDAcBAheCGLmWGh7+AICCAAw\n"
  11751. "DAYIKoZIhvcNAgkFADAdBglghkgBZQMEASoEEC4L5P6GappsTyhOOoQfvh8EQJMX\n"
  11752. "OAdlsYKCOcFo4djg6AI1lRdeBRwVFWkha7gBdoCJOzS8wDvTbYcJMPvANu5ft3nl\n"
  11753. "2L9W4v7swXkV+X+a1ww=\n"
  11754. "-----END ENCRYPTED PRIVATE KEY-----\n";
  11755. const char password[] = "abcdefghijklmnopqrstuvwxyz";
  11756. byte der[FOURK_BUF];
  11757. WOLFSSL_CTX* ctx = NULL;
  11758. int bytes;
  11759. XMEMSET(der, 0, sizeof(der));
  11760. ExpectIntGT((bytes = wc_KeyPemToDer(encPrivKey, sizeof(encPrivKey), der,
  11761. (word32)sizeof(der), password)), 0);
  11762. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  11763. #ifndef NO_WOLFSSL_SERVER
  11764. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  11765. #else
  11766. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  11767. #endif
  11768. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, der, bytes,
  11769. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11770. wolfSSL_CTX_free(ctx);
  11771. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  11772. #endif
  11773. return EXPECT_RESULT();
  11774. }
  11775. static int test_wolfSSL_PKCS8_ED448(void)
  11776. {
  11777. EXPECT_DECLS;
  11778. #if !defined(NO_ASN) && defined(HAVE_PKCS8) && defined(HAVE_AES_CBC) && \
  11779. defined(WOLFSSL_ENCRYPTED_KEYS) && defined(HAVE_ED448) && \
  11780. defined(HAVE_ED448_KEY_IMPORT)
  11781. const byte encPrivKey[] = \
  11782. "-----BEGIN ENCRYPTED PRIVATE KEY-----\n"
  11783. "MIGrMFcGCSqGSIb3DQEFDTBKMCkGCSqGSIb3DQEFDDAcBAjSbZKnG4EPggICCAAw\n"
  11784. "DAYIKoZIhvcNAgkFADAdBglghkgBZQMEASoEEFvCFWBBHBlJBsYleBJlJWcEUNC7\n"
  11785. "Tf5pZviT5Btar4D/MNg6BsQHSDf5KW4ix871EsgDY2Zz+euaoWspiMntz7gU+PQu\n"
  11786. "T/JJcbD2Ly8BbE3l5WHMifAQqNLxJBfXrHkfYtAo\n"
  11787. "-----END ENCRYPTED PRIVATE KEY-----\n";
  11788. const char password[] = "abcdefghijklmnopqrstuvwxyz";
  11789. byte der[FOURK_BUF];
  11790. WOLFSSL_CTX* ctx = NULL;
  11791. int bytes;
  11792. XMEMSET(der, 0, sizeof(der));
  11793. ExpectIntGT((bytes = wc_KeyPemToDer(encPrivKey, sizeof(encPrivKey), der,
  11794. (word32)sizeof(der), password)), 0);
  11795. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  11796. #ifndef NO_WOLFSSL_SERVER
  11797. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  11798. #else
  11799. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  11800. #endif
  11801. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_buffer(ctx, der, bytes,
  11802. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  11803. wolfSSL_CTX_free(ctx);
  11804. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  11805. #endif
  11806. return EXPECT_RESULT();
  11807. }
  11808. /* Testing functions dealing with PKCS5 */
  11809. static int test_wolfSSL_PKCS5(void)
  11810. {
  11811. EXPECT_DECLS;
  11812. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA) && !defined(NO_PWDBASED)
  11813. #ifdef HAVE_FIPS /* Password minimum length is 14 (112-bit) in FIPS MODE */
  11814. const char* passwd = "myfipsPa$$W0rd";
  11815. #else
  11816. const char *passwd = "pass1234";
  11817. #endif
  11818. const unsigned char *salt = (unsigned char *)"salt1234";
  11819. unsigned char *out = (unsigned char *)XMALLOC(WC_SHA_DIGEST_SIZE, NULL,
  11820. DYNAMIC_TYPE_TMP_BUFFER);
  11821. int ret = 0;
  11822. ExpectNotNull(out);
  11823. ExpectIntEQ(ret = PKCS5_PBKDF2_HMAC_SHA1(passwd,(int)XSTRLEN(passwd), salt,
  11824. (int)XSTRLEN((const char *) salt), 10, WC_SHA_DIGEST_SIZE,out),
  11825. WOLFSSL_SUCCESS);
  11826. #ifdef WOLFSSL_SHA512
  11827. ExpectIntEQ(ret = PKCS5_PBKDF2_HMAC(passwd,(int)XSTRLEN(passwd), salt,
  11828. (int)XSTRLEN((const char *) salt), 10, wolfSSL_EVP_sha512(),
  11829. WC_SHA_DIGEST_SIZE, out), SSL_SUCCESS);
  11830. #endif
  11831. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  11832. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_SHA) */
  11833. return EXPECT_RESULT();
  11834. }
  11835. /* test parsing URI from certificate */
  11836. static int test_wolfSSL_URI(void)
  11837. {
  11838. EXPECT_DECLS;
  11839. #if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) \
  11840. && (defined(KEEP_PEER_CERT) || defined(SESSION_CERTS) || \
  11841. defined(OPENSSL_EXTRA))
  11842. WOLFSSL_X509* x509 = NULL;
  11843. const char uri[] = "./certs/client-uri-cert.pem";
  11844. const char urn[] = "./certs/client-absolute-urn.pem";
  11845. const char badUri[] = "./certs/client-relative-uri.pem";
  11846. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(uri,
  11847. WOLFSSL_FILETYPE_PEM));
  11848. wolfSSL_FreeX509(x509);
  11849. x509 = NULL;
  11850. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(urn,
  11851. WOLFSSL_FILETYPE_PEM));
  11852. wolfSSL_FreeX509(x509);
  11853. x509 = NULL;
  11854. #if !defined(IGNORE_NAME_CONSTRAINTS) && !defined(WOLFSSL_NO_ASN_STRICT) \
  11855. && !defined(WOLFSSL_FPKI)
  11856. ExpectNull(x509 = wolfSSL_X509_load_certificate_file(badUri,
  11857. WOLFSSL_FILETYPE_PEM));
  11858. #else
  11859. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(badUri,
  11860. WOLFSSL_FILETYPE_PEM));
  11861. #endif
  11862. wolfSSL_FreeX509(x509);
  11863. #endif
  11864. return EXPECT_RESULT();
  11865. }
  11866. static int test_wolfSSL_TBS(void)
  11867. {
  11868. EXPECT_DECLS;
  11869. #if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) \
  11870. && defined(OPENSSL_EXTRA)
  11871. WOLFSSL_X509* x509 = NULL;
  11872. const unsigned char* tbs;
  11873. int tbsSz;
  11874. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(caCertFile,
  11875. WOLFSSL_FILETYPE_PEM));
  11876. ExpectNull(tbs = wolfSSL_X509_get_tbs(NULL, &tbsSz));
  11877. ExpectNull(tbs = wolfSSL_X509_get_tbs(x509, NULL));
  11878. ExpectNotNull(tbs = wolfSSL_X509_get_tbs(x509, &tbsSz));
  11879. ExpectIntEQ(tbsSz, 1003);
  11880. wolfSSL_FreeX509(x509);
  11881. #endif
  11882. return EXPECT_RESULT();
  11883. }
  11884. static int test_wolfSSL_X509_verify(void)
  11885. {
  11886. EXPECT_DECLS;
  11887. #if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) && \
  11888. defined(OPENSSL_EXTRA)
  11889. WOLFSSL_X509* ca = NULL;
  11890. WOLFSSL_X509* serv = NULL;
  11891. WOLFSSL_EVP_PKEY* pkey = NULL;
  11892. unsigned char buf[2048];
  11893. const unsigned char* pt = NULL;
  11894. int bufSz;
  11895. ExpectNotNull(ca = wolfSSL_X509_load_certificate_file(caCertFile,
  11896. WOLFSSL_FILETYPE_PEM));
  11897. ExpectIntNE(wolfSSL_X509_get_pubkey_buffer(NULL, buf, &bufSz),
  11898. WOLFSSL_SUCCESS);
  11899. ExpectIntEQ(wolfSSL_X509_get_pubkey_buffer(ca, NULL, &bufSz),
  11900. WOLFSSL_SUCCESS);
  11901. ExpectIntEQ(bufSz, 294);
  11902. bufSz = 2048;
  11903. ExpectIntEQ(wolfSSL_X509_get_pubkey_buffer(ca, buf, &bufSz),
  11904. WOLFSSL_SUCCESS);
  11905. ExpectIntEQ(wolfSSL_X509_get_pubkey_type(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  11906. ExpectIntEQ(wolfSSL_X509_get_pubkey_type(ca), RSAk);
  11907. ExpectNotNull(serv = wolfSSL_X509_load_certificate_file(svrCertFile,
  11908. WOLFSSL_FILETYPE_PEM));
  11909. /* success case */
  11910. pt = buf;
  11911. ExpectNotNull(pkey = wolfSSL_d2i_PUBKEY(NULL, &pt, bufSz));
  11912. ExpectIntEQ(i2d_PUBKEY(pkey, NULL), bufSz);
  11913. ExpectIntEQ(wolfSSL_X509_verify(serv, pkey), WOLFSSL_SUCCESS);
  11914. wolfSSL_EVP_PKEY_free(pkey);
  11915. pkey = NULL;
  11916. /* fail case */
  11917. bufSz = 2048;
  11918. ExpectIntEQ(wolfSSL_X509_get_pubkey_buffer(serv, buf, &bufSz),
  11919. WOLFSSL_SUCCESS);
  11920. pt = buf;
  11921. ExpectNotNull(pkey = wolfSSL_d2i_PUBKEY(NULL, &pt, bufSz));
  11922. ExpectIntEQ(wolfSSL_X509_verify(serv, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  11923. ExpectIntEQ(wolfSSL_X509_verify(NULL, pkey), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  11924. ExpectIntEQ(wolfSSL_X509_verify(serv, NULL), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  11925. wolfSSL_EVP_PKEY_free(pkey);
  11926. wolfSSL_FreeX509(ca);
  11927. wolfSSL_FreeX509(serv);
  11928. #endif
  11929. return EXPECT_RESULT();
  11930. }
  11931. #if defined(WOLFSSL_ACERT) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  11932. !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA)
  11933. /* Given acert file and its pubkey file, read them and then
  11934. * attempt to verify signed acert.
  11935. *
  11936. * If expect_pass is true, then verification should pass.
  11937. * If expect_pass is false, then verification should fail.
  11938. * */
  11939. static int do_acert_verify_test(const char * acert_file,
  11940. const char * pkey_file,
  11941. size_t expect_pass)
  11942. {
  11943. X509_ACERT * x509 = NULL;
  11944. EVP_PKEY * pkey = NULL;
  11945. BIO * bp = NULL;
  11946. int verify_rc = 0;
  11947. /* First read the attribute certificate. */
  11948. bp = BIO_new_file(acert_file, "r");
  11949. if (bp == NULL) {
  11950. return -1;
  11951. }
  11952. x509 = PEM_read_bio_X509_ACERT(bp, NULL, NULL, NULL);
  11953. BIO_free(bp);
  11954. bp = NULL;
  11955. if (x509 == NULL) {
  11956. return -1;
  11957. }
  11958. /* Next read the associated pub key. */
  11959. bp = BIO_new_file(pkey_file, "r");
  11960. if (bp == NULL) {
  11961. X509_ACERT_free(x509);
  11962. x509 = NULL;
  11963. return -1;
  11964. }
  11965. pkey = PEM_read_bio_PUBKEY(bp, &pkey, NULL, NULL);
  11966. BIO_free(bp);
  11967. bp = NULL;
  11968. if (pkey == NULL) {
  11969. X509_ACERT_free(x509);
  11970. x509 = NULL;
  11971. return -1;
  11972. }
  11973. /* Finally, do verification. */
  11974. verify_rc = X509_ACERT_verify(x509, pkey);
  11975. X509_ACERT_free(x509);
  11976. x509 = NULL;
  11977. EVP_PKEY_free(pkey);
  11978. pkey = NULL;
  11979. if (expect_pass && verify_rc != 1) {
  11980. return -1;
  11981. }
  11982. if (!expect_pass && verify_rc == 1) {
  11983. return -1;
  11984. }
  11985. return 0;
  11986. }
  11987. #endif
  11988. static int test_wolfSSL_X509_ACERT_verify(void)
  11989. {
  11990. EXPECT_DECLS;
  11991. #if defined(WOLFSSL_ACERT) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  11992. defined(WC_RSA_PSS) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA)
  11993. /* Walk over list of signed ACERTs and their pubkeys.
  11994. * All should load and pass verification. */
  11995. const char * acerts[4] = {"certs/acert/acert.pem",
  11996. "certs/acert/acert_ietf.pem",
  11997. "certs/acert/rsa_pss/acert.pem",
  11998. "certs/acert/rsa_pss/acert_ietf.pem"};
  11999. const char * pkeys[4] = {"certs/acert/acert_pubkey.pem",
  12000. "certs/acert/acert_ietf_pubkey.pem",
  12001. "certs/acert/rsa_pss/acert_pubkey.pem",
  12002. "certs/acert/rsa_pss/acert_ietf_pubkey.pem"};
  12003. int rc = 0;
  12004. size_t i = 0;
  12005. size_t j = 0;
  12006. for (i = 0; i < 4; ++i) {
  12007. for (j = i; j < 4; ++j) {
  12008. rc = do_acert_verify_test(acerts[i], pkeys[j], i == j);
  12009. if (rc) {
  12010. fprintf(stderr, "error: %s: i = %zu, j = %zu, rc = %d\n",
  12011. "do_acert_verify_test", i, j, rc);
  12012. break;
  12013. }
  12014. }
  12015. if (rc) { break; }
  12016. }
  12017. ExpectIntEQ(rc, 0);
  12018. #endif
  12019. return EXPECT_RESULT();
  12020. }
  12021. static int test_wolfSSL_X509_ACERT_misc_api(void)
  12022. {
  12023. EXPECT_DECLS;
  12024. #if defined(WOLFSSL_ACERT) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  12025. !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA)
  12026. const char * acerts[4] = {"certs/acert/acert.pem",
  12027. "certs/acert/acert_ietf.pem",
  12028. "certs/acert/rsa_pss/acert.pem",
  12029. "certs/acert/rsa_pss/acert_ietf.pem"};
  12030. int rc = 0;
  12031. X509_ACERT * x509 = NULL;
  12032. BIO * bp = NULL;
  12033. long ver_long = 0;
  12034. int ver = 0;
  12035. int nid = 0;
  12036. const byte * raw_attr = NULL;
  12037. word32 attr_len = 0;
  12038. size_t i = 0;
  12039. int buf_len = 0;
  12040. byte ietf_serial[] = {0x03, 0xb5, 0x90, 0x59, 0x02,
  12041. 0xa2, 0xaa, 0xb5, 0x40, 0x21,
  12042. 0x44, 0xb8, 0x2c, 0x4f, 0xd9,
  12043. 0x80, 0x1b, 0x5f, 0x57, 0xc2};
  12044. for (i = 0; i < 4; ++i) {
  12045. const char * acert_file = acerts[i];
  12046. int is_rsa_pss = 0;
  12047. int is_ietf_acert = 0;
  12048. byte serial[64];
  12049. int serial_len = sizeof(serial);
  12050. XMEMSET(serial, 0, sizeof(serial));
  12051. is_rsa_pss = XSTRSTR(acert_file, "rsa_pss") != NULL ? 1 : 0;
  12052. is_ietf_acert = XSTRSTR(acert_file, "ietf.pem") != NULL ? 1 : 0;
  12053. /* First read the attribute certificate. */
  12054. bp = BIO_new_file(acert_file, "r");
  12055. ExpectNotNull(bp);
  12056. x509 = PEM_read_bio_X509_ACERT(bp, NULL, NULL, NULL);
  12057. ExpectNotNull(x509);
  12058. /* We're done with the bio for now. */
  12059. if (bp != NULL) {
  12060. BIO_free(bp);
  12061. bp = NULL;
  12062. }
  12063. /* Check version and signature NID. */
  12064. ver_long = X509_ACERT_get_version(x509);
  12065. ExpectIntEQ(ver_long, 1);
  12066. ver = wolfSSL_X509_ACERT_version(x509);
  12067. ExpectIntEQ(ver, 2);
  12068. nid = X509_ACERT_get_signature_nid(x509);
  12069. if (is_rsa_pss) {
  12070. ExpectIntEQ(nid, NID_rsassaPss);
  12071. }
  12072. else {
  12073. ExpectIntEQ(nid, NID_sha256WithRSAEncryption);
  12074. }
  12075. /* Get the serial number buffer.
  12076. * The ietf acert example has a 20 byte serial number. */
  12077. rc = wolfSSL_X509_ACERT_get_serial_number(x509, serial, &serial_len);
  12078. ExpectIntEQ(rc, SSL_SUCCESS);
  12079. if (is_ietf_acert) {
  12080. ExpectIntEQ(serial_len, 20);
  12081. ExpectIntEQ(XMEMCMP(serial, ietf_serial, sizeof(ietf_serial)), 0);
  12082. }
  12083. else {
  12084. ExpectIntEQ(serial_len, 1);
  12085. ExpectTrue(serial[0] == 0x01);
  12086. }
  12087. /* Repeat the same but with null serial buffer. This is ok. */
  12088. rc = wolfSSL_X509_ACERT_get_serial_number(x509, NULL, &serial_len);
  12089. ExpectIntEQ(rc, SSL_SUCCESS);
  12090. if (is_ietf_acert) {
  12091. ExpectIntEQ(serial_len, 20);
  12092. }
  12093. else {
  12094. ExpectIntEQ(serial_len, 1);
  12095. ExpectTrue(serial[0] == 0x01);
  12096. }
  12097. /* Get the attributes buffer. */
  12098. rc = wolfSSL_X509_ACERT_get_attr_buf(x509, &raw_attr, &attr_len);
  12099. ExpectIntEQ(rc, SSL_SUCCESS);
  12100. if (is_ietf_acert) {
  12101. /* This cert has a 65 byte attributes field. */
  12102. ExpectNotNull(raw_attr);
  12103. ExpectIntEQ(attr_len, 65);
  12104. }
  12105. else {
  12106. /* This cert has a 237 byte attributes field. */
  12107. ExpectNotNull(raw_attr);
  12108. ExpectIntEQ(attr_len, 237);
  12109. }
  12110. /* Test printing acert to memory bio. */
  12111. ExpectNotNull(bp = BIO_new(BIO_s_mem()));
  12112. rc = X509_ACERT_print(bp, x509);
  12113. ExpectIntEQ(rc, SSL_SUCCESS);
  12114. /* Now do a bunch of invalid stuff with partially valid inputs. */
  12115. rc = wolfSSL_X509_ACERT_get_attr_buf(x509, &raw_attr, NULL);
  12116. ExpectIntEQ(rc, BAD_FUNC_ARG);
  12117. rc = wolfSSL_X509_ACERT_get_attr_buf(x509, NULL, &attr_len);
  12118. ExpectIntEQ(rc, BAD_FUNC_ARG);
  12119. rc = wolfSSL_X509_ACERT_get_attr_buf(NULL, &raw_attr, &attr_len);
  12120. ExpectIntEQ(rc, BAD_FUNC_ARG);
  12121. ver_long = X509_ACERT_get_version(NULL);
  12122. ExpectIntEQ(ver_long, 0);
  12123. ver = wolfSSL_X509_ACERT_version(NULL);
  12124. ExpectIntEQ(ver, 0);
  12125. rc = wolfSSL_X509_ACERT_get_signature(x509, NULL, NULL);
  12126. ExpectIntEQ(rc, WOLFSSL_FATAL_ERROR);
  12127. rc = wolfSSL_X509_ACERT_get_signature(x509, NULL, &buf_len);
  12128. ExpectIntEQ(rc, SSL_SUCCESS);
  12129. ExpectIntEQ(buf_len, 256);
  12130. rc = wolfSSL_X509_ACERT_get_serial_number(x509, serial, NULL);
  12131. ExpectIntEQ(rc, BAD_FUNC_ARG);
  12132. rc = X509_ACERT_print(bp, NULL);
  12133. ExpectIntEQ(rc, WOLFSSL_FAILURE);
  12134. rc = X509_ACERT_print(NULL, x509);
  12135. ExpectIntEQ(rc, WOLFSSL_FAILURE);
  12136. /* Finally free the acert and bio, we're done with them. */
  12137. if (x509 != NULL) {
  12138. X509_ACERT_free(x509);
  12139. x509 = NULL;
  12140. }
  12141. if (bp != NULL) {
  12142. BIO_free(bp);
  12143. bp = NULL;
  12144. }
  12145. }
  12146. #endif
  12147. return EXPECT_RESULT();
  12148. }
  12149. static int test_wolfSSL_X509_ACERT_buffer(void)
  12150. {
  12151. EXPECT_DECLS;
  12152. #if defined(WOLFSSL_ACERT) && !defined(NO_CERTS) && \
  12153. !defined(NO_RSA) && defined(WC_RSA_PSS) && \
  12154. (defined(OPENSSL_EXTRA_X509_SMALL) || defined(OPENSSL_EXTRA))
  12155. const byte acert_ietf[] = \
  12156. "-----BEGIN ATTRIBUTE CERTIFICATE-----\n"
  12157. "MIICPTCCASUCAQEwN6AWMBGkDzANMQswCQYDVQQDDAJDQQIBAqEdpBswGTEXMBUG\n"
  12158. "A1UEAwwOc2VydmVyLmV4YW1wbGWgLTArpCkwJzElMCMGA1UEAwwcQXR0cmlidXRl\n"
  12159. "IENlcnRpZmljYXRlIElzc3VlcjANBgkqhkiG9w0BAQsFAAIUA7WQWQKiqrVAIUS4\n"
  12160. "LE/ZgBtfV8IwIhgPMjAyMTA2MTUxMjM1MDBaGA8yMDMxMDYxMzEyMzUwMFowQTAj\n"
  12161. "BggrBgEFBQcKBDEXMBWgCYYHVGVzdHZhbDAIDAZncm91cDEwGgYDVQRIMRMwEaEP\n"
  12162. "gw1hZG1pbmlzdHJhdG9yMCwwHwYDVR0jBBgwFoAUYm7JaGdsZLtTgt0tqoCK2MrI\n"
  12163. "i10wCQYDVR04BAIFADANBgkqhkiG9w0BAQsFAAOCAQEAlIOJ2Dj3TEUj6BIv6vUs\n"
  12164. "GqFWms05i+d10XSzWrunlUTQPoJcUjYkifOWp/7RpZ2XnRl+6hH+nIbmwSmXWwBn\n"
  12165. "ERw2bQMmw/""/nWuN4Qv9t7ltuovWC0pJX6VMT1IRTuTV4SxuZpFL37vkmnFlPBlb+\n"
  12166. "mn3ESSxLTjThWFIq1tip4IaxE/i5Uh32GlJglatFHM1PCGoJtyLtYb6KHDlvknw6\n"
  12167. "coDyjIcj0FZwtQw41jLwxI8jWNmrpt978wdpprB/URrRs+m02HmeQoiHFi/qvdv8\n"
  12168. "d+5vHf3Pi/ulhz/+dvr0p1vEQSoFnYxLXuty2p5m3PJPZCFmT3gURgmgR3BN9d7A\n"
  12169. "Bw==\n"
  12170. "-----END ATTRIBUTE CERTIFICATE-----\n";
  12171. X509_ACERT * x509 = NULL;
  12172. int rc = 0;
  12173. byte ietf_serial[] = {0x03, 0xb5, 0x90, 0x59, 0x02,
  12174. 0xa2, 0xaa, 0xb5, 0x40, 0x21,
  12175. 0x44, 0xb8, 0x2c, 0x4f, 0xd9,
  12176. 0x80, 0x1b, 0x5f, 0x57, 0xc2};
  12177. byte serial[64];
  12178. int serial_len = sizeof(serial);
  12179. const byte * raw_attr = NULL;
  12180. word32 attr_len = 0;
  12181. x509 = wolfSSL_X509_ACERT_load_certificate_buffer_ex(acert_ietf,
  12182. sizeof(acert_ietf),
  12183. WOLFSSL_FILETYPE_PEM,
  12184. HEAP_HINT);
  12185. rc = wolfSSL_X509_ACERT_get_serial_number(x509, serial, &serial_len);
  12186. ExpectIntEQ(rc, SSL_SUCCESS);
  12187. ExpectIntEQ(serial_len, 20);
  12188. ExpectIntEQ(XMEMCMP(serial, ietf_serial, sizeof(ietf_serial)), 0);
  12189. /* Get the attributes buffer. */
  12190. rc = wolfSSL_X509_ACERT_get_attr_buf(x509, &raw_attr, &attr_len);
  12191. ExpectIntEQ(rc, SSL_SUCCESS);
  12192. /* This cert has a 65 byte attributes field. */
  12193. ExpectNotNull(raw_attr);
  12194. ExpectIntEQ(attr_len, 65);
  12195. ExpectNotNull(x509);
  12196. if (x509 != NULL) {
  12197. wolfSSL_X509_ACERT_free(x509);
  12198. x509 = NULL;
  12199. }
  12200. #endif
  12201. return EXPECT_RESULT();
  12202. }
  12203. /* Test ACERT support, but with ASN functions only.
  12204. * */
  12205. static int test_wolfSSL_X509_ACERT_asn(void)
  12206. {
  12207. EXPECT_DECLS;
  12208. #if defined(WOLFSSL_ACERT) && !defined(NO_CERTS)
  12209. const byte acert_ietf[] = \
  12210. "-----BEGIN ATTRIBUTE CERTIFICATE-----\n"
  12211. "MIICPTCCASUCAQEwN6AWMBGkDzANMQswCQYDVQQDDAJDQQIBAqEdpBswGTEXMBUG\n"
  12212. "A1UEAwwOc2VydmVyLmV4YW1wbGWgLTArpCkwJzElMCMGA1UEAwwcQXR0cmlidXRl\n"
  12213. "IENlcnRpZmljYXRlIElzc3VlcjANBgkqhkiG9w0BAQsFAAIUA7WQWQKiqrVAIUS4\n"
  12214. "LE/ZgBtfV8IwIhgPMjAyMTA2MTUxMjM1MDBaGA8yMDMxMDYxMzEyMzUwMFowQTAj\n"
  12215. "BggrBgEFBQcKBDEXMBWgCYYHVGVzdHZhbDAIDAZncm91cDEwGgYDVQRIMRMwEaEP\n"
  12216. "gw1hZG1pbmlzdHJhdG9yMCwwHwYDVR0jBBgwFoAUYm7JaGdsZLtTgt0tqoCK2MrI\n"
  12217. "i10wCQYDVR04BAIFADANBgkqhkiG9w0BAQsFAAOCAQEAlIOJ2Dj3TEUj6BIv6vUs\n"
  12218. "GqFWms05i+d10XSzWrunlUTQPoJcUjYkifOWp/7RpZ2XnRl+6hH+nIbmwSmXWwBn\n"
  12219. "ERw2bQMmw/""/nWuN4Qv9t7ltuovWC0pJX6VMT1IRTuTV4SxuZpFL37vkmnFlPBlb+\n"
  12220. "mn3ESSxLTjThWFIq1tip4IaxE/i5Uh32GlJglatFHM1PCGoJtyLtYb6KHDlvknw6\n"
  12221. "coDyjIcj0FZwtQw41jLwxI8jWNmrpt978wdpprB/URrRs+m02HmeQoiHFi/qvdv8\n"
  12222. "d+5vHf3Pi/ulhz/+dvr0p1vEQSoFnYxLXuty2p5m3PJPZCFmT3gURgmgR3BN9d7A\n"
  12223. "Bw==\n"
  12224. "-----END ATTRIBUTE CERTIFICATE-----\n";
  12225. int rc = 0;
  12226. byte ietf_serial[] = {0x03, 0xb5, 0x90, 0x59, 0x02,
  12227. 0xa2, 0xaa, 0xb5, 0x40, 0x21,
  12228. 0x44, 0xb8, 0x2c, 0x4f, 0xd9,
  12229. 0x80, 0x1b, 0x5f, 0x57, 0xc2};
  12230. DerBuffer * der = NULL;
  12231. #ifdef WOLFSSL_SMALL_STACK
  12232. DecodedAcert * acert = NULL;
  12233. #else
  12234. DecodedAcert acert[1];
  12235. #endif
  12236. rc = wc_PemToDer(acert_ietf, sizeof(acert_ietf), ACERT_TYPE, &der,
  12237. HEAP_HINT, NULL, NULL);
  12238. ExpectIntEQ(rc, 0);
  12239. ExpectNotNull(der);
  12240. if (der != NULL) {
  12241. ExpectNotNull(der->buffer);
  12242. }
  12243. #ifdef WOLFSSL_SMALL_STACK
  12244. acert = (DecodedAcert*)XMALLOC(sizeof(DecodedAcert), HEAP_HINT,
  12245. DYNAMIC_TYPE_DCERT);
  12246. ExpectNotNull(acert);
  12247. #endif
  12248. #ifdef WOLFSSL_SMALL_STACK
  12249. if (acert != NULL)
  12250. #endif
  12251. {
  12252. if (der != NULL && der->buffer != NULL) {
  12253. wc_InitDecodedAcert(acert, der->buffer, der->length, HEAP_HINT);
  12254. rc = wc_ParseX509Acert(acert, VERIFY_SKIP_DATE);
  12255. ExpectIntEQ(rc, 0);
  12256. }
  12257. ExpectIntEQ(acert->serialSz, 20);
  12258. ExpectIntEQ(XMEMCMP(acert->serial, ietf_serial, sizeof(ietf_serial)),
  12259. 0);
  12260. /* This cert has a 65 byte attributes field. */
  12261. ExpectNotNull(acert->rawAttr);
  12262. ExpectIntEQ(acert->rawAttrLen, 65);
  12263. wc_FreeDecodedAcert(acert);
  12264. }
  12265. #ifdef WOLFSSL_SMALL_STACK
  12266. if (acert != NULL) {
  12267. XFREE(acert, HEAP_HINT, DYNAMIC_TYPE_DCERT);
  12268. acert = NULL;
  12269. }
  12270. #endif
  12271. if (der != NULL) {
  12272. wc_FreeDer(&der);
  12273. }
  12274. #endif
  12275. return EXPECT_RESULT();
  12276. }
  12277. #if !defined(NO_DH) && !defined(NO_AES) && defined(WOLFSSL_CERT_GEN) && \
  12278. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  12279. defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  12280. /* create certificate with version 2 */
  12281. static int test_set_x509_badversion(WOLFSSL_CTX* ctx)
  12282. {
  12283. EXPECT_DECLS;
  12284. WOLFSSL_X509 *x509 = NULL, *x509v2 = NULL;
  12285. WOLFSSL_EVP_PKEY *priv = NULL, *pub = NULL;
  12286. unsigned char *der = NULL, *key = NULL, *pt;
  12287. char *header = NULL, *name = NULL;
  12288. int derSz;
  12289. long keySz;
  12290. XFILE fp = XBADFILE;
  12291. WOLFSSL_ASN1_TIME *notBefore = NULL, *notAfter = NULL;
  12292. time_t t;
  12293. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  12294. WOLFSSL_FILETYPE_PEM));
  12295. ExpectTrue((fp = XFOPEN(cliKeyFile, "rb")) != XBADFILE);
  12296. ExpectIntEQ(wolfSSL_PEM_read(fp, &name, &header, &key, &keySz),
  12297. WOLFSSL_SUCCESS);
  12298. if (fp != XBADFILE)
  12299. XFCLOSE(fp);
  12300. pt = key;
  12301. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  12302. (const unsigned char**)&pt, keySz));
  12303. /* create the version 2 certificate */
  12304. ExpectNotNull(x509v2 = X509_new());
  12305. ExpectIntEQ(wolfSSL_X509_set_version(x509v2, 1), WOLFSSL_SUCCESS);
  12306. ExpectIntEQ(wolfSSL_X509_set_subject_name(x509v2,
  12307. wolfSSL_X509_get_subject_name(x509)), WOLFSSL_SUCCESS);
  12308. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509v2,
  12309. wolfSSL_X509_get_issuer_name(x509)), WOLFSSL_SUCCESS);
  12310. ExpectNotNull(pub = wolfSSL_X509_get_pubkey(x509));
  12311. ExpectIntEQ(X509_set_pubkey(x509v2, pub), WOLFSSL_SUCCESS);
  12312. t = time(NULL);
  12313. ExpectNotNull(notBefore = wolfSSL_ASN1_TIME_adj(NULL, t, 0, 0));
  12314. ExpectNotNull(notAfter = wolfSSL_ASN1_TIME_adj(NULL, t, 365, 0));
  12315. ExpectTrue(wolfSSL_X509_set_notBefore(x509v2, notBefore));
  12316. ExpectTrue(wolfSSL_X509_set_notAfter(x509v2, notAfter));
  12317. ExpectIntGT(wolfSSL_X509_sign(x509v2, priv, EVP_sha256()), 0);
  12318. derSz = wolfSSL_i2d_X509(x509v2, &der);
  12319. ExpectIntGT(derSz, 0);
  12320. ExpectIntEQ(wolfSSL_CTX_use_certificate_buffer(ctx, der, derSz,
  12321. WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
  12322. /* TODO: Replace with API call */
  12323. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  12324. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12325. XFREE(name, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12326. XFREE(header, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12327. wolfSSL_X509_free(x509);
  12328. wolfSSL_X509_free(x509v2);
  12329. wolfSSL_EVP_PKEY_free(priv);
  12330. wolfSSL_EVP_PKEY_free(pub);
  12331. wolfSSL_ASN1_TIME_free(notBefore);
  12332. wolfSSL_ASN1_TIME_free(notAfter);
  12333. return EXPECT_RESULT();
  12334. }
  12335. /* override certificate version error */
  12336. static int test_override_x509(int preverify, WOLFSSL_X509_STORE_CTX* store)
  12337. {
  12338. EXPECT_DECLS;
  12339. #ifndef OPENSSL_COMPATIBLE_DEFAULTS
  12340. ExpectIntEQ(store->error, WC_NO_ERR_TRACE(ASN_VERSION_E));
  12341. #else
  12342. ExpectIntEQ(store->error, 0);
  12343. #endif
  12344. ExpectIntEQ((int)wolfSSL_X509_get_version(store->current_cert), 1);
  12345. (void)preverify;
  12346. return EXPECT_RESULT() == TEST_SUCCESS;
  12347. }
  12348. /* set verify callback that will override bad certificate version */
  12349. static int test_set_override_x509(WOLFSSL_CTX* ctx)
  12350. {
  12351. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, test_override_x509);
  12352. return TEST_SUCCESS;
  12353. }
  12354. #endif
  12355. static int test_wolfSSL_X509_TLS_version_test_1(void)
  12356. {
  12357. EXPECT_DECLS;
  12358. #if !defined(NO_DH) && !defined(NO_AES) && defined(WOLFSSL_CERT_GEN) && \
  12359. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  12360. defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  12361. test_ssl_cbf func_cb_client;
  12362. test_ssl_cbf func_cb_server;
  12363. /* test server rejects a client certificate that is not version 3 */
  12364. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  12365. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  12366. func_cb_client.ctx_ready = &test_set_x509_badversion;
  12367. #ifndef WOLFSSL_NO_TLS12
  12368. func_cb_client.method = wolfTLSv1_2_client_method;
  12369. #else
  12370. func_cb_client.method = wolfTLSv1_3_client_method;
  12371. #endif
  12372. #ifndef WOLFSSL_NO_TLS12
  12373. func_cb_server.method = wolfTLSv1_2_server_method;
  12374. #else
  12375. func_cb_server.method = wolfTLSv1_3_server_method;
  12376. #endif
  12377. #ifndef OPENSSL_COMPATIBLE_DEFAULTS
  12378. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  12379. &func_cb_server, NULL), -1001);
  12380. #else
  12381. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  12382. &func_cb_server, NULL), TEST_SUCCESS);
  12383. #endif
  12384. #endif
  12385. return EXPECT_RESULT();
  12386. }
  12387. static int test_wolfSSL_X509_TLS_version_test_2(void)
  12388. {
  12389. EXPECT_DECLS;
  12390. #if !defined(NO_DH) && !defined(NO_AES) && defined(WOLFSSL_CERT_GEN) && \
  12391. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  12392. defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  12393. test_ssl_cbf func_cb_client;
  12394. test_ssl_cbf func_cb_server;
  12395. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  12396. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  12397. func_cb_client.ctx_ready = &test_set_x509_badversion;
  12398. func_cb_server.ctx_ready = &test_set_override_x509;
  12399. #ifndef WOLFSSL_NO_TLS12
  12400. func_cb_client.method = wolfTLSv1_2_client_method;
  12401. #else
  12402. func_cb_client.method = wolfTLSv1_3_client_method;
  12403. #endif
  12404. #ifndef WOLFSSL_NO_TLS12
  12405. func_cb_server.method = wolfTLSv1_2_server_method;
  12406. #else
  12407. func_cb_server.method = wolfTLSv1_3_server_method;
  12408. #endif
  12409. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  12410. &func_cb_server, NULL), TEST_SUCCESS);
  12411. #endif
  12412. return EXPECT_RESULT();
  12413. }
  12414. /* Testing function wolfSSL_CTX_SetMinVersion; sets the minimum downgrade
  12415. * version allowed.
  12416. * POST: 1 on success.
  12417. */
  12418. static int test_wolfSSL_CTX_SetMinVersion(void)
  12419. {
  12420. int res = TEST_SKIPPED;
  12421. #ifndef NO_WOLFSSL_CLIENT
  12422. int failFlag = WOLFSSL_SUCCESS;
  12423. WOLFSSL_CTX* ctx;
  12424. int itr;
  12425. #ifndef NO_OLD_TLS
  12426. const int versions[] = {
  12427. #ifdef WOLFSSL_ALLOW_TLSV10
  12428. WOLFSSL_TLSV1,
  12429. #endif
  12430. WOLFSSL_TLSV1_1,
  12431. WOLFSSL_TLSV1_2 };
  12432. #elif !defined(WOLFSSL_NO_TLS12)
  12433. const int versions[] = { WOLFSSL_TLSV1_2 };
  12434. #elif defined(WOLFSSL_TLS13)
  12435. const int versions[] = { WOLFSSL_TLSV1_3 };
  12436. #else
  12437. const int versions[0];
  12438. #endif
  12439. ctx = wolfSSL_CTX_new(wolfSSLv23_client_method());
  12440. for (itr = 0; itr < (int)(sizeof(versions)/sizeof(int)); itr++) {
  12441. if (wolfSSL_CTX_SetMinVersion(ctx, *(versions + itr))
  12442. != WOLFSSL_SUCCESS) {
  12443. failFlag = WOLFSSL_FAILURE;
  12444. }
  12445. }
  12446. wolfSSL_CTX_free(ctx);
  12447. res = TEST_RES_CHECK(failFlag == WOLFSSL_SUCCESS);
  12448. #endif
  12449. return res;
  12450. } /* END test_wolfSSL_CTX_SetMinVersion */
  12451. /*----------------------------------------------------------------------------*
  12452. | OCSP Stapling
  12453. *----------------------------------------------------------------------------*/
  12454. /* Testing wolfSSL_UseOCSPStapling function. OCSP stapling eliminates the need
  12455. * need to contact the CA, lowering the cost of cert revocation checking.
  12456. * PRE: HAVE_OCSP and HAVE_CERTIFICATE_STATUS_REQUEST
  12457. * POST: 1 returned for success.
  12458. */
  12459. static int test_wolfSSL_UseOCSPStapling(void)
  12460. {
  12461. EXPECT_DECLS;
  12462. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) && defined(HAVE_OCSP) && \
  12463. !defined(NO_WOLFSSL_CLIENT)
  12464. WOLFSSL_CTX* ctx = NULL;
  12465. WOLFSSL* ssl = NULL;
  12466. #ifndef NO_WOLFSSL_CLIENT
  12467. #ifndef WOLFSSL_NO_TLS12
  12468. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  12469. #else
  12470. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  12471. #endif
  12472. #else
  12473. #ifndef WOLFSSL_NO_TLS12
  12474. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method()));
  12475. #else
  12476. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  12477. #endif
  12478. #endif
  12479. ExpectNotNull(ssl = wolfSSL_new(ctx));
  12480. ExpectIntEQ(wolfSSL_UseOCSPStapling(NULL, WOLFSSL_CSR2_OCSP,
  12481. WOLFSSL_CSR2_OCSP_USE_NONCE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12482. #ifndef NO_WOLFSSL_CLIENT
  12483. ExpectIntEQ(wolfSSL_UseOCSPStapling(ssl, WOLFSSL_CSR2_OCSP,
  12484. WOLFSSL_CSR2_OCSP_USE_NONCE), 1);
  12485. #else
  12486. ExpectIntEQ(wolfSSL_UseOCSPStapling(ssl, WOLFSSL_CSR2_OCSP,
  12487. WOLFSSL_CSR2_OCSP_USE_NONCE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12488. #endif
  12489. wolfSSL_free(ssl);
  12490. wolfSSL_CTX_free(ctx);
  12491. #endif
  12492. return EXPECT_RESULT();
  12493. } /* END test_wolfSSL_UseOCSPStapling */
  12494. /* Testing OCSP stapling version 2, wolfSSL_UseOCSPStaplingV2 function. OCSP
  12495. * stapling eliminates the need to contact the CA and lowers cert revocation
  12496. * check.
  12497. * PRE: HAVE_CERTIFICATE_STATUS_REQUEST_V2 and HAVE_OCSP defined.
  12498. */
  12499. static int test_wolfSSL_UseOCSPStaplingV2(void)
  12500. {
  12501. EXPECT_DECLS;
  12502. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2) && defined(HAVE_OCSP) && \
  12503. !defined(NO_WOLFSSL_CLIENT)
  12504. WOLFSSL_CTX* ctx = NULL;
  12505. WOLFSSL* ssl = NULL;
  12506. #ifndef NO_WOLFSSL_CLIENT
  12507. #ifndef WOLFSSL_NO_TLS12
  12508. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  12509. #else
  12510. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  12511. #endif
  12512. #else
  12513. #ifndef WOLFSSL_NO_TLS12
  12514. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method()));
  12515. #else
  12516. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  12517. #endif
  12518. #endif
  12519. ExpectNotNull(ssl = wolfSSL_new(ctx));
  12520. ExpectIntEQ(wolfSSL_UseOCSPStaplingV2(NULL, WOLFSSL_CSR2_OCSP,
  12521. WOLFSSL_CSR2_OCSP_USE_NONCE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12522. #ifndef NO_WOLFSSL_CLIENT
  12523. ExpectIntEQ(wolfSSL_UseOCSPStaplingV2(ssl, WOLFSSL_CSR2_OCSP,
  12524. WOLFSSL_CSR2_OCSP_USE_NONCE), 1);
  12525. #else
  12526. ExpectIntEQ(wolfSSL_UseOCSPStaplingV2(ssl, WOLFSSL_CSR2_OCSP,
  12527. WOLFSSL_CSR2_OCSP_USE_NONCE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12528. #endif
  12529. wolfSSL_free(ssl);
  12530. wolfSSL_CTX_free(ctx);
  12531. #endif
  12532. return EXPECT_RESULT();
  12533. } /* END test_wolfSSL_UseOCSPStaplingV2 */
  12534. /*----------------------------------------------------------------------------*
  12535. | Multicast Tests
  12536. *----------------------------------------------------------------------------*/
  12537. static int test_wolfSSL_mcast(void)
  12538. {
  12539. EXPECT_DECLS;
  12540. #if defined(WOLFSSL_DTLS) && defined(WOLFSSL_MULTICAST) && \
  12541. (defined(WOLFSSL_TLS13) || defined(WOLFSSL_SNIFFER))
  12542. WOLFSSL_CTX* ctx = NULL;
  12543. WOLFSSL* ssl = NULL;
  12544. byte preMasterSecret[512];
  12545. byte clientRandom[32];
  12546. byte serverRandom[32];
  12547. byte suite[2] = {0, 0xfe}; /* WDM_WITH_NULL_SHA256 */
  12548. byte buf[256];
  12549. word16 newId;
  12550. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_2_client_method()));
  12551. ExpectIntEQ(wolfSSL_CTX_mcast_set_member_id(ctx, 0), WOLFSSL_SUCCESS);
  12552. ExpectNotNull(ssl = wolfSSL_new(ctx));
  12553. XMEMSET(preMasterSecret, 0x23, sizeof(preMasterSecret));
  12554. XMEMSET(clientRandom, 0xA5, sizeof(clientRandom));
  12555. XMEMSET(serverRandom, 0x5A, sizeof(serverRandom));
  12556. ExpectIntEQ(wolfSSL_set_secret(ssl, 23, preMasterSecret,
  12557. sizeof(preMasterSecret), clientRandom, serverRandom, suite),
  12558. WOLFSSL_SUCCESS);
  12559. ExpectIntLE(wolfSSL_mcast_read(ssl, &newId, buf, sizeof(buf)), 0);
  12560. ExpectIntLE(newId, 100);
  12561. wolfSSL_free(ssl);
  12562. wolfSSL_CTX_free(ctx);
  12563. #endif /* WOLFSSL_DTLS && WOLFSSL_MULTICAST && (WOLFSSL_TLS13 ||
  12564. * WOLFSSL_SNIFFER) */
  12565. return EXPECT_RESULT();
  12566. }
  12567. /*----------------------------------------------------------------------------*
  12568. | Wolfcrypt
  12569. *----------------------------------------------------------------------------*/
  12570. /*
  12571. * Unit test for the wc_InitBlake2b()
  12572. */
  12573. static int test_wc_InitBlake2b(void)
  12574. {
  12575. EXPECT_DECLS;
  12576. #ifdef HAVE_BLAKE2
  12577. Blake2b blake;
  12578. /* Test good arg. */
  12579. ExpectIntEQ(wc_InitBlake2b(&blake, 64), 0);
  12580. /* Test bad arg. */
  12581. ExpectIntEQ(wc_InitBlake2b(NULL, 64), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12582. ExpectIntEQ(wc_InitBlake2b(NULL, 128), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12583. ExpectIntEQ(wc_InitBlake2b(&blake, 128), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12584. ExpectIntEQ(wc_InitBlake2b(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12585. ExpectIntEQ(wc_InitBlake2b(&blake, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12586. #endif
  12587. return EXPECT_RESULT();
  12588. } /* END test_wc_InitBlake2b*/
  12589. /*
  12590. * Unit test for the wc_InitBlake2b_WithKey()
  12591. */
  12592. static int test_wc_InitBlake2b_WithKey(void)
  12593. {
  12594. EXPECT_DECLS;
  12595. #ifdef HAVE_BLAKE2
  12596. Blake2b blake;
  12597. word32 digestSz = BLAKE2B_KEYBYTES;
  12598. byte key[BLAKE2B_KEYBYTES];
  12599. word32 keylen = BLAKE2B_KEYBYTES;
  12600. XMEMSET(key, 0, sizeof(key));
  12601. /* Test good arg. */
  12602. ExpectIntEQ(wc_InitBlake2b_WithKey(&blake, digestSz, key, keylen), 0);
  12603. /* Test bad args. */
  12604. ExpectIntEQ(wc_InitBlake2b_WithKey(NULL, digestSz, key, keylen),
  12605. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12606. ExpectIntEQ(wc_InitBlake2b_WithKey(&blake, digestSz, key, 256),
  12607. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12608. ExpectIntEQ(wc_InitBlake2b_WithKey(&blake, digestSz, NULL, keylen), 0);
  12609. #endif
  12610. return EXPECT_RESULT();
  12611. } /* END wc_InitBlake2b_WithKey*/
  12612. /*
  12613. * Unit test for the wc_InitBlake2s_WithKey()
  12614. */
  12615. static int test_wc_InitBlake2s_WithKey(void)
  12616. {
  12617. EXPECT_DECLS;
  12618. #ifdef HAVE_BLAKE2S
  12619. Blake2s blake;
  12620. word32 digestSz = BLAKE2S_KEYBYTES;
  12621. byte *key = (byte*)"01234567890123456789012345678901";
  12622. word32 keylen = BLAKE2S_KEYBYTES;
  12623. /* Test good arg. */
  12624. ExpectIntEQ(wc_InitBlake2s_WithKey(&blake, digestSz, key, keylen), 0);
  12625. /* Test bad args. */
  12626. ExpectIntEQ(wc_InitBlake2s_WithKey(NULL, digestSz, key, keylen),
  12627. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12628. ExpectIntEQ(wc_InitBlake2s_WithKey(&blake, digestSz, key, 256),
  12629. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12630. ExpectIntEQ(wc_InitBlake2s_WithKey(&blake, digestSz, NULL, keylen), 0);
  12631. #endif
  12632. return EXPECT_RESULT();
  12633. } /* END wc_InitBlake2s_WithKey*/
  12634. /*
  12635. * Unit test for the wc_InitMd5()
  12636. */
  12637. static int test_wc_InitMd5(void)
  12638. {
  12639. EXPECT_DECLS;
  12640. #ifndef NO_MD5
  12641. wc_Md5 md5;
  12642. /* Test good arg. */
  12643. ExpectIntEQ(wc_InitMd5(&md5), 0);
  12644. /* Test bad arg. */
  12645. ExpectIntEQ(wc_InitMd5(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12646. wc_Md5Free(&md5);
  12647. #endif
  12648. return EXPECT_RESULT();
  12649. } /* END test_wc_InitMd5 */
  12650. /*
  12651. * Testing wc_UpdateMd5()
  12652. */
  12653. static int test_wc_Md5Update(void)
  12654. {
  12655. EXPECT_DECLS;
  12656. #ifndef NO_MD5
  12657. wc_Md5 md5;
  12658. byte hash[WC_MD5_DIGEST_SIZE];
  12659. testVector a, b, c;
  12660. ExpectIntEQ(wc_InitMd5(&md5), 0);
  12661. /* Input */
  12662. a.input = "a";
  12663. a.inLen = XSTRLEN(a.input);
  12664. ExpectIntEQ(wc_Md5Update(&md5, (byte*)a.input, (word32)a.inLen), 0);
  12665. ExpectIntEQ(wc_Md5Final(&md5, hash), 0);
  12666. /* Update input. */
  12667. a.input = "abc";
  12668. a.output = "\x90\x01\x50\x98\x3c\xd2\x4f\xb0\xd6\x96\x3f\x7d\x28\xe1\x7f"
  12669. "\x72";
  12670. a.inLen = XSTRLEN(a.input);
  12671. a.outLen = XSTRLEN(a.output);
  12672. ExpectIntEQ(wc_Md5Update(&md5, (byte*) a.input, (word32) a.inLen), 0);
  12673. ExpectIntEQ(wc_Md5Final(&md5, hash), 0);
  12674. ExpectIntEQ(XMEMCMP(hash, a.output, WC_MD5_DIGEST_SIZE), 0);
  12675. /* Pass in bad values. */
  12676. b.input = NULL;
  12677. b.inLen = 0;
  12678. ExpectIntEQ(wc_Md5Update(&md5, (byte*)b.input, (word32)b.inLen), 0);
  12679. c.input = NULL;
  12680. c.inLen = WC_MD5_DIGEST_SIZE;
  12681. ExpectIntEQ(wc_Md5Update(&md5, (byte*)c.input, (word32)c.inLen),
  12682. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12683. ExpectIntEQ(wc_Md5Update(NULL, (byte*)a.input, (word32)a.inLen),
  12684. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12685. wc_Md5Free(&md5);
  12686. #endif
  12687. return EXPECT_RESULT();
  12688. } /* END test_wc_Md5Update() */
  12689. /*
  12690. * Unit test on wc_Md5Final() in wolfcrypt/src/md5.c
  12691. */
  12692. static int test_wc_Md5Final(void)
  12693. {
  12694. EXPECT_DECLS;
  12695. #ifndef NO_MD5
  12696. /* Instantiate */
  12697. wc_Md5 md5;
  12698. byte* hash_test[3];
  12699. byte hash1[WC_MD5_DIGEST_SIZE];
  12700. byte hash2[2*WC_MD5_DIGEST_SIZE];
  12701. byte hash3[5*WC_MD5_DIGEST_SIZE];
  12702. int times, i;
  12703. /* Initialize */
  12704. ExpectIntEQ(wc_InitMd5(&md5), 0);
  12705. hash_test[0] = hash1;
  12706. hash_test[1] = hash2;
  12707. hash_test[2] = hash3;
  12708. times = sizeof(hash_test)/sizeof(byte*);
  12709. for (i = 0; i < times; i++) {
  12710. ExpectIntEQ(wc_Md5Final(&md5, hash_test[i]), 0);
  12711. }
  12712. /* Test bad args. */
  12713. ExpectIntEQ(wc_Md5Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12714. ExpectIntEQ(wc_Md5Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12715. ExpectIntEQ(wc_Md5Final(&md5, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12716. wc_Md5Free(&md5);
  12717. #endif
  12718. return EXPECT_RESULT();
  12719. }
  12720. /*
  12721. * Unit test for the wc_InitSha()
  12722. */
  12723. static int test_wc_InitSha(void)
  12724. {
  12725. EXPECT_DECLS;
  12726. #ifndef NO_SHA
  12727. wc_Sha sha;
  12728. /* Test good arg. */
  12729. ExpectIntEQ(wc_InitSha(&sha), 0);
  12730. /* Test bad arg. */
  12731. ExpectIntEQ(wc_InitSha(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12732. wc_ShaFree(&sha);
  12733. #endif
  12734. return EXPECT_RESULT();
  12735. } /* END test_wc_InitSha */
  12736. /*
  12737. * Tesing wc_ShaUpdate()
  12738. */
  12739. static int test_wc_ShaUpdate(void)
  12740. {
  12741. EXPECT_DECLS;
  12742. #ifndef NO_SHA
  12743. wc_Sha sha;
  12744. byte hash[WC_SHA_DIGEST_SIZE];
  12745. testVector a, b, c;
  12746. ExpectIntEQ(wc_InitSha(&sha), 0);
  12747. /* Input. */
  12748. a.input = "a";
  12749. a.inLen = XSTRLEN(a.input);
  12750. ExpectIntEQ(wc_ShaUpdate(&sha, NULL, 0), 0);
  12751. ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)a.input, 0), 0);
  12752. ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)a.input, (word32)a.inLen), 0);
  12753. ExpectIntEQ(wc_ShaFinal(&sha, hash), 0);
  12754. /* Update input. */
  12755. a.input = "abc";
  12756. a.output = "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E\x25\x71\x78\x50\xC2"
  12757. "\x6C\x9C\xD0\xD8\x9D";
  12758. a.inLen = XSTRLEN(a.input);
  12759. a.outLen = XSTRLEN(a.output);
  12760. ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)a.input, (word32)a.inLen), 0);
  12761. ExpectIntEQ(wc_ShaFinal(&sha, hash), 0);
  12762. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA_DIGEST_SIZE), 0);
  12763. /* Try passing in bad values. */
  12764. b.input = NULL;
  12765. b.inLen = 0;
  12766. ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)b.input, (word32)b.inLen), 0);
  12767. c.input = NULL;
  12768. c.inLen = WC_SHA_DIGEST_SIZE;
  12769. ExpectIntEQ(wc_ShaUpdate(&sha, (byte*)c.input, (word32)c.inLen),
  12770. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12771. ExpectIntEQ(wc_ShaUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  12772. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12773. wc_ShaFree(&sha);
  12774. #endif
  12775. return EXPECT_RESULT();
  12776. } /* END test_wc_ShaUpdate() */
  12777. /*
  12778. * Unit test on wc_ShaFinal
  12779. */
  12780. static int test_wc_ShaFinal(void)
  12781. {
  12782. EXPECT_DECLS;
  12783. #ifndef NO_SHA
  12784. wc_Sha sha;
  12785. byte* hash_test[3];
  12786. byte hash1[WC_SHA_DIGEST_SIZE];
  12787. byte hash2[2*WC_SHA_DIGEST_SIZE];
  12788. byte hash3[5*WC_SHA_DIGEST_SIZE];
  12789. int times, i;
  12790. /* Initialize*/
  12791. ExpectIntEQ(wc_InitSha(&sha), 0);
  12792. hash_test[0] = hash1;
  12793. hash_test[1] = hash2;
  12794. hash_test[2] = hash3;
  12795. times = sizeof(hash_test)/sizeof(byte*);
  12796. for (i = 0; i < times; i++) {
  12797. ExpectIntEQ(wc_ShaFinal(&sha, hash_test[i]), 0);
  12798. }
  12799. /* Test bad args. */
  12800. ExpectIntEQ(wc_ShaFinal(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12801. ExpectIntEQ(wc_ShaFinal(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12802. ExpectIntEQ(wc_ShaFinal(&sha, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12803. wc_ShaFree(&sha);
  12804. #endif
  12805. return EXPECT_RESULT();
  12806. } /* END test_wc_ShaFinal */
  12807. /*
  12808. * Unit test for wc_InitSha256()
  12809. */
  12810. static int test_wc_InitSha256(void)
  12811. {
  12812. EXPECT_DECLS;
  12813. #ifndef NO_SHA256
  12814. wc_Sha256 sha256;
  12815. /* Test good arg. */
  12816. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12817. /* Test bad arg. */
  12818. ExpectIntEQ(wc_InitSha256(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12819. wc_Sha256Free(&sha256);
  12820. #endif
  12821. return EXPECT_RESULT();
  12822. } /* END test_wc_InitSha256 */
  12823. /*
  12824. * Unit test for wc_Sha256Update()
  12825. */
  12826. static int test_wc_Sha256Update(void)
  12827. {
  12828. EXPECT_DECLS;
  12829. #ifndef NO_SHA256
  12830. wc_Sha256 sha256;
  12831. byte hash[WC_SHA256_DIGEST_SIZE];
  12832. byte hash_unaligned[WC_SHA256_DIGEST_SIZE+1];
  12833. testVector a, b, c;
  12834. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12835. /* Input. */
  12836. a.input = "a";
  12837. a.inLen = XSTRLEN(a.input);
  12838. ExpectIntEQ(wc_Sha256Update(&sha256, NULL, 0), 0);
  12839. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)a.input, 0), 0);
  12840. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)a.input, (word32)a.inLen), 0);
  12841. ExpectIntEQ(wc_Sha256Final(&sha256, hash), 0);
  12842. /* Update input. */
  12843. a.input = "abc";
  12844. a.output = "\xBA\x78\x16\xBF\x8F\x01\xCF\xEA\x41\x41\x40\xDE\x5D\xAE\x22"
  12845. "\x23\xB0\x03\x61\xA3\x96\x17\x7A\x9C\xB4\x10\xFF\x61\xF2\x00"
  12846. "\x15\xAD";
  12847. a.inLen = XSTRLEN(a.input);
  12848. a.outLen = XSTRLEN(a.output);
  12849. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)a.input, (word32)a.inLen), 0);
  12850. ExpectIntEQ(wc_Sha256Final(&sha256, hash), 0);
  12851. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA256_DIGEST_SIZE), 0);
  12852. /* Unaligned check. */
  12853. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)a.input+1, (word32)a.inLen-1),
  12854. 0);
  12855. ExpectIntEQ(wc_Sha256Final(&sha256, hash_unaligned + 1), 0);
  12856. /* Try passing in bad values */
  12857. b.input = NULL;
  12858. b.inLen = 0;
  12859. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)b.input, (word32)b.inLen), 0);
  12860. c.input = NULL;
  12861. c.inLen = WC_SHA256_DIGEST_SIZE;
  12862. ExpectIntEQ(wc_Sha256Update(&sha256, (byte*)c.input, (word32)c.inLen),
  12863. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12864. ExpectIntEQ(wc_Sha256Update(NULL, (byte*)a.input, (word32)a.inLen),
  12865. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12866. wc_Sha256Free(&sha256);
  12867. #endif
  12868. return EXPECT_RESULT();
  12869. } /* END test_wc_Sha256Update */
  12870. /*
  12871. * Unit test function for wc_Sha256Final()
  12872. */
  12873. static int test_wc_Sha256Final(void)
  12874. {
  12875. EXPECT_DECLS;
  12876. #ifndef NO_SHA256
  12877. wc_Sha256 sha256;
  12878. byte* hash_test[3];
  12879. byte hash1[WC_SHA256_DIGEST_SIZE];
  12880. byte hash2[2*WC_SHA256_DIGEST_SIZE];
  12881. byte hash3[5*WC_SHA256_DIGEST_SIZE];
  12882. int times, i;
  12883. /* Initialize */
  12884. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12885. hash_test[0] = hash1;
  12886. hash_test[1] = hash2;
  12887. hash_test[2] = hash3;
  12888. times = sizeof(hash_test) / sizeof(byte*);
  12889. for (i = 0; i < times; i++) {
  12890. ExpectIntEQ(wc_Sha256Final(&sha256, hash_test[i]), 0);
  12891. }
  12892. /* Test bad args. */
  12893. ExpectIntEQ(wc_Sha256Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12894. ExpectIntEQ(wc_Sha256Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12895. ExpectIntEQ(wc_Sha256Final(&sha256, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12896. wc_Sha256Free(&sha256);
  12897. #endif
  12898. return EXPECT_RESULT();
  12899. } /* END test_wc_Sha256Final */
  12900. /*
  12901. * Unit test function for wc_Sha256FinalRaw()
  12902. */
  12903. static int test_wc_Sha256FinalRaw(void)
  12904. {
  12905. EXPECT_DECLS;
  12906. #if !defined(NO_SHA256) && !defined(HAVE_SELFTEST) && !defined(WOLFSSL_DEVCRYPTO) && (!defined(HAVE_FIPS) || \
  12907. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3))) && \
  12908. !defined(WOLFSSL_NO_HASH_RAW)
  12909. wc_Sha256 sha256;
  12910. byte* hash_test[3];
  12911. byte hash1[WC_SHA256_DIGEST_SIZE];
  12912. byte hash2[2*WC_SHA256_DIGEST_SIZE];
  12913. byte hash3[5*WC_SHA256_DIGEST_SIZE];
  12914. int times, i;
  12915. /* Initialize */
  12916. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12917. hash_test[0] = hash1;
  12918. hash_test[1] = hash2;
  12919. hash_test[2] = hash3;
  12920. times = sizeof(hash_test) / sizeof(byte*);
  12921. for (i = 0; i < times; i++) {
  12922. ExpectIntEQ(wc_Sha256FinalRaw(&sha256, hash_test[i]), 0);
  12923. }
  12924. /* Test bad args. */
  12925. ExpectIntEQ(wc_Sha256FinalRaw(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12926. ExpectIntEQ(wc_Sha256FinalRaw(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12927. ExpectIntEQ(wc_Sha256FinalRaw(&sha256, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12928. wc_Sha256Free(&sha256);
  12929. #endif
  12930. return EXPECT_RESULT();
  12931. } /* END test_wc_Sha256FinalRaw */
  12932. /*
  12933. * Unit test function for wc_Sha256GetFlags()
  12934. */
  12935. static int test_wc_Sha256GetFlags(void)
  12936. {
  12937. EXPECT_DECLS;
  12938. #if !defined(NO_SHA256) && defined(WOLFSSL_HASH_FLAGS)
  12939. wc_Sha256 sha256;
  12940. word32 flags = 0;
  12941. /* Initialize */
  12942. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12943. ExpectIntEQ(wc_Sha256GetFlags(&sha256, &flags), 0);
  12944. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  12945. wc_Sha256Free(&sha256);
  12946. #endif
  12947. return EXPECT_RESULT();
  12948. } /* END test_wc_Sha256GetFlags */
  12949. /*
  12950. * Unit test function for wc_Sha256Free()
  12951. */
  12952. static int test_wc_Sha256Free(void)
  12953. {
  12954. EXPECT_DECLS;
  12955. #ifndef NO_SHA256
  12956. wc_Sha256Free(NULL);
  12957. /* Set result to SUCCESS. */
  12958. ExpectTrue(1);
  12959. #endif
  12960. return EXPECT_RESULT();
  12961. } /* END test_wc_Sha256Free */
  12962. /*
  12963. * Unit test function for wc_Sha256GetHash()
  12964. */
  12965. static int test_wc_Sha256GetHash(void)
  12966. {
  12967. EXPECT_DECLS;
  12968. #ifndef NO_SHA256
  12969. wc_Sha256 sha256;
  12970. byte hash1[WC_SHA256_DIGEST_SIZE];
  12971. /* Initialize */
  12972. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12973. ExpectIntEQ(wc_Sha256GetHash(&sha256, hash1), 0);
  12974. /* test bad arguments*/
  12975. ExpectIntEQ(wc_Sha256GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12976. ExpectIntEQ(wc_Sha256GetHash(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12977. ExpectIntEQ(wc_Sha256GetHash(&sha256, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12978. wc_Sha256Free(&sha256);
  12979. #endif
  12980. return EXPECT_RESULT();
  12981. } /* END test_wc_Sha256GetHash */
  12982. /*
  12983. * Unit test function for wc_Sha256Copy()
  12984. */
  12985. static int test_wc_Sha256Copy(void)
  12986. {
  12987. EXPECT_DECLS;
  12988. #ifndef NO_SHA256
  12989. wc_Sha256 sha256;
  12990. wc_Sha256 temp;
  12991. XMEMSET(&sha256, 0, sizeof(sha256));
  12992. XMEMSET(&temp, 0, sizeof(temp));
  12993. /* Initialize */
  12994. ExpectIntEQ(wc_InitSha256(&sha256), 0);
  12995. ExpectIntEQ(wc_InitSha256(&temp), 0);
  12996. ExpectIntEQ(wc_Sha256Copy(&sha256, &temp), 0);
  12997. /* test bad arguments*/
  12998. ExpectIntEQ(wc_Sha256Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  12999. ExpectIntEQ(wc_Sha256Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13000. ExpectIntEQ(wc_Sha256Copy(&sha256, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13001. wc_Sha256Free(&sha256);
  13002. wc_Sha256Free(&temp);
  13003. #endif
  13004. return EXPECT_RESULT();
  13005. } /* END test_wc_Sha256Copy */
  13006. /*
  13007. * Testing wc_InitSha512()
  13008. */
  13009. static int test_wc_InitSha512(void)
  13010. {
  13011. EXPECT_DECLS;
  13012. #ifdef WOLFSSL_SHA512
  13013. wc_Sha512 sha512;
  13014. /* Test good arg. */
  13015. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  13016. /* Test bad arg. */
  13017. ExpectIntEQ(wc_InitSha512(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13018. wc_Sha512Free(&sha512);
  13019. #endif
  13020. return EXPECT_RESULT();
  13021. } /* END test_wc_InitSha512 */
  13022. /*
  13023. * wc_Sha512Update() test.
  13024. */
  13025. static int test_wc_Sha512Update(void)
  13026. {
  13027. EXPECT_DECLS;
  13028. #ifdef WOLFSSL_SHA512
  13029. wc_Sha512 sha512;
  13030. byte hash[WC_SHA512_DIGEST_SIZE];
  13031. byte hash_unaligned[WC_SHA512_DIGEST_SIZE + 1];
  13032. testVector a, b, c;
  13033. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  13034. /* Input. */
  13035. a.input = "a";
  13036. a.inLen = XSTRLEN(a.input);
  13037. ExpectIntEQ(wc_Sha512Update(&sha512, NULL, 0), 0);
  13038. ExpectIntEQ(wc_Sha512Update(&sha512,(byte*)a.input, 0), 0);
  13039. ExpectIntEQ(wc_Sha512Update(&sha512, (byte*)a.input, (word32)a.inLen), 0);
  13040. ExpectIntEQ(wc_Sha512Final(&sha512, hash), 0);
  13041. /* Update input. */
  13042. a.input = "abc";
  13043. a.output = "\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41"
  13044. "\x31\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b"
  13045. "\x55\xd3\x9a\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c"
  13046. "\x23\xa3\xfe\xeb\xbd\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a"
  13047. "\x9a\xc9\x4f\xa5\x4c\xa4\x9f";
  13048. a.inLen = XSTRLEN(a.input);
  13049. a.outLen = XSTRLEN(a.output);
  13050. ExpectIntEQ(wc_Sha512Update(&sha512, (byte*) a.input, (word32) a.inLen), 0);
  13051. ExpectIntEQ(wc_Sha512Final(&sha512, hash), 0);
  13052. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA512_DIGEST_SIZE), 0);
  13053. /* Unaligned check. */
  13054. ExpectIntEQ(wc_Sha512Update(&sha512, (byte*)a.input+1, (word32)a.inLen-1),
  13055. 0);
  13056. ExpectIntEQ(wc_Sha512Final(&sha512, hash_unaligned+1), 0);
  13057. /* Try passing in bad values */
  13058. b.input = NULL;
  13059. b.inLen = 0;
  13060. ExpectIntEQ(wc_Sha512Update(&sha512, (byte*)b.input, (word32)b.inLen), 0);
  13061. c.input = NULL;
  13062. c.inLen = WC_SHA512_DIGEST_SIZE;
  13063. ExpectIntEQ(wc_Sha512Update(&sha512, (byte*)c.input, (word32)c.inLen),
  13064. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13065. ExpectIntEQ(wc_Sha512Update(NULL, (byte*)a.input, (word32)a.inLen),
  13066. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13067. wc_Sha512Free(&sha512);
  13068. #endif
  13069. return EXPECT_RESULT();
  13070. } /* END test_wc_Sha512Update */
  13071. #ifdef WOLFSSL_SHA512
  13072. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  13073. (!defined(WOLFSSL_NOSHA512_224) || !defined(WOLFSSL_NOSHA512_256))
  13074. /* Performs test for
  13075. * - wc_Sha512Final/wc_Sha512FinalRaw
  13076. * - wc_Sha512_224Final/wc_Sha512_224Final
  13077. * - wc_Sha512_256Final/wc_Sha512_256Final
  13078. * parameter:
  13079. * - type : must be one of WC_HASH_TYPE_SHA512, WC_HASH_TYPE_SHA512_224 or
  13080. * WC_HASH_TYPE_SHA512_256
  13081. * - isRaw: if is non-zero, xxxFinalRaw function will be tested
  13082. *return 0 on success
  13083. */
  13084. static int test_Sha512_Family_Final(int type, int isRaw)
  13085. {
  13086. EXPECT_DECLS;
  13087. wc_Sha512 sha512;
  13088. byte* hash_test[3];
  13089. byte hash1[WC_SHA512_DIGEST_SIZE];
  13090. byte hash2[2*WC_SHA512_DIGEST_SIZE];
  13091. byte hash3[5*WC_SHA512_DIGEST_SIZE];
  13092. int times, i;
  13093. int(*initFp)(wc_Sha512*);
  13094. int(*finalFp)(wc_Sha512*, byte*);
  13095. void(*freeFp)(wc_Sha512*);
  13096. if (type == WC_HASH_TYPE_SHA512) {
  13097. initFp = wc_InitSha512;
  13098. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  13099. !defined(WOLFSSL_NO_HASH_RAW)
  13100. finalFp = (isRaw)? wc_Sha512FinalRaw : wc_Sha512Final;
  13101. #else
  13102. finalFp = (isRaw)? NULL : wc_Sha512Final;
  13103. #endif
  13104. freeFp = wc_Sha512Free;
  13105. }
  13106. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13107. #if !defined(WOLFSSL_NOSHA512_224)
  13108. else if (type == WC_HASH_TYPE_SHA512_224) {
  13109. initFp = wc_InitSha512_224;
  13110. #if !defined(WOLFSSL_NO_HASH_RAW)
  13111. finalFp = (isRaw)? wc_Sha512_224FinalRaw : wc_Sha512_224Final;
  13112. #else
  13113. finalFp = (isRaw)? NULL : wc_Sha512_224Final;
  13114. #endif
  13115. freeFp = wc_Sha512_224Free;
  13116. }
  13117. #endif
  13118. #if !defined(WOLFSSL_NOSHA512_256)
  13119. else if (type == WC_HASH_TYPE_SHA512_256) {
  13120. initFp = wc_InitSha512_256;
  13121. #if !defined(WOLFSSL_NO_HASH_RAW)
  13122. finalFp = (isRaw)? wc_Sha512_256FinalRaw : wc_Sha512_256Final;
  13123. #else
  13124. finalFp = (isRaw)? NULL : wc_Sha512_256Final;
  13125. #endif
  13126. freeFp = wc_Sha512_256Free;
  13127. }
  13128. #endif
  13129. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13130. else
  13131. return TEST_FAIL;
  13132. /* Initialize */
  13133. ExpectIntEQ(initFp(&sha512), 0);
  13134. hash_test[0] = hash1;
  13135. hash_test[1] = hash2;
  13136. hash_test[2] = hash3;
  13137. times = sizeof(hash_test) / sizeof(byte *);
  13138. #if defined(HAVE_FIPS) || defined(HAVE_SELFTEST) || \
  13139. defined(WOLFSSL_NO_HASH_RAW)
  13140. if (finalFp != NULL)
  13141. #endif
  13142. {
  13143. /* Good test args. */
  13144. for (i = 0; i < times; i++) {
  13145. ExpectIntEQ(finalFp(&sha512, hash_test[i]), 0);
  13146. }
  13147. /* Test bad args. */
  13148. ExpectIntEQ(finalFp(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13149. ExpectIntEQ(finalFp(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13150. ExpectIntEQ(finalFp(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13151. }
  13152. freeFp(&sha512);
  13153. return EXPECT_RESULT();
  13154. }
  13155. #endif /* !HAVE_FIPS && !HAVE_SELFTEST &&
  13156. (!WOLFSSL_NOSHA512_224 || !WOLFSSL_NOSHA512_256) */
  13157. #endif /* WOLFSSL_SHA512 */
  13158. /*
  13159. * Unit test function for wc_Sha512Final()
  13160. */
  13161. static int test_wc_Sha512Final(void)
  13162. {
  13163. EXPECT_DECLS;
  13164. #ifdef WOLFSSL_SHA512
  13165. wc_Sha512 sha512;
  13166. byte* hash_test[3];
  13167. byte hash1[WC_SHA512_DIGEST_SIZE];
  13168. byte hash2[2*WC_SHA512_DIGEST_SIZE];
  13169. byte hash3[5*WC_SHA512_DIGEST_SIZE];
  13170. int times, i;
  13171. /* Initialize */
  13172. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  13173. hash_test[0] = hash1;
  13174. hash_test[1] = hash2;
  13175. hash_test[2] = hash3;
  13176. times = sizeof(hash_test) / sizeof(byte *);
  13177. for (i = 0; i < times; i++) {
  13178. ExpectIntEQ(wc_Sha512Final(&sha512, hash_test[i]), 0);
  13179. }
  13180. /* Test bad args. */
  13181. ExpectIntEQ(wc_Sha512Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13182. ExpectIntEQ(wc_Sha512Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13183. ExpectIntEQ(wc_Sha512Final(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13184. wc_Sha512Free(&sha512);
  13185. #endif
  13186. return EXPECT_RESULT();
  13187. } /* END test_wc_Sha512Final */
  13188. /*
  13189. * Unit test function for wc_Sha512GetFlags()
  13190. */
  13191. static int test_wc_Sha512GetFlags(void)
  13192. {
  13193. EXPECT_DECLS;
  13194. #if defined(WOLFSSL_SHA512) && defined(WOLFSSL_HASH_FLAGS)
  13195. wc_Sha512 sha512;
  13196. word32 flags = 0;
  13197. /* Initialize */
  13198. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  13199. ExpectIntEQ(wc_Sha512GetFlags(&sha512, &flags), 0);
  13200. ExpectIntEQ((flags & WC_HASH_FLAG_ISCOPY), 0);
  13201. wc_Sha512Free(&sha512);
  13202. #endif
  13203. return EXPECT_RESULT();
  13204. } /* END test_wc_Sha512GetFlags */
  13205. /*
  13206. * Unit test function for wc_Sha512FinalRaw()
  13207. */
  13208. static int test_wc_Sha512FinalRaw(void)
  13209. {
  13210. EXPECT_DECLS;
  13211. #if (defined(WOLFSSL_SHA512) && !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  13212. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3)))) && \
  13213. !defined(WOLFSSL_NO_HASH_RAW)
  13214. wc_Sha512 sha512;
  13215. byte* hash_test[3];
  13216. byte hash1[WC_SHA512_DIGEST_SIZE];
  13217. byte hash2[2*WC_SHA512_DIGEST_SIZE];
  13218. byte hash3[5*WC_SHA512_DIGEST_SIZE];
  13219. int times, i;
  13220. /* Initialize */
  13221. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  13222. hash_test[0] = hash1;
  13223. hash_test[1] = hash2;
  13224. hash_test[2] = hash3;
  13225. times = sizeof(hash_test) / sizeof(byte*);
  13226. /* Good test args. */
  13227. for (i = 0; i < times; i++) {
  13228. ExpectIntEQ(wc_Sha512FinalRaw(&sha512, hash_test[i]), 0);
  13229. }
  13230. /* Test bad args. */
  13231. ExpectIntEQ(wc_Sha512FinalRaw(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13232. ExpectIntEQ(wc_Sha512FinalRaw(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13233. ExpectIntEQ(wc_Sha512FinalRaw(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13234. wc_Sha512Free(&sha512);
  13235. #endif
  13236. return EXPECT_RESULT();
  13237. } /* END test_wc_Sha512FinalRaw */
  13238. /*
  13239. * Unit test function for wc_Sha512Free()
  13240. */
  13241. static int test_wc_Sha512Free(void)
  13242. {
  13243. EXPECT_DECLS;
  13244. #ifdef WOLFSSL_SHA512
  13245. wc_Sha512Free(NULL);
  13246. /* Set result to SUCCESS. */
  13247. ExpectTrue(1);
  13248. #endif
  13249. return EXPECT_RESULT();
  13250. } /* END test_wc_Sha512Free */
  13251. #ifdef WOLFSSL_SHA512
  13252. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  13253. (!defined(WOLFSSL_NOSHA512_224) || !defined(WOLFSSL_NOSHA512_256))
  13254. static int test_Sha512_Family_GetHash(int type )
  13255. {
  13256. EXPECT_DECLS;
  13257. int(*initFp)(wc_Sha512*);
  13258. int(*ghashFp)(wc_Sha512*, byte*);
  13259. wc_Sha512 sha512;
  13260. byte hash1[WC_SHA512_DIGEST_SIZE];
  13261. if (type == WC_HASH_TYPE_SHA512) {
  13262. initFp = wc_InitSha512;
  13263. ghashFp = wc_Sha512GetHash;
  13264. }
  13265. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13266. #if !defined(WOLFSSL_NOSHA512_224)
  13267. else if (type == WC_HASH_TYPE_SHA512_224) {
  13268. initFp = wc_InitSha512_224;
  13269. ghashFp = wc_Sha512_224GetHash;
  13270. }
  13271. #endif
  13272. #if !defined(WOLFSSL_NOSHA512_256)
  13273. else if (type == WC_HASH_TYPE_SHA512_256) {
  13274. initFp = wc_InitSha512_256;
  13275. ghashFp = wc_Sha512_256GetHash;
  13276. }
  13277. #endif
  13278. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13279. else {
  13280. initFp = NULL;
  13281. ghashFp = NULL;
  13282. }
  13283. if (initFp == NULL || ghashFp == NULL)
  13284. return TEST_FAIL;
  13285. ExpectIntEQ(initFp(&sha512), 0);
  13286. ExpectIntEQ(ghashFp(&sha512, hash1), 0);
  13287. /* test bad arguments*/
  13288. ExpectIntEQ(ghashFp(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13289. ExpectIntEQ(ghashFp(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13290. ExpectIntEQ(ghashFp(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13291. wc_Sha512Free(&sha512);
  13292. return EXPECT_RESULT();
  13293. }
  13294. #endif /* !HAVE_FIPS && !HAVE_SELFTEST &&
  13295. (!WOLFSSL_NOSHA512_224 || !WOLFSSL_NOSHA512_256) */
  13296. #endif /* WOLFSSL_SHA512 */
  13297. /*
  13298. * Unit test function for wc_Sha512GetHash()
  13299. */
  13300. static int test_wc_Sha512GetHash(void)
  13301. {
  13302. EXPECT_DECLS;
  13303. #ifdef WOLFSSL_SHA512
  13304. wc_Sha512 sha512;
  13305. byte hash1[WC_SHA512_DIGEST_SIZE];
  13306. /* Initialize */
  13307. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  13308. ExpectIntEQ(wc_Sha512GetHash(&sha512, hash1), 0);
  13309. /* test bad arguments*/
  13310. ExpectIntEQ(wc_Sha512GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13311. ExpectIntEQ(wc_Sha512GetHash(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13312. ExpectIntEQ(wc_Sha512GetHash(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13313. wc_Sha512Free(&sha512);
  13314. #endif
  13315. return EXPECT_RESULT();
  13316. } /* END test_wc_Sha512GetHash */
  13317. /*
  13318. * Unit test function for wc_Sha512Copy()
  13319. */
  13320. static int test_wc_Sha512Copy(void)
  13321. {
  13322. EXPECT_DECLS;
  13323. #ifdef WOLFSSL_SHA512
  13324. wc_Sha512 sha512;
  13325. wc_Sha512 temp;
  13326. XMEMSET(&sha512, 0, sizeof(wc_Sha512));
  13327. XMEMSET(&temp, 0, sizeof(wc_Sha512));
  13328. /* Initialize */
  13329. ExpectIntEQ(wc_InitSha512(&sha512), 0);
  13330. ExpectIntEQ(wc_InitSha512(&temp), 0);
  13331. ExpectIntEQ(wc_Sha512Copy(&sha512, &temp), 0);
  13332. /* test bad arguments*/
  13333. ExpectIntEQ(wc_Sha512Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13334. ExpectIntEQ(wc_Sha512Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13335. ExpectIntEQ(wc_Sha512Copy(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13336. wc_Sha512Free(&sha512);
  13337. wc_Sha512Free(&temp);
  13338. #endif
  13339. return EXPECT_RESULT();
  13340. } /* END test_wc_Sha512Copy */
  13341. static int test_wc_InitSha512_224(void)
  13342. {
  13343. EXPECT_DECLS;
  13344. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13345. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  13346. wc_Sha512 sha512;
  13347. /* Test good arg. */
  13348. ExpectIntEQ(wc_InitSha512_224(&sha512), 0);
  13349. /* Test bad arg. */
  13350. ExpectIntEQ(wc_InitSha512_224(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13351. wc_Sha512_224Free(&sha512);
  13352. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_224 */
  13353. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13354. return EXPECT_RESULT();
  13355. }
  13356. static int test_wc_Sha512_224Update(void)
  13357. {
  13358. EXPECT_DECLS;
  13359. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13360. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  13361. wc_Sha512 sha512;
  13362. byte hash[WC_SHA512_DIGEST_SIZE];
  13363. testVector a, c;
  13364. ExpectIntEQ(wc_InitSha512_224(&sha512), 0);
  13365. /* Input. */
  13366. a.input = "a";
  13367. a.inLen = XSTRLEN(a.input);
  13368. ExpectIntEQ(wc_Sha512_224Update(&sha512, NULL, 0), 0);
  13369. ExpectIntEQ(wc_Sha512_224Update(&sha512,(byte*)a.input, 0), 0);
  13370. ExpectIntEQ(wc_Sha512_224Update(&sha512, (byte*)a.input, (word32)a.inLen),
  13371. 0);
  13372. ExpectIntEQ(wc_Sha512_224Final(&sha512, hash), 0);
  13373. /* Update input. */
  13374. a.input = "abc";
  13375. a.output = "\x46\x34\x27\x0f\x70\x7b\x6a\x54\xda\xae\x75\x30\x46\x08"
  13376. "\x42\xe2\x0e\x37\xed\x26\x5c\xee\xe9\xa4\x3e\x89\x24\xaa";
  13377. a.inLen = XSTRLEN(a.input);
  13378. a.outLen = XSTRLEN(a.output);
  13379. ExpectIntEQ(wc_Sha512_224Update(&sha512, (byte*) a.input, (word32) a.inLen),
  13380. 0);
  13381. ExpectIntEQ(wc_Sha512_224Final(&sha512, hash), 0);
  13382. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA512_224_DIGEST_SIZE), 0);
  13383. c.input = NULL;
  13384. c.inLen = WC_SHA512_224_DIGEST_SIZE;
  13385. ExpectIntEQ(wc_Sha512_224Update(&sha512, (byte*)c.input, (word32)c.inLen),
  13386. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13387. ExpectIntEQ(wc_Sha512_224Update(NULL, (byte*)a.input, (word32)a.inLen),
  13388. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13389. wc_Sha512_224Free(&sha512);
  13390. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_224 */
  13391. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13392. return EXPECT_RESULT();
  13393. }
  13394. static int test_wc_Sha512_224Final(void)
  13395. {
  13396. EXPECT_DECLS;
  13397. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13398. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  13399. ExpectIntEQ(test_Sha512_Family_Final(WC_HASH_TYPE_SHA512_224, 0),
  13400. TEST_SUCCESS);
  13401. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_224 */
  13402. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13403. return EXPECT_RESULT();
  13404. }
  13405. static int test_wc_Sha512_224GetFlags(void)
  13406. {
  13407. EXPECT_DECLS;
  13408. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13409. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224) && defined(WOLFSSL_HASH_FLAGS)
  13410. wc_Sha512 sha512;
  13411. wc_Sha512 copy;
  13412. word32 flags = 0;
  13413. XMEMSET(&sha512, 0, sizeof(wc_Sha512));
  13414. XMEMSET(&copy, 0, sizeof(wc_Sha512));
  13415. /* Initialize */
  13416. ExpectIntEQ(wc_InitSha512_224(&sha512), 0);
  13417. ExpectIntEQ(wc_InitSha512_224(&copy), 0);
  13418. ExpectIntEQ(wc_Sha512_224GetFlags(&sha512, &flags), 0);
  13419. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  13420. ExpectIntEQ(wc_Sha512_224Copy(&sha512, &copy), 0);
  13421. ExpectIntEQ(wc_Sha512_224GetFlags(&copy, &flags), 0);
  13422. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == WC_HASH_FLAG_ISCOPY);
  13423. wc_Sha512_224Free(&copy);
  13424. wc_Sha512_224Free(&sha512);
  13425. #endif
  13426. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13427. return EXPECT_RESULT();
  13428. }
  13429. static int test_wc_Sha512_224FinalRaw(void)
  13430. {
  13431. EXPECT_DECLS;
  13432. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  13433. defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224) && \
  13434. !defined(WOLFSSL_NO_HASH_RAW)
  13435. ExpectIntEQ(test_Sha512_Family_Final(WC_HASH_TYPE_SHA512_224, 1),
  13436. TEST_SUCCESS);
  13437. #endif
  13438. return EXPECT_RESULT();
  13439. }
  13440. static int test_wc_Sha512_224Free(void)
  13441. {
  13442. EXPECT_DECLS;
  13443. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13444. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  13445. wc_Sha512_224Free(NULL);
  13446. /* Set result to SUCCESS. */
  13447. ExpectTrue(1);
  13448. #endif
  13449. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13450. return EXPECT_RESULT();
  13451. }
  13452. static int test_wc_Sha512_224GetHash(void)
  13453. {
  13454. EXPECT_DECLS;
  13455. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13456. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  13457. ExpectIntEQ(test_Sha512_Family_GetHash(WC_HASH_TYPE_SHA512_224),
  13458. TEST_SUCCESS);
  13459. #endif
  13460. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13461. return EXPECT_RESULT();
  13462. }
  13463. static int test_wc_Sha512_224Copy(void)
  13464. {
  13465. EXPECT_DECLS;
  13466. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13467. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  13468. wc_Sha512 sha512;
  13469. wc_Sha512 temp;
  13470. XMEMSET(&sha512, 0, sizeof(wc_Sha512));
  13471. XMEMSET(&temp, 0, sizeof(wc_Sha512));
  13472. /* Initialize */
  13473. ExpectIntEQ(wc_InitSha512_224(&sha512), 0);
  13474. ExpectIntEQ(wc_InitSha512_224(&temp), 0);
  13475. ExpectIntEQ(wc_Sha512_224Copy(&sha512, &temp), 0);
  13476. /* test bad arguments*/
  13477. ExpectIntEQ(wc_Sha512_224Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13478. ExpectIntEQ(wc_Sha512_224Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13479. ExpectIntEQ(wc_Sha512_224Copy(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13480. wc_Sha512_224Free(&sha512);
  13481. wc_Sha512_224Free(&temp);
  13482. #endif
  13483. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13484. return EXPECT_RESULT();
  13485. }
  13486. static int test_wc_InitSha512_256(void)
  13487. {
  13488. EXPECT_DECLS;
  13489. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13490. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  13491. wc_Sha512 sha512;
  13492. /* Test good arg. */
  13493. ExpectIntEQ(wc_InitSha512_256(&sha512), 0);
  13494. /* Test bad arg. */
  13495. ExpectIntEQ(wc_InitSha512_256(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13496. wc_Sha512_256Free(&sha512);
  13497. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_256 */
  13498. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13499. return EXPECT_RESULT();
  13500. }
  13501. static int test_wc_Sha512_256Update(void)
  13502. {
  13503. EXPECT_DECLS;
  13504. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13505. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  13506. wc_Sha512 sha512;
  13507. byte hash[WC_SHA512_DIGEST_SIZE];
  13508. testVector a, c;
  13509. ExpectIntEQ(wc_InitSha512_256(&sha512), 0);
  13510. /* Input. */
  13511. a.input = "a";
  13512. a.inLen = XSTRLEN(a.input);
  13513. ExpectIntEQ(wc_Sha512_256Update(&sha512, NULL, 0), 0);
  13514. ExpectIntEQ(wc_Sha512_256Update(&sha512,(byte*)a.input, 0), 0);
  13515. ExpectIntEQ(wc_Sha512_256Update(&sha512, (byte*)a.input, (word32)a.inLen),
  13516. 0);
  13517. ExpectIntEQ(wc_Sha512_256Final(&sha512, hash), 0);
  13518. /* Update input. */
  13519. a.input = "abc";
  13520. a.output = "\x53\x04\x8e\x26\x81\x94\x1e\xf9\x9b\x2e\x29\xb7\x6b\x4c"
  13521. "\x7d\xab\xe4\xc2\xd0\xc6\x34\xfc\x6d\x46\xe0\xe2\xf1\x31"
  13522. "\x07\xe7\xaf\x23";
  13523. a.inLen = XSTRLEN(a.input);
  13524. a.outLen = XSTRLEN(a.output);
  13525. ExpectIntEQ(wc_Sha512_256Update(&sha512, (byte*) a.input, (word32) a.inLen),
  13526. 0);
  13527. ExpectIntEQ(wc_Sha512_256Final(&sha512, hash), 0);
  13528. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA512_256_DIGEST_SIZE), 0);
  13529. c.input = NULL;
  13530. c.inLen = WC_SHA512_256_DIGEST_SIZE;
  13531. ExpectIntEQ(wc_Sha512_256Update(&sha512, (byte*)c.input, (word32)c.inLen),
  13532. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13533. ExpectIntEQ(wc_Sha512_256Update(NULL, (byte*)a.input, (word32)a.inLen),
  13534. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13535. wc_Sha512_256Free(&sha512);
  13536. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_256 */
  13537. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13538. return EXPECT_RESULT();
  13539. }
  13540. static int test_wc_Sha512_256Final(void)
  13541. {
  13542. EXPECT_DECLS;
  13543. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13544. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  13545. ExpectIntEQ(test_Sha512_Family_Final(WC_HASH_TYPE_SHA512_256, 0),
  13546. TEST_SUCCESS);
  13547. #endif /* WOLFSSL_SHA512 && !WOLFSSL_NOSHA512_256 */
  13548. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13549. return EXPECT_RESULT();
  13550. }
  13551. static int test_wc_Sha512_256GetFlags(void)
  13552. {
  13553. EXPECT_DECLS;
  13554. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13555. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256) && defined(WOLFSSL_HASH_FLAGS)
  13556. wc_Sha512 sha512, copy;
  13557. word32 flags = 0;
  13558. XMEMSET(&sha512, 0, sizeof(wc_Sha512));
  13559. XMEMSET(&copy, 0, sizeof(wc_Sha512));
  13560. /* Initialize */
  13561. ExpectIntEQ(wc_InitSha512_256(&sha512), 0);
  13562. ExpectIntEQ(wc_InitSha512_256(&copy), 0);
  13563. ExpectIntEQ(wc_Sha512_256GetFlags(&sha512, &flags), 0);
  13564. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  13565. ExpectIntEQ(wc_Sha512_256Copy(&sha512, &copy), 0);
  13566. ExpectIntEQ(wc_Sha512_256GetFlags(&copy, &flags), 0);
  13567. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == WC_HASH_FLAG_ISCOPY);
  13568. wc_Sha512_256Free(&sha512);
  13569. #endif
  13570. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13571. return EXPECT_RESULT();
  13572. }
  13573. static int test_wc_Sha512_256FinalRaw(void)
  13574. {
  13575. EXPECT_DECLS;
  13576. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  13577. defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256) && \
  13578. !defined(WOLFSSL_NO_HASH_RAW)
  13579. ExpectIntEQ(test_Sha512_Family_Final(WC_HASH_TYPE_SHA512_256, 1),
  13580. TEST_SUCCESS);
  13581. #endif
  13582. return EXPECT_RESULT();
  13583. }
  13584. static int test_wc_Sha512_256Free(void)
  13585. {
  13586. EXPECT_DECLS;
  13587. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13588. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  13589. wc_Sha512_256Free(NULL);
  13590. /* Set result to SUCCESS. */
  13591. ExpectTrue(1);
  13592. #endif
  13593. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13594. return EXPECT_RESULT();
  13595. }
  13596. static int test_wc_Sha512_256GetHash(void)
  13597. {
  13598. EXPECT_DECLS;
  13599. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13600. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  13601. ExpectIntEQ(test_Sha512_Family_GetHash(WC_HASH_TYPE_SHA512_256),
  13602. TEST_SUCCESS);
  13603. #endif
  13604. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13605. return EXPECT_RESULT();
  13606. }
  13607. static int test_wc_Sha512_256Copy(void)
  13608. {
  13609. EXPECT_DECLS;
  13610. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  13611. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  13612. wc_Sha512 sha512;
  13613. wc_Sha512 temp;
  13614. XMEMSET(&sha512, 0, sizeof(wc_Sha512));
  13615. XMEMSET(&temp, 0, sizeof(wc_Sha512));
  13616. /* Initialize */
  13617. ExpectIntEQ(wc_InitSha512_256(&sha512), 0);
  13618. ExpectIntEQ(wc_InitSha512_256(&temp), 0);
  13619. ExpectIntEQ(wc_Sha512_256Copy(&sha512, &temp), 0);
  13620. /* test bad arguments*/
  13621. ExpectIntEQ(wc_Sha512_256Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13622. ExpectIntEQ(wc_Sha512_256Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13623. ExpectIntEQ(wc_Sha512_256Copy(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13624. wc_Sha512_256Free(&sha512);
  13625. wc_Sha512_256Free(&temp);
  13626. #endif
  13627. #endif /* !HAVE_FIPS && !HAVE_SELFTEST */
  13628. return EXPECT_RESULT();
  13629. }
  13630. /*
  13631. * Testing wc_InitSha384()
  13632. */
  13633. static int test_wc_InitSha384(void)
  13634. {
  13635. EXPECT_DECLS;
  13636. #ifdef WOLFSSL_SHA384
  13637. wc_Sha384 sha384;
  13638. /* Test good arg. */
  13639. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13640. /* Test bad arg. */
  13641. ExpectIntEQ(wc_InitSha384(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13642. wc_Sha384Free(&sha384);
  13643. #endif
  13644. return EXPECT_RESULT();
  13645. } /* END test_wc_InitSha384 */
  13646. /*
  13647. * test wc_Sha384Update()
  13648. */
  13649. static int test_wc_Sha384Update(void)
  13650. {
  13651. EXPECT_DECLS;
  13652. #ifdef WOLFSSL_SHA384
  13653. wc_Sha384 sha384;
  13654. byte hash[WC_SHA384_DIGEST_SIZE];
  13655. testVector a, b, c;
  13656. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13657. /* Input */
  13658. a.input = "a";
  13659. a.inLen = XSTRLEN(a.input);
  13660. ExpectIntEQ(wc_Sha384Update(&sha384, NULL, 0), 0);
  13661. ExpectIntEQ(wc_Sha384Update(&sha384, (byte*)a.input, 0), 0);
  13662. ExpectIntEQ(wc_Sha384Update(&sha384, (byte*)a.input, (word32)a.inLen), 0);
  13663. ExpectIntEQ(wc_Sha384Final(&sha384, hash), 0);
  13664. /* Update input. */
  13665. a.input = "abc";
  13666. a.output = "\xcb\x00\x75\x3f\x45\xa3\x5e\x8b\xb5\xa0\x3d\x69\x9a\xc6\x50"
  13667. "\x07\x27\x2c\x32\xab\x0e\xde\xd1\x63\x1a\x8b\x60\x5a\x43\xff"
  13668. "\x5b\xed\x80\x86\x07\x2b\xa1\xe7\xcc\x23\x58\xba\xec\xa1\x34"
  13669. "\xc8\x25\xa7";
  13670. a.inLen = XSTRLEN(a.input);
  13671. a.outLen = XSTRLEN(a.output);
  13672. ExpectIntEQ(wc_Sha384Update(&sha384, (byte*)a.input, (word32)a.inLen), 0);
  13673. ExpectIntEQ(wc_Sha384Final(&sha384, hash), 0);
  13674. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA384_DIGEST_SIZE), 0);
  13675. /* Pass in bad values. */
  13676. b.input = NULL;
  13677. b.inLen = 0;
  13678. ExpectIntEQ(wc_Sha384Update(&sha384, (byte*)b.input, (word32)b.inLen), 0);
  13679. c.input = NULL;
  13680. c.inLen = WC_SHA384_DIGEST_SIZE;
  13681. ExpectIntEQ( wc_Sha384Update(&sha384, (byte*)c.input, (word32)c.inLen),
  13682. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13683. ExpectIntEQ(wc_Sha384Update(NULL, (byte*)a.input, (word32)a.inLen),
  13684. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13685. wc_Sha384Free(&sha384);
  13686. #endif
  13687. return EXPECT_RESULT();
  13688. } /* END test_wc_Sha384Update */
  13689. /*
  13690. * Unit test function for wc_Sha384Final();
  13691. */
  13692. static int test_wc_Sha384Final(void)
  13693. {
  13694. EXPECT_DECLS;
  13695. #ifdef WOLFSSL_SHA384
  13696. wc_Sha384 sha384;
  13697. byte* hash_test[3];
  13698. byte hash1[WC_SHA384_DIGEST_SIZE];
  13699. byte hash2[2*WC_SHA384_DIGEST_SIZE];
  13700. byte hash3[5*WC_SHA384_DIGEST_SIZE];
  13701. int times, i;
  13702. /* Initialize */
  13703. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13704. hash_test[0] = hash1;
  13705. hash_test[1] = hash2;
  13706. hash_test[2] = hash3;
  13707. times = sizeof(hash_test) / sizeof(byte*);
  13708. /* Good test args. */
  13709. for (i = 0; i < times; i++) {
  13710. ExpectIntEQ(wc_Sha384Final(&sha384, hash_test[i]), 0);
  13711. }
  13712. /* Test bad args. */
  13713. ExpectIntEQ(wc_Sha384Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13714. ExpectIntEQ(wc_Sha384Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13715. ExpectIntEQ(wc_Sha384Final(&sha384, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13716. wc_Sha384Free(&sha384);
  13717. #endif
  13718. return EXPECT_RESULT();
  13719. } /* END test_wc_Sha384Final */
  13720. /*
  13721. * Unit test function for wc_Sha384GetFlags()
  13722. */
  13723. static int test_wc_Sha384GetFlags(void)
  13724. {
  13725. EXPECT_DECLS;
  13726. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_HASH_FLAGS)
  13727. wc_Sha384 sha384;
  13728. word32 flags = 0;
  13729. /* Initialize */
  13730. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13731. ExpectIntEQ(wc_Sha384GetFlags(&sha384, &flags), 0);
  13732. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  13733. wc_Sha384Free(&sha384);
  13734. #endif
  13735. return EXPECT_RESULT();
  13736. } /* END test_wc_Sha384GetFlags */
  13737. /*
  13738. * Unit test function for wc_Sha384FinalRaw()
  13739. */
  13740. static int test_wc_Sha384FinalRaw(void)
  13741. {
  13742. EXPECT_DECLS;
  13743. #if (defined(WOLFSSL_SHA384) && !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  13744. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3)))) && \
  13745. !defined(WOLFSSL_NO_HASH_RAW)
  13746. wc_Sha384 sha384;
  13747. byte* hash_test[3];
  13748. byte hash1[WC_SHA384_DIGEST_SIZE];
  13749. byte hash2[2*WC_SHA384_DIGEST_SIZE];
  13750. byte hash3[5*WC_SHA384_DIGEST_SIZE];
  13751. int times, i;
  13752. /* Initialize */
  13753. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13754. hash_test[0] = hash1;
  13755. hash_test[1] = hash2;
  13756. hash_test[2] = hash3;
  13757. times = sizeof(hash_test) / sizeof(byte*);
  13758. /* Good test args. */
  13759. for (i = 0; i < times; i++) {
  13760. ExpectIntEQ(wc_Sha384FinalRaw(&sha384, hash_test[i]), 0);
  13761. }
  13762. /* Test bad args. */
  13763. ExpectIntEQ(wc_Sha384FinalRaw(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13764. ExpectIntEQ(wc_Sha384FinalRaw(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13765. ExpectIntEQ(wc_Sha384FinalRaw(&sha384, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13766. wc_Sha384Free(&sha384);
  13767. #endif
  13768. return EXPECT_RESULT();
  13769. } /* END test_wc_Sha384FinalRaw */
  13770. /*
  13771. * Unit test function for wc_Sha384Free()
  13772. */
  13773. static int test_wc_Sha384Free(void)
  13774. {
  13775. EXPECT_DECLS;
  13776. #ifdef WOLFSSL_SHA384
  13777. wc_Sha384Free(NULL);
  13778. /* Set result to SUCCESS. */
  13779. ExpectTrue(1);
  13780. #endif
  13781. return EXPECT_RESULT();
  13782. } /* END test_wc_Sha384Free */
  13783. /*
  13784. * Unit test function for wc_Sha384GetHash()
  13785. */
  13786. static int test_wc_Sha384GetHash(void)
  13787. {
  13788. EXPECT_DECLS;
  13789. #ifdef WOLFSSL_SHA384
  13790. wc_Sha384 sha384;
  13791. byte hash1[WC_SHA384_DIGEST_SIZE];
  13792. /* Initialize */
  13793. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13794. ExpectIntEQ(wc_Sha384GetHash(&sha384, hash1), 0);
  13795. /* test bad arguments*/
  13796. ExpectIntEQ(wc_Sha384GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13797. ExpectIntEQ(wc_Sha384GetHash(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13798. ExpectIntEQ(wc_Sha384GetHash(&sha384, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13799. wc_Sha384Free(&sha384);
  13800. #endif
  13801. return EXPECT_RESULT();
  13802. } /* END test_wc_Sha384GetHash */
  13803. /*
  13804. * Unit test function for wc_Sha384Copy()
  13805. */
  13806. static int test_wc_Sha384Copy(void)
  13807. {
  13808. EXPECT_DECLS;
  13809. #ifdef WOLFSSL_SHA384
  13810. wc_Sha384 sha384;
  13811. wc_Sha384 temp;
  13812. XMEMSET(&sha384, 0, sizeof(wc_Sha384));
  13813. XMEMSET(&temp, 0, sizeof(wc_Sha384));
  13814. /* Initialize */
  13815. ExpectIntEQ(wc_InitSha384(&sha384), 0);
  13816. ExpectIntEQ(wc_InitSha384(&temp), 0);
  13817. ExpectIntEQ(wc_Sha384Copy(&sha384, &temp), 0);
  13818. /* test bad arguments*/
  13819. ExpectIntEQ(wc_Sha384Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13820. ExpectIntEQ(wc_Sha384Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13821. ExpectIntEQ(wc_Sha384Copy(&sha384, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13822. wc_Sha384Free(&sha384);
  13823. wc_Sha384Free(&temp);
  13824. #endif
  13825. return EXPECT_RESULT();
  13826. } /* END test_wc_Sha384Copy */
  13827. /*
  13828. * Testing wc_InitSha224();
  13829. */
  13830. static int test_wc_InitSha224(void)
  13831. {
  13832. EXPECT_DECLS;
  13833. #ifdef WOLFSSL_SHA224
  13834. wc_Sha224 sha224;
  13835. /* Test good arg. */
  13836. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13837. /* Test bad arg. */
  13838. ExpectIntEQ(wc_InitSha224(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13839. wc_Sha224Free(&sha224);
  13840. #endif
  13841. return EXPECT_RESULT();
  13842. } /* END test_wc_InitSha224 */
  13843. /*
  13844. * Unit test on wc_Sha224Update
  13845. */
  13846. static int test_wc_Sha224Update(void)
  13847. {
  13848. EXPECT_DECLS;
  13849. #ifdef WOLFSSL_SHA224
  13850. wc_Sha224 sha224;
  13851. byte hash[WC_SHA224_DIGEST_SIZE];
  13852. testVector a, b, c;
  13853. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13854. /* Input. */
  13855. a.input = "a";
  13856. a.inLen = XSTRLEN(a.input);
  13857. ExpectIntEQ(wc_Sha224Update(&sha224, NULL, 0), 0);
  13858. ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)a.input, 0), 0);
  13859. ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)a.input, (word32)a.inLen), 0);
  13860. ExpectIntEQ(wc_Sha224Final(&sha224, hash), 0);
  13861. /* Update input. */
  13862. a.input = "abc";
  13863. a.output = "\x23\x09\x7d\x22\x34\x05\xd8\x22\x86\x42\xa4\x77\xbd\xa2"
  13864. "\x55\xb3\x2a\xad\xbc\xe4\xbd\xa0\xb3\xf7\xe3\x6c\x9d\xa7";
  13865. a.inLen = XSTRLEN(a.input);
  13866. a.outLen = XSTRLEN(a.output);
  13867. ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)a.input, (word32)a.inLen), 0);
  13868. ExpectIntEQ(wc_Sha224Final(&sha224, hash), 0);
  13869. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA224_DIGEST_SIZE), 0);
  13870. /* Pass in bad values. */
  13871. b.input = NULL;
  13872. b.inLen = 0;
  13873. ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)b.input, (word32)b.inLen), 0);
  13874. c.input = NULL;
  13875. c.inLen = WC_SHA224_DIGEST_SIZE;
  13876. ExpectIntEQ(wc_Sha224Update(&sha224, (byte*)c.input, (word32)c.inLen),
  13877. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13878. ExpectIntEQ(wc_Sha224Update(NULL, (byte*)a.input, (word32)a.inLen),
  13879. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13880. wc_Sha224Free(&sha224);
  13881. #endif
  13882. return EXPECT_RESULT();
  13883. } /* END test_wc_Sha224Update */
  13884. /*
  13885. * Unit test for wc_Sha224Final();
  13886. */
  13887. static int test_wc_Sha224Final(void)
  13888. {
  13889. EXPECT_DECLS;
  13890. #ifdef WOLFSSL_SHA224
  13891. wc_Sha224 sha224;
  13892. byte* hash_test[3];
  13893. byte hash1[WC_SHA224_DIGEST_SIZE];
  13894. byte hash2[2*WC_SHA224_DIGEST_SIZE];
  13895. byte hash3[5*WC_SHA224_DIGEST_SIZE];
  13896. int times, i;
  13897. /* Initialize */
  13898. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13899. hash_test[0] = hash1;
  13900. hash_test[1] = hash2;
  13901. hash_test[2] = hash3;
  13902. times = sizeof(hash_test) / sizeof(byte*);
  13903. /* Good test args. */
  13904. /* Testing oversized buffers. */
  13905. for (i = 0; i < times; i++) {
  13906. ExpectIntEQ(wc_Sha224Final(&sha224, hash_test[i]), 0);
  13907. }
  13908. /* Test bad args. */
  13909. ExpectIntEQ(wc_Sha224Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13910. ExpectIntEQ(wc_Sha224Final(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13911. ExpectIntEQ(wc_Sha224Final(&sha224, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13912. wc_Sha224Free(&sha224);
  13913. #endif
  13914. return EXPECT_RESULT();
  13915. } /* END test_wc_Sha224Final */
  13916. /*
  13917. * Unit test function for wc_Sha224SetFlags()
  13918. */
  13919. static int test_wc_Sha224SetFlags(void)
  13920. {
  13921. EXPECT_DECLS;
  13922. #if defined(WOLFSSL_SHA224) && defined(WOLFSSL_HASH_FLAGS)
  13923. wc_Sha224 sha224;
  13924. word32 flags = WC_HASH_FLAG_WILLCOPY;
  13925. /* Initialize */
  13926. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13927. ExpectIntEQ(wc_Sha224SetFlags(&sha224, flags), 0);
  13928. flags = 0;
  13929. ExpectIntEQ(wc_Sha224GetFlags(&sha224, &flags), 0);
  13930. ExpectTrue(flags == WC_HASH_FLAG_WILLCOPY);
  13931. wc_Sha224Free(&sha224);
  13932. #endif
  13933. return EXPECT_RESULT();
  13934. } /* END test_wc_Sha224SetFlags */
  13935. /*
  13936. * Unit test function for wc_Sha224GetFlags()
  13937. */
  13938. static int test_wc_Sha224GetFlags(void)
  13939. {
  13940. EXPECT_DECLS;
  13941. #if defined(WOLFSSL_SHA224) && defined(WOLFSSL_HASH_FLAGS)
  13942. wc_Sha224 sha224;
  13943. word32 flags = 0;
  13944. /* Initialize */
  13945. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13946. ExpectIntEQ(wc_Sha224GetFlags(&sha224, &flags), 0);
  13947. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  13948. wc_Sha224Free(&sha224);
  13949. #endif
  13950. return EXPECT_RESULT();
  13951. } /* END test_wc_Sha224GetFlags */
  13952. /*
  13953. * Unit test function for wc_Sha224Free()
  13954. */
  13955. static int test_wc_Sha224Free(void)
  13956. {
  13957. EXPECT_DECLS;
  13958. #ifdef WOLFSSL_SHA224
  13959. wc_Sha224Free(NULL);
  13960. /* Set result to SUCCESS. */
  13961. ExpectTrue(1);
  13962. #endif
  13963. return EXPECT_RESULT();
  13964. } /* END test_wc_Sha224Free */
  13965. /*
  13966. * Unit test function for wc_Sha224GetHash()
  13967. */
  13968. static int test_wc_Sha224GetHash(void)
  13969. {
  13970. EXPECT_DECLS;
  13971. #ifdef WOLFSSL_SHA224
  13972. wc_Sha224 sha224;
  13973. byte hash1[WC_SHA224_DIGEST_SIZE];
  13974. /* Initialize */
  13975. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13976. ExpectIntEQ(wc_Sha224GetHash(&sha224, hash1), 0);
  13977. /* test bad arguments*/
  13978. ExpectIntEQ(wc_Sha224GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13979. ExpectIntEQ(wc_Sha224GetHash(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13980. ExpectIntEQ(wc_Sha224GetHash(&sha224, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  13981. wc_Sha224Free(&sha224);
  13982. #endif
  13983. return EXPECT_RESULT();
  13984. } /* END test_wc_Sha224GetHash */
  13985. /*
  13986. * Unit test function for wc_Sha224Copy()
  13987. */
  13988. static int test_wc_Sha224Copy(void)
  13989. {
  13990. EXPECT_DECLS;
  13991. #ifdef WOLFSSL_SHA224
  13992. wc_Sha224 sha224;
  13993. wc_Sha224 temp;
  13994. XMEMSET(&sha224, 0, sizeof(wc_Sha224));
  13995. XMEMSET(&temp, 0, sizeof(wc_Sha224));
  13996. /* Initialize */
  13997. ExpectIntEQ(wc_InitSha224(&sha224), 0);
  13998. ExpectIntEQ(wc_InitSha224(&temp), 0);
  13999. ExpectIntEQ(wc_Sha224Copy(&sha224, &temp), 0);
  14000. /* test bad arguments*/
  14001. ExpectIntEQ(wc_Sha224Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14002. ExpectIntEQ(wc_Sha224Copy(NULL, &temp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14003. ExpectIntEQ(wc_Sha224Copy(&sha224, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14004. wc_Sha224Free(&sha224);
  14005. wc_Sha224Free(&temp);
  14006. #endif
  14007. return EXPECT_RESULT();
  14008. } /* END test_wc_Sha224Copy */
  14009. /*
  14010. * Testing wc_InitRipeMd()
  14011. */
  14012. static int test_wc_InitRipeMd(void)
  14013. {
  14014. EXPECT_DECLS;
  14015. #ifdef WOLFSSL_RIPEMD
  14016. RipeMd ripemd;
  14017. /* Test good arg. */
  14018. ExpectIntEQ(wc_InitRipeMd(&ripemd), 0);
  14019. /* Test bad arg. */
  14020. ExpectIntEQ(wc_InitRipeMd(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14021. #endif
  14022. return EXPECT_RESULT();
  14023. } /* END test_wc_InitRipeMd */
  14024. /*
  14025. * Testing wc_RipeMdUpdate()
  14026. */
  14027. static int test_wc_RipeMdUpdate(void)
  14028. {
  14029. EXPECT_DECLS;
  14030. #ifdef WOLFSSL_RIPEMD
  14031. RipeMd ripemd;
  14032. byte hash[RIPEMD_DIGEST_SIZE];
  14033. testVector a, b, c;
  14034. ExpectIntEQ(wc_InitRipeMd(&ripemd), 0);
  14035. /* Input */
  14036. a.input = "a";
  14037. a.inLen = XSTRLEN(a.input);
  14038. ExpectIntEQ(wc_RipeMdUpdate(&ripemd, (byte*)a.input, (word32)a.inLen), 0);
  14039. ExpectIntEQ(wc_RipeMdFinal(&ripemd, hash), 0);
  14040. /* Update input. */
  14041. a.input = "abc";
  14042. a.output = "\x8e\xb2\x08\xf7\xe0\x5d\x98\x7a\x9b\x04\x4a\x8e\x98\xc6"
  14043. "\xb0\x87\xf1\x5a\x0b\xfc";
  14044. a.inLen = XSTRLEN(a.input);
  14045. a.outLen = XSTRLEN(a.output);
  14046. ExpectIntEQ(wc_RipeMdUpdate(&ripemd, (byte*)a.input, (word32)a.inLen), 0);
  14047. ExpectIntEQ(wc_RipeMdFinal(&ripemd, hash), 0);
  14048. ExpectIntEQ(XMEMCMP(hash, a.output, RIPEMD_DIGEST_SIZE), 0);
  14049. /* Pass in bad values. */
  14050. b.input = NULL;
  14051. b.inLen = 0;
  14052. ExpectIntEQ(wc_RipeMdUpdate(&ripemd, (byte*)b.input, (word32)b.inLen), 0);
  14053. c.input = NULL;
  14054. c.inLen = RIPEMD_DIGEST_SIZE;
  14055. ExpectIntEQ(wc_RipeMdUpdate(&ripemd, (byte*)c.input, (word32)c.inLen),
  14056. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14057. ExpectIntEQ(wc_RipeMdUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  14058. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14059. #endif
  14060. return EXPECT_RESULT();
  14061. } /* END test_wc_RipeMdUdpate */
  14062. /*
  14063. * Unit test function for wc_RipeMdFinal()
  14064. */
  14065. static int test_wc_RipeMdFinal(void)
  14066. {
  14067. EXPECT_DECLS;
  14068. #ifdef WOLFSSL_RIPEMD
  14069. RipeMd ripemd;
  14070. byte* hash_test[3];
  14071. byte hash1[RIPEMD_DIGEST_SIZE];
  14072. byte hash2[2*RIPEMD_DIGEST_SIZE];
  14073. byte hash3[5*RIPEMD_DIGEST_SIZE];
  14074. int times, i;
  14075. /* Initialize */
  14076. ExpectIntEQ(wc_InitRipeMd(&ripemd), 0);
  14077. hash_test[0] = hash1;
  14078. hash_test[1] = hash2;
  14079. hash_test[2] = hash3;
  14080. times = sizeof(hash_test) / sizeof(byte*);
  14081. /* Testing oversized buffers. */
  14082. for (i = 0; i < times; i++) {
  14083. ExpectIntEQ(wc_RipeMdFinal(&ripemd, hash_test[i]), 0);
  14084. }
  14085. /* Test bad args. */
  14086. ExpectIntEQ(wc_RipeMdFinal(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14087. ExpectIntEQ(wc_RipeMdFinal(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14088. ExpectIntEQ(wc_RipeMdFinal(&ripemd, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14089. #endif
  14090. return EXPECT_RESULT();
  14091. } /* END test_wc_RipeMdFinal */
  14092. /*
  14093. * Testing wc_InitSha3_224, wc_InitSha3_256, wc_InitSha3_384, and
  14094. * wc_InitSha3_512
  14095. */
  14096. static int test_wc_InitSha3(void)
  14097. {
  14098. EXPECT_DECLS;
  14099. #if defined(WOLFSSL_SHA3)
  14100. wc_Sha3 sha3;
  14101. (void)sha3;
  14102. #if !defined(WOLFSSL_NOSHA3_224)
  14103. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  14104. /* Test bad args. */
  14105. ExpectIntEQ(wc_InitSha3_224(NULL, HEAP_HINT, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14106. wc_Sha3_224_Free(&sha3);
  14107. #endif /* NOSHA3_224 */
  14108. #if !defined(WOLFSSL_NOSHA3_256)
  14109. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  14110. /* Test bad args. */
  14111. ExpectIntEQ(wc_InitSha3_256(NULL, HEAP_HINT, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14112. wc_Sha3_256_Free(&sha3);
  14113. #endif /* NOSHA3_256 */
  14114. #if !defined(WOLFSSL_NOSHA3_384)
  14115. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  14116. /* Test bad args. */
  14117. ExpectIntEQ(wc_InitSha3_384(NULL, HEAP_HINT, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14118. wc_Sha3_384_Free(&sha3);
  14119. #endif /* NOSHA3_384 */
  14120. #if !defined(WOLFSSL_NOSHA3_512)
  14121. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  14122. /* Test bad args. */
  14123. ExpectIntEQ(wc_InitSha3_512(NULL, HEAP_HINT, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14124. wc_Sha3_512_Free(&sha3);
  14125. #endif /* NOSHA3_512 */
  14126. #endif
  14127. return EXPECT_RESULT();
  14128. } /* END test_wc_InitSha3 */
  14129. /*
  14130. * Testing wc_Sha3_Update()
  14131. */
  14132. static int testing_wc_Sha3_Update(void)
  14133. {
  14134. EXPECT_DECLS;
  14135. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_XILINX_CRYPT) && \
  14136. !defined(WOLFSSL_AFALG_XILINX)
  14137. wc_Sha3 sha3;
  14138. byte msg[] = "Everybody's working for the weekend.";
  14139. byte msg2[] = "Everybody gets Friday off.";
  14140. byte msgCmp[] = "\x45\x76\x65\x72\x79\x62\x6f\x64\x79\x27\x73\x20"
  14141. "\x77\x6f\x72\x6b\x69\x6e\x67\x20\x66\x6f\x72\x20\x74"
  14142. "\x68\x65\x20\x77\x65\x65\x6b\x65\x6e\x64\x2e\x45\x76"
  14143. "\x65\x72\x79\x62\x6f\x64\x79\x20\x67\x65\x74\x73\x20"
  14144. "\x46\x72\x69\x64\x61\x79\x20\x6f\x66\x66\x2e";
  14145. word32 msglen = sizeof(msg) - 1;
  14146. word32 msg2len = sizeof(msg2);
  14147. word32 msgCmplen = sizeof(msgCmp);
  14148. #if !defined(WOLFSSL_NOSHA3_224)
  14149. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  14150. ExpectIntEQ(wc_Sha3_224_Update(&sha3, msg, msglen), 0);
  14151. ExpectIntEQ(XMEMCMP(msg, sha3.t, msglen), 0);
  14152. ExpectTrue(sha3.i == msglen);
  14153. ExpectIntEQ(wc_Sha3_224_Update(&sha3, msg2, msg2len), 0);
  14154. ExpectIntEQ(XMEMCMP(sha3.t, msgCmp, msgCmplen), 0);
  14155. /* Pass bad args. */
  14156. ExpectIntEQ(wc_Sha3_224_Update(NULL, msg2, msg2len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14157. ExpectIntEQ(wc_Sha3_224_Update(&sha3, NULL, 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14158. wc_Sha3_224_Free(&sha3);
  14159. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  14160. ExpectIntEQ(wc_Sha3_224_Update(&sha3, NULL, 0), 0);
  14161. ExpectIntEQ(wc_Sha3_224_Update(&sha3, msg2, msg2len), 0);
  14162. ExpectIntEQ(XMEMCMP(msg2, sha3.t, msg2len), 0);
  14163. wc_Sha3_224_Free(&sha3);
  14164. #endif /* SHA3_224 */
  14165. #if !defined(WOLFSSL_NOSHA3_256)
  14166. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  14167. ExpectIntEQ(wc_Sha3_256_Update(&sha3, msg, msglen), 0);
  14168. ExpectIntEQ(XMEMCMP(msg, sha3.t, msglen), 0);
  14169. ExpectTrue(sha3.i == msglen);
  14170. ExpectIntEQ(wc_Sha3_256_Update(&sha3, msg2, msg2len), 0);
  14171. ExpectIntEQ(XMEMCMP(sha3.t, msgCmp, msgCmplen), 0);
  14172. /* Pass bad args. */
  14173. ExpectIntEQ(wc_Sha3_256_Update(NULL, msg2, msg2len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14174. ExpectIntEQ(wc_Sha3_256_Update(&sha3, NULL, 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14175. wc_Sha3_256_Free(&sha3);
  14176. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  14177. ExpectIntEQ(wc_Sha3_256_Update(&sha3, NULL, 0), 0);
  14178. ExpectIntEQ(wc_Sha3_256_Update(&sha3, msg2, msg2len), 0);
  14179. ExpectIntEQ(XMEMCMP(msg2, sha3.t, msg2len), 0);
  14180. wc_Sha3_256_Free(&sha3);
  14181. #endif /* SHA3_256 */
  14182. #if !defined(WOLFSSL_NOSHA3_384)
  14183. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  14184. ExpectIntEQ(wc_Sha3_384_Update(&sha3, msg, msglen), 0);
  14185. ExpectIntEQ(XMEMCMP(msg, sha3.t, msglen), 0);
  14186. ExpectTrue(sha3.i == msglen);
  14187. ExpectIntEQ(wc_Sha3_384_Update(&sha3, msg2, msg2len), 0);
  14188. ExpectIntEQ(XMEMCMP(sha3.t, msgCmp, msgCmplen), 0);
  14189. /* Pass bad args. */
  14190. ExpectIntEQ(wc_Sha3_384_Update(NULL, msg2, msg2len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14191. ExpectIntEQ(wc_Sha3_384_Update(&sha3, NULL, 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14192. wc_Sha3_384_Free(&sha3);
  14193. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  14194. ExpectIntEQ(wc_Sha3_384_Update(&sha3, NULL, 0), 0);
  14195. ExpectIntEQ(wc_Sha3_384_Update(&sha3, msg2, msg2len), 0);
  14196. ExpectIntEQ(XMEMCMP(msg2, sha3.t, msg2len), 0);
  14197. wc_Sha3_384_Free(&sha3);
  14198. #endif /* SHA3_384 */
  14199. #if !defined(WOLFSSL_NOSHA3_512)
  14200. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  14201. ExpectIntEQ(wc_Sha3_512_Update(&sha3, msg, msglen), 0);
  14202. ExpectIntEQ(XMEMCMP(msg, sha3.t, msglen), 0);
  14203. ExpectTrue(sha3.i == msglen);
  14204. ExpectIntEQ(wc_Sha3_512_Update(&sha3, msg2, msg2len), 0);
  14205. ExpectIntEQ(XMEMCMP(sha3.t, msgCmp, msgCmplen), 0);
  14206. /* Pass bad args. */
  14207. ExpectIntEQ(wc_Sha3_512_Update(NULL, msg2, msg2len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14208. ExpectIntEQ(wc_Sha3_512_Update(&sha3, NULL, 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14209. wc_Sha3_512_Free(&sha3);
  14210. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  14211. ExpectIntEQ(wc_Sha3_512_Update(&sha3, NULL, 0), 0);
  14212. ExpectIntEQ(wc_Sha3_512_Update(&sha3, msg2, msg2len), 0);
  14213. ExpectIntEQ(XMEMCMP(msg2, sha3.t, msg2len), 0);
  14214. wc_Sha3_512_Free(&sha3);
  14215. #endif /* SHA3_512 */
  14216. #endif /* WOLFSSL_SHA3 */
  14217. return EXPECT_RESULT();
  14218. } /* END testing_wc_Sha3_Update */
  14219. /*
  14220. * Testing wc_Sha3_224_Final()
  14221. */
  14222. static int test_wc_Sha3_224_Final(void)
  14223. {
  14224. EXPECT_DECLS;
  14225. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_224)
  14226. wc_Sha3 sha3;
  14227. const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
  14228. "nopnopq";
  14229. const char* expOut = "\x8a\x24\x10\x8b\x15\x4a\xda\x21\xc9\xfd\x55"
  14230. "\x74\x49\x44\x79\xba\x5c\x7e\x7a\xb7\x6e\xf2"
  14231. "\x64\xea\xd0\xfc\xce\x33";
  14232. byte hash[WC_SHA3_224_DIGEST_SIZE];
  14233. byte hashRet[WC_SHA3_224_DIGEST_SIZE];
  14234. /* Init stack variables. */
  14235. XMEMSET(hash, 0, sizeof(hash));
  14236. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  14237. ExpectIntEQ(wc_Sha3_224_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14238. ExpectIntEQ(wc_Sha3_224_Final(&sha3, hash), 0);
  14239. ExpectIntEQ(XMEMCMP(expOut, hash, WC_SHA3_224_DIGEST_SIZE), 0);
  14240. /* Test bad args. */
  14241. ExpectIntEQ(wc_Sha3_224_Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14242. ExpectIntEQ(wc_Sha3_224_Final(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14243. wc_Sha3_224_Free(&sha3);
  14244. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  14245. /* Init stack variables. */
  14246. XMEMSET(hash, 0, sizeof(hash));
  14247. XMEMSET(hashRet, 0, sizeof(hashRet));
  14248. ExpectIntEQ(wc_Sha3_224_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14249. ExpectIntEQ(wc_Sha3_224_GetHash(&sha3, hashRet), 0);
  14250. ExpectIntEQ(wc_Sha3_224_Final(&sha3, hash), 0);
  14251. ExpectIntEQ(XMEMCMP(hash, hashRet, WC_SHA3_224_DIGEST_SIZE), 0);
  14252. /* Test bad args. */
  14253. ExpectIntEQ(wc_Sha3_224_GetHash(NULL, hashRet), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14254. ExpectIntEQ(wc_Sha3_224_GetHash(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14255. wc_Sha3_224_Free(&sha3);
  14256. #endif
  14257. return EXPECT_RESULT();
  14258. } /* END test_wc_Sha3_224_Final */
  14259. /*
  14260. * Testing wc_Sha3_256_Final()
  14261. */
  14262. static int test_wc_Sha3_256_Final(void)
  14263. {
  14264. EXPECT_DECLS;
  14265. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  14266. wc_Sha3 sha3;
  14267. const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
  14268. "nopnopq";
  14269. const char* expOut = "\x41\xc0\xdb\xa2\xa9\xd6\x24\x08\x49\x10\x03\x76\xa8"
  14270. "\x23\x5e\x2c\x82\xe1\xb9\x99\x8a\x99\x9e\x21\xdb\x32"
  14271. "\xdd\x97\x49\x6d\x33\x76";
  14272. byte hash[WC_SHA3_256_DIGEST_SIZE];
  14273. byte hashRet[WC_SHA3_256_DIGEST_SIZE];
  14274. /* Init stack variables. */
  14275. XMEMSET(hash, 0, sizeof(hash));
  14276. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  14277. ExpectIntEQ(wc_Sha3_256_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14278. ExpectIntEQ(wc_Sha3_256_Final(&sha3, hash), 0);
  14279. ExpectIntEQ(XMEMCMP(expOut, hash, WC_SHA3_256_DIGEST_SIZE), 0);
  14280. /* Test bad args. */
  14281. ExpectIntEQ(wc_Sha3_256_Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14282. ExpectIntEQ(wc_Sha3_256_Final(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14283. wc_Sha3_256_Free(&sha3);
  14284. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  14285. /* Init stack variables. */
  14286. XMEMSET(hash, 0, sizeof(hash));
  14287. XMEMSET(hashRet, 0, sizeof(hashRet));
  14288. ExpectIntEQ(wc_Sha3_256_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14289. ExpectIntEQ(wc_Sha3_256_GetHash(&sha3, hashRet), 0);
  14290. ExpectIntEQ(wc_Sha3_256_Final(&sha3, hash), 0);
  14291. ExpectIntEQ(XMEMCMP(hash, hashRet, WC_SHA3_256_DIGEST_SIZE), 0);
  14292. /* Test bad args. */
  14293. ExpectIntEQ(wc_Sha3_256_GetHash(NULL, hashRet), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14294. ExpectIntEQ(wc_Sha3_256_GetHash(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14295. wc_Sha3_256_Free(&sha3);
  14296. #endif
  14297. return EXPECT_RESULT();
  14298. } /* END test_wc_Sha3_256_Final */
  14299. /*
  14300. * Testing wc_Sha3_384_Final()
  14301. */
  14302. static int test_wc_Sha3_384_Final(void)
  14303. {
  14304. EXPECT_DECLS;
  14305. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_384)
  14306. wc_Sha3 sha3;
  14307. const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
  14308. "nopnopq";
  14309. const char* expOut = "\x99\x1c\x66\x57\x55\xeb\x3a\x4b\x6b\xbd\xfb\x75\xc7"
  14310. "\x8a\x49\x2e\x8c\x56\xa2\x2c\x5c\x4d\x7e\x42\x9b\xfd"
  14311. "\xbc\x32\xb9\xd4\xad\x5a\xa0\x4a\x1f\x07\x6e\x62\xfe"
  14312. "\xa1\x9e\xef\x51\xac\xd0\x65\x7c\x22";
  14313. byte hash[WC_SHA3_384_DIGEST_SIZE];
  14314. byte hashRet[WC_SHA3_384_DIGEST_SIZE];
  14315. /* Init stack variables. */
  14316. XMEMSET(hash, 0, sizeof(hash));
  14317. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  14318. ExpectIntEQ(wc_Sha3_384_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14319. ExpectIntEQ(wc_Sha3_384_Final(&sha3, hash), 0);
  14320. ExpectIntEQ(XMEMCMP(expOut, hash, WC_SHA3_384_DIGEST_SIZE), 0);
  14321. /* Test bad args. */
  14322. ExpectIntEQ(wc_Sha3_384_Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14323. ExpectIntEQ(wc_Sha3_384_Final(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14324. wc_Sha3_384_Free(&sha3);
  14325. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  14326. /* Init stack variables. */
  14327. XMEMSET(hash, 0, sizeof(hash));
  14328. XMEMSET(hashRet, 0, sizeof(hashRet));
  14329. ExpectIntEQ(wc_Sha3_384_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14330. ExpectIntEQ(wc_Sha3_384_GetHash(&sha3, hashRet), 0);
  14331. ExpectIntEQ(wc_Sha3_384_Final(&sha3, hash), 0);
  14332. ExpectIntEQ(XMEMCMP(hash, hashRet, WC_SHA3_384_DIGEST_SIZE), 0);
  14333. /* Test bad args. */
  14334. ExpectIntEQ(wc_Sha3_384_GetHash(NULL, hashRet), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14335. ExpectIntEQ(wc_Sha3_384_GetHash(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14336. wc_Sha3_384_Free(&sha3);
  14337. #endif
  14338. return EXPECT_RESULT();
  14339. } /* END test_wc_Sha3_384_Final */
  14340. /*
  14341. * Testing wc_Sha3_512_Final()
  14342. */
  14343. static int test_wc_Sha3_512_Final(void)
  14344. {
  14345. EXPECT_DECLS;
  14346. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_512) && \
  14347. !defined(WOLFSSL_NOSHA3_384)
  14348. wc_Sha3 sha3;
  14349. const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
  14350. "nopnopq";
  14351. const char* expOut = "\x04\xa3\x71\xe8\x4e\xcf\xb5\xb8\xb7\x7c\xb4\x86\x10"
  14352. "\xfc\xa8\x18\x2d\xd4\x57\xce\x6f\x32\x6a\x0f\xd3\xd7"
  14353. "\xec\x2f\x1e\x91\x63\x6d\xee\x69\x1f\xbe\x0c\x98\x53"
  14354. "\x02\xba\x1b\x0d\x8d\xc7\x8c\x08\x63\x46\xb5\x33\xb4"
  14355. "\x9c\x03\x0d\x99\xa2\x7d\xaf\x11\x39\xd6\xe7\x5e";
  14356. byte hash[WC_SHA3_512_DIGEST_SIZE];
  14357. byte hashRet[WC_SHA3_512_DIGEST_SIZE];
  14358. /* Init stack variables. */
  14359. XMEMSET(hash, 0, sizeof(hash));
  14360. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  14361. ExpectIntEQ(wc_Sha3_512_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14362. ExpectIntEQ(wc_Sha3_512_Final(&sha3, hash), 0);
  14363. ExpectIntEQ(XMEMCMP(expOut, hash, WC_SHA3_512_DIGEST_SIZE), 0);
  14364. /* Test bad args. */
  14365. ExpectIntEQ(wc_Sha3_512_Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14366. ExpectIntEQ(wc_Sha3_512_Final(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14367. wc_Sha3_512_Free(&sha3);
  14368. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  14369. /* Init stack variables. */
  14370. XMEMSET(hash, 0, sizeof(hash));
  14371. XMEMSET(hashRet, 0, sizeof(hashRet));
  14372. ExpectIntEQ(wc_Sha3_512_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg)), 0);
  14373. ExpectIntEQ(wc_Sha3_512_GetHash(&sha3, hashRet), 0);
  14374. ExpectIntEQ(wc_Sha3_512_Final(&sha3, hash), 0);
  14375. ExpectIntEQ(XMEMCMP(hash, hashRet, WC_SHA3_512_DIGEST_SIZE), 0);
  14376. /* Test bad args. */
  14377. ExpectIntEQ(wc_Sha3_512_GetHash(NULL, hashRet), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14378. ExpectIntEQ(wc_Sha3_512_GetHash(&sha3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14379. wc_Sha3_512_Free(&sha3);
  14380. #endif
  14381. return EXPECT_RESULT();
  14382. } /* END test_wc_Sha3_512_Final */
  14383. /*
  14384. * Testing wc_Sha3_224_Copy()
  14385. */
  14386. static int test_wc_Sha3_224_Copy(void)
  14387. {
  14388. EXPECT_DECLS;
  14389. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_224)
  14390. wc_Sha3 sha3, sha3Cpy;
  14391. const char* msg = TEST_STRING;
  14392. word32 msglen = (word32)TEST_STRING_SZ;
  14393. byte hash[WC_SHA3_224_DIGEST_SIZE];
  14394. byte hashCpy[WC_SHA3_224_DIGEST_SIZE];
  14395. XMEMSET(hash, 0, sizeof(hash));
  14396. XMEMSET(hashCpy, 0, sizeof(hashCpy));
  14397. XMEMSET(&sha3, 0, sizeof(wc_Sha3));
  14398. XMEMSET(&sha3Cpy, 0, sizeof(wc_Sha3));
  14399. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  14400. ExpectIntEQ(wc_InitSha3_224(&sha3Cpy, HEAP_HINT, testDevId), 0);
  14401. ExpectIntEQ(wc_Sha3_224_Update(&sha3, (byte*)msg, msglen), 0);
  14402. ExpectIntEQ(wc_Sha3_224_Copy(&sha3Cpy, &sha3), 0);
  14403. ExpectIntEQ(wc_Sha3_224_Final(&sha3, hash), 0);
  14404. ExpectIntEQ(wc_Sha3_224_Final(&sha3Cpy, hashCpy), 0);
  14405. ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0);
  14406. /* Test bad args. */
  14407. ExpectIntEQ(wc_Sha3_224_Copy(NULL, &sha3), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14408. ExpectIntEQ(wc_Sha3_224_Copy(&sha3Cpy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14409. wc_Sha3_224_Free(&sha3);
  14410. wc_Sha3_224_Free(&sha3Cpy);
  14411. #endif
  14412. return EXPECT_RESULT();
  14413. } /* END test_wc_Sha3_224_Copy */
  14414. /*
  14415. * Testing wc_Sha3_256_Copy()
  14416. */
  14417. static int test_wc_Sha3_256_Copy(void)
  14418. {
  14419. EXPECT_DECLS;
  14420. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  14421. wc_Sha3 sha3, sha3Cpy;
  14422. const char* msg = TEST_STRING;
  14423. word32 msglen = (word32)TEST_STRING_SZ;
  14424. byte hash[WC_SHA3_256_DIGEST_SIZE];
  14425. byte hashCpy[WC_SHA3_256_DIGEST_SIZE];
  14426. XMEMSET(hash, 0, sizeof(hash));
  14427. XMEMSET(hashCpy, 0, sizeof(hashCpy));
  14428. XMEMSET(&sha3, 0, sizeof(wc_Sha3));
  14429. XMEMSET(&sha3Cpy, 0, sizeof(wc_Sha3));
  14430. ExpectIntEQ(wc_InitSha3_256(&sha3, HEAP_HINT, testDevId), 0);
  14431. ExpectIntEQ(wc_InitSha3_256(&sha3Cpy, HEAP_HINT, testDevId), 0);
  14432. ExpectIntEQ(wc_Sha3_256_Update(&sha3, (byte*)msg, msglen), 0);
  14433. ExpectIntEQ(wc_Sha3_256_Copy(&sha3Cpy, &sha3), 0);
  14434. ExpectIntEQ(wc_Sha3_256_Final(&sha3, hash), 0);
  14435. ExpectIntEQ(wc_Sha3_256_Final(&sha3Cpy, hashCpy), 0);
  14436. ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0);
  14437. /* Test bad args. */
  14438. ExpectIntEQ(wc_Sha3_256_Copy(NULL, &sha3), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14439. ExpectIntEQ(wc_Sha3_256_Copy(&sha3Cpy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14440. wc_Sha3_256_Free(&sha3);
  14441. wc_Sha3_256_Free(&sha3Cpy);
  14442. #endif
  14443. return EXPECT_RESULT();
  14444. } /* END test_wc_Sha3_256_Copy */
  14445. /*
  14446. * Testing wc_Sha3_384_Copy()
  14447. */
  14448. static int test_wc_Sha3_384_Copy(void)
  14449. {
  14450. EXPECT_DECLS;
  14451. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_384)
  14452. wc_Sha3 sha3, sha3Cpy;
  14453. const char* msg = TEST_STRING;
  14454. word32 msglen = (word32)TEST_STRING_SZ;
  14455. byte hash[WC_SHA3_384_DIGEST_SIZE];
  14456. byte hashCpy[WC_SHA3_384_DIGEST_SIZE];
  14457. XMEMSET(hash, 0, sizeof(hash));
  14458. XMEMSET(hashCpy, 0, sizeof(hashCpy));
  14459. XMEMSET(&sha3, 0, sizeof(wc_Sha3));
  14460. XMEMSET(&sha3Cpy, 0, sizeof(wc_Sha3));
  14461. ExpectIntEQ(wc_InitSha3_384(&sha3, HEAP_HINT, testDevId), 0);
  14462. ExpectIntEQ(wc_InitSha3_384(&sha3Cpy, HEAP_HINT, testDevId), 0);
  14463. ExpectIntEQ(wc_Sha3_384_Update(&sha3, (byte*)msg, msglen), 0);
  14464. ExpectIntEQ(wc_Sha3_384_Copy(&sha3Cpy, &sha3), 0);
  14465. ExpectIntEQ(wc_Sha3_384_Final(&sha3, hash), 0);
  14466. ExpectIntEQ(wc_Sha3_384_Final(&sha3Cpy, hashCpy), 0);
  14467. ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0);
  14468. /* Test bad args. */
  14469. ExpectIntEQ(wc_Sha3_384_Copy(NULL, &sha3), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14470. ExpectIntEQ(wc_Sha3_384_Copy(&sha3Cpy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14471. wc_Sha3_384_Free(&sha3);
  14472. wc_Sha3_384_Free(&sha3Cpy);
  14473. #endif
  14474. return EXPECT_RESULT();
  14475. } /* END test_wc_Sha3_384_Copy */
  14476. /*
  14477. * Testing wc_Sha3_512_Copy()
  14478. */
  14479. static int test_wc_Sha3_512_Copy(void)
  14480. {
  14481. EXPECT_DECLS;
  14482. #if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_512)
  14483. wc_Sha3 sha3, sha3Cpy;
  14484. const char* msg = TEST_STRING;
  14485. word32 msglen = (word32)TEST_STRING_SZ;
  14486. byte hash[WC_SHA3_512_DIGEST_SIZE];
  14487. byte hashCpy[WC_SHA3_512_DIGEST_SIZE];
  14488. XMEMSET(hash, 0, sizeof(hash));
  14489. XMEMSET(hashCpy, 0, sizeof(hashCpy));
  14490. XMEMSET(&sha3, 0, sizeof(wc_Sha3));
  14491. XMEMSET(&sha3Cpy, 0, sizeof(wc_Sha3));
  14492. ExpectIntEQ(wc_InitSha3_512(&sha3, HEAP_HINT, testDevId), 0);
  14493. ExpectIntEQ(wc_InitSha3_512(&sha3Cpy, HEAP_HINT, testDevId), 0);
  14494. ExpectIntEQ(wc_Sha3_512_Update(&sha3, (byte*)msg, msglen), 0);
  14495. ExpectIntEQ(wc_Sha3_512_Copy(&sha3Cpy, &sha3), 0);
  14496. ExpectIntEQ(wc_Sha3_512_Final(&sha3, hash), 0);
  14497. ExpectIntEQ(wc_Sha3_512_Final(&sha3Cpy, hashCpy), 0);
  14498. ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0);
  14499. /* Test bad args. */
  14500. ExpectIntEQ(wc_Sha3_512_Copy(NULL, &sha3), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14501. ExpectIntEQ(wc_Sha3_512_Copy(&sha3Cpy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14502. wc_Sha3_512_Free(&sha3);
  14503. wc_Sha3_512_Free(&sha3Cpy);
  14504. #endif
  14505. return EXPECT_RESULT();
  14506. } /* END test_wc_Sha3_512_Copy */
  14507. /*
  14508. * Unit test function for wc_Sha3_GetFlags()
  14509. */
  14510. static int test_wc_Sha3_GetFlags(void)
  14511. {
  14512. EXPECT_DECLS;
  14513. #if defined(WOLFSSL_SHA3) && defined(WOLFSSL_HASH_FLAGS)
  14514. wc_Sha3 sha3;
  14515. word32 flags = 0;
  14516. /* Initialize */
  14517. ExpectIntEQ(wc_InitSha3_224(&sha3, HEAP_HINT, testDevId), 0);
  14518. ExpectIntEQ(wc_Sha3_GetFlags(&sha3, &flags), 0);
  14519. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  14520. wc_Sha3_224_Free(&sha3);
  14521. #endif
  14522. return EXPECT_RESULT();
  14523. } /* END test_wc_Sha3_GetFlags */
  14524. static int test_wc_InitShake256(void)
  14525. {
  14526. EXPECT_DECLS;
  14527. #ifdef WOLFSSL_SHAKE256
  14528. wc_Shake shake;
  14529. ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0);
  14530. /* Test bad args. */
  14531. ExpectIntEQ(wc_InitShake256(NULL, HEAP_HINT, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14532. wc_Shake256_Free(&shake);
  14533. #endif
  14534. return EXPECT_RESULT();
  14535. }
  14536. static int testing_wc_Shake256_Update(void)
  14537. {
  14538. EXPECT_DECLS;
  14539. #ifdef WOLFSSL_SHAKE256
  14540. wc_Shake shake;
  14541. byte msg[] = "Everybody's working for the weekend.";
  14542. byte msg2[] = "Everybody gets Friday off.";
  14543. byte msgCmp[] = "\x45\x76\x65\x72\x79\x62\x6f\x64\x79\x27\x73\x20"
  14544. "\x77\x6f\x72\x6b\x69\x6e\x67\x20\x66\x6f\x72\x20\x74"
  14545. "\x68\x65\x20\x77\x65\x65\x6b\x65\x6e\x64\x2e\x45\x76"
  14546. "\x65\x72\x79\x62\x6f\x64\x79\x20\x67\x65\x74\x73\x20"
  14547. "\x46\x72\x69\x64\x61\x79\x20\x6f\x66\x66\x2e";
  14548. word32 msglen = sizeof(msg) - 1;
  14549. word32 msg2len = sizeof(msg2);
  14550. word32 msgCmplen = sizeof(msgCmp);
  14551. ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0);
  14552. ExpectIntEQ(wc_Shake256_Update(&shake, msg, msglen), 0);
  14553. ExpectIntEQ(XMEMCMP(msg, shake.t, msglen), 0);
  14554. ExpectTrue(shake.i == msglen);
  14555. ExpectIntEQ(wc_Shake256_Update(&shake, msg2, msg2len), 0);
  14556. ExpectIntEQ(XMEMCMP(shake.t, msgCmp, msgCmplen), 0);
  14557. /* Pass bad args. */
  14558. ExpectIntEQ(wc_Shake256_Update(NULL, msg2, msg2len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14559. ExpectIntEQ(wc_Shake256_Update(&shake, NULL, 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14560. wc_Shake256_Free(&shake);
  14561. ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0);
  14562. ExpectIntEQ(wc_Shake256_Update(&shake, NULL, 0), 0);
  14563. ExpectIntEQ(wc_Shake256_Update(&shake, msg2, msg2len), 0);
  14564. ExpectIntEQ(XMEMCMP(msg2, shake.t, msg2len), 0);
  14565. wc_Shake256_Free(&shake);
  14566. #endif /* WOLFSSL_SHAKE256 */
  14567. return EXPECT_RESULT();
  14568. }
  14569. static int test_wc_Shake256_Final(void)
  14570. {
  14571. EXPECT_DECLS;
  14572. #ifdef WOLFSSL_SHAKE256
  14573. wc_Shake shake;
  14574. const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
  14575. "nopnopq";
  14576. const char* expOut = "\x4d\x8c\x2d\xd2\x43\x5a\x01\x28\xee\xfb\xb8\xc3\x6f"
  14577. "\x6f\x87\x13\x3a\x79\x11\xe1\x8d\x97\x9e\xe1\xae\x6b"
  14578. "\xe5\xd4\xfd\x2e\x33\x29\x40\xd8\x68\x8a\x4e\x6a\x59"
  14579. "\xaa\x80\x60\xf1\xf9\xbc\x99\x6c\x05\xac\xa3\xc6\x96"
  14580. "\xa8\xb6\x62\x79\xdc\x67\x2c\x74\x0b\xb2\x24\xec\x37"
  14581. "\xa9\x2b\x65\xdb\x05\x39\xc0\x20\x34\x55\xf5\x1d\x97"
  14582. "\xcc\xe4\xcf\xc4\x91\x27\xd7\x26\x0a\xfc\x67\x3a\xf2"
  14583. "\x08\xba\xf1\x9b\xe2\x12\x33\xf3\xde\xbe\x78\xd0\x67"
  14584. "\x60\xcf\xa5\x51\xee\x1e\x07\x91\x41\xd4";
  14585. byte hash[114];
  14586. /* Init stack variables. */
  14587. XMEMSET(hash, 0, sizeof(hash));
  14588. ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0);
  14589. ExpectIntEQ(wc_Shake256_Update(&shake, (byte*)msg, (word32)XSTRLEN(msg)),
  14590. 0);
  14591. ExpectIntEQ(wc_Shake256_Final(&shake, hash, (word32)sizeof(hash)), 0);
  14592. ExpectIntEQ(XMEMCMP(expOut, hash, (word32)sizeof(hash)), 0);
  14593. /* Test bad args. */
  14594. ExpectIntEQ(wc_Shake256_Final(NULL, hash, (word32)sizeof(hash)),
  14595. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14596. ExpectIntEQ(wc_Shake256_Final(&shake, NULL, (word32)sizeof(hash)),
  14597. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14598. wc_Shake256_Free(&shake);
  14599. #endif
  14600. return EXPECT_RESULT();
  14601. }
  14602. /*
  14603. * Testing wc_Shake256_Copy()
  14604. */
  14605. static int test_wc_Shake256_Copy(void)
  14606. {
  14607. EXPECT_DECLS;
  14608. #ifdef WOLFSSL_SHAKE256
  14609. wc_Shake shake, shakeCpy;
  14610. const char* msg = TEST_STRING;
  14611. word32 msglen = (word32)TEST_STRING_SZ;
  14612. byte hash[144];
  14613. byte hashCpy[144];
  14614. word32 hashLen = sizeof(hash);
  14615. word32 hashLenCpy = sizeof(hashCpy);
  14616. XMEMSET(hash, 0, sizeof(hash));
  14617. XMEMSET(hashCpy, 0, sizeof(hashCpy));
  14618. ExpectIntEQ(wc_InitShake256(&shake, HEAP_HINT, testDevId), 0);
  14619. ExpectIntEQ(wc_InitShake256(&shakeCpy, HEAP_HINT, testDevId), 0);
  14620. ExpectIntEQ(wc_Shake256_Update(&shake, (byte*)msg, msglen), 0);
  14621. ExpectIntEQ(wc_Shake256_Copy(&shakeCpy, &shake), 0);
  14622. ExpectIntEQ(wc_Shake256_Final(&shake, hash, hashLen), 0);
  14623. ExpectIntEQ(wc_Shake256_Final(&shakeCpy, hashCpy, hashLenCpy), 0);
  14624. ExpectIntEQ(XMEMCMP(hash, hashCpy, sizeof(hash)), 0);
  14625. /* Test bad args. */
  14626. ExpectIntEQ(wc_Shake256_Copy(NULL, &shake), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14627. ExpectIntEQ(wc_Shake256_Copy(&shakeCpy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14628. wc_Shake256_Free(&shake);
  14629. wc_Shake256_Free(&shakeCpy);
  14630. #endif
  14631. return EXPECT_RESULT();
  14632. } /* END test_wc_Shake256_Copy */
  14633. /*
  14634. * Unit test function for wc_Shake256Hash()
  14635. */
  14636. static int test_wc_Shake256Hash(void)
  14637. {
  14638. EXPECT_DECLS;
  14639. #ifdef WOLFSSL_SHAKE256
  14640. const byte data[] = { /* Hello World */
  14641. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  14642. 0x72,0x6c,0x64
  14643. };
  14644. word32 len = sizeof(data);
  14645. byte hash[144];
  14646. word32 hashLen = sizeof(hash);
  14647. ExpectIntEQ(wc_Shake256Hash(data, len, hash, hashLen), 0);
  14648. #endif
  14649. return EXPECT_RESULT();
  14650. } /* END test_wc_Shake256Hash */
  14651. /*
  14652. * Testing wc_InitSm3(), wc_Sm3Free()
  14653. */
  14654. static int test_wc_InitSm3Free(void)
  14655. {
  14656. EXPECT_DECLS;
  14657. #ifdef WOLFSSL_SM3
  14658. wc_Sm3 sm3;
  14659. /* Invalid Parameters */
  14660. ExpectIntEQ(wc_InitSm3(NULL, NULL, INVALID_DEVID), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14661. /* Valid Parameters */
  14662. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14663. wc_Sm3Free(NULL);
  14664. wc_Sm3Free(&sm3);
  14665. #endif
  14666. return EXPECT_RESULT();
  14667. } /* END test_wc_InitSm3 */
  14668. /*
  14669. * Testing wc_Sm3Update(), wc_Sm3Final()
  14670. */
  14671. static int test_wc_Sm3UpdateFinal(void)
  14672. {
  14673. EXPECT_DECLS;
  14674. #ifdef WOLFSSL_SM3
  14675. wc_Sm3 sm3;
  14676. byte data[WC_SM3_BLOCK_SIZE * 4];
  14677. byte hash[WC_SM3_DIGEST_SIZE];
  14678. byte calcHash[WC_SM3_DIGEST_SIZE];
  14679. byte expHash[WC_SM3_DIGEST_SIZE] = {
  14680. 0x38, 0x48, 0x15, 0xa7, 0x0e, 0xae, 0x0b, 0x27,
  14681. 0x5c, 0xde, 0x9d, 0xa5, 0xd1, 0xa4, 0x30, 0xa1,
  14682. 0xca, 0xd4, 0x54, 0x58, 0x44, 0xa2, 0x96, 0x1b,
  14683. 0xd7, 0x14, 0x80, 0x3f, 0x80, 0x1a, 0x07, 0xb6
  14684. };
  14685. word32 chunk;
  14686. word32 i;
  14687. XMEMSET(data, 0, sizeof(data));
  14688. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14689. /* Invalid Parameters */
  14690. ExpectIntEQ(wc_Sm3Update(NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14691. ExpectIntEQ(wc_Sm3Update(&sm3, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14692. ExpectIntEQ(wc_Sm3Update(NULL, data, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14693. /* Valid Parameters */
  14694. ExpectIntEQ(wc_Sm3Update(&sm3, NULL, 0), 0);
  14695. ExpectIntEQ(wc_Sm3Update(&sm3, data, 1), 0);
  14696. ExpectIntEQ(wc_Sm3Update(&sm3, data, 1), 0);
  14697. ExpectIntEQ(wc_Sm3Update(&sm3, data, WC_SM3_BLOCK_SIZE), 0);
  14698. ExpectIntEQ(wc_Sm3Update(&sm3, data, WC_SM3_BLOCK_SIZE - 2), 0);
  14699. ExpectIntEQ(wc_Sm3Update(&sm3, data, WC_SM3_BLOCK_SIZE * 2), 0);
  14700. /* Ensure too many bytes for lengths. */
  14701. ExpectIntEQ(wc_Sm3Update(&sm3, data, WC_SM3_PAD_SIZE), 0);
  14702. /* Invalid Parameters */
  14703. ExpectIntEQ(wc_Sm3Final(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14704. ExpectIntEQ(wc_Sm3Final(&sm3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14705. ExpectIntEQ(wc_Sm3Final(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14706. /* Valid Parameters */
  14707. ExpectIntEQ(wc_Sm3Final(&sm3, hash), 0);
  14708. ExpectBufEQ(hash, expHash, WC_SM3_DIGEST_SIZE);
  14709. /* Chunk tests. */
  14710. ExpectIntEQ(wc_Sm3Update(&sm3, data, sizeof(data)), 0);
  14711. ExpectIntEQ(wc_Sm3Final(&sm3, calcHash), 0);
  14712. for (chunk = 1; chunk <= WC_SM3_BLOCK_SIZE + 1; chunk++) {
  14713. for (i = 0; i + chunk <= (word32)sizeof(data); i += chunk) {
  14714. ExpectIntEQ(wc_Sm3Update(&sm3, data + i, chunk), 0);
  14715. }
  14716. if (i < (word32)sizeof(data)) {
  14717. ExpectIntEQ(wc_Sm3Update(&sm3, data + i, (word32)sizeof(data) - i),
  14718. 0);
  14719. }
  14720. ExpectIntEQ(wc_Sm3Final(&sm3, hash), 0);
  14721. ExpectBufEQ(hash, calcHash, WC_SM3_DIGEST_SIZE);
  14722. }
  14723. /* Not testing when the low 32-bit length overflows. */
  14724. wc_Sm3Free(&sm3);
  14725. #endif
  14726. return EXPECT_RESULT();
  14727. } /* END test_wc_Sm3Update */
  14728. /*
  14729. * Testing wc_Sm3GetHash()
  14730. */
  14731. static int test_wc_Sm3GetHash(void)
  14732. {
  14733. EXPECT_DECLS;
  14734. #ifdef WOLFSSL_SM3
  14735. wc_Sm3 sm3;
  14736. byte hash[WC_SM3_DIGEST_SIZE];
  14737. byte calcHash[WC_SM3_DIGEST_SIZE];
  14738. byte data[WC_SM3_BLOCK_SIZE];
  14739. XMEMSET(data, 0, sizeof(data));
  14740. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14741. ExpectIntEQ(wc_Sm3Final(&sm3, calcHash), 0);
  14742. /* Invalid Parameters */
  14743. ExpectIntEQ(wc_Sm3GetHash(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14744. ExpectIntEQ(wc_Sm3GetHash(&sm3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14745. ExpectIntEQ(wc_Sm3GetHash(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14746. /* Valid Parameters */
  14747. ExpectIntEQ(wc_Sm3GetHash(&sm3, hash), 0);
  14748. ExpectBufEQ(hash, calcHash, WC_SM3_DIGEST_SIZE);
  14749. /* With update. */
  14750. ExpectIntEQ(wc_Sm3Update(&sm3, data, sizeof(data)), 0);
  14751. ExpectIntEQ(wc_Sm3GetHash(&sm3, hash), 0);
  14752. ExpectIntEQ(wc_Sm3Final(&sm3, calcHash), 0);
  14753. ExpectBufEQ(hash, calcHash, WC_SM3_DIGEST_SIZE);
  14754. wc_Sm3Free(&sm3);
  14755. #endif
  14756. return EXPECT_RESULT();
  14757. } /* END test_wc_Sm3Update */
  14758. /*
  14759. * Testing wc_Sm3Copy()
  14760. */
  14761. static int test_wc_Sm3Copy(void)
  14762. {
  14763. EXPECT_DECLS;
  14764. #if defined(WOLFSSL_SM3) && defined(WOLFSSL_HASH_FLAGS)
  14765. wc_Sm3 sm3;
  14766. wc_Sm3 sm3Copy;
  14767. byte hash[WC_SM3_DIGEST_SIZE];
  14768. byte hashCopy[WC_SM3_DIGEST_SIZE];
  14769. byte data[WC_SM3_BLOCK_SIZE + 1];
  14770. int i;
  14771. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14772. ExpectIntEQ(wc_InitSm3(&sm3Copy, NULL, INVALID_DEVID), 0);
  14773. /* Invalid Parameters */
  14774. ExpectIntEQ(wc_Sm3Copy(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14775. ExpectIntEQ(wc_Sm3Copy(&sm3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14776. ExpectIntEQ(wc_Sm3Copy(NULL, &sm3Copy), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14777. /* Valid Parameters */
  14778. ExpectIntEQ(wc_Sm3Copy(&sm3, &sm3Copy), 0);
  14779. /* Ensure all parts of data updated during hashing are copied. */
  14780. for (i = 0; i < WC_SM3_BLOCK_SIZE + 1; i++) {
  14781. ExpectIntEQ(wc_Sm3Update(&sm3, data, i), 0);
  14782. ExpectIntEQ(wc_Sm3Copy(&sm3, &sm3Copy), 0);
  14783. ExpectIntEQ(wc_Sm3Update(&sm3, data, 1), 0);
  14784. ExpectIntEQ(wc_Sm3Update(&sm3Copy, data, 1), 0);
  14785. ExpectIntEQ(wc_Sm3Final(&sm3, hash), 0);
  14786. ExpectIntEQ(wc_Sm3Final(&sm3Copy, hashCopy), 0);
  14787. ExpectBufEQ(hash, hashCopy, WC_SM3_DIGEST_SIZE);
  14788. }
  14789. wc_Sm3Free(&sm3Copy);
  14790. wc_Sm3Free(&sm3);
  14791. #endif
  14792. return EXPECT_RESULT();
  14793. } /* END test_wc_Sm3Copy */
  14794. /*
  14795. * Testing wc_Sm3FinalRaw()
  14796. */
  14797. static int test_wc_Sm3FinalRaw(void)
  14798. {
  14799. EXPECT_DECLS;
  14800. #if defined(WOLFSSL_SM3) && !defined(HAVE_SELFTEST) && \
  14801. !defined(WOLFSSL_DEVCRYPTO) && (!defined(HAVE_FIPS) || \
  14802. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3))) && \
  14803. !defined(WOLFSSL_NO_HASH_RAW)
  14804. wc_Sm3 sm3;
  14805. byte hash1[WC_SM3_DIGEST_SIZE];
  14806. byte hash2[WC_SM3_DIGEST_SIZE];
  14807. byte hash3[WC_SM3_DIGEST_SIZE];
  14808. byte* hash_test[3] = { hash1, hash2, hash3 };
  14809. int times;
  14810. int i;
  14811. XMEMSET(&sm3, 0, sizeof(sm3));
  14812. /* Initialize */
  14813. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14814. /* Invalid Parameters */
  14815. ExpectIntEQ(wc_Sm3FinalRaw(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14816. ExpectIntEQ(wc_Sm3FinalRaw(&sm3, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14817. ExpectIntEQ(wc_Sm3FinalRaw(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14818. times = sizeof(hash_test) / sizeof(byte*);
  14819. for (i = 0; i < times; i++) {
  14820. ExpectIntEQ(wc_Sm3FinalRaw(&sm3, hash_test[i]), 0);
  14821. }
  14822. wc_Sm3Free(&sm3);
  14823. #endif
  14824. return EXPECT_RESULT();
  14825. } /* END test_wc_Sm3FinalRaw */
  14826. /*
  14827. * Testing wc_Sm3GetFlags, wc_Sm3SetFlags()
  14828. */
  14829. static int test_wc_Sm3GetSetFlags(void)
  14830. {
  14831. EXPECT_DECLS;
  14832. #if defined(WOLFSSL_SM3) && defined(WOLFSSL_HASH_FLAGS)
  14833. wc_Sm3 sm3;
  14834. wc_Sm3 sm3Copy;
  14835. word32 flags = 0;
  14836. ExpectIntEQ(wc_InitSm3(&sm3, NULL, INVALID_DEVID), 0);
  14837. ExpectIntEQ(wc_InitSm3(&sm3Copy, NULL, INVALID_DEVID), 0);
  14838. ExpectIntEQ(wc_Sm3GetFlags(NULL, &flags), 0);
  14839. ExpectIntEQ(flags, 0);
  14840. ExpectIntEQ(wc_Sm3SetFlags(NULL, WC_HASH_FLAG_WILLCOPY), 0);
  14841. ExpectIntEQ(wc_Sm3GetFlags(NULL, &flags), 0);
  14842. ExpectIntEQ(flags, 0);
  14843. ExpectIntEQ(wc_Sm3GetFlags(&sm3, &flags), 0);
  14844. ExpectIntEQ(flags, 0);
  14845. ExpectIntEQ(wc_Sm3SetFlags(&sm3, WC_HASH_FLAG_WILLCOPY), 0);
  14846. ExpectIntEQ(wc_Sm3GetFlags(&sm3, &flags), 0);
  14847. ExpectIntEQ(flags, WC_HASH_FLAG_WILLCOPY);
  14848. ExpectIntEQ(wc_Sm3Copy(&sm3, &sm3Copy), 0);
  14849. ExpectIntEQ(wc_Sm3GetFlags(&sm3Copy, &flags), 0);
  14850. ExpectIntEQ(flags, WC_HASH_FLAG_ISCOPY | WC_HASH_FLAG_WILLCOPY);
  14851. wc_Sm3Free(&sm3Copy);
  14852. wc_Sm3Free(&sm3);
  14853. #endif
  14854. return EXPECT_RESULT();
  14855. } /* END test_wc_Sm3Update */
  14856. /*
  14857. * Testing wc_Sm3Hash()
  14858. */
  14859. static int test_wc_Sm3Hash(void)
  14860. {
  14861. EXPECT_DECLS;
  14862. #if defined(WOLFSSL_SM3) && defined(WOLFSSL_HASH_FLAGS)
  14863. byte data[WC_SM3_BLOCK_SIZE];
  14864. byte hash[WC_SM3_DIGEST_SIZE];
  14865. /* Invalid parameters. */
  14866. ExpectIntEQ(wc_Sm3Hash(NULL, sizeof(data), hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14867. ExpectIntEQ(wc_Sm3Hash(data, sizeof(data), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14868. /* Valid parameters. */
  14869. ExpectIntEQ(wc_Sm3Hash(data, sizeof(data), hash), 0);
  14870. #endif
  14871. return EXPECT_RESULT();
  14872. } /* END test_wc_Sm3Hash */
  14873. /*
  14874. * Test function for wc_HmacSetKey
  14875. */
  14876. static int test_wc_Md5HmacSetKey(void)
  14877. {
  14878. EXPECT_DECLS;
  14879. #if !defined(NO_HMAC) && !defined(NO_MD5)
  14880. Hmac hmac;
  14881. int ret, times, itr;
  14882. const char* keys[]=
  14883. {
  14884. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
  14885. #ifndef HAVE_FIPS
  14886. "Jefe", /* smaller than minimum FIPS key size */
  14887. #endif
  14888. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\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. ret = wc_HmacSetKey(&hmac, WC_MD5, (byte*)keys[itr],
  14894. (word32)XSTRLEN(keys[itr]));
  14895. #if defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 5)
  14896. wc_HmacFree(&hmac);
  14897. ExpectIntEQ(ret, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14898. #else
  14899. ExpectIntEQ(ret, 0);
  14900. #endif
  14901. }
  14902. /* Bad args. */
  14903. ExpectIntEQ(wc_HmacSetKey(NULL, WC_MD5, (byte*)keys[0],
  14904. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14905. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_MD5, NULL, (word32)XSTRLEN(keys[0])),
  14906. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14907. ExpectIntEQ(wc_HmacSetKey(&hmac, 21, (byte*)keys[0],
  14908. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14909. ret = wc_HmacSetKey(&hmac, WC_MD5, (byte*)keys[0], 0);
  14910. #if defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 5)
  14911. ExpectIntEQ(ret, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14912. #elif defined(HAVE_FIPS)
  14913. ExpectIntEQ(ret, WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E));
  14914. #else
  14915. ExpectIntEQ(ret, 0);
  14916. #endif
  14917. wc_HmacFree(&hmac);
  14918. #endif
  14919. return EXPECT_RESULT();
  14920. } /* END test_wc_Md5HmacSetKey */
  14921. /*
  14922. * testing wc_HmacSetKey() on wc_Sha hash.
  14923. */
  14924. static int test_wc_ShaHmacSetKey(void)
  14925. {
  14926. EXPECT_DECLS;
  14927. #if !defined(NO_HMAC) && !defined(NO_SHA)
  14928. Hmac hmac;
  14929. int ret, times, itr;
  14930. const char* keys[]=
  14931. {
  14932. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  14933. "\x0b\x0b\x0b",
  14934. #ifndef HAVE_FIPS
  14935. "Jefe", /* smaller than minimum FIPS key size */
  14936. #endif
  14937. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  14938. "\xAA\xAA\xAA"
  14939. };
  14940. times = sizeof(keys) / sizeof(char*);
  14941. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14942. for (itr = 0; itr < times; itr++) {
  14943. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA, (byte*)keys[itr],
  14944. (word32)XSTRLEN(keys[itr])), 0);
  14945. }
  14946. /* Bad args. */
  14947. ExpectIntEQ(wc_HmacSetKey(NULL, WC_SHA, (byte*)keys[0],
  14948. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14949. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA, NULL, (word32)XSTRLEN(keys[0])),
  14950. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14951. ExpectIntEQ(wc_HmacSetKey(&hmac, 21, (byte*)keys[0],
  14952. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14953. ret = wc_HmacSetKey(&hmac, WC_SHA, (byte*)keys[0], 0);
  14954. #ifdef HAVE_FIPS
  14955. ExpectIntEQ(ret, WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E));
  14956. #else
  14957. ExpectIntEQ(ret, 0);
  14958. #endif
  14959. wc_HmacFree(&hmac);
  14960. #endif
  14961. return EXPECT_RESULT();
  14962. } /* END test_wc_ShaHmacSetKey() */
  14963. /*
  14964. * testing wc_HmacSetKey() on Sha224 hash.
  14965. */
  14966. static int test_wc_Sha224HmacSetKey(void)
  14967. {
  14968. EXPECT_DECLS;
  14969. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA224)
  14970. Hmac hmac;
  14971. int ret, times, itr;
  14972. const char* keys[]=
  14973. {
  14974. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  14975. "\x0b\x0b\x0b",
  14976. #ifndef HAVE_FIPS
  14977. "Jefe", /* smaller than minimum FIPS key size */
  14978. #endif
  14979. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  14980. "\xAA\xAA\xAA"
  14981. };
  14982. times = sizeof(keys) / sizeof(char*);
  14983. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  14984. for (itr = 0; itr < times; itr++) {
  14985. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA224, (byte*)keys[itr],
  14986. (word32)XSTRLEN(keys[itr])), 0);
  14987. }
  14988. /* Bad args. */
  14989. ExpectIntEQ(wc_HmacSetKey(NULL, WC_SHA224, (byte*)keys[0],
  14990. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14991. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA224, NULL, (word32)XSTRLEN(keys[0])),
  14992. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14993. ExpectIntEQ(wc_HmacSetKey(&hmac, 21, (byte*)keys[0],
  14994. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  14995. ret = wc_HmacSetKey(&hmac, WC_SHA224, (byte*)keys[0], 0);
  14996. #ifdef HAVE_FIPS
  14997. ExpectIntEQ(ret, WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E));
  14998. #else
  14999. ExpectIntEQ(ret, 0);
  15000. #endif
  15001. wc_HmacFree(&hmac);
  15002. #endif
  15003. return EXPECT_RESULT();
  15004. } /* END test_wc_Sha224HmacSetKey() */
  15005. /*
  15006. * testing wc_HmacSetKey() on Sha256 hash
  15007. */
  15008. static int test_wc_Sha256HmacSetKey(void)
  15009. {
  15010. EXPECT_DECLS;
  15011. #if !defined(NO_HMAC) && !defined(NO_SHA256)
  15012. Hmac hmac;
  15013. int ret, times, itr;
  15014. const char* keys[]=
  15015. {
  15016. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  15017. "\x0b\x0b\x0b",
  15018. #ifndef HAVE_FIPS
  15019. "Jefe", /* smaller than minimum FIPS key size */
  15020. #endif
  15021. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  15022. "\xAA\xAA\xAA"
  15023. };
  15024. times = sizeof(keys) / sizeof(char*);
  15025. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15026. for (itr = 0; itr < times; itr++) {
  15027. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA256, (byte*)keys[itr],
  15028. (word32)XSTRLEN(keys[itr])), 0);
  15029. }
  15030. /* Bad args. */
  15031. ExpectIntEQ(wc_HmacSetKey(NULL, WC_SHA256, (byte*)keys[0],
  15032. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15033. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA256, NULL, (word32)XSTRLEN(keys[0])),
  15034. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15035. ExpectIntEQ(wc_HmacSetKey(&hmac, 21, (byte*)keys[0],
  15036. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15037. ret = wc_HmacSetKey(&hmac, WC_SHA256, (byte*)keys[0], 0);
  15038. #ifdef HAVE_FIPS
  15039. ExpectIntEQ(ret, WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E));
  15040. #else
  15041. ExpectIntEQ(ret, 0);
  15042. #endif
  15043. wc_HmacFree(&hmac);
  15044. #endif
  15045. return EXPECT_RESULT();
  15046. } /* END test_wc_Sha256HmacSetKey() */
  15047. /*
  15048. * testing wc_HmacSetKey on Sha384 hash.
  15049. */
  15050. static int test_wc_Sha384HmacSetKey(void)
  15051. {
  15052. EXPECT_DECLS;
  15053. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  15054. Hmac hmac;
  15055. int ret, times, itr;
  15056. const char* keys[]=
  15057. {
  15058. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  15059. "\x0b\x0b\x0b",
  15060. #ifndef HAVE_FIPS
  15061. "Jefe", /* smaller than minimum FIPS key size */
  15062. #endif
  15063. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  15064. "\xAA\xAA\xAA"
  15065. };
  15066. times = sizeof(keys) / sizeof(char*);
  15067. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15068. for (itr = 0; itr < times; itr++) {
  15069. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA384, (byte*)keys[itr],
  15070. (word32)XSTRLEN(keys[itr])), 0);
  15071. }
  15072. /* Bad args. */
  15073. ExpectIntEQ(wc_HmacSetKey(NULL, WC_SHA384, (byte*)keys[0],
  15074. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15075. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA384, NULL, (word32)XSTRLEN(keys[0])),
  15076. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15077. ExpectIntEQ(wc_HmacSetKey(&hmac, 21, (byte*)keys[0],
  15078. (word32)XSTRLEN(keys[0])), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15079. ret = wc_HmacSetKey(&hmac, WC_SHA384, (byte*)keys[0], 0);
  15080. #ifdef HAVE_FIPS
  15081. ExpectIntEQ(ret, WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E));
  15082. #else
  15083. ExpectIntEQ(ret, 0);
  15084. #endif
  15085. wc_HmacFree(&hmac);
  15086. #endif
  15087. return EXPECT_RESULT();
  15088. } /* END test_wc_Sha384HmacSetKey() */
  15089. /*
  15090. * testing wc_HmacUpdate on wc_Md5 hash.
  15091. */
  15092. static int test_wc_Md5HmacUpdate(void)
  15093. {
  15094. EXPECT_DECLS;
  15095. #if !defined(NO_HMAC) && !defined(NO_MD5) && !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 5))
  15096. Hmac hmac;
  15097. testVector a, b;
  15098. #ifdef HAVE_FIPS
  15099. const char* keys =
  15100. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  15101. #else
  15102. const char* keys = "Jefe";
  15103. #endif
  15104. a.input = "what do ya want for nothing?";
  15105. a.inLen = XSTRLEN(a.input);
  15106. b.input = "Hi There";
  15107. b.inLen = XSTRLEN(b.input);
  15108. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15109. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_MD5, (byte*)keys,
  15110. (word32)XSTRLEN(keys)), 0);
  15111. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0);
  15112. /* Update Hmac. */
  15113. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15114. /* Test bad args. */
  15115. ExpectIntEQ(wc_HmacUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  15116. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15117. ExpectIntEQ(wc_HmacUpdate(&hmac, NULL, (word32)a.inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15118. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, 0), 0);
  15119. wc_HmacFree(&hmac);
  15120. #endif
  15121. return EXPECT_RESULT();
  15122. } /* END test_wc_Md5HmacUpdate */
  15123. /*
  15124. * testing wc_HmacUpdate on SHA hash.
  15125. */
  15126. static int test_wc_ShaHmacUpdate(void)
  15127. {
  15128. EXPECT_DECLS;
  15129. #if !defined(NO_HMAC) && !defined(NO_SHA)
  15130. Hmac hmac;
  15131. testVector a, b;
  15132. #ifdef HAVE_FIPS
  15133. const char* keys =
  15134. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  15135. #else
  15136. const char* keys = "Jefe";
  15137. #endif
  15138. a.input = "what do ya want for nothing?";
  15139. a.inLen = XSTRLEN(a.input);
  15140. b.input = "Hi There";
  15141. b.inLen = XSTRLEN(b.input);
  15142. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15143. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA, (byte*)keys,
  15144. (word32)XSTRLEN(keys)), 0);
  15145. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0);
  15146. /* Update Hmac. */
  15147. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15148. /* Test bad args. */
  15149. ExpectIntEQ(wc_HmacUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  15150. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15151. ExpectIntEQ(wc_HmacUpdate(&hmac, NULL, (word32)a.inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15152. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, 0), 0);
  15153. wc_HmacFree(&hmac);
  15154. #endif
  15155. return EXPECT_RESULT();
  15156. } /* END test_wc_ShaHmacUpdate */
  15157. /*
  15158. * testing wc_HmacUpdate on SHA224 hash.
  15159. */
  15160. static int test_wc_Sha224HmacUpdate(void)
  15161. {
  15162. EXPECT_DECLS;
  15163. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA224)
  15164. Hmac hmac;
  15165. testVector a, b;
  15166. #ifdef HAVE_FIPS
  15167. const char* keys =
  15168. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  15169. #else
  15170. const char* keys = "Jefe";
  15171. #endif
  15172. a.input = "what do ya want for nothing?";
  15173. a.inLen = XSTRLEN(a.input);
  15174. b.input = "Hi There";
  15175. b.inLen = XSTRLEN(b.input);
  15176. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15177. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA224, (byte*)keys,
  15178. (word32)XSTRLEN(keys)), 0);
  15179. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0);
  15180. /* Update Hmac. */
  15181. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15182. /* Test bad args. */
  15183. ExpectIntEQ(wc_HmacUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  15184. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15185. ExpectIntEQ(wc_HmacUpdate(&hmac, NULL, (word32)a.inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15186. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, 0), 0);
  15187. wc_HmacFree(&hmac);
  15188. #endif
  15189. return EXPECT_RESULT();
  15190. } /* END test_wc_Sha224HmacUpdate */
  15191. /*
  15192. * testing wc_HmacUpdate on SHA256 hash.
  15193. */
  15194. static int test_wc_Sha256HmacUpdate(void)
  15195. {
  15196. EXPECT_DECLS;
  15197. #if !defined(NO_HMAC) && !defined(NO_SHA256)
  15198. Hmac hmac;
  15199. testVector a, b;
  15200. #ifdef HAVE_FIPS
  15201. const char* keys =
  15202. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  15203. #else
  15204. const char* keys = "Jefe";
  15205. #endif
  15206. a.input = "what do ya want for nothing?";
  15207. a.inLen = XSTRLEN(a.input);
  15208. b.input = "Hi There";
  15209. b.inLen = XSTRLEN(b.input);
  15210. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15211. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA256, (byte*)keys,
  15212. (word32)XSTRLEN(keys)), 0);
  15213. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0);
  15214. /* Update Hmac. */
  15215. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15216. /* Test bad args. */
  15217. ExpectIntEQ(wc_HmacUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  15218. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15219. ExpectIntEQ(wc_HmacUpdate(&hmac, NULL, (word32)a.inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15220. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, 0), 0);
  15221. wc_HmacFree(&hmac);
  15222. #endif
  15223. return EXPECT_RESULT();
  15224. } /* END test_wc_Sha256HmacUpdate */
  15225. /*
  15226. * testing wc_HmacUpdate on SHA384 hash.
  15227. */
  15228. static int test_wc_Sha384HmacUpdate(void)
  15229. {
  15230. EXPECT_DECLS;
  15231. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  15232. Hmac hmac;
  15233. testVector a, b;
  15234. #ifdef HAVE_FIPS
  15235. const char* keys =
  15236. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  15237. #else
  15238. const char* keys = "Jefe";
  15239. #endif
  15240. a.input = "what do ya want for nothing?";
  15241. a.inLen = XSTRLEN(a.input);
  15242. b.input = "Hi There";
  15243. b.inLen = XSTRLEN(b.input);
  15244. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15245. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA384, (byte*)keys,
  15246. (word32)XSTRLEN(keys)), 0);
  15247. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)b.input, (word32)b.inLen), 0);
  15248. /* Update Hmac. */
  15249. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15250. /* Test bad args. */
  15251. ExpectIntEQ(wc_HmacUpdate(NULL, (byte*)a.input, (word32)a.inLen),
  15252. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15253. ExpectIntEQ(wc_HmacUpdate(&hmac, NULL, (word32)a.inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15254. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, 0), 0);
  15255. wc_HmacFree(&hmac);
  15256. #endif
  15257. return EXPECT_RESULT();
  15258. } /* END test_wc_Sha384HmacUpdate */
  15259. /*
  15260. * Testing wc_HmacFinal() with MD5
  15261. */
  15262. static int test_wc_Md5HmacFinal(void)
  15263. {
  15264. EXPECT_DECLS;
  15265. #if !defined(NO_HMAC) && !defined(NO_MD5) && !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 5))
  15266. Hmac hmac;
  15267. byte hash[WC_MD5_DIGEST_SIZE];
  15268. testVector a;
  15269. const char* key;
  15270. key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  15271. a.input = "Hi There";
  15272. a.output = "\x92\x94\x72\x7a\x36\x38\xbb\x1c\x13\xf4\x8e\xf8\x15\x8b\xfc"
  15273. "\x9d";
  15274. a.inLen = XSTRLEN(a.input);
  15275. a.outLen = XSTRLEN(a.output);
  15276. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15277. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_MD5, (byte*)key, (word32)XSTRLEN(key)),
  15278. 0);
  15279. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15280. ExpectIntEQ(wc_HmacFinal(&hmac, hash), 0);
  15281. ExpectIntEQ(XMEMCMP(hash, a.output, WC_MD5_DIGEST_SIZE), 0);
  15282. /* Try bad parameters. */
  15283. ExpectIntEQ(wc_HmacFinal(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15284. #ifndef HAVE_FIPS
  15285. ExpectIntEQ(wc_HmacFinal(&hmac, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15286. #endif
  15287. wc_HmacFree(&hmac);
  15288. #endif
  15289. return EXPECT_RESULT();
  15290. } /* END test_wc_Md5HmacFinal */
  15291. /*
  15292. * Testing wc_HmacFinal() with SHA
  15293. */
  15294. static int test_wc_ShaHmacFinal(void)
  15295. {
  15296. EXPECT_DECLS;
  15297. #if !defined(NO_HMAC) && !defined(NO_SHA)
  15298. Hmac hmac;
  15299. byte hash[WC_SHA_DIGEST_SIZE];
  15300. testVector a;
  15301. const char* key;
  15302. key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  15303. "\x0b\x0b\x0b";
  15304. a.input = "Hi There";
  15305. a.output = "\xb6\x17\x31\x86\x55\x05\x72\x64\xe2\x8b\xc0\xb6\xfb\x37\x8c"
  15306. "\x8e\xf1\x46\xbe\x00";
  15307. a.inLen = XSTRLEN(a.input);
  15308. a.outLen = XSTRLEN(a.output);
  15309. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15310. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA, (byte*)key, (word32)XSTRLEN(key)),
  15311. 0);
  15312. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15313. ExpectIntEQ(wc_HmacFinal(&hmac, hash), 0);
  15314. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA_DIGEST_SIZE), 0);
  15315. /* Try bad parameters. */
  15316. ExpectIntEQ(wc_HmacFinal(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15317. #ifndef HAVE_FIPS
  15318. ExpectIntEQ(wc_HmacFinal(&hmac, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15319. #endif
  15320. wc_HmacFree(&hmac);
  15321. #endif
  15322. return EXPECT_RESULT();
  15323. } /* END test_wc_ShaHmacFinal */
  15324. /*
  15325. * Testing wc_HmacFinal() with SHA224
  15326. */
  15327. static int test_wc_Sha224HmacFinal(void)
  15328. {
  15329. EXPECT_DECLS;
  15330. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA224)
  15331. Hmac hmac;
  15332. byte hash[WC_SHA224_DIGEST_SIZE];
  15333. testVector a;
  15334. const char* key;
  15335. key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  15336. "\x0b\x0b\x0b";
  15337. a.input = "Hi There";
  15338. a.output = "\x89\x6f\xb1\x12\x8a\xbb\xdf\x19\x68\x32\x10\x7c\xd4\x9d\xf3"
  15339. "\x3f\x47\xb4\xb1\x16\x99\x12\xba\x4f\x53\x68\x4b\x22";
  15340. a.inLen = XSTRLEN(a.input);
  15341. a.outLen = XSTRLEN(a.output);
  15342. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15343. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA224, (byte*)key,
  15344. (word32)XSTRLEN(key)), 0);
  15345. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15346. ExpectIntEQ(wc_HmacFinal(&hmac, hash), 0);
  15347. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA224_DIGEST_SIZE), 0);
  15348. /* Try bad parameters. */
  15349. ExpectIntEQ(wc_HmacFinal(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15350. #ifndef HAVE_FIPS
  15351. ExpectIntEQ(wc_HmacFinal(&hmac, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15352. #endif
  15353. wc_HmacFree(&hmac);
  15354. #endif
  15355. return EXPECT_RESULT();
  15356. } /* END test_wc_Sha224HmacFinal */
  15357. /*
  15358. * Testing wc_HmacFinal() with SHA256
  15359. */
  15360. static int test_wc_Sha256HmacFinal(void)
  15361. {
  15362. EXPECT_DECLS;
  15363. #if !defined(NO_HMAC) && !defined(NO_SHA256)
  15364. Hmac hmac;
  15365. byte hash[WC_SHA256_DIGEST_SIZE];
  15366. testVector a;
  15367. const char* key;
  15368. key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  15369. "\x0b\x0b\x0b";
  15370. a.input = "Hi There";
  15371. a.output = "\xb0\x34\x4c\x61\xd8\xdb\x38\x53\x5c\xa8\xaf\xce\xaf\x0b\xf1"
  15372. "\x2b\x88\x1d\xc2\x00\xc9\x83\x3d\xa7\x26\xe9\x37\x6c\x2e\x32"
  15373. "\xcf\xf7";
  15374. a.inLen = XSTRLEN(a.input);
  15375. a.outLen = XSTRLEN(a.output);
  15376. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15377. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA256, (byte*)key,
  15378. (word32)XSTRLEN(key)), 0);
  15379. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15380. ExpectIntEQ(wc_HmacFinal(&hmac, hash), 0);
  15381. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA256_DIGEST_SIZE), 0);
  15382. /* Try bad parameters. */
  15383. ExpectIntEQ(wc_HmacFinal(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15384. #ifndef HAVE_FIPS
  15385. ExpectIntEQ(wc_HmacFinal(&hmac, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15386. #endif
  15387. wc_HmacFree(&hmac);
  15388. #endif
  15389. return EXPECT_RESULT();
  15390. } /* END test_wc_Sha256HmacFinal */
  15391. /*
  15392. * Testing wc_HmacFinal() with SHA384
  15393. */
  15394. static int test_wc_Sha384HmacFinal(void)
  15395. {
  15396. EXPECT_DECLS;
  15397. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  15398. Hmac hmac;
  15399. byte hash[WC_SHA384_DIGEST_SIZE];
  15400. testVector a;
  15401. const char* key;
  15402. key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  15403. "\x0b\x0b\x0b";
  15404. a.input = "Hi There";
  15405. a.output = "\xaf\xd0\x39\x44\xd8\x48\x95\x62\x6b\x08\x25\xf4\xab\x46\x90"
  15406. "\x7f\x15\xf9\xda\xdb\xe4\x10\x1e\xc6\x82\xaa\x03\x4c\x7c\xeb"
  15407. "\xc5\x9c\xfa\xea\x9e\xa9\x07\x6e\xde\x7f\x4a\xf1\x52\xe8\xb2"
  15408. "\xfa\x9c\xb6";
  15409. a.inLen = XSTRLEN(a.input);
  15410. a.outLen = XSTRLEN(a.output);
  15411. ExpectIntEQ(wc_HmacInit(&hmac, NULL, INVALID_DEVID), 0);
  15412. ExpectIntEQ(wc_HmacSetKey(&hmac, WC_SHA384, (byte*)key,
  15413. (word32)XSTRLEN(key)), 0);
  15414. ExpectIntEQ(wc_HmacUpdate(&hmac, (byte*)a.input, (word32)a.inLen), 0);
  15415. ExpectIntEQ(wc_HmacFinal(&hmac, hash), 0);
  15416. ExpectIntEQ(XMEMCMP(hash, a.output, WC_SHA384_DIGEST_SIZE), 0);
  15417. /* Try bad parameters. */
  15418. ExpectIntEQ(wc_HmacFinal(NULL, hash), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15419. #ifndef HAVE_FIPS
  15420. ExpectIntEQ(wc_HmacFinal(&hmac, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15421. #endif
  15422. wc_HmacFree(&hmac);
  15423. #endif
  15424. return EXPECT_RESULT();
  15425. } /* END test_wc_Sha384HmacFinal */
  15426. /*
  15427. * Testing wc_InitCmac()
  15428. */
  15429. static int test_wc_InitCmac(void)
  15430. {
  15431. EXPECT_DECLS;
  15432. #if defined(WOLFSSL_CMAC) && !defined(NO_AES)
  15433. Cmac cmac1;
  15434. Cmac cmac2;
  15435. Cmac cmac3;
  15436. /* AES 128 key. */
  15437. byte key1[] = "\x01\x02\x03\x04\x05\x06\x07\x08"
  15438. "\x09\x10\x11\x12\x13\x14\x15\x16";
  15439. /* AES 192 key. */
  15440. byte key2[] = "\x01\x02\x03\x04\x05\x06\x07\x08"
  15441. "\x09\x01\x11\x12\x13\x14\x15\x16"
  15442. "\x01\x02\x03\x04\x05\x06\x07\x08";
  15443. /* AES 256 key. */
  15444. byte key3[] = "\x01\x02\x03\x04\x05\x06\x07\x08"
  15445. "\x09\x01\x11\x12\x13\x14\x15\x16"
  15446. "\x01\x02\x03\x04\x05\x06\x07\x08"
  15447. "\x09\x01\x11\x12\x13\x14\x15\x16";
  15448. word32 key1Sz = (word32)sizeof(key1) - 1;
  15449. word32 key2Sz = (word32)sizeof(key2) - 1;
  15450. word32 key3Sz = (word32)sizeof(key3) - 1;
  15451. int type = WC_CMAC_AES;
  15452. (void)key1;
  15453. (void)key1Sz;
  15454. (void)key2;
  15455. (void)key2Sz;
  15456. XMEMSET(&cmac1, 0, sizeof(Cmac));
  15457. XMEMSET(&cmac2, 0, sizeof(Cmac));
  15458. XMEMSET(&cmac3, 0, sizeof(Cmac));
  15459. #ifdef WOLFSSL_AES_128
  15460. ExpectIntEQ(wc_InitCmac(&cmac1, key1, key1Sz, type, NULL), 0);
  15461. #endif
  15462. #ifdef WOLFSSL_AES_192
  15463. wc_AesFree(&cmac1.aes);
  15464. ExpectIntEQ(wc_InitCmac(&cmac2, key2, key2Sz, type, NULL), 0);
  15465. #endif
  15466. #ifdef WOLFSSL_AES_256
  15467. wc_AesFree(&cmac2.aes);
  15468. ExpectIntEQ(wc_InitCmac(&cmac3, key3, key3Sz, type, NULL), 0);
  15469. #endif
  15470. wc_AesFree(&cmac3.aes);
  15471. /* Test bad args. */
  15472. ExpectIntEQ(wc_InitCmac(NULL, key3, key3Sz, type, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15473. ExpectIntEQ(wc_InitCmac(&cmac3, NULL, key3Sz, type, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15474. ExpectIntEQ(wc_InitCmac(&cmac3, key3, 0, type, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15475. ExpectIntEQ(wc_InitCmac(&cmac3, key3, key3Sz, 0, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15476. #endif
  15477. return EXPECT_RESULT();
  15478. } /* END test_wc_InitCmac */
  15479. /*
  15480. * Testing wc_CmacUpdate()
  15481. */
  15482. static int test_wc_CmacUpdate(void)
  15483. {
  15484. EXPECT_DECLS;
  15485. #if defined(WOLFSSL_CMAC) && !defined(NO_AES) && defined(WOLFSSL_AES_128)
  15486. Cmac cmac;
  15487. byte key[] = {
  15488. 0x64, 0x4c, 0xbf, 0x12, 0x85, 0x9d, 0xf0, 0x55,
  15489. 0x7e, 0xa9, 0x1f, 0x08, 0xe0, 0x51, 0xff, 0x27
  15490. };
  15491. byte in[] = "\xe2\xb4\xb6\xf9\x48\x44\x02\x64"
  15492. "\x5c\x47\x80\x9e\xd5\xa8\x3a\x17"
  15493. "\xb3\x78\xcf\x85\x22\x41\x74\xd9"
  15494. "\xa0\x97\x39\x71\x62\xf1\x8e\x8f"
  15495. "\xf4";
  15496. word32 inSz = (word32)sizeof(in) - 1;
  15497. word32 keySz = (word32)sizeof(key);
  15498. int type = WC_CMAC_AES;
  15499. XMEMSET(&cmac, 0, sizeof(Cmac));
  15500. ExpectIntEQ(wc_InitCmac(&cmac, key, keySz, type, NULL), 0);
  15501. ExpectIntEQ(wc_CmacUpdate(&cmac, in, inSz), 0);
  15502. /* Test bad args. */
  15503. ExpectIntEQ(wc_CmacUpdate(NULL, in, inSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15504. ExpectIntEQ(wc_CmacUpdate(&cmac, NULL, 30), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15505. wc_AesFree(&cmac.aes);
  15506. #endif
  15507. return EXPECT_RESULT();
  15508. } /* END test_wc_CmacUpdate */
  15509. /*
  15510. * Testing wc_CmacFinal()
  15511. */
  15512. static int test_wc_CmacFinal(void)
  15513. {
  15514. EXPECT_DECLS;
  15515. #if defined(WOLFSSL_CMAC) && !defined(NO_AES) && defined(WOLFSSL_AES_128)
  15516. Cmac cmac;
  15517. byte key[] = {
  15518. 0x64, 0x4c, 0xbf, 0x12, 0x85, 0x9d, 0xf0, 0x55,
  15519. 0x7e, 0xa9, 0x1f, 0x08, 0xe0, 0x51, 0xff, 0x27
  15520. };
  15521. byte msg[] = {
  15522. 0xe2, 0xb4, 0xb6, 0xf9, 0x48, 0x44, 0x02, 0x64,
  15523. 0x5c, 0x47, 0x80, 0x9e, 0xd5, 0xa8, 0x3a, 0x17,
  15524. 0xb3, 0x78, 0xcf, 0x85, 0x22, 0x41, 0x74, 0xd9,
  15525. 0xa0, 0x97, 0x39, 0x71, 0x62, 0xf1, 0x8e, 0x8f,
  15526. 0xf4
  15527. };
  15528. /* Test vectors from CMACGenAES128.rsp from
  15529. * http://csrc.nist.gov/groups/STM/cavp/block-cipher-modes.html#cmac
  15530. * Per RFC4493 truncation of lsb is possible.
  15531. */
  15532. byte expMac[] = {
  15533. 0x4e, 0x6e, 0xc5, 0x6f, 0xf9, 0x5d, 0x0e, 0xae,
  15534. 0x1c, 0xf8, 0x3e, 0xfc, 0xf4, 0x4b, 0xeb
  15535. };
  15536. byte mac[AES_BLOCK_SIZE];
  15537. word32 msgSz = (word32)sizeof(msg);
  15538. word32 keySz = (word32)sizeof(key);
  15539. word32 macSz = sizeof(mac);
  15540. word32 badMacSz = 17;
  15541. int expMacSz = sizeof(expMac);
  15542. int type = WC_CMAC_AES;
  15543. XMEMSET(&cmac, 0, sizeof(Cmac));
  15544. XMEMSET(mac, 0, macSz);
  15545. ExpectIntEQ(wc_InitCmac(&cmac, key, keySz, type, NULL), 0);
  15546. ExpectIntEQ(wc_CmacUpdate(&cmac, msg, msgSz), 0);
  15547. #if (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  15548. /* Pass in bad args. */
  15549. ExpectIntEQ(wc_CmacFinalNoFree(NULL, mac, &macSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15550. ExpectIntEQ(wc_CmacFinalNoFree(&cmac, NULL, &macSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15551. ExpectIntEQ(wc_CmacFinalNoFree(&cmac, mac, &badMacSz), WC_NO_ERR_TRACE(BUFFER_E));
  15552. /* For the last call, use the API with implicit wc_CmacFree(). */
  15553. ExpectIntEQ(wc_CmacFinal(&cmac, mac, &macSz), 0);
  15554. ExpectIntEQ(XMEMCMP(mac, expMac, expMacSz), 0);
  15555. #else /* !HAVE_FIPS || FIPS>=5.3 */
  15556. ExpectIntEQ(wc_CmacFinal(&cmac, mac, &macSz), 0);
  15557. ExpectIntEQ(XMEMCMP(mac, expMac, expMacSz), 0);
  15558. /* Pass in bad args. */
  15559. ExpectIntEQ(wc_CmacFinal(NULL, mac, &macSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15560. ExpectIntEQ(wc_CmacFinal(&cmac, NULL, &macSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15561. ExpectIntEQ(wc_CmacFinal(&cmac, mac, &badMacSz), WC_NO_ERR_TRACE(BUFFER_E));
  15562. #endif /* !HAVE_FIPS || FIPS>=5.3 */
  15563. #endif
  15564. return EXPECT_RESULT();
  15565. } /* END test_wc_CmacFinal */
  15566. /*
  15567. * Testing wc_AesCmacGenerate() && wc_AesCmacVerify()
  15568. */
  15569. static int test_wc_AesCmacGenerate(void)
  15570. {
  15571. EXPECT_DECLS;
  15572. #if defined(WOLFSSL_CMAC) && !defined(NO_AES) && defined(WOLFSSL_AES_128)
  15573. byte key[] = {
  15574. 0x26, 0xef, 0x8b, 0x40, 0x34, 0x11, 0x7d, 0x9e,
  15575. 0xbe, 0xc0, 0xc7, 0xfc, 0x31, 0x08, 0x54, 0x69
  15576. };
  15577. byte msg[] = "\x18\x90\x49\xef\xfd\x7c\xf9\xc8"
  15578. "\xf3\x59\x65\xbc\xb0\x97\x8f\xd4";
  15579. byte expMac[] = "\x29\x5f\x2f\x71\xfc\x58\xe6\xf6"
  15580. "\x3d\x32\x65\x4c\x66\x23\xc5";
  15581. byte mac[AES_BLOCK_SIZE];
  15582. word32 keySz = sizeof(key);
  15583. word32 macSz = sizeof(mac);
  15584. word32 msgSz = sizeof(msg) - 1;
  15585. word32 expMacSz = sizeof(expMac) - 1;
  15586. XMEMSET(mac, 0, macSz);
  15587. ExpectIntEQ(wc_AesCmacGenerate(mac, &macSz, msg, msgSz, key, keySz), 0);
  15588. ExpectIntEQ(XMEMCMP(mac, expMac, expMacSz), 0);
  15589. /* Pass in bad args. */
  15590. ExpectIntEQ(wc_AesCmacGenerate(NULL, &macSz, msg, msgSz, key, keySz),
  15591. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15592. ExpectIntEQ(wc_AesCmacGenerate(mac, &macSz, msg, msgSz, NULL, keySz),
  15593. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15594. ExpectIntEQ(wc_AesCmacGenerate(mac, &macSz, msg, msgSz, key, 0),
  15595. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15596. ExpectIntEQ(wc_AesCmacGenerate(mac, &macSz, NULL, msgSz, key, keySz),
  15597. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15598. ExpectIntEQ(wc_AesCmacVerify(mac, macSz, msg, msgSz, key, keySz), 0);
  15599. /* Test bad args. */
  15600. ExpectIntEQ(wc_AesCmacVerify(NULL, macSz, msg, msgSz, key, keySz),
  15601. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15602. ExpectIntEQ(wc_AesCmacVerify(mac, 0, msg, msgSz, key, keySz),
  15603. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15604. ExpectIntEQ(wc_AesCmacVerify(mac, macSz, msg, msgSz, NULL, keySz),
  15605. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15606. ExpectIntEQ(wc_AesCmacVerify(mac, macSz, msg, msgSz, key, 0),
  15607. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15608. ExpectIntEQ(wc_AesCmacVerify(mac, macSz, NULL, msgSz, key, keySz),
  15609. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15610. #endif
  15611. return EXPECT_RESULT();
  15612. } /* END test_wc_AesCmacGenerate */
  15613. /*
  15614. * Testing streaming AES-GCM API.
  15615. */
  15616. static int test_wc_AesGcmStream(void)
  15617. {
  15618. EXPECT_DECLS;
  15619. #if !defined(NO_AES) && defined(WOLFSSL_AES_128) && defined(HAVE_AESGCM) && \
  15620. defined(WOLFSSL_AESGCM_STREAM)
  15621. int i;
  15622. WC_RNG rng[1];
  15623. Aes aesEnc[1];
  15624. Aes aesDec[1];
  15625. byte tag[AES_BLOCK_SIZE];
  15626. byte in[AES_BLOCK_SIZE * 3 + 2] = { 0, };
  15627. byte out[AES_BLOCK_SIZE * 3 + 2];
  15628. byte plain[AES_BLOCK_SIZE * 3 + 2];
  15629. byte aad[AES_BLOCK_SIZE * 3 + 2] = { 0, };
  15630. byte key[AES_128_KEY_SIZE] = { 0, };
  15631. byte iv[AES_IV_SIZE] = { 1, };
  15632. byte ivOut[AES_IV_SIZE];
  15633. static const byte expTagAAD1[AES_BLOCK_SIZE] = {
  15634. 0x6c, 0x35, 0xe6, 0x7f, 0x59, 0x9e, 0xa9, 0x2f,
  15635. 0x27, 0x2d, 0x5f, 0x8e, 0x7e, 0x42, 0xd3, 0x05
  15636. };
  15637. static const byte expTagPlain1[AES_BLOCK_SIZE] = {
  15638. 0x24, 0xba, 0x57, 0x95, 0xd0, 0x27, 0x9e, 0x78,
  15639. 0x3a, 0x88, 0x4c, 0x0a, 0x5d, 0x50, 0x23, 0xd1
  15640. };
  15641. static const byte expTag[AES_BLOCK_SIZE] = {
  15642. 0x22, 0x91, 0x70, 0xad, 0x42, 0xc3, 0xad, 0x96,
  15643. 0xe0, 0x31, 0x57, 0x60, 0xb7, 0x92, 0xa3, 0x6d
  15644. };
  15645. XMEMSET(&rng, 0, sizeof(WC_RNG));
  15646. XMEMSET(&aesEnc, 0, sizeof(Aes));
  15647. XMEMSET(&aesDec, 0, sizeof(Aes));
  15648. /* Create a random for generating IV/nonce. */
  15649. ExpectIntEQ(wc_InitRng(rng), 0);
  15650. /* Initialize data structures. */
  15651. ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
  15652. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15653. /* BadParameters to streaming init. */
  15654. ExpectIntEQ(wc_AesGcmEncryptInit(NULL, NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15655. ExpectIntEQ(wc_AesGcmDecryptInit(NULL, NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15656. ExpectIntEQ(wc_AesGcmDecryptInit(aesEnc, NULL, AES_128_KEY_SIZE, NULL, 0),
  15657. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15658. ExpectIntEQ(wc_AesGcmDecryptInit(aesEnc, NULL, 0, NULL, GCM_NONCE_MID_SZ),
  15659. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15660. /* Bad parameters to encrypt update. */
  15661. ExpectIntEQ(wc_AesGcmEncryptUpdate(NULL, NULL, NULL, 0, NULL, 0),
  15662. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15663. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 1, NULL, 0),
  15664. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15665. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, in, 1, NULL, 0),
  15666. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15667. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, out, NULL, 1, NULL, 0),
  15668. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15669. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 0, NULL, 1),
  15670. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15671. /* Bad parameters to decrypt update. */
  15672. ExpectIntEQ(wc_AesGcmDecryptUpdate(NULL, NULL, NULL, 0, NULL, 0),
  15673. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15674. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 1, NULL, 0),
  15675. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15676. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, in, 1, NULL, 0),
  15677. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15678. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, out, NULL, 1, NULL, 0),
  15679. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15680. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 0, NULL, 1),
  15681. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15682. /* Bad parameters to encrypt final. */
  15683. ExpectIntEQ(wc_AesGcmEncryptFinal(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15684. ExpectIntEQ(wc_AesGcmEncryptFinal(NULL, tag, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15685. ExpectIntEQ(wc_AesGcmEncryptFinal(NULL, NULL, AES_BLOCK_SIZE),
  15686. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15687. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15688. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, NULL, AES_BLOCK_SIZE),
  15689. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15690. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE + 1),
  15691. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15692. /* Bad parameters to decrypt final. */
  15693. ExpectIntEQ(wc_AesGcmDecryptFinal(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15694. ExpectIntEQ(wc_AesGcmDecryptFinal(NULL, tag, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15695. ExpectIntEQ(wc_AesGcmDecryptFinal(NULL, NULL, AES_BLOCK_SIZE),
  15696. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15697. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15698. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, NULL, AES_BLOCK_SIZE),
  15699. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15700. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE + 1),
  15701. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15702. /* Check calling final before setting key fails. */
  15703. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, sizeof(tag)), WC_NO_ERR_TRACE(MISSING_KEY));
  15704. ExpectIntEQ(wc_AesGcmEncryptFinal(aesDec, tag, sizeof(tag)), WC_NO_ERR_TRACE(MISSING_KEY));
  15705. /* Check calling update before setting key else fails. */
  15706. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 0, aad, 1),
  15707. WC_NO_ERR_TRACE(MISSING_KEY));
  15708. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 0, aad, 1),
  15709. WC_NO_ERR_TRACE(MISSING_KEY));
  15710. /* Set key but not IV. */
  15711. ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), NULL, 0), 0);
  15712. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), NULL, 0), 0);
  15713. /* Check calling final before setting IV fails. */
  15714. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, sizeof(tag)), WC_NO_ERR_TRACE(MISSING_IV));
  15715. ExpectIntEQ(wc_AesGcmEncryptFinal(aesDec, tag, sizeof(tag)), WC_NO_ERR_TRACE(MISSING_IV));
  15716. /* Check calling update before setting IV else fails. */
  15717. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 0, aad, 1),
  15718. WC_NO_ERR_TRACE(MISSING_IV));
  15719. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 0, aad, 1),
  15720. WC_NO_ERR_TRACE(MISSING_IV));
  15721. /* Set IV using fixed part IV and external IV APIs. */
  15722. ExpectIntEQ(wc_AesGcmSetIV(aesEnc, GCM_NONCE_MID_SZ, iv, AES_IV_FIXED_SZ,
  15723. rng), 0);
  15724. ExpectIntEQ(wc_AesGcmEncryptInit_ex(aesEnc, NULL, 0, ivOut,
  15725. GCM_NONCE_MID_SZ), 0);
  15726. ExpectIntEQ(wc_AesGcmSetExtIV(aesDec, ivOut, GCM_NONCE_MID_SZ), 0);
  15727. ExpectIntEQ(wc_AesGcmInit(aesDec, NULL, 0, NULL, 0), 0);
  15728. /* Encrypt and decrypt data. */
  15729. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, out, in, 1, aad, 1), 0);
  15730. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, plain, out, 1, aad, 1), 0);
  15731. ExpectIntEQ(XMEMCMP(plain, in, 1), 0);
  15732. /* Finalize and check tag matches. */
  15733. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE), 0);
  15734. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
  15735. /* Set key and IV through streaming init API. */
  15736. wc_AesFree(aesEnc);
  15737. wc_AesFree(aesDec);
  15738. ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
  15739. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15740. ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15741. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15742. /* Encrypt/decrypt one block and AAD of one block. */
  15743. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, out, in, AES_BLOCK_SIZE, aad,
  15744. AES_BLOCK_SIZE), 0);
  15745. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, plain, out, AES_BLOCK_SIZE, aad,
  15746. AES_BLOCK_SIZE), 0);
  15747. ExpectIntEQ(XMEMCMP(plain, in, AES_BLOCK_SIZE), 0);
  15748. /* Finalize and check tag matches. */
  15749. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE), 0);
  15750. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
  15751. /* Set key and IV through streaming init API. */
  15752. wc_AesFree(aesEnc);
  15753. wc_AesFree(aesDec);
  15754. ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
  15755. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15756. ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15757. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15758. /* No data to encrypt/decrypt one byte of AAD. */
  15759. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 0, aad, 1), 0);
  15760. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 0, aad, 1), 0);
  15761. /* Finalize and check tag matches. */
  15762. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE), 0);
  15763. ExpectIntEQ(XMEMCMP(tag, expTagAAD1, AES_BLOCK_SIZE), 0);
  15764. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
  15765. /* Set key and IV through streaming init API. */
  15766. wc_AesFree(aesEnc);
  15767. wc_AesFree(aesDec);
  15768. ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
  15769. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15770. ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15771. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15772. /* Encrypt/decrypt one byte and no AAD. */
  15773. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, out, in, 1, NULL, 0), 0);
  15774. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, plain, out, 1, NULL, 0), 0);
  15775. ExpectIntEQ(XMEMCMP(plain, in, 1), 0);
  15776. /* Finalize and check tag matches. */
  15777. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE), 0);
  15778. ExpectIntEQ(XMEMCMP(tag, expTagPlain1, AES_BLOCK_SIZE), 0);
  15779. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
  15780. /* Set key and IV through streaming init API. */
  15781. wc_AesFree(aesEnc);
  15782. wc_AesFree(aesDec);
  15783. ExpectIntEQ(wc_AesInit(aesEnc, NULL, INVALID_DEVID), 0);
  15784. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15785. ExpectIntEQ(wc_AesGcmInit(aesEnc, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15786. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15787. /* Encryption AES is one byte at a time */
  15788. for (i = 0; i < (int)sizeof(aad); i++) {
  15789. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, NULL, NULL, 0, aad + i, 1),
  15790. 0);
  15791. }
  15792. for (i = 0; i < (int)sizeof(in); i++) {
  15793. ExpectIntEQ(wc_AesGcmEncryptUpdate(aesEnc, out + i, in + i, 1, NULL, 0),
  15794. 0);
  15795. }
  15796. /* Decryption AES is two bytes at a time */
  15797. for (i = 0; i < (int)sizeof(aad); i += 2) {
  15798. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, NULL, NULL, 0, aad + i, 2),
  15799. 0);
  15800. }
  15801. for (i = 0; i < (int)sizeof(aad); i += 2) {
  15802. ExpectIntEQ(wc_AesGcmDecryptUpdate(aesDec, plain + i, out + i, 2, NULL,
  15803. 0), 0);
  15804. }
  15805. ExpectIntEQ(XMEMCMP(plain, in, sizeof(in)), 0);
  15806. /* Finalize and check tag matches. */
  15807. ExpectIntEQ(wc_AesGcmEncryptFinal(aesEnc, tag, AES_BLOCK_SIZE), 0);
  15808. ExpectIntEQ(XMEMCMP(tag, expTag, AES_BLOCK_SIZE), 0);
  15809. ExpectIntEQ(wc_AesGcmDecryptFinal(aesDec, tag, AES_BLOCK_SIZE), 0);
  15810. /* Check streaming encryption can be decrypted with one shot. */
  15811. wc_AesFree(aesDec);
  15812. ExpectIntEQ(wc_AesInit(aesDec, NULL, INVALID_DEVID), 0);
  15813. ExpectIntEQ(wc_AesGcmInit(aesDec, key, sizeof(key), iv, AES_IV_SIZE), 0);
  15814. ExpectIntEQ(wc_AesGcmSetKey(aesDec, key, sizeof(key)), 0);
  15815. ExpectIntEQ(wc_AesGcmDecrypt(aesDec, plain, out, sizeof(in), iv,
  15816. AES_IV_SIZE, tag, AES_BLOCK_SIZE, aad, sizeof(aad)), 0);
  15817. ExpectIntEQ(XMEMCMP(plain, in, sizeof(in)), 0);
  15818. wc_AesFree(aesEnc);
  15819. wc_AesFree(aesDec);
  15820. wc_FreeRng(rng);
  15821. #endif
  15822. return EXPECT_RESULT();
  15823. } /* END test_wc_AesGcmStream */
  15824. /*
  15825. * Testing streaming SM4 API.
  15826. */
  15827. static int test_wc_Sm4(void)
  15828. {
  15829. int res = TEST_SKIPPED;
  15830. #ifdef WOLFSSL_SM4
  15831. EXPECT_DECLS;
  15832. wc_Sm4 sm4;
  15833. #if defined(WOLFSSL_SM4_ECB) || defined(WOLFSSL_SM4_CBC) || \
  15834. defined(WOLFSSL_SM4_CTR) || defined(WOLFSSL_SM4_CCM)
  15835. unsigned char key[SM4_KEY_SIZE];
  15836. #endif
  15837. #if defined(WOLFSSL_SM4_CBC) || defined(WOLFSSL_SM4_CTR)
  15838. unsigned char iv[SM4_IV_SIZE];
  15839. #endif
  15840. /* Invalid parameters - wc_Sm4Init */
  15841. ExpectIntEQ(wc_Sm4Init(NULL, NULL, INVALID_DEVID), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15842. /* Valid cases - wc_Sm4Init */
  15843. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  15844. #if defined(WOLFSSL_SM4_ECB) || defined(WOLFSSL_SM4_CBC) || \
  15845. defined(WOLFSSL_SM4_CTR) || defined(WOLFSSL_SM4_CCM)
  15846. XMEMSET(key, 0, sizeof(key));
  15847. /* Invalid parameters - wc_Sm4SetKey. */
  15848. ExpectIntEQ(wc_Sm4SetKey(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15849. ExpectIntEQ(wc_Sm4SetKey(&sm4, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15850. ExpectIntEQ(wc_Sm4SetKey(NULL, key, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15851. ExpectIntEQ(wc_Sm4SetKey(NULL, NULL, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15852. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15853. ExpectIntEQ(wc_Sm4SetKey(&sm4, NULL, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15854. ExpectIntEQ(wc_Sm4SetKey(NULL, key, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15855. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE-1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15856. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE+1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15857. /* Valid cases - wc_Sm4SetKey. */
  15858. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE), 0);
  15859. #endif
  15860. #if defined(WOLFSSL_SM4_CBC) || defined(WOLFSSL_SM4_CTR)
  15861. XMEMSET(iv, 0, sizeof(iv));
  15862. /* Invalid parameters - wc_Sm4SetIV. */
  15863. ExpectIntEQ(wc_Sm4SetIV(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15864. ExpectIntEQ(wc_Sm4SetIV(&sm4, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15865. ExpectIntEQ(wc_Sm4SetIV(NULL, iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15866. /* Valid cases - wc_Sm4SetIV. */
  15867. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15868. #endif
  15869. /* Valid cases - wc_Sm4Free */
  15870. wc_Sm4Free(NULL);
  15871. wc_Sm4Free(&sm4);
  15872. res = EXPECT_RESULT();
  15873. #endif
  15874. return res;
  15875. } /* END test_wc_Sm4 */
  15876. /*
  15877. * Testing block based SM4-ECB API.
  15878. */
  15879. static int test_wc_Sm4Ecb(void)
  15880. {
  15881. int res = TEST_SKIPPED;
  15882. #ifdef WOLFSSL_SM4_ECB
  15883. EXPECT_DECLS;
  15884. wc_Sm4 sm4;
  15885. unsigned char key[SM4_KEY_SIZE];
  15886. unsigned char in[SM4_BLOCK_SIZE * 2];
  15887. unsigned char out[SM4_BLOCK_SIZE * 2];
  15888. unsigned char out2[SM4_BLOCK_SIZE];
  15889. XMEMSET(key, 0, sizeof(key));
  15890. XMEMSET(in, 0, sizeof(in));
  15891. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  15892. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_KEY));
  15893. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_KEY));
  15894. /* Tested in test_wc_Sm4. */
  15895. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE), 0);
  15896. /* Invalid parameters - wc_Sm4EcbEncrypt. */
  15897. ExpectIntEQ(wc_Sm4EcbEncrypt(NULL, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15898. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15899. ExpectIntEQ(wc_Sm4EcbEncrypt(NULL, out, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15900. ExpectIntEQ(wc_Sm4EcbEncrypt(NULL, NULL, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15901. ExpectIntEQ(wc_Sm4EcbEncrypt(NULL, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15902. ExpectIntEQ(wc_Sm4EcbEncrypt(NULL, out, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15903. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15904. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15905. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15906. /* Valid cases - wc_Sm4EcbEncrypt. */
  15907. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out, in, 0), 0);
  15908. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out2, in, SM4_BLOCK_SIZE), 0);
  15909. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15910. ExpectIntEQ(XMEMCMP(out, out2, SM4_BLOCK_SIZE), 0);
  15911. /* In and out are same pointer. */
  15912. ExpectIntEQ(wc_Sm4EcbEncrypt(&sm4, in, in, SM4_BLOCK_SIZE * 2), 0);
  15913. ExpectIntEQ(XMEMCMP(in, out, SM4_BLOCK_SIZE * 2), 0);
  15914. /* Invalid parameters - wc_Sm4EcbDecrypt. */
  15915. ExpectIntEQ(wc_Sm4EcbDecrypt(NULL, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15916. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15917. ExpectIntEQ(wc_Sm4EcbDecrypt(NULL, out, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15918. ExpectIntEQ(wc_Sm4EcbDecrypt(NULL, NULL, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15919. ExpectIntEQ(wc_Sm4EcbDecrypt(NULL, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15920. ExpectIntEQ(wc_Sm4EcbDecrypt(NULL, out, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15921. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15922. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15923. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15924. /* Valid cases - wc_Sm4EcbDecrypt. */
  15925. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out, in, 0), 0);
  15926. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out2, in, SM4_BLOCK_SIZE), 0);
  15927. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15928. ExpectIntEQ(XMEMCMP(out, out2, SM4_BLOCK_SIZE), 0);
  15929. /* In and out are same pointer. */
  15930. ExpectIntEQ(wc_Sm4EcbDecrypt(&sm4, in, in, SM4_BLOCK_SIZE * 2), 0);
  15931. ExpectIntEQ(XMEMCMP(in, out, SM4_BLOCK_SIZE * 2), 0);
  15932. wc_Sm4Free(&sm4);
  15933. res = EXPECT_RESULT();
  15934. #endif
  15935. return res;
  15936. } /* END test_wc_Sm4Ecb */
  15937. /*
  15938. * Testing block based SM4-CBC API.
  15939. */
  15940. static int test_wc_Sm4Cbc(void)
  15941. {
  15942. int res = TEST_SKIPPED;
  15943. #ifdef WOLFSSL_SM4_CBC
  15944. EXPECT_DECLS;
  15945. wc_Sm4 sm4;
  15946. unsigned char key[SM4_KEY_SIZE];
  15947. unsigned char iv[SM4_IV_SIZE];
  15948. unsigned char in[SM4_BLOCK_SIZE * 2];
  15949. unsigned char out[SM4_BLOCK_SIZE * 2];
  15950. unsigned char out2[SM4_BLOCK_SIZE];
  15951. XMEMSET(key, 0, sizeof(key));
  15952. XMEMSET(iv, 0, sizeof(iv));
  15953. XMEMSET(in, 0, sizeof(in));
  15954. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  15955. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_KEY));
  15956. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_KEY));
  15957. /* Tested in test_wc_Sm4. */
  15958. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE), 0);
  15959. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_IV));
  15960. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_IV));
  15961. /* Tested in test_wc_Sm4. */
  15962. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15963. /* Invalid parameters - wc_Sm4CbcEncrypt. */
  15964. ExpectIntEQ(wc_Sm4CbcEncrypt(NULL, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15965. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15966. ExpectIntEQ(wc_Sm4CbcEncrypt(NULL, out, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15967. ExpectIntEQ(wc_Sm4CbcEncrypt(NULL, NULL, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15968. ExpectIntEQ(wc_Sm4CbcEncrypt(NULL, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15969. ExpectIntEQ(wc_Sm4CbcEncrypt(NULL, out, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15970. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15971. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15972. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15973. /* Valid cases - wc_Sm4CbcEncrypt. */
  15974. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, in, 0), 0);
  15975. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out2, in, SM4_BLOCK_SIZE), 0);
  15976. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15977. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15978. ExpectIntEQ(XMEMCMP(out, out2, SM4_BLOCK_SIZE), 0);
  15979. /* In and out are same pointer. */
  15980. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15981. ExpectIntEQ(wc_Sm4CbcEncrypt(&sm4, in, in, SM4_BLOCK_SIZE * 2), 0);
  15982. ExpectIntEQ(XMEMCMP(in, out, SM4_BLOCK_SIZE * 2), 0);
  15983. /* Invalid parameters - wc_Sm4CbcDecrypt. */
  15984. ExpectIntEQ(wc_Sm4CbcDecrypt(NULL, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15985. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, NULL, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15986. ExpectIntEQ(wc_Sm4CbcDecrypt(NULL, out, NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15987. ExpectIntEQ(wc_Sm4CbcDecrypt(NULL, NULL, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15988. ExpectIntEQ(wc_Sm4CbcDecrypt(NULL, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15989. ExpectIntEQ(wc_Sm4CbcDecrypt(NULL, out, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15990. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15991. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15992. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, in, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  15993. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15994. /* Valid cases - wc_Sm4CbcDecrypt. */
  15995. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, in, 0), 0);
  15996. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out2, in, SM4_BLOCK_SIZE), 0);
  15997. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  15998. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  15999. ExpectIntEQ(XMEMCMP(out, out2, SM4_BLOCK_SIZE), 0);
  16000. /* In and out are same pointer. */
  16001. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  16002. ExpectIntEQ(wc_Sm4CbcDecrypt(&sm4, in, in, SM4_BLOCK_SIZE * 2), 0);
  16003. ExpectIntEQ(XMEMCMP(in, out, SM4_BLOCK_SIZE * 2), 0);
  16004. wc_Sm4Free(&sm4);
  16005. res = EXPECT_RESULT();
  16006. #endif
  16007. return res;
  16008. } /* END test_wc_Sm4Cbc */
  16009. /*
  16010. * Testing streaming SM4-CTR API.
  16011. */
  16012. static int test_wc_Sm4Ctr(void)
  16013. {
  16014. int res = TEST_SKIPPED;
  16015. #ifdef WOLFSSL_SM4_CTR
  16016. EXPECT_DECLS;
  16017. wc_Sm4 sm4;
  16018. unsigned char key[SM4_KEY_SIZE];
  16019. unsigned char iv[SM4_IV_SIZE];
  16020. unsigned char in[SM4_BLOCK_SIZE * 4];
  16021. unsigned char out[SM4_BLOCK_SIZE * 4];
  16022. unsigned char out2[SM4_BLOCK_SIZE * 4];
  16023. word32 chunk;
  16024. word32 i;
  16025. XMEMSET(key, 0, sizeof(key));
  16026. XMEMSET(iv, 0, sizeof(iv));
  16027. XMEMSET(in, 0, sizeof(in));
  16028. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  16029. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_KEY));
  16030. /* Tested in test_wc_Sm4. */
  16031. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE), 0);
  16032. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, 0), WC_NO_ERR_TRACE(MISSING_IV));
  16033. /* Tested in test_wc_Sm4. */
  16034. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  16035. /* Invalid parameters - wc_Sm4CtrEncrypt. */
  16036. ExpectIntEQ(wc_Sm4CtrEncrypt(NULL, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16037. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16038. ExpectIntEQ(wc_Sm4CtrEncrypt(NULL, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16039. ExpectIntEQ(wc_Sm4CtrEncrypt(NULL, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16040. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16041. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, NULL, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16042. ExpectIntEQ(wc_Sm4CtrEncrypt(NULL, out, in, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16043. /* Valid cases - wc_Sm4CtrEncrypt. */
  16044. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, 0), 0);
  16045. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out2, in, 1), 0);
  16046. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  16047. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, 2), 0);
  16048. ExpectIntEQ(XMEMCMP(out, out2, 1), 0);
  16049. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  16050. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out2, in, SM4_BLOCK_SIZE), 0);
  16051. ExpectIntEQ(XMEMCMP(out2, out, 2), 0);
  16052. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  16053. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  16054. ExpectIntEQ(XMEMCMP(out, out2, SM4_BLOCK_SIZE), 0);
  16055. /* In and out are same pointer. Also check encrypt of cipher text produces
  16056. * plaintext.
  16057. */
  16058. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  16059. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, out, SM4_BLOCK_SIZE * 2), 0);
  16060. ExpectIntEQ(XMEMCMP(in, out, SM4_BLOCK_SIZE * 2), 0);
  16061. /* Chunking tests. */
  16062. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  16063. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out2, in, (word32)sizeof(in)), 0);
  16064. for (chunk = 1; chunk <= SM4_BLOCK_SIZE + 1; chunk++) {
  16065. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  16066. for (i = 0; i + chunk <= (word32)sizeof(in); i += chunk) {
  16067. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out + i, in + i, chunk), 0);
  16068. }
  16069. if (i < (word32)sizeof(in)) {
  16070. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out + i, in + i,
  16071. (word32)sizeof(in) - i), 0);
  16072. }
  16073. ExpectIntEQ(XMEMCMP(out, out2, (word32)sizeof(out)), 0);
  16074. }
  16075. for (i = 0; i < (word32)sizeof(iv); i++) {
  16076. iv[i] = 0xff;
  16077. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  16078. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2), 0);
  16079. ExpectIntEQ(wc_Sm4SetIV(&sm4, iv), 0);
  16080. ExpectIntEQ(wc_Sm4CtrEncrypt(&sm4, out2, out, SM4_BLOCK_SIZE * 2), 0);
  16081. ExpectIntEQ(XMEMCMP(out2, in, SM4_BLOCK_SIZE * 2), 0);
  16082. }
  16083. wc_Sm4Free(&sm4);
  16084. res = EXPECT_RESULT();
  16085. #endif
  16086. return res;
  16087. } /* END test_wc_Sm4Ctr */
  16088. /*
  16089. * Testing stream SM4-GCM API.
  16090. */
  16091. static int test_wc_Sm4Gcm(void)
  16092. {
  16093. int res = TEST_SKIPPED;
  16094. #ifdef WOLFSSL_SM4_GCM
  16095. EXPECT_DECLS;
  16096. wc_Sm4 sm4;
  16097. unsigned char key[SM4_KEY_SIZE];
  16098. unsigned char nonce[GCM_NONCE_MAX_SZ];
  16099. unsigned char in[SM4_BLOCK_SIZE * 2];
  16100. unsigned char in2[SM4_BLOCK_SIZE * 2];
  16101. unsigned char out[SM4_BLOCK_SIZE * 2];
  16102. unsigned char out2[SM4_BLOCK_SIZE * 2];
  16103. unsigned char dec[SM4_BLOCK_SIZE * 2];
  16104. unsigned char tag[SM4_BLOCK_SIZE];
  16105. unsigned char aad[SM4_BLOCK_SIZE * 2];
  16106. word32 i;
  16107. XMEMSET(key, 0, sizeof(key));
  16108. XMEMSET(nonce, 0, sizeof(nonce));
  16109. XMEMSET(in, 0, sizeof(in));
  16110. XMEMSET(in2, 0, sizeof(in2));
  16111. XMEMSET(aad, 0, sizeof(aad));
  16112. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  16113. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 0, nonce, GCM_NONCE_MID_SZ, tag,
  16114. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(MISSING_KEY));
  16115. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 0, nonce, GCM_NONCE_MID_SZ, tag,
  16116. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(MISSING_KEY));
  16117. /* Invalid parameters - wc_Sm4GcmSetKey. */
  16118. ExpectIntEQ(wc_Sm4GcmSetKey(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16119. ExpectIntEQ(wc_Sm4GcmSetKey(&sm4, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16120. ExpectIntEQ(wc_Sm4GcmSetKey(NULL, key, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16121. ExpectIntEQ(wc_Sm4GcmSetKey(NULL, NULL, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16122. ExpectIntEQ(wc_Sm4GcmSetKey(&sm4, key, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16123. ExpectIntEQ(wc_Sm4GcmSetKey(&sm4, NULL, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16124. ExpectIntEQ(wc_Sm4GcmSetKey(NULL, key, SM4_KEY_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16125. /* Valid parameters - wc_Sm4GcmSetKey. */
  16126. ExpectIntEQ(wc_Sm4GcmSetKey(&sm4, key, SM4_KEY_SIZE), 0);
  16127. /* Invalid parameters - wc_Sm4GcmEncrypt. */
  16128. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  16129. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16130. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  16131. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16132. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, out, NULL, 1, NULL, 0, NULL, 0, NULL,
  16133. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16134. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, NULL, in, 1, NULL, 0, NULL, 0, NULL,
  16135. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16136. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, NULL, NULL, 1, nonce, GCM_NONCE_MID_SZ,
  16137. NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16138. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, NULL, NULL, 1, NULL, 0, tag,
  16139. SM4_BLOCK_SIZE, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16140. ExpectIntEQ(wc_Sm4GcmEncrypt(NULL, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  16141. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16142. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, NULL, in, 1, nonce, GCM_NONCE_MID_SZ,
  16143. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16144. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, NULL, 1, nonce, GCM_NONCE_MID_SZ,
  16145. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16146. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, NULL, GCM_NONCE_MID_SZ, tag,
  16147. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16148. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, nonce, 0, tag,
  16149. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16150. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ,
  16151. NULL, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16152. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  16153. WOLFSSL_MIN_AUTH_TAG_SZ-1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16154. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  16155. SM4_BLOCK_SIZE+1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16156. /* Invalid parameters - wc_Sm4GcmDecrypt. */
  16157. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  16158. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16159. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  16160. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16161. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, out, NULL, 1, NULL, 0, NULL, 0, NULL,
  16162. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16163. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, NULL, in, 1, NULL, 0, NULL, 0, NULL,
  16164. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16165. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, NULL, NULL, 1, nonce, GCM_NONCE_MID_SZ,
  16166. NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16167. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, NULL, NULL, 1, NULL, 0, tag,
  16168. SM4_BLOCK_SIZE, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16169. ExpectIntEQ(wc_Sm4GcmDecrypt(NULL, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  16170. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16171. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, NULL, in, 1, nonce, GCM_NONCE_MID_SZ,
  16172. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16173. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, NULL, 1, nonce, GCM_NONCE_MID_SZ,
  16174. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16175. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 1, NULL, GCM_NONCE_MID_SZ, tag,
  16176. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16177. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 1, nonce, 0, tag,
  16178. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16179. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ,
  16180. NULL, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16181. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  16182. WOLFSSL_MIN_AUTH_TAG_SZ-1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16183. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 1, nonce, GCM_NONCE_MID_SZ, tag,
  16184. SM4_BLOCK_SIZE+1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16185. /* Valid cases - wc_Sm4GcmEncrypt/wc_Sm4GcmDecrypt. */
  16186. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, NULL, NULL, 0, nonce, GCM_NONCE_MID_SZ,
  16187. tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16188. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, NULL, NULL, 0, nonce, GCM_NONCE_MID_SZ,
  16189. tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16190. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, NULL, NULL, 0, nonce, GCM_NONCE_MID_SZ,
  16191. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16192. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, NULL, NULL, 0, nonce, GCM_NONCE_MID_SZ,
  16193. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16194. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16195. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16196. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16197. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16198. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16199. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 1), 0);
  16200. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16201. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 1), 0);
  16202. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2, nonce,
  16203. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16204. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE * 2, nonce,
  16205. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16206. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, in2, in2, SM4_BLOCK_SIZE * 2, nonce,
  16207. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16208. ExpectIntEQ(XMEMCMP(in2, out, SM4_BLOCK_SIZE * 2), 0);
  16209. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in2, in2, SM4_BLOCK_SIZE * 2, nonce,
  16210. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16211. ExpectIntEQ(XMEMCMP(in2, in, SM4_BLOCK_SIZE * 2), 0);
  16212. /* Check vald values of nonce - wc_Sm4GcmEncrypt/wc_Sm4GcmDecrypt. */
  16213. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16214. GCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16215. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16216. GCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16217. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2, nonce,
  16218. GCM_NONCE_MIN_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16219. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE * 2, nonce,
  16220. GCM_NONCE_MIN_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16221. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE * 2, nonce,
  16222. GCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)),
  16223. WC_NO_ERR_TRACE(SM4_GCM_AUTH_E));
  16224. /* Check valid values of tag size - wc_Sm4GcmEncrypt/wc_Sm4GcmDecrypt. */
  16225. for (i = WOLFSSL_MIN_AUTH_TAG_SZ; i < SM4_BLOCK_SIZE; i++) {
  16226. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16227. GCM_NONCE_MID_SZ, tag, i, aad, sizeof(aad)), 0);
  16228. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16229. GCM_NONCE_MID_SZ, tag, i, aad, sizeof(aad)), 0);
  16230. }
  16231. /* Check different in/out sizes. */
  16232. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 0, nonce,
  16233. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16234. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, out, in, 0, nonce,
  16235. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16236. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, 1, nonce,
  16237. GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16238. for (i = 2; i <= SM4_BLOCK_SIZE * 2; i++) {
  16239. XMEMCPY(out2, out, i - 1);
  16240. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, out, in, i, nonce, GCM_NONCE_MID_SZ,
  16241. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16242. ExpectIntEQ(XMEMCMP(out, out2, i - 1), 0);
  16243. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, dec, out, i, nonce, GCM_NONCE_MID_SZ,
  16244. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16245. ExpectIntEQ(XMEMCMP(in, dec, i), 0);
  16246. }
  16247. /* Force the counter to roll over in first byte. */
  16248. {
  16249. static unsigned char largeIn[256 * SM4_BLOCK_SIZE];
  16250. static unsigned char largeOut[256 * SM4_BLOCK_SIZE];
  16251. ExpectIntEQ(wc_Sm4GcmEncrypt(&sm4, largeOut, largeIn, sizeof(largeIn),
  16252. nonce, GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16253. ExpectIntEQ(wc_Sm4GcmDecrypt(&sm4, largeOut, largeOut, sizeof(largeIn),
  16254. nonce, GCM_NONCE_MID_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16255. ExpectIntEQ(XMEMCMP(largeOut, largeIn, sizeof(largeIn)), 0);
  16256. }
  16257. wc_Sm4Free(&sm4);
  16258. res = EXPECT_RESULT();
  16259. #endif
  16260. return res;
  16261. } /* END test_wc_Sm4Gcm */
  16262. /*
  16263. * Testing stream SM4-CCM API.
  16264. */
  16265. static int test_wc_Sm4Ccm(void)
  16266. {
  16267. int res = TEST_SKIPPED;
  16268. #ifdef WOLFSSL_SM4_CCM
  16269. EXPECT_DECLS;
  16270. wc_Sm4 sm4;
  16271. unsigned char key[SM4_KEY_SIZE];
  16272. unsigned char nonce[CCM_NONCE_MAX_SZ];
  16273. unsigned char in[SM4_BLOCK_SIZE * 2];
  16274. unsigned char in2[SM4_BLOCK_SIZE * 2];
  16275. unsigned char out[SM4_BLOCK_SIZE * 2];
  16276. unsigned char out2[SM4_BLOCK_SIZE * 2];
  16277. unsigned char dec[SM4_BLOCK_SIZE * 2];
  16278. unsigned char tag[SM4_BLOCK_SIZE];
  16279. unsigned char aad[SM4_BLOCK_SIZE * 2];
  16280. word32 i;
  16281. XMEMSET(key, 0, sizeof(key));
  16282. XMEMSET(nonce, 0, sizeof(nonce));
  16283. XMEMSET(in, 0, sizeof(in));
  16284. XMEMSET(in2, 0, sizeof(in2));
  16285. XMEMSET(aad, 0, sizeof(aad));
  16286. ExpectIntEQ(wc_Sm4Init(&sm4, NULL, INVALID_DEVID), 0);
  16287. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 0, nonce, CCM_NONCE_MAX_SZ, tag,
  16288. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(MISSING_KEY));
  16289. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 0, nonce, CCM_NONCE_MAX_SZ, tag,
  16290. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(MISSING_KEY));
  16291. ExpectIntEQ(wc_Sm4SetKey(&sm4, key, SM4_KEY_SIZE), 0);
  16292. /* Invalid parameters - wc_Sm4CcmEncrypt. */
  16293. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  16294. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16295. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  16296. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16297. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, out, NULL, 1, NULL, 0, NULL, 0, NULL,
  16298. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16299. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, NULL, in, 1, NULL, 0, NULL, 0, NULL,
  16300. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16301. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, NULL, NULL, 1, nonce, CCM_NONCE_MAX_SZ,
  16302. NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16303. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, NULL, NULL, 1, NULL, 0, tag,
  16304. SM4_BLOCK_SIZE, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16305. ExpectIntEQ(wc_Sm4CcmEncrypt(NULL, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  16306. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16307. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, NULL, in, 1, nonce, CCM_NONCE_MAX_SZ,
  16308. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16309. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, NULL, 1, nonce, CCM_NONCE_MAX_SZ,
  16310. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16311. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, NULL, CCM_NONCE_MAX_SZ, tag,
  16312. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16313. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, nonce, 0, tag,
  16314. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16315. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ,
  16316. NULL, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16317. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  16318. WOLFSSL_MIN_AUTH_TAG_SZ-1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16319. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  16320. SM4_BLOCK_SIZE+1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16321. /* Invalid parameters - wc_Sm4CcmDecrypt. */
  16322. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  16323. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16324. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, NULL, NULL, 1, NULL, 0, NULL, 0, NULL,
  16325. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16326. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, out, NULL, 1, NULL, 0, NULL, 0, NULL,
  16327. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16328. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, NULL, in, 1, NULL, 0, NULL, 0, NULL,
  16329. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16330. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, NULL, NULL, 1, nonce, CCM_NONCE_MAX_SZ,
  16331. NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16332. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, NULL, NULL, 1, NULL, 0, tag,
  16333. SM4_BLOCK_SIZE, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16334. ExpectIntEQ(wc_Sm4CcmDecrypt(NULL, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  16335. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16336. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, NULL, in, 1, nonce, CCM_NONCE_MAX_SZ,
  16337. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16338. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, NULL, 1, nonce, CCM_NONCE_MAX_SZ,
  16339. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16340. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 1, NULL, CCM_NONCE_MAX_SZ, tag,
  16341. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16342. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 1, nonce, 0, tag,
  16343. SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16344. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ,
  16345. NULL, SM4_BLOCK_SIZE, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16346. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  16347. WOLFSSL_MIN_AUTH_TAG_SZ - 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16348. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 1, nonce, CCM_NONCE_MAX_SZ, tag,
  16349. SM4_BLOCK_SIZE + 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16350. /* Valid cases - wc_Sm4CcmEncrypt/wc_Sm4CcmDecrypt. */
  16351. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, NULL, NULL, 0, nonce, CCM_NONCE_MAX_SZ,
  16352. tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16353. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, NULL, NULL, 0, nonce, CCM_NONCE_MAX_SZ,
  16354. tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16355. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, NULL, NULL, 0, nonce, CCM_NONCE_MAX_SZ,
  16356. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16357. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, NULL, NULL, 0, nonce, CCM_NONCE_MAX_SZ,
  16358. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16359. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16360. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16361. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16362. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16363. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16364. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 1), 0);
  16365. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16366. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 1), 0);
  16367. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE * 2, nonce,
  16368. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16369. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE * 2, nonce,
  16370. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16371. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, in2, in2, SM4_BLOCK_SIZE * 2, nonce,
  16372. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16373. ExpectIntEQ(XMEMCMP(in2, out, SM4_BLOCK_SIZE * 2), 0);
  16374. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in2, in2, SM4_BLOCK_SIZE * 2, nonce,
  16375. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16376. ExpectIntEQ(XMEMCMP(in2, in, SM4_BLOCK_SIZE * 2), 0);
  16377. /* Check vald values of nonce - wc_Sm4CcmEncrypt/wc_Sm4CcmDecrypt. */
  16378. for (i = CCM_NONCE_MIN_SZ; i <= CCM_NONCE_MAX_SZ; i++) {
  16379. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16380. i, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16381. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16382. i, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16383. }
  16384. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16385. CCM_NONCE_MIN_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)),
  16386. WC_NO_ERR_TRACE(SM4_CCM_AUTH_E));
  16387. /* Check invalid values of tag size - wc_Sm4CcmEncrypt/wc_Sm4CcmDecrypt. */
  16388. for (i = 0; i < 4; i++) {
  16389. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16390. CCM_NONCE_MAX_SZ, tag, i * 2 + 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16391. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16392. CCM_NONCE_MAX_SZ, tag, i * 2 + 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16393. }
  16394. /* Odd values in range 4..SM4_BLOCK_SIZE. */
  16395. for (i = 2; i < SM4_BLOCK_SIZE / 2; i++) {
  16396. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16397. CCM_NONCE_MAX_SZ, tag, i * 2 + 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16398. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16399. CCM_NONCE_MAX_SZ, tag, i * 2 + 1, aad, sizeof(aad)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16400. }
  16401. /* Check valid values of tag size - wc_Sm4CcmEncrypt/wc_Sm4CcmDecrypt.
  16402. * Even values in range 4..SM4_BLOCK_SIZE.
  16403. */
  16404. for (i = 2; i < SM4_BLOCK_SIZE / 2; i++) {
  16405. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, SM4_BLOCK_SIZE, nonce,
  16406. CCM_NONCE_MAX_SZ, tag, i * 2, aad, sizeof(aad)), 0);
  16407. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, in, out, SM4_BLOCK_SIZE, nonce,
  16408. CCM_NONCE_MAX_SZ, tag, i * 2, aad, sizeof(aad)), 0);
  16409. }
  16410. /* Check different in/out sizes. */
  16411. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 0, nonce,
  16412. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16413. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, out, in, 0, nonce,
  16414. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16415. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, 1, nonce,
  16416. CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, NULL, 0), 0);
  16417. for (i = 2; i <= SM4_BLOCK_SIZE * 2; i++) {
  16418. XMEMCPY(out2, out, i - 1);
  16419. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, out, in, i, nonce, CCM_NONCE_MAX_SZ,
  16420. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16421. ExpectIntEQ(XMEMCMP(out, out2, i - 1), 0);
  16422. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, dec, out, i, nonce, CCM_NONCE_MAX_SZ,
  16423. tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16424. ExpectIntEQ(XMEMCMP(in, dec, i), 0);
  16425. }
  16426. /* Force the counter to roll over in first byte. */
  16427. {
  16428. static unsigned char largeIn[256 * SM4_BLOCK_SIZE];
  16429. static unsigned char largeOut[256 * SM4_BLOCK_SIZE];
  16430. ExpectIntEQ(wc_Sm4CcmEncrypt(&sm4, largeOut, largeIn, sizeof(largeIn),
  16431. nonce, CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16432. ExpectIntEQ(wc_Sm4CcmDecrypt(&sm4, largeOut, largeOut, sizeof(largeIn),
  16433. nonce, CCM_NONCE_MAX_SZ, tag, SM4_BLOCK_SIZE, aad, sizeof(aad)), 0);
  16434. ExpectIntEQ(XMEMCMP(largeOut, largeIn, sizeof(largeIn)), 0);
  16435. }
  16436. wc_Sm4Free(&sm4);
  16437. res = EXPECT_RESULT();
  16438. #endif
  16439. return res;
  16440. } /* END test_wc_Sm4Ccm */
  16441. /*
  16442. * unit test for wc_Des3_SetIV()
  16443. */
  16444. static int test_wc_Des3_SetIV(void)
  16445. {
  16446. EXPECT_DECLS;
  16447. #ifndef NO_DES3
  16448. Des3 des;
  16449. const byte key[] = {
  16450. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  16451. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  16452. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  16453. };
  16454. const byte iv[] = {
  16455. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  16456. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  16457. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  16458. };
  16459. XMEMSET(&des, 0, sizeof(Des3));
  16460. ExpectIntEQ(wc_Des3Init(&des, NULL, INVALID_DEVID), 0);
  16461. /* DES_ENCRYPTION or DES_DECRYPTION */
  16462. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, DES_ENCRYPTION), 0);
  16463. ExpectIntEQ(XMEMCMP(iv, des.reg, DES_BLOCK_SIZE), 0);
  16464. #ifndef HAVE_FIPS /* no sanity checks with FIPS wrapper */
  16465. /* Test explicitly wc_Des3_SetIV() */
  16466. ExpectIntEQ(wc_Des3_SetIV(NULL, iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16467. ExpectIntEQ(wc_Des3_SetIV(&des, NULL), 0);
  16468. #endif
  16469. wc_Des3Free(&des);
  16470. #endif
  16471. return EXPECT_RESULT();
  16472. } /* END test_wc_Des3_SetIV */
  16473. /*
  16474. * unit test for wc_Des3_SetKey()
  16475. */
  16476. static int test_wc_Des3_SetKey(void)
  16477. {
  16478. EXPECT_DECLS;
  16479. #ifndef NO_DES3
  16480. Des3 des;
  16481. const byte key[] = {
  16482. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  16483. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  16484. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  16485. };
  16486. const byte iv[] = {
  16487. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  16488. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  16489. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  16490. };
  16491. XMEMSET(&des, 0, sizeof(Des3));
  16492. ExpectIntEQ(wc_Des3Init(&des, NULL, INVALID_DEVID), 0);
  16493. /* DES_ENCRYPTION or DES_DECRYPTION */
  16494. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, DES_ENCRYPTION), 0);
  16495. ExpectIntEQ(XMEMCMP(iv, des.reg, DES_BLOCK_SIZE), 0);
  16496. /* Test bad args. */
  16497. ExpectIntEQ(wc_Des3_SetKey(NULL, key, iv, DES_ENCRYPTION), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16498. ExpectIntEQ(wc_Des3_SetKey(&des, NULL, iv, DES_ENCRYPTION), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16499. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16500. /* Default case. Should return 0. */
  16501. ExpectIntEQ(wc_Des3_SetKey(&des, key, NULL, DES_ENCRYPTION), 0);
  16502. wc_Des3Free(&des);
  16503. #endif
  16504. return EXPECT_RESULT();
  16505. } /* END test_wc_Des3_SetKey */
  16506. /*
  16507. * Test function for wc_Des3_CbcEncrypt and wc_Des3_CbcDecrypt
  16508. */
  16509. static int test_wc_Des3_CbcEncryptDecrypt(void)
  16510. {
  16511. EXPECT_DECLS;
  16512. #ifndef NO_DES3
  16513. Des3 des;
  16514. byte cipher[24];
  16515. byte plain[24];
  16516. const byte key[] = {
  16517. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  16518. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  16519. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  16520. };
  16521. const byte iv[] = {
  16522. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  16523. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  16524. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  16525. };
  16526. const byte vector[] = { /* "Now is the time for all " w/o trailing 0 */
  16527. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  16528. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  16529. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  16530. };
  16531. XMEMSET(&des, 0, sizeof(Des3));
  16532. ExpectIntEQ(wc_Des3Init(&des, NULL, INVALID_DEVID), 0);
  16533. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, DES_ENCRYPTION), 0);
  16534. ExpectIntEQ(wc_Des3_CbcEncrypt(&des, cipher, vector, 24), 0);
  16535. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, DES_DECRYPTION), 0);
  16536. ExpectIntEQ(wc_Des3_CbcDecrypt(&des, plain, cipher, 24), 0);
  16537. ExpectIntEQ(XMEMCMP(plain, vector, 24), 0);
  16538. /* Pass in bad args. */
  16539. ExpectIntEQ(wc_Des3_CbcEncrypt(NULL, cipher, vector, 24), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16540. ExpectIntEQ(wc_Des3_CbcEncrypt(&des, NULL, vector, 24), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16541. ExpectIntEQ(wc_Des3_CbcEncrypt(&des, cipher, NULL, sizeof(vector)),
  16542. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16543. ExpectIntEQ(wc_Des3_CbcDecrypt(NULL, plain, cipher, 24), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16544. ExpectIntEQ(wc_Des3_CbcDecrypt(&des, NULL, cipher, 24), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16545. ExpectIntEQ(wc_Des3_CbcDecrypt(&des, plain, NULL, 24), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16546. wc_Des3Free(&des);
  16547. #endif
  16548. return EXPECT_RESULT();
  16549. } /* END wc_Des3_CbcEncrypt */
  16550. /*
  16551. * Unit test for wc_Des3_CbcEncryptWithKey and wc_Des3_CbcDecryptWithKey
  16552. */
  16553. static int test_wc_Des3_CbcEncryptDecryptWithKey(void)
  16554. {
  16555. EXPECT_DECLS;
  16556. #ifndef NO_DES3
  16557. word32 vectorSz, cipherSz;
  16558. byte cipher[24];
  16559. byte plain[24];
  16560. byte vector[] = { /* Now is the time for all w/o trailing 0 */
  16561. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  16562. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  16563. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  16564. };
  16565. byte key[] = {
  16566. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  16567. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  16568. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  16569. };
  16570. byte iv[] = {
  16571. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  16572. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  16573. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  16574. };
  16575. vectorSz = sizeof(byte) * 24;
  16576. cipherSz = sizeof(byte) * 24;
  16577. ExpectIntEQ(wc_Des3_CbcEncryptWithKey(cipher, vector, vectorSz, key, iv),
  16578. 0);
  16579. ExpectIntEQ(wc_Des3_CbcDecryptWithKey(plain, cipher, cipherSz, key, iv), 0);
  16580. ExpectIntEQ(XMEMCMP(plain, vector, 24), 0);
  16581. /* pass in bad args. */
  16582. ExpectIntEQ(wc_Des3_CbcEncryptWithKey(NULL, vector, vectorSz, key, iv),
  16583. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16584. ExpectIntEQ(wc_Des3_CbcEncryptWithKey(cipher, NULL, vectorSz, key, iv),
  16585. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16586. ExpectIntEQ(wc_Des3_CbcEncryptWithKey(cipher, vector, vectorSz, NULL, iv),
  16587. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16588. ExpectIntEQ(wc_Des3_CbcEncryptWithKey(cipher, vector, vectorSz, key, NULL),
  16589. 0);
  16590. ExpectIntEQ(wc_Des3_CbcDecryptWithKey(NULL, cipher, cipherSz, key, iv),
  16591. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16592. ExpectIntEQ(wc_Des3_CbcDecryptWithKey(plain, NULL, cipherSz, key, iv),
  16593. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16594. ExpectIntEQ(wc_Des3_CbcDecryptWithKey(plain, cipher, cipherSz, NULL, iv),
  16595. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16596. ExpectIntEQ(wc_Des3_CbcDecryptWithKey(plain, cipher, cipherSz, key, NULL),
  16597. 0);
  16598. #endif
  16599. return EXPECT_RESULT();
  16600. } /* END test_wc_Des3_CbcEncryptDecryptWithKey */
  16601. /*
  16602. * Unit test for wc_Des3_EcbEncrypt
  16603. */
  16604. static int test_wc_Des3_EcbEncrypt(void)
  16605. {
  16606. EXPECT_DECLS;
  16607. #if !defined(NO_DES3) && defined(WOLFSSL_DES_ECB)
  16608. Des3 des;
  16609. byte cipher[24];
  16610. word32 cipherSz = sizeof(cipher);
  16611. const byte key[] = {
  16612. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  16613. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  16614. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  16615. };
  16616. const byte iv[] = {
  16617. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  16618. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  16619. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  16620. };
  16621. const byte vector[] = { /* "Now is the time for all " w/o trailing 0 */
  16622. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  16623. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  16624. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  16625. };
  16626. XMEMSET(&des, 0, sizeof(Des3));
  16627. ExpectIntEQ(wc_Des3Init(&des, NULL, INVALID_DEVID), 0);
  16628. ExpectIntEQ(wc_Des3_SetKey(&des, key, iv, DES_ENCRYPTION), 0);
  16629. /* Bad Cases */
  16630. ExpectIntEQ(wc_Des3_EcbEncrypt(NULL, 0, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16631. ExpectIntEQ(wc_Des3_EcbEncrypt(NULL, cipher, vector, cipherSz),
  16632. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16633. ExpectIntEQ(wc_Des3_EcbEncrypt(&des, 0, vector, cipherSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16634. ExpectIntEQ(wc_Des3_EcbEncrypt(&des, cipher, NULL, cipherSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16635. ExpectIntEQ(wc_Des3_EcbEncrypt(&des, cipher, vector, 0), 0);
  16636. /* Good Cases */
  16637. ExpectIntEQ(wc_Des3_EcbEncrypt(&des, cipher, vector, cipherSz), 0);
  16638. wc_Des3Free(&des);
  16639. #endif
  16640. return EXPECT_RESULT();
  16641. } /* END test_wc_Des3_EcbEncrypt */
  16642. /*
  16643. * Testing wc_Chacha_SetKey() and wc_Chacha_SetIV()
  16644. */
  16645. static int test_wc_Chacha_SetKey(void)
  16646. {
  16647. EXPECT_DECLS;
  16648. #ifdef HAVE_CHACHA
  16649. ChaCha ctx;
  16650. const byte key[] = {
  16651. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16652. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16653. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16654. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  16655. };
  16656. word32 keySz = (word32)(sizeof(key)/sizeof(byte));
  16657. byte cipher[128];
  16658. XMEMSET(cipher, 0, sizeof(cipher));
  16659. ExpectIntEQ(wc_Chacha_SetKey(&ctx, key, keySz), 0);
  16660. /* Test bad args. */
  16661. ExpectIntEQ(wc_Chacha_SetKey(NULL, key, keySz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16662. ExpectIntEQ(wc_Chacha_SetKey(&ctx, key, 18), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16663. ExpectIntEQ(wc_Chacha_SetIV(&ctx, cipher, 0), 0);
  16664. /* Test bad args. */
  16665. ExpectIntEQ(wc_Chacha_SetIV(NULL, cipher, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16666. #endif
  16667. return EXPECT_RESULT();
  16668. } /* END test_wc_Chacha_SetKey */
  16669. /*
  16670. * unit test for wc_Poly1305SetKey()
  16671. */
  16672. static int test_wc_Poly1305SetKey(void)
  16673. {
  16674. EXPECT_DECLS;
  16675. #ifdef HAVE_POLY1305
  16676. Poly1305 ctx;
  16677. const byte key[] =
  16678. {
  16679. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16680. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16681. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16682. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  16683. };
  16684. word32 keySz = (word32)(sizeof(key)/sizeof(byte));
  16685. ExpectIntEQ(wc_Poly1305SetKey(&ctx, key, keySz), 0);
  16686. /* Test bad args. */
  16687. ExpectIntEQ(wc_Poly1305SetKey(NULL, key,keySz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16688. ExpectIntEQ(wc_Poly1305SetKey(&ctx, NULL, keySz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16689. ExpectIntEQ(wc_Poly1305SetKey(&ctx, key, 18), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16690. #endif
  16691. return EXPECT_RESULT();
  16692. } /* END test_wc_Poly1305_SetKey() */
  16693. /*
  16694. * Testing wc_Chacha_Process()
  16695. */
  16696. static int test_wc_Chacha_Process(void)
  16697. {
  16698. EXPECT_DECLS;
  16699. #ifdef HAVE_CHACHA
  16700. ChaCha enc, dec;
  16701. byte cipher[128];
  16702. byte plain[128];
  16703. const byte key[] =
  16704. {
  16705. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16706. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16707. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16708. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  16709. };
  16710. const char* input = "Everybody gets Friday off.";
  16711. word32 keySz = sizeof(key)/sizeof(byte);
  16712. unsigned long int inlen = XSTRLEN(input);
  16713. /* Initialize stack variables. */
  16714. XMEMSET(cipher, 0, 128);
  16715. XMEMSET(plain, 0, 128);
  16716. ExpectIntEQ(wc_Chacha_SetKey(&enc, key, keySz), 0);
  16717. ExpectIntEQ(wc_Chacha_SetKey(&dec, key, keySz), 0);
  16718. ExpectIntEQ(wc_Chacha_SetIV(&enc, cipher, 0), 0);
  16719. ExpectIntEQ(wc_Chacha_SetIV(&dec, cipher, 0), 0);
  16720. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, (byte*)input, (word32)inlen),
  16721. 0);
  16722. ExpectIntEQ(wc_Chacha_Process(&dec, plain, cipher, (word32)inlen), 0);
  16723. ExpectIntEQ(XMEMCMP(input, plain, inlen), 0);
  16724. #if !defined(USE_INTEL_CHACHA_SPEEDUP) && !defined(WOLFSSL_ARMASM)
  16725. /* test checking and using leftovers, currently just in C code */
  16726. ExpectIntEQ(wc_Chacha_SetIV(&enc, cipher, 0), 0);
  16727. ExpectIntEQ(wc_Chacha_SetIV(&dec, cipher, 0), 0);
  16728. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, (byte*)input,
  16729. (word32)inlen - 2), 0);
  16730. ExpectIntEQ(wc_Chacha_Process(&enc, cipher + (inlen - 2),
  16731. (byte*)input + (inlen - 2), 2), 0);
  16732. ExpectIntEQ(wc_Chacha_Process(&dec, plain, (byte*)cipher,
  16733. (word32)inlen - 2), 0);
  16734. ExpectIntEQ(wc_Chacha_Process(&dec, cipher + (inlen - 2),
  16735. (byte*)input + (inlen - 2), 2), 0);
  16736. ExpectIntEQ(XMEMCMP(input, plain, inlen), 0);
  16737. /* check edge cases with counter increment */
  16738. {
  16739. /* expected results collected from wolfSSL 4.3.0 encrypted in one call*/
  16740. const byte expected[] = {
  16741. 0x54,0xB1,0xE2,0xD4,0xA2,0x4D,0x52,0x5F,
  16742. 0x42,0x04,0x89,0x7C,0x6E,0x2D,0xFC,0x2D,
  16743. 0x10,0x25,0xB6,0x92,0x71,0xD5,0xC3,0x20,
  16744. 0xE3,0x0E,0xEC,0xF4,0xD8,0x10,0x70,0x29,
  16745. 0x2D,0x4C,0x2A,0x56,0x21,0xE1,0xC7,0x37,
  16746. 0x0B,0x86,0xF5,0x02,0x8C,0xB8,0xB8,0x38,
  16747. 0x41,0xFD,0xDF,0xD9,0xC3,0xE6,0xC8,0x88,
  16748. 0x06,0x82,0xD4,0x80,0x6A,0x50,0x69,0xD5,
  16749. 0xB9,0xB0,0x2F,0x44,0x36,0x5D,0xDA,0x5E,
  16750. 0xDE,0xF6,0xF5,0xFC,0x44,0xDC,0x07,0x51,
  16751. 0xA7,0x32,0x42,0xDB,0xCC,0xBD,0xE2,0xE5,
  16752. 0x0B,0xB1,0x14,0xFF,0x12,0x80,0x16,0x43,
  16753. 0xE7,0x40,0xD5,0xEA,0xC7,0x3F,0x69,0x07,
  16754. 0x64,0xD4,0x86,0x6C,0xE2,0x1F,0x8F,0x6E,
  16755. 0x35,0x41,0xE7,0xD3,0xB5,0x5D,0xD6,0xD4,
  16756. 0x9F,0x00,0xA9,0xAE,0x3D,0x28,0xA5,0x37,
  16757. 0x80,0x3D,0x11,0x25,0xE2,0xB6,0x99,0xD9,
  16758. 0x9B,0x98,0xE9,0x37,0xB9,0xF8,0xA0,0x04,
  16759. 0xDF,0x13,0x49,0x3F,0x19,0x6A,0x45,0x06,
  16760. 0x21,0xB4,0xC7,0x3B,0x49,0x45,0xB4,0xC8,
  16761. 0x03,0x5B,0x43,0x89,0xBD,0xB3,0x96,0x4B,
  16762. 0x17,0x6F,0x85,0xC6,0xCF,0xA6,0x05,0x35,
  16763. 0x1E,0x25,0x03,0xBB,0x55,0x0A,0xD5,0x54,
  16764. 0x41,0xEA,0xEB,0x50,0x40,0x1B,0x43,0x19,
  16765. 0x59,0x1B,0x0E,0x12,0x3E,0xA2,0x71,0xC3,
  16766. 0x1A,0xA7,0x11,0x50,0x43,0x9D,0x56,0x3B,
  16767. 0x63,0x2F,0x63,0xF1,0x8D,0xAE,0xF3,0x23,
  16768. 0xFA,0x1E,0xD8,0x6A,0xE1,0xB2,0x4B,0xF3,
  16769. 0xB9,0x13,0x7A,0x72,0x2B,0x6D,0xCC,0x41,
  16770. 0x1C,0x69,0x7C,0xCD,0x43,0x6F,0xE4,0xE2,
  16771. 0x38,0x99,0xFB,0xC3,0x38,0x92,0x62,0x35,
  16772. 0xC0,0x1D,0x60,0xE4,0x4B,0xDD,0x0C,0x14
  16773. };
  16774. const byte iv2[] = {
  16775. 0x9D,0xED,0xE7,0x0F,0xEC,0x81,0x51,0xD9,
  16776. 0x77,0x39,0x71,0xA6,0x21,0xDF,0xB8,0x93
  16777. };
  16778. byte input2[256];
  16779. int i;
  16780. for (i = 0; i < 256; i++)
  16781. input2[i] = (byte)i;
  16782. ExpectIntEQ(wc_Chacha_SetIV(&enc, iv2, 0), 0);
  16783. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, input2, 64), 0);
  16784. ExpectIntEQ(XMEMCMP(expected, cipher, 64), 0);
  16785. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, input2 + 64, 128), 0);
  16786. ExpectIntEQ(XMEMCMP(expected + 64, cipher, 128), 0);
  16787. /* partial */
  16788. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, input2 + 192, 32), 0);
  16789. ExpectIntEQ(XMEMCMP(expected + 192, cipher, 32), 0);
  16790. ExpectIntEQ(wc_Chacha_Process(&enc, cipher, input2 + 224, 32), 0);
  16791. ExpectIntEQ(XMEMCMP(expected + 224, cipher, 32), 0);
  16792. }
  16793. #endif
  16794. /* Test bad args. */
  16795. ExpectIntEQ(wc_Chacha_Process(NULL, cipher, (byte*)input, (word32)inlen),
  16796. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16797. #endif
  16798. return EXPECT_RESULT();
  16799. } /* END test_wc_Chacha_Process */
  16800. /*
  16801. * Testing wc_ChaCha20Poly1305_Encrypt() and wc_ChaCha20Poly1305_Decrypt()
  16802. */
  16803. static int test_wc_ChaCha20Poly1305_aead(void)
  16804. {
  16805. EXPECT_DECLS;
  16806. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  16807. const byte key[] = {
  16808. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  16809. 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  16810. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
  16811. 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f
  16812. };
  16813. const byte plaintext[] = {
  16814. 0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61,
  16815. 0x6e, 0x64, 0x20, 0x47, 0x65, 0x6e, 0x74, 0x6c,
  16816. 0x65, 0x6d, 0x65, 0x6e, 0x20, 0x6f, 0x66, 0x20,
  16817. 0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73,
  16818. 0x73, 0x20, 0x6f, 0x66, 0x20, 0x27, 0x39, 0x39,
  16819. 0x3a, 0x20, 0x49, 0x66, 0x20, 0x49, 0x20, 0x63,
  16820. 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x6f, 0x66, 0x66,
  16821. 0x65, 0x72, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6f,
  16822. 0x6e, 0x6c, 0x79, 0x20, 0x6f, 0x6e, 0x65, 0x20,
  16823. 0x74, 0x69, 0x70, 0x20, 0x66, 0x6f, 0x72, 0x20,
  16824. 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x74, 0x75,
  16825. 0x72, 0x65, 0x2c, 0x20, 0x73, 0x75, 0x6e, 0x73,
  16826. 0x63, 0x72, 0x65, 0x65, 0x6e, 0x20, 0x77, 0x6f,
  16827. 0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, 0x20, 0x69,
  16828. 0x74, 0x2e
  16829. };
  16830. const byte iv[] = {
  16831. 0x07, 0x00, 0x00, 0x00, 0x40, 0x41, 0x42, 0x43,
  16832. 0x44, 0x45, 0x46, 0x47
  16833. };
  16834. const byte aad[] = { /* additional data */
  16835. 0x50, 0x51, 0x52, 0x53, 0xc0, 0xc1, 0xc2, 0xc3,
  16836. 0xc4, 0xc5, 0xc6, 0xc7
  16837. };
  16838. const byte cipher[] = { /* expected output from operation */
  16839. 0xd3, 0x1a, 0x8d, 0x34, 0x64, 0x8e, 0x60, 0xdb,
  16840. 0x7b, 0x86, 0xaf, 0xbc, 0x53, 0xef, 0x7e, 0xc2,
  16841. 0xa4, 0xad, 0xed, 0x51, 0x29, 0x6e, 0x08, 0xfe,
  16842. 0xa9, 0xe2, 0xb5, 0xa7, 0x36, 0xee, 0x62, 0xd6,
  16843. 0x3d, 0xbe, 0xa4, 0x5e, 0x8c, 0xa9, 0x67, 0x12,
  16844. 0x82, 0xfa, 0xfb, 0x69, 0xda, 0x92, 0x72, 0x8b,
  16845. 0x1a, 0x71, 0xde, 0x0a, 0x9e, 0x06, 0x0b, 0x29,
  16846. 0x05, 0xd6, 0xa5, 0xb6, 0x7e, 0xcd, 0x3b, 0x36,
  16847. 0x92, 0xdd, 0xbd, 0x7f, 0x2d, 0x77, 0x8b, 0x8c,
  16848. 0x98, 0x03, 0xae, 0xe3, 0x28, 0x09, 0x1b, 0x58,
  16849. 0xfa, 0xb3, 0x24, 0xe4, 0xfa, 0xd6, 0x75, 0x94,
  16850. 0x55, 0x85, 0x80, 0x8b, 0x48, 0x31, 0xd7, 0xbc,
  16851. 0x3f, 0xf4, 0xde, 0xf0, 0x8e, 0x4b, 0x7a, 0x9d,
  16852. 0xe5, 0x76, 0xd2, 0x65, 0x86, 0xce, 0xc6, 0x4b,
  16853. 0x61, 0x16
  16854. };
  16855. const byte authTag[] = { /* expected output from operation */
  16856. 0x1a, 0xe1, 0x0b, 0x59, 0x4f, 0x09, 0xe2, 0x6a,
  16857. 0x7e, 0x90, 0x2e, 0xcb, 0xd0, 0x60, 0x06, 0x91
  16858. };
  16859. byte generatedCiphertext[272];
  16860. byte generatedPlaintext[272];
  16861. byte generatedAuthTag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE];
  16862. /* Initialize stack variables. */
  16863. XMEMSET(generatedCiphertext, 0, 272);
  16864. XMEMSET(generatedPlaintext, 0, 272);
  16865. /* Test Encrypt */
  16866. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, iv, aad, sizeof(aad),
  16867. plaintext, sizeof(plaintext), generatedCiphertext, generatedAuthTag),
  16868. 0);
  16869. ExpectIntEQ(XMEMCMP(generatedCiphertext, cipher,
  16870. sizeof(cipher)/sizeof(byte)), 0);
  16871. /* Test bad args. */
  16872. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(NULL, iv, aad, sizeof(aad),
  16873. plaintext, sizeof(plaintext), generatedCiphertext, generatedAuthTag),
  16874. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16875. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, NULL, aad, sizeof(aad),
  16876. plaintext, sizeof(plaintext), generatedCiphertext, generatedAuthTag),
  16877. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16878. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, iv, aad, sizeof(aad), NULL,
  16879. sizeof(plaintext), generatedCiphertext, generatedAuthTag),
  16880. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16881. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, iv, aad, sizeof(aad),
  16882. NULL, sizeof(plaintext), generatedCiphertext, generatedAuthTag),
  16883. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16884. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, iv, aad, sizeof(aad),
  16885. plaintext, sizeof(plaintext), NULL, generatedAuthTag), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16886. ExpectIntEQ(wc_ChaCha20Poly1305_Encrypt(key, iv, aad, sizeof(aad),
  16887. plaintext, sizeof(plaintext), generatedCiphertext, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16888. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, iv, aad, sizeof(aad), cipher,
  16889. sizeof(cipher), authTag, generatedPlaintext), 0);
  16890. ExpectIntEQ(XMEMCMP(generatedPlaintext, plaintext,
  16891. sizeof(plaintext)/sizeof(byte)), 0);
  16892. /* Test bad args. */
  16893. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(NULL, iv, aad, sizeof(aad), cipher,
  16894. sizeof(cipher), authTag, generatedPlaintext), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16895. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, NULL, aad, sizeof(aad),
  16896. cipher, sizeof(cipher), authTag, generatedPlaintext), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16897. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, iv, aad, sizeof(aad), NULL,
  16898. sizeof(cipher), authTag, generatedPlaintext), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16899. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, iv, aad, sizeof(aad), cipher,
  16900. sizeof(cipher), NULL, generatedPlaintext), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16901. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, iv, aad, sizeof(aad), cipher,
  16902. sizeof(cipher), authTag, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16903. ExpectIntEQ(wc_ChaCha20Poly1305_Decrypt(key, iv, aad, sizeof(aad), NULL,
  16904. sizeof(cipher), authTag, generatedPlaintext), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16905. #endif
  16906. return EXPECT_RESULT();
  16907. } /* END test_wc_ChaCha20Poly1305_aead */
  16908. /*
  16909. * Testing function for wc_Rc2SetKey().
  16910. */
  16911. static int test_wc_Rc2SetKey(void)
  16912. {
  16913. EXPECT_DECLS;
  16914. #ifdef WC_RC2
  16915. Rc2 rc2;
  16916. byte key40[] = { 0x01, 0x02, 0x03, 0x04, 0x05 };
  16917. byte iv[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
  16918. /* valid key and IV */
  16919. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, (word32) sizeof(key40) / sizeof(byte),
  16920. iv, 40), 0);
  16921. /* valid key, no IV */
  16922. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, (word32) sizeof(key40) / sizeof(byte),
  16923. NULL, 40), 0);
  16924. /* bad arguments */
  16925. /* null Rc2 struct */
  16926. ExpectIntEQ(wc_Rc2SetKey(NULL, key40, (word32) sizeof(key40) / sizeof(byte),
  16927. iv, 40), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16928. /* null key */
  16929. ExpectIntEQ(wc_Rc2SetKey(&rc2, NULL, (word32) sizeof(key40) / sizeof(byte),
  16930. iv, 40), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16931. /* key size == 0 */
  16932. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, 0, iv, 40), WC_NO_ERR_TRACE(WC_KEY_SIZE_E));
  16933. /* key size > 128 */
  16934. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, 129, iv, 40), WC_NO_ERR_TRACE(WC_KEY_SIZE_E));
  16935. /* effective bits == 0 */
  16936. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, (word32)sizeof(key40) / sizeof(byte),
  16937. iv, 0), WC_NO_ERR_TRACE(WC_KEY_SIZE_E));
  16938. /* effective bits > 1024 */
  16939. ExpectIntEQ(wc_Rc2SetKey(&rc2, key40, (word32)sizeof(key40) / sizeof(byte),
  16940. iv, 1025), WC_NO_ERR_TRACE(WC_KEY_SIZE_E));
  16941. #endif
  16942. return EXPECT_RESULT();
  16943. } /* END test_wc_Rc2SetKey */
  16944. /*
  16945. * Testing function for wc_Rc2SetIV().
  16946. */
  16947. static int test_wc_Rc2SetIV(void)
  16948. {
  16949. EXPECT_DECLS;
  16950. #ifdef WC_RC2
  16951. Rc2 rc2;
  16952. byte iv[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
  16953. /* valid IV */
  16954. ExpectIntEQ(wc_Rc2SetIV(&rc2, iv), 0);
  16955. /* valid NULL IV */
  16956. ExpectIntEQ(wc_Rc2SetIV(&rc2, NULL), 0);
  16957. /* bad arguments */
  16958. ExpectIntEQ(wc_Rc2SetIV(NULL, iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16959. ExpectIntEQ(wc_Rc2SetIV(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16960. #endif
  16961. return EXPECT_RESULT();
  16962. } /* END test_wc_Rc2SetIV */
  16963. /*
  16964. * Testing function for wc_Rc2EcbEncrypt() and wc_Rc2EcbDecrypt().
  16965. */
  16966. static int test_wc_Rc2EcbEncryptDecrypt(void)
  16967. {
  16968. EXPECT_DECLS;
  16969. #ifdef WC_RC2
  16970. Rc2 rc2;
  16971. int effectiveKeyBits = 63;
  16972. byte cipher[RC2_BLOCK_SIZE];
  16973. byte plain[RC2_BLOCK_SIZE];
  16974. byte key[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  16975. byte input[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  16976. byte output[] = { 0xeb, 0xb7, 0x73, 0xf9, 0x93, 0x27, 0x8e, 0xff };
  16977. XMEMSET(cipher, 0, sizeof(cipher));
  16978. XMEMSET(plain, 0, sizeof(plain));
  16979. ExpectIntEQ(wc_Rc2SetKey(&rc2, key, (word32) sizeof(key) / sizeof(byte),
  16980. NULL, effectiveKeyBits), 0);
  16981. ExpectIntEQ(wc_Rc2EcbEncrypt(&rc2, cipher, input, RC2_BLOCK_SIZE), 0);
  16982. ExpectIntEQ(XMEMCMP(cipher, output, RC2_BLOCK_SIZE), 0);
  16983. ExpectIntEQ(wc_Rc2EcbDecrypt(&rc2, plain, cipher, RC2_BLOCK_SIZE), 0);
  16984. ExpectIntEQ(XMEMCMP(plain, input, RC2_BLOCK_SIZE), 0);
  16985. /* Rc2EcbEncrypt bad arguments */
  16986. /* null Rc2 struct */
  16987. ExpectIntEQ(wc_Rc2EcbEncrypt(NULL, cipher, input, RC2_BLOCK_SIZE),
  16988. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16989. /* null out buffer */
  16990. ExpectIntEQ(wc_Rc2EcbEncrypt(&rc2, NULL, input, RC2_BLOCK_SIZE),
  16991. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16992. /* null input buffer */
  16993. ExpectIntEQ(wc_Rc2EcbEncrypt(&rc2, cipher, NULL, RC2_BLOCK_SIZE),
  16994. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  16995. /* output buffer sz != RC2_BLOCK_SIZE (8) */
  16996. ExpectIntEQ(wc_Rc2EcbEncrypt(&rc2, cipher, input, 7), WC_NO_ERR_TRACE(BUFFER_E));
  16997. /* Rc2EcbDecrypt bad arguments */
  16998. /* null Rc2 struct */
  16999. ExpectIntEQ(wc_Rc2EcbDecrypt(NULL, plain, output, RC2_BLOCK_SIZE),
  17000. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17001. /* null out buffer */
  17002. ExpectIntEQ(wc_Rc2EcbDecrypt(&rc2, NULL, output, RC2_BLOCK_SIZE),
  17003. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17004. /* null input buffer */
  17005. ExpectIntEQ(wc_Rc2EcbDecrypt(&rc2, plain, NULL, RC2_BLOCK_SIZE),
  17006. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17007. /* output buffer sz != RC2_BLOCK_SIZE (8) */
  17008. ExpectIntEQ(wc_Rc2EcbDecrypt(&rc2, plain, output, 7), WC_NO_ERR_TRACE(BUFFER_E));
  17009. #endif
  17010. return EXPECT_RESULT();
  17011. } /* END test_wc_Rc2EcbEncryptDecrypt */
  17012. /*
  17013. * Testing function for wc_Rc2CbcEncrypt() and wc_Rc2CbcDecrypt().
  17014. */
  17015. static int test_wc_Rc2CbcEncryptDecrypt(void)
  17016. {
  17017. EXPECT_DECLS;
  17018. #ifdef WC_RC2
  17019. Rc2 rc2;
  17020. int effectiveKeyBits = 63;
  17021. byte cipher[RC2_BLOCK_SIZE*2];
  17022. byte plain[RC2_BLOCK_SIZE*2];
  17023. /* vector taken from test.c */
  17024. byte key[] = {
  17025. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  17026. };
  17027. byte iv[] = {
  17028. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  17029. };
  17030. byte input[] = {
  17031. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  17032. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  17033. };
  17034. byte output[] = {
  17035. 0xeb, 0xb7, 0x73, 0xf9, 0x93, 0x27, 0x8e, 0xff,
  17036. 0xf0, 0x51, 0x77, 0x8b, 0x65, 0xdb, 0x13, 0x57
  17037. };
  17038. XMEMSET(cipher, 0, sizeof(cipher));
  17039. XMEMSET(plain, 0, sizeof(plain));
  17040. ExpectIntEQ(wc_Rc2SetKey(&rc2, key, (word32) sizeof(key) / sizeof(byte),
  17041. iv, effectiveKeyBits), 0);
  17042. ExpectIntEQ(wc_Rc2CbcEncrypt(&rc2, cipher, input, sizeof(input)), 0);
  17043. ExpectIntEQ(XMEMCMP(cipher, output, sizeof(output)), 0);
  17044. /* reset IV for decrypt */
  17045. ExpectIntEQ(wc_Rc2SetIV(&rc2, iv), 0);
  17046. ExpectIntEQ(wc_Rc2CbcDecrypt(&rc2, plain, cipher, sizeof(cipher)), 0);
  17047. ExpectIntEQ(XMEMCMP(plain, input, sizeof(input)), 0);
  17048. /* Rc2CbcEncrypt bad arguments */
  17049. /* null Rc2 struct */
  17050. ExpectIntEQ(wc_Rc2CbcEncrypt(NULL, cipher, input, sizeof(input)),
  17051. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17052. /* null out buffer */
  17053. ExpectIntEQ(wc_Rc2CbcEncrypt(&rc2, NULL, input, sizeof(input)),
  17054. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17055. /* null input buffer */
  17056. ExpectIntEQ(wc_Rc2CbcEncrypt(&rc2, cipher, NULL, sizeof(input)),
  17057. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17058. /* Rc2CbcDecrypt bad arguments */
  17059. /* in size is 0 */
  17060. ExpectIntEQ(wc_Rc2CbcDecrypt(&rc2, plain, output, 0), 0);
  17061. /* null Rc2 struct */
  17062. ExpectIntEQ(wc_Rc2CbcDecrypt(NULL, plain, output, sizeof(output)),
  17063. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17064. /* null out buffer */
  17065. ExpectIntEQ(wc_Rc2CbcDecrypt(&rc2, NULL, output, sizeof(output)),
  17066. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17067. /* null input buffer */
  17068. ExpectIntEQ(wc_Rc2CbcDecrypt(&rc2, plain, NULL, sizeof(output)),
  17069. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17070. #endif
  17071. return EXPECT_RESULT();
  17072. } /* END test_wc_Rc2CbcEncryptDecrypt */
  17073. /*
  17074. * Testing function for wc_AesSetIV
  17075. */
  17076. static int test_wc_AesSetIV(void)
  17077. {
  17078. int res = TEST_SKIPPED;
  17079. #if !defined(NO_AES) && defined(WOLFSSL_AES_128)
  17080. Aes aes;
  17081. int ret = 0;
  17082. byte key16[] =
  17083. {
  17084. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17085. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17086. };
  17087. byte iv1[] = "1234567890abcdef";
  17088. byte iv2[] = "0987654321fedcba";
  17089. ret = wc_AesInit(&aes, NULL, INVALID_DEVID);
  17090. if (ret != 0)
  17091. return ret;
  17092. ret = wc_AesSetKey(&aes, key16, (word32) sizeof(key16) / sizeof(byte),
  17093. iv1, AES_ENCRYPTION);
  17094. if (ret == 0) {
  17095. ret = wc_AesSetIV(&aes, iv2);
  17096. }
  17097. /* Test bad args. */
  17098. if (ret == 0) {
  17099. ret = wc_AesSetIV(NULL, iv1);
  17100. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17101. /* NULL iv should return 0. */
  17102. ret = wc_AesSetIV(&aes, NULL);
  17103. }
  17104. else {
  17105. ret = WOLFSSL_FATAL_ERROR;
  17106. }
  17107. }
  17108. wc_AesFree(&aes);
  17109. res = TEST_RES_CHECK(ret == 0);
  17110. #endif
  17111. return res;
  17112. } /* test_wc_AesSetIV */
  17113. /*
  17114. * Testing function for wc_AesSetKey().
  17115. */
  17116. static int test_wc_AesSetKey(void)
  17117. {
  17118. EXPECT_DECLS;
  17119. #ifndef NO_AES
  17120. Aes aes;
  17121. byte key16[] = {
  17122. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17123. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17124. };
  17125. #ifdef WOLFSSL_AES_192
  17126. byte key24[] = {
  17127. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17128. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17129. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
  17130. };
  17131. #endif
  17132. #ifdef WOLFSSL_AES_256
  17133. byte key32[] = {
  17134. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17135. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17136. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17137. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17138. };
  17139. #endif
  17140. byte badKey16[] = {
  17141. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17142. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65
  17143. };
  17144. byte iv[] = "1234567890abcdef";
  17145. XMEMSET(&aes, 0, sizeof(Aes));
  17146. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  17147. #ifdef WOLFSSL_AES_128
  17148. ExpectIntEQ(wc_AesSetKey(&aes, key16, (word32)sizeof(key16) / sizeof(byte),
  17149. iv, AES_ENCRYPTION), 0);
  17150. #endif
  17151. #ifdef WOLFSSL_AES_192
  17152. ExpectIntEQ(wc_AesSetKey(&aes, key24, (word32)sizeof(key24) / sizeof(byte),
  17153. iv, AES_ENCRYPTION), 0);
  17154. #endif
  17155. #ifdef WOLFSSL_AES_256
  17156. ExpectIntEQ(wc_AesSetKey(&aes, key32, (word32)sizeof(key32) / sizeof(byte),
  17157. iv, AES_ENCRYPTION), 0);
  17158. #endif
  17159. /* Pass in bad args. */
  17160. ExpectIntEQ(wc_AesSetKey(NULL, key16, (word32)sizeof(key16) / sizeof(byte),
  17161. iv, AES_ENCRYPTION), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17162. ExpectIntEQ(wc_AesSetKey(&aes, badKey16,
  17163. (word32)sizeof(badKey16) / sizeof(byte), iv, AES_ENCRYPTION),
  17164. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17165. wc_AesFree(&aes);
  17166. #endif
  17167. return EXPECT_RESULT();
  17168. } /* END test_wc_AesSetKey */
  17169. /*
  17170. * test function for wc_AesCbcEncrypt(), wc_AesCbcDecrypt(),
  17171. * and wc_AesCbcDecryptWithKey()
  17172. */
  17173. static int test_wc_AesCbcEncryptDecrypt(void)
  17174. {
  17175. EXPECT_DECLS;
  17176. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(HAVE_AES_DECRYPT)&& \
  17177. defined(WOLFSSL_AES_256)
  17178. Aes aes;
  17179. byte key32[] = {
  17180. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17181. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17182. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17183. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17184. };
  17185. byte vector[] = { /* Now is the time for all good men w/o trailing 0 */
  17186. 0x4e, 0x6f, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74,
  17187. 0x68, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20,
  17188. 0x66, 0x6f, 0x72, 0x20, 0x61, 0x6c, 0x6c, 0x20,
  17189. 0x67, 0x6f, 0x6f, 0x64, 0x20, 0x6d, 0x65, 0x6e
  17190. };
  17191. byte iv[] = "1234567890abcdef";
  17192. byte enc[sizeof(vector)];
  17193. byte dec[sizeof(vector)];
  17194. byte dec2[sizeof(vector)];
  17195. /* Init stack variables. */
  17196. XMEMSET(&aes, 0, sizeof(Aes));
  17197. XMEMSET(enc, 0, sizeof(enc));
  17198. XMEMSET(dec, 0, sizeof(vector));
  17199. XMEMSET(dec2, 0, sizeof(vector));
  17200. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  17201. ExpectIntEQ(wc_AesSetKey(&aes, key32, AES_BLOCK_SIZE * 2, iv,
  17202. AES_ENCRYPTION), 0);
  17203. ExpectIntEQ(wc_AesCbcEncrypt(&aes, enc, vector, sizeof(vector)), 0);
  17204. /* Re init for decrypt and set flag. */
  17205. ExpectIntEQ(wc_AesSetKey(&aes, key32, AES_BLOCK_SIZE * 2, iv,
  17206. AES_DECRYPTION), 0);
  17207. ExpectIntEQ(wc_AesCbcDecrypt(&aes, dec, enc, sizeof(vector)), 0);
  17208. ExpectIntEQ(XMEMCMP(vector, dec, sizeof(vector)), 0);
  17209. ExpectIntEQ(wc_AesCbcDecryptWithKey(dec2, enc, AES_BLOCK_SIZE, key32,
  17210. sizeof(key32)/sizeof(byte), iv), 0);
  17211. ExpectIntEQ(XMEMCMP(vector, dec2, AES_BLOCK_SIZE), 0);
  17212. /* Pass in bad args */
  17213. ExpectIntEQ(wc_AesCbcEncrypt(NULL, enc, vector, sizeof(vector)),
  17214. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17215. ExpectIntEQ(wc_AesCbcEncrypt(&aes, NULL, vector, sizeof(vector)),
  17216. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17217. ExpectIntEQ(wc_AesCbcEncrypt(&aes, enc, NULL, sizeof(vector)),
  17218. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17219. #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS
  17220. ExpectIntEQ(wc_AesCbcEncrypt(&aes, enc, vector, sizeof(vector) - 1),
  17221. WC_NO_ERR_TRACE(BAD_LENGTH_E));
  17222. #endif
  17223. #if defined(HAVE_FIPS) && defined(HAVE_FIPS_VERSION) && \
  17224. (HAVE_FIPS_VERSION == 2) && defined(WOLFSSL_AESNI)
  17225. fprintf(stderr, "Zero length inputs not supported with AESNI in FIPS "
  17226. "mode (v2), skip test");
  17227. #else
  17228. /* Test passing in size of 0 */
  17229. XMEMSET(enc, 0, sizeof(enc));
  17230. ExpectIntEQ(wc_AesCbcEncrypt(&aes, enc, vector, 0), 0);
  17231. /* Check enc was not modified */
  17232. {
  17233. int i;
  17234. for (i = 0; i < (int)sizeof(enc); i++)
  17235. ExpectIntEQ(enc[i], 0);
  17236. }
  17237. #endif
  17238. ExpectIntEQ(wc_AesCbcDecrypt(NULL, dec, enc, AES_BLOCK_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17239. ExpectIntEQ(wc_AesCbcDecrypt(&aes, NULL, enc, AES_BLOCK_SIZE),
  17240. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17241. ExpectIntEQ(wc_AesCbcDecrypt(&aes, dec, NULL, AES_BLOCK_SIZE),
  17242. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17243. #ifdef WOLFSSL_AES_CBC_LENGTH_CHECKS
  17244. ExpectIntEQ(wc_AesCbcDecrypt(&aes, dec, enc, AES_BLOCK_SIZE * 2 - 1),
  17245. WC_NO_ERR_TRACE(BAD_LENGTH_E));
  17246. #else
  17247. ExpectIntEQ(wc_AesCbcDecrypt(&aes, dec, enc, AES_BLOCK_SIZE * 2 - 1),
  17248. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17249. #endif
  17250. /* Test passing in size of 0 */
  17251. XMEMSET(dec, 0, sizeof(dec));
  17252. ExpectIntEQ(wc_AesCbcDecrypt(&aes, dec, enc, 0), 0);
  17253. /* Check dec was not modified */
  17254. {
  17255. int i;
  17256. for (i = 0; i < (int)sizeof(dec); i++)
  17257. ExpectIntEQ(dec[i], 0);
  17258. }
  17259. ExpectIntEQ(wc_AesCbcDecryptWithKey(NULL, enc, AES_BLOCK_SIZE,
  17260. key32, sizeof(key32)/sizeof(byte), iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17261. ExpectIntEQ(wc_AesCbcDecryptWithKey(dec2, NULL, AES_BLOCK_SIZE,
  17262. key32, sizeof(key32)/sizeof(byte), iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17263. ExpectIntEQ(wc_AesCbcDecryptWithKey(dec2, enc, AES_BLOCK_SIZE,
  17264. NULL, sizeof(key32)/sizeof(byte), iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17265. ExpectIntEQ(wc_AesCbcDecryptWithKey(dec2, enc, AES_BLOCK_SIZE,
  17266. key32, sizeof(key32)/sizeof(byte), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17267. wc_AesFree(&aes);
  17268. #endif
  17269. return EXPECT_RESULT();
  17270. } /* END test_wc_AesCbcEncryptDecrypt */
  17271. /*
  17272. * Testing wc_AesCtrEncrypt and wc_AesCtrDecrypt
  17273. */
  17274. static int test_wc_AesCtrEncryptDecrypt(void)
  17275. {
  17276. EXPECT_DECLS;
  17277. #if !defined(NO_AES) && defined(WOLFSSL_AES_COUNTER) && defined(WOLFSSL_AES_256)
  17278. Aes aesEnc;
  17279. Aes aesDec;
  17280. byte key32[] = {
  17281. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17282. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17283. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17284. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17285. };
  17286. byte vector[] = { /* Now is the time for all w/o trailing 0 */
  17287. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  17288. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  17289. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  17290. };
  17291. byte iv[] = "1234567890abcdef";
  17292. byte enc[AES_BLOCK_SIZE * 2];
  17293. byte dec[AES_BLOCK_SIZE * 2];
  17294. /* Init stack variables. */
  17295. XMEMSET(&aesEnc, 0, sizeof(Aes));
  17296. XMEMSET(&aesDec, 0, sizeof(Aes));
  17297. XMEMSET(enc, 0, AES_BLOCK_SIZE * 2);
  17298. XMEMSET(dec, 0, AES_BLOCK_SIZE * 2);
  17299. ExpectIntEQ(wc_AesInit(&aesEnc, NULL, INVALID_DEVID), 0);
  17300. ExpectIntEQ(wc_AesInit(&aesDec, NULL, INVALID_DEVID), 0);
  17301. ExpectIntEQ(wc_AesSetKey(&aesEnc, key32, AES_BLOCK_SIZE * 2, iv,
  17302. AES_ENCRYPTION), 0);
  17303. ExpectIntEQ(wc_AesCtrEncrypt(&aesEnc, enc, vector,
  17304. sizeof(vector)/sizeof(byte)), 0);
  17305. /* Decrypt with wc_AesCtrEncrypt() */
  17306. ExpectIntEQ(wc_AesSetKey(&aesDec, key32, AES_BLOCK_SIZE * 2, iv,
  17307. AES_ENCRYPTION), 0);
  17308. ExpectIntEQ(wc_AesCtrEncrypt(&aesDec, dec, enc, sizeof(enc)/sizeof(byte)),
  17309. 0);
  17310. ExpectIntEQ(XMEMCMP(vector, dec, sizeof(vector)), 0);
  17311. /* Test bad args. */
  17312. ExpectIntEQ(wc_AesCtrEncrypt(NULL, dec, enc, sizeof(enc)/sizeof(byte)),
  17313. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17314. ExpectIntEQ(wc_AesCtrEncrypt(&aesDec, NULL, enc, sizeof(enc)/sizeof(byte)),
  17315. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17316. ExpectIntEQ(wc_AesCtrEncrypt(&aesDec, dec, NULL, sizeof(enc)/sizeof(byte)),
  17317. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17318. wc_AesFree(&aesEnc);
  17319. wc_AesFree(&aesDec);
  17320. #endif
  17321. return EXPECT_RESULT();
  17322. } /* END test_wc_AesCtrEncryptDecrypt */
  17323. /*
  17324. * test function for wc_AesGcmSetKey()
  17325. */
  17326. static int test_wc_AesGcmSetKey(void)
  17327. {
  17328. EXPECT_DECLS;
  17329. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  17330. Aes aes;
  17331. #ifdef WOLFSSL_AES_128
  17332. byte key16[] = {
  17333. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17334. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17335. };
  17336. #endif
  17337. #ifdef WOLFSSL_AES_192
  17338. byte key24[] = {
  17339. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17340. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17341. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
  17342. };
  17343. #endif
  17344. #ifdef WOLFSSL_AES_256
  17345. byte key32[] = {
  17346. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17347. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17348. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17349. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17350. };
  17351. #endif
  17352. byte badKey16[] = {
  17353. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17354. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65
  17355. };
  17356. byte badKey24[] = {
  17357. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17358. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17359. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36
  17360. };
  17361. byte badKey32[] = {
  17362. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x37, 0x37,
  17363. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17364. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17365. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65
  17366. };
  17367. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  17368. #ifdef WOLFSSL_AES_128
  17369. ExpectIntEQ(wc_AesGcmSetKey(&aes, key16, sizeof(key16)/sizeof(byte)), 0);
  17370. #endif
  17371. #ifdef WOLFSSL_AES_192
  17372. ExpectIntEQ(wc_AesGcmSetKey(&aes, key24, sizeof(key24)/sizeof(byte)), 0);
  17373. #endif
  17374. #ifdef WOLFSSL_AES_256
  17375. ExpectIntEQ(wc_AesGcmSetKey(&aes, key32, sizeof(key32)/sizeof(byte)), 0);
  17376. #endif
  17377. /* Pass in bad args. */
  17378. ExpectIntEQ(wc_AesGcmSetKey(&aes, badKey16, sizeof(badKey16)/sizeof(byte)),
  17379. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17380. ExpectIntEQ(wc_AesGcmSetKey(&aes, badKey24, sizeof(badKey24)/sizeof(byte)),
  17381. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17382. ExpectIntEQ(wc_AesGcmSetKey(&aes, badKey32, sizeof(badKey32)/sizeof(byte)),
  17383. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17384. wc_AesFree(&aes);
  17385. #endif
  17386. return EXPECT_RESULT();
  17387. } /* END test_wc_AesGcmSetKey */
  17388. /*
  17389. * test function for wc_AesGcmEncrypt and wc_AesGcmDecrypt
  17390. */
  17391. static int test_wc_AesGcmEncryptDecrypt(void)
  17392. {
  17393. EXPECT_DECLS;
  17394. /* WOLFSSL_AFALG requires 12 byte IV */
  17395. #if !defined(NO_AES) && defined(HAVE_AESGCM) && defined(WOLFSSL_AES_256) && \
  17396. !defined(WOLFSSL_AFALG) && !defined(WOLFSSL_DEVCRYPTO_AES)
  17397. Aes aes;
  17398. byte key32[] = {
  17399. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17400. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17401. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17402. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17403. };
  17404. byte vector[] = { /* Now is the time for all w/o trailing 0 */
  17405. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  17406. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  17407. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  17408. };
  17409. const byte a[] = {
  17410. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  17411. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  17412. 0xab, 0xad, 0xda, 0xd2
  17413. };
  17414. byte iv[] = "1234567890a";
  17415. byte longIV[] = "1234567890abcdefghij";
  17416. byte enc[sizeof(vector)];
  17417. byte resultT[AES_BLOCK_SIZE];
  17418. byte dec[sizeof(vector)];
  17419. /* Init stack variables. */
  17420. XMEMSET(&aes, 0, sizeof(Aes));
  17421. XMEMSET(enc, 0, sizeof(vector));
  17422. XMEMSET(dec, 0, sizeof(vector));
  17423. XMEMSET(resultT, 0, AES_BLOCK_SIZE);
  17424. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  17425. ExpectIntEQ(wc_AesGcmSetKey(&aes, key32, sizeof(key32)/sizeof(byte)), 0);
  17426. ExpectIntEQ(wc_AesGcmEncrypt(&aes, enc, vector, sizeof(vector), iv,
  17427. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)), 0);
  17428. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(vector), iv,
  17429. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)), 0);
  17430. ExpectIntEQ(XMEMCMP(vector, dec, sizeof(vector)), 0);
  17431. /* Test bad args for wc_AesGcmEncrypt and wc_AesGcmDecrypt */
  17432. ExpectIntEQ(wc_AesGcmEncrypt(NULL, enc, vector, sizeof(vector), iv,
  17433. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  17434. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17435. ExpectIntEQ(wc_AesGcmEncrypt(&aes, enc, vector, sizeof(vector), iv,
  17436. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT) + 1, a, sizeof(a)),
  17437. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17438. ExpectIntEQ(wc_AesGcmEncrypt(&aes, enc, vector, sizeof(vector), iv,
  17439. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT) - 5, a, sizeof(a)),
  17440. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17441. #if (defined(HAVE_FIPS) && defined(HAVE_FIPS_VERSION) && \
  17442. (HAVE_FIPS_VERSION == 2)) || defined(HAVE_SELFTEST) || \
  17443. defined(WOLFSSL_AES_GCM_FIXED_IV_AAD)
  17444. /* FIPS does not check the lower bound of ivSz */
  17445. #else
  17446. ExpectIntEQ(wc_AesGcmEncrypt(&aes, enc, vector, sizeof(vector), iv, 0,
  17447. resultT, sizeof(resultT), a, sizeof(a)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17448. #endif
  17449. /* This case is now considered good. Long IVs are now allowed.
  17450. * Except for the original FIPS release, it still has an upper
  17451. * bound on the IV length. */
  17452. #if (!defined(HAVE_FIPS) || \
  17453. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))) && \
  17454. !defined(WOLFSSL_AES_GCM_FIXED_IV_AAD)
  17455. ExpectIntEQ(wc_AesGcmEncrypt(&aes, enc, vector, sizeof(vector), longIV,
  17456. sizeof(longIV)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  17457. 0);
  17458. #else
  17459. (void)longIV;
  17460. #endif /* Old FIPS */
  17461. /* END wc_AesGcmEncrypt */
  17462. #ifdef HAVE_AES_DECRYPT
  17463. ExpectIntEQ(wc_AesGcmDecrypt(NULL, dec, enc, sizeof(enc)/sizeof(byte), iv,
  17464. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  17465. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17466. ExpectIntEQ(wc_AesGcmDecrypt(&aes, NULL, enc, sizeof(enc)/sizeof(byte), iv,
  17467. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  17468. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17469. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, NULL, sizeof(enc)/sizeof(byte), iv,
  17470. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  17471. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17472. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(enc)/sizeof(byte), NULL,
  17473. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT), a, sizeof(a)),
  17474. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17475. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(enc)/sizeof(byte), iv,
  17476. sizeof(iv)/sizeof(byte), NULL, sizeof(resultT), a, sizeof(a)),
  17477. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17478. #if (defined(HAVE_FIPS) && FIPS_VERSION_LE(2,0) && defined(WOLFSSL_ARMASM))
  17479. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(enc)/sizeof(byte), iv,
  17480. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT) + 1, a, sizeof(a)),
  17481. WC_NO_ERR_TRACE(AES_GCM_AUTH_E));
  17482. #else
  17483. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(enc)/sizeof(byte), iv,
  17484. sizeof(iv)/sizeof(byte), resultT, sizeof(resultT) + 1, a, sizeof(a)),
  17485. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17486. #endif
  17487. #if ((defined(HAVE_FIPS) && defined(HAVE_FIPS_VERSION) && \
  17488. (HAVE_FIPS_VERSION == 2)) || defined(HAVE_SELFTEST)) && \
  17489. !defined(WOLFSSL_AES_GCM_FIXED_IV_AAD)
  17490. /* FIPS does not check the lower bound of ivSz */
  17491. #else
  17492. ExpectIntEQ(wc_AesGcmDecrypt(&aes, dec, enc, sizeof(enc)/sizeof(byte),
  17493. iv, 0, resultT, sizeof(resultT), a, sizeof(a)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17494. #endif
  17495. #endif /* HAVE_AES_DECRYPT */
  17496. wc_AesFree(&aes);
  17497. #endif
  17498. return EXPECT_RESULT();
  17499. } /* END test_wc_AesGcmEncryptDecrypt */
  17500. /*
  17501. * test function for mixed (one-shot encrpytion + stream decryption) AES GCM
  17502. * using a long IV (older FIPS does NOT support long IVs). Relates to zd15423
  17503. */
  17504. static int test_wc_AesGcmMixedEncDecLongIV(void)
  17505. {
  17506. EXPECT_DECLS;
  17507. #if (!defined(HAVE_FIPS) || \
  17508. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))) && \
  17509. !defined(NO_AES) && defined(HAVE_AESGCM) && defined(WOLFSSL_AESGCM_STREAM)
  17510. const byte key[] = {
  17511. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17512. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17513. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17514. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17515. };
  17516. const byte in[] = {
  17517. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  17518. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  17519. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  17520. };
  17521. const byte aad[] = {
  17522. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  17523. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  17524. 0xab, 0xad, 0xda, 0xd2
  17525. };
  17526. Aes aesEnc;
  17527. Aes aesDec;
  17528. byte iv[] = "1234567890abcdefghij";
  17529. byte out[sizeof(in)];
  17530. byte plain[sizeof(in)];
  17531. byte tag[AES_BLOCK_SIZE];
  17532. XMEMSET(&aesEnc, 0, sizeof(Aes));
  17533. XMEMSET(&aesDec, 0, sizeof(Aes));
  17534. XMEMSET(out, 0, sizeof(out));
  17535. XMEMSET(plain, 0, sizeof(plain));
  17536. XMEMSET(tag, 0, sizeof(tag));
  17537. /* Perform one-shot encryption using long IV */
  17538. ExpectIntEQ(wc_AesInit(&aesEnc, NULL, INVALID_DEVID), 0);
  17539. ExpectIntEQ(wc_AesGcmSetKey(&aesEnc, key, sizeof(key)), 0);
  17540. ExpectIntEQ(wc_AesGcmEncrypt(&aesEnc, out, in, sizeof(in), iv, sizeof(iv),
  17541. tag, sizeof(tag), aad, sizeof(aad)), 0);
  17542. /* Perform streaming decryption using long IV */
  17543. ExpectIntEQ(wc_AesInit(&aesDec, NULL, INVALID_DEVID), 0);
  17544. ExpectIntEQ(wc_AesGcmInit(&aesDec, key, sizeof(key), iv, sizeof(iv)), 0);
  17545. ExpectIntEQ(wc_AesGcmDecryptUpdate(&aesDec, plain, out, sizeof(out), aad,
  17546. sizeof(aad)), 0);
  17547. ExpectIntEQ(wc_AesGcmDecryptFinal(&aesDec, tag, sizeof(tag)), 0);
  17548. ExpectIntEQ(XMEMCMP(plain, in, sizeof(in)), 0);
  17549. /* Free resources */
  17550. wc_AesFree(&aesEnc);
  17551. wc_AesFree(&aesDec);
  17552. #endif
  17553. return EXPECT_RESULT();
  17554. } /* END wc_AesGcmMixedEncDecLongIV */
  17555. /*
  17556. * unit test for wc_GmacSetKey()
  17557. */
  17558. static int test_wc_GmacSetKey(void)
  17559. {
  17560. EXPECT_DECLS;
  17561. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  17562. Gmac gmac;
  17563. byte key16[] = {
  17564. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17565. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17566. };
  17567. #ifdef WOLFSSL_AES_192
  17568. byte key24[] = {
  17569. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17570. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17571. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
  17572. };
  17573. #endif
  17574. #ifdef WOLFSSL_AES_256
  17575. byte key32[] = {
  17576. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17577. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17578. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17579. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17580. };
  17581. #endif
  17582. byte badKey16[] = {
  17583. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17584. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x66
  17585. };
  17586. byte badKey24[] = {
  17587. 0x30, 0x31, 0x32, 0x33, 0x34, 0x36, 0x37,
  17588. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  17589. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
  17590. };
  17591. byte badKey32[] = {
  17592. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17593. 0x38, 0x39, 0x61, 0x62, 0x64, 0x65, 0x66,
  17594. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  17595. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  17596. };
  17597. XMEMSET(&gmac, 0, sizeof(Gmac));
  17598. ExpectIntEQ(wc_AesInit(&gmac.aes, NULL, INVALID_DEVID), 0);
  17599. #ifdef WOLFSSL_AES_128
  17600. ExpectIntEQ(wc_GmacSetKey(&gmac, key16, sizeof(key16)/sizeof(byte)), 0);
  17601. #endif
  17602. #ifdef WOLFSSL_AES_192
  17603. ExpectIntEQ(wc_GmacSetKey(&gmac, key24, sizeof(key24)/sizeof(byte)), 0);
  17604. #endif
  17605. #ifdef WOLFSSL_AES_256
  17606. ExpectIntEQ(wc_GmacSetKey(&gmac, key32, sizeof(key32)/sizeof(byte)), 0);
  17607. #endif
  17608. /* Pass in bad args. */
  17609. ExpectIntEQ(wc_GmacSetKey(NULL, key16, sizeof(key16)/sizeof(byte)),
  17610. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17611. ExpectIntEQ(wc_GmacSetKey(&gmac, NULL, sizeof(key16)/sizeof(byte)),
  17612. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17613. ExpectIntEQ(wc_GmacSetKey(&gmac, badKey16, sizeof(badKey16)/sizeof(byte)),
  17614. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17615. ExpectIntEQ(wc_GmacSetKey(&gmac, badKey24, sizeof(badKey24)/sizeof(byte)),
  17616. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17617. ExpectIntEQ(wc_GmacSetKey(&gmac, badKey32, sizeof(badKey32)/sizeof(byte)),
  17618. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17619. wc_AesFree(&gmac.aes);
  17620. #endif
  17621. return EXPECT_RESULT();
  17622. } /* END test_wc_GmacSetKey */
  17623. /*
  17624. * unit test for wc_GmacUpdate
  17625. */
  17626. static int test_wc_GmacUpdate(void)
  17627. {
  17628. EXPECT_DECLS;
  17629. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  17630. Gmac gmac;
  17631. #ifdef WOLFSSL_AES_128
  17632. const byte key16[] = {
  17633. 0x89, 0xc9, 0x49, 0xe9, 0xc8, 0x04, 0xaf, 0x01,
  17634. 0x4d, 0x56, 0x04, 0xb3, 0x94, 0x59, 0xf2, 0xc8
  17635. };
  17636. #endif
  17637. #ifdef WOLFSSL_AES_192
  17638. byte key24[] = {
  17639. 0x41, 0xc5, 0xda, 0x86, 0x67, 0xef, 0x72, 0x52,
  17640. 0x20, 0xff, 0xe3, 0x9a, 0xe0, 0xac, 0x59, 0x0a,
  17641. 0xc9, 0xfc, 0xa7, 0x29, 0xab, 0x60, 0xad, 0xa0
  17642. };
  17643. #endif
  17644. #ifdef WOLFSSL_AES_256
  17645. byte key32[] = {
  17646. 0x78, 0xdc, 0x4e, 0x0a, 0xaf, 0x52, 0xd9, 0x35,
  17647. 0xc3, 0xc0, 0x1e, 0xea, 0x57, 0x42, 0x8f, 0x00,
  17648. 0xca, 0x1f, 0xd4, 0x75, 0xf5, 0xda, 0x86, 0xa4,
  17649. 0x9c, 0x8d, 0xd7, 0x3d, 0x68, 0xc8, 0xe2, 0x23
  17650. };
  17651. #endif
  17652. #ifdef WOLFSSL_AES_128
  17653. const byte authIn[] = {
  17654. 0x82, 0xad, 0xcd, 0x63, 0x8d, 0x3f, 0xa9, 0xd9,
  17655. 0xf3, 0xe8, 0x41, 0x00, 0xd6, 0x1e, 0x07, 0x77
  17656. };
  17657. #endif
  17658. #ifdef WOLFSSL_AES_192
  17659. const byte authIn2[] = {
  17660. 0x8b, 0x5c, 0x12, 0x4b, 0xef, 0x6e, 0x2f, 0x0f,
  17661. 0xe4, 0xd8, 0xc9, 0x5c, 0xd5, 0xfa, 0x4c, 0xf1
  17662. };
  17663. #endif
  17664. const byte authIn3[] = {
  17665. 0xb9, 0x6b, 0xaa, 0x8c, 0x1c, 0x75, 0xa6, 0x71,
  17666. 0xbf, 0xb2, 0xd0, 0x8d, 0x06, 0xbe, 0x5f, 0x36
  17667. };
  17668. #ifdef WOLFSSL_AES_128
  17669. const byte tag1[] = { /* Known. */
  17670. 0x88, 0xdb, 0x9d, 0x62, 0x17, 0x2e, 0xd0, 0x43,
  17671. 0xaa, 0x10, 0xf1, 0x6d, 0x22, 0x7d, 0xc4, 0x1b
  17672. };
  17673. #endif
  17674. #ifdef WOLFSSL_AES_192
  17675. const byte tag2[] = { /* Known */
  17676. 0x20, 0x4b, 0xdb, 0x1b, 0xd6, 0x21, 0x54, 0xbf,
  17677. 0x08, 0x92, 0x2a, 0xaa, 0x54, 0xee, 0xd7, 0x05
  17678. };
  17679. #endif
  17680. const byte tag3[] = { /* Known */
  17681. 0x3e, 0x5d, 0x48, 0x6a, 0xa2, 0xe3, 0x0b, 0x22,
  17682. 0xe0, 0x40, 0xb8, 0x57, 0x23, 0xa0, 0x6e, 0x76
  17683. };
  17684. #ifdef WOLFSSL_AES_128
  17685. const byte iv[] = {
  17686. 0xd1, 0xb1, 0x04, 0xc8, 0x15, 0xbf, 0x1e, 0x94,
  17687. 0xe2, 0x8c, 0x8f, 0x16
  17688. };
  17689. #endif
  17690. #ifdef WOLFSSL_AES_192
  17691. const byte iv2[] = {
  17692. 0x05, 0xad, 0x13, 0xa5, 0xe2, 0xc2, 0xab, 0x66,
  17693. 0x7e, 0x1a, 0x6f, 0xbc
  17694. };
  17695. #endif
  17696. const byte iv3[] = {
  17697. 0xd7, 0x9c, 0xf2, 0x2d, 0x50, 0x4c, 0xc7, 0x93,
  17698. 0xc3, 0xfb, 0x6c, 0x8a
  17699. };
  17700. byte tagOut[16];
  17701. byte tagOut2[24];
  17702. byte tagOut3[32];
  17703. /* Init stack variables. */
  17704. XMEMSET(&gmac, 0, sizeof(Gmac));
  17705. XMEMSET(tagOut, 0, sizeof(tagOut));
  17706. XMEMSET(tagOut2, 0, sizeof(tagOut2));
  17707. XMEMSET(tagOut3, 0, sizeof(tagOut3));
  17708. #ifdef WOLFSSL_AES_128
  17709. ExpectIntEQ(wc_AesInit(&gmac.aes, NULL, INVALID_DEVID), 0);
  17710. ExpectIntEQ(wc_GmacSetKey(&gmac, key16, sizeof(key16)), 0);
  17711. ExpectIntEQ(wc_GmacUpdate(&gmac, iv, sizeof(iv), authIn, sizeof(authIn),
  17712. tagOut, sizeof(tag1)), 0);
  17713. ExpectIntEQ(XMEMCMP(tag1, tagOut, sizeof(tag1)), 0);
  17714. wc_AesFree(&gmac.aes);
  17715. #endif
  17716. #ifdef WOLFSSL_AES_192
  17717. ExpectNotNull(XMEMSET(&gmac, 0, sizeof(Gmac)));
  17718. ExpectIntEQ(wc_AesInit(&gmac.aes, HEAP_HINT, INVALID_DEVID), 0);
  17719. ExpectIntEQ(wc_GmacSetKey(&gmac, key24, sizeof(key24)/sizeof(byte)), 0);
  17720. ExpectIntEQ(wc_GmacUpdate(&gmac, iv2, sizeof(iv2), authIn2, sizeof(authIn2),
  17721. tagOut2, sizeof(tag2)), 0);
  17722. ExpectIntEQ(XMEMCMP(tagOut2, tag2, sizeof(tag2)), 0);
  17723. wc_AesFree(&gmac.aes);
  17724. #endif
  17725. #ifdef WOLFSSL_AES_256
  17726. ExpectNotNull(XMEMSET(&gmac, 0, sizeof(Gmac)));
  17727. ExpectIntEQ(wc_AesInit(&gmac.aes, HEAP_HINT, INVALID_DEVID), 0);
  17728. ExpectIntEQ(wc_GmacSetKey(&gmac, key32, sizeof(key32)/sizeof(byte)), 0);
  17729. ExpectIntEQ(wc_GmacUpdate(&gmac, iv3, sizeof(iv3), authIn3, sizeof(authIn3),
  17730. tagOut3, sizeof(tag3)), 0);
  17731. ExpectIntEQ(XMEMCMP(tag3, tagOut3, sizeof(tag3)), 0);
  17732. wc_AesFree(&gmac.aes);
  17733. #endif
  17734. /* Pass bad args. */
  17735. ExpectIntEQ(wc_AesInit(&gmac.aes, NULL, INVALID_DEVID), 0);
  17736. ExpectIntEQ(wc_GmacUpdate(NULL, iv3, sizeof(iv3), authIn3, sizeof(authIn3),
  17737. tagOut3, sizeof(tag3)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17738. ExpectIntEQ(wc_GmacUpdate(&gmac, iv3, sizeof(iv3), authIn3, sizeof(authIn3),
  17739. tagOut3, sizeof(tag3) - 5), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17740. ExpectIntEQ(wc_GmacUpdate(&gmac, iv3, sizeof(iv3), authIn3, sizeof(authIn3),
  17741. tagOut3, sizeof(tag3) + 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17742. wc_AesFree(&gmac.aes);
  17743. #endif
  17744. return EXPECT_RESULT();
  17745. } /* END test_wc_GmacUpdate */
  17746. /*
  17747. * testing wc_CamelliaSetKey
  17748. */
  17749. static int test_wc_CamelliaSetKey(void)
  17750. {
  17751. EXPECT_DECLS;
  17752. #ifdef HAVE_CAMELLIA
  17753. Camellia camellia;
  17754. /*128-bit key*/
  17755. static const byte key16[] = {
  17756. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  17757. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10
  17758. };
  17759. /* 192-bit key */
  17760. static const byte key24[] = {
  17761. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  17762. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  17763. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77
  17764. };
  17765. /* 256-bit key */
  17766. static const byte key32[] = {
  17767. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  17768. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  17769. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  17770. 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
  17771. };
  17772. static const byte iv[] = {
  17773. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  17774. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  17775. };
  17776. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key16, (word32)sizeof(key16), iv),
  17777. 0);
  17778. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key16, (word32)sizeof(key16),
  17779. NULL), 0);
  17780. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key24, (word32)sizeof(key24), iv),
  17781. 0);
  17782. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key24, (word32)sizeof(key24),
  17783. NULL), 0);
  17784. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key32, (word32)sizeof(key32), iv),
  17785. 0);
  17786. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key32, (word32)sizeof(key32),
  17787. NULL), 0);
  17788. /* Bad args. */
  17789. ExpectIntEQ(wc_CamelliaSetKey(NULL, key32, (word32)sizeof(key32), iv),
  17790. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17791. #endif
  17792. return EXPECT_RESULT();
  17793. } /* END test_wc_CammeliaSetKey */
  17794. /*
  17795. * Testing wc_CamelliaSetIV()
  17796. */
  17797. static int test_wc_CamelliaSetIV(void)
  17798. {
  17799. EXPECT_DECLS;
  17800. #ifdef HAVE_CAMELLIA
  17801. Camellia camellia;
  17802. static const byte iv[] = {
  17803. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  17804. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  17805. };
  17806. ExpectIntEQ(wc_CamelliaSetIV(&camellia, iv), 0);
  17807. ExpectIntEQ(wc_CamelliaSetIV(&camellia, NULL), 0);
  17808. /* Bad args. */
  17809. ExpectIntEQ(wc_CamelliaSetIV(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17810. ExpectIntEQ(wc_CamelliaSetIV(NULL, iv), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17811. #endif
  17812. return EXPECT_RESULT();
  17813. } /* END test_wc_CamelliaSetIV*/
  17814. /*
  17815. * Test wc_CamelliaEncryptDirect and wc_CamelliaDecryptDirect
  17816. */
  17817. static int test_wc_CamelliaEncryptDecryptDirect(void)
  17818. {
  17819. EXPECT_DECLS;
  17820. #ifdef HAVE_CAMELLIA
  17821. Camellia camellia;
  17822. static const byte key24[] = {
  17823. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  17824. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  17825. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77
  17826. };
  17827. static const byte iv[] = {
  17828. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  17829. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  17830. };
  17831. static const byte plainT[] = {
  17832. 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
  17833. 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A
  17834. };
  17835. byte enc[sizeof(plainT)];
  17836. byte dec[sizeof(enc)];
  17837. /* Init stack variables.*/
  17838. XMEMSET(enc, 0, 16);
  17839. XMEMSET(enc, 0, 16);
  17840. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key24, (word32)sizeof(key24), iv),
  17841. 0);
  17842. ExpectIntEQ(wc_CamelliaEncryptDirect(&camellia, enc, plainT), 0);
  17843. ExpectIntEQ(wc_CamelliaDecryptDirect(&camellia, dec, enc), 0);
  17844. ExpectIntEQ(XMEMCMP(plainT, dec, CAMELLIA_BLOCK_SIZE), 0);
  17845. /* Pass bad args. */
  17846. ExpectIntEQ(wc_CamelliaEncryptDirect(NULL, enc, plainT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17847. ExpectIntEQ(wc_CamelliaEncryptDirect(&camellia, NULL, plainT),
  17848. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17849. ExpectIntEQ(wc_CamelliaEncryptDirect(&camellia, enc, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17850. ExpectIntEQ(wc_CamelliaDecryptDirect(NULL, dec, enc), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17851. ExpectIntEQ(wc_CamelliaDecryptDirect(&camellia, NULL, enc), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17852. ExpectIntEQ(wc_CamelliaDecryptDirect(&camellia, dec, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17853. #endif
  17854. return EXPECT_RESULT();
  17855. } /* END test-wc_CamelliaEncryptDecryptDirect */
  17856. /*
  17857. * Testing wc_CamelliaCbcEncrypt and wc_CamelliaCbcDecrypt
  17858. */
  17859. static int test_wc_CamelliaCbcEncryptDecrypt(void)
  17860. {
  17861. EXPECT_DECLS;
  17862. #ifdef HAVE_CAMELLIA
  17863. Camellia camellia;
  17864. static const byte key24[] = {
  17865. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  17866. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  17867. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77
  17868. };
  17869. static const byte plainT[] = {
  17870. 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
  17871. 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A
  17872. };
  17873. byte enc[CAMELLIA_BLOCK_SIZE];
  17874. byte dec[CAMELLIA_BLOCK_SIZE];
  17875. /* Init stack variables. */
  17876. XMEMSET(enc, 0, CAMELLIA_BLOCK_SIZE);
  17877. XMEMSET(enc, 0, CAMELLIA_BLOCK_SIZE);
  17878. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key24, (word32)sizeof(key24),
  17879. NULL), 0);
  17880. ExpectIntEQ(wc_CamelliaCbcEncrypt(&camellia, enc, plainT,
  17881. CAMELLIA_BLOCK_SIZE), 0);
  17882. ExpectIntEQ(wc_CamelliaSetKey(&camellia, key24, (word32)sizeof(key24),
  17883. NULL), 0);
  17884. ExpectIntEQ(wc_CamelliaCbcDecrypt(&camellia, dec, enc, CAMELLIA_BLOCK_SIZE),
  17885. 0);
  17886. ExpectIntEQ(XMEMCMP(plainT, dec, CAMELLIA_BLOCK_SIZE), 0);
  17887. /* Pass in bad args. */
  17888. ExpectIntEQ(wc_CamelliaCbcEncrypt(NULL, enc, plainT, CAMELLIA_BLOCK_SIZE),
  17889. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17890. ExpectIntEQ(wc_CamelliaCbcEncrypt(&camellia, NULL, plainT,
  17891. CAMELLIA_BLOCK_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17892. ExpectIntEQ(wc_CamelliaCbcEncrypt(&camellia, enc, NULL,
  17893. CAMELLIA_BLOCK_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17894. ExpectIntEQ(wc_CamelliaCbcDecrypt(NULL, dec, enc, CAMELLIA_BLOCK_SIZE),
  17895. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17896. ExpectIntEQ(wc_CamelliaCbcDecrypt(&camellia, NULL, enc,
  17897. CAMELLIA_BLOCK_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17898. ExpectIntEQ(wc_CamelliaCbcDecrypt(&camellia, dec, NULL,
  17899. CAMELLIA_BLOCK_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17900. #endif
  17901. return EXPECT_RESULT();
  17902. } /* END test_wc_CamelliaCbcEncryptDecrypt */
  17903. /*
  17904. * Testing wc_Arc4SetKey()
  17905. */
  17906. static int test_wc_Arc4SetKey(void)
  17907. {
  17908. EXPECT_DECLS;
  17909. #ifndef NO_RC4
  17910. Arc4 arc;
  17911. const char* key = "\x01\x23\x45\x67\x89\xab\xcd\xef";
  17912. int keyLen = 8;
  17913. ExpectIntEQ(wc_Arc4SetKey(&arc, (byte*)key, (word32)keyLen), 0);
  17914. /* Test bad args. */
  17915. ExpectIntEQ(wc_Arc4SetKey(NULL, (byte*)key, (word32)keyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17916. ExpectIntEQ(wc_Arc4SetKey(&arc, NULL , (word32)keyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17917. ExpectIntEQ(wc_Arc4SetKey(&arc, (byte*)key, 0 ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17918. #endif
  17919. return EXPECT_RESULT();
  17920. } /* END test_wc_Arc4SetKey */
  17921. /*
  17922. * Testing wc_Arc4Process for ENC/DEC.
  17923. */
  17924. static int test_wc_Arc4Process(void)
  17925. {
  17926. EXPECT_DECLS;
  17927. #ifndef NO_RC4
  17928. Arc4 enc;
  17929. Arc4 dec;
  17930. const char* key = "\x01\x23\x45\x67\x89\xab\xcd\xef";
  17931. int keyLen = 8;
  17932. const char* input = "\x01\x23\x45\x67\x89\xab\xcd\xef";
  17933. byte cipher[8];
  17934. byte plain[8];
  17935. /* Init stack variables */
  17936. XMEMSET(&enc, 0, sizeof(Arc4));
  17937. XMEMSET(&dec, 0, sizeof(Arc4));
  17938. XMEMSET(cipher, 0, sizeof(cipher));
  17939. XMEMSET(plain, 0, sizeof(plain));
  17940. /* Use for async. */
  17941. ExpectIntEQ(wc_Arc4Init(&enc, NULL, INVALID_DEVID), 0);
  17942. ExpectIntEQ(wc_Arc4Init(&dec, NULL, INVALID_DEVID), 0);
  17943. ExpectIntEQ(wc_Arc4SetKey(&enc, (byte*)key, (word32)keyLen), 0);
  17944. ExpectIntEQ(wc_Arc4SetKey(&dec, (byte*)key, (word32)keyLen), 0);
  17945. ExpectIntEQ(wc_Arc4Process(&enc, cipher, (byte*)input, (word32)keyLen), 0);
  17946. ExpectIntEQ(wc_Arc4Process(&dec, plain, cipher, (word32)keyLen), 0);
  17947. ExpectIntEQ(XMEMCMP(plain, input, keyLen), 0);
  17948. /* Bad args. */
  17949. ExpectIntEQ(wc_Arc4Process(NULL, plain, cipher, (word32)keyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17950. ExpectIntEQ(wc_Arc4Process(&dec, NULL, cipher, (word32)keyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17951. ExpectIntEQ(wc_Arc4Process(&dec, plain, NULL, (word32)keyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17952. wc_Arc4Free(&enc);
  17953. wc_Arc4Free(&dec);
  17954. #endif
  17955. return EXPECT_RESULT();
  17956. } /* END test_wc_Arc4Process */
  17957. /*
  17958. * Testing wc_Init RsaKey()
  17959. */
  17960. static int test_wc_InitRsaKey(void)
  17961. {
  17962. EXPECT_DECLS;
  17963. #ifndef NO_RSA
  17964. RsaKey key;
  17965. XMEMSET(&key, 0, sizeof(RsaKey));
  17966. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  17967. /* Test bad args. */
  17968. ExpectIntEQ(wc_InitRsaKey(NULL, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  17969. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  17970. #endif
  17971. return EXPECT_RESULT();
  17972. } /* END test_wc_InitRsaKey */
  17973. /*
  17974. * Testing wc_RsaPrivateKeyDecode()
  17975. */
  17976. static int test_wc_RsaPrivateKeyDecode(void)
  17977. {
  17978. EXPECT_DECLS;
  17979. #if !defined(NO_RSA) && (defined(USE_CERT_BUFFERS_1024)\
  17980. || defined(USE_CERT_BUFFERS_2048)) && !defined(HAVE_FIPS)
  17981. RsaKey key;
  17982. byte* tmp = NULL;
  17983. word32 idx = 0;
  17984. int bytes = 0;
  17985. XMEMSET(&key, 0, sizeof(RsaKey));
  17986. ExpectNotNull(tmp = (byte*)XMALLOC(FOURK_BUF, NULL,
  17987. DYNAMIC_TYPE_TMP_BUFFER));
  17988. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  17989. if (tmp != NULL) {
  17990. #ifdef USE_CERT_BUFFERS_1024
  17991. XMEMCPY(tmp, client_key_der_1024, sizeof_client_key_der_1024);
  17992. bytes = sizeof_client_key_der_1024;
  17993. #else
  17994. XMEMCPY(tmp, client_key_der_2048, sizeof_client_key_der_2048);
  17995. bytes = sizeof_client_key_der_2048;
  17996. #endif /* Use cert buffers. */
  17997. }
  17998. ExpectIntEQ(wc_RsaPrivateKeyDecode(tmp, &idx, &key, (word32)bytes), 0);
  17999. /* Test bad args. */
  18000. ExpectIntEQ(wc_RsaPrivateKeyDecode(NULL, &idx, &key, (word32)bytes),
  18001. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18002. ExpectIntEQ(wc_RsaPrivateKeyDecode(tmp, NULL, &key, (word32)bytes),
  18003. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18004. ExpectIntEQ(wc_RsaPrivateKeyDecode(tmp, &idx, NULL, (word32)bytes),
  18005. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18006. XFREE(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  18007. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18008. #endif
  18009. return EXPECT_RESULT();
  18010. } /* END test_wc_RsaPrivateKeyDecode */
  18011. /*
  18012. * Testing wc_RsaPublicKeyDecode()
  18013. */
  18014. static int test_wc_RsaPublicKeyDecode(void)
  18015. {
  18016. EXPECT_DECLS;
  18017. #if !defined(NO_RSA) && (defined(USE_CERT_BUFFERS_1024)\
  18018. || defined(USE_CERT_BUFFERS_2048)) && !defined(HAVE_FIPS)
  18019. RsaKey keyPub;
  18020. byte* tmp = NULL;
  18021. word32 idx = 0;
  18022. int bytes = 0;
  18023. word32 keySz = 0;
  18024. word32 tstKeySz = 0;
  18025. #if defined(WC_RSA_PSS) && !defined(NO_FILESYSTEM)
  18026. XFILE f = XBADFILE;
  18027. const char* rsaPssPubKey = "./certs/rsapss/ca-rsapss-key.der";
  18028. const char* rsaPssPubKeyNoParams = "./certs/rsapss/ca-3072-rsapss-key.der";
  18029. byte buf[4096];
  18030. #endif
  18031. XMEMSET(&keyPub, 0, sizeof(RsaKey));
  18032. ExpectNotNull(tmp = (byte*)XMALLOC(GEN_BUF, NULL, DYNAMIC_TYPE_TMP_BUFFER));
  18033. ExpectIntEQ(wc_InitRsaKey(&keyPub, HEAP_HINT), 0);
  18034. if (tmp != NULL) {
  18035. #ifdef USE_CERT_BUFFERS_1024
  18036. XMEMCPY(tmp, client_keypub_der_1024, sizeof_client_keypub_der_1024);
  18037. bytes = sizeof_client_keypub_der_1024;
  18038. keySz = 1024;
  18039. #else
  18040. XMEMCPY(tmp, client_keypub_der_2048, sizeof_client_keypub_der_2048);
  18041. bytes = sizeof_client_keypub_der_2048;
  18042. keySz = 2048;
  18043. #endif
  18044. }
  18045. ExpectIntEQ(wc_RsaPublicKeyDecode(tmp, &idx, &keyPub, (word32)bytes), 0);
  18046. /* Pass in bad args. */
  18047. ExpectIntEQ(wc_RsaPublicKeyDecode(NULL, &idx, &keyPub, (word32)bytes),
  18048. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18049. ExpectIntEQ(wc_RsaPublicKeyDecode(tmp, NULL, &keyPub, (word32)bytes),
  18050. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18051. ExpectIntEQ(wc_RsaPublicKeyDecode(tmp, &idx, NULL, (word32)bytes),
  18052. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18053. DoExpectIntEQ(wc_FreeRsaKey(&keyPub), 0);
  18054. /* Test for getting modulus key size */
  18055. idx = 0;
  18056. ExpectIntEQ(wc_RsaPublicKeyDecode_ex(tmp, &idx, (word32)bytes, NULL,
  18057. &tstKeySz, NULL, NULL), 0);
  18058. ExpectIntEQ(tstKeySz, keySz/8);
  18059. #if defined(WC_RSA_PSS) && !defined(NO_FILESYSTEM)
  18060. ExpectTrue((f = XFOPEN(rsaPssPubKey, "rb")) != XBADFILE);
  18061. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  18062. if (f != XBADFILE) {
  18063. XFCLOSE(f);
  18064. f = XBADFILE;
  18065. }
  18066. idx = 0;
  18067. ExpectIntEQ(wc_RsaPublicKeyDecode_ex(buf, &idx, (word32)bytes, NULL, NULL, NULL,
  18068. NULL), 0);
  18069. ExpectTrue((f = XFOPEN(rsaPssPubKeyNoParams, "rb")) != XBADFILE);
  18070. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  18071. if (f != XBADFILE)
  18072. XFCLOSE(f);
  18073. idx = 0;
  18074. ExpectIntEQ(wc_RsaPublicKeyDecode_ex(buf, &idx, (word32)bytes, NULL, NULL, NULL,
  18075. NULL), 0);
  18076. #endif
  18077. XFREE(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  18078. #endif
  18079. return EXPECT_RESULT();
  18080. } /* END test_wc_RsaPublicKeyDecode */
  18081. /*
  18082. * Testing wc_RsaPublicKeyDecodeRaw()
  18083. */
  18084. static int test_wc_RsaPublicKeyDecodeRaw(void)
  18085. {
  18086. EXPECT_DECLS;
  18087. #if !defined(NO_RSA)
  18088. RsaKey key;
  18089. const byte n = 0x23;
  18090. const byte e = 0x03;
  18091. word32 nSz = sizeof(n);
  18092. word32 eSz = sizeof(e);
  18093. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18094. ExpectIntEQ(wc_RsaPublicKeyDecodeRaw(&n, nSz, &e, eSz, &key), 0);
  18095. /* Pass in bad args. */
  18096. ExpectIntEQ(wc_RsaPublicKeyDecodeRaw(NULL, nSz, &e, eSz, &key),
  18097. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18098. ExpectIntEQ(wc_RsaPublicKeyDecodeRaw(&n, nSz, NULL, eSz, &key),
  18099. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18100. ExpectIntEQ(wc_RsaPublicKeyDecodeRaw(&n, nSz, &e, eSz, NULL),
  18101. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18102. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18103. #endif
  18104. return EXPECT_RESULT();
  18105. } /* END test_wc_RsaPublicKeyDecodeRaw */
  18106. /*
  18107. * Testing wc_RsaPrivateKeyDecodeRaw()
  18108. */
  18109. static int test_wc_RsaPrivateKeyDecodeRaw(void)
  18110. {
  18111. EXPECT_DECLS;
  18112. #if !defined(NO_RSA) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) \
  18113. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  18114. RsaKey key;
  18115. const byte n = 33;
  18116. const byte e = 3;
  18117. const byte d = 7;
  18118. const byte u = 2;
  18119. const byte p = 3;
  18120. const byte q = 11;
  18121. const byte dp = 1;
  18122. const byte dq = 7;
  18123. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18124. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18125. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  18126. &p, sizeof(p), &q, sizeof(q), NULL, 0,
  18127. NULL, 0, &key), 0);
  18128. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18129. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  18130. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18131. NULL, 0, &key), 0);
  18132. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18133. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  18134. &p, sizeof(p), &q, sizeof(q), NULL, 0,
  18135. &dq, sizeof(dq), &key), 0);
  18136. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18137. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  18138. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18139. &dq, sizeof(dq), &key), 0);
  18140. /* Pass in bad args. */
  18141. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(NULL, sizeof(n),
  18142. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  18143. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18144. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18145. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, 0,
  18146. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  18147. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18148. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18149. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18150. NULL, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  18151. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18152. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18153. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18154. &e, 0, &d, sizeof(d), &u, sizeof(u),
  18155. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18156. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18157. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18158. &e, sizeof(e), NULL, sizeof(d), &u, sizeof(u),
  18159. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18160. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18161. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18162. &e, sizeof(e), &d, 0, &u, sizeof(u),
  18163. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18164. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18165. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18166. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  18167. NULL, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18168. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18169. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18170. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  18171. &p, 0, &q, sizeof(q), &dp, sizeof(dp),
  18172. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18173. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18174. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  18175. &p, sizeof(p), NULL, sizeof(q), &dp, sizeof(dp),
  18176. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18177. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18178. &e, sizeof(e), &d, sizeof(d), &u, sizeof(u),
  18179. &p, sizeof(p), &q, 0, &dp, sizeof(dp),
  18180. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18181. #if defined(WOLFSSL_KEY_GEN) || defined(OPENSSL_EXTRA) || !defined(RSA_LOW_MEM)
  18182. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18183. &e, sizeof(e), &d, sizeof(d), &u, 0,
  18184. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18185. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18186. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18187. &e, sizeof(e), &d, sizeof(d), NULL, sizeof(u),
  18188. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18189. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18190. ExpectIntEQ(wc_RsaPrivateKeyDecodeRaw(&n, sizeof(n),
  18191. &e, sizeof(e), &d, sizeof(d), &u, 0,
  18192. &p, sizeof(p), &q, sizeof(q), &dp, sizeof(dp),
  18193. &dq, sizeof(dq), &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18194. #endif
  18195. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18196. #endif
  18197. return EXPECT_RESULT();
  18198. } /* END test_wc_RsaPrivateKeyDecodeRaw */
  18199. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18200. /* In FIPS builds, wc_MakeRsaKey() will return an error if it cannot find
  18201. * a probable prime in 5*(modLen/2) attempts. In non-FIPS builds, it keeps
  18202. * trying until it gets a probable prime. */
  18203. #ifdef HAVE_FIPS
  18204. static int MakeRsaKeyRetry(RsaKey* key, int size, long e, WC_RNG* rng)
  18205. {
  18206. int ret;
  18207. for (;;) {
  18208. ret = wc_MakeRsaKey(key, size, e, rng);
  18209. if (ret != WC_NO_ERR_TRACE(PRIME_GEN_E)) break;
  18210. fprintf(stderr, "MakeRsaKey couldn't find prime; "
  18211. "trying again.\n");
  18212. }
  18213. return ret;
  18214. }
  18215. #define MAKE_RSA_KEY(a, b, c, d) MakeRsaKeyRetry(a, b, c, d)
  18216. #else
  18217. #define MAKE_RSA_KEY(a, b, c, d) wc_MakeRsaKey(a, b, c, d)
  18218. #endif
  18219. #endif
  18220. /*
  18221. * Testing wc_MakeRsaKey()
  18222. */
  18223. static int test_wc_MakeRsaKey(void)
  18224. {
  18225. EXPECT_DECLS;
  18226. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18227. RsaKey genKey;
  18228. WC_RNG rng;
  18229. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  18230. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4)) && \
  18231. (defined(RSA_MIN_SIZE) && (RSA_MIN_SIZE <= 1024))
  18232. int bits = 1024;
  18233. #else
  18234. int bits = 2048;
  18235. #endif
  18236. XMEMSET(&genKey, 0, sizeof(RsaKey));
  18237. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18238. ExpectIntEQ(wc_InitRsaKey(&genKey, HEAP_HINT), 0);
  18239. ExpectIntEQ(wc_InitRng(&rng), 0);
  18240. ExpectIntEQ(MAKE_RSA_KEY(&genKey, bits, WC_RSA_EXPONENT, &rng), 0);
  18241. DoExpectIntEQ(wc_FreeRsaKey(&genKey), 0);
  18242. /* Test bad args. */
  18243. ExpectIntEQ(MAKE_RSA_KEY(NULL, bits, WC_RSA_EXPONENT, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18244. ExpectIntEQ(MAKE_RSA_KEY(&genKey, bits, WC_RSA_EXPONENT, NULL),
  18245. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18246. /* e < 3 */
  18247. ExpectIntEQ(MAKE_RSA_KEY(&genKey, bits, 2, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18248. /* e & 1 == 0 */
  18249. ExpectIntEQ(MAKE_RSA_KEY(&genKey, bits, 6, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18250. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18251. #endif
  18252. return EXPECT_RESULT();
  18253. } /* END test_wc_MakeRsaKey */
  18254. /*
  18255. * Test the bounds checking on the cipher text versus the key modulus.
  18256. * 1. Make a new RSA key.
  18257. * 2. Set c to 1.
  18258. * 3. Decrypt c into k. (error)
  18259. * 4. Copy the key modulus to c and sub 1 from the copy.
  18260. * 5. Decrypt c into k. (error)
  18261. * Valid bounds test cases are covered by all the other RSA tests.
  18262. */
  18263. static int test_RsaDecryptBoundsCheck(void)
  18264. {
  18265. EXPECT_DECLS;
  18266. #if !defined(NO_RSA) && defined(WC_RSA_NO_PADDING) && \
  18267. (defined(USE_CERT_BUFFERS_1024) || defined(USE_CERT_BUFFERS_2048)) && \
  18268. defined(WOLFSSL_PUBLIC_MP) && !defined(NO_RSA_BOUNDS_CHECK)
  18269. WC_RNG rng;
  18270. RsaKey key;
  18271. byte flatC[256];
  18272. word32 flatCSz;
  18273. byte out[256];
  18274. word32 outSz = sizeof(out);
  18275. XMEMSET(&key, 0, sizeof(RsaKey));
  18276. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18277. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18278. ExpectIntEQ(wc_InitRng(&rng), 0);
  18279. if (EXPECT_SUCCESS()) {
  18280. const byte* derKey;
  18281. word32 derKeySz;
  18282. word32 idx = 0;
  18283. #ifdef USE_CERT_BUFFERS_1024
  18284. derKey = server_key_der_1024;
  18285. derKeySz = (word32)sizeof_server_key_der_1024;
  18286. flatCSz = 128;
  18287. #else
  18288. derKey = server_key_der_2048;
  18289. derKeySz = (word32)sizeof_server_key_der_2048;
  18290. flatCSz = 256;
  18291. #endif
  18292. ExpectIntEQ(wc_RsaPrivateKeyDecode(derKey, &idx, &key, derKeySz), 0);
  18293. }
  18294. if (EXPECT_SUCCESS()) {
  18295. XMEMSET(flatC, 0, flatCSz);
  18296. flatC[flatCSz-1] = 1;
  18297. ExpectIntEQ(wc_RsaDirect(flatC, flatCSz, out, &outSz, &key,
  18298. RSA_PRIVATE_DECRYPT, &rng), WC_NO_ERR_TRACE(RSA_OUT_OF_RANGE_E));
  18299. if (EXPECT_SUCCESS()) {
  18300. mp_int c;
  18301. ExpectIntEQ(mp_init_copy(&c, &key.n), 0);
  18302. ExpectIntEQ(mp_sub_d(&c, 1, &c), 0);
  18303. ExpectIntEQ(mp_to_unsigned_bin(&c, flatC), 0);
  18304. ExpectIntEQ(wc_RsaDirect(flatC, flatCSz, out, &outSz, &key,
  18305. RSA_PRIVATE_DECRYPT, NULL), WC_NO_ERR_TRACE(RSA_OUT_OF_RANGE_E));
  18306. mp_clear(&c);
  18307. }
  18308. }
  18309. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18310. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18311. #endif
  18312. return EXPECT_RESULT();
  18313. } /* END test_wc_RsaDecryptBoundsCheck */
  18314. /*
  18315. * Testing wc_SetKeyUsage()
  18316. */
  18317. static int test_wc_SetKeyUsage(void)
  18318. {
  18319. EXPECT_DECLS;
  18320. #if !defined(NO_RSA) && defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN) && !defined(HAVE_FIPS)
  18321. Cert myCert;
  18322. ExpectIntEQ(wc_InitCert(&myCert), 0);
  18323. ExpectIntEQ(wc_SetKeyUsage(&myCert, "keyEncipherment,keyAgreement"), 0);
  18324. ExpectIntEQ(wc_SetKeyUsage(&myCert, "digitalSignature,nonRepudiation"), 0);
  18325. ExpectIntEQ(wc_SetKeyUsage(&myCert, "contentCommitment,encipherOnly"), 0);
  18326. ExpectIntEQ(wc_SetKeyUsage(&myCert, "decipherOnly"), 0);
  18327. ExpectIntEQ(wc_SetKeyUsage(&myCert, "cRLSign,keyCertSign"), 0);
  18328. /* Test bad args. */
  18329. ExpectIntEQ(wc_SetKeyUsage(NULL, "decipherOnly"), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18330. ExpectIntEQ(wc_SetKeyUsage(&myCert, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18331. ExpectIntEQ(wc_SetKeyUsage(&myCert, ""), WC_NO_ERR_TRACE(KEYUSAGE_E));
  18332. ExpectIntEQ(wc_SetKeyUsage(&myCert, ","), WC_NO_ERR_TRACE(KEYUSAGE_E));
  18333. ExpectIntEQ(wc_SetKeyUsage(&myCert, "digitalSignature, cRLSign"),
  18334. WC_NO_ERR_TRACE(KEYUSAGE_E));
  18335. #endif
  18336. return EXPECT_RESULT();
  18337. } /* END test_wc_SetKeyUsage */
  18338. /*
  18339. * Testing wc_CheckProbablePrime()
  18340. */
  18341. static int test_wc_CheckProbablePrime(void)
  18342. {
  18343. EXPECT_DECLS;
  18344. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(HAVE_SELFTEST) && \
  18345. !defined(HAVE_FIPS) && defined(WC_RSA_BLINDING)
  18346. #define CHECK_PROBABLE_PRIME_KEY_BITS 2048
  18347. RsaKey key;
  18348. WC_RNG rng;
  18349. byte e[3];
  18350. word32 eSz = (word32)sizeof(e);
  18351. byte n[CHECK_PROBABLE_PRIME_KEY_BITS / 8];
  18352. word32 nSz = (word32)sizeof(n);
  18353. byte d[CHECK_PROBABLE_PRIME_KEY_BITS / 8];
  18354. word32 dSz = (word32)sizeof(d);
  18355. byte p[CHECK_PROBABLE_PRIME_KEY_BITS / 8 / 2];
  18356. word32 pSz = (word32)sizeof(p);
  18357. byte q[CHECK_PROBABLE_PRIME_KEY_BITS / 8 / 2];
  18358. word32 qSz = (word32)sizeof(q);
  18359. int nlen = CHECK_PROBABLE_PRIME_KEY_BITS;
  18360. int* isPrime;
  18361. int test[5];
  18362. isPrime = test;
  18363. XMEMSET(&key, 0, sizeof(RsaKey));
  18364. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18365. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18366. ExpectIntEQ(wc_InitRng(&rng), 0);
  18367. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  18368. ExpectIntEQ(wc_MakeRsaKey(&key, CHECK_PROBABLE_PRIME_KEY_BITS,
  18369. WC_RSA_EXPONENT, &rng), 0);
  18370. PRIVATE_KEY_UNLOCK();
  18371. ExpectIntEQ(wc_RsaExportKey(&key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q,
  18372. &qSz), 0);
  18373. PRIVATE_KEY_LOCK();
  18374. /* Bad cases */
  18375. ExpectIntEQ(wc_CheckProbablePrime(NULL, pSz, q, qSz, e, eSz, nlen, isPrime),
  18376. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18377. ExpectIntEQ(wc_CheckProbablePrime(p, 0, q, qSz, e, eSz, nlen, isPrime),
  18378. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18379. ExpectIntEQ(wc_CheckProbablePrime(p, pSz, NULL, qSz, e, eSz, nlen, isPrime),
  18380. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18381. ExpectIntEQ(wc_CheckProbablePrime(p, pSz, q, 0, e, eSz, nlen, isPrime),
  18382. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18383. ExpectIntEQ(wc_CheckProbablePrime(p, pSz, q, qSz, NULL, eSz, nlen, isPrime),
  18384. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18385. ExpectIntEQ(wc_CheckProbablePrime(p, pSz, q, qSz, e, 0, nlen, isPrime),
  18386. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18387. ExpectIntEQ(wc_CheckProbablePrime(NULL, 0, NULL, 0, NULL, 0, nlen, isPrime),
  18388. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18389. /* Good case */
  18390. ExpectIntEQ(wc_CheckProbablePrime(p, pSz, q, qSz, e, eSz, nlen, isPrime),
  18391. 0);
  18392. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18393. wc_FreeRng(&rng);
  18394. #undef CHECK_PROBABLE_PRIME_KEY_BITS
  18395. #endif
  18396. return EXPECT_RESULT();
  18397. } /* END test_wc_CheckProbablePrime */
  18398. /*
  18399. * Testing wc_RsaPSS_Verify()
  18400. */
  18401. static int test_wc_RsaPSS_Verify(void)
  18402. {
  18403. EXPECT_DECLS;
  18404. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(HAVE_SELFTEST) && \
  18405. !defined(HAVE_FIPS) && defined(WC_RSA_BLINDING) && defined(WC_RSA_PSS)
  18406. RsaKey key;
  18407. WC_RNG rng;
  18408. int sz = 256;
  18409. const char* szMessage = "This is the string to be signed";
  18410. unsigned char pSignature[2048/8]; /* 2048 is RSA_KEY_SIZE */
  18411. unsigned char pDecrypted[2048/8];
  18412. byte* pt = pDecrypted;
  18413. word32 outLen = sizeof(pDecrypted);
  18414. XMEMSET(&key, 0, sizeof(RsaKey));
  18415. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18416. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18417. ExpectIntEQ(wc_InitRng(&rng), 0);
  18418. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  18419. ExpectIntEQ(wc_MakeRsaKey(&key, 2048, WC_RSA_EXPONENT, &rng), 0);
  18420. ExpectIntGT(sz = wc_RsaPSS_Sign((byte*)szMessage,
  18421. (word32)XSTRLEN(szMessage)+1, pSignature, sizeof(pSignature),
  18422. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key, &rng), 0);
  18423. /* Bad cases */
  18424. ExpectIntEQ(wc_RsaPSS_Verify(NULL, (word32)sz, pt, outLen,
  18425. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18426. ExpectIntEQ(wc_RsaPSS_Verify(pSignature, 0, pt, outLen,
  18427. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18428. ExpectIntEQ(wc_RsaPSS_Verify(pSignature, (word32)sz, NULL, outLen,
  18429. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18430. ExpectIntEQ(wc_RsaPSS_Verify(NULL, 0, NULL, outLen,
  18431. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18432. /* Good case */
  18433. ExpectIntGT(wc_RsaPSS_Verify(pSignature, (word32)sz, pt, outLen,
  18434. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), 0);
  18435. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18436. wc_FreeRng(&rng);
  18437. #endif
  18438. return EXPECT_RESULT();
  18439. } /* END test_wc_RsaPSS_Verify */
  18440. /*
  18441. * Testing wc_RsaPSS_VerifyCheck()
  18442. */
  18443. static int test_wc_RsaPSS_VerifyCheck(void)
  18444. {
  18445. EXPECT_DECLS;
  18446. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(HAVE_SELFTEST) && \
  18447. !defined(HAVE_FIPS) && defined(WC_RSA_BLINDING) && defined(WC_RSA_PSS)
  18448. RsaKey key;
  18449. WC_RNG rng;
  18450. int sz = 256; /* 2048/8 */
  18451. byte digest[32];
  18452. word32 digestSz = sizeof(digest);
  18453. unsigned char pSignature[2048/8]; /* 2048 is RSA_KEY_SIZE */
  18454. word32 pSignatureSz = sizeof(pSignature);
  18455. unsigned char pDecrypted[2048/8];
  18456. byte* pt = pDecrypted;
  18457. word32 outLen = sizeof(pDecrypted);
  18458. XMEMSET(&key, 0, sizeof(RsaKey));
  18459. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18460. XMEMSET(digest, 0, sizeof(digest));
  18461. XMEMSET(pSignature, 0, sizeof(pSignature));
  18462. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18463. ExpectIntEQ(wc_InitRng(&rng), 0);
  18464. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  18465. ExpectIntEQ(wc_MakeRsaKey(&key, 2048, WC_RSA_EXPONENT, &rng), 0);
  18466. ExpectTrue((digestSz = (word32)wc_HashGetDigestSize(WC_HASH_TYPE_SHA256)) > 0);
  18467. ExpectIntEQ(wc_Hash(WC_HASH_TYPE_SHA256, pSignature, (word32)sz, digest, digestSz),
  18468. 0);
  18469. ExpectIntGT(sz = wc_RsaPSS_Sign(digest, digestSz, pSignature, pSignatureSz,
  18470. WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key, &rng), 0);
  18471. /* Bad cases */
  18472. ExpectIntEQ(wc_RsaPSS_VerifyCheck(NULL, (word32)sz, pt, outLen, digest,
  18473. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18474. ExpectIntEQ(wc_RsaPSS_VerifyCheck(pSignature, 0, pt, outLen, digest,
  18475. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18476. ExpectIntEQ(wc_RsaPSS_VerifyCheck(pSignature, (word32)sz, NULL, outLen, digest,
  18477. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18478. ExpectIntEQ(wc_RsaPSS_VerifyCheck(NULL, 0, NULL, outLen, digest,
  18479. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18480. /* Good case */
  18481. ExpectIntGT(wc_RsaPSS_VerifyCheck(pSignature, (word32)sz, pt, outLen, digest,
  18482. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), 0);
  18483. ExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18484. wc_FreeRng(&rng);
  18485. #endif
  18486. return EXPECT_RESULT();
  18487. } /* END test_wc_RsaPSS_VerifyCheck */
  18488. /*
  18489. * Testing wc_RsaPSS_VerifyCheckInline()
  18490. */
  18491. static int test_wc_RsaPSS_VerifyCheckInline(void)
  18492. {
  18493. EXPECT_DECLS;
  18494. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(HAVE_SELFTEST) && \
  18495. !defined(HAVE_FIPS) && defined(WC_RSA_BLINDING) && defined(WC_RSA_PSS)
  18496. RsaKey key;
  18497. WC_RNG rng;
  18498. int sz = 256;
  18499. byte digest[32];
  18500. word32 digestSz = sizeof(digest);
  18501. unsigned char pSignature[2048/8]; /* 2048 is RSA_KEY_SIZE */
  18502. unsigned char pDecrypted[2048/8];
  18503. byte* pt = pDecrypted;
  18504. XMEMSET(&key, 0, sizeof(RsaKey));
  18505. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18506. XMEMSET(digest, 0, sizeof(digest));
  18507. XMEMSET(pSignature, 0, sizeof(pSignature));
  18508. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18509. ExpectIntEQ(wc_InitRng(&rng), 0);
  18510. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  18511. ExpectIntEQ(wc_MakeRsaKey(&key, 2048, WC_RSA_EXPONENT, &rng), 0);
  18512. ExpectTrue((digestSz = (word32)wc_HashGetDigestSize(WC_HASH_TYPE_SHA256)) > 0);
  18513. ExpectIntEQ(wc_Hash(WC_HASH_TYPE_SHA256, pSignature, (word32)sz, digest, digestSz),
  18514. 0);
  18515. ExpectIntGT(sz = wc_RsaPSS_Sign(digest, digestSz, pSignature,
  18516. sizeof(pSignature), WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key, &rng), 0);
  18517. /* Bad Cases */
  18518. ExpectIntEQ(wc_RsaPSS_VerifyCheckInline(NULL, (word32)sz, &pt, digest,
  18519. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18520. ExpectIntEQ(wc_RsaPSS_VerifyCheckInline(pSignature, 0, NULL, digest,
  18521. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18522. ExpectIntEQ(wc_RsaPSS_VerifyCheckInline(NULL, 0, &pt, digest,
  18523. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18524. ExpectIntEQ(wc_RsaPSS_VerifyCheckInline(pSignature, (word32)sz, &pt, digest,
  18525. digestSz, WC_HASH_TYPE_SHA, WC_MGF1SHA256, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18526. /* Good case */
  18527. ExpectIntGT(wc_RsaPSS_VerifyCheckInline(pSignature, (word32)sz, &pt, digest,
  18528. digestSz, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, &key), 0);
  18529. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18530. wc_FreeRng(&rng);
  18531. #endif
  18532. return EXPECT_RESULT();
  18533. } /* END test_wc_RsaPSS_VerifyCheckInline */
  18534. #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
  18535. static void sample_mutex_cb (int flag, int type, const char* file, int line)
  18536. {
  18537. (void)flag;
  18538. (void)type;
  18539. (void)file;
  18540. (void)line;
  18541. }
  18542. #endif
  18543. /*
  18544. * Testing wc_LockMutex_ex
  18545. */
  18546. static int test_wc_LockMutex_ex(void)
  18547. {
  18548. EXPECT_DECLS;
  18549. #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
  18550. int flag = CRYPTO_LOCK;
  18551. int type = 0;
  18552. const char* file = "./test-LockMutex_ex.txt";
  18553. int line = 0;
  18554. /* without SetMutexCb */
  18555. ExpectIntEQ(wc_LockMutex_ex(flag, type, file, line), WC_NO_ERR_TRACE(BAD_STATE_E));
  18556. /* with SetMutexCb */
  18557. ExpectIntEQ(wc_SetMutexCb(sample_mutex_cb), 0);
  18558. ExpectIntEQ(wc_LockMutex_ex(flag, type, file, line), 0);
  18559. ExpectIntEQ(wc_SetMutexCb(NULL), 0);
  18560. #endif
  18561. return EXPECT_RESULT();
  18562. } /* End test_wc_LockMutex_ex*/
  18563. /*
  18564. * Testing wc_SetMutexCb
  18565. */
  18566. static int test_wc_SetMutexCb(void)
  18567. {
  18568. EXPECT_DECLS;
  18569. #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER)
  18570. ExpectIntEQ(wc_SetMutexCb(sample_mutex_cb), 0);
  18571. ExpectIntEQ(wc_SetMutexCb(NULL), 0);
  18572. #endif
  18573. return EXPECT_RESULT();
  18574. } /* End test_wc_SetMutexCb*/
  18575. /*
  18576. * Testing wc_RsaKeyToDer()
  18577. */
  18578. static int test_wc_RsaKeyToDer(void)
  18579. {
  18580. EXPECT_DECLS;
  18581. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18582. RsaKey genKey;
  18583. WC_RNG rng;
  18584. byte* der = NULL;
  18585. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  18586. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4)) && \
  18587. (defined(RSA_MIN_SIZE) && (RSA_MIN_SIZE <= 1024))
  18588. int bits = 1024;
  18589. word32 derSz = 611;
  18590. /* (2 x 128) + 2 (possible leading 00) + (5 x 64) + 5 (possible leading 00)
  18591. + 3 (e) + 8 (ASN tag) + 10 (ASN length) + 4 seqSz + 3 version */
  18592. #else
  18593. int bits = 2048;
  18594. word32 derSz = 1196;
  18595. /* (2 x 256) + 2 (possible leading 00) + (5 x 128) + 5 (possible leading 00)
  18596. + 3 (e) + 8 (ASN tag) + 17 (ASN length) + 4 seqSz + 3 version */
  18597. #endif
  18598. XMEMSET(&rng, 0, sizeof(rng));
  18599. XMEMSET(&genKey, 0, sizeof(genKey));
  18600. ExpectNotNull(der = (byte*)XMALLOC(derSz, NULL, DYNAMIC_TYPE_TMP_BUFFER));
  18601. /* Init structures. */
  18602. ExpectIntEQ(wc_InitRsaKey(&genKey, HEAP_HINT), 0);
  18603. ExpectIntEQ(wc_InitRng(&rng), 0);
  18604. /* Make key. */
  18605. ExpectIntEQ(MAKE_RSA_KEY(&genKey, bits, WC_RSA_EXPONENT, &rng), 0);
  18606. ExpectIntGT(wc_RsaKeyToDer(&genKey, der, derSz), 0);
  18607. /* Pass good/bad args. */
  18608. ExpectIntEQ(wc_RsaKeyToDer(NULL, der, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18609. /* Get just the output length */
  18610. ExpectIntGT(wc_RsaKeyToDer(&genKey, NULL, 0), 0);
  18611. /* Try Public Key. */
  18612. genKey.type = 0;
  18613. ExpectIntEQ(wc_RsaKeyToDer(&genKey, der, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18614. #ifdef WOLFSSL_CHECK_MEM_ZERO
  18615. /* Put back to Private Key */
  18616. genKey.type = 1;
  18617. #endif
  18618. XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  18619. DoExpectIntEQ(wc_FreeRsaKey(&genKey), 0);
  18620. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18621. #endif
  18622. return EXPECT_RESULT();
  18623. } /* END test_wc_RsaKeyToDer */
  18624. /*
  18625. * Testing wc_RsaKeyToPublicDer()
  18626. */
  18627. static int test_wc_RsaKeyToPublicDer(void)
  18628. {
  18629. EXPECT_DECLS;
  18630. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18631. RsaKey key;
  18632. WC_RNG rng;
  18633. byte* der = NULL;
  18634. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  18635. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4)) && \
  18636. (defined(RSA_MIN_SIZE) && (RSA_MIN_SIZE <= 1024))
  18637. int bits = 1024;
  18638. word32 derLen = 162;
  18639. #else
  18640. int bits = 2048;
  18641. word32 derLen = 294;
  18642. #endif
  18643. int ret = 0;
  18644. XMEMSET(&rng, 0, sizeof(rng));
  18645. XMEMSET(&key, 0, sizeof(key));
  18646. ExpectNotNull(der = (byte*)XMALLOC(derLen, NULL, DYNAMIC_TYPE_TMP_BUFFER));
  18647. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18648. ExpectIntEQ(wc_InitRng(&rng), 0);
  18649. ExpectIntEQ(MAKE_RSA_KEY(&key, bits, WC_RSA_EXPONENT, &rng), 0);
  18650. /* test getting size only */
  18651. ExpectIntGT(wc_RsaKeyToPublicDer(&key, NULL, derLen), 0);
  18652. ExpectIntGT(wc_RsaKeyToPublicDer(&key, der, derLen), 0);
  18653. /* test getting size only */
  18654. ExpectIntGT(wc_RsaKeyToPublicDer_ex(&key, NULL, derLen, 0), 0);
  18655. ExpectIntGT(wc_RsaKeyToPublicDer_ex(&key, der, derLen, 0), 0);
  18656. /* Pass in bad args. */
  18657. ExpectIntEQ(wc_RsaKeyToPublicDer(NULL, der, derLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18658. ExpectIntLT(ret = wc_RsaKeyToPublicDer(&key, der, -1), 0);
  18659. ExpectTrue((ret == WC_NO_ERR_TRACE(BUFFER_E)) || (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)));
  18660. XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  18661. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18662. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18663. #endif
  18664. return EXPECT_RESULT();
  18665. } /* END test_wc_RsaKeyToPublicDer */
  18666. /*
  18667. * Testing wc_RsaPublicEncrypt() and wc_RsaPrivateDecrypt()
  18668. */
  18669. static int test_wc_RsaPublicEncryptDecrypt(void)
  18670. {
  18671. EXPECT_DECLS;
  18672. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18673. RsaKey key;
  18674. WC_RNG rng;
  18675. const char inStr[] = TEST_STRING;
  18676. const word32 plainLen = (word32)TEST_STRING_SZ;
  18677. const word32 inLen = (word32)TEST_STRING_SZ;
  18678. int bits = TEST_RSA_BITS;
  18679. const word32 cipherLen = TEST_RSA_BYTES;
  18680. word32 cipherLenResult = cipherLen;
  18681. WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, NULL);
  18682. WC_DECLARE_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18683. WC_DECLARE_VAR(cipher, byte, TEST_RSA_BYTES, NULL);
  18684. WC_ALLOC_VAR(in, byte, TEST_STRING_SZ, NULL);
  18685. WC_ALLOC_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18686. WC_ALLOC_VAR(cipher, byte, TEST_RSA_BYTES, NULL);
  18687. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  18688. ExpectNotNull(in);
  18689. ExpectNotNull(plain);
  18690. ExpectNotNull(cipher);
  18691. #endif
  18692. ExpectNotNull(XMEMCPY(in, inStr, inLen));
  18693. /* Initialize stack structures. */
  18694. XMEMSET(&key, 0, sizeof(RsaKey));
  18695. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18696. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18697. ExpectIntEQ(wc_InitRng(&rng), 0);
  18698. ExpectIntEQ(MAKE_RSA_KEY(&key, bits, WC_RSA_EXPONENT, &rng), 0);
  18699. /* Encrypt. */
  18700. ExpectIntGT(cipherLenResult = (word32)wc_RsaPublicEncrypt(in, inLen, cipher,
  18701. cipherLen, &key, &rng), 0);
  18702. /* Pass bad args - tested in another testing function.*/
  18703. /* Decrypt */
  18704. #if defined(WC_RSA_BLINDING) && !defined(HAVE_FIPS)
  18705. /* Bind rng */
  18706. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  18707. #endif
  18708. ExpectIntGE(wc_RsaPrivateDecrypt(cipher, cipherLenResult, plain, plainLen,
  18709. &key), 0);
  18710. ExpectIntEQ(XMEMCMP(plain, inStr, plainLen), 0);
  18711. /* Pass bad args - tested in another testing function.*/
  18712. WC_FREE_VAR(in, NULL);
  18713. WC_FREE_VAR(plain, NULL);
  18714. WC_FREE_VAR(cipher, NULL);
  18715. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18716. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18717. #endif
  18718. return EXPECT_RESULT();
  18719. } /* END test_wc_RsaPublicEncryptDecrypt */
  18720. /*
  18721. * Testing wc_RsaPrivateDecrypt_ex() and wc_RsaPrivateDecryptInline_ex()
  18722. */
  18723. static int test_wc_RsaPublicEncryptDecrypt_ex(void)
  18724. {
  18725. EXPECT_DECLS;
  18726. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(HAVE_FIPS)\
  18727. && !defined(WC_NO_RSA_OAEP) && !defined(NO_SHA256)
  18728. RsaKey key;
  18729. WC_RNG rng;
  18730. const char inStr[] = TEST_STRING;
  18731. const word32 inLen = (word32)TEST_STRING_SZ;
  18732. const word32 plainSz = (word32)TEST_STRING_SZ;
  18733. byte* res = NULL;
  18734. int idx = 0;
  18735. int bits = TEST_RSA_BITS;
  18736. const word32 cipherSz = TEST_RSA_BYTES;
  18737. WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, NULL);
  18738. WC_DECLARE_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18739. WC_DECLARE_VAR(cipher, byte, TEST_RSA_BYTES, NULL);
  18740. WC_ALLOC_VAR(in, byte, TEST_STRING_SZ, NULL);
  18741. WC_ALLOC_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18742. WC_ALLOC_VAR(cipher, byte, TEST_RSA_BYTES, NULL);
  18743. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  18744. ExpectNotNull(in);
  18745. ExpectNotNull(plain);
  18746. ExpectNotNull(cipher);
  18747. #endif
  18748. ExpectNotNull(XMEMCPY(in, inStr, inLen));
  18749. /* Initialize stack structures. */
  18750. XMEMSET(&key, 0, sizeof(RsaKey));
  18751. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18752. ExpectIntEQ(wc_InitRsaKey_ex(&key, HEAP_HINT, INVALID_DEVID), 0);
  18753. ExpectIntEQ(wc_InitRng(&rng), 0);
  18754. ExpectIntEQ(MAKE_RSA_KEY(&key, bits, WC_RSA_EXPONENT, &rng), 0);
  18755. /* Encrypt */
  18756. ExpectIntGE(idx = wc_RsaPublicEncrypt_ex(in, inLen, cipher, cipherSz, &key,
  18757. &rng, WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0), 0);
  18758. /* Pass bad args - tested in another testing function.*/
  18759. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18760. /* Decrypt */
  18761. #if defined(WC_RSA_BLINDING) && !defined(HAVE_FIPS)
  18762. ExpectIntEQ(wc_RsaSetRNG(&key, &rng), 0);
  18763. #endif
  18764. ExpectIntGE(wc_RsaPrivateDecrypt_ex(cipher, (word32)idx, plain, plainSz,
  18765. &key, WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0), 0);
  18766. ExpectIntEQ(XMEMCMP(plain, inStr, plainSz), 0);
  18767. /* Pass bad args - tested in another testing function.*/
  18768. ExpectIntGE(wc_RsaPrivateDecryptInline_ex(cipher, (word32)idx, &res, &key,
  18769. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0), 0);
  18770. ExpectIntEQ(XMEMCMP(inStr, res, plainSz), 0);
  18771. #endif
  18772. WC_FREE_VAR(in, NULL);
  18773. WC_FREE_VAR(plain, NULL);
  18774. WC_FREE_VAR(cipher, NULL);
  18775. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18776. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18777. #endif
  18778. return EXPECT_RESULT();
  18779. } /* END test_wc_RsaPublicEncryptDecrypt_ex */
  18780. /*
  18781. * Tesing wc_RsaSSL_Sign() and wc_RsaSSL_Verify()
  18782. */
  18783. static int test_wc_RsaSSL_SignVerify(void)
  18784. {
  18785. EXPECT_DECLS;
  18786. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18787. RsaKey key;
  18788. WC_RNG rng;
  18789. const char inStr[] = TEST_STRING;
  18790. const word32 plainSz = (word32)TEST_STRING_SZ;
  18791. const word32 inLen = (word32)TEST_STRING_SZ;
  18792. word32 idx = 0;
  18793. int bits = TEST_RSA_BITS;
  18794. const word32 outSz = TEST_RSA_BYTES;
  18795. WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, NULL);
  18796. WC_DECLARE_VAR(out, byte, TEST_RSA_BYTES, NULL);
  18797. WC_DECLARE_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18798. WC_ALLOC_VAR(in, byte, TEST_STRING_SZ, NULL);
  18799. WC_ALLOC_VAR(out, byte, TEST_RSA_BYTES, NULL);
  18800. WC_ALLOC_VAR(plain, byte, TEST_STRING_SZ, NULL);
  18801. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  18802. ExpectNotNull(in);
  18803. ExpectNotNull(out);
  18804. ExpectNotNull(plain);
  18805. #endif
  18806. ExpectNotNull(XMEMCPY(in, inStr, inLen));
  18807. XMEMSET(&key, 0, sizeof(RsaKey));
  18808. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18809. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18810. ExpectIntEQ(wc_InitRng(&rng), 0);
  18811. ExpectIntEQ(MAKE_RSA_KEY(&key, bits, WC_RSA_EXPONENT, &rng), 0);
  18812. /* Sign. */
  18813. ExpectIntEQ(wc_RsaSSL_Sign(in, inLen, out, outSz, &key, &rng), (int)outSz);
  18814. idx = (int)outSz;
  18815. /* Test bad args. */
  18816. ExpectIntEQ(wc_RsaSSL_Sign(NULL, inLen, out, outSz, &key, &rng),
  18817. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18818. ExpectIntEQ(wc_RsaSSL_Sign(in, 0, out, outSz, &key, &rng),
  18819. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18820. ExpectIntEQ(wc_RsaSSL_Sign(in, inLen, NULL, outSz, &key, &rng),
  18821. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18822. ExpectIntEQ(wc_RsaSSL_Sign(in, inLen, out, outSz, NULL, &rng),
  18823. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18824. /* Verify. */
  18825. ExpectIntEQ(wc_RsaSSL_Verify(out, idx, plain, plainSz, &key), (int)inLen);
  18826. /* Pass bad args. */
  18827. ExpectIntEQ(wc_RsaSSL_Verify(NULL, idx, plain, plainSz, &key),
  18828. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18829. ExpectIntEQ(wc_RsaSSL_Verify(out, 0, plain, plainSz, &key),
  18830. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18831. ExpectIntEQ(wc_RsaSSL_Verify(out, idx, NULL, plainSz, &key),
  18832. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18833. ExpectIntEQ(wc_RsaSSL_Verify(out, idx, plain, plainSz, NULL),
  18834. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18835. WC_FREE_VAR(in, NULL);
  18836. WC_FREE_VAR(out, NULL);
  18837. WC_FREE_VAR(plain, NULL);
  18838. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18839. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18840. #endif
  18841. return EXPECT_RESULT();
  18842. } /* END test_wc_RsaSSL_SignVerify */
  18843. /*
  18844. * Testing wc_RsaEncryptSize()
  18845. */
  18846. static int test_wc_RsaEncryptSize(void)
  18847. {
  18848. EXPECT_DECLS;
  18849. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18850. RsaKey key;
  18851. WC_RNG rng;
  18852. XMEMSET(&key, 0, sizeof(RsaKey));
  18853. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18854. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18855. ExpectIntEQ(wc_InitRng(&rng), 0);
  18856. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  18857. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4)) && \
  18858. (defined(RSA_MIN_SIZE) && (RSA_MIN_SIZE <= 1024))
  18859. ExpectIntEQ(MAKE_RSA_KEY(&key, 1024, WC_RSA_EXPONENT, &rng), 0);
  18860. ExpectIntEQ(wc_RsaEncryptSize(&key), 128);
  18861. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18862. #endif
  18863. ExpectIntEQ(MAKE_RSA_KEY(&key, 2048, WC_RSA_EXPONENT, &rng), 0);
  18864. ExpectIntEQ(wc_RsaEncryptSize(&key), 256);
  18865. /* Pass in bad arg. */
  18866. ExpectIntEQ(wc_RsaEncryptSize(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18867. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18868. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18869. #endif
  18870. return EXPECT_RESULT();
  18871. } /* END test_wc_RsaEncryptSize*/
  18872. /*
  18873. * Testing wc_RsaFlattenPublicKey()
  18874. */
  18875. static int test_wc_RsaFlattenPublicKey(void)
  18876. {
  18877. EXPECT_DECLS;
  18878. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  18879. RsaKey key;
  18880. WC_RNG rng;
  18881. byte e[256];
  18882. byte n[256];
  18883. word32 eSz = sizeof(e);
  18884. word32 nSz = sizeof(n);
  18885. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  18886. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 4)) && \
  18887. (defined(RSA_MIN_SIZE) && (RSA_MIN_SIZE <= 1024))
  18888. int bits = 1024;
  18889. #else
  18890. int bits = 2048;
  18891. #endif
  18892. XMEMSET(&key, 0, sizeof(RsaKey));
  18893. XMEMSET(&rng, 0, sizeof(WC_RNG));
  18894. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  18895. ExpectIntEQ(wc_InitRng(&rng), 0);
  18896. ExpectIntEQ(MAKE_RSA_KEY(&key, bits, WC_RSA_EXPONENT, &rng), 0);
  18897. ExpectIntEQ(wc_RsaFlattenPublicKey(&key, e, &eSz, n, &nSz), 0);
  18898. /* Pass bad args. */
  18899. ExpectIntEQ(wc_RsaFlattenPublicKey(NULL, e, &eSz, n, &nSz),
  18900. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18901. ExpectIntEQ(wc_RsaFlattenPublicKey(&key, NULL, &eSz, n, &nSz),
  18902. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18903. ExpectIntEQ(wc_RsaFlattenPublicKey(&key, e, NULL, n, &nSz),
  18904. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18905. ExpectIntEQ(wc_RsaFlattenPublicKey(&key, e, &eSz, NULL, &nSz),
  18906. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18907. ExpectIntEQ(wc_RsaFlattenPublicKey(&key, e, &eSz, n, NULL),
  18908. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18909. DoExpectIntEQ(wc_FreeRsaKey(&key), 0);
  18910. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  18911. #endif
  18912. return EXPECT_RESULT();
  18913. } /* END test_wc_RsaFlattenPublicKey */
  18914. /*
  18915. * unit test for wc_AesCcmSetKey
  18916. */
  18917. static int test_wc_AesCcmSetKey(void)
  18918. {
  18919. EXPECT_DECLS;
  18920. #ifdef HAVE_AESCCM
  18921. Aes aes;
  18922. const byte key16[] = {
  18923. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
  18924. 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf
  18925. };
  18926. const byte key24[] = {
  18927. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  18928. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  18929. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37
  18930. };
  18931. const byte key32[] = {
  18932. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  18933. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  18934. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  18935. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66
  18936. };
  18937. XMEMSET(&aes, 0, sizeof(Aes));
  18938. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  18939. #ifdef WOLFSSL_AES_128
  18940. ExpectIntEQ(wc_AesCcmSetKey(&aes, key16, sizeof(key16)), 0);
  18941. #endif
  18942. #ifdef WOLFSSL_AES_192
  18943. ExpectIntEQ(wc_AesCcmSetKey(&aes, key24, sizeof(key24)), 0);
  18944. #endif
  18945. #ifdef WOLFSSL_AES_256
  18946. ExpectIntEQ(wc_AesCcmSetKey(&aes, key32, sizeof(key32)), 0);
  18947. #endif
  18948. /* Test bad args. */
  18949. ExpectIntEQ(wc_AesCcmSetKey(&aes, key16, sizeof(key16) - 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18950. ExpectIntEQ(wc_AesCcmSetKey(&aes, key24, sizeof(key24) - 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18951. ExpectIntEQ(wc_AesCcmSetKey(&aes, key32, sizeof(key32) - 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  18952. wc_AesFree(&aes);
  18953. #endif
  18954. return EXPECT_RESULT();
  18955. } /* END test_wc_AesCcmSetKey */
  18956. /*
  18957. * Unit test function for wc_AesCcmEncrypt and wc_AesCcmDecrypt
  18958. */
  18959. static int test_wc_AesCcmEncryptDecrypt(void)
  18960. {
  18961. EXPECT_DECLS;
  18962. #if defined(HAVE_AESCCM) && defined(WOLFSSL_AES_128)
  18963. Aes aes;
  18964. const byte key16[] = {
  18965. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
  18966. 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf
  18967. };
  18968. /* plaintext */
  18969. const byte plainT[] = {
  18970. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  18971. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  18972. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e
  18973. };
  18974. /* nonce */
  18975. const byte iv[] = {
  18976. 0x00, 0x00, 0x00, 0x03, 0x02, 0x01, 0x00, 0xa0,
  18977. 0xa1, 0xa2, 0xa3, 0xa4, 0xa5
  18978. };
  18979. const byte c[] = { /* cipher text. */
  18980. 0x58, 0x8c, 0x97, 0x9a, 0x61, 0xc6, 0x63, 0xd2,
  18981. 0xf0, 0x66, 0xd0, 0xc2, 0xc0, 0xf9, 0x89, 0x80,
  18982. 0x6d, 0x5f, 0x6b, 0x61, 0xda, 0xc3, 0x84
  18983. };
  18984. const byte t[] = { /* Auth tag */
  18985. 0x17, 0xe8, 0xd1, 0x2c, 0xfd, 0xf9, 0x26, 0xe0
  18986. };
  18987. const byte authIn[] = {
  18988. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
  18989. };
  18990. byte cipherOut[sizeof(plainT)];
  18991. byte authTag[sizeof(t)];
  18992. #ifdef HAVE_AES_DECRYPT
  18993. byte plainOut[sizeof(cipherOut)];
  18994. #endif
  18995. XMEMSET(&aes, 0, sizeof(Aes));
  18996. ExpectIntEQ(wc_AesInit(&aes, NULL, INVALID_DEVID), 0);
  18997. ExpectIntEQ(wc_AesCcmSetKey(&aes, key16, sizeof(key16)), 0);
  18998. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, plainT, sizeof(cipherOut),
  18999. iv, sizeof(iv), authTag, sizeof(authTag), authIn , sizeof(authIn)), 0);
  19000. ExpectIntEQ(XMEMCMP(cipherOut, c, sizeof(c)), 0);
  19001. ExpectIntEQ(XMEMCMP(t, authTag, sizeof(t)), 0);
  19002. #ifdef HAVE_AES_DECRYPT
  19003. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, cipherOut, sizeof(plainOut),
  19004. iv, sizeof(iv), authTag, sizeof(authTag), authIn, sizeof(authIn)), 0);
  19005. ExpectIntEQ(XMEMCMP(plainOut, plainT, sizeof(plainT)), 0);
  19006. #endif
  19007. /* Pass in bad args. Encrypt*/
  19008. ExpectIntEQ(wc_AesCcmEncrypt(NULL, cipherOut, plainT, sizeof(cipherOut),
  19009. iv, sizeof(iv), authTag, sizeof(authTag), authIn , sizeof(authIn)),
  19010. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19011. ExpectIntEQ(wc_AesCcmEncrypt(&aes, NULL, plainT, sizeof(cipherOut),
  19012. iv, sizeof(iv), authTag, sizeof(authTag), authIn , sizeof(authIn)),
  19013. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19014. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, NULL, sizeof(cipherOut),
  19015. iv, sizeof(iv), authTag, sizeof(authTag), authIn , sizeof(authIn)),
  19016. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19017. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, plainT, sizeof(cipherOut),
  19018. NULL, sizeof(iv), authTag, sizeof(authTag), authIn , sizeof(authIn)),
  19019. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19020. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, plainT, sizeof(cipherOut),
  19021. iv, sizeof(iv), NULL, sizeof(authTag), authIn , sizeof(authIn)),
  19022. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19023. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, plainT, sizeof(cipherOut),
  19024. iv, sizeof(iv) + 1, authTag, sizeof(authTag), authIn , sizeof(authIn)),
  19025. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19026. ExpectIntEQ(wc_AesCcmEncrypt(&aes, cipherOut, plainT, sizeof(cipherOut),
  19027. iv, sizeof(iv) - 7, authTag, sizeof(authTag), authIn , sizeof(authIn)),
  19028. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19029. #ifdef HAVE_AES_DECRYPT
  19030. /* Pass in bad args. Decrypt*/
  19031. ExpectIntEQ(wc_AesCcmDecrypt(NULL, plainOut, cipherOut, sizeof(plainOut),
  19032. iv, sizeof(iv), authTag, sizeof(authTag), authIn, sizeof(authIn)),
  19033. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19034. ExpectIntEQ(wc_AesCcmDecrypt(&aes, NULL, cipherOut, sizeof(plainOut),
  19035. iv, sizeof(iv), authTag, sizeof(authTag), authIn, sizeof(authIn)),
  19036. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19037. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, NULL, sizeof(plainOut),
  19038. iv, sizeof(iv), authTag, sizeof(authTag), authIn, sizeof(authIn)),
  19039. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19040. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, cipherOut, sizeof(plainOut),
  19041. NULL, sizeof(iv), authTag, sizeof(authTag), authIn, sizeof(authIn)),
  19042. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19043. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, cipherOut, sizeof(plainOut),
  19044. iv, sizeof(iv), NULL, sizeof(authTag), authIn, sizeof(authIn)),
  19045. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19046. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, cipherOut, sizeof(plainOut),
  19047. iv, sizeof(iv) + 1, authTag, sizeof(authTag), authIn, sizeof(authIn)),
  19048. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19049. ExpectIntEQ(wc_AesCcmDecrypt(&aes, plainOut, cipherOut, sizeof(plainOut),
  19050. iv, sizeof(iv) - 7, authTag, sizeof(authTag), authIn, sizeof(authIn)),
  19051. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  19052. #endif
  19053. wc_AesFree(&aes);
  19054. #endif /* HAVE_AESCCM */
  19055. return EXPECT_RESULT();
  19056. } /* END test_wc_AesCcmEncryptDecrypt */
  19057. #if defined(WOLFSSL_AES_EAX) && \
  19058. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  19059. /*
  19060. * Testing test_wc_AesEaxVectors()
  19061. */
  19062. static int test_wc_AesEaxVectors(void)
  19063. {
  19064. EXPECT_DECLS;
  19065. typedef struct {
  19066. byte key[AES_256_KEY_SIZE];
  19067. int key_length;
  19068. byte iv[AES_BLOCK_SIZE];
  19069. int iv_length;
  19070. byte aad[AES_BLOCK_SIZE * 2];
  19071. int aad_length;
  19072. byte msg[AES_BLOCK_SIZE * 5];
  19073. int msg_length;
  19074. byte ct[AES_BLOCK_SIZE * 5];
  19075. int ct_length;
  19076. byte tag[AES_BLOCK_SIZE];
  19077. int tag_length;
  19078. int valid;
  19079. } AadVector;
  19080. /* Test vectors obtained from Google wycheproof project
  19081. * https://github.com/google/wycheproof
  19082. * from testvectors/aes_eax_test.json
  19083. */
  19084. const AadVector vectors[] = {
  19085. {
  19086. /* key, key length */
  19087. {0x23, 0x39, 0x52, 0xde, 0xe4, 0xd5, 0xed, 0x5f,
  19088. 0x9b, 0x9c, 0x6d, 0x6f, 0xf8, 0x0f, 0xf4, 0x78}, 16,
  19089. /* iv, iv length */
  19090. {0x62, 0xec, 0x67, 0xf9, 0xc3, 0xa4, 0xa4, 0x07,
  19091. 0xfc, 0xb2, 0xa8, 0xc4, 0x90, 0x31, 0xa8, 0xb3}, 16,
  19092. /* aad, aad length */
  19093. {0x6b, 0xfb, 0x91, 0x4f, 0xd0, 0x7e, 0xae, 0x6b}, 8,
  19094. /* msg, msg length */
  19095. {0x00}, 0,
  19096. /* ct, ct length */
  19097. {0x00}, 0,
  19098. /* tag, tag length */
  19099. {0xe0, 0x37, 0x83, 0x0e, 0x83, 0x89, 0xf2, 0x7b,
  19100. 0x02, 0x5a, 0x2d, 0x65, 0x27, 0xe7, 0x9d, 0x01}, 16,
  19101. /* valid */
  19102. 1,
  19103. },
  19104. {
  19105. /* key, key length */
  19106. {0x91, 0x94, 0x5d, 0x3f, 0x4d, 0xcb, 0xee, 0x0b,
  19107. 0xf4, 0x5e, 0xf5, 0x22, 0x55, 0xf0, 0x95, 0xa4}, 16,
  19108. /* iv, iv length */
  19109. {0xbe, 0xca, 0xf0, 0x43, 0xb0, 0xa2, 0x3d, 0x84,
  19110. 0x31, 0x94, 0xba, 0x97, 0x2c, 0x66, 0xde, 0xbd}, 16,
  19111. /* aad, aad length */
  19112. {0xfa, 0x3b, 0xfd, 0x48, 0x06, 0xeb, 0x53, 0xfa}, 8,
  19113. /* msg, msg length */
  19114. {0xf7, 0xfb}, 2,
  19115. /* ct, ct length */
  19116. {0x19, 0xdd}, 2,
  19117. /* tag, tag length */
  19118. {0x5c, 0x4c, 0x93, 0x31, 0x04, 0x9d, 0x0b, 0xda,
  19119. 0xb0, 0x27, 0x74, 0x08, 0xf6, 0x79, 0x67, 0xe5}, 16,
  19120. /* valid */
  19121. 1,
  19122. },
  19123. {
  19124. /* key, key length */
  19125. {0x01, 0xf7, 0x4a, 0xd6, 0x40, 0x77, 0xf2, 0xe7,
  19126. 0x04, 0xc0, 0xf6, 0x0a, 0xda, 0x3d, 0xd5, 0x23}, 16,
  19127. /* iv, iv length */
  19128. {0x70, 0xc3, 0xdb, 0x4f, 0x0d, 0x26, 0x36, 0x84,
  19129. 0x00, 0xa1, 0x0e, 0xd0, 0x5d, 0x2b, 0xff, 0x5e}, 16,
  19130. /* aad, aad length */
  19131. {0x23, 0x4a, 0x34, 0x63, 0xc1, 0x26, 0x4a, 0xc6}, 8,
  19132. /* msg, msg length */
  19133. {0x1a, 0x47, 0xcb, 0x49, 0x33}, 5,
  19134. /* ct, ct length */
  19135. {0xd8, 0x51, 0xd5, 0xba, 0xe0}, 5,
  19136. /* tag, tag length */
  19137. {0x3a, 0x59, 0xf2, 0x38, 0xa2, 0x3e, 0x39, 0x19,
  19138. 0x9d, 0xc9, 0x26, 0x66, 0x26, 0xc4, 0x0f, 0x80}, 16,
  19139. /* valid */
  19140. 1,
  19141. },
  19142. {
  19143. /* key, key length */
  19144. {0xd0, 0x7c, 0xf6, 0xcb, 0xb7, 0xf3, 0x13, 0xbd,
  19145. 0xde, 0x66, 0xb7, 0x27, 0xaf, 0xd3, 0xc5, 0xe8}, 16,
  19146. /* iv, iv length */
  19147. {0x84, 0x08, 0xdf, 0xff, 0x3c, 0x1a, 0x2b, 0x12,
  19148. 0x92, 0xdc, 0x19, 0x9e, 0x46, 0xb7, 0xd6, 0x17}, 16,
  19149. /* aad, aad length */
  19150. {0x33, 0xcc, 0xe2, 0xea, 0xbf, 0xf5, 0xa7, 0x9d}, 8,
  19151. /* msg, msg length */
  19152. {0x48, 0x1c, 0x9e, 0x39, 0xb1}, 5,
  19153. /* ct, ct length */
  19154. {0x63, 0x2a, 0x9d, 0x13, 0x1a}, 5,
  19155. /* tag, tag length */
  19156. {0xd4, 0xc1, 0x68, 0xa4, 0x22, 0x5d, 0x8e, 0x1f,
  19157. 0xf7, 0x55, 0x93, 0x99, 0x74, 0xa7, 0xbe, 0xde}, 16,
  19158. /* valid */
  19159. 1,
  19160. },
  19161. {
  19162. /* key, key length */
  19163. {0x35, 0xb6, 0xd0, 0x58, 0x00, 0x05, 0xbb, 0xc1,
  19164. 0x2b, 0x05, 0x87, 0x12, 0x45, 0x57, 0xd2, 0xc2}, 16,
  19165. /* iv, iv length */
  19166. {0xfd, 0xb6, 0xb0, 0x66, 0x76, 0xee, 0xdc, 0x5c,
  19167. 0x61, 0xd7, 0x42, 0x76, 0xe1, 0xf8, 0xe8, 0x16}, 16,
  19168. /* aad, aad length */
  19169. {0xae, 0xb9, 0x6e, 0xae, 0xbe, 0x29, 0x70, 0xe9}, 8,
  19170. /* msg, msg length */
  19171. {0x40, 0xd0, 0xc0, 0x7d, 0xa5, 0xe4}, 6,
  19172. /* ct, ct length */
  19173. {0x07, 0x1d, 0xfe, 0x16, 0xc6, 0x75}, 6,
  19174. /* tag, tag length */
  19175. {0xcb, 0x06, 0x77, 0xe5, 0x36, 0xf7, 0x3a, 0xfe,
  19176. 0x6a, 0x14, 0xb7, 0x4e, 0xe4, 0x98, 0x44, 0xdd}, 16,
  19177. /* valid */
  19178. 1,
  19179. },
  19180. {
  19181. /* key, key length */
  19182. {0xbd, 0x8e, 0x6e, 0x11, 0x47, 0x5e, 0x60, 0xb2,
  19183. 0x68, 0x78, 0x4c, 0x38, 0xc6, 0x2f, 0xeb, 0x22}, 16,
  19184. /* iv, iv length */
  19185. {0x6e, 0xac, 0x5c, 0x93, 0x07, 0x2d, 0x8e, 0x85,
  19186. 0x13, 0xf7, 0x50, 0x93, 0x5e, 0x46, 0xda, 0x1b}, 16,
  19187. /* aad, aad length */
  19188. {0xd4, 0x48, 0x2d, 0x1c, 0xa7, 0x8d, 0xce, 0x0f}, 8,
  19189. /* msg, msg length */
  19190. {0x4d, 0xe3, 0xb3, 0x5c, 0x3f, 0xc0, 0x39, 0x24,
  19191. 0x5b, 0xd1, 0xfb, 0x7d}, 12,
  19192. /* ct, ct length */
  19193. {0x83, 0x5b, 0xb4, 0xf1, 0x5d, 0x74, 0x3e, 0x35,
  19194. 0x0e, 0x72, 0x84, 0x14}, 12,
  19195. /* tag, tag length */
  19196. {0xab, 0xb8, 0x64, 0x4f, 0xd6, 0xcc, 0xb8, 0x69,
  19197. 0x47, 0xc5, 0xe1, 0x05, 0x90, 0x21, 0x0a, 0x4f}, 16,
  19198. /* valid */
  19199. 1,
  19200. },
  19201. {
  19202. /* key, key length */
  19203. {0x7c, 0x77, 0xd6, 0xe8, 0x13, 0xbe, 0xd5, 0xac,
  19204. 0x98, 0xba, 0xa4, 0x17, 0x47, 0x7a, 0x2e, 0x7d}, 16,
  19205. /* iv, iv length */
  19206. {0x1a, 0x8c, 0x98, 0xdc, 0xd7, 0x3d, 0x38, 0x39,
  19207. 0x3b, 0x2b, 0xf1, 0x56, 0x9d, 0xee, 0xfc, 0x19}, 16,
  19208. /* aad, aad length */
  19209. {0x65, 0xd2, 0x01, 0x79, 0x90, 0xd6, 0x25, 0x28}, 8,
  19210. /* msg, msg length */
  19211. {0x8b, 0x0a, 0x79, 0x30, 0x6c, 0x9c, 0xe7, 0xed,
  19212. 0x99, 0xda, 0xe4, 0xf8, 0x7f, 0x8d, 0xd6, 0x16,
  19213. 0x36}, 17,
  19214. /* ct, ct length */
  19215. {0x02, 0x08, 0x3e, 0x39, 0x79, 0xda, 0x01, 0x48,
  19216. 0x12, 0xf5, 0x9f, 0x11, 0xd5, 0x26, 0x30, 0xda,
  19217. 0x30}, 17,
  19218. /* tag, tag length */
  19219. {0x13, 0x73, 0x27, 0xd1, 0x06, 0x49, 0xb0, 0xaa,
  19220. 0x6e, 0x1c, 0x18, 0x1d, 0xb6, 0x17, 0xd7, 0xf2}, 16,
  19221. /* valid */
  19222. 1,
  19223. },
  19224. {
  19225. /* key, key length */
  19226. {0x5f, 0xff, 0x20, 0xca, 0xfa, 0xb1, 0x19, 0xca,
  19227. 0x2f, 0xc7, 0x35, 0x49, 0xe2, 0x0f, 0x5b, 0x0d}, 16,
  19228. /* iv, iv length */
  19229. {0xdd, 0xe5, 0x9b, 0x97, 0xd7, 0x22, 0x15, 0x6d,
  19230. 0x4d, 0x9a, 0xff, 0x2b, 0xc7, 0x55, 0x98, 0x26}, 16,
  19231. /* aad, aad length */
  19232. {0x54, 0xb9, 0xf0, 0x4e, 0x6a, 0x09, 0x18, 0x9a}, 8,
  19233. /* msg, msg length */
  19234. {0x1b, 0xda, 0x12, 0x2b, 0xce, 0x8a, 0x8d, 0xba,
  19235. 0xf1, 0x87, 0x7d, 0x96, 0x2b, 0x85, 0x92, 0xdd,
  19236. 0x2d, 0x56}, 18,
  19237. /* ct, ct length */
  19238. {0x2e, 0xc4, 0x7b, 0x2c, 0x49, 0x54, 0xa4, 0x89,
  19239. 0xaf, 0xc7, 0xba, 0x48, 0x97, 0xed, 0xcd, 0xae,
  19240. 0x8c, 0xc3}, 18,
  19241. /* tag, tag length */
  19242. {0x3b, 0x60, 0x45, 0x05, 0x99, 0xbd, 0x02, 0xc9,
  19243. 0x63, 0x82, 0x90, 0x2a, 0xef, 0x7f, 0x83, 0x2a}, 16,
  19244. /* valid */
  19245. 1,
  19246. },
  19247. {
  19248. /* key, key length */
  19249. {0xa4, 0xa4, 0x78, 0x2b, 0xcf, 0xfd, 0x3e, 0xc5,
  19250. 0xe7, 0xef, 0x6d, 0x8c, 0x34, 0xa5, 0x61, 0x23}, 16,
  19251. /* iv, iv length */
  19252. {0xb7, 0x81, 0xfc, 0xf2, 0xf7, 0x5f, 0xa5, 0xa8,
  19253. 0xde, 0x97, 0xa9, 0xca, 0x48, 0xe5, 0x22, 0xec}, 16,
  19254. /* aad, aad length */
  19255. {0x89, 0x9a, 0x17, 0x58, 0x97, 0x56, 0x1d, 0x7e}, 8,
  19256. /* msg, msg length */
  19257. {0x6c, 0xf3, 0x67, 0x20, 0x87, 0x2b, 0x85, 0x13,
  19258. 0xf6, 0xea, 0xb1, 0xa8, 0xa4, 0x44, 0x38, 0xd5,
  19259. 0xef, 0x11}, 18,
  19260. /* ct, ct length */
  19261. {0x0d, 0xe1, 0x8f, 0xd0, 0xfd, 0xd9, 0x1e, 0x7a,
  19262. 0xf1, 0x9f, 0x1d, 0x8e, 0xe8, 0x73, 0x39, 0x38,
  19263. 0xb1, 0xe8}, 18,
  19264. /* tag, tag length */
  19265. {0xe7, 0xf6, 0xd2, 0x23, 0x16, 0x18, 0x10, 0x2f,
  19266. 0xdb, 0x7f, 0xe5, 0x5f, 0xf1, 0x99, 0x17, 0x00}, 16,
  19267. /* valid */
  19268. 1,
  19269. },
  19270. {
  19271. /* key, key length */
  19272. {0x83, 0x95, 0xfc, 0xf1, 0xe9, 0x5b, 0xeb, 0xd6,
  19273. 0x97, 0xbd, 0x01, 0x0b, 0xc7, 0x66, 0xaa, 0xc3}, 16,
  19274. /* iv, iv length */
  19275. {0x22, 0xe7, 0xad, 0xd9, 0x3c, 0xfc, 0x63, 0x93,
  19276. 0xc5, 0x7e, 0xc0, 0xb3, 0xc1, 0x7d, 0x6b, 0x44}, 16,
  19277. /* aad, aad length */
  19278. {0x12, 0x67, 0x35, 0xfc, 0xc3, 0x20, 0xd2, 0x5a}, 8,
  19279. /* msg, msg length */
  19280. {0xca, 0x40, 0xd7, 0x44, 0x6e, 0x54, 0x5f, 0xfa,
  19281. 0xed, 0x3b, 0xd1, 0x2a, 0x74, 0x0a, 0x65, 0x9f,
  19282. 0xfb, 0xbb, 0x3c, 0xea, 0xb7}, 21,
  19283. /* ct, ct length */
  19284. {0xcb, 0x89, 0x20, 0xf8, 0x7a, 0x6c, 0x75, 0xcf,
  19285. 0xf3, 0x96, 0x27, 0xb5, 0x6e, 0x3e, 0xd1, 0x97,
  19286. 0xc5, 0x52, 0xd2, 0x95, 0xa7}, 21,
  19287. /* tag, tag length */
  19288. {0xcf, 0xc4, 0x6a, 0xfc, 0x25, 0x3b, 0x46, 0x52,
  19289. 0xb1, 0xaf, 0x37, 0x95, 0xb1, 0x24, 0xab, 0x6e}, 16,
  19290. /* valid */
  19291. 1,
  19292. },
  19293. {
  19294. /* key, key length */
  19295. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19296. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19297. /* iv, iv length */
  19298. {0x3c, 0x8c, 0xc2, 0x97, 0x0a, 0x00, 0x8f, 0x75,
  19299. 0xcc, 0x5b, 0xea, 0xe2, 0x84, 0x72, 0x58, 0xc2}, 16,
  19300. /* aad, aad length */
  19301. {0x00}, 0,
  19302. /* msg, msg length */
  19303. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19304. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19305. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19306. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  19307. /* ct, ct length */
  19308. {0x3c, 0x44, 0x1f, 0x32, 0xce, 0x07, 0x82, 0x23,
  19309. 0x64, 0xd7, 0xa2, 0x99, 0x0e, 0x50, 0xbb, 0x13,
  19310. 0xd7, 0xb0, 0x2a, 0x26, 0x96, 0x9e, 0x4a, 0x93,
  19311. 0x7e, 0x5e, 0x90, 0x73, 0xb0, 0xd9, 0xc9, 0x68}, 32,
  19312. /* tag, tag length */
  19313. {0xdb, 0x90, 0xbd, 0xb3, 0xda, 0x3d, 0x00, 0xaf,
  19314. 0xd0, 0xfc, 0x6a, 0x83, 0x55, 0x1d, 0xa9, 0x5e}, 16,
  19315. /* valid */
  19316. 1,
  19317. },
  19318. {
  19319. /* key, key length */
  19320. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19321. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19322. /* iv, iv length */
  19323. {0xae, 0xf0, 0x3d, 0x00, 0x59, 0x84, 0x94, 0xe9,
  19324. 0xfb, 0x03, 0xcd, 0x7d, 0x8b, 0x59, 0x08, 0x66}, 16,
  19325. /* aad, aad length */
  19326. {0x00}, 0,
  19327. /* msg, msg length */
  19328. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19329. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19330. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19331. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  19332. /* ct, ct length */
  19333. {0xd1, 0x9a, 0xc5, 0x98, 0x49, 0x02, 0x6a, 0x91,
  19334. 0xaa, 0x1b, 0x9a, 0xec, 0x29, 0xb1, 0x1a, 0x20,
  19335. 0x2a, 0x4d, 0x73, 0x9f, 0xd8, 0x6c, 0x28, 0xe3,
  19336. 0xae, 0x3d, 0x58, 0x8e, 0xa2, 0x1d, 0x70, 0xc6}, 32,
  19337. /* tag, tag length */
  19338. {0xc3, 0x0f, 0x6c, 0xd9, 0x20, 0x20, 0x74, 0xed,
  19339. 0x6e, 0x2a, 0x2a, 0x36, 0x0e, 0xac, 0x8c, 0x47}, 16,
  19340. /* valid */
  19341. 1,
  19342. },
  19343. {
  19344. /* key, key length */
  19345. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19346. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19347. /* iv, iv length */
  19348. {0x55, 0xd1, 0x25, 0x11, 0xc6, 0x96, 0xa8, 0x0d,
  19349. 0x05, 0x14, 0xd1, 0xff, 0xba, 0x49, 0xca, 0xda}, 16,
  19350. /* aad, aad length */
  19351. {0x00}, 0,
  19352. /* msg, msg length */
  19353. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19354. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19355. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19356. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  19357. /* ct, ct length */
  19358. {0x21, 0x08, 0x55, 0x8a, 0xc4, 0xb2, 0xc2, 0xd5,
  19359. 0xcc, 0x66, 0xce, 0xa5, 0x1d, 0x62, 0x10, 0xe0,
  19360. 0x46, 0x17, 0x7a, 0x67, 0x63, 0x1c, 0xd2, 0xdd,
  19361. 0x8f, 0x09, 0x46, 0x97, 0x33, 0xac, 0xb5, 0x17}, 32,
  19362. /* tag, tag length */
  19363. {0xfc, 0x35, 0x5e, 0x87, 0xa2, 0x67, 0xbe, 0x3a,
  19364. 0xe3, 0xe4, 0x4c, 0x0b, 0xf3, 0xf9, 0x9b, 0x2b}, 16,
  19365. /* valid */
  19366. 1,
  19367. },
  19368. {
  19369. /* key, key length */
  19370. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19371. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19372. /* iv, iv length */
  19373. {0x79, 0x42, 0x2d, 0xdd, 0x91, 0xc4, 0xee, 0xe2,
  19374. 0xde, 0xae, 0xf1, 0xf9, 0x68, 0x30, 0x53, 0x04}, 16,
  19375. /* aad, aad length */
  19376. {0x00}, 0,
  19377. /* msg, msg length */
  19378. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19379. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19380. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19381. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  19382. /* ct, ct length */
  19383. {0x4d, 0x2c, 0x15, 0x24, 0xca, 0x4b, 0xaa, 0x4e,
  19384. 0xef, 0xcc, 0xe6, 0xb9, 0x1b, 0x22, 0x7e, 0xe8,
  19385. 0x3a, 0xba, 0xff, 0x81, 0x05, 0xdc, 0xaf, 0xa2,
  19386. 0xab, 0x19, 0x1f, 0x5d, 0xf2, 0x57, 0x50, 0x35}, 32,
  19387. /* tag, tag length */
  19388. {0xe2, 0xc8, 0x65, 0xce, 0x2d, 0x7a, 0xbd, 0xac,
  19389. 0x02, 0x4c, 0x6f, 0x99, 0x1a, 0x84, 0x83, 0x90}, 16,
  19390. /* valid */
  19391. 1,
  19392. },
  19393. {
  19394. /* key, key length */
  19395. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19396. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19397. /* iv, iv length */
  19398. {0x0a, 0xf5, 0xaa, 0x7a, 0x76, 0x76, 0xe2, 0x83,
  19399. 0x06, 0x30, 0x6b, 0xcd, 0x9b, 0xf2, 0x00, 0x3a}, 16,
  19400. /* aad, aad length */
  19401. {0x00}, 0,
  19402. /* msg, msg length */
  19403. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19404. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19405. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19406. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  19407. /* ct, ct length */
  19408. {0x8e, 0xb0, 0x1e, 0x62, 0x18, 0x5d, 0x78, 0x2e,
  19409. 0xb9, 0x28, 0x7a, 0x34, 0x1a, 0x68, 0x62, 0xac,
  19410. 0x52, 0x57, 0xd6, 0xf9, 0xad, 0xc9, 0x9e, 0xe0,
  19411. 0xa2, 0x4d, 0x9c, 0x22, 0xb3, 0xe9, 0xb3, 0x8a}, 32,
  19412. /* tag, tag length */
  19413. {0x39, 0xc3, 0x39, 0xbc, 0x8a, 0x74, 0xc7, 0x5e,
  19414. 0x2c, 0x65, 0xc6, 0x11, 0x95, 0x44, 0xd6, 0x1e}, 16,
  19415. /* valid */
  19416. 1,
  19417. },
  19418. {
  19419. /* key, key length */
  19420. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19421. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19422. /* iv, iv length */
  19423. {0xaf, 0x5a, 0x03, 0xae, 0x7e, 0xdd, 0x73, 0x47,
  19424. 0x1b, 0xdc, 0xdf, 0xac, 0x5e, 0x19, 0x4a, 0x60}, 16,
  19425. /* aad, aad length */
  19426. {0x00}, 0,
  19427. /* msg, msg length */
  19428. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19429. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19430. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19431. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  19432. /* ct, ct length */
  19433. {0x94, 0xc5, 0xd2, 0xac, 0xa6, 0xdb, 0xbc, 0xe8,
  19434. 0xc2, 0x45, 0x13, 0xa2, 0x5e, 0x09, 0x5c, 0x0e,
  19435. 0x54, 0xa9, 0x42, 0x86, 0x0d, 0x32, 0x7a, 0x22,
  19436. 0x2a, 0x81, 0x5c, 0xc7, 0x13, 0xb1, 0x63, 0xb4}, 32,
  19437. /* tag, tag length */
  19438. {0xf5, 0x0b, 0x30, 0x30, 0x4e, 0x45, 0xc9, 0xd4,
  19439. 0x11, 0xe8, 0xdf, 0x45, 0x08, 0xa9, 0x86, 0x12}, 16,
  19440. /* valid */
  19441. 1,
  19442. },
  19443. {
  19444. /* key, key length */
  19445. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19446. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19447. /* iv, iv length */
  19448. {0xb3, 0x70, 0x87, 0x68, 0x0f, 0x0e, 0xdd, 0x5a,
  19449. 0x52, 0x22, 0x8b, 0x8c, 0x7a, 0xae, 0xa6, 0x64}, 16,
  19450. /* aad, aad length */
  19451. {0x00}, 0,
  19452. /* msg, msg length */
  19453. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19454. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19455. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19456. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19457. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  19458. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  19459. 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
  19460. 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33}, 64,
  19461. /* ct, ct length */
  19462. {0x3b, 0xb6, 0x17, 0x3e, 0x37, 0x72, 0xd4, 0xb6,
  19463. 0x2e, 0xef, 0x37, 0xf9, 0xef, 0x07, 0x81, 0xf3,
  19464. 0x60, 0xb6, 0xc7, 0x4b, 0xe3, 0xbf, 0x6b, 0x37,
  19465. 0x10, 0x67, 0xbc, 0x1b, 0x09, 0x0d, 0x9d, 0x66,
  19466. 0x22, 0xa1, 0xfb, 0xec, 0x6a, 0xc4, 0x71, 0xb3,
  19467. 0x34, 0x9c, 0xd4, 0x27, 0x7a, 0x10, 0x1d, 0x40,
  19468. 0x89, 0x0f, 0xbf, 0x27, 0xdf, 0xdc, 0xd0, 0xb4,
  19469. 0xe3, 0x78, 0x1f, 0x98, 0x06, 0xda, 0xab, 0xb6}, 64,
  19470. /* tag, tag length */
  19471. {0xa0, 0x49, 0x87, 0x45, 0xe5, 0x99, 0x99, 0xdd,
  19472. 0xc3, 0x2d, 0x5b, 0x14, 0x02, 0x41, 0x12, 0x4e}, 16,
  19473. /* valid */
  19474. 1,
  19475. },
  19476. {
  19477. /* key, key length */
  19478. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19479. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19480. /* iv, iv length */
  19481. {0x4f, 0x80, 0x2d, 0xa6, 0x2a, 0x38, 0x45, 0x55,
  19482. 0xa1, 0x9b, 0xc2, 0xb3, 0x82, 0xeb, 0x25, 0xaf}, 16,
  19483. /* aad, aad length */
  19484. {0x00}, 0,
  19485. /* msg, msg length */
  19486. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19487. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19488. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19489. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  19490. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  19491. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  19492. 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
  19493. 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
  19494. 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
  19495. 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44}, 80,
  19496. /* ct, ct length */
  19497. {0xe9, 0xb0, 0xbb, 0x88, 0x57, 0x81, 0x8c, 0xe3,
  19498. 0x20, 0x1c, 0x36, 0x90, 0xd2, 0x1d, 0xaa, 0x7f,
  19499. 0x26, 0x4f, 0xb8, 0xee, 0x93, 0xcc, 0x7a, 0x46,
  19500. 0x74, 0xea, 0x2f, 0xc3, 0x2b, 0xf1, 0x82, 0xfb,
  19501. 0x2a, 0x7e, 0x8a, 0xd5, 0x15, 0x07, 0xad, 0x4f,
  19502. 0x31, 0xce, 0xfc, 0x23, 0x56, 0xfe, 0x79, 0x36,
  19503. 0xa7, 0xf6, 0xe1, 0x9f, 0x95, 0xe8, 0x8f, 0xdb,
  19504. 0xf1, 0x76, 0x20, 0x91, 0x6d, 0x3a, 0x6f, 0x3d,
  19505. 0x01, 0xfc, 0x17, 0xd3, 0x58, 0x67, 0x2f, 0x77,
  19506. 0x7f, 0xd4, 0x09, 0x92, 0x46, 0xe4, 0x36, 0xe1}, 80,
  19507. /* tag, tag length */
  19508. {0x67, 0x91, 0x0b, 0xe7, 0x44, 0xb8, 0x31, 0x5a,
  19509. 0xe0, 0xeb, 0x61, 0x24, 0x59, 0x0c, 0x5d, 0x8b}, 16,
  19510. /* valid */
  19511. 1,
  19512. },
  19513. {
  19514. /* key, key length */
  19515. {0xb6, 0x7b, 0x1a, 0x6e, 0xfd, 0xd4, 0x0d, 0x37,
  19516. 0x08, 0x0f, 0xbe, 0x8f, 0x80, 0x47, 0xae, 0xb9}, 16,
  19517. /* iv, iv length */
  19518. {0xfa, 0x29, 0x4b, 0x12, 0x99, 0x72, 0xf7, 0xfc,
  19519. 0x5b, 0xbd, 0x5b, 0x96, 0xbb, 0xa8, 0x37, 0xc9}, 16,
  19520. /* aad, aad length */
  19521. {0x00}, 0,
  19522. /* msg, msg length */
  19523. {0x00}, 0,
  19524. /* ct, ct length */
  19525. {0x00}, 0,
  19526. /* tag, tag length */
  19527. {0xb1, 0x4b, 0x64, 0xfb, 0x58, 0x98, 0x99, 0x69,
  19528. 0x95, 0x70, 0xcc, 0x91, 0x60, 0xe3, 0x98, 0x96}, 16,
  19529. /* valid */
  19530. 1,
  19531. },
  19532. {
  19533. /* key, key length */
  19534. {0x20, 0x9e, 0x6d, 0xbf, 0x2a, 0xd2, 0x6a, 0x10,
  19535. 0x54, 0x45, 0xfc, 0x02, 0x07, 0xcd, 0x9e, 0x9a}, 16,
  19536. /* iv, iv length */
  19537. {0x94, 0x77, 0x84, 0x9d, 0x6c, 0xcd, 0xfc, 0xa1,
  19538. 0x12, 0xd9, 0x2e, 0x53, 0xfa, 0xe4, 0xa7, 0xca}, 16,
  19539. /* aad, aad length */
  19540. {0x00}, 0,
  19541. /* msg, msg length */
  19542. {0x01}, 1,
  19543. /* ct, ct length */
  19544. {0x1d}, 1,
  19545. /* tag, tag length */
  19546. {0x52, 0xa5, 0xf6, 0x00, 0xfe, 0x53, 0x38, 0x02,
  19547. 0x6a, 0x7c, 0xb0, 0x9c, 0x11, 0x64, 0x00, 0x82}, 16,
  19548. /* valid */
  19549. 1,
  19550. },
  19551. {
  19552. /* key, key length */
  19553. {0xa5, 0x49, 0x44, 0x2e, 0x35, 0x15, 0x40, 0x32,
  19554. 0xd0, 0x7c, 0x86, 0x66, 0x00, 0x6a, 0xa6, 0xa2}, 16,
  19555. /* iv, iv length */
  19556. {0x51, 0x71, 0x52, 0x45, 0x68, 0xe8, 0x1d, 0x97,
  19557. 0xe8, 0xc4, 0xde, 0x4b, 0xa5, 0x6c, 0x10, 0xa0}, 16,
  19558. /* aad, aad length */
  19559. {0x00}, 0,
  19560. /* msg, msg length */
  19561. {0x11, 0x82, 0xe9, 0x35, 0x96, 0xca, 0xc5, 0x60,
  19562. 0x89, 0x46, 0x40, 0x0b, 0xc7, 0x3f, 0x3a}, 15,
  19563. /* ct, ct length */
  19564. {0xd7, 0xb8, 0xa6, 0xb4, 0x3d, 0x2e, 0x9f, 0x98,
  19565. 0xc2, 0xb4, 0x4c, 0xe5, 0xe3, 0xcf, 0xdb}, 15,
  19566. /* tag, tag length */
  19567. {0x1b, 0xdd, 0x52, 0xfc, 0x98, 0x7d, 0xaf, 0x0e,
  19568. 0xe1, 0x92, 0x34, 0xc9, 0x05, 0xea, 0x64, 0x5f}, 16,
  19569. /* valid */
  19570. 1,
  19571. },
  19572. {
  19573. /* key, key length */
  19574. {0x95, 0x8b, 0xcd, 0xb6, 0x6a, 0x39, 0x52, 0xb5,
  19575. 0x37, 0x01, 0x58, 0x2a, 0x68, 0xa0, 0xe4, 0x74}, 16,
  19576. /* iv, iv length */
  19577. {0x0e, 0x6e, 0xc8, 0x79, 0xb0, 0x2c, 0x6f, 0x51,
  19578. 0x69, 0x76, 0xe3, 0x58, 0x98, 0x42, 0x8d, 0xa7}, 16,
  19579. /* aad, aad length */
  19580. {0x00}, 0,
  19581. /* msg, msg length */
  19582. {0x14, 0x04, 0x15, 0x82, 0x3e, 0xcc, 0x89, 0x32,
  19583. 0xa0, 0x58, 0x38, 0x4b, 0x73, 0x8e, 0xa6, 0xea,
  19584. 0x6d, 0x4d, 0xfe, 0x3b, 0xbe, 0xee}, 22,
  19585. /* ct, ct length */
  19586. {0x73, 0xe5, 0xc6, 0xf0, 0xe7, 0x03, 0xa5, 0x2d,
  19587. 0x02, 0xf7, 0xf7, 0xfa, 0xeb, 0x1b, 0x77, 0xfd,
  19588. 0x4f, 0xd0, 0xcb, 0x42, 0x1e, 0xaf}, 22,
  19589. /* tag, tag length */
  19590. {0x6c, 0x15, 0x4a, 0x85, 0x96, 0x8e, 0xdd, 0x74,
  19591. 0x77, 0x65, 0x75, 0xa4, 0x45, 0x0b, 0xd8, 0x97}, 16,
  19592. /* valid */
  19593. 1,
  19594. },
  19595. {
  19596. /* key, key length */
  19597. {0x96, 0x5b, 0x75, 0x7b, 0xa5, 0x01, 0x8a, 0x8d,
  19598. 0x66, 0xed, 0xc7, 0x8e, 0x0c, 0xee, 0xe8, 0x6b}, 16,
  19599. /* iv, iv length */
  19600. {0x2e, 0x35, 0x90, 0x1a, 0xe7, 0xd4, 0x91, 0xee,
  19601. 0xcc, 0x88, 0x38, 0xfe, 0xdd, 0x63, 0x14, 0x05}, 16,
  19602. /* aad, aad length */
  19603. {0xdf, 0x10, 0xd0, 0xd2, 0x12, 0x24, 0x24, 0x50}, 8,
  19604. /* msg, msg length */
  19605. {0x36, 0xe5, 0x7a, 0x76, 0x39, 0x58, 0xb0, 0x2c,
  19606. 0xea, 0x9d, 0x6a, 0x67, 0x6e, 0xbc, 0xe8, 0x1f}, 16,
  19607. /* ct, ct length */
  19608. {0x93, 0x6b, 0x69, 0xb6, 0xc9, 0x55, 0xad, 0xfd,
  19609. 0x15, 0x53, 0x9b, 0x9b, 0xe4, 0x98, 0x9c, 0xb6}, 16,
  19610. /* tag, tag length */
  19611. {0xee, 0x15, 0xa1, 0x45, 0x4e, 0x88, 0xfa, 0xad,
  19612. 0x8e, 0x48, 0xa8, 0xdf, 0x29, 0x83, 0xb4, 0x25}, 16,
  19613. /* valid */
  19614. 1,
  19615. },
  19616. {
  19617. /* key, key length */
  19618. {0x88, 0xd0, 0x20, 0x33, 0x78, 0x1c, 0x7b, 0x41,
  19619. 0x64, 0x71, 0x1a, 0x05, 0x42, 0x0f, 0x25, 0x6e}, 16,
  19620. /* iv, iv length */
  19621. {0x7f, 0x29, 0x85, 0x29, 0x63, 0x15, 0x50, 0x7a,
  19622. 0xa4, 0xc0, 0xa9, 0x3d, 0x5c, 0x12, 0xbd, 0x77}, 16,
  19623. /* aad, aad length */
  19624. {0x7c, 0x57, 0x1d, 0x2f, 0xbb, 0x5f, 0x62, 0x52,
  19625. 0x3c, 0x0e, 0xb3, 0x38, 0xbe, 0xf9, 0xa9}, 15,
  19626. /* msg, msg length */
  19627. {0xd9, 0x8a, 0xdc, 0x03, 0xd9, 0xd5, 0x82, 0x73,
  19628. 0x2e, 0xb0, 0x7d, 0xf2, 0x3d, 0x7b, 0x9f, 0x74}, 16,
  19629. /* ct, ct length */
  19630. {0x67, 0xca, 0xac, 0x35, 0x44, 0x3a, 0x31, 0x38,
  19631. 0xd2, 0xcb, 0x81, 0x1f, 0x0c, 0xe0, 0x4d, 0xd2}, 16,
  19632. /* tag, tag length */
  19633. {0xb7, 0x96, 0x8e, 0x0b, 0x56, 0x40, 0xe3, 0xb2,
  19634. 0x36, 0x56, 0x96, 0x53, 0x20, 0x8b, 0x9d, 0xeb}, 16,
  19635. /* valid */
  19636. 1,
  19637. },
  19638. {
  19639. /* key, key length */
  19640. {0x51, 0x58, 0x40, 0xcf, 0x67, 0xd2, 0xe4, 0x0e,
  19641. 0xb6, 0x5e, 0x54, 0xa2, 0x4c, 0x72, 0xcb, 0xf2}, 16,
  19642. /* iv, iv length */
  19643. {0xbf, 0x47, 0xaf, 0xdf, 0xd4, 0x92, 0x13, 0x7a,
  19644. 0x24, 0x23, 0x6b, 0xc3, 0x67, 0x97, 0xa8, 0x8e}, 16,
  19645. /* aad, aad length */
  19646. {0x16, 0x84, 0x3c, 0x09, 0x1d, 0x43, 0xb0, 0xa1,
  19647. 0x91, 0xd0, 0xc7, 0x3d, 0x15, 0x60, 0x1b, 0xe9}, 16,
  19648. /* msg, msg length */
  19649. {0xc8, 0x34, 0x58, 0x8c, 0xb6, 0xda, 0xf9, 0xf0,
  19650. 0x6d, 0xd2, 0x35, 0x19, 0xf4, 0xbe, 0x9f, 0x56}, 16,
  19651. /* ct, ct length */
  19652. {0x20, 0x0a, 0xc4, 0x51, 0xfb, 0xeb, 0x0f, 0x61,
  19653. 0x51, 0xd6, 0x15, 0x83, 0xa4, 0x3b, 0x73, 0x43}, 16,
  19654. /* tag, tag length */
  19655. {0x2a, 0xd4, 0x3e, 0x4c, 0xaa, 0x51, 0x98, 0x3a,
  19656. 0x9d, 0x4d, 0x24, 0x48, 0x1b, 0xf4, 0xc8, 0x39}, 16,
  19657. /* valid */
  19658. 1,
  19659. },
  19660. {
  19661. /* key, key length */
  19662. {0x2e, 0x44, 0x92, 0xd4, 0x44, 0xe5, 0xb6, 0xf4,
  19663. 0xce, 0xc8, 0xc2, 0xd3, 0x61, 0x5a, 0xc8, 0x58}, 16,
  19664. /* iv, iv length */
  19665. {0xd0, 0x2b, 0xf0, 0x76, 0x3a, 0x9f, 0xef, 0xbf,
  19666. 0x70, 0xc3, 0x3a, 0xee, 0x1e, 0x9d, 0xa1, 0xd6}, 16,
  19667. /* aad, aad length */
  19668. {0x90, 0x4d, 0x86, 0xf1, 0x33, 0xce, 0xc1, 0x5a,
  19669. 0x0c, 0x3c, 0xaf, 0x14, 0xd7, 0xe0, 0x29, 0xc8,
  19670. 0x2a, 0x07, 0x70, 0x5a, 0x23, 0xf0, 0xd0, 0x80}, 24,
  19671. /* msg, msg length */
  19672. {0x9e, 0x62, 0xd6, 0x51, 0x1b, 0x0b, 0xda, 0x7d,
  19673. 0xd7, 0x74, 0x0b, 0x61, 0x4d, 0x97, 0xba, 0xe0}, 16,
  19674. /* ct, ct length */
  19675. {0x27, 0xc6, 0xe9, 0xa6, 0x53, 0xc5, 0x25, 0x3c,
  19676. 0xa1, 0xc5, 0x67, 0x3f, 0x97, 0xb9, 0xb3, 0x3e}, 16,
  19677. /* tag, tag length */
  19678. {0x2d, 0x58, 0x12, 0x71, 0xe1, 0xfa, 0x9e, 0x36,
  19679. 0x86, 0x13, 0x6c, 0xaa, 0x8f, 0x4d, 0x6c, 0x8e}, 16,
  19680. /* valid */
  19681. 1,
  19682. },
  19683. {
  19684. /* key, key length */
  19685. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19686. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19687. /* iv, iv length */
  19688. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19689. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19690. /* aad, aad length */
  19691. {0x00}, 0,
  19692. /* msg, msg length */
  19693. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19694. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19695. /* ct, ct length */
  19696. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19697. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19698. /* tag, tag length */
  19699. {0xe7, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19700. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19701. /* valid */
  19702. 0,
  19703. },
  19704. {
  19705. /* key, key length */
  19706. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19707. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19708. /* iv, iv length */
  19709. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19710. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19711. /* aad, aad length */
  19712. {0x00}, 0,
  19713. /* msg, msg length */
  19714. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19715. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19716. /* ct, ct length */
  19717. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19718. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19719. /* tag, tag length */
  19720. {0xe4, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19721. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19722. /* valid */
  19723. 0,
  19724. },
  19725. {
  19726. /* key, key length */
  19727. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19728. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19729. /* iv, iv length */
  19730. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19731. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19732. /* aad, aad length */
  19733. {0x00}, 0,
  19734. /* msg, msg length */
  19735. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19736. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19737. /* ct, ct length */
  19738. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19739. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19740. /* tag, tag length */
  19741. {0x66, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19742. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19743. /* valid */
  19744. 0,
  19745. },
  19746. {
  19747. /* key, key length */
  19748. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19749. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19750. /* iv, iv length */
  19751. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19752. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19753. /* aad, aad length */
  19754. {0x00}, 0,
  19755. /* msg, msg length */
  19756. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19757. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19758. /* ct, ct length */
  19759. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19760. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19761. /* tag, tag length */
  19762. {0xe6, 0x0f, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19763. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19764. /* valid */
  19765. 0,
  19766. },
  19767. {
  19768. /* key, key length */
  19769. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19770. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19771. /* iv, iv length */
  19772. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19773. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19774. /* aad, aad length */
  19775. {0x00}, 0,
  19776. /* msg, msg length */
  19777. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19778. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19779. /* ct, ct length */
  19780. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19781. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19782. /* tag, tag length */
  19783. {0xe6, 0x0e, 0x7c, 0xd0, 0x13, 0xa6, 0xdb, 0xf2,
  19784. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19785. /* valid */
  19786. 0,
  19787. },
  19788. {
  19789. /* key, key length */
  19790. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19791. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19792. /* iv, iv length */
  19793. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19794. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19795. /* aad, aad length */
  19796. {0x00}, 0,
  19797. /* msg, msg length */
  19798. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19799. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19800. /* ct, ct length */
  19801. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19802. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19803. /* tag, tag length */
  19804. {0xe6, 0x0e, 0x7c, 0x50, 0x12, 0xa6, 0xdb, 0xf2,
  19805. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19806. /* valid */
  19807. 0,
  19808. },
  19809. {
  19810. /* key, key length */
  19811. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19812. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19813. /* iv, iv length */
  19814. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19815. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19816. /* aad, aad length */
  19817. {0x00}, 0,
  19818. /* msg, msg length */
  19819. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19820. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19821. /* ct, ct length */
  19822. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19823. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19824. /* tag, tag length */
  19825. {0xe6, 0x0e, 0x7c, 0x50, 0x11, 0xa6, 0xdb, 0xf2,
  19826. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19827. /* valid */
  19828. 0,
  19829. },
  19830. {
  19831. /* key, key length */
  19832. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19833. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19834. /* iv, iv length */
  19835. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19836. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19837. /* aad, aad length */
  19838. {0x00}, 0,
  19839. /* msg, msg length */
  19840. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19841. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19842. /* ct, ct length */
  19843. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19844. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19845. /* tag, tag length */
  19846. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0x72,
  19847. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19848. /* valid */
  19849. 0,
  19850. },
  19851. {
  19852. /* key, key length */
  19853. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19854. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19855. /* iv, iv length */
  19856. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19857. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19858. /* aad, aad length */
  19859. {0x00}, 0,
  19860. /* msg, msg length */
  19861. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19862. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19863. /* ct, ct length */
  19864. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19865. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19866. /* tag, tag length */
  19867. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19868. 0x53, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19869. /* valid */
  19870. 0,
  19871. },
  19872. {
  19873. /* key, key length */
  19874. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19875. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19876. /* iv, iv length */
  19877. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19878. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19879. /* aad, aad length */
  19880. {0x00}, 0,
  19881. /* msg, msg length */
  19882. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19883. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19884. /* ct, ct length */
  19885. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19886. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19887. /* tag, tag length */
  19888. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19889. 0xd2, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19890. /* valid */
  19891. 0,
  19892. },
  19893. {
  19894. /* key, key length */
  19895. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19896. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19897. /* iv, iv length */
  19898. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19899. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19900. /* aad, aad length */
  19901. {0x00}, 0,
  19902. /* msg, msg length */
  19903. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19904. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19905. /* ct, ct length */
  19906. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19907. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19908. /* tag, tag length */
  19909. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19910. 0x52, 0xb8, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19911. /* valid */
  19912. 0,
  19913. },
  19914. {
  19915. /* key, key length */
  19916. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19917. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19918. /* iv, iv length */
  19919. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19920. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19921. /* aad, aad length */
  19922. {0x00}, 0,
  19923. /* msg, msg length */
  19924. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19925. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19926. /* ct, ct length */
  19927. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19928. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19929. /* tag, tag length */
  19930. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19931. 0x52, 0x98, 0xb0, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  19932. /* valid */
  19933. 0,
  19934. },
  19935. {
  19936. /* key, key length */
  19937. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19938. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19939. /* iv, iv length */
  19940. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19941. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19942. /* aad, aad length */
  19943. {0x00}, 0,
  19944. /* msg, msg length */
  19945. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19946. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19947. /* ct, ct length */
  19948. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19949. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19950. /* tag, tag length */
  19951. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19952. 0x52, 0x98, 0xb1, 0x92, 0x9a, 0xc3, 0x56, 0xa7}, 16,
  19953. /* valid */
  19954. 0,
  19955. },
  19956. {
  19957. /* key, key length */
  19958. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19959. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19960. /* iv, iv length */
  19961. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19962. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19963. /* aad, aad length */
  19964. {0x00}, 0,
  19965. /* msg, msg length */
  19966. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19967. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19968. /* ct, ct length */
  19969. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19970. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19971. /* tag, tag length */
  19972. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19973. 0x52, 0x98, 0xb1, 0x92, 0x99, 0xc3, 0x56, 0xa7}, 16,
  19974. /* valid */
  19975. 0,
  19976. },
  19977. {
  19978. /* key, key length */
  19979. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  19980. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  19981. /* iv, iv length */
  19982. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  19983. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  19984. /* aad, aad length */
  19985. {0x00}, 0,
  19986. /* msg, msg length */
  19987. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  19988. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  19989. /* ct, ct length */
  19990. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  19991. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  19992. /* tag, tag length */
  19993. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  19994. 0x52, 0x98, 0xb1, 0x92, 0x1b, 0xc3, 0x56, 0xa7}, 16,
  19995. /* valid */
  19996. 0,
  19997. },
  19998. {
  19999. /* key, key length */
  20000. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20001. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  20002. /* iv, iv length */
  20003. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  20004. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  20005. /* aad, aad length */
  20006. {0x00}, 0,
  20007. /* msg, msg length */
  20008. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  20009. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  20010. /* ct, ct length */
  20011. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  20012. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  20013. /* tag, tag length */
  20014. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  20015. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa6}, 16,
  20016. /* valid */
  20017. 0,
  20018. },
  20019. {
  20020. /* key, key length */
  20021. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20022. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  20023. /* iv, iv length */
  20024. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  20025. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  20026. /* aad, aad length */
  20027. {0x00}, 0,
  20028. /* msg, msg length */
  20029. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  20030. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  20031. /* ct, ct length */
  20032. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  20033. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  20034. /* tag, tag length */
  20035. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  20036. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa5}, 16,
  20037. /* valid */
  20038. 0,
  20039. },
  20040. {
  20041. /* key, key length */
  20042. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20043. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  20044. /* iv, iv length */
  20045. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  20046. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  20047. /* aad, aad length */
  20048. {0x00}, 0,
  20049. /* msg, msg length */
  20050. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  20051. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  20052. /* ct, ct length */
  20053. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  20054. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  20055. /* tag, tag length */
  20056. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  20057. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xe7}, 16,
  20058. /* valid */
  20059. 0,
  20060. },
  20061. {
  20062. /* key, key length */
  20063. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20064. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  20065. /* iv, iv length */
  20066. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  20067. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  20068. /* aad, aad length */
  20069. {0x00}, 0,
  20070. /* msg, msg length */
  20071. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  20072. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  20073. /* ct, ct length */
  20074. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  20075. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  20076. /* tag, tag length */
  20077. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  20078. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0x27}, 16,
  20079. /* valid */
  20080. 0,
  20081. },
  20082. {
  20083. /* key, key length */
  20084. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20085. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  20086. /* iv, iv length */
  20087. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  20088. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  20089. /* aad, aad length */
  20090. {0x00}, 0,
  20091. /* msg, msg length */
  20092. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  20093. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  20094. /* ct, ct length */
  20095. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  20096. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  20097. /* tag, tag length */
  20098. {0xe7, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  20099. 0x53, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  20100. /* valid */
  20101. 0,
  20102. },
  20103. {
  20104. /* key, key length */
  20105. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20106. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  20107. /* iv, iv length */
  20108. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  20109. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  20110. /* aad, aad length */
  20111. {0x00}, 0,
  20112. /* msg, msg length */
  20113. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  20114. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  20115. /* ct, ct length */
  20116. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  20117. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  20118. /* tag, tag length */
  20119. {0xe6, 0x0e, 0x7c, 0xd0, 0x13, 0xa6, 0xdb, 0x72,
  20120. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  20121. /* valid */
  20122. 0,
  20123. },
  20124. {
  20125. /* key, key length */
  20126. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20127. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  20128. /* iv, iv length */
  20129. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  20130. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  20131. /* aad, aad length */
  20132. {0x00}, 0,
  20133. /* msg, msg length */
  20134. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  20135. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  20136. /* ct, ct length */
  20137. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  20138. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  20139. /* tag, tag length */
  20140. {0xe6, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0x72,
  20141. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0x27}, 16,
  20142. /* valid */
  20143. 0,
  20144. },
  20145. {
  20146. /* key, key length */
  20147. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20148. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  20149. /* iv, iv length */
  20150. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  20151. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  20152. /* aad, aad length */
  20153. {0x00}, 0,
  20154. /* msg, msg length */
  20155. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  20156. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  20157. /* ct, ct length */
  20158. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  20159. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  20160. /* tag, tag length */
  20161. {0x19, 0xf1, 0x83, 0xaf, 0xec, 0x59, 0x24, 0x0d,
  20162. 0xad, 0x67, 0x4e, 0x6d, 0x64, 0x3c, 0xa9, 0x58}, 16,
  20163. /* valid */
  20164. 0,
  20165. },
  20166. {
  20167. /* key, key length */
  20168. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20169. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  20170. /* iv, iv length */
  20171. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  20172. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  20173. /* aad, aad length */
  20174. {0x00}, 0,
  20175. /* msg, msg length */
  20176. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  20177. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  20178. /* ct, ct length */
  20179. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  20180. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  20181. /* tag, tag length */
  20182. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  20183. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 16,
  20184. /* valid */
  20185. 0,
  20186. },
  20187. {
  20188. /* key, key length */
  20189. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20190. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  20191. /* iv, iv length */
  20192. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  20193. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  20194. /* aad, aad length */
  20195. {0x00}, 0,
  20196. /* msg, msg length */
  20197. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  20198. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  20199. /* ct, ct length */
  20200. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  20201. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  20202. /* tag, tag length */
  20203. {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  20204. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 16,
  20205. /* valid */
  20206. 0,
  20207. },
  20208. {
  20209. /* key, key length */
  20210. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20211. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  20212. /* iv, iv length */
  20213. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  20214. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  20215. /* aad, aad length */
  20216. {0x00}, 0,
  20217. /* msg, msg length */
  20218. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  20219. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  20220. /* ct, ct length */
  20221. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  20222. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  20223. /* tag, tag length */
  20224. {0x66, 0x8e, 0xfc, 0xd0, 0x93, 0x26, 0x5b, 0x72,
  20225. 0xd2, 0x18, 0x31, 0x12, 0x1b, 0x43, 0xd6, 0x27}, 16,
  20226. /* valid */
  20227. 0,
  20228. },
  20229. {
  20230. /* key, key length */
  20231. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20232. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  20233. /* iv, iv length */
  20234. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  20235. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  20236. /* aad, aad length */
  20237. {0x00}, 0,
  20238. /* msg, msg length */
  20239. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  20240. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  20241. /* ct, ct length */
  20242. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  20243. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  20244. /* tag, tag length */
  20245. {0xe7, 0x0f, 0x7d, 0x51, 0x12, 0xa7, 0xda, 0xf3,
  20246. 0x53, 0x99, 0xb0, 0x93, 0x9a, 0xc2, 0x57, 0xa6}, 16,
  20247. /* valid */
  20248. 0,
  20249. },
  20250. };
  20251. byte ciphertext[sizeof(vectors[0].ct)];
  20252. byte authtag[sizeof(vectors[0].tag)];
  20253. int i;
  20254. int len;
  20255. int ret;
  20256. for (i = 0; i < (int)(sizeof(vectors)/sizeof(vectors[0])); i++) {
  20257. XMEMSET(ciphertext, 0, sizeof(ciphertext));
  20258. len = sizeof(authtag);
  20259. ExpectIntEQ(wc_AesEaxEncryptAuth(vectors[i].key, vectors[i].key_length,
  20260. ciphertext,
  20261. vectors[i].msg, vectors[i].msg_length,
  20262. vectors[i].iv, vectors[i].iv_length,
  20263. authtag, len,
  20264. vectors[i].aad, vectors[i].aad_length),
  20265. 0);
  20266. /* check ciphertext matches vector */
  20267. ExpectIntEQ(XMEMCMP(ciphertext, vectors[i].ct, vectors[i].ct_length),
  20268. 0);
  20269. /* check that computed tag matches vector only for vectors marked as valid */
  20270. ret = XMEMCMP(authtag, vectors[i].tag, len);
  20271. if (vectors[i].valid) {
  20272. ExpectIntEQ(ret, 0);
  20273. }
  20274. else {
  20275. ExpectIntNE(ret, 0);
  20276. }
  20277. XMEMSET(ciphertext, 0, sizeof(ciphertext));
  20278. /* Decrypt, checking that the computed auth tags match */
  20279. ExpectIntEQ(wc_AesEaxDecryptAuth(vectors[i].key, vectors[i].key_length,
  20280. ciphertext,
  20281. vectors[i].ct, vectors[i].ct_length,
  20282. vectors[i].iv, vectors[i].iv_length,
  20283. authtag, len,
  20284. vectors[i].aad, vectors[i].aad_length),
  20285. 0);
  20286. /* check decrypted ciphertext matches vector plaintext */
  20287. ExpectIntEQ(XMEMCMP(ciphertext, vectors[i].msg, vectors[i].msg_length),
  20288. 0);
  20289. }
  20290. return EXPECT_RESULT();
  20291. } /* END test_wc_AesEaxVectors */
  20292. /*
  20293. * Testing test_wc_AesEaxEncryptAuth()
  20294. */
  20295. static int test_wc_AesEaxEncryptAuth(void)
  20296. {
  20297. EXPECT_DECLS;
  20298. const byte key[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20299. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  20300. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  20301. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
  20302. const byte iv[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20303. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  20304. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  20305. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
  20306. const byte aad[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
  20307. const byte msg[] = {0x00, 0x01, 0x02, 0x03, 0x04};
  20308. byte ciphertext[sizeof(msg)];
  20309. byte authtag[AES_BLOCK_SIZE];
  20310. int i;
  20311. int len;
  20312. len = sizeof(authtag);
  20313. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  20314. ciphertext,
  20315. msg, sizeof(msg),
  20316. iv, sizeof(iv),
  20317. authtag, (word32)len,
  20318. aad, sizeof(aad)),
  20319. 0);
  20320. /* Test null checking */
  20321. ExpectIntEQ(wc_AesEaxEncryptAuth(NULL, sizeof(key),
  20322. ciphertext,
  20323. msg, sizeof(msg),
  20324. iv, sizeof(iv),
  20325. authtag, (word32)len,
  20326. aad, sizeof(aad)),
  20327. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20328. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  20329. NULL,
  20330. msg, sizeof(msg),
  20331. iv, sizeof(iv),
  20332. authtag, (word32)len,
  20333. aad, sizeof(aad)),
  20334. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20335. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  20336. ciphertext,
  20337. NULL, sizeof(msg),
  20338. iv, sizeof(iv),
  20339. authtag, (word32)len,
  20340. aad, sizeof(aad)),
  20341. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20342. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  20343. ciphertext,
  20344. msg, sizeof(msg),
  20345. NULL, sizeof(iv),
  20346. authtag, (word32)len,
  20347. aad, sizeof(aad)),
  20348. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20349. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  20350. ciphertext,
  20351. msg, sizeof(msg),
  20352. iv, sizeof(iv),
  20353. NULL, (word32)len,
  20354. aad, sizeof(aad)),
  20355. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20356. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  20357. ciphertext,
  20358. msg, sizeof(msg),
  20359. iv, sizeof(iv),
  20360. authtag, (word32)len,
  20361. NULL, sizeof(aad)),
  20362. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20363. /* Test bad key lengths */
  20364. for (i = 0; i <= 32; i++) {
  20365. int exp_ret;
  20366. if (i == AES_128_KEY_SIZE || i == AES_192_KEY_SIZE
  20367. || i == AES_256_KEY_SIZE) {
  20368. exp_ret = 0;
  20369. }
  20370. else {
  20371. exp_ret = WC_NO_ERR_TRACE(BAD_FUNC_ARG);
  20372. }
  20373. ExpectIntEQ(wc_AesEaxEncryptAuth(key, (word32)i,
  20374. ciphertext,
  20375. msg, sizeof(msg),
  20376. iv, sizeof(iv),
  20377. authtag, (word32)len,
  20378. aad, sizeof(aad)),
  20379. exp_ret);
  20380. }
  20381. /* Test auth tag size out of range */
  20382. len = AES_BLOCK_SIZE + 1;
  20383. ExpectIntEQ(wc_AesEaxEncryptAuth(key, sizeof(key),
  20384. ciphertext,
  20385. msg, sizeof(msg),
  20386. iv, sizeof(iv),
  20387. authtag, (word32)len,
  20388. aad, sizeof(aad)),
  20389. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20390. return EXPECT_RESULT();
  20391. } /* END test_wc_AesEaxEncryptAuth() */
  20392. /*
  20393. * Testing test_wc_AesEaxDecryptAuth()
  20394. */
  20395. static int test_wc_AesEaxDecryptAuth(void)
  20396. {
  20397. EXPECT_DECLS;
  20398. const byte key[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20399. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  20400. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  20401. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
  20402. const byte iv[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  20403. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  20404. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  20405. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
  20406. const byte aad[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
  20407. const byte ct[] = {0x00, 0x01, 0x02, 0x03, 0x04};
  20408. /* Garbage tag that should always fail for above aad */
  20409. const byte tag[] = {0xFE, 0xED, 0xBE, 0xEF, 0xDE, 0xAD, 0xC0, 0xDE,
  20410. 0xCA, 0xFE, 0xBE, 0xEF, 0xDE, 0xAF, 0xBE, 0xEF};
  20411. byte plaintext[sizeof(ct)];
  20412. int i;
  20413. int len;
  20414. len = sizeof(tag);
  20415. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20416. plaintext,
  20417. ct, sizeof(ct),
  20418. iv, sizeof(iv),
  20419. tag, (word32)len,
  20420. aad, sizeof(aad)),
  20421. WC_NO_ERR_TRACE(AES_EAX_AUTH_E));
  20422. /* Test null checking */
  20423. ExpectIntEQ(wc_AesEaxDecryptAuth(NULL, sizeof(key),
  20424. plaintext,
  20425. ct, sizeof(ct),
  20426. iv, sizeof(iv),
  20427. tag, (word32)len,
  20428. aad, sizeof(aad)),
  20429. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20430. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20431. NULL,
  20432. ct, sizeof(ct),
  20433. iv, sizeof(iv),
  20434. tag, (word32)len,
  20435. aad, sizeof(aad)),
  20436. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20437. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20438. plaintext,
  20439. NULL, sizeof(ct),
  20440. iv, sizeof(iv),
  20441. tag, (word32)len,
  20442. aad, sizeof(aad)),
  20443. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20444. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20445. plaintext,
  20446. ct, sizeof(ct),
  20447. NULL, sizeof(iv),
  20448. tag, (word32)len,
  20449. aad, sizeof(aad)),
  20450. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20451. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20452. plaintext,
  20453. ct, sizeof(ct),
  20454. iv, sizeof(iv),
  20455. NULL, (word32)len,
  20456. aad, sizeof(aad)),
  20457. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20458. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20459. plaintext,
  20460. ct, sizeof(ct),
  20461. iv, sizeof(iv),
  20462. tag, (word32)len,
  20463. NULL, sizeof(aad)),
  20464. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20465. /* Test bad key lengths */
  20466. for (i = 0; i <= 32; i++) {
  20467. int exp_ret;
  20468. if (i == AES_128_KEY_SIZE || i == AES_192_KEY_SIZE
  20469. || i == AES_256_KEY_SIZE) {
  20470. exp_ret = WC_NO_ERR_TRACE(AES_EAX_AUTH_E);
  20471. }
  20472. else {
  20473. exp_ret = WC_NO_ERR_TRACE(BAD_FUNC_ARG);
  20474. }
  20475. ExpectIntEQ(wc_AesEaxDecryptAuth(key, (word32)i,
  20476. plaintext,
  20477. ct, sizeof(ct),
  20478. iv, sizeof(iv),
  20479. tag, (word32)len,
  20480. aad, sizeof(aad)),
  20481. exp_ret);
  20482. }
  20483. /* Test auth tag size out of range */
  20484. len = AES_BLOCK_SIZE + 1;
  20485. ExpectIntEQ(wc_AesEaxDecryptAuth(key, sizeof(key),
  20486. plaintext,
  20487. ct, sizeof(ct),
  20488. iv, sizeof(iv),
  20489. tag, (word32)len,
  20490. aad, sizeof(aad)),
  20491. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20492. return EXPECT_RESULT();
  20493. } /* END test_wc_AesEaxDecryptAuth() */
  20494. #endif /* WOLFSSL_AES_EAX &&
  20495. * (!HAVE_FIPS || FIPS_VERSION_GE(5, 3)) && !HAVE_SELFTEST
  20496. */
  20497. /*
  20498. * Testing wc_InitDsaKey()
  20499. */
  20500. static int test_wc_InitDsaKey(void)
  20501. {
  20502. EXPECT_DECLS;
  20503. #ifndef NO_DSA
  20504. DsaKey key;
  20505. XMEMSET(&key, 0, sizeof(DsaKey));
  20506. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20507. /* Pass in bad args. */
  20508. ExpectIntEQ(wc_InitDsaKey(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20509. wc_FreeDsaKey(&key);
  20510. #endif
  20511. return EXPECT_RESULT();
  20512. } /* END test_wc_InitDsaKey */
  20513. /*
  20514. * Testing wc_DsaSign() and wc_DsaVerify()
  20515. */
  20516. static int test_wc_DsaSignVerify(void)
  20517. {
  20518. EXPECT_DECLS;
  20519. #if !defined(NO_DSA)
  20520. DsaKey key;
  20521. WC_RNG rng;
  20522. wc_Sha sha;
  20523. byte signature[DSA_SIG_SIZE];
  20524. byte hash[WC_SHA_DIGEST_SIZE];
  20525. word32 idx = 0;
  20526. word32 bytes;
  20527. int answer;
  20528. #ifdef USE_CERT_BUFFERS_1024
  20529. byte tmp[ONEK_BUF];
  20530. XMEMSET(tmp, 0, sizeof(tmp));
  20531. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  20532. bytes = sizeof_dsa_key_der_1024;
  20533. #elif defined(USE_CERT_BUFFERS_2048)
  20534. byte tmp[TWOK_BUF];
  20535. XMEMSET(tmp, 0, sizeof(tmp));
  20536. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  20537. bytes = sizeof_dsa_key_der_2048;
  20538. #else
  20539. byte tmp[TWOK_BUF];
  20540. XFILE fp = XBADFILE;
  20541. XMEMSET(tmp, 0, sizeof(tmp));
  20542. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb")) != XBADFILE);
  20543. ExpectTrue((bytes = (word32)XFREAD(tmp, 1, sizeof(tmp), fp)) > 0);
  20544. if (fp != XBADFILE)
  20545. XFCLOSE(fp);
  20546. #endif /* END USE_CERT_BUFFERS_1024 */
  20547. ExpectIntEQ(wc_InitSha(&sha), 0);
  20548. ExpectIntEQ(wc_ShaUpdate(&sha, tmp, bytes), 0);
  20549. ExpectIntEQ(wc_ShaFinal(&sha, hash), 0);
  20550. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20551. ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, &idx, &key, bytes), 0);
  20552. ExpectIntEQ(wc_InitRng(&rng), 0);
  20553. /* Sign. */
  20554. ExpectIntEQ(wc_DsaSign(hash, signature, &key, &rng), 0);
  20555. /* Test bad args. */
  20556. ExpectIntEQ(wc_DsaSign(NULL, signature, &key, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20557. ExpectIntEQ(wc_DsaSign(hash, NULL, &key, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20558. ExpectIntEQ(wc_DsaSign(hash, signature, NULL, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20559. ExpectIntEQ(wc_DsaSign(hash, signature, &key, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20560. /* Verify. */
  20561. ExpectIntEQ(wc_DsaVerify(hash, signature, &key, &answer), 0);
  20562. ExpectIntEQ(answer, 1);
  20563. /* Pass in bad args. */
  20564. ExpectIntEQ(wc_DsaVerify(NULL, signature, &key, &answer), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20565. ExpectIntEQ(wc_DsaVerify(hash, NULL, &key, &answer), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20566. ExpectIntEQ(wc_DsaVerify(hash, signature, NULL, &answer), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20567. ExpectIntEQ(wc_DsaVerify(hash, signature, &key, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20568. #if !defined(HAVE_FIPS) && defined(WOLFSSL_PUBLIC_MP)
  20569. /* hard set q to 0 and test fail case */
  20570. mp_free(&key.q);
  20571. mp_init(&key.q);
  20572. ExpectIntEQ(wc_DsaSign(hash, signature, &key, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20573. mp_set(&key.q, 1);
  20574. ExpectIntEQ(wc_DsaSign(hash, signature, &key, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20575. #endif
  20576. DoExpectIntEQ(wc_FreeRng(&rng),0);
  20577. wc_FreeDsaKey(&key);
  20578. wc_ShaFree(&sha);
  20579. #endif
  20580. return EXPECT_RESULT();
  20581. } /* END test_wc_DsaSign */
  20582. /*
  20583. * Testing wc_DsaPrivateKeyDecode() and wc_DsaPublicKeyDecode()
  20584. */
  20585. static int test_wc_DsaPublicPrivateKeyDecode(void)
  20586. {
  20587. EXPECT_DECLS;
  20588. #if !defined(NO_DSA)
  20589. DsaKey key;
  20590. word32 bytes = 0;
  20591. word32 idx = 0;
  20592. int ret = 0;
  20593. #ifdef USE_CERT_BUFFERS_1024
  20594. byte tmp[ONEK_BUF];
  20595. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  20596. bytes = sizeof_dsa_key_der_1024;
  20597. #elif defined(USE_CERT_BUFFERS_2048)
  20598. byte tmp[TWOK_BUF];
  20599. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  20600. bytes = sizeof_dsa_key_der_2048;
  20601. #else
  20602. byte tmp[TWOK_BUF];
  20603. XFILE fp = XBADFILE;
  20604. XMEMSET(tmp, 0, sizeof(tmp));
  20605. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb")) != XBADFILE);
  20606. ExpectTrue((bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), fp)) > 0);
  20607. if (fp != XBADFILE)
  20608. XFCLOSE(fp);
  20609. #endif /* END USE_CERT_BUFFERS_1024 */
  20610. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20611. ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, &idx, &key, bytes), 0);
  20612. /* Test bad args. */
  20613. ExpectIntEQ(wc_DsaPrivateKeyDecode(NULL, &idx, &key, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20614. ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, NULL, &key, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20615. ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, &idx, NULL, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20616. ExpectIntLT(ret = wc_DsaPrivateKeyDecode(tmp, &idx, &key, bytes), 0);
  20617. ExpectTrue((ret == WC_NO_ERR_TRACE(ASN_PARSE_E)) || (ret == WC_NO_ERR_TRACE(BUFFER_E)));
  20618. wc_FreeDsaKey(&key);
  20619. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20620. idx = 0; /* Reset */
  20621. ExpectIntEQ(wc_DsaPublicKeyDecode(tmp, &idx, &key, bytes), 0);
  20622. /* Test bad args. */
  20623. ExpectIntEQ(wc_DsaPublicKeyDecode(NULL, &idx, &key, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20624. ExpectIntEQ(wc_DsaPublicKeyDecode(tmp, NULL, &key, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20625. ExpectIntEQ(wc_DsaPublicKeyDecode(tmp, &idx, NULL, bytes), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20626. ExpectIntLT(ret = wc_DsaPublicKeyDecode(tmp, &idx, &key, bytes), 0);
  20627. ExpectTrue((ret == WC_NO_ERR_TRACE(ASN_PARSE_E)) || (ret == WC_NO_ERR_TRACE(BUFFER_E)));
  20628. wc_FreeDsaKey(&key);
  20629. #endif /* !NO_DSA */
  20630. return EXPECT_RESULT();
  20631. } /* END test_wc_DsaPublicPrivateKeyDecode */
  20632. /*
  20633. * Testing wc_MakeDsaKey() and wc_MakeDsaParameters()
  20634. */
  20635. static int test_wc_MakeDsaKey(void)
  20636. {
  20637. EXPECT_DECLS;
  20638. #if !defined(NO_DSA) && defined(WOLFSSL_KEY_GEN)
  20639. DsaKey genKey;
  20640. WC_RNG rng;
  20641. XMEMSET(&genKey, 0, sizeof(genKey));
  20642. XMEMSET(&rng, 0, sizeof(rng));
  20643. ExpectIntEQ(wc_InitDsaKey(&genKey), 0);
  20644. ExpectIntEQ(wc_InitRng(&rng), 0);
  20645. ExpectIntEQ(wc_MakeDsaParameters(&rng, ONEK_BUF, &genKey), 0);
  20646. /* Test bad args. */
  20647. ExpectIntEQ(wc_MakeDsaParameters(NULL, ONEK_BUF, &genKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20648. ExpectIntEQ(wc_MakeDsaParameters(&rng, ONEK_BUF, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20649. ExpectIntEQ(wc_MakeDsaParameters(&rng, ONEK_BUF + 1, &genKey),
  20650. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20651. ExpectIntEQ(wc_MakeDsaKey(&rng, &genKey), 0);
  20652. /* Test bad args. */
  20653. ExpectIntEQ(wc_MakeDsaKey(NULL, &genKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20654. ExpectIntEQ(wc_MakeDsaKey(&rng, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20655. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20656. wc_FreeDsaKey(&genKey);
  20657. #endif
  20658. return EXPECT_RESULT();
  20659. } /* END test_wc_MakeDsaKey */
  20660. /*
  20661. * Testing wc_DsaKeyToDer()
  20662. */
  20663. static int test_wc_DsaKeyToDer(void)
  20664. {
  20665. EXPECT_DECLS;
  20666. #if !defined(NO_DSA) && defined(WOLFSSL_KEY_GEN)
  20667. DsaKey key;
  20668. word32 bytes;
  20669. word32 idx = 0;
  20670. #ifdef USE_CERT_BUFFERS_1024
  20671. byte tmp[ONEK_BUF];
  20672. byte der[ONEK_BUF];
  20673. XMEMSET(tmp, 0, sizeof(tmp));
  20674. XMEMSET(der, 0, sizeof(der));
  20675. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  20676. bytes = sizeof_dsa_key_der_1024;
  20677. #elif defined(USE_CERT_BUFFERS_2048)
  20678. byte tmp[TWOK_BUF];
  20679. byte der[TWOK_BUF];
  20680. XMEMSET(tmp, 0, sizeof(tmp));
  20681. XMEMSET(der, 0, sizeof(der));
  20682. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  20683. bytes = sizeof_dsa_key_der_2048;
  20684. #else
  20685. byte tmp[TWOK_BUF];
  20686. byte der[TWOK_BUF];
  20687. XFILE fp = XBADFILE;
  20688. XMEMSET(tmp, 0, sizeof(tmp));
  20689. XMEMSET(der, 0, sizeof(der));
  20690. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb")) != XBADFILE);
  20691. ExpectTrue((bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), fp)) > 0);
  20692. if (fp != XBADFILE)
  20693. XFCLOSE(fp);
  20694. #endif /* END USE_CERT_BUFFERS_1024 */
  20695. XMEMSET(&key, 0, sizeof(DsaKey));
  20696. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20697. ExpectIntEQ(wc_DsaPrivateKeyDecode(tmp, &idx, &key, bytes), 0);
  20698. ExpectIntGE(wc_DsaKeyToDer(&key, der, bytes), 0);
  20699. ExpectIntEQ(XMEMCMP(der, tmp, bytes), 0);
  20700. /* Test bad args. */
  20701. ExpectIntEQ(wc_DsaKeyToDer(NULL, der, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20702. ExpectIntEQ(wc_DsaKeyToDer(&key, NULL, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20703. wc_FreeDsaKey(&key);
  20704. #endif /* !NO_DSA && WOLFSSL_KEY_GEN */
  20705. return EXPECT_RESULT();
  20706. } /* END test_wc_DsaKeyToDer */
  20707. /*
  20708. * Testing wc_DsaKeyToPublicDer()
  20709. * (indirectly testing setDsaPublicKey())
  20710. */
  20711. static int test_wc_DsaKeyToPublicDer(void)
  20712. {
  20713. EXPECT_DECLS;
  20714. #ifndef HAVE_SELFTEST
  20715. #if !defined(NO_DSA) && defined(WOLFSSL_KEY_GEN)
  20716. DsaKey key;
  20717. WC_RNG rng;
  20718. byte* der = NULL;
  20719. word32 sz = 0;
  20720. word32 idx = 0;
  20721. XMEMSET(&key, 0, sizeof(DsaKey));
  20722. XMEMSET(&rng, 0, sizeof(WC_RNG));
  20723. ExpectNotNull(der = (byte*)XMALLOC(ONEK_BUF, NULL,
  20724. DYNAMIC_TYPE_TMP_BUFFER));
  20725. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20726. ExpectIntEQ(wc_InitRng(&rng), 0);
  20727. ExpectIntEQ(wc_MakeDsaParameters(&rng, ONEK_BUF, &key), 0);
  20728. ExpectIntEQ(wc_MakeDsaKey(&rng, &key), 0);
  20729. ExpectIntGE(sz = (word32)wc_DsaKeyToPublicDer(&key, der, ONEK_BUF), 0);
  20730. wc_FreeDsaKey(&key);
  20731. idx = 0;
  20732. ExpectIntEQ(wc_DsaPublicKeyDecode(der, &idx, &key, sz), 0);
  20733. /* Test without the SubjectPublicKeyInfo header */
  20734. ExpectIntGE(sz = (word32)wc_SetDsaPublicKey(der, &key, ONEK_BUF, 0), 0);
  20735. wc_FreeDsaKey(&key);
  20736. idx = 0;
  20737. ExpectIntEQ(wc_DsaPublicKeyDecode(der, &idx, &key, sz), 0);
  20738. /* Test bad args. */
  20739. ExpectIntEQ(wc_DsaKeyToPublicDer(NULL, der, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20740. ExpectIntEQ(wc_DsaKeyToPublicDer(&key, NULL, FOURK_BUF), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20741. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20742. wc_FreeDsaKey(&key);
  20743. XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  20744. #endif /* !NO_DSA && WOLFSSL_KEY_GEN */
  20745. #endif /* !HAVE_SELFTEST */
  20746. return EXPECT_RESULT();
  20747. } /* END test_wc_DsaKeyToPublicDer */
  20748. /*
  20749. * Testing wc_DsaImportParamsRaw()
  20750. */
  20751. static int test_wc_DsaImportParamsRaw(void)
  20752. {
  20753. EXPECT_DECLS;
  20754. #if !defined(NO_DSA)
  20755. DsaKey key;
  20756. /* [mod = L=1024, N=160], from CAVP KeyPair */
  20757. const char* p = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d"
  20758. "4b725ef341eabb47cf8a7a8a41e792a156b7ce97206c4f9c"
  20759. "5ce6fc5ae7912102b6b502e59050b5b21ce263dddb2044b6"
  20760. "52236f4d42ab4b5d6aa73189cef1ace778d7845a5c1c1c71"
  20761. "47123188f8dc551054ee162b634d60f097f719076640e209"
  20762. "80a0093113a8bd73";
  20763. const char* q = "96c5390a8b612c0e422bb2b0ea194a3ec935a281";
  20764. const char* g = "06b7861abbd35cc89e79c52f68d20875389b127361ca66822"
  20765. "138ce4991d2b862259d6b4548a6495b195aa0e0b6137ca37e"
  20766. "b23b94074d3c3d300042bdf15762812b6333ef7b07ceba786"
  20767. "07610fcc9ee68491dbc1e34cd12615474e52b18bc934fb00c"
  20768. "61d39e7da8902291c4434a4e2224c3f4fd9f93cd6f4f17fc0"
  20769. "76341a7e7d9";
  20770. /* invalid p and q parameters */
  20771. const char* invalidP = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d";
  20772. const char* invalidQ = "96c5390a";
  20773. XMEMSET(&key, 0, sizeof(DsaKey));
  20774. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20775. ExpectIntEQ(wc_DsaImportParamsRaw(&key, p, q, g), 0);
  20776. /* test bad args */
  20777. /* null key struct */
  20778. ExpectIntEQ(wc_DsaImportParamsRaw(NULL, p, q, g), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20779. /* null param pointers */
  20780. ExpectIntEQ(wc_DsaImportParamsRaw(&key, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20781. /* illegal p length */
  20782. ExpectIntEQ(wc_DsaImportParamsRaw(&key, invalidP, q, g), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20783. /* illegal q length */
  20784. ExpectIntEQ(wc_DsaImportParamsRaw(&key, p, invalidQ, g), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20785. wc_FreeDsaKey(&key);
  20786. #endif
  20787. return EXPECT_RESULT();
  20788. } /* END test_wc_DsaImportParamsRaw */
  20789. /*
  20790. * Testing wc_DsaImportParamsRawCheck()
  20791. */
  20792. static int test_wc_DsaImportParamsRawCheck(void)
  20793. {
  20794. EXPECT_DECLS;
  20795. #if !defined(NO_DSA) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  20796. DsaKey key;
  20797. int trusted = 0;
  20798. /* [mod = L=1024, N=160], from CAVP KeyPair */
  20799. const char* p = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d"
  20800. "4b725ef341eabb47cf8a7a8a41e792a156b7ce97206c4f9c"
  20801. "5ce6fc5ae7912102b6b502e59050b5b21ce263dddb2044b6"
  20802. "52236f4d42ab4b5d6aa73189cef1ace778d7845a5c1c1c71"
  20803. "47123188f8dc551054ee162b634d60f097f719076640e209"
  20804. "80a0093113a8bd73";
  20805. const char* q = "96c5390a8b612c0e422bb2b0ea194a3ec935a281";
  20806. const char* g = "06b7861abbd35cc89e79c52f68d20875389b127361ca66822"
  20807. "138ce4991d2b862259d6b4548a6495b195aa0e0b6137ca37e"
  20808. "b23b94074d3c3d300042bdf15762812b6333ef7b07ceba786"
  20809. "07610fcc9ee68491dbc1e34cd12615474e52b18bc934fb00c"
  20810. "61d39e7da8902291c4434a4e2224c3f4fd9f93cd6f4f17fc0"
  20811. "76341a7e7d9";
  20812. /* invalid p and q parameters */
  20813. const char* invalidP = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d";
  20814. const char* invalidQ = "96c5390a";
  20815. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20816. ExpectIntEQ(wc_DsaImportParamsRawCheck(&key, p, q, g, trusted, NULL), 0);
  20817. /* test bad args */
  20818. /* null key struct */
  20819. ExpectIntEQ(wc_DsaImportParamsRawCheck(NULL, p, q, g, trusted, NULL),
  20820. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20821. /* null param pointers */
  20822. ExpectIntEQ(wc_DsaImportParamsRawCheck(&key, NULL, NULL, NULL, trusted,
  20823. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20824. /* illegal p length */
  20825. ExpectIntEQ(wc_DsaImportParamsRawCheck(&key, invalidP, q, g, trusted, NULL),
  20826. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20827. /* illegal q length */
  20828. ExpectIntEQ(wc_DsaImportParamsRawCheck(&key, p, invalidQ, g, trusted, NULL),
  20829. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20830. wc_FreeDsaKey(&key);
  20831. #endif
  20832. return EXPECT_RESULT();
  20833. } /* END test_wc_DsaImportParamsRawCheck */
  20834. /*
  20835. * Testing wc_DsaExportParamsRaw()
  20836. */
  20837. static int test_wc_DsaExportParamsRaw(void)
  20838. {
  20839. EXPECT_DECLS;
  20840. #if !defined(NO_DSA)
  20841. DsaKey key;
  20842. /* [mod = L=1024, N=160], from CAVP KeyPair */
  20843. const char* p = "d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d"
  20844. "4b725ef341eabb47cf8a7a8a41e792a156b7ce97206c4f9c"
  20845. "5ce6fc5ae7912102b6b502e59050b5b21ce263dddb2044b6"
  20846. "52236f4d42ab4b5d6aa73189cef1ace778d7845a5c1c1c71"
  20847. "47123188f8dc551054ee162b634d60f097f719076640e209"
  20848. "80a0093113a8bd73";
  20849. const char* q = "96c5390a8b612c0e422bb2b0ea194a3ec935a281";
  20850. const char* g = "06b7861abbd35cc89e79c52f68d20875389b127361ca66822"
  20851. "138ce4991d2b862259d6b4548a6495b195aa0e0b6137ca37e"
  20852. "b23b94074d3c3d300042bdf15762812b6333ef7b07ceba786"
  20853. "07610fcc9ee68491dbc1e34cd12615474e52b18bc934fb00c"
  20854. "61d39e7da8902291c4434a4e2224c3f4fd9f93cd6f4f17fc0"
  20855. "76341a7e7d9";
  20856. const char* pCompare = "\xd3\x83\x11\xe2\xcd\x38\x8c\x3e\xd6\x98\xe8\x2f"
  20857. "\xdf\x88\xeb\x92\xb5\xa9\xa4\x83\xdc\x88\x00\x5d"
  20858. "\x4b\x72\x5e\xf3\x41\xea\xbb\x47\xcf\x8a\x7a\x8a"
  20859. "\x41\xe7\x92\xa1\x56\xb7\xce\x97\x20\x6c\x4f\x9c"
  20860. "\x5c\xe6\xfc\x5a\xe7\x91\x21\x02\xb6\xb5\x02\xe5"
  20861. "\x90\x50\xb5\xb2\x1c\xe2\x63\xdd\xdb\x20\x44\xb6"
  20862. "\x52\x23\x6f\x4d\x42\xab\x4b\x5d\x6a\xa7\x31\x89"
  20863. "\xce\xf1\xac\xe7\x78\xd7\x84\x5a\x5c\x1c\x1c\x71"
  20864. "\x47\x12\x31\x88\xf8\xdc\x55\x10\x54\xee\x16\x2b"
  20865. "\x63\x4d\x60\xf0\x97\xf7\x19\x07\x66\x40\xe2\x09"
  20866. "\x80\xa0\x09\x31\x13\xa8\xbd\x73";
  20867. const char* qCompare = "\x96\xc5\x39\x0a\x8b\x61\x2c\x0e\x42\x2b\xb2\xb0"
  20868. "\xea\x19\x4a\x3e\xc9\x35\xa2\x81";
  20869. const char* gCompare = "\x06\xb7\x86\x1a\xbb\xd3\x5c\xc8\x9e\x79\xc5\x2f"
  20870. "\x68\xd2\x08\x75\x38\x9b\x12\x73\x61\xca\x66\x82"
  20871. "\x21\x38\xce\x49\x91\xd2\xb8\x62\x25\x9d\x6b\x45"
  20872. "\x48\xa6\x49\x5b\x19\x5a\xa0\xe0\xb6\x13\x7c\xa3"
  20873. "\x7e\xb2\x3b\x94\x07\x4d\x3c\x3d\x30\x00\x42\xbd"
  20874. "\xf1\x57\x62\x81\x2b\x63\x33\xef\x7b\x07\xce\xba"
  20875. "\x78\x60\x76\x10\xfc\xc9\xee\x68\x49\x1d\xbc\x1e"
  20876. "\x34\xcd\x12\x61\x54\x74\xe5\x2b\x18\xbc\x93\x4f"
  20877. "\xb0\x0c\x61\xd3\x9e\x7d\xa8\x90\x22\x91\xc4\x43"
  20878. "\x4a\x4e\x22\x24\xc3\xf4\xfd\x9f\x93\xcd\x6f\x4f"
  20879. "\x17\xfc\x07\x63\x41\xa7\xe7\xd9";
  20880. byte pOut[MAX_DSA_PARAM_SIZE];
  20881. byte qOut[MAX_DSA_PARAM_SIZE];
  20882. byte gOut[MAX_DSA_PARAM_SIZE];
  20883. word32 pOutSz;
  20884. word32 qOutSz;
  20885. word32 gOutSz;
  20886. XMEMSET(&key, 0, sizeof(DsaKey));
  20887. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20888. /* first test using imported raw parameters, for expected */
  20889. ExpectIntEQ(wc_DsaImportParamsRaw(&key, p, q, g), 0);
  20890. pOutSz = sizeof(pOut);
  20891. qOutSz = sizeof(qOut);
  20892. gOutSz = sizeof(gOut);
  20893. ExpectIntEQ(wc_DsaExportParamsRaw(&key, pOut, &pOutSz, qOut, &qOutSz, gOut,
  20894. &gOutSz), 0);
  20895. /* validate exported parameters are correct */
  20896. ExpectIntEQ(XMEMCMP(pOut, pCompare, pOutSz), 0);
  20897. ExpectIntEQ(XMEMCMP(qOut, qCompare, qOutSz), 0);
  20898. ExpectIntEQ(XMEMCMP(gOut, gCompare, gOutSz), 0);
  20899. /* test bad args */
  20900. /* null key struct */
  20901. ExpectIntEQ(wc_DsaExportParamsRaw(NULL, pOut, &pOutSz, qOut, &qOutSz, gOut,
  20902. &gOutSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20903. /* null output pointers */
  20904. ExpectIntEQ(wc_DsaExportParamsRaw(&key, NULL, &pOutSz, NULL, &qOutSz, NULL,
  20905. &gOutSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  20906. /* null output size pointers */
  20907. ExpectIntEQ( wc_DsaExportParamsRaw(&key, pOut, NULL, qOut, NULL, gOut,
  20908. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20909. /* p output buffer size too small */
  20910. pOutSz = 1;
  20911. ExpectIntEQ(wc_DsaExportParamsRaw(&key, pOut, &pOutSz, qOut, &qOutSz, gOut,
  20912. &gOutSz), WC_NO_ERR_TRACE(BUFFER_E));
  20913. pOutSz = sizeof(pOut);
  20914. /* q output buffer size too small */
  20915. qOutSz = 1;
  20916. ExpectIntEQ(wc_DsaExportParamsRaw(&key, pOut, &pOutSz, qOut, &qOutSz, gOut,
  20917. &gOutSz), WC_NO_ERR_TRACE(BUFFER_E));
  20918. qOutSz = sizeof(qOut);
  20919. /* g output buffer size too small */
  20920. gOutSz = 1;
  20921. ExpectIntEQ(wc_DsaExportParamsRaw(&key, pOut, &pOutSz, qOut, &qOutSz, gOut,
  20922. &gOutSz), WC_NO_ERR_TRACE(BUFFER_E));
  20923. wc_FreeDsaKey(&key);
  20924. #endif
  20925. return EXPECT_RESULT();
  20926. } /* END test_wc_DsaExportParamsRaw */
  20927. /*
  20928. * Testing wc_DsaExportKeyRaw()
  20929. */
  20930. static int test_wc_DsaExportKeyRaw(void)
  20931. {
  20932. EXPECT_DECLS;
  20933. #if !defined(NO_DSA) && defined(WOLFSSL_KEY_GEN)
  20934. DsaKey key;
  20935. WC_RNG rng;
  20936. byte xOut[MAX_DSA_PARAM_SIZE];
  20937. byte yOut[MAX_DSA_PARAM_SIZE];
  20938. word32 xOutSz, yOutSz;
  20939. XMEMSET(&key, 0, sizeof(key));
  20940. XMEMSET(&rng, 0, sizeof(rng));
  20941. ExpectIntEQ(wc_InitDsaKey(&key), 0);
  20942. ExpectIntEQ(wc_InitRng(&rng), 0);
  20943. ExpectIntEQ(wc_MakeDsaParameters(&rng, 1024, &key), 0);
  20944. ExpectIntEQ(wc_MakeDsaKey(&rng, &key), 0);
  20945. /* try successful export */
  20946. xOutSz = sizeof(xOut);
  20947. yOutSz = sizeof(yOut);
  20948. ExpectIntEQ(wc_DsaExportKeyRaw(&key, xOut, &xOutSz, yOut, &yOutSz), 0);
  20949. /* test bad args */
  20950. /* null key struct */
  20951. ExpectIntEQ(wc_DsaExportKeyRaw(NULL, xOut, &xOutSz, yOut, &yOutSz),
  20952. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20953. /* null output pointers */
  20954. ExpectIntEQ(wc_DsaExportKeyRaw(&key, NULL, &xOutSz, NULL, &yOutSz),
  20955. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  20956. /* null output size pointers */
  20957. ExpectIntEQ(wc_DsaExportKeyRaw(&key, xOut, NULL, yOut, NULL),
  20958. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20959. /* x output buffer size too small */
  20960. xOutSz = 1;
  20961. ExpectIntEQ(wc_DsaExportKeyRaw(&key, xOut, &xOutSz, yOut, &yOutSz),
  20962. WC_NO_ERR_TRACE(BUFFER_E));
  20963. xOutSz = sizeof(xOut);
  20964. /* y output buffer size too small */
  20965. yOutSz = 1;
  20966. ExpectIntEQ(wc_DsaExportKeyRaw(&key, xOut, &xOutSz, yOut, &yOutSz),
  20967. WC_NO_ERR_TRACE(BUFFER_E));
  20968. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  20969. wc_FreeDsaKey(&key);
  20970. #endif
  20971. return EXPECT_RESULT();
  20972. } /* END test_wc_DsaExportParamsRaw */
  20973. /*
  20974. * Testing wc_ed25519_make_key().
  20975. */
  20976. static int test_wc_ed25519_make_key(void)
  20977. {
  20978. EXPECT_DECLS;
  20979. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_MAKE_KEY)
  20980. ed25519_key key;
  20981. WC_RNG rng;
  20982. unsigned char pubkey[ED25519_PUB_KEY_SIZE+1];
  20983. int pubkey_sz = ED25519_PUB_KEY_SIZE;
  20984. XMEMSET(&key, 0, sizeof(ed25519_key));
  20985. XMEMSET(&rng, 0, sizeof(WC_RNG));
  20986. ExpectIntEQ(wc_ed25519_init(&key), 0);
  20987. ExpectIntEQ(wc_InitRng(&rng), 0);
  20988. ExpectIntEQ(wc_ed25519_make_public(&key, pubkey, (word32)pubkey_sz),
  20989. WC_NO_ERR_TRACE(ECC_PRIV_KEY_E));
  20990. ExpectIntEQ(wc_ed25519_make_public(&key, pubkey+1, (word32)pubkey_sz),
  20991. WC_NO_ERR_TRACE(ECC_PRIV_KEY_E));
  20992. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  20993. /* Test bad args. */
  20994. ExpectIntEQ(wc_ed25519_make_key(NULL, ED25519_KEY_SIZE, &key),
  20995. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20996. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, NULL),
  20997. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  20998. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE - 1, &key),
  20999. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21000. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE + 1, &key),
  21001. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21002. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21003. wc_ed25519_free(&key);
  21004. #endif
  21005. return EXPECT_RESULT();
  21006. } /* END test_wc_ed25519_make_key */
  21007. /*
  21008. * Testing wc_ed25519_init()
  21009. */
  21010. static int test_wc_ed25519_init(void)
  21011. {
  21012. EXPECT_DECLS;
  21013. #if defined(HAVE_ED25519)
  21014. ed25519_key key;
  21015. XMEMSET(&key, 0, sizeof(ed25519_key));
  21016. ExpectIntEQ(wc_ed25519_init(&key), 0);
  21017. /* Test bad args. */
  21018. ExpectIntEQ(wc_ed25519_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21019. wc_ed25519_free(&key);
  21020. #endif
  21021. return EXPECT_RESULT();
  21022. } /* END test_wc_ed25519_init */
  21023. /*
  21024. * Test wc_ed25519_sign_msg() and wc_ed25519_verify_msg()
  21025. */
  21026. static int test_wc_ed25519_sign_msg(void)
  21027. {
  21028. EXPECT_DECLS;
  21029. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_SIGN)
  21030. WC_RNG rng;
  21031. ed25519_key key;
  21032. byte msg[] = "Everybody gets Friday off.\n";
  21033. byte sig[ED25519_SIG_SIZE+1];
  21034. word32 msglen = sizeof(msg);
  21035. word32 siglen = ED25519_SIG_SIZE;
  21036. word32 badSigLen = ED25519_SIG_SIZE - 1;
  21037. #ifdef HAVE_ED25519_VERIFY
  21038. int verify_ok = 0; /*1 = Verify success.*/
  21039. #endif
  21040. /* Initialize stack variables. */
  21041. XMEMSET(&key, 0, sizeof(ed25519_key));
  21042. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21043. XMEMSET(sig, 0, sizeof(sig));
  21044. /* Initialize key. */
  21045. ExpectIntEQ(wc_ed25519_init(&key), 0);
  21046. ExpectIntEQ(wc_InitRng(&rng), 0);
  21047. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  21048. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig, &siglen, &key), 0);
  21049. ExpectIntEQ(siglen, ED25519_SIG_SIZE);
  21050. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig+1, &siglen, &key), 0);
  21051. ExpectIntEQ(siglen, ED25519_SIG_SIZE);
  21052. /* Test bad args. */
  21053. ExpectIntEQ(wc_ed25519_sign_msg(NULL, msglen, sig, &siglen, &key),
  21054. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21055. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, NULL, &siglen, &key),
  21056. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21057. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig, NULL, &key),
  21058. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21059. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig, &siglen, NULL),
  21060. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21061. ExpectIntEQ(wc_ed25519_sign_msg(msg, msglen, sig, &badSigLen, &key),
  21062. WC_NO_ERR_TRACE(BUFFER_E));
  21063. ExpectIntEQ(badSigLen, ED25519_SIG_SIZE);
  21064. badSigLen -= 1;
  21065. #ifdef HAVE_ED25519_VERIFY
  21066. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen, msg, msglen, &verify_ok,
  21067. &key), 0);
  21068. ExpectIntEQ(verify_ok, 1);
  21069. /* Test bad args. */
  21070. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen - 1, msg, msglen,
  21071. &verify_ok, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21072. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen + 1, msg, msglen,
  21073. &verify_ok, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21074. ExpectIntEQ(wc_ed25519_verify_msg(NULL, siglen, msg, msglen, &verify_ok,
  21075. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21076. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen, NULL, msglen, &verify_ok,
  21077. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21078. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen, msg, msglen, NULL, &key),
  21079. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21080. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, siglen, msg, msglen, &verify_ok,
  21081. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21082. ExpectIntEQ(wc_ed25519_verify_msg(sig+1, badSigLen, msg, msglen, &verify_ok,
  21083. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21084. #endif /* Verify. */
  21085. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21086. wc_ed25519_free(&key);
  21087. #endif
  21088. return EXPECT_RESULT();
  21089. } /* END test_wc_ed25519_sign_msg */
  21090. /*
  21091. * Testing wc_ed25519_import_public()
  21092. */
  21093. static int test_wc_ed25519_import_public(void)
  21094. {
  21095. EXPECT_DECLS;
  21096. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_IMPORT)
  21097. ed25519_key pubKey;
  21098. WC_RNG rng;
  21099. const byte in[] = "Ed25519PublicKeyUnitTest......\n";
  21100. word32 inlen = sizeof(in);
  21101. XMEMSET(&pubKey, 0, sizeof(ed25519_key));
  21102. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21103. ExpectIntEQ(wc_ed25519_init(&pubKey), 0);
  21104. ExpectIntEQ(wc_InitRng(&rng), 0);
  21105. #ifdef HAVE_ED25519_MAKE_KEY
  21106. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &pubKey), 0);
  21107. #endif
  21108. ExpectIntEQ(wc_ed25519_import_public_ex(in, inlen, &pubKey, 1), 0);
  21109. ExpectIntEQ(XMEMCMP(in, pubKey.p, inlen), 0);
  21110. /* Test bad args. */
  21111. ExpectIntEQ(wc_ed25519_import_public(NULL, inlen, &pubKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21112. ExpectIntEQ(wc_ed25519_import_public(in, inlen, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21113. ExpectIntEQ(wc_ed25519_import_public(in, inlen - 1, &pubKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21114. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21115. wc_ed25519_free(&pubKey);
  21116. #endif
  21117. return EXPECT_RESULT();
  21118. } /* END wc_ed25519_import_public */
  21119. /*
  21120. * Testing wc_ed25519_import_private_key()
  21121. */
  21122. static int test_wc_ed25519_import_private_key(void)
  21123. {
  21124. EXPECT_DECLS;
  21125. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_IMPORT)
  21126. ed25519_key key;
  21127. WC_RNG rng;
  21128. const byte privKey[] = "Ed25519PrivateKeyUnitTest.....\n";
  21129. const byte pubKey[] = "Ed25519PublicKeyUnitTest......\n";
  21130. word32 privKeySz = sizeof(privKey);
  21131. word32 pubKeySz = sizeof(pubKey);
  21132. #ifdef HAVE_ED25519_KEY_EXPORT
  21133. byte bothKeys[sizeof(privKey) + sizeof(pubKey)];
  21134. word32 bothKeysSz = sizeof(bothKeys);
  21135. #endif
  21136. XMEMSET(&key, 0, sizeof(ed25519_key));
  21137. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21138. ExpectIntEQ(wc_ed25519_init(&key), 0);
  21139. ExpectIntEQ(wc_InitRng(&rng), 0);
  21140. #ifdef HAVE_ED25519_MAKE_KEY
  21141. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  21142. #endif
  21143. ExpectIntEQ(wc_ed25519_import_private_key_ex(privKey, privKeySz, pubKey,
  21144. pubKeySz, &key, 1), 0);
  21145. ExpectIntEQ(XMEMCMP(pubKey, key.p, privKeySz), 0);
  21146. ExpectIntEQ(XMEMCMP(privKey, key.k, pubKeySz), 0);
  21147. #ifdef HAVE_ED25519_KEY_EXPORT
  21148. PRIVATE_KEY_UNLOCK();
  21149. ExpectIntEQ(wc_ed25519_export_private(&key, bothKeys, &bothKeysSz), 0);
  21150. PRIVATE_KEY_LOCK();
  21151. ExpectIntEQ(wc_ed25519_import_private_key_ex(bothKeys, bothKeysSz, NULL, 0,
  21152. &key, 1), 0);
  21153. ExpectIntEQ(XMEMCMP(pubKey, key.p, privKeySz), 0);
  21154. ExpectIntEQ(XMEMCMP(privKey, key.k, pubKeySz), 0);
  21155. #endif
  21156. /* Test bad args. */
  21157. ExpectIntEQ(wc_ed25519_import_private_key(NULL, privKeySz, pubKey, pubKeySz,
  21158. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21159. ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz, NULL,
  21160. pubKeySz, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21161. ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz, pubKey,
  21162. pubKeySz, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21163. ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz - 1, pubKey,
  21164. pubKeySz, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21165. ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz, pubKey,
  21166. pubKeySz - 1, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21167. ExpectIntEQ(wc_ed25519_import_private_key(privKey, privKeySz, NULL, 0,
  21168. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21169. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21170. wc_ed25519_free(&key);
  21171. #endif
  21172. return EXPECT_RESULT();
  21173. } /* END test_wc_ed25519_import_private_key */
  21174. /*
  21175. * Testing wc_ed25519_export_public() and wc_ed25519_export_private_only()
  21176. */
  21177. static int test_wc_ed25519_export(void)
  21178. {
  21179. EXPECT_DECLS;
  21180. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  21181. ed25519_key key;
  21182. WC_RNG rng;
  21183. byte priv[ED25519_PRV_KEY_SIZE];
  21184. byte pub[ED25519_PUB_KEY_SIZE];
  21185. word32 privSz = sizeof(priv);
  21186. word32 pubSz = sizeof(pub);
  21187. #ifndef HAVE_ED25519_MAKE_KEY
  21188. const byte privKey[] = {
  21189. 0xf8, 0x55, 0xb7, 0xb6, 0x49, 0x3f, 0x99, 0x9c,
  21190. 0x88, 0xe3, 0xc5, 0x42, 0x6a, 0xa4, 0x47, 0x4a,
  21191. 0xe4, 0x95, 0xda, 0xdb, 0xbf, 0xf8, 0xa7, 0x42,
  21192. 0x9d, 0x0e, 0xe7, 0xd0, 0x57, 0x8f, 0x16, 0x69
  21193. };
  21194. const byte pubKey[] = {
  21195. 0x42, 0x3b, 0x7a, 0xf9, 0x82, 0xcf, 0xf9, 0xdf,
  21196. 0x19, 0xdd, 0xf3, 0xf0, 0x32, 0x29, 0x6d, 0xfa,
  21197. 0xfd, 0x76, 0x4f, 0x68, 0xc2, 0xc2, 0xe0, 0x6c,
  21198. 0x47, 0xae, 0xc2, 0x55, 0x68, 0xac, 0x0d, 0x4d
  21199. };
  21200. #endif
  21201. XMEMSET(&key, 0, sizeof(ed25519_key));
  21202. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21203. ExpectIntEQ(wc_ed25519_init(&key), 0);
  21204. ExpectIntEQ(wc_InitRng(&rng), 0);
  21205. #ifdef HAVE_ED25519_MAKE_KEY
  21206. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  21207. #else
  21208. ExpectIntEQ(wc_ed25519_import_private_key_ex(privKey, sizeof(privKey),
  21209. pubKey, sizeof(pubKey), &key, 1), 0);
  21210. #endif
  21211. PRIVATE_KEY_UNLOCK();
  21212. ExpectIntEQ(wc_ed25519_export_public(&key, pub, &pubSz), 0);
  21213. ExpectIntEQ(pubSz, ED25519_KEY_SIZE);
  21214. ExpectIntEQ(XMEMCMP(key.p, pub, pubSz), 0);
  21215. /* Test bad args. */
  21216. ExpectIntEQ(wc_ed25519_export_public(NULL, pub, &pubSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21217. ExpectIntEQ(wc_ed25519_export_public(&key, NULL, &pubSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21218. ExpectIntEQ(wc_ed25519_export_public(&key, pub, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21219. ExpectIntEQ(wc_ed25519_export_private_only(&key, priv, &privSz), 0);
  21220. ExpectIntEQ(privSz, ED25519_KEY_SIZE);
  21221. ExpectIntEQ(XMEMCMP(key.k, priv, privSz), 0);
  21222. /* Test bad args. */
  21223. ExpectIntEQ(wc_ed25519_export_private_only(NULL, priv, &privSz),
  21224. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21225. ExpectIntEQ(wc_ed25519_export_private_only(&key, NULL, &privSz),
  21226. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21227. ExpectIntEQ(wc_ed25519_export_private_only(&key, priv, NULL),
  21228. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21229. PRIVATE_KEY_LOCK();
  21230. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21231. wc_ed25519_free(&key);
  21232. #endif
  21233. return EXPECT_RESULT();
  21234. } /* END test_wc_ed25519_export */
  21235. /*
  21236. * Testing wc_ed25519_size()
  21237. */
  21238. static int test_wc_ed25519_size(void)
  21239. {
  21240. EXPECT_DECLS;
  21241. #if defined(HAVE_ED25519)
  21242. ed25519_key key;
  21243. WC_RNG rng;
  21244. #ifndef HAVE_ED25519_MAKE_KEY
  21245. const byte privKey[] = {
  21246. 0xf8, 0x55, 0xb7, 0xb6, 0x49, 0x3f, 0x99, 0x9c,
  21247. 0x88, 0xe3, 0xc5, 0x42, 0x6a, 0xa4, 0x47, 0x4a,
  21248. 0xe4, 0x95, 0xda, 0xdb, 0xbf, 0xf8, 0xa7, 0x42,
  21249. 0x9d, 0x0e, 0xe7, 0xd0, 0x57, 0x8f, 0x16, 0x69
  21250. };
  21251. const byte pubKey[] = {
  21252. 0x42, 0x3b, 0x7a, 0xf9, 0x82, 0xcf, 0xf9, 0xdf,
  21253. 0x19, 0xdd, 0xf3, 0xf0, 0x32, 0x29, 0x6d, 0xfa,
  21254. 0xfd, 0x76, 0x4f, 0x68, 0xc2, 0xc2, 0xe0, 0x6c,
  21255. 0x47, 0xae, 0xc2, 0x55, 0x68, 0xac, 0x0d, 0x4d
  21256. };
  21257. #endif
  21258. XMEMSET(&key, 0, sizeof(ed25519_key));
  21259. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21260. ExpectIntEQ(wc_ed25519_init(&key), 0);
  21261. ExpectIntEQ(wc_InitRng(&rng), 0);
  21262. #ifdef HAVE_ED25519_MAKE_KEY
  21263. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  21264. #else
  21265. ExpectIntEQ(wc_ed25519_import_private_key_ex(privKey, sizeof(privKey),
  21266. pubKey, sizeof(pubKey), &key, 1), 0);
  21267. #endif
  21268. ExpectIntEQ(wc_ed25519_size(&key), ED25519_KEY_SIZE);
  21269. /* Test bad args. */
  21270. ExpectIntEQ(wc_ed25519_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21271. ExpectIntEQ(wc_ed25519_sig_size(&key), ED25519_SIG_SIZE);
  21272. /* Test bad args. */
  21273. ExpectIntEQ(wc_ed25519_sig_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21274. ExpectIntEQ(wc_ed25519_pub_size(&key), ED25519_PUB_KEY_SIZE);
  21275. /* Test bad args. */
  21276. ExpectIntEQ(wc_ed25519_pub_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21277. ExpectIntEQ(wc_ed25519_priv_size(&key), ED25519_PRV_KEY_SIZE);
  21278. /* Test bad args. */
  21279. ExpectIntEQ(wc_ed25519_priv_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21280. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21281. wc_ed25519_free(&key);
  21282. #endif
  21283. return EXPECT_RESULT();
  21284. } /* END test_wc_ed25519_size */
  21285. /*
  21286. * Testing wc_ed25519_export_private() and wc_ed25519_export_key()
  21287. */
  21288. static int test_wc_ed25519_exportKey(void)
  21289. {
  21290. EXPECT_DECLS;
  21291. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  21292. WC_RNG rng;
  21293. ed25519_key key;
  21294. byte priv[ED25519_PRV_KEY_SIZE];
  21295. byte pub[ED25519_PUB_KEY_SIZE];
  21296. byte privOnly[ED25519_PRV_KEY_SIZE];
  21297. word32 privSz = sizeof(priv);
  21298. word32 pubSz = sizeof(pub);
  21299. word32 privOnlySz = sizeof(privOnly);
  21300. #ifndef HAVE_ED25519_MAKE_KEY
  21301. const byte privKey[] = {
  21302. 0xf8, 0x55, 0xb7, 0xb6, 0x49, 0x3f, 0x99, 0x9c,
  21303. 0x88, 0xe3, 0xc5, 0x42, 0x6a, 0xa4, 0x47, 0x4a,
  21304. 0xe4, 0x95, 0xda, 0xdb, 0xbf, 0xf8, 0xa7, 0x42,
  21305. 0x9d, 0x0e, 0xe7, 0xd0, 0x57, 0x8f, 0x16, 0x69
  21306. };
  21307. const byte pubKey[] = {
  21308. 0x42, 0x3b, 0x7a, 0xf9, 0x82, 0xcf, 0xf9, 0xdf,
  21309. 0x19, 0xdd, 0xf3, 0xf0, 0x32, 0x29, 0x6d, 0xfa,
  21310. 0xfd, 0x76, 0x4f, 0x68, 0xc2, 0xc2, 0xe0, 0x6c,
  21311. 0x47, 0xae, 0xc2, 0x55, 0x68, 0xac, 0x0d, 0x4d
  21312. };
  21313. #endif
  21314. XMEMSET(&key, 0, sizeof(ed25519_key));
  21315. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21316. ExpectIntEQ(wc_ed25519_init(&key), 0);
  21317. ExpectIntEQ(wc_InitRng(&rng), 0);
  21318. #ifdef HAVE_ED25519_MAKE_KEY
  21319. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  21320. #else
  21321. ExpectIntEQ(wc_ed25519_import_private_key_ex(privKey, sizeof(privKey),
  21322. pubKey, sizeof(pubKey), &key, 1), 0);
  21323. #endif
  21324. PRIVATE_KEY_UNLOCK();
  21325. ExpectIntEQ(wc_ed25519_export_private(&key, privOnly, &privOnlySz), 0);
  21326. /* Test bad args. */
  21327. ExpectIntEQ(wc_ed25519_export_private(NULL, privOnly, &privOnlySz),
  21328. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21329. ExpectIntEQ(wc_ed25519_export_private(&key, NULL, &privOnlySz),
  21330. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21331. ExpectIntEQ(wc_ed25519_export_private(&key, privOnly, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21332. ExpectIntEQ(wc_ed25519_export_key(&key, priv, &privSz, pub, &pubSz), 0);
  21333. /* Test bad args. */
  21334. ExpectIntEQ(wc_ed25519_export_key(NULL, priv, &privSz, pub, &pubSz),
  21335. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21336. ExpectIntEQ(wc_ed25519_export_key(&key, NULL, &privSz, pub, &pubSz),
  21337. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21338. ExpectIntEQ(wc_ed25519_export_key(&key, priv, NULL, pub, &pubSz),
  21339. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21340. ExpectIntEQ(wc_ed25519_export_key(&key, priv, &privSz, NULL, &pubSz),
  21341. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21342. ExpectIntEQ(wc_ed25519_export_key(&key, priv, &privSz, pub, NULL),
  21343. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21344. PRIVATE_KEY_LOCK();
  21345. /* Cross check output. */
  21346. ExpectIntEQ(XMEMCMP(priv, privOnly, privSz), 0);
  21347. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21348. wc_ed25519_free(&key);
  21349. #endif
  21350. return EXPECT_RESULT();
  21351. } /* END test_wc_ed25519_exportKey */
  21352. /*
  21353. * Testing wc_Ed25519PublicKeyToDer
  21354. */
  21355. static int test_wc_Ed25519PublicKeyToDer(void)
  21356. {
  21357. EXPECT_DECLS;
  21358. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT) && \
  21359. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  21360. ed25519_key key;
  21361. byte derBuf[1024];
  21362. XMEMSET(&key, 0, sizeof(ed25519_key));
  21363. /* Test bad args */
  21364. ExpectIntEQ(wc_Ed25519PublicKeyToDer(NULL, NULL, 0, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21365. ExpectIntEQ(wc_ed25519_init(&key), 0);
  21366. ExpectIntEQ(wc_Ed25519PublicKeyToDer(&key, derBuf, 0, 0), WC_NO_ERR_TRACE(BUFFER_E));
  21367. wc_ed25519_free(&key);
  21368. /* Test good args */
  21369. if (EXPECT_SUCCESS()) {
  21370. WC_RNG rng;
  21371. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21372. ExpectIntEQ(wc_ed25519_init(&key), 0);
  21373. ExpectIntEQ(wc_InitRng(&rng), 0);
  21374. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key), 0);
  21375. /* length only */
  21376. ExpectIntGT(wc_Ed25519PublicKeyToDer(&key, NULL, 0, 0), 0);
  21377. ExpectIntGT(wc_Ed25519PublicKeyToDer(&key, NULL, 0, 1), 0);
  21378. ExpectIntGT(wc_Ed25519PublicKeyToDer(&key, derBuf,
  21379. (word32)sizeof(derBuf), 1), 0);
  21380. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21381. wc_ed25519_free(&key);
  21382. }
  21383. #endif
  21384. return EXPECT_RESULT();
  21385. } /* END testing wc_Ed25519PublicKeyToDer */
  21386. /*
  21387. * Testing wc_curve25519_init and wc_curve25519_free.
  21388. */
  21389. static int test_wc_curve25519_init(void)
  21390. {
  21391. EXPECT_DECLS;
  21392. #if defined(HAVE_CURVE25519)
  21393. curve25519_key key;
  21394. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21395. /* Test bad args for wc_curve25519_init */
  21396. ExpectIntEQ(wc_curve25519_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21397. /* Test good args for wc_curve_25519_free */
  21398. wc_curve25519_free(&key);
  21399. /* Test bad args for wc_curve25519 free. */
  21400. wc_curve25519_free(NULL);
  21401. #endif
  21402. return EXPECT_RESULT();
  21403. } /* END test_wc_curve25519_init and wc_curve_25519_free*/
  21404. /*
  21405. * Testing test_wc_curve25519_size.
  21406. */
  21407. static int test_wc_curve25519_size(void)
  21408. {
  21409. EXPECT_DECLS;
  21410. #if defined(HAVE_CURVE25519)
  21411. curve25519_key key;
  21412. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21413. /* Test good args for wc_curve25519_size */
  21414. ExpectIntEQ(wc_curve25519_size(&key), CURVE25519_KEYSIZE);
  21415. /* Test bad args for wc_curve25519_size */
  21416. ExpectIntEQ(wc_curve25519_size(NULL), 0);
  21417. wc_curve25519_free(&key);
  21418. #endif
  21419. return EXPECT_RESULT();
  21420. } /* END test_wc_curve25519_size*/
  21421. /*
  21422. * Testing test_wc_curve25519_export_key_raw().
  21423. */
  21424. static int test_wc_curve25519_export_key_raw(void)
  21425. {
  21426. EXPECT_DECLS;
  21427. #if defined(HAVE_CURVE25519) && defined(HAVE_CURVE25519_KEY_EXPORT)
  21428. curve25519_key key;
  21429. WC_RNG rng;
  21430. byte privateKey[CURVE25519_KEYSIZE];
  21431. byte publicKey[CURVE25519_KEYSIZE];
  21432. word32 prvkSz;
  21433. word32 pubkSz;
  21434. byte prik[CURVE25519_KEYSIZE];
  21435. byte pubk[CURVE25519_KEYSIZE];
  21436. word32 prksz;
  21437. word32 pbksz;
  21438. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21439. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21440. ExpectIntEQ(wc_InitRng(&rng), 0);
  21441. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21442. /* bad-argument-test cases - target function should return BAD_FUNC_ARG */
  21443. prvkSz = CURVE25519_KEYSIZE;
  21444. pubkSz = CURVE25519_KEYSIZE;
  21445. ExpectIntEQ(wc_curve25519_export_key_raw(NULL, privateKey, &prvkSz,
  21446. publicKey, &pubkSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21447. prvkSz = CURVE25519_KEYSIZE;
  21448. pubkSz = CURVE25519_KEYSIZE;
  21449. ExpectIntEQ(wc_curve25519_export_key_raw(&key, NULL, &prvkSz, publicKey,
  21450. &pubkSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21451. prvkSz = CURVE25519_KEYSIZE;
  21452. pubkSz = CURVE25519_KEYSIZE;
  21453. ExpectIntEQ(wc_curve25519_export_key_raw(&key, privateKey, NULL,
  21454. publicKey, &pubkSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21455. /* prvkSz = CURVE25519_KEYSIZE; */
  21456. pubkSz = CURVE25519_KEYSIZE;
  21457. ExpectIntEQ(wc_curve25519_export_key_raw(&key, privateKey, &prvkSz,
  21458. NULL, &pubkSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21459. prvkSz = CURVE25519_KEYSIZE;
  21460. pubkSz = CURVE25519_KEYSIZE;
  21461. ExpectIntEQ(wc_curve25519_export_key_raw(&key, privateKey, &prvkSz,
  21462. publicKey, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21463. /* cross-testing */
  21464. prksz = CURVE25519_KEYSIZE;
  21465. ExpectIntEQ(wc_curve25519_export_private_raw(&key, prik, &prksz), 0);
  21466. pbksz = CURVE25519_KEYSIZE;
  21467. ExpectIntEQ(wc_curve25519_export_public(&key, pubk, &pbksz), 0);
  21468. prvkSz = CURVE25519_KEYSIZE;
  21469. /* pubkSz = CURVE25519_KEYSIZE; */
  21470. ExpectIntEQ(wc_curve25519_export_key_raw(&key, privateKey, &prvkSz,
  21471. publicKey, &pubkSz), 0);
  21472. ExpectIntEQ(prksz, CURVE25519_KEYSIZE);
  21473. ExpectIntEQ(pbksz, CURVE25519_KEYSIZE);
  21474. ExpectIntEQ(prvkSz, CURVE25519_KEYSIZE);
  21475. ExpectIntEQ(pubkSz, CURVE25519_KEYSIZE);
  21476. ExpectIntEQ(XMEMCMP(privateKey, prik, CURVE25519_KEYSIZE), 0);
  21477. ExpectIntEQ(XMEMCMP(publicKey, pubk, CURVE25519_KEYSIZE), 0);
  21478. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21479. wc_curve25519_free(&key);
  21480. #endif
  21481. return EXPECT_RESULT();
  21482. } /* end of test_wc_curve25519_export_key_raw */
  21483. /*
  21484. * Testing test_wc_curve25519_export_key_raw_ex().
  21485. */
  21486. static int test_wc_curve25519_export_key_raw_ex(void)
  21487. {
  21488. EXPECT_DECLS;
  21489. #if defined(HAVE_CURVE25519) && defined(HAVE_CURVE25519_KEY_EXPORT)
  21490. curve25519_key key;
  21491. WC_RNG rng;
  21492. byte privateKey[CURVE25519_KEYSIZE];
  21493. byte publicKey[CURVE25519_KEYSIZE];
  21494. word32 prvkSz;
  21495. word32 pubkSz;
  21496. byte prik[CURVE25519_KEYSIZE];
  21497. byte pubk[CURVE25519_KEYSIZE];
  21498. word32 prksz;
  21499. word32 pbksz;
  21500. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21501. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21502. ExpectIntEQ(wc_InitRng(&rng), 0);
  21503. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21504. /* bad-argument-test cases - target function should return BAD_FUNC_ARG */
  21505. prvkSz = CURVE25519_KEYSIZE;
  21506. pubkSz = CURVE25519_KEYSIZE;
  21507. ExpectIntEQ(wc_curve25519_export_key_raw_ex(NULL, privateKey,
  21508. &prvkSz, publicKey, &pubkSz, EC25519_LITTLE_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21509. prvkSz = CURVE25519_KEYSIZE;
  21510. pubkSz = CURVE25519_KEYSIZE;
  21511. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, NULL,
  21512. &prvkSz, publicKey, &pubkSz, EC25519_LITTLE_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21513. prvkSz = CURVE25519_KEYSIZE;
  21514. pubkSz = CURVE25519_KEYSIZE;
  21515. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
  21516. NULL, publicKey, &pubkSz, EC25519_LITTLE_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21517. /* prvkSz = CURVE25519_KEYSIZE; */
  21518. pubkSz = CURVE25519_KEYSIZE;
  21519. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
  21520. &prvkSz, NULL, &pubkSz, EC25519_LITTLE_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21521. prvkSz = CURVE25519_KEYSIZE;
  21522. pubkSz = CURVE25519_KEYSIZE;
  21523. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
  21524. &prvkSz, publicKey, NULL, EC25519_LITTLE_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21525. prvkSz = CURVE25519_KEYSIZE;
  21526. /* pubkSz = CURVE25519_KEYSIZE; */
  21527. ExpectIntEQ(wc_curve25519_export_key_raw_ex(NULL, privateKey,
  21528. &prvkSz, publicKey, &pubkSz, EC25519_BIG_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21529. prvkSz = CURVE25519_KEYSIZE;
  21530. pubkSz = CURVE25519_KEYSIZE;
  21531. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, NULL,
  21532. &prvkSz, publicKey, &pubkSz, EC25519_BIG_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21533. prvkSz = CURVE25519_KEYSIZE;
  21534. pubkSz = CURVE25519_KEYSIZE;
  21535. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
  21536. NULL, publicKey, &pubkSz, EC25519_BIG_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21537. /* prvkSz = CURVE25519_KEYSIZE; */
  21538. pubkSz = CURVE25519_KEYSIZE;
  21539. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
  21540. &prvkSz, NULL, &pubkSz, EC25519_BIG_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21541. prvkSz = CURVE25519_KEYSIZE;
  21542. pubkSz = CURVE25519_KEYSIZE;
  21543. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey,
  21544. &prvkSz, publicKey, NULL, EC25519_BIG_ENDIAN), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21545. /* illegal value for endian */
  21546. prvkSz = CURVE25519_KEYSIZE;
  21547. /* pubkSz = CURVE25519_KEYSIZE; */
  21548. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey, &prvkSz,
  21549. publicKey, NULL, EC25519_BIG_ENDIAN + 10), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21550. /* cross-testing */
  21551. prksz = CURVE25519_KEYSIZE;
  21552. ExpectIntEQ(wc_curve25519_export_private_raw( &key, prik, &prksz), 0);
  21553. pbksz = CURVE25519_KEYSIZE;
  21554. ExpectIntEQ(wc_curve25519_export_public( &key, pubk, &pbksz), 0);
  21555. prvkSz = CURVE25519_KEYSIZE;
  21556. /* pubkSz = CURVE25519_KEYSIZE; */
  21557. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey, &prvkSz,
  21558. publicKey, &pubkSz, EC25519_BIG_ENDIAN), 0);
  21559. ExpectIntEQ(prksz, CURVE25519_KEYSIZE);
  21560. ExpectIntEQ(pbksz, CURVE25519_KEYSIZE);
  21561. ExpectIntEQ(prvkSz, CURVE25519_KEYSIZE);
  21562. ExpectIntEQ(pubkSz, CURVE25519_KEYSIZE);
  21563. ExpectIntEQ(XMEMCMP(privateKey, prik, CURVE25519_KEYSIZE), 0);
  21564. ExpectIntEQ(XMEMCMP(publicKey, pubk, CURVE25519_KEYSIZE), 0);
  21565. ExpectIntEQ(wc_curve25519_export_key_raw_ex(&key, privateKey, &prvkSz,
  21566. publicKey, &pubkSz, EC25519_LITTLE_ENDIAN), 0);
  21567. ExpectIntEQ(prvkSz, CURVE25519_KEYSIZE);
  21568. ExpectIntEQ(pubkSz, CURVE25519_KEYSIZE);
  21569. /* try once with another endian */
  21570. prvkSz = CURVE25519_KEYSIZE;
  21571. pubkSz = CURVE25519_KEYSIZE;
  21572. ExpectIntEQ(wc_curve25519_export_key_raw_ex( &key, privateKey, &prvkSz,
  21573. publicKey, &pubkSz, EC25519_BIG_ENDIAN), 0);
  21574. ExpectIntEQ(prvkSz, CURVE25519_KEYSIZE);
  21575. ExpectIntEQ(pubkSz, CURVE25519_KEYSIZE);
  21576. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21577. wc_curve25519_free(&key);
  21578. #endif
  21579. return EXPECT_RESULT();
  21580. } /* end of test_wc_curve25519_export_key_raw_ex */
  21581. /*
  21582. * Testing wc_curve25519_make_key
  21583. */
  21584. static int test_wc_curve25519_make_key(void)
  21585. {
  21586. EXPECT_DECLS;
  21587. #if defined(HAVE_CURVE25519)
  21588. curve25519_key key;
  21589. WC_RNG rng;
  21590. int keysize = 0;
  21591. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21592. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21593. ExpectIntEQ(wc_InitRng(&rng), 0);
  21594. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21595. ExpectIntEQ(keysize = wc_curve25519_size(&key), CURVE25519_KEYSIZE);
  21596. ExpectIntEQ(wc_curve25519_make_key(&rng, keysize, &key), 0);
  21597. /* test bad cases*/
  21598. ExpectIntEQ(wc_curve25519_make_key(NULL, 0, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21599. ExpectIntEQ(wc_curve25519_make_key(&rng, keysize, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21600. ExpectIntEQ(wc_curve25519_make_key(NULL, keysize, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21601. ExpectIntEQ(wc_curve25519_make_key(&rng, 0, &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21602. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21603. wc_curve25519_free(&key);
  21604. #endif
  21605. return EXPECT_RESULT();
  21606. } /* END test_wc_curve25519_make_key*/
  21607. /*
  21608. * Testing wc_curve25519_shared_secret_ex
  21609. */
  21610. static int test_wc_curve25519_shared_secret_ex(void)
  21611. {
  21612. EXPECT_DECLS;
  21613. #if defined(HAVE_CURVE25519)
  21614. curve25519_key private_key;
  21615. curve25519_key public_key;
  21616. WC_RNG rng;
  21617. byte out[CURVE25519_KEYSIZE];
  21618. word32 outLen = sizeof(out);
  21619. int endian = EC25519_BIG_ENDIAN;
  21620. ExpectIntEQ(wc_curve25519_init(&private_key), 0);
  21621. ExpectIntEQ(wc_curve25519_init(&public_key), 0);
  21622. ExpectIntEQ(wc_InitRng(&rng), 0);
  21623. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &private_key),
  21624. 0);
  21625. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &public_key),
  21626. 0);
  21627. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, out,
  21628. &outLen, endian), 0);
  21629. /* test bad cases*/
  21630. ExpectIntEQ(wc_curve25519_shared_secret_ex(NULL, NULL, NULL, 0, endian),
  21631. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21632. ExpectIntEQ(wc_curve25519_shared_secret_ex(NULL, &public_key, out, &outLen,
  21633. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21634. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, NULL, out, &outLen,
  21635. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21636. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, NULL,
  21637. &outLen, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21638. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, out,
  21639. NULL, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21640. /* curve25519.c is checking for public_key size less than or equal to 0x7f,
  21641. * increasing to 0x8f checks for error being returned*/
  21642. public_key.p.point[CURVE25519_KEYSIZE-1] = 0x8F;
  21643. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, out,
  21644. &outLen, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21645. outLen = outLen - 2;
  21646. ExpectIntEQ(wc_curve25519_shared_secret_ex(&private_key, &public_key, out,
  21647. &outLen, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21648. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21649. wc_curve25519_free(&private_key);
  21650. wc_curve25519_free(&public_key);
  21651. #endif
  21652. return EXPECT_RESULT();
  21653. } /* END test_wc_curve25519_shared_secret_ex*/
  21654. /*
  21655. * Testing wc_curve25519_make_pub
  21656. */
  21657. static int test_wc_curve25519_make_pub(void)
  21658. {
  21659. EXPECT_DECLS;
  21660. #ifdef HAVE_CURVE25519
  21661. curve25519_key key;
  21662. WC_RNG rng;
  21663. byte out[CURVE25519_KEYSIZE];
  21664. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21665. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21666. ExpectIntEQ(wc_InitRng(&rng), 0);
  21667. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21668. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof(out), out,
  21669. (int)sizeof(key.k), key.k), 0);
  21670. /* test bad cases*/
  21671. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof(key.k) - 1, key.k,
  21672. (int)sizeof out, out), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21673. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out, out, (int)sizeof(key.k),
  21674. NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21675. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out - 1, out,
  21676. (int)sizeof(key.k), key.k), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21677. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out, NULL,
  21678. (int)sizeof(key.k), key.k), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21679. /* verify clamping test */
  21680. key.k[0] |= ~248;
  21681. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out, out, (int)sizeof(key.k),
  21682. key.k), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21683. key.k[0] &= 248;
  21684. /* repeat the expected-to-succeed test. */
  21685. ExpectIntEQ(wc_curve25519_make_pub((int)sizeof out, out, (int)sizeof(key.k),
  21686. key.k), 0);
  21687. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21688. wc_curve25519_free(&key);
  21689. #endif
  21690. return EXPECT_RESULT();
  21691. } /* END test_wc_curve25519_make_pub */
  21692. /*
  21693. * Testing test_wc_curve25519_export_public_ex
  21694. */
  21695. static int test_wc_curve25519_export_public_ex(void)
  21696. {
  21697. EXPECT_DECLS;
  21698. #if defined(HAVE_CURVE25519)
  21699. curve25519_key key;
  21700. WC_RNG rng;
  21701. byte out[CURVE25519_KEYSIZE];
  21702. word32 outLen = sizeof(out);
  21703. int endian = EC25519_BIG_ENDIAN;
  21704. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21705. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21706. ExpectIntEQ(wc_InitRng(&rng), 0);
  21707. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21708. ExpectIntEQ(wc_curve25519_export_public(&key, out, &outLen), 0);
  21709. ExpectIntEQ(wc_curve25519_export_public_ex(&key, out, &outLen, endian), 0);
  21710. /* test bad cases*/
  21711. ExpectIntEQ(wc_curve25519_export_public_ex(NULL, NULL, NULL, endian),
  21712. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21713. ExpectIntEQ(wc_curve25519_export_public_ex(NULL, out, &outLen, endian),
  21714. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21715. ExpectIntEQ(wc_curve25519_export_public_ex(&key, NULL, &outLen, endian),
  21716. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21717. ExpectIntEQ(wc_curve25519_export_public_ex(&key, out, NULL, endian),
  21718. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21719. outLen = outLen - 2;
  21720. ExpectIntEQ(wc_curve25519_export_public_ex(&key, out, &outLen, endian),
  21721. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21722. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21723. wc_curve25519_free(&key);
  21724. #endif
  21725. return EXPECT_RESULT();
  21726. } /* END test_wc_curve25519_export_public_ex*/
  21727. /*
  21728. * Testing test_wc_curve25519_import_private_raw_ex
  21729. */
  21730. static int test_wc_curve25519_import_private_raw_ex(void)
  21731. {
  21732. EXPECT_DECLS;
  21733. #if defined(HAVE_CURVE25519)
  21734. curve25519_key key;
  21735. WC_RNG rng;
  21736. byte priv[CURVE25519_KEYSIZE];
  21737. byte pub[CURVE25519_KEYSIZE];
  21738. word32 privSz = sizeof(priv);
  21739. word32 pubSz = sizeof(pub);
  21740. int endian = EC25519_BIG_ENDIAN;
  21741. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21742. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21743. ExpectIntEQ(wc_InitRng(&rng), 0);
  21744. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21745. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, priv, &privSz,
  21746. endian), 0);
  21747. ExpectIntEQ(wc_curve25519_export_public(&key, pub, &pubSz), 0);
  21748. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, pub, pubSz,
  21749. &key, endian), 0);
  21750. /* test bad cases*/
  21751. ExpectIntEQ(wc_curve25519_import_private_raw_ex(NULL, 0, NULL, 0, NULL,
  21752. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21753. ExpectIntEQ(wc_curve25519_import_private_raw_ex(NULL, privSz, pub, pubSz,
  21754. &key, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21755. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, NULL, pubSz,
  21756. &key, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21757. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, pub, pubSz,
  21758. NULL, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21759. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, 0, pub, pubSz,
  21760. &key, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21761. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, pub, 0,
  21762. &key, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21763. ExpectIntEQ(wc_curve25519_import_private_raw_ex(priv, privSz, pub, pubSz,
  21764. &key, EC25519_LITTLE_ENDIAN), 0);
  21765. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21766. wc_curve25519_free(&key);
  21767. #endif
  21768. return EXPECT_RESULT();
  21769. } /* END test_wc_curve25519_import_private_raw_ex*/
  21770. /*
  21771. * Testing test_wc_curve25519_import_private
  21772. */
  21773. static int test_wc_curve25519_import_private(void)
  21774. {
  21775. EXPECT_DECLS;
  21776. #if defined(HAVE_CURVE25519)
  21777. curve25519_key key;
  21778. WC_RNG rng;
  21779. byte priv[CURVE25519_KEYSIZE];
  21780. word32 privSz = sizeof(priv);
  21781. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21782. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21783. ExpectIntEQ(wc_InitRng(&rng), 0);
  21784. ExpectIntEQ(wc_curve25519_make_key(&rng, CURVE25519_KEYSIZE, &key), 0);
  21785. ExpectIntEQ(wc_curve25519_export_private_raw(&key, priv, &privSz), 0);
  21786. ExpectIntEQ(wc_curve25519_import_private(priv, privSz, &key), 0);
  21787. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21788. wc_curve25519_free(&key);
  21789. #endif
  21790. return EXPECT_RESULT();
  21791. } /* END test_wc_curve25519_import*/
  21792. /*
  21793. * Testing test_wc_curve25519_export_private_raw_ex
  21794. */
  21795. static int test_wc_curve25519_export_private_raw_ex(void)
  21796. {
  21797. EXPECT_DECLS;
  21798. #if defined(HAVE_CURVE25519)
  21799. curve25519_key key;
  21800. byte out[CURVE25519_KEYSIZE];
  21801. word32 outLen = sizeof(out);
  21802. int endian = EC25519_BIG_ENDIAN;
  21803. ExpectIntEQ(wc_curve25519_init(&key), 0);
  21804. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, out, &outLen, endian),
  21805. 0);
  21806. /* test bad cases*/
  21807. ExpectIntEQ(wc_curve25519_export_private_raw_ex(NULL, NULL, NULL, endian),
  21808. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21809. ExpectIntEQ(wc_curve25519_export_private_raw_ex(NULL, out, &outLen, endian),
  21810. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21811. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, NULL, &outLen,
  21812. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21813. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, out, NULL, endian),
  21814. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21815. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, out, &outLen,
  21816. EC25519_LITTLE_ENDIAN), 0);
  21817. outLen = outLen - 2;
  21818. ExpectIntEQ(wc_curve25519_export_private_raw_ex(&key, out, &outLen, endian),
  21819. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  21820. wc_curve25519_free(&key);
  21821. #endif
  21822. return EXPECT_RESULT();
  21823. } /* END test_wc_curve25519_export_private_raw_ex*/
  21824. /*
  21825. * Testing wc_ed448_make_key().
  21826. */
  21827. static int test_wc_ed448_make_key(void)
  21828. {
  21829. EXPECT_DECLS;
  21830. #if defined(HAVE_ED448)
  21831. ed448_key key;
  21832. WC_RNG rng;
  21833. unsigned char pubkey[ED448_PUB_KEY_SIZE];
  21834. XMEMSET(&key, 0, sizeof(ed448_key));
  21835. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21836. ExpectIntEQ(wc_ed448_init(&key), 0);
  21837. ExpectIntEQ(wc_InitRng(&rng), 0);
  21838. ExpectIntEQ(wc_ed448_make_public(&key, pubkey, sizeof(pubkey)),
  21839. WC_NO_ERR_TRACE(ECC_PRIV_KEY_E));
  21840. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21841. /* Test bad args. */
  21842. ExpectIntEQ(wc_ed448_make_key(NULL, ED448_KEY_SIZE, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21843. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21844. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE - 1, &key),
  21845. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21846. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE + 1, &key),
  21847. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21848. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21849. wc_ed448_free(&key);
  21850. #endif
  21851. return EXPECT_RESULT();
  21852. } /* END test_wc_ed448_make_key */
  21853. /*
  21854. * Testing wc_ed448_init()
  21855. */
  21856. static int test_wc_ed448_init(void)
  21857. {
  21858. EXPECT_DECLS;
  21859. #if defined(HAVE_ED448)
  21860. ed448_key key;
  21861. XMEMSET(&key, 0, sizeof(ed448_key));
  21862. ExpectIntEQ(wc_ed448_init(&key), 0);
  21863. /* Test bad args. */
  21864. ExpectIntEQ(wc_ed448_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21865. wc_ed448_free(&key);
  21866. #endif
  21867. return EXPECT_RESULT();
  21868. } /* END test_wc_ed448_init */
  21869. /*
  21870. * Test wc_ed448_sign_msg() and wc_ed448_verify_msg()
  21871. */
  21872. static int test_wc_ed448_sign_msg(void)
  21873. {
  21874. EXPECT_DECLS;
  21875. #if defined(HAVE_ED448) && defined(HAVE_ED448_SIGN)
  21876. ed448_key key;
  21877. WC_RNG rng;
  21878. byte msg[] = "Everybody gets Friday off.\n";
  21879. byte sig[ED448_SIG_SIZE];
  21880. word32 msglen = sizeof(msg);
  21881. word32 siglen = sizeof(sig);
  21882. word32 badSigLen = sizeof(sig) - 1;
  21883. #ifdef HAVE_ED448_VERIFY
  21884. int verify_ok = 0; /*1 = Verify success.*/
  21885. #endif
  21886. /* Initialize stack variables. */
  21887. XMEMSET(&key, 0, sizeof(ed448_key));
  21888. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21889. XMEMSET(sig, 0, siglen);
  21890. /* Initialize key. */
  21891. ExpectIntEQ(wc_ed448_init(&key), 0);
  21892. ExpectIntEQ(wc_InitRng(&rng), 0);
  21893. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21894. ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, sig, &siglen, &key, NULL, 0), 0);
  21895. ExpectIntEQ(siglen, ED448_SIG_SIZE);
  21896. /* Test bad args. */
  21897. ExpectIntEQ(wc_ed448_sign_msg(NULL, msglen, sig, &siglen, &key, NULL, 0),
  21898. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21899. ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, NULL, &siglen, &key, NULL, 0),
  21900. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21901. ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, sig, NULL, &key, NULL, 0),
  21902. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21903. ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, sig, &siglen, NULL, NULL, 0),
  21904. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21905. ExpectIntEQ(wc_ed448_sign_msg(msg, msglen, sig, &badSigLen, &key, NULL, 0),
  21906. WC_NO_ERR_TRACE(BUFFER_E));
  21907. ExpectIntEQ(badSigLen, ED448_SIG_SIZE);
  21908. badSigLen -= 1;
  21909. #ifdef HAVE_ED448_VERIFY
  21910. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen, msg, msglen, &verify_ok, &key,
  21911. NULL, 0), 0);
  21912. ExpectIntEQ(verify_ok, 1);
  21913. /* Test bad args. */
  21914. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen - 1, msg, msglen, &verify_ok,
  21915. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21916. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen + 1, msg, msglen, &verify_ok,
  21917. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21918. ExpectIntEQ(wc_ed448_verify_msg(NULL, siglen, msg, msglen, &verify_ok,
  21919. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21920. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen, NULL, msglen, &verify_ok,
  21921. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21922. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen, msg, msglen, NULL,
  21923. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21924. ExpectIntEQ(wc_ed448_verify_msg(sig, siglen, msg, msglen, &verify_ok,
  21925. NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21926. ExpectIntEQ(wc_ed448_verify_msg(sig, badSigLen, msg, msglen, &verify_ok,
  21927. &key, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21928. #endif /* Verify. */
  21929. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21930. wc_ed448_free(&key);
  21931. #endif
  21932. return EXPECT_RESULT();
  21933. } /* END test_wc_ed448_sign_msg */
  21934. /*
  21935. * Testing wc_ed448_import_public()
  21936. */
  21937. static int test_wc_ed448_import_public(void)
  21938. {
  21939. EXPECT_DECLS;
  21940. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_IMPORT)
  21941. ed448_key pubKey;
  21942. WC_RNG rng;
  21943. const byte in[] =
  21944. "Ed448PublicKeyUnitTest.................................\n";
  21945. word32 inlen = sizeof(in);
  21946. XMEMSET(&pubKey, 0, sizeof(ed448_key));
  21947. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21948. ExpectIntEQ(wc_ed448_init(&pubKey), 0);
  21949. ExpectIntEQ(wc_InitRng(&rng), 0);
  21950. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &pubKey), 0);
  21951. ExpectIntEQ(wc_ed448_import_public_ex(in, inlen, &pubKey, 1), 0);
  21952. ExpectIntEQ(XMEMCMP(in, pubKey.p, inlen), 0);
  21953. /* Test bad args. */
  21954. ExpectIntEQ(wc_ed448_import_public(NULL, inlen, &pubKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21955. ExpectIntEQ(wc_ed448_import_public(in, inlen, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21956. ExpectIntEQ(wc_ed448_import_public(in, inlen - 1, &pubKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  21957. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  21958. wc_ed448_free(&pubKey);
  21959. #endif
  21960. return EXPECT_RESULT();
  21961. } /* END wc_ed448_import_public */
  21962. /*
  21963. * Testing wc_ed448_import_private_key()
  21964. */
  21965. static int test_wc_ed448_import_private_key(void)
  21966. {
  21967. EXPECT_DECLS;
  21968. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_IMPORT)
  21969. ed448_key key;
  21970. WC_RNG rng;
  21971. const byte privKey[] =
  21972. "Ed448PrivateKeyUnitTest................................\n";
  21973. const byte pubKey[] =
  21974. "Ed448PublicKeyUnitTest.................................\n";
  21975. word32 privKeySz = sizeof(privKey);
  21976. word32 pubKeySz = sizeof(pubKey);
  21977. #ifdef HAVE_ED448_KEY_EXPORT
  21978. byte bothKeys[sizeof(privKey) + sizeof(pubKey)];
  21979. word32 bothKeysSz = sizeof(bothKeys);
  21980. #endif
  21981. XMEMSET(&key, 0, sizeof(ed448_key));
  21982. XMEMSET(&rng, 0, sizeof(WC_RNG));
  21983. ExpectIntEQ(wc_ed448_init(&key), 0);
  21984. ExpectIntEQ(wc_InitRng(&rng), 0);
  21985. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  21986. ExpectIntEQ(wc_ed448_import_private_key_ex(privKey, privKeySz, pubKey,
  21987. pubKeySz, &key, 1), 0);
  21988. ExpectIntEQ(XMEMCMP(pubKey, key.p, privKeySz), 0);
  21989. ExpectIntEQ(XMEMCMP(privKey, key.k, pubKeySz), 0);
  21990. #ifdef HAVE_ED448_KEY_EXPORT
  21991. PRIVATE_KEY_UNLOCK();
  21992. ExpectIntEQ(wc_ed448_export_private(&key, bothKeys, &bothKeysSz), 0);
  21993. PRIVATE_KEY_LOCK();
  21994. ExpectIntEQ(wc_ed448_import_private_key_ex(bothKeys, bothKeysSz, NULL, 0,
  21995. &key, 1), 0);
  21996. ExpectIntEQ(XMEMCMP(pubKey, key.p, privKeySz), 0);
  21997. ExpectIntEQ(XMEMCMP(privKey, key.k, pubKeySz), 0);
  21998. #endif
  21999. /* Test bad args. */
  22000. ExpectIntEQ(wc_ed448_import_private_key(NULL, privKeySz, pubKey, pubKeySz,
  22001. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22002. ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz, NULL, pubKeySz,
  22003. &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22004. ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz, pubKey,
  22005. pubKeySz, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22006. ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz - 1, pubKey,
  22007. pubKeySz, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22008. ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz, pubKey,
  22009. pubKeySz - 1, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22010. ExpectIntEQ(wc_ed448_import_private_key(privKey, privKeySz, NULL, 0, &key),
  22011. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22012. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22013. wc_ed448_free(&key);
  22014. #endif
  22015. return EXPECT_RESULT();
  22016. } /* END test_wc_ed448_import_private_key */
  22017. /*
  22018. * Testing wc_ed448_export_public() and wc_ed448_export_private_only()
  22019. */
  22020. static int test_wc_ed448_export(void)
  22021. {
  22022. EXPECT_DECLS;
  22023. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  22024. ed448_key key;
  22025. WC_RNG rng;
  22026. byte priv[ED448_PRV_KEY_SIZE];
  22027. byte pub[ED448_PUB_KEY_SIZE];
  22028. word32 privSz = sizeof(priv);
  22029. word32 pubSz = sizeof(pub);
  22030. XMEMSET(&key, 0, sizeof(ed448_key));
  22031. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22032. ExpectIntEQ(wc_ed448_init(&key), 0);
  22033. ExpectIntEQ(wc_InitRng(&rng), 0);
  22034. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  22035. ExpectIntEQ(wc_ed448_export_public(&key, pub, &pubSz), 0);
  22036. ExpectIntEQ(pubSz, ED448_KEY_SIZE);
  22037. ExpectIntEQ(XMEMCMP(key.p, pub, pubSz), 0);
  22038. /* Test bad args. */
  22039. ExpectIntEQ(wc_ed448_export_public(NULL, pub, &pubSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22040. ExpectIntEQ(wc_ed448_export_public(&key, NULL, &pubSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22041. ExpectIntEQ(wc_ed448_export_public(&key, pub, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22042. PRIVATE_KEY_UNLOCK();
  22043. ExpectIntEQ(wc_ed448_export_private_only(&key, priv, &privSz), 0);
  22044. ExpectIntEQ(privSz, ED448_KEY_SIZE);
  22045. ExpectIntEQ(XMEMCMP(key.k, priv, privSz), 0);
  22046. /* Test bad args. */
  22047. ExpectIntEQ(wc_ed448_export_private_only(NULL, priv, &privSz),
  22048. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22049. ExpectIntEQ(wc_ed448_export_private_only(&key, NULL, &privSz),
  22050. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22051. ExpectIntEQ(wc_ed448_export_private_only(&key, priv, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22052. PRIVATE_KEY_LOCK();
  22053. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22054. wc_ed448_free(&key);
  22055. #endif
  22056. return EXPECT_RESULT();
  22057. } /* END test_wc_ed448_export */
  22058. /*
  22059. * Testing wc_ed448_size()
  22060. */
  22061. static int test_wc_ed448_size(void)
  22062. {
  22063. EXPECT_DECLS;
  22064. #if defined(HAVE_ED448)
  22065. ed448_key key;
  22066. WC_RNG rng;
  22067. XMEMSET(&key, 0, sizeof(ed448_key));
  22068. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22069. ExpectIntEQ(wc_ed448_init(&key), 0);
  22070. ExpectIntEQ(wc_InitRng(&rng), 0);
  22071. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  22072. ExpectIntEQ(wc_ed448_size(&key), ED448_KEY_SIZE);
  22073. /* Test bad args. */
  22074. ExpectIntEQ(wc_ed448_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22075. ExpectIntEQ(wc_ed448_sig_size(&key), ED448_SIG_SIZE);
  22076. /* Test bad args. */
  22077. ExpectIntEQ(wc_ed448_sig_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22078. ExpectIntEQ(wc_ed448_pub_size(&key), ED448_PUB_KEY_SIZE);
  22079. /* Test bad args. */
  22080. ExpectIntEQ(wc_ed448_pub_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22081. ExpectIntEQ(wc_ed448_priv_size(&key), ED448_PRV_KEY_SIZE);
  22082. /* Test bad args. */
  22083. ExpectIntEQ(wc_ed448_priv_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22084. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22085. wc_ed448_free(&key);
  22086. #endif
  22087. return EXPECT_RESULT();
  22088. } /* END test_wc_ed448_size */
  22089. /*
  22090. * Testing wc_ed448_export_private() and wc_ed448_export_key()
  22091. */
  22092. static int test_wc_ed448_exportKey(void)
  22093. {
  22094. EXPECT_DECLS;
  22095. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  22096. ed448_key key;
  22097. WC_RNG rng;
  22098. byte priv[ED448_PRV_KEY_SIZE];
  22099. byte pub[ED448_PUB_KEY_SIZE];
  22100. byte privOnly[ED448_PRV_KEY_SIZE];
  22101. word32 privSz = sizeof(priv);
  22102. word32 pubSz = sizeof(pub);
  22103. word32 privOnlySz = sizeof(privOnly);
  22104. XMEMSET(&key, 0, sizeof(ed448_key));
  22105. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22106. ExpectIntEQ(wc_ed448_init(&key), 0);
  22107. ExpectIntEQ(wc_InitRng(&rng), 0);
  22108. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  22109. PRIVATE_KEY_UNLOCK();
  22110. ExpectIntEQ(wc_ed448_export_private(&key, privOnly, &privOnlySz), 0);
  22111. /* Test bad args. */
  22112. ExpectIntEQ(wc_ed448_export_private(NULL, privOnly, &privOnlySz),
  22113. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22114. ExpectIntEQ(wc_ed448_export_private(&key, NULL, &privOnlySz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22115. ExpectIntEQ(wc_ed448_export_private(&key, privOnly, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22116. ExpectIntEQ(wc_ed448_export_key(&key, priv, &privSz, pub, &pubSz), 0);
  22117. /* Test bad args. */
  22118. ExpectIntEQ(wc_ed448_export_key(NULL, priv, &privSz, pub, &pubSz),
  22119. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22120. ExpectIntEQ(wc_ed448_export_key(&key, NULL, &privSz, pub, &pubSz),
  22121. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22122. ExpectIntEQ(wc_ed448_export_key(&key, priv, NULL, pub, &pubSz),
  22123. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22124. ExpectIntEQ(wc_ed448_export_key(&key, priv, &privSz, NULL, &pubSz),
  22125. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22126. ExpectIntEQ(wc_ed448_export_key(&key, priv, &privSz, pub, NULL),
  22127. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22128. PRIVATE_KEY_LOCK();
  22129. /* Cross check output. */
  22130. ExpectIntEQ(XMEMCMP(priv, privOnly, privSz), 0);
  22131. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22132. wc_ed448_free(&key);
  22133. #endif
  22134. return EXPECT_RESULT();
  22135. } /* END test_wc_ed448_exportKey */
  22136. /*
  22137. * Testing wc_Ed448PublicKeyToDer
  22138. */
  22139. static int test_wc_Ed448PublicKeyToDer(void)
  22140. {
  22141. EXPECT_DECLS;
  22142. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT) && \
  22143. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  22144. ed448_key key;
  22145. byte derBuf[1024];
  22146. XMEMSET(&key, 0, sizeof(ed448_key));
  22147. /* Test bad args */
  22148. ExpectIntEQ(wc_Ed448PublicKeyToDer(NULL, NULL, 0, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22149. ExpectIntEQ(wc_ed448_init(&key), 0);
  22150. ExpectIntEQ(wc_Ed448PublicKeyToDer(&key, derBuf, 0, 0), WC_NO_ERR_TRACE(BUFFER_E));
  22151. wc_ed448_free(&key);
  22152. /* Test good args */
  22153. if (EXPECT_SUCCESS()) {
  22154. WC_RNG rng;
  22155. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22156. ExpectIntEQ(wc_ed448_init(&key), 0);
  22157. ExpectIntEQ(wc_InitRng(&rng), 0);
  22158. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &key), 0);
  22159. /* length only */
  22160. ExpectIntGT(wc_Ed448PublicKeyToDer(&key, NULL, 0, 0), 0);
  22161. ExpectIntGT(wc_Ed448PublicKeyToDer(&key, NULL, 0, 1), 0);
  22162. ExpectIntGT(wc_Ed448PublicKeyToDer(&key, derBuf,
  22163. (word32)sizeof(derBuf), 1), 0);
  22164. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22165. wc_ed448_free(&key);
  22166. }
  22167. #endif
  22168. return EXPECT_RESULT();
  22169. } /* END testing wc_Ed448PublicKeyToDer */
  22170. /*
  22171. * Testing wc_curve448_init and wc_curve448_free.
  22172. */
  22173. static int test_wc_curve448_init(void)
  22174. {
  22175. EXPECT_DECLS;
  22176. #if defined(HAVE_CURVE448)
  22177. curve448_key key;
  22178. /* Test bad args for wc_curve448_init */
  22179. ExpectIntEQ(wc_curve448_init(&key), 0);
  22180. /* Test bad args for wc_curve448_init */
  22181. ExpectIntEQ(wc_curve448_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22182. /* Test good args for wc_curve_448_free */
  22183. wc_curve448_free(&key);
  22184. /* Test bad args for wc_curve448_free */
  22185. wc_curve448_free(NULL);
  22186. #endif
  22187. return EXPECT_RESULT();
  22188. } /* END test_wc_curve448_init and wc_curve_448_free*/
  22189. /*
  22190. * Testing wc_curve448_make_key
  22191. */
  22192. static int test_wc_curve448_make_key(void)
  22193. {
  22194. EXPECT_DECLS;
  22195. #if defined(HAVE_CURVE448)
  22196. curve448_key key;
  22197. WC_RNG rng;
  22198. int keysize = 0;
  22199. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22200. ExpectIntEQ(wc_curve448_init(&key), 0);
  22201. ExpectIntEQ(wc_InitRng(&rng), 0);
  22202. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
  22203. ExpectIntEQ(keysize = wc_curve448_size(&key), CURVE448_KEY_SIZE);
  22204. ExpectIntEQ(wc_curve448_make_key(&rng, keysize, &key), 0);
  22205. /* test bad cases */
  22206. ExpectIntEQ(wc_curve448_make_key(NULL, 0, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22207. ExpectIntEQ(wc_curve448_make_key(&rng, keysize, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22208. ExpectIntEQ(wc_curve448_make_key(NULL, keysize, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22209. ExpectIntEQ(wc_curve448_make_key(&rng, 0, &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22210. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22211. wc_curve448_free(&key);
  22212. #endif
  22213. return EXPECT_RESULT();
  22214. } /* END test_wc_curve448_make_key*/
  22215. /*
  22216. * Testing test_wc_curve448_shared_secret_ex
  22217. */
  22218. static int test_wc_curve448_shared_secret_ex(void)
  22219. {
  22220. EXPECT_DECLS;
  22221. #if defined(HAVE_CURVE448)
  22222. curve448_key private_key;
  22223. curve448_key public_key;
  22224. WC_RNG rng;
  22225. byte out[CURVE448_KEY_SIZE];
  22226. word32 outLen = sizeof(out);
  22227. int endian = EC448_BIG_ENDIAN;
  22228. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22229. ExpectIntEQ(wc_curve448_init(&private_key), 0);
  22230. ExpectIntEQ(wc_InitRng(&rng), 0);
  22231. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &private_key), 0);
  22232. ExpectIntEQ(wc_curve448_init(&public_key), 0);
  22233. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &public_key), 0);
  22234. ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, &public_key, out,
  22235. &outLen, endian), 0);
  22236. /* test bad cases */
  22237. ExpectIntEQ(wc_curve448_shared_secret_ex(NULL, NULL, NULL, 0, endian),
  22238. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22239. ExpectIntEQ(wc_curve448_shared_secret_ex(NULL, &public_key, out, &outLen,
  22240. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22241. ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, NULL, out, &outLen,
  22242. endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22243. ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, &public_key, NULL,
  22244. &outLen, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22245. ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, &public_key, out,
  22246. NULL, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22247. outLen = outLen - 2;
  22248. ExpectIntEQ(wc_curve448_shared_secret_ex(&private_key, &public_key, out,
  22249. &outLen, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22250. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22251. wc_curve448_free(&private_key);
  22252. wc_curve448_free(&public_key);
  22253. #endif
  22254. return EXPECT_RESULT();
  22255. } /* END test_wc_curve448_shared_secret_ex*/
  22256. /*
  22257. * Testing test_wc_curve448_export_public_ex
  22258. */
  22259. static int test_wc_curve448_export_public_ex(void)
  22260. {
  22261. EXPECT_DECLS;
  22262. #if defined(HAVE_CURVE448)
  22263. WC_RNG rng;
  22264. curve448_key key;
  22265. byte out[CURVE448_KEY_SIZE];
  22266. word32 outLen = sizeof(out);
  22267. int endian = EC448_BIG_ENDIAN;
  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_public(&key, out, &outLen), 0);
  22273. ExpectIntEQ(wc_curve448_export_public_ex(&key, out, &outLen, endian), 0);
  22274. /* test bad cases*/
  22275. ExpectIntEQ(wc_curve448_export_public_ex(NULL, NULL, NULL, endian),
  22276. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22277. ExpectIntEQ(wc_curve448_export_public_ex(NULL, out, &outLen, endian),
  22278. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22279. ExpectIntEQ(wc_curve448_export_public_ex(&key, NULL, &outLen, endian),
  22280. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22281. ExpectIntEQ(wc_curve448_export_public_ex(&key, out, NULL, endian),
  22282. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22283. outLen = outLen - 2;
  22284. ExpectIntEQ(wc_curve448_export_public_ex(&key, out, &outLen, endian),
  22285. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22286. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22287. wc_curve448_free(&key);
  22288. #endif
  22289. return EXPECT_RESULT();
  22290. } /* END test_wc_curve448_export_public_ex*/
  22291. /*
  22292. * Testing test_wc_curve448_export_private_raw_ex
  22293. */
  22294. static int test_wc_curve448_export_private_raw_ex(void)
  22295. {
  22296. EXPECT_DECLS;
  22297. #if defined(HAVE_CURVE448)
  22298. curve448_key key;
  22299. byte out[CURVE448_KEY_SIZE];
  22300. word32 outLen = sizeof(out);
  22301. int endian = EC448_BIG_ENDIAN;
  22302. ExpectIntEQ(wc_curve448_init(&key), 0);
  22303. ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, out, &outLen, endian),
  22304. 0);
  22305. /* test bad cases*/
  22306. ExpectIntEQ(wc_curve448_export_private_raw_ex(NULL, NULL, NULL, endian),
  22307. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22308. ExpectIntEQ(wc_curve448_export_private_raw_ex(NULL, out, &outLen, endian),
  22309. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22310. ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, NULL, &outLen, endian),
  22311. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22312. ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, out, NULL, endian),
  22313. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22314. ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, out, &outLen,
  22315. EC448_LITTLE_ENDIAN), 0);
  22316. outLen = outLen - 2;
  22317. ExpectIntEQ(wc_curve448_export_private_raw_ex(&key, out, &outLen, endian),
  22318. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22319. wc_curve448_free(&key);
  22320. #endif
  22321. return EXPECT_RESULT();
  22322. } /* END test_wc_curve448_export_private_raw_ex*/
  22323. /*
  22324. * Testing test_wc_curve448_import_private_raw_ex
  22325. */
  22326. static int test_wc_curve448_import_private_raw_ex(void)
  22327. {
  22328. EXPECT_DECLS;
  22329. #if defined(HAVE_CURVE448)
  22330. curve448_key key;
  22331. WC_RNG rng;
  22332. byte priv[CURVE448_KEY_SIZE];
  22333. byte pub[CURVE448_KEY_SIZE];
  22334. word32 privSz = sizeof(priv);
  22335. word32 pubSz = sizeof(pub);
  22336. int endian = EC448_BIG_ENDIAN;
  22337. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22338. ExpectIntEQ(wc_curve448_init(&key), 0);
  22339. ExpectIntEQ(wc_InitRng(&rng), 0);
  22340. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
  22341. ExpectIntEQ(wc_curve448_export_private_raw(&key, priv, &privSz), 0);
  22342. ExpectIntEQ(wc_curve448_export_public(&key, pub, &pubSz), 0);
  22343. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, pub, pubSz,
  22344. &key, endian), 0);
  22345. /* test bad cases */
  22346. ExpectIntEQ(wc_curve448_import_private_raw_ex(NULL, 0, NULL, 0, NULL, 0),
  22347. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22348. ExpectIntEQ(wc_curve448_import_private_raw_ex(NULL, privSz, pub, pubSz,
  22349. &key, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22350. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, NULL, pubSz,
  22351. &key, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22352. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, pub, pubSz,
  22353. NULL, endian), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22354. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, 0, pub, pubSz,
  22355. &key, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22356. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, pub, 0,
  22357. &key, endian), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22358. ExpectIntEQ(wc_curve448_import_private_raw_ex(priv, privSz, pub, pubSz,
  22359. &key, EC448_LITTLE_ENDIAN), 0);
  22360. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22361. wc_curve448_free(&key);
  22362. #endif
  22363. return EXPECT_RESULT();
  22364. } /* END test_wc_curve448_import_private_raw_ex*/
  22365. /*
  22366. * Testing test_curve448_export_key_raw
  22367. */
  22368. static int test_wc_curve448_export_key_raw(void)
  22369. {
  22370. EXPECT_DECLS;
  22371. #if defined(HAVE_CURVE448)
  22372. curve448_key key;
  22373. WC_RNG rng;
  22374. byte priv[CURVE448_KEY_SIZE];
  22375. byte pub[CURVE448_KEY_SIZE];
  22376. word32 privSz = sizeof(priv);
  22377. word32 pubSz = sizeof(pub);
  22378. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22379. ExpectIntEQ(wc_curve448_init(&key), 0);
  22380. ExpectIntEQ(wc_InitRng(&rng), 0);
  22381. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
  22382. ExpectIntEQ(wc_curve448_export_private_raw(&key, priv, &privSz), 0);
  22383. ExpectIntEQ(wc_curve448_export_public(&key, pub, &pubSz), 0);
  22384. ExpectIntEQ(wc_curve448_export_key_raw(&key, priv, &privSz, pub, &pubSz),
  22385. 0);
  22386. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22387. wc_curve448_free(&key);
  22388. #endif
  22389. return EXPECT_RESULT();
  22390. } /* END test_wc_curve448_import_private_raw_ex*/
  22391. /*
  22392. * Testing test_wc_curve448_import_private
  22393. */
  22394. static int test_wc_curve448_import_private(void)
  22395. {
  22396. EXPECT_DECLS;
  22397. #if defined(HAVE_CURVE448)
  22398. curve448_key key;
  22399. WC_RNG rng;
  22400. byte priv[CURVE448_KEY_SIZE];
  22401. word32 privSz = sizeof(priv);
  22402. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22403. ExpectIntEQ(wc_curve448_init(&key), 0);
  22404. ExpectIntEQ(wc_InitRng(&rng), 0);
  22405. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &key), 0);
  22406. ExpectIntEQ(wc_curve448_export_private_raw(&key, priv, &privSz), 0);
  22407. ExpectIntEQ(wc_curve448_import_private(priv, privSz, &key), 0);
  22408. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22409. wc_curve448_free(&key);
  22410. #endif
  22411. return EXPECT_RESULT();
  22412. } /* END test_wc_curve448_import*/
  22413. /*
  22414. * Testing test_wc_curve448_size.
  22415. */
  22416. static int test_wc_curve448_size(void)
  22417. {
  22418. EXPECT_DECLS;
  22419. #if defined(HAVE_CURVE448)
  22420. curve448_key key;
  22421. ExpectIntEQ(wc_curve448_init(&key), 0);
  22422. /* Test good args for wc_curve448_size */
  22423. ExpectIntEQ(wc_curve448_size(&key), CURVE448_KEY_SIZE);
  22424. /* Test bad args for wc_curve448_size */
  22425. ExpectIntEQ(wc_curve448_size(NULL), 0);
  22426. wc_curve448_free(&key);
  22427. #endif
  22428. return EXPECT_RESULT();
  22429. } /* END test_wc_curve448_size*/
  22430. /*
  22431. * Testing wc_ecc_make_key.
  22432. */
  22433. static int test_wc_ecc_make_key(void)
  22434. {
  22435. EXPECT_DECLS;
  22436. #if defined(HAVE_ECC) && !defined(WC_NO_RNG)
  22437. ecc_key key;
  22438. WC_RNG rng;
  22439. int ret;
  22440. XMEMSET(&key, 0, sizeof(ecc_key));
  22441. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22442. ExpectIntEQ(wc_ecc_init(&key), 0);
  22443. ExpectIntEQ(wc_InitRng(&rng), 0);
  22444. ret = wc_ecc_make_key(&rng, KEY14, &key);
  22445. #if defined(WOLFSSL_ASYNC_CRYPT)
  22446. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22447. #endif
  22448. ExpectIntEQ(ret, 0);
  22449. /* Pass in bad args. */
  22450. ExpectIntEQ(wc_ecc_make_key(NULL, KEY14, &key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22451. ExpectIntEQ(wc_ecc_make_key(&rng, KEY14, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22452. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22453. wc_ecc_free(&key);
  22454. #ifdef FP_ECC
  22455. wc_ecc_fp_free();
  22456. #endif
  22457. #endif
  22458. return EXPECT_RESULT();
  22459. } /* END test_wc_ecc_make_key */
  22460. /*
  22461. * Testing wc_ecc_init()
  22462. */
  22463. static int test_wc_ecc_init(void)
  22464. {
  22465. EXPECT_DECLS;
  22466. #ifdef HAVE_ECC
  22467. ecc_key key;
  22468. XMEMSET(&key, 0, sizeof(ecc_key));
  22469. ExpectIntEQ(wc_ecc_init(&key), 0);
  22470. /* Pass in bad args. */
  22471. ExpectIntEQ(wc_ecc_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22472. wc_ecc_free(&key);
  22473. #endif
  22474. return EXPECT_RESULT();
  22475. } /* END test_wc_ecc_init */
  22476. /*
  22477. * Testing wc_ecc_check_key()
  22478. */
  22479. static int test_wc_ecc_check_key(void)
  22480. {
  22481. EXPECT_DECLS;
  22482. #if defined(HAVE_ECC) && !defined(WC_NO_RNG)
  22483. ecc_key key;
  22484. WC_RNG rng;
  22485. int ret;
  22486. XMEMSET(&rng, 0, sizeof(rng));
  22487. XMEMSET(&key, 0, sizeof(key));
  22488. ExpectIntEQ(wc_ecc_init(&key), 0);
  22489. ExpectIntEQ(wc_InitRng(&rng), 0);
  22490. ret = wc_ecc_make_key(&rng, KEY14, &key);
  22491. #if defined(WOLFSSL_ASYNC_CRYPT)
  22492. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22493. #endif
  22494. ExpectIntEQ(ret, 0);
  22495. ExpectIntEQ(wc_ecc_check_key(&key), 0);
  22496. /* Pass in bad args. */
  22497. ExpectIntEQ(wc_ecc_check_key(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22498. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22499. wc_ecc_free(&key);
  22500. #ifdef FP_ECC
  22501. wc_ecc_fp_free();
  22502. #endif
  22503. #endif
  22504. return EXPECT_RESULT();
  22505. } /* END test_wc_ecc_check_key */
  22506. /*
  22507. * Testing wc_ecc_get_generator()
  22508. */
  22509. static int test_wc_ecc_get_generator(void)
  22510. {
  22511. EXPECT_DECLS;
  22512. #if defined(HAVE_ECC) && !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST) && \
  22513. !defined(HAVE_FIPS) && defined(OPENSSL_EXTRA)
  22514. ecc_point* pt = NULL;
  22515. ExpectNotNull(pt = wc_ecc_new_point());
  22516. ExpectIntEQ(wc_ecc_get_generator(pt, wc_ecc_get_curve_idx(ECC_SECP256R1)),
  22517. MP_OKAY);
  22518. /* Test bad args. */
  22519. /* Returns Zero for bad arg. */
  22520. ExpectIntNE(wc_ecc_get_generator(pt, -1), MP_OKAY);
  22521. ExpectIntNE(wc_ecc_get_generator(NULL, wc_ecc_get_curve_idx(ECC_SECP256R1)),
  22522. MP_OKAY);
  22523. /* If we ever get to 1000 curves increase this number */
  22524. ExpectIntNE(wc_ecc_get_generator(pt, 1000), MP_OKAY);
  22525. ExpectIntNE(wc_ecc_get_generator(NULL, -1), MP_OKAY);
  22526. wc_ecc_del_point(pt);
  22527. #endif
  22528. return EXPECT_RESULT();
  22529. } /* END test_wc_ecc_get_generator */
  22530. /*
  22531. * Testing wc_ecc_size()
  22532. */
  22533. static int test_wc_ecc_size(void)
  22534. {
  22535. EXPECT_DECLS;
  22536. #if defined(HAVE_ECC) && !defined(WC_NO_RNG)
  22537. WC_RNG rng;
  22538. ecc_key key;
  22539. int ret;
  22540. XMEMSET(&key, 0, sizeof(ecc_key));
  22541. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22542. ExpectIntEQ(wc_ecc_init(&key), 0);
  22543. ExpectIntEQ(wc_InitRng(&rng), 0);
  22544. ret = wc_ecc_make_key(&rng, KEY14, &key);
  22545. #if defined(WOLFSSL_ASYNC_CRYPT)
  22546. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22547. #endif
  22548. ExpectIntEQ(ret, 0);
  22549. ExpectIntEQ(wc_ecc_size(&key), KEY14);
  22550. /* Test bad args. */
  22551. /* Returns Zero for bad arg. */
  22552. ExpectIntEQ(wc_ecc_size(NULL), 0);
  22553. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22554. wc_ecc_free(&key);
  22555. #endif
  22556. return EXPECT_RESULT();
  22557. } /* END test_wc_ecc_size */
  22558. static int test_wc_ecc_params(void)
  22559. {
  22560. EXPECT_DECLS;
  22561. /* FIPS/CAVP self-test modules do not have `wc_ecc_get_curve_params`.
  22562. It was added after certifications */
  22563. #if defined(HAVE_ECC) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  22564. const ecc_set_type* ecc_set = NULL;
  22565. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  22566. /* Test for SECP256R1 curve */
  22567. int curve_id = ECC_SECP256R1;
  22568. int curve_idx;
  22569. ExpectIntNE(curve_idx = wc_ecc_get_curve_idx(curve_id), ECC_CURVE_INVALID);
  22570. ExpectNotNull(ecc_set = wc_ecc_get_curve_params(curve_idx));
  22571. ExpectIntEQ(ecc_set->id, curve_id);
  22572. #endif
  22573. /* Test case when SECP256R1 is not enabled */
  22574. /* Test that we get curve params for index 0 */
  22575. ExpectNotNull(ecc_set = wc_ecc_get_curve_params(0));
  22576. #endif /* HAVE_ECC && !HAVE_FIPS && !HAVE_SELFTEST */
  22577. return EXPECT_RESULT();
  22578. }
  22579. /*
  22580. * Testing wc_ecc_sign_hash() and wc_ecc_verify_hash()
  22581. */
  22582. static int test_wc_ecc_signVerify_hash(void)
  22583. {
  22584. EXPECT_DECLS;
  22585. #if defined(HAVE_ECC) && defined(HAVE_ECC_SIGN) && !defined(NO_ASN) && !defined(WC_NO_RNG)
  22586. ecc_key key;
  22587. WC_RNG rng;
  22588. int ret;
  22589. #ifdef HAVE_ECC_VERIFY
  22590. int verify = 0;
  22591. #endif
  22592. word32 siglen = ECC_BUFSIZE;
  22593. byte sig[ECC_BUFSIZE];
  22594. byte adjustedSig[ECC_BUFSIZE+1];
  22595. byte digest[] = TEST_STRING;
  22596. word32 digestlen = (word32)TEST_STRING_SZ;
  22597. /* Init stack var */
  22598. XMEMSET(&key, 0, sizeof(ecc_key));
  22599. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22600. XMEMSET(sig, 0, siglen);
  22601. XMEMSET(adjustedSig, 0, ECC_BUFSIZE+1);
  22602. /* Init structs. */
  22603. ExpectIntEQ(wc_ecc_init(&key), 0);
  22604. ExpectIntEQ(wc_InitRng(&rng), 0);
  22605. ret = wc_ecc_make_key(&rng, KEY14, &key);
  22606. #if defined(WOLFSSL_ASYNC_CRYPT)
  22607. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22608. #endif
  22609. ExpectIntEQ(ret, 0);
  22610. ExpectIntEQ(wc_ecc_sign_hash(digest, digestlen, sig, &siglen, &rng, &key),
  22611. 0);
  22612. /* Check bad args. */
  22613. ExpectIntEQ(wc_ecc_sign_hash(NULL, digestlen, sig, &siglen, &rng, &key),
  22614. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22615. ExpectIntEQ(wc_ecc_sign_hash(digest, digestlen, NULL, &siglen, &rng, &key),
  22616. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22617. ExpectIntEQ(wc_ecc_sign_hash(digest, digestlen, sig, NULL, &rng, &key),
  22618. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22619. ExpectIntEQ(wc_ecc_sign_hash(digest, digestlen, sig, &siglen, NULL, &key),
  22620. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22621. ExpectIntEQ(wc_ecc_sign_hash(digest, digestlen, sig, &siglen, &rng, NULL),
  22622. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22623. #ifdef HAVE_ECC_VERIFY
  22624. ExpectIntEQ(wc_ecc_verify_hash(sig, siglen, digest, digestlen, &verify,
  22625. &key), 0);
  22626. ExpectIntEQ(verify, 1);
  22627. /* test check on length of signature passed in */
  22628. XMEMCPY(adjustedSig, sig, siglen);
  22629. adjustedSig[1] = adjustedSig[1] + 1; /* add 1 to length for extra byte*/
  22630. #ifndef NO_STRICT_ECDSA_LEN
  22631. ExpectIntNE(wc_ecc_verify_hash(adjustedSig, siglen+1, digest, digestlen,
  22632. &verify, &key), 0);
  22633. #else
  22634. /* if NO_STRICT_ECDSA_LEN is set then extra bytes after the signature
  22635. * is allowed */
  22636. ExpectIntEQ(wc_ecc_verify_hash(adjustedSig, siglen+1, digest, digestlen,
  22637. &verify, &key), 0);
  22638. #endif
  22639. /* Test bad args. */
  22640. ExpectIntEQ(wc_ecc_verify_hash(NULL, siglen, digest, digestlen, &verify,
  22641. &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22642. ExpectIntEQ(wc_ecc_verify_hash(sig, siglen, NULL, digestlen, &verify, &key),
  22643. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22644. ExpectIntEQ(wc_ecc_verify_hash(sig, siglen, digest, digestlen, NULL, &key),
  22645. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22646. ExpectIntEQ(wc_ecc_verify_hash(sig, siglen, digest, digestlen, &verify,
  22647. NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22648. #endif /* HAVE_ECC_VERIFY */
  22649. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22650. wc_ecc_free(&key);
  22651. #ifdef FP_ECC
  22652. wc_ecc_fp_free();
  22653. #endif
  22654. #endif
  22655. return EXPECT_RESULT();
  22656. } /* END test_wc_ecc_sign_hash */
  22657. /*
  22658. * Testing wc_ecc_shared_secret()
  22659. */
  22660. static int test_wc_ecc_shared_secret(void)
  22661. {
  22662. EXPECT_DECLS;
  22663. #if defined(HAVE_ECC) && defined(HAVE_ECC_DHE) && !defined(WC_NO_RNG)
  22664. ecc_key key;
  22665. ecc_key pubKey;
  22666. WC_RNG rng;
  22667. #if defined(NO_ECC256)
  22668. int ret;
  22669. #endif
  22670. byte out[KEY32];
  22671. int keySz = sizeof(out);
  22672. word32 outlen = (word32)sizeof(out);
  22673. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  22674. const char* qx =
  22675. "bb33ac4c27504ac64aa504c33cde9f36db722dce94ea2bfacb2009392c16e861";
  22676. const char* qy =
  22677. "02e9af4dd302939a315b9792217ff0cf18da9111023486e82058330b803489d8";
  22678. const char* d =
  22679. "45b66902739c6c85a1385b72e8e8c7acc4038d533504fa6c28dc348de1a8098c";
  22680. const char* curveName = "SECP256R1";
  22681. const byte expected_shared_secret[] =
  22682. {
  22683. 0x65, 0xc0, 0xd4, 0x61, 0x17, 0xe6, 0x09, 0x75,
  22684. 0xf0, 0x12, 0xa0, 0x4d, 0x0b, 0x41, 0x30, 0x7a,
  22685. 0x51, 0xf0, 0xb3, 0xaf, 0x23, 0x8f, 0x0f, 0xdf,
  22686. 0xf1, 0xff, 0x23, 0x64, 0x28, 0xca, 0xf8, 0x06
  22687. };
  22688. #endif
  22689. PRIVATE_KEY_UNLOCK();
  22690. /* Initialize variables. */
  22691. XMEMSET(&key, 0, sizeof(ecc_key));
  22692. XMEMSET(&pubKey, 0, sizeof(ecc_key));
  22693. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22694. XMEMSET(out, 0, keySz);
  22695. ExpectIntEQ(wc_ecc_init(&key), 0);
  22696. ExpectIntEQ(wc_ecc_init(&pubKey), 0);
  22697. ExpectIntEQ(wc_InitRng(&rng), 0);
  22698. #if !defined(NO_ECC256)
  22699. ExpectIntEQ(wc_ecc_import_raw(&key, qx, qy, d, curveName), 0);
  22700. ExpectIntEQ(wc_ecc_import_raw(&pubKey, qx, qy, NULL, curveName), 0);
  22701. #else
  22702. ret = wc_ecc_make_key(&rng, keySz, &key);
  22703. #if defined(WOLFSSL_ASYNC_CRYPT)
  22704. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22705. #endif
  22706. ExpectIntEQ(ret, 0);
  22707. ret = wc_ecc_make_key(&rng, keySz, &key);
  22708. #if defined(WOLFSSL_ASYNC_CRYPT)
  22709. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22710. #endif
  22711. ExpectIntEQ(ret, 0);
  22712. #endif
  22713. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  22714. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  22715. !defined(HAVE_SELFTEST)
  22716. ExpectIntEQ(wc_ecc_set_rng(&key, &rng), 0);
  22717. #endif
  22718. ExpectIntEQ(wc_ecc_shared_secret(&key, &pubKey, out, &outlen), 0);
  22719. #if !defined(NO_ECC256)
  22720. ExpectIntEQ(XMEMCMP(out, expected_shared_secret, outlen), 0);
  22721. #endif
  22722. /* Test bad args. */
  22723. ExpectIntEQ(wc_ecc_shared_secret(NULL, &pubKey, out, &outlen),
  22724. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22725. ExpectIntEQ(wc_ecc_shared_secret(&key, NULL, out, &outlen),
  22726. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22727. ExpectIntEQ(wc_ecc_shared_secret(&key, &pubKey, NULL, &outlen),
  22728. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22729. ExpectIntEQ(wc_ecc_shared_secret(&key, &pubKey, out, NULL),
  22730. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22731. /* Invalid length */
  22732. outlen = 1;
  22733. ExpectIntEQ(wc_ecc_shared_secret(&key, &pubKey, out, &outlen),
  22734. WC_NO_ERR_TRACE(BUFFER_E));
  22735. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22736. wc_ecc_free(&pubKey);
  22737. wc_ecc_free(&key);
  22738. #ifdef FP_ECC
  22739. wc_ecc_fp_free();
  22740. #endif
  22741. PRIVATE_KEY_LOCK();
  22742. #endif
  22743. return EXPECT_RESULT();
  22744. } /* END tests_wc_ecc_shared_secret */
  22745. /*
  22746. * testint wc_ecc_export_x963()
  22747. */
  22748. static int test_wc_ecc_export_x963(void)
  22749. {
  22750. EXPECT_DECLS;
  22751. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  22752. ecc_key key;
  22753. WC_RNG rng;
  22754. byte out[ECC_ASN963_MAX_BUF_SZ];
  22755. word32 outlen = sizeof(out);
  22756. int ret;
  22757. PRIVATE_KEY_UNLOCK();
  22758. /* Initialize variables. */
  22759. XMEMSET(&key, 0, sizeof(ecc_key));
  22760. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22761. XMEMSET(out, 0, outlen);
  22762. ExpectIntEQ(wc_ecc_init(&key), 0);
  22763. ExpectIntEQ(wc_InitRng(&rng), 0);
  22764. ret = wc_ecc_make_key(&rng, KEY20, &key);
  22765. #if defined(WOLFSSL_ASYNC_CRYPT)
  22766. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22767. #endif
  22768. ExpectIntEQ(ret, 0);
  22769. ExpectIntEQ(wc_ecc_export_x963(&key, out, &outlen), 0);
  22770. /* Test bad args. */
  22771. ExpectIntEQ(wc_ecc_export_x963(NULL, out, &outlen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22772. ExpectIntEQ(wc_ecc_export_x963(&key, NULL, &outlen), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  22773. ExpectIntEQ(wc_ecc_export_x963(&key, out, NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22774. key.idx = -4;
  22775. ExpectIntEQ(wc_ecc_export_x963(&key, out, &outlen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22776. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22777. wc_ecc_free(&key);
  22778. #ifdef FP_ECC
  22779. wc_ecc_fp_free();
  22780. #endif
  22781. PRIVATE_KEY_LOCK();
  22782. #endif
  22783. return EXPECT_RESULT();
  22784. } /* END test_wc_ecc_export_x963 */
  22785. /*
  22786. * Testing wc_ecc_export_x963_ex()
  22787. * compile with --enable-compkey will use compression.
  22788. */
  22789. static int test_wc_ecc_export_x963_ex(void)
  22790. {
  22791. EXPECT_DECLS;
  22792. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  22793. ecc_key key;
  22794. WC_RNG rng;
  22795. int ret;
  22796. byte out[ECC_ASN963_MAX_BUF_SZ];
  22797. word32 outlen = sizeof(out);
  22798. #ifdef HAVE_COMP_KEY
  22799. word32 badOutLen = 5;
  22800. #endif
  22801. /* Init stack variables. */
  22802. XMEMSET(&key, 0, sizeof(ecc_key));
  22803. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22804. XMEMSET(out, 0, outlen);
  22805. PRIVATE_KEY_UNLOCK();
  22806. ExpectIntEQ(wc_ecc_init(&key), 0);
  22807. ExpectIntEQ(wc_InitRng(&rng), 0);
  22808. ret = wc_ecc_make_key(&rng, KEY64, &key);
  22809. #if defined(WOLFSSL_ASYNC_CRYPT)
  22810. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22811. #endif
  22812. ExpectIntEQ(ret, 0);
  22813. #ifdef HAVE_COMP_KEY
  22814. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &outlen, COMP), 0);
  22815. #else
  22816. ExpectIntEQ(ret = wc_ecc_export_x963_ex(&key, out, &outlen, NOCOMP), 0);
  22817. #endif
  22818. /* Test bad args. */
  22819. #ifdef HAVE_COMP_KEY
  22820. ExpectIntEQ(wc_ecc_export_x963_ex(NULL, out, &outlen, COMP), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22821. ExpectIntEQ(wc_ecc_export_x963_ex(&key, NULL, &outlen, COMP), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22822. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, NULL, COMP), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22823. #if defined(HAVE_FIPS) && (!defined(FIPS_VERSION_LT) || FIPS_VERSION_LT(5,3))
  22824. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &badOutLen, COMP), WC_NO_ERR_TRACE(BUFFER_E));
  22825. #else
  22826. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &badOutLen, COMP),
  22827. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  22828. #endif
  22829. key.idx = -4;
  22830. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &outlen, COMP), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22831. #else
  22832. ExpectIntEQ(wc_ecc_export_x963_ex(NULL, out, &outlen, NOCOMP),
  22833. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22834. ExpectIntEQ(wc_ecc_export_x963_ex(&key, NULL, &outlen, NOCOMP),
  22835. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  22836. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &outlen, 1), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  22837. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, NULL, NOCOMP),
  22838. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22839. key.idx = -4;
  22840. ExpectIntEQ(wc_ecc_export_x963_ex(&key, out, &outlen, NOCOMP),
  22841. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22842. #endif
  22843. PRIVATE_KEY_LOCK();
  22844. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22845. wc_ecc_free(&key);
  22846. #ifdef FP_ECC
  22847. wc_ecc_fp_free();
  22848. #endif
  22849. #endif
  22850. return EXPECT_RESULT();
  22851. } /* END test_wc_ecc_export_x963_ex */
  22852. /*
  22853. * testing wc_ecc_import_x963()
  22854. */
  22855. static int test_wc_ecc_import_x963(void)
  22856. {
  22857. EXPECT_DECLS;
  22858. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_IMPORT) && \
  22859. defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  22860. ecc_key pubKey;
  22861. ecc_key key;
  22862. WC_RNG rng;
  22863. byte x963[ECC_ASN963_MAX_BUF_SZ];
  22864. word32 x963Len = (word32)sizeof(x963);
  22865. int ret;
  22866. /* Init stack variables. */
  22867. XMEMSET(&key, 0, sizeof(ecc_key));
  22868. XMEMSET(&pubKey, 0, sizeof(ecc_key));
  22869. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22870. XMEMSET(x963, 0, x963Len);
  22871. ExpectIntEQ(wc_ecc_init(&pubKey), 0);
  22872. ExpectIntEQ(wc_ecc_init(&key), 0);
  22873. ExpectIntEQ(wc_InitRng(&rng), 0);
  22874. #if FIPS_VERSION3_GE(6,0,0)
  22875. ret = wc_ecc_make_key(&rng, KEY32, &key);
  22876. #else
  22877. ret = wc_ecc_make_key(&rng, KEY24, &key);
  22878. #endif
  22879. #if defined(WOLFSSL_ASYNC_CRYPT)
  22880. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22881. #endif
  22882. ExpectIntEQ(ret, 0);
  22883. PRIVATE_KEY_UNLOCK();
  22884. ExpectIntEQ(wc_ecc_export_x963(&key, x963, &x963Len), 0);
  22885. PRIVATE_KEY_LOCK();
  22886. ExpectIntEQ(wc_ecc_import_x963(x963, x963Len, &pubKey), 0);
  22887. /* Test bad args. */
  22888. ExpectIntEQ(wc_ecc_import_x963(NULL, x963Len, &pubKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22889. ExpectIntEQ(wc_ecc_import_x963(x963, x963Len, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22890. ExpectIntEQ(wc_ecc_import_x963(x963, x963Len + 1, &pubKey), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  22891. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22892. wc_ecc_free(&key);
  22893. wc_ecc_free(&pubKey);
  22894. #ifdef FP_ECC
  22895. wc_ecc_fp_free();
  22896. #endif
  22897. #endif
  22898. return EXPECT_RESULT();
  22899. } /* END wc_ecc_import_x963 */
  22900. /*
  22901. * testing wc_ecc_import_private_key()
  22902. */
  22903. static int test_wc_ecc_import_private_key(void)
  22904. {
  22905. EXPECT_DECLS;
  22906. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_IMPORT) && \
  22907. defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  22908. ecc_key key;
  22909. ecc_key keyImp;
  22910. WC_RNG rng;
  22911. byte privKey[ECC_PRIV_KEY_BUF]; /* Raw private key.*/
  22912. byte x963Key[ECC_ASN963_MAX_BUF_SZ];
  22913. word32 privKeySz = (word32)sizeof(privKey);
  22914. word32 x963KeySz = (word32)sizeof(x963Key);
  22915. int ret;
  22916. /* Init stack variables. */
  22917. XMEMSET(&key, 0, sizeof(ecc_key));
  22918. XMEMSET(&keyImp, 0, sizeof(ecc_key));
  22919. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22920. XMEMSET(privKey, 0, privKeySz);
  22921. XMEMSET(x963Key, 0, x963KeySz);
  22922. PRIVATE_KEY_UNLOCK();
  22923. ExpectIntEQ(wc_ecc_init(&key), 0);
  22924. ExpectIntEQ(wc_ecc_init(&keyImp), 0);
  22925. ExpectIntEQ(wc_InitRng(&rng), 0);
  22926. ret = wc_ecc_make_key(&rng, KEY48, &key);
  22927. #if defined(WOLFSSL_ASYNC_CRYPT)
  22928. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22929. #endif
  22930. ExpectIntEQ(ret, 0);
  22931. PRIVATE_KEY_UNLOCK();
  22932. ExpectIntEQ(wc_ecc_export_x963(&key, x963Key, &x963KeySz), 0);
  22933. PRIVATE_KEY_LOCK();
  22934. ExpectIntEQ(wc_ecc_export_private_only(&key, privKey, &privKeySz), 0);
  22935. ExpectIntEQ(wc_ecc_import_private_key(privKey, privKeySz, x963Key,
  22936. x963KeySz, &keyImp), 0);
  22937. /* Pass in bad args. */
  22938. ExpectIntEQ(wc_ecc_import_private_key(privKey, privKeySz, x963Key,
  22939. x963KeySz, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22940. ExpectIntEQ(wc_ecc_import_private_key(NULL, privKeySz, x963Key, x963KeySz,
  22941. &keyImp), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22942. PRIVATE_KEY_LOCK();
  22943. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22944. wc_ecc_free(&keyImp);
  22945. wc_ecc_free(&key);
  22946. #ifdef FP_ECC
  22947. wc_ecc_fp_free();
  22948. #endif
  22949. #endif
  22950. return EXPECT_RESULT();
  22951. } /* END test_wc_ecc_import_private_key */
  22952. /*
  22953. * Testing wc_ecc_export_private_only()
  22954. */
  22955. static int test_wc_ecc_export_private_only(void)
  22956. {
  22957. EXPECT_DECLS;
  22958. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  22959. ecc_key key;
  22960. WC_RNG rng;
  22961. byte out[ECC_PRIV_KEY_BUF];
  22962. word32 outlen = sizeof(out);
  22963. int ret;
  22964. /* Init stack variables. */
  22965. XMEMSET(&key, 0, sizeof(ecc_key));
  22966. XMEMSET(&rng, 0, sizeof(WC_RNG));
  22967. XMEMSET(out, 0, outlen);
  22968. PRIVATE_KEY_UNLOCK();
  22969. ExpectIntEQ(wc_ecc_init(&key), 0);
  22970. ExpectIntEQ(wc_InitRng(&rng), 0);
  22971. ret = wc_ecc_make_key(&rng, KEY32, &key);
  22972. #if defined(WOLFSSL_ASYNC_CRYPT)
  22973. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  22974. #endif
  22975. ExpectIntEQ(ret, 0);
  22976. ExpectIntEQ(wc_ecc_export_private_only(&key, out, &outlen), 0);
  22977. /* Pass in bad args. */
  22978. ExpectIntEQ(wc_ecc_export_private_only(NULL, out, &outlen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22979. ExpectIntEQ(wc_ecc_export_private_only(&key, NULL, &outlen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22980. ExpectIntEQ(wc_ecc_export_private_only(&key, out, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  22981. PRIVATE_KEY_LOCK();
  22982. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  22983. wc_ecc_free(&key);
  22984. #ifdef FP_ECC
  22985. wc_ecc_fp_free();
  22986. #endif
  22987. #endif
  22988. return EXPECT_RESULT();
  22989. } /* END test_wc_ecc_export_private_only */
  22990. /*
  22991. * Testing wc_ecc_rs_to_sig()
  22992. */
  22993. static int test_wc_ecc_rs_to_sig(void)
  22994. {
  22995. EXPECT_DECLS;
  22996. #if defined(HAVE_ECC) && !defined(NO_ASN)
  22997. /* first [P-192,SHA-1] vector from FIPS 186-3 NIST vectors */
  22998. const char* R = "6994d962bdd0d793ffddf855ec5bf2f91a9698b46258a63e";
  22999. const char* S = "02ba6465a234903744ab02bc8521405b73cf5fc00e1a9f41";
  23000. const char* zeroStr = "0";
  23001. byte sig[ECC_MAX_SIG_SIZE];
  23002. word32 siglen = (word32)sizeof(sig);
  23003. /* R and S max size is the order of curve. 2^192.*/
  23004. int keySz = KEY24;
  23005. byte r[KEY24];
  23006. byte s[KEY24];
  23007. word32 rlen = (word32)sizeof(r);
  23008. word32 slen = (word32)sizeof(s);
  23009. /* Init stack variables. */
  23010. XMEMSET(sig, 0, ECC_MAX_SIG_SIZE);
  23011. XMEMSET(r, 0, keySz);
  23012. XMEMSET(s, 0, keySz);
  23013. ExpectIntEQ(wc_ecc_rs_to_sig(R, S, sig, &siglen), 0);
  23014. ExpectIntEQ(wc_ecc_sig_to_rs(sig, siglen, r, &rlen, s, &slen), 0);
  23015. /* Test bad args. */
  23016. ExpectIntEQ(wc_ecc_rs_to_sig(NULL, S, sig, &siglen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23017. ExpectIntEQ(wc_ecc_rs_to_sig(R, NULL, sig, &siglen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23018. ExpectIntEQ(wc_ecc_rs_to_sig(R, S, sig, NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23019. ExpectIntEQ(wc_ecc_rs_to_sig(R, S, NULL, &siglen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23020. ExpectIntEQ(wc_ecc_rs_to_sig(R, zeroStr, sig, &siglen), WC_NO_ERR_TRACE(MP_ZERO_E));
  23021. ExpectIntEQ(wc_ecc_rs_to_sig(zeroStr, S, sig, &siglen), WC_NO_ERR_TRACE(MP_ZERO_E));
  23022. ExpectIntEQ(wc_ecc_sig_to_rs(NULL, siglen, r, &rlen, s, &slen),
  23023. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23024. ExpectIntEQ(wc_ecc_sig_to_rs(sig, siglen, NULL, &rlen, s, &slen),
  23025. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23026. ExpectIntEQ(wc_ecc_sig_to_rs(sig, siglen, r, NULL, s, &slen),
  23027. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23028. ExpectIntEQ(wc_ecc_sig_to_rs(sig, siglen, r, &rlen, NULL, &slen),
  23029. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23030. ExpectIntEQ(wc_ecc_sig_to_rs(sig, siglen, r, &rlen, s, NULL),
  23031. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23032. #endif
  23033. return EXPECT_RESULT();
  23034. } /* END test_wc_ecc_rs_to_sig */
  23035. static int test_wc_ecc_import_raw(void)
  23036. {
  23037. EXPECT_DECLS;
  23038. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  23039. ecc_key key;
  23040. const char* qx =
  23041. "bb33ac4c27504ac64aa504c33cde9f36db722dce94ea2bfacb2009392c16e861";
  23042. const char* qy =
  23043. "02e9af4dd302939a315b9792217ff0cf18da9111023486e82058330b803489d8";
  23044. const char* d =
  23045. "45b66902739c6c85a1385b72e8e8c7acc4038d533504fa6c28dc348de1a8098c";
  23046. const char* curveName = "SECP256R1";
  23047. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  23048. const char* kNullStr = "";
  23049. int ret;
  23050. #endif
  23051. XMEMSET(&key, 0, sizeof(ecc_key));
  23052. ExpectIntEQ(wc_ecc_init(&key), 0);
  23053. /* Test good import */
  23054. ExpectIntEQ(wc_ecc_import_raw(&key, qx, qy, d, curveName), 0);
  23055. /* Test bad args. */
  23056. ExpectIntEQ(wc_ecc_import_raw(NULL, qx, qy, d, curveName), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23057. ExpectIntEQ(wc_ecc_import_raw(&key, NULL, qy, d, curveName), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23058. ExpectIntEQ(wc_ecc_import_raw(&key, qx, NULL, d, curveName), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23059. ExpectIntEQ(wc_ecc_import_raw(&key, qx, qy, d, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23060. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  23061. #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_SP_MATH)
  23062. wc_ecc_free(&key);
  23063. #endif
  23064. ExpectIntLT(ret = wc_ecc_import_raw(&key, kNullStr, kNullStr, kNullStr,
  23065. curveName), 0);
  23066. ExpectTrue((ret == WC_NO_ERR_TRACE(ECC_INF_E)) || (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)));
  23067. #endif
  23068. #if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  23069. #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_SP_MATH)
  23070. wc_ecc_free(&key);
  23071. #endif
  23072. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  23073. ExpectIntLT(ret = wc_ecc_import_raw(&key, "0", qy, d, curveName), 0);
  23074. ExpectTrue((ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)) || (ret == WC_NO_ERR_TRACE(MP_VAL)));
  23075. #else
  23076. ExpectIntEQ(wc_ecc_import_raw(&key, "0", qy, d, curveName), 0);
  23077. #endif
  23078. #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_SP_MATH)
  23079. wc_ecc_free(&key);
  23080. #endif
  23081. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  23082. ExpectIntLT(ret = wc_ecc_import_raw(&key, qx, "0", d, curveName), 0);
  23083. ExpectTrue((ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)) || (ret == WC_NO_ERR_TRACE(MP_VAL)));
  23084. #else
  23085. ExpectIntEQ(wc_ecc_import_raw(&key, qx, "0", d, curveName), 0);
  23086. #endif
  23087. #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_SP_MATH)
  23088. wc_ecc_free(&key);
  23089. #endif
  23090. ExpectIntEQ(wc_ecc_import_raw(&key, "0", "0", d, curveName), WC_NO_ERR_TRACE(ECC_INF_E));
  23091. #endif
  23092. wc_ecc_free(&key);
  23093. #endif
  23094. return EXPECT_RESULT();
  23095. } /* END test_wc_ecc_import_raw */
  23096. static int test_wc_ecc_import_unsigned(void)
  23097. {
  23098. EXPECT_DECLS;
  23099. #if defined(HAVE_ECC) && !defined(NO_ECC256) && !defined(HAVE_SELFTEST) && \
  23100. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  23101. HAVE_FIPS_VERSION >= 2))
  23102. ecc_key key;
  23103. const byte qx[] = {
  23104. 0xbb, 0x33, 0xac, 0x4c, 0x27, 0x50, 0x4a, 0xc6,
  23105. 0x4a, 0xa5, 0x04, 0xc3, 0x3c, 0xde, 0x9f, 0x36,
  23106. 0xdb, 0x72, 0x2d, 0xce, 0x94, 0xea, 0x2b, 0xfa,
  23107. 0xcb, 0x20, 0x09, 0x39, 0x2c, 0x16, 0xe8, 0x61
  23108. };
  23109. const byte qy[] = {
  23110. 0x02, 0xe9, 0xaf, 0x4d, 0xd3, 0x02, 0x93, 0x9a,
  23111. 0x31, 0x5b, 0x97, 0x92, 0x21, 0x7f, 0xf0, 0xcf,
  23112. 0x18, 0xda, 0x91, 0x11, 0x02, 0x34, 0x86, 0xe8,
  23113. 0x20, 0x58, 0x33, 0x0b, 0x80, 0x34, 0x89, 0xd8
  23114. };
  23115. const byte d[] = {
  23116. 0x45, 0xb6, 0x69, 0x02, 0x73, 0x9c, 0x6c, 0x85,
  23117. 0xa1, 0x38, 0x5b, 0x72, 0xe8, 0xe8, 0xc7, 0xac,
  23118. 0xc4, 0x03, 0x8d, 0x53, 0x35, 0x04, 0xfa, 0x6c,
  23119. 0x28, 0xdc, 0x34, 0x8d, 0xe1, 0xa8, 0x09, 0x8c
  23120. };
  23121. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  23122. const byte nullBytes[32] = {0};
  23123. int ret;
  23124. #endif
  23125. int curveId = ECC_SECP256R1;
  23126. XMEMSET(&key, 0, sizeof(ecc_key));
  23127. ExpectIntEQ(wc_ecc_init(&key), 0);
  23128. ExpectIntEQ(wc_ecc_import_unsigned(&key, (byte*)qx, (byte*)qy, (byte*)d,
  23129. curveId), 0);
  23130. /* Test bad args. */
  23131. ExpectIntEQ(wc_ecc_import_unsigned(NULL, (byte*)qx, (byte*)qy, (byte*)d,
  23132. curveId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23133. ExpectIntEQ(wc_ecc_import_unsigned(&key, NULL, (byte*)qy, (byte*)d,
  23134. curveId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23135. ExpectIntEQ(wc_ecc_import_unsigned(&key, (byte*)qx, NULL, (byte*)d,
  23136. curveId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23137. ExpectIntEQ(wc_ecc_import_unsigned(&key, (byte*)qx, (byte*)qy, (byte*)d,
  23138. ECC_CURVE_INVALID), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23139. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  23140. ExpectIntLT(ret = wc_ecc_import_unsigned(&key, (byte*)nullBytes,
  23141. (byte*)nullBytes, (byte*)nullBytes, curveId), 0);
  23142. ExpectTrue((ret == WC_NO_ERR_TRACE(ECC_INF_E)) || (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG)));
  23143. #endif
  23144. wc_ecc_free(&key);
  23145. #endif
  23146. return EXPECT_RESULT();
  23147. } /* END test_wc_ecc_import_unsigned */
  23148. /*
  23149. * Testing wc_ecc_sig_size()
  23150. */
  23151. static int test_wc_ecc_sig_size(void)
  23152. {
  23153. EXPECT_DECLS;
  23154. #if defined(HAVE_ECC) && !defined(WC_NO_RNG)
  23155. ecc_key key;
  23156. WC_RNG rng;
  23157. int keySz = KEY16;
  23158. int ret;
  23159. XMEMSET(&rng, 0, sizeof(rng));
  23160. XMEMSET(&key, 0, sizeof(key));
  23161. ExpectIntEQ(wc_ecc_init(&key), 0);
  23162. ExpectIntEQ(wc_InitRng(&rng), 0);
  23163. ret = wc_ecc_make_key(&rng, keySz, &key);
  23164. #if defined(WOLFSSL_ASYNC_CRYPT)
  23165. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  23166. #endif
  23167. ExpectIntEQ(ret, 0);
  23168. ExpectIntLE(wc_ecc_sig_size(&key),
  23169. (2 * keySz + SIG_HEADER_SZ + ECC_MAX_PAD_SZ));
  23170. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23171. wc_ecc_free(&key);
  23172. #endif
  23173. return EXPECT_RESULT();
  23174. } /* END test_wc_ecc_sig_size */
  23175. /*
  23176. * Testing wc_ecc_ctx_new()
  23177. */
  23178. static int test_wc_ecc_ctx_new(void)
  23179. {
  23180. EXPECT_DECLS;
  23181. #if defined(HAVE_ECC) && defined(HAVE_ECC_ENCRYPT) && !defined(WC_NO_RNG)
  23182. WC_RNG rng;
  23183. ecEncCtx* cli = NULL;
  23184. ecEncCtx* srv = NULL;
  23185. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23186. ExpectIntEQ(wc_InitRng(&rng), 0);
  23187. ExpectNotNull(cli = wc_ecc_ctx_new(REQ_RESP_CLIENT, &rng));
  23188. ExpectNotNull(srv = wc_ecc_ctx_new(REQ_RESP_SERVER, &rng));
  23189. wc_ecc_ctx_free(cli);
  23190. cli = NULL;
  23191. wc_ecc_ctx_free(srv);
  23192. /* Test bad args. */
  23193. /* wc_ecc_ctx_new_ex() will free if returned NULL. */
  23194. ExpectNull(cli = wc_ecc_ctx_new(0, &rng));
  23195. ExpectNull(cli = wc_ecc_ctx_new(REQ_RESP_CLIENT, NULL));
  23196. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23197. wc_ecc_ctx_free(cli);
  23198. #endif
  23199. return EXPECT_RESULT();
  23200. } /* END test_wc_ecc_ctx_new */
  23201. /*
  23202. * Tesing wc_ecc_reset()
  23203. */
  23204. static int test_wc_ecc_ctx_reset(void)
  23205. {
  23206. EXPECT_DECLS;
  23207. #if defined(HAVE_ECC) && defined(HAVE_ECC_ENCRYPT) && !defined(WC_NO_RNG)
  23208. ecEncCtx* ctx = NULL;
  23209. WC_RNG rng;
  23210. XMEMSET(&rng, 0, sizeof(rng));
  23211. ExpectIntEQ(wc_InitRng(&rng), 0);
  23212. ExpectNotNull(ctx = wc_ecc_ctx_new(REQ_RESP_CLIENT, &rng));
  23213. ExpectIntEQ(wc_ecc_ctx_reset(ctx, &rng), 0);
  23214. /* Pass in bad args. */
  23215. ExpectIntEQ(wc_ecc_ctx_reset(NULL, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23216. ExpectIntEQ(wc_ecc_ctx_reset(ctx, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23217. wc_ecc_ctx_free(ctx);
  23218. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23219. #endif
  23220. return EXPECT_RESULT();
  23221. } /* END test_wc_ecc_ctx_reset */
  23222. /*
  23223. * Testing wc_ecc_ctx_set_peer_salt() and wc_ecc_ctx_get_own_salt()
  23224. */
  23225. static int test_wc_ecc_ctx_set_peer_salt(void)
  23226. {
  23227. EXPECT_DECLS;
  23228. #if defined(HAVE_ECC) && defined(HAVE_ECC_ENCRYPT) && !defined(WC_NO_RNG)
  23229. WC_RNG rng;
  23230. ecEncCtx* cliCtx = NULL;
  23231. ecEncCtx* servCtx = NULL;
  23232. const byte* cliSalt = NULL;
  23233. const byte* servSalt = NULL;
  23234. XMEMSET(&rng, 0, sizeof(rng));
  23235. ExpectIntEQ(wc_InitRng(&rng), 0);
  23236. ExpectNotNull(cliCtx = wc_ecc_ctx_new(REQ_RESP_CLIENT, &rng));
  23237. ExpectNotNull(servCtx = wc_ecc_ctx_new(REQ_RESP_SERVER, &rng));
  23238. /* Test bad args. */
  23239. ExpectNull(cliSalt = wc_ecc_ctx_get_own_salt(NULL));
  23240. ExpectNotNull(cliSalt = wc_ecc_ctx_get_own_salt(cliCtx));
  23241. ExpectNotNull(servSalt = wc_ecc_ctx_get_own_salt(servCtx));
  23242. ExpectIntEQ(wc_ecc_ctx_set_peer_salt(cliCtx, servSalt), 0);
  23243. /* Test bad args. */
  23244. ExpectIntEQ(wc_ecc_ctx_set_peer_salt(NULL, servSalt), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23245. ExpectIntEQ(wc_ecc_ctx_set_peer_salt(cliCtx, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23246. wc_ecc_ctx_free(cliCtx);
  23247. wc_ecc_ctx_free(servCtx);
  23248. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23249. #endif
  23250. return EXPECT_RESULT();
  23251. } /* END test_wc_ecc_ctx_set_peer_salt */
  23252. /*
  23253. * Testing wc_ecc_ctx_set_info()
  23254. */
  23255. static int test_wc_ecc_ctx_set_info(void)
  23256. {
  23257. EXPECT_DECLS;
  23258. #if defined(HAVE_ECC) && defined(HAVE_ECC_ENCRYPT) && !defined(WC_NO_RNG)
  23259. ecEncCtx* ctx = NULL;
  23260. WC_RNG rng;
  23261. const char* optInfo = "Optional Test Info.";
  23262. int optInfoSz = (int)XSTRLEN(optInfo);
  23263. const char* badOptInfo = NULL;
  23264. XMEMSET(&rng, 0, sizeof(rng));
  23265. ExpectIntEQ(wc_InitRng(&rng), 0);
  23266. ExpectNotNull(ctx = wc_ecc_ctx_new(REQ_RESP_CLIENT, &rng));
  23267. ExpectIntEQ(wc_ecc_ctx_set_info(ctx, (byte*)optInfo, optInfoSz), 0);
  23268. /* Test bad args. */
  23269. ExpectIntEQ(wc_ecc_ctx_set_info(NULL, (byte*)optInfo, optInfoSz),
  23270. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23271. ExpectIntEQ(wc_ecc_ctx_set_info(ctx, (byte*)badOptInfo, optInfoSz),
  23272. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23273. ExpectIntEQ(wc_ecc_ctx_set_info(ctx, (byte*)optInfo, -1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23274. wc_ecc_ctx_free(ctx);
  23275. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23276. #endif
  23277. return EXPECT_RESULT();
  23278. } /* END test_wc_ecc_ctx_set_info */
  23279. /*
  23280. * Testing wc_ecc_encrypt() and wc_ecc_decrypt()
  23281. */
  23282. static int test_wc_ecc_encryptDecrypt(void)
  23283. {
  23284. EXPECT_DECLS;
  23285. #if defined(HAVE_ECC) && defined(HAVE_ECC_ENCRYPT) && !defined(WC_NO_RNG) && \
  23286. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  23287. ecc_key srvKey;
  23288. ecc_key cliKey;
  23289. ecc_key tmpKey;
  23290. WC_RNG rng;
  23291. int ret;
  23292. const char* msg = "EccBlock Size 16";
  23293. word32 msgSz = (word32)XSTRLEN("EccBlock Size 16");
  23294. #ifdef WOLFSSL_ECIES_OLD
  23295. byte out[(sizeof("EccBlock Size 16") - 1) + WC_SHA256_DIGEST_SIZE];
  23296. #elif defined(WOLFSSL_ECIES_GEN_IV)
  23297. byte out[KEY20 * 2 + 1 + AES_BLOCK_SIZE +
  23298. (sizeof("EccBlock Size 16") - 1) + WC_SHA256_DIGEST_SIZE];
  23299. #else
  23300. byte out[KEY20 * 2 + 1 + (sizeof("EccBlock Size 16") - 1) +
  23301. WC_SHA256_DIGEST_SIZE];
  23302. #endif
  23303. word32 outSz = (word32)sizeof(out);
  23304. byte plain[sizeof("EccBlock Size 16")];
  23305. word32 plainSz = (word32)sizeof(plain);
  23306. int keySz = KEY20;
  23307. /* Init stack variables. */
  23308. XMEMSET(out, 0, outSz);
  23309. XMEMSET(plain, 0, plainSz);
  23310. XMEMSET(&rng, 0, sizeof(rng));
  23311. XMEMSET(&srvKey, 0, sizeof(ecc_key));
  23312. XMEMSET(&cliKey, 0, sizeof(ecc_key));
  23313. XMEMSET(&tmpKey, 0, sizeof(ecc_key));
  23314. ExpectIntEQ(wc_InitRng(&rng), 0);
  23315. ExpectIntEQ(wc_ecc_init(&cliKey), 0);
  23316. ret = wc_ecc_make_key(&rng, keySz, &cliKey);
  23317. #if defined(WOLFSSL_ASYNC_CRYPT)
  23318. ret = wc_AsyncWait(ret, &cliKey.asyncDev, WC_ASYNC_FLAG_NONE);
  23319. #endif
  23320. ExpectIntEQ(ret, 0);
  23321. ExpectIntEQ(wc_ecc_init(&srvKey), 0);
  23322. ret = wc_ecc_make_key(&rng, keySz, &srvKey);
  23323. #if defined(WOLFSSL_ASYNC_CRYPT)
  23324. ret = wc_AsyncWait(ret, &srvKey.asyncDev, WC_ASYNC_FLAG_NONE);
  23325. #endif
  23326. ExpectIntEQ(ret, 0);
  23327. ExpectIntEQ(wc_ecc_init(&tmpKey), 0);
  23328. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  23329. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  23330. !defined(HAVE_SELFTEST)
  23331. ExpectIntEQ(wc_ecc_set_rng(&srvKey, &rng), 0);
  23332. ExpectIntEQ(wc_ecc_set_rng(&cliKey, &rng), 0);
  23333. #endif
  23334. ExpectIntEQ(wc_ecc_encrypt(&cliKey, &srvKey, (byte*)msg, msgSz, out,
  23335. &outSz, NULL), 0);
  23336. /* Test bad args. */
  23337. ExpectIntEQ(wc_ecc_encrypt(NULL, &srvKey, (byte*)msg, msgSz, out, &outSz,
  23338. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23339. ExpectIntEQ(wc_ecc_encrypt(&cliKey, NULL, (byte*)msg, msgSz, out, &outSz,
  23340. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23341. ExpectIntEQ(wc_ecc_encrypt(&cliKey, &srvKey, NULL, msgSz, out, &outSz,
  23342. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23343. ExpectIntEQ(wc_ecc_encrypt(&cliKey, &srvKey, (byte*)msg, msgSz, NULL,
  23344. &outSz, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23345. ExpectIntEQ(wc_ecc_encrypt(&cliKey, &srvKey, (byte*)msg, msgSz, out, NULL,
  23346. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23347. #ifdef WOLFSSL_ECIES_OLD
  23348. tmpKey.dp = cliKey.dp;
  23349. ExpectIntEQ(wc_ecc_copy_point(&cliKey.pubkey, &tmpKey.pubkey), 0);
  23350. #endif
  23351. ExpectIntEQ(wc_ecc_decrypt(&srvKey, &tmpKey, out, outSz, plain, &plainSz,
  23352. NULL), 0);
  23353. ExpectIntEQ(wc_ecc_decrypt(NULL, &tmpKey, out, outSz, plain, &plainSz,
  23354. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23355. #ifdef WOLFSSL_ECIES_OLD
  23356. /* NULL parameter allowed in new implementations - public key comes from
  23357. * the message. */
  23358. ExpectIntEQ(wc_ecc_decrypt(&srvKey, NULL, out, outSz, plain, &plainSz,
  23359. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23360. #endif
  23361. ExpectIntEQ(wc_ecc_decrypt(&srvKey, &tmpKey, NULL, outSz, plain, &plainSz,
  23362. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23363. ExpectIntEQ(wc_ecc_decrypt(&srvKey, &tmpKey, out, outSz, NULL, &plainSz,
  23364. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23365. ExpectIntEQ(wc_ecc_decrypt(&srvKey, &tmpKey, out, outSz, plain, NULL, NULL),
  23366. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23367. ExpectIntEQ(XMEMCMP(msg, plain, msgSz), 0);
  23368. wc_ecc_free(&tmpKey);
  23369. wc_ecc_free(&srvKey);
  23370. wc_ecc_free(&cliKey);
  23371. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23372. #endif
  23373. return EXPECT_RESULT();
  23374. } /* END test_wc_ecc_encryptDecrypt */
  23375. /*
  23376. * Testing wc_ecc_del_point() and wc_ecc_new_point()
  23377. */
  23378. static int test_wc_ecc_del_point(void)
  23379. {
  23380. EXPECT_DECLS;
  23381. #if defined(HAVE_ECC)
  23382. ecc_point* pt = NULL;
  23383. ExpectNotNull(pt = wc_ecc_new_point());
  23384. wc_ecc_del_point(pt);
  23385. #endif
  23386. return EXPECT_RESULT();
  23387. } /* END test_wc_ecc_del_point */
  23388. /*
  23389. * Testing wc_ecc_point_is_at_infinity(), wc_ecc_export_point_der(),
  23390. * wc_ecc_import_point_der(), wc_ecc_copy_point(), wc_ecc_point_is_on_curve(),
  23391. * and wc_ecc_cmp_point()
  23392. */
  23393. static int test_wc_ecc_pointFns(void)
  23394. {
  23395. EXPECT_DECLS;
  23396. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT) && \
  23397. !defined(WC_NO_RNG) && !defined(WOLFSSL_ATECC508A) && \
  23398. !defined(WOLFSSL_ATECC608A)
  23399. ecc_key key;
  23400. WC_RNG rng;
  23401. int ret;
  23402. ecc_point* point = NULL;
  23403. ecc_point* cpypt = NULL;
  23404. int idx = 0;
  23405. int keySz = KEY32;
  23406. byte der[DER_SZ(KEY32)];
  23407. word32 derlenChk = 0;
  23408. word32 derSz = DER_SZ(KEY32);
  23409. /* Init stack variables. */
  23410. XMEMSET(der, 0, derSz);
  23411. XMEMSET(&key, 0, sizeof(ecc_key));
  23412. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23413. ExpectIntEQ(wc_InitRng(&rng), 0);
  23414. ExpectIntEQ(wc_ecc_init(&key), 0);
  23415. ret = wc_ecc_make_key(&rng, keySz, &key);
  23416. #if defined(WOLFSSL_ASYNC_CRYPT)
  23417. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  23418. #endif
  23419. ExpectIntEQ(ret, 0);
  23420. ExpectNotNull(point = wc_ecc_new_point());
  23421. ExpectNotNull(cpypt = wc_ecc_new_point());
  23422. /* Export */
  23423. ExpectIntEQ(wc_ecc_export_point_der((idx = key.idx), &key.pubkey, NULL,
  23424. &derlenChk), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  23425. /* Check length value. */
  23426. ExpectIntEQ(derSz, derlenChk);
  23427. ExpectIntEQ(wc_ecc_export_point_der((idx = key.idx), &key.pubkey, der,
  23428. &derSz), 0);
  23429. /* Test bad args. */
  23430. ExpectIntEQ(wc_ecc_export_point_der(-2, &key.pubkey, der, &derSz),
  23431. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23432. ExpectIntEQ(wc_ecc_export_point_der((idx = key.idx), NULL, der, &derSz),
  23433. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23434. ExpectIntEQ(wc_ecc_export_point_der((idx = key.idx), &key.pubkey, der,
  23435. NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23436. /* Import */
  23437. ExpectIntEQ(wc_ecc_import_point_der(der, derSz, idx, point), 0);
  23438. ExpectIntEQ(wc_ecc_cmp_point(&key.pubkey, point), 0);
  23439. /* Test bad args. */
  23440. ExpectIntEQ( wc_ecc_import_point_der(NULL, derSz, idx, point),
  23441. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23442. ExpectIntEQ(wc_ecc_import_point_der(der, derSz, idx, NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23443. ExpectIntEQ(wc_ecc_import_point_der(der, derSz, -1, point), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23444. ExpectIntEQ(wc_ecc_import_point_der(der, derSz + 1, idx, point),
  23445. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23446. /* Copy */
  23447. ExpectIntEQ(wc_ecc_copy_point(point, cpypt), 0);
  23448. /* Test bad args. */
  23449. ExpectIntEQ(wc_ecc_copy_point(NULL, cpypt), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23450. ExpectIntEQ(wc_ecc_copy_point(point, NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23451. /* Compare point */
  23452. ExpectIntEQ(wc_ecc_cmp_point(point, cpypt), 0);
  23453. /* Test bad args. */
  23454. ExpectIntEQ(wc_ecc_cmp_point(NULL, cpypt), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23455. ExpectIntEQ(wc_ecc_cmp_point(point, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23456. /* At infinity if return == 1, otherwise return == 0. */
  23457. ExpectIntEQ(wc_ecc_point_is_at_infinity(point), 0);
  23458. /* Test bad args. */
  23459. ExpectIntEQ(wc_ecc_point_is_at_infinity(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23460. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  23461. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2)))
  23462. #ifdef USE_ECC_B_PARAM
  23463. /* On curve if ret == 0 */
  23464. ExpectIntEQ(wc_ecc_point_is_on_curve(point, idx), 0);
  23465. /* Test bad args. */
  23466. ExpectIntEQ(wc_ecc_point_is_on_curve(NULL, idx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23467. ExpectIntEQ(wc_ecc_point_is_on_curve(point, 1000), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23468. #endif /* USE_ECC_B_PARAM */
  23469. #endif /* !HAVE_SELFTEST && (!HAVE_FIPS || HAVE_FIPS_VERSION > 2) */
  23470. /* Free */
  23471. wc_ecc_del_point(point);
  23472. wc_ecc_del_point(cpypt);
  23473. wc_ecc_free(&key);
  23474. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23475. #endif
  23476. return EXPECT_RESULT();
  23477. } /* END test_wc_ecc_pointFns */
  23478. /*
  23479. * Testing wc_ecc_shared_secret_ssh()
  23480. */
  23481. static int test_wc_ecc_shared_secret_ssh(void)
  23482. {
  23483. EXPECT_DECLS;
  23484. #if defined(HAVE_ECC) && defined(HAVE_ECC_DHE) && \
  23485. !defined(WC_NO_RNG) && !defined(WOLFSSL_ATECC508A) && \
  23486. !defined(WOLFSSL_ATECC608A) && !defined(PLUTON_CRYPTO_ECC) && \
  23487. !defined(WOLFSSL_CRYPTOCELL)
  23488. ecc_key key;
  23489. ecc_key key2;
  23490. WC_RNG rng;
  23491. int ret;
  23492. int keySz = KEY32;
  23493. #if FIPS_VERSION3_GE(6,0,0)
  23494. int key2Sz = KEY28;
  23495. #else
  23496. int key2Sz = KEY24;
  23497. #endif
  23498. byte secret[KEY32];
  23499. word32 secretLen = (word32)keySz;
  23500. /* Init stack variables. */
  23501. XMEMSET(&key, 0, sizeof(ecc_key));
  23502. XMEMSET(&key2, 0, sizeof(ecc_key));
  23503. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23504. XMEMSET(secret, 0, secretLen);
  23505. PRIVATE_KEY_UNLOCK();
  23506. /* Make keys */
  23507. ExpectIntEQ(wc_ecc_init(&key), 0);
  23508. ExpectIntEQ(wc_InitRng(&rng), 0);
  23509. ret = wc_ecc_make_key(&rng, keySz, &key);
  23510. #if defined(WOLFSSL_ASYNC_CRYPT)
  23511. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  23512. #endif
  23513. ExpectIntEQ(ret, 0);
  23514. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23515. ExpectIntEQ(wc_ecc_init(&key2), 0);
  23516. ExpectIntEQ(wc_InitRng(&rng), 0);
  23517. ret = wc_ecc_make_key(&rng, key2Sz, &key2);
  23518. #if defined(WOLFSSL_ASYNC_CRYPT)
  23519. ret = wc_AsyncWait(ret, &key2.asyncDev, WC_ASYNC_FLAG_NONE);
  23520. #endif
  23521. ExpectIntEQ(ret, 0);
  23522. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  23523. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  23524. !defined(HAVE_SELFTEST)
  23525. ExpectIntEQ(wc_ecc_set_rng(&key, &rng), 0);
  23526. #endif
  23527. ExpectIntEQ(wc_ecc_shared_secret_ssh(&key, &key2.pubkey, secret,
  23528. &secretLen), 0);
  23529. /* Pass in bad args. */
  23530. ExpectIntEQ(wc_ecc_shared_secret_ssh(NULL, &key2.pubkey, secret,
  23531. &secretLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23532. ExpectIntEQ(wc_ecc_shared_secret_ssh(&key, NULL, secret, &secretLen),
  23533. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23534. ExpectIntEQ(wc_ecc_shared_secret_ssh(&key, &key2.pubkey, NULL, &secretLen),
  23535. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23536. ExpectIntEQ(wc_ecc_shared_secret_ssh(&key, &key2.pubkey, secret, NULL),
  23537. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23538. key.type = ECC_PUBLICKEY;
  23539. ExpectIntEQ(wc_ecc_shared_secret_ssh(&key, &key2.pubkey, secret,
  23540. &secretLen), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23541. PRIVATE_KEY_LOCK();
  23542. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23543. wc_ecc_free(&key);
  23544. wc_ecc_free(&key2);
  23545. #ifdef FP_ECC
  23546. wc_ecc_fp_free();
  23547. #endif
  23548. #endif
  23549. return EXPECT_RESULT();
  23550. } /* END test_wc_ecc_shared_secret_ssh */
  23551. /*
  23552. * Testing wc_ecc_verify_hash_ex() and wc_ecc_verify_hash_ex()
  23553. */
  23554. static int test_wc_ecc_verify_hash_ex(void)
  23555. {
  23556. EXPECT_DECLS;
  23557. #if defined(HAVE_ECC) && defined(HAVE_ECC_SIGN) && defined(WOLFSSL_PUBLIC_MP) \
  23558. && !defined(WC_NO_RNG) && !defined(WOLFSSL_ATECC508A) && \
  23559. !defined(WOLFSSL_ATECC608A) && !defined(WOLFSSL_KCAPI_ECC)
  23560. ecc_key key;
  23561. WC_RNG rng;
  23562. int ret;
  23563. mp_int r;
  23564. mp_int s;
  23565. mp_int z;
  23566. unsigned char hash[] = "Everyone gets Friday off.EccSig";
  23567. unsigned char iHash[] = "Everyone gets Friday off.......";
  23568. unsigned char shortHash[] = TEST_STRING;
  23569. word32 hashlen = sizeof(hash);
  23570. word32 iHashLen = sizeof(iHash);
  23571. word32 shortHashLen = sizeof(shortHash);
  23572. int keySz = KEY32;
  23573. int verify_ok = 0;
  23574. XMEMSET(&key, 0, sizeof(ecc_key));
  23575. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23576. XMEMSET(&r, 0, sizeof(mp_int));
  23577. XMEMSET(&s, 0, sizeof(mp_int));
  23578. XMEMSET(&z, 0, sizeof(mp_int));
  23579. /* Initialize r, s and z. */
  23580. ExpectIntEQ(mp_init_multi(&r, &s, &z, NULL, NULL, NULL), MP_OKAY);
  23581. ExpectIntEQ(wc_ecc_init(&key), 0);
  23582. ExpectIntEQ(wc_InitRng(&rng), 0);
  23583. ret = wc_ecc_make_key(&rng, keySz, &key);
  23584. #if defined(WOLFSSL_ASYNC_CRYPT)
  23585. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  23586. #endif
  23587. ExpectIntEQ(ret, 0);
  23588. ExpectIntEQ(wc_ecc_sign_hash_ex(hash, hashlen, &rng, &key, &r, &s), 0);
  23589. /* verify_ok should be 1. */
  23590. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, hash, hashlen, &verify_ok, &key),
  23591. 0);
  23592. ExpectIntEQ(verify_ok, 1);
  23593. /* verify_ok should be 0 */
  23594. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, iHash, iHashLen, &verify_ok,
  23595. &key), 0);
  23596. ExpectIntEQ(verify_ok, 0);
  23597. /* verify_ok should be 0. */
  23598. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, shortHash, shortHashLen,
  23599. &verify_ok, &key), 0);
  23600. ExpectIntEQ(verify_ok, 0);
  23601. /* Test bad args. */
  23602. ExpectIntEQ(wc_ecc_sign_hash_ex(NULL, hashlen, &rng, &key, &r, &s),
  23603. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23604. ExpectIntEQ(wc_ecc_sign_hash_ex(hash, hashlen, NULL, &key, &r, &s),
  23605. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23606. ExpectIntEQ(wc_ecc_sign_hash_ex(hash, hashlen, &rng, NULL, &r, &s),
  23607. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23608. ExpectIntEQ(wc_ecc_sign_hash_ex(hash, hashlen, &rng, &key, NULL, &s),
  23609. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23610. ExpectIntEQ(wc_ecc_sign_hash_ex(hash, hashlen, &rng, &key, &r, NULL),
  23611. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23612. /* Test bad args. */
  23613. ExpectIntEQ(wc_ecc_verify_hash_ex(NULL, &s, shortHash, shortHashLen,
  23614. &verify_ok, &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23615. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, NULL, shortHash, shortHashLen,
  23616. &verify_ok, &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23617. ExpectIntEQ(wc_ecc_verify_hash_ex(&z, &s, shortHash, shortHashLen,
  23618. &verify_ok, &key), WC_NO_ERR_TRACE(MP_ZERO_E));
  23619. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &z, shortHash, shortHashLen,
  23620. &verify_ok, &key), WC_NO_ERR_TRACE(MP_ZERO_E));
  23621. ExpectIntEQ(wc_ecc_verify_hash_ex(&z, &z, shortHash, shortHashLen,
  23622. &verify_ok, &key), WC_NO_ERR_TRACE(MP_ZERO_E));
  23623. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, NULL, shortHashLen, &verify_ok,
  23624. &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23625. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, shortHash, shortHashLen, NULL,
  23626. &key), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23627. ExpectIntEQ(wc_ecc_verify_hash_ex(&r, &s, shortHash, shortHashLen,
  23628. &verify_ok, NULL), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23629. wc_ecc_free(&key);
  23630. mp_free(&r);
  23631. mp_free(&s);
  23632. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23633. #endif
  23634. return EXPECT_RESULT();
  23635. } /* END test_wc_ecc_verify_hash_ex */
  23636. /*
  23637. * Testing wc_ecc_mulmod()
  23638. */
  23639. static int test_wc_ecc_mulmod(void)
  23640. {
  23641. EXPECT_DECLS;
  23642. #if defined(HAVE_ECC) && !defined(WC_NO_RNG) && \
  23643. !(defined(WOLFSSL_ATECC508A) || defined(WOLFSSL_ATECC608A) || \
  23644. defined(WOLFSSL_VALIDATE_ECC_IMPORT))
  23645. ecc_key key1;
  23646. ecc_key key2;
  23647. ecc_key key3;
  23648. WC_RNG rng;
  23649. int ret;
  23650. XMEMSET(&key1, 0, sizeof(ecc_key));
  23651. XMEMSET(&key2, 0, sizeof(ecc_key));
  23652. XMEMSET(&key3, 0, sizeof(ecc_key));
  23653. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23654. ExpectIntEQ(wc_ecc_init(&key1), 0);
  23655. ExpectIntEQ(wc_ecc_init(&key2), 0);
  23656. ExpectIntEQ(wc_ecc_init(&key3), 0);
  23657. ExpectIntEQ(wc_InitRng(&rng), 0);
  23658. ret = wc_ecc_make_key(&rng, KEY32, &key1);
  23659. #if defined(WOLFSSL_ASYNC_CRYPT)
  23660. ret = wc_AsyncWait(ret, &key1.asyncDev, WC_ASYNC_FLAG_NONE);
  23661. #endif
  23662. ExpectIntEQ(ret, 0);
  23663. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23664. ExpectIntEQ(wc_ecc_import_raw_ex(&key2, key1.dp->Gx, key1.dp->Gy,
  23665. key1.dp->Af, ECC_SECP256R1), 0);
  23666. ExpectIntEQ(wc_ecc_import_raw_ex(&key3, key1.dp->Gx, key1.dp->Gy,
  23667. key1.dp->prime, ECC_SECP256R1), 0);
  23668. ExpectIntEQ(wc_ecc_mulmod(wc_ecc_key_get_priv(&key1), &key2.pubkey,
  23669. &key3.pubkey, wc_ecc_key_get_priv(&key2), wc_ecc_key_get_priv(&key3),
  23670. 1), 0);
  23671. /* Test bad args. */
  23672. ExpectIntEQ(ret = wc_ecc_mulmod(NULL, &key2.pubkey, &key3.pubkey,
  23673. wc_ecc_key_get_priv(&key2), wc_ecc_key_get_priv(&key3), 1),
  23674. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23675. ExpectIntEQ(wc_ecc_mulmod(wc_ecc_key_get_priv(&key1), NULL, &key3.pubkey,
  23676. wc_ecc_key_get_priv(&key2), wc_ecc_key_get_priv(&key3), 1),
  23677. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23678. ExpectIntEQ(wc_ecc_mulmod(wc_ecc_key_get_priv(&key1), &key2.pubkey, NULL,
  23679. wc_ecc_key_get_priv(&key2), wc_ecc_key_get_priv(&key3), 1),
  23680. WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23681. ExpectIntEQ(wc_ecc_mulmod(wc_ecc_key_get_priv(&key1), &key2.pubkey,
  23682. &key3.pubkey, wc_ecc_key_get_priv(&key2), NULL, 1), WC_NO_ERR_TRACE(ECC_BAD_ARG_E));
  23683. wc_ecc_free(&key1);
  23684. wc_ecc_free(&key2);
  23685. wc_ecc_free(&key3);
  23686. #ifdef FP_ECC
  23687. wc_ecc_fp_free();
  23688. #endif
  23689. #endif /* HAVE_ECC && !WOLFSSL_ATECC508A */
  23690. return EXPECT_RESULT();
  23691. } /* END test_wc_ecc_mulmod */
  23692. /*
  23693. * Testing wc_ecc_is_valid_idx()
  23694. */
  23695. static int test_wc_ecc_is_valid_idx(void)
  23696. {
  23697. EXPECT_DECLS;
  23698. #if defined(HAVE_ECC) && !defined(WC_NO_RNG)
  23699. ecc_key key;
  23700. WC_RNG rng;
  23701. int ret;
  23702. int iVal = -2;
  23703. int iVal2 = 3000;
  23704. XMEMSET(&key, 0, sizeof(ecc_key));
  23705. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23706. ExpectIntEQ(wc_ecc_init(&key), 0);
  23707. ExpectIntEQ(wc_InitRng(&rng), 0);
  23708. ret = wc_ecc_make_key(&rng, 32, &key);
  23709. #if defined(WOLFSSL_ASYNC_CRYPT)
  23710. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  23711. #endif
  23712. ExpectIntEQ(ret, 0);
  23713. ExpectIntEQ(wc_ecc_is_valid_idx(key.idx), 1);
  23714. /* Test bad args. */
  23715. ExpectIntEQ(wc_ecc_is_valid_idx(iVal), 0);
  23716. ExpectIntEQ(wc_ecc_is_valid_idx(iVal2), 0);
  23717. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23718. wc_ecc_free(&key);
  23719. #ifdef FP_ECC
  23720. wc_ecc_fp_free();
  23721. #endif
  23722. #endif
  23723. return EXPECT_RESULT();
  23724. } /* END test_wc_ecc_is_valid_idx */
  23725. /*
  23726. * Testing wc_ecc_get_curve_id_from_oid()
  23727. */
  23728. static int test_wc_ecc_get_curve_id_from_oid(void)
  23729. {
  23730. EXPECT_DECLS;
  23731. #if defined(HAVE_ECC) && !defined(NO_ECC256) && !defined(HAVE_SELFTEST) && \
  23732. !defined(HAVE_FIPS)
  23733. const byte oid[] = {0x2A,0x86,0x48,0xCE,0x3D,0x03,0x01,0x07};
  23734. word32 len = sizeof(oid);
  23735. /* Bad Cases */
  23736. ExpectIntEQ(wc_ecc_get_curve_id_from_oid(NULL, len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23737. ExpectIntEQ(wc_ecc_get_curve_id_from_oid(oid, 0), ECC_CURVE_INVALID);
  23738. /* Good Case */
  23739. ExpectIntEQ(wc_ecc_get_curve_id_from_oid(oid, len), ECC_SECP256R1);
  23740. #endif
  23741. return EXPECT_RESULT();
  23742. } /* END test_wc_ecc_get_curve_id_from_oid */
  23743. /*
  23744. * Testing wc_ecc_sig_size_calc()
  23745. */
  23746. static int test_wc_ecc_sig_size_calc(void)
  23747. {
  23748. EXPECT_DECLS;
  23749. #if defined(HAVE_ECC) && !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST)
  23750. ecc_key key;
  23751. WC_RNG rng;
  23752. int sz = 0;
  23753. int ret;
  23754. XMEMSET(&key, 0, sizeof(ecc_key));
  23755. XMEMSET(&rng, 0, sizeof(WC_RNG));
  23756. ExpectIntEQ(wc_ecc_init(&key), 0);
  23757. ExpectIntEQ(wc_InitRng(&rng), 0);
  23758. ret = wc_ecc_make_key(&rng, 16, &key);
  23759. #if defined(WOLFSSL_ASYNC_CRYPT)
  23760. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_NONE);
  23761. #endif
  23762. #if FIPS_VERSION3_GE(6,0,0)
  23763. ExpectIntEQ(ret, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23764. #else
  23765. ExpectIntEQ(ret, 0);
  23766. #endif
  23767. #if FIPS_VERSION3_LT(6,0,0)
  23768. sz = key.dp->size;
  23769. ExpectIntGT(wc_ecc_sig_size_calc(sz), 0);
  23770. #else
  23771. (void) sz;
  23772. #endif
  23773. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  23774. wc_ecc_free(&key);
  23775. #endif
  23776. return EXPECT_RESULT();
  23777. } /* END test_wc_ecc_sig_size_calc */
  23778. /*
  23779. * Testing wc_ecc_sm2_make_key()
  23780. */
  23781. static int test_wc_ecc_sm2_make_key(void)
  23782. {
  23783. int res = TEST_SKIPPED;
  23784. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2)
  23785. EXPECT_DECLS;
  23786. WC_RNG rng[1];
  23787. ecc_key key[1];
  23788. XMEMSET(rng, 0, sizeof(*rng));
  23789. XMEMSET(key, 0, sizeof(*key));
  23790. ExpectIntEQ(wc_InitRng(rng), 0);
  23791. ExpectIntEQ(wc_ecc_init(key), 0);
  23792. /* Test invalid parameters. */
  23793. ExpectIntEQ(wc_ecc_sm2_make_key(NULL, NULL, WC_ECC_FLAG_NONE),
  23794. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23795. ExpectIntEQ(wc_ecc_sm2_make_key(rng, NULL, WC_ECC_FLAG_NONE),
  23796. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23797. ExpectIntEQ(wc_ecc_sm2_make_key(NULL, key, WC_ECC_FLAG_NONE),
  23798. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23799. /* Test valid parameters. */
  23800. ExpectIntEQ(wc_ecc_sm2_make_key(rng, key, WC_ECC_FLAG_NONE), 0);
  23801. ExpectIntEQ(key->dp->id, ECC_SM2P256V1);
  23802. wc_ecc_free(key);
  23803. wc_FreeRng(rng);
  23804. #ifdef FP_ECC
  23805. wc_ecc_fp_free();
  23806. #endif
  23807. res = EXPECT_RESULT();
  23808. #endif
  23809. return res;
  23810. }
  23811. /*
  23812. * Testing wc_ecc_sm2_shared_secret()
  23813. */
  23814. static int test_wc_ecc_sm2_shared_secret(void)
  23815. {
  23816. int res = TEST_SKIPPED;
  23817. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2)
  23818. EXPECT_DECLS;
  23819. WC_RNG rng[1];
  23820. ecc_key keyA[1];
  23821. ecc_key keyB[1];
  23822. byte outA[32];
  23823. byte outB[32];
  23824. word32 outALen = 32;
  23825. word32 outBLen = 32;
  23826. XMEMSET(rng, 0, sizeof(*rng));
  23827. XMEMSET(keyA, 0, sizeof(*keyA));
  23828. XMEMSET(keyB, 0, sizeof(*keyB));
  23829. ExpectIntEQ(wc_InitRng(rng), 0);
  23830. ExpectIntEQ(wc_ecc_init(keyA), 0);
  23831. ExpectIntEQ(wc_ecc_init(keyB), 0);
  23832. ExpectIntEQ(wc_ecc_sm2_make_key(rng, keyA, WC_ECC_FLAG_NONE), 0);
  23833. ExpectIntEQ(wc_ecc_sm2_make_key(rng, keyB, WC_ECC_FLAG_NONE), 0);
  23834. #ifdef ECC_TIMING_RESISTANT
  23835. ExpectIntEQ(wc_ecc_set_rng(keyA, rng), 0);
  23836. ExpectIntEQ(wc_ecc_set_rng(keyB, rng), 0);
  23837. #endif
  23838. /* Test invalid parameters. */
  23839. ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23840. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, NULL, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23841. ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, keyB, NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23842. ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, NULL, outA, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23843. ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, NULL, NULL, &outALen),
  23844. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23845. ExpectIntEQ(wc_ecc_sm2_shared_secret(NULL, keyB, outA, &outALen),
  23846. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23847. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, NULL, outA, &outALen),
  23848. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23849. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, keyB, NULL, &outALen),
  23850. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23851. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, keyB, outA, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23852. /* Test valid parameters. */
  23853. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyA, keyB, outA, &outALen), 0);
  23854. ExpectIntLE(outALen, 32);
  23855. ExpectIntEQ(wc_ecc_sm2_shared_secret(keyB, keyA, outB, &outBLen), 0);
  23856. ExpectIntLE(outBLen, 32);
  23857. ExpectIntEQ(outALen, outBLen);
  23858. ExpectBufEQ(outA, outB, outALen);
  23859. wc_ecc_free(keyB);
  23860. wc_ecc_free(keyA);
  23861. wc_FreeRng(rng);
  23862. #ifdef FP_ECC
  23863. wc_ecc_fp_free();
  23864. #endif
  23865. res = EXPECT_RESULT();
  23866. #endif
  23867. return res;
  23868. }
  23869. /*
  23870. * Testing wc_ecc_sm2_create_digest()
  23871. */
  23872. static int test_wc_ecc_sm2_create_digest(void)
  23873. {
  23874. int res = TEST_SKIPPED;
  23875. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && !defined(NO_HASH_WRAPPER) && \
  23876. (defined(WOLFSSL_SM3) || !defined(NO_SHA256))
  23877. EXPECT_DECLS;
  23878. ecc_key key[1];
  23879. enum wc_HashType hashType;
  23880. unsigned char pub[] = {
  23881. 0x04,
  23882. 0x63, 0x7F, 0x1B, 0x13, 0x50, 0x36, 0xC9, 0x33,
  23883. 0xDC, 0x3F, 0x7A, 0x8E, 0xBB, 0x1B, 0x7B, 0x2F,
  23884. 0xD1, 0xDF, 0xBD, 0x26, 0x8D, 0x4F, 0x89, 0x4B,
  23885. 0x5A, 0xD4, 0x7D, 0xBD, 0xBE, 0xCD, 0x55, 0x8F,
  23886. 0xE8, 0x81, 0x01, 0xD0, 0x80, 0x48, 0xE3, 0x6C,
  23887. 0xCB, 0xF6, 0x1C, 0xA3, 0x8D, 0xDF, 0x7A, 0xBA,
  23888. 0x54, 0x2B, 0x44, 0x86, 0xE9, 0x9E, 0x49, 0xF3,
  23889. 0xA7, 0x47, 0x0A, 0x85, 0x7A, 0x09, 0x64, 0x33
  23890. };
  23891. unsigned char id[] = {
  23892. 0x01, 0x02, 0x03,
  23893. };
  23894. unsigned char msg[] = {
  23895. 0x01, 0x02, 0x03,
  23896. };
  23897. unsigned char hash[32];
  23898. #ifdef WOLFSSL_SM3
  23899. unsigned char expHash[32] = {
  23900. 0xc1, 0xdd, 0x92, 0xc5, 0x60, 0xd3, 0x94, 0x28,
  23901. 0xeb, 0x0f, 0x57, 0x79, 0x3f, 0xc9, 0x96, 0xc5,
  23902. 0xfa, 0xf5, 0x90, 0xb2, 0x64, 0x2f, 0xaf, 0x9c,
  23903. 0xc8, 0x57, 0x21, 0x6a, 0x52, 0x7e, 0xf1, 0x95
  23904. };
  23905. #else
  23906. unsigned char expHash[32] = {
  23907. 0xea, 0x41, 0x55, 0x21, 0x61, 0x00, 0x5c, 0x9a,
  23908. 0x57, 0x35, 0x6b, 0x49, 0xca, 0x8f, 0x65, 0xc2,
  23909. 0x0e, 0x29, 0x0c, 0xa0, 0x1d, 0xa7, 0xc4, 0xed,
  23910. 0xdd, 0x51, 0x12, 0xf6, 0xe7, 0x55, 0xc5, 0xf4
  23911. };
  23912. #endif
  23913. #ifdef WOLFSSL_SM3
  23914. hashType = WC_HASH_TYPE_SM3;
  23915. #else
  23916. hashType = WC_HASH_TYPE_SHA256;
  23917. #endif
  23918. XMEMSET(key, 0, sizeof(*key));
  23919. ExpectIntEQ(wc_ecc_init(key), 0);
  23920. /* Test with no curve set. */
  23921. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23922. hashType, hash, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23923. ExpectIntEQ(wc_ecc_import_x963_ex(pub, sizeof(pub), key, ECC_SM2P256V1), 0);
  23924. /* Test invalid parameters. */
  23925. ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), NULL, sizeof(msg),
  23926. hashType, NULL, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23927. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), NULL, sizeof(msg),
  23928. hashType, NULL, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23929. ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), msg, sizeof(msg),
  23930. hashType, NULL, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23931. ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), NULL, sizeof(msg),
  23932. hashType, hash, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23933. ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), NULL, sizeof(msg),
  23934. hashType, NULL, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23935. ExpectIntEQ(wc_ecc_sm2_create_digest(NULL, sizeof(id), msg, sizeof(msg),
  23936. hashType, hash, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23937. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), NULL, sizeof(msg),
  23938. hashType, hash, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23939. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23940. hashType, NULL, sizeof(hash), key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23941. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23942. hashType, hash, sizeof(hash), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23943. /* Bad hash type. */
  23944. /* // NOLINTBEGIN(clang-analyzer-optin.core.EnumCastOutOfRange) */
  23945. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23946. -1, hash, 0, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  23947. /* // NOLINTEND(clang-analyzer-optin.core.EnumCastOutOfRange) */
  23948. /* Bad hash size. */
  23949. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23950. hashType, hash, 0, key), WC_NO_ERR_TRACE(BUFFER_E));
  23951. /* Test valid parameters. */
  23952. ExpectIntEQ(wc_ecc_sm2_create_digest(id, sizeof(id), msg, sizeof(msg),
  23953. hashType, hash, sizeof(hash), key), 0);
  23954. ExpectBufEQ(hash, expHash, sizeof(expHash));
  23955. wc_ecc_free(key);
  23956. res = EXPECT_RESULT();
  23957. #endif
  23958. return res;
  23959. }
  23960. /*
  23961. * Testing wc_ecc_sm2_verify_hash_ex()
  23962. */
  23963. static int test_wc_ecc_sm2_verify_hash_ex(void)
  23964. {
  23965. int res = TEST_SKIPPED;
  23966. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && defined(HAVE_ECC_VERIFY) && \
  23967. defined(WOLFSSL_PUBLIC_MP)
  23968. EXPECT_DECLS;
  23969. ecc_key key[1];
  23970. mp_int r[1];
  23971. mp_int s[1];
  23972. int verified;
  23973. unsigned char pub[] = {
  23974. 0x04,
  23975. 0x63, 0x7F, 0x1B, 0x13, 0x50, 0x36, 0xC9, 0x33,
  23976. 0xDC, 0x3F, 0x7A, 0x8E, 0xBB, 0x1B, 0x7B, 0x2F,
  23977. 0xD1, 0xDF, 0xBD, 0x26, 0x8D, 0x4F, 0x89, 0x4B,
  23978. 0x5A, 0xD4, 0x7D, 0xBD, 0xBE, 0xCD, 0x55, 0x8F,
  23979. 0xE8, 0x81, 0x01, 0xD0, 0x80, 0x48, 0xE3, 0x6C,
  23980. 0xCB, 0xF6, 0x1C, 0xA3, 0x8D, 0xDF, 0x7A, 0xBA,
  23981. 0x54, 0x2B, 0x44, 0x86, 0xE9, 0x9E, 0x49, 0xF3,
  23982. 0xA7, 0x47, 0x0A, 0x85, 0x7A, 0x09, 0x64, 0x33
  23983. };
  23984. unsigned char hash[] = {
  23985. 0x3B, 0xFA, 0x5F, 0xFB, 0xC4, 0x27, 0x8C, 0x9D,
  23986. 0x02, 0x3A, 0x19, 0xCB, 0x1E, 0xAA, 0xD2, 0xF1,
  23987. 0x50, 0x69, 0x5B, 0x20
  23988. };
  23989. unsigned char rData[] = {
  23990. 0xD2, 0xFC, 0xA3, 0x88, 0xE3, 0xDF, 0xA3, 0x00,
  23991. 0x73, 0x9B, 0x3C, 0x2A, 0x0D, 0xAD, 0x44, 0xA2,
  23992. 0xFC, 0x62, 0xD5, 0x6B, 0x84, 0x54, 0xD8, 0x40,
  23993. 0x22, 0x62, 0x3D, 0x5C, 0xA6, 0x61, 0x9B, 0xE7,
  23994. };
  23995. unsigned char sData[] = {
  23996. 0x1D,
  23997. 0xB5, 0xB5, 0xD9, 0xD8, 0xF1, 0x20, 0xDD, 0x97,
  23998. 0x92, 0xBF, 0x7E, 0x9B, 0x3F, 0xE6, 0x3C, 0x4B,
  23999. 0x03, 0xD8, 0x80, 0xBD, 0xB7, 0x27, 0x7E, 0x6A,
  24000. 0x84, 0x23, 0xDE, 0x61, 0x7C, 0x8D, 0xDC
  24001. };
  24002. unsigned char rBadData[] = {
  24003. 0xD2, 0xFC, 0xA3, 0x88, 0xE3, 0xDF, 0xA3, 0x00,
  24004. 0x73, 0x9B, 0x3C, 0x2A, 0x0D, 0xAD, 0x44, 0xA2,
  24005. 0xFC, 0x62, 0xD5, 0x6B, 0x84, 0x54, 0xD8, 0x40,
  24006. 0x22, 0x62, 0x3D, 0x5C, 0xA6, 0x61, 0x9B, 0xE8,
  24007. };
  24008. XMEMSET(key, 0, sizeof(*key));
  24009. XMEMSET(r, 0, sizeof(*r));
  24010. XMEMSET(s, 0, sizeof(*s));
  24011. ExpectIntEQ(mp_init(r), 0);
  24012. ExpectIntEQ(mp_init(s), 0);
  24013. ExpectIntEQ(mp_read_unsigned_bin(r, rData, sizeof(rData)), 0);
  24014. ExpectIntEQ(mp_read_unsigned_bin(s, sData, sizeof(sData)), 0);
  24015. ExpectIntEQ(wc_ecc_init(key), 0);
  24016. /* Test with no curve set. */
  24017. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  24018. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24019. ExpectIntEQ(wc_ecc_import_x963_ex(pub, sizeof(pub), key, ECC_SM2P256V1), 0);
  24020. /* Test invalid parameters. */
  24021. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, NULL, NULL, sizeof(hash),
  24022. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24023. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, NULL, NULL, sizeof(hash),
  24024. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24025. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, s, NULL, sizeof(hash),
  24026. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24027. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, NULL, hash, sizeof(hash),
  24028. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24029. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, NULL, NULL, sizeof(hash),
  24030. &verified, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24031. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, NULL, NULL, sizeof(hash),
  24032. NULL, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24033. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(NULL, s, hash, sizeof(hash),
  24034. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24035. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, NULL, hash, sizeof(hash),
  24036. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24037. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, NULL, sizeof(hash),
  24038. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24039. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  24040. NULL, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24041. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  24042. &verified, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24043. /* Make key not on the SM2 curve. */
  24044. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SECP256R1), 0);
  24045. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  24046. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24047. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SM2P256V1), 0);
  24048. /* Test valid parameters. */
  24049. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  24050. &verified, key), 0);
  24051. ExpectIntEQ(verified, 1);
  24052. ExpectIntEQ(mp_read_unsigned_bin(r, rBadData, sizeof(rBadData)), 0);
  24053. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash),
  24054. &verified, key), 0);
  24055. ExpectIntEQ(verified, 0);
  24056. mp_free(s);
  24057. mp_free(r);
  24058. wc_ecc_free(key);
  24059. #ifdef FP_ECC
  24060. wc_ecc_fp_free();
  24061. #endif
  24062. res = EXPECT_RESULT();
  24063. #endif
  24064. return res;
  24065. }
  24066. /*
  24067. * Testing wc_ecc_sm2_verify_hash()
  24068. */
  24069. static int test_wc_ecc_sm2_verify_hash(void)
  24070. {
  24071. int res = TEST_SKIPPED;
  24072. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && defined(HAVE_ECC_VERIFY)
  24073. EXPECT_DECLS;
  24074. ecc_key key[1];
  24075. int verified;
  24076. unsigned char pub[] = {
  24077. 0x04,
  24078. 0x63, 0x7F, 0x1B, 0x13, 0x50, 0x36, 0xC9, 0x33,
  24079. 0xDC, 0x3F, 0x7A, 0x8E, 0xBB, 0x1B, 0x7B, 0x2F,
  24080. 0xD1, 0xDF, 0xBD, 0x26, 0x8D, 0x4F, 0x89, 0x4B,
  24081. 0x5A, 0xD4, 0x7D, 0xBD, 0xBE, 0xCD, 0x55, 0x8F,
  24082. 0xE8, 0x81, 0x01, 0xD0, 0x80, 0x48, 0xE3, 0x6C,
  24083. 0xCB, 0xF6, 0x1C, 0xA3, 0x8D, 0xDF, 0x7A, 0xBA,
  24084. 0x54, 0x2B, 0x44, 0x86, 0xE9, 0x9E, 0x49, 0xF3,
  24085. 0xA7, 0x47, 0x0A, 0x85, 0x7A, 0x09, 0x64, 0x33
  24086. };
  24087. unsigned char hash[] = {
  24088. 0x3B, 0xFA, 0x5F, 0xFB, 0xC4, 0x27, 0x8C, 0x9D,
  24089. 0x02, 0x3A, 0x19, 0xCB, 0x1E, 0xAA, 0xD2, 0xF1,
  24090. 0x50, 0x69, 0x5B, 0x20
  24091. };
  24092. unsigned char sig[] = {
  24093. 0x30, 0x45, 0x02, 0x21, 0x00, 0xD2, 0xFC, 0xA3,
  24094. 0x88, 0xE3, 0xDF, 0xA3, 0x00, 0x73, 0x9B, 0x3C,
  24095. 0x2A, 0x0D, 0xAD, 0x44, 0xA2, 0xFC, 0x62, 0xD5,
  24096. 0x6B, 0x84, 0x54, 0xD8, 0x40, 0x22, 0x62, 0x3D,
  24097. 0x5C, 0xA6, 0x61, 0x9B, 0xE7, 0x02, 0x20, 0x1D,
  24098. 0xB5, 0xB5, 0xD9, 0xD8, 0xF1, 0x20, 0xDD, 0x97,
  24099. 0x92, 0xBF, 0x7E, 0x9B, 0x3F, 0xE6, 0x3C, 0x4B,
  24100. 0x03, 0xD8, 0x80, 0xBD, 0xB7, 0x27, 0x7E, 0x6A,
  24101. 0x84, 0x23, 0xDE, 0x61, 0x7C, 0x8D, 0xDC
  24102. };
  24103. unsigned char sigBad[] = {
  24104. 0x30, 0x45, 0x02, 0x21, 0x00, 0xD2, 0xFC, 0xA3,
  24105. 0x88, 0xE3, 0xDF, 0xA3, 0x00, 0x73, 0x9B, 0x3C,
  24106. 0x2A, 0x0D, 0xAD, 0x44, 0xA2, 0xFC, 0x62, 0xD5,
  24107. 0x6B, 0x84, 0x54, 0xD8, 0x40, 0x22, 0x62, 0x3D,
  24108. 0x5C, 0xA6, 0x61, 0x9B, 0xE7, 0x02, 0x20, 0x1D,
  24109. 0xB5, 0xB5, 0xD9, 0xD8, 0xF1, 0x20, 0xDD, 0x97,
  24110. 0x92, 0xBF, 0x7E, 0x9B, 0x3F, 0xE6, 0x3C, 0x4B,
  24111. 0x03, 0xD8, 0x80, 0xBD, 0xB7, 0x27, 0x7E, 0x6A,
  24112. 0x84, 0x23, 0xDE, 0x61, 0x7C, 0x8D, 0xDD
  24113. };
  24114. XMEMSET(key, 0, sizeof(*key));
  24115. ExpectIntEQ(wc_ecc_init(key), 0);
  24116. /* Test with no curve set. */
  24117. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
  24118. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24119. ExpectIntEQ(wc_ecc_import_x963_ex(pub, sizeof(pub), key, ECC_SM2P256V1), 0);
  24120. /* Test invalid parameters. */
  24121. ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), NULL, sizeof(hash),
  24122. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24123. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), NULL, sizeof(hash),
  24124. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24125. ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), hash, sizeof(hash),
  24126. NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24127. ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), NULL, sizeof(hash),
  24128. &verified, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24129. ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), NULL, sizeof(hash),
  24130. NULL, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24131. ExpectIntEQ(wc_ecc_sm2_verify_hash(NULL, sizeof(sig), hash, sizeof(hash),
  24132. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24133. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), NULL, sizeof(hash),
  24134. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24135. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
  24136. NULL, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24137. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
  24138. &verified, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24139. /* Make key not on the SM2 curve. */
  24140. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SECP256R1), 0);
  24141. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
  24142. &verified, key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24143. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SM2P256V1), 0);
  24144. /* Test valid parameters. */
  24145. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
  24146. &verified, key), 0);
  24147. ExpectIntEQ(verified, 1);
  24148. ExpectIntEQ(wc_ecc_sm2_verify_hash(sigBad, sizeof(sigBad), hash,
  24149. sizeof(hash), &verified, key), 0);
  24150. ExpectIntEQ(verified, 0);
  24151. wc_ecc_free(key);
  24152. #ifdef FP_ECC
  24153. wc_ecc_fp_free();
  24154. #endif
  24155. res = EXPECT_RESULT();
  24156. #endif
  24157. return res;
  24158. }
  24159. /*
  24160. * Testing wc_ecc_sm2_verify_hash_ex()
  24161. */
  24162. static int test_wc_ecc_sm2_sign_hash_ex(void)
  24163. {
  24164. int res = TEST_SKIPPED;
  24165. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && defined(HAVE_ECC_SIGN) && \
  24166. defined(WOLFSSL_PUBLIC_MP)
  24167. EXPECT_DECLS;
  24168. WC_RNG rng[1];
  24169. ecc_key key[1];
  24170. mp_int r[1];
  24171. mp_int s[1];
  24172. unsigned char hash[32];
  24173. #ifdef HAVE_ECC_VERIFY
  24174. int verified;
  24175. #endif
  24176. XMEMSET(rng, 0, sizeof(*rng));
  24177. XMEMSET(key, 0, sizeof(*key));
  24178. XMEMSET(r, 0, sizeof(*r));
  24179. XMEMSET(s, 0, sizeof(*s));
  24180. ExpectIntEQ(wc_InitRng(rng), 0);
  24181. ExpectIntEQ(mp_init(r), 0);
  24182. ExpectIntEQ(mp_init(s), 0);
  24183. ExpectIntEQ(wc_RNG_GenerateBlock(rng, hash, sizeof(hash)), 0);
  24184. ExpectIntEQ(wc_ecc_init(key), 0);
  24185. /* Test with no curve set. */
  24186. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, r, s),
  24187. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24188. ExpectIntEQ(wc_ecc_sm2_make_key(rng, key, WC_ECC_FLAG_NONE), 0);
  24189. /* Test invalid parameters. */
  24190. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), NULL, NULL, NULL,
  24191. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24192. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), NULL, NULL, NULL,
  24193. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24194. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), rng, NULL, NULL,
  24195. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24196. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), NULL, key, NULL,
  24197. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24198. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), NULL, NULL, r,
  24199. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24200. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), NULL, NULL, NULL,
  24201. s), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24202. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(NULL, sizeof(hash), rng, key, r, s),
  24203. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24204. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), NULL, key, r, s),
  24205. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24206. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, NULL, r, s),
  24207. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24208. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, NULL, s),
  24209. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24210. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, r, NULL),
  24211. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24212. /* Make key not on the SM2 curve. */
  24213. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SECP256R1), 0);
  24214. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, r, s),
  24215. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24216. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SM2P256V1), 0);
  24217. #ifdef WOLFSSL_SP_MATH_ALL
  24218. {
  24219. mp_int smallR[1];
  24220. sp_init_size(smallR, 1);
  24221. /* Force failure in _ecc_sm2_calc_r_s by r being too small. */
  24222. ExpectIntLT(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key,
  24223. smallR, s), 0);
  24224. }
  24225. #endif
  24226. /* Test valid parameters. */
  24227. ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, r, s),
  24228. 0);
  24229. #ifdef HAVE_ECC_VERIFY
  24230. ExpectIntEQ(wc_ecc_sm2_verify_hash_ex(r, s, hash, sizeof(hash), &verified,
  24231. key), 0);
  24232. ExpectIntEQ(verified, 1);
  24233. #endif
  24234. mp_free(s);
  24235. mp_free(r);
  24236. wc_ecc_free(key);
  24237. wc_FreeRng(rng);
  24238. #ifdef FP_ECC
  24239. wc_ecc_fp_free();
  24240. #endif
  24241. res = EXPECT_RESULT();
  24242. #endif
  24243. return res;
  24244. }
  24245. /*
  24246. * Testing wc_ecc_sm2_verify_hash()
  24247. */
  24248. static int test_wc_ecc_sm2_sign_hash(void)
  24249. {
  24250. int res = TEST_SKIPPED;
  24251. #if defined(HAVE_ECC) && defined(WOLFSSL_SM2) && defined(HAVE_ECC_SIGN)
  24252. EXPECT_DECLS;
  24253. WC_RNG rng[1];
  24254. ecc_key key[1];
  24255. unsigned char hash[32];
  24256. unsigned char sig[72];
  24257. word32 sigSz = sizeof(sig);
  24258. #ifdef HAVE_ECC_VERIFY
  24259. int verified;
  24260. #endif
  24261. XMEMSET(rng, 0, sizeof(*rng));
  24262. XMEMSET(key, 0, sizeof(*key));
  24263. ExpectIntEQ(wc_InitRng(rng), 0);
  24264. ExpectIntEQ(wc_RNG_GenerateBlock(rng, hash, sizeof(hash)), 0);
  24265. ExpectIntEQ(wc_ecc_init(key), 0);
  24266. /* Test with no curve set. */
  24267. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key),
  24268. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24269. ExpectIntEQ(wc_ecc_sm2_make_key(rng, key, WC_ECC_FLAG_NONE), 0);
  24270. /* Test invalid parameters. */
  24271. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), NULL, NULL, NULL,
  24272. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24273. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), NULL, NULL, NULL,
  24274. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24275. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), sig, NULL, NULL,
  24276. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24277. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), NULL, &sigSz, NULL,
  24278. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24279. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), NULL, NULL, rng,
  24280. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24281. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), NULL, NULL, NULL,
  24282. key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24283. ExpectIntEQ(wc_ecc_sm2_sign_hash(NULL, sizeof(hash), sig, &sigSz, rng,
  24284. key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24285. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), NULL, &sigSz, rng,
  24286. key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24287. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, NULL, rng,
  24288. key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24289. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, NULL,
  24290. key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24291. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, rng,
  24292. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24293. /* Make key not on the SM2 curve. */
  24294. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SECP256R1), 0);
  24295. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key),
  24296. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24297. ExpectIntEQ(wc_ecc_set_curve(key, 32, ECC_SM2P256V1), 0);
  24298. /* Test valid parameters. */
  24299. ExpectIntEQ(wc_ecc_sm2_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key),
  24300. 0);
  24301. #ifdef HAVE_ECC_VERIFY
  24302. ExpectIntEQ(wc_ecc_sm2_verify_hash(sig, sigSz, hash, sizeof(hash),
  24303. &verified, key), 0);
  24304. ExpectIntEQ(verified, 1);
  24305. #endif
  24306. wc_ecc_free(key);
  24307. wc_FreeRng(rng);
  24308. #ifdef FP_ECC
  24309. wc_ecc_fp_free();
  24310. #endif
  24311. res = EXPECT_RESULT();
  24312. #endif
  24313. return res;
  24314. }
  24315. /*
  24316. * Testing ToTraditional
  24317. */
  24318. static int test_ToTraditional(void)
  24319. {
  24320. EXPECT_DECLS;
  24321. #if !defined(NO_ASN) && (defined(HAVE_PKCS8) || defined(HAVE_PKCS12)) && \
  24322. (defined(WOLFSSL_TEST_CERT) || defined(OPENSSL_EXTRA) || \
  24323. defined(OPENSSL_EXTRA_X509_SMALL)) && !defined(NO_FILESYSTEM)
  24324. XFILE f = XBADFILE;
  24325. byte input[TWOK_BUF];
  24326. word32 sz = 0;
  24327. ExpectTrue((f = XFOPEN("./certs/server-keyPkcs8.der", "rb")) != XBADFILE);
  24328. ExpectTrue((sz = (word32)XFREAD(input, 1, sizeof(input), f)) > 0);
  24329. if (f != XBADFILE)
  24330. XFCLOSE(f);
  24331. /* Good case */
  24332. ExpectIntGT(ToTraditional(input, sz), 0);
  24333. /* Bad cases */
  24334. ExpectIntEQ(ToTraditional(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24335. ExpectIntEQ(ToTraditional(NULL, sz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24336. #ifdef WOLFSSL_ASN_TEMPLATE
  24337. ExpectIntEQ(ToTraditional(input, 0), WC_NO_ERR_TRACE(BUFFER_E));
  24338. #else
  24339. ExpectIntEQ(ToTraditional(input, 0), WC_NO_ERR_TRACE(ASN_PARSE_E));
  24340. #endif
  24341. #endif
  24342. return EXPECT_RESULT();
  24343. } /* End test_ToTraditional*/
  24344. /*
  24345. * Testing wc_EccPrivateKeyToDer
  24346. */
  24347. static int test_wc_EccPrivateKeyToDer(void)
  24348. {
  24349. EXPECT_DECLS;
  24350. #if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  24351. byte output[ONEK_BUF];
  24352. ecc_key eccKey;
  24353. WC_RNG rng;
  24354. word32 inLen = 0;
  24355. word32 outLen = 0;
  24356. int ret;
  24357. XMEMSET(&eccKey, 0, sizeof(ecc_key));
  24358. XMEMSET(&rng, 0, sizeof(WC_RNG));
  24359. PRIVATE_KEY_UNLOCK();
  24360. ExpectIntEQ(wc_InitRng(&rng), 0);
  24361. ExpectIntEQ(wc_ecc_init(&eccKey), 0);
  24362. ret = wc_ecc_make_key(&rng, KEY14, &eccKey);
  24363. #if defined(WOLFSSL_ASYNC_CRYPT)
  24364. ret = wc_AsyncWait(ret, &eccKey.asyncDev, WC_ASYNC_FLAG_NONE);
  24365. #endif
  24366. ExpectIntEQ(ret, 0);
  24367. /* Bad Cases */
  24368. ExpectIntEQ(wc_EccPrivateKeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24369. ExpectIntEQ(wc_EccPrivateKeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24370. inLen = wc_EccPrivateKeyToDer(&eccKey, NULL, 0);
  24371. ExpectIntGT(inLen, 0);
  24372. ExpectIntEQ(wc_EccPrivateKeyToDer(&eccKey, output, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24373. /* Good Case */
  24374. ExpectIntGT(outLen = (word32)wc_EccPrivateKeyToDer(&eccKey, output, inLen), 0);
  24375. wc_ecc_free(&eccKey);
  24376. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  24377. #if defined(OPENSSL_EXTRA) && defined(HAVE_ALL_CURVES)
  24378. {
  24379. /* test importing private only into a PKEY struct */
  24380. EC_KEY* ec = NULL;
  24381. EVP_PKEY* pkey = NULL;
  24382. const unsigned char* der;
  24383. der = output;
  24384. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &der, outLen));
  24385. der = output;
  24386. ExpectNotNull(ec = d2i_ECPrivateKey(NULL, &der, outLen));
  24387. ExpectIntEQ(EVP_PKEY_assign_EC_KEY(pkey, ec), SSL_SUCCESS);
  24388. if (EXPECT_FAIL()) {
  24389. EC_KEY_free(ec);
  24390. }
  24391. EVP_PKEY_free(pkey); /* EC_KEY should be free'd by free'ing pkey */
  24392. }
  24393. #endif
  24394. PRIVATE_KEY_LOCK();
  24395. #endif
  24396. return EXPECT_RESULT();
  24397. } /* End test_wc_EccPrivateKeyToDer*/
  24398. /*
  24399. * Testing wc_DhPublicKeyDecode
  24400. */
  24401. static int test_wc_DhPublicKeyDecode(void)
  24402. {
  24403. EXPECT_DECLS;
  24404. #ifndef NO_DH
  24405. #if defined(WOLFSSL_DH_EXTRA) && defined(USE_CERT_BUFFERS_2048)
  24406. DhKey key;
  24407. word32 inOutIdx;
  24408. XMEMSET(&key, 0, sizeof(DhKey));
  24409. ExpectIntEQ(wc_InitDhKey(&key), 0);
  24410. ExpectIntEQ(wc_DhPublicKeyDecode(NULL,NULL,NULL,0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24411. ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,NULL,NULL,0),
  24412. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24413. ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,NULL,NULL,0),
  24414. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24415. inOutIdx = 0;
  24416. ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,&inOutIdx,NULL, 0),
  24417. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24418. inOutIdx = 0;
  24419. ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,&inOutIdx,&key, 0),
  24420. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24421. inOutIdx = 0;
  24422. ExpectIntEQ(wc_DhPublicKeyDecode(dh_pub_key_der_2048,&inOutIdx,&key,
  24423. sizeof_dh_pub_key_der_2048), 0);
  24424. ExpectIntNE(key.p.used, 0);
  24425. ExpectIntNE(key.g.used, 0);
  24426. ExpectIntEQ(key.q.used, 0);
  24427. ExpectIntNE(key.pub.used, 0);
  24428. ExpectIntEQ(key.priv.used, 0);
  24429. DoExpectIntEQ(wc_FreeDhKey(&key), 0);
  24430. #endif
  24431. #endif /* !NO_DH */
  24432. return EXPECT_RESULT();
  24433. }
  24434. /*
  24435. * Testing wc_Ed25519KeyToDer
  24436. */
  24437. static int test_wc_Ed25519KeyToDer(void)
  24438. {
  24439. EXPECT_DECLS;
  24440. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT) && \
  24441. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  24442. byte output[ONEK_BUF];
  24443. ed25519_key ed25519Key;
  24444. WC_RNG rng;
  24445. word32 inLen;
  24446. XMEMSET(&ed25519Key, 0, sizeof(ed25519_key));
  24447. XMEMSET(&rng, 0, sizeof(WC_RNG));
  24448. ExpectIntEQ(wc_ed25519_init(&ed25519Key), 0);
  24449. ExpectIntEQ(wc_InitRng(&rng), 0);
  24450. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &ed25519Key), 0);
  24451. inLen = (word32)sizeof(output);
  24452. /* Bad Cases */
  24453. ExpectIntEQ(wc_Ed25519KeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24454. ExpectIntEQ(wc_Ed25519KeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24455. ExpectIntEQ(wc_Ed25519KeyToDer(&ed25519Key, output, 0), WC_NO_ERR_TRACE(BUFFER_E));
  24456. /* Good Cases */
  24457. /* length only */
  24458. ExpectIntGT(wc_Ed25519KeyToDer(&ed25519Key, NULL, 0), 0);
  24459. ExpectIntGT(wc_Ed25519KeyToDer(&ed25519Key, NULL, inLen), 0);
  24460. ExpectIntGT(wc_Ed25519KeyToDer(&ed25519Key, output, inLen), 0);
  24461. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  24462. wc_ed25519_free(&ed25519Key);
  24463. #endif
  24464. return EXPECT_RESULT();
  24465. } /* End test_wc_Ed25519KeyToDer*/
  24466. /*
  24467. * Testing wc_Ed25519PrivateKeyToDer
  24468. */
  24469. static int test_wc_Ed25519PrivateKeyToDer(void)
  24470. {
  24471. EXPECT_DECLS;
  24472. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT) && \
  24473. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  24474. byte output[ONEK_BUF];
  24475. ed25519_key ed25519PrivKey;
  24476. WC_RNG rng;
  24477. word32 inLen;
  24478. XMEMSET(&ed25519PrivKey, 0, sizeof(ed25519_key));
  24479. XMEMSET(&rng, 0, sizeof(WC_RNG));
  24480. ExpectIntEQ(wc_ed25519_init(&ed25519PrivKey), 0);
  24481. ExpectIntEQ(wc_InitRng(&rng), 0);
  24482. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &ed25519PrivKey),
  24483. 0);
  24484. inLen = (word32)sizeof(output);
  24485. /* Bad Cases */
  24486. ExpectIntEQ(wc_Ed25519PrivateKeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24487. ExpectIntEQ(wc_Ed25519PrivateKeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24488. ExpectIntEQ(wc_Ed25519PrivateKeyToDer(&ed25519PrivKey, output, 0),
  24489. WC_NO_ERR_TRACE(BUFFER_E));
  24490. /* Good Cases */
  24491. /* length only */
  24492. ExpectIntGT(wc_Ed25519PrivateKeyToDer(&ed25519PrivKey, NULL, 0), 0);
  24493. ExpectIntGT(wc_Ed25519PrivateKeyToDer(&ed25519PrivKey, output, inLen), 0);
  24494. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  24495. wc_ed25519_free(&ed25519PrivKey);
  24496. #endif
  24497. return EXPECT_RESULT();
  24498. } /* End test_wc_Ed25519PrivateKeyToDer*/
  24499. /*
  24500. * Testing wc_Ed448KeyToDer
  24501. */
  24502. static int test_wc_Ed448KeyToDer(void)
  24503. {
  24504. EXPECT_DECLS;
  24505. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT) && \
  24506. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  24507. byte output[ONEK_BUF];
  24508. ed448_key ed448Key;
  24509. WC_RNG rng;
  24510. word32 inLen;
  24511. XMEMSET(&ed448Key, 0, sizeof(ed448_key));
  24512. XMEMSET(&rng, 0, sizeof(WC_RNG));
  24513. ExpectIntEQ(wc_ed448_init(&ed448Key), 0);
  24514. ExpectIntEQ(wc_InitRng(&rng), 0);
  24515. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &ed448Key), 0);
  24516. inLen = (word32)sizeof(output);
  24517. /* Bad Cases */
  24518. ExpectIntEQ(wc_Ed448KeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24519. ExpectIntEQ(wc_Ed448KeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24520. ExpectIntEQ(wc_Ed448KeyToDer(&ed448Key, output, 0), WC_NO_ERR_TRACE(BUFFER_E));
  24521. /* Good Cases */
  24522. /* length only */
  24523. ExpectIntGT(wc_Ed448KeyToDer(&ed448Key, NULL, 0), 0);
  24524. ExpectIntGT(wc_Ed448KeyToDer(&ed448Key, output, inLen), 0);
  24525. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  24526. wc_ed448_free(&ed448Key);
  24527. #endif
  24528. return EXPECT_RESULT();
  24529. } /* End test_wc_Ed448KeyToDer*/
  24530. /*
  24531. * Testing wc_Ed448PrivateKeyToDer
  24532. */
  24533. static int test_wc_Ed448PrivateKeyToDer(void)
  24534. {
  24535. EXPECT_DECLS;
  24536. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT) && \
  24537. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  24538. byte output[ONEK_BUF];
  24539. ed448_key ed448PrivKey;
  24540. WC_RNG rng;
  24541. word32 inLen;
  24542. XMEMSET(&ed448PrivKey, 0, sizeof(ed448_key));
  24543. XMEMSET(&rng, 0, sizeof(WC_RNG));
  24544. ExpectIntEQ(wc_ed448_init(&ed448PrivKey), 0);
  24545. ExpectIntEQ(wc_InitRng(&rng), 0);
  24546. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &ed448PrivKey),
  24547. 0);
  24548. inLen = (word32)sizeof(output);
  24549. /* Bad Cases */
  24550. ExpectIntEQ(wc_Ed448PrivateKeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24551. ExpectIntEQ(wc_Ed448PrivateKeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24552. ExpectIntEQ(wc_Ed448PrivateKeyToDer(&ed448PrivKey, output, 0),
  24553. WC_NO_ERR_TRACE(BUFFER_E));
  24554. /* Good cases */
  24555. /* length only */
  24556. ExpectIntGT(wc_Ed448PrivateKeyToDer(&ed448PrivKey, NULL, 0), 0);
  24557. ExpectIntGT(wc_Ed448PrivateKeyToDer(&ed448PrivKey, output, inLen), 0);
  24558. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  24559. wc_ed448_free(&ed448PrivKey);
  24560. #endif
  24561. return EXPECT_RESULT();
  24562. } /* End test_wc_Ed448PrivateKeyToDer*/
  24563. /*
  24564. * Testing wc_Curve448PrivateKeyToDer
  24565. */
  24566. static int test_wc_Curve448PrivateKeyToDer(void)
  24567. {
  24568. EXPECT_DECLS;
  24569. #if defined(HAVE_CURVE448) && defined(HAVE_CURVE448_KEY_EXPORT) && \
  24570. (defined(WOLFSSL_CERT_GEN) || defined(WOLFSSL_KEY_GEN))
  24571. byte output[ONEK_BUF];
  24572. curve448_key curve448PrivKey;
  24573. WC_RNG rng;
  24574. word32 inLen;
  24575. XMEMSET(&curve448PrivKey, 0, sizeof(curve448PrivKey));
  24576. XMEMSET(&rng, 0, sizeof(WC_RNG));
  24577. ExpectIntEQ(wc_curve448_init(&curve448PrivKey), 0);
  24578. ExpectIntEQ(wc_InitRng(&rng), 0);
  24579. ExpectIntEQ(wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &curve448PrivKey),
  24580. 0);
  24581. inLen = (word32)sizeof(output);
  24582. /* Bad Cases */
  24583. ExpectIntEQ(wc_Curve448PrivateKeyToDer(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24584. ExpectIntEQ(wc_Curve448PrivateKeyToDer(NULL, output, inLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24585. ExpectIntEQ(wc_Curve448PrivateKeyToDer(&curve448PrivKey, output, 0),
  24586. WC_NO_ERR_TRACE(BUFFER_E));
  24587. /* Good cases */
  24588. /* length only */
  24589. ExpectIntGT(wc_Curve448PrivateKeyToDer(&curve448PrivKey, NULL, 0), 0);
  24590. ExpectIntGT(wc_Curve448PrivateKeyToDer(&curve448PrivKey, output, inLen), 0);
  24591. /* Bad Cases */
  24592. ExpectIntEQ(wc_Curve448PublicKeyToDer(NULL, NULL, 0, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24593. ExpectIntEQ(wc_Curve448PublicKeyToDer(NULL, output, inLen, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  24594. ExpectIntEQ(wc_Curve448PublicKeyToDer(&curve448PrivKey, output, 0, 0),
  24595. WC_NO_ERR_TRACE(BUFFER_E));
  24596. ExpectIntEQ(wc_Curve448PublicKeyToDer(&curve448PrivKey, output, 0, 1),
  24597. WC_NO_ERR_TRACE(BUFFER_E));
  24598. /* Good cases */
  24599. /* length only */
  24600. ExpectIntGT(wc_Curve448PublicKeyToDer(&curve448PrivKey, NULL, 0, 0), 0);
  24601. ExpectIntGT(wc_Curve448PublicKeyToDer(&curve448PrivKey, NULL, 0, 1), 0);
  24602. ExpectIntGT(wc_Curve448PublicKeyToDer(&curve448PrivKey, output, inLen, 0), 0);
  24603. ExpectIntGT(wc_Curve448PublicKeyToDer(&curve448PrivKey, output, inLen, 1), 0);
  24604. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  24605. wc_curve448_free(&curve448PrivKey);
  24606. #endif
  24607. return EXPECT_RESULT();
  24608. } /* End wc_Curve448PrivateKeyToDer*/
  24609. static int test_wc_kyber_make_key_kats(void)
  24610. {
  24611. EXPECT_DECLS;
  24612. #if defined(WOLFSSL_HAVE_KYBER) && defined(WOLFSSL_WC_KYBER) && \
  24613. !defined(WOLFSSL_KYBER_ORIGINAL)
  24614. KyberKey* key;
  24615. #ifndef WOLFSSL_NO_KYBER512
  24616. static const byte seed_512[KYBER_MAKEKEY_RAND_SZ] = {
  24617. /* d */
  24618. 0x2C, 0xB8, 0x43, 0xA0, 0x2E, 0xF0, 0x2E, 0xE1,
  24619. 0x09, 0x30, 0x5F, 0x39, 0x11, 0x9F, 0xAB, 0xF4,
  24620. 0x9A, 0xB9, 0x0A, 0x57, 0xFF, 0xEC, 0xB3, 0xA0,
  24621. 0xE7, 0x5E, 0x17, 0x94, 0x50, 0xF5, 0x27, 0x61,
  24622. /* z */
  24623. 0x84, 0xCC, 0x91, 0x21, 0xAE, 0x56, 0xFB, 0xF3,
  24624. 0x9E, 0x67, 0xAD, 0xBD, 0x83, 0xAD, 0x2D, 0x3E,
  24625. 0x3B, 0xB8, 0x08, 0x43, 0x64, 0x52, 0x06, 0xBD,
  24626. 0xD9, 0xF2, 0xF6, 0x29, 0xE3, 0xCC, 0x49, 0xB7
  24627. };
  24628. static const byte ek_512[KYBER512_PUBLIC_KEY_SIZE] = {
  24629. 0xA3, 0x24, 0x39, 0xF8, 0x5A, 0x3C, 0x21, 0xD2,
  24630. 0x1A, 0x71, 0xB9, 0xB9, 0x2A, 0x9B, 0x64, 0xEA,
  24631. 0x0A, 0xB8, 0x43, 0x12, 0xC7, 0x70, 0x23, 0x69,
  24632. 0x4F, 0xD6, 0x4E, 0xAA, 0xB9, 0x07, 0xA4, 0x35,
  24633. 0x39, 0xDD, 0xB2, 0x7B, 0xA0, 0xA8, 0x53, 0xCC,
  24634. 0x90, 0x69, 0xEA, 0xC8, 0x50, 0x8C, 0x65, 0x3E,
  24635. 0x60, 0x0B, 0x2A, 0xC0, 0x18, 0x38, 0x1B, 0x4B,
  24636. 0xB4, 0xA8, 0x79, 0xAC, 0xDA, 0xD3, 0x42, 0xF9,
  24637. 0x11, 0x79, 0xCA, 0x82, 0x49, 0x52, 0x5C, 0xB1,
  24638. 0x96, 0x8B, 0xBE, 0x52, 0xF7, 0x55, 0xB7, 0xF5,
  24639. 0xB4, 0x3D, 0x66, 0x63, 0xD7, 0xA3, 0xBF, 0x0F,
  24640. 0x33, 0x57, 0xD8, 0xA2, 0x1D, 0x15, 0xB5, 0x2D,
  24641. 0xB3, 0x81, 0x8E, 0xCE, 0x5B, 0x40, 0x2A, 0x60,
  24642. 0xC9, 0x93, 0xE7, 0xCF, 0x43, 0x64, 0x87, 0xB8,
  24643. 0xD2, 0xAE, 0x91, 0xE6, 0xC5, 0xB8, 0x82, 0x75,
  24644. 0xE7, 0x58, 0x24, 0xB0, 0x00, 0x7E, 0xF3, 0x12,
  24645. 0x3C, 0x0A, 0xB5, 0x1B, 0x5C, 0xC6, 0x1B, 0x9B,
  24646. 0x22, 0x38, 0x0D, 0xE6, 0x6C, 0x5B, 0x20, 0xB0,
  24647. 0x60, 0xCB, 0xB9, 0x86, 0xF8, 0x12, 0x3D, 0x94,
  24648. 0x06, 0x00, 0x49, 0xCD, 0xF8, 0x03, 0x68, 0x73,
  24649. 0xA7, 0xBE, 0x10, 0x94, 0x44, 0xA0, 0xA1, 0xCD,
  24650. 0x87, 0xA4, 0x8C, 0xAE, 0x54, 0x19, 0x24, 0x84,
  24651. 0xAF, 0x84, 0x44, 0x29, 0xC1, 0xC5, 0x8C, 0x29,
  24652. 0xAC, 0x62, 0x4C, 0xD5, 0x04, 0xF1, 0xC4, 0x4F,
  24653. 0x1E, 0x13, 0x47, 0x82, 0x2B, 0x6F, 0x22, 0x13,
  24654. 0x23, 0x85, 0x9A, 0x7F, 0x6F, 0x75, 0x4B, 0xFE,
  24655. 0x71, 0x0B, 0xDA, 0x60, 0x27, 0x62, 0x40, 0xA4,
  24656. 0xFF, 0x2A, 0x53, 0x50, 0x70, 0x37, 0x86, 0xF5,
  24657. 0x67, 0x1F, 0x44, 0x9F, 0x20, 0xC2, 0xA9, 0x5A,
  24658. 0xE7, 0xC2, 0x90, 0x3A, 0x42, 0xCB, 0x3B, 0x30,
  24659. 0x3F, 0xF4, 0xC4, 0x27, 0xC0, 0x8B, 0x11, 0xB4,
  24660. 0xCD, 0x31, 0xC4, 0x18, 0xC6, 0xD1, 0x8D, 0x08,
  24661. 0x61, 0x87, 0x3B, 0xFA, 0x03, 0x32, 0xF1, 0x12,
  24662. 0x71, 0x55, 0x2E, 0xD7, 0xC0, 0x35, 0xF0, 0xE4,
  24663. 0xBC, 0x42, 0x8C, 0x43, 0x72, 0x0B, 0x39, 0xA6,
  24664. 0x51, 0x66, 0xBA, 0x9C, 0x2D, 0x3D, 0x77, 0x0E,
  24665. 0x13, 0x03, 0x60, 0xCC, 0x23, 0x84, 0xE8, 0x30,
  24666. 0x95, 0xB1, 0xA1, 0x59, 0x49, 0x55, 0x33, 0xF1,
  24667. 0x16, 0xC7, 0xB5, 0x58, 0xB6, 0x50, 0xDB, 0x04,
  24668. 0xD5, 0xA2, 0x6E, 0xAA, 0xA0, 0x8C, 0x3E, 0xE5,
  24669. 0x7D, 0xE4, 0x5A, 0x7F, 0x88, 0xC6, 0xA3, 0xCE,
  24670. 0xB2, 0x4D, 0xC5, 0x39, 0x7B, 0x88, 0xC3, 0xCE,
  24671. 0xF0, 0x03, 0x31, 0x9B, 0xB0, 0x23, 0x3F, 0xD6,
  24672. 0x92, 0xFD, 0xA1, 0x52, 0x44, 0x75, 0xB3, 0x51,
  24673. 0xF3, 0xC7, 0x82, 0x18, 0x2D, 0xEC, 0xF5, 0x90,
  24674. 0xB7, 0x72, 0x3B, 0xE4, 0x00, 0xBE, 0x14, 0x80,
  24675. 0x9C, 0x44, 0x32, 0x99, 0x63, 0xFC, 0x46, 0x95,
  24676. 0x92, 0x11, 0xD6, 0xA6, 0x23, 0x33, 0x95, 0x37,
  24677. 0x84, 0x8C, 0x25, 0x16, 0x69, 0x94, 0x1D, 0x90,
  24678. 0xB1, 0x30, 0x25, 0x8A, 0xDF, 0x55, 0xA7, 0x20,
  24679. 0xA7, 0x24, 0xE8, 0xB6, 0xA6, 0xCA, 0xE3, 0xC2,
  24680. 0x26, 0x4B, 0x16, 0x24, 0xCC, 0xBE, 0x7B, 0x45,
  24681. 0x6B, 0x30, 0xC8, 0xC7, 0x39, 0x32, 0x94, 0xCA,
  24682. 0x51, 0x80, 0xBC, 0x83, 0x7D, 0xD2, 0xE4, 0x5D,
  24683. 0xBD, 0x59, 0xB6, 0xE1, 0x7B, 0x24, 0xFE, 0x93,
  24684. 0x05, 0x2E, 0xB7, 0xC4, 0x3B, 0x27, 0xAC, 0x3D,
  24685. 0xC2, 0x49, 0xCA, 0x0C, 0xBC, 0xA4, 0xFB, 0x58,
  24686. 0x97, 0xC0, 0xB7, 0x44, 0x08, 0x8A, 0x8A, 0x07,
  24687. 0x79, 0xD3, 0x22, 0x33, 0x82, 0x6A, 0x01, 0xDD,
  24688. 0x64, 0x89, 0x95, 0x2A, 0x48, 0x25, 0xE5, 0x35,
  24689. 0x8A, 0x70, 0x0B, 0xE0, 0xE1, 0x79, 0xAC, 0x19,
  24690. 0x77, 0x10, 0xD8, 0x3E, 0xCC, 0x85, 0x3E, 0x52,
  24691. 0x69, 0x5E, 0x9B, 0xF8, 0x7B, 0xB1, 0xF6, 0xCB,
  24692. 0xD0, 0x5B, 0x02, 0xD4, 0xE6, 0x79, 0xE3, 0xB8,
  24693. 0x8D, 0xD4, 0x83, 0xB0, 0x74, 0x9B, 0x11, 0xBD,
  24694. 0x37, 0xB3, 0x83, 0xDC, 0xCA, 0x71, 0xF9, 0x09,
  24695. 0x18, 0x34, 0xA1, 0x69, 0x55, 0x02, 0xC4, 0xB9,
  24696. 0x5F, 0xC9, 0x11, 0x8C, 0x1C, 0xFC, 0x34, 0xC8,
  24697. 0x4C, 0x22, 0x65, 0xBB, 0xBC, 0x56, 0x3C, 0x28,
  24698. 0x26, 0x66, 0xB6, 0x0A, 0xE5, 0xC7, 0xF3, 0x85,
  24699. 0x1D, 0x25, 0xEC, 0xBB, 0x50, 0x21, 0xCC, 0x38,
  24700. 0xCB, 0x73, 0xEB, 0x6A, 0x34, 0x11, 0xB1, 0xC2,
  24701. 0x90, 0x46, 0xCA, 0x66, 0x54, 0x06, 0x67, 0xD1,
  24702. 0x36, 0x95, 0x44, 0x60, 0xC6, 0xFC, 0xBC, 0x4B,
  24703. 0xC7, 0xC0, 0x49, 0xBB, 0x04, 0x7F, 0xA6, 0x7A,
  24704. 0x63, 0xB3, 0xCC, 0x11, 0x11, 0xC1, 0xD8, 0xAC,
  24705. 0x27, 0xE8, 0x05, 0x8B, 0xCC, 0xA4, 0xA1, 0x54,
  24706. 0x55, 0x85, 0x8A, 0x58, 0x35, 0x8F, 0x7A, 0x61,
  24707. 0x02, 0x0B, 0xC9, 0xC4, 0xC1, 0x7F, 0x8B, 0x95,
  24708. 0xC2, 0x68, 0xCC, 0xB4, 0x04, 0xB9, 0xAA, 0xB4,
  24709. 0xA2, 0x72, 0xA2, 0x1A, 0x70, 0xDA, 0xF6, 0xB6,
  24710. 0xF1, 0x51, 0x21, 0xEE, 0x01, 0xC1, 0x56, 0xA3,
  24711. 0x54, 0xAA, 0x17, 0x08, 0x7E, 0x07, 0x70, 0x2E,
  24712. 0xAB, 0x38, 0xB3, 0x24, 0x1F, 0xDB, 0x55, 0x3F,
  24713. 0x65, 0x73, 0x39, 0xD5, 0xE2, 0x9D, 0xC5, 0xD9,
  24714. 0x1B, 0x7A, 0x5A, 0x82, 0x8E, 0xE9, 0x59, 0xFE,
  24715. 0xBB, 0x90, 0xB0, 0x72, 0x29, 0xF6, 0xE4, 0x9D,
  24716. 0x23, 0xC3, 0xA1, 0x90, 0x29, 0x70, 0x42, 0xFB,
  24717. 0x43, 0x98, 0x69, 0x55, 0xB6, 0x9C, 0x28, 0xE1,
  24718. 0x01, 0x6F, 0x77, 0xA5, 0x8B, 0x43, 0x15, 0x14,
  24719. 0xD2, 0x1B, 0x88, 0x88, 0x99, 0xC3, 0x60, 0x82,
  24720. 0x76, 0x08, 0x1B, 0x75, 0xF5, 0x68, 0x09, 0x7C,
  24721. 0xDC, 0x17, 0x48, 0xF3, 0x23, 0x07, 0x88, 0x58,
  24722. 0x15, 0xF3, 0xAE, 0xC9, 0x65, 0x18, 0x19, 0xAA,
  24723. 0x68, 0x73, 0xD1, 0xA4, 0xEB, 0x83, 0xB1, 0x95,
  24724. 0x38, 0x43, 0xB9, 0x34, 0x22, 0x51, 0x94, 0x83,
  24725. 0xFE, 0xF0, 0x05, 0x9D, 0x36, 0xBB, 0x2D, 0xB1,
  24726. 0xF3, 0xD4, 0x68, 0xFB, 0x06, 0x8C, 0x86, 0xE8,
  24727. 0x97, 0x37, 0x33, 0xC3, 0x98, 0xEA, 0xF0, 0x0E,
  24728. 0x17, 0x02, 0xC6, 0x73, 0x4A, 0xD8, 0xEB, 0x3B
  24729. };
  24730. static const byte dk_512[KYBER512_PRIVATE_KEY_SIZE] = {
  24731. 0x7F, 0xE4, 0x20, 0x6F, 0x26, 0xBE, 0xDB, 0x64,
  24732. 0xC1, 0xED, 0x00, 0x09, 0x61, 0x52, 0x45, 0xDC,
  24733. 0x98, 0x48, 0x3F, 0x66, 0x3A, 0xCC, 0x61, 0x7E,
  24734. 0x65, 0x89, 0x8D, 0x59, 0x6A, 0x88, 0x36, 0xC4,
  24735. 0x9F, 0xBD, 0x3B, 0x4A, 0x84, 0x97, 0x59, 0xAA,
  24736. 0x15, 0x46, 0xBD, 0xA8, 0x35, 0xCA, 0xF1, 0x75,
  24737. 0x64, 0x2C, 0x28, 0x28, 0x08, 0x92, 0xA7, 0x87,
  24738. 0x8C, 0xC3, 0x18, 0xBC, 0xC7, 0x5B, 0x83, 0x4C,
  24739. 0xB2, 0x9F, 0xDF, 0x53, 0x60, 0xD7, 0xF9, 0x82,
  24740. 0xA5, 0x2C, 0x88, 0xAE, 0x91, 0x4D, 0xBF, 0x02,
  24741. 0xB5, 0x8B, 0xEB, 0x8B, 0xA8, 0x87, 0xAE, 0x8F,
  24742. 0xAB, 0x5E, 0xB7, 0x87, 0x31, 0xC6, 0x75, 0x78,
  24743. 0x05, 0x47, 0x1E, 0xBC, 0xEC, 0x2E, 0x38, 0xDB,
  24744. 0x1F, 0x4B, 0x83, 0x10, 0xD2, 0x88, 0x92, 0x0D,
  24745. 0x8A, 0x49, 0x27, 0x95, 0xA3, 0x90, 0xA7, 0x4B,
  24746. 0xCD, 0x55, 0xCD, 0x85, 0x57, 0xB4, 0xDA, 0xAB,
  24747. 0xA8, 0x2C, 0x28, 0xCB, 0x3F, 0x15, 0x2C, 0x52,
  24748. 0x31, 0x19, 0x61, 0x93, 0xA6, 0x6A, 0x8C, 0xCF,
  24749. 0x34, 0xB8, 0x0E, 0x1F, 0x69, 0x42, 0xC3, 0x2B,
  24750. 0xCF, 0xF9, 0x6A, 0x6E, 0x3C, 0xF3, 0x93, 0x9B,
  24751. 0x7B, 0x94, 0x24, 0x98, 0xCC, 0x5E, 0x4C, 0xB8,
  24752. 0xE8, 0x46, 0x8E, 0x70, 0x27, 0x59, 0x85, 0x2A,
  24753. 0xA2, 0x29, 0xC0, 0x25, 0x7F, 0x02, 0x98, 0x20,
  24754. 0x97, 0x33, 0x86, 0x07, 0xC0, 0xF0, 0xF4, 0x54,
  24755. 0x46, 0xFA, 0xB4, 0x26, 0x79, 0x93, 0xB8, 0xA5,
  24756. 0x90, 0x8C, 0xAB, 0x9C, 0x46, 0x78, 0x01, 0x34,
  24757. 0x80, 0x4A, 0xE1, 0x88, 0x15, 0xB1, 0x02, 0x05,
  24758. 0x27, 0xA2, 0x22, 0xEC, 0x4B, 0x39, 0xA3, 0x19,
  24759. 0x4E, 0x66, 0x17, 0x37, 0x79, 0x17, 0x14, 0x12,
  24760. 0x26, 0x62, 0xD8, 0xB9, 0x76, 0x9F, 0x6C, 0x67,
  24761. 0xDE, 0x62, 0x5C, 0x0D, 0x48, 0x3C, 0x3D, 0x42,
  24762. 0x0F, 0xF1, 0xBB, 0x88, 0x9A, 0x72, 0x7E, 0x75,
  24763. 0x62, 0x81, 0x51, 0x3A, 0x70, 0x04, 0x76, 0x48,
  24764. 0xD2, 0x9C, 0x0C, 0x30, 0xF9, 0xBE, 0x52, 0xEC,
  24765. 0x0D, 0xEB, 0x97, 0x7C, 0xF0, 0xF3, 0x4F, 0xC2,
  24766. 0x07, 0x84, 0x83, 0x45, 0x69, 0x64, 0x74, 0x34,
  24767. 0x10, 0x63, 0x8C, 0x57, 0xB5, 0x53, 0x95, 0x77,
  24768. 0xBF, 0x85, 0x66, 0x90, 0x78, 0xC3, 0x56, 0xB3,
  24769. 0x46, 0x2E, 0x9F, 0xA5, 0x80, 0x7D, 0x49, 0x59,
  24770. 0x1A, 0xFA, 0x41, 0xC1, 0x96, 0x9F, 0x65, 0xE3,
  24771. 0x40, 0x5C, 0xB6, 0x4D, 0xDF, 0x16, 0x3F, 0x26,
  24772. 0x73, 0x4C, 0xE3, 0x48, 0xB9, 0xCF, 0x45, 0x67,
  24773. 0xA3, 0x3A, 0x59, 0x69, 0xEB, 0x32, 0x6C, 0xFB,
  24774. 0x5A, 0xDC, 0x69, 0x5D, 0xCA, 0x0C, 0x8B, 0x2A,
  24775. 0x7B, 0x1F, 0x4F, 0x40, 0x4C, 0xC7, 0xA0, 0x98,
  24776. 0x1E, 0x2C, 0xC2, 0x4C, 0x1C, 0x23, 0xD1, 0x6A,
  24777. 0xA9, 0xB4, 0x39, 0x24, 0x15, 0xE2, 0x6C, 0x22,
  24778. 0xF4, 0xA9, 0x34, 0xD7, 0x94, 0xC1, 0xFB, 0x4E,
  24779. 0x5A, 0x67, 0x05, 0x11, 0x23, 0xCC, 0xD1, 0x53,
  24780. 0x76, 0x4D, 0xEC, 0x99, 0xD5, 0x53, 0x52, 0x90,
  24781. 0x53, 0xC3, 0xDA, 0x55, 0x0B, 0xCE, 0xA3, 0xAC,
  24782. 0x54, 0x13, 0x6A, 0x26, 0xA6, 0x76, 0xD2, 0xBA,
  24783. 0x84, 0x21, 0x06, 0x70, 0x68, 0xC6, 0x38, 0x1C,
  24784. 0x2A, 0x62, 0xA7, 0x27, 0xC9, 0x33, 0x70, 0x2E,
  24785. 0xE5, 0x80, 0x4A, 0x31, 0xCA, 0x86, 0x5A, 0x45,
  24786. 0x58, 0x8F, 0xB7, 0x4D, 0xE7, 0xE2, 0x22, 0x3D,
  24787. 0x88, 0xC0, 0x60, 0x8A, 0x16, 0xBF, 0xEC, 0x4F,
  24788. 0xAD, 0x67, 0x52, 0xDB, 0x56, 0xB4, 0x8B, 0x88,
  24789. 0x72, 0xBF, 0x26, 0xBA, 0x2F, 0xFA, 0x0C, 0xED,
  24790. 0xE5, 0x34, 0x3B, 0xE8, 0x14, 0x36, 0x89, 0x26,
  24791. 0x5E, 0x06, 0x5F, 0x41, 0xA6, 0x92, 0x5B, 0x86,
  24792. 0xC8, 0x92, 0xE6, 0x2E, 0xB0, 0x77, 0x27, 0x34,
  24793. 0xF5, 0xA3, 0x57, 0xC7, 0x5C, 0xA1, 0xAC, 0x6D,
  24794. 0xF7, 0x8A, 0xB1, 0xB8, 0x88, 0x5A, 0xD0, 0x81,
  24795. 0x96, 0x15, 0x37, 0x6D, 0x33, 0xEB, 0xB9, 0x8F,
  24796. 0x87, 0x33, 0xA6, 0x75, 0x58, 0x03, 0xD9, 0x77,
  24797. 0xBF, 0x51, 0xC1, 0x27, 0x40, 0x42, 0x4B, 0x2B,
  24798. 0x49, 0xC2, 0x83, 0x82, 0xA6, 0x91, 0x7C, 0xBF,
  24799. 0xA0, 0x34, 0xC3, 0xF1, 0x26, 0xA3, 0x8C, 0x21,
  24800. 0x6C, 0x03, 0xC3, 0x57, 0x70, 0xAD, 0x48, 0x1B,
  24801. 0x90, 0x84, 0xB5, 0x58, 0x8D, 0xA6, 0x5F, 0xF1,
  24802. 0x18, 0xA7, 0x4F, 0x93, 0x2C, 0x7E, 0x53, 0x7A,
  24803. 0xBE, 0x58, 0x63, 0xFB, 0x29, 0xA1, 0x0C, 0x09,
  24804. 0x70, 0x1B, 0x44, 0x1F, 0x83, 0x99, 0xC1, 0xF8,
  24805. 0xA6, 0x37, 0x82, 0x5A, 0xCE, 0xA3, 0xE9, 0x31,
  24806. 0x80, 0x57, 0x4F, 0xDE, 0xB8, 0x80, 0x76, 0x66,
  24807. 0x1A, 0xB4, 0x69, 0x51, 0x71, 0x6A, 0x50, 0x01,
  24808. 0x84, 0xA0, 0x40, 0x55, 0x72, 0x66, 0x59, 0x8C,
  24809. 0xAF, 0x76, 0x10, 0x5E, 0x1C, 0x18, 0x70, 0xB4,
  24810. 0x39, 0x69, 0xC3, 0xBC, 0xC1, 0xA0, 0x49, 0x27,
  24811. 0x63, 0x80, 0x17, 0x49, 0x8B, 0xB6, 0x2C, 0xAF,
  24812. 0xD3, 0xA6, 0xB0, 0x82, 0xB7, 0xBF, 0x7A, 0x23,
  24813. 0x45, 0x0E, 0x19, 0x17, 0x99, 0x61, 0x9B, 0x92,
  24814. 0x51, 0x12, 0xD0, 0x72, 0x02, 0x5C, 0xA8, 0x88,
  24815. 0x54, 0x8C, 0x79, 0x1A, 0xA4, 0x22, 0x51, 0x50,
  24816. 0x4D, 0x5D, 0x1C, 0x1C, 0xDD, 0xB2, 0x13, 0x30,
  24817. 0x3B, 0x04, 0x9E, 0x73, 0x46, 0xE8, 0xD8, 0x3A,
  24818. 0xD5, 0x87, 0x83, 0x6F, 0x35, 0x28, 0x4E, 0x10,
  24819. 0x97, 0x27, 0xE6, 0x6B, 0xBC, 0xC9, 0x52, 0x1F,
  24820. 0xE0, 0xB1, 0x91, 0x63, 0x00, 0x47, 0xD1, 0x58,
  24821. 0xF7, 0x56, 0x40, 0xFF, 0xEB, 0x54, 0x56, 0x07,
  24822. 0x27, 0x40, 0x02, 0x1A, 0xFD, 0x15, 0xA4, 0x54,
  24823. 0x69, 0xC5, 0x83, 0x82, 0x9D, 0xAA, 0xC8, 0xA7,
  24824. 0xDE, 0xB0, 0x5B, 0x24, 0xF0, 0x56, 0x7E, 0x43,
  24825. 0x17, 0xB3, 0xE3, 0xB3, 0x33, 0x89, 0xB5, 0xC5,
  24826. 0xF8, 0xB0, 0x4B, 0x09, 0x9F, 0xB4, 0xD1, 0x03,
  24827. 0xA3, 0x24, 0x39, 0xF8, 0x5A, 0x3C, 0x21, 0xD2,
  24828. 0x1A, 0x71, 0xB9, 0xB9, 0x2A, 0x9B, 0x64, 0xEA,
  24829. 0x0A, 0xB8, 0x43, 0x12, 0xC7, 0x70, 0x23, 0x69,
  24830. 0x4F, 0xD6, 0x4E, 0xAA, 0xB9, 0x07, 0xA4, 0x35,
  24831. 0x39, 0xDD, 0xB2, 0x7B, 0xA0, 0xA8, 0x53, 0xCC,
  24832. 0x90, 0x69, 0xEA, 0xC8, 0x50, 0x8C, 0x65, 0x3E,
  24833. 0x60, 0x0B, 0x2A, 0xC0, 0x18, 0x38, 0x1B, 0x4B,
  24834. 0xB4, 0xA8, 0x79, 0xAC, 0xDA, 0xD3, 0x42, 0xF9,
  24835. 0x11, 0x79, 0xCA, 0x82, 0x49, 0x52, 0x5C, 0xB1,
  24836. 0x96, 0x8B, 0xBE, 0x52, 0xF7, 0x55, 0xB7, 0xF5,
  24837. 0xB4, 0x3D, 0x66, 0x63, 0xD7, 0xA3, 0xBF, 0x0F,
  24838. 0x33, 0x57, 0xD8, 0xA2, 0x1D, 0x15, 0xB5, 0x2D,
  24839. 0xB3, 0x81, 0x8E, 0xCE, 0x5B, 0x40, 0x2A, 0x60,
  24840. 0xC9, 0x93, 0xE7, 0xCF, 0x43, 0x64, 0x87, 0xB8,
  24841. 0xD2, 0xAE, 0x91, 0xE6, 0xC5, 0xB8, 0x82, 0x75,
  24842. 0xE7, 0x58, 0x24, 0xB0, 0x00, 0x7E, 0xF3, 0x12,
  24843. 0x3C, 0x0A, 0xB5, 0x1B, 0x5C, 0xC6, 0x1B, 0x9B,
  24844. 0x22, 0x38, 0x0D, 0xE6, 0x6C, 0x5B, 0x20, 0xB0,
  24845. 0x60, 0xCB, 0xB9, 0x86, 0xF8, 0x12, 0x3D, 0x94,
  24846. 0x06, 0x00, 0x49, 0xCD, 0xF8, 0x03, 0x68, 0x73,
  24847. 0xA7, 0xBE, 0x10, 0x94, 0x44, 0xA0, 0xA1, 0xCD,
  24848. 0x87, 0xA4, 0x8C, 0xAE, 0x54, 0x19, 0x24, 0x84,
  24849. 0xAF, 0x84, 0x44, 0x29, 0xC1, 0xC5, 0x8C, 0x29,
  24850. 0xAC, 0x62, 0x4C, 0xD5, 0x04, 0xF1, 0xC4, 0x4F,
  24851. 0x1E, 0x13, 0x47, 0x82, 0x2B, 0x6F, 0x22, 0x13,
  24852. 0x23, 0x85, 0x9A, 0x7F, 0x6F, 0x75, 0x4B, 0xFE,
  24853. 0x71, 0x0B, 0xDA, 0x60, 0x27, 0x62, 0x40, 0xA4,
  24854. 0xFF, 0x2A, 0x53, 0x50, 0x70, 0x37, 0x86, 0xF5,
  24855. 0x67, 0x1F, 0x44, 0x9F, 0x20, 0xC2, 0xA9, 0x5A,
  24856. 0xE7, 0xC2, 0x90, 0x3A, 0x42, 0xCB, 0x3B, 0x30,
  24857. 0x3F, 0xF4, 0xC4, 0x27, 0xC0, 0x8B, 0x11, 0xB4,
  24858. 0xCD, 0x31, 0xC4, 0x18, 0xC6, 0xD1, 0x8D, 0x08,
  24859. 0x61, 0x87, 0x3B, 0xFA, 0x03, 0x32, 0xF1, 0x12,
  24860. 0x71, 0x55, 0x2E, 0xD7, 0xC0, 0x35, 0xF0, 0xE4,
  24861. 0xBC, 0x42, 0x8C, 0x43, 0x72, 0x0B, 0x39, 0xA6,
  24862. 0x51, 0x66, 0xBA, 0x9C, 0x2D, 0x3D, 0x77, 0x0E,
  24863. 0x13, 0x03, 0x60, 0xCC, 0x23, 0x84, 0xE8, 0x30,
  24864. 0x95, 0xB1, 0xA1, 0x59, 0x49, 0x55, 0x33, 0xF1,
  24865. 0x16, 0xC7, 0xB5, 0x58, 0xB6, 0x50, 0xDB, 0x04,
  24866. 0xD5, 0xA2, 0x6E, 0xAA, 0xA0, 0x8C, 0x3E, 0xE5,
  24867. 0x7D, 0xE4, 0x5A, 0x7F, 0x88, 0xC6, 0xA3, 0xCE,
  24868. 0xB2, 0x4D, 0xC5, 0x39, 0x7B, 0x88, 0xC3, 0xCE,
  24869. 0xF0, 0x03, 0x31, 0x9B, 0xB0, 0x23, 0x3F, 0xD6,
  24870. 0x92, 0xFD, 0xA1, 0x52, 0x44, 0x75, 0xB3, 0x51,
  24871. 0xF3, 0xC7, 0x82, 0x18, 0x2D, 0xEC, 0xF5, 0x90,
  24872. 0xB7, 0x72, 0x3B, 0xE4, 0x00, 0xBE, 0x14, 0x80,
  24873. 0x9C, 0x44, 0x32, 0x99, 0x63, 0xFC, 0x46, 0x95,
  24874. 0x92, 0x11, 0xD6, 0xA6, 0x23, 0x33, 0x95, 0x37,
  24875. 0x84, 0x8C, 0x25, 0x16, 0x69, 0x94, 0x1D, 0x90,
  24876. 0xB1, 0x30, 0x25, 0x8A, 0xDF, 0x55, 0xA7, 0x20,
  24877. 0xA7, 0x24, 0xE8, 0xB6, 0xA6, 0xCA, 0xE3, 0xC2,
  24878. 0x26, 0x4B, 0x16, 0x24, 0xCC, 0xBE, 0x7B, 0x45,
  24879. 0x6B, 0x30, 0xC8, 0xC7, 0x39, 0x32, 0x94, 0xCA,
  24880. 0x51, 0x80, 0xBC, 0x83, 0x7D, 0xD2, 0xE4, 0x5D,
  24881. 0xBD, 0x59, 0xB6, 0xE1, 0x7B, 0x24, 0xFE, 0x93,
  24882. 0x05, 0x2E, 0xB7, 0xC4, 0x3B, 0x27, 0xAC, 0x3D,
  24883. 0xC2, 0x49, 0xCA, 0x0C, 0xBC, 0xA4, 0xFB, 0x58,
  24884. 0x97, 0xC0, 0xB7, 0x44, 0x08, 0x8A, 0x8A, 0x07,
  24885. 0x79, 0xD3, 0x22, 0x33, 0x82, 0x6A, 0x01, 0xDD,
  24886. 0x64, 0x89, 0x95, 0x2A, 0x48, 0x25, 0xE5, 0x35,
  24887. 0x8A, 0x70, 0x0B, 0xE0, 0xE1, 0x79, 0xAC, 0x19,
  24888. 0x77, 0x10, 0xD8, 0x3E, 0xCC, 0x85, 0x3E, 0x52,
  24889. 0x69, 0x5E, 0x9B, 0xF8, 0x7B, 0xB1, 0xF6, 0xCB,
  24890. 0xD0, 0x5B, 0x02, 0xD4, 0xE6, 0x79, 0xE3, 0xB8,
  24891. 0x8D, 0xD4, 0x83, 0xB0, 0x74, 0x9B, 0x11, 0xBD,
  24892. 0x37, 0xB3, 0x83, 0xDC, 0xCA, 0x71, 0xF9, 0x09,
  24893. 0x18, 0x34, 0xA1, 0x69, 0x55, 0x02, 0xC4, 0xB9,
  24894. 0x5F, 0xC9, 0x11, 0x8C, 0x1C, 0xFC, 0x34, 0xC8,
  24895. 0x4C, 0x22, 0x65, 0xBB, 0xBC, 0x56, 0x3C, 0x28,
  24896. 0x26, 0x66, 0xB6, 0x0A, 0xE5, 0xC7, 0xF3, 0x85,
  24897. 0x1D, 0x25, 0xEC, 0xBB, 0x50, 0x21, 0xCC, 0x38,
  24898. 0xCB, 0x73, 0xEB, 0x6A, 0x34, 0x11, 0xB1, 0xC2,
  24899. 0x90, 0x46, 0xCA, 0x66, 0x54, 0x06, 0x67, 0xD1,
  24900. 0x36, 0x95, 0x44, 0x60, 0xC6, 0xFC, 0xBC, 0x4B,
  24901. 0xC7, 0xC0, 0x49, 0xBB, 0x04, 0x7F, 0xA6, 0x7A,
  24902. 0x63, 0xB3, 0xCC, 0x11, 0x11, 0xC1, 0xD8, 0xAC,
  24903. 0x27, 0xE8, 0x05, 0x8B, 0xCC, 0xA4, 0xA1, 0x54,
  24904. 0x55, 0x85, 0x8A, 0x58, 0x35, 0x8F, 0x7A, 0x61,
  24905. 0x02, 0x0B, 0xC9, 0xC4, 0xC1, 0x7F, 0x8B, 0x95,
  24906. 0xC2, 0x68, 0xCC, 0xB4, 0x04, 0xB9, 0xAA, 0xB4,
  24907. 0xA2, 0x72, 0xA2, 0x1A, 0x70, 0xDA, 0xF6, 0xB6,
  24908. 0xF1, 0x51, 0x21, 0xEE, 0x01, 0xC1, 0x56, 0xA3,
  24909. 0x54, 0xAA, 0x17, 0x08, 0x7E, 0x07, 0x70, 0x2E,
  24910. 0xAB, 0x38, 0xB3, 0x24, 0x1F, 0xDB, 0x55, 0x3F,
  24911. 0x65, 0x73, 0x39, 0xD5, 0xE2, 0x9D, 0xC5, 0xD9,
  24912. 0x1B, 0x7A, 0x5A, 0x82, 0x8E, 0xE9, 0x59, 0xFE,
  24913. 0xBB, 0x90, 0xB0, 0x72, 0x29, 0xF6, 0xE4, 0x9D,
  24914. 0x23, 0xC3, 0xA1, 0x90, 0x29, 0x70, 0x42, 0xFB,
  24915. 0x43, 0x98, 0x69, 0x55, 0xB6, 0x9C, 0x28, 0xE1,
  24916. 0x01, 0x6F, 0x77, 0xA5, 0x8B, 0x43, 0x15, 0x14,
  24917. 0xD2, 0x1B, 0x88, 0x88, 0x99, 0xC3, 0x60, 0x82,
  24918. 0x76, 0x08, 0x1B, 0x75, 0xF5, 0x68, 0x09, 0x7C,
  24919. 0xDC, 0x17, 0x48, 0xF3, 0x23, 0x07, 0x88, 0x58,
  24920. 0x15, 0xF3, 0xAE, 0xC9, 0x65, 0x18, 0x19, 0xAA,
  24921. 0x68, 0x73, 0xD1, 0xA4, 0xEB, 0x83, 0xB1, 0x95,
  24922. 0x38, 0x43, 0xB9, 0x34, 0x22, 0x51, 0x94, 0x83,
  24923. 0xFE, 0xF0, 0x05, 0x9D, 0x36, 0xBB, 0x2D, 0xB1,
  24924. 0xF3, 0xD4, 0x68, 0xFB, 0x06, 0x8C, 0x86, 0xE8,
  24925. 0x97, 0x37, 0x33, 0xC3, 0x98, 0xEA, 0xF0, 0x0E,
  24926. 0x17, 0x02, 0xC6, 0x73, 0x4A, 0xD8, 0xEB, 0x3B,
  24927. 0x62, 0x01, 0x30, 0xD6, 0xC2, 0xB8, 0xC9, 0x04,
  24928. 0xA3, 0xBB, 0x93, 0x07, 0xBE, 0x51, 0x03, 0xF8,
  24929. 0xD8, 0x14, 0x50, 0x5F, 0xB6, 0xA6, 0x0A, 0xF7,
  24930. 0x93, 0x7E, 0xA6, 0xCA, 0xA1, 0x17, 0x31, 0x5E,
  24931. 0x84, 0xCC, 0x91, 0x21, 0xAE, 0x56, 0xFB, 0xF3,
  24932. 0x9E, 0x67, 0xAD, 0xBD, 0x83, 0xAD, 0x2D, 0x3E,
  24933. 0x3B, 0xB8, 0x08, 0x43, 0x64, 0x52, 0x06, 0xBD,
  24934. 0xD9, 0xF2, 0xF6, 0x29, 0xE3, 0xCC, 0x49, 0xB7
  24935. };
  24936. #endif
  24937. #ifndef WOLFSSL_NO_KYBER768
  24938. static const byte seed_768[KYBER_MAKEKEY_RAND_SZ] = {
  24939. /* d */
  24940. 0xE3, 0x4A, 0x70, 0x1C, 0x4C, 0x87, 0x58, 0x2F,
  24941. 0x42, 0x26, 0x4E, 0xE4, 0x22, 0xD3, 0xC6, 0x84,
  24942. 0xD9, 0x76, 0x11, 0xF2, 0x52, 0x3E, 0xFE, 0x0C,
  24943. 0x99, 0x8A, 0xF0, 0x50, 0x56, 0xD6, 0x93, 0xDC,
  24944. /* z */
  24945. 0xA8, 0x57, 0x68, 0xF3, 0x48, 0x6B, 0xD3, 0x2A,
  24946. 0x01, 0xBF, 0x9A, 0x8F, 0x21, 0xEA, 0x93, 0x8E,
  24947. 0x64, 0x8E, 0xAE, 0x4E, 0x54, 0x48, 0xC3, 0x4C,
  24948. 0x3E, 0xB8, 0x88, 0x20, 0xB1, 0x59, 0xEE, 0xDD
  24949. };
  24950. static const byte ek_768[KYBER768_PUBLIC_KEY_SIZE] = {
  24951. 0x6D, 0x14, 0xA0, 0x71, 0xF7, 0xCC, 0x45, 0x25,
  24952. 0x58, 0xD5, 0xE7, 0x1A, 0x7B, 0x08, 0x70, 0x62,
  24953. 0xEC, 0xB1, 0x38, 0x68, 0x44, 0x58, 0x82, 0x46,
  24954. 0x12, 0x64, 0x02, 0xB1, 0xFA, 0x16, 0x37, 0x73,
  24955. 0x3C, 0xD5, 0xF6, 0x0C, 0xC8, 0x4B, 0xCB, 0x64,
  24956. 0x6A, 0x78, 0x92, 0x61, 0x4D, 0x7C, 0x51, 0xB1,
  24957. 0xC7, 0xF1, 0xA2, 0x79, 0x91, 0x32, 0xF1, 0x34,
  24958. 0x27, 0xDC, 0x48, 0x21, 0x58, 0xDA, 0x25, 0x44,
  24959. 0x70, 0xA5, 0x9E, 0x00, 0xA4, 0xE4, 0x96, 0x86,
  24960. 0xFD, 0xC0, 0x77, 0x55, 0x93, 0x67, 0x27, 0x0C,
  24961. 0x21, 0x53, 0xF1, 0x10, 0x07, 0x59, 0x2C, 0x9C,
  24962. 0x43, 0x10, 0xCF, 0x8A, 0x12, 0xC6, 0xA8, 0x71,
  24963. 0x3B, 0xD6, 0xBB, 0x51, 0xF3, 0x12, 0x4F, 0x98,
  24964. 0x9B, 0xA0, 0xD5, 0x40, 0x73, 0xCC, 0x24, 0x2E,
  24965. 0x09, 0x68, 0x78, 0x0B, 0x87, 0x5A, 0x86, 0x9E,
  24966. 0xFB, 0x85, 0x15, 0x86, 0xB9, 0xA8, 0x68, 0xA3,
  24967. 0x84, 0xB9, 0xE6, 0x82, 0x1B, 0x20, 0x1B, 0x93,
  24968. 0x2C, 0x45, 0x53, 0x69, 0xA7, 0x39, 0xEC, 0x22,
  24969. 0x56, 0x9C, 0x97, 0x7C, 0x21, 0x2B, 0x38, 0x18,
  24970. 0x71, 0x81, 0x36, 0x56, 0xAF, 0x5B, 0x56, 0x7E,
  24971. 0xF8, 0x93, 0xB5, 0x84, 0x62, 0x4C, 0x86, 0x3A,
  24972. 0x25, 0x90, 0x00, 0xF1, 0x7B, 0x25, 0x4B, 0x98,
  24973. 0xB1, 0x85, 0x09, 0x7C, 0x50, 0xEB, 0xB6, 0x8B,
  24974. 0x24, 0x43, 0x42, 0xE0, 0x5D, 0x4D, 0xE5, 0x20,
  24975. 0x12, 0x5B, 0x8E, 0x10, 0x33, 0xB1, 0x43, 0x60,
  24976. 0x93, 0xAC, 0xE7, 0xCE, 0x8E, 0x71, 0xB4, 0x58,
  24977. 0xD5, 0x25, 0x67, 0x33, 0x63, 0x04, 0x5A, 0x3B,
  24978. 0x3E, 0xEA, 0x94, 0x55, 0x42, 0x8A, 0x39, 0x87,
  24979. 0x05, 0xA4, 0x23, 0x27, 0xAD, 0xB3, 0x77, 0x4B,
  24980. 0x70, 0x57, 0xF4, 0x2B, 0x01, 0x7E, 0xC0, 0x73,
  24981. 0x9A, 0x98, 0x3F, 0x19, 0xE8, 0x21, 0x4D, 0x09,
  24982. 0x19, 0x5F, 0xA2, 0x4D, 0x2D, 0x57, 0x1D, 0xB7,
  24983. 0x3C, 0x19, 0xA6, 0xF8, 0x46, 0x0E, 0x50, 0x83,
  24984. 0x0D, 0x41, 0x5F, 0x62, 0x7B, 0x88, 0xE9, 0x4A,
  24985. 0x7B, 0x15, 0x37, 0x91, 0xA0, 0xC0, 0xC7, 0xE9,
  24986. 0x48, 0x4C, 0x74, 0xD5, 0x3C, 0x71, 0x48, 0x89,
  24987. 0xF0, 0xE3, 0x21, 0xB6, 0x66, 0x0A, 0x53, 0x2A,
  24988. 0x5B, 0xC0, 0xE5, 0x57, 0xFB, 0xCA, 0x35, 0xE2,
  24989. 0x9B, 0xC6, 0x11, 0x20, 0x0E, 0xD3, 0xC6, 0x33,
  24990. 0x07, 0x7A, 0x4D, 0x87, 0x3C, 0x5C, 0xC6, 0x70,
  24991. 0x06, 0xB7, 0x53, 0xBF, 0x6D, 0x6B, 0x7A, 0xF6,
  24992. 0xCA, 0x40, 0x2A, 0xB6, 0x18, 0x23, 0x6C, 0x0A,
  24993. 0xFF, 0xBC, 0x80, 0x1F, 0x82, 0x22, 0xFB, 0xC3,
  24994. 0x6C, 0xE0, 0x98, 0x4E, 0x2B, 0x18, 0xC9, 0x44,
  24995. 0xBB, 0xCB, 0xEF, 0x03, 0xB1, 0xE1, 0x36, 0x1C,
  24996. 0x1F, 0x44, 0xB0, 0xD7, 0x34, 0xAF, 0xB1, 0x56,
  24997. 0x6C, 0xFF, 0x87, 0x44, 0xDA, 0x8B, 0x99, 0x43,
  24998. 0xD6, 0xB4, 0x5A, 0x3C, 0x09, 0x03, 0x07, 0x02,
  24999. 0xCA, 0x20, 0x1F, 0xFE, 0x20, 0xCB, 0x7E, 0xC5,
  25000. 0xB0, 0xD4, 0x14, 0x9E, 0xE2, 0xC2, 0x8E, 0x8B,
  25001. 0x23, 0x37, 0x4F, 0x47, 0x1B, 0x57, 0x15, 0x0D,
  25002. 0x0E, 0xC9, 0x33, 0x62, 0x61, 0xA2, 0xD5, 0xCB,
  25003. 0x84, 0xA3, 0xAC, 0xAC, 0xC4, 0x28, 0x94, 0x73,
  25004. 0xA4, 0xC0, 0xAB, 0xC6, 0x17, 0xC9, 0xAB, 0xC1,
  25005. 0x78, 0x73, 0x44, 0x34, 0xC8, 0x2E, 0x16, 0x85,
  25006. 0x58, 0x8A, 0x5C, 0x2E, 0xA2, 0x67, 0x8F, 0x6B,
  25007. 0x3C, 0x22, 0x28, 0x73, 0x31, 0x30, 0xC4, 0x66,
  25008. 0xE5, 0xB8, 0x6E, 0xF4, 0x91, 0x15, 0x3E, 0x48,
  25009. 0x66, 0x22, 0x47, 0xB8, 0x75, 0xD2, 0x01, 0x02,
  25010. 0x0B, 0x56, 0x6B, 0x81, 0xB6, 0x4D, 0x83, 0x9A,
  25011. 0xB4, 0x63, 0x3B, 0xAA, 0x8A, 0xCE, 0x20, 0x2B,
  25012. 0xAA, 0xB4, 0x49, 0x62, 0x97, 0xF9, 0x80, 0x7A,
  25013. 0xDB, 0xBB, 0x1E, 0x33, 0x2C, 0x6F, 0x80, 0x22,
  25014. 0xB2, 0xA1, 0x8C, 0xFD, 0xD4, 0xA8, 0x25, 0x30,
  25015. 0xB6, 0xD3, 0xF0, 0x07, 0xC3, 0x35, 0x38, 0x98,
  25016. 0xD9, 0x66, 0xCC, 0x2C, 0x21, 0xCB, 0x42, 0x44,
  25017. 0xBD, 0x00, 0x44, 0x3F, 0x20, 0x98, 0x70, 0xAC,
  25018. 0xC4, 0x2B, 0xC3, 0x30, 0x68, 0xC7, 0x24, 0xEC,
  25019. 0x17, 0x22, 0x36, 0x19, 0xC1, 0x09, 0x3C, 0xCA,
  25020. 0x6A, 0xEB, 0x29, 0x50, 0x06, 0x64, 0xD1, 0x22,
  25021. 0x50, 0x36, 0xB4, 0xB8, 0x10, 0x91, 0x90, 0x69,
  25022. 0x69, 0x48, 0x1F, 0x1C, 0x72, 0x3C, 0x14, 0x0B,
  25023. 0x9D, 0x6C, 0x16, 0x8F, 0x5B, 0x64, 0xBE, 0xA6,
  25024. 0x9C, 0x5F, 0xD6, 0x38, 0x5D, 0xF7, 0x36, 0x4B,
  25025. 0x87, 0x23, 0xBC, 0xC8, 0x5E, 0x03, 0x8C, 0x7E,
  25026. 0x46, 0x4A, 0x90, 0x0D, 0x68, 0xA2, 0x12, 0x78,
  25027. 0x18, 0x99, 0x42, 0x17, 0xAE, 0xC8, 0xBD, 0xB3,
  25028. 0x9A, 0x97, 0x0A, 0x99, 0x63, 0xDE, 0x93, 0x68,
  25029. 0x8E, 0x2A, 0xC8, 0x2A, 0xBC, 0xC2, 0x2F, 0xB9,
  25030. 0x27, 0x7B, 0xA2, 0x20, 0x09, 0xE8, 0x78, 0x38,
  25031. 0x1A, 0x38, 0x16, 0x39, 0x01, 0xC7, 0xD4, 0xC8,
  25032. 0x50, 0x19, 0x53, 0x8D, 0x35, 0xCA, 0xAE, 0x9C,
  25033. 0x41, 0xAF, 0x8C, 0x92, 0x9E, 0xE2, 0x0B, 0xB0,
  25034. 0x8C, 0xA6, 0x19, 0xE7, 0x2C, 0x2F, 0x22, 0x62,
  25035. 0xC1, 0xC9, 0x93, 0x85, 0x72, 0x55, 0x1A, 0xC0,
  25036. 0x2D, 0xC9, 0x26, 0x8F, 0xBC, 0xC3, 0x5D, 0x79,
  25037. 0x01, 0x1C, 0x3C, 0x09, 0x0A, 0xD4, 0x0A, 0x4F,
  25038. 0x11, 0x1C, 0x9B, 0xE5, 0x5C, 0x42, 0x7E, 0xB7,
  25039. 0x96, 0xC1, 0x93, 0x2D, 0x86, 0x73, 0x57, 0x9A,
  25040. 0xF1, 0xB4, 0xC6, 0x38, 0xB0, 0x94, 0x44, 0x89,
  25041. 0x01, 0x2A, 0x25, 0x59, 0xA3, 0xB0, 0x24, 0x81,
  25042. 0xB0, 0x1A, 0xC3, 0x0B, 0xA8, 0x96, 0x0F, 0x80,
  25043. 0xC0, 0xC2, 0xB3, 0x94, 0x7D, 0x36, 0xA1, 0x2C,
  25044. 0x08, 0x04, 0x98, 0xBE, 0xE4, 0x48, 0x71, 0x6C,
  25045. 0x97, 0x34, 0x16, 0xC8, 0x24, 0x28, 0x04, 0xA3,
  25046. 0xDA, 0x09, 0x9E, 0xE1, 0x37, 0xB0, 0xBA, 0x90,
  25047. 0xFE, 0x4A, 0x5C, 0x6A, 0x89, 0x20, 0x02, 0x76,
  25048. 0xA0, 0xCF, 0xB6, 0x43, 0xEC, 0x2C, 0x56, 0xA2,
  25049. 0xD7, 0x08, 0xD7, 0xB4, 0x37, 0x3E, 0x44, 0xC1,
  25050. 0x50, 0x2A, 0x76, 0x3A, 0x60, 0x05, 0x86, 0xE6,
  25051. 0xCD, 0xA6, 0x27, 0x38, 0x97, 0xD4, 0x44, 0x48,
  25052. 0x28, 0x7D, 0xC2, 0xE6, 0x02, 0xDC, 0x39, 0x20,
  25053. 0x0B, 0xF6, 0x16, 0x62, 0x36, 0x55, 0x9F, 0xD1,
  25054. 0x2A, 0x60, 0x89, 0x2A, 0xEB, 0x15, 0x3D, 0xD6,
  25055. 0x51, 0xBB, 0x46, 0x99, 0x10, 0xB4, 0xB3, 0x46,
  25056. 0x69, 0xF9, 0x1D, 0xA8, 0x65, 0x4D, 0x1E, 0xB7,
  25057. 0x2E, 0xB6, 0xE0, 0x28, 0x00, 0xB3, 0xB0, 0xA7,
  25058. 0xD0, 0xA4, 0x8C, 0x83, 0x68, 0x54, 0xD3, 0xA8,
  25059. 0x3E, 0x65, 0x56, 0x9C, 0xB7, 0x23, 0x0B, 0xB4,
  25060. 0x4F, 0x3F, 0x14, 0x3A, 0x6D, 0xEC, 0x5F, 0x2C,
  25061. 0x39, 0xAB, 0x90, 0xF2, 0x74, 0xF2, 0x08, 0x8B,
  25062. 0xD3, 0xD6, 0xA6, 0xFC, 0xA0, 0x07, 0x02, 0x73,
  25063. 0xBE, 0xDC, 0x84, 0x77, 0x7F, 0xB5, 0x2E, 0x3C,
  25064. 0x55, 0x8B, 0x0A, 0xE0, 0x61, 0x83, 0xD5, 0xA4,
  25065. 0x8D, 0x45, 0x2F, 0x68, 0xE1, 0x52, 0x07, 0xF8,
  25066. 0x61, 0x62, 0x7A, 0xCA, 0x14, 0x27, 0x96, 0x30,
  25067. 0xF8, 0x2E, 0xC3, 0xA0, 0xCA, 0x07, 0x86, 0x33,
  25068. 0xB6, 0x00, 0xAF, 0xA7, 0x97, 0x43, 0xA6, 0x00,
  25069. 0x21, 0x5B, 0xE5, 0x63, 0x74, 0x58, 0xCE, 0x2C,
  25070. 0xE8, 0xAF, 0xF5, 0xA0, 0x8E, 0xB5, 0x01, 0x7B,
  25071. 0x2C, 0x76, 0x65, 0x77, 0x47, 0x9F, 0x8D, 0xC6,
  25072. 0xBF, 0x9F, 0x5C, 0xC7, 0x50, 0x89, 0x93, 0x21,
  25073. 0x61, 0xB9, 0x6C, 0xEA, 0x40, 0x66, 0x20, 0xAE,
  25074. 0xDB, 0x63, 0x04, 0x07, 0xF7, 0x68, 0x7E, 0xBB,
  25075. 0xB4, 0x81, 0x4C, 0x79, 0x81, 0x63, 0x7A, 0x48,
  25076. 0xA9, 0x0D, 0xE6, 0x80, 0x31, 0xE0, 0x62, 0xA7,
  25077. 0xAF, 0x76, 0x12, 0xB4, 0xF5, 0xC7, 0xA6, 0xDA,
  25078. 0x86, 0xBD, 0x13, 0x65, 0x29, 0xE6, 0x42, 0x95,
  25079. 0xA5, 0x61, 0x3E, 0xA7, 0x3B, 0xD3, 0xD4, 0x44,
  25080. 0x8C, 0xB8, 0x1F, 0x24, 0x31, 0x35, 0xC0, 0xA6,
  25081. 0x60, 0xBE, 0xB9, 0xC1, 0x7E, 0x65, 0x1D, 0xEF,
  25082. 0x46, 0x9A, 0x7D, 0x90, 0xA1, 0x5D, 0x34, 0x81,
  25083. 0x09, 0x0B, 0xCB, 0xF2, 0x27, 0x01, 0x23, 0x28,
  25084. 0x94, 0x1F, 0xA4, 0x6F, 0x39, 0xC5, 0x00, 0x6A,
  25085. 0xD9, 0x3D, 0x45, 0x8A, 0xA6, 0xAD, 0xD6, 0x55,
  25086. 0x86, 0x2B, 0x41, 0x8C, 0x30, 0x94, 0xF5, 0x51,
  25087. 0x46, 0x0D, 0xF2, 0x15, 0x3A, 0x58, 0x10, 0xA7,
  25088. 0xDA, 0x74, 0xF0, 0x61, 0x4C, 0x25, 0x88, 0xBE,
  25089. 0x49, 0xDC, 0x6F, 0x5E, 0x88, 0x15, 0x46, 0x42,
  25090. 0xBD, 0x1D, 0x37, 0x62, 0x56, 0x33, 0x26, 0x43,
  25091. 0x35, 0x07, 0x15, 0x6A, 0x57, 0xC5, 0x76, 0x94,
  25092. 0xBD, 0xD2, 0x6E, 0x7A, 0x24, 0x6F, 0xEB, 0x72,
  25093. 0x3A, 0xED, 0x67, 0xB0, 0x48, 0x87, 0xC8, 0xE4,
  25094. 0x76, 0xB4, 0x8C, 0xAB, 0x59, 0xE5, 0x36, 0x2F,
  25095. 0x26, 0xA9, 0xEF, 0x50, 0xC2, 0xBC, 0x80, 0xBA,
  25096. 0x14, 0x62, 0x26, 0x21, 0x6F, 0xE6, 0x29, 0x68,
  25097. 0xA6, 0x0D, 0x04, 0xE8, 0xC1, 0x70, 0xD7, 0x41,
  25098. 0xC7, 0xA2, 0xB0, 0xE1, 0xAB, 0xDA, 0xC9, 0x68
  25099. };
  25100. static const byte dk_768[KYBER768_PRIVATE_KEY_SIZE] = {
  25101. 0x98, 0xA1, 0xB2, 0xDA, 0x4A, 0x65, 0xCF, 0xB5,
  25102. 0x84, 0x5E, 0xA7, 0x31, 0x1E, 0x6A, 0x06, 0xDB,
  25103. 0x73, 0x1F, 0x15, 0x90, 0xC4, 0x1E, 0xE7, 0x4B,
  25104. 0xA1, 0x07, 0x82, 0x71, 0x5B, 0x35, 0xA3, 0x10,
  25105. 0x2D, 0xF6, 0x37, 0x87, 0x2B, 0xE6, 0x5B, 0xAB,
  25106. 0x37, 0xA1, 0xDE, 0x25, 0x11, 0xD7, 0x03, 0xC7,
  25107. 0x02, 0x47, 0xB3, 0x5E, 0xF2, 0x74, 0x35, 0x48,
  25108. 0x50, 0x24, 0xD9, 0x3F, 0xD9, 0xE7, 0x7C, 0x43,
  25109. 0x80, 0x4F, 0x37, 0x17, 0x49, 0xBA, 0x00, 0xB2,
  25110. 0x0A, 0x8C, 0x5C, 0x58, 0x8B, 0xC9, 0xAB, 0xE0,
  25111. 0x68, 0xAE, 0xAA, 0xA9, 0x38, 0x51, 0x7E, 0xBF,
  25112. 0xE5, 0x3B, 0x6B, 0x66, 0x32, 0x82, 0x90, 0x3D,
  25113. 0xCD, 0x18, 0x97, 0x36, 0xD7, 0x29, 0x68, 0x16,
  25114. 0xC7, 0x33, 0xA1, 0xC7, 0x7C, 0x63, 0x75, 0xE5,
  25115. 0x39, 0x7C, 0x0F, 0x18, 0x9B, 0xBF, 0xE4, 0x76,
  25116. 0x43, 0xA6, 0x1F, 0x58, 0xF8, 0xA3, 0xC6, 0x91,
  25117. 0x1B, 0xE4, 0x61, 0x1A, 0x8C, 0x7B, 0xC0, 0x50,
  25118. 0x02, 0x11, 0x63, 0xD0, 0xA4, 0x04, 0xDC, 0x14,
  25119. 0x06, 0x57, 0x48, 0xFF, 0x29, 0xBE, 0x60, 0xD2,
  25120. 0xB9, 0xFD, 0xCC, 0x8F, 0xFD, 0x98, 0xC5, 0x87,
  25121. 0xF3, 0x8C, 0x67, 0x11, 0x57, 0x86, 0x46, 0x4B,
  25122. 0xDB, 0x34, 0x2B, 0x17, 0xE8, 0x97, 0xD6, 0x46,
  25123. 0x17, 0xCB, 0xFB, 0x11, 0x79, 0x73, 0xA5, 0x45,
  25124. 0x89, 0x77, 0xA7, 0xD7, 0x61, 0x7A, 0x1B, 0x4D,
  25125. 0x83, 0xBA, 0x03, 0xC6, 0x11, 0x13, 0x8A, 0x46,
  25126. 0x73, 0xB1, 0xEB, 0x34, 0xB0, 0x78, 0x03, 0x3F,
  25127. 0x97, 0xCF, 0xFE, 0x80, 0xC1, 0x46, 0xA2, 0x69,
  25128. 0x43, 0xF8, 0x42, 0xB9, 0x76, 0x32, 0x7B, 0xF1,
  25129. 0xCB, 0xC6, 0x01, 0x19, 0x52, 0x5B, 0xB9, 0xA3,
  25130. 0xC0, 0x34, 0x93, 0x34, 0x90, 0x00, 0xDD, 0x8F,
  25131. 0x51, 0xBA, 0x21, 0xA2, 0xE9, 0x23, 0x61, 0x76,
  25132. 0x23, 0x24, 0x60, 0x0E, 0x0C, 0x13, 0xAA, 0xA6,
  25133. 0xCB, 0x69, 0xBF, 0xB2, 0x42, 0x76, 0x48, 0x3F,
  25134. 0x6B, 0x02, 0x42, 0x12, 0x59, 0xB7, 0x58, 0x52,
  25135. 0x63, 0xC1, 0xA0, 0x28, 0xD6, 0x82, 0xC5, 0x08,
  25136. 0xBB, 0xC2, 0x80, 0x1A, 0x56, 0xE9, 0x8B, 0x8F,
  25137. 0x62, 0x0B, 0x04, 0x83, 0xD7, 0x9B, 0x5A, 0xD8,
  25138. 0x58, 0x5A, 0xC0, 0xA4, 0x75, 0xBA, 0xC7, 0x78,
  25139. 0x65, 0x19, 0x41, 0x96, 0x33, 0x87, 0x91, 0xB7,
  25140. 0x98, 0x5A, 0x05, 0xD1, 0x09, 0x39, 0x5C, 0xCA,
  25141. 0x89, 0x32, 0x72, 0x2A, 0x91, 0x95, 0x0D, 0x37,
  25142. 0xE1, 0x2B, 0x89, 0x14, 0x20, 0xA5, 0x2B, 0x62,
  25143. 0xCB, 0xFA, 0x81, 0x5D, 0xF6, 0x17, 0x4C, 0xE0,
  25144. 0x0E, 0x68, 0xBC, 0xA7, 0x5D, 0x48, 0x38, 0xCA,
  25145. 0x28, 0x0F, 0x71, 0x3C, 0x7E, 0x69, 0x24, 0xAF,
  25146. 0xD9, 0x5B, 0xAA, 0x0D, 0x01, 0xAD, 0xA6, 0x37,
  25147. 0xB1, 0x58, 0x34, 0x70, 0x34, 0xC0, 0xAB, 0x1A,
  25148. 0x71, 0x83, 0x33, 0x1A, 0x82, 0x0A, 0xCB, 0xCB,
  25149. 0x83, 0x19, 0x3A, 0x1A, 0x94, 0xC8, 0xF7, 0xE3,
  25150. 0x84, 0xAE, 0xD0, 0xC3, 0x5E, 0xD3, 0xCB, 0x33,
  25151. 0x97, 0xBB, 0x63, 0x80, 0x86, 0xE7, 0xA3, 0x5A,
  25152. 0x64, 0x08, 0xA3, 0xA4, 0xB9, 0x0C, 0xE9, 0x53,
  25153. 0x70, 0x7C, 0x19, 0xBC, 0x46, 0xC3, 0xB2, 0xDA,
  25154. 0x3B, 0x2E, 0xE3, 0x23, 0x19, 0xC5, 0x6B, 0x92,
  25155. 0x80, 0x32, 0xB5, 0xED, 0x12, 0x56, 0xD0, 0x75,
  25156. 0x3D, 0x34, 0x14, 0x23, 0xE9, 0xDB, 0x13, 0x9D,
  25157. 0xE7, 0x71, 0x4F, 0xF0, 0x75, 0xCA, 0xF5, 0x8F,
  25158. 0xD9, 0xF5, 0x7D, 0x1A, 0x54, 0x01, 0x9B, 0x59,
  25159. 0x26, 0x40, 0x68, 0x30, 0xDA, 0xE2, 0x9A, 0x87,
  25160. 0x53, 0x02, 0xA8, 0x12, 0x56, 0xF4, 0xD6, 0xCF,
  25161. 0x5E, 0x74, 0x03, 0x4E, 0xA6, 0x14, 0xBF, 0x70,
  25162. 0xC2, 0x76, 0x4B, 0x20, 0xC9, 0x58, 0x9C, 0xDB,
  25163. 0x5C, 0x25, 0x76, 0x1A, 0x04, 0xE5, 0x82, 0x92,
  25164. 0x90, 0x7C, 0x57, 0x8A, 0x94, 0xA3, 0x58, 0x36,
  25165. 0xBE, 0xE3, 0x11, 0x2D, 0xC2, 0xC3, 0xAE, 0x21,
  25166. 0x92, 0xC9, 0xDE, 0xAA, 0x30, 0x4B, 0x29, 0xC7,
  25167. 0xFE, 0xA1, 0xBD, 0xF4, 0x7B, 0x3B, 0x6B, 0xCB,
  25168. 0xA2, 0xC0, 0xE5, 0x5C, 0x9C, 0xDB, 0x6D, 0xE7,
  25169. 0x14, 0x9E, 0x9C, 0xB1, 0x79, 0x17, 0x71, 0x8F,
  25170. 0x12, 0xC8, 0x03, 0x2D, 0xE1, 0xAD, 0xE0, 0x64,
  25171. 0x8D, 0x40, 0x55, 0x19, 0xC7, 0x07, 0x19, 0xBE,
  25172. 0xCC, 0x70, 0x18, 0x45, 0xCF, 0x9F, 0x4B, 0x91,
  25173. 0x2F, 0xE7, 0x19, 0x83, 0xCA, 0x34, 0xF9, 0x01,
  25174. 0x8C, 0x7C, 0xA7, 0xBB, 0x2F, 0x6C, 0x5D, 0x7F,
  25175. 0x8C, 0x5B, 0x29, 0x73, 0x59, 0xEC, 0x75, 0x20,
  25176. 0x9C, 0x25, 0x43, 0xFF, 0x11, 0xC4, 0x24, 0x49,
  25177. 0x77, 0xC5, 0x96, 0x95, 0x24, 0xEC, 0x45, 0x4D,
  25178. 0x44, 0xC3, 0x23, 0xFC, 0xCA, 0x94, 0xAC, 0xAC,
  25179. 0x27, 0x3A, 0x0E, 0xC4, 0x9B, 0x4A, 0x8A, 0x58,
  25180. 0x5B, 0xCE, 0x7A, 0x5B, 0x30, 0x5C, 0x04, 0xC3,
  25181. 0x50, 0x64, 0x22, 0x58, 0x03, 0x57, 0x01, 0x6A,
  25182. 0x85, 0x0C, 0x3F, 0x7E, 0xE1, 0x72, 0x05, 0xA7,
  25183. 0x7B, 0x29, 0x1C, 0x77, 0x31, 0xC9, 0x83, 0x6C,
  25184. 0x02, 0xAE, 0xE5, 0x40, 0x6F, 0x63, 0xC6, 0xA0,
  25185. 0x7A, 0x21, 0x43, 0x82, 0xAA, 0x15, 0x33, 0x6C,
  25186. 0x05, 0xD1, 0x04, 0x55, 0x88, 0x10, 0x76, 0x45,
  25187. 0xEA, 0x7D, 0xE6, 0x87, 0x0F, 0xC0, 0xE5, 0x5E,
  25188. 0x15, 0x40, 0x97, 0x43, 0x01, 0xC4, 0x2E, 0xC1,
  25189. 0x41, 0x05, 0x51, 0x86, 0x80, 0xF6, 0x88, 0xAB,
  25190. 0xE4, 0xCE, 0x45, 0x37, 0x38, 0xFE, 0x47, 0x1B,
  25191. 0x87, 0xFC, 0x31, 0xF5, 0xC6, 0x8A, 0x39, 0xE6,
  25192. 0x8A, 0xF5, 0x1B, 0x02, 0x40, 0xB9, 0x0E, 0x03,
  25193. 0x64, 0xB0, 0x4B, 0xAC, 0x43, 0xD6, 0xFB, 0x68,
  25194. 0xAB, 0x65, 0xAE, 0x02, 0x8B, 0x62, 0xBD, 0x68,
  25195. 0x3B, 0x7D, 0x28, 0xAD, 0x38, 0x80, 0x6B, 0xEE,
  25196. 0x72, 0x5B, 0x5B, 0x24, 0x16, 0xA8, 0xD7, 0x9C,
  25197. 0x16, 0xEC, 0x2A, 0x99, 0xEA, 0x4A, 0x8D, 0x92,
  25198. 0xA2, 0xF5, 0x05, 0x2E, 0x67, 0xF9, 0x73, 0x52,
  25199. 0x28, 0x97, 0x61, 0xC5, 0xC3, 0x9F, 0xC5, 0xC7,
  25200. 0x42, 0xE9, 0xC0, 0xA7, 0x40, 0xCA, 0x59, 0xFC,
  25201. 0x01, 0x82, 0xF7, 0x09, 0xD0, 0x1B, 0x51, 0x87,
  25202. 0xF0, 0x00, 0x63, 0xDA, 0xAB, 0x39, 0x75, 0x96,
  25203. 0xEE, 0xA4, 0xA3, 0x1B, 0xDB, 0xCB, 0xD4, 0xC1,
  25204. 0xBB, 0x0C, 0x55, 0xBE, 0x7C, 0x68, 0x50, 0xFD,
  25205. 0xA9, 0x32, 0x6B, 0x35, 0x3E, 0x28, 0x8C, 0x50,
  25206. 0x13, 0x22, 0x6C, 0x3C, 0x39, 0x23, 0xA7, 0x91,
  25207. 0x60, 0x9E, 0x80, 0x02, 0xE7, 0x3A, 0x5F, 0x7B,
  25208. 0x6B, 0xB4, 0xA8, 0x77, 0xB1, 0xFD, 0xF5, 0x3B,
  25209. 0xB2, 0xBA, 0xB3, 0xDD, 0x42, 0x4D, 0x31, 0xBB,
  25210. 0xB4, 0x48, 0xE6, 0x09, 0xA6, 0x6B, 0x0E, 0x34,
  25211. 0x3C, 0x28, 0x6E, 0x87, 0x60, 0x31, 0x2B, 0x6D,
  25212. 0x37, 0xAA, 0x52, 0x01, 0xD2, 0x1F, 0x53, 0x50,
  25213. 0x3D, 0x88, 0x38, 0x9A, 0xDC, 0xA2, 0x1C, 0x70,
  25214. 0xFB, 0x6C, 0x0F, 0xC9, 0xC6, 0x9D, 0x66, 0x16,
  25215. 0xC9, 0xEA, 0x37, 0x80, 0xE3, 0x55, 0x65, 0xC0,
  25216. 0xC9, 0x7C, 0x15, 0x17, 0x9C, 0x95, 0x34, 0x3E,
  25217. 0xCC, 0x5E, 0x1C, 0x2A, 0x24, 0xDE, 0x46, 0x99,
  25218. 0xF6, 0x87, 0x5E, 0xA2, 0xFA, 0x2D, 0xD3, 0xE3,
  25219. 0x57, 0xBC, 0x43, 0x91, 0x47, 0x95, 0x20, 0x7E,
  25220. 0x02, 0x6B, 0x85, 0x0A, 0x22, 0x37, 0x95, 0x0C,
  25221. 0x10, 0x8A, 0x51, 0x2F, 0xC8, 0x8C, 0x22, 0x48,
  25222. 0x81, 0x12, 0x60, 0x70, 0x88, 0x18, 0x5F, 0xB0,
  25223. 0xE0, 0x9C, 0x2C, 0x41, 0x97, 0xA8, 0x36, 0x87,
  25224. 0x26, 0x6B, 0xAB, 0x2E, 0x58, 0x3E, 0x21, 0xC4,
  25225. 0x0F, 0x4C, 0xC0, 0x08, 0xFE, 0x65, 0x28, 0x04,
  25226. 0xD8, 0x22, 0x3F, 0x15, 0x20, 0xA9, 0x0B, 0x0D,
  25227. 0x53, 0x85, 0xC7, 0x55, 0x3C, 0xC7, 0x67, 0xC5,
  25228. 0x8D, 0x12, 0x0C, 0xCD, 0x3E, 0xF5, 0xB5, 0xD1,
  25229. 0xA6, 0xCD, 0x7B, 0xC0, 0x0D, 0xFF, 0x13, 0x21,
  25230. 0xB2, 0xF2, 0xC4, 0x32, 0xB6, 0x4E, 0xFB, 0x8A,
  25231. 0x3F, 0x5D, 0x00, 0x64, 0xB3, 0xF3, 0x42, 0x93,
  25232. 0x02, 0x6C, 0x85, 0x1C, 0x2D, 0xED, 0x68, 0xB9,
  25233. 0xDF, 0xF4, 0xA2, 0x8F, 0x6A, 0x8D, 0x22, 0x55,
  25234. 0x35, 0xE0, 0x47, 0x70, 0x84, 0x43, 0x0C, 0xFF,
  25235. 0xDA, 0x0A, 0xC0, 0x55, 0x2F, 0x9A, 0x21, 0x27,
  25236. 0x85, 0xB7, 0x49, 0x91, 0x3A, 0x06, 0xFA, 0x22,
  25237. 0x74, 0xC0, 0xD1, 0x5B, 0xAD, 0x32, 0x54, 0x58,
  25238. 0xD3, 0x23, 0xEF, 0x6B, 0xAE, 0x13, 0xC0, 0x01,
  25239. 0x0D, 0x52, 0x5C, 0x1D, 0x52, 0x69, 0x97, 0x3A,
  25240. 0xC2, 0x9B, 0xDA, 0x7C, 0x98, 0x37, 0x46, 0x91,
  25241. 0x8B, 0xA0, 0xE0, 0x02, 0x58, 0x8E, 0x30, 0x37,
  25242. 0x5D, 0x78, 0x32, 0x9E, 0x6B, 0x8B, 0xA8, 0xC4,
  25243. 0x46, 0x2A, 0x69, 0x2F, 0xB6, 0x08, 0x38, 0x42,
  25244. 0xB8, 0xC8, 0xC9, 0x2C, 0x60, 0xF2, 0x52, 0x72,
  25245. 0x6D, 0x14, 0xA0, 0x71, 0xF7, 0xCC, 0x45, 0x25,
  25246. 0x58, 0xD5, 0xE7, 0x1A, 0x7B, 0x08, 0x70, 0x62,
  25247. 0xEC, 0xB1, 0x38, 0x68, 0x44, 0x58, 0x82, 0x46,
  25248. 0x12, 0x64, 0x02, 0xB1, 0xFA, 0x16, 0x37, 0x73,
  25249. 0x3C, 0xD5, 0xF6, 0x0C, 0xC8, 0x4B, 0xCB, 0x64,
  25250. 0x6A, 0x78, 0x92, 0x61, 0x4D, 0x7C, 0x51, 0xB1,
  25251. 0xC7, 0xF1, 0xA2, 0x79, 0x91, 0x32, 0xF1, 0x34,
  25252. 0x27, 0xDC, 0x48, 0x21, 0x58, 0xDA, 0x25, 0x44,
  25253. 0x70, 0xA5, 0x9E, 0x00, 0xA4, 0xE4, 0x96, 0x86,
  25254. 0xFD, 0xC0, 0x77, 0x55, 0x93, 0x67, 0x27, 0x0C,
  25255. 0x21, 0x53, 0xF1, 0x10, 0x07, 0x59, 0x2C, 0x9C,
  25256. 0x43, 0x10, 0xCF, 0x8A, 0x12, 0xC6, 0xA8, 0x71,
  25257. 0x3B, 0xD6, 0xBB, 0x51, 0xF3, 0x12, 0x4F, 0x98,
  25258. 0x9B, 0xA0, 0xD5, 0x40, 0x73, 0xCC, 0x24, 0x2E,
  25259. 0x09, 0x68, 0x78, 0x0B, 0x87, 0x5A, 0x86, 0x9E,
  25260. 0xFB, 0x85, 0x15, 0x86, 0xB9, 0xA8, 0x68, 0xA3,
  25261. 0x84, 0xB9, 0xE6, 0x82, 0x1B, 0x20, 0x1B, 0x93,
  25262. 0x2C, 0x45, 0x53, 0x69, 0xA7, 0x39, 0xEC, 0x22,
  25263. 0x56, 0x9C, 0x97, 0x7C, 0x21, 0x2B, 0x38, 0x18,
  25264. 0x71, 0x81, 0x36, 0x56, 0xAF, 0x5B, 0x56, 0x7E,
  25265. 0xF8, 0x93, 0xB5, 0x84, 0x62, 0x4C, 0x86, 0x3A,
  25266. 0x25, 0x90, 0x00, 0xF1, 0x7B, 0x25, 0x4B, 0x98,
  25267. 0xB1, 0x85, 0x09, 0x7C, 0x50, 0xEB, 0xB6, 0x8B,
  25268. 0x24, 0x43, 0x42, 0xE0, 0x5D, 0x4D, 0xE5, 0x20,
  25269. 0x12, 0x5B, 0x8E, 0x10, 0x33, 0xB1, 0x43, 0x60,
  25270. 0x93, 0xAC, 0xE7, 0xCE, 0x8E, 0x71, 0xB4, 0x58,
  25271. 0xD5, 0x25, 0x67, 0x33, 0x63, 0x04, 0x5A, 0x3B,
  25272. 0x3E, 0xEA, 0x94, 0x55, 0x42, 0x8A, 0x39, 0x87,
  25273. 0x05, 0xA4, 0x23, 0x27, 0xAD, 0xB3, 0x77, 0x4B,
  25274. 0x70, 0x57, 0xF4, 0x2B, 0x01, 0x7E, 0xC0, 0x73,
  25275. 0x9A, 0x98, 0x3F, 0x19, 0xE8, 0x21, 0x4D, 0x09,
  25276. 0x19, 0x5F, 0xA2, 0x4D, 0x2D, 0x57, 0x1D, 0xB7,
  25277. 0x3C, 0x19, 0xA6, 0xF8, 0x46, 0x0E, 0x50, 0x83,
  25278. 0x0D, 0x41, 0x5F, 0x62, 0x7B, 0x88, 0xE9, 0x4A,
  25279. 0x7B, 0x15, 0x37, 0x91, 0xA0, 0xC0, 0xC7, 0xE9,
  25280. 0x48, 0x4C, 0x74, 0xD5, 0x3C, 0x71, 0x48, 0x89,
  25281. 0xF0, 0xE3, 0x21, 0xB6, 0x66, 0x0A, 0x53, 0x2A,
  25282. 0x5B, 0xC0, 0xE5, 0x57, 0xFB, 0xCA, 0x35, 0xE2,
  25283. 0x9B, 0xC6, 0x11, 0x20, 0x0E, 0xD3, 0xC6, 0x33,
  25284. 0x07, 0x7A, 0x4D, 0x87, 0x3C, 0x5C, 0xC6, 0x70,
  25285. 0x06, 0xB7, 0x53, 0xBF, 0x6D, 0x6B, 0x7A, 0xF6,
  25286. 0xCA, 0x40, 0x2A, 0xB6, 0x18, 0x23, 0x6C, 0x0A,
  25287. 0xFF, 0xBC, 0x80, 0x1F, 0x82, 0x22, 0xFB, 0xC3,
  25288. 0x6C, 0xE0, 0x98, 0x4E, 0x2B, 0x18, 0xC9, 0x44,
  25289. 0xBB, 0xCB, 0xEF, 0x03, 0xB1, 0xE1, 0x36, 0x1C,
  25290. 0x1F, 0x44, 0xB0, 0xD7, 0x34, 0xAF, 0xB1, 0x56,
  25291. 0x6C, 0xFF, 0x87, 0x44, 0xDA, 0x8B, 0x99, 0x43,
  25292. 0xD6, 0xB4, 0x5A, 0x3C, 0x09, 0x03, 0x07, 0x02,
  25293. 0xCA, 0x20, 0x1F, 0xFE, 0x20, 0xCB, 0x7E, 0xC5,
  25294. 0xB0, 0xD4, 0x14, 0x9E, 0xE2, 0xC2, 0x8E, 0x8B,
  25295. 0x23, 0x37, 0x4F, 0x47, 0x1B, 0x57, 0x15, 0x0D,
  25296. 0x0E, 0xC9, 0x33, 0x62, 0x61, 0xA2, 0xD5, 0xCB,
  25297. 0x84, 0xA3, 0xAC, 0xAC, 0xC4, 0x28, 0x94, 0x73,
  25298. 0xA4, 0xC0, 0xAB, 0xC6, 0x17, 0xC9, 0xAB, 0xC1,
  25299. 0x78, 0x73, 0x44, 0x34, 0xC8, 0x2E, 0x16, 0x85,
  25300. 0x58, 0x8A, 0x5C, 0x2E, 0xA2, 0x67, 0x8F, 0x6B,
  25301. 0x3C, 0x22, 0x28, 0x73, 0x31, 0x30, 0xC4, 0x66,
  25302. 0xE5, 0xB8, 0x6E, 0xF4, 0x91, 0x15, 0x3E, 0x48,
  25303. 0x66, 0x22, 0x47, 0xB8, 0x75, 0xD2, 0x01, 0x02,
  25304. 0x0B, 0x56, 0x6B, 0x81, 0xB6, 0x4D, 0x83, 0x9A,
  25305. 0xB4, 0x63, 0x3B, 0xAA, 0x8A, 0xCE, 0x20, 0x2B,
  25306. 0xAA, 0xB4, 0x49, 0x62, 0x97, 0xF9, 0x80, 0x7A,
  25307. 0xDB, 0xBB, 0x1E, 0x33, 0x2C, 0x6F, 0x80, 0x22,
  25308. 0xB2, 0xA1, 0x8C, 0xFD, 0xD4, 0xA8, 0x25, 0x30,
  25309. 0xB6, 0xD3, 0xF0, 0x07, 0xC3, 0x35, 0x38, 0x98,
  25310. 0xD9, 0x66, 0xCC, 0x2C, 0x21, 0xCB, 0x42, 0x44,
  25311. 0xBD, 0x00, 0x44, 0x3F, 0x20, 0x98, 0x70, 0xAC,
  25312. 0xC4, 0x2B, 0xC3, 0x30, 0x68, 0xC7, 0x24, 0xEC,
  25313. 0x17, 0x22, 0x36, 0x19, 0xC1, 0x09, 0x3C, 0xCA,
  25314. 0x6A, 0xEB, 0x29, 0x50, 0x06, 0x64, 0xD1, 0x22,
  25315. 0x50, 0x36, 0xB4, 0xB8, 0x10, 0x91, 0x90, 0x69,
  25316. 0x69, 0x48, 0x1F, 0x1C, 0x72, 0x3C, 0x14, 0x0B,
  25317. 0x9D, 0x6C, 0x16, 0x8F, 0x5B, 0x64, 0xBE, 0xA6,
  25318. 0x9C, 0x5F, 0xD6, 0x38, 0x5D, 0xF7, 0x36, 0x4B,
  25319. 0x87, 0x23, 0xBC, 0xC8, 0x5E, 0x03, 0x8C, 0x7E,
  25320. 0x46, 0x4A, 0x90, 0x0D, 0x68, 0xA2, 0x12, 0x78,
  25321. 0x18, 0x99, 0x42, 0x17, 0xAE, 0xC8, 0xBD, 0xB3,
  25322. 0x9A, 0x97, 0x0A, 0x99, 0x63, 0xDE, 0x93, 0x68,
  25323. 0x8E, 0x2A, 0xC8, 0x2A, 0xBC, 0xC2, 0x2F, 0xB9,
  25324. 0x27, 0x7B, 0xA2, 0x20, 0x09, 0xE8, 0x78, 0x38,
  25325. 0x1A, 0x38, 0x16, 0x39, 0x01, 0xC7, 0xD4, 0xC8,
  25326. 0x50, 0x19, 0x53, 0x8D, 0x35, 0xCA, 0xAE, 0x9C,
  25327. 0x41, 0xAF, 0x8C, 0x92, 0x9E, 0xE2, 0x0B, 0xB0,
  25328. 0x8C, 0xA6, 0x19, 0xE7, 0x2C, 0x2F, 0x22, 0x62,
  25329. 0xC1, 0xC9, 0x93, 0x85, 0x72, 0x55, 0x1A, 0xC0,
  25330. 0x2D, 0xC9, 0x26, 0x8F, 0xBC, 0xC3, 0x5D, 0x79,
  25331. 0x01, 0x1C, 0x3C, 0x09, 0x0A, 0xD4, 0x0A, 0x4F,
  25332. 0x11, 0x1C, 0x9B, 0xE5, 0x5C, 0x42, 0x7E, 0xB7,
  25333. 0x96, 0xC1, 0x93, 0x2D, 0x86, 0x73, 0x57, 0x9A,
  25334. 0xF1, 0xB4, 0xC6, 0x38, 0xB0, 0x94, 0x44, 0x89,
  25335. 0x01, 0x2A, 0x25, 0x59, 0xA3, 0xB0, 0x24, 0x81,
  25336. 0xB0, 0x1A, 0xC3, 0x0B, 0xA8, 0x96, 0x0F, 0x80,
  25337. 0xC0, 0xC2, 0xB3, 0x94, 0x7D, 0x36, 0xA1, 0x2C,
  25338. 0x08, 0x04, 0x98, 0xBE, 0xE4, 0x48, 0x71, 0x6C,
  25339. 0x97, 0x34, 0x16, 0xC8, 0x24, 0x28, 0x04, 0xA3,
  25340. 0xDA, 0x09, 0x9E, 0xE1, 0x37, 0xB0, 0xBA, 0x90,
  25341. 0xFE, 0x4A, 0x5C, 0x6A, 0x89, 0x20, 0x02, 0x76,
  25342. 0xA0, 0xCF, 0xB6, 0x43, 0xEC, 0x2C, 0x56, 0xA2,
  25343. 0xD7, 0x08, 0xD7, 0xB4, 0x37, 0x3E, 0x44, 0xC1,
  25344. 0x50, 0x2A, 0x76, 0x3A, 0x60, 0x05, 0x86, 0xE6,
  25345. 0xCD, 0xA6, 0x27, 0x38, 0x97, 0xD4, 0x44, 0x48,
  25346. 0x28, 0x7D, 0xC2, 0xE6, 0x02, 0xDC, 0x39, 0x20,
  25347. 0x0B, 0xF6, 0x16, 0x62, 0x36, 0x55, 0x9F, 0xD1,
  25348. 0x2A, 0x60, 0x89, 0x2A, 0xEB, 0x15, 0x3D, 0xD6,
  25349. 0x51, 0xBB, 0x46, 0x99, 0x10, 0xB4, 0xB3, 0x46,
  25350. 0x69, 0xF9, 0x1D, 0xA8, 0x65, 0x4D, 0x1E, 0xB7,
  25351. 0x2E, 0xB6, 0xE0, 0x28, 0x00, 0xB3, 0xB0, 0xA7,
  25352. 0xD0, 0xA4, 0x8C, 0x83, 0x68, 0x54, 0xD3, 0xA8,
  25353. 0x3E, 0x65, 0x56, 0x9C, 0xB7, 0x23, 0x0B, 0xB4,
  25354. 0x4F, 0x3F, 0x14, 0x3A, 0x6D, 0xEC, 0x5F, 0x2C,
  25355. 0x39, 0xAB, 0x90, 0xF2, 0x74, 0xF2, 0x08, 0x8B,
  25356. 0xD3, 0xD6, 0xA6, 0xFC, 0xA0, 0x07, 0x02, 0x73,
  25357. 0xBE, 0xDC, 0x84, 0x77, 0x7F, 0xB5, 0x2E, 0x3C,
  25358. 0x55, 0x8B, 0x0A, 0xE0, 0x61, 0x83, 0xD5, 0xA4,
  25359. 0x8D, 0x45, 0x2F, 0x68, 0xE1, 0x52, 0x07, 0xF8,
  25360. 0x61, 0x62, 0x7A, 0xCA, 0x14, 0x27, 0x96, 0x30,
  25361. 0xF8, 0x2E, 0xC3, 0xA0, 0xCA, 0x07, 0x86, 0x33,
  25362. 0xB6, 0x00, 0xAF, 0xA7, 0x97, 0x43, 0xA6, 0x00,
  25363. 0x21, 0x5B, 0xE5, 0x63, 0x74, 0x58, 0xCE, 0x2C,
  25364. 0xE8, 0xAF, 0xF5, 0xA0, 0x8E, 0xB5, 0x01, 0x7B,
  25365. 0x2C, 0x76, 0x65, 0x77, 0x47, 0x9F, 0x8D, 0xC6,
  25366. 0xBF, 0x9F, 0x5C, 0xC7, 0x50, 0x89, 0x93, 0x21,
  25367. 0x61, 0xB9, 0x6C, 0xEA, 0x40, 0x66, 0x20, 0xAE,
  25368. 0xDB, 0x63, 0x04, 0x07, 0xF7, 0x68, 0x7E, 0xBB,
  25369. 0xB4, 0x81, 0x4C, 0x79, 0x81, 0x63, 0x7A, 0x48,
  25370. 0xA9, 0x0D, 0xE6, 0x80, 0x31, 0xE0, 0x62, 0xA7,
  25371. 0xAF, 0x76, 0x12, 0xB4, 0xF5, 0xC7, 0xA6, 0xDA,
  25372. 0x86, 0xBD, 0x13, 0x65, 0x29, 0xE6, 0x42, 0x95,
  25373. 0xA5, 0x61, 0x3E, 0xA7, 0x3B, 0xD3, 0xD4, 0x44,
  25374. 0x8C, 0xB8, 0x1F, 0x24, 0x31, 0x35, 0xC0, 0xA6,
  25375. 0x60, 0xBE, 0xB9, 0xC1, 0x7E, 0x65, 0x1D, 0xEF,
  25376. 0x46, 0x9A, 0x7D, 0x90, 0xA1, 0x5D, 0x34, 0x81,
  25377. 0x09, 0x0B, 0xCB, 0xF2, 0x27, 0x01, 0x23, 0x28,
  25378. 0x94, 0x1F, 0xA4, 0x6F, 0x39, 0xC5, 0x00, 0x6A,
  25379. 0xD9, 0x3D, 0x45, 0x8A, 0xA6, 0xAD, 0xD6, 0x55,
  25380. 0x86, 0x2B, 0x41, 0x8C, 0x30, 0x94, 0xF5, 0x51,
  25381. 0x46, 0x0D, 0xF2, 0x15, 0x3A, 0x58, 0x10, 0xA7,
  25382. 0xDA, 0x74, 0xF0, 0x61, 0x4C, 0x25, 0x88, 0xBE,
  25383. 0x49, 0xDC, 0x6F, 0x5E, 0x88, 0x15, 0x46, 0x42,
  25384. 0xBD, 0x1D, 0x37, 0x62, 0x56, 0x33, 0x26, 0x43,
  25385. 0x35, 0x07, 0x15, 0x6A, 0x57, 0xC5, 0x76, 0x94,
  25386. 0xBD, 0xD2, 0x6E, 0x7A, 0x24, 0x6F, 0xEB, 0x72,
  25387. 0x3A, 0xED, 0x67, 0xB0, 0x48, 0x87, 0xC8, 0xE4,
  25388. 0x76, 0xB4, 0x8C, 0xAB, 0x59, 0xE5, 0x36, 0x2F,
  25389. 0x26, 0xA9, 0xEF, 0x50, 0xC2, 0xBC, 0x80, 0xBA,
  25390. 0x14, 0x62, 0x26, 0x21, 0x6F, 0xE6, 0x29, 0x68,
  25391. 0xA6, 0x0D, 0x04, 0xE8, 0xC1, 0x70, 0xD7, 0x41,
  25392. 0xC7, 0xA2, 0xB0, 0xE1, 0xAB, 0xDA, 0xC9, 0x68,
  25393. 0xE2, 0x90, 0x20, 0x83, 0x9D, 0x05, 0x2F, 0xA3,
  25394. 0x72, 0x58, 0x56, 0x27, 0xF8, 0xB5, 0x9E, 0xE3,
  25395. 0x12, 0xAE, 0x41, 0x4C, 0x97, 0x9D, 0x82, 0x5F,
  25396. 0x06, 0xA6, 0x92, 0x9A, 0x79, 0x62, 0x57, 0x18,
  25397. 0xA8, 0x57, 0x68, 0xF3, 0x48, 0x6B, 0xD3, 0x2A,
  25398. 0x01, 0xBF, 0x9A, 0x8F, 0x21, 0xEA, 0x93, 0x8E,
  25399. 0x64, 0x8E, 0xAE, 0x4E, 0x54, 0x48, 0xC3, 0x4C,
  25400. 0x3E, 0xB8, 0x88, 0x20, 0xB1, 0x59, 0xEE, 0xDD
  25401. };
  25402. #endif
  25403. #ifndef WOLFSSL_NO_KYBER1024
  25404. static const byte seed_1024[KYBER_MAKEKEY_RAND_SZ] = {
  25405. /* d */
  25406. 0x49, 0xAC, 0x8B, 0x99, 0xBB, 0x1E, 0x6A, 0x8E,
  25407. 0xA8, 0x18, 0x26, 0x1F, 0x8B, 0xE6, 0x8B, 0xDE,
  25408. 0xAA, 0x52, 0x89, 0x7E, 0x7E, 0xC6, 0xC4, 0x0B,
  25409. 0x53, 0x0B, 0xC7, 0x60, 0xAB, 0x77, 0xDC, 0xE3,
  25410. /* z */
  25411. 0x99, 0xE3, 0x24, 0x68, 0x84, 0x18, 0x1F, 0x8E,
  25412. 0x1D, 0xD4, 0x4E, 0x0C, 0x76, 0x29, 0x09, 0x33,
  25413. 0x30, 0x22, 0x1F, 0xD6, 0x7D, 0x9B, 0x7D, 0x6E,
  25414. 0x15, 0x10, 0xB2, 0xDB, 0xAD, 0x87, 0x62, 0xF7
  25415. };
  25416. static const byte ek_1024[KYBER1024_PUBLIC_KEY_SIZE] = {
  25417. 0xA0, 0x41, 0x84, 0xD4, 0xBC, 0x7B, 0x53, 0x2A,
  25418. 0x0F, 0x70, 0xA5, 0x4D, 0x77, 0x57, 0xCD, 0xE6,
  25419. 0x17, 0x5A, 0x68, 0x43, 0xB8, 0x61, 0xCB, 0x2B,
  25420. 0xC4, 0x83, 0x0C, 0x00, 0x12, 0x55, 0x4C, 0xFC,
  25421. 0x5D, 0x2C, 0x8A, 0x20, 0x27, 0xAA, 0x3C, 0xD9,
  25422. 0x67, 0x13, 0x0E, 0x9B, 0x96, 0x24, 0x1B, 0x11,
  25423. 0xC4, 0x32, 0x0C, 0x76, 0x49, 0xCC, 0x23, 0xA7,
  25424. 0x1B, 0xAF, 0xE6, 0x91, 0xAF, 0xC0, 0x8E, 0x68,
  25425. 0x0B, 0xCE, 0xF4, 0x29, 0x07, 0x00, 0x07, 0x18,
  25426. 0xE4, 0xEA, 0xCE, 0x8D, 0xA2, 0x82, 0x14, 0x19,
  25427. 0x7B, 0xE1, 0xC2, 0x69, 0xDA, 0x9C, 0xB5, 0x41,
  25428. 0xE1, 0xA3, 0xCE, 0x97, 0xCF, 0xAD, 0xF9, 0xC6,
  25429. 0x05, 0x87, 0x80, 0xFE, 0x67, 0x93, 0xDB, 0xFA,
  25430. 0x82, 0x18, 0xA2, 0x76, 0x0B, 0x80, 0x2B, 0x8D,
  25431. 0xA2, 0xAA, 0x27, 0x1A, 0x38, 0x77, 0x25, 0x23,
  25432. 0xA7, 0x67, 0x36, 0xA7, 0xA3, 0x1B, 0x9D, 0x30,
  25433. 0x37, 0xAD, 0x21, 0xCE, 0xBB, 0x11, 0xA4, 0x72,
  25434. 0xB8, 0x79, 0x2E, 0xB1, 0x75, 0x58, 0xB9, 0x40,
  25435. 0xE7, 0x08, 0x83, 0xF2, 0x64, 0x59, 0x2C, 0x68,
  25436. 0x9B, 0x24, 0x0B, 0xB4, 0x3D, 0x54, 0x08, 0xBF,
  25437. 0x44, 0x64, 0x32, 0xF4, 0x12, 0xF4, 0xB9, 0xA5,
  25438. 0xF6, 0x86, 0x5C, 0xC2, 0x52, 0xA4, 0x3C, 0xF4,
  25439. 0x0A, 0x32, 0x03, 0x91, 0x55, 0x55, 0x91, 0xD6,
  25440. 0x75, 0x61, 0xFD, 0xD0, 0x53, 0x53, 0xAB, 0x6B,
  25441. 0x01, 0x9B, 0x3A, 0x08, 0xA7, 0x33, 0x53, 0xD5,
  25442. 0x1B, 0x61, 0x13, 0xAB, 0x2F, 0xA5, 0x1D, 0x97,
  25443. 0x56, 0x48, 0xEE, 0x25, 0x4A, 0xF8, 0x9A, 0x23,
  25444. 0x05, 0x04, 0xA2, 0x36, 0xA4, 0x65, 0x82, 0x57,
  25445. 0x74, 0x0B, 0xDC, 0xBB, 0xE1, 0x70, 0x8A, 0xB0,
  25446. 0x22, 0xC3, 0xC5, 0x88, 0xA4, 0x10, 0xDB, 0x3B,
  25447. 0x9C, 0x30, 0x8A, 0x06, 0x27, 0x5B, 0xDF, 0x5B,
  25448. 0x48, 0x59, 0xD3, 0xA2, 0x61, 0x7A, 0x29, 0x5E,
  25449. 0x1A, 0x22, 0xF9, 0x01, 0x98, 0xBA, 0xD0, 0x16,
  25450. 0x6F, 0x4A, 0x94, 0x34, 0x17, 0xC5, 0xB8, 0x31,
  25451. 0x73, 0x6C, 0xB2, 0xC8, 0x58, 0x0A, 0xBF, 0xDE,
  25452. 0x57, 0x14, 0xB5, 0x86, 0xAB, 0xEE, 0xC0, 0xA1,
  25453. 0x75, 0xA0, 0x8B, 0xC7, 0x10, 0xC7, 0xA2, 0x89,
  25454. 0x5D, 0xE9, 0x3A, 0xC4, 0x38, 0x06, 0x1B, 0xF7,
  25455. 0x76, 0x5D, 0x0D, 0x21, 0xCD, 0x41, 0x81, 0x67,
  25456. 0xCA, 0xF8, 0x9D, 0x1E, 0xFC, 0x34, 0x48, 0xBC,
  25457. 0xBB, 0x96, 0xD6, 0x9B, 0x3E, 0x01, 0x0C, 0x82,
  25458. 0xD1, 0x5C, 0xAB, 0x6C, 0xAC, 0xC6, 0x79, 0x9D,
  25459. 0x36, 0x39, 0x66, 0x9A, 0x5B, 0x21, 0xA6, 0x33,
  25460. 0xC8, 0x65, 0xF8, 0x59, 0x3B, 0x5B, 0x7B, 0xC8,
  25461. 0x00, 0x26, 0x2B, 0xB8, 0x37, 0xA9, 0x24, 0xA6,
  25462. 0xC5, 0x44, 0x0E, 0x4F, 0xC7, 0x3B, 0x41, 0xB2,
  25463. 0x30, 0x92, 0xC3, 0x91, 0x2F, 0x4C, 0x6B, 0xEB,
  25464. 0xB4, 0xC7, 0xB4, 0xC6, 0x29, 0x08, 0xB0, 0x37,
  25465. 0x75, 0x66, 0x6C, 0x22, 0x22, 0x0D, 0xF9, 0xC8,
  25466. 0x88, 0x23, 0xE3, 0x44, 0xC7, 0x30, 0x83, 0x32,
  25467. 0x34, 0x5C, 0x8B, 0x79, 0x5D, 0x34, 0xE8, 0xC0,
  25468. 0x51, 0xF2, 0x1F, 0x5A, 0x21, 0xC2, 0x14, 0xB6,
  25469. 0x98, 0x41, 0x35, 0x87, 0x09, 0xB1, 0xC3, 0x05,
  25470. 0xB3, 0x2C, 0xC2, 0xC3, 0x80, 0x6A, 0xE9, 0xCC,
  25471. 0xD3, 0x81, 0x9F, 0xFF, 0x45, 0x07, 0xFE, 0x52,
  25472. 0x0F, 0xBF, 0xC2, 0x71, 0x99, 0xBC, 0x23, 0xBE,
  25473. 0x6B, 0x9B, 0x2D, 0x2A, 0xC1, 0x71, 0x75, 0x79,
  25474. 0xAC, 0x76, 0x92, 0x79, 0xE2, 0xA7, 0xAA, 0xC6,
  25475. 0x8A, 0x37, 0x1A, 0x47, 0xBA, 0x3A, 0x7D, 0xBE,
  25476. 0x01, 0x6F, 0x14, 0xE1, 0xA7, 0x27, 0x33, 0x36,
  25477. 0x63, 0xC4, 0xA5, 0xCD, 0x1A, 0x0F, 0x88, 0x36,
  25478. 0xCF, 0x7B, 0x5C, 0x49, 0xAC, 0x51, 0x48, 0x5C,
  25479. 0xA6, 0x03, 0x45, 0xC9, 0x90, 0xE0, 0x68, 0x88,
  25480. 0x72, 0x00, 0x03, 0x73, 0x13, 0x22, 0xC5, 0xB8,
  25481. 0xCD, 0x5E, 0x69, 0x07, 0xFD, 0xA1, 0x15, 0x7F,
  25482. 0x46, 0x8F, 0xD3, 0xFC, 0x20, 0xFA, 0x81, 0x75,
  25483. 0xEE, 0xC9, 0x5C, 0x29, 0x1A, 0x26, 0x2B, 0xA8,
  25484. 0xC5, 0xBE, 0x99, 0x08, 0x72, 0x41, 0x89, 0x30,
  25485. 0x85, 0x23, 0x39, 0xD8, 0x8A, 0x19, 0xB3, 0x7F,
  25486. 0xEF, 0xA3, 0xCF, 0xE8, 0x21, 0x75, 0xC2, 0x24,
  25487. 0x40, 0x7C, 0xA4, 0x14, 0xBA, 0xEB, 0x37, 0x92,
  25488. 0x3B, 0x4D, 0x2D, 0x83, 0x13, 0x4A, 0xE1, 0x54,
  25489. 0xE4, 0x90, 0xA9, 0xB4, 0x5A, 0x05, 0x63, 0xB0,
  25490. 0x6C, 0x95, 0x3C, 0x33, 0x01, 0x45, 0x0A, 0x21,
  25491. 0x76, 0xA0, 0x7C, 0x61, 0x4A, 0x74, 0xE3, 0x47,
  25492. 0x8E, 0x48, 0x50, 0x9F, 0x9A, 0x60, 0xAE, 0x94,
  25493. 0x5A, 0x8E, 0xBC, 0x78, 0x15, 0x12, 0x1D, 0x90,
  25494. 0xA3, 0xB0, 0xE0, 0x70, 0x91, 0xA0, 0x96, 0xCF,
  25495. 0x02, 0xC5, 0x7B, 0x25, 0xBC, 0xA5, 0x81, 0x26,
  25496. 0xAD, 0x0C, 0x62, 0x9C, 0xE1, 0x66, 0xA7, 0xED,
  25497. 0xB4, 0xB3, 0x32, 0x21, 0xA0, 0xD3, 0xF7, 0x2B,
  25498. 0x85, 0xD5, 0x62, 0xEC, 0x69, 0x8B, 0x7D, 0x0A,
  25499. 0x91, 0x3D, 0x73, 0x80, 0x6F, 0x1C, 0x5C, 0x87,
  25500. 0xB3, 0x8E, 0xC0, 0x03, 0xCB, 0x30, 0x3A, 0x3D,
  25501. 0xC5, 0x1B, 0x4B, 0x35, 0x35, 0x6A, 0x67, 0x82,
  25502. 0x6D, 0x6E, 0xDA, 0xA8, 0xFE, 0xB9, 0x3B, 0x98,
  25503. 0x49, 0x3B, 0x2D, 0x1C, 0x11, 0xB6, 0x76, 0xA6,
  25504. 0xAD, 0x95, 0x06, 0xA1, 0xAA, 0xAE, 0x13, 0xA8,
  25505. 0x24, 0xC7, 0xC0, 0x8D, 0x1C, 0x6C, 0x2C, 0x4D,
  25506. 0xBA, 0x96, 0x42, 0xC7, 0x6E, 0xA7, 0xF6, 0xC8,
  25507. 0x26, 0x4B, 0x64, 0xA2, 0x3C, 0xCC, 0xA9, 0xA7,
  25508. 0x46, 0x35, 0xFC, 0xBF, 0x03, 0xE0, 0x0F, 0x1B,
  25509. 0x57, 0x22, 0xB2, 0x14, 0x37, 0x67, 0x90, 0x79,
  25510. 0x3B, 0x2C, 0x4F, 0x0A, 0x13, 0xB5, 0xC4, 0x07,
  25511. 0x60, 0xB4, 0x21, 0x8E, 0x1D, 0x25, 0x94, 0xDC,
  25512. 0xB3, 0x0A, 0x70, 0xD9, 0xC1, 0x78, 0x2A, 0x5D,
  25513. 0xD3, 0x05, 0x76, 0xFA, 0x41, 0x44, 0xBF, 0xC8,
  25514. 0x41, 0x6E, 0xDA, 0x81, 0x18, 0xFC, 0x64, 0x72,
  25515. 0xF5, 0x6A, 0x97, 0x95, 0x86, 0xF3, 0x3B, 0xB0,
  25516. 0x70, 0xFB, 0x0F, 0x1B, 0x0B, 0x10, 0xBC, 0x48,
  25517. 0x97, 0xEB, 0xE0, 0x1B, 0xCA, 0x38, 0x93, 0xD4,
  25518. 0xE1, 0x6A, 0xDB, 0x25, 0x09, 0x3A, 0x74, 0x17,
  25519. 0xD0, 0x70, 0x8C, 0x83, 0xA2, 0x63, 0x22, 0xE2,
  25520. 0x2E, 0x63, 0x30, 0x09, 0x1E, 0x30, 0x15, 0x2B,
  25521. 0xF8, 0x23, 0x59, 0x7C, 0x04, 0xCC, 0xF4, 0xCF,
  25522. 0xC7, 0x33, 0x15, 0x78, 0xF4, 0x3A, 0x27, 0x26,
  25523. 0xCC, 0xB4, 0x28, 0x28, 0x9A, 0x90, 0xC8, 0x63,
  25524. 0x25, 0x9D, 0xD1, 0x80, 0xC5, 0xFF, 0x14, 0x2B,
  25525. 0xEF, 0x41, 0xC7, 0x71, 0x70, 0x94, 0xBE, 0x07,
  25526. 0x85, 0x6D, 0xA2, 0xB1, 0x40, 0xFA, 0x67, 0x71,
  25527. 0x09, 0x67, 0x35, 0x6A, 0xA4, 0x7D, 0xFB, 0xC8,
  25528. 0xD2, 0x55, 0xB4, 0x72, 0x2A, 0xB8, 0x6D, 0x43,
  25529. 0x9B, 0x7E, 0x0A, 0x60, 0x90, 0x25, 0x1D, 0x2D,
  25530. 0x4C, 0x1E, 0xD5, 0xF2, 0x0B, 0xBE, 0x68, 0x07,
  25531. 0xBF, 0x65, 0xA9, 0x0B, 0x7C, 0xB2, 0xEC, 0x01,
  25532. 0x02, 0xAF, 0x02, 0x80, 0x9D, 0xC9, 0xAC, 0x7D,
  25533. 0x0A, 0x3A, 0xBC, 0x69, 0xC1, 0x83, 0x65, 0xBC,
  25534. 0xFF, 0x59, 0x18, 0x5F, 0x33, 0x99, 0x68, 0x87,
  25535. 0x74, 0x61, 0x85, 0x90, 0x6C, 0x01, 0x91, 0xAE,
  25536. 0xD4, 0x40, 0x7E, 0x13, 0x94, 0x46, 0x45, 0x9B,
  25537. 0xE2, 0x9C, 0x68, 0x22, 0x71, 0x76, 0x44, 0x35,
  25538. 0x3D, 0x24, 0xAB, 0x63, 0x39, 0x15, 0x6A, 0x9C,
  25539. 0x42, 0x49, 0x09, 0xF0, 0xA9, 0x02, 0x5B, 0xB7,
  25540. 0x47, 0x20, 0x77, 0x9B, 0xE4, 0x3F, 0x16, 0xD8,
  25541. 0x1C, 0x8C, 0xC6, 0x66, 0xE9, 0x97, 0x10, 0xD8,
  25542. 0xC6, 0x8B, 0xB5, 0xCC, 0x4E, 0x12, 0xF3, 0x14,
  25543. 0xE9, 0x25, 0xA5, 0x51, 0xF0, 0x9C, 0xC5, 0x90,
  25544. 0x03, 0xA1, 0xF8, 0x81, 0x03, 0xC2, 0x54, 0xBB,
  25545. 0x97, 0x8D, 0x75, 0xF3, 0x94, 0xD3, 0x54, 0x0E,
  25546. 0x31, 0xE7, 0x71, 0xCD, 0xA3, 0x6E, 0x39, 0xEC,
  25547. 0x54, 0xA6, 0x2B, 0x58, 0x32, 0x66, 0x4D, 0x82,
  25548. 0x1A, 0x72, 0xF1, 0xE6, 0xAF, 0xBB, 0xA2, 0x7F,
  25549. 0x84, 0x29, 0x5B, 0x26, 0x94, 0xC4, 0x98, 0x49,
  25550. 0x8E, 0x81, 0x2B, 0xC8, 0xE9, 0x37, 0x8F, 0xE5,
  25551. 0x41, 0xCE, 0xC5, 0x89, 0x1B, 0x25, 0x06, 0x29,
  25552. 0x01, 0xCB, 0x72, 0x12, 0xE3, 0xCD, 0xC4, 0x61,
  25553. 0x79, 0xEC, 0x5B, 0xCE, 0xC1, 0x0B, 0xC0, 0xB9,
  25554. 0x31, 0x1D, 0xE0, 0x50, 0x74, 0x29, 0x06, 0x87,
  25555. 0xFD, 0x6A, 0x53, 0x92, 0x67, 0x16, 0x54, 0x28,
  25556. 0x4C, 0xD9, 0xC8, 0xCC, 0x3E, 0xBA, 0x80, 0xEB,
  25557. 0x3B, 0x66, 0x2E, 0xB5, 0x3E, 0xB7, 0x51, 0x16,
  25558. 0x70, 0x4A, 0x1F, 0xEB, 0x5C, 0x2D, 0x05, 0x63,
  25559. 0x38, 0x53, 0x28, 0x68, 0xDD, 0xF2, 0x4E, 0xB8,
  25560. 0x99, 0x2A, 0xB8, 0x56, 0x5D, 0x9E, 0x49, 0x0C,
  25561. 0xAD, 0xF1, 0x48, 0x04, 0x36, 0x0D, 0xAA, 0x90,
  25562. 0x71, 0x8E, 0xAB, 0x61, 0x6B, 0xAB, 0x07, 0x65,
  25563. 0xD3, 0x39, 0x87, 0xB4, 0x7E, 0xFB, 0x65, 0x99,
  25564. 0xC5, 0x56, 0x32, 0x35, 0xE6, 0x1E, 0x4B, 0xE6,
  25565. 0x70, 0xE9, 0x79, 0x55, 0xAB, 0x29, 0x2D, 0x97,
  25566. 0x32, 0xCB, 0x89, 0x30, 0x94, 0x8A, 0xC8, 0x2D,
  25567. 0xF2, 0x30, 0xAC, 0x72, 0x29, 0x7A, 0x23, 0x67,
  25568. 0x9D, 0x6B, 0x94, 0xC1, 0x7F, 0x13, 0x59, 0x48,
  25569. 0x32, 0x54, 0xFE, 0xDC, 0x2F, 0x05, 0x81, 0x9F,
  25570. 0x0D, 0x06, 0x9A, 0x44, 0x3B, 0x78, 0xE3, 0xFC,
  25571. 0x6C, 0x3E, 0xF4, 0x71, 0x4B, 0x05, 0xA3, 0xFC,
  25572. 0xA8, 0x1C, 0xBB, 0xA6, 0x02, 0x42, 0xA7, 0x06,
  25573. 0x0C, 0xD8, 0x85, 0xD8, 0xF3, 0x99, 0x81, 0xBB,
  25574. 0x18, 0x09, 0x2B, 0x23, 0xDA, 0xA5, 0x9F, 0xD9,
  25575. 0x57, 0x83, 0x88, 0x68, 0x8A, 0x09, 0xBB, 0xA0,
  25576. 0x79, 0xBC, 0x80, 0x9A, 0x54, 0x84, 0x3A, 0x60,
  25577. 0x38, 0x5E, 0x23, 0x10, 0xBB, 0xCB, 0xCC, 0x02,
  25578. 0x13, 0xCE, 0x3D, 0xFA, 0xAB, 0x33, 0xB4, 0x7F,
  25579. 0x9D, 0x63, 0x05, 0xBC, 0x95, 0xC6, 0x10, 0x78,
  25580. 0x13, 0xC5, 0x85, 0xC4, 0xB6, 0x57, 0xBF, 0x30,
  25581. 0x54, 0x28, 0x33, 0xB1, 0x49, 0x49, 0xF5, 0x73,
  25582. 0xC0, 0x61, 0x2A, 0xD5, 0x24, 0xBA, 0xAE, 0x69,
  25583. 0x59, 0x0C, 0x12, 0x77, 0xB8, 0x6C, 0x28, 0x65,
  25584. 0x71, 0xBF, 0x66, 0xB3, 0xCF, 0xF4, 0x6A, 0x38,
  25585. 0x58, 0xC0, 0x99, 0x06, 0xA7, 0x94, 0xDF, 0x4A,
  25586. 0x06, 0xE9, 0xD4, 0xB0, 0xA2, 0xE4, 0x3F, 0x10,
  25587. 0xF7, 0x2A, 0x6C, 0x6C, 0x47, 0xE5, 0x64, 0x6E,
  25588. 0x2C, 0x79, 0x9B, 0x71, 0xC3, 0x3E, 0xD2, 0xF0,
  25589. 0x1E, 0xEB, 0x45, 0x93, 0x8E, 0xB7, 0xA4, 0xE2,
  25590. 0xE2, 0x90, 0x8C, 0x53, 0x55, 0x8A, 0x54, 0x0D,
  25591. 0x35, 0x03, 0x69, 0xFA, 0x18, 0x9C, 0x61, 0x69,
  25592. 0x43, 0xF7, 0x98, 0x1D, 0x76, 0x18, 0xCF, 0x02,
  25593. 0xA5, 0xB0, 0xA2, 0xBC, 0xC4, 0x22, 0xE8, 0x57,
  25594. 0xD1, 0xA4, 0x78, 0x71, 0x25, 0x3D, 0x08, 0x29,
  25595. 0x3C, 0x1C, 0x17, 0x9B, 0xCD, 0xC0, 0x43, 0x70,
  25596. 0x69, 0x10, 0x74, 0x18, 0x20, 0x5F, 0xDB, 0x98,
  25597. 0x56, 0x62, 0x3B, 0x8C, 0xA6, 0xB6, 0x94, 0xC9,
  25598. 0x6C, 0x08, 0x4B, 0x17, 0xF1, 0x3B, 0xB6, 0xDF,
  25599. 0x12, 0xB2, 0xCF, 0xBB, 0xC2, 0xB0, 0xE0, 0xC3,
  25600. 0x4B, 0x00, 0xD0, 0xFC, 0xD0, 0xAE, 0xCF, 0xB2,
  25601. 0x79, 0x24, 0xF6, 0x98, 0x4E, 0x74, 0x7B, 0xE2,
  25602. 0xA0, 0x9D, 0x83, 0xA8, 0x66, 0x45, 0x90, 0xA8,
  25603. 0x07, 0x73, 0x31, 0x49, 0x1A, 0x4F, 0x7D, 0x72,
  25604. 0x08, 0x43, 0xF2, 0x3E, 0x65, 0x2C, 0x6F, 0xA8,
  25605. 0x40, 0x30, 0x8D, 0xB4, 0x02, 0x03, 0x37, 0xAA,
  25606. 0xD3, 0x79, 0x67, 0x03, 0x4A, 0x9F, 0xB5, 0x23,
  25607. 0xB6, 0x7C, 0xA7, 0x03, 0x30, 0xF0, 0x2D, 0x9E,
  25608. 0xA2, 0x0C, 0x1E, 0x84, 0xCB, 0x8E, 0x57, 0x57,
  25609. 0xC9, 0xE1, 0x89, 0x6B, 0x60, 0x58, 0x14, 0x41,
  25610. 0xED, 0x61, 0x8A, 0xA5, 0xB2, 0x6D, 0xA5, 0x6C,
  25611. 0x0A, 0x5A, 0x73, 0xC4, 0xDC, 0xFD, 0x75, 0x5E,
  25612. 0x61, 0x0B, 0x4F, 0xC8, 0x1F, 0xF8, 0x4E, 0x21
  25613. };
  25614. static const byte dk_1024[KYBER1024_PRIVATE_KEY_SIZE] = {
  25615. 0x8C, 0x8B, 0x37, 0x22, 0xA8, 0x2E, 0x55, 0x05,
  25616. 0x65, 0x52, 0x16, 0x11, 0xEB, 0xBC, 0x63, 0x07,
  25617. 0x99, 0x44, 0xC9, 0xB1, 0xAB, 0xB3, 0xB0, 0x02,
  25618. 0x0F, 0xF1, 0x2F, 0x63, 0x18, 0x91, 0xA9, 0xC4,
  25619. 0x68, 0xD3, 0xA6, 0x7B, 0xF6, 0x27, 0x12, 0x80,
  25620. 0xDA, 0x58, 0xD0, 0x3C, 0xB0, 0x42, 0xB3, 0xA4,
  25621. 0x61, 0x44, 0x16, 0x37, 0xF9, 0x29, 0xC2, 0x73,
  25622. 0x46, 0x9A, 0xD1, 0x53, 0x11, 0xE9, 0x10, 0xDE,
  25623. 0x18, 0xCB, 0x95, 0x37, 0xBA, 0x1B, 0xE4, 0x2E,
  25624. 0x98, 0xBB, 0x59, 0xE4, 0x98, 0xA1, 0x3F, 0xD4,
  25625. 0x40, 0xD0, 0xE6, 0x9E, 0xE8, 0x32, 0xB4, 0x5C,
  25626. 0xD9, 0x5C, 0x38, 0x21, 0x77, 0xD6, 0x70, 0x96,
  25627. 0xA1, 0x8C, 0x07, 0xF1, 0x78, 0x16, 0x63, 0x65,
  25628. 0x1B, 0xDC, 0xAC, 0x90, 0xDE, 0xDA, 0x3D, 0xDD,
  25629. 0x14, 0x34, 0x85, 0x86, 0x41, 0x81, 0xC9, 0x1F,
  25630. 0xA2, 0x08, 0x0F, 0x6D, 0xAB, 0x3F, 0x86, 0x20,
  25631. 0x4C, 0xEB, 0x64, 0xA7, 0xB4, 0x44, 0x68, 0x95,
  25632. 0xC0, 0x39, 0x87, 0xA0, 0x31, 0xCB, 0x4B, 0x6D,
  25633. 0x9E, 0x04, 0x62, 0xFD, 0xA8, 0x29, 0x17, 0x2B,
  25634. 0x6C, 0x01, 0x2C, 0x63, 0x8B, 0x29, 0xB5, 0xCD,
  25635. 0x75, 0xA2, 0xC9, 0x30, 0xA5, 0x59, 0x6A, 0x31,
  25636. 0x81, 0xC3, 0x3A, 0x22, 0xD5, 0x74, 0xD3, 0x02,
  25637. 0x61, 0x19, 0x6B, 0xC3, 0x50, 0x73, 0x8D, 0x4F,
  25638. 0xD9, 0x18, 0x3A, 0x76, 0x33, 0x36, 0x24, 0x3A,
  25639. 0xCE, 0xD9, 0x9B, 0x32, 0x21, 0xC7, 0x1D, 0x88,
  25640. 0x66, 0x89, 0x5C, 0x4E, 0x52, 0xC1, 0x19, 0xBF,
  25641. 0x32, 0x80, 0xDA, 0xF8, 0x0A, 0x95, 0xE1, 0x52,
  25642. 0x09, 0xA7, 0x95, 0xC4, 0x43, 0x5F, 0xBB, 0x35,
  25643. 0x70, 0xFD, 0xB8, 0xAA, 0x9B, 0xF9, 0xAE, 0xFD,
  25644. 0x43, 0xB0, 0x94, 0xB7, 0x81, 0xD5, 0xA8, 0x11,
  25645. 0x36, 0xDA, 0xB8, 0x8B, 0x87, 0x99, 0x69, 0x65,
  25646. 0x56, 0xFE, 0xC6, 0xAE, 0x14, 0xB0, 0xBB, 0x8B,
  25647. 0xE4, 0x69, 0x5E, 0x9A, 0x12, 0x4C, 0x2A, 0xB8,
  25648. 0xFF, 0x4A, 0xB1, 0x22, 0x9B, 0x8A, 0xAA, 0x8C,
  25649. 0x6F, 0x41, 0xA6, 0x0C, 0x34, 0xC7, 0xB5, 0x61,
  25650. 0x82, 0xC5, 0x5C, 0x2C, 0x68, 0x5E, 0x73, 0x7C,
  25651. 0x6C, 0xA0, 0x0A, 0x23, 0xFB, 0x8A, 0x68, 0xC1,
  25652. 0xCD, 0x61, 0xF3, 0x0D, 0x39, 0x93, 0xA1, 0x65,
  25653. 0x3C, 0x16, 0x75, 0xAC, 0x5F, 0x09, 0x01, 0xA7,
  25654. 0x16, 0x0A, 0x73, 0x96, 0x64, 0x08, 0xB8, 0x87,
  25655. 0x6B, 0x71, 0x53, 0x96, 0xCF, 0xA4, 0x90, 0x3F,
  25656. 0xC6, 0x9D, 0x60, 0x49, 0x1F, 0x81, 0x46, 0x80,
  25657. 0x8C, 0x97, 0xCD, 0x5C, 0x53, 0x3E, 0x71, 0x01,
  25658. 0x79, 0x09, 0xE9, 0x7B, 0x83, 0x5B, 0x86, 0xFF,
  25659. 0x84, 0x7B, 0x42, 0xA6, 0x96, 0x37, 0x54, 0x35,
  25660. 0xE0, 0x06, 0x06, 0x1C, 0xF7, 0xA4, 0x79, 0x46,
  25661. 0x32, 0x72, 0x11, 0x4A, 0x89, 0xEB, 0x3E, 0xAF,
  25662. 0x22, 0x46, 0xF0, 0xF8, 0xC1, 0x04, 0xA1, 0x49,
  25663. 0x86, 0x82, 0x8E, 0x0A, 0xD2, 0x04, 0x20, 0xC9,
  25664. 0xB3, 0x7E, 0xA2, 0x3F, 0x5C, 0x51, 0x49, 0x49,
  25665. 0xE7, 0x7A, 0xD9, 0xE9, 0xAD, 0x12, 0x29, 0x0D,
  25666. 0xD1, 0x21, 0x5E, 0x11, 0xDA, 0x27, 0x44, 0x57,
  25667. 0xAC, 0x86, 0xB1, 0xCE, 0x68, 0x64, 0xB1, 0x22,
  25668. 0x67, 0x7F, 0x37, 0x18, 0xAA, 0x31, 0xB0, 0x25,
  25669. 0x80, 0xE6, 0x43, 0x17, 0x17, 0x8D, 0x38, 0xF2,
  25670. 0x5F, 0x60, 0x9B, 0xC6, 0xC5, 0x5B, 0xC3, 0x74,
  25671. 0xA1, 0xBF, 0x78, 0xEA, 0x8E, 0xCC, 0x21, 0x9B,
  25672. 0x30, 0xB7, 0x4C, 0xBB, 0x32, 0x72, 0xA5, 0x99,
  25673. 0x23, 0x8C, 0x93, 0x98, 0x51, 0x70, 0x04, 0x8F,
  25674. 0x17, 0x67, 0x75, 0xFB, 0x19, 0x96, 0x2A, 0xC3,
  25675. 0xB1, 0x35, 0xAA, 0x59, 0xDB, 0x10, 0x4F, 0x71,
  25676. 0x14, 0xDB, 0xC2, 0xC2, 0xD4, 0x29, 0x49, 0xAD,
  25677. 0xEC, 0xA6, 0xA8, 0x5B, 0x32, 0x3E, 0xE2, 0xB2,
  25678. 0xB2, 0x3A, 0x77, 0xD9, 0xDB, 0x23, 0x59, 0x79,
  25679. 0xA8, 0xE2, 0xD6, 0x7C, 0xF7, 0xD2, 0x13, 0x6B,
  25680. 0xBB, 0xA7, 0x1F, 0x26, 0x95, 0x74, 0xB3, 0x88,
  25681. 0x88, 0xE1, 0x54, 0x13, 0x40, 0xC1, 0x92, 0x84,
  25682. 0x07, 0x4F, 0x9B, 0x7C, 0x8C, 0xF3, 0x7E, 0xB0,
  25683. 0x13, 0x84, 0xE6, 0xE3, 0x82, 0x2E, 0xC4, 0x88,
  25684. 0x2D, 0xFB, 0xBE, 0xC4, 0xE6, 0x09, 0x8E, 0xF2,
  25685. 0xB2, 0xFC, 0x17, 0x7A, 0x1F, 0x0B, 0xCB, 0x65,
  25686. 0xA5, 0x7F, 0xDA, 0xA8, 0x93, 0x15, 0x46, 0x1B,
  25687. 0xEB, 0x78, 0x85, 0xFB, 0x68, 0xB3, 0xCD, 0x09,
  25688. 0x6E, 0xDA, 0x59, 0x6A, 0xC0, 0xE6, 0x1D, 0xD7,
  25689. 0xA9, 0xC5, 0x07, 0xBC, 0x63, 0x45, 0xE0, 0x82,
  25690. 0x7D, 0xFC, 0xC8, 0xA3, 0xAC, 0x2D, 0xCE, 0x51,
  25691. 0xAD, 0x73, 0x1A, 0xA0, 0xEB, 0x93, 0x2A, 0x6D,
  25692. 0x09, 0x83, 0x99, 0x23, 0x47, 0xCB, 0xEB, 0x3C,
  25693. 0xD0, 0xD9, 0xC9, 0x71, 0x97, 0x97, 0xCC, 0x21,
  25694. 0xCF, 0x00, 0x62, 0xB0, 0xAD, 0x94, 0xCA, 0xD7,
  25695. 0x34, 0xC6, 0x3E, 0x6B, 0x5D, 0x85, 0x9C, 0xBE,
  25696. 0x19, 0xF0, 0x36, 0x82, 0x45, 0x35, 0x1B, 0xF4,
  25697. 0x64, 0xD7, 0x50, 0x55, 0x69, 0x79, 0x0D, 0x2B,
  25698. 0xB7, 0x24, 0xD8, 0x65, 0x9A, 0x9F, 0xEB, 0x1C,
  25699. 0x7C, 0x47, 0x3D, 0xC4, 0xD0, 0x61, 0xE2, 0x98,
  25700. 0x63, 0xA2, 0x71, 0x4B, 0xAC, 0x42, 0xAD, 0xCD,
  25701. 0x1A, 0x83, 0x72, 0x77, 0x65, 0x56, 0xF7, 0x92,
  25702. 0x8A, 0x7A, 0x44, 0xE9, 0x4B, 0x6A, 0x25, 0x32,
  25703. 0x2D, 0x03, 0xC0, 0xA1, 0x62, 0x2A, 0x7F, 0xD2,
  25704. 0x61, 0x52, 0x2B, 0x73, 0x58, 0xF0, 0x85, 0xBD,
  25705. 0xFB, 0x60, 0x75, 0x87, 0x62, 0xCB, 0x90, 0x10,
  25706. 0x31, 0x90, 0x1B, 0x5E, 0xEC, 0xF4, 0x92, 0x0C,
  25707. 0x81, 0x02, 0x0A, 0x9B, 0x17, 0x81, 0xBC, 0xB9,
  25708. 0xDD, 0x19, 0xA9, 0xDF, 0xB6, 0x64, 0x58, 0xE7,
  25709. 0x75, 0x7C, 0x52, 0xCE, 0xC7, 0x5B, 0x4B, 0xA7,
  25710. 0x40, 0xA2, 0x40, 0x99, 0xCB, 0x56, 0xBB, 0x60,
  25711. 0xA7, 0x6B, 0x69, 0x01, 0xAA, 0x3E, 0x01, 0x69,
  25712. 0xC9, 0xE8, 0x34, 0x96, 0xD7, 0x3C, 0x4C, 0x99,
  25713. 0x43, 0x5A, 0x28, 0xD6, 0x13, 0xE9, 0x7A, 0x11,
  25714. 0x77, 0xF5, 0x8B, 0x6C, 0xC5, 0x95, 0xD3, 0xB2,
  25715. 0x33, 0x1E, 0x9C, 0xA7, 0xB5, 0x7B, 0x74, 0xDC,
  25716. 0x2C, 0x52, 0x77, 0xD2, 0x6F, 0x2F, 0xE1, 0x92,
  25717. 0x40, 0xA5, 0x5C, 0x35, 0xD6, 0xCF, 0xCA, 0x26,
  25718. 0xC7, 0x3E, 0x9A, 0x2D, 0x7C, 0x98, 0x0D, 0x97,
  25719. 0x96, 0x0A, 0xE1, 0xA0, 0x46, 0x98, 0xC1, 0x6B,
  25720. 0x39, 0x8A, 0x5F, 0x20, 0xC3, 0x5A, 0x09, 0x14,
  25721. 0x14, 0x5C, 0xE1, 0x67, 0x4B, 0x71, 0xAB, 0xC6,
  25722. 0x06, 0x6A, 0x90, 0x9A, 0x3E, 0x4B, 0x91, 0x1E,
  25723. 0x69, 0xD5, 0xA8, 0x49, 0x43, 0x03, 0x61, 0xF7,
  25724. 0x31, 0xB0, 0x72, 0x46, 0xA6, 0x32, 0x9B, 0x52,
  25725. 0x36, 0x19, 0x04, 0x22, 0x50, 0x82, 0xD0, 0xAA,
  25726. 0xC5, 0xB2, 0x1D, 0x6B, 0x34, 0x86, 0x24, 0x81,
  25727. 0xA8, 0x90, 0xC3, 0xC3, 0x60, 0x76, 0x6F, 0x04,
  25728. 0x26, 0x36, 0x03, 0xA6, 0xB7, 0x3E, 0x80, 0x2B,
  25729. 0x1F, 0x70, 0xB2, 0xEB, 0x00, 0x04, 0x68, 0x36,
  25730. 0xB8, 0xF4, 0x93, 0xBF, 0x10, 0xB9, 0x0B, 0x87,
  25731. 0x37, 0xC6, 0xC5, 0x48, 0x44, 0x9B, 0x29, 0x4C,
  25732. 0x47, 0x25, 0x3B, 0xE2, 0x6C, 0xA7, 0x23, 0x36,
  25733. 0xA6, 0x32, 0x06, 0x3A, 0xD3, 0xD0, 0xB4, 0x8C,
  25734. 0x8B, 0x0F, 0x4A, 0x34, 0x44, 0x7E, 0xF1, 0x3B,
  25735. 0x76, 0x40, 0x20, 0xDE, 0x73, 0x9E, 0xB7, 0x9A,
  25736. 0xBA, 0x20, 0xE2, 0xBE, 0x19, 0x51, 0x82, 0x5F,
  25737. 0x29, 0x3B, 0xED, 0xD1, 0x08, 0x9F, 0xCB, 0x0A,
  25738. 0x91, 0xF5, 0x60, 0xC8, 0xE1, 0x7C, 0xDF, 0x52,
  25739. 0x54, 0x1D, 0xC2, 0xB8, 0x1F, 0x97, 0x2A, 0x73,
  25740. 0x75, 0xB2, 0x01, 0xF1, 0x0C, 0x08, 0xD9, 0xB5,
  25741. 0xBC, 0x8B, 0x95, 0x10, 0x00, 0x54, 0xA3, 0xD0,
  25742. 0xAA, 0xFF, 0x89, 0xBD, 0x08, 0xD6, 0xA0, 0xE7,
  25743. 0xF2, 0x11, 0x5A, 0x43, 0x52, 0x31, 0x29, 0x04,
  25744. 0x60, 0xC9, 0xAD, 0x43, 0x5A, 0x3B, 0x3C, 0xF3,
  25745. 0x5E, 0x52, 0x09, 0x1E, 0xDD, 0x18, 0x90, 0x04,
  25746. 0x7B, 0xCC, 0x0A, 0xAB, 0xB1, 0xAC, 0xEB, 0xC7,
  25747. 0x5F, 0x4A, 0x32, 0xBC, 0x14, 0x51, 0xAC, 0xC4,
  25748. 0x96, 0x99, 0x40, 0x78, 0x8E, 0x89, 0x41, 0x21,
  25749. 0x88, 0x94, 0x6C, 0x91, 0x43, 0xC5, 0x04, 0x6B,
  25750. 0xD1, 0xB4, 0x58, 0xDF, 0x61, 0x7C, 0x5D, 0xF5,
  25751. 0x33, 0xB0, 0x52, 0xCD, 0x60, 0x38, 0xB7, 0x75,
  25752. 0x40, 0x34, 0xA2, 0x3C, 0x2F, 0x77, 0x20, 0x13,
  25753. 0x4C, 0x7B, 0x4E, 0xAC, 0xE0, 0x1F, 0xAC, 0x0A,
  25754. 0x28, 0x53, 0xA9, 0x28, 0x58, 0x47, 0xAB, 0xBD,
  25755. 0x06, 0xA3, 0x34, 0x3A, 0x77, 0x8A, 0xC6, 0x06,
  25756. 0x2E, 0x45, 0x8B, 0xC5, 0xE6, 0x1E, 0xCE, 0x1C,
  25757. 0x0D, 0xE0, 0x20, 0x6E, 0x6F, 0xE8, 0xA8, 0x40,
  25758. 0x34, 0xA7, 0xC5, 0xF1, 0xB0, 0x05, 0xFB, 0x0A,
  25759. 0x58, 0x40, 0x51, 0xD3, 0x22, 0x9B, 0x86, 0xC9,
  25760. 0x09, 0xAC, 0x56, 0x47, 0xB3, 0xD7, 0x55, 0x69,
  25761. 0xE0, 0x5A, 0x88, 0x27, 0x9D, 0x80, 0xE5, 0xC3,
  25762. 0x0F, 0x57, 0x4D, 0xC3, 0x27, 0x51, 0x2C, 0x6B,
  25763. 0xBE, 0x81, 0x01, 0x23, 0x9E, 0xC6, 0x28, 0x61,
  25764. 0xF4, 0xBE, 0x67, 0xB0, 0x5B, 0x9C, 0xDA, 0x9C,
  25765. 0x54, 0x5C, 0x13, 0xE7, 0xEB, 0x53, 0xCF, 0xF2,
  25766. 0x60, 0xAD, 0x98, 0x70, 0x19, 0x9C, 0x21, 0xF8,
  25767. 0xC6, 0x3D, 0x64, 0xF0, 0x45, 0x8A, 0x71, 0x41,
  25768. 0x28, 0x50, 0x23, 0xFE, 0xB8, 0x29, 0x29, 0x08,
  25769. 0x72, 0x38, 0x96, 0x44, 0xB0, 0xC3, 0xB7, 0x3A,
  25770. 0xC2, 0xC8, 0xE1, 0x21, 0xA2, 0x9B, 0xB1, 0xC4,
  25771. 0x3C, 0x19, 0xA2, 0x33, 0xD5, 0x6B, 0xED, 0x82,
  25772. 0x74, 0x0E, 0xB0, 0x21, 0xC9, 0x7B, 0x8E, 0xBB,
  25773. 0xA4, 0x0F, 0xF3, 0x28, 0xB5, 0x41, 0x76, 0x0F,
  25774. 0xCC, 0x37, 0x2B, 0x52, 0xD3, 0xBC, 0x4F, 0xCB,
  25775. 0xC0, 0x6F, 0x42, 0x4E, 0xAF, 0x25, 0x38, 0x04,
  25776. 0xD4, 0xCB, 0x46, 0xF4, 0x1F, 0xF2, 0x54, 0xC0,
  25777. 0xC5, 0xBA, 0x48, 0x3B, 0x44, 0xA8, 0x7C, 0x21,
  25778. 0x96, 0x54, 0x55, 0x5E, 0xC7, 0xC1, 0x63, 0xC7,
  25779. 0x9B, 0x9C, 0xB7, 0x60, 0xA2, 0xAD, 0x9B, 0xB7,
  25780. 0x22, 0xB9, 0x3E, 0x0C, 0x28, 0xBD, 0x4B, 0x16,
  25781. 0x85, 0x94, 0x9C, 0x49, 0x6E, 0xAB, 0x1A, 0xFF,
  25782. 0x90, 0x91, 0x9E, 0x37, 0x61, 0xB3, 0x46, 0x83,
  25783. 0x8A, 0xBB, 0x2F, 0x01, 0xA9, 0x1E, 0x55, 0x43,
  25784. 0x75, 0xAF, 0xDA, 0xAA, 0xF3, 0x82, 0x6E, 0x6D,
  25785. 0xB7, 0x9F, 0xE7, 0x35, 0x3A, 0x7A, 0x57, 0x8A,
  25786. 0x7C, 0x05, 0x98, 0xCE, 0x28, 0xB6, 0xD9, 0x91,
  25787. 0x52, 0x14, 0x23, 0x6B, 0xBF, 0xFA, 0x6D, 0x45,
  25788. 0xB6, 0x37, 0x6A, 0x07, 0x92, 0x4A, 0x39, 0xA7,
  25789. 0xBE, 0x81, 0x82, 0x86, 0x71, 0x5C, 0x8A, 0x3C,
  25790. 0x11, 0x0C, 0xD7, 0x6C, 0x02, 0xE0, 0x41, 0x7A,
  25791. 0xF1, 0x38, 0xBD, 0xB9, 0x5C, 0x3C, 0xCA, 0x79,
  25792. 0x8A, 0xC8, 0x09, 0xED, 0x69, 0xCF, 0xB6, 0x72,
  25793. 0xB6, 0xFD, 0xDC, 0x24, 0xD8, 0x9C, 0x06, 0xA6,
  25794. 0x55, 0x88, 0x14, 0xAB, 0x0C, 0x21, 0xC6, 0x2B,
  25795. 0x2F, 0x84, 0xC0, 0xE3, 0xE0, 0x80, 0x3D, 0xB3,
  25796. 0x37, 0xA4, 0xE0, 0xC7, 0x12, 0x7A, 0x6B, 0x4C,
  25797. 0x8C, 0x08, 0xB1, 0xD1, 0xA7, 0x6B, 0xF0, 0x7E,
  25798. 0xB6, 0xE5, 0xB5, 0xBB, 0x47, 0xA1, 0x6C, 0x74,
  25799. 0xBC, 0x54, 0x83, 0x75, 0xFB, 0x29, 0xCD, 0x78,
  25800. 0x9A, 0x5C, 0xFF, 0x91, 0xBD, 0xBD, 0x07, 0x18,
  25801. 0x59, 0xF4, 0x84, 0x6E, 0x35, 0x5B, 0xB0, 0xD2,
  25802. 0x94, 0x84, 0xE2, 0x64, 0xDF, 0xF3, 0x6C, 0x91,
  25803. 0x77, 0xA7, 0xAC, 0xA7, 0x89, 0x08, 0x87, 0x96,
  25804. 0x95, 0xCA, 0x87, 0xF2, 0x54, 0x36, 0xBC, 0x12,
  25805. 0x63, 0x07, 0x24, 0xBB, 0x22, 0xF0, 0xCB, 0x64,
  25806. 0x89, 0x7F, 0xE5, 0xC4, 0x11, 0x95, 0x28, 0x0D,
  25807. 0xA0, 0x41, 0x84, 0xD4, 0xBC, 0x7B, 0x53, 0x2A,
  25808. 0x0F, 0x70, 0xA5, 0x4D, 0x77, 0x57, 0xCD, 0xE6,
  25809. 0x17, 0x5A, 0x68, 0x43, 0xB8, 0x61, 0xCB, 0x2B,
  25810. 0xC4, 0x83, 0x0C, 0x00, 0x12, 0x55, 0x4C, 0xFC,
  25811. 0x5D, 0x2C, 0x8A, 0x20, 0x27, 0xAA, 0x3C, 0xD9,
  25812. 0x67, 0x13, 0x0E, 0x9B, 0x96, 0x24, 0x1B, 0x11,
  25813. 0xC4, 0x32, 0x0C, 0x76, 0x49, 0xCC, 0x23, 0xA7,
  25814. 0x1B, 0xAF, 0xE6, 0x91, 0xAF, 0xC0, 0x8E, 0x68,
  25815. 0x0B, 0xCE, 0xF4, 0x29, 0x07, 0x00, 0x07, 0x18,
  25816. 0xE4, 0xEA, 0xCE, 0x8D, 0xA2, 0x82, 0x14, 0x19,
  25817. 0x7B, 0xE1, 0xC2, 0x69, 0xDA, 0x9C, 0xB5, 0x41,
  25818. 0xE1, 0xA3, 0xCE, 0x97, 0xCF, 0xAD, 0xF9, 0xC6,
  25819. 0x05, 0x87, 0x80, 0xFE, 0x67, 0x93, 0xDB, 0xFA,
  25820. 0x82, 0x18, 0xA2, 0x76, 0x0B, 0x80, 0x2B, 0x8D,
  25821. 0xA2, 0xAA, 0x27, 0x1A, 0x38, 0x77, 0x25, 0x23,
  25822. 0xA7, 0x67, 0x36, 0xA7, 0xA3, 0x1B, 0x9D, 0x30,
  25823. 0x37, 0xAD, 0x21, 0xCE, 0xBB, 0x11, 0xA4, 0x72,
  25824. 0xB8, 0x79, 0x2E, 0xB1, 0x75, 0x58, 0xB9, 0x40,
  25825. 0xE7, 0x08, 0x83, 0xF2, 0x64, 0x59, 0x2C, 0x68,
  25826. 0x9B, 0x24, 0x0B, 0xB4, 0x3D, 0x54, 0x08, 0xBF,
  25827. 0x44, 0x64, 0x32, 0xF4, 0x12, 0xF4, 0xB9, 0xA5,
  25828. 0xF6, 0x86, 0x5C, 0xC2, 0x52, 0xA4, 0x3C, 0xF4,
  25829. 0x0A, 0x32, 0x03, 0x91, 0x55, 0x55, 0x91, 0xD6,
  25830. 0x75, 0x61, 0xFD, 0xD0, 0x53, 0x53, 0xAB, 0x6B,
  25831. 0x01, 0x9B, 0x3A, 0x08, 0xA7, 0x33, 0x53, 0xD5,
  25832. 0x1B, 0x61, 0x13, 0xAB, 0x2F, 0xA5, 0x1D, 0x97,
  25833. 0x56, 0x48, 0xEE, 0x25, 0x4A, 0xF8, 0x9A, 0x23,
  25834. 0x05, 0x04, 0xA2, 0x36, 0xA4, 0x65, 0x82, 0x57,
  25835. 0x74, 0x0B, 0xDC, 0xBB, 0xE1, 0x70, 0x8A, 0xB0,
  25836. 0x22, 0xC3, 0xC5, 0x88, 0xA4, 0x10, 0xDB, 0x3B,
  25837. 0x9C, 0x30, 0x8A, 0x06, 0x27, 0x5B, 0xDF, 0x5B,
  25838. 0x48, 0x59, 0xD3, 0xA2, 0x61, 0x7A, 0x29, 0x5E,
  25839. 0x1A, 0x22, 0xF9, 0x01, 0x98, 0xBA, 0xD0, 0x16,
  25840. 0x6F, 0x4A, 0x94, 0x34, 0x17, 0xC5, 0xB8, 0x31,
  25841. 0x73, 0x6C, 0xB2, 0xC8, 0x58, 0x0A, 0xBF, 0xDE,
  25842. 0x57, 0x14, 0xB5, 0x86, 0xAB, 0xEE, 0xC0, 0xA1,
  25843. 0x75, 0xA0, 0x8B, 0xC7, 0x10, 0xC7, 0xA2, 0x89,
  25844. 0x5D, 0xE9, 0x3A, 0xC4, 0x38, 0x06, 0x1B, 0xF7,
  25845. 0x76, 0x5D, 0x0D, 0x21, 0xCD, 0x41, 0x81, 0x67,
  25846. 0xCA, 0xF8, 0x9D, 0x1E, 0xFC, 0x34, 0x48, 0xBC,
  25847. 0xBB, 0x96, 0xD6, 0x9B, 0x3E, 0x01, 0x0C, 0x82,
  25848. 0xD1, 0x5C, 0xAB, 0x6C, 0xAC, 0xC6, 0x79, 0x9D,
  25849. 0x36, 0x39, 0x66, 0x9A, 0x5B, 0x21, 0xA6, 0x33,
  25850. 0xC8, 0x65, 0xF8, 0x59, 0x3B, 0x5B, 0x7B, 0xC8,
  25851. 0x00, 0x26, 0x2B, 0xB8, 0x37, 0xA9, 0x24, 0xA6,
  25852. 0xC5, 0x44, 0x0E, 0x4F, 0xC7, 0x3B, 0x41, 0xB2,
  25853. 0x30, 0x92, 0xC3, 0x91, 0x2F, 0x4C, 0x6B, 0xEB,
  25854. 0xB4, 0xC7, 0xB4, 0xC6, 0x29, 0x08, 0xB0, 0x37,
  25855. 0x75, 0x66, 0x6C, 0x22, 0x22, 0x0D, 0xF9, 0xC8,
  25856. 0x88, 0x23, 0xE3, 0x44, 0xC7, 0x30, 0x83, 0x32,
  25857. 0x34, 0x5C, 0x8B, 0x79, 0x5D, 0x34, 0xE8, 0xC0,
  25858. 0x51, 0xF2, 0x1F, 0x5A, 0x21, 0xC2, 0x14, 0xB6,
  25859. 0x98, 0x41, 0x35, 0x87, 0x09, 0xB1, 0xC3, 0x05,
  25860. 0xB3, 0x2C, 0xC2, 0xC3, 0x80, 0x6A, 0xE9, 0xCC,
  25861. 0xD3, 0x81, 0x9F, 0xFF, 0x45, 0x07, 0xFE, 0x52,
  25862. 0x0F, 0xBF, 0xC2, 0x71, 0x99, 0xBC, 0x23, 0xBE,
  25863. 0x6B, 0x9B, 0x2D, 0x2A, 0xC1, 0x71, 0x75, 0x79,
  25864. 0xAC, 0x76, 0x92, 0x79, 0xE2, 0xA7, 0xAA, 0xC6,
  25865. 0x8A, 0x37, 0x1A, 0x47, 0xBA, 0x3A, 0x7D, 0xBE,
  25866. 0x01, 0x6F, 0x14, 0xE1, 0xA7, 0x27, 0x33, 0x36,
  25867. 0x63, 0xC4, 0xA5, 0xCD, 0x1A, 0x0F, 0x88, 0x36,
  25868. 0xCF, 0x7B, 0x5C, 0x49, 0xAC, 0x51, 0x48, 0x5C,
  25869. 0xA6, 0x03, 0x45, 0xC9, 0x90, 0xE0, 0x68, 0x88,
  25870. 0x72, 0x00, 0x03, 0x73, 0x13, 0x22, 0xC5, 0xB8,
  25871. 0xCD, 0x5E, 0x69, 0x07, 0xFD, 0xA1, 0x15, 0x7F,
  25872. 0x46, 0x8F, 0xD3, 0xFC, 0x20, 0xFA, 0x81, 0x75,
  25873. 0xEE, 0xC9, 0x5C, 0x29, 0x1A, 0x26, 0x2B, 0xA8,
  25874. 0xC5, 0xBE, 0x99, 0x08, 0x72, 0x41, 0x89, 0x30,
  25875. 0x85, 0x23, 0x39, 0xD8, 0x8A, 0x19, 0xB3, 0x7F,
  25876. 0xEF, 0xA3, 0xCF, 0xE8, 0x21, 0x75, 0xC2, 0x24,
  25877. 0x40, 0x7C, 0xA4, 0x14, 0xBA, 0xEB, 0x37, 0x92,
  25878. 0x3B, 0x4D, 0x2D, 0x83, 0x13, 0x4A, 0xE1, 0x54,
  25879. 0xE4, 0x90, 0xA9, 0xB4, 0x5A, 0x05, 0x63, 0xB0,
  25880. 0x6C, 0x95, 0x3C, 0x33, 0x01, 0x45, 0x0A, 0x21,
  25881. 0x76, 0xA0, 0x7C, 0x61, 0x4A, 0x74, 0xE3, 0x47,
  25882. 0x8E, 0x48, 0x50, 0x9F, 0x9A, 0x60, 0xAE, 0x94,
  25883. 0x5A, 0x8E, 0xBC, 0x78, 0x15, 0x12, 0x1D, 0x90,
  25884. 0xA3, 0xB0, 0xE0, 0x70, 0x91, 0xA0, 0x96, 0xCF,
  25885. 0x02, 0xC5, 0x7B, 0x25, 0xBC, 0xA5, 0x81, 0x26,
  25886. 0xAD, 0x0C, 0x62, 0x9C, 0xE1, 0x66, 0xA7, 0xED,
  25887. 0xB4, 0xB3, 0x32, 0x21, 0xA0, 0xD3, 0xF7, 0x2B,
  25888. 0x85, 0xD5, 0x62, 0xEC, 0x69, 0x8B, 0x7D, 0x0A,
  25889. 0x91, 0x3D, 0x73, 0x80, 0x6F, 0x1C, 0x5C, 0x87,
  25890. 0xB3, 0x8E, 0xC0, 0x03, 0xCB, 0x30, 0x3A, 0x3D,
  25891. 0xC5, 0x1B, 0x4B, 0x35, 0x35, 0x6A, 0x67, 0x82,
  25892. 0x6D, 0x6E, 0xDA, 0xA8, 0xFE, 0xB9, 0x3B, 0x98,
  25893. 0x49, 0x3B, 0x2D, 0x1C, 0x11, 0xB6, 0x76, 0xA6,
  25894. 0xAD, 0x95, 0x06, 0xA1, 0xAA, 0xAE, 0x13, 0xA8,
  25895. 0x24, 0xC7, 0xC0, 0x8D, 0x1C, 0x6C, 0x2C, 0x4D,
  25896. 0xBA, 0x96, 0x42, 0xC7, 0x6E, 0xA7, 0xF6, 0xC8,
  25897. 0x26, 0x4B, 0x64, 0xA2, 0x3C, 0xCC, 0xA9, 0xA7,
  25898. 0x46, 0x35, 0xFC, 0xBF, 0x03, 0xE0, 0x0F, 0x1B,
  25899. 0x57, 0x22, 0xB2, 0x14, 0x37, 0x67, 0x90, 0x79,
  25900. 0x3B, 0x2C, 0x4F, 0x0A, 0x13, 0xB5, 0xC4, 0x07,
  25901. 0x60, 0xB4, 0x21, 0x8E, 0x1D, 0x25, 0x94, 0xDC,
  25902. 0xB3, 0x0A, 0x70, 0xD9, 0xC1, 0x78, 0x2A, 0x5D,
  25903. 0xD3, 0x05, 0x76, 0xFA, 0x41, 0x44, 0xBF, 0xC8,
  25904. 0x41, 0x6E, 0xDA, 0x81, 0x18, 0xFC, 0x64, 0x72,
  25905. 0xF5, 0x6A, 0x97, 0x95, 0x86, 0xF3, 0x3B, 0xB0,
  25906. 0x70, 0xFB, 0x0F, 0x1B, 0x0B, 0x10, 0xBC, 0x48,
  25907. 0x97, 0xEB, 0xE0, 0x1B, 0xCA, 0x38, 0x93, 0xD4,
  25908. 0xE1, 0x6A, 0xDB, 0x25, 0x09, 0x3A, 0x74, 0x17,
  25909. 0xD0, 0x70, 0x8C, 0x83, 0xA2, 0x63, 0x22, 0xE2,
  25910. 0x2E, 0x63, 0x30, 0x09, 0x1E, 0x30, 0x15, 0x2B,
  25911. 0xF8, 0x23, 0x59, 0x7C, 0x04, 0xCC, 0xF4, 0xCF,
  25912. 0xC7, 0x33, 0x15, 0x78, 0xF4, 0x3A, 0x27, 0x26,
  25913. 0xCC, 0xB4, 0x28, 0x28, 0x9A, 0x90, 0xC8, 0x63,
  25914. 0x25, 0x9D, 0xD1, 0x80, 0xC5, 0xFF, 0x14, 0x2B,
  25915. 0xEF, 0x41, 0xC7, 0x71, 0x70, 0x94, 0xBE, 0x07,
  25916. 0x85, 0x6D, 0xA2, 0xB1, 0x40, 0xFA, 0x67, 0x71,
  25917. 0x09, 0x67, 0x35, 0x6A, 0xA4, 0x7D, 0xFB, 0xC8,
  25918. 0xD2, 0x55, 0xB4, 0x72, 0x2A, 0xB8, 0x6D, 0x43,
  25919. 0x9B, 0x7E, 0x0A, 0x60, 0x90, 0x25, 0x1D, 0x2D,
  25920. 0x4C, 0x1E, 0xD5, 0xF2, 0x0B, 0xBE, 0x68, 0x07,
  25921. 0xBF, 0x65, 0xA9, 0x0B, 0x7C, 0xB2, 0xEC, 0x01,
  25922. 0x02, 0xAF, 0x02, 0x80, 0x9D, 0xC9, 0xAC, 0x7D,
  25923. 0x0A, 0x3A, 0xBC, 0x69, 0xC1, 0x83, 0x65, 0xBC,
  25924. 0xFF, 0x59, 0x18, 0x5F, 0x33, 0x99, 0x68, 0x87,
  25925. 0x74, 0x61, 0x85, 0x90, 0x6C, 0x01, 0x91, 0xAE,
  25926. 0xD4, 0x40, 0x7E, 0x13, 0x94, 0x46, 0x45, 0x9B,
  25927. 0xE2, 0x9C, 0x68, 0x22, 0x71, 0x76, 0x44, 0x35,
  25928. 0x3D, 0x24, 0xAB, 0x63, 0x39, 0x15, 0x6A, 0x9C,
  25929. 0x42, 0x49, 0x09, 0xF0, 0xA9, 0x02, 0x5B, 0xB7,
  25930. 0x47, 0x20, 0x77, 0x9B, 0xE4, 0x3F, 0x16, 0xD8,
  25931. 0x1C, 0x8C, 0xC6, 0x66, 0xE9, 0x97, 0x10, 0xD8,
  25932. 0xC6, 0x8B, 0xB5, 0xCC, 0x4E, 0x12, 0xF3, 0x14,
  25933. 0xE9, 0x25, 0xA5, 0x51, 0xF0, 0x9C, 0xC5, 0x90,
  25934. 0x03, 0xA1, 0xF8, 0x81, 0x03, 0xC2, 0x54, 0xBB,
  25935. 0x97, 0x8D, 0x75, 0xF3, 0x94, 0xD3, 0x54, 0x0E,
  25936. 0x31, 0xE7, 0x71, 0xCD, 0xA3, 0x6E, 0x39, 0xEC,
  25937. 0x54, 0xA6, 0x2B, 0x58, 0x32, 0x66, 0x4D, 0x82,
  25938. 0x1A, 0x72, 0xF1, 0xE6, 0xAF, 0xBB, 0xA2, 0x7F,
  25939. 0x84, 0x29, 0x5B, 0x26, 0x94, 0xC4, 0x98, 0x49,
  25940. 0x8E, 0x81, 0x2B, 0xC8, 0xE9, 0x37, 0x8F, 0xE5,
  25941. 0x41, 0xCE, 0xC5, 0x89, 0x1B, 0x25, 0x06, 0x29,
  25942. 0x01, 0xCB, 0x72, 0x12, 0xE3, 0xCD, 0xC4, 0x61,
  25943. 0x79, 0xEC, 0x5B, 0xCE, 0xC1, 0x0B, 0xC0, 0xB9,
  25944. 0x31, 0x1D, 0xE0, 0x50, 0x74, 0x29, 0x06, 0x87,
  25945. 0xFD, 0x6A, 0x53, 0x92, 0x67, 0x16, 0x54, 0x28,
  25946. 0x4C, 0xD9, 0xC8, 0xCC, 0x3E, 0xBA, 0x80, 0xEB,
  25947. 0x3B, 0x66, 0x2E, 0xB5, 0x3E, 0xB7, 0x51, 0x16,
  25948. 0x70, 0x4A, 0x1F, 0xEB, 0x5C, 0x2D, 0x05, 0x63,
  25949. 0x38, 0x53, 0x28, 0x68, 0xDD, 0xF2, 0x4E, 0xB8,
  25950. 0x99, 0x2A, 0xB8, 0x56, 0x5D, 0x9E, 0x49, 0x0C,
  25951. 0xAD, 0xF1, 0x48, 0x04, 0x36, 0x0D, 0xAA, 0x90,
  25952. 0x71, 0x8E, 0xAB, 0x61, 0x6B, 0xAB, 0x07, 0x65,
  25953. 0xD3, 0x39, 0x87, 0xB4, 0x7E, 0xFB, 0x65, 0x99,
  25954. 0xC5, 0x56, 0x32, 0x35, 0xE6, 0x1E, 0x4B, 0xE6,
  25955. 0x70, 0xE9, 0x79, 0x55, 0xAB, 0x29, 0x2D, 0x97,
  25956. 0x32, 0xCB, 0x89, 0x30, 0x94, 0x8A, 0xC8, 0x2D,
  25957. 0xF2, 0x30, 0xAC, 0x72, 0x29, 0x7A, 0x23, 0x67,
  25958. 0x9D, 0x6B, 0x94, 0xC1, 0x7F, 0x13, 0x59, 0x48,
  25959. 0x32, 0x54, 0xFE, 0xDC, 0x2F, 0x05, 0x81, 0x9F,
  25960. 0x0D, 0x06, 0x9A, 0x44, 0x3B, 0x78, 0xE3, 0xFC,
  25961. 0x6C, 0x3E, 0xF4, 0x71, 0x4B, 0x05, 0xA3, 0xFC,
  25962. 0xA8, 0x1C, 0xBB, 0xA6, 0x02, 0x42, 0xA7, 0x06,
  25963. 0x0C, 0xD8, 0x85, 0xD8, 0xF3, 0x99, 0x81, 0xBB,
  25964. 0x18, 0x09, 0x2B, 0x23, 0xDA, 0xA5, 0x9F, 0xD9,
  25965. 0x57, 0x83, 0x88, 0x68, 0x8A, 0x09, 0xBB, 0xA0,
  25966. 0x79, 0xBC, 0x80, 0x9A, 0x54, 0x84, 0x3A, 0x60,
  25967. 0x38, 0x5E, 0x23, 0x10, 0xBB, 0xCB, 0xCC, 0x02,
  25968. 0x13, 0xCE, 0x3D, 0xFA, 0xAB, 0x33, 0xB4, 0x7F,
  25969. 0x9D, 0x63, 0x05, 0xBC, 0x95, 0xC6, 0x10, 0x78,
  25970. 0x13, 0xC5, 0x85, 0xC4, 0xB6, 0x57, 0xBF, 0x30,
  25971. 0x54, 0x28, 0x33, 0xB1, 0x49, 0x49, 0xF5, 0x73,
  25972. 0xC0, 0x61, 0x2A, 0xD5, 0x24, 0xBA, 0xAE, 0x69,
  25973. 0x59, 0x0C, 0x12, 0x77, 0xB8, 0x6C, 0x28, 0x65,
  25974. 0x71, 0xBF, 0x66, 0xB3, 0xCF, 0xF4, 0x6A, 0x38,
  25975. 0x58, 0xC0, 0x99, 0x06, 0xA7, 0x94, 0xDF, 0x4A,
  25976. 0x06, 0xE9, 0xD4, 0xB0, 0xA2, 0xE4, 0x3F, 0x10,
  25977. 0xF7, 0x2A, 0x6C, 0x6C, 0x47, 0xE5, 0x64, 0x6E,
  25978. 0x2C, 0x79, 0x9B, 0x71, 0xC3, 0x3E, 0xD2, 0xF0,
  25979. 0x1E, 0xEB, 0x45, 0x93, 0x8E, 0xB7, 0xA4, 0xE2,
  25980. 0xE2, 0x90, 0x8C, 0x53, 0x55, 0x8A, 0x54, 0x0D,
  25981. 0x35, 0x03, 0x69, 0xFA, 0x18, 0x9C, 0x61, 0x69,
  25982. 0x43, 0xF7, 0x98, 0x1D, 0x76, 0x18, 0xCF, 0x02,
  25983. 0xA5, 0xB0, 0xA2, 0xBC, 0xC4, 0x22, 0xE8, 0x57,
  25984. 0xD1, 0xA4, 0x78, 0x71, 0x25, 0x3D, 0x08, 0x29,
  25985. 0x3C, 0x1C, 0x17, 0x9B, 0xCD, 0xC0, 0x43, 0x70,
  25986. 0x69, 0x10, 0x74, 0x18, 0x20, 0x5F, 0xDB, 0x98,
  25987. 0x56, 0x62, 0x3B, 0x8C, 0xA6, 0xB6, 0x94, 0xC9,
  25988. 0x6C, 0x08, 0x4B, 0x17, 0xF1, 0x3B, 0xB6, 0xDF,
  25989. 0x12, 0xB2, 0xCF, 0xBB, 0xC2, 0xB0, 0xE0, 0xC3,
  25990. 0x4B, 0x00, 0xD0, 0xFC, 0xD0, 0xAE, 0xCF, 0xB2,
  25991. 0x79, 0x24, 0xF6, 0x98, 0x4E, 0x74, 0x7B, 0xE2,
  25992. 0xA0, 0x9D, 0x83, 0xA8, 0x66, 0x45, 0x90, 0xA8,
  25993. 0x07, 0x73, 0x31, 0x49, 0x1A, 0x4F, 0x7D, 0x72,
  25994. 0x08, 0x43, 0xF2, 0x3E, 0x65, 0x2C, 0x6F, 0xA8,
  25995. 0x40, 0x30, 0x8D, 0xB4, 0x02, 0x03, 0x37, 0xAA,
  25996. 0xD3, 0x79, 0x67, 0x03, 0x4A, 0x9F, 0xB5, 0x23,
  25997. 0xB6, 0x7C, 0xA7, 0x03, 0x30, 0xF0, 0x2D, 0x9E,
  25998. 0xA2, 0x0C, 0x1E, 0x84, 0xCB, 0x8E, 0x57, 0x57,
  25999. 0xC9, 0xE1, 0x89, 0x6B, 0x60, 0x58, 0x14, 0x41,
  26000. 0xED, 0x61, 0x8A, 0xA5, 0xB2, 0x6D, 0xA5, 0x6C,
  26001. 0x0A, 0x5A, 0x73, 0xC4, 0xDC, 0xFD, 0x75, 0x5E,
  26002. 0x61, 0x0B, 0x4F, 0xC8, 0x1F, 0xF8, 0x4E, 0x21,
  26003. 0xD2, 0xE5, 0x74, 0xDF, 0xD8, 0xCD, 0x0A, 0xE8,
  26004. 0x93, 0xAA, 0x7E, 0x12, 0x5B, 0x44, 0xB9, 0x24,
  26005. 0xF4, 0x52, 0x23, 0xEC, 0x09, 0xF2, 0xAD, 0x11,
  26006. 0x41, 0xEA, 0x93, 0xA6, 0x80, 0x50, 0xDB, 0xF6,
  26007. 0x99, 0xE3, 0x24, 0x68, 0x84, 0x18, 0x1F, 0x8E,
  26008. 0x1D, 0xD4, 0x4E, 0x0C, 0x76, 0x29, 0x09, 0x33,
  26009. 0x30, 0x22, 0x1F, 0xD6, 0x7D, 0x9B, 0x7D, 0x6E,
  26010. 0x15, 0x10, 0xB2, 0xDB, 0xAD, 0x87, 0x62, 0xF7
  26011. };
  26012. #endif
  26013. static byte pubKey[KYBER_MAX_PUBLIC_KEY_SIZE];
  26014. static byte privKey[KYBER_MAX_PRIVATE_KEY_SIZE];
  26015. key = (KyberKey*)XMALLOC(sizeof(KyberKey), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  26016. ExpectNotNull(key);
  26017. if (key != NULL) {
  26018. XMEMSET(key, 0, sizeof(KyberKey));
  26019. }
  26020. #ifndef WOLFSSL_NO_KYBER512
  26021. ExpectIntEQ(wc_KyberKey_Init(KYBER512, key, NULL, INVALID_DEVID), 0);
  26022. ExpectIntEQ(wc_KyberKey_MakeKeyWithRandom(key, seed_512, sizeof(seed_512)),
  26023. 0);
  26024. ExpectIntEQ(wc_KyberKey_EncodePublicKey(key, pubKey,
  26025. KYBER512_PUBLIC_KEY_SIZE), 0);
  26026. ExpectIntEQ(wc_KyberKey_EncodePrivateKey(key, privKey,
  26027. KYBER512_PRIVATE_KEY_SIZE), 0);
  26028. ExpectIntEQ(XMEMCMP(pubKey, ek_512, KYBER512_PUBLIC_KEY_SIZE), 0);
  26029. ExpectIntEQ(XMEMCMP(privKey, dk_512, KYBER512_PRIVATE_KEY_SIZE), 0);
  26030. wc_KyberKey_Free(key);
  26031. #endif
  26032. #ifndef WOLFSSL_NO_KYBER768
  26033. ExpectIntEQ(wc_KyberKey_Init(KYBER768, key, NULL, INVALID_DEVID), 0);
  26034. ExpectIntEQ(wc_KyberKey_MakeKeyWithRandom(key, seed_768, sizeof(seed_768)),
  26035. 0);
  26036. ExpectIntEQ(wc_KyberKey_EncodePublicKey(key, pubKey,
  26037. KYBER768_PUBLIC_KEY_SIZE), 0);
  26038. ExpectIntEQ(wc_KyberKey_EncodePrivateKey(key, privKey,
  26039. KYBER768_PRIVATE_KEY_SIZE), 0);
  26040. ExpectIntEQ(XMEMCMP(pubKey, ek_768, KYBER768_PUBLIC_KEY_SIZE), 0);
  26041. ExpectIntEQ(XMEMCMP(privKey, dk_768, KYBER768_PRIVATE_KEY_SIZE), 0);
  26042. wc_KyberKey_Free(key);
  26043. #endif
  26044. #ifndef WOLFSSL_NO_KYBER1024
  26045. ExpectIntEQ(wc_KyberKey_Init(KYBER1024, key, NULL, INVALID_DEVID), 0);
  26046. ExpectIntEQ(wc_KyberKey_MakeKeyWithRandom(key, seed_1024,
  26047. sizeof(seed_1024)), 0);
  26048. ExpectIntEQ(wc_KyberKey_EncodePublicKey(key, pubKey,
  26049. KYBER1024_PUBLIC_KEY_SIZE), 0);
  26050. ExpectIntEQ(wc_KyberKey_EncodePrivateKey(key, privKey,
  26051. KYBER1024_PRIVATE_KEY_SIZE), 0);
  26052. ExpectIntEQ(XMEMCMP(pubKey, ek_1024, KYBER1024_PUBLIC_KEY_SIZE), 0);
  26053. ExpectIntEQ(XMEMCMP(privKey, dk_1024, KYBER1024_PRIVATE_KEY_SIZE), 0);
  26054. wc_KyberKey_Free(key);
  26055. #endif
  26056. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  26057. #endif
  26058. return EXPECT_RESULT();
  26059. }
  26060. static int test_wc_kyber_encapsulate_kats(void)
  26061. {
  26062. EXPECT_DECLS;
  26063. #if defined(WOLFSSL_HAVE_KYBER) && defined(WOLFSSL_WC_KYBER) && \
  26064. !defined(WOLFSSL_KYBER_ORIGINAL)
  26065. KyberKey* key;
  26066. #ifndef WOLFSSL_NO_KYBER512
  26067. static const byte ek_512[KYBER512_PUBLIC_KEY_SIZE] = {
  26068. 0xDD, 0x19, 0x24, 0x93, 0x5A, 0xA8, 0xE6, 0x17,
  26069. 0xAF, 0x18, 0xB5, 0xA0, 0x65, 0xAC, 0x45, 0x72,
  26070. 0x77, 0x67, 0xEE, 0x89, 0x7C, 0xF4, 0xF9, 0x44,
  26071. 0x2B, 0x2A, 0xCE, 0x30, 0xC0, 0x23, 0x7B, 0x30,
  26072. 0x7D, 0x3E, 0x76, 0xBF, 0x8E, 0xEB, 0x78, 0xAD,
  26073. 0xDC, 0x4A, 0xAC, 0xD1, 0x64, 0x63, 0xD8, 0x60,
  26074. 0x2F, 0xD5, 0x48, 0x7B, 0x63, 0xC8, 0x8B, 0xB6,
  26075. 0x60, 0x27, 0xF3, 0x7D, 0x0D, 0x61, 0x4D, 0x6F,
  26076. 0x9C, 0x24, 0x60, 0x3C, 0x42, 0x94, 0x76, 0x64,
  26077. 0xAC, 0x43, 0x98, 0xC6, 0xC5, 0x23, 0x83, 0x46,
  26078. 0x9B, 0x4F, 0x97, 0x77, 0xE5, 0xEC, 0x72, 0x06,
  26079. 0x21, 0x0F, 0x3E, 0x5A, 0x79, 0x6B, 0xF4, 0x5C,
  26080. 0x53, 0x26, 0x8E, 0x25, 0xF3, 0x9A, 0xC2, 0x61,
  26081. 0xAF, 0x3B, 0xFA, 0x2E, 0xE7, 0x55, 0xBE, 0xB8,
  26082. 0xB6, 0x7A, 0xB3, 0xAC, 0x8D, 0xF6, 0xC6, 0x29,
  26083. 0xC1, 0x17, 0x6E, 0x9E, 0x3B, 0x96, 0x5E, 0x93,
  26084. 0x69, 0xF9, 0xB3, 0xB9, 0x2A, 0xD7, 0xC2, 0x09,
  26085. 0x55, 0x64, 0x1D, 0x99, 0x52, 0x6F, 0xE7, 0xB9,
  26086. 0xFE, 0x8C, 0x85, 0x08, 0x20, 0x27, 0x5C, 0xD9,
  26087. 0x64, 0x84, 0x92, 0x50, 0x09, 0x07, 0x33, 0xCE,
  26088. 0x12, 0x4E, 0xCF, 0x31, 0x66, 0x24, 0x37, 0x4B,
  26089. 0xD1, 0x8B, 0x7C, 0x35, 0x8C, 0x06, 0xE9, 0xC1,
  26090. 0x36, 0xEE, 0x12, 0x59, 0xA9, 0x24, 0x5A, 0xBC,
  26091. 0x55, 0xB9, 0x64, 0xD6, 0x89, 0xF5, 0xA0, 0x82,
  26092. 0x92, 0xD2, 0x82, 0x65, 0x65, 0x8E, 0xBB, 0x40,
  26093. 0xCB, 0xFE, 0x48, 0x8A, 0x22, 0x28, 0x27, 0x55,
  26094. 0x90, 0xAB, 0x9F, 0x32, 0xA3, 0x41, 0x09, 0x70,
  26095. 0x9C, 0x1C, 0x29, 0x1D, 0x4A, 0x23, 0x33, 0x72,
  26096. 0x74, 0xC7, 0xA5, 0xA5, 0x99, 0x1C, 0x7A, 0x87,
  26097. 0xB8, 0x1C, 0x97, 0x4A, 0xB1, 0x8C, 0xE7, 0x78,
  26098. 0x59, 0xE4, 0x99, 0x5E, 0x7C, 0x14, 0xF0, 0x37,
  26099. 0x17, 0x48, 0xB7, 0x71, 0x2F, 0xB5, 0x2C, 0x59,
  26100. 0x66, 0xCD, 0x63, 0x06, 0x3C, 0x4F, 0x3B, 0x81,
  26101. 0xB4, 0x7C, 0x45, 0xDD, 0xE8, 0x3F, 0xB3, 0xA2,
  26102. 0x72, 0x40, 0x29, 0xB1, 0x0B, 0x32, 0x30, 0x21,
  26103. 0x4C, 0x04, 0xFA, 0x05, 0x77, 0xFC, 0x29, 0xAC,
  26104. 0x90, 0x86, 0xAE, 0x18, 0xC5, 0x3B, 0x3E, 0xD4,
  26105. 0x4E, 0x50, 0x74, 0x12, 0xFC, 0xA0, 0x4B, 0x4F,
  26106. 0x53, 0x8A, 0x51, 0x58, 0x8E, 0xC1, 0xF1, 0x02,
  26107. 0x9D, 0x15, 0x2D, 0x9A, 0xE7, 0x73, 0x5F, 0x76,
  26108. 0xA0, 0x77, 0xAA, 0x94, 0x84, 0x38, 0x0A, 0xED,
  26109. 0x91, 0x89, 0xE5, 0x91, 0x24, 0x87, 0xFC, 0xC5,
  26110. 0xB7, 0xC7, 0x01, 0x2D, 0x92, 0x23, 0xDD, 0x96,
  26111. 0x7E, 0xEC, 0xDA, 0xC3, 0x00, 0x8A, 0x89, 0x31,
  26112. 0xB6, 0x48, 0x24, 0x35, 0x37, 0xF5, 0x48, 0xC1,
  26113. 0x71, 0x69, 0x8C, 0x5B, 0x38, 0x1D, 0x84, 0x6A,
  26114. 0x72, 0xE5, 0xC9, 0x2D, 0x42, 0x26, 0xC5, 0xA8,
  26115. 0x90, 0x98, 0x84, 0xF1, 0xC4, 0xA3, 0x40, 0x4C,
  26116. 0x17, 0x20, 0xA5, 0x27, 0x94, 0x14, 0xD7, 0xF2,
  26117. 0x7B, 0x2B, 0x98, 0x26, 0x52, 0xB6, 0x74, 0x02,
  26118. 0x19, 0xC5, 0x6D, 0x21, 0x77, 0x80, 0xD7, 0xA5,
  26119. 0xE5, 0xBA, 0x59, 0x83, 0x63, 0x49, 0xF7, 0x26,
  26120. 0x88, 0x1D, 0xEA, 0x18, 0xEF, 0x75, 0xC0, 0x77,
  26121. 0x2A, 0x8B, 0x92, 0x27, 0x66, 0x95, 0x37, 0x18,
  26122. 0xCA, 0xCC, 0x14, 0xCC, 0xBA, 0xCB, 0x5F, 0xC4,
  26123. 0x12, 0xA2, 0xD0, 0xBE, 0x52, 0x18, 0x17, 0x64,
  26124. 0x5A, 0xB2, 0xBF, 0x6A, 0x47, 0x85, 0xE9, 0x2B,
  26125. 0xC9, 0x4C, 0xAF, 0x47, 0x7A, 0x96, 0x78, 0x76,
  26126. 0x79, 0x6C, 0x0A, 0x51, 0x90, 0x31, 0x5A, 0xC0,
  26127. 0x88, 0x56, 0x71, 0xA4, 0xC7, 0x49, 0x56, 0x4C,
  26128. 0x3B, 0x2C, 0x7A, 0xED, 0x90, 0x64, 0xEB, 0xA2,
  26129. 0x99, 0xEF, 0x21, 0x4B, 0xA2, 0xF4, 0x04, 0x93,
  26130. 0x66, 0x7C, 0x8B, 0xD0, 0x32, 0xAE, 0xC5, 0x62,
  26131. 0x17, 0x11, 0xB4, 0x1A, 0x38, 0x52, 0xC5, 0xC2,
  26132. 0xBA, 0xB4, 0xA3, 0x49, 0xCE, 0x4B, 0x7F, 0x08,
  26133. 0x5A, 0x81, 0x2B, 0xBB, 0xC8, 0x20, 0xB8, 0x1B,
  26134. 0xEF, 0xE6, 0x3A, 0x05, 0xB8, 0xBC, 0xDF, 0xE9,
  26135. 0xC2, 0xA7, 0x0A, 0x8B, 0x1A, 0xCA, 0x9B, 0xF9,
  26136. 0x81, 0x64, 0x81, 0x90, 0x7F, 0xF4, 0x43, 0x24,
  26137. 0x61, 0x11, 0x12, 0x87, 0x30, 0x3F, 0x0B, 0xD8,
  26138. 0x17, 0xC0, 0x57, 0x26, 0xBF, 0xA1, 0x8A, 0x2E,
  26139. 0x24, 0xC7, 0x72, 0x49, 0x21, 0x02, 0x80, 0x32,
  26140. 0xF6, 0x22, 0xBD, 0x96, 0x0A, 0x31, 0x7D, 0x83,
  26141. 0xB3, 0x56, 0xB5, 0x7F, 0x4A, 0x80, 0x04, 0x49,
  26142. 0x9C, 0xBC, 0x73, 0xC9, 0x7D, 0x1E, 0xB7, 0x74,
  26143. 0x59, 0x72, 0x63, 0x1C, 0x05, 0x61, 0xC1, 0xA3,
  26144. 0xAB, 0x6E, 0xF9, 0x1B, 0xD3, 0x63, 0x28, 0x0A,
  26145. 0x10, 0x54, 0x5D, 0xA6, 0x93, 0xE6, 0xD5, 0x8A,
  26146. 0xED, 0x68, 0x45, 0xE7, 0xCC, 0x5F, 0x0D, 0x08,
  26147. 0xCA, 0x79, 0x05, 0x05, 0x2C, 0x77, 0x36, 0x6D,
  26148. 0x19, 0x72, 0xCC, 0xFC, 0xC1, 0xA2, 0x76, 0x10,
  26149. 0xCB, 0x54, 0x36, 0x65, 0xAA, 0x79, 0x8E, 0x20,
  26150. 0x94, 0x01, 0x28, 0xB9, 0x56, 0x7A, 0x7E, 0xDB,
  26151. 0x7A, 0x90, 0x04, 0x07, 0xC7, 0x0D, 0x35, 0x94,
  26152. 0x38, 0x43, 0x5E, 0x13, 0x96, 0x16, 0x08, 0xD5,
  26153. 0x52, 0xA9, 0x4C, 0x5C, 0xDA, 0x78, 0x59, 0x22,
  26154. 0x05, 0x09, 0xB4, 0x83, 0xC5, 0xC5, 0x2A, 0x21,
  26155. 0x0E, 0x9C, 0x81, 0x2B, 0xC0, 0xC2, 0x32, 0x8C,
  26156. 0xA0, 0x0E, 0x78, 0x9A, 0x56, 0xB2, 0x60, 0x6B,
  26157. 0x90, 0x29, 0x2E, 0x35, 0x43, 0xDA, 0xCA, 0xA2,
  26158. 0x43, 0x18, 0x41, 0xD6, 0x1A, 0x22, 0xCA, 0x90,
  26159. 0xC1, 0xCC, 0xF0, 0xB5, 0xB4, 0xE0, 0xA6, 0xF6,
  26160. 0x40, 0x53, 0x6D, 0x1A, 0x26, 0xAB, 0x5B, 0x8D,
  26161. 0x21, 0x51, 0x32, 0x79, 0x28, 0xCE, 0x02, 0x90,
  26162. 0x4C, 0xF1, 0xD1, 0x5E, 0x32, 0x78, 0x8A, 0x95,
  26163. 0xF6, 0x2D, 0x3C, 0x27, 0x0B, 0x6F, 0xA1, 0x50,
  26164. 0x8F, 0x97, 0xB9, 0x15, 0x5A, 0x27, 0x26, 0xD8,
  26165. 0x0A, 0x1A, 0xFA, 0x3C, 0x53, 0x87, 0xA2, 0x76,
  26166. 0xA4, 0xD0, 0x31, 0xA0, 0x8A, 0xBF, 0x4F, 0x2E,
  26167. 0x74, 0xF1, 0xA0, 0xBB, 0x8A, 0x0F, 0xD3, 0xCB
  26168. };
  26169. static const byte seed_512[KYBER_ENC_RAND_SZ] = {
  26170. 0x6F, 0xF0, 0x2E, 0x1D, 0xC7, 0xFD, 0x91, 0x1B,
  26171. 0xEE, 0xE0, 0xC6, 0x92, 0xC8, 0xBD, 0x10, 0x0C,
  26172. 0x3E, 0x5C, 0x48, 0x96, 0x4D, 0x31, 0xDF, 0x92,
  26173. 0x99, 0x42, 0x18, 0xE8, 0x06, 0x64, 0xA6, 0xCA
  26174. };
  26175. static const byte c_512[KYBER512_CIPHER_TEXT_SIZE] = {
  26176. 0x19, 0xC5, 0x92, 0x50, 0x59, 0x07, 0xC2, 0x4C,
  26177. 0x5F, 0xA2, 0xEB, 0xFA, 0x93, 0x2D, 0x2C, 0xBB,
  26178. 0x48, 0xF3, 0xE4, 0x34, 0x0A, 0x28, 0xF7, 0xEB,
  26179. 0xA5, 0xD0, 0x68, 0xFC, 0xAC, 0xAB, 0xED, 0xF7,
  26180. 0x77, 0x84, 0xE2, 0xB2, 0x4D, 0x79, 0x61, 0x77,
  26181. 0x5F, 0x0B, 0xF1, 0xA9, 0x97, 0xAE, 0x8B, 0xA9,
  26182. 0xFC, 0x43, 0x11, 0xBE, 0x63, 0x71, 0x67, 0x79,
  26183. 0xC2, 0xB7, 0x88, 0xF8, 0x12, 0xCB, 0xB7, 0x8C,
  26184. 0x74, 0xE7, 0x51, 0x7E, 0x22, 0xE9, 0x10, 0xEF,
  26185. 0xF5, 0xF3, 0x8D, 0x44, 0x46, 0x9C, 0x50, 0xDE,
  26186. 0x16, 0x75, 0xAE, 0x19, 0x8F, 0xD6, 0xA2, 0x89,
  26187. 0xAE, 0x7E, 0x6C, 0x30, 0xA9, 0xD4, 0x35, 0x1B,
  26188. 0x3D, 0x1F, 0x4C, 0x36, 0xEF, 0xF9, 0xC6, 0x8D,
  26189. 0xA9, 0x1C, 0x40, 0xB8, 0x2D, 0xC9, 0xB2, 0x79,
  26190. 0x9A, 0x33, 0xA2, 0x6B, 0x60, 0xA4, 0xE7, 0x0D,
  26191. 0x71, 0x01, 0x86, 0x27, 0x79, 0x46, 0x9F, 0x3A,
  26192. 0x9D, 0xAE, 0xC8, 0xE3, 0xE8, 0xF8, 0xC6, 0xA1,
  26193. 0x6B, 0xF0, 0x92, 0xFB, 0xA5, 0x86, 0x61, 0x86,
  26194. 0xB8, 0xD2, 0x08, 0xFD, 0xEB, 0x27, 0x4A, 0xC1,
  26195. 0xF8, 0x29, 0x65, 0x9D, 0xC2, 0xBE, 0x4A, 0xC4,
  26196. 0xF3, 0x06, 0xCB, 0x55, 0x84, 0xBA, 0xD1, 0x93,
  26197. 0x6A, 0x92, 0xC9, 0xB7, 0x68, 0x19, 0x23, 0x42,
  26198. 0x81, 0xBB, 0x39, 0x58, 0x41, 0xC2, 0x57, 0x56,
  26199. 0x08, 0x6E, 0xA5, 0x64, 0xCA, 0x3E, 0x22, 0x7E,
  26200. 0x3D, 0x9F, 0x10, 0x52, 0xC0, 0x76, 0x6D, 0x2E,
  26201. 0xB7, 0x9A, 0x47, 0xC1, 0x50, 0x72, 0x1E, 0x0D,
  26202. 0xEA, 0x7C, 0x00, 0x69, 0xD5, 0x51, 0xB2, 0x64,
  26203. 0x80, 0x1B, 0x77, 0x27, 0xEC, 0xAF, 0x82, 0xEE,
  26204. 0xCB, 0x99, 0xA8, 0x76, 0xFD, 0xA0, 0x90, 0xBF,
  26205. 0x6C, 0x3F, 0xC6, 0xB1, 0x09, 0xF1, 0x70, 0x14,
  26206. 0x85, 0xF0, 0x3C, 0xE6, 0x62, 0x74, 0xB8, 0x43,
  26207. 0x5B, 0x0A, 0x01, 0x4C, 0xFB, 0x3E, 0x79, 0xCC,
  26208. 0xED, 0x67, 0x05, 0x7B, 0x5A, 0xE2, 0xAD, 0x7F,
  26209. 0x52, 0x79, 0xEB, 0x71, 0x49, 0x42, 0xE4, 0xC1,
  26210. 0xCC, 0xFF, 0x7E, 0x85, 0xC0, 0xDB, 0x43, 0xE5,
  26211. 0xD4, 0x12, 0x89, 0x20, 0x73, 0x63, 0xB4, 0x44,
  26212. 0xBB, 0x51, 0xBB, 0x8A, 0xB0, 0x37, 0x1E, 0x70,
  26213. 0xCB, 0xD5, 0x5F, 0x0F, 0x3D, 0xAD, 0x40, 0x3E,
  26214. 0x10, 0x51, 0x76, 0xE3, 0xE8, 0xA2, 0x25, 0xD8,
  26215. 0x4A, 0xC8, 0xBE, 0xE3, 0x8C, 0x82, 0x1E, 0xE0,
  26216. 0xF5, 0x47, 0x43, 0x11, 0x45, 0xDC, 0xB3, 0x13,
  26217. 0x92, 0x86, 0xAB, 0xB1, 0x17, 0x94, 0xA4, 0x3A,
  26218. 0x3C, 0x1B, 0x52, 0x29, 0xE4, 0xBC, 0xFE, 0x95,
  26219. 0x9C, 0x78, 0xAD, 0xAE, 0xE2, 0xD5, 0xF2, 0x49,
  26220. 0x7B, 0x5D, 0x24, 0xBC, 0x21, 0xFA, 0x03, 0xA9,
  26221. 0xA5, 0x8C, 0x24, 0x55, 0x37, 0x3E, 0xC8, 0x95,
  26222. 0x83, 0xE7, 0xE5, 0x88, 0xD7, 0xFE, 0x67, 0x99,
  26223. 0x1E, 0xE9, 0x37, 0x83, 0xED, 0x4A, 0x6F, 0x9E,
  26224. 0xEA, 0xE0, 0x4E, 0x64, 0xE2, 0xE1, 0xE0, 0xE6,
  26225. 0x99, 0xF6, 0xDC, 0x9C, 0x5D, 0x39, 0xEF, 0x92,
  26226. 0x78, 0xC9, 0x85, 0xE7, 0xFD, 0xF2, 0xA7, 0x64,
  26227. 0xFF, 0xD1, 0xA0, 0xB9, 0x57, 0x92, 0xAD, 0x68,
  26228. 0x1E, 0x93, 0x0D, 0x76, 0xDF, 0x4E, 0xFE, 0x5D,
  26229. 0x65, 0xDB, 0xBD, 0x0F, 0x14, 0x38, 0x48, 0x1E,
  26230. 0xD8, 0x33, 0xAD, 0x49, 0x46, 0xAD, 0x1C, 0x69,
  26231. 0xAD, 0x21, 0xDD, 0x7C, 0x86, 0x18, 0x57, 0x74,
  26232. 0x42, 0x6F, 0x3F, 0xCF, 0x53, 0xB5, 0x2A, 0xD4,
  26233. 0xB4, 0x0D, 0x22, 0x8C, 0xE1, 0x24, 0x07, 0x2F,
  26234. 0x59, 0x2C, 0x7D, 0xAA, 0x05, 0x7F, 0x17, 0xD7,
  26235. 0x90, 0xA5, 0xBD, 0x5B, 0x93, 0x83, 0x4D, 0x58,
  26236. 0xC0, 0x8C, 0x88, 0xDC, 0x8F, 0x0E, 0xF4, 0x88,
  26237. 0x15, 0x64, 0x25, 0xB7, 0x44, 0x65, 0x4E, 0xAC,
  26238. 0xA9, 0xD6, 0x48, 0x58, 0xA4, 0xD6, 0xCE, 0xB4,
  26239. 0x78, 0x79, 0x51, 0x94, 0xBF, 0xAD, 0xB1, 0x8D,
  26240. 0xC0, 0xEA, 0x05, 0x4F, 0x97, 0x71, 0x21, 0x5A,
  26241. 0xD3, 0xCB, 0x1F, 0xD0, 0x31, 0xD7, 0xBE, 0x45,
  26242. 0x98, 0x62, 0x19, 0x26, 0x47, 0x8D, 0x37, 0x5A,
  26243. 0x18, 0x45, 0xAA, 0x91, 0xD7, 0xC7, 0x33, 0xF8,
  26244. 0xF0, 0xE1, 0x88, 0xC8, 0x38, 0x96, 0xED, 0xF8,
  26245. 0x3B, 0x86, 0x46, 0xC9, 0x9E, 0x29, 0xC0, 0xDA,
  26246. 0x22, 0x90, 0xE7, 0x1C, 0x3D, 0x2E, 0x97, 0x07,
  26247. 0x20, 0xC9, 0x7B, 0x5B, 0x7F, 0x95, 0x04, 0x86,
  26248. 0x03, 0x3C, 0x6A, 0x25, 0x71, 0xDD, 0xF2, 0xBC,
  26249. 0xCD, 0xAB, 0xB2, 0xDF, 0xA5, 0xFC, 0xE4, 0xC3,
  26250. 0xA1, 0x88, 0x46, 0x06, 0x04, 0x1D, 0x18, 0x1C,
  26251. 0x72, 0x87, 0x94, 0xAE, 0x0E, 0x80, 0x6E, 0xCB,
  26252. 0x49, 0xAF, 0x16, 0x75, 0x6A, 0x4C, 0xE7, 0x3C,
  26253. 0x87, 0xBD, 0x42, 0x34, 0xE6, 0x0F, 0x05, 0x53,
  26254. 0x5F, 0xA5, 0x92, 0x9F, 0xD5, 0xA3, 0x44, 0x73,
  26255. 0x26, 0x64, 0x01, 0xF6, 0x3B, 0xBD, 0x6B, 0x90,
  26256. 0xE0, 0x03, 0x47, 0x2A, 0xC0, 0xCE, 0x88, 0xF1,
  26257. 0xB6, 0x66, 0x59, 0x72, 0x79, 0xD0, 0x56, 0xA6,
  26258. 0x32, 0xC8, 0xD6, 0xB7, 0x90, 0xFD, 0x41, 0x17,
  26259. 0x67, 0x84, 0x8A, 0x69, 0xE3, 0x7A, 0x8A, 0x83,
  26260. 0x9B, 0xC7, 0x66, 0xA0, 0x2C, 0xA2, 0xF6, 0x95,
  26261. 0xEC, 0x63, 0xF0, 0x56, 0xA4, 0xE2, 0xA1, 0x14,
  26262. 0xCA, 0xCF, 0x9F, 0xD9, 0x0D, 0x73, 0x0C, 0x97,
  26263. 0x0D, 0xB3, 0x87, 0xF6, 0xDE, 0x73, 0x39, 0x5F,
  26264. 0x70, 0x1A, 0x1D, 0x95, 0x3B, 0x2A, 0x89, 0xDD,
  26265. 0x7E, 0xDA, 0xD4, 0x39, 0xFC, 0x20, 0x5A, 0x54,
  26266. 0xA4, 0x81, 0xE8, 0x89, 0xB0, 0x98, 0xD5, 0x25,
  26267. 0x56, 0x70, 0xF0, 0x26, 0xB4, 0xA2, 0xBF, 0x02,
  26268. 0xD2, 0xBD, 0xDE, 0x87, 0xC7, 0x66, 0xB2, 0x5F,
  26269. 0xC5, 0xE0, 0xFD, 0x45, 0x37, 0x57, 0xE7, 0x56,
  26270. 0xD1, 0x8C, 0x8C, 0xD9, 0x12, 0xF9, 0xA7, 0x7F,
  26271. 0x8E, 0x6B, 0xF0, 0x20, 0x53, 0x74, 0xB4, 0x62
  26272. };
  26273. static const byte k_512[KYBER_SS_SZ] = {
  26274. 0x0B, 0xF3, 0x23, 0x33, 0x8D, 0x6F, 0x0A, 0x21,
  26275. 0xD5, 0x51, 0x4B, 0x67, 0x3C, 0xD1, 0x0B, 0x71,
  26276. 0x4C, 0xE6, 0xE3, 0x6F, 0x35, 0xBC, 0xD1, 0xBF,
  26277. 0x54, 0x41, 0x96, 0x36, 0x8E, 0xE5, 0x1A, 0x13
  26278. };
  26279. #endif
  26280. #ifndef WOLFSSL_NO_KYBER768
  26281. static const byte ek_768[KYBER768_PUBLIC_KEY_SIZE] = {
  26282. 0x89, 0xD2, 0xCB, 0x65, 0xF9, 0x4D, 0xCB, 0xFC,
  26283. 0x89, 0x0E, 0xFC, 0x7D, 0x0E, 0x5A, 0x7A, 0x38,
  26284. 0x34, 0x4D, 0x16, 0x41, 0xA3, 0xD0, 0xB0, 0x24,
  26285. 0xD5, 0x07, 0x97, 0xA5, 0xF2, 0x3C, 0x3A, 0x18,
  26286. 0xB3, 0x10, 0x1A, 0x12, 0x69, 0x06, 0x9F, 0x43,
  26287. 0xA8, 0x42, 0xBA, 0xCC, 0x09, 0x8A, 0x88, 0x21,
  26288. 0x27, 0x1C, 0x67, 0x3D, 0xB1, 0xBE, 0xB3, 0x30,
  26289. 0x34, 0xE4, 0xD7, 0x77, 0x4D, 0x16, 0x63, 0x5C,
  26290. 0x7C, 0x2C, 0x3C, 0x27, 0x63, 0x45, 0x35, 0x38,
  26291. 0xBC, 0x16, 0x32, 0xE1, 0x85, 0x15, 0x91, 0xA5,
  26292. 0x16, 0x42, 0x97, 0x4E, 0x59, 0x28, 0xAB, 0xB8,
  26293. 0xE5, 0x5F, 0xE5, 0x56, 0x12, 0xF9, 0xB1, 0x41,
  26294. 0xAF, 0xF0, 0x15, 0x54, 0x53, 0x94, 0xB2, 0x09,
  26295. 0x2E, 0x59, 0x09, 0x70, 0xEC, 0x29, 0xA7, 0xB7,
  26296. 0xE7, 0xAA, 0x1F, 0xB4, 0x49, 0x3B, 0xF7, 0xCB,
  26297. 0x73, 0x19, 0x06, 0xC2, 0xA5, 0xCB, 0x49, 0xE6,
  26298. 0x61, 0x48, 0x59, 0x06, 0x4E, 0x19, 0xB8, 0xFA,
  26299. 0x26, 0xAF, 0x51, 0xC4, 0x4B, 0x5E, 0x75, 0x35,
  26300. 0xBF, 0xDA, 0xC0, 0x72, 0xB6, 0x46, 0xD3, 0xEA,
  26301. 0x49, 0x0D, 0x27, 0x7F, 0x0D, 0x97, 0xCE, 0xD4,
  26302. 0x73, 0x95, 0xFE, 0xD9, 0x1E, 0x8F, 0x2B, 0xCE,
  26303. 0x0E, 0x3C, 0xA1, 0x22, 0xC2, 0x02, 0x5F, 0x74,
  26304. 0x06, 0x7A, 0xB9, 0x28, 0xA8, 0x22, 0xB3, 0x56,
  26305. 0x53, 0xA7, 0x4F, 0x06, 0x75, 0x76, 0x29, 0xAF,
  26306. 0xB1, 0xA1, 0xCA, 0xF2, 0x37, 0x10, 0x0E, 0xA9,
  26307. 0x35, 0xE7, 0x93, 0xC8, 0xF5, 0x8A, 0x71, 0xB3,
  26308. 0xD6, 0xAE, 0x2C, 0x86, 0x58, 0xB1, 0x01, 0x50,
  26309. 0xD4, 0xA3, 0x8F, 0x57, 0x2A, 0x0D, 0x49, 0xD2,
  26310. 0x8A, 0xE8, 0x94, 0x51, 0xD3, 0x38, 0x32, 0x6F,
  26311. 0xDB, 0x3B, 0x43, 0x50, 0x03, 0x6C, 0x10, 0x81,
  26312. 0x11, 0x77, 0x40, 0xED, 0xB8, 0x6B, 0x12, 0x08,
  26313. 0x1C, 0x5C, 0x12, 0x23, 0xDB, 0xB5, 0x66, 0x0D,
  26314. 0x5B, 0x3C, 0xB3, 0x78, 0x7D, 0x48, 0x18, 0x49,
  26315. 0x30, 0x4C, 0x68, 0xBE, 0x87, 0x54, 0x66, 0xF1,
  26316. 0x4E, 0xE5, 0x49, 0x5C, 0x2B, 0xD7, 0x95, 0xAE,
  26317. 0x41, 0x2D, 0x09, 0x00, 0x2D, 0x65, 0xB8, 0x71,
  26318. 0x9B, 0x90, 0xCB, 0xA3, 0x60, 0x3A, 0xC4, 0x95,
  26319. 0x8E, 0xA0, 0x3C, 0xC1, 0x38, 0xC8, 0x6F, 0x78,
  26320. 0x51, 0x59, 0x31, 0x25, 0x33, 0x47, 0x01, 0xB6,
  26321. 0x77, 0xF8, 0x2F, 0x49, 0x52, 0xA4, 0xC9, 0x3B,
  26322. 0x5B, 0x4C, 0x13, 0x4B, 0xB4, 0x2A, 0x85, 0x7F,
  26323. 0xD1, 0x5C, 0x65, 0x08, 0x64, 0xA6, 0xAA, 0x94,
  26324. 0xEB, 0x69, 0x1C, 0x0B, 0x69, 0x1B, 0xE4, 0x68,
  26325. 0x4C, 0x1F, 0x5B, 0x74, 0x90, 0x46, 0x7F, 0xC0,
  26326. 0x1B, 0x1D, 0x1F, 0xDA, 0x4D, 0xDA, 0x35, 0xC4,
  26327. 0xEC, 0xC2, 0x31, 0xBC, 0x73, 0xA6, 0xFE, 0xF4,
  26328. 0x2C, 0x99, 0xD3, 0x4E, 0xB8, 0x2A, 0x4D, 0x01,
  26329. 0x49, 0x87, 0xB3, 0xE3, 0x86, 0x91, 0x0C, 0x62,
  26330. 0x67, 0x9A, 0x11, 0x8F, 0x3C, 0x5B, 0xD9, 0xF4,
  26331. 0x67, 0xE4, 0x16, 0x20, 0x42, 0x42, 0x43, 0x57,
  26332. 0xDB, 0x92, 0xEF, 0x48, 0x4A, 0x4A, 0x17, 0x98,
  26333. 0xC1, 0x25, 0x7E, 0x87, 0x0A, 0x30, 0xCB, 0x20,
  26334. 0xAA, 0xA0, 0x33, 0x5D, 0x83, 0x31, 0x4F, 0xE0,
  26335. 0xAA, 0x7E, 0x63, 0xA8, 0x62, 0x64, 0x80, 0x41,
  26336. 0xA7, 0x2A, 0x63, 0x21, 0x52, 0x32, 0x20, 0xB1,
  26337. 0xAC, 0xE9, 0xBB, 0x70, 0x1B, 0x21, 0xAC, 0x12,
  26338. 0x53, 0xCB, 0x81, 0x2C, 0x15, 0x57, 0x5A, 0x90,
  26339. 0x85, 0xEA, 0xBE, 0xAD, 0xE7, 0x3A, 0x4A, 0xE7,
  26340. 0x6E, 0x6A, 0x7B, 0x15, 0x8A, 0x20, 0x58, 0x6D,
  26341. 0x78, 0xA5, 0xAC, 0x62, 0x0A, 0x5C, 0x9A, 0xBC,
  26342. 0xC9, 0xC0, 0x43, 0x35, 0x0A, 0x73, 0x65, 0x6B,
  26343. 0x0A, 0xBE, 0x82, 0x2D, 0xA5, 0xE0, 0xBA, 0x76,
  26344. 0x04, 0x5F, 0xAD, 0x75, 0x40, 0x1D, 0x7A, 0x3B,
  26345. 0x70, 0x37, 0x91, 0xB7, 0xE9, 0x92, 0x61, 0x71,
  26346. 0x0F, 0x86, 0xB7, 0x24, 0x21, 0xD2, 0x40, 0xA3,
  26347. 0x47, 0x63, 0x83, 0x77, 0x20, 0x5A, 0x15, 0x2C,
  26348. 0x79, 0x41, 0x30, 0xA4, 0xE0, 0x47, 0x74, 0x2B,
  26349. 0x88, 0x83, 0x03, 0xBD, 0xDC, 0x30, 0x91, 0x16,
  26350. 0x76, 0x4D, 0xE7, 0x42, 0x4C, 0xEB, 0xEA, 0x6D,
  26351. 0xB6, 0x53, 0x48, 0xAC, 0x53, 0x7E, 0x01, 0xA9,
  26352. 0xCC, 0x56, 0xEA, 0x66, 0x7D, 0x5A, 0xA8, 0x7A,
  26353. 0xC9, 0xAA, 0xA4, 0x31, 0x7D, 0x26, 0x2C, 0x10,
  26354. 0x14, 0x30, 0x50, 0xB8, 0xD0, 0x7A, 0x72, 0x8C,
  26355. 0xA6, 0x33, 0xC1, 0x3E, 0x46, 0x8A, 0xBC, 0xEA,
  26356. 0xD3, 0x72, 0xC7, 0x7B, 0x8E, 0xCF, 0x3B, 0x98,
  26357. 0x6B, 0x98, 0xC1, 0xE5, 0x58, 0x60, 0xB2, 0xB4,
  26358. 0x21, 0x67, 0x66, 0xAD, 0x87, 0x4C, 0x35, 0xED,
  26359. 0x72, 0x05, 0x06, 0x87, 0x39, 0x23, 0x02, 0x20,
  26360. 0xB5, 0xA2, 0x31, 0x7D, 0x10, 0x2C, 0x59, 0x83,
  26361. 0x56, 0xF1, 0x68, 0xAC, 0xBE, 0x80, 0x60, 0x8D,
  26362. 0xE4, 0xC9, 0xA7, 0x10, 0xB8, 0xDD, 0x07, 0x07,
  26363. 0x8C, 0xD7, 0xC6, 0x71, 0x05, 0x8A, 0xF1, 0xB0,
  26364. 0xB8, 0x30, 0x4A, 0x31, 0x4F, 0x7B, 0x29, 0xBE,
  26365. 0x78, 0xA9, 0x33, 0xC7, 0xB9, 0x29, 0x44, 0x24,
  26366. 0x95, 0x4A, 0x1B, 0xF8, 0xBC, 0x74, 0x5D, 0xE8,
  26367. 0x61, 0x98, 0x65, 0x9E, 0x0E, 0x12, 0x25, 0xA9,
  26368. 0x10, 0x72, 0x60, 0x74, 0x96, 0x9C, 0x39, 0xA9,
  26369. 0x7C, 0x19, 0x24, 0x06, 0x01, 0xA4, 0x6E, 0x01,
  26370. 0x3D, 0xCD, 0xCB, 0x67, 0x7A, 0x8C, 0xBD, 0x2C,
  26371. 0x95, 0xA4, 0x06, 0x29, 0xC2, 0x56, 0xF2, 0x4A,
  26372. 0x32, 0x89, 0x51, 0xDF, 0x57, 0x50, 0x2A, 0xB3,
  26373. 0x07, 0x72, 0xCC, 0x7E, 0x5B, 0x85, 0x00, 0x27,
  26374. 0xC8, 0x55, 0x17, 0x81, 0xCE, 0x49, 0x85, 0xBD,
  26375. 0xAC, 0xF6, 0xB8, 0x65, 0xC1, 0x04, 0xE8, 0xA4,
  26376. 0xBC, 0x65, 0xC4, 0x16, 0x94, 0xD4, 0x56, 0xB7,
  26377. 0x16, 0x9E, 0x45, 0xAB, 0x3D, 0x7A, 0xCA, 0xBE,
  26378. 0xAF, 0xE2, 0x3A, 0xD6, 0xA7, 0xB9, 0x4D, 0x19,
  26379. 0x79, 0xA2, 0xF4, 0xC1, 0xCA, 0xE7, 0xCD, 0x77,
  26380. 0xD6, 0x81, 0xD2, 0x90, 0xB5, 0xD8, 0xE4, 0x51,
  26381. 0xBF, 0xDC, 0xCC, 0xF5, 0x31, 0x0B, 0x9D, 0x12,
  26382. 0xA8, 0x8E, 0xC2, 0x9B, 0x10, 0x25, 0x5D, 0x5E,
  26383. 0x17, 0xA1, 0x92, 0x67, 0x0A, 0xA9, 0x73, 0x1C,
  26384. 0x5C, 0xA6, 0x7E, 0xC7, 0x84, 0xC5, 0x02, 0x78,
  26385. 0x1B, 0xE8, 0x52, 0x7D, 0x6F, 0xC0, 0x03, 0xC6,
  26386. 0x70, 0x1B, 0x36, 0x32, 0x28, 0x4B, 0x40, 0x30,
  26387. 0x7A, 0x52, 0x7C, 0x76, 0x20, 0x37, 0x7F, 0xEB,
  26388. 0x0B, 0x73, 0xF7, 0x22, 0xC9, 0xE3, 0xCD, 0x4D,
  26389. 0xEC, 0x64, 0x87, 0x6B, 0x93, 0xAB, 0x5B, 0x7C,
  26390. 0xFC, 0x4A, 0x65, 0x7F, 0x85, 0x2B, 0x65, 0x92,
  26391. 0x82, 0x86, 0x43, 0x84, 0xF4, 0x42, 0xB2, 0x2E,
  26392. 0x8A, 0x21, 0x10, 0x93, 0x87, 0xB8, 0xB4, 0x75,
  26393. 0x85, 0xFC, 0x68, 0x0D, 0x0B, 0xA4, 0x5C, 0x7A,
  26394. 0x8B, 0x1D, 0x72, 0x74, 0xBD, 0xA5, 0x78, 0x45,
  26395. 0xD1, 0x00, 0xD0, 0xF4, 0x2A, 0x3B, 0x74, 0x62,
  26396. 0x87, 0x73, 0x35, 0x1F, 0xD7, 0xAC, 0x30, 0x5B,
  26397. 0x24, 0x97, 0x63, 0x9B, 0xE9, 0x0B, 0x3F, 0x4F,
  26398. 0x71, 0xA6, 0xAA, 0x35, 0x61, 0xEE, 0xCC, 0x6A,
  26399. 0x69, 0x1B, 0xB5, 0xCB, 0x39, 0x14, 0xD8, 0x63,
  26400. 0x4C, 0xA1, 0xE1, 0xAF, 0x54, 0x3C, 0x04, 0x9A,
  26401. 0x8C, 0x6E, 0x86, 0x8C, 0x51, 0xF0, 0x42, 0x3B,
  26402. 0xD2, 0xD5, 0xAE, 0x09, 0xB7, 0x9E, 0x57, 0xC2,
  26403. 0x7F, 0x3F, 0xE3, 0xAE, 0x2B, 0x26, 0xA4, 0x41,
  26404. 0xBA, 0xBF, 0xC6, 0x71, 0x8C, 0xE8, 0xC0, 0x5B,
  26405. 0x4F, 0xE7, 0x93, 0xB9, 0x10, 0xB8, 0xFB, 0xCB,
  26406. 0xBE, 0x7F, 0x10, 0x13, 0x24, 0x2B, 0x40, 0xE0,
  26407. 0x51, 0x4D, 0x0B, 0xDC, 0x5C, 0x88, 0xBA, 0xC5,
  26408. 0x94, 0xC7, 0x94, 0xCE, 0x51, 0x22, 0xFB, 0xF3,
  26409. 0x48, 0x96, 0x81, 0x91, 0x47, 0xB9, 0x28, 0x38,
  26410. 0x15, 0x87, 0x96, 0x3B, 0x0B, 0x90, 0x03, 0x4A,
  26411. 0xA0, 0x7A, 0x10, 0xBE, 0x17, 0x6E, 0x01, 0xC8,
  26412. 0x0A, 0xD6, 0xA4, 0xB7, 0x1B, 0x10, 0xAF, 0x42,
  26413. 0x41, 0x40, 0x0A, 0x2A, 0x4C, 0xBB, 0xC0, 0x59,
  26414. 0x61, 0xA1, 0x5E, 0xC1, 0x47, 0x4E, 0xD5, 0x1A,
  26415. 0x3C, 0xC6, 0xD3, 0x58, 0x00, 0x67, 0x9A, 0x46,
  26416. 0x28, 0x09, 0xCA, 0xA3, 0xAB, 0x4F, 0x70, 0x94,
  26417. 0xCD, 0x66, 0x10, 0xB4, 0xA7, 0x00, 0xCB, 0xA9,
  26418. 0x39, 0xE7, 0xEA, 0xC9, 0x3E, 0x38, 0xC9, 0x97,
  26419. 0x55, 0x90, 0x87, 0x27, 0x61, 0x9E, 0xD7, 0x6A,
  26420. 0x34, 0xE5, 0x3C, 0x4F, 0xA2, 0x5B, 0xFC, 0x97,
  26421. 0x00, 0x82, 0x06, 0x69, 0x7D, 0xD1, 0x45, 0xE5,
  26422. 0xB9, 0x18, 0x8E, 0x5B, 0x01, 0x4E, 0x94, 0x16,
  26423. 0x81, 0xE1, 0x5F, 0xE3, 0xE1, 0x32, 0xB8, 0xA3,
  26424. 0x90, 0x34, 0x74, 0x14, 0x8B, 0xA2, 0x8B, 0x98,
  26425. 0x71, 0x11, 0xC9, 0xBC, 0xB3, 0x98, 0x9B, 0xBB,
  26426. 0xC6, 0x71, 0xC5, 0x81, 0xB4, 0x4A, 0x49, 0x28,
  26427. 0x45, 0xF2, 0x88, 0xE6, 0x21, 0x96, 0xE4, 0x71,
  26428. 0xFE, 0xD3, 0xC3, 0x9C, 0x1B, 0xBD, 0xDB, 0x08,
  26429. 0x37, 0xD0, 0xD4, 0x70, 0x6B, 0x09, 0x22, 0xC4
  26430. };
  26431. static const byte seed_768[KYBER_ENC_RAND_SZ] = {
  26432. 0x2C, 0xE7, 0x4A, 0xD2, 0x91, 0x13, 0x35, 0x18,
  26433. 0xFE, 0x60, 0xC7, 0xDF, 0x5D, 0x25, 0x1B, 0x9D,
  26434. 0x82, 0xAD, 0xD4, 0x84, 0x62, 0xFF, 0x50, 0x5C,
  26435. 0x6E, 0x54, 0x7E, 0x94, 0x9E, 0x6B, 0x6B, 0xF7
  26436. };
  26437. static const byte c_768[KYBER768_CIPHER_TEXT_SIZE] = {
  26438. 0x56, 0xB4, 0x2D, 0x59, 0x3A, 0xAB, 0x8E, 0x87,
  26439. 0x73, 0xBD, 0x92, 0xD7, 0x6E, 0xAB, 0xDD, 0xF3,
  26440. 0xB1, 0x54, 0x6F, 0x83, 0x26, 0xF5, 0x7A, 0x7B,
  26441. 0x77, 0x37, 0x64, 0xB6, 0xC0, 0xDD, 0x30, 0x47,
  26442. 0x0F, 0x68, 0xDF, 0xF8, 0x2E, 0x0D, 0xCA, 0x92,
  26443. 0x50, 0x92, 0x74, 0xEC, 0xFE, 0x83, 0xA9, 0x54,
  26444. 0x73, 0x5F, 0xDE, 0x6E, 0x14, 0x67, 0x6D, 0xAA,
  26445. 0xA3, 0x68, 0x0C, 0x30, 0xD5, 0x24, 0xF4, 0xEF,
  26446. 0xA7, 0x9E, 0xD6, 0xA1, 0xF9, 0xED, 0x7E, 0x1C,
  26447. 0x00, 0x56, 0x0E, 0x86, 0x83, 0x53, 0x8C, 0x31,
  26448. 0x05, 0xAB, 0x93, 0x1B, 0xE0, 0xD2, 0xB2, 0x49,
  26449. 0xB3, 0x8C, 0xB9, 0xB1, 0x3A, 0xF5, 0xCE, 0xAF,
  26450. 0x78, 0x87, 0xA5, 0x9D, 0xBA, 0x16, 0x68, 0x8A,
  26451. 0x7F, 0x28, 0xDE, 0x0B, 0x14, 0xD1, 0x9F, 0x39,
  26452. 0x1E, 0xB4, 0x18, 0x32, 0xA5, 0x64, 0x79, 0x41,
  26453. 0x6C, 0xCF, 0x94, 0xE9, 0x97, 0x39, 0x0E, 0xD7,
  26454. 0x87, 0x8E, 0xEA, 0xFF, 0x49, 0x32, 0x8A, 0x70,
  26455. 0xE0, 0xAB, 0x5F, 0xCE, 0x6C, 0x63, 0xC0, 0x9B,
  26456. 0x35, 0xF4, 0xE4, 0x59, 0x94, 0xDE, 0x61, 0x5B,
  26457. 0x88, 0xBB, 0x72, 0x2F, 0x70, 0xE8, 0x7D, 0x2B,
  26458. 0xBD, 0x72, 0xAE, 0x71, 0xE1, 0xEE, 0x90, 0x08,
  26459. 0xE4, 0x59, 0xD8, 0xE7, 0x43, 0x03, 0x9A, 0x8D,
  26460. 0xDE, 0xB8, 0x74, 0xFC, 0xE5, 0x30, 0x1A, 0x2F,
  26461. 0x8C, 0x0E, 0xE8, 0xC2, 0xFE, 0xE7, 0xA4, 0xEE,
  26462. 0x68, 0xB5, 0xED, 0x6A, 0x6D, 0x9A, 0xB7, 0x4F,
  26463. 0x98, 0xBB, 0x3B, 0xA0, 0xFE, 0x89, 0xE8, 0x2B,
  26464. 0xD5, 0xA5, 0x25, 0xC5, 0xE8, 0x79, 0x0F, 0x81,
  26465. 0x8C, 0xCC, 0x60, 0x58, 0x77, 0xD4, 0x6C, 0x8B,
  26466. 0xDB, 0x5C, 0x33, 0x7B, 0x02, 0x5B, 0xB8, 0x40,
  26467. 0xFF, 0x47, 0x18, 0x96, 0xE4, 0x3B, 0xFA, 0x99,
  26468. 0xD7, 0x3D, 0xBE, 0x31, 0x80, 0x5C, 0x27, 0xA4,
  26469. 0x3E, 0x57, 0xF0, 0x61, 0x8B, 0x3A, 0xE5, 0x22,
  26470. 0xA4, 0x64, 0x4E, 0x0D, 0x4E, 0x4C, 0x1C, 0x54,
  26471. 0x84, 0x89, 0x43, 0x1B, 0xE5, 0x58, 0xF3, 0xBF,
  26472. 0xC5, 0x0E, 0x16, 0x61, 0x7E, 0x11, 0x0D, 0xD7,
  26473. 0xAF, 0x9A, 0x6F, 0xD8, 0x3E, 0x3F, 0xBB, 0x68,
  26474. 0xC3, 0x04, 0xD1, 0x5F, 0x6C, 0xB7, 0x00, 0xD6,
  26475. 0x1D, 0x7A, 0xA9, 0x15, 0xA6, 0x75, 0x1E, 0xA3,
  26476. 0xBA, 0x80, 0x22, 0x3E, 0x65, 0x41, 0x32, 0xA2,
  26477. 0x09, 0x99, 0xA4, 0x3B, 0xF4, 0x08, 0x59, 0x27,
  26478. 0x30, 0xB9, 0xA9, 0x49, 0x96, 0x36, 0xC0, 0x9F,
  26479. 0xA7, 0x29, 0xF9, 0xCB, 0x1F, 0x9D, 0x34, 0x42,
  26480. 0xF4, 0x73, 0x57, 0xA2, 0xB9, 0xCF, 0x15, 0xD3,
  26481. 0x10, 0x3B, 0x9B, 0xF3, 0x96, 0xC2, 0x30, 0x88,
  26482. 0xF1, 0x18, 0xED, 0xE3, 0x46, 0xB5, 0xC0, 0x38,
  26483. 0x91, 0xCF, 0xA5, 0xD5, 0x17, 0xCE, 0xF8, 0x47,
  26484. 0x13, 0x22, 0xE7, 0xE3, 0x10, 0x87, 0xC4, 0xB0,
  26485. 0x36, 0xAB, 0xAD, 0x78, 0x4B, 0xFF, 0x72, 0xA9,
  26486. 0xB1, 0x1F, 0xA1, 0x98, 0xFA, 0xCB, 0xCB, 0x91,
  26487. 0xF0, 0x67, 0xFE, 0xAF, 0x76, 0xFC, 0xFE, 0x53,
  26488. 0x27, 0xC1, 0x07, 0x0B, 0x3D, 0xA6, 0x98, 0x84,
  26489. 0x00, 0x75, 0x67, 0x60, 0xD2, 0xD1, 0xF0, 0x60,
  26490. 0x29, 0x8F, 0x16, 0x83, 0xD5, 0x1E, 0x36, 0x16,
  26491. 0xE9, 0x8C, 0x51, 0xC9, 0xC0, 0x3A, 0xA4, 0x2F,
  26492. 0x2E, 0x63, 0x36, 0x51, 0xA4, 0x7A, 0xD3, 0xCC,
  26493. 0x2A, 0xB4, 0xA8, 0x52, 0xAE, 0x0C, 0x4B, 0x04,
  26494. 0xB4, 0xE1, 0xC3, 0xDD, 0x94, 0x44, 0x45, 0xA2,
  26495. 0xB1, 0x2B, 0x4F, 0x42, 0xA6, 0x43, 0x51, 0x05,
  26496. 0xC0, 0x41, 0x22, 0xFC, 0x35, 0x87, 0xAF, 0xE4,
  26497. 0x09, 0xA0, 0x0B, 0x30, 0x8D, 0x63, 0xC5, 0xDD,
  26498. 0x81, 0x63, 0x65, 0x45, 0x04, 0xEE, 0xDB, 0xB7,
  26499. 0xB5, 0x32, 0x95, 0x77, 0xC3, 0x5F, 0xBE, 0xB3,
  26500. 0xF4, 0x63, 0x87, 0x2C, 0xAC, 0x28, 0x14, 0x2B,
  26501. 0x3C, 0x12, 0xA7, 0x40, 0xEC, 0x6E, 0xA7, 0xCE,
  26502. 0x9A, 0xD7, 0x8C, 0x6F, 0xC8, 0xFE, 0x1B, 0x4D,
  26503. 0xF5, 0xFC, 0x55, 0xC1, 0x66, 0x7F, 0x31, 0xF2,
  26504. 0x31, 0x2D, 0xA0, 0x77, 0x99, 0xDC, 0x87, 0x0A,
  26505. 0x47, 0x86, 0x08, 0x54, 0x9F, 0xED, 0xAF, 0xE0,
  26506. 0x21, 0xF1, 0xCF, 0x29, 0x84, 0x18, 0x03, 0x64,
  26507. 0xE9, 0x0A, 0xD9, 0x8D, 0x84, 0x56, 0x52, 0xAA,
  26508. 0x3C, 0xDD, 0x7A, 0x8E, 0xB0, 0x9F, 0x5E, 0x51,
  26509. 0x42, 0x3F, 0xAB, 0x42, 0xA7, 0xB7, 0xBB, 0x4D,
  26510. 0x51, 0x48, 0x64, 0xBE, 0x8D, 0x71, 0x29, 0x7E,
  26511. 0x9C, 0x3B, 0x17, 0xA9, 0x93, 0xF0, 0xAE, 0x62,
  26512. 0xE8, 0xEF, 0x52, 0x63, 0x7B, 0xD1, 0xB8, 0x85,
  26513. 0xBD, 0x9B, 0x6A, 0xB7, 0x27, 0x85, 0x4D, 0x70,
  26514. 0x3D, 0x8D, 0xC4, 0x78, 0xF9, 0x6C, 0xB8, 0x1F,
  26515. 0xCE, 0x4C, 0x60, 0x38, 0x3A, 0xC0, 0x1F, 0xCF,
  26516. 0x0F, 0x97, 0x1D, 0x4C, 0x8F, 0x35, 0x2B, 0x7A,
  26517. 0x82, 0xE2, 0x18, 0x65, 0x2F, 0x2C, 0x10, 0x6C,
  26518. 0xA9, 0x2A, 0xE6, 0x86, 0xBA, 0xCF, 0xCE, 0xF5,
  26519. 0xD3, 0x27, 0x34, 0x7A, 0x97, 0xA9, 0xB3, 0x75,
  26520. 0xD6, 0x73, 0x41, 0x55, 0x2B, 0xC2, 0xC5, 0x38,
  26521. 0x77, 0x8E, 0x0F, 0x98, 0x01, 0x82, 0x3C, 0xCD,
  26522. 0xFC, 0xD1, 0xEA, 0xAD, 0xED, 0x55, 0xB1, 0x8C,
  26523. 0x97, 0x57, 0xE3, 0xF2, 0x12, 0xB2, 0x88, 0x9D,
  26524. 0x38, 0x57, 0xDB, 0x51, 0xF9, 0x81, 0xD1, 0x61,
  26525. 0x85, 0xFD, 0x0F, 0x90, 0x08, 0x53, 0xA7, 0x50,
  26526. 0x05, 0xE3, 0x02, 0x0A, 0x8B, 0x95, 0xB7, 0xD8,
  26527. 0xF2, 0xF2, 0x63, 0x1C, 0x70, 0xD7, 0x8A, 0x95,
  26528. 0x7C, 0x7A, 0x62, 0xE1, 0xB3, 0x71, 0x90, 0x70,
  26529. 0xAC, 0xD1, 0xFD, 0x48, 0x0C, 0x25, 0xB8, 0x38,
  26530. 0x47, 0xDA, 0x02, 0x7B, 0x6E, 0xBB, 0xC2, 0xEE,
  26531. 0xC2, 0xDF, 0x22, 0xC8, 0x7F, 0x9B, 0x46, 0xD5,
  26532. 0xD7, 0xBA, 0xF1, 0x56, 0xB5, 0x3C, 0xEE, 0x92,
  26533. 0x95, 0x72, 0xB9, 0x2C, 0x47, 0x84, 0xC4, 0xE8,
  26534. 0x29, 0xF3, 0x44, 0x6A, 0x1F, 0xFE, 0x47, 0xF9,
  26535. 0x9D, 0xEC, 0xD0, 0x43, 0x60, 0x29, 0xDD, 0xEB,
  26536. 0xD3, 0xED, 0x8E, 0x87, 0xE5, 0xE7, 0x3D, 0x12,
  26537. 0x3D, 0xBE, 0x8A, 0x4D, 0xDA, 0xCF, 0x2A, 0xBD,
  26538. 0xE8, 0x7F, 0x33, 0xAE, 0x2B, 0x62, 0x1C, 0x0E,
  26539. 0xC5, 0xD5, 0xCA, 0xD1, 0x25, 0x9D, 0xEE, 0xC2,
  26540. 0xAE, 0xFF, 0x60, 0x88, 0xF0, 0x4F, 0x27, 0xA2,
  26541. 0x03, 0x38, 0xB5, 0x76, 0x25, 0x43, 0xE5, 0x10,
  26542. 0x08, 0x99, 0xA4, 0xCB, 0xFB, 0x7B, 0x3C, 0xA4,
  26543. 0x56, 0xB3, 0xA1, 0x9B, 0x83, 0xA4, 0xC4, 0x32,
  26544. 0x23, 0x0C, 0x23, 0xE1, 0xC7, 0xF1, 0x07, 0xC4,
  26545. 0xCB, 0x11, 0x21, 0x52, 0xF1, 0xC0, 0xF3, 0x0D,
  26546. 0xA0, 0xBB, 0x33, 0xF4, 0xF1, 0x1F, 0x47, 0xEE,
  26547. 0xA4, 0x38, 0x72, 0xBA, 0xFA, 0x84, 0xAE, 0x22,
  26548. 0x25, 0x6D, 0x70, 0x8E, 0x06, 0x04, 0xDA, 0xDE,
  26549. 0x4B, 0x2A, 0x4D, 0xDE, 0x8C, 0xCC, 0xF1, 0x19,
  26550. 0x30, 0xE1, 0x35, 0x53, 0x93, 0x4A, 0xE3, 0xEC,
  26551. 0xE5, 0x2F, 0x3D, 0x7C, 0xCC, 0x00, 0x28, 0x73,
  26552. 0x77, 0x87, 0x9F, 0xE6, 0xB8, 0xEC, 0xE7, 0xEF,
  26553. 0x79, 0x42, 0x35, 0x07, 0xC9, 0xDA, 0x33, 0x95,
  26554. 0x59, 0xC2, 0x0D, 0xE1, 0xC5, 0x19, 0x55, 0x99,
  26555. 0x9B, 0xAE, 0x47, 0x40, 0x1D, 0xC3, 0xCD, 0xFA,
  26556. 0xA1, 0xB2, 0x56, 0xD0, 0x9C, 0x7D, 0xB9, 0xFC,
  26557. 0x86, 0x98, 0xBF, 0xCE, 0xFA, 0x73, 0x02, 0xD5,
  26558. 0x6F, 0xBC, 0xDE, 0x1F, 0xBA, 0xAA, 0x1C, 0x65,
  26559. 0x34, 0x54, 0xE6, 0xFD, 0x3D, 0x84, 0xE4, 0xF7,
  26560. 0x9A, 0x93, 0x1C, 0x68, 0x1C, 0xBB, 0x6C, 0xB4,
  26561. 0x62, 0xB1, 0x0D, 0xAE, 0x11, 0x2B, 0xDF, 0xB7,
  26562. 0xF6, 0x5C, 0x7F, 0xDF, 0x6E, 0x5F, 0xC5, 0x94,
  26563. 0xEC, 0x3A, 0x47, 0x4A, 0x94, 0xBD, 0x97, 0xE6,
  26564. 0xEC, 0x81, 0xF7, 0x1C, 0x23, 0x0B, 0xF7, 0x0C,
  26565. 0xA0, 0xF1, 0x3C, 0xE3, 0xDF, 0xFB, 0xD9, 0xFF,
  26566. 0x98, 0x04, 0xEF, 0xD8, 0xF3, 0x7A, 0x4D, 0x36,
  26567. 0x29, 0xB4, 0x3A, 0x8F, 0x55, 0x54, 0x4E, 0xBC,
  26568. 0x5A, 0xC0, 0xAB, 0xD9, 0xA3, 0x3D, 0x79, 0x69,
  26569. 0x90, 0x68, 0x34, 0x6A, 0x0F, 0x1A, 0x3A, 0x96,
  26570. 0xE1, 0x15, 0xA5, 0xD8, 0x0B, 0xE1, 0x65, 0xB5,
  26571. 0x62, 0xD0, 0x82, 0x98, 0x4D, 0x5A, 0xAC, 0xC3,
  26572. 0xA2, 0x30, 0x19, 0x81, 0xA6, 0x41, 0x8F, 0x8B,
  26573. 0xA7, 0xD7, 0xB0, 0xD7, 0xCA, 0x58, 0x75, 0xC6
  26574. };
  26575. static const byte k_768[KYBER_SS_SZ] = {
  26576. 0x26, 0x96, 0xD2, 0x8E, 0x9C, 0x61, 0xC2, 0xA0,
  26577. 0x1C, 0xE9, 0xB1, 0x60, 0x8D, 0xCB, 0x9D, 0x29,
  26578. 0x27, 0x85, 0xA0, 0xCD, 0x58, 0xEF, 0xB7, 0xFE,
  26579. 0x13, 0xB1, 0xDE, 0x95, 0xF0, 0xDB, 0x55, 0xB3
  26580. };
  26581. #endif
  26582. #ifndef WOLFSSL_NO_KYBER1024
  26583. static const byte ek_1024[KYBER1024_PUBLIC_KEY_SIZE] = {
  26584. 0x30, 0x7A, 0x4C, 0xEA, 0x41, 0x48, 0x21, 0x9B,
  26585. 0x95, 0x8E, 0xA0, 0xB7, 0x88, 0x66, 0x59, 0x23,
  26586. 0x5A, 0x4D, 0x19, 0x80, 0xB1, 0x92, 0x61, 0x08,
  26587. 0x47, 0xD8, 0x6E, 0xF3, 0x27, 0x39, 0xF9, 0x4C,
  26588. 0x3B, 0x44, 0x6C, 0x4D, 0x81, 0xD8, 0x9B, 0x8B,
  26589. 0x42, 0x2A, 0x9D, 0x07, 0x9C, 0x88, 0xB1, 0x1A,
  26590. 0xCA, 0xF3, 0x21, 0xB0, 0x14, 0x29, 0x4E, 0x18,
  26591. 0xB2, 0x96, 0xE5, 0x2F, 0x3F, 0x74, 0x4C, 0xF9,
  26592. 0x63, 0x4A, 0x4F, 0xB0, 0x1D, 0xB0, 0xD9, 0x9E,
  26593. 0xF2, 0x0A, 0x63, 0x3A, 0x55, 0x2E, 0x76, 0xA0,
  26594. 0x58, 0x5C, 0x61, 0x09, 0xF0, 0x18, 0x76, 0x8B,
  26595. 0x76, 0x3A, 0xF3, 0x67, 0x8B, 0x47, 0x80, 0x08,
  26596. 0x9C, 0x13, 0x42, 0xB9, 0x69, 0x07, 0xA2, 0x9A,
  26597. 0x1C, 0x11, 0x52, 0x1C, 0x74, 0x4C, 0x27, 0x97,
  26598. 0xD0, 0xBF, 0x2B, 0x9C, 0xCD, 0xCA, 0x61, 0x46,
  26599. 0x72, 0xB4, 0x50, 0x76, 0x77, 0x3F, 0x45, 0x8A,
  26600. 0x31, 0xEF, 0x86, 0x9B, 0xE1, 0xEB, 0x2E, 0xFE,
  26601. 0xB5, 0x0D, 0x0E, 0x37, 0x49, 0x5D, 0xC5, 0xCA,
  26602. 0x55, 0xE0, 0x75, 0x28, 0x93, 0x4F, 0x62, 0x93,
  26603. 0xC4, 0x16, 0x80, 0x27, 0xD0, 0xE5, 0x3D, 0x07,
  26604. 0xFA, 0xCC, 0x66, 0x30, 0xCB, 0x08, 0x19, 0x7E,
  26605. 0x53, 0xFB, 0x19, 0x3A, 0x17, 0x11, 0x35, 0xDC,
  26606. 0x8A, 0xD9, 0x97, 0x94, 0x02, 0xA7, 0x1B, 0x69,
  26607. 0x26, 0xBC, 0xDC, 0xDC, 0x47, 0xB9, 0x34, 0x01,
  26608. 0x91, 0x0A, 0x5F, 0xCC, 0x1A, 0x81, 0x3B, 0x68,
  26609. 0x2B, 0x09, 0xBA, 0x7A, 0x72, 0xD2, 0x48, 0x6D,
  26610. 0x6C, 0x79, 0x95, 0x16, 0x46, 0x5C, 0x14, 0x72,
  26611. 0x9B, 0x26, 0x94, 0x9B, 0x0B, 0x7C, 0xBC, 0x7C,
  26612. 0x64, 0x0F, 0x26, 0x7F, 0xED, 0x80, 0xB1, 0x62,
  26613. 0xC5, 0x1F, 0xD8, 0xE0, 0x92, 0x27, 0xC1, 0x01,
  26614. 0xD5, 0x05, 0xA8, 0xFA, 0xE8, 0xA2, 0xD7, 0x05,
  26615. 0x4E, 0x28, 0xA7, 0x8B, 0xA8, 0x75, 0x0D, 0xEC,
  26616. 0xF9, 0x05, 0x7C, 0x83, 0x97, 0x9F, 0x7A, 0xBB,
  26617. 0x08, 0x49, 0x45, 0x64, 0x80, 0x06, 0xC5, 0xB2,
  26618. 0x88, 0x04, 0xF3, 0x4E, 0x73, 0xB2, 0x38, 0x11,
  26619. 0x1A, 0x65, 0xA1, 0xF5, 0x00, 0xB1, 0xCC, 0x60,
  26620. 0x6A, 0x84, 0x8F, 0x28, 0x59, 0x07, 0x0B, 0xEB,
  26621. 0xA7, 0x57, 0x31, 0x79, 0xF3, 0x61, 0x49, 0xCF,
  26622. 0x58, 0x01, 0xBF, 0x89, 0xA1, 0xC3, 0x8C, 0xC2,
  26623. 0x78, 0x41, 0x55, 0x28, 0xD0, 0x3B, 0xDB, 0x94,
  26624. 0x3F, 0x96, 0x28, 0x0C, 0x8C, 0xC5, 0x20, 0x42,
  26625. 0xD9, 0xB9, 0x1F, 0xAA, 0x9D, 0x6E, 0xA7, 0xBC,
  26626. 0xBB, 0x7A, 0xB1, 0x89, 0x7A, 0x32, 0x66, 0x96,
  26627. 0x6F, 0x78, 0x39, 0x34, 0x26, 0xC7, 0x6D, 0x8A,
  26628. 0x49, 0x57, 0x8B, 0x98, 0xB1, 0x59, 0xEB, 0xB4,
  26629. 0x6E, 0xE0, 0xA8, 0x83, 0xA2, 0x70, 0xD8, 0x05,
  26630. 0x7C, 0xD0, 0x23, 0x1C, 0x86, 0x90, 0x6A, 0x91,
  26631. 0xDB, 0xBA, 0xDE, 0x6B, 0x24, 0x69, 0x58, 0x1E,
  26632. 0x2B, 0xCA, 0x2F, 0xEA, 0x83, 0x89, 0xF7, 0xC7,
  26633. 0x4B, 0xCD, 0x70, 0x96, 0x1E, 0xA5, 0xB9, 0x34,
  26634. 0xFB, 0xCF, 0x9A, 0x65, 0x90, 0xBF, 0x86, 0xB8,
  26635. 0xDB, 0x54, 0x88, 0x54, 0xD9, 0xA3, 0xFB, 0x30,
  26636. 0x11, 0x04, 0x33, 0xBD, 0x7A, 0x1B, 0x65, 0x9C,
  26637. 0xA8, 0x56, 0x80, 0x85, 0x63, 0x92, 0x37, 0xB3,
  26638. 0xBD, 0xC3, 0x7B, 0x7F, 0xA7, 0x16, 0xD4, 0x82,
  26639. 0xA2, 0x5B, 0x54, 0x10, 0x6B, 0x3A, 0x8F, 0x54,
  26640. 0xD3, 0xAA, 0x99, 0xB5, 0x12, 0x3D, 0xA9, 0x60,
  26641. 0x66, 0x90, 0x45, 0x92, 0xF3, 0xA5, 0x4E, 0xE2,
  26642. 0x3A, 0x79, 0x81, 0xAB, 0x60, 0x8A, 0x2F, 0x44,
  26643. 0x13, 0xCC, 0x65, 0x89, 0x46, 0xC6, 0xD7, 0x78,
  26644. 0x0E, 0xA7, 0x65, 0x64, 0x4B, 0x3C, 0xC0, 0x6C,
  26645. 0x70, 0x03, 0x4A, 0xB4, 0xEB, 0x35, 0x19, 0x12,
  26646. 0xE7, 0x71, 0x5B, 0x56, 0x75, 0x5D, 0x09, 0x02,
  26647. 0x15, 0x71, 0xBF, 0x34, 0x0A, 0xB9, 0x25, 0x98,
  26648. 0xA2, 0x4E, 0x81, 0x18, 0x93, 0x19, 0x5B, 0x96,
  26649. 0xA1, 0x62, 0x9F, 0x80, 0x41, 0xF5, 0x86, 0x58,
  26650. 0x43, 0x15, 0x61, 0xFC, 0x0A, 0xB1, 0x52, 0x92,
  26651. 0xB9, 0x13, 0xEC, 0x47, 0x3F, 0x04, 0x47, 0x9B,
  26652. 0xC1, 0x45, 0xCD, 0x4C, 0x56, 0x3A, 0x28, 0x62,
  26653. 0x35, 0x64, 0x6C, 0xD3, 0x05, 0xA9, 0xBE, 0x10,
  26654. 0x14, 0xE2, 0xC7, 0xB1, 0x30, 0xC3, 0x3E, 0xB7,
  26655. 0x7C, 0xC4, 0xA0, 0xD9, 0x78, 0x6B, 0xD6, 0xBC,
  26656. 0x2A, 0x95, 0x4B, 0xF3, 0x00, 0x57, 0x78, 0xF8,
  26657. 0x91, 0x7C, 0xE1, 0x37, 0x89, 0xBB, 0xB9, 0x62,
  26658. 0x80, 0x78, 0x58, 0xB6, 0x77, 0x31, 0x57, 0x2B,
  26659. 0x6D, 0x3C, 0x9B, 0x4B, 0x52, 0x06, 0xFA, 0xC9,
  26660. 0xA7, 0xC8, 0x96, 0x16, 0x98, 0xD8, 0x83, 0x24,
  26661. 0xA9, 0x15, 0x18, 0x68, 0x99, 0xB2, 0x99, 0x23,
  26662. 0xF0, 0x84, 0x42, 0xA3, 0xD3, 0x86, 0xBD, 0x41,
  26663. 0x6B, 0xCC, 0x9A, 0x10, 0x01, 0x64, 0xC9, 0x30,
  26664. 0xEC, 0x35, 0xEA, 0xFB, 0x6A, 0xB3, 0x58, 0x51,
  26665. 0xB6, 0xC8, 0xCE, 0x63, 0x77, 0x36, 0x6A, 0x17,
  26666. 0x5F, 0x3D, 0x75, 0x29, 0x8C, 0x51, 0x8D, 0x44,
  26667. 0x89, 0x89, 0x33, 0xF5, 0x3D, 0xEE, 0x61, 0x71,
  26668. 0x45, 0x09, 0x33, 0x79, 0xC4, 0x65, 0x9F, 0x68,
  26669. 0x58, 0x3B, 0x2B, 0x28, 0x12, 0x26, 0x66, 0xBE,
  26670. 0xC5, 0x78, 0x38, 0x99, 0x1F, 0xF1, 0x6C, 0x36,
  26671. 0x8D, 0xD2, 0x2C, 0x36, 0xE7, 0x80, 0xC9, 0x1A,
  26672. 0x35, 0x82, 0xE2, 0x5E, 0x19, 0x79, 0x4C, 0x6B,
  26673. 0xF2, 0xAB, 0x42, 0x45, 0x8A, 0x8D, 0xD7, 0x70,
  26674. 0x5D, 0xE2, 0xC2, 0xAA, 0x20, 0xC0, 0x54, 0xE8,
  26675. 0x4B, 0x3E, 0xF3, 0x50, 0x32, 0x79, 0x86, 0x26,
  26676. 0xC2, 0x48, 0x26, 0x32, 0x53, 0xA7, 0x1A, 0x11,
  26677. 0x94, 0x35, 0x71, 0x34, 0x0A, 0x97, 0x8C, 0xD0,
  26678. 0xA6, 0x02, 0xE4, 0x7D, 0xEE, 0x54, 0x0A, 0x88,
  26679. 0x14, 0xBA, 0x06, 0xF3, 0x14, 0x14, 0x79, 0x7C,
  26680. 0xDF, 0x60, 0x49, 0x58, 0x23, 0x61, 0xBB, 0xAB,
  26681. 0xA3, 0x87, 0xA8, 0x3D, 0x89, 0x91, 0x3F, 0xE4,
  26682. 0xC0, 0xC1, 0x12, 0xB9, 0x56, 0x21, 0xA4, 0xBD,
  26683. 0xA8, 0x12, 0x3A, 0x14, 0xD1, 0xA8, 0x42, 0xFB,
  26684. 0x57, 0xB8, 0x3A, 0x4F, 0xBA, 0xF3, 0x3A, 0x8E,
  26685. 0x55, 0x22, 0x38, 0xA5, 0x96, 0xAA, 0xE7, 0xA1,
  26686. 0x50, 0xD7, 0x5D, 0xA6, 0x48, 0xBC, 0x44, 0x64,
  26687. 0x49, 0x77, 0xBA, 0x1F, 0x87, 0xA4, 0xC6, 0x8A,
  26688. 0x8C, 0x4B, 0xD2, 0x45, 0xB7, 0xD0, 0x07, 0x21,
  26689. 0xF7, 0xD6, 0x4E, 0x82, 0x2B, 0x08, 0x5B, 0x90,
  26690. 0x13, 0x12, 0xEC, 0x37, 0xA8, 0x16, 0x98, 0x02,
  26691. 0x16, 0x0C, 0xCE, 0x11, 0x60, 0xF0, 0x10, 0xBE,
  26692. 0x8C, 0xBC, 0xAC, 0xE8, 0xE7, 0xB0, 0x05, 0xD7,
  26693. 0x83, 0x92, 0x34, 0xA7, 0x07, 0x86, 0x83, 0x09,
  26694. 0xD0, 0x37, 0x84, 0xB4, 0x27, 0x3B, 0x1C, 0x8A,
  26695. 0x16, 0x01, 0x33, 0xED, 0x29, 0x81, 0x84, 0x70,
  26696. 0x46, 0x25, 0xF2, 0x9C, 0xFA, 0x08, 0x6D, 0x13,
  26697. 0x26, 0x3E, 0xE5, 0x89, 0x91, 0x23, 0xC5, 0x96,
  26698. 0xBA, 0x78, 0x8E, 0x5C, 0x54, 0xA8, 0xE9, 0xBA,
  26699. 0x82, 0x9B, 0x8A, 0x9D, 0x90, 0x4B, 0xC4, 0xBC,
  26700. 0x0B, 0xBE, 0xA7, 0x6B, 0xC5, 0x3F, 0xF8, 0x11,
  26701. 0x21, 0x45, 0x98, 0x47, 0x2C, 0x9C, 0x20, 0x2B,
  26702. 0x73, 0xEF, 0xF0, 0x35, 0xDC, 0x09, 0x70, 0x3A,
  26703. 0xF7, 0xBF, 0x1B, 0xAB, 0xAA, 0xC7, 0x31, 0x93,
  26704. 0xCB, 0x46, 0x11, 0x7A, 0x7C, 0x94, 0x92, 0xA4,
  26705. 0x3F, 0xC9, 0x57, 0x89, 0xA9, 0x24, 0xC5, 0x91,
  26706. 0x27, 0x87, 0xB2, 0xE2, 0x09, 0x0E, 0xBB, 0xCF,
  26707. 0xD3, 0x79, 0x62, 0x21, 0xF0, 0x6D, 0xEB, 0xF9,
  26708. 0xCF, 0x70, 0xE0, 0x56, 0xB8, 0xB9, 0x16, 0x1D,
  26709. 0x63, 0x47, 0xF4, 0x73, 0x35, 0xF3, 0xE1, 0x77,
  26710. 0x6D, 0xA4, 0xBB, 0x87, 0xC1, 0x5C, 0xC8, 0x26,
  26711. 0x14, 0x6F, 0xF0, 0x24, 0x9A, 0x41, 0x3B, 0x45,
  26712. 0xAA, 0x93, 0xA8, 0x05, 0x19, 0x6E, 0xA4, 0x53,
  26713. 0x11, 0x4B, 0x52, 0x4E, 0x31, 0x0A, 0xED, 0xAA,
  26714. 0x46, 0xE3, 0xB9, 0x96, 0x42, 0x36, 0x87, 0x82,
  26715. 0x56, 0x6D, 0x04, 0x9A, 0x72, 0x6D, 0x6C, 0xCA,
  26716. 0x91, 0x09, 0x93, 0xAE, 0xD6, 0x21, 0xD0, 0x14,
  26717. 0x9E, 0xA5, 0x88, 0xA9, 0xAB, 0xD9, 0x09, 0xDB,
  26718. 0xB6, 0x9A, 0xA2, 0x28, 0x29, 0xD9, 0xB8, 0x3A,
  26719. 0xDA, 0x22, 0x09, 0xA6, 0xC2, 0x65, 0x9F, 0x21,
  26720. 0x69, 0xD6, 0x68, 0xB9, 0x31, 0x48, 0x42, 0xC6,
  26721. 0xE2, 0x2A, 0x74, 0x95, 0x8B, 0x4C, 0x25, 0xBB,
  26722. 0xDC, 0xD2, 0x93, 0xD9, 0x9C, 0xB6, 0x09, 0xD8,
  26723. 0x66, 0x74, 0x9A, 0x48, 0x5D, 0xFB, 0x56, 0x02,
  26724. 0x48, 0x83, 0xCF, 0x54, 0x65, 0xDB, 0xA0, 0x36,
  26725. 0x32, 0x06, 0x58, 0x7F, 0x45, 0x59, 0x7F, 0x89,
  26726. 0x00, 0x2F, 0xB8, 0x60, 0x72, 0x32, 0x13, 0x8E,
  26727. 0x03, 0xB2, 0xA8, 0x94, 0x52, 0x5F, 0x26, 0x53,
  26728. 0x70, 0x05, 0x4B, 0x48, 0x86, 0x36, 0x14, 0x47,
  26729. 0x2B, 0x95, 0xD0, 0xA2, 0x30, 0x34, 0x42, 0xE3,
  26730. 0x78, 0xB0, 0xDD, 0x1C, 0x75, 0xAC, 0xBA, 0xB9,
  26731. 0x71, 0xA9, 0xA8, 0xD1, 0x28, 0x1C, 0x79, 0x61,
  26732. 0x3A, 0xCE, 0xC6, 0x93, 0x3C, 0x37, 0x7B, 0x3C,
  26733. 0x57, 0x8C, 0x2A, 0x61, 0xA1, 0xEC, 0x18, 0x1B,
  26734. 0x10, 0x12, 0x97, 0xA3, 0x7C, 0xC5, 0x19, 0x7B,
  26735. 0x29, 0x42, 0xF6, 0xA0, 0xE4, 0x70, 0x4C, 0x0E,
  26736. 0xC6, 0x35, 0x40, 0x48, 0x1B, 0x9F, 0x15, 0x9D,
  26737. 0xC2, 0x55, 0xB5, 0x9B, 0xB5, 0x5D, 0xF4, 0x96,
  26738. 0xAE, 0x54, 0x21, 0x7B, 0x76, 0x89, 0xBD, 0x51,
  26739. 0xDB, 0xA0, 0x38, 0x3A, 0x3D, 0x72, 0xD8, 0x52,
  26740. 0xFF, 0xCA, 0x76, 0xDF, 0x05, 0xB6, 0x6E, 0xEC,
  26741. 0xCB, 0xD4, 0x7B, 0xC5, 0x30, 0x40, 0x81, 0x76,
  26742. 0x28, 0xC7, 0x1E, 0x36, 0x1D, 0x6A, 0xF8, 0x89,
  26743. 0x08, 0x49, 0x16, 0xB4, 0x08, 0xA4, 0x66, 0xC9,
  26744. 0x6E, 0x70, 0x86, 0xC4, 0xA6, 0x0A, 0x10, 0xFC,
  26745. 0xF7, 0x53, 0x7B, 0xB9, 0x4A, 0xFB, 0xCC, 0x7D,
  26746. 0x43, 0x75, 0x90, 0x91, 0x9C, 0x28, 0x65, 0x0C,
  26747. 0x4F, 0x23, 0x68, 0x25, 0x92, 0x26, 0xA9, 0xBF,
  26748. 0xDA, 0x3A, 0x3A, 0x0B, 0xA1, 0xB5, 0x08, 0x7D,
  26749. 0x9D, 0x76, 0x44, 0x2F, 0xD7, 0x86, 0xC6, 0xF8,
  26750. 0x1C, 0x68, 0xC0, 0x36, 0x0D, 0x71, 0x94, 0xD7,
  26751. 0x07, 0x2C, 0x45, 0x33, 0xAE, 0xA8, 0x6C, 0x2D,
  26752. 0x1F, 0x8C, 0x0A, 0x27, 0x69, 0x60, 0x66, 0xF6,
  26753. 0xCF, 0xD1, 0x10, 0x03, 0xF7, 0x97, 0x27, 0x0B,
  26754. 0x32, 0x38, 0x97, 0x13, 0xCF, 0xFA, 0x09, 0x3D,
  26755. 0x99, 0x1B, 0x63, 0x84, 0x4C, 0x38, 0x5E, 0x72,
  26756. 0x27, 0x7F, 0x16, 0x6F, 0x5A, 0x39, 0x34, 0xD6,
  26757. 0xBB, 0x89, 0xA4, 0x78, 0x8D, 0xE2, 0x83, 0x21,
  26758. 0xDE, 0xFC, 0x74, 0x57, 0xAB, 0x48, 0x4B, 0xD3,
  26759. 0x09, 0x86, 0xDC, 0x1D, 0xAB, 0x30, 0x08, 0xCD,
  26760. 0x7B, 0x22, 0xF6, 0x97, 0x02, 0xFA, 0xBB, 0x9A,
  26761. 0x10, 0x45, 0x40, 0x7D, 0xA4, 0x79, 0x1C, 0x35,
  26762. 0x90, 0xFF, 0x59, 0x9D, 0x81, 0xD6, 0x88, 0xCF,
  26763. 0xA7, 0xCC, 0x12, 0xA6, 0x8C, 0x50, 0xF5, 0x1A,
  26764. 0x10, 0x09, 0x41, 0x1B, 0x44, 0x85, 0x0F, 0x90,
  26765. 0x15, 0xDC, 0x84, 0xA9, 0x3B, 0x17, 0xC7, 0xA2,
  26766. 0x07, 0x55, 0x2C, 0x66, 0x1E, 0xA9, 0x83, 0x8E,
  26767. 0x31, 0xB9, 0x5E, 0xAD, 0x54, 0x62, 0x48, 0xE5,
  26768. 0x6B, 0xE7, 0xA5, 0x13, 0x05, 0x05, 0x26, 0x87,
  26769. 0x71, 0x19, 0x98, 0x80, 0xA1, 0x41, 0x77, 0x1A,
  26770. 0x9E, 0x47, 0xAC, 0xFE, 0xD5, 0x90, 0xCB, 0x3A,
  26771. 0xA7, 0xCB, 0x7C, 0x5F, 0x74, 0x91, 0x1D, 0x89,
  26772. 0x12, 0xC2, 0x9D, 0x62, 0x33, 0xF4, 0xD5, 0x3B,
  26773. 0xC6, 0x41, 0x39, 0xE2, 0xF5, 0x5B, 0xE7, 0x55,
  26774. 0x07, 0xDD, 0x77, 0x86, 0x8E, 0x38, 0x4A, 0xEC,
  26775. 0x58, 0x1F, 0x3F, 0x41, 0x1D, 0xB1, 0xA7, 0x42,
  26776. 0x97, 0x2D, 0x3E, 0xBF, 0xD3, 0x31, 0x5C, 0x84,
  26777. 0xA5, 0xAD, 0x63, 0xA0, 0xE7, 0x5C, 0x8B, 0xCA,
  26778. 0x3E, 0x30, 0x41, 0xE0, 0x5D, 0x90, 0x67, 0xAF,
  26779. 0xF3, 0xB1, 0x24, 0x4F, 0x76, 0x3E, 0x79, 0x83
  26780. };
  26781. static const byte seed_1024[KYBER_ENC_RAND_SZ] = {
  26782. 0x59, 0xC5, 0x15, 0x4C, 0x04, 0xAE, 0x43, 0xAA,
  26783. 0xFF, 0x32, 0x70, 0x0F, 0x08, 0x17, 0x00, 0x38,
  26784. 0x9D, 0x54, 0xBE, 0xC4, 0xC3, 0x7C, 0x08, 0x8B,
  26785. 0x1C, 0x53, 0xF6, 0x62, 0x12, 0xB1, 0x2C, 0x72
  26786. };
  26787. static const byte c_1024[KYBER1024_CIPHER_TEXT_SIZE] = {
  26788. 0xE2, 0xD5, 0xFD, 0x4C, 0x13, 0xCE, 0xA0, 0xB5,
  26789. 0x2D, 0x87, 0x4F, 0xEA, 0x90, 0x12, 0xF3, 0xA5,
  26790. 0x17, 0x43, 0xA1, 0x09, 0x37, 0x10, 0xBB, 0xF2,
  26791. 0x39, 0x50, 0xF9, 0x14, 0x7A, 0x47, 0x2E, 0xE5,
  26792. 0x53, 0x39, 0x28, 0xA2, 0xF4, 0x6D, 0x59, 0x2F,
  26793. 0x35, 0xDA, 0x8B, 0x4F, 0x75, 0x8C, 0x89, 0x3B,
  26794. 0x0D, 0x7B, 0x98, 0x94, 0x8B, 0xE4, 0x47, 0xB1,
  26795. 0x7C, 0xB2, 0xAE, 0x58, 0xAF, 0x8A, 0x48, 0x9D,
  26796. 0xDD, 0x92, 0x32, 0xB9, 0x9B, 0x1C, 0x0D, 0x2D,
  26797. 0xE7, 0x7C, 0xAA, 0x47, 0x2B, 0xC3, 0xBB, 0xD4,
  26798. 0xA7, 0xC6, 0x0D, 0xBF, 0xDC, 0xA9, 0x2E, 0xBF,
  26799. 0x3A, 0x1C, 0xE1, 0xC2, 0x2D, 0xAD, 0x13, 0xE8,
  26800. 0x87, 0x00, 0x4E, 0x29, 0x24, 0xFD, 0x22, 0x65,
  26801. 0x6F, 0x5E, 0x50, 0x87, 0x91, 0xDE, 0x06, 0xD8,
  26802. 0x5E, 0x1A, 0x14, 0x26, 0x80, 0x8E, 0xD9, 0xA8,
  26803. 0x9F, 0x6E, 0x2F, 0xD3, 0xC2, 0x45, 0xD4, 0x75,
  26804. 0x8B, 0x22, 0xB0, 0x2C, 0xAD, 0xE3, 0x3B, 0x60,
  26805. 0xFC, 0x88, 0x9A, 0x33, 0xFC, 0x44, 0x47, 0xED,
  26806. 0xEB, 0xBF, 0xD4, 0x53, 0x0D, 0xE8, 0x65, 0x96,
  26807. 0xA3, 0x37, 0x89, 0xD5, 0xDB, 0xA6, 0xE6, 0xEC,
  26808. 0x9F, 0x89, 0x87, 0x9A, 0xF4, 0xBE, 0x49, 0x09,
  26809. 0xA6, 0x90, 0x17, 0xC9, 0xBB, 0x7A, 0x5E, 0x31,
  26810. 0x81, 0x5E, 0xA5, 0xF1, 0x32, 0xEE, 0xC4, 0x98,
  26811. 0x4F, 0xAA, 0x7C, 0xCF, 0x59, 0x4D, 0xD0, 0x0D,
  26812. 0x4D, 0x84, 0x87, 0xE4, 0x56, 0x21, 0xAF, 0x8F,
  26813. 0x6E, 0x33, 0x05, 0x51, 0x43, 0x9C, 0x93, 0xEC,
  26814. 0x07, 0x8A, 0x7A, 0x3C, 0xC1, 0x59, 0x4A, 0xF9,
  26815. 0x1F, 0x84, 0x17, 0x37, 0x5F, 0xD6, 0x08, 0x8C,
  26816. 0xEB, 0x5E, 0x85, 0xC6, 0x70, 0x99, 0x09, 0x1B,
  26817. 0xAC, 0x11, 0x49, 0x8A, 0x0D, 0x71, 0x14, 0x55,
  26818. 0xF5, 0xE0, 0xD9, 0x5C, 0xD7, 0xBB, 0xE5, 0xCD,
  26819. 0xD8, 0xFE, 0xCB, 0x31, 0x9E, 0x68, 0x53, 0xC2,
  26820. 0x3C, 0x9B, 0xE2, 0xC7, 0x63, 0xDF, 0x57, 0x86,
  26821. 0x66, 0xC4, 0x0A, 0x40, 0xA8, 0x74, 0x86, 0xE4,
  26822. 0x6B, 0xA8, 0x71, 0x61, 0x46, 0x19, 0x29, 0x04,
  26823. 0x51, 0x0A, 0x6D, 0xC5, 0x9D, 0xA8, 0x02, 0x58,
  26824. 0x25, 0x28, 0x3D, 0x68, 0x4D, 0xB9, 0x14, 0x10,
  26825. 0xB4, 0xF1, 0x2C, 0x6D, 0x8F, 0xBD, 0x0A, 0xDD,
  26826. 0x75, 0xD3, 0x09, 0x89, 0x18, 0xCB, 0x04, 0xAC,
  26827. 0x7B, 0xC4, 0xDB, 0x0D, 0x6B, 0xCD, 0xF1, 0x19,
  26828. 0x4D, 0xD8, 0x62, 0x92, 0xE0, 0x5B, 0x7B, 0x86,
  26829. 0x30, 0x62, 0x5B, 0x58, 0x9C, 0xC5, 0x09, 0xD2,
  26830. 0x15, 0xBB, 0xD0, 0x6A, 0x2E, 0x7C, 0x66, 0xF4,
  26831. 0x24, 0xCD, 0xF8, 0xC4, 0x0A, 0xC6, 0xC1, 0xE5,
  26832. 0xAE, 0x6C, 0x96, 0x4B, 0x7D, 0x9E, 0x92, 0xF9,
  26833. 0x5F, 0xC5, 0xC8, 0x85, 0x22, 0x81, 0x62, 0x8B,
  26834. 0x81, 0xB9, 0xAF, 0xAB, 0xC7, 0xF0, 0x3B, 0xE3,
  26835. 0xF6, 0x2E, 0x80, 0x47, 0xBB, 0x88, 0xD0, 0x1C,
  26836. 0x68, 0x68, 0x7B, 0x8D, 0xD4, 0xFE, 0x63, 0x82,
  26837. 0x00, 0x62, 0xB6, 0x78, 0x8A, 0x53, 0x72, 0x90,
  26838. 0x53, 0x82, 0x6E, 0xD3, 0xB7, 0xC7, 0xEF, 0x82,
  26839. 0x41, 0xE1, 0x9C, 0x85, 0x11, 0x7B, 0x3C, 0x53,
  26840. 0x41, 0x88, 0x1D, 0x4F, 0x29, 0x9E, 0x50, 0x37,
  26841. 0x4C, 0x8E, 0xEF, 0xD5, 0x56, 0x0B, 0xD1, 0x83,
  26842. 0x19, 0xA7, 0x96, 0x3A, 0x3D, 0x02, 0xF0, 0xFB,
  26843. 0xE8, 0x4B, 0xC4, 0x84, 0xB5, 0xA4, 0x01, 0x8B,
  26844. 0x97, 0xD2, 0x74, 0x19, 0x1C, 0x95, 0xF7, 0x02,
  26845. 0xBA, 0xB9, 0xB0, 0xD1, 0x05, 0xFA, 0xF9, 0xFD,
  26846. 0xCF, 0xF9, 0x7E, 0x43, 0x72, 0x36, 0x56, 0x75,
  26847. 0x99, 0xFA, 0xF7, 0x3B, 0x07, 0x5D, 0x40, 0x61,
  26848. 0x04, 0xD4, 0x03, 0xCD, 0xF8, 0x12, 0x24, 0xDA,
  26849. 0x59, 0x0B, 0xEC, 0x28, 0x97, 0xE3, 0x01, 0x09,
  26850. 0xE1, 0xF2, 0xE5, 0xAE, 0x46, 0x10, 0xC8, 0x09,
  26851. 0xA7, 0x3F, 0x63, 0x8C, 0x84, 0x21, 0x0B, 0x34,
  26852. 0x47, 0xA7, 0xC8, 0xB6, 0xDD, 0xDB, 0x5A, 0xE2,
  26853. 0x00, 0xBF, 0x20, 0xE2, 0xFE, 0x4D, 0x4B, 0xA6,
  26854. 0xC6, 0xB1, 0x27, 0x67, 0xFB, 0x87, 0x60, 0xF6,
  26855. 0x6C, 0x51, 0x18, 0xE7, 0xA9, 0x93, 0x5B, 0x41,
  26856. 0xC9, 0xA4, 0x71, 0xA1, 0xD3, 0x23, 0x76, 0x88,
  26857. 0xC1, 0xE6, 0x18, 0xCC, 0x3B, 0xE9, 0x36, 0xAA,
  26858. 0x3F, 0x5E, 0x44, 0xE0, 0x86, 0x82, 0x0B, 0x81,
  26859. 0x0E, 0x06, 0x32, 0x11, 0xFC, 0x21, 0xC4, 0x04,
  26860. 0x4B, 0x3A, 0xC4, 0xD0, 0x0D, 0xF1, 0xBC, 0xC7,
  26861. 0xB2, 0x4D, 0xC0, 0x7B, 0xA4, 0x8B, 0x23, 0xB0,
  26862. 0xFC, 0x12, 0xA3, 0xED, 0x3D, 0x0A, 0x5C, 0xF7,
  26863. 0x67, 0x14, 0x15, 0xAB, 0x9C, 0xF2, 0x12, 0x86,
  26864. 0xFE, 0x63, 0xFB, 0x41, 0x41, 0x85, 0x70, 0x55,
  26865. 0x5D, 0x47, 0x39, 0xB8, 0x81, 0x04, 0xA8, 0x59,
  26866. 0x3F, 0x29, 0x30, 0x25, 0xA4, 0xE3, 0xEE, 0x7C,
  26867. 0x67, 0xE4, 0xB4, 0x8E, 0x40, 0xF6, 0xBA, 0x8C,
  26868. 0x09, 0x86, 0x0C, 0x3F, 0xBB, 0xE5, 0x5D, 0x45,
  26869. 0xB4, 0x5F, 0xC9, 0xAB, 0x62, 0x9B, 0x17, 0xC2,
  26870. 0x76, 0xC9, 0xC9, 0xE2, 0xAF, 0x3A, 0x04, 0x3B,
  26871. 0xEA, 0xFC, 0x18, 0xFD, 0x4F, 0x25, 0xEE, 0x7F,
  26872. 0x83, 0xBD, 0xDC, 0xD2, 0xD9, 0x39, 0x14, 0xB7,
  26873. 0xED, 0x4F, 0x7C, 0x9A, 0xF1, 0x27, 0xF3, 0xF1,
  26874. 0x5C, 0x27, 0x7B, 0xE1, 0x65, 0x51, 0xFE, 0xF3,
  26875. 0xAE, 0x03, 0xD7, 0xB9, 0x14, 0x3F, 0x0C, 0x9C,
  26876. 0x01, 0x9A, 0xB9, 0x7E, 0xEA, 0x07, 0x63, 0x66,
  26877. 0x13, 0x1F, 0x51, 0x83, 0x63, 0x71, 0x1B, 0x34,
  26878. 0xE9, 0x6D, 0x3F, 0x8A, 0x51, 0x3F, 0x3E, 0x20,
  26879. 0xB1, 0xD4, 0x52, 0xC4, 0xB7, 0xAE, 0x3B, 0x97,
  26880. 0x5E, 0xA9, 0x4D, 0x88, 0x0D, 0xAC, 0x66, 0x93,
  26881. 0x39, 0x97, 0x50, 0xD0, 0x22, 0x20, 0x40, 0x3F,
  26882. 0x0D, 0x3E, 0x3F, 0xC1, 0x17, 0x2A, 0x4D, 0xE9,
  26883. 0xDC, 0x28, 0x0E, 0xAF, 0x0F, 0xEE, 0x28, 0x83,
  26884. 0xA6, 0x66, 0x0B, 0xF5, 0xA3, 0xD2, 0x46, 0xFF,
  26885. 0x41, 0xD2, 0x1B, 0x36, 0xEA, 0x52, 0x1C, 0xF7,
  26886. 0xAA, 0x68, 0x9F, 0x80, 0x0D, 0x0F, 0x86, 0xF4,
  26887. 0xFA, 0x10, 0x57, 0xD8, 0xA1, 0x3F, 0x9D, 0xA8,
  26888. 0xFF, 0xFD, 0x0D, 0xC1, 0xFA, 0xD3, 0xC0, 0x4B,
  26889. 0xB1, 0xCC, 0xCB, 0x7C, 0x83, 0x4D, 0xB0, 0x51,
  26890. 0xA7, 0xAC, 0x2E, 0x4C, 0x60, 0x30, 0x19, 0x96,
  26891. 0xC9, 0x30, 0x71, 0xEA, 0x41, 0x6B, 0x42, 0x17,
  26892. 0x59, 0x93, 0x56, 0x59, 0xCF, 0x62, 0xCA, 0x5F,
  26893. 0x13, 0xAE, 0x07, 0xC3, 0xB1, 0x95, 0xC1, 0x48,
  26894. 0x15, 0x9D, 0x8B, 0xEB, 0x03, 0xD4, 0x40, 0xB0,
  26895. 0x0F, 0x53, 0x05, 0x76, 0x5F, 0x20, 0xC0, 0xC4,
  26896. 0x6E, 0xEE, 0x59, 0xC6, 0xD1, 0x62, 0x06, 0x40,
  26897. 0x2D, 0xB1, 0xC7, 0x15, 0xE8, 0x88, 0xBD, 0xE5,
  26898. 0x9C, 0x78, 0x1F, 0x35, 0xA7, 0xCC, 0x7C, 0x1C,
  26899. 0x5E, 0xCB, 0x21, 0x55, 0xAE, 0x3E, 0x95, 0x9C,
  26900. 0x09, 0x64, 0xCC, 0x1E, 0xF8, 0xD7, 0xC6, 0x9D,
  26901. 0x14, 0x58, 0xA9, 0xA4, 0x2F, 0x95, 0xF4, 0xC6,
  26902. 0xB5, 0xB9, 0x96, 0x34, 0x57, 0x12, 0xAA, 0x29,
  26903. 0x0F, 0xBB, 0xF7, 0xDF, 0xD4, 0xA6, 0xE8, 0x64,
  26904. 0x63, 0x02, 0x2A, 0x3F, 0x47, 0x25, 0xF6, 0x51,
  26905. 0x1B, 0xF7, 0xEA, 0x5E, 0x95, 0xC7, 0x07, 0xCD,
  26906. 0x35, 0x73, 0x60, 0x9A, 0xAD, 0xEA, 0xF5, 0x40,
  26907. 0x15, 0x2C, 0x49, 0x5F, 0x37, 0xFE, 0x6E, 0xC8,
  26908. 0xBB, 0x9F, 0xA2, 0xAA, 0x61, 0xD1, 0x57, 0x35,
  26909. 0x93, 0x4F, 0x47, 0x37, 0x92, 0x8F, 0xDE, 0x90,
  26910. 0xBA, 0x99, 0x57, 0x22, 0x46, 0x5D, 0x4A, 0x64,
  26911. 0x50, 0x5A, 0x52, 0x01, 0xF0, 0x7A, 0xA5, 0x8C,
  26912. 0xFD, 0x8A, 0xE2, 0x26, 0xE0, 0x20, 0x70, 0xB2,
  26913. 0xDB, 0xF5, 0x12, 0xB9, 0x75, 0x31, 0x9A, 0x7E,
  26914. 0x87, 0x53, 0xB4, 0xFD, 0xAE, 0x0E, 0xB4, 0x92,
  26915. 0x28, 0x69, 0xCC, 0x8E, 0x25, 0xC4, 0xA5, 0x56,
  26916. 0x0C, 0x2A, 0x06, 0x85, 0xDE, 0x3A, 0xC3, 0x92,
  26917. 0xA8, 0x92, 0x5B, 0xA8, 0x82, 0x00, 0x48, 0x94,
  26918. 0x74, 0x2E, 0x43, 0xCC, 0xFC, 0x27, 0x74, 0x39,
  26919. 0xEC, 0x80, 0x50, 0xA9, 0xAE, 0xB4, 0x29, 0x32,
  26920. 0xE0, 0x1C, 0x84, 0x0D, 0xFC, 0xED, 0xCC, 0x34,
  26921. 0xD3, 0x99, 0x12, 0x89, 0xA6, 0x2C, 0x17, 0xD1,
  26922. 0x28, 0x4C, 0x83, 0x95, 0x14, 0xB9, 0x33, 0x51,
  26923. 0xDB, 0xB2, 0xDD, 0xA8, 0x1F, 0x92, 0x45, 0x65,
  26924. 0xD7, 0x0E, 0x70, 0x79, 0xD5, 0xB8, 0x12, 0x6C,
  26925. 0xAA, 0xB7, 0xA4, 0xA1, 0xC7, 0x31, 0x65, 0x5A,
  26926. 0x53, 0xBC, 0xC0, 0x9F, 0x5D, 0x63, 0xEC, 0x90,
  26927. 0x86, 0xDE, 0xA6, 0x50, 0x05, 0x59, 0x85, 0xED,
  26928. 0xFA, 0x82, 0x97, 0xD9, 0xC9, 0x54, 0x10, 0xC5,
  26929. 0xD1, 0x89, 0x4D, 0x17, 0xD5, 0x93, 0x05, 0x49,
  26930. 0xAD, 0xBC, 0x2B, 0x87, 0x33, 0xC9, 0x9F, 0xE6,
  26931. 0x2E, 0x17, 0xC4, 0xDE, 0x34, 0xA5, 0xD8, 0x9B,
  26932. 0x12, 0xD1, 0x8E, 0x42, 0xA4, 0x22, 0xD2, 0xCE,
  26933. 0x77, 0x9C, 0x2C, 0x28, 0xEB, 0x2D, 0x98, 0x00,
  26934. 0x3D, 0x5C, 0xD3, 0x23, 0xFC, 0xBE, 0xCF, 0x02,
  26935. 0xB5, 0x06, 0x6E, 0x0E, 0x73, 0x48, 0x10, 0xF0,
  26936. 0x9E, 0xD8, 0x90, 0x13, 0xC0, 0x0F, 0x01, 0x1B,
  26937. 0xD2, 0x20, 0xF2, 0xE5, 0xD6, 0xA3, 0x62, 0xDF,
  26938. 0x90, 0x59, 0x91, 0x98, 0xA0, 0x93, 0xB0, 0x3C,
  26939. 0x8D, 0x8E, 0xFB, 0xFE, 0x0B, 0x61, 0x75, 0x92,
  26940. 0xFA, 0xF1, 0xE6, 0x42, 0x20, 0xC4, 0x44, 0x0B,
  26941. 0x53, 0xFF, 0xB4, 0x71, 0x64, 0xF3, 0x69, 0xC9,
  26942. 0x52, 0x90, 0xBA, 0x9F, 0x31, 0x08, 0xD6, 0x86,
  26943. 0xC5, 0x7D, 0xB6, 0x45, 0xC5, 0x3C, 0x01, 0x2E,
  26944. 0x57, 0xAF, 0x25, 0xBD, 0x66, 0x93, 0xE2, 0xCC,
  26945. 0x6B, 0x57, 0x65, 0x1A, 0xF1, 0x59, 0x1F, 0xE5,
  26946. 0xD8, 0x91, 0x66, 0x40, 0xEC, 0x01, 0x7C, 0x25,
  26947. 0x3D, 0xF0, 0x60, 0x6B, 0xB6, 0xB3, 0x03, 0x5F,
  26948. 0xAE, 0x74, 0x8F, 0x3D, 0x40, 0x34, 0x22, 0x3B,
  26949. 0x1B, 0x5E, 0xFB, 0xF5, 0x28, 0x3E, 0x77, 0x8C,
  26950. 0x10, 0x94, 0x29, 0x1C, 0xF7, 0xB1, 0x9B, 0xE0,
  26951. 0xF3, 0x17, 0x35, 0x0E, 0x6F, 0x85, 0x18, 0xFD,
  26952. 0xE0, 0xEF, 0xB1, 0x38, 0x1F, 0xB6, 0xE1, 0x6C,
  26953. 0x24, 0x1F, 0x7F, 0x17, 0xA5, 0x21, 0x06, 0x93,
  26954. 0xA2, 0x74, 0x15, 0x9E, 0x7F, 0xAC, 0x86, 0x8C,
  26955. 0xD0, 0xDC, 0x43, 0x59, 0xC3, 0xD9, 0xEE, 0xFE,
  26956. 0xA0, 0xD9, 0xE3, 0x1E, 0x43, 0xFA, 0x65, 0x13,
  26957. 0x92, 0xC6, 0x5A, 0x54, 0x3A, 0x59, 0xB3, 0xEE,
  26958. 0xE3, 0xA6, 0x39, 0xDC, 0x94, 0x17, 0xD0, 0x56,
  26959. 0xA5, 0xFF, 0x0F, 0x16, 0x0B, 0xEE, 0xE2, 0xEA,
  26960. 0xC2, 0x9A, 0x7D, 0x88, 0xC0, 0x98, 0x2C, 0xF7,
  26961. 0x0B, 0x5A, 0x46, 0x37, 0x9F, 0x21, 0xE5, 0x06,
  26962. 0xAA, 0xC6, 0x1A, 0x9B, 0xB1, 0xB8, 0xC2, 0xB9,
  26963. 0xDA, 0xB0, 0xE4, 0x4A, 0x82, 0x3B, 0x61, 0xD0,
  26964. 0xAA, 0x11, 0xD9, 0x4F, 0x76, 0xA4, 0xA8, 0xE2,
  26965. 0x1F, 0x9D, 0x42, 0x80, 0x68, 0x32, 0x08, 0xF4,
  26966. 0xEA, 0x91, 0x11, 0x16, 0xF6, 0xFD, 0x6A, 0x97,
  26967. 0x42, 0x69, 0x34, 0xEC, 0x34, 0x26, 0xB8, 0xC8,
  26968. 0xF7, 0x03, 0xDA, 0x85, 0xE9, 0xDC, 0xF9, 0x93,
  26969. 0x36, 0x13, 0x60, 0x03, 0x72, 0x8B, 0x8E, 0xCD,
  26970. 0xD0, 0x4A, 0x38, 0x9F, 0x6A, 0x81, 0x7A, 0x78,
  26971. 0xBF, 0xA6, 0x1B, 0xA4, 0x60, 0x20, 0xBF, 0x3C,
  26972. 0x34, 0x82, 0x95, 0x08, 0xF9, 0xD0, 0x6D, 0x15,
  26973. 0x53, 0xCD, 0x98, 0x7A, 0xAC, 0x38, 0x0D, 0x86,
  26974. 0xF1, 0x68, 0x84, 0x3B, 0xA3, 0x90, 0x4D, 0xE5,
  26975. 0xF7, 0x05, 0x8A, 0x41, 0xB4, 0xCD, 0x38, 0x8B,
  26976. 0xC9, 0xCE, 0x3A, 0xBA, 0x7E, 0xE7, 0x13, 0x9B,
  26977. 0x7F, 0xC9, 0xE5, 0xB8, 0xCF, 0xAA, 0xA3, 0x89,
  26978. 0x90, 0xBD, 0x4A, 0x5D, 0xB3, 0x2E, 0x26, 0x13,
  26979. 0xE7, 0xEC, 0x4F, 0x5F, 0x8B, 0x12, 0x92, 0xA3,
  26980. 0x8C, 0x6F, 0x4F, 0xF5, 0xA4, 0x04, 0x90, 0xD7,
  26981. 0x6B, 0x12, 0x66, 0x52, 0xFC, 0xF8, 0x6E, 0x24,
  26982. 0x52, 0x35, 0xD6, 0x36, 0xC6, 0x5C, 0xD1, 0x02,
  26983. 0xB0, 0x1E, 0x22, 0x78, 0x1A, 0x72, 0x91, 0x8C
  26984. };
  26985. static const byte k_1024[KYBER_SS_SZ] = {
  26986. 0x72, 0x64, 0xBD, 0xE5, 0xC6, 0xCE, 0xC1, 0x48,
  26987. 0x49, 0x69, 0x3E, 0x2C, 0x3C, 0x86, 0xE4, 0x8F,
  26988. 0x80, 0x95, 0x8A, 0x4F, 0x61, 0x86, 0xFC, 0x69,
  26989. 0x33, 0x3A, 0x41, 0x48, 0xE6, 0xE4, 0x97, 0xF3
  26990. };
  26991. #endif
  26992. static byte ct[KYBER_MAX_CIPHER_TEXT_SIZE];
  26993. static byte ss[KYBER_SS_SZ];
  26994. key = (KyberKey*)XMALLOC(sizeof(KyberKey), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  26995. ExpectNotNull(key);
  26996. if (key != NULL) {
  26997. XMEMSET(key, 0, sizeof(KyberKey));
  26998. }
  26999. #ifndef WOLFSSL_NO_KYBER512
  27000. ExpectIntEQ(wc_KyberKey_Init(KYBER512, key, NULL, INVALID_DEVID), 0);
  27001. ExpectIntEQ(wc_KyberKey_DecodePublicKey(key, ek_512, sizeof(ek_512)), 0);
  27002. ExpectIntEQ(wc_KyberKey_EncapsulateWithRandom(key, ct, ss, seed_512,
  27003. sizeof(seed_512)), 0);
  27004. ExpectIntEQ(XMEMCMP(ct, c_512, KYBER512_CIPHER_TEXT_SIZE), 0);
  27005. ExpectIntEQ(XMEMCMP(ss, k_512, KYBER_SS_SZ), 0);
  27006. wc_KyberKey_Free(key);
  27007. #endif
  27008. #ifndef WOLFSSL_NO_KYBER768
  27009. ExpectIntEQ(wc_KyberKey_Init(KYBER768, key, NULL, INVALID_DEVID), 0);
  27010. ExpectIntEQ(wc_KyberKey_DecodePublicKey(key, ek_768, sizeof(ek_768)), 0);
  27011. ExpectIntEQ(wc_KyberKey_EncapsulateWithRandom(key, ct, ss, seed_768,
  27012. sizeof(seed_768)), 0);
  27013. ExpectIntEQ(XMEMCMP(ct, c_768, KYBER768_CIPHER_TEXT_SIZE), 0);
  27014. ExpectIntEQ(XMEMCMP(ss, k_768, KYBER_SS_SZ), 0);
  27015. wc_KyberKey_Free(key);
  27016. #endif
  27017. #ifndef WOLFSSL_NO_KYBER1024
  27018. ExpectIntEQ(wc_KyberKey_Init(KYBER1024, key, NULL, INVALID_DEVID), 0);
  27019. ExpectIntEQ(wc_KyberKey_DecodePublicKey(key, ek_1024, sizeof(ek_1024)), 0);
  27020. ExpectIntEQ(wc_KyberKey_EncapsulateWithRandom(key, ct, ss, seed_1024,
  27021. sizeof(seed_1024)), 0);
  27022. ExpectIntEQ(XMEMCMP(ct, c_1024, KYBER1024_CIPHER_TEXT_SIZE), 0);
  27023. ExpectIntEQ(XMEMCMP(ss, k_1024, KYBER_SS_SZ), 0);
  27024. wc_KyberKey_Free(key);
  27025. #endif
  27026. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  27027. #endif
  27028. return EXPECT_RESULT();
  27029. }
  27030. static int test_wc_kyber_decapsulate_kats(void)
  27031. {
  27032. EXPECT_DECLS;
  27033. #if defined(WOLFSSL_HAVE_KYBER) && defined(WOLFSSL_WC_KYBER) && \
  27034. !defined(WOLFSSL_KYBER_ORIGINAL)
  27035. KyberKey* key;
  27036. #ifndef WOLFSSL_NO_KYBER512
  27037. static const byte dk_512[KYBER512_PRIVATE_KEY_SIZE] = {
  27038. 0x69, 0xF9, 0xCB, 0xFD, 0x12, 0x37, 0xBA, 0x16,
  27039. 0x1C, 0xF6, 0xE6, 0xC1, 0x8F, 0x48, 0x8F, 0xC6,
  27040. 0xE3, 0x9A, 0xB4, 0xA5, 0xC9, 0xE6, 0xC2, 0x2E,
  27041. 0xA4, 0xE3, 0xAD, 0x8F, 0x26, 0x7A, 0x9C, 0x44,
  27042. 0x20, 0x10, 0xD3, 0x2E, 0x61, 0xF8, 0x3E, 0x6B,
  27043. 0xFA, 0x5C, 0x58, 0x70, 0x61, 0x45, 0x37, 0x6D,
  27044. 0xBB, 0x84, 0x95, 0x28, 0xF6, 0x80, 0x07, 0xC8,
  27045. 0x22, 0xB3, 0x3A, 0x95, 0xB8, 0x49, 0x04, 0xDC,
  27046. 0xD2, 0x70, 0x8D, 0x03, 0x40, 0xC8, 0xB8, 0x08,
  27047. 0xBC, 0xD3, 0xAA, 0xD0, 0xE4, 0x8B, 0x85, 0x84,
  27048. 0x95, 0x83, 0xA1, 0xB4, 0xE5, 0x94, 0x5D, 0xD9,
  27049. 0x51, 0x4A, 0x7F, 0x64, 0x61, 0xE0, 0x57, 0xB7,
  27050. 0xEC, 0xF6, 0x19, 0x57, 0xE9, 0x7C, 0xF6, 0x28,
  27051. 0x15, 0xF9, 0xC3, 0x22, 0x94, 0xB3, 0x26, 0xE1,
  27052. 0xA1, 0xC4, 0xE3, 0x60, 0xB9, 0x49, 0x8B, 0xA8,
  27053. 0x0F, 0x8C, 0xA9, 0x15, 0x32, 0xB1, 0x71, 0xD0,
  27054. 0xAE, 0xFC, 0x48, 0x49, 0xFA, 0x53, 0xBC, 0x61,
  27055. 0x79, 0x32, 0xE2, 0x08, 0xA6, 0x77, 0xC6, 0x04,
  27056. 0x4A, 0x66, 0x00, 0xB8, 0xD8, 0xB8, 0x3F, 0x26,
  27057. 0xA7, 0x47, 0xB1, 0x8C, 0xFB, 0x78, 0xBE, 0xAF,
  27058. 0xC5, 0x51, 0xAD, 0x52, 0xB7, 0xCA, 0x6C, 0xB8,
  27059. 0x8F, 0x3B, 0x5D, 0x9C, 0xE2, 0xAF, 0x6C, 0x67,
  27060. 0x95, 0x6C, 0x47, 0x8C, 0xEF, 0x49, 0x1F, 0x59,
  27061. 0xE0, 0x19, 0x1B, 0x3B, 0xBE, 0x92, 0x9B, 0x94,
  27062. 0xB6, 0x66, 0xC1, 0x76, 0x13, 0x8B, 0x00, 0xF4,
  27063. 0x97, 0x24, 0x34, 0x1E, 0xE2, 0xE1, 0x64, 0xB9,
  27064. 0x4C, 0x05, 0x3C, 0x18, 0x5A, 0x51, 0xF9, 0x3E,
  27065. 0x00, 0xF3, 0x68, 0x61, 0x61, 0x3A, 0x7F, 0xD7,
  27066. 0x2F, 0xEB, 0xD2, 0x3A, 0x8B, 0x96, 0xA2, 0x60,
  27067. 0x23, 0x42, 0x39, 0xC9, 0x62, 0x8F, 0x99, 0x5D,
  27068. 0xC1, 0x38, 0x07, 0xB4, 0x3A, 0x69, 0x46, 0x81,
  27069. 0x67, 0xCB, 0x1A, 0x8F, 0x9D, 0xD0, 0x7E, 0xE3,
  27070. 0xB3, 0x32, 0x38, 0xF6, 0x30, 0x96, 0xEB, 0xC4,
  27071. 0x9D, 0x50, 0x51, 0xC4, 0xB6, 0x59, 0x63, 0xD7,
  27072. 0x4A, 0x47, 0x66, 0xC2, 0x26, 0xF0, 0xB9, 0x4F,
  27073. 0x18, 0x62, 0xC2, 0x12, 0x4C, 0x8C, 0x74, 0x97,
  27074. 0x48, 0xC0, 0xBC, 0x4D, 0xC1, 0x4C, 0xB3, 0x49,
  27075. 0x06, 0xB8, 0x1C, 0x55, 0x24, 0xFB, 0x81, 0x00,
  27076. 0x79, 0x85, 0x42, 0xDC, 0x6C, 0xC2, 0xAA, 0x0A,
  27077. 0x70, 0x85, 0x75, 0xEA, 0xBC, 0xC1, 0x1F, 0x96,
  27078. 0xA9, 0xE6, 0x1C, 0x01, 0x7A, 0x96, 0xA7, 0xCE,
  27079. 0x93, 0xC4, 0x20, 0x91, 0x73, 0x71, 0x13, 0xAE,
  27080. 0x78, 0x3C, 0x0A, 0xE8, 0x75, 0x5E, 0x59, 0x41,
  27081. 0x11, 0xED, 0xFA, 0xBF, 0xD8, 0x6C, 0x32, 0x12,
  27082. 0xC6, 0x12, 0xA7, 0xB6, 0x2A, 0xFD, 0x3C, 0x7A,
  27083. 0x5C, 0x78, 0xB2, 0xF0, 0x73, 0x44, 0xB7, 0x89,
  27084. 0xC2, 0xB2, 0xDB, 0xB5, 0xF4, 0x44, 0x8B, 0xE9,
  27085. 0x7B, 0xBA, 0x42, 0x33, 0xC0, 0x03, 0x9C, 0x0F,
  27086. 0xE8, 0x43, 0x00, 0xF9, 0xB0, 0x3A, 0xC9, 0x94,
  27087. 0x97, 0xE6, 0xD4, 0x6B, 0x6E, 0x95, 0x30, 0x8F,
  27088. 0xF8, 0x47, 0x90, 0xF6, 0x12, 0xCF, 0x18, 0x6E,
  27089. 0xC1, 0x68, 0x11, 0xE8, 0x0C, 0x17, 0x93, 0x16,
  27090. 0xA6, 0x3B, 0x25, 0x70, 0x3F, 0x60, 0xB8, 0x42,
  27091. 0xB6, 0x19, 0x07, 0xE6, 0x28, 0x94, 0xE7, 0x36,
  27092. 0x64, 0x7B, 0x3C, 0x09, 0xDA, 0x6F, 0xEC, 0x59,
  27093. 0x32, 0x78, 0x2B, 0x36, 0xE0, 0x63, 0x50, 0x85,
  27094. 0xA3, 0x94, 0x9E, 0x69, 0x4D, 0x7E, 0x17, 0xCB,
  27095. 0xA3, 0xD9, 0x06, 0x43, 0x30, 0x43, 0x8C, 0x07,
  27096. 0x1B, 0x58, 0x36, 0xA7, 0x70, 0xC5, 0x5F, 0x62,
  27097. 0x13, 0xCC, 0x14, 0x25, 0x84, 0x5D, 0xE5, 0xA3,
  27098. 0x34, 0xD7, 0x5D, 0x3E, 0x50, 0x58, 0xC7, 0x80,
  27099. 0x9F, 0xDA, 0x4B, 0xCD, 0x78, 0x19, 0x1D, 0xA9,
  27100. 0x79, 0x73, 0x25, 0xE6, 0x23, 0x6C, 0x26, 0x50,
  27101. 0xFC, 0x60, 0x4E, 0xE4, 0x3A, 0x83, 0xCE, 0xB3,
  27102. 0x49, 0x80, 0x08, 0x44, 0x03, 0xA3, 0x32, 0x59,
  27103. 0x85, 0x79, 0x07, 0x79, 0x9A, 0x9D, 0x2A, 0x71,
  27104. 0x3A, 0x63, 0x3B, 0x5C, 0x90, 0x47, 0x27, 0xF6,
  27105. 0x1E, 0x42, 0x52, 0x09, 0x91, 0xD6, 0x55, 0x70,
  27106. 0x5C, 0xB6, 0xBC, 0x1B, 0x74, 0xAF, 0x60, 0x71,
  27107. 0x3E, 0xF8, 0x71, 0x2F, 0x14, 0x08, 0x68, 0x69,
  27108. 0xBE, 0x8E, 0xB2, 0x97, 0xD2, 0x28, 0xB3, 0x25,
  27109. 0xA0, 0x60, 0x9F, 0xD6, 0x15, 0xEA, 0xB7, 0x08,
  27110. 0x15, 0x40, 0xA6, 0x1A, 0x82, 0xAB, 0xF4, 0x3B,
  27111. 0x7D, 0xF9, 0x8A, 0x59, 0x5B, 0xE1, 0x1F, 0x41,
  27112. 0x6B, 0x41, 0xE1, 0xEB, 0x75, 0xBB, 0x57, 0x97,
  27113. 0x7C, 0x25, 0xC6, 0x4E, 0x97, 0x43, 0x7D, 0x88,
  27114. 0xCA, 0x5F, 0xDA, 0x61, 0x59, 0xD6, 0x68, 0xF6,
  27115. 0xBA, 0xB8, 0x15, 0x75, 0x55, 0xB5, 0xD5, 0x4C,
  27116. 0x0F, 0x47, 0xCB, 0xCD, 0x16, 0x84, 0x3B, 0x1A,
  27117. 0x0A, 0x0F, 0x02, 0x10, 0xEE, 0x31, 0x03, 0x13,
  27118. 0x96, 0x7F, 0x3D, 0x51, 0x64, 0x99, 0x01, 0x8F,
  27119. 0xDF, 0x31, 0x14, 0x77, 0x24, 0x70, 0xA1, 0x88,
  27120. 0x9C, 0xC0, 0x6C, 0xB6, 0xB6, 0x69, 0x0A, 0xC3,
  27121. 0x1A, 0xBC, 0xFA, 0xF4, 0xBC, 0x70, 0x76, 0x84,
  27122. 0x54, 0x5B, 0x00, 0x0B, 0x58, 0x0C, 0xCB, 0xFC,
  27123. 0xBC, 0xE9, 0xFA, 0x70, 0xAA, 0xEA, 0x0B, 0xBD,
  27124. 0x91, 0x10, 0x99, 0x2A, 0x7C, 0x6C, 0x06, 0xCB,
  27125. 0x36, 0x85, 0x27, 0xFD, 0x22, 0x90, 0x90, 0x75,
  27126. 0x7E, 0x6F, 0xE7, 0x57, 0x05, 0xFA, 0x59, 0x2A,
  27127. 0x76, 0x08, 0xF0, 0x50, 0xC6, 0xF8, 0x87, 0x03,
  27128. 0xCC, 0x28, 0xCB, 0x00, 0x0C, 0x1D, 0x7E, 0x77,
  27129. 0xB8, 0x97, 0xB7, 0x2C, 0x62, 0xBC, 0xC7, 0xAE,
  27130. 0xA2, 0x1A, 0x57, 0x72, 0x94, 0x83, 0xD2, 0x21,
  27131. 0x18, 0x32, 0xBE, 0xD6, 0x12, 0x43, 0x0C, 0x98,
  27132. 0x31, 0x03, 0xC6, 0x9E, 0x8C, 0x07, 0x2C, 0x0E,
  27133. 0xA7, 0x89, 0x8F, 0x22, 0x83, 0xBE, 0xC4, 0x8C,
  27134. 0x5A, 0xC8, 0x19, 0x84, 0xD4, 0xA5, 0xA8, 0x36,
  27135. 0x19, 0x73, 0x5A, 0x84, 0x2B, 0xD1, 0x72, 0xC0,
  27136. 0xD1, 0xB3, 0x9F, 0x43, 0x58, 0x8A, 0xF1, 0x70,
  27137. 0x45, 0x8B, 0xA9, 0xEE, 0x74, 0x92, 0xEA, 0xAA,
  27138. 0x94, 0xEA, 0x53, 0xA4, 0xD3, 0x84, 0x98, 0xEC,
  27139. 0xBB, 0x98, 0xA5, 0xF4, 0x07, 0xE7, 0xC9, 0x7B,
  27140. 0x4E, 0x16, 0x6E, 0x39, 0x71, 0x92, 0xC2, 0x16,
  27141. 0x03, 0x30, 0x14, 0xB8, 0x78, 0xE9, 0x38, 0x07,
  27142. 0x5C, 0x6C, 0x1F, 0x10, 0xA0, 0x06, 0x5A, 0xBC,
  27143. 0x31, 0x63, 0x72, 0x2F, 0x1A, 0x2E, 0xFF, 0xEC,
  27144. 0x8D, 0x6E, 0x3A, 0x0C, 0x4F, 0x71, 0x74, 0xFC,
  27145. 0x16, 0xB7, 0x9F, 0xB5, 0x18, 0x6A, 0x75, 0x16,
  27146. 0x8F, 0x81, 0xA5, 0x6A, 0xA4, 0x8A, 0x20, 0xA0,
  27147. 0x4B, 0xDD, 0xF1, 0x82, 0xC6, 0xE1, 0x79, 0xC3,
  27148. 0xF6, 0x90, 0x61, 0x55, 0x5E, 0xF7, 0x39, 0x6D,
  27149. 0xD0, 0xB7, 0x49, 0x96, 0x01, 0xA6, 0xEB, 0x3A,
  27150. 0x96, 0xA9, 0xA2, 0x2D, 0x04, 0xF1, 0x16, 0x8D,
  27151. 0xB5, 0x63, 0x55, 0xB0, 0x76, 0x00, 0xA2, 0x03,
  27152. 0x70, 0x63, 0x7B, 0x64, 0x59, 0x76, 0xBB, 0xD9,
  27153. 0x7B, 0x6D, 0x62, 0x88, 0xA0, 0xD3, 0x03, 0x63,
  27154. 0x60, 0x47, 0x2E, 0x3A, 0xC7, 0x1D, 0x56, 0x6D,
  27155. 0xB8, 0xFB, 0xB1, 0xB1, 0xD7, 0x6C, 0xB7, 0x55,
  27156. 0xCD, 0x0D, 0x68, 0xBD, 0xBF, 0xC0, 0x48, 0xEB,
  27157. 0xA2, 0x52, 0x5E, 0xEA, 0x9D, 0xD5, 0xB1, 0x44,
  27158. 0xFB, 0x3B, 0x60, 0xFB, 0xC3, 0x42, 0x39, 0x32,
  27159. 0x0C, 0xBC, 0x06, 0x9B, 0x35, 0xAB, 0x16, 0xB8,
  27160. 0x75, 0x65, 0x36, 0xFB, 0x33, 0xE8, 0xA6, 0xAF,
  27161. 0x1D, 0xD4, 0x2C, 0x79, 0xF4, 0x8A, 0xD1, 0x20,
  27162. 0xAE, 0x4B, 0x15, 0x9D, 0x3D, 0x8C, 0x31, 0x90,
  27163. 0x60, 0xCC, 0xE5, 0x69, 0xC3, 0xF6, 0x03, 0x53,
  27164. 0x65, 0x58, 0x5D, 0x34, 0x41, 0x37, 0x95, 0xA6,
  27165. 0xA1, 0x8E, 0xC5, 0x13, 0x6A, 0xB1, 0x3C, 0x90,
  27166. 0xE3, 0xAF, 0x14, 0xC0, 0xB8, 0xA4, 0x64, 0xC8,
  27167. 0x6B, 0x90, 0x73, 0x22, 0x2B, 0x56, 0xB3, 0xF7,
  27168. 0x32, 0x8A, 0xEA, 0x79, 0x81, 0x55, 0x32, 0x59,
  27169. 0x11, 0x25, 0x0E, 0xF0, 0x16, 0xD7, 0x28, 0x02,
  27170. 0xE3, 0x87, 0x8A, 0xA5, 0x05, 0x40, 0xCC, 0x98,
  27171. 0x39, 0x56, 0x97, 0x1D, 0x6E, 0xFA, 0x35, 0x2C,
  27172. 0x02, 0x55, 0x4D, 0xC7, 0x60, 0xA5, 0xA9, 0x13,
  27173. 0x58, 0xEA, 0x56, 0x37, 0x08, 0x84, 0xFD, 0x5B,
  27174. 0x3F, 0x85, 0xB7, 0x0E, 0x83, 0xE4, 0x69, 0x7D,
  27175. 0xEB, 0x17, 0x05, 0x16, 0x9E, 0x9C, 0x60, 0xA7,
  27176. 0x45, 0x28, 0xCF, 0x15, 0x28, 0x1C, 0xB1, 0xB1,
  27177. 0xC4, 0x57, 0xD4, 0x67, 0xB5, 0xF9, 0x3A, 0x60,
  27178. 0x37, 0x3D, 0x10, 0xE0, 0xCF, 0x6A, 0x83, 0x7A,
  27179. 0xA3, 0xC9, 0x59, 0x6A, 0x72, 0xBE, 0xC2, 0x9B,
  27180. 0x2D, 0x7E, 0x58, 0x65, 0x3D, 0x53, 0x30, 0x61,
  27181. 0xD3, 0x81, 0xD5, 0x17, 0x59, 0x75, 0x22, 0x17,
  27182. 0xEB, 0x46, 0xCA, 0xC7, 0x80, 0x7C, 0x4A, 0xD3,
  27183. 0x8B, 0x61, 0x16, 0x44, 0xAC, 0xF0, 0xA3, 0xF2,
  27184. 0x6B, 0x6B, 0x08, 0x4A, 0xB4, 0x7A, 0x83, 0xBF,
  27185. 0x0D, 0x69, 0x6F, 0x8A, 0x47, 0x68, 0xFC, 0x35,
  27186. 0xBC, 0xA6, 0xBC, 0x79, 0x03, 0xB2, 0xA2, 0x37,
  27187. 0xC2, 0x77, 0x49, 0xF5, 0x51, 0x0C, 0x86, 0x38,
  27188. 0x69, 0xE6, 0xAE, 0x56, 0xBB, 0x2A, 0xFE, 0x47,
  27189. 0x71, 0xC9, 0x22, 0x18, 0x74, 0xF5, 0x0F, 0x5B,
  27190. 0x14, 0xBA, 0xAD, 0x59, 0x93, 0xB4, 0x92, 0x38,
  27191. 0xFD, 0x0A, 0x0C, 0x9F, 0x79, 0xB7, 0xB4, 0x58,
  27192. 0x4E, 0x41, 0x30, 0x1F, 0x7A, 0x88, 0x5C, 0x9F,
  27193. 0x91, 0x81, 0x9B, 0xEA, 0x00, 0xD5, 0x12, 0x58,
  27194. 0x17, 0x30, 0x53, 0x9F, 0xB3, 0x7E, 0x59, 0xE8,
  27195. 0x6A, 0x6D, 0x19, 0xCA, 0x25, 0xF0, 0xA8, 0x11,
  27196. 0xC9, 0xB4, 0x28, 0xBA, 0x86, 0x14, 0xAA, 0x4F,
  27197. 0x94, 0x80, 0x7B, 0xC0, 0x31, 0xCB, 0xCC, 0x18,
  27198. 0x3F, 0x3B, 0xF0, 0x7F, 0xE2, 0xC1, 0xA6, 0xEB,
  27199. 0xA8, 0x0D, 0x5A, 0x70, 0x6E, 0xE0, 0xDA, 0xB2,
  27200. 0x7E, 0x23, 0x14, 0x58, 0x02, 0x5D, 0x84, 0xA7,
  27201. 0xA9, 0xB0, 0x23, 0x05, 0x01, 0x11, 0x6C, 0x29,
  27202. 0x0A, 0x6B, 0xB5, 0x06, 0x26, 0xD9, 0x7B, 0x93,
  27203. 0x98, 0x50, 0x94, 0x28, 0x28, 0x39, 0x0B, 0x0A,
  27204. 0x20, 0x01, 0xB7, 0x85, 0x3A, 0xD1, 0xAE, 0x9B,
  27205. 0x01, 0x1B, 0x2D, 0xB3, 0x6C, 0xAE, 0xEA, 0x73,
  27206. 0xA2, 0x32, 0x8E, 0x3C, 0x56, 0x48, 0x5B, 0x49,
  27207. 0x1C, 0x29, 0x91, 0x15, 0xA0, 0x17, 0xC9, 0x07,
  27208. 0xAB, 0x54, 0x31, 0x72, 0x60, 0xA5, 0x93, 0xA0,
  27209. 0xD7, 0xBA, 0x6D, 0x06, 0x61, 0x5D, 0x6E, 0x2C,
  27210. 0xA8, 0x4B, 0x86, 0x0E, 0xFF, 0x3C, 0xCB, 0x59,
  27211. 0x72, 0x11, 0xBF, 0xE3, 0x6B, 0xDE, 0xF8, 0x06,
  27212. 0x9A, 0xFA, 0x36, 0xC5, 0xA7, 0x33, 0x92, 0x72,
  27213. 0x26, 0x50, 0xE4, 0x95, 0x7D, 0xCA, 0x59, 0x7A,
  27214. 0xCB, 0xA5, 0x60, 0x5B, 0x63, 0xC1, 0x63, 0xCF,
  27215. 0xA9, 0x4B, 0x64, 0xDD, 0xD6, 0x23, 0x01, 0xA4,
  27216. 0x33, 0x20, 0x83, 0x36, 0x19, 0x72, 0x58, 0x9D,
  27217. 0xB0, 0x59, 0x9A, 0x69, 0x4D, 0xD4, 0x54, 0x7A,
  27218. 0x5E, 0xE9, 0x19, 0x65, 0x77, 0xC2, 0x2E, 0xD4,
  27219. 0x27, 0xAC, 0x89, 0xBB, 0x8B, 0xA3, 0x75, 0x3E,
  27220. 0xB7, 0x6C, 0x41, 0xF2, 0xC1, 0x12, 0x9C, 0x8A,
  27221. 0x77, 0xD6, 0x80, 0x5F, 0xA7, 0x19, 0xB1, 0xB6,
  27222. 0xCA, 0x11, 0xB7, 0x40, 0xA7, 0x8A, 0x3D, 0x41,
  27223. 0xB5, 0x33, 0x05, 0x26, 0xAB, 0x87, 0xD5, 0x8D,
  27224. 0x59, 0x25, 0x31, 0x5A, 0x14, 0x85, 0xED, 0xC6,
  27225. 0x47, 0xC1, 0x60, 0x4E, 0xB3, 0x81, 0x38, 0xDE,
  27226. 0x63, 0x7A, 0xD2, 0xC6, 0xCA, 0x5B, 0xE4, 0x4E,
  27227. 0x10, 0x08, 0xB2, 0xC0, 0x86, 0x7B, 0x22, 0x9C,
  27228. 0xCC, 0x36, 0x61, 0x9E, 0x27, 0x58, 0xC4, 0xC2,
  27229. 0x02, 0x9E, 0xAE, 0xB2, 0x6E, 0x7A, 0x80, 0x3F,
  27230. 0xCA, 0x30, 0x5A, 0x59, 0xCD, 0x58, 0x5E, 0x11,
  27231. 0x7D, 0x69, 0x8E, 0xCE, 0x01, 0x1C, 0xC3, 0xFC,
  27232. 0xE5, 0x4D, 0x2E, 0x11, 0x45, 0x45, 0xA2, 0x1A,
  27233. 0xC5, 0xBE, 0x67, 0x71, 0xAB, 0x8F, 0x13, 0x12,
  27234. 0x2F, 0xAD, 0x29, 0x5E, 0x74, 0x5A, 0x50, 0x3B,
  27235. 0x14, 0x2F, 0x91, 0xAE, 0xF7, 0xBD, 0xE9, 0x99,
  27236. 0x98, 0x84, 0x5F, 0xDA, 0x04, 0x35, 0x55, 0xC9,
  27237. 0xC1, 0xEE, 0x53, 0x5B, 0xE1, 0x25, 0xE5, 0xDC,
  27238. 0xE5, 0xD2, 0x66, 0x66, 0x7E, 0x72, 0x3E, 0x67,
  27239. 0xB6, 0xBA, 0x89, 0x1C, 0x16, 0xCB, 0xA1, 0x74,
  27240. 0x09, 0x8A, 0x3F, 0x35, 0x17, 0x78, 0xB0, 0x88,
  27241. 0x8C, 0x95, 0x90, 0xA9, 0x09, 0x0C, 0xD4, 0x04
  27242. };
  27243. static const byte c_512[KYBER512_CIPHER_TEXT_SIZE] = {
  27244. 0x16, 0x1C, 0xD2, 0x59, 0xFE, 0xAA, 0x7E, 0xC6,
  27245. 0xB2, 0x86, 0x49, 0x8A, 0x9A, 0x6F, 0x69, 0xF8,
  27246. 0xB2, 0x62, 0xA2, 0xE2, 0x09, 0x3D, 0x0F, 0xBD,
  27247. 0x76, 0xD5, 0xDC, 0x1C, 0x9F, 0xDE, 0x0D, 0xED,
  27248. 0xB3, 0x65, 0x81, 0x00, 0x4C, 0xB4, 0x81, 0x12,
  27249. 0xF8, 0x52, 0xE7, 0xF8, 0x7F, 0x64, 0x9E, 0x8A,
  27250. 0x42, 0xCD, 0x9E, 0x03, 0x49, 0xE7, 0xDA, 0xBD,
  27251. 0xF0, 0xA9, 0xAC, 0x1B, 0x52, 0x1C, 0x37, 0xEA,
  27252. 0x52, 0x41, 0x37, 0x0A, 0x8A, 0xB2, 0x91, 0x1C,
  27253. 0xC7, 0x99, 0x02, 0xC9, 0x5D, 0x28, 0x22, 0x4F,
  27254. 0xA8, 0x89, 0x6A, 0xD7, 0x15, 0x20, 0x9E, 0xCD,
  27255. 0xD5, 0xD7, 0x84, 0xE9, 0x1D, 0xD9, 0xD0, 0xBE,
  27256. 0x91, 0x6B, 0x45, 0x65, 0xF4, 0xD5, 0x66, 0x9A,
  27257. 0xEE, 0x0D, 0xEF, 0x93, 0x1E, 0x97, 0x68, 0x29,
  27258. 0x4E, 0xEC, 0x52, 0x58, 0xDE, 0x83, 0x91, 0xEC,
  27259. 0xE2, 0x71, 0xE7, 0xE4, 0xCF, 0xD9, 0xD2, 0x3A,
  27260. 0x79, 0xFA, 0xC3, 0xA8, 0xE0, 0xDB, 0x5D, 0xDD,
  27261. 0x6E, 0x01, 0x07, 0x23, 0x56, 0x88, 0xBB, 0xDF,
  27262. 0x7B, 0xC5, 0xD5, 0x63, 0x2F, 0x20, 0x6C, 0x63,
  27263. 0xA0, 0xC9, 0x56, 0x4F, 0x30, 0x96, 0x5C, 0xA5,
  27264. 0x8C, 0x69, 0xFF, 0x92, 0xD2, 0x5A, 0x4F, 0x93,
  27265. 0xA0, 0x9E, 0xAB, 0x9B, 0x90, 0x85, 0x94, 0x7E,
  27266. 0x07, 0x8A, 0x23, 0xE4, 0xD9, 0xC1, 0x3B, 0x8A,
  27267. 0x56, 0xE7, 0x3E, 0x18, 0xDF, 0x42, 0xD6, 0x94,
  27268. 0x9F, 0xAF, 0x59, 0x21, 0xF2, 0xE3, 0x73, 0xD4,
  27269. 0x50, 0xC8, 0xC0, 0x9D, 0x07, 0xB1, 0x52, 0xA9,
  27270. 0x7C, 0x24, 0x54, 0x47, 0x42, 0x94, 0x81, 0xD4,
  27271. 0x98, 0xBE, 0xB7, 0x25, 0x6B, 0xC4, 0x7F, 0x68,
  27272. 0xF9, 0x92, 0x2B, 0x0B, 0x1C, 0x62, 0xD9, 0xC2,
  27273. 0x3F, 0x9F, 0x73, 0x3D, 0xD7, 0x37, 0x92, 0xCF,
  27274. 0xC7, 0xB4, 0x3C, 0xBC, 0xEA, 0x27, 0x7D, 0x51,
  27275. 0xB2, 0xB8, 0xAD, 0x4A, 0x4F, 0x52, 0x2F, 0x64,
  27276. 0x2C, 0xAD, 0x5C, 0x5D, 0xEB, 0x21, 0xF3, 0x62,
  27277. 0x7F, 0x8A, 0xF4, 0xD3, 0xE5, 0xBC, 0x9E, 0x91,
  27278. 0xD4, 0xCB, 0x2F, 0x12, 0x4B, 0x5B, 0xD7, 0xC2,
  27279. 0xF4, 0xA0, 0x50, 0xCA, 0x75, 0x5B, 0xDB, 0x80,
  27280. 0x56, 0x60, 0x96, 0x63, 0xFB, 0x95, 0x11, 0xC9,
  27281. 0xAD, 0x83, 0xB5, 0x03, 0x90, 0x88, 0xCC, 0x01,
  27282. 0xF0, 0xDD, 0x54, 0x35, 0x3B, 0x0D, 0xD7, 0x43,
  27283. 0x3F, 0x0C, 0x6C, 0xEE, 0x0D, 0x07, 0x59, 0x59,
  27284. 0x81, 0x0D, 0xEC, 0x54, 0x16, 0x52, 0x2B, 0xB1,
  27285. 0xF1, 0xF6, 0x55, 0x47, 0xA0, 0xC2, 0xE9, 0xCC,
  27286. 0x9B, 0xC1, 0x7F, 0x8D, 0x39, 0xD2, 0x93, 0x09,
  27287. 0xEB, 0xE7, 0x9F, 0x21, 0x33, 0x1B, 0x75, 0xE1,
  27288. 0x2A, 0xF2, 0xE9, 0x3F, 0x03, 0xF7, 0x4F, 0x7F,
  27289. 0x87, 0xD3, 0x60, 0xF1, 0xDA, 0xF8, 0x6C, 0xED,
  27290. 0x73, 0x60, 0x92, 0xA2, 0x11, 0xA8, 0x15, 0x88,
  27291. 0x59, 0xC4, 0x2E, 0x22, 0x3C, 0xFE, 0x2E, 0x6E,
  27292. 0x55, 0x34, 0x37, 0xD8, 0x05, 0x76, 0xCF, 0xD1,
  27293. 0x94, 0x4E, 0x97, 0xEE, 0xFF, 0x9B, 0x49, 0xE5,
  27294. 0xEC, 0xCF, 0xC6, 0x78, 0xEE, 0x16, 0x52, 0x68,
  27295. 0xDF, 0xE3, 0xD3, 0x59, 0x6B, 0x4B, 0x86, 0x20,
  27296. 0x4A, 0x81, 0xC6, 0x06, 0x3B, 0x0C, 0xDC, 0xE6,
  27297. 0x19, 0xFD, 0xBB, 0x96, 0xDF, 0x7D, 0xE6, 0xE0,
  27298. 0xBD, 0x52, 0x70, 0xB4, 0xD5, 0x9C, 0x4D, 0xC5,
  27299. 0x08, 0x47, 0x6E, 0x7F, 0x07, 0x08, 0xF9, 0x8C,
  27300. 0x7A, 0x4F, 0x66, 0x45, 0xC4, 0x9D, 0x06, 0x10,
  27301. 0x0C, 0x76, 0x0C, 0x59, 0x95, 0x28, 0xD1, 0xB8,
  27302. 0xBB, 0xFE, 0x62, 0x81, 0x91, 0xCC, 0x08, 0x3C,
  27303. 0x8D, 0x22, 0x5A, 0x09, 0x3F, 0x9F, 0x17, 0xE3,
  27304. 0x55, 0x74, 0x98, 0x6F, 0x86, 0xBA, 0xA4, 0x68,
  27305. 0x98, 0xB5, 0x89, 0xF3, 0xCB, 0x7D, 0xB4, 0x6A,
  27306. 0x45, 0xF3, 0xED, 0xD4, 0xFA, 0xC2, 0x08, 0x08,
  27307. 0xF4, 0xCD, 0x02, 0x49, 0xDA, 0x69, 0x3F, 0x8F,
  27308. 0xAB, 0xFB, 0xD4, 0xE1, 0x0C, 0x02, 0xC6, 0x5B,
  27309. 0xA8, 0xC8, 0x61, 0x0F, 0xA8, 0xC6, 0xDF, 0x3D,
  27310. 0xBA, 0xEB, 0x67, 0x63, 0xDD, 0x48, 0x2A, 0xF4,
  27311. 0x15, 0x58, 0xB1, 0xE1, 0x5C, 0xC9, 0xC7, 0xA7,
  27312. 0x2E, 0x07, 0x16, 0x85, 0xAC, 0x19, 0xA0, 0x51,
  27313. 0xF1, 0x92, 0x45, 0xB9, 0xF7, 0x7C, 0x30, 0x38,
  27314. 0xA5, 0x4E, 0x29, 0x58, 0x62, 0x3E, 0xB8, 0x10,
  27315. 0x59, 0x55, 0x60, 0x9E, 0x27, 0xD6, 0x7C, 0xF7,
  27316. 0x2E, 0xC5, 0xC4, 0xA8, 0xE9, 0xB9, 0xC2, 0x92,
  27317. 0x4A, 0x9E, 0x22, 0x98, 0x50, 0x8B, 0xAB, 0xA1,
  27318. 0x3C, 0xF1, 0x11, 0xFD, 0xFB, 0x06, 0x2C, 0x96,
  27319. 0x07, 0xAC, 0x1A, 0xAA, 0x6C, 0x63, 0x73, 0x10,
  27320. 0xA8, 0x89, 0x4B, 0xF0, 0xB9, 0x6F, 0x0C, 0x19,
  27321. 0x13, 0x61, 0x86, 0xB6, 0x18, 0xDF, 0xFB, 0x27,
  27322. 0x55, 0x28, 0xBE, 0xD1, 0xCC, 0x27, 0x15, 0xDE,
  27323. 0xF4, 0x12, 0xF7, 0x7A, 0x3C, 0xF9, 0x66, 0x45,
  27324. 0x73, 0x3B, 0x04, 0x8A, 0x78, 0x47, 0x43, 0x20,
  27325. 0xD1, 0xA3, 0x80, 0xF5, 0xEE, 0xDB, 0xDA, 0x21,
  27326. 0xFA, 0x01, 0x25, 0xC9, 0x1D, 0x3C, 0x37, 0xC5,
  27327. 0x4B, 0xF3, 0x75, 0x2A, 0x1F, 0x84, 0x71, 0xC8,
  27328. 0x1F, 0xCA, 0xE2, 0xD3, 0xED, 0xA9, 0x66, 0xE1,
  27329. 0x4E, 0x66, 0xF2, 0x23, 0xB0, 0x54, 0xD7, 0x98,
  27330. 0x48, 0xFF, 0x94, 0x11, 0xD6, 0x34, 0x02, 0x4A,
  27331. 0x09, 0x89, 0x70, 0xAD, 0xE6, 0xA8, 0x8B, 0x5F,
  27332. 0x90, 0x69, 0xF7, 0x60, 0x58, 0x4D, 0xC4, 0xCF,
  27333. 0xFF, 0xCE, 0xA8, 0xEC, 0xE1, 0x1B, 0xB5, 0x56,
  27334. 0x6B, 0xD2, 0x36, 0x0A, 0xB7, 0x07, 0xDF, 0x2D,
  27335. 0x21, 0xB6, 0x74, 0x88, 0xD9, 0x31, 0xF0, 0x20,
  27336. 0x06, 0x91, 0x76, 0x42, 0x3E, 0x69, 0x44, 0x49,
  27337. 0x0C, 0xB3, 0x85, 0xE7, 0x0B, 0x35, 0x8A, 0x25,
  27338. 0x34, 0x6B, 0xAF, 0xCD, 0xD0, 0x6D, 0x40, 0x2F,
  27339. 0xF2, 0x4D, 0x6C, 0x1E, 0x5F, 0x61, 0xA8, 0x5D
  27340. };
  27341. static const byte kprime_512[KYBER_SS_SZ] = {
  27342. 0xDF, 0x46, 0x2A, 0xD6, 0x8F, 0x1E, 0xC8, 0x97,
  27343. 0x2E, 0xD9, 0xB0, 0x2D, 0x6D, 0xE0, 0x60, 0x4B,
  27344. 0xDE, 0xC7, 0x57, 0x20, 0xE0, 0x50, 0x49, 0x73,
  27345. 0x51, 0xE6, 0xEC, 0x93, 0x3E, 0x71, 0xF8, 0x82
  27346. };
  27347. #endif
  27348. #ifndef WOLFSSL_NO_KYBER768
  27349. static const byte dk_768[KYBER768_PRIVATE_KEY_SIZE] = {
  27350. 0x1E, 0x4A, 0xC8, 0x7B, 0x1A, 0x69, 0x2A, 0x52,
  27351. 0x9F, 0xDB, 0xBA, 0xB9, 0x33, 0x74, 0xC5, 0x7D,
  27352. 0x11, 0x0B, 0x10, 0xF2, 0xB1, 0xDD, 0xEB, 0xAC,
  27353. 0x0D, 0x19, 0x6B, 0x7B, 0xA6, 0x31, 0xB8, 0xE9,
  27354. 0x29, 0x30, 0x28, 0xA8, 0xF3, 0x79, 0x88, 0x8C,
  27355. 0x42, 0x2D, 0xC8, 0xD3, 0x2B, 0xBF, 0x22, 0x60,
  27356. 0x10, 0xC2, 0xC1, 0xEC, 0x73, 0x18, 0x90, 0x80,
  27357. 0x45, 0x6B, 0x05, 0x64, 0xB2, 0x58, 0xB0, 0xF2,
  27358. 0x31, 0x31, 0xBC, 0x79, 0xC8, 0xE8, 0xC1, 0x1C,
  27359. 0xEF, 0x39, 0x38, 0xB2, 0x43, 0xC5, 0xCE, 0x9C,
  27360. 0x0E, 0xDD, 0x37, 0xC8, 0xF9, 0xD2, 0x98, 0x77,
  27361. 0xDB, 0xBB, 0x61, 0x5B, 0x9B, 0x5A, 0xC3, 0xC9,
  27362. 0x48, 0x48, 0x7E, 0x46, 0x71, 0x96, 0xA9, 0x14,
  27363. 0x3E, 0xFB, 0xC7, 0xCE, 0xDB, 0x64, 0xB4, 0x5D,
  27364. 0x4A, 0xCD, 0xA2, 0x66, 0x6C, 0xBC, 0x28, 0x04,
  27365. 0xF2, 0xC8, 0x66, 0x2E, 0x12, 0x8F, 0x6A, 0x99,
  27366. 0x69, 0xEC, 0x15, 0xBC, 0x0B, 0x93, 0x51, 0xF6,
  27367. 0xF9, 0x63, 0x46, 0xAA, 0x7A, 0xBC, 0x74, 0x3A,
  27368. 0x14, 0xFA, 0x03, 0x0E, 0x37, 0xA2, 0xE7, 0x59,
  27369. 0x7B, 0xDD, 0xFC, 0x5A, 0x22, 0xF9, 0xCE, 0xDA,
  27370. 0xF8, 0x61, 0x48, 0x32, 0x52, 0x72, 0x10, 0xB2,
  27371. 0x6F, 0x02, 0x4C, 0x7F, 0x6C, 0x0D, 0xCF, 0x55,
  27372. 0x1E, 0x97, 0xA4, 0x85, 0x87, 0x64, 0xC3, 0x21,
  27373. 0xD1, 0x83, 0x4A, 0xD5, 0x1D, 0x75, 0xBB, 0x24,
  27374. 0x6D, 0x27, 0x72, 0x37, 0xB7, 0xBD, 0x41, 0xDC,
  27375. 0x43, 0x62, 0xD0, 0x63, 0xF4, 0x29, 0x82, 0x92,
  27376. 0x27, 0x2D, 0x01, 0x01, 0x17, 0x80, 0xB7, 0x98,
  27377. 0x56, 0xB2, 0x96, 0xC4, 0xE9, 0x46, 0x65, 0x8B,
  27378. 0x79, 0x60, 0x31, 0x97, 0xC9, 0xB2, 0xA9, 0x9E,
  27379. 0xC6, 0x6A, 0xCB, 0x06, 0xCE, 0x2F, 0x69, 0xB5,
  27380. 0xA5, 0xA6, 0x1E, 0x9B, 0xD0, 0x6A, 0xD4, 0x43,
  27381. 0xCE, 0xB0, 0xC7, 0x4E, 0xD6, 0x53, 0x45, 0xA9,
  27382. 0x03, 0xB6, 0x14, 0xE8, 0x13, 0x68, 0xAA, 0xC2,
  27383. 0xB3, 0xD2, 0xA7, 0x9C, 0xA8, 0xCC, 0xAA, 0x1C,
  27384. 0x3B, 0x88, 0xFB, 0x82, 0xA3, 0x66, 0x32, 0x86,
  27385. 0x0B, 0x3F, 0x79, 0x50, 0x83, 0x3F, 0xD0, 0x21,
  27386. 0x2E, 0xC9, 0x6E, 0xDE, 0x4A, 0xB6, 0xF5, 0xA0,
  27387. 0xBD, 0xA3, 0xEC, 0x60, 0x60, 0xA6, 0x58, 0xF9,
  27388. 0x45, 0x7F, 0x6C, 0xC8, 0x7C, 0x6B, 0x62, 0x0C,
  27389. 0x1A, 0x14, 0x51, 0x98, 0x74, 0x86, 0xE4, 0x96,
  27390. 0x61, 0x2A, 0x10, 0x1D, 0x0E, 0x9C, 0x20, 0x57,
  27391. 0x7C, 0x57, 0x1E, 0xDB, 0x52, 0x82, 0x60, 0x8B,
  27392. 0xF4, 0xE1, 0xAC, 0x92, 0x6C, 0x0D, 0xB1, 0xC8,
  27393. 0x2A, 0x50, 0x4A, 0x79, 0x9D, 0x89, 0x88, 0x5C,
  27394. 0xA6, 0x25, 0x2B, 0xD5, 0xB1, 0xC1, 0x83, 0xAF,
  27395. 0x70, 0x13, 0x92, 0xA4, 0x07, 0xC0, 0x5B, 0x84,
  27396. 0x8C, 0x2A, 0x30, 0x16, 0xC4, 0x06, 0x13, 0xF0,
  27397. 0x2A, 0x44, 0x9B, 0x3C, 0x79, 0x26, 0xDA, 0x06,
  27398. 0x7A, 0x53, 0x31, 0x16, 0x50, 0x68, 0x40, 0x09,
  27399. 0x75, 0x10, 0x46, 0x0B, 0xBF, 0xD3, 0x60, 0x73,
  27400. 0xDC, 0xB0, 0xBF, 0xA0, 0x09, 0xB3, 0x6A, 0x91,
  27401. 0x23, 0xEA, 0xA6, 0x8F, 0x83, 0x5F, 0x74, 0xA0,
  27402. 0x1B, 0x00, 0xD2, 0x09, 0x78, 0x35, 0x96, 0x4D,
  27403. 0xF5, 0x21, 0xCE, 0x92, 0x10, 0x78, 0x9C, 0x30,
  27404. 0xB7, 0xF0, 0x6E, 0x58, 0x44, 0xB4, 0x44, 0xC5,
  27405. 0x33, 0x22, 0x39, 0x6E, 0x47, 0x99, 0xBA, 0xF6,
  27406. 0xA8, 0x8A, 0xF7, 0x31, 0x58, 0x60, 0xD0, 0x19,
  27407. 0x2D, 0x48, 0xC2, 0xC0, 0xDA, 0x6B, 0x5B, 0xA6,
  27408. 0x43, 0x25, 0x54, 0x3A, 0xCD, 0xF5, 0x90, 0x0E,
  27409. 0x8B, 0xC4, 0x77, 0xAB, 0x05, 0x82, 0x00, 0x72,
  27410. 0xD4, 0x63, 0xAF, 0xFE, 0xD0, 0x97, 0xE0, 0x62,
  27411. 0xBD, 0x78, 0xC9, 0x9D, 0x12, 0xB3, 0x85, 0x13,
  27412. 0x1A, 0x24, 0x1B, 0x70, 0x88, 0x65, 0xB4, 0x19,
  27413. 0x0A, 0xF6, 0x9E, 0xA0, 0xA6, 0x4D, 0xB7, 0x14,
  27414. 0x48, 0xA6, 0x08, 0x29, 0x36, 0x9C, 0x75, 0x55,
  27415. 0x19, 0x8E, 0x43, 0x8C, 0x9A, 0xBC, 0x31, 0x0B,
  27416. 0xC7, 0x01, 0x01, 0x91, 0x3B, 0xB1, 0x2F, 0xAA,
  27417. 0x5B, 0xEE, 0xF9, 0x75, 0x84, 0x16, 0x17, 0xC8,
  27418. 0x47, 0xCD, 0x6B, 0x33, 0x6F, 0x87, 0x79, 0x87,
  27419. 0x75, 0x38, 0x22, 0x02, 0x0B, 0x92, 0xC4, 0xCC,
  27420. 0x97, 0x05, 0x5C, 0x9B, 0x1E, 0x0B, 0x12, 0x8B,
  27421. 0xF1, 0x1F, 0x50, 0x50, 0x05, 0xB6, 0xAB, 0x0E,
  27422. 0x62, 0x77, 0x95, 0xA2, 0x06, 0x09, 0xEF, 0xA9,
  27423. 0x91, 0xE5, 0x98, 0xB8, 0x0F, 0x37, 0xB1, 0xC6,
  27424. 0xA1, 0xC3, 0xA1, 0xE9, 0xAE, 0xE7, 0x02, 0x8F,
  27425. 0x77, 0x57, 0x0A, 0xB2, 0x13, 0x91, 0x28, 0xA0,
  27426. 0x01, 0x08, 0xC5, 0x0E, 0xB3, 0x05, 0xCD, 0xB8,
  27427. 0xF9, 0xA6, 0x03, 0xA6, 0xB0, 0x78, 0x41, 0x3F,
  27428. 0x6F, 0x9B, 0x14, 0xC6, 0xD8, 0x2B, 0x51, 0x99,
  27429. 0xCE, 0x59, 0xD8, 0x87, 0x90, 0x2A, 0x28, 0x1A,
  27430. 0x02, 0x7B, 0x71, 0x74, 0x95, 0xFE, 0x12, 0x67,
  27431. 0x2A, 0x12, 0x7B, 0xBF, 0x9B, 0x25, 0x6C, 0x43,
  27432. 0x72, 0x0D, 0x7C, 0x16, 0x0B, 0x28, 0x1C, 0x12,
  27433. 0x75, 0x7D, 0xA1, 0x35, 0xB1, 0x93, 0x33, 0x52,
  27434. 0xBE, 0x4A, 0xB6, 0x7E, 0x40, 0x24, 0x8A, 0xFC,
  27435. 0x31, 0x8E, 0x23, 0x70, 0xC3, 0xB8, 0x20, 0x8E,
  27436. 0x69, 0x5B, 0xDF, 0x33, 0x74, 0x59, 0xB9, 0xAC,
  27437. 0xBF, 0xE5, 0xB4, 0x87, 0xF7, 0x6E, 0x9B, 0x4B,
  27438. 0x40, 0x01, 0xD6, 0xCF, 0x90, 0xCA, 0x8C, 0x69,
  27439. 0x9A, 0x17, 0x4D, 0x42, 0x97, 0x2D, 0xC7, 0x33,
  27440. 0xF3, 0x33, 0x89, 0xFD, 0xF5, 0x9A, 0x1D, 0xAB,
  27441. 0xA8, 0x1D, 0x83, 0x49, 0x55, 0x02, 0x73, 0x34,
  27442. 0x18, 0x5A, 0xD0, 0x2C, 0x76, 0xCF, 0x29, 0x48,
  27443. 0x46, 0xCA, 0x92, 0x94, 0xBA, 0x0E, 0xD6, 0x67,
  27444. 0x41, 0xDD, 0xEC, 0x79, 0x1C, 0xAB, 0x34, 0x19,
  27445. 0x6A, 0xC5, 0x65, 0x7C, 0x5A, 0x78, 0x32, 0x1B,
  27446. 0x56, 0xC3, 0x33, 0x06, 0xB5, 0x10, 0x23, 0x97,
  27447. 0xA5, 0xC0, 0x9C, 0x35, 0x08, 0xF7, 0x6B, 0x48,
  27448. 0x28, 0x24, 0x59, 0xF8, 0x1D, 0x0C, 0x72, 0xA4,
  27449. 0x3F, 0x73, 0x7B, 0xC2, 0xF1, 0x2F, 0x45, 0x42,
  27450. 0x26, 0x28, 0xB6, 0x7D, 0xB5, 0x1A, 0xC1, 0x42,
  27451. 0x42, 0x76, 0xA6, 0xC0, 0x8C, 0x3F, 0x76, 0x15,
  27452. 0x66, 0x5B, 0xBB, 0x8E, 0x92, 0x81, 0x48, 0xA2,
  27453. 0x70, 0xF9, 0x91, 0xBC, 0xF3, 0x65, 0xA9, 0x0F,
  27454. 0x87, 0xC3, 0x06, 0x87, 0xB6, 0x88, 0x09, 0xC9,
  27455. 0x1F, 0x23, 0x18, 0x13, 0xB8, 0x66, 0xBE, 0xA8,
  27456. 0x2E, 0x30, 0x37, 0x4D, 0x80, 0xAA, 0x0C, 0x02,
  27457. 0x97, 0x34, 0x37, 0x49, 0x8A, 0x53, 0xB1, 0x4B,
  27458. 0xF6, 0xB6, 0xCA, 0x1E, 0xD7, 0x6A, 0xB8, 0xA2,
  27459. 0x0D, 0x54, 0xA0, 0x83, 0xF4, 0xA2, 0x6B, 0x7C,
  27460. 0x03, 0x8D, 0x81, 0x96, 0x76, 0x40, 0xC2, 0x0B,
  27461. 0xF4, 0x43, 0x1E, 0x71, 0xDA, 0xCC, 0xE8, 0x57,
  27462. 0x7B, 0x21, 0x24, 0x0E, 0x49, 0x4C, 0x31, 0xF2,
  27463. 0xD8, 0x77, 0xDA, 0xF4, 0x92, 0x4F, 0xD3, 0x9D,
  27464. 0x82, 0xD6, 0x16, 0x7F, 0xBC, 0xC1, 0xF9, 0xC5,
  27465. 0xA2, 0x59, 0xF8, 0x43, 0xE3, 0x09, 0x87, 0xCC,
  27466. 0xC4, 0xBC, 0xE7, 0x49, 0x3A, 0x24, 0x04, 0xB5,
  27467. 0xE4, 0x43, 0x87, 0xF7, 0x07, 0x42, 0x57, 0x81,
  27468. 0xB7, 0x43, 0xFB, 0x55, 0x56, 0x85, 0x58, 0x4E,
  27469. 0x25, 0x57, 0xCC, 0x03, 0x8B, 0x1A, 0x9B, 0x3F,
  27470. 0x40, 0x43, 0x12, 0x1F, 0x54, 0x72, 0xEB, 0x2B,
  27471. 0x96, 0xE5, 0x94, 0x1F, 0xEC, 0x01, 0x1C, 0xEE,
  27472. 0xA5, 0x07, 0x91, 0x63, 0x6C, 0x6A, 0xBC, 0x26,
  27473. 0xC1, 0x37, 0x7E, 0xE3, 0xB5, 0x14, 0x6F, 0xC7,
  27474. 0xC8, 0x5C, 0xB3, 0x35, 0xB1, 0xE7, 0x95, 0xEE,
  27475. 0xC2, 0x03, 0x3E, 0xE4, 0x4B, 0x9A, 0xA9, 0x06,
  27476. 0x85, 0x24, 0x5E, 0xF7, 0xB4, 0x43, 0x6C, 0x00,
  27477. 0x0E, 0x66, 0xBC, 0x8B, 0xCB, 0xF1, 0xCD, 0xB8,
  27478. 0x03, 0xAC, 0x14, 0x21, 0xB1, 0xFD, 0xB2, 0x66,
  27479. 0xD5, 0x29, 0x1C, 0x83, 0x10, 0x37, 0x3A, 0x8A,
  27480. 0x3C, 0xE9, 0x56, 0x2A, 0xB1, 0x97, 0x95, 0x38,
  27481. 0x71, 0xAB, 0x99, 0xF3, 0x82, 0xCC, 0x5A, 0xA9,
  27482. 0xC0, 0xF2, 0x73, 0xD1, 0xDC, 0xA5, 0x5D, 0x27,
  27483. 0x12, 0x85, 0x38, 0x71, 0xE1, 0xA8, 0x3C, 0xB3,
  27484. 0xB8, 0x54, 0x50, 0xF7, 0x6D, 0x3F, 0x3C, 0x42,
  27485. 0xBA, 0xB5, 0x50, 0x5F, 0x72, 0x12, 0xFD, 0xB6,
  27486. 0xB8, 0xB7, 0xF6, 0x02, 0x99, 0x72, 0xA8, 0xF3,
  27487. 0x75, 0x1E, 0x4C, 0x94, 0xC1, 0x10, 0x8B, 0x02,
  27488. 0xD6, 0xAC, 0x79, 0xF8, 0xD9, 0x38, 0xF0, 0x5A,
  27489. 0x1B, 0x2C, 0x22, 0x9B, 0x14, 0xB4, 0x2B, 0x31,
  27490. 0xB0, 0x1A, 0x36, 0x40, 0x17, 0xE5, 0x95, 0x78,
  27491. 0xC6, 0xB0, 0x33, 0x83, 0x37, 0x74, 0xCB, 0x9B,
  27492. 0x57, 0x0F, 0x90, 0x86, 0xB7, 0x22, 0x90, 0x3B,
  27493. 0x37, 0x54, 0x46, 0xB4, 0x95, 0xD8, 0xA2, 0x9B,
  27494. 0xF8, 0x07, 0x51, 0x87, 0x7A, 0x80, 0xFB, 0x72,
  27495. 0x4A, 0x02, 0x10, 0xC3, 0xE1, 0x69, 0x2F, 0x39,
  27496. 0x7C, 0x2F, 0x1D, 0xDC, 0x2E, 0x6B, 0xA1, 0x7A,
  27497. 0xF8, 0x1B, 0x92, 0xAC, 0xFA, 0xBE, 0xF5, 0xF7,
  27498. 0x57, 0x3C, 0xB4, 0x93, 0xD1, 0x84, 0x02, 0x7B,
  27499. 0x71, 0x82, 0x38, 0xC8, 0x9A, 0x35, 0x49, 0xB8,
  27500. 0x90, 0x5B, 0x28, 0xA8, 0x33, 0x62, 0x86, 0x7C,
  27501. 0x08, 0x2D, 0x30, 0x19, 0xD3, 0xCA, 0x70, 0x70,
  27502. 0x07, 0x31, 0xCE, 0xB7, 0x3E, 0x84, 0x72, 0xC1,
  27503. 0xA3, 0xA0, 0x93, 0x36, 0x1C, 0x5F, 0xEA, 0x6A,
  27504. 0x7D, 0x40, 0x95, 0x5D, 0x07, 0xA4, 0x1B, 0x64,
  27505. 0xE5, 0x00, 0x81, 0xA3, 0x61, 0xB6, 0x04, 0xCC,
  27506. 0x51, 0x84, 0x47, 0xC8, 0xE2, 0x57, 0x65, 0xAB,
  27507. 0x7D, 0x68, 0xB2, 0x43, 0x27, 0x52, 0x07, 0xAF,
  27508. 0x8C, 0xA6, 0x56, 0x4A, 0x4C, 0xB1, 0xE9, 0x41,
  27509. 0x99, 0xDB, 0xA1, 0x87, 0x8C, 0x59, 0xBE, 0xC8,
  27510. 0x09, 0xAB, 0x48, 0xB2, 0xF2, 0x11, 0xBA, 0xDC,
  27511. 0x6A, 0x19, 0x98, 0xD9, 0xC7, 0x22, 0x7C, 0x13,
  27512. 0x03, 0xF4, 0x69, 0xD4, 0x6A, 0x9C, 0x7E, 0x53,
  27513. 0x03, 0xF9, 0x8A, 0xBA, 0x67, 0x56, 0x9A, 0xE8,
  27514. 0x22, 0x7C, 0x16, 0xBA, 0x1F, 0xB3, 0x24, 0x44,
  27515. 0x66, 0xA2, 0x5E, 0x7F, 0x82, 0x36, 0x71, 0x81,
  27516. 0x0C, 0xC2, 0x62, 0x06, 0xFE, 0xB2, 0x9C, 0x7E,
  27517. 0x2A, 0x1A, 0x91, 0x95, 0x9E, 0xEB, 0x03, 0xA9,
  27518. 0x82, 0x52, 0xA4, 0xF7, 0x41, 0x26, 0x74, 0xEB,
  27519. 0x9A, 0x4B, 0x27, 0x7E, 0x1F, 0x25, 0x95, 0xFC,
  27520. 0xA6, 0x40, 0x33, 0xB4, 0x1B, 0x40, 0x33, 0x08,
  27521. 0x12, 0xE9, 0x73, 0x5B, 0x7C, 0x60, 0x75, 0x01,
  27522. 0xCD, 0x81, 0x83, 0xA2, 0x2A, 0xFC, 0x33, 0x92,
  27523. 0x55, 0x37, 0x44, 0xF3, 0x3C, 0x4D, 0x20, 0x25,
  27524. 0x26, 0x94, 0x5C, 0x6D, 0x78, 0xA6, 0x0E, 0x20,
  27525. 0x1A, 0x16, 0x98, 0x7A, 0x6F, 0xA5, 0x9D, 0x94,
  27526. 0x46, 0x4B, 0x56, 0x50, 0x65, 0x56, 0x78, 0x48,
  27527. 0x24, 0xA0, 0x70, 0x58, 0xF5, 0x73, 0x20, 0xE7,
  27528. 0x6C, 0x82, 0x5B, 0x93, 0x47, 0xF2, 0x93, 0x6F,
  27529. 0x4A, 0x0E, 0x5C, 0xDA, 0xA1, 0x8C, 0xF8, 0x83,
  27530. 0x39, 0x45, 0xAE, 0x31, 0x2A, 0x36, 0xB5, 0xF5,
  27531. 0xA3, 0x81, 0x0A, 0xAC, 0x82, 0x38, 0x1F, 0xDA,
  27532. 0xE4, 0xCB, 0x9C, 0x68, 0x31, 0xD8, 0xEB, 0x8A,
  27533. 0xBA, 0xB8, 0x50, 0x41, 0x64, 0x43, 0xD7, 0x39,
  27534. 0x08, 0x6B, 0x1C, 0x32, 0x6F, 0xC2, 0xA3, 0x97,
  27535. 0x57, 0x04, 0xE3, 0x96, 0xA5, 0x96, 0x80, 0xC3,
  27536. 0xB5, 0xF3, 0x60, 0xF5, 0x48, 0x0D, 0x2B, 0x62,
  27537. 0x16, 0x9C, 0xD9, 0x4C, 0xA7, 0x1B, 0x37, 0xBC,
  27538. 0x58, 0x78, 0xBA, 0x29, 0x85, 0xE0, 0x68, 0xBA,
  27539. 0x05, 0x0B, 0x2C, 0xE5, 0x07, 0x26, 0xD4, 0xB4,
  27540. 0x45, 0x1B, 0x77, 0xAA, 0xA8, 0x67, 0x6E, 0xAE,
  27541. 0x09, 0x49, 0x82, 0x21, 0x01, 0x92, 0x19, 0x7B,
  27542. 0x1E, 0x92, 0xA2, 0x7F, 0x59, 0x86, 0x8B, 0x78,
  27543. 0x86, 0x78, 0x87, 0xB9, 0xA7, 0x0C, 0x32, 0xAF,
  27544. 0x84, 0x63, 0x0A, 0xA9, 0x08, 0x81, 0x43, 0x79,
  27545. 0xE6, 0x51, 0x91, 0x50, 0xBA, 0x16, 0x43, 0x9B,
  27546. 0x5E, 0x2B, 0x06, 0x03, 0xD0, 0x6A, 0xA6, 0x67,
  27547. 0x45, 0x57, 0xF5, 0xB0, 0x98, 0x3E, 0x5C, 0xB6,
  27548. 0xA9, 0x75, 0x96, 0x06, 0x9B, 0x01, 0xBB, 0x31,
  27549. 0x28, 0xC4, 0x16, 0x68, 0x06, 0x57, 0x20, 0x4F,
  27550. 0xD0, 0x76, 0x40, 0x39, 0x2E, 0x16, 0xB1, 0x9F,
  27551. 0x33, 0x7A, 0x99, 0xA3, 0x04, 0x84, 0x4E, 0x1A,
  27552. 0xA4, 0x74, 0xE9, 0xC7, 0x99, 0x06, 0x29, 0x71,
  27553. 0xF6, 0x72, 0x26, 0x89, 0x60, 0xF5, 0xA8, 0x2F,
  27554. 0x95, 0x00, 0x70, 0xBB, 0xE9, 0xC2, 0xA7, 0x19,
  27555. 0x50, 0xA3, 0x78, 0x5B, 0xDF, 0x0B, 0x84, 0x40,
  27556. 0x25, 0x5E, 0xD6, 0x39, 0x28, 0xD2, 0x57, 0x84,
  27557. 0x51, 0x68, 0xB1, 0xEC, 0xCC, 0x41, 0x91, 0x32,
  27558. 0x5A, 0xA7, 0x66, 0x45, 0x71, 0x9B, 0x28, 0xEB,
  27559. 0xD8, 0x93, 0x02, 0xDC, 0x67, 0x23, 0xC7, 0x86,
  27560. 0xDF, 0x52, 0x17, 0xB2, 0x43, 0x09, 0x9C, 0xA7,
  27561. 0x82, 0x38, 0xE5, 0x7E, 0x64, 0x69, 0x2F, 0x20,
  27562. 0x6B, 0x17, 0x7A, 0xBC, 0x25, 0x96, 0x60, 0x39,
  27563. 0x5C, 0xD7, 0x86, 0x0F, 0xB3, 0x5A, 0x16, 0xF6,
  27564. 0xB2, 0xFE, 0x65, 0x48, 0xC8, 0x5A, 0xB6, 0x63,
  27565. 0x30, 0xC5, 0x17, 0xFA, 0x74, 0xCD, 0xF3, 0xCB,
  27566. 0x49, 0xD2, 0x6B, 0x11, 0x81, 0x90, 0x1A, 0xF7,
  27567. 0x75, 0xA1, 0xE1, 0x80, 0x81, 0x3B, 0x6A, 0x24,
  27568. 0xC4, 0x56, 0x82, 0x9B, 0x5C, 0x38, 0x10, 0x4E,
  27569. 0xCE, 0x43, 0xC7, 0x6A, 0x43, 0x7A, 0x6A, 0x33,
  27570. 0xB6, 0xFC, 0x6C, 0x5E, 0x65, 0xC8, 0xA8, 0x94,
  27571. 0x66, 0xC1, 0x42, 0x54, 0x85, 0xB2, 0x9B, 0x9E,
  27572. 0x18, 0x54, 0x36, 0x8A, 0xFC, 0xA3, 0x53, 0xE1,
  27573. 0x43, 0xD0, 0xA9, 0x0A, 0x6C, 0x6C, 0x9E, 0x7F,
  27574. 0xDB, 0x62, 0xA6, 0x06, 0x85, 0x6B, 0x56, 0x14,
  27575. 0xF1, 0x2B, 0x64, 0xB7, 0x96, 0x02, 0x0C, 0x35,
  27576. 0x34, 0xC3, 0x60, 0x5C, 0xFD, 0xC7, 0x3B, 0x86,
  27577. 0x71, 0x4F, 0x41, 0x18, 0x50, 0x22, 0x8A, 0x28,
  27578. 0xB8, 0xF4, 0xB4, 0x9E, 0x66, 0x34, 0x16, 0xC8,
  27579. 0x4F, 0x7E, 0x38, 0x1F, 0x6A, 0xF1, 0x07, 0x13,
  27580. 0x43, 0xBF, 0x9D, 0x39, 0xB4, 0x54, 0x39, 0x24,
  27581. 0x0C, 0xC0, 0x38, 0x97, 0x29, 0x5F, 0xEA, 0x08,
  27582. 0x0B, 0x14, 0xBB, 0x2D, 0x81, 0x19, 0xA8, 0x80,
  27583. 0xE1, 0x64, 0x49, 0x5C, 0x61, 0xBE, 0xBC, 0x71,
  27584. 0x39, 0xC1, 0x18, 0x57, 0xC8, 0x5E, 0x17, 0x50,
  27585. 0x33, 0x8D, 0x63, 0x43, 0x91, 0x37, 0x06, 0xA5,
  27586. 0x07, 0xC9, 0x56, 0x64, 0x64, 0xCD, 0x28, 0x37,
  27587. 0xCF, 0x91, 0x4D, 0x1A, 0x3C, 0x35, 0xE8, 0x9B,
  27588. 0x23, 0x5C, 0x6A, 0xB7, 0xED, 0x07, 0x8B, 0xED,
  27589. 0x23, 0x47, 0x57, 0xC0, 0x2E, 0xF6, 0x99, 0x3D,
  27590. 0x4A, 0x27, 0x3C, 0xB8, 0x15, 0x05, 0x28, 0xDA,
  27591. 0x4D, 0x76, 0x70, 0x81, 0x77, 0xE9, 0x42, 0x55,
  27592. 0x46, 0xC8, 0x3E, 0x14, 0x70, 0x39, 0x76, 0x66,
  27593. 0x03, 0xB3, 0x0D, 0xA6, 0x26, 0x8F, 0x45, 0x98,
  27594. 0xA5, 0x31, 0x94, 0x24, 0x0A, 0x28, 0x32, 0xA3,
  27595. 0xD6, 0x75, 0x33, 0xB5, 0x05, 0x6F, 0x9A, 0xAA,
  27596. 0xC6, 0x1B, 0x4B, 0x17, 0xB9, 0xA2, 0x69, 0x3A,
  27597. 0xA0, 0xD5, 0x88, 0x91, 0xE6, 0xCC, 0x56, 0xCD,
  27598. 0xD7, 0x72, 0x41, 0x09, 0x00, 0xC4, 0x05, 0xAF,
  27599. 0x20, 0xB9, 0x03, 0x79, 0x7C, 0x64, 0x87, 0x69,
  27600. 0x15, 0xC3, 0x7B, 0x84, 0x87, 0xA1, 0x44, 0x9C,
  27601. 0xE9, 0x24, 0xCD, 0x34, 0x5C, 0x29, 0xA3, 0x6E,
  27602. 0x08, 0x23, 0x8F, 0x7A, 0x15, 0x7C, 0xC7, 0xE5,
  27603. 0x16, 0xAB, 0x5B, 0xA7, 0x3C, 0x80, 0x63, 0xF7,
  27604. 0x26, 0xBB, 0x5A, 0x0A, 0x03, 0x19, 0xE5, 0x71,
  27605. 0x27, 0x43, 0x8C, 0x7F, 0xC6, 0x01, 0xC9, 0x9C,
  27606. 0xCA, 0xAE, 0x4C, 0x1A, 0x83, 0x72, 0x6F, 0xDC,
  27607. 0xB5, 0x04, 0x5E, 0xD1, 0xA8, 0x2A, 0x98, 0x5E,
  27608. 0xA9, 0x95, 0x39, 0x6D, 0x77, 0x27, 0x2C, 0x66,
  27609. 0xCE, 0x49, 0x32, 0x89, 0xF6, 0x11, 0x09, 0x10,
  27610. 0xF3, 0x7C, 0x27, 0x41, 0xCE, 0x47, 0x02, 0x6A,
  27611. 0x6F, 0x82, 0x61, 0x99, 0x9C, 0x64, 0x82, 0x57,
  27612. 0x2B, 0x16, 0x93, 0x91, 0x2E, 0xF1, 0x2E, 0xEB,
  27613. 0xEA, 0x7A, 0xCF, 0x92, 0x34, 0xFB, 0x40, 0x9F,
  27614. 0x2A, 0x60, 0x90, 0xE6, 0xB0, 0xBF, 0xD8, 0x95,
  27615. 0x46, 0x9D, 0x0B, 0x2A, 0x92, 0x1B, 0xB7, 0x23,
  27616. 0xF8, 0x7A, 0x33, 0xEA, 0x54, 0x65, 0xAB, 0x90,
  27617. 0xF5, 0x14, 0xB6, 0x76, 0x98, 0xC0, 0x76, 0x8B,
  27618. 0x6C, 0xA4, 0x98, 0xB0, 0x22, 0xC5, 0x12, 0xFA,
  27619. 0x08, 0x75, 0xF0, 0x54, 0xAA, 0x22, 0x65, 0x86,
  27620. 0x7E, 0x31, 0xC0, 0xE5, 0x22, 0x65, 0x1E, 0x02,
  27621. 0x4A, 0x07, 0xD6, 0x0D, 0xD9, 0xF6, 0x33, 0x16,
  27622. 0x69, 0x21, 0xF4, 0x12, 0x6B, 0xC2, 0xB6, 0xAA,
  27623. 0x01, 0xCC, 0x15, 0xA0, 0x9B, 0x85, 0xBF, 0xF8,
  27624. 0x21, 0x8C, 0x5A, 0xAE, 0x95, 0xBC, 0x1F, 0xFB,
  27625. 0x26, 0xAE, 0x5A, 0x13, 0x76, 0x70, 0xF0, 0x49,
  27626. 0x10, 0xCA, 0x9D, 0x72, 0x41, 0xB6, 0x66, 0x0C,
  27627. 0x39, 0x4C, 0x54, 0x55, 0x91, 0x77, 0x46, 0xA2,
  27628. 0x66, 0x82, 0xFB, 0x71, 0xA4, 0x32, 0xEA, 0x95,
  27629. 0x30, 0xE8, 0x39, 0xBD, 0xEB, 0x07, 0x43, 0x30,
  27630. 0x04, 0xF4, 0x5A, 0x0D, 0xDA, 0xA0, 0xB2, 0x4E,
  27631. 0x3A, 0x56, 0x6A, 0x54, 0x08, 0x15, 0xF2, 0x81,
  27632. 0xE3, 0xFC, 0x25, 0x9A, 0xC6, 0xCB, 0xC0, 0xAC,
  27633. 0xB8, 0xD6, 0x22, 0x68, 0xB6, 0x03, 0xBC, 0x67,
  27634. 0x6A, 0xB4, 0x15, 0xC4, 0x74, 0xBB, 0x94, 0x87,
  27635. 0x3E, 0x44, 0x87, 0xAE, 0x31, 0xA4, 0xE3, 0x84,
  27636. 0x5C, 0x79, 0x90, 0x15, 0x50, 0x89, 0x0E, 0xE8,
  27637. 0x78, 0x4E, 0xEF, 0x90, 0x4F, 0xEE, 0x62, 0xBA,
  27638. 0x8C, 0x5F, 0x95, 0x2C, 0x68, 0x41, 0x30, 0x52,
  27639. 0xE0, 0xA7, 0xE3, 0x38, 0x8B, 0xB8, 0xFF, 0x0A,
  27640. 0xD6, 0x02, 0xAE, 0x3E, 0xA1, 0x4D, 0x9D, 0xF6,
  27641. 0xDD, 0x5E, 0x4C, 0xC6, 0xA3, 0x81, 0xA4, 0x1D,
  27642. 0xA5, 0xC1, 0x37, 0xEC, 0xC4, 0x9D, 0xF5, 0x87,
  27643. 0xE1, 0x78, 0xEA, 0xF4, 0x77, 0x02, 0xEC, 0x62,
  27644. 0x37, 0x80, 0x69, 0x1A, 0x32, 0x33, 0xF6, 0x9F,
  27645. 0x12, 0xBD, 0x9C, 0x9B, 0x96, 0x37, 0xC5, 0x13,
  27646. 0x78, 0xAD, 0x71, 0xA8, 0x31, 0x05, 0x52, 0x77,
  27647. 0x25, 0x4C, 0xC6, 0x3C, 0x5A, 0xD4, 0xCB, 0x76,
  27648. 0xB4, 0xAB, 0x82, 0xE5, 0xFC, 0xA1, 0x35, 0xE8,
  27649. 0xD2, 0x6A, 0x6B, 0x3A, 0x89, 0xFA, 0x5B, 0x6F
  27650. };
  27651. static const byte c_768[KYBER768_CIPHER_TEXT_SIZE] = {
  27652. 0xA5, 0xC8, 0x1C, 0x76, 0xC2, 0x43, 0x05, 0xE1,
  27653. 0xCE, 0x5D, 0x81, 0x35, 0xD4, 0x15, 0x23, 0x68,
  27654. 0x2E, 0x9E, 0xE6, 0xD7, 0xB4, 0x0A, 0xD4, 0x1D,
  27655. 0xF1, 0xF3, 0x7C, 0x9B, 0x17, 0xDC, 0xE7, 0x80,
  27656. 0x76, 0x01, 0x9A, 0x6B, 0x0B, 0x7C, 0x95, 0xC9,
  27657. 0xBE, 0x7A, 0xF2, 0x95, 0x07, 0xB2, 0xD5, 0xA6,
  27658. 0x98, 0x7C, 0x8E, 0xE3, 0x25, 0x91, 0x90, 0x85,
  27659. 0x52, 0x43, 0xE6, 0xE5, 0x6F, 0x56, 0x20, 0x60,
  27660. 0x8C, 0x52, 0xD9, 0x6F, 0xAB, 0x10, 0x3A, 0x87,
  27661. 0x00, 0xFB, 0xA1, 0xA8, 0x7D, 0xCA, 0x60, 0x78,
  27662. 0x11, 0x8A, 0x08, 0x71, 0x76, 0x2C, 0x95, 0x34,
  27663. 0xC0, 0xC0, 0xC3, 0x97, 0x8C, 0x91, 0xC3, 0xA0,
  27664. 0x1F, 0x0F, 0x60, 0x8D, 0xCF, 0x75, 0x78, 0x15,
  27665. 0x43, 0x8F, 0xE8, 0x95, 0x7C, 0x8A, 0x85, 0x91,
  27666. 0x83, 0xB1, 0xB6, 0x72, 0x1A, 0x08, 0x65, 0xBE,
  27667. 0xBC, 0x79, 0x9D, 0x4E, 0x5C, 0x0E, 0x7B, 0xD3,
  27668. 0xEA, 0xE4, 0x85, 0x8E, 0x6A, 0xB6, 0xA2, 0xE7,
  27669. 0x65, 0x8E, 0xD8, 0x0D, 0x4E, 0xD1, 0x58, 0xB0,
  27670. 0x36, 0xB9, 0x3F, 0xA0, 0x3A, 0xFA, 0x6A, 0xE3,
  27671. 0x13, 0x6C, 0xF3, 0xD6, 0x93, 0xC9, 0x11, 0xBC,
  27672. 0xC7, 0x59, 0x05, 0xE5, 0xB0, 0xCB, 0x28, 0x65,
  27673. 0xB9, 0xE9, 0x88, 0x45, 0x22, 0xA7, 0x77, 0x77,
  27674. 0x61, 0x3E, 0x53, 0x11, 0x1D, 0x5A, 0x1C, 0x7D,
  27675. 0x3D, 0xAB, 0x73, 0x4C, 0xEB, 0x03, 0x65, 0x7A,
  27676. 0xE0, 0xC8, 0x97, 0x63, 0xE9, 0x94, 0x71, 0x05,
  27677. 0x47, 0x76, 0xBA, 0xE7, 0xD5, 0x1B, 0x0E, 0x73,
  27678. 0xA5, 0xBB, 0x35, 0xAE, 0xC3, 0x0F, 0xF6, 0xBC,
  27679. 0x93, 0x68, 0x49, 0x16, 0xFE, 0xF1, 0x16, 0x25,
  27680. 0x86, 0x45, 0x2F, 0x42, 0x66, 0x53, 0xE2, 0xCA,
  27681. 0x84, 0x4D, 0x57, 0x44, 0x30, 0x7F, 0xF9, 0xAE,
  27682. 0xB2, 0x87, 0xA6, 0x44, 0x77, 0x83, 0xB2, 0x1A,
  27683. 0x0E, 0x93, 0x9C, 0x81, 0x42, 0x1D, 0x63, 0x1F,
  27684. 0x5D, 0xCB, 0x45, 0x2E, 0x51, 0xED, 0x34, 0xE3,
  27685. 0xDA, 0xD1, 0xCF, 0x50, 0x4E, 0x0A, 0x3B, 0x0F,
  27686. 0x47, 0x11, 0xA8, 0xDC, 0x64, 0x99, 0xD1, 0x69,
  27687. 0x1D, 0x10, 0x95, 0x69, 0x33, 0x6C, 0xE1, 0x55,
  27688. 0x8A, 0x4C, 0x0A, 0x46, 0x4E, 0x20, 0x87, 0xEA,
  27689. 0x8F, 0x9E, 0x3B, 0x18, 0xF7, 0x47, 0xEF, 0x61,
  27690. 0xF4, 0x57, 0x6A, 0xEB, 0x42, 0xB1, 0x7C, 0xAD,
  27691. 0xB7, 0xF0, 0xFD, 0x84, 0xDA, 0x8E, 0x3A, 0x6F,
  27692. 0x47, 0x1D, 0x95, 0xED, 0xFA, 0x65, 0xBE, 0x9E,
  27693. 0x6C, 0x9F, 0x6A, 0xE7, 0x56, 0xA2, 0x2A, 0x4F,
  27694. 0x1A, 0x5C, 0x54, 0x3C, 0x26, 0xBA, 0x7B, 0xAD,
  27695. 0x88, 0xE1, 0x6D, 0x5F, 0x5B, 0x7E, 0x12, 0xE2,
  27696. 0xD4, 0xCA, 0x34, 0xB3, 0xA6, 0x4D, 0x17, 0xF8,
  27697. 0x7C, 0xCF, 0xC4, 0xFF, 0x8C, 0x5E, 0x4F, 0x53,
  27698. 0x75, 0x2A, 0x07, 0x7C, 0x68, 0x72, 0x1E, 0x8C,
  27699. 0xC8, 0x17, 0xF9, 0xFF, 0x24, 0x87, 0x61, 0x70,
  27700. 0xFF, 0x2A, 0xF8, 0x9F, 0xA9, 0x58, 0x55, 0xA5,
  27701. 0xB1, 0xDE, 0x34, 0x7C, 0x07, 0xFD, 0xDB, 0xCF,
  27702. 0xE7, 0x26, 0x4A, 0xA5, 0xED, 0x64, 0x01, 0x49,
  27703. 0x15, 0x61, 0xD8, 0x31, 0x53, 0x8F, 0x85, 0x2B,
  27704. 0x0E, 0xD7, 0xB9, 0xE8, 0xEB, 0xAF, 0xFC, 0x06,
  27705. 0x02, 0x84, 0xF2, 0x2D, 0x2B, 0xAE, 0xE5, 0x6F,
  27706. 0xA9, 0xF6, 0xD0, 0x14, 0x32, 0xA1, 0x15, 0xA2,
  27707. 0xD6, 0xA6, 0x4C, 0x38, 0xAE, 0x0A, 0x50, 0xBA,
  27708. 0x36, 0x2F, 0xB5, 0x7B, 0x53, 0xE3, 0xE8, 0x55,
  27709. 0xB8, 0x3C, 0xE8, 0xC4, 0x22, 0x74, 0x04, 0x55,
  27710. 0x99, 0xF6, 0x5F, 0xA6, 0xA8, 0x92, 0x1D, 0x85,
  27711. 0xF9, 0x4E, 0xD2, 0x30, 0xB5, 0x16, 0x71, 0x2D,
  27712. 0xB6, 0xFD, 0x2F, 0xF2, 0x8B, 0x3A, 0x33, 0x71,
  27713. 0xD9, 0xBE, 0x05, 0x8A, 0xE7, 0x5C, 0x2F, 0xA5,
  27714. 0x91, 0xB7, 0xEC, 0x3C, 0x3D, 0xAA, 0x1F, 0x76,
  27715. 0x42, 0xBC, 0x26, 0xC3, 0x24, 0xC0, 0x80, 0x90,
  27716. 0x60, 0x7E, 0x66, 0x62, 0x15, 0x4D, 0xB3, 0x7C,
  27717. 0xF7, 0x47, 0x96, 0x7A, 0x1F, 0x9F, 0xC2, 0x90,
  27718. 0x89, 0xF5, 0x70, 0xEB, 0xE6, 0x0E, 0xEE, 0xF8,
  27719. 0x9F, 0xD2, 0x44, 0x81, 0x02, 0x8C, 0x85, 0xAE,
  27720. 0xF1, 0xDC, 0x3B, 0x09, 0xF2, 0x2C, 0xD3, 0x69,
  27721. 0x1B, 0xBB, 0xB8, 0x21, 0xC7, 0xA8, 0xA0, 0xF3,
  27722. 0x5A, 0xD1, 0x2B, 0xE1, 0xDD, 0x19, 0x9B, 0x97,
  27723. 0x70, 0x48, 0xF3, 0xD4, 0x8C, 0x16, 0xBB, 0x2C,
  27724. 0xA9, 0x4C, 0xEC, 0xB8, 0x92, 0x87, 0x70, 0xD5,
  27725. 0xBB, 0x32, 0x9A, 0x03, 0x27, 0xE0, 0xB2, 0x86,
  27726. 0xFA, 0xA1, 0xC6, 0x52, 0x81, 0x03, 0x1A, 0x31,
  27727. 0xC8, 0x4F, 0x2E, 0xDC, 0x9C, 0x04, 0xD4, 0x75,
  27728. 0xED, 0x4E, 0x12, 0x8E, 0x51, 0xEF, 0xA9, 0x7D,
  27729. 0x01, 0x48, 0xCB, 0xA6, 0xC9, 0x5F, 0x67, 0x4C,
  27730. 0x58, 0x9F, 0x30, 0x1C, 0x26, 0x5B, 0xED, 0x70,
  27731. 0x8E, 0x9A, 0xD8, 0xDA, 0x3C, 0x5C, 0xEC, 0xBD,
  27732. 0xEE, 0xED, 0x35, 0xEF, 0x1E, 0x25, 0x31, 0x32,
  27733. 0xBA, 0x89, 0x92, 0x0D, 0x78, 0x6B, 0x88, 0x23,
  27734. 0x0B, 0x01, 0x3B, 0xCF, 0x2D, 0xC9, 0x2D, 0x6B,
  27735. 0x15, 0x7A, 0xFA, 0x8D, 0xA8, 0x59, 0x2C, 0xD0,
  27736. 0x74, 0x3D, 0x49, 0x82, 0xBE, 0x60, 0xD7, 0xC2,
  27737. 0xD5, 0xC4, 0x72, 0xAB, 0x9F, 0xA7, 0xF4, 0xCC,
  27738. 0x3D, 0x12, 0xB0, 0xEB, 0xAF, 0x0A, 0xBE, 0x55,
  27739. 0x5C, 0x75, 0x80, 0x54, 0x26, 0x84, 0x4D, 0xD9,
  27740. 0x42, 0x86, 0x43, 0xF8, 0x44, 0x06, 0xA1, 0xB8,
  27741. 0xD6, 0xFA, 0xED, 0xFD, 0x8A, 0xE6, 0xE7, 0x3A,
  27742. 0x72, 0x77, 0x2A, 0x21, 0x59, 0xAC, 0xAB, 0xD9,
  27743. 0x72, 0xAE, 0xB6, 0xF7, 0xDE, 0x09, 0x1A, 0xC5,
  27744. 0xFD, 0xD7, 0xF4, 0x9A, 0x3D, 0xC6, 0x64, 0x1C,
  27745. 0xDF, 0x62, 0x44, 0x6B, 0x4B, 0x04, 0xA3, 0x1F,
  27746. 0x73, 0xB8, 0x0A, 0x62, 0xF8, 0x0A, 0x40, 0x4A,
  27747. 0x8C, 0xB1, 0x8C, 0xE3, 0xE6, 0x54, 0x80, 0xEF,
  27748. 0x7B, 0x52, 0xBF, 0x00, 0x91, 0x11, 0x7E, 0x5D,
  27749. 0x08, 0xEA, 0xE1, 0xB0, 0xAA, 0xBB, 0x72, 0xE6,
  27750. 0xDF, 0xFF, 0xF7, 0x6F, 0x6E, 0x44, 0xBB, 0xD7,
  27751. 0xEA, 0x57, 0x0D, 0x66, 0x04, 0xBC, 0x2E, 0x74,
  27752. 0x31, 0x8B, 0xAF, 0xA3, 0x15, 0xA3, 0x88, 0x61,
  27753. 0xAA, 0x1B, 0x21, 0xAF, 0xB2, 0xA5, 0x3F, 0x26,
  27754. 0x14, 0xF1, 0xD6, 0x40, 0x07, 0x59, 0x84, 0xAE,
  27755. 0x62, 0xE2, 0xFC, 0xA1, 0xD1, 0xB4, 0xDB, 0x36,
  27756. 0x9F, 0x15, 0x70, 0x5C, 0xE7, 0xD4, 0xDF, 0x8A,
  27757. 0xE9, 0x82, 0x64, 0x50, 0x10, 0x51, 0xC0, 0xDE,
  27758. 0xF2, 0x1D, 0x64, 0x5D, 0x49, 0x62, 0x5A, 0xF0,
  27759. 0x2C, 0xA4, 0x28, 0xD9, 0xF0, 0xC2, 0xCD, 0x9F,
  27760. 0xBA, 0xEE, 0xAB, 0x97, 0xE8, 0xE9, 0x15, 0x16,
  27761. 0x62, 0xB6, 0x99, 0x2B, 0x4C, 0x99, 0xAB, 0x1B,
  27762. 0x92, 0x5D, 0x08, 0x92, 0x03, 0x63, 0x37, 0x3F,
  27763. 0x76, 0xD3, 0xFD, 0xF0, 0x82, 0x8C, 0xAA, 0x69,
  27764. 0xC8, 0xB1, 0xBD, 0xC6, 0xF5, 0x21, 0xDF, 0x64,
  27765. 0x1C, 0xF1, 0xC8, 0xA4, 0xE7, 0xEF, 0x0C, 0x23,
  27766. 0x28, 0x9A, 0x4E, 0x2C, 0xF1, 0x8A, 0xCE, 0xBB,
  27767. 0xE4, 0xC1, 0xE6, 0x83, 0x69, 0xBD, 0x52, 0x35,
  27768. 0x12, 0x01, 0x42, 0xEC, 0xDD, 0x1A, 0x73, 0x81,
  27769. 0x1E, 0x2E, 0x53, 0x3A, 0x64, 0x7D, 0x7A, 0xEE,
  27770. 0x16, 0xDA, 0xA0, 0x3B, 0x68, 0x36, 0x39, 0xDC,
  27771. 0xF1, 0xE1, 0xF1, 0xE7, 0x1C, 0xFA, 0xED, 0x48,
  27772. 0xF6, 0x9A, 0xEC, 0x3E, 0x83, 0x17, 0x33, 0xDA,
  27773. 0x19, 0xCE, 0xBE, 0xC1, 0xDD, 0xBF, 0x71, 0xCB,
  27774. 0xAE, 0x08, 0x00, 0xF2, 0xF6, 0xD6, 0x4A, 0x09,
  27775. 0x6E, 0xC4, 0x95, 0xD6, 0x2F, 0x43, 0x44, 0xF7,
  27776. 0xAA, 0x56, 0x21, 0xB3, 0x22, 0x35, 0x3A, 0x79,
  27777. 0x5A, 0xA0, 0x99, 0xEA, 0x3A, 0x07, 0x02, 0x72,
  27778. 0xD0, 0x53, 0xD4, 0x65, 0x3A, 0x20, 0xCF, 0x21,
  27779. 0x0E, 0xAA, 0xF1, 0x2C, 0xAE, 0x60, 0x23, 0xD8,
  27780. 0xE5, 0x11, 0x8D, 0xF0, 0x4B, 0x38, 0x4A, 0x44,
  27781. 0xD1, 0xED, 0xB9, 0x1C, 0x44, 0x98, 0x9E, 0xF7,
  27782. 0xEE, 0x57, 0xF2, 0xBF, 0x81, 0xA2, 0x4B, 0xDC,
  27783. 0x76, 0x80, 0x7D, 0xA9, 0x67, 0xEE, 0x65, 0x25,
  27784. 0x41, 0x0C, 0x5C, 0x48, 0x50, 0x67, 0xEF, 0xC3,
  27785. 0xD3, 0x9A, 0x9A, 0xD4, 0x2C, 0xC7, 0x53, 0xBA,
  27786. 0xA5, 0x9A, 0x1F, 0xD2, 0x8A, 0xF3, 0x5C, 0x00,
  27787. 0xD1, 0x8A, 0x40, 0x6A, 0x28, 0xFC, 0x79, 0xBA
  27788. };
  27789. static const byte kprime_768[KYBER_SS_SZ] = {
  27790. 0xDC, 0x5B, 0x88, 0x88, 0xBC, 0x1E, 0xBA, 0x5C,
  27791. 0x19, 0x69, 0xC2, 0x11, 0x64, 0xEA, 0x43, 0xE2,
  27792. 0x2E, 0x7A, 0xC0, 0xCD, 0x01, 0x2A, 0x2F, 0x26,
  27793. 0xCB, 0x8C, 0x48, 0x7E, 0x69, 0xEF, 0x7C, 0xE4
  27794. };
  27795. #endif
  27796. #ifndef WOLFSSL_NO_KYBER1024
  27797. static const byte dk_1024[KYBER1024_PRIVATE_KEY_SIZE] = {
  27798. 0x84, 0x45, 0xC3, 0x36, 0xF3, 0x51, 0x8B, 0x29,
  27799. 0x81, 0x63, 0xDC, 0xBB, 0x63, 0x57, 0x59, 0x79,
  27800. 0x83, 0xCA, 0x2E, 0x87, 0x3D, 0xCB, 0x49, 0x61,
  27801. 0x0C, 0xF5, 0x2F, 0x14, 0xDB, 0xCB, 0x94, 0x7C,
  27802. 0x1F, 0x3E, 0xE9, 0x26, 0x69, 0x67, 0x27, 0x6B,
  27803. 0x0C, 0x57, 0x6C, 0xF7, 0xC3, 0x0E, 0xE6, 0xB9,
  27804. 0x3D, 0xEA, 0x51, 0x18, 0x67, 0x6C, 0xBE, 0xE1,
  27805. 0xB1, 0xD4, 0x79, 0x42, 0x06, 0xFB, 0x36, 0x9A,
  27806. 0xBA, 0x41, 0x16, 0x7B, 0x43, 0x93, 0x85, 0x5C,
  27807. 0x84, 0xEB, 0xA8, 0xF3, 0x23, 0x73, 0xC0, 0x5B,
  27808. 0xAE, 0x76, 0x31, 0xC8, 0x02, 0x74, 0x4A, 0xAD,
  27809. 0xB6, 0xC2, 0xDE, 0x41, 0x25, 0x0C, 0x49, 0x43,
  27810. 0x15, 0x23, 0x0B, 0x52, 0x82, 0x6C, 0x34, 0x58,
  27811. 0x7C, 0xB2, 0x1B, 0x18, 0x3B, 0x49, 0xB2, 0xA5,
  27812. 0xAC, 0x04, 0x92, 0x1A, 0xC6, 0xBF, 0xAC, 0x1B,
  27813. 0x24, 0xA4, 0xB3, 0x7A, 0x93, 0xA4, 0xB1, 0x68,
  27814. 0xCC, 0xE7, 0x59, 0x1B, 0xE6, 0x11, 0x1F, 0x47,
  27815. 0x62, 0x60, 0xF2, 0x76, 0x29, 0x59, 0xF5, 0xC1,
  27816. 0x64, 0x01, 0x18, 0xC2, 0x42, 0x37, 0x72, 0xE2,
  27817. 0xAD, 0x03, 0xDC, 0x71, 0x68, 0xA3, 0x8C, 0x6D,
  27818. 0xD3, 0x9F, 0x5F, 0x72, 0x54, 0x26, 0x42, 0x80,
  27819. 0xC8, 0xBC, 0x10, 0xB9, 0x14, 0x16, 0x80, 0x70,
  27820. 0x47, 0x2F, 0xA8, 0x80, 0xAC, 0xB8, 0x60, 0x1A,
  27821. 0x8A, 0x08, 0x37, 0xF2, 0x5F, 0xE1, 0x94, 0x68,
  27822. 0x7C, 0xD6, 0x8B, 0x7D, 0xE2, 0x34, 0x0F, 0x03,
  27823. 0x6D, 0xAD, 0x89, 0x1D, 0x38, 0xD1, 0xB0, 0xCE,
  27824. 0x9C, 0x26, 0x33, 0x35, 0x5C, 0xF5, 0x7B, 0x50,
  27825. 0xB8, 0x96, 0x03, 0x6F, 0xCA, 0x26, 0x0D, 0x26,
  27826. 0x69, 0xF8, 0x5B, 0xAC, 0x79, 0x71, 0x4F, 0xDA,
  27827. 0xFB, 0x41, 0xEF, 0x80, 0xB8, 0xC3, 0x02, 0x64,
  27828. 0xC3, 0x13, 0x86, 0xAE, 0x60, 0xB0, 0x5F, 0xAA,
  27829. 0x54, 0x2A, 0x26, 0xB4, 0x1E, 0xB8, 0x5F, 0x67,
  27830. 0x06, 0x8F, 0x08, 0x80, 0x34, 0xFF, 0x67, 0xAA,
  27831. 0x2E, 0x81, 0x5A, 0xAB, 0x8B, 0xCA, 0x6B, 0xF7,
  27832. 0x1F, 0x70, 0xEC, 0xC3, 0xCB, 0xCB, 0xC4, 0x5E,
  27833. 0xF7, 0x01, 0xFC, 0xD5, 0x42, 0xBD, 0x21, 0xC7,
  27834. 0xB0, 0x95, 0x68, 0xF3, 0x69, 0xC6, 0x69, 0xF3,
  27835. 0x96, 0x47, 0x38, 0x44, 0xFB, 0xA1, 0x49, 0x57,
  27836. 0xF5, 0x19, 0x74, 0xD8, 0x52, 0xB9, 0x78, 0x01,
  27837. 0x46, 0x03, 0xA2, 0x10, 0xC0, 0x19, 0x03, 0x62,
  27838. 0x87, 0x00, 0x89, 0x94, 0xF2, 0x12, 0x55, 0xB2,
  27839. 0x50, 0x99, 0xAD, 0x82, 0xAA, 0x13, 0x24, 0x38,
  27840. 0x96, 0x3B, 0x2C, 0x0A, 0x47, 0xCD, 0xF5, 0xF3,
  27841. 0x2B, 0xA4, 0x6B, 0x76, 0xC7, 0xA6, 0x55, 0x9F,
  27842. 0x18, 0xBF, 0xD5, 0x55, 0xB7, 0x62, 0xE4, 0x87,
  27843. 0xB6, 0xAC, 0x99, 0x2F, 0xE2, 0x0E, 0x28, 0x3C,
  27844. 0xA0, 0xB3, 0xF6, 0x16, 0x44, 0x96, 0x95, 0x59,
  27845. 0x95, 0xC3, 0xB2, 0x8A, 0x57, 0xBB, 0xC2, 0x98,
  27846. 0x26, 0xF0, 0x6F, 0xB3, 0x8B, 0x25, 0x34, 0x70,
  27847. 0xAF, 0x63, 0x1B, 0xC4, 0x6C, 0x3A, 0x8F, 0x9C,
  27848. 0xE8, 0x24, 0x32, 0x19, 0x85, 0xDD, 0x01, 0xC0,
  27849. 0x5F, 0x69, 0xB8, 0x24, 0xF9, 0x16, 0x63, 0x3B,
  27850. 0x40, 0x65, 0x4C, 0x75, 0xAA, 0xEB, 0x93, 0x85,
  27851. 0x57, 0x6F, 0xFD, 0xE2, 0x99, 0x0A, 0x6B, 0x0A,
  27852. 0x3B, 0xE8, 0x29, 0xD6, 0xD8, 0x4E, 0x34, 0xF1,
  27853. 0x78, 0x05, 0x89, 0xC7, 0x92, 0x04, 0xC6, 0x3C,
  27854. 0x79, 0x8F, 0x55, 0xD2, 0x31, 0x87, 0xE4, 0x61,
  27855. 0xD4, 0x8C, 0x21, 0xE5, 0xC0, 0x47, 0xE5, 0x35,
  27856. 0xB1, 0x9F, 0x45, 0x8B, 0xBA, 0x13, 0x45, 0xB9,
  27857. 0xE4, 0x1E, 0x0C, 0xB4, 0xA9, 0xC2, 0xD8, 0xC4,
  27858. 0x0B, 0x49, 0x0A, 0x3B, 0xAB, 0xC5, 0x53, 0xB3,
  27859. 0x02, 0x6B, 0x16, 0x72, 0xD2, 0x8C, 0xBC, 0x8B,
  27860. 0x49, 0x8A, 0x3A, 0x99, 0x57, 0x9A, 0x83, 0x2F,
  27861. 0xEA, 0xE7, 0x46, 0x10, 0xF0, 0xB6, 0x25, 0x0C,
  27862. 0xC3, 0x33, 0xE9, 0x49, 0x3E, 0xB1, 0x62, 0x1E,
  27863. 0xD3, 0x4A, 0xA4, 0xAB, 0x17, 0x5F, 0x2C, 0xA2,
  27864. 0x31, 0x15, 0x25, 0x09, 0xAC, 0xB6, 0xAC, 0x86,
  27865. 0xB2, 0x0F, 0x6B, 0x39, 0x10, 0x84, 0x39, 0xE5,
  27866. 0xEC, 0x12, 0xD4, 0x65, 0xA0, 0xFE, 0xF3, 0x50,
  27867. 0x03, 0xE1, 0x42, 0x77, 0xA2, 0x18, 0x12, 0x14,
  27868. 0x6B, 0x25, 0x44, 0x71, 0x6D, 0x6A, 0xB8, 0x2D,
  27869. 0x1B, 0x07, 0x26, 0xC2, 0x7A, 0x98, 0xD5, 0x89,
  27870. 0xEB, 0xDA, 0xCC, 0x4C, 0x54, 0xBA, 0x77, 0xB2,
  27871. 0x49, 0x8F, 0x21, 0x7E, 0x14, 0xE3, 0x4E, 0x66,
  27872. 0x02, 0x5A, 0x2A, 0x14, 0x3A, 0x99, 0x25, 0x20,
  27873. 0xA6, 0x1C, 0x06, 0x72, 0xCC, 0x9C, 0xCE, 0xD7,
  27874. 0xC9, 0x45, 0x0C, 0x68, 0x3E, 0x90, 0xA3, 0xE4,
  27875. 0x65, 0x1D, 0xB6, 0x23, 0xA6, 0xDB, 0x39, 0xAC,
  27876. 0x26, 0x12, 0x5B, 0x7F, 0xC1, 0x98, 0x6D, 0x7B,
  27877. 0x04, 0x93, 0xB8, 0xB7, 0x2D, 0xE7, 0x70, 0x7D,
  27878. 0xC2, 0x0B, 0xBD, 0xD4, 0x37, 0x13, 0x15, 0x6A,
  27879. 0xF7, 0xD9, 0x43, 0x0E, 0xF4, 0x53, 0x99, 0x66,
  27880. 0x3C, 0x22, 0x02, 0x73, 0x91, 0x68, 0x69, 0x2D,
  27881. 0xD6, 0x57, 0x54, 0x5B, 0x05, 0x6D, 0x9C, 0x92,
  27882. 0x38, 0x5A, 0x7F, 0x41, 0x4B, 0x34, 0xB9, 0x0C,
  27883. 0x79, 0x60, 0xD5, 0x7B, 0x35, 0xBA, 0x7D, 0xDE,
  27884. 0x7B, 0x81, 0xFC, 0xA0, 0x11, 0x9D, 0x74, 0x1B,
  27885. 0x12, 0x78, 0x09, 0x26, 0x01, 0x8F, 0xE4, 0xC8,
  27886. 0x03, 0x0B, 0xF0, 0x38, 0xE1, 0x8B, 0x4F, 0xA3,
  27887. 0x37, 0x43, 0xD0, 0xD3, 0xC8, 0x46, 0x41, 0x7E,
  27888. 0x9D, 0x59, 0x15, 0xC2, 0x46, 0x31, 0x59, 0x38,
  27889. 0xB1, 0xE2, 0x33, 0x61, 0x45, 0x01, 0xD0, 0x26,
  27890. 0x95, 0x95, 0x51, 0x25, 0x8B, 0x23, 0x32, 0x30,
  27891. 0xD4, 0x28, 0xB1, 0x81, 0xB1, 0x32, 0xF1, 0xD0,
  27892. 0xB0, 0x26, 0x06, 0x7B, 0xA8, 0x16, 0x99, 0x9B,
  27893. 0xC0, 0xCD, 0x6B, 0x54, 0x7E, 0x54, 0x8B, 0x63,
  27894. 0xC9, 0xEA, 0xA0, 0x91, 0xBA, 0xC4, 0x93, 0xDC,
  27895. 0x59, 0x8D, 0xBC, 0x2B, 0x0E, 0x14, 0x6A, 0x25,
  27896. 0x91, 0xC2, 0xA8, 0xC0, 0x09, 0xDD, 0x51, 0x70,
  27897. 0xAA, 0xE0, 0x27, 0xC5, 0x41, 0xA1, 0xB5, 0xE6,
  27898. 0x6E, 0x45, 0xC6, 0x56, 0x12, 0x98, 0x4C, 0x46,
  27899. 0x77, 0x04, 0x93, 0xEC, 0x89, 0x6E, 0xF2, 0x5A,
  27900. 0xA9, 0x30, 0x5E, 0x9F, 0x06, 0x69, 0x2C, 0xD0,
  27901. 0xB2, 0xF0, 0x69, 0x62, 0xE2, 0x05, 0xBE, 0xBE,
  27902. 0x11, 0x3A, 0x34, 0xEB, 0xB1, 0xA4, 0x83, 0x0A,
  27903. 0x9B, 0x37, 0x49, 0x64, 0x1B, 0xB9, 0x35, 0x00,
  27904. 0x7B, 0x23, 0xB2, 0x4B, 0xFE, 0x57, 0x69, 0x56,
  27905. 0x25, 0x4D, 0x7A, 0x35, 0xAA, 0x49, 0x6A, 0xC4,
  27906. 0x46, 0xC6, 0x7A, 0x7F, 0xEC, 0x85, 0xA6, 0x00,
  27907. 0x57, 0xE8, 0x58, 0x06, 0x17, 0xBC, 0xB3, 0xFA,
  27908. 0xD1, 0x5C, 0x76, 0x44, 0x0F, 0xED, 0x54, 0xCC,
  27909. 0x78, 0x93, 0x94, 0xFE, 0xA2, 0x44, 0x52, 0xCC,
  27910. 0x6B, 0x05, 0x85, 0xB7, 0xEB, 0x0A, 0x88, 0xBB,
  27911. 0xA9, 0x50, 0x0D, 0x98, 0x00, 0xE6, 0x24, 0x1A,
  27912. 0xFE, 0xB5, 0x23, 0xB5, 0x5A, 0x96, 0xA5, 0x35,
  27913. 0x15, 0x1D, 0x10, 0x49, 0x57, 0x32, 0x06, 0xE5,
  27914. 0x9C, 0x7F, 0xEB, 0x07, 0x09, 0x66, 0x82, 0x36,
  27915. 0x34, 0xF7, 0x7D, 0x5F, 0x12, 0x91, 0x75, 0x5A,
  27916. 0x24, 0x31, 0x19, 0x62, 0x1A, 0xF8, 0x08, 0x4A,
  27917. 0xB7, 0xAC, 0x1E, 0x22, 0xA0, 0x56, 0x8C, 0x62,
  27918. 0x01, 0x41, 0x7C, 0xBE, 0x36, 0x55, 0xD8, 0xA0,
  27919. 0x8D, 0xD5, 0xB5, 0x13, 0x88, 0x4C, 0x98, 0xD5,
  27920. 0xA4, 0x93, 0xFD, 0x49, 0x38, 0x2E, 0xA4, 0x18,
  27921. 0x60, 0xF1, 0x33, 0xCC, 0xD6, 0x01, 0xE8, 0x85,
  27922. 0x96, 0x64, 0x26, 0xA2, 0xB1, 0xF2, 0x3D, 0x42,
  27923. 0xD8, 0x2E, 0x24, 0x58, 0x2D, 0x99, 0x72, 0x51,
  27924. 0x92, 0xC2, 0x17, 0x77, 0x46, 0x7B, 0x14, 0x57,
  27925. 0xB1, 0xDD, 0x42, 0x9A, 0x0C, 0x41, 0xA5, 0xC3,
  27926. 0xD7, 0x04, 0xCE, 0xA0, 0x62, 0x78, 0xC5, 0x99,
  27927. 0x41, 0xB4, 0x38, 0xC6, 0x27, 0x27, 0x09, 0x78,
  27928. 0x09, 0xB4, 0x53, 0x0D, 0xBE, 0x83, 0x7E, 0xA3,
  27929. 0x96, 0xB6, 0xD3, 0x10, 0x77, 0xFA, 0xD3, 0x73,
  27930. 0x30, 0x53, 0x98, 0x9A, 0x84, 0x42, 0xAA, 0xC4,
  27931. 0x25, 0x5C, 0xB1, 0x63, 0xB8, 0xCA, 0x2F, 0x27,
  27932. 0x50, 0x1E, 0xA9, 0x67, 0x30, 0x56, 0x95, 0xAB,
  27933. 0xD6, 0x59, 0xAA, 0x02, 0xC8, 0x3E, 0xE6, 0x0B,
  27934. 0xB5, 0x74, 0x20, 0x3E, 0x99, 0x37, 0xAE, 0x1C,
  27935. 0x62, 0x1C, 0x8E, 0xCB, 0x5C, 0xC1, 0xD2, 0x1D,
  27936. 0x55, 0x69, 0x60, 0xB5, 0xB9, 0x16, 0x1E, 0xA9,
  27937. 0x6F, 0xFF, 0xEB, 0xAC, 0x72, 0xE1, 0xB8, 0xA6,
  27938. 0x15, 0x4F, 0xC4, 0xD8, 0x8B, 0x56, 0xC0, 0x47,
  27939. 0x41, 0xF0, 0x90, 0xCB, 0xB1, 0x56, 0xA7, 0x37,
  27940. 0xC9, 0xE6, 0xA2, 0x2B, 0xA8, 0xAC, 0x70, 0x4B,
  27941. 0xC3, 0x04, 0xF8, 0xE1, 0x7E, 0x5E, 0xA8, 0x45,
  27942. 0xFD, 0xE5, 0x9F, 0xBF, 0x78, 0x8C, 0xCE, 0x0B,
  27943. 0x97, 0xC8, 0x76, 0x1F, 0x89, 0xA2, 0x42, 0xF3,
  27944. 0x05, 0x25, 0x83, 0xC6, 0x84, 0x4A, 0x63, 0x20,
  27945. 0x31, 0xC9, 0x64, 0xA6, 0xC4, 0xA8, 0x5A, 0x12,
  27946. 0x8A, 0x28, 0x61, 0x9B, 0xA1, 0xBB, 0x3D, 0x1B,
  27947. 0xEA, 0x4B, 0x49, 0x84, 0x1F, 0xC8, 0x47, 0x61,
  27948. 0x4A, 0x06, 0x68, 0x41, 0xF5, 0x2E, 0xD0, 0xEB,
  27949. 0x8A, 0xE0, 0xB8, 0xB0, 0x96, 0xE9, 0x2B, 0x81,
  27950. 0x95, 0x40, 0x58, 0x15, 0xB2, 0x31, 0x26, 0x6F,
  27951. 0x36, 0xB1, 0x8C, 0x1A, 0x53, 0x33, 0x3D, 0xAB,
  27952. 0x95, 0xD2, 0xA9, 0xA3, 0x74, 0xB5, 0x47, 0x8A,
  27953. 0x4A, 0x41, 0xFB, 0x87, 0x59, 0x95, 0x7C, 0x9A,
  27954. 0xB2, 0x2C, 0xAE, 0x54, 0x5A, 0xB5, 0x44, 0xBA,
  27955. 0x8D, 0xD0, 0x5B, 0x83, 0xF3, 0xA6, 0x13, 0xA2,
  27956. 0x43, 0x7A, 0xDB, 0x07, 0x3A, 0x96, 0x35, 0xCB,
  27957. 0x4B, 0xBC, 0x96, 0x5F, 0xB4, 0x54, 0xCF, 0x27,
  27958. 0xB2, 0x98, 0xA4, 0x0C, 0xD0, 0xDA, 0x3B, 0x8F,
  27959. 0x9C, 0xA9, 0x9D, 0x8C, 0xB4, 0x28, 0x6C, 0x5E,
  27960. 0xB4, 0x76, 0x41, 0x67, 0x96, 0x07, 0x0B, 0xA5,
  27961. 0x35, 0xAA, 0xA5, 0x8C, 0xDB, 0x45, 0x1C, 0xD6,
  27962. 0xDB, 0x5C, 0xBB, 0x0C, 0xA2, 0x0F, 0x0C, 0x71,
  27963. 0xDE, 0x97, 0xC3, 0x0D, 0xA9, 0x7E, 0xC7, 0x90,
  27964. 0x6D, 0x06, 0xB4, 0xB9, 0x39, 0x39, 0x60, 0x28,
  27965. 0xC4, 0x6B, 0xA0, 0xE7, 0xA8, 0x65, 0xBC, 0x83,
  27966. 0x08, 0xA3, 0x81, 0x0F, 0x12, 0x12, 0x00, 0x63,
  27967. 0x39, 0xF7, 0xBC, 0x16, 0x9B, 0x16, 0x66, 0xFD,
  27968. 0xF4, 0x75, 0x91, 0x1B, 0xBC, 0x8A, 0xAA, 0xB4,
  27969. 0x17, 0x55, 0xC9, 0xA8, 0xAA, 0xBF, 0xA2, 0x3C,
  27970. 0x0E, 0x37, 0xF8, 0x4F, 0xE4, 0x69, 0x99, 0xE0,
  27971. 0x30, 0x49, 0x4B, 0x92, 0x98, 0xEF, 0x99, 0x34,
  27972. 0xE8, 0xA6, 0x49, 0xC0, 0xA5, 0xCC, 0xE2, 0xB2,
  27973. 0x2F, 0x31, 0x80, 0x9A, 0xFE, 0xD2, 0x39, 0x55,
  27974. 0xD8, 0x78, 0x81, 0xD9, 0x9F, 0xC1, 0xD3, 0x52,
  27975. 0x89, 0x6C, 0xAC, 0x90, 0x55, 0xBE, 0xA0, 0xD0,
  27976. 0x16, 0xCC, 0xBA, 0x78, 0x05, 0xA3, 0xA5, 0x0E,
  27977. 0x22, 0x16, 0x30, 0x37, 0x9B, 0xD0, 0x11, 0x35,
  27978. 0x22, 0x1C, 0xAD, 0x5D, 0x95, 0x17, 0xC8, 0xCC,
  27979. 0x42, 0x63, 0x7B, 0x9F, 0xC0, 0x71, 0x8E, 0x9A,
  27980. 0x9B, 0xB4, 0x94, 0x5C, 0x72, 0xD8, 0xD1, 0x1D,
  27981. 0x3D, 0x65, 0x9D, 0x83, 0xA3, 0xC4, 0x19, 0x50,
  27982. 0x9A, 0xF5, 0xB4, 0x70, 0xDD, 0x89, 0xB7, 0xF3,
  27983. 0xAC, 0xCF, 0x5F, 0x35, 0xCF, 0xC3, 0x22, 0x11,
  27984. 0x5F, 0xD6, 0x6A, 0x5C, 0xD2, 0x87, 0x56, 0x51,
  27985. 0x32, 0x6F, 0x9B, 0x31, 0x68, 0x91, 0x3B, 0xE5,
  27986. 0xB9, 0xC8, 0x7A, 0xE0, 0xB0, 0x25, 0xEC, 0x7A,
  27987. 0x2F, 0x4A, 0x07, 0x27, 0x50, 0x94, 0x6A, 0xC6,
  27988. 0x11, 0x70, 0xA7, 0x82, 0x6D, 0x97, 0x04, 0xC5,
  27989. 0xA2, 0x3A, 0x1C, 0x0A, 0x23, 0x25, 0x14, 0x6C,
  27990. 0x3B, 0xC1, 0x85, 0x88, 0x26, 0xC6, 0xB3, 0x92,
  27991. 0x79, 0xC2, 0xDA, 0x74, 0x38, 0xA3, 0x70, 0xED,
  27992. 0x8A, 0x0A, 0xA5, 0x16, 0x9E, 0x3B, 0xEC, 0x29,
  27993. 0xED, 0x88, 0x47, 0x87, 0x32, 0x75, 0x8D, 0x45,
  27994. 0x41, 0x43, 0xE2, 0x27, 0xF8, 0x59, 0x58, 0x83,
  27995. 0x29, 0x78, 0x42, 0xE6, 0xAF, 0x13, 0x3B, 0x17,
  27996. 0xE4, 0x81, 0x1B, 0x0F, 0x57, 0x13, 0xAC, 0x73,
  27997. 0xB7, 0xE3, 0x47, 0x42, 0x3E, 0xB9, 0x28, 0x22,
  27998. 0xD2, 0x30, 0x6F, 0xA1, 0x45, 0x00, 0xA7, 0x20,
  27999. 0x7A, 0x06, 0x72, 0x67, 0x20, 0x46, 0x54, 0x4A,
  28000. 0xCC, 0x4E, 0xA9, 0xC1, 0x6E, 0xD7, 0x42, 0x1A,
  28001. 0x06, 0x9E, 0x0D, 0x73, 0x7A, 0x98, 0x62, 0x85,
  28002. 0x19, 0xC6, 0xA2, 0x9A, 0x42, 0x4A, 0x86, 0x8B,
  28003. 0x46, 0xD9, 0xA0, 0xCC, 0x7C, 0x6C, 0x9D, 0xDD,
  28004. 0x8B, 0x8B, 0xCB, 0xF4, 0x22, 0xC8, 0xF4, 0x8A,
  28005. 0x73, 0x14, 0x3D, 0x5A, 0xBB, 0x66, 0xBC, 0x55,
  28006. 0x49, 0x94, 0x18, 0x43, 0x08, 0x02, 0xBA, 0xC5,
  28007. 0x44, 0x46, 0x3C, 0xC7, 0x31, 0x9D, 0x17, 0x99,
  28008. 0x8F, 0x29, 0x41, 0x13, 0x65, 0x76, 0x6D, 0x04,
  28009. 0xC8, 0x47, 0xF3, 0x12, 0x9D, 0x90, 0x77, 0xB7,
  28010. 0xD8, 0x33, 0x9B, 0xFB, 0x96, 0xA6, 0x73, 0x9C,
  28011. 0x3F, 0x6B, 0x74, 0xA8, 0xF0, 0x5F, 0x91, 0x38,
  28012. 0xAB, 0x2F, 0xE3, 0x7A, 0xCB, 0x57, 0x63, 0x4D,
  28013. 0x18, 0x20, 0xB5, 0x01, 0x76, 0xF5, 0xA0, 0xB6,
  28014. 0xBC, 0x29, 0x40, 0xF1, 0xD5, 0x93, 0x8F, 0x19,
  28015. 0x36, 0xB5, 0xF9, 0x58, 0x28, 0xB9, 0x2E, 0xB7,
  28016. 0x29, 0x73, 0xC1, 0x59, 0x0A, 0xEB, 0x7A, 0x55,
  28017. 0x2C, 0xEC, 0xA1, 0x0B, 0x00, 0xC3, 0x03, 0xB7,
  28018. 0xC7, 0x5D, 0x40, 0x20, 0x71, 0xA7, 0x9E, 0x2C,
  28019. 0x81, 0x0A, 0xF7, 0xC7, 0x45, 0xE3, 0x33, 0x67,
  28020. 0x12, 0x49, 0x2A, 0x42, 0x04, 0x3F, 0x29, 0x03,
  28021. 0xA3, 0x7C, 0x64, 0x34, 0xCE, 0xE2, 0x0B, 0x1D,
  28022. 0x15, 0x9B, 0x05, 0x76, 0x99, 0xFF, 0x9C, 0x1D,
  28023. 0x3B, 0xD6, 0x80, 0x29, 0x83, 0x9A, 0x08, 0xF4,
  28024. 0x3E, 0x6C, 0x1C, 0x81, 0x99, 0x13, 0x53, 0x2F,
  28025. 0x91, 0x1D, 0xD3, 0x70, 0xC7, 0x02, 0x14, 0x88,
  28026. 0xE1, 0x1C, 0xB5, 0x04, 0xCB, 0x9C, 0x70, 0x57,
  28027. 0x0F, 0xFF, 0x35, 0xB4, 0xB4, 0x60, 0x11, 0x91,
  28028. 0xDC, 0x1A, 0xD9, 0xE6, 0xAD, 0xC5, 0xFA, 0x96,
  28029. 0x18, 0x79, 0x8D, 0x7C, 0xC8, 0x60, 0xC8, 0x7A,
  28030. 0x93, 0x9E, 0x4C, 0xCF, 0x85, 0x33, 0x63, 0x22,
  28031. 0x68, 0xCF, 0x1A, 0x51, 0xAF, 0xF0, 0xCB, 0x81,
  28032. 0x1C, 0x55, 0x45, 0xCB, 0x16, 0x56, 0xE6, 0x52,
  28033. 0x69, 0x47, 0x74, 0x30, 0x69, 0x9C, 0xCD, 0xEA,
  28034. 0x38, 0x00, 0x63, 0x0B, 0x78, 0xCD, 0x58, 0x10,
  28035. 0x33, 0x4C, 0xCF, 0x02, 0xE0, 0x13, 0xF3, 0xB8,
  28036. 0x02, 0x44, 0xE7, 0x0A, 0xCD, 0xB0, 0x60, 0xBB,
  28037. 0xE7, 0xA5, 0x53, 0xB0, 0x63, 0x45, 0x6B, 0x2E,
  28038. 0xA8, 0x07, 0x47, 0x34, 0x13, 0x16, 0x5C, 0xE5,
  28039. 0x7D, 0xD5, 0x63, 0x47, 0x3C, 0xFB, 0xC9, 0x06,
  28040. 0x18, 0xAD, 0xE1, 0xF0, 0xB8, 0x88, 0xAA, 0x48,
  28041. 0xE7, 0x22, 0xBB, 0x27, 0x51, 0x85, 0x8F, 0xE1,
  28042. 0x96, 0x87, 0x44, 0x2A, 0x48, 0xE7, 0xCA, 0x0D,
  28043. 0x2A, 0x29, 0xCD, 0x51, 0xBF, 0xD8, 0xF7, 0x8C,
  28044. 0x17, 0xB9, 0x66, 0x0B, 0xFB, 0x54, 0xA4, 0x70,
  28045. 0xB2, 0xAE, 0x9A, 0x95, 0x5C, 0x6A, 0xB8, 0xD6,
  28046. 0xE5, 0xCC, 0x92, 0xAC, 0x8E, 0xD3, 0xC1, 0x85,
  28047. 0xDA, 0xA8, 0xBC, 0x29, 0xF0, 0x57, 0x8E, 0xBB,
  28048. 0x81, 0x2B, 0x97, 0xC9, 0xE5, 0xA8, 0x48, 0xA6,
  28049. 0x38, 0x4D, 0xE4, 0xE7, 0x5A, 0x31, 0x47, 0x0B,
  28050. 0x53, 0x06, 0x6A, 0x8D, 0x02, 0x7B, 0xA4, 0x4B,
  28051. 0x21, 0x74, 0x9C, 0x04, 0x92, 0x46, 0x5F, 0x90,
  28052. 0x72, 0xB2, 0x83, 0x76, 0xC4, 0xE2, 0x90, 0xB3,
  28053. 0x0C, 0x18, 0x63, 0xF9, 0xE5, 0xB7, 0x99, 0x96,
  28054. 0x08, 0x34, 0x22, 0xBD, 0x8C, 0x27, 0x2C, 0x10,
  28055. 0xEC, 0xC6, 0xEB, 0x9A, 0x0A, 0x82, 0x25, 0xB3,
  28056. 0x1A, 0xA0, 0xA6, 0x6E, 0x35, 0xB9, 0xC0, 0xB9,
  28057. 0xA7, 0x95, 0x82, 0xBA, 0x20, 0xA3, 0xC0, 0x4C,
  28058. 0xD2, 0x99, 0x14, 0xF0, 0x83, 0xA0, 0x15, 0x82,
  28059. 0x88, 0xBA, 0x4D, 0x6E, 0xB6, 0x2D, 0x87, 0x26,
  28060. 0x4B, 0x91, 0x2B, 0xCA, 0x39, 0x73, 0x2F, 0xBD,
  28061. 0xE5, 0x36, 0xA3, 0x77, 0xAD, 0x02, 0xB8, 0xC8,
  28062. 0x35, 0xD4, 0xA2, 0xF4, 0xE7, 0xB1, 0xCE, 0x11,
  28063. 0x5D, 0x0C, 0x86, 0x0B, 0xEA, 0xA7, 0x95, 0x5A,
  28064. 0x49, 0xAD, 0x68, 0x95, 0x86, 0xA8, 0x9A, 0x2B,
  28065. 0x9F, 0x9B, 0x10, 0xD1, 0x59, 0x5D, 0x2F, 0xC0,
  28066. 0x65, 0xAD, 0x01, 0x8A, 0x7D, 0x56, 0xC6, 0x14,
  28067. 0x47, 0x1F, 0x8E, 0x94, 0x6F, 0xE8, 0xAB, 0x49,
  28068. 0xE8, 0x22, 0x65, 0x91, 0x11, 0x9F, 0xCA, 0xDB,
  28069. 0x4F, 0x9A, 0x86, 0x16, 0x31, 0x37, 0x87, 0x36,
  28070. 0xB6, 0x68, 0x8B, 0x78, 0x2D, 0x58, 0xE9, 0x7E,
  28071. 0x45, 0x72, 0x75, 0x3A, 0x96, 0x64, 0xB6, 0xB8,
  28072. 0x53, 0x68, 0x12, 0xB2, 0x59, 0x11, 0xAA, 0x76,
  28073. 0xA2, 0x42, 0x37, 0x54, 0x33, 0x19, 0x27, 0x38,
  28074. 0xEE, 0xE7, 0x62, 0xF6, 0xB8, 0x43, 0x15, 0xBB,
  28075. 0x34, 0x36, 0x23, 0x1E, 0x0A, 0x9B, 0x27, 0x7E,
  28076. 0xD2, 0x8A, 0xE0, 0x05, 0x07, 0x28, 0x34, 0x64,
  28077. 0x57, 0xE1, 0x34, 0x05, 0x06, 0x2D, 0xB2, 0x80,
  28078. 0x4B, 0x8D, 0xA6, 0x0B, 0xB5, 0xC7, 0x93, 0xD4,
  28079. 0xCC, 0x0E, 0x10, 0x1C, 0xBA, 0x2D, 0x91, 0x82,
  28080. 0xFD, 0x71, 0x24, 0xFF, 0x52, 0xBF, 0x4C, 0xA2,
  28081. 0x82, 0x92, 0xAC, 0x26, 0xD6, 0x78, 0x08, 0x89,
  28082. 0x53, 0x97, 0x1D, 0xBA, 0x0B, 0x6F, 0xEC, 0x2C,
  28083. 0x96, 0x59, 0x35, 0x32, 0x91, 0xC7, 0x0C, 0x5B,
  28084. 0x92, 0x45, 0xA0, 0xCA, 0x25, 0x33, 0x04, 0xAF,
  28085. 0xD3, 0xC9, 0x51, 0x02, 0xBE, 0xA6, 0x68, 0x75,
  28086. 0xC6, 0x20, 0x16, 0x80, 0xB4, 0xBD, 0xA3, 0x86,
  28087. 0x87, 0xB6, 0x48, 0xC2, 0x8E, 0xB3, 0x74, 0x78,
  28088. 0xE3, 0xBC, 0x00, 0xCA, 0x8A, 0x3C, 0xC2, 0x72,
  28089. 0x04, 0x64, 0x2B, 0x42, 0xB6, 0x8F, 0xCB, 0xE7,
  28090. 0xB2, 0x1A, 0x36, 0x6D, 0x06, 0x68, 0xA5, 0x02,
  28091. 0x9A, 0x7D, 0xEE, 0xF9, 0x4C, 0xDD, 0x6A, 0x95,
  28092. 0xD7, 0xEA, 0x89, 0x31, 0x67, 0x3B, 0xF7, 0x11,
  28093. 0x2D, 0x40, 0x42, 0x10, 0x7B, 0x1B, 0x8B, 0x97,
  28094. 0x00, 0xC9, 0x74, 0xF9, 0xC4, 0xE8, 0x3A, 0x8F,
  28095. 0xAC, 0xD8, 0x9B, 0xFE, 0x0C, 0xA3, 0xCC, 0x4C,
  28096. 0x2F, 0xCE, 0x80, 0xA0, 0x3D, 0x35, 0x76, 0xC2,
  28097. 0x22, 0xA7, 0x92, 0xB7, 0x2B, 0x1F, 0x07, 0x0A,
  28098. 0xB7, 0xF6, 0xB6, 0xF2, 0xB5, 0xCA, 0x2A, 0xF5,
  28099. 0x05, 0x4A, 0xFA, 0x70, 0xA8, 0x96, 0x99, 0x01,
  28100. 0x59, 0xB4, 0x5D, 0x10, 0x03, 0xE2, 0xA0, 0x56,
  28101. 0x48, 0x67, 0x5E, 0x59, 0x60, 0x16, 0xF1, 0xB7,
  28102. 0x1D, 0xD0, 0xF7, 0xBD, 0xA7, 0xE2, 0x09, 0x7F,
  28103. 0xC7, 0x3B, 0x3A, 0x14, 0x3D, 0x12, 0xC7, 0x26,
  28104. 0x02, 0x0A, 0xC3, 0x49, 0x58, 0xAD, 0x70, 0x62,
  28105. 0xB9, 0x2B, 0x9A, 0xBF, 0x3C, 0xA6, 0xBE, 0x5A,
  28106. 0xE2, 0x9F, 0x57, 0x13, 0x5E, 0x62, 0x5A, 0x36,
  28107. 0x79, 0x71, 0x83, 0x7E, 0x63, 0x63, 0xD1, 0x53,
  28108. 0x20, 0x94, 0xE0, 0x22, 0xA2, 0x34, 0x67, 0xCF,
  28109. 0x93, 0x2E, 0x1F, 0x89, 0xB5, 0xB0, 0x80, 0x3C,
  28110. 0x1E, 0xC9, 0x9B, 0x58, 0x5A, 0x78, 0xB5, 0x86,
  28111. 0x50, 0x96, 0x74, 0x6F, 0x32, 0x25, 0x82, 0x14,
  28112. 0xEC, 0xB3, 0x80, 0x65, 0xC9, 0x7F, 0x45, 0x5E,
  28113. 0x15, 0x5A, 0xCC, 0x2D, 0xD0, 0x05, 0xA9, 0xC7,
  28114. 0x6B, 0xED, 0x59, 0xCD, 0xA7, 0x38, 0x37, 0xD3,
  28115. 0x03, 0x50, 0x4E, 0x6C, 0x97, 0x6A, 0x60, 0x6A,
  28116. 0x2B, 0xE7, 0xBB, 0xEC, 0x59, 0x48, 0xB9, 0x1A,
  28117. 0x34, 0x9E, 0x89, 0x36, 0x68, 0x8C, 0xC0, 0x27,
  28118. 0x97, 0x54, 0xB7, 0x43, 0xAB, 0xC5, 0x86, 0x66,
  28119. 0xB1, 0x9B, 0x6C, 0x32, 0x60, 0x05, 0x1F, 0x19,
  28120. 0x20, 0x6B, 0xB9, 0x62, 0xBB, 0x66, 0x33, 0xEB,
  28121. 0x00, 0x48, 0xE3, 0x2B, 0xAA, 0xCC, 0x5B, 0x02,
  28122. 0x0D, 0x02, 0xC8, 0x6C, 0xA9, 0x77, 0x0A, 0xD4,
  28123. 0x69, 0xDB, 0x54, 0xA1, 0x06, 0xAC, 0x73, 0xA3,
  28124. 0x5B, 0x80, 0x57, 0x42, 0x2B, 0x3D, 0xB2, 0x02,
  28125. 0xC5, 0xA5, 0xB4, 0xE3, 0xD5, 0x35, 0xF0, 0xFC,
  28126. 0x99, 0x32, 0x6C, 0x4B, 0x8B, 0x7B, 0x16, 0xF1,
  28127. 0xCB, 0x5A, 0xF9, 0x68, 0x03, 0xFA, 0x8C, 0x19,
  28128. 0x5F, 0xC0, 0xBC, 0xED, 0xDA, 0xAF, 0x01, 0x2A,
  28129. 0x51, 0x72, 0x8B, 0x76, 0x48, 0x90, 0x82, 0x37,
  28130. 0x3C, 0x91, 0xE9, 0x2C, 0x87, 0xAC, 0xCA, 0x79,
  28131. 0x51, 0x60, 0x78, 0x2E, 0x3B, 0x0D, 0xD6, 0x43,
  28132. 0x54, 0x4B, 0xB9, 0x6A, 0xBC, 0x27, 0x08, 0xD4,
  28133. 0x9B, 0x75, 0x9C, 0xF0, 0x57, 0xAA, 0x22, 0x3B,
  28134. 0xAF, 0xD9, 0x6A, 0x33, 0x0B, 0xAF, 0x39, 0x81,
  28135. 0x0F, 0xE8, 0x67, 0x1B, 0x43, 0x43, 0xC2, 0x97,
  28136. 0xDA, 0x1E, 0x19, 0x69, 0xC9, 0x96, 0x21, 0x6A,
  28137. 0xB5, 0x10, 0x6D, 0xA6, 0x68, 0x94, 0x1B, 0x16,
  28138. 0x0D, 0x44, 0x77, 0x01, 0x71, 0x36, 0xCB, 0xCA,
  28139. 0x5B, 0x5A, 0x8D, 0x44, 0xC4, 0xA8, 0xB1, 0xCF,
  28140. 0x3E, 0xF7, 0x97, 0x85, 0xE5, 0xAA, 0x25, 0xC3,
  28141. 0xA1, 0xAD, 0x6C, 0x24, 0xFD, 0x14, 0x0F, 0x79,
  28142. 0x20, 0x7D, 0xE5, 0xA4, 0x99, 0xF8, 0xA1, 0x53,
  28143. 0x4F, 0xFA, 0x80, 0x4A, 0xA7, 0xB3, 0x88, 0x9C,
  28144. 0xBE, 0x25, 0xC0, 0x41, 0x47, 0x04, 0xAA, 0x57,
  28145. 0x89, 0x7F, 0x17, 0x86, 0x23, 0x64, 0xEC, 0xA5,
  28146. 0x62, 0x58, 0x00, 0x72, 0x48, 0x81, 0x39, 0x12,
  28147. 0xB8, 0x36, 0x49, 0x7F, 0x03, 0x59, 0xC2, 0xF7,
  28148. 0x23, 0x8A, 0x05, 0xD3, 0x05, 0xA0, 0xEA, 0x15,
  28149. 0x2E, 0x72, 0xB4, 0x44, 0x17, 0xA8, 0x68, 0x13,
  28150. 0x4E, 0x91, 0xB3, 0xCA, 0x79, 0x31, 0x23, 0x2F,
  28151. 0xD4, 0xC2, 0x5F, 0x8C, 0x2A, 0x49, 0x2A, 0x33,
  28152. 0x9C, 0xDC, 0x0A, 0x13, 0x89, 0x67, 0x21, 0x14,
  28153. 0x51, 0xF2, 0x56, 0x26, 0x78, 0xFA, 0x14, 0x08,
  28154. 0x0A, 0x34, 0x43, 0x6C, 0x42, 0xB0, 0x78, 0x65,
  28155. 0xAC, 0x03, 0x6A, 0x81, 0xE9, 0x7A, 0x77, 0x87,
  28156. 0xA9, 0x38, 0x02, 0x5C, 0xAF, 0x81, 0x34, 0x50,
  28157. 0x36, 0x8B, 0xED, 0x0C, 0x94, 0xB1, 0x85, 0x76,
  28158. 0x04, 0x52, 0x64, 0x05, 0xD2, 0x7A, 0x1C, 0x1A,
  28159. 0xBC, 0x81, 0xB5, 0xB6, 0xEC, 0x13, 0xC7, 0x19,
  28160. 0x30, 0xA9, 0x7D, 0x92, 0x32, 0xCF, 0x70, 0x21,
  28161. 0xEF, 0x87, 0xA4, 0xD1, 0x55, 0x32, 0x8E, 0x62,
  28162. 0xB5, 0x83, 0xA8, 0x3B, 0x4A, 0xF2, 0x1F, 0x9F,
  28163. 0x57, 0x50, 0xF8, 0x57, 0x51, 0x50, 0x42, 0x4F,
  28164. 0x63, 0xB8, 0x99, 0xD7, 0x1C, 0xAD, 0x26, 0x7C,
  28165. 0x09, 0xE4, 0x46, 0x71, 0x46, 0xE1, 0x6E, 0x9B,
  28166. 0x6C, 0x65, 0x3F, 0x00, 0x8C, 0x31, 0x13, 0x75,
  28167. 0xE2, 0xE0, 0x06, 0xD4, 0x07, 0x6A, 0x54, 0x6B,
  28168. 0x82, 0xF5, 0x31, 0x42, 0x22, 0xF7, 0xC6, 0x54,
  28169. 0x31, 0x7E, 0x79, 0xEC, 0x60, 0x35, 0xB7, 0x3F,
  28170. 0xAF, 0x49, 0x17, 0x57, 0xE6, 0x1C, 0x82, 0x83,
  28171. 0x26, 0xD5, 0x30, 0x44, 0x54, 0x1C, 0x4D, 0x45,
  28172. 0x37, 0xAB, 0xD3, 0xEA, 0x1E, 0x67, 0x99, 0x8C,
  28173. 0x33, 0x82, 0x97, 0x4C, 0xA7, 0x8A, 0xE1, 0xB1,
  28174. 0x96, 0x0E, 0x4A, 0x92, 0x26, 0xB0, 0x21, 0x9A,
  28175. 0xB0, 0x70, 0xF0, 0xD7, 0xAA, 0x66, 0xD7, 0x6F,
  28176. 0x93, 0x16, 0xAD, 0xB8, 0x0C, 0x54, 0xD6, 0x49,
  28177. 0x97, 0x71, 0xB4, 0x71, 0xE8, 0x16, 0x8D, 0x47,
  28178. 0xBC, 0xAA, 0x08, 0x32, 0x4A, 0xB6, 0xBA, 0x92,
  28179. 0xC3, 0xA7, 0x02, 0x75, 0xF2, 0x4F, 0xA4, 0xDC,
  28180. 0x10, 0xE2, 0x51, 0x63, 0x3F, 0xB9, 0x8D, 0x16,
  28181. 0x2B, 0xB5, 0x53, 0x72, 0x02, 0xC6, 0xA5, 0x53,
  28182. 0xCE, 0x78, 0x41, 0xC4, 0xD4, 0x0B, 0x87, 0x3B,
  28183. 0x85, 0xCA, 0x03, 0xA0, 0xA1, 0xE1, 0xCF, 0xAD,
  28184. 0xE6, 0xBA, 0x51, 0x80, 0xAB, 0x13, 0x23, 0xCC,
  28185. 0xBA, 0x9A, 0x3E, 0x9C, 0x53, 0xD3, 0x75, 0x75,
  28186. 0xAB, 0x1F, 0xD9, 0xE7, 0x31, 0x6C, 0x6F, 0xEE,
  28187. 0xCB, 0x0A, 0x14, 0xDF, 0x6F, 0x2D, 0xA5, 0x6C,
  28188. 0x2F, 0x56, 0xF5, 0x5A, 0x89, 0x63, 0x5C, 0xFC,
  28189. 0xFD, 0xA4, 0x79, 0x27, 0xAF, 0x1F, 0x0A, 0x47,
  28190. 0xB2, 0xD4, 0xE4, 0xE6, 0x16, 0x34, 0xB1, 0xB5,
  28191. 0x1D, 0x37, 0xA3, 0xA3, 0x07, 0xA9, 0x72, 0x42,
  28192. 0x0D, 0xE1, 0xB7, 0xA4, 0x81, 0xB8, 0x3E, 0x58,
  28193. 0x3B, 0x6A, 0xF1, 0x6F, 0x63, 0xCB, 0x00, 0xC6
  28194. };
  28195. static const byte c_1024[KYBER1024_CIPHER_TEXT_SIZE] = {
  28196. 0x0C, 0x68, 0x1B, 0x4A, 0xA8, 0x1F, 0x26, 0xAD,
  28197. 0xFB, 0x64, 0x5E, 0xC2, 0x4B, 0x37, 0x52, 0xF6,
  28198. 0xB3, 0x2C, 0x68, 0x64, 0x5A, 0xA5, 0xE7, 0xA9,
  28199. 0x99, 0xB6, 0x20, 0x36, 0xA5, 0x3D, 0xC5, 0xCB,
  28200. 0x06, 0x0A, 0x47, 0x3C, 0x08, 0xE5, 0xDA, 0x5C,
  28201. 0x0F, 0x5A, 0xF0, 0xE5, 0x17, 0x0C, 0x65, 0x97,
  28202. 0xE5, 0x0E, 0xC0, 0x80, 0x60, 0xF9, 0x9B, 0x0C,
  28203. 0x00, 0xEE, 0x9B, 0xDD, 0xAD, 0x7E, 0x7D, 0x25,
  28204. 0xA2, 0x2B, 0x22, 0x6F, 0x90, 0x14, 0x9B, 0x4C,
  28205. 0xE8, 0x87, 0xC7, 0x2F, 0xB6, 0x0A, 0xFF, 0x21,
  28206. 0x44, 0xEA, 0x2A, 0x72, 0x38, 0x3B, 0x31, 0x18,
  28207. 0xF9, 0x22, 0xD0, 0x32, 0xA1, 0x6F, 0x55, 0x42,
  28208. 0x89, 0x90, 0x2A, 0x14, 0xCF, 0x77, 0x55, 0x51,
  28209. 0x2B, 0xB1, 0x18, 0x6B, 0xAF, 0xAF, 0xFE, 0x79,
  28210. 0x4D, 0x2B, 0x6C, 0xDE, 0x90, 0x10, 0x9E, 0x65,
  28211. 0x82, 0xD3, 0x9C, 0xE0, 0xC9, 0x61, 0x97, 0x48,
  28212. 0x4B, 0x3F, 0xA0, 0x7F, 0xC9, 0x1D, 0x39, 0x4F,
  28213. 0xC8, 0xD8, 0x8E, 0x7F, 0xC4, 0xBE, 0x00, 0x2E,
  28214. 0x2D, 0xB5, 0x6F, 0x0C, 0x4D, 0x9D, 0x3F, 0xBD,
  28215. 0xA2, 0x74, 0x53, 0x6A, 0x0B, 0x86, 0xAB, 0xC6,
  28216. 0xE3, 0x9B, 0xDA, 0x52, 0x93, 0x1A, 0xEB, 0xB8,
  28217. 0xF1, 0x08, 0x4C, 0x5C, 0x1F, 0x7C, 0xB3, 0x17,
  28218. 0x77, 0x88, 0xB7, 0xF3, 0x31, 0xB7, 0x07, 0x43,
  28219. 0x61, 0x16, 0x34, 0x91, 0xD4, 0x28, 0xE7, 0x8B,
  28220. 0xCB, 0xB5, 0x7B, 0x63, 0x08, 0x41, 0xAA, 0x98,
  28221. 0x73, 0x33, 0x37, 0x7C, 0xF0, 0x95, 0x69, 0xCF,
  28222. 0xD1, 0x4C, 0xC2, 0xA1, 0x1C, 0x50, 0x1B, 0xDF,
  28223. 0x82, 0xC9, 0x3D, 0xE0, 0x5B, 0xEA, 0x20, 0x06,
  28224. 0x0D, 0xE8, 0x9C, 0x68, 0x6B, 0x82, 0x45, 0x71,
  28225. 0xCE, 0xF9, 0x4A, 0xB3, 0xFD, 0xAF, 0xA8, 0x51,
  28226. 0x26, 0x19, 0x81, 0x36, 0x69, 0xD4, 0xF5, 0x36,
  28227. 0x37, 0xFE, 0xFA, 0x4D, 0x02, 0x8C, 0xB2, 0x33,
  28228. 0xE5, 0x69, 0x30, 0xE2, 0x23, 0x5F, 0x7E, 0x60,
  28229. 0x34, 0xCA, 0x94, 0xB1, 0x43, 0xB7, 0x7A, 0xD4,
  28230. 0xA6, 0x87, 0x56, 0xE8, 0xA9, 0x18, 0x4D, 0xBA,
  28231. 0x61, 0xA8, 0x9F, 0x91, 0xED, 0xFB, 0x51, 0xA3,
  28232. 0x92, 0x11, 0x40, 0x24, 0x73, 0xA5, 0xF8, 0x91,
  28233. 0x45, 0x73, 0x6B, 0x2B, 0xF8, 0x56, 0x9C, 0x70,
  28234. 0x5B, 0x0C, 0xDB, 0x89, 0x80, 0xA4, 0x47, 0xE4,
  28235. 0xE1, 0xEA, 0xAD, 0x3E, 0x7E, 0x05, 0x78, 0xF5,
  28236. 0xF8, 0x6B, 0x8D, 0x03, 0xC9, 0xDA, 0xFE, 0x87,
  28237. 0x5E, 0x33, 0x9B, 0x44, 0x23, 0x84, 0x56, 0x16,
  28238. 0x79, 0x9E, 0xDC, 0xE0, 0x5F, 0x31, 0xB9, 0x26,
  28239. 0x64, 0xC5, 0xA5, 0x92, 0x53, 0xA6, 0x0E, 0x9D,
  28240. 0x89, 0x54, 0x8A, 0x30, 0x0C, 0x1A, 0xDB, 0x6D,
  28241. 0x19, 0x0A, 0x77, 0x5C, 0x5E, 0xE6, 0xE8, 0xA8,
  28242. 0x9B, 0x6E, 0x77, 0x9B, 0x03, 0x4C, 0x34, 0x00,
  28243. 0xA6, 0x25, 0xF4, 0xBB, 0xED, 0xBF, 0x91, 0x9C,
  28244. 0x45, 0xB2, 0xBC, 0xD1, 0x4C, 0x66, 0x92, 0x48,
  28245. 0xFC, 0x43, 0xC3, 0xEF, 0x47, 0xE1, 0x00, 0x75,
  28246. 0x89, 0x42, 0xE7, 0x5E, 0x8E, 0xD6, 0x07, 0x5A,
  28247. 0x96, 0xD7, 0x0D, 0x4E, 0xBD, 0x2B, 0x61, 0x35,
  28248. 0x82, 0x24, 0xDD, 0xA1, 0xEC, 0x4C, 0x19, 0xC2,
  28249. 0xA9, 0x28, 0x98, 0x17, 0x6F, 0xEB, 0x3C, 0x02,
  28250. 0xED, 0xCB, 0x99, 0x08, 0xBA, 0xE4, 0x9B, 0xD9,
  28251. 0x4A, 0xF0, 0x28, 0xED, 0xF8, 0xCF, 0xC2, 0xE5,
  28252. 0xF2, 0xE0, 0xBD, 0x37, 0x50, 0x06, 0x98, 0x6A,
  28253. 0xD4, 0x9E, 0x71, 0x75, 0x48, 0xE7, 0x46, 0xFE,
  28254. 0xF4, 0x9C, 0x86, 0x8B, 0xCE, 0xA2, 0x79, 0x0A,
  28255. 0xA9, 0x7E, 0x04, 0x06, 0x1B, 0x75, 0x60, 0x5C,
  28256. 0xB3, 0x9E, 0xFD, 0x46, 0x3D, 0x7B, 0x3D, 0x68,
  28257. 0xBA, 0x57, 0x44, 0x34, 0xFF, 0x7B, 0xE8, 0xE2,
  28258. 0xB8, 0x4B, 0xFC, 0x47, 0xE6, 0x7E, 0x9C, 0xD1,
  28259. 0x5F, 0x3E, 0xD4, 0x50, 0xC6, 0x1A, 0xFB, 0xA7,
  28260. 0x9A, 0x20, 0xB0, 0xB6, 0xF2, 0x87, 0x77, 0x7C,
  28261. 0x72, 0xF4, 0xAD, 0x24, 0x81, 0x74, 0xF1, 0x95,
  28262. 0x94, 0x77, 0xAA, 0x7A, 0x7C, 0x97, 0xF1, 0x22,
  28263. 0xC5, 0x04, 0x47, 0xC7, 0x48, 0x4F, 0x38, 0x2B,
  28264. 0xC4, 0x7D, 0x81, 0xFC, 0xC9, 0xC7, 0xE8, 0x92,
  28265. 0xC8, 0x83, 0x9D, 0x37, 0xB3, 0x53, 0x94, 0xB5,
  28266. 0x3E, 0x6B, 0x2B, 0x18, 0x95, 0xAB, 0xB0, 0xDE,
  28267. 0x8C, 0x98, 0xF2, 0x63, 0x3D, 0xC4, 0x41, 0x3A,
  28268. 0x8D, 0x57, 0x35, 0xDF, 0xC9, 0xA6, 0x40, 0x26,
  28269. 0xB6, 0xF3, 0x47, 0x79, 0xD6, 0xAC, 0x8A, 0xD9,
  28270. 0x9C, 0xC3, 0x1A, 0xA8, 0x98, 0xC2, 0xE7, 0x05,
  28271. 0x7F, 0x3D, 0xB8, 0xA1, 0xA8, 0xA9, 0x85, 0x27,
  28272. 0xA7, 0x9E, 0x43, 0x55, 0x2F, 0x28, 0xD1, 0x02,
  28273. 0x3E, 0x1F, 0x6A, 0x6B, 0x84, 0x85, 0x5C, 0xF5,
  28274. 0xE6, 0xDF, 0x88, 0x9B, 0xA2, 0x69, 0xF0, 0x48,
  28275. 0x94, 0x6E, 0x84, 0x02, 0x1C, 0x65, 0xC5, 0xA9,
  28276. 0x3B, 0x00, 0x7B, 0x07, 0x74, 0x1C, 0x1E, 0xE1,
  28277. 0x76, 0xC7, 0x39, 0x49, 0x11, 0x0F, 0x54, 0x8E,
  28278. 0xF4, 0x33, 0x2D, 0xCD, 0xD4, 0x91, 0xD2, 0xCE,
  28279. 0xFD, 0x02, 0x48, 0x88, 0x3F, 0x5E, 0x95, 0x25,
  28280. 0xBC, 0x91, 0xF3, 0x0A, 0xF1, 0x7C, 0xF5, 0xA9,
  28281. 0x8D, 0xD4, 0x4E, 0xF9, 0xA7, 0x1F, 0x99, 0xBB,
  28282. 0x73, 0x29, 0x85, 0xBA, 0x10, 0xA7, 0x23, 0xEF,
  28283. 0x47, 0x6F, 0xCF, 0x96, 0x6D, 0xA9, 0x45, 0x6B,
  28284. 0x24, 0x97, 0x8E, 0x33, 0x05, 0x0D, 0x0E, 0xC9,
  28285. 0x0D, 0x3C, 0xE4, 0x63, 0x78, 0x85, 0x1C, 0x9E,
  28286. 0xCF, 0xCF, 0xD3, 0x6C, 0x89, 0x5D, 0x44, 0xE9,
  28287. 0xE5, 0x06, 0x99, 0x30, 0x82, 0x52, 0x3D, 0x26,
  28288. 0x18, 0x57, 0x66, 0xB2, 0x35, 0x68, 0xCB, 0x95,
  28289. 0xE6, 0x41, 0x08, 0xF8, 0x9D, 0x10, 0x14, 0x74,
  28290. 0x7C, 0x67, 0xB6, 0xF3, 0xC8, 0x76, 0x7B, 0xE5,
  28291. 0xFC, 0x34, 0x12, 0x27, 0xDE, 0x94, 0x88, 0x86,
  28292. 0x1C, 0x5F, 0xE8, 0x11, 0x40, 0x9F, 0x80, 0x95,
  28293. 0x7D, 0x07, 0x52, 0x2A, 0x72, 0xCF, 0x6A, 0xB0,
  28294. 0x37, 0x8D, 0x0F, 0x2F, 0x28, 0xAF, 0x54, 0x81,
  28295. 0x85, 0xC3, 0x93, 0x67, 0x77, 0x99, 0x44, 0x66,
  28296. 0xA0, 0x19, 0xD3, 0x3B, 0x18, 0xA5, 0x4F, 0x38,
  28297. 0x0A, 0x33, 0x89, 0x2A, 0xB4, 0xD4, 0xBD, 0x50,
  28298. 0x7B, 0x5A, 0x61, 0xD0, 0xD3, 0x58, 0x34, 0x1A,
  28299. 0xC9, 0x2F, 0x07, 0xB4, 0x3B, 0x8F, 0x6A, 0xFC,
  28300. 0x69, 0x91, 0xBB, 0x6A, 0x1E, 0xAC, 0x23, 0xCA,
  28301. 0x6F, 0x73, 0xE9, 0x1F, 0x24, 0x64, 0xBD, 0x11,
  28302. 0x90, 0x98, 0xD7, 0xE7, 0x68, 0xE7, 0x7E, 0xCE,
  28303. 0x53, 0xFB, 0x89, 0x9B, 0xEB, 0x42, 0x26, 0x5E,
  28304. 0xCF, 0x7B, 0x27, 0x1F, 0x66, 0x54, 0x62, 0x82,
  28305. 0xD4, 0x72, 0xC3, 0x62, 0x39, 0x00, 0x6B, 0xB0,
  28306. 0xAB, 0xAB, 0xCC, 0xA2, 0x45, 0x50, 0xBA, 0xA0,
  28307. 0xA6, 0x01, 0x34, 0x8C, 0x81, 0x0F, 0xF5, 0xF9,
  28308. 0xEE, 0x50, 0x4B, 0xF7, 0x15, 0x5D, 0xEE, 0x41,
  28309. 0x41, 0xA1, 0x16, 0x05, 0xA4, 0xF3, 0x50, 0x9A,
  28310. 0xC9, 0xCA, 0xEF, 0x66, 0x24, 0xD2, 0x1D, 0xE3,
  28311. 0x32, 0xD5, 0xD5, 0x08, 0x28, 0xB5, 0x2E, 0x92,
  28312. 0x88, 0x5D, 0x3B, 0x90, 0x55, 0x3B, 0x14, 0x46,
  28313. 0x3A, 0xFB, 0x1E, 0xDC, 0xCD, 0x3B, 0x56, 0x9B,
  28314. 0x5A, 0x7F, 0x00, 0xBB, 0x66, 0x76, 0x9D, 0xAD,
  28315. 0xAC, 0x23, 0xAD, 0x8B, 0xB5, 0xD7, 0x3A, 0x6F,
  28316. 0x39, 0x0E, 0x6F, 0xC2, 0xF6, 0xF8, 0xEE, 0x3C,
  28317. 0xF4, 0x00, 0x9A, 0x5C, 0x3E, 0x1E, 0xF6, 0x0E,
  28318. 0x8F, 0x04, 0x06, 0x72, 0xD2, 0x62, 0xE6, 0x49,
  28319. 0x03, 0x79, 0xBB, 0xC7, 0x04, 0x95, 0xDF, 0xF2,
  28320. 0x37, 0xBE, 0xCD, 0x99, 0x52, 0xCD, 0x7E, 0xDE,
  28321. 0xB6, 0xD1, 0xDF, 0xC3, 0x60, 0xB3, 0xFC, 0x8B,
  28322. 0x0A, 0xF4, 0x80, 0xFF, 0xE0, 0x24, 0xAE, 0xEF,
  28323. 0xCD, 0x4E, 0x9C, 0xE9, 0x5D, 0x9B, 0x46, 0x9C,
  28324. 0x9A, 0x70, 0xE5, 0x11, 0x0D, 0xA0, 0xBA, 0xC1,
  28325. 0x24, 0xFC, 0x37, 0x41, 0xDC, 0xF4, 0x91, 0x16,
  28326. 0x26, 0x17, 0x96, 0x50, 0x4D, 0x5F, 0x49, 0x0B,
  28327. 0x43, 0x3C, 0x33, 0xC4, 0x0E, 0xDC, 0xE2, 0xB7,
  28328. 0x51, 0x51, 0xDA, 0x25, 0x6A, 0x86, 0x8A, 0x5E,
  28329. 0x35, 0xF8, 0x62, 0x26, 0xB8, 0x15, 0x1C, 0x91,
  28330. 0x93, 0x4C, 0xCC, 0x3D, 0xAC, 0xA3, 0x91, 0xDE,
  28331. 0xCC, 0xA7, 0x45, 0x37, 0x56, 0x60, 0xB6, 0xEC,
  28332. 0x41, 0xAE, 0x5D, 0x81, 0x08, 0x38, 0xCB, 0xEE,
  28333. 0xFF, 0xA1, 0x25, 0x57, 0x88, 0x44, 0x12, 0x35,
  28334. 0x7B, 0x10, 0x08, 0x36, 0x3D, 0x32, 0xB2, 0x37,
  28335. 0xAA, 0x1D, 0xD8, 0xE2, 0xD9, 0xC6, 0x36, 0x7A,
  28336. 0xDA, 0x09, 0xB2, 0xC9, 0x50, 0x60, 0x20, 0x6C,
  28337. 0xEC, 0x3E, 0xED, 0x39, 0x1F, 0xDC, 0x5D, 0xBE,
  28338. 0xF6, 0xF0, 0x8B, 0xDF, 0x04, 0x08, 0xE5, 0x85,
  28339. 0xAE, 0x5E, 0xBC, 0x8E, 0x97, 0x45, 0xD4, 0x4F,
  28340. 0xEC, 0xA9, 0x75, 0xAB, 0xBC, 0x14, 0x0B, 0xB3,
  28341. 0x7B, 0x8A, 0xDD, 0x16, 0xFC, 0xC2, 0x95, 0x69,
  28342. 0x10, 0xDC, 0x72, 0xBB, 0x3F, 0x02, 0xE9, 0xA1,
  28343. 0x30, 0xC9, 0xA8, 0x4F, 0x9C, 0xCB, 0x74, 0xD1,
  28344. 0x34, 0xCD, 0xF4, 0x0A, 0xFC, 0xBA, 0x20, 0x09,
  28345. 0xC8, 0xF0, 0x04, 0x02, 0x39, 0xBC, 0x99, 0x22,
  28346. 0x0E, 0xF6, 0x4C, 0x4D, 0xCC, 0xDE, 0x2E, 0x2E,
  28347. 0x5C, 0x9B, 0x68, 0x60, 0x2F, 0xBE, 0x8E, 0xF4,
  28348. 0xC9, 0x8B, 0x34, 0x68, 0xC7, 0x9D, 0xF4, 0xE0,
  28349. 0x78, 0x51, 0x1B, 0xFB, 0x8A, 0xA3, 0xDA, 0x09,
  28350. 0x59, 0x7A, 0x02, 0x51, 0x1E, 0x7C, 0x21, 0xA7,
  28351. 0xCF, 0x66, 0xA9, 0x38, 0x43, 0xA9, 0x48, 0x68,
  28352. 0xF1, 0x9E, 0x85, 0x52, 0x55, 0x2E, 0x3A, 0xCD,
  28353. 0xF6, 0xCB, 0x81, 0x06, 0x34, 0xDB, 0x97, 0xCB,
  28354. 0xC4, 0xBB, 0x56, 0x97, 0x09, 0xDA, 0xD4, 0x84,
  28355. 0x56, 0x45, 0x44, 0x6F, 0xA8, 0xD2, 0x89, 0xFC,
  28356. 0x59, 0x30, 0x7B, 0x80, 0x1E, 0x60, 0xCE, 0x2A,
  28357. 0x91, 0xE0, 0x6E, 0x9C, 0x22, 0xC1, 0x6E, 0x2E,
  28358. 0x59, 0xBD, 0xE3, 0x8A, 0x41, 0x6B, 0xB1, 0xB4,
  28359. 0xAC, 0x54, 0x57, 0x43, 0x8F, 0xDC, 0x5D, 0x64,
  28360. 0x45, 0x0A, 0x89, 0xEC, 0xB8, 0x32, 0xC1, 0xBB,
  28361. 0x27, 0x9D, 0xBF, 0x59, 0x33, 0x46, 0x81, 0x77,
  28362. 0x6A, 0xC0, 0x04, 0x09, 0x84, 0x6D, 0x09, 0xD6,
  28363. 0xF6, 0x87, 0x77, 0x2E, 0x34, 0x08, 0x50, 0xAB,
  28364. 0x86, 0x73, 0x38, 0x42, 0x15, 0xE1, 0x2C, 0x8D,
  28365. 0x0F, 0x53, 0x1C, 0x45, 0x1E, 0x58, 0x49, 0x3E,
  28366. 0x0E, 0xE4, 0x15, 0xAD, 0x59, 0x4D, 0xF3, 0x8C,
  28367. 0x34, 0x40, 0x8C, 0x7E, 0xD9, 0xF0, 0xC3, 0x92,
  28368. 0xF1, 0x53, 0x46, 0x04, 0xEA, 0xC3, 0xD9, 0xC1,
  28369. 0x54, 0x65, 0xA9, 0xA4, 0x66, 0x32, 0x21, 0x4B,
  28370. 0x53, 0x69, 0x90, 0xD7, 0x80, 0x78, 0xE5, 0xBD,
  28371. 0x7E, 0xAE, 0x20, 0x13, 0xFF, 0xF8, 0xFD, 0xD8,
  28372. 0xB2, 0x75, 0xC8, 0x9D, 0x97, 0xC9, 0x35, 0x3D,
  28373. 0xF3, 0xC4, 0x2A, 0x28, 0xE8, 0x14, 0xD8, 0x46,
  28374. 0x8E, 0x2B, 0x48, 0xDB, 0x09, 0x76, 0xD8, 0x8F,
  28375. 0x5E, 0xEC, 0xEF, 0xEA, 0xFB, 0x8F, 0x7F, 0x4A,
  28376. 0xF2, 0x91, 0xA7, 0x28, 0xF6, 0x24, 0x9E, 0xCF,
  28377. 0x56, 0x22, 0x33, 0x92, 0x69, 0xAA, 0x94, 0x53,
  28378. 0x29, 0xE9, 0x19, 0xF8, 0xB4, 0x41, 0xC8, 0x3D,
  28379. 0x55, 0x07, 0xF3, 0x0D, 0xF0, 0xFD, 0x2B, 0x13,
  28380. 0xFF, 0x80, 0x6F, 0x52, 0x2D, 0xAA, 0x11, 0xAF,
  28381. 0x67, 0x6A, 0x51, 0x3C, 0x14, 0x9C, 0x70, 0xF0,
  28382. 0xD6, 0xE9, 0x9A, 0x88, 0x04, 0x50, 0xA5, 0x4E,
  28383. 0x04, 0x17, 0xFE, 0x3C, 0x1E, 0x51, 0x3E, 0x9D,
  28384. 0x92, 0x0E, 0x30, 0xA8, 0xB4, 0x28, 0x91, 0x26,
  28385. 0x7A, 0x2D, 0xC5, 0x0A, 0xD8, 0x1F, 0x98, 0x04,
  28386. 0x49, 0x20, 0xC0, 0x99, 0xDF, 0x22, 0xC7, 0x39,
  28387. 0x98, 0xA2, 0x5C, 0x58, 0x1A, 0x51, 0x78, 0xC7,
  28388. 0x2B, 0x17, 0xAC, 0x87, 0x5B, 0xC6, 0x85, 0x48,
  28389. 0xA0, 0xFB, 0x0C, 0xBE, 0xE3, 0x8F, 0x05, 0x01,
  28390. 0x7B, 0x12, 0x43, 0x33, 0x43, 0xA6, 0x58, 0xF1,
  28391. 0x98, 0x0C, 0x81, 0x24, 0xEA, 0x6D, 0xD8, 0x1F
  28392. };
  28393. static const byte kprime_1024[KYBER_SS_SZ] = {
  28394. 0x8F, 0x33, 0x6E, 0x9C, 0x28, 0xDF, 0x34, 0x9E,
  28395. 0x03, 0x22, 0x0A, 0xF0, 0x1C, 0x42, 0x83, 0x2F,
  28396. 0xEF, 0xAB, 0x1F, 0x2A, 0x74, 0xC1, 0x6F, 0xAF,
  28397. 0x6F, 0x64, 0xAD, 0x07, 0x1C, 0x1A, 0x33, 0x94
  28398. };
  28399. #endif
  28400. static byte ss[KYBER_SS_SZ];
  28401. key = (KyberKey*)XMALLOC(sizeof(KyberKey), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28402. ExpectNotNull(key);
  28403. if (key != NULL) {
  28404. XMEMSET(key, 0, sizeof(KyberKey));
  28405. }
  28406. #ifndef WOLFSSL_NO_KYBER512
  28407. ExpectIntEQ(wc_KyberKey_Init(KYBER512, key, NULL, INVALID_DEVID), 0);
  28408. ExpectIntEQ(wc_KyberKey_DecodePrivateKey(key, dk_512, sizeof(dk_512)), 0);
  28409. ExpectIntEQ(wc_KyberKey_Decapsulate(key, ss, c_512, sizeof(c_512)), 0);
  28410. ExpectIntEQ(XMEMCMP(ss, kprime_512, KYBER_SS_SZ), 0);
  28411. wc_KyberKey_Free(key);
  28412. #endif
  28413. #ifndef WOLFSSL_NO_KYBER768
  28414. ExpectIntEQ(wc_KyberKey_Init(KYBER768, key, NULL, INVALID_DEVID), 0);
  28415. ExpectIntEQ(wc_KyberKey_DecodePrivateKey(key, dk_768, sizeof(dk_768)), 0);
  28416. ExpectIntEQ(wc_KyberKey_Decapsulate(key, ss, c_768, sizeof(c_768)), 0);
  28417. ExpectIntEQ(XMEMCMP(ss, kprime_768, KYBER_SS_SZ), 0);
  28418. wc_KyberKey_Free(key);
  28419. #endif
  28420. #ifndef WOLFSSL_NO_KYBER1024
  28421. ExpectIntEQ(wc_KyberKey_Init(KYBER1024, key, NULL, INVALID_DEVID), 0);
  28422. ExpectIntEQ(wc_KyberKey_DecodePrivateKey(key, dk_1024, sizeof(dk_1024)), 0);
  28423. ExpectIntEQ(wc_KyberKey_Decapsulate(key, ss, c_1024, sizeof(c_1024)), 0);
  28424. ExpectIntEQ(XMEMCMP(ss, kprime_1024, KYBER_SS_SZ), 0);
  28425. wc_KyberKey_Free(key);
  28426. #endif
  28427. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28428. #endif
  28429. return EXPECT_RESULT();
  28430. }
  28431. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  28432. !defined(WOLFSSL_DILITHIUM_NO_VERIFY) && !defined(WOLFSSL_NO_ML_DSA_44)
  28433. static const byte ml_dsa_44_pub_key[] = {
  28434. 0x7c, 0x33, 0x31, 0x41, 0x15, 0xa7, 0x2d, 0x6b,
  28435. 0x17, 0x7c, 0x10, 0xab, 0x75, 0xf7, 0x83, 0xb3,
  28436. 0x30, 0x75, 0x6f, 0xa9, 0x42, 0xb0, 0x9b, 0x59,
  28437. 0x59, 0x99, 0x2b, 0x5d, 0x7d, 0x6e, 0xeb, 0xdd,
  28438. 0xd9, 0x99, 0x8f, 0x7b, 0xad, 0xe5, 0x90, 0x0f,
  28439. 0xa4, 0x80, 0xd8, 0xa2, 0x0d, 0x95, 0xea, 0x63,
  28440. 0x2b, 0xcf, 0xb4, 0x5b, 0x3c, 0xd1, 0x5a, 0xc4,
  28441. 0xc4, 0xd1, 0x71, 0x28, 0x4b, 0x0b, 0x28, 0x32,
  28442. 0x73, 0xb5, 0x0d, 0xd6, 0x8f, 0x6b, 0x01, 0x26,
  28443. 0x04, 0x45, 0xa3, 0x80, 0xc0, 0x21, 0x12, 0xee,
  28444. 0x52, 0x0f, 0x35, 0xe4, 0x8e, 0xca, 0xf8, 0x91,
  28445. 0xf4, 0x99, 0x51, 0xe2, 0x80, 0x76, 0xa7, 0x2d,
  28446. 0x09, 0xf5, 0x04, 0xcc, 0xa6, 0x6b, 0x20, 0xc4,
  28447. 0xac, 0xcd, 0x6c, 0x9c, 0x09, 0xe7, 0x51, 0xa2,
  28448. 0x29, 0x60, 0xfd, 0xf2, 0xbd, 0x7e, 0x4c, 0x9d,
  28449. 0xc0, 0xba, 0x62, 0x2f, 0x53, 0xb2, 0x47, 0x03,
  28450. 0xf2, 0x6f, 0x70, 0x51, 0xa8, 0xe1, 0xb7, 0x9f,
  28451. 0x37, 0x15, 0xfa, 0xd1, 0x6c, 0x74, 0x1a, 0x2b,
  28452. 0x4f, 0x39, 0x4f, 0x43, 0x49, 0x71, 0x6a, 0xf8,
  28453. 0x7c, 0x65, 0x1a, 0xdd, 0x1a, 0x25, 0xf8, 0x79,
  28454. 0xfa, 0x8c, 0x02, 0xf2, 0xf7, 0xf7, 0x7b, 0x9f,
  28455. 0xe4, 0xaf, 0x9e, 0x1a, 0x0b, 0x5b, 0x2e, 0x41,
  28456. 0xbb, 0xa9, 0x4f, 0xd0, 0xdb, 0xad, 0xe5, 0x25,
  28457. 0xff, 0x36, 0x3b, 0x9a, 0xc3, 0xdf, 0xb6, 0x27,
  28458. 0xd3, 0xba, 0xb0, 0xd4, 0xb2, 0x07, 0xc3, 0xd8,
  28459. 0xab, 0x10, 0x3d, 0xcd, 0x23, 0x52, 0x46, 0xe6,
  28460. 0x96, 0x57, 0x85, 0xc7, 0x60, 0xe2, 0x8c, 0x46,
  28461. 0x65, 0x7d, 0x76, 0x1c, 0x45, 0x20, 0x5d, 0x51,
  28462. 0xd6, 0x13, 0xde, 0xe5, 0x3d, 0xc2, 0x8c, 0x36,
  28463. 0xdb, 0x7f, 0x83, 0x6f, 0x6a, 0xc2, 0xa3, 0xf2,
  28464. 0xdc, 0x63, 0x69, 0x7f, 0xbd, 0xd0, 0xc1, 0x90,
  28465. 0xfb, 0x62, 0x42, 0xa1, 0xf6, 0xf7, 0xdd, 0xc2,
  28466. 0x4a, 0x38, 0x62, 0x9b, 0xef, 0x67, 0xf9, 0x5c,
  28467. 0xd8, 0xff, 0xf4, 0xf2, 0x67, 0x90, 0x42, 0x85,
  28468. 0xaf, 0xe2, 0x92, 0x6e, 0xc4, 0x9b, 0x63, 0xc3,
  28469. 0x91, 0xa5, 0x11, 0x66, 0x13, 0x83, 0xbc, 0xbb,
  28470. 0xc7, 0x34, 0x3b, 0x30, 0x40, 0x53, 0x91, 0xdf,
  28471. 0x7c, 0x3d, 0x17, 0xdd, 0xa1, 0xa6, 0x80, 0xfd,
  28472. 0x26, 0x9d, 0x60, 0x7b, 0xcd, 0xb4, 0x2b, 0xba,
  28473. 0x61, 0x0f, 0x43, 0x7c, 0x51, 0x3c, 0xb9, 0xfa,
  28474. 0xdb, 0x48, 0x35, 0x9f, 0x0d, 0x0c, 0x04, 0xe8,
  28475. 0xf9, 0x6e, 0x07, 0x65, 0x7d, 0x46, 0x1b, 0xd2,
  28476. 0x51, 0xdb, 0x55, 0x27, 0xd7, 0x3d, 0x1e, 0x36,
  28477. 0x07, 0x59, 0x18, 0xec, 0x04, 0x4b, 0x87, 0xbb,
  28478. 0xfb, 0x27, 0xac, 0xeb, 0x8f, 0x43, 0x46, 0xd0,
  28479. 0x39, 0x00, 0x90, 0x54, 0x70, 0xb1, 0x71, 0xf2,
  28480. 0xe7, 0x3d, 0x02, 0x1a, 0xcf, 0x87, 0x16, 0x67,
  28481. 0xa2, 0x3c, 0x31, 0x48, 0xe8, 0xbd, 0x4f, 0xb3,
  28482. 0xc2, 0xfd, 0x3d, 0xa1, 0x9c, 0x87, 0x54, 0x60,
  28483. 0x30, 0x21, 0x52, 0x57, 0xcd, 0x03, 0x96, 0x9e,
  28484. 0xa7, 0x8d, 0xe5, 0x02, 0x04, 0x78, 0x43, 0x72,
  28485. 0xda, 0xb2, 0x22, 0xf1, 0xee, 0x8f, 0x27, 0x0b,
  28486. 0x8f, 0x7b, 0xf8, 0xbc, 0x16, 0xa1, 0xef, 0x0b,
  28487. 0x35, 0xda, 0xfc, 0x29, 0x1b, 0xf8, 0xa1, 0x35,
  28488. 0x40, 0xe7, 0xed, 0x4c, 0x02, 0x4a, 0x83, 0xb7,
  28489. 0x49, 0x75, 0x34, 0x3f, 0x2b, 0xb3, 0x61, 0xf5,
  28490. 0xa3, 0x9b, 0x23, 0xca, 0xfb, 0x58, 0x16, 0x4f,
  28491. 0x3c, 0x50, 0xbf, 0x81, 0xab, 0x54, 0x50, 0x1a,
  28492. 0x39, 0x57, 0x5f, 0x9a, 0x72, 0x22, 0xba, 0xa4,
  28493. 0xf6, 0xbf, 0xac, 0x31, 0x5c, 0xc5, 0x96, 0xd7,
  28494. 0xa9, 0xe4, 0x3b, 0x0c, 0xd0, 0x7f, 0x79, 0x68,
  28495. 0x4d, 0x41, 0x04, 0x81, 0x73, 0xcf, 0x47, 0x4a,
  28496. 0x7b, 0x37, 0xac, 0x8e, 0x47, 0x0d, 0x72, 0x65,
  28497. 0x0f, 0x9d, 0x44, 0xd7, 0x08, 0x21, 0x5b, 0x3f,
  28498. 0xc8, 0x9d, 0xea, 0xa2, 0x64, 0x7b, 0x0d, 0x98,
  28499. 0xc1, 0x61, 0xcd, 0xa4, 0xf7, 0x8c, 0x4a, 0xa3,
  28500. 0x3b, 0xdd, 0x92, 0xce, 0x61, 0x97, 0x0e, 0x98,
  28501. 0xa4, 0x10, 0xb5, 0x1f, 0xc5, 0xfb, 0xee, 0x49,
  28502. 0x36, 0x8f, 0xe3, 0x2d, 0x46, 0x9c, 0xa9, 0xff,
  28503. 0xdd, 0x1a, 0x48, 0x1b, 0x5a, 0x99, 0x84, 0x0a,
  28504. 0x3d, 0x5c, 0xd7, 0x67, 0x32, 0x88, 0x87, 0x2a,
  28505. 0x34, 0x50, 0x04, 0xad, 0xe6, 0xbb, 0x3c, 0xb5,
  28506. 0xee, 0x80, 0x99, 0x70, 0xaa, 0x9d, 0x5a, 0x63,
  28507. 0xec, 0xd5, 0x9a, 0x6a, 0x3a, 0xe8, 0xaa, 0x3d,
  28508. 0x3f, 0xe8, 0x15, 0x2c, 0x16, 0x3e, 0x86, 0x46,
  28509. 0x21, 0xf2, 0xd2, 0x6e, 0x74, 0x3d, 0x53, 0x94,
  28510. 0x7c, 0x41, 0xec, 0x5b, 0xf5, 0xa4, 0xc8, 0x1f,
  28511. 0x75, 0x22, 0x50, 0x58, 0x31, 0xf5, 0x29, 0x9a,
  28512. 0xc2, 0x2c, 0x67, 0xd9, 0xf6, 0x2e, 0xa1, 0xa9,
  28513. 0x0a, 0x69, 0x90, 0x7a, 0xd8, 0xed, 0x5c, 0x09,
  28514. 0x3d, 0x14, 0xa3, 0x2b, 0xc0, 0x47, 0x88, 0xb7,
  28515. 0xea, 0x14, 0x8a, 0xec, 0xaf, 0x0c, 0xb7, 0xc6,
  28516. 0x7c, 0x32, 0x0f, 0x57, 0xea, 0x9f, 0xd4, 0x99,
  28517. 0x8d, 0xab, 0xd6, 0xc9, 0x31, 0x07, 0x81, 0x37,
  28518. 0x3d, 0xf5, 0x07, 0xb3, 0x93, 0xb7, 0x04, 0x20,
  28519. 0xdf, 0x91, 0xef, 0xfb, 0xa6, 0x7d, 0x4b, 0x5d,
  28520. 0xd4, 0x24, 0xd2, 0x0b, 0xc5, 0x34, 0xf6, 0x7a,
  28521. 0xf9, 0x4a, 0x48, 0xc7, 0xab, 0xaf, 0xa8, 0xd2,
  28522. 0xfc, 0x41, 0xc9, 0x8b, 0xa8, 0xc4, 0x2f, 0x94,
  28523. 0x4e, 0xb0, 0xab, 0xd3, 0xd9, 0x09, 0x4b, 0x1f,
  28524. 0x35, 0xb7, 0xb4, 0x4c, 0x2d, 0x6b, 0xe6, 0xb4,
  28525. 0x2e, 0x8a, 0x09, 0xd3, 0x9d, 0x54, 0x3f, 0x53,
  28526. 0xcc, 0x8e, 0x16, 0x18, 0x4e, 0x9a, 0xe8, 0x52,
  28527. 0x84, 0x3a, 0x3e, 0xdb, 0xab, 0x65, 0xc4, 0xa1,
  28528. 0x3c, 0xd0, 0xf6, 0x57, 0x3c, 0x0e, 0x10, 0xed,
  28529. 0xb2, 0xa9, 0x7d, 0x70, 0x3f, 0x18, 0x1a, 0xba,
  28530. 0x31, 0x33, 0xcb, 0x2a, 0xfd, 0x13, 0xf5, 0x23,
  28531. 0xd7, 0x71, 0xfa, 0xb6, 0xe8, 0xda, 0x63, 0xca,
  28532. 0x55, 0x3c, 0x5b, 0x87, 0x27, 0x96, 0x3d, 0xd0,
  28533. 0x43, 0x9d, 0x76, 0x9f, 0x28, 0x5a, 0xb6, 0xc8,
  28534. 0x81, 0xe4, 0x7c, 0x2a, 0x7a, 0x84, 0x0f, 0x2d,
  28535. 0x1b, 0xd0, 0xe4, 0x0e, 0x1b, 0x47, 0x32, 0xc8,
  28536. 0x02, 0x2d, 0x39, 0x0e, 0x7d, 0xb1, 0x12, 0x56,
  28537. 0x50, 0x00, 0xae, 0xcc, 0x45, 0x0a, 0xd5, 0x30,
  28538. 0x16, 0xe7, 0x3a, 0x53, 0x02, 0xbc, 0xd5, 0xef,
  28539. 0xca, 0x00, 0xea, 0x5f, 0xbe, 0x15, 0x0d, 0x08,
  28540. 0x76, 0xc1, 0x03, 0x93, 0x96, 0x4a, 0x88, 0xda,
  28541. 0x9d, 0x0b, 0x51, 0x39, 0x9a, 0xef, 0xd2, 0xde,
  28542. 0x8a, 0x2c, 0xe6, 0xf3, 0xa5, 0x70, 0x15, 0x3a,
  28543. 0x17, 0x43, 0x31, 0xfc, 0x47, 0x9d, 0xec, 0x3b,
  28544. 0x28, 0x6f, 0xdf, 0x45, 0x6f, 0x9e, 0x10, 0xbb,
  28545. 0x8e, 0x43, 0xc5, 0x59, 0xe5, 0x61, 0x9b, 0xa7,
  28546. 0xa1, 0xb8, 0x7a, 0x1c, 0xd4, 0x25, 0x26, 0xca,
  28547. 0xe9, 0x2b, 0x0b, 0x3d, 0x06, 0xeb, 0x44, 0x44,
  28548. 0xab, 0x4a, 0x5e, 0x68, 0x5c, 0x93, 0xf1, 0x3f,
  28549. 0x39, 0x01, 0xb9, 0xf1, 0x01, 0xb7, 0xb6, 0x14,
  28550. 0x44, 0x1d, 0x6d, 0x6b, 0x03, 0x45, 0x0d, 0xf3,
  28551. 0xbf, 0x71, 0x4e, 0xf3, 0x84, 0x3d, 0xef, 0xea,
  28552. 0x60, 0x2e, 0x2e, 0xf7, 0x33, 0xa6, 0xbe, 0x53,
  28553. 0x49, 0x26, 0xed, 0xb4, 0xbf, 0x7f, 0xb0, 0x1d,
  28554. 0x39, 0xb2, 0xc2, 0x88, 0xc2, 0xa2, 0xd4, 0x7f,
  28555. 0x0e, 0x1c, 0x44, 0xa3, 0x38, 0x76, 0xa7, 0xa6,
  28556. 0x19, 0x7e, 0x4c, 0x84, 0x25, 0x01, 0xb2, 0x78,
  28557. 0xb4, 0x56, 0xc5, 0xc1, 0x50, 0x3f, 0xf2, 0xb6,
  28558. 0x76, 0x09, 0x55, 0x57, 0x1c, 0xd1, 0x55, 0x23,
  28559. 0x16, 0x2a, 0x51, 0x16, 0xaa, 0x13, 0x4f, 0x35,
  28560. 0x69, 0xaf, 0xea, 0x01, 0x5f, 0x22, 0xc9, 0x2e,
  28561. 0xe9, 0x8c, 0x6c, 0xa2, 0x17, 0x92, 0xdc, 0x3d,
  28562. 0xd6, 0xf0, 0xfa, 0x5a, 0x53, 0xe0, 0xcd, 0x55,
  28563. 0xa2, 0x91, 0x62, 0xba, 0xae, 0x67, 0x40, 0x1c,
  28564. 0xda, 0xb4, 0xcc, 0xfc, 0x67, 0x1f, 0x44, 0xa0,
  28565. 0x50, 0xa5, 0xde, 0xc5, 0xde, 0x5e, 0xa0, 0x3b,
  28566. 0x05, 0x84, 0x1c, 0x2a, 0xc4, 0x96, 0x47, 0xd6,
  28567. 0x97, 0x56, 0x40, 0x33, 0x99, 0x7c, 0x8b, 0x56,
  28568. 0xb4, 0xfb, 0xf4, 0x23, 0xcb, 0x48, 0x81, 0x6c,
  28569. 0xa4, 0x53, 0x41, 0x8c, 0x28, 0x61, 0xd7, 0x8c,
  28570. 0xde, 0xde, 0xeb, 0xd4, 0xe7, 0x8a, 0x2a, 0x40,
  28571. 0x83, 0x1c, 0xa4, 0x19, 0x0f, 0x6c, 0x73, 0xa5,
  28572. 0x0e, 0xb6, 0x5c, 0x14, 0x36, 0xff, 0xc9, 0x99,
  28573. 0x56, 0x53, 0x8c, 0x4e, 0x4f, 0x4a, 0x82, 0xc8,
  28574. 0x76, 0x83, 0x81, 0xf1, 0x17, 0x82, 0x98, 0x3e,
  28575. 0x9c, 0x99, 0x3a, 0x7c, 0x08, 0x77, 0x3e, 0xe2,
  28576. 0x10, 0x98, 0xb0, 0xf6, 0x1d, 0xd3, 0x24, 0xe8,
  28577. 0x98, 0xcf, 0xd8, 0x9a, 0xb8, 0xd7, 0xbe, 0x56,
  28578. 0xa2, 0xb6, 0xf8, 0x2e, 0xfe, 0xeb, 0x96, 0xfa,
  28579. 0xd0, 0xba, 0x79, 0x9e, 0xde, 0x72, 0x0d, 0x53,
  28580. 0x5f, 0xdd, 0x0d, 0xb2, 0x0a, 0x8f, 0x14, 0x94,
  28581. 0x87, 0x25, 0x5e, 0xcd, 0xd4, 0x4b, 0xaa, 0xc9,
  28582. 0x7e, 0x41, 0x9f, 0x33, 0x77, 0xbe, 0x6d, 0x57,
  28583. 0x68, 0xef, 0xee, 0x1a, 0xc4, 0x5c, 0x7b, 0xca,
  28584. 0x7e, 0x33, 0x93, 0x3d, 0x88, 0x91, 0xd1, 0x34,
  28585. 0x6a, 0x39, 0x98, 0x92, 0x50, 0x1a, 0x02, 0xcf,
  28586. 0x89, 0x34, 0x33, 0x10, 0x65, 0x23, 0x4d, 0xb7,
  28587. 0x00, 0xcc, 0xc1, 0x60, 0xdd, 0x7d, 0x8e, 0xd1,
  28588. 0x16, 0xa7, 0x71, 0x7b, 0x20, 0xcb, 0xe4, 0xe8,
  28589. 0xcc, 0xfc, 0xb8, 0x5f, 0xe4, 0xe2, 0xd6, 0x8c,
  28590. 0x43, 0x9c, 0x06, 0xf4, 0x8d, 0xbc, 0x56, 0xd0,
  28591. 0x0c, 0xd6, 0x0b, 0x6c, 0x33, 0x0e, 0x08, 0x77,
  28592. 0x66, 0x52, 0x1f, 0x48, 0x0c, 0x50, 0x4a, 0xc2,
  28593. 0x99, 0x0a, 0x15, 0x86, 0xc3, 0x9b, 0x7a, 0x5f,
  28594. 0xfb, 0x58, 0xbd, 0x63, 0x0c, 0xbe, 0x83, 0x40,
  28595. 0x8f, 0xba, 0x39, 0xfb, 0x45, 0xb9, 0xf7, 0x96,
  28596. 0x62, 0xec, 0x7e, 0x77, 0xa4, 0xfb, 0xe1, 0x86,
  28597. 0x5c, 0x0a, 0xae, 0x32, 0xbd, 0x79, 0x76, 0x8b
  28598. };
  28599. static const byte ml_dsa_44_good_sig[] = {
  28600. 0x09, 0xf0, 0xae, 0xbb, 0x25, 0xc7, 0xfc, 0xdd,
  28601. 0x93, 0x25, 0x9c, 0x50, 0xd9, 0x2e, 0x72, 0x5d,
  28602. 0x53, 0xf5, 0x29, 0xd7, 0x4c, 0xc2, 0xd6, 0x81,
  28603. 0x5c, 0xf3, 0x3f, 0x9a, 0x8a, 0xa9, 0x00, 0x21,
  28604. 0x6c, 0xc6, 0xb9, 0x72, 0xb7, 0x0e, 0x00, 0x55,
  28605. 0x9f, 0xd7, 0xae, 0x92, 0xc3, 0xbc, 0x8f, 0x2d,
  28606. 0x4f, 0x54, 0x87, 0x56, 0x52, 0xd3, 0xdd, 0xaf,
  28607. 0xe0, 0xff, 0xda, 0x80, 0x1b, 0xf3, 0x56, 0x90,
  28608. 0xdd, 0x07, 0x86, 0xad, 0xf7, 0xf3, 0x8e, 0xcf,
  28609. 0x3a, 0x57, 0x30, 0x52, 0xaa, 0xd2, 0xb1, 0xf0,
  28610. 0x66, 0xea, 0x67, 0xab, 0x94, 0x1d, 0x96, 0x04,
  28611. 0xaa, 0xcf, 0x0e, 0xb0, 0xbc, 0x7d, 0x8a, 0x4c,
  28612. 0x62, 0x21, 0x82, 0x81, 0x98, 0x63, 0x22, 0x91,
  28613. 0xb9, 0xfe, 0x53, 0x63, 0x8d, 0xdf, 0xe6, 0x19,
  28614. 0xc1, 0x54, 0x3b, 0xf0, 0xf5, 0xe4, 0xc4, 0x36,
  28615. 0x66, 0x2f, 0xcc, 0x4f, 0xed, 0xc6, 0x62, 0x7d,
  28616. 0x8b, 0x7b, 0x89, 0xac, 0x23, 0x0b, 0x40, 0x4e,
  28617. 0x2d, 0xdc, 0xe5, 0xa2, 0xbc, 0x8b, 0xac, 0xe7,
  28618. 0x0b, 0xaa, 0x15, 0xa0, 0x79, 0x4a, 0x97, 0x8a,
  28619. 0xc8, 0xb1, 0x31, 0xea, 0x29, 0x99, 0x14, 0x5d,
  28620. 0x5b, 0x8c, 0xc2, 0xd0, 0xc2, 0x29, 0xd0, 0x85,
  28621. 0xb9, 0x25, 0x16, 0x08, 0xe8, 0x41, 0xa7, 0x77,
  28622. 0x1a, 0xbf, 0x5a, 0x48, 0x5a, 0x7f, 0x97, 0x44,
  28623. 0x62, 0xb4, 0x68, 0x2e, 0x05, 0x48, 0xde, 0x0f,
  28624. 0x69, 0xcc, 0x05, 0x3c, 0xa4, 0x85, 0x20, 0x60,
  28625. 0xfd, 0x45, 0x6a, 0x14, 0xb9, 0x76, 0x8d, 0x48,
  28626. 0xe7, 0x71, 0xd0, 0xd7, 0xbe, 0xe3, 0x36, 0xd6,
  28627. 0x94, 0x5c, 0x22, 0x6e, 0x28, 0xc6, 0x34, 0x93,
  28628. 0xf4, 0x6c, 0xf2, 0x62, 0xbf, 0x8f, 0x6d, 0x07,
  28629. 0xff, 0x38, 0x92, 0x23, 0x19, 0x55, 0xd0, 0x66,
  28630. 0x72, 0x76, 0xc1, 0x43, 0xbc, 0x60, 0x5d, 0xaa,
  28631. 0x61, 0x10, 0xdb, 0x0c, 0x49, 0x7b, 0x99, 0xce,
  28632. 0x14, 0xe3, 0x0b, 0x80, 0xdc, 0x8a, 0x3d, 0xa5,
  28633. 0x3a, 0x0e, 0x29, 0x88, 0x09, 0x1f, 0x9c, 0x03,
  28634. 0x32, 0x13, 0xc2, 0xe1, 0x49, 0x26, 0xc7, 0x11,
  28635. 0xfa, 0x7f, 0x2d, 0x64, 0xfc, 0xf9, 0xaf, 0xd0,
  28636. 0x4d, 0xcf, 0x3a, 0x23, 0x49, 0xde, 0xf2, 0x5d,
  28637. 0xad, 0xf3, 0xde, 0xe0, 0x9a, 0xa2, 0x96, 0x0a,
  28638. 0x9d, 0x97, 0x39, 0x88, 0x60, 0x75, 0xec, 0x29,
  28639. 0x9b, 0x93, 0xfc, 0x80, 0xb3, 0xeb, 0xb0, 0xc6,
  28640. 0xa8, 0xea, 0x75, 0x67, 0xed, 0xbd, 0x42, 0x2a,
  28641. 0xed, 0x22, 0x27, 0xdb, 0x41, 0x3a, 0x94, 0x86,
  28642. 0xd7, 0x4a, 0xf1, 0x8f, 0xa5, 0x47, 0x38, 0xa3,
  28643. 0x3c, 0xe7, 0x17, 0x5d, 0xce, 0xdc, 0x32, 0x7c,
  28644. 0xe4, 0x05, 0x58, 0x98, 0x67, 0xc8, 0xaf, 0x35,
  28645. 0x5d, 0xf9, 0xc0, 0x10, 0x6d, 0x9d, 0xd3, 0x27,
  28646. 0x79, 0x3c, 0x1d, 0xdd, 0xfb, 0x53, 0x3c, 0x03,
  28647. 0x4c, 0xb3, 0x1b, 0x0b, 0x3a, 0x60, 0x80, 0xcd,
  28648. 0x9b, 0x1e, 0x5f, 0x3f, 0x29, 0xfa, 0xb1, 0x09,
  28649. 0x9a, 0x88, 0x58, 0x4a, 0xf5, 0xed, 0xe9, 0x7c,
  28650. 0x9d, 0x70, 0xbe, 0x57, 0xfb, 0x92, 0x12, 0xc9,
  28651. 0x8c, 0x6b, 0x77, 0xe2, 0x44, 0xc6, 0x82, 0x2a,
  28652. 0x29, 0xb3, 0x9c, 0xb0, 0x60, 0xda, 0x3d, 0xcd,
  28653. 0x4e, 0x49, 0x96, 0x8c, 0xd7, 0x2b, 0x29, 0x28,
  28654. 0x7b, 0xec, 0xf1, 0x46, 0x40, 0xf0, 0xe1, 0xd7,
  28655. 0x48, 0x9e, 0xdf, 0xfd, 0xa6, 0xd0, 0xaa, 0x35,
  28656. 0x94, 0x7a, 0x94, 0x57, 0xf3, 0xd4, 0x15, 0x19,
  28657. 0xd3, 0xc5, 0x35, 0x73, 0xc4, 0xf5, 0x86, 0x0d,
  28658. 0x2a, 0x5b, 0x67, 0x0d, 0x8d, 0xaa, 0x18, 0x3e,
  28659. 0xea, 0x9d, 0x80, 0xe7, 0xf8, 0xbb, 0x23, 0xea,
  28660. 0x5d, 0x1c, 0x4d, 0xb2, 0x58, 0x7e, 0xe5, 0xef,
  28661. 0x80, 0xc1, 0x63, 0x44, 0xaf, 0x1d, 0xed, 0xf6,
  28662. 0x92, 0x05, 0x0c, 0xda, 0xcc, 0x58, 0x39, 0x27,
  28663. 0xdd, 0x24, 0xac, 0x63, 0x23, 0x34, 0xaa, 0x2d,
  28664. 0xd0, 0x5b, 0xd7, 0x7f, 0x6d, 0xcb, 0x64, 0xed,
  28665. 0xb3, 0x9b, 0x05, 0x90, 0x79, 0xc2, 0x25, 0x68,
  28666. 0xed, 0xf6, 0xa8, 0x7e, 0x30, 0x4a, 0x46, 0x44,
  28667. 0xad, 0xc8, 0x12, 0x8d, 0x04, 0xc3, 0x11, 0x83,
  28668. 0x7e, 0x77, 0xef, 0x9c, 0xa2, 0xf9, 0x3b, 0x06,
  28669. 0x84, 0x7f, 0x72, 0xd9, 0x2f, 0x22, 0x95, 0xb7,
  28670. 0x7b, 0x4e, 0x35, 0x6a, 0xfa, 0x73, 0x7d, 0x88,
  28671. 0x5b, 0xac, 0x7b, 0xc5, 0x53, 0xc1, 0xfe, 0x6b,
  28672. 0x7c, 0x05, 0xc3, 0xe4, 0xae, 0x48, 0x1a, 0xea,
  28673. 0x6e, 0x51, 0x46, 0x1e, 0x82, 0x80, 0xde, 0x31,
  28674. 0xe1, 0x41, 0x71, 0x88, 0x41, 0xa7, 0xb2, 0xcd,
  28675. 0x3d, 0xf7, 0x5c, 0x4f, 0x4c, 0xfd, 0x3f, 0x6f,
  28676. 0x6c, 0x82, 0xc1, 0xba, 0xe0, 0xf0, 0xb4, 0x8c,
  28677. 0xd5, 0xb5, 0x32, 0xbf, 0x91, 0x49, 0x7e, 0x39,
  28678. 0x5e, 0x0a, 0xdf, 0x4b, 0xd6, 0x07, 0x72, 0xff,
  28679. 0x58, 0x65, 0x1b, 0x1f, 0xc6, 0x56, 0xd2, 0x00,
  28680. 0xec, 0x60, 0xd1, 0x22, 0xc9, 0x1a, 0xa4, 0xcc,
  28681. 0x26, 0xb4, 0xd1, 0x93, 0xbc, 0xfc, 0x52, 0xdf,
  28682. 0xa1, 0x23, 0x37, 0x9b, 0xa2, 0xa8, 0x8f, 0xf3,
  28683. 0x39, 0x03, 0xa5, 0x4c, 0xf0, 0x68, 0xe5, 0x95,
  28684. 0x62, 0xfb, 0xd8, 0x88, 0x39, 0xf6, 0x02, 0x0a,
  28685. 0x4e, 0x7c, 0xf0, 0xbf, 0x71, 0x99, 0x0f, 0x19,
  28686. 0x61, 0xd9, 0x39, 0xe8, 0x3f, 0x59, 0x22, 0x4a,
  28687. 0xaa, 0xdd, 0x03, 0xf8, 0x09, 0xb8, 0xaf, 0xd9,
  28688. 0xb9, 0x9c, 0x3f, 0xf1, 0xfe, 0x49, 0xae, 0x99,
  28689. 0x2f, 0xa2, 0x22, 0x5a, 0x3c, 0xe9, 0xe9, 0xf7,
  28690. 0xba, 0x2d, 0xeb, 0x1f, 0x6c, 0xa7, 0xe1, 0x87,
  28691. 0x2f, 0xa5, 0xff, 0xcf, 0x1c, 0x22, 0x8d, 0xf2,
  28692. 0x5f, 0x63, 0xf5, 0xbb, 0x36, 0x66, 0xcc, 0x62,
  28693. 0x89, 0x8e, 0xf7, 0x78, 0xc5, 0x97, 0x95, 0xde,
  28694. 0xec, 0x43, 0x39, 0x6e, 0x0d, 0xe0, 0x8e, 0xbd,
  28695. 0x2b, 0x3b, 0xe6, 0xff, 0xf5, 0x8f, 0x90, 0xd2,
  28696. 0xd2, 0xce, 0x3b, 0x6f, 0x78, 0xf5, 0xd3, 0x42,
  28697. 0xf3, 0x0f, 0x27, 0x4b, 0x2b, 0xe4, 0xd8, 0x0d,
  28698. 0x31, 0xfa, 0xba, 0xdc, 0x54, 0x21, 0x9a, 0xbf,
  28699. 0x1e, 0x1d, 0x06, 0x8e, 0xd9, 0x58, 0xce, 0x9a,
  28700. 0x71, 0x79, 0x4d, 0xcb, 0xfb, 0x99, 0x4b, 0x66,
  28701. 0xed, 0xef, 0x75, 0x20, 0x4d, 0x47, 0x9b, 0x40,
  28702. 0xd5, 0xcf, 0xd9, 0x00, 0xfe, 0x32, 0x45, 0xae,
  28703. 0x4b, 0x7e, 0x8e, 0x7b, 0xf9, 0xd4, 0xd4, 0x2e,
  28704. 0x1a, 0x2a, 0xac, 0x73, 0xdb, 0x79, 0xb7, 0x02,
  28705. 0x6a, 0x3d, 0xa2, 0xfe, 0x52, 0x27, 0x25, 0x43,
  28706. 0xd1, 0xb5, 0x48, 0x0e, 0xef, 0xf1, 0x0f, 0xe7,
  28707. 0x27, 0xc2, 0x59, 0x4e, 0x47, 0xe2, 0x12, 0xaa,
  28708. 0x1e, 0xae, 0xbc, 0x86, 0x22, 0x70, 0x33, 0xa5,
  28709. 0x50, 0x3f, 0xed, 0x3c, 0x98, 0xbb, 0xd5, 0xb3,
  28710. 0x3e, 0x43, 0x21, 0x8e, 0x3e, 0x8c, 0xcc, 0x0c,
  28711. 0xcf, 0x50, 0xcd, 0xeb, 0x1b, 0x9d, 0x0c, 0xc9,
  28712. 0xe3, 0x2f, 0xbb, 0x4b, 0x43, 0xfc, 0x37, 0x27,
  28713. 0xcb, 0xc9, 0x5a, 0xe9, 0x45, 0x92, 0x9d, 0xe9,
  28714. 0x60, 0x8f, 0x93, 0x1b, 0xd8, 0x6a, 0x68, 0x86,
  28715. 0xc2, 0x1d, 0x49, 0x92, 0x11, 0x29, 0x62, 0x14,
  28716. 0x15, 0x4c, 0xe9, 0x33, 0xe3, 0x70, 0x2d, 0x6b,
  28717. 0x8b, 0xb5, 0x22, 0x44, 0x82, 0xbe, 0x43, 0xe2,
  28718. 0x80, 0xfb, 0xb5, 0xfa, 0x6a, 0x30, 0x04, 0x20,
  28719. 0xb6, 0x58, 0xe1, 0xf4, 0x8c, 0xe6, 0x4c, 0x7c,
  28720. 0x8d, 0x38, 0xf6, 0xdd, 0x59, 0xfc, 0x5a, 0xd7,
  28721. 0x9f, 0x34, 0x92, 0xcc, 0xde, 0x65, 0x89, 0xa7,
  28722. 0xd9, 0x57, 0xf7, 0xf2, 0x71, 0x39, 0xaf, 0xb6,
  28723. 0x88, 0x02, 0x40, 0x24, 0x8b, 0x4f, 0xc5, 0xfc,
  28724. 0xdc, 0x5c, 0xc0, 0x1d, 0xa6, 0x68, 0x87, 0xe0,
  28725. 0x8f, 0xdc, 0xf0, 0xac, 0xd8, 0x5f, 0x1c, 0xb3,
  28726. 0x07, 0xac, 0x58, 0x97, 0x3f, 0x3e, 0x72, 0x19,
  28727. 0x18, 0x64, 0x55, 0x73, 0x11, 0x71, 0xd1, 0xa4,
  28728. 0xa6, 0x57, 0xb0, 0x27, 0xaf, 0xad, 0x8a, 0xf7,
  28729. 0xdf, 0xde, 0x1e, 0xdb, 0x31, 0xc9, 0x32, 0x85,
  28730. 0x90, 0x40, 0x3d, 0xfe, 0x64, 0x5d, 0xe3, 0x94,
  28731. 0x74, 0x98, 0xa7, 0xed, 0x84, 0x44, 0x13, 0x76,
  28732. 0xba, 0xe9, 0x09, 0x9a, 0x17, 0xe0, 0x38, 0x03,
  28733. 0x3b, 0x7a, 0xa7, 0x0e, 0x74, 0xbd, 0x93, 0xb1,
  28734. 0x85, 0x64, 0xc9, 0xc4, 0x22, 0xb9, 0xdf, 0x80,
  28735. 0xac, 0xa1, 0x17, 0xdb, 0x11, 0xdb, 0xfa, 0xeb,
  28736. 0x90, 0x3c, 0x28, 0xfb, 0xa2, 0x36, 0x76, 0x61,
  28737. 0x20, 0x00, 0x88, 0x15, 0xc0, 0x79, 0x9f, 0x7d,
  28738. 0x9f, 0x90, 0xdb, 0x79, 0xbf, 0x1c, 0xdf, 0x86,
  28739. 0xc9, 0x60, 0x8c, 0xea, 0xa6, 0x24, 0x81, 0xd6,
  28740. 0x6d, 0xd8, 0x8d, 0x17, 0x5f, 0x5c, 0x6d, 0x93,
  28741. 0xbc, 0xed, 0xe5, 0x41, 0x05, 0xbe, 0xc6, 0x0f,
  28742. 0x66, 0x50, 0xc3, 0xce, 0x7e, 0x6c, 0x80, 0x88,
  28743. 0xf5, 0x52, 0x61, 0xaf, 0xdb, 0xc0, 0x80, 0xbe,
  28744. 0x78, 0x49, 0x64, 0x39, 0x54, 0x26, 0xeb, 0xab,
  28745. 0x07, 0x4d, 0x38, 0x66, 0x06, 0x98, 0x58, 0xaa,
  28746. 0x40, 0xc4, 0x89, 0xb2, 0x08, 0x85, 0xf3, 0x14,
  28747. 0x58, 0x5d, 0x36, 0xf7, 0xf0, 0x6b, 0x72, 0x79,
  28748. 0x6d, 0xbe, 0x5e, 0x24, 0x68, 0xf1, 0x3c, 0xa2,
  28749. 0x82, 0x22, 0x6e, 0xc4, 0x46, 0x94, 0x8e, 0x00,
  28750. 0xcb, 0xc0, 0x07, 0x69, 0xa5, 0x6d, 0x57, 0x04,
  28751. 0x79, 0xeb, 0x06, 0x7a, 0x42, 0x20, 0x6e, 0xdc,
  28752. 0xb5, 0xa4, 0xdd, 0x74, 0xb3, 0x92, 0x16, 0x71,
  28753. 0x7d, 0x99, 0xfa, 0x26, 0x35, 0x57, 0xe2, 0x83,
  28754. 0xc2, 0xb6, 0xfb, 0x0a, 0xae, 0x22, 0xed, 0xe3,
  28755. 0x98, 0x65, 0x18, 0x32, 0xf8, 0xe5, 0xed, 0xa9,
  28756. 0xf9, 0x7d, 0xb8, 0xea, 0x21, 0x51, 0x6c, 0x70,
  28757. 0x4c, 0xfa, 0xec, 0x6d, 0x4c, 0xf4, 0xcb, 0x1c,
  28758. 0x43, 0xfb, 0xfc, 0xbb, 0xa9, 0xcb, 0xc5, 0x21,
  28759. 0xb3, 0x89, 0xd6, 0x4c, 0xc4, 0x42, 0xd1, 0x55,
  28760. 0x3d, 0x43, 0x74, 0xbf, 0xb7, 0x47, 0xb3, 0x5b,
  28761. 0x14, 0xc3, 0x8f, 0x42, 0x30, 0x57, 0xb0, 0x22,
  28762. 0x56, 0xbe, 0x8d, 0x88, 0x7e, 0x7d, 0x63, 0xc8,
  28763. 0xec, 0x01, 0x41, 0xd5, 0x9d, 0xb6, 0x7a, 0x3b,
  28764. 0xfe, 0x8b, 0x95, 0x94, 0xdb, 0xca, 0xf1, 0xb4,
  28765. 0x56, 0xd7, 0x83, 0xf4, 0x11, 0x05, 0x65, 0xde,
  28766. 0x7a, 0xa3, 0x5a, 0x7a, 0x70, 0xe4, 0xd2, 0xad,
  28767. 0xc0, 0xff, 0x3f, 0x66, 0x2e, 0x1a, 0x65, 0x38,
  28768. 0xda, 0x1f, 0x3f, 0xac, 0x04, 0x2f, 0x0f, 0xde,
  28769. 0x7e, 0x55, 0x05, 0x12, 0xe9, 0xe7, 0x69, 0xf9,
  28770. 0x34, 0x2c, 0x84, 0x97, 0xa8, 0x86, 0x0c, 0x24,
  28771. 0x32, 0x87, 0xfd, 0xbe, 0x67, 0xd1, 0x02, 0x21,
  28772. 0x3b, 0x33, 0xfd, 0x11, 0xb1, 0xca, 0x4f, 0xeb,
  28773. 0x40, 0x38, 0xf6, 0x19, 0x83, 0x9d, 0x73, 0x44,
  28774. 0x37, 0xd6, 0x69, 0x6d, 0x85, 0xda, 0xf7, 0x69,
  28775. 0xfb, 0x88, 0x2b, 0xe7, 0xe7, 0x3c, 0x18, 0xa8,
  28776. 0x13, 0xb7, 0xee, 0x5c, 0x50, 0x5b, 0xa3, 0x09,
  28777. 0x1c, 0xef, 0x8d, 0x37, 0x89, 0x75, 0x0f, 0x8b,
  28778. 0xea, 0x17, 0x02, 0x47, 0x21, 0xcb, 0xa8, 0x73,
  28779. 0x71, 0x23, 0x4c, 0xf7, 0x50, 0xdd, 0x21, 0xe5,
  28780. 0xdb, 0x40, 0x3a, 0x87, 0x40, 0x8d, 0x60, 0x89,
  28781. 0x9e, 0x20, 0x00, 0x58, 0xeb, 0xbb, 0x24, 0x9b,
  28782. 0x0a, 0x17, 0x8f, 0xf6, 0x56, 0x07, 0x11, 0x5b,
  28783. 0xa7, 0xcd, 0x93, 0x0a, 0x31, 0x3d, 0x1f, 0x45,
  28784. 0xa0, 0x08, 0x8f, 0x88, 0x34, 0xa5, 0x01, 0x3b,
  28785. 0xea, 0x07, 0xa3, 0x7b, 0x66, 0x3e, 0x96, 0xe8,
  28786. 0xf7, 0x4d, 0x63, 0x04, 0x55, 0x89, 0xf1, 0x02,
  28787. 0x1e, 0x4a, 0x21, 0xb1, 0x2b, 0x8c, 0x7f, 0x2e,
  28788. 0x0c, 0x64, 0x26, 0x36, 0xd8, 0x63, 0xab, 0xf5,
  28789. 0x22, 0xaf, 0xa9, 0xfa, 0xfa, 0x21, 0x4b, 0x7e,
  28790. 0x6f, 0x8c, 0xce, 0x98, 0xf2, 0x85, 0x3f, 0x2c,
  28791. 0x07, 0x90, 0xc3, 0x2c, 0x06, 0xc5, 0xde, 0xc8,
  28792. 0xc2, 0x7c, 0xd7, 0x9b, 0x64, 0x25, 0x8a, 0x9b,
  28793. 0x77, 0x07, 0xc7, 0x4c, 0xd7, 0x67, 0xff, 0xe6,
  28794. 0xdb, 0x17, 0xf5, 0xc4, 0x2a, 0x14, 0x44, 0x1a,
  28795. 0xff, 0xda, 0xe0, 0xa7, 0x09, 0x1c, 0xe9, 0x03,
  28796. 0xde, 0x4a, 0x59, 0xe4, 0xdf, 0xa3, 0x0d, 0x3a,
  28797. 0x43, 0xdf, 0x80, 0x82, 0x87, 0xfa, 0x75, 0xf5,
  28798. 0xe8, 0xef, 0x6f, 0xd0, 0x89, 0xdd, 0xa1, 0x75,
  28799. 0x17, 0x5b, 0x71, 0x47, 0xe8, 0x8d, 0xae, 0xf6,
  28800. 0x18, 0x7f, 0xb9, 0x24, 0x68, 0x3f, 0x17, 0x6b,
  28801. 0xa8, 0x30, 0x67, 0x7e, 0x02, 0x9b, 0xf6, 0x4d,
  28802. 0x03, 0xa8, 0xfb, 0x33, 0x2f, 0xb4, 0x65, 0x72,
  28803. 0x2a, 0x30, 0xa6, 0x93, 0x94, 0x7a, 0x41, 0x0f,
  28804. 0xd3, 0x67, 0x0b, 0xba, 0xa4, 0x49, 0x7c, 0xcf,
  28805. 0x1f, 0x59, 0x1e, 0x2e, 0x45, 0xd4, 0xa8, 0xb1,
  28806. 0x98, 0x2b, 0xd7, 0x6f, 0x55, 0xb8, 0xf2, 0x65,
  28807. 0x7b, 0x96, 0x18, 0xf7, 0x2e, 0xde, 0x9c, 0x39,
  28808. 0x7a, 0x08, 0x2e, 0xe7, 0x3c, 0x9e, 0x4a, 0xfe,
  28809. 0xba, 0x49, 0xce, 0xba, 0x65, 0x18, 0xae, 0xae,
  28810. 0x9b, 0xd5, 0xf5, 0xeb, 0xd3, 0xdc, 0xd7, 0x2c,
  28811. 0x92, 0x3c, 0xe2, 0x93, 0xb9, 0x69, 0xf2, 0x20,
  28812. 0xea, 0xbd, 0xa9, 0x01, 0x2b, 0x72, 0x7c, 0x93,
  28813. 0x6c, 0x1f, 0x80, 0x3a, 0xd2, 0x2d, 0xf6, 0xc1,
  28814. 0x31, 0x63, 0xd2, 0x2f, 0x6c, 0x1a, 0x54, 0x1f,
  28815. 0x74, 0xe6, 0xa0, 0xac, 0xb1, 0x04, 0x03, 0xb3,
  28816. 0x22, 0x19, 0x48, 0x0a, 0xa7, 0x55, 0x25, 0xc1,
  28817. 0x77, 0x28, 0xb9, 0xbe, 0xef, 0xa8, 0xc6, 0x2b,
  28818. 0xd5, 0x6c, 0x5d, 0x7b, 0x85, 0xcd, 0x10, 0x2d,
  28819. 0x9e, 0xfd, 0xb8, 0xa5, 0x10, 0x65, 0xf7, 0x29,
  28820. 0xa7, 0x41, 0x18, 0xc8, 0xc2, 0x23, 0xe5, 0xcb,
  28821. 0x96, 0x91, 0x8a, 0x7e, 0x45, 0x30, 0x6b, 0x91,
  28822. 0xf1, 0x88, 0xb3, 0x2e, 0x92, 0x96, 0x0a, 0x42,
  28823. 0x4a, 0x16, 0x9d, 0x0c, 0xa8, 0xa7, 0xe5, 0x64,
  28824. 0x38, 0x8a, 0x53, 0x41, 0x28, 0xbf, 0xd7, 0xa4,
  28825. 0x14, 0x05, 0x59, 0x11, 0x2e, 0x0f, 0xc8, 0x5c,
  28826. 0x97, 0x8d, 0xd3, 0x92, 0xbf, 0xb9, 0x05, 0xfa,
  28827. 0xff, 0x38, 0xbf, 0xd6, 0xc5, 0x22, 0xf8, 0xa4,
  28828. 0x75, 0x30, 0x45, 0x93, 0x14, 0xda, 0xc0, 0x7f,
  28829. 0xea, 0x24, 0xe0, 0x33, 0x68, 0xf2, 0x6d, 0xe1,
  28830. 0xb1, 0x0c, 0x7d, 0x40, 0xaa, 0x16, 0x53, 0xa1,
  28831. 0xf6, 0x26, 0xb1, 0x25, 0xe8, 0x83, 0xe9, 0xea,
  28832. 0xea, 0xd2, 0x5a, 0x24, 0xda, 0xe2, 0x6e, 0xd1,
  28833. 0x2a, 0x87, 0x64, 0x48, 0x13, 0x55, 0xb1, 0x2c,
  28834. 0x1a, 0x58, 0x43, 0x5b, 0x63, 0x14, 0x3e, 0x02,
  28835. 0xf0, 0xcf, 0x61, 0x7d, 0x83, 0x81, 0xb9, 0x65,
  28836. 0x4b, 0x72, 0xee, 0xff, 0xfb, 0x6a, 0xbe, 0x71,
  28837. 0x26, 0x56, 0x28, 0x13, 0x9f, 0x31, 0xda, 0x8c,
  28838. 0x2f, 0xdb, 0x21, 0xbe, 0x4b, 0x66, 0xbb, 0xad,
  28839. 0x7a, 0x13, 0x55, 0x92, 0x7c, 0xb5, 0x6e, 0x5f,
  28840. 0x45, 0x1b, 0x64, 0x2d, 0xad, 0x6d, 0x32, 0x07,
  28841. 0xe4, 0x91, 0xdc, 0x0c, 0x1b, 0x5f, 0xcd, 0x86,
  28842. 0xe2, 0x99, 0x2b, 0xb9, 0x7e, 0x60, 0xbd, 0xad,
  28843. 0xa1, 0x5c, 0xab, 0x7f, 0x76, 0xf3, 0x77, 0xba,
  28844. 0x73, 0x7f, 0x6a, 0x88, 0x4e, 0xff, 0x40, 0x72,
  28845. 0x7a, 0x4d, 0x9b, 0x20, 0x2d, 0xc9, 0x2a, 0x30,
  28846. 0x0f, 0x8f, 0x0f, 0xc9, 0x79, 0xc8, 0xc3, 0x8a,
  28847. 0x83, 0x52, 0xff, 0x66, 0x7a, 0x42, 0x04, 0x08,
  28848. 0x6e, 0x5b, 0x13, 0xda, 0xb9, 0xb6, 0x2d, 0x45,
  28849. 0x77, 0x9a, 0xa0, 0x2b, 0xc1, 0x87, 0xc2, 0xa6,
  28850. 0x35, 0x7f, 0x39, 0x34, 0x2e, 0x95, 0x1e, 0x8c,
  28851. 0xbf, 0x89, 0x6d, 0xcf, 0x82, 0xb8, 0x9f, 0x9b,
  28852. 0xd1, 0xbc, 0xa2, 0x55, 0x83, 0xf4, 0xca, 0x21,
  28853. 0x11, 0x8f, 0x28, 0xa9, 0x5e, 0x28, 0x23, 0xb4,
  28854. 0x43, 0x60, 0xb6, 0x11, 0x1a, 0x6f, 0xb4, 0xd1,
  28855. 0x96, 0xc8, 0x79, 0xf2, 0x39, 0x8b, 0x82, 0xae,
  28856. 0xe0, 0xc2, 0xe4, 0xf9, 0xfb, 0xf8, 0x85, 0x64,
  28857. 0x28, 0xad, 0xb5, 0xfd, 0x37, 0xc5, 0x21, 0x38,
  28858. 0x31, 0x94, 0x0d, 0xbe, 0xd8, 0xaf, 0x9b, 0x8a,
  28859. 0x7d, 0xfb, 0x56, 0xd8, 0x23, 0xf7, 0x55, 0x55,
  28860. 0xe7, 0xd9, 0x63, 0x65, 0xfd, 0x64, 0x2e, 0x8a,
  28861. 0x1d, 0x1b, 0xac, 0x4e, 0x2f, 0xef, 0x1b, 0x77,
  28862. 0xca, 0x01, 0xd6, 0xfc, 0xb0, 0x11, 0xda, 0x6b,
  28863. 0xef, 0x9f, 0x76, 0x81, 0x3e, 0x3f, 0x26, 0x4b,
  28864. 0x3b, 0x97, 0xa0, 0x7d, 0xd6, 0xcf, 0x51, 0x0d,
  28865. 0x06, 0xf7, 0xf5, 0x88, 0x64, 0x34, 0x7a, 0xe3,
  28866. 0xb9, 0x16, 0xc3, 0x06, 0x04, 0xf3, 0xe9, 0x55,
  28867. 0xd2, 0xff, 0x49, 0xec, 0x57, 0x84, 0x1f, 0x39,
  28868. 0x28, 0x71, 0x57, 0x87, 0x40, 0xf2, 0x7a, 0x30,
  28869. 0xa0, 0x88, 0xba, 0x6c, 0xb1, 0x09, 0x30, 0x3a,
  28870. 0x11, 0x75, 0xcf, 0xbe, 0x4c, 0xf7, 0xf7, 0xca,
  28871. 0x44, 0x52, 0x91, 0xd0, 0x4c, 0x12, 0x3e, 0x3a,
  28872. 0x4b, 0x31, 0x20, 0xfe, 0x27, 0xd2, 0x08, 0x5b,
  28873. 0x83, 0x7b, 0x82, 0xd3, 0xa3, 0x72, 0xba, 0x2f,
  28874. 0x5f, 0xa3, 0x71, 0xcd, 0x8d, 0x3f, 0x94, 0xce,
  28875. 0x86, 0xa8, 0x6b, 0x43, 0xb7, 0x06, 0x80, 0x70,
  28876. 0x64, 0x06, 0xab, 0x54, 0xce, 0xb5, 0x29, 0xaf,
  28877. 0x73, 0xf7, 0x0f, 0x65, 0x70, 0xa7, 0x84, 0x1a,
  28878. 0x0b, 0xdb, 0x0c, 0xa9, 0x20, 0xea, 0x06, 0x7a,
  28879. 0xba, 0x80, 0xc6, 0xae, 0x3e, 0x0a, 0x7b, 0xd6,
  28880. 0x21, 0x99, 0xe0, 0xae, 0x6e, 0x8f, 0x80, 0xa9,
  28881. 0x97, 0x27, 0x3d, 0x7e, 0xb2, 0xd8, 0x06, 0x10,
  28882. 0x36, 0x07, 0x64, 0x12, 0xd0, 0xc7, 0x91, 0xd2,
  28883. 0x81, 0x74, 0x22, 0x8b, 0x8f, 0xe0, 0x48, 0xc4,
  28884. 0xe1, 0x9b, 0x05, 0xc8, 0xc5, 0xc3, 0x9a, 0x7b,
  28885. 0x9d, 0xee, 0x23, 0xe0, 0x98, 0xc0, 0xd0, 0x05,
  28886. 0x21, 0x89, 0x9a, 0xf4, 0x45, 0xd1, 0x1d, 0x80,
  28887. 0x79, 0xb7, 0xfe, 0x3c, 0xff, 0x84, 0x86, 0xf0,
  28888. 0x2a, 0x69, 0x8b, 0x2d, 0x3b, 0x82, 0xa0, 0xab,
  28889. 0xee, 0xe6, 0xf4, 0x64, 0x84, 0x2b, 0x7a, 0x42,
  28890. 0x12, 0x8d, 0x10, 0xa6, 0xae, 0x10, 0x6d, 0x03,
  28891. 0xb5, 0x72, 0x09, 0xf8, 0x3f, 0xe4, 0x1c, 0x0a,
  28892. 0x08, 0x0d, 0x1a, 0x45, 0x5b, 0x70, 0x7b, 0x95,
  28893. 0xa1, 0xa7, 0xb4, 0xb6, 0xbf, 0xcc, 0xfc, 0x09,
  28894. 0x1a, 0x30, 0x40, 0x44, 0x5e, 0x69, 0x73, 0x7a,
  28895. 0x81, 0xa5, 0xb9, 0xd7, 0xdd, 0xe3, 0xee, 0xfb,
  28896. 0x16, 0x1a, 0x1d, 0x40, 0x41, 0x4e, 0x8d, 0x90,
  28897. 0x92, 0x9d, 0xaf, 0xb0, 0xbb, 0xc2, 0xe0, 0xfc,
  28898. 0x06, 0x0b, 0x20, 0x37, 0x47, 0x50, 0x53, 0x65,
  28899. 0x87, 0x89, 0x99, 0xa4, 0xb7, 0xdb, 0x00, 0x00,
  28900. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  28901. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  28902. 0x0f, 0x20, 0x30, 0x3e
  28903. };
  28904. #endif
  28905. static int test_wc_dilithium(void)
  28906. {
  28907. EXPECT_DECLS;
  28908. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM)
  28909. dilithium_key* key;
  28910. byte level;
  28911. #if !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) || \
  28912. !defined(WOLFSSL_DILITHIUM_NO_SIGN)
  28913. WC_RNG rng;
  28914. #endif
  28915. byte* privKey = NULL;
  28916. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  28917. word32 privKeyLen = DILITHIUM_MAX_KEY_SIZE;
  28918. #endif
  28919. byte* pubKey = NULL;
  28920. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  28921. word32 pubKeyLen = DILITHIUM_MAX_PUB_KEY_SIZE;
  28922. #endif
  28923. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  28924. ExpectNotNull(key);
  28925. privKey = (byte*)XMALLOC(DILITHIUM_MAX_KEY_SIZE, NULL,
  28926. DYNAMIC_TYPE_TMP_BUFFER);
  28927. ExpectNotNull(privKey);
  28928. pubKey = (byte*)XMALLOC(DILITHIUM_MAX_PUB_KEY_SIZE, NULL,
  28929. DYNAMIC_TYPE_TMP_BUFFER);
  28930. ExpectNotNull(pubKey);
  28931. if (key != NULL) {
  28932. XMEMSET(key, 0, sizeof(*key));
  28933. }
  28934. #if !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) || \
  28935. !defined(WOLFSSL_DILITHIUM_NO_SIGN)
  28936. XMEMSET(&rng, 0, sizeof(WC_RNG));
  28937. #endif
  28938. #if !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) || \
  28939. !defined(WOLFSSL_DILITHIUM_NO_SIGN)
  28940. ExpectIntEQ(wc_InitRng(&rng), 0);
  28941. #endif
  28942. ExpectIntEQ(wc_dilithium_init(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28943. ExpectIntEQ(wc_dilithium_init_ex(NULL, NULL, INVALID_DEVID), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28944. wc_dilithium_free(NULL);
  28945. ExpectIntEQ(wc_dilithium_init(key), 0);
  28946. wc_dilithium_free(key);
  28947. ExpectIntEQ(wc_dilithium_init_ex(key, NULL, INVALID_DEVID), 0);
  28948. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  28949. ExpectIntEQ(wc_dilithium_export_public(key, pubKey, &pubKeyLen),
  28950. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28951. #endif
  28952. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  28953. ExpectIntEQ(wc_dilithium_export_private(key, privKey, &privKeyLen),
  28954. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28955. #endif
  28956. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  28957. ExpectIntEQ(wc_dilithium_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28958. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28959. ExpectIntEQ(wc_dilithium_priv_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28960. #endif
  28961. #endif
  28962. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28963. ExpectIntEQ(wc_dilithium_pub_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28964. #endif
  28965. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  28966. ExpectIntEQ(wc_dilithium_sig_size(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28967. #endif
  28968. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  28969. ExpectIntEQ(wc_dilithium_size(key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28970. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28971. ExpectIntEQ(wc_dilithium_priv_size(key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28972. #endif
  28973. #endif
  28974. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28975. ExpectIntEQ(wc_dilithium_pub_size(key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28976. #endif
  28977. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  28978. ExpectIntEQ(wc_dilithium_sig_size(key), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28979. #endif
  28980. ExpectIntEQ(wc_dilithium_set_level(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28981. ExpectIntEQ(wc_dilithium_set_level(key, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28982. ExpectIntEQ(wc_dilithium_set_level(NULL, WC_ML_DSA_44), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28983. ExpectIntEQ(wc_dilithium_set_level(key, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28984. ExpectIntEQ(wc_dilithium_set_level(key, 4), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28985. ExpectIntEQ(wc_dilithium_get_level(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28986. ExpectIntEQ(wc_dilithium_get_level(key, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28987. ExpectIntEQ(wc_dilithium_get_level(NULL, &level), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28988. ExpectIntEQ(wc_dilithium_get_level(key, &level), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  28989. #ifndef WOLFSSL_NO_ML_DSA_87
  28990. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  28991. ExpectIntEQ(wc_dilithium_get_level(key, &level), 0);
  28992. ExpectIntEQ(level, WC_ML_DSA_87);
  28993. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  28994. ExpectIntEQ(wc_dilithium_size(key), DILITHIUM_LEVEL5_KEY_SIZE);
  28995. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  28996. ExpectIntEQ(wc_dilithium_priv_size(key), DILITHIUM_LEVEL5_PRV_KEY_SIZE);
  28997. #endif
  28998. #endif
  28999. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  29000. ExpectIntEQ(wc_dilithium_pub_size(key), DILITHIUM_LEVEL5_PUB_KEY_SIZE);
  29001. #endif
  29002. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  29003. ExpectIntEQ(wc_dilithium_sig_size(key), DILITHIUM_LEVEL5_SIG_SIZE);
  29004. #endif
  29005. #else
  29006. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  29007. #endif
  29008. #ifndef WOLFSSL_NO_ML_DSA_65
  29009. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  29010. ExpectIntEQ(wc_dilithium_get_level(key, &level), 0);
  29011. ExpectIntEQ(level, WC_ML_DSA_65);
  29012. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  29013. ExpectIntEQ(wc_dilithium_size(key), DILITHIUM_LEVEL3_KEY_SIZE);
  29014. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  29015. ExpectIntEQ(wc_dilithium_priv_size(key), DILITHIUM_LEVEL3_PRV_KEY_SIZE);
  29016. #endif
  29017. #endif
  29018. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  29019. ExpectIntEQ(wc_dilithium_pub_size(key), DILITHIUM_LEVEL3_PUB_KEY_SIZE);
  29020. #endif
  29021. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  29022. ExpectIntEQ(wc_dilithium_sig_size(key), DILITHIUM_LEVEL3_SIG_SIZE);
  29023. #endif
  29024. #else
  29025. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  29026. #endif
  29027. #ifndef WOLFSSL_NO_ML_DSA_44
  29028. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  29029. ExpectIntEQ(wc_dilithium_get_level(key, &level), 0);
  29030. ExpectIntEQ(level, WC_ML_DSA_44);
  29031. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  29032. ExpectIntEQ(wc_dilithium_size(key), DILITHIUM_LEVEL2_KEY_SIZE);
  29033. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  29034. ExpectIntEQ(wc_dilithium_priv_size(key), DILITHIUM_LEVEL2_PRV_KEY_SIZE);
  29035. #endif
  29036. #endif
  29037. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  29038. ExpectIntEQ(wc_dilithium_pub_size(key), DILITHIUM_LEVEL2_PUB_KEY_SIZE);
  29039. #endif
  29040. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  29041. ExpectIntEQ(wc_dilithium_sig_size(key), DILITHIUM_LEVEL2_SIG_SIZE);
  29042. #endif
  29043. #else
  29044. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  29045. #endif
  29046. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  29047. ExpectIntEQ(wc_dilithium_export_public(key, pubKey, &pubKeyLen),
  29048. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29049. #endif
  29050. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  29051. ExpectIntEQ(wc_dilithium_export_private(key, privKey, &privKeyLen),
  29052. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29053. #endif
  29054. wc_dilithium_free(key);
  29055. #if !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) || \
  29056. !defined(WOLFSSL_DILITHIUM_NO_SIGN)
  29057. wc_FreeRng(&rng);
  29058. #endif
  29059. XFREE(pubKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29060. XFREE(privKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29061. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29062. #endif
  29063. return EXPECT_RESULT();
  29064. }
  29065. static int test_wc_dilithium_make_key(void)
  29066. {
  29067. EXPECT_DECLS;
  29068. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  29069. !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY)
  29070. dilithium_key* key;
  29071. WC_RNG rng;
  29072. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29073. ExpectNotNull(key);
  29074. if (key != NULL) {
  29075. XMEMSET(key, 0, sizeof(*key));
  29076. }
  29077. XMEMSET(&rng, 0, sizeof(WC_RNG));
  29078. ExpectIntEQ(wc_InitRng(&rng), 0);
  29079. ExpectIntEQ(wc_dilithium_init(key), 0);
  29080. ExpectIntEQ(wc_dilithium_make_key(key, &rng), WC_NO_ERR_TRACE(BAD_STATE_E));
  29081. #ifndef WOLFSSL_NO_ML_DSA_44
  29082. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  29083. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29084. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  29085. #else
  29086. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  29087. #endif
  29088. ExpectIntEQ(wc_dilithium_make_key(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29089. ExpectIntEQ(wc_dilithium_make_key(key, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29090. ExpectIntEQ(wc_dilithium_make_key(NULL, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29091. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  29092. wc_dilithium_free(key);
  29093. wc_FreeRng(&rng);
  29094. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29095. #endif
  29096. return EXPECT_RESULT();
  29097. }
  29098. static int test_wc_dilithium_sign(void)
  29099. {
  29100. EXPECT_DECLS;
  29101. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  29102. !defined(WOLFSSL_DILITHIUM_NO_SIGN)
  29103. dilithium_key* key;
  29104. dilithium_key* importKey = NULL;
  29105. WC_RNG rng;
  29106. byte* privKey = NULL;
  29107. word32 privKeyLen = DILITHIUM_MAX_KEY_SIZE;
  29108. word32 badKeyLen;
  29109. byte msg[32];
  29110. byte* sig = NULL;
  29111. word32 sigLen = DILITHIUM_MAX_SIG_SIZE;
  29112. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29113. ExpectNotNull(key);
  29114. importKey = (dilithium_key*)XMALLOC(sizeof(*key), NULL,
  29115. DYNAMIC_TYPE_TMP_BUFFER);
  29116. ExpectNotNull(importKey);
  29117. privKey = (byte*)XMALLOC(DILITHIUM_MAX_KEY_SIZE, NULL,
  29118. DYNAMIC_TYPE_TMP_BUFFER);
  29119. ExpectNotNull(privKey);
  29120. sig = (byte*)XMALLOC(DILITHIUM_MAX_SIG_SIZE, NULL,
  29121. DYNAMIC_TYPE_TMP_BUFFER);
  29122. ExpectNotNull(sig);
  29123. if (key != NULL) {
  29124. XMEMSET(key, 0, sizeof(*key));
  29125. }
  29126. if (importKey != NULL) {
  29127. XMEMSET(importKey, 0, sizeof(*importKey));
  29128. }
  29129. XMEMSET(&rng, 0, sizeof(WC_RNG));
  29130. XMEMSET(msg, 0x55, sizeof(msg));
  29131. ExpectIntEQ(wc_InitRng(&rng), 0);
  29132. ExpectIntEQ(wc_dilithium_init(key), 0);
  29133. #ifndef WOLFSSL_NO_ML_DSA_44
  29134. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  29135. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29136. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  29137. #else
  29138. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  29139. #endif
  29140. #ifdef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  29141. #ifndef WOLFSSL_NO_ML_DSA_44
  29142. ExpectIntEQ(wc_dilithium_import_private(bench_dilithium_level2_key,
  29143. sizeof_bench_dilithium_level2_key, key), 0);
  29144. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29145. ExpectIntEQ(wc_dilithium_import_private(bench_dilithium_level3_key,
  29146. sizeof_bench_dilithium_level3_key, key), 0);
  29147. #else
  29148. ExpectIntEQ(wc_dilithium_import_private(bench_dilithium_level5_key,
  29149. sizeof_bench_dilithium_level5_key, key), 0);
  29150. #endif
  29151. #else
  29152. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  29153. #endif
  29154. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, NULL, NULL, NULL, NULL),
  29155. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29156. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, NULL, NULL, NULL, NULL),
  29157. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29158. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, sig, NULL, NULL, NULL),
  29159. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29160. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, NULL, &sigLen, NULL, NULL),
  29161. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29162. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, NULL, NULL, key, NULL),
  29163. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29164. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, NULL, NULL, NULL, &rng),
  29165. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29166. ExpectIntEQ(wc_dilithium_sign_msg(NULL, 32, sig, &sigLen, key, &rng),
  29167. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29168. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, NULL, &sigLen, key, &rng),
  29169. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29170. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, NULL, key, &rng),
  29171. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29172. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, &sigLen, NULL, &rng),
  29173. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29174. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, &sigLen, key, NULL),
  29175. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29176. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, &sigLen, key, &rng), 0);
  29177. ExpectIntEQ(wc_dilithium_export_private(NULL, NULL, NULL),
  29178. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29179. ExpectIntEQ(wc_dilithium_export_private(key, NULL, NULL),
  29180. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29181. ExpectIntEQ(wc_dilithium_export_private(NULL, privKey, NULL),
  29182. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29183. ExpectIntEQ(wc_dilithium_export_private(NULL, NULL, &privKeyLen),
  29184. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29185. ExpectIntEQ(wc_dilithium_export_private(NULL, privKey, &privKeyLen),
  29186. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29187. ExpectIntEQ(wc_dilithium_export_private(key, NULL, &privKeyLen),
  29188. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29189. ExpectIntEQ(wc_dilithium_export_private(key, privKey, NULL),
  29190. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29191. badKeyLen = 0;
  29192. ExpectIntEQ(wc_dilithium_export_private(key, privKey, &badKeyLen),
  29193. WC_NO_ERR_TRACE(BUFFER_E));
  29194. #ifndef WOLFSSL_NO_ML_DSA_44
  29195. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL2_KEY_SIZE);
  29196. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29197. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL3_KEY_SIZE);
  29198. #else
  29199. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL5_KEY_SIZE);
  29200. #endif
  29201. ExpectIntEQ(wc_dilithium_export_private(key, privKey, &privKeyLen),
  29202. 0);
  29203. #ifndef WOLFSSL_NO_ML_DSA_44
  29204. ExpectIntEQ(privKeyLen, DILITHIUM_LEVEL2_KEY_SIZE);
  29205. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29206. ExpectIntEQ(privKeyLen, DILITHIUM_LEVEL3_KEY_SIZE);
  29207. #else
  29208. ExpectIntEQ(privKeyLen, DILITHIUM_LEVEL5_KEY_SIZE);
  29209. #endif
  29210. ExpectIntEQ(wc_dilithium_init(importKey), 0);
  29211. ExpectIntEQ(wc_dilithium_import_private(privKey, privKeyLen, importKey),
  29212. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29213. #ifndef WOLFSSL_NO_ML_DSA_44
  29214. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_44), 0);
  29215. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29216. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_65), 0);
  29217. #else
  29218. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_87), 0);
  29219. #endif
  29220. ExpectIntEQ(wc_dilithium_import_private(NULL, 0, NULL),
  29221. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29222. ExpectIntEQ(wc_dilithium_import_private(privKey, 0, NULL),
  29223. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29224. ExpectIntEQ(wc_dilithium_import_private(NULL, privKeyLen, NULL),
  29225. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29226. ExpectIntEQ(wc_dilithium_import_private(NULL, 0, importKey),
  29227. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29228. ExpectIntEQ(wc_dilithium_import_private(NULL, privKeyLen, importKey),
  29229. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29230. ExpectIntEQ(wc_dilithium_import_private(privKey, 0, importKey),
  29231. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29232. ExpectIntEQ(wc_dilithium_import_private(privKey, privKeyLen, NULL),
  29233. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29234. ExpectIntEQ(wc_dilithium_import_private(privKey, privKeyLen, importKey),
  29235. 0);
  29236. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, &sigLen, key, &rng), 0);
  29237. #ifdef WOLFSSL_DILITHIUM_CHECK_KEY
  29238. ExpectIntEQ(wc_dilithium_check_key(importKey), WC_NO_ERR_TRACE(PUBLIC_KEY_E));
  29239. #endif
  29240. wc_dilithium_free(importKey);
  29241. wc_dilithium_free(key);
  29242. wc_FreeRng(&rng);
  29243. XFREE(sig, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29244. XFREE(privKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29245. XFREE(importKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29246. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29247. #endif
  29248. return EXPECT_RESULT();
  29249. }
  29250. static int test_wc_dilithium_verify(void)
  29251. {
  29252. EXPECT_DECLS;
  29253. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  29254. !defined(WOLFSSL_DILITHIUM_NO_VERIFY) && \
  29255. (!defined(WOLFSSL_NO_ML_DSA_44) || !defined(WOLFSSL_DILITHIUM_NO_SIGN))
  29256. dilithium_key* key;
  29257. dilithium_key* importKey = NULL;
  29258. WC_RNG rng;
  29259. byte* pubKey = NULL;
  29260. word32 pubKeyLen = DILITHIUM_MAX_PUB_KEY_SIZE;
  29261. word32 badKeyLen;
  29262. byte msg[32];
  29263. byte* sig = NULL;
  29264. word32 sigLen = DILITHIUM_MAX_SIG_SIZE;
  29265. int res;
  29266. #ifndef WOLFSSL_NO_ML_DSA_44
  29267. byte b;
  29268. #endif
  29269. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29270. ExpectNotNull(key);
  29271. importKey = (dilithium_key*)XMALLOC(sizeof(*key), NULL,
  29272. DYNAMIC_TYPE_TMP_BUFFER);
  29273. ExpectNotNull(importKey);
  29274. pubKey = (byte*)XMALLOC(DILITHIUM_MAX_PUB_KEY_SIZE, NULL,
  29275. DYNAMIC_TYPE_TMP_BUFFER);
  29276. ExpectNotNull(pubKey);
  29277. sig = (byte*)XMALLOC(DILITHIUM_MAX_SIG_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29278. ExpectNotNull(sig);
  29279. if (key != NULL) {
  29280. XMEMSET(key, 0, sizeof(*key));
  29281. }
  29282. if (importKey != NULL) {
  29283. XMEMSET(importKey, 0, sizeof(*importKey));
  29284. }
  29285. XMEMSET(&rng, 0, sizeof(WC_RNG));
  29286. XMEMSET(msg, 0x55, sizeof(msg));
  29287. ExpectIntEQ(wc_InitRng(&rng), 0);
  29288. ExpectIntEQ(wc_dilithium_init(key), 0);
  29289. #ifndef WOLFSSL_NO_ML_DSA_44
  29290. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  29291. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29292. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  29293. #else
  29294. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  29295. #endif
  29296. #if !defined(WOLFSSL_NO_ML_DSA_44)
  29297. ExpectIntEQ(wc_dilithium_import_public(ml_dsa_44_pub_key,
  29298. (word32)sizeof(ml_dsa_44_pub_key), key), 0);
  29299. if (sig != NULL) {
  29300. XMEMCPY(sig, ml_dsa_44_good_sig, sizeof(ml_dsa_44_good_sig));
  29301. }
  29302. sigLen = (word32)sizeof(ml_dsa_44_good_sig);
  29303. #else
  29304. #ifdef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  29305. #ifndef WOLFSSL_NO_ML_DSA_65
  29306. ExpectIntEQ(wc_dilithium_import_public(bench_dilithium_level3_pub_key,
  29307. sizeof_bench_dilithium_level3_pub_key, key), 0);
  29308. #else
  29309. ExpectIntEQ(wc_dilithium_import_public(bench_dilithium_level5_pub_key,
  29310. sizeof_bench_dilithium_level5_pub_key, key), 0);
  29311. #endif /* !WOLFSSL_NO_ML_DSA_65 */
  29312. #else
  29313. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  29314. #endif /* WOLFSSL_DILITHIUM_NO_MAKE_KEY */
  29315. ExpectIntEQ(wc_dilithium_sign_msg(msg, 32, sig, &sigLen, key, &rng), 0);
  29316. #endif /* !WOLFSSL_NO_ML_DSA_44 */
  29317. ExpectIntEQ(wc_dilithium_export_public(NULL, NULL, NULL),
  29318. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29319. ExpectIntEQ(wc_dilithium_export_public(key, NULL, NULL),
  29320. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29321. ExpectIntEQ(wc_dilithium_export_public(NULL, pubKey, NULL),
  29322. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29323. ExpectIntEQ(wc_dilithium_export_public(NULL, NULL, &pubKeyLen),
  29324. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29325. ExpectIntEQ(wc_dilithium_export_public(NULL, pubKey, &pubKeyLen),
  29326. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29327. ExpectIntEQ(wc_dilithium_export_public(key, NULL, &pubKeyLen),
  29328. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29329. ExpectIntEQ(wc_dilithium_export_public(key, pubKey, NULL),
  29330. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29331. badKeyLen = 0;
  29332. ExpectIntEQ(wc_dilithium_export_public(key, pubKey, &badKeyLen),
  29333. WC_NO_ERR_TRACE(BUFFER_E));
  29334. #ifndef WOLFSSL_NO_ML_DSA_44
  29335. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL2_PUB_KEY_SIZE);
  29336. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29337. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL3_PUB_KEY_SIZE);
  29338. #else
  29339. ExpectIntEQ(badKeyLen, DILITHIUM_LEVEL5_PUB_KEY_SIZE);
  29340. #endif
  29341. ExpectIntEQ(wc_dilithium_export_public(key, pubKey, &pubKeyLen), 0);
  29342. #ifndef WOLFSSL_NO_ML_DSA_44
  29343. ExpectIntEQ(pubKeyLen, DILITHIUM_LEVEL2_PUB_KEY_SIZE);
  29344. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29345. ExpectIntEQ(pubKeyLen, DILITHIUM_LEVEL3_PUB_KEY_SIZE);
  29346. #else
  29347. ExpectIntEQ(pubKeyLen, DILITHIUM_LEVEL5_PUB_KEY_SIZE);
  29348. #endif
  29349. ExpectIntEQ(wc_dilithium_verify_msg(NULL, 0, NULL, 32, NULL, NULL),
  29350. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29351. ExpectIntEQ(wc_dilithium_verify_msg(sig, 0, NULL, 32, NULL, NULL),
  29352. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29353. ExpectIntEQ(wc_dilithium_verify_msg(NULL, 0, msg, 32, NULL, NULL),
  29354. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29355. ExpectIntEQ(wc_dilithium_verify_msg(NULL, 0, NULL, 32, &res, NULL),
  29356. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29357. ExpectIntEQ(wc_dilithium_verify_msg(NULL, 0, NULL, 32, NULL, key),
  29358. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29359. ExpectIntEQ(wc_dilithium_verify_msg(NULL, sigLen, msg, 32, &res, key),
  29360. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29361. ExpectIntEQ(wc_dilithium_verify_msg(sig, 0, msg, 32, &res, key),
  29362. WC_NO_ERR_TRACE(BUFFER_E));
  29363. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, NULL, 32, &res, key),
  29364. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29365. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, NULL, key),
  29366. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29367. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, NULL),
  29368. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29369. res = 0;
  29370. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, key), 0);
  29371. ExpectIntEQ(res, 1);
  29372. ExpectIntEQ(wc_dilithium_init(importKey), 0);
  29373. ExpectIntEQ(wc_dilithium_import_public(pubKey, pubKeyLen, importKey),
  29374. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29375. #ifndef WOLFSSL_NO_ML_DSA_44
  29376. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_44), 0);
  29377. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29378. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_65), 0);
  29379. #else
  29380. ExpectIntEQ(wc_dilithium_set_level(importKey, WC_ML_DSA_87), 0);
  29381. #endif
  29382. ExpectIntEQ(wc_dilithium_import_public(NULL, 0, NULL),
  29383. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29384. ExpectIntEQ(wc_dilithium_import_public(pubKey, 0, NULL),
  29385. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29386. ExpectIntEQ(wc_dilithium_import_public(NULL, pubKeyLen, NULL),
  29387. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29388. ExpectIntEQ(wc_dilithium_import_public(NULL, 0, importKey),
  29389. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29390. ExpectIntEQ(wc_dilithium_import_public(NULL, pubKeyLen, importKey),
  29391. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29392. ExpectIntEQ(wc_dilithium_import_public(pubKey, 0, importKey),
  29393. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29394. ExpectIntEQ(wc_dilithium_import_public(pubKey, pubKeyLen, NULL),
  29395. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29396. ExpectIntEQ(wc_dilithium_import_public(pubKey, pubKeyLen, importKey), 0);
  29397. res = 0;
  29398. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, importKey),
  29399. 0);
  29400. ExpectIntEQ(res, 1);
  29401. #ifdef WOLFSSL_DILITHIUM_CHECK_KEY
  29402. ExpectIntEQ(wc_dilithium_check_key(importKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29403. #endif
  29404. wc_dilithium_free(importKey);
  29405. #ifndef WOLFSSL_NO_ML_DSA_44
  29406. if (sig != NULL) {
  29407. if (sig[sigLen - 5] == 0) {
  29408. /* Unused hints meant to be 0. */
  29409. sig[sigLen - 5] = 0xff;
  29410. res = 1;
  29411. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res,
  29412. key), WC_NO_ERR_TRACE(SIG_VERIFY_E));
  29413. ExpectIntEQ(res, 0);
  29414. sig[sigLen - 5] = 0x00;
  29415. }
  29416. /* Last count of hints must be less than PARAMS_ML_DSA_44_OMEGA == 80 */
  29417. b = sig[sigLen - 1];
  29418. sig[sigLen - 1] = 0xff;
  29419. res = 1;
  29420. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, key),
  29421. WC_NO_ERR_TRACE(SIG_VERIFY_E));
  29422. ExpectIntEQ(res, 0);
  29423. sig[sigLen - 1] = b;
  29424. if (sig[sigLen - 4] > 1) {
  29425. /* Index must be less than previous. */
  29426. b = sig[sigLen - 84];
  29427. sig[sigLen - 84] = 0xff;
  29428. res = 1;
  29429. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res,
  29430. key), WC_NO_ERR_TRACE(SIG_VERIFY_E));
  29431. ExpectIntEQ(res, 0);
  29432. sig[sigLen - 84] = b;
  29433. }
  29434. /* Mess up commit hash. */
  29435. sig[0] ^= 0x80;
  29436. res = 1;
  29437. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, key),
  29438. 0);
  29439. ExpectIntEQ(res, 0);
  29440. sig[0] ^= 0x80;
  29441. /* Mess up z. */
  29442. sig[100] ^= 0x80;
  29443. res = 1;
  29444. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, key),
  29445. 0);
  29446. ExpectIntEQ(res, 0);
  29447. sig[100] ^= 0x80;
  29448. /* Set all indeces to 0. */
  29449. XMEMSET(sig + sigLen - 4, 0, 4);
  29450. ExpectIntEQ(wc_dilithium_verify_msg(sig, sigLen, msg, 32, &res, key),
  29451. WC_NO_ERR_TRACE(SIG_VERIFY_E));
  29452. ExpectIntEQ(res, 0);
  29453. }
  29454. #endif
  29455. wc_dilithium_free(key);
  29456. wc_FreeRng(&rng);
  29457. XFREE(sig, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29458. XFREE(pubKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29459. XFREE(importKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29460. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29461. #endif
  29462. return EXPECT_RESULT();
  29463. }
  29464. static int test_wc_dilithium_sign_vfy(void)
  29465. {
  29466. EXPECT_DECLS;
  29467. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  29468. !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) && \
  29469. !defined(WOLFSSL_DILITHIUM_NO_SIGN) && !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  29470. dilithium_key* key;
  29471. WC_RNG rng;
  29472. byte msg[64];
  29473. byte* sig = NULL;
  29474. word32 sigLen;
  29475. byte ctx[10];
  29476. int res;
  29477. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29478. ExpectNotNull(key);
  29479. sig = (byte*)XMALLOC(DILITHIUM_MAX_SIG_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29480. ExpectNotNull(sig);
  29481. if (key != NULL) {
  29482. XMEMSET(key, 0, sizeof(*key));
  29483. }
  29484. XMEMSET(&rng, 0, sizeof(WC_RNG));
  29485. XMEMSET(msg, 0xAA, sizeof(msg));
  29486. XMEMSET(ctx, 0x01, sizeof(ctx));
  29487. ExpectIntEQ(wc_InitRng(&rng), 0);
  29488. #ifndef WOLFSSL_NO_ML_DSA_44
  29489. ExpectIntEQ(wc_dilithium_init(key), 0);
  29490. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  29491. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  29492. sigLen = DILITHIUM_MAX_SIG_SIZE;
  29493. ExpectIntEQ(wc_dilithium_sign_ctx_msg(ctx, sizeof(ctx), msg, sizeof(msg),
  29494. sig, &sigLen, key, &rng), 0);
  29495. ExpectIntEQ(wc_dilithium_verify_ctx_msg(sig, sigLen, ctx, sizeof(ctx), msg,
  29496. sizeof(msg), &res, key), 0);
  29497. ExpectIntEQ(res, 1);
  29498. sigLen = DILITHIUM_MAX_SIG_SIZE;
  29499. ExpectIntEQ(wc_dilithium_sign_ctx_hash(ctx, sizeof(ctx),
  29500. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), sig, &sigLen, key, &rng), 0);
  29501. ExpectIntEQ(wc_dilithium_verify_ctx_hash(sig, sigLen, ctx, sizeof(ctx),
  29502. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), &res, key), 0);
  29503. ExpectIntEQ(res, 1);
  29504. wc_dilithium_free(key);
  29505. #endif
  29506. #ifndef WOLFSSL_NO_ML_DSA_65
  29507. ExpectIntEQ(wc_dilithium_init(key), 0);
  29508. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  29509. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  29510. sigLen = DILITHIUM_MAX_SIG_SIZE;
  29511. ExpectIntEQ(wc_dilithium_sign_ctx_msg(ctx, sizeof(ctx), msg, sizeof(msg),
  29512. sig, &sigLen, key, &rng), 0);
  29513. ExpectIntEQ(wc_dilithium_verify_ctx_msg(sig, sigLen, ctx, sizeof(ctx), msg,
  29514. sizeof(msg), &res, key), 0);
  29515. ExpectIntEQ(res, 1);
  29516. sigLen = DILITHIUM_MAX_SIG_SIZE;
  29517. ExpectIntEQ(wc_dilithium_sign_ctx_hash(ctx, sizeof(ctx),
  29518. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), sig, &sigLen, key, &rng), 0);
  29519. ExpectIntEQ(wc_dilithium_verify_ctx_hash(sig, sigLen, ctx, sizeof(ctx),
  29520. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), &res, key), 0);
  29521. ExpectIntEQ(res, 1);
  29522. wc_dilithium_free(key);
  29523. #endif
  29524. #ifndef WOLFSSL_NO_ML_DSA_87
  29525. ExpectIntEQ(wc_dilithium_init(key), 0);
  29526. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  29527. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  29528. sigLen = DILITHIUM_MAX_SIG_SIZE;
  29529. ExpectIntEQ(wc_dilithium_sign_ctx_msg(ctx, sizeof(ctx), msg, sizeof(msg),
  29530. sig, &sigLen, key, &rng), 0);
  29531. ExpectIntEQ(wc_dilithium_verify_ctx_msg(sig, sigLen, ctx, sizeof(ctx), msg,
  29532. sizeof(msg), &res, key), 0);
  29533. ExpectIntEQ(res, 1);
  29534. sigLen = DILITHIUM_MAX_SIG_SIZE;
  29535. ExpectIntEQ(wc_dilithium_sign_ctx_hash(ctx, sizeof(ctx),
  29536. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), sig, &sigLen, key, &rng), 0);
  29537. ExpectIntEQ(wc_dilithium_verify_ctx_hash(sig, sigLen, ctx, sizeof(ctx),
  29538. WC_HASH_TYPE_SHA3_512, msg, sizeof(msg), &res, key), 0);
  29539. ExpectIntEQ(res, 1);
  29540. wc_dilithium_free(key);
  29541. #endif
  29542. wc_FreeRng(&rng);
  29543. XFREE(sig, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29544. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29545. #endif
  29546. return EXPECT_RESULT();
  29547. }
  29548. static int test_wc_dilithium_check_key(void)
  29549. {
  29550. EXPECT_DECLS;
  29551. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  29552. defined(WOLFSSL_DILITHIUM_CHECK_KEY) && \
  29553. !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY)
  29554. dilithium_key* checkKey;
  29555. WC_RNG rng;
  29556. byte* privCheckKey = NULL;
  29557. word32 privCheckKeyLen = DILITHIUM_MAX_KEY_SIZE;
  29558. byte* pubCheckKey = NULL;
  29559. word32 pubCheckKeyLen = DILITHIUM_MAX_PUB_KEY_SIZE;
  29560. checkKey = (dilithium_key*)XMALLOC(sizeof(*checkKey), NULL,
  29561. DYNAMIC_TYPE_TMP_BUFFER);
  29562. ExpectNotNull(checkKey);
  29563. privCheckKey = (byte*)XMALLOC(DILITHIUM_MAX_KEY_SIZE, NULL,
  29564. DYNAMIC_TYPE_TMP_BUFFER);
  29565. ExpectNotNull(privCheckKey);
  29566. pubCheckKey = (byte*)XMALLOC(DILITHIUM_MAX_PUB_KEY_SIZE, NULL,
  29567. DYNAMIC_TYPE_TMP_BUFFER);
  29568. ExpectNotNull(pubCheckKey);
  29569. if (checkKey != NULL) {
  29570. XMEMSET(checkKey, 0, sizeof(*checkKey));
  29571. }
  29572. XMEMSET(&rng, 0, sizeof(WC_RNG));
  29573. ExpectIntEQ(wc_InitRng(&rng), 0);
  29574. ExpectIntEQ(wc_dilithium_check_key(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29575. ExpectIntEQ(wc_dilithium_init(checkKey), 0);
  29576. ExpectIntEQ(wc_dilithium_export_key(NULL, privCheckKey,
  29577. &privCheckKeyLen, pubCheckKey, &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29578. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29579. privCheckKeyLen, pubCheckKey, pubCheckKeyLen, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29580. ExpectIntEQ(wc_dilithium_export_key(checkKey, privCheckKey,
  29581. &privCheckKeyLen, pubCheckKey, &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29582. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29583. privCheckKeyLen, pubCheckKey, pubCheckKeyLen, checkKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29584. #ifndef WOLFSSL_NO_ML_DSA_44
  29585. ExpectIntEQ(wc_dilithium_set_level(checkKey, WC_ML_DSA_44), 0);
  29586. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29587. ExpectIntEQ(wc_dilithium_set_level(checkKey, WC_ML_DSA_65), 0);
  29588. #else
  29589. ExpectIntEQ(wc_dilithium_set_level(checkKey, WC_ML_DSA_87), 0);
  29590. #endif
  29591. ExpectIntEQ(wc_dilithium_make_key(checkKey, &rng), 0);
  29592. ExpectIntEQ(wc_dilithium_export_key(NULL, NULL, NULL, NULL, NULL),
  29593. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29594. ExpectIntEQ(wc_dilithium_export_key(checkKey, NULL, NULL, NULL, NULL),
  29595. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29596. ExpectIntEQ(wc_dilithium_export_key(NULL, privCheckKey, NULL, NULL, NULL),
  29597. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29598. ExpectIntEQ(wc_dilithium_export_key(NULL, NULL, &privCheckKeyLen, NULL,
  29599. NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29600. ExpectIntEQ(wc_dilithium_export_key(NULL, NULL, NULL, pubCheckKey, NULL),
  29601. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29602. ExpectIntEQ(wc_dilithium_export_key(NULL, NULL, NULL, NULL,
  29603. &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29604. ExpectIntEQ(wc_dilithium_export_key(NULL , privCheckKey,
  29605. &privCheckKeyLen, pubCheckKey, &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29606. ExpectIntEQ(wc_dilithium_export_key(checkKey, NULL ,
  29607. &privCheckKeyLen, pubCheckKey, &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29608. ExpectIntEQ(wc_dilithium_export_key(checkKey, privCheckKey,
  29609. NULL , pubCheckKey, &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29610. ExpectIntEQ(wc_dilithium_export_key(checkKey, privCheckKey,
  29611. &privCheckKeyLen, NULL , &pubCheckKeyLen), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29612. ExpectIntEQ(wc_dilithium_export_key(checkKey, privCheckKey,
  29613. &privCheckKeyLen, pubCheckKey, NULL ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29614. ExpectIntEQ(wc_dilithium_export_key(checkKey, privCheckKey,
  29615. &privCheckKeyLen, pubCheckKey, &pubCheckKeyLen), 0);
  29616. /* Modify hash. */
  29617. if (pubCheckKey != NULL) {
  29618. pubCheckKey[0] ^= 0x80;
  29619. ExpectIntEQ(wc_dilithium_import_key(NULL, 0, NULL, 0, NULL),
  29620. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29621. ExpectIntEQ(wc_dilithium_import_key(privCheckKey, 0, NULL, 0, NULL),
  29622. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29623. ExpectIntEQ(wc_dilithium_import_key(NULL, 0, pubCheckKey, 0, NULL),
  29624. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29625. ExpectIntEQ(wc_dilithium_import_key(NULL, 0, NULL, 0, checkKey),
  29626. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29627. ExpectIntEQ(wc_dilithium_import_key(NULL ,
  29628. privCheckKeyLen, pubCheckKey, pubCheckKeyLen, checkKey),
  29629. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29630. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29631. 0 , pubCheckKey, pubCheckKeyLen, checkKey),
  29632. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29633. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29634. privCheckKeyLen, NULL , pubCheckKeyLen, checkKey),
  29635. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29636. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29637. privCheckKeyLen, pubCheckKey, 0 , checkKey),
  29638. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29639. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29640. privCheckKeyLen, pubCheckKey, pubCheckKeyLen, NULL ),
  29641. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  29642. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29643. privCheckKeyLen, pubCheckKey, pubCheckKeyLen, checkKey), 0);
  29644. ExpectIntEQ(wc_dilithium_check_key(checkKey), WC_NO_ERR_TRACE(PUBLIC_KEY_E));
  29645. pubCheckKey[0] ^= 0x80;
  29646. /* Modify encoded t1. */
  29647. pubCheckKey[48] ^= 0x80;
  29648. ExpectIntEQ(wc_dilithium_import_key(privCheckKey,
  29649. privCheckKeyLen,pubCheckKey, pubCheckKeyLen, checkKey), 0);
  29650. ExpectIntEQ(wc_dilithium_check_key(checkKey), WC_NO_ERR_TRACE(PUBLIC_KEY_E));
  29651. pubCheckKey[48] ^= 0x80;
  29652. }
  29653. wc_dilithium_free(checkKey);
  29654. wc_FreeRng(&rng);
  29655. XFREE(pubCheckKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29656. XFREE(privCheckKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29657. XFREE(checkKey, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  29658. #endif
  29659. return EXPECT_RESULT();
  29660. }
  29661. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  29662. defined(WOLFSSL_DILITHIUM_PUBLIC_KEY)
  29663. static const unsigned char ml_dsa_public_der[] = {
  29664. #ifndef WOLFSSL_NO_ML_DSA_44
  29665. 0x30, 0x82, 0x05, 0x32, 0x30, 0x0d, 0x06, 0x09,
  29666. 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x03,
  29667. 0x11, 0x03, 0x82, 0x05, 0x21, 0x00,
  29668. 0xBC, 0x5F, 0xF8, 0x10, 0xEB, 0x08, 0x90, 0x48,
  29669. 0xB8, 0xAB, 0x30, 0x20, 0xA7, 0xBD, 0x3B, 0x16,
  29670. 0xC0, 0xE0, 0xCA, 0x3D, 0x6B, 0x97, 0xE4, 0x64,
  29671. 0x6C, 0x2C, 0xCA, 0xE0, 0xBB, 0xF1, 0x9E, 0xF7,
  29672. 0x23, 0x0A, 0x19, 0xD7, 0x5A, 0xDB, 0xDE, 0xD5,
  29673. 0x2D, 0xB8, 0x55, 0xE2, 0x52, 0xA7, 0x19, 0xFC,
  29674. 0xBD, 0x14, 0x7B, 0xA6, 0x7B, 0x2F, 0xAD, 0x14,
  29675. 0xED, 0x0E, 0x68, 0xFD, 0xFE, 0x8C, 0x65, 0xBA,
  29676. 0xDE, 0xAC, 0xB0, 0x91, 0x11, 0x93, 0xAD, 0xFA,
  29677. 0x87, 0x94, 0xD7, 0x8F, 0x8E, 0x3D, 0x66, 0x2A,
  29678. 0x1C, 0x49, 0xDA, 0x81, 0x9F, 0xD9, 0x59, 0xE7,
  29679. 0xF0, 0x78, 0xF2, 0x03, 0xC4, 0x56, 0xF8, 0xB6,
  29680. 0xE7, 0xC9, 0x41, 0x58, 0x98, 0xE5, 0x41, 0xC7,
  29681. 0x30, 0x32, 0xDB, 0xD6, 0x19, 0xEA, 0xF6, 0x0F,
  29682. 0x8D, 0x64, 0xF8, 0x68, 0x3D, 0xA9, 0x9E, 0xCA,
  29683. 0x51, 0x22, 0x0B, 0x0A, 0xCA, 0x28, 0x46, 0x40,
  29684. 0x99, 0xF5, 0x47, 0xC0, 0x27, 0x77, 0xBD, 0x37,
  29685. 0xD8, 0x4A, 0x59, 0xBD, 0x37, 0xED, 0x7A, 0x8A,
  29686. 0x92, 0x63, 0x3C, 0x75, 0xD0, 0x7C, 0x79, 0x3F,
  29687. 0xE7, 0x25, 0x2B, 0x58, 0x4A, 0xBF, 0x6A, 0x15,
  29688. 0xEE, 0x14, 0x50, 0x7E, 0x5E, 0x19, 0x3F, 0x89,
  29689. 0x86, 0x4D, 0x09, 0xAC, 0x87, 0x27, 0xA6, 0xD0,
  29690. 0x42, 0x1F, 0x0C, 0x19, 0xF0, 0xE2, 0xFB, 0xFC,
  29691. 0x21, 0x3D, 0x3F, 0xBD, 0x70, 0xF4, 0xF9, 0x76,
  29692. 0x2C, 0xEC, 0xFF, 0x23, 0x1E, 0x9C, 0x8A, 0x76,
  29693. 0x28, 0xD3, 0xF8, 0xB0, 0x85, 0x7B, 0x03, 0x2D,
  29694. 0x32, 0xDE, 0x62, 0xFF, 0x8E, 0xCB, 0xF4, 0x00,
  29695. 0x82, 0x89, 0xBF, 0x34, 0x40, 0x36, 0x65, 0xF8,
  29696. 0x1A, 0x08, 0x1A, 0xD5, 0xA8, 0x5A, 0x28, 0x2F,
  29697. 0x99, 0xBA, 0xB9, 0xE5, 0x38, 0x5A, 0xFB, 0xCC,
  29698. 0xCF, 0x44, 0xB7, 0x4C, 0x01, 0x96, 0xC7, 0x54,
  29699. 0x55, 0x27, 0xEC, 0x30, 0x26, 0xDA, 0x12, 0x80,
  29700. 0xC4, 0xEB, 0x37, 0xD0, 0x9C, 0xFE, 0x3E, 0xC4,
  29701. 0xB4, 0x91, 0x0B, 0x62, 0xEB, 0x98, 0x15, 0xA4,
  29702. 0x25, 0xC6, 0x59, 0x0F, 0xC4, 0xAD, 0x3F, 0xBB,
  29703. 0x22, 0x57, 0x52, 0xCC, 0x1F, 0xC5, 0x69, 0x3F,
  29704. 0x18, 0x7E, 0x7D, 0xEC, 0x4E, 0xEF, 0xBE, 0xB6,
  29705. 0xB9, 0x1B, 0xD9, 0x1C, 0x5E, 0x2E, 0xA6, 0xA9,
  29706. 0x1D, 0x14, 0xD0, 0x97, 0xBE, 0x20, 0x3F, 0xBA,
  29707. 0x0B, 0xF9, 0x37, 0xC9, 0x75, 0x07, 0xDC, 0x00,
  29708. 0x7C, 0x4C, 0xAA, 0x9B, 0x07, 0x85, 0x89, 0x29,
  29709. 0x66, 0xFF, 0x15, 0x90, 0x09, 0x24, 0xE5, 0x79,
  29710. 0xD4, 0xFB, 0xA0, 0x2B, 0xDA, 0x87, 0x55, 0x5F,
  29711. 0x07, 0x3D, 0xAE, 0x00, 0x51, 0x3E, 0x70, 0x80,
  29712. 0x9A, 0xBB, 0xC7, 0x11, 0xFB, 0xA2, 0xE7, 0x64,
  29713. 0x95, 0x77, 0xC4, 0x2A, 0xFD, 0xC2, 0x4B, 0xF7,
  29714. 0x41, 0x3E, 0x51, 0x26, 0x8A, 0xD6, 0xDB, 0x61,
  29715. 0x13, 0xB7, 0xD9, 0x19, 0x1A, 0xF9, 0xD0, 0x61,
  29716. 0xDB, 0xDE, 0xD5, 0xD6, 0x30, 0x87, 0x76, 0x50,
  29717. 0xC1, 0x24, 0xF1, 0x1B, 0xC4, 0xBD, 0xC3, 0xFD,
  29718. 0xC6, 0xA9, 0x00, 0xF6, 0x31, 0x26, 0xF9, 0x21,
  29719. 0xE8, 0x38, 0xAD, 0x0C, 0x22, 0x75, 0xA3, 0x38,
  29720. 0x9A, 0x39, 0xBD, 0x99, 0xA1, 0x34, 0x50, 0x45,
  29721. 0x50, 0x10, 0x1C, 0xD3, 0xE9, 0x5E, 0x6D, 0x14,
  29722. 0x96, 0xBE, 0x7D, 0xE6, 0x62, 0x7D, 0xF4, 0xFD,
  29723. 0x6C, 0x28, 0xBB, 0xF4, 0x0B, 0x30, 0xEF, 0xA9,
  29724. 0xB5, 0xC3, 0xD5, 0xC8, 0x5A, 0xB1, 0x4A, 0x65,
  29725. 0xC0, 0x2D, 0x6D, 0x47, 0x81, 0xFF, 0x13, 0xD3,
  29726. 0x28, 0x60, 0x85, 0x54, 0xB6, 0xD1, 0x5E, 0xD9,
  29727. 0x12, 0x89, 0xA6, 0xD5, 0x5A, 0xAC, 0x0C, 0x38,
  29728. 0xE3, 0x77, 0x06, 0xF7, 0x35, 0x5E, 0x9A, 0x4F,
  29729. 0xDA, 0x61, 0x5B, 0x87, 0x59, 0x26, 0xBF, 0xE5,
  29730. 0xA5, 0x9D, 0x9E, 0xF2, 0x73, 0xBF, 0x94, 0xA0,
  29731. 0x7C, 0xFA, 0x57, 0x31, 0x78, 0xF0, 0xE0, 0x04,
  29732. 0xB6, 0xE1, 0xEF, 0x0A, 0x83, 0x49, 0xE9, 0xBC,
  29733. 0xC0, 0x19, 0x81, 0xF2, 0x46, 0x0F, 0x0A, 0x27,
  29734. 0x43, 0xC2, 0x8D, 0x1E, 0x13, 0x8F, 0xFB, 0x76,
  29735. 0x5E, 0x7E, 0x33, 0x97, 0xB7, 0x91, 0x33, 0x35,
  29736. 0xD4, 0x02, 0xFE, 0x91, 0x80, 0x6A, 0xA8, 0xFC,
  29737. 0x81, 0x92, 0x53, 0xAF, 0x32, 0x69, 0x2F, 0xA6,
  29738. 0x51, 0xE8, 0x67, 0xF5, 0x90, 0x7E, 0xF4, 0x6F,
  29739. 0x00, 0x62, 0x5A, 0x03, 0x0E, 0xC9, 0x04, 0xED,
  29740. 0xAB, 0x21, 0x42, 0x6D, 0x59, 0x11, 0x9D, 0x2C,
  29741. 0xAA, 0x43, 0xBD, 0x93, 0x5D, 0xEC, 0x0A, 0x55,
  29742. 0x0C, 0x61, 0xEE, 0x4B, 0x27, 0x9C, 0x1C, 0xA3,
  29743. 0xA7, 0x9C, 0x79, 0xA6, 0x6E, 0x3F, 0x2D, 0x2F,
  29744. 0xAD, 0xB0, 0x0F, 0x59, 0xA3, 0xA4, 0x38, 0xAA,
  29745. 0x44, 0x57, 0x01, 0x06, 0x07, 0x30, 0x17, 0xFA,
  29746. 0x1C, 0x87, 0x57, 0x50, 0x01, 0x09, 0x72, 0x0D,
  29747. 0x12, 0x5B, 0xBA, 0x23, 0x1A, 0x0C, 0x36, 0x35,
  29748. 0x0C, 0x78, 0x08, 0x6D, 0xFD, 0xC8, 0xD6, 0x13,
  29749. 0xAE, 0xCA, 0x88, 0xC4, 0xCC, 0xAE, 0xB4, 0xA4,
  29750. 0x4D, 0x13, 0xAD, 0xB3, 0xC7, 0x17, 0xD6, 0x5C,
  29751. 0x82, 0xA3, 0x51, 0xB9, 0xB6, 0xEA, 0xBF, 0x6A,
  29752. 0x10, 0xF4, 0xB4, 0xE9, 0x62, 0x3E, 0x3A, 0x95,
  29753. 0xB4, 0xD4, 0x0A, 0x12, 0xA8, 0x18, 0xAC, 0x6B,
  29754. 0x38, 0x22, 0xDB, 0x82, 0xFB, 0x05, 0xDC, 0x42,
  29755. 0x02, 0x64, 0x8B, 0x44, 0x54, 0x68, 0x9A, 0xEB,
  29756. 0x69, 0xEA, 0x32, 0x5F, 0x03, 0xE3, 0x5D, 0xEF,
  29757. 0xA5, 0x47, 0x08, 0x48, 0x14, 0x20, 0xC6, 0xD6,
  29758. 0x97, 0xBB, 0x91, 0x2F, 0xCA, 0x0D, 0x3F, 0x19,
  29759. 0x2E, 0xF2, 0x97, 0xDF, 0xE7, 0x7F, 0xF3, 0x6B,
  29760. 0x21, 0x03, 0xF1, 0xAD, 0x1A, 0xEE, 0xCE, 0xD1,
  29761. 0xC8, 0x14, 0xC2, 0xCD, 0x7E, 0xF1, 0x6B, 0xCE,
  29762. 0x47, 0x6A, 0xD0, 0x4F, 0x94, 0x1A, 0xFC, 0x79,
  29763. 0xE3, 0x29, 0x54, 0x74, 0xA4, 0x10, 0x62, 0x51,
  29764. 0x8C, 0x00, 0x37, 0x86, 0x09, 0x34, 0xF0, 0xE5,
  29765. 0xE6, 0x52, 0xF7, 0x27, 0x49, 0xA6, 0x98, 0x63,
  29766. 0x2A, 0x09, 0x91, 0xF6, 0x13, 0xF5, 0xCB, 0x96,
  29767. 0xCA, 0x11, 0x78, 0xF9, 0x74, 0xF2, 0xC4, 0xAA,
  29768. 0x0C, 0xE6, 0x3D, 0xC2, 0x4E, 0x36, 0x4C, 0x92,
  29769. 0xA6, 0x43, 0xB9, 0x0A, 0x5F, 0x85, 0xA6, 0x2F,
  29770. 0xD4, 0xD8, 0xD2, 0xB1, 0x93, 0xD2, 0x9B, 0x18,
  29771. 0xBE, 0xDE, 0x26, 0x53, 0xFC, 0x5D, 0x3F, 0x24,
  29772. 0xF5, 0xB2, 0xC0, 0x18, 0xDB, 0xBC, 0xB6, 0xEF,
  29773. 0x00, 0xF3, 0x05, 0xBF, 0x93, 0x66, 0x6B, 0xD4,
  29774. 0x7F, 0xEA, 0x91, 0x93, 0xBC, 0x23, 0x3D, 0xB3,
  29775. 0x91, 0x21, 0x44, 0x2E, 0x93, 0x8D, 0xA5, 0xDD,
  29776. 0x07, 0xEE, 0x6E, 0x87, 0x9C, 0x5B, 0x9D, 0xFF,
  29777. 0x41, 0xEC, 0xEE, 0x5E, 0x05, 0x89, 0xAE, 0x61,
  29778. 0x75, 0xFF, 0x5E, 0xC6, 0xF6, 0xD2, 0x62, 0x9F,
  29779. 0x56, 0xB1, 0x8B, 0x4D, 0xE6, 0x6F, 0xCB, 0x13,
  29780. 0xDF, 0x04, 0x00, 0xA7, 0x97, 0xC9, 0x22, 0x70,
  29781. 0xF6, 0x9B, 0xDE, 0xBD, 0xDC, 0xB8, 0x8C, 0x42,
  29782. 0x48, 0x91, 0x9B, 0x56, 0xCD, 0xA7, 0x0B, 0x8A,
  29783. 0xC4, 0xF9, 0x42, 0x9C, 0x29, 0x2D, 0xA9, 0x4D,
  29784. 0x64, 0x78, 0x28, 0x07, 0x64, 0xFE, 0x23, 0x86,
  29785. 0xFC, 0x38, 0xCB, 0x09, 0x31, 0x45, 0x88, 0x39,
  29786. 0xEF, 0x4E, 0x7D, 0xE8, 0xF0, 0x68, 0x9D, 0x99,
  29787. 0x80, 0x59, 0x88, 0xC7, 0xF9, 0x61, 0x11, 0x85,
  29788. 0x2C, 0x89, 0x29, 0xE5, 0xA5, 0x40, 0xD3, 0xB7,
  29789. 0x8D, 0x71, 0x2D, 0xEC, 0xC3, 0x96, 0xFE, 0xF3,
  29790. 0xEC, 0x34, 0x40, 0x21, 0x84, 0xE4, 0xFD, 0x29,
  29791. 0xF3, 0x63, 0xEA, 0x80, 0xF6, 0xFC, 0x50, 0xBA,
  29792. 0x9A, 0x11, 0x35, 0x1A, 0xCE, 0xEA, 0x8F, 0xE6,
  29793. 0x8D, 0x54, 0x1E, 0x1A, 0xA5, 0x84, 0x8D, 0x9F,
  29794. 0x6E, 0x61, 0xDF, 0xB6, 0x2B, 0x2F, 0x23, 0xBC,
  29795. 0x50, 0x81, 0xE8, 0x2F, 0x76, 0x22, 0x6E, 0x03,
  29796. 0x28, 0x49, 0x82, 0xEC, 0x48, 0x48, 0x12, 0x09,
  29797. 0xB1, 0xA7, 0xD4, 0xC8, 0x79, 0x7E, 0x44, 0xBF,
  29798. 0xA8, 0x70, 0xB2, 0x20, 0x04, 0xDB, 0x74, 0xBD,
  29799. 0x7D, 0x47, 0x8D, 0x5B, 0x36, 0x14, 0xD2, 0xB1,
  29800. 0xDA, 0x75, 0x02, 0xB3, 0x98, 0xEB, 0x9D, 0xA8,
  29801. 0x0D, 0x06, 0x46, 0x1E, 0x90, 0xE0, 0x30, 0x60,
  29802. 0x44, 0x6A, 0xB4, 0xA8, 0x23, 0x84, 0x32, 0xBF,
  29803. 0xAF, 0x75, 0x2F, 0x39, 0x17, 0x91, 0x21, 0x4F,
  29804. 0x1E, 0x6B, 0x63, 0x59, 0x0D, 0x53, 0x60, 0x60,
  29805. 0xD1, 0xC2, 0x45, 0x30, 0x7B, 0xC5, 0xC1, 0xBA,
  29806. 0xC4, 0xAA, 0xA0, 0x99, 0xD3, 0x6B, 0xB6, 0xDC,
  29807. 0xBC, 0x97, 0x3C, 0xF2, 0xE6, 0x9F, 0x27, 0x34,
  29808. 0xD0, 0xF2, 0x9A, 0xEE, 0xC4, 0x56, 0x7B, 0x99,
  29809. 0xA1, 0x6B, 0xC1, 0x7C, 0x6C, 0xDD, 0xAC, 0xEF,
  29810. 0xE4, 0x99, 0x27, 0xFB, 0x14, 0xE7, 0xD9, 0x8D,
  29811. 0xD4, 0x26, 0x35, 0x19, 0x46, 0x9C, 0xCA, 0x3D,
  29812. 0xB4, 0x67, 0x9A, 0x68, 0xCE, 0xED, 0xA9, 0x55,
  29813. 0x59, 0x22, 0x10, 0xFC, 0x49, 0xAA, 0x5F, 0xBE,
  29814. 0x93, 0x4C, 0xC7, 0x3D, 0x84, 0xE4, 0xBA, 0x54,
  29815. 0x78, 0x00, 0x2D, 0x68, 0x90, 0x98, 0x90, 0x68,
  29816. 0xEF, 0x8F, 0xC9, 0x8C, 0x25, 0x32, 0xB8, 0x3B,
  29817. 0xF3, 0xCB, 0x9E, 0xF0, 0x28, 0x93, 0xC2, 0x15,
  29818. 0x24, 0x26, 0xB9, 0xD1, 0xA9, 0x47, 0x34, 0xDF,
  29819. 0xB4, 0xF9, 0x11, 0x35, 0x14, 0x3C, 0x9E, 0xED,
  29820. 0x18, 0xFD, 0x51, 0xAE, 0x87, 0x5D, 0x07, 0xA2,
  29821. 0x37, 0x75, 0x60, 0x6A, 0x73, 0x4F, 0xBA, 0x98,
  29822. 0xC0, 0x63, 0xB4, 0xA1, 0x62, 0x2E, 0x7F, 0xF2,
  29823. 0x1A, 0xA7, 0xE6, 0x52, 0xA3, 0xD6, 0xC1, 0x9F,
  29824. 0xE0, 0xDC, 0x67, 0x61, 0xB7, 0xD3, 0x53, 0x02,
  29825. 0xBF, 0x21, 0x4D, 0x30, 0x79, 0xF7, 0x60, 0x51,
  29826. 0x08, 0x2A, 0x87, 0x59, 0x29, 0x92, 0x0D, 0xC3,
  29827. 0xB3, 0xCB, 0x43, 0x21, 0x1A, 0x23, 0xA4, 0x3A,
  29828. 0x50, 0x33, 0x2F, 0xAF, 0x1A, 0xC2, 0x19, 0x1E,
  29829. 0x71, 0x71, 0x25, 0xF6, 0x3E, 0x25, 0x86, 0xC4,
  29830. 0xD8, 0x6D, 0xCA, 0x6B, 0xCD, 0x3D, 0x03, 0x8F,
  29831. 0x9D, 0x3A, 0x7B, 0x66, 0xCB, 0xC7, 0xDF, 0x34
  29832. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  29833. 0x30, 0x82, 0x07, 0xb2, 0x30, 0x0d, 0x06, 0x09,
  29834. 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x03,
  29835. 0x12, 0x03, 0x82, 0x07, 0xa1, 0x00,
  29836. 0xD2, 0xFD, 0x03, 0xF3, 0xA1, 0xB7, 0xF6, 0x35,
  29837. 0xAF, 0x9F, 0x34, 0xD5, 0x80, 0xA9, 0x8F, 0x52,
  29838. 0x4C, 0x73, 0x5B, 0xD5, 0xBA, 0x23, 0x55, 0xDC,
  29839. 0x6E, 0x03, 0x5B, 0xD2, 0x17, 0x65, 0x58, 0x0C,
  29840. 0xBB, 0x11, 0x19, 0x23, 0xF1, 0x94, 0xA7, 0xCC,
  29841. 0x8A, 0x7B, 0xB2, 0xEB, 0xC5, 0xC0, 0xE7, 0x1A,
  29842. 0xA6, 0x37, 0xCC, 0x80, 0x0E, 0x61, 0x03, 0xB8,
  29843. 0x50, 0xA5, 0x39, 0xB2, 0xA3, 0x9E, 0x1B, 0x6D,
  29844. 0x71, 0x3E, 0x5D, 0xB8, 0x31, 0x4C, 0x9A, 0xE1,
  29845. 0xF8, 0xBF, 0x8A, 0x38, 0xF0, 0x6A, 0xFB, 0x9D,
  29846. 0x73, 0xB1, 0x61, 0xB0, 0xFF, 0xE3, 0xA4, 0x89,
  29847. 0x17, 0x06, 0xAE, 0x26, 0xD5, 0x4F, 0xFB, 0x49,
  29848. 0x6D, 0xF8, 0xDC, 0x0F, 0x19, 0x83, 0x50, 0x95,
  29849. 0x00, 0xC9, 0xAB, 0xBD, 0x28, 0xE5, 0x9B, 0x3F,
  29850. 0xCD, 0xAB, 0xBD, 0xAD, 0xAB, 0xD4, 0x5E, 0xC3,
  29851. 0x14, 0x99, 0x37, 0x8B, 0xDE, 0x84, 0x9E, 0x7C,
  29852. 0x1F, 0x19, 0xB7, 0x04, 0x4D, 0x67, 0xE0, 0x51,
  29853. 0x06, 0xD7, 0x13, 0x6D, 0x95, 0x38, 0x0D, 0x56,
  29854. 0x05, 0xD4, 0x46, 0x5D, 0x87, 0x75, 0x57, 0x06,
  29855. 0x5D, 0xF0, 0xA7, 0x5D, 0x3C, 0x28, 0x54, 0x2F,
  29856. 0x40, 0xFE, 0xED, 0x42, 0xEC, 0x7E, 0x28, 0x06,
  29857. 0x37, 0xB0, 0x83, 0xD9, 0x88, 0xBC, 0xA5, 0xF6,
  29858. 0x39, 0x4E, 0x02, 0x39, 0x6C, 0x46, 0x76, 0x18,
  29859. 0x4F, 0xB6, 0x33, 0x18, 0xDA, 0xFA, 0xF5, 0xBB,
  29860. 0xDD, 0xE0, 0x0E, 0x30, 0x8F, 0xE8, 0x40, 0x19,
  29861. 0xC2, 0x34, 0x0A, 0x3F, 0x3E, 0x1C, 0x08, 0x65,
  29862. 0x62, 0x49, 0x70, 0x71, 0x12, 0x83, 0x35, 0x6A,
  29863. 0xE1, 0x4B, 0xD6, 0xB9, 0x4D, 0x1C, 0x9A, 0xE1,
  29864. 0x88, 0xDE, 0x1A, 0x8A, 0x2C, 0xA8, 0x24, 0xA8,
  29865. 0xEA, 0xE2, 0xFE, 0x6A, 0xFB, 0x38, 0xD8, 0x3A,
  29866. 0x2D, 0x99, 0x99, 0x6A, 0xB2, 0x1F, 0xE3, 0xE8,
  29867. 0x4C, 0x0B, 0xE6, 0xB6, 0xDA, 0x08, 0x87, 0x9B,
  29868. 0x67, 0x73, 0x74, 0xFA, 0x7C, 0x69, 0x1B, 0x13,
  29869. 0xD4, 0x0F, 0xA9, 0xD4, 0xCC, 0x26, 0xB2, 0x28,
  29870. 0x8D, 0x5A, 0x8C, 0x9A, 0x43, 0x72, 0x43, 0x81,
  29871. 0x00, 0x4D, 0x61, 0xB0, 0xD5, 0x7F, 0xF4, 0x00,
  29872. 0x31, 0x4C, 0x8E, 0x30, 0xEE, 0x79, 0x6A, 0xF1,
  29873. 0x0F, 0x7E, 0xE2, 0x1B, 0xF1, 0x3D, 0x08, 0x18,
  29874. 0x04, 0x65, 0xAB, 0xC7, 0x2E, 0xDD, 0xB0, 0x80,
  29875. 0xC6, 0xA0, 0x71, 0x84, 0xE3, 0xEE, 0xDC, 0x47,
  29876. 0xC1, 0x9A, 0xA7, 0xF0, 0x9D, 0x1F, 0x33, 0x09,
  29877. 0xE1, 0x83, 0xA2, 0xBD, 0x9B, 0x05, 0x73, 0xDD,
  29878. 0xE4, 0x74, 0xA8, 0x1B, 0xA4, 0xF7, 0x8D, 0x0C,
  29879. 0x52, 0x3D, 0x0C, 0x04, 0xF9, 0x00, 0x60, 0xFD,
  29880. 0x57, 0x1A, 0x35, 0xC0, 0x37, 0xE0, 0x79, 0xC5,
  29881. 0xE2, 0x10, 0xD7, 0x39, 0x0D, 0xF5, 0x68, 0xF2,
  29882. 0xE2, 0xF0, 0x3C, 0xE4, 0x44, 0x20, 0xC8, 0x2F,
  29883. 0x3F, 0xE6, 0x9E, 0xB9, 0xB4, 0x8E, 0xE9, 0x09,
  29884. 0x62, 0xD6, 0xB0, 0xF2, 0x44, 0x40, 0x64, 0x8F,
  29885. 0x71, 0xED, 0xB2, 0x41, 0xEE, 0x65, 0x66, 0xFC,
  29886. 0x1A, 0x64, 0xCA, 0xBF, 0x66, 0xBE, 0x6F, 0xEC,
  29887. 0xBC, 0xB1, 0x38, 0x7C, 0x82, 0xA7, 0xBC, 0x20,
  29888. 0x2D, 0x9E, 0x36, 0x79, 0x98, 0xE2, 0xA2, 0x91,
  29889. 0xAF, 0x0C, 0xD1, 0x57, 0x06, 0x77, 0xFE, 0x8D,
  29890. 0x63, 0xA3, 0x28, 0x5A, 0x2E, 0xA6, 0xEB, 0x29,
  29891. 0xAF, 0x9D, 0xC1, 0xAE, 0xC1, 0xC3, 0x6C, 0x47,
  29892. 0x06, 0xB1, 0x2B, 0xAA, 0x20, 0x83, 0x96, 0x92,
  29893. 0xF2, 0x86, 0xA6, 0xE0, 0x32, 0x14, 0x68, 0xF7,
  29894. 0x47, 0x93, 0x45, 0xC4, 0xD5, 0x2F, 0xBD, 0xB2,
  29895. 0xF0, 0x67, 0x25, 0xB5, 0x54, 0xB8, 0x9E, 0x24,
  29896. 0x92, 0x61, 0x26, 0x81, 0xAC, 0xEB, 0xC6, 0xC7,
  29897. 0xBA, 0xDA, 0x92, 0x25, 0x81, 0x8D, 0xBC, 0x35,
  29898. 0xD6, 0x4C, 0x22, 0xC4, 0x8B, 0xFF, 0x80, 0xA7,
  29899. 0x30, 0xD0, 0x71, 0x6D, 0xFA, 0xC9, 0x9D, 0xFD,
  29900. 0x5B, 0x89, 0x92, 0x61, 0x1D, 0x0C, 0x93, 0xEE,
  29901. 0x90, 0xBD, 0xB2, 0x60, 0x02, 0x2A, 0xFE, 0x25,
  29902. 0xD9, 0x13, 0xE0, 0x6E, 0xFF, 0xB5, 0x9C, 0xB1,
  29903. 0xF8, 0xA6, 0x0C, 0xBF, 0xA5, 0xAB, 0x2F, 0x45,
  29904. 0x9A, 0x16, 0xF4, 0x67, 0xE9, 0x89, 0x52, 0x5E,
  29905. 0x0A, 0x37, 0xEB, 0xE5, 0x6E, 0x83, 0x3F, 0xDE,
  29906. 0x55, 0xDB, 0x9D, 0x15, 0x30, 0xAD, 0xCF, 0x45,
  29907. 0x84, 0x6D, 0xF2, 0x81, 0xE4, 0x7C, 0xAA, 0x1E,
  29908. 0x0A, 0x27, 0xEF, 0xDE, 0x21, 0x07, 0xD3, 0x54,
  29909. 0xCE, 0xA0, 0xF6, 0xA4, 0x54, 0x69, 0x2F, 0x04,
  29910. 0xCD, 0x83, 0x8E, 0xBD, 0xD4, 0x6E, 0x19, 0x1E,
  29911. 0x5D, 0x9C, 0x11, 0x83, 0x9A, 0x2C, 0x3F, 0x48,
  29912. 0x8A, 0x4F, 0xC7, 0xCD, 0x26, 0x5A, 0x7B, 0x5D,
  29913. 0x32, 0xB0, 0x8C, 0xBD, 0xBF, 0xAB, 0x9D, 0x2C,
  29914. 0xCD, 0x76, 0x22, 0x2C, 0x8E, 0xE3, 0x7D, 0xDC,
  29915. 0xBD, 0x2A, 0xA0, 0x63, 0xED, 0x86, 0x14, 0x73,
  29916. 0xA6, 0x45, 0x4C, 0xAE, 0xA3, 0x77, 0x85, 0x0B,
  29917. 0x1A, 0x2B, 0x9D, 0xDB, 0xBC, 0xB3, 0x74, 0xFA,
  29918. 0xB5, 0xB1, 0x2F, 0x35, 0x1C, 0x8E, 0x58, 0x88,
  29919. 0x87, 0x2E, 0x5C, 0xD1, 0xF6, 0x0A, 0x4F, 0xAE,
  29920. 0x1F, 0xF8, 0x37, 0xD1, 0x92, 0xC2, 0x2B, 0xEB,
  29921. 0x41, 0xEE, 0x6F, 0xA3, 0x92, 0xFC, 0xDF, 0x45,
  29922. 0x50, 0xFF, 0x46, 0xB5, 0xCE, 0x90, 0x6D, 0x01,
  29923. 0x7E, 0xF3, 0x07, 0x7D, 0xF1, 0x32, 0x30, 0x0D,
  29924. 0x8B, 0xBF, 0xA9, 0xBB, 0x03, 0xC7, 0x5E, 0x79,
  29925. 0xE2, 0xF0, 0x4C, 0x28, 0x4A, 0xD0, 0x6A, 0x44,
  29926. 0x39, 0x96, 0x49, 0xC3, 0xE2, 0xA2, 0xA8, 0xD1,
  29927. 0xEF, 0xE9, 0xB7, 0xA4, 0xE0, 0xC2, 0x71, 0x04,
  29928. 0x7A, 0xB7, 0x59, 0x08, 0xBF, 0xF7, 0xDF, 0x9E,
  29929. 0x30, 0xEC, 0xA5, 0x47, 0x74, 0x5B, 0xAE, 0x23,
  29930. 0xA8, 0x6F, 0xF9, 0xA8, 0xB5, 0x8C, 0x25, 0x38,
  29931. 0xB8, 0x8B, 0x86, 0x64, 0x01, 0x07, 0x69, 0x02,
  29932. 0xDC, 0x5F, 0x0B, 0xD7, 0x61, 0x68, 0x7B, 0x49,
  29933. 0xEA, 0xFE, 0x36, 0xD3, 0x50, 0xCB, 0xED, 0xFD,
  29934. 0xD3, 0x6C, 0x12, 0x1C, 0xF2, 0x37, 0x86, 0xBF,
  29935. 0xCF, 0x7E, 0x47, 0x07, 0x64, 0x96, 0xEA, 0xB6,
  29936. 0xBB, 0xDA, 0x77, 0x40, 0x49, 0xC2, 0xEB, 0xAB,
  29937. 0xE2, 0xDE, 0x99, 0xC4, 0xC2, 0x4F, 0x2D, 0xB7,
  29938. 0x36, 0x84, 0x01, 0x5B, 0x37, 0x39, 0x77, 0x49,
  29939. 0x67, 0x60, 0xCF, 0x9A, 0xC2, 0x3D, 0x8B, 0x62,
  29940. 0x31, 0x33, 0xDB, 0x2D, 0xE1, 0x0D, 0x73, 0xFA,
  29941. 0x6A, 0xD1, 0xC6, 0xDA, 0xC8, 0x43, 0x4F, 0x28,
  29942. 0xC6, 0xE2, 0x51, 0xCE, 0x72, 0x93, 0xCF, 0xF3,
  29943. 0xF3, 0xB6, 0x1E, 0xFC, 0xB5, 0xA4, 0x35, 0x12,
  29944. 0x36, 0x70, 0xF2, 0x98, 0x46, 0xA1, 0x3D, 0xF3,
  29945. 0xEE, 0x71, 0x26, 0x04, 0x46, 0x1F, 0x1B, 0xAB,
  29946. 0x8F, 0x4E, 0xBC, 0x83, 0x6D, 0xE0, 0x58, 0x97,
  29947. 0x8A, 0xE7, 0x34, 0x39, 0x6A, 0x98, 0x08, 0x1B,
  29948. 0x35, 0xCC, 0x98, 0x18, 0x8A, 0x86, 0x94, 0x9C,
  29949. 0x99, 0x27, 0x0D, 0x47, 0x09, 0x85, 0x4C, 0x5B,
  29950. 0x35, 0xB1, 0x7F, 0x48, 0xA3, 0x73, 0x13, 0x4C,
  29951. 0x81, 0x4C, 0xC8, 0xA0, 0xF3, 0xE2, 0xFA, 0x80,
  29952. 0x7F, 0x2A, 0x91, 0x85, 0x30, 0x90, 0x78, 0x64,
  29953. 0x77, 0x82, 0x82, 0xD7, 0x5E, 0x03, 0xA4, 0x1B,
  29954. 0x25, 0x04, 0xEE, 0xD8, 0x16, 0xA4, 0x17, 0xA3,
  29955. 0xAC, 0x6B, 0xA1, 0x60, 0x80, 0xC3, 0x9B, 0x73,
  29956. 0x10, 0x19, 0x20, 0x02, 0xA7, 0x28, 0xF7, 0xF2,
  29957. 0x03, 0x95, 0x00, 0x9A, 0x9E, 0x16, 0x76, 0x7C,
  29958. 0xE1, 0x97, 0x1F, 0x5D, 0xE7, 0xD2, 0x29, 0xA5,
  29959. 0x06, 0x13, 0x36, 0x9E, 0x43, 0x82, 0x04, 0x5A,
  29960. 0x8E, 0x81, 0x90, 0x1F, 0x4D, 0xBA, 0x81, 0x02,
  29961. 0xF3, 0xD4, 0x13, 0xFE, 0x35, 0xB3, 0x26, 0xA8,
  29962. 0x74, 0xF2, 0x33, 0xB7, 0x19, 0xA7, 0x13, 0x76,
  29963. 0x00, 0xD3, 0x5D, 0x33, 0xAE, 0xB6, 0xB7, 0x25,
  29964. 0x96, 0x24, 0x08, 0x3A, 0xA9, 0x68, 0x73, 0x0C,
  29965. 0x8F, 0x78, 0x29, 0x2A, 0xD2, 0x8F, 0x14, 0xEE,
  29966. 0xAB, 0xE6, 0x60, 0x83, 0x59, 0x84, 0xFE, 0x69,
  29967. 0xEF, 0x23, 0xDE, 0xC8, 0xC3, 0x27, 0xC0, 0xEB,
  29968. 0x0B, 0x88, 0x2D, 0x58, 0x7E, 0x1E, 0xC4, 0x33,
  29969. 0xDA, 0x85, 0xC9, 0xFD, 0x1E, 0x0A, 0x34, 0x99,
  29970. 0x4D, 0xEA, 0x24, 0x0C, 0x85, 0x44, 0x52, 0xD1,
  29971. 0x8C, 0x30, 0xF4, 0x96, 0xE4, 0x9E, 0xC9, 0x04,
  29972. 0xB6, 0x02, 0xE0, 0xF5, 0x06, 0x2E, 0xDC, 0xDA,
  29973. 0x03, 0x28, 0x0A, 0x53, 0xB4, 0x31, 0x35, 0x74,
  29974. 0xCC, 0x2C, 0x0D, 0x54, 0x71, 0xBC, 0x96, 0x13,
  29975. 0xBD, 0xFD, 0x66, 0x41, 0xF5, 0xBD, 0x12, 0x7B,
  29976. 0xAB, 0x5B, 0x5E, 0xB3, 0xD4, 0x99, 0xA3, 0x31,
  29977. 0x14, 0x04, 0x82, 0x20, 0xE8, 0x19, 0xF8, 0xEE,
  29978. 0x12, 0xCA, 0x92, 0x2C, 0x8F, 0x17, 0xD9, 0xC9,
  29979. 0xF5, 0x1A, 0xD5, 0xBD, 0x68, 0x83, 0xB1, 0x0E,
  29980. 0x6A, 0xA2, 0x48, 0x3B, 0xA4, 0x9D, 0xC5, 0x47,
  29981. 0xDA, 0x76, 0x86, 0x15, 0x13, 0x44, 0xF4, 0xE9,
  29982. 0x09, 0x9B, 0x38, 0xE4, 0x30, 0xB5, 0x22, 0x6B,
  29983. 0x05, 0x98, 0x32, 0xCF, 0x03, 0xDB, 0x48, 0xFB,
  29984. 0x02, 0xDB, 0xA4, 0xE6, 0x15, 0x93, 0xDC, 0x45,
  29985. 0x76, 0x36, 0x04, 0x91, 0x89, 0x0E, 0x53, 0xEC,
  29986. 0x0E, 0x6A, 0xC7, 0x3C, 0xF3, 0x2B, 0x25, 0xD8,
  29987. 0x23, 0xB3, 0x84, 0x56, 0xE2, 0x86, 0x50, 0x5A,
  29988. 0x54, 0x1E, 0x5A, 0xEE, 0xE9, 0x6B, 0x19, 0x14,
  29989. 0xF5, 0xF7, 0x66, 0x87, 0xCE, 0x2B, 0x01, 0x60,
  29990. 0x22, 0x7A, 0xBE, 0xD7, 0x79, 0x93, 0x59, 0x4B,
  29991. 0xCD, 0x83, 0x13, 0x66, 0x20, 0x6D, 0x75, 0x71,
  29992. 0x40, 0x82, 0xF1, 0xC4, 0x6F, 0x1F, 0x44, 0x39,
  29993. 0xAC, 0x81, 0xA5, 0x7A, 0xF3, 0x1C, 0x81, 0xC5,
  29994. 0x55, 0x30, 0x7A, 0x07, 0x0F, 0xFA, 0x94, 0xE0,
  29995. 0x47, 0x9B, 0x78, 0x4B, 0xBD, 0x88, 0xA6, 0x0C,
  29996. 0xD4, 0xC7, 0xCF, 0xD9, 0x4E, 0x6A, 0xFE, 0x02,
  29997. 0xF6, 0xB2, 0x1F, 0x72, 0xAF, 0x0D, 0xCD, 0x66,
  29998. 0x09, 0xD4, 0x0C, 0x96, 0x5C, 0x14, 0xE5, 0xF2,
  29999. 0x38, 0x91, 0x83, 0xE5, 0x3D, 0xE9, 0x30, 0xF7,
  30000. 0xDE, 0x1D, 0x44, 0x21, 0x5C, 0xF4, 0x91, 0x44,
  30001. 0x84, 0x4E, 0x8B, 0x87, 0xF7, 0x8A, 0x7F, 0x13,
  30002. 0x2A, 0xEF, 0xE2, 0x2B, 0xE8, 0x0B, 0x4E, 0x3A,
  30003. 0x05, 0xEE, 0x3A, 0x68, 0xCC, 0xF6, 0x09, 0xEF,
  30004. 0x44, 0x04, 0x74, 0x02, 0xE4, 0x49, 0x30, 0x46,
  30005. 0xE6, 0xF9, 0xC7, 0x67, 0xFF, 0x8A, 0x75, 0xE2,
  30006. 0x8B, 0x3C, 0xE0, 0x77, 0xFD, 0xE7, 0xE7, 0xEE,
  30007. 0xD3, 0x13, 0xB5, 0xBF, 0x7E, 0x46, 0x01, 0x27,
  30008. 0xCA, 0x81, 0x82, 0xE9, 0xBC, 0x79, 0x4C, 0x0D,
  30009. 0xFA, 0x73, 0x0F, 0xB9, 0x20, 0x08, 0x05, 0x75,
  30010. 0xA7, 0x51, 0xB5, 0xCA, 0xEC, 0x85, 0xA1, 0x09,
  30011. 0xB4, 0x42, 0x2B, 0xA2, 0x66, 0x74, 0x3F, 0x0D,
  30012. 0x03, 0x2B, 0xDA, 0x8F, 0x1C, 0xA6, 0x24, 0x8C,
  30013. 0xDB, 0x91, 0x75, 0x30, 0xDF, 0x13, 0x02, 0xA5,
  30014. 0xF8, 0xC1, 0x8D, 0xC6, 0x42, 0xD5, 0x24, 0x78,
  30015. 0xC9, 0x8C, 0x12, 0xA3, 0xF1, 0x6E, 0xF2, 0xB6,
  30016. 0x2B, 0x4F, 0x59, 0xEA, 0x1B, 0xB5, 0x8D, 0xE7,
  30017. 0xB6, 0x5B, 0x3C, 0x71, 0x53, 0xCE, 0x6D, 0xA5,
  30018. 0xE4, 0x95, 0x07, 0x46, 0xF8, 0x0E, 0x08, 0x7A,
  30019. 0x0E, 0x35, 0x86, 0xD0, 0x97, 0x79, 0x1B, 0xF3,
  30020. 0x6D, 0xEF, 0x86, 0x5D, 0x68, 0x59, 0x1D, 0x39,
  30021. 0xD0, 0x90, 0x37, 0x73, 0xEE, 0xA9, 0x62, 0x14,
  30022. 0x7F, 0x34, 0x70, 0x41, 0x38, 0xB5, 0x4D, 0xF7,
  30023. 0x92, 0x4C, 0xDD, 0x8C, 0x33, 0x3D, 0xB5, 0xE1,
  30024. 0xA4, 0x09, 0xCC, 0xB2, 0xB3, 0x4E, 0x2C, 0x3C,
  30025. 0x8C, 0x7F, 0xDD, 0x3F, 0xD8, 0xD0, 0x12, 0xCB,
  30026. 0xF3, 0x82, 0xAA, 0xA8, 0x5E, 0x83, 0xA1, 0x2F,
  30027. 0x23, 0x5A, 0x2D, 0x14, 0x7D, 0x03, 0x5B, 0x7B,
  30028. 0x28, 0xB3, 0x4B, 0x6F, 0x57, 0x94, 0x9F, 0x32,
  30029. 0x24, 0x82, 0xA7, 0xD4, 0xD3, 0xB1, 0x50, 0x45,
  30030. 0xC4, 0x20, 0xD5, 0xAD, 0xDC, 0x7F, 0x0E, 0x69,
  30031. 0xB4, 0xDC, 0x1C, 0xBA, 0x58, 0xB0, 0x1D, 0x87,
  30032. 0x24, 0x80, 0xB0, 0x6A, 0x26, 0x0D, 0x82, 0x7D,
  30033. 0x89, 0x1B, 0x13, 0xC4, 0xC5, 0xCA, 0x50, 0xC7,
  30034. 0x48, 0xDE, 0x3C, 0x77, 0x1B, 0xE6, 0x1E, 0x9A,
  30035. 0xA1, 0x70, 0x16, 0x5C, 0xB0, 0x1F, 0x4B, 0xF5,
  30036. 0xDA, 0x27, 0xA7, 0x79, 0x1D, 0x3A, 0xD3, 0xF6,
  30037. 0x26, 0x7B, 0x4C, 0xB4, 0xE6, 0x1B, 0x28, 0xFA,
  30038. 0x17, 0x08, 0x41, 0x8D, 0x93, 0x2D, 0xFC, 0x41,
  30039. 0x61, 0x88, 0x0C, 0x5D, 0x3B, 0x17, 0xA9, 0x66,
  30040. 0x3A, 0x90, 0x61, 0xFA, 0x8F, 0x18, 0x04, 0x31,
  30041. 0x58, 0x50, 0xFE, 0x4E, 0x73, 0x06, 0xC8, 0x82,
  30042. 0xB3, 0x82, 0x27, 0xE8, 0x67, 0xF8, 0x08, 0x72,
  30043. 0xCD, 0xC1, 0x94, 0x4D, 0x47, 0x26, 0x15, 0xEA,
  30044. 0x49, 0x00, 0xEF, 0x7D, 0x27, 0x0B, 0x88, 0x1D,
  30045. 0x41, 0x30, 0xF5, 0x6C, 0x5C, 0xC9, 0x80, 0xD9,
  30046. 0x2A, 0x47, 0xAD, 0xA6, 0x65, 0x7E, 0xB6, 0xF3,
  30047. 0x7A, 0x38, 0x5D, 0x2D, 0x8C, 0xC9, 0x93, 0xE1,
  30048. 0x44, 0x2E, 0xB0, 0x52, 0x81, 0x85, 0x36, 0x36,
  30049. 0x99, 0x1E, 0x34, 0xAA, 0xDC, 0x68, 0x95, 0x4D,
  30050. 0x04, 0xE7, 0xAD, 0xEF, 0x76, 0xBF, 0x88, 0x0F,
  30051. 0x05, 0x9B, 0x0C, 0xBB, 0x55, 0xD9, 0x15, 0xA4,
  30052. 0xB1, 0x23, 0xE2, 0xF1, 0x33, 0x9A, 0x07, 0x3C,
  30053. 0xBF, 0xBC, 0x40, 0x9B, 0xEF, 0xF6, 0x40, 0x0A,
  30054. 0xE0, 0x96, 0xD5, 0xAE, 0x18, 0xEC, 0x42, 0xCF,
  30055. 0xFA, 0xD5, 0xB4, 0x98, 0x0F, 0xA3, 0x5B, 0xF0,
  30056. 0x34, 0x13, 0xAD, 0xB5, 0xD7, 0xE6, 0x87, 0x6A,
  30057. 0xC3, 0x55, 0xD1, 0xC9, 0xED, 0x70, 0xCA, 0x2B,
  30058. 0x97, 0x39, 0x54, 0xD1, 0x2B, 0x3C, 0xDD, 0x76,
  30059. 0xAC, 0x68, 0x35, 0xDB, 0x96, 0x00, 0x3E, 0xD8,
  30060. 0xC4, 0xE2, 0x88, 0xB7, 0x1F, 0xD7, 0x7D, 0xBA,
  30061. 0xA7, 0x63, 0x57, 0x20, 0xE1, 0x2A, 0xE0, 0xA3,
  30062. 0x17, 0xDE, 0x80, 0x8C, 0x66, 0x4E, 0x31, 0x7F,
  30063. 0x55, 0x27, 0x57, 0x91, 0xF3, 0x24, 0x5C, 0xA4,
  30064. 0xFE, 0x5D, 0x4D, 0x41, 0x07, 0x7F, 0xC1, 0x50,
  30065. 0xA6, 0xE4, 0x03, 0xD5, 0xA2, 0x08, 0xE4, 0x6E,
  30066. 0xAD, 0xBE, 0x8F, 0x2C, 0xFB, 0x8A, 0xF4, 0x72,
  30067. 0xF4, 0xA0, 0xCE, 0xAC, 0x01, 0x52, 0x19, 0x47,
  30068. 0x8E, 0x6B, 0x86, 0xC9, 0x58, 0xCF, 0x86, 0x52,
  30069. 0x5B, 0x74, 0x85, 0xC1, 0x73, 0x4C, 0x7E, 0xF0,
  30070. 0x0E, 0x90, 0x68, 0x3F, 0xFF, 0x5D, 0xBD, 0x0A,
  30071. 0x7D, 0x41, 0x3A, 0x85, 0x50, 0x21, 0x02, 0x6A,
  30072. 0x1B, 0x32, 0x01, 0x3A, 0x46, 0x16, 0xCB, 0xCD,
  30073. 0x37, 0x00, 0xAC, 0xBC, 0x70, 0x5B, 0xE3, 0xEF,
  30074. 0xBA, 0x62, 0x5C, 0x69, 0xA0, 0x25, 0x26, 0x7B,
  30075. 0xCE, 0x9D, 0x13, 0x5E, 0x3F, 0x5B, 0x5C, 0xC8,
  30076. 0xC4, 0x39, 0x56, 0x40, 0x7E, 0x84, 0xB6, 0x66,
  30077. 0x31, 0x03, 0xE2, 0x9C, 0x24, 0x20, 0x35, 0x55,
  30078. 0x1A, 0xE7, 0x97, 0xF5, 0x6C, 0x63, 0x74, 0xBE,
  30079. 0x0C, 0x79, 0x8C, 0x0C, 0xF3, 0x98, 0xF1, 0xED
  30080. #else
  30081. 0x30, 0x82, 0x0a, 0x32, 0x30, 0x0d, 0x06, 0x09,
  30082. 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x03,
  30083. 0x13, 0x03, 0x82, 0x0a, 0x21, 0x00,
  30084. 0x69, 0x24, 0xBB, 0x42, 0x57, 0xA7, 0xB9, 0xAF,
  30085. 0xF0, 0x95, 0xC3, 0x0B, 0xB3, 0x5C, 0x6A, 0xE4,
  30086. 0x19, 0x82, 0x63, 0x12, 0x0F, 0x80, 0x39, 0xAA,
  30087. 0x4E, 0x78, 0xE1, 0x74, 0xA7, 0x86, 0xCE, 0x00,
  30088. 0x83, 0x01, 0xE6, 0x66, 0xF5, 0x9D, 0x3E, 0xC5,
  30089. 0x04, 0x4D, 0xE4, 0x56, 0x78, 0x8F, 0xDE, 0x19,
  30090. 0xEB, 0x39, 0x67, 0x7B, 0x5F, 0x9F, 0xE1, 0x41,
  30091. 0x50, 0xDA, 0x46, 0x3A, 0x70, 0x6F, 0x3B, 0xAF,
  30092. 0x71, 0x5B, 0x95, 0x33, 0x6B, 0x2D, 0x68, 0x5A,
  30093. 0x7C, 0xD7, 0x88, 0x07, 0x13, 0xE4, 0x58, 0x7B,
  30094. 0xF7, 0xD8, 0x57, 0xBF, 0x7E, 0x31, 0x56, 0x96,
  30095. 0xB8, 0xD0, 0xD9, 0xD4, 0x9E, 0x14, 0x29, 0x18,
  30096. 0xBF, 0x09, 0x74, 0xE7, 0xF4, 0x32, 0x37, 0xD4,
  30097. 0xBE, 0x3A, 0xD3, 0x94, 0x59, 0x9E, 0x3D, 0x39,
  30098. 0xBB, 0x76, 0x49, 0x93, 0x25, 0x53, 0x44, 0x7E,
  30099. 0x5D, 0x5A, 0xCC, 0x34, 0x99, 0x93, 0x01, 0x76,
  30100. 0xEC, 0xD3, 0xA8, 0x44, 0xA4, 0x25, 0xF5, 0x0D,
  30101. 0x05, 0x11, 0xC9, 0x22, 0x6C, 0x4B, 0x9A, 0x24,
  30102. 0xF2, 0xA0, 0x11, 0xCD, 0x88, 0xD3, 0x23, 0x08,
  30103. 0xE0, 0x31, 0x2A, 0x0C, 0x87, 0xCC, 0x34, 0xA9,
  30104. 0x95, 0x82, 0x3C, 0x65, 0xF4, 0xF0, 0xF9, 0x8E,
  30105. 0x50, 0xC3, 0x77, 0x88, 0xCE, 0x38, 0xDC, 0x28,
  30106. 0xFB, 0x8B, 0x9B, 0xFA, 0xAF, 0xA9, 0x04, 0xB5,
  30107. 0x41, 0xEE, 0x71, 0x2F, 0x6A, 0x04, 0x1E, 0x06,
  30108. 0x11, 0x37, 0x4F, 0x6B, 0xF1, 0x7E, 0xAC, 0x0B,
  30109. 0xD5, 0x6F, 0x3B, 0x6B, 0xF3, 0x36, 0xDA, 0x92,
  30110. 0x42, 0x07, 0x0C, 0x24, 0x69, 0xA2, 0x0C, 0x4D,
  30111. 0x16, 0x16, 0x14, 0x9A, 0x61, 0x59, 0x25, 0x20,
  30112. 0x11, 0xD2, 0x99, 0xF9, 0x3F, 0x98, 0x6D, 0x87,
  30113. 0x5D, 0xD3, 0x0B, 0x38, 0xA2, 0x25, 0x49, 0x17,
  30114. 0x45, 0x70, 0x13, 0x8C, 0x2B, 0xB3, 0xAA, 0x9C,
  30115. 0xBE, 0xA9, 0x19, 0x74, 0xF3, 0xD8, 0x9B, 0xF5,
  30116. 0xAE, 0x32, 0xBE, 0x9E, 0x58, 0xB8, 0x54, 0xA2,
  30117. 0xF8, 0xE8, 0x6F, 0xF7, 0x67, 0x80, 0xC0, 0x34,
  30118. 0x90, 0xF4, 0x67, 0xDB, 0x06, 0x51, 0xC2, 0x0B,
  30119. 0x1D, 0xF6, 0x0E, 0xB9, 0x7A, 0x3C, 0x99, 0xD9,
  30120. 0xBD, 0x66, 0x4B, 0xE6, 0xA5, 0xE4, 0xC8, 0xA8,
  30121. 0xAD, 0x4C, 0xC3, 0x63, 0x90, 0xD7, 0x00, 0x4E,
  30122. 0x4B, 0xB4, 0x21, 0xDA, 0xED, 0x65, 0x4C, 0x35,
  30123. 0x7D, 0xA4, 0xD6, 0x84, 0x98, 0x93, 0x3E, 0xC7,
  30124. 0x17, 0x77, 0xAD, 0x64, 0xC2, 0xAE, 0x01, 0x3C,
  30125. 0x73, 0xEB, 0x45, 0x7C, 0x68, 0xEF, 0x9A, 0x74,
  30126. 0x5A, 0xDE, 0xEB, 0x4F, 0xDF, 0xC8, 0x79, 0xE7,
  30127. 0x74, 0xD0, 0x3F, 0xAF, 0x6B, 0x14, 0xAA, 0xB1,
  30128. 0x07, 0x52, 0xE2, 0x4B, 0x52, 0xD0, 0xF2, 0xD9,
  30129. 0x4D, 0x54, 0x0A, 0x1E, 0xBE, 0x10, 0xF5, 0x97,
  30130. 0xE5, 0x14, 0x44, 0x2D, 0x6C, 0x13, 0xC2, 0xE2,
  30131. 0x49, 0x8E, 0x8A, 0xF3, 0x01, 0x7C, 0x52, 0xDB,
  30132. 0x23, 0x3A, 0x90, 0x71, 0x7D, 0xF2, 0x5B, 0x4D,
  30133. 0x07, 0x2B, 0x7D, 0x88, 0xEE, 0x87, 0x31, 0xD1,
  30134. 0x68, 0x24, 0xC9, 0x5D, 0x1F, 0xB9, 0x83, 0xC4,
  30135. 0x49, 0xDE, 0xB4, 0x66, 0x27, 0x60, 0x60, 0xFE,
  30136. 0xE4, 0xC7, 0xEE, 0x38, 0x14, 0x51, 0xF2, 0x32,
  30137. 0xC2, 0x9C, 0x7C, 0x32, 0x20, 0x85, 0x0C, 0x61,
  30138. 0xD1, 0xC3, 0xC0, 0x0D, 0xB1, 0xCD, 0x97, 0x26,
  30139. 0xA0, 0x2A, 0x56, 0x60, 0x9F, 0x3A, 0x65, 0xD3,
  30140. 0xD1, 0x64, 0x60, 0x45, 0x88, 0xCD, 0x9B, 0x43,
  30141. 0x14, 0x12, 0xF1, 0xAD, 0xD9, 0x14, 0xC5, 0xC2,
  30142. 0xDA, 0xBB, 0xC9, 0x04, 0x67, 0xC0, 0xC4, 0xEA,
  30143. 0x5F, 0x76, 0xE2, 0x4A, 0xA6, 0x18, 0x76, 0x5F,
  30144. 0x8B, 0x06, 0x36, 0xD7, 0xB0, 0x65, 0xE1, 0xF4,
  30145. 0xE6, 0xF6, 0x22, 0xEA, 0xE1, 0x71, 0x52, 0x45,
  30146. 0x8C, 0x76, 0x65, 0x86, 0x77, 0x2D, 0x36, 0x3F,
  30147. 0xA9, 0x92, 0x14, 0xF4, 0x72, 0xB0, 0xDB, 0x8A,
  30148. 0x1E, 0x49, 0xD8, 0x2D, 0x02, 0x78, 0xF2, 0x95,
  30149. 0x8B, 0x0A, 0xAA, 0x15, 0x86, 0xDB, 0x13, 0x4B,
  30150. 0xDF, 0xD2, 0x43, 0x87, 0x42, 0x49, 0x50, 0x07,
  30151. 0xE2, 0xFE, 0x5B, 0x60, 0xE2, 0x46, 0x39, 0x92,
  30152. 0x26, 0x94, 0x7A, 0x12, 0xEA, 0x17, 0x63, 0x1C,
  30153. 0xAA, 0x53, 0x46, 0x87, 0xCB, 0x75, 0xC0, 0x60,
  30154. 0xB4, 0x79, 0x7E, 0xAB, 0x82, 0x77, 0xCC, 0x4F,
  30155. 0x8A, 0x7A, 0x20, 0x38, 0x76, 0x06, 0xEF, 0xE2,
  30156. 0xDB, 0xD3, 0xE7, 0x36, 0x24, 0x92, 0x77, 0xD9,
  30157. 0x0F, 0xCA, 0xB9, 0x92, 0xA8, 0xC9, 0x9E, 0x85,
  30158. 0xAB, 0x03, 0xEB, 0x4C, 0xAC, 0x5D, 0x88, 0x55,
  30159. 0x39, 0x58, 0x52, 0x8A, 0xF9, 0x29, 0x74, 0x71,
  30160. 0x81, 0x35, 0xF1, 0xD0, 0xC7, 0x93, 0xEB, 0x00,
  30161. 0x0E, 0xA0, 0xAE, 0xC3, 0xEC, 0x18, 0x58, 0xFD,
  30162. 0xD1, 0x86, 0x88, 0xD1, 0xDA, 0x27, 0x27, 0x8D,
  30163. 0xEB, 0xF2, 0xCA, 0x81, 0x10, 0xBA, 0x4A, 0x20,
  30164. 0x4F, 0x79, 0x30, 0xE1, 0xC8, 0xCE, 0xEC, 0xAF,
  30165. 0xB7, 0x3F, 0x75, 0xDD, 0xB3, 0x4C, 0x5C, 0x55,
  30166. 0x96, 0x8A, 0x79, 0x33, 0x05, 0x84, 0x26, 0xB5,
  30167. 0x5D, 0x03, 0x9F, 0x72, 0x92, 0xAC, 0x43, 0xF6,
  30168. 0x45, 0x84, 0xF6, 0xDF, 0x18, 0x7A, 0x1D, 0x6B,
  30169. 0x00, 0x3F, 0x51, 0x4C, 0xC1, 0x3B, 0x26, 0xC2,
  30170. 0xF3, 0x48, 0x19, 0x5A, 0xA3, 0x21, 0xDE, 0x6A,
  30171. 0x27, 0xEC, 0x11, 0x34, 0x8D, 0xE5, 0x0D, 0x82,
  30172. 0x5A, 0x29, 0x64, 0xC6, 0x31, 0x99, 0x2E, 0x4B,
  30173. 0x0B, 0x42, 0x5B, 0x1B, 0xEB, 0x4F, 0x96, 0x00,
  30174. 0xE3, 0xAD, 0xC4, 0x43, 0x1C, 0xF2, 0xE8, 0x8B,
  30175. 0x42, 0x23, 0xD2, 0xDB, 0x66, 0x3C, 0x3C, 0xE7,
  30176. 0x0E, 0xF8, 0x5D, 0xDD, 0x56, 0xA9, 0xBA, 0xF1,
  30177. 0x38, 0xA9, 0xD7, 0xED, 0xD8, 0x94, 0x13, 0x1C,
  30178. 0x3A, 0x8F, 0x41, 0xA0, 0x4E, 0xF9, 0xF8, 0x67,
  30179. 0x52, 0xB7, 0x21, 0x81, 0xFA, 0xBB, 0x37, 0xC8,
  30180. 0x6B, 0x87, 0x7E, 0x61, 0xD6, 0x0E, 0xED, 0x95,
  30181. 0xEE, 0xFF, 0xAB, 0xE6, 0x37, 0x6E, 0x14, 0xAC,
  30182. 0xA8, 0x17, 0xC5, 0xF4, 0x19, 0x61, 0xAF, 0x8A,
  30183. 0x78, 0x49, 0xBA, 0xC0, 0x94, 0x91, 0x7B, 0x2D,
  30184. 0x13, 0x22, 0x76, 0xB6, 0xB3, 0x48, 0x6A, 0xFF,
  30185. 0x95, 0x0D, 0x23, 0xD4, 0xAA, 0xDC, 0x24, 0xCE,
  30186. 0x98, 0xA5, 0x26, 0x9E, 0x1C, 0x69, 0x91, 0x79,
  30187. 0x60, 0xA3, 0x1E, 0xE0, 0x9A, 0x52, 0x7C, 0x35,
  30188. 0x81, 0x75, 0xCA, 0xA0, 0xCB, 0x1B, 0x01, 0x8E,
  30189. 0x95, 0x26, 0xD9, 0x35, 0x34, 0xEA, 0xDB, 0xAC,
  30190. 0xB5, 0x2B, 0x27, 0x3D, 0x73, 0x5E, 0x22, 0xDD,
  30191. 0x0D, 0x5C, 0x28, 0xFA, 0x3E, 0x47, 0xCF, 0xE9,
  30192. 0x0B, 0x52, 0x15, 0xAE, 0x24, 0xF1, 0x46, 0xC3,
  30193. 0x46, 0x4B, 0xFE, 0xAF, 0x01, 0xD2, 0x8D, 0xAA,
  30194. 0x55, 0x3C, 0x1E, 0x94, 0x42, 0x8A, 0x10, 0x4A,
  30195. 0x9D, 0x78, 0xAE, 0xC7, 0x62, 0x59, 0x1E, 0x88,
  30196. 0x79, 0xF7, 0x68, 0x51, 0xCF, 0xB4, 0x64, 0x85,
  30197. 0x66, 0x72, 0x1B, 0x0C, 0xAC, 0x1F, 0x14, 0xFE,
  30198. 0x16, 0x14, 0x9A, 0x9D, 0x82, 0x10, 0xCC, 0x8F,
  30199. 0x2F, 0x50, 0xDE, 0xF7, 0xB4, 0x6C, 0x84, 0x3B,
  30200. 0xE9, 0x3B, 0xD8, 0xD5, 0x56, 0x02, 0x49, 0x33,
  30201. 0x50, 0xAB, 0x56, 0x0E, 0xA5, 0xBA, 0x17, 0x71,
  30202. 0x64, 0x23, 0xBE, 0x0E, 0xB8, 0x36, 0x0A, 0xB1,
  30203. 0x09, 0xD8, 0xFB, 0x18, 0xBF, 0xEA, 0x04, 0x08,
  30204. 0x47, 0xB7, 0x33, 0x51, 0x45, 0xD4, 0xF2, 0x00,
  30205. 0xD1, 0x9C, 0xF6, 0xFE, 0x7B, 0xAC, 0x91, 0x7F,
  30206. 0x42, 0x6C, 0x9B, 0x3D, 0x39, 0xA9, 0xCA, 0x43,
  30207. 0x29, 0x81, 0x8F, 0x24, 0x0E, 0x7D, 0xA3, 0x82,
  30208. 0x76, 0x10, 0x72, 0xF4, 0xA6, 0x50, 0x5E, 0xA8,
  30209. 0xE7, 0x6C, 0x1E, 0x44, 0x6F, 0xEB, 0x66, 0x25,
  30210. 0xE3, 0x8D, 0xDB, 0xCD, 0x3C, 0xDA, 0x81, 0xE8,
  30211. 0x3B, 0xF7, 0x68, 0xF3, 0xE0, 0x1D, 0x9D, 0x26,
  30212. 0x3B, 0x36, 0x73, 0x03, 0xAE, 0x15, 0x6C, 0x0B,
  30213. 0x71, 0x83, 0x36, 0x4A, 0x1E, 0x79, 0x41, 0xA0,
  30214. 0x92, 0x98, 0xA3, 0xAD, 0xF7, 0xBD, 0x23, 0x1E,
  30215. 0x61, 0x14, 0xB9, 0xDC, 0xE7, 0x95, 0x2B, 0x11,
  30216. 0x3F, 0x78, 0x16, 0x31, 0x38, 0xB9, 0x26, 0x6F,
  30217. 0x84, 0x3F, 0x1E, 0xD9, 0x7D, 0x9C, 0x2B, 0x16,
  30218. 0x3A, 0x6E, 0x8B, 0xD4, 0xC1, 0xAB, 0x4E, 0x17,
  30219. 0x93, 0x67, 0xC5, 0xAC, 0x96, 0xCE, 0xCF, 0x50,
  30220. 0x50, 0xFE, 0x82, 0x1F, 0xDF, 0xA4, 0x4E, 0x9E,
  30221. 0x68, 0x0B, 0x61, 0xC6, 0x01, 0x89, 0x32, 0xDF,
  30222. 0x71, 0x78, 0x11, 0x45, 0x9A, 0xF2, 0x54, 0x2E,
  30223. 0x2C, 0xDE, 0x77, 0x17, 0x8C, 0x2E, 0x98, 0x80,
  30224. 0xF0, 0x11, 0xE4, 0x05, 0xEA, 0xFA, 0x59, 0xC8,
  30225. 0xCB, 0xBE, 0xD7, 0x6E, 0x5A, 0x19, 0x41, 0x10,
  30226. 0x4B, 0x1B, 0x9D, 0x3A, 0x60, 0x49, 0x1C, 0x95,
  30227. 0x47, 0x55, 0xE0, 0x2E, 0x89, 0x41, 0x03, 0xF1,
  30228. 0xF4, 0x97, 0x74, 0x75, 0xE9, 0xEA, 0x36, 0x60,
  30229. 0x9F, 0xD6, 0x7C, 0x9D, 0xE3, 0x18, 0xED, 0xA2,
  30230. 0x37, 0x0D, 0xCC, 0xDB, 0xB9, 0xCE, 0xF7, 0xAE,
  30231. 0x63, 0x60, 0x90, 0x5E, 0xC2, 0x20, 0x83, 0x8C,
  30232. 0x97, 0x69, 0x82, 0x34, 0x41, 0xCD, 0xD0, 0xDA,
  30233. 0x8E, 0xF0, 0xAB, 0xE5, 0xF2, 0xD1, 0xD7, 0x6E,
  30234. 0x2F, 0xE0, 0x8F, 0xEF, 0x53, 0xDE, 0x1D, 0x61,
  30235. 0x66, 0xAB, 0x1A, 0x92, 0xB1, 0xAC, 0x09, 0x3E,
  30236. 0x5A, 0xBF, 0x76, 0x58, 0xC4, 0xB5, 0x72, 0x87,
  30237. 0xF2, 0xD1, 0xFD, 0x7B, 0x82, 0xDE, 0xDA, 0xF8,
  30238. 0xD5, 0xA4, 0xFB, 0xAC, 0x4B, 0x35, 0xD5, 0x82,
  30239. 0x31, 0x69, 0x4E, 0x16, 0x24, 0x97, 0x57, 0x8A,
  30240. 0xBD, 0x7A, 0xA7, 0xC8, 0xFE, 0x7B, 0x35, 0x41,
  30241. 0xA7, 0xF1, 0x8E, 0x54, 0xE8, 0xB7, 0xF0, 0x87,
  30242. 0x64, 0xC5, 0xE6, 0x84, 0x49, 0xDF, 0x65, 0x59,
  30243. 0x01, 0x54, 0x98, 0x32, 0xD6, 0x28, 0xFA, 0x63,
  30244. 0xD2, 0xB2, 0xC5, 0xA1, 0x50, 0x93, 0x39, 0x94,
  30245. 0xA9, 0x86, 0x33, 0x17, 0xAD, 0x40, 0xD7, 0x78,
  30246. 0xD9, 0xD2, 0xC0, 0x5C, 0x78, 0x98, 0x85, 0x0B,
  30247. 0x90, 0x17, 0x32, 0x23, 0xC7, 0xA0, 0xAF, 0x89,
  30248. 0x0F, 0xD7, 0xE6, 0x62, 0x21, 0xB6, 0xF0, 0x63,
  30249. 0x18, 0xB2, 0xED, 0x5E, 0x19, 0x9C, 0xB4, 0x24,
  30250. 0x88, 0x5A, 0xB8, 0x41, 0xE7, 0xA4, 0x72, 0x6F,
  30251. 0xAB, 0xA2, 0xF9, 0xBB, 0x53, 0xBC, 0x32, 0x36,
  30252. 0x43, 0x4C, 0x35, 0xFB, 0xBE, 0x4B, 0x1A, 0x0F,
  30253. 0x93, 0xF5, 0x0C, 0x37, 0x89, 0x6C, 0x29, 0xF8,
  30254. 0xE3, 0x02, 0xAD, 0x31, 0xED, 0x33, 0x31, 0xD6,
  30255. 0x20, 0xE3, 0xB6, 0x29, 0x45, 0x51, 0x01, 0xA1,
  30256. 0xF1, 0xCC, 0x7B, 0xA5, 0xE4, 0x6E, 0x68, 0xED,
  30257. 0x4A, 0x8C, 0xCC, 0x87, 0xB4, 0xDC, 0x75, 0xBC,
  30258. 0x01, 0x62, 0xB6, 0x33, 0x0F, 0x83, 0x3F, 0xBA,
  30259. 0x25, 0x75, 0xDF, 0xAF, 0x5B, 0x5F, 0x28, 0xBC,
  30260. 0x54, 0xFF, 0x2B, 0xA8, 0x1E, 0x7A, 0x47, 0x31,
  30261. 0x3C, 0x15, 0x48, 0x2B, 0x60, 0x5E, 0x66, 0xBB,
  30262. 0x38, 0xC6, 0x19, 0x8F, 0x13, 0x92, 0x10, 0x40,
  30263. 0x80, 0xFB, 0xE7, 0x8B, 0x86, 0xB1, 0xBC, 0x9A,
  30264. 0x6F, 0xB8, 0x81, 0xF5, 0xC7, 0x82, 0x01, 0x47,
  30265. 0xE6, 0xBA, 0x14, 0xB8, 0x1A, 0xCC, 0xF2, 0x0C,
  30266. 0xAE, 0x96, 0x64, 0x10, 0x94, 0xC2, 0x16, 0x90,
  30267. 0x2E, 0xA5, 0xC1, 0x25, 0xF6, 0xC9, 0x35, 0xA1,
  30268. 0x50, 0xD7, 0xC9, 0xAC, 0xC5, 0xD9, 0xE2, 0xE5,
  30269. 0xD9, 0x0E, 0x38, 0xC0, 0x50, 0x3A, 0xA9, 0x42,
  30270. 0x60, 0x17, 0xC7, 0x6A, 0xAF, 0xCD, 0x52, 0x61,
  30271. 0xB5, 0x06, 0x27, 0x4E, 0xC1, 0x3A, 0x96, 0x79,
  30272. 0xFB, 0x09, 0x79, 0x60, 0x27, 0xA4, 0xBB, 0x75,
  30273. 0x9D, 0x92, 0x82, 0x79, 0xB9, 0x4D, 0x84, 0x1A,
  30274. 0x09, 0x73, 0x93, 0xBF, 0x7E, 0x5B, 0xD6, 0x9A,
  30275. 0x49, 0x6C, 0xC3, 0xDE, 0xCD, 0x2B, 0x0F, 0x07,
  30276. 0xF8, 0x33, 0x92, 0xAA, 0xDE, 0x33, 0xDC, 0x51,
  30277. 0xB2, 0xA8, 0x4F, 0x6A, 0x07, 0x63, 0x5D, 0xC0,
  30278. 0xEF, 0x57, 0xA9, 0xAD, 0x59, 0x59, 0xB6, 0xA5,
  30279. 0x0B, 0x7B, 0xA5, 0x09, 0xAD, 0x5B, 0x11, 0xFA,
  30280. 0xD2, 0x6B, 0x41, 0x9F, 0x9F, 0x1E, 0x3F, 0x9C,
  30281. 0x73, 0x29, 0xB5, 0xA9, 0x53, 0xD7, 0xCC, 0x87,
  30282. 0xB2, 0xDE, 0x21, 0x06, 0x11, 0xCF, 0x52, 0xA6,
  30283. 0x39, 0xEF, 0x2B, 0x39, 0x08, 0x01, 0x2C, 0xB8,
  30284. 0x8E, 0x1D, 0x6F, 0x57, 0x62, 0x50, 0x79, 0xCB,
  30285. 0x10, 0x3D, 0x6C, 0x98, 0x10, 0x1A, 0x11, 0xBD,
  30286. 0x22, 0x33, 0xB6, 0x56, 0x02, 0xCA, 0x30, 0x49,
  30287. 0xBD, 0x32, 0x05, 0x20, 0x41, 0x9F, 0x76, 0xB0,
  30288. 0x61, 0xE3, 0x59, 0x8D, 0xE3, 0x81, 0x52, 0xC8,
  30289. 0x87, 0x67, 0xD1, 0xA2, 0x4F, 0xBD, 0x02, 0xBB,
  30290. 0x10, 0xC3, 0x8E, 0xAC, 0xAE, 0x31, 0x7D, 0xE6,
  30291. 0xBB, 0x28, 0x7B, 0x4D, 0x2C, 0xAE, 0x5D, 0xA0,
  30292. 0x21, 0x49, 0x65, 0xD8, 0x77, 0x37, 0x78, 0x62,
  30293. 0x6E, 0x9B, 0x97, 0x28, 0x59, 0xD8, 0x48, 0x2B,
  30294. 0x8D, 0x05, 0x47, 0xE4, 0xF5, 0x6D, 0xFF, 0x87,
  30295. 0x68, 0x1D, 0x5B, 0xC5, 0x12, 0x0F, 0x61, 0x3F,
  30296. 0xBB, 0xD9, 0x1E, 0x1F, 0x14, 0xE6, 0xDE, 0xFE,
  30297. 0x67, 0x2E, 0x2A, 0x7E, 0xAB, 0xCB, 0xBB, 0x9B,
  30298. 0x11, 0x08, 0x2C, 0x5E, 0x70, 0x0A, 0xA0, 0xB1,
  30299. 0xF7, 0xC1, 0x78, 0x5F, 0xCE, 0xD1, 0x9A, 0x93,
  30300. 0xAF, 0xE7, 0xC5, 0x9F, 0xA2, 0x51, 0x9B, 0xCD,
  30301. 0xEB, 0x49, 0x4C, 0x3D, 0x13, 0xB2, 0x12, 0x5F,
  30302. 0x38, 0x53, 0x23, 0xB8, 0x16, 0xC6, 0x8F, 0x8F,
  30303. 0x56, 0x28, 0xC7, 0xC2, 0xAB, 0xFD, 0x02, 0x78,
  30304. 0xA3, 0x37, 0x07, 0x3D, 0xA7, 0x4D, 0x16, 0x09,
  30305. 0x96, 0x98, 0xC4, 0xB1, 0x14, 0xE8, 0xA8, 0xCE,
  30306. 0x34, 0x4E, 0x0A, 0x15, 0xD0, 0xFC, 0x7E, 0xD4,
  30307. 0x97, 0xB0, 0x01, 0xD5, 0x3D, 0x4C, 0x96, 0xDC,
  30308. 0x39, 0x54, 0xD3, 0xB4, 0xB9, 0x56, 0xCB, 0x9D,
  30309. 0x2A, 0x27, 0x2C, 0x51, 0xF1, 0x55, 0x9B, 0x22,
  30310. 0x90, 0x4B, 0x40, 0xCC, 0x85, 0x31, 0xE4, 0x0C,
  30311. 0xC4, 0x12, 0xC6, 0x8C, 0xB6, 0xEE, 0xA4, 0xA4,
  30312. 0x09, 0x0B, 0x38, 0xE2, 0x79, 0x73, 0x29, 0x98,
  30313. 0x54, 0x67, 0xE8, 0x18, 0xA5, 0x24, 0xD3, 0x22,
  30314. 0x8E, 0xAC, 0xAE, 0x78, 0x25, 0xD3, 0xDA, 0xD2,
  30315. 0xEA, 0xA4, 0x22, 0xFD, 0xC7, 0x7A, 0xED, 0x71,
  30316. 0xA2, 0x05, 0xDA, 0x78, 0x38, 0xD9, 0x45, 0xE7,
  30317. 0xFE, 0xC3, 0x7E, 0x4D, 0xCA, 0x67, 0xE5, 0x04,
  30318. 0xCE, 0x35, 0xE5, 0xB0, 0x45, 0xF5, 0x6F, 0x1E,
  30319. 0x8D, 0x75, 0x29, 0xEB, 0xD6, 0xF1, 0xAF, 0x7B,
  30320. 0x6E, 0x93, 0x9E, 0x2B, 0x7A, 0xB4, 0x02, 0x7D,
  30321. 0x37, 0xA5, 0x13, 0x5D, 0x17, 0x2D, 0xA1, 0xAF,
  30322. 0x9C, 0xA2, 0xF7, 0x28, 0xA6, 0xF3, 0x7D, 0xE6,
  30323. 0x0D, 0xD2, 0x3D, 0x97, 0xD1, 0x1E, 0x75, 0xAB,
  30324. 0x1F, 0xD5, 0x1F, 0x8E, 0x9A, 0x13, 0x97, 0xE5,
  30325. 0x82, 0x21, 0x59, 0xDB, 0x58, 0x38, 0x02, 0xB3,
  30326. 0x2E, 0xEB, 0xB4, 0x56, 0x7E, 0xCE, 0x37, 0x46,
  30327. 0xD1, 0xAE, 0x33, 0x31, 0x47, 0x85, 0x64, 0x3D,
  30328. 0xD2, 0xA0, 0x74, 0x1E, 0x7F, 0x1B, 0xF2, 0xD2,
  30329. 0x61, 0xF2, 0x21, 0x24, 0xE8, 0xDD, 0xD0, 0x8C,
  30330. 0x64, 0x0A, 0x48, 0xB5, 0x47, 0x17, 0x51, 0x7C,
  30331. 0x21, 0xCD, 0x32, 0x53, 0x28, 0xBC, 0x23, 0x9C,
  30332. 0xA0, 0x28, 0xB2, 0x63, 0x0D, 0x06, 0x3C, 0x8C,
  30333. 0xC2, 0x0B, 0xE9, 0xBD, 0xB4, 0x85, 0x02, 0xDA,
  30334. 0xDD, 0xE7, 0x3F, 0xFE, 0xD5, 0x96, 0x38, 0x16,
  30335. 0x53, 0x3E, 0x02, 0x0A, 0xED, 0x12, 0x08, 0x53,
  30336. 0x62, 0x55, 0xB1, 0xCC, 0xE9, 0x85, 0x43, 0x31,
  30337. 0x27, 0xFF, 0x4F, 0x04, 0xD5, 0xB1, 0xE2, 0xF2,
  30338. 0x10, 0x87, 0x04, 0xB8, 0xB9, 0x66, 0x58, 0x8C,
  30339. 0x01, 0x56, 0xAF, 0xC2, 0xAE, 0x19, 0x29, 0x86,
  30340. 0xFB, 0xEC, 0x44, 0x3B, 0xAE, 0xF6, 0xCB, 0x85,
  30341. 0xA6, 0xF2, 0x9C, 0x77, 0x92, 0x40, 0x5A, 0x24,
  30342. 0x11, 0x47, 0x10, 0xAE, 0x1C, 0x74, 0x64, 0x44,
  30343. 0xFD, 0xF5, 0xFB, 0x65, 0x9E, 0x5E, 0x34, 0x68,
  30344. 0x26, 0x20, 0x7B, 0x8C, 0x54, 0x46, 0x3A, 0x06,
  30345. 0x17, 0xCE, 0x17, 0xFF, 0x33, 0xE4, 0x0F, 0x93,
  30346. 0x1F, 0xE5, 0x76, 0x71, 0x5C, 0x93, 0x2E, 0xF2,
  30347. 0x9F, 0xD7, 0x6B, 0x04, 0xA6, 0x9B, 0x58, 0xE0,
  30348. 0x30, 0x3D, 0x8E, 0xF2, 0x56, 0x78, 0xC8, 0xB7,
  30349. 0x0A, 0xF1, 0x2E, 0x90, 0x45, 0x59, 0x1C, 0x04,
  30350. 0xE8, 0xB7, 0x71, 0x06, 0x94, 0x04, 0x15, 0x17,
  30351. 0x7E, 0x86, 0x85, 0x93, 0xA0, 0x9C, 0x7E, 0x14,
  30352. 0x61, 0x9A, 0x4B, 0x33, 0x2F, 0x9A, 0xDC, 0x3A,
  30353. 0x65, 0x8B, 0x86, 0x01, 0x7F, 0x32, 0x65, 0x6C,
  30354. 0x54, 0x29, 0xC1, 0x15, 0xE1, 0x10, 0x03, 0x7A,
  30355. 0x8C, 0xC7, 0xE5, 0x44, 0x67, 0x7D, 0x2D, 0xD2,
  30356. 0x39, 0xA5, 0x9D, 0x54, 0xD0, 0xF3, 0xC7, 0x46,
  30357. 0x0E, 0xC1, 0x52, 0x08, 0x34, 0x6B, 0xA5, 0x6D,
  30358. 0xF5, 0x08, 0x6C, 0x5D, 0xBC, 0xC4, 0x1E, 0x0C,
  30359. 0x95, 0xFC, 0xB6, 0x86, 0x1C, 0x2C, 0x0C, 0x32,
  30360. 0xAA, 0xF3, 0x45, 0x4E, 0xFE, 0xE2, 0xFF, 0xBA,
  30361. 0x21, 0x4B, 0x43, 0x0E, 0xF2, 0x48, 0xA5, 0x9B,
  30362. 0x32, 0x44, 0x4D, 0x8D, 0x0D, 0x3D, 0xB8, 0x7C,
  30363. 0x9D, 0x4B, 0x15, 0x36, 0xD1, 0x57, 0x72, 0x8E,
  30364. 0xE7, 0x58, 0x5E, 0xF5, 0x32, 0x77, 0x6A, 0x00,
  30365. 0x3A, 0x02, 0x3C, 0x0A, 0xB0, 0xE9, 0xFF, 0x55,
  30366. 0x71, 0x08, 0xC3, 0x90, 0x68, 0x4D, 0x56, 0x5A,
  30367. 0x66, 0x50, 0x63, 0x26, 0x6A, 0xE6, 0x67, 0x0E,
  30368. 0xD5, 0x3B, 0x0F, 0xAF, 0x8F, 0xF6, 0x78, 0x29,
  30369. 0xBB, 0x73, 0x78, 0x25, 0xB1, 0x53, 0xA9, 0x33,
  30370. 0x8C, 0xBE, 0x3D, 0xF1, 0xA4, 0x62, 0x84, 0x9B,
  30371. 0x93, 0xA8, 0x1F, 0x84, 0xED, 0x07, 0xBE, 0x6D,
  30372. 0x62, 0x40, 0x00, 0x32, 0x74, 0x73, 0x7F, 0x61,
  30373. 0x8D, 0xCB, 0x26, 0xE4, 0x82, 0x52, 0xCE, 0x42,
  30374. 0x04, 0xDD, 0x31, 0x39, 0xFF, 0x68, 0x76, 0xF4,
  30375. 0x3B, 0x30, 0x5D, 0x83, 0x56, 0x20, 0xFE, 0xDF,
  30376. 0x79, 0xAA, 0x67, 0x43, 0x3D, 0xC2, 0x52, 0x87,
  30377. 0x32, 0x0E, 0x99, 0x17, 0x96, 0x7B, 0x70, 0xB2,
  30378. 0xD8, 0x66, 0xD1, 0x7B, 0x69, 0x8B, 0xFF, 0xF2,
  30379. 0xB3, 0xAB, 0x95, 0x14, 0x94, 0x9E, 0x58, 0xB5,
  30380. 0x7C, 0x68, 0xA4, 0x54, 0x12, 0xC1, 0xFC, 0x42,
  30381. 0x1C, 0x76, 0x8B, 0xF5, 0xEE, 0x8A, 0x10, 0xC8,
  30382. 0xAE, 0xF5, 0x69, 0x26, 0xF5, 0x1E, 0xC6, 0x2C,
  30383. 0x11, 0x56, 0x9F, 0x31, 0xAA, 0x51, 0x78, 0x68,
  30384. 0xE5, 0xCA, 0xD8, 0x9E, 0x95, 0x80, 0x66, 0xEB,
  30385. 0x9E, 0xDD, 0x72, 0x71, 0xB3, 0x1C, 0xB4, 0xB1,
  30386. 0xD6, 0xCE, 0x21, 0x12, 0x25, 0xAE, 0xB5, 0xB5,
  30387. 0x7F, 0x74, 0x97, 0x19, 0xDA, 0x07, 0xEC, 0xBE,
  30388. 0xFE, 0x03, 0x88, 0x1D, 0xDE, 0x3D, 0x81, 0xE4,
  30389. 0x13, 0x5F, 0x2D, 0xC8, 0x1A, 0xF7, 0x79, 0x77,
  30390. 0x6C, 0x1B, 0x80, 0x57, 0x16, 0x2A, 0x6C, 0x98,
  30391. 0x2F, 0xBB, 0x4D, 0xA6, 0xA9, 0xAD, 0x28, 0x4A,
  30392. 0xB1, 0x0C, 0x70, 0x02, 0x20, 0x44, 0xF4, 0x6D,
  30393. 0x40, 0x0B, 0xF6, 0xAD, 0x71, 0x82, 0xD1, 0x97,
  30394. 0x78, 0x99, 0x83, 0xBE, 0x99, 0x22, 0x79, 0x79,
  30395. 0xA1, 0x33, 0x4B, 0xA1, 0x49, 0xD8, 0x69, 0xBA,
  30396. 0x1C, 0x40, 0x88, 0x12, 0x34, 0x35, 0xBF, 0x97,
  30397. 0x85, 0x41, 0x35, 0x6D, 0xAF, 0x17, 0x1F, 0x33,
  30398. 0xAD, 0xB1, 0xC9, 0x79, 0x07, 0xA0, 0xFB, 0x58,
  30399. 0x45, 0x07, 0x4A, 0x85, 0xD2, 0x6F, 0x54, 0x61,
  30400. 0x35, 0xAE, 0xD0, 0xF9, 0x1B, 0xE4, 0x53, 0x9C,
  30401. 0x12, 0xBF, 0x94, 0x11, 0xE4, 0xB5, 0x56, 0xF6,
  30402. 0x87, 0xD0, 0x69, 0xDB, 0x6B, 0x21, 0xFE, 0x2B,
  30403. 0x7F, 0x32, 0x18, 0x87, 0x44, 0x8C, 0xEA, 0x55,
  30404. 0xDB, 0x19, 0xFB, 0xB8, 0xB0, 0x48, 0x2A, 0x55,
  30405. 0xAE, 0xC1, 0x67, 0x38, 0xD7, 0x4C, 0xD2, 0x65,
  30406. 0x09, 0x38, 0x36, 0xBE, 0x99, 0xD4, 0xFB, 0x53,
  30407. 0xE9, 0xB0, 0x14, 0xB0, 0x37, 0xCD, 0xBF, 0xE9
  30408. #endif
  30409. };
  30410. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  30411. static const unsigned char dilithium_public_der[] = {
  30412. #ifndef WOLFSSL_NO_ML_DSA_44
  30413. 0x30, 0x82, 0x05, 0x34, 0x30, 0x0d, 0x06, 0x0b,
  30414. 0x2b, 0x06, 0x01, 0x04, 0x01, 0x02, 0x82, 0x0b,
  30415. 0x0c, 0x04, 0x04, 0x03, 0x82, 0x05, 0x21, 0x00,
  30416. 0x0a, 0xf7, 0xc8, 0xa4, 0x96, 0x01, 0xa7, 0xb2,
  30417. 0x2e, 0x4d, 0xc9, 0xd9, 0x1c, 0xa1, 0x86, 0x09,
  30418. 0xce, 0x14, 0x6f, 0xe8, 0x33, 0x3c, 0x7b, 0xdb,
  30419. 0x19, 0x9c, 0x56, 0x39, 0x6a, 0x6c, 0x5d, 0x1f,
  30420. 0xe4, 0x26, 0xcb, 0x16, 0x91, 0x4d, 0xeb, 0x5a,
  30421. 0x36, 0x22, 0xee, 0xda, 0xdf, 0x46, 0x3e, 0xa1,
  30422. 0x4f, 0x9a, 0x30, 0xb5, 0x3f, 0x60, 0xf7, 0x75,
  30423. 0x47, 0xdc, 0x55, 0xf1, 0xbe, 0xbc, 0x87, 0x6c,
  30424. 0x50, 0x7c, 0x21, 0x55, 0x35, 0xad, 0xa7, 0xf9,
  30425. 0x1c, 0xf8, 0xa1, 0x92, 0x79, 0x10, 0x52, 0x7a,
  30426. 0xc3, 0xba, 0xd3, 0x9d, 0xc6, 0x9b, 0xf4, 0xcb,
  30427. 0x1b, 0xa2, 0xde, 0x83, 0x86, 0xa6, 0x35, 0xea,
  30428. 0xf2, 0x8c, 0xdc, 0xba, 0x3e, 0xef, 0x9c, 0xf5,
  30429. 0x8e, 0xc3, 0xb0, 0xc0, 0x5b, 0xcc, 0x35, 0x6a,
  30430. 0x81, 0xe5, 0x17, 0xb3, 0x9a, 0x57, 0xa6, 0x4a,
  30431. 0x87, 0xb1, 0xa7, 0xf5, 0xa2, 0x96, 0x40, 0x8b,
  30432. 0xc1, 0x62, 0xb2, 0xd9, 0x76, 0xe8, 0x51, 0x33,
  30433. 0x44, 0x3d, 0xeb, 0x14, 0x86, 0x88, 0x2c, 0xc1,
  30434. 0x47, 0xba, 0x2b, 0x85, 0x3b, 0x72, 0xcb, 0x9f,
  30435. 0x40, 0xba, 0x19, 0x58, 0xa4, 0x34, 0x0a, 0xd2,
  30436. 0x8c, 0x97, 0xbd, 0x3d, 0x09, 0xb0, 0x4a, 0xeb,
  30437. 0xaa, 0xee, 0x58, 0x1e, 0xc1, 0x19, 0x26, 0x70,
  30438. 0x15, 0xa5, 0x17, 0x7e, 0xd0, 0xa1, 0x08, 0xf9,
  30439. 0x6d, 0xcf, 0x20, 0x62, 0x95, 0x8e, 0x61, 0xf4,
  30440. 0x29, 0x96, 0x6f, 0x38, 0x1c, 0x67, 0xd5, 0xa6,
  30441. 0x4c, 0xf5, 0x1f, 0xda, 0x12, 0x22, 0x24, 0x6b,
  30442. 0x0d, 0xb7, 0x6a, 0xe5, 0xaf, 0x6c, 0x89, 0x52,
  30443. 0xc2, 0x85, 0x85, 0x5f, 0x16, 0x33, 0x0c, 0xc6,
  30444. 0x7a, 0xe0, 0xa8, 0xed, 0x13, 0x58, 0xf3, 0xa0,
  30445. 0x80, 0x42, 0x3c, 0xe3, 0x57, 0xd1, 0xe2, 0x66,
  30446. 0xc4, 0xe0, 0x3d, 0x49, 0x32, 0x21, 0xd9, 0xa1,
  30447. 0x3c, 0x93, 0x0a, 0xf7, 0x5f, 0x34, 0x65, 0xa4,
  30448. 0x30, 0xf9, 0xe7, 0x8a, 0x96, 0x04, 0xdb, 0xc5,
  30449. 0x16, 0x15, 0x10, 0x74, 0x4f, 0xc9, 0x6b, 0x4b,
  30450. 0x66, 0x29, 0xb0, 0xd1, 0x3b, 0xdd, 0x41, 0x0a,
  30451. 0xfe, 0xdf, 0x5f, 0x72, 0x91, 0xbc, 0x99, 0x2f,
  30452. 0x8d, 0x72, 0x3a, 0x4a, 0xde, 0x11, 0x3a, 0x20,
  30453. 0xb2, 0x56, 0xb5, 0x73, 0x89, 0xb4, 0x63, 0x37,
  30454. 0x86, 0xbd, 0x99, 0x8b, 0x03, 0x56, 0x50, 0x21,
  30455. 0x11, 0x78, 0x8c, 0xd5, 0xc1, 0x92, 0x33, 0x72,
  30456. 0x6e, 0x8d, 0x88, 0x2d, 0x10, 0x8f, 0x31, 0xd3,
  30457. 0x23, 0xe5, 0xaa, 0x1f, 0xe1, 0x37, 0xec, 0x34,
  30458. 0x42, 0x30, 0x75, 0xff, 0xb2, 0x1a, 0x8e, 0x29,
  30459. 0x03, 0x4c, 0xfd, 0xdf, 0x53, 0xf2, 0x0b, 0x2d,
  30460. 0xf9, 0x1c, 0x9e, 0xb6, 0x5a, 0x6c, 0x5e, 0x88,
  30461. 0x48, 0x29, 0x89, 0x42, 0xfc, 0x97, 0xfb, 0x27,
  30462. 0x1c, 0x99, 0x2a, 0xbf, 0x7f, 0x04, 0xb2, 0xcd,
  30463. 0xc9, 0x3a, 0x39, 0xfe, 0x4f, 0x47, 0x92, 0x0b,
  30464. 0x85, 0xfc, 0x92, 0x57, 0xc5, 0x0b, 0x23, 0x1f,
  30465. 0x0b, 0x72, 0xb4, 0xde, 0xfe, 0xbe, 0xb7, 0x39,
  30466. 0xb3, 0xd7, 0x48, 0x03, 0xed, 0x76, 0xac, 0x63,
  30467. 0xf7, 0x2a, 0x58, 0xef, 0xdb, 0x63, 0x5a, 0x56,
  30468. 0x68, 0xcc, 0xb2, 0x8b, 0x22, 0xac, 0xdf, 0xc4,
  30469. 0xad, 0x6f, 0xad, 0x24, 0xfd, 0x30, 0xfb, 0xed,
  30470. 0x6e, 0xde, 0x65, 0x2b, 0xb4, 0x57, 0x35, 0x49,
  30471. 0xc1, 0xc9, 0x82, 0xf4, 0x72, 0x69, 0xef, 0x34,
  30472. 0xc0, 0x37, 0x8b, 0x8b, 0xd3, 0xd3, 0x25, 0xcc,
  30473. 0xe5, 0xf5, 0xf6, 0x9c, 0xa3, 0xe7, 0x88, 0xd7,
  30474. 0x55, 0x73, 0x31, 0x4c, 0xb1, 0x7b, 0x64, 0xb3,
  30475. 0x38, 0xde, 0x47, 0x9a, 0xfc, 0xf1, 0xfa, 0xf8,
  30476. 0x6e, 0xc5, 0x95, 0xb9, 0xaf, 0x6a, 0x7a, 0x94,
  30477. 0x80, 0x0d, 0x29, 0x62, 0x99, 0x0a, 0x34, 0xa2,
  30478. 0x8f, 0xa1, 0x5e, 0x98, 0x7c, 0x4e, 0x18, 0xcd,
  30479. 0x63, 0x68, 0x0e, 0xfa, 0x6f, 0x49, 0x01, 0x02,
  30480. 0xcd, 0xf1, 0xc1, 0x09, 0x57, 0xa3, 0x03, 0xec,
  30481. 0x94, 0x36, 0xab, 0xc6, 0x1c, 0xc0, 0x98, 0x22,
  30482. 0x15, 0x5b, 0x5b, 0x61, 0x3c, 0xc2, 0x5b, 0x6f,
  30483. 0x1c, 0x82, 0x41, 0x39, 0x87, 0xde, 0x92, 0xa9,
  30484. 0xe4, 0x12, 0x74, 0x3b, 0x31, 0x36, 0xac, 0x92,
  30485. 0xb0, 0x23, 0x26, 0xfa, 0xd8, 0xa3, 0xe8, 0x84,
  30486. 0xfc, 0x52, 0xc5, 0x7b, 0xd1, 0x4b, 0xe2, 0x1a,
  30487. 0x33, 0xdd, 0x3c, 0xdf, 0x27, 0x50, 0x6f, 0x12,
  30488. 0xd3, 0x17, 0x66, 0xd7, 0x54, 0x33, 0x30, 0x2b,
  30489. 0xe8, 0xd1, 0x1f, 0x2d, 0xf3, 0x37, 0x81, 0xa0,
  30490. 0x3c, 0x21, 0x8c, 0xea, 0x95, 0xa5, 0x5b, 0x3a,
  30491. 0x24, 0xed, 0xf7, 0x67, 0x7b, 0x72, 0x3a, 0xda,
  30492. 0x31, 0xbd, 0xa7, 0x63, 0xa6, 0x6f, 0xf9, 0xdf,
  30493. 0x06, 0x36, 0xb4, 0xe2, 0x35, 0x4b, 0xa5, 0x8e,
  30494. 0x29, 0x8e, 0x6c, 0x02, 0xc5, 0x06, 0x9b, 0x98,
  30495. 0x6e, 0x5e, 0x00, 0x6a, 0x42, 0x09, 0x4b, 0xc3,
  30496. 0x09, 0x37, 0x67, 0x19, 0x58, 0x6d, 0x40, 0x50,
  30497. 0xb0, 0x62, 0x5b, 0xd6, 0x63, 0x7f, 0xed, 0xb0,
  30498. 0x97, 0x80, 0x9e, 0x91, 0x3f, 0x82, 0xfd, 0x83,
  30499. 0x36, 0xce, 0x06, 0xc4, 0xdc, 0xa4, 0x1e, 0x70,
  30500. 0xd4, 0x94, 0xfc, 0x6e, 0x46, 0xa3, 0xc8, 0xed,
  30501. 0x34, 0x0a, 0xb1, 0x9a, 0x66, 0x5d, 0xc0, 0xce,
  30502. 0x73, 0xd3, 0x65, 0xcb, 0xfb, 0x79, 0xdd, 0xf6,
  30503. 0x19, 0xf6, 0xd8, 0xa9, 0xe6, 0x34, 0x15, 0x86,
  30504. 0x7a, 0x30, 0x79, 0xde, 0x2b, 0x06, 0xa4, 0xc0,
  30505. 0xc8, 0xa2, 0xc1, 0x41, 0xb3, 0x4c, 0xf6, 0xdb,
  30506. 0x16, 0xcd, 0xd2, 0x8b, 0xf1, 0x18, 0x5a, 0xc8,
  30507. 0x3e, 0xd9, 0x54, 0x40, 0xd4, 0xce, 0x88, 0xbb,
  30508. 0x66, 0xf1, 0x74, 0x20, 0xa2, 0x3c, 0x31, 0x09,
  30509. 0xba, 0xac, 0x61, 0x15, 0x9f, 0x73, 0x5f, 0xa7,
  30510. 0xe5, 0x0d, 0xb3, 0xab, 0xa2, 0x72, 0x25, 0xc9,
  30511. 0x87, 0x9b, 0x18, 0xdb, 0xff, 0xfb, 0x39, 0x84,
  30512. 0x8d, 0xf8, 0x97, 0x47, 0xab, 0xc4, 0xfb, 0xc2,
  30513. 0xd8, 0xe8, 0xce, 0x6e, 0x65, 0x76, 0x88, 0x4a,
  30514. 0x22, 0x2f, 0xdd, 0x43, 0xa7, 0xc4, 0x8d, 0x32,
  30515. 0x12, 0x75, 0x0b, 0x72, 0xd6, 0xb7, 0x43, 0x84,
  30516. 0xc8, 0x59, 0xa8, 0xb7, 0x8b, 0x84, 0x33, 0x92,
  30517. 0x8f, 0x94, 0xe8, 0xd0, 0xaf, 0x11, 0x35, 0xde,
  30518. 0xb7, 0x63, 0xb8, 0x91, 0x4c, 0x96, 0x4e, 0x9c,
  30519. 0x62, 0x28, 0xa2, 0xbc, 0x0b, 0x90, 0xae, 0x94,
  30520. 0x90, 0xe9, 0x32, 0xeb, 0xe3, 0x77, 0x60, 0x5f,
  30521. 0x87, 0x48, 0x4b, 0xb0, 0x78, 0x0e, 0xe2, 0x85,
  30522. 0x47, 0x06, 0xa4, 0xc9, 0x26, 0xac, 0x8f, 0xe7,
  30523. 0xc2, 0xc7, 0xce, 0xf5, 0xd1, 0x20, 0xa8, 0x56,
  30524. 0xe1, 0x4f, 0x50, 0x90, 0xb3, 0xc1, 0x03, 0x57,
  30525. 0xd3, 0x62, 0x0e, 0x2a, 0xe8, 0x86, 0xf4, 0x94,
  30526. 0x0e, 0xa5, 0x8b, 0x4e, 0x73, 0xa2, 0x76, 0xac,
  30527. 0x00, 0x29, 0xe5, 0x80, 0x26, 0x02, 0x13, 0xd1,
  30528. 0xb2, 0x68, 0x72, 0x23, 0x38, 0x55, 0xfc, 0x4d,
  30529. 0x05, 0x60, 0x49, 0x7b, 0xfb, 0xaa, 0x17, 0x8f,
  30530. 0x26, 0x0a, 0x08, 0x33, 0x8d, 0x7f, 0x4e, 0xe5,
  30531. 0x6e, 0xf8, 0x84, 0x9b, 0x9f, 0xcb, 0xa2, 0x2b,
  30532. 0xfb, 0xaf, 0xad, 0x21, 0xe2, 0x4f, 0x6f, 0x55,
  30533. 0xc1, 0x78, 0x46, 0xe3, 0xb5, 0x63, 0x06, 0x9b,
  30534. 0x93, 0x7d, 0xac, 0xd4, 0xe0, 0x64, 0x01, 0x8d,
  30535. 0xac, 0x30, 0x8b, 0x8b, 0x55, 0xb7, 0x8a, 0x16,
  30536. 0x3f, 0xc9, 0x82, 0x7f, 0xb5, 0x3b, 0x0d, 0xc0,
  30537. 0x46, 0x89, 0x5c, 0x6c, 0x45, 0x21, 0x78, 0xda,
  30538. 0x84, 0x1f, 0xc8, 0xcf, 0xf1, 0x1e, 0x79, 0x71,
  30539. 0x3b, 0xc8, 0xe2, 0x8b, 0x41, 0xfe, 0xaf, 0x2f,
  30540. 0x3b, 0x23, 0x13, 0xc5, 0x46, 0x87, 0xc6, 0x24,
  30541. 0x37, 0x21, 0x68, 0x8a, 0x3e, 0x45, 0x61, 0xf4,
  30542. 0xad, 0xf5, 0x1c, 0x23, 0x45, 0xa3, 0x42, 0xf2,
  30543. 0xa9, 0xac, 0x94, 0x50, 0xc9, 0x3d, 0x5e, 0x70,
  30544. 0x33, 0x2b, 0x78, 0xd1, 0x5c, 0x13, 0x35, 0xe6,
  30545. 0x13, 0x80, 0x5e, 0x55, 0xa7, 0xcc, 0x67, 0xb0,
  30546. 0x6c, 0xfe, 0xa2, 0x24, 0x02, 0x6d, 0xb3, 0xcb,
  30547. 0x9e, 0x94, 0xb3, 0xc6, 0x01, 0xf3, 0x01, 0x3a,
  30548. 0xe4, 0xa7, 0xa3, 0xdf, 0x56, 0x4c, 0x30, 0xce,
  30549. 0xb1, 0xd5, 0x1b, 0x68, 0x9b, 0x75, 0xae, 0xf4,
  30550. 0xb9, 0x2a, 0xe5, 0x8b, 0x7b, 0xe5, 0x99, 0x46,
  30551. 0x5f, 0x29, 0xf6, 0x82, 0xd0, 0x42, 0xb1, 0x45,
  30552. 0x09, 0x16, 0x5b, 0x32, 0x11, 0xca, 0x48, 0xea,
  30553. 0x51, 0x12, 0x0a, 0x9f, 0x6e, 0x3f, 0x74, 0xe6,
  30554. 0xe0, 0xfe, 0xf8, 0xa5, 0xc0, 0xfd, 0x15, 0x6e,
  30555. 0x2b, 0x4a, 0xd5, 0x76, 0xa8, 0x3d, 0xe3, 0x0d,
  30556. 0xfe, 0x44, 0x11, 0x5e, 0x7a, 0xde, 0x12, 0x29,
  30557. 0x5a, 0x5a, 0x25, 0xc0, 0x8e, 0x98, 0xd1, 0x11,
  30558. 0xc8, 0x00, 0x65, 0xb2, 0xf4, 0xd7, 0x56, 0x32,
  30559. 0x46, 0x2b, 0x4f, 0x7e, 0xc3, 0x4e, 0xf1, 0x17,
  30560. 0xff, 0x03, 0x32, 0xae, 0xe3, 0xbe, 0x0b, 0xab,
  30561. 0xfb, 0x43, 0x0f, 0x6d, 0xa5, 0xc6, 0x44, 0xba,
  30562. 0xc9, 0xe3, 0x3d, 0x40, 0xe7, 0x6c, 0xe8, 0x21,
  30563. 0xb2, 0x46, 0x7b, 0x3b, 0x3d, 0xde, 0x80, 0xc8,
  30564. 0xea, 0xf4, 0x6b, 0xf3, 0x53, 0xca, 0x51, 0x84,
  30565. 0xcf, 0xad, 0x7e, 0xce, 0xce, 0xc2, 0x65, 0xfc,
  30566. 0x03, 0x8c, 0xcb, 0xfa, 0xcb, 0x37, 0x89, 0x82,
  30567. 0x59, 0x5e, 0x36, 0x52, 0xe4, 0xbc, 0x8d, 0x47,
  30568. 0x7c, 0xb8, 0x3f, 0x63, 0x59, 0xdc, 0xd3, 0x74,
  30569. 0x11, 0x33, 0xb4, 0x69, 0x74, 0x40, 0x0d, 0x42,
  30570. 0x63, 0x1d, 0xe6, 0x5c, 0x1b, 0xca, 0x41, 0xff,
  30571. 0x23, 0x4e, 0xe8, 0x3d, 0x14, 0xa8, 0x17, 0x18,
  30572. 0xd0, 0x78, 0x08, 0x87, 0x7d, 0x5e, 0xdc, 0x3a,
  30573. 0x07, 0xba, 0x12, 0x8e, 0x8e, 0x56, 0x0a, 0xcb,
  30574. 0x37, 0xf6, 0x54, 0xeb, 0x55, 0x16, 0x8f, 0x06,
  30575. 0x15, 0x28, 0x6b, 0xfb, 0xed, 0x38, 0x9e, 0x9b,
  30576. 0x98, 0x5b, 0xdc, 0x67, 0x33, 0x0e, 0x02, 0x36,
  30577. 0x1b, 0x7a, 0x9a, 0x43, 0xcd, 0xf2, 0x65, 0xef,
  30578. 0x37, 0x19, 0x24, 0x6f, 0x4b, 0xb9, 0x4d, 0x3e,
  30579. 0x0b, 0x47, 0xd1, 0x67, 0x50, 0x6a, 0x7f, 0x07
  30580. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  30581. 0x30, 0x82, 0x07, 0xb4, 0x30, 0x0d, 0x06, 0x0b,
  30582. 0x2b, 0x06, 0x01, 0x04, 0x01, 0x02, 0x82, 0x0b,
  30583. 0x0c, 0x06, 0x05, 0x03, 0x82, 0x07, 0xa1, 0x00,
  30584. 0xff, 0x89, 0xee, 0xad, 0x20, 0x8f, 0x61, 0xa4,
  30585. 0x07, 0x1c, 0x54, 0x98, 0x8c, 0xf4, 0x2e, 0xd9,
  30586. 0xe6, 0x0f, 0xcb, 0x0e, 0xab, 0xa1, 0x37, 0x4d,
  30587. 0xc0, 0x48, 0x24, 0x78, 0xd6, 0x2d, 0x9b, 0x6f,
  30588. 0x0f, 0x17, 0x08, 0x71, 0xc3, 0xd1, 0xc8, 0x7a,
  30589. 0xe7, 0x32, 0xcb, 0xcd, 0xd6, 0xb5, 0x90, 0x08,
  30590. 0xe1, 0xda, 0xaa, 0x89, 0x3e, 0x4a, 0x62, 0x98,
  30591. 0x3d, 0xc6, 0x71, 0x30, 0xb4, 0x63, 0xa5, 0x3b,
  30592. 0xb3, 0x69, 0x75, 0x10, 0xaf, 0x5e, 0x72, 0x78,
  30593. 0xa2, 0xef, 0x63, 0x63, 0x21, 0xe7, 0xf4, 0xa7,
  30594. 0x9c, 0x50, 0x74, 0x14, 0x3e, 0xdd, 0x73, 0x9e,
  30595. 0x97, 0x65, 0xdd, 0xdf, 0x3c, 0x40, 0x4d, 0x03,
  30596. 0x49, 0xe4, 0xbf, 0x65, 0xe7, 0x44, 0x8f, 0x59,
  30597. 0x00, 0xe2, 0x98, 0xb5, 0x66, 0xa3, 0x3b, 0x11,
  30598. 0x9f, 0xc7, 0xc2, 0x16, 0x61, 0xf0, 0x1e, 0x89,
  30599. 0xc8, 0x96, 0x8d, 0x18, 0xac, 0x86, 0xa0, 0xe2,
  30600. 0xd9, 0x8c, 0xef, 0x53, 0x6d, 0x4e, 0x74, 0xc9,
  30601. 0x66, 0x28, 0x16, 0xf3, 0x62, 0xc4, 0x6f, 0x2b,
  30602. 0x6e, 0x36, 0x03, 0xad, 0xc5, 0xe4, 0x8f, 0x0b,
  30603. 0x90, 0x8c, 0x8f, 0xff, 0x5d, 0xdf, 0x7a, 0xe6,
  30604. 0xaf, 0x9a, 0x43, 0xbc, 0xd4, 0x73, 0x22, 0xdc,
  30605. 0x5f, 0x08, 0xa1, 0x17, 0x97, 0x89, 0x79, 0xf5,
  30606. 0xdc, 0xed, 0x4f, 0x85, 0x8e, 0x0c, 0x23, 0x35,
  30607. 0x3c, 0x34, 0x19, 0x65, 0xf5, 0xd6, 0xc9, 0x2d,
  30608. 0x7a, 0x2e, 0x67, 0xd5, 0xf1, 0x82, 0x97, 0xaa,
  30609. 0x05, 0x26, 0x84, 0x25, 0x47, 0x58, 0x2c, 0xe6,
  30610. 0x59, 0xc7, 0x98, 0x7a, 0xdb, 0x40, 0x45, 0x1c,
  30611. 0x71, 0x55, 0x2e, 0xea, 0x3f, 0x6e, 0x7c, 0x82,
  30612. 0x52, 0x6a, 0x19, 0x3a, 0xd3, 0xa1, 0x3c, 0xce,
  30613. 0x00, 0x06, 0xec, 0xed, 0x97, 0xce, 0xd8, 0xdf,
  30614. 0xde, 0xa3, 0xed, 0xe7, 0x81, 0x62, 0x02, 0x9c,
  30615. 0x1b, 0x51, 0xa1, 0xf4, 0x9d, 0x1b, 0x28, 0x76,
  30616. 0x93, 0x96, 0x20, 0x55, 0x60, 0x1f, 0xaf, 0x52,
  30617. 0xc3, 0xce, 0xb9, 0x12, 0x66, 0xf5, 0x64, 0x22,
  30618. 0x87, 0x86, 0x29, 0x80, 0x8f, 0x18, 0x33, 0xba,
  30619. 0x48, 0x71, 0x1d, 0x00, 0xfe, 0xa5, 0xfc, 0xc6,
  30620. 0x87, 0xbe, 0x44, 0x3c, 0xc9, 0x49, 0xfb, 0x68,
  30621. 0x3c, 0xdf, 0xca, 0xef, 0xa7, 0xdc, 0x67, 0xb8,
  30622. 0x28, 0xd6, 0xad, 0x18, 0xaf, 0xad, 0x1f, 0x4c,
  30623. 0x85, 0xa3, 0x64, 0xac, 0x3f, 0xa9, 0x39, 0x28,
  30624. 0xef, 0x8a, 0x45, 0x7e, 0xb0, 0xf4, 0x89, 0x72,
  30625. 0xf7, 0xb1, 0xef, 0x9d, 0x1c, 0x3c, 0x93, 0xcb,
  30626. 0xa0, 0xfb, 0x2a, 0x90, 0xe2, 0x1d, 0x49, 0x8e,
  30627. 0x36, 0xb8, 0x07, 0xf4, 0xb3, 0x09, 0xf0, 0x6f,
  30628. 0x3c, 0xd9, 0x37, 0x19, 0x57, 0xd4, 0x1e, 0x2a,
  30629. 0xa2, 0xa7, 0x2e, 0xc1, 0xcd, 0x8d, 0x48, 0x47,
  30630. 0xb5, 0x8a, 0x12, 0x93, 0x34, 0xb8, 0xec, 0x32,
  30631. 0x07, 0x49, 0xb6, 0x8d, 0x73, 0xd4, 0x2c, 0x6a,
  30632. 0xa0, 0x33, 0x29, 0x21, 0x5d, 0x37, 0xa9, 0x39,
  30633. 0x40, 0xbe, 0x71, 0x29, 0xbe, 0xd1, 0x4b, 0xbc,
  30634. 0x9a, 0x17, 0x93, 0x52, 0xb8, 0x81, 0xee, 0xc5,
  30635. 0xff, 0x25, 0x78, 0x2f, 0x52, 0x0a, 0x8f, 0xb2,
  30636. 0xef, 0xf3, 0x1d, 0x68, 0x56, 0x31, 0x29, 0x84,
  30637. 0x55, 0x47, 0x32, 0x34, 0x0f, 0x60, 0x07, 0xd6,
  30638. 0x2b, 0xb9, 0x29, 0xaf, 0x0f, 0xcd, 0x1c, 0xc0,
  30639. 0x77, 0x4c, 0xc6, 0x31, 0xdb, 0xf4, 0x17, 0xbe,
  30640. 0x3d, 0xf8, 0x8c, 0xf1, 0x02, 0x7c, 0x6b, 0xd4,
  30641. 0xaf, 0x03, 0xb2, 0xf4, 0x78, 0x8d, 0xd3, 0x4e,
  30642. 0x5c, 0x04, 0xb9, 0x01, 0xe3, 0x73, 0xb4, 0x67,
  30643. 0xe9, 0xa8, 0x77, 0x6f, 0x87, 0x2b, 0xe2, 0x00,
  30644. 0x98, 0x5f, 0x02, 0x43, 0x85, 0x03, 0x4c, 0x71,
  30645. 0xd2, 0xe7, 0x61, 0x03, 0x22, 0x9e, 0xe5, 0xc2,
  30646. 0xa7, 0x66, 0x42, 0x7c, 0x9f, 0xf4, 0xb8, 0x6b,
  30647. 0x2d, 0xe4, 0xaa, 0x51, 0xda, 0x08, 0x73, 0x75,
  30648. 0x26, 0x45, 0xdc, 0xa6, 0x20, 0xd7, 0xcb, 0x00,
  30649. 0xfc, 0xe4, 0xdb, 0x28, 0x92, 0xf8, 0xb0, 0xc7,
  30650. 0xf0, 0x4b, 0x6d, 0xe8, 0xc1, 0x84, 0x38, 0xed,
  30651. 0x1a, 0xd4, 0x66, 0x69, 0xc4, 0x96, 0x40, 0xc4,
  30652. 0x7d, 0xfa, 0x58, 0x70, 0x7e, 0x70, 0x40, 0xba,
  30653. 0xfc, 0x95, 0xb6, 0x4c, 0x7c, 0x58, 0xbc, 0xb3,
  30654. 0x59, 0x08, 0x14, 0x03, 0x35, 0xf3, 0xf1, 0xaa,
  30655. 0xd5, 0xa2, 0x57, 0x70, 0xb6, 0x20, 0x75, 0x0a,
  30656. 0x58, 0x66, 0x74, 0xf7, 0x1c, 0xfd, 0x99, 0x7c,
  30657. 0x20, 0xda, 0xe7, 0x76, 0xcb, 0xf4, 0xa3, 0x9b,
  30658. 0xbc, 0x8f, 0x74, 0xef, 0xe2, 0x46, 0x5a, 0x72,
  30659. 0x33, 0x06, 0x32, 0x1e, 0xbd, 0x4e, 0x4c, 0xf6,
  30660. 0x16, 0x43, 0xa5, 0xa5, 0xa5, 0x6c, 0x76, 0x33,
  30661. 0x35, 0x63, 0xdc, 0xe4, 0xec, 0x7f, 0x8a, 0xfa,
  30662. 0xc3, 0x53, 0x69, 0x28, 0xf7, 0xd6, 0x97, 0xb9,
  30663. 0x3a, 0xf4, 0x15, 0x90, 0x50, 0xd3, 0xdf, 0xf5,
  30664. 0xd3, 0xcf, 0x15, 0x76, 0xe3, 0x3d, 0x24, 0x14,
  30665. 0xfd, 0xd3, 0x01, 0x25, 0x82, 0xb4, 0xe3, 0xd8,
  30666. 0x68, 0x89, 0x86, 0xa8, 0x26, 0x02, 0x5f, 0xc6,
  30667. 0xf4, 0x99, 0x3b, 0x97, 0xa8, 0x65, 0xed, 0x18,
  30668. 0xbb, 0x3c, 0x43, 0x4a, 0x6e, 0xaa, 0xbc, 0x83,
  30669. 0x85, 0x19, 0x9f, 0x9b, 0xb8, 0xa4, 0xa3, 0xb2,
  30670. 0xb7, 0x56, 0x07, 0x6c, 0xbf, 0x7d, 0xff, 0x5d,
  30671. 0xb5, 0x1e, 0x83, 0xc8, 0x74, 0x70, 0x98, 0x17,
  30672. 0x40, 0xe0, 0x2d, 0xad, 0x31, 0x00, 0x8e, 0x42,
  30673. 0xd5, 0xb2, 0x25, 0xaa, 0x82, 0xaf, 0x33, 0xd8,
  30674. 0x5b, 0xe2, 0x07, 0xed, 0xda, 0x84, 0xe9, 0xa2,
  30675. 0xff, 0xbb, 0xa5, 0x47, 0x95, 0x6e, 0xa1, 0x8d,
  30676. 0x59, 0x52, 0xeb, 0xf3, 0x3c, 0x18, 0x29, 0x92,
  30677. 0x72, 0x27, 0x18, 0xfc, 0x95, 0xb9, 0xde, 0x46,
  30678. 0xda, 0xcc, 0x4c, 0x31, 0x1d, 0x78, 0x86, 0xd2,
  30679. 0x8c, 0x38, 0x9c, 0x32, 0xab, 0xf7, 0xca, 0x73,
  30680. 0x85, 0xa5, 0xf1, 0xe0, 0x25, 0x06, 0xf9, 0x18,
  30681. 0x14, 0xab, 0x3b, 0x73, 0x26, 0xee, 0xa0, 0xfd,
  30682. 0x15, 0xac, 0xd6, 0x4e, 0x6b, 0xdb, 0x01, 0xa1,
  30683. 0xdc, 0xd1, 0x2f, 0xd2, 0xb7, 0x5e, 0x12, 0x4f,
  30684. 0x4b, 0x59, 0xd8, 0x03, 0x12, 0x60, 0xc9, 0x81,
  30685. 0xb7, 0x06, 0x23, 0x09, 0xc4, 0xd9, 0xa8, 0x93,
  30686. 0x6e, 0x96, 0xf4, 0x93, 0x53, 0xf0, 0x3d, 0xde,
  30687. 0x10, 0x88, 0xb1, 0xd0, 0xcc, 0xad, 0x2c, 0xbf,
  30688. 0x88, 0x98, 0x8f, 0x25, 0x76, 0xd7, 0x65, 0x77,
  30689. 0xcc, 0x36, 0x1d, 0x1b, 0x6b, 0x60, 0x58, 0xc4,
  30690. 0xfe, 0xe6, 0xca, 0xa8, 0x29, 0x33, 0x69, 0x36,
  30691. 0xb8, 0x12, 0x95, 0x38, 0xd9, 0xd4, 0x16, 0xe9,
  30692. 0x3e, 0x40, 0x8c, 0xc7, 0xae, 0x04, 0x11, 0xdf,
  30693. 0x51, 0xd3, 0xdd, 0xbf, 0xa9, 0x41, 0x43, 0x4c,
  30694. 0xff, 0x87, 0x2f, 0xea, 0x0f, 0x13, 0x66, 0x2a,
  30695. 0x2b, 0x18, 0xe8, 0xc4, 0xff, 0xa0, 0x1c, 0x78,
  30696. 0x79, 0x21, 0xf8, 0xaa, 0x8a, 0xf8, 0x92, 0xdf,
  30697. 0x7b, 0x5f, 0x6a, 0x71, 0x60, 0x67, 0x5d, 0x94,
  30698. 0xf6, 0xbb, 0x1d, 0x90, 0x7c, 0x51, 0x70, 0x1d,
  30699. 0x87, 0xde, 0xf8, 0x91, 0xcb, 0x42, 0x9f, 0xc7,
  30700. 0x4b, 0xa0, 0x16, 0xee, 0xb4, 0x73, 0xe8, 0xe0,
  30701. 0x0b, 0xa5, 0xd3, 0x26, 0x9e, 0x52, 0xda, 0x4a,
  30702. 0x1f, 0xae, 0x76, 0xbf, 0xbb, 0x4d, 0x74, 0x98,
  30703. 0xa6, 0xae, 0xc0, 0x60, 0x96, 0xc5, 0xad, 0x9b,
  30704. 0x91, 0x31, 0xb9, 0x50, 0x3d, 0x9a, 0x0f, 0xe1,
  30705. 0x93, 0xef, 0x08, 0x72, 0xb2, 0x66, 0xe5, 0x5d,
  30706. 0xe4, 0x15, 0x53, 0x8e, 0xb0, 0xb3, 0xf8, 0x78,
  30707. 0xfc, 0x5d, 0x44, 0xc5, 0xbf, 0xf5, 0x01, 0x54,
  30708. 0xc5, 0x45, 0xa9, 0x30, 0xa4, 0xf1, 0x49, 0x79,
  30709. 0x4e, 0xab, 0xfc, 0xb2, 0x93, 0xe7, 0x3a, 0xe1,
  30710. 0x7f, 0x1f, 0x2f, 0x45, 0x3a, 0x53, 0x2b, 0x68,
  30711. 0xb3, 0xa4, 0xac, 0x23, 0x54, 0xb7, 0x5d, 0x25,
  30712. 0xa3, 0xe3, 0x90, 0x8a, 0xb0, 0x02, 0xfb, 0x7f,
  30713. 0x2d, 0xeb, 0x80, 0xc2, 0x5c, 0x62, 0xe1, 0x36,
  30714. 0x5a, 0x82, 0x8f, 0x4e, 0x74, 0xeb, 0x7d, 0x70,
  30715. 0xaf, 0x23, 0x92, 0x65, 0x3a, 0x11, 0xc0, 0x29,
  30716. 0xdb, 0xf7, 0x9a, 0xdc, 0x81, 0x45, 0x25, 0x0c,
  30717. 0x2e, 0x4f, 0x88, 0x41, 0x34, 0x53, 0xc6, 0x08,
  30718. 0x21, 0x77, 0xc1, 0xbb, 0x61, 0x48, 0x20, 0x69,
  30719. 0x1a, 0xbb, 0x71, 0x1b, 0x56, 0x18, 0x79, 0x75,
  30720. 0x16, 0x9a, 0xb3, 0x79, 0x31, 0x11, 0xa2, 0x89,
  30721. 0x8d, 0xea, 0x10, 0xb0, 0x04, 0x7f, 0xf8, 0x6e,
  30722. 0xdc, 0x08, 0x9b, 0x51, 0xa7, 0x64, 0xbd, 0x8d,
  30723. 0xd4, 0xd0, 0x1e, 0x38, 0x50, 0x1a, 0xa8, 0x7e,
  30724. 0x20, 0xae, 0xee, 0x8c, 0xa7, 0x72, 0x94, 0xc9,
  30725. 0xba, 0xf0, 0x67, 0xbd, 0x25, 0x1a, 0x3a, 0xdf,
  30726. 0x75, 0x39, 0xb7, 0xd3, 0x83, 0x3b, 0x89, 0xdf,
  30727. 0xb5, 0x2d, 0xd3, 0x12, 0x24, 0x21, 0x7c, 0x9e,
  30728. 0x92, 0x1c, 0x19, 0xae, 0x28, 0xcb, 0x2e, 0x2e,
  30729. 0x3c, 0xa9, 0x9b, 0xbd, 0xf9, 0x33, 0x30, 0xb2,
  30730. 0xbd, 0x8b, 0xbf, 0xc1, 0x8b, 0x32, 0xf1, 0x20,
  30731. 0xa1, 0x00, 0xfd, 0x11, 0x7d, 0x9a, 0xa8, 0x14,
  30732. 0x2c, 0xce, 0x16, 0x16, 0x4b, 0xdd, 0x56, 0x91,
  30733. 0x15, 0x36, 0x83, 0xcb, 0x01, 0x58, 0x35, 0xe1,
  30734. 0xdc, 0x22, 0x3d, 0xf8, 0xc2, 0x06, 0x54, 0x68,
  30735. 0x77, 0xd1, 0x47, 0x28, 0xdc, 0x09, 0x2a, 0x86,
  30736. 0x13, 0x80, 0xa6, 0xe9, 0xd0, 0xb4, 0xa3, 0x41,
  30737. 0x47, 0xf4, 0x71, 0x24, 0x10, 0x4c, 0x9f, 0xb7,
  30738. 0x57, 0x34, 0x48, 0x1b, 0xb4, 0xed, 0x0e, 0x89,
  30739. 0x4c, 0xf1, 0x73, 0x44, 0xff, 0x35, 0xb6, 0xe0,
  30740. 0x8f, 0x02, 0xa3, 0xa3, 0x81, 0x55, 0x38, 0xb5,
  30741. 0xc1, 0x99, 0xb3, 0x88, 0x84, 0x0d, 0xd9, 0x73,
  30742. 0x77, 0x65, 0x0b, 0xd7, 0xf8, 0x03, 0x88, 0xcb,
  30743. 0xdf, 0x25, 0xaf, 0xc6, 0xf1, 0xfa, 0x5c, 0x4d,
  30744. 0xfa, 0xc3, 0x7b, 0x8f, 0xb8, 0x38, 0x5d, 0x29,
  30745. 0xbb, 0x3d, 0x3e, 0x62, 0x1c, 0xdd, 0xe6, 0x97,
  30746. 0xe6, 0xe9, 0xbe, 0x6e, 0xd2, 0xb7, 0x7a, 0x9a,
  30747. 0x8e, 0xaf, 0xb3, 0xc8, 0x9e, 0x19, 0xee, 0x3d,
  30748. 0x5b, 0x1f, 0xec, 0x34, 0x3a, 0x1c, 0x27, 0x90,
  30749. 0xbd, 0x1e, 0x49, 0x72, 0x25, 0x2e, 0x38, 0x48,
  30750. 0x7d, 0xe1, 0x85, 0x46, 0xa7, 0x1b, 0x4a, 0xd5,
  30751. 0x23, 0x75, 0x6d, 0x8b, 0xc3, 0xf1, 0x87, 0xec,
  30752. 0x8b, 0x45, 0xf0, 0x9b, 0xb2, 0x14, 0x7a, 0x7c,
  30753. 0x8d, 0x78, 0x9c, 0x82, 0x64, 0x14, 0xfe, 0x01,
  30754. 0xfa, 0x04, 0x33, 0x96, 0xdd, 0x5f, 0x56, 0xbc,
  30755. 0xb2, 0x03, 0xe3, 0x0c, 0xa1, 0x09, 0x66, 0xa0,
  30756. 0x5e, 0x44, 0xde, 0x21, 0xae, 0x7d, 0x7a, 0x0e,
  30757. 0x81, 0x27, 0xd2, 0xfb, 0x85, 0xed, 0x27, 0x27,
  30758. 0xac, 0x11, 0x1c, 0xa1, 0x6d, 0xe9, 0xc1, 0xca,
  30759. 0xf6, 0x40, 0x7c, 0x95, 0x01, 0xb7, 0xa8, 0x29,
  30760. 0x9a, 0xd2, 0xcc, 0x62, 0x70, 0x1c, 0x7d, 0x0e,
  30761. 0xe5, 0x60, 0xcb, 0x79, 0xa3, 0xd7, 0x5d, 0x48,
  30762. 0x4b, 0x3c, 0xf8, 0x12, 0xe8, 0x7a, 0x7e, 0x83,
  30763. 0xab, 0x24, 0x33, 0x0f, 0x7b, 0x0a, 0x38, 0xae,
  30764. 0xb1, 0xfc, 0xc3, 0x50, 0x5c, 0x83, 0x53, 0xfd,
  30765. 0x15, 0xd6, 0x49, 0x54, 0xb6, 0x40, 0xe5, 0xe8,
  30766. 0x55, 0xba, 0x08, 0x2f, 0x21, 0xd7, 0x0e, 0x71,
  30767. 0x8a, 0xb2, 0xe1, 0x6b, 0xc6, 0x7e, 0x0f, 0x1c,
  30768. 0x4d, 0x41, 0x9f, 0x38, 0xc2, 0xce, 0x41, 0x41,
  30769. 0x48, 0xcd, 0xec, 0x16, 0x1d, 0x23, 0x8e, 0x41,
  30770. 0xcd, 0x5e, 0xf9, 0x5f, 0x01, 0x5e, 0x73, 0xa2,
  30771. 0xa1, 0xef, 0xe9, 0x57, 0xe0, 0xba, 0xe6, 0xbb,
  30772. 0x2b, 0xff, 0x3e, 0xb8, 0xad, 0xd5, 0x12, 0xc1,
  30773. 0x54, 0x49, 0xca, 0x93, 0xb0, 0x7d, 0x7b, 0xcf,
  30774. 0xf0, 0xc5, 0x94, 0x43, 0x30, 0x94, 0x11, 0x8d,
  30775. 0x15, 0x79, 0x2e, 0x57, 0xb8, 0x24, 0xcd, 0x2e,
  30776. 0xc2, 0x49, 0x3d, 0x92, 0x44, 0x23, 0x0c, 0x3e,
  30777. 0xa0, 0xf9, 0xa5, 0xad, 0x2a, 0x56, 0xec, 0xf4,
  30778. 0x6d, 0x0f, 0x5b, 0xb5, 0xd4, 0x2a, 0x3f, 0x2b,
  30779. 0x17, 0x9f, 0x5d, 0x33, 0x97, 0x42, 0xd4, 0x1e,
  30780. 0x14, 0x49, 0x01, 0xfb, 0xb6, 0x72, 0xbc, 0x14,
  30781. 0x5b, 0x79, 0xf4, 0x0a, 0xc5, 0x49, 0xe1, 0x76,
  30782. 0x44, 0x78, 0x87, 0xd1, 0x8e, 0x5b, 0xd5, 0x95,
  30783. 0xad, 0x19, 0x7c, 0x0d, 0x39, 0x7f, 0x41, 0x2e,
  30784. 0xd7, 0x9e, 0xbc, 0xfd, 0x2c, 0xde, 0xfa, 0x01,
  30785. 0x7d, 0x2b, 0x04, 0xef, 0x4d, 0xf9, 0xf4, 0x5b,
  30786. 0xed, 0x05, 0x9a, 0x50, 0x35, 0xe7, 0xb0, 0xba,
  30787. 0x24, 0xea, 0x16, 0x51, 0xe1, 0x6f, 0x32, 0x08,
  30788. 0x94, 0xd6, 0x19, 0x9d, 0x0e, 0x4c, 0xc1, 0xbb,
  30789. 0x01, 0x87, 0xa5, 0x90, 0x5f, 0x6f, 0xc4, 0xed,
  30790. 0xa1, 0x4c, 0x06, 0x4d, 0x2c, 0x47, 0x24, 0xda,
  30791. 0xae, 0xd2, 0x41, 0x92, 0x1f, 0x46, 0xce, 0xec,
  30792. 0xb1, 0xcc, 0x80, 0x1e, 0xb2, 0xcb, 0x66, 0x48,
  30793. 0x22, 0xec, 0x0e, 0x47, 0xfc, 0xad, 0x17, 0xfe,
  30794. 0x7b, 0xc5, 0x4d, 0x34, 0x95, 0x40, 0xd0, 0x02,
  30795. 0x7e, 0x90, 0xaa, 0x92, 0xaf, 0x48, 0x64, 0xc5,
  30796. 0xc1, 0x56, 0xd8, 0x9b, 0x6c, 0x5f, 0x2e, 0xfa,
  30797. 0xd7, 0x84, 0xdc, 0x71, 0x65, 0x1b, 0xfb, 0xbc,
  30798. 0x21, 0xc7, 0x57, 0xf4, 0x71, 0x2e, 0x6f, 0x34,
  30799. 0x85, 0x99, 0xa8, 0x5c, 0x6f, 0x34, 0x22, 0x44,
  30800. 0x89, 0x01, 0xf9, 0x48, 0xd2, 0xe2, 0xe4, 0x71,
  30801. 0x9d, 0x48, 0x07, 0x97, 0xd4, 0x66, 0xe4, 0x4d,
  30802. 0x48, 0xa3, 0x08, 0x7f, 0x6e, 0xaa, 0x7b, 0xe9,
  30803. 0x93, 0x81, 0x03, 0x0c, 0xd2, 0x48, 0xcf, 0x3f,
  30804. 0x5f, 0xbe, 0x03, 0xfb, 0x0f, 0xad, 0xc3, 0x81,
  30805. 0xd9, 0xce, 0x88, 0x0b, 0xfa, 0xed, 0x29, 0x7e,
  30806. 0x0b, 0xa1, 0x6f, 0x4c, 0x7d, 0xe4, 0x36, 0xff,
  30807. 0xdf, 0x94, 0x1a, 0x24, 0xb3, 0x7b, 0xca, 0x24,
  30808. 0x7e, 0x3a, 0x19, 0x53, 0x13, 0x4a, 0x17, 0x58,
  30809. 0xe7, 0x16, 0x9b, 0x50, 0xd8, 0xda, 0xcc, 0x6e,
  30810. 0x05, 0x25, 0xfe, 0x16, 0xcb, 0x5b, 0xd5, 0x35,
  30811. 0x76, 0x40, 0x44, 0x96, 0x23, 0x97, 0xe2, 0x4a,
  30812. 0x72, 0x0c, 0x54, 0x43, 0xc0, 0x09, 0x85, 0x8e,
  30813. 0x15, 0x85, 0xaf, 0x3c, 0x5e, 0x5f, 0x3c, 0x2d,
  30814. 0x21, 0x42, 0x75, 0xb7, 0xe4, 0x50, 0xf9, 0x00,
  30815. 0xa3, 0x4f, 0xb1, 0x7c, 0xfe, 0x62, 0xd0, 0xe9,
  30816. 0x6d, 0x51, 0xcc, 0x83, 0xc1, 0xdc, 0x37, 0x10,
  30817. 0x90, 0x0a, 0x15, 0xd8, 0xd5, 0x02, 0xf7, 0x74,
  30818. 0xb8, 0x46, 0x84, 0xc3, 0x61, 0x17, 0x26, 0x0f,
  30819. 0xe4, 0xde, 0x1a, 0xcf, 0x42, 0x53, 0x63, 0x2f,
  30820. 0x8d, 0xf7, 0x06, 0x07, 0xc3, 0x33, 0x39, 0x59,
  30821. 0xe9, 0x17, 0xc8, 0x05, 0xd2, 0xa2, 0xae, 0x53,
  30822. 0x2c, 0x7e, 0xd0, 0x9d, 0x5c, 0xb5, 0x42, 0x9f,
  30823. 0x84, 0xd7, 0xfe, 0x93, 0x74, 0xfb, 0xbb, 0xd2,
  30824. 0x1e, 0x57, 0x4e, 0x7f, 0x79, 0xaf, 0xd2, 0xf9,
  30825. 0x5e, 0x41, 0x9e, 0x63, 0x54, 0x61, 0x47, 0x0c,
  30826. 0x92, 0x4c, 0xc9, 0xfe, 0x4f, 0xcb, 0xe5, 0x8e,
  30827. 0x65, 0xb3, 0x97, 0x1b, 0xd8, 0xd1, 0x62, 0xfd
  30828. #else
  30829. 0x30, 0x82, 0x0a, 0x34, 0x30, 0x0d, 0x06, 0x0b,
  30830. 0x2b, 0x06, 0x01, 0x04, 0x01, 0x02, 0x82, 0x0b,
  30831. 0x0c, 0x08, 0x07, 0x03, 0x82, 0x0a, 0x21, 0x00,
  30832. 0x7f, 0x5f, 0x63, 0x81, 0x6f, 0x04, 0x4c, 0xec,
  30833. 0xa8, 0xaf, 0x7b, 0x99, 0x41, 0xc6, 0xff, 0xdf,
  30834. 0x77, 0x66, 0x28, 0xc0, 0xe2, 0x58, 0xea, 0x9c,
  30835. 0x60, 0xbb, 0x03, 0x3e, 0xca, 0xa8, 0x38, 0x64,
  30836. 0xfb, 0xf7, 0x1b, 0x3f, 0xec, 0xfd, 0x0f, 0xf1,
  30837. 0x9c, 0xe4, 0xfd, 0xad, 0x83, 0xf7, 0x03, 0x66,
  30838. 0x6e, 0x7f, 0x4d, 0x42, 0xab, 0x6b, 0x73, 0x26,
  30839. 0xde, 0x6f, 0x8c, 0xc4, 0xca, 0x21, 0x66, 0x31,
  30840. 0x79, 0x57, 0x88, 0xcb, 0x1e, 0xab, 0xda, 0x1d,
  30841. 0x56, 0x70, 0xd9, 0x83, 0xa1, 0xb4, 0x83, 0xce,
  30842. 0xcc, 0x0f, 0xeb, 0xd6, 0x63, 0xbd, 0xf6, 0x02,
  30843. 0x5d, 0x5b, 0x0c, 0x17, 0x3c, 0x3e, 0x15, 0x02,
  30844. 0x22, 0xa1, 0x5d, 0xb5, 0xc5, 0x81, 0x28, 0x95,
  30845. 0x0b, 0x34, 0x2b, 0x96, 0x0a, 0xae, 0x6a, 0xa8,
  30846. 0xb5, 0x1d, 0x56, 0xbb, 0x7d, 0x83, 0x9a, 0x15,
  30847. 0xad, 0x63, 0x9e, 0x86, 0x8c, 0x6e, 0x6a, 0xa8,
  30848. 0xde, 0x55, 0xd0, 0xce, 0xc0, 0x2e, 0x05, 0xfe,
  30849. 0x1f, 0x4d, 0xd7, 0x12, 0xa4, 0x5a, 0xe9, 0x04,
  30850. 0x0d, 0x20, 0x84, 0x90, 0xb9, 0xca, 0x64, 0xe4,
  30851. 0xad, 0x2e, 0x74, 0x4b, 0x1d, 0x2f, 0xcc, 0xac,
  30852. 0xd8, 0x1a, 0x5e, 0xb2, 0x78, 0xbe, 0x61, 0xf7,
  30853. 0x36, 0xa3, 0xd1, 0x93, 0x86, 0xb5, 0x15, 0xf1,
  30854. 0x74, 0xf8, 0x9f, 0x6d, 0x6a, 0x8f, 0x6d, 0x86,
  30855. 0x8b, 0x36, 0x61, 0x10, 0xc9, 0x1a, 0x31, 0x39,
  30856. 0x09, 0xe6, 0x15, 0xa0, 0xb1, 0xfa, 0x69, 0xd4,
  30857. 0xc2, 0xb2, 0x56, 0x4c, 0x06, 0x33, 0x13, 0xc4,
  30858. 0x78, 0x53, 0x16, 0xfc, 0x52, 0x99, 0xe6, 0x27,
  30859. 0xc9, 0x3b, 0x24, 0x5c, 0x3e, 0x85, 0x73, 0x76,
  30860. 0x61, 0xa3, 0x61, 0xf0, 0x95, 0xd5, 0xb2, 0xf5,
  30861. 0x21, 0xe7, 0x09, 0xc3, 0x0c, 0x5c, 0xb0, 0x36,
  30862. 0xce, 0x45, 0x68, 0x41, 0x45, 0xcb, 0x1c, 0x36,
  30863. 0x2f, 0x3a, 0x00, 0x07, 0x56, 0xbe, 0x61, 0xd2,
  30864. 0x77, 0x37, 0x63, 0xa4, 0xdb, 0xfa, 0xa9, 0x6b,
  30865. 0x37, 0x90, 0x35, 0xd1, 0x1e, 0x27, 0x5b, 0x3e,
  30866. 0xc0, 0x0a, 0x02, 0x64, 0xe4, 0x58, 0x49, 0xab,
  30867. 0x2d, 0xc1, 0x38, 0x29, 0x3d, 0x44, 0xf9, 0xac,
  30868. 0xb7, 0x65, 0xd1, 0x5f, 0xf8, 0xce, 0x52, 0x76,
  30869. 0x22, 0x15, 0x61, 0x02, 0x1f, 0xa7, 0xcd, 0xff,
  30870. 0xeb, 0xa6, 0x7f, 0x6b, 0xba, 0x75, 0xe3, 0x09,
  30871. 0x01, 0x06, 0x41, 0x20, 0x88, 0x75, 0x64, 0x6b,
  30872. 0x97, 0x38, 0x13, 0xab, 0x4c, 0x0a, 0xd4, 0x7e,
  30873. 0xd2, 0xfa, 0x78, 0xe8, 0x9f, 0x5d, 0xf9, 0x53,
  30874. 0x30, 0x17, 0xf1, 0x10, 0x9e, 0x4a, 0x32, 0x17,
  30875. 0x3a, 0x9b, 0xb9, 0x25, 0x8e, 0xeb, 0xd9, 0x41,
  30876. 0x01, 0xa2, 0xc6, 0x58, 0x4a, 0x9f, 0xc3, 0x73,
  30877. 0xfd, 0xe2, 0xe4, 0x2c, 0x92, 0xb4, 0xa2, 0x3d,
  30878. 0x0f, 0x1f, 0x37, 0x64, 0xf1, 0x17, 0x2a, 0x8c,
  30879. 0xc6, 0xb5, 0xb0, 0x69, 0x7d, 0xfe, 0x08, 0xe0,
  30880. 0x8e, 0xaa, 0xe0, 0x08, 0xd5, 0x28, 0x92, 0x51,
  30881. 0x73, 0x8a, 0x2f, 0x7a, 0x4a, 0xbf, 0x52, 0x8d,
  30882. 0x3e, 0x9b, 0x36, 0x6a, 0xfb, 0x19, 0xf0, 0xea,
  30883. 0xfe, 0x05, 0xbd, 0x2d, 0xa9, 0x58, 0x48, 0x02,
  30884. 0xa8, 0x20, 0x9e, 0xdc, 0x04, 0x57, 0xc2, 0x0c,
  30885. 0xae, 0xc1, 0x03, 0xe7, 0x17, 0x48, 0x80, 0x00,
  30886. 0x8d, 0x1b, 0xd0, 0xc5, 0xdc, 0x2a, 0x02, 0x6e,
  30887. 0x8e, 0x54, 0xf3, 0x79, 0x31, 0x02, 0x93, 0xc5,
  30888. 0xf2, 0x55, 0xea, 0x61, 0xd0, 0xb2, 0x8e, 0xc9,
  30889. 0x74, 0x17, 0x0d, 0x38, 0xf8, 0xab, 0xf4, 0x42,
  30890. 0xd4, 0xc2, 0xdc, 0xf7, 0x1b, 0xdb, 0x65, 0x36,
  30891. 0x9f, 0x56, 0xe2, 0xeb, 0xf7, 0xe5, 0x2d, 0x45,
  30892. 0xae, 0xc0, 0x95, 0xbc, 0xe4, 0x1f, 0x22, 0xdc,
  30893. 0x0f, 0x54, 0xed, 0x14, 0xb8, 0xf1, 0x2f, 0x5d,
  30894. 0xd1, 0x79, 0xa0, 0x81, 0x17, 0x71, 0xa1, 0xd6,
  30895. 0xf0, 0x88, 0x9c, 0x1c, 0xc7, 0x95, 0x07, 0xb0,
  30896. 0xea, 0xf7, 0xd3, 0xa2, 0x55, 0xfe, 0x85, 0x65,
  30897. 0x42, 0x06, 0xec, 0xd2, 0xbe, 0x03, 0x8f, 0x63,
  30898. 0x84, 0x4b, 0xb1, 0x47, 0x48, 0x20, 0x71, 0xd2,
  30899. 0xdf, 0xc9, 0x59, 0xb0, 0x24, 0x8a, 0x6e, 0xf9,
  30900. 0x4a, 0xa1, 0x7b, 0xed, 0x11, 0xb6, 0xf9, 0x9b,
  30901. 0xf7, 0x93, 0x0e, 0xcb, 0x7a, 0x32, 0x22, 0x23,
  30902. 0x4e, 0x86, 0xce, 0xad, 0x9d, 0x1b, 0x84, 0x57,
  30903. 0xaf, 0xa5, 0x04, 0x03, 0x0a, 0xc9, 0x04, 0x97,
  30904. 0xd0, 0xce, 0x8e, 0x2a, 0x9a, 0x00, 0x15, 0xeb,
  30905. 0xac, 0x96, 0x57, 0xde, 0xe6, 0xc1, 0x2d, 0xbd,
  30906. 0xfc, 0xd6, 0x95, 0x0f, 0x5f, 0x19, 0xac, 0xaf,
  30907. 0x6c, 0xd8, 0xa6, 0x1e, 0xd8, 0xdb, 0x14, 0xfd,
  30908. 0xba, 0x0f, 0xd0, 0x3f, 0x61, 0xe3, 0x76, 0xfc,
  30909. 0x47, 0x61, 0x07, 0x24, 0x49, 0x17, 0xca, 0x24,
  30910. 0x31, 0x16, 0x26, 0x4f, 0xdc, 0x2b, 0x39, 0xae,
  30911. 0x5f, 0xfa, 0x4f, 0x82, 0xef, 0xe1, 0x41, 0x8c,
  30912. 0x3e, 0x8e, 0xa7, 0x6c, 0xf2, 0x51, 0xf7, 0x85,
  30913. 0x35, 0x6c, 0xad, 0xea, 0x32, 0x35, 0xf3, 0xc0,
  30914. 0x14, 0x17, 0xe2, 0x98, 0x27, 0x36, 0x7e, 0x60,
  30915. 0x2f, 0x01, 0x60, 0x3e, 0x18, 0xf4, 0x4e, 0xe0,
  30916. 0xf5, 0x14, 0x21, 0x81, 0x05, 0x78, 0x1c, 0x5f,
  30917. 0x4e, 0x89, 0xbb, 0x23, 0x60, 0xb1, 0x8f, 0x07,
  30918. 0x53, 0x16, 0x6e, 0xfb, 0x86, 0x07, 0x90, 0xff,
  30919. 0xa6, 0x27, 0x60, 0xe6, 0x3e, 0x92, 0x2a, 0x3c,
  30920. 0xa3, 0x57, 0xec, 0x97, 0x23, 0xaf, 0xd2, 0x44,
  30921. 0xac, 0x09, 0x87, 0xb0, 0x54, 0xe9, 0x5b, 0x50,
  30922. 0x37, 0xfa, 0x12, 0xa4, 0xcb, 0x6f, 0xed, 0x9f,
  30923. 0x29, 0x73, 0xa7, 0x09, 0x29, 0x91, 0x93, 0x5c,
  30924. 0x54, 0xf4, 0x44, 0xc2, 0x04, 0x64, 0xfc, 0xd2,
  30925. 0xf2, 0x0a, 0x0b, 0x45, 0x1f, 0xc5, 0x18, 0xf0,
  30926. 0xff, 0x10, 0x1f, 0x3a, 0x97, 0xf8, 0xb1, 0x83,
  30927. 0x0e, 0x08, 0xe2, 0x55, 0x75, 0x6a, 0x45, 0x96,
  30928. 0xf8, 0x1b, 0xdc, 0xb6, 0x57, 0x83, 0x8c, 0x28,
  30929. 0xc0, 0x4a, 0x57, 0xc6, 0xfb, 0x27, 0x3d, 0xfa,
  30930. 0x5a, 0x0d, 0x69, 0x56, 0x23, 0x66, 0x02, 0x78,
  30931. 0xca, 0xf1, 0xfa, 0xcb, 0xc1, 0xf6, 0x92, 0x1c,
  30932. 0xa0, 0xe3, 0x09, 0x7d, 0x48, 0x5e, 0x86, 0xa0,
  30933. 0x82, 0xa8, 0xf1, 0x1e, 0xe1, 0xfe, 0xc6, 0x9d,
  30934. 0x4f, 0x2e, 0xf4, 0xfc, 0xc6, 0x48, 0x1d, 0xc1,
  30935. 0x2a, 0x6a, 0xb7, 0xea, 0x46, 0x89, 0x04, 0xe9,
  30936. 0xbd, 0xf1, 0xed, 0x16, 0x76, 0xd8, 0x4b, 0x42,
  30937. 0xd5, 0x43, 0xa4, 0xfb, 0x02, 0x01, 0x54, 0x00,
  30938. 0xaf, 0x55, 0x52, 0x27, 0xff, 0x00, 0xe2, 0xbb,
  30939. 0x4a, 0xf2, 0x69, 0xb4, 0x4e, 0x6c, 0x6b, 0xa3,
  30940. 0x96, 0x4f, 0xf4, 0x65, 0x90, 0x2d, 0xc8, 0x57,
  30941. 0x1f, 0xb2, 0xf0, 0x86, 0x7b, 0x93, 0x09, 0x49,
  30942. 0x31, 0xc4, 0xf4, 0x8f, 0xc8, 0x2d, 0xac, 0x1d,
  30943. 0xfc, 0xba, 0xa4, 0xa5, 0x41, 0x90, 0x76, 0x7d,
  30944. 0x9e, 0x47, 0xdc, 0x10, 0xe6, 0x0c, 0xf7, 0x0f,
  30945. 0xa4, 0xba, 0x4f, 0xe2, 0x46, 0x38, 0x4c, 0x28,
  30946. 0xa0, 0x57, 0xb5, 0x3c, 0xb3, 0x4b, 0x8f, 0x03,
  30947. 0x04, 0xff, 0xf6, 0xec, 0x60, 0x90, 0x62, 0xfe,
  30948. 0x74, 0x76, 0x48, 0xb3, 0xf4, 0x0a, 0x6a, 0x5a,
  30949. 0x5b, 0xad, 0xc8, 0x54, 0x62, 0x11, 0x52, 0xd9,
  30950. 0x84, 0x1a, 0x09, 0x4b, 0xca, 0x66, 0xaa, 0x3c,
  30951. 0x36, 0x08, 0x9d, 0x58, 0xd0, 0x4a, 0x3a, 0x8b,
  30952. 0x24, 0xe0, 0x80, 0x9f, 0xe3, 0x76, 0xb6, 0x07,
  30953. 0xb1, 0xbc, 0x00, 0x98, 0xb0, 0xc1, 0xe0, 0xf6,
  30954. 0x1f, 0x4d, 0xa8, 0xd1, 0x69, 0x44, 0x9c, 0x33,
  30955. 0xb0, 0x0f, 0x9c, 0xc9, 0x0c, 0x8c, 0xbc, 0x03,
  30956. 0x58, 0x81, 0x76, 0xab, 0x0d, 0xef, 0x25, 0x5a,
  30957. 0xf6, 0xab, 0x3b, 0xf1, 0x1f, 0x97, 0x12, 0x8e,
  30958. 0x7f, 0x28, 0x77, 0x26, 0x18, 0xc4, 0xc4, 0xda,
  30959. 0x2c, 0x43, 0x57, 0xd2, 0x1f, 0x67, 0x95, 0x40,
  30960. 0x2c, 0x94, 0x41, 0x69, 0x22, 0x8a, 0x24, 0xd9,
  30961. 0xc7, 0xfc, 0xea, 0x49, 0x83, 0x8f, 0x5d, 0x2e,
  30962. 0x9d, 0xac, 0x17, 0xb6, 0xe0, 0xc4, 0xe7, 0xe6,
  30963. 0xd5, 0xc2, 0x73, 0xa1, 0x8f, 0x33, 0x14, 0x02,
  30964. 0xae, 0x01, 0x9f, 0x6f, 0x40, 0x92, 0x4e, 0x03,
  30965. 0xc2, 0xa9, 0xf1, 0x36, 0x78, 0xe4, 0xde, 0x39,
  30966. 0x4d, 0x29, 0x2e, 0xc2, 0x00, 0x93, 0x79, 0xe4,
  30967. 0xb2, 0x29, 0x4b, 0x81, 0x5c, 0x06, 0x06, 0xbc,
  30968. 0xc1, 0x01, 0x1c, 0xa7, 0x08, 0xf7, 0x47, 0x1f,
  30969. 0x52, 0x4f, 0xdf, 0x94, 0x1e, 0xe6, 0x89, 0xe6,
  30970. 0x26, 0x71, 0x2e, 0xa2, 0xd2, 0xfe, 0x04, 0xf2,
  30971. 0x12, 0x4c, 0x06, 0x78, 0x34, 0xc0, 0xb9, 0x76,
  30972. 0x62, 0x3b, 0x72, 0x25, 0x8c, 0x0d, 0x73, 0x24,
  30973. 0xcf, 0x4b, 0x4c, 0x47, 0x20, 0x9d, 0x04, 0x7f,
  30974. 0x86, 0x2c, 0x45, 0xb8, 0xfe, 0xb2, 0xaa, 0x36,
  30975. 0xf8, 0xe0, 0x24, 0x25, 0x05, 0x23, 0x12, 0x16,
  30976. 0xbf, 0x64, 0x10, 0xdd, 0xe4, 0xc0, 0xb0, 0x85,
  30977. 0xa7, 0xd3, 0xd1, 0x18, 0x1b, 0x81, 0x6b, 0x94,
  30978. 0xfd, 0x07, 0x43, 0xdd, 0x12, 0x37, 0x78, 0x69,
  30979. 0xec, 0x8c, 0xd0, 0x41, 0x2c, 0x42, 0x94, 0x3e,
  30980. 0x9f, 0xe3, 0x49, 0xb3, 0xb8, 0x45, 0x0b, 0x1d,
  30981. 0xc1, 0x9b, 0x4d, 0x21, 0x85, 0x62, 0xea, 0xd1,
  30982. 0xc9, 0x12, 0x30, 0x8c, 0x4b, 0x63, 0xeb, 0x7d,
  30983. 0x02, 0x52, 0x15, 0xa1, 0x95, 0x48, 0x9f, 0xc2,
  30984. 0xce, 0xf3, 0x4b, 0xff, 0x5a, 0xb6, 0x8f, 0xce,
  30985. 0xcd, 0x42, 0x21, 0x40, 0x82, 0xad, 0x08, 0x99,
  30986. 0x4d, 0x24, 0x58, 0x25, 0xf3, 0x7e, 0x42, 0x86,
  30987. 0x06, 0x33, 0x1f, 0x53, 0xbb, 0x07, 0x33, 0xca,
  30988. 0xc0, 0x02, 0x18, 0x30, 0x3c, 0xc5, 0x67, 0x1c,
  30989. 0x32, 0x3f, 0x2d, 0x58, 0x4c, 0x24, 0x6e, 0x60,
  30990. 0x96, 0x1a, 0xf4, 0xd0, 0x55, 0xb8, 0x84, 0xf0,
  30991. 0xb9, 0x83, 0xbf, 0x3d, 0x37, 0xe4, 0xa6, 0x06,
  30992. 0x1c, 0xd1, 0xd7, 0x91, 0x24, 0xdc, 0x3f, 0xcc,
  30993. 0x71, 0xf3, 0x0c, 0x90, 0x2c, 0x1d, 0x2f, 0x90,
  30994. 0xc8, 0x3c, 0x6f, 0x2c, 0x5d, 0xad, 0x8c, 0xdf,
  30995. 0xbb, 0x0d, 0x2a, 0x7f, 0x4a, 0x34, 0x5a, 0xd9,
  30996. 0x83, 0xfd, 0x61, 0x36, 0xe0, 0x0a, 0xb3, 0xf6,
  30997. 0x69, 0xb1, 0xaf, 0x81, 0x22, 0xd6, 0x9e, 0x9a,
  30998. 0xf8, 0xa6, 0x24, 0x8e, 0x0c, 0xcb, 0x25, 0xc2,
  30999. 0xfc, 0xc5, 0x94, 0xbd, 0x23, 0x9c, 0xa9, 0xbd,
  31000. 0x76, 0x28, 0xa4, 0x55, 0x92, 0x7c, 0xe6, 0x76,
  31001. 0xf7, 0x30, 0xf8, 0x7d, 0xdc, 0x0a, 0x93, 0x9e,
  31002. 0x7c, 0x39, 0x0a, 0x70, 0xa0, 0xb2, 0x77, 0xe0,
  31003. 0x7a, 0x89, 0x50, 0xce, 0x75, 0xca, 0x2f, 0xa4,
  31004. 0x12, 0x0e, 0xcb, 0x75, 0x1f, 0x0a, 0x83, 0xe8,
  31005. 0x14, 0x80, 0xa7, 0xb0, 0xe8, 0x11, 0xca, 0x12,
  31006. 0x5e, 0xf7, 0x31, 0x65, 0xbd, 0x20, 0x3d, 0x8c,
  31007. 0xa6, 0x89, 0x83, 0x68, 0x66, 0x03, 0x28, 0x49,
  31008. 0x17, 0xc4, 0x3f, 0x43, 0x02, 0x9b, 0xf8, 0xed,
  31009. 0xae, 0x8e, 0x68, 0xbc, 0x8e, 0x39, 0xe7, 0x15,
  31010. 0x32, 0x45, 0x66, 0x2c, 0x1f, 0xce, 0x56, 0xc7,
  31011. 0xc0, 0x15, 0x52, 0x19, 0x40, 0xcf, 0x87, 0x20,
  31012. 0xcd, 0x3d, 0xec, 0x90, 0x8d, 0x04, 0x01, 0x31,
  31013. 0x0b, 0x74, 0x80, 0x6e, 0x61, 0xa7, 0xf3, 0x4c,
  31014. 0xb2, 0x16, 0x00, 0xd5, 0xdb, 0xcc, 0xbb, 0x2c,
  31015. 0x9f, 0xb6, 0x02, 0x4a, 0xcf, 0x71, 0x06, 0xfd,
  31016. 0x60, 0xe0, 0x00, 0xbe, 0x22, 0xba, 0x39, 0x36,
  31017. 0xa8, 0x7e, 0xe5, 0xcb, 0xea, 0x87, 0xb1, 0xee,
  31018. 0xa2, 0x6c, 0x85, 0x94, 0x18, 0x6c, 0xab, 0x9a,
  31019. 0x93, 0xa7, 0xab, 0x4e, 0x3b, 0x85, 0xf3, 0xef,
  31020. 0x8f, 0x15, 0x74, 0x21, 0x9f, 0x5d, 0x9c, 0x22,
  31021. 0x32, 0x71, 0xb5, 0x4d, 0x7f, 0xaa, 0x85, 0xe0,
  31022. 0x05, 0x2a, 0x53, 0xbb, 0x3c, 0xab, 0xc3, 0xd2,
  31023. 0x73, 0x6e, 0x97, 0xa3, 0xfd, 0x05, 0x58, 0xaa,
  31024. 0x49, 0xc8, 0x69, 0xa9, 0x0b, 0x73, 0xd4, 0xe9,
  31025. 0x1d, 0x84, 0x60, 0x34, 0x2a, 0x09, 0xb3, 0x0f,
  31026. 0x08, 0x13, 0x67, 0x77, 0xb3, 0x24, 0xdf, 0xad,
  31027. 0xbf, 0x51, 0x71, 0x2b, 0xbe, 0x4f, 0x5d, 0xf4,
  31028. 0xe7, 0x25, 0x4c, 0x24, 0xa2, 0x4a, 0x22, 0xec,
  31029. 0xcc, 0x7c, 0x6c, 0x62, 0xee, 0x47, 0x12, 0x43,
  31030. 0x88, 0xe4, 0x71, 0xaa, 0x63, 0xaa, 0x2b, 0xed,
  31031. 0x70, 0xbf, 0x26, 0x37, 0xcc, 0xa4, 0xff, 0xe9,
  31032. 0xb6, 0x65, 0x31, 0x4d, 0x0d, 0x32, 0xd6, 0x84,
  31033. 0xb8, 0xab, 0x98, 0xa7, 0x10, 0x44, 0x77, 0xc7,
  31034. 0x2a, 0x60, 0xf0, 0xf5, 0xd5, 0xd4, 0x3a, 0x73,
  31035. 0x11, 0xa5, 0x1b, 0x18, 0x3c, 0x13, 0xfb, 0xda,
  31036. 0x76, 0x9d, 0xeb, 0x3e, 0xb9, 0x7a, 0xce, 0x02,
  31037. 0xa7, 0x5e, 0x25, 0x96, 0xd2, 0xbc, 0x85, 0x1a,
  31038. 0xd1, 0xa4, 0xe2, 0x02, 0x15, 0x08, 0x49, 0x16,
  31039. 0x7c, 0xaf, 0xc6, 0x38, 0x7b, 0x95, 0xf9, 0x37,
  31040. 0xc0, 0x87, 0x73, 0x6f, 0x01, 0xcd, 0x2b, 0xf1,
  31041. 0xe7, 0x6e, 0x47, 0x18, 0x30, 0xb8, 0x16, 0x87,
  31042. 0x1d, 0x23, 0x62, 0x22, 0x85, 0x92, 0x69, 0x46,
  31043. 0x9c, 0x65, 0xd8, 0xf1, 0x27, 0x32, 0xe4, 0x16,
  31044. 0x7f, 0x9a, 0xba, 0x46, 0x61, 0x60, 0x34, 0xe5,
  31045. 0xc0, 0x14, 0xb5, 0xde, 0x4d, 0xd1, 0x71, 0x39,
  31046. 0x26, 0xdc, 0x0c, 0x0a, 0x53, 0x9e, 0x31, 0x10,
  31047. 0x45, 0x7a, 0xf9, 0xc8, 0xfa, 0x1d, 0x69, 0x5e,
  31048. 0x25, 0xc1, 0xe2, 0x00, 0xbf, 0x94, 0xa3, 0xa2,
  31049. 0x97, 0xca, 0xb4, 0x6a, 0x89, 0x68, 0xdd, 0xed,
  31050. 0x6b, 0x99, 0x5a, 0x87, 0x9e, 0xe9, 0x68, 0xe4,
  31051. 0xf2, 0xc2, 0x7e, 0x37, 0x02, 0xdf, 0x96, 0x1a,
  31052. 0x5b, 0xed, 0xa1, 0xe8, 0xdf, 0x3c, 0xf7, 0xd2,
  31053. 0x25, 0xac, 0xf7, 0x4a, 0x7f, 0x10, 0x27, 0x2b,
  31054. 0x02, 0xc7, 0x95, 0x10, 0x5a, 0xb5, 0xb0, 0xcd,
  31055. 0xa9, 0xe1, 0x36, 0xe2, 0x1c, 0x87, 0x99, 0x0e,
  31056. 0x0a, 0x44, 0xec, 0x97, 0x75, 0xa7, 0x03, 0x27,
  31057. 0x38, 0x3b, 0x16, 0x30, 0x00, 0x98, 0xbe, 0x77,
  31058. 0xfe, 0x3a, 0xac, 0x6f, 0x8f, 0x4d, 0xe1, 0xa9,
  31059. 0x9c, 0xba, 0x39, 0x52, 0xe8, 0xf7, 0xe4, 0xe6,
  31060. 0xf9, 0xe9, 0xb3, 0x57, 0x82, 0xb2, 0x23, 0xd6,
  31061. 0xa5, 0x14, 0xc0, 0x78, 0xb4, 0xa0, 0xf9, 0x96,
  31062. 0xe4, 0x03, 0xe8, 0x6c, 0x27, 0xd8, 0x37, 0x7c,
  31063. 0x8f, 0xf4, 0x80, 0x09, 0x09, 0xc9, 0x32, 0x15,
  31064. 0xe0, 0x3f, 0x37, 0xa7, 0x1a, 0x5f, 0x8c, 0xfb,
  31065. 0xdd, 0xfe, 0x6b, 0x34, 0x28, 0x53, 0x03, 0x4b,
  31066. 0x39, 0x91, 0xf2, 0x48, 0x4c, 0x2a, 0x45, 0xfe,
  31067. 0x66, 0xf7, 0x23, 0x74, 0xb8, 0x30, 0x70, 0xb4,
  31068. 0x0c, 0x2c, 0x65, 0xb1, 0x4e, 0x32, 0x0f, 0x50,
  31069. 0xbb, 0x46, 0x9b, 0x03, 0x34, 0x38, 0xfb, 0xe4,
  31070. 0x25, 0x37, 0x8d, 0x0f, 0xa1, 0x41, 0x50, 0x85,
  31071. 0x92, 0x07, 0x71, 0xff, 0x3c, 0xe6, 0xd9, 0x1d,
  31072. 0x55, 0xb7, 0x10, 0x9c, 0xea, 0x70, 0x5f, 0xa3,
  31073. 0xba, 0x84, 0x99, 0x91, 0x30, 0x3d, 0x4c, 0x98,
  31074. 0x0b, 0x1f, 0x1f, 0xcc, 0x17, 0x94, 0xdd, 0x78,
  31075. 0x7d, 0x50, 0xe5, 0xf5, 0x21, 0x88, 0x5a, 0x52,
  31076. 0x76, 0x5a, 0x97, 0xbe, 0xba, 0xa9, 0xfe, 0x82,
  31077. 0x8a, 0xb5, 0x46, 0xcf, 0x9c, 0xbe, 0xe8, 0x2f,
  31078. 0x01, 0x2f, 0x6a, 0x03, 0x8a, 0xfa, 0x4b, 0x0b,
  31079. 0xdc, 0x78, 0x79, 0x9c, 0x49, 0xc4, 0x01, 0x26,
  31080. 0x16, 0x58, 0xc6, 0xb8, 0xee, 0x6c, 0xc9, 0xa9,
  31081. 0x38, 0x7c, 0xcf, 0xf3, 0xf8, 0xd0, 0x6b, 0x99,
  31082. 0x43, 0x13, 0xe0, 0x43, 0x8e, 0xfb, 0xb2, 0xdb,
  31083. 0x61, 0x67, 0xf4, 0xfc, 0x01, 0x21, 0xd9, 0xb1,
  31084. 0x1e, 0x6c, 0x6f, 0x2a, 0x9a, 0x4b, 0x86, 0x3c,
  31085. 0x62, 0x03, 0x53, 0x83, 0x11, 0x18, 0x1a, 0x59,
  31086. 0x9e, 0x25, 0xfe, 0xdb, 0x85, 0xd0, 0xee, 0x7c,
  31087. 0x97, 0x72, 0xca, 0xf3, 0x0d, 0xd4, 0x19, 0x66,
  31088. 0x14, 0xaf, 0x46, 0x68, 0x75, 0xdb, 0x8f, 0x5f,
  31089. 0x77, 0x7f, 0xfe, 0xa9, 0xe6, 0xa1, 0x9e, 0x46,
  31090. 0x5e, 0x92, 0xda, 0xea, 0xdd, 0x89, 0x01, 0xd9,
  31091. 0xab, 0x25, 0x7d, 0xb4, 0x64, 0x50, 0x8f, 0xa3,
  31092. 0xbe, 0xe2, 0x03, 0xd5, 0xc6, 0x9c, 0xc2, 0xf8,
  31093. 0xac, 0xa4, 0x36, 0xa9, 0x37, 0x10, 0x59, 0x00,
  31094. 0x45, 0xbb, 0x55, 0x33, 0xb9, 0x6f, 0xbc, 0xa2,
  31095. 0x02, 0x9e, 0xa3, 0x1d, 0xf4, 0x17, 0x78, 0x9b,
  31096. 0xbc, 0x42, 0x4e, 0x21, 0xc3, 0xde, 0xb5, 0x70,
  31097. 0x4a, 0x23, 0x1e, 0xd4, 0x36, 0x5d, 0x7a, 0x08,
  31098. 0x37, 0x55, 0x98, 0x07, 0xa0, 0x16, 0xa3, 0x4e,
  31099. 0xa1, 0x2b, 0x96, 0x8b, 0x51, 0x63, 0x48, 0xab,
  31100. 0xc9, 0x19, 0x6f, 0x5f, 0x25, 0x9d, 0xe7, 0x25,
  31101. 0x63, 0xf0, 0x8e, 0xdb, 0x06, 0x2d, 0x42, 0x31,
  31102. 0xfd, 0x14, 0x2b, 0x7a, 0x31, 0x43, 0x04, 0xd5,
  31103. 0xe2, 0x89, 0x2e, 0xa8, 0xe4, 0x6e, 0xd5, 0xa5,
  31104. 0x21, 0x67, 0x9b, 0x92, 0x61, 0x79, 0xdd, 0xe5,
  31105. 0x44, 0x43, 0x45, 0x57, 0x13, 0xec, 0x04, 0xc1,
  31106. 0x41, 0xa3, 0x14, 0x70, 0x86, 0xda, 0x76, 0x5d,
  31107. 0xe8, 0x61, 0xd2, 0xfb, 0x7b, 0xe4, 0x71, 0x46,
  31108. 0xa3, 0x52, 0xbf, 0xf2, 0xa0, 0x3c, 0xc1, 0x90,
  31109. 0x0c, 0x2e, 0xeb, 0xb3, 0x38, 0xae, 0x13, 0x27,
  31110. 0x84, 0xe9, 0x7a, 0xd6, 0x02, 0x40, 0x84, 0xff,
  31111. 0x87, 0x1f, 0x37, 0x44, 0xd8, 0x2e, 0x93, 0xf7,
  31112. 0x0a, 0xff, 0x5b, 0x4d, 0x07, 0x82, 0xfd, 0x6e,
  31113. 0x44, 0xcc, 0x19, 0xc3, 0x7d, 0x7c, 0x31, 0xf9,
  31114. 0x0e, 0xa8, 0x1c, 0x0d, 0xcb, 0x8e, 0xe8, 0x33,
  31115. 0xb2, 0xff, 0x9e, 0x1d, 0x99, 0x7c, 0x46, 0x5b,
  31116. 0xc7, 0x28, 0xec, 0x01, 0x62, 0x82, 0xfe, 0x2a,
  31117. 0x22, 0xa3, 0x86, 0x4e, 0x47, 0xe2, 0x57, 0xf1,
  31118. 0xb4, 0x58, 0x94, 0x89, 0xe5, 0xf1, 0xcd, 0x4d,
  31119. 0x90, 0xd1, 0xa4, 0x4c, 0x34, 0x5d, 0xde, 0xdc,
  31120. 0x39, 0x63, 0x8b, 0x85, 0xfd, 0x02, 0x21, 0xf1,
  31121. 0x12, 0xa3, 0x6d, 0x65, 0x0f, 0x8d, 0xe5, 0xcd,
  31122. 0x70, 0xd5, 0x1d, 0xf8, 0x65, 0x99, 0xfb, 0xe8,
  31123. 0xb5, 0x5a, 0x09, 0x39, 0x9e, 0x09, 0x45, 0x62,
  31124. 0x22, 0x1d, 0xa2, 0x46, 0xbf, 0x75, 0x20, 0xd1,
  31125. 0xe7, 0xb0, 0x06, 0x68, 0xc3, 0x50, 0x48, 0xfc,
  31126. 0xf8, 0x5c, 0x67, 0x69, 0x68, 0x66, 0xb6, 0x81,
  31127. 0x95, 0x91, 0x81, 0x3d, 0xf6, 0x34, 0xd9, 0x4b,
  31128. 0x06, 0x35, 0x17, 0x59, 0x89, 0x18, 0x74, 0x32,
  31129. 0x50, 0xcf, 0x81, 0x16, 0x8e, 0x53, 0x9d, 0x1c,
  31130. 0xad, 0x2d, 0x8e, 0x16, 0x41, 0xda, 0xca, 0xab,
  31131. 0x78, 0x0d, 0xc9, 0x49, 0x61, 0xaa, 0x18, 0xf4,
  31132. 0x56, 0x48, 0x29, 0x8c, 0xe3, 0x9a, 0x7d, 0x58,
  31133. 0xf8, 0x99, 0x72, 0xf1, 0x78, 0xa8, 0x5a, 0x97,
  31134. 0xe3, 0x2a, 0xc6, 0xa9, 0x59, 0xde, 0xcc, 0x62,
  31135. 0xfb, 0xab, 0xc5, 0x9a, 0x0b, 0xc7, 0x16, 0x8f,
  31136. 0x18, 0x20, 0x6e, 0x01, 0x7e, 0x04, 0xef, 0x72,
  31137. 0x83, 0x61, 0xb8, 0x1a, 0x77, 0x0f, 0xd1, 0xa9,
  31138. 0x75, 0xe0, 0x4a, 0x11, 0x69, 0x9d, 0xb6, 0xc9,
  31139. 0x2e, 0xd3, 0xbf, 0xe2, 0x5b, 0x24, 0x77, 0x30,
  31140. 0x85, 0x91, 0xef, 0xa8, 0x93, 0x4e, 0xad, 0x99,
  31141. 0xad, 0xcb, 0x6d, 0x9d, 0x8f, 0xd8, 0x0f, 0xe5,
  31142. 0x41, 0xd9, 0x9e, 0x0b, 0xce, 0x33, 0xd9, 0xbb,
  31143. 0x87, 0x66, 0x2c, 0xa3, 0x0b, 0x68, 0x1b, 0xb0,
  31144. 0x71, 0x30, 0xfa, 0x15, 0x2e, 0xe8, 0xc1, 0x99,
  31145. 0x71, 0x01, 0xcc, 0xdb, 0x6f, 0x9f, 0x8a, 0xfd,
  31146. 0xb4, 0x0f, 0x35, 0xa1, 0x36, 0xf4, 0x3a, 0xc4,
  31147. 0x17, 0x77, 0x43, 0x60, 0x10, 0x18, 0xb4, 0xc2,
  31148. 0xe5, 0xc0, 0x64, 0xd8, 0x38, 0x7c, 0x05, 0x9a,
  31149. 0xfb, 0x2b, 0xb3, 0x9b, 0x9e, 0x34, 0x6b, 0x4b,
  31150. 0xc8, 0x3b, 0x77, 0xe0, 0x6f, 0x08, 0xa1, 0x7b,
  31151. 0x66, 0x69, 0x2f, 0xdb, 0x34, 0x9e, 0x98, 0x90,
  31152. 0x5b, 0x4d, 0x7b, 0xa2, 0x32, 0x8e, 0x64, 0xe6,
  31153. 0x0d, 0x75, 0xc9, 0x96, 0xe3, 0x57, 0xba, 0xad,
  31154. 0x3e, 0x3b, 0x23, 0xfb, 0x9e, 0x7f, 0xc0, 0x3c,
  31155. 0xd5, 0x41, 0x9c, 0xfb, 0xbc, 0xb3, 0x52, 0x49
  31156. #endif
  31157. };
  31158. #endif
  31159. #endif
  31160. static int test_wc_dilithium_public_der_decode(void)
  31161. {
  31162. EXPECT_DECLS;
  31163. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  31164. defined(WOLFSSL_DILITHIUM_PUBLIC_KEY)
  31165. dilithium_key* key;
  31166. word32 idx = 0;
  31167. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  31168. ExpectNotNull(key);
  31169. if (key != NULL) {
  31170. XMEMSET(key, 0, sizeof(*key));
  31171. }
  31172. ExpectIntEQ(wc_dilithium_init(key), 0);
  31173. #ifndef WOLFSSL_NO_ML_DSA_44
  31174. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  31175. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  31176. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  31177. #else
  31178. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  31179. #endif
  31180. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(ml_dsa_public_der, &idx, key,
  31181. (word32)sizeof(ml_dsa_public_der)), 0);
  31182. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  31183. idx = 0;
  31184. #ifndef WOLFSSL_NO_ML_DSA_44
  31185. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44_DRAFT), 0);
  31186. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  31187. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65_DRAFT), 0);
  31188. #else
  31189. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87_DRAFT), 0);
  31190. #endif
  31191. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(dilithium_public_der, &idx, key,
  31192. (word32)sizeof(dilithium_public_der)), 0);
  31193. #endif
  31194. wc_dilithium_free(key);
  31195. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  31196. #endif
  31197. return EXPECT_RESULT();
  31198. }
  31199. static int test_wc_dilithium_der(void)
  31200. {
  31201. EXPECT_DECLS;
  31202. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  31203. !defined(WOLFSSL_DILITHIUM_NO_ASN1) && \
  31204. !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY)
  31205. #define DILITHIUM_MAX_DER_SIZE 8192
  31206. dilithium_key* key;
  31207. WC_RNG rng;
  31208. byte* der = NULL;
  31209. int len;
  31210. int pubLen;
  31211. int pubDerLen;
  31212. int privDerLen;
  31213. int keyDerLen;
  31214. word32 idx;
  31215. #ifndef WOLFSSL_NO_ML_DSA_44
  31216. pubLen = DILITHIUM_LEVEL2_PUB_KEY_SIZE;
  31217. pubDerLen = DILITHIUM_LEVEL2_PUB_KEY_SIZE + 22;
  31218. privDerLen = DILITHIUM_LEVEL2_KEY_SIZE + 28;
  31219. keyDerLen = DILITHIUM_LEVEL2_PUB_KEY_SIZE + DILITHIUM_LEVEL2_KEY_SIZE + 32;
  31220. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  31221. pubLen = DILITHIUM_LEVEL3_PUB_KEY_SIZE;
  31222. pubDerLen = DILITHIUM_LEVEL3_PUB_KEY_SIZE + 22;
  31223. privDerLen = DILITHIUM_LEVEL3_KEY_SIZE + 28;
  31224. keyDerLen = DILITHIUM_LEVEL3_PUB_KEY_SIZE + DILITHIUM_LEVEL3_KEY_SIZE + 32;
  31225. #else
  31226. pubLen = DILITHIUM_LEVEL5_PUB_KEY_SIZE;
  31227. pubDerLen = DILITHIUM_LEVEL5_PUB_KEY_SIZE + 22;
  31228. privDerLen = DILITHIUM_LEVEL5_KEY_SIZE + 28;
  31229. keyDerLen = DILITHIUM_LEVEL5_PUB_KEY_SIZE + DILITHIUM_LEVEL5_KEY_SIZE + 32;
  31230. #endif
  31231. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  31232. ExpectNotNull(key);
  31233. der = (byte*)XMALLOC(DILITHIUM_MAX_DER_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  31234. ExpectNotNull(der);
  31235. if (key != NULL) {
  31236. XMEMSET(key, 0, sizeof(*key));
  31237. }
  31238. XMEMSET(&rng, 0, sizeof(WC_RNG));
  31239. ExpectIntEQ(wc_InitRng(&rng), 0);
  31240. ExpectIntEQ(wc_dilithium_init(key), 0);
  31241. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE,
  31242. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31243. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE,
  31244. 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31245. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE),
  31246. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31247. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der, &idx, key, pubDerLen),
  31248. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31249. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der, &idx, key, privDerLen),
  31250. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31251. #ifndef WOLFSSL_NO_ML_DSA_44
  31252. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  31253. #elif !defined(WOLFSSL_NO_ML_DSA_65)
  31254. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  31255. #else
  31256. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  31257. #endif
  31258. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE,
  31259. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31260. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE,
  31261. 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31262. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(key, der, DILITHIUM_MAX_DER_SIZE),
  31263. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31264. ExpectIntEQ(wc_dilithium_make_key(key, &rng), 0);
  31265. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(NULL, NULL, 0 ,
  31266. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31267. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(NULL, der , 0 ,
  31268. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31269. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(NULL, NULL, DILITHIUM_MAX_DER_SIZE,
  31270. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31271. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(NULL, der , DILITHIUM_MAX_DER_SIZE,
  31272. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31273. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key , der , 0 ,
  31274. 0), WC_NO_ERR_TRACE(BUFFER_E));
  31275. /* Get length only. */
  31276. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key , NULL, 0 ,
  31277. 0), pubLen);
  31278. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key , NULL, DILITHIUM_MAX_DER_SIZE,
  31279. 0), pubLen);
  31280. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key , NULL, 0 ,
  31281. 1), pubDerLen);
  31282. ExpectIntEQ(wc_Dilithium_PublicKeyToDer(key , NULL, DILITHIUM_MAX_DER_SIZE,
  31283. 1), pubDerLen);
  31284. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(NULL, NULL,
  31285. 0 ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31286. ExpectIntGT(wc_Dilithium_PrivateKeyToDer(key , NULL,
  31287. 0 ), 0);
  31288. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(NULL, der ,
  31289. 0 ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31290. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(NULL, NULL,
  31291. DILITHIUM_MAX_DER_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31292. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(NULL, der ,
  31293. DILITHIUM_MAX_DER_SIZE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31294. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(key , der ,
  31295. 0 ), WC_NO_ERR_TRACE(BUFFER_E));
  31296. /* Get length only. */
  31297. ExpectIntEQ(wc_Dilithium_PrivateKeyToDer(key , NULL,
  31298. DILITHIUM_MAX_DER_SIZE), privDerLen);
  31299. ExpectIntEQ(wc_Dilithium_KeyToDer(NULL, NULL, 0 ),
  31300. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31301. ExpectIntGT(wc_Dilithium_KeyToDer(key , NULL, 0 ),
  31302. 0 );
  31303. ExpectIntEQ(wc_Dilithium_KeyToDer(NULL, der , 0 ),
  31304. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31305. ExpectIntEQ(wc_Dilithium_KeyToDer(NULL, NULL, DILITHIUM_MAX_DER_SIZE),
  31306. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31307. ExpectIntEQ(wc_Dilithium_KeyToDer(NULL, der , DILITHIUM_MAX_DER_SIZE),
  31308. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31309. ExpectIntEQ(wc_Dilithium_KeyToDer(key , der , 0 ),
  31310. WC_NO_ERR_TRACE(BUFFER_E));
  31311. /* Get length only. */
  31312. ExpectIntEQ(wc_Dilithium_KeyToDer(key , NULL, DILITHIUM_MAX_DER_SIZE),
  31313. keyDerLen);
  31314. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(NULL, NULL, NULL, 0 ),
  31315. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31316. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der , NULL, NULL, 0 ),
  31317. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31318. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(NULL, &idx, NULL, 0 ),
  31319. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31320. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(NULL, NULL, key , 0 ),
  31321. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31322. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(NULL, NULL, NULL, pubDerLen),
  31323. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31324. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(NULL, &idx, key , pubDerLen),
  31325. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31326. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der , NULL, key , pubDerLen),
  31327. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31328. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der , &idx, NULL, pubDerLen),
  31329. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31330. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der , &idx, key , 0 ),
  31331. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31332. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(NULL, NULL, NULL, 0 ),
  31333. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31334. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der , NULL, NULL, 0 ),
  31335. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31336. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(NULL, &idx, NULL, 0 ),
  31337. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31338. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(NULL, NULL, key , 0 ),
  31339. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31340. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(NULL, NULL, NULL, privDerLen),
  31341. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31342. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(NULL, &idx, key , privDerLen),
  31343. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31344. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der , NULL, key , privDerLen),
  31345. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31346. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der , &idx, NULL, privDerLen),
  31347. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31348. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der , &idx, key , 0 ),
  31349. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  31350. ExpectIntEQ(len = wc_Dilithium_PublicKeyToDer(key, der,
  31351. DILITHIUM_MAX_DER_SIZE, 0), pubLen);
  31352. ExpectIntEQ(wc_dilithium_import_public(der, len, key), 0);
  31353. ExpectIntEQ(len = wc_Dilithium_PublicKeyToDer(key, der,
  31354. DILITHIUM_MAX_DER_SIZE, 1), pubDerLen);
  31355. idx = 0;
  31356. {
  31357. fprintf(stderr, "\n");
  31358. for (int ii = 0; ii < pubDerLen; ii++) {
  31359. if ((ii % 8) == 0) fprintf(stderr, " ");
  31360. fprintf(stderr, "0x%02x,", der[ii]);
  31361. if ((ii % 8) == 7) fprintf(stderr, "\n");
  31362. else fprintf(stderr, " ");
  31363. }
  31364. }
  31365. ExpectIntEQ(wc_Dilithium_PublicKeyDecode(der, &idx, key, len), 0);
  31366. ExpectIntEQ(len = wc_Dilithium_PrivateKeyToDer(key, der,
  31367. DILITHIUM_MAX_DER_SIZE), privDerLen);
  31368. idx = 0;
  31369. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der, &idx, key, len), 0);
  31370. ExpectIntEQ(len = wc_Dilithium_KeyToDer(key, der, DILITHIUM_MAX_DER_SIZE),
  31371. keyDerLen);
  31372. idx = 0;
  31373. ExpectIntEQ(wc_Dilithium_PrivateKeyDecode(der, &idx, key, len), 0);
  31374. wc_dilithium_free(key);
  31375. wc_FreeRng(&rng);
  31376. XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  31377. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  31378. #endif
  31379. return EXPECT_RESULT();
  31380. }
  31381. static int test_wc_dilithium_make_key_from_seed(void)
  31382. {
  31383. EXPECT_DECLS;
  31384. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  31385. !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY)
  31386. dilithium_key* key;
  31387. #ifndef WOLFSSL_NO_ML_DSA_44
  31388. static const byte seed_44[] = {
  31389. 0x93, 0xEF, 0x2E, 0x6E, 0xF1, 0xFB, 0x08, 0x99,
  31390. 0x9D, 0x14, 0x2A, 0xBE, 0x02, 0x95, 0x48, 0x23,
  31391. 0x70, 0xD3, 0xF4, 0x3B, 0xDB, 0x25, 0x4A, 0x78,
  31392. 0xE2, 0xB0, 0xD5, 0x16, 0x8E, 0xCA, 0x06, 0x5F
  31393. };
  31394. static const byte pk_44[] = {
  31395. 0xBC, 0x5F, 0xF8, 0x10, 0xEB, 0x08, 0x90, 0x48,
  31396. 0xB8, 0xAB, 0x30, 0x20, 0xA7, 0xBD, 0x3B, 0x16,
  31397. 0xC0, 0xE0, 0xCA, 0x3D, 0x6B, 0x97, 0xE4, 0x64,
  31398. 0x6C, 0x2C, 0xCA, 0xE0, 0xBB, 0xF1, 0x9E, 0xF7,
  31399. 0x23, 0x0A, 0x19, 0xD7, 0x5A, 0xDB, 0xDE, 0xD5,
  31400. 0x2D, 0xB8, 0x55, 0xE2, 0x52, 0xA7, 0x19, 0xFC,
  31401. 0xBD, 0x14, 0x7B, 0xA6, 0x7B, 0x2F, 0xAD, 0x14,
  31402. 0xED, 0x0E, 0x68, 0xFD, 0xFE, 0x8C, 0x65, 0xBA,
  31403. 0xDE, 0xAC, 0xB0, 0x91, 0x11, 0x93, 0xAD, 0xFA,
  31404. 0x87, 0x94, 0xD7, 0x8F, 0x8E, 0x3D, 0x66, 0x2A,
  31405. 0x1C, 0x49, 0xDA, 0x81, 0x9F, 0xD9, 0x59, 0xE7,
  31406. 0xF0, 0x78, 0xF2, 0x03, 0xC4, 0x56, 0xF8, 0xB6,
  31407. 0xE7, 0xC9, 0x41, 0x58, 0x98, 0xE5, 0x41, 0xC7,
  31408. 0x30, 0x32, 0xDB, 0xD6, 0x19, 0xEA, 0xF6, 0x0F,
  31409. 0x8D, 0x64, 0xF8, 0x68, 0x3D, 0xA9, 0x9E, 0xCA,
  31410. 0x51, 0x22, 0x0B, 0x0A, 0xCA, 0x28, 0x46, 0x40,
  31411. 0x99, 0xF5, 0x47, 0xC0, 0x27, 0x77, 0xBD, 0x37,
  31412. 0xD8, 0x4A, 0x59, 0xBD, 0x37, 0xED, 0x7A, 0x8A,
  31413. 0x92, 0x63, 0x3C, 0x75, 0xD0, 0x7C, 0x79, 0x3F,
  31414. 0xE7, 0x25, 0x2B, 0x58, 0x4A, 0xBF, 0x6A, 0x15,
  31415. 0xEE, 0x14, 0x50, 0x7E, 0x5E, 0x19, 0x3F, 0x89,
  31416. 0x86, 0x4D, 0x09, 0xAC, 0x87, 0x27, 0xA6, 0xD0,
  31417. 0x42, 0x1F, 0x0C, 0x19, 0xF0, 0xE2, 0xFB, 0xFC,
  31418. 0x21, 0x3D, 0x3F, 0xBD, 0x70, 0xF4, 0xF9, 0x76,
  31419. 0x2C, 0xEC, 0xFF, 0x23, 0x1E, 0x9C, 0x8A, 0x76,
  31420. 0x28, 0xD3, 0xF8, 0xB0, 0x85, 0x7B, 0x03, 0x2D,
  31421. 0x32, 0xDE, 0x62, 0xFF, 0x8E, 0xCB, 0xF4, 0x00,
  31422. 0x82, 0x89, 0xBF, 0x34, 0x40, 0x36, 0x65, 0xF8,
  31423. 0x1A, 0x08, 0x1A, 0xD5, 0xA8, 0x5A, 0x28, 0x2F,
  31424. 0x99, 0xBA, 0xB9, 0xE5, 0x38, 0x5A, 0xFB, 0xCC,
  31425. 0xCF, 0x44, 0xB7, 0x4C, 0x01, 0x96, 0xC7, 0x54,
  31426. 0x55, 0x27, 0xEC, 0x30, 0x26, 0xDA, 0x12, 0x80,
  31427. 0xC4, 0xEB, 0x37, 0xD0, 0x9C, 0xFE, 0x3E, 0xC4,
  31428. 0xB4, 0x91, 0x0B, 0x62, 0xEB, 0x98, 0x15, 0xA4,
  31429. 0x25, 0xC6, 0x59, 0x0F, 0xC4, 0xAD, 0x3F, 0xBB,
  31430. 0x22, 0x57, 0x52, 0xCC, 0x1F, 0xC5, 0x69, 0x3F,
  31431. 0x18, 0x7E, 0x7D, 0xEC, 0x4E, 0xEF, 0xBE, 0xB6,
  31432. 0xB9, 0x1B, 0xD9, 0x1C, 0x5E, 0x2E, 0xA6, 0xA9,
  31433. 0x1D, 0x14, 0xD0, 0x97, 0xBE, 0x20, 0x3F, 0xBA,
  31434. 0x0B, 0xF9, 0x37, 0xC9, 0x75, 0x07, 0xDC, 0x00,
  31435. 0x7C, 0x4C, 0xAA, 0x9B, 0x07, 0x85, 0x89, 0x29,
  31436. 0x66, 0xFF, 0x15, 0x90, 0x09, 0x24, 0xE5, 0x79,
  31437. 0xD4, 0xFB, 0xA0, 0x2B, 0xDA, 0x87, 0x55, 0x5F,
  31438. 0x07, 0x3D, 0xAE, 0x00, 0x51, 0x3E, 0x70, 0x80,
  31439. 0x9A, 0xBB, 0xC7, 0x11, 0xFB, 0xA2, 0xE7, 0x64,
  31440. 0x95, 0x77, 0xC4, 0x2A, 0xFD, 0xC2, 0x4B, 0xF7,
  31441. 0x41, 0x3E, 0x51, 0x26, 0x8A, 0xD6, 0xDB, 0x61,
  31442. 0x13, 0xB7, 0xD9, 0x19, 0x1A, 0xF9, 0xD0, 0x61,
  31443. 0xDB, 0xDE, 0xD5, 0xD6, 0x30, 0x87, 0x76, 0x50,
  31444. 0xC1, 0x24, 0xF1, 0x1B, 0xC4, 0xBD, 0xC3, 0xFD,
  31445. 0xC6, 0xA9, 0x00, 0xF6, 0x31, 0x26, 0xF9, 0x21,
  31446. 0xE8, 0x38, 0xAD, 0x0C, 0x22, 0x75, 0xA3, 0x38,
  31447. 0x9A, 0x39, 0xBD, 0x99, 0xA1, 0x34, 0x50, 0x45,
  31448. 0x50, 0x10, 0x1C, 0xD3, 0xE9, 0x5E, 0x6D, 0x14,
  31449. 0x96, 0xBE, 0x7D, 0xE6, 0x62, 0x7D, 0xF4, 0xFD,
  31450. 0x6C, 0x28, 0xBB, 0xF4, 0x0B, 0x30, 0xEF, 0xA9,
  31451. 0xB5, 0xC3, 0xD5, 0xC8, 0x5A, 0xB1, 0x4A, 0x65,
  31452. 0xC0, 0x2D, 0x6D, 0x47, 0x81, 0xFF, 0x13, 0xD3,
  31453. 0x28, 0x60, 0x85, 0x54, 0xB6, 0xD1, 0x5E, 0xD9,
  31454. 0x12, 0x89, 0xA6, 0xD5, 0x5A, 0xAC, 0x0C, 0x38,
  31455. 0xE3, 0x77, 0x06, 0xF7, 0x35, 0x5E, 0x9A, 0x4F,
  31456. 0xDA, 0x61, 0x5B, 0x87, 0x59, 0x26, 0xBF, 0xE5,
  31457. 0xA5, 0x9D, 0x9E, 0xF2, 0x73, 0xBF, 0x94, 0xA0,
  31458. 0x7C, 0xFA, 0x57, 0x31, 0x78, 0xF0, 0xE0, 0x04,
  31459. 0xB6, 0xE1, 0xEF, 0x0A, 0x83, 0x49, 0xE9, 0xBC,
  31460. 0xC0, 0x19, 0x81, 0xF2, 0x46, 0x0F, 0x0A, 0x27,
  31461. 0x43, 0xC2, 0x8D, 0x1E, 0x13, 0x8F, 0xFB, 0x76,
  31462. 0x5E, 0x7E, 0x33, 0x97, 0xB7, 0x91, 0x33, 0x35,
  31463. 0xD4, 0x02, 0xFE, 0x91, 0x80, 0x6A, 0xA8, 0xFC,
  31464. 0x81, 0x92, 0x53, 0xAF, 0x32, 0x69, 0x2F, 0xA6,
  31465. 0x51, 0xE8, 0x67, 0xF5, 0x90, 0x7E, 0xF4, 0x6F,
  31466. 0x00, 0x62, 0x5A, 0x03, 0x0E, 0xC9, 0x04, 0xED,
  31467. 0xAB, 0x21, 0x42, 0x6D, 0x59, 0x11, 0x9D, 0x2C,
  31468. 0xAA, 0x43, 0xBD, 0x93, 0x5D, 0xEC, 0x0A, 0x55,
  31469. 0x0C, 0x61, 0xEE, 0x4B, 0x27, 0x9C, 0x1C, 0xA3,
  31470. 0xA7, 0x9C, 0x79, 0xA6, 0x6E, 0x3F, 0x2D, 0x2F,
  31471. 0xAD, 0xB0, 0x0F, 0x59, 0xA3, 0xA4, 0x38, 0xAA,
  31472. 0x44, 0x57, 0x01, 0x06, 0x07, 0x30, 0x17, 0xFA,
  31473. 0x1C, 0x87, 0x57, 0x50, 0x01, 0x09, 0x72, 0x0D,
  31474. 0x12, 0x5B, 0xBA, 0x23, 0x1A, 0x0C, 0x36, 0x35,
  31475. 0x0C, 0x78, 0x08, 0x6D, 0xFD, 0xC8, 0xD6, 0x13,
  31476. 0xAE, 0xCA, 0x88, 0xC4, 0xCC, 0xAE, 0xB4, 0xA4,
  31477. 0x4D, 0x13, 0xAD, 0xB3, 0xC7, 0x17, 0xD6, 0x5C,
  31478. 0x82, 0xA3, 0x51, 0xB9, 0xB6, 0xEA, 0xBF, 0x6A,
  31479. 0x10, 0xF4, 0xB4, 0xE9, 0x62, 0x3E, 0x3A, 0x95,
  31480. 0xB4, 0xD4, 0x0A, 0x12, 0xA8, 0x18, 0xAC, 0x6B,
  31481. 0x38, 0x22, 0xDB, 0x82, 0xFB, 0x05, 0xDC, 0x42,
  31482. 0x02, 0x64, 0x8B, 0x44, 0x54, 0x68, 0x9A, 0xEB,
  31483. 0x69, 0xEA, 0x32, 0x5F, 0x03, 0xE3, 0x5D, 0xEF,
  31484. 0xA5, 0x47, 0x08, 0x48, 0x14, 0x20, 0xC6, 0xD6,
  31485. 0x97, 0xBB, 0x91, 0x2F, 0xCA, 0x0D, 0x3F, 0x19,
  31486. 0x2E, 0xF2, 0x97, 0xDF, 0xE7, 0x7F, 0xF3, 0x6B,
  31487. 0x21, 0x03, 0xF1, 0xAD, 0x1A, 0xEE, 0xCE, 0xD1,
  31488. 0xC8, 0x14, 0xC2, 0xCD, 0x7E, 0xF1, 0x6B, 0xCE,
  31489. 0x47, 0x6A, 0xD0, 0x4F, 0x94, 0x1A, 0xFC, 0x79,
  31490. 0xE3, 0x29, 0x54, 0x74, 0xA4, 0x10, 0x62, 0x51,
  31491. 0x8C, 0x00, 0x37, 0x86, 0x09, 0x34, 0xF0, 0xE5,
  31492. 0xE6, 0x52, 0xF7, 0x27, 0x49, 0xA6, 0x98, 0x63,
  31493. 0x2A, 0x09, 0x91, 0xF6, 0x13, 0xF5, 0xCB, 0x96,
  31494. 0xCA, 0x11, 0x78, 0xF9, 0x74, 0xF2, 0xC4, 0xAA,
  31495. 0x0C, 0xE6, 0x3D, 0xC2, 0x4E, 0x36, 0x4C, 0x92,
  31496. 0xA6, 0x43, 0xB9, 0x0A, 0x5F, 0x85, 0xA6, 0x2F,
  31497. 0xD4, 0xD8, 0xD2, 0xB1, 0x93, 0xD2, 0x9B, 0x18,
  31498. 0xBE, 0xDE, 0x26, 0x53, 0xFC, 0x5D, 0x3F, 0x24,
  31499. 0xF5, 0xB2, 0xC0, 0x18, 0xDB, 0xBC, 0xB6, 0xEF,
  31500. 0x00, 0xF3, 0x05, 0xBF, 0x93, 0x66, 0x6B, 0xD4,
  31501. 0x7F, 0xEA, 0x91, 0x93, 0xBC, 0x23, 0x3D, 0xB3,
  31502. 0x91, 0x21, 0x44, 0x2E, 0x93, 0x8D, 0xA5, 0xDD,
  31503. 0x07, 0xEE, 0x6E, 0x87, 0x9C, 0x5B, 0x9D, 0xFF,
  31504. 0x41, 0xEC, 0xEE, 0x5E, 0x05, 0x89, 0xAE, 0x61,
  31505. 0x75, 0xFF, 0x5E, 0xC6, 0xF6, 0xD2, 0x62, 0x9F,
  31506. 0x56, 0xB1, 0x8B, 0x4D, 0xE6, 0x6F, 0xCB, 0x13,
  31507. 0xDF, 0x04, 0x00, 0xA7, 0x97, 0xC9, 0x22, 0x70,
  31508. 0xF6, 0x9B, 0xDE, 0xBD, 0xDC, 0xB8, 0x8C, 0x42,
  31509. 0x48, 0x91, 0x9B, 0x56, 0xCD, 0xA7, 0x0B, 0x8A,
  31510. 0xC4, 0xF9, 0x42, 0x9C, 0x29, 0x2D, 0xA9, 0x4D,
  31511. 0x64, 0x78, 0x28, 0x07, 0x64, 0xFE, 0x23, 0x86,
  31512. 0xFC, 0x38, 0xCB, 0x09, 0x31, 0x45, 0x88, 0x39,
  31513. 0xEF, 0x4E, 0x7D, 0xE8, 0xF0, 0x68, 0x9D, 0x99,
  31514. 0x80, 0x59, 0x88, 0xC7, 0xF9, 0x61, 0x11, 0x85,
  31515. 0x2C, 0x89, 0x29, 0xE5, 0xA5, 0x40, 0xD3, 0xB7,
  31516. 0x8D, 0x71, 0x2D, 0xEC, 0xC3, 0x96, 0xFE, 0xF3,
  31517. 0xEC, 0x34, 0x40, 0x21, 0x84, 0xE4, 0xFD, 0x29,
  31518. 0xF3, 0x63, 0xEA, 0x80, 0xF6, 0xFC, 0x50, 0xBA,
  31519. 0x9A, 0x11, 0x35, 0x1A, 0xCE, 0xEA, 0x8F, 0xE6,
  31520. 0x8D, 0x54, 0x1E, 0x1A, 0xA5, 0x84, 0x8D, 0x9F,
  31521. 0x6E, 0x61, 0xDF, 0xB6, 0x2B, 0x2F, 0x23, 0xBC,
  31522. 0x50, 0x81, 0xE8, 0x2F, 0x76, 0x22, 0x6E, 0x03,
  31523. 0x28, 0x49, 0x82, 0xEC, 0x48, 0x48, 0x12, 0x09,
  31524. 0xB1, 0xA7, 0xD4, 0xC8, 0x79, 0x7E, 0x44, 0xBF,
  31525. 0xA8, 0x70, 0xB2, 0x20, 0x04, 0xDB, 0x74, 0xBD,
  31526. 0x7D, 0x47, 0x8D, 0x5B, 0x36, 0x14, 0xD2, 0xB1,
  31527. 0xDA, 0x75, 0x02, 0xB3, 0x98, 0xEB, 0x9D, 0xA8,
  31528. 0x0D, 0x06, 0x46, 0x1E, 0x90, 0xE0, 0x30, 0x60,
  31529. 0x44, 0x6A, 0xB4, 0xA8, 0x23, 0x84, 0x32, 0xBF,
  31530. 0xAF, 0x75, 0x2F, 0x39, 0x17, 0x91, 0x21, 0x4F,
  31531. 0x1E, 0x6B, 0x63, 0x59, 0x0D, 0x53, 0x60, 0x60,
  31532. 0xD1, 0xC2, 0x45, 0x30, 0x7B, 0xC5, 0xC1, 0xBA,
  31533. 0xC4, 0xAA, 0xA0, 0x99, 0xD3, 0x6B, 0xB6, 0xDC,
  31534. 0xBC, 0x97, 0x3C, 0xF2, 0xE6, 0x9F, 0x27, 0x34,
  31535. 0xD0, 0xF2, 0x9A, 0xEE, 0xC4, 0x56, 0x7B, 0x99,
  31536. 0xA1, 0x6B, 0xC1, 0x7C, 0x6C, 0xDD, 0xAC, 0xEF,
  31537. 0xE4, 0x99, 0x27, 0xFB, 0x14, 0xE7, 0xD9, 0x8D,
  31538. 0xD4, 0x26, 0x35, 0x19, 0x46, 0x9C, 0xCA, 0x3D,
  31539. 0xB4, 0x67, 0x9A, 0x68, 0xCE, 0xED, 0xA9, 0x55,
  31540. 0x59, 0x22, 0x10, 0xFC, 0x49, 0xAA, 0x5F, 0xBE,
  31541. 0x93, 0x4C, 0xC7, 0x3D, 0x84, 0xE4, 0xBA, 0x54,
  31542. 0x78, 0x00, 0x2D, 0x68, 0x90, 0x98, 0x90, 0x68,
  31543. 0xEF, 0x8F, 0xC9, 0x8C, 0x25, 0x32, 0xB8, 0x3B,
  31544. 0xF3, 0xCB, 0x9E, 0xF0, 0x28, 0x93, 0xC2, 0x15,
  31545. 0x24, 0x26, 0xB9, 0xD1, 0xA9, 0x47, 0x34, 0xDF,
  31546. 0xB4, 0xF9, 0x11, 0x35, 0x14, 0x3C, 0x9E, 0xED,
  31547. 0x18, 0xFD, 0x51, 0xAE, 0x87, 0x5D, 0x07, 0xA2,
  31548. 0x37, 0x75, 0x60, 0x6A, 0x73, 0x4F, 0xBA, 0x98,
  31549. 0xC0, 0x63, 0xB4, 0xA1, 0x62, 0x2E, 0x7F, 0xF2,
  31550. 0x1A, 0xA7, 0xE6, 0x52, 0xA3, 0xD6, 0xC1, 0x9F,
  31551. 0xE0, 0xDC, 0x67, 0x61, 0xB7, 0xD3, 0x53, 0x02,
  31552. 0xBF, 0x21, 0x4D, 0x30, 0x79, 0xF7, 0x60, 0x51,
  31553. 0x08, 0x2A, 0x87, 0x59, 0x29, 0x92, 0x0D, 0xC3,
  31554. 0xB3, 0xCB, 0x43, 0x21, 0x1A, 0x23, 0xA4, 0x3A,
  31555. 0x50, 0x33, 0x2F, 0xAF, 0x1A, 0xC2, 0x19, 0x1E,
  31556. 0x71, 0x71, 0x25, 0xF6, 0x3E, 0x25, 0x86, 0xC4,
  31557. 0xD8, 0x6D, 0xCA, 0x6B, 0xCD, 0x3D, 0x03, 0x8F,
  31558. 0x9D, 0x3A, 0x7B, 0x66, 0xCB, 0xC7, 0xDF, 0x34
  31559. };
  31560. static const byte sk_44[] = {
  31561. 0xBC, 0x5F, 0xF8, 0x10, 0xEB, 0x08, 0x90, 0x48,
  31562. 0xB8, 0xAB, 0x30, 0x20, 0xA7, 0xBD, 0x3B, 0x16,
  31563. 0xC0, 0xE0, 0xCA, 0x3D, 0x6B, 0x97, 0xE4, 0x64,
  31564. 0x6C, 0x2C, 0xCA, 0xE0, 0xBB, 0xF1, 0x9E, 0xF7,
  31565. 0xBA, 0x2B, 0x57, 0xC4, 0x46, 0x55, 0x6E, 0xE2,
  31566. 0xB7, 0x2C, 0x78, 0xB9, 0x6B, 0xB7, 0xA8, 0x50,
  31567. 0x3D, 0xE4, 0x0A, 0xFB, 0x54, 0x18, 0x4E, 0x3B,
  31568. 0x54, 0x63, 0xC2, 0x1A, 0xF7, 0x48, 0x53, 0x23,
  31569. 0xDF, 0x98, 0xF0, 0x16, 0x0A, 0xE5, 0xD1, 0x37,
  31570. 0x51, 0x27, 0x25, 0xF8, 0x9D, 0x56, 0x3B, 0xC9,
  31571. 0xA1, 0x89, 0xD3, 0x1D, 0x20, 0xB3, 0xB3, 0xC8,
  31572. 0xFF, 0xAA, 0xF5, 0xE4, 0x86, 0xE7, 0x90, 0x51,
  31573. 0xF6, 0xF3, 0x60, 0x5C, 0xCA, 0x25, 0x69, 0xFD,
  31574. 0xB4, 0x6B, 0x33, 0x18, 0xD2, 0x38, 0x42, 0xCE,
  31575. 0x40, 0xD6, 0x43, 0x86, 0x13, 0xF6, 0x8B, 0x45,
  31576. 0x5B, 0x0D, 0x3B, 0xCA, 0x0E, 0x05, 0x0D, 0x4D,
  31577. 0x11, 0x99, 0x88, 0xA2, 0xC4, 0x80, 0x1B, 0x90,
  31578. 0x84, 0xE0, 0xB0, 0x48, 0xC9, 0x28, 0x09, 0x22,
  31579. 0x30, 0x90, 0x24, 0x06, 0x49, 0x98, 0x40, 0x65,
  31580. 0x5A, 0x26, 0x8A, 0xDA, 0x32, 0x90, 0xDA, 0x48,
  31581. 0x08, 0x22, 0x81, 0x90, 0xC8, 0x14, 0x61, 0xDC,
  31582. 0x16, 0x6A, 0x21, 0x47, 0x8E, 0x08, 0xB2, 0x21,
  31583. 0xE3, 0x08, 0x68, 0x1A, 0x02, 0x44, 0x14, 0xC6,
  31584. 0x65, 0xE1, 0x98, 0x71, 0x90, 0xC6, 0x69, 0x0C,
  31585. 0x15, 0x44, 0xC9, 0xA0, 0x11, 0xCC, 0x34, 0x71,
  31586. 0x83, 0x40, 0x45, 0x00, 0x12, 0x4D, 0x91, 0x08,
  31587. 0x00, 0x83, 0x36, 0x84, 0x12, 0x85, 0x4C, 0xCC,
  31588. 0x00, 0x41, 0x09, 0x90, 0x70, 0x18, 0x95, 0x00,
  31589. 0xA2, 0xB2, 0x85, 0x94, 0x26, 0x41, 0x0B, 0x00,
  31590. 0x41, 0x0A, 0xB9, 0x80, 0xC0, 0xC6, 0x10, 0x0C,
  31591. 0x33, 0x29, 0xA3, 0xA6, 0x28, 0x1C, 0x26, 0x10,
  31592. 0x1A, 0x37, 0x49, 0x13, 0x35, 0x8A, 0x0B, 0x29,
  31593. 0x2E, 0x82, 0xA2, 0x70, 0x8B, 0x38, 0x49, 0x94,
  31594. 0x04, 0x80, 0x9B, 0x26, 0x10, 0xA4, 0x80, 0x30,
  31595. 0x04, 0x37, 0x0C, 0x48, 0xB2, 0x60, 0x04, 0x17,
  31596. 0x2E, 0x19, 0x49, 0x64, 0xC8, 0xC4, 0x64, 0x1A,
  31597. 0x96, 0x60, 0x10, 0x83, 0x6D, 0x20, 0x38, 0x22,
  31598. 0x49, 0x06, 0x08, 0x1B, 0xB7, 0x20, 0x01, 0x48,
  31599. 0x4D, 0xE1, 0x10, 0x49, 0x08, 0x38, 0x44, 0x4C,
  31600. 0x16, 0x8E, 0x04, 0xB2, 0x2C, 0x09, 0x91, 0x50,
  31601. 0x83, 0x36, 0x06, 0x5C, 0x02, 0x8C, 0x8A, 0x38,
  31602. 0x05, 0x1A, 0xB5, 0x81, 0x82, 0xC0, 0x09, 0x51,
  31603. 0x12, 0x72, 0x22, 0x10, 0x0D, 0x04, 0x08, 0x2A,
  31604. 0xA4, 0x84, 0x10, 0x58, 0x08, 0x52, 0x08, 0x26,
  31605. 0x0A, 0x02, 0xB6, 0x2D, 0x8A, 0x12, 0x0E, 0x14,
  31606. 0x22, 0x10, 0x48, 0x44, 0x0A, 0x14, 0x23, 0x91,
  31607. 0x50, 0x40, 0x90, 0x0A, 0x27, 0x92, 0xA4, 0xB0,
  31608. 0x60, 0x08, 0x84, 0x11, 0xC4, 0x40, 0x22, 0x63,
  31609. 0x46, 0x2A, 0xDA, 0xA6, 0x90, 0xC1, 0xB2, 0x30,
  31610. 0x50, 0x10, 0x00, 0xA0, 0xB4, 0x6C, 0x53, 0xB4,
  31611. 0x50, 0x13, 0x05, 0x8D, 0x02, 0x31, 0x0E, 0x08,
  31612. 0x20, 0x10, 0x91, 0xC8, 0x4C, 0x22, 0xA7, 0x50,
  31613. 0xC2, 0xA6, 0x70, 0x92, 0x46, 0x41, 0x63, 0x16,
  31614. 0x8C, 0x84, 0x00, 0x11, 0x0B, 0x81, 0x90, 0x13,
  31615. 0x83, 0x71, 0x21, 0x85, 0x30, 0x1B, 0x18, 0x46,
  31616. 0xA3, 0x10, 0x84, 0x14, 0x43, 0x40, 0x80, 0x98,
  31617. 0x25, 0x0C, 0x27, 0x2C, 0x94, 0x42, 0x41, 0xA2,
  31618. 0x88, 0x45, 0x02, 0x13, 0x05, 0x44, 0xB6, 0x44,
  31619. 0x52, 0x22, 0x92, 0xD0, 0x80, 0x50, 0x4B, 0xA6,
  31620. 0x04, 0x84, 0x36, 0x70, 0x09, 0xB2, 0x4D, 0x19,
  31621. 0xA8, 0x84, 0x24, 0x93, 0x49, 0x94, 0xA2, 0x80,
  31622. 0x49, 0xB4, 0x48, 0x91, 0x28, 0x64, 0xA1, 0xC8,
  31623. 0x65, 0x4B, 0x82, 0x85, 0x93, 0x30, 0x06, 0x63,
  31624. 0x12, 0x66, 0x10, 0x37, 0x01, 0x4A, 0x40, 0x80,
  31625. 0x18, 0x18, 0x90, 0x44, 0xC4, 0x0D, 0x4B, 0x28,
  31626. 0x81, 0xA2, 0x06, 0x40, 0xD4, 0x30, 0x2C, 0x1B,
  31627. 0x96, 0x4C, 0xE1, 0xB2, 0x60, 0x44, 0x28, 0x41,
  31628. 0xD8, 0x30, 0x65, 0x24, 0x09, 0x04, 0x64, 0x00,
  31629. 0x89, 0x63, 0xC2, 0x24, 0xC0, 0x00, 0x49, 0x92,
  31630. 0x16, 0x52, 0x23, 0xC1, 0x29, 0x42, 0x26, 0x91,
  31631. 0xD0, 0x38, 0x31, 0x83, 0x28, 0x28, 0x4C, 0x28,
  31632. 0x61, 0x1A, 0xB2, 0x88, 0x80, 0x26, 0x2D, 0x0C,
  31633. 0x19, 0x52, 0x5B, 0x22, 0x60, 0x8A, 0x92, 0x28,
  31634. 0xA2, 0x18, 0x90, 0xD9, 0x42, 0x52, 0xCB, 0x40,
  31635. 0x8E, 0x9B, 0x16, 0x06, 0x4B, 0xC8, 0x05, 0xE0,
  31636. 0x06, 0x6C, 0x49, 0xC2, 0x25, 0xD4, 0x22, 0x69,
  31637. 0x14, 0x11, 0x69, 0x1C, 0x34, 0x90, 0x0C, 0x85,
  31638. 0x8D, 0x1C, 0x84, 0x49, 0x63, 0x10, 0x85, 0x08,
  31639. 0x34, 0x89, 0x58, 0x16, 0x66, 0xA0, 0x38, 0x68,
  31640. 0x0B, 0xA2, 0x50, 0xE0, 0x84, 0x61, 0xC1, 0x26,
  31641. 0x6E, 0xC9, 0x14, 0x6A, 0xC0, 0xC0, 0x31, 0x84,
  31642. 0x18, 0x2E, 0xDC, 0x16, 0x52, 0x14, 0x18, 0x91,
  31643. 0x0A, 0x39, 0x2C, 0x83, 0xA6, 0x8D, 0x12, 0x29,
  31644. 0x62, 0x92, 0xA6, 0x60, 0x08, 0xA5, 0x10, 0xD9,
  31645. 0xC8, 0x4D, 0x24, 0x48, 0x24, 0x83, 0x98, 0x24,
  31646. 0x1A, 0x44, 0x42, 0x08, 0x08, 0x48, 0xC8, 0x96,
  31647. 0x2D, 0xA1, 0x10, 0x20, 0x60, 0x24, 0x51, 0x9C,
  31648. 0x30, 0x11, 0xDB, 0xC8, 0x04, 0x11, 0x22, 0x51,
  31649. 0x18, 0x04, 0x68, 0xE2, 0x24, 0x4E, 0x10, 0xC4,
  31650. 0x0D, 0x18, 0x37, 0x29, 0x11, 0xB7, 0x84, 0x43,
  31651. 0x84, 0x8D, 0x54, 0x40, 0x70, 0x64, 0x80, 0x70,
  31652. 0x21, 0xB0, 0x4D, 0x00, 0x26, 0x62, 0x00, 0x45,
  31653. 0x25, 0x1B, 0x83, 0x84, 0x84, 0x80, 0x70, 0x19,
  31654. 0xB0, 0x04, 0x0A, 0xC9, 0x28, 0xCA, 0x80, 0x05,
  31655. 0x1B, 0x21, 0x4E, 0xD4, 0xB0, 0x49, 0x8C, 0x96,
  31656. 0x6C, 0xD0, 0x96, 0x25, 0x48, 0x32, 0x72, 0x54,
  31657. 0x12, 0x05, 0x09, 0x98, 0x8C, 0x8A, 0x32, 0x6D,
  31658. 0xC0, 0x04, 0x31, 0x63, 0xC8, 0x61, 0xC8, 0xC2,
  31659. 0x68, 0x9B, 0xB4, 0x8C, 0x5B, 0xC0, 0x2D, 0xC3,
  31660. 0xA8, 0x8D, 0x1B, 0x16, 0x6C, 0xD8, 0x96, 0x41,
  31661. 0x98, 0x34, 0x02, 0x44, 0x14, 0x2C, 0xD3, 0x86,
  31662. 0x44, 0x0A, 0x18, 0x8A, 0x1A, 0x46, 0x92, 0x1A,
  31663. 0xB7, 0x08, 0x4C, 0x34, 0x24, 0x21, 0x91, 0x0D,
  31664. 0x9A, 0x96, 0x2D, 0xCB, 0x24, 0x22, 0x92, 0x86,
  31665. 0x08, 0x98, 0xA0, 0x50, 0xDA, 0x44, 0x6A, 0x19,
  31666. 0xB1, 0x05, 0x8B, 0x20, 0x6E, 0x24, 0xC4, 0x81,
  31667. 0xC9, 0x98, 0x40, 0x22, 0x19, 0x32, 0x11, 0x05,
  31668. 0x69, 0xD3, 0x94, 0x91, 0x08, 0xA7, 0x71, 0xDB,
  31669. 0xC0, 0x70, 0x02, 0xB8, 0x28, 0x83, 0xB4, 0x49,
  31670. 0xA0, 0x44, 0x8A, 0x0B, 0xB4, 0x10, 0x61, 0x02,
  31671. 0x48, 0x1C, 0xA6, 0x11, 0xE3, 0x20, 0x66, 0x40,
  31672. 0xB4, 0x70, 0x03, 0xB6, 0x04, 0x60, 0x48, 0x21,
  31673. 0x5B, 0x21, 0x83, 0x39, 0x88, 0xDB, 0x67, 0x4A,
  31674. 0x61, 0xE7, 0xC2, 0x08, 0xDE, 0xBE, 0x8D, 0xAE,
  31675. 0x41, 0x19, 0xAF, 0xB0, 0x26, 0x61, 0xA6, 0x9A,
  31676. 0xBC, 0x8B, 0xDD, 0x24, 0x5B, 0x5D, 0x0F, 0xB1,
  31677. 0xA2, 0x67, 0x01, 0xC9, 0xB9, 0xC9, 0xA8, 0xF7,
  31678. 0xD9, 0xFC, 0xD4, 0xC2, 0x87, 0xFF, 0x3D, 0x60,
  31679. 0x8C, 0xF2, 0x58, 0x28, 0x2A, 0x1E, 0xB2, 0x9F,
  31680. 0x93, 0x04, 0xE8, 0x9C, 0x14, 0xF3, 0xE1, 0xCE,
  31681. 0x56, 0x12, 0x89, 0x1C, 0x60, 0x29, 0x34, 0x52,
  31682. 0x60, 0x06, 0xC9, 0x9B, 0x4A, 0xA2, 0x39, 0x9B,
  31683. 0xF4, 0x94, 0xBC, 0xF8, 0xDF, 0x61, 0xD6, 0xDF,
  31684. 0x4C, 0x69, 0xBC, 0x93, 0xE0, 0x2D, 0x49, 0x95,
  31685. 0xE2, 0xF7, 0x6E, 0x9F, 0xDA, 0x4E, 0xF6, 0x7E,
  31686. 0xB7, 0x25, 0x6C, 0xA8, 0x9A, 0x3F, 0x38, 0xFE,
  31687. 0xB2, 0xE9, 0xDF, 0x6A, 0x01, 0x0D, 0xC1, 0xC1,
  31688. 0x50, 0x02, 0xFB, 0xD4, 0x56, 0xFA, 0xE8, 0x84,
  31689. 0x82, 0x1A, 0x34, 0x16, 0x6B, 0x06, 0x58, 0xA2,
  31690. 0x41, 0x25, 0x95, 0x71, 0x8E, 0x14, 0x9B, 0xBC,
  31691. 0x6E, 0x22, 0x0A, 0xEE, 0x26, 0x8D, 0x4D, 0x82,
  31692. 0x18, 0xC2, 0x5F, 0x6A, 0x95, 0x7D, 0xE5, 0xB2,
  31693. 0x6C, 0xEA, 0x7B, 0x14, 0xCB, 0x32, 0x0D, 0x89,
  31694. 0xE1, 0x69, 0x9A, 0xD9, 0xF2, 0xB3, 0x89, 0xC6,
  31695. 0x7E, 0xF9, 0x33, 0x86, 0xA2, 0xC6, 0x5F, 0x2C,
  31696. 0x32, 0x23, 0x33, 0x67, 0xD7, 0x6A, 0xE4, 0xAB,
  31697. 0x2A, 0xBB, 0xD4, 0x22, 0xE9, 0x8E, 0x49, 0x3D,
  31698. 0xCC, 0x3C, 0xC5, 0xDA, 0xF6, 0x89, 0xB6, 0x5C,
  31699. 0xC4, 0xBC, 0x3F, 0xA5, 0x1C, 0x9C, 0x59, 0xEE,
  31700. 0xAF, 0x07, 0x55, 0x17, 0x0C, 0x24, 0x95, 0x80,
  31701. 0x4D, 0x02, 0xA6, 0x07, 0xC5, 0xBF, 0x88, 0x7C,
  31702. 0xD8, 0x6A, 0x03, 0x89, 0xF2, 0x8F, 0xC9, 0x72,
  31703. 0x5E, 0xF4, 0x60, 0x03, 0xF1, 0x3B, 0x01, 0x87,
  31704. 0x68, 0x4B, 0xEA, 0xB1, 0xF2, 0x4A, 0x29, 0xF5,
  31705. 0x31, 0x96, 0x01, 0xF3, 0x09, 0xC9, 0x1D, 0x2A,
  31706. 0x33, 0x3D, 0x1B, 0x88, 0xDF, 0x20, 0x5A, 0x51,
  31707. 0x20, 0xC4, 0xCF, 0xDC, 0x22, 0x38, 0x12, 0x4E,
  31708. 0x4E, 0x2B, 0x47, 0xD0, 0xB5, 0xE6, 0x6A, 0x65,
  31709. 0x4F, 0xE4, 0xCC, 0xCB, 0x07, 0x8F, 0x07, 0xCB,
  31710. 0xD4, 0x55, 0xD1, 0x5D, 0x3E, 0xEC, 0x7D, 0xA2,
  31711. 0x74, 0xD2, 0x4A, 0x2E, 0x57, 0x18, 0x84, 0xDE,
  31712. 0x41, 0xC3, 0xA9, 0xA4, 0xFD, 0xB3, 0xF6, 0x09,
  31713. 0x8A, 0x17, 0x2C, 0x30, 0x96, 0x80, 0x39, 0xBD,
  31714. 0x0E, 0x4E, 0xB3, 0xE2, 0xFB, 0x6D, 0x6E, 0xEE,
  31715. 0xD3, 0x9E, 0x0B, 0x63, 0x62, 0xD5, 0x4E, 0x7B,
  31716. 0x88, 0x95, 0x98, 0x69, 0xDD, 0xD5, 0xD8, 0x73,
  31717. 0xD9, 0x65, 0x24, 0x01, 0xA2, 0x9F, 0x27, 0xA2,
  31718. 0x8E, 0xA6, 0x6D, 0x32, 0xCC, 0xB0, 0xEF, 0x3B,
  31719. 0xF4, 0x60, 0x0F, 0x75, 0x57, 0xEE, 0x8D, 0x54,
  31720. 0xBF, 0x1D, 0xAD, 0x18, 0xF4, 0x5D, 0xDC, 0xD4,
  31721. 0xC9, 0xED, 0x57, 0xB1, 0x3E, 0x44, 0x5B, 0xF1,
  31722. 0x22, 0xA4, 0x3F, 0x53, 0x94, 0x03, 0x89, 0xBF,
  31723. 0x87, 0x14, 0xFF, 0xAC, 0x72, 0x1E, 0x59, 0x31,
  31724. 0x7E, 0x4B, 0x70, 0x50, 0x0A, 0xD0, 0xD1, 0xB9,
  31725. 0xA6, 0x27, 0x05, 0x4D, 0x31, 0x93, 0x20, 0x8C,
  31726. 0x77, 0x4E, 0x0B, 0x20, 0xED, 0x04, 0x1A, 0x8C,
  31727. 0x05, 0x5E, 0x75, 0xEE, 0xCD, 0x37, 0x38, 0xF0,
  31728. 0x07, 0x15, 0x8F, 0xAD, 0xDF, 0xCA, 0x5F, 0x43,
  31729. 0x56, 0x2D, 0x63, 0x6A, 0x5A, 0xCF, 0x3A, 0x39,
  31730. 0x83, 0xD3, 0xCF, 0xEB, 0xCA, 0x10, 0xB8, 0x13,
  31731. 0xF9, 0xF6, 0x52, 0x65, 0x19, 0x19, 0x9A, 0x03,
  31732. 0x13, 0xCD, 0x1D, 0xE1, 0x3F, 0x06, 0xAD, 0x53,
  31733. 0x86, 0xE1, 0xE1, 0x20, 0x79, 0x5F, 0xD2, 0x67,
  31734. 0xB7, 0xF4, 0x20, 0x19, 0xD8, 0x4D, 0xF6, 0xCD,
  31735. 0x1B, 0xF9, 0x19, 0x30, 0xFC, 0xA7, 0xAF, 0xD5,
  31736. 0x2E, 0x80, 0x70, 0x0F, 0x4C, 0xF5, 0xCD, 0xC3,
  31737. 0x8A, 0x5F, 0x7A, 0x57, 0x49, 0x79, 0x1C, 0x2F,
  31738. 0xDF, 0xFC, 0x4A, 0x10, 0x75, 0x3C, 0x24, 0xDB,
  31739. 0x19, 0xE8, 0xEB, 0x65, 0x1C, 0x5B, 0x36, 0x32,
  31740. 0x00, 0xF0, 0xB5, 0xD1, 0x69, 0x94, 0x70, 0x26,
  31741. 0xE9, 0xF7, 0x4F, 0x01, 0x2D, 0xC7, 0xC5, 0xB3,
  31742. 0x39, 0xDD, 0x49, 0xD2, 0x61, 0xCA, 0x1D, 0x37,
  31743. 0xF8, 0xF2, 0x83, 0x46, 0xE6, 0x19, 0x78, 0x05,
  31744. 0x4F, 0x45, 0xAE, 0xE4, 0x36, 0xDC, 0xCB, 0xE7,
  31745. 0xBF, 0xAF, 0xE0, 0x7C, 0xE9, 0xA8, 0xB8, 0x3C,
  31746. 0x90, 0xA2, 0x68, 0x6F, 0xA9, 0x54, 0x02, 0x85,
  31747. 0x09, 0x25, 0xC8, 0x58, 0x2B, 0xC9, 0xB7, 0x34,
  31748. 0xE4, 0xEC, 0xA1, 0xF7, 0xB2, 0x0B, 0x08, 0x6F,
  31749. 0x12, 0x9F, 0x27, 0x7A, 0x5C, 0xBD, 0xAA, 0x96,
  31750. 0x3C, 0x92, 0x71, 0x7E, 0xF7, 0x0E, 0xC1, 0x9B,
  31751. 0xF3, 0xDB, 0xC6, 0xDA, 0x20, 0x3A, 0xD9, 0x0F,
  31752. 0x3B, 0x13, 0xBB, 0xC2, 0x2F, 0xBD, 0x98, 0x0B,
  31753. 0xB1, 0xB9, 0xD3, 0xA3, 0x44, 0x52, 0xB3, 0x35,
  31754. 0x70, 0x21, 0xCE, 0x36, 0x13, 0x58, 0x4E, 0x09,
  31755. 0x36, 0xBF, 0x1D, 0x09, 0x42, 0x09, 0x37, 0x81,
  31756. 0x5E, 0x11, 0xCC, 0x5D, 0x5D, 0xDB, 0x4B, 0xF1,
  31757. 0xD8, 0x30, 0xC4, 0xF8, 0x3F, 0x30, 0xE5, 0x15,
  31758. 0x92, 0x1C, 0x78, 0x4D, 0x87, 0xBB, 0x20, 0xC0,
  31759. 0x9E, 0x3C, 0x64, 0xBD, 0xCE, 0x9A, 0xB1, 0xC6,
  31760. 0x9F, 0xD3, 0x07, 0xEF, 0xE3, 0x59, 0xC7, 0xF9,
  31761. 0x38, 0x56, 0x6C, 0x9F, 0x25, 0x17, 0xB0, 0x63,
  31762. 0x38, 0x51, 0x67, 0xE2, 0x47, 0xF3, 0x10, 0x81,
  31763. 0x11, 0x9B, 0xAC, 0x6B, 0x55, 0xA0, 0xBD, 0xD7,
  31764. 0x14, 0x25, 0x51, 0x0F, 0xFA, 0x2A, 0xBD, 0xFA,
  31765. 0x88, 0x83, 0x76, 0xA3, 0x7F, 0x20, 0xC2, 0x48,
  31766. 0x01, 0x52, 0xBB, 0x36, 0x16, 0x34, 0x52, 0x00,
  31767. 0x07, 0xC5, 0xB3, 0x4B, 0xF2, 0x28, 0x17, 0xCB,
  31768. 0x2E, 0x67, 0xAC, 0x1A, 0x82, 0x67, 0x0B, 0x71,
  31769. 0xF1, 0x96, 0xC8, 0x9F, 0x23, 0xBA, 0x31, 0x4B,
  31770. 0x16, 0xA9, 0x48, 0x49, 0x93, 0x04, 0xEF, 0x5C,
  31771. 0x03, 0xDC, 0xF5, 0x8E, 0x52, 0xBE, 0x31, 0x48,
  31772. 0x63, 0xE7, 0x23, 0xC5, 0x6D, 0x3A, 0xEB, 0x34,
  31773. 0x0B, 0xFF, 0x18, 0xAB, 0xFA, 0x20, 0xDC, 0x03,
  31774. 0x44, 0x20, 0x30, 0x23, 0x05, 0x33, 0xD9, 0x12,
  31775. 0x9B, 0x83, 0xED, 0x22, 0xC3, 0x51, 0xF2, 0x32,
  31776. 0x81, 0x72, 0xE3, 0x63, 0x44, 0x74, 0x44, 0xAE,
  31777. 0x5C, 0x69, 0x02, 0xB7, 0x92, 0x79, 0x9F, 0x54,
  31778. 0x44, 0x50, 0x78, 0x71, 0x19, 0x61, 0x2E, 0x9B,
  31779. 0xB4, 0x13, 0x0A, 0x33, 0xA2, 0xA5, 0x96, 0x2A,
  31780. 0xC0, 0x9D, 0x57, 0x7D, 0x6D, 0xDC, 0x88, 0x1F,
  31781. 0xE6, 0x61, 0x61, 0x26, 0xD8, 0xA0, 0xA7, 0xDF,
  31782. 0x2B, 0x22, 0x53, 0xBC, 0x8E, 0xC4, 0xE3, 0x53,
  31783. 0x86, 0xEA, 0x55, 0x11, 0xF0, 0xF1, 0x58, 0x87,
  31784. 0x14, 0x5B, 0x6C, 0x23, 0xAB, 0x3D, 0x40, 0x33,
  31785. 0x39, 0xE4, 0x04, 0x07, 0x3E, 0xD9, 0xC6, 0xA8,
  31786. 0x96, 0xA2, 0xF9, 0xEC, 0x70, 0xC4, 0x4B, 0xD2,
  31787. 0xAE, 0xC1, 0x0F, 0xC4, 0x36, 0x0E, 0x87, 0x63,
  31788. 0x6B, 0xE1, 0x55, 0xB6, 0xA6, 0x7B, 0x7E, 0xDF,
  31789. 0x38, 0xCF, 0x73, 0x00, 0x48, 0x13, 0xC9, 0xE7,
  31790. 0xD2, 0xC6, 0x54, 0xC2, 0x53, 0x0A, 0x71, 0xE5,
  31791. 0xF8, 0xC1, 0x09, 0x42, 0xFB, 0x6D, 0x88, 0x41,
  31792. 0x53, 0x5A, 0xB1, 0xDA, 0x43, 0xE8, 0xCB, 0x0B,
  31793. 0xB8, 0x9E, 0x78, 0xEC, 0x91, 0xF8, 0xDE, 0x15,
  31794. 0x31, 0xA0, 0x36, 0x65, 0xCC, 0xD5, 0xA7, 0x5B,
  31795. 0xDA, 0x0E, 0xD0, 0xE5, 0x98, 0x64, 0xEE, 0xEF,
  31796. 0x51, 0xA8, 0x3F, 0xA5, 0x53, 0xAF, 0x66, 0x2A,
  31797. 0xEE, 0x00, 0xD1, 0xF8, 0x36, 0x7B, 0x4D, 0x5D,
  31798. 0xDD, 0xC3, 0x45, 0x54, 0x4C, 0x6B, 0xD5, 0x14,
  31799. 0xF8, 0x88, 0xE6, 0x03, 0x3C, 0x25, 0x5D, 0xB6,
  31800. 0x50, 0xDA, 0x73, 0x4A, 0xD3, 0x3A, 0x3C, 0xF8,
  31801. 0x4B, 0xD3, 0xF0, 0x6F, 0xA1, 0xA7, 0xCA, 0x02,
  31802. 0xE4, 0xB8, 0xE9, 0x93, 0xAE, 0x7A, 0xE6, 0x34,
  31803. 0x20, 0xA4, 0x6B, 0xA8, 0xA3, 0x81, 0x3D, 0x1E,
  31804. 0x9D, 0x29, 0x66, 0xBB, 0x85, 0x60, 0xD7, 0x1C,
  31805. 0x62, 0xA0, 0x44, 0xEA, 0x94, 0x17, 0x9F, 0x4E,
  31806. 0xB1, 0xB6, 0xED, 0x60, 0x71, 0x9D, 0x51, 0xE0,
  31807. 0xEE, 0xF6, 0xCD, 0x07, 0x91, 0x52, 0xF6, 0xBE,
  31808. 0x48, 0x8E, 0xC9, 0x19, 0x11, 0xC6, 0xD3, 0xF1,
  31809. 0xD1, 0x17, 0x3C, 0x54, 0x1F, 0x9D, 0x25, 0xBF,
  31810. 0x34, 0x2F, 0xCA, 0xA3, 0xFF, 0x46, 0xC1, 0x8F,
  31811. 0x2A, 0x04, 0x41, 0xD8, 0x3B, 0xDE, 0x35, 0x46,
  31812. 0xA9, 0x82, 0x6C, 0x34, 0x96, 0xE0, 0x6F, 0x2F,
  31813. 0x2B, 0x0E, 0xEB, 0x9D, 0x5B, 0xE8, 0x73, 0x9F,
  31814. 0x83, 0xA4, 0x2D, 0x3B, 0x30, 0x0E, 0x70, 0xEE,
  31815. 0x84, 0xDF, 0xFF, 0xB2, 0x07, 0x64, 0xA0, 0x60,
  31816. 0x21, 0x2F, 0x05, 0x8C, 0x8A, 0x5F, 0xFA, 0x9A,
  31817. 0x34, 0xE9, 0x28, 0xD6, 0xA7, 0xE0, 0x77, 0x08,
  31818. 0xFE, 0x53, 0x93, 0xE3, 0x01, 0x7C, 0xE4, 0x70,
  31819. 0xEB, 0x96, 0x58, 0xA7, 0x4E, 0x49, 0x51, 0xE6,
  31820. 0xFA, 0x48, 0x54, 0xC9, 0xE9, 0xC2, 0x89, 0x88,
  31821. 0x81, 0x2E, 0x44, 0x18, 0xA2, 0xE8, 0x32, 0x58,
  31822. 0x0B, 0x4A, 0x27, 0x03, 0x72, 0xBC, 0x69, 0x67,
  31823. 0x68, 0x89, 0xD0, 0xCC, 0x43, 0x24, 0x0E, 0xDA,
  31824. 0xBC, 0x1D, 0x31, 0x14, 0xD8, 0xF3, 0x5A, 0xB2,
  31825. 0xE9, 0xEA, 0x95, 0x30, 0x82, 0xE9, 0x53, 0x62,
  31826. 0x79, 0xAC, 0xB3, 0xBE, 0x16, 0xD3, 0xA2, 0x05,
  31827. 0xF4, 0x6C, 0xB6, 0x7B, 0x22, 0x14, 0x96, 0x93,
  31828. 0x5A, 0xC0, 0x42, 0x92, 0xBB, 0xFB, 0x9A, 0x61,
  31829. 0xC0, 0xA0, 0x3E, 0xF4, 0xC9, 0xB6, 0x82, 0x04,
  31830. 0x95, 0xF3, 0xD8, 0x0E, 0x4A, 0x6F, 0xB7, 0xE1,
  31831. 0xC6, 0x99, 0x03, 0xFA, 0x22, 0x6E, 0x02, 0x3E,
  31832. 0x95, 0xBA, 0x41, 0x6D, 0xF2, 0xE5, 0xE4, 0x54,
  31833. 0x1E, 0x15, 0xDC, 0xC0, 0x00, 0xB5, 0xE6, 0x5C,
  31834. 0x97, 0x20, 0xDA, 0xF6, 0x96, 0x01, 0x2F, 0xA2,
  31835. 0xA6, 0xCF, 0x75, 0x8E, 0xD6, 0xD2, 0x25, 0xA3,
  31836. 0xE4, 0xFE, 0xE4, 0x5A, 0xC5, 0xFB, 0x48, 0x70,
  31837. 0x7F, 0xAE, 0x13, 0x3D, 0x59, 0x2C, 0xFD, 0x2E,
  31838. 0x8C, 0x43, 0xC2, 0x12, 0x6F, 0x65, 0x2B, 0xEE,
  31839. 0x9B, 0xAB, 0x43, 0xA1, 0xA1, 0x0B, 0xE2, 0x41,
  31840. 0x1A, 0x67, 0x94, 0xB2, 0x6C, 0xB5, 0x5C, 0xC2,
  31841. 0x17, 0xEB, 0x7B, 0x0B, 0x14, 0x6D, 0x23, 0xF7,
  31842. 0x92, 0x2D, 0x32, 0x22, 0xAE, 0x5E, 0xE8, 0xC6,
  31843. 0xD3, 0x8E, 0x83, 0x99, 0xBA, 0x51, 0xC6, 0x81,
  31844. 0xB8, 0x38, 0x16, 0xFC, 0xF7, 0x44, 0x38, 0x82,
  31845. 0x59, 0x20, 0xF9, 0xCE, 0x8A, 0x20, 0x2A, 0x8F,
  31846. 0x6D, 0x94, 0x2D, 0xA8, 0x62, 0x38, 0xFB, 0x4C,
  31847. 0x9F, 0x21, 0x98, 0xEA, 0x8D, 0xFF, 0x81, 0xC1,
  31848. 0x72, 0x86, 0xE0, 0x18, 0xDF, 0x4B, 0x7F, 0xE3,
  31849. 0x88, 0x4D, 0x17, 0x59, 0xE4, 0xC5, 0x9B, 0xB5,
  31850. 0x26, 0x17, 0xAE, 0xD4, 0xE7, 0x8E, 0x4E, 0x7C,
  31851. 0x4E, 0x9A, 0x36, 0xE4, 0xE9, 0x96, 0xD3, 0x23,
  31852. 0x91, 0xA3, 0x4A, 0x0D, 0xAA, 0xAB, 0x6B, 0x54,
  31853. 0x08, 0x15, 0xA3, 0x4D, 0x20, 0x40, 0x7A, 0xEF,
  31854. 0x81, 0x94, 0x9B, 0xE6, 0x7B, 0x90, 0x69, 0x50,
  31855. 0xD8, 0x9B, 0xE9, 0xF0, 0x85, 0xE9, 0x9E, 0xB5,
  31856. 0x87, 0x26, 0x95, 0x17, 0x3B, 0x3E, 0xFA, 0xCA,
  31857. 0xE9, 0x45, 0x5D, 0x2B, 0x2C, 0xD4, 0xF7, 0x10,
  31858. 0xB8, 0x72, 0xCF, 0x66, 0x2B, 0x73, 0x62, 0x16,
  31859. 0xB1, 0xBB, 0xFB, 0x1F, 0x5F, 0x3D, 0x48, 0x6C,
  31860. 0x7B, 0x4B, 0x87, 0x56, 0x12, 0x33, 0x3F, 0x8E,
  31861. 0x4B, 0xA9, 0x33, 0xDC, 0x79, 0xF0, 0xED, 0xFD,
  31862. 0x7B, 0xAA, 0xDE, 0x2C, 0x16, 0xF2, 0x14, 0x6A,
  31863. 0x49, 0x6F, 0x79, 0xC4, 0x2A, 0x4D, 0x6B, 0x52,
  31864. 0x39, 0xA3, 0x0D, 0xD3, 0xC4, 0x8B, 0xEB, 0x09,
  31865. 0x2C, 0xA0, 0x75, 0x00, 0x10, 0xF6, 0x9E, 0xD4,
  31866. 0xB9, 0x23, 0x20, 0x14, 0x7D, 0xBB, 0xE2, 0x08,
  31867. 0xF6, 0xE8, 0xEB, 0x1C, 0xF2, 0x47, 0xD2, 0x1A,
  31868. 0x3A, 0x3B, 0x01, 0xDF, 0x58, 0xC0, 0xAA, 0x62,
  31869. 0x94, 0x4D, 0xA0, 0xEF, 0x04, 0x50, 0xE8, 0xCE,
  31870. 0x48, 0xAA, 0x13, 0x7E, 0x7E, 0x15, 0x16, 0xC1,
  31871. 0xD5, 0xC8, 0x6E, 0xEA, 0x17, 0xFD, 0xFA, 0xC1,
  31872. 0x69, 0x07, 0x46, 0xE7, 0x26, 0x70, 0x45, 0xA3,
  31873. 0xE9, 0x05, 0x96, 0xBD, 0xB7, 0x5D, 0x50, 0xB6,
  31874. 0xDD, 0x5C, 0x34, 0xE5, 0xC8, 0xD8, 0x9D, 0xC6,
  31875. 0xF2, 0xF1, 0xD2, 0x44, 0x40, 0xE5, 0x7B, 0x47,
  31876. 0x59, 0xB8, 0x62, 0x5F, 0x72, 0xBC, 0x4A, 0x7B,
  31877. 0x10, 0xD5, 0x19, 0xD3, 0x31, 0xF9, 0xC4, 0x00,
  31878. 0xAA, 0xE1, 0xE5, 0x0D, 0x48, 0x0C, 0xAA, 0xE5,
  31879. 0xA1, 0xC0, 0xFA, 0x99, 0xD7, 0x79, 0x24, 0xCF,
  31880. 0x8D, 0xFE, 0x56, 0xCD, 0x70, 0x92, 0xE7, 0xB9
  31881. };
  31882. #endif /* !WOLFSSL_NO_ML_DSA_44 */
  31883. #ifndef WOLFSSL_NO_ML_DSA_65
  31884. static const byte seed_65[] = {
  31885. 0x70, 0xCE, 0xFB, 0x9A, 0xED, 0x5B, 0x68, 0xE0,
  31886. 0x18, 0xB0, 0x79, 0xDA, 0x82, 0x84, 0xB9, 0xD5,
  31887. 0xCA, 0xD5, 0x49, 0x9E, 0xD9, 0xC2, 0x65, 0xFF,
  31888. 0x73, 0x58, 0x80, 0x05, 0xD8, 0x5C, 0x22, 0x5C
  31889. };
  31890. static const byte pk_65[] = {
  31891. 0xD2, 0xFD, 0x03, 0xF3, 0xA1, 0xB7, 0xF6, 0x35,
  31892. 0xAF, 0x9F, 0x34, 0xD5, 0x80, 0xA9, 0x8F, 0x52,
  31893. 0x4C, 0x73, 0x5B, 0xD5, 0xBA, 0x23, 0x55, 0xDC,
  31894. 0x6E, 0x03, 0x5B, 0xD2, 0x17, 0x65, 0x58, 0x0C,
  31895. 0xBB, 0x11, 0x19, 0x23, 0xF1, 0x94, 0xA7, 0xCC,
  31896. 0x8A, 0x7B, 0xB2, 0xEB, 0xC5, 0xC0, 0xE7, 0x1A,
  31897. 0xA6, 0x37, 0xCC, 0x80, 0x0E, 0x61, 0x03, 0xB8,
  31898. 0x50, 0xA5, 0x39, 0xB2, 0xA3, 0x9E, 0x1B, 0x6D,
  31899. 0x71, 0x3E, 0x5D, 0xB8, 0x31, 0x4C, 0x9A, 0xE1,
  31900. 0xF8, 0xBF, 0x8A, 0x38, 0xF0, 0x6A, 0xFB, 0x9D,
  31901. 0x73, 0xB1, 0x61, 0xB0, 0xFF, 0xE3, 0xA4, 0x89,
  31902. 0x17, 0x06, 0xAE, 0x26, 0xD5, 0x4F, 0xFB, 0x49,
  31903. 0x6D, 0xF8, 0xDC, 0x0F, 0x19, 0x83, 0x50, 0x95,
  31904. 0x00, 0xC9, 0xAB, 0xBD, 0x28, 0xE5, 0x9B, 0x3F,
  31905. 0xCD, 0xAB, 0xBD, 0xAD, 0xAB, 0xD4, 0x5E, 0xC3,
  31906. 0x14, 0x99, 0x37, 0x8B, 0xDE, 0x84, 0x9E, 0x7C,
  31907. 0x1F, 0x19, 0xB7, 0x04, 0x4D, 0x67, 0xE0, 0x51,
  31908. 0x06, 0xD7, 0x13, 0x6D, 0x95, 0x38, 0x0D, 0x56,
  31909. 0x05, 0xD4, 0x46, 0x5D, 0x87, 0x75, 0x57, 0x06,
  31910. 0x5D, 0xF0, 0xA7, 0x5D, 0x3C, 0x28, 0x54, 0x2F,
  31911. 0x40, 0xFE, 0xED, 0x42, 0xEC, 0x7E, 0x28, 0x06,
  31912. 0x37, 0xB0, 0x83, 0xD9, 0x88, 0xBC, 0xA5, 0xF6,
  31913. 0x39, 0x4E, 0x02, 0x39, 0x6C, 0x46, 0x76, 0x18,
  31914. 0x4F, 0xB6, 0x33, 0x18, 0xDA, 0xFA, 0xF5, 0xBB,
  31915. 0xDD, 0xE0, 0x0E, 0x30, 0x8F, 0xE8, 0x40, 0x19,
  31916. 0xC2, 0x34, 0x0A, 0x3F, 0x3E, 0x1C, 0x08, 0x65,
  31917. 0x62, 0x49, 0x70, 0x71, 0x12, 0x83, 0x35, 0x6A,
  31918. 0xE1, 0x4B, 0xD6, 0xB9, 0x4D, 0x1C, 0x9A, 0xE1,
  31919. 0x88, 0xDE, 0x1A, 0x8A, 0x2C, 0xA8, 0x24, 0xA8,
  31920. 0xEA, 0xE2, 0xFE, 0x6A, 0xFB, 0x38, 0xD8, 0x3A,
  31921. 0x2D, 0x99, 0x99, 0x6A, 0xB2, 0x1F, 0xE3, 0xE8,
  31922. 0x4C, 0x0B, 0xE6, 0xB6, 0xDA, 0x08, 0x87, 0x9B,
  31923. 0x67, 0x73, 0x74, 0xFA, 0x7C, 0x69, 0x1B, 0x13,
  31924. 0xD4, 0x0F, 0xA9, 0xD4, 0xCC, 0x26, 0xB2, 0x28,
  31925. 0x8D, 0x5A, 0x8C, 0x9A, 0x43, 0x72, 0x43, 0x81,
  31926. 0x00, 0x4D, 0x61, 0xB0, 0xD5, 0x7F, 0xF4, 0x00,
  31927. 0x31, 0x4C, 0x8E, 0x30, 0xEE, 0x79, 0x6A, 0xF1,
  31928. 0x0F, 0x7E, 0xE2, 0x1B, 0xF1, 0x3D, 0x08, 0x18,
  31929. 0x04, 0x65, 0xAB, 0xC7, 0x2E, 0xDD, 0xB0, 0x80,
  31930. 0xC6, 0xA0, 0x71, 0x84, 0xE3, 0xEE, 0xDC, 0x47,
  31931. 0xC1, 0x9A, 0xA7, 0xF0, 0x9D, 0x1F, 0x33, 0x09,
  31932. 0xE1, 0x83, 0xA2, 0xBD, 0x9B, 0x05, 0x73, 0xDD,
  31933. 0xE4, 0x74, 0xA8, 0x1B, 0xA4, 0xF7, 0x8D, 0x0C,
  31934. 0x52, 0x3D, 0x0C, 0x04, 0xF9, 0x00, 0x60, 0xFD,
  31935. 0x57, 0x1A, 0x35, 0xC0, 0x37, 0xE0, 0x79, 0xC5,
  31936. 0xE2, 0x10, 0xD7, 0x39, 0x0D, 0xF5, 0x68, 0xF2,
  31937. 0xE2, 0xF0, 0x3C, 0xE4, 0x44, 0x20, 0xC8, 0x2F,
  31938. 0x3F, 0xE6, 0x9E, 0xB9, 0xB4, 0x8E, 0xE9, 0x09,
  31939. 0x62, 0xD6, 0xB0, 0xF2, 0x44, 0x40, 0x64, 0x8F,
  31940. 0x71, 0xED, 0xB2, 0x41, 0xEE, 0x65, 0x66, 0xFC,
  31941. 0x1A, 0x64, 0xCA, 0xBF, 0x66, 0xBE, 0x6F, 0xEC,
  31942. 0xBC, 0xB1, 0x38, 0x7C, 0x82, 0xA7, 0xBC, 0x20,
  31943. 0x2D, 0x9E, 0x36, 0x79, 0x98, 0xE2, 0xA2, 0x91,
  31944. 0xAF, 0x0C, 0xD1, 0x57, 0x06, 0x77, 0xFE, 0x8D,
  31945. 0x63, 0xA3, 0x28, 0x5A, 0x2E, 0xA6, 0xEB, 0x29,
  31946. 0xAF, 0x9D, 0xC1, 0xAE, 0xC1, 0xC3, 0x6C, 0x47,
  31947. 0x06, 0xB1, 0x2B, 0xAA, 0x20, 0x83, 0x96, 0x92,
  31948. 0xF2, 0x86, 0xA6, 0xE0, 0x32, 0x14, 0x68, 0xF7,
  31949. 0x47, 0x93, 0x45, 0xC4, 0xD5, 0x2F, 0xBD, 0xB2,
  31950. 0xF0, 0x67, 0x25, 0xB5, 0x54, 0xB8, 0x9E, 0x24,
  31951. 0x92, 0x61, 0x26, 0x81, 0xAC, 0xEB, 0xC6, 0xC7,
  31952. 0xBA, 0xDA, 0x92, 0x25, 0x81, 0x8D, 0xBC, 0x35,
  31953. 0xD6, 0x4C, 0x22, 0xC4, 0x8B, 0xFF, 0x80, 0xA7,
  31954. 0x30, 0xD0, 0x71, 0x6D, 0xFA, 0xC9, 0x9D, 0xFD,
  31955. 0x5B, 0x89, 0x92, 0x61, 0x1D, 0x0C, 0x93, 0xEE,
  31956. 0x90, 0xBD, 0xB2, 0x60, 0x02, 0x2A, 0xFE, 0x25,
  31957. 0xD9, 0x13, 0xE0, 0x6E, 0xFF, 0xB5, 0x9C, 0xB1,
  31958. 0xF8, 0xA6, 0x0C, 0xBF, 0xA5, 0xAB, 0x2F, 0x45,
  31959. 0x9A, 0x16, 0xF4, 0x67, 0xE9, 0x89, 0x52, 0x5E,
  31960. 0x0A, 0x37, 0xEB, 0xE5, 0x6E, 0x83, 0x3F, 0xDE,
  31961. 0x55, 0xDB, 0x9D, 0x15, 0x30, 0xAD, 0xCF, 0x45,
  31962. 0x84, 0x6D, 0xF2, 0x81, 0xE4, 0x7C, 0xAA, 0x1E,
  31963. 0x0A, 0x27, 0xEF, 0xDE, 0x21, 0x07, 0xD3, 0x54,
  31964. 0xCE, 0xA0, 0xF6, 0xA4, 0x54, 0x69, 0x2F, 0x04,
  31965. 0xCD, 0x83, 0x8E, 0xBD, 0xD4, 0x6E, 0x19, 0x1E,
  31966. 0x5D, 0x9C, 0x11, 0x83, 0x9A, 0x2C, 0x3F, 0x48,
  31967. 0x8A, 0x4F, 0xC7, 0xCD, 0x26, 0x5A, 0x7B, 0x5D,
  31968. 0x32, 0xB0, 0x8C, 0xBD, 0xBF, 0xAB, 0x9D, 0x2C,
  31969. 0xCD, 0x76, 0x22, 0x2C, 0x8E, 0xE3, 0x7D, 0xDC,
  31970. 0xBD, 0x2A, 0xA0, 0x63, 0xED, 0x86, 0x14, 0x73,
  31971. 0xA6, 0x45, 0x4C, 0xAE, 0xA3, 0x77, 0x85, 0x0B,
  31972. 0x1A, 0x2B, 0x9D, 0xDB, 0xBC, 0xB3, 0x74, 0xFA,
  31973. 0xB5, 0xB1, 0x2F, 0x35, 0x1C, 0x8E, 0x58, 0x88,
  31974. 0x87, 0x2E, 0x5C, 0xD1, 0xF6, 0x0A, 0x4F, 0xAE,
  31975. 0x1F, 0xF8, 0x37, 0xD1, 0x92, 0xC2, 0x2B, 0xEB,
  31976. 0x41, 0xEE, 0x6F, 0xA3, 0x92, 0xFC, 0xDF, 0x45,
  31977. 0x50, 0xFF, 0x46, 0xB5, 0xCE, 0x90, 0x6D, 0x01,
  31978. 0x7E, 0xF3, 0x07, 0x7D, 0xF1, 0x32, 0x30, 0x0D,
  31979. 0x8B, 0xBF, 0xA9, 0xBB, 0x03, 0xC7, 0x5E, 0x79,
  31980. 0xE2, 0xF0, 0x4C, 0x28, 0x4A, 0xD0, 0x6A, 0x44,
  31981. 0x39, 0x96, 0x49, 0xC3, 0xE2, 0xA2, 0xA8, 0xD1,
  31982. 0xEF, 0xE9, 0xB7, 0xA4, 0xE0, 0xC2, 0x71, 0x04,
  31983. 0x7A, 0xB7, 0x59, 0x08, 0xBF, 0xF7, 0xDF, 0x9E,
  31984. 0x30, 0xEC, 0xA5, 0x47, 0x74, 0x5B, 0xAE, 0x23,
  31985. 0xA8, 0x6F, 0xF9, 0xA8, 0xB5, 0x8C, 0x25, 0x38,
  31986. 0xB8, 0x8B, 0x86, 0x64, 0x01, 0x07, 0x69, 0x02,
  31987. 0xDC, 0x5F, 0x0B, 0xD7, 0x61, 0x68, 0x7B, 0x49,
  31988. 0xEA, 0xFE, 0x36, 0xD3, 0x50, 0xCB, 0xED, 0xFD,
  31989. 0xD3, 0x6C, 0x12, 0x1C, 0xF2, 0x37, 0x86, 0xBF,
  31990. 0xCF, 0x7E, 0x47, 0x07, 0x64, 0x96, 0xEA, 0xB6,
  31991. 0xBB, 0xDA, 0x77, 0x40, 0x49, 0xC2, 0xEB, 0xAB,
  31992. 0xE2, 0xDE, 0x99, 0xC4, 0xC2, 0x4F, 0x2D, 0xB7,
  31993. 0x36, 0x84, 0x01, 0x5B, 0x37, 0x39, 0x77, 0x49,
  31994. 0x67, 0x60, 0xCF, 0x9A, 0xC2, 0x3D, 0x8B, 0x62,
  31995. 0x31, 0x33, 0xDB, 0x2D, 0xE1, 0x0D, 0x73, 0xFA,
  31996. 0x6A, 0xD1, 0xC6, 0xDA, 0xC8, 0x43, 0x4F, 0x28,
  31997. 0xC6, 0xE2, 0x51, 0xCE, 0x72, 0x93, 0xCF, 0xF3,
  31998. 0xF3, 0xB6, 0x1E, 0xFC, 0xB5, 0xA4, 0x35, 0x12,
  31999. 0x36, 0x70, 0xF2, 0x98, 0x46, 0xA1, 0x3D, 0xF3,
  32000. 0xEE, 0x71, 0x26, 0x04, 0x46, 0x1F, 0x1B, 0xAB,
  32001. 0x8F, 0x4E, 0xBC, 0x83, 0x6D, 0xE0, 0x58, 0x97,
  32002. 0x8A, 0xE7, 0x34, 0x39, 0x6A, 0x98, 0x08, 0x1B,
  32003. 0x35, 0xCC, 0x98, 0x18, 0x8A, 0x86, 0x94, 0x9C,
  32004. 0x99, 0x27, 0x0D, 0x47, 0x09, 0x85, 0x4C, 0x5B,
  32005. 0x35, 0xB1, 0x7F, 0x48, 0xA3, 0x73, 0x13, 0x4C,
  32006. 0x81, 0x4C, 0xC8, 0xA0, 0xF3, 0xE2, 0xFA, 0x80,
  32007. 0x7F, 0x2A, 0x91, 0x85, 0x30, 0x90, 0x78, 0x64,
  32008. 0x77, 0x82, 0x82, 0xD7, 0x5E, 0x03, 0xA4, 0x1B,
  32009. 0x25, 0x04, 0xEE, 0xD8, 0x16, 0xA4, 0x17, 0xA3,
  32010. 0xAC, 0x6B, 0xA1, 0x60, 0x80, 0xC3, 0x9B, 0x73,
  32011. 0x10, 0x19, 0x20, 0x02, 0xA7, 0x28, 0xF7, 0xF2,
  32012. 0x03, 0x95, 0x00, 0x9A, 0x9E, 0x16, 0x76, 0x7C,
  32013. 0xE1, 0x97, 0x1F, 0x5D, 0xE7, 0xD2, 0x29, 0xA5,
  32014. 0x06, 0x13, 0x36, 0x9E, 0x43, 0x82, 0x04, 0x5A,
  32015. 0x8E, 0x81, 0x90, 0x1F, 0x4D, 0xBA, 0x81, 0x02,
  32016. 0xF3, 0xD4, 0x13, 0xFE, 0x35, 0xB3, 0x26, 0xA8,
  32017. 0x74, 0xF2, 0x33, 0xB7, 0x19, 0xA7, 0x13, 0x76,
  32018. 0x00, 0xD3, 0x5D, 0x33, 0xAE, 0xB6, 0xB7, 0x25,
  32019. 0x96, 0x24, 0x08, 0x3A, 0xA9, 0x68, 0x73, 0x0C,
  32020. 0x8F, 0x78, 0x29, 0x2A, 0xD2, 0x8F, 0x14, 0xEE,
  32021. 0xAB, 0xE6, 0x60, 0x83, 0x59, 0x84, 0xFE, 0x69,
  32022. 0xEF, 0x23, 0xDE, 0xC8, 0xC3, 0x27, 0xC0, 0xEB,
  32023. 0x0B, 0x88, 0x2D, 0x58, 0x7E, 0x1E, 0xC4, 0x33,
  32024. 0xDA, 0x85, 0xC9, 0xFD, 0x1E, 0x0A, 0x34, 0x99,
  32025. 0x4D, 0xEA, 0x24, 0x0C, 0x85, 0x44, 0x52, 0xD1,
  32026. 0x8C, 0x30, 0xF4, 0x96, 0xE4, 0x9E, 0xC9, 0x04,
  32027. 0xB6, 0x02, 0xE0, 0xF5, 0x06, 0x2E, 0xDC, 0xDA,
  32028. 0x03, 0x28, 0x0A, 0x53, 0xB4, 0x31, 0x35, 0x74,
  32029. 0xCC, 0x2C, 0x0D, 0x54, 0x71, 0xBC, 0x96, 0x13,
  32030. 0xBD, 0xFD, 0x66, 0x41, 0xF5, 0xBD, 0x12, 0x7B,
  32031. 0xAB, 0x5B, 0x5E, 0xB3, 0xD4, 0x99, 0xA3, 0x31,
  32032. 0x14, 0x04, 0x82, 0x20, 0xE8, 0x19, 0xF8, 0xEE,
  32033. 0x12, 0xCA, 0x92, 0x2C, 0x8F, 0x17, 0xD9, 0xC9,
  32034. 0xF5, 0x1A, 0xD5, 0xBD, 0x68, 0x83, 0xB1, 0x0E,
  32035. 0x6A, 0xA2, 0x48, 0x3B, 0xA4, 0x9D, 0xC5, 0x47,
  32036. 0xDA, 0x76, 0x86, 0x15, 0x13, 0x44, 0xF4, 0xE9,
  32037. 0x09, 0x9B, 0x38, 0xE4, 0x30, 0xB5, 0x22, 0x6B,
  32038. 0x05, 0x98, 0x32, 0xCF, 0x03, 0xDB, 0x48, 0xFB,
  32039. 0x02, 0xDB, 0xA4, 0xE6, 0x15, 0x93, 0xDC, 0x45,
  32040. 0x76, 0x36, 0x04, 0x91, 0x89, 0x0E, 0x53, 0xEC,
  32041. 0x0E, 0x6A, 0xC7, 0x3C, 0xF3, 0x2B, 0x25, 0xD8,
  32042. 0x23, 0xB3, 0x84, 0x56, 0xE2, 0x86, 0x50, 0x5A,
  32043. 0x54, 0x1E, 0x5A, 0xEE, 0xE9, 0x6B, 0x19, 0x14,
  32044. 0xF5, 0xF7, 0x66, 0x87, 0xCE, 0x2B, 0x01, 0x60,
  32045. 0x22, 0x7A, 0xBE, 0xD7, 0x79, 0x93, 0x59, 0x4B,
  32046. 0xCD, 0x83, 0x13, 0x66, 0x20, 0x6D, 0x75, 0x71,
  32047. 0x40, 0x82, 0xF1, 0xC4, 0x6F, 0x1F, 0x44, 0x39,
  32048. 0xAC, 0x81, 0xA5, 0x7A, 0xF3, 0x1C, 0x81, 0xC5,
  32049. 0x55, 0x30, 0x7A, 0x07, 0x0F, 0xFA, 0x94, 0xE0,
  32050. 0x47, 0x9B, 0x78, 0x4B, 0xBD, 0x88, 0xA6, 0x0C,
  32051. 0xD4, 0xC7, 0xCF, 0xD9, 0x4E, 0x6A, 0xFE, 0x02,
  32052. 0xF6, 0xB2, 0x1F, 0x72, 0xAF, 0x0D, 0xCD, 0x66,
  32053. 0x09, 0xD4, 0x0C, 0x96, 0x5C, 0x14, 0xE5, 0xF2,
  32054. 0x38, 0x91, 0x83, 0xE5, 0x3D, 0xE9, 0x30, 0xF7,
  32055. 0xDE, 0x1D, 0x44, 0x21, 0x5C, 0xF4, 0x91, 0x44,
  32056. 0x84, 0x4E, 0x8B, 0x87, 0xF7, 0x8A, 0x7F, 0x13,
  32057. 0x2A, 0xEF, 0xE2, 0x2B, 0xE8, 0x0B, 0x4E, 0x3A,
  32058. 0x05, 0xEE, 0x3A, 0x68, 0xCC, 0xF6, 0x09, 0xEF,
  32059. 0x44, 0x04, 0x74, 0x02, 0xE4, 0x49, 0x30, 0x46,
  32060. 0xE6, 0xF9, 0xC7, 0x67, 0xFF, 0x8A, 0x75, 0xE2,
  32061. 0x8B, 0x3C, 0xE0, 0x77, 0xFD, 0xE7, 0xE7, 0xEE,
  32062. 0xD3, 0x13, 0xB5, 0xBF, 0x7E, 0x46, 0x01, 0x27,
  32063. 0xCA, 0x81, 0x82, 0xE9, 0xBC, 0x79, 0x4C, 0x0D,
  32064. 0xFA, 0x73, 0x0F, 0xB9, 0x20, 0x08, 0x05, 0x75,
  32065. 0xA7, 0x51, 0xB5, 0xCA, 0xEC, 0x85, 0xA1, 0x09,
  32066. 0xB4, 0x42, 0x2B, 0xA2, 0x66, 0x74, 0x3F, 0x0D,
  32067. 0x03, 0x2B, 0xDA, 0x8F, 0x1C, 0xA6, 0x24, 0x8C,
  32068. 0xDB, 0x91, 0x75, 0x30, 0xDF, 0x13, 0x02, 0xA5,
  32069. 0xF8, 0xC1, 0x8D, 0xC6, 0x42, 0xD5, 0x24, 0x78,
  32070. 0xC9, 0x8C, 0x12, 0xA3, 0xF1, 0x6E, 0xF2, 0xB6,
  32071. 0x2B, 0x4F, 0x59, 0xEA, 0x1B, 0xB5, 0x8D, 0xE7,
  32072. 0xB6, 0x5B, 0x3C, 0x71, 0x53, 0xCE, 0x6D, 0xA5,
  32073. 0xE4, 0x95, 0x07, 0x46, 0xF8, 0x0E, 0x08, 0x7A,
  32074. 0x0E, 0x35, 0x86, 0xD0, 0x97, 0x79, 0x1B, 0xF3,
  32075. 0x6D, 0xEF, 0x86, 0x5D, 0x68, 0x59, 0x1D, 0x39,
  32076. 0xD0, 0x90, 0x37, 0x73, 0xEE, 0xA9, 0x62, 0x14,
  32077. 0x7F, 0x34, 0x70, 0x41, 0x38, 0xB5, 0x4D, 0xF7,
  32078. 0x92, 0x4C, 0xDD, 0x8C, 0x33, 0x3D, 0xB5, 0xE1,
  32079. 0xA4, 0x09, 0xCC, 0xB2, 0xB3, 0x4E, 0x2C, 0x3C,
  32080. 0x8C, 0x7F, 0xDD, 0x3F, 0xD8, 0xD0, 0x12, 0xCB,
  32081. 0xF3, 0x82, 0xAA, 0xA8, 0x5E, 0x83, 0xA1, 0x2F,
  32082. 0x23, 0x5A, 0x2D, 0x14, 0x7D, 0x03, 0x5B, 0x7B,
  32083. 0x28, 0xB3, 0x4B, 0x6F, 0x57, 0x94, 0x9F, 0x32,
  32084. 0x24, 0x82, 0xA7, 0xD4, 0xD3, 0xB1, 0x50, 0x45,
  32085. 0xC4, 0x20, 0xD5, 0xAD, 0xDC, 0x7F, 0x0E, 0x69,
  32086. 0xB4, 0xDC, 0x1C, 0xBA, 0x58, 0xB0, 0x1D, 0x87,
  32087. 0x24, 0x80, 0xB0, 0x6A, 0x26, 0x0D, 0x82, 0x7D,
  32088. 0x89, 0x1B, 0x13, 0xC4, 0xC5, 0xCA, 0x50, 0xC7,
  32089. 0x48, 0xDE, 0x3C, 0x77, 0x1B, 0xE6, 0x1E, 0x9A,
  32090. 0xA1, 0x70, 0x16, 0x5C, 0xB0, 0x1F, 0x4B, 0xF5,
  32091. 0xDA, 0x27, 0xA7, 0x79, 0x1D, 0x3A, 0xD3, 0xF6,
  32092. 0x26, 0x7B, 0x4C, 0xB4, 0xE6, 0x1B, 0x28, 0xFA,
  32093. 0x17, 0x08, 0x41, 0x8D, 0x93, 0x2D, 0xFC, 0x41,
  32094. 0x61, 0x88, 0x0C, 0x5D, 0x3B, 0x17, 0xA9, 0x66,
  32095. 0x3A, 0x90, 0x61, 0xFA, 0x8F, 0x18, 0x04, 0x31,
  32096. 0x58, 0x50, 0xFE, 0x4E, 0x73, 0x06, 0xC8, 0x82,
  32097. 0xB3, 0x82, 0x27, 0xE8, 0x67, 0xF8, 0x08, 0x72,
  32098. 0xCD, 0xC1, 0x94, 0x4D, 0x47, 0x26, 0x15, 0xEA,
  32099. 0x49, 0x00, 0xEF, 0x7D, 0x27, 0x0B, 0x88, 0x1D,
  32100. 0x41, 0x30, 0xF5, 0x6C, 0x5C, 0xC9, 0x80, 0xD9,
  32101. 0x2A, 0x47, 0xAD, 0xA6, 0x65, 0x7E, 0xB6, 0xF3,
  32102. 0x7A, 0x38, 0x5D, 0x2D, 0x8C, 0xC9, 0x93, 0xE1,
  32103. 0x44, 0x2E, 0xB0, 0x52, 0x81, 0x85, 0x36, 0x36,
  32104. 0x99, 0x1E, 0x34, 0xAA, 0xDC, 0x68, 0x95, 0x4D,
  32105. 0x04, 0xE7, 0xAD, 0xEF, 0x76, 0xBF, 0x88, 0x0F,
  32106. 0x05, 0x9B, 0x0C, 0xBB, 0x55, 0xD9, 0x15, 0xA4,
  32107. 0xB1, 0x23, 0xE2, 0xF1, 0x33, 0x9A, 0x07, 0x3C,
  32108. 0xBF, 0xBC, 0x40, 0x9B, 0xEF, 0xF6, 0x40, 0x0A,
  32109. 0xE0, 0x96, 0xD5, 0xAE, 0x18, 0xEC, 0x42, 0xCF,
  32110. 0xFA, 0xD5, 0xB4, 0x98, 0x0F, 0xA3, 0x5B, 0xF0,
  32111. 0x34, 0x13, 0xAD, 0xB5, 0xD7, 0xE6, 0x87, 0x6A,
  32112. 0xC3, 0x55, 0xD1, 0xC9, 0xED, 0x70, 0xCA, 0x2B,
  32113. 0x97, 0x39, 0x54, 0xD1, 0x2B, 0x3C, 0xDD, 0x76,
  32114. 0xAC, 0x68, 0x35, 0xDB, 0x96, 0x00, 0x3E, 0xD8,
  32115. 0xC4, 0xE2, 0x88, 0xB7, 0x1F, 0xD7, 0x7D, 0xBA,
  32116. 0xA7, 0x63, 0x57, 0x20, 0xE1, 0x2A, 0xE0, 0xA3,
  32117. 0x17, 0xDE, 0x80, 0x8C, 0x66, 0x4E, 0x31, 0x7F,
  32118. 0x55, 0x27, 0x57, 0x91, 0xF3, 0x24, 0x5C, 0xA4,
  32119. 0xFE, 0x5D, 0x4D, 0x41, 0x07, 0x7F, 0xC1, 0x50,
  32120. 0xA6, 0xE4, 0x03, 0xD5, 0xA2, 0x08, 0xE4, 0x6E,
  32121. 0xAD, 0xBE, 0x8F, 0x2C, 0xFB, 0x8A, 0xF4, 0x72,
  32122. 0xF4, 0xA0, 0xCE, 0xAC, 0x01, 0x52, 0x19, 0x47,
  32123. 0x8E, 0x6B, 0x86, 0xC9, 0x58, 0xCF, 0x86, 0x52,
  32124. 0x5B, 0x74, 0x85, 0xC1, 0x73, 0x4C, 0x7E, 0xF0,
  32125. 0x0E, 0x90, 0x68, 0x3F, 0xFF, 0x5D, 0xBD, 0x0A,
  32126. 0x7D, 0x41, 0x3A, 0x85, 0x50, 0x21, 0x02, 0x6A,
  32127. 0x1B, 0x32, 0x01, 0x3A, 0x46, 0x16, 0xCB, 0xCD,
  32128. 0x37, 0x00, 0xAC, 0xBC, 0x70, 0x5B, 0xE3, 0xEF,
  32129. 0xBA, 0x62, 0x5C, 0x69, 0xA0, 0x25, 0x26, 0x7B,
  32130. 0xCE, 0x9D, 0x13, 0x5E, 0x3F, 0x5B, 0x5C, 0xC8,
  32131. 0xC4, 0x39, 0x56, 0x40, 0x7E, 0x84, 0xB6, 0x66,
  32132. 0x31, 0x03, 0xE2, 0x9C, 0x24, 0x20, 0x35, 0x55,
  32133. 0x1A, 0xE7, 0x97, 0xF5, 0x6C, 0x63, 0x74, 0xBE,
  32134. 0x0C, 0x79, 0x8C, 0x0C, 0xF3, 0x98, 0xF1, 0xED
  32135. };
  32136. static const byte sk_65[] = {
  32137. 0xD2, 0xFD, 0x03, 0xF3, 0xA1, 0xB7, 0xF6, 0x35,
  32138. 0xAF, 0x9F, 0x34, 0xD5, 0x80, 0xA9, 0x8F, 0x52,
  32139. 0x4C, 0x73, 0x5B, 0xD5, 0xBA, 0x23, 0x55, 0xDC,
  32140. 0x6E, 0x03, 0x5B, 0xD2, 0x17, 0x65, 0x58, 0x0C,
  32141. 0xE3, 0x8D, 0x1C, 0x14, 0xF6, 0x46, 0x7C, 0x35,
  32142. 0xA9, 0xF3, 0x80, 0xD2, 0x7D, 0xE6, 0x1F, 0x7C,
  32143. 0x75, 0x03, 0x15, 0x69, 0xEA, 0x2E, 0xC8, 0x26,
  32144. 0x0E, 0xEE, 0x91, 0x05, 0x26, 0x1B, 0x7F, 0xE1,
  32145. 0x60, 0xC9, 0x13, 0x44, 0xB0, 0xC6, 0x76, 0x4C,
  32146. 0x20, 0x4E, 0x5B, 0x8D, 0x42, 0x46, 0x50, 0xBE,
  32147. 0xC0, 0x6B, 0x9E, 0x2E, 0x62, 0x5A, 0xF0, 0x7E,
  32148. 0x23, 0xF4, 0x95, 0x0C, 0xA2, 0x4F, 0xB4, 0xD6,
  32149. 0xEC, 0x2C, 0x8B, 0x3A, 0x71, 0x7C, 0x93, 0x11,
  32150. 0xEB, 0x87, 0x27, 0x9F, 0xE2, 0x5E, 0x31, 0x1F,
  32151. 0x48, 0xB8, 0x25, 0x65, 0x01, 0xF6, 0x46, 0x34,
  32152. 0x12, 0xB5, 0x0D, 0xBC, 0x89, 0xA8, 0x69, 0xBA,
  32153. 0x22, 0x41, 0x11, 0x26, 0x48, 0x40, 0x07, 0x38,
  32154. 0x73, 0x02, 0x12, 0x44, 0x25, 0x44, 0x57, 0x54,
  32155. 0x83, 0x72, 0x50, 0x33, 0x35, 0x62, 0x58, 0x42,
  32156. 0x32, 0x01, 0x62, 0x11, 0x83, 0x61, 0x02, 0x45,
  32157. 0x66, 0x56, 0x48, 0x35, 0x61, 0x20, 0x84, 0x52,
  32158. 0x60, 0x68, 0x50, 0x45, 0x65, 0x55, 0x12, 0x72,
  32159. 0x47, 0x47, 0x21, 0x21, 0x25, 0x40, 0x22, 0x21,
  32160. 0x42, 0x81, 0x17, 0x65, 0x03, 0x06, 0x42, 0x61,
  32161. 0x52, 0x13, 0x43, 0x25, 0x24, 0x33, 0x82, 0x12,
  32162. 0x11, 0x35, 0x62, 0x33, 0x32, 0x07, 0x47, 0x86,
  32163. 0x22, 0x31, 0x50, 0x83, 0x70, 0x84, 0x26, 0x43,
  32164. 0x45, 0x64, 0x51, 0x48, 0x31, 0x14, 0x86, 0x24,
  32165. 0x66, 0x86, 0x74, 0x33, 0x71, 0x36, 0x67, 0x26,
  32166. 0x01, 0x47, 0x07, 0x72, 0x11, 0x61, 0x58, 0x85,
  32167. 0x58, 0x38, 0x71, 0x83, 0x80, 0x67, 0x01, 0x65,
  32168. 0x78, 0x70, 0x64, 0x77, 0x85, 0x60, 0x02, 0x88,
  32169. 0x53, 0x48, 0x46, 0x62, 0x25, 0x83, 0x54, 0x88,
  32170. 0x04, 0x74, 0x40, 0x12, 0x57, 0x43, 0x71, 0x07,
  32171. 0x75, 0x44, 0x38, 0x71, 0x21, 0x14, 0x22, 0x08,
  32172. 0x88, 0x72, 0x23, 0x58, 0x87, 0x46, 0x14, 0x85,
  32173. 0x53, 0x71, 0x67, 0x73, 0x82, 0x28, 0x22, 0x74,
  32174. 0x14, 0x03, 0x57, 0x73, 0x28, 0x71, 0x83, 0x80,
  32175. 0x78, 0x14, 0x34, 0x87, 0x52, 0x07, 0x64, 0x74,
  32176. 0x01, 0x60, 0x75, 0x61, 0x06, 0x08, 0x61, 0x32,
  32177. 0x21, 0x46, 0x15, 0x65, 0x42, 0x67, 0x08, 0x20,
  32178. 0x84, 0x10, 0x73, 0x13, 0x03, 0x61, 0x02, 0x86,
  32179. 0x50, 0x45, 0x26, 0x12, 0x16, 0x68, 0x33, 0x55,
  32180. 0x25, 0x84, 0x73, 0x53, 0x54, 0x52, 0x65, 0x17,
  32181. 0x10, 0x60, 0x00, 0x38, 0x57, 0x77, 0x81, 0x24,
  32182. 0x26, 0x80, 0x41, 0x46, 0x43, 0x26, 0x67, 0x41,
  32183. 0x06, 0x03, 0x55, 0x41, 0x28, 0x33, 0x37, 0x25,
  32184. 0x23, 0x06, 0x77, 0x82, 0x15, 0x16, 0x31, 0x73,
  32185. 0x00, 0x08, 0x75, 0x26, 0x58, 0x46, 0x34, 0x63,
  32186. 0x88, 0x08, 0x84, 0x64, 0x51, 0x11, 0x24, 0x05,
  32187. 0x32, 0x10, 0x11, 0x18, 0x18, 0x64, 0x78, 0x22,
  32188. 0x41, 0x00, 0x38, 0x55, 0x75, 0x42, 0x10, 0x46,
  32189. 0x83, 0x43, 0x73, 0x38, 0x80, 0x07, 0x83, 0x43,
  32190. 0x78, 0x74, 0x13, 0x57, 0x62, 0x32, 0x68, 0x80,
  32191. 0x65, 0x86, 0x48, 0x53, 0x48, 0x35, 0x51, 0x58,
  32192. 0x50, 0x74, 0x46, 0x05, 0x88, 0x70, 0x07, 0x72,
  32193. 0x01, 0x31, 0x00, 0x87, 0x54, 0x88, 0x14, 0x20,
  32194. 0x84, 0x16, 0x61, 0x15, 0x60, 0x56, 0x85, 0x11,
  32195. 0x58, 0x08, 0x05, 0x88, 0x63, 0x01, 0x82, 0x86,
  32196. 0x13, 0x14, 0x17, 0x22, 0x01, 0x68, 0x17, 0x17,
  32197. 0x86, 0x58, 0x53, 0x10, 0x62, 0x28, 0x52, 0x82,
  32198. 0x26, 0x15, 0x04, 0x31, 0x42, 0x88, 0x54, 0x31,
  32199. 0x78, 0x05, 0x80, 0x11, 0x50, 0x45, 0x68, 0x82,
  32200. 0x33, 0x66, 0x36, 0x36, 0x40, 0x65, 0x15, 0x24,
  32201. 0x47, 0x67, 0x06, 0x45, 0x36, 0x42, 0x26, 0x86,
  32202. 0x75, 0x06, 0x35, 0x41, 0x33, 0x47, 0x85, 0x12,
  32203. 0x17, 0x80, 0x83, 0x87, 0x65, 0x51, 0x42, 0x31,
  32204. 0x38, 0x87, 0x56, 0x62, 0x05, 0x17, 0x40, 0x85,
  32205. 0x28, 0x14, 0x17, 0x21, 0x38, 0x12, 0x60, 0x81,
  32206. 0x24, 0x41, 0x45, 0x75, 0x01, 0x82, 0x87, 0x10,
  32207. 0x10, 0x02, 0x13, 0x25, 0x57, 0x04, 0x21, 0x72,
  32208. 0x42, 0x78, 0x61, 0x11, 0x70, 0x05, 0x30, 0x47,
  32209. 0x72, 0x13, 0x20, 0x30, 0x21, 0x67, 0x44, 0x31,
  32210. 0x57, 0x71, 0x45, 0x57, 0x10, 0x54, 0x16, 0x65,
  32211. 0x74, 0x15, 0x24, 0x02, 0x43, 0x71, 0x51, 0x20,
  32212. 0x55, 0x11, 0x67, 0x83, 0x67, 0x82, 0x52, 0x53,
  32213. 0x35, 0x66, 0x42, 0x46, 0x13, 0x70, 0x22, 0x32,
  32214. 0x74, 0x00, 0x07, 0x06, 0x81, 0x87, 0x17, 0x57,
  32215. 0x80, 0x28, 0x68, 0x01, 0x72, 0x10, 0x04, 0x27,
  32216. 0x55, 0x22, 0x86, 0x42, 0x53, 0x15, 0x81, 0x76,
  32217. 0x30, 0x86, 0x40, 0x83, 0x11, 0x43, 0x30, 0x53,
  32218. 0x82, 0x73, 0x53, 0x03, 0x72, 0x35, 0x68, 0x70,
  32219. 0x45, 0x41, 0x15, 0x73, 0x14, 0x12, 0x31, 0x64,
  32220. 0x32, 0x66, 0x63, 0x56, 0x21, 0x51, 0x50, 0x82,
  32221. 0x10, 0x30, 0x23, 0x38, 0x17, 0x21, 0x27, 0x10,
  32222. 0x23, 0x14, 0x22, 0x75, 0x77, 0x28, 0x37, 0x71,
  32223. 0x62, 0x75, 0x06, 0x88, 0x72, 0x14, 0x18, 0x73,
  32224. 0x13, 0x03, 0x01, 0x50, 0x71, 0x58, 0x62, 0x86,
  32225. 0x62, 0x88, 0x86, 0x86, 0x03, 0x27, 0x01, 0x46,
  32226. 0x17, 0x22, 0x71, 0x38, 0x53, 0x81, 0x70, 0x33,
  32227. 0x88, 0x68, 0x13, 0x78, 0x81, 0x04, 0x86, 0x57,
  32228. 0x30, 0x16, 0x52, 0x31, 0x40, 0x83, 0x07, 0x56,
  32229. 0x82, 0x10, 0x32, 0x31, 0x28, 0x50, 0x06, 0x50,
  32230. 0x81, 0x63, 0x06, 0x75, 0x76, 0x65, 0x11, 0x60,
  32231. 0x14, 0x17, 0x12, 0x12, 0x55, 0x56, 0x48, 0x11,
  32232. 0x41, 0x13, 0x28, 0x82, 0x62, 0x07, 0x47, 0x64,
  32233. 0x24, 0x48, 0x23, 0x24, 0x77, 0x53, 0x26, 0x08,
  32234. 0x17, 0x58, 0x11, 0x56, 0x37, 0x48, 0x35, 0x51,
  32235. 0x47, 0x86, 0x85, 0x66, 0x66, 0x81, 0x73, 0x20,
  32236. 0x21, 0x36, 0x75, 0x22, 0x74, 0x66, 0x83, 0x44,
  32237. 0x57, 0x00, 0x66, 0x64, 0x77, 0x20, 0x47, 0x22,
  32238. 0x28, 0x56, 0x87, 0x12, 0x47, 0x02, 0x48, 0x07,
  32239. 0x02, 0x54, 0x23, 0x01, 0x25, 0x71, 0x37, 0x36,
  32240. 0x75, 0x36, 0x00, 0x52, 0x68, 0x15, 0x33, 0x35,
  32241. 0x82, 0x06, 0x13, 0x73, 0x24, 0x08, 0x71, 0x76,
  32242. 0x15, 0x22, 0x42, 0x60, 0x18, 0x53, 0x43, 0x11,
  32243. 0x64, 0x57, 0x76, 0x17, 0x61, 0x56, 0x68, 0x76,
  32244. 0x60, 0x65, 0x54, 0x78, 0x10, 0x33, 0x63, 0x14,
  32245. 0x21, 0x83, 0x21, 0x60, 0x15, 0x55, 0x80, 0x42,
  32246. 0x38, 0x42, 0x03, 0x13, 0x12, 0x34, 0x36, 0x25,
  32247. 0x27, 0x30, 0x82, 0x81, 0x25, 0x47, 0x51, 0x35,
  32248. 0x44, 0x12, 0x67, 0x35, 0x00, 0x10, 0x01, 0x83,
  32249. 0x85, 0x74, 0x42, 0x40, 0x13, 0x03, 0x61, 0x27,
  32250. 0x81, 0x26, 0x26, 0x81, 0x18, 0x87, 0x43, 0x51,
  32251. 0x20, 0x62, 0x71, 0x27, 0x51, 0x56, 0x10, 0x22,
  32252. 0x22, 0x81, 0x11, 0x81, 0x41, 0x66, 0x66, 0x38,
  32253. 0x20, 0x86, 0x75, 0x56, 0x12, 0x40, 0x06, 0x54,
  32254. 0x61, 0x12, 0x74, 0x40, 0x34, 0x58, 0x58, 0x78,
  32255. 0x10, 0x07, 0x85, 0x25, 0x72, 0x88, 0x57, 0x22,
  32256. 0x22, 0x25, 0x50, 0x84, 0x00, 0x41, 0x26, 0x08,
  32257. 0x36, 0x46, 0x28, 0x78, 0x46, 0x78, 0x05, 0x02,
  32258. 0x28, 0x20, 0x77, 0x13, 0x60, 0x75, 0x14, 0x43,
  32259. 0x68, 0x78, 0x64, 0x31, 0x38, 0x77, 0x73, 0x73,
  32260. 0x55, 0x41, 0x27, 0x00, 0x54, 0x07, 0x08, 0x28,
  32261. 0x68, 0x80, 0x04, 0x53, 0x83, 0x43, 0x22, 0x81,
  32262. 0x00, 0x64, 0x35, 0x48, 0x67, 0x66, 0x50, 0x17,
  32263. 0x75, 0x76, 0x12, 0x75, 0x43, 0x81, 0x62, 0x40,
  32264. 0x33, 0x43, 0x45, 0x38, 0x87, 0x21, 0x66, 0x14,
  32265. 0x70, 0x48, 0x41, 0x43, 0x14, 0x66, 0x58, 0x78,
  32266. 0x45, 0x82, 0x02, 0x25, 0x45, 0x73, 0x15, 0x21,
  32267. 0x32, 0x03, 0x02, 0x48, 0x80, 0x80, 0x13, 0x71,
  32268. 0x25, 0x54, 0x32, 0x72, 0x05, 0x68, 0x65, 0x24,
  32269. 0x68, 0x04, 0x06, 0x16, 0x83, 0x50, 0x54, 0x53,
  32270. 0x37, 0x37, 0x27, 0x22, 0x20, 0x68, 0x08, 0x25,
  32271. 0x50, 0x84, 0x72, 0x86, 0x74, 0x22, 0x36, 0x16,
  32272. 0x80, 0x07, 0x55, 0x18, 0x12, 0x17, 0x84, 0x44,
  32273. 0x81, 0x15, 0x64, 0x50, 0x71, 0x10, 0x58, 0x15,
  32274. 0x51, 0x10, 0x10, 0x47, 0x16, 0x21, 0x07, 0x58,
  32275. 0x61, 0x18, 0x78, 0x00, 0x52, 0x72, 0x64, 0x52,
  32276. 0x17, 0x43, 0x23, 0x40, 0x76, 0x48, 0x67, 0x30,
  32277. 0x77, 0x63, 0x64, 0x87, 0x51, 0x31, 0x63, 0x84,
  32278. 0x68, 0x74, 0x53, 0x63, 0x84, 0x23, 0x54, 0x66,
  32279. 0x10, 0x48, 0x36, 0x33, 0x85, 0x21, 0x48, 0x42,
  32280. 0x03, 0x82, 0x51, 0x10, 0x33, 0x57, 0x46, 0x80,
  32281. 0x16, 0x43, 0x34, 0x02, 0x07, 0x03, 0x53, 0x22,
  32282. 0x12, 0x75, 0x73, 0x34, 0x65, 0x83, 0x33, 0x87,
  32283. 0x43, 0x85, 0x17, 0x50, 0x36, 0x60, 0x88, 0x02,
  32284. 0x58, 0x75, 0x80, 0x88, 0x31, 0x63, 0x60, 0x18,
  32285. 0x21, 0x32, 0x26, 0x15, 0x68, 0x74, 0x11, 0x10,
  32286. 0x33, 0x14, 0x13, 0x05, 0x34, 0x16, 0x72, 0x65,
  32287. 0x35, 0x50, 0x13, 0x34, 0x80, 0x87, 0x10, 0x26,
  32288. 0x48, 0x68, 0x84, 0x52, 0x71, 0x44, 0x23, 0x58,
  32289. 0x80, 0x35, 0x57, 0x70, 0x54, 0x84, 0x28, 0x70,
  32290. 0x55, 0x88, 0x86, 0x83, 0x86, 0x25, 0x21, 0x82,
  32291. 0x72, 0x61, 0x17, 0x78, 0x85, 0x17, 0x67, 0x73,
  32292. 0x00, 0x57, 0x71, 0x11, 0x78, 0x51, 0x10, 0x65,
  32293. 0x63, 0x57, 0x02, 0x87, 0x40, 0x13, 0x40, 0x01,
  32294. 0x26, 0x53, 0x45, 0x12, 0x05, 0x46, 0x75, 0x18,
  32295. 0x80, 0x70, 0x33, 0x35, 0x66, 0x22, 0x62, 0x00,
  32296. 0x70, 0x23, 0x26, 0x87, 0x72, 0x63, 0x11, 0x13,
  32297. 0x33, 0x33, 0x81, 0x41, 0x70, 0x62, 0x28, 0x61,
  32298. 0x51, 0x47, 0x31, 0x30, 0x25, 0x46, 0x51, 0x17,
  32299. 0x61, 0x58, 0x07, 0x41, 0x61, 0x37, 0x37, 0x06,
  32300. 0x14, 0x00, 0x54, 0x88, 0x77, 0x75, 0x67, 0x77,
  32301. 0x66, 0x53, 0x16, 0x72, 0x66, 0x66, 0x88, 0x76,
  32302. 0x43, 0x58, 0x31, 0x04, 0x87, 0x57, 0x06, 0x76,
  32303. 0x47, 0x00, 0x43, 0x63, 0x58, 0x60, 0x52, 0x03,
  32304. 0x44, 0x27, 0x36, 0x48, 0x61, 0x23, 0x72, 0x16,
  32305. 0x10, 0x62, 0x42, 0x08, 0x60, 0x83, 0x23, 0x54,
  32306. 0x03, 0x55, 0x55, 0x73, 0x00, 0x61, 0x03, 0x65,
  32307. 0x34, 0x27, 0x14, 0x15, 0x86, 0x62, 0x55, 0x80,
  32308. 0x16, 0x53, 0x10, 0x18, 0x26, 0x11, 0x35, 0x46,
  32309. 0x82, 0x46, 0x13, 0x25, 0x83, 0x47, 0x70, 0x50,
  32310. 0x06, 0x01, 0x56, 0x02, 0x11, 0x68, 0x54, 0x53,
  32311. 0x03, 0x68, 0x73, 0x36, 0x41, 0x88, 0x86, 0x33,
  32312. 0x42, 0x52, 0x01, 0x58, 0x33, 0x42, 0x32, 0x88,
  32313. 0x56, 0x81, 0x77, 0x55, 0x51, 0x48, 0x48, 0x12,
  32314. 0x01, 0x58, 0x13, 0x85, 0x04, 0x14, 0x71, 0x83,
  32315. 0x57, 0x07, 0x54, 0x55, 0x54, 0x55, 0x28, 0x27,
  32316. 0x31, 0x36, 0x02, 0x12, 0x32, 0x68, 0x32, 0x13,
  32317. 0x82, 0x58, 0x70, 0x28, 0x58, 0x53, 0x44, 0x86,
  32318. 0x72, 0x73, 0x42, 0x84, 0x18, 0x22, 0x08, 0x83,
  32319. 0x61, 0x02, 0x14, 0x16, 0x17, 0x12, 0x41, 0x57,
  32320. 0x48, 0x85, 0x25, 0x10, 0x26, 0x07, 0x36, 0x76,
  32321. 0x12, 0x66, 0x17, 0x21, 0x32, 0x36, 0x03, 0x25,
  32322. 0x41, 0x10, 0x11, 0x22, 0x66, 0x60, 0x16, 0x16,
  32323. 0x32, 0x64, 0x26, 0x05, 0x18, 0x63, 0x51, 0x58,
  32324. 0x51, 0x31, 0x42, 0x53, 0x84, 0x56, 0x66, 0x27,
  32325. 0x83, 0x33, 0x54, 0x50, 0x76, 0x46, 0x50, 0x80,
  32326. 0x25, 0x43, 0x41, 0x57, 0x35, 0x78, 0x25, 0x43,
  32327. 0x02, 0x82, 0x38, 0x47, 0x45, 0x70, 0x15, 0x67,
  32328. 0x51, 0x77, 0x47, 0x80, 0x31, 0x52, 0x75, 0x00,
  32329. 0x00, 0x94, 0x7B, 0xCA, 0x93, 0xC2, 0x7D, 0x58,
  32330. 0x4E, 0x2C, 0x66, 0xEA, 0xC9, 0xC7, 0x64, 0x0C,
  32331. 0x1C, 0xA2, 0x17, 0xEE, 0xF6, 0x6D, 0xAB, 0xBC,
  32332. 0xB2, 0x60, 0xB4, 0xC3, 0x43, 0x00, 0xFA, 0x05,
  32333. 0x13, 0x57, 0x82, 0x0F, 0x57, 0x39, 0x25, 0x44,
  32334. 0x98, 0x2F, 0xD1, 0x10, 0x57, 0xDE, 0x23, 0x3E,
  32335. 0x6D, 0x2D, 0xD8, 0x49, 0x72, 0xA7, 0xE4, 0x7D,
  32336. 0x4D, 0xBA, 0x99, 0xBC, 0x30, 0xCF, 0x8F, 0x2A,
  32337. 0xD5, 0xA2, 0xC0, 0x24, 0x31, 0x95, 0xED, 0x27,
  32338. 0x30, 0xFF, 0xA9, 0x2D, 0x22, 0x7D, 0x15, 0x30,
  32339. 0x95, 0x97, 0x2D, 0x4B, 0x34, 0x47, 0xFF, 0xAC,
  32340. 0x45, 0xA2, 0x3E, 0xB4, 0x1C, 0xBC, 0x87, 0xCD,
  32341. 0xD1, 0x25, 0x0A, 0x8A, 0x47, 0x8B, 0x0F, 0x7A,
  32342. 0x1D, 0x5B, 0x39, 0xAA, 0x22, 0x06, 0xE4, 0x86,
  32343. 0x45, 0x58, 0x4F, 0xE7, 0xBF, 0x7A, 0x13, 0x16,
  32344. 0x8F, 0x48, 0x27, 0x65, 0xE5, 0x7B, 0xB9, 0x24,
  32345. 0xAC, 0x6D, 0x9A, 0x11, 0x36, 0x9F, 0x4A, 0x6A,
  32346. 0xFF, 0xCD, 0x16, 0x9B, 0x7D, 0x75, 0x12, 0x9B,
  32347. 0x35, 0xD5, 0x13, 0x4A, 0x31, 0x76, 0x1B, 0xB8,
  32348. 0x35, 0x5A, 0xEE, 0xED, 0x27, 0xE2, 0x01, 0xA0,
  32349. 0x63, 0x13, 0x01, 0x3E, 0x30, 0x7A, 0x01, 0xA7,
  32350. 0x3A, 0xEA, 0x79, 0x55, 0xC0, 0x57, 0x8C, 0x8C,
  32351. 0x5E, 0x5A, 0x1A, 0x2D, 0x2F, 0xA4, 0x59, 0x3F,
  32352. 0xAC, 0xD9, 0x04, 0xC6, 0x20, 0x40, 0xBD, 0xB9,
  32353. 0xF3, 0x29, 0x93, 0x35, 0x36, 0xBF, 0x8D, 0x81,
  32354. 0xC4, 0x25, 0x6B, 0xAA, 0xE8, 0x72, 0x3F, 0xD4,
  32355. 0xDC, 0x66, 0xBB, 0x5E, 0x7F, 0x9C, 0xA4, 0x90,
  32356. 0x31, 0xA1, 0x93, 0xEC, 0xEC, 0xBB, 0x5D, 0xC3,
  32357. 0x90, 0xEC, 0x6D, 0x55, 0x13, 0xC7, 0x9A, 0x05,
  32358. 0x2B, 0x3F, 0xD4, 0x36, 0x12, 0xFB, 0x73, 0x75,
  32359. 0x31, 0x5D, 0x80, 0x91, 0xF7, 0x9B, 0xAB, 0x13,
  32360. 0x18, 0xF1, 0x78, 0x54, 0x56, 0x1B, 0xC9, 0x3A,
  32361. 0xE0, 0xE5, 0xCD, 0x6D, 0x13, 0x1E, 0x56, 0x2C,
  32362. 0x81, 0x14, 0x81, 0x0C, 0x93, 0x9A, 0xE5, 0x63,
  32363. 0xAA, 0x10, 0xB4, 0x7C, 0xE4, 0x48, 0x43, 0x17,
  32364. 0xF3, 0x4A, 0xBD, 0x02, 0xD0, 0xCC, 0xAD, 0x58,
  32365. 0xDD, 0x29, 0xBC, 0xF6, 0x57, 0xBB, 0xD9, 0x25,
  32366. 0x4B, 0x01, 0xCA, 0x97, 0x26, 0x09, 0x19, 0x38,
  32367. 0xED, 0x32, 0x05, 0x4B, 0x37, 0xDD, 0x61, 0x72,
  32368. 0x40, 0xF4, 0x43, 0x4C, 0x1A, 0x4A, 0x87, 0x11,
  32369. 0xAA, 0x3A, 0x39, 0x9A, 0x8A, 0x53, 0x88, 0x33,
  32370. 0x0B, 0x70, 0x59, 0xEC, 0xCB, 0xB6, 0xB1, 0xB9,
  32371. 0xCF, 0x71, 0x87, 0xAD, 0xF1, 0x0B, 0x0C, 0x91,
  32372. 0x71, 0xD3, 0xC0, 0xF6, 0xE2, 0xD4, 0x60, 0xA4,
  32373. 0x19, 0x24, 0x76, 0x72, 0xE3, 0xB9, 0xFE, 0xA2,
  32374. 0xC9, 0x59, 0x10, 0xBF, 0x2F, 0xB6, 0xA5, 0xD6,
  32375. 0x1F, 0x25, 0x74, 0x53, 0xB0, 0x7A, 0xFB, 0x64,
  32376. 0xB0, 0xBA, 0x27, 0x58, 0xBC, 0xD7, 0x35, 0x75,
  32377. 0x1F, 0x2D, 0x53, 0x51, 0x5E, 0x23, 0x6F, 0xE8,
  32378. 0xA5, 0xB4, 0x39, 0x3B, 0x80, 0xBF, 0x06, 0xDF,
  32379. 0x97, 0xBD, 0xC6, 0x38, 0x00, 0x87, 0xE6, 0xAA,
  32380. 0x8D, 0xDE, 0x6E, 0x09, 0x81, 0x11, 0xA7, 0x34,
  32381. 0x3F, 0xCD, 0xD1, 0xE9, 0x03, 0x70, 0x8E, 0x63,
  32382. 0x7E, 0xBF, 0x28, 0x32, 0x3C, 0xDA, 0x6B, 0x94,
  32383. 0x05, 0x81, 0x0E, 0xDC, 0xFB, 0x36, 0x91, 0x14,
  32384. 0x9E, 0xCF, 0x22, 0x4C, 0x50, 0xF8, 0xDF, 0x92,
  32385. 0xA9, 0x4A, 0xA4, 0x77, 0x0A, 0x0E, 0x91, 0x46,
  32386. 0x61, 0x94, 0xBB, 0x0E, 0x27, 0xBF, 0x1C, 0xAB,
  32387. 0xF1, 0x6A, 0xDF, 0xD3, 0x51, 0x22, 0x00, 0x33,
  32388. 0xF7, 0x6F, 0x59, 0x25, 0x55, 0x7B, 0xCF, 0x96,
  32389. 0x34, 0xE9, 0x46, 0x13, 0x59, 0x62, 0x1D, 0x80,
  32390. 0xB4, 0xBB, 0xAD, 0x7E, 0x2A, 0x6E, 0x43, 0x2D,
  32391. 0xC4, 0x3B, 0x12, 0x6C, 0xA4, 0x2A, 0xB8, 0x8A,
  32392. 0xA8, 0x8F, 0x0A, 0x84, 0xAF, 0x58, 0x02, 0x9C,
  32393. 0x99, 0xA0, 0x24, 0x8F, 0x0C, 0x45, 0x40, 0x71,
  32394. 0xF3, 0x5B, 0x83, 0x1F, 0xED, 0x12, 0x54, 0xD6,
  32395. 0xF4, 0xE2, 0x72, 0x04, 0x85, 0x78, 0x62, 0x15,
  32396. 0xF7, 0xC7, 0xF0, 0xC4, 0xED, 0x15, 0xFA, 0x85,
  32397. 0x3C, 0xD3, 0xAA, 0x07, 0x25, 0x9B, 0x39, 0x24,
  32398. 0x0A, 0x82, 0x13, 0x5C, 0x29, 0x23, 0xA7, 0x2B,
  32399. 0x87, 0x6F, 0xAB, 0xB3, 0xF0, 0xF2, 0xC0, 0x96,
  32400. 0x13, 0xDE, 0x39, 0xD4, 0x59, 0xA0, 0x7C, 0x14,
  32401. 0xE7, 0xBA, 0x43, 0x7D, 0x80, 0x41, 0x49, 0x1F,
  32402. 0xCE, 0xC1, 0x43, 0x34, 0x04, 0xBA, 0xD1, 0xDA,
  32403. 0x9E, 0xE9, 0x47, 0x1E, 0x17, 0xCB, 0x69, 0x1B,
  32404. 0x2A, 0x35, 0x37, 0x10, 0xC9, 0xFF, 0xA4, 0xE5,
  32405. 0x17, 0x81, 0x12, 0x02, 0x77, 0x64, 0xEB, 0x7D,
  32406. 0xE8, 0x09, 0xC3, 0xE1, 0xF1, 0xFA, 0x41, 0x78,
  32407. 0xA5, 0xD4, 0xDC, 0x9E, 0xE2, 0x78, 0x57, 0xEF,
  32408. 0xF2, 0x6B, 0x91, 0x71, 0x1F, 0xC1, 0x44, 0xD5,
  32409. 0xA7, 0x75, 0xB8, 0xB5, 0x0D, 0x5D, 0xB9, 0x39,
  32410. 0xBA, 0x32, 0x07, 0x68, 0x0C, 0x24, 0x2F, 0xC8,
  32411. 0x21, 0x94, 0x7F, 0x93, 0x4C, 0x8D, 0xAE, 0xE2,
  32412. 0x03, 0x56, 0x3D, 0x28, 0x60, 0x6B, 0xE6, 0x24,
  32413. 0xA3, 0x29, 0x01, 0x93, 0x2D, 0xAE, 0x85, 0x71,
  32414. 0x2A, 0xF6, 0xC8, 0x01, 0x60, 0x26, 0x92, 0x7E,
  32415. 0x9B, 0x81, 0x29, 0x57, 0x4B, 0xE3, 0xCB, 0x1E,
  32416. 0x95, 0x33, 0x2B, 0x05, 0x27, 0x07, 0xAC, 0x8A,
  32417. 0xA8, 0xF4, 0x35, 0xE8, 0x8B, 0x7E, 0x56, 0x8D,
  32418. 0x49, 0x87, 0xC6, 0xAC, 0x0E, 0x90, 0x2B, 0x06,
  32419. 0x09, 0xA0, 0x2D, 0x91, 0xB3, 0xF5, 0xFD, 0x3F,
  32420. 0xD9, 0x01, 0xDD, 0xD0, 0xDB, 0x98, 0x73, 0xBD,
  32421. 0x7C, 0x71, 0xED, 0x92, 0x1D, 0x45, 0x77, 0xA7,
  32422. 0x8C, 0x4F, 0xCC, 0x9B, 0xF0, 0x75, 0x20, 0x3D,
  32423. 0x38, 0xF5, 0xE7, 0x6E, 0x74, 0xF2, 0x77, 0x48,
  32424. 0x4E, 0x05, 0x7B, 0x61, 0x89, 0x00, 0x41, 0x31,
  32425. 0xB0, 0xC9, 0xB1, 0xA1, 0x55, 0x29, 0x4D, 0x1C,
  32426. 0xD3, 0xD5, 0x20, 0x8E, 0x26, 0x69, 0x01, 0xD7,
  32427. 0xD3, 0x14, 0xFA, 0xCC, 0xE7, 0xE2, 0xAA, 0x58,
  32428. 0x45, 0x83, 0xA1, 0x1E, 0x4D, 0x7C, 0x21, 0xB9,
  32429. 0x4A, 0x32, 0xE5, 0x08, 0xED, 0xDB, 0xBD, 0x7A,
  32430. 0x65, 0xAA, 0x86, 0xB4, 0xFD, 0xFA, 0x6B, 0xC2,
  32431. 0x85, 0xD4, 0xCF, 0xF5, 0x39, 0x26, 0xC7, 0x17,
  32432. 0x3F, 0xBE, 0x1F, 0x89, 0xCC, 0x30, 0x32, 0x34,
  32433. 0xB8, 0x78, 0xC6, 0xB8, 0x10, 0x1F, 0x58, 0xAC,
  32434. 0x8D, 0x3E, 0x5E, 0x1B, 0xF5, 0xAB, 0x6B, 0x26,
  32435. 0x29, 0x7C, 0xC9, 0x7B, 0x95, 0x95, 0x4A, 0xAB,
  32436. 0xDB, 0x25, 0xBE, 0x00, 0x8A, 0x3F, 0x47, 0xE5,
  32437. 0x64, 0x87, 0xB0, 0x0D, 0x3D, 0xED, 0xA8, 0x90,
  32438. 0xD9, 0x2C, 0x83, 0x95, 0x7F, 0xEA, 0xC6, 0xB8,
  32439. 0x29, 0x1A, 0xF6, 0x59, 0x59, 0xE1, 0xD1, 0xFC,
  32440. 0xA3, 0xBD, 0x19, 0x6E, 0x9F, 0xC9, 0xE6, 0x7E,
  32441. 0x06, 0x07, 0x09, 0x48, 0x22, 0xE5, 0xB4, 0x19,
  32442. 0x1D, 0xB9, 0x68, 0x24, 0xB9, 0xF0, 0x3F, 0x2E,
  32443. 0xF5, 0x7F, 0x52, 0x38, 0xBA, 0x7E, 0x1E, 0x84,
  32444. 0xED, 0x55, 0xB7, 0xDF, 0xF3, 0xD6, 0xC2, 0xC1,
  32445. 0x27, 0x36, 0x92, 0xA9, 0xA1, 0x92, 0x72, 0x16,
  32446. 0x61, 0x30, 0xDB, 0x89, 0xFC, 0x67, 0xDC, 0x94,
  32447. 0xDB, 0x61, 0x4E, 0x3E, 0x82, 0xBA, 0x3A, 0x35,
  32448. 0x12, 0xB0, 0x12, 0xD5, 0x1F, 0xB4, 0x86, 0xB5,
  32449. 0xA3, 0x15, 0x0B, 0x78, 0xE7, 0x24, 0xE2, 0xA1,
  32450. 0x2D, 0xE0, 0x7D, 0x86, 0x71, 0xFB, 0xA2, 0xDA,
  32451. 0x7F, 0xD5, 0xD1, 0x47, 0x20, 0x8F, 0xC3, 0xAF,
  32452. 0x65, 0x3E, 0x65, 0x20, 0xFC, 0x40, 0x87, 0x1A,
  32453. 0xF2, 0x17, 0x7E, 0x65, 0xCB, 0xD0, 0xEA, 0xF3,
  32454. 0x04, 0x21, 0x7B, 0x36, 0x7A, 0x66, 0x5F, 0x22,
  32455. 0x4C, 0xAE, 0xDF, 0xE9, 0x30, 0x06, 0xAC, 0x1E,
  32456. 0x14, 0xBC, 0xD6, 0x7A, 0x88, 0xD1, 0x71, 0xF3,
  32457. 0xD8, 0xF3, 0xE3, 0x58, 0xA7, 0x19, 0x26, 0xBA,
  32458. 0x3E, 0x5C, 0x23, 0x9A, 0x53, 0x12, 0x63, 0xEC,
  32459. 0x94, 0x37, 0xBF, 0x2A, 0x03, 0x3B, 0x8B, 0x55,
  32460. 0xB2, 0xC0, 0xCB, 0x6E, 0x7E, 0x97, 0x31, 0x6E,
  32461. 0x22, 0xDF, 0x77, 0xCA, 0xD9, 0x10, 0xD2, 0x0E,
  32462. 0xEC, 0xE1, 0xC5, 0x09, 0x10, 0xA5, 0xCC, 0x32,
  32463. 0xAD, 0xAB, 0x09, 0x37, 0x75, 0x50, 0xF9, 0x2D,
  32464. 0x5B, 0xB1, 0xF4, 0xC0, 0x7F, 0x4A, 0x28, 0x22,
  32465. 0x33, 0x8E, 0x2C, 0xFF, 0x53, 0x48, 0xDF, 0x77,
  32466. 0xCF, 0x8E, 0xF8, 0xE6, 0x65, 0x7D, 0xED, 0x1E,
  32467. 0x0C, 0xE0, 0x58, 0xE3, 0xCC, 0xFB, 0xF3, 0x9B,
  32468. 0x3F, 0x16, 0x6E, 0x30, 0x3D, 0x33, 0xC3, 0x55,
  32469. 0x6C, 0x9A, 0xC8, 0xEC, 0xB3, 0xDF, 0x7C, 0x74,
  32470. 0xAB, 0x36, 0xD0, 0xF2, 0x79, 0x44, 0x41, 0xBA,
  32471. 0x98, 0x08, 0x82, 0x7B, 0x57, 0x8F, 0xB5, 0xC2,
  32472. 0x9E, 0x49, 0x4E, 0x21, 0x53, 0x9A, 0xD3, 0xAB,
  32473. 0x2B, 0x41, 0xBF, 0x16, 0x1D, 0x7F, 0x69, 0x58,
  32474. 0x9D, 0x45, 0x24, 0xC5, 0x4C, 0x89, 0xB4, 0x86,
  32475. 0xF7, 0x5D, 0x25, 0x2F, 0x54, 0x1C, 0xC6, 0x3B,
  32476. 0x9E, 0x70, 0x6D, 0x64, 0xA1, 0x28, 0x9A, 0x23,
  32477. 0x06, 0xC5, 0x95, 0x36, 0x3C, 0xB6, 0xFB, 0xEF,
  32478. 0x0A, 0x1B, 0x5B, 0x17, 0xAB, 0x5B, 0x17, 0x94,
  32479. 0xBF, 0x27, 0x03, 0x6F, 0x64, 0xEA, 0xF0, 0xBD,
  32480. 0x43, 0x0D, 0xD5, 0x8D, 0x80, 0x01, 0x0C, 0xCD,
  32481. 0xAD, 0xA4, 0xA5, 0xA3, 0xA1, 0xE4, 0x1A, 0x6F,
  32482. 0xBF, 0x12, 0x9D, 0x73, 0x77, 0x9A, 0x37, 0xAE,
  32483. 0x5C, 0x8D, 0x68, 0x41, 0xA9, 0x99, 0x3C, 0x51,
  32484. 0xE3, 0x64, 0xE0, 0x4F, 0xAC, 0x8E, 0x25, 0xA4,
  32485. 0xE6, 0x87, 0x2F, 0x6C, 0x86, 0x0F, 0xA2, 0x65,
  32486. 0xC1, 0xC4, 0x42, 0x6A, 0xD9, 0xC2, 0x1D, 0x26,
  32487. 0xDA, 0x8C, 0x27, 0x85, 0x46, 0xAD, 0xCD, 0x83,
  32488. 0x1F, 0x2B, 0x8B, 0x26, 0xD4, 0xE1, 0xF6, 0x70,
  32489. 0x62, 0x3D, 0x95, 0xC8, 0x36, 0x2D, 0xA6, 0x62,
  32490. 0xD1, 0xFF, 0x0A, 0xB6, 0x87, 0x50, 0x3F, 0x32,
  32491. 0x8D, 0xE0, 0x95, 0x81, 0x0E, 0xDE, 0x12, 0xB4,
  32492. 0x9E, 0xAD, 0x15, 0x33, 0x51, 0x95, 0x58, 0xC1,
  32493. 0xE9, 0x40, 0xB4, 0x6E, 0x4E, 0xDB, 0x02, 0x7B,
  32494. 0xE9, 0xDA, 0x20, 0x39, 0xB2, 0x5D, 0xCF, 0x73,
  32495. 0x57, 0xE1, 0x9E, 0x54, 0x16, 0xAE, 0x26, 0x8C,
  32496. 0x14, 0xFB, 0x3A, 0x8B, 0xAB, 0xCB, 0x3D, 0x23,
  32497. 0xF7, 0x0C, 0xC9, 0xD5, 0x96, 0x81, 0xC5, 0xD8,
  32498. 0x33, 0xAC, 0x22, 0xE6, 0x53, 0xD8, 0x6E, 0x22,
  32499. 0xCE, 0x82, 0x25, 0x40, 0x75, 0x5D, 0x8D, 0x24,
  32500. 0x3C, 0x15, 0x21, 0x3D, 0x07, 0x6C, 0x6B, 0x26,
  32501. 0x43, 0x6D, 0xDC, 0x07, 0xC7, 0xE0, 0x01, 0x34,
  32502. 0x7B, 0x0C, 0xB8, 0x78, 0x3D, 0xFE, 0xFE, 0xDF,
  32503. 0x27, 0x5F, 0xEC, 0x47, 0x92, 0x68, 0x67, 0x34,
  32504. 0x00, 0x7F, 0x0F, 0xF8, 0x54, 0x08, 0x11, 0xC2,
  32505. 0xAF, 0xE6, 0xCA, 0x15, 0x14, 0x20, 0x53, 0x2F,
  32506. 0xA5, 0x52, 0x6A, 0x10, 0x74, 0xC3, 0xD7, 0x89,
  32507. 0xF2, 0x93, 0x2D, 0xE4, 0x2E, 0x3A, 0xCF, 0xBF,
  32508. 0x94, 0x76, 0x0F, 0x42, 0x6D, 0x96, 0xCF, 0x03,
  32509. 0x3F, 0xA4, 0x9E, 0x2F, 0x45, 0x8F, 0x9A, 0x9C,
  32510. 0x2E, 0x71, 0xDA, 0xCF, 0xE0, 0x09, 0xDD, 0x9C,
  32511. 0x3F, 0x3C, 0x8A, 0xB3, 0x28, 0x2D, 0x6F, 0x38,
  32512. 0x3B, 0x98, 0x1C, 0x82, 0xD6, 0x36, 0x4F, 0x0E,
  32513. 0x4B, 0xDB, 0x2A, 0xF6, 0xA9, 0x5B, 0xA6, 0x1F,
  32514. 0x47, 0x41, 0x50, 0xCA, 0xD7, 0x23, 0x3F, 0x89,
  32515. 0x03, 0xDF, 0x97, 0x2D, 0xBB, 0x03, 0x28, 0xC0,
  32516. 0xCB, 0x9D, 0x0C, 0xCB, 0xEF, 0x88, 0x3D, 0x2E,
  32517. 0x6A, 0xDD, 0x18, 0x0E, 0xCA, 0x1B, 0x66, 0x2F,
  32518. 0xC1, 0xD2, 0xDB, 0xBD, 0xDB, 0x36, 0x34, 0x21,
  32519. 0x9E, 0x1E, 0xFF, 0x38, 0xB1, 0xE5, 0x28, 0x75,
  32520. 0x35, 0x6C, 0x03, 0xEA, 0xDE, 0x94, 0x20, 0x55,
  32521. 0xF4, 0x83, 0x50, 0x4B, 0xBB, 0xCB, 0x43, 0x02,
  32522. 0xA4, 0x17, 0xCF, 0x6D, 0x32, 0x8E, 0xD7, 0x93,
  32523. 0xB1, 0xA3, 0xC0, 0x96, 0x9B, 0x7B, 0x34, 0x18,
  32524. 0xF5, 0x0A, 0xB3, 0x9F, 0x83, 0xC5, 0x66, 0x6C,
  32525. 0x90, 0xE3, 0x83, 0x56, 0xF7, 0xF9, 0xD4, 0x94,
  32526. 0xA6, 0xDC, 0xB6, 0x3D, 0x67, 0xC3, 0x4E, 0x3D,
  32527. 0x14, 0xA4, 0xE1, 0x55, 0x96, 0x49, 0x79, 0x26,
  32528. 0xC8, 0x56, 0x8D, 0x8E, 0xC3, 0xDB, 0xD9, 0xC2,
  32529. 0xE8, 0x2C, 0x38, 0x5B, 0xCF, 0xB8, 0xD9, 0x67,
  32530. 0x48, 0x63, 0xBD, 0x4F, 0xBF, 0x17, 0x57, 0xDB,
  32531. 0x44, 0x7B, 0xF8, 0x04, 0xAE, 0x95, 0x01, 0x47,
  32532. 0xC9, 0x1F, 0xBF, 0x9A, 0xA1, 0x78, 0x91, 0x04,
  32533. 0x4C, 0xCA, 0xA7, 0x3B, 0x45, 0x52, 0x85, 0x97,
  32534. 0x46, 0x2C, 0xED, 0x75, 0x1D, 0x01, 0x5E, 0xBB,
  32535. 0xA9, 0xE2, 0xB7, 0xCD, 0xCB, 0xE6, 0xDC, 0x05,
  32536. 0xAA, 0x9E, 0xAE, 0x0C, 0x86, 0x84, 0x8A, 0x34,
  32537. 0x75, 0xBB, 0x1C, 0x57, 0x44, 0xF5, 0x90, 0x3E,
  32538. 0xE4, 0xA8, 0x42, 0xA4, 0x69, 0xCC, 0x18, 0x12,
  32539. 0x71, 0xF2, 0x45, 0xAD, 0x70, 0xD0, 0x2A, 0x48,
  32540. 0x37, 0x86, 0x3B, 0x29, 0x6B, 0x4A, 0xDB, 0x4E,
  32541. 0x8D, 0x03, 0xD8, 0x2B, 0x64, 0xAA, 0x11, 0xDD,
  32542. 0x31, 0xCD, 0xF2, 0x1E, 0xDF, 0x1D, 0xFE, 0x32,
  32543. 0x76, 0xC4, 0xDB, 0xC8, 0x77, 0xE3, 0x5B, 0x15,
  32544. 0xFB, 0x28, 0x35, 0xEC, 0x3A, 0x1C, 0x45, 0x31,
  32545. 0x68, 0xA3, 0x8C, 0xA8, 0xE5, 0x63, 0xCF, 0x3E,
  32546. 0x9A, 0x00, 0x73, 0x6C, 0xD5, 0xCF, 0xBD, 0x28,
  32547. 0x41, 0xD1, 0x0F, 0x94, 0xAD, 0x55, 0x79, 0x9C,
  32548. 0x29, 0x27, 0xE5, 0x46, 0x1B, 0x28, 0xBA, 0xC5,
  32549. 0x17, 0x4D, 0x0C, 0xE3, 0xF8, 0xF7, 0xCD, 0x76,
  32550. 0x09, 0xFB, 0xC8, 0xDA, 0x0C, 0x38, 0xCC, 0x21,
  32551. 0x69, 0x5C, 0xED, 0xAD, 0x12, 0xF8, 0xD2, 0xE6,
  32552. 0x49, 0x51, 0xA8, 0x99, 0x6E, 0x51, 0x0D, 0x6D,
  32553. 0x52, 0x79, 0x7C, 0x5B, 0xA0, 0xEB, 0x4A, 0xFA,
  32554. 0x6B, 0xF2, 0xCC, 0x43, 0xDA, 0x09, 0xDE, 0x31,
  32555. 0x79, 0xE8, 0x99, 0xBD, 0x71, 0x88, 0xB3, 0x2A,
  32556. 0x98, 0xA4, 0x99, 0xD3, 0x72, 0xF3, 0x70, 0x7C,
  32557. 0xED, 0x47, 0x9B, 0x09, 0x81, 0xCB, 0x50, 0xC0,
  32558. 0xC0, 0x53, 0x9C, 0xF7, 0xE3, 0x10, 0x0B, 0x72,
  32559. 0x0E, 0x46, 0x66, 0x52, 0xA4, 0xF4, 0x99, 0xC2,
  32560. 0xBA, 0x3A, 0x17, 0xF5, 0x23, 0x22, 0x68, 0x73,
  32561. 0x0B, 0x96, 0x2B, 0xC5, 0x72, 0xC0, 0xDE, 0x96,
  32562. 0xE8, 0xC9, 0xE2, 0x8F, 0x7E, 0x35, 0x32, 0xC2,
  32563. 0x22, 0x41, 0x96, 0xAA, 0x9E, 0x27, 0x68, 0x8D,
  32564. 0xD0, 0x50, 0xD7, 0xCB, 0x78, 0x54, 0xFB, 0x3C,
  32565. 0x35, 0xF9, 0xC6, 0x2E, 0xFB, 0x10, 0xDA, 0x84,
  32566. 0x83, 0x3F, 0x29, 0xBB, 0x1B, 0xE5, 0xEF, 0x3B,
  32567. 0x53, 0x36, 0x38, 0xEE, 0xF7, 0x43, 0xD8, 0x11,
  32568. 0x9D, 0xDC, 0x29, 0x0B, 0xDF, 0x08, 0xB6, 0xF0,
  32569. 0xF9, 0xE4, 0xE1, 0xE1, 0x34, 0x46, 0xC5, 0x3E,
  32570. 0xD6, 0x98, 0x05, 0xDA, 0x26, 0x90, 0x8A, 0x15,
  32571. 0xDF, 0x1C, 0x48, 0xE0, 0x09, 0xEC, 0x12, 0x53,
  32572. 0xBD, 0x5A, 0x58, 0x98, 0xEB, 0xB5, 0x12, 0x1C,
  32573. 0xC2, 0x49, 0x04, 0xC8, 0xB1, 0x0E, 0x24, 0xE6,
  32574. 0x80, 0xE5, 0x65, 0x98, 0x50, 0x76, 0xFD, 0xA1,
  32575. 0x1D, 0x13, 0xFF, 0xDF, 0xA4, 0xDB, 0x28, 0xAC,
  32576. 0x9F, 0x0A, 0xEA, 0x2F, 0x81, 0xFD, 0x7E, 0xD4,
  32577. 0xDC, 0xA8, 0xD3, 0xB2, 0xE3, 0x84, 0x8B, 0x4D,
  32578. 0x60, 0x46, 0xF6, 0xE0, 0xDE, 0x3A, 0x4F, 0x68,
  32579. 0x3F, 0x25, 0xE0, 0x60, 0x5E, 0x84, 0xB3, 0x6F,
  32580. 0x48, 0x3C, 0x40, 0x4E, 0xF8, 0x99, 0xCB, 0x3F,
  32581. 0xCC, 0xBE, 0x8C, 0xB2, 0xA6, 0xF0, 0xA7, 0xE1,
  32582. 0x0B, 0x19, 0x48, 0xCD, 0x4F, 0x93, 0xF1, 0x81,
  32583. 0x55, 0x5F, 0x66, 0x1D, 0x31, 0xD4, 0x26, 0x80,
  32584. 0x8B, 0xBF, 0x9F, 0x66, 0xFD, 0x60, 0xD6, 0x49,
  32585. 0x26, 0x9C, 0xA3, 0xFE, 0x99, 0x1B, 0x22, 0x42,
  32586. 0x8C, 0x37, 0xAD, 0x2A, 0x08, 0x68, 0x0F, 0x74,
  32587. 0x7C, 0xC0, 0x36, 0x0C, 0xCD, 0x37, 0x3D, 0xC6,
  32588. 0xA9, 0xF4, 0x3A, 0x66, 0x47, 0x0E, 0x01, 0x4E,
  32589. 0x72, 0xB3, 0xD8, 0xC3, 0x8E, 0x02, 0x04, 0x42,
  32590. 0xD8, 0xAA, 0xB9, 0x74, 0xE6, 0x04, 0x93, 0x74,
  32591. 0x14, 0x5B, 0x04, 0xCB, 0x7F, 0x30, 0x44, 0xAA,
  32592. 0xC1, 0xEF, 0xDA, 0xB2, 0xA1, 0x8B, 0xB4, 0x64,
  32593. 0xD4, 0xF2, 0xF2, 0xD8, 0x14, 0x39, 0x74, 0xC9,
  32594. 0x5E, 0xEE, 0x85, 0x6D, 0x59, 0xEC, 0x00, 0x28,
  32595. 0x8E, 0xD4, 0x3F, 0xF5, 0xCC, 0x88, 0x03, 0x00,
  32596. 0x6C, 0x99, 0x55, 0x14, 0xA2, 0xCC, 0x9C, 0xA6,
  32597. 0x22, 0xB6, 0x1B, 0xCD, 0x75, 0xEC, 0x51, 0xC2,
  32598. 0x02, 0xA9, 0x17, 0x10, 0x5B, 0x4A, 0x4B, 0xED,
  32599. 0x1B, 0x80, 0x14, 0x68, 0x31, 0xDC, 0xED, 0x07,
  32600. 0xEF, 0xD2, 0xED, 0x25, 0x73, 0x9F, 0x54, 0x09,
  32601. 0x69, 0x11, 0xB1, 0x50, 0xD3, 0x07, 0x7C, 0xCD,
  32602. 0x73, 0x1A, 0x03, 0x61, 0x68, 0x27, 0x25, 0xD5,
  32603. 0x38, 0x03, 0xF8, 0xFC, 0xEA, 0xA8, 0x39, 0x19,
  32604. 0x29, 0x1E, 0xDB, 0x44, 0x93, 0xEC, 0x84, 0xCC,
  32605. 0xE1, 0xD0, 0xF8, 0x2A, 0x67, 0x92, 0x36, 0xEA,
  32606. 0xD1, 0x00, 0x2A, 0xE8, 0x01, 0x8C, 0xAC, 0x9F,
  32607. 0xDB, 0xD2, 0x46, 0xFF, 0x09, 0x3D, 0x80, 0x3C,
  32608. 0x0D, 0xE3, 0x32, 0x6A, 0x57, 0x90, 0x7B, 0x0D,
  32609. 0xD6, 0xB0, 0x1D, 0x08, 0x14, 0x58, 0xC7, 0x57,
  32610. 0x28, 0xC6, 0x00, 0x82, 0x99, 0x28, 0x89, 0x0A,
  32611. 0x56, 0xAA, 0xAF, 0xEF, 0xCF, 0x74, 0x23, 0xB7,
  32612. 0x0A, 0x6D, 0x86, 0xB4, 0x15, 0xB8, 0x35, 0x8D,
  32613. 0xD0, 0x44, 0xAB, 0xEE, 0x00, 0xB9, 0xC9, 0x79,
  32614. 0x5F, 0xC8, 0xF6, 0x1A, 0x64, 0x68, 0x6D, 0xF5,
  32615. 0xF8, 0x76, 0xA8, 0xF3, 0x30, 0x61, 0x59, 0x9A,
  32616. 0xE8, 0x30, 0xF7, 0xEB, 0x4C, 0x4B, 0xFF, 0x87,
  32617. 0x5F, 0x4A, 0x93, 0x6C, 0x40, 0x3C, 0x5D, 0x16,
  32618. 0x0D, 0xE5, 0xD3, 0x3C, 0xAE, 0xE4, 0x0F, 0xB7,
  32619. 0x18, 0xDD, 0xA4, 0x47, 0x8A, 0xC6, 0xF5, 0x1C,
  32620. 0x59, 0xC2, 0x15, 0x52, 0x54, 0xBD, 0x77, 0x67,
  32621. 0x11, 0x18, 0x41, 0x1E, 0x26, 0x09, 0xD0, 0x00,
  32622. 0x30, 0x6F, 0xC9, 0x50, 0x70, 0x04, 0xA3, 0x1E,
  32623. 0x89, 0x57, 0xEA, 0x40, 0xC2, 0x56, 0x4B, 0x83,
  32624. 0xC3, 0xAB, 0xB7, 0x1A, 0x87, 0xC1, 0x1B, 0xD1,
  32625. 0x8D, 0x78, 0x91, 0xC4, 0x49, 0xDB, 0xBE, 0x79,
  32626. 0xB4, 0xA4, 0xFB, 0x04, 0x83, 0x07, 0xCE, 0x0E,
  32627. 0x81, 0x2B, 0x2C, 0x68, 0xEC, 0xAB, 0x77, 0xFD,
  32628. 0x11, 0x11, 0x52, 0x6A, 0xB0, 0x81, 0x73, 0x06,
  32629. 0xCE, 0xBC, 0xB0, 0x49, 0x7C, 0x55, 0x24, 0x31,
  32630. 0xCE, 0x15, 0xE4, 0xAB, 0x52, 0x28, 0x3F, 0x67,
  32631. 0x94, 0x80, 0xD6, 0x9D, 0xDD, 0xE1, 0xF2, 0x57,
  32632. 0x9C, 0xFD, 0xBE, 0x0B, 0xCA, 0x95, 0xFC, 0x5B,
  32633. 0x2D, 0xB0, 0xC5, 0xCC, 0x76, 0xA3, 0x19, 0x50,
  32634. 0xF5, 0x11, 0x6A, 0xAE, 0x5F, 0x02, 0xD4, 0x67,
  32635. 0x10, 0xE4, 0x25, 0x7A, 0x75, 0xFD, 0xED, 0xF2,
  32636. 0xF4, 0x7C, 0xE3, 0x7C, 0x20, 0x3E, 0x7F, 0x24,
  32637. 0xD3, 0xC9, 0x17, 0x97, 0x13, 0xC5, 0xD8, 0x07,
  32638. 0xC2, 0x96, 0x14, 0x9A, 0x75, 0xCC, 0xB4, 0x44,
  32639. 0xF0, 0xC6, 0xF6, 0xAB, 0xDD, 0x2D, 0xBB, 0x29,
  32640. 0x85, 0xFE, 0x26, 0x74, 0x82, 0x85, 0x8A, 0x1E
  32641. };
  32642. #endif /* WOLFSSL_NO_ML_DSA_65 */
  32643. #ifndef WOLFSSL_NO_ML_DSA_87
  32644. static const byte seed_87[] = {
  32645. 0x38, 0x35, 0x9F, 0xBC, 0xD7, 0x95, 0x82, 0xCF,
  32646. 0xFE, 0x60, 0x9E, 0x13, 0x7E, 0xE2, 0xEF, 0xE8,
  32647. 0xA8, 0xDB, 0xCB, 0xAD, 0x18, 0xBA, 0x92, 0xBB,
  32648. 0x43, 0x3A, 0xB4, 0xF0, 0x9B, 0x49, 0x29, 0x9D
  32649. };
  32650. static const byte pk_87[] = {
  32651. 0x69, 0x24, 0xBB, 0x42, 0x57, 0xA7, 0xB9, 0xAF,
  32652. 0xF0, 0x95, 0xC3, 0x0B, 0xB3, 0x5C, 0x6A, 0xE4,
  32653. 0x19, 0x82, 0x63, 0x12, 0x0F, 0x80, 0x39, 0xAA,
  32654. 0x4E, 0x78, 0xE1, 0x74, 0xA7, 0x86, 0xCE, 0x00,
  32655. 0x83, 0x01, 0xE6, 0x66, 0xF5, 0x9D, 0x3E, 0xC5,
  32656. 0x04, 0x4D, 0xE4, 0x56, 0x78, 0x8F, 0xDE, 0x19,
  32657. 0xEB, 0x39, 0x67, 0x7B, 0x5F, 0x9F, 0xE1, 0x41,
  32658. 0x50, 0xDA, 0x46, 0x3A, 0x70, 0x6F, 0x3B, 0xAF,
  32659. 0x71, 0x5B, 0x95, 0x33, 0x6B, 0x2D, 0x68, 0x5A,
  32660. 0x7C, 0xD7, 0x88, 0x07, 0x13, 0xE4, 0x58, 0x7B,
  32661. 0xF7, 0xD8, 0x57, 0xBF, 0x7E, 0x31, 0x56, 0x96,
  32662. 0xB8, 0xD0, 0xD9, 0xD4, 0x9E, 0x14, 0x29, 0x18,
  32663. 0xBF, 0x09, 0x74, 0xE7, 0xF4, 0x32, 0x37, 0xD4,
  32664. 0xBE, 0x3A, 0xD3, 0x94, 0x59, 0x9E, 0x3D, 0x39,
  32665. 0xBB, 0x76, 0x49, 0x93, 0x25, 0x53, 0x44, 0x7E,
  32666. 0x5D, 0x5A, 0xCC, 0x34, 0x99, 0x93, 0x01, 0x76,
  32667. 0xEC, 0xD3, 0xA8, 0x44, 0xA4, 0x25, 0xF5, 0x0D,
  32668. 0x05, 0x11, 0xC9, 0x22, 0x6C, 0x4B, 0x9A, 0x24,
  32669. 0xF2, 0xA0, 0x11, 0xCD, 0x88, 0xD3, 0x23, 0x08,
  32670. 0xE0, 0x31, 0x2A, 0x0C, 0x87, 0xCC, 0x34, 0xA9,
  32671. 0x95, 0x82, 0x3C, 0x65, 0xF4, 0xF0, 0xF9, 0x8E,
  32672. 0x50, 0xC3, 0x77, 0x88, 0xCE, 0x38, 0xDC, 0x28,
  32673. 0xFB, 0x8B, 0x9B, 0xFA, 0xAF, 0xA9, 0x04, 0xB5,
  32674. 0x41, 0xEE, 0x71, 0x2F, 0x6A, 0x04, 0x1E, 0x06,
  32675. 0x11, 0x37, 0x4F, 0x6B, 0xF1, 0x7E, 0xAC, 0x0B,
  32676. 0xD5, 0x6F, 0x3B, 0x6B, 0xF3, 0x36, 0xDA, 0x92,
  32677. 0x42, 0x07, 0x0C, 0x24, 0x69, 0xA2, 0x0C, 0x4D,
  32678. 0x16, 0x16, 0x14, 0x9A, 0x61, 0x59, 0x25, 0x20,
  32679. 0x11, 0xD2, 0x99, 0xF9, 0x3F, 0x98, 0x6D, 0x87,
  32680. 0x5D, 0xD3, 0x0B, 0x38, 0xA2, 0x25, 0x49, 0x17,
  32681. 0x45, 0x70, 0x13, 0x8C, 0x2B, 0xB3, 0xAA, 0x9C,
  32682. 0xBE, 0xA9, 0x19, 0x74, 0xF3, 0xD8, 0x9B, 0xF5,
  32683. 0xAE, 0x32, 0xBE, 0x9E, 0x58, 0xB8, 0x54, 0xA2,
  32684. 0xF8, 0xE8, 0x6F, 0xF7, 0x67, 0x80, 0xC0, 0x34,
  32685. 0x90, 0xF4, 0x67, 0xDB, 0x06, 0x51, 0xC2, 0x0B,
  32686. 0x1D, 0xF6, 0x0E, 0xB9, 0x7A, 0x3C, 0x99, 0xD9,
  32687. 0xBD, 0x66, 0x4B, 0xE6, 0xA5, 0xE4, 0xC8, 0xA8,
  32688. 0xAD, 0x4C, 0xC3, 0x63, 0x90, 0xD7, 0x00, 0x4E,
  32689. 0x4B, 0xB4, 0x21, 0xDA, 0xED, 0x65, 0x4C, 0x35,
  32690. 0x7D, 0xA4, 0xD6, 0x84, 0x98, 0x93, 0x3E, 0xC7,
  32691. 0x17, 0x77, 0xAD, 0x64, 0xC2, 0xAE, 0x01, 0x3C,
  32692. 0x73, 0xEB, 0x45, 0x7C, 0x68, 0xEF, 0x9A, 0x74,
  32693. 0x5A, 0xDE, 0xEB, 0x4F, 0xDF, 0xC8, 0x79, 0xE7,
  32694. 0x74, 0xD0, 0x3F, 0xAF, 0x6B, 0x14, 0xAA, 0xB1,
  32695. 0x07, 0x52, 0xE2, 0x4B, 0x52, 0xD0, 0xF2, 0xD9,
  32696. 0x4D, 0x54, 0x0A, 0x1E, 0xBE, 0x10, 0xF5, 0x97,
  32697. 0xE5, 0x14, 0x44, 0x2D, 0x6C, 0x13, 0xC2, 0xE2,
  32698. 0x49, 0x8E, 0x8A, 0xF3, 0x01, 0x7C, 0x52, 0xDB,
  32699. 0x23, 0x3A, 0x90, 0x71, 0x7D, 0xF2, 0x5B, 0x4D,
  32700. 0x07, 0x2B, 0x7D, 0x88, 0xEE, 0x87, 0x31, 0xD1,
  32701. 0x68, 0x24, 0xC9, 0x5D, 0x1F, 0xB9, 0x83, 0xC4,
  32702. 0x49, 0xDE, 0xB4, 0x66, 0x27, 0x60, 0x60, 0xFE,
  32703. 0xE4, 0xC7, 0xEE, 0x38, 0x14, 0x51, 0xF2, 0x32,
  32704. 0xC2, 0x9C, 0x7C, 0x32, 0x20, 0x85, 0x0C, 0x61,
  32705. 0xD1, 0xC3, 0xC0, 0x0D, 0xB1, 0xCD, 0x97, 0x26,
  32706. 0xA0, 0x2A, 0x56, 0x60, 0x9F, 0x3A, 0x65, 0xD3,
  32707. 0xD1, 0x64, 0x60, 0x45, 0x88, 0xCD, 0x9B, 0x43,
  32708. 0x14, 0x12, 0xF1, 0xAD, 0xD9, 0x14, 0xC5, 0xC2,
  32709. 0xDA, 0xBB, 0xC9, 0x04, 0x67, 0xC0, 0xC4, 0xEA,
  32710. 0x5F, 0x76, 0xE2, 0x4A, 0xA6, 0x18, 0x76, 0x5F,
  32711. 0x8B, 0x06, 0x36, 0xD7, 0xB0, 0x65, 0xE1, 0xF4,
  32712. 0xE6, 0xF6, 0x22, 0xEA, 0xE1, 0x71, 0x52, 0x45,
  32713. 0x8C, 0x76, 0x65, 0x86, 0x77, 0x2D, 0x36, 0x3F,
  32714. 0xA9, 0x92, 0x14, 0xF4, 0x72, 0xB0, 0xDB, 0x8A,
  32715. 0x1E, 0x49, 0xD8, 0x2D, 0x02, 0x78, 0xF2, 0x95,
  32716. 0x8B, 0x0A, 0xAA, 0x15, 0x86, 0xDB, 0x13, 0x4B,
  32717. 0xDF, 0xD2, 0x43, 0x87, 0x42, 0x49, 0x50, 0x07,
  32718. 0xE2, 0xFE, 0x5B, 0x60, 0xE2, 0x46, 0x39, 0x92,
  32719. 0x26, 0x94, 0x7A, 0x12, 0xEA, 0x17, 0x63, 0x1C,
  32720. 0xAA, 0x53, 0x46, 0x87, 0xCB, 0x75, 0xC0, 0x60,
  32721. 0xB4, 0x79, 0x7E, 0xAB, 0x82, 0x77, 0xCC, 0x4F,
  32722. 0x8A, 0x7A, 0x20, 0x38, 0x76, 0x06, 0xEF, 0xE2,
  32723. 0xDB, 0xD3, 0xE7, 0x36, 0x24, 0x92, 0x77, 0xD9,
  32724. 0x0F, 0xCA, 0xB9, 0x92, 0xA8, 0xC9, 0x9E, 0x85,
  32725. 0xAB, 0x03, 0xEB, 0x4C, 0xAC, 0x5D, 0x88, 0x55,
  32726. 0x39, 0x58, 0x52, 0x8A, 0xF9, 0x29, 0x74, 0x71,
  32727. 0x81, 0x35, 0xF1, 0xD0, 0xC7, 0x93, 0xEB, 0x00,
  32728. 0x0E, 0xA0, 0xAE, 0xC3, 0xEC, 0x18, 0x58, 0xFD,
  32729. 0xD1, 0x86, 0x88, 0xD1, 0xDA, 0x27, 0x27, 0x8D,
  32730. 0xEB, 0xF2, 0xCA, 0x81, 0x10, 0xBA, 0x4A, 0x20,
  32731. 0x4F, 0x79, 0x30, 0xE1, 0xC8, 0xCE, 0xEC, 0xAF,
  32732. 0xB7, 0x3F, 0x75, 0xDD, 0xB3, 0x4C, 0x5C, 0x55,
  32733. 0x96, 0x8A, 0x79, 0x33, 0x05, 0x84, 0x26, 0xB5,
  32734. 0x5D, 0x03, 0x9F, 0x72, 0x92, 0xAC, 0x43, 0xF6,
  32735. 0x45, 0x84, 0xF6, 0xDF, 0x18, 0x7A, 0x1D, 0x6B,
  32736. 0x00, 0x3F, 0x51, 0x4C, 0xC1, 0x3B, 0x26, 0xC2,
  32737. 0xF3, 0x48, 0x19, 0x5A, 0xA3, 0x21, 0xDE, 0x6A,
  32738. 0x27, 0xEC, 0x11, 0x34, 0x8D, 0xE5, 0x0D, 0x82,
  32739. 0x5A, 0x29, 0x64, 0xC6, 0x31, 0x99, 0x2E, 0x4B,
  32740. 0x0B, 0x42, 0x5B, 0x1B, 0xEB, 0x4F, 0x96, 0x00,
  32741. 0xE3, 0xAD, 0xC4, 0x43, 0x1C, 0xF2, 0xE8, 0x8B,
  32742. 0x42, 0x23, 0xD2, 0xDB, 0x66, 0x3C, 0x3C, 0xE7,
  32743. 0x0E, 0xF8, 0x5D, 0xDD, 0x56, 0xA9, 0xBA, 0xF1,
  32744. 0x38, 0xA9, 0xD7, 0xED, 0xD8, 0x94, 0x13, 0x1C,
  32745. 0x3A, 0x8F, 0x41, 0xA0, 0x4E, 0xF9, 0xF8, 0x67,
  32746. 0x52, 0xB7, 0x21, 0x81, 0xFA, 0xBB, 0x37, 0xC8,
  32747. 0x6B, 0x87, 0x7E, 0x61, 0xD6, 0x0E, 0xED, 0x95,
  32748. 0xEE, 0xFF, 0xAB, 0xE6, 0x37, 0x6E, 0x14, 0xAC,
  32749. 0xA8, 0x17, 0xC5, 0xF4, 0x19, 0x61, 0xAF, 0x8A,
  32750. 0x78, 0x49, 0xBA, 0xC0, 0x94, 0x91, 0x7B, 0x2D,
  32751. 0x13, 0x22, 0x76, 0xB6, 0xB3, 0x48, 0x6A, 0xFF,
  32752. 0x95, 0x0D, 0x23, 0xD4, 0xAA, 0xDC, 0x24, 0xCE,
  32753. 0x98, 0xA5, 0x26, 0x9E, 0x1C, 0x69, 0x91, 0x79,
  32754. 0x60, 0xA3, 0x1E, 0xE0, 0x9A, 0x52, 0x7C, 0x35,
  32755. 0x81, 0x75, 0xCA, 0xA0, 0xCB, 0x1B, 0x01, 0x8E,
  32756. 0x95, 0x26, 0xD9, 0x35, 0x34, 0xEA, 0xDB, 0xAC,
  32757. 0xB5, 0x2B, 0x27, 0x3D, 0x73, 0x5E, 0x22, 0xDD,
  32758. 0x0D, 0x5C, 0x28, 0xFA, 0x3E, 0x47, 0xCF, 0xE9,
  32759. 0x0B, 0x52, 0x15, 0xAE, 0x24, 0xF1, 0x46, 0xC3,
  32760. 0x46, 0x4B, 0xFE, 0xAF, 0x01, 0xD2, 0x8D, 0xAA,
  32761. 0x55, 0x3C, 0x1E, 0x94, 0x42, 0x8A, 0x10, 0x4A,
  32762. 0x9D, 0x78, 0xAE, 0xC7, 0x62, 0x59, 0x1E, 0x88,
  32763. 0x79, 0xF7, 0x68, 0x51, 0xCF, 0xB4, 0x64, 0x85,
  32764. 0x66, 0x72, 0x1B, 0x0C, 0xAC, 0x1F, 0x14, 0xFE,
  32765. 0x16, 0x14, 0x9A, 0x9D, 0x82, 0x10, 0xCC, 0x8F,
  32766. 0x2F, 0x50, 0xDE, 0xF7, 0xB4, 0x6C, 0x84, 0x3B,
  32767. 0xE9, 0x3B, 0xD8, 0xD5, 0x56, 0x02, 0x49, 0x33,
  32768. 0x50, 0xAB, 0x56, 0x0E, 0xA5, 0xBA, 0x17, 0x71,
  32769. 0x64, 0x23, 0xBE, 0x0E, 0xB8, 0x36, 0x0A, 0xB1,
  32770. 0x09, 0xD8, 0xFB, 0x18, 0xBF, 0xEA, 0x04, 0x08,
  32771. 0x47, 0xB7, 0x33, 0x51, 0x45, 0xD4, 0xF2, 0x00,
  32772. 0xD1, 0x9C, 0xF6, 0xFE, 0x7B, 0xAC, 0x91, 0x7F,
  32773. 0x42, 0x6C, 0x9B, 0x3D, 0x39, 0xA9, 0xCA, 0x43,
  32774. 0x29, 0x81, 0x8F, 0x24, 0x0E, 0x7D, 0xA3, 0x82,
  32775. 0x76, 0x10, 0x72, 0xF4, 0xA6, 0x50, 0x5E, 0xA8,
  32776. 0xE7, 0x6C, 0x1E, 0x44, 0x6F, 0xEB, 0x66, 0x25,
  32777. 0xE3, 0x8D, 0xDB, 0xCD, 0x3C, 0xDA, 0x81, 0xE8,
  32778. 0x3B, 0xF7, 0x68, 0xF3, 0xE0, 0x1D, 0x9D, 0x26,
  32779. 0x3B, 0x36, 0x73, 0x03, 0xAE, 0x15, 0x6C, 0x0B,
  32780. 0x71, 0x83, 0x36, 0x4A, 0x1E, 0x79, 0x41, 0xA0,
  32781. 0x92, 0x98, 0xA3, 0xAD, 0xF7, 0xBD, 0x23, 0x1E,
  32782. 0x61, 0x14, 0xB9, 0xDC, 0xE7, 0x95, 0x2B, 0x11,
  32783. 0x3F, 0x78, 0x16, 0x31, 0x38, 0xB9, 0x26, 0x6F,
  32784. 0x84, 0x3F, 0x1E, 0xD9, 0x7D, 0x9C, 0x2B, 0x16,
  32785. 0x3A, 0x6E, 0x8B, 0xD4, 0xC1, 0xAB, 0x4E, 0x17,
  32786. 0x93, 0x67, 0xC5, 0xAC, 0x96, 0xCE, 0xCF, 0x50,
  32787. 0x50, 0xFE, 0x82, 0x1F, 0xDF, 0xA4, 0x4E, 0x9E,
  32788. 0x68, 0x0B, 0x61, 0xC6, 0x01, 0x89, 0x32, 0xDF,
  32789. 0x71, 0x78, 0x11, 0x45, 0x9A, 0xF2, 0x54, 0x2E,
  32790. 0x2C, 0xDE, 0x77, 0x17, 0x8C, 0x2E, 0x98, 0x80,
  32791. 0xF0, 0x11, 0xE4, 0x05, 0xEA, 0xFA, 0x59, 0xC8,
  32792. 0xCB, 0xBE, 0xD7, 0x6E, 0x5A, 0x19, 0x41, 0x10,
  32793. 0x4B, 0x1B, 0x9D, 0x3A, 0x60, 0x49, 0x1C, 0x95,
  32794. 0x47, 0x55, 0xE0, 0x2E, 0x89, 0x41, 0x03, 0xF1,
  32795. 0xF4, 0x97, 0x74, 0x75, 0xE9, 0xEA, 0x36, 0x60,
  32796. 0x9F, 0xD6, 0x7C, 0x9D, 0xE3, 0x18, 0xED, 0xA2,
  32797. 0x37, 0x0D, 0xCC, 0xDB, 0xB9, 0xCE, 0xF7, 0xAE,
  32798. 0x63, 0x60, 0x90, 0x5E, 0xC2, 0x20, 0x83, 0x8C,
  32799. 0x97, 0x69, 0x82, 0x34, 0x41, 0xCD, 0xD0, 0xDA,
  32800. 0x8E, 0xF0, 0xAB, 0xE5, 0xF2, 0xD1, 0xD7, 0x6E,
  32801. 0x2F, 0xE0, 0x8F, 0xEF, 0x53, 0xDE, 0x1D, 0x61,
  32802. 0x66, 0xAB, 0x1A, 0x92, 0xB1, 0xAC, 0x09, 0x3E,
  32803. 0x5A, 0xBF, 0x76, 0x58, 0xC4, 0xB5, 0x72, 0x87,
  32804. 0xF2, 0xD1, 0xFD, 0x7B, 0x82, 0xDE, 0xDA, 0xF8,
  32805. 0xD5, 0xA4, 0xFB, 0xAC, 0x4B, 0x35, 0xD5, 0x82,
  32806. 0x31, 0x69, 0x4E, 0x16, 0x24, 0x97, 0x57, 0x8A,
  32807. 0xBD, 0x7A, 0xA7, 0xC8, 0xFE, 0x7B, 0x35, 0x41,
  32808. 0xA7, 0xF1, 0x8E, 0x54, 0xE8, 0xB7, 0xF0, 0x87,
  32809. 0x64, 0xC5, 0xE6, 0x84, 0x49, 0xDF, 0x65, 0x59,
  32810. 0x01, 0x54, 0x98, 0x32, 0xD6, 0x28, 0xFA, 0x63,
  32811. 0xD2, 0xB2, 0xC5, 0xA1, 0x50, 0x93, 0x39, 0x94,
  32812. 0xA9, 0x86, 0x33, 0x17, 0xAD, 0x40, 0xD7, 0x78,
  32813. 0xD9, 0xD2, 0xC0, 0x5C, 0x78, 0x98, 0x85, 0x0B,
  32814. 0x90, 0x17, 0x32, 0x23, 0xC7, 0xA0, 0xAF, 0x89,
  32815. 0x0F, 0xD7, 0xE6, 0x62, 0x21, 0xB6, 0xF0, 0x63,
  32816. 0x18, 0xB2, 0xED, 0x5E, 0x19, 0x9C, 0xB4, 0x24,
  32817. 0x88, 0x5A, 0xB8, 0x41, 0xE7, 0xA4, 0x72, 0x6F,
  32818. 0xAB, 0xA2, 0xF9, 0xBB, 0x53, 0xBC, 0x32, 0x36,
  32819. 0x43, 0x4C, 0x35, 0xFB, 0xBE, 0x4B, 0x1A, 0x0F,
  32820. 0x93, 0xF5, 0x0C, 0x37, 0x89, 0x6C, 0x29, 0xF8,
  32821. 0xE3, 0x02, 0xAD, 0x31, 0xED, 0x33, 0x31, 0xD6,
  32822. 0x20, 0xE3, 0xB6, 0x29, 0x45, 0x51, 0x01, 0xA1,
  32823. 0xF1, 0xCC, 0x7B, 0xA5, 0xE4, 0x6E, 0x68, 0xED,
  32824. 0x4A, 0x8C, 0xCC, 0x87, 0xB4, 0xDC, 0x75, 0xBC,
  32825. 0x01, 0x62, 0xB6, 0x33, 0x0F, 0x83, 0x3F, 0xBA,
  32826. 0x25, 0x75, 0xDF, 0xAF, 0x5B, 0x5F, 0x28, 0xBC,
  32827. 0x54, 0xFF, 0x2B, 0xA8, 0x1E, 0x7A, 0x47, 0x31,
  32828. 0x3C, 0x15, 0x48, 0x2B, 0x60, 0x5E, 0x66, 0xBB,
  32829. 0x38, 0xC6, 0x19, 0x8F, 0x13, 0x92, 0x10, 0x40,
  32830. 0x80, 0xFB, 0xE7, 0x8B, 0x86, 0xB1, 0xBC, 0x9A,
  32831. 0x6F, 0xB8, 0x81, 0xF5, 0xC7, 0x82, 0x01, 0x47,
  32832. 0xE6, 0xBA, 0x14, 0xB8, 0x1A, 0xCC, 0xF2, 0x0C,
  32833. 0xAE, 0x96, 0x64, 0x10, 0x94, 0xC2, 0x16, 0x90,
  32834. 0x2E, 0xA5, 0xC1, 0x25, 0xF6, 0xC9, 0x35, 0xA1,
  32835. 0x50, 0xD7, 0xC9, 0xAC, 0xC5, 0xD9, 0xE2, 0xE5,
  32836. 0xD9, 0x0E, 0x38, 0xC0, 0x50, 0x3A, 0xA9, 0x42,
  32837. 0x60, 0x17, 0xC7, 0x6A, 0xAF, 0xCD, 0x52, 0x61,
  32838. 0xB5, 0x06, 0x27, 0x4E, 0xC1, 0x3A, 0x96, 0x79,
  32839. 0xFB, 0x09, 0x79, 0x60, 0x27, 0xA4, 0xBB, 0x75,
  32840. 0x9D, 0x92, 0x82, 0x79, 0xB9, 0x4D, 0x84, 0x1A,
  32841. 0x09, 0x73, 0x93, 0xBF, 0x7E, 0x5B, 0xD6, 0x9A,
  32842. 0x49, 0x6C, 0xC3, 0xDE, 0xCD, 0x2B, 0x0F, 0x07,
  32843. 0xF8, 0x33, 0x92, 0xAA, 0xDE, 0x33, 0xDC, 0x51,
  32844. 0xB2, 0xA8, 0x4F, 0x6A, 0x07, 0x63, 0x5D, 0xC0,
  32845. 0xEF, 0x57, 0xA9, 0xAD, 0x59, 0x59, 0xB6, 0xA5,
  32846. 0x0B, 0x7B, 0xA5, 0x09, 0xAD, 0x5B, 0x11, 0xFA,
  32847. 0xD2, 0x6B, 0x41, 0x9F, 0x9F, 0x1E, 0x3F, 0x9C,
  32848. 0x73, 0x29, 0xB5, 0xA9, 0x53, 0xD7, 0xCC, 0x87,
  32849. 0xB2, 0xDE, 0x21, 0x06, 0x11, 0xCF, 0x52, 0xA6,
  32850. 0x39, 0xEF, 0x2B, 0x39, 0x08, 0x01, 0x2C, 0xB8,
  32851. 0x8E, 0x1D, 0x6F, 0x57, 0x62, 0x50, 0x79, 0xCB,
  32852. 0x10, 0x3D, 0x6C, 0x98, 0x10, 0x1A, 0x11, 0xBD,
  32853. 0x22, 0x33, 0xB6, 0x56, 0x02, 0xCA, 0x30, 0x49,
  32854. 0xBD, 0x32, 0x05, 0x20, 0x41, 0x9F, 0x76, 0xB0,
  32855. 0x61, 0xE3, 0x59, 0x8D, 0xE3, 0x81, 0x52, 0xC8,
  32856. 0x87, 0x67, 0xD1, 0xA2, 0x4F, 0xBD, 0x02, 0xBB,
  32857. 0x10, 0xC3, 0x8E, 0xAC, 0xAE, 0x31, 0x7D, 0xE6,
  32858. 0xBB, 0x28, 0x7B, 0x4D, 0x2C, 0xAE, 0x5D, 0xA0,
  32859. 0x21, 0x49, 0x65, 0xD8, 0x77, 0x37, 0x78, 0x62,
  32860. 0x6E, 0x9B, 0x97, 0x28, 0x59, 0xD8, 0x48, 0x2B,
  32861. 0x8D, 0x05, 0x47, 0xE4, 0xF5, 0x6D, 0xFF, 0x87,
  32862. 0x68, 0x1D, 0x5B, 0xC5, 0x12, 0x0F, 0x61, 0x3F,
  32863. 0xBB, 0xD9, 0x1E, 0x1F, 0x14, 0xE6, 0xDE, 0xFE,
  32864. 0x67, 0x2E, 0x2A, 0x7E, 0xAB, 0xCB, 0xBB, 0x9B,
  32865. 0x11, 0x08, 0x2C, 0x5E, 0x70, 0x0A, 0xA0, 0xB1,
  32866. 0xF7, 0xC1, 0x78, 0x5F, 0xCE, 0xD1, 0x9A, 0x93,
  32867. 0xAF, 0xE7, 0xC5, 0x9F, 0xA2, 0x51, 0x9B, 0xCD,
  32868. 0xEB, 0x49, 0x4C, 0x3D, 0x13, 0xB2, 0x12, 0x5F,
  32869. 0x38, 0x53, 0x23, 0xB8, 0x16, 0xC6, 0x8F, 0x8F,
  32870. 0x56, 0x28, 0xC7, 0xC2, 0xAB, 0xFD, 0x02, 0x78,
  32871. 0xA3, 0x37, 0x07, 0x3D, 0xA7, 0x4D, 0x16, 0x09,
  32872. 0x96, 0x98, 0xC4, 0xB1, 0x14, 0xE8, 0xA8, 0xCE,
  32873. 0x34, 0x4E, 0x0A, 0x15, 0xD0, 0xFC, 0x7E, 0xD4,
  32874. 0x97, 0xB0, 0x01, 0xD5, 0x3D, 0x4C, 0x96, 0xDC,
  32875. 0x39, 0x54, 0xD3, 0xB4, 0xB9, 0x56, 0xCB, 0x9D,
  32876. 0x2A, 0x27, 0x2C, 0x51, 0xF1, 0x55, 0x9B, 0x22,
  32877. 0x90, 0x4B, 0x40, 0xCC, 0x85, 0x31, 0xE4, 0x0C,
  32878. 0xC4, 0x12, 0xC6, 0x8C, 0xB6, 0xEE, 0xA4, 0xA4,
  32879. 0x09, 0x0B, 0x38, 0xE2, 0x79, 0x73, 0x29, 0x98,
  32880. 0x54, 0x67, 0xE8, 0x18, 0xA5, 0x24, 0xD3, 0x22,
  32881. 0x8E, 0xAC, 0xAE, 0x78, 0x25, 0xD3, 0xDA, 0xD2,
  32882. 0xEA, 0xA4, 0x22, 0xFD, 0xC7, 0x7A, 0xED, 0x71,
  32883. 0xA2, 0x05, 0xDA, 0x78, 0x38, 0xD9, 0x45, 0xE7,
  32884. 0xFE, 0xC3, 0x7E, 0x4D, 0xCA, 0x67, 0xE5, 0x04,
  32885. 0xCE, 0x35, 0xE5, 0xB0, 0x45, 0xF5, 0x6F, 0x1E,
  32886. 0x8D, 0x75, 0x29, 0xEB, 0xD6, 0xF1, 0xAF, 0x7B,
  32887. 0x6E, 0x93, 0x9E, 0x2B, 0x7A, 0xB4, 0x02, 0x7D,
  32888. 0x37, 0xA5, 0x13, 0x5D, 0x17, 0x2D, 0xA1, 0xAF,
  32889. 0x9C, 0xA2, 0xF7, 0x28, 0xA6, 0xF3, 0x7D, 0xE6,
  32890. 0x0D, 0xD2, 0x3D, 0x97, 0xD1, 0x1E, 0x75, 0xAB,
  32891. 0x1F, 0xD5, 0x1F, 0x8E, 0x9A, 0x13, 0x97, 0xE5,
  32892. 0x82, 0x21, 0x59, 0xDB, 0x58, 0x38, 0x02, 0xB3,
  32893. 0x2E, 0xEB, 0xB4, 0x56, 0x7E, 0xCE, 0x37, 0x46,
  32894. 0xD1, 0xAE, 0x33, 0x31, 0x47, 0x85, 0x64, 0x3D,
  32895. 0xD2, 0xA0, 0x74, 0x1E, 0x7F, 0x1B, 0xF2, 0xD2,
  32896. 0x61, 0xF2, 0x21, 0x24, 0xE8, 0xDD, 0xD0, 0x8C,
  32897. 0x64, 0x0A, 0x48, 0xB5, 0x47, 0x17, 0x51, 0x7C,
  32898. 0x21, 0xCD, 0x32, 0x53, 0x28, 0xBC, 0x23, 0x9C,
  32899. 0xA0, 0x28, 0xB2, 0x63, 0x0D, 0x06, 0x3C, 0x8C,
  32900. 0xC2, 0x0B, 0xE9, 0xBD, 0xB4, 0x85, 0x02, 0xDA,
  32901. 0xDD, 0xE7, 0x3F, 0xFE, 0xD5, 0x96, 0x38, 0x16,
  32902. 0x53, 0x3E, 0x02, 0x0A, 0xED, 0x12, 0x08, 0x53,
  32903. 0x62, 0x55, 0xB1, 0xCC, 0xE9, 0x85, 0x43, 0x31,
  32904. 0x27, 0xFF, 0x4F, 0x04, 0xD5, 0xB1, 0xE2, 0xF2,
  32905. 0x10, 0x87, 0x04, 0xB8, 0xB9, 0x66, 0x58, 0x8C,
  32906. 0x01, 0x56, 0xAF, 0xC2, 0xAE, 0x19, 0x29, 0x86,
  32907. 0xFB, 0xEC, 0x44, 0x3B, 0xAE, 0xF6, 0xCB, 0x85,
  32908. 0xA6, 0xF2, 0x9C, 0x77, 0x92, 0x40, 0x5A, 0x24,
  32909. 0x11, 0x47, 0x10, 0xAE, 0x1C, 0x74, 0x64, 0x44,
  32910. 0xFD, 0xF5, 0xFB, 0x65, 0x9E, 0x5E, 0x34, 0x68,
  32911. 0x26, 0x20, 0x7B, 0x8C, 0x54, 0x46, 0x3A, 0x06,
  32912. 0x17, 0xCE, 0x17, 0xFF, 0x33, 0xE4, 0x0F, 0x93,
  32913. 0x1F, 0xE5, 0x76, 0x71, 0x5C, 0x93, 0x2E, 0xF2,
  32914. 0x9F, 0xD7, 0x6B, 0x04, 0xA6, 0x9B, 0x58, 0xE0,
  32915. 0x30, 0x3D, 0x8E, 0xF2, 0x56, 0x78, 0xC8, 0xB7,
  32916. 0x0A, 0xF1, 0x2E, 0x90, 0x45, 0x59, 0x1C, 0x04,
  32917. 0xE8, 0xB7, 0x71, 0x06, 0x94, 0x04, 0x15, 0x17,
  32918. 0x7E, 0x86, 0x85, 0x93, 0xA0, 0x9C, 0x7E, 0x14,
  32919. 0x61, 0x9A, 0x4B, 0x33, 0x2F, 0x9A, 0xDC, 0x3A,
  32920. 0x65, 0x8B, 0x86, 0x01, 0x7F, 0x32, 0x65, 0x6C,
  32921. 0x54, 0x29, 0xC1, 0x15, 0xE1, 0x10, 0x03, 0x7A,
  32922. 0x8C, 0xC7, 0xE5, 0x44, 0x67, 0x7D, 0x2D, 0xD2,
  32923. 0x39, 0xA5, 0x9D, 0x54, 0xD0, 0xF3, 0xC7, 0x46,
  32924. 0x0E, 0xC1, 0x52, 0x08, 0x34, 0x6B, 0xA5, 0x6D,
  32925. 0xF5, 0x08, 0x6C, 0x5D, 0xBC, 0xC4, 0x1E, 0x0C,
  32926. 0x95, 0xFC, 0xB6, 0x86, 0x1C, 0x2C, 0x0C, 0x32,
  32927. 0xAA, 0xF3, 0x45, 0x4E, 0xFE, 0xE2, 0xFF, 0xBA,
  32928. 0x21, 0x4B, 0x43, 0x0E, 0xF2, 0x48, 0xA5, 0x9B,
  32929. 0x32, 0x44, 0x4D, 0x8D, 0x0D, 0x3D, 0xB8, 0x7C,
  32930. 0x9D, 0x4B, 0x15, 0x36, 0xD1, 0x57, 0x72, 0x8E,
  32931. 0xE7, 0x58, 0x5E, 0xF5, 0x32, 0x77, 0x6A, 0x00,
  32932. 0x3A, 0x02, 0x3C, 0x0A, 0xB0, 0xE9, 0xFF, 0x55,
  32933. 0x71, 0x08, 0xC3, 0x90, 0x68, 0x4D, 0x56, 0x5A,
  32934. 0x66, 0x50, 0x63, 0x26, 0x6A, 0xE6, 0x67, 0x0E,
  32935. 0xD5, 0x3B, 0x0F, 0xAF, 0x8F, 0xF6, 0x78, 0x29,
  32936. 0xBB, 0x73, 0x78, 0x25, 0xB1, 0x53, 0xA9, 0x33,
  32937. 0x8C, 0xBE, 0x3D, 0xF1, 0xA4, 0x62, 0x84, 0x9B,
  32938. 0x93, 0xA8, 0x1F, 0x84, 0xED, 0x07, 0xBE, 0x6D,
  32939. 0x62, 0x40, 0x00, 0x32, 0x74, 0x73, 0x7F, 0x61,
  32940. 0x8D, 0xCB, 0x26, 0xE4, 0x82, 0x52, 0xCE, 0x42,
  32941. 0x04, 0xDD, 0x31, 0x39, 0xFF, 0x68, 0x76, 0xF4,
  32942. 0x3B, 0x30, 0x5D, 0x83, 0x56, 0x20, 0xFE, 0xDF,
  32943. 0x79, 0xAA, 0x67, 0x43, 0x3D, 0xC2, 0x52, 0x87,
  32944. 0x32, 0x0E, 0x99, 0x17, 0x96, 0x7B, 0x70, 0xB2,
  32945. 0xD8, 0x66, 0xD1, 0x7B, 0x69, 0x8B, 0xFF, 0xF2,
  32946. 0xB3, 0xAB, 0x95, 0x14, 0x94, 0x9E, 0x58, 0xB5,
  32947. 0x7C, 0x68, 0xA4, 0x54, 0x12, 0xC1, 0xFC, 0x42,
  32948. 0x1C, 0x76, 0x8B, 0xF5, 0xEE, 0x8A, 0x10, 0xC8,
  32949. 0xAE, 0xF5, 0x69, 0x26, 0xF5, 0x1E, 0xC6, 0x2C,
  32950. 0x11, 0x56, 0x9F, 0x31, 0xAA, 0x51, 0x78, 0x68,
  32951. 0xE5, 0xCA, 0xD8, 0x9E, 0x95, 0x80, 0x66, 0xEB,
  32952. 0x9E, 0xDD, 0x72, 0x71, 0xB3, 0x1C, 0xB4, 0xB1,
  32953. 0xD6, 0xCE, 0x21, 0x12, 0x25, 0xAE, 0xB5, 0xB5,
  32954. 0x7F, 0x74, 0x97, 0x19, 0xDA, 0x07, 0xEC, 0xBE,
  32955. 0xFE, 0x03, 0x88, 0x1D, 0xDE, 0x3D, 0x81, 0xE4,
  32956. 0x13, 0x5F, 0x2D, 0xC8, 0x1A, 0xF7, 0x79, 0x77,
  32957. 0x6C, 0x1B, 0x80, 0x57, 0x16, 0x2A, 0x6C, 0x98,
  32958. 0x2F, 0xBB, 0x4D, 0xA6, 0xA9, 0xAD, 0x28, 0x4A,
  32959. 0xB1, 0x0C, 0x70, 0x02, 0x20, 0x44, 0xF4, 0x6D,
  32960. 0x40, 0x0B, 0xF6, 0xAD, 0x71, 0x82, 0xD1, 0x97,
  32961. 0x78, 0x99, 0x83, 0xBE, 0x99, 0x22, 0x79, 0x79,
  32962. 0xA1, 0x33, 0x4B, 0xA1, 0x49, 0xD8, 0x69, 0xBA,
  32963. 0x1C, 0x40, 0x88, 0x12, 0x34, 0x35, 0xBF, 0x97,
  32964. 0x85, 0x41, 0x35, 0x6D, 0xAF, 0x17, 0x1F, 0x33,
  32965. 0xAD, 0xB1, 0xC9, 0x79, 0x07, 0xA0, 0xFB, 0x58,
  32966. 0x45, 0x07, 0x4A, 0x85, 0xD2, 0x6F, 0x54, 0x61,
  32967. 0x35, 0xAE, 0xD0, 0xF9, 0x1B, 0xE4, 0x53, 0x9C,
  32968. 0x12, 0xBF, 0x94, 0x11, 0xE4, 0xB5, 0x56, 0xF6,
  32969. 0x87, 0xD0, 0x69, 0xDB, 0x6B, 0x21, 0xFE, 0x2B,
  32970. 0x7F, 0x32, 0x18, 0x87, 0x44, 0x8C, 0xEA, 0x55,
  32971. 0xDB, 0x19, 0xFB, 0xB8, 0xB0, 0x48, 0x2A, 0x55,
  32972. 0xAE, 0xC1, 0x67, 0x38, 0xD7, 0x4C, 0xD2, 0x65,
  32973. 0x09, 0x38, 0x36, 0xBE, 0x99, 0xD4, 0xFB, 0x53,
  32974. 0xE9, 0xB0, 0x14, 0xB0, 0x37, 0xCD, 0xBF, 0xE9
  32975. };
  32976. static const byte sk_87[] = {
  32977. 0x69, 0x24, 0xBB, 0x42, 0x57, 0xA7, 0xB9, 0xAF,
  32978. 0xF0, 0x95, 0xC3, 0x0B, 0xB3, 0x5C, 0x6A, 0xE4,
  32979. 0x19, 0x82, 0x63, 0x12, 0x0F, 0x80, 0x39, 0xAA,
  32980. 0x4E, 0x78, 0xE1, 0x74, 0xA7, 0x86, 0xCE, 0x00,
  32981. 0x3B, 0x9A, 0xC2, 0xC1, 0x42, 0x2A, 0x1A, 0xE8,
  32982. 0x02, 0xDD, 0xD7, 0x46, 0x4D, 0x3F, 0x32, 0x72,
  32983. 0x9A, 0x3C, 0x7D, 0xE8, 0x94, 0xD5, 0x06, 0xAC,
  32984. 0xAD, 0x25, 0xCE, 0xB3, 0x72, 0xEA, 0x31, 0x49,
  32985. 0xC9, 0x87, 0x80, 0xDC, 0xD1, 0x31, 0x4B, 0xAA,
  32986. 0x29, 0xB9, 0xB8, 0x07, 0x75, 0x4C, 0x47, 0xDE,
  32987. 0x5D, 0xCA, 0x95, 0x40, 0x64, 0xF2, 0x85, 0x28,
  32988. 0xB8, 0x15, 0xFE, 0x27, 0xB7, 0x9A, 0xC5, 0x06,
  32989. 0xB3, 0xAD, 0x76, 0x29, 0xD2, 0xC9, 0x71, 0xAB,
  32990. 0x8F, 0x28, 0x2E, 0x0C, 0x6E, 0x7E, 0x55, 0x48,
  32991. 0xEE, 0x0E, 0x11, 0x32, 0x42, 0xB7, 0xA0, 0xE0,
  32992. 0x64, 0xA6, 0xDB, 0xCE, 0x30, 0xC5, 0x61, 0x9B,
  32993. 0x19, 0x80, 0x08, 0x89, 0xA0, 0x44, 0x04, 0xB5,
  32994. 0x00, 0x13, 0xC0, 0x88, 0xC1, 0x30, 0x29, 0x62,
  32995. 0x12, 0x4C, 0xD3, 0xB4, 0x91, 0x0A, 0x35, 0x2C,
  32996. 0x43, 0x12, 0x31, 0x19, 0x99, 0x65, 0x22, 0x18,
  32997. 0x52, 0x02, 0xC3, 0x85, 0x23, 0x44, 0x0D, 0x90,
  32998. 0x24, 0x4A, 0x1A, 0x30, 0x22, 0x44, 0x28, 0x61,
  32999. 0x81, 0x06, 0x29, 0x18, 0x97, 0x68, 0x0A, 0x20,
  33000. 0x09, 0x08, 0x32, 0x6A, 0x44, 0xA4, 0x4C, 0x44,
  33001. 0x90, 0x21, 0x8A, 0x16, 0x68, 0x9A, 0xA8, 0x51,
  33002. 0x1A, 0xA5, 0x2C, 0x62, 0x46, 0x8D, 0x04, 0xC3,
  33003. 0x40, 0xD3, 0x86, 0x28, 0x60, 0xA4, 0x60, 0x13,
  33004. 0x18, 0x70, 0x84, 0x94, 0x8C, 0x63, 0xC0, 0x44,
  33005. 0x04, 0xA9, 0x28, 0x20, 0x08, 0x20, 0x43, 0x16,
  33006. 0x2A, 0x23, 0x29, 0x2D, 0x1A, 0xB1, 0x29, 0x48,
  33007. 0xB6, 0x09, 0x21, 0x88, 0x31, 0x00, 0xC5, 0x30,
  33008. 0x00, 0xC4, 0x8C, 0xD9, 0x82, 0x68, 0xE1, 0x30,
  33009. 0x4C, 0x63, 0x32, 0x45, 0x0C, 0x32, 0x86, 0x18,
  33010. 0x08, 0x31, 0x91, 0x98, 0x0D, 0x10, 0xB8, 0x70,
  33011. 0x9B, 0x30, 0x22, 0x64, 0x04, 0x08, 0x93, 0xA4,
  33012. 0x8C, 0x21, 0xC9, 0x70, 0x0C, 0x35, 0x71, 0x5B,
  33013. 0x00, 0x0D, 0x14, 0x31, 0x22, 0xCC, 0x98, 0x10,
  33014. 0x21, 0x04, 0x80, 0x9B, 0x28, 0x64, 0x1C, 0x30,
  33015. 0x80, 0x21, 0x30, 0x71, 0x18, 0x33, 0x50, 0x24,
  33016. 0x25, 0x44, 0x08, 0x17, 0x8C, 0xC0, 0x08, 0x48,
  33017. 0x84, 0x44, 0x90, 0x48, 0x98, 0x30, 0xCA, 0x44,
  33018. 0x00, 0x09, 0x19, 0x51, 0x19, 0x23, 0x0C, 0x52,
  33019. 0x20, 0x0E, 0x49, 0x06, 0x32, 0x1C, 0x15, 0x4E,
  33020. 0x19, 0x48, 0x85, 0x13, 0x25, 0x49, 0xA3, 0x00,
  33021. 0x04, 0x08, 0x15, 0x6D, 0x20, 0x41, 0x0C, 0xDA,
  33022. 0x42, 0x52, 0xC1, 0x34, 0x8C, 0x00, 0x31, 0x69,
  33023. 0x43, 0x82, 0x24, 0x64, 0x94, 0x6D, 0x1C, 0x81,
  33024. 0x11, 0x01, 0x96, 0x21, 0x4B, 0x02, 0x00, 0xCA,
  33025. 0x28, 0x84, 0xCC, 0x46, 0x64, 0x51, 0x18, 0x6A,
  33026. 0x18, 0x10, 0x00, 0xA4, 0x98, 0x21, 0x60, 0xB0,
  33027. 0x68, 0x03, 0x94, 0x6C, 0x94, 0x48, 0x51, 0x80,
  33028. 0x40, 0x46, 0x92, 0x22, 0x2C, 0x23, 0x44, 0x69,
  33029. 0x98, 0x26, 0x4D, 0x1C, 0x01, 0x08, 0x52, 0x02,
  33030. 0x20, 0x8A, 0xA6, 0x08, 0x0A, 0x31, 0x61, 0x93,
  33031. 0x40, 0x0E, 0x9C, 0xC8, 0x11, 0x81, 0x32, 0x2E,
  33032. 0x21, 0x15, 0x84, 0x84, 0xC2, 0x41, 0x00, 0x22,
  33033. 0x72, 0x54, 0x22, 0x62, 0x58, 0x06, 0x92, 0x48,
  33034. 0x48, 0x44, 0x11, 0x27, 0x04, 0x04, 0xC0, 0x11,
  33035. 0x92, 0x82, 0x45, 0xA1, 0xC6, 0x8C, 0xE3, 0x32,
  33036. 0x66, 0xC1, 0x38, 0x72, 0x5A, 0x86, 0x01, 0x0C,
  33037. 0xC9, 0x90, 0x84, 0x34, 0x08, 0x58, 0xA8, 0x60,
  33038. 0x80, 0xC0, 0x70, 0xD0, 0x26, 0x62, 0x9B, 0x30,
  33039. 0x2A, 0x04, 0x29, 0x69, 0x04, 0x10, 0x8D, 0x0B,
  33040. 0xB9, 0x04, 0x50, 0x46, 0x28, 0x50, 0x48, 0x24,
  33041. 0xD0, 0x48, 0x05, 0xA2, 0x48, 0x02, 0xC3, 0x20,
  33042. 0x8C, 0xA0, 0x14, 0x00, 0x41, 0x38, 0x21, 0x4B,
  33043. 0x24, 0x01, 0x04, 0xB5, 0x49, 0x42, 0x00, 0x00,
  33044. 0x0C, 0x24, 0x28, 0x12, 0x40, 0x84, 0xA2, 0x20,
  33045. 0x44, 0x9B, 0x06, 0x90, 0x63, 0xC0, 0x88, 0x8C,
  33046. 0x14, 0x21, 0x49, 0x12, 0x10, 0x54, 0x16, 0x24,
  33047. 0x20, 0x87, 0x44, 0x50, 0x10, 0x85, 0x0C, 0xB5,
  33048. 0x64, 0xDB, 0x24, 0x41, 0xD0, 0x42, 0x29, 0x9A,
  33049. 0x16, 0x8A, 0x21, 0xB4, 0x4C, 0x13, 0xB7, 0x70,
  33050. 0x10, 0xC0, 0x85, 0x19, 0x02, 0x69, 0xCC, 0x40,
  33051. 0x61, 0x1C, 0x48, 0x46, 0x98, 0x06, 0x25, 0x60,
  33052. 0x14, 0x46, 0xE4, 0x22, 0x62, 0x24, 0x27, 0x22,
  33053. 0x62, 0x24, 0x29, 0x44, 0xC6, 0x2D, 0x08, 0x31,
  33054. 0x84, 0x20, 0x32, 0x21, 0x04, 0xB4, 0x61, 0x0A,
  33055. 0x38, 0x12, 0xD9, 0x28, 0x44, 0xA4, 0x08, 0x20,
  33056. 0xCC, 0xA8, 0x29, 0x0B, 0x21, 0x31, 0x0A, 0x34,
  33057. 0x29, 0x03, 0x21, 0x40, 0xC1, 0xA2, 0x6C, 0x8A,
  33058. 0x16, 0x12, 0x52, 0xA6, 0x64, 0xA3, 0xB2, 0x51,
  33059. 0x04, 0x29, 0x51, 0xC4, 0x04, 0x91, 0x63, 0xB0,
  33060. 0x2D, 0x14, 0x44, 0x30, 0x8C, 0x40, 0x66, 0x0C,
  33061. 0x40, 0x0C, 0x01, 0xA5, 0x2C, 0x09, 0x94, 0x2D,
  33062. 0x62, 0xC6, 0x11, 0x03, 0x98, 0x50, 0x19, 0x10,
  33063. 0x4D, 0x19, 0xA8, 0x28, 0xD3, 0x86, 0x40, 0xC0,
  33064. 0x30, 0x65, 0x54, 0xA6, 0x71, 0xE0, 0xB4, 0x85,
  33065. 0x9B, 0x86, 0x10, 0x04, 0x36, 0x69, 0xD0, 0x46,
  33066. 0x29, 0x18, 0xA3, 0x71, 0x40, 0x22, 0x49, 0x00,
  33067. 0x43, 0x85, 0xCB, 0x40, 0x28, 0x89, 0x36, 0x66,
  33068. 0x41, 0x22, 0x69, 0xA4, 0x28, 0x51, 0xD9, 0x80,
  33069. 0x29, 0x14, 0x07, 0x21, 0xDA, 0x80, 0x91, 0x1B,
  33070. 0x26, 0x50, 0x5B, 0xA0, 0x60, 0x99, 0x42, 0x71,
  33071. 0x50, 0x88, 0x49, 0x10, 0x23, 0x09, 0x5A, 0x90,
  33072. 0x21, 0x22, 0x27, 0x8E, 0x43, 0xB2, 0x70, 0x0C,
  33073. 0xC9, 0x4C, 0xA4, 0x02, 0x70, 0x92, 0x40, 0x10,
  33074. 0x0A, 0x39, 0x70, 0x02, 0x36, 0x0E, 0x11, 0x30,
  33075. 0x41, 0xD8, 0x40, 0x2D, 0x1B, 0x24, 0x6D, 0xC3,
  33076. 0x92, 0x61, 0x4C, 0x86, 0x8D, 0x21, 0xB8, 0x00,
  33077. 0xD3, 0x24, 0x22, 0x12, 0xC8, 0x21, 0x12, 0x99,
  33078. 0x85, 0x09, 0x16, 0x0C, 0x5A, 0xA2, 0x24, 0x09,
  33079. 0x34, 0x42, 0x10, 0xA2, 0x24, 0x03, 0x42, 0x8C,
  33080. 0xC0, 0xB2, 0x8D, 0x12, 0xB6, 0x69, 0x63, 0x34,
  33081. 0x0D, 0xCC, 0xB0, 0x65, 0xA1, 0x12, 0x11, 0x4A,
  33082. 0x38, 0x69, 0xCC, 0x14, 0x81, 0x58, 0x44, 0x09,
  33083. 0x54, 0xA6, 0x80, 0x0C, 0xA8, 0x05, 0xC4, 0x38,
  33084. 0x8A, 0x84, 0x06, 0x01, 0x9B, 0x32, 0x2D, 0x83,
  33085. 0x12, 0x90, 0x09, 0x02, 0x60, 0xA1, 0x28, 0x88,
  33086. 0x58, 0x10, 0x41, 0x24, 0x40, 0x02, 0x19, 0x34,
  33087. 0x48, 0x18, 0xA0, 0x4D, 0x00, 0x10, 0x62, 0x13,
  33088. 0x22, 0x50, 0xE3, 0x38, 0x21, 0x9A, 0x96, 0x21,
  33089. 0x53, 0x08, 0x80, 0x51, 0x26, 0x01, 0x99, 0xC4,
  33090. 0x28, 0x1B, 0xB9, 0x71, 0x04, 0x97, 0x84, 0x04,
  33091. 0x05, 0x2C, 0xA0, 0xC2, 0x10, 0xD3, 0x42, 0x81,
  33092. 0x81, 0x42, 0x4D, 0x61, 0x84, 0x6C, 0x5A, 0x30,
  33093. 0x49, 0x1B, 0xC2, 0x24, 0xC0, 0x20, 0x28, 0xCA,
  33094. 0x92, 0x2D, 0x4A, 0x90, 0x10, 0x04, 0x27, 0x86,
  33095. 0x4C, 0x96, 0x21, 0x09, 0x19, 0x45, 0x14, 0x82,
  33096. 0x2C, 0x11, 0xA6, 0x91, 0x13, 0xB8, 0x04, 0x03,
  33097. 0x18, 0x70, 0x01, 0xA2, 0x51, 0x52, 0x14, 0x49,
  33098. 0x5A, 0x02, 0x30, 0xCB, 0x30, 0x2C, 0x94, 0x10,
  33099. 0x2C, 0x00, 0x49, 0x86, 0x09, 0xA0, 0x25, 0xC2,
  33100. 0x12, 0x4C, 0x1B, 0x02, 0x69, 0x40, 0xA4, 0x44,
  33101. 0x41, 0x16, 0x62, 0x02, 0x25, 0x28, 0xDC, 0xA2,
  33102. 0x2D, 0x00, 0x16, 0x42, 0x58, 0x30, 0x66, 0x5B,
  33103. 0x86, 0x24, 0xD4, 0x24, 0x48, 0xDB, 0x26, 0x0C,
  33104. 0x4C, 0x08, 0x85, 0x01, 0x90, 0x49, 0x21, 0x24,
  33105. 0x41, 0x54, 0x06, 0x84, 0x02, 0x43, 0x4A, 0x24,
  33106. 0x42, 0x05, 0x40, 0x14, 0x48, 0xCA, 0x44, 0x84,
  33107. 0xC0, 0x42, 0x0C, 0x98, 0x26, 0x04, 0x9C, 0xA2,
  33108. 0x05, 0xD1, 0xC2, 0x51, 0x13, 0x01, 0x86, 0x1C,
  33109. 0xA1, 0x50, 0xD9, 0x02, 0x50, 0x0C, 0x39, 0x86,
  33110. 0x8C, 0x00, 0x31, 0x22, 0x05, 0x48, 0xD3, 0x10,
  33111. 0x81, 0x12, 0x48, 0x05, 0xD1, 0x08, 0x69, 0x62,
  33112. 0x38, 0x2C, 0x0A, 0x23, 0x70, 0x9B, 0x44, 0x72,
  33113. 0xE3, 0x48, 0x6E, 0x22, 0x96, 0x70, 0x14, 0x33,
  33114. 0x6C, 0xD8, 0x90, 0x29, 0x03, 0x00, 0x49, 0x63,
  33115. 0x20, 0x8A, 0x03, 0x91, 0x25, 0x08, 0x89, 0x21,
  33116. 0xC0, 0x82, 0x0C, 0x99, 0x40, 0x32, 0xC2, 0x34,
  33117. 0x4E, 0x4B, 0x98, 0x69, 0x09, 0x80, 0x44, 0xE4,
  33118. 0x04, 0x69, 0x94, 0x20, 0x09, 0x99, 0x24, 0x6D,
  33119. 0x09, 0xA9, 0x60, 0x01, 0x29, 0x2D, 0xC8, 0x42,
  33120. 0x28, 0x8A, 0x34, 0x02, 0xE4, 0x08, 0x70, 0x0C,
  33121. 0x23, 0x6E, 0x0A, 0x05, 0x49, 0x64, 0x44, 0x2A,
  33122. 0x82, 0xC8, 0x00, 0x02, 0x48, 0x31, 0xCB, 0x90,
  33123. 0x50, 0x1C, 0x05, 0x68, 0x12, 0x12, 0x2C, 0xD0,
  33124. 0x80, 0x0C, 0x59, 0x48, 0x61, 0xCB, 0xA6, 0x09,
  33125. 0x9C, 0xC0, 0x81, 0x42, 0xB8, 0x00, 0x24, 0x41,
  33126. 0x8A, 0x94, 0x20, 0x40, 0x42, 0x14, 0x4D, 0x19,
  33127. 0x46, 0x62, 0x18, 0x05, 0x09, 0x24, 0x33, 0x6A,
  33128. 0xD4, 0x00, 0x61, 0x12, 0x48, 0x32, 0x8A, 0x04,
  33129. 0x72, 0x93, 0xB4, 0x69, 0x62, 0xC2, 0x71, 0x41,
  33130. 0xA6, 0x89, 0x44, 0x96, 0x31, 0x62, 0x30, 0x46,
  33131. 0x83, 0x42, 0x6C, 0x00, 0x19, 0x22, 0x09, 0x46,
  33132. 0x4D, 0x8B, 0x06, 0x49, 0xE1, 0xB0, 0x70, 0x42,
  33133. 0x44, 0x31, 0xC1, 0x80, 0x65, 0x9C, 0x00, 0x24,
  33134. 0x11, 0xA8, 0x31, 0x13, 0x21, 0x2C, 0x4B, 0x46,
  33135. 0x28, 0x1B, 0x18, 0x0D, 0x88, 0x42, 0x70, 0xD1,
  33136. 0xB0, 0x0D, 0x90, 0xC8, 0x45, 0xDA, 0xC2, 0x48,
  33137. 0x59, 0x14, 0x26, 0x22, 0x44, 0x00, 0xC2, 0x94,
  33138. 0x41, 0x50, 0xC8, 0x04, 0x18, 0x00, 0x00, 0xCB,
  33139. 0xA6, 0x24, 0x19, 0x02, 0x10, 0x10, 0x89, 0x0C,
  33140. 0x18, 0x22, 0x21, 0x62, 0xA8, 0x81, 0xC8, 0x92,
  33141. 0x48, 0xD3, 0x94, 0x20, 0x82, 0x06, 0x72, 0x09,
  33142. 0xA8, 0x90, 0x0C, 0x49, 0x8A, 0x41, 0x86, 0x28,
  33143. 0x19, 0xC5, 0x80, 0x9A, 0x18, 0x4D, 0x14, 0x10,
  33144. 0x2E, 0x22, 0x12, 0x52, 0x00, 0x08, 0x12, 0x0C,
  33145. 0x33, 0x45, 0x63, 0xC6, 0x30, 0x10, 0x93, 0x4C,
  33146. 0x60, 0xC6, 0x31, 0xDC, 0x40, 0x0E, 0x98, 0x82,
  33147. 0x50, 0x60, 0x02, 0x2A, 0xD2, 0x22, 0x40, 0xE4,
  33148. 0x06, 0x2D, 0xDB, 0x32, 0x0E, 0xCA, 0x32, 0x4E,
  33149. 0xD4, 0x18, 0x24, 0x08, 0xC3, 0x28, 0x4A, 0xC2,
  33150. 0x68, 0xE2, 0x80, 0x40, 0xA1, 0xC8, 0x64, 0x51,
  33151. 0xC2, 0x65, 0xCB, 0x16, 0x60, 0x23, 0x09, 0x4C,
  33152. 0x82, 0x04, 0x68, 0xD9, 0x22, 0x2E, 0x1C, 0x49,
  33153. 0x92, 0x42, 0x24, 0x21, 0x00, 0x37, 0x0E, 0xC8,
  33154. 0x12, 0x72, 0x64, 0x08, 0x25, 0x0A, 0x20, 0x2A,
  33155. 0x58, 0x24, 0x04, 0x59, 0x16, 0x4C, 0x08, 0x17,
  33156. 0x30, 0x00, 0x46, 0x05, 0x12, 0x90, 0x40, 0x03,
  33157. 0x07, 0x21, 0x52, 0xC0, 0x64, 0x1C, 0x83, 0x6D,
  33158. 0x9C, 0x32, 0x2E, 0x11, 0x15, 0x8A, 0x10, 0x35,
  33159. 0x88, 0x5A, 0xA0, 0x8D, 0xD9, 0x80, 0x48, 0x03,
  33160. 0xB6, 0x4C, 0x01, 0x10, 0x65, 0x10, 0x86, 0x40,
  33161. 0x11, 0x01, 0x42, 0x0A, 0xC1, 0x64, 0xDB, 0x22,
  33162. 0x4D, 0x64, 0xB2, 0x51, 0x02, 0x36, 0x0D, 0x93,
  33163. 0x46, 0x31, 0x14, 0xB6, 0x68, 0x63, 0x84, 0x29,
  33164. 0xC8, 0x10, 0x24, 0x94, 0x30, 0x08, 0x19, 0x37,
  33165. 0x02, 0x14, 0x82, 0x45, 0x88, 0x28, 0x40, 0x54,
  33166. 0xA8, 0x29, 0x90, 0x14, 0x12, 0x61, 0x36, 0x12,
  33167. 0x0B, 0x09, 0x8C, 0xA4, 0x98, 0x28, 0xC2, 0x92,
  33168. 0x45, 0x4C, 0x00, 0x60, 0x63, 0xC4, 0x81, 0xC0,
  33169. 0x36, 0x25, 0xCA, 0x88, 0x2D, 0x24, 0x40, 0x30,
  33170. 0xD3, 0xA8, 0x2D, 0xC9, 0xC8, 0x25, 0xD2, 0x84,
  33171. 0x48, 0x00, 0x32, 0x92, 0x50, 0xA2, 0x71, 0xD3,
  33172. 0x44, 0x0D, 0x22, 0x34, 0x60, 0x12, 0x13, 0x12,
  33173. 0x86, 0x8C, 0x5F, 0x86, 0x20, 0x79, 0x4A, 0x05,
  33174. 0x0E, 0x20, 0xD0, 0xE1, 0x01, 0x17, 0x86, 0x24,
  33175. 0x0E, 0xA6, 0x64, 0xF2, 0xF6, 0x9B, 0xB1, 0xB7,
  33176. 0xE3, 0x0E, 0xC6, 0x6B, 0x1A, 0x4A, 0x0B, 0xE5,
  33177. 0x9B, 0x79, 0xF2, 0x19, 0x8A, 0xD9, 0x80, 0x44,
  33178. 0x83, 0xE4, 0x75, 0xE5, 0x3B, 0x3C, 0x49, 0xCB,
  33179. 0x0C, 0xE5, 0xEF, 0x92, 0x91, 0x2A, 0xF4, 0x40,
  33180. 0xF2, 0x3B, 0x99, 0x58, 0x13, 0xD1, 0x1B, 0x59,
  33181. 0xF7, 0x98, 0xE9, 0x3C, 0x9D, 0x13, 0x53, 0x98,
  33182. 0x17, 0xC7, 0xAC, 0x68, 0xCA, 0xD1, 0xAA, 0x1A,
  33183. 0xC2, 0x76, 0x56, 0xBD, 0x0C, 0x47, 0x97, 0xE9,
  33184. 0xC8, 0xEC, 0x17, 0x78, 0x4C, 0x1A, 0x32, 0x7A,
  33185. 0x9D, 0xFE, 0xAF, 0x4D, 0x61, 0x91, 0xEE, 0xCD,
  33186. 0xAF, 0xE0, 0x49, 0xB7, 0x33, 0xFE, 0x39, 0xD5,
  33187. 0xEB, 0x40, 0x00, 0x93, 0x6F, 0xEE, 0xFC, 0xF8,
  33188. 0x29, 0x28, 0xE9, 0xF9, 0x4C, 0xFD, 0x5C, 0xF4,
  33189. 0xC1, 0xE3, 0xDE, 0xB1, 0x43, 0x3A, 0x47, 0xF6,
  33190. 0xD3, 0x28, 0xB5, 0xE8, 0x3D, 0xD1, 0x56, 0xD0,
  33191. 0x18, 0x2D, 0xC6, 0x92, 0x34, 0x75, 0x91, 0xAA,
  33192. 0x6F, 0x73, 0x2C, 0xFB, 0xE9, 0x82, 0x93, 0x5F,
  33193. 0xD1, 0x84, 0x6C, 0xAC, 0xF4, 0xCB, 0x85, 0x15,
  33194. 0xC5, 0x5A, 0xB8, 0x5E, 0xE5, 0xAD, 0x44, 0xCB,
  33195. 0x09, 0xD3, 0x26, 0x9E, 0x2E, 0x6D, 0x11, 0x78,
  33196. 0x09, 0x61, 0xFD, 0x13, 0x1D, 0x5E, 0x6F, 0xBF,
  33197. 0x89, 0x84, 0x9F, 0x47, 0xF2, 0xB7, 0x1D, 0x82,
  33198. 0x83, 0xFF, 0x25, 0x38, 0x5E, 0x52, 0xB0, 0x7D,
  33199. 0xBB, 0x26, 0x6C, 0x67, 0x4C, 0xEE, 0x3D, 0x0B,
  33200. 0x5D, 0xF5, 0xA5, 0x6D, 0x8B, 0xDC, 0xDC, 0xFA,
  33201. 0xAE, 0xE6, 0xA2, 0x48, 0xE7, 0x1D, 0xB1, 0x34,
  33202. 0x5A, 0xFC, 0x59, 0x7C, 0xA8, 0x30, 0xA1, 0xA3,
  33203. 0x5B, 0x43, 0x96, 0xEF, 0x4C, 0x1A, 0xDF, 0x9E,
  33204. 0xD0, 0x1B, 0xCE, 0x9B, 0x6E, 0xB6, 0x37, 0xFA,
  33205. 0x24, 0xAA, 0x16, 0x0B, 0x90, 0x76, 0xBA, 0xE3,
  33206. 0x05, 0x59, 0xF8, 0xB2, 0x9D, 0xED, 0xB3, 0xD2,
  33207. 0x5B, 0x79, 0x06, 0x4A, 0xB0, 0xCF, 0x8B, 0x8D,
  33208. 0x70, 0xAD, 0xDD, 0xEB, 0x8B, 0x17, 0x42, 0x48,
  33209. 0xD5, 0xAE, 0xA4, 0xD1, 0x8D, 0xE4, 0x3B, 0x89,
  33210. 0x38, 0xCD, 0xD2, 0xAC, 0xBA, 0x54, 0x77, 0xBD,
  33211. 0x4A, 0xAC, 0xC3, 0xCE, 0x59, 0x5E, 0x5D, 0x26,
  33212. 0x9F, 0xE6, 0x75, 0x21, 0x0D, 0x23, 0x15, 0x2B,
  33213. 0x04, 0x71, 0x0F, 0x36, 0x84, 0x28, 0x79, 0x4A,
  33214. 0x75, 0xF4, 0x9B, 0x68, 0x3E, 0xD2, 0x0D, 0xD6,
  33215. 0x47, 0x51, 0x57, 0x77, 0x95, 0x5A, 0x8C, 0xB3,
  33216. 0x8A, 0x36, 0xAF, 0xCD, 0x2C, 0xE0, 0xAC, 0xEC,
  33217. 0x4F, 0x0D, 0xFE, 0x80, 0x77, 0x02, 0xD1, 0xEB,
  33218. 0x3B, 0xDE, 0x72, 0xE9, 0xE0, 0x85, 0xAA, 0x4E,
  33219. 0x09, 0xEB, 0x1B, 0x09, 0x47, 0x41, 0x38, 0x52,
  33220. 0xEC, 0x3C, 0x0A, 0xC5, 0x2F, 0x06, 0xCB, 0x95,
  33221. 0x9C, 0x85, 0x39, 0x4E, 0xB3, 0x74, 0x81, 0x19,
  33222. 0xED, 0xBE, 0x6C, 0x80, 0xD2, 0xD8, 0xF7, 0x92,
  33223. 0xCE, 0x0D, 0x91, 0x5E, 0x4F, 0x4B, 0x15, 0x1E,
  33224. 0xFB, 0x13, 0x5E, 0x7F, 0x4D, 0xC9, 0x7D, 0x85,
  33225. 0x81, 0x41, 0xC5, 0x7F, 0x70, 0x41, 0x7B, 0x43,
  33226. 0xA6, 0xA1, 0x26, 0x95, 0x69, 0x78, 0xD7, 0x8E,
  33227. 0xFB, 0x9F, 0x03, 0x72, 0x43, 0xB4, 0xCB, 0x41,
  33228. 0xDF, 0x96, 0x8B, 0x7E, 0xE5, 0xB5, 0x20, 0x87,
  33229. 0xF0, 0x5A, 0xA9, 0xFE, 0x48, 0x7B, 0xD1, 0x6C,
  33230. 0x03, 0x47, 0xCF, 0x13, 0x35, 0x76, 0x0B, 0xD2,
  33231. 0x39, 0x8A, 0xD5, 0x4D, 0xDA, 0x00, 0xA5, 0xAA,
  33232. 0xC4, 0x46, 0xD8, 0x0B, 0x1C, 0x79, 0x98, 0xC6,
  33233. 0x02, 0x19, 0x2A, 0xDA, 0xFC, 0xB8, 0x09, 0xD1,
  33234. 0x4E, 0xE3, 0x28, 0x64, 0x1B, 0xA3, 0xAA, 0x00,
  33235. 0xF8, 0xD2, 0x9C, 0x3A, 0x84, 0x8A, 0xCB, 0xDC,
  33236. 0x19, 0x46, 0xBC, 0x0D, 0x35, 0xE0, 0xBE, 0x0F,
  33237. 0x8F, 0x7E, 0x3D, 0xA3, 0xF6, 0x8D, 0x9F, 0xA9,
  33238. 0x76, 0x8F, 0x5C, 0xF2, 0x75, 0x53, 0x4A, 0x0E,
  33239. 0xCA, 0x9E, 0x60, 0xFC, 0xEA, 0x38, 0xF1, 0xE0,
  33240. 0x42, 0xC3, 0x16, 0x14, 0x3A, 0x76, 0x7B, 0x33,
  33241. 0xAC, 0xCA, 0xD8, 0xC8, 0xD6, 0x6C, 0x70, 0xC7,
  33242. 0x5F, 0xD1, 0xF0, 0xB2, 0x58, 0x6B, 0x65, 0x3A,
  33243. 0xD4, 0xAF, 0x54, 0xE5, 0x6E, 0xF0, 0x69, 0x33,
  33244. 0xEA, 0xD3, 0x1D, 0xE3, 0x65, 0xD1, 0x10, 0xB9,
  33245. 0xC4, 0xA2, 0xA9, 0x8B, 0xCB, 0xA1, 0x65, 0xCA,
  33246. 0xFE, 0x38, 0x6F, 0x88, 0x7C, 0x72, 0x15, 0x6E,
  33247. 0xB1, 0x4F, 0xF0, 0xDA, 0xD6, 0x65, 0x61, 0x6C,
  33248. 0xE3, 0xCE, 0x65, 0xC1, 0x90, 0x4F, 0x2C, 0x17,
  33249. 0x47, 0xB2, 0xEC, 0x2B, 0x5C, 0x9D, 0x67, 0x76,
  33250. 0xBC, 0xD7, 0x9E, 0x5A, 0xC6, 0x4B, 0x79, 0x33,
  33251. 0xBD, 0xDE, 0xDE, 0xDD, 0xBB, 0xC7, 0x25, 0xBF,
  33252. 0xDB, 0xCC, 0xDE, 0x2F, 0xB3, 0x75, 0xAE, 0x2B,
  33253. 0xE3, 0x53, 0x7B, 0xDF, 0x89, 0xBF, 0x4C, 0x25,
  33254. 0xF8, 0x3A, 0x49, 0xD6, 0xA6, 0xA8, 0xD0, 0x76,
  33255. 0x1C, 0xF3, 0x9D, 0x62, 0x0C, 0x53, 0xED, 0x83,
  33256. 0x7D, 0x19, 0x82, 0x55, 0xCF, 0x5B, 0x91, 0x0A,
  33257. 0x6D, 0xB5, 0x78, 0x77, 0xDF, 0x92, 0xD8, 0xBB,
  33258. 0x6E, 0x9C, 0x52, 0x6B, 0x8C, 0x4E, 0xC9, 0x31,
  33259. 0x00, 0xDE, 0xE0, 0x50, 0x0A, 0x21, 0x0C, 0x98,
  33260. 0x45, 0x83, 0xE1, 0x53, 0x81, 0x60, 0xED, 0xAC,
  33261. 0x2C, 0x6F, 0x86, 0x6E, 0x7F, 0x5D, 0x99, 0xD7,
  33262. 0xB1, 0xB8, 0x15, 0x82, 0xF5, 0xD0, 0xEB, 0xBF,
  33263. 0x27, 0x86, 0xE3, 0xF5, 0x56, 0x01, 0x3B, 0xA9,
  33264. 0xB6, 0xF6, 0x56, 0xEB, 0x79, 0x88, 0x38, 0xEA,
  33265. 0x05, 0x79, 0x20, 0x1A, 0x95, 0xD5, 0x6B, 0xBC,
  33266. 0x3B, 0xCD, 0xB9, 0x51, 0x1A, 0xFB, 0xD4, 0xD8,
  33267. 0x12, 0x88, 0x89, 0x6F, 0x87, 0x10, 0x8C, 0x07,
  33268. 0x7F, 0x1A, 0x81, 0xA3, 0xBD, 0x29, 0x7B, 0xB1,
  33269. 0x24, 0xA8, 0x00, 0x86, 0x89, 0x02, 0x42, 0x99,
  33270. 0x5E, 0x03, 0xCF, 0x42, 0xA0, 0xC2, 0x1E, 0x27,
  33271. 0x2A, 0x9A, 0xFA, 0x1D, 0xC1, 0x03, 0x46, 0x3D,
  33272. 0x2A, 0xB4, 0x94, 0xF7, 0xD0, 0x17, 0x68, 0x6D,
  33273. 0x31, 0x89, 0x4D, 0xD2, 0xF6, 0xEB, 0xB0, 0xC3,
  33274. 0xCB, 0x62, 0x23, 0xEC, 0x79, 0xC6, 0x5D, 0x45,
  33275. 0xC1, 0xB0, 0xD4, 0xEF, 0x19, 0x61, 0xF1, 0x6D,
  33276. 0x65, 0x3F, 0xCF, 0x25, 0x97, 0x7B, 0x65, 0x1E,
  33277. 0xC5, 0x1A, 0x13, 0xAE, 0x8D, 0x4A, 0x34, 0x72,
  33278. 0xEE, 0x71, 0x96, 0x9A, 0x7A, 0x93, 0x6F, 0x5D,
  33279. 0xBB, 0xB9, 0x39, 0x6A, 0x46, 0xD9, 0x76, 0x42,
  33280. 0x35, 0x8C, 0xAF, 0x48, 0x94, 0xC9, 0xA6, 0xDF,
  33281. 0x84, 0xA5, 0x9C, 0x59, 0x62, 0xA6, 0x99, 0x0A,
  33282. 0x76, 0xF0, 0x61, 0x48, 0x90, 0x16, 0x9F, 0x00,
  33283. 0x18, 0x70, 0xD4, 0x9C, 0xF2, 0xE7, 0x50, 0x08,
  33284. 0xCC, 0x4A, 0x5D, 0x85, 0xE7, 0x2D, 0xE2, 0xD6,
  33285. 0xCF, 0x3F, 0xA7, 0x18, 0x52, 0x25, 0x35, 0x22,
  33286. 0xFE, 0x8B, 0x0E, 0x42, 0x3C, 0xB4, 0x17, 0xA3,
  33287. 0x8E, 0xB7, 0x8C, 0x87, 0x63, 0xC3, 0x72, 0x0C,
  33288. 0x04, 0xE6, 0x7F, 0xF8, 0x89, 0x79, 0xEB, 0xA0,
  33289. 0x9E, 0x34, 0x53, 0x8B, 0xB5, 0x23, 0xB9, 0x9B,
  33290. 0x8E, 0x34, 0x16, 0x74, 0x12, 0xF7, 0x7A, 0xEA,
  33291. 0x89, 0x4D, 0x83, 0xAC, 0xF9, 0x46, 0xFC, 0x05,
  33292. 0x4D, 0x0A, 0xF4, 0x72, 0x95, 0xE5, 0x1E, 0xD8,
  33293. 0x3F, 0x74, 0x86, 0x94, 0x0A, 0x4D, 0x41, 0xC0,
  33294. 0x4A, 0xD7, 0xEB, 0xEE, 0x61, 0x0B, 0xF1, 0xD0,
  33295. 0x3F, 0xA5, 0x40, 0x71, 0xD5, 0x1A, 0x15, 0x09,
  33296. 0xE4, 0xF4, 0x91, 0x63, 0xA2, 0x50, 0x81, 0xBE,
  33297. 0x87, 0x90, 0xD0, 0x87, 0xF5, 0xF4, 0xF0, 0x5C,
  33298. 0x88, 0x55, 0x0F, 0xCA, 0x9B, 0xF9, 0x9C, 0x9B,
  33299. 0xE5, 0x95, 0x3D, 0x51, 0xDD, 0x08, 0x45, 0xC9,
  33300. 0x3E, 0x41, 0xEE, 0xEF, 0x62, 0xE0, 0x79, 0x4B,
  33301. 0x29, 0x27, 0xC4, 0xF5, 0xED, 0x9B, 0xD3, 0xE3,
  33302. 0x4E, 0xA9, 0x20, 0x0A, 0x79, 0xDD, 0xEB, 0x4B,
  33303. 0x2D, 0x8F, 0x30, 0x5F, 0xE0, 0x5F, 0x82, 0x7C,
  33304. 0x7E, 0x2E, 0xD1, 0x86, 0x34, 0x1C, 0xB5, 0xD1,
  33305. 0x15, 0x2F, 0xC8, 0x01, 0x04, 0xE0, 0xE1, 0x36,
  33306. 0x83, 0xD9, 0x41, 0x29, 0x4C, 0x77, 0x84, 0x17,
  33307. 0x16, 0x4B, 0x68, 0x4A, 0x97, 0x6E, 0x56, 0xE7,
  33308. 0x8D, 0xA4, 0xD1, 0x7C, 0x3C, 0x73, 0x22, 0x93,
  33309. 0x14, 0x87, 0x0B, 0x85, 0xC4, 0x55, 0xC2, 0x3B,
  33310. 0x83, 0x0B, 0x9A, 0x28, 0xA3, 0xD8, 0xC0, 0xB5,
  33311. 0x66, 0x42, 0x6D, 0xC1, 0x69, 0xF3, 0x26, 0xAB,
  33312. 0xCE, 0x2E, 0xFF, 0xF3, 0x9E, 0x9B, 0x19, 0x9A,
  33313. 0xE5, 0xC1, 0x29, 0x2B, 0x6F, 0x2E, 0xF3, 0x7A,
  33314. 0xF1, 0xDE, 0xA9, 0x27, 0x2C, 0x8D, 0x54, 0x23,
  33315. 0xDF, 0x8A, 0x56, 0x32, 0xF9, 0x91, 0xE1, 0x4D,
  33316. 0xCA, 0x25, 0x14, 0x78, 0x8B, 0x62, 0xBE, 0x16,
  33317. 0x48, 0x28, 0xE9, 0xAC, 0xB8, 0x93, 0xDD, 0xA6,
  33318. 0x02, 0xA5, 0xE2, 0xFB, 0x9E, 0xFC, 0xBE, 0xFD,
  33319. 0x95, 0xAB, 0xFB, 0x82, 0xD2, 0xB0, 0x2D, 0x49,
  33320. 0xCC, 0x53, 0x08, 0x4A, 0x49, 0xAB, 0x1B, 0xEC,
  33321. 0x23, 0xE5, 0xB4, 0xC8, 0xE7, 0x14, 0xCB, 0x03,
  33322. 0x40, 0x5F, 0x1B, 0xCF, 0x7E, 0x11, 0xBB, 0x59,
  33323. 0x72, 0x9D, 0xDC, 0x0B, 0x7B, 0xEF, 0xB2, 0x91,
  33324. 0x27, 0x6D, 0xCE, 0xDA, 0xCA, 0xAD, 0x39, 0xA2,
  33325. 0xF0, 0x1C, 0x7D, 0xC9, 0x8B, 0x9E, 0x06, 0x5E,
  33326. 0xAF, 0xED, 0x1C, 0xC8, 0xCE, 0x3E, 0x84, 0x80,
  33327. 0x80, 0xA2, 0xFC, 0x5B, 0x98, 0xC9, 0xF6, 0xBF,
  33328. 0x50, 0x40, 0x27, 0x33, 0x42, 0xF0, 0x31, 0x2F,
  33329. 0x8B, 0x98, 0x44, 0x59, 0x4A, 0x50, 0x3D, 0xD3,
  33330. 0xE6, 0xAF, 0x1C, 0x9E, 0x35, 0xC1, 0x03, 0x2A,
  33331. 0x4A, 0x8A, 0x5E, 0x7B, 0xF3, 0x3A, 0x82, 0xF3,
  33332. 0x5E, 0x16, 0xED, 0xF8, 0xC6, 0x0C, 0x90, 0x02,
  33333. 0x1D, 0x8C, 0x0B, 0xA4, 0xC3, 0x86, 0x24, 0x5D,
  33334. 0xFE, 0xF0, 0x94, 0x48, 0x43, 0x1D, 0x8C, 0x00,
  33335. 0xD1, 0xE2, 0x6E, 0xE4, 0xD8, 0xC7, 0x7D, 0xAA,
  33336. 0x1A, 0x70, 0x5E, 0xD4, 0x79, 0x2A, 0xCB, 0x4E,
  33337. 0xA2, 0x7C, 0x15, 0x66, 0xFB, 0x56, 0x68, 0x3C,
  33338. 0x43, 0xBF, 0x67, 0x84, 0x2E, 0x67, 0x53, 0x4C,
  33339. 0xB3, 0xF9, 0x67, 0x7C, 0x8A, 0xB9, 0xD0, 0xEE,
  33340. 0xE7, 0x82, 0x7C, 0xDE, 0xFC, 0x22, 0x3A, 0xC9,
  33341. 0x48, 0xB8, 0x80, 0xB5, 0xF1, 0xCE, 0x95, 0x37,
  33342. 0x27, 0x29, 0x32, 0x00, 0x2C, 0x1A, 0x4D, 0xD2,
  33343. 0x18, 0xF5, 0x27, 0x16, 0x6E, 0xBF, 0xB2, 0xB2,
  33344. 0xFA, 0x2B, 0xF3, 0x72, 0x46, 0xEC, 0xDF, 0xDF,
  33345. 0xA7, 0x2B, 0x6D, 0xA1, 0x1C, 0x30, 0xD1, 0xC7,
  33346. 0xD2, 0x48, 0xAD, 0x64, 0x81, 0x8F, 0x69, 0x1D,
  33347. 0x59, 0xB7, 0x55, 0xDA, 0xF7, 0x1B, 0xED, 0x9A,
  33348. 0xB5, 0xFB, 0x52, 0xE0, 0x36, 0x22, 0xA9, 0x00,
  33349. 0xD6, 0x6B, 0x4C, 0x63, 0x84, 0x16, 0x9B, 0xDF,
  33350. 0x9E, 0xB6, 0x1C, 0x02, 0xDF, 0x45, 0xFB, 0x76,
  33351. 0xB1, 0xA2, 0x6F, 0x34, 0xE9, 0x38, 0xB1, 0x90,
  33352. 0x86, 0x17, 0x45, 0xC0, 0x21, 0xFA, 0x87, 0x62,
  33353. 0x00, 0xC7, 0xFC, 0x8E, 0x22, 0x2D, 0xDB, 0xFA,
  33354. 0xD8, 0xBE, 0x78, 0x1B, 0x18, 0x54, 0x24, 0xAA,
  33355. 0xAF, 0xC6, 0x58, 0x62, 0xDB, 0x13, 0x2B, 0xEC,
  33356. 0x6D, 0x18, 0x83, 0x7A, 0x1F, 0x58, 0xA8, 0x76,
  33357. 0xC9, 0x9E, 0x63, 0xF5, 0x14, 0x20, 0xB8, 0x3F,
  33358. 0x45, 0x96, 0x75, 0x61, 0x2F, 0x7A, 0xCF, 0x80,
  33359. 0xB4, 0xEB, 0x1D, 0xD0, 0x72, 0x1C, 0xAA, 0x1B,
  33360. 0x49, 0x70, 0xDA, 0x60, 0x86, 0x79, 0xC6, 0x38,
  33361. 0x3E, 0x81, 0x7F, 0xE1, 0x6B, 0x66, 0xB1, 0x91,
  33362. 0x81, 0xED, 0xFC, 0x39, 0x27, 0x0C, 0x7E, 0x91,
  33363. 0x7B, 0x1F, 0x10, 0xEB, 0x7A, 0x01, 0x19, 0x97,
  33364. 0xE9, 0x67, 0x85, 0x3B, 0x78, 0xE0, 0x0C, 0xFD,
  33365. 0x58, 0xD2, 0x24, 0xD9, 0x33, 0xCC, 0x5A, 0x99,
  33366. 0x55, 0x32, 0xDC, 0xD4, 0xE5, 0x32, 0xE4, 0x03,
  33367. 0x05, 0x15, 0xF4, 0xA0, 0x5B, 0x33, 0x1D, 0x57,
  33368. 0x5D, 0xDA, 0xC2, 0x9B, 0xAB, 0x06, 0x9F, 0x09,
  33369. 0xAF, 0x0D, 0x17, 0x33, 0x73, 0xDB, 0x1E, 0xC2,
  33370. 0xB6, 0x36, 0x6B, 0xB3, 0x71, 0x00, 0x8A, 0x23,
  33371. 0x86, 0xFD, 0x88, 0xBE, 0x77, 0xF5, 0xED, 0x5E,
  33372. 0x19, 0x8C, 0xBE, 0x88, 0xDF, 0x24, 0xBC, 0x6E,
  33373. 0x39, 0x3F, 0xEB, 0xC1, 0x0C, 0x47, 0x0A, 0x72,
  33374. 0xD4, 0x7C, 0x0F, 0x83, 0x46, 0x53, 0xC9, 0xAE,
  33375. 0x80, 0x0E, 0x89, 0x3C, 0x6B, 0xA6, 0x8E, 0xA2,
  33376. 0x8A, 0x83, 0x8F, 0xCB, 0xB6, 0x9C, 0x3E, 0x96,
  33377. 0x4A, 0x5F, 0xAF, 0xC2, 0x06, 0x7D, 0xD4, 0x06,
  33378. 0xB2, 0x57, 0xC9, 0x8D, 0xD3, 0x97, 0x9E, 0xC7,
  33379. 0xC7, 0xEC, 0xBE, 0x96, 0xA3, 0x3D, 0x85, 0x51,
  33380. 0x5D, 0xA2, 0xCB, 0x6A, 0xA5, 0xE1, 0xFF, 0xF2,
  33381. 0x04, 0xAF, 0x62, 0xDD, 0x41, 0x19, 0xA0, 0xE4,
  33382. 0x8C, 0x04, 0xA3, 0xF2, 0xB3, 0x86, 0x60, 0xF5,
  33383. 0x29, 0x64, 0xD8, 0xD4, 0xAE, 0xE1, 0x46, 0xA9,
  33384. 0xC5, 0x3C, 0x31, 0x90, 0x6D, 0xAD, 0x0F, 0xD9,
  33385. 0x0B, 0x5D, 0x83, 0xB3, 0xE3, 0x1B, 0x69, 0x0A,
  33386. 0x4C, 0x49, 0x35, 0x24, 0x99, 0x81, 0xBE, 0x1F,
  33387. 0x1A, 0x85, 0xEC, 0x6E, 0x0F, 0xEE, 0x4C, 0x88,
  33388. 0xF2, 0xD8, 0x9E, 0x29, 0x69, 0xAB, 0x8C, 0xBB,
  33389. 0xEB, 0x50, 0x19, 0x16, 0x55, 0x8D, 0x29, 0xEA,
  33390. 0x7C, 0x3E, 0xCF, 0x1C, 0x9E, 0xF1, 0xA0, 0x43,
  33391. 0x50, 0x63, 0x3B, 0x4C, 0xDA, 0x73, 0x7D, 0xFB,
  33392. 0x15, 0x1C, 0xB5, 0xE7, 0x36, 0x11, 0x73, 0xF3,
  33393. 0xAE, 0xDD, 0xDF, 0x52, 0x7D, 0x73, 0xF2, 0xF9,
  33394. 0xD5, 0xB6, 0x21, 0x3A, 0xA6, 0x8F, 0x88, 0x3E,
  33395. 0x9A, 0x26, 0x33, 0x78, 0x5E, 0xC6, 0xBE, 0x64,
  33396. 0x2A, 0x9F, 0xD0, 0xF2, 0x1A, 0x42, 0xF6, 0xB9,
  33397. 0xDA, 0xAB, 0xDC, 0xD1, 0xE6, 0xAD, 0xBE, 0xF6,
  33398. 0x48, 0x41, 0xB5, 0x96, 0x86, 0xEA, 0xE3, 0xEC,
  33399. 0x88, 0xEE, 0xF0, 0xA9, 0xCB, 0xC1, 0x2B, 0xC0,
  33400. 0x12, 0x62, 0x2D, 0xF2, 0xDD, 0x93, 0xA8, 0x62,
  33401. 0x29, 0x04, 0x4A, 0xF2, 0xF2, 0x60, 0xD2, 0x18,
  33402. 0x3F, 0x51, 0xE8, 0x33, 0xEE, 0x92, 0xD9, 0x8F,
  33403. 0x02, 0x51, 0xE3, 0xF8, 0x5F, 0xAB, 0x74, 0xCE,
  33404. 0x36, 0x7B, 0x8B, 0x7A, 0xA6, 0x3D, 0x3C, 0xF8,
  33405. 0xC8, 0xBF, 0x4D, 0x78, 0x35, 0x8B, 0xAE, 0x0A,
  33406. 0x02, 0x41, 0xE2, 0x10, 0xAC, 0x69, 0x35, 0x30,
  33407. 0x87, 0xCC, 0x73, 0x31, 0x35, 0x7E, 0xB4, 0x45,
  33408. 0x0F, 0x95, 0x09, 0xCF, 0xE5, 0x95, 0xF5, 0x40,
  33409. 0x32, 0xEE, 0x05, 0x77, 0x54, 0xA8, 0xED, 0xD7,
  33410. 0x46, 0xCB, 0x92, 0x82, 0xE7, 0x68, 0xDC, 0x6B,
  33411. 0x83, 0x0C, 0x5B, 0x4A, 0x21, 0x93, 0x43, 0xAD,
  33412. 0x12, 0x4E, 0xDB, 0x3B, 0xBC, 0x42, 0x50, 0x55,
  33413. 0x66, 0xA7, 0x03, 0x8C, 0x95, 0x9B, 0xC3, 0x55,
  33414. 0x85, 0xB6, 0x05, 0x5F, 0x19, 0x68, 0xDA, 0x24,
  33415. 0x3F, 0x77, 0x8F, 0x4E, 0x46, 0xDB, 0x46, 0x2A,
  33416. 0xBE, 0xB9, 0x3B, 0x81, 0x24, 0x3C, 0x31, 0xEB,
  33417. 0x59, 0x62, 0x2E, 0xDF, 0x81, 0xF0, 0x6C, 0xCC,
  33418. 0x61, 0xD2, 0xA6, 0xEA, 0x73, 0xE1, 0x09, 0xC3,
  33419. 0x87, 0x91, 0x5F, 0x27, 0x7B, 0xCF, 0x1F, 0xC1,
  33420. 0x11, 0x05, 0xBB, 0xA7, 0x02, 0x93, 0xC0, 0xFA,
  33421. 0xB5, 0xC0, 0x65, 0xF2, 0x3B, 0xAA, 0x19, 0x29,
  33422. 0x0A, 0x30, 0x2F, 0x08, 0x09, 0x11, 0x07, 0xA4,
  33423. 0xB1, 0xD5, 0x68, 0x85, 0x26, 0x22, 0x09, 0x83,
  33424. 0x83, 0x42, 0x77, 0x60, 0xEF, 0x8F, 0x29, 0x28,
  33425. 0x62, 0x5B, 0xDD, 0xA5, 0xF5, 0x14, 0xC5, 0xAD,
  33426. 0xE9, 0x59, 0x89, 0x1E, 0xF2, 0x95, 0x9F, 0x24,
  33427. 0x8A, 0x35, 0x32, 0xBF, 0x9D, 0x30, 0xE7, 0x14,
  33428. 0x05, 0x9E, 0xBD, 0xEC, 0x95, 0x87, 0x08, 0xF8,
  33429. 0xA8, 0x3C, 0x26, 0x8B, 0xEF, 0x26, 0x82, 0xD6,
  33430. 0x03, 0xCA, 0x88, 0x63, 0x47, 0xE1, 0x98, 0xFD,
  33431. 0x68, 0x23, 0x39, 0x99, 0xC7, 0x7D, 0x30, 0xD7,
  33432. 0x45, 0x5D, 0xE6, 0xBC, 0xFD, 0x01, 0x44, 0x27,
  33433. 0x70, 0x62, 0xB3, 0x04, 0xBE, 0xF0, 0xE3, 0x4C,
  33434. 0x5A, 0x9D, 0x8D, 0x78, 0x0D, 0x29, 0xEC, 0x23,
  33435. 0x21, 0xE0, 0x73, 0x40, 0x77, 0x1C, 0x46, 0x36,
  33436. 0x04, 0x83, 0xAD, 0xCA, 0xF1, 0x2D, 0x5B, 0x79,
  33437. 0xFD, 0xBF, 0xE2, 0x85, 0x6A, 0xCE, 0x88, 0x59,
  33438. 0xF6, 0xB1, 0x24, 0x14, 0xB3, 0xF7, 0xE8, 0xBB,
  33439. 0x58, 0x13, 0x49, 0x89, 0x60, 0xF3, 0x4F, 0xDC,
  33440. 0x64, 0xFC, 0x84, 0x85, 0x79, 0xCA, 0xF9, 0xDC,
  33441. 0xCF, 0x19, 0xB4, 0xFB, 0x82, 0x5E, 0xD5, 0x71,
  33442. 0x6D, 0xCC, 0xCD, 0x68, 0x72, 0xCB, 0xDE, 0x38,
  33443. 0x31, 0xD6, 0x73, 0x84, 0x94, 0x2C, 0xD8, 0xA9,
  33444. 0xEC, 0x4B, 0xBF, 0xEF, 0x57, 0x06, 0xB8, 0xF9,
  33445. 0xF0, 0x5F, 0xE1, 0xE8, 0xFE, 0x69, 0xD3, 0xEA,
  33446. 0x6A, 0x86, 0x21, 0xC2, 0x21, 0x44, 0x17, 0x7B,
  33447. 0x1C, 0x12, 0x59, 0xE1, 0xA7, 0x9D, 0xFD, 0xF8,
  33448. 0x97, 0x28, 0x88, 0x7B, 0xEF, 0x1A, 0x70, 0x48,
  33449. 0x25, 0x56, 0x83, 0x1B, 0x67, 0x24, 0x40, 0xE1,
  33450. 0x3F, 0xE3, 0xE3, 0xFC, 0x82, 0x04, 0xA0, 0x2E,
  33451. 0xA1, 0xEF, 0xF1, 0x9D, 0x95, 0x25, 0x38, 0x87,
  33452. 0x28, 0x5B, 0xFB, 0xEA, 0x16, 0xA0, 0xF2, 0x19,
  33453. 0xEF, 0xBC, 0xEC, 0x30, 0xA8, 0xAE, 0x86, 0x58,
  33454. 0x9A, 0x57, 0x03, 0x10, 0x3A, 0x8A, 0x39, 0x3F,
  33455. 0xA6, 0xF6, 0xB6, 0x57, 0x70, 0x4A, 0xC6, 0x77,
  33456. 0xC1, 0x4C, 0xD1, 0x0D, 0x3D, 0x62, 0xD1, 0x3F,
  33457. 0xBD, 0x37, 0x8C, 0x2D, 0xDA, 0x32, 0x5B, 0x61,
  33458. 0xB8, 0x59, 0x52, 0xD5, 0x12, 0x93, 0x87, 0x1E,
  33459. 0x1F, 0xCD, 0xC9, 0x48, 0xC7, 0x7B, 0xEA, 0xE9,
  33460. 0xA6, 0xF0, 0xE8, 0x7C, 0xE1, 0xA8, 0x05, 0x1C,
  33461. 0x8F, 0x80, 0x87, 0x68, 0x5C, 0x12, 0x62, 0x4B,
  33462. 0xDF, 0x58, 0x38, 0x0E, 0xD6, 0x6F, 0x55, 0xB4,
  33463. 0x3D, 0xDD, 0x6D, 0x36, 0x21, 0x73, 0xA5, 0xBD,
  33464. 0x38, 0x98, 0x59, 0xC1, 0x7D, 0x95, 0xEC, 0xE3,
  33465. 0xAB, 0x73, 0x26, 0x39, 0xFF, 0xE4, 0x51, 0xCD,
  33466. 0x10, 0x3E, 0xE4, 0x85, 0x4D, 0xB2, 0xF3, 0x96,
  33467. 0x14, 0xF6, 0x58, 0xBA, 0xA3, 0x84, 0xBC, 0x99,
  33468. 0x48, 0xD0, 0x71, 0x4E, 0xB4, 0x8A, 0x88, 0x71,
  33469. 0x43, 0xE7, 0xA1, 0xFA, 0x4B, 0x69, 0x0C, 0x22,
  33470. 0xB4, 0x92, 0xA7, 0x0C, 0x61, 0x2B, 0x59, 0xFF,
  33471. 0xD2, 0xD6, 0xB3, 0xB5, 0xE9, 0x9C, 0x20, 0x03,
  33472. 0xE2, 0xC3, 0x59, 0xB1, 0xE6, 0x2D, 0xCB, 0x62,
  33473. 0x0C, 0x7A, 0x24, 0x6A, 0x7B, 0x9B, 0x32, 0x46,
  33474. 0x13, 0x15, 0x56, 0xF2, 0xF3, 0xD5, 0x13, 0xA2,
  33475. 0x3C, 0x6A, 0x9F, 0xD2, 0x28, 0x0E, 0xD6, 0x86,
  33476. 0xD7, 0x67, 0xCC, 0xD0, 0x17, 0x54, 0xEB, 0x4C,
  33477. 0x99, 0x69, 0x2F, 0x2B, 0x38, 0x0C, 0x36, 0x08,
  33478. 0x13, 0x44, 0xC1, 0xD3, 0x5E, 0xE1, 0x94, 0x97,
  33479. 0x36, 0xB6, 0x97, 0x6F, 0x48, 0x52, 0xCF, 0xBE,
  33480. 0x64, 0xFA, 0xBC, 0xF1, 0x1B, 0x9A, 0xFB, 0x82,
  33481. 0x85, 0x76, 0xB4, 0xF9, 0x78, 0x7A, 0xA7, 0xD0,
  33482. 0x3E, 0x84, 0x59, 0x8A, 0x71, 0x43, 0xEF, 0x73,
  33483. 0x11, 0xFA, 0xF2, 0x97, 0x0E, 0x23, 0xED, 0x4C,
  33484. 0x17, 0x3F, 0x98, 0x5D, 0x64, 0x50, 0x16, 0x5A,
  33485. 0xE3, 0xE2, 0x41, 0xA1, 0x82, 0x34, 0xE7, 0x4F,
  33486. 0xF3, 0xDD, 0xB9, 0x21, 0xA5, 0x30, 0x0B, 0x1C,
  33487. 0x4F, 0xB6, 0xE4, 0x32, 0xE6, 0x98, 0xF5, 0x3F,
  33488. 0x66, 0xE3, 0x8C, 0x07, 0xBC, 0xD6, 0xE7, 0x76,
  33489. 0x05, 0xDF, 0x46, 0x24, 0xD5, 0x79, 0x07, 0x62,
  33490. 0x92, 0xDE, 0x1C, 0xE6, 0xFC, 0x6F, 0x00, 0x81,
  33491. 0xA3, 0x8B, 0xD9, 0x2D, 0x39, 0xB2, 0x4B, 0x73,
  33492. 0xBA, 0xC1, 0xC5, 0x2B, 0xD6, 0x8E, 0x91, 0x81,
  33493. 0xD3, 0xDC, 0xD0, 0xAC, 0x75, 0x34, 0xDB, 0x48,
  33494. 0x90, 0x1E, 0x59, 0x84, 0xF9, 0x90, 0x25, 0x57,
  33495. 0xBF, 0xA2, 0x31, 0xB2, 0xEA, 0x28, 0xC3, 0x18,
  33496. 0x32, 0x62, 0xA1, 0xB2, 0x22, 0x1F, 0x74, 0x26,
  33497. 0xEA, 0x88, 0xA5, 0x81, 0x60, 0x93, 0xA5, 0xCA,
  33498. 0xE2, 0xCD, 0x5D, 0x59, 0xA9, 0x39, 0x0F, 0xC9,
  33499. 0x3A, 0x29, 0x56, 0x94, 0x4B, 0x06, 0x4C, 0xF0,
  33500. 0x13, 0xBC, 0xDB, 0x67, 0xFB, 0x42, 0x3D, 0x13,
  33501. 0x28, 0xD2, 0xC6, 0xD7, 0xBA, 0x32, 0x90, 0x13,
  33502. 0xFA, 0x2D, 0x30, 0xEF, 0xD6, 0x9F, 0xDC, 0xA1,
  33503. 0xA9, 0x5E, 0xA6, 0xD0, 0x6C, 0x73, 0x63, 0x53,
  33504. 0x4B, 0x2F, 0x3F, 0x7D, 0xAA, 0xFA, 0x29, 0x6E,
  33505. 0xAA, 0x09, 0xB3, 0x66, 0x8E, 0x9C, 0xF8, 0x2D,
  33506. 0x9B, 0xA9, 0x59, 0xB3, 0x2F, 0x3C, 0xAD, 0x3C,
  33507. 0x10, 0xC6, 0xEA, 0x48, 0x61, 0x15, 0x54, 0x53,
  33508. 0x9C, 0x37, 0xDF, 0x6B, 0xCA, 0x33, 0x85, 0xEA,
  33509. 0xD3, 0xFC, 0xFF, 0x96, 0xD3, 0x72, 0xB4, 0x23,
  33510. 0x93, 0xB7, 0x3C, 0x8D, 0xAA, 0xAA, 0x31, 0x50,
  33511. 0x6E, 0xE0, 0x52, 0x7B, 0x7F, 0xB3, 0xE5, 0x93,
  33512. 0xDC, 0xCC, 0xA5, 0x7C, 0x8F, 0xBB, 0xD4, 0xA3,
  33513. 0xC7, 0xF8, 0xA5, 0x38, 0x99, 0x86, 0x91, 0x32,
  33514. 0xFB, 0xC3, 0xE4, 0x05, 0x06, 0x07, 0xBB, 0xFE,
  33515. 0x29, 0xC6, 0x75, 0xE3, 0x94, 0x5E, 0x74, 0xA3,
  33516. 0x1C, 0xD5, 0x31, 0xBA, 0x7A, 0xEB, 0x2E, 0x2F,
  33517. 0x0C, 0xD9, 0x90, 0xB8, 0xF9, 0x83, 0xA9, 0x0D,
  33518. 0xFE, 0xA0, 0x56, 0x8F, 0x06, 0x77, 0xEA, 0x95,
  33519. 0x63, 0xF7, 0xC4, 0x79, 0xDE, 0x96, 0x89, 0x40,
  33520. 0xCF, 0x24, 0x29, 0x92, 0x69, 0x28, 0x65, 0xCF,
  33521. 0xDA, 0x89, 0xFA, 0x07, 0x8B, 0xBE, 0xF4, 0x9C,
  33522. 0xE4, 0x57, 0x5B, 0xDF, 0xB3, 0x80, 0x36, 0x60,
  33523. 0x11, 0xC8, 0x43, 0x5F, 0x12, 0xB4, 0x2D, 0x9A,
  33524. 0xB9, 0x9A, 0xB6, 0xA3, 0x19, 0x12, 0xC4, 0x35,
  33525. 0x41, 0x49, 0xD7, 0x23, 0x10, 0x1D, 0x13, 0x65,
  33526. 0xA6, 0x5E, 0x7C, 0xC6, 0x8D, 0x82, 0xE3, 0x05,
  33527. 0x17, 0x77, 0x39, 0x02, 0xFB, 0x38, 0xDD, 0xA2,
  33528. 0xB3, 0x24, 0xE7, 0x20, 0x8E, 0x98, 0x7E, 0xD2,
  33529. 0x87, 0xD0, 0x92, 0xE7, 0x66, 0x2A, 0x43, 0x02,
  33530. 0x41, 0xBF, 0xCA, 0x55, 0x2D, 0x31, 0x41, 0x27,
  33531. 0xE3, 0x8C, 0x85, 0x97, 0xA8, 0x95, 0x19, 0xD4,
  33532. 0xF1, 0xE6, 0x2A, 0x79, 0x46, 0x5A, 0xD5, 0xF4,
  33533. 0xEA, 0xA3, 0xFA, 0x77, 0xCD, 0x98, 0x32, 0x6D,
  33534. 0x2F, 0x92, 0xCE, 0x98, 0x52, 0x05, 0x5C, 0xEC,
  33535. 0xCF, 0x62, 0xD6, 0x3C, 0xB9, 0xD7, 0xF1, 0x98,
  33536. 0xAE, 0x08, 0x5E, 0x4D, 0x45, 0xC8, 0xE4, 0x8F,
  33537. 0xCF, 0xFE, 0x59, 0x3A, 0xD6, 0x52, 0xD9, 0x15,
  33538. 0x41, 0x67, 0xBF, 0x3E, 0x61, 0x95, 0x81, 0x0A,
  33539. 0x44, 0x5A, 0xE1, 0x58, 0xF1, 0xF9, 0xA6, 0x79,
  33540. 0x33, 0x63, 0xAF, 0xC1, 0xF2, 0x2C, 0xA8, 0x82,
  33541. 0xFE, 0xED, 0x3A, 0x5F, 0x57, 0x27, 0xCA, 0x76,
  33542. 0x47, 0x7C, 0x5F, 0x23, 0xF0, 0xFC, 0x87, 0x00,
  33543. 0xCD, 0xC6, 0xA5, 0xBC, 0xB2, 0xB2, 0x0B, 0x4F,
  33544. 0x92, 0x66, 0x35, 0x1D, 0x30, 0x4A, 0x96, 0xA8,
  33545. 0x2B, 0xF5, 0xF3, 0x14, 0xAF, 0x68, 0x5C, 0x1C,
  33546. 0x70, 0x7C, 0x92, 0xE3, 0xE8, 0x47, 0xB7, 0x04,
  33547. 0x7D, 0x68, 0x9C, 0x70, 0xB2, 0x5E, 0x55, 0x01,
  33548. 0xCA, 0xEC, 0x99, 0x19, 0x62, 0x6F, 0x4A, 0x0F,
  33549. 0xC8, 0x15, 0x86, 0xAF, 0x1E, 0xC8, 0x88, 0x89,
  33550. 0xB4, 0x23, 0x38, 0x7D, 0x5D, 0x95, 0x48, 0x26,
  33551. 0x18, 0xA6, 0x50, 0xE8, 0x0B, 0x53, 0xB0, 0x7C,
  33552. 0xAC, 0xE3, 0x22, 0x89, 0x40, 0x60, 0x2E, 0x3D,
  33553. 0xB4, 0x74, 0x66, 0xCE, 0x9B, 0xCC, 0xB6, 0xE4,
  33554. 0xD8, 0xAA, 0x61, 0xC8, 0x91, 0x25, 0x83, 0xE8,
  33555. 0x10, 0xB3, 0xB2, 0xE7, 0xE9, 0xCB, 0x48, 0xBD,
  33556. 0x40, 0x3E, 0xCF, 0x08, 0xD2, 0x8C, 0x70, 0xAE,
  33557. 0x0B, 0x62, 0x08, 0x59, 0xC1, 0xF0, 0x9B, 0x61,
  33558. 0x13, 0x14, 0x04, 0xC3, 0xD5, 0xBF, 0xFC, 0xD8,
  33559. 0x60, 0xE0, 0xF4, 0x2A, 0xB2, 0x99, 0x00, 0x62,
  33560. 0x30, 0xB2, 0x87, 0x6D, 0x77, 0xDD, 0xA9, 0x1C,
  33561. 0x8C, 0x62, 0xBD, 0x93, 0xA8, 0x44, 0xE4, 0xB3,
  33562. 0x44, 0xE3, 0x25, 0x5E, 0xEA, 0x53, 0x1C, 0x6C,
  33563. 0x45, 0x8D, 0x04, 0xAB, 0xDB, 0x0F, 0xAE, 0xF2,
  33564. 0xD1, 0xC0, 0xB4, 0xC5, 0x5F, 0x57, 0x0A, 0x5A,
  33565. 0x51, 0x02, 0x3F, 0x4D, 0x4E, 0xFF, 0xF5, 0x9F,
  33566. 0x9A, 0xBE, 0x17, 0x92, 0x2F, 0xE7, 0x32, 0xCA,
  33567. 0x71, 0xBC, 0xD4, 0x34, 0xAD, 0x77, 0x10, 0xB8,
  33568. 0x4C, 0xD4, 0xAC, 0x9F, 0x25, 0x07, 0xA0, 0x68,
  33569. 0x26, 0x56, 0x2A, 0xD7, 0xF6, 0x47, 0x82, 0x6F,
  33570. 0x9D, 0xBB, 0xE4, 0xED, 0xD2, 0x3F, 0x12, 0x43,
  33571. 0x69, 0xDB, 0x85, 0x26, 0xFC, 0x2B, 0x4D, 0x52,
  33572. 0xF0, 0x74, 0x14, 0x15, 0xF9, 0x72, 0xBE, 0xF6,
  33573. 0xA9, 0x35, 0xBD, 0x81, 0x2A, 0x56, 0xC8, 0x22,
  33574. 0x1B, 0x7D, 0xEF, 0x0F, 0x51, 0x06, 0xBC, 0x01,
  33575. 0xE9, 0x13, 0xE3, 0xD4, 0x3D, 0xB8, 0x6C, 0x2B,
  33576. 0xB4, 0xC7, 0xE0, 0x76, 0x26, 0x63, 0xC6, 0xDE,
  33577. 0x78, 0x87, 0x21, 0xC2, 0xAA, 0x07, 0xF8, 0x95,
  33578. 0x48, 0x87, 0xE2, 0x14, 0x2F, 0x2E, 0x91, 0x4A,
  33579. 0x09, 0x9E, 0xFC, 0x0A, 0xEE, 0x13, 0x39, 0x21,
  33580. 0x0D, 0x3E, 0x53, 0xDA, 0x3E, 0xCF, 0x88, 0x62,
  33581. 0x4B, 0x11, 0x19, 0xBE, 0x34, 0x01, 0x0B, 0x88,
  33582. 0x6C, 0x80, 0xF5, 0x1D, 0x18, 0x50, 0x83, 0x8F,
  33583. 0x21, 0x50, 0xE7, 0x2B, 0x04, 0x2A, 0xF3, 0x28,
  33584. 0x99, 0xC0, 0xD3, 0xD7, 0xB0, 0x2A, 0x57, 0xF8,
  33585. 0xCF, 0x26, 0x3A, 0x36, 0x95, 0x62, 0xE4, 0xE9,
  33586. 0x45, 0xA3, 0x12, 0x82, 0xA5, 0x02, 0xA9, 0x5E,
  33587. 0xE9, 0xBB, 0x03, 0x16, 0xC6, 0x86, 0x10, 0x06,
  33588. 0xDA, 0xC1, 0x7F, 0x93, 0x6F, 0x54, 0xC4, 0xC7
  33589. };
  33590. #endif /* WOLFSSL_NO_ML_DSA_87 */
  33591. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  33592. #ifndef WOLFSSL_NO_ML_DSA_44
  33593. static const byte seed_44_draft[] = {
  33594. 0xBA, 0xC0, 0x59, 0x52, 0x75, 0x5B, 0x26, 0x47,
  33595. 0x01, 0xCA, 0x7D, 0x80, 0x6D, 0xFA, 0x08, 0x35,
  33596. 0x10, 0x28, 0xF6, 0x7B, 0x0E, 0x83, 0xC4, 0x24,
  33597. 0x01, 0x6F, 0x66, 0xCC, 0x83, 0x87, 0xD4, 0x69
  33598. };
  33599. static const byte pk_44_draft[] = {
  33600. 0x86, 0xF0, 0x0C, 0x20, 0xE0, 0xDA, 0xEE, 0x5E,
  33601. 0x1E, 0xDE, 0x71, 0x39, 0x49, 0x0C, 0xC8, 0xCF,
  33602. 0xEF, 0xC9, 0xAB, 0x62, 0x3B, 0x8D, 0xEF, 0x0B,
  33603. 0xD8, 0x03, 0x12, 0x5B, 0x4A, 0xB2, 0x83, 0x61,
  33604. 0xED, 0x7E, 0xA9, 0xED, 0x2D, 0xED, 0x5A, 0x71,
  33605. 0xDD, 0xAE, 0x4A, 0x06, 0xE0, 0x2A, 0x5A, 0xAF,
  33606. 0x99, 0x69, 0x89, 0xC6, 0xAF, 0xE3, 0x2A, 0xFE,
  33607. 0x3D, 0x6E, 0x0A, 0x46, 0x71, 0x48, 0xD7, 0x17,
  33608. 0x99, 0x20, 0x01, 0x78, 0xD5, 0x8B, 0x40, 0xCB,
  33609. 0x81, 0xA0, 0x33, 0x38, 0xAE, 0x2B, 0x83, 0x4A,
  33610. 0xFD, 0x5F, 0xE0, 0xB7, 0xEE, 0xA0, 0xC4, 0x3D,
  33611. 0xB6, 0xA4, 0xD5, 0x59, 0x4B, 0xDD, 0x87, 0x1A,
  33612. 0xFC, 0x03, 0x30, 0xA0, 0xB3, 0xAD, 0x75, 0x3C,
  33613. 0xD4, 0x47, 0x72, 0x59, 0xCE, 0xB7, 0x80, 0xFD,
  33614. 0x34, 0x35, 0x5E, 0x96, 0xC8, 0x42, 0xD9, 0xDD,
  33615. 0x6C, 0xF1, 0xAB, 0xEF, 0x48, 0xD1, 0xA8, 0x02,
  33616. 0x02, 0x0F, 0x5B, 0x71, 0x4D, 0x36, 0x1E, 0x0D,
  33617. 0xC2, 0x09, 0x46, 0x7B, 0xF9, 0xEA, 0x24, 0x8F,
  33618. 0x7C, 0xCF, 0xB8, 0x9C, 0xF7, 0x49, 0x15, 0x8E,
  33619. 0x16, 0x49, 0x7E, 0xC5, 0x54, 0xF5, 0x03, 0x1D,
  33620. 0x16, 0x12, 0x02, 0x72, 0x1B, 0x38, 0x2D, 0x58,
  33621. 0x53, 0x15, 0x5E, 0xB6, 0x72, 0xCC, 0xA1, 0x09,
  33622. 0xB0, 0x2F, 0x10, 0xFA, 0x21, 0x45, 0x46, 0x37,
  33623. 0xD4, 0xFA, 0x7F, 0xFB, 0xB0, 0xD9, 0x20, 0xE2,
  33624. 0xCB, 0x56, 0xB3, 0x1E, 0xDF, 0x82, 0x67, 0x25,
  33625. 0x09, 0xD1, 0x8F, 0xFF, 0xE0, 0x43, 0xBD, 0x37,
  33626. 0x2B, 0x73, 0x0E, 0x13, 0x08, 0xC9, 0x49, 0x88,
  33627. 0x69, 0x69, 0xD9, 0x8C, 0x86, 0xE4, 0x7E, 0x63,
  33628. 0x35, 0xC5, 0xE1, 0xD0, 0x14, 0x9A, 0x89, 0x27,
  33629. 0x28, 0x17, 0xB0, 0x5B, 0x7A, 0x8F, 0xDD, 0x72,
  33630. 0x8B, 0x0A, 0x0D, 0x49, 0x58, 0x59, 0x2F, 0x0D,
  33631. 0x8F, 0x3D, 0x16, 0xCE, 0x7B, 0x11, 0xC7, 0x06,
  33632. 0x5D, 0xD5, 0x6D, 0x7B, 0x96, 0xED, 0x1E, 0x1A,
  33633. 0xF4, 0x10, 0x85, 0xDA, 0xDE, 0x84, 0x2F, 0x2B,
  33634. 0xBA, 0xFB, 0xA2, 0x5F, 0x33, 0x7D, 0x7C, 0x18,
  33635. 0x6B, 0xDF, 0x43, 0x3C, 0xE9, 0xEB, 0xB4, 0xC5,
  33636. 0x8E, 0x52, 0xF5, 0x7E, 0x4C, 0x3E, 0x6A, 0x33,
  33637. 0x41, 0x4C, 0x14, 0x05, 0x8E, 0x2C, 0x19, 0x0E,
  33638. 0x86, 0x91, 0x66, 0xDE, 0xF6, 0x4B, 0x35, 0xC2,
  33639. 0xDF, 0x3D, 0x4C, 0x7B, 0xC5, 0x58, 0x5E, 0x86,
  33640. 0x89, 0x6A, 0xFC, 0x86, 0x48, 0x75, 0xD1, 0x18,
  33641. 0xD1, 0xCB, 0x41, 0xC0, 0xF6, 0xD8, 0x87, 0x79,
  33642. 0xD9, 0xA2, 0x56, 0x2E, 0x83, 0x26, 0x11, 0xC1,
  33643. 0x4B, 0x53, 0x37, 0x85, 0x62, 0xFF, 0x6A, 0x67,
  33644. 0xFD, 0x18, 0x79, 0xD7, 0x55, 0x9B, 0xF7, 0x64,
  33645. 0xA9, 0x21, 0xB6, 0x1B, 0xF6, 0x11, 0x85, 0xF8,
  33646. 0xC0, 0x68, 0xDE, 0x61, 0x0C, 0x61, 0x7E, 0x8E,
  33647. 0xED, 0x9E, 0x58, 0x84, 0x16, 0x1A, 0x28, 0xC5,
  33648. 0x41, 0x63, 0xB3, 0xF0, 0x82, 0xAA, 0xE8, 0x36,
  33649. 0x81, 0x5C, 0xD3, 0xB7, 0xFB, 0x92, 0xF4, 0x7A,
  33650. 0x1E, 0x85, 0xA2, 0xB7, 0x21, 0xD5, 0xFA, 0xC8,
  33651. 0xE8, 0x02, 0x43, 0x5B, 0x56, 0x42, 0x03, 0x17,
  33652. 0x67, 0xEE, 0x3E, 0x31, 0x23, 0x63, 0xC7, 0x33,
  33653. 0x95, 0xDE, 0x07, 0xF6, 0x11, 0x3A, 0x2C, 0x3F,
  33654. 0x7B, 0xBB, 0x2D, 0x5C, 0x23, 0xF9, 0x2F, 0x9C,
  33655. 0x51, 0x19, 0x9F, 0x35, 0xC3, 0x18, 0x9F, 0x83,
  33656. 0x6E, 0xA8, 0x03, 0xF1, 0x79, 0x1F, 0xB0, 0xC8,
  33657. 0x2F, 0xF4, 0x2E, 0x9A, 0x26, 0xF3, 0x44, 0x02,
  33658. 0x8F, 0x45, 0x8B, 0xB0, 0x25, 0x1D, 0xF2, 0xD4,
  33659. 0x55, 0xB7, 0x65, 0xEF, 0xDB, 0x3D, 0x8E, 0x92,
  33660. 0xC8, 0xA0, 0x63, 0x4C, 0x38, 0xA3, 0x54, 0xD3,
  33661. 0xC2, 0x5A, 0x2A, 0x6A, 0x15, 0x27, 0x2A, 0xE2,
  33662. 0xFC, 0x25, 0xB6, 0xC8, 0x68, 0xEB, 0xED, 0x2D,
  33663. 0x23, 0xE8, 0x6D, 0x5C, 0xDD, 0x3F, 0x18, 0xB4,
  33664. 0x6E, 0x79, 0x36, 0xC9, 0x1C, 0xB4, 0x92, 0x41,
  33665. 0xAD, 0x35, 0xD4, 0x15, 0xE4, 0x64, 0x1C, 0x51,
  33666. 0xCB, 0x0C, 0x41, 0xB7, 0xFD, 0xC1, 0x09, 0x3E,
  33667. 0xD2, 0x4D, 0x38, 0x88, 0x77, 0x1C, 0x71, 0x91,
  33668. 0x74, 0xD3, 0x28, 0xE0, 0xCE, 0x9A, 0x11, 0x8D,
  33669. 0xBF, 0x4D, 0x8D, 0xF0, 0x44, 0xF6, 0x79, 0xFC,
  33670. 0x4C, 0xAD, 0x17, 0x88, 0xC0, 0x8C, 0x0B, 0x7A,
  33671. 0x90, 0x01, 0x53, 0x6C, 0x6B, 0x44, 0xF6, 0xE5,
  33672. 0x2E, 0xEC, 0x44, 0x4F, 0xB8, 0x9B, 0x10, 0xBE,
  33673. 0xCF, 0x55, 0x55, 0x29, 0x83, 0xB8, 0xD0, 0x25,
  33674. 0x5B, 0xCE, 0x8F, 0xA5, 0xB7, 0x6C, 0xA7, 0x47,
  33675. 0x65, 0xA9, 0xE9, 0x9B, 0xA5, 0xBC, 0x28, 0x1D,
  33676. 0x9F, 0x1F, 0x5E, 0x97, 0x42, 0x10, 0x84, 0x92,
  33677. 0xFB, 0x38, 0x0B, 0x2E, 0xAC, 0x79, 0x0A, 0x7D,
  33678. 0x00, 0x2C, 0x35, 0xD0, 0x54, 0x0D, 0x28, 0xE7,
  33679. 0xAB, 0x06, 0x02, 0xDA, 0x89, 0xA3, 0x06, 0x8E,
  33680. 0x13, 0x9A, 0xA7, 0xCA, 0x48, 0x09, 0xB0, 0x48,
  33681. 0x37, 0x08, 0xA7, 0x7D, 0xDA, 0xEB, 0x58, 0x64,
  33682. 0x39, 0xB3, 0xF3, 0xB2, 0x4C, 0x00, 0x4B, 0xCB,
  33683. 0x94, 0x36, 0xD4, 0x7C, 0x73, 0x45, 0xC8, 0x93,
  33684. 0xE5, 0x2A, 0x11, 0xF0, 0xEF, 0x0C, 0xED, 0x5F,
  33685. 0x8B, 0x0C, 0x86, 0xAD, 0x3A, 0x01, 0x07, 0x1A,
  33686. 0xC0, 0x34, 0xE8, 0x74, 0x21, 0x27, 0x73, 0x56,
  33687. 0x93, 0x76, 0x5D, 0x80, 0x59, 0xB4, 0xA4, 0xDC,
  33688. 0x80, 0xE7, 0xCE, 0x70, 0x0E, 0x0F, 0xEC, 0x56,
  33689. 0x42, 0x6E, 0x9C, 0x76, 0x3D, 0xF6, 0xB4, 0x41,
  33690. 0xE2, 0x3E, 0xAC, 0x25, 0xE7, 0x86, 0xA7, 0xA7,
  33691. 0x0A, 0x0D, 0x5D, 0x04, 0x1F, 0x45, 0xD4, 0x5B,
  33692. 0x42, 0x38, 0x4C, 0x60, 0xE7, 0xB7, 0x0D, 0xC7,
  33693. 0x28, 0x4F, 0xA5, 0x4E, 0x0C, 0x1B, 0xC4, 0xDA,
  33694. 0x50, 0x1A, 0xA0, 0x93, 0xAE, 0x10, 0x9A, 0x1A,
  33695. 0xC8, 0xC6, 0x56, 0xFC, 0x0A, 0xEA, 0x89, 0x3A,
  33696. 0x28, 0x21, 0xE9, 0x52, 0x9D, 0xEB, 0x07, 0x68,
  33697. 0xC1, 0x57, 0x32, 0x25, 0x1F, 0x93, 0x5D, 0x35,
  33698. 0xB2, 0x4B, 0x58, 0x30, 0xAF, 0x51, 0xC6, 0x7D,
  33699. 0x47, 0xD1, 0xA2, 0xAD, 0xDE, 0x75, 0x48, 0x84,
  33700. 0x74, 0x19, 0x74, 0x18, 0xA0, 0x2C, 0xD8, 0xB2,
  33701. 0xFE, 0x44, 0x78, 0x95, 0x6A, 0xBF, 0x56, 0x4D,
  33702. 0x20, 0x79, 0xE7, 0xE2, 0xE3, 0x56, 0x69, 0xB3,
  33703. 0xFA, 0xE1, 0xEB, 0xE6, 0x11, 0xAC, 0x18, 0xB3,
  33704. 0x98, 0xC1, 0x04, 0x20, 0x96, 0x4B, 0xAD, 0xDE,
  33705. 0x5B, 0x18, 0xEB, 0x7B, 0xBC, 0x15, 0x11, 0x57,
  33706. 0x29, 0x10, 0xE5, 0x80, 0x78, 0x4A, 0xF0, 0x87,
  33707. 0xF6, 0xD1, 0x3C, 0x23, 0xC5, 0xF4, 0x2D, 0xD7,
  33708. 0xAB, 0xA4, 0xD7, 0xB8, 0x45, 0x8E, 0x04, 0x1B,
  33709. 0x78, 0x59, 0x9F, 0x81, 0xE6, 0x04, 0xDF, 0x70,
  33710. 0x2B, 0x14, 0x74, 0x16, 0x49, 0xDA, 0xF0, 0xE1,
  33711. 0xC8, 0x29, 0xCC, 0x87, 0x8C, 0x2F, 0xFB, 0x18,
  33712. 0x3B, 0x47, 0xFC, 0x79, 0x04, 0x84, 0xCB, 0x0A,
  33713. 0xD2, 0x64, 0xBF, 0x86, 0xEA, 0x01, 0xAC, 0xE0,
  33714. 0xBD, 0xEC, 0x3B, 0xE1, 0xA7, 0x6C, 0xDE, 0x1D,
  33715. 0x58, 0x76, 0xCC, 0x53, 0x9E, 0xF6, 0xC6, 0xD4,
  33716. 0x2C, 0x87, 0x92, 0xA2, 0x89, 0x27, 0x31, 0x33,
  33717. 0x01, 0xA5, 0xA2, 0xE8, 0x8F, 0x13, 0x19, 0x0F,
  33718. 0xFD, 0x73, 0xB9, 0x91, 0xBD, 0xB8, 0x80, 0x9A,
  33719. 0xA3, 0xB1, 0x21, 0x6C, 0x91, 0x13, 0x8A, 0xAE,
  33720. 0xC7, 0xCB, 0x67, 0x14, 0xD1, 0xC0, 0x28, 0x89,
  33721. 0x04, 0x8C, 0x9F, 0xDE, 0xA0, 0x9A, 0x99, 0xA8,
  33722. 0x61, 0xE6, 0x8F, 0x8E, 0x39, 0xEF, 0x6B, 0x5E,
  33723. 0x84, 0x5F, 0x5D, 0x24, 0x37, 0x73, 0x9D, 0x75,
  33724. 0xC4, 0xEF, 0xE2, 0xA1, 0xF2, 0xBC, 0x0D, 0xE1,
  33725. 0x0D, 0xEC, 0xFA, 0xEE, 0xC1, 0x63, 0xC8, 0x2E,
  33726. 0x7D, 0x85, 0x65, 0xC3, 0xF2, 0x0D, 0x8B, 0x73,
  33727. 0xF9, 0x3B, 0x0B, 0x3D, 0x49, 0x8B, 0xFB, 0x16,
  33728. 0x5B, 0x75, 0x48, 0x9B, 0x56, 0x0A, 0x83, 0x4C,
  33729. 0x0D, 0x13, 0xB2, 0xB4, 0x25, 0xC7, 0x2C, 0xCB,
  33730. 0xA7, 0x9E, 0xCA, 0x41, 0x44, 0x14, 0x9A, 0x03,
  33731. 0xD3, 0x01, 0x8C, 0xB0, 0xD5, 0xA9, 0x36, 0xA4,
  33732. 0x16, 0x21, 0x49, 0x0A, 0x99, 0xA1, 0x89, 0xA5,
  33733. 0x91, 0x10, 0xA2, 0x1B, 0x3F, 0x98, 0x1E, 0x1C,
  33734. 0x43, 0xAA, 0x9C, 0x16, 0x5A, 0xF0, 0x18, 0x64,
  33735. 0x0F, 0x6A, 0xE3, 0x97, 0x83, 0x31, 0x4E, 0x84,
  33736. 0xC9, 0xEA, 0xD8, 0x9F, 0xEA, 0x9E, 0xD6, 0xF2,
  33737. 0x0E, 0x15, 0xA5, 0x48, 0x15, 0x8B, 0x10, 0x1D,
  33738. 0x77, 0x78, 0x1B, 0x54, 0x03, 0xC1, 0x2C, 0xB1,
  33739. 0xC8, 0x22, 0x11, 0x9D, 0xB8, 0x82, 0x94, 0x26,
  33740. 0xA0, 0xED, 0x6C, 0xAD, 0xA8, 0x03, 0xC2, 0xED,
  33741. 0x02, 0x74, 0x3E, 0x54, 0xBD, 0x77, 0xA6, 0x0B,
  33742. 0x37, 0xFE, 0x04, 0xCD, 0x25, 0x10, 0x2D, 0x52,
  33743. 0xC2, 0xD4, 0x5B, 0x9B, 0xAE, 0xFE, 0x35, 0x73,
  33744. 0x16, 0x61, 0x84, 0x25, 0x1D, 0xBE, 0x95, 0x34,
  33745. 0xA4, 0xF6, 0xB9, 0xA4, 0xF9, 0xAA, 0x5D, 0x1E,
  33746. 0x49, 0xBB, 0x19, 0xD9, 0x64, 0xD7, 0x48, 0x1A,
  33747. 0x0A, 0x93, 0xC3, 0x69, 0x13, 0x12, 0x68, 0xBB,
  33748. 0x97, 0x97, 0xBD, 0x99, 0x69, 0xCE, 0xE6, 0xF5,
  33749. 0x84, 0x7B, 0xCC, 0xE4, 0x7D, 0xD3, 0xCD, 0x8A,
  33750. 0x7A, 0x4B, 0x98, 0xF4, 0x09, 0x9D, 0xEA, 0x5D,
  33751. 0x4E, 0x1F, 0xE1, 0x1E, 0x6C, 0x48, 0xD3, 0x5E,
  33752. 0x67, 0xD9, 0xFF, 0x64, 0x4D, 0xA7, 0x64, 0x7A,
  33753. 0x01, 0xB2, 0xE9, 0x63, 0x14, 0x10, 0xB7, 0x08,
  33754. 0x0C, 0xF9, 0x4D, 0x66, 0x48, 0x46, 0xE3, 0xC2,
  33755. 0x48, 0x6B, 0x47, 0xCE, 0x00, 0x98, 0x92, 0x83,
  33756. 0xF7, 0xE0, 0x1F, 0x96, 0xFA, 0x53, 0xD5, 0x49,
  33757. 0x1C, 0xC7, 0x89, 0xB4, 0xA5, 0x4B, 0x63, 0xBF,
  33758. 0xD2, 0x00, 0x79, 0xDD, 0xC1, 0x60, 0xAA, 0xF2,
  33759. 0x0F, 0x47, 0xB9, 0x4F, 0x8A, 0x66, 0x05, 0x3D,
  33760. 0x96, 0x36, 0x64, 0x48, 0x5F, 0x7E, 0x56, 0x2B,
  33761. 0xB3, 0x47, 0xE2, 0x76, 0x64, 0x21, 0x65, 0x34,
  33762. 0xFC, 0xDD, 0x2D, 0x4C, 0xE2, 0x99, 0x33, 0x04,
  33763. 0xE4, 0x26, 0x15, 0x37, 0x6C, 0x32, 0xB9, 0x17
  33764. };
  33765. static const byte sk_44_draft[] = {
  33766. 0x86, 0xF0, 0x0C, 0x20, 0xE0, 0xDA, 0xEE, 0x5E,
  33767. 0x1E, 0xDE, 0x71, 0x39, 0x49, 0x0C, 0xC8, 0xCF,
  33768. 0xEF, 0xC9, 0xAB, 0x62, 0x3B, 0x8D, 0xEF, 0x0B,
  33769. 0xD8, 0x03, 0x12, 0x5B, 0x4A, 0xB2, 0x83, 0x61,
  33770. 0x73, 0x61, 0x49, 0x01, 0x0F, 0x94, 0x08, 0x30,
  33771. 0x26, 0x02, 0x12, 0x63, 0x64, 0x15, 0x7A, 0x4D,
  33772. 0xBA, 0xF5, 0x25, 0xA7, 0xAA, 0x0B, 0x7C, 0x3D,
  33773. 0xCE, 0x05, 0x91, 0x95, 0xEF, 0x17, 0x2F, 0xE2,
  33774. 0x5A, 0x03, 0x5E, 0x2E, 0x4D, 0xFA, 0xE7, 0x5F,
  33775. 0xCD, 0x61, 0x34, 0xFB, 0x3D, 0x3C, 0x5C, 0x60,
  33776. 0x1A, 0x6F, 0x09, 0xB5, 0x9D, 0xDD, 0x90, 0x53,
  33777. 0xF6, 0x89, 0x50, 0xC2, 0xE1, 0xED, 0x0A, 0x61,
  33778. 0x8F, 0xFA, 0xDC, 0x2D, 0xB2, 0x8B, 0xA1, 0x56,
  33779. 0xAC, 0x5E, 0x0E, 0xF1, 0x3B, 0x1E, 0x22, 0x9F,
  33780. 0xAA, 0x05, 0x96, 0xA3, 0x5E, 0x44, 0x86, 0xA8,
  33781. 0xBA, 0x15, 0xD1, 0x11, 0x7D, 0xAA, 0xD0, 0xAA,
  33782. 0x01, 0x27, 0x25, 0x04, 0x82, 0x89, 0xA4, 0x22,
  33783. 0x2E, 0xDB, 0x80, 0x45, 0xD2, 0x30, 0x45, 0x59,
  33784. 0x16, 0x64, 0xE2, 0x08, 0x86, 0x50, 0x00, 0x8E,
  33785. 0xCA, 0x08, 0x51, 0x5A, 0x06, 0x01, 0x54, 0x82,
  33786. 0x20, 0xC4, 0x92, 0x30, 0x02, 0x21, 0x4E, 0x0A,
  33787. 0x93, 0x89, 0x84, 0xB8, 0x70, 0x24, 0x40, 0x51,
  33788. 0x24, 0xB3, 0x44, 0xDB, 0x08, 0x40, 0x1B, 0x37,
  33789. 0x44, 0x21, 0x22, 0x8E, 0x8C, 0x16, 0x42, 0x10,
  33790. 0x22, 0x0E, 0xA1, 0xB2, 0x8D, 0x18, 0x49, 0x30,
  33791. 0xC1, 0x32, 0x69, 0x21, 0x03, 0x8E, 0x49, 0x44,
  33792. 0x08, 0xD3, 0x16, 0x89, 0x10, 0xA4, 0x25, 0x5C,
  33793. 0x22, 0x8A, 0xC0, 0xC8, 0x08, 0xC1, 0x04, 0x6A,
  33794. 0xD2, 0xA0, 0x50, 0x8A, 0x02, 0x52, 0x92, 0x16,
  33795. 0x44, 0x54, 0x30, 0x4A, 0x92, 0x32, 0x0C, 0x4C,
  33796. 0x44, 0x2D, 0x04, 0x15, 0x2A, 0x99, 0x24, 0x42,
  33797. 0x52, 0xA8, 0x30, 0x53, 0x24, 0x85, 0x9A, 0xB8,
  33798. 0x01, 0xE2, 0x08, 0x09, 0x23, 0x28, 0x08, 0xC4,
  33799. 0x98, 0x85, 0x0B, 0xB9, 0x40, 0x60, 0x26, 0x28,
  33800. 0x0A, 0x45, 0x12, 0x0C, 0x43, 0x84, 0x82, 0x16,
  33801. 0x89, 0xC4, 0x48, 0x28, 0x58, 0x18, 0x2A, 0x20,
  33802. 0x07, 0x02, 0xD3, 0x82, 0x45, 0x50, 0xB0, 0x50,
  33803. 0x64, 0x36, 0x91, 0x52, 0x02, 0x45, 0x5A, 0x42,
  33804. 0x26, 0x01, 0x28, 0x71, 0xD4, 0x86, 0x10, 0x19,
  33805. 0xC4, 0x68, 0xC4, 0x30, 0x66, 0xE0, 0x02, 0x49,
  33806. 0x18, 0x34, 0x05, 0x04, 0x02, 0x04, 0x90, 0x94,
  33807. 0x4C, 0x01, 0xA7, 0x80, 0x12, 0x97, 0x08, 0x19,
  33808. 0xC5, 0x41, 0x24, 0xC1, 0x61, 0x08, 0xB0, 0x0C,
  33809. 0x21, 0xC1, 0x49, 0x9B, 0x42, 0x51, 0x62, 0x18,
  33810. 0x22, 0x54, 0x06, 0x06, 0x93, 0x26, 0x70, 0x49,
  33811. 0x86, 0x91, 0x00, 0x28, 0x6C, 0x02, 0xC9, 0x60,
  33812. 0x13, 0xC3, 0x09, 0xCB, 0x14, 0x66, 0x09, 0x17,
  33813. 0x25, 0x1C, 0x16, 0x89, 0x01, 0xB6, 0x01, 0x60,
  33814. 0x86, 0x71, 0x58, 0x96, 0x04, 0x82, 0x38, 0x61,
  33815. 0x43, 0x40, 0x72, 0xCC, 0x46, 0x71, 0x81, 0x20,
  33816. 0x2C, 0x18, 0x20, 0x6E, 0x03, 0x91, 0x11, 0x9A,
  33817. 0x08, 0x89, 0x43, 0x06, 0x48, 0x64, 0x02, 0x6C,
  33818. 0x21, 0x33, 0x8D, 0x48, 0x16, 0x66, 0x9B, 0xA4,
  33819. 0x2D, 0x01, 0x10, 0x66, 0xDC, 0xB0, 0x25, 0x40,
  33820. 0xA0, 0x24, 0xA2, 0xB4, 0x44, 0xC8, 0x26, 0x61,
  33821. 0x0A, 0x10, 0x4E, 0xD0, 0x04, 0x11, 0x4A, 0x82,
  33822. 0x51, 0x03, 0x04, 0x6C, 0x18, 0x88, 0x6C, 0xE0,
  33823. 0x98, 0x41, 0x11, 0x29, 0x06, 0x62, 0x12, 0x8E,
  33824. 0xDA, 0x42, 0x91, 0x09, 0x48, 0x60, 0xD1, 0xB4,
  33825. 0x80, 0x10, 0x30, 0x30, 0x80, 0x38, 0x82, 0xD0,
  33826. 0x84, 0x0D, 0x08, 0x14, 0x92, 0x24, 0x41, 0x40,
  33827. 0x0C, 0x10, 0x89, 0xCC, 0x38, 0x8A, 0x13, 0xB6,
  33828. 0x89, 0x1A, 0xA7, 0x24, 0x5C, 0x10, 0x12, 0x1B,
  33829. 0x21, 0x50, 0x91, 0xB4, 0x29, 0x99, 0xB6, 0x51,
  33830. 0x04, 0xB1, 0x91, 0x59, 0xA6, 0x05, 0x19, 0x08,
  33831. 0x4A, 0x4A, 0x84, 0x6C, 0x1C, 0x49, 0x02, 0x44,
  33832. 0x20, 0x85, 0x14, 0xB1, 0x89, 0x09, 0x44, 0x2C,
  33833. 0x10, 0x02, 0x22, 0xE1, 0xB4, 0x25, 0x01, 0x21,
  33834. 0x71, 0x53, 0xC2, 0x85, 0x82, 0x88, 0x28, 0xC0,
  33835. 0x02, 0x52, 0x19, 0xC5, 0x51, 0x19, 0xA5, 0x09,
  33836. 0xC0, 0x82, 0x91, 0x21, 0x47, 0x0D, 0x1C, 0x30,
  33837. 0x69, 0xDC, 0xB8, 0x6C, 0x04, 0x41, 0x6A, 0x91,
  33838. 0x16, 0x40, 0xA0, 0xC8, 0x24, 0x1A, 0x10, 0x01,
  33839. 0x04, 0x39, 0x25, 0x80, 0x16, 0x02, 0x63, 0x36,
  33840. 0x71, 0x90, 0xB0, 0x8D, 0x44, 0x16, 0x8E, 0xDA,
  33841. 0x16, 0x2E, 0xCB, 0x44, 0x20, 0x54, 0x38, 0x06,
  33842. 0x54, 0xC4, 0x01, 0x51, 0x40, 0x86, 0x52, 0x44,
  33843. 0x0E, 0x82, 0x02, 0x32, 0x21, 0x38, 0x89, 0x19,
  33844. 0x04, 0x40, 0xD8, 0x12, 0x68, 0x21, 0x98, 0x11,
  33845. 0x03, 0x33, 0x8A, 0x18, 0x00, 0x45, 0xCB, 0x22,
  33846. 0x32, 0xC3, 0x04, 0x46, 0x09, 0x18, 0x51, 0x22,
  33847. 0x44, 0x89, 0x13, 0x16, 0x6E, 0xDA, 0x46, 0x45,
  33848. 0x09, 0x19, 0x41, 0x81, 0x10, 0x01, 0xDC, 0x18,
  33849. 0x8E, 0xC8, 0x44, 0x4C, 0x00, 0x17, 0x82, 0x9C,
  33850. 0xA6, 0x4D, 0xC8, 0x08, 0x10, 0x24, 0x42, 0x6D,
  33851. 0x91, 0x38, 0x89, 0x8C, 0x40, 0x6E, 0x00, 0x35,
  33852. 0x11, 0xD3, 0x24, 0x09, 0x1A, 0x01, 0x65, 0x88,
  33853. 0x48, 0x45, 0x09, 0x01, 0x71, 0x43, 0xB8, 0x80,
  33854. 0x11, 0x82, 0x2C, 0x84, 0xB8, 0x49, 0x58, 0x14,
  33855. 0x28, 0x92, 0x20, 0x32, 0x09, 0x12, 0x05, 0x20,
  33856. 0x81, 0x2D, 0x5B, 0x86, 0x11, 0x04, 0x90, 0x45,
  33857. 0x49, 0x80, 0x40, 0xD1, 0xC8, 0x24, 0x98, 0xC2,
  33858. 0x2C, 0x99, 0xA2, 0x30, 0x04, 0x98, 0x8C, 0x53,
  33859. 0x24, 0x02, 0x8A, 0x04, 0x01, 0x4C, 0x28, 0x71,
  33860. 0xC3, 0x86, 0x6C, 0x24, 0x49, 0x81, 0x04, 0x02,
  33861. 0x28, 0x62, 0x44, 0x32, 0x61, 0x20, 0x28, 0x01,
  33862. 0x04, 0x11, 0x0C, 0x09, 0x08, 0x90, 0x98, 0x84,
  33863. 0x63, 0xB2, 0x45, 0x63, 0x38, 0x2E, 0x04, 0xA4,
  33864. 0x0C, 0x18, 0x05, 0x4E, 0xCC, 0x86, 0x90, 0x43,
  33865. 0x40, 0x91, 0x54, 0x02, 0x21, 0x43, 0x28, 0x42,
  33866. 0x23, 0x94, 0x29, 0xC8, 0xA6, 0x91, 0x02, 0x09,
  33867. 0x80, 0xE3, 0x82, 0x00, 0xC1, 0x34, 0x08, 0xD1,
  33868. 0x34, 0x84, 0x12, 0x45, 0x8C, 0x02, 0xC6, 0x81,
  33869. 0x41, 0xC6, 0x6C, 0x1B, 0x12, 0x24, 0x04, 0x08,
  33870. 0x0D, 0x02, 0x00, 0x0C, 0x9C, 0xA2, 0x05, 0x49,
  33871. 0x34, 0x65, 0x00, 0x06, 0x89, 0x88, 0x34, 0x00,
  33872. 0xD8, 0x82, 0x29, 0x92, 0x12, 0x91, 0xE3, 0x36,
  33873. 0x86, 0xD1, 0x80, 0x71, 0x98, 0xB0, 0x50, 0x48,
  33874. 0xC6, 0x11, 0x14, 0x80, 0x0D, 0xA0, 0x12, 0x4D,
  33875. 0x9B, 0xB2, 0x40, 0x21, 0x41, 0x50, 0x4B, 0x36,
  33876. 0x05, 0x52, 0x10, 0x26, 0x19, 0xB2, 0x60, 0x92,
  33877. 0xA2, 0x24, 0xCB, 0x08, 0x00, 0x14, 0x22, 0x49,
  33878. 0x5A, 0xD0, 0x55, 0xBD, 0x2B, 0x45, 0xE4, 0x31,
  33879. 0x41, 0xA8, 0xC3, 0xA3, 0xAD, 0xBD, 0xB6, 0x37,
  33880. 0x92, 0x06, 0x95, 0x6B, 0x3D, 0xD8, 0xE5, 0x33,
  33881. 0x71, 0xB6, 0x62, 0xB7, 0x67, 0x6C, 0x77, 0x84,
  33882. 0x63, 0x2F, 0x41, 0x1D, 0xBA, 0x51, 0x27, 0xE1,
  33883. 0x24, 0x5D, 0xC2, 0x38, 0x71, 0x65, 0x9E, 0x8E,
  33884. 0xE4, 0xEB, 0xBB, 0x1D, 0x89, 0xEB, 0x18, 0xCA,
  33885. 0x0C, 0xA6, 0x86, 0xA3, 0x4D, 0x7C, 0x7A, 0x02,
  33886. 0xAC, 0xDD, 0x34, 0xCE, 0x05, 0x3B, 0x1B, 0x49,
  33887. 0xF4, 0x6D, 0x12, 0x33, 0xBC, 0x52, 0x70, 0x59,
  33888. 0xDF, 0xBC, 0x5D, 0x49, 0x42, 0x6A, 0xED, 0xC7,
  33889. 0xF1, 0x8C, 0xF5, 0x6D, 0x1F, 0xBC, 0xE4, 0xBD,
  33890. 0x45, 0x5D, 0x59, 0xF8, 0xCE, 0x9A, 0x39, 0xB5,
  33891. 0x96, 0x32, 0xFD, 0x93, 0x65, 0x8E, 0x92, 0xF1,
  33892. 0x8F, 0xB0, 0x99, 0xF3, 0x80, 0x0F, 0x66, 0x14,
  33893. 0xFE, 0xEB, 0x23, 0x17, 0x2D, 0x4C, 0x8F, 0x41,
  33894. 0x9A, 0x9B, 0xD1, 0x5B, 0x5B, 0xC0, 0x3D, 0xA6,
  33895. 0x0E, 0xF3, 0xE0, 0xA1, 0x04, 0xDC, 0x24, 0x18,
  33896. 0x9D, 0x90, 0xC6, 0x89, 0x5A, 0x7F, 0x10, 0x1E,
  33897. 0x4B, 0x21, 0xEC, 0x91, 0xD8, 0x5D, 0x65, 0xDB,
  33898. 0xCF, 0x90, 0x62, 0x85, 0xE9, 0x58, 0xA3, 0x47,
  33899. 0x92, 0x1C, 0xD0, 0x0C, 0xA3, 0xF3, 0x3E, 0x36,
  33900. 0xDB, 0x24, 0xA6, 0x98, 0xAB, 0xA7, 0x89, 0x2B,
  33901. 0x71, 0x6C, 0x4D, 0x00, 0xB0, 0xD5, 0xA0, 0xCA,
  33902. 0x1A, 0x76, 0x8E, 0x80, 0xB7, 0xAE, 0x83, 0x89,
  33903. 0x50, 0xF8, 0xA7, 0x52, 0x8B, 0x94, 0xD2, 0x2B,
  33904. 0x9F, 0x49, 0x92, 0x3D, 0x54, 0x0D, 0xB8, 0xD1,
  33905. 0x19, 0x49, 0xAC, 0x91, 0xAF, 0xDB, 0xE9, 0x24,
  33906. 0x4D, 0xD8, 0xE1, 0xD5, 0x16, 0x0E, 0xB1, 0x39,
  33907. 0x40, 0x7D, 0x5F, 0xF5, 0x92, 0xB4, 0xAF, 0xC3,
  33908. 0x76, 0x2B, 0xDB, 0x7D, 0x52, 0x97, 0x62, 0x9F,
  33909. 0xCF, 0x32, 0x19, 0x5F, 0xE6, 0x32, 0xFB, 0x8E,
  33910. 0x39, 0x24, 0xB4, 0xEB, 0xE9, 0x17, 0x9E, 0x47,
  33911. 0x69, 0x4D, 0x92, 0x82, 0x96, 0x88, 0x38, 0x11,
  33912. 0xCE, 0xD6, 0xBF, 0x18, 0xE3, 0x51, 0x40, 0x81,
  33913. 0x11, 0xA0, 0x74, 0xDA, 0x0D, 0x5E, 0xEC, 0xD8,
  33914. 0x5D, 0x33, 0x22, 0x1E, 0xB9, 0x5D, 0xBF, 0x79,
  33915. 0xB0, 0xA1, 0xEF, 0xD1, 0x2D, 0xA0, 0x5F, 0xA1,
  33916. 0xC7, 0x6E, 0xD5, 0x08, 0xB8, 0xD0, 0xC1, 0x95,
  33917. 0x51, 0x9B, 0x07, 0xC3, 0x4A, 0x0A, 0xB5, 0xA1,
  33918. 0x28, 0xFE, 0x95, 0x95, 0x0A, 0xCF, 0x83, 0xA8,
  33919. 0xEB, 0x8F, 0xFB, 0x18, 0xD5, 0xBD, 0x69, 0x50,
  33920. 0xF1, 0xDF, 0x06, 0xFA, 0x9A, 0x65, 0x47, 0xBB,
  33921. 0x56, 0xE9, 0xCB, 0x8F, 0x69, 0x5F, 0xE0, 0xAD,
  33922. 0x19, 0x3A, 0x70, 0xE5, 0x66, 0x42, 0xD7, 0x1C,
  33923. 0x0C, 0xB4, 0x03, 0x89, 0x7D, 0x47, 0x4D, 0x29,
  33924. 0x67, 0x8C, 0x41, 0x73, 0xAB, 0x7D, 0xFD, 0x69,
  33925. 0x15, 0xAD, 0xE3, 0xB7, 0xF8, 0x98, 0x3B, 0xCA,
  33926. 0x8F, 0x27, 0x37, 0x7B, 0x72, 0x2C, 0x5F, 0x23,
  33927. 0x73, 0x15, 0xE2, 0xB6, 0xBD, 0xDE, 0x84, 0xF8,
  33928. 0x7E, 0x22, 0xB9, 0xFD, 0xD3, 0x4D, 0x62, 0x80,
  33929. 0xBA, 0xC5, 0x57, 0x29, 0x30, 0x1B, 0x06, 0x4D,
  33930. 0x20, 0xB1, 0x53, 0x86, 0xCB, 0x6A, 0x4A, 0xE3,
  33931. 0xC1, 0xA9, 0x88, 0xCF, 0xEB, 0x15, 0x2F, 0xA8,
  33932. 0xA8, 0x6F, 0xFC, 0x2A, 0xA8, 0x0E, 0xD9, 0xFA,
  33933. 0xEA, 0xD7, 0x3B, 0xCE, 0xF8, 0x5B, 0xD8, 0x92,
  33934. 0x22, 0x6A, 0x1A, 0x8E, 0x5E, 0x91, 0x37, 0x2C,
  33935. 0x21, 0x05, 0xC4, 0xAC, 0xF7, 0x62, 0x83, 0xBA,
  33936. 0x55, 0xD5, 0x2C, 0xCE, 0xA1, 0x19, 0x93, 0x0E,
  33937. 0xDE, 0xB6, 0xB8, 0x78, 0x0F, 0xBF, 0x4C, 0xA4,
  33938. 0x66, 0xAD, 0x97, 0x2F, 0xEE, 0x34, 0xE9, 0xA2,
  33939. 0xB6, 0x1D, 0x3C, 0x60, 0xFB, 0xB8, 0x7F, 0xF8,
  33940. 0xFD, 0x34, 0x8C, 0xC5, 0xC7, 0x38, 0x72, 0x74,
  33941. 0x19, 0xA9, 0xCF, 0x54, 0x49, 0x5B, 0xBA, 0x70,
  33942. 0x12, 0xC1, 0x61, 0xDC, 0x32, 0x61, 0x49, 0x66,
  33943. 0xF3, 0x57, 0xAA, 0x0F, 0xE6, 0x44, 0x9E, 0x8A,
  33944. 0x19, 0x9C, 0x6B, 0x63, 0x2C, 0x14, 0x1E, 0xDD,
  33945. 0x00, 0x27, 0xE3, 0x95, 0xE3, 0xE7, 0xD9, 0xFF,
  33946. 0x30, 0x2D, 0x14, 0x19, 0x4F, 0x49, 0x20, 0x0B,
  33947. 0x58, 0x2A, 0x23, 0x1C, 0xE2, 0xAD, 0x6B, 0x9C,
  33948. 0x7B, 0xB6, 0x20, 0x63, 0x08, 0x24, 0x55, 0x04,
  33949. 0x58, 0x1F, 0x0E, 0xBE, 0x2A, 0x6F, 0x79, 0x90,
  33950. 0x9E, 0x15, 0x8F, 0x4B, 0xDB, 0xE2, 0xBE, 0xBC,
  33951. 0x28, 0xB1, 0xC8, 0xFE, 0x00, 0x6D, 0x71, 0xCC,
  33952. 0x91, 0x6A, 0xCC, 0xF8, 0x12, 0x8B, 0xEC, 0xF3,
  33953. 0x46, 0x53, 0xB1, 0x7F, 0xB3, 0x79, 0xF0, 0xC7,
  33954. 0xD7, 0xA5, 0xCF, 0x2C, 0xC3, 0x09, 0x66, 0x82,
  33955. 0x53, 0x43, 0xFD, 0xAC, 0xDE, 0xD5, 0x85, 0xB3,
  33956. 0x79, 0x74, 0x55, 0xE8, 0xF6, 0xE5, 0xFB, 0xF0,
  33957. 0x63, 0x0C, 0x36, 0x63, 0x65, 0x10, 0x43, 0xC9,
  33958. 0x60, 0x99, 0xD6, 0x0C, 0xB9, 0x66, 0x1C, 0xA9,
  33959. 0x97, 0x4D, 0xDB, 0xA8, 0x13, 0x9E, 0xAE, 0xCA,
  33960. 0x7A, 0x5F, 0xE3, 0x24, 0xA0, 0xEE, 0x8A, 0x9D,
  33961. 0x7F, 0x03, 0x53, 0x21, 0x6B, 0xAF, 0x3D, 0xF9,
  33962. 0x38, 0xF3, 0x7A, 0x1D, 0xDA, 0xE2, 0xEF, 0xBA,
  33963. 0x86, 0x21, 0x85, 0x1F, 0x36, 0x08, 0x0B, 0xDA,
  33964. 0x37, 0x5A, 0x0A, 0xD7, 0x55, 0x41, 0xD5, 0x84,
  33965. 0x1B, 0x36, 0xA2, 0x50, 0x65, 0xD7, 0xF3, 0xA3,
  33966. 0xEB, 0xE1, 0xDE, 0x0F, 0x85, 0xAA, 0xF6, 0x2F,
  33967. 0xAB, 0xBB, 0xC8, 0xF1, 0x2A, 0xD1, 0x0A, 0x9B,
  33968. 0xE4, 0x7B, 0xBC, 0x4D, 0x42, 0xD8, 0xA3, 0x4C,
  33969. 0x07, 0x6A, 0x60, 0x3E, 0xE2, 0xDA, 0xE7, 0x00,
  33970. 0xDF, 0x27, 0x94, 0xEF, 0x90, 0x99, 0x88, 0x2C,
  33971. 0xCF, 0xAA, 0xE1, 0x71, 0x2D, 0xFD, 0x00, 0x9C,
  33972. 0x55, 0xBF, 0xC4, 0x7A, 0x55, 0xE9, 0xE0, 0xB4,
  33973. 0x7F, 0x3D, 0xE9, 0xB0, 0x01, 0xA7, 0x27, 0x23,
  33974. 0x27, 0x58, 0x31, 0x0E, 0x8E, 0x80, 0xD8, 0xEB,
  33975. 0x64, 0xA0, 0xC3, 0xC9, 0xEA, 0x69, 0x9C, 0x74,
  33976. 0x5E, 0xAF, 0xD5, 0xEF, 0x5C, 0x4E, 0x40, 0x71,
  33977. 0xD6, 0x57, 0x77, 0xE2, 0xAF, 0x0E, 0x1D, 0xB8,
  33978. 0x5A, 0x91, 0x20, 0x4C, 0x33, 0x4D, 0xD8, 0x4F,
  33979. 0x98, 0xE0, 0x86, 0x1D, 0x02, 0xA0, 0xDA, 0x06,
  33980. 0x17, 0xC4, 0x5D, 0x2E, 0x49, 0x31, 0xE6, 0xE4,
  33981. 0xDC, 0x18, 0x23, 0x26, 0xF3, 0x61, 0xF5, 0x8D,
  33982. 0x26, 0x2C, 0x18, 0x4C, 0xDF, 0x71, 0x90, 0x24,
  33983. 0x96, 0xD3, 0xD4, 0x1A, 0x6F, 0x08, 0xAB, 0x29,
  33984. 0x7D, 0xFF, 0x4E, 0x27, 0x6D, 0x39, 0x83, 0x17,
  33985. 0x90, 0xA4, 0x07, 0x8A, 0xDE, 0x79, 0x53, 0xF6,
  33986. 0x99, 0x2E, 0xA6, 0x39, 0x47, 0xC3, 0xBE, 0x12,
  33987. 0xC7, 0xA5, 0x7E, 0xA2, 0x19, 0x57, 0x04, 0x45,
  33988. 0xBE, 0x44, 0x62, 0x92, 0xCA, 0x56, 0xE1, 0xF0,
  33989. 0x45, 0x3B, 0xA4, 0xF8, 0xF5, 0xCD, 0xC7, 0xD2,
  33990. 0xB2, 0x46, 0x57, 0x51, 0x0B, 0x06, 0xDA, 0x54,
  33991. 0x03, 0x9E, 0x52, 0xA2, 0x78, 0x69, 0x25, 0x2E,
  33992. 0x75, 0x83, 0x25, 0x3F, 0xA3, 0x62, 0x27, 0xB9,
  33993. 0xA6, 0x59, 0x7A, 0xB1, 0xB6, 0xE9, 0xC1, 0xDD,
  33994. 0x2F, 0x22, 0x2D, 0x3B, 0xA3, 0x22, 0xD6, 0x11,
  33995. 0x7B, 0x08, 0x27, 0x92, 0x83, 0x7A, 0x5D, 0x0D,
  33996. 0x6B, 0x9D, 0x5B, 0xEB, 0xE9, 0xC0, 0x88, 0xDE,
  33997. 0x44, 0x55, 0xBA, 0x69, 0xC1, 0x7A, 0x4D, 0xE6,
  33998. 0x35, 0x67, 0x6F, 0x99, 0x9B, 0x07, 0xD8, 0x04,
  33999. 0xAA, 0xEA, 0x7D, 0xFF, 0x8E, 0xB8, 0xAA, 0x4C,
  34000. 0x79, 0xE2, 0x88, 0xA8, 0x1D, 0xE8, 0xA6, 0x77,
  34001. 0xCA, 0x06, 0xC0, 0xDF, 0x0E, 0x2B, 0xCB, 0xFF,
  34002. 0x9F, 0x64, 0x67, 0x11, 0xF1, 0xB9, 0x38, 0x83,
  34003. 0x19, 0x05, 0x30, 0x9B, 0x01, 0x11, 0x55, 0x03,
  34004. 0xAD, 0x44, 0x7D, 0x3C, 0x07, 0xEF, 0x88, 0x19,
  34005. 0x92, 0xC0, 0xFE, 0xE1, 0xAB, 0xDB, 0x24, 0x18,
  34006. 0x17, 0xD0, 0x03, 0x5C, 0x91, 0xD4, 0xA6, 0x2A,
  34007. 0xF1, 0xE9, 0x72, 0x62, 0x58, 0x22, 0x7D, 0x55,
  34008. 0x15, 0xE2, 0xA1, 0x70, 0x14, 0x5E, 0x34, 0xB9,
  34009. 0x5A, 0xB7, 0x5D, 0x3F, 0xB8, 0xB5, 0x45, 0x44,
  34010. 0xD2, 0x50, 0xD1, 0xC6, 0x7E, 0xE7, 0x3D, 0xF4,
  34011. 0xD3, 0xEC, 0xFB, 0x97, 0x32, 0x11, 0x72, 0x51,
  34012. 0xB7, 0x4A, 0xC8, 0x38, 0x96, 0xFC, 0x6F, 0x69,
  34013. 0xC2, 0xD5, 0xD3, 0x28, 0xE9, 0x63, 0x14, 0x14,
  34014. 0xFE, 0xB1, 0xA4, 0x02, 0x80, 0x65, 0x73, 0xD3,
  34015. 0x57, 0x07, 0x95, 0x21, 0x40, 0x00, 0x77, 0xA7,
  34016. 0x6D, 0x44, 0x2B, 0x0D, 0x77, 0x07, 0x92, 0x64,
  34017. 0xD4, 0x3A, 0xE2, 0x7F, 0xF2, 0x1C, 0x14, 0x08,
  34018. 0x60, 0x74, 0x8F, 0xFC, 0x0B, 0xE8, 0xEC, 0xA9,
  34019. 0xB7, 0x97, 0xA7, 0x85, 0x8A, 0xEF, 0xD7, 0x7E,
  34020. 0xD5, 0x15, 0xF7, 0x45, 0x8D, 0x9C, 0xBF, 0x23,
  34021. 0xEB, 0x8C, 0x4D, 0xD2, 0x28, 0x7E, 0x0A, 0x61,
  34022. 0x2E, 0xBA, 0xBE, 0x89, 0x1D, 0x64, 0x45, 0x22,
  34023. 0x70, 0x9D, 0x48, 0xEB, 0x2F, 0x96, 0xF1, 0xA7,
  34024. 0xDE, 0xD3, 0x28, 0x4C, 0xC9, 0xFB, 0xF2, 0x9C,
  34025. 0x5B, 0xFC, 0xBE, 0xBE, 0xF4, 0x38, 0xC9, 0x43,
  34026. 0xC3, 0x66, 0x53, 0xA9, 0x06, 0xE5, 0x71, 0x16,
  34027. 0xA4, 0xBB, 0x3B, 0x50, 0x53, 0xCF, 0xF4, 0x1F,
  34028. 0xD6, 0x00, 0x07, 0x46, 0xFB, 0x97, 0x0B, 0xF9,
  34029. 0x3D, 0xF4, 0xC6, 0x60, 0xD0, 0x37, 0x70, 0xC0,
  34030. 0x2D, 0xD1, 0x9F, 0xA5, 0x78, 0xF3, 0x1F, 0x03,
  34031. 0x81, 0xB1, 0x93, 0xBA, 0xE5, 0x82, 0xE6, 0xD1,
  34032. 0x66, 0x93, 0x83, 0x5B, 0xB9, 0xAD, 0xD9, 0x01,
  34033. 0xA5, 0xB6, 0x5C, 0x69, 0x82, 0xD7, 0x2F, 0x35,
  34034. 0x35, 0x98, 0xEE, 0xE9, 0xA0, 0x74, 0xC1, 0x91,
  34035. 0x44, 0x0A, 0x04, 0xCD, 0x97, 0xBE, 0x6B, 0x60,
  34036. 0x90, 0x9A, 0x48, 0x7B, 0x83, 0xA2, 0x28, 0x97,
  34037. 0xB5, 0xBA, 0xB1, 0x4D, 0x35, 0x8B, 0x34, 0x0A,
  34038. 0xA1, 0xCB, 0xA5, 0xC2, 0xA4, 0x6A, 0x36, 0xB3,
  34039. 0x12, 0x46, 0x59, 0xDB, 0x63, 0xE5, 0xF9, 0xF1,
  34040. 0x7F, 0xAD, 0x42, 0xF4, 0x24, 0xF0, 0x02, 0x3D,
  34041. 0x1E, 0x6C, 0xD5, 0xB3, 0x06, 0x8F, 0x1F, 0x59,
  34042. 0x79, 0xCC, 0xF9, 0x5B, 0x4F, 0x8B, 0xD6, 0x03,
  34043. 0xC7, 0x53, 0xE6, 0xCE, 0xBB, 0xD8, 0x52, 0x89,
  34044. 0x70, 0x5D, 0x98, 0x86, 0xA5, 0x9E, 0x44, 0xA9,
  34045. 0xC8, 0x17, 0xA2, 0x6F, 0x43, 0x2D, 0x8D, 0xA7,
  34046. 0xDE, 0x3E, 0xFA, 0xE7, 0x98, 0x7B, 0xB5, 0xBE,
  34047. 0x7B, 0x10, 0xB8, 0xB8, 0xA5, 0x3D, 0x3E, 0xCD,
  34048. 0x94, 0x19, 0x5E, 0x06, 0x51, 0xB8, 0x58, 0x1E,
  34049. 0x0E, 0xCF, 0xFE, 0xE5, 0xED, 0x84, 0xB5, 0xF5,
  34050. 0x0F, 0x34, 0x32, 0xAC, 0x0A, 0x7F, 0x03, 0xF0,
  34051. 0xF8, 0xFC, 0x69, 0xA0, 0x26, 0x0D, 0x2E, 0xFA,
  34052. 0x62, 0x49, 0x5C, 0xC4, 0xE5, 0xF6, 0x8B, 0xC5,
  34053. 0x26, 0x21, 0x23, 0x3B, 0xBD, 0x9A, 0x23, 0x95,
  34054. 0x69, 0xA7, 0x48, 0x94, 0x30, 0x1E, 0xC3, 0x82,
  34055. 0xB6, 0x75, 0x30, 0xA6, 0xF3, 0x1E, 0xBB, 0xBC,
  34056. 0xF7, 0x21, 0x27, 0x12, 0x2C, 0x51, 0x50, 0x55,
  34057. 0x87, 0x0D, 0xF1, 0xCC, 0x6C, 0xFF, 0xEA, 0x7E,
  34058. 0x2C, 0xDA, 0x8B, 0x9B, 0x20, 0xF4, 0x75, 0xFB,
  34059. 0xC2, 0x3F, 0xBE, 0x09, 0xA6, 0xC9, 0x26, 0xE7,
  34060. 0xB5, 0xC7, 0xE6, 0xB9, 0x35, 0x8C, 0xAF, 0xFA,
  34061. 0xC0, 0x8D, 0x43, 0x33, 0x25, 0xBA, 0xAA, 0xDC,
  34062. 0xCF, 0xBC, 0xE4, 0xC4, 0xC6, 0x26, 0x4A, 0x0D,
  34063. 0x9D, 0xCC, 0x2A, 0xE0, 0x5B, 0x1E, 0xC9, 0x78,
  34064. 0xF8, 0xA2, 0xB5, 0x46, 0xE5, 0x49, 0xB8, 0x4C,
  34065. 0xC2, 0x22, 0x40, 0xCE, 0x97, 0x9A, 0x95, 0x40,
  34066. 0xF7, 0xD6, 0x52, 0x54, 0x3B, 0xBB, 0x42, 0xC5,
  34067. 0x6F, 0x00, 0x7F, 0x83, 0xDD, 0x88, 0x71, 0xF7,
  34068. 0xD4, 0x1B, 0x3D, 0x81, 0xC4, 0xB1, 0x49, 0x9B,
  34069. 0xF3, 0x68, 0x15, 0xC5, 0x15, 0x97, 0x0F, 0xC5,
  34070. 0x43, 0xDD, 0x07, 0xBE, 0x98, 0x43, 0x2C, 0xB3,
  34071. 0xEF, 0x08, 0xCA, 0xDC, 0x9C, 0x27, 0x58, 0xFE,
  34072. 0x49, 0xE9, 0x77, 0xD9, 0x1C, 0x62, 0xA4, 0xA2,
  34073. 0xF9, 0x78, 0xCC, 0xB3, 0x21, 0x06, 0x10, 0xDE,
  34074. 0x5A, 0x52, 0xA3, 0x67, 0xBD, 0x5E, 0xBC, 0x9B,
  34075. 0x4E, 0x40, 0x87, 0x93, 0xCF, 0x0E, 0x27, 0x0E,
  34076. 0xE3, 0x11, 0x4B, 0xB3, 0xE0, 0xCE, 0x24, 0xB6,
  34077. 0x0A, 0x53, 0x03, 0xF8, 0x01, 0x6A, 0x7E, 0xFE,
  34078. 0xC8, 0x66, 0x9F, 0x29, 0xF3, 0x45, 0x94, 0xD6,
  34079. 0x0E, 0x30, 0xB5, 0x61, 0xA9, 0xEC, 0x8F, 0x71,
  34080. 0xF7, 0x36, 0xD6, 0x43, 0x4B, 0x0C, 0xCD, 0x45,
  34081. 0xBB, 0xA4, 0xBD, 0xE9, 0xA9, 0xC3, 0xC1, 0x95,
  34082. 0x1E, 0xF9, 0x42, 0x07, 0x18, 0xEA, 0xF5, 0x0B,
  34083. 0x27, 0xB6, 0xDE, 0xEF, 0x67, 0x33, 0x83, 0x0D,
  34084. 0xD9, 0x5E, 0x3A, 0x93, 0xD2, 0xD0, 0xDB, 0xB9,
  34085. 0x98, 0xF0, 0x25, 0x21, 0xF3, 0xDF, 0x0B, 0x1E
  34086. };
  34087. #endif /* !WOLFSSL_NO_ML_DSA_44 */
  34088. #ifndef WOLFSSL_NO_ML_DSA_65
  34089. static const byte seed_65_draft[] = {
  34090. 0x41, 0xAF, 0x98, 0x7B, 0x02, 0x6E, 0x47, 0x5F,
  34091. 0x37, 0x91, 0x7F, 0x2A, 0x6A, 0x9A, 0x87, 0xE7,
  34092. 0x51, 0xAD, 0xF9, 0x5B, 0x92, 0x7F, 0x2D, 0xCE,
  34093. 0xF0, 0xD4, 0xF3, 0xDA, 0x8F, 0x8C, 0x86, 0x6B
  34094. };
  34095. static const byte pk_65_draft[] = {
  34096. 0xDC, 0x38, 0xE5, 0x5F, 0xDF, 0x2E, 0x9D, 0xD4,
  34097. 0x34, 0x5C, 0xAE, 0x1A, 0x7D, 0xF4, 0x2E, 0x2E,
  34098. 0xBC, 0x58, 0x57, 0x80, 0x55, 0x02, 0xE4, 0x3F,
  34099. 0xA5, 0x19, 0x41, 0xE4, 0x44, 0x58, 0x66, 0x41,
  34100. 0x39, 0x5D, 0xF9, 0x20, 0x6C, 0x36, 0x0D, 0x4F,
  34101. 0x83, 0x43, 0xBE, 0x86, 0xEF, 0x6C, 0x43, 0xD0,
  34102. 0x3E, 0xD0, 0x63, 0x0A, 0x5B, 0x92, 0x8D, 0x31,
  34103. 0x19, 0x1D, 0xA9, 0x51, 0x61, 0x48, 0xE6, 0x26,
  34104. 0x50, 0x07, 0x54, 0x9B, 0xB0, 0xB7, 0x62, 0x54,
  34105. 0xDB, 0x80, 0x4E, 0x48, 0x7F, 0x48, 0xC5, 0x11,
  34106. 0x91, 0xFC, 0xA9, 0x26, 0x25, 0x08, 0xA5, 0x99,
  34107. 0xA0, 0x3C, 0xB9, 0x0C, 0xCF, 0x6C, 0xCD, 0x83,
  34108. 0x9A, 0x38, 0x6D, 0x22, 0xDE, 0x0A, 0xC3, 0x8F,
  34109. 0xF7, 0xD0, 0x57, 0x40, 0x53, 0xE9, 0xE9, 0x4E,
  34110. 0x73, 0xFA, 0x58, 0x40, 0x9F, 0x6D, 0x8A, 0xD3,
  34111. 0x6F, 0x86, 0x84, 0x4D, 0x18, 0xD7, 0x4C, 0x76,
  34112. 0x39, 0x57, 0x9E, 0xC0, 0xC7, 0xE4, 0xEE, 0x54,
  34113. 0xF4, 0xAD, 0x10, 0xC5, 0x69, 0x59, 0xE0, 0xBC,
  34114. 0x9B, 0xF4, 0x20, 0x8F, 0xBA, 0x0A, 0x94, 0x10,
  34115. 0x55, 0x07, 0x7E, 0xD1, 0xF9, 0x20, 0xCC, 0x2F,
  34116. 0xA9, 0xAE, 0x9D, 0xF5, 0xE4, 0x29, 0x40, 0x7E,
  34117. 0x44, 0xA4, 0xDF, 0xB2, 0xE9, 0x25, 0xE0, 0xBA,
  34118. 0x8D, 0x6C, 0x33, 0x88, 0x9C, 0xEE, 0x27, 0xDB,
  34119. 0xC7, 0x0A, 0x6E, 0x5A, 0x08, 0x92, 0x9B, 0x53,
  34120. 0xF8, 0xFD, 0xF9, 0x5B, 0xEB, 0x03, 0x8E, 0x45,
  34121. 0xCB, 0x91, 0x19, 0x4E, 0x6B, 0x1E, 0xA0, 0xA4,
  34122. 0xF0, 0x43, 0xC9, 0x8F, 0xDF, 0x93, 0x5E, 0x86,
  34123. 0xB0, 0x09, 0xD3, 0x47, 0x38, 0x7C, 0x8E, 0x78,
  34124. 0x85, 0x71, 0x3D, 0x07, 0x2E, 0x2E, 0x12, 0x6F,
  34125. 0x06, 0x97, 0x0E, 0x54, 0xAD, 0x71, 0x09, 0xEF,
  34126. 0xA5, 0x55, 0x0A, 0x39, 0x86, 0xE6, 0x17, 0x17,
  34127. 0x70, 0x9A, 0xA7, 0xA7, 0x1B, 0xCE, 0x78, 0x06,
  34128. 0x2C, 0x61, 0x1A, 0xB9, 0x48, 0x22, 0x41, 0x45,
  34129. 0x15, 0xEB, 0x10, 0x3C, 0x6E, 0x24, 0x37, 0xA4,
  34130. 0xB5, 0xE8, 0x82, 0x4D, 0x6D, 0xCC, 0x44, 0xC6,
  34131. 0xB0, 0x5D, 0xBE, 0x46, 0xDA, 0x5F, 0x00, 0x36,
  34132. 0x5B, 0xBD, 0x87, 0x65, 0x3A, 0x96, 0x21, 0x58,
  34133. 0x45, 0x65, 0xDB, 0xD8, 0x77, 0x76, 0x7B, 0x25,
  34134. 0xC3, 0x78, 0x6E, 0xD9, 0x14, 0xA7, 0x19, 0x69,
  34135. 0x4F, 0xBB, 0x1B, 0xDB, 0x37, 0xCE, 0xAF, 0x8C,
  34136. 0x88, 0x2E, 0x9E, 0x30, 0xF6, 0xAE, 0x43, 0xCC,
  34137. 0x59, 0x0F, 0x67, 0x8A, 0xCB, 0x4F, 0x08, 0x20,
  34138. 0x6D, 0x99, 0xD7, 0xA9, 0xDE, 0xE5, 0xE5, 0xB3,
  34139. 0xFF, 0xAA, 0x45, 0x3C, 0xF1, 0xE3, 0x02, 0x7D,
  34140. 0x2F, 0xEE, 0x69, 0x04, 0x81, 0x73, 0x01, 0x37,
  34141. 0x51, 0x68, 0xC8, 0x0B, 0x51, 0xFD, 0x05, 0xB4,
  34142. 0x05, 0xBB, 0xA1, 0xDB, 0x1D, 0xF6, 0x5F, 0x70,
  34143. 0xD3, 0x0A, 0x37, 0x4B, 0x9C, 0xC4, 0x45, 0x30,
  34144. 0x11, 0x36, 0xE2, 0x48, 0x9F, 0xC4, 0x2E, 0x4E,
  34145. 0x0C, 0x0C, 0xA1, 0x04, 0x41, 0x75, 0x95, 0xAA,
  34146. 0xED, 0xAC, 0xD4, 0xB2, 0xE7, 0x85, 0x7E, 0xE1,
  34147. 0xA6, 0xFE, 0x2A, 0x09, 0x19, 0x09, 0x3D, 0x7C,
  34148. 0x20, 0x1E, 0x98, 0x3D, 0x6E, 0x02, 0xC1, 0xCA,
  34149. 0xBB, 0x24, 0x82, 0x9F, 0x45, 0x1D, 0x26, 0x99,
  34150. 0xAE, 0x02, 0x82, 0xF9, 0x86, 0x3B, 0x67, 0x8C,
  34151. 0xBD, 0xFE, 0xF1, 0xD0, 0xB6, 0xB8, 0xAB, 0x00,
  34152. 0x0F, 0xEC, 0x30, 0xDC, 0x27, 0x58, 0xE2, 0x29,
  34153. 0x18, 0x05, 0x5A, 0x66, 0xA5, 0x88, 0x39, 0x8E,
  34154. 0x49, 0x5B, 0xB9, 0x52, 0x43, 0x84, 0xDC, 0xA9,
  34155. 0x50, 0x2B, 0x83, 0x3C, 0x84, 0x81, 0x37, 0x52,
  34156. 0x30, 0x79, 0xBD, 0x04, 0xB8, 0xDD, 0x47, 0xC1,
  34157. 0x02, 0x2E, 0xEC, 0x24, 0xD0, 0x56, 0x23, 0xE1,
  34158. 0x92, 0xD0, 0x65, 0x7F, 0xC7, 0xC2, 0xF7, 0x60,
  34159. 0x73, 0xB8, 0xAF, 0x0A, 0xF4, 0xEF, 0xFC, 0x1B,
  34160. 0xC2, 0xB9, 0x76, 0x87, 0x8A, 0xA6, 0xC2, 0x3F,
  34161. 0xD3, 0x9F, 0x1F, 0x2D, 0x94, 0xBC, 0x89, 0x4E,
  34162. 0x31, 0x8D, 0x28, 0xD0, 0x90, 0xB5, 0x5B, 0x60,
  34163. 0x30, 0xC6, 0x0B, 0x37, 0x63, 0x5D, 0xDC, 0xC6,
  34164. 0xE0, 0x1A, 0xBA, 0x6B, 0x23, 0xCD, 0x2E, 0x09,
  34165. 0x2D, 0x6A, 0x7E, 0x0C, 0xD9, 0x4F, 0xB1, 0xE2,
  34166. 0x89, 0x67, 0xE7, 0xB1, 0x54, 0x08, 0xB2, 0xFA,
  34167. 0x83, 0x43, 0x7C, 0x77, 0x06, 0xED, 0xE2, 0x29,
  34168. 0x53, 0xB7, 0x09, 0xC4, 0x1B, 0x81, 0x55, 0x12,
  34169. 0x41, 0x8E, 0x8B, 0x03, 0x36, 0xEE, 0x45, 0x70,
  34170. 0x57, 0xA8, 0x73, 0xEF, 0x70, 0x7B, 0x1F, 0x63,
  34171. 0xB0, 0xE8, 0x00, 0xBD, 0x1E, 0xE6, 0xA9, 0x93,
  34172. 0x9D, 0x03, 0x19, 0x22, 0xDF, 0xE1, 0x01, 0xF2,
  34173. 0xA9, 0x6B, 0x90, 0x5C, 0xD2, 0xC1, 0xAC, 0x9F,
  34174. 0xB2, 0x21, 0x1C, 0x2D, 0xC6, 0x80, 0x9A, 0xB5,
  34175. 0x1E, 0x46, 0x95, 0x6C, 0xCE, 0x47, 0x3E, 0x67,
  34176. 0xCD, 0xD6, 0xC9, 0xB9, 0x81, 0x74, 0x7F, 0x17,
  34177. 0xA3, 0xF7, 0x48, 0x99, 0xF3, 0x36, 0x84, 0xF3,
  34178. 0x16, 0x41, 0x55, 0x5F, 0xA7, 0xBF, 0x4B, 0x69,
  34179. 0x8D, 0xA3, 0x3D, 0x1E, 0xEA, 0xF5, 0x1E, 0xC6,
  34180. 0xB8, 0x1C, 0xD6, 0x89, 0x45, 0x68, 0xFA, 0xE7,
  34181. 0xCA, 0x86, 0xE4, 0xB1, 0xC9, 0x9C, 0xB2, 0xAB,
  34182. 0x89, 0x03, 0xE7, 0x19, 0x7B, 0xA9, 0xF2, 0x6B,
  34183. 0x4A, 0x43, 0x1D, 0x90, 0xAF, 0xA4, 0xE3, 0xBC,
  34184. 0xEF, 0xD4, 0x37, 0xC5, 0x55, 0x5C, 0x9E, 0x14,
  34185. 0xC6, 0x18, 0xDD, 0x45, 0x3F, 0x80, 0x49, 0x1C,
  34186. 0x93, 0xFF, 0xBD, 0xDD, 0x75, 0x54, 0x0B, 0xD1,
  34187. 0xA9, 0xF6, 0xBC, 0x89, 0x98, 0x7D, 0x6F, 0x03,
  34188. 0x7B, 0x06, 0xD5, 0x40, 0x7D, 0x85, 0x48, 0x2E,
  34189. 0x11, 0x3E, 0xF0, 0x47, 0x77, 0xD0, 0xBA, 0x03,
  34190. 0x33, 0x58, 0xC4, 0x8F, 0x76, 0xF8, 0x72, 0x47,
  34191. 0x04, 0x21, 0x5E, 0x85, 0x5A, 0x0F, 0x35, 0x77,
  34192. 0xFB, 0x96, 0x29, 0x81, 0x2D, 0x55, 0x6E, 0x53,
  34193. 0xC6, 0x13, 0x1E, 0xFA, 0x4D, 0xCE, 0xA9, 0x36,
  34194. 0x1D, 0x8F, 0xAB, 0xAC, 0x13, 0x19, 0x94, 0xFC,
  34195. 0x4B, 0xCD, 0x36, 0x4C, 0x6E, 0x21, 0xAE, 0xF1,
  34196. 0x13, 0xA4, 0xF7, 0x64, 0x8E, 0xE1, 0xAF, 0x50,
  34197. 0x6A, 0x63, 0x0E, 0xCA, 0x2F, 0xE9, 0x0C, 0x8A,
  34198. 0xE7, 0xF2, 0xE3, 0x68, 0x03, 0xE0, 0x40, 0x1C,
  34199. 0x64, 0xAB, 0xC3, 0xEC, 0xC0, 0x92, 0xE9, 0x57,
  34200. 0x3E, 0x66, 0x72, 0x36, 0x39, 0x22, 0x4E, 0xCD,
  34201. 0x13, 0x08, 0xBA, 0xF8, 0x2B, 0xA1, 0xF2, 0x69,
  34202. 0x44, 0x7E, 0x90, 0x5C, 0xC8, 0xEC, 0xB6, 0xBE,
  34203. 0x8C, 0x30, 0xE0, 0x69, 0xB7, 0x97, 0xA1, 0x1C,
  34204. 0x18, 0xE5, 0x54, 0x62, 0xC3, 0x29, 0x99, 0x21,
  34205. 0x16, 0xD9, 0x78, 0x1C, 0x4C, 0x9C, 0x88, 0x4C,
  34206. 0xA5, 0xE1, 0x11, 0x66, 0x5B, 0x6E, 0x71, 0xE7,
  34207. 0xE2, 0xE7, 0xE4, 0x02, 0xDD, 0x1A, 0x8D, 0x0C,
  34208. 0xF5, 0x32, 0xFD, 0x41, 0x28, 0x35, 0x75, 0xD0,
  34209. 0x0C, 0x5F, 0x06, 0x6A, 0x5A, 0x61, 0x49, 0x59,
  34210. 0xC1, 0x0C, 0xD4, 0x9E, 0xD6, 0x29, 0xE2, 0x37,
  34211. 0xDF, 0x2B, 0x3D, 0xE8, 0x98, 0xB9, 0xDF, 0x8E,
  34212. 0xA0, 0xC4, 0xE2, 0xFC, 0x45, 0x70, 0xE8, 0x1B,
  34213. 0xF4, 0xFA, 0xC5, 0xE6, 0xA7, 0xCF, 0x4F, 0xA2,
  34214. 0xDA, 0x3D, 0x90, 0x49, 0x24, 0x8F, 0x61, 0x54,
  34215. 0xD5, 0x50, 0x8E, 0xE8, 0x0C, 0x14, 0xAD, 0x6F,
  34216. 0x65, 0x88, 0x3A, 0xF6, 0x92, 0xDB, 0x35, 0x5D,
  34217. 0xFF, 0x21, 0x20, 0xAC, 0x01, 0x16, 0x0B, 0xEC,
  34218. 0x84, 0x15, 0x3B, 0xA9, 0x93, 0x92, 0x75, 0xB3,
  34219. 0x73, 0xF1, 0x23, 0x69, 0x94, 0x10, 0xF5, 0xFE,
  34220. 0x20, 0xA8, 0xAF, 0x05, 0x87, 0x49, 0x4E, 0x9C,
  34221. 0xEB, 0x21, 0x0A, 0xCF, 0x0B, 0xA1, 0x65, 0x38,
  34222. 0xA6, 0x18, 0x4D, 0xF7, 0xD8, 0xC1, 0x2C, 0x14,
  34223. 0x4C, 0xD9, 0x40, 0xC2, 0xF7, 0xBF, 0xE3, 0x07,
  34224. 0x79, 0x55, 0xAE, 0xB9, 0xB6, 0x50, 0x06, 0x92,
  34225. 0x94, 0x8C, 0x6A, 0x0E, 0x22, 0x14, 0xE2, 0xCC,
  34226. 0x65, 0xBA, 0x0C, 0x4D, 0xB6, 0x5C, 0x4A, 0xE9,
  34227. 0x0A, 0x08, 0x0C, 0xF9, 0x26, 0xA2, 0x51, 0x85,
  34228. 0x36, 0xE2, 0xC1, 0xF1, 0x0A, 0x66, 0x51, 0x66,
  34229. 0x7A, 0x98, 0x9B, 0x2C, 0x30, 0x1A, 0x0D, 0x49,
  34230. 0x3C, 0x1E, 0xEC, 0x63, 0x53, 0x5E, 0xD9, 0xDD,
  34231. 0x84, 0x69, 0xCD, 0x7E, 0x79, 0x58, 0x3D, 0x6E,
  34232. 0xD9, 0x98, 0x58, 0xD8, 0x0A, 0x48, 0xB5, 0x13,
  34233. 0x3F, 0x72, 0x4C, 0x11, 0x90, 0x15, 0x12, 0x74,
  34234. 0xFF, 0x5C, 0x0D, 0xC6, 0x20, 0x8C, 0xC1, 0x99,
  34235. 0xCA, 0x8E, 0xFC, 0xA2, 0xE8, 0xB8, 0xEE, 0xAA,
  34236. 0x27, 0xC2, 0x97, 0x8D, 0xFA, 0xBE, 0xE0, 0x43,
  34237. 0x99, 0xB6, 0x90, 0x60, 0x00, 0x7C, 0x33, 0xD4,
  34238. 0x87, 0x71, 0x7B, 0x56, 0x6C, 0xAA, 0xE0, 0xAC,
  34239. 0x9D, 0x7E, 0x7E, 0xA3, 0xCF, 0xBB, 0xB3, 0xA0,
  34240. 0x5F, 0xD4, 0xC4, 0x3A, 0xA7, 0xB9, 0x0C, 0xCE,
  34241. 0xF3, 0x05, 0x09, 0x91, 0xA7, 0xE9, 0x11, 0x55,
  34242. 0x32, 0x45, 0xA6, 0x08, 0x0E, 0x10, 0x37, 0x91,
  34243. 0xF3, 0xBF, 0xED, 0x64, 0x26, 0xEB, 0x39, 0xC2,
  34244. 0x57, 0xAE, 0x64, 0x79, 0x33, 0x7C, 0x51, 0xB2,
  34245. 0xC8, 0x85, 0xE0, 0xF9, 0x6D, 0x10, 0x52, 0x9F,
  34246. 0x72, 0xF4, 0xD1, 0x5B, 0x54, 0x5B, 0x93, 0x28,
  34247. 0x36, 0xA8, 0xCD, 0xB3, 0x30, 0x5B, 0x7A, 0xB0,
  34248. 0xB6, 0xF0, 0xD8, 0xA0, 0xBA, 0x24, 0x59, 0x5F,
  34249. 0x43, 0x02, 0x01, 0x57, 0x91, 0x7B, 0x94, 0x07,
  34250. 0x63, 0x23, 0x12, 0x94, 0xFB, 0x9F, 0xF2, 0xC1,
  34251. 0xD6, 0x80, 0x8F, 0x4E, 0xA7, 0x9E, 0x11, 0xD8,
  34252. 0xB3, 0x08, 0xB6, 0x3B, 0x3B, 0xF2, 0xEE, 0x14,
  34253. 0xA5, 0xDB, 0xB0, 0xBB, 0x17, 0xA5, 0x96, 0x3C,
  34254. 0x2F, 0xB9, 0xE7, 0x4A, 0xD7, 0x52, 0x34, 0x98,
  34255. 0xCB, 0x0C, 0xEB, 0x42, 0x5B, 0x2D, 0x2D, 0x2B,
  34256. 0x0D, 0x94, 0x66, 0xD3, 0xAD, 0x08, 0x0A, 0x28,
  34257. 0xF6, 0x0E, 0xDA, 0xD4, 0x54, 0xFD, 0xC6, 0x48,
  34258. 0x08, 0xA1, 0x8D, 0xB0, 0x30, 0xFD, 0x18, 0xB1,
  34259. 0x50, 0xB1, 0xFD, 0xE0, 0x6E, 0x33, 0x25, 0x0D,
  34260. 0x90, 0xB1, 0xC1, 0xE7, 0x88, 0x74, 0x87, 0x05,
  34261. 0xE7, 0xBE, 0xBD, 0xAA, 0x8C, 0x6D, 0xC2, 0x3D,
  34262. 0x6F, 0x95, 0x84, 0xFA, 0x03, 0x74, 0x85, 0xE1,
  34263. 0xED, 0xE5, 0xF4, 0xE8, 0x26, 0x4A, 0x0B, 0x20,
  34264. 0x87, 0xB6, 0xE1, 0x10, 0x75, 0x6D, 0x9F, 0x95,
  34265. 0x39, 0x4C, 0x0F, 0x50, 0x1B, 0xA8, 0x69, 0x82,
  34266. 0xBB, 0xE2, 0xD6, 0x11, 0xD7, 0xBE, 0xFB, 0x4F,
  34267. 0x60, 0xD3, 0x16, 0xC6, 0x04, 0x3A, 0x5A, 0xF5,
  34268. 0x78, 0x9B, 0x0B, 0x21, 0xA1, 0x00, 0x96, 0xCD,
  34269. 0x63, 0x78, 0x1D, 0x2D, 0x4F, 0x6E, 0x50, 0xEE,
  34270. 0x62, 0x2D, 0x88, 0x62, 0x01, 0xF6, 0xB4, 0x17,
  34271. 0x4F, 0x8C, 0xAD, 0xCB, 0x4B, 0xF9, 0xF6, 0x9D,
  34272. 0xC7, 0xD8, 0xCC, 0xBF, 0x96, 0x1B, 0x1B, 0x79,
  34273. 0xF3, 0x25, 0x85, 0x23, 0x10, 0x63, 0x30, 0x8D,
  34274. 0xA8, 0x3A, 0x4B, 0x92, 0x1B, 0x88, 0x53, 0x24,
  34275. 0x2D, 0x29, 0xA5, 0x2E, 0x7A, 0xD5, 0x58, 0xEB,
  34276. 0x1B, 0x1C, 0xE6, 0xB8, 0x94, 0x0C, 0x58, 0x96,
  34277. 0x5B, 0xA0, 0x2C, 0xBF, 0xE2, 0x99, 0xA0, 0x1F,
  34278. 0x0C, 0xCC, 0xBD, 0x83, 0x72, 0x56, 0xBB, 0x13,
  34279. 0x61, 0x5A, 0xC2, 0x04, 0x27, 0x29, 0x1F, 0xD4,
  34280. 0xE4, 0x3D, 0x8A, 0x87, 0xE3, 0x81, 0x91, 0x07,
  34281. 0xD3, 0x9B, 0xBC, 0xA9, 0xB3, 0xBA, 0xF5, 0x8B,
  34282. 0x6A, 0xAD, 0xDE, 0xB0, 0x54, 0x3E, 0xFE, 0xCC,
  34283. 0xD3, 0xCB, 0x2C, 0x69, 0xF0, 0x58, 0xD7, 0xEF,
  34284. 0xA9, 0xC0, 0x15, 0x9B, 0x5A, 0xDF, 0x71, 0x25,
  34285. 0x38, 0x44, 0xEC, 0xA9, 0x18, 0x47, 0x41, 0xCE,
  34286. 0x3D, 0x53, 0x10, 0x12, 0xC3, 0x1B, 0x59, 0x9A,
  34287. 0x93, 0xA1, 0xEA, 0xBE, 0x3E, 0xBA, 0x74, 0xF6,
  34288. 0x2D, 0x40, 0x9D, 0xCB, 0x9E, 0xA1, 0xA5, 0x85,
  34289. 0xFF, 0xDC, 0xC5, 0x60, 0x6F, 0x61, 0xE8, 0x17,
  34290. 0x6C, 0x36, 0x9F, 0x7A, 0x48, 0x47, 0xDD, 0xF1,
  34291. 0xF4, 0x43, 0x21, 0xCB, 0xB3, 0x55, 0x86, 0xD0,
  34292. 0xE9, 0x46, 0x7D, 0xB5, 0x3D, 0x90, 0x34, 0x1E,
  34293. 0xBB, 0x40, 0xD3, 0x2A, 0xEB, 0xE6, 0x4C, 0x46,
  34294. 0x42, 0xA2, 0x8A, 0xBF, 0x90, 0xE7, 0x4B, 0x6D,
  34295. 0x5C, 0x94, 0x97, 0xD2, 0xF0, 0x97, 0x74, 0x4C,
  34296. 0x76, 0x03, 0xAC, 0x3D, 0xDE, 0x15, 0x96, 0x0C,
  34297. 0xEF, 0x18, 0x9D, 0xBD, 0x1A, 0x20, 0x35, 0x7E,
  34298. 0x2A, 0x70, 0x9D, 0xEA, 0x2E, 0x11, 0xDF, 0xF3,
  34299. 0x2F, 0xFE, 0x23, 0xA9, 0xB6, 0xCF, 0xB7, 0xB9,
  34300. 0x3F, 0x4F, 0x30, 0x6B, 0x3B, 0x0D, 0x3B, 0xED,
  34301. 0xCD, 0x77, 0xD4, 0xBF, 0xEE, 0xDD, 0xB6, 0x56,
  34302. 0x24, 0xD4, 0x29, 0x83, 0xDE, 0xDB, 0xC1, 0xFB,
  34303. 0x6A, 0xCE, 0x7F, 0x47, 0xD2, 0xC5, 0xF1, 0x78,
  34304. 0x5C, 0x2C, 0x5A, 0x28, 0x3E, 0x05, 0x50, 0x2E,
  34305. 0xD9, 0xAE, 0x9B, 0x95, 0x64, 0xC7, 0xD2, 0x7B,
  34306. 0xCB, 0xC5, 0x91, 0x80, 0xEB, 0x79, 0xC7, 0xCC,
  34307. 0xA8, 0x06, 0xC8, 0xF9, 0xDF, 0x2A, 0x49, 0x4A,
  34308. 0xF8, 0xFE, 0xBA, 0xA5, 0x85, 0x67, 0x1B, 0xDA,
  34309. 0x51, 0x3B, 0xC2, 0x04, 0xA6, 0xA3, 0xFF, 0x99,
  34310. 0x21, 0xE8, 0x17, 0x91, 0x33, 0x9B, 0x83, 0x75,
  34311. 0x20, 0x5E, 0x95, 0xBE, 0x49, 0xDF, 0x53, 0xFC,
  34312. 0x05, 0xA2, 0x3C, 0xAA, 0x5A, 0x22, 0x15, 0xA5,
  34313. 0x56, 0xE0, 0x51, 0x30, 0x4E, 0x32, 0x14, 0xF2,
  34314. 0x9F, 0x03, 0x51, 0x8E, 0xDD, 0x8B, 0x39, 0x19,
  34315. 0x1E, 0x39, 0xC5, 0xA7, 0x1C, 0xC6, 0xA4, 0xE1,
  34316. 0x77, 0xCA, 0x8C, 0x9D, 0x27, 0xBC, 0xCC, 0x16,
  34317. 0xD6, 0xFC, 0x59, 0x10, 0x23, 0xFF, 0x64, 0x90,
  34318. 0x9C, 0x23, 0x5A, 0xFF, 0x7E, 0x27, 0x1B, 0xC7,
  34319. 0x7F, 0x21, 0x3B, 0x41, 0xDB, 0xBC, 0x96, 0x60,
  34320. 0x0B, 0x35, 0xA1, 0xF3, 0xF8, 0x51, 0x0A, 0x65,
  34321. 0xCF, 0xDF, 0x7A, 0xB8, 0x04, 0x56, 0x49, 0xD7,
  34322. 0xD3, 0xC5, 0x0B, 0x4A, 0x1F, 0x60, 0xE1, 0x86,
  34323. 0x36, 0x53, 0x8E, 0x6C, 0x3E, 0xAF, 0x5B, 0xC1,
  34324. 0xCA, 0xCB, 0x22, 0x1A, 0x07, 0xDA, 0x54, 0xEC,
  34325. 0xAA, 0x06, 0x72, 0x17, 0xCF, 0x80, 0xC4, 0x89,
  34326. 0x56, 0x24, 0x1B, 0xD4, 0xFF, 0x50, 0x6B, 0x51,
  34327. 0x55, 0x4D, 0x6E, 0x79, 0x7E, 0xEC, 0x61, 0xC6,
  34328. 0xE4, 0x21, 0xC8, 0x0E, 0x10, 0x3F, 0x8C, 0x85,
  34329. 0x3A, 0x27, 0xEA, 0x91, 0x07, 0xCB, 0x37, 0x18,
  34330. 0x14, 0xB5, 0x63, 0x6E, 0x00, 0xBC, 0x0F, 0x36,
  34331. 0xF9, 0x54, 0x75, 0xE7, 0x0B, 0xDC, 0xE7, 0xA0,
  34332. 0x59, 0xF0, 0x64, 0xFB, 0x73, 0x07, 0x0E, 0xFE,
  34333. 0x57, 0x7F, 0x0D, 0x12, 0xBC, 0xB0, 0xBF, 0xA2,
  34334. 0x3A, 0x18, 0x08, 0x7E, 0xD5, 0x6C, 0xF0, 0x6F,
  34335. 0xF8, 0x98, 0xFB, 0xA5, 0x10, 0x7B, 0x10, 0x5F,
  34336. 0x6B, 0xC8, 0x6D, 0xDE, 0x2F, 0x1F, 0xE0, 0xC8,
  34337. 0x19, 0xEE, 0xC2, 0x03, 0x39, 0x49, 0x70, 0x3E,
  34338. 0x36, 0xE3, 0x3C, 0x70, 0xE3, 0xEA, 0xAC, 0x34,
  34339. 0x32, 0xB7, 0x0D, 0xBA, 0x7C, 0xAB, 0xE6, 0x18
  34340. };
  34341. static const byte sk_65_draft[] = {
  34342. 0xDC, 0x38, 0xE5, 0x5F, 0xDF, 0x2E, 0x9D, 0xD4,
  34343. 0x34, 0x5C, 0xAE, 0x1A, 0x7D, 0xF4, 0x2E, 0x2E,
  34344. 0xBC, 0x58, 0x57, 0x80, 0x55, 0x02, 0xE4, 0x3F,
  34345. 0xA5, 0x19, 0x41, 0xE4, 0x44, 0x58, 0x66, 0x41,
  34346. 0x52, 0x8D, 0xA0, 0xC7, 0xD2, 0x80, 0xDD, 0x49,
  34347. 0x0D, 0x5E, 0xB7, 0x65, 0xDB, 0x32, 0x33, 0x15,
  34348. 0x0F, 0x9E, 0xC8, 0xEB, 0xC9, 0x6E, 0xE8, 0xE8,
  34349. 0x5C, 0xBD, 0x18, 0x4F, 0xDC, 0xF8, 0xA8, 0xD9,
  34350. 0xC5, 0x33, 0x84, 0x79, 0x5A, 0x5E, 0xB7, 0x3C,
  34351. 0x6D, 0x82, 0xCA, 0xB9, 0xBA, 0x94, 0xB6, 0x46,
  34352. 0xAE, 0x3A, 0xD9, 0x19, 0x6C, 0xB4, 0xDA, 0xE2,
  34353. 0xF1, 0x4B, 0xB6, 0x43, 0xF0, 0x24, 0x08, 0xE5,
  34354. 0xF7, 0x9A, 0x41, 0xF1, 0x15, 0x9C, 0xA8, 0x08,
  34355. 0x79, 0x9F, 0xB8, 0x26, 0xD4, 0x08, 0x32, 0x47,
  34356. 0xC8, 0xF0, 0xD5, 0x31, 0xA1, 0xC1, 0x19, 0x04,
  34357. 0x02, 0x06, 0x2B, 0x4D, 0x46, 0xAE, 0x43, 0x6A,
  34358. 0x25, 0x82, 0x75, 0x41, 0x70, 0x36, 0x42, 0x48,
  34359. 0x78, 0x06, 0x36, 0x50, 0x23, 0x84, 0x68, 0x10,
  34360. 0x87, 0x08, 0x62, 0x00, 0x08, 0x34, 0x20, 0x73,
  34361. 0x32, 0x13, 0x36, 0x61, 0x87, 0x61, 0x43, 0x50,
  34362. 0x30, 0x02, 0x26, 0x07, 0x65, 0x45, 0x32, 0x00,
  34363. 0x25, 0x75, 0x01, 0x04, 0x88, 0x81, 0x58, 0x64,
  34364. 0x52, 0x40, 0x84, 0x22, 0x88, 0x42, 0x82, 0x56,
  34365. 0x47, 0x50, 0x05, 0x21, 0x88, 0x25, 0x32, 0x25,
  34366. 0x12, 0x85, 0x14, 0x52, 0x87, 0x77, 0x67, 0x18,
  34367. 0x46, 0x54, 0x63, 0x07, 0x88, 0x67, 0x37, 0x26,
  34368. 0x72, 0x62, 0x41, 0x02, 0x00, 0x01, 0x17, 0x84,
  34369. 0x33, 0x64, 0x32, 0x57, 0x06, 0x20, 0x05, 0x44,
  34370. 0x88, 0x57, 0x33, 0x45, 0x70, 0x55, 0x14, 0x43,
  34371. 0x12, 0x54, 0x04, 0x38, 0x37, 0x08, 0x42, 0x57,
  34372. 0x36, 0x05, 0x30, 0x03, 0x86, 0x53, 0x02, 0x53,
  34373. 0x75, 0x22, 0x62, 0x13, 0x38, 0x82, 0x48, 0x30,
  34374. 0x83, 0x83, 0x64, 0x83, 0x13, 0x74, 0x57, 0x32,
  34375. 0x46, 0x70, 0x06, 0x05, 0x82, 0x52, 0x73, 0x55,
  34376. 0x25, 0x77, 0x21, 0x78, 0x57, 0x83, 0x66, 0x20,
  34377. 0x38, 0x53, 0x21, 0x41, 0x77, 0x56, 0x77, 0x46,
  34378. 0x34, 0x42, 0x58, 0x31, 0x08, 0x06, 0x03, 0x62,
  34379. 0x20, 0x35, 0x11, 0x42, 0x35, 0x38, 0x63, 0x86,
  34380. 0x64, 0x13, 0x13, 0x75, 0x40, 0x01, 0x53, 0x74,
  34381. 0x41, 0x31, 0x56, 0x64, 0x38, 0x17, 0x14, 0x16,
  34382. 0x62, 0x33, 0x22, 0x12, 0x64, 0x40, 0x67, 0x11,
  34383. 0x62, 0x42, 0x25, 0x60, 0x38, 0x05, 0x83, 0x13,
  34384. 0x51, 0x00, 0x28, 0x36, 0x62, 0x56, 0x41, 0x43,
  34385. 0x58, 0x37, 0x51, 0x22, 0x70, 0x25, 0x82, 0x82,
  34386. 0x35, 0x24, 0x06, 0x83, 0x48, 0x58, 0x81, 0x78,
  34387. 0x07, 0x86, 0x23, 0x15, 0x75, 0x32, 0x46, 0x75,
  34388. 0x35, 0x40, 0x08, 0x43, 0x10, 0x66, 0x74, 0x05,
  34389. 0x13, 0x72, 0x74, 0x08, 0x83, 0x41, 0x81, 0x08,
  34390. 0x75, 0x87, 0x83, 0x28, 0x56, 0x66, 0x20, 0x01,
  34391. 0x18, 0x83, 0x57, 0x22, 0x14, 0x64, 0x18, 0x05,
  34392. 0x27, 0x75, 0x22, 0x84, 0x12, 0x38, 0x87, 0x52,
  34393. 0x32, 0x25, 0x28, 0x08, 0x14, 0x41, 0x81, 0x14,
  34394. 0x03, 0x24, 0x54, 0x23, 0x04, 0x81, 0x40, 0x36,
  34395. 0x38, 0x38, 0x64, 0x42, 0x46, 0x36, 0x68, 0x11,
  34396. 0x55, 0x00, 0x11, 0x25, 0x76, 0x16, 0x43, 0x07,
  34397. 0x23, 0x03, 0x34, 0x10, 0x46, 0x41, 0x14, 0x02,
  34398. 0x26, 0x10, 0x74, 0x38, 0x38, 0x72, 0x07, 0x87,
  34399. 0x54, 0x11, 0x12, 0x83, 0x75, 0x05, 0x82, 0x17,
  34400. 0x45, 0x20, 0x38, 0x41, 0x37, 0x20, 0x00, 0x08,
  34401. 0x32, 0x18, 0x16, 0x25, 0x58, 0x85, 0x16, 0x88,
  34402. 0x71, 0x82, 0x45, 0x60, 0x33, 0x11, 0x13, 0x42,
  34403. 0x43, 0x37, 0x68, 0x11, 0x16, 0x54, 0x04, 0x08,
  34404. 0x52, 0x78, 0x13, 0x56, 0x83, 0x52, 0x15, 0x24,
  34405. 0x03, 0x61, 0x78, 0x44, 0x13, 0x70, 0x67, 0x36,
  34406. 0x74, 0x86, 0x52, 0x50, 0x15, 0x41, 0x88, 0x74,
  34407. 0x53, 0x00, 0x05, 0x18, 0x65, 0x62, 0x14, 0x84,
  34408. 0x12, 0x32, 0x01, 0x88, 0x40, 0x42, 0x34, 0x05,
  34409. 0x32, 0x80, 0x72, 0x55, 0x20, 0x68, 0x16, 0x43,
  34410. 0x14, 0x15, 0x15, 0x38, 0x43, 0x85, 0x27, 0x60,
  34411. 0x70, 0x18, 0x27, 0x35, 0x53, 0x01, 0x28, 0x73,
  34412. 0x27, 0x84, 0x10, 0x53, 0x67, 0x10, 0x45, 0x40,
  34413. 0x81, 0x52, 0x86, 0x06, 0x11, 0x18, 0x04, 0x31,
  34414. 0x57, 0x25, 0x22, 0x44, 0x47, 0x81, 0x45, 0x44,
  34415. 0x55, 0x04, 0x72, 0x57, 0x06, 0x46, 0x76, 0x23,
  34416. 0x38, 0x85, 0x65, 0x30, 0x08, 0x48, 0x20, 0x13,
  34417. 0x22, 0x77, 0x44, 0x60, 0x43, 0x14, 0x15, 0x27,
  34418. 0x86, 0x22, 0x37, 0x37, 0x27, 0x04, 0x27, 0x50,
  34419. 0x74, 0x31, 0x10, 0x82, 0x00, 0x75, 0x80, 0x44,
  34420. 0x38, 0x10, 0x58, 0x40, 0x86, 0x60, 0x63, 0x13,
  34421. 0x65, 0x18, 0x33, 0x70, 0x57, 0x68, 0x05, 0x10,
  34422. 0x81, 0x03, 0x42, 0x05, 0x25, 0x65, 0x33, 0x57,
  34423. 0x38, 0x05, 0x65, 0x34, 0x46, 0x53, 0x68, 0x11,
  34424. 0x75, 0x10, 0x04, 0x54, 0x18, 0x47, 0x52, 0x24,
  34425. 0x63, 0x23, 0x74, 0x45, 0x11, 0x34, 0x68, 0x32,
  34426. 0x35, 0x38, 0x52, 0x85, 0x28, 0x08, 0x71, 0x78,
  34427. 0x37, 0x38, 0x27, 0x10, 0x80, 0x54, 0x26, 0x33,
  34428. 0x31, 0x82, 0x44, 0x88, 0x33, 0x24, 0x62, 0x86,
  34429. 0x32, 0x82, 0x73, 0x31, 0x28, 0x14, 0x73, 0x87,
  34430. 0x06, 0x35, 0x80, 0x36, 0x67, 0x02, 0x33, 0x75,
  34431. 0x27, 0x36, 0x38, 0x16, 0x35, 0x70, 0x52, 0x16,
  34432. 0x87, 0x58, 0x85, 0x17, 0x22, 0x13, 0x54, 0x85,
  34433. 0x07, 0x53, 0x31, 0x26, 0x78, 0x01, 0x85, 0x18,
  34434. 0x08, 0x68, 0x38, 0x52, 0x11, 0x73, 0x32, 0x25,
  34435. 0x58, 0x82, 0x70, 0x70, 0x36, 0x30, 0x50, 0x38,
  34436. 0x65, 0x12, 0x78, 0x31, 0x77, 0x72, 0x18, 0x41,
  34437. 0x05, 0x42, 0x32, 0x26, 0x26, 0x50, 0x52, 0x86,
  34438. 0x15, 0x76, 0x28, 0x66, 0x88, 0x03, 0x78, 0x28,
  34439. 0x70, 0x33, 0x36, 0x27, 0x16, 0x61, 0x43, 0x56,
  34440. 0x62, 0x81, 0x85, 0x75, 0x47, 0x60, 0x63, 0x38,
  34441. 0x66, 0x81, 0x51, 0x78, 0x03, 0x42, 0x60, 0x38,
  34442. 0x01, 0x24, 0x73, 0x63, 0x81, 0x12, 0x01, 0x27,
  34443. 0x63, 0x13, 0x11, 0x78, 0x36, 0x37, 0x15, 0x03,
  34444. 0x84, 0x58, 0x17, 0x25, 0x67, 0x87, 0x57, 0x83,
  34445. 0x71, 0x85, 0x37, 0x53, 0x86, 0x22, 0x33, 0x28,
  34446. 0x77, 0x30, 0x18, 0x15, 0x01, 0x37, 0x85, 0x40,
  34447. 0x15, 0x38, 0x51, 0x33, 0x17, 0x42, 0x64, 0x04,
  34448. 0x56, 0x27, 0x50, 0x45, 0x11, 0x27, 0x20, 0x17,
  34449. 0x76, 0x55, 0x33, 0x37, 0x58, 0x88, 0x88, 0x45,
  34450. 0x16, 0x55, 0x08, 0x53, 0x52, 0x48, 0x72, 0x85,
  34451. 0x30, 0x15, 0x23, 0x44, 0x22, 0x02, 0x43, 0x45,
  34452. 0x41, 0x10, 0x00, 0x52, 0x32, 0x73, 0x05, 0x75,
  34453. 0x72, 0x16, 0x08, 0x11, 0x51, 0x36, 0x20, 0x04,
  34454. 0x76, 0x48, 0x78, 0x56, 0x60, 0x88, 0x07, 0x47,
  34455. 0x70, 0x20, 0x46, 0x40, 0x43, 0x26, 0x04, 0x37,
  34456. 0x17, 0x51, 0x58, 0x46, 0x72, 0x44, 0x50, 0x23,
  34457. 0x67, 0x63, 0x60, 0x84, 0x30, 0x51, 0x52, 0x53,
  34458. 0x21, 0x74, 0x85, 0x45, 0x74, 0x43, 0x11, 0x72,
  34459. 0x52, 0x65, 0x76, 0x08, 0x78, 0x63, 0x14, 0x27,
  34460. 0x41, 0x34, 0x67, 0x07, 0x45, 0x15, 0x10, 0x83,
  34461. 0x24, 0x02, 0x80, 0x53, 0x07, 0x21, 0x58, 0x10,
  34462. 0x34, 0x20, 0x54, 0x12, 0x58, 0x44, 0x25, 0x53,
  34463. 0x33, 0x46, 0x02, 0x38, 0x60, 0x17, 0x70, 0x64,
  34464. 0x18, 0x52, 0x62, 0x26, 0x65, 0x61, 0x42, 0x31,
  34465. 0x22, 0x57, 0x34, 0x57, 0x02, 0x34, 0x62, 0x76,
  34466. 0x74, 0x38, 0x73, 0x21, 0x68, 0x71, 0x07, 0x21,
  34467. 0x61, 0x05, 0x20, 0x20, 0x86, 0x83, 0x30, 0x25,
  34468. 0x50, 0x50, 0x83, 0x30, 0x31, 0x56, 0x30, 0x31,
  34469. 0x76, 0x04, 0x54, 0x80, 0x75, 0x18, 0x82, 0x23,
  34470. 0x61, 0x87, 0x58, 0x25, 0x13, 0x63, 0x21, 0x51,
  34471. 0x48, 0x02, 0x67, 0x37, 0x12, 0x88, 0x70, 0x60,
  34472. 0x07, 0x36, 0x18, 0x15, 0x87, 0x74, 0x55, 0x60,
  34473. 0x00, 0x54, 0x37, 0x11, 0x01, 0x37, 0x14, 0x17,
  34474. 0x11, 0x72, 0x14, 0x55, 0x31, 0x75, 0x77, 0x48,
  34475. 0x10, 0x23, 0x83, 0x20, 0x00, 0x04, 0x32, 0x64,
  34476. 0x66, 0x61, 0x71, 0x31, 0x03, 0x15, 0x44, 0x32,
  34477. 0x57, 0x25, 0x64, 0x31, 0x28, 0x15, 0x33, 0x67,
  34478. 0x86, 0x87, 0x37, 0x03, 0x12, 0x78, 0x86, 0x13,
  34479. 0x47, 0x80, 0x61, 0x42, 0x50, 0x40, 0x23, 0x37,
  34480. 0x01, 0x01, 0x66, 0x24, 0x06, 0x57, 0x82, 0x02,
  34481. 0x22, 0x42, 0x41, 0x02, 0x26, 0x06, 0x41, 0x35,
  34482. 0x64, 0x16, 0x44, 0x42, 0x38, 0x30, 0x86, 0x88,
  34483. 0x47, 0x71, 0x62, 0x33, 0x24, 0x02, 0x12, 0x37,
  34484. 0x42, 0x33, 0x20, 0x81, 0x80, 0x53, 0x07, 0x65,
  34485. 0x71, 0x27, 0x13, 0x53, 0x15, 0x43, 0x76, 0x38,
  34486. 0x71, 0x30, 0x07, 0x87, 0x25, 0x63, 0x03, 0x33,
  34487. 0x70, 0x56, 0x18, 0x13, 0x83, 0x51, 0x44, 0x40,
  34488. 0x04, 0x80, 0x62, 0x24, 0x20, 0x64, 0x54, 0x40,
  34489. 0x20, 0x73, 0x61, 0x45, 0x01, 0x24, 0x47, 0x78,
  34490. 0x23, 0x34, 0x56, 0x10, 0x25, 0x32, 0x02, 0x70,
  34491. 0x08, 0x02, 0x23, 0x24, 0x80, 0x43, 0x04, 0x02,
  34492. 0x81, 0x11, 0x23, 0x82, 0x03, 0x61, 0x30, 0x33,
  34493. 0x15, 0x36, 0x25, 0x32, 0x14, 0x73, 0x22, 0x46,
  34494. 0x81, 0x25, 0x16, 0x13, 0x52, 0x58, 0x71, 0x61,
  34495. 0x67, 0x08, 0x38, 0x76, 0x71, 0x15, 0x88, 0x47,
  34496. 0x31, 0x25, 0x27, 0x18, 0x31, 0x50, 0x40, 0x71,
  34497. 0x06, 0x87, 0x37, 0x30, 0x85, 0x64, 0x62, 0x78,
  34498. 0x32, 0x74, 0x18, 0x83, 0x67, 0x40, 0x37, 0x44,
  34499. 0x56, 0x02, 0x72, 0x61, 0x27, 0x28, 0x38, 0x38,
  34500. 0x67, 0x17, 0x58, 0x04, 0x61, 0x28, 0x67, 0x37,
  34501. 0x46, 0x50, 0x38, 0x15, 0x45, 0x12, 0x71, 0x44,
  34502. 0x22, 0x02, 0x34, 0x83, 0x40, 0x70, 0x55, 0x75,
  34503. 0x54, 0x26, 0x88, 0x07, 0x25, 0x58, 0x73, 0x60,
  34504. 0x58, 0x61, 0x45, 0x63, 0x35, 0x05, 0x48, 0x63,
  34505. 0x48, 0x57, 0x03, 0x31, 0x28, 0x14, 0x05, 0x01,
  34506. 0x57, 0x34, 0x64, 0x50, 0x23, 0x86, 0x75, 0x85,
  34507. 0x18, 0x75, 0x56, 0x88, 0x08, 0x26, 0x01, 0x34,
  34508. 0x01, 0x57, 0x05, 0x28, 0x35, 0x48, 0x17, 0x57,
  34509. 0x71, 0x81, 0x41, 0x33, 0x77, 0x86, 0x07, 0x77,
  34510. 0x02, 0x25, 0x71, 0x74, 0x37, 0x31, 0x20, 0x14,
  34511. 0x32, 0x54, 0x20, 0x35, 0x54, 0x76, 0x83, 0x15,
  34512. 0x80, 0x73, 0x27, 0x23, 0x00, 0x58, 0x22, 0x84,
  34513. 0x64, 0x56, 0x14, 0x84, 0x38, 0x34, 0x16, 0x21,
  34514. 0x77, 0x07, 0x34, 0x81, 0x66, 0x87, 0x40, 0x11,
  34515. 0x62, 0x46, 0x45, 0x01, 0x20, 0x53, 0x21, 0x73,
  34516. 0x07, 0x76, 0x44, 0x15, 0x61, 0x50, 0x83, 0x48,
  34517. 0x58, 0x58, 0x45, 0x33, 0x25, 0x36, 0x07, 0x42,
  34518. 0x70, 0x24, 0x07, 0x41, 0x08, 0x35, 0x00, 0x78,
  34519. 0x41, 0x47, 0x02, 0x56, 0x07, 0x14, 0x68, 0x33,
  34520. 0x55, 0x77, 0x32, 0x40, 0x55, 0x24, 0x50, 0x26,
  34521. 0x47, 0x12, 0x65, 0x58, 0x43, 0x05, 0x52, 0x55,
  34522. 0x75, 0x50, 0x18, 0x46, 0x65, 0x48, 0x03, 0x32,
  34523. 0x85, 0x31, 0x16, 0x52, 0x71, 0x57, 0x87, 0x46,
  34524. 0x76, 0x14, 0x42, 0x81, 0x28, 0x74, 0x60, 0x34,
  34525. 0x35, 0x55, 0x52, 0x16, 0x58, 0x48, 0x61, 0x75,
  34526. 0x80, 0x88, 0x15, 0x32, 0x72, 0x26, 0x31, 0x03,
  34527. 0x05, 0x03, 0x16, 0x04, 0x07, 0x37, 0x37, 0x73,
  34528. 0x43, 0x81, 0x57, 0x31, 0x88, 0x04, 0x72, 0x76,
  34529. 0x01, 0x61, 0x81, 0x17, 0x37, 0x65, 0x44, 0x38,
  34530. 0x61, 0x23, 0x16, 0x26, 0x52, 0x45, 0x00, 0x73,
  34531. 0x83, 0x63, 0x64, 0x62, 0x26, 0x74, 0x60, 0x11,
  34532. 0x81, 0x08, 0x06, 0x30, 0x36, 0x05, 0x10, 0x48,
  34533. 0x47, 0x35, 0x10, 0x85, 0x30, 0x86, 0x71, 0x38,
  34534. 0x16, 0x37, 0x6F, 0x3B, 0x1C, 0x18, 0xB1, 0xE3,
  34535. 0xE8, 0xEE, 0x83, 0x3E, 0x8D, 0x38, 0x43, 0x9E,
  34536. 0x78, 0x1C, 0xA3, 0xB8, 0x94, 0x06, 0x54, 0xEF,
  34537. 0x44, 0x6C, 0x9A, 0xAC, 0xC3, 0xF1, 0xD3, 0x0E,
  34538. 0xE0, 0x10, 0x5B, 0x8F, 0x63, 0xEB, 0x89, 0x74,
  34539. 0x6E, 0xF4, 0xBE, 0xB5, 0x4C, 0xFC, 0xE8, 0x81,
  34540. 0x2C, 0xF9, 0x47, 0xCF, 0x54, 0x54, 0xFB, 0x1C,
  34541. 0xA5, 0x5F, 0x25, 0xA0, 0xFE, 0x57, 0xF5, 0xFC,
  34542. 0xFD, 0x73, 0xB0, 0xDA, 0x04, 0xB0, 0xBF, 0x28,
  34543. 0x92, 0x92, 0xAF, 0x39, 0x74, 0x72, 0x56, 0x69,
  34544. 0xC3, 0x00, 0x03, 0xE0, 0x50, 0x9F, 0xED, 0xC8,
  34545. 0x0F, 0x6C, 0x89, 0x4B, 0xB0, 0x47, 0xC2, 0xE2,
  34546. 0xAF, 0x48, 0x5C, 0xAD, 0x68, 0xC2, 0x1D, 0x80,
  34547. 0xEF, 0x33, 0xB0, 0xC4, 0xFD, 0xA6, 0x7B, 0x85,
  34548. 0x31, 0xA1, 0x58, 0x87, 0x67, 0x54, 0x71, 0x3F,
  34549. 0xF8, 0xA8, 0xA6, 0x8D, 0x9A, 0xBD, 0xC4, 0x81,
  34550. 0x6B, 0x24, 0xB4, 0xA3, 0x6A, 0x8A, 0x2B, 0xB1,
  34551. 0xFD, 0x1C, 0x2C, 0x25, 0xC3, 0x72, 0xC4, 0xB7,
  34552. 0x75, 0xF8, 0xCC, 0x17, 0x39, 0xCF, 0x2C, 0xE9,
  34553. 0xA4, 0x54, 0x58, 0xE4, 0x1A, 0xAE, 0xC6, 0x4A,
  34554. 0xEE, 0xDE, 0x75, 0x7C, 0xE7, 0x38, 0xBC, 0xDF,
  34555. 0x4D, 0xA0, 0xEE, 0x2B, 0xDD, 0x5F, 0x80, 0x5C,
  34556. 0xCF, 0xF7, 0x2A, 0x5F, 0x73, 0x8B, 0xAC, 0x12,
  34557. 0x34, 0x2E, 0xE3, 0xF1, 0x4C, 0xB7, 0x22, 0x68,
  34558. 0xC2, 0xD6, 0x36, 0x7D, 0xF1, 0x7F, 0x20, 0x46,
  34559. 0xA2, 0x4B, 0x47, 0x4B, 0x32, 0x58, 0xF7, 0xB0,
  34560. 0x88, 0x54, 0x6C, 0x99, 0x3B, 0x0D, 0xA1, 0xE2,
  34561. 0x92, 0x92, 0xEB, 0x72, 0x1E, 0xE7, 0xE5, 0xA1,
  34562. 0xF8, 0x6E, 0x14, 0xA5, 0x39, 0xB0, 0x63, 0x6F,
  34563. 0x78, 0x82, 0xA1, 0x9C, 0x8D, 0x79, 0x02, 0x85,
  34564. 0xA6, 0xDF, 0x7D, 0xEE, 0xCE, 0x17, 0x4D, 0x63,
  34565. 0xCF, 0xF3, 0xB2, 0xFF, 0x85, 0x68, 0x81, 0xCB,
  34566. 0x38, 0x6B, 0x1B, 0x38, 0xA2, 0xE0, 0xF2, 0x4C,
  34567. 0x31, 0xE0, 0x91, 0x93, 0xDD, 0xF3, 0x71, 0x47,
  34568. 0xF2, 0x69, 0xD9, 0x4C, 0xDE, 0xF9, 0x90, 0x61,
  34569. 0x34, 0x62, 0x07, 0x71, 0x79, 0xD0, 0xDD, 0x09,
  34570. 0x32, 0x64, 0x39, 0x49, 0x93, 0x1A, 0x02, 0xBA,
  34571. 0xFA, 0x80, 0x17, 0x6E, 0xDF, 0x97, 0xB6, 0xA2,
  34572. 0x31, 0x34, 0x71, 0xF0, 0xB1, 0x9B, 0x3B, 0x59,
  34573. 0xF4, 0x3B, 0xD2, 0x2A, 0x05, 0x49, 0x3E, 0xFB,
  34574. 0x0C, 0xF8, 0xB5, 0xD7, 0xB6, 0x25, 0x2B, 0x09,
  34575. 0x8B, 0x4B, 0xFA, 0x39, 0x5B, 0xF9, 0xA2, 0x09,
  34576. 0xE9, 0xBB, 0x46, 0x01, 0x30, 0x00, 0x90, 0x32,
  34577. 0x58, 0xA6, 0x9B, 0x67, 0xF5, 0x94, 0x11, 0xC8,
  34578. 0x35, 0x95, 0xFA, 0x6E, 0x67, 0x42, 0x8D, 0x96,
  34579. 0x6D, 0x20, 0xFC, 0xD3, 0x09, 0x61, 0x11, 0x86,
  34580. 0x77, 0xC0, 0x86, 0xA3, 0x54, 0xAE, 0x6D, 0x41,
  34581. 0xEE, 0x17, 0xDC, 0xA1, 0xB0, 0xB7, 0x50, 0x43,
  34582. 0xD6, 0xCE, 0x23, 0xBD, 0xB0, 0x1E, 0x02, 0xE5,
  34583. 0x9E, 0xCF, 0xC6, 0x2E, 0x8C, 0x39, 0x71, 0xB1,
  34584. 0x45, 0x02, 0x75, 0xBA, 0x7F, 0x60, 0xB0, 0x8B,
  34585. 0x1C, 0x33, 0xBA, 0x0C, 0xFF, 0x54, 0x63, 0xE3,
  34586. 0x47, 0x5B, 0x07, 0x77, 0x77, 0xC5, 0x72, 0x24,
  34587. 0x60, 0xFA, 0xDB, 0x0B, 0xF6, 0x41, 0x82, 0x69,
  34588. 0x3C, 0x68, 0x37, 0xF5, 0xFD, 0x45, 0x4A, 0x66,
  34589. 0x6C, 0xD7, 0x01, 0x10, 0x78, 0x4A, 0xED, 0x09,
  34590. 0xAE, 0x49, 0x0A, 0x60, 0xC7, 0x78, 0x56, 0x51,
  34591. 0x15, 0xE3, 0x4A, 0xB5, 0xAE, 0xAD, 0x09, 0xD1,
  34592. 0x71, 0xA8, 0xCA, 0x3C, 0x8A, 0xE6, 0xCA, 0x39,
  34593. 0x43, 0x60, 0x56, 0x83, 0x3C, 0x58, 0x04, 0xD4,
  34594. 0xB4, 0x62, 0xDD, 0x53, 0x05, 0xC8, 0x51, 0xAF,
  34595. 0x59, 0xF6, 0x4F, 0x04, 0xC3, 0x1E, 0x69, 0xFF,
  34596. 0x82, 0xBF, 0xD7, 0x89, 0xD2, 0x30, 0x9F, 0xF2,
  34597. 0xE6, 0x38, 0x05, 0x9C, 0xD5, 0x08, 0xB8, 0x25,
  34598. 0xF3, 0x3B, 0x99, 0x85, 0x4E, 0x40, 0xF8, 0x40,
  34599. 0xF2, 0x4B, 0x5C, 0x3A, 0xA8, 0x64, 0x41, 0x92,
  34600. 0xEA, 0xCA, 0x9A, 0x7B, 0xCF, 0xBA, 0x1F, 0xDE,
  34601. 0xE0, 0x9D, 0xCA, 0xAD, 0xB4, 0x0C, 0x90, 0xFF,
  34602. 0xE1, 0x6C, 0xEC, 0xDD, 0x32, 0x38, 0x2A, 0xF7,
  34603. 0x19, 0x20, 0x39, 0xCB, 0x29, 0x67, 0x2F, 0x70,
  34604. 0x71, 0x12, 0x10, 0xB6, 0xB8, 0x3E, 0x8D, 0xFD,
  34605. 0xB5, 0xFB, 0xBD, 0xBF, 0xA8, 0xCA, 0x19, 0xC4,
  34606. 0xC6, 0xAC, 0x37, 0x31, 0xFC, 0x33, 0xC2, 0x7F,
  34607. 0xA2, 0xA2, 0x6D, 0xEB, 0x15, 0x2E, 0xA1, 0x90,
  34608. 0xF8, 0x29, 0xC6, 0x34, 0xD1, 0x39, 0x30, 0x24,
  34609. 0x1C, 0xB9, 0x26, 0xAC, 0xDD, 0xE5, 0x24, 0x9C,
  34610. 0xDD, 0x35, 0x60, 0x7E, 0x38, 0x0C, 0xC1, 0x2A,
  34611. 0x7D, 0x1E, 0xA9, 0xBA, 0xA5, 0x58, 0x4C, 0xDD,
  34612. 0x26, 0x86, 0x09, 0xDC, 0xC3, 0xB0, 0x1F, 0xCD,
  34613. 0xC9, 0xAD, 0xCB, 0x4A, 0x7E, 0x51, 0x67, 0xE5,
  34614. 0xED, 0x5A, 0xD2, 0x21, 0xDB, 0x2E, 0xAB, 0xD9,
  34615. 0x0A, 0xEC, 0xAE, 0x71, 0xFA, 0x23, 0x7A, 0xEF,
  34616. 0x98, 0xDF, 0x53, 0x89, 0x93, 0xE8, 0x71, 0xD7,
  34617. 0x35, 0xDA, 0x6B, 0x88, 0x31, 0xAF, 0x67, 0xF2,
  34618. 0x97, 0x29, 0x1C, 0x39, 0x67, 0xEB, 0xAF, 0x60,
  34619. 0xD9, 0x53, 0xC4, 0x0F, 0x7A, 0x46, 0x4E, 0xF3,
  34620. 0x2F, 0x8E, 0xAE, 0xFA, 0x64, 0x2E, 0x37, 0xDE,
  34621. 0xA9, 0x74, 0x73, 0x5D, 0xDD, 0xBB, 0x83, 0x54,
  34622. 0x27, 0xB9, 0x7A, 0x63, 0x2B, 0x19, 0x8B, 0x26,
  34623. 0x22, 0x28, 0x84, 0xA0, 0x58, 0x00, 0x2D, 0x55,
  34624. 0xEA, 0x2A, 0x80, 0x0D, 0x6C, 0x97, 0x0E, 0x8B,
  34625. 0xF7, 0x67, 0xB2, 0x8B, 0x2D, 0xDE, 0x8F, 0x58,
  34626. 0xFE, 0x97, 0x81, 0xE7, 0xE2, 0x58, 0x8D, 0x7E,
  34627. 0x1B, 0xAB, 0xE5, 0x15, 0x9D, 0x54, 0xF4, 0x00,
  34628. 0x34, 0x1D, 0x12, 0x1B, 0x03, 0x23, 0x2B, 0x06,
  34629. 0x2E, 0x8C, 0xD0, 0x0A, 0xDC, 0x19, 0xA1, 0x69,
  34630. 0x1D, 0x72, 0x91, 0xB4, 0xED, 0x0E, 0x81, 0xF7,
  34631. 0x05, 0x99, 0x84, 0xFC, 0x74, 0x0F, 0x7D, 0xF8,
  34632. 0x9B, 0x3E, 0x7F, 0x63, 0x7C, 0x73, 0xEB, 0xF5,
  34633. 0x36, 0xB3, 0x24, 0x22, 0xAA, 0x33, 0x0C, 0x30,
  34634. 0x42, 0xC3, 0xE2, 0x04, 0x6B, 0x3F, 0x2A, 0x0D,
  34635. 0xAB, 0xE8, 0x5A, 0x9A, 0x09, 0xD7, 0xB6, 0xAA,
  34636. 0x9C, 0x3E, 0xD0, 0x9E, 0xB5, 0x9B, 0x52, 0x7B,
  34637. 0xAF, 0x2D, 0x6B, 0xE0, 0x40, 0x12, 0x34, 0xBE,
  34638. 0x49, 0xAB, 0xD2, 0xC8, 0xB5, 0x89, 0x1B, 0x79,
  34639. 0xEC, 0xAE, 0x88, 0x89, 0x3C, 0x05, 0xC7, 0x75,
  34640. 0xC5, 0x84, 0xF7, 0x10, 0x49, 0x48, 0x92, 0x69,
  34641. 0x9E, 0xD5, 0x56, 0xB2, 0x1E, 0x81, 0x18, 0x78,
  34642. 0xCB, 0x93, 0x5D, 0x70, 0x3A, 0xB2, 0x67, 0xD1,
  34643. 0xCC, 0x8F, 0x83, 0x03, 0xB9, 0x64, 0x46, 0x22,
  34644. 0x78, 0x0D, 0x55, 0x67, 0x22, 0x58, 0x0E, 0x22,
  34645. 0x6B, 0xBA, 0x01, 0xD4, 0x77, 0x05, 0xA7, 0xAC,
  34646. 0xB7, 0xE5, 0xFC, 0xE6, 0x11, 0xCC, 0x92, 0x5A,
  34647. 0x8C, 0xC0, 0x08, 0x24, 0xAF, 0xCC, 0x4D, 0xBD,
  34648. 0x79, 0xD3, 0x5C, 0x52, 0x2C, 0xFF, 0x1A, 0x48,
  34649. 0xBB, 0x91, 0x59, 0x6A, 0x80, 0x32, 0x8C, 0x75,
  34650. 0x7C, 0xD2, 0xC1, 0x94, 0x94, 0xA8, 0x55, 0x4B,
  34651. 0xF2, 0x96, 0xF7, 0x86, 0xF7, 0x53, 0x4F, 0x54,
  34652. 0x74, 0x05, 0x5C, 0xEF, 0x02, 0xA0, 0x8A, 0xD1,
  34653. 0x88, 0x72, 0xEB, 0x1B, 0x82, 0xF9, 0xFB, 0xDA,
  34654. 0xBC, 0xB9, 0x90, 0x98, 0xF2, 0x4B, 0x9A, 0xA6,
  34655. 0x89, 0xD5, 0xB3, 0xD8, 0x7B, 0x94, 0xE3, 0x1F,
  34656. 0x17, 0x4F, 0xEB, 0x24, 0x06, 0x2B, 0xAB, 0x5F,
  34657. 0x27, 0x9B, 0xCD, 0xCE, 0x50, 0x06, 0x40, 0xDD,
  34658. 0x7A, 0x8C, 0x67, 0xF0, 0x8E, 0x07, 0xB4, 0x1C,
  34659. 0x3C, 0x13, 0xB2, 0x07, 0x6A, 0x38, 0x59, 0x94,
  34660. 0x2C, 0xB1, 0x72, 0xA8, 0x77, 0x5B, 0x15, 0x8F,
  34661. 0x88, 0xC4, 0x5C, 0xDC, 0x92, 0xCA, 0xC0, 0xED,
  34662. 0x02, 0xFF, 0x1D, 0x57, 0x25, 0xBE, 0x67, 0x3E,
  34663. 0x4C, 0xE8, 0x95, 0x2A, 0x80, 0xB2, 0x5D, 0xBC,
  34664. 0xFA, 0x17, 0xA9, 0x35, 0x0A, 0x6B, 0x07, 0xC8,
  34665. 0x8F, 0x88, 0x8D, 0xBC, 0x97, 0x84, 0xE2, 0x07,
  34666. 0x57, 0x92, 0x99, 0x4B, 0xE8, 0xDD, 0xD7, 0xA4,
  34667. 0x58, 0xCB, 0x61, 0xCE, 0x16, 0xFC, 0x22, 0xCD,
  34668. 0x4B, 0x1A, 0x08, 0xC9, 0xAD, 0x3D, 0xB1, 0xF2,
  34669. 0xA9, 0x1B, 0x8E, 0xD0, 0xC7, 0xBC, 0xCE, 0xF9,
  34670. 0x0A, 0x7A, 0x4D, 0xBE, 0x82, 0x0A, 0xBD, 0x6C,
  34671. 0x42, 0x99, 0xBF, 0x86, 0x65, 0x53, 0xAA, 0x04,
  34672. 0x79, 0xD6, 0x6D, 0x7E, 0x0F, 0x40, 0xFA, 0xEE,
  34673. 0xCE, 0x38, 0x3B, 0x1C, 0x2F, 0xA4, 0x45, 0xA3,
  34674. 0x78, 0x2B, 0xA0, 0x29, 0xC5, 0xAA, 0xA9, 0x09,
  34675. 0x29, 0x51, 0xDC, 0x5B, 0xB5, 0x95, 0xE4, 0xCE,
  34676. 0xC8, 0x50, 0x71, 0x2D, 0xE9, 0x32, 0x12, 0xA0,
  34677. 0x7C, 0x88, 0x6B, 0xED, 0xE4, 0x38, 0xB7, 0x92,
  34678. 0xCA, 0xE4, 0xDC, 0xD4, 0x05, 0x3B, 0x2B, 0x84,
  34679. 0x95, 0x07, 0xFF, 0xF4, 0x79, 0xFF, 0x1E, 0x73,
  34680. 0x1B, 0x8E, 0xDF, 0xA3, 0x15, 0xBD, 0x56, 0xAC,
  34681. 0xDA, 0xAD, 0x73, 0x95, 0xC2, 0xD3, 0x72, 0xA8,
  34682. 0xF0, 0x8E, 0x6C, 0xE3, 0x7D, 0xBE, 0x4C, 0x87,
  34683. 0xFC, 0x0F, 0xA6, 0x3B, 0xED, 0xA4, 0x0F, 0x4F,
  34684. 0xF1, 0x5D, 0xF2, 0x56, 0x54, 0xD1, 0xCE, 0x6C,
  34685. 0xCA, 0x1C, 0xCB, 0xC2, 0x45, 0x7F, 0x90, 0x61,
  34686. 0x0E, 0x3D, 0xCE, 0xBB, 0x5E, 0x41, 0x38, 0x2B,
  34687. 0xD4, 0x41, 0x7C, 0x67, 0x7C, 0x71, 0x95, 0x34,
  34688. 0xD7, 0xED, 0x4D, 0xAC, 0x6E, 0xF1, 0x46, 0xEA,
  34689. 0x7D, 0xA4, 0x4C, 0x69, 0x0B, 0x9C, 0x2F, 0xAA,
  34690. 0xF1, 0x17, 0x90, 0x1B, 0xF4, 0x4C, 0x03, 0xBE,
  34691. 0x9D, 0x56, 0xCE, 0x0C, 0xCF, 0xE0, 0x87, 0x44,
  34692. 0xBE, 0x2C, 0x52, 0xD3, 0xBC, 0xAE, 0x02, 0x30,
  34693. 0xC7, 0x26, 0x06, 0x88, 0xA6, 0xAA, 0x9D, 0x50,
  34694. 0xF1, 0x94, 0x58, 0xC7, 0x60, 0xF3, 0xA0, 0x6F,
  34695. 0x53, 0x66, 0x53, 0xCD, 0x1D, 0xBE, 0xD1, 0xF2,
  34696. 0x39, 0xBA, 0x1F, 0xE8, 0x40, 0x84, 0xCD, 0x1C,
  34697. 0x8F, 0x3D, 0xB7, 0xD1, 0x51, 0x00, 0xDE, 0xB8,
  34698. 0x11, 0xD9, 0x66, 0xAD, 0xD5, 0xE9, 0x33, 0x09,
  34699. 0xE1, 0xA8, 0x00, 0x58, 0x65, 0xF1, 0xC1, 0x67,
  34700. 0xB4, 0x3A, 0xA7, 0x98, 0x90, 0x6A, 0xDB, 0x91,
  34701. 0xDB, 0x4A, 0x16, 0x35, 0xDC, 0x3D, 0x69, 0xEB,
  34702. 0x7B, 0xDE, 0xCC, 0x91, 0x1B, 0x8D, 0xE6, 0x46,
  34703. 0x61, 0x8E, 0x3F, 0x4C, 0x88, 0x81, 0x85, 0x4A,
  34704. 0x73, 0x08, 0x56, 0x52, 0xAE, 0xE6, 0x4A, 0x60,
  34705. 0x4A, 0x2E, 0x0C, 0x9A, 0x93, 0x76, 0x35, 0xC9,
  34706. 0x36, 0x28, 0x0C, 0x72, 0x19, 0xAD, 0x33, 0xCF,
  34707. 0x2B, 0xFB, 0xCE, 0x1A, 0x7D, 0xAC, 0xAA, 0x75,
  34708. 0x15, 0x76, 0x81, 0x52, 0x55, 0xCC, 0xB9, 0x39,
  34709. 0x07, 0xA3, 0x39, 0x12, 0x8D, 0x6F, 0x53, 0xAF,
  34710. 0xC7, 0x14, 0x7F, 0xC7, 0x96, 0x5A, 0x49, 0x3C,
  34711. 0x5C, 0xB0, 0x26, 0x47, 0xF4, 0x9D, 0xCA, 0x23,
  34712. 0xA6, 0x7D, 0xA6, 0x61, 0xC4, 0xA3, 0x26, 0x40,
  34713. 0x0F, 0xA7, 0x27, 0x09, 0xBC, 0x39, 0xFD, 0xA7,
  34714. 0x75, 0x38, 0x74, 0xD0, 0x9D, 0x29, 0x15, 0x97,
  34715. 0xDE, 0x25, 0x60, 0x4D, 0x19, 0x36, 0x04, 0xFB,
  34716. 0xA5, 0x2C, 0xB0, 0xC8, 0xB5, 0xFE, 0xE5, 0x94,
  34717. 0x7C, 0xE2, 0x1F, 0x84, 0xBB, 0xFB, 0x78, 0x9E,
  34718. 0xA5, 0x7C, 0x5D, 0x4A, 0xB2, 0x48, 0x6F, 0x6E,
  34719. 0x67, 0x95, 0x16, 0x5F, 0x01, 0x2A, 0xF8, 0x70,
  34720. 0x95, 0xCB, 0x06, 0x93, 0x26, 0x6E, 0x7A, 0x75,
  34721. 0xB5, 0xE5, 0x4E, 0x27, 0x1D, 0x8B, 0x30, 0xA6,
  34722. 0x67, 0x67, 0xD6, 0xE2, 0xD6, 0xD1, 0x99, 0xA4,
  34723. 0x55, 0x73, 0x19, 0x32, 0xF6, 0x0B, 0x6B, 0x4A,
  34724. 0xEE, 0x23, 0x33, 0x38, 0x30, 0x68, 0x6F, 0x8E,
  34725. 0x60, 0xA9, 0x60, 0x97, 0x3E, 0xEA, 0x5D, 0xE1,
  34726. 0x40, 0x6F, 0x0C, 0x76, 0x84, 0xCF, 0xAF, 0x86,
  34727. 0x8D, 0x36, 0xE5, 0x7D, 0xAE, 0x9A, 0x13, 0x70,
  34728. 0x22, 0x2A, 0x31, 0xFE, 0xC2, 0xFB, 0xE1, 0x58,
  34729. 0xA5, 0x4E, 0xEF, 0x10, 0x5B, 0x5E, 0xD4, 0x39,
  34730. 0xFC, 0xF9, 0x15, 0x64, 0x78, 0x43, 0x7D, 0x03,
  34731. 0x9F, 0x5B, 0xCB, 0x86, 0xD2, 0xEF, 0x28, 0xBD,
  34732. 0x14, 0xCB, 0x8A, 0x04, 0x1D, 0x59, 0x23, 0x53,
  34733. 0x4D, 0x13, 0xF9, 0x93, 0xFE, 0x19, 0x9C, 0xC3,
  34734. 0x3F, 0xD9, 0xC1, 0x12, 0x94, 0x84, 0x13, 0x95,
  34735. 0x8F, 0xD9, 0x10, 0xAB, 0x37, 0x69, 0x08, 0x04,
  34736. 0x4A, 0x97, 0x82, 0x28, 0x75, 0xBB, 0xC9, 0xF4,
  34737. 0x3F, 0x19, 0x6B, 0x00, 0x4C, 0x56, 0x16, 0x1F,
  34738. 0x50, 0x82, 0xD1, 0x45, 0xFF, 0x0C, 0x37, 0x28,
  34739. 0x04, 0xBB, 0x6C, 0x00, 0x97, 0x3A, 0x79, 0x2D,
  34740. 0x9A, 0xB9, 0xA5, 0x16, 0x52, 0x02, 0xA3, 0x86,
  34741. 0x81, 0xAA, 0x3A, 0x31, 0xE5, 0xB5, 0x44, 0x2D,
  34742. 0x34, 0xE2, 0x7A, 0xD8, 0xFE, 0xA1, 0x36, 0xC0,
  34743. 0x36, 0x65, 0x73, 0x12, 0x9F, 0x61, 0x3F, 0x59,
  34744. 0xC9, 0x68, 0xB6, 0x34, 0x41, 0x40, 0x25, 0xD6,
  34745. 0xE7, 0xAD, 0x25, 0x7D, 0xCB, 0xF1, 0x2A, 0xD8,
  34746. 0x53, 0x48, 0x9D, 0xBF, 0xB5, 0xD5, 0x61, 0x18,
  34747. 0x0E, 0x2A, 0x21, 0x3E, 0x61, 0x18, 0x07, 0x8E,
  34748. 0x6F, 0x9A, 0x96, 0xA8, 0x61, 0xFE, 0x8D, 0x66,
  34749. 0x1A, 0x21, 0x99, 0xD9, 0x60, 0x8B, 0xAC, 0x85,
  34750. 0x84, 0x3D, 0x41, 0xF9, 0x93, 0x35, 0x24, 0x32,
  34751. 0xFF, 0xC0, 0x8A, 0xFA, 0xBC, 0xA7, 0x85, 0x57,
  34752. 0x3C, 0x16, 0x83, 0xAE, 0x90, 0xDE, 0x40, 0x12,
  34753. 0xE4, 0x2B, 0xA2, 0x47, 0xA4, 0x92, 0x73, 0x54,
  34754. 0x6C, 0xA5, 0xB7, 0xEE, 0x62, 0xEA, 0x62, 0x37,
  34755. 0xD9, 0xD7, 0x73, 0x58, 0x43, 0xDB, 0x20, 0x60,
  34756. 0x8C, 0x4F, 0x87, 0x58, 0xB2, 0x2B, 0xC3, 0x40,
  34757. 0xB0, 0xC1, 0xB6, 0xB6, 0xA9, 0xCD, 0xCC, 0x05,
  34758. 0x4F, 0x38, 0x5F, 0x08, 0xB3, 0x3B, 0x08, 0x4D,
  34759. 0x78, 0x6B, 0x0D, 0x40, 0x46, 0xB9, 0x20, 0xDE,
  34760. 0x29, 0x6F, 0x23, 0x96, 0xDA, 0x02, 0xF5, 0x1C,
  34761. 0x1A, 0x1A, 0x36, 0xA3, 0x3A, 0xFA, 0x1D, 0x80,
  34762. 0x36, 0x3C, 0xF6, 0xB4, 0xDC, 0x2C, 0x88, 0x54,
  34763. 0xF7, 0x86, 0xC6, 0xF2, 0x15, 0xF8, 0x85, 0x33,
  34764. 0xFB, 0x21, 0x20, 0x59, 0xCE, 0x60, 0x4B, 0xE8,
  34765. 0xF1, 0xB7, 0x54, 0x17, 0x1E, 0x83, 0xCD, 0x82,
  34766. 0x39, 0x40, 0x14, 0x31, 0xEC, 0x89, 0xC8, 0xE2,
  34767. 0x6A, 0xAE, 0x3F, 0x49, 0x5B, 0x38, 0xE7, 0xCD,
  34768. 0xE2, 0xF6, 0xEF, 0x90, 0x51, 0x10, 0x83, 0x79,
  34769. 0x27, 0x80, 0x2F, 0x45, 0x78, 0x67, 0xAF, 0xF4,
  34770. 0x65, 0x95, 0x2D, 0xFE, 0x00, 0xF3, 0x2A, 0x60,
  34771. 0x00, 0xF7, 0x26, 0xFA, 0x3C, 0xAD, 0xA9, 0xAF,
  34772. 0xCA, 0xF6, 0x69, 0x48, 0x03, 0xBE, 0x18, 0x73,
  34773. 0x54, 0x06, 0x06, 0x3E, 0x4E, 0xAD, 0xFC, 0x8B,
  34774. 0xC3, 0x43, 0x24, 0x5D, 0xE9, 0xDE, 0x78, 0xDC,
  34775. 0xD0, 0xA7, 0x04, 0x77, 0xF0, 0x0D, 0xA3, 0x37,
  34776. 0x8C, 0x5F, 0x8B, 0xDF, 0xBE, 0x90, 0x1F, 0xA6,
  34777. 0xB3, 0x17, 0x9D, 0x68, 0x36, 0x45, 0x11, 0x60,
  34778. 0xFF, 0xF9, 0xBA, 0xDA, 0x80, 0xAA, 0x37, 0x57,
  34779. 0xDD, 0x34, 0x30, 0x42, 0x7A, 0x9C, 0x86, 0xB4,
  34780. 0x91, 0x30, 0xB8, 0xC0, 0xC4, 0x29, 0x15, 0x31,
  34781. 0xF3, 0x9A, 0xB0, 0xCD, 0xAC, 0x8C, 0x7C, 0x8C,
  34782. 0x4A, 0xDC, 0x76, 0xB6, 0x31, 0x30, 0xDE, 0x2D,
  34783. 0x81, 0x04, 0xC7, 0x48, 0x73, 0x69, 0x02, 0x40,
  34784. 0x30, 0x19, 0x66, 0x94, 0x21, 0x65, 0x13, 0x18,
  34785. 0xC2, 0x09, 0x14, 0x5F, 0xC4, 0x2F, 0xC4, 0xD6,
  34786. 0xA6, 0x05, 0x37, 0xAF, 0x72, 0x0C, 0x47, 0x02,
  34787. 0x29, 0x95, 0x08, 0x9D, 0xC9, 0x07, 0x31, 0x38,
  34788. 0xA9, 0xB5, 0xDA, 0x21, 0x76, 0x1D, 0x84, 0xD0,
  34789. 0x15, 0xAF, 0x2A, 0xA3, 0x69, 0x0A, 0xE9, 0x4F,
  34790. 0x75, 0x8A, 0x50, 0xA5, 0x11, 0xD4, 0x5F, 0xAF,
  34791. 0x70, 0x43, 0xCB, 0xD7, 0x03, 0x9E, 0xB0, 0xBD,
  34792. 0x19, 0x47, 0x94, 0x58, 0x22, 0x86, 0xC6, 0xE3,
  34793. 0x62, 0xD8, 0x63, 0x05, 0xD9, 0xE2, 0xE5, 0x4A,
  34794. 0x04, 0x54, 0x5A, 0x55, 0x25, 0xAD, 0x15, 0x5C,
  34795. 0x4B, 0x71, 0x25, 0xE1, 0x50, 0xE3, 0x62, 0x1B,
  34796. 0xD2, 0x43, 0x28, 0xD2, 0x84, 0xE4, 0xE2, 0x05,
  34797. 0xE3, 0x01, 0x4C, 0x8F, 0x38, 0x17, 0x49, 0xFD,
  34798. 0x3B, 0x52, 0x1A, 0x55, 0xB3, 0x1D, 0x69, 0x83,
  34799. 0xAB, 0x9E, 0xC4, 0x73, 0xEE, 0x64, 0x7A, 0x73,
  34800. 0x19, 0xEF, 0xCD, 0x7D, 0xB7, 0xF4, 0x2E, 0xCB,
  34801. 0x55, 0x2A, 0x8A, 0xCC, 0x8F, 0xF8, 0x4E, 0xFB,
  34802. 0xD2, 0x63, 0x8F, 0xF1, 0x10, 0x89, 0x02, 0x93,
  34803. 0x3E, 0xAC, 0xA4, 0xB4, 0x89, 0xC7, 0xF7, 0x8B,
  34804. 0x3E, 0xE1, 0xE8, 0x93, 0xB9, 0x8E, 0x36, 0x25,
  34805. 0xC1, 0xC0, 0xD9, 0x44, 0x81, 0xC0, 0x99, 0x3C,
  34806. 0x2B, 0x89, 0xF7, 0xDF, 0xDB, 0xD8, 0xCC, 0x84,
  34807. 0xE6, 0xFF, 0xFE, 0xAC, 0x21, 0x16, 0xF1, 0xE2,
  34808. 0xEF, 0x0A, 0x32, 0xA7, 0xDE, 0x87, 0x51, 0xEC,
  34809. 0xB1, 0x0C, 0x0B, 0xC7, 0x07, 0xD9, 0x9A, 0xF8,
  34810. 0xE8, 0xB0, 0xFE, 0xA5, 0x67, 0xAF, 0x53, 0x9F,
  34811. 0xEF, 0x23, 0xEF, 0x7D, 0xFF, 0xA8, 0x8E, 0xDE,
  34812. 0x97, 0x93, 0x32, 0xA6, 0x7C, 0xCF, 0x49, 0xBC,
  34813. 0x36, 0x0D, 0x88, 0x90, 0x89, 0x39, 0x76, 0xA8,
  34814. 0x82, 0x19, 0x02, 0xB6, 0x02, 0x82, 0xFE, 0xED,
  34815. 0x9C, 0x28, 0x8D, 0xB0, 0x1E, 0x2B, 0x2A, 0xCF,
  34816. 0xF3, 0x94, 0xFF, 0x66, 0x33, 0x93, 0x31, 0xD6,
  34817. 0xFC, 0xAF, 0xE7, 0xC5, 0x98, 0x01, 0x46, 0xCD,
  34818. 0xCB, 0xC4, 0x41, 0x13, 0x6D, 0x42, 0xF5, 0x13,
  34819. 0xDF, 0xF9, 0x97, 0x65, 0xD4, 0x7B, 0x6E, 0x10,
  34820. 0x79, 0x5D, 0x5A, 0x82, 0xA2, 0x49, 0x53, 0xA7,
  34821. 0x6D, 0x9C, 0xDD, 0x0A, 0x80, 0x98, 0x58, 0x07,
  34822. 0x30, 0xBF, 0x0B, 0x30, 0xAC, 0x24, 0x9E, 0xA0,
  34823. 0xE8, 0xE4, 0x7A, 0x0D, 0xD0, 0x50, 0x82, 0xAE,
  34824. 0xBB, 0xEC, 0x15, 0x30, 0x2A, 0xF2, 0xA7, 0xA6,
  34825. 0x6A, 0xC8, 0xAE, 0x1E, 0x14, 0x80, 0x7C, 0x18,
  34826. 0xE7, 0x2B, 0x88, 0x65, 0xB7, 0x93, 0x12, 0xB3,
  34827. 0xC1, 0x2A, 0x20, 0xAD, 0x3B, 0x2E, 0x84, 0xC4,
  34828. 0x0D, 0xA7, 0x62, 0x5C, 0x79, 0x52, 0x5D, 0x59,
  34829. 0xA4, 0x69, 0x5C, 0x26, 0xFD, 0x4F, 0x80, 0xCC,
  34830. 0xFE, 0x8E, 0x70, 0x72, 0xB1, 0x41, 0xE1, 0x75,
  34831. 0x53, 0x51, 0xCF, 0x4C, 0x0B, 0x57, 0xF2, 0xB8,
  34832. 0x59, 0x76, 0xE6, 0xEF, 0x6D, 0x74, 0xA6, 0x73,
  34833. 0x69, 0x7F, 0x7C, 0xB2, 0x35, 0xFE, 0x8A, 0x02,
  34834. 0x2F, 0xBE, 0x7C, 0x4D, 0x02, 0xBE, 0x8F, 0xFB,
  34835. 0x7A, 0x58, 0x45, 0xEC, 0xBA, 0x1B, 0xC6, 0xB9,
  34836. 0x8D, 0xF5, 0xB0, 0x82, 0xD1, 0xB4, 0x97, 0x86,
  34837. 0x9B, 0x33, 0x54, 0x49, 0x5B, 0x88, 0xD9, 0xB5,
  34838. 0xD0, 0x93, 0x8A, 0x00, 0x5D, 0x0F, 0x37, 0x88,
  34839. 0x57, 0xE3, 0xFA, 0x7E, 0x7B, 0xFA, 0x43, 0x74,
  34840. 0x8D, 0x64, 0x07, 0xD7, 0x07, 0x85, 0x4D, 0x49,
  34841. 0xBC, 0x83, 0xF5, 0xD4, 0x95, 0x3E, 0x3E, 0x09,
  34842. 0x65, 0xF3, 0xFC, 0x88, 0xA7, 0xF0, 0x46, 0x61,
  34843. 0x44, 0x7D, 0x76, 0xED, 0xC9, 0x8D, 0x0F, 0x8D,
  34844. 0xDA, 0x0D, 0x01, 0xC8, 0xB1, 0xA8, 0x9B, 0x4A,
  34845. 0xF0, 0xA3, 0x88, 0x54, 0xC1, 0xD6, 0x52, 0x97
  34846. };
  34847. #endif /* WOLFSSL_NO_ML_DSA_65 */
  34848. #ifndef WOLFSSL_NO_ML_DSA_87
  34849. static const byte seed_87_draft[] = {
  34850. 0x22, 0x5F, 0x77, 0x07, 0x5E, 0x66, 0xCE, 0x1C,
  34851. 0x99, 0xBA, 0x95, 0xB4, 0xFC, 0xDF, 0x25, 0x8B,
  34852. 0xBB, 0x6F, 0xA5, 0xFE, 0x9C, 0x34, 0x9F, 0x0F,
  34853. 0xDE, 0x3F, 0x71, 0xD5, 0x33, 0x9F, 0x6F, 0xD8
  34854. };
  34855. static const byte pk_87_draft[] = {
  34856. 0x8C, 0x52, 0x4B, 0xD9, 0xAC, 0x48, 0x5C, 0xC6,
  34857. 0x9A, 0xA0, 0x75, 0x64, 0xE1, 0x4F, 0x0F, 0x60,
  34858. 0x13, 0x0E, 0xDE, 0x34, 0x08, 0xA5, 0xD4, 0x81,
  34859. 0xFD, 0x76, 0xC2, 0x51, 0x74, 0x75, 0xA8, 0xFB,
  34860. 0x24, 0xBF, 0x9E, 0x97, 0x9C, 0xD2, 0x3E, 0xDA,
  34861. 0x8A, 0x1B, 0xB6, 0x76, 0xDA, 0x7D, 0x7F, 0x44,
  34862. 0xAD, 0x6B, 0xB9, 0xB0, 0x70, 0xD3, 0xD6, 0x44,
  34863. 0x7F, 0xBE, 0x6C, 0x0C, 0x71, 0x37, 0xC6, 0xFB,
  34864. 0x7B, 0x39, 0x83, 0x63, 0x9C, 0x41, 0x5C, 0xF2,
  34865. 0xC9, 0x15, 0xFF, 0xD4, 0x18, 0xEA, 0xA1, 0x4D,
  34866. 0xA9, 0xD1, 0xAD, 0x3C, 0x09, 0x8E, 0xA9, 0x05,
  34867. 0x34, 0x6C, 0xAA, 0x75, 0x78, 0xF8, 0x6B, 0x6E,
  34868. 0x52, 0xE6, 0x57, 0x55, 0x16, 0xF4, 0x92, 0x3E,
  34869. 0x74, 0x3F, 0x96, 0xA3, 0x2A, 0xD0, 0x0E, 0xEE,
  34870. 0xA1, 0xCE, 0x8A, 0x33, 0xF4, 0x87, 0xB9, 0xF3,
  34871. 0x22, 0x5D, 0x2D, 0x84, 0xCD, 0x27, 0x57, 0xCC,
  34872. 0xCF, 0xE6, 0xA3, 0x66, 0x24, 0x53, 0x0E, 0x52,
  34873. 0x8A, 0x2F, 0x64, 0xFC, 0xE7, 0x04, 0xE7, 0xA7,
  34874. 0x6C, 0x2E, 0x6A, 0xDC, 0x00, 0xEF, 0x9B, 0xEC,
  34875. 0x91, 0x07, 0xB9, 0x69, 0x8F, 0x11, 0x59, 0xFC,
  34876. 0x52, 0xEF, 0x4C, 0x36, 0x5A, 0xFD, 0xB1, 0x50,
  34877. 0xED, 0xC3, 0x43, 0x5E, 0x03, 0xBB, 0x70, 0x26,
  34878. 0x00, 0x6E, 0x5A, 0x55, 0x13, 0x51, 0xA4, 0xB1,
  34879. 0x5F, 0xB8, 0x9F, 0xD2, 0xE9, 0x98, 0x38, 0xE8,
  34880. 0xCF, 0x41, 0x73, 0xFD, 0x0D, 0xF1, 0xF6, 0x80,
  34881. 0x89, 0xE1, 0x51, 0x8D, 0xD4, 0xB5, 0x79, 0x27,
  34882. 0x76, 0xBD, 0xD9, 0x2F, 0xC7, 0xC7, 0x9B, 0xC7,
  34883. 0x99, 0x7F, 0x78, 0x84, 0xD2, 0xB8, 0x80, 0xC5,
  34884. 0xD2, 0xB7, 0xEE, 0xC8, 0x0A, 0xFE, 0x35, 0x59,
  34885. 0x84, 0x5D, 0x39, 0x08, 0x39, 0xBE, 0x5E, 0xBF,
  34886. 0x95, 0x93, 0xA7, 0x3E, 0xD0, 0x1E, 0xF6, 0x7D,
  34887. 0x50, 0x3F, 0xFB, 0x74, 0x47, 0x04, 0xA2, 0xDC,
  34888. 0x49, 0x48, 0x76, 0x2B, 0xC8, 0x43, 0x45, 0x75,
  34889. 0x72, 0x84, 0x4D, 0x15, 0x74, 0xE3, 0xEB, 0x37,
  34890. 0x83, 0x0A, 0x3B, 0x7C, 0xD4, 0x02, 0xC7, 0x6E,
  34891. 0xD5, 0xB4, 0xFC, 0x15, 0xF0, 0x5E, 0x76, 0x03,
  34892. 0x4C, 0xBB, 0x6A, 0x29, 0xDE, 0xBC, 0x7E, 0x2B,
  34893. 0x34, 0xB2, 0x14, 0x2A, 0x57, 0xCF, 0x1B, 0x39,
  34894. 0x73, 0xE5, 0x8B, 0xFF, 0x47, 0x50, 0x42, 0xDC,
  34895. 0x22, 0x6C, 0x7E, 0x13, 0x71, 0xF3, 0x37, 0x51,
  34896. 0x40, 0xF2, 0x90, 0x57, 0xAC, 0xB4, 0x64, 0x7C,
  34897. 0x5F, 0x92, 0x6D, 0x3F, 0xDC, 0xCC, 0xC8, 0xD2,
  34898. 0xE1, 0x6B, 0x81, 0xA9, 0xED, 0xCD, 0x0C, 0x8B,
  34899. 0x5B, 0x2E, 0x11, 0x89, 0x87, 0x42, 0x4B, 0xEC,
  34900. 0xAD, 0x40, 0xA5, 0xE5, 0xB4, 0x6D, 0x1C, 0xB4,
  34901. 0x01, 0x0A, 0x8E, 0x9F, 0x6F, 0x25, 0x92, 0x5D,
  34902. 0xFE, 0x6B, 0x6F, 0x24, 0x64, 0x5F, 0x9C, 0x88,
  34903. 0x86, 0x96, 0xE8, 0x79, 0x64, 0x5B, 0x6A, 0x3A,
  34904. 0x76, 0x21, 0x90, 0xCC, 0xB7, 0xD6, 0x26, 0x9D,
  34905. 0x35, 0x54, 0x79, 0xDF, 0x71, 0x90, 0x55, 0x2A,
  34906. 0x38, 0x52, 0xD1, 0xE9, 0x56, 0x73, 0xE7, 0x19,
  34907. 0x44, 0x6A, 0xD3, 0x10, 0x24, 0xB9, 0x4B, 0xF8,
  34908. 0xBB, 0xC9, 0x7B, 0x04, 0x66, 0x39, 0xCE, 0x12,
  34909. 0x3F, 0xDE, 0xC3, 0x75, 0xAF, 0x9F, 0x8D, 0x4C,
  34910. 0xF7, 0x16, 0x9B, 0xEB, 0x5F, 0xE5, 0x1B, 0xBF,
  34911. 0x82, 0x2C, 0x53, 0xBA, 0x2D, 0x98, 0xA4, 0xA0,
  34912. 0x14, 0xA2, 0xDE, 0x69, 0x7F, 0x03, 0x3C, 0x9E,
  34913. 0x4A, 0x57, 0xC6, 0xED, 0xF6, 0x10, 0x6A, 0x76,
  34914. 0x2A, 0x81, 0x92, 0x9F, 0x3E, 0xF0, 0xFD, 0xE9,
  34915. 0xB7, 0xB3, 0x8A, 0xF6, 0x1A, 0x19, 0x9A, 0x16,
  34916. 0x0F, 0x09, 0x45, 0xBD, 0xBB, 0x96, 0x7C, 0x72,
  34917. 0x40, 0xFE, 0x94, 0xBD, 0xE1, 0x60, 0x50, 0x53,
  34918. 0x13, 0xC9, 0x2B, 0xFA, 0x52, 0x40, 0xA2, 0xA7,
  34919. 0xF0, 0x8C, 0x85, 0x78, 0xDB, 0xD6, 0x7F, 0x21,
  34920. 0x39, 0xB5, 0x06, 0x72, 0xEE, 0x99, 0xA1, 0xBD,
  34921. 0x78, 0x1F, 0xA4, 0xE9, 0x54, 0xF4, 0xFA, 0xDF,
  34922. 0xA7, 0x9E, 0xDD, 0x8E, 0xB1, 0xCF, 0xA8, 0x48,
  34923. 0x84, 0x5D, 0x70, 0xCB, 0x2D, 0xA9, 0x66, 0x09,
  34924. 0x0B, 0x75, 0x75, 0xA2, 0x32, 0xFE, 0xDF, 0x96,
  34925. 0x33, 0x84, 0xA7, 0x84, 0x48, 0x1A, 0xFA, 0x82,
  34926. 0x79, 0x0A, 0x87, 0xE1, 0x1F, 0x11, 0x74, 0xD4,
  34927. 0x3C, 0xC0, 0x8D, 0x4F, 0xD2, 0x5D, 0xBB, 0x40,
  34928. 0x10, 0xB2, 0x6F, 0x23, 0xD2, 0xD6, 0xF4, 0xA5,
  34929. 0x87, 0xEF, 0x7D, 0xE8, 0xC6, 0xF7, 0xC6, 0x0F,
  34930. 0xF9, 0x6F, 0xF8, 0x4C, 0x39, 0xE4, 0x82, 0x1E,
  34931. 0x1E, 0x6A, 0x80, 0x2F, 0xEC, 0x22, 0xD6, 0xA0,
  34932. 0xAA, 0xB6, 0x2C, 0xCB, 0x16, 0x43, 0x68, 0xC2,
  34933. 0x27, 0xF6, 0xA2, 0x31, 0x62, 0x66, 0xEC, 0x2F,
  34934. 0xFF, 0x8D, 0xB4, 0x19, 0x51, 0x19, 0xA0, 0x8C,
  34935. 0x67, 0xE2, 0x04, 0x04, 0xB9, 0x1F, 0x08, 0x70,
  34936. 0x9E, 0xAA, 0xC2, 0xDE, 0xCB, 0x96, 0x19, 0x8F,
  34937. 0x02, 0x74, 0x10, 0xCC, 0x1B, 0x82, 0x5D, 0x9C,
  34938. 0x07, 0x00, 0xE5, 0xD7, 0x04, 0x51, 0xBA, 0x7F,
  34939. 0x67, 0xF9, 0x64, 0x0C, 0xA3, 0x6B, 0xF3, 0x12,
  34940. 0x21, 0x80, 0x68, 0xD6, 0xA2, 0xCA, 0xFF, 0x59,
  34941. 0x33, 0x43, 0x7D, 0x67, 0xBF, 0xD4, 0x88, 0x4A,
  34942. 0x6E, 0x92, 0xBA, 0x41, 0xE1, 0x28, 0xDA, 0xEB,
  34943. 0xE1, 0xEA, 0x25, 0x60, 0xE1, 0x2F, 0xED, 0x2C,
  34944. 0xD4, 0x4B, 0xC9, 0x4E, 0x9E, 0x9D, 0xFA, 0xBB,
  34945. 0xF9, 0x61, 0x41, 0x4C, 0x24, 0x24, 0xFC, 0x9B,
  34946. 0x62, 0xFE, 0x73, 0x74, 0xF6, 0xB8, 0x9B, 0xA9,
  34947. 0x02, 0x96, 0xF4, 0x90, 0x18, 0xA7, 0xF5, 0x49,
  34948. 0xC1, 0xA3, 0x94, 0xB8, 0xED, 0xBD, 0x0B, 0xF3,
  34949. 0xDB, 0xF3, 0xBC, 0x10, 0x6A, 0x6B, 0x3F, 0x79,
  34950. 0x07, 0xF2, 0x11, 0x09, 0xD5, 0x42, 0x8F, 0xA9,
  34951. 0x09, 0x94, 0xBE, 0xF2, 0x0D, 0x3A, 0x91, 0x33,
  34952. 0x01, 0x31, 0x34, 0xBF, 0x0A, 0xCA, 0xF1, 0x3E,
  34953. 0x66, 0x18, 0xA6, 0x69, 0xEC, 0xEA, 0xC5, 0xE9,
  34954. 0x8B, 0x80, 0xFE, 0x4D, 0x93, 0x7B, 0xD4, 0xE5,
  34955. 0x74, 0x90, 0xFA, 0xFD, 0xCE, 0x45, 0xE8, 0xD7,
  34956. 0xD8, 0x8F, 0x08, 0x8B, 0x3A, 0xA8, 0x01, 0xA2,
  34957. 0xB4, 0xE5, 0xF2, 0x29, 0x41, 0x02, 0xBD, 0xCB,
  34958. 0xF9, 0x4A, 0x62, 0x54, 0x99, 0x94, 0x61, 0xB7,
  34959. 0x8F, 0xA5, 0x8A, 0x7F, 0xDC, 0xAD, 0xD2, 0xF2,
  34960. 0x28, 0x1E, 0xF3, 0x18, 0xAE, 0x21, 0x81, 0xF7,
  34961. 0xE9, 0xE5, 0xBF, 0x2B, 0xC2, 0x98, 0x24, 0xB1,
  34962. 0x45, 0x56, 0x57, 0x31, 0xA1, 0x48, 0xAB, 0x39,
  34963. 0xC2, 0x04, 0x29, 0x1B, 0x5B, 0xD3, 0x23, 0x35,
  34964. 0xCC, 0x5A, 0x58, 0x10, 0x11, 0x5B, 0xD5, 0x88,
  34965. 0xC2, 0x60, 0x37, 0x3D, 0x1C, 0x1C, 0x7B, 0x09,
  34966. 0x95, 0xB5, 0x05, 0x12, 0xD8, 0x52, 0x8D, 0xF5,
  34967. 0xBD, 0x4A, 0xA5, 0x45, 0x6F, 0x3D, 0x55, 0x9D,
  34968. 0x90, 0xAD, 0xD7, 0xA9, 0xD0, 0x25, 0x0B, 0xD7,
  34969. 0x55, 0x11, 0x5C, 0x60, 0xBF, 0xBD, 0xFB, 0x9D,
  34970. 0x2A, 0xCE, 0x4F, 0xE6, 0xB8, 0x36, 0x3A, 0x4D,
  34971. 0xE7, 0xB6, 0xFF, 0x6B, 0xD8, 0xBA, 0xD4, 0xEE,
  34972. 0x95, 0x9A, 0x0A, 0x47, 0xD4, 0x76, 0xE0, 0xF7,
  34973. 0xAC, 0x02, 0xB6, 0xA8, 0x10, 0x1E, 0xA5, 0x98,
  34974. 0xC0, 0xF4, 0x68, 0x5E, 0x55, 0xC1, 0x67, 0xCD,
  34975. 0x16, 0x31, 0xBD, 0xA2, 0x86, 0xF3, 0xF8, 0xC0,
  34976. 0xED, 0x4A, 0xFF, 0xE8, 0xF5, 0x2C, 0xFA, 0xD2,
  34977. 0x06, 0x78, 0x6D, 0x34, 0xBE, 0xF9, 0x15, 0x84,
  34978. 0x6D, 0xE5, 0x5F, 0xA4, 0xAC, 0x84, 0x3B, 0x3A,
  34979. 0xA6, 0x2D, 0xC2, 0x01, 0xE0, 0x63, 0x92, 0xC7,
  34980. 0x77, 0xB5, 0x4E, 0x2C, 0x40, 0x90, 0x48, 0xAF,
  34981. 0x8B, 0xE9, 0x6C, 0x1E, 0xEE, 0x16, 0x8F, 0x4E,
  34982. 0x4F, 0xFF, 0x35, 0x15, 0xE5, 0x51, 0xF4, 0xB2,
  34983. 0x23, 0x1C, 0x6A, 0xCE, 0x05, 0xDC, 0xDC, 0xAD,
  34984. 0x7F, 0x9D, 0xDA, 0xB3, 0x0C, 0xAD, 0x9C, 0x62,
  34985. 0x68, 0xD6, 0x84, 0x00, 0x76, 0xFF, 0xD3, 0x01,
  34986. 0x18, 0xB0, 0xC4, 0xE5, 0xE5, 0x0D, 0x87, 0x8E,
  34987. 0xAF, 0x77, 0xEE, 0xCB, 0x56, 0x88, 0x7F, 0xED,
  34988. 0xC5, 0x7C, 0x54, 0xD6, 0x28, 0x46, 0xE0, 0x8C,
  34989. 0xE6, 0x87, 0xF2, 0x4D, 0x0D, 0x2F, 0x12, 0x62,
  34990. 0x06, 0xDF, 0xB2, 0x4E, 0x03, 0x04, 0x78, 0x0B,
  34991. 0x03, 0x4C, 0xCE, 0x86, 0xD1, 0xCD, 0x53, 0x00,
  34992. 0xED, 0xC6, 0xF8, 0x9A, 0xCB, 0x59, 0x14, 0xA6,
  34993. 0x0C, 0x87, 0x35, 0x92, 0x66, 0x0D, 0x02, 0xA9,
  34994. 0xEF, 0x0D, 0x7D, 0xC6, 0x45, 0xF3, 0x11, 0xEF,
  34995. 0x1F, 0x55, 0x72, 0x1F, 0x1B, 0x45, 0xD2, 0xE4,
  34996. 0x8F, 0x3F, 0x9F, 0xEB, 0x27, 0x02, 0xD8, 0x2C,
  34997. 0xEF, 0xAD, 0x7E, 0x7E, 0x10, 0xDD, 0x91, 0x5E,
  34998. 0x39, 0x06, 0x7C, 0x39, 0xEA, 0x61, 0xB9, 0xCC,
  34999. 0xF1, 0x45, 0x56, 0x81, 0x53, 0x55, 0x42, 0xD4,
  35000. 0x37, 0x0F, 0x53, 0xF0, 0x7F, 0xA0, 0xC6, 0x50,
  35001. 0x9B, 0x1D, 0xC6, 0x7E, 0x9F, 0x1D, 0x89, 0x3B,
  35002. 0xEB, 0x85, 0x59, 0x6D, 0x9C, 0x12, 0xEE, 0xAC,
  35003. 0xFC, 0xAE, 0xC0, 0xAE, 0x5F, 0xD4, 0x9C, 0x62,
  35004. 0xE7, 0x09, 0x8C, 0xFA, 0x80, 0x1A, 0x19, 0x09,
  35005. 0x0F, 0x8D, 0x68, 0x9E, 0x45, 0x33, 0xE2, 0x58,
  35006. 0x7B, 0xEF, 0xC7, 0x6A, 0xDC, 0x38, 0x33, 0x3E,
  35007. 0x5C, 0x53, 0xB5, 0x99, 0xDB, 0x04, 0xA7, 0xEA,
  35008. 0xFB, 0x07, 0x9B, 0x25, 0x47, 0xED, 0xAC, 0x5A,
  35009. 0xAA, 0x1E, 0xE5, 0x23, 0xDE, 0x64, 0xE5, 0x87,
  35010. 0x46, 0x8C, 0x41, 0x52, 0xC9, 0x4F, 0x90, 0x48,
  35011. 0x1C, 0xAA, 0xA6, 0xB0, 0x3A, 0x1E, 0xC9, 0x08,
  35012. 0xF7, 0x82, 0x71, 0x13, 0x76, 0x6B, 0x9E, 0x52,
  35013. 0x22, 0x32, 0xE0, 0xC6, 0xF7, 0xD7, 0x4C, 0xBD,
  35014. 0xC3, 0x1C, 0x18, 0xAF, 0xA0, 0x12, 0xD3, 0x22,
  35015. 0x6A, 0xFC, 0x71, 0x8A, 0x64, 0x24, 0xAC, 0x19,
  35016. 0x4E, 0x85, 0x3C, 0x51, 0xE6, 0xA3, 0xAD, 0xA9,
  35017. 0x59, 0x94, 0xD2, 0x7F, 0xC4, 0x9D, 0x93, 0x5B,
  35018. 0x51, 0xD7, 0xF3, 0x03, 0xE7, 0x7D, 0x5B, 0x13,
  35019. 0x0E, 0xCD, 0x7D, 0x0F, 0x77, 0x3E, 0x84, 0xD7,
  35020. 0x4E, 0x69, 0x57, 0x1B, 0x73, 0x99, 0xC9, 0x4D,
  35021. 0xC0, 0x19, 0x6B, 0x9D, 0x5F, 0xBA, 0x69, 0xEE,
  35022. 0x11, 0xBD, 0x7C, 0x45, 0xD9, 0xA9, 0x65, 0x88,
  35023. 0xA7, 0x0E, 0x16, 0xBF, 0xB3, 0x82, 0x5E, 0x5E,
  35024. 0x56, 0x13, 0x02, 0x7D, 0xB1, 0xDC, 0xF5, 0x4A,
  35025. 0x82, 0x73, 0x72, 0x35, 0x9B, 0x91, 0xAC, 0x04,
  35026. 0x69, 0xE9, 0xEA, 0x19, 0xC9, 0xD8, 0x59, 0xEB,
  35027. 0x8F, 0x22, 0x5F, 0x43, 0x11, 0x0C, 0xCF, 0xB4,
  35028. 0x16, 0x6C, 0x7D, 0x60, 0xCE, 0x14, 0x24, 0xAD,
  35029. 0xD7, 0x07, 0xC2, 0x4E, 0x98, 0xA0, 0xDE, 0x9E,
  35030. 0xE6, 0x31, 0xED, 0xF8, 0x5B, 0x9C, 0xAF, 0xF7,
  35031. 0x57, 0x59, 0x10, 0xA9, 0x92, 0xDC, 0x4F, 0x0C,
  35032. 0x2B, 0x88, 0x75, 0x19, 0x1D, 0xB3, 0xBF, 0x70,
  35033. 0x23, 0x17, 0xD5, 0x1A, 0x50, 0x30, 0x18, 0x14,
  35034. 0x1A, 0x14, 0xE6, 0x1D, 0x4F, 0x8A, 0x96, 0x3E,
  35035. 0xD8, 0x6E, 0xD9, 0xBF, 0x94, 0x4E, 0xDE, 0xB8,
  35036. 0xFF, 0xE1, 0x6F, 0xFD, 0x31, 0xE8, 0xFE, 0x43,
  35037. 0xC2, 0x40, 0x82, 0x45, 0x50, 0xFE, 0x1B, 0xBC,
  35038. 0x77, 0x4B, 0xB4, 0x30, 0xA7, 0xD4, 0x46, 0x32,
  35039. 0x6A, 0xF7, 0xC5, 0x92, 0xDA, 0x70, 0xB1, 0xB7,
  35040. 0xA1, 0x5A, 0x5D, 0x17, 0x3B, 0xDB, 0x2F, 0x28,
  35041. 0x8A, 0x6E, 0xEC, 0xDA, 0xC4, 0xF7, 0x2E, 0xCB,
  35042. 0xEB, 0x96, 0x60, 0x92, 0x1B, 0xDD, 0xD6, 0x13,
  35043. 0x7C, 0x85, 0x9F, 0x8A, 0x9A, 0xE9, 0x5F, 0xC4,
  35044. 0x24, 0xFD, 0x33, 0xDF, 0xB3, 0x98, 0x66, 0xF7,
  35045. 0xA1, 0x5A, 0xDC, 0x01, 0xC9, 0xFA, 0x37, 0xF1,
  35046. 0x7B, 0xD0, 0xF6, 0x66, 0x8A, 0x26, 0x7C, 0xC2,
  35047. 0x1B, 0xFF, 0x62, 0xBC, 0xFD, 0xCD, 0x47, 0xDA,
  35048. 0xEE, 0x75, 0xF2, 0xAC, 0x60, 0x69, 0x87, 0x26,
  35049. 0xCC, 0x92, 0x10, 0x1C, 0x92, 0xC1, 0x43, 0x09,
  35050. 0xE9, 0xCE, 0x7D, 0x05, 0x5C, 0x64, 0x55, 0xCB,
  35051. 0xBB, 0x7A, 0xAE, 0x05, 0xDB, 0x38, 0xD3, 0xD5,
  35052. 0xBB, 0xD9, 0x9F, 0xCB, 0xCF, 0xB7, 0x9C, 0xEF,
  35053. 0x7E, 0x7B, 0x2A, 0x6F, 0x84, 0x4E, 0x6A, 0x7F,
  35054. 0xD3, 0x5F, 0xF3, 0xB3, 0xC1, 0xF0, 0x02, 0x9C,
  35055. 0xA2, 0x4C, 0x86, 0x0E, 0x6B, 0xE2, 0x2B, 0x1D,
  35056. 0x1D, 0xB4, 0x55, 0x7F, 0x85, 0x54, 0x2D, 0x85,
  35057. 0x64, 0x89, 0x92, 0x19, 0x65, 0x44, 0xD7, 0x95,
  35058. 0x48, 0x2C, 0x46, 0x8D, 0x0E, 0xBA, 0xFB, 0x13,
  35059. 0x63, 0x52, 0x2E, 0x22, 0x19, 0x3F, 0x7F, 0xFB,
  35060. 0x54, 0x4D, 0x73, 0xA1, 0x3C, 0x22, 0xD6, 0x5D,
  35061. 0x2B, 0x4A, 0xBD, 0xD7, 0xBB, 0x72, 0x55, 0x80,
  35062. 0xD4, 0x57, 0x4E, 0xDC, 0xF2, 0x8B, 0xB3, 0x09,
  35063. 0x6A, 0xF9, 0x1A, 0xD3, 0x41, 0x0E, 0x72, 0x95,
  35064. 0x49, 0xE7, 0xD1, 0xDC, 0x05, 0x22, 0xC3, 0x3E,
  35065. 0x26, 0x95, 0x00, 0x01, 0x8C, 0xE1, 0x54, 0x47,
  35066. 0x84, 0x10, 0xA7, 0x67, 0x45, 0xBB, 0xB9, 0x7B,
  35067. 0x0B, 0xB4, 0x74, 0x82, 0xED, 0x6C, 0x26, 0x6E,
  35068. 0xF2, 0x56, 0xCA, 0x1A, 0xD1, 0x10, 0x68, 0x40,
  35069. 0x28, 0x23, 0xD5, 0x98, 0xB3, 0x6B, 0x75, 0x16,
  35070. 0x13, 0x87, 0xE1, 0xF2, 0x3F, 0xAB, 0xC0, 0x2A,
  35071. 0xF0, 0x16, 0x59, 0x85, 0x1A, 0x5B, 0x41, 0xB7,
  35072. 0x52, 0xB1, 0x79, 0x46, 0x20, 0xDF, 0x59, 0xFB,
  35073. 0x33, 0xB3, 0x05, 0xF1, 0x12, 0x8B, 0xDB, 0x7C,
  35074. 0x51, 0x90, 0xC9, 0x8A, 0xC9, 0x48, 0x10, 0x54,
  35075. 0xF4, 0x0F, 0x88, 0x1D, 0xDB, 0x40, 0x1B, 0x3A,
  35076. 0xD7, 0x62, 0xD1, 0x75, 0x73, 0xD6, 0xCA, 0x23,
  35077. 0x26, 0xB2, 0xBF, 0x4C, 0xCA, 0x22, 0xDD, 0xF6,
  35078. 0xAF, 0x22, 0xB8, 0x4F, 0xC2, 0xC3, 0xB3, 0xD3,
  35079. 0xED, 0xFA, 0xBA, 0x2E, 0x38, 0x28, 0x6A, 0xAE,
  35080. 0x60, 0xE9, 0x2D, 0x11, 0x33, 0xED, 0x7E, 0xE9,
  35081. 0x29, 0x8E, 0x01, 0xB0, 0x0F, 0x13, 0x83, 0x44,
  35082. 0x17, 0xFA, 0xB6, 0x54, 0x7C, 0xAC, 0x1F, 0xED,
  35083. 0xC9, 0x22, 0xF2, 0x4F, 0x69, 0x24, 0x04, 0xFE,
  35084. 0xC2, 0x6A, 0xEB, 0xB0, 0xE4, 0xF5, 0x03, 0xCB,
  35085. 0xB3, 0x99, 0x50, 0x66, 0x1F, 0x6B, 0xF3, 0xFE,
  35086. 0xB7, 0xBF, 0x8D, 0xBA, 0x59, 0x75, 0x75, 0x51,
  35087. 0xB0, 0xA5, 0xB9, 0x66, 0xC8, 0xDD, 0x35, 0xAE,
  35088. 0x20, 0x66, 0x21, 0x9B, 0x04, 0x3F, 0xC6, 0x90,
  35089. 0x6F, 0x2B, 0x5C, 0x78, 0x49, 0x3C, 0x40, 0xE6,
  35090. 0xF9, 0x6B, 0x1A, 0xEF, 0xCE, 0x5A, 0xC1, 0x68,
  35091. 0xD3, 0x34, 0x05, 0xD0, 0x21, 0x6C, 0xF8, 0xA8,
  35092. 0x55, 0xE4, 0x6E, 0x80, 0x9B, 0xAD, 0xA5, 0xC3,
  35093. 0x55, 0x0B, 0x28, 0xBB, 0x54, 0x02, 0xD4, 0xF6,
  35094. 0x82, 0x73, 0xAB, 0x56, 0x0B, 0xB1, 0x5F, 0x94,
  35095. 0xC3, 0xDA, 0x24, 0x1E, 0x7F, 0x62, 0x6B, 0x98,
  35096. 0x6B, 0x2A, 0xF3, 0x92, 0x37, 0x3A, 0xB9, 0xE6,
  35097. 0x27, 0xC4, 0xBB, 0xAB, 0xE4, 0x9A, 0x60, 0xD2,
  35098. 0xAE, 0xCE, 0xFD, 0x44, 0xEB, 0x1C, 0xCF, 0x74,
  35099. 0x54, 0xFC, 0xEC, 0x4F, 0xC2, 0xBA, 0xF4, 0x3B,
  35100. 0xAC, 0x03, 0xC7, 0x2E, 0xE6, 0x62, 0x44, 0x61,
  35101. 0x42, 0xC8, 0xAE, 0xF1, 0xB2, 0xA9, 0xAC, 0xE0,
  35102. 0xCE, 0x23, 0xAF, 0xCC, 0x86, 0x61, 0xFE, 0xC5,
  35103. 0xCB, 0xAC, 0x4A, 0x1B, 0x5C, 0xC7, 0x2B, 0xFF,
  35104. 0x8A, 0x20, 0x62, 0x0E, 0xB9, 0x1D, 0xDD, 0x93,
  35105. 0x19, 0x29, 0xE4, 0xD9, 0x13, 0x1D, 0x28, 0x32,
  35106. 0x03, 0x5A, 0xA6, 0x8E, 0x20, 0xC7, 0xD6, 0xC6,
  35107. 0x4D, 0x19, 0x17, 0xCC, 0x65, 0xB8, 0x84, 0x0C,
  35108. 0x38, 0xB4, 0xA9, 0x45, 0x2B, 0x91, 0x61, 0x79,
  35109. 0x87, 0x08, 0xA6, 0xBD, 0x28, 0x9A, 0x58, 0x48,
  35110. 0xD5, 0x58, 0xC6, 0xCE, 0xC2, 0xC5, 0x72, 0x16,
  35111. 0xD9, 0xF4, 0xED, 0x66, 0xAC, 0xFA, 0x93, 0xE8,
  35112. 0x26, 0x10, 0x3B, 0x3D, 0x8F, 0xEA, 0x51, 0xCC,
  35113. 0x82, 0xC0, 0xDB, 0xDF, 0xA7, 0x13, 0xFB, 0x1B,
  35114. 0x77, 0x7E, 0x6F, 0x9E, 0x3C, 0xC5, 0x86, 0x35,
  35115. 0x92, 0x5B, 0x6F, 0x76, 0xA1, 0x71, 0x0D, 0x8C,
  35116. 0xDC, 0x95, 0x9F, 0xAC, 0x2C, 0x8E, 0x21, 0x01,
  35117. 0x37, 0x06, 0x28, 0x64, 0x4C, 0x23, 0xE2, 0x75,
  35118. 0x0B, 0xA7, 0xA4, 0xF5, 0x90, 0x87, 0xD2, 0x43,
  35119. 0x71, 0x59, 0x7C, 0x8C, 0xCA, 0x77, 0x3B, 0xC5,
  35120. 0x36, 0x46, 0xF7, 0x2F, 0xD3, 0x47, 0x18, 0xD7,
  35121. 0xC9, 0x4E, 0x56, 0x2D, 0x49, 0x82, 0xAC, 0x7D,
  35122. 0xD7, 0x3D, 0xF1, 0xDD, 0x73, 0x8B, 0xE4, 0xA1,
  35123. 0x10, 0x85, 0xB6, 0x94, 0xBE, 0x6A, 0x5E, 0xEE,
  35124. 0xBD, 0x60, 0xEB, 0x95, 0x76, 0xA8, 0x52, 0xE1,
  35125. 0x47, 0x57, 0xA1, 0x9C, 0xEC, 0x44, 0xE5, 0x6F,
  35126. 0x68, 0x34, 0x7E, 0x19, 0xBE, 0xCE, 0x56, 0xC9,
  35127. 0xBE, 0xCE, 0xFC, 0xB8, 0x32, 0x6D, 0xCB, 0x84,
  35128. 0x59, 0xBF, 0x4D, 0xF6, 0xE1, 0x53, 0x41, 0x61,
  35129. 0x5C, 0xFB, 0xD2, 0x48, 0xA6, 0x7F, 0x05, 0xB2,
  35130. 0xFC, 0xE8, 0xB2, 0x8A, 0x55, 0x7D, 0x19, 0xC0,
  35131. 0x69, 0x3B, 0x91, 0x5D, 0x71, 0xE7, 0xBB, 0x72,
  35132. 0x7D, 0xB9, 0x64, 0x6E, 0x8B, 0x5B, 0x70, 0x51,
  35133. 0xB5, 0x69, 0x8C, 0xC0, 0xFC, 0x95, 0xB2, 0x43,
  35134. 0x08, 0xF8, 0x70, 0xE4, 0x6F, 0x87, 0xA7, 0xDF,
  35135. 0x23, 0x84, 0xEE, 0xCF, 0x73, 0x38, 0xDE, 0x99,
  35136. 0x4C, 0xF8, 0xF1, 0x2D, 0xA2, 0x68, 0x99, 0xE3,
  35137. 0x9B, 0xB8, 0xF6, 0xC1, 0x5C, 0x83, 0x07, 0xE9,
  35138. 0xB9, 0xE2, 0x51, 0x62, 0xC8, 0x53, 0xF1, 0xC2,
  35139. 0xF7, 0x57, 0x8A, 0xA0, 0x42, 0x3C, 0x18, 0x36,
  35140. 0xF3, 0x99, 0xFD, 0x34, 0xB2, 0xF0, 0x1D, 0xBA,
  35141. 0x43, 0xEA, 0x72, 0x1C, 0x0B, 0x37, 0x47, 0xBC,
  35142. 0xAF, 0xDA, 0x22, 0x1F, 0x1C, 0x08, 0x16, 0x13,
  35143. 0xBD, 0xAA, 0x07, 0xFD, 0x7E, 0xCA, 0x70, 0x57,
  35144. 0x74, 0xDF, 0x68, 0x6B, 0x9F, 0x2D, 0x56, 0xBD,
  35145. 0x21, 0x89, 0xFA, 0x09, 0x04, 0xCA, 0x09, 0xBD,
  35146. 0x4F, 0xE6, 0x15, 0xF5, 0x89, 0xAB, 0xAC, 0xB2,
  35147. 0xC9, 0xBF, 0xC8, 0xBB, 0x87, 0x83, 0xB4, 0xD3,
  35148. 0xDC, 0xB1, 0x25, 0x9B, 0xAE, 0xC5, 0x75, 0x0C,
  35149. 0x9E, 0x6A, 0x83, 0x41, 0x85, 0x9D, 0x4B, 0xBF,
  35150. 0x62, 0x0C, 0x7D, 0x77, 0xC9, 0x89, 0xA6, 0xE1,
  35151. 0x28, 0xBD, 0x13, 0x5D, 0x41, 0x26, 0x80, 0x75,
  35152. 0x23, 0x57, 0xE7, 0x4F, 0x4D, 0x02, 0x8E, 0x0F,
  35153. 0x43, 0x67, 0xF6, 0xA6, 0xE6, 0xB6, 0x84, 0x8D,
  35154. 0xF5, 0x7B, 0x6A, 0x95, 0x73, 0x27, 0x86, 0x02,
  35155. 0x72, 0xCB, 0xDF, 0x77, 0x1C, 0x6C, 0x5E, 0xD3,
  35156. 0xF0, 0x1C, 0x82, 0x7A, 0x0D, 0xBB, 0x70, 0xA3,
  35157. 0x98, 0x8B, 0x7B, 0x4A, 0xFE, 0x2D, 0xB1, 0x5C,
  35158. 0x61, 0x89, 0x34, 0x4C, 0x81, 0x4B, 0x52, 0x17,
  35159. 0x03, 0x81, 0x54, 0x4F, 0x9E, 0x9E, 0x07, 0x16,
  35160. 0xF3, 0xD9, 0x18, 0x01, 0x11, 0xFD, 0x67, 0x18,
  35161. 0xA2, 0x64, 0x35, 0x42, 0x81, 0x80, 0x4A, 0xBA,
  35162. 0xCB, 0xD5, 0xF5, 0x4A, 0x10, 0x7F, 0xE2, 0xCF,
  35163. 0xA5, 0x1E, 0xCB, 0x0C, 0xAB, 0x3E, 0x03, 0x98,
  35164. 0x73, 0x89, 0xA4, 0x10, 0x75, 0xD5, 0xAC, 0x3D,
  35165. 0xCF, 0x56, 0x75, 0xD8, 0x86, 0xC2, 0x21, 0x42,
  35166. 0x99, 0x8D, 0x1B, 0x49, 0x09, 0xFE, 0x86, 0x41,
  35167. 0xC9, 0xDC, 0x87, 0x8D, 0x5A, 0xF0, 0xF5, 0xBE,
  35168. 0xF5, 0x49, 0x64, 0x5A, 0x7A, 0xC3, 0x5D, 0xE4,
  35169. 0xD6, 0xB7, 0x30, 0x92, 0x2A, 0x15, 0x86, 0x02,
  35170. 0xBE, 0xBA, 0x6E, 0xF6, 0x3D, 0x2D, 0x70, 0x89,
  35171. 0xFB, 0xB5, 0x1E, 0xBA, 0xDA, 0x20, 0x12, 0x49,
  35172. 0x22, 0xA0, 0xD8, 0x33, 0x9E, 0x4C, 0xC0, 0x27,
  35173. 0x0F, 0x9C, 0x1F, 0xD2, 0xA9, 0xF4, 0xD2, 0xA9,
  35174. 0x6D, 0xC5, 0x32, 0x16, 0x35, 0x9F, 0x19, 0x88,
  35175. 0xC1, 0xAA, 0xA4, 0x66, 0x33, 0xE6, 0x2C, 0x6A,
  35176. 0x6E, 0xA2, 0x1B, 0x33, 0xCB, 0xC3, 0x7E, 0xC5,
  35177. 0x31, 0x4D, 0x5C, 0x17, 0x4C, 0x33, 0x7F, 0x09,
  35178. 0x01, 0x33, 0x82, 0x84, 0x37, 0x03, 0xEB, 0x0E,
  35179. 0xB1, 0x5F, 0x1B, 0x60, 0x8A, 0x2C, 0x9F, 0x39
  35180. };
  35181. static const byte sk_87_draft[] = {
  35182. 0x8C, 0x52, 0x4B, 0xD9, 0xAC, 0x48, 0x5C, 0xC6,
  35183. 0x9A, 0xA0, 0x75, 0x64, 0xE1, 0x4F, 0x0F, 0x60,
  35184. 0x13, 0x0E, 0xDE, 0x34, 0x08, 0xA5, 0xD4, 0x81,
  35185. 0xFD, 0x76, 0xC2, 0x51, 0x74, 0x75, 0xA8, 0xFB,
  35186. 0x9A, 0xFE, 0xF5, 0x92, 0x58, 0xBB, 0x3C, 0xEB,
  35187. 0x4C, 0x5E, 0x83, 0xF9, 0xFF, 0xBC, 0x3B, 0x49,
  35188. 0xAE, 0xE1, 0xFC, 0x4B, 0x94, 0x4B, 0x8C, 0x75,
  35189. 0xD4, 0x67, 0x75, 0x66, 0x7D, 0x6B, 0xA4, 0xF2,
  35190. 0xDA, 0xC2, 0xB7, 0xC4, 0xD8, 0x50, 0x25, 0xCB,
  35191. 0x5A, 0xDB, 0xA4, 0xAD, 0xBB, 0x44, 0x20, 0x24,
  35192. 0x90, 0xEA, 0xA5, 0x2C, 0xAE, 0x80, 0x22, 0xC9,
  35193. 0x59, 0x02, 0xB7, 0x10, 0xB0, 0x5E, 0x1E, 0x5F,
  35194. 0x52, 0x7D, 0x88, 0xDA, 0xE2, 0x04, 0xBF, 0x45,
  35195. 0xA7, 0xA8, 0x49, 0x97, 0x7D, 0xAD, 0x7C, 0x7C,
  35196. 0x9E, 0x9C, 0x4A, 0xCC, 0x36, 0x33, 0x0F, 0x30,
  35197. 0xFA, 0xDE, 0x52, 0xE9, 0xAE, 0x23, 0x29, 0x13,
  35198. 0x10, 0x17, 0x8A, 0xD0, 0x08, 0x8E, 0xE1, 0x10,
  35199. 0x30, 0xD0, 0x84, 0x65, 0x92, 0x12, 0x2A, 0x81,
  35200. 0x26, 0x2E, 0x11, 0x14, 0x30, 0x61, 0x38, 0x61,
  35201. 0x64, 0x42, 0x05, 0x08, 0x91, 0x90, 0x4C, 0x06,
  35202. 0x82, 0xCC, 0x90, 0x45, 0x10, 0x39, 0x90, 0x22,
  35203. 0x40, 0x2A, 0x9B, 0x16, 0x26, 0x9A, 0xA8, 0x50,
  35204. 0x91, 0x12, 0x70, 0x91, 0x20, 0x4D, 0xC0, 0x34,
  35205. 0x90, 0x18, 0x28, 0x31, 0x10, 0x02, 0x11, 0x22,
  35206. 0xB3, 0x6C, 0x8B, 0xB8, 0x2C, 0x22, 0xB0, 0x69,
  35207. 0x53, 0x36, 0x31, 0x61, 0x42, 0x6C, 0xD9, 0x06,
  35208. 0x6A, 0xD9, 0x04, 0x45, 0xDB, 0x18, 0x05, 0x12,
  35209. 0x37, 0x4A, 0xD4, 0x06, 0x64, 0xD3, 0xA2, 0x85,
  35210. 0xA0, 0x38, 0x8A, 0x14, 0xA5, 0x85, 0x50, 0x20,
  35211. 0x85, 0xE4, 0xA8, 0x24, 0xC3, 0xC6, 0x31, 0xC9,
  35212. 0x34, 0x4E, 0xD2, 0x14, 0x68, 0x82, 0x90, 0x85,
  35213. 0xC4, 0x02, 0x61, 0x24, 0x38, 0x05, 0x01, 0xA3,
  35214. 0x50, 0x48, 0x08, 0x62, 0x20, 0xB0, 0x25, 0x5B,
  35215. 0xA6, 0x4D, 0x98, 0x92, 0x11, 0xC2, 0x06, 0x00,
  35216. 0xD1, 0xB0, 0x4D, 0x21, 0xA4, 0x8C, 0x01, 0x16,
  35217. 0x72, 0x11, 0xA6, 0x20, 0xD0, 0x16, 0x45, 0x10,
  35218. 0x31, 0x8E, 0xCB, 0xC2, 0x69, 0x02, 0x08, 0x91,
  35219. 0xD4, 0x30, 0x89, 0x03, 0x41, 0x05, 0x93, 0x16,
  35220. 0x8E, 0x5A, 0x18, 0x04, 0x41, 0x10, 0x6D, 0x18,
  35221. 0x42, 0x70, 0x53, 0x16, 0x31, 0x52, 0x30, 0x8E,
  35222. 0x0C, 0x49, 0x66, 0x0C, 0x90, 0x0C, 0xA4, 0x08,
  35223. 0x2E, 0x41, 0x92, 0x05, 0x24, 0x07, 0x30, 0x12,
  35224. 0x46, 0x72, 0x13, 0x99, 0x20, 0xE0, 0xA2, 0x4C,
  35225. 0x1B, 0x14, 0x52, 0x5A, 0x90, 0x05, 0x08, 0x82,
  35226. 0x31, 0x53, 0xC2, 0x90, 0xCC, 0x42, 0x68, 0x18,
  35227. 0xB0, 0x2C, 0x00, 0x80, 0x65, 0x58, 0x12, 0x84,
  35228. 0x19, 0x90, 0x08, 0x44, 0x26, 0x4A, 0x10, 0xA9,
  35229. 0x0C, 0x12, 0x25, 0x0C, 0x9C, 0x10, 0x25, 0x0C,
  35230. 0x28, 0x25, 0xD8, 0x46, 0x84, 0x1A, 0x22, 0x71,
  35231. 0x5B, 0x28, 0x6E, 0x98, 0x02, 0x51, 0x61, 0xB4,
  35232. 0x51, 0x01, 0xA1, 0x21, 0x24, 0x39, 0x12, 0xC8,
  35233. 0x08, 0x85, 0xD1, 0x34, 0x64, 0xA4, 0xA8, 0x04,
  35234. 0xA2, 0xC0, 0x09, 0x44, 0x48, 0x48, 0x03, 0x37,
  35235. 0x00, 0x20, 0x05, 0x4D, 0x20, 0xA4, 0x05, 0x11,
  35236. 0x18, 0x82, 0x42, 0x94, 0x4D, 0x24, 0x16, 0x01,
  35237. 0x02, 0x93, 0x4C, 0x00, 0x16, 0x06, 0xC1, 0xC0,
  35238. 0x0C, 0x8B, 0xC0, 0x41, 0x41, 0x06, 0x42, 0xA3,
  35239. 0xC6, 0x64, 0x1A, 0x85, 0x91, 0x41, 0x06, 0x49,
  35240. 0x04, 0xA7, 0x44, 0x82, 0x22, 0x6A, 0x50, 0x08,
  35241. 0x0E, 0x14, 0x18, 0x20, 0x4B, 0x88, 0x91, 0x01,
  35242. 0xA0, 0x49, 0x1A, 0x85, 0x4D, 0x94, 0x18, 0x10,
  35243. 0x0A, 0x05, 0x44, 0x94, 0x38, 0x05, 0x93, 0x40,
  35244. 0x68, 0x23, 0x07, 0x85, 0xE2, 0x12, 0x22, 0x9B,
  35245. 0xB8, 0x08, 0xD2, 0x10, 0x2A, 0x08, 0xA8, 0x10,
  35246. 0x92, 0x40, 0x2D, 0xD8, 0x44, 0x4C, 0xCC, 0x94,
  35247. 0x05, 0x24, 0x43, 0x4C, 0xD3, 0xC2, 0x48, 0x10,
  35248. 0x21, 0x2D, 0xC9, 0xB6, 0x08, 0xC9, 0x06, 0x4D,
  35249. 0xE1, 0x90, 0x20, 0x14, 0x24, 0x70, 0x5C, 0x84,
  35250. 0x28, 0xC0, 0xC2, 0x81, 0x22, 0x13, 0x50, 0x44,
  35251. 0x84, 0x91, 0xCA, 0xA2, 0x48, 0x12, 0x91, 0x05,
  35252. 0x5B, 0x92, 0x8D, 0x92, 0x92, 0x24, 0x82, 0x42,
  35253. 0x48, 0x03, 0x37, 0x46, 0xD8, 0x44, 0x86, 0x44,
  35254. 0x20, 0x89, 0xE4, 0xC2, 0x84, 0xC2, 0x04, 0x65,
  35255. 0x49, 0xA8, 0x4D, 0xA4, 0x38, 0x28, 0xDB, 0xA4,
  35256. 0x64, 0x24, 0x00, 0x51, 0xC8, 0x12, 0x6D, 0x19,
  35257. 0x82, 0x24, 0xCB, 0x00, 0x44, 0x4B, 0x20, 0x20,
  35258. 0x9B, 0x82, 0x4C, 0x5C, 0xA8, 0x08, 0xD2, 0xB6,
  35259. 0x8C, 0x08, 0x35, 0x20, 0xC0, 0x92, 0x45, 0xE3,
  35260. 0xB4, 0x2C, 0x50, 0x32, 0x0E, 0xD1, 0x82, 0x11,
  35261. 0x4A, 0x96, 0x08, 0x1C, 0x86, 0x29, 0x02, 0x19,
  35262. 0x71, 0x12, 0x03, 0x6E, 0x94, 0x08, 0x50, 0x12,
  35263. 0x27, 0x20, 0x0B, 0x10, 0x12, 0xA1, 0x18, 0x06,
  35264. 0x5A, 0x36, 0x4C, 0x93, 0xB4, 0x68, 0x21, 0xA7,
  35265. 0x28, 0x09, 0x34, 0x91, 0x18, 0x93, 0x49, 0x4A,
  35266. 0x32, 0x60, 0x00, 0x29, 0x2D, 0x94, 0x48, 0x44,
  35267. 0x09, 0x94, 0x2C, 0x21, 0x07, 0x6C, 0x41, 0x38,
  35268. 0x60, 0x8C, 0x10, 0x46, 0x11, 0x19, 0x65, 0x01,
  35269. 0x46, 0x60, 0x1A, 0x29, 0x42, 0x23, 0x30, 0x29,
  35270. 0x40, 0x96, 0x85, 0x81, 0xC6, 0x6C, 0x09, 0xA2,
  35271. 0x31, 0x23, 0xC9, 0x84, 0x18, 0x27, 0x61, 0x02,
  35272. 0xA6, 0x05, 0x1B, 0x11, 0x32, 0xD1, 0x80, 0x24,
  35273. 0x59, 0x22, 0x52, 0x21, 0x34, 0x64, 0x0A, 0x21,
  35274. 0x52, 0x10, 0xC2, 0x80, 0x5C, 0x98, 0x0D, 0x81,
  35275. 0xA0, 0x84, 0x14, 0x97, 0x04, 0xCC, 0xC2, 0x04,
  35276. 0x1A, 0x81, 0x45, 0x23, 0x44, 0x6C, 0x13, 0xC0,
  35277. 0x44, 0x59, 0xC2, 0x68, 0x64, 0x08, 0x52, 0x51,
  35278. 0x30, 0x71, 0x12, 0x49, 0x70, 0x12, 0x94, 0x84,
  35279. 0x80, 0x12, 0x12, 0x1B, 0x00, 0x50, 0x84, 0x10,
  35280. 0x45, 0x4A, 0x30, 0x10, 0x22, 0x95, 0x49, 0xC9,
  35281. 0x82, 0x24, 0x03, 0x35, 0x21, 0x18, 0x16, 0x72,
  35282. 0x09, 0x89, 0x65, 0x88, 0xB2, 0x89, 0x41, 0xB4,
  35283. 0x90, 0x92, 0x38, 0x8C, 0x08, 0x23, 0x26, 0x0B,
  35284. 0x80, 0x61, 0x84, 0x28, 0x6A, 0x4C, 0x98, 0x44,
  35285. 0x10, 0xB9, 0x30, 0x93, 0x02, 0x49, 0x22, 0x13,
  35286. 0x80, 0x1C, 0xC3, 0x48, 0x50, 0xA8, 0x20, 0x1C,
  35287. 0x05, 0x00, 0x5B, 0x02, 0x41, 0xD2, 0x84, 0x61,
  35288. 0x4B, 0x40, 0x46, 0x20, 0x21, 0x44, 0xD9, 0xC4,
  35289. 0x21, 0xD3, 0xA4, 0x4D, 0xC0, 0xC0, 0x09, 0x5B,
  35290. 0x28, 0x91, 0x18, 0x15, 0x41, 0x18, 0xC5, 0x4C,
  35291. 0x14, 0xB7, 0x61, 0xDB, 0x34, 0x25, 0x02, 0x06,
  35292. 0x41, 0x14, 0xA9, 0x65, 0x0B, 0x10, 0x04, 0x23,
  35293. 0xC7, 0x49, 0x13, 0x47, 0x0A, 0xD0, 0x30, 0x80,
  35294. 0x99, 0x32, 0x68, 0x50, 0x18, 0x06, 0xA2, 0x28,
  35295. 0x65, 0x13, 0x35, 0x82, 0xD3, 0x06, 0x81, 0x22,
  35296. 0x49, 0x4D, 0x48, 0x44, 0x30, 0xCA, 0x96, 0x2C,
  35297. 0x12, 0xC8, 0x08, 0xA1, 0x24, 0x2C, 0x52, 0xA8,
  35298. 0x28, 0x23, 0x14, 0x0A, 0xD4, 0x20, 0x4D, 0x18,
  35299. 0x12, 0x72, 0xD4, 0x80, 0x44, 0xDC, 0x26, 0x2C,
  35300. 0x88, 0x10, 0x0A, 0x04, 0x14, 0x51, 0xC1, 0x96,
  35301. 0x00, 0xA3, 0x40, 0x30, 0x99, 0x48, 0x92, 0x9B,
  35302. 0x08, 0x86, 0x81, 0x04, 0x20, 0x4C, 0xB2, 0x29,
  35303. 0x18, 0x31, 0x08, 0x09, 0x23, 0x8C, 0x4C, 0x02,
  35304. 0x6A, 0xCA, 0x00, 0x62, 0x09, 0x22, 0x2D, 0x21,
  35305. 0x00, 0x02, 0x0A, 0x39, 0x41, 0x04, 0xA3, 0x50,
  35306. 0x90, 0x80, 0x2D, 0x59, 0xB4, 0x71, 0x13, 0x16,
  35307. 0x31, 0x11, 0x90, 0x4C, 0xC3, 0x14, 0x20, 0x60,
  35308. 0xB2, 0x30, 0x0A, 0xB6, 0x24, 0x21, 0xA9, 0x10,
  35309. 0x89, 0x80, 0x88, 0x44, 0x06, 0x8A, 0x91, 0x22,
  35310. 0x8E, 0xD9, 0x36, 0x86, 0x10, 0x46, 0x0A, 0xE1,
  35311. 0x16, 0x85, 0x42, 0x40, 0x6C, 0x09, 0x49, 0x11,
  35312. 0xE0, 0x88, 0x68, 0x12, 0x08, 0x68, 0x5C, 0x26,
  35313. 0x24, 0x04, 0xA8, 0x70, 0xC8, 0x08, 0x05, 0x13,
  35314. 0x87, 0x41, 0x23, 0x29, 0x72, 0xC9, 0xB8, 0x88,
  35315. 0x1B, 0x22, 0x66, 0x11, 0xA5, 0x2D, 0x11, 0x29,
  35316. 0x12, 0x50, 0x12, 0x70, 0x03, 0x09, 0x6A, 0x4B,
  35317. 0x88, 0x4C, 0xD2, 0xC8, 0x31, 0x40, 0x26, 0x40,
  35318. 0x4C, 0x04, 0x50, 0x58, 0x16, 0x71, 0x90, 0xC2,
  35319. 0x00, 0x0A, 0x30, 0x8A, 0xDC, 0x24, 0x85, 0x19,
  35320. 0xB0, 0x65, 0x1A, 0xA3, 0x64, 0x13, 0xA3, 0x45,
  35321. 0xC8, 0x48, 0x91, 0x91, 0x12, 0x20, 0xDC, 0x42,
  35322. 0x40, 0x24, 0xC0, 0x4D, 0xA3, 0x98, 0x10, 0x40,
  35323. 0x26, 0x25, 0xDC, 0xB4, 0x68, 0x4B, 0xC2, 0x45,
  35324. 0x13, 0x06, 0x91, 0xC8, 0x92, 0x24, 0x82, 0xA8,
  35325. 0x20, 0x4C, 0x30, 0x48, 0x52, 0x06, 0x01, 0x0B,
  35326. 0x24, 0x51, 0x41, 0x36, 0x40, 0x93, 0xC4, 0x70,
  35327. 0x44, 0x40, 0x2C, 0x24, 0x28, 0x22, 0x81, 0xA4,
  35328. 0x4C, 0x43, 0x84, 0x60, 0x20, 0x23, 0x90, 0x01,
  35329. 0x94, 0x6C, 0xDB, 0x28, 0x21, 0x93, 0x30, 0x80,
  35330. 0x93, 0xC0, 0x25, 0xC8, 0xA6, 0x50, 0xCA, 0x24,
  35331. 0x26, 0xD1, 0x40, 0x31, 0x04, 0xC4, 0x8D, 0xE2,
  35332. 0xC0, 0x04, 0x08, 0x33, 0x8C, 0x18, 0x87, 0x91,
  35333. 0xC8, 0xC8, 0x71, 0x40, 0x46, 0x06, 0x00, 0x44,
  35334. 0x20, 0x22, 0x49, 0x70, 0x11, 0x45, 0x90, 0x02,
  35335. 0xC3, 0x61, 0x60, 0xB4, 0x25, 0x80, 0x16, 0x21,
  35336. 0x11, 0x09, 0x04, 0x88, 0x04, 0x05, 0xCC, 0x36,
  35337. 0x20, 0x01, 0xB1, 0x2C, 0x64, 0xB6, 0x50, 0x54,
  35338. 0x32, 0x42, 0x0B, 0x08, 0x8D, 0x12, 0x39, 0x0D,
  35339. 0x10, 0x29, 0x52, 0x88, 0xB0, 0x04, 0x11, 0x38,
  35340. 0x44, 0xD2, 0xA6, 0x71, 0x0B, 0x45, 0x48, 0x9C,
  35341. 0x34, 0x72, 0xA0, 0x28, 0x49, 0x82, 0x16, 0x86,
  35342. 0x12, 0x18, 0x61, 0x04, 0x41, 0x0D, 0x8A, 0xA6,
  35343. 0x41, 0x80, 0xA8, 0x61, 0xDA, 0x30, 0x65, 0x82,
  35344. 0x84, 0x30, 0x08, 0xA3, 0x29, 0x04, 0x33, 0x8E,
  35345. 0x02, 0x24, 0x0D, 0x9C, 0x44, 0x10, 0xC9, 0x02,
  35346. 0x81, 0x53, 0x06, 0x66, 0x8B, 0x06, 0x90, 0x03,
  35347. 0x87, 0x69, 0x21, 0xC9, 0x69, 0x83, 0x46, 0x4E,
  35348. 0x14, 0x24, 0x89, 0x8C, 0xA0, 0x6C, 0x99, 0xA2,
  35349. 0x2C, 0x11, 0x37, 0x66, 0x0C, 0xA6, 0x4D, 0xD3,
  35350. 0xC8, 0x70, 0x03, 0x02, 0x61, 0xC3, 0xB6, 0x65,
  35351. 0x23, 0xC1, 0x6C, 0x10, 0x34, 0x8D, 0x1A, 0xC1,
  35352. 0x31, 0x43, 0x40, 0x44, 0xD4, 0x08, 0x02, 0x0A,
  35353. 0x36, 0x20, 0xE3, 0x26, 0x42, 0x0A, 0x48, 0x26,
  35354. 0x1A, 0x13, 0x44, 0x0C, 0x18, 0x61, 0x91, 0x96,
  35355. 0x84, 0x02, 0x17, 0x46, 0x9C, 0x20, 0x40, 0x41,
  35356. 0xC6, 0x2D, 0x1B, 0x16, 0x0C, 0x98, 0xB2, 0x90,
  35357. 0x1A, 0x20, 0x84, 0xE2, 0x34, 0x2D, 0xCB, 0x14,
  35358. 0x44, 0x93, 0xC6, 0x8D, 0x58, 0xB2, 0x69, 0x22,
  35359. 0xB2, 0x88, 0xC0, 0xB8, 0x2D, 0xA2, 0xC2, 0x31,
  35360. 0x20, 0xA3, 0x24, 0x11, 0x46, 0x48, 0x4A, 0xA6,
  35361. 0x50, 0x24, 0x09, 0x21, 0x1A, 0x01, 0x0D, 0x20,
  35362. 0x36, 0x01, 0xC4, 0x34, 0x70, 0xDA, 0x16, 0x68,
  35363. 0x84, 0x22, 0x4C, 0x11, 0x14, 0x09, 0x13, 0xC4,
  35364. 0x68, 0x11, 0x41, 0x2D, 0x1C, 0x10, 0x31, 0xDC,
  35365. 0xB2, 0x64, 0x42, 0x36, 0x08, 0x5C, 0x10, 0x88,
  35366. 0x04, 0x91, 0x25, 0xE1, 0xA0, 0x20, 0x14, 0x18,
  35367. 0x12, 0x14, 0x94, 0x91, 0x4C, 0xC2, 0x24, 0xD4,
  35368. 0x06, 0x71, 0x21, 0x02, 0x8D, 0xD4, 0x88, 0x30,
  35369. 0xC9, 0x36, 0x0E, 0xE4, 0x82, 0x81, 0xC0, 0x04,
  35370. 0x6D, 0x24, 0x23, 0x09, 0x21, 0x45, 0x45, 0x20,
  35371. 0x06, 0x65, 0xC2, 0x30, 0x2A, 0x18, 0x30, 0x8E,
  35372. 0x24, 0x83, 0x89, 0x93, 0x32, 0x66, 0xC1, 0x48,
  35373. 0x45, 0x62, 0x48, 0x0A, 0x52, 0xB8, 0x80, 0x11,
  35374. 0x86, 0x21, 0x04, 0x34, 0x11, 0x24, 0xB5, 0x6C,
  35375. 0x50, 0x36, 0x0A, 0x19, 0xA7, 0x8C, 0x14, 0x90,
  35376. 0x0D, 0x1A, 0xA5, 0x68, 0x0B, 0xB1, 0x11, 0x50,
  35377. 0x40, 0x08, 0x48, 0xB6, 0x31, 0x14, 0x28, 0x8D,
  35378. 0xE3, 0x47, 0xB4, 0xA1, 0x44, 0x94, 0xCC, 0x9F,
  35379. 0x0B, 0x94, 0x9F, 0x25, 0x49, 0xD9, 0xB3, 0x8F,
  35380. 0x71, 0xF4, 0x17, 0xA4, 0xA6, 0xAC, 0x24, 0x58,
  35381. 0x14, 0x25, 0x03, 0xC8, 0x63, 0x3E, 0x10, 0xA8,
  35382. 0xD4, 0x10, 0xD7, 0x90, 0x4A, 0x28, 0x37, 0x90,
  35383. 0x70, 0x27, 0xE3, 0x56, 0x5F, 0x04, 0x67, 0x76,
  35384. 0xC3, 0x67, 0x3F, 0xF5, 0xA5, 0x11, 0xA2, 0x2C,
  35385. 0x11, 0x01, 0x5D, 0x63, 0x71, 0x1A, 0xE6, 0x70,
  35386. 0x86, 0x46, 0xAB, 0xCE, 0x03, 0xB6, 0x82, 0xAF,
  35387. 0x51, 0xBA, 0x81, 0x94, 0x9C, 0x82, 0x36, 0xA9,
  35388. 0x49, 0xA5, 0xA3, 0x11, 0x08, 0x8C, 0x4B, 0x13,
  35389. 0x41, 0xF0, 0x08, 0xFD, 0xB2, 0x99, 0xED, 0xA8,
  35390. 0x07, 0x61, 0x3C, 0x2E, 0xBC, 0x49, 0x7B, 0x1C,
  35391. 0xBC, 0x87, 0xBC, 0xAE, 0x5F, 0x5E, 0x8F, 0x5D,
  35392. 0xE7, 0xB9, 0x0C, 0x70, 0x36, 0x25, 0x61, 0xFD,
  35393. 0x95, 0x9F, 0xAE, 0x0F, 0x8D, 0xF3, 0xA2, 0x45,
  35394. 0x24, 0xA7, 0xDE, 0x60, 0xD1, 0x4E, 0x6D, 0xAC,
  35395. 0xC7, 0x6A, 0x32, 0x42, 0xC0, 0x73, 0xEB, 0x78,
  35396. 0x50, 0xF4, 0x49, 0x52, 0x5E, 0x6F, 0x81, 0x42,
  35397. 0x54, 0xF8, 0x82, 0x05, 0xC9, 0x64, 0x74, 0x6A,
  35398. 0x60, 0x5E, 0x36, 0x59, 0x40, 0x50, 0xA3, 0xFE,
  35399. 0xDA, 0xE2, 0x6D, 0x8D, 0x6E, 0xE4, 0x5A, 0x27,
  35400. 0x73, 0x89, 0xDB, 0x0C, 0x5B, 0x14, 0xD9, 0xED,
  35401. 0xB2, 0xC7, 0x1D, 0x71, 0x93, 0x91, 0x0A, 0x72,
  35402. 0x32, 0xBE, 0xA3, 0xD8, 0x95, 0x8C, 0x94, 0x7E,
  35403. 0x63, 0xEB, 0xCE, 0x8B, 0xFC, 0xB0, 0x3F, 0x77,
  35404. 0x5C, 0x43, 0x48, 0x18, 0x83, 0xFE, 0xC8, 0xDA,
  35405. 0x89, 0xF2, 0x3B, 0x54, 0x82, 0x44, 0xC6, 0x9C,
  35406. 0xCC, 0x77, 0x0A, 0xC1, 0x6F, 0xB9, 0x98, 0x10,
  35407. 0xD5, 0xF2, 0x60, 0xFF, 0x38, 0xD2, 0x0D, 0xD6,
  35408. 0x8C, 0x38, 0x54, 0x5B, 0xD8, 0x38, 0x84, 0x50,
  35409. 0x36, 0xF4, 0x02, 0xC1, 0x06, 0x0F, 0x15, 0x1B,
  35410. 0xC8, 0x90, 0x9B, 0x6E, 0x36, 0xC8, 0x3F, 0xE9,
  35411. 0x8B, 0x62, 0x15, 0x6F, 0xF0, 0xC2, 0x86, 0x7F,
  35412. 0xD1, 0xB5, 0x97, 0x53, 0xAE, 0x41, 0xAE, 0x21,
  35413. 0x84, 0xAC, 0x57, 0xA5, 0x1F, 0xA7, 0xC7, 0x24,
  35414. 0xDF, 0xDE, 0x2F, 0x3C, 0xCD, 0xA2, 0x7E, 0x1D,
  35415. 0x97, 0xE1, 0x96, 0xC5, 0xB4, 0x7D, 0xF9, 0x5F,
  35416. 0x7E, 0xEF, 0x09, 0xC4, 0xF3, 0x57, 0xF0, 0x51,
  35417. 0x73, 0xAB, 0x0E, 0x6A, 0xCA, 0x64, 0xE4, 0x99,
  35418. 0x0F, 0xD2, 0x20, 0xAC, 0x72, 0xF1, 0xA8, 0x23,
  35419. 0x8F, 0x94, 0x63, 0xDC, 0xB3, 0xBB, 0x62, 0x2C,
  35420. 0xEA, 0xA6, 0x27, 0x5A, 0x93, 0xC6, 0xCD, 0xCE,
  35421. 0x1E, 0x09, 0xAF, 0x89, 0xEC, 0x22, 0xE4, 0x30,
  35422. 0x2D, 0xB9, 0xCD, 0x08, 0x2E, 0x12, 0x76, 0x79,
  35423. 0x99, 0xBC, 0xA0, 0x34, 0x0B, 0xDA, 0x89, 0x08,
  35424. 0x14, 0x60, 0x7B, 0x98, 0xE6, 0xAF, 0xD2, 0xE1,
  35425. 0x87, 0xC8, 0xDA, 0x50, 0xF7, 0x10, 0x2C, 0x72,
  35426. 0x74, 0x50, 0xD0, 0x3C, 0x98, 0x06, 0xFE, 0xEB,
  35427. 0xC6, 0xC5, 0x69, 0x31, 0x06, 0xE2, 0x2E, 0x7E,
  35428. 0x7D, 0x3D, 0x2B, 0x1F, 0x48, 0x43, 0xC5, 0x95,
  35429. 0xDA, 0x84, 0x08, 0x1E, 0x2B, 0x50, 0x6D, 0x91,
  35430. 0xA6, 0x2B, 0xCD, 0x08, 0x43, 0x7B, 0xA2, 0xD8,
  35431. 0x60, 0x6E, 0xF7, 0x80, 0x08, 0xC3, 0x3F, 0x35,
  35432. 0xF3, 0x70, 0xA5, 0xC7, 0x56, 0xFC, 0xBD, 0x34,
  35433. 0x46, 0x7B, 0xBF, 0x63, 0x19, 0xAC, 0xB6, 0xC3,
  35434. 0x1B, 0x81, 0x84, 0x9F, 0xBB, 0x54, 0x05, 0x99,
  35435. 0xAE, 0x43, 0xE2, 0xA5, 0x20, 0xFD, 0x5C, 0xC7,
  35436. 0x25, 0x47, 0xB1, 0xFD, 0x80, 0xB5, 0x78, 0xC2,
  35437. 0x00, 0x98, 0x02, 0xB9, 0x61, 0x2A, 0xBA, 0x39,
  35438. 0xC7, 0x20, 0xB8, 0x7D, 0x7A, 0x03, 0x68, 0xE5,
  35439. 0x37, 0x71, 0x1F, 0x72, 0xAA, 0x41, 0x61, 0xB4,
  35440. 0xC0, 0xC2, 0xD3, 0x7A, 0xCD, 0xD2, 0xED, 0xC2,
  35441. 0xC5, 0x99, 0x8C, 0x62, 0xA3, 0x7D, 0xC8, 0x9C,
  35442. 0xD2, 0x50, 0x02, 0x0D, 0xCB, 0x68, 0x15, 0xB0,
  35443. 0xD6, 0x19, 0x03, 0xC8, 0x01, 0x12, 0x72, 0xA1,
  35444. 0x3A, 0xC2, 0xA6, 0x63, 0x51, 0x26, 0x03, 0x5D,
  35445. 0x3F, 0x1D, 0x3B, 0x0E, 0x30, 0x6B, 0xB7, 0xEC,
  35446. 0xB6, 0x8E, 0x2D, 0x76, 0xC8, 0xD7, 0xAE, 0x59,
  35447. 0x81, 0xFC, 0x5F, 0x57, 0x5E, 0xAD, 0xA0, 0x20,
  35448. 0xC8, 0xB4, 0x91, 0x2D, 0xEC, 0x03, 0xC4, 0xC6,
  35449. 0x55, 0x05, 0x87, 0xA4, 0xA2, 0x21, 0x09, 0x25,
  35450. 0x97, 0x21, 0xA4, 0x46, 0x45, 0x46, 0x40, 0x3B,
  35451. 0xDC, 0x6F, 0xCD, 0xFB, 0xFB, 0xD9, 0xF4, 0x2C,
  35452. 0xEC, 0xF1, 0xC4, 0x73, 0x41, 0x30, 0x60, 0x63,
  35453. 0x9A, 0xF2, 0xA5, 0x26, 0x78, 0x9A, 0x5E, 0x70,
  35454. 0x98, 0xDE, 0x35, 0x10, 0xA0, 0x5D, 0x45, 0xD5,
  35455. 0x95, 0xF7, 0x11, 0xBC, 0x99, 0xD3, 0x00, 0x67,
  35456. 0x9A, 0x30, 0x85, 0x36, 0x50, 0xDB, 0x18, 0xEA,
  35457. 0x6D, 0xB2, 0xF3, 0x14, 0xDA, 0x23, 0xE2, 0x8A,
  35458. 0x44, 0x21, 0x25, 0xD4, 0xA3, 0x28, 0x43, 0xA0,
  35459. 0xC6, 0x5C, 0x99, 0xB0, 0x72, 0x6B, 0xC2, 0x1A,
  35460. 0x30, 0xBE, 0x6B, 0x7B, 0xE0, 0x31, 0x54, 0x8C,
  35461. 0x29, 0xE5, 0xC6, 0x69, 0x53, 0xDE, 0x05, 0x1E,
  35462. 0x43, 0xCC, 0x7E, 0x9A, 0x82, 0x4A, 0xC4, 0x0A,
  35463. 0x50, 0x65, 0xDC, 0xD8, 0xF9, 0x01, 0x32, 0x65,
  35464. 0x1E, 0xF9, 0xA4, 0xCC, 0x07, 0xB9, 0x55, 0x97,
  35465. 0x45, 0xA9, 0x61, 0xF8, 0xBE, 0x99, 0x00, 0x12,
  35466. 0xD8, 0x17, 0x62, 0xFB, 0x89, 0xE7, 0x05, 0x5E,
  35467. 0x1B, 0xCD, 0x2B, 0x09, 0x6C, 0x5A, 0x5C, 0xA3,
  35468. 0x66, 0x4D, 0x02, 0x78, 0x0C, 0xC3, 0x63, 0x30,
  35469. 0xD0, 0xFA, 0x7B, 0x11, 0x00, 0x40, 0xDD, 0xF0,
  35470. 0x8C, 0x7C, 0xBA, 0x4C, 0x63, 0x78, 0xDA, 0xBB,
  35471. 0xDF, 0xF9, 0xC9, 0xA4, 0x40, 0x25, 0x86, 0xD1,
  35472. 0xBA, 0x22, 0xD7, 0x69, 0x98, 0x4E, 0x9D, 0x15,
  35473. 0x21, 0xA8, 0x56, 0xC0, 0xFF, 0x52, 0xE4, 0xB4,
  35474. 0x0F, 0xB2, 0x53, 0xE7, 0xA1, 0x34, 0x18, 0xEA,
  35475. 0x5B, 0x25, 0x42, 0x13, 0xE3, 0x13, 0xE7, 0xDF,
  35476. 0x54, 0x2B, 0x8D, 0x70, 0x51, 0xC7, 0x60, 0xB1,
  35477. 0x1E, 0x4D, 0x3A, 0x46, 0x04, 0xA1, 0x11, 0x43,
  35478. 0xAD, 0x24, 0x29, 0x90, 0xC9, 0x04, 0x15, 0xC5,
  35479. 0x07, 0xE5, 0x46, 0xB8, 0x50, 0x16, 0x6B, 0x66,
  35480. 0xFE, 0x1C, 0x8B, 0xFC, 0x20, 0x9C, 0xC4, 0x88,
  35481. 0x10, 0x36, 0x5E, 0x56, 0xE8, 0x45, 0x75, 0x89,
  35482. 0xFB, 0xD6, 0xD0, 0x8D, 0x9D, 0x53, 0xAE, 0x89,
  35483. 0x19, 0x54, 0xCF, 0xE1, 0xFF, 0x12, 0x13, 0xF2,
  35484. 0xC7, 0xBE, 0x4C, 0x1E, 0xB0, 0x70, 0x6E, 0xDC,
  35485. 0x0A, 0x64, 0x3B, 0x60, 0x3A, 0xEA, 0x0D, 0x41,
  35486. 0xDD, 0x8E, 0x09, 0xB9, 0x96, 0x8F, 0x6A, 0x49,
  35487. 0x50, 0xEF, 0xDF, 0xD7, 0x73, 0x8D, 0x16, 0x32,
  35488. 0xA8, 0x5C, 0x0A, 0x90, 0x18, 0xA1, 0xEB, 0x19,
  35489. 0xCC, 0x50, 0xD5, 0x59, 0xD7, 0x35, 0x3F, 0xBA,
  35490. 0x38, 0x1B, 0x5F, 0x71, 0x56, 0x70, 0xB3, 0x20,
  35491. 0x4D, 0x9E, 0x16, 0xA8, 0xF7, 0x35, 0x19, 0xD2,
  35492. 0x09, 0x0A, 0x22, 0x28, 0x81, 0x61, 0x26, 0x5B,
  35493. 0x9C, 0xEC, 0x9D, 0x4A, 0x61, 0xCF, 0x0D, 0x3C,
  35494. 0x88, 0xEA, 0x0B, 0x7A, 0xA7, 0xC6, 0xAE, 0x31,
  35495. 0xBE, 0xC2, 0xBA, 0x48, 0xBB, 0x9D, 0x06, 0xE1,
  35496. 0x32, 0x6D, 0x80, 0xCE, 0x27, 0x5C, 0x6F, 0x13,
  35497. 0x79, 0x35, 0x9F, 0x9C, 0x11, 0xEA, 0xDB, 0xF5,
  35498. 0x49, 0x15, 0xB6, 0x51, 0x86, 0xFC, 0x62, 0x34,
  35499. 0x3D, 0x58, 0x6B, 0x0E, 0xF8, 0x3B, 0xBB, 0x42,
  35500. 0xF6, 0x2D, 0x5C, 0xE2, 0xF3, 0xAA, 0x9F, 0x03,
  35501. 0x43, 0xE9, 0x9E, 0x90, 0xB9, 0xFF, 0x55, 0x93,
  35502. 0x60, 0xF8, 0x10, 0x2F, 0xFC, 0xBD, 0x40, 0x23,
  35503. 0xB8, 0x4F, 0x4C, 0x7A, 0x74, 0x9F, 0xDC, 0x55,
  35504. 0xDF, 0x5E, 0xCD, 0x23, 0xEB, 0xAC, 0x47, 0x4E,
  35505. 0x0D, 0x0F, 0xBE, 0xDE, 0x02, 0x64, 0x61, 0x7E,
  35506. 0x73, 0x78, 0x8E, 0x25, 0xE9, 0x7D, 0x66, 0xE5,
  35507. 0x82, 0xBF, 0x98, 0x5B, 0x36, 0xCE, 0x17, 0x72,
  35508. 0x56, 0x9C, 0xDA, 0x63, 0x77, 0x55, 0x8B, 0xA9,
  35509. 0x75, 0xF5, 0x28, 0xC3, 0x78, 0x6D, 0x8F, 0xC2,
  35510. 0x75, 0x5F, 0x28, 0x9E, 0x3F, 0xFB, 0xF1, 0xFD,
  35511. 0xB7, 0xDE, 0x05, 0x3C, 0xD3, 0xE8, 0xD7, 0x7A,
  35512. 0x7D, 0xC9, 0xF7, 0x9D, 0x58, 0xB4, 0xA6, 0x21,
  35513. 0x25, 0xFC, 0x52, 0x84, 0x21, 0xF6, 0x0B, 0x6D,
  35514. 0xA6, 0x62, 0x51, 0x97, 0xCD, 0xA9, 0xA1, 0x0C,
  35515. 0x88, 0x21, 0x67, 0xA5, 0xFB, 0x8C, 0x8A, 0x50,
  35516. 0xC5, 0x21, 0x91, 0x3A, 0xAB, 0x95, 0x96, 0xF3,
  35517. 0x30, 0x6D, 0x08, 0x42, 0x07, 0x4B, 0x78, 0x1F,
  35518. 0xC1, 0xD3, 0x41, 0x15, 0x68, 0xED, 0x93, 0x09,
  35519. 0xC7, 0x8B, 0xF9, 0x77, 0x25, 0xD3, 0xCE, 0x2B,
  35520. 0xA2, 0x0D, 0xB4, 0xC6, 0x84, 0x7F, 0x8E, 0xE5,
  35521. 0x24, 0x46, 0x59, 0x8D, 0x6F, 0x0F, 0x0C, 0xA8,
  35522. 0xFC, 0x04, 0x9B, 0x4D, 0x2B, 0xA7, 0x70, 0x1F,
  35523. 0x46, 0x7E, 0x76, 0x03, 0xC6, 0x7E, 0xA5, 0x3D,
  35524. 0x79, 0xE2, 0xF1, 0xAC, 0xBC, 0xDD, 0xF6, 0x91,
  35525. 0x69, 0x4C, 0x44, 0x1F, 0xC3, 0xBF, 0x9F, 0xFC,
  35526. 0x4E, 0xB0, 0x79, 0x30, 0x68, 0x89, 0xAC, 0xF2,
  35527. 0xD7, 0xC6, 0xE1, 0x6C, 0x37, 0xFB, 0xB3, 0x38,
  35528. 0x44, 0x2C, 0x97, 0xAB, 0xDA, 0x2C, 0x88, 0xC7,
  35529. 0xF2, 0x80, 0x08, 0x00, 0x4E, 0x44, 0xED, 0xBE,
  35530. 0xA4, 0x28, 0x3D, 0xC1, 0xCF, 0x9E, 0x83, 0xE7,
  35531. 0x2E, 0x7F, 0xF5, 0x08, 0x47, 0x26, 0xE0, 0xBD,
  35532. 0x1A, 0x17, 0xDB, 0x2F, 0xED, 0x19, 0x2E, 0x65,
  35533. 0x1B, 0x62, 0x5F, 0x08, 0x82, 0x10, 0x61, 0xCB,
  35534. 0xAA, 0xA7, 0xF8, 0x59, 0x4B, 0x46, 0xCB, 0xA2,
  35535. 0xCB, 0x41, 0x34, 0x30, 0x51, 0x58, 0x2A, 0xEE,
  35536. 0xE1, 0x5E, 0xAC, 0xCA, 0xBF, 0x37, 0x45, 0x98,
  35537. 0xBD, 0x93, 0x1B, 0x5A, 0x5E, 0x92, 0x14, 0x05,
  35538. 0x75, 0x2D, 0xFB, 0x8F, 0xBD, 0x24, 0x9B, 0x81,
  35539. 0xCD, 0xDD, 0xF5, 0xBE, 0x05, 0x0D, 0xBD, 0x4B,
  35540. 0x2B, 0x8C, 0x0A, 0xF0, 0x3A, 0x85, 0xD6, 0x74,
  35541. 0x65, 0x7F, 0x98, 0xF8, 0x57, 0xA2, 0x36, 0xA2,
  35542. 0xFE, 0xE4, 0xB4, 0xA4, 0x0D, 0xEA, 0x9A, 0xBE,
  35543. 0x41, 0x79, 0x68, 0x63, 0x70, 0x3F, 0x3E, 0x38,
  35544. 0x60, 0xC3, 0x40, 0x81, 0x72, 0xDD, 0x25, 0x34,
  35545. 0xB4, 0xFE, 0xAC, 0x41, 0x6E, 0x4A, 0xE7, 0xBF,
  35546. 0xE3, 0x87, 0xFA, 0x20, 0x8B, 0xBD, 0x68, 0x9E,
  35547. 0x06, 0xA9, 0x15, 0x23, 0x07, 0x04, 0x4B, 0xFA,
  35548. 0x45, 0x45, 0xB7, 0x75, 0xD3, 0x3E, 0x16, 0x70,
  35549. 0xF6, 0x26, 0xF2, 0x3A, 0x9D, 0xFB, 0xEA, 0xEB,
  35550. 0x47, 0xCE, 0x99, 0x6B, 0x0E, 0xB2, 0xE8, 0x2B,
  35551. 0x18, 0x15, 0x14, 0x2E, 0xF2, 0x14, 0x0D, 0x44,
  35552. 0x47, 0x1E, 0x63, 0x84, 0x5B, 0x3F, 0xA8, 0xEF,
  35553. 0x5F, 0xEB, 0xA0, 0x41, 0x77, 0xC1, 0xF4, 0x4F,
  35554. 0x8E, 0x2E, 0x29, 0xCD, 0xDB, 0xF2, 0x75, 0x24,
  35555. 0x24, 0x46, 0x73, 0xC3, 0x46, 0xB5, 0xCA, 0x13,
  35556. 0x35, 0x12, 0x0A, 0x8D, 0x88, 0x89, 0x17, 0x99,
  35557. 0x13, 0xCA, 0x66, 0x07, 0x67, 0x6B, 0x7B, 0x3B,
  35558. 0x20, 0xD3, 0x5F, 0x78, 0x1C, 0xC0, 0x99, 0x59,
  35559. 0x0A, 0xBA, 0x8F, 0xA0, 0xDB, 0xDF, 0xCC, 0x03,
  35560. 0xC4, 0xA6, 0xC7, 0x08, 0xB9, 0xFD, 0x95, 0xC2,
  35561. 0x45, 0xF9, 0xF3, 0x11, 0x62, 0xF7, 0x14, 0xB9,
  35562. 0xEB, 0x09, 0xB3, 0x7C, 0xF8, 0xF6, 0x67, 0xCC,
  35563. 0x03, 0xB3, 0x06, 0x6F, 0x60, 0xAC, 0x72, 0xF2,
  35564. 0xD3, 0x71, 0x6C, 0x4D, 0xAD, 0x3A, 0x99, 0x75,
  35565. 0x5C, 0x52, 0x2D, 0x87, 0x69, 0x3E, 0xD6, 0x7E,
  35566. 0x12, 0x96, 0xD3, 0x88, 0x8D, 0x11, 0x85, 0xAA,
  35567. 0x0A, 0xA5, 0x32, 0x90, 0x51, 0xC5, 0x65, 0x64,
  35568. 0xE0, 0xA9, 0x73, 0xA4, 0xF3, 0x8A, 0x32, 0x83,
  35569. 0xE5, 0x08, 0x09, 0x39, 0x6A, 0x90, 0x2C, 0xC3,
  35570. 0xFC, 0x92, 0x29, 0x7A, 0x45, 0xBE, 0x02, 0x79,
  35571. 0x15, 0x1B, 0xBB, 0x60, 0xBB, 0xD9, 0x42, 0xF1,
  35572. 0xE5, 0x14, 0xB4, 0xA5, 0xFF, 0x12, 0x42, 0x30,
  35573. 0xB0, 0xCB, 0xD0, 0x1D, 0xB4, 0x62, 0x49, 0xC5,
  35574. 0xB7, 0xDA, 0x37, 0x47, 0x2C, 0x8B, 0x16, 0xCA,
  35575. 0xD2, 0x2C, 0xA1, 0x24, 0xE6, 0x57, 0xFA, 0xEB,
  35576. 0x2C, 0x62, 0x2E, 0x12, 0x74, 0x37, 0x2B, 0x3F,
  35577. 0x56, 0x23, 0x9C, 0xED, 0x90, 0xDE, 0x0D, 0x6E,
  35578. 0x9E, 0x11, 0x78, 0xA4, 0x9C, 0xB3, 0xA1, 0x37,
  35579. 0xF7, 0x4B, 0x09, 0x61, 0xD8, 0x33, 0x1D, 0x80,
  35580. 0x68, 0x5C, 0xDD, 0xBD, 0x3E, 0xAE, 0x9D, 0xB8,
  35581. 0xBA, 0x42, 0x41, 0xDC, 0xC9, 0x93, 0xF1, 0x92,
  35582. 0x2F, 0x7A, 0xF9, 0xFE, 0x67, 0x13, 0x87, 0xBD,
  35583. 0x7D, 0x04, 0x17, 0x91, 0xB6, 0x03, 0x5E, 0xA0,
  35584. 0x5B, 0x23, 0xEA, 0x0C, 0xFA, 0x45, 0xCB, 0x1A,
  35585. 0xC5, 0x7F, 0x63, 0xD6, 0x3D, 0x3C, 0x66, 0x4A,
  35586. 0x83, 0x4E, 0x4E, 0x90, 0xA6, 0x63, 0xB0, 0x8A,
  35587. 0xD7, 0x0D, 0xB4, 0xB7, 0xA9, 0x0F, 0xC6, 0xC7,
  35588. 0x3B, 0xAD, 0x07, 0xA6, 0x94, 0x47, 0xDB, 0x63,
  35589. 0x26, 0x00, 0x18, 0x5E, 0x27, 0xB5, 0xE2, 0xE3,
  35590. 0xED, 0x8D, 0x97, 0x95, 0x38, 0x20, 0x24, 0x9F,
  35591. 0x40, 0x84, 0x44, 0x7E, 0x8C, 0x05, 0xAB, 0xB1,
  35592. 0x89, 0x26, 0x7D, 0x46, 0x2C, 0x9F, 0xE5, 0xC1,
  35593. 0x27, 0xCE, 0x1D, 0x5A, 0x9F, 0xF1, 0xF8, 0x57,
  35594. 0x8F, 0xCF, 0xB7, 0x4E, 0x07, 0xF3, 0xBA, 0x56,
  35595. 0xCF, 0xE9, 0x87, 0x21, 0x61, 0xD6, 0x97, 0x7B,
  35596. 0x26, 0x97, 0x07, 0xB4, 0x87, 0xFE, 0x25, 0x9C,
  35597. 0xA9, 0x8E, 0x06, 0x90, 0x17, 0x2C, 0x98, 0x26,
  35598. 0x23, 0xEE, 0xBB, 0x91, 0x8A, 0x15, 0x38, 0xA1,
  35599. 0x38, 0xCB, 0x8B, 0xA0, 0xF3, 0x4A, 0xF2, 0x12,
  35600. 0xA7, 0xB7, 0x05, 0xB6, 0x09, 0xD0, 0xEC, 0xDD,
  35601. 0x21, 0xB6, 0xFA, 0x29, 0x95, 0xB4, 0x08, 0xD5,
  35602. 0x95, 0xB7, 0xB8, 0x2E, 0x23, 0xAA, 0x89, 0x81,
  35603. 0xE2, 0xD0, 0xFD, 0x9C, 0x8D, 0xF0, 0xCA, 0x61,
  35604. 0xE3, 0x1E, 0x73, 0x9E, 0xD1, 0x72, 0x5C, 0x63,
  35605. 0xB8, 0x74, 0x0E, 0x2C, 0x27, 0x3A, 0x71, 0xF9,
  35606. 0xFE, 0x66, 0x33, 0xE9, 0x41, 0x27, 0x61, 0xA3,
  35607. 0xFA, 0xD8, 0x66, 0x2A, 0x52, 0x6D, 0xAB, 0xBF,
  35608. 0x32, 0xC2, 0x8E, 0x8F, 0xB0, 0x60, 0x52, 0xE1,
  35609. 0x96, 0xC8, 0x1E, 0x9A, 0x3E, 0x07, 0xFA, 0x34,
  35610. 0xFA, 0x9C, 0x4C, 0x0D, 0x29, 0x0F, 0x68, 0xA6,
  35611. 0x59, 0x28, 0x22, 0xB1, 0x99, 0x56, 0x2C, 0x01,
  35612. 0x04, 0x2F, 0x34, 0x65, 0xFD, 0xD4, 0xD0, 0xD5,
  35613. 0x17, 0x7C, 0x14, 0x92, 0x73, 0x6C, 0x31, 0xCE,
  35614. 0xD4, 0xB3, 0x59, 0x83, 0x6B, 0x34, 0x7C, 0x76,
  35615. 0x8C, 0xED, 0xD5, 0xE2, 0x4F, 0x39, 0x44, 0xBF,
  35616. 0x90, 0x53, 0x9A, 0xC7, 0xD4, 0x6A, 0x86, 0xA3,
  35617. 0xE2, 0x15, 0x59, 0xD0, 0x0F, 0x32, 0x92, 0xC2,
  35618. 0x9B, 0x9E, 0xE3, 0xF6, 0x94, 0x96, 0xFD, 0x0B,
  35619. 0xB6, 0x06, 0x8F, 0x0D, 0x1F, 0x38, 0xFC, 0x6F,
  35620. 0xA2, 0x78, 0xAC, 0xC5, 0xB5, 0x6A, 0x6B, 0xEC,
  35621. 0x78, 0x8A, 0x6F, 0xD8, 0x21, 0xB7, 0xCF, 0x66,
  35622. 0x73, 0x03, 0xCA, 0x2E, 0x3C, 0x7F, 0x2F, 0x29,
  35623. 0x41, 0xC9, 0x88, 0xFD, 0x0E, 0xA0, 0x43, 0xD6,
  35624. 0x9E, 0xB1, 0xE7, 0x13, 0x9C, 0xF0, 0x9C, 0xCF,
  35625. 0x33, 0x22, 0x57, 0xEF, 0xE5, 0xCE, 0xD9, 0xAC,
  35626. 0x7D, 0x34, 0x75, 0xBD, 0xAE, 0x84, 0xEE, 0xE8,
  35627. 0x5D, 0x8C, 0x55, 0x86, 0xBA, 0x19, 0xE5, 0x9D,
  35628. 0x35, 0x6D, 0xD8, 0x70, 0xC5, 0xE0, 0xEA, 0x77,
  35629. 0x3A, 0xE5, 0xB5, 0x2C, 0xD2, 0x28, 0xB5, 0xE8,
  35630. 0xAF, 0xB1, 0xD2, 0xC4, 0xE5, 0x59, 0x06, 0xB8,
  35631. 0x2E, 0xA6, 0x8F, 0xC4, 0x9B, 0x30, 0xF9, 0x37,
  35632. 0xDB, 0x29, 0xA1, 0x44, 0x0B, 0xB7, 0xB5, 0xB4,
  35633. 0x12, 0xD3, 0x4E, 0xB3, 0xB7, 0xD8, 0x2F, 0x19,
  35634. 0xDE, 0x3B, 0xC3, 0x53, 0xCE, 0x1C, 0x34, 0x4C,
  35635. 0xA4, 0x6A, 0xE2, 0xD0, 0x04, 0xDF, 0x3C, 0x53,
  35636. 0x8B, 0x06, 0x8F, 0x36, 0xE5, 0x77, 0xB2, 0x7A,
  35637. 0x1A, 0xC0, 0x0C, 0xBD, 0xA3, 0xA0, 0xEE, 0xB6,
  35638. 0x40, 0xAD, 0x5C, 0x04, 0xAE, 0xCF, 0x64, 0x2B,
  35639. 0x8A, 0x18, 0x58, 0x86, 0xDE, 0xC9, 0x3D, 0x7D,
  35640. 0x15, 0xBC, 0xEE, 0x4C, 0x22, 0xF4, 0x98, 0xD9,
  35641. 0x37, 0xEE, 0xE2, 0x40, 0x43, 0xFF, 0xB2, 0x6F,
  35642. 0x05, 0xC0, 0x0E, 0x30, 0xDE, 0xD8, 0x0C, 0x0B,
  35643. 0xAD, 0xED, 0xCC, 0xBC, 0x29, 0x95, 0x07, 0x40,
  35644. 0x10, 0x99, 0xA0, 0xD1, 0x08, 0xF7, 0xD5, 0xF1,
  35645. 0xAD, 0xC9, 0xDD, 0xC8, 0x6A, 0x1E, 0x9E, 0x06,
  35646. 0xDF, 0x12, 0xFF, 0x66, 0x33, 0x5E, 0x21, 0x47,
  35647. 0xC3, 0xDE, 0x36, 0x98, 0x5B, 0xBF, 0x42, 0x9E,
  35648. 0x30, 0xA0, 0x81, 0x5C, 0x28, 0x34, 0x1B, 0x3A,
  35649. 0x32, 0xBC, 0xDE, 0x52, 0x53, 0x25, 0x1E, 0xF6,
  35650. 0xE2, 0x99, 0x12, 0x92, 0x07, 0x1D, 0xEB, 0x08,
  35651. 0x36, 0xA7, 0xD5, 0x18, 0x1F, 0xDB, 0x44, 0xA7,
  35652. 0xE1, 0x13, 0x06, 0xB0, 0xDF, 0x63, 0x82, 0x68,
  35653. 0xEF, 0xF5, 0x2B, 0x04, 0x0B, 0x93, 0xE8, 0xB0,
  35654. 0x92, 0x7B, 0xDE, 0x1F, 0xC9, 0x39, 0x8F, 0x42,
  35655. 0x9D, 0x06, 0x22, 0x13, 0xC9, 0x97, 0x2F, 0x43,
  35656. 0x8A, 0xBA, 0xAF, 0xF9, 0x71, 0xE3, 0x55, 0x5D,
  35657. 0x06, 0x77, 0x38, 0x39, 0xA3, 0xED, 0x41, 0x63,
  35658. 0xFE, 0x2A, 0xB3, 0x23, 0x43, 0x0C, 0xF3, 0x17,
  35659. 0x3B, 0x69, 0xED, 0x32, 0x0A, 0x54, 0xF3, 0x8D,
  35660. 0x76, 0xC6, 0x09, 0xDD, 0x88, 0x5B, 0x23, 0x57,
  35661. 0x72, 0xC4, 0x87, 0xB8, 0x9D, 0xF7, 0xCA, 0xFB,
  35662. 0x7C, 0x61, 0x67, 0x5C, 0x65, 0xF8, 0xD6, 0xD7,
  35663. 0x1E, 0x95, 0xB9, 0x73, 0x4D, 0x2E, 0x1F, 0x43,
  35664. 0x3E, 0x2B, 0x58, 0x92, 0x15, 0x2E, 0xAA, 0x51,
  35665. 0xF0, 0xD4, 0xF2, 0xA6, 0xCD, 0x12, 0x21, 0xD6,
  35666. 0xCA, 0x46, 0x2A, 0xFF, 0xCB, 0x1B, 0x6B, 0xB4,
  35667. 0x09, 0x17, 0x3B, 0xA2, 0x94, 0xDF, 0x1D, 0x68,
  35668. 0x8B, 0x75, 0xEA, 0x11, 0xD6, 0x99, 0x04, 0xD1,
  35669. 0x00, 0xDB, 0x61, 0xBC, 0xF2, 0x3B, 0x88, 0x4B,
  35670. 0x33, 0xDF, 0x0F, 0xD4, 0xFB, 0x14, 0x0C, 0x6A,
  35671. 0x53, 0x61, 0x1F, 0xBD, 0x28, 0xB2, 0x11, 0x19,
  35672. 0x38, 0x71, 0x17, 0x76, 0x4D, 0xEE, 0x01, 0xC4,
  35673. 0x77, 0x53, 0x2A, 0xAF, 0xD3, 0x78, 0xFF, 0x45,
  35674. 0x7F, 0x97, 0x9D, 0x26, 0x92, 0x0E, 0xD9, 0x4E,
  35675. 0x34, 0x1D, 0xE8, 0xDD, 0xBF, 0x5F, 0x87, 0xE6,
  35676. 0x35, 0x9A, 0x39, 0x71, 0x59, 0x20, 0x01, 0xFB,
  35677. 0x53, 0x2C, 0x61, 0x38, 0x0C, 0x8C, 0x02, 0xD3,
  35678. 0xA0, 0x53, 0x95, 0x02, 0xED, 0x5C, 0xFE, 0x9B,
  35679. 0xD3, 0x6A, 0xF3, 0x3F, 0x92, 0x6F, 0x33, 0x37,
  35680. 0x19, 0x97, 0x81, 0x3A, 0x50, 0xE1, 0xD9, 0x27,
  35681. 0x7E, 0x64, 0xF8, 0x01, 0x52, 0x26, 0x51, 0xD1,
  35682. 0x06, 0xAF, 0x20, 0xA0, 0x28, 0x0F, 0x3F, 0xCB,
  35683. 0x21, 0xB7, 0x55, 0x1A, 0x76, 0xB8, 0x9B, 0x4D,
  35684. 0xED, 0x2A, 0x05, 0x0E, 0x6E, 0xAF, 0xCC, 0xA1,
  35685. 0x08, 0x9C, 0xBE, 0x3F, 0x98, 0xE6, 0xB4, 0xB9,
  35686. 0x83, 0xC9, 0x08, 0x41, 0x96, 0xDD, 0xD9, 0x0D,
  35687. 0x52, 0x66, 0x94, 0xA4, 0xEA, 0xFC, 0xE5, 0x48,
  35688. 0x04, 0x73, 0x64, 0x79, 0x68, 0xC9, 0x4A, 0x81,
  35689. 0xA8, 0x07, 0xF8, 0xD9, 0x4E, 0x07, 0x1E, 0xC1,
  35690. 0x8F, 0x62, 0xAB, 0xA6, 0xD7, 0x68, 0xFC, 0x57,
  35691. 0x5E, 0x75, 0x1B, 0xBF, 0x3D, 0xA6, 0x91, 0xC5,
  35692. 0x08, 0x14, 0x5E, 0xF2, 0x4C, 0x22, 0x8B, 0x4E,
  35693. 0x29, 0x2D, 0xC0, 0x46, 0x3A, 0x9C, 0x9D, 0x86,
  35694. 0xCF, 0x51, 0x85, 0x9D, 0x93, 0x23, 0xA1, 0xA1,
  35695. 0xF3, 0x76, 0xB1, 0x56, 0xB0, 0xF4, 0x1F, 0x39,
  35696. 0xDA, 0xDB, 0x13, 0x70, 0x29, 0x89, 0x95, 0xD2,
  35697. 0xC5, 0xF3, 0x76, 0xFE, 0xEE, 0x99, 0xCF, 0xA0,
  35698. 0x84, 0xEC, 0x70, 0xF0, 0xD3, 0xFA, 0x42, 0xDB,
  35699. 0xFD, 0x99, 0x65, 0x2F, 0x84, 0x11, 0x99, 0xCD,
  35700. 0x38, 0xB3, 0x1B, 0xAB, 0x8C, 0x2D, 0x33, 0x04,
  35701. 0xCA, 0xE1, 0xB3, 0x05, 0x9A, 0x20, 0x80, 0xDB,
  35702. 0xED, 0x59, 0x42, 0x30, 0x48, 0x37, 0xB3, 0x85,
  35703. 0x5C, 0xEE, 0x54, 0x06, 0x92, 0x97, 0x4E, 0xFC,
  35704. 0xFA, 0xF7, 0x25, 0xE0, 0x4E, 0x57, 0xC4, 0x72,
  35705. 0x38, 0x59, 0xCA, 0x3C, 0x4A, 0x3F, 0x09, 0xD6,
  35706. 0x09, 0x15, 0x83, 0xEF, 0x24, 0x21, 0xDD, 0xFD,
  35707. 0x66, 0x9E, 0xBF, 0xEE, 0xCC, 0xBF, 0x86, 0x20,
  35708. 0x29, 0x40, 0x5E, 0x42, 0xD2, 0xC0, 0x24, 0x2D,
  35709. 0x76, 0xE6, 0x64, 0xF9, 0x5D, 0xC2, 0x85, 0xB6,
  35710. 0x09, 0x41, 0x04, 0x62, 0x17, 0xDC, 0xF8, 0xFA,
  35711. 0x2A, 0x4C, 0xD1, 0x82, 0x31, 0x57, 0xB7, 0x2B,
  35712. 0x49, 0xE8, 0x40, 0x13, 0x2A, 0xA1, 0x86, 0xD2,
  35713. 0x9A, 0xB8, 0xA9, 0xBE, 0x39, 0xBE, 0xE9, 0xA5,
  35714. 0x35, 0x12, 0x08, 0xF1, 0xA9, 0x9E, 0x57, 0x46,
  35715. 0x3A, 0x55, 0x16, 0xA7, 0x41, 0xD9, 0x25, 0xB8,
  35716. 0x2F, 0xAF, 0xA8, 0x81, 0x5F, 0x5F, 0x46, 0xA4,
  35717. 0x3B, 0xB3, 0xE9, 0x1B, 0x74, 0xEF, 0x5D, 0x57,
  35718. 0x48, 0x4A, 0x72, 0x08, 0xDA, 0xFE, 0x1D, 0x55,
  35719. 0x6B, 0xAB, 0x8B, 0x13, 0x18, 0xBF, 0xDD, 0xF4,
  35720. 0x4E, 0x01, 0x5F, 0x4B, 0xF6, 0x80, 0xD4, 0x16,
  35721. 0x4B, 0x2F, 0x03, 0x4B, 0xF8, 0x93, 0x20, 0x21,
  35722. 0x55, 0x52, 0x49, 0x4A, 0x6C, 0x1F, 0x7D, 0xAD,
  35723. 0x04, 0xEF, 0xB3, 0x74, 0xEE, 0xC5, 0xB6, 0xBC,
  35724. 0x33, 0x7A, 0xCF, 0x64, 0xB9, 0xF9, 0x41, 0x70,
  35725. 0xAF, 0xE9, 0xC7, 0xD6, 0x25, 0x18, 0x17, 0xAB,
  35726. 0xBA, 0xC9, 0x05, 0xEF, 0x40, 0x89, 0xD5, 0x69,
  35727. 0x76, 0xAA, 0xA0, 0x3E, 0x4D, 0x1C, 0xE7, 0x9D,
  35728. 0x9E, 0x74, 0xF4, 0xF2, 0x7B, 0x40, 0xF6, 0x57,
  35729. 0x78, 0x66, 0xFC, 0xDA, 0xE3, 0x6B, 0xD2, 0x6E,
  35730. 0xC7, 0x9D, 0x65, 0x84, 0xAF, 0x7A, 0x1F, 0xE4,
  35731. 0x34, 0xD4, 0x1A, 0x17, 0xA2, 0x72, 0xB0, 0xEE,
  35732. 0x5A, 0x0C, 0xF4, 0x02, 0xAC, 0x1D, 0x6F, 0x4A,
  35733. 0xD0, 0xB2, 0x02, 0x3A, 0x7D, 0x2C, 0xF1, 0x43,
  35734. 0x0E, 0x1E, 0x96, 0xEB, 0x42, 0xF8, 0x3A, 0xF5,
  35735. 0x0B, 0x5D, 0xA9, 0x23, 0x02, 0x28, 0xE5, 0x26,
  35736. 0x5E, 0x69, 0x38, 0x2F, 0x85, 0x34, 0x32, 0x5E,
  35737. 0x5E, 0x29, 0x33, 0x94, 0x05, 0xBD, 0x58, 0xF8,
  35738. 0xE8, 0x9C, 0xBF, 0xB1, 0x5A, 0x05, 0xC6, 0x23,
  35739. 0x9B, 0xBB, 0x57, 0x69, 0x8C, 0xE6, 0x41, 0x97,
  35740. 0x48, 0x01, 0x95, 0xAF, 0xE9, 0x62, 0x8C, 0x6F,
  35741. 0x09, 0x43, 0xF3, 0x64, 0x50, 0x90, 0x2F, 0x14,
  35742. 0xF7, 0x30, 0x07, 0xE0, 0x4B, 0xA8, 0x39, 0xAC,
  35743. 0x21, 0xC4, 0x07, 0x45, 0x5F, 0xD9, 0x87, 0xB1,
  35744. 0x57, 0x47, 0x07, 0x66, 0xFF, 0xC7, 0xAB, 0xEE,
  35745. 0x1F, 0x55, 0x71, 0x50, 0x63, 0xCF, 0x58, 0x3B,
  35746. 0xC8, 0x1B, 0xEA, 0xA5, 0xE2, 0xF1, 0x57, 0xB3,
  35747. 0x77, 0x65, 0xA9, 0xBD, 0x23, 0xC8, 0x30, 0x86,
  35748. 0xC3, 0x5F, 0xBF, 0x16, 0x3F, 0x42, 0x28, 0x0A,
  35749. 0xC6, 0x5A, 0x57, 0x15, 0x2F, 0xA1, 0x96, 0xA9,
  35750. 0x25, 0xC5, 0x8E, 0x32, 0x11, 0x62, 0xB3, 0x54,
  35751. 0x18, 0x00, 0xA4, 0xA6, 0xD4, 0x0F, 0x68, 0x27,
  35752. 0x8F, 0x21, 0x78, 0x02, 0x37, 0x98, 0xBD, 0xCE,
  35753. 0x3F, 0xBC, 0xF2, 0x9C, 0x66, 0x8E, 0x79, 0xA1,
  35754. 0x54, 0x12, 0x55, 0x2E, 0xC0, 0x59, 0xC7, 0x18,
  35755. 0x18, 0x22, 0x4D, 0x27, 0x8B, 0x8D, 0xF3, 0x08,
  35756. 0x99, 0xE6, 0x35, 0x14, 0xB1, 0xE3, 0xB8, 0x7A,
  35757. 0x40, 0x7B, 0x68, 0x7B, 0xFF, 0xDC, 0x54, 0x41,
  35758. 0x06, 0xCA, 0x91, 0xFE, 0xDB, 0x2B, 0xDA, 0x9E,
  35759. 0xC5, 0x20, 0xD8, 0xBF, 0x42, 0xBC, 0xE6, 0x39,
  35760. 0xC4, 0x26, 0x9E, 0xF3, 0x82, 0xD9, 0xF1, 0xA0,
  35761. 0x04, 0xAF, 0xFB, 0x77, 0x13, 0x36, 0xAF, 0xD7,
  35762. 0x91, 0x9B, 0x3A, 0x57, 0x98, 0xFE, 0xAD, 0xCD,
  35763. 0x46, 0xF8, 0xF8, 0xF1, 0x87, 0x53, 0xBD, 0x57,
  35764. 0x3F, 0x99, 0xBC, 0xA6, 0xBD, 0x9B, 0x6E, 0xF4,
  35765. 0x17, 0x7A, 0x78, 0x30, 0x70, 0xA3, 0x43, 0xFF,
  35766. 0x92, 0xCD, 0x99, 0x73, 0xAE, 0x65, 0x6A, 0x10,
  35767. 0xFF, 0x70, 0x47, 0x0F, 0x16, 0x4C, 0x4A, 0x90,
  35768. 0xF4, 0x52, 0x05, 0x79, 0x33, 0x63, 0xDE, 0x14,
  35769. 0x65, 0xAF, 0x8A, 0x5E, 0x67, 0x20, 0x03, 0x9F,
  35770. 0xE6, 0x70, 0x13, 0x6B, 0xE0, 0xF3, 0x6A, 0x4C,
  35771. 0x6B, 0x5B, 0xCB, 0xE1, 0x7C, 0x5D, 0x7D, 0xE3,
  35772. 0x23, 0xFD, 0xB8, 0x6A, 0xDA, 0x56, 0x1E, 0xA8,
  35773. 0x36, 0xC4, 0x29, 0x2D, 0x70, 0x41, 0x03, 0x18,
  35774. 0x31, 0x40, 0x79, 0x2E, 0xC8, 0x22, 0x98, 0x5E,
  35775. 0x11, 0xED, 0xA6, 0xDD, 0xB9, 0xAF, 0x8C, 0x27,
  35776. 0x5C, 0x1B, 0x2E, 0xEA, 0xB8, 0xC6, 0x2F, 0xA0,
  35777. 0x40, 0xB2, 0x64, 0x61, 0xFC, 0x0A, 0x3A, 0x10,
  35778. 0x88, 0xC2, 0x58, 0xEC, 0xA5, 0x8D, 0x14, 0xE9,
  35779. 0x9D, 0x21, 0xAF, 0x64, 0xD6, 0xC2, 0x5D, 0xAA,
  35780. 0x0B, 0x8A, 0x57, 0x0F, 0x84, 0x3E, 0x60, 0x8D,
  35781. 0xED, 0x05, 0x1D, 0x98, 0xED, 0xAE, 0x11, 0xD9,
  35782. 0x27, 0x03, 0x55, 0xED, 0xF5, 0x34, 0x92, 0x52,
  35783. 0xF2, 0x6F, 0x30, 0x3E, 0x69, 0xA5, 0x54, 0xA7,
  35784. 0x2E, 0x1B, 0x85, 0xAB, 0xA2, 0x3B, 0xEC, 0xC8,
  35785. 0x9D, 0xA9, 0xA3, 0xE4, 0xEF, 0x58, 0xB5, 0x33,
  35786. 0x88, 0x55, 0x16, 0x5E, 0x7D, 0x7E, 0x69, 0xFC,
  35787. 0xCA, 0xBD, 0x9C, 0x65, 0xFA, 0x0B, 0xBD, 0x7B,
  35788. 0x16, 0xC4, 0xE2, 0x9C, 0xB4, 0xF1, 0x6A, 0x25,
  35789. 0x70, 0x30, 0x32, 0xED, 0xEA, 0xD3, 0x1D, 0xDB,
  35790. 0x6F, 0x29, 0x2E, 0x42, 0x14, 0xBE, 0x03, 0x29,
  35791. 0x0A, 0x8A, 0x98, 0x9A, 0xD7, 0xB7, 0x0C, 0xF8,
  35792. 0xB9, 0xCF, 0x37, 0xC6, 0xAC, 0xAC, 0x6D, 0xCC,
  35793. 0x03, 0x23, 0x9F, 0x66, 0x85, 0x4B, 0x70, 0x45
  35794. };
  35795. #endif /* WOLFSSL_NO_ML_DSA_87 */
  35796. #endif
  35797. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  35798. ExpectNotNull(key);
  35799. if (key != NULL) {
  35800. XMEMSET(key, 0, sizeof(*key));
  35801. }
  35802. ExpectIntEQ(wc_dilithium_init_ex(key, NULL, INVALID_DEVID), 0);
  35803. #ifndef WOLFSSL_NO_ML_DSA_44
  35804. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  35805. ExpectIntEQ(wc_dilithium_make_key_from_seed(key, seed_44), 0);
  35806. ExpectIntEQ(XMEMCMP(key->p, pk_44, sizeof(pk_44)), 0);
  35807. ExpectIntEQ(XMEMCMP(key->k, sk_44, sizeof(sk_44)), 0);
  35808. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  35809. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44_DRAFT), 0);
  35810. ExpectIntEQ(wc_dilithium_make_key_from_seed(key, seed_44_draft), 0);
  35811. ExpectIntEQ(XMEMCMP(key->p, pk_44_draft, sizeof(pk_44_draft)), 0);
  35812. ExpectIntEQ(XMEMCMP(key->k, sk_44_draft, sizeof(sk_44_draft)), 0);
  35813. #endif
  35814. #endif
  35815. #ifndef WOLFSSL_NO_ML_DSA_65
  35816. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  35817. ExpectIntEQ(wc_dilithium_make_key_from_seed(key, seed_65), 0);
  35818. ExpectIntEQ(XMEMCMP(key->p, pk_65, sizeof(pk_65)), 0);
  35819. ExpectIntEQ(XMEMCMP(key->k, sk_65, sizeof(sk_65)), 0);
  35820. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  35821. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65_DRAFT), 0);
  35822. ExpectIntEQ(wc_dilithium_make_key_from_seed(key, seed_65_draft), 0);
  35823. ExpectIntEQ(XMEMCMP(key->p, pk_65_draft, sizeof(pk_65_draft)), 0);
  35824. ExpectIntEQ(XMEMCMP(key->k, sk_65_draft, sizeof(sk_65_draft)), 0);
  35825. #endif
  35826. #endif
  35827. #ifndef WOLFSSL_NO_ML_DSA_87
  35828. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  35829. ExpectIntEQ(wc_dilithium_make_key_from_seed(key, seed_87), 0);
  35830. ExpectIntEQ(XMEMCMP(key->p, pk_87, sizeof(pk_87)), 0);
  35831. ExpectIntEQ(XMEMCMP(key->k, sk_87, sizeof(sk_87)), 0);
  35832. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  35833. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87_DRAFT), 0);
  35834. ExpectIntEQ(wc_dilithium_make_key_from_seed(key, seed_87_draft), 0);
  35835. ExpectIntEQ(XMEMCMP(key->p, pk_87_draft, sizeof(pk_87_draft)), 0);
  35836. ExpectIntEQ(XMEMCMP(key->k, sk_87_draft, sizeof(sk_87_draft)), 0);
  35837. #endif
  35838. #endif
  35839. wc_dilithium_free(key);
  35840. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  35841. #endif
  35842. return EXPECT_RESULT();
  35843. }
  35844. static int test_wc_dilithium_sig_kats(void)
  35845. {
  35846. EXPECT_DECLS;
  35847. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  35848. !defined(WOLFSSL_DILITHIUM_NO_SIGN)
  35849. dilithium_key* key;
  35850. #ifndef WOLFSSL_NO_ML_DSA_44
  35851. static const byte sk_44[] = {
  35852. 0x5D, 0xFB, 0x07, 0xA2, 0x04, 0x4B, 0x93, 0x16,
  35853. 0x75, 0xC7, 0x89, 0x43, 0xEA, 0xC3, 0xC4, 0xC5,
  35854. 0x7B, 0x07, 0x77, 0x8A, 0xD9, 0xAF, 0x2E, 0x87,
  35855. 0xC4, 0x70, 0xB9, 0xCC, 0x2C, 0x8D, 0xA1, 0xE3,
  35856. 0x75, 0xBC, 0xB3, 0xBC, 0xD1, 0x9E, 0x7B, 0xB9,
  35857. 0x83, 0xC9, 0x63, 0x66, 0xCC, 0xEA, 0x14, 0x1E,
  35858. 0xAE, 0x22, 0x07, 0x75, 0x52, 0x24, 0xC8, 0xC6,
  35859. 0xC6, 0x1F, 0x90, 0x89, 0x89, 0xCF, 0xF2, 0xF6,
  35860. 0x27, 0x98, 0xA6, 0x86, 0x45, 0x77, 0x95, 0x15,
  35861. 0xD4, 0x74, 0xDD, 0xA6, 0x1F, 0x33, 0x41, 0x42,
  35862. 0x4E, 0xDA, 0x24, 0x79, 0x60, 0x27, 0x34, 0x4E,
  35863. 0x36, 0x94, 0x14, 0x74, 0x81, 0x9A, 0x58, 0x44,
  35864. 0x2B, 0x74, 0xBF, 0x50, 0x60, 0xB8, 0x40, 0x94,
  35865. 0x4A, 0xEF, 0xDE, 0xA7, 0xA4, 0xCF, 0xFC, 0xB3,
  35866. 0x9D, 0xE2, 0x07, 0xFD, 0x9E, 0x6A, 0xC6, 0x2E,
  35867. 0x6D, 0x0D, 0xB2, 0xB4, 0x51, 0x2E, 0x20, 0x26,
  35868. 0x00, 0xB5, 0x30, 0x01, 0xA9, 0x2D, 0xE2, 0x42,
  35869. 0x02, 0x42, 0x12, 0x71, 0x24, 0xB7, 0x28, 0x94,
  35870. 0x30, 0x86, 0xDA, 0x22, 0x30, 0x00, 0x87, 0x65,
  35871. 0xCC, 0x22, 0x91, 0x1B, 0x05, 0x82, 0x03, 0x46,
  35872. 0x8A, 0xA0, 0x32, 0x26, 0x40, 0xB4, 0x84, 0xC3,
  35873. 0x14, 0x2D, 0x88, 0x14, 0x8C, 0x94, 0x92, 0x49,
  35874. 0x23, 0x15, 0x0E, 0xCA, 0x88, 0x09, 0x18, 0x94,
  35875. 0x68, 0x82, 0x38, 0x00, 0x21, 0x41, 0x28, 0x8C,
  35876. 0xB8, 0x80, 0x02, 0x09, 0x49, 0x5A, 0xB4, 0x11,
  35877. 0x9B, 0x28, 0x05, 0xE4, 0x42, 0x30, 0xCA, 0x24,
  35878. 0x80, 0xA4, 0x06, 0x2A, 0xD3, 0x92, 0x05, 0x1C,
  35879. 0x03, 0x6A, 0x22, 0x36, 0x4A, 0x92, 0x44, 0x52,
  35880. 0xE2, 0x48, 0x28, 0x19, 0x83, 0x68, 0x88, 0xC6,
  35881. 0x31, 0x41, 0x90, 0x50, 0x00, 0x43, 0x8E, 0x23,
  35882. 0x87, 0x60, 0x19, 0x43, 0x81, 0x50, 0x32, 0x69,
  35883. 0x81, 0xC0, 0x51, 0x12, 0x06, 0x08, 0x02, 0x08,
  35884. 0x82, 0xC4, 0xA6, 0x81, 0x03, 0xA5, 0x90, 0x8C,
  35885. 0xB6, 0x00, 0x90, 0x14, 0x66, 0x01, 0xB1, 0x08,
  35886. 0x12, 0x25, 0x48, 0x1A, 0x88, 0x11, 0x43, 0x38,
  35887. 0x60, 0x23, 0x26, 0x2E, 0x14, 0x45, 0x0D, 0x9C,
  35888. 0x92, 0x8C, 0xA2, 0x46, 0x12, 0x94, 0xA6, 0x05,
  35889. 0x88, 0xB0, 0x11, 0x0A, 0xB0, 0x28, 0xA4, 0x42,
  35890. 0x09, 0x9C, 0x82, 0x80, 0x1A, 0x80, 0x61, 0x59,
  35891. 0xB0, 0x8D, 0x40, 0xA6, 0x6D, 0x12, 0xC9, 0x0C,
  35892. 0xD9, 0x18, 0x68, 0xA3, 0x84, 0x2C, 0x02, 0xB6,
  35893. 0x25, 0x01, 0x40, 0x2C, 0xD8, 0x20, 0x4D, 0x1B,
  35894. 0x35, 0x30, 0x11, 0x10, 0x49, 0x63, 0x44, 0x31,
  35895. 0x8A, 0xB2, 0x70, 0x4B, 0x24, 0x28, 0xA0, 0x46,
  35896. 0x08, 0xC9, 0x06, 0x81, 0x08, 0xC5, 0x04, 0x4A,
  35897. 0xB2, 0x30, 0x08, 0x15, 0x04, 0x24, 0xA2, 0x65,
  35898. 0x9B, 0x88, 0x41, 0x19, 0x36, 0x2E, 0xE2, 0xB8,
  35899. 0x29, 0xD9, 0x12, 0x64, 0x41, 0xA6, 0x30, 0x22,
  35900. 0xB7, 0x8C, 0x93, 0x38, 0x69, 0x93, 0x30, 0x0A,
  35901. 0xC8, 0xB6, 0x85, 0x23, 0xB1, 0x8D, 0x01, 0x38,
  35902. 0x0A, 0x59, 0xA0, 0x09, 0x64, 0x12, 0x6E, 0x88,
  35903. 0x08, 0x22, 0xDB, 0x00, 0x08, 0x0C, 0x08, 0x12,
  35904. 0x99, 0x42, 0x44, 0x1B, 0x00, 0x68, 0x08, 0x13,
  35905. 0x26, 0x53, 0xA2, 0x40, 0x5A, 0x34, 0x25, 0x98,
  35906. 0x90, 0x8C, 0x00, 0x34, 0x2D, 0x93, 0x94, 0x48,
  35907. 0xC8, 0x22, 0x4C, 0xE2, 0x44, 0x29, 0xE2, 0x00,
  35908. 0x28, 0x14, 0x22, 0x40, 0x48, 0x28, 0x24, 0x22,
  35909. 0x49, 0x06, 0xCA, 0xC8, 0x0C, 0x4C, 0x12, 0x80,
  35910. 0x1B, 0xA5, 0x41, 0x11, 0x06, 0x48, 0x1B, 0x27,
  35911. 0x72, 0x20, 0x07, 0x31, 0x24, 0x10, 0x8E, 0x9C,
  35912. 0x94, 0x91, 0x1B, 0x37, 0x82, 0x51, 0x28, 0x2E,
  35913. 0x11, 0x06, 0x42, 0x01, 0x34, 0x6E, 0x8C, 0x22,
  35914. 0x25, 0x24, 0x34, 0x6A, 0x19, 0x47, 0x21, 0x23,
  35915. 0xB6, 0x09, 0x51, 0xB2, 0x31, 0x18, 0x34, 0x45,
  35916. 0x8C, 0xB8, 0x20, 0x1C, 0x19, 0x0A, 0x19, 0xB7,
  35917. 0x6D, 0x18, 0x97, 0x48, 0x09, 0x82, 0x04, 0x9C,
  35918. 0x12, 0x8A, 0x41, 0x08, 0x46, 0x24, 0x13, 0x31,
  35919. 0xD0, 0x42, 0x46, 0xC3, 0x16, 0x80, 0x51, 0x10,
  35920. 0x2E, 0x51, 0x48, 0x04, 0x5C, 0xC2, 0x64, 0x1A,
  35921. 0x10, 0x8E, 0xD9, 0x86, 0x64, 0x90, 0x24, 0x68,
  35922. 0x93, 0xB4, 0x45, 0x94, 0x30, 0x4A, 0xE3, 0x12,
  35923. 0x0C, 0x54, 0x04, 0x90, 0x03, 0x31, 0x40, 0x62,
  35924. 0x92, 0x4D, 0x5C, 0xC8, 0x10, 0x8A, 0xB8, 0x61,
  35925. 0x5C, 0x04, 0x6A, 0xC8, 0xB0, 0x85, 0x93, 0x00,
  35926. 0x05, 0xC3, 0x06, 0x69, 0x1B, 0x34, 0x8E, 0x03,
  35927. 0x84, 0x0C, 0x50, 0x00, 0x2C, 0x8C, 0x96, 0x90,
  35928. 0x08, 0x32, 0x68, 0x0B, 0x90, 0x8C, 0x02, 0x86,
  35929. 0x2D, 0x18, 0x38, 0x09, 0x1C, 0xB2, 0x21, 0x1B,
  35930. 0x48, 0x04, 0x5C, 0x10, 0x86, 0xD8, 0x34, 0x51,
  35931. 0x43, 0x84, 0x88, 0x43, 0xB2, 0x65, 0x12, 0xB6,
  35932. 0x8D, 0x03, 0x01, 0x45, 0x19, 0xB8, 0x8D, 0x92,
  35933. 0x26, 0x4E, 0x12, 0x12, 0x88, 0x52, 0xB2, 0x64,
  35934. 0x21, 0x09, 0x26, 0x49, 0x38, 0x05, 0x24, 0x11,
  35935. 0x0A, 0x22, 0x38, 0x32, 0x23, 0x31, 0x20, 0x4A,
  35936. 0x24, 0x42, 0xC4, 0xA2, 0x44, 0x20, 0x10, 0x0D,
  35937. 0xA1, 0xA8, 0x51, 0x23, 0x86, 0x84, 0x81, 0x38,
  35938. 0x8E, 0x02, 0x00, 0x4A, 0x1C, 0xB7, 0x24, 0x4C,
  35939. 0x06, 0x0A, 0x1C, 0x26, 0x4E, 0xCC, 0x22, 0x48,
  35940. 0x4C, 0x92, 0x2D, 0xC0, 0x20, 0x2D, 0xA1, 0x16,
  35941. 0x89, 0xC3, 0x44, 0x82, 0x19, 0xA7, 0x6D, 0xC4,
  35942. 0x90, 0x10, 0x01, 0x82, 0x89, 0xD8, 0x44, 0x22,
  35943. 0xD9, 0x98, 0x20, 0xC0, 0x88, 0x45, 0x88, 0x22,
  35944. 0x0C, 0x90, 0x36, 0x90, 0x90, 0xA4, 0x05, 0xD3,
  35945. 0x82, 0x21, 0xD0, 0xA6, 0x28, 0x00, 0x33, 0x25,
  35946. 0xA2, 0xC2, 0x6C, 0xD8, 0x10, 0x71, 0xD1, 0x96,
  35947. 0x50, 0xC3, 0x34, 0x08, 0x8B, 0x94, 0x2D, 0x61,
  35948. 0x88, 0x04, 0x1B, 0xC8, 0x2D, 0xE2, 0x30, 0x64,
  35949. 0x20, 0x28, 0x24, 0x1A, 0x34, 0x50, 0x10, 0x25,
  35950. 0x6A, 0x64, 0x36, 0x81, 0x09, 0xC1, 0x45, 0xE3,
  35951. 0x30, 0x80, 0xC3, 0xA6, 0x8C, 0xE0, 0xB6, 0x10,
  35952. 0xC3, 0x34, 0x8D, 0xD1, 0x06, 0x11, 0x88, 0x20,
  35953. 0x0A, 0x0A, 0xC8, 0x21, 0x20, 0x81, 0x30, 0x9C,
  35954. 0x14, 0x61, 0x9B, 0xC2, 0x50, 0x22, 0x15, 0x8D,
  35955. 0x80, 0xA0, 0x41, 0x89, 0x24, 0x41, 0x20, 0x93,
  35956. 0x40, 0x01, 0xA6, 0x09, 0x08, 0x25, 0x2E, 0xC1,
  35957. 0xC6, 0x85, 0x00, 0x17, 0x62, 0x41, 0x30, 0x32,
  35958. 0xDC, 0x06, 0x6D, 0x48, 0x88, 0x08, 0x84, 0xC8,
  35959. 0x30, 0x5B, 0x96, 0x8D, 0x42, 0xB4, 0x4C, 0xD0,
  35960. 0x34, 0x88, 0xD0, 0x04, 0x02, 0x18, 0x15, 0x52,
  35961. 0x52, 0x26, 0x30, 0x8C, 0x46, 0x28, 0x20, 0x94,
  35962. 0x4C, 0x21, 0x18, 0x00, 0xD0, 0xB2, 0x48, 0x1B,
  35963. 0x17, 0x0A, 0x09, 0x30, 0x4C, 0x44, 0xC2, 0x04,
  35964. 0x47, 0x5E, 0xF2, 0x33, 0x31, 0xFF, 0x66, 0x73,
  35965. 0xE2, 0x6E, 0x6A, 0x32, 0xF2, 0x94, 0xBE, 0xFB,
  35966. 0xD5, 0x96, 0x4F, 0xED, 0x98, 0x7A, 0x42, 0xA2,
  35967. 0x35, 0xFC, 0x5B, 0x16, 0x08, 0x61, 0x45, 0xC0,
  35968. 0xB8, 0xA8, 0x23, 0xFB, 0xC1, 0x4F, 0x1C, 0x8C,
  35969. 0xD0, 0x3F, 0xD6, 0xEE, 0xC4, 0x95, 0x28, 0x3E,
  35970. 0x03, 0x5C, 0x0D, 0xCA, 0xE5, 0x2E, 0x68, 0xF3,
  35971. 0x29, 0xDE, 0x7A, 0xDF, 0xD6, 0x4F, 0xEE, 0x0B,
  35972. 0x11, 0x6D, 0x4A, 0x14, 0xE1, 0x53, 0x94, 0xB3,
  35973. 0x1D, 0xF8, 0x8B, 0xCA, 0x10, 0xD1, 0xC9, 0x06,
  35974. 0xAA, 0x82, 0x28, 0x7C, 0x11, 0x74, 0x99, 0xE9,
  35975. 0xD8, 0xC7, 0x7D, 0x17, 0xA9, 0x5C, 0xCC, 0x14,
  35976. 0xAF, 0xF9, 0xC2, 0x05, 0xD2, 0x64, 0x80, 0xA5,
  35977. 0x70, 0xB5, 0x77, 0x0B, 0x04, 0x81, 0x99, 0xCF,
  35978. 0x3F, 0x0E, 0x1B, 0x91, 0xAB, 0x39, 0x4B, 0x1F,
  35979. 0x65, 0xD4, 0x7F, 0x92, 0x98, 0xD0, 0x96, 0xCA,
  35980. 0x25, 0xC0, 0x99, 0xBC, 0x67, 0xF4, 0x33, 0x42,
  35981. 0x63, 0xE3, 0x6B, 0xD9, 0xE6, 0x6B, 0x99, 0x8A,
  35982. 0x07, 0xDC, 0x1E, 0x18, 0x1E, 0x05, 0x38, 0x6E,
  35983. 0x96, 0x8F, 0x1C, 0xB0, 0xAB, 0x1E, 0x9A, 0x67,
  35984. 0xD5, 0xD3, 0x30, 0x11, 0x20, 0x37, 0x82, 0x24,
  35985. 0x88, 0x1F, 0x65, 0x17, 0x59, 0xEC, 0x7D, 0xBF,
  35986. 0x45, 0x78, 0x1E, 0xF8, 0xA8, 0x4D, 0xAD, 0xAF,
  35987. 0xE6, 0x13, 0xD6, 0x01, 0x69, 0x66, 0xBD, 0x88,
  35988. 0x44, 0xB6, 0xA6, 0x17, 0xAC, 0xA1, 0xEE, 0xF6,
  35989. 0x73, 0xB7, 0x74, 0xCC, 0x80, 0x7B, 0x36, 0xDD,
  35990. 0x02, 0xDD, 0x45, 0x21, 0x66, 0x86, 0x03, 0x7F,
  35991. 0x9A, 0xC0, 0xB1, 0x2F, 0x57, 0x26, 0xF2, 0x51,
  35992. 0xC5, 0x72, 0x43, 0xE2, 0xC1, 0x88, 0xF5, 0xEC,
  35993. 0xC0, 0x97, 0xE0, 0xB9, 0x89, 0xB5, 0x8A, 0x5D,
  35994. 0x80, 0x4A, 0xBF, 0xD7, 0x20, 0x25, 0x55, 0x77,
  35995. 0x66, 0x8E, 0xE3, 0x04, 0xD0, 0x1C, 0x50, 0xFE,
  35996. 0x8B, 0x6D, 0x90, 0x68, 0x53, 0xCF, 0x7A, 0x49,
  35997. 0x4F, 0xB4, 0x79, 0x91, 0xF1, 0x81, 0xB7, 0x42,
  35998. 0x0E, 0x74, 0x19, 0x9C, 0x82, 0xE7, 0x1A, 0x82,
  35999. 0x4B, 0xF8, 0xC6, 0x13, 0x1D, 0xF4, 0xD1, 0x85,
  36000. 0x6F, 0x11, 0xE7, 0x04, 0x07, 0x70, 0x72, 0x4D,
  36001. 0xE7, 0x2C, 0x81, 0x5A, 0xC0, 0x44, 0x3F, 0x2E,
  36002. 0x77, 0xEC, 0x22, 0xA1, 0x28, 0xDB, 0x18, 0xE1,
  36003. 0x18, 0x3E, 0xE7, 0x96, 0x82, 0xC4, 0x30, 0x24,
  36004. 0xC9, 0x07, 0x46, 0x6C, 0x35, 0x4B, 0x1C, 0x7B,
  36005. 0x0E, 0x0E, 0xF0, 0x9F, 0x16, 0x48, 0x7B, 0xD8,
  36006. 0xA9, 0x9C, 0x3A, 0x0A, 0x9E, 0xDB, 0xF0, 0x0F,
  36007. 0x15, 0xA5, 0xEB, 0x1C, 0x50, 0xD4, 0x27, 0x36,
  36008. 0xDB, 0x07, 0x63, 0xBD, 0x56, 0xBD, 0xFA, 0x81,
  36009. 0x09, 0x9A, 0xDE, 0xCE, 0xE8, 0x4A, 0xEA, 0x06,
  36010. 0x9C, 0x06, 0x5B, 0x67, 0x03, 0x14, 0xB9, 0xE4,
  36011. 0x8C, 0x66, 0x75, 0xA3, 0xCC, 0x69, 0x39, 0x57,
  36012. 0xDA, 0x1D, 0x21, 0xBA, 0xCE, 0xD8, 0x70, 0x02,
  36013. 0xFF, 0xF5, 0x6F, 0x25, 0x3A, 0x3D, 0xFC, 0x79,
  36014. 0xA3, 0xF0, 0x3A, 0x3F, 0x2B, 0x10, 0x51, 0x9A,
  36015. 0xCB, 0xC9, 0x1A, 0xF5, 0xF1, 0x98, 0x5B, 0x5C,
  36016. 0x87, 0x96, 0x4E, 0xC8, 0x00, 0x8A, 0x3A, 0x6E,
  36017. 0x85, 0x02, 0xA5, 0xF1, 0x69, 0x32, 0x6E, 0xC1,
  36018. 0x95, 0x68, 0xCF, 0xA8, 0xE8, 0x85, 0x55, 0x4D,
  36019. 0x6A, 0x68, 0x1F, 0x00, 0xDD, 0x26, 0xB3, 0x24,
  36020. 0xF4, 0x9D, 0xD2, 0x4D, 0x81, 0x06, 0xDA, 0xE6,
  36021. 0x4D, 0x11, 0x73, 0xDF, 0xFE, 0x4F, 0xA6, 0x22,
  36022. 0x5E, 0x6C, 0x6D, 0x5E, 0xE3, 0x59, 0xCF, 0xF4,
  36023. 0x35, 0xA0, 0x80, 0x86, 0x89, 0x49, 0xB2, 0xED,
  36024. 0x0C, 0xC7, 0x3B, 0x42, 0x06, 0x68, 0x8D, 0x90,
  36025. 0x04, 0x1A, 0xBD, 0x51, 0xF6, 0xB9, 0x29, 0x2E,
  36026. 0xB6, 0xF0, 0x79, 0x40, 0x1E, 0x6E, 0x59, 0x94,
  36027. 0xFB, 0xF5, 0x6B, 0x72, 0x82, 0x4C, 0xB6, 0xC7,
  36028. 0x2B, 0x12, 0x71, 0x77, 0xDD, 0x89, 0xCC, 0x2F,
  36029. 0x98, 0xB0, 0x93, 0x1C, 0x98, 0xCE, 0x5E, 0x89,
  36030. 0x0D, 0x95, 0x7B, 0x98, 0xE1, 0xEA, 0xDC, 0xB7,
  36031. 0xFF, 0x22, 0xC5, 0x31, 0x40, 0x9E, 0x1C, 0x80,
  36032. 0x59, 0x47, 0x01, 0x49, 0xEC, 0x81, 0xEF, 0x16,
  36033. 0x32, 0x6B, 0xB0, 0x4E, 0xE2, 0x3B, 0xA3, 0xC1,
  36034. 0x03, 0x12, 0x0D, 0xA6, 0x65, 0xDE, 0x8D, 0xB0,
  36035. 0xA0, 0xBB, 0x75, 0xEF, 0x5C, 0xDA, 0xF4, 0xEE,
  36036. 0x47, 0x6E, 0x55, 0x02, 0x38, 0xCD, 0xC1, 0xAC,
  36037. 0xDD, 0x71, 0xA6, 0x34, 0xAB, 0xCE, 0xA5, 0x5C,
  36038. 0x90, 0xFF, 0xF8, 0xE0, 0xA7, 0x87, 0xBD, 0x21,
  36039. 0x36, 0x91, 0x4F, 0x23, 0xD8, 0x75, 0x58, 0xC5,
  36040. 0xF6, 0xBA, 0xAC, 0x54, 0x6C, 0x24, 0xB1, 0x41,
  36041. 0x02, 0x02, 0xB9, 0x44, 0x31, 0x0E, 0xC4, 0xC9,
  36042. 0xC6, 0x87, 0x85, 0x36, 0x05, 0xC8, 0xAE, 0xC9,
  36043. 0xF1, 0xEF, 0x6B, 0x67, 0x52, 0xD3, 0x9A, 0x15,
  36044. 0xBF, 0xA2, 0x47, 0xEF, 0x89, 0xFC, 0x06, 0x99,
  36045. 0xA1, 0x1A, 0xE4, 0x5A, 0x75, 0xE5, 0x09, 0xD4,
  36046. 0x54, 0xE9, 0x89, 0xF2, 0x60, 0x6E, 0xAB, 0x10,
  36047. 0xF8, 0x42, 0xE4, 0xAD, 0x57, 0xC6, 0xE3, 0x65,
  36048. 0x48, 0x94, 0x14, 0x05, 0x4F, 0x62, 0x20, 0x0F,
  36049. 0x3A, 0x1E, 0xC7, 0x62, 0xDC, 0x5C, 0x8E, 0xFA,
  36050. 0x19, 0x88, 0x47, 0x5D, 0xE8, 0xC3, 0xD5, 0x8C,
  36051. 0x2B, 0x71, 0xBA, 0x11, 0x98, 0x7C, 0x0A, 0xC6,
  36052. 0x42, 0x08, 0x3B, 0xAC, 0x76, 0xFB, 0x50, 0x78,
  36053. 0x8C, 0x26, 0x8F, 0xEE, 0x7B, 0xE2, 0x59, 0x9B,
  36054. 0x34, 0x58, 0x09, 0x2A, 0x8B, 0xCB, 0x1F, 0x31,
  36055. 0x94, 0x8F, 0xE4, 0x82, 0xDF, 0x9A, 0x54, 0x5B,
  36056. 0x63, 0x85, 0x94, 0xD6, 0x7A, 0x44, 0x06, 0x91,
  36057. 0x5C, 0xCD, 0xC7, 0x55, 0x57, 0x47, 0xC0, 0x4E,
  36058. 0x72, 0xA5, 0x48, 0xAB, 0x8F, 0xEE, 0x87, 0x6B,
  36059. 0x25, 0x82, 0x61, 0x3C, 0xCA, 0xBD, 0xA9, 0x6C,
  36060. 0xF1, 0x4A, 0xAA, 0xF6, 0x71, 0x6B, 0x79, 0x0B,
  36061. 0xFE, 0x4D, 0x92, 0x32, 0xD9, 0x03, 0x70, 0xD6,
  36062. 0x0B, 0xBC, 0x18, 0x4B, 0xA3, 0x3B, 0xCF, 0x77,
  36063. 0x83, 0x16, 0xE3, 0x4B, 0x11, 0x83, 0x8D, 0x8F,
  36064. 0x71, 0xFE, 0xEA, 0xC0, 0x42, 0xF0, 0x35, 0xB0,
  36065. 0x76, 0xEA, 0xC1, 0xC2, 0x62, 0xFA, 0x9C, 0x32,
  36066. 0xBC, 0x8D, 0x69, 0xB1, 0x38, 0xB3, 0x51, 0x31,
  36067. 0x8E, 0xD1, 0xF3, 0x44, 0x95, 0x95, 0x11, 0x52,
  36068. 0x36, 0xF4, 0xCA, 0x7C, 0xBA, 0x2B, 0xA9, 0xE1,
  36069. 0x03, 0xF0, 0xF5, 0x09, 0xAB, 0x91, 0x6E, 0x48,
  36070. 0xB8, 0xAF, 0x03, 0x9B, 0xDC, 0xD5, 0x1C, 0xAB,
  36071. 0xFA, 0xCA, 0xDC, 0xEE, 0x8E, 0x49, 0x84, 0xF5,
  36072. 0x61, 0xF9, 0x7D, 0x17, 0xCB, 0xF1, 0xDE, 0x9A,
  36073. 0x7A, 0x7B, 0xDA, 0xF3, 0x26, 0xE6, 0xD8, 0xAD,
  36074. 0x90, 0xE9, 0x5B, 0xAF, 0x15, 0x45, 0xD3, 0xE2,
  36075. 0x46, 0x69, 0xD1, 0xC5, 0xF4, 0x28, 0xE0, 0x7E,
  36076. 0x2C, 0x71, 0x10, 0xFF, 0x43, 0x59, 0x80, 0x93,
  36077. 0xE6, 0xF9, 0x28, 0xA0, 0x34, 0xC6, 0x86, 0xBA,
  36078. 0xE7, 0x5A, 0x56, 0x7A, 0xE4, 0xF5, 0x20, 0xB4,
  36079. 0x4D, 0xAC, 0xB4, 0x95, 0xE5, 0xB2, 0xC6, 0x43,
  36080. 0x9E, 0x2E, 0x67, 0x8E, 0x7C, 0x05, 0x4F, 0xF7,
  36081. 0x60, 0x14, 0x88, 0xC6, 0xAE, 0x4A, 0x05, 0x36,
  36082. 0x99, 0x73, 0x55, 0x10, 0xF9, 0xDB, 0xC3, 0x4C,
  36083. 0xD7, 0x6A, 0x19, 0x94, 0xC0, 0xFE, 0x74, 0x12,
  36084. 0xC0, 0xCE, 0x95, 0x15, 0xBF, 0x60, 0x3A, 0x8E,
  36085. 0xB5, 0xFC, 0x8A, 0xBC, 0xAC, 0x9F, 0x15, 0x10,
  36086. 0x44, 0x73, 0x58, 0x60, 0x5D, 0xA1, 0x33, 0xFD,
  36087. 0xDE, 0xBD, 0xF2, 0x22, 0x69, 0xEE, 0x1D, 0x46,
  36088. 0x8E, 0x2E, 0xE8, 0x21, 0x62, 0x1D, 0x27, 0x84,
  36089. 0xC4, 0x6D, 0xA8, 0x30, 0x02, 0xA6, 0x26, 0x94,
  36090. 0xFA, 0xB1, 0xEF, 0xEC, 0x3B, 0x8D, 0x6F, 0x1B,
  36091. 0x2C, 0xCE, 0x2A, 0x4E, 0xC4, 0x28, 0x35, 0x4E,
  36092. 0x39, 0xA4, 0xF4, 0x5C, 0x96, 0x65, 0xC1, 0xB8,
  36093. 0x55, 0xA5, 0x09, 0x15, 0xBC, 0x4D, 0x3B, 0xD0,
  36094. 0x1F, 0x7F, 0xBA, 0x90, 0x20, 0xCD, 0xBD, 0xC2,
  36095. 0xC8, 0xE5, 0xC6, 0xB0, 0x6F, 0x14, 0x4E, 0x6B,
  36096. 0xEA, 0x8A, 0x24, 0x44, 0xE1, 0x0A, 0xCD, 0xB2,
  36097. 0x05, 0xF3, 0x15, 0x71, 0x7C, 0x86, 0xFC, 0xF1,
  36098. 0xFD, 0x6B, 0xA6, 0xE3, 0xFC, 0x86, 0xE3, 0xBA,
  36099. 0x56, 0x6B, 0x8F, 0xBE, 0x02, 0x9A, 0x03, 0x0C,
  36100. 0x8C, 0x69, 0xE5, 0x7C, 0x15, 0xAE, 0x13, 0x12,
  36101. 0x25, 0x2B, 0x36, 0xFB, 0x51, 0xA1, 0x61, 0x5E,
  36102. 0x37, 0x46, 0x92, 0x0C, 0x0B, 0x71, 0x5C, 0x1D,
  36103. 0xA4, 0xDB, 0x04, 0xC1, 0x08, 0xED, 0x5C, 0x44,
  36104. 0x80, 0x70, 0xC1, 0x0E, 0x63, 0x6D, 0x92, 0xC2,
  36105. 0x1E, 0x18, 0x8E, 0x71, 0x0E, 0x7C, 0x10, 0x21,
  36106. 0x1E, 0xC2, 0xCF, 0xD6, 0x38, 0x7A, 0x9B, 0x5C,
  36107. 0x9E, 0xE8, 0x82, 0x3D, 0xDD, 0x40, 0x0C, 0x96,
  36108. 0x17, 0xEF, 0xB1, 0x25, 0xBA, 0x84, 0x45, 0x4F,
  36109. 0x64, 0xA6, 0x8E, 0x2B, 0xBA, 0xF1, 0xED, 0xB3,
  36110. 0x4F, 0x92, 0x5F, 0x1A, 0x73, 0x2A, 0x2A, 0x22,
  36111. 0x68, 0x19, 0x4C, 0x8A, 0x87, 0x51, 0x75, 0x78,
  36112. 0xCF, 0x3C, 0xC5, 0x97, 0xFD, 0x77, 0x43, 0xCB,
  36113. 0xAE, 0x3D, 0x9C, 0xB6, 0x45, 0x54, 0x45, 0xF4,
  36114. 0x1B, 0x92, 0xEE, 0xF4, 0x9D, 0xC4, 0x32, 0x10,
  36115. 0x6A, 0x48, 0xAB, 0xE9, 0x47, 0xBF, 0x2B, 0x92,
  36116. 0x49, 0x84, 0x23, 0x52, 0x05, 0xA1, 0x92, 0x3B,
  36117. 0xD7, 0x78, 0x2D, 0x9A, 0x15, 0xB4, 0xD9, 0xD3,
  36118. 0x45, 0xD0, 0x69, 0xF1, 0x38, 0x4D, 0x39, 0xEA,
  36119. 0x49, 0x7E, 0xC0, 0xE7, 0x7A, 0x07, 0x88, 0x1D,
  36120. 0x1F, 0xA3, 0xAC, 0xE9, 0xC3, 0xFD, 0x6B, 0x5D,
  36121. 0xF6, 0xB2, 0xB9, 0xAA, 0x9A, 0xBE, 0xF4, 0x06,
  36122. 0xD9, 0x5E, 0x81, 0xE5, 0x68, 0xDF, 0xEA, 0x20,
  36123. 0x4C, 0xEE, 0xED, 0x42, 0xA4, 0xD3, 0x7B, 0xA8,
  36124. 0x82, 0x98, 0x0D, 0xB4, 0xC8, 0xC3, 0x43, 0x28,
  36125. 0x13, 0xE9, 0x6B, 0x11, 0x0E, 0x54, 0xE6, 0xCD,
  36126. 0x11, 0x0A, 0x01, 0x36, 0x41, 0x78, 0xC5, 0x7D,
  36127. 0x00, 0xC6, 0x8D, 0xE7, 0x7B, 0x4C, 0xE6, 0x35,
  36128. 0x57, 0x8F, 0x56, 0xA9, 0x73, 0x5A, 0xEF, 0x93,
  36129. 0xF0, 0xD8, 0x16, 0xE3, 0x44, 0x8A, 0xA0, 0xA9,
  36130. 0xF1, 0x9C, 0x2E, 0x02, 0xD1, 0x3C, 0x66, 0xDD,
  36131. 0xE5, 0x35, 0xFE, 0x81, 0x77, 0x8D, 0xC2, 0x46,
  36132. 0x64, 0x03, 0x23, 0xCC, 0x37, 0x22, 0x60, 0x68,
  36133. 0xCC, 0x7F, 0x79, 0xE8, 0x6B, 0xD0, 0xEE, 0x1C,
  36134. 0x6A, 0xC3, 0x3C, 0xEB, 0x51, 0x95, 0xFA, 0xE4,
  36135. 0x28, 0x17, 0x94, 0x49, 0x22, 0x69, 0x64, 0x98,
  36136. 0x82, 0x8B, 0x68, 0x9F, 0x69, 0x35, 0xF9, 0xBF,
  36137. 0x33, 0x22, 0xA4, 0x32, 0x0F, 0x4C, 0x26, 0xE4,
  36138. 0x8D, 0xDF, 0xAE, 0xBD, 0xF4, 0x4D, 0x01, 0xAF,
  36139. 0xA1, 0xFA, 0x3E, 0xCE, 0xD3, 0xB0, 0x5D, 0x02,
  36140. 0xDB, 0x3B, 0xB4, 0x23, 0xB8, 0x55, 0x97, 0xB5,
  36141. 0x1F, 0x25, 0x64, 0xA7, 0x5D, 0x4A, 0x8C, 0x90,
  36142. 0xD4, 0xB6, 0x85, 0x20, 0x32, 0x09, 0x37, 0x26,
  36143. 0x00, 0xD5, 0x4D, 0x98, 0x5A, 0xCF, 0x29, 0x3B,
  36144. 0x0E, 0xAF, 0x69, 0x88, 0x78, 0x18, 0xAD, 0xD1,
  36145. 0xE1, 0xB7, 0xC5, 0xD7, 0xB7, 0x5F, 0xFE, 0xB5,
  36146. 0x64, 0xE0, 0x68, 0x0B, 0x4F, 0x46, 0x7B, 0xDE,
  36147. 0x0B, 0x11, 0x7A, 0x42, 0x10, 0x86, 0x09, 0x60,
  36148. 0xB5, 0xE0, 0x22, 0x17, 0x28, 0x68, 0x7A, 0xE9,
  36149. 0xEB, 0xBC, 0x6B, 0xD5, 0x95, 0x4C, 0xE0, 0xAE,
  36150. 0x57, 0xB1, 0x45, 0xFF, 0xC2, 0x7E, 0xB6, 0xA0,
  36151. 0xD3, 0x8E, 0x46, 0x16, 0xCE, 0xBE, 0x76, 0xCE,
  36152. 0x59, 0x5B, 0xA4, 0x96, 0x1E, 0x9F, 0x80, 0xF0,
  36153. 0x06, 0x7E, 0xCD, 0x6E, 0x27, 0xB8, 0x7D, 0x26,
  36154. 0xB6, 0x60, 0xA3, 0xAB, 0x52, 0xC1, 0x37, 0x9A,
  36155. 0xDD, 0x46, 0xF5, 0xB9, 0x39, 0x75, 0xAA, 0x19,
  36156. 0xF3, 0xE4, 0xA8, 0x95, 0x4B, 0x25, 0x3F, 0x0B,
  36157. 0x44, 0x13, 0xF5, 0x82, 0x10, 0x68, 0x03, 0xD5,
  36158. 0x0F, 0x99, 0xB5, 0xB2, 0x8B, 0x85, 0x77, 0x2E,
  36159. 0x78, 0x3E, 0xEE, 0x21, 0x6E, 0xAD, 0x2D, 0xCF,
  36160. 0x95, 0x62, 0x94, 0x1C, 0x50, 0xAB, 0xC5, 0xFA,
  36161. 0x8E, 0x24, 0xB6, 0x14, 0x86, 0x46, 0x8A, 0xAA,
  36162. 0x20, 0xDF, 0x15, 0xD1, 0x72, 0xF6, 0xAC, 0x03,
  36163. 0xAF, 0xDF, 0xCD, 0x53, 0x81, 0xBA, 0xDB, 0x07,
  36164. 0x8B, 0x8E, 0xBB, 0x70, 0x91, 0x57, 0x04, 0xB9,
  36165. 0x88, 0xE5, 0x8F, 0x45, 0xD3, 0xD6, 0x31, 0x12,
  36166. 0xA5, 0xC1, 0x28, 0xC6, 0x49, 0x90, 0x0F, 0x1D,
  36167. 0x69, 0x66, 0xE3, 0x98, 0x56, 0x7D, 0xE3, 0x48,
  36168. 0xAC, 0xC0, 0xDE, 0xE4, 0x2B, 0x88, 0x01, 0x19,
  36169. 0x4E, 0x99, 0xBB, 0x1A, 0xAF, 0x02, 0x5A, 0x91,
  36170. 0xE3, 0x2C, 0xE6, 0x56, 0x4D, 0x05, 0x10, 0xB9,
  36171. 0x10, 0xF2, 0x2A, 0x27, 0xDE, 0xCF, 0x9D, 0x2E
  36172. };
  36173. static const byte msg_44[] = {
  36174. 0xB1, 0x34, 0x49, 0x15, 0xCC, 0xD6, 0x93, 0x41,
  36175. 0x6B, 0x37, 0xFE, 0xBD, 0x8D, 0xC7, 0xC7, 0xDB,
  36176. 0x9F, 0x25, 0x3E, 0x9D, 0xF5, 0x3C, 0xEC, 0x51,
  36177. 0x49, 0x23, 0xAA, 0xA2, 0x67, 0x6F, 0xBF, 0xA4,
  36178. 0xCC, 0x04, 0xFC, 0x68, 0xF9, 0xE3, 0x2F, 0x9E,
  36179. 0x86, 0x4C, 0x68, 0x95, 0xDB, 0x37, 0xE9, 0xFF,
  36180. 0xEB, 0x80, 0xF0, 0xF6, 0xB8, 0x6C, 0xB6, 0xAD,
  36181. 0x9C, 0x42, 0xF8, 0xFC, 0x75, 0x19, 0x8D, 0xD3,
  36182. 0xCC, 0xDA, 0xF5, 0x77, 0xC7, 0xB3, 0x5B, 0x8F,
  36183. 0x1B, 0xF6, 0x0A, 0xAB, 0xEA, 0x89, 0x94, 0x42,
  36184. 0x20, 0x1F, 0xBB, 0xF4, 0x42, 0x8C, 0x7E, 0xC1,
  36185. 0x7B, 0xC3, 0x1B, 0x54, 0x72, 0x4B, 0x95, 0x90,
  36186. 0xF7, 0x53, 0x1E, 0x6F, 0x79, 0x0A, 0x1F, 0xA7,
  36187. 0x74, 0x32, 0x83, 0x37, 0x2D, 0x31, 0x71, 0xB8,
  36188. 0x96, 0x6B, 0x47, 0x0A, 0xAA, 0x85, 0x26, 0xEB,
  36189. 0x4A, 0x6E, 0x81, 0xE6, 0x5A, 0xD0, 0xC2, 0x9F,
  36190. 0x2D, 0x37, 0xDD, 0x5B, 0x41, 0x2B, 0xAE, 0x68,
  36191. 0x2A, 0x66, 0x79, 0x68, 0x77, 0xC8, 0x2F, 0xFD,
  36192. 0xA9, 0x76, 0x24, 0x34, 0xEA, 0xC2, 0xC7, 0xD4,
  36193. 0xAF, 0x60, 0x9B, 0x27, 0x72, 0x49, 0x0D, 0xEE,
  36194. 0x9B, 0xFB, 0x00, 0x5D, 0x2F, 0x1A, 0x2E, 0xBB,
  36195. 0xA0, 0x32, 0xCD, 0x71, 0x59, 0xD5, 0x4B, 0xE5,
  36196. 0x96, 0xF3, 0x30, 0x68, 0xBE, 0x5D, 0x9A, 0x2D,
  36197. 0x94, 0x0C, 0x76, 0x70, 0xE6, 0x4E, 0x9A, 0xF7,
  36198. 0xD7, 0xD3, 0x3E, 0xC3, 0xAE, 0xC6, 0xF1, 0xD9,
  36199. 0xDE, 0xE3, 0x92, 0x84, 0xF0, 0x5C, 0xE0, 0x25,
  36200. 0xD1, 0x81, 0x76, 0x0D, 0x40, 0xE5, 0xC2, 0xD9,
  36201. 0xBE, 0xAE, 0x24, 0x20, 0xF4, 0x0D, 0x9F, 0x32,
  36202. 0xB7, 0xBD, 0xCD, 0x3A, 0xFB, 0x1C, 0x66, 0x0D,
  36203. 0x01, 0x71, 0x4D, 0x81, 0x37, 0x58, 0xDB, 0xB8,
  36204. 0x2C, 0x6B, 0x7E, 0x85, 0x80, 0x52, 0xB5, 0xA5,
  36205. 0x0E, 0x39, 0xE0, 0x15, 0xD3, 0xF2, 0x4A, 0x2C,
  36206. 0x64, 0xC9, 0xDD, 0xCC, 0x15, 0x0D, 0x90, 0x4F,
  36207. 0x07, 0xF6, 0x5F, 0xF6, 0x8A, 0xD0, 0x12, 0x9E,
  36208. 0xC3, 0xF8, 0x12, 0x3F, 0x3A, 0x03, 0xFC, 0x95,
  36209. 0x8A, 0xE2, 0x47, 0x8C, 0x6C, 0x6E, 0x03, 0x61,
  36210. 0x67, 0xD8, 0x51, 0x49, 0xF7, 0x9F, 0xB0, 0x3F,
  36211. 0xAA, 0xB9, 0x89, 0x7C, 0xE7, 0x3F, 0x88, 0x55,
  36212. 0xC5, 0x4C, 0x83, 0xD7, 0x53, 0xB1, 0x04, 0xB5,
  36213. 0x13, 0xD5, 0x6B, 0xC6, 0x4C, 0x3B, 0x08, 0x91,
  36214. 0x73, 0x47, 0x35, 0x13, 0x26, 0xD8, 0xEB, 0x47,
  36215. 0xCF, 0x66, 0xF1, 0x3F, 0xB9, 0x0F, 0x6A, 0xF5,
  36216. 0xA8, 0x94, 0xC7, 0x75, 0x00, 0x77, 0xA8, 0x9C,
  36217. 0xEB, 0x77, 0x22, 0xE2, 0xE6, 0x80, 0xA5, 0x9B,
  36218. 0xF8, 0x43, 0x8C, 0x52, 0x35, 0x31, 0xEA, 0x8C,
  36219. 0xC2, 0x83, 0x4F, 0xFC, 0x4E, 0xF0, 0x2D, 0x35,
  36220. 0xB8, 0x51, 0x46, 0xF2, 0xD6, 0x01, 0xD5, 0x00,
  36221. 0x99, 0x6A, 0x44, 0x10, 0x64, 0xAD, 0xCA, 0x1F,
  36222. 0x62, 0x3F, 0x2F, 0xE7, 0x45, 0x22, 0x47, 0xEF,
  36223. 0x86, 0x9D, 0x76, 0xD5, 0x78, 0x42, 0x07, 0x30,
  36224. 0x88, 0x86, 0x90, 0xB1, 0xA0, 0x08, 0xDA, 0x28,
  36225. 0x2A, 0xD1, 0x75, 0x7D, 0x21, 0x71, 0x29, 0x38,
  36226. 0x59, 0xC7, 0x3F, 0x55, 0x20, 0xB5, 0xBB, 0x48,
  36227. 0x03, 0xE7, 0xFA, 0xB0, 0x29, 0x00, 0xD2, 0x0F,
  36228. 0xE7, 0x65, 0x81, 0x8E, 0xE6, 0x24, 0xE7, 0xA1,
  36229. 0x94, 0x50, 0x9D, 0x01, 0x6B, 0x4B, 0xD7, 0x81,
  36230. 0x4E, 0xA0, 0xD5, 0x4A, 0x51, 0xEE, 0x95, 0x0A,
  36231. 0x14, 0x76, 0xD5, 0x87, 0xAA, 0x6F, 0x78, 0xC8,
  36232. 0xD2, 0xE0, 0xC8, 0xF8, 0xF2, 0x78, 0xD8, 0x2E,
  36233. 0x11, 0x90, 0x44, 0xB6, 0xBF, 0xD0, 0xBE, 0xD8,
  36234. 0x6F, 0xA4, 0x20, 0xA2, 0xC8, 0xA4, 0xEF, 0xB0,
  36235. 0x5D, 0x73, 0x06, 0xBE, 0x52, 0xF9, 0x32, 0xD8,
  36236. 0x06, 0x5D, 0xD1, 0x29, 0x23, 0x46, 0x25, 0x6E,
  36237. 0x42, 0x9D, 0xEE, 0x41, 0x9E, 0xF3, 0x7D, 0x1B,
  36238. 0x35, 0x28, 0x81, 0xDC, 0x47, 0x7F, 0x25, 0xA4,
  36239. 0x0A, 0xEB, 0x3E, 0x17, 0xE6, 0x1B, 0xCC, 0x00,
  36240. 0xD2, 0xE2, 0xA9, 0x3D, 0xEC, 0xF3, 0x00, 0xF0,
  36241. 0x81, 0x68, 0x21, 0xED, 0x49, 0xF9, 0x9B, 0x9B,
  36242. 0x8B, 0xED, 0xD9, 0x1E, 0xFA, 0x04, 0xBB, 0xB0,
  36243. 0x9A, 0xBD, 0x1D, 0x24, 0x36, 0xA7, 0xD6, 0x64,
  36244. 0x8A, 0x38, 0x3A, 0x3A, 0x8F, 0x09, 0x08, 0x0E,
  36245. 0x46, 0x7B, 0xE1, 0x03, 0x30, 0xBF, 0x62, 0x27,
  36246. 0x10, 0x74, 0xBE, 0xBD, 0x7F, 0x56, 0x39, 0x0D,
  36247. 0x1D, 0x39, 0x47, 0xF4, 0x02, 0x47, 0x6B, 0x62,
  36248. 0x6B, 0x52, 0xAC, 0xAB, 0x21, 0xAC, 0x10, 0x4A,
  36249. 0xAB, 0x59, 0x75, 0x33, 0x11, 0xD9, 0xE9, 0xE2,
  36250. 0xB2, 0x20, 0x6B, 0xA1, 0x09, 0x42, 0xB6, 0x37,
  36251. 0xE4, 0x5C, 0xE6, 0x9F, 0x54, 0xB4, 0x67, 0xBC,
  36252. 0xAE, 0xF3, 0xDC, 0x1A, 0xA2, 0x15, 0x47, 0x7B,
  36253. 0x15, 0xC8, 0x00, 0x35, 0x8E, 0x1D, 0x69, 0x04,
  36254. 0xD8, 0x9C, 0xA9, 0x6A, 0x03, 0x1A, 0x55, 0x48,
  36255. 0x6C, 0x4F, 0xC1, 0x68, 0x27, 0x26, 0x13, 0xAB,
  36256. 0x8E, 0x03, 0x50, 0x7B, 0xDD, 0xC2, 0x7E, 0x5C,
  36257. 0x8A, 0x6F, 0xBB, 0x5F, 0x8B, 0x22, 0x86, 0xA5,
  36258. 0xC5, 0x0E, 0xC5, 0x68, 0x60, 0xF6, 0xBF, 0xFF,
  36259. 0x6E, 0xBA, 0xDC, 0x21, 0x71, 0xD2, 0xEB, 0xD1,
  36260. 0x27, 0x8C, 0x58, 0x14, 0xC3, 0x2E, 0x13, 0x9E,
  36261. 0x04, 0x09, 0x61, 0xC3, 0x19, 0xC3, 0x03, 0x48,
  36262. 0x70, 0x33, 0x3B, 0x12, 0xF7, 0x3B, 0x38, 0xE7,
  36263. 0x18, 0x14, 0xA9, 0xF1, 0x60, 0x83, 0x65, 0xEB,
  36264. 0x32, 0xD5, 0x23, 0x8F, 0x6B, 0xF7, 0xD8, 0x00,
  36265. 0x21, 0xBD, 0xA3, 0x98, 0xDE, 0xD7, 0x13, 0x17,
  36266. 0xAB, 0x3C, 0xA4, 0xD7, 0xBE, 0x1D, 0xA7, 0x4A,
  36267. 0x1B, 0xC4, 0x0C, 0x9B, 0x2E, 0x34, 0x5B, 0xA7,
  36268. 0xA2, 0x3F, 0x9B, 0x2D, 0xDB, 0xAF, 0x85, 0x14,
  36269. 0x0A, 0xF9, 0x30, 0x9E, 0x86, 0x53, 0xAC, 0x24,
  36270. 0xAF, 0xD8, 0x25, 0xBC, 0x2A, 0x07, 0x2B, 0xCD,
  36271. 0x02, 0xFE, 0x3E, 0xF0, 0x0B, 0xE3, 0xF9, 0x51,
  36272. 0x5C, 0x29, 0xEB, 0x8A, 0xFB, 0xC3, 0xEF, 0xD1,
  36273. 0xF9, 0xCF, 0xDF, 0xE9, 0xEB, 0xA9, 0x49, 0x59,
  36274. 0xB5, 0x17, 0x7E, 0x28, 0x86, 0xB8, 0xD1, 0x8D,
  36275. 0xCA, 0x97, 0xF0, 0xCB, 0x80, 0x7E, 0xE3, 0xEA,
  36276. 0xE3, 0x1B, 0x48, 0xCF, 0xAC, 0x61, 0x3C, 0x2E,
  36277. 0x00, 0xAB, 0x74, 0xFB, 0x95, 0xF6, 0x64, 0xF3,
  36278. 0xCA, 0xBF, 0x6E, 0xEF, 0xCD, 0xDD, 0x6D, 0xA5,
  36279. 0xF8, 0x98, 0xEC, 0x38, 0xF2, 0xF0, 0x7D, 0x6D,
  36280. 0xCB, 0x75, 0xE0, 0x50, 0x9D, 0x13, 0x19, 0x24,
  36281. 0x07, 0x4C, 0x05, 0xF4, 0x5D, 0xCA, 0x25, 0xB7,
  36282. 0xCF, 0xE2, 0xBC, 0xFE, 0xEC, 0xAF, 0x5F, 0xC3,
  36283. 0x6C, 0xE6, 0xE3, 0xC5, 0x85, 0x43, 0x7B, 0x06,
  36284. 0x9F, 0xD2, 0xC6, 0xBB, 0xAD, 0x33, 0xD6, 0x86,
  36285. 0xBD, 0x5B, 0x9E, 0x2C, 0xA0, 0xD9, 0x8B, 0xDC,
  36286. 0x5E, 0x71, 0x7B, 0x6D, 0xF7, 0x1D, 0x40, 0x91,
  36287. 0x30, 0x8E, 0x84, 0x73, 0x9A, 0xD6, 0x7F, 0xA6,
  36288. 0x79, 0xA6, 0xCE, 0xE9, 0xA6, 0x83, 0x28, 0x4B,
  36289. 0x4F, 0xB3, 0x1B, 0x2C, 0x40, 0x8F, 0x52, 0xF0,
  36290. 0x59, 0x7D, 0x9C, 0x04, 0xEA, 0xF4, 0xAC, 0x6D,
  36291. 0xBB, 0x6C, 0x3F, 0xD6, 0x7F, 0x25, 0x39, 0xD8,
  36292. 0x87, 0xDF, 0xBC, 0xF3, 0xCA, 0xE4, 0x59, 0xFA,
  36293. 0x76, 0x66, 0x61, 0xA4, 0x8B, 0xFC, 0xFD, 0x6F,
  36294. 0x64, 0x03, 0x99, 0xD3, 0xAF, 0x07, 0x86, 0x35,
  36295. 0x99, 0x98, 0xCE, 0xFF, 0x7E, 0x9E, 0xB1, 0xB0,
  36296. 0x57, 0xA6, 0x29, 0x3D, 0xFF, 0xB7, 0xF3, 0xF2,
  36297. 0x51, 0x4B, 0x0B, 0x70, 0x29, 0x46, 0x06, 0x8A,
  36298. 0x6B, 0xBD, 0x75, 0x30, 0xD6, 0x91, 0x7F, 0xB1,
  36299. 0x1D, 0xBB, 0xAA, 0xBE, 0xD7, 0xAA, 0x46, 0x81,
  36300. 0xD7, 0x8A, 0xEA, 0x91, 0x86, 0x69, 0x2D, 0xDA,
  36301. 0x34, 0x70, 0x65, 0x2E, 0xB8, 0xA3, 0xF1, 0x44,
  36302. 0x56, 0xA5, 0xAA, 0xC4, 0x20, 0x88, 0x3B, 0x42,
  36303. 0x37, 0xB0, 0xA7, 0x2D, 0x91, 0x27, 0x63, 0xB6,
  36304. 0x7A, 0xC4, 0x13, 0x1A, 0x8A, 0x5D, 0x2F, 0x16,
  36305. 0x82, 0x96, 0xB9, 0x12, 0xD3, 0xB6, 0x61, 0xC4,
  36306. 0xE8, 0x3C, 0xE6, 0x3A, 0x61, 0xC0, 0x45, 0xEB,
  36307. 0xA5, 0x75, 0xEE, 0xB6, 0x7F, 0xB0, 0x70, 0xED,
  36308. 0x82, 0x39, 0xE5, 0x1A, 0x67, 0xD9, 0x80, 0x3C,
  36309. 0xE0, 0x0B, 0x85, 0x66, 0x74, 0xE0, 0xB7, 0x26,
  36310. 0x66, 0x26, 0xDD, 0x02, 0x15, 0xE5, 0xEF, 0x5F,
  36311. 0xDE, 0x7B, 0xF4, 0x0B, 0x99, 0x10, 0x21, 0x08,
  36312. 0xFC, 0x2D, 0xF2, 0x8B, 0xDC, 0xC8, 0xEA, 0xC6,
  36313. 0x3E, 0xFB, 0x20, 0x50, 0x1F, 0x24, 0x66, 0x99,
  36314. 0x80, 0x88, 0xC7, 0xA0, 0xB9, 0x6D, 0x1B, 0x75,
  36315. 0xC4, 0xC2, 0xE2, 0x52, 0xA0, 0xBF, 0x38, 0x01,
  36316. 0x5C, 0xA5, 0x8A, 0xDA, 0x79, 0x38, 0xAE, 0x2E,
  36317. 0xC7, 0x96, 0x6F, 0x30, 0x5B, 0xB4, 0x21, 0xC0,
  36318. 0xCD, 0x95, 0xCA, 0xD2, 0x12, 0x7D, 0xAD, 0x87,
  36319. 0x08, 0x6C, 0xC3, 0x8B, 0xF6, 0xB1, 0x5D, 0xAD,
  36320. 0x2C, 0x7C, 0x04, 0x41, 0xE5, 0x34, 0x2E, 0x4B,
  36321. 0x5A, 0xD9, 0x1E, 0x66, 0xF4, 0x23, 0xE2, 0x88,
  36322. 0x4D, 0xD9, 0x03, 0xFE, 0x6C, 0x64, 0x7D, 0x61,
  36323. 0xE6, 0x70, 0x0E, 0xA8, 0x83, 0x08, 0x07, 0xE6,
  36324. 0xFD, 0x64, 0x54, 0x3E, 0x3C, 0x6E, 0x9A, 0xD1,
  36325. 0x93, 0x37, 0x36, 0x90, 0xDE, 0x94, 0xF7, 0x16,
  36326. 0x15, 0x47, 0x94, 0xFE, 0x97, 0x5B, 0x11, 0x80,
  36327. 0xBA, 0x40, 0xAF, 0x7F, 0x05, 0xC1, 0x82, 0x91,
  36328. 0x69, 0xFD, 0xFB, 0xEC, 0x3A, 0xF7, 0xCF, 0xE1,
  36329. 0xD7, 0x9B, 0x59, 0x7E, 0xE4, 0x38, 0xA2, 0x96,
  36330. 0xEF, 0x14, 0x6A, 0x05, 0x99, 0x71, 0xE3, 0xF9,
  36331. 0x50, 0x8E, 0x35, 0x0B, 0x50, 0x71, 0x6D, 0xEC,
  36332. 0xB5, 0x1B, 0xC8, 0x80, 0x2A, 0xE6, 0x2A, 0x7F,
  36333. 0x4C, 0x2E, 0x6F, 0x7B, 0x54, 0x62, 0x0E, 0xF0,
  36334. 0x4C, 0x00, 0xF0, 0x72, 0xAE, 0x37, 0xAC, 0x32,
  36335. 0x7E, 0x26, 0xD3, 0x65, 0x76, 0x1C, 0x10, 0x46,
  36336. 0x17, 0xAE, 0xE0, 0xF3, 0x28, 0xEE, 0x97, 0xE0,
  36337. 0x86, 0x18, 0x3D, 0x46, 0xA3, 0x62, 0x1F, 0x23,
  36338. 0xF3, 0xAC, 0x27, 0x60, 0xB8, 0x85, 0x9A, 0x96,
  36339. 0x0E, 0xF1, 0x6F, 0xC1, 0xC6, 0xB1, 0x97, 0x8A,
  36340. 0x74, 0x12, 0xDD, 0x73, 0x85, 0x02, 0x9C, 0x73,
  36341. 0x61, 0xA8, 0xF7, 0x49, 0xCE, 0xBA, 0x23, 0xED,
  36342. 0xE7, 0x9A, 0x17, 0x0E, 0xA6, 0x84, 0x59, 0xF5,
  36343. 0x21, 0x66, 0xF5, 0xC5, 0x61, 0xF8, 0x88, 0x7E,
  36344. 0x62, 0x0C, 0x00, 0xC6, 0x4F, 0x06, 0xBD, 0x0A,
  36345. 0xBB, 0xCD, 0xE5, 0x11, 0x7A, 0xBC, 0xFD, 0x03,
  36346. 0xB6, 0xD1, 0xBA, 0x4F, 0x30, 0xFA, 0x96, 0x75,
  36347. 0xD8, 0x2D, 0x7A, 0x43, 0x0D, 0x58, 0x41, 0x46,
  36348. 0xBA, 0x72, 0x06, 0xCB, 0xBD, 0xD9, 0xBE, 0xA1,
  36349. 0xEA, 0x47, 0x08, 0x3D, 0xF9, 0x32, 0x23, 0x9C,
  36350. 0xAA, 0x02, 0x1D, 0xA3, 0x3E, 0x43, 0xF1, 0x68,
  36351. 0xD8, 0xBE, 0x9F, 0x0E, 0xA8, 0xA8, 0x52, 0xC4,
  36352. 0x0A, 0xDE, 0x43, 0x9D, 0x58, 0xA8, 0x05, 0xD4,
  36353. 0x74, 0xF8, 0x93, 0x21, 0x62, 0x6E, 0x33, 0x78,
  36354. 0x3C, 0x23, 0xEB, 0x60, 0x1C, 0x4C, 0x25, 0xFE,
  36355. 0x0F, 0x5E, 0x73, 0xC3, 0xAD, 0x33, 0x9A, 0x7D,
  36356. 0x69, 0x6B, 0xAB, 0x2C, 0xAA, 0x5F, 0xBF, 0x96,
  36357. 0x62, 0x3A, 0xF0, 0x63, 0x41, 0x00, 0xC7, 0x4C,
  36358. 0x81, 0x4D, 0x42, 0x43, 0x25, 0xBC, 0x30, 0xB6,
  36359. 0x0B, 0xEE, 0xFC, 0x18, 0x3E, 0x68, 0x0E, 0x64,
  36360. 0x5C, 0xD4, 0x22, 0x2A, 0xBA, 0xB5, 0xC6, 0x7E,
  36361. 0x67, 0x11, 0x1C, 0x4C, 0x03, 0x30, 0xEC, 0x0C,
  36362. 0x77, 0xB2, 0x2B, 0xBC, 0x98, 0xF7, 0x52, 0x8C,
  36363. 0x95, 0x66, 0xE1, 0x71, 0xDD, 0x26, 0xA7, 0x7F,
  36364. 0x87, 0xF3, 0x94, 0x2E, 0x0D, 0x3E, 0xFE, 0xAD,
  36365. 0x0A, 0xDA, 0x3B, 0x77, 0x49, 0xC5, 0x1D, 0xED,
  36366. 0x5F, 0xDA, 0x3F, 0xE6, 0xE7, 0x96, 0x58, 0xF1,
  36367. 0x02, 0x30, 0x68, 0xB9, 0x62, 0xD0, 0x58, 0xA2,
  36368. 0x89, 0x65, 0x12, 0x20, 0x1E, 0x4C, 0xE7, 0xB6,
  36369. 0x98, 0x12, 0x52, 0xF0, 0xE8, 0x55, 0xBC, 0xFE,
  36370. 0x1F, 0x44, 0x42, 0x36, 0xC9, 0x30, 0xE4, 0x9A,
  36371. 0x13, 0xB3, 0x7A, 0xF4, 0xF5, 0x97, 0xC0, 0x5D,
  36372. 0xCA, 0x23, 0xCC, 0x05, 0xC4, 0x3C, 0x32, 0xA2,
  36373. 0x11, 0x08, 0x17, 0xCB, 0x30, 0x6B, 0xA4, 0x7D,
  36374. 0x24, 0x5E, 0x50, 0x22, 0x2E, 0x23, 0xC6, 0x55,
  36375. 0x6B, 0xD7, 0x5D, 0x50, 0xEE, 0xF8, 0xBE, 0xB0,
  36376. 0xDE, 0x83, 0x5C, 0x8D, 0xD2, 0xE1, 0x5C, 0x70,
  36377. 0x66, 0x70, 0x59, 0x8F, 0x86, 0x50, 0x71, 0x71,
  36378. 0x04, 0x69, 0xEC, 0xB3, 0x47, 0x9E, 0xE0, 0x26,
  36379. 0xB1, 0x9F, 0xE6, 0x21, 0xAC, 0x99, 0x12, 0x6B,
  36380. 0x97, 0x9E, 0x1B, 0xA1, 0xDD, 0xA8, 0xE6, 0x11,
  36381. 0x12, 0x97, 0xC1, 0x0E, 0x4A, 0x77, 0xF5, 0x52,
  36382. 0xF8, 0x09, 0xE9, 0x01, 0x63, 0x56, 0x4E, 0xFA,
  36383. 0x24, 0x39, 0x36, 0xB9, 0xF2, 0x6E, 0x07, 0x28,
  36384. 0x7F, 0xA4, 0x07, 0x7C, 0xA2, 0x69, 0x7B, 0xED,
  36385. 0x6A, 0x4F, 0x0A, 0x95, 0x99, 0x05, 0x60, 0xE7,
  36386. 0x58, 0xD9, 0x90, 0xB4, 0xC1, 0x92, 0x0F, 0x9E,
  36387. 0x1A, 0xBE, 0x0B, 0x58, 0x96, 0x50, 0x61, 0x1C,
  36388. 0x2D, 0x5A, 0x13, 0xAA, 0x5F, 0x4E, 0x2B, 0x88,
  36389. 0xBE, 0xAB, 0x93, 0x72, 0xF4, 0x68, 0xB8, 0x30,
  36390. 0x91, 0xCD, 0x0A, 0x53, 0x8A, 0x35, 0x82, 0x93,
  36391. 0x4F, 0x66, 0xCA, 0xCD, 0xF2, 0x39, 0x98, 0xFE,
  36392. 0xC2, 0xFE, 0xFE, 0x51, 0x35, 0xF1, 0xB5, 0x62,
  36393. 0x2D, 0x1A, 0xE9, 0x43, 0x25, 0x5E, 0x05, 0xE4,
  36394. 0x8B, 0xFE, 0x91, 0x2F, 0x4F, 0x24, 0x1B, 0x2B,
  36395. 0xAC, 0x49, 0x9C, 0x14, 0xB0, 0x58, 0xA3, 0xA8,
  36396. 0xEE, 0xB9, 0xD1, 0xFA, 0x4D, 0x44, 0x2E, 0x23,
  36397. 0xFC, 0x59, 0x77, 0xA5, 0x60, 0x2E, 0xDC, 0xEB,
  36398. 0x7B, 0x7B, 0x26, 0x95, 0xE1, 0x87, 0xB7, 0x94,
  36399. 0xF8, 0x4B, 0x96, 0x63, 0x15, 0xB1, 0xBB, 0xA5,
  36400. 0xC0, 0x4A, 0x72, 0x02, 0x4A, 0x80, 0x5F, 0xB1,
  36401. 0x94, 0x73, 0xB7, 0x06, 0xB8, 0x13, 0x76, 0x42,
  36402. 0xAD, 0xB1, 0xC6, 0x6C, 0xFD, 0x64, 0xF2, 0x60,
  36403. 0xBB, 0x1B, 0x7A, 0xAD, 0xF6, 0xC2, 0x96, 0xB3,
  36404. 0x5F, 0x30, 0xB9, 0xD7, 0x70, 0x8A, 0x9D, 0x41,
  36405. 0xE7, 0x23, 0xFA, 0xD4, 0xE8, 0x72, 0xAF, 0x73,
  36406. 0xF8, 0x8C, 0x26, 0xAB, 0x65, 0x1B, 0xD5, 0x7A,
  36407. 0x21, 0xE2, 0x8C, 0xE8, 0xC2, 0x47, 0xD5, 0x8E,
  36408. 0x47, 0x9F, 0x79, 0x68, 0x87, 0x6F, 0xCE, 0xD3,
  36409. 0x5D, 0x2B, 0x87, 0xD2, 0xDF, 0x14, 0x43, 0x47,
  36410. 0x03, 0x3D, 0xF4, 0xCB, 0x50, 0xDE, 0x52, 0xD8,
  36411. 0x98, 0x41, 0x46, 0x3F, 0x5D, 0xFB, 0x6D, 0x6F,
  36412. 0xF6, 0xD9, 0xE8, 0x2B, 0xBA, 0xB3, 0xB1, 0xEC,
  36413. 0x58, 0x77, 0x8A, 0xB8, 0xF3, 0x6D, 0xBC, 0x68,
  36414. 0x22, 0xEA, 0xE3, 0x2F, 0xB6, 0xCB, 0x67, 0x30,
  36415. 0xCB, 0x33, 0x1C, 0x39, 0x5C, 0x27, 0x4A, 0xE7,
  36416. 0xE3, 0x7B, 0x40, 0x9B, 0x7C, 0x66, 0x32, 0xE7,
  36417. 0x6D, 0xAA, 0x97, 0xB8, 0x0F, 0x1E, 0x0C, 0xB4,
  36418. 0x7A, 0xA3, 0x66, 0xA8, 0xE3, 0x50, 0xEA, 0x36,
  36419. 0x74, 0x65, 0x92, 0xEC, 0x9B, 0x1E, 0x97, 0xF0,
  36420. 0x2F, 0x99, 0xD6, 0x00, 0x21, 0x37, 0x0B, 0x89,
  36421. 0x93, 0xC6, 0x80, 0xA1, 0x02, 0xDC, 0x96, 0x5D,
  36422. 0x20, 0xB7, 0x57, 0xF4, 0x17, 0x7A, 0x81, 0xBA,
  36423. 0x7B, 0x61, 0xD2, 0x88, 0xEF, 0xC5, 0xAD, 0xED,
  36424. 0x4C, 0x9A, 0x94, 0xA5, 0x7B, 0x2C, 0x6B, 0xD2,
  36425. 0x97, 0x7E, 0x23, 0x64, 0x0A, 0x66, 0x98, 0x47,
  36426. 0xEE, 0x81, 0xB1, 0x49, 0x0B, 0xE3, 0x8A, 0xC4,
  36427. 0x3E, 0x52, 0x2C, 0x8D, 0x09, 0xA2, 0x07, 0xB6,
  36428. 0x2A, 0x8B, 0x07, 0x9A, 0x24, 0x84, 0xDE, 0xD1,
  36429. 0x00, 0x63, 0xD7, 0xA1, 0x3F, 0xBF, 0x0C, 0xA8,
  36430. 0xEE, 0xDC, 0x2B, 0xF6, 0x7B, 0xD8, 0x78, 0x53,
  36431. 0x35, 0xB8, 0x29, 0x5A, 0xFE, 0x6B, 0x35, 0x6E,
  36432. 0x20, 0x62, 0x24, 0x17, 0x0E, 0x87, 0x23, 0x1A,
  36433. 0x77, 0x2D, 0x21, 0x84, 0x37, 0xBF, 0x7D, 0x68,
  36434. 0xAC, 0x2A, 0xF9, 0x3F, 0x11, 0x27, 0x18, 0x4F,
  36435. 0xA2, 0x15, 0x21, 0x47, 0x9E, 0x56, 0xFF, 0x22,
  36436. 0xE8, 0x0F, 0x61, 0xBC, 0x28, 0xB8, 0xD2, 0xE7,
  36437. 0x1B, 0x3D, 0x1D, 0x94, 0x28, 0x1B, 0x69, 0x56,
  36438. 0x00, 0xC8, 0xB0, 0xFD, 0x8E, 0x1D, 0x7E, 0x81,
  36439. 0x1F, 0x4C, 0xCF, 0xE1, 0x6E, 0x3F, 0x57, 0x95,
  36440. 0xC2, 0x4A, 0xA0, 0xA0, 0x16, 0x7E, 0x30, 0x5C,
  36441. 0x28, 0x87, 0x5C, 0x8F, 0xA9, 0x38, 0x9B, 0x72,
  36442. 0xF7, 0x90, 0x86, 0xF6, 0xEC, 0xC1, 0x6C, 0x88,
  36443. 0xB0, 0x78, 0x3A, 0x58, 0x15, 0xFB, 0x6F, 0x77,
  36444. 0xCD, 0xC7, 0xCC, 0xC3, 0x8D, 0x60, 0xE7, 0x87,
  36445. 0xBE, 0x9C, 0xBF, 0xFA, 0xA6, 0x2E, 0xF9, 0x59,
  36446. 0xA5, 0xE5, 0xDC, 0xDE, 0xB6, 0x25, 0x5C, 0x8E,
  36447. 0x0D, 0x2E, 0x01, 0xFE, 0x05, 0xEF, 0xF9, 0xE7,
  36448. 0x81, 0x02, 0xBE, 0xA2, 0x91, 0x40, 0x57, 0xD3,
  36449. 0x6E, 0x3D, 0x1B, 0x48, 0x50, 0x7A, 0xB6, 0xB1,
  36450. 0x76, 0x40, 0x47, 0x0F, 0xE3, 0xF1, 0x7A, 0x8B,
  36451. 0x6A, 0x5E, 0x04, 0xE5, 0x34, 0x56, 0xC5, 0xD9,
  36452. 0xE5, 0x0F, 0x74, 0x5D, 0xE0, 0x6F, 0x9A, 0xED,
  36453. 0xF4, 0xBF, 0xCF, 0x31, 0xB0, 0xC6, 0xED, 0x12,
  36454. 0x13, 0x36, 0x54, 0xCB, 0xC8, 0xDE, 0xF7, 0xF6,
  36455. 0x60, 0x9E, 0x12, 0x2C, 0x2E, 0x4C, 0x93, 0x3E,
  36456. 0x6F, 0xCB, 0x0F, 0x3D, 0x8C, 0xCA, 0xE8, 0xCA,
  36457. 0x0B, 0x10, 0xED, 0xDA, 0xE8, 0xDB, 0x29, 0x7C,
  36458. 0x8B, 0x32, 0x31, 0xC8, 0x94, 0x34, 0xA5, 0xF5,
  36459. 0x4D, 0x01, 0x28, 0xC8, 0x3A, 0xA6, 0xFD, 0xE2,
  36460. 0x9A, 0xB7, 0x0C, 0xDA, 0x43, 0x78, 0x45, 0x45,
  36461. 0xFE, 0xE9, 0xFF, 0x6E, 0xD4, 0x44, 0xF8, 0x88,
  36462. 0x66, 0x4D, 0xD2, 0x2B, 0x2E, 0x2D, 0xF5, 0x7C,
  36463. 0xA6, 0x53, 0xB6, 0xD2, 0x10, 0xE6, 0xB4, 0x0B,
  36464. 0x7F, 0xC2, 0x1F, 0xE0, 0x63, 0x90, 0xCA, 0x5D,
  36465. 0x5E, 0x60, 0xF5, 0x8A, 0xB1, 0x4C, 0x49, 0x03,
  36466. 0xD4, 0x38, 0xAE, 0xEF, 0xB1, 0x7C, 0xA4, 0xB9,
  36467. 0x98, 0x70, 0x6A, 0x0E, 0xD6, 0xA4, 0xA6, 0xF4,
  36468. 0x74, 0xB1, 0xBA, 0x1D, 0x48, 0xCC, 0xC1, 0x14,
  36469. 0x3C, 0x84, 0xA8, 0xD2, 0xE7, 0x8D, 0xEC, 0x11,
  36470. 0x61, 0x8C, 0x76, 0xB6, 0xDA, 0x28, 0xBC, 0x39,
  36471. 0xDF, 0x68, 0xAD, 0x24, 0xA4, 0x07, 0xE1, 0x07,
  36472. 0x33, 0xDD, 0x18, 0x9D, 0x5D, 0xAA, 0x90, 0x4B,
  36473. 0xEF, 0x88, 0x18, 0x6E, 0xB6, 0x83, 0x21, 0x45,
  36474. 0x94, 0x0F, 0x15, 0xB8, 0xAC, 0xD9, 0xD1, 0x8D,
  36475. 0x4F, 0x17, 0xC8, 0xD9, 0x17, 0xB0, 0x9D, 0x54,
  36476. 0xF2, 0x5F, 0x56, 0x09, 0xD3, 0x80, 0x20, 0x77,
  36477. 0x44, 0x23, 0x90, 0xAB, 0xB6, 0x0B, 0x51, 0xA7,
  36478. 0x41, 0xC5, 0xD4, 0x42, 0x5B, 0xD4, 0x67, 0x89,
  36479. 0xE6, 0xEC, 0x1E, 0x7D, 0x22, 0xD5, 0x6E, 0x7F,
  36480. 0x34, 0xCE, 0x7A, 0x07, 0x2B, 0x63, 0x0A, 0x69,
  36481. 0x51, 0x71, 0x8C, 0x13, 0x63, 0xB8, 0x79, 0x6D,
  36482. 0x94, 0xEA, 0xAF, 0x86, 0x30, 0xD2, 0x22, 0x6C,
  36483. 0x67, 0x82, 0x6C, 0xDE, 0xEA, 0x71, 0xE8, 0xD1,
  36484. 0x36, 0xF3, 0x64, 0x2F, 0x79, 0xE6, 0x92, 0xF0,
  36485. 0x4B, 0x05, 0x14, 0x7E, 0x40, 0xCE, 0x0C, 0x53,
  36486. 0xCA, 0x08, 0xEF, 0x0A, 0xA6, 0xA5, 0x73, 0x99,
  36487. 0xFD, 0xF3, 0xED, 0xBD, 0x54, 0x56, 0x6E, 0x66,
  36488. 0xEF, 0xCC, 0xE1, 0x6F, 0x0C, 0x44, 0x76, 0x84,
  36489. 0xF5, 0x55, 0x2B, 0xA3, 0x6B, 0x20, 0x60, 0x54,
  36490. 0x3F, 0xC1, 0x35, 0x58, 0xD8, 0xD8, 0x9E, 0x18,
  36491. 0x63, 0x70, 0x73, 0xEF, 0x6A, 0x87, 0x46, 0x77,
  36492. 0xA9, 0x7F, 0x9F, 0xA0, 0x23, 0x4B, 0x14, 0x00,
  36493. 0x61, 0xC7, 0xE3, 0x44, 0xBE, 0xD6, 0x09, 0x71,
  36494. 0xE3, 0x58, 0x44, 0x9A, 0xCD, 0x17, 0xE5, 0x8E,
  36495. 0x6D, 0x05, 0xBB, 0x21, 0x44, 0xD7, 0x4B, 0xD8,
  36496. 0x9A, 0xE9, 0x7A, 0x75, 0x91, 0x43, 0xAD, 0x84,
  36497. 0x5B, 0x02, 0x70, 0xBE, 0x67, 0x0B, 0x1E, 0x1E,
  36498. 0x92, 0xB8, 0xC7, 0xB6, 0x5F, 0xE1, 0x60, 0x23,
  36499. 0xF5, 0x30, 0xE4, 0xD0, 0xCF, 0x70, 0x03, 0xD1,
  36500. 0x85, 0x4A, 0x50, 0xDC, 0xF4, 0x9C, 0x29, 0xAB,
  36501. 0x0E, 0xA4, 0x7B, 0x2E, 0x3B, 0xDB, 0xBF, 0x52,
  36502. 0xD5, 0x8A, 0x91, 0x47, 0xA9, 0xD1, 0x23, 0xEB,
  36503. 0xC5, 0x6F, 0x11, 0xBB, 0xEE, 0xBB, 0x29, 0xD7,
  36504. 0x31, 0xAB, 0x99, 0x27, 0x5E, 0xF3, 0xA9, 0x23,
  36505. 0xFF, 0x70, 0x87, 0x83, 0xCC, 0x26, 0x92, 0x06,
  36506. 0xEC, 0xD3, 0x8C, 0xF9, 0x47, 0x34, 0x7D, 0x1E,
  36507. 0x71, 0xAF, 0xCF, 0x9D, 0xBF, 0x29, 0x1B, 0x95,
  36508. 0x27, 0x48, 0x55, 0xCE, 0xE2, 0xAC, 0x25, 0x61,
  36509. 0x83, 0xD9, 0x7B, 0x26, 0xEF, 0x94, 0x9A, 0x95,
  36510. 0x0C, 0xD1, 0xE4, 0x0A, 0x51, 0x50, 0x1F, 0x86,
  36511. 0x7A, 0x7B, 0xD3, 0x83, 0x55, 0x2D, 0xFC, 0x7B,
  36512. 0x97, 0x77, 0x17, 0x67, 0xBB, 0x9F, 0xD7, 0xD1,
  36513. 0xDD, 0xDD, 0x49, 0x67, 0xBB, 0xF7, 0x9A, 0x45,
  36514. 0x33, 0x24, 0xCA, 0xBC, 0xA5, 0xB2, 0x0D, 0x3F,
  36515. 0xB0, 0x10, 0x6D, 0xB9, 0x7D, 0x03, 0x3F, 0xCD,
  36516. 0x40, 0x37, 0x1E, 0x8A, 0xDA, 0xCD, 0xBA, 0xD7,
  36517. 0x8D, 0x89, 0xBD, 0x5E, 0x90, 0xCF, 0x97, 0xE8,
  36518. 0x35, 0x51, 0x87, 0x94, 0xFA, 0x3D, 0xB2, 0xB5,
  36519. 0x01, 0xF2, 0x35, 0x75, 0x77, 0x65, 0x5B, 0x9A,
  36520. 0x3C, 0xDA, 0x36, 0x52, 0xDF, 0xCF, 0x96, 0xBA,
  36521. 0xB9, 0xC5, 0xF9, 0x57, 0x67, 0x0E, 0x32, 0xE5,
  36522. 0x86, 0xE5, 0x1F, 0xD8, 0x9D, 0x7B, 0xA8, 0x76,
  36523. 0x89, 0xFD, 0x59, 0x70, 0x88, 0x73, 0x9D, 0x87,
  36524. 0xE1, 0x24, 0x6D, 0xC2, 0xB5, 0x1E, 0xCD, 0x54,
  36525. 0x29, 0x25, 0x10, 0xA3, 0xB4, 0x3C, 0xB2, 0x5A,
  36526. 0x62, 0xBD, 0xE9, 0x14, 0xEC, 0x3C, 0xBF, 0xA9,
  36527. 0x9D, 0xEC, 0x70, 0xAC, 0x23, 0xC0, 0xDF, 0xC9,
  36528. 0x69, 0xAD, 0x94, 0x1A, 0x69, 0x94, 0xA3, 0x70,
  36529. 0xF9, 0x0B, 0x15, 0x5D, 0x25, 0x45, 0x63, 0xFA,
  36530. 0xAA, 0x7D, 0x30, 0x67, 0x3C, 0x06, 0x34, 0x75,
  36531. 0x3F, 0xD6, 0x57, 0x58, 0x8E, 0xC6, 0x60, 0x3F,
  36532. 0x82, 0x35, 0xE9, 0x17, 0x36, 0x5D, 0xD8, 0x93,
  36533. 0x25, 0x25, 0x1B, 0x21, 0xB2, 0xFF, 0x80, 0xF5,
  36534. 0x44, 0xFE, 0x73, 0x84, 0xFF, 0x62, 0xFE, 0x52,
  36535. 0xC4, 0xCA, 0x77, 0x41, 0x28, 0xC8, 0x95, 0x15,
  36536. 0x2C, 0xC7, 0x5C, 0xA6, 0x3B, 0xA8, 0xF8, 0x1E,
  36537. 0x01, 0x30, 0xC9, 0x3B, 0x59, 0xF9, 0x40, 0xB7,
  36538. 0x18, 0x80, 0x21, 0x24, 0xDB, 0x8D, 0x07, 0xDF,
  36539. 0xDC, 0x24, 0xBF, 0x2F, 0x7B, 0xD9, 0xC4, 0xEF,
  36540. 0x61, 0x74, 0x1A, 0xF2, 0xB6, 0x98, 0x75, 0x66,
  36541. 0x22, 0x4F, 0x11, 0x06, 0x41, 0xDB, 0x77, 0x83,
  36542. 0xFA, 0xF3, 0x1B, 0xEC, 0xB8, 0xF7, 0x89, 0x47,
  36543. 0xBA, 0x12, 0x3F, 0xB0, 0x0E, 0x1B, 0x6D, 0x13,
  36544. 0x36, 0x0B, 0x16, 0xD0, 0x7C, 0x3A, 0xAA, 0x33,
  36545. 0x6D, 0xDA, 0x1B, 0x65, 0xD4, 0xC2, 0xF2, 0x1B,
  36546. 0xD5, 0xCD, 0x4B, 0xE9, 0xED, 0xFA, 0xFA, 0x78,
  36547. 0x45, 0x97, 0x2D, 0x60, 0xCC, 0xE3, 0x40, 0x3E,
  36548. 0xB5, 0xE5, 0xC8, 0x33, 0xF6, 0x4C, 0x51, 0x45,
  36549. 0xDC, 0x08, 0xE7, 0xB3, 0x6F, 0xCF, 0xDE, 0xE8,
  36550. 0x73, 0x0B, 0x94, 0x4F, 0x5A, 0x23, 0xF9, 0xFF,
  36551. 0x3F, 0x0D, 0x1D, 0xCE, 0x80, 0x86, 0x3B, 0x55,
  36552. 0x8D, 0x8A, 0x35, 0xB2, 0xAA, 0x65, 0x27, 0x69,
  36553. 0x1D, 0xA5, 0x0C, 0xE6, 0xFA, 0x39, 0x85, 0x62,
  36554. 0x65, 0xAD, 0xE6, 0x08, 0x38, 0xCE, 0xC9, 0xEA,
  36555. 0x98, 0x73, 0x99, 0x1D, 0xB5, 0x6F, 0xEA, 0xE8,
  36556. 0xEE, 0xE2, 0xEC, 0xF4, 0x32, 0x44, 0x96, 0x5A,
  36557. 0x13, 0xCC, 0x1D, 0x23, 0x0E, 0x91, 0x72, 0xD8,
  36558. 0x2A, 0xD2, 0x3D, 0x6A, 0x6E, 0x2A, 0x37, 0x7A,
  36559. 0x7F, 0x67, 0xF6, 0x40, 0xBF, 0x3A, 0x36, 0x3B,
  36560. 0xC8, 0x1A, 0x78, 0x6D, 0x12, 0xB0, 0x35, 0xA3,
  36561. 0x18, 0x55, 0x33, 0x70, 0x48, 0x48, 0x52, 0x8F,
  36562. 0xB4, 0x59, 0x58, 0xEB, 0xAA, 0xB3, 0x03, 0x67,
  36563. 0x4F, 0xFF, 0xA5, 0x68, 0xE7, 0xAE, 0xAF, 0x46,
  36564. 0x3D, 0x66, 0x6B, 0x60, 0x21, 0x26, 0x31, 0x83,
  36565. 0xBE, 0xE8, 0x1E, 0x72, 0x92, 0x87, 0x79, 0x24,
  36566. 0xCF, 0xDE, 0xEF, 0x6F, 0x81, 0x73, 0xA1, 0x34,
  36567. 0x7B, 0x99, 0x94, 0x43, 0x33, 0xF4, 0x8B, 0x36,
  36568. 0xC8, 0xC5, 0xF8, 0xC1, 0x6D, 0x22, 0x6D, 0xA3,
  36569. 0xC9, 0xDA, 0x5F, 0x4C, 0xE7, 0x7F, 0x00, 0xE4,
  36570. 0x42, 0xD8, 0x5C, 0x73, 0xE5, 0x78, 0x0C, 0x36,
  36571. 0x28, 0xD9, 0x83, 0x8F, 0xCA, 0xFA, 0x5D, 0x1D,
  36572. 0x34, 0x05, 0xF1, 0x93, 0x6C, 0xBC, 0xFD, 0x2C,
  36573. 0x52, 0xD4, 0xE8, 0x8D, 0xA9, 0xC9, 0x0D, 0xFF,
  36574. 0x28, 0x5E, 0x3E, 0x91, 0x12, 0xC0, 0x3C, 0xBA,
  36575. 0x58, 0x64, 0x7E, 0x6B, 0x4E, 0xC0, 0x77, 0xB1,
  36576. 0x67, 0x08, 0x16, 0xF5, 0x7E, 0x29, 0x42, 0x81,
  36577. 0x6A, 0x6F, 0x34, 0x21, 0x32, 0x64, 0x9A, 0xA6,
  36578. 0x44, 0xD1, 0x4F, 0x41, 0xAB, 0xC5, 0x26, 0x4A,
  36579. 0xFA, 0x70, 0xBC, 0xAE, 0x3D, 0x67, 0x9B, 0x86,
  36580. 0xF5, 0x1A, 0xF2, 0x44, 0x70, 0x52, 0xD0, 0x78,
  36581. 0xA0, 0xEA, 0x56, 0x39, 0x0B, 0x37, 0x2A, 0x15,
  36582. 0x13, 0xBC, 0xD2, 0xEA, 0x46, 0x6D, 0xCB, 0x5A,
  36583. 0x4D, 0x86, 0x47, 0x4F, 0xA1, 0xE2, 0x6B, 0xC0,
  36584. 0xA8, 0x3F, 0x58, 0x5C, 0x79, 0xAD, 0x62, 0x17,
  36585. 0xBC, 0x96, 0xAF, 0x77, 0x1F, 0x74, 0xD1, 0x42,
  36586. 0xBF, 0x5E, 0x91, 0xA9, 0x28, 0x44, 0xC5, 0x4E,
  36587. 0x76, 0x6B, 0xF2, 0xD3, 0x69, 0x8C, 0x0E, 0x4F,
  36588. 0x61, 0x76, 0xAD, 0xDC, 0x79, 0xE9, 0x74, 0xA4,
  36589. 0x66, 0xFB, 0x2E, 0x0C, 0xBB, 0x42, 0xC5, 0x3F,
  36590. 0x59, 0xB0, 0xDC, 0xB0, 0x32, 0xCD, 0x37, 0x56,
  36591. 0x1B, 0xD2, 0x46, 0xED, 0x52, 0xC8, 0x12, 0xEA,
  36592. 0xA3, 0x6B, 0xB9, 0xE5, 0xB3, 0x2A, 0xF3, 0x9B,
  36593. 0x0F, 0xC3, 0x77, 0x5F, 0x9A, 0xE1, 0x20, 0xBC,
  36594. 0x59, 0x44, 0x9B, 0x7B, 0x77, 0xB1, 0xBA, 0x1A,
  36595. 0x5B, 0x60, 0x06, 0x6C, 0x85, 0x83, 0x68, 0xDD,
  36596. 0x5A, 0xC8, 0xEE, 0xDC, 0xFE, 0x1F, 0x83, 0xF5,
  36597. 0x2C, 0x53, 0x62, 0xED, 0xE8, 0x93, 0xB7, 0x22,
  36598. 0x3E, 0xCB, 0x70, 0xBA, 0xA6, 0x6D, 0xB2, 0x91,
  36599. 0x47, 0xB8, 0x04, 0x37, 0x20, 0x1F, 0xEF, 0x71,
  36600. 0xB0, 0x5F, 0xF2, 0x51, 0x03, 0x5F, 0x88, 0xCA,
  36601. 0xFF, 0x42, 0xE8, 0x2A, 0x43, 0x02, 0xD3, 0x60,
  36602. 0x98, 0x26, 0x8B, 0x74, 0xF4, 0x18, 0x3D, 0x4D,
  36603. 0x19, 0xF1, 0x3B, 0x87, 0xE9, 0x83, 0x37, 0x15,
  36604. 0x7D, 0xA5, 0xEF, 0xBB, 0xF3, 0x4F, 0x48, 0xCA,
  36605. 0x40, 0x65, 0xD3, 0xE3, 0xBA, 0xCC, 0x83, 0x83,
  36606. 0x3F, 0xEE, 0xBA, 0x57, 0x34, 0x6D, 0x16, 0x9F,
  36607. 0x1B, 0xE6, 0xA0, 0x4C, 0x29, 0xC8, 0x2F, 0xD2,
  36608. 0x25, 0xA3, 0xF7, 0xC6, 0x85, 0x12, 0x4F, 0x53,
  36609. 0x7E, 0xC0, 0xE1, 0x0A, 0xB8, 0x58, 0x34, 0xBA,
  36610. 0x3E, 0x65, 0x4F, 0x19, 0x55, 0x5C, 0xB9, 0x74,
  36611. 0x6B, 0x74, 0xCE, 0x43, 0xA2, 0xC7, 0x8B, 0x21,
  36612. 0x70, 0x8C, 0x3B, 0xEF, 0x87, 0xC1, 0xE8, 0x8F,
  36613. 0x08, 0x10, 0xB4, 0xED, 0xE1, 0x81, 0x14, 0xE9,
  36614. 0x2A, 0x43, 0x13, 0xB4, 0xEA, 0xA0, 0x5F, 0x60,
  36615. 0x93, 0x7E, 0x87, 0x6D, 0xA2, 0x57, 0x63, 0x32,
  36616. 0xAE, 0xC3, 0x8C, 0xCD, 0x42, 0x5E, 0xFD, 0x51,
  36617. 0x1A, 0x39, 0xB9, 0xB4, 0xBD, 0x4C, 0xF3, 0xF2,
  36618. 0xE2, 0x70, 0x9A, 0x05, 0xF9, 0x39, 0xE5, 0xFC,
  36619. 0x59, 0x7D, 0x4E, 0x85, 0x12, 0x02, 0xC9, 0xC2,
  36620. 0xC5, 0x71, 0x3A, 0xD5, 0x73, 0xF7, 0x5A, 0xC5,
  36621. 0x49, 0x0D, 0xEE, 0xCF, 0x9D, 0xB8, 0xDE, 0xE2,
  36622. 0x03, 0x99, 0x70, 0x6B, 0x19, 0x29, 0xA4, 0xE8,
  36623. 0x99, 0x00, 0xC4, 0x9C, 0x24, 0x46, 0x5E, 0x08,
  36624. 0x09, 0x56, 0x6D, 0x9C, 0x2E, 0xF7, 0x8C, 0x52,
  36625. 0xDB, 0xB4, 0x2F, 0x9E, 0x22, 0x7E, 0xFD, 0x1E,
  36626. 0x1A, 0x72, 0xCB, 0x71, 0x0B, 0xD2, 0x19, 0x33,
  36627. 0x0E, 0x69, 0xCC, 0x00, 0x49, 0x36, 0x79, 0x78,
  36628. 0xAB, 0x11, 0x4D, 0x9A, 0xD7, 0xF9, 0x55, 0xCF,
  36629. 0x0B, 0x7B, 0x3D, 0x32, 0x5C, 0xB3, 0x51, 0x65,
  36630. 0x00, 0x0E, 0xD2, 0x9D, 0xBE, 0x0A, 0x19, 0x56,
  36631. 0xF1, 0x45, 0x95, 0x83, 0xC6, 0x97, 0xCD, 0x19,
  36632. 0xE7, 0x8B, 0x51, 0x74, 0xE4, 0xFD, 0x2C, 0xEC,
  36633. 0x10, 0x8A, 0x7C, 0x24, 0x28, 0x0A, 0x78, 0xA3,
  36634. 0xEC, 0x93, 0x97, 0x16, 0x4F, 0x60, 0x03, 0xFD,
  36635. 0x85, 0x31, 0x98, 0x04, 0xE5, 0x65, 0x5A, 0x87,
  36636. 0x9F, 0x66, 0x3D, 0xD4, 0x56, 0x3E, 0xF9, 0x98,
  36637. 0x25, 0x21, 0xFE, 0xC2, 0x07, 0x9E, 0x88, 0x89,
  36638. 0x49, 0x7B, 0xE9, 0x20, 0x1F, 0x6D, 0x7F, 0x24,
  36639. 0x60, 0xA8, 0xB2, 0xDD, 0x96, 0x51, 0x0E, 0x0E,
  36640. 0x4C, 0x83, 0xC3, 0xB1, 0x93, 0xC1, 0x1F, 0xD6,
  36641. 0xB4, 0xB6, 0x84, 0xCE, 0x85, 0x63, 0xA5, 0x38,
  36642. 0x0F, 0x2E, 0x55, 0xF4, 0x74, 0xA6, 0x0B, 0x63,
  36643. 0x17, 0xD0, 0x96, 0x76, 0x15, 0xAD, 0x4F, 0xA9,
  36644. 0xF0, 0x83, 0x25, 0xAD, 0xD7, 0x97, 0xB7, 0x9E,
  36645. 0x6F, 0x5D, 0xC7, 0x2A, 0xD1, 0x97, 0xF5, 0xF6,
  36646. 0x1E, 0xC8, 0x8B, 0xE5, 0xFB, 0xFF, 0x92, 0x72,
  36647. 0x31, 0x9A, 0x49, 0x4B, 0x60, 0x8F, 0x34, 0x7C,
  36648. 0xE1, 0x55, 0x66, 0x7A, 0x59, 0xC3, 0x00, 0x9A,
  36649. 0x14, 0x50, 0xF3, 0x06, 0x19, 0x3C, 0xFE, 0x61,
  36650. 0x1C, 0xF7, 0x05, 0x49, 0x2A, 0x30, 0xFF, 0x56,
  36651. 0xFE, 0x7F, 0x71, 0xD7, 0x32, 0xCC, 0xEF, 0x63,
  36652. 0x64, 0xE1, 0x66, 0xCF, 0xF8, 0x12, 0xED, 0x23,
  36653. 0x11, 0xB5, 0x16, 0xFA, 0x56, 0x90, 0xF2, 0xA2,
  36654. 0x72, 0x7B, 0x18, 0x50, 0xF2, 0x98, 0x5D, 0x48,
  36655. 0x25, 0x5E, 0x8C, 0x47, 0xE7, 0x11, 0x50, 0x2A,
  36656. 0x4B, 0x4A, 0x97, 0x0B, 0xDF, 0x70, 0xDC, 0x34,
  36657. 0x47, 0xF8, 0xE2, 0x88, 0x78, 0x24, 0xB5, 0x8A,
  36658. 0xC7, 0x58, 0xE8, 0x83, 0xF7, 0x3B, 0xAD, 0xFC,
  36659. 0xED, 0x46, 0x40, 0xD5, 0x46, 0x35, 0x1B, 0xF3,
  36660. 0x3E, 0x8F, 0x1E, 0x0B, 0x1B, 0xB9, 0xFB, 0x5A,
  36661. 0xFF, 0x0F, 0x8B, 0xA0, 0x95, 0x4A, 0x8E, 0x65,
  36662. 0x33, 0xD3, 0x7C, 0x03, 0x04, 0x8E, 0xBA, 0x6A,
  36663. 0x55, 0xB3, 0xC5, 0xDA, 0xCB, 0xDC, 0x44, 0xD3,
  36664. 0x98, 0x77, 0xD3, 0x07, 0x8A, 0xE9, 0x5E, 0x44,
  36665. 0x5B, 0xED, 0x12, 0xB1, 0xA5, 0x03, 0xAF, 0xB2,
  36666. 0x20, 0x0C, 0xB1, 0x8B, 0x08, 0xB4, 0x6A, 0x11,
  36667. 0x96, 0xA9, 0xF5, 0x7A, 0xFD, 0x56, 0x48, 0x11,
  36668. 0xC0, 0x30, 0xA4, 0x45, 0xFC, 0xAE, 0x72, 0xE5,
  36669. 0x5E, 0x85, 0xB7, 0x6F, 0xA0, 0x50, 0x13, 0x4B,
  36670. 0x2E, 0xC2, 0x31, 0x13, 0xED, 0x04, 0x04, 0x3D,
  36671. 0xBC, 0xD0, 0xB6, 0xFC, 0xCE, 0xBD, 0xC9, 0x13,
  36672. 0x5C, 0xB2, 0x02, 0xB8, 0x4F, 0xDD, 0x74, 0x51,
  36673. 0x1F, 0x9E, 0x8F, 0x0C, 0xF2, 0x26, 0xE1, 0x4C,
  36674. 0xA5, 0xC4, 0x38, 0xC7, 0x6A, 0xA5, 0xC3, 0xC2,
  36675. 0xE9, 0xF3, 0x22, 0x71, 0x00, 0x91, 0x83, 0xEE,
  36676. 0x92, 0xA9, 0x95, 0x81, 0x9D, 0xB9, 0x0F, 0x66,
  36677. 0x89, 0x9B, 0xB9, 0xB0, 0xC7, 0xED, 0x31, 0xDF,
  36678. 0x41, 0xB6, 0x8E, 0x52, 0xAC, 0x5B, 0xBD, 0xF2,
  36679. 0x33, 0x9F, 0x71, 0x5E, 0x43, 0xFE, 0xED, 0xD9,
  36680. 0x4F, 0x57, 0xF9, 0x23, 0x05, 0x23, 0x03, 0x34,
  36681. 0x17, 0xE4, 0x22, 0x27, 0x97, 0xF7, 0x62, 0x5B,
  36682. 0x52, 0x66, 0x70, 0xEE, 0x6B, 0xD3, 0x46, 0x8C,
  36683. 0xCD, 0x9B, 0xA4, 0xA1, 0xED, 0x26, 0x4A, 0xAC,
  36684. 0xC2, 0x50, 0xA8, 0x2A, 0x48, 0x83, 0x46, 0xB2,
  36685. 0xA5, 0xF9, 0x26, 0xF2, 0xE7, 0x8A, 0x8E, 0xD8,
  36686. 0x40, 0x5F, 0x85, 0x8E, 0xAB, 0xB0, 0x29, 0xF7,
  36687. 0x81, 0x42, 0xA7, 0x4B, 0xD5, 0xA8, 0x2D, 0x3D,
  36688. 0xD7, 0x0A, 0xB1, 0x26, 0xCF, 0xA3, 0xBA, 0xD7,
  36689. 0xF5, 0x1B, 0x9E, 0x95, 0xCB, 0xC8, 0xCE, 0x75,
  36690. 0xE7, 0x7A, 0x4A, 0x1B, 0x63, 0x21, 0xB7, 0x74,
  36691. 0x77, 0x78, 0xCD, 0x03, 0x5B, 0x3B, 0xCD, 0x44,
  36692. 0x8E, 0xF1, 0xBB, 0xB6, 0xFF, 0x75, 0x52, 0x8A,
  36693. 0x7A, 0xE9, 0xAF, 0x62, 0x24, 0xA1, 0x6F, 0x4F,
  36694. 0x45, 0x03, 0x87, 0xA3, 0xED, 0xBC, 0x2E, 0x92,
  36695. 0xC0, 0xB1, 0x9C, 0x22, 0x2E, 0x35, 0xC1, 0xA5,
  36696. 0x7E, 0xC3, 0x36, 0x3B, 0x18, 0x14, 0x78, 0x6E,
  36697. 0x1D, 0x37, 0xD7, 0x92, 0xB3, 0x78, 0x26, 0x13,
  36698. 0x9A, 0xFB, 0x38, 0x1D, 0xE0, 0x4C, 0x07, 0xC4,
  36699. 0x2C, 0xD3, 0xCA, 0x78, 0xE4, 0x70, 0xC2, 0x52,
  36700. 0x7C, 0x63, 0xDB, 0x4B, 0xB4, 0x0A, 0x4B, 0x7D,
  36701. 0x20, 0x67, 0xF0, 0xF4, 0x80, 0x5B, 0x65, 0x8B,
  36702. 0x29, 0x80, 0x92, 0xF0, 0x87, 0x3D, 0x09, 0x5A,
  36703. 0x0E, 0xEA, 0x45, 0x63, 0x92, 0x99, 0xD6, 0x0D,
  36704. 0x2B, 0x58, 0xEE, 0x19, 0x03, 0x4F, 0x94, 0x2D,
  36705. 0xEC, 0xBF, 0x5A, 0xE9, 0xA6, 0x16, 0xAF, 0x72,
  36706. 0x37, 0x5C, 0x12, 0xBB, 0x7D, 0xED, 0xAA, 0x6A,
  36707. 0x7D, 0xDF, 0x9A, 0x48, 0x37, 0x37, 0x3D, 0x7B,
  36708. 0x51, 0x96, 0x0B, 0x30, 0xCE, 0x9C, 0xE7, 0x3B,
  36709. 0x3C, 0x10, 0xDE, 0x32, 0xA7, 0x86, 0x39, 0xA9,
  36710. 0x33, 0x7D, 0x9B, 0xCF, 0x15, 0x27, 0xA4, 0x36,
  36711. 0x88, 0xBD, 0xB6, 0xEB, 0x8B, 0xD0, 0x3D, 0xCA,
  36712. 0xF1, 0x02, 0x70, 0xDF, 0xC0, 0xE2, 0xF0, 0xD2,
  36713. 0x2C, 0x27, 0xE3, 0x22, 0x24, 0x33, 0x27, 0x34,
  36714. 0xCA, 0x26, 0x19, 0x74, 0x02, 0x2F, 0x7E, 0xC1,
  36715. 0x76, 0xCB, 0x12, 0xBE, 0x6F, 0x13, 0x62, 0x1F,
  36716. 0x32, 0x03, 0x65, 0xCF, 0xBB, 0x03, 0xD0, 0x4C,
  36717. 0xF2, 0x9E, 0xFE, 0x93, 0xE9, 0x1B, 0x02, 0x9B,
  36718. 0x7B, 0x26, 0xFF, 0xEE, 0xF0, 0x6F, 0xCE, 0x57,
  36719. 0xD1, 0x2B, 0xE3, 0x90, 0x2E, 0xE2, 0x71, 0x2A,
  36720. 0xBA, 0xCC, 0x3D, 0x27, 0xCE, 0xA3, 0x5A, 0xCA,
  36721. 0x15, 0x09, 0xE4, 0xD0, 0x86, 0x4F, 0xEC, 0x5A,
  36722. 0x5B, 0x41, 0xA0, 0xE0, 0x3E, 0x1D, 0xEC, 0x6F,
  36723. 0x2A, 0x33, 0x72, 0x15, 0xCD, 0xE5, 0x55, 0xD6,
  36724. 0x6F, 0x84, 0xE3, 0xD6, 0x75, 0x5D, 0xDC, 0x1C,
  36725. 0x07, 0x3D, 0x0C, 0xDC, 0xDE, 0xF8, 0x8A, 0x44,
  36726. 0x40, 0xB1, 0x76, 0x84, 0xB8, 0xE0, 0xAF, 0x9D,
  36727. 0xA2, 0xB2, 0x84, 0xAA, 0xBF, 0x61, 0x08, 0x21,
  36728. 0xE5, 0xC2, 0xC9, 0x11, 0x94, 0x2D, 0x0B, 0xD1,
  36729. 0xC6, 0x59, 0xC1, 0xEE, 0xBA, 0x8E, 0x21, 0xAF,
  36730. 0xDE, 0x32, 0x77, 0xD5, 0x07, 0x3B, 0x98, 0x39,
  36731. 0x95, 0x77, 0x03, 0x80, 0x2F, 0xA2, 0x76, 0xC8,
  36732. 0x2C, 0xC6, 0x6A, 0x00, 0xA8, 0x69, 0x77, 0xB8,
  36733. 0x87, 0x7D, 0xC0, 0x51, 0x19, 0x45, 0x14, 0xA6,
  36734. 0x33, 0xB3, 0x4D, 0x36, 0x29, 0x34, 0xE8, 0x50,
  36735. 0xC2, 0x71, 0x7A, 0x0B, 0xE5, 0x92, 0x4E, 0x86,
  36736. 0xAA, 0xDA, 0x33, 0xCF, 0x34, 0x54, 0x63, 0x2C,
  36737. 0x68, 0xA1, 0x0A, 0xEF, 0x8B, 0x5B, 0xAA, 0x10,
  36738. 0x83, 0xE9, 0x13, 0x7D, 0x29, 0x20, 0xA2, 0x5F,
  36739. 0x96, 0x9F, 0x54, 0x0B, 0x95, 0xDF, 0x59, 0x91,
  36740. 0x6C, 0x4C, 0xAC, 0xC4, 0x55, 0x98, 0x8F, 0x46,
  36741. 0x31, 0x77, 0x56, 0xCC, 0x93, 0x7E, 0xF0, 0x17,
  36742. 0x7C, 0x0F, 0xEB, 0x3F, 0x23, 0xBB, 0xD3, 0x56,
  36743. 0x9E, 0x89, 0x67, 0xC4, 0x9B, 0x95, 0xA3, 0xBF,
  36744. 0x6D, 0x9D, 0x6D, 0x7C, 0x72, 0x27, 0x20, 0x6E,
  36745. 0x28, 0x37, 0x39, 0xFC, 0x77, 0x41, 0xE9, 0xFE,
  36746. 0x64, 0xEF, 0xA0, 0x38, 0x9F, 0xC7, 0x2F, 0xDA,
  36747. 0xC8, 0x1F, 0xEB, 0x75, 0x07, 0xB8, 0x7E, 0x6B,
  36748. 0x73, 0xCE, 0x0E, 0x7C, 0x7C, 0x54, 0x06, 0x1D,
  36749. 0x48, 0x8A, 0x06, 0x53, 0x95, 0x9B, 0x75, 0x8A,
  36750. 0xFF, 0x6F, 0x7D, 0x19, 0x00, 0x17, 0x8D, 0x7C,
  36751. 0x1A, 0xEA, 0xD0, 0x79, 0x45, 0x68, 0xF9, 0x2F,
  36752. 0x8A, 0xCE, 0x98, 0xED, 0xCC, 0xE8, 0x6D, 0xE1,
  36753. 0x08, 0xA0, 0x50, 0x2C, 0x43, 0x49, 0xC4, 0x99,
  36754. 0x98, 0x31, 0xDE, 0x00, 0xE8, 0x08, 0x39, 0x0B,
  36755. 0xBB, 0xDB, 0x65, 0xEA, 0x36, 0x0F, 0xBE, 0x98,
  36756. 0xB7, 0x4A, 0x9C, 0x59, 0x34, 0x0E, 0xBB, 0xDD,
  36757. 0x6F, 0x65, 0x21, 0x39, 0x23, 0x48, 0x57, 0x7F,
  36758. 0xD4, 0x07, 0x89, 0x03, 0x01, 0xB0, 0x79, 0x27,
  36759. 0x28, 0xCC, 0xFB, 0x88, 0xC5, 0xDD, 0x47, 0x2A,
  36760. 0xDA, 0x73, 0x75, 0x9B, 0xC9, 0x99, 0xA0, 0x21,
  36761. 0x34, 0xDF, 0xB1, 0x62, 0x2F, 0x61, 0xD8, 0xB7,
  36762. 0x63, 0x2A, 0xC7, 0x7E, 0x3A, 0x98, 0x0B, 0x2C,
  36763. 0xE5, 0x66, 0xF3, 0xD5, 0x30, 0xF0, 0xBC, 0x21,
  36764. 0xC7, 0x51, 0x9B, 0xFB, 0x00, 0xBB, 0xAA, 0x9C,
  36765. 0x85, 0xC3, 0x9B, 0x0C, 0xDC, 0x5F, 0x8D, 0x1B,
  36766. 0xA1, 0x2B, 0x78, 0x82, 0xFE, 0x0F, 0x7C, 0x75,
  36767. 0x6E, 0x75, 0x56, 0x74, 0x35, 0x25, 0xE5, 0xD0,
  36768. 0xEC, 0x8E, 0xC1, 0xBD, 0x7D, 0x7A, 0xE3, 0xDC,
  36769. 0xAD, 0xC6, 0x8D, 0xB6, 0x0D, 0x7A, 0xA1, 0x3C,
  36770. 0xDB, 0x29, 0xFA, 0x15, 0xC0, 0xA9, 0xAF, 0x89,
  36771. 0x0F, 0x18, 0x75, 0xE3, 0x97, 0x58, 0x62, 0x12,
  36772. 0x79, 0xA9, 0x87, 0x7D, 0x9C, 0x69, 0x44, 0x9C,
  36773. 0x41, 0x39, 0x2C, 0xAD, 0x98, 0x8B, 0x8D, 0xE4,
  36774. 0x58, 0xEE, 0xCD, 0x98, 0x38, 0x5F, 0x79, 0x73,
  36775. 0x0B, 0x5E, 0x26, 0xC1, 0x16, 0x24, 0x15, 0xD9,
  36776. 0x73, 0x26, 0x41, 0x9B, 0x5F, 0xF9, 0x2A, 0xA8,
  36777. 0xC1, 0x33, 0x74, 0x39, 0x1D, 0xBB, 0xE7, 0x36,
  36778. 0xD9, 0x8C, 0x07, 0xAD, 0x32, 0xD6, 0x38, 0xBB,
  36779. 0x44, 0xE6, 0x77, 0xC7, 0x11, 0x05, 0xCF, 0xB5,
  36780. 0x72, 0x49, 0x68, 0x80, 0xC1, 0x67, 0x71, 0x5F,
  36781. 0x9B, 0xFF, 0x6E, 0x71, 0x1A, 0xBE, 0x5A, 0x83,
  36782. 0x25, 0x38, 0xC7, 0xE6, 0xDA, 0x88, 0x22, 0xDC,
  36783. 0xA6, 0x03, 0x02, 0xD1, 0x59, 0xC6, 0xA8, 0x2F,
  36784. 0xA4, 0x8F, 0xF8, 0x77, 0x3E, 0x0C, 0x6F, 0xA1,
  36785. 0x73, 0xE1, 0x35, 0x55, 0xB2, 0xDF, 0xBF, 0x47,
  36786. 0xB7, 0xD0, 0x8D, 0xBA, 0x35, 0x74, 0x44, 0x6B,
  36787. 0xC0, 0xA7, 0x8D, 0x30, 0x08, 0xE4, 0x41, 0xD1,
  36788. 0x55, 0x21, 0x50, 0xD9, 0x06, 0x12, 0x54, 0xB2,
  36789. 0xF3, 0xFC, 0x5A, 0x1E, 0xF3, 0xE3, 0x84, 0x33,
  36790. 0x34, 0x0B, 0xB5, 0x9A, 0x97, 0xFD, 0x51, 0xF4,
  36791. 0x68, 0xFE, 0x8A, 0x92, 0xBF, 0x62, 0x9D, 0xCD,
  36792. 0x00, 0x29, 0x39, 0x37, 0x12, 0xF3, 0x53, 0x6D,
  36793. 0x6B, 0x24, 0xB8, 0x86, 0x68, 0xAD, 0x6A, 0x4B,
  36794. 0x3A, 0x4C, 0x93, 0xA6, 0xB1, 0x41, 0xFA, 0x8E,
  36795. 0x58, 0x63, 0xCD, 0x59, 0x80, 0xBF, 0xD7, 0xAB,
  36796. 0x83, 0xC3, 0xCC, 0x5D, 0x2F, 0xBE, 0x80, 0xC7,
  36797. 0xB1, 0x67, 0xDC, 0x92, 0x8C, 0xA9, 0x57, 0x36,
  36798. 0x58, 0x0A, 0x52, 0x96, 0x0E, 0x20, 0x90, 0xCD,
  36799. 0x87, 0x68, 0xF5, 0x93, 0xBB, 0x04, 0xD4, 0x48,
  36800. 0xB6, 0x45, 0x30, 0xC0, 0xE3, 0xC2, 0x56, 0x8C,
  36801. 0xE3, 0xA2, 0xC6, 0x42, 0x0F, 0x81, 0xF7, 0x4D,
  36802. 0xF6, 0x88, 0x5D, 0x55, 0x07, 0x8E, 0xF1, 0xB3,
  36803. 0x83, 0xB0, 0x20, 0x85, 0x4A, 0x63, 0x6A, 0x78,
  36804. 0xA9, 0xEC, 0x13, 0x84, 0xF7, 0x4E, 0xBE, 0xB6,
  36805. 0x5F, 0x5A, 0x25, 0xFF, 0xD4, 0x14, 0x7D, 0xA7,
  36806. 0xEE, 0x40, 0xF6, 0x25, 0x7C, 0x7E, 0x34, 0xCA,
  36807. 0xC9, 0x27, 0x0E, 0xA2, 0x78, 0xB6, 0xE6, 0x08,
  36808. 0xA1, 0x9B, 0x56, 0x8D, 0x29, 0xE5, 0x8D, 0xEC,
  36809. 0xAD, 0xDA, 0xD3, 0x3C, 0x59, 0xBA, 0xDB, 0x92,
  36810. 0x52, 0x99, 0x3B, 0x31, 0x6B, 0x0B, 0x13, 0x00,
  36811. 0x79, 0x3D, 0x69, 0x85, 0x3A, 0x6B, 0x90, 0x33,
  36812. 0x96
  36813. };
  36814. static const byte rnd_44[] = {
  36815. 0x08, 0x34, 0x57, 0xD4, 0x0E, 0x25, 0x04, 0x88,
  36816. 0xA6, 0x0E, 0x76, 0x34, 0xA0, 0x1D, 0x43, 0x0A,
  36817. 0x60, 0xE8, 0x57, 0x2B, 0xA8, 0x8A, 0xED, 0xC5,
  36818. 0x54, 0x49, 0x18, 0x81, 0x37, 0x13, 0xA0, 0xB1
  36819. };
  36820. static const byte sig_44[] = {
  36821. 0x63, 0xA8, 0x23, 0x20, 0xD4, 0xCE, 0x09, 0xC4,
  36822. 0x7A, 0xD1, 0x27, 0xC5, 0xBB, 0x7F, 0x6C, 0x2D,
  36823. 0xFF, 0x15, 0x29, 0xCD, 0xAF, 0x9F, 0x74, 0x56,
  36824. 0xFF, 0xC2, 0xC6, 0xED, 0x90, 0x51, 0x17, 0xDC,
  36825. 0xAD, 0x8C, 0x08, 0x7A, 0xC0, 0xD8, 0x9E, 0x0C,
  36826. 0xE9, 0x61, 0xC0, 0x94, 0xFA, 0x9C, 0x2E, 0xDE,
  36827. 0x27, 0x9C, 0x65, 0xE6, 0x99, 0xD1, 0xD1, 0x7E,
  36828. 0xA6, 0x95, 0x98, 0x8F, 0xA1, 0xC4, 0x98, 0x3F,
  36829. 0x7E, 0x1F, 0x18, 0x86, 0x2A, 0xFE, 0xB2, 0xEC,
  36830. 0x9D, 0x0F, 0x5B, 0x0C, 0x11, 0xB2, 0xAA, 0x0B,
  36831. 0xDE, 0x95, 0x7C, 0x40, 0xA1, 0x5B, 0xFF, 0x97,
  36832. 0xD7, 0xCB, 0xCF, 0x4E, 0x59, 0xDA, 0xE9, 0xD5,
  36833. 0xA3, 0xC9, 0xF8, 0x7D, 0xDD, 0xA5, 0xB9, 0x06,
  36834. 0x9D, 0x82, 0xCC, 0x18, 0x10, 0x20, 0x80, 0x92,
  36835. 0xBC, 0xBA, 0x1C, 0x43, 0x73, 0xF2, 0xA8, 0x3E,
  36836. 0x19, 0x15, 0x80, 0x9E, 0x81, 0xD8, 0xD2, 0x06,
  36837. 0xEA, 0x78, 0x10, 0x3F, 0x68, 0x66, 0x3D, 0xBE,
  36838. 0xB1, 0x79, 0xB0, 0x28, 0x83, 0xCD, 0xD3, 0x33,
  36839. 0xEE, 0xFE, 0x6D, 0x02, 0x39, 0x17, 0xC6, 0xF2,
  36840. 0xA4, 0x6E, 0x5A, 0x5C, 0x45, 0x14, 0xF5, 0x7D,
  36841. 0xCA, 0x7B, 0x62, 0x4A, 0xF4, 0xE7, 0x71, 0x7B,
  36842. 0xD7, 0x1B, 0x51, 0x26, 0xE6, 0xDE, 0x2D, 0xC9,
  36843. 0x65, 0x24, 0x30, 0x2C, 0x08, 0x04, 0xD7, 0xBE,
  36844. 0x3A, 0xDA, 0x64, 0xAF, 0x11, 0x6F, 0xC6, 0xE7,
  36845. 0x38, 0xEF, 0xA6, 0xE6, 0x5E, 0x87, 0x90, 0xB4,
  36846. 0x0E, 0xB1, 0xB4, 0x83, 0x64, 0xD2, 0x15, 0xEF,
  36847. 0xD6, 0x1F, 0x7A, 0x44, 0x75, 0x3A, 0x95, 0x50,
  36848. 0x6E, 0x52, 0xC9, 0x9C, 0xE9, 0xB4, 0x56, 0xDC,
  36849. 0x93, 0x85, 0x92, 0xF1, 0x35, 0xEC, 0x50, 0x1B,
  36850. 0x3B, 0xCF, 0x82, 0xDA, 0x69, 0xA1, 0xDD, 0x44,
  36851. 0xE8, 0xB3, 0xC1, 0xCB, 0x8D, 0xD5, 0x13, 0xD0,
  36852. 0xF3, 0x14, 0x2C, 0x80, 0x82, 0x2C, 0x31, 0xBF,
  36853. 0x75, 0x20, 0x14, 0x39, 0x9F, 0x81, 0x79, 0x76,
  36854. 0x0F, 0xB6, 0x7D, 0xB6, 0x58, 0x1C, 0xF3, 0xE6,
  36855. 0x93, 0x5A, 0x9B, 0xE1, 0x8B, 0x92, 0xC2, 0xDB,
  36856. 0xF1, 0x89, 0xAA, 0x46, 0x67, 0xFA, 0x80, 0x45,
  36857. 0x72, 0xAA, 0xB4, 0xE2, 0x5E, 0xE9, 0xD1, 0xA7,
  36858. 0xA0, 0xD7, 0x05, 0x5C, 0xC6, 0xC7, 0x6D, 0x1D,
  36859. 0x66, 0x3D, 0x35, 0x0C, 0xB7, 0x1A, 0xFA, 0xB1,
  36860. 0xDB, 0xD0, 0xCB, 0x3A, 0x8B, 0xB7, 0x1B, 0x03,
  36861. 0x60, 0xA0, 0xA4, 0xDA, 0xD0, 0xE2, 0x3A, 0x1E,
  36862. 0xB5, 0xE4, 0x59, 0x68, 0x6A, 0x02, 0x94, 0x66,
  36863. 0x05, 0x60, 0x08, 0x64, 0xB4, 0xEE, 0x0F, 0x3A,
  36864. 0xCE, 0xFD, 0x40, 0x7B, 0x6F, 0xF5, 0x8D, 0x1E,
  36865. 0xFF, 0x0C, 0x75, 0xAF, 0xC1, 0x41, 0xC6, 0x24,
  36866. 0x1D, 0xF3, 0x76, 0x02, 0x48, 0x6B, 0xBA, 0x58,
  36867. 0xBC, 0xBB, 0xFE, 0xD3, 0x51, 0xC2, 0x68, 0x21,
  36868. 0x4B, 0x20, 0x4E, 0xAF, 0x8A, 0x0C, 0x74, 0x7F,
  36869. 0x5F, 0xB7, 0xAA, 0x43, 0xFC, 0x5A, 0x77, 0xA1,
  36870. 0x81, 0xCD, 0xBA, 0xE1, 0x31, 0x87, 0x1F, 0xA8,
  36871. 0x1F, 0x76, 0x30, 0x6C, 0xE0, 0x84, 0xCD, 0x14,
  36872. 0x4A, 0xDB, 0x67, 0xFD, 0x65, 0x8C, 0x35, 0xC0,
  36873. 0x91, 0x6C, 0x2B, 0xCF, 0x5B, 0x89, 0x29, 0x58,
  36874. 0x42, 0x9B, 0x65, 0xDB, 0x34, 0x7D, 0xD8, 0x31,
  36875. 0xC9, 0xB8, 0x0D, 0x07, 0xD1, 0x94, 0x60, 0x63,
  36876. 0x65, 0xDC, 0xB3, 0x70, 0x48, 0x46, 0x37, 0x18,
  36877. 0x4D, 0x5D, 0xE0, 0xAC, 0x77, 0xD0, 0x9E, 0xE1,
  36878. 0xD9, 0xB2, 0x2D, 0x09, 0xD6, 0xF8, 0x94, 0x96,
  36879. 0x7B, 0x43, 0xD9, 0x76, 0x36, 0xE6, 0x24, 0xA4,
  36880. 0x4A, 0xFF, 0x12, 0xFE, 0x30, 0x95, 0xD7, 0xCB,
  36881. 0xA9, 0xA0, 0x3A, 0xCA, 0xFC, 0x52, 0x57, 0xB8,
  36882. 0x20, 0x80, 0xF2, 0xD8, 0xAE, 0x3E, 0x18, 0xFC,
  36883. 0x0D, 0xE0, 0x9D, 0x01, 0x7B, 0x03, 0xAD, 0x6B,
  36884. 0xEE, 0xA4, 0xEC, 0x38, 0x40, 0xAC, 0x85, 0x42,
  36885. 0xF8, 0xCF, 0x93, 0x10, 0x8F, 0x8C, 0xFE, 0xF8,
  36886. 0x22, 0x64, 0xFC, 0xDD, 0x2C, 0xDD, 0x86, 0x97,
  36887. 0x5B, 0x3F, 0x8F, 0xDF, 0x1F, 0x58, 0x22, 0x08,
  36888. 0x26, 0x8A, 0x76, 0xE6, 0xC9, 0xFE, 0xDF, 0x42,
  36889. 0x90, 0x8D, 0x52, 0x78, 0xA2, 0xBF, 0xBD, 0x3F,
  36890. 0xD5, 0xD5, 0xDB, 0xAF, 0xDD, 0x5E, 0x2C, 0x2B,
  36891. 0x9F, 0x2E, 0xDC, 0xC1, 0xC4, 0x52, 0x96, 0x38,
  36892. 0x49, 0xCB, 0x34, 0xEC, 0x51, 0x00, 0x8D, 0x1B,
  36893. 0xF6, 0xDA, 0x50, 0xA0, 0xD1, 0x9D, 0x82, 0x34,
  36894. 0x5B, 0x78, 0x8C, 0x05, 0x40, 0xE1, 0x7B, 0x25,
  36895. 0xFF, 0xDC, 0xE8, 0xD4, 0x45, 0x3B, 0xBE, 0x75,
  36896. 0x1E, 0xDA, 0x96, 0xA4, 0x4C, 0x75, 0xFD, 0xD9,
  36897. 0x00, 0x81, 0x85, 0x7D, 0xC0, 0xF8, 0x26, 0x2A,
  36898. 0x30, 0x7B, 0x34, 0xCB, 0xEC, 0xD1, 0x56, 0x58,
  36899. 0x69, 0xA3, 0x14, 0xD6, 0x4C, 0x09, 0xDC, 0x9D,
  36900. 0x4A, 0x80, 0x26, 0x52, 0x2F, 0xDF, 0xE4, 0xCB,
  36901. 0x5B, 0x8B, 0x11, 0x05, 0xDA, 0xE0, 0xDB, 0x66,
  36902. 0xC8, 0x5B, 0xB4, 0x32, 0x1D, 0xBE, 0x76, 0x84,
  36903. 0xEB, 0x6B, 0x6F, 0x85, 0x87, 0xD8, 0x32, 0x0C,
  36904. 0x6D, 0xB3, 0x8D, 0xED, 0xD6, 0x18, 0x96, 0xED,
  36905. 0x51, 0xAB, 0x0C, 0x7F, 0x42, 0x8F, 0x19, 0xD2,
  36906. 0x55, 0xC6, 0xB0, 0xFD, 0xF5, 0x89, 0x51, 0xE5,
  36907. 0xCD, 0xB1, 0x96, 0x9C, 0xD9, 0xA7, 0x93, 0x4E,
  36908. 0xFD, 0xB9, 0xC8, 0x2E, 0x1E, 0x8D, 0x2A, 0x59,
  36909. 0xC9, 0xF7, 0x9D, 0xF1, 0xAA, 0x93, 0xE5, 0x07,
  36910. 0x1E, 0x3F, 0xAC, 0x73, 0x19, 0xFF, 0x68, 0x87,
  36911. 0x8C, 0xF2, 0x49, 0xDC, 0xBD, 0xCD, 0x10, 0x46,
  36912. 0x16, 0xCC, 0xC1, 0xC1, 0xFB, 0xD7, 0x85, 0x56,
  36913. 0x9F, 0x55, 0x87, 0x10, 0x44, 0x1B, 0x31, 0xCA,
  36914. 0xE3, 0x16, 0x7A, 0x4C, 0xD7, 0xDD, 0xD1, 0x86,
  36915. 0x26, 0xC5, 0x43, 0x62, 0x96, 0x20, 0x32, 0xE6,
  36916. 0xB7, 0xA2, 0x76, 0x05, 0x61, 0x96, 0xFC, 0x22,
  36917. 0x96, 0x7E, 0x90, 0x7C, 0x32, 0x0A, 0x7A, 0xF5,
  36918. 0x8C, 0xE3, 0xF5, 0x01, 0xC4, 0xCD, 0x31, 0x8A,
  36919. 0x70, 0x75, 0x04, 0xF1, 0xC2, 0x59, 0xE5, 0x07,
  36920. 0xA0, 0xD4, 0x7D, 0x25, 0x8E, 0x2F, 0x38, 0xE2,
  36921. 0x6A, 0x53, 0x41, 0x34, 0x7A, 0x06, 0xB5, 0x8B,
  36922. 0xB0, 0xBF, 0x21, 0xDE, 0xE6, 0x5F, 0x55, 0x6A,
  36923. 0xD4, 0x88, 0xA7, 0x36, 0xD4, 0xC6, 0x5C, 0x82,
  36924. 0xC6, 0x73, 0xC0, 0x60, 0xD7, 0xA6, 0xA0, 0x77,
  36925. 0x5C, 0xF8, 0xC3, 0x9A, 0xA1, 0x31, 0xFD, 0x64,
  36926. 0xDB, 0xB1, 0x7B, 0x72, 0x70, 0x4B, 0x7D, 0x1D,
  36927. 0x24, 0xBC, 0x5F, 0x84, 0x08, 0x3B, 0xF8, 0xA6,
  36928. 0x47, 0xEB, 0xED, 0xCF, 0xDD, 0xA0, 0x91, 0x14,
  36929. 0x26, 0x7D, 0x77, 0xCF, 0xBF, 0x39, 0x9B, 0xD9,
  36930. 0x2F, 0x3B, 0x2A, 0xA7, 0x2B, 0xBC, 0xF7, 0xDE,
  36931. 0x9D, 0x69, 0xBF, 0x90, 0xA4, 0xDE, 0x2C, 0xF8,
  36932. 0x24, 0x92, 0x7D, 0xE2, 0xB8, 0xBD, 0xF4, 0x6B,
  36933. 0x10, 0x9E, 0xD6, 0x08, 0x51, 0xC5, 0x9C, 0x44,
  36934. 0x8E, 0xCB, 0x44, 0x3F, 0x00, 0x26, 0x3C, 0x9C,
  36935. 0x25, 0xF4, 0x62, 0x74, 0xD1, 0x7C, 0x29, 0x4C,
  36936. 0xEB, 0xF2, 0x53, 0x7D, 0x8F, 0xEA, 0xBD, 0x78,
  36937. 0xEE, 0xBC, 0xBA, 0x72, 0x64, 0xA5, 0xB9, 0x45,
  36938. 0x08, 0xE0, 0xBF, 0x62, 0xEF, 0xC2, 0x1E, 0x06,
  36939. 0xE1, 0xE2, 0xFB, 0x14, 0x44, 0xC5, 0xAB, 0x6F,
  36940. 0x84, 0x7F, 0x52, 0x2F, 0x8A, 0xBE, 0xED, 0x04,
  36941. 0x6D, 0x6D, 0xDC, 0xFF, 0xBC, 0xB8, 0xC8, 0x1F,
  36942. 0xD0, 0x5D, 0x4D, 0x7F, 0x2E, 0x1B, 0xC9, 0x9B,
  36943. 0xEA, 0xF8, 0xC1, 0xAF, 0xE3, 0xE0, 0x5B, 0x36,
  36944. 0x90, 0xFE, 0xE4, 0xAA, 0x37, 0x5A, 0x3D, 0xCB,
  36945. 0x77, 0x57, 0x7C, 0xCC, 0x6E, 0x3E, 0xBE, 0x8A,
  36946. 0x98, 0x7C, 0x6D, 0x7E, 0x89, 0x60, 0x73, 0xC0,
  36947. 0xCC, 0x0C, 0x48, 0x25, 0x46, 0xB5, 0x39, 0xB4,
  36948. 0xFD, 0xF0, 0x4E, 0xED, 0x8E, 0x87, 0xF8, 0x5B,
  36949. 0x00, 0xBE, 0x43, 0xA6, 0x0B, 0x21, 0x7E, 0x96,
  36950. 0x88, 0x3B, 0x91, 0xD7, 0x88, 0x1A, 0xA0, 0xDD,
  36951. 0x3E, 0xBF, 0x5B, 0x0D, 0x08, 0xD0, 0x85, 0x4E,
  36952. 0xD4, 0x27, 0x8F, 0xC9, 0x02, 0xE0, 0x60, 0xEA,
  36953. 0x16, 0xFB, 0xC2, 0x54, 0xA5, 0x08, 0xC8, 0x6F,
  36954. 0x7A, 0xE7, 0x54, 0x93, 0xB8, 0xDD, 0xA0, 0x86,
  36955. 0xE9, 0xC1, 0xB2, 0x17, 0xF5, 0xC9, 0x11, 0x97,
  36956. 0x83, 0x66, 0x88, 0xCD, 0x2D, 0x0B, 0xB8, 0xE5,
  36957. 0x52, 0xD1, 0x13, 0x7A, 0xA7, 0xEB, 0xD5, 0xD5,
  36958. 0x60, 0x53, 0x8E, 0x9B, 0xB6, 0xB4, 0x1D, 0x06,
  36959. 0x90, 0xB0, 0x6C, 0x66, 0xD1, 0x57, 0x5B, 0x86,
  36960. 0x1C, 0x8A, 0x7D, 0x3A, 0x88, 0x4C, 0xC9, 0x88,
  36961. 0x1A, 0xC3, 0x00, 0x1F, 0x30, 0x0D, 0xF3, 0x47,
  36962. 0x62, 0x79, 0x85, 0x89, 0xF9, 0xEE, 0x5C, 0x92,
  36963. 0x43, 0x61, 0x53, 0xD8, 0xC7, 0x32, 0x55, 0x9B,
  36964. 0x33, 0x3D, 0x69, 0x8F, 0x3E, 0xC5, 0x82, 0x0E,
  36965. 0x8A, 0xA5, 0xF2, 0xE5, 0xA7, 0x69, 0xC2, 0xB4,
  36966. 0x7A, 0xFA, 0x27, 0x5F, 0xE4, 0x74, 0xAF, 0x81,
  36967. 0x37, 0xC7, 0x01, 0x9A, 0xF2, 0xE6, 0x0C, 0xA7,
  36968. 0x5E, 0xDB, 0xE4, 0x8F, 0x81, 0xA6, 0x51, 0xCE,
  36969. 0x6B, 0xAB, 0xD3, 0x37, 0x4C, 0x07, 0x72, 0xA8,
  36970. 0xAC, 0x36, 0x77, 0xB1, 0x0F, 0x54, 0x77, 0x17,
  36971. 0xC9, 0x67, 0x50, 0xDA, 0x44, 0x8B, 0xD9, 0xC7,
  36972. 0x93, 0x8C, 0x66, 0xCD, 0x6F, 0xB7, 0x5D, 0x73,
  36973. 0x2D, 0xAC, 0x83, 0x1A, 0xDC, 0xE9, 0x17, 0x6D,
  36974. 0x94, 0x85, 0x6E, 0x1B, 0xF6, 0x08, 0x38, 0xD0,
  36975. 0x9E, 0x63, 0x23, 0xA2, 0x7B, 0x16, 0x09, 0xF9,
  36976. 0xC1, 0x21, 0xF4, 0x98, 0xD2, 0xBB, 0x68, 0x58,
  36977. 0x18, 0xA0, 0x0D, 0xE7, 0xBA, 0x6B, 0x28, 0x47,
  36978. 0xC5, 0x16, 0x14, 0x9F, 0x35, 0x6E, 0xCE, 0xF0,
  36979. 0x4F, 0x34, 0xEA, 0x48, 0x35, 0x46, 0xFE, 0xEB,
  36980. 0x12, 0xEA, 0x40, 0x77, 0x62, 0x04, 0x30, 0xC3,
  36981. 0x9D, 0xBF, 0x47, 0xC0, 0x5E, 0xED, 0x5E, 0xD5,
  36982. 0x87, 0xFF, 0xF5, 0x92, 0x21, 0x7C, 0xA9, 0x5A,
  36983. 0x2C, 0x3D, 0x1E, 0x6F, 0x6F, 0xF9, 0xFF, 0x20,
  36984. 0x9F, 0x8B, 0x30, 0xA9, 0x9D, 0x56, 0xA3, 0x97,
  36985. 0x7A, 0x33, 0x17, 0x49, 0x0B, 0x2B, 0x00, 0x1F,
  36986. 0x43, 0xCD, 0x8D, 0xDD, 0x1D, 0x8F, 0xC1, 0x6A,
  36987. 0x3F, 0xA9, 0xB4, 0x31, 0x54, 0x62, 0x84, 0x5B,
  36988. 0x99, 0x5D, 0x2A, 0xB7, 0x6E, 0xA5, 0x39, 0xC7,
  36989. 0xF0, 0x4C, 0x31, 0x6C, 0x71, 0xD6, 0x00, 0xE1,
  36990. 0xAC, 0x4F, 0xD5, 0xC8, 0xC6, 0x34, 0x3B, 0xC8,
  36991. 0x05, 0x5F, 0x17, 0x00, 0xB4, 0x0E, 0xA2, 0xF1,
  36992. 0xAB, 0xE9, 0x4B, 0xE0, 0x06, 0x01, 0x3A, 0xA2,
  36993. 0x61, 0xF0, 0x72, 0x0A, 0xB7, 0x99, 0xD0, 0xFC,
  36994. 0x6D, 0xB5, 0xE9, 0xA4, 0xC3, 0xC5, 0xA7, 0xF8,
  36995. 0x2D, 0x70, 0xD2, 0x8E, 0x41, 0x0D, 0xD1, 0x64,
  36996. 0xE3, 0xE4, 0x61, 0xA4, 0x6E, 0x81, 0xFB, 0xDC,
  36997. 0xB8, 0x10, 0x84, 0x8B, 0xCE, 0xE0, 0x6F, 0x88,
  36998. 0x33, 0x25, 0x64, 0x6E, 0x1E, 0x2A, 0x69, 0x3F,
  36999. 0xA5, 0xDA, 0x7C, 0x25, 0xEB, 0x21, 0xC4, 0xEA,
  37000. 0xB8, 0x7D, 0xC7, 0x87, 0xA2, 0x67, 0x7C, 0xEB,
  37001. 0x6A, 0x26, 0xE1, 0x06, 0xFE, 0x78, 0xE1, 0x18,
  37002. 0xFF, 0x54, 0x71, 0x3E, 0x00, 0x59, 0x7B, 0xFA,
  37003. 0x52, 0x8C, 0x2A, 0xED, 0x06, 0x9A, 0x12, 0x6D,
  37004. 0xE3, 0x74, 0x6F, 0x06, 0x65, 0xE1, 0x75, 0x80,
  37005. 0x63, 0x0F, 0x70, 0x2F, 0xAB, 0xC0, 0xF1, 0xCD,
  37006. 0x7F, 0x57, 0xAA, 0x71, 0xF6, 0x38, 0xD8, 0xAF,
  37007. 0x37, 0xD3, 0xD9, 0xE0, 0xA7, 0xE9, 0x05, 0x5D,
  37008. 0xA3, 0xDF, 0x86, 0x48, 0x3F, 0x25, 0xDE, 0xBA,
  37009. 0x18, 0xCE, 0xF6, 0x99, 0xEB, 0x87, 0x70, 0xC7,
  37010. 0x85, 0x84, 0x79, 0x8A, 0xD8, 0x02, 0x8B, 0xAD,
  37011. 0xC5, 0x9D, 0x2A, 0xF9, 0xAE, 0xAE, 0x37, 0xEC,
  37012. 0x93, 0x91, 0x16, 0x10, 0x5F, 0x9F, 0x64, 0xEF,
  37013. 0x82, 0x78, 0xC6, 0x4D, 0xED, 0x3F, 0xD4, 0x33,
  37014. 0xA7, 0xB8, 0x82, 0x09, 0x16, 0xBE, 0xDC, 0x6B,
  37015. 0x7A, 0x75, 0x69, 0x8A, 0xDE, 0xD3, 0xFD, 0xE8,
  37016. 0x86, 0x75, 0x42, 0x83, 0x03, 0x57, 0x30, 0x70,
  37017. 0xA5, 0xA3, 0x85, 0x1F, 0x9F, 0x21, 0xEA, 0xC7,
  37018. 0x80, 0xFA, 0x8A, 0xA4, 0x02, 0x3E, 0x39, 0x11,
  37019. 0x48, 0x7D, 0x85, 0x2A, 0x53, 0x77, 0x43, 0x5A,
  37020. 0x5F, 0xFF, 0x9C, 0x60, 0x4B, 0x5D, 0x95, 0xB0,
  37021. 0x96, 0x8A, 0xE0, 0xEC, 0xF4, 0x43, 0x1B, 0x10,
  37022. 0x3F, 0xA6, 0xBA, 0x71, 0xC4, 0xDC, 0x81, 0x73,
  37023. 0xA2, 0xDE, 0x1F, 0x79, 0xDD, 0xB6, 0x0D, 0x2D,
  37024. 0x0C, 0x8E, 0x56, 0x55, 0xD0, 0x94, 0x44, 0x29,
  37025. 0x16, 0x92, 0x99, 0x2D, 0x99, 0xFC, 0x48, 0xF2,
  37026. 0x16, 0x0E, 0xC0, 0xAC, 0xE4, 0xC4, 0x92, 0x07,
  37027. 0xBB, 0xB7, 0x6D, 0x7F, 0x2A, 0x85, 0xE1, 0x81,
  37028. 0x02, 0xB9, 0x5A, 0x51, 0x45, 0x88, 0xF5, 0x9F,
  37029. 0x16, 0x2D, 0x33, 0xCE, 0xD6, 0x18, 0x07, 0x03,
  37030. 0xED, 0xC3, 0x6C, 0x8B, 0x33, 0x94, 0x88, 0x81,
  37031. 0x0D, 0x2E, 0xAE, 0x96, 0x25, 0xCE, 0xE3, 0x83,
  37032. 0x27, 0x1C, 0x71, 0x72, 0xEE, 0xD6, 0xB5, 0x48,
  37033. 0x69, 0x60, 0xE8, 0x99, 0x18, 0x74, 0xB0, 0x13,
  37034. 0x53, 0x59, 0x3D, 0x70, 0x70, 0xBD, 0xEB, 0x7A,
  37035. 0x9F, 0x92, 0x29, 0xAB, 0x77, 0x0E, 0xEB, 0x46,
  37036. 0x37, 0x8D, 0x57, 0xD9, 0x56, 0xDF, 0x7A, 0x86,
  37037. 0x40, 0x04, 0x02, 0x98, 0xF7, 0x00, 0xF4, 0x41,
  37038. 0x5B, 0xDD, 0x3A, 0x96, 0x15, 0xA4, 0x65, 0xDB,
  37039. 0x01, 0x28, 0x22, 0x12, 0xCF, 0x1A, 0xEC, 0x4B,
  37040. 0x0B, 0x8C, 0xB3, 0xB1, 0x7E, 0x5E, 0xFA, 0x28,
  37041. 0x6C, 0x6C, 0x04, 0x5B, 0x43, 0x9C, 0x74, 0x9F,
  37042. 0xE1, 0xD4, 0x50, 0x75, 0xD8, 0xE7, 0xA0, 0x0F,
  37043. 0xBE, 0x84, 0x48, 0xFC, 0xAC, 0xAA, 0x15, 0x3D,
  37044. 0x69, 0x70, 0x9D, 0x9F, 0xF2, 0xB9, 0x7C, 0xDB,
  37045. 0x26, 0xC0, 0xC3, 0x79, 0x28, 0x7C, 0xE6, 0x48,
  37046. 0x61, 0xAD, 0xD7, 0x89, 0xD0, 0xC8, 0x93, 0x9A,
  37047. 0x14, 0x21, 0xB0, 0x85, 0xD6, 0x23, 0x4C, 0xE1,
  37048. 0xA7, 0x49, 0xDE, 0x3D, 0xCB, 0xE8, 0xE0, 0x61,
  37049. 0x5C, 0xB3, 0xBC, 0xDC, 0x6A, 0x81, 0xA5, 0xC4,
  37050. 0x9D, 0x92, 0x85, 0x74, 0x5F, 0x1C, 0xA8, 0xA0,
  37051. 0x64, 0x1E, 0x32, 0x68, 0x83, 0x41, 0x93, 0x34,
  37052. 0x82, 0x18, 0x3E, 0x24, 0x5C, 0x1F, 0x9C, 0xD2,
  37053. 0x80, 0x28, 0xC3, 0x8A, 0x23, 0x18, 0x1A, 0x44,
  37054. 0x5A, 0xA6, 0xEA, 0xCC, 0xE2, 0x06, 0x06, 0xE6,
  37055. 0xF7, 0xF1, 0xDF, 0x70, 0x68, 0x83, 0xCD, 0xA5,
  37056. 0x2F, 0x3F, 0x2B, 0x68, 0xDE, 0x26, 0xDD, 0x37,
  37057. 0x71, 0xE9, 0x50, 0x03, 0x2C, 0xC7, 0x20, 0x0C,
  37058. 0x20, 0x23, 0xC8, 0x24, 0x96, 0x50, 0x82, 0x82,
  37059. 0xCD, 0x3B, 0xC4, 0x7F, 0xEC, 0xE5, 0xD9, 0x7C,
  37060. 0xA1, 0xCE, 0x35, 0x74, 0x4D, 0x03, 0xD7, 0xA4,
  37061. 0x28, 0xB7, 0xAF, 0x12, 0xB0, 0xCB, 0x8E, 0x65,
  37062. 0x7C, 0x01, 0x30, 0xF8, 0xA3, 0xA2, 0x54, 0x97,
  37063. 0x6E, 0xC8, 0xF7, 0xDC, 0xCF, 0x3A, 0xBF, 0x31,
  37064. 0xF4, 0xB0, 0xB3, 0xF7, 0x12, 0x6F, 0xFC, 0x48,
  37065. 0x77, 0xF3, 0xD1, 0xA0, 0x66, 0xD2, 0x6A, 0x23,
  37066. 0x2F, 0xA9, 0x99, 0x21, 0x61, 0x22, 0x54, 0x11,
  37067. 0xED, 0x7D, 0xDB, 0x93, 0xC3, 0x5C, 0x6A, 0x37,
  37068. 0x7F, 0x30, 0xCF, 0x22, 0xAA, 0x39, 0x2D, 0x5C,
  37069. 0x4F, 0xEE, 0x4F, 0x73, 0xC9, 0xEF, 0x6E, 0xD3,
  37070. 0xA0, 0x27, 0x97, 0x14, 0x52, 0x3B, 0x19, 0x18,
  37071. 0x65, 0x1E, 0x9B, 0x0F, 0xFA, 0x55, 0x0F, 0x16,
  37072. 0x10, 0x53, 0xEE, 0x78, 0x01, 0x39, 0x7B, 0x4C,
  37073. 0x18, 0x49, 0x98, 0x7C, 0x17, 0x9E, 0x76, 0x3E,
  37074. 0xCC, 0x60, 0xA4, 0xE4, 0xC5, 0x36, 0xB7, 0xE2,
  37075. 0x66, 0x3E, 0x4C, 0x72, 0x67, 0x14, 0xB0, 0x2E,
  37076. 0xC3, 0x16, 0x9E, 0x84, 0x07, 0xBA, 0x59, 0x2B,
  37077. 0x0E, 0xB8, 0x46, 0xF3, 0x69, 0x2D, 0xD4, 0x46,
  37078. 0x51, 0xEE, 0x08, 0x47, 0x21, 0xCA, 0xC0, 0xFE,
  37079. 0x1C, 0xCC, 0x30, 0x27, 0x07, 0xEF, 0xE2, 0x46,
  37080. 0x64, 0xE0, 0x5B, 0xDC, 0x69, 0xC8, 0x39, 0x04,
  37081. 0xAC, 0xB8, 0xCF, 0x97, 0x12, 0x1C, 0x7E, 0x5C,
  37082. 0x6D, 0xB2, 0x7E, 0xA2, 0x8E, 0x77, 0xBC, 0xDA,
  37083. 0x55, 0xD2, 0xBC, 0xC1, 0xC5, 0xFC, 0xC5, 0x52,
  37084. 0xAB, 0x83, 0xBC, 0xE4, 0x23, 0x8C, 0xA1, 0x80,
  37085. 0x62, 0xC2, 0xD2, 0x3A, 0x8B, 0x80, 0x0C, 0x82,
  37086. 0x09, 0xC3, 0xA4, 0xCD, 0xDA, 0xF1, 0x16, 0x16,
  37087. 0x57, 0x8A, 0x84, 0x55, 0x66, 0xFC, 0x28, 0x9A,
  37088. 0x8E, 0x3C, 0x88, 0xF5, 0x54, 0xC4, 0x92, 0x60,
  37089. 0x71, 0xDA, 0x89, 0x32, 0x6B, 0xEB, 0x25, 0x9A,
  37090. 0x0E, 0x1F, 0x6D, 0x84, 0x4E, 0xBF, 0x7B, 0x28,
  37091. 0x1F, 0x9F, 0xC3, 0x74, 0x3A, 0x65, 0x49, 0x9E,
  37092. 0x73, 0x94, 0x63, 0x48, 0x18, 0xE1, 0x33, 0xFA,
  37093. 0xC6, 0x64, 0xFA, 0x0C, 0x88, 0xF1, 0x01, 0xCE,
  37094. 0xC3, 0xFE, 0xD8, 0x79, 0x29, 0x50, 0xBF, 0x6E,
  37095. 0x49, 0x74, 0x84, 0x9E, 0x1E, 0xBD, 0x27, 0x69,
  37096. 0x1B, 0xF5, 0x51, 0x9B, 0x70, 0x2E, 0x1A, 0xA4,
  37097. 0xB3, 0xDB, 0xAD, 0xAB, 0x5D, 0xFA, 0x34, 0xFB,
  37098. 0x0E, 0xD9, 0xD4, 0xA9, 0xDF, 0x4B, 0x6B, 0x63,
  37099. 0xCA, 0x71, 0x65, 0xE2, 0xA9, 0x08, 0x27, 0x40,
  37100. 0x8C, 0x48, 0x2D, 0x9D, 0xBC, 0x97, 0x24, 0x68,
  37101. 0x58, 0x4F, 0x42, 0x37, 0x60, 0x04, 0xE7, 0x8B,
  37102. 0xE0, 0x67, 0x00, 0x9E, 0x43, 0x30, 0x4B, 0xED,
  37103. 0xC1, 0x07, 0xA4, 0xE2, 0xA8, 0x9C, 0xAF, 0x18,
  37104. 0x5C, 0x9B, 0xB7, 0xE9, 0xFD, 0x2C, 0xB9, 0x2A,
  37105. 0xEF, 0x36, 0x3B, 0xD7, 0x96, 0xF3, 0x60, 0x4E,
  37106. 0xDC, 0x08, 0xA7, 0xC5, 0x45, 0xB8, 0x37, 0x02,
  37107. 0xD3, 0xCF, 0x80, 0x88, 0x52, 0x10, 0x3E, 0x01,
  37108. 0x3B, 0xFE, 0xA1, 0x61, 0xAF, 0x25, 0x0B, 0xCC,
  37109. 0x72, 0x77, 0x1D, 0x0C, 0x48, 0x4D, 0xD5, 0x55,
  37110. 0x41, 0x72, 0x3A, 0x21, 0x0D, 0x68, 0x3B, 0x99,
  37111. 0x8C, 0xDB, 0xAF, 0x3D, 0x9A, 0x5E, 0x71, 0x78,
  37112. 0x6F, 0x1C, 0xF4, 0x7B, 0x86, 0x22, 0x51, 0xB5,
  37113. 0x16, 0x33, 0x60, 0x87, 0x9A, 0xC0, 0x20, 0x2D,
  37114. 0x33, 0x49, 0x51, 0x54, 0x5C, 0x5F, 0x71, 0x76,
  37115. 0x7C, 0x8F, 0x96, 0xA9, 0xD6, 0xE4, 0xF2, 0x1F,
  37116. 0x28, 0x43, 0x4D, 0x7E, 0x96, 0xBB, 0xC5, 0xE3,
  37117. 0xEF, 0xF3, 0xFD, 0x02, 0x0C, 0x17, 0x23, 0x3E,
  37118. 0x7F, 0x99, 0xB0, 0xE3, 0xE8, 0xF5, 0x00, 0x00,
  37119. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  37120. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  37121. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  37122. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  37123. 0x06, 0x17, 0x23, 0x2E
  37124. };
  37125. #endif
  37126. #ifndef WOLFSSL_NO_ML_DSA_65
  37127. static const byte sk_65[] = {
  37128. 0xF2, 0x6B, 0xFE, 0x12, 0x68, 0x86, 0xF4, 0x82,
  37129. 0x22, 0x94, 0x4D, 0x02, 0x18, 0xFA, 0xC1, 0x7C,
  37130. 0xD8, 0xA9, 0xCC, 0x6D, 0x67, 0xA0, 0x23, 0xFD,
  37131. 0xC0, 0x7A, 0xFF, 0xC2, 0xD0, 0x25, 0xF7, 0x70,
  37132. 0x63, 0x85, 0x0D, 0x88, 0x0E, 0x98, 0xFE, 0xE5,
  37133. 0x02, 0xE0, 0x17, 0x32, 0x70, 0x00, 0xCC, 0xAF,
  37134. 0x61, 0x45, 0x73, 0xB3, 0x5A, 0xDE, 0xFE, 0xBC,
  37135. 0xAC, 0xEE, 0xA4, 0xB2, 0xC4, 0xD0, 0x45, 0xE5,
  37136. 0xBB, 0xFD, 0x3E, 0x5A, 0x72, 0xE3, 0x71, 0xAD,
  37137. 0x83, 0xB9, 0x94, 0x98, 0x77, 0xD8, 0xE6, 0x56,
  37138. 0xD4, 0x6B, 0x47, 0x75, 0x0F, 0x73, 0x0F, 0x96,
  37139. 0xDB, 0x43, 0x0B, 0x18, 0x60, 0x88, 0x67, 0x5D,
  37140. 0x9A, 0x9B, 0xD7, 0x8E, 0x47, 0xB8, 0x9D, 0x04,
  37141. 0xA8, 0x51, 0x7E, 0xD2, 0x22, 0x06, 0x95, 0x33,
  37142. 0x9F, 0x99, 0xA9, 0x7F, 0x35, 0x3C, 0xE4, 0x20,
  37143. 0x47, 0x77, 0x20, 0x9F, 0x5F, 0x3C, 0x9E, 0x9A,
  37144. 0x36, 0x14, 0x54, 0x01, 0x57, 0x48, 0x60, 0x50,
  37145. 0x75, 0x28, 0x64, 0x61, 0x72, 0x60, 0x54, 0x20,
  37146. 0x75, 0x48, 0x60, 0x32, 0x73, 0x85, 0x34, 0x24,
  37147. 0x68, 0x63, 0x71, 0x73, 0x81, 0x26, 0x71, 0x68,
  37148. 0x32, 0x61, 0x24, 0x71, 0x14, 0x18, 0x26, 0x15,
  37149. 0x05, 0x77, 0x36, 0x27, 0x50, 0x35, 0x21, 0x82,
  37150. 0x50, 0x15, 0x31, 0x47, 0x48, 0x24, 0x43, 0x76,
  37151. 0x18, 0x85, 0x66, 0x18, 0x05, 0x64, 0x27, 0x01,
  37152. 0x06, 0x06, 0x01, 0x45, 0x42, 0x60, 0x80, 0x68,
  37153. 0x25, 0x08, 0x08, 0x36, 0x13, 0x05, 0x04, 0x32,
  37154. 0x34, 0x87, 0x00, 0x70, 0x71, 0x70, 0x02, 0x51,
  37155. 0x37, 0x15, 0x08, 0x28, 0x25, 0x72, 0x61, 0x67,
  37156. 0x08, 0x52, 0x63, 0x44, 0x07, 0x88, 0x60, 0x42,
  37157. 0x03, 0x17, 0x24, 0x64, 0x80, 0x08, 0x70, 0x23,
  37158. 0x56, 0x41, 0x46, 0x17, 0x46, 0x01, 0x57, 0x74,
  37159. 0x02, 0x76, 0x31, 0x64, 0x73, 0x83, 0x50, 0x62,
  37160. 0x72, 0x61, 0x62, 0x75, 0x45, 0x73, 0x46, 0x33,
  37161. 0x65, 0x14, 0x36, 0x46, 0x12, 0x26, 0x04, 0x34,
  37162. 0x02, 0x81, 0x20, 0x34, 0x41, 0x88, 0x26, 0x77,
  37163. 0x33, 0x40, 0x18, 0x58, 0x03, 0x41, 0x16, 0x58,
  37164. 0x88, 0x04, 0x88, 0x32, 0x71, 0x05, 0x85, 0x83,
  37165. 0x42, 0x55, 0x34, 0x20, 0x18, 0x46, 0x12, 0x54,
  37166. 0x28, 0x03, 0x67, 0x10, 0x84, 0x31, 0x76, 0x00,
  37167. 0x40, 0x85, 0x46, 0x71, 0x71, 0x56, 0x00, 0x50,
  37168. 0x15, 0x33, 0x43, 0x13, 0x37, 0x57, 0x13, 0x86,
  37169. 0x43, 0x77, 0x85, 0x57, 0x54, 0x81, 0x75, 0x60,
  37170. 0x37, 0x31, 0x28, 0x52, 0x20, 0x78, 0x65, 0x53,
  37171. 0x76, 0x10, 0x84, 0x87, 0x57, 0x13, 0x66, 0x03,
  37172. 0x56, 0x81, 0x36, 0x66, 0x68, 0x41, 0x55, 0x64,
  37173. 0x63, 0x70, 0x26, 0x21, 0x02, 0x30, 0x28, 0x35,
  37174. 0x02, 0x45, 0x88, 0x80, 0x02, 0x06, 0x44, 0x58,
  37175. 0x24, 0x13, 0x88, 0x83, 0x22, 0x34, 0x22, 0x50,
  37176. 0x47, 0x11, 0x01, 0x86, 0x45, 0x60, 0x67, 0x36,
  37177. 0x82, 0x22, 0x18, 0x74, 0x11, 0x60, 0x58, 0x60,
  37178. 0x87, 0x26, 0x31, 0x85, 0x12, 0x70, 0x84, 0x83,
  37179. 0x88, 0x68, 0x88, 0x51, 0x00, 0x55, 0x02, 0x57,
  37180. 0x77, 0x42, 0x13, 0x23, 0x14, 0x04, 0x76, 0x80,
  37181. 0x72, 0x25, 0x51, 0x56, 0x10, 0x63, 0x12, 0x21,
  37182. 0x03, 0x86, 0x27, 0x30, 0x28, 0x12, 0x01, 0x37,
  37183. 0x48, 0x32, 0x53, 0x86, 0x15, 0x46, 0x50, 0x05,
  37184. 0x34, 0x87, 0x61, 0x04, 0x88, 0x18, 0x35, 0x85,
  37185. 0x44, 0x46, 0x24, 0x67, 0x43, 0x83, 0x02, 0x26,
  37186. 0x56, 0x41, 0x41, 0x77, 0x86, 0x56, 0x41, 0x75,
  37187. 0x25, 0x61, 0x36, 0x05, 0x47, 0x65, 0x00, 0x14,
  37188. 0x32, 0x38, 0x16, 0x81, 0x06, 0x30, 0x61, 0x25,
  37189. 0x16, 0x30, 0x50, 0x44, 0x13, 0x08, 0x75, 0x00,
  37190. 0x50, 0x20, 0x68, 0x21, 0x55, 0x74, 0x61, 0x18,
  37191. 0x62, 0x05, 0x15, 0x51, 0x08, 0x24, 0x01, 0x13,
  37192. 0x81, 0x33, 0x64, 0x83, 0x23, 0x00, 0x55, 0x73,
  37193. 0x62, 0x40, 0x61, 0x75, 0x15, 0x78, 0x21, 0x14,
  37194. 0x13, 0x64, 0x21, 0x47, 0x07, 0x76, 0x80, 0x76,
  37195. 0x76, 0x17, 0x75, 0x50, 0x61, 0x14, 0x40, 0x82,
  37196. 0x87, 0x83, 0x50, 0x87, 0x30, 0x86, 0x35, 0x30,
  37197. 0x28, 0x20, 0x10, 0x01, 0x48, 0x18, 0x34, 0x65,
  37198. 0x23, 0x10, 0x25, 0x42, 0x40, 0x22, 0x54, 0x34,
  37199. 0x35, 0x33, 0x71, 0x70, 0x20, 0x61, 0x55, 0x74,
  37200. 0x33, 0x01, 0x02, 0x60, 0x58, 0x24, 0x80, 0x12,
  37201. 0x46, 0x41, 0x38, 0x10, 0x76, 0x67, 0x34, 0x63,
  37202. 0x48, 0x85, 0x06, 0x48, 0x04, 0x23, 0x22, 0x66,
  37203. 0x57, 0x71, 0x68, 0x18, 0x04, 0x32, 0x01, 0x31,
  37204. 0x01, 0x55, 0x22, 0x27, 0x55, 0x72, 0x10, 0x00,
  37205. 0x43, 0x88, 0x76, 0x62, 0x84, 0x77, 0x07, 0x77,
  37206. 0x14, 0x07, 0x20, 0x53, 0x74, 0x17, 0x51, 0x17,
  37207. 0x66, 0x84, 0x47, 0x83, 0x61, 0x03, 0x52, 0x10,
  37208. 0x05, 0x40, 0x46, 0x55, 0x61, 0x47, 0x26, 0x70,
  37209. 0x40, 0x22, 0x10, 0x34, 0x41, 0x01, 0x03, 0x48,
  37210. 0x33, 0x05, 0x72, 0x32, 0x75, 0x82, 0x45, 0x85,
  37211. 0x20, 0x70, 0x80, 0x82, 0x20, 0x23, 0x62, 0x81,
  37212. 0x15, 0x47, 0x80, 0x23, 0x67, 0x23, 0x73, 0x34,
  37213. 0x44, 0x33, 0x85, 0x10, 0x05, 0x50, 0x30, 0x03,
  37214. 0x48, 0x13, 0x01, 0x36, 0x45, 0x11, 0x06, 0x33,
  37215. 0x82, 0x22, 0x78, 0x75, 0x42, 0x02, 0x40, 0x45,
  37216. 0x04, 0x47, 0x43, 0x05, 0x30, 0x44, 0x42, 0x02,
  37217. 0x28, 0x26, 0x64, 0x24, 0x74, 0x75, 0x86, 0x11,
  37218. 0x85, 0x43, 0x25, 0x46, 0x10, 0x62, 0x82, 0x71,
  37219. 0x08, 0x27, 0x45, 0x13, 0x73, 0x18, 0x84, 0x73,
  37220. 0x51, 0x51, 0x67, 0x14, 0x70, 0x11, 0x07, 0x08,
  37221. 0x62, 0x16, 0x25, 0x27, 0x36, 0x68, 0x44, 0x01,
  37222. 0x18, 0x63, 0x74, 0x50, 0x31, 0x13, 0x43, 0x65,
  37223. 0x80, 0x11, 0x16, 0x52, 0x86, 0x42, 0x51, 0x81,
  37224. 0x51, 0x17, 0x05, 0x68, 0x05, 0x73, 0x60, 0x37,
  37225. 0x63, 0x85, 0x86, 0x11, 0x23, 0x23, 0x38, 0x13,
  37226. 0x87, 0x48, 0x82, 0x74, 0x71, 0x81, 0x87, 0x65,
  37227. 0x58, 0x26, 0x60, 0x34, 0x76, 0x16, 0x15, 0x24,
  37228. 0x06, 0x78, 0x16, 0x40, 0x03, 0x45, 0x72, 0x31,
  37229. 0x63, 0x73, 0x31, 0x85, 0x02, 0x66, 0x44, 0x36,
  37230. 0x24, 0x82, 0x56, 0x38, 0x86, 0x10, 0x40, 0x54,
  37231. 0x72, 0x70, 0x24, 0x22, 0x72, 0x78, 0x47, 0x07,
  37232. 0x86, 0x30, 0x48, 0x72, 0x84, 0x57, 0x06, 0x34,
  37233. 0x78, 0x37, 0x63, 0x25, 0x56, 0x64, 0x81, 0x30,
  37234. 0x62, 0x77, 0x22, 0x84, 0x20, 0x10, 0x74, 0x25,
  37235. 0x04, 0x21, 0x76, 0x47, 0x72, 0x35, 0x05, 0x06,
  37236. 0x22, 0x50, 0x34, 0x11, 0x26, 0x67, 0x03, 0x05,
  37237. 0x42, 0x04, 0x16, 0x01, 0x27, 0x17, 0x86, 0x67,
  37238. 0x70, 0x51, 0x53, 0x13, 0x12, 0x62, 0x03, 0x25,
  37239. 0x05, 0x38, 0x37, 0x44, 0x02, 0x66, 0x84, 0x74,
  37240. 0x14, 0x40, 0x35, 0x20, 0x40, 0x30, 0x44, 0x64,
  37241. 0x27, 0x50, 0x77, 0x47, 0x06, 0x15, 0x84, 0x48,
  37242. 0x13, 0x14, 0x32, 0x48, 0x11, 0x74, 0x80, 0x68,
  37243. 0x85, 0x81, 0x17, 0x67, 0x38, 0x22, 0x76, 0x16,
  37244. 0x18, 0x44, 0x55, 0x47, 0x85, 0x36, 0x44, 0x11,
  37245. 0x52, 0x01, 0x81, 0x50, 0x41, 0x00, 0x00, 0x25,
  37246. 0x83, 0x41, 0x62, 0x22, 0x12, 0x54, 0x88, 0x77,
  37247. 0x70, 0x48, 0x84, 0x25, 0x77, 0x75, 0x40, 0x16,
  37248. 0x46, 0x24, 0x88, 0x81, 0x65, 0x70, 0x02, 0x66,
  37249. 0x28, 0x64, 0x12, 0x40, 0x30, 0x60, 0x53, 0x06,
  37250. 0x44, 0x02, 0x48, 0x78, 0x75, 0x68, 0x21, 0x23,
  37251. 0x30, 0x05, 0x81, 0x17, 0x72, 0x66, 0x88, 0x71,
  37252. 0x50, 0x25, 0x03, 0x51, 0x42, 0x27, 0x20, 0x81,
  37253. 0x03, 0x52, 0x73, 0x53, 0x63, 0x57, 0x13, 0x60,
  37254. 0x41, 0x20, 0x47, 0x12, 0x55, 0x57, 0x58, 0x16,
  37255. 0x38, 0x63, 0x21, 0x34, 0x51, 0x76, 0x33, 0x26,
  37256. 0x70, 0x41, 0x18, 0x11, 0x07, 0x37, 0x16, 0x12,
  37257. 0x01, 0x14, 0x28, 0x56, 0x78, 0x10, 0x86, 0x24,
  37258. 0x24, 0x32, 0x01, 0x13, 0x57, 0x53, 0x46, 0x46,
  37259. 0x24, 0x05, 0x20, 0x16, 0x56, 0x83, 0x30, 0x30,
  37260. 0x61, 0x20, 0x75, 0x07, 0x05, 0x74, 0x14, 0x17,
  37261. 0x43, 0x72, 0x23, 0x04, 0x18, 0x61, 0x50, 0x13,
  37262. 0x67, 0x31, 0x75, 0x36, 0x71, 0x02, 0x38, 0x74,
  37263. 0x21, 0x80, 0x20, 0x48, 0x66, 0x23, 0x52, 0x54,
  37264. 0x77, 0x27, 0x45, 0x73, 0x23, 0x88, 0x60, 0x50,
  37265. 0x88, 0x82, 0x70, 0x23, 0x72, 0x08, 0x44, 0x66,
  37266. 0x44, 0x36, 0x12, 0x57, 0x66, 0x14, 0x25, 0x12,
  37267. 0x17, 0x34, 0x64, 0x82, 0x01, 0x54, 0x61, 0x57,
  37268. 0x50, 0x31, 0x65, 0x64, 0x75, 0x44, 0x76, 0x48,
  37269. 0x16, 0x44, 0x46, 0x55, 0x80, 0x64, 0x26, 0x53,
  37270. 0x27, 0x22, 0x10, 0x87, 0x84, 0x03, 0x15, 0x35,
  37271. 0x15, 0x20, 0x86, 0x14, 0x04, 0x03, 0x26, 0x43,
  37272. 0x31, 0x43, 0x31, 0x45, 0x46, 0x34, 0x36, 0x87,
  37273. 0x44, 0x41, 0x21, 0x77, 0x61, 0x20, 0x85, 0x06,
  37274. 0x28, 0x51, 0x15, 0x62, 0x77, 0x20, 0x38, 0x58,
  37275. 0x78, 0x27, 0x12, 0x22, 0x46, 0x71, 0x51, 0x38,
  37276. 0x11, 0x15, 0x40, 0x03, 0x78, 0x36, 0x15, 0x57,
  37277. 0x34, 0x28, 0x53, 0x21, 0x37, 0x35, 0x04, 0x76,
  37278. 0x00, 0x56, 0x72, 0x48, 0x46, 0x01, 0x56, 0x67,
  37279. 0x62, 0x36, 0x14, 0x51, 0x23, 0x54, 0x32, 0x35,
  37280. 0x82, 0x83, 0x21, 0x60, 0x38, 0x62, 0x21, 0x03,
  37281. 0x62, 0x76, 0x40, 0x34, 0x66, 0x88, 0x50, 0x73,
  37282. 0x00, 0x53, 0x87, 0x31, 0x37, 0x50, 0x11, 0x32,
  37283. 0x86, 0x52, 0x18, 0x64, 0x16, 0x63, 0x48, 0x71,
  37284. 0x70, 0x47, 0x24, 0x85, 0x31, 0x86, 0x60, 0x86,
  37285. 0x33, 0x52, 0x85, 0x82, 0x68, 0x17, 0x70, 0x88,
  37286. 0x84, 0x56, 0x52, 0x77, 0x04, 0x48, 0x22, 0x22,
  37287. 0x54, 0x57, 0x20, 0x31, 0x76, 0x47, 0x26, 0x25,
  37288. 0x04, 0x35, 0x38, 0x44, 0x55, 0x21, 0x14, 0x02,
  37289. 0x13, 0x64, 0x74, 0x87, 0x68, 0x68, 0x73, 0x05,
  37290. 0x22, 0x45, 0x54, 0x45, 0x83, 0x46, 0x64, 0x54,
  37291. 0x80, 0x07, 0x32, 0x87, 0x52, 0x43, 0x54, 0x54,
  37292. 0x14, 0x73, 0x24, 0x87, 0x36, 0x41, 0x74, 0x84,
  37293. 0x06, 0x35, 0x13, 0x40, 0x61, 0x54, 0x21, 0x31,
  37294. 0x48, 0x63, 0x05, 0x74, 0x24, 0x84, 0x74, 0x76,
  37295. 0x11, 0x10, 0x16, 0x63, 0x77, 0x12, 0x26, 0x61,
  37296. 0x31, 0x28, 0x70, 0x34, 0x25, 0x01, 0x30, 0x76,
  37297. 0x76, 0x06, 0x21, 0x58, 0x42, 0x87, 0x31, 0x72,
  37298. 0x76, 0x03, 0x76, 0x26, 0x78, 0x05, 0x88, 0x25,
  37299. 0x25, 0x86, 0x17, 0x02, 0x85, 0x88, 0x76, 0x20,
  37300. 0x36, 0x57, 0x30, 0x81, 0x83, 0x61, 0x05, 0x80,
  37301. 0x21, 0x45, 0x74, 0x01, 0x12, 0x74, 0x51, 0x28,
  37302. 0x77, 0x26, 0x30, 0x14, 0x54, 0x84, 0x13, 0x78,
  37303. 0x06, 0x00, 0x12, 0x64, 0x00, 0x37, 0x44, 0x68,
  37304. 0x40, 0x57, 0x05, 0x27, 0x07, 0x41, 0x56, 0x22,
  37305. 0x31, 0x40, 0x23, 0x26, 0x55, 0x42, 0x55, 0x16,
  37306. 0x02, 0x65, 0x32, 0x16, 0x33, 0x44, 0x46, 0x48,
  37307. 0x04, 0x52, 0x06, 0x53, 0x44, 0x40, 0x11, 0x28,
  37308. 0x46, 0x67, 0x56, 0x81, 0x72, 0x75, 0x51, 0x38,
  37309. 0x21, 0x86, 0x46, 0x03, 0x22, 0x87, 0x21, 0x70,
  37310. 0x68, 0x50, 0x75, 0x13, 0x11, 0x44, 0x35, 0x12,
  37311. 0x60, 0x02, 0x13, 0x47, 0x18, 0x38, 0x78, 0x86,
  37312. 0x38, 0x58, 0x45, 0x57, 0x23, 0x03, 0x88, 0x66,
  37313. 0x56, 0x82, 0x18, 0x31, 0x20, 0x08, 0x61, 0x47,
  37314. 0x78, 0x08, 0x68, 0x37, 0x21, 0x04, 0x65, 0x47,
  37315. 0x58, 0x70, 0x34, 0x58, 0x73, 0x24, 0x22, 0x30,
  37316. 0x66, 0x05, 0x01, 0x28, 0x87, 0x85, 0x77, 0x74,
  37317. 0x23, 0x86, 0x65, 0x84, 0x85, 0x57, 0x85, 0x63,
  37318. 0x06, 0x55, 0x61, 0x75, 0x46, 0x22, 0x87, 0x00,
  37319. 0x18, 0x53, 0x08, 0x03, 0x07, 0x50, 0x42, 0x70,
  37320. 0xFC, 0xB8, 0x7B, 0x22, 0x3D, 0x24, 0xAE, 0x5D,
  37321. 0xB1, 0x89, 0x04, 0x21, 0xC3, 0xFF, 0x1D, 0x59,
  37322. 0xB8, 0x4B, 0x19, 0xE2, 0x4D, 0x14, 0x36, 0x99,
  37323. 0x19, 0x1C, 0x7E, 0x9A, 0x46, 0x48, 0x42, 0x20,
  37324. 0x6B, 0xBA, 0x24, 0x7E, 0x8C, 0x6B, 0x27, 0xBA,
  37325. 0x26, 0xE6, 0x8A, 0xD5, 0xA7, 0x1D, 0x03, 0x61,
  37326. 0xCD, 0x5C, 0x74, 0xCE, 0x50, 0xC2, 0xCE, 0xF1,
  37327. 0x91, 0x31, 0xEF, 0x54, 0x66, 0x23, 0x7F, 0xFE,
  37328. 0xF7, 0xFE, 0x6B, 0x5F, 0xD1, 0x98, 0x23, 0x8E,
  37329. 0x1C, 0xA0, 0xB1, 0x01, 0x30, 0xC6, 0x29, 0xCC,
  37330. 0x91, 0x91, 0xF5, 0x78, 0x6F, 0x5C, 0xD6, 0x28,
  37331. 0xA4, 0x22, 0x56, 0xCB, 0x6F, 0xC7, 0xD7, 0x09,
  37332. 0x56, 0x88, 0xAF, 0x1B, 0xC8, 0x43, 0x51, 0xA4,
  37333. 0x7B, 0x4B, 0x38, 0x2E, 0xF6, 0x1F, 0xD6, 0x5C,
  37334. 0x9E, 0xC2, 0x26, 0xF4, 0x2B, 0x0A, 0x19, 0x7C,
  37335. 0x6A, 0xD8, 0xF0, 0xB0, 0x15, 0xD0, 0xB1, 0xC7,
  37336. 0xE0, 0x14, 0x28, 0x95, 0x6A, 0x9B, 0xB2, 0xDE,
  37337. 0x9A, 0x97, 0xE5, 0x75, 0x66, 0xF8, 0xF5, 0x66,
  37338. 0x86, 0xA1, 0xF4, 0x68, 0x0C, 0xEC, 0xEA, 0x87,
  37339. 0x3B, 0x69, 0x1C, 0xF8, 0xBD, 0x63, 0xAB, 0x73,
  37340. 0x73, 0xBA, 0xE8, 0x09, 0x5B, 0xA7, 0x76, 0x3E,
  37341. 0x50, 0xD6, 0x83, 0x9D, 0x00, 0x35, 0xBB, 0xFB,
  37342. 0x91, 0xBA, 0x60, 0x72, 0x17, 0x98, 0xFB, 0x2C,
  37343. 0x80, 0x2C, 0x60, 0x3A, 0x08, 0xA1, 0x24, 0x05,
  37344. 0xE0, 0xB5, 0x20, 0xEA, 0x41, 0x43, 0x8F, 0xEA,
  37345. 0xEF, 0xA5, 0x62, 0xDC, 0x78, 0x92, 0xF4, 0x58,
  37346. 0x9F, 0x8D, 0x2B, 0x96, 0x5E, 0xE5, 0x49, 0x73,
  37347. 0xA7, 0x2C, 0x8D, 0x33, 0x5C, 0x62, 0x61, 0x98,
  37348. 0x80, 0x64, 0x13, 0x31, 0x03, 0x10, 0xE3, 0x2E,
  37349. 0xFE, 0x6B, 0x39, 0xB5, 0xCF, 0xB1, 0xD1, 0x33,
  37350. 0xAD, 0xE0, 0x1B, 0xCE, 0x94, 0x21, 0x6C, 0xF4,
  37351. 0xCD, 0x8F, 0x86, 0x43, 0x03, 0x1D, 0xB8, 0xC2,
  37352. 0x47, 0xB5, 0x73, 0x21, 0xCA, 0x1E, 0xFB, 0xB8,
  37353. 0x53, 0x63, 0x7D, 0x0C, 0x57, 0x52, 0x14, 0xFC,
  37354. 0x77, 0xA5, 0xA6, 0x84, 0xD5, 0x0A, 0xBF, 0xE4,
  37355. 0xE9, 0x71, 0x99, 0x8E, 0x06, 0x6E, 0x50, 0x24,
  37356. 0xDA, 0x02, 0x76, 0x8A, 0xED, 0xE1, 0x3E, 0x83,
  37357. 0xF0, 0x51, 0x54, 0xA9, 0x99, 0x29, 0x48, 0x42,
  37358. 0x7A, 0xA9, 0x8C, 0x87, 0x42, 0x51, 0xAF, 0x56,
  37359. 0x94, 0x23, 0x53, 0x89, 0x44, 0xFA, 0xD8, 0x93,
  37360. 0xFC, 0x65, 0x6E, 0x9C, 0xED, 0x80, 0x6A, 0x85,
  37361. 0xD9, 0xC3, 0x36, 0x71, 0x02, 0x25, 0x29, 0x36,
  37362. 0x8E, 0x7E, 0xC7, 0x0C, 0x9E, 0xE9, 0x74, 0x30,
  37363. 0x1C, 0x08, 0xCB, 0xE6, 0xAC, 0x5E, 0x88, 0xE6,
  37364. 0x37, 0x79, 0x5C, 0xB2, 0xA2, 0x15, 0xFF, 0xAA,
  37365. 0x08, 0xED, 0xDE, 0x40, 0xAC, 0xFA, 0xEE, 0x2A,
  37366. 0x40, 0xD5, 0x05, 0xCF, 0x58, 0xA6, 0x69, 0x66,
  37367. 0x31, 0x5A, 0x68, 0x98, 0x24, 0x03, 0xD8, 0x1B,
  37368. 0xFA, 0x89, 0xE3, 0x7C, 0x9E, 0x42, 0x1D, 0xA5,
  37369. 0x88, 0xBA, 0x7E, 0x42, 0x2A, 0xC7, 0x44, 0x6A,
  37370. 0x1E, 0x61, 0xC8, 0x22, 0x29, 0x9D, 0xFC, 0x34,
  37371. 0xEC, 0xFA, 0xBE, 0x5C, 0xB6, 0x26, 0xB9, 0x6C,
  37372. 0x8E, 0xA6, 0xC9, 0x3B, 0xDB, 0xD2, 0xD5, 0xBD,
  37373. 0x70, 0xC5, 0xF8, 0x26, 0x7A, 0x84, 0xE0, 0x07,
  37374. 0xA7, 0x11, 0x5E, 0x5B, 0xE5, 0xF1, 0x20, 0x32,
  37375. 0xA3, 0x7C, 0xAB, 0x05, 0xD5, 0x41, 0xE3, 0xDE,
  37376. 0xA5, 0x1A, 0x83, 0x2E, 0xDE, 0x8D, 0x34, 0x9A,
  37377. 0xFD, 0xD5, 0xE6, 0xFC, 0xFC, 0x83, 0x46, 0xE3,
  37378. 0xD4, 0x7C, 0xF1, 0x7F, 0xEA, 0x87, 0x5E, 0x38,
  37379. 0x5D, 0xB9, 0x8A, 0xC2, 0xDB, 0xE8, 0xB4, 0xF8,
  37380. 0x05, 0x37, 0x31, 0x0D, 0xD9, 0x4C, 0xD0, 0xB6,
  37381. 0x25, 0xE9, 0x97, 0x85, 0xDB, 0x04, 0x9A, 0x01,
  37382. 0xF5, 0x4B, 0xA1, 0xF4, 0x2A, 0xDF, 0xEC, 0xAE,
  37383. 0x24, 0x11, 0xD3, 0x2B, 0x2F, 0x84, 0x6C, 0x88,
  37384. 0xA3, 0x0C, 0x76, 0xEA, 0x0A, 0x38, 0xB2, 0x71,
  37385. 0xB6, 0xAC, 0xA8, 0x23, 0x6E, 0x61, 0xEB, 0xB8,
  37386. 0x4A, 0x9D, 0xC4, 0x9E, 0x5C, 0x5B, 0xEE, 0x7E,
  37387. 0x7D, 0x8D, 0xA2, 0xC1, 0xA1, 0xA0, 0xA3, 0x14,
  37388. 0x50, 0xE0, 0x8F, 0xAB, 0xBB, 0x1B, 0x1F, 0x05,
  37389. 0xAA, 0xE3, 0x00, 0xD8, 0xCD, 0xE7, 0x35, 0xB4,
  37390. 0x7B, 0xBD, 0xB0, 0x5C, 0xCC, 0x0C, 0x05, 0x33,
  37391. 0x6B, 0xE4, 0x51, 0x73, 0x1B, 0x6B, 0x77, 0x7B,
  37392. 0xE5, 0xCB, 0xAF, 0x98, 0x53, 0x5F, 0x7E, 0x08,
  37393. 0xFF, 0xCD, 0x8A, 0x44, 0x9E, 0x1D, 0x43, 0x6A,
  37394. 0x4F, 0x05, 0x99, 0x01, 0xF5, 0x6F, 0x01, 0x30,
  37395. 0xBD, 0x15, 0xD7, 0x51, 0x16, 0x45, 0x40, 0x6B,
  37396. 0xF3, 0x13, 0xCA, 0x1F, 0x22, 0x02, 0xA4, 0xA8,
  37397. 0x6A, 0x1D, 0x04, 0x7F, 0xD5, 0x8A, 0x3E, 0x87,
  37398. 0x7F, 0x1D, 0x5A, 0x79, 0x75, 0xD1, 0x6D, 0x67,
  37399. 0xB3, 0x23, 0xC6, 0x28, 0x7B, 0x9C, 0xCE, 0xEE,
  37400. 0x98, 0x9E, 0xE8, 0x44, 0xA9, 0x3E, 0x7E, 0xFD,
  37401. 0x3B, 0xD9, 0xD8, 0x31, 0x6D, 0xA3, 0x77, 0xDF,
  37402. 0x0B, 0xB9, 0xE2, 0x61, 0xA2, 0x71, 0xD5, 0x0C,
  37403. 0xB7, 0x01, 0x67, 0xC3, 0x0D, 0x19, 0x2D, 0xAA,
  37404. 0xDE, 0x96, 0x0E, 0xEA, 0x33, 0x5E, 0xEC, 0x52,
  37405. 0xE5, 0x2D, 0x95, 0x39, 0xE1, 0xF9, 0x5D, 0x9E,
  37406. 0xB6, 0x5E, 0x54, 0x8F, 0x16, 0x60, 0x99, 0xED,
  37407. 0x88, 0x2C, 0x30, 0x72, 0x53, 0x6A, 0x6C, 0xAA,
  37408. 0x05, 0x21, 0xA5, 0xAA, 0x7C, 0x64, 0x72, 0xA0,
  37409. 0xC0, 0x4F, 0x80, 0xDA, 0x20, 0x5D, 0x52, 0x18,
  37410. 0x77, 0x07, 0xDF, 0x5C, 0x2F, 0x2E, 0xA2, 0x5F,
  37411. 0xEF, 0x00, 0xCA, 0x7B, 0xF0, 0xD3, 0xB7, 0xF8,
  37412. 0x1E, 0x31, 0x9E, 0x61, 0xCA, 0x2C, 0xC5, 0xA5,
  37413. 0x25, 0xA2, 0x7B, 0x56, 0xAA, 0xBA, 0xE4, 0xD5,
  37414. 0x35, 0xE5, 0xEC, 0x24, 0x2D, 0x81, 0x1A, 0x24,
  37415. 0xD7, 0x45, 0x76, 0xBF, 0x4B, 0x8A, 0x72, 0xFA,
  37416. 0x5F, 0xAE, 0xC1, 0xA2, 0x83, 0xB6, 0x1D, 0x60,
  37417. 0x28, 0x7E, 0x1E, 0x2E, 0xC8, 0xC6, 0xAB, 0x04,
  37418. 0x56, 0x5F, 0xD5, 0xCD, 0x64, 0x26, 0x34, 0x94,
  37419. 0xE8, 0x03, 0x41, 0x63, 0x35, 0x5B, 0x45, 0x84,
  37420. 0xCE, 0xFA, 0x0B, 0x66, 0x40, 0x85, 0x1A, 0xE1,
  37421. 0x23, 0xE9, 0x8F, 0xBD, 0xA9, 0x23, 0xFC, 0xA3,
  37422. 0x8E, 0x38, 0xB3, 0x84, 0xE2, 0xB9, 0x54, 0x41,
  37423. 0x4B, 0x36, 0x4F, 0xB8, 0xB0, 0x87, 0x56, 0x04,
  37424. 0x8B, 0x75, 0xC7, 0x85, 0x31, 0xD4, 0xA5, 0x12,
  37425. 0x99, 0xC4, 0x9D, 0xEA, 0x4B, 0x36, 0x8C, 0x19,
  37426. 0x82, 0xFE, 0xAD, 0x4A, 0xB1, 0xAA, 0x52, 0x35,
  37427. 0xA4, 0xA1, 0x7F, 0xB0, 0x64, 0x6F, 0x04, 0x04,
  37428. 0x7B, 0xF0, 0x80, 0x48, 0xA1, 0x1C, 0xF8, 0x95,
  37429. 0x8B, 0x68, 0x34, 0xB7, 0xFD, 0x00, 0x31, 0x30,
  37430. 0x6A, 0x39, 0xC8, 0xAE, 0x68, 0xC3, 0x53, 0x65,
  37431. 0x19, 0x7C, 0x1E, 0x57, 0x97, 0xFC, 0x47, 0x3E,
  37432. 0xB1, 0x94, 0x54, 0x48, 0x6F, 0xEB, 0xAA, 0xEC,
  37433. 0x5C, 0x2E, 0xE9, 0x2C, 0xCC, 0x3A, 0xF3, 0xC7,
  37434. 0x43, 0x08, 0x7D, 0x2D, 0x56, 0x4B, 0x7D, 0xE9,
  37435. 0xE5, 0x96, 0xF3, 0x12, 0x4B, 0xE9, 0x08, 0xF3,
  37436. 0x04, 0x5A, 0x75, 0x1A, 0x7D, 0x7E, 0x37, 0xE6,
  37437. 0xC8, 0xC1, 0xFE, 0xF3, 0x32, 0x63, 0x2D, 0x0B,
  37438. 0xBE, 0x05, 0x13, 0x6A, 0x44, 0x58, 0x7F, 0x54,
  37439. 0x5F, 0x5F, 0xF5, 0x2F, 0xB8, 0x0B, 0xF2, 0xBF,
  37440. 0x0B, 0xF4, 0x30, 0x2F, 0xCF, 0xEC, 0xFE, 0x08,
  37441. 0xEC, 0x51, 0xF2, 0x29, 0xD7, 0xAC, 0x28, 0xE1,
  37442. 0x75, 0x42, 0x61, 0xBC, 0xE7, 0xB1, 0x53, 0x4F,
  37443. 0x7D, 0x3B, 0xB0, 0x8D, 0x01, 0x15, 0x1E, 0xBE,
  37444. 0xEC, 0xD9, 0x54, 0xC2, 0x4E, 0x70, 0x3E, 0xEA,
  37445. 0x39, 0x14, 0x26, 0xB7, 0x01, 0x79, 0x5D, 0x06,
  37446. 0x93, 0x85, 0x99, 0xAA, 0x7D, 0xDC, 0xF9, 0x2E,
  37447. 0x44, 0x56, 0x9B, 0xFA, 0x9D, 0x91, 0x2A, 0x8E,
  37448. 0x89, 0x48, 0x51, 0xE3, 0xD0, 0x53, 0xB3, 0xAD,
  37449. 0x43, 0x29, 0xB7, 0x6A, 0x50, 0xC0, 0x78, 0x4D,
  37450. 0x42, 0xF3, 0x7C, 0x5F, 0x90, 0x06, 0xAC, 0x2A,
  37451. 0x9D, 0x5D, 0xE5, 0x18, 0x3F, 0xA3, 0xC6, 0x5E,
  37452. 0xCD, 0xB6, 0xCF, 0x31, 0x67, 0xA4, 0x7A, 0x8F,
  37453. 0x5C, 0x59, 0xBD, 0xD7, 0x9B, 0x7C, 0x24, 0x06,
  37454. 0x97, 0xE1, 0x59, 0x72, 0x85, 0x02, 0x74, 0xFE,
  37455. 0x41, 0xAD, 0x84, 0xD9, 0x0D, 0xCB, 0x34, 0x16,
  37456. 0x11, 0xE7, 0x66, 0xD2, 0x12, 0xDC, 0x76, 0x3C,
  37457. 0xF9, 0x4C, 0x8C, 0x41, 0x94, 0xCC, 0xA9, 0x1B,
  37458. 0x21, 0x03, 0x28, 0xE4, 0xA3, 0x37, 0x4E, 0x29,
  37459. 0xD2, 0x48, 0x11, 0x2B, 0xB6, 0x68, 0xA3, 0x92,
  37460. 0xC2, 0x0D, 0x87, 0x91, 0x03, 0x76, 0xB5, 0x00,
  37461. 0x1F, 0x3F, 0xFB, 0xBE, 0xC3, 0xE0, 0x08, 0xBF,
  37462. 0x2F, 0x46, 0xF7, 0x40, 0x73, 0x83, 0xA8, 0x0D,
  37463. 0xDA, 0x08, 0x2B, 0xDB, 0x8F, 0xE9, 0x25, 0xE4,
  37464. 0xF1, 0x2B, 0x37, 0x92, 0x27, 0x0E, 0x5A, 0x46,
  37465. 0xB8, 0xC5, 0x7B, 0x6E, 0x5A, 0x4B, 0x95, 0x58,
  37466. 0x4E, 0xF3, 0x80, 0xED, 0x49, 0x93, 0xEC, 0x52,
  37467. 0x9F, 0xF2, 0xAA, 0x39, 0xDD, 0x6D, 0xFE, 0x88,
  37468. 0xFD, 0xEB, 0x6E, 0xDA, 0x0E, 0x8D, 0xA7, 0x95,
  37469. 0x66, 0xB0, 0x7D, 0x37, 0xAE, 0xCC, 0x64, 0x37,
  37470. 0x25, 0x95, 0x18, 0xF9, 0x7E, 0x6C, 0x86, 0x12,
  37471. 0xB3, 0xC3, 0x57, 0x03, 0xBF, 0xF9, 0x92, 0x15,
  37472. 0x3E, 0x66, 0x0E, 0x2E, 0x20, 0x77, 0xA0, 0x5F,
  37473. 0x26, 0x5F, 0xB5, 0x12, 0x1D, 0xD7, 0x9F, 0x0A,
  37474. 0x33, 0xBC, 0x38, 0xEC, 0x83, 0x08, 0xE2, 0xA9,
  37475. 0x84, 0xCD, 0x3D, 0x8A, 0xC6, 0x09, 0x30, 0x6F,
  37476. 0x77, 0x93, 0xD7, 0xDE, 0x08, 0xD8, 0x45, 0xA4,
  37477. 0x21, 0x28, 0x26, 0x4E, 0x5C, 0x17, 0x77, 0x74,
  37478. 0xE3, 0x5D, 0x58, 0x7C, 0x96, 0xB2, 0x47, 0x05,
  37479. 0x42, 0x21, 0x78, 0x5D, 0xB3, 0x8D, 0xDC, 0x6F,
  37480. 0xDB, 0xF7, 0xBF, 0x6F, 0x66, 0x4B, 0xD6, 0x30,
  37481. 0x14, 0xC0, 0xBF, 0x94, 0x2A, 0x83, 0x91, 0x6C,
  37482. 0xBF, 0x2C, 0x42, 0x85, 0x41, 0xED, 0xA2, 0xBB,
  37483. 0xCB, 0xFC, 0xF9, 0x35, 0xDE, 0xFC, 0xB3, 0x63,
  37484. 0xE1, 0x64, 0xAA, 0x51, 0x2D, 0xD5, 0xFA, 0x79,
  37485. 0x53, 0x31, 0x40, 0x0B, 0x9B, 0xD0, 0x3C, 0xE3,
  37486. 0xD7, 0x2D, 0x91, 0x05, 0x62, 0xC3, 0x81, 0xFE,
  37487. 0x93, 0x1E, 0x8C, 0x37, 0x9E, 0x30, 0x23, 0x73,
  37488. 0x3A, 0xB9, 0x18, 0x6E, 0x5D, 0xEF, 0x31, 0xE9,
  37489. 0xF6, 0x25, 0x7F, 0xB8, 0x47, 0x74, 0xCE, 0x28,
  37490. 0x23, 0xD4, 0x4F, 0xC1, 0x42, 0xCB, 0xEB, 0x59,
  37491. 0x8A, 0x68, 0xFD, 0x39, 0x48, 0x37, 0x1A, 0x5D,
  37492. 0x0C, 0x09, 0x64, 0xC6, 0xE1, 0x21, 0x5D, 0x89,
  37493. 0xF6, 0x58, 0xE5, 0x50, 0x4A, 0xD0, 0x93, 0xBC,
  37494. 0x86, 0x02, 0xBA, 0xD2, 0x36, 0x24, 0x9D, 0x7E,
  37495. 0xAF, 0xB6, 0xA1, 0xA0, 0x7C, 0xA7, 0xC7, 0x4D,
  37496. 0xAC, 0x30, 0x7A, 0x70, 0x0F, 0x2F, 0x81, 0x40,
  37497. 0xC1, 0x08, 0x6B, 0x21, 0xF2, 0xE1, 0x51, 0x9C,
  37498. 0x1D, 0x46, 0x94, 0x93, 0x2A, 0x1C, 0x18, 0xCB,
  37499. 0xED, 0x0D, 0x0E, 0x29, 0xDE, 0xFC, 0x52, 0x52,
  37500. 0x97, 0x93, 0x70, 0x85, 0xE2, 0x63, 0x0D, 0xC6,
  37501. 0x2C, 0x0C, 0x05, 0x0C, 0x4F, 0xF2, 0x70, 0x87,
  37502. 0x2B, 0xE7, 0xBB, 0x52, 0x2D, 0xD6, 0x99, 0x1B,
  37503. 0x59, 0x6F, 0xC2, 0x92, 0x11, 0x72, 0x5D, 0x99,
  37504. 0x60, 0xB1, 0x6A, 0x52, 0xEA, 0x91, 0x78, 0x19,
  37505. 0x23, 0xC0, 0x3B, 0x71, 0x9D, 0x09, 0xD6, 0xE7,
  37506. 0x10, 0x6D, 0xC5, 0x70, 0x55, 0xC1, 0x9E, 0xF8,
  37507. 0x76, 0xE5, 0xEC, 0x23, 0x17, 0xE7, 0xE4, 0x23,
  37508. 0xC9, 0x71, 0x45, 0x40, 0x72, 0x01, 0x9E, 0x28,
  37509. 0xE6, 0x5C, 0x81, 0xED, 0x52, 0x7A, 0xF1, 0x89,
  37510. 0xBD, 0xFC, 0xF5, 0x21, 0xC9, 0x23, 0x40, 0x75,
  37511. 0x54, 0xAC, 0xBF, 0x69, 0x45, 0xD1, 0x85, 0x44,
  37512. 0x3D, 0xAC, 0x1A, 0x1A, 0x08, 0x8A, 0x68, 0xB5,
  37513. 0x17, 0xD5, 0xD9, 0x90, 0xE1, 0x10, 0x30, 0xDE,
  37514. 0x4F, 0x75, 0x09, 0xE8, 0x7A, 0x77, 0xB3, 0x7C,
  37515. 0xF2, 0x0A, 0x78, 0xE2, 0xCD, 0x48, 0x94, 0x17,
  37516. 0x3C, 0x32, 0xA3, 0x27, 0x35, 0x51, 0x16, 0xB7,
  37517. 0x18, 0x51, 0x44, 0x42, 0x65, 0x60, 0x6A, 0x0A,
  37518. 0x9A, 0x6D, 0x94, 0x61, 0xCC, 0x5D, 0xD8, 0x3B,
  37519. 0x52, 0x7E, 0x4D, 0xBD, 0x6A, 0xEE, 0x03, 0x3D,
  37520. 0x66, 0x1C, 0x3D, 0xE8, 0xC1, 0x82, 0x97, 0xE5,
  37521. 0xD1, 0x31, 0xDB, 0xC8, 0xF6, 0x96, 0xE9, 0x47,
  37522. 0xC9, 0x5C, 0x71, 0x77, 0x2B, 0x62, 0x44, 0x74,
  37523. 0x4D, 0x06, 0x1E, 0x14, 0x45, 0x3B, 0x9F, 0xB1,
  37524. 0x17, 0x34, 0x80, 0x2D, 0xBA, 0x6F, 0x81, 0x79,
  37525. 0xB8, 0x0D, 0xAC, 0xFE, 0xB6, 0xBA, 0xDF, 0xD1,
  37526. 0x4E, 0x05, 0x76, 0x73, 0x6F, 0x80, 0x10, 0xC5,
  37527. 0x32, 0x87, 0xA3, 0xD3, 0x93, 0x18, 0x79, 0xEF,
  37528. 0x27, 0x3B, 0xBF, 0xCD, 0xB5, 0xDE, 0x5B, 0x88,
  37529. 0xAF, 0x51, 0xFD, 0x8A, 0x8C, 0x8F, 0x0A, 0x58,
  37530. 0x94, 0xE2, 0x25, 0xDF, 0xE8, 0x73, 0xFC, 0xC0,
  37531. 0x3C, 0xB1, 0xC9, 0xB5, 0x78, 0x25, 0xF1, 0x11,
  37532. 0x75, 0xC8, 0x7D, 0x08, 0x78, 0xB9, 0xE6, 0x15,
  37533. 0x6B, 0x40, 0x1B, 0x2F, 0xBE, 0x30, 0x03, 0x6B,
  37534. 0xFC, 0x7D, 0xB1, 0x00, 0x02, 0x71, 0xB7, 0xFF,
  37535. 0x5D, 0x63, 0xA8, 0x09, 0x50, 0x75, 0xEF, 0xBD,
  37536. 0x34, 0xEE, 0x73, 0xDE, 0x60, 0x14, 0x95, 0x2D,
  37537. 0x15, 0xBC, 0x30, 0x23, 0x07, 0x02, 0xD8, 0x7C,
  37538. 0x9A, 0x96, 0xD5, 0xE9, 0xF1, 0xF0, 0xF9, 0x26,
  37539. 0x25, 0x96, 0xAA, 0x58, 0xB7, 0xE4, 0x1A, 0xD9,
  37540. 0xA0, 0x9E, 0xAD, 0xB9, 0x44, 0xB6, 0x3F, 0xD9,
  37541. 0x8B, 0x34, 0x7D, 0x11, 0xBD, 0x52, 0x97, 0xC3,
  37542. 0xBE, 0x28, 0x23, 0x85, 0x9F, 0x2F, 0x35, 0xA4,
  37543. 0xE5, 0x4E, 0x13, 0x68, 0x89, 0x09, 0xC3, 0x1A,
  37544. 0x83, 0xE7, 0xDE, 0xCE, 0x4B, 0xDF, 0x31, 0x03,
  37545. 0x9C, 0x72, 0xBA, 0x54, 0xA1, 0x20, 0x2D, 0x17,
  37546. 0x2A, 0x6B, 0x8A, 0x2C, 0xE9, 0x6D, 0xED, 0xCA,
  37547. 0x5B, 0x24, 0xF7, 0xB9, 0x42, 0xC1, 0x4E, 0x13,
  37548. 0x3D, 0xAA, 0x8A, 0xB8, 0xCB, 0xD2, 0x4C, 0x1F,
  37549. 0x0B, 0xBE, 0xB1, 0x27, 0x97, 0x67, 0x26, 0x72,
  37550. 0xE2, 0x2C, 0xE6, 0xC2, 0x12, 0x37, 0xB2, 0x79,
  37551. 0x7D, 0x8E, 0x54, 0xCC, 0x8F, 0xC7, 0x6C, 0x43,
  37552. 0xB4, 0x75, 0x29, 0x66, 0xA3, 0xA4, 0x09, 0x44,
  37553. 0xE7, 0x2D, 0x37, 0x3F, 0x0D, 0x3E, 0x84, 0xF9,
  37554. 0xA3, 0x30, 0x1E, 0xAE, 0x9E, 0xDA, 0x35, 0x44,
  37555. 0x4B, 0x1E, 0x49, 0xE6, 0x61, 0x18, 0x20, 0x6A,
  37556. 0x56, 0xEB, 0x46, 0xD4, 0x8D, 0x20, 0x95, 0x4A,
  37557. 0x77, 0x9A, 0x1E, 0x74, 0xE3, 0xE3, 0xB2, 0xBD,
  37558. 0x40, 0x3D, 0x46, 0xB3, 0x35, 0x10, 0x11, 0xCB,
  37559. 0x6F, 0x8A, 0x86, 0x72, 0xB2, 0xF3, 0xD9, 0x90,
  37560. 0x31, 0x47, 0x55, 0x77, 0x6C, 0xE3, 0x23, 0x7F,
  37561. 0x0A, 0x50, 0xE7, 0x71, 0x20, 0x53, 0x09, 0xC0,
  37562. 0x5D, 0x9A, 0x78, 0xD3, 0x68, 0x88, 0xA8, 0x3B,
  37563. 0xAD, 0x78, 0xE8, 0x6E, 0xDF, 0x36, 0xA8, 0x8D,
  37564. 0xC7, 0x1C, 0x5F, 0x11, 0x56, 0x83, 0x90, 0xD0,
  37565. 0xB5, 0x92, 0x02, 0xE2, 0x9E, 0xE1, 0x1E, 0xCB,
  37566. 0x9F, 0x56, 0x89, 0x63, 0xE8, 0x17, 0x70, 0x83,
  37567. 0x9F, 0xF2, 0x39, 0xAD, 0x03, 0x15, 0x6C, 0xC0,
  37568. 0x71, 0xE8, 0xB7, 0x40, 0x15, 0x95, 0xEC, 0xEE,
  37569. 0x62, 0x34, 0xAC, 0x34, 0xB7, 0x11, 0x70, 0x3D,
  37570. 0x68, 0xC6, 0x7A, 0x28, 0x83, 0xBE, 0x9C, 0x18,
  37571. 0xAB, 0x7F, 0x1A, 0x1B, 0x2E, 0x5C, 0x90, 0xA2,
  37572. 0x32, 0x3C, 0xDF, 0x1E, 0xD4, 0x98, 0x50, 0xB8,
  37573. 0x39, 0x38, 0x19, 0x2F, 0x62, 0x8C, 0x9E, 0xF6,
  37574. 0x5B, 0x77, 0x93, 0x95, 0xEE, 0x37, 0x34, 0xC7,
  37575. 0xA9, 0x01, 0xF7, 0x47, 0x38, 0x86, 0xD7, 0x12,
  37576. 0xD2, 0x15, 0x41, 0x68, 0x16, 0xC3, 0x01, 0x6C,
  37577. 0xC2, 0x83, 0x83, 0xD4, 0x78, 0x7B, 0x46, 0xF6,
  37578. 0x89, 0xDC, 0xE1, 0x11, 0xDA, 0x4D, 0xB8, 0xAC,
  37579. 0x10, 0xE8, 0x4F, 0x66, 0xA5, 0xC2, 0xBD, 0xA1,
  37580. 0xB3, 0xFC, 0x97, 0x7F, 0x6A, 0x0F, 0x73, 0x2E,
  37581. 0xDA, 0x4F, 0x69, 0xB9, 0x75, 0x51, 0xA4, 0xB8,
  37582. 0xB2, 0x61, 0xD6, 0x88, 0x71, 0x94, 0xD3, 0xAF,
  37583. 0xE7, 0xF4, 0xB8, 0x7F, 0xB3, 0xD4, 0x1A, 0xC6,
  37584. 0xDC, 0xDB, 0x8F, 0xD3, 0x9B, 0xE5, 0x0F, 0x2F,
  37585. 0x38, 0x2B, 0xAA, 0x4D, 0x19, 0xC7, 0x45, 0x0A,
  37586. 0xB3, 0xA1, 0xAC, 0x4C, 0x63, 0xCF, 0x93, 0x0A,
  37587. 0xAA, 0x51, 0x7A, 0x15, 0xD5, 0xC0, 0xD5, 0x49,
  37588. 0xFE, 0x03, 0x22, 0x00, 0x71, 0xD3, 0x69, 0x22,
  37589. 0x3E, 0x51, 0x29, 0x6E, 0xCB, 0xF8, 0x0D, 0xCD,
  37590. 0x79, 0xFB, 0xDF, 0xB8, 0xDF, 0x62, 0x90, 0x4D,
  37591. 0x5A, 0x36, 0x20, 0x0F, 0x29, 0xCC, 0x47, 0xE8,
  37592. 0x0C, 0x86, 0x15, 0xEF, 0x1B, 0x78, 0xDB, 0xB2,
  37593. 0x6A, 0x1A, 0xA7, 0xA6, 0x6E, 0x4D, 0x9A, 0x51,
  37594. 0xC9, 0x72, 0xAC, 0x9C, 0x94, 0xEA, 0xB9, 0x95,
  37595. 0x14, 0xB5, 0xAD, 0xAE, 0x62, 0x51, 0xE8, 0xAA,
  37596. 0x30, 0xA5, 0xE5, 0x87, 0x42, 0x4E, 0x3B, 0x7B,
  37597. 0xCC, 0x42, 0xEB, 0xE7, 0x33, 0x3D, 0x92, 0x10,
  37598. 0x97, 0x26, 0x53, 0xF8, 0x11, 0x8B, 0x83, 0xAB,
  37599. 0xE1, 0xBF, 0x7E, 0x9E, 0xE9, 0xCD, 0xAC, 0x28,
  37600. 0x99, 0x7D, 0x14, 0x4C, 0x34, 0xDE, 0xA6, 0x5B,
  37601. 0x59, 0x51, 0x2C, 0x73, 0x29, 0x27, 0xDB, 0xA8,
  37602. 0x20, 0x7D, 0x56, 0x91, 0x98, 0x47, 0x21, 0xB7,
  37603. 0x27, 0x9A, 0xFC, 0xDD, 0xE0, 0x6A, 0x6B, 0xD2,
  37604. 0x68, 0x0E, 0xBB, 0x9B, 0x2E, 0x3C, 0xFE, 0xE9,
  37605. 0xA6, 0x6D, 0x73, 0xD0, 0xC0, 0xDE, 0xD6, 0x53,
  37606. 0x70, 0x8B, 0x09, 0x0B, 0x82, 0x30, 0x65, 0xF9,
  37607. 0x70, 0x78, 0x49, 0xE3, 0xB3, 0x7D, 0x41, 0x25,
  37608. 0xCA, 0x69, 0x3E, 0x74, 0x2E, 0x02, 0x3F, 0x05,
  37609. 0x8A, 0xDC, 0x95, 0x07, 0x9B, 0xB0, 0x0C, 0x56,
  37610. 0xBE, 0x0D, 0x2F, 0x07, 0x81, 0x82, 0xEF, 0xAB,
  37611. 0x30, 0x72, 0xB0, 0xFD, 0x09, 0x76, 0x7B, 0x8A,
  37612. 0x13, 0xC2, 0x80, 0x5A, 0x75, 0x91, 0xB5, 0xB2,
  37613. 0xE1, 0x24, 0x75, 0xB5, 0xC8, 0x24, 0xDB, 0xEB,
  37614. 0x15, 0x79, 0x30, 0xAB, 0x38, 0x9F, 0x91, 0x5F,
  37615. 0xCC, 0xEC, 0x8F, 0x48, 0x64, 0x7E, 0xE4, 0xB6,
  37616. 0x6A, 0xB6, 0xB5, 0x36, 0xC2, 0x2D, 0xE3, 0xE5,
  37617. 0xEE, 0x4A, 0xBB, 0x42, 0xF8, 0xE0, 0x00, 0x9A,
  37618. 0xF0, 0x45, 0x54, 0xF1, 0x28, 0xAC, 0xA3, 0xCC,
  37619. 0xE4, 0x03, 0xBB, 0x01, 0xFD, 0xB7, 0xB5, 0xE2,
  37620. 0xA7, 0x2B, 0x82, 0x91, 0x1C, 0x1F, 0xD0, 0x65,
  37621. 0x23, 0xFF, 0x90, 0x19, 0x21, 0x41, 0xC6, 0x89,
  37622. 0xEC, 0xCB, 0x0B, 0xE6, 0x1B, 0x4C, 0x6D, 0x77,
  37623. 0x06, 0x29, 0x59, 0x02, 0x18, 0xA4, 0x01, 0x1A,
  37624. 0x68, 0xB8, 0x6F, 0xF5, 0x0D, 0x23, 0x03, 0x9C,
  37625. 0x9B, 0xCD, 0x43, 0x61, 0xF6, 0x98, 0x0A, 0x60,
  37626. 0xEF, 0x88, 0xD1, 0x44, 0x0D, 0x30, 0x4C, 0x5B,
  37627. 0x4B, 0x52, 0xD6, 0xED, 0xC2, 0x91, 0x12, 0xDC,
  37628. 0x3A, 0x8A, 0xF2, 0x85, 0x89, 0xE8, 0xF6, 0x29,
  37629. 0x48, 0xED, 0xB6, 0xBE, 0x76, 0x64, 0x6D, 0x59,
  37630. 0x66, 0x06, 0xB9, 0xE7, 0x05, 0xFE, 0xE3, 0xF1,
  37631. 0x44, 0xA0, 0x7B, 0xC9, 0xED, 0x1D, 0x40, 0x0C
  37632. };
  37633. static const byte msg_65[] = {
  37634. 0x88, 0x5A, 0x0B, 0xDD, 0x8D, 0xE7, 0x4B, 0xC7,
  37635. 0x11, 0x69, 0x0A, 0xA6, 0x14, 0xDD, 0xA5, 0x32,
  37636. 0xF4, 0xD8, 0xC7, 0xEA, 0x2C, 0x27, 0x85, 0x5A,
  37637. 0x57, 0x8E, 0x63, 0x61, 0xCA, 0xAE, 0x2C, 0x0B,
  37638. 0xF7, 0xE7, 0x73, 0xB4, 0x90, 0x0A, 0x32, 0x93,
  37639. 0x12, 0x1A, 0x6E, 0x0D, 0xD6, 0x10, 0x10, 0x7A,
  37640. 0x7A, 0x65, 0xBD, 0x6E, 0x11, 0xF6, 0x19, 0xFC,
  37641. 0x0E, 0x9C, 0xE7, 0xBF, 0x7B, 0x5D, 0xE1, 0x80,
  37642. 0x76, 0xE1, 0xB7, 0x25, 0x57, 0x20, 0x97, 0xB2,
  37643. 0x47, 0xD8, 0xE0, 0x46, 0x24, 0x94, 0xF6, 0x3F,
  37644. 0x4E, 0xDF, 0xBE, 0xAC, 0x2F, 0xA2, 0xEC, 0xAE,
  37645. 0x0C, 0xCA, 0xD4, 0x28, 0xBD, 0x79, 0x6C, 0xF2,
  37646. 0x60, 0x92, 0xA1, 0xCD, 0x50, 0x5F, 0x59, 0x39,
  37647. 0x11, 0xED, 0x10, 0xFD, 0xA4, 0x26, 0xC7, 0xE3,
  37648. 0xC5, 0xA4, 0x39, 0xE8, 0x50, 0x42, 0x13, 0x18,
  37649. 0xAE, 0x07, 0x85, 0xB0, 0x5A, 0xA9, 0x9F, 0x58,
  37650. 0xD6, 0x85, 0x6D, 0xEB, 0x78, 0xBB, 0xE4, 0x88,
  37651. 0xC7, 0x0E, 0xEE, 0x42, 0xBB, 0x9A, 0xB5, 0x92,
  37652. 0x7B, 0x2E, 0xD2, 0x5C, 0xD1, 0x43, 0x77, 0xCD,
  37653. 0x7E, 0x1A, 0x88, 0x34, 0xE8, 0x21, 0x48, 0x00,
  37654. 0x2F, 0xCB, 0x98, 0x5A, 0xB9, 0x43, 0x12, 0x97,
  37655. 0x01, 0x0B, 0x2B, 0xC7, 0x0F, 0x91, 0x32, 0x37,
  37656. 0x3C, 0x6D, 0xD2, 0xA2, 0xA9, 0xCF, 0x24, 0x6F,
  37657. 0xE0, 0x26, 0x2E, 0x8B, 0x53, 0xE6, 0x93, 0xF3,
  37658. 0xD6, 0xFE, 0xD3, 0xED, 0xD1, 0xF2, 0x00, 0x4E,
  37659. 0xD1, 0x7C, 0x2C, 0xF5, 0xB2, 0x57, 0xF4, 0xAD,
  37660. 0xA5, 0xDC, 0x1A, 0x7C, 0x15, 0x1F, 0xFE, 0x03,
  37661. 0xB9, 0x6A, 0x4D, 0xB9, 0x91, 0xE4, 0x13, 0x2D,
  37662. 0x01, 0xDE, 0x1F, 0x03, 0x3E, 0xD8, 0x13, 0x57,
  37663. 0xEA, 0xE7, 0xC1, 0xA8, 0xD2, 0xDD, 0xD9, 0x2D,
  37664. 0xDF, 0xC0, 0x6F, 0x67, 0x13, 0x94, 0xD2, 0xF6,
  37665. 0x02, 0x12, 0xC6, 0xE4, 0x49, 0xEA, 0x35, 0x93,
  37666. 0x24, 0xFE, 0xD3, 0x8C, 0x84, 0xD3, 0x6D, 0x15,
  37667. 0x43, 0x2E, 0x11, 0xE7, 0x15, 0x00, 0x15, 0x80,
  37668. 0x4F, 0x97, 0xA3, 0xC6, 0x77, 0x38, 0x2C, 0xD4,
  37669. 0x6A, 0xA4, 0xD7, 0xAC, 0xEE, 0x56, 0x86, 0xFB,
  37670. 0xCE, 0xD7, 0xA9, 0xE8, 0x5D, 0x29, 0xC4, 0x83,
  37671. 0x86, 0xE6, 0x9F, 0x40, 0x69, 0x3D, 0x9A, 0xDA,
  37672. 0xBE, 0xB4, 0x3B, 0xD0, 0xE5, 0x03, 0x6A, 0xCD,
  37673. 0xE6, 0x31, 0xB5, 0x49, 0x57, 0xF4, 0xFC, 0xE2,
  37674. 0x6F, 0x7A, 0x24, 0xB0, 0xDA, 0xD4, 0x34, 0x8A,
  37675. 0x67, 0x89, 0xCA, 0xE1, 0x06, 0x13, 0x06, 0x20,
  37676. 0xED, 0x2F, 0xA0, 0xEA, 0x38, 0xF5, 0x75, 0xF2,
  37677. 0x87, 0x83, 0xBC, 0x92, 0xB3, 0x2B, 0x0C, 0x51,
  37678. 0xC8, 0xA6, 0x54, 0x6F, 0x5D, 0x88, 0x09, 0x5F,
  37679. 0x9F, 0x73, 0xC6, 0x5B, 0xF6, 0xF2, 0x51, 0xA2,
  37680. 0xC4, 0x69, 0x74, 0x64, 0x45, 0xC5, 0x88, 0xC3,
  37681. 0xEA, 0x81, 0x39, 0xE4, 0x33, 0xD4, 0xFE, 0x2D,
  37682. 0xE4, 0xC0, 0xD3, 0x58, 0xB6, 0xCA, 0x8A, 0x62,
  37683. 0x94, 0xE6, 0xAF, 0xC1, 0xB9, 0x60, 0x74, 0xC0,
  37684. 0x68, 0xEF, 0x67, 0xB1, 0x58, 0xF1, 0x12, 0x9C,
  37685. 0xFE, 0x0A, 0x3A, 0xE7, 0xEB, 0x9D, 0x45, 0x4F,
  37686. 0x35, 0x7F, 0xBB, 0x6A, 0xB3, 0xB9, 0x92, 0x2B,
  37687. 0x1B, 0xCD, 0x55, 0x58, 0x61, 0x87, 0xCD, 0x24,
  37688. 0x69, 0x24, 0x82, 0x78, 0x23, 0x34, 0xAC, 0x9F,
  37689. 0x2B, 0x86, 0x12, 0x48, 0xF6, 0xA5, 0x30, 0xE9,
  37690. 0x3E, 0x11, 0x48, 0x87, 0x84, 0xDD, 0xE5, 0xEA,
  37691. 0x67, 0x8A, 0xE5, 0x05, 0x90, 0x3E, 0x23, 0x10,
  37692. 0x53, 0x30, 0x8C, 0x1B, 0x87, 0x84, 0x60, 0x7E,
  37693. 0x06, 0x3F, 0x48, 0x98, 0xA4, 0xFA, 0xB6, 0x01,
  37694. 0xD3, 0xE6, 0x96, 0x85, 0x97, 0x21, 0x55, 0xF6,
  37695. 0x3F, 0x09, 0xFD, 0x84, 0xB2, 0xB3, 0xDF, 0x74,
  37696. 0x1F, 0xB6, 0x42, 0xAC, 0xA6, 0x03, 0xD0, 0xD5,
  37697. 0x96, 0xE0, 0xA8, 0xDA, 0xD4, 0x24, 0xF4, 0x64,
  37698. 0x0F, 0x98, 0xB9, 0x6F, 0xB2, 0x42, 0xC6, 0x95,
  37699. 0xDC, 0x33, 0x1F, 0x57, 0x59, 0xF7, 0x5E, 0xAF,
  37700. 0x19, 0x1C, 0xBD, 0x98, 0x5E, 0xC5, 0x99, 0x8D,
  37701. 0x56, 0x48, 0xC8, 0x5E, 0xB6, 0x31, 0x29, 0x5F,
  37702. 0x61, 0x56, 0x7C, 0x11, 0x63, 0xF9, 0x90, 0xDC,
  37703. 0x4F, 0xA1, 0x71, 0x40, 0x91, 0x26, 0x1E, 0x5F,
  37704. 0x3E, 0x5F, 0x0B, 0xFE, 0x84, 0x55, 0xBB, 0x8B,
  37705. 0xAA, 0x1D, 0x69, 0x42, 0x1F, 0x15, 0x37, 0x4E,
  37706. 0x73, 0xB0, 0x7E, 0x78, 0x57, 0x9D, 0x0E, 0x25,
  37707. 0x1A, 0x41, 0xEE, 0x1A, 0x50, 0x43, 0xAA, 0xBF,
  37708. 0x8B, 0xE7, 0x73, 0xEE, 0x7F, 0x9D, 0x0F, 0xDF,
  37709. 0xCF, 0xD3, 0xAE, 0x71, 0x1F, 0xAB, 0x1D, 0x3D,
  37710. 0xBC, 0xC2, 0x84, 0x3B, 0xE5, 0xA9, 0x46, 0xB2,
  37711. 0x4D, 0x8B, 0x9B, 0x94, 0x35, 0x8B, 0x5F, 0x59,
  37712. 0x8E, 0x88, 0xED, 0x3D, 0x53, 0xF3, 0x10, 0xF8,
  37713. 0xEC, 0x63, 0x22, 0x9D, 0x4F, 0x5B, 0xB1, 0xB6,
  37714. 0xD5, 0x24, 0xA5, 0xAF, 0x9C, 0x39, 0x47, 0x79,
  37715. 0x25, 0xC7, 0xE2, 0x90, 0x95, 0xFC, 0x43, 0xF1,
  37716. 0x71, 0xFE, 0xCD, 0xD0, 0x61, 0xF3, 0x62, 0x62,
  37717. 0x71, 0x21, 0x75, 0x2C, 0x23, 0x6B, 0x79, 0x2F,
  37718. 0x1B, 0x31, 0x90, 0x79, 0x7C, 0xD0, 0x57, 0x5C,
  37719. 0x58, 0x4F, 0x30, 0xB5, 0x56, 0x81, 0x19, 0x61,
  37720. 0x90, 0x45, 0x09, 0xC9, 0x8B, 0xCD, 0xE8, 0x65,
  37721. 0x9D, 0x22, 0x80, 0xF4, 0x95, 0xA0, 0xC9, 0x55,
  37722. 0x7D, 0x38, 0x11, 0xAF, 0x5E, 0xD4, 0x37, 0x7B,
  37723. 0xC7, 0x59, 0x9E, 0x49, 0x59, 0xFF, 0x85, 0xF2,
  37724. 0x15, 0x0A, 0xCD, 0xEC, 0xC1, 0xF7, 0x67, 0x2D,
  37725. 0xE1, 0xEE, 0x4D, 0xB4, 0x4C, 0x1F, 0xB5, 0xF7,
  37726. 0x99, 0x8A, 0xB5, 0xDB, 0x74, 0x2F, 0x6C, 0x5D,
  37727. 0x32, 0xCB, 0xC0, 0xF2, 0xFB, 0xC9, 0x54, 0xEA,
  37728. 0xD6, 0xCC, 0x13, 0x4B, 0x97, 0x62, 0xDF, 0x33,
  37729. 0x13, 0x86, 0xDE, 0xCA, 0x31, 0x69, 0x47, 0x88,
  37730. 0x4B, 0x9A, 0x13, 0xAD, 0xEA, 0x5C, 0xBE, 0x29,
  37731. 0x56, 0x64, 0x4F, 0xA1, 0x2A, 0x7B, 0xB3, 0xBF,
  37732. 0xB9, 0x7E, 0x1D, 0x93, 0xA7, 0x01, 0x91, 0xAC,
  37733. 0x38, 0xA0, 0x37, 0x32, 0x58, 0xC2, 0xC2, 0x81,
  37734. 0x6D, 0xEA, 0x6E, 0xAF, 0x88, 0x0D, 0x69, 0xF4,
  37735. 0x5F, 0xBA, 0x4C, 0x29, 0x0F, 0x18, 0xD3, 0x4B,
  37736. 0xB8, 0x36, 0x8C, 0xF4, 0xEB, 0xB4, 0x72, 0xBA,
  37737. 0x49, 0x9C, 0xBB, 0x54, 0x50, 0x1E, 0xE3, 0xA2,
  37738. 0x8E, 0x5F, 0xB9, 0xFD, 0xC6, 0x6C, 0xF6, 0x45,
  37739. 0x72, 0x09, 0x47, 0x19, 0xBB, 0xDB, 0x48, 0xF3,
  37740. 0xF4, 0x88, 0x51, 0x3B, 0x65, 0x50, 0xE1, 0x27,
  37741. 0xE8, 0x34, 0x1C, 0x7E, 0x53, 0xDC, 0xFD, 0xA7,
  37742. 0xD4, 0x08, 0x05, 0x58, 0x0B, 0xC7, 0xD3, 0x0A,
  37743. 0x72, 0xF2, 0x44, 0xCC, 0xDB, 0x5A, 0xEF, 0x66,
  37744. 0x1B, 0x0F, 0x30, 0x4E, 0xC5, 0xB7, 0xAB, 0x93,
  37745. 0xB8, 0xC5, 0xC4, 0x9A, 0x77, 0x68, 0x38, 0xB7,
  37746. 0xD5, 0x23, 0x74, 0xAA, 0x41, 0x63, 0x02, 0x24,
  37747. 0xD6, 0x16, 0xF3, 0x10, 0xE4, 0x99, 0xEC, 0xAD,
  37748. 0xCE, 0x93, 0xE7, 0x8B, 0x94, 0xD3, 0xCA, 0x48,
  37749. 0xB3, 0x47, 0xBC, 0x0E, 0xEC, 0xAA, 0x20, 0x66,
  37750. 0x02, 0x29, 0x65, 0xC8, 0x07, 0xBE, 0xF9, 0x02,
  37751. 0x9B, 0xC5, 0x22, 0x8F, 0x00, 0x5E, 0xDB, 0x74,
  37752. 0xD4, 0xB1, 0x44, 0x98, 0xCE, 0x3A, 0xE1, 0x3B,
  37753. 0xEB, 0x7C, 0x69, 0x3B, 0x66, 0x9E, 0xE9, 0xF9,
  37754. 0xA6, 0xF4, 0x6F, 0xC0, 0x0E, 0xC0, 0x5E, 0x13,
  37755. 0x2B, 0xB6, 0xC6, 0x76, 0x0F, 0xB5, 0xC5, 0x1C,
  37756. 0x83, 0x23, 0xAC, 0xD6, 0xA3, 0xC7, 0x5A, 0x72,
  37757. 0xE9, 0x73, 0x89, 0x66, 0xD1, 0x25, 0xB9, 0x61,
  37758. 0x3B, 0x31, 0x45, 0xC6, 0x7B, 0x5E, 0x98, 0x81,
  37759. 0x87, 0xE8, 0x5F, 0x29, 0xAD, 0xCB, 0xAF, 0x74,
  37760. 0xE3, 0x3A, 0x61, 0x1F, 0xFF, 0x25, 0x2A, 0xEB,
  37761. 0xBA, 0xEB, 0x1E, 0xA6, 0x41, 0xE6, 0xFC, 0x8B,
  37762. 0xDF, 0x73, 0x41, 0xBE, 0x2A, 0xA8, 0x57, 0xE4,
  37763. 0x43, 0xAC, 0xFB, 0xCE, 0xB2, 0x15, 0x5D, 0x08,
  37764. 0x1A, 0xCB, 0x4C, 0xCD, 0xB0, 0x98, 0xD5, 0x7C,
  37765. 0xEF, 0x6F, 0x6F, 0xD3, 0x42, 0xDB, 0x2D, 0x83,
  37766. 0xB6, 0x12, 0x3E, 0x0A, 0xD3, 0xC9, 0x3F, 0x30,
  37767. 0x08, 0x11, 0xB8, 0xD5, 0xA1, 0x1A, 0x5A, 0x29,
  37768. 0xBE, 0x60, 0x81, 0x6F, 0x69, 0xB2, 0x9D, 0x1D,
  37769. 0x7E, 0x15, 0x88, 0x69, 0xD8, 0x60, 0xF6, 0xFB,
  37770. 0x82, 0x9D, 0xE8, 0x0D, 0x3E, 0x1B, 0x69, 0x9C,
  37771. 0x3A, 0xB6, 0x80, 0x4E, 0xB6, 0x54, 0x91, 0x78,
  37772. 0xD9, 0x47, 0x33, 0x38, 0xD6, 0xAF, 0x20, 0x9E,
  37773. 0x1F, 0x7D, 0x26, 0x3C, 0x66, 0x7A, 0xE6, 0x89,
  37774. 0x5F, 0x6E, 0x29, 0x33, 0x92, 0x34, 0x71, 0xF1,
  37775. 0x99, 0x58, 0x1F, 0x8A, 0x51, 0xBD, 0x9A, 0xA4,
  37776. 0x52, 0xEE, 0xE4, 0xBF, 0xE9, 0x56, 0x69, 0xAC,
  37777. 0xD0, 0x7B, 0x41, 0xB0, 0x0C, 0x03, 0xF5, 0x5A,
  37778. 0x40, 0xD1, 0x0B, 0x50, 0xF8, 0xE4, 0x67, 0xBD,
  37779. 0x07, 0x1C, 0x8F, 0x40, 0x5C, 0xF1, 0x19, 0x61,
  37780. 0x2D, 0x32, 0x40, 0x5B, 0xD5, 0x27, 0x5A, 0x6B,
  37781. 0xBF, 0x22, 0x17, 0xF9, 0xF1, 0x79, 0x0D, 0x29,
  37782. 0x99, 0x7B, 0x7B, 0x6B, 0x1E, 0xC8, 0xD7, 0x92,
  37783. 0x4A, 0xB9, 0xE6, 0x44, 0xC1, 0x29, 0xCE, 0xE8,
  37784. 0x74, 0x33, 0x29, 0x1A, 0x2C, 0x8E, 0xD6, 0xBC,
  37785. 0x3C, 0x2A, 0x19, 0xD0, 0x76, 0xB1, 0x77, 0xEE,
  37786. 0x60, 0x50, 0x69, 0x2A, 0xDA, 0x8E, 0x95, 0x57,
  37787. 0x4D, 0x6C, 0xE9, 0xAB, 0xE4, 0x97, 0x95, 0xD8,
  37788. 0xF2, 0x8E, 0xAB, 0x69, 0x67, 0x6E, 0x79, 0x03,
  37789. 0xA6, 0x56, 0xFA, 0xB3, 0x20, 0x25, 0xFE, 0x34,
  37790. 0x65, 0xCB, 0xDB, 0x57, 0x01, 0xC1, 0x77, 0x20,
  37791. 0x9D, 0x91, 0x89, 0xA5, 0x91, 0x7C, 0x13, 0x37,
  37792. 0xDE, 0x39, 0xF5, 0x75, 0xE5, 0xDD, 0xB9, 0x3C,
  37793. 0xA7, 0x6B, 0xEB, 0x52, 0xAF, 0x32, 0xE8, 0xD7,
  37794. 0x12, 0x7B, 0x28, 0xF7, 0xCE, 0x73, 0x12, 0xE8,
  37795. 0x03, 0x90, 0x47, 0x21, 0xAB, 0x21, 0x6E, 0x92,
  37796. 0xA8, 0xA9, 0xE6, 0x09, 0xFC, 0x10, 0xAF, 0x8D,
  37797. 0xC2, 0xAA, 0xCA, 0x14, 0xA9, 0x7B, 0xB0, 0xE4,
  37798. 0xB2, 0x34, 0xC7, 0x00, 0x0E, 0xBB, 0xE0, 0xC4,
  37799. 0x42, 0xF1, 0x85, 0x94, 0x6B, 0x7C, 0xE7, 0x72,
  37800. 0x80, 0x95, 0xCD, 0x60, 0x16, 0x9B, 0x0B, 0xD9,
  37801. 0x7B, 0x36, 0xB3, 0xAE, 0x38, 0x55, 0xD9, 0x89,
  37802. 0x25, 0xB2, 0x9D, 0x92, 0x94, 0xEF, 0x27, 0x75,
  37803. 0x09, 0xFC, 0xA4, 0x07, 0xEA, 0x2B, 0xC4, 0x76,
  37804. 0x59, 0x02, 0x6A, 0x82, 0x04, 0xD6, 0x96, 0x4F,
  37805. 0xC6, 0x5B, 0xEF, 0x35, 0x31, 0xE9, 0xC1, 0xE6,
  37806. 0xF9, 0x70, 0xBF, 0x2F, 0xF2, 0x40, 0x75, 0xEA,
  37807. 0x17, 0xD1, 0x36, 0xAD, 0xEA, 0xD2, 0x35, 0x6B,
  37808. 0x6C, 0xE4, 0x98, 0xF9, 0x3C, 0xD2, 0xF9, 0xE5,
  37809. 0xE1, 0x90, 0xD2, 0x09, 0xD9, 0x3E, 0x47, 0x3F,
  37810. 0xAA, 0x8E, 0xD9, 0x20, 0x96, 0x31, 0x5B, 0xF1,
  37811. 0xFC, 0xA6, 0x55, 0xFE, 0xBC, 0x78, 0xE0, 0x99,
  37812. 0x65, 0xC9, 0x74, 0x78, 0x29, 0x6B, 0x75, 0xD3,
  37813. 0x90, 0x56, 0x60, 0x4D, 0x32, 0x71, 0x91, 0x6D,
  37814. 0xCF, 0xF2, 0x25, 0xCB, 0x6B, 0x9A, 0x34, 0xE1,
  37815. 0x5D, 0xC1, 0x64, 0xB2, 0xA6, 0x8A, 0x3B, 0x42,
  37816. 0xDE, 0x05, 0x7A, 0x6B, 0xAC, 0x17, 0x32, 0xCF,
  37817. 0x59, 0x45, 0xBB, 0xCA, 0x12, 0xB8, 0xB3, 0x61,
  37818. 0x59, 0xFB, 0x89, 0xF7, 0xBB, 0xBE, 0x9F, 0xE0,
  37819. 0x34, 0x21, 0x8F, 0x5B, 0x3B, 0xCF, 0x18, 0x4C,
  37820. 0x20, 0x73, 0x06, 0xE6, 0xD2, 0xEA, 0x69, 0x59,
  37821. 0xEA, 0xE0, 0x89, 0x0A, 0x7B, 0x68, 0x02, 0xEC,
  37822. 0x1D, 0xA0, 0x82, 0xBE, 0xD6, 0x5B, 0xB6, 0xE4,
  37823. 0xEB, 0x4D, 0x56, 0x15, 0x70, 0x1C, 0xB0, 0xE3,
  37824. 0x50, 0x36, 0x33, 0x14, 0xA4, 0xD1, 0x01, 0xDB,
  37825. 0xBA, 0x60, 0x53, 0x71, 0xA3, 0x8B, 0x2D, 0x8A,
  37826. 0x37, 0xFF, 0x78, 0xEB, 0xB3, 0x69, 0x82, 0x53,
  37827. 0x88, 0xAA, 0xB7, 0xD3, 0xC6, 0x23, 0xB9, 0x3E,
  37828. 0x51, 0x2D, 0x96, 0xA9, 0xF3, 0x39, 0xEC, 0x96,
  37829. 0x8B, 0x35, 0x27, 0x59, 0xAF, 0x3E, 0x8F, 0xA3,
  37830. 0x21, 0x1C, 0x39, 0x29, 0x5B, 0x01, 0x10, 0xE6,
  37831. 0xDF, 0x26, 0x4E, 0x90, 0x67, 0x8C, 0x11, 0xE2,
  37832. 0xB9, 0x03, 0xAF, 0x32, 0x2E, 0x4F, 0xA7, 0x70,
  37833. 0x28, 0xD3, 0xEC, 0xC4, 0x4F, 0x62, 0x79, 0xD6,
  37834. 0x3B, 0x1E, 0x60, 0xD8, 0x06, 0x72, 0x41, 0x01,
  37835. 0x5F, 0xC4, 0xF8, 0x9B, 0xAA, 0x15, 0x6A, 0x78,
  37836. 0xFA, 0x77, 0xBB, 0x29, 0x14, 0xCA, 0xC2, 0x81,
  37837. 0xF4, 0x40, 0x9C, 0x9C, 0x03, 0x70, 0xAB, 0xD7,
  37838. 0xC1, 0xF8, 0xA5, 0xD1, 0x04, 0x0B, 0x59, 0x75,
  37839. 0x2C, 0xC4, 0xFD, 0xF0, 0xD1, 0x9C, 0xB0, 0xC5,
  37840. 0x6F, 0xEF, 0x34, 0xFA, 0x3A, 0x3B, 0xCE, 0xE1,
  37841. 0xF0, 0x64, 0xE3, 0x60, 0xE8, 0x6D, 0xC5, 0x5D,
  37842. 0xB5, 0xC9, 0x37, 0x5B, 0xDA, 0xDA, 0x67, 0x2E,
  37843. 0x72, 0xF6, 0x64, 0xE3, 0xAC, 0xB2, 0xE6, 0xD8,
  37844. 0xA0, 0x84, 0x09, 0xC8, 0xCD, 0x60, 0xA1, 0xF9,
  37845. 0x53, 0x80, 0xAB, 0x6C, 0x3A, 0xCB, 0x6B, 0x91,
  37846. 0xA8, 0xA9, 0xA3, 0xB7, 0x75, 0x50, 0x49, 0x79,
  37847. 0xB8, 0x02, 0x5A, 0xDB, 0x34, 0x22, 0x61, 0x9B,
  37848. 0xD1, 0x1E, 0x2B, 0x54, 0xFE, 0x6D, 0x07, 0x58,
  37849. 0x81, 0xAC, 0xAC, 0x24, 0x53, 0x20, 0x31, 0xCC,
  37850. 0xD2, 0x99, 0x06, 0x0E, 0x4E, 0xB7, 0xF7, 0xCB,
  37851. 0xD8, 0x08, 0x36, 0xD4, 0xB8, 0x23, 0xA5, 0xFF,
  37852. 0xA4, 0xFE, 0x8C, 0x6B, 0x98, 0x3D, 0x2A, 0xAE,
  37853. 0xB8, 0xF1, 0x6F, 0x6C, 0x1C, 0x22, 0x81, 0xEF,
  37854. 0xD7, 0x13, 0xFF, 0xDA, 0x22, 0x06, 0x9A, 0x5D,
  37855. 0x8A, 0xC4, 0x91, 0x29, 0x1C, 0xBF, 0x49, 0xF1,
  37856. 0x18, 0xC9, 0x46, 0xD5, 0x0F, 0x08, 0xE0, 0xD1,
  37857. 0x73, 0x28, 0x14, 0xE8, 0x15, 0x81, 0x90, 0x6A,
  37858. 0x31, 0x53, 0x94, 0x01, 0x14, 0xBE, 0xC8, 0xEB,
  37859. 0xD4, 0x9C, 0x73, 0x79, 0x0F, 0x9E, 0xD7, 0xCC,
  37860. 0xD9, 0x85, 0xED, 0xAD, 0x8D, 0xB3, 0x42, 0x6B,
  37861. 0x15, 0x13, 0x98, 0xEB, 0xF1, 0x6E, 0xFA, 0xFE,
  37862. 0x3D, 0xA0, 0xC7, 0xF3, 0x8B, 0x22, 0x76, 0x05,
  37863. 0x76, 0xD4, 0x88, 0x52, 0x73, 0xF5, 0xE4, 0x0B,
  37864. 0x14, 0x05, 0x57, 0x10, 0x7F, 0xCE, 0x0B, 0xF8,
  37865. 0x46, 0x1F, 0x24, 0x8B, 0xC4, 0x3F, 0xBF, 0x5C,
  37866. 0xEE, 0xE7, 0x6E, 0xF3, 0xA9, 0xEB, 0xD2, 0x30,
  37867. 0x95, 0x6C, 0x7B, 0x98, 0xAC, 0x89, 0x8A, 0x39,
  37868. 0x9E, 0x5C, 0x2A, 0xB0, 0xCB, 0xE9, 0xE5, 0xAB,
  37869. 0x94, 0x71, 0xDF, 0x5E, 0x53, 0x0C, 0x72, 0xF2,
  37870. 0x6C, 0x34, 0xDB, 0xFE, 0x2F, 0x83, 0x68, 0x3E,
  37871. 0xB6, 0x22, 0xF9, 0x64, 0x7A, 0xA0, 0x6A, 0x26,
  37872. 0x7D, 0x78, 0x97, 0x36, 0x31, 0x2C, 0x90, 0xC9,
  37873. 0xE5, 0x9D, 0x77, 0x12, 0x2A, 0x88, 0x53, 0x8F,
  37874. 0xD0, 0xF5, 0x39, 0x16, 0xAF, 0x08, 0xB2, 0x36,
  37875. 0x93, 0x5C, 0xDC, 0x5B, 0xB3, 0xCB, 0x49, 0x0C,
  37876. 0x83, 0x09, 0xE6, 0xA7, 0x9B, 0x43, 0xE7, 0xA5,
  37877. 0x4A, 0x8A, 0x07, 0xE1, 0xBA, 0xFB, 0x9B, 0x93,
  37878. 0x7E, 0xAC, 0x2F, 0xC3, 0xAC, 0xED, 0x30, 0x64,
  37879. 0x1F, 0x33, 0x79, 0x19, 0xD2, 0xDB, 0x54, 0xEC,
  37880. 0x7F, 0x32, 0x0E, 0xC5, 0x1C, 0xD1, 0x3C, 0x00,
  37881. 0xB9, 0xE6, 0x03, 0xDF, 0x6D, 0xD2, 0x69, 0x0C,
  37882. 0x75, 0xAF, 0x37, 0x07, 0xB7, 0xC9, 0x3E, 0x91,
  37883. 0xCF, 0x02, 0x78, 0xD7, 0x43, 0xA1, 0x8B, 0x4E,
  37884. 0x69, 0x74, 0xB4, 0x24, 0x08, 0x10, 0x42, 0xB5,
  37885. 0xB4, 0xE7, 0x8C, 0xEB, 0x7F, 0xFF, 0x67, 0x98,
  37886. 0x0B, 0xBC, 0xBA, 0x5E, 0x29, 0xBE, 0x61, 0x33,
  37887. 0x56, 0x16, 0xD6, 0x5E, 0x86, 0xF0, 0xE7, 0x46,
  37888. 0xD1, 0x83, 0xDF, 0xD4, 0x6B, 0x75, 0xC9, 0x30,
  37889. 0x0D, 0x60, 0xC5, 0x19, 0xFD, 0x95, 0xA8, 0xA6,
  37890. 0x61, 0xFF, 0xC8, 0x2A, 0xE7, 0x5D, 0xD1, 0x49,
  37891. 0x49, 0x1F, 0x99, 0xD1, 0x41, 0x4F, 0x15, 0x79,
  37892. 0x00, 0x8A, 0x80, 0x27, 0xA6, 0xC9, 0x98, 0xD3,
  37893. 0xE7, 0xA2, 0xBB, 0xFA, 0x07, 0xAB, 0x53, 0xEF,
  37894. 0xE8, 0x17, 0xAE, 0x9C, 0x6A, 0xE8, 0xD0, 0x52,
  37895. 0xAA, 0x85, 0x9D, 0x03, 0x48, 0xB0, 0xD2, 0xC8,
  37896. 0x5B, 0xCC, 0xC4, 0x50, 0x84, 0x90, 0xBE, 0x0F,
  37897. 0x9B, 0x32, 0x13, 0xB8, 0xAF, 0x7C, 0xCE, 0xE7,
  37898. 0x22, 0xE2, 0x82, 0x13, 0x18, 0x71, 0x46, 0xC5,
  37899. 0xDA, 0x05, 0xB7, 0x65, 0xD8, 0x33, 0x06, 0xFA,
  37900. 0x5A, 0x6B, 0x76, 0xD6, 0x92, 0x76, 0xD1, 0x6A,
  37901. 0x2B, 0xC6, 0x0D, 0xB1, 0xAD, 0xAB, 0x57, 0x62,
  37902. 0xEA, 0x76, 0x37, 0x4E, 0xAB, 0x2D, 0x34, 0xD2,
  37903. 0xA3, 0x57, 0xC7, 0x56, 0xFB, 0xEA, 0xD6, 0xA9,
  37904. 0xE3, 0xC1, 0x63, 0x07, 0xDE, 0xB9, 0x5E, 0x5A,
  37905. 0x30, 0x2E, 0x41, 0x4D, 0x43, 0xE9, 0x1C, 0xA1,
  37906. 0x5B, 0xB2, 0x4F, 0xAF, 0xDC, 0xE9, 0xBB, 0xBE,
  37907. 0x73, 0x55, 0x90, 0xF0, 0xD0, 0x02, 0x98, 0x6D,
  37908. 0x13, 0x50, 0x9A, 0xCA, 0x4C, 0xB3, 0x15, 0x3A,
  37909. 0x26, 0x14, 0x38, 0x67, 0xEB, 0xA7, 0x27, 0x33,
  37910. 0x48, 0x97, 0x58, 0x94, 0x57, 0xEA, 0xF9, 0x7E,
  37911. 0x8B, 0xB0, 0xBB, 0xF3, 0xF4, 0x84, 0x6E, 0x69,
  37912. 0x95, 0x2C, 0xF4, 0x6B, 0x1C, 0x65, 0x39, 0xB4,
  37913. 0x46, 0xA7, 0x99, 0xD6, 0x68, 0x47, 0x6E, 0x2E,
  37914. 0x49, 0x84, 0x75, 0x3E, 0x6C, 0x2E, 0x9A, 0x08,
  37915. 0xBC, 0xB7, 0x2F, 0x86, 0x68, 0x5C, 0xE1, 0xBF,
  37916. 0xEA, 0xA1, 0xAF, 0x59, 0xD6, 0x71, 0xB7, 0xBD,
  37917. 0xD6, 0xC5, 0xC2, 0xF2, 0xF3, 0xB5, 0x36, 0xBB,
  37918. 0x36, 0x23, 0x4F, 0xD6, 0x44, 0x59, 0x0A, 0x44,
  37919. 0x86, 0xCA, 0xDC, 0xD4, 0x22, 0x0F, 0x79, 0x09,
  37920. 0x99, 0x8C, 0x8C, 0x9E, 0x03, 0xA4, 0x51, 0x99,
  37921. 0x5A, 0xB9, 0x97, 0x76, 0x73, 0x20, 0xD3, 0x98,
  37922. 0x8C, 0x52, 0x96, 0xE1, 0x65, 0x7B, 0x4C, 0x77,
  37923. 0x40, 0xB2, 0xFE, 0x27, 0x0A, 0x11, 0x76, 0x6E,
  37924. 0x3B, 0x35, 0x12, 0xC6, 0x4E, 0xC2, 0x0E, 0xCC,
  37925. 0x04, 0xB5, 0x51, 0x91, 0xD0, 0x4A, 0xF7, 0x84,
  37926. 0xF2, 0xE7, 0xE5, 0x99, 0x7E, 0xB5, 0x3E, 0xAC,
  37927. 0x53, 0xDB, 0x61, 0x11, 0x71, 0x56, 0x4E, 0xAB,
  37928. 0x4A, 0x68, 0xC1, 0x6A, 0xA5, 0xC5, 0x7F, 0x72,
  37929. 0xEB, 0x14, 0x97, 0xA4, 0x27, 0xA0, 0x53, 0xA1,
  37930. 0xC4, 0x70, 0x7D, 0x58, 0xBD, 0xC1, 0xD7, 0xFD,
  37931. 0x9F, 0xB8, 0x8C, 0xCE, 0x34, 0xF9, 0xE1, 0x9C,
  37932. 0x59, 0x79, 0x31, 0x24, 0xEC, 0xBB, 0xF5, 0x6F,
  37933. 0x3F, 0xA3, 0x5A, 0x55, 0xB3, 0xDE, 0x64, 0xDF,
  37934. 0xA9, 0x95, 0x0B, 0x53, 0xF2, 0xA7, 0x25, 0x7B,
  37935. 0x8C, 0xAD, 0x25, 0x9A, 0x35, 0xBF, 0x15, 0x46,
  37936. 0x69, 0x4A, 0x83, 0x8C, 0x80, 0xFC, 0x37, 0xD0,
  37937. 0xC3, 0x6F, 0x00, 0xE2, 0x3C, 0x63, 0xAB, 0xC5,
  37938. 0x53, 0xC1, 0x8D, 0x4A, 0x40, 0x4B, 0xE6, 0xDC,
  37939. 0x05, 0xB1, 0x20, 0x23, 0x8B, 0xB8, 0xDF, 0x40,
  37940. 0x86, 0x97, 0xB9, 0x5E, 0xA4, 0xB7, 0xA1, 0x37,
  37941. 0xE0, 0x4B, 0x9E, 0xD9, 0x84, 0x2B, 0x2D, 0xAD,
  37942. 0xD1, 0xB1, 0x52, 0x15, 0x00, 0x9B, 0xDD, 0x23,
  37943. 0xA9, 0x27, 0x44, 0x21, 0x33, 0x17, 0x1C, 0x61,
  37944. 0x49, 0x84, 0x0D, 0x6A, 0x11, 0x7C, 0x77, 0xA5,
  37945. 0xD6, 0x8E, 0xE6, 0x1D, 0x6E, 0x90, 0x04, 0x4A,
  37946. 0xD3, 0x54, 0x3A, 0xA7, 0x1A, 0x28, 0xC5, 0x94,
  37947. 0x01, 0xCA, 0xDB, 0x1B, 0x5D, 0x78, 0xC5, 0xC6,
  37948. 0x69, 0x0D, 0x69, 0x88, 0x75, 0x00, 0x02, 0x0B,
  37949. 0x59, 0x6C, 0x3E, 0xC5, 0x30, 0xDF, 0xEE, 0x85,
  37950. 0x43, 0xA2, 0x9A, 0xF9, 0xDD, 0x85, 0x6E, 0xB3,
  37951. 0x0D, 0x83, 0x6A, 0x13, 0x88, 0xD0, 0x12, 0x15,
  37952. 0x53, 0x16, 0xFC, 0x5C, 0x15, 0x47, 0xEC, 0x6D,
  37953. 0x4D, 0x18, 0x2D, 0x88, 0xDB, 0xD2, 0x17, 0x6C,
  37954. 0xDE, 0x64, 0xEC, 0x70, 0x8D, 0x19, 0xDC, 0x66,
  37955. 0x69, 0x7F, 0xCF, 0x61, 0x6E, 0x4F, 0x23, 0x86,
  37956. 0xF5, 0x1A, 0x98, 0x47, 0x4B, 0xCC, 0xE9, 0x2F,
  37957. 0x12, 0x28, 0x12, 0xB9, 0xEB, 0xD8, 0x32, 0xDC,
  37958. 0xE4, 0xD8, 0x63, 0xAC, 0x56, 0x08, 0x2F, 0xEC,
  37959. 0x5E, 0x47, 0x29, 0xFF, 0x76, 0xFE, 0x95, 0x60,
  37960. 0xD2, 0x19, 0x61, 0x0E, 0xAF, 0xFC, 0x44, 0x42,
  37961. 0x11, 0x42, 0x79, 0xBC, 0x06, 0x3A, 0xAD, 0x93,
  37962. 0x7E, 0x46, 0x60, 0x03, 0xB0, 0xF5, 0x9F, 0x57,
  37963. 0x28, 0x48, 0x44, 0x8F, 0x0E, 0xFA, 0x72, 0x8C,
  37964. 0xE4, 0x18, 0xF4, 0x99, 0x6B, 0xB1, 0x23, 0x45,
  37965. 0xDC, 0x13, 0xA2, 0xF6, 0x5F, 0x57, 0x35, 0xA2,
  37966. 0xD7, 0x38, 0xF9, 0xE9, 0x8A, 0x7A, 0x79, 0xC6,
  37967. 0xB2, 0xCD, 0xBF, 0xD3, 0x41, 0x21, 0x56, 0xB3,
  37968. 0x39, 0xD9, 0x14, 0x3B, 0xDD, 0x85, 0xCB, 0x78,
  37969. 0x2F, 0xEB, 0x7E, 0x29, 0xBC, 0x52, 0x24, 0xE7,
  37970. 0x1B, 0x85, 0xB1, 0x65, 0xAE, 0xAB, 0x65, 0xF9,
  37971. 0x54, 0xD2, 0x1F, 0x37, 0x29, 0x52, 0x30, 0x5B,
  37972. 0x3D, 0x5F, 0x48, 0x84, 0x3F, 0x51, 0x27, 0x88,
  37973. 0x9D, 0xA7, 0x94, 0xF0, 0x73, 0xCD, 0x98, 0xD2,
  37974. 0x05, 0xE8, 0x25, 0x71, 0x7C, 0x93, 0x13, 0x82,
  37975. 0x5D, 0x53, 0x8D, 0x05, 0x0E, 0x69, 0x20, 0xC4,
  37976. 0xDB, 0xF2, 0xF6, 0x55, 0x24, 0x29, 0xD0, 0x41,
  37977. 0xF6, 0x2D, 0xF8, 0xC1, 0x2E, 0xC2, 0x4D, 0xE1,
  37978. 0xD7, 0x2D, 0xA0, 0x49, 0x16, 0x0B, 0x4D, 0x34,
  37979. 0xB5, 0x6D, 0xAE, 0x10, 0x93, 0x1E, 0xB6, 0x95,
  37980. 0x69, 0xC2, 0xB3, 0xC0, 0xAF, 0x6F, 0xFF, 0xA5,
  37981. 0x32, 0x3C, 0x7D, 0xC9, 0xC7, 0xC8, 0xEF, 0x0C,
  37982. 0x64, 0x20, 0x23, 0xC4, 0xFE, 0x89, 0x87, 0x8E,
  37983. 0xB3, 0xA6, 0xC5, 0x24, 0xCF, 0x03, 0x7E, 0x74,
  37984. 0xF7, 0xBF, 0x89, 0x1E, 0xCF, 0xB1, 0x02, 0xFA,
  37985. 0xF2, 0x9F, 0xD3, 0x9D, 0x99, 0x00, 0xDA, 0x7A,
  37986. 0x92, 0x7D, 0x13, 0x11, 0x92, 0xAD, 0x55, 0xF2,
  37987. 0xE1, 0x82, 0x72, 0xB1, 0x6A, 0xF1, 0x45, 0x05,
  37988. 0xDA, 0x17, 0xC9, 0xA1, 0x42, 0x82, 0x89, 0x77,
  37989. 0x31, 0xB6, 0x72, 0x54, 0x7C, 0x68, 0x10, 0x25,
  37990. 0x57, 0x30, 0x16, 0x15, 0x08, 0x58, 0x8B, 0xC1,
  37991. 0x61, 0xCB, 0xA0, 0x58, 0x29, 0x33, 0xB1, 0x64,
  37992. 0xF4, 0x4F, 0x06, 0xAA, 0x25, 0x31, 0xAA, 0xA8,
  37993. 0x92, 0x1C, 0x69, 0x1E, 0x6E, 0xB6, 0xBE, 0x81,
  37994. 0xDA, 0x9B, 0xE5, 0x1C, 0x56, 0x39, 0x55, 0xE0,
  37995. 0xC1, 0xEF, 0xD3, 0xED, 0x2A, 0x1C, 0x94, 0x9B,
  37996. 0xD4, 0xE0, 0x0B, 0x3A, 0xE9, 0xEB, 0xC1, 0x3C,
  37997. 0x4C, 0x6C, 0x4E, 0x5E, 0x39, 0x4C, 0xB0, 0x34,
  37998. 0xB9, 0xCB, 0x75, 0xBE, 0xCE, 0x86, 0x44, 0xFF,
  37999. 0x89, 0xEF, 0x95, 0xE7, 0x6E, 0xF7, 0x15, 0xE1,
  38000. 0x7A, 0xA2, 0x6B, 0x1F, 0xEB, 0x77, 0x4C, 0x50,
  38001. 0x59, 0xB3, 0xA3, 0x9A, 0x38, 0xDF, 0xD0, 0x57,
  38002. 0xD6, 0x41, 0xE4, 0x3F, 0xFE, 0x0F, 0x3E, 0x40,
  38003. 0xFF, 0xF6, 0xB2, 0x36, 0x3C, 0x1B, 0xF0, 0xEF,
  38004. 0x07, 0x87, 0x3D, 0x09, 0xA4, 0x87, 0x76, 0x9D,
  38005. 0x0A, 0x73, 0xCD, 0x0C, 0xC6, 0x44, 0xF5, 0x3C,
  38006. 0x25, 0xD2, 0x02, 0x5E, 0xE7, 0x1C, 0x69, 0xB7,
  38007. 0xAC, 0x0F, 0xA6, 0x61, 0x15, 0x57, 0xC4, 0x27,
  38008. 0xC0, 0x69, 0xDF, 0x2E, 0x1B, 0xF6, 0x29, 0xD9,
  38009. 0xA0, 0xCB, 0x5C, 0x67, 0xC7, 0xEA, 0x4F, 0xA6,
  38010. 0x58, 0xC7, 0x8D, 0x00, 0x42, 0xB0, 0x59, 0xE6,
  38011. 0xB6, 0x58, 0xFF, 0xCE, 0x60, 0x16, 0x69, 0x67,
  38012. 0xDB, 0x94, 0xF7, 0x16, 0xEB, 0x4D, 0x04, 0xB3,
  38013. 0xD2, 0x45, 0x0F, 0x40, 0x03, 0x1F, 0x10, 0xAC,
  38014. 0xDD, 0x07, 0x77, 0x7F, 0xBE, 0x9F, 0xBB, 0xB7,
  38015. 0x7F, 0xCB, 0x7C, 0x1F, 0xA9, 0xFC, 0x1E, 0xAF,
  38016. 0x0C, 0x5F, 0x86, 0xD7, 0x96, 0x2D, 0xAE, 0xD0,
  38017. 0x47, 0x4B, 0xA0, 0xFE, 0x68, 0xD9, 0xB2, 0x32,
  38018. 0x77, 0xA9, 0xCA, 0x7F, 0xC6, 0x76, 0xC6, 0x61,
  38019. 0x6B, 0x8E, 0x43, 0x9A, 0x1D, 0x4B, 0xFF, 0x72,
  38020. 0x43, 0x78, 0x19, 0xB5, 0x51, 0x87, 0x56, 0xA7,
  38021. 0x87, 0x3E, 0xF5, 0x84, 0x01, 0x26, 0x46, 0xC3,
  38022. 0x65, 0x9A, 0x6B, 0xA8, 0x6E, 0x62, 0x27, 0x26,
  38023. 0x14, 0xD8, 0x5E, 0xEC, 0xD5, 0x35, 0x0E, 0x3C,
  38024. 0xD0, 0xA1, 0x25, 0xAE, 0x9C, 0x17, 0xCC, 0xE2,
  38025. 0x52, 0x39, 0xE1, 0xEE, 0x9C, 0xDB, 0x39, 0xCA,
  38026. 0x7B, 0x18, 0xCF, 0x2C, 0x88, 0xCF, 0x14, 0x68,
  38027. 0x26, 0xB6, 0xCC, 0x1E, 0x6A, 0xA8, 0xE1, 0x69,
  38028. 0x2C, 0x91, 0x5F, 0x3B, 0xF1, 0xC1, 0xDB, 0x34,
  38029. 0xC6, 0xF3, 0x78, 0x83, 0xCB, 0x4E, 0xDC, 0xE0,
  38030. 0xF7, 0xC9, 0x95, 0xB6, 0x9E, 0x3A, 0xCE, 0x30,
  38031. 0xDC, 0x16, 0x6F, 0x78, 0x4C, 0x93, 0xD6, 0xCB,
  38032. 0xBC, 0xAC, 0x3C, 0x79, 0xBC, 0x31, 0x93, 0x10,
  38033. 0xCE, 0x6E, 0x66, 0x57, 0x00, 0xF1, 0x7F, 0x96,
  38034. 0x2F, 0x18, 0xB2, 0x40, 0x73, 0x9D, 0x15, 0x69,
  38035. 0x0B, 0x1B, 0x6C, 0x85, 0xD1, 0xAA, 0xA3, 0x2D,
  38036. 0x4A, 0x79, 0x74, 0x4A, 0xE5, 0x0C, 0xF9, 0xA9,
  38037. 0x0A, 0x09, 0x54, 0xB4, 0xA4, 0xD9, 0x4C, 0x49,
  38038. 0x9B, 0x41, 0x23, 0xEF, 0xC0, 0x20, 0x44, 0x31,
  38039. 0xF7, 0x22, 0x85, 0xB5, 0xDA, 0x9E, 0x19, 0x22,
  38040. 0x23, 0x0A, 0x30, 0x4D, 0x3A, 0x1B, 0xD8, 0x52,
  38041. 0x08, 0x72, 0x61, 0xB7, 0xCF, 0x0D, 0x8B, 0x90,
  38042. 0xD1, 0x46, 0x23, 0xEB, 0xCD, 0xC6, 0x38, 0x7B,
  38043. 0xC6, 0xAF, 0x65, 0xBE, 0x5F, 0x01, 0x1B, 0x6B,
  38044. 0xC1, 0x23, 0xC1, 0x30, 0x6A, 0x1E, 0x8F, 0xBF,
  38045. 0x2D, 0xF0, 0xB6, 0xF8, 0x9B, 0x0A, 0xE0, 0x5D,
  38046. 0xE0, 0xE4, 0xB7, 0xF5, 0x0A, 0xDA, 0x46, 0xE5,
  38047. 0x3A, 0x9B, 0x6B, 0xCA, 0xDA, 0x06, 0x43, 0xBE,
  38048. 0x6B, 0xFD, 0xC2, 0xB0, 0x6A, 0x6C, 0x75, 0x88,
  38049. 0x3C, 0x2D, 0xC6, 0x13, 0xAC, 0x72, 0x16, 0x31,
  38050. 0x7A, 0x40, 0xC4, 0xA2, 0xC0, 0x86, 0x69, 0x83,
  38051. 0xD3, 0x2C, 0x9C, 0xE0, 0xA6, 0xCC, 0xED, 0xF4,
  38052. 0x03, 0x62, 0x6B, 0xB2, 0x3B, 0x5B, 0x9D, 0xA5,
  38053. 0x86, 0x77, 0x7C, 0x73, 0x5E, 0x19, 0x11, 0xD7,
  38054. 0x7B, 0x11, 0x96, 0xC8, 0xFA, 0x47, 0x21, 0xD6,
  38055. 0xB0, 0xFE, 0x0B, 0x08, 0x11, 0xFC, 0x00, 0xB9,
  38056. 0xA1, 0x24, 0x2C, 0xBD, 0x4A, 0x92, 0x43, 0x10,
  38057. 0x08, 0xBE, 0xE9, 0xE1, 0x5D, 0x19, 0x82, 0xDE,
  38058. 0x34, 0xAE, 0xDC, 0xA6, 0x85, 0x8F, 0x19, 0x30,
  38059. 0x20, 0xB6, 0x44, 0x7F, 0x6B, 0xA6, 0x63, 0x70,
  38060. 0x59, 0xDA, 0x8D, 0xE0, 0xF8, 0x46, 0x86, 0x57,
  38061. 0xB8, 0x1C, 0x57, 0x13, 0x78, 0x41, 0x8C, 0xF5,
  38062. 0x7D, 0x77, 0xAE, 0x75, 0x6C, 0x59, 0x93, 0x2E,
  38063. 0x05, 0x25, 0x03, 0xD1, 0xEA, 0xFB, 0x2D, 0x60,
  38064. 0xD2, 0x61, 0x23, 0xEA, 0x0E, 0xFF, 0x55, 0xE3,
  38065. 0x24, 0x49, 0x00, 0x19, 0xBD, 0x1E, 0x56, 0x24,
  38066. 0x87, 0x2F, 0x7B, 0x98, 0x07, 0x36, 0xD2, 0x7C,
  38067. 0xC5, 0x9B, 0xE0, 0x4E, 0x29, 0xAB, 0xA1, 0xB8,
  38068. 0x35, 0x15, 0x31, 0xCE, 0x65, 0x14, 0x24, 0xF8,
  38069. 0x10, 0xB5, 0xAB, 0x3E, 0xD5, 0x58, 0xCA, 0xE5,
  38070. 0x73, 0x2D, 0x7C, 0x8B, 0xB4, 0x62, 0x75, 0x03,
  38071. 0x30, 0x89, 0xFE, 0x32, 0xF8, 0x65, 0x99, 0xD0,
  38072. 0x88, 0xD5, 0x72, 0x88, 0x03, 0xC9, 0x51, 0x03,
  38073. 0xBA, 0x2F, 0xFB, 0x7C, 0x39, 0x02, 0x05, 0xC4,
  38074. 0xCE, 0xD8, 0xB3, 0xC2, 0x7B, 0x29, 0x8E, 0xA7,
  38075. 0x9D, 0x35, 0x97, 0xB7, 0x17, 0xDE, 0x28, 0x0B,
  38076. 0x32, 0xE5, 0x41, 0xDA, 0x1D, 0x98, 0xBD, 0x27,
  38077. 0xEF, 0xF7, 0xB4, 0x43, 0x09, 0x13, 0x39, 0xC7,
  38078. 0x40, 0x16, 0x11, 0x20, 0x71, 0xCB, 0xB6, 0xC9,
  38079. 0xB0, 0x8F, 0x20, 0xC1, 0xF0, 0x40, 0xFB, 0x6E,
  38080. 0x73, 0x04, 0x8F, 0x73, 0xCA, 0x45, 0xDB, 0xE0,
  38081. 0xF9, 0x25, 0x8D, 0x32, 0xF2, 0x3E, 0x36, 0xBE,
  38082. 0xF7, 0x88, 0xF8, 0x13, 0x4D, 0x9B, 0x10, 0xC2,
  38083. 0x58, 0x0B, 0x20, 0xF8, 0x78, 0xB6, 0x4C, 0x7D,
  38084. 0x2A, 0xA6, 0x81, 0x40, 0xD1, 0x30, 0x50, 0x38,
  38085. 0x2A, 0x5F, 0xBC, 0x81, 0x8E, 0x0F, 0xD4, 0xD0,
  38086. 0x87, 0x99, 0x78, 0x3D, 0xBE, 0x25, 0x15, 0xF4,
  38087. 0x45, 0x61, 0xA3, 0x1A, 0x7D, 0x05, 0x3F, 0xB5,
  38088. 0xA6, 0x1C, 0x41, 0xC6, 0x0E, 0xBE, 0x57, 0x6F,
  38089. 0xC5, 0xB6, 0x38, 0x63, 0x90, 0x55, 0x23, 0xFC,
  38090. 0x26, 0x9E, 0xFD, 0xB8, 0x6C, 0xF2, 0x99, 0x6B,
  38091. 0x6D, 0x90, 0xFE, 0x28, 0xA0, 0x16, 0xEE, 0x63,
  38092. 0xC2, 0x4C, 0xD6, 0xB2, 0x0C, 0xFA, 0x6E, 0x85,
  38093. 0x51, 0xE4, 0x2F, 0x57, 0x91, 0x82, 0x84, 0x43,
  38094. 0x8A, 0x44, 0x31, 0x6C, 0x68, 0x02, 0x01, 0x7C,
  38095. 0xCE, 0x4D, 0xC0, 0x7C, 0x43, 0xA9, 0x54, 0xF5,
  38096. 0x0E, 0xCA, 0xE6, 0x15, 0x98, 0xAE, 0x41, 0x57,
  38097. 0x0A, 0x66, 0xBA, 0x6D, 0x6E, 0x68, 0xB9, 0x2E,
  38098. 0x0D, 0x42, 0xD2, 0xF5, 0x0B, 0xFC, 0x2D, 0xA8,
  38099. 0x61, 0x6E, 0x60, 0x4E, 0x51, 0x78, 0xEB, 0x0C,
  38100. 0x52, 0x9E, 0xC0, 0x4A, 0xB0, 0x92, 0x85, 0x5C,
  38101. 0x3A, 0x3D, 0x69, 0x95, 0xAB, 0x62, 0xEB, 0x2F,
  38102. 0x9B, 0x12, 0xF5, 0x2E, 0xB5, 0xA6, 0x93, 0xCE,
  38103. 0x14, 0x97, 0xA7, 0x1E, 0x0A, 0x7B, 0x94, 0x74,
  38104. 0xFB, 0x65, 0xD0, 0x5A, 0x97, 0x55, 0x40, 0x02,
  38105. 0x71, 0x87, 0x9C, 0x9F, 0xCB, 0x41, 0x3F, 0x08,
  38106. 0x8D, 0x6A, 0xCA, 0xE6, 0xEC, 0xE6, 0x71, 0x22,
  38107. 0xF8, 0x58, 0x9F, 0xF1, 0x94, 0xF6, 0xE4, 0xD6,
  38108. 0xDC, 0x35, 0xD7, 0xEB, 0x6B, 0x78, 0x99, 0x66,
  38109. 0xF9, 0xE2, 0x15, 0x27, 0xC9, 0x8C, 0x27, 0xB4,
  38110. 0x89, 0x3C, 0x15, 0xEE, 0x52, 0x71, 0xA9, 0xD2,
  38111. 0x50, 0x3C, 0xD2, 0x31, 0xBB, 0x3A, 0xE5, 0x87,
  38112. 0xAF, 0x65, 0x2B, 0xF2, 0xF5, 0xC9, 0x44, 0xA2,
  38113. 0x59, 0x1C, 0x57, 0x96, 0xB9, 0xC2, 0x5E, 0xCB,
  38114. 0x8A, 0x5B, 0x2B, 0x7A, 0x7E, 0x93, 0x3C, 0x08,
  38115. 0x27, 0xCD, 0xB4, 0xB0, 0x1B, 0xF3, 0x82, 0x50,
  38116. 0x78, 0xCF, 0xEA, 0x28, 0x57, 0xB1, 0x0F, 0xB4,
  38117. 0xB6, 0x93, 0x82, 0x8E, 0x7A, 0xD1, 0x9F, 0x04,
  38118. 0xEC, 0xEE, 0x24, 0x3D, 0x8A, 0x5E, 0x56, 0x99,
  38119. 0x8D, 0x83, 0xA4, 0x05, 0x7D, 0xFB, 0x36, 0xDB,
  38120. 0xAB, 0xD1, 0x67, 0x59, 0xC7, 0x4A, 0xB9, 0xAF,
  38121. 0x99, 0xB6, 0xD8, 0xD4, 0x2C, 0xCA, 0x8C, 0xCC,
  38122. 0xD2, 0x32, 0xAB, 0x51, 0xCE, 0x2D, 0x22, 0xE0,
  38123. 0x29, 0xB1, 0x73, 0x10, 0x60, 0xA8, 0x6B, 0x8F,
  38124. 0x68, 0xAF, 0x58, 0x06, 0x9D, 0x72, 0x36, 0x98,
  38125. 0x3F, 0xF3, 0x6B, 0xAD, 0x3E, 0x7F, 0x4A, 0x00,
  38126. 0x94, 0x04, 0xAE, 0xE9, 0x8A, 0x9E, 0x8A, 0x03,
  38127. 0xD8, 0x04, 0xCC, 0xFE, 0xE3, 0xF8, 0xA2, 0x04,
  38128. 0x64, 0x17, 0x54, 0x77, 0xCA, 0x20, 0xD0, 0x80,
  38129. 0x1B, 0x36, 0xEF, 0x59, 0x31, 0xFA, 0xE4, 0xF5,
  38130. 0xAF, 0x56, 0x09, 0x02, 0xAD, 0xCF, 0xA6, 0xBC,
  38131. 0x26, 0x23, 0x27, 0x6D, 0xF3, 0x52, 0xCE, 0x2F,
  38132. 0x4C, 0x9C, 0xA8, 0x23, 0x75, 0xFA, 0x56, 0x9E,
  38133. 0x07, 0x5B, 0xB9, 0x30, 0x5A, 0xB1, 0x27, 0xFF,
  38134. 0x72, 0xBF, 0x50, 0xB1, 0x27, 0xEF, 0xA1, 0x0C,
  38135. 0x3A, 0xC9, 0x72, 0x21, 0xBE, 0xD8, 0xDC, 0xD5,
  38136. 0x66, 0x4A, 0x0A, 0x58, 0xFA, 0x57, 0xB4, 0x00,
  38137. 0x07, 0x31, 0xF2, 0x4E, 0xDC, 0xE0, 0x86, 0x99,
  38138. 0x45, 0xE5, 0x45, 0xCF, 0x27, 0x35, 0x79, 0x57,
  38139. 0xF5, 0xA2, 0x7A, 0x29, 0xFA, 0x5E, 0xCF, 0xF9,
  38140. 0xA9, 0x96, 0x11, 0xE1, 0x4A, 0x6C, 0xE5, 0xB8,
  38141. 0x8E, 0x78, 0xE6, 0xA1, 0x46, 0x97, 0xAE, 0xB4,
  38142. 0xF3, 0x6D, 0x7F, 0x8E, 0xD1, 0x86, 0x6B, 0x78,
  38143. 0x2B, 0x55, 0xC5, 0xDF, 0x0F, 0x43, 0x78, 0xED,
  38144. 0xD2, 0x38, 0xE5, 0x8B, 0x94, 0x7A, 0x06, 0xC5,
  38145. 0x73, 0x17, 0x55, 0x93, 0xAD, 0xA5, 0xAC, 0xBA,
  38146. 0x81, 0x8A, 0x6D, 0x73, 0x4B, 0xA1, 0x32, 0x8F,
  38147. 0x21, 0xA6, 0x5B, 0x51, 0x31, 0x58, 0xD0, 0xE4,
  38148. 0x0B, 0x93, 0x46, 0xF2, 0x51, 0x30, 0x3E, 0x60,
  38149. 0xE1, 0xCB, 0x30, 0x04, 0x15, 0x8D, 0x1E, 0x87,
  38150. 0xA6, 0xF6, 0x38, 0xE0, 0x27, 0x84, 0x81, 0x18,
  38151. 0x2B, 0x37, 0xBB, 0xD3, 0xDB, 0xE7, 0x91, 0xA3,
  38152. 0x1B, 0x6B, 0x20, 0xCB, 0x2C, 0x52, 0xB1, 0xB9,
  38153. 0x6A, 0x94, 0xF8, 0xCD, 0xBA, 0x5D, 0xC7, 0xDD,
  38154. 0x79, 0x36, 0x38, 0xC2, 0xFC, 0xEC, 0x4F, 0x2B,
  38155. 0x5F, 0x73, 0x44, 0x03, 0xE9, 0xA9, 0xF5, 0xD9,
  38156. 0x99, 0xEA, 0x61, 0xDC, 0x6A, 0x98, 0xBE, 0xDE,
  38157. 0xB9, 0x34, 0xCC, 0x76, 0xB0, 0xE1, 0x8C, 0x70,
  38158. 0x3A, 0xA5, 0x7C, 0xD1, 0xC0, 0x2A, 0x8E, 0x7D,
  38159. 0x47, 0x8A, 0x63, 0xEA, 0x30, 0x6B, 0xEE, 0x36,
  38160. 0x0B, 0xA8, 0xAE, 0x46, 0xCD, 0x01, 0x83, 0xF6,
  38161. 0x07, 0xF9, 0xED, 0x8B, 0x69, 0x97, 0xB6, 0xC3,
  38162. 0x5D, 0x75, 0x6E, 0xD8, 0xDF, 0x01, 0x82, 0x48,
  38163. 0x31, 0x2F, 0xDE, 0xED, 0x8E, 0xC5, 0xD8, 0xA6,
  38164. 0xC0, 0x36, 0x0E, 0x66, 0xA4, 0xE9, 0xE5, 0xA9,
  38165. 0x7D, 0x5C, 0xD2, 0x43, 0x72, 0xC0, 0xAD, 0x26,
  38166. 0x78, 0xF2, 0xB0, 0x08, 0x12, 0xAE, 0x6C, 0x1A,
  38167. 0x0F, 0x53, 0x30, 0xB3, 0xAB, 0x01, 0x53, 0xDA,
  38168. 0x3C, 0x5F, 0x4C, 0x17, 0xBD, 0x2F, 0xB6, 0x0E,
  38169. 0x7E, 0x80, 0x87, 0x4C, 0x1B, 0x92, 0x9B, 0x62,
  38170. 0xE3, 0x89, 0xEE, 0xE2, 0xA0, 0x14, 0x06, 0x0D,
  38171. 0x4D, 0xCC, 0x96, 0x5A, 0xF8, 0x64, 0x2A, 0x05,
  38172. 0xA9, 0xEE, 0xD5, 0x0D, 0x23, 0x90, 0xB0, 0x67,
  38173. 0xD5, 0x51, 0x1D, 0x18, 0xBC, 0xBA, 0xE6, 0xA5,
  38174. 0xAD, 0x29, 0x18, 0xD5, 0x06, 0xFC, 0xC9, 0x12,
  38175. 0x6D, 0x70, 0xA8, 0x6E, 0x96, 0x8B, 0x5F, 0x9C,
  38176. 0x99, 0x43, 0x07, 0x02, 0x37, 0x48, 0x8C, 0xFB,
  38177. 0x5F, 0xF5, 0xDE, 0x69, 0x26, 0x73, 0x7D, 0xF6,
  38178. 0x3A, 0x2C, 0xE5, 0x58, 0x01, 0xC3, 0x48, 0xB0,
  38179. 0xF0, 0x0D, 0x56, 0xAF, 0x8C, 0x0F, 0x5C, 0xB3,
  38180. 0xBA, 0x44, 0x8C, 0x39, 0xB0, 0x20, 0xD2, 0x93,
  38181. 0x81, 0x19, 0x99, 0x4E, 0xAC, 0xB9, 0x1F, 0xC3,
  38182. 0x1F, 0x34, 0x7D, 0xF3, 0x3E, 0x1A, 0xE1, 0x26,
  38183. 0x7C, 0xB7, 0x22, 0x0A, 0xDC, 0x0D, 0x14, 0xF8,
  38184. 0x43, 0x8A, 0x23, 0x46, 0x37, 0x9C, 0x2A, 0xB8,
  38185. 0x1F, 0x24, 0x72, 0xE2, 0xEA, 0xC4, 0x67, 0x13,
  38186. 0x17, 0x33, 0xBD, 0xA0, 0x07, 0xA0, 0x3E, 0xDE,
  38187. 0x8B, 0xC4, 0xD6, 0xDB, 0xD9, 0xF1, 0xB8, 0xF4,
  38188. 0xFB, 0x83, 0x13, 0x14, 0xCD, 0x36, 0xF6, 0xDC,
  38189. 0xD5, 0x85, 0x93, 0x7C, 0xF9, 0x6C, 0xEA, 0x52,
  38190. 0x92, 0xFB, 0xFC, 0x95, 0x02, 0x10, 0x7B, 0x57,
  38191. 0x9F, 0xF0, 0x7C, 0x2E, 0x79, 0x00, 0x3D, 0xB2,
  38192. 0xA1, 0x6C, 0x4E, 0xD4, 0x17, 0xFA, 0x0F, 0x13,
  38193. 0xC8, 0xBF, 0xB1, 0x82, 0xF7, 0xDD, 0xCF, 0x08,
  38194. 0xF2, 0x50, 0xDB, 0x16, 0xA4, 0x5A, 0x60, 0x4A,
  38195. 0x57, 0x2B, 0x0E, 0xDC, 0x4A, 0xBF, 0x9C, 0x86,
  38196. 0x08, 0x8A, 0x5A, 0xC8, 0x74, 0xDD, 0xA2, 0x6E,
  38197. 0x12, 0xA0, 0xEF, 0x63, 0x5A, 0xD2, 0x82, 0xAD,
  38198. 0xCD, 0xC7, 0xED, 0x16, 0x86, 0x45, 0x3D, 0xFB,
  38199. 0x35, 0xC3, 0xB1, 0xBA, 0x68, 0x21, 0xB4, 0xB7,
  38200. 0x22, 0x0B, 0x55, 0x79, 0x8B, 0x9C, 0xCF, 0xE0,
  38201. 0x66, 0x61, 0x5C, 0xE2, 0x55, 0x96, 0x0D, 0x09,
  38202. 0xE6, 0x77, 0xFE, 0xFE, 0x76, 0xBE, 0x91, 0x5E,
  38203. 0x04, 0xE5, 0x65, 0x44, 0xBD, 0x09, 0xD0, 0x6F,
  38204. 0x83, 0x44, 0xF9, 0x68, 0xDC, 0x68, 0x25, 0xCB,
  38205. 0xC6, 0x64, 0xD5, 0x18, 0xA4, 0x41, 0xE1, 0x9B,
  38206. 0x07, 0x6F, 0xC3, 0x38, 0x91, 0x37, 0xFC, 0x1B,
  38207. 0x73, 0x32, 0xE2, 0xB0, 0x68, 0x95, 0x44, 0x3B,
  38208. 0x7A, 0x00, 0x23, 0x36, 0x31, 0x15, 0x79, 0xA9,
  38209. 0xB0, 0x8F, 0x36, 0x73, 0xDA, 0x05, 0x90, 0xE6,
  38210. 0x96, 0xCE, 0xD9, 0x01, 0x44, 0x4A, 0x70, 0xA6,
  38211. 0x7B, 0x2A, 0x7D, 0x55, 0x12, 0xD6, 0x5B, 0xFC,
  38212. 0xD7, 0xAF, 0x1E, 0x34, 0x27, 0x77, 0x69, 0xE1,
  38213. 0x71, 0x08, 0x83, 0x01, 0xDE, 0x78, 0x46, 0xF0,
  38214. 0x88, 0xF4, 0x87, 0xC4, 0x92, 0x1B, 0xEB, 0x98,
  38215. 0x35, 0x4B, 0xAE, 0x9A, 0xF6, 0xEA, 0xB2, 0x34,
  38216. 0x91, 0x14, 0xEB, 0x21, 0xF6, 0x18, 0xDB, 0x1D,
  38217. 0x92, 0x6C, 0x1D, 0x2F, 0xE3, 0xA5, 0xF2, 0x29,
  38218. 0xC5, 0x73, 0x40, 0xC4, 0x0A, 0xEC, 0x11, 0xC2,
  38219. 0xD0, 0x14, 0x4D, 0x03, 0x94, 0xFC, 0x4D, 0x8E,
  38220. 0x38, 0x66, 0xA7, 0xD0, 0xA1, 0x0B, 0x64, 0xC8,
  38221. 0xB9, 0x92, 0xB0, 0xA4, 0xDD, 0xBC, 0xAD, 0x82,
  38222. 0x4E, 0x43, 0x97, 0x43, 0x78, 0xEA, 0x9A, 0x38,
  38223. 0xE5, 0x8C, 0x2C, 0x5A, 0xE1, 0x94, 0xAF, 0x43,
  38224. 0x10, 0xFB, 0xEC, 0x90, 0x28, 0x41, 0x6C, 0x5C,
  38225. 0xB7, 0xB8, 0xAF, 0xA5, 0x24, 0xF7, 0x4F, 0xFD,
  38226. 0x6F, 0x2E, 0x98, 0x44, 0x3F, 0x5E, 0x89, 0x24,
  38227. 0xF6, 0xCF, 0x11, 0x0E, 0x67, 0x1B, 0x81, 0x68,
  38228. 0x37, 0xD5, 0x9B, 0x2D, 0xB9, 0x1C, 0xB1, 0xE6,
  38229. 0x87, 0xD6, 0xA2, 0x02, 0x0F, 0x91, 0x08, 0xF6,
  38230. 0x9B, 0x94, 0x76, 0x62, 0xFD, 0xE7, 0x18, 0xAC,
  38231. 0x28, 0xA6, 0xAC, 0xDA, 0x27, 0xF4, 0x33, 0x59,
  38232. 0xBB, 0xBE, 0x36, 0x2C, 0xEE, 0xEA, 0x91, 0xE6,
  38233. 0x91, 0x95, 0x2C, 0x58, 0x0A, 0xB2, 0xCA, 0xA3,
  38234. 0xAA, 0x39, 0x03, 0x9A, 0x75, 0x3C, 0x27, 0x6E,
  38235. 0x02, 0x89, 0x17, 0x4B, 0x02, 0x42, 0x7C, 0xB4,
  38236. 0x2E, 0xAD, 0xB4, 0xD9, 0x35, 0xB2, 0x30, 0x9E,
  38237. 0x2F, 0xEC, 0x9F, 0x25, 0x56, 0x1A, 0x35, 0x40,
  38238. 0xF1, 0xAF, 0x1D, 0xA4, 0xA8, 0x62, 0x07, 0x70,
  38239. 0x98, 0x6C, 0xDE, 0x1E, 0x89, 0xC1, 0xD3, 0x30,
  38240. 0xBB, 0x82, 0x72, 0x40, 0xF2, 0xBC, 0x53, 0xC7,
  38241. 0xDE, 0xAB, 0xFC, 0x7D, 0xAD, 0xBF, 0xDA, 0xE0,
  38242. 0xA7, 0xA1, 0x0C, 0xD6, 0x73, 0x37, 0x36, 0xA1,
  38243. 0xEE, 0xA6, 0x96, 0x88, 0x79, 0x0E, 0x4A, 0x2C,
  38244. 0x69, 0x4C, 0xE5, 0x30, 0xFB, 0xDD, 0xE1, 0xFE,
  38245. 0x86, 0x90, 0xDC, 0xDF, 0x03, 0xF5, 0x17, 0x2F,
  38246. 0xF4, 0x58, 0x2D, 0xD3, 0xED, 0x3D, 0x7D, 0xA0,
  38247. 0xB3, 0x6E, 0x1E, 0xD3, 0xBB, 0xD9, 0x57, 0xBA,
  38248. 0x8B, 0x00, 0x72, 0xC4, 0xEE, 0xCF, 0x39, 0xD5,
  38249. 0x74, 0xFA, 0x13, 0xF0, 0xD7, 0xE9, 0x10, 0x0C,
  38250. 0x7A, 0x52, 0x62, 0xD0, 0xC9, 0xD5, 0x2D, 0xDC,
  38251. 0x11, 0xD4, 0xFF, 0x34, 0xB2, 0x55, 0xF9, 0x99,
  38252. 0x81, 0xB4, 0xC9, 0x14, 0x02, 0x91, 0x81, 0x56,
  38253. 0x29, 0xF6, 0xA9, 0x1A, 0x19, 0x8E, 0x74, 0xB3,
  38254. 0xA3, 0xD1, 0x28, 0xB5, 0x72, 0xD8, 0x6F, 0x54,
  38255. 0x15, 0x74, 0x55, 0x70, 0x26, 0x62, 0xCB, 0x1D,
  38256. 0x15, 0x2C, 0x7F, 0x4C, 0x9C, 0xB4, 0xDE, 0xA2,
  38257. 0x07, 0xD5, 0xA9, 0x38, 0x29, 0x42, 0x51, 0x67,
  38258. 0x44, 0x26, 0x97, 0x7E, 0x73, 0x0E, 0xC6, 0x01,
  38259. 0x00, 0x65, 0xC8, 0xE0, 0x34, 0x88, 0x2B, 0xD3,
  38260. 0x2F, 0xD3, 0x5C, 0x6A, 0xF6, 0xB8, 0xD9, 0x3A,
  38261. 0x50, 0x9C, 0xC3, 0x39, 0xD9, 0x6F, 0xB9, 0xDD,
  38262. 0x55, 0x8A, 0xF9, 0x52, 0x35, 0xFB, 0xF1, 0x71,
  38263. 0x97, 0x76, 0x04, 0x75, 0xEE, 0x2E, 0x3F, 0xCA,
  38264. 0x0E, 0x83, 0xA8, 0xE3, 0x1F, 0xA7, 0xF1, 0x3D,
  38265. 0x78, 0xCC, 0x79, 0x64, 0x80, 0x5E, 0x77, 0x05,
  38266. 0xDB, 0xB7, 0x0F, 0x73, 0x53, 0x3A, 0x56, 0xD8,
  38267. 0xB7, 0x7C, 0x12, 0xE8, 0xF6, 0x51, 0x07, 0xC9,
  38268. 0x01, 0x43, 0x97, 0x51, 0x75, 0x95, 0x94, 0x65,
  38269. 0xFD, 0x4D, 0x8C, 0x8C, 0xD3, 0xA8, 0xEE, 0xA9,
  38270. 0x5E, 0xFB, 0xC7, 0xF6, 0xF8, 0x40, 0x0E, 0xA5,
  38271. 0xD5, 0x1E, 0x79, 0xB4, 0x0C, 0xEF, 0x8B, 0x04,
  38272. 0x59, 0x4D, 0x0C, 0x6F, 0x08, 0xD5, 0x00, 0xA2,
  38273. 0xAD, 0x08, 0xB4, 0x62, 0xE0, 0x2C, 0xF6, 0x30,
  38274. 0x31, 0x1E, 0xD7, 0x81, 0x56, 0x61, 0x17, 0x0D,
  38275. 0xB3, 0x9F, 0x27, 0x75, 0x38, 0x42, 0x6E, 0xB2,
  38276. 0xB0, 0x6C, 0xB8, 0xC9, 0xD8, 0x20, 0xC8, 0x36,
  38277. 0x7D, 0x1D, 0x57, 0x10, 0x4E, 0xC1, 0x45, 0xFC,
  38278. 0x93, 0xB1, 0xF7, 0x7B, 0xA1, 0x3B, 0x71, 0x12,
  38279. 0x16, 0xE5, 0x8F, 0xD0, 0x0C, 0x7D, 0xC0, 0x05,
  38280. 0x18, 0x02, 0x24, 0x25, 0x28, 0x8A, 0xE1, 0x29,
  38281. 0x9A, 0x79, 0xBD, 0xC7, 0x73, 0x2D, 0xF3, 0x42,
  38282. 0x70, 0x33, 0xF3, 0xF8, 0x48, 0x87, 0xB4, 0xD4,
  38283. 0x91, 0xE1, 0x53, 0xBA, 0x4A, 0x63, 0xAF, 0x3A,
  38284. 0xE5, 0xCB, 0x3D, 0x41, 0x04, 0xB5, 0x30, 0x87,
  38285. 0xAA, 0x40, 0x03, 0x56, 0x10, 0x02, 0xF3, 0x6A,
  38286. 0x9F, 0xDA, 0x33, 0xBC, 0xB8, 0xA5, 0xD0, 0x56,
  38287. 0x43, 0x29, 0xDA, 0x58, 0x12, 0x8B, 0x6A, 0x9D,
  38288. 0xCF, 0xCD, 0xCA, 0x66, 0x98, 0x92, 0x1D, 0xA4,
  38289. 0xEF, 0xAC, 0x9E, 0x19, 0xDE, 0xF7, 0xFE, 0x6C,
  38290. 0x3A, 0x66, 0x46, 0xB4, 0x00, 0x7F, 0x08, 0xAF,
  38291. 0x31, 0xD6, 0xD3, 0x22, 0x59, 0x1F, 0x34, 0x48,
  38292. 0x5A, 0xE1, 0x4E, 0x0F, 0x6F, 0x2D, 0xD0, 0xE5,
  38293. 0x8E, 0x34, 0x3B, 0xC0, 0x55, 0x02, 0x2D, 0x17,
  38294. 0x4B, 0x34, 0x78, 0x46, 0xD4, 0xC4, 0x7F, 0x1D,
  38295. 0xDC, 0x39, 0x94, 0x69, 0x78, 0xAB, 0xD8, 0x2B,
  38296. 0x6D, 0xF3, 0x1C, 0x0B, 0x0F, 0x4A, 0xA0, 0xB2,
  38297. 0xAC, 0x1A, 0x79, 0x7F, 0x9D, 0xE5, 0xE8, 0xC6,
  38298. 0x40, 0x4B, 0xCE, 0x32, 0x4B, 0xA1, 0x3C, 0x77,
  38299. 0xED, 0x5D, 0x59, 0x0F, 0xE0, 0x7D, 0x00, 0x07,
  38300. 0xB4, 0xD8, 0xA6, 0x3E, 0xC9, 0x6D, 0x62, 0x19,
  38301. 0x66, 0xC3, 0xE7, 0x10, 0x3B, 0x6C, 0x7A, 0x36,
  38302. 0x49, 0x75, 0xE6, 0x78, 0xB3, 0x8D, 0x04, 0x13,
  38303. 0x31, 0xE6, 0x79, 0x72, 0x64, 0x07, 0x76, 0x94,
  38304. 0x2B, 0xB4, 0xEC, 0x18, 0x1C, 0x32, 0x3C, 0x26,
  38305. 0xC4, 0x81, 0xBF, 0x4F, 0xB5, 0x6E, 0x5D, 0x67,
  38306. 0xCF, 0xBE, 0x17, 0x57, 0x11, 0x2B, 0xBC, 0xA0,
  38307. 0xF0, 0xC2, 0x70, 0x06, 0x94, 0x26, 0x9B, 0x26,
  38308. 0x12, 0x9C, 0x7F, 0x99, 0xD4, 0x4A, 0xF5, 0x60,
  38309. 0xCD, 0xF7, 0xA4, 0x70, 0x2E, 0xF5, 0xD6, 0xA2,
  38310. 0xEC, 0x0E, 0x99, 0x00, 0x2E, 0x89, 0x30, 0xAA,
  38311. 0x4E, 0xC0, 0x62, 0x11, 0x93, 0x0A, 0x1E, 0x68,
  38312. 0xF2, 0xED, 0x44, 0x8B, 0x10, 0x4A, 0x75, 0x68,
  38313. 0xBF, 0x46, 0xE1, 0x41, 0xD6, 0x0B, 0x61, 0x53,
  38314. 0xD4, 0x03, 0x10, 0xB3, 0x8F, 0x8E, 0x14, 0x57,
  38315. 0x27, 0x8F, 0xE3, 0x49, 0xB2, 0xB4, 0xA7, 0xAE,
  38316. 0x39, 0x7A, 0x7B, 0x8F, 0x48, 0xAA, 0xA5, 0xFD,
  38317. 0xC1, 0x28, 0x8E, 0x43, 0xE0, 0x58, 0x39, 0x32,
  38318. 0x0A, 0x14, 0xC6, 0x3A, 0xB8, 0x58, 0xE2, 0x6E,
  38319. 0x7D, 0x8C, 0x35, 0xB6, 0x47, 0x37, 0x90, 0x4D,
  38320. 0x89, 0xC1, 0x9A, 0x10, 0x3D, 0x6B, 0x68, 0x9A,
  38321. 0x3D, 0xC9, 0x0C, 0x72, 0xFC, 0x92, 0xE3, 0x5D,
  38322. 0x45, 0x2B, 0x81, 0x43, 0x02, 0x30, 0x70, 0xD4,
  38323. 0x8B, 0xB9, 0xFB, 0xB0, 0x45, 0xE3, 0xC6, 0xCE,
  38324. 0x9A, 0x8B, 0xD5, 0xC4, 0xB6, 0x7F, 0x5D, 0x8B,
  38325. 0x58, 0xC9, 0x6A, 0x28, 0x2D, 0x6E, 0x27, 0x78,
  38326. 0x3D, 0x7B, 0x99, 0x0E, 0x05, 0x2B, 0xD9, 0x5E,
  38327. 0x86, 0x50, 0x8F, 0x9B, 0xF7, 0xC0, 0x64, 0xA8,
  38328. 0xF2, 0x39, 0xE0, 0x24, 0x0A, 0x20, 0xD8, 0xDF,
  38329. 0x3A, 0x87, 0x6E, 0xDC, 0x8F, 0xF6, 0x24, 0x1B,
  38330. 0x54, 0xF2, 0x70, 0xA9, 0x8C, 0xB8, 0x07, 0x7A,
  38331. 0xAF, 0xE0, 0xE5, 0x8E, 0x5E, 0x98, 0x13, 0xC6,
  38332. 0xA5, 0xF9, 0x1F, 0x52, 0x89, 0x7B, 0x6A, 0xAD,
  38333. 0x24, 0x26, 0xC6, 0x0D, 0xA5, 0x88, 0x3E, 0x6B,
  38334. 0xDF, 0xEE, 0x33, 0x0A, 0x86, 0x09, 0xA2, 0x11,
  38335. 0x8B, 0x69, 0x9F, 0x75, 0xCE, 0xFD, 0x05, 0x01,
  38336. 0x95, 0x14, 0x64, 0xCD, 0x62, 0x04, 0x09, 0x87,
  38337. 0xFC, 0xF6, 0xB2, 0x2E, 0xCA, 0x92, 0xE4, 0x4F,
  38338. 0x55, 0xB3, 0x8C, 0x64, 0x99, 0xA8, 0xDA, 0x0A,
  38339. 0xC7, 0x82, 0x56, 0x93, 0x03, 0x67, 0xA4, 0xD7,
  38340. 0x54, 0x91, 0xA0, 0x89, 0xD8, 0x94, 0x1F, 0x6C,
  38341. 0x53, 0xCC, 0xB2, 0x60, 0x13, 0x6A, 0x93, 0xE1,
  38342. 0xFC, 0xA3, 0xDD, 0x72, 0xD5, 0x5A, 0x92, 0x35,
  38343. 0x9E, 0x3D, 0x62, 0x82, 0x70, 0x5D, 0x54, 0xAF,
  38344. 0x57, 0xC6, 0x98, 0x5E, 0x74, 0xE0, 0xF2, 0x33,
  38345. 0x26, 0x61, 0xBF, 0x2B, 0xDD, 0x78, 0x47, 0x29,
  38346. 0x04, 0xC7, 0xF0, 0x58, 0x17, 0xFC, 0x9D, 0xED,
  38347. 0xEF, 0x15, 0x6A, 0xCA, 0xC7, 0x46, 0xCE, 0x12,
  38348. 0xF8, 0x90, 0xD8, 0x5A, 0x93, 0x98, 0xA9, 0xED,
  38349. 0xFB, 0xF4, 0x6E, 0x73, 0x48, 0x81, 0x4A, 0x08,
  38350. 0x07, 0x29, 0xC8, 0x3E, 0x70, 0x4C, 0x40, 0x30,
  38351. 0x20, 0x2C, 0xF6, 0x1E, 0xCD, 0xEE, 0x27, 0x95,
  38352. 0xD5, 0x07, 0xAC, 0x28, 0x81, 0x4F, 0x53, 0xCD,
  38353. 0x06, 0x60, 0xA5, 0x57, 0x2C, 0xBE, 0x1A, 0xE5,
  38354. 0x33, 0x38, 0xB8, 0xEF, 0xDC, 0xA3, 0x1A, 0xA5,
  38355. 0xB9, 0x5A, 0xA9, 0xE7, 0x65, 0xAF, 0x4D, 0xA0,
  38356. 0x4C, 0x9B, 0x31, 0x62, 0x67, 0x7E, 0x41, 0xC0,
  38357. 0x18, 0xA5, 0xE1, 0x8A, 0xF2, 0xF9, 0x8A, 0xCA,
  38358. 0x14, 0x5C, 0xCD, 0x1B, 0x8F, 0x74, 0x31, 0x07,
  38359. 0x6A, 0x14, 0xA7, 0xC2, 0x0F, 0x6C, 0x72, 0xE8,
  38360. 0xEB, 0x97, 0x51, 0xB7, 0x89, 0x2E, 0x41, 0x01,
  38361. 0x54, 0x47, 0x63, 0x0E, 0xAA, 0x84, 0xB9, 0x60,
  38362. 0x1C, 0xB9, 0x54, 0xD8, 0x97, 0x39, 0x38, 0x9D,
  38363. 0x52, 0xBB, 0x91, 0xA9, 0x7F, 0x96, 0x08, 0x7C,
  38364. 0xB3, 0x8B, 0x0E, 0xAB, 0x59, 0xA7, 0x84, 0x68,
  38365. 0x34, 0x65, 0x55, 0xC7, 0x12, 0x84, 0xC2, 0xFB,
  38366. 0xBD, 0x27, 0x58, 0x18, 0xE9, 0x26, 0x73, 0xFA,
  38367. 0x42, 0xAB, 0x5E, 0x0D, 0x97, 0x76, 0x67, 0xA9,
  38368. 0x0F, 0x75, 0x92, 0x6C, 0x80, 0x76, 0x87, 0x75,
  38369. 0xD2, 0x3D, 0xFE, 0x0B, 0x33, 0x7B, 0x48, 0xB0,
  38370. 0xC8, 0x28, 0x1F, 0xE6, 0x3F, 0x18, 0xF2, 0x45,
  38371. 0xF8, 0x8F, 0x21, 0xE1, 0x1C, 0x56, 0xA5, 0x33,
  38372. 0x71, 0x88, 0x42, 0x5A, 0x34, 0x8B, 0x24, 0xDD,
  38373. 0x0E, 0x98, 0x30, 0xDB, 0x6B, 0x6C, 0x89, 0x64,
  38374. 0x8C, 0x7A, 0x63, 0x3C, 0xA9, 0xD8, 0x32, 0x51,
  38375. 0xD0, 0xC6, 0xF7, 0xA4, 0x53, 0x95, 0x0D, 0x02,
  38376. 0x19, 0x6A, 0x77, 0xBC, 0xDF, 0xD5, 0x2B, 0x2C,
  38377. 0x65, 0xC9, 0xBF, 0x72, 0x69, 0xC3, 0x0C, 0xEF,
  38378. 0x34, 0x75, 0x76, 0x29, 0x59, 0xBE, 0x9D, 0xE9,
  38379. 0x44, 0x21, 0x2F, 0x5F, 0xB7, 0x89, 0xA6, 0xCD,
  38380. 0x0A, 0x9A, 0x9E, 0x77, 0x5B, 0xBD, 0xDA, 0x03,
  38381. 0xA4, 0xBC, 0xFB, 0x47, 0xC1, 0x77, 0x73, 0x00,
  38382. 0x26, 0xAE, 0x2E, 0xFA, 0x62, 0x18, 0x9D, 0xB8,
  38383. 0xE2, 0xD3, 0x7A, 0xB9, 0xD8, 0xCF, 0xE9, 0x61,
  38384. 0x11, 0x80, 0xE9, 0xDC, 0xC3, 0x32, 0x9E, 0x63,
  38385. 0x6F, 0xD9, 0x42, 0xF6, 0x76, 0x7F, 0xBC, 0xBF,
  38386. 0xDB, 0x08, 0x2F, 0xA0, 0xEB, 0xB8, 0x4D, 0xF3,
  38387. 0x76, 0x62, 0xAA, 0xFA, 0x20, 0x4A, 0xDD, 0xE6,
  38388. 0xB3, 0x72, 0xC7, 0x7D, 0x36, 0x4F, 0x08, 0x56,
  38389. 0x4F, 0x19, 0xB2, 0xB0, 0x0C, 0x13, 0x1A, 0x8C,
  38390. 0xCE, 0x9A, 0x04, 0xB5, 0xB6, 0x9C, 0xD3, 0xD8,
  38391. 0xFE, 0x1F, 0x2C, 0xCC, 0x89, 0xEE, 0x7D, 0x22,
  38392. 0x8A, 0x4E, 0x0A, 0x91, 0x0C, 0x8B, 0x5A, 0xE0,
  38393. 0xBD, 0xE5, 0x3D, 0xBE, 0x90, 0x4B, 0x13, 0xA3,
  38394. 0x2F, 0x33, 0xE9, 0x9D, 0x6C, 0x67, 0x35, 0xBD,
  38395. 0x03, 0xD4, 0x09, 0x90, 0x2F, 0xC6, 0x3C, 0x8D,
  38396. 0xD8, 0x43, 0xFC, 0x1F, 0xB7, 0x49, 0xC0, 0xB7,
  38397. 0x38, 0x70, 0x1D, 0xEB, 0x5A, 0xD7, 0xAC, 0x07,
  38398. 0xAF, 0x5B, 0x93, 0xC5, 0x7B, 0x55, 0x65, 0x86,
  38399. 0x6E, 0xC1, 0xDB, 0xCD, 0x42, 0x92, 0x50, 0xDB,
  38400. 0xD1, 0x97, 0x95, 0x3D, 0x53, 0xC3, 0xFE, 0xC2,
  38401. 0xF9, 0x65, 0xF3, 0xD2, 0xEE, 0xA4, 0x7E, 0xDE,
  38402. 0xA1, 0x4B, 0x23, 0x7F, 0xA1, 0x0D, 0x25, 0x6E,
  38403. 0x80, 0x4F, 0xE3, 0xB5, 0x0C, 0xBA, 0x1C, 0x2B,
  38404. 0x42, 0x0B, 0x8F, 0xD9, 0xB6, 0x4E, 0x52, 0xD2,
  38405. 0xDB, 0x35, 0xD2, 0xA1, 0xC4, 0xE6, 0xD6, 0x51,
  38406. 0x76, 0xE7, 0x87, 0x5E, 0xBE, 0x93, 0xE6, 0x61,
  38407. 0x71, 0x4C, 0x8B, 0xA6, 0x96, 0xDA, 0xF7, 0xCB,
  38408. 0x06, 0xB7, 0xB8, 0xC4, 0xF6, 0xF5, 0xC6, 0x29,
  38409. 0xAA, 0xE1, 0x13, 0x87, 0x6F, 0x96, 0xBA, 0x0C,
  38410. 0xF6, 0x79, 0x8F, 0x03, 0x86, 0x22, 0xE3, 0xFB,
  38411. 0xCF, 0x86, 0xCF, 0x7C, 0x77, 0xFD, 0xB4, 0xEE,
  38412. 0xBD, 0x42, 0x38, 0x7F, 0xF2, 0xCC, 0xCB, 0x06,
  38413. 0xEA, 0x0D, 0x81, 0xA1, 0x8E, 0xB5, 0xE7, 0x40,
  38414. 0xC8, 0x03, 0xA3, 0x4B, 0xC8, 0xB4, 0x0E, 0x3E,
  38415. 0x36, 0xAB, 0x90, 0xC1, 0xFC, 0xB0, 0x37, 0x2B,
  38416. 0x83, 0xA1, 0x3D, 0x56, 0xD6, 0x83, 0x0F, 0x99,
  38417. 0xC4, 0x58, 0xB8, 0x94, 0x61, 0x19, 0xA6, 0x60,
  38418. 0x47, 0xCB, 0x2D, 0xAF, 0x29, 0x38, 0x90, 0xFA,
  38419. 0x99, 0x0F, 0x02, 0x02, 0x65, 0x90, 0x5F, 0xA2,
  38420. 0xA2, 0xE3, 0xBB, 0x34, 0x15, 0x2F, 0x0B, 0xF5,
  38421. 0xB2, 0xCC, 0x83, 0x59, 0xAF, 0xA7, 0x4D, 0x38,
  38422. 0xAD, 0xF6, 0x52, 0x5C, 0x53, 0xD9, 0x0E, 0x3F,
  38423. 0xD6, 0x53, 0x86, 0xE2, 0x79, 0xC2, 0x65, 0x48,
  38424. 0xB2, 0x67, 0x3B, 0xAF, 0x52, 0x53, 0x57, 0x9A,
  38425. 0x27, 0x80, 0x88, 0x37, 0x77, 0x67, 0x4E, 0x1F,
  38426. 0xF1, 0x7B, 0xC5, 0xCB, 0xD8, 0x11, 0x0A, 0xDD,
  38427. 0x92, 0x0E, 0x88, 0x6C, 0xCA, 0x33, 0x76, 0x3B,
  38428. 0x04, 0xFA, 0xC0, 0xFD, 0xC6, 0x3F, 0xB4, 0x72,
  38429. 0xC2, 0x2B, 0x6D, 0x5E, 0xB6, 0xA1, 0x4E, 0x5F,
  38430. 0xC0, 0x50, 0x16, 0xEF, 0xFE, 0x6A, 0x42, 0x72,
  38431. 0x65, 0x02, 0xEE, 0x07, 0xC6, 0x19, 0xC6, 0x95,
  38432. 0xDE, 0x3F, 0xD9, 0xC5, 0xC6, 0x0E, 0x70, 0x07,
  38433. 0x6A, 0xC3, 0x36, 0x1B, 0x84, 0x6F, 0xDF, 0x80,
  38434. 0x16, 0x4E, 0x86, 0x90, 0xC8, 0x55, 0x7B, 0xDD,
  38435. 0xC0, 0x86, 0x0C, 0x37, 0x47, 0x1F, 0x35, 0xF8,
  38436. 0x47, 0xF2, 0xCD, 0x96, 0x21, 0x64, 0xAD, 0x46,
  38437. 0xE1, 0xDF, 0x44, 0x79, 0x48, 0x02, 0xF9, 0x71,
  38438. 0x39, 0x35, 0x26, 0xFC, 0x12, 0x0D, 0x88, 0xAC,
  38439. 0xD6, 0xFA, 0x29, 0x74, 0x55, 0x51, 0xE7, 0xAF,
  38440. 0x3D, 0x7E, 0x1E, 0x7E, 0xE0, 0x18, 0xB6, 0x3C,
  38441. 0x4B, 0x99, 0x9D, 0x51, 0x02, 0x51, 0xD8, 0xE9,
  38442. 0xFA, 0x61, 0x88, 0x2E, 0xCF, 0x73, 0x77, 0x65,
  38443. 0x71, 0xAE, 0xAE, 0xD7, 0xA1, 0xF9, 0xE0, 0x7F,
  38444. 0x30, 0x46, 0xCB, 0x20, 0xEC, 0xF4, 0xD2, 0xC1,
  38445. 0x63, 0xF5, 0x6F, 0x8A, 0x72, 0xF9, 0x5B, 0x85,
  38446. 0xD2, 0xCA, 0x6D, 0x35, 0xD1, 0x17, 0xF6, 0x08,
  38447. 0x9E, 0x0A, 0x73, 0xB3, 0xDA, 0x1A, 0x32, 0xBA,
  38448. 0x23, 0x10, 0x4A, 0x5D, 0xD7, 0xAA, 0xB4, 0x68,
  38449. 0x97, 0x59, 0x45, 0xC5, 0x7C, 0x16, 0x6F, 0xE4,
  38450. 0x62, 0x89, 0xF1, 0xD3, 0xB4, 0x03, 0x90, 0x7B,
  38451. 0xA4, 0xA2, 0xCA, 0xA0, 0x5D, 0x69, 0x1B, 0xA9,
  38452. 0xBB, 0xEB, 0xA0, 0xE2, 0xDE, 0xBE, 0x0E, 0xC4,
  38453. 0x9E, 0x21, 0x38, 0x61, 0x92, 0x9B, 0xAB, 0x69,
  38454. 0xAA, 0xD0, 0x1D, 0xF6, 0xC3, 0xEE, 0xA6, 0xC3,
  38455. 0xF3, 0x29, 0x1B, 0xE5, 0x6E, 0x52, 0x89, 0xD0,
  38456. 0xBA, 0xD8, 0x60, 0x27, 0x80, 0x1A, 0xB5, 0x7F,
  38457. 0x7F, 0xB5, 0xC2, 0x5A, 0xC6, 0x83, 0xA4, 0xC0,
  38458. 0x88, 0x39, 0xF3, 0xE7, 0x39, 0xD6, 0x81, 0x1C,
  38459. 0x13, 0x20, 0xFD, 0x93, 0x3D, 0x8E, 0x79, 0x60,
  38460. 0x7C, 0xFF, 0xE4, 0x37, 0x5B, 0x33, 0xA3, 0x9D,
  38461. 0xB7, 0x57, 0xCD, 0x45, 0x0A, 0xB9, 0xE4, 0xF1,
  38462. 0xBC, 0x59, 0x74, 0xE8, 0xB3, 0x06, 0xD0, 0x9F,
  38463. 0x0F, 0xBC, 0x5B, 0x23, 0xB8, 0x6C, 0xD6, 0x4D,
  38464. 0xFA, 0xCC, 0x14, 0xAB, 0x74, 0x61, 0x1A, 0xFC,
  38465. 0x22, 0xA6, 0xED, 0x09, 0x76, 0x91, 0xD8, 0x6E,
  38466. 0x44, 0xB6, 0x00, 0x14, 0xDC, 0x74, 0x2D, 0x90,
  38467. 0xAA, 0x59, 0x98, 0x76, 0x30, 0xC5, 0x44, 0xA4,
  38468. 0x61, 0x43, 0xD6, 0xE2, 0x28, 0x28, 0xA7, 0xBD,
  38469. 0x6E, 0x50, 0x5C, 0xE1, 0x96, 0x7A, 0xF8, 0xA8,
  38470. 0x32, 0x8C, 0xE9, 0xFD, 0x11, 0x37, 0x91, 0xD1,
  38471. 0xAF, 0x3C, 0xD3, 0x1C, 0x1E, 0x88, 0x4D, 0x7E,
  38472. 0x87, 0x84, 0x84, 0x6F, 0x39, 0x0B, 0xFB, 0x2D,
  38473. 0xB3, 0x12, 0x4C, 0x6D, 0x45, 0xDD, 0xCD, 0x7D,
  38474. 0x75, 0xB7, 0xFE, 0x7E, 0x44, 0xCC, 0x29, 0xE5,
  38475. 0xB3, 0x10, 0xEE, 0x23, 0x55, 0x5B, 0xCF, 0xBA,
  38476. 0xBD, 0xA1, 0xBE, 0x64, 0xF8, 0x6E, 0x60, 0x31,
  38477. 0x0A, 0x2D, 0xC9, 0x3B, 0x1D, 0x44, 0xE1, 0x9D,
  38478. 0x60, 0x28, 0x77, 0xEE
  38479. };
  38480. static const byte rnd_65[] = {
  38481. 0x4E, 0x7A, 0x01, 0x7C, 0x15, 0x03, 0x9D, 0xC2,
  38482. 0x00, 0x51, 0xD2, 0x96, 0x0E, 0x5E, 0x15, 0x59,
  38483. 0xCC, 0x27, 0xED, 0x46, 0x87, 0x7C, 0xB9, 0x81,
  38484. 0x16, 0x19, 0x9A, 0x0F, 0x41, 0x05, 0xFE, 0x32
  38485. };
  38486. static const byte sig_65[] = {
  38487. 0xB8, 0x65, 0xB0, 0x0B, 0x21, 0x18, 0xDB, 0xB0,
  38488. 0x0B, 0x70, 0x1C, 0x66, 0x45, 0x65, 0x5E, 0x8A,
  38489. 0xCF, 0xA8, 0x4E, 0xA7, 0x92, 0xB4, 0x48, 0x64,
  38490. 0x2E, 0x18, 0x32, 0xC3, 0x70, 0x7C, 0x87, 0xCF,
  38491. 0x09, 0xFB, 0xE7, 0x72, 0xF1, 0xD4, 0x38, 0x5B,
  38492. 0xFB, 0xE5, 0xE6, 0xCF, 0xBB, 0xE2, 0x6C, 0x10,
  38493. 0xED, 0x6E, 0xB8, 0x65, 0xC8, 0x87, 0xF8, 0x69,
  38494. 0x39, 0x43, 0x9A, 0x9B, 0xF7, 0x68, 0xBF, 0x03,
  38495. 0x9D, 0x73, 0xE3, 0xEA, 0x83, 0xBD, 0xF1, 0x85,
  38496. 0x03, 0xB5, 0xD1, 0xB3, 0x91, 0x79, 0xA8, 0x27,
  38497. 0xB0, 0xD7, 0x80, 0x5F, 0x98, 0x42, 0x8B, 0xD8,
  38498. 0x7C, 0xEA, 0x6B, 0x06, 0x96, 0x0C, 0x78, 0xB4,
  38499. 0xB5, 0x86, 0xFB, 0x0D, 0x5E, 0xDA, 0x9F, 0xAA,
  38500. 0xC0, 0x25, 0x6E, 0x38, 0x82, 0x35, 0x62, 0xA3,
  38501. 0x07, 0x96, 0x61, 0x17, 0x00, 0x5A, 0xA4, 0x2F,
  38502. 0x1B, 0x65, 0x54, 0xA0, 0x48, 0x75, 0xF8, 0x5C,
  38503. 0x2E, 0x3F, 0xAF, 0xA6, 0x52, 0x47, 0x1D, 0x4E,
  38504. 0x98, 0x06, 0x54, 0x82, 0xFC, 0x7D, 0xF4, 0x9B,
  38505. 0x2C, 0x40, 0xD0, 0xE7, 0xB9, 0x82, 0x38, 0xDF,
  38506. 0xBE, 0x85, 0x3D, 0x16, 0xBF, 0x99, 0x92, 0xBB,
  38507. 0x08, 0xC1, 0x92, 0x59, 0xF9, 0xB5, 0x75, 0xEA,
  38508. 0x7A, 0x4A, 0x80, 0x09, 0x3A, 0x64, 0xA9, 0x26,
  38509. 0x71, 0x85, 0x7A, 0x50, 0x89, 0x20, 0xD6, 0x0F,
  38510. 0xF6, 0xFB, 0xF3, 0x83, 0x41, 0xC5, 0x59, 0x01,
  38511. 0x05, 0x63, 0x3A, 0x42, 0x6D, 0x60, 0x2D, 0xAC,
  38512. 0x06, 0x4D, 0xD7, 0xA7, 0xF1, 0x1A, 0x60, 0x21,
  38513. 0x5C, 0x35, 0xB7, 0xB9, 0xC0, 0x0E, 0x9D, 0x84,
  38514. 0x63, 0x98, 0x8C, 0xF4, 0x72, 0xCD, 0x6A, 0xCF,
  38515. 0xB7, 0xF7, 0x22, 0xB8, 0xC4, 0xC6, 0x27, 0x02,
  38516. 0x60, 0x7A, 0x67, 0x48, 0x80, 0xAC, 0xB3, 0xD6,
  38517. 0xC6, 0x25, 0x3E, 0x71, 0x17, 0x5A, 0x05, 0xB3,
  38518. 0x92, 0xCA, 0xB4, 0xBB, 0x14, 0xCE, 0x86, 0xA5,
  38519. 0x98, 0xAB, 0xC7, 0x88, 0xD0, 0xFF, 0x4D, 0x82,
  38520. 0x77, 0x5E, 0x4E, 0xA0, 0xFC, 0x36, 0x36, 0x3C,
  38521. 0xD0, 0xE9, 0x7B, 0x78, 0xA6, 0xAE, 0x4D, 0xA8,
  38522. 0xE9, 0x8C, 0xA6, 0x12, 0x77, 0x2D, 0x56, 0xB5,
  38523. 0x82, 0xF8, 0x2C, 0x07, 0x09, 0xBE, 0xAE, 0x46,
  38524. 0x67, 0x3B, 0xDD, 0x80, 0x42, 0x86, 0x5C, 0xFA,
  38525. 0x95, 0xBF, 0x53, 0x38, 0xCF, 0xEA, 0x60, 0x6A,
  38526. 0x6E, 0xF3, 0x16, 0x38, 0x46, 0xAE, 0x83, 0xB2,
  38527. 0x5E, 0x5F, 0x5B, 0xD3, 0x1C, 0x83, 0xF1, 0x36,
  38528. 0x72, 0x9A, 0x8E, 0xA6, 0x27, 0x4F, 0x99, 0x4F,
  38529. 0xA9, 0x04, 0x5F, 0xA8, 0xA9, 0x0F, 0xF8, 0x54,
  38530. 0xB8, 0x71, 0xCF, 0x82, 0xE2, 0xB7, 0x01, 0xE8,
  38531. 0xF4, 0xAC, 0x04, 0xFE, 0x9E, 0x28, 0x49, 0x1B,
  38532. 0x9A, 0x25, 0xFF, 0x26, 0x3E, 0x2C, 0xF7, 0x54,
  38533. 0x99, 0xE0, 0x09, 0xFD, 0x02, 0x29, 0xFB, 0xF7,
  38534. 0xE5, 0xE4, 0x60, 0x44, 0x34, 0x4B, 0x07, 0xD7,
  38535. 0x22, 0x14, 0xA9, 0xAC, 0xB4, 0xFF, 0x61, 0x02,
  38536. 0xAB, 0xC1, 0x26, 0x2B, 0xC2, 0xE1, 0xCD, 0x24,
  38537. 0x91, 0x60, 0x7A, 0xE7, 0xAA, 0xEC, 0xF4, 0xC3,
  38538. 0x51, 0x75, 0xCF, 0xA4, 0x38, 0x3A, 0xA8, 0x6A,
  38539. 0xF1, 0xE6, 0x2E, 0xD0, 0x63, 0x87, 0xCC, 0x59,
  38540. 0x48, 0x36, 0x46, 0x7F, 0x41, 0xDF, 0xCA, 0x8F,
  38541. 0xA0, 0xCA, 0x71, 0x28, 0x0B, 0xFB, 0x1C, 0x25,
  38542. 0x60, 0xC8, 0x99, 0x55, 0x36, 0xF8, 0x42, 0x74,
  38543. 0x70, 0x45, 0x59, 0x14, 0x53, 0x74, 0x5F, 0x26,
  38544. 0x03, 0x82, 0xE3, 0xDA, 0x50, 0x79, 0x3F, 0xD7,
  38545. 0xCA, 0x76, 0x27, 0x18, 0x5D, 0xBD, 0xCE, 0xDD,
  38546. 0xF6, 0x9B, 0x2D, 0x3E, 0x15, 0x1C, 0x7F, 0x97,
  38547. 0x28, 0x8A, 0x38, 0x2A, 0x92, 0xB0, 0x50, 0xF7,
  38548. 0x91, 0xF9, 0x58, 0x7D, 0x77, 0xC6, 0x4D, 0x8B,
  38549. 0x5D, 0x40, 0xAA, 0x19, 0x9D, 0x49, 0x66, 0xBE,
  38550. 0x2D, 0x52, 0x4F, 0x96, 0x10, 0xF2, 0xFA, 0x02,
  38551. 0xED, 0x23, 0x17, 0x63, 0x69, 0xDB, 0x93, 0x93,
  38552. 0x50, 0xDA, 0x60, 0x1E, 0xA6, 0x67, 0x70, 0x95,
  38553. 0x2E, 0x0F, 0x23, 0xED, 0xA6, 0x8A, 0x73, 0x75,
  38554. 0x6E, 0xFF, 0x61, 0x0E, 0x8D, 0x6A, 0x9F, 0x49,
  38555. 0x34, 0x56, 0x58, 0x54, 0x42, 0x82, 0x45, 0x3B,
  38556. 0x5E, 0x73, 0xA3, 0x22, 0xA0, 0x32, 0x67, 0xC9,
  38557. 0x69, 0xB5, 0x07, 0x34, 0xF2, 0xEC, 0xD4, 0xEC,
  38558. 0x90, 0x55, 0x76, 0x0D, 0x92, 0x86, 0x10, 0xE9,
  38559. 0x4E, 0x0B, 0x16, 0x28, 0xD6, 0xAF, 0x1B, 0x27,
  38560. 0xAB, 0x13, 0x82, 0x9F, 0x7F, 0x8E, 0xF5, 0x0D,
  38561. 0x9E, 0x29, 0x96, 0xFC, 0x64, 0xB0, 0x6A, 0xC8,
  38562. 0x94, 0x61, 0x14, 0x76, 0x6D, 0xAD, 0x8D, 0xFF,
  38563. 0xE6, 0x34, 0xF4, 0x7E, 0x9D, 0x85, 0x69, 0x96,
  38564. 0x6C, 0x6F, 0x69, 0x68, 0x21, 0x8C, 0x5B, 0x86,
  38565. 0x33, 0x61, 0x1B, 0xF4, 0x2B, 0x4F, 0xC0, 0xE7,
  38566. 0x8D, 0x0C, 0x02, 0x9E, 0xAB, 0x85, 0xF2, 0x2F,
  38567. 0x16, 0x17, 0x19, 0x80, 0xCC, 0x65, 0xF2, 0x84,
  38568. 0x45, 0xA1, 0x1A, 0x08, 0x3A, 0xA0, 0x29, 0x77,
  38569. 0xC2, 0xE8, 0x88, 0x6E, 0xD2, 0x70, 0x67, 0x2E,
  38570. 0x51, 0x2A, 0xE8, 0x9C, 0x6A, 0x26, 0xFC, 0xAD,
  38571. 0x1E, 0xC7, 0x2B, 0x9E, 0xCF, 0xA5, 0xA5, 0xEF,
  38572. 0xC7, 0x0F, 0xF0, 0xBA, 0xB2, 0x8F, 0x11, 0x4F,
  38573. 0x4D, 0xA8, 0x17, 0x0F, 0xE8, 0xB6, 0x3C, 0x2E,
  38574. 0x11, 0xBE, 0x7A, 0x35, 0x46, 0x6E, 0x97, 0x9A,
  38575. 0x12, 0x7E, 0xC0, 0xD2, 0x03, 0x23, 0xD5, 0x02,
  38576. 0x73, 0x0A, 0xBC, 0xE6, 0x40, 0xA2, 0x44, 0x1C,
  38577. 0xDD, 0xAB, 0xA3, 0x26, 0xD6, 0x78, 0x3D, 0x01,
  38578. 0x92, 0xDB, 0xA9, 0xE9, 0x3F, 0xE5, 0x07, 0xC6,
  38579. 0xA7, 0x37, 0x67, 0xBE, 0x56, 0xE2, 0x77, 0x65,
  38580. 0x76, 0xEF, 0xEF, 0xF1, 0xCA, 0x17, 0x9D, 0x83,
  38581. 0x34, 0x3E, 0x38, 0xC6, 0xA9, 0xC2, 0xFE, 0x72,
  38582. 0x5D, 0xDE, 0x80, 0x7D, 0x21, 0x72, 0x5E, 0x73,
  38583. 0x08, 0x72, 0xE2, 0xAB, 0x3D, 0x90, 0x11, 0x61,
  38584. 0xF4, 0x55, 0xBC, 0xAD, 0x23, 0xA8, 0x43, 0x3A,
  38585. 0x41, 0x31, 0x51, 0xFD, 0x22, 0x17, 0x14, 0x31,
  38586. 0x0E, 0x4D, 0x0B, 0x6A, 0x1E, 0x1B, 0x2C, 0xAC,
  38587. 0xA4, 0x99, 0xEE, 0xE8, 0x05, 0xA1, 0x64, 0xF2,
  38588. 0x91, 0xD5, 0x07, 0x5E, 0x6B, 0x65, 0xA7, 0x9C,
  38589. 0x2B, 0xCA, 0xD9, 0x17, 0xB1, 0x22, 0xFE, 0x1A,
  38590. 0xC4, 0xFB, 0xB4, 0x10, 0x21, 0x1B, 0xA0, 0xA1,
  38591. 0x99, 0x7A, 0x31, 0x30, 0x7C, 0x01, 0xF0, 0xFE,
  38592. 0xD3, 0xB3, 0x14, 0x3D, 0x28, 0x34, 0x0F, 0xAC,
  38593. 0xF0, 0x93, 0x37, 0xC4, 0xEF, 0x04, 0x74, 0x80,
  38594. 0xA2, 0x90, 0xAE, 0x02, 0xB2, 0xF7, 0xD8, 0x7B,
  38595. 0x8C, 0x29, 0xA0, 0xAE, 0xAE, 0x2E, 0x92, 0xC9,
  38596. 0xC5, 0x44, 0x7D, 0x66, 0xC5, 0x5C, 0x1D, 0x1E,
  38597. 0x25, 0x88, 0x5D, 0x10, 0x37, 0xFB, 0x5F, 0xCC,
  38598. 0x80, 0x15, 0x4F, 0x1D, 0x23, 0xB4, 0xF2, 0x7B,
  38599. 0x5B, 0xAC, 0x89, 0xBE, 0x1C, 0x36, 0x3C, 0xFF,
  38600. 0x8E, 0xA7, 0x58, 0x73, 0xAC, 0x3F, 0x63, 0x33,
  38601. 0xE8, 0x6C, 0x53, 0xEC, 0xA5, 0x5D, 0xBE, 0xD5,
  38602. 0xE1, 0xF1, 0x12, 0x6B, 0x12, 0x78, 0xC7, 0x29,
  38603. 0xC9, 0xA8, 0x4C, 0x4A, 0x1B, 0x7F, 0x15, 0x11,
  38604. 0x93, 0x01, 0xC8, 0x0B, 0xE2, 0x2F, 0xE9, 0xBE,
  38605. 0xBA, 0x17, 0x59, 0x45, 0xB2, 0x61, 0x2B, 0x66,
  38606. 0xDD, 0xCE, 0xDF, 0x9A, 0x2A, 0x4D, 0x5F, 0x24,
  38607. 0xF9, 0x02, 0xBB, 0xA6, 0x8D, 0xA7, 0x5D, 0x95,
  38608. 0x97, 0x2E, 0x28, 0xD6, 0xCB, 0x70, 0x17, 0xCA,
  38609. 0x51, 0xED, 0x58, 0x73, 0xAB, 0x03, 0xDD, 0x2E,
  38610. 0x92, 0x6C, 0x15, 0x64, 0x2C, 0x9D, 0x6E, 0x64,
  38611. 0x27, 0xFC, 0xE8, 0x0F, 0xC3, 0x8B, 0x34, 0xFE,
  38612. 0xB3, 0xC1, 0x55, 0x13, 0xA6, 0x87, 0xC3, 0x5B,
  38613. 0x94, 0xEB, 0x83, 0xE4, 0xAB, 0x3E, 0x18, 0x76,
  38614. 0x67, 0x92, 0x70, 0xF5, 0xA9, 0x8F, 0x18, 0xA6,
  38615. 0x5F, 0x57, 0x41, 0x76, 0x55, 0xFD, 0xA9, 0x99,
  38616. 0x4E, 0x8F, 0xCC, 0x61, 0x6C, 0x6C, 0x60, 0x06,
  38617. 0x10, 0x40, 0x26, 0xD6, 0xCD, 0x7A, 0xA0, 0x56,
  38618. 0x3D, 0x51, 0x07, 0x25, 0x76, 0x00, 0x05, 0xF5,
  38619. 0xFD, 0x39, 0xE7, 0x59, 0x24, 0x90, 0x29, 0xF0,
  38620. 0x3D, 0x9F, 0x00, 0x67, 0x10, 0x3F, 0xA0, 0x45,
  38621. 0x21, 0x14, 0xDF, 0x24, 0x40, 0xE8, 0xC6, 0xDB,
  38622. 0x65, 0xE2, 0x39, 0x56, 0xEB, 0x1B, 0xEE, 0xB2,
  38623. 0xC3, 0x4E, 0x5B, 0x20, 0xAC, 0x31, 0x6A, 0x03,
  38624. 0xA9, 0x54, 0x36, 0x66, 0x62, 0x68, 0xC3, 0xD8,
  38625. 0x22, 0x8F, 0x62, 0xEB, 0x56, 0x67, 0xB3, 0xB6,
  38626. 0xBB, 0x85, 0x7D, 0xD0, 0x73, 0x7B, 0x69, 0x05,
  38627. 0x1E, 0x9F, 0x26, 0xEE, 0x02, 0x36, 0x71, 0xCE,
  38628. 0xAD, 0xFA, 0xCA, 0xF9, 0x49, 0x7F, 0x1A, 0xDE,
  38629. 0x58, 0x7A, 0x69, 0x3E, 0xEF, 0xFB, 0xFC, 0xD5,
  38630. 0x50, 0xEC, 0x20, 0x8C, 0x23, 0x56, 0x91, 0xE8,
  38631. 0xE3, 0x66, 0xD9, 0x65, 0xB6, 0x2B, 0xEC, 0x16,
  38632. 0xA6, 0x61, 0xCD, 0x5D, 0xE2, 0x87, 0x93, 0x22,
  38633. 0x0D, 0x66, 0xF2, 0x64, 0x55, 0x05, 0xB8, 0x52,
  38634. 0x41, 0x2F, 0xAE, 0x7B, 0x9D, 0x98, 0x29, 0xBF,
  38635. 0x61, 0x5F, 0x7C, 0xBD, 0x59, 0xA7, 0xBC, 0x1D,
  38636. 0x03, 0x4E, 0x6A, 0x25, 0x52, 0x9C, 0xFB, 0x48,
  38637. 0x6A, 0xF2, 0x01, 0xDE, 0xB7, 0xEA, 0x95, 0xBA,
  38638. 0x70, 0x8A, 0x31, 0x59, 0x17, 0x16, 0x74, 0x34,
  38639. 0x53, 0x09, 0xDB, 0x81, 0x50, 0xE6, 0x7E, 0xBB,
  38640. 0x30, 0xA7, 0xFF, 0x80, 0xCA, 0xC9, 0xAB, 0x13,
  38641. 0x92, 0x50, 0x0A, 0x83, 0xE6, 0x3B, 0xBF, 0x7C,
  38642. 0x42, 0xEB, 0x94, 0x53, 0xC2, 0xC9, 0xAC, 0xDA,
  38643. 0x02, 0xBE, 0x53, 0x82, 0x34, 0xAA, 0xA7, 0xDB,
  38644. 0x5A, 0x7F, 0x58, 0x8F, 0xC9, 0x1B, 0x90, 0xEE,
  38645. 0x24, 0x77, 0xF2, 0xB6, 0x1C, 0xD1, 0x06, 0x2A,
  38646. 0x7E, 0xF1, 0xE6, 0xE4, 0xDC, 0x54, 0xB3, 0x6D,
  38647. 0x0E, 0x19, 0x93, 0x3E, 0x98, 0x1C, 0xB7, 0x63,
  38648. 0xA9, 0xE1, 0x07, 0xE0, 0x1D, 0xA9, 0x42, 0x0F,
  38649. 0x82, 0xCA, 0x79, 0x35, 0x92, 0xA4, 0x7C, 0x4B,
  38650. 0x97, 0x7F, 0xF2, 0xC8, 0x84, 0x98, 0xDA, 0x95,
  38651. 0xC4, 0x3D, 0x23, 0x2F, 0x42, 0xAF, 0x99, 0x48,
  38652. 0x0B, 0xF0, 0xA4, 0xF8, 0xB7, 0xC4, 0x94, 0x9D,
  38653. 0x1A, 0xE1, 0xD4, 0xFA, 0x8E, 0x1D, 0x1A, 0x8C,
  38654. 0xD0, 0xF9, 0xED, 0x00, 0xDA, 0x59, 0x5E, 0xFD,
  38655. 0x2B, 0x76, 0x6F, 0x0B, 0x79, 0xD4, 0x49, 0x0D,
  38656. 0xB9, 0x28, 0xEC, 0x44, 0xB5, 0x03, 0x0A, 0x74,
  38657. 0xCA, 0x42, 0x81, 0x1A, 0x5B, 0x5A, 0xE5, 0x22,
  38658. 0xC7, 0x76, 0x4D, 0xDF, 0xD9, 0xFD, 0x92, 0xF0,
  38659. 0x06, 0xE9, 0x4B, 0x35, 0xA7, 0xEF, 0x01, 0x42,
  38660. 0xDA, 0x71, 0x78, 0xC2, 0xF5, 0x30, 0x74, 0xD0,
  38661. 0x74, 0x51, 0xB1, 0x55, 0x65, 0xA9, 0xE0, 0xC5,
  38662. 0x7E, 0xA1, 0xB9, 0x4C, 0x88, 0xEA, 0xE7, 0x41,
  38663. 0xB1, 0xF5, 0x01, 0xC4, 0xD3, 0x70, 0x72, 0x7D,
  38664. 0xAD, 0x27, 0x65, 0xF7, 0x95, 0xAD, 0x41, 0x46,
  38665. 0x35, 0x80, 0x0E, 0xC1, 0x94, 0x9D, 0x03, 0x71,
  38666. 0x39, 0xDE, 0x26, 0xAF, 0xCF, 0x93, 0x3D, 0x9A,
  38667. 0x09, 0xC1, 0x27, 0xFC, 0x6B, 0x36, 0xE5, 0x18,
  38668. 0xC6, 0xDE, 0x94, 0x92, 0xBA, 0x70, 0x82, 0x7B,
  38669. 0x68, 0x1C, 0x2D, 0x18, 0xA4, 0x01, 0x23, 0xB6,
  38670. 0xC5, 0xF6, 0x17, 0x37, 0xCB, 0x9D, 0xC6, 0xAA,
  38671. 0x9C, 0xE1, 0x7D, 0x16, 0x8E, 0xBB, 0xDD, 0xD6,
  38672. 0x3C, 0x07, 0x60, 0x19, 0x3C, 0x97, 0x49, 0x33,
  38673. 0xDB, 0x47, 0x4A, 0xA8, 0x9A, 0xF3, 0x0E, 0x16,
  38674. 0x29, 0x38, 0xF6, 0xDB, 0x78, 0x65, 0xDE, 0x23,
  38675. 0x1F, 0x86, 0x16, 0x9C, 0x9E, 0x2A, 0x30, 0x2F,
  38676. 0xC4, 0x1F, 0x1B, 0xE5, 0xF3, 0x6C, 0x55, 0x83,
  38677. 0xFC, 0xD9, 0x1E, 0x21, 0xCB, 0x8A, 0x67, 0x57,
  38678. 0xD3, 0x0A, 0x4B, 0xAC, 0xDB, 0x67, 0xE7, 0xA6,
  38679. 0x1B, 0x0C, 0x8E, 0x21, 0x7E, 0x0C, 0xCB, 0xF5,
  38680. 0x0E, 0xA6, 0x42, 0xCD, 0xE3, 0xFC, 0x74, 0xC7,
  38681. 0xF9, 0xFF, 0xBD, 0xA9, 0xA1, 0xE6, 0x84, 0xBB,
  38682. 0xC9, 0xA8, 0xF7, 0xCD, 0x3F, 0x1B, 0xD0, 0xDB,
  38683. 0x63, 0xDD, 0xDF, 0x4E, 0xA4, 0x79, 0xC2, 0x35,
  38684. 0x65, 0x2C, 0x5D, 0xCB, 0xCA, 0x7B, 0xDD, 0x4E,
  38685. 0x2F, 0x33, 0xE8, 0x71, 0x72, 0xC1, 0x8B, 0x5F,
  38686. 0xF3, 0x90, 0x99, 0x40, 0x8D, 0x27, 0x2F, 0xD0,
  38687. 0xFB, 0x0D, 0x6A, 0x23, 0xB1, 0x43, 0x00, 0xDF,
  38688. 0xC6, 0x4C, 0x02, 0x74, 0x3E, 0x52, 0x36, 0x08,
  38689. 0xE9, 0x73, 0x61, 0x3D, 0xCA, 0xAC, 0x9D, 0x1D,
  38690. 0x14, 0xB3, 0xA6, 0x24, 0x0E, 0xC2, 0xF2, 0x29,
  38691. 0x39, 0x91, 0xF6, 0x90, 0x6A, 0xE3, 0x6C, 0x04,
  38692. 0x69, 0xF3, 0x09, 0x11, 0x34, 0x8E, 0xC1, 0x2D,
  38693. 0xDB, 0xA6, 0xC3, 0xCA, 0x19, 0xBC, 0x69, 0x5F,
  38694. 0xCD, 0x16, 0xE5, 0xAE, 0xF2, 0xAD, 0x7C, 0x73,
  38695. 0x25, 0x15, 0x70, 0xB5, 0xD0, 0x49, 0xA6, 0xC3,
  38696. 0xA5, 0x2F, 0xA3, 0xFC, 0x9E, 0xD5, 0x4E, 0x54,
  38697. 0x97, 0x3A, 0xE7, 0x89, 0xB0, 0xBF, 0xD6, 0xF8,
  38698. 0xCC, 0x26, 0x44, 0xA9, 0xF8, 0x5A, 0xCE, 0x06,
  38699. 0x78, 0xD8, 0x9E, 0xFC, 0x12, 0xB6, 0x11, 0xC3,
  38700. 0xDF, 0xAE, 0x3F, 0x94, 0x50, 0x34, 0xB8, 0x99,
  38701. 0xBE, 0x99, 0xA7, 0x32, 0x88, 0x9F, 0x17, 0xD2,
  38702. 0x08, 0xDC, 0xD7, 0xEE, 0x95, 0x9D, 0x1A, 0xC7,
  38703. 0x61, 0xDB, 0xA4, 0x86, 0x4C, 0x14, 0xB0, 0xA3,
  38704. 0x5E, 0x4C, 0x7B, 0xBD, 0xA0, 0x96, 0xFB, 0x8A,
  38705. 0xB3, 0x22, 0x69, 0x26, 0xC8, 0x9E, 0x7C, 0xDA,
  38706. 0x92, 0x9E, 0xF1, 0x30, 0xC6, 0x92, 0xC9, 0x26,
  38707. 0x59, 0xE6, 0xF4, 0x65, 0x2B, 0xF2, 0x15, 0x63,
  38708. 0x61, 0xC7, 0x7D, 0xBE, 0xEF, 0x5A, 0x06, 0x23,
  38709. 0xA0, 0x67, 0x04, 0x99, 0x0E, 0x19, 0x8A, 0x13,
  38710. 0x67, 0x30, 0x54, 0x32, 0x4B, 0xBB, 0xAA, 0x64,
  38711. 0x36, 0x92, 0xF2, 0x43, 0xD6, 0x7C, 0x1B, 0x4F,
  38712. 0x95, 0xB9, 0x28, 0xAC, 0xF1, 0x68, 0x6F, 0x60,
  38713. 0xC1, 0x44, 0x87, 0xD6, 0xDD, 0x7F, 0x88, 0x01,
  38714. 0xEF, 0x20, 0x93, 0x9E, 0x03, 0xA1, 0xCA, 0x7D,
  38715. 0x74, 0x32, 0xDC, 0xF5, 0x95, 0xF1, 0xE9, 0xED,
  38716. 0xF2, 0xB2, 0x93, 0x57, 0xA1, 0xD4, 0xC7, 0xDA,
  38717. 0x33, 0x51, 0x2C, 0x45, 0x1A, 0x7C, 0x66, 0x04,
  38718. 0x38, 0x2D, 0x90, 0xC3, 0x30, 0x79, 0xD9, 0x57,
  38719. 0x38, 0xE4, 0x71, 0x89, 0xD8, 0x54, 0x9E, 0x43,
  38720. 0xD2, 0x94, 0xE7, 0x3D, 0x1C, 0xA7, 0x48, 0x7B,
  38721. 0x50, 0xD0, 0xED, 0x7C, 0xC6, 0xF9, 0x6B, 0xEE,
  38722. 0xA7, 0x6C, 0xCE, 0xB9, 0x6D, 0x37, 0x92, 0x00,
  38723. 0x4E, 0xB3, 0xE5, 0x49, 0x16, 0x35, 0xA6, 0x7F,
  38724. 0x6F, 0xFA, 0x1F, 0x1D, 0xF6, 0xA1, 0xF2, 0xFD,
  38725. 0xEE, 0x77, 0x84, 0x17, 0x80, 0xAE, 0x08, 0x09,
  38726. 0xD2, 0x92, 0xED, 0x7B, 0x00, 0xF4, 0x2D, 0x80,
  38727. 0x91, 0x19, 0x09, 0xB5, 0x1C, 0x9A, 0x3A, 0xE5,
  38728. 0x4B, 0x7A, 0x6D, 0x7D, 0x29, 0xD2, 0x00, 0x05,
  38729. 0x22, 0xD4, 0xF8, 0x76, 0xE2, 0x5C, 0x0D, 0x6A,
  38730. 0x15, 0x77, 0x22, 0x18, 0x85, 0xFD, 0x30, 0x74,
  38731. 0xF3, 0x3B, 0xDC, 0xD9, 0x6C, 0xDE, 0x80, 0x40,
  38732. 0x4A, 0x37, 0xE1, 0x60, 0x9F, 0x26, 0xCF, 0xBE,
  38733. 0x24, 0xA1, 0xFB, 0xF9, 0x76, 0x2A, 0x1A, 0x23,
  38734. 0x32, 0xE7, 0xA2, 0xD8, 0x2D, 0xF9, 0xD2, 0x0F,
  38735. 0x08, 0x3A, 0xDB, 0x35, 0x35, 0x33, 0x59, 0x0B,
  38736. 0xB1, 0xF9, 0x54, 0x33, 0x49, 0x36, 0x9E, 0x21,
  38737. 0xEC, 0xF5, 0x94, 0xE2, 0x78, 0x07, 0xA5, 0x63,
  38738. 0x50, 0xD6, 0x23, 0x84, 0xDE, 0xAD, 0xA7, 0x89,
  38739. 0xBE, 0x92, 0xF0, 0x12, 0xC1, 0xF8, 0xA7, 0x2D,
  38740. 0x8B, 0xE0, 0x79, 0xF8, 0xD7, 0xBD, 0x04, 0x0B,
  38741. 0xC5, 0xF2, 0x23, 0x36, 0x11, 0x6D, 0x6F, 0x37,
  38742. 0xDB, 0xFB, 0xD2, 0xC7, 0x44, 0xC3, 0xAE, 0x78,
  38743. 0xEC, 0xB4, 0xE0, 0x5A, 0x55, 0xB3, 0xFC, 0xC3,
  38744. 0x1B, 0x8C, 0xA6, 0xDB, 0xE8, 0x95, 0x72, 0x44,
  38745. 0x90, 0x8F, 0x4E, 0xD1, 0xD3, 0x46, 0x6C, 0x9E,
  38746. 0x00, 0xC6, 0xCC, 0xAE, 0xFC, 0x95, 0x4D, 0x85,
  38747. 0x7C, 0x65, 0x5F, 0x74, 0x71, 0xE3, 0x80, 0x88,
  38748. 0xCF, 0x1E, 0xB8, 0xBE, 0xED, 0x8D, 0xC4, 0xFB,
  38749. 0x3E, 0x36, 0xF3, 0xB8, 0x42, 0x1F, 0x37, 0x31,
  38750. 0x8D, 0xA2, 0x35, 0x36, 0x9E, 0x92, 0x3D, 0xD8,
  38751. 0xEA, 0xA7, 0xA2, 0x29, 0x0E, 0x14, 0xBF, 0x59,
  38752. 0x1E, 0x1D, 0x98, 0x27, 0x30, 0x3B, 0xF3, 0x57,
  38753. 0x69, 0x75, 0xCC, 0x3A, 0xB3, 0x49, 0x99, 0x70,
  38754. 0x19, 0x50, 0xAB, 0xF6, 0x7F, 0xF6, 0x55, 0x1A,
  38755. 0xCA, 0x2D, 0xA0, 0x73, 0x50, 0xE0, 0x9C, 0xEE,
  38756. 0x07, 0xEC, 0x37, 0x26, 0x6B, 0xAA, 0xA5, 0x34,
  38757. 0xFD, 0x7B, 0x1A, 0x92, 0x4E, 0xE7, 0x36, 0x1A,
  38758. 0xEB, 0x35, 0xCC, 0x5A, 0x5C, 0x06, 0x7F, 0x77,
  38759. 0xCE, 0x52, 0x33, 0x57, 0x73, 0x9D, 0xEC, 0x2D,
  38760. 0x28, 0x0C, 0xC9, 0xBF, 0x06, 0x9E, 0xA7, 0x7C,
  38761. 0x36, 0xF9, 0x0B, 0xC6, 0x7F, 0x0F, 0x66, 0x24,
  38762. 0x65, 0x2D, 0x30, 0x2B, 0xD7, 0x7F, 0x07, 0xD3,
  38763. 0x57, 0xC8, 0x4B, 0xC3, 0x0C, 0xA3, 0x5B, 0xAA,
  38764. 0xAF, 0xEA, 0xF3, 0xA3, 0x9E, 0x9E, 0xD4, 0x63,
  38765. 0xCD, 0x82, 0x8B, 0xBC, 0x5D, 0xEF, 0xE6, 0x2A,
  38766. 0x4D, 0x5B, 0x95, 0x13, 0x17, 0x98, 0xD3, 0x67,
  38767. 0x66, 0x04, 0x9E, 0x71, 0x71, 0xE6, 0xBD, 0x44,
  38768. 0x15, 0x6B, 0x29, 0x76, 0xE4, 0x62, 0x01, 0x99,
  38769. 0xEB, 0xF4, 0x2E, 0x14, 0x29, 0x0D, 0xBF, 0x8A,
  38770. 0x02, 0x30, 0x4A, 0xE7, 0x0D, 0x25, 0x42, 0x9E,
  38771. 0xD7, 0x0C, 0xAD, 0x30, 0xC6, 0xA3, 0x49, 0xF9,
  38772. 0x90, 0x0C, 0x46, 0x5B, 0x77, 0x67, 0x5F, 0x0B,
  38773. 0xE9, 0xA9, 0xFE, 0xFA, 0xC8, 0x5F, 0x19, 0xF7,
  38774. 0x35, 0x09, 0xF7, 0xB5, 0x6D, 0x51, 0x32, 0x17,
  38775. 0xBE, 0xE6, 0xC3, 0xBE, 0x4A, 0x9A, 0x33, 0xDA,
  38776. 0xC6, 0x90, 0xB7, 0xA7, 0x6F, 0x97, 0x9E, 0xD5,
  38777. 0x80, 0xE5, 0x02, 0x9E, 0x58, 0xD6, 0x45, 0x34,
  38778. 0x4D, 0x61, 0x71, 0x19, 0x07, 0x69, 0x1F, 0xAF,
  38779. 0xFF, 0x9F, 0xDE, 0x97, 0x13, 0xA1, 0xDF, 0x47,
  38780. 0x0E, 0x8B, 0xD6, 0xD0, 0x75, 0x40, 0x08, 0x59,
  38781. 0x7D, 0xFB, 0x74, 0x74, 0xF2, 0x48, 0xF4, 0x23,
  38782. 0x1B, 0x5E, 0x18, 0x4E, 0x2D, 0x2D, 0xC5, 0x40,
  38783. 0xD0, 0x90, 0x4F, 0x95, 0x69, 0xC4, 0xDA, 0xFB,
  38784. 0x39, 0x4B, 0x12, 0x7D, 0x22, 0x1E, 0x9A, 0x68,
  38785. 0x5B, 0x68, 0x2E, 0x47, 0x23, 0xB9, 0x6A, 0xBF,
  38786. 0xF7, 0xE2, 0x56, 0x79, 0xDD, 0x7A, 0x72, 0xF9,
  38787. 0x5F, 0x20, 0x6B, 0x29, 0x56, 0xEE, 0x04, 0x11,
  38788. 0x4C, 0x16, 0x34, 0x04, 0x14, 0x54, 0xB5, 0x21,
  38789. 0xAA, 0x6A, 0x46, 0x40, 0xE4, 0xF1, 0x78, 0x7C,
  38790. 0x50, 0xF3, 0x4D, 0xBC, 0x57, 0x34, 0x7C, 0x6A,
  38791. 0xBD, 0x9B, 0xEF, 0x03, 0x80, 0x7D, 0xAB, 0x20,
  38792. 0x0F, 0x77, 0x87, 0x6F, 0x93, 0xFB, 0x24, 0x20,
  38793. 0x82, 0xC7, 0x7E, 0xFB, 0x43, 0x2D, 0xC6, 0xD4,
  38794. 0xE9, 0x27, 0x8C, 0x66, 0xA8, 0x5A, 0x58, 0xC8,
  38795. 0xD8, 0x9A, 0xA8, 0x50, 0x5F, 0x3A, 0x3D, 0x0B,
  38796. 0xC3, 0x4F, 0xCE, 0x94, 0xE0, 0x0D, 0x16, 0xCB,
  38797. 0x20, 0xE0, 0xF5, 0x1A, 0x13, 0x6E, 0x28, 0xA6,
  38798. 0x42, 0xB2, 0xB1, 0x30, 0x1D, 0x56, 0x28, 0xCD,
  38799. 0xF3, 0x4E, 0xA7, 0x3E, 0x74, 0x04, 0x7D, 0xA5,
  38800. 0x86, 0xD9, 0x1A, 0xDF, 0x07, 0xBC, 0x2C, 0x59,
  38801. 0xB1, 0x91, 0x6D, 0x9B, 0xA2, 0xD0, 0x72, 0xE7,
  38802. 0xA5, 0x56, 0x4A, 0x27, 0x56, 0x1F, 0x65, 0xCD,
  38803. 0x90, 0x7B, 0xB7, 0x5A, 0x51, 0x25, 0x75, 0x1B,
  38804. 0xD9, 0xD4, 0xC7, 0x19, 0x8A, 0xB0, 0x3D, 0x38,
  38805. 0x22, 0x61, 0xCF, 0xD9, 0x66, 0xED, 0xF5, 0xB8,
  38806. 0xF5, 0x86, 0xFF, 0x98, 0x1A, 0xB7, 0xFB, 0x67,
  38807. 0xED, 0x25, 0x52, 0xD9, 0x2F, 0x84, 0xDC, 0x96,
  38808. 0x89, 0x2C, 0x52, 0xCF, 0x5F, 0xA0, 0xEA, 0xD0,
  38809. 0xB3, 0x38, 0x98, 0xFC, 0xD7, 0x50, 0x84, 0xCF,
  38810. 0xA5, 0xE9, 0x53, 0x8B, 0x44, 0x38, 0xB5, 0x7D,
  38811. 0xD8, 0xAD, 0x0A, 0xE5, 0x35, 0x78, 0x29, 0xBF,
  38812. 0x9F, 0x6B, 0x2C, 0xBB, 0x97, 0x9D, 0xD3, 0x64,
  38813. 0x23, 0x2B, 0xA8, 0xA4, 0x71, 0xE3, 0xF1, 0x2F,
  38814. 0x61, 0xC9, 0x68, 0xD2, 0x06, 0xD0, 0x4E, 0x87,
  38815. 0x03, 0x99, 0xCC, 0xB1, 0x83, 0xB6, 0x94, 0x61,
  38816. 0x3C, 0xE9, 0xE0, 0x7D, 0x13, 0xAF, 0xCF, 0xE4,
  38817. 0xA6, 0x42, 0x7F, 0x62, 0x8F, 0xFC, 0x10, 0xF1,
  38818. 0x08, 0x4D, 0x1D, 0xFC, 0x0F, 0x37, 0x11, 0xBE,
  38819. 0xD7, 0xF1, 0x80, 0x46, 0xAF, 0xFA, 0x13, 0x65,
  38820. 0x99, 0xAE, 0xF9, 0xD0, 0x13, 0xA7, 0xC7, 0x3A,
  38821. 0xD2, 0xC1, 0x9B, 0x5A, 0xB8, 0xC3, 0x08, 0x13,
  38822. 0x49, 0x40, 0x33, 0x0D, 0x1F, 0x93, 0x5D, 0x10,
  38823. 0x49, 0x3E, 0x4F, 0x90, 0x34, 0xC5, 0xEA, 0xF7,
  38824. 0x24, 0xFF, 0xF3, 0xC5, 0x95, 0xF7, 0x1F, 0x13,
  38825. 0x9A, 0xE0, 0x0C, 0xCD, 0x61, 0x93, 0x39, 0xE6,
  38826. 0xAF, 0xD5, 0x3E, 0xA9, 0xD8, 0xC4, 0x8F, 0x64,
  38827. 0x05, 0x09, 0x45, 0x2A, 0xEB, 0x12, 0xC5, 0x51,
  38828. 0x58, 0x1C, 0x55, 0x20, 0xE9, 0x29, 0x74, 0xC7,
  38829. 0x10, 0x01, 0xF3, 0xA4, 0x56, 0xB4, 0x14, 0xFE,
  38830. 0x9C, 0x10, 0x2F, 0xF8, 0xBF, 0xB5, 0x9C, 0x6E,
  38831. 0xBB, 0xE6, 0x52, 0xE7, 0xAC, 0xA7, 0xCE, 0x41,
  38832. 0x6E, 0x00, 0x66, 0x0A, 0x2F, 0x46, 0x71, 0xB8,
  38833. 0x8F, 0x45, 0x89, 0x26, 0x68, 0xCD, 0x49, 0xDF,
  38834. 0xCB, 0xCD, 0xD6, 0x66, 0xC6, 0xA7, 0x8E, 0xB3,
  38835. 0xE4, 0x72, 0xEF, 0xBA, 0xA6, 0x6D, 0x7A, 0xB7,
  38836. 0xE9, 0xD9, 0xB2, 0x60, 0xB5, 0x82, 0x77, 0x20,
  38837. 0x2A, 0xFA, 0xE3, 0xCB, 0xF5, 0x30, 0x50, 0x30,
  38838. 0xC6, 0x19, 0x67, 0xA8, 0xB8, 0xFA, 0xFE, 0xB6,
  38839. 0xDA, 0xB6, 0xB6, 0xBF, 0x07, 0x90, 0x40, 0xD8,
  38840. 0x5B, 0x15, 0x48, 0x39, 0xCD, 0x99, 0x0F, 0x3A,
  38841. 0x28, 0xD2, 0x2E, 0xBA, 0xAC, 0x6D, 0xA3, 0xF8,
  38842. 0x53, 0x88, 0xF0, 0x86, 0x87, 0x70, 0xF5, 0x07,
  38843. 0xD2, 0x99, 0xC4, 0xCA, 0xDD, 0xD8, 0x8C, 0xEB,
  38844. 0x00, 0x96, 0xB4, 0x62, 0xA3, 0x7B, 0x79, 0x31,
  38845. 0xB2, 0x85, 0xB0, 0x61, 0x39, 0xF2, 0xBC, 0x1D,
  38846. 0x31, 0xC3, 0x0C, 0x7F, 0x70, 0x9A, 0x63, 0x74,
  38847. 0xC6, 0xCB, 0xD3, 0x93, 0x0D, 0x43, 0x7F, 0x80,
  38848. 0x85, 0x87, 0x72, 0x98, 0xE1, 0x6E, 0x9A, 0x59,
  38849. 0x2E, 0x6C, 0xA8, 0x9E, 0xC2, 0xC0, 0x72, 0xFE,
  38850. 0x26, 0xE8, 0xAF, 0x89, 0x61, 0xCA, 0x0D, 0x15,
  38851. 0xCC, 0xB0, 0xBA, 0x10, 0xB8, 0x9D, 0x77, 0x2C,
  38852. 0x6C, 0x28, 0xCC, 0x70, 0x5B, 0x1F, 0x5D, 0x68,
  38853. 0xD4, 0xC8, 0x1F, 0x0F, 0x67, 0xF5, 0x3E, 0x5C,
  38854. 0x70, 0x50, 0x4B, 0x32, 0x12, 0xE6, 0x1A, 0xCE,
  38855. 0xB8, 0x32, 0x5F, 0x1D, 0xC5, 0xFB, 0x07, 0x77,
  38856. 0xAD, 0x85, 0x45, 0x95, 0x04, 0x0D, 0x94, 0x7A,
  38857. 0x1F, 0xDD, 0x05, 0x74, 0x14, 0xA5, 0x9A, 0x66,
  38858. 0xF4, 0x93, 0xBE, 0xF2, 0xA9, 0x5B, 0xCD, 0xAB,
  38859. 0xC7, 0x82, 0xF7, 0xE7, 0x4A, 0x1C, 0x90, 0x6B,
  38860. 0x9A, 0xBD, 0x93, 0xDD, 0x41, 0x56, 0xDA, 0xA5,
  38861. 0x0F, 0x5D, 0x57, 0x2C, 0xBA, 0x07, 0x07, 0x4B,
  38862. 0x91, 0x33, 0xE6, 0x1B, 0x0E, 0x25, 0x9E, 0x36,
  38863. 0xBF, 0xCA, 0x21, 0xCE, 0xC6, 0x82, 0x33, 0x4D,
  38864. 0x42, 0x4F, 0x2E, 0x71, 0xC2, 0xE7, 0x6F, 0x16,
  38865. 0xF6, 0xB7, 0x30, 0x1C, 0xA1, 0xA8, 0xE3, 0xE7,
  38866. 0xB1, 0x71, 0xDD, 0x9F, 0x90, 0x1F, 0x01, 0x1D,
  38867. 0x0A, 0xBD, 0x2C, 0x4A, 0x22, 0x84, 0x5C, 0xBF,
  38868. 0x61, 0x07, 0x24, 0xC4, 0x0D, 0x23, 0xDB, 0xC6,
  38869. 0x28, 0xB1, 0x27, 0xCB, 0x7E, 0x06, 0xF8, 0x3C,
  38870. 0x42, 0xF9, 0x51, 0x2F, 0x21, 0xC5, 0x80, 0x98,
  38871. 0x08, 0x2F, 0x56, 0x58, 0xD7, 0xE0, 0xDA, 0xC4,
  38872. 0x24, 0x0C, 0xE8, 0xFA, 0x94, 0x23, 0x57, 0xA6,
  38873. 0xD8, 0xE2, 0xC5, 0xCC, 0x16, 0x70, 0x55, 0x57,
  38874. 0xC4, 0x52, 0x2D, 0x94, 0xCE, 0x5B, 0x22, 0x8E,
  38875. 0x6C, 0x3D, 0x8E, 0x74, 0x9D, 0xFD, 0x47, 0xC7,
  38876. 0x42, 0x11, 0x41, 0x9F, 0x6A, 0x0A, 0xF6, 0x16,
  38877. 0x97, 0xB1, 0x24, 0xC4, 0x6C, 0x98, 0xF8, 0x62,
  38878. 0x51, 0xE9, 0x67, 0x6D, 0x39, 0x2B, 0x76, 0x19,
  38879. 0x5F, 0x41, 0xF4, 0x82, 0x51, 0x87, 0xFF, 0xAA,
  38880. 0x87, 0xE3, 0x46, 0x87, 0xC0, 0xC9, 0xBB, 0xB5,
  38881. 0xAC, 0xA0, 0xD1, 0x56, 0x54, 0xC2, 0x2C, 0x59,
  38882. 0x9E, 0x78, 0xF9, 0xA6, 0xBA, 0xCB, 0xE2, 0x45,
  38883. 0x8A, 0xC1, 0xE5, 0xDF, 0xC3, 0x81, 0x91, 0xDB,
  38884. 0xDB, 0x9E, 0xE2, 0x9C, 0xB9, 0x44, 0x5F, 0x5D,
  38885. 0x6D, 0x83, 0x8D, 0x2D, 0x3E, 0x72, 0x2F, 0x98,
  38886. 0xFC, 0xFA, 0x5F, 0xC0, 0xF0, 0x03, 0x4A, 0x42,
  38887. 0x19, 0x67, 0x48, 0x24, 0x70, 0x35, 0xAE, 0x37,
  38888. 0x34, 0x27, 0xAB, 0xD6, 0x92, 0xB8, 0xB4, 0x52,
  38889. 0xC9, 0xD1, 0xF0, 0x5C, 0xAC, 0xFA, 0xB9, 0x2D,
  38890. 0xCE, 0xF2, 0x24, 0xE3, 0x53, 0xF4, 0x2D, 0x65,
  38891. 0x8D, 0xBF, 0x27, 0x3F, 0xAF, 0x62, 0xE0, 0x27,
  38892. 0xBE, 0x12, 0xCB, 0x40, 0xA4, 0x99, 0xAF, 0x47,
  38893. 0x19, 0x5F, 0x68, 0x69, 0x7F, 0x8C, 0xD2, 0x1E,
  38894. 0x4A, 0xA1, 0xA4, 0x3D, 0x5A, 0x62, 0x6F, 0x78,
  38895. 0x87, 0x8E, 0xA0, 0xC0, 0xF3, 0x2C, 0x60, 0xC3,
  38896. 0xCE, 0xDD, 0xED, 0x7C, 0xAF, 0xE0, 0x0B, 0x72,
  38897. 0x9D, 0xBA, 0xC6, 0xEE, 0x00, 0x00, 0x00, 0x00,
  38898. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  38899. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07,
  38900. 0x0B, 0x15, 0x1B, 0x1E, 0x24
  38901. };
  38902. #endif
  38903. #ifndef WOLFSSL_NO_ML_DSA_87
  38904. static const byte sk_87[] = {
  38905. 0xF1, 0x79, 0x16, 0xD9, 0x5C, 0x51, 0x2F, 0xEC,
  38906. 0x0C, 0xEF, 0xA6, 0xA1, 0x5C, 0x9F, 0xB3, 0xBF,
  38907. 0x84, 0xFF, 0x8D, 0x7F, 0xA3, 0x55, 0x22, 0xEB,
  38908. 0x1C, 0x91, 0x5C, 0x4D, 0x25, 0x4E, 0x89, 0x35,
  38909. 0x24, 0x8E, 0x3C, 0x08, 0x58, 0x2B, 0x74, 0x5E,
  38910. 0xB2, 0xFD, 0x13, 0x15, 0x2B, 0x5D, 0xAE, 0xEA,
  38911. 0xB0, 0x72, 0x80, 0x42, 0xB0, 0x08, 0x85, 0xBB,
  38912. 0x92, 0xF8, 0x44, 0xA8, 0x6B, 0x42, 0x62, 0x03,
  38913. 0x5C, 0x9F, 0x44, 0x8A, 0x2B, 0x78, 0xEF, 0x5D,
  38914. 0xB3, 0x47, 0xE0, 0x25, 0x04, 0x15, 0xE1, 0x01,
  38915. 0x5F, 0xBB, 0x34, 0x31, 0x91, 0x24, 0x07, 0xC8,
  38916. 0x5A, 0x2F, 0x36, 0x2A, 0x85, 0xA9, 0xAE, 0x42,
  38917. 0x77, 0x23, 0xBF, 0x62, 0x69, 0x7B, 0x77, 0x99,
  38918. 0x1B, 0x3E, 0x93, 0xA3, 0x81, 0x13, 0x3F, 0x95,
  38919. 0x0D, 0x40, 0xE7, 0xC1, 0xAC, 0xBC, 0x17, 0xE4,
  38920. 0xF1, 0xD1, 0x0C, 0xD1, 0x27, 0x4C, 0x8D, 0x3C,
  38921. 0x84, 0x02, 0x02, 0x0A, 0xC5, 0x10, 0x1C, 0xC3,
  38922. 0x4D, 0xD0, 0x94, 0x70, 0x24, 0xC0, 0x89, 0x94,
  38923. 0x08, 0x4D, 0xC2, 0x30, 0x20, 0x63, 0xC0, 0x24,
  38924. 0xE1, 0x80, 0x40, 0xD0, 0x26, 0x68, 0x10, 0x97,
  38925. 0x01, 0x83, 0xC2, 0x91, 0x5A, 0x90, 0x2D, 0x44,
  38926. 0x94, 0x6D, 0x10, 0x09, 0x50, 0x11, 0xA7, 0x0D,
  38927. 0xE4, 0x04, 0x89, 0x9B, 0x80, 0x8D, 0x40, 0xB8,
  38928. 0x45, 0x4B, 0x86, 0x0D, 0xC8, 0xB6, 0x05, 0xC0,
  38929. 0xC0, 0x71, 0x02, 0x09, 0x06, 0xA2, 0x00, 0x2D,
  38930. 0x0B, 0x24, 0x86, 0xA0, 0x90, 0x11, 0x20, 0x16,
  38931. 0x82, 0x1B, 0x24, 0x42, 0xCB, 0xB6, 0x70, 0x43,
  38932. 0x36, 0x05, 0xDA, 0x16, 0x25, 0x9A, 0x34, 0x6C,
  38933. 0xCB, 0xB4, 0x08, 0xC4, 0x16, 0x90, 0x24, 0x29,
  38934. 0x6C, 0x42, 0x90, 0x04, 0x24, 0x06, 0x46, 0x84,
  38935. 0x12, 0x6D, 0xC2, 0x26, 0x00, 0x88, 0x40, 0x02,
  38936. 0x51, 0xC8, 0x40, 0x9C, 0x16, 0x24, 0x82, 0x18,
  38937. 0x26, 0x21, 0x06, 0x0C, 0x12, 0xC2, 0x71, 0x50,
  38938. 0x98, 0x91, 0x4A, 0x40, 0x28, 0x48, 0x48, 0x21,
  38939. 0x5A, 0x18, 0x49, 0x1B, 0xB7, 0x01, 0x5A, 0xC6,
  38940. 0x48, 0xA1, 0x90, 0x2C, 0x14, 0x18, 0x2D, 0xD2,
  38941. 0x20, 0x62, 0xDC, 0xB6, 0x49, 0x00, 0x09, 0x6D,
  38942. 0x40, 0xA8, 0x4D, 0x24, 0xC8, 0x24, 0x4C, 0x06,
  38943. 0x08, 0x80, 0x40, 0x4E, 0xD3, 0x18, 0x88, 0x12,
  38944. 0x09, 0x91, 0x8B, 0x12, 0x31, 0xC9, 0x16, 0x04,
  38945. 0x64, 0x10, 0x72, 0xDA, 0x84, 0x91, 0x92, 0xC6,
  38946. 0x65, 0x22, 0x10, 0x48, 0x18, 0xC9, 0x00, 0x14,
  38947. 0x44, 0x62, 0x24, 0xC1, 0x60, 0x40, 0xC6, 0x10,
  38948. 0x4A, 0x48, 0x28, 0x9B, 0x44, 0x66, 0x91, 0x10,
  38949. 0x52, 0xD3, 0x26, 0x52, 0xD8, 0xA6, 0x0C, 0x0A,
  38950. 0xA8, 0x44, 0xD8, 0x26, 0x0C, 0x64, 0x86, 0x45,
  38951. 0x44, 0x20, 0x00, 0xD2, 0x48, 0x85, 0xDC, 0x46,
  38952. 0x32, 0xC8, 0x22, 0x45, 0x5B, 0x00, 0x8D, 0x20,
  38953. 0xA5, 0x45, 0x01, 0xC1, 0x91, 0xA2, 0x12, 0x84,
  38954. 0x20, 0x47, 0x0E, 0x98, 0xA8, 0x25, 0xD9, 0xA0,
  38955. 0x4D, 0xA4, 0x06, 0x2D, 0x5B, 0xB0, 0x08, 0x21,
  38956. 0xB0, 0x80, 0x4C, 0x10, 0x2C, 0xC4, 0x98, 0x71,
  38957. 0x99, 0x24, 0x24, 0xA4, 0x36, 0x71, 0x4B, 0xB6,
  38958. 0x49, 0xE1, 0x92, 0x00, 0x09, 0x92, 0x4C, 0x89,
  38959. 0x12, 0x49, 0x1A, 0x39, 0x2A, 0xE0, 0x22, 0x69,
  38960. 0x61, 0xB2, 0x50, 0x40, 0x26, 0x8E, 0xC9, 0xA2,
  38961. 0x08, 0x0A, 0x90, 0x24, 0x13, 0x35, 0x06, 0x21,
  38962. 0x24, 0x62, 0x60, 0xB0, 0x01, 0xE3, 0xC6, 0x29,
  38963. 0x5B, 0x28, 0x89, 0x20, 0x90, 0x70, 0xC4, 0xA4,
  38964. 0x31, 0x08, 0x42, 0x11, 0x10, 0xC0, 0x71, 0x98,
  38965. 0x98, 0x20, 0xC4, 0xA8, 0x29, 0x1A, 0x15, 0x32,
  38966. 0xC4, 0x86, 0x6C, 0x18, 0x14, 0x6A, 0x02, 0x46,
  38967. 0x46, 0xDC, 0xC2, 0x4C, 0x81, 0x02, 0x6D, 0x49,
  38968. 0x16, 0x48, 0x10, 0x94, 0x6C, 0x0A, 0x85, 0x90,
  38969. 0x9C, 0x34, 0x84, 0x54, 0x24, 0x25, 0x49, 0xA8,
  38970. 0x21, 0x04, 0xA6, 0x2C, 0x61, 0x00, 0x01, 0x61,
  38971. 0x46, 0x92, 0xE0, 0xA6, 0x44, 0xE2, 0x00, 0x90,
  38972. 0xC8, 0x06, 0x06, 0x90, 0xB8, 0x2D, 0x0B, 0x85,
  38973. 0x85, 0x20, 0x23, 0x0D, 0x83, 0x94, 0x04, 0x54,
  38974. 0x26, 0x50, 0x41, 0x92, 0x29, 0x09, 0x16, 0x20,
  38975. 0x54, 0xC6, 0x2D, 0x81, 0xC8, 0x8C, 0x09, 0x44,
  38976. 0x44, 0xE2, 0x06, 0x30, 0x13, 0x92, 0x49, 0x0B,
  38977. 0x17, 0x48, 0x93, 0x28, 0x86, 0xD8, 0xA4, 0x50,
  38978. 0xD1, 0x32, 0x91, 0x08, 0xB8, 0x05, 0xA4, 0x02,
  38979. 0x62, 0x01, 0x15, 0x82, 0xE3, 0x18, 0x42, 0x83,
  38980. 0xC6, 0x44, 0x43, 0x02, 0x81, 0x53, 0x88, 0x04,
  38981. 0x04, 0x98, 0x31, 0x19, 0x18, 0x46, 0xDB, 0x02,
  38982. 0x89, 0x10, 0x23, 0x81, 0x03, 0x90, 0x71, 0x83,
  38983. 0x26, 0x89, 0x1A, 0x01, 0x05, 0xCA, 0xB0, 0x01,
  38984. 0x4C, 0x84, 0x09, 0x10, 0x11, 0x84, 0x13, 0xB1,
  38985. 0x20, 0x61, 0xB8, 0x41, 0x1B, 0x02, 0x8C, 0x09,
  38986. 0x98, 0x61, 0x83, 0x18, 0x61, 0x08, 0xC1, 0x6D,
  38987. 0x44, 0x86, 0x09, 0xCB, 0x88, 0x8D, 0x93, 0xB4,
  38988. 0x41, 0x58, 0x90, 0x81, 0x04, 0x31, 0x08, 0xD1,
  38989. 0xC4, 0x04, 0x19, 0xB4, 0x4C, 0x1C, 0x88, 0x20,
  38990. 0xCA, 0x30, 0x72, 0x1C, 0xB5, 0x85, 0x13, 0x27,
  38991. 0x32, 0x84, 0xB4, 0x44, 0x04, 0x42, 0x20, 0x61,
  38992. 0x18, 0x52, 0x50, 0x96, 0x44, 0x03, 0x38, 0x86,
  38993. 0xE3, 0x48, 0x31, 0x02, 0x82, 0x68, 0x98, 0x06,
  38994. 0x90, 0x23, 0x28, 0x04, 0x10, 0x18, 0x0D, 0x10,
  38995. 0x28, 0x45, 0x4C, 0x84, 0x6C, 0x09, 0x36, 0x71,
  38996. 0x82, 0x26, 0x64, 0x18, 0xC6, 0x21, 0x90, 0x18,
  38997. 0x22, 0x0A, 0x37, 0x08, 0xC4, 0x94, 0x28, 0xE2,
  38998. 0x30, 0x2C, 0x92, 0xB4, 0x24, 0x63, 0x46, 0x70,
  38999. 0x52, 0x96, 0x0C, 0x8B, 0xA4, 0x05, 0xD3, 0x02,
  39000. 0x85, 0x09, 0x32, 0x92, 0x49, 0x12, 0x21, 0x18,
  39001. 0x43, 0x28, 0x01, 0x32, 0x45, 0x0B, 0xA5, 0x50,
  39002. 0x14, 0x16, 0x65, 0x91, 0x80, 0x65, 0x0A, 0x44,
  39003. 0x66, 0x13, 0xB6, 0x4C, 0x01, 0x38, 0x71, 0x11,
  39004. 0x49, 0x28, 0x22, 0x43, 0x02, 0x0B, 0x34, 0x04,
  39005. 0x01, 0x16, 0x91, 0x80, 0x14, 0x0E, 0x12, 0x93,
  39006. 0x01, 0x00, 0x11, 0x80, 0xDC, 0x28, 0x51, 0x11,
  39007. 0x87, 0x85, 0xC1, 0x34, 0x28, 0x02, 0xA2, 0x11,
  39008. 0x02, 0x38, 0x44, 0x52, 0x14, 0x64, 0xC2, 0xA0,
  39009. 0x01, 0x1B, 0x42, 0x8C, 0xC2, 0xB2, 0x71, 0xCB,
  39010. 0x16, 0x00, 0xCC, 0x10, 0x21, 0x04, 0x12, 0x52,
  39011. 0x84, 0x24, 0x2A, 0xD3, 0x48, 0x12, 0x08, 0x44,
  39012. 0x08, 0x81, 0x88, 0x44, 0x01, 0x23, 0x50, 0xC0,
  39013. 0xA2, 0x09, 0x81, 0x94, 0x50, 0x02, 0x89, 0x61,
  39014. 0x01, 0x31, 0x88, 0x1B, 0xA2, 0x61, 0x90, 0x94,
  39015. 0x84, 0x91, 0x24, 0x09, 0x03, 0x18, 0x22, 0xA3,
  39016. 0x46, 0x60, 0x10, 0x16, 0x4D, 0x48, 0x84, 0x89,
  39017. 0x11, 0x00, 0x2E, 0xCC, 0xC0, 0x40, 0x8C, 0xC0,
  39018. 0x51, 0xE4, 0x42, 0x62, 0xDA, 0x24, 0x11, 0x13,
  39019. 0x19, 0x46, 0x93, 0x34, 0x4C, 0x42, 0x42, 0x24,
  39020. 0xC4, 0x48, 0x90, 0x00, 0x35, 0x80, 0x1B, 0x98,
  39021. 0x51, 0x0B, 0x41, 0x60, 0x0C, 0x25, 0x46, 0x9A,
  39022. 0xA8, 0x89, 0x12, 0x86, 0x4C, 0xE3, 0x16, 0x09,
  39023. 0x14, 0x27, 0x24, 0x51, 0x26, 0x4D, 0x1B, 0x02,
  39024. 0x10, 0x00, 0x17, 0x28, 0xD4, 0xA8, 0x45, 0x48,
  39025. 0x88, 0x48, 0x01, 0xC7, 0x0D, 0x93, 0xC8, 0x40,
  39026. 0x5B, 0x02, 0x49, 0x51, 0x02, 0x4A, 0x01, 0x42,
  39027. 0x10, 0xE1, 0x08, 0x90, 0x03, 0x85, 0x48, 0x11,
  39028. 0xA8, 0x68, 0x8B, 0x90, 0x08, 0x5A, 0x02, 0x0C,
  39029. 0x5A, 0x18, 0x50, 0x11, 0x87, 0x51, 0x9C, 0x38,
  39030. 0x92, 0xD0, 0x44, 0x82, 0x10, 0x33, 0x21, 0x88,
  39031. 0x44, 0x2D, 0x24, 0x28, 0x0D, 0x22, 0xA3, 0x30,
  39032. 0x49, 0x88, 0x25, 0xA1, 0xB2, 0x01, 0x5C, 0x40,
  39033. 0x20, 0x1C, 0x03, 0x72, 0xCC, 0x96, 0x8C, 0x51,
  39034. 0xA6, 0x88, 0xE3, 0x92, 0x08, 0x13, 0xB0, 0x08,
  39035. 0x5C, 0x38, 0x44, 0x03, 0x47, 0x8E, 0x93, 0x12,
  39036. 0x4A, 0x88, 0x20, 0x48, 0xE0, 0x42, 0x20, 0x81,
  39037. 0x90, 0x09, 0x4B, 0x06, 0x6D, 0xD2, 0x90, 0x10,
  39038. 0x01, 0x82, 0x49, 0x19, 0x28, 0x91, 0xDA, 0x20,
  39039. 0x2A, 0x20, 0x85, 0x40, 0x0A, 0x16, 0x8A, 0x1C,
  39040. 0x83, 0x60, 0xCA, 0x48, 0x4A, 0xA2, 0xC8, 0x50,
  39041. 0xE4, 0x02, 0x31, 0x88, 0x86, 0x88, 0x53, 0x00,
  39042. 0x89, 0x60, 0x08, 0x8A, 0xA2, 0x02, 0x0A, 0x0A,
  39043. 0x34, 0x45, 0x03, 0x04, 0x42, 0x1B, 0x40, 0x09,
  39044. 0x89, 0xA0, 0x69, 0x42, 0x18, 0x49, 0x4A, 0xA8,
  39045. 0x8C, 0x99, 0x90, 0x30, 0xCA, 0x38, 0x91, 0x09,
  39046. 0x31, 0x72, 0x8B, 0x44, 0x29, 0x52, 0xA2, 0x8D,
  39047. 0x08, 0x14, 0x6E, 0xA1, 0x84, 0x50, 0x1C, 0x31,
  39048. 0x46, 0x19, 0xB7, 0x01, 0xCC, 0x06, 0x29, 0x11,
  39049. 0x09, 0x20, 0x4B, 0x40, 0x66, 0x40, 0xC4, 0x49,
  39050. 0x00, 0x13, 0x24, 0xD0, 0xA2, 0x84, 0xCA, 0x16,
  39051. 0x29, 0xD0, 0xC0, 0x84, 0xC8, 0x88, 0x44, 0xE1,
  39052. 0x20, 0x29, 0x1A, 0x97, 0x05, 0x90, 0x42, 0x90,
  39053. 0x04, 0x40, 0x71, 0x9C, 0x32, 0x4E, 0x64, 0x26,
  39054. 0x22, 0x93, 0x36, 0x66, 0xD3, 0x06, 0x49, 0xA3,
  39055. 0x26, 0x51, 0x4C, 0xA6, 0x89, 0x84, 0x36, 0x84,
  39056. 0x93, 0x46, 0x6D, 0x14, 0x07, 0x8D, 0x18, 0x29,
  39057. 0x42, 0x52, 0x34, 0x72, 0x44, 0x10, 0x90, 0x12,
  39058. 0x37, 0x81, 0xD4, 0x10, 0x64, 0x04, 0xA5, 0x08,
  39059. 0x84, 0x24, 0x09, 0x1C, 0x08, 0x8D, 0x02, 0x99,
  39060. 0x6C, 0x1B, 0x30, 0x50, 0x09, 0x89, 0x81, 0x19,
  39061. 0x30, 0x48, 0x5B, 0x14, 0x4D, 0xD9, 0x20, 0x20,
  39062. 0x0C, 0x01, 0x2A, 0x00, 0x90, 0x4D, 0xA1, 0x02,
  39063. 0x64, 0x1C, 0x03, 0x01, 0xC2, 0x26, 0x8C, 0x14,
  39064. 0x08, 0x45, 0xE3, 0x12, 0x48, 0x09, 0x20, 0x09,
  39065. 0x41, 0x40, 0x61, 0x90, 0x44, 0x21, 0x49, 0x06,
  39066. 0x91, 0x4B, 0xC0, 0x84, 0x22, 0x95, 0x51, 0x23,
  39067. 0x38, 0x0E, 0x5C, 0x28, 0x70, 0xC2, 0x40, 0x2C,
  39068. 0x94, 0x18, 0x62, 0x9A, 0x30, 0x4A, 0xE2, 0x86,
  39069. 0x4C, 0x5C, 0x10, 0x8D, 0xC2, 0x12, 0x21, 0x9C,
  39070. 0xC4, 0x4D, 0xD9, 0x96, 0x88, 0x0C, 0x29, 0x45,
  39071. 0x1B, 0x45, 0x6A, 0x1A, 0x00, 0x60, 0x91, 0x30,
  39072. 0x0C, 0x12, 0x00, 0x69, 0xA2, 0xA0, 0x04, 0x81,
  39073. 0x00, 0x65, 0x5C, 0x38, 0x8A, 0x18, 0x05, 0x89,
  39074. 0x48, 0x32, 0x24, 0x81, 0xC6, 0x4D, 0x60, 0x90,
  39075. 0x31, 0x83, 0x22, 0x12, 0xE1, 0xC2, 0x6C, 0x89,
  39076. 0x00, 0x90, 0x14, 0xB4, 0x40, 0xD3, 0xB8, 0x45,
  39077. 0x89, 0x24, 0x70, 0x09, 0x26, 0x6C, 0xD9, 0x32,
  39078. 0x8A, 0x83, 0x44, 0x0E, 0x21, 0x44, 0x61, 0x99,
  39079. 0xA4, 0x20, 0x44, 0x16, 0x2E, 0x1A, 0xC2, 0x08,
  39080. 0x09, 0x98, 0x6C, 0x8C, 0x18, 0x8C, 0x0C, 0x30,
  39081. 0x62, 0x8B, 0x46, 0x45, 0x80, 0x10, 0x21, 0x20,
  39082. 0x33, 0x32, 0x5A, 0x38, 0x4C, 0x98, 0x06, 0x45,
  39083. 0x1A, 0x33, 0x09, 0x82, 0x34, 0x44, 0x02, 0x20,
  39084. 0x09, 0x59, 0x00, 0x41, 0x08, 0x13, 0x08, 0xDC,
  39085. 0x18, 0x68, 0x12, 0x47, 0x86, 0x43, 0xB8, 0x21,
  39086. 0x62, 0x02, 0x8D, 0x5C, 0x10, 0x0D, 0x60, 0x96,
  39087. 0x65, 0xA2, 0x22, 0x4C, 0x83, 0x18, 0x09, 0x41,
  39088. 0x08, 0x41, 0x63, 0xC2, 0x80, 0x13, 0x81, 0x65,
  39089. 0x22, 0x03, 0x92, 0x04, 0xA9, 0x4D, 0x1C, 0xB0,
  39090. 0x44, 0x80, 0xC6, 0x24, 0x00, 0x01, 0x44, 0x22,
  39091. 0x11, 0x80, 0x21, 0x95, 0x64, 0x09, 0x99, 0x8C,
  39092. 0xD3, 0x14, 0x4A, 0xD1, 0x98, 0x2D, 0x19, 0x31,
  39093. 0x4C, 0x0A, 0x92, 0x40, 0x13, 0x98, 0x48, 0x14,
  39094. 0x89, 0x20, 0x23, 0xB3, 0x0D, 0x14, 0x98, 0x6D,
  39095. 0x12, 0x98, 0x05, 0x9B, 0x14, 0x06, 0x5B, 0x26,
  39096. 0x91, 0x0A, 0x38, 0x09, 0x08, 0x98, 0x2C, 0x19,
  39097. 0xA0, 0x45, 0x44, 0x26, 0x00, 0x0A, 0x05, 0x21,
  39098. 0xDB, 0xA0, 0x69, 0x51, 0x42, 0x92, 0x0B, 0x43,
  39099. 0x00, 0xD1, 0x42, 0x0D, 0x81, 0x30, 0x28, 0x13,
  39100. 0xC2, 0x20, 0x03, 0x27, 0x60, 0x10, 0x83, 0x91,
  39101. 0x0A, 0x53, 0x7E, 0xA1, 0x4F, 0x11, 0x54, 0x5E,
  39102. 0x25, 0x4F, 0xCF, 0x28, 0x03, 0x95, 0x2A, 0x58,
  39103. 0x0A, 0x4B, 0x6C, 0x9B, 0x29, 0x10, 0x3D, 0x97,
  39104. 0x43, 0x6C, 0x00, 0x3E, 0x2E, 0xCE, 0xAE, 0x20,
  39105. 0x28, 0x01, 0x7F, 0xF1, 0xD5, 0x18, 0xB0, 0xB5,
  39106. 0xD5, 0xE6, 0x24, 0x26, 0x64, 0xED, 0x33, 0x7C,
  39107. 0xCA, 0x45, 0x26, 0xED, 0x5D, 0xB5, 0xEA, 0xD8,
  39108. 0xBB, 0x31, 0x16, 0x94, 0x1C, 0xD0, 0xC8, 0xF0,
  39109. 0xA7, 0xED, 0x5A, 0x1A, 0x5A, 0x00, 0xB9, 0x8C,
  39110. 0x33, 0x6A, 0x9B, 0xC8, 0xEB, 0x6B, 0x3A, 0x30,
  39111. 0x83, 0x16, 0xF1, 0x17, 0xEA, 0xA8, 0x0D, 0x4B,
  39112. 0x77, 0x56, 0xDD, 0x4A, 0x91, 0xDA, 0xA5, 0x8E,
  39113. 0x80, 0xD7, 0xB5, 0x77, 0x55, 0x83, 0x97, 0xAF,
  39114. 0x90, 0x5B, 0x67, 0xC5, 0x9F, 0x14, 0xE1, 0x2C,
  39115. 0x15, 0x8D, 0x29, 0x2C, 0xA6, 0xB6, 0x41, 0xED,
  39116. 0x0C, 0x75, 0xE3, 0x9A, 0x91, 0x4F, 0xFA, 0x1A,
  39117. 0x9F, 0x24, 0xCA, 0x28, 0xF2, 0x00, 0xC7, 0x48,
  39118. 0xDE, 0x70, 0x9D, 0x15, 0xD7, 0x22, 0xE7, 0xED,
  39119. 0x2C, 0x91, 0x8D, 0xEF, 0x08, 0xCF, 0xAF, 0x9B,
  39120. 0x7E, 0x24, 0xDE, 0xF2, 0xD5, 0x1A, 0x4D, 0x42,
  39121. 0x0E, 0x7E, 0x89, 0x06, 0xFA, 0xCD, 0x9A, 0x5A,
  39122. 0x98, 0xB0, 0xD1, 0xD5, 0x34, 0x5C, 0x8B, 0x9A,
  39123. 0xC0, 0xBB, 0xF4, 0xB1, 0x5E, 0xF0, 0xB4, 0x6A,
  39124. 0x8E, 0x3B, 0x6B, 0xAE, 0x0C, 0x6E, 0x9F, 0x09,
  39125. 0x2E, 0xB3, 0xEF, 0x1D, 0x49, 0x62, 0x0B, 0x65,
  39126. 0xE7, 0xDE, 0xDB, 0xEF, 0x68, 0x7E, 0xBD, 0x0E,
  39127. 0xA0, 0x95, 0x97, 0x2A, 0x56, 0xA0, 0xEA, 0xFB,
  39128. 0x2D, 0x75, 0xF4, 0x32, 0x1B, 0x80, 0xAC, 0xBC,
  39129. 0xA3, 0x2B, 0x1B, 0x11, 0xAA, 0x57, 0x6F, 0xE4,
  39130. 0xE0, 0xCC, 0xCC, 0x20, 0x52, 0x12, 0x65, 0x42,
  39131. 0x96, 0xF0, 0x60, 0x8F, 0xF3, 0x83, 0x69, 0xAF,
  39132. 0x19, 0x80, 0x75, 0x68, 0xDB, 0xE1, 0x71, 0xDB,
  39133. 0x79, 0xEB, 0x8C, 0x1C, 0xB7, 0x6A, 0x8E, 0xB9,
  39134. 0x5B, 0x28, 0x8C, 0x9D, 0xCC, 0x62, 0x0B, 0xEF,
  39135. 0xCE, 0x96, 0x06, 0x0F, 0x45, 0xA6, 0xA2, 0xDA,
  39136. 0xC2, 0x2F, 0x55, 0xE4, 0x7D, 0xC7, 0xBA, 0xB4,
  39137. 0xA7, 0x93, 0xD9, 0x65, 0x8F, 0xE2, 0x7C, 0x66,
  39138. 0x2C, 0xA6, 0x37, 0x00, 0x81, 0x30, 0xF1, 0x00,
  39139. 0xD9, 0x65, 0xB4, 0x78, 0x17, 0x7A, 0xC6, 0xDC,
  39140. 0x35, 0x93, 0x1A, 0x5E, 0xCC, 0x5F, 0x93, 0x31,
  39141. 0x22, 0x40, 0x2C, 0x17, 0x0E, 0xB8, 0xE0, 0xA4,
  39142. 0x1C, 0xB6, 0x3F, 0xE5, 0x60, 0x2F, 0x7B, 0x18,
  39143. 0xE1, 0xDB, 0xB6, 0xDB, 0x30, 0xA7, 0x61, 0x55,
  39144. 0xC6, 0xCF, 0x03, 0x0F, 0x73, 0x8D, 0xC0, 0x91,
  39145. 0x6D, 0xB1, 0x80, 0xF8, 0x3F, 0x02, 0x90, 0x93,
  39146. 0x11, 0xCB, 0x6B, 0x3B, 0x9E, 0x55, 0x3F, 0xAC,
  39147. 0xA0, 0x52, 0x23, 0xB3, 0x3C, 0x69, 0x60, 0x2D,
  39148. 0x0F, 0x05, 0xA0, 0x8B, 0xEB, 0x84, 0x80, 0x96,
  39149. 0x51, 0x99, 0x9A, 0x55, 0x26, 0xE7, 0x76, 0xF3,
  39150. 0xDE, 0x39, 0x30, 0x4A, 0x5F, 0xEF, 0x00, 0x95,
  39151. 0x0A, 0x9A, 0x81, 0x0D, 0x12, 0xE0, 0x1D, 0x15,
  39152. 0xD8, 0x86, 0xDB, 0x26, 0x75, 0xF6, 0x54, 0xCA,
  39153. 0x17, 0xFA, 0xAE, 0xEB, 0xD1, 0xF5, 0x61, 0xF9,
  39154. 0xD1, 0xA9, 0x5E, 0x0B, 0xAD, 0xF7, 0xC3, 0x31,
  39155. 0x5A, 0xFA, 0xBA, 0x8D, 0x4B, 0xEC, 0x1F, 0x05,
  39156. 0x42, 0xA8, 0xF1, 0x0A, 0xC6, 0x66, 0xFD, 0x8D,
  39157. 0x0C, 0x5A, 0xF1, 0xD6, 0x86, 0x7A, 0x9D, 0x82,
  39158. 0x6B, 0xFB, 0x6B, 0x03, 0x0B, 0x58, 0xEC, 0xEF,
  39159. 0x67, 0x78, 0xD2, 0xC5, 0x2B, 0xF6, 0x2C, 0xB3,
  39160. 0x4B, 0x81, 0xFF, 0x93, 0x6D, 0xA3, 0x3E, 0xDA,
  39161. 0xB3, 0x1D, 0xB3, 0x9A, 0xB7, 0x63, 0x66, 0xD0,
  39162. 0x94, 0x36, 0x2F, 0x04, 0x6D, 0x50, 0x78, 0xB4,
  39163. 0x22, 0x35, 0x04, 0xA1, 0x2B, 0xA0, 0xC7, 0xB8,
  39164. 0xE8, 0x83, 0x72, 0x77, 0x18, 0x50, 0x9B, 0xD4,
  39165. 0x7A, 0x69, 0x6E, 0xE9, 0x88, 0x0C, 0xAF, 0xF6,
  39166. 0x63, 0x61, 0x2B, 0x95, 0x86, 0x30, 0x3D, 0x6D,
  39167. 0xE0, 0xD2, 0x1F, 0x9A, 0x21, 0x96, 0x22, 0x78,
  39168. 0xEB, 0xCE, 0x60, 0xA6, 0xD4, 0x68, 0x44, 0x09,
  39169. 0x5C, 0x5F, 0x89, 0x2D, 0xAC, 0xA4, 0x8D, 0x78,
  39170. 0x28, 0x22, 0x45, 0x38, 0x34, 0xB4, 0xE4, 0x2C,
  39171. 0xD3, 0xA1, 0xFE, 0x39, 0x87, 0x35, 0x6E, 0xAB,
  39172. 0x11, 0xEF, 0xB8, 0xEE, 0xCD, 0x8E, 0x9C, 0xC8,
  39173. 0xF3, 0x9A, 0x0F, 0xF1, 0xFF, 0xB8, 0x06, 0x9A,
  39174. 0x44, 0x1F, 0x85, 0x1E, 0xB4, 0x38, 0xE9, 0xC0,
  39175. 0xB5, 0x7E, 0x88, 0x18, 0xA3, 0x22, 0x65, 0x1E,
  39176. 0x60, 0xF4, 0xB6, 0x78, 0x90, 0xE5, 0xED, 0x7A,
  39177. 0x0F, 0xBF, 0x75, 0x36, 0xC3, 0xFD, 0x50, 0xD0,
  39178. 0xB0, 0x65, 0x8D, 0x7C, 0xCF, 0x27, 0x5E, 0x8A,
  39179. 0x9E, 0x9F, 0xBB, 0x99, 0xBE, 0x2E, 0x5F, 0x5E,
  39180. 0x16, 0x7B, 0xE2, 0x90, 0xB7, 0xE9, 0x67, 0x32,
  39181. 0xF8, 0x9E, 0x40, 0xD7, 0x85, 0xAF, 0x25, 0xC1,
  39182. 0xBA, 0x61, 0xA7, 0x78, 0x6D, 0x3E, 0xF2, 0xD0,
  39183. 0xC1, 0x14, 0xD1, 0x04, 0x8E, 0x76, 0x46, 0xDF,
  39184. 0xA3, 0x03, 0x2B, 0xFB, 0x7A, 0x51, 0xA6, 0x36,
  39185. 0x05, 0xDC, 0xE3, 0xE1, 0xD8, 0x98, 0x95, 0x00,
  39186. 0xD6, 0xE5, 0x8E, 0x96, 0x05, 0x19, 0x93, 0x1D,
  39187. 0xAC, 0x9F, 0x14, 0xDD, 0xA4, 0x28, 0xF5, 0xA2,
  39188. 0xC9, 0xC7, 0x4D, 0x91, 0x6D, 0x90, 0x77, 0x07,
  39189. 0xB5, 0x3E, 0xB5, 0x2C, 0x44, 0xAD, 0x71, 0xD7,
  39190. 0x27, 0x82, 0x6E, 0xB2, 0xCA, 0x68, 0x07, 0x0A,
  39191. 0x6F, 0x0E, 0x47, 0xFA, 0x16, 0xE5, 0x2E, 0x96,
  39192. 0x29, 0xB7, 0xAA, 0x82, 0x41, 0xDA, 0xAB, 0xB1,
  39193. 0x94, 0x97, 0xA5, 0x82, 0x4E, 0x58, 0xD7, 0x26,
  39194. 0x75, 0xC3, 0xA6, 0x7E, 0x10, 0xA1, 0x19, 0xB2,
  39195. 0x74, 0xB8, 0x4D, 0x9B, 0xEE, 0x28, 0x71, 0x72,
  39196. 0x8E, 0xD2, 0xF9, 0x4F, 0x85, 0x59, 0xB9, 0x7F,
  39197. 0x97, 0x9A, 0xE8, 0x82, 0xEA, 0x54, 0x99, 0x28,
  39198. 0xD6, 0xB1, 0xA9, 0xA4, 0xE4, 0xA2, 0x29, 0xF6,
  39199. 0xEB, 0x3F, 0xB1, 0xA4, 0x34, 0xA0, 0xFA, 0xED,
  39200. 0xAD, 0x62, 0xB7, 0x03, 0x30, 0xCF, 0xCB, 0x24,
  39201. 0xCB, 0x34, 0x98, 0x80, 0x2A, 0x67, 0x9F, 0x8F,
  39202. 0x54, 0xBF, 0x83, 0xEF, 0x34, 0x47, 0x22, 0x96,
  39203. 0x91, 0x98, 0x31, 0xCA, 0xAD, 0x59, 0xEB, 0xE8,
  39204. 0x30, 0x82, 0xEA, 0xB6, 0x7D, 0x4A, 0xBD, 0x90,
  39205. 0x22, 0x9A, 0x5E, 0x93, 0xA0, 0xB5, 0x80, 0x97,
  39206. 0x7F, 0x08, 0x13, 0xCC, 0xB1, 0x5E, 0xCD, 0x74,
  39207. 0xFF, 0x71, 0x5F, 0xE8, 0xDB, 0x5B, 0x05, 0xCE,
  39208. 0xF3, 0x7D, 0x34, 0x93, 0xBE, 0xDA, 0x27, 0x05,
  39209. 0x84, 0x94, 0x4C, 0x02, 0x09, 0x86, 0x34, 0x51,
  39210. 0x4D, 0xAA, 0xCE, 0x70, 0x47, 0xE4, 0x74, 0x32,
  39211. 0xF9, 0x2A, 0xDC, 0xA4, 0x91, 0xA3, 0xE0, 0x96,
  39212. 0x1A, 0x5D, 0x9F, 0x01, 0x44, 0x85, 0x2E, 0x46,
  39213. 0x32, 0x63, 0x35, 0xE2, 0x15, 0x24, 0x3D, 0xAA,
  39214. 0xE8, 0x37, 0x92, 0x7F, 0xBF, 0xDC, 0xE6, 0x91,
  39215. 0xF4, 0x98, 0x59, 0x26, 0x6E, 0x90, 0x08, 0x16,
  39216. 0x8C, 0x6A, 0x5E, 0x2F, 0x60, 0x9C, 0x80, 0xC6,
  39217. 0x8E, 0x08, 0x20, 0xE7, 0x27, 0x19, 0xE9, 0xB5,
  39218. 0x87, 0x3F, 0xA1, 0x99, 0xE1, 0x97, 0xF9, 0xC4,
  39219. 0x94, 0xAA, 0x8A, 0x3A, 0x65, 0x26, 0x9E, 0x95,
  39220. 0xB7, 0x61, 0xB6, 0x7B, 0xEC, 0x61, 0x13, 0xC1,
  39221. 0x44, 0xA5, 0x69, 0x89, 0xC5, 0x75, 0x0D, 0x45,
  39222. 0x05, 0x42, 0xCC, 0xF8, 0x1B, 0x24, 0x62, 0x09,
  39223. 0x2F, 0x70, 0x71, 0x5D, 0x49, 0x14, 0xEB, 0x2C,
  39224. 0xAA, 0x31, 0x74, 0xBC, 0x9E, 0xEB, 0x20, 0xAA,
  39225. 0xB6, 0xC6, 0x40, 0xF8, 0xB5, 0xD9, 0xC6, 0xA0,
  39226. 0xDC, 0xC6, 0xF0, 0xAE, 0xC9, 0x7B, 0x3A, 0xF6,
  39227. 0x47, 0xEB, 0xF8, 0x00, 0x34, 0xA4, 0x3B, 0xF3,
  39228. 0x19, 0xBF, 0x40, 0xAD, 0xF7, 0x9A, 0xFE, 0xAB,
  39229. 0x58, 0x90, 0xD2, 0x02, 0x3B, 0xAE, 0x02, 0xC9,
  39230. 0xFD, 0x02, 0xC5, 0xBB, 0x65, 0x87, 0x9C, 0x1B,
  39231. 0x5E, 0xA4, 0x06, 0x02, 0x9A, 0xE7, 0x78, 0x45,
  39232. 0xCB, 0x99, 0x4D, 0xB8, 0xC3, 0x52, 0x11, 0xCA,
  39233. 0x1D, 0xC8, 0x81, 0xF7, 0xF2, 0x0A, 0x47, 0x06,
  39234. 0x50, 0x5F, 0x29, 0xD9, 0xCD, 0x19, 0x89, 0xAD,
  39235. 0x42, 0xB0, 0x7E, 0xF5, 0x2D, 0x96, 0x54, 0xE2,
  39236. 0x8E, 0x3D, 0xCB, 0x83, 0x00, 0x08, 0xA1, 0xBE,
  39237. 0x31, 0x99, 0x38, 0x7E, 0x06, 0x6B, 0x28, 0xB3,
  39238. 0x15, 0xCA, 0x19, 0x02, 0xF4, 0xBB, 0x0E, 0xE6,
  39239. 0x3F, 0xDC, 0x4C, 0x93, 0xE1, 0xAB, 0x88, 0x6F,
  39240. 0xD7, 0x42, 0x52, 0x61, 0xC3, 0x7A, 0xC5, 0x87,
  39241. 0x62, 0xD0, 0x3D, 0xB6, 0x07, 0x06, 0x88, 0x7E,
  39242. 0x72, 0xCF, 0x74, 0x5A, 0x44, 0x6D, 0xF6, 0xC6,
  39243. 0x66, 0x2F, 0x53, 0xDD, 0x61, 0x24, 0x71, 0xA4,
  39244. 0x34, 0xAC, 0x56, 0xC4, 0xBE, 0xDB, 0x3C, 0x9F,
  39245. 0x36, 0x47, 0xE6, 0x03, 0x2B, 0x3C, 0xC0, 0x99,
  39246. 0x0A, 0x3A, 0x2E, 0x87, 0x05, 0x2B, 0x36, 0xD4,
  39247. 0xA1, 0x62, 0x42, 0x4E, 0x2D, 0x39, 0x9E, 0x1B,
  39248. 0xC2, 0x37, 0x92, 0x8D, 0x0B, 0xD7, 0x71, 0x58,
  39249. 0x07, 0x9C, 0xCB, 0x20, 0x8B, 0x71, 0x95, 0x07,
  39250. 0x96, 0x55, 0xBD, 0xB7, 0x6C, 0xBA, 0xFF, 0x44,
  39251. 0x7C, 0x34, 0xC5, 0x82, 0x9F, 0xAC, 0x19, 0x9B,
  39252. 0xB0, 0x27, 0xA0, 0x80, 0x06, 0x50, 0x8D, 0x56,
  39253. 0xC8, 0x1D, 0x18, 0x70, 0x90, 0xE7, 0x10, 0x24,
  39254. 0xDB, 0x7F, 0xBF, 0x3A, 0x7D, 0x64, 0xD8, 0xFA,
  39255. 0x48, 0x74, 0xA8, 0xF4, 0x70, 0x37, 0x7B, 0x15,
  39256. 0x38, 0x00, 0x96, 0x82, 0x2F, 0xFE, 0x46, 0x55,
  39257. 0x71, 0xB5, 0x0C, 0x54, 0x05, 0x58, 0xBA, 0x50,
  39258. 0xE9, 0x0E, 0xB8, 0x14, 0x52, 0xF4, 0x12, 0x75,
  39259. 0xC2, 0x51, 0x5B, 0xAE, 0x05, 0x92, 0xD5, 0x3F,
  39260. 0x6A, 0x6A, 0x34, 0xD2, 0xA3, 0x4D, 0x8E, 0xAC,
  39261. 0x6E, 0x7A, 0x03, 0xFB, 0xDB, 0x52, 0x49, 0x4F,
  39262. 0x4B, 0x98, 0x1B, 0x56, 0xC0, 0x96, 0x26, 0x08,
  39263. 0x48, 0x50, 0xC7, 0xCF, 0x96, 0x2F, 0x93, 0x10,
  39264. 0x72, 0x25, 0x15, 0xA6, 0x2A, 0xC0, 0x85, 0xA6,
  39265. 0x18, 0x9A, 0xDD, 0xEA, 0x38, 0x12, 0x91, 0x13,
  39266. 0x57, 0x31, 0xB2, 0xEE, 0x83, 0xA4, 0xF1, 0xEB,
  39267. 0xFA, 0x09, 0xAF, 0x80, 0xA9, 0x12, 0x68, 0xA8,
  39268. 0x76, 0x23, 0xCB, 0x55, 0x7C, 0x9F, 0x66, 0xDE,
  39269. 0xB4, 0x54, 0xFB, 0x2F, 0x4F, 0xC2, 0x64, 0x8F,
  39270. 0x44, 0x41, 0x5A, 0x7B, 0xEF, 0x29, 0x96, 0x2D,
  39271. 0x5F, 0x7C, 0x16, 0xE7, 0x85, 0x79, 0xF5, 0x26,
  39272. 0xDD, 0x20, 0xE9, 0x20, 0x9B, 0x6C, 0xA6, 0xDF,
  39273. 0xD1, 0x30, 0xF9, 0x2E, 0xF7, 0x24, 0x64, 0x5B,
  39274. 0x5B, 0x84, 0xD8, 0x72, 0x4F, 0x3C, 0xF6, 0xF3,
  39275. 0xA3, 0xB2, 0xA9, 0xCF, 0x61, 0x24, 0x7A, 0x54,
  39276. 0xBA, 0x92, 0x8F, 0x53, 0xEA, 0xCB, 0xA7, 0xE6,
  39277. 0xD6, 0xB8, 0x12, 0xC4, 0xCE, 0x21, 0xA1, 0x8B,
  39278. 0xA8, 0xD1, 0x14, 0x50, 0xE7, 0x04, 0x89, 0xBA,
  39279. 0x57, 0x2E, 0x5E, 0xB9, 0xA7, 0x72, 0x2D, 0x9D,
  39280. 0xC6, 0xAA, 0xE4, 0xF9, 0x57, 0x93, 0x60, 0x09,
  39281. 0xE2, 0x6E, 0xB3, 0xE7, 0x4D, 0x9F, 0x99, 0x33,
  39282. 0xF3, 0xDB, 0x4D, 0xA0, 0xA1, 0xF5, 0x44, 0x93,
  39283. 0x99, 0xB5, 0xE1, 0x01, 0x03, 0x11, 0xF8, 0x7D,
  39284. 0x92, 0xC1, 0x87, 0xAD, 0x2E, 0xFA, 0xBB, 0x0A,
  39285. 0x2C, 0x86, 0xB7, 0xD7, 0xF9, 0xA0, 0x72, 0xAB,
  39286. 0xC0, 0xC6, 0x60, 0x6D, 0xBC, 0xD9, 0x20, 0x17,
  39287. 0x7A, 0x22, 0x57, 0x20, 0xA7, 0x05, 0x76, 0xB8,
  39288. 0xE8, 0x2D, 0x7D, 0x53, 0xC1, 0xDF, 0xA4, 0x8E,
  39289. 0xA7, 0x31, 0x81, 0xAF, 0x0A, 0xF0, 0x86, 0xB6,
  39290. 0xAA, 0xF8, 0x0A, 0xB2, 0x49, 0x81, 0xF2, 0x75,
  39291. 0xD6, 0x6D, 0x4F, 0xBD, 0xE2, 0xC5, 0x1A, 0xE8,
  39292. 0xE8, 0xD4, 0x58, 0x33, 0x72, 0x9F, 0x45, 0x03,
  39293. 0x01, 0x30, 0xBC, 0x85, 0xB2, 0xBD, 0x9A, 0x14,
  39294. 0xC8, 0x13, 0xA3, 0x7F, 0x1F, 0xA1, 0x47, 0xF8,
  39295. 0x15, 0x48, 0x8D, 0x7A, 0x17, 0xC0, 0xC0, 0x39,
  39296. 0xEA, 0xF8, 0x66, 0xCE, 0xA7, 0x5F, 0x5B, 0x2E,
  39297. 0xBE, 0x05, 0xEF, 0x31, 0x09, 0x47, 0x2B, 0xA5,
  39298. 0xF7, 0xCF, 0xCE, 0x4C, 0x35, 0x8B, 0x60, 0x80,
  39299. 0x40, 0x0C, 0x5C, 0xC0, 0x85, 0x15, 0x14, 0x92,
  39300. 0xD1, 0x3A, 0x5B, 0x00, 0x96, 0xA0, 0x63, 0x1F,
  39301. 0xAA, 0x30, 0xCB, 0x48, 0xF2, 0xDA, 0x87, 0x3B,
  39302. 0x85, 0x7D, 0xFD, 0xB3, 0x86, 0xD9, 0x33, 0x98,
  39303. 0x18, 0x07, 0x34, 0x92, 0x55, 0x9A, 0x0E, 0xC2,
  39304. 0xDA, 0xF3, 0x73, 0x8E, 0x15, 0x88, 0xB0, 0x98,
  39305. 0x75, 0x1F, 0xF0, 0xFA, 0x1C, 0x87, 0x1B, 0x22,
  39306. 0x23, 0x7E, 0x5C, 0xD1, 0x5B, 0x0E, 0x17, 0x28,
  39307. 0xEA, 0x26, 0x71, 0x66, 0xC3, 0x8A, 0x71, 0x97,
  39308. 0xB6, 0xCC, 0x7D, 0xAD, 0x39, 0x11, 0x6B, 0xE6,
  39309. 0x1D, 0xF4, 0x33, 0x3C, 0xD7, 0xC2, 0xA4, 0x13,
  39310. 0xDB, 0x30, 0x63, 0xD7, 0xF0, 0x22, 0x8C, 0x61,
  39311. 0xFA, 0xDA, 0xC3, 0xF8, 0xC3, 0x31, 0xF4, 0x45,
  39312. 0x09, 0xB4, 0xD6, 0x08, 0x53, 0x1F, 0x99, 0x5D,
  39313. 0x15, 0xFA, 0xB1, 0x19, 0xD8, 0x47, 0xE6, 0xD8,
  39314. 0x54, 0x95, 0x75, 0xB7, 0xD8, 0x50, 0xB2, 0x60,
  39315. 0x0E, 0x4D, 0x13, 0x64, 0x6C, 0xF9, 0x6B, 0x6B,
  39316. 0x9D, 0xA6, 0xC6, 0x2F, 0x2A, 0x80, 0xAE, 0x02,
  39317. 0x58, 0xA8, 0xCD, 0x6E, 0xF4, 0xC5, 0x5E, 0xEA,
  39318. 0x7E, 0x78, 0xD2, 0x0A, 0x46, 0x4A, 0x19, 0x4C,
  39319. 0xEC, 0xBB, 0x01, 0xE7, 0x3F, 0x32, 0x76, 0xD6,
  39320. 0x6E, 0x12, 0xAD, 0x37, 0x74, 0x51, 0xBB, 0xB9,
  39321. 0x4E, 0x5C, 0x94, 0x88, 0x32, 0x59, 0x5F, 0x6B,
  39322. 0x6E, 0x38, 0x2A, 0xD1, 0x42, 0xD9, 0xF1, 0xB8,
  39323. 0x68, 0x97, 0x95, 0xE9, 0xEB, 0xC3, 0x2A, 0x5A,
  39324. 0x10, 0x1E, 0x69, 0x6C, 0xA3, 0x4A, 0xBA, 0x00,
  39325. 0x5B, 0x4C, 0xED, 0xA2, 0x7D, 0x12, 0x00, 0xFE,
  39326. 0x48, 0xFD, 0x82, 0xC1, 0x72, 0x17, 0xE5, 0x08,
  39327. 0xA8, 0x48, 0x4F, 0x03, 0x88, 0x34, 0x5C, 0x9D,
  39328. 0xED, 0xE2, 0xA1, 0x39, 0x28, 0xFA, 0xC3, 0x29,
  39329. 0x21, 0x84, 0x2F, 0x6E, 0x6A, 0xA5, 0xCF, 0xBF,
  39330. 0x57, 0xFA, 0xA2, 0x8F, 0x43, 0xE0, 0x5E, 0x9A,
  39331. 0x45, 0x23, 0x12, 0x50, 0x29, 0x11, 0xEF, 0x9C,
  39332. 0x33, 0xC8, 0x11, 0xEB, 0xE7, 0xCA, 0xD7, 0x30,
  39333. 0x62, 0x3D, 0xB7, 0x04, 0x8E, 0xC2, 0x18, 0xC7,
  39334. 0xEA, 0x9D, 0xFC, 0x6E, 0x19, 0x65, 0xA9, 0x85,
  39335. 0x7E, 0x92, 0x94, 0xC4, 0xE4, 0x7F, 0x4D, 0x96,
  39336. 0x23, 0xCB, 0x74, 0xB6, 0x5F, 0x7B, 0xB5, 0x86,
  39337. 0x22, 0x83, 0x8D, 0xC4, 0x4E, 0x16, 0xD9, 0x15,
  39338. 0xD9, 0x59, 0x65, 0x55, 0xCA, 0x3D, 0x26, 0x1C,
  39339. 0x9C, 0x2A, 0xFC, 0xCB, 0xAF, 0x5A, 0xC0, 0x3D,
  39340. 0xE0, 0x91, 0xF0, 0xDB, 0xEA, 0xE1, 0xB4, 0xA7,
  39341. 0xE3, 0xDE, 0xC4, 0x39, 0x09, 0x89, 0x67, 0x65,
  39342. 0x77, 0xA0, 0x53, 0x68, 0x4F, 0x57, 0x86, 0x8D,
  39343. 0x91, 0xFE, 0x6A, 0x5B, 0x7D, 0x3D, 0x7C, 0x79,
  39344. 0x50, 0x78, 0x9E, 0x89, 0xD8, 0x38, 0x83, 0xBC,
  39345. 0x3D, 0xAE, 0x55, 0xCA, 0x30, 0x78, 0xB0, 0x8D,
  39346. 0x99, 0x18, 0x31, 0xBA, 0x91, 0x50, 0x2A, 0x5A,
  39347. 0x33, 0x54, 0xB8, 0x8E, 0x15, 0x9B, 0x0A, 0xFF,
  39348. 0xD2, 0x5B, 0x0D, 0xBB, 0x72, 0xBC, 0xD6, 0xF4,
  39349. 0x04, 0x65, 0xDD, 0xFC, 0x00, 0xFF, 0x8B, 0x63,
  39350. 0x39, 0xC0, 0x67, 0x09, 0x5D, 0x6C, 0x7C, 0xB0,
  39351. 0x6F, 0x3B, 0xE7, 0x59, 0xC5, 0x27, 0x40, 0x39,
  39352. 0x5D, 0xD1, 0x08, 0x29, 0x6F, 0x2B, 0xBC, 0x2E,
  39353. 0x7A, 0x5D, 0xDD, 0xE3, 0xD1, 0xC3, 0x5D, 0x18,
  39354. 0xBF, 0xBE, 0x39, 0x68, 0xEC, 0x59, 0xAB, 0xF8,
  39355. 0x5C, 0x1B, 0xD2, 0x92, 0x8A, 0xB2, 0xAA, 0x67,
  39356. 0x8A, 0x78, 0x91, 0x74, 0x6E, 0x88, 0xF4, 0x39,
  39357. 0xF8, 0xB4, 0x38, 0x40, 0x31, 0xC3, 0xED, 0xB7,
  39358. 0x31, 0x97, 0xE5, 0x2A, 0x4E, 0x77, 0x3D, 0x2D,
  39359. 0x8B, 0x7B, 0xAD, 0xDC, 0x5D, 0xD0, 0xA7, 0xE4,
  39360. 0x4C, 0x80, 0x8D, 0x73, 0xB8, 0x18, 0x1D, 0x19,
  39361. 0x1C, 0x3C, 0x89, 0xFE, 0x15, 0xEA, 0x90, 0xD7,
  39362. 0x56, 0x7E, 0x89, 0x16, 0xA3, 0x37, 0x83, 0x03,
  39363. 0x05, 0x04, 0x1B, 0x1E, 0x94, 0xB3, 0xB4, 0x06,
  39364. 0xDA, 0x4C, 0x36, 0xBE, 0xF0, 0x5D, 0x91, 0x00,
  39365. 0xAB, 0x99, 0x2A, 0x4D, 0x56, 0x25, 0x33, 0x73,
  39366. 0x0E, 0x0D, 0x8C, 0x05, 0x2B, 0x3A, 0x62, 0xD3,
  39367. 0xF6, 0x9A, 0x83, 0xA0, 0xC9, 0xB2, 0x12, 0x4F,
  39368. 0x12, 0xAE, 0x7D, 0xAC, 0xC9, 0x78, 0xC4, 0xA0,
  39369. 0xAD, 0xCC, 0x2E, 0xBA, 0x2D, 0x80, 0xF4, 0x94,
  39370. 0xAA, 0x16, 0xEC, 0x1E, 0x8E, 0x71, 0xC7, 0x9B,
  39371. 0x02, 0xF3, 0x26, 0x1B, 0x6F, 0x98, 0x68, 0xB8,
  39372. 0xD5, 0x7E, 0x9D, 0x16, 0xF4, 0x2B, 0x7C, 0xC6,
  39373. 0x64, 0x06, 0x54, 0x9A, 0x27, 0x6D, 0x37, 0x14,
  39374. 0x37, 0xDE, 0x88, 0xB7, 0xF3, 0x9E, 0x74, 0x08,
  39375. 0x7C, 0xBB, 0xC5, 0x61, 0x16, 0x80, 0x31, 0x2D,
  39376. 0xE8, 0xF0, 0xC3, 0x68, 0x14, 0xE1, 0x74, 0xF9,
  39377. 0x1E, 0xB6, 0x00, 0xCC, 0x96, 0xE3, 0xCF, 0x51,
  39378. 0xBB, 0x20, 0x25, 0x88, 0x77, 0xA2, 0xAA, 0xEB,
  39379. 0x82, 0x7F, 0x7F, 0x5A, 0xDA, 0x80, 0x78, 0x6B,
  39380. 0x50, 0x84, 0xC8, 0x02, 0xE6, 0x06, 0xDE, 0xF3,
  39381. 0x88, 0xA3, 0x9C, 0xE4, 0xF0, 0xD5, 0xBC, 0x19,
  39382. 0x39, 0x4C, 0xE8, 0x41, 0xE2, 0xD2, 0xAA, 0x74,
  39383. 0x25, 0x23, 0x05, 0x80, 0xFA, 0x66, 0x75, 0xC5,
  39384. 0x17, 0x41, 0xD1, 0x75, 0x87, 0x9B, 0x4D, 0x03,
  39385. 0xC3, 0x90, 0xF6, 0x52, 0xA5, 0x03, 0xA7, 0x51,
  39386. 0x6A, 0x1F, 0x07, 0x5E, 0x30, 0x82, 0xD5, 0x2C,
  39387. 0x60, 0xB8, 0x64, 0x2A, 0x82, 0x40, 0xEE, 0x94,
  39388. 0x4D, 0x5F, 0xB4, 0x27, 0x37, 0x6B, 0x40, 0xB0,
  39389. 0xB2, 0x82, 0xE1, 0x9A, 0xB9, 0x08, 0xCC, 0xF2,
  39390. 0x0C, 0xA9, 0x26, 0x11, 0x64, 0x90, 0xAF, 0xED,
  39391. 0x57, 0xEA, 0xD0, 0xDC, 0x0C, 0x8E, 0x29, 0x6C,
  39392. 0x79, 0xA4, 0x8D, 0x08, 0x8E, 0x83, 0x7A, 0xF0,
  39393. 0x67, 0xDC, 0x02, 0x9E, 0xC6, 0x31, 0xF9, 0x93,
  39394. 0x3E, 0xE4, 0xD2, 0x07, 0x46, 0xE6, 0x4E, 0x5F,
  39395. 0x21, 0x67, 0x55, 0xA1, 0x38, 0x97, 0x4D, 0x30,
  39396. 0x82, 0x93, 0x73, 0x6D, 0xC1, 0x86, 0x04, 0x27,
  39397. 0x6C, 0xC4, 0x18, 0xBA, 0x69, 0xF8, 0x72, 0xB5,
  39398. 0x8E, 0x7F, 0x6E, 0x3A, 0x8B, 0x84, 0x6E, 0xBA,
  39399. 0xAE, 0xB3, 0x83, 0xE7, 0xF8, 0x90, 0xF5, 0x4E,
  39400. 0x77, 0xF5, 0xD7, 0xF5, 0xD4, 0xA5, 0x8D, 0xB7,
  39401. 0x83, 0xEC, 0xA0, 0x49, 0xF1, 0x86, 0x17, 0x12,
  39402. 0x82, 0xBA, 0xC2, 0x60, 0x7D, 0x51, 0xB2, 0x98,
  39403. 0xB1, 0x49, 0x38, 0xEF, 0xB1, 0x92, 0x8F, 0xC8,
  39404. 0xD0, 0x78, 0x06, 0xE8, 0xC3, 0xE7, 0x3B, 0x46,
  39405. 0x46, 0xBC, 0xF1, 0x68, 0x90, 0xCC, 0x13, 0x80,
  39406. 0xE7, 0xB6, 0x33, 0x50, 0x2B, 0x3E, 0xAD, 0xA4,
  39407. 0x47, 0x75, 0x02, 0xE2, 0x46, 0x7C, 0xFD, 0xB9,
  39408. 0xAC, 0xBD, 0x1C, 0x72, 0xBC, 0x6A, 0xEB, 0x4F,
  39409. 0x41, 0xE1, 0xC2, 0x3C, 0x63, 0x68, 0x39, 0xE3,
  39410. 0x57, 0x13, 0x5F, 0x76, 0xBC, 0x39, 0xC4, 0xF9,
  39411. 0xAC, 0x1C, 0xE8, 0xF1, 0xBE, 0xEF, 0xEB, 0xFF,
  39412. 0x87, 0x59, 0xE8, 0xF7, 0x19, 0x65, 0xD4, 0x85,
  39413. 0x4B, 0xEA, 0xAD, 0x0A, 0xFE, 0xDC, 0xA9, 0xD4,
  39414. 0xD6, 0xBD, 0x1E, 0x63, 0xD3, 0x48, 0xA4, 0x2C,
  39415. 0xEE, 0xFF, 0xC1, 0x70, 0xD0, 0xEE, 0x9F, 0x13,
  39416. 0x6F, 0x5B, 0xE9, 0x90, 0x14, 0x66, 0x92, 0x61,
  39417. 0x22, 0xF9, 0x48, 0xBD, 0xDE, 0x2A, 0x91, 0x07,
  39418. 0xD2, 0xA9, 0x8B, 0xA2, 0xDE, 0xA6, 0xD6, 0xF2,
  39419. 0xDA, 0x17, 0x72, 0x47, 0x02, 0xEC, 0x51, 0x8C,
  39420. 0x03, 0x75, 0x3D, 0x51, 0xEA, 0x83, 0x1E, 0x95,
  39421. 0xCB, 0x87, 0x08, 0xD5, 0xDE, 0xC8, 0x22, 0xDB,
  39422. 0x73, 0x7E, 0x44, 0x14, 0x3C, 0x86, 0xF4, 0x71,
  39423. 0x77, 0xD8, 0x5C, 0xD0, 0x98, 0xC2, 0x1B, 0x9B,
  39424. 0xC8, 0x00, 0xDF, 0xA9, 0xDC, 0x26, 0xFD, 0xC2,
  39425. 0x61, 0xE9, 0x21, 0xDE, 0x00, 0x2D, 0x81, 0xC1,
  39426. 0x59, 0xF8, 0xEB, 0x1F, 0xEE, 0x67, 0x67, 0x9D,
  39427. 0x62, 0x1E, 0xCE, 0x6B, 0x36, 0xD0, 0x1C, 0x77,
  39428. 0x5A, 0x16, 0x45, 0xD5, 0x22, 0x92, 0xB4, 0xB2,
  39429. 0xB8, 0x22, 0x73, 0x18, 0x77, 0x2A, 0x80, 0x91,
  39430. 0xE9, 0xEC, 0x01, 0x70, 0x13, 0xB1, 0x95, 0xEB,
  39431. 0xF4, 0xEF, 0x20, 0x1F, 0x4E, 0x88, 0x1C, 0x49,
  39432. 0x36, 0x33, 0xC0, 0x7F, 0x27, 0xC9, 0x79, 0x0D,
  39433. 0xD8, 0xAE, 0xCC, 0x94, 0x49, 0xCF, 0x63, 0xBC,
  39434. 0xB1, 0x19, 0x46, 0x16, 0x9A, 0xCF, 0xF3, 0x95,
  39435. 0x42, 0x26, 0x6B, 0x0C, 0x66, 0x85, 0xBB, 0xB0,
  39436. 0x80, 0xB5, 0x9F, 0x11, 0x7E, 0xEB, 0x2A, 0x73,
  39437. 0x38, 0x2B, 0x3D, 0x18, 0x7C, 0x06, 0x80, 0xC5,
  39438. 0xAE, 0x70, 0x90, 0x70, 0xDF, 0x03, 0xA0, 0x08,
  39439. 0xA7, 0xAD, 0x13, 0x22, 0x6F, 0x3C, 0x37, 0x15,
  39440. 0x39, 0x20, 0x52, 0xF2, 0x44, 0x1B, 0x4A, 0x17,
  39441. 0x8D, 0x7C, 0xF7, 0x05, 0x18, 0x33, 0x9C, 0xFF,
  39442. 0xBB, 0x54, 0xA6, 0xD9, 0xB9, 0xCD, 0xE3, 0xB0,
  39443. 0xB5, 0x7D, 0xBC, 0x79, 0xF4, 0xE4, 0x7A, 0xD6,
  39444. 0x27, 0x4C, 0xE2, 0x18, 0x0C, 0x92, 0xAC, 0x64,
  39445. 0x10, 0xE5, 0x0D, 0x05, 0xF6, 0x66, 0x5A, 0x57,
  39446. 0xD4, 0xD4, 0x47, 0x6C, 0x2C, 0x0E, 0x6E, 0xE0,
  39447. 0x75, 0x7A, 0x3A, 0xFE, 0xA2, 0xB1, 0xBF, 0x86,
  39448. 0xA5, 0x51, 0xEF, 0x98, 0xAA, 0x1D, 0xFC, 0xBA,
  39449. 0x96, 0x31, 0x59, 0x59, 0x45, 0x2B, 0x2B, 0x3A,
  39450. 0x2F, 0xCB, 0xBB, 0x95, 0x5C, 0xB3, 0xFA, 0x1E,
  39451. 0xEB, 0xBB, 0x83, 0xBD, 0x17, 0x87, 0x67, 0xC0,
  39452. 0x2E, 0xFB, 0xBE, 0xFF, 0x6C, 0x7E, 0xEF, 0x94,
  39453. 0xB5, 0x5D, 0xF8, 0x83, 0x1D, 0xDF, 0xB7, 0xB2,
  39454. 0x02, 0xCE, 0x7D, 0xE0, 0x55, 0xEA, 0xF9, 0x92,
  39455. 0x8A, 0xDA, 0xF6, 0xED, 0x0E, 0x31, 0x59, 0xCA,
  39456. 0x56, 0xC4, 0x83, 0xFA, 0x3B, 0xA3, 0xD2, 0x47,
  39457. 0x8C, 0xA3, 0x94, 0x82, 0x4C, 0xEE, 0x6A, 0xBD,
  39458. 0x59, 0x67, 0x09, 0x53, 0xEE, 0x80, 0xD3, 0x83,
  39459. 0xAA, 0xA6, 0x08, 0xE1, 0x58, 0x51, 0x13, 0x5C,
  39460. 0x1C, 0xDE, 0xEE, 0xB5, 0xF6, 0xA8, 0x89, 0x7C,
  39461. 0x3C, 0x9E, 0x06, 0x6A, 0xB4, 0x73, 0x4F, 0xDD,
  39462. 0xFA, 0xBC, 0x3B, 0xC3, 0xBA, 0x12, 0x06, 0xBA,
  39463. 0x54, 0x34, 0xDC, 0xDE, 0xDB, 0x9D, 0x8B, 0x3A,
  39464. 0x81, 0xA2, 0xE6, 0x38, 0x14, 0x6D, 0x83, 0xF1,
  39465. 0x4F, 0x06, 0xE5, 0x60, 0x99, 0xC0, 0xC8, 0xA0,
  39466. 0xFC, 0xCD, 0xB9, 0xEC, 0xF0, 0xF3, 0xD8, 0x8D,
  39467. 0xE3, 0x79, 0x2F, 0x2D, 0x0B, 0x65, 0x1B, 0x61,
  39468. 0x9C, 0x57, 0x1B, 0x69, 0xF4, 0xBF, 0x8E, 0x7C,
  39469. 0xD1, 0x91, 0x0F, 0x26, 0x6A, 0x4D, 0xAD, 0xF8,
  39470. 0xC2, 0xAB, 0xB4, 0xAC, 0x05, 0xBD, 0x1F, 0xBA,
  39471. 0x05, 0x8C, 0x03, 0x94, 0xC0, 0x16, 0xDE, 0xE6,
  39472. 0x0C, 0x66, 0x40, 0x1A, 0x17, 0xD1, 0x34, 0x59,
  39473. 0x54, 0x79, 0x33, 0x38, 0x9A, 0x35, 0x65, 0x69,
  39474. 0xAD, 0xA5, 0x32, 0xC9, 0xF4, 0x87, 0x69, 0x88,
  39475. 0x55, 0xA4, 0xD7, 0xBC, 0xCD, 0x0E, 0xF6, 0x95,
  39476. 0x31, 0x09, 0x4D, 0xA4, 0x08, 0x6F, 0x52, 0xBF,
  39477. 0x98, 0xCD, 0xC9, 0xA4, 0xB0, 0xBC, 0x88, 0x8D,
  39478. 0xC3, 0x89, 0x1A, 0x76, 0x09, 0x6C, 0x7C, 0x48,
  39479. 0x34, 0x90, 0xE9, 0x52, 0x32, 0x6A, 0xE4, 0x02,
  39480. 0xD8, 0xDF, 0xD2, 0xF3, 0xDC, 0xCF, 0x1A, 0xA5,
  39481. 0xD7, 0xBD, 0x69, 0x8E, 0x2A, 0xA8, 0x8D, 0x29,
  39482. 0x48, 0x13, 0xA8, 0x8F, 0xD3, 0x18, 0x66, 0xBC,
  39483. 0xA1, 0x1B, 0x3B, 0x91, 0xC0, 0x09, 0xEE, 0xB6,
  39484. 0x67, 0x60, 0x1C, 0xEE, 0xAF, 0xAF, 0xE9, 0x7C,
  39485. 0x56, 0xFA, 0x33, 0xF9, 0x38, 0x1F, 0x3E, 0x43,
  39486. 0x29, 0x90, 0x1A, 0xC3, 0xB7, 0xEA, 0x70, 0x32,
  39487. 0xC0, 0x19, 0xE5, 0xC8, 0xA8, 0xEF, 0xD7, 0x04,
  39488. 0x4C, 0x97, 0x36, 0x44, 0xAF, 0x2B, 0xE4, 0x20,
  39489. 0xA0, 0x33, 0xC6, 0xC2, 0xC7, 0xCE, 0x0C, 0xEA,
  39490. 0x39, 0x34, 0xDC, 0x18, 0xB4, 0x2A, 0xDF, 0xD7,
  39491. 0xA8, 0x46, 0xF4, 0x2D, 0xD4, 0x06, 0x86, 0x6A,
  39492. 0x39, 0x09, 0x29, 0x02, 0x6A, 0xDE, 0x5C, 0x79,
  39493. 0x1B, 0x5F, 0x61, 0xF9, 0x42, 0xB1, 0x55, 0x07,
  39494. 0x7D, 0x82, 0xF2, 0xAF, 0xCC, 0xFF, 0xF8, 0x5B,
  39495. 0x04, 0x06, 0x64, 0x7A, 0x96, 0x27, 0xE3, 0x69,
  39496. 0x5D, 0x4B, 0xEA, 0x3D, 0x58, 0xA6, 0x3E, 0x17,
  39497. 0x18, 0xD1, 0x84, 0xE4, 0x6B, 0x5F, 0x4B, 0xC8,
  39498. 0x41, 0x03, 0x34, 0xA4, 0x09, 0x5D, 0x0F, 0xAF,
  39499. 0x30, 0x6F, 0xB9, 0xDC, 0x10, 0x94, 0x25, 0xC3,
  39500. 0x16, 0x52, 0xD0, 0x6F, 0xF0, 0x51, 0xA1, 0x62,
  39501. 0xEE, 0x2B, 0x7B, 0x1C, 0x54, 0xD6, 0xC7, 0xDE,
  39502. 0xD6, 0xE3, 0x95, 0xAA, 0xD1, 0xA8, 0x6D, 0x03,
  39503. 0xB1, 0xB6, 0xC8, 0x00, 0x76, 0x7E, 0xC1, 0x44,
  39504. 0x12, 0xEE, 0xCE, 0x13, 0x46, 0x20, 0xA6, 0x1D,
  39505. 0x36, 0x9A, 0xF4, 0x9E, 0x21, 0xB0, 0xD1, 0x4B,
  39506. 0xC4, 0x23, 0x06, 0x49, 0xCD, 0xD3, 0xE9, 0xFD,
  39507. 0x84, 0x7A, 0xE5, 0x0B, 0xE9, 0x62, 0xEF, 0xC8,
  39508. 0xCB, 0x0F, 0x33, 0x9F, 0x9E, 0x6D, 0x32, 0x47,
  39509. 0x53, 0x3B, 0xDE, 0xD8, 0x71, 0x1D, 0x46, 0x1D,
  39510. 0x4A, 0xF2, 0xAE, 0x3F, 0xDD, 0x1D, 0x7D, 0x2A,
  39511. 0x28, 0x9C, 0x78, 0xCB, 0x19, 0xF3, 0xCD, 0xC2,
  39512. 0x14, 0x2B, 0xF5, 0x2B, 0x23, 0xE6, 0xA2, 0x7B,
  39513. 0x39, 0xD6, 0x99, 0x54, 0x3C, 0x3D, 0x63, 0x9B,
  39514. 0x9C, 0x72, 0xCA, 0x80, 0xB3, 0x7E, 0xA2, 0x77,
  39515. 0x5B, 0x5E, 0x26, 0x81, 0xF0, 0xDD, 0x01, 0xDF,
  39516. 0xF0, 0xC0, 0x55, 0x13, 0x36, 0x90, 0x62, 0xFE
  39517. };
  39518. static const byte msg_87[] = {
  39519. 0x9E, 0xFF, 0x34, 0x15, 0x06, 0xD1, 0x8B, 0xCB,
  39520. 0x27, 0xA7, 0xFC, 0x4E, 0xAA, 0xBF, 0x5A, 0x7C,
  39521. 0x4A, 0x59, 0x37, 0x77, 0x19, 0x6F, 0x66, 0x4B,
  39522. 0xCE, 0x31, 0x6C, 0x95, 0x5B, 0x83, 0x5A, 0xD4,
  39523. 0xC9, 0xF5, 0xDE, 0x9A, 0x2B, 0xF8, 0x96, 0x15,
  39524. 0xDA, 0xCB, 0x9C, 0x1E, 0x61, 0x8C, 0x78, 0xE7,
  39525. 0x11, 0x44, 0xCD, 0x4B, 0x70, 0x46, 0xF4, 0x7D,
  39526. 0x9A, 0x60, 0x0E, 0x9C, 0xE6, 0x65, 0x96, 0xC4,
  39527. 0xC5, 0x5E, 0xDA, 0x23, 0xA6, 0x6C, 0xC1, 0x18,
  39528. 0xA4, 0xA7, 0xBD, 0x0D, 0xED, 0x00, 0xAB, 0xDD,
  39529. 0xCE, 0x53, 0xFB, 0xF2, 0x48, 0x20, 0x33, 0xA4,
  39530. 0x18, 0x85, 0x06, 0xEC, 0x11, 0x3B, 0xBD, 0x98,
  39531. 0xD9, 0x89, 0x1F, 0x0D, 0x69, 0x46, 0x3A, 0x0D,
  39532. 0x36, 0x15, 0x6B, 0xA3, 0xEA, 0x0D, 0x02, 0xA1,
  39533. 0x4C, 0x1F, 0xD7, 0xA3, 0xFE, 0x70, 0x4E, 0xE5,
  39534. 0x6B, 0x44, 0x6A, 0xE1, 0x79, 0xF7, 0x2E, 0x10,
  39535. 0x4A, 0xA8, 0x1A, 0xF0, 0xA2, 0xF8, 0xFC, 0xA6,
  39536. 0xF6, 0xF9, 0x62, 0x96, 0x05, 0x9E, 0xE8, 0x82,
  39537. 0x66, 0x80, 0xE4, 0x3F, 0x4B, 0x07, 0x40, 0xF4,
  39538. 0x7A, 0xC1, 0x05, 0x66, 0xED, 0x31, 0x07, 0x99,
  39539. 0xAC, 0x71, 0x41, 0xD3, 0x8F, 0x69, 0x21, 0x31,
  39540. 0x5F, 0x23, 0xAB, 0x3E, 0x64, 0xC8, 0xA7, 0x70,
  39541. 0xAA, 0x57, 0x12, 0x80, 0x90, 0xDB, 0x82, 0x8C,
  39542. 0x7B, 0xAA, 0x59, 0xC3, 0x29, 0x5C, 0xCA, 0xA2,
  39543. 0x38, 0xC7, 0x5F, 0xAC, 0x0F, 0x93, 0xDA, 0x79,
  39544. 0x00, 0x74, 0x1B, 0xCD, 0x94, 0xBB, 0x9F, 0xD3,
  39545. 0x85, 0x2E, 0xC2, 0xB7, 0xD3, 0x3F, 0x60, 0x0B,
  39546. 0x1D, 0x51, 0x66, 0x6A, 0xE2, 0x22, 0xA5, 0x7A,
  39547. 0xF1, 0x40, 0xFA, 0x04, 0x9C, 0x2C, 0x9F, 0x6D,
  39548. 0x0F, 0xE6, 0xC0, 0xF1, 0xE7, 0xA0, 0xDD, 0xE1,
  39549. 0x14, 0x3B, 0xE5, 0xCE, 0xD7, 0xBB, 0xE2, 0x32,
  39550. 0xCB, 0xFB, 0xD8, 0xAE, 0x00, 0xEA, 0x5F, 0xC1,
  39551. 0x65, 0x02, 0x6D, 0x72, 0x9D, 0xB3, 0x0F, 0x6A,
  39552. 0xFD, 0x99, 0x73, 0xB6, 0x72, 0x2C, 0x07, 0xF6,
  39553. 0x00, 0x66, 0x54, 0x41, 0xE3, 0x0B, 0x7C, 0x5F,
  39554. 0xB2, 0x97, 0xB8, 0xAB, 0x96, 0x9C, 0x06, 0x83,
  39555. 0x9D, 0x33, 0x1D, 0xEE, 0x96, 0xDE, 0x48, 0x68,
  39556. 0x7D, 0xC9, 0xDA, 0x53, 0x1A, 0x95, 0xCA, 0x83,
  39557. 0xA7, 0x6F, 0x4B, 0x07, 0x6D, 0xFC, 0xF4, 0x83,
  39558. 0xF0, 0x04, 0x50, 0xE5, 0x1C, 0x8D, 0x34, 0xD8,
  39559. 0xED, 0x8E, 0x4B, 0x3D, 0xAF, 0xAE, 0x66, 0x4B,
  39560. 0x6D, 0xC1, 0x3E, 0xD8, 0x8E, 0x6D, 0x63, 0x02,
  39561. 0x7D, 0xD4, 0x38, 0xCB, 0x74, 0xF4, 0x12, 0xE8,
  39562. 0x70, 0xCC, 0x9D, 0xFD, 0x29, 0xB5, 0x2A, 0xBC,
  39563. 0xA1, 0x69, 0xC1, 0x7E, 0x97, 0x47, 0x58, 0xE0,
  39564. 0x3A, 0xC0, 0xFB, 0x7F, 0xE5, 0x64, 0x50, 0x8E,
  39565. 0x01, 0x7A, 0x9B, 0x47, 0x49, 0xD6, 0x41, 0xAF,
  39566. 0x0D, 0xE3, 0x84, 0x08, 0x8F, 0xA0, 0x0C, 0x69,
  39567. 0x40, 0x23, 0x3D, 0xDE, 0xFB, 0x65, 0x7C, 0x18,
  39568. 0x1C, 0x82, 0xA1, 0xB6, 0xA3, 0x1F, 0xCC, 0xF4,
  39569. 0xD5, 0x2C, 0x9D, 0x35, 0x1E, 0x6B, 0xDF, 0xDF,
  39570. 0x48, 0xBC, 0xE4, 0x14, 0x60, 0x74, 0x62, 0xDB,
  39571. 0x76, 0x9F, 0x9E, 0xB1, 0x59, 0x25, 0xBA, 0x9F,
  39572. 0xAF, 0xBA, 0xB2, 0x29, 0xB5, 0x89, 0x6B, 0xF1,
  39573. 0xF8, 0xE4, 0x7D, 0xF1, 0x7C, 0x82, 0x08, 0xDF,
  39574. 0xD5, 0x96, 0x04, 0xB6, 0x05, 0x2C, 0xD2, 0xCE,
  39575. 0xAB, 0x56, 0x40, 0x0F, 0x11, 0xC4, 0xD9, 0x52,
  39576. 0x1E, 0x1A, 0xB8, 0x27, 0x4A, 0xB5, 0x76, 0x4C,
  39577. 0x73, 0xE9, 0x41, 0x32, 0x42, 0x0E, 0x32, 0xB6,
  39578. 0xAE, 0xB0, 0x76, 0x33, 0x78, 0xD9, 0xBA, 0x68,
  39579. 0xE1, 0xFC, 0xDE, 0x2B, 0xD6, 0xDE, 0xDA, 0x39,
  39580. 0x17, 0xC0, 0x00, 0xAF, 0x39, 0xB7, 0x8F, 0x4C,
  39581. 0xCA, 0x7C, 0x8F, 0xBF, 0x94, 0xB4, 0xCB, 0x8A,
  39582. 0x81, 0x16, 0xEE, 0xEC, 0xFE, 0xF0, 0x13, 0x1E,
  39583. 0xC9, 0xF2, 0xDE, 0xDA, 0x01, 0x40, 0xC9, 0x02,
  39584. 0xA8, 0xD6, 0xE6, 0x0E, 0x98, 0xB3, 0xCD, 0x9D,
  39585. 0x9C, 0x75, 0x24, 0x8B, 0xF8, 0x84, 0x5A, 0xC0,
  39586. 0xD7, 0xE0, 0x6B, 0xA0, 0xE1, 0x83, 0x10, 0xFE,
  39587. 0xCE, 0x98, 0x62, 0x07, 0x54, 0x2C, 0xC1, 0xEE,
  39588. 0x08, 0x88, 0x43, 0xEF, 0x74, 0xA2, 0x6A, 0xEC,
  39589. 0xB6, 0xD0, 0x6F, 0x0F, 0xEF, 0xE1, 0xB7, 0x2C,
  39590. 0xF9, 0x33, 0x06, 0xC3, 0x2E, 0xD2, 0x8A, 0xEC,
  39591. 0xC5, 0x5B, 0xB1, 0x03, 0xA0, 0x84, 0x6D, 0x0C,
  39592. 0x84, 0x13, 0x6D, 0xB0, 0xB0, 0x54, 0xF3, 0xDE,
  39593. 0xA3, 0x9A, 0x72, 0x6C, 0x6F, 0xD6, 0x59, 0x7F,
  39594. 0x9B, 0x03, 0x8C, 0xC2, 0x38, 0x46, 0x01, 0x76,
  39595. 0x38, 0xF4, 0x43, 0x68, 0x81, 0x0D, 0x86, 0x29,
  39596. 0x3D, 0xDF, 0xE5, 0x48, 0x61, 0x53, 0x2F, 0x85,
  39597. 0xF5, 0x3F, 0x09, 0x30, 0x48, 0xC3, 0xE0, 0x09,
  39598. 0xC4, 0x32, 0x11, 0x27, 0xAD, 0xAA, 0xEC, 0x6A,
  39599. 0x5C, 0xCE, 0x03, 0xE0, 0xD9, 0xE9, 0x1D, 0xAC,
  39600. 0xCA, 0xBB, 0x2F, 0x50, 0xE0, 0x1E, 0xB2, 0xAC,
  39601. 0x2B, 0x39, 0x6D, 0x24, 0xB0, 0x5D, 0x45, 0x3B,
  39602. 0xD5, 0x1D, 0x52, 0x9F, 0xBA, 0x51, 0xE4, 0x6D,
  39603. 0x30, 0xC5, 0x66, 0x13, 0x00, 0x5A, 0xBF, 0x62,
  39604. 0x63, 0xB9, 0x8D, 0x8D, 0xFE, 0xB5, 0x26, 0x16,
  39605. 0xD1, 0xCB, 0x78, 0x92, 0x18, 0x1C, 0x2F, 0xC2,
  39606. 0xE2, 0x04, 0x3B, 0x99, 0x4C, 0x81, 0x66, 0x58,
  39607. 0x48, 0x2E, 0x06, 0x06, 0x34, 0x83, 0x78, 0xA3,
  39608. 0xCC, 0x85, 0x40, 0xE0, 0x20, 0x27, 0x3F, 0x10,
  39609. 0xB6, 0x9E, 0x20, 0x21, 0xA9, 0x2D, 0x9C, 0x36,
  39610. 0xCC, 0x9B, 0x97, 0x79, 0xFE, 0x8C, 0xE7, 0xA4,
  39611. 0x99, 0xAE, 0xB5, 0x3E, 0xC6, 0xDD, 0xB4, 0xF2,
  39612. 0xEC, 0x22, 0xBF, 0xB4, 0x52, 0xFC, 0x5E, 0x79,
  39613. 0x7D, 0x3A, 0x25, 0x33, 0x26, 0x00, 0x06, 0xFE,
  39614. 0x6D, 0xCC, 0xE4, 0xE9, 0x76, 0x65, 0xC6, 0x8C,
  39615. 0x39, 0x93, 0xDC, 0x7E, 0xA0, 0xBD, 0x4B, 0xDC,
  39616. 0xD2, 0x47, 0x21, 0xB0, 0x2B, 0x09, 0x02, 0xB1,
  39617. 0x84, 0x0D, 0xDE, 0xC5, 0x18, 0x20, 0x38, 0x76,
  39618. 0x2D, 0x55, 0xFC, 0x11, 0xB9, 0x87, 0x3A, 0x0D,
  39619. 0xD2, 0xEB, 0xBD, 0x55, 0xAD, 0xE3, 0x86, 0x5C,
  39620. 0xFF, 0x3D, 0x54, 0x5F, 0x76, 0x33, 0x53, 0x69,
  39621. 0xDD, 0x9E, 0x70, 0xB0, 0x73, 0x99, 0x77, 0xF6,
  39622. 0xE9, 0x8A, 0x61, 0x27, 0x19, 0x4A, 0x19, 0x26,
  39623. 0xA6, 0x97, 0xE4, 0x7F, 0x73, 0xE0, 0x4F, 0xF5,
  39624. 0xBD, 0x52, 0x5E, 0x8F, 0x17, 0x22, 0x00, 0x8F,
  39625. 0x7C, 0x15, 0x5C, 0xD3, 0xAD, 0xE0, 0xA5, 0xB6,
  39626. 0x6A, 0x31, 0x36, 0xFD, 0xD8, 0x44, 0xAE, 0x5E,
  39627. 0xCD, 0x6C, 0x82, 0x77, 0xC3, 0xD0, 0x7F, 0x39,
  39628. 0x72, 0x1E, 0x91, 0x19, 0x50, 0xE1, 0x28, 0x20,
  39629. 0x88, 0x3A, 0x6B, 0xC8, 0xA9, 0xE7, 0x93, 0x28,
  39630. 0x0F, 0xA7, 0x4F, 0xF2, 0x1A, 0xC2, 0x13, 0x4E,
  39631. 0x6B, 0xAE, 0x71, 0x3F, 0x43, 0x89, 0xC9, 0xE7,
  39632. 0xDD, 0x05, 0xBB, 0x41, 0x09, 0xB5, 0x5E, 0xB9,
  39633. 0x23, 0x51, 0xC0, 0xEB, 0x92, 0x1A, 0x0C, 0x3F,
  39634. 0xAC, 0xC5, 0x00, 0x8C, 0xB8, 0x5C, 0x3F, 0x2D,
  39635. 0x5F, 0x9A, 0xCE, 0xAE, 0x9B, 0x4B, 0x71, 0x48,
  39636. 0x25, 0xFD, 0xE2, 0xB6, 0x26, 0x3F, 0xEE, 0x10,
  39637. 0x33, 0x07, 0x4F, 0x59, 0xF0, 0x73, 0xE9, 0x39,
  39638. 0x5C, 0x0D, 0x8B, 0xB5, 0xD1, 0xEF, 0xE5, 0xBF,
  39639. 0xBB, 0xE1, 0x80, 0xF7, 0xC5, 0x91, 0xC1, 0x72,
  39640. 0xAA, 0xB0, 0x5E, 0x7C, 0x53, 0x69, 0x4C, 0x37,
  39641. 0x7A, 0xD2, 0x7B, 0x9D, 0x1C, 0xFA, 0x0F, 0xE0,
  39642. 0x92, 0x93, 0x40, 0x5D, 0xBE, 0x1C, 0xF8, 0x84,
  39643. 0x7A, 0x35, 0x1F, 0x72, 0x77, 0x68, 0xE2, 0xAF,
  39644. 0xA5, 0x6B, 0x54, 0xFF, 0x53, 0x7C, 0xCD, 0x9D,
  39645. 0x6A, 0x49, 0xD1, 0xCA, 0x74, 0x5F, 0xF5, 0xDB,
  39646. 0x54, 0xF8, 0x60, 0xA7, 0x41, 0x66, 0xDE, 0xFF,
  39647. 0xB0, 0xB2, 0xF9, 0x21, 0x06, 0xB7, 0x81, 0x4C,
  39648. 0x9C, 0xEF, 0xFD, 0x11, 0xD5, 0x63, 0xD8, 0xF3,
  39649. 0x3A, 0x81, 0xC4, 0x9D, 0x1B, 0xA8, 0x37, 0x73,
  39650. 0x57, 0x26, 0x29, 0xF8, 0xB4, 0x7F, 0x9F, 0xA2,
  39651. 0x7D, 0x2A, 0x63, 0x2C, 0x70, 0x08, 0x1E, 0x2E,
  39652. 0xE7, 0xED, 0x73, 0xAB, 0xD2, 0x4C, 0x02, 0x7E,
  39653. 0xF1, 0x15, 0x26, 0xE1, 0x09, 0x5C, 0x29, 0x13,
  39654. 0xDF, 0x69, 0x29, 0x25, 0xE5, 0x68, 0x39, 0x10,
  39655. 0x9B, 0xD0, 0x5E, 0xD8, 0xE2, 0xC9, 0x08, 0x61,
  39656. 0x63, 0xCD, 0xF9, 0x45, 0xBC, 0x16, 0xDC, 0x80,
  39657. 0x4C, 0x0F, 0x61, 0xEE, 0x8F, 0x3B, 0x72, 0xDB,
  39658. 0x02, 0x45, 0xF6, 0x78, 0x69, 0x81, 0xFC, 0xE0,
  39659. 0x32, 0x2F, 0xC2, 0xAF, 0xCD, 0x4E, 0x8E, 0x52,
  39660. 0x03, 0xB5, 0x1C, 0x7C, 0x37, 0x2C, 0x58, 0xD5,
  39661. 0xE2, 0x92, 0xA7, 0xE2, 0x49, 0x6C, 0x3F, 0x5D,
  39662. 0x7F, 0x2B, 0x26, 0x70, 0x1C, 0x0C, 0x16, 0x7F,
  39663. 0x49, 0x30, 0x71, 0x14, 0xEB, 0xBE, 0x13, 0xF4,
  39664. 0xF1, 0xAA, 0x5A, 0xCF, 0x98, 0xF2, 0x07, 0x29,
  39665. 0xB5, 0x12, 0x84, 0x80, 0x01, 0x46, 0x11, 0xA4,
  39666. 0x44, 0xAE, 0x6D, 0xE0, 0x43, 0x7F, 0xFD, 0x5D,
  39667. 0x84, 0xB5, 0x6E, 0x3E, 0x55, 0x0D, 0xE8, 0x66,
  39668. 0x13, 0xA9, 0x28, 0x5A, 0x10, 0x84, 0x0B, 0xED,
  39669. 0x0B, 0x69, 0xF0, 0x19, 0x69, 0x9B, 0x34, 0xB8,
  39670. 0x6F, 0xC6, 0x22, 0xD3, 0x25, 0x26, 0x9D, 0x1A,
  39671. 0x04, 0x6B, 0x53, 0xA4, 0xDF, 0x12, 0x93, 0xA5,
  39672. 0x2C, 0xEE, 0x1C, 0x35, 0xFE, 0x81, 0x6B, 0x67,
  39673. 0x81, 0x92, 0x07, 0xE0, 0x9A, 0x02, 0xC9, 0xD8,
  39674. 0x59, 0x4D, 0x51, 0xE8, 0xB3, 0x14, 0x55, 0x2F,
  39675. 0xDE, 0x26, 0xDB, 0x7C, 0xEB, 0x8D, 0x80, 0x12,
  39676. 0x4A, 0x8A, 0x1C, 0x33, 0x74, 0x8E, 0x05, 0xC1,
  39677. 0xAF, 0xD6, 0xE8, 0x7B, 0x56, 0x7C, 0x41, 0xE0,
  39678. 0xE7, 0x3F, 0x32, 0x5F, 0x25, 0xDD, 0x2F, 0x48,
  39679. 0x21, 0x90, 0xC4, 0x04, 0x42, 0x1A, 0x3D, 0x6A,
  39680. 0x0E, 0x5D, 0x5C, 0xDB, 0xE2, 0xB0, 0x18, 0x8B,
  39681. 0xAC, 0x77, 0xC6, 0xE3, 0x5D, 0x77, 0xC0, 0xA3,
  39682. 0x2B, 0x1D, 0x96, 0x29, 0xF8, 0x8E, 0x70, 0xA7,
  39683. 0x65, 0xFE, 0xE3, 0x8C, 0x1A, 0xB2, 0x39, 0x75,
  39684. 0xB9, 0x45, 0xF2, 0x16, 0x1F, 0x6C, 0xFE, 0x7E,
  39685. 0x68, 0x2A, 0xED, 0x96, 0x84, 0x95, 0x47, 0x05,
  39686. 0x1D, 0xDE, 0xB7, 0x7B, 0x90, 0xF6, 0xAF, 0x00,
  39687. 0x74, 0x7C, 0x47, 0xE0, 0x2E, 0x80, 0xB6, 0x9A,
  39688. 0x0D, 0x4B, 0x78, 0xA4, 0x7D, 0xDD, 0x81, 0xE2,
  39689. 0x99, 0x27, 0x1F, 0xA7, 0x8F, 0xE4, 0x23, 0xAD,
  39690. 0xDF, 0x12, 0x0D, 0xD0, 0x4D, 0x46, 0xC1, 0x32,
  39691. 0xE9, 0x70, 0xF4, 0xA0, 0x4E, 0x97, 0xA5, 0x88,
  39692. 0xD2, 0x7C, 0x7B, 0xA8, 0x43, 0x26, 0x18, 0x2A,
  39693. 0xAE, 0x04, 0xC2, 0x51, 0x28, 0x99, 0x71, 0x69,
  39694. 0x1D, 0x96, 0x78, 0xD4, 0x09, 0x88, 0x16, 0x88,
  39695. 0xF3, 0xBC, 0xCB, 0x95, 0x08, 0x30, 0xE6, 0x5B,
  39696. 0x78, 0x48, 0x41, 0x00, 0x4E, 0x40, 0x44, 0x58,
  39697. 0xE6, 0x16, 0x59, 0x63, 0xCF, 0xB4, 0xEE, 0xB5,
  39698. 0x05, 0xFD, 0xD1, 0x35, 0xF3, 0x1E, 0xD0, 0x14,
  39699. 0x7C, 0xC9, 0xE9, 0x87, 0x7F, 0xFF, 0x41, 0x07,
  39700. 0x68, 0x91, 0x06, 0x17, 0x4E, 0x76, 0x66, 0xEE,
  39701. 0xCB, 0x6C, 0xF2, 0xDA, 0x9C, 0x93, 0x51, 0xDC,
  39702. 0x43, 0x4A, 0x94, 0x49, 0x38, 0x4E, 0xED, 0x7F,
  39703. 0x5F, 0x90, 0x77, 0xB4, 0x2F, 0x0F, 0xC5, 0xD9,
  39704. 0xF0, 0xF5, 0xF7, 0x21, 0x91, 0x32, 0xFF, 0x9A,
  39705. 0x47, 0x09, 0x83, 0xE1, 0x9D, 0x30, 0xA4, 0xF3,
  39706. 0x7D, 0x18, 0x97, 0x44, 0xD8, 0x32, 0xFD, 0x5F,
  39707. 0xB3, 0x97, 0x49, 0x4E, 0x11, 0xAD, 0xF7, 0x4F,
  39708. 0x4E, 0x90, 0x0A, 0x41, 0x87, 0xCF, 0xF5, 0xDA,
  39709. 0x8F, 0x6D, 0x7B, 0x35, 0xAE, 0xA0, 0x16, 0xA8,
  39710. 0xDE, 0x88, 0x62, 0x26, 0x5F, 0x13, 0x69, 0xFB,
  39711. 0x36, 0x7E, 0xF1, 0x86, 0x0C, 0x8E, 0x07, 0xC3,
  39712. 0x3F, 0x32, 0x82, 0xB4, 0xD9, 0x83, 0x7C, 0xDF,
  39713. 0x3E, 0xF6, 0x58, 0x42, 0x2D, 0x34, 0xDE, 0xA4,
  39714. 0x1E, 0x56, 0xDD, 0x18, 0x70, 0x36, 0x81, 0xD0,
  39715. 0x44, 0xE3, 0xC4, 0x03, 0xAF, 0x33, 0xD1, 0xE7,
  39716. 0xAF, 0xA9, 0x6A, 0x8C, 0x44, 0x35, 0xFE, 0xBB,
  39717. 0xA0, 0xD2, 0x5D, 0xE0, 0xE4, 0xAE, 0xDF, 0xFB,
  39718. 0x82, 0xA0, 0xBA, 0xDE, 0x76, 0xB6, 0x6C, 0xA9,
  39719. 0xBE, 0xC7, 0xE9, 0xD7, 0x3F, 0x1C, 0xB2, 0x9C,
  39720. 0xD7, 0x3C, 0xF0, 0x0C, 0x2F, 0x60, 0x44, 0xD8,
  39721. 0x34, 0x53, 0xCE, 0xDD, 0xE0, 0x3F, 0x97, 0x2E,
  39722. 0xBB, 0x03, 0x20, 0x62, 0xD0, 0xA8, 0x23, 0x9F,
  39723. 0xB6, 0x99, 0xEC, 0x89, 0x0D, 0x32, 0x0F, 0x6F,
  39724. 0xAF, 0x3D, 0x20, 0x7B, 0xDC, 0x9A, 0xFE, 0xA2,
  39725. 0x02, 0x8B, 0x86, 0x99, 0x56, 0x23, 0x43, 0xAA,
  39726. 0x50, 0xF7, 0x0A, 0x4E, 0x8C, 0x62, 0xDA, 0xF8,
  39727. 0xB8, 0xCC, 0xA7, 0x2D, 0x02, 0x47, 0x63, 0xBA,
  39728. 0xEC, 0x25, 0x00, 0x23, 0xEA, 0xE8, 0x25, 0xC6,
  39729. 0x51, 0xAC, 0xC4, 0xAA, 0xA0, 0xDB, 0x6C, 0x5E,
  39730. 0xC7, 0xEF, 0xD0, 0x71, 0xED, 0xFB, 0x95, 0xAF,
  39731. 0x61, 0x0B, 0x64, 0x01, 0x61, 0x4F, 0x4F, 0xC6,
  39732. 0x36, 0x27, 0x75, 0xC3, 0x81, 0x0A, 0x9A, 0x21,
  39733. 0x69, 0xF8, 0x4A, 0x21, 0x12, 0x3B, 0x03, 0x1C,
  39734. 0xCE, 0x08, 0x7D, 0x52, 0x0E, 0x99, 0xE2, 0x62,
  39735. 0xE8, 0x81, 0x2E, 0x84, 0x09, 0x8E, 0xBE, 0x9B,
  39736. 0xCE, 0xD6, 0xE6, 0xA4, 0xF7, 0x3B, 0x67, 0x45,
  39737. 0x41, 0xDE, 0x0B, 0xCF, 0x5E, 0x7E, 0x31, 0x8F,
  39738. 0x90, 0x6D, 0x90, 0x1F, 0xEB, 0x1D, 0x9D, 0x1C,
  39739. 0xCB, 0x6C, 0xFF, 0xE8, 0x50, 0xDB, 0xFF, 0x75,
  39740. 0xC8, 0xA8, 0x9F, 0x43, 0xCB, 0x94, 0x89, 0x5F,
  39741. 0x28, 0x69, 0x6F, 0xAB, 0xB6, 0xAD, 0xCE, 0xE7,
  39742. 0x69, 0x7E, 0x60, 0x09, 0x03, 0x87, 0x43, 0x6E,
  39743. 0x19, 0xB1, 0x38, 0x81, 0x9B, 0x90, 0xAE, 0xB1,
  39744. 0x8A, 0xC2, 0x7D, 0x2C, 0x65, 0x9B, 0x0D, 0xF1,
  39745. 0x77, 0x94, 0xA7, 0x2F, 0x8B, 0xB7, 0xCE, 0x03,
  39746. 0xEE, 0x9A, 0x78, 0xFE, 0x8C, 0x8A, 0x37, 0x45,
  39747. 0xD5, 0x05, 0xDE, 0xD8, 0x85, 0x00, 0xF4, 0xCF,
  39748. 0x98, 0xFB, 0x62, 0x85, 0xB0, 0xBD, 0x82, 0xE2,
  39749. 0x7D, 0xED, 0x93, 0x3B, 0xCC, 0x18, 0x73, 0xF8,
  39750. 0x8A, 0xBD, 0x82, 0x8F, 0x60, 0x47, 0xAC, 0xEC,
  39751. 0x47, 0x2D, 0xEA, 0xE8, 0x7D, 0x8A, 0xDE, 0x0A,
  39752. 0xD0, 0x73, 0x48, 0xFF, 0xAF, 0x59, 0xC1, 0x70,
  39753. 0x29, 0xD8, 0x45, 0x38, 0x77, 0x7F, 0x73, 0xBF,
  39754. 0xED, 0x5C, 0x63, 0x63, 0x0B, 0xC4, 0x43, 0xE0,
  39755. 0xFA, 0x12, 0xDE, 0x72, 0x2D, 0xAB, 0xBB, 0xC2,
  39756. 0x25, 0x0A, 0xBA, 0x3F, 0xD8, 0x61, 0x54, 0xEE,
  39757. 0x20, 0x8D, 0x53, 0xA3, 0x27, 0xA7, 0xFF, 0x26,
  39758. 0xA0, 0x17, 0x93, 0x39, 0x4D, 0x04, 0x15, 0x8B,
  39759. 0xB3, 0x20, 0x60, 0x04, 0x47, 0xE2, 0xFD, 0x7D,
  39760. 0x7C, 0x6D, 0xE0, 0x76, 0xA5, 0x13, 0xD6, 0x81,
  39761. 0x95, 0xB0, 0x67, 0x20, 0x4F, 0xF6, 0x00, 0x5B,
  39762. 0x16, 0x25, 0x54, 0x2B, 0x28, 0x37, 0x2F, 0x06,
  39763. 0x80, 0x60, 0x53, 0xAE, 0xE2, 0xEA, 0x9F, 0x88,
  39764. 0xAE, 0xA2, 0x9A, 0x27, 0x02, 0x15, 0x4B, 0xF4,
  39765. 0x43, 0xBC, 0x70, 0x7D, 0x0A, 0x96, 0xEB, 0x06,
  39766. 0xCE, 0x43, 0xEF, 0xE6, 0x6A, 0xAC, 0x1F, 0x16,
  39767. 0x95, 0xE2, 0x8C, 0xF1, 0x07, 0x19, 0x3D, 0x06,
  39768. 0x2E, 0x71, 0xB6, 0x3A, 0xFD, 0xCF, 0x9E, 0x05,
  39769. 0x0B, 0xBE, 0xD7, 0x48, 0x4E, 0xC5, 0xE8, 0x0C,
  39770. 0x51, 0x5A, 0xC8, 0x20, 0xF0, 0xCD, 0xF9, 0x65,
  39771. 0xDD, 0x97, 0xF7, 0xA1, 0x1B, 0x57, 0xB2, 0x1A,
  39772. 0x04, 0xBF, 0x42, 0xF2, 0xA3, 0x3D, 0x61, 0x97,
  39773. 0x64, 0xDF, 0xB3, 0x63, 0x11, 0xFD, 0xAD, 0x8C,
  39774. 0x83, 0xA7, 0x48, 0xBA, 0x34, 0x42, 0xC5, 0x70,
  39775. 0x64, 0x5A, 0x78, 0x5E, 0x67, 0x03, 0xE5, 0xBF,
  39776. 0x22, 0xE8, 0x46, 0xFC, 0x51, 0x6C, 0xB4, 0x99,
  39777. 0x15, 0xFD, 0x63, 0xB6, 0x3E, 0x5D, 0xBF, 0x56,
  39778. 0xF5, 0x5E, 0xA4, 0x01, 0x16, 0xD5, 0x03, 0x4B,
  39779. 0xBB, 0x94, 0x5F, 0x58, 0xD6, 0x76, 0x95, 0xC7,
  39780. 0x96, 0xF1, 0xC1, 0xD0, 0x53, 0xA3, 0xEB, 0x28,
  39781. 0xA9, 0x5E, 0x8F, 0x38, 0x8E, 0x80, 0x04, 0xC3,
  39782. 0xB2, 0x4F, 0xD5, 0xFC, 0xCA, 0x7B, 0xB1, 0xE3,
  39783. 0xB9, 0x9A, 0x9F, 0x3C, 0x94, 0x5E, 0xF8, 0xA5,
  39784. 0x35, 0xF1, 0x37, 0x43, 0x20, 0x71, 0xA5, 0xCA,
  39785. 0x5B, 0x6F, 0x7D, 0xC7, 0xB8, 0xBC, 0xE5, 0x5A,
  39786. 0xD0, 0xF3, 0xB6, 0xCF, 0x1B, 0xCB, 0xB9, 0xCD,
  39787. 0x35, 0xE2, 0x41, 0xF8, 0x6E, 0x46, 0x97, 0x27,
  39788. 0x26, 0x48, 0xF4, 0x73, 0xDB, 0xD5, 0xB7, 0x68,
  39789. 0x1E, 0xF0, 0xC7, 0x84, 0x49, 0xE6, 0xC5, 0xFA,
  39790. 0x93, 0x0D, 0x83, 0x2C, 0x85, 0x1E, 0xED, 0x2A,
  39791. 0x65, 0x12, 0x19, 0xD7, 0xD9, 0xC3, 0xBB, 0x23,
  39792. 0xF3, 0xC6, 0xAD, 0x7E, 0xB7, 0x78, 0x68, 0x54,
  39793. 0x1F, 0x3C, 0xEE, 0x09, 0xF5, 0x1E, 0xE0, 0x4E,
  39794. 0xBA, 0x1B, 0xBC, 0x29, 0x69, 0x8A, 0xED, 0xD3,
  39795. 0xC7, 0xAC, 0xEC, 0x44, 0x29, 0xD7, 0xA4, 0x0C,
  39796. 0xFA, 0xBD, 0xA2, 0x29, 0x34, 0x80, 0x16, 0x4F,
  39797. 0x37, 0xEC, 0xB6, 0x73, 0xF2, 0xB5, 0xD7, 0x51,
  39798. 0x57, 0x43, 0xAF, 0x7E, 0xD0, 0xB6, 0xE0, 0x96,
  39799. 0xF0, 0xE2, 0xFE, 0xCE, 0xC8, 0x9F, 0x40, 0xD6,
  39800. 0xAF, 0xE0, 0xBF, 0xCD, 0x70, 0x37, 0x91, 0x69,
  39801. 0x99, 0x8C, 0xDF, 0x4A, 0x20, 0xDE, 0xB6, 0xC6,
  39802. 0x7A, 0xB4, 0xE3, 0x6A, 0xAD, 0x53, 0xED, 0xB9,
  39803. 0x8A, 0x13, 0x61, 0xC5, 0xE9, 0xB0, 0xDC, 0x16,
  39804. 0x36, 0xD7, 0x51, 0xA8, 0x7B, 0x52, 0x05, 0x3B,
  39805. 0xAD, 0x5C, 0xD2, 0xBD, 0x6F, 0x6B, 0xA9, 0x51,
  39806. 0xA7, 0xE8, 0x7E, 0xA4, 0xB6, 0x77, 0xAE, 0x00,
  39807. 0x89, 0x3A, 0x1F, 0x76, 0x72, 0x3F, 0xC5, 0x6C,
  39808. 0x49, 0x4F, 0xB5, 0xCA, 0x2F, 0x5D, 0xAE, 0xF8,
  39809. 0x58, 0x9A, 0xE2, 0x5B, 0x54, 0x76, 0xF4, 0xAA,
  39810. 0x89, 0xD4, 0x04, 0xAF, 0x1C, 0x26, 0x65, 0xEC,
  39811. 0xA1, 0x81, 0x06, 0x2A, 0x4B, 0x5E, 0xD5, 0x90,
  39812. 0xB8, 0x26, 0x33, 0x64, 0x15, 0x33, 0x25, 0xAC,
  39813. 0x97, 0x9A, 0xCA, 0x1B, 0x64, 0x50, 0x82, 0x8F,
  39814. 0x65, 0x6A, 0xD4, 0x47, 0xCF, 0x7E, 0x93, 0x7D,
  39815. 0xB3, 0xCB, 0xFE, 0x55, 0x0A, 0x46, 0x93, 0x22,
  39816. 0xB5, 0x46, 0xAB, 0xD6, 0x05, 0x59, 0x14, 0x5E,
  39817. 0x1B, 0xD4, 0x2D, 0xAF, 0xA3, 0x18, 0xB7, 0xA0,
  39818. 0xD7, 0x11, 0x70, 0xDE, 0x81, 0x8B, 0xD6, 0x64,
  39819. 0xFD, 0x38, 0xBD, 0x29, 0x92, 0x41, 0x80, 0xC4,
  39820. 0x4A, 0x6D, 0x34, 0x1B, 0xF0, 0x59, 0xA0, 0xD6,
  39821. 0x48, 0x55, 0xD2, 0xA5, 0xE2, 0x91, 0xB6, 0x71,
  39822. 0xF4, 0x90, 0x97, 0x8B, 0x0A, 0xDD, 0x90, 0xEA,
  39823. 0x61, 0x9B, 0x30, 0xA6, 0x2F, 0x5D, 0xB4, 0xEE,
  39824. 0x7A, 0x10, 0x40, 0x59, 0x89, 0xAC, 0x30, 0x6E,
  39825. 0x9C, 0x7B, 0xBC, 0x11, 0x75, 0x38, 0x00, 0x2E,
  39826. 0xDF, 0xED, 0x87, 0x47, 0x30, 0xFB, 0xD4, 0x8A,
  39827. 0xC6, 0xBE, 0xC7, 0x20, 0xC8, 0x3D, 0x51, 0x05,
  39828. 0x67, 0x48, 0xDE, 0xE2, 0xBF, 0x95, 0x5E, 0x7B,
  39829. 0xD7, 0xC7, 0x86, 0xDF, 0x68, 0x57, 0xA9, 0x29,
  39830. 0xBC, 0xF8, 0xE3, 0x81, 0x62, 0x1B, 0x37, 0x58,
  39831. 0xF2, 0xFF, 0xEE, 0xE8, 0x28, 0x08, 0x36, 0x23,
  39832. 0x5B, 0x24, 0x68, 0x1E, 0x62, 0xBD, 0x27, 0xC2,
  39833. 0x6F, 0xE9, 0x63, 0x67, 0x53, 0xC7, 0x8A, 0xB5,
  39834. 0xA7, 0xEF, 0x29, 0xFE, 0x60, 0xAC, 0x29, 0xCF,
  39835. 0x67, 0x40, 0x9F, 0xE6, 0x57, 0xCE, 0x65, 0x3A,
  39836. 0x2F, 0xDA, 0xA7, 0xF2, 0x0C, 0x50, 0x19, 0xE6,
  39837. 0xF7, 0x43, 0x2E, 0x8C, 0xEB, 0x9E, 0x99, 0x92,
  39838. 0xE6, 0x46, 0xB7, 0x8D, 0x43, 0x65, 0xFD, 0x02,
  39839. 0x17, 0x74, 0x6F, 0x7B, 0xA3, 0x1E, 0x06, 0x9D,
  39840. 0x75, 0x4E, 0x05, 0xED, 0x5A, 0x71, 0xFC, 0x5E,
  39841. 0x7D, 0x6D, 0x64, 0x5E, 0xAF, 0x41, 0x44, 0xD6,
  39842. 0xBC, 0x43, 0x05, 0x5E, 0x6C, 0xDB, 0x89, 0x34,
  39843. 0xC7, 0x02, 0x64, 0x08, 0xAE, 0x96, 0x53, 0x5B,
  39844. 0xA2, 0xDE, 0xCD, 0x2F, 0x74, 0x56, 0xD6, 0xEC,
  39845. 0xA4, 0x23, 0x68, 0xCD, 0x9A, 0xC5, 0x05, 0x7B,
  39846. 0x7D, 0x1E, 0x12, 0xF7, 0x7A, 0xA8, 0x7C, 0x43,
  39847. 0x7E, 0x7A, 0x43, 0x31, 0x5D, 0xA0, 0x81, 0xE5,
  39848. 0x3A, 0xFE, 0x23, 0xB5, 0xBC, 0xC2, 0xF4, 0xCE,
  39849. 0x3A, 0x80, 0x06, 0xE8, 0x1E, 0x08, 0xAF, 0x0A,
  39850. 0x33, 0xC1, 0xA9, 0x30, 0x7C, 0x8D, 0x5A, 0xC5,
  39851. 0x93, 0x89, 0xF2, 0x69, 0x24, 0x11, 0x6C, 0xAB,
  39852. 0x0B, 0x87, 0xD5, 0x49, 0xD0, 0x38, 0x3C, 0x27,
  39853. 0x4E, 0x8E, 0x85, 0xD4, 0x6E, 0x0F, 0xCD, 0x70,
  39854. 0xE3, 0x68, 0x42, 0xCA, 0x4C, 0x8D, 0x6D, 0x0F,
  39855. 0x48, 0xF3, 0xED, 0xF9, 0xE9, 0x43, 0x5D, 0xBF,
  39856. 0x55, 0x75, 0xF8, 0xEB, 0x78, 0x93, 0x72, 0x75,
  39857. 0x8B, 0xF5, 0xBD, 0xE9, 0x9D, 0xA2, 0xB9, 0x81,
  39858. 0x83, 0xDB, 0xAC, 0x82, 0xD1, 0xC1, 0x20, 0x03,
  39859. 0x72, 0x4D, 0xDC, 0x42, 0xAE, 0xC8, 0x1C, 0x0C,
  39860. 0x78, 0x22, 0x77, 0x27, 0x91, 0x50, 0x4C, 0x90,
  39861. 0xEA, 0x13, 0x8B, 0x6C, 0x91, 0xDF, 0x5D, 0x25,
  39862. 0x36, 0x9C, 0xC2, 0x06, 0x4F, 0xD5, 0xE2, 0xCC,
  39863. 0x9D, 0x89, 0x3B, 0xC4, 0x23, 0x5D, 0x88, 0x17,
  39864. 0x62, 0x4E, 0xC9, 0xFA, 0xC8, 0xEF, 0x1D, 0x45,
  39865. 0xE1, 0xFB, 0x58, 0xB3, 0x8E, 0xBD, 0x8D, 0xAE,
  39866. 0x12, 0xFF, 0xA0, 0x37, 0xE0, 0x7F, 0x5B, 0x41,
  39867. 0x1D, 0x40, 0x17, 0xAF, 0x95, 0x2D, 0x8C, 0x42,
  39868. 0xC6, 0x1A, 0x2A, 0x1E, 0x8E, 0x70, 0x25, 0xD6,
  39869. 0xD3, 0xA2, 0x85, 0xAA, 0x17, 0xFF, 0x0D, 0xB4,
  39870. 0x39, 0xD0, 0xF2, 0xAF, 0xA0, 0x4F, 0x31, 0x8D,
  39871. 0x6D, 0x57, 0x6A, 0xED, 0xC6, 0xF1, 0xE7, 0x67,
  39872. 0xA6, 0x6F, 0xB3, 0x9B, 0x72, 0xC6, 0x7F, 0x05,
  39873. 0xAF, 0x40, 0x87, 0x12, 0x0D, 0xC8, 0x98, 0x88,
  39874. 0x2D, 0xDE, 0xA1, 0x7C, 0x95, 0x32, 0xB2, 0x7A,
  39875. 0xB5, 0x9D, 0xE4, 0x0D, 0x75, 0xD4, 0x17, 0x5B,
  39876. 0xB4, 0x92, 0x73, 0xAF, 0x87, 0x3A, 0x92, 0xDA,
  39877. 0x4D, 0x87, 0xE2, 0x53, 0xCA, 0xE7, 0x2A, 0x52,
  39878. 0x64, 0xE0, 0xC1, 0xDE, 0x4C, 0x9C, 0xF9, 0x1A,
  39879. 0x1F, 0x3A, 0xD6, 0x05, 0xA0, 0xCC, 0x8D, 0x91,
  39880. 0x93, 0x51, 0xF9, 0x37, 0x1A, 0xFC, 0x68, 0xEF,
  39881. 0xBC, 0xED, 0x19, 0x8E, 0x4C, 0xD1, 0xB5, 0x8C,
  39882. 0xA2, 0x85, 0xDA, 0x02, 0x65, 0xAB, 0xAC, 0xAE,
  39883. 0xCA, 0x8E, 0xAC, 0xF0, 0x2A, 0x4F, 0xC7, 0x67,
  39884. 0x16, 0x2E, 0x24, 0x7F, 0x73, 0xCD, 0xD7, 0x3E,
  39885. 0xE3, 0x27, 0x8A, 0xF9, 0x4A, 0xC4, 0xA8, 0xCB,
  39886. 0x2B, 0x01, 0x55, 0x68, 0x34, 0xA3, 0xC0, 0xB8,
  39887. 0xD0, 0x6D, 0x05, 0xF2, 0x3B, 0x4C, 0x17, 0x47,
  39888. 0xE7, 0x64, 0x53, 0xF4, 0x9D, 0xE0, 0x8D, 0xF8,
  39889. 0xEE, 0x0E, 0xA6, 0x25, 0x64, 0x7D, 0x1B, 0xD0,
  39890. 0x80, 0xE7, 0x3C, 0x41, 0x97, 0xAE, 0xCB, 0x6A,
  39891. 0x23, 0xC2, 0x5F, 0x00, 0xC6, 0xC5, 0x4C, 0x8A,
  39892. 0x4C, 0xEF, 0x76, 0x65, 0x95, 0x28, 0xB3, 0x67,
  39893. 0x42, 0xEC, 0x17, 0xFF, 0x0E, 0xE3, 0x7B, 0x30,
  39894. 0x6D, 0xCC, 0xB8, 0x87, 0xD6, 0x63, 0x36, 0x5D,
  39895. 0xC9, 0xE8, 0x1D, 0x51, 0x47, 0xCF, 0xE5, 0x05,
  39896. 0x0D, 0xB4, 0x09, 0xDF, 0xAD, 0x88, 0x9C, 0x38,
  39897. 0x6F, 0x12, 0xA5, 0xCD, 0x0C, 0x95, 0x53, 0x41,
  39898. 0x13, 0xA6, 0xD0, 0xAB, 0xCB, 0x5A, 0x3F, 0x56,
  39899. 0xCE, 0x23, 0xEE, 0x32, 0x61, 0x22, 0x79, 0xE8,
  39900. 0xBA, 0x23, 0x94, 0x61, 0x25, 0x8E, 0xD6, 0x3E,
  39901. 0x78, 0x83, 0xE1, 0x15, 0xBA, 0x05, 0x81, 0xB8,
  39902. 0x1A, 0x7F, 0x73, 0xC1, 0xB7, 0x9F, 0x29, 0xA1,
  39903. 0x16, 0x2E, 0x6E, 0x84, 0xC7, 0x15, 0xBC, 0x50,
  39904. 0x28, 0x5F, 0xD3, 0x8D, 0x4D, 0x6D, 0xC0, 0x87,
  39905. 0x68, 0x88, 0x4B, 0xF4, 0xFB, 0x55, 0x85, 0x3D,
  39906. 0xA7, 0xB5, 0x47, 0x1E, 0x73, 0xA1, 0x47, 0x8D,
  39907. 0xB1, 0xE1, 0xCF, 0xE6, 0x15, 0x3E, 0xC6, 0xC3,
  39908. 0x78, 0xDD, 0x6A, 0x3F, 0x42, 0x29, 0x6E, 0x61,
  39909. 0x9D, 0xE7, 0x63, 0xFF, 0x2D, 0xDB, 0x83, 0xE5,
  39910. 0x15, 0x84, 0xC2, 0x8D, 0xD8, 0x34, 0x2E, 0x92,
  39911. 0x9E, 0x15, 0xB7, 0xBB, 0xCF, 0x5D, 0x6E, 0xCB,
  39912. 0x87, 0x79, 0xCF, 0x7F, 0x3A, 0x9A, 0xC1, 0x6A,
  39913. 0x43, 0x1F, 0x52, 0xA2, 0x34, 0xE6, 0xA3, 0x69,
  39914. 0x9D, 0x9E, 0x44, 0x84, 0x0A, 0x4D, 0x3D, 0x48,
  39915. 0x5D, 0xA5, 0xD9, 0x03, 0x94, 0xB1, 0x81, 0xEF,
  39916. 0x89, 0x98, 0xE6, 0xD1, 0x44, 0x21, 0x83, 0x59,
  39917. 0x09, 0xCD, 0xDB, 0x16, 0x7C, 0x8C, 0x38, 0x78,
  39918. 0x19, 0x4B, 0x6D, 0x51, 0x4D, 0xF8, 0x63, 0x6D,
  39919. 0x4A, 0x14, 0xA1, 0xBE, 0xF3, 0xCA, 0x38, 0x1E,
  39920. 0x36, 0xCF, 0x2E, 0x6D, 0x5F, 0xBC, 0xB4, 0x0A,
  39921. 0xF0, 0x91, 0x7D, 0x6D, 0xBB, 0x87, 0x5C, 0xFF,
  39922. 0x64, 0xCD, 0xCE, 0xCC, 0xCF, 0xB8, 0xBF, 0xB8,
  39923. 0x05, 0x45, 0x8D, 0xF8, 0x2C, 0x74, 0xEB, 0x86,
  39924. 0x3A, 0x96, 0x9E, 0xD9, 0x8B, 0x9C, 0x46, 0xE7,
  39925. 0x17, 0x3C, 0x09, 0x0D, 0xB0, 0x68, 0xB2, 0xD8,
  39926. 0x0C, 0xCE, 0x32, 0xDE, 0x51, 0x72, 0xB5, 0xD4,
  39927. 0xA8, 0xB9, 0x09, 0xA5, 0xA4, 0xCC, 0x47, 0xFA,
  39928. 0x9F, 0x2E, 0xD6, 0x6E, 0x60, 0x69, 0xCD, 0x96,
  39929. 0xAB, 0x1F, 0x3E, 0x84, 0x8C, 0x68, 0x72, 0x0F,
  39930. 0xEA, 0x32, 0xC5, 0x73, 0x6E, 0x8A, 0xB5, 0x10,
  39931. 0x05, 0xFE, 0x42, 0x58, 0x33, 0xF2, 0x07, 0x56,
  39932. 0xC1, 0x96, 0x76, 0x23, 0x77, 0x9D, 0x0A, 0xD2,
  39933. 0x42, 0xA1, 0x69, 0x06, 0x83, 0xBA, 0xD2, 0xEB,
  39934. 0x12, 0x3D, 0x97, 0xAB, 0x23, 0x08, 0x90, 0x15,
  39935. 0x51, 0x4D, 0x0C, 0x6A, 0x3B, 0x0F, 0x37, 0x15,
  39936. 0x25, 0xC2, 0x3E, 0x5F, 0x53, 0x84, 0x4C, 0x81,
  39937. 0xDD, 0xE8, 0x7C, 0xFE, 0x9F, 0x06, 0x5E, 0x11,
  39938. 0x68, 0x7D, 0x68, 0x6B, 0x07, 0x2C, 0x19, 0x00,
  39939. 0xF5, 0xC9, 0xA7, 0xC3, 0x1F, 0xE8, 0xBA, 0xBE,
  39940. 0x9F, 0x09, 0x0C, 0xE2, 0xCB, 0x3B, 0x68, 0x7B,
  39941. 0xA8, 0x9E, 0xD8, 0x3C, 0x08, 0x85, 0xDF, 0xF9,
  39942. 0x11, 0x2B, 0x52, 0xF6, 0xCE, 0xD7, 0x1E, 0x32,
  39943. 0xA4, 0x0A, 0x9A, 0xBC, 0xFF, 0xF4, 0x20, 0xB6,
  39944. 0x24, 0x85, 0x84, 0x7F, 0xFF, 0x70, 0x3C, 0xBB,
  39945. 0x74, 0x36, 0x42, 0x25, 0x5F, 0xBD, 0x0A, 0x90,
  39946. 0x86, 0xA7, 0xB8, 0x3F, 0x9E, 0xDF, 0x43, 0x24,
  39947. 0x88, 0x0C, 0x52, 0x08, 0xF7, 0xDC, 0xB1, 0xEA,
  39948. 0xC3, 0x38, 0xF9, 0x13, 0x16, 0x65, 0xA0, 0xCA,
  39949. 0x6B, 0xF0, 0xD6, 0x12, 0xFB, 0xA6, 0x3F, 0xF7,
  39950. 0x13, 0x91, 0x99, 0xB1, 0xDE, 0xE4, 0xEE, 0x1E,
  39951. 0x98, 0x9B, 0xE4, 0xA0, 0x3A, 0xA8, 0xAC, 0x4A,
  39952. 0x48, 0x3E, 0xCB, 0x9E, 0xB4, 0x1D, 0x22, 0x1F,
  39953. 0x59, 0x97, 0x24, 0x8C, 0xFE, 0xDC, 0xBF, 0x6C,
  39954. 0xAD, 0x8D, 0xB0, 0xA3, 0x27, 0xFA, 0x28, 0x8F,
  39955. 0xD6, 0xAE, 0x31, 0x39, 0x84, 0xFA, 0x61, 0x8F,
  39956. 0x7D, 0xD4, 0xEE, 0xBB, 0x13, 0xED, 0x85, 0xC4,
  39957. 0x35, 0xC0, 0xAB, 0x07, 0x73, 0xC5, 0xCD, 0xCA,
  39958. 0xD4, 0x69, 0x9B, 0x9C, 0x38, 0x2A, 0x1F, 0x37,
  39959. 0xF9, 0xDF, 0x8C, 0x3A, 0xE1, 0x57, 0xDF, 0x05,
  39960. 0x9F, 0x97, 0x51, 0xCC, 0xA6, 0x93, 0xD5, 0x49,
  39961. 0x2A, 0xE9, 0xCD, 0x46, 0x31, 0x22, 0x6E, 0x62,
  39962. 0xE8, 0x13, 0x90, 0x64, 0xFF, 0x00, 0x27, 0xCF,
  39963. 0xA1, 0x95, 0x4E, 0xE9, 0x36, 0xAF, 0xAD, 0x02,
  39964. 0x06, 0xDD, 0x2A, 0xE2, 0x28, 0xB6, 0xDD, 0x65,
  39965. 0xCD, 0x9A, 0x9D, 0x5F, 0xF9, 0xC0, 0xCC, 0x48,
  39966. 0xC8, 0xC2, 0xE9, 0x8F, 0x5A, 0xE6, 0xE2, 0xC9,
  39967. 0x79, 0x7A, 0x83, 0x84, 0xF8, 0xA3, 0xE3, 0xC7,
  39968. 0x48, 0xC7, 0x06, 0xFE, 0x6A, 0x36, 0x25, 0xD2,
  39969. 0xA2, 0xEB, 0x4A, 0xE2, 0xCA, 0xA0, 0x49, 0x24,
  39970. 0x1A, 0x47, 0x8C, 0x1A, 0x77, 0xF5, 0xC9, 0x0D,
  39971. 0xDC, 0x94, 0x18, 0x4D, 0x89, 0x80, 0x50, 0x18,
  39972. 0x7D, 0x67, 0x00, 0x43, 0xE4, 0xE7, 0x8F, 0x54,
  39973. 0xDC, 0x60, 0x84, 0x24, 0xF3, 0xBF, 0x5E, 0x92,
  39974. 0xC7, 0x0C, 0x05, 0x49, 0xBB, 0x61, 0x2F, 0x48,
  39975. 0x0A, 0xEB, 0xE5, 0xFA, 0x8B, 0x01, 0x33, 0x27,
  39976. 0x10, 0x3E, 0xA1, 0x28, 0x33, 0x11, 0x30, 0x1F,
  39977. 0x91, 0x47, 0x7B, 0xA6, 0x3E, 0xD4, 0xF9, 0xC2,
  39978. 0x8F, 0xA3, 0x4E, 0xBC, 0xA7, 0x61, 0x56, 0x1F,
  39979. 0x90, 0x33, 0x54, 0x15, 0x06, 0x21, 0x9C, 0x57,
  39980. 0x07, 0xC2, 0xF8, 0xED, 0x81, 0xED, 0x36, 0x15,
  39981. 0xC8, 0xAC, 0xAB, 0x12, 0x80, 0xBF, 0x7C, 0x5E,
  39982. 0x00, 0xEC, 0x1B, 0x27, 0x58, 0x3A, 0xE9, 0x09,
  39983. 0x2B, 0x23, 0x16, 0x69, 0x26, 0xF9, 0xCC, 0x3C,
  39984. 0x5A, 0xFB, 0x66, 0xBA, 0x32, 0xF9, 0xAF, 0xAB,
  39985. 0xCB, 0xA7, 0xF7, 0x91, 0x6A, 0x82, 0x42, 0xA7,
  39986. 0x9D, 0x7B, 0x0E, 0xD3, 0x5D, 0xF6, 0x52, 0x6D,
  39987. 0x7D, 0x2B, 0xE6, 0x30, 0x99, 0x01, 0xBD, 0xC0,
  39988. 0x3D, 0x15, 0x95, 0xC2, 0x67, 0x19, 0xD9, 0x0F,
  39989. 0xC0, 0x79, 0x1E, 0xAB, 0xA7, 0x67, 0x35, 0x12,
  39990. 0x53, 0xB0, 0x6A, 0xE4, 0xB9, 0x0A, 0x52, 0xEF,
  39991. 0xBD, 0xCD, 0xD4, 0x0C, 0x09, 0x6F, 0x24, 0xE9,
  39992. 0x52, 0x9F, 0xF8, 0x9F, 0x95, 0x95, 0x57, 0x07,
  39993. 0x5F, 0xC8, 0xDD, 0xAF, 0xE6, 0x10, 0x3A, 0x51,
  39994. 0x38, 0xF0, 0x9F, 0xBD, 0xEB, 0x0F, 0x5F, 0x36,
  39995. 0xB5, 0x2A, 0x57, 0xBE, 0x21, 0x39, 0xD8, 0x9D,
  39996. 0x29, 0x04, 0xBC, 0xE2, 0xB8, 0x6D, 0x03, 0xF2,
  39997. 0x6D, 0x56, 0xF4, 0x18, 0x40, 0x07, 0x1A, 0x15,
  39998. 0x8B, 0xF5, 0x46, 0xE1, 0x0C, 0x4D, 0xED, 0x0E,
  39999. 0x81, 0xB0, 0x0D, 0x98, 0x88, 0xC5, 0x5D, 0x53,
  40000. 0xE1, 0x1D, 0xB7, 0x00, 0x26, 0xC6, 0x46, 0x7E,
  40001. 0xD2, 0xAB, 0x0B, 0xD9, 0x1E, 0xE0, 0xE7, 0xC3,
  40002. 0xC3, 0xE0, 0x83, 0x7F, 0x8C, 0xB9, 0xBA, 0xE0,
  40003. 0x04, 0xE2, 0xA8, 0xFF, 0xEC, 0xD5, 0x9E, 0x79,
  40004. 0x2F, 0x13, 0xF9, 0x27, 0xCA, 0xDD, 0xF5, 0x0F,
  40005. 0x74, 0xD2, 0x9B, 0xC6, 0x2E, 0xF2, 0xF0, 0x2A,
  40006. 0xB0, 0xF9, 0x6E, 0x27, 0x3E, 0x8D, 0x66, 0xDB,
  40007. 0x44, 0x82, 0xDD, 0x1B, 0xD5, 0xBB, 0x51, 0x6E,
  40008. 0x72, 0x3A, 0xCB, 0x0F, 0x0B, 0x97, 0xBC, 0x32,
  40009. 0x07, 0xC1, 0x0C, 0xF3, 0x94, 0xFF, 0x62, 0xE2,
  40010. 0xFD, 0x7D, 0xBB, 0x3D, 0x43, 0x11, 0xB3, 0xFA,
  40011. 0x22, 0x05, 0xBF, 0x87, 0x0F, 0xFD, 0xD1, 0x81,
  40012. 0xC6, 0x30, 0xC6, 0x91, 0xD4, 0xEE, 0xA8, 0x6B,
  40013. 0x37, 0xB2, 0x38, 0xF1, 0x87, 0x89, 0xE0, 0x04,
  40014. 0x09, 0xED, 0x18, 0xA6, 0x3C, 0x18, 0x9E, 0x38,
  40015. 0xCB, 0x9F, 0xFE, 0xB3, 0x03, 0xF4, 0xE4, 0x3F,
  40016. 0xB3, 0x94, 0x7C, 0x74, 0x03, 0x6C, 0xCF, 0x16,
  40017. 0x24, 0xF8, 0x56, 0xE2, 0x4A, 0x7E, 0x9A, 0x21,
  40018. 0xB8, 0xC2, 0x7C, 0xF4, 0x3D, 0x85, 0x15, 0x43,
  40019. 0xA5, 0xCA, 0xFD, 0xA3, 0x05, 0xCC, 0x63, 0x8D,
  40020. 0x94, 0x82, 0x70
  40021. };
  40022. static const byte rnd_87[] = {
  40023. 0x16, 0xB8, 0x2B, 0x9B, 0x0A, 0x90, 0x5B, 0xB3,
  40024. 0xD8, 0x7B, 0x4A, 0x1E, 0x40, 0xAE, 0xAD, 0x3C,
  40025. 0xDE, 0x63, 0xB2, 0x2C, 0xB7, 0x16, 0xBD, 0x46,
  40026. 0x7A, 0x7B, 0xE8, 0x4A, 0xF1, 0x9B, 0x7C, 0xFE
  40027. };
  40028. static const byte sig_87[] = {
  40029. 0xE5, 0x5D, 0x62, 0x56, 0x92, 0x73, 0x72, 0x13,
  40030. 0xDD, 0x3D, 0x7F, 0x51, 0x42, 0xF3, 0xAA, 0x33,
  40031. 0x87, 0x12, 0x2F, 0x20, 0xC9, 0x50, 0x93, 0x0A,
  40032. 0x7E, 0x7C, 0xCC, 0x0C, 0x6D, 0x21, 0xB9, 0x5D,
  40033. 0x62, 0x47, 0xD5, 0xFB, 0x3A, 0xCC, 0xBC, 0xB8,
  40034. 0xA1, 0x5A, 0xDF, 0x97, 0x58, 0xBA, 0x7E, 0x40,
  40035. 0x9A, 0x76, 0xD0, 0x1C, 0xBF, 0x0F, 0x14, 0xC3,
  40036. 0x23, 0x3B, 0x21, 0xB0, 0x5D, 0x11, 0x3B, 0x1F,
  40037. 0x70, 0xCB, 0x21, 0x78, 0x51, 0x68, 0xE2, 0x3A,
  40038. 0x29, 0x4A, 0x0D, 0xD0, 0x32, 0x50, 0xDC, 0xBB,
  40039. 0xD1, 0xCF, 0x80, 0x19, 0x7A, 0xC7, 0xFC, 0x37,
  40040. 0x2D, 0x5A, 0x5A, 0xDF, 0x3E, 0x7E, 0x89, 0x2D,
  40041. 0xC6, 0x0E, 0x75, 0x9A, 0xBB, 0xDF, 0x69, 0x82,
  40042. 0x28, 0xB6, 0xD0, 0xF3, 0xF4, 0xCB, 0x4F, 0xD5,
  40043. 0xDC, 0x5D, 0xFE, 0x8D, 0x01, 0xB4, 0x93, 0x9F,
  40044. 0x89, 0x53, 0x18, 0x74, 0x29, 0x20, 0x36, 0xBF,
  40045. 0x34, 0xCA, 0x71, 0x2B, 0x01, 0x14, 0xFB, 0x66,
  40046. 0x94, 0x28, 0x81, 0xF1, 0xF1, 0x7E, 0x80, 0xB6,
  40047. 0x4E, 0x0E, 0x9E, 0x9E, 0x60, 0xD7, 0x6A, 0xFB,
  40048. 0x59, 0xC7, 0x96, 0x9F, 0xB4, 0x9C, 0x98, 0x72,
  40049. 0x06, 0xC1, 0x6C, 0xAA, 0x8E, 0xC7, 0x48, 0xE6,
  40050. 0xC3, 0xAD, 0x8B, 0x4E, 0xF7, 0x81, 0x92, 0x74,
  40051. 0xC0, 0x5A, 0x2B, 0x54, 0x8D, 0x47, 0x15, 0xAC,
  40052. 0xED, 0x45, 0x69, 0xD0, 0x7C, 0x28, 0x80, 0x18,
  40053. 0xA3, 0x9F, 0xB7, 0x14, 0xC6, 0x51, 0xF9, 0x02,
  40054. 0x70, 0x98, 0xD9, 0xC1, 0x09, 0xC0, 0xD7, 0xCE,
  40055. 0x8B, 0x81, 0x7B, 0x30, 0x99, 0x4C, 0x85, 0x1C,
  40056. 0xFA, 0xAE, 0xBF, 0x05, 0x95, 0xBB, 0x6E, 0x01,
  40057. 0xE4, 0xFC, 0xE7, 0x11, 0x16, 0x90, 0x28, 0xC3,
  40058. 0xC4, 0x36, 0x9F, 0x11, 0xCD, 0xEB, 0xEB, 0x71,
  40059. 0x15, 0x08, 0x1D, 0x43, 0x2B, 0x12, 0xA6, 0x4E,
  40060. 0xB6, 0xF9, 0x35, 0xE4, 0x37, 0x0D, 0xF7, 0x49,
  40061. 0xDF, 0x73, 0x4D, 0xE3, 0x57, 0x33, 0x96, 0x7B,
  40062. 0x72, 0x45, 0x2F, 0x92, 0x70, 0xBB, 0x6F, 0xCD,
  40063. 0x90, 0x82, 0x67, 0xBB, 0x31, 0x9D, 0x9E, 0x38,
  40064. 0x75, 0xCD, 0x5B, 0x55, 0x10, 0x6B, 0xFC, 0x00,
  40065. 0x15, 0xC8, 0xCB, 0xFC, 0xE1, 0x18, 0x41, 0xE8,
  40066. 0x6E, 0x92, 0xEC, 0x1A, 0x26, 0x88, 0x6C, 0xF6,
  40067. 0x2A, 0x5C, 0x05, 0x94, 0xD7, 0xB8, 0xD0, 0x78,
  40068. 0x52, 0x68, 0x8D, 0xC5, 0xBD, 0xD6, 0x29, 0xF8,
  40069. 0x21, 0xDF, 0xB3, 0x28, 0x43, 0x74, 0xC7, 0x0E,
  40070. 0x99, 0xD3, 0x0C, 0xDE, 0xE9, 0x06, 0x44, 0xCD,
  40071. 0x77, 0x13, 0x34, 0x82, 0xBA, 0x36, 0x20, 0x71,
  40072. 0x02, 0xB1, 0x6E, 0xBA, 0xCF, 0x9F, 0x15, 0x36,
  40073. 0xC8, 0xF1, 0x4E, 0x36, 0x30, 0x34, 0x2D, 0x23,
  40074. 0x6C, 0x77, 0xEC, 0xCA, 0xBA, 0x7C, 0x17, 0x4F,
  40075. 0x3F, 0x22, 0x4A, 0x34, 0xA1, 0x5C, 0xB3, 0x8F,
  40076. 0xD8, 0x48, 0xD5, 0x8A, 0x2C, 0x8B, 0x1B, 0xFB,
  40077. 0x87, 0xDA, 0xBC, 0xB6, 0xD9, 0x59, 0xD6, 0x9B,
  40078. 0xF0, 0x6E, 0x8D, 0xB1, 0x52, 0xE1, 0x8A, 0x36,
  40079. 0x31, 0xA7, 0x83, 0xCE, 0xDF, 0x36, 0xEB, 0xBE,
  40080. 0xEA, 0xC3, 0xC6, 0xA6, 0x52, 0x2D, 0x89, 0x0B,
  40081. 0xF9, 0x5B, 0x1D, 0x14, 0xA9, 0xBF, 0x37, 0x31,
  40082. 0xE0, 0x1C, 0xF5, 0x29, 0x95, 0xF0, 0xC0, 0x08,
  40083. 0xE8, 0x97, 0xEE, 0x53, 0x27, 0x85, 0x81, 0x7D,
  40084. 0x47, 0xE5, 0xAC, 0xC5, 0x1B, 0x48, 0xA5, 0x36,
  40085. 0x1E, 0x8A, 0xD7, 0xF5, 0xC9, 0x93, 0x74, 0xCE,
  40086. 0x06, 0xEA, 0xC3, 0x26, 0x45, 0xFF, 0xED, 0x39,
  40087. 0xC1, 0x0B, 0x7A, 0x59, 0x3C, 0x0F, 0xEE, 0x89,
  40088. 0xEF, 0xA4, 0xEC, 0xD0, 0x72, 0x34, 0x95, 0xC9,
  40089. 0xC4, 0x78, 0x47, 0xB6, 0xB7, 0xCE, 0xA4, 0xD9,
  40090. 0xA1, 0xB6, 0x37, 0xC1, 0xF1, 0xFB, 0x4E, 0x4C,
  40091. 0x38, 0xB0, 0x4A, 0xE5, 0x13, 0x63, 0xDC, 0x44,
  40092. 0xC4, 0x7E, 0x86, 0x9C, 0xAD, 0x69, 0x29, 0xFD,
  40093. 0xA1, 0xFE, 0xAD, 0x3B, 0x59, 0x24, 0x2F, 0x70,
  40094. 0xAE, 0x5F, 0x2C, 0x00, 0xFE, 0x01, 0x09, 0xA3,
  40095. 0x10, 0x87, 0xF0, 0xAD, 0xFA, 0x9B, 0x83, 0x8F,
  40096. 0x48, 0x96, 0x8B, 0x9A, 0x35, 0xE7, 0x4D, 0xAA,
  40097. 0xEC, 0xA4, 0xCD, 0x26, 0x7C, 0x3E, 0xAC, 0x93,
  40098. 0x26, 0x9D, 0x6B, 0x83, 0x34, 0xC4, 0x71, 0xE1,
  40099. 0xC8, 0x93, 0x88, 0x09, 0xAF, 0x00, 0xB5, 0x7F,
  40100. 0xD9, 0x5A, 0x8E, 0x36, 0xC1, 0x2E, 0x7E, 0xF1,
  40101. 0x0C, 0xC5, 0x2A, 0xB3, 0xE4, 0x48, 0xDF, 0xFB,
  40102. 0xFF, 0x99, 0xC9, 0x66, 0xD2, 0x28, 0x46, 0x7C,
  40103. 0x43, 0x39, 0x96, 0x69, 0x95, 0x42, 0xAC, 0xE0,
  40104. 0xC2, 0x0C, 0x65, 0x99, 0xC8, 0xB0, 0xAE, 0x76,
  40105. 0xE8, 0x18, 0x3E, 0xA9, 0x1D, 0x44, 0x81, 0x14,
  40106. 0x65, 0xF7, 0xDF, 0xD1, 0xD1, 0x7B, 0x7C, 0x28,
  40107. 0xE0, 0x77, 0x9D, 0x79, 0x9C, 0xE4, 0x1A, 0xF1,
  40108. 0xD0, 0xFF, 0x8E, 0xEA, 0x58, 0x84, 0xB3, 0x47,
  40109. 0xBC, 0xA1, 0x47, 0x48, 0xB7, 0xC3, 0xD5, 0xD1,
  40110. 0xF3, 0xDD, 0xA6, 0x3B, 0x15, 0x4C, 0xB3, 0xB5,
  40111. 0xFD, 0x52, 0x9D, 0x7E, 0xF0, 0xC7, 0x40, 0x2C,
  40112. 0x34, 0xBC, 0xCF, 0x1C, 0x67, 0x30, 0xC0, 0x4D,
  40113. 0xA1, 0xC7, 0x5E, 0xAD, 0xAF, 0xCD, 0xFA, 0x21,
  40114. 0xE4, 0xB5, 0x33, 0x8B, 0x37, 0x2D, 0xCF, 0x4D,
  40115. 0x07, 0x48, 0x61, 0xB0, 0xB6, 0x8B, 0x27, 0x05,
  40116. 0xA0, 0x8C, 0x71, 0x95, 0x84, 0x02, 0xB2, 0x1E,
  40117. 0x59, 0xBC, 0xB6, 0xE2, 0x2C, 0x3C, 0x20, 0x4C,
  40118. 0xDE, 0x1E, 0x35, 0x24, 0xC1, 0x5B, 0x3C, 0xB4,
  40119. 0x2A, 0x8C, 0xA7, 0x2D, 0xE3, 0xDC, 0x45, 0x26,
  40120. 0x6E, 0x29, 0x52, 0x5D, 0x24, 0x8A, 0xC2, 0x16,
  40121. 0x73, 0xDB, 0x80, 0xF2, 0x91, 0xEC, 0x05, 0x3E,
  40122. 0x2E, 0x9E, 0x39, 0x12, 0x5E, 0x11, 0x80, 0x24,
  40123. 0xF5, 0xFC, 0x86, 0x4C, 0xD9, 0xF9, 0x70, 0x59,
  40124. 0xC8, 0xC8, 0x57, 0x5D, 0x0F, 0x68, 0x75, 0x3C,
  40125. 0x7A, 0x3D, 0x1B, 0xF7, 0xD0, 0xDF, 0xE2, 0xF9,
  40126. 0xBD, 0x44, 0xFD, 0x21, 0x75, 0x86, 0x77, 0x25,
  40127. 0xAF, 0xD3, 0x28, 0x55, 0x2A, 0x60, 0x7D, 0x79,
  40128. 0x9C, 0x72, 0x2F, 0x6E, 0xAB, 0x2F, 0x26, 0x44,
  40129. 0x0C, 0xFF, 0x52, 0xBD, 0xA1, 0xA9, 0x07, 0xBD,
  40130. 0x9D, 0x2A, 0x64, 0x2E, 0x0B, 0xA1, 0xB8, 0x78,
  40131. 0xD3, 0xC4, 0x84, 0x9A, 0xE1, 0xDB, 0xB4, 0x4A,
  40132. 0x4C, 0x45, 0x7A, 0x8E, 0xD5, 0xA3, 0x6B, 0x09,
  40133. 0x8D, 0x72, 0x8E, 0x6D, 0x17, 0x34, 0xFF, 0xD6,
  40134. 0xED, 0x24, 0x19, 0x7D, 0xC6, 0x2D, 0x5B, 0x82,
  40135. 0x68, 0xAE, 0x25, 0x33, 0xBB, 0xCB, 0x7D, 0xFD,
  40136. 0x00, 0x15, 0x83, 0xEA, 0xBB, 0xE7, 0x40, 0x3D,
  40137. 0x80, 0xD5, 0x9E, 0x6C, 0xE0, 0x3C, 0x7E, 0x3E,
  40138. 0x12, 0xC7, 0x36, 0x7E, 0x41, 0x84, 0xE8, 0xB4,
  40139. 0x16, 0xCA, 0x4A, 0xB7, 0xEB, 0x16, 0xEC, 0xAB,
  40140. 0x5A, 0x69, 0x24, 0x7F, 0x5E, 0x81, 0x86, 0x7D,
  40141. 0x30, 0x61, 0x4E, 0x0F, 0x75, 0x39, 0xEE, 0xF2,
  40142. 0xF4, 0xDC, 0x5E, 0x23, 0x40, 0xE8, 0x3C, 0xC0,
  40143. 0x10, 0xAD, 0x5E, 0xE6, 0x06, 0x8E, 0x5F, 0x55,
  40144. 0xC5, 0x69, 0x65, 0x5F, 0xA3, 0x6E, 0x73, 0x86,
  40145. 0x82, 0x32, 0x5F, 0x36, 0xA7, 0x6B, 0x2C, 0x26,
  40146. 0xCD, 0x64, 0xC8, 0x57, 0x1F, 0x06, 0x7A, 0xAB,
  40147. 0x8B, 0xA7, 0xDB, 0x53, 0x48, 0x1A, 0x06, 0x8D,
  40148. 0x36, 0xF1, 0x77, 0x74, 0xE6, 0xF5, 0x18, 0x62,
  40149. 0x8E, 0x8A, 0xBF, 0xB7, 0x7F, 0x72, 0x44, 0xAC,
  40150. 0xC8, 0x9A, 0x0E, 0x60, 0x4B, 0xAB, 0xB2, 0x9E,
  40151. 0x95, 0xDF, 0x95, 0x28, 0x98, 0x78, 0xBB, 0xA9,
  40152. 0x5D, 0x8E, 0xEE, 0xB4, 0x84, 0xF5, 0x81, 0x7E,
  40153. 0xA1, 0x53, 0x3E, 0xBB, 0x43, 0xF6, 0xD4, 0xB7,
  40154. 0x60, 0xFD, 0xF4, 0xF8, 0x68, 0xB6, 0x1D, 0x9A,
  40155. 0xF7, 0xDA, 0x77, 0xFA, 0xBB, 0x74, 0x44, 0xDE,
  40156. 0x7C, 0x32, 0x2D, 0x5C, 0x24, 0xD8, 0x4D, 0xBF,
  40157. 0xE0, 0x5C, 0x70, 0x12, 0x3C, 0x43, 0xCC, 0x5F,
  40158. 0x00, 0xD5, 0x1F, 0xEA, 0x5D, 0xC9, 0x3A, 0x5C,
  40159. 0x32, 0xED, 0xE0, 0xF1, 0x59, 0xA0, 0xB7, 0x71,
  40160. 0xDC, 0x65, 0xD2, 0x88, 0x20, 0x20, 0xD8, 0x59,
  40161. 0x53, 0x2D, 0x30, 0x2D, 0xFC, 0xA9, 0xEA, 0x45,
  40162. 0xB0, 0xF3, 0x1E, 0x66, 0x9F, 0xF6, 0xF1, 0x5E,
  40163. 0x9B, 0x67, 0x1D, 0xBF, 0x5E, 0x19, 0xB3, 0x2A,
  40164. 0xE8, 0xCE, 0xE5, 0x90, 0xFE, 0x82, 0x5C, 0x19,
  40165. 0x7B, 0x84, 0x3E, 0x45, 0xFF, 0x5D, 0xC2, 0x2E,
  40166. 0x49, 0x6A, 0xB1, 0x2D, 0x50, 0x2D, 0x21, 0xF7,
  40167. 0x2A, 0xA2, 0x39, 0x47, 0x8D, 0xB5, 0x17, 0x64,
  40168. 0x3E, 0x96, 0x13, 0x90, 0x53, 0xEA, 0x57, 0x4C,
  40169. 0xDB, 0x3D, 0x43, 0xC3, 0xE7, 0xD6, 0x5C, 0x54,
  40170. 0x89, 0xDF, 0x6E, 0xF9, 0xE4, 0xC6, 0x64, 0xF0,
  40171. 0x88, 0x1C, 0xD0, 0xF6, 0x9D, 0x9E, 0xD7, 0xCD,
  40172. 0x2C, 0xFB, 0xCC, 0x54, 0x0E, 0x96, 0xD7, 0x4E,
  40173. 0x05, 0xD2, 0xB3, 0x88, 0x85, 0xD8, 0x60, 0xA4,
  40174. 0xF2, 0xE4, 0xD7, 0xFF, 0xAF, 0x12, 0x2E, 0xBA,
  40175. 0xC4, 0x5A, 0x3A, 0x3E, 0xC5, 0xD7, 0xF3, 0x60,
  40176. 0x4F, 0x27, 0xEF, 0xE0, 0x35, 0xAC, 0x4A, 0x8B,
  40177. 0x14, 0x7D, 0xC4, 0xEF, 0x61, 0x9A, 0x69, 0x2E,
  40178. 0x49, 0x80, 0x04, 0x0C, 0x18, 0xB9, 0x42, 0xC6,
  40179. 0x8C, 0x8A, 0x99, 0x43, 0xA6, 0x5A, 0xCD, 0x72,
  40180. 0x20, 0xAD, 0xFD, 0x9C, 0xC4, 0xAA, 0xDF, 0x6C,
  40181. 0x6C, 0x03, 0xEF, 0x48, 0x3E, 0xFB, 0x4A, 0xBC,
  40182. 0xAA, 0x44, 0xEE, 0xC4, 0x25, 0x8F, 0xF9, 0x8A,
  40183. 0xC2, 0x24, 0x73, 0x15, 0xFA, 0x0E, 0xCB, 0x00,
  40184. 0xEE, 0x9B, 0x39, 0x3F, 0x60, 0x1F, 0x00, 0x95,
  40185. 0xCA, 0xFE, 0xC2, 0x2C, 0x35, 0x5F, 0xD9, 0xD1,
  40186. 0x29, 0xB5, 0x4D, 0xC1, 0x66, 0x51, 0x8F, 0x17,
  40187. 0x3B, 0xF4, 0xF1, 0x49, 0x42, 0x36, 0x0C, 0x5B,
  40188. 0x58, 0xF2, 0x9B, 0x59, 0x01, 0xFB, 0x15, 0x7F,
  40189. 0x21, 0x90, 0x1F, 0x56, 0x69, 0x8B, 0xE2, 0xA5,
  40190. 0x44, 0xCB, 0x84, 0x98, 0x4B, 0x75, 0xA8, 0xCB,
  40191. 0x83, 0x0D, 0xE8, 0x1C, 0x91, 0x7F, 0xE4, 0x57,
  40192. 0x81, 0x16, 0x34, 0x2F, 0xCE, 0x01, 0xAA, 0x62,
  40193. 0x54, 0x44, 0xB7, 0xD6, 0xC7, 0xF1, 0x68, 0x9A,
  40194. 0x00, 0x3B, 0x71, 0x16, 0xF9, 0x96, 0x6A, 0x90,
  40195. 0x6C, 0x2C, 0x4E, 0x58, 0xBC, 0xDD, 0xE9, 0x3B,
  40196. 0x60, 0xB7, 0xA0, 0x97, 0xEE, 0xD6, 0x34, 0xDD,
  40197. 0x49, 0x4A, 0xD9, 0x85, 0xD1, 0xB7, 0x95, 0x14,
  40198. 0xEC, 0x6A, 0x40, 0xE8, 0x31, 0x80, 0xF1, 0xD8,
  40199. 0x5F, 0x75, 0xF6, 0x92, 0x3A, 0x4F, 0xCD, 0x0A,
  40200. 0x6E, 0xBF, 0xA1, 0x27, 0x48, 0x79, 0x27, 0x04,
  40201. 0x76, 0x2C, 0xAB, 0x25, 0x06, 0xEB, 0x43, 0xDD,
  40202. 0x1B, 0x4B, 0x24, 0xFC, 0x93, 0x51, 0x1C, 0x45,
  40203. 0xF6, 0xAE, 0x77, 0xCF, 0xC9, 0xE6, 0x20, 0xE4,
  40204. 0xA5, 0x2B, 0x3D, 0x7D, 0xF0, 0xEB, 0x51, 0x7C,
  40205. 0xCA, 0xFE, 0x58, 0xBA, 0xC4, 0x07, 0x95, 0x75,
  40206. 0x62, 0x0C, 0x50, 0x68, 0x88, 0x1A, 0x8A, 0x0D,
  40207. 0x1B, 0x5C, 0x53, 0x1A, 0x9C, 0xA8, 0x4E, 0xFE,
  40208. 0x63, 0x9B, 0xDB, 0x05, 0x70, 0x01, 0x75, 0xA1,
  40209. 0x3A, 0x08, 0xFA, 0x51, 0xD5, 0xF6, 0x81, 0xDE,
  40210. 0x69, 0xE5, 0x40, 0xB3, 0xF8, 0x7C, 0x46, 0x97,
  40211. 0xA6, 0x4E, 0xA8, 0x51, 0x47, 0x9C, 0xB9, 0x25,
  40212. 0xCD, 0x4E, 0xED, 0xFC, 0xEE, 0x03, 0x6A, 0xCD,
  40213. 0x93, 0x65, 0xB3, 0x68, 0x09, 0x6F, 0xE8, 0x00,
  40214. 0x6A, 0x3F, 0xBF, 0xE8, 0x6F, 0x09, 0xE9, 0xF2,
  40215. 0x6F, 0x44, 0x2E, 0xB1, 0x81, 0x76, 0x04, 0xDD,
  40216. 0x6E, 0xF4, 0x93, 0x61, 0xE5, 0x78, 0xD4, 0xDA,
  40217. 0xBF, 0x05, 0xA1, 0xF4, 0x9D, 0xFD, 0x57, 0x06,
  40218. 0x9C, 0x13, 0x45, 0x97, 0xF2, 0x48, 0xE6, 0x1A,
  40219. 0xB5, 0xAD, 0x09, 0x11, 0x04, 0xBB, 0xA0, 0xA8,
  40220. 0xA3, 0xA3, 0x33, 0xCD, 0x42, 0x2C, 0x66, 0xC2,
  40221. 0x94, 0x80, 0x15, 0x9D, 0x56, 0x74, 0x02, 0xEE,
  40222. 0xA7, 0xE4, 0x90, 0xDD, 0xFB, 0x0B, 0x3B, 0xF0,
  40223. 0x7A, 0x02, 0x44, 0xE8, 0x11, 0xC4, 0x3A, 0xFE,
  40224. 0x73, 0x2A, 0x4C, 0x92, 0x3C, 0x23, 0x37, 0x8B,
  40225. 0x4F, 0x28, 0x8E, 0x1C, 0x4E, 0x7D, 0x0D, 0x6B,
  40226. 0xFD, 0x20, 0xB5, 0x93, 0xB3, 0x75, 0x30, 0x28,
  40227. 0xC7, 0x7E, 0x67, 0xC4, 0xDE, 0xDA, 0x27, 0xA9,
  40228. 0xE3, 0xF2, 0xF5, 0x25, 0x98, 0x5F, 0x6B, 0xBE,
  40229. 0x11, 0x80, 0x23, 0x49, 0x30, 0xC8, 0x8A, 0x63,
  40230. 0xF9, 0xC4, 0x14, 0x77, 0x2A, 0xE2, 0x21, 0x42,
  40231. 0x28, 0x1C, 0xEB, 0x9F, 0x7B, 0x70, 0xA8, 0x2B,
  40232. 0xFB, 0x25, 0x36, 0xA6, 0xAC, 0xFE, 0x8E, 0xFF,
  40233. 0xB6, 0x86, 0x09, 0x15, 0x7E, 0xD9, 0x26, 0x8F,
  40234. 0xDB, 0xF2, 0x2D, 0xC2, 0xFA, 0xAE, 0xDA, 0x50,
  40235. 0xF6, 0x24, 0x53, 0xDB, 0xBF, 0x92, 0x9D, 0x7E,
  40236. 0x48, 0xCC, 0x75, 0xAC, 0xD0, 0xD3, 0x45, 0x09,
  40237. 0x2F, 0x01, 0x60, 0xBB, 0xAE, 0xCB, 0xE6, 0xB3,
  40238. 0x30, 0xDA, 0xD9, 0xB6, 0x12, 0xCD, 0xF5, 0x11,
  40239. 0xCF, 0x2B, 0x2A, 0xC6, 0x61, 0x9A, 0x05, 0x59,
  40240. 0x08, 0x58, 0x64, 0xEC, 0xDB, 0x77, 0xCF, 0x64,
  40241. 0xE2, 0x4B, 0x6E, 0xF4, 0x07, 0x68, 0x5E, 0xE9,
  40242. 0x31, 0xB1, 0x38, 0x67, 0xF9, 0x29, 0x2E, 0x7A,
  40243. 0xD2, 0x03, 0xA6, 0x29, 0x3F, 0x22, 0x58, 0x66,
  40244. 0x6A, 0x07, 0xD8, 0xFD, 0xC5, 0x03, 0xEE, 0x66,
  40245. 0xD4, 0x66, 0x70, 0x6D, 0xA4, 0xC4, 0xA1, 0xEE,
  40246. 0xCD, 0x4D, 0xFA, 0x3C, 0x34, 0x36, 0xC2, 0xC5,
  40247. 0x1E, 0x86, 0xB8, 0x7B, 0x7C, 0xBC, 0x67, 0x16,
  40248. 0xF3, 0x6E, 0xF2, 0xB7, 0xEA, 0x96, 0x1B, 0x0D,
  40249. 0xA2, 0xC8, 0x42, 0xBF, 0x30, 0x09, 0x2A, 0x6D,
  40250. 0x9D, 0x35, 0xB3, 0x92, 0xBA, 0x3E, 0xE2, 0xE9,
  40251. 0xE2, 0xAA, 0x90, 0x70, 0xCE, 0x0F, 0x07, 0xFA,
  40252. 0x7C, 0x3B, 0xF7, 0x66, 0x7F, 0x5C, 0xFE, 0xD9,
  40253. 0x72, 0x1C, 0x4E, 0xFE, 0x7E, 0x86, 0x8E, 0x7F,
  40254. 0x62, 0x8D, 0x41, 0x46, 0x7B, 0x43, 0x17, 0xB9,
  40255. 0x44, 0xED, 0x39, 0x1B, 0x3E, 0xF9, 0x2D, 0xC7,
  40256. 0x5C, 0x9D, 0xAC, 0x05, 0x00, 0xC6, 0x85, 0x4E,
  40257. 0xB8, 0xBC, 0x29, 0xDF, 0x6D, 0x6A, 0xCC, 0xEB,
  40258. 0xD6, 0x44, 0x86, 0xAA, 0xC9, 0x55, 0x49, 0xA1,
  40259. 0x3F, 0x59, 0x5E, 0xAF, 0xD5, 0xC9, 0x96, 0x19,
  40260. 0x84, 0xC0, 0x4D, 0x1B, 0xE5, 0x2C, 0x42, 0x8D,
  40261. 0x2C, 0xC8, 0x83, 0x00, 0x26, 0xBF, 0x46, 0x9F,
  40262. 0x20, 0x97, 0xEC, 0x2C, 0xA9, 0x2C, 0xF0, 0xA7,
  40263. 0x11, 0xED, 0xE2, 0xA2, 0x57, 0x83, 0x40, 0x92,
  40264. 0xF3, 0x58, 0xB7, 0x4E, 0xD6, 0x3A, 0x9D, 0xF0,
  40265. 0xDD, 0xD4, 0x5F, 0x82, 0x58, 0xD3, 0x72, 0x05,
  40266. 0x69, 0xFF, 0x1E, 0xBC, 0x74, 0x90, 0x87, 0xB5,
  40267. 0x7A, 0xEE, 0xF8, 0xCE, 0x3F, 0x59, 0xE1, 0xC0,
  40268. 0x46, 0x24, 0xF8, 0x9D, 0x93, 0x51, 0x4A, 0x44,
  40269. 0xFB, 0xEA, 0x58, 0xA6, 0xAC, 0x9A, 0x7C, 0xA3,
  40270. 0x11, 0xA3, 0x47, 0x44, 0x24, 0x11, 0xF5, 0x56,
  40271. 0x1A, 0x3B, 0xCF, 0xEC, 0xD9, 0x2B, 0x6C, 0xBA,
  40272. 0xA6, 0xA2, 0x67, 0xB9, 0xE0, 0xCB, 0x3F, 0x8D,
  40273. 0xA8, 0xC4, 0x8A, 0x45, 0xAB, 0xE2, 0x10, 0x19,
  40274. 0x10, 0xC9, 0xDB, 0x01, 0x64, 0xC0, 0x0B, 0x6F,
  40275. 0x3B, 0xA1, 0xE9, 0xEB, 0x74, 0x9A, 0x63, 0x93,
  40276. 0xE5, 0x74, 0x3F, 0xD3, 0x7B, 0xEA, 0x8C, 0xD6,
  40277. 0x7D, 0x66, 0xDD, 0x90, 0x6C, 0x69, 0x67, 0x05,
  40278. 0xAD, 0x70, 0xF1, 0xFA, 0x52, 0xBB, 0xD5, 0x3D,
  40279. 0x0E, 0x7E, 0x87, 0xE0, 0x98, 0xAF, 0xA6, 0xE6,
  40280. 0x0E, 0x25, 0x91, 0x70, 0xCA, 0x36, 0xE4, 0xF8,
  40281. 0xF7, 0x95, 0x1C, 0x48, 0xF6, 0x62, 0x9A, 0x4D,
  40282. 0xE4, 0xE7, 0x3A, 0x92, 0xC6, 0x2E, 0xAB, 0x8A,
  40283. 0x75, 0x7C, 0x45, 0xDA, 0x54, 0xB1, 0x6D, 0x2E,
  40284. 0xCC, 0x13, 0x46, 0x67, 0x8F, 0xFF, 0xDA, 0x18,
  40285. 0xE1, 0x4C, 0xE4, 0x6A, 0xB6, 0xAC, 0x65, 0x32,
  40286. 0x0C, 0x63, 0xD5, 0x43, 0xB5, 0x8B, 0xB1, 0x52,
  40287. 0xEE, 0x0C, 0xBB, 0x62, 0x34, 0x30, 0xDB, 0xF7,
  40288. 0x08, 0xC6, 0xE8, 0x5B, 0x07, 0x66, 0x6D, 0x4B,
  40289. 0x39, 0xC6, 0x94, 0x2B, 0x22, 0x9E, 0x3E, 0x45,
  40290. 0x62, 0x3D, 0x05, 0x03, 0x2B, 0x16, 0x71, 0xBB,
  40291. 0x85, 0x1B, 0x6E, 0x84, 0xD3, 0x48, 0x4D, 0x63,
  40292. 0x26, 0x60, 0x97, 0x45, 0xB8, 0xEA, 0x43, 0x96,
  40293. 0x00, 0xFE, 0x0B, 0x85, 0xBD, 0x22, 0x40, 0xA4,
  40294. 0xA7, 0x2F, 0xC1, 0xEB, 0xFD, 0xB5, 0x22, 0xD5,
  40295. 0x1F, 0xB3, 0xEA, 0x7C, 0x6D, 0x20, 0xFB, 0x98,
  40296. 0xA5, 0xF2, 0x84, 0x70, 0xF7, 0xB9, 0x2A, 0x12,
  40297. 0x63, 0x0C, 0x2D, 0x97, 0x6C, 0xC2, 0x76, 0xAC,
  40298. 0x32, 0xE2, 0xB1, 0x3A, 0xB3, 0xAB, 0x9E, 0xBB,
  40299. 0x61, 0xB4, 0x6A, 0x5F, 0x2D, 0x4D, 0xCE, 0x0D,
  40300. 0xFB, 0x97, 0x80, 0x89, 0x4A, 0x81, 0xFB, 0xB2,
  40301. 0x72, 0x37, 0x66, 0xB9, 0x08, 0xBF, 0xCD, 0x9F,
  40302. 0x63, 0xB2, 0xBA, 0x54, 0xF1, 0x9E, 0xEC, 0x11,
  40303. 0x67, 0x26, 0xC7, 0x98, 0xDD, 0xA3, 0xC5, 0x50,
  40304. 0x86, 0x17, 0xD5, 0xCF, 0x51, 0x97, 0x22, 0x65,
  40305. 0x2B, 0x71, 0xF7, 0x34, 0x84, 0x55, 0xC9, 0xD1,
  40306. 0xFE, 0x75, 0x42, 0x0A, 0x5A, 0x31, 0x59, 0xE8,
  40307. 0x8A, 0x0D, 0xE5, 0x77, 0x1C, 0xF5, 0xFD, 0x27,
  40308. 0x05, 0x05, 0xF7, 0x28, 0xDA, 0x54, 0xAB, 0xBD,
  40309. 0xDC, 0x50, 0xB8, 0xDB, 0x2E, 0xB4, 0x28, 0x41,
  40310. 0x30, 0x04, 0x40, 0xD5, 0xF0, 0x12, 0xD7, 0x16,
  40311. 0x3D, 0x8F, 0x41, 0xE7, 0x70, 0x76, 0x82, 0xB9,
  40312. 0xC4, 0xB2, 0x1F, 0x57, 0x10, 0xB6, 0xC4, 0x84,
  40313. 0x0D, 0xB1, 0xB8, 0x21, 0xB2, 0x77, 0x09, 0xF6,
  40314. 0xD5, 0x9C, 0xE4, 0xA2, 0xFA, 0x83, 0x13, 0x56,
  40315. 0x94, 0x3F, 0x37, 0x6D, 0x0D, 0x7C, 0x7E, 0xA0,
  40316. 0xE5, 0xC8, 0xD9, 0x42, 0x0F, 0x35, 0xB1, 0xDC,
  40317. 0xB9, 0x49, 0xD5, 0xED, 0xA8, 0x90, 0x09, 0x14,
  40318. 0xAE, 0x63, 0xB5, 0xEA, 0x62, 0x0D, 0x9E, 0x6D,
  40319. 0x93, 0xBD, 0x3A, 0xEA, 0x24, 0xB5, 0xAC, 0xC9,
  40320. 0xD1, 0x7B, 0xBC, 0xC6, 0xC4, 0xBA, 0x68, 0xB1,
  40321. 0x65, 0xFE, 0xAB, 0x30, 0xD4, 0x92, 0xD9, 0xC1,
  40322. 0x94, 0x84, 0xE1, 0x20, 0x4E, 0x28, 0x7C, 0x3A,
  40323. 0x3E, 0x8B, 0x44, 0x79, 0xC7, 0xB5, 0xA5, 0x95,
  40324. 0xC2, 0xC9, 0xA8, 0x3F, 0x92, 0x67, 0x06, 0x9A,
  40325. 0x12, 0xD3, 0xAE, 0x78, 0x87, 0x0E, 0x31, 0x54,
  40326. 0x26, 0xDF, 0x97, 0xEB, 0x6C, 0xF3, 0xC9, 0x53,
  40327. 0x39, 0xED, 0x50, 0x5A, 0xF9, 0x6A, 0x03, 0x27,
  40328. 0x8E, 0xC6, 0x79, 0x5B, 0xD4, 0xD3, 0x57, 0x97,
  40329. 0xFD, 0xF5, 0xCB, 0x14, 0xDB, 0xBE, 0x39, 0xB9,
  40330. 0x64, 0x8A, 0x75, 0xAA, 0xE3, 0x4A, 0x19, 0x59,
  40331. 0x69, 0x7D, 0xF8, 0x7D, 0x8C, 0xB8, 0x2F, 0x32,
  40332. 0x57, 0xBF, 0x84, 0x9E, 0x45, 0x4E, 0xC4, 0xA0,
  40333. 0x65, 0xA4, 0x0B, 0x73, 0x36, 0xC5, 0xD1, 0x07,
  40334. 0xF8, 0x1C, 0x91, 0x07, 0xB8, 0x0B, 0x4B, 0xE5,
  40335. 0x4F, 0xE6, 0xA1, 0xDF, 0x29, 0x03, 0xE7, 0x68,
  40336. 0xA4, 0x32, 0x8E, 0x21, 0x8F, 0x15, 0x51, 0x57,
  40337. 0x65, 0x16, 0xF0, 0x55, 0x71, 0x8C, 0x28, 0xD8,
  40338. 0x82, 0xDC, 0x8A, 0xC1, 0xE7, 0x5C, 0xF2, 0xD5,
  40339. 0xB8, 0x18, 0x16, 0x9F, 0x63, 0x89, 0x21, 0xF1,
  40340. 0xA6, 0xED, 0x21, 0xDA, 0xC8, 0x0A, 0x10, 0x21,
  40341. 0x18, 0x98, 0xD0, 0xF2, 0x9E, 0xDE, 0x5A, 0xA1,
  40342. 0x51, 0xC9, 0x18, 0x3B, 0x68, 0x79, 0x75, 0xE7,
  40343. 0xF4, 0xF9, 0xBF, 0x5F, 0xBE, 0x61, 0x35, 0xA9,
  40344. 0x02, 0x56, 0x2D, 0x99, 0xD8, 0x95, 0xFA, 0x78,
  40345. 0x8A, 0x67, 0x24, 0x1D, 0xDF, 0x13, 0x14, 0xD0,
  40346. 0xB4, 0xB6, 0x21, 0x11, 0xB7, 0xA4, 0x06, 0x8D,
  40347. 0x1D, 0xF6, 0xD5, 0x50, 0x2A, 0x0A, 0x42, 0x3C,
  40348. 0x7C, 0xF1, 0x1F, 0x15, 0x1C, 0x81, 0x69, 0xDA,
  40349. 0xCC, 0xAC, 0x8F, 0xB9, 0x08, 0x4E, 0xF8, 0x4E,
  40350. 0x3E, 0x77, 0x26, 0x4A, 0x1F, 0x72, 0x89, 0xCA,
  40351. 0x91, 0x77, 0x99, 0xBF, 0x28, 0xD2, 0x31, 0x65,
  40352. 0x30, 0x37, 0x84, 0x66, 0x8A, 0x1C, 0xC6, 0x59,
  40353. 0x7D, 0x48, 0x9B, 0x4D, 0xDC, 0x87, 0x4F, 0xD2,
  40354. 0x04, 0xA0, 0x8B, 0x8B, 0x37, 0x3B, 0x1A, 0xDB,
  40355. 0xCF, 0x63, 0x39, 0x07, 0xF3, 0x37, 0xCF, 0x0E,
  40356. 0x2F, 0xEB, 0xE6, 0x2A, 0xA1, 0x4C, 0xE0, 0x75,
  40357. 0x3F, 0xAB, 0xF7, 0xDE, 0x48, 0x83, 0x79, 0x89,
  40358. 0x30, 0xA7, 0x1B, 0xE8, 0x73, 0x8E, 0x9D, 0x1D,
  40359. 0xF6, 0x5C, 0x91, 0x4F, 0x44, 0x7C, 0x04, 0xA7,
  40360. 0x07, 0xC8, 0xCC, 0x4A, 0x5C, 0x81, 0xAD, 0x48,
  40361. 0x7C, 0xE5, 0x19, 0x5A, 0xC4, 0x29, 0x80, 0x14,
  40362. 0xFA, 0xC2, 0x26, 0x1C, 0x50, 0x28, 0xB9, 0xF6,
  40363. 0x7F, 0x8D, 0x51, 0x9A, 0xDA, 0xBB, 0x8E, 0x90,
  40364. 0xBA, 0x3B, 0xD9, 0x4D, 0x61, 0xBE, 0xFD, 0x33,
  40365. 0xC0, 0xCA, 0x7B, 0x09, 0xFF, 0x36, 0x84, 0x70,
  40366. 0x11, 0xB4, 0xBE, 0x81, 0xFE, 0x71, 0xEE, 0x81,
  40367. 0xD7, 0x61, 0xBB, 0x83, 0xA6, 0xA0, 0xDC, 0x20,
  40368. 0x04, 0x02, 0x4C, 0x1B, 0x4D, 0xED, 0x8A, 0xC1,
  40369. 0x38, 0x70, 0xC3, 0x69, 0xC9, 0x50, 0xC2, 0x17,
  40370. 0x64, 0xAD, 0x9D, 0x44, 0x63, 0x44, 0xE5, 0x32,
  40371. 0x7B, 0x90, 0xE3, 0xEF, 0x45, 0x28, 0xA6, 0x23,
  40372. 0x92, 0xCB, 0xA1, 0xFC, 0xA8, 0xB4, 0x39, 0xF1,
  40373. 0xB1, 0x00, 0x1F, 0x06, 0xD4, 0x91, 0x5D, 0xDB,
  40374. 0xAC, 0x7D, 0x87, 0xD4, 0xEE, 0xCD, 0x4A, 0x06,
  40375. 0x3E, 0xB4, 0x84, 0x65, 0xAA, 0x47, 0x05, 0x41,
  40376. 0x7C, 0x95, 0x47, 0x3A, 0x49, 0x80, 0xC5, 0xAC,
  40377. 0x32, 0x41, 0x6A, 0x3A, 0x2B, 0xB9, 0xD9, 0x21,
  40378. 0x80, 0xC7, 0xC1, 0xD0, 0xC9, 0x95, 0x4B, 0xC3,
  40379. 0xEA, 0x0D, 0x3F, 0x0E, 0xE4, 0x5A, 0xD8, 0xBD,
  40380. 0x11, 0xD0, 0x76, 0x6D, 0x3C, 0xA7, 0x64, 0xD8,
  40381. 0xCA, 0x4C, 0x8F, 0x58, 0x2C, 0xDD, 0x95, 0x1F,
  40382. 0xBB, 0x76, 0x8D, 0x10, 0xFD, 0xAD, 0x45, 0xCE,
  40383. 0x71, 0x6E, 0x27, 0x92, 0xC4, 0xA6, 0x17, 0x46,
  40384. 0x95, 0xDB, 0xD8, 0xEA, 0x9A, 0x5F, 0x0E, 0xE0,
  40385. 0x0A, 0xA2, 0xF5, 0x79, 0xC3, 0x74, 0xA7, 0x70,
  40386. 0x99, 0x3B, 0x23, 0xD7, 0x3E, 0xA4, 0x96, 0xB5,
  40387. 0x54, 0x77, 0x71, 0x8D, 0x78, 0x2E, 0xCC, 0x0A,
  40388. 0x4E, 0xF8, 0xA9, 0x96, 0xEE, 0xB4, 0x4B, 0x5B,
  40389. 0xDC, 0x52, 0x6D, 0xE1, 0x61, 0x36, 0xE1, 0x32,
  40390. 0xD6, 0xA2, 0x7B, 0x2E, 0xCC, 0x78, 0x92, 0xA1,
  40391. 0x81, 0x59, 0xB8, 0xC7, 0x04, 0x11, 0x3D, 0xF0,
  40392. 0xF9, 0xF9, 0x3E, 0x47, 0x3C, 0xEA, 0xD5, 0x30,
  40393. 0x2D, 0xAE, 0xC0, 0x47, 0xC8, 0x61, 0xCC, 0x9C,
  40394. 0x2E, 0xC0, 0x40, 0x16, 0x11, 0x73, 0x13, 0xF3,
  40395. 0x19, 0xAE, 0x72, 0x44, 0x72, 0xC5, 0x59, 0x51,
  40396. 0x2E, 0x9F, 0xE3, 0x07, 0xB0, 0xCA, 0x6B, 0xB0,
  40397. 0x15, 0x20, 0xB4, 0x25, 0x00, 0xED, 0xFD, 0xAC,
  40398. 0xD6, 0x34, 0x8B, 0xCA, 0xE8, 0xC6, 0x3B, 0xFD,
  40399. 0x02, 0x22, 0xE6, 0x91, 0x2B, 0x4B, 0x61, 0xDF,
  40400. 0x63, 0x5C, 0x2B, 0x5F, 0x82, 0x07, 0x23, 0x59,
  40401. 0x82, 0x5E, 0x0E, 0x21, 0xF7, 0x9C, 0x37, 0x1C,
  40402. 0x7E, 0x6F, 0xD4, 0xFA, 0x91, 0x40, 0x8B, 0x98,
  40403. 0x68, 0xBD, 0x60, 0x2F, 0x0A, 0xC8, 0xC8, 0x99,
  40404. 0xA1, 0xC6, 0x10, 0xF1, 0x27, 0x53, 0xD3, 0xFB,
  40405. 0x23, 0x02, 0xE7, 0x8E, 0x95, 0xB1, 0xF0, 0x21,
  40406. 0xCB, 0x90, 0xEE, 0x8D, 0xE0, 0x27, 0x57, 0xDE,
  40407. 0x40, 0xA3, 0xE7, 0x8F, 0x61, 0xC1, 0x8F, 0xC5,
  40408. 0x0C, 0x0F, 0xBA, 0x05, 0xA0, 0x58, 0x8E, 0x86,
  40409. 0x8A, 0xF5, 0x72, 0xE1, 0x34, 0xB4, 0xF6, 0x8E,
  40410. 0x6E, 0xA4, 0x21, 0x75, 0x43, 0x73, 0xE7, 0x32,
  40411. 0x72, 0x80, 0x9B, 0xE7, 0x1D, 0x78, 0x8F, 0x0D,
  40412. 0x06, 0x47, 0x9E, 0x4D, 0xB4, 0xAC, 0x3E, 0x0D,
  40413. 0xB8, 0x11, 0x23, 0xFF, 0xAD, 0xB9, 0x23, 0xE0,
  40414. 0xA4, 0x37, 0xA6, 0x3D, 0xC2, 0x15, 0xF4, 0x64,
  40415. 0x03, 0x1F, 0x0A, 0x68, 0xED, 0x37, 0x37, 0xE8,
  40416. 0x3E, 0x5B, 0x49, 0x78, 0xFC, 0xFC, 0x12, 0x06,
  40417. 0xE8, 0xC7, 0xCD, 0x3A, 0xAF, 0xD4, 0x54, 0xA7,
  40418. 0x04, 0x7B, 0xFC, 0x66, 0xA6, 0xA8, 0x1C, 0x38,
  40419. 0x0C, 0x26, 0x08, 0xE6, 0xEE, 0x47, 0x25, 0x80,
  40420. 0x59, 0xA5, 0x39, 0x81, 0x20, 0xEE, 0x5F, 0x49,
  40421. 0x9A, 0x01, 0x37, 0xE9, 0x96, 0x18, 0xD0, 0x05,
  40422. 0x2D, 0xE3, 0x73, 0xD5, 0x08, 0x3B, 0x18, 0x46,
  40423. 0xFE, 0x9E, 0x67, 0x5B, 0x9E, 0xF8, 0x53, 0x05,
  40424. 0x2F, 0x96, 0x18, 0x9C, 0x09, 0x0D, 0xA6, 0x05,
  40425. 0xB3, 0x9E, 0x2F, 0x0B, 0x5A, 0xF3, 0x93, 0xFF,
  40426. 0x29, 0xF3, 0x4F, 0x62, 0xD5, 0x9A, 0xCE, 0x74,
  40427. 0x64, 0xD0, 0xBC, 0xB3, 0x08, 0xF1, 0xD3, 0x22,
  40428. 0xA5, 0xBE, 0x64, 0x0A, 0xEB, 0xA5, 0xF5, 0x1B,
  40429. 0x7E, 0x0A, 0x44, 0x3B, 0x1D, 0xA9, 0x48, 0x9A,
  40430. 0x2F, 0xED, 0x05, 0x0F, 0x44, 0xB3, 0x6D, 0xAD,
  40431. 0x39, 0x2C, 0xBA, 0x8E, 0x2B, 0xDE, 0x17, 0x38,
  40432. 0xD1, 0x69, 0xEA, 0xAE, 0x4E, 0x97, 0xCD, 0x61,
  40433. 0xBA, 0x75, 0x39, 0xF2, 0x81, 0xBB, 0xA9, 0x0F,
  40434. 0x6F, 0x82, 0xD4, 0xCB, 0xE4, 0x93, 0x82, 0x11,
  40435. 0x72, 0x9A, 0xE9, 0x87, 0xEC, 0xCC, 0x6D, 0xA1,
  40436. 0x7D, 0x47, 0x60, 0x20, 0xB6, 0xEE, 0xC6, 0xAA,
  40437. 0xC0, 0x3C, 0x95, 0x08, 0xA0, 0x8B, 0xFA, 0x04,
  40438. 0xF6, 0x6F, 0x65, 0x48, 0xCA, 0xA7, 0xA3, 0xA8,
  40439. 0xBB, 0x3B, 0x80, 0x91, 0xB6, 0x6D, 0x2F, 0x9D,
  40440. 0x97, 0xBB, 0x52, 0xE6, 0xC4, 0x24, 0x99, 0x97,
  40441. 0x63, 0xAD, 0xD2, 0xFD, 0xB3, 0x94, 0x6D, 0xC1,
  40442. 0xFB, 0xFA, 0x89, 0x45, 0x78, 0x80, 0x3C, 0xAA,
  40443. 0x3F, 0xC0, 0x7E, 0x8D, 0x37, 0x00, 0xA7, 0x70,
  40444. 0xD6, 0x57, 0x2A, 0xD3, 0x17, 0xB1, 0x9E, 0xDF,
  40445. 0x96, 0x98, 0x40, 0xB8, 0x1C, 0xCC, 0xC6, 0xCD,
  40446. 0xCD, 0xB0, 0xF3, 0x23, 0x53, 0xB6, 0x45, 0x78,
  40447. 0xA6, 0xA0, 0x88, 0x61, 0x06, 0x04, 0x8E, 0x1B,
  40448. 0xCD, 0x12, 0x29, 0x50, 0x0F, 0xD2, 0x8C, 0x89,
  40449. 0x51, 0xD1, 0x74, 0x0B, 0xE3, 0xA7, 0x75, 0x8A,
  40450. 0x60, 0x95, 0xEF, 0x6A, 0x98, 0xC7, 0x35, 0xA5,
  40451. 0xC0, 0xFB, 0x4C, 0x88, 0xA1, 0xDA, 0xCE, 0x79,
  40452. 0x3D, 0x4E, 0x4F, 0x91, 0x75, 0x88, 0xE0, 0x5F,
  40453. 0x17, 0xF5, 0xEF, 0xF8, 0x49, 0xFE, 0xB1, 0xDB,
  40454. 0x0D, 0xE8, 0xB2, 0xF7, 0xD4, 0x90, 0xBD, 0xB0,
  40455. 0x6B, 0x3A, 0x1B, 0xB5, 0xC6, 0xFB, 0x93, 0xEF,
  40456. 0xF3, 0xDD, 0x60, 0xEA, 0x67, 0x11, 0xFE, 0x6A,
  40457. 0xCC, 0x2C, 0x64, 0x2A, 0x85, 0x2E, 0x24, 0x39,
  40458. 0x34, 0x6B, 0xBC, 0xF8, 0x89, 0xB3, 0x49, 0x82,
  40459. 0x9C, 0xC0, 0x04, 0x29, 0x6D, 0x25, 0xCB, 0x19,
  40460. 0xE1, 0x53, 0xC6, 0x10, 0x7D, 0x62, 0x07, 0xD2,
  40461. 0x83, 0x8B, 0x89, 0x04, 0x70, 0x06, 0x60, 0x4F,
  40462. 0xB6, 0x10, 0x2B, 0xA0, 0x92, 0xF4, 0x1A, 0x7A,
  40463. 0xD6, 0x4F, 0xDC, 0x6C, 0x6C, 0x27, 0xE5, 0xEC,
  40464. 0x68, 0x1B, 0x95, 0x7C, 0x1C, 0x95, 0x2C, 0xB7,
  40465. 0x0A, 0x8D, 0xC7, 0x57, 0x92, 0x00, 0x4D, 0xC0,
  40466. 0x5F, 0xD4, 0xF4, 0x88, 0x3F, 0x8D, 0x43, 0x12,
  40467. 0x05, 0xE2, 0x14, 0x0E, 0xDD, 0x2C, 0xEC, 0xD5,
  40468. 0x2F, 0x1A, 0xE6, 0x97, 0xDC, 0xFE, 0x96, 0x80,
  40469. 0x67, 0x3B, 0xD4, 0x63, 0x73, 0xFA, 0xC8, 0x4F,
  40470. 0x4C, 0x4F, 0x2D, 0x68, 0x76, 0x44, 0x8E, 0xC2,
  40471. 0x19, 0x99, 0x44, 0xEA, 0xF2, 0x33, 0x23, 0x83,
  40472. 0xC8, 0xB1, 0x7C, 0x27, 0x43, 0x9B, 0x67, 0xF9,
  40473. 0xDE, 0xE1, 0xAE, 0x03, 0xA5, 0xA5, 0x2B, 0x96,
  40474. 0xB2, 0xEC, 0x4A, 0x43, 0xA7, 0x6D, 0xF4, 0xDB,
  40475. 0x32, 0x5B, 0x54, 0xD6, 0x63, 0xEA, 0x65, 0xC2,
  40476. 0xA8, 0x4B, 0x80, 0xCC, 0x65, 0x2D, 0xCE, 0x6F,
  40477. 0x61, 0x2F, 0x58, 0xD1, 0xE5, 0x64, 0x8A, 0x42,
  40478. 0x8D, 0xBA, 0xFA, 0x35, 0x5C, 0x9E, 0xD5, 0x80,
  40479. 0x2D, 0x5C, 0xC3, 0x47, 0xFB, 0x0D, 0x43, 0x20,
  40480. 0x7A, 0xA4, 0x37, 0xB2, 0x2F, 0x0B, 0x43, 0xB9,
  40481. 0x94, 0xD3, 0xD9, 0xC2, 0xD7, 0x02, 0x5D, 0x6A,
  40482. 0x12, 0x99, 0xE7, 0x32, 0x6C, 0xF0, 0x0C, 0x73,
  40483. 0x51, 0x33, 0x84, 0xA9, 0x0C, 0x66, 0xC9, 0x19,
  40484. 0x88, 0x9A, 0xF1, 0xB6, 0xF8, 0x41, 0xB1, 0xDC,
  40485. 0x60, 0xA4, 0x80, 0x73, 0x0B, 0x21, 0xF9, 0xB8,
  40486. 0x01, 0x7E, 0x66, 0x0D, 0xB4, 0x2B, 0x53, 0x8D,
  40487. 0x7D, 0x0B, 0xE1, 0xA3, 0x0C, 0x27, 0xF6, 0x2F,
  40488. 0x27, 0x34, 0x53, 0x75, 0x54, 0xF7, 0x5E, 0x05,
  40489. 0x1C, 0x5A, 0x94, 0x08, 0x14, 0xDE, 0xAA, 0x98,
  40490. 0xD9, 0xA5, 0xA0, 0xBE, 0x80, 0xC1, 0xEB, 0x3C,
  40491. 0xCF, 0x78, 0x88, 0xA4, 0xA2, 0x03, 0xF8, 0x79,
  40492. 0x1F, 0x84, 0x84, 0xA7, 0x0E, 0x95, 0x1A, 0x85,
  40493. 0xEF, 0x4C, 0xBE, 0xA2, 0x99, 0xAB, 0x10, 0xDD,
  40494. 0x85, 0x3F, 0x10, 0x6A, 0x9C, 0xD5, 0xDD, 0x7A,
  40495. 0xFB, 0xF5, 0xD9, 0xD9, 0xAA, 0xDF, 0x03, 0x78,
  40496. 0xAF, 0x1D, 0xEC, 0x18, 0xEB, 0x00, 0xB6, 0x64,
  40497. 0xB5, 0x75, 0xA5, 0x00, 0xDC, 0x36, 0x45, 0xBD,
  40498. 0x0C, 0x66, 0xCE, 0xA9, 0xBB, 0xD1, 0xF7, 0xE4,
  40499. 0x6A, 0xDA, 0x0E, 0x81, 0x0F, 0x6A, 0x71, 0x60,
  40500. 0x5C, 0x41, 0xD2, 0x12, 0x45, 0x14, 0xEF, 0x6F,
  40501. 0xEC, 0x22, 0x73, 0x4C, 0xA7, 0x94, 0xDD, 0x1A,
  40502. 0x42, 0x22, 0x58, 0x14, 0x0C, 0x4E, 0x6D, 0x77,
  40503. 0x7F, 0xF5, 0xC9, 0x69, 0x81, 0xA3, 0xB8, 0x6D,
  40504. 0x1C, 0x39, 0x47, 0xA5, 0xC4, 0x61, 0x1C, 0x91,
  40505. 0x2F, 0x67, 0xC3, 0x5E, 0x87, 0x1A, 0x85, 0x81,
  40506. 0x7D, 0x76, 0xF2, 0xE0, 0xB9, 0xD0, 0x43, 0x33,
  40507. 0xF1, 0xC1, 0xBA, 0x48, 0x6F, 0x48, 0xD5, 0xAE,
  40508. 0xB6, 0xDC, 0xAA, 0xCA, 0xEB, 0x0B, 0x6B, 0xFE,
  40509. 0xF4, 0xF1, 0x6E, 0x5D, 0xE4, 0x90, 0x53, 0xCF,
  40510. 0x9E, 0x13, 0x80, 0xCE, 0xE5, 0xDD, 0xA4, 0x01,
  40511. 0xBC, 0x16, 0x50, 0xD0, 0x78, 0x96, 0x3F, 0x2B,
  40512. 0x7A, 0x71, 0x8E, 0x86, 0xFD, 0x14, 0x21, 0xDF,
  40513. 0x4D, 0xD7, 0xDD, 0x42, 0x59, 0xB3, 0xED, 0x81,
  40514. 0xE3, 0xAF, 0x71, 0x57, 0xE7, 0x04, 0xD2, 0x26,
  40515. 0xA8, 0x83, 0xFC, 0x03, 0x90, 0x8C, 0x88, 0xC4,
  40516. 0xBF, 0x74, 0x54, 0x59, 0xD8, 0x66, 0x9F, 0xE2,
  40517. 0x7A, 0xCE, 0x5B, 0x9C, 0xC4, 0x37, 0xFA, 0xDB,
  40518. 0x40, 0x9A, 0xDD, 0x73, 0x9C, 0x06, 0x5A, 0x21,
  40519. 0x43, 0xFB, 0xFA, 0x1B, 0x41, 0x31, 0x9F, 0xF4,
  40520. 0x24, 0x09, 0x05, 0xFE, 0x56, 0x17, 0x52, 0x9C,
  40521. 0xC7, 0xE2, 0xCA, 0xC9, 0x1F, 0xBE, 0xE2, 0xEB,
  40522. 0x92, 0xEE, 0xD4, 0x76, 0x44, 0x9A, 0xFA, 0xFB,
  40523. 0x07, 0x62, 0x98, 0xEC, 0xA0, 0xCF, 0xBF, 0xFA,
  40524. 0x5E, 0x1B, 0x8B, 0xCD, 0x33, 0xFB, 0x1A, 0x97,
  40525. 0xFE, 0x50, 0x65, 0x22, 0x08, 0x9E, 0xC3, 0x87,
  40526. 0x88, 0xCA, 0xDD, 0x11, 0x5E, 0xA7, 0xCF, 0xF3,
  40527. 0x07, 0x0A, 0x34, 0x0E, 0x30, 0x1B, 0xC5, 0xCE,
  40528. 0xF7, 0xA6, 0xA4, 0x31, 0xB5, 0x40, 0xB8, 0x81,
  40529. 0xAC, 0xAA, 0x07, 0xE0, 0x7D, 0x5E, 0x6A, 0x25,
  40530. 0x85, 0x8D, 0x1D, 0x82, 0x45, 0x82, 0x76, 0xB2,
  40531. 0x65, 0x69, 0x3E, 0x88, 0xFE, 0x21, 0xFE, 0x6A,
  40532. 0x6B, 0x97, 0xD6, 0x70, 0x70, 0x00, 0x83, 0x18,
  40533. 0x39, 0xA6, 0x91, 0x3F, 0xB1, 0xB7, 0xED, 0x11,
  40534. 0xD3, 0xF9, 0x74, 0x31, 0xEC, 0x21, 0xA2, 0xEE,
  40535. 0x69, 0x04, 0xC0, 0xEA, 0x4A, 0x17, 0x1A, 0xF8,
  40536. 0xDA, 0xF1, 0x52, 0xB2, 0x78, 0x69, 0x4F, 0xDF,
  40537. 0xE6, 0xB9, 0xF3, 0xE7, 0x48, 0x8B, 0x09, 0x5F,
  40538. 0x4A, 0x7A, 0x05, 0x8E, 0xA8, 0xF6, 0x69, 0x3D,
  40539. 0x91, 0x7A, 0x6F, 0x6C, 0xAD, 0x03, 0x16, 0xEA,
  40540. 0xE0, 0x04, 0xFE, 0x54, 0x71, 0x50, 0x6D, 0x31,
  40541. 0xE4, 0x37, 0x76, 0xD6, 0x1B, 0xA9, 0xEE, 0x56,
  40542. 0x7A, 0x39, 0x34, 0x24, 0x00, 0x58, 0xE3, 0x2F,
  40543. 0xD4, 0x97, 0x57, 0x6F, 0xD8, 0x0E, 0x8B, 0xD3,
  40544. 0x88, 0x7F, 0xE8, 0x74, 0x72, 0xF7, 0xBA, 0x26,
  40545. 0x25, 0xE4, 0xD5, 0x86, 0xCD, 0xA8, 0x1E, 0x8D,
  40546. 0x49, 0xCF, 0x04, 0x92, 0x5B, 0x50, 0xD0, 0x73,
  40547. 0x3C, 0xC9, 0x17, 0xC3, 0x0E, 0x67, 0x02, 0xC5,
  40548. 0xDE, 0x48, 0x88, 0x0D, 0x2C, 0x0D, 0x68, 0x04,
  40549. 0xD5, 0x51, 0xDF, 0x4F, 0x23, 0x89, 0x7A, 0x29,
  40550. 0x41, 0xB2, 0x7A, 0xCA, 0x86, 0xA5, 0xCC, 0xC4,
  40551. 0xF5, 0xD3, 0xE1, 0xEF, 0xB8, 0xCD, 0x84, 0xB5,
  40552. 0x6D, 0xB6, 0x51, 0x1B, 0x81, 0x26, 0x97, 0xAC,
  40553. 0x00, 0xFC, 0x76, 0x8D, 0x99, 0xD9, 0x35, 0x8E,
  40554. 0x4D, 0x3E, 0xC0, 0xC1, 0x0E, 0x8D, 0x9B, 0xE5,
  40555. 0x79, 0xF3, 0xC7, 0xA0, 0xA4, 0xA6, 0xA2, 0xE9,
  40556. 0x8B, 0xCD, 0x36, 0x79, 0x76, 0xF1, 0x6A, 0xEE,
  40557. 0xCF, 0x91, 0x8D, 0x91, 0xB1, 0xAF, 0xF2, 0xF5,
  40558. 0x43, 0xF6, 0xB2, 0x3A, 0x39, 0x9F, 0xBF, 0xDE,
  40559. 0x16, 0x03, 0x52, 0x18, 0x62, 0x93, 0xB5, 0x09,
  40560. 0xC4, 0xEE, 0x27, 0x9C, 0x56, 0x6F, 0x0C, 0x1C,
  40561. 0x12, 0x42, 0xF0, 0x34, 0xBD, 0x44, 0x52, 0x4C,
  40562. 0x32, 0x7E, 0x64, 0xDF, 0x78, 0x16, 0xD9, 0x9E,
  40563. 0xD7, 0x8A, 0x11, 0x33, 0x65, 0x42, 0xEC, 0x36,
  40564. 0x07, 0xEE, 0x3F, 0x19, 0x97, 0x9B, 0x92, 0x9D,
  40565. 0x3A, 0xE4, 0x98, 0x83, 0xDB, 0x0C, 0x85, 0x39,
  40566. 0xFA, 0x8D, 0x73, 0xF5, 0xBF, 0xE0, 0x75, 0x40,
  40567. 0x50, 0x9B, 0xF2, 0xE6, 0xB6, 0xA5, 0x33, 0xD0,
  40568. 0xC4, 0xD6, 0xAB, 0xFF, 0x16, 0xDE, 0x30, 0x9C,
  40569. 0x68, 0x90, 0xE0, 0x5E, 0xD3, 0xD5, 0xA9, 0xB0,
  40570. 0xD9, 0x6B, 0x0A, 0x43, 0x45, 0x9A, 0x3D, 0xE8,
  40571. 0xB6, 0x66, 0xE4, 0x57, 0x05, 0x8E, 0x5B, 0x72,
  40572. 0xFE, 0x50, 0x44, 0x8C, 0xE4, 0x68, 0x43, 0x51,
  40573. 0x0D, 0x9A, 0xD3, 0x36, 0xA9, 0xC7, 0xF6, 0xCF,
  40574. 0x6D, 0x2C, 0x95, 0x46, 0x98, 0x6D, 0x9E, 0x78,
  40575. 0x90, 0x87, 0x19, 0x64, 0xD5, 0xDE, 0x1D, 0x9B,
  40576. 0x37, 0x4E, 0x52, 0xF5, 0x14, 0xAA, 0xEE, 0x31,
  40577. 0x83, 0x55, 0x7C, 0x38, 0x0F, 0xB3, 0xF6, 0xF2,
  40578. 0x1C, 0x60, 0x71, 0x68, 0x1F, 0x06, 0xBD, 0x99,
  40579. 0xFD, 0x42, 0x12, 0x54, 0x3E, 0xBA, 0x4B, 0x60,
  40580. 0xFB, 0xFB, 0x51, 0x4D, 0x02, 0xCE, 0xE5, 0x9E,
  40581. 0x59, 0xB2, 0xE6, 0x98, 0x67, 0xBB, 0xAB, 0xC8,
  40582. 0x08, 0xE4, 0x08, 0x0D, 0xF5, 0x3B, 0x47, 0x78,
  40583. 0x39, 0x24, 0x56, 0x80, 0xF0, 0x6A, 0x1D, 0x33,
  40584. 0x05, 0x5F, 0xF2, 0xA2, 0x38, 0xAD, 0xDF, 0x5C,
  40585. 0xC5, 0xEA, 0x9C, 0xC7, 0x0A, 0x1B, 0x5B, 0x43,
  40586. 0xE9, 0x59, 0x3D, 0x68, 0x00, 0x23, 0x32, 0x5D,
  40587. 0x25, 0xFD, 0xA7, 0xCA, 0xDA, 0xA1, 0xFD, 0x22,
  40588. 0x4E, 0x34, 0x96, 0xE7, 0x0D, 0xFF, 0x89, 0x3B,
  40589. 0xA6, 0x56, 0x0D, 0x11, 0x13, 0xA6, 0x9D, 0x3B,
  40590. 0xBC, 0x12, 0x97, 0x9A, 0x2B, 0xAA, 0xE9, 0xE2,
  40591. 0xCF, 0xD2, 0xD3, 0xEF, 0x95, 0xFC, 0x40, 0x80,
  40592. 0x94, 0x48, 0x80, 0x5A, 0x3F, 0x4A, 0xD2, 0xB5,
  40593. 0x7D, 0x61, 0xA2, 0x26, 0x7B, 0xDC, 0x32, 0xCB,
  40594. 0x84, 0x2E, 0x9B, 0x29, 0x63, 0x45, 0x74, 0x0D,
  40595. 0x85, 0x54, 0xB2, 0x16, 0x77, 0x9B, 0x47, 0x51,
  40596. 0x63, 0x33, 0xE9, 0x1A, 0x52, 0x9D, 0xEB, 0x26,
  40597. 0x06, 0x7F, 0x97, 0xA0, 0xA1, 0xAA, 0x07, 0x0F,
  40598. 0x1E, 0x23, 0xAB, 0xCC, 0xD5, 0x0F, 0x3E, 0x88,
  40599. 0xAA, 0xC3, 0xED, 0x06, 0x25, 0x3A, 0x4A, 0x62,
  40600. 0x85, 0x9F, 0xA7, 0xD3, 0xF5, 0x1C, 0x9A, 0xCC,
  40601. 0x52, 0x87, 0x9F, 0xB8, 0xC7, 0xDD, 0xF1, 0x50,
  40602. 0x66, 0x70, 0xAC, 0xC6, 0x2C, 0x2E, 0x8C, 0xC9,
  40603. 0xD9, 0xF6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  40604. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  40605. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  40606. 0x00, 0x00, 0x00, 0x06, 0x0D, 0x13, 0x1D, 0x20,
  40607. 0x27, 0x2C, 0x32
  40608. };
  40609. #endif
  40610. byte sig[DILITHIUM_MAX_SIG_SIZE];
  40611. word32 sigLen;
  40612. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  40613. ExpectNotNull(key);
  40614. if (key != NULL) {
  40615. XMEMSET(key, 0, sizeof(*key));
  40616. }
  40617. ExpectIntEQ(wc_dilithium_init_ex(key, NULL, INVALID_DEVID), 0);
  40618. #ifndef WOLFSSL_NO_ML_DSA_44
  40619. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  40620. ExpectIntEQ(wc_dilithium_import_private(sk_44, (word32)sizeof(sk_44), key),
  40621. 0);
  40622. sigLen = PARAMS_ML_DSA_44_SIG_SIZE;
  40623. ExpectIntEQ(wc_dilithium_sign_msg_with_seed(msg_44, (word32)sizeof(msg_44),
  40624. sig, &sigLen, key, rnd_44), 0);
  40625. ExpectIntEQ(sigLen, PARAMS_ML_DSA_44_SIG_SIZE);
  40626. ExpectIntEQ(XMEMCMP(sig, sig_44, sizeof(sig_44)), 0);
  40627. #endif
  40628. #ifndef WOLFSSL_NO_ML_DSA_65
  40629. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  40630. ExpectIntEQ(wc_dilithium_import_private(sk_65, (word32)sizeof(sk_65), key),
  40631. 0);
  40632. sigLen = PARAMS_ML_DSA_65_SIG_SIZE;
  40633. ExpectIntEQ(wc_dilithium_sign_msg_with_seed(msg_65, (word32)sizeof(msg_65),
  40634. sig, &sigLen, key, rnd_65), 0);
  40635. ExpectIntEQ(sigLen, PARAMS_ML_DSA_65_SIG_SIZE);
  40636. ExpectIntEQ(XMEMCMP(sig, sig_65, sizeof(sig_65)), 0);
  40637. #endif
  40638. #ifndef WOLFSSL_NO_ML_DSA_87
  40639. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  40640. ExpectIntEQ(wc_dilithium_import_private(sk_87, (word32)sizeof(sk_87), key),
  40641. 0);
  40642. sigLen = PARAMS_ML_DSA_87_SIG_SIZE;
  40643. ExpectIntEQ(wc_dilithium_sign_msg_with_seed(msg_87, (word32)sizeof(msg_87),
  40644. sig, &sigLen, key, rnd_87), 0);
  40645. ExpectIntEQ(sigLen, PARAMS_ML_DSA_87_SIG_SIZE);
  40646. ExpectIntEQ(XMEMCMP(sig, sig_87, sizeof(sig_87)), 0);
  40647. #endif
  40648. wc_dilithium_free(key);
  40649. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  40650. #endif
  40651. return EXPECT_RESULT();
  40652. }
  40653. static int test_wc_dilithium_verify_kats(void)
  40654. {
  40655. EXPECT_DECLS;
  40656. #if defined(HAVE_DILITHIUM) && defined(WOLFSSL_WC_DILITHIUM) && \
  40657. !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  40658. dilithium_key* key;
  40659. int res;
  40660. #ifndef WOLFSSL_NO_ML_DSA_44
  40661. static const byte pk_44[] = {
  40662. 0x09, 0xB4, 0x88, 0x7D, 0x97, 0xBC, 0xF6, 0x37,
  40663. 0x9C, 0xC5, 0x9B, 0x61, 0x62, 0xC1, 0xE8, 0xBF,
  40664. 0x05, 0x60, 0xBF, 0x44, 0xD6, 0x18, 0x09, 0x17,
  40665. 0x0E, 0x6E, 0x28, 0xF7, 0x06, 0x69, 0xA3, 0xE9,
  40666. 0x49, 0x64, 0x38, 0xE8, 0x91, 0x57, 0x35, 0xAD,
  40667. 0xAE, 0xB4, 0x45, 0xCF, 0xDB, 0x7D, 0x89, 0xB3,
  40668. 0x8C, 0x04, 0x8F, 0x4C, 0x3E, 0x00, 0x58, 0x15,
  40669. 0x14, 0xC5, 0xFD, 0x19, 0x8B, 0x2D, 0x17, 0x39,
  40670. 0xE8, 0x83, 0xB8, 0x78, 0xD5, 0x6B, 0xB4, 0x12,
  40671. 0x64, 0xBE, 0x41, 0xD3, 0xD5, 0x15, 0x65, 0xE2,
  40672. 0xE9, 0xCA, 0xE3, 0x31, 0x84, 0xA8, 0x99, 0xF6,
  40673. 0x2D, 0xD5, 0x7D, 0x07, 0x40, 0x0E, 0x98, 0xE5,
  40674. 0x86, 0x87, 0xA9, 0xB2, 0x2F, 0xA3, 0x17, 0xEE,
  40675. 0xD1, 0x34, 0xCA, 0x72, 0x14, 0xBF, 0xF0, 0x21,
  40676. 0xDD, 0x21, 0x62, 0xB1, 0x83, 0x09, 0x1D, 0x15,
  40677. 0xF2, 0x63, 0xB7, 0x29, 0x82, 0x14, 0x42, 0x3C,
  40678. 0x6B, 0xB6, 0x96, 0xD7, 0x5C, 0x20, 0xD9, 0xEA,
  40679. 0xCD, 0x0A, 0x03, 0xE4, 0x26, 0x2C, 0x4B, 0x08,
  40680. 0xBE, 0x39, 0xFA, 0x21, 0x54, 0xBD, 0x6E, 0x50,
  40681. 0x25, 0xFF, 0x79, 0x1E, 0x88, 0x5F, 0x22, 0x26,
  40682. 0xE3, 0xCF, 0x48, 0xF7, 0xB5, 0xEB, 0x04, 0xFB,
  40683. 0xE9, 0xEC, 0xF7, 0x5B, 0x19, 0xE1, 0xD1, 0x5C,
  40684. 0x30, 0x5E, 0x92, 0x26, 0x0A, 0xB0, 0xD6, 0xAE,
  40685. 0x7D, 0xBA, 0x7B, 0xBE, 0x73, 0xB6, 0xBC, 0x18,
  40686. 0x1C, 0xF9, 0x33, 0x84, 0x0C, 0xC1, 0x0A, 0x00,
  40687. 0x05, 0x02, 0x28, 0xFA, 0x46, 0xA2, 0x63, 0x6D,
  40688. 0xD9, 0xA9, 0x09, 0x47, 0xE9, 0xF1, 0x3A, 0x93,
  40689. 0xEF, 0x4C, 0x62, 0xBE, 0x37, 0x4D, 0x76, 0xD1,
  40690. 0xFD, 0xBB, 0xC5, 0xD8, 0xB5, 0x5E, 0x72, 0x9F,
  40691. 0xA5, 0x86, 0x65, 0xAA, 0x07, 0xB9, 0x0C, 0x8C,
  40692. 0xDD, 0xD6, 0x1C, 0x56, 0x6B, 0x0D, 0x7E, 0xD6,
  40693. 0x57, 0x70, 0x49, 0x2E, 0xA0, 0x71, 0x3E, 0x1E,
  40694. 0xD4, 0x6A, 0xC7, 0xAD, 0x15, 0x03, 0xC5, 0x6D,
  40695. 0x90, 0x52, 0xD2, 0xC9, 0x4D, 0x49, 0xE4, 0x41,
  40696. 0x6A, 0xC9, 0x2B, 0x70, 0x39, 0x6F, 0x76, 0xF6,
  40697. 0xFB, 0x48, 0x10, 0x45, 0x68, 0x17, 0x25, 0xA6,
  40698. 0x8C, 0xB3, 0x56, 0x37, 0x7F, 0xB2, 0x31, 0xAB,
  40699. 0x8F, 0x3E, 0xB9, 0xA4, 0x98, 0x2F, 0xFF, 0x18,
  40700. 0x36, 0x47, 0x3B, 0xCB, 0xDA, 0xB6, 0x87, 0x2D,
  40701. 0x22, 0x94, 0x67, 0xEF, 0xB9, 0x36, 0x62, 0x61,
  40702. 0xFE, 0xB1, 0x48, 0xBA, 0x9B, 0x7D, 0xB9, 0xC4,
  40703. 0xFE, 0x0B, 0xB8, 0x86, 0x12, 0xAB, 0xB8, 0xFD,
  40704. 0x61, 0x09, 0x6F, 0x18, 0x19, 0x60, 0x4D, 0x55,
  40705. 0xDF, 0x60, 0x20, 0x46, 0x4D, 0x3F, 0x09, 0x2C,
  40706. 0xFC, 0xA5, 0x98, 0x12, 0x08, 0x22, 0x18, 0x56,
  40707. 0x68, 0x99, 0xA5, 0x6A, 0x3C, 0x63, 0x3C, 0xC8,
  40708. 0x1F, 0x88, 0xAD, 0xB2, 0xE1, 0x41, 0x4E, 0xF3,
  40709. 0x85, 0x0D, 0x10, 0xBF, 0x5A, 0x77, 0xAC, 0xE7,
  40710. 0x24, 0xD6, 0xC1, 0xF3, 0x88, 0x92, 0x87, 0x44,
  40711. 0xB3, 0xE5, 0x42, 0xAE, 0x49, 0x1C, 0xD5, 0x6A,
  40712. 0x64, 0x21, 0x3F, 0x1D, 0x3C, 0xC9, 0x0B, 0x29,
  40713. 0x10, 0x5F, 0x43, 0xD2, 0x37, 0xC8, 0x3D, 0x5F,
  40714. 0xB8, 0x29, 0x32, 0x5C, 0x83, 0xE6, 0x54, 0x57,
  40715. 0x77, 0x76, 0x39, 0x2F, 0x85, 0x36, 0xAA, 0x9D,
  40716. 0xAE, 0x87, 0x24, 0x07, 0xAB, 0xAA, 0xA9, 0xAC,
  40717. 0xC2, 0x2A, 0x68, 0x12, 0xCE, 0xA7, 0x4C, 0x0B,
  40718. 0xA6, 0x7E, 0xAF, 0x4A, 0x41, 0x01, 0x52, 0x97,
  40719. 0x5E, 0x9A, 0x83, 0xEE, 0x44, 0x69, 0x29, 0x53,
  40720. 0x17, 0xBE, 0xD1, 0x05, 0x51, 0xBA, 0x32, 0xE6,
  40721. 0x5A, 0xFC, 0x8C, 0x8E, 0x68, 0xDD, 0x55, 0x42,
  40722. 0x0C, 0x50, 0x2D, 0x93, 0x7D, 0xAD, 0xD2, 0xEF,
  40723. 0xA2, 0xCB, 0xFD, 0x1F, 0x73, 0x9F, 0xC0, 0xAB,
  40724. 0x2B, 0x26, 0x54, 0xFA, 0xE0, 0x8C, 0x0C, 0x7F,
  40725. 0x8E, 0xDD, 0x43, 0xCF, 0x9F, 0xF0, 0xB0, 0x1D,
  40726. 0x98, 0x4D, 0x49, 0x18, 0x52, 0xA3, 0x72, 0xE9,
  40727. 0xFE, 0xFD, 0xCC, 0x1B, 0xC1, 0x6C, 0xDB, 0x52,
  40728. 0x39, 0xAE, 0x10, 0x01, 0x15, 0x5F, 0x89, 0x56,
  40729. 0x30, 0x51, 0xCE, 0x47, 0x99, 0x6C, 0x5A, 0xEE,
  40730. 0xB2, 0x19, 0x0E, 0xA1, 0x8F, 0x7F, 0x73, 0x40,
  40731. 0x42, 0xDE, 0x68, 0xE9, 0x88, 0x36, 0x7D, 0x89,
  40732. 0x35, 0x5D, 0x9D, 0x83, 0x77, 0xBA, 0xF9, 0x64,
  40733. 0x79, 0x78, 0xEB, 0x2E, 0x49, 0x2A, 0xD0, 0x21,
  40734. 0xC5, 0x69, 0xAE, 0x8B, 0xA6, 0x9B, 0x15, 0xF1,
  40735. 0xFC, 0xF7, 0x03, 0x9A, 0x7E, 0x64, 0xAF, 0x10,
  40736. 0xAB, 0xF3, 0xEA, 0x45, 0xB7, 0x22, 0x2F, 0x96,
  40737. 0x59, 0xE3, 0x33, 0x73, 0x37, 0x2E, 0x1D, 0xB1,
  40738. 0x86, 0xD2, 0xC2, 0xA0, 0xD7, 0x54, 0x51, 0xC4,
  40739. 0x78, 0xAE, 0xF3, 0x3E, 0x59, 0x49, 0xF2, 0x40,
  40740. 0x04, 0x0C, 0x2A, 0xFC, 0x44, 0xB1, 0xD3, 0xA0,
  40741. 0x2A, 0x6D, 0x2F, 0x87, 0x90, 0x2A, 0x28, 0x0E,
  40742. 0x27, 0xA2, 0x0D, 0x4E, 0x57, 0xF8, 0x89, 0x66,
  40743. 0x27, 0x00, 0xDB, 0x8A, 0x9D, 0x24, 0x99, 0x57,
  40744. 0xA7, 0xDB, 0x43, 0x7C, 0xD4, 0x80, 0xDD, 0xC0,
  40745. 0x58, 0x84, 0xFB, 0x23, 0xF8, 0x68, 0x26, 0x8E,
  40746. 0xAC, 0xE3, 0x4E, 0xED, 0x27, 0x4A, 0x92, 0x7D,
  40747. 0x9D, 0x84, 0xF1, 0xEA, 0x57, 0xEA, 0xB1, 0xA8,
  40748. 0x13, 0xB5, 0xE6, 0xAA, 0xBE, 0x9E, 0xD2, 0x61,
  40749. 0x0B, 0xC6, 0xF7, 0x2E, 0x32, 0x0C, 0xDE, 0xC4,
  40750. 0xF9, 0x95, 0x23, 0xF9, 0x3F, 0xA4, 0x48, 0xDC,
  40751. 0x1F, 0xBB, 0xDD, 0x25, 0x9B, 0x10, 0x2F, 0x5D,
  40752. 0xC9, 0x95, 0x5A, 0xFA, 0x0C, 0x41, 0x60, 0x4D,
  40753. 0x83, 0xDD, 0x1C, 0x2D, 0x22, 0x95, 0xEF, 0x44,
  40754. 0x61, 0x45, 0x6B, 0xAE, 0x86, 0x90, 0x5C, 0x4C,
  40755. 0x30, 0xD8, 0xA9, 0xFA, 0x48, 0xC9, 0x0F, 0x37,
  40756. 0xA1, 0x9C, 0x41, 0xA2, 0xD5, 0x98, 0x8F, 0x13,
  40757. 0xD5, 0x13, 0x44, 0xEC, 0x30, 0xA4, 0xA4, 0x62,
  40758. 0x19, 0xFE, 0x84, 0x11, 0x37, 0xD5, 0xAA, 0x1F,
  40759. 0x51, 0xE6, 0xC4, 0x44, 0x16, 0x8A, 0xF3, 0x98,
  40760. 0x90, 0xB6, 0xFA, 0x40, 0x0D, 0x67, 0xF4, 0x80,
  40761. 0x6F, 0x5B, 0xBD, 0x44, 0x47, 0x03, 0x07, 0x4A,
  40762. 0x7A, 0x11, 0x39, 0xC7, 0x17, 0x46, 0xD7, 0xC4,
  40763. 0xCE, 0xB3, 0xC9, 0x11, 0xF5, 0x25, 0x7E, 0x3E,
  40764. 0x53, 0xEB, 0xFA, 0x5A, 0xA8, 0xF2, 0x27, 0x80,
  40765. 0x9D, 0x44, 0xEE, 0x7D, 0xE1, 0x3C, 0x02, 0x79,
  40766. 0x24, 0xDD, 0x60, 0x15, 0x3B, 0x30, 0xAA, 0x76,
  40767. 0xDD, 0x96, 0xA7, 0xC5, 0xAC, 0xC5, 0x9B, 0x62,
  40768. 0x79, 0x19, 0x50, 0x7B, 0xF1, 0x42, 0x57, 0xAE,
  40769. 0x7A, 0x26, 0x24, 0x3C, 0x16, 0x83, 0xB2, 0x8D,
  40770. 0x1B, 0x14, 0xB5, 0x01, 0xAD, 0x05, 0x9B, 0x4D,
  40771. 0x52, 0x2A, 0x57, 0x99, 0x1E, 0x55, 0x39, 0xCE,
  40772. 0xF1, 0x8C, 0xEB, 0x5C, 0x26, 0xD6, 0x60, 0xB8,
  40773. 0x82, 0x24, 0x54, 0xC9, 0xC4, 0x2A, 0x95, 0xE6,
  40774. 0xF7, 0x2B, 0x84, 0xF7, 0x8A, 0xB9, 0x9F, 0x51,
  40775. 0xEC, 0x49, 0x78, 0x9F, 0x9D, 0xB4, 0xC1, 0x28,
  40776. 0xB0, 0x31, 0x8F, 0xFF, 0xC8, 0x2D, 0x95, 0xCA,
  40777. 0xD2, 0x77, 0xF1, 0x1E, 0x14, 0xF1, 0xEF, 0x87,
  40778. 0x14, 0x14, 0x88, 0x11, 0x22, 0xA9, 0xB1, 0x1B,
  40779. 0xDF, 0xAE, 0x4A, 0x7A, 0xBC, 0x8E, 0x75, 0x75,
  40780. 0x5A, 0xB1, 0x37, 0x41, 0xDF, 0xAC, 0xD6, 0x64,
  40781. 0x29, 0x3D, 0x1A, 0x32, 0x6B, 0xF5, 0xED, 0x5A,
  40782. 0xBB, 0xB1, 0x53, 0xEB, 0xE6, 0x99, 0x6D, 0xD6,
  40783. 0x22, 0xF0, 0xA8, 0xCB, 0x47, 0x39, 0x69, 0xA5,
  40784. 0x03, 0x66, 0xBD, 0x0B, 0x01, 0xC5, 0xC7, 0x3A,
  40785. 0x89, 0x2B, 0x8E, 0x26, 0xCE, 0x08, 0xF7, 0x5F,
  40786. 0xF8, 0x01, 0xB6, 0xDE, 0xF0, 0x41, 0xE1, 0x71,
  40787. 0x3B, 0xE6, 0xDF, 0x0E, 0xFB, 0x51, 0x58, 0x7B,
  40788. 0xE5, 0xFB, 0xEA, 0x72, 0x7E, 0x00, 0xD7, 0x17,
  40789. 0x64, 0x7D, 0xD5, 0x39, 0x07, 0x9D, 0xE1, 0x8A,
  40790. 0xE7, 0xBE, 0xD1, 0x2B, 0x91, 0xAF, 0x8D, 0xBB,
  40791. 0x1B, 0x8B, 0x32, 0xD2, 0x86, 0x0B, 0xAF, 0x40,
  40792. 0xAF, 0x8A, 0x0B, 0xBF, 0xE0, 0x28, 0x87, 0xEB,
  40793. 0x5D, 0xBE, 0x7A, 0xB1, 0xAF, 0xC4, 0x1D, 0xA7,
  40794. 0x9B, 0x01, 0x6A, 0xA1, 0x6E, 0xDA, 0x28, 0x13,
  40795. 0x21, 0xCA, 0xA5, 0xDA, 0x64, 0x4F, 0xD8, 0x65,
  40796. 0x8A, 0x7B, 0x70, 0x21, 0x81, 0x00, 0x14, 0x31,
  40797. 0x56, 0x0D, 0xD6, 0x3C, 0xB2, 0x1E, 0x5F, 0xF7,
  40798. 0x5C, 0x3F, 0x72, 0x50, 0x45, 0x6B, 0xE0, 0x8C,
  40799. 0x0D, 0x5E, 0x34, 0xC3, 0xBD, 0xE2, 0xF6, 0x06,
  40800. 0xA2, 0xBF, 0x34, 0x17, 0x76, 0x8D, 0x24, 0xB2,
  40801. 0x37, 0x39, 0xEA, 0x86, 0xCB, 0xEF, 0xDD, 0xA3,
  40802. 0x43, 0x88, 0xBC, 0x1F, 0x91, 0x8F, 0x95, 0x1E,
  40803. 0x15, 0xE4, 0x3B, 0x13, 0x85, 0xA7, 0xBC, 0xC5,
  40804. 0x59, 0xF9, 0x49, 0x2C, 0x72, 0x13, 0xA1, 0x42,
  40805. 0x27, 0xE0, 0x93, 0xE9, 0x29, 0xF3, 0x2D, 0x1E,
  40806. 0xFB, 0xE7, 0xF1, 0xEE, 0x57, 0xC4, 0x9C, 0x90,
  40807. 0x55, 0x62, 0x3E, 0xA4, 0x2E, 0xC6, 0xC7, 0x9D,
  40808. 0x7F, 0xCE, 0x71, 0xFA, 0x74, 0x76, 0x07, 0x56,
  40809. 0x6D, 0xDA, 0x69, 0xF6, 0x9D, 0xAF, 0x68, 0x11,
  40810. 0x59, 0x19, 0xC6, 0x32, 0x2E, 0xBB, 0x42, 0xC8,
  40811. 0xC0, 0x89, 0x33, 0x8C, 0x9E, 0x0C, 0x53, 0x56,
  40812. 0x5B, 0xCB, 0xE7, 0x2F, 0xBE, 0x47, 0x26, 0x68,
  40813. 0x7B, 0x07, 0x87, 0x07, 0x18, 0x06, 0xC5, 0xA6,
  40814. 0xC1, 0x49, 0xC8, 0x2B, 0x66, 0x8A, 0xA6, 0x4A,
  40815. 0x7B, 0xA0, 0xCC, 0xC1, 0xCC, 0x49, 0xA1, 0xEE,
  40816. 0xE9, 0x45, 0x3D, 0x04, 0x33, 0x6E, 0x5D, 0xC8,
  40817. 0x11, 0xE0, 0x38, 0x92, 0xF7, 0xF4, 0x66, 0x88,
  40818. 0xEC, 0xEF, 0xD0, 0x4F, 0x18, 0x76, 0xF7, 0x11,
  40819. 0x17, 0x12, 0xB5, 0x95, 0xED, 0x62, 0xDA, 0x00,
  40820. 0x67, 0x8F, 0x9E, 0x37, 0x86, 0xB5, 0xC1, 0xA5,
  40821. 0x09, 0x5B, 0xE8, 0x71, 0x0D, 0xCF, 0xA4, 0x16,
  40822. 0x52, 0x56, 0x50, 0x9E, 0x00, 0x14, 0x3A, 0x6F,
  40823. 0x11, 0x72, 0xFA, 0xBE, 0x8B, 0xF2, 0x1E, 0x5F,
  40824. 0xCE, 0x7C, 0x79, 0xC1, 0xA4, 0x4B, 0x4B, 0x15,
  40825. 0x25, 0xA0, 0x76, 0xFF, 0xB8, 0xDD, 0x90, 0x66
  40826. };
  40827. static const byte msg_44[] = {
  40828. 0x3A, 0xFD, 0x7F, 0xF8, 0xCA, 0xD3, 0xAC, 0xBD,
  40829. 0xF9, 0x77, 0x31, 0x26, 0x1C, 0x7A, 0x1C, 0x96,
  40830. 0x9D, 0x50, 0x16, 0xF1, 0x7D, 0x3E, 0x7F, 0x83,
  40831. 0xD2, 0x44, 0x1A, 0xF9, 0x01, 0x4B, 0x63, 0x47,
  40832. 0x7B, 0x14, 0xA6, 0x41, 0x31, 0x50, 0xFA, 0xD7,
  40833. 0xC8, 0x44, 0x39, 0xBC, 0x88, 0x66, 0x2C, 0x5E,
  40834. 0x93, 0x1F, 0x06, 0xB9, 0x51, 0x41, 0x90, 0xE1,
  40835. 0x3F, 0xB0, 0x49, 0xC4, 0xAB, 0x74, 0x01, 0x32,
  40836. 0x33, 0xB9, 0x8D, 0x48, 0xD9, 0xAF, 0xB6, 0xA3,
  40837. 0x0A, 0x67, 0x33, 0x0E, 0x1F, 0xBE, 0x33, 0x1B,
  40838. 0x09, 0xC5, 0x6D, 0x03, 0x7E, 0x97, 0x01, 0x08,
  40839. 0x5D, 0x80, 0xF1, 0xE7, 0xF4, 0x04, 0x3E, 0xFB,
  40840. 0x53, 0x58, 0x7A, 0xBB, 0x82, 0x36, 0x24, 0x01,
  40841. 0x23, 0x84, 0x51, 0x52, 0x49, 0xEE, 0x61, 0x30,
  40842. 0x97, 0x3D, 0xC9, 0xEA, 0x6F, 0x55, 0x8B, 0xAE,
  40843. 0x75, 0x10, 0x7E, 0xFD, 0xB1, 0xD9, 0x28, 0x5B
  40844. };
  40845. static const byte sig_44[] = {
  40846. 0x4A, 0x2B, 0x16, 0xCD, 0xB5, 0x52, 0xF9, 0x29,
  40847. 0x7F, 0x8E, 0x39, 0x1A, 0xD8, 0xF5, 0xAD, 0xC8,
  40848. 0xCC, 0x5D, 0x2C, 0x56, 0xC4, 0x6B, 0x80, 0x0F,
  40849. 0x9B, 0x3E, 0xE4, 0xBB, 0xD2, 0xF2, 0xE8, 0xA8,
  40850. 0x9D, 0x59, 0x9D, 0x7B, 0x5C, 0xC2, 0xD8, 0x8C,
  40851. 0x80, 0xF2, 0x71, 0x85, 0x9B, 0xBC, 0x83, 0x04,
  40852. 0x3E, 0xC4, 0xE5, 0x48, 0x12, 0xF5, 0x93, 0x6B,
  40853. 0x44, 0x6C, 0x95, 0x13, 0xC8, 0x55, 0x28, 0x9C,
  40854. 0x94, 0xB1, 0x15, 0x51, 0xA0, 0xC7, 0x65, 0x3E,
  40855. 0x7B, 0xA7, 0x4F, 0xFB, 0x6F, 0x72, 0xD4, 0x65,
  40856. 0x2C, 0x91, 0xD3, 0x8D, 0xD1, 0xF9, 0x0D, 0xFE,
  40857. 0x44, 0x39, 0xBC, 0x21, 0xCA, 0x53, 0xE0, 0xCC,
  40858. 0x7A, 0x7A, 0xA5, 0xB8, 0x75, 0xA5, 0xB9, 0xBA,
  40859. 0x42, 0x36, 0x6E, 0xB8, 0xEC, 0xBA, 0x24, 0x36,
  40860. 0xDA, 0xF0, 0x8A, 0x91, 0x97, 0x8D, 0xD0, 0x93,
  40861. 0xF2, 0x0F, 0x1E, 0xFB, 0x6B, 0x0B, 0xCB, 0x90,
  40862. 0xDA, 0x99, 0xCC, 0xA0, 0x5E, 0x8F, 0x6F, 0x82,
  40863. 0xB8, 0x6D, 0x3C, 0x6E, 0xE2, 0x4B, 0xA5, 0xD5,
  40864. 0x0A, 0xEA, 0x10, 0xB2, 0x30, 0x7F, 0x57, 0xF8,
  40865. 0x9E, 0xD7, 0x8D, 0xB4, 0xA7, 0x4F, 0xBB, 0xF6,
  40866. 0xEB, 0x33, 0x2A, 0xFB, 0x08, 0xD0, 0x74, 0xAC,
  40867. 0xF0, 0xDE, 0x5C, 0xD7, 0xFE, 0xC1, 0x2F, 0x76,
  40868. 0xF3, 0xAB, 0x61, 0x9C, 0x81, 0x5B, 0x9E, 0xDD,
  40869. 0x28, 0x7E, 0xAD, 0x67, 0xF0, 0x4F, 0x14, 0x79,
  40870. 0x7F, 0x8D, 0xCF, 0x2C, 0xDE, 0x9A, 0x87, 0x53,
  40871. 0xB5, 0xAD, 0x0A, 0xFA, 0x12, 0x87, 0x41, 0x97,
  40872. 0xD1, 0x74, 0x40, 0x92, 0x87, 0x25, 0x21, 0xE8,
  40873. 0x68, 0xAF, 0x9E, 0x64, 0x45, 0x23, 0x73, 0xFE,
  40874. 0xB6, 0xFE, 0x25, 0xD5, 0x27, 0x3D, 0x63, 0xC0,
  40875. 0xEB, 0xD6, 0xD3, 0xB1, 0x02, 0x8C, 0x1C, 0xD0,
  40876. 0x6A, 0xF3, 0x2C, 0xEC, 0xA2, 0x62, 0x13, 0x10,
  40877. 0x83, 0x7C, 0x72, 0x78, 0x8C, 0x8A, 0xDA, 0xB5,
  40878. 0xA0, 0xF0, 0x38, 0x17, 0x12, 0x8E, 0xB7, 0xB7,
  40879. 0x66, 0xFA, 0x81, 0x2C, 0x69, 0x6C, 0xF8, 0x86,
  40880. 0xF0, 0x0A, 0x10, 0x44, 0xCD, 0xD0, 0x6B, 0xB2,
  40881. 0x8C, 0xB2, 0xE5, 0x78, 0x0C, 0x8D, 0x8C, 0xC7,
  40882. 0xE6, 0x0A, 0xB6, 0x99, 0xDD, 0x78, 0x66, 0x8B,
  40883. 0xE4, 0xFF, 0x9F, 0x46, 0x90, 0xC6, 0xFC, 0x98,
  40884. 0xAA, 0xC9, 0xC0, 0x2B, 0x66, 0xB9, 0xB9, 0x82,
  40885. 0x6A, 0x30, 0x61, 0xFD, 0x32, 0x22, 0xDA, 0x84,
  40886. 0x82, 0x66, 0x79, 0x60, 0xA3, 0x16, 0x52, 0xEE,
  40887. 0x88, 0xEB, 0x32, 0xB0, 0x46, 0x9A, 0xB7, 0x1C,
  40888. 0xAA, 0x25, 0x19, 0xF2, 0x3D, 0x1A, 0x24, 0x42,
  40889. 0xD5, 0xB1, 0x31, 0x62, 0x62, 0x13, 0x1D, 0xCE,
  40890. 0xC5, 0xF2, 0x87, 0xE3, 0x2F, 0xD3, 0x43, 0xFE,
  40891. 0xB4, 0x42, 0x9E, 0x54, 0x25, 0x8D, 0x69, 0x0D,
  40892. 0x9D, 0x20, 0xA1, 0x0A, 0xBD, 0x75, 0xA5, 0x36,
  40893. 0xDF, 0xF8, 0xCF, 0x1D, 0x6D, 0xDF, 0x19, 0x29,
  40894. 0x1E, 0x27, 0x49, 0xA7, 0xD1, 0x6E, 0xB9, 0x0A,
  40895. 0xB5, 0x09, 0x3B, 0xAD, 0x38, 0xE1, 0x16, 0xA8,
  40896. 0x6B, 0x73, 0x0E, 0x65, 0x57, 0x4C, 0x06, 0x8C,
  40897. 0x38, 0xBA, 0x94, 0x57, 0xC9, 0xD6, 0xD9, 0x13,
  40898. 0xEA, 0xFF, 0x57, 0xFE, 0x23, 0xBF, 0x3D, 0xD2,
  40899. 0x4D, 0x8C, 0xA5, 0x11, 0xEF, 0xA3, 0x76, 0xA5,
  40900. 0xDF, 0x08, 0x46, 0x70, 0x25, 0xFF, 0x51, 0xBE,
  40901. 0xAD, 0x3E, 0xDE, 0x0A, 0x84, 0xED, 0xC5, 0x32,
  40902. 0x16, 0x20, 0x99, 0x80, 0x61, 0xE8, 0xA1, 0xA7,
  40903. 0x3D, 0x67, 0xB7, 0x02, 0x1B, 0x81, 0x0C, 0x78,
  40904. 0x67, 0xFF, 0x39, 0x18, 0x7B, 0x59, 0xD4, 0x03,
  40905. 0xBF, 0x7C, 0x75, 0x06, 0x30, 0x0C, 0x73, 0x45,
  40906. 0xB1, 0xFE, 0x07, 0xC1, 0x12, 0x78, 0xB0, 0xAB,
  40907. 0xA6, 0x1D, 0xBB, 0x4F, 0x2B, 0x8C, 0x43, 0xE7,
  40908. 0x4F, 0xEF, 0xA5, 0x5E, 0xD5, 0x2C, 0x10, 0xA8,
  40909. 0xC4, 0x90, 0x88, 0x2B, 0xBF, 0xE3, 0xE3, 0xB3,
  40910. 0xCE, 0x57, 0x9E, 0x81, 0x16, 0xA9, 0xB6, 0x68,
  40911. 0x6C, 0x1A, 0x10, 0x0A, 0xA1, 0xF6, 0x59, 0x1F,
  40912. 0x19, 0x1F, 0x77, 0x2B, 0x5A, 0x5A, 0x50, 0xDD,
  40913. 0x6C, 0xC1, 0x55, 0xCB, 0x5A, 0x1B, 0xE5, 0xBA,
  40914. 0x12, 0x2E, 0x91, 0xF0, 0x44, 0x42, 0x01, 0x56,
  40915. 0xCD, 0x63, 0x08, 0x0F, 0x0A, 0x45, 0xD6, 0x62,
  40916. 0xE7, 0x6D, 0xD5, 0x7B, 0xD0, 0xF6, 0x89, 0xD0,
  40917. 0xB2, 0x99, 0x04, 0x2B, 0xFF, 0x48, 0x5E, 0x8A,
  40918. 0x38, 0x2D, 0x86, 0x5C, 0x26, 0xCD, 0x46, 0xB4,
  40919. 0xA5, 0x47, 0x28, 0xBD, 0x48, 0x45, 0x83, 0x62,
  40920. 0xD7, 0x9A, 0xC3, 0xEB, 0x75, 0x6F, 0xC6, 0xC5,
  40921. 0x18, 0xC9, 0xE2, 0xF0, 0xE7, 0xD5, 0xA3, 0x03,
  40922. 0xAF, 0x11, 0x59, 0xEE, 0x6D, 0xBE, 0x7D, 0xD5,
  40923. 0x6B, 0xA0, 0x71, 0x28, 0x57, 0xA6, 0x88, 0x36,
  40924. 0xC3, 0xC7, 0x8C, 0x6C, 0x9F, 0x74, 0x88, 0x57,
  40925. 0x28, 0x13, 0xC0, 0xF6, 0xA8, 0x14, 0x70, 0x9D,
  40926. 0x2B, 0xC1, 0x42, 0xFE, 0xF0, 0x25, 0x27, 0xCA,
  40927. 0xE7, 0x71, 0x23, 0x58, 0x37, 0x1C, 0x54, 0x26,
  40928. 0x52, 0x2C, 0xCC, 0x64, 0x30, 0x0C, 0x2C, 0xD9,
  40929. 0xFB, 0xE2, 0x0C, 0x65, 0x62, 0xE3, 0x48, 0x35,
  40930. 0x20, 0x5F, 0xCD, 0xD5, 0xA8, 0x98, 0x2C, 0x92,
  40931. 0x0B, 0xB4, 0x77, 0xFB, 0x88, 0x17, 0x02, 0x82,
  40932. 0x7B, 0x49, 0x11, 0x87, 0x13, 0x94, 0xC0, 0x6B,
  40933. 0x5F, 0xEC, 0xD0, 0xC7, 0x40, 0xAF, 0x7B, 0x27,
  40934. 0x63, 0x7B, 0xAC, 0x1A, 0x0C, 0xBC, 0xA5, 0x37,
  40935. 0xE4, 0x43, 0x3E, 0xA8, 0x47, 0x45, 0x4C, 0x69,
  40936. 0x38, 0x97, 0xA3, 0x2E, 0x4D, 0x18, 0x44, 0x19,
  40937. 0x54, 0x26, 0xA0, 0xC6, 0xAE, 0xD6, 0x74, 0x72,
  40938. 0xBD, 0x2C, 0x4E, 0xEE, 0x17, 0x9F, 0x3F, 0x60,
  40939. 0x84, 0xA3, 0x6A, 0x76, 0x89, 0xF4, 0xCB, 0x1F,
  40940. 0x8E, 0x5D, 0xB2, 0xDD, 0xE5, 0x4A, 0xCC, 0x06,
  40941. 0x66, 0xBA, 0x98, 0x41, 0x54, 0x31, 0xA4, 0xB2,
  40942. 0x02, 0xF4, 0x02, 0xFB, 0x1F, 0x1B, 0xCC, 0xDC,
  40943. 0x23, 0xBF, 0xF1, 0x31, 0x48, 0xC7, 0xB8, 0xF6,
  40944. 0x1F, 0xBF, 0x62, 0x43, 0xB2, 0x96, 0xA7, 0x8E,
  40945. 0xB6, 0x98, 0x18, 0x9D, 0xA9, 0x5B, 0xDA, 0x85,
  40946. 0xDB, 0xC1, 0x1D, 0x15, 0xFF, 0xDC, 0x6B, 0xF4,
  40947. 0x6C, 0x53, 0xF6, 0xE4, 0x72, 0xA8, 0x71, 0x40,
  40948. 0x1E, 0x9A, 0x9A, 0xB7, 0xF9, 0xFB, 0x46, 0x7E,
  40949. 0xB4, 0xEC, 0xB1, 0xF0, 0xDA, 0x7E, 0x63, 0xEE,
  40950. 0x86, 0x19, 0xCB, 0xC4, 0x86, 0xEB, 0xB0, 0xF2,
  40951. 0x12, 0x0A, 0x78, 0x11, 0xBF, 0xB0, 0x55, 0x7D,
  40952. 0x13, 0x93, 0x05, 0x74, 0x29, 0x7C, 0x94, 0x64,
  40953. 0xFC, 0x59, 0x5B, 0x27, 0x56, 0x9A, 0xDF, 0x5F,
  40954. 0x4A, 0x8D, 0xF6, 0x69, 0xC9, 0xEE, 0xA0, 0xA2,
  40955. 0x50, 0xF4, 0xD2, 0x2C, 0x2E, 0x8C, 0x64, 0x1B,
  40956. 0xA3, 0x90, 0x2B, 0xA8, 0x08, 0x00, 0x48, 0x99,
  40957. 0x65, 0xF1, 0x1A, 0xF1, 0xE1, 0xA8, 0x57, 0x17,
  40958. 0xC6, 0x24, 0xE7, 0x42, 0xF1, 0x61, 0x55, 0x08,
  40959. 0x19, 0xD1, 0xF0, 0x37, 0x2C, 0x5C, 0xAE, 0x8B,
  40960. 0xC6, 0x2B, 0x54, 0x9E, 0xFE, 0x87, 0x44, 0x61,
  40961. 0x08, 0x0D, 0x06, 0x34, 0x6E, 0x1F, 0xA6, 0xF0,
  40962. 0x15, 0x14, 0xFB, 0xEC, 0xCB, 0x06, 0xE3, 0x4E,
  40963. 0xE2, 0x71, 0xA0, 0xF0, 0x03, 0x17, 0x90, 0xBD,
  40964. 0xAB, 0xE0, 0xF0, 0x2B, 0xBA, 0x4A, 0xEA, 0x4B,
  40965. 0x73, 0x97, 0xFE, 0x33, 0x33, 0xEB, 0x81, 0x21,
  40966. 0x82, 0x07, 0x57, 0x28, 0x1F, 0x96, 0xA5, 0x83,
  40967. 0x1F, 0x9E, 0x49, 0x03, 0x66, 0x54, 0x9D, 0x16,
  40968. 0x76, 0x3F, 0xF1, 0x9F, 0xF7, 0x73, 0x58, 0x0E,
  40969. 0xD5, 0xE3, 0xE1, 0xE2, 0xAA, 0x3E, 0x38, 0xF8,
  40970. 0x84, 0x74, 0xDE, 0x6D, 0x9B, 0xA6, 0x99, 0x4F,
  40971. 0x8E, 0x62, 0x91, 0x60, 0x48, 0x8C, 0xB4, 0xCD,
  40972. 0x5B, 0x87, 0x8C, 0xDA, 0x37, 0xAA, 0xEC, 0x9B,
  40973. 0x56, 0x36, 0x9A, 0x7E, 0x73, 0xF7, 0x3B, 0x42,
  40974. 0x86, 0x39, 0xA0, 0x5C, 0x13, 0x78, 0x44, 0x8A,
  40975. 0xDB, 0x7F, 0x07, 0x4D, 0xC8, 0x15, 0x4D, 0x92,
  40976. 0xE1, 0x3C, 0x63, 0x56, 0xB5, 0xF4, 0x66, 0xD6,
  40977. 0x64, 0x77, 0x15, 0x9B, 0x2A, 0x94, 0x37, 0x99,
  40978. 0xAD, 0x61, 0x9A, 0x02, 0x9F, 0x30, 0x10, 0xD0,
  40979. 0x37, 0x67, 0x2D, 0xBB, 0x68, 0x20, 0xE5, 0x13,
  40980. 0x23, 0xAD, 0xA9, 0x88, 0x81, 0xC6, 0xDE, 0x85,
  40981. 0x9D, 0xF8, 0x75, 0xAB, 0xAF, 0x11, 0xDA, 0x5D,
  40982. 0xDC, 0xA5, 0xA7, 0x77, 0x62, 0x2B, 0xDA, 0xE8,
  40983. 0xFA, 0xCE, 0x2E, 0x0C, 0xED, 0x3B, 0x6A, 0x77,
  40984. 0xB8, 0x8A, 0x87, 0x29, 0xFB, 0x7C, 0x50, 0x93,
  40985. 0x3D, 0xA6, 0xC5, 0x2E, 0x3F, 0x4D, 0x94, 0x8F,
  40986. 0x9D, 0xC1, 0x53, 0xB5, 0xB1, 0x29, 0x9C, 0xD8,
  40987. 0x62, 0x1D, 0xDF, 0xBA, 0x48, 0xAF, 0x44, 0xE4,
  40988. 0xB6, 0xF6, 0x10, 0x6E, 0xE7, 0x77, 0x95, 0x01,
  40989. 0xDD, 0x5F, 0xB3, 0xC5, 0x78, 0xEA, 0x4D, 0x32,
  40990. 0xC5, 0xC2, 0xF0, 0x36, 0xA7, 0x35, 0x27, 0x03,
  40991. 0xAD, 0xD1, 0x35, 0xAB, 0x84, 0x46, 0x01, 0x62,
  40992. 0x41, 0x7E, 0x50, 0xBF, 0x91, 0xE6, 0x07, 0x97,
  40993. 0xD5, 0x9B, 0x9E, 0x18, 0xD3, 0x24, 0xDA, 0x97,
  40994. 0x1F, 0x4F, 0xF4, 0x28, 0xAE, 0xAF, 0x23, 0xAC,
  40995. 0x0B, 0xA4, 0xE2, 0xE2, 0xFC, 0x7A, 0xBA, 0xA6,
  40996. 0xC8, 0x98, 0x4F, 0xE9, 0xE2, 0xD8, 0x5B, 0x8A,
  40997. 0xDA, 0x40, 0x86, 0xB3, 0xC1, 0x3A, 0xBD, 0x43,
  40998. 0xCF, 0xD1, 0xC7, 0x11, 0xD8, 0x32, 0x6B, 0x18,
  40999. 0xAD, 0xC3, 0x4C, 0xC1, 0x4C, 0xF8, 0x95, 0x7E,
  41000. 0xC3, 0x95, 0x94, 0x98, 0xFC, 0x2A, 0x7B, 0xE0,
  41001. 0x6B, 0xD1, 0x84, 0x0D, 0xE1, 0x70, 0x36, 0x65,
  41002. 0x66, 0xE5, 0x07, 0x41, 0x95, 0x77, 0x63, 0xC2,
  41003. 0xDD, 0x27, 0xAC, 0xF8, 0xC3, 0xF1, 0x02, 0x6F,
  41004. 0xAE, 0xE1, 0xD2, 0x56, 0x2F, 0xA1, 0x05, 0x2E,
  41005. 0x69, 0xAF, 0xDD, 0x42, 0xF4, 0x46, 0xF0, 0x59,
  41006. 0x88, 0x66, 0xD5, 0xD3, 0x06, 0xBF, 0x1B, 0x77,
  41007. 0x50, 0x42, 0xB0, 0x35, 0x92, 0x73, 0x72, 0x82,
  41008. 0x7F, 0x43, 0x86, 0x31, 0x65, 0x34, 0xFA, 0x1B,
  41009. 0x7E, 0xE6, 0x33, 0xBA, 0x95, 0x8C, 0xED, 0x8F,
  41010. 0x0D, 0x24, 0x1D, 0x46, 0x88, 0xE3, 0xC7, 0x91,
  41011. 0x8E, 0x2A, 0x75, 0x62, 0x63, 0x77, 0xC3, 0x42,
  41012. 0xA5, 0x90, 0x69, 0x2B, 0xBF, 0xB8, 0x27, 0xBF,
  41013. 0x90, 0x51, 0x41, 0x82, 0xD4, 0x09, 0x0D, 0xF8,
  41014. 0xD7, 0x32, 0x35, 0x19, 0xA1, 0xAB, 0x6C, 0xD0,
  41015. 0x22, 0x73, 0x67, 0x41, 0x0D, 0xD1, 0x4D, 0x37,
  41016. 0x86, 0xA2, 0x6D, 0xDF, 0x91, 0x72, 0x4F, 0xC8,
  41017. 0x2D, 0x06, 0xA2, 0x5D, 0x5F, 0x56, 0x68, 0x39,
  41018. 0x53, 0xE8, 0xE0, 0xF2, 0x0E, 0x3C, 0x17, 0x71,
  41019. 0xDA, 0xF4, 0x2E, 0x52, 0x02, 0x4C, 0x11, 0x6E,
  41020. 0xD8, 0xA4, 0xC0, 0xA6, 0x11, 0x68, 0x0F, 0x5F,
  41021. 0xE0, 0x0E, 0xD9, 0xB1, 0x48, 0xD1, 0x5F, 0x12,
  41022. 0xAA, 0x95, 0xB9, 0xBD, 0x5A, 0x9F, 0xD8, 0x10,
  41023. 0x16, 0x42, 0xB3, 0x69, 0x11, 0xF3, 0x10, 0xB0,
  41024. 0xDE, 0x18, 0x17, 0x1D, 0x62, 0x37, 0xD9, 0xBE,
  41025. 0x17, 0x25, 0xDC, 0x29, 0x9A, 0x1A, 0x3A, 0xAA,
  41026. 0xE9, 0x85, 0x40, 0xCE, 0xED, 0x26, 0x95, 0x3D,
  41027. 0x10, 0xCE, 0x85, 0x47, 0xF1, 0xC3, 0xE4, 0x6A,
  41028. 0x86, 0x2B, 0xED, 0x42, 0x8D, 0x1E, 0x10, 0x60,
  41029. 0x1B, 0xF3, 0x28, 0xC7, 0x27, 0xFD, 0x95, 0x34,
  41030. 0x3E, 0x2D, 0xB4, 0xD9, 0xAC, 0xD5, 0xD1, 0xCB,
  41031. 0x47, 0x15, 0xF6, 0x00, 0x40, 0x96, 0xED, 0xA0,
  41032. 0x93, 0xD1, 0xB0, 0xA3, 0x3B, 0x1E, 0x56, 0xF1,
  41033. 0x6D, 0x73, 0xAD, 0xB8, 0x73, 0x2C, 0xB4, 0xA3,
  41034. 0x11, 0x60, 0xA4, 0x49, 0x1F, 0xAA, 0x0C, 0x86,
  41035. 0xE6, 0x80, 0xE3, 0xD7, 0xC0, 0x2C, 0xCE, 0xA8,
  41036. 0xFE, 0x92, 0xF1, 0xE0, 0x01, 0x01, 0x6D, 0x22,
  41037. 0x02, 0x21, 0xDD, 0x10, 0xED, 0x62, 0x60, 0x17,
  41038. 0x96, 0x6C, 0x34, 0x50, 0xAD, 0x12, 0x13, 0x65,
  41039. 0x91, 0x8C, 0x93, 0x09, 0x1F, 0x14, 0x71, 0x2B,
  41040. 0xA4, 0x77, 0xCF, 0x2E, 0x26, 0x32, 0x96, 0xC7,
  41041. 0x78, 0xA2, 0xBA, 0xEE, 0xF5, 0x84, 0x94, 0x55,
  41042. 0xFA, 0x35, 0xCB, 0x61, 0x72, 0x51, 0xE0, 0x2A,
  41043. 0x22, 0xDA, 0xF5, 0xC3, 0x3E, 0x5A, 0xAA, 0x9F,
  41044. 0x00, 0xE8, 0xAC, 0xDC, 0x50, 0xEC, 0xF4, 0x7C,
  41045. 0x52, 0x15, 0x03, 0xC5, 0x2F, 0x27, 0xD6, 0xB5,
  41046. 0x7C, 0x8F, 0x2B, 0x3D, 0x8F, 0x12, 0x22, 0x41,
  41047. 0x3E, 0x7F, 0xA4, 0xEC, 0x59, 0x29, 0x63, 0x38,
  41048. 0x09, 0x8C, 0x9A, 0xB5, 0xA1, 0xD8, 0xA5, 0x78,
  41049. 0x84, 0xBD, 0x86, 0x00, 0x41, 0x40, 0x6D, 0x96,
  41050. 0x55, 0xD1, 0x73, 0x82, 0x94, 0x9A, 0x03, 0xD5,
  41051. 0x0F, 0x11, 0x08, 0xD0, 0x5B, 0xDB, 0x31, 0xCA,
  41052. 0x08, 0xE6, 0x6F, 0x2D, 0x8D, 0xE4, 0x80, 0xC6,
  41053. 0x79, 0x35, 0x18, 0xD4, 0x9A, 0x60, 0xD4, 0x76,
  41054. 0x2A, 0x9E, 0xDD, 0xC0, 0x24, 0x9B, 0x42, 0x2E,
  41055. 0x84, 0x02, 0x0E, 0xD5, 0x39, 0xA1, 0x4E, 0x24,
  41056. 0x78, 0xF6, 0x8B, 0xAB, 0x1F, 0x2B, 0x00, 0xE2,
  41057. 0x2A, 0x5C, 0xBB, 0x62, 0x97, 0x9A, 0xC7, 0x44,
  41058. 0xE0, 0x8B, 0x57, 0xD5, 0xB5, 0x78, 0xC4, 0x01,
  41059. 0xA8, 0xD2, 0x6D, 0x9A, 0xDD, 0x15, 0x05, 0x23,
  41060. 0x60, 0x82, 0x86, 0x36, 0x72, 0xD9, 0x11, 0xCF,
  41061. 0x3A, 0x09, 0x66, 0xD3, 0x03, 0xF8, 0x91, 0x70,
  41062. 0x93, 0xBF, 0x97, 0xAF, 0x90, 0xA7, 0xE1, 0xF9,
  41063. 0xD5, 0x9B, 0x09, 0x20, 0x6B, 0x9C, 0xAC, 0x35,
  41064. 0x11, 0x0F, 0xA3, 0x8D, 0x58, 0x90, 0xED, 0x21,
  41065. 0x16, 0x83, 0x5C, 0xE3, 0x73, 0x84, 0xF5, 0x63,
  41066. 0x0F, 0x1C, 0x42, 0x8E, 0x21, 0x36, 0x05, 0x87,
  41067. 0x2E, 0xCF, 0x91, 0x1B, 0x01, 0x4B, 0x91, 0xC2,
  41068. 0xC6, 0x00, 0xE8, 0xA4, 0x07, 0x29, 0xD0, 0x7B,
  41069. 0xF9, 0x18, 0x79, 0x07, 0x42, 0xC9, 0x27, 0x9F,
  41070. 0x31, 0x14, 0xF6, 0x8C, 0xDF, 0x65, 0x94, 0xCD,
  41071. 0xA3, 0xCA, 0x66, 0x94, 0x22, 0x3A, 0x82, 0xF6,
  41072. 0x6C, 0x2B, 0x4B, 0xDF, 0x3E, 0x51, 0xC6, 0xFF,
  41073. 0xDC, 0x55, 0xE0, 0xFF, 0x51, 0xEF, 0xD6, 0xC9,
  41074. 0x34, 0x36, 0x2B, 0xE7, 0xD6, 0xFA, 0xBC, 0x11,
  41075. 0xB8, 0xB0, 0xDA, 0xDD, 0xD5, 0x21, 0x08, 0xFA,
  41076. 0x5F, 0xB5, 0xCA, 0x75, 0x8A, 0x64, 0x37, 0x7D,
  41077. 0x38, 0x6D, 0x45, 0xCE, 0x70, 0x60, 0x5B, 0x46,
  41078. 0x0E, 0x81, 0x57, 0x03, 0x7B, 0x5B, 0x1B, 0x2E,
  41079. 0x0A, 0xED, 0xD1, 0x2A, 0x63, 0x31, 0x15, 0xD6,
  41080. 0xC4, 0x3B, 0xC6, 0xC7, 0xC8, 0x36, 0xFF, 0xF3,
  41081. 0x3E, 0x7D, 0x03, 0x3F, 0x2E, 0x58, 0x00, 0x52,
  41082. 0x71, 0x64, 0xC0, 0xC4, 0x78, 0x1C, 0x37, 0xDF,
  41083. 0x50, 0xB6, 0x6B, 0xBA, 0x5C, 0x81, 0x94, 0x73,
  41084. 0xA1, 0xC5, 0x30, 0x20, 0x83, 0xA1, 0x6F, 0x01,
  41085. 0x43, 0x72, 0x79, 0xD2, 0xF2, 0xDF, 0x14, 0xC8,
  41086. 0x78, 0x26, 0x9A, 0x2F, 0x3F, 0xA4, 0x0C, 0x1C,
  41087. 0x76, 0x1E, 0xD6, 0x15, 0x01, 0xAC, 0x9E, 0xF1,
  41088. 0x41, 0x02, 0x90, 0x38, 0xC8, 0x19, 0x95, 0x40,
  41089. 0x89, 0xB7, 0x38, 0x09, 0x87, 0x08, 0x17, 0x43,
  41090. 0x93, 0xFE, 0xAE, 0xA7, 0xB0, 0x2A, 0xE5, 0xCE,
  41091. 0xF6, 0x7B, 0x3C, 0x8C, 0xE6, 0xA9, 0x70, 0x67,
  41092. 0x5C, 0xA1, 0xB8, 0xC8, 0x56, 0xDC, 0xF5, 0x97,
  41093. 0x25, 0x08, 0xC7, 0xC6, 0xB2, 0x5E, 0xE4, 0xD1,
  41094. 0x2D, 0x82, 0x12, 0xB9, 0x89, 0x40, 0xB4, 0x88,
  41095. 0xEC, 0x40, 0x2A, 0xC7, 0xAE, 0x3C, 0x70, 0xDF,
  41096. 0x93, 0x8D, 0x12, 0x88, 0xCD, 0xA7, 0xA3, 0x19,
  41097. 0xE0, 0x85, 0xBC, 0x73, 0xA4, 0x69, 0xB2, 0xD2,
  41098. 0xA3, 0x30, 0x3B, 0x11, 0xA6, 0x83, 0x10, 0x0A,
  41099. 0xF6, 0xDB, 0x86, 0x93, 0x7B, 0xA1, 0x18, 0x29,
  41100. 0x03, 0x61, 0x6E, 0x3F, 0x03, 0x47, 0xBD, 0x68,
  41101. 0x59, 0x1B, 0x47, 0xBA, 0x65, 0x15, 0x6B, 0x93,
  41102. 0xF2, 0x60, 0xDE, 0x59, 0xB3, 0xAE, 0xB2, 0x89,
  41103. 0xE2, 0xA7, 0x3A, 0x3B, 0xFF, 0x38, 0xC2, 0xF3,
  41104. 0xAD, 0xED, 0xA2, 0x9C, 0x7E, 0x90, 0x28, 0x3A,
  41105. 0xC7, 0xB8, 0x6D, 0x03, 0x6B, 0x47, 0xD5, 0xBA,
  41106. 0x1A, 0x03, 0xEC, 0x78, 0x3D, 0x25, 0x0B, 0xAC,
  41107. 0xAE, 0x58, 0x47, 0xE4, 0x1F, 0x82, 0x9C, 0xB3,
  41108. 0x3D, 0xE0, 0x8D, 0xF8, 0xF7, 0xD6, 0x9C, 0x9A,
  41109. 0xA4, 0xED, 0xE8, 0xD7, 0xAB, 0x96, 0x84, 0x07,
  41110. 0xEE, 0xD3, 0x1A, 0x05, 0x6B, 0xA0, 0xEF, 0x88,
  41111. 0x16, 0xE1, 0x27, 0xAA, 0x90, 0x06, 0x5A, 0x67,
  41112. 0x9E, 0x1C, 0xA9, 0x55, 0x0D, 0xEE, 0xF2, 0x5A,
  41113. 0xC5, 0xB7, 0xA3, 0x4F, 0x70, 0xDC, 0xF2, 0xB1,
  41114. 0x16, 0xCF, 0x35, 0x1F, 0x3B, 0xAD, 0xA9, 0x9F,
  41115. 0x83, 0x6C, 0x73, 0x0D, 0xCC, 0x1A, 0xE0, 0x3F,
  41116. 0x49, 0x6C, 0xF3, 0xF0, 0x38, 0x7A, 0x0C, 0x2C,
  41117. 0x70, 0x2E, 0x2C, 0x13, 0xBD, 0xD9, 0xCF, 0x45,
  41118. 0xA1, 0xCD, 0x53, 0xAB, 0x58, 0x73, 0x11, 0x88,
  41119. 0xB1, 0x8E, 0xA8, 0xBE, 0x48, 0xD5, 0x10, 0xC5,
  41120. 0x81, 0x2E, 0x90, 0xBC, 0xEC, 0xBC, 0x6E, 0x19,
  41121. 0x8E, 0x70, 0x8B, 0x1C, 0x08, 0xC8, 0xF8, 0x64,
  41122. 0xB1, 0x24, 0xBB, 0x4C, 0xC0, 0xBD, 0xBB, 0xDF,
  41123. 0x2C, 0x2F, 0x4E, 0x38, 0x8F, 0xC1, 0x96, 0x60,
  41124. 0xD6, 0x9C, 0xC2, 0xC0, 0xEB, 0xF9, 0x10, 0x08,
  41125. 0xC8, 0x24, 0x3D, 0xB4, 0x2D, 0xDA, 0xF5, 0x7C,
  41126. 0x02, 0x42, 0x51, 0xC4, 0x23, 0x1D, 0xF5, 0x37,
  41127. 0x90, 0xCE, 0x57, 0x56, 0x13, 0xEE, 0x8E, 0x1C,
  41128. 0x7A, 0x33, 0xC1, 0x56, 0x1F, 0x35, 0x04, 0xDE,
  41129. 0xAA, 0xED, 0x1E, 0x84, 0x08, 0x50, 0x06, 0x23,
  41130. 0xEC, 0xA5, 0xAE, 0x5A, 0x28, 0x45, 0x41, 0x17,
  41131. 0x49, 0x93, 0x0D, 0x8E, 0x42, 0x07, 0x8C, 0x03,
  41132. 0x23, 0x49, 0x95, 0x7F, 0xC3, 0x9A, 0x1D, 0xA0,
  41133. 0xEA, 0xF9, 0xE8, 0x7C, 0x31, 0xFF, 0xBF, 0x6A,
  41134. 0xC0, 0xC1, 0x81, 0x1E, 0xB2, 0x8A, 0x41, 0xB1,
  41135. 0xD8, 0x6B, 0xD7, 0xD4, 0x9A, 0xD1, 0xC4, 0x68,
  41136. 0xA4, 0x95, 0x94, 0x95, 0x65, 0x25, 0xA2, 0x0A,
  41137. 0x31, 0x70, 0x0F, 0x12, 0x2F, 0x4C, 0x4B, 0xB2,
  41138. 0x25, 0x2A, 0x2F, 0x3D, 0x5C, 0x5D, 0x68, 0x73,
  41139. 0x83, 0x8C, 0x90, 0x95, 0x97, 0xBB, 0xCA, 0xD8,
  41140. 0xE1, 0x33, 0x3D, 0x5D, 0x61, 0x7C, 0x87, 0xC8,
  41141. 0xEE, 0x0F, 0x1B, 0x22, 0x38, 0x3B, 0x42, 0x4B,
  41142. 0x4C, 0x5C, 0x62, 0x72, 0x98, 0xA3, 0xBE, 0xCC,
  41143. 0x1B, 0x32, 0x47, 0x5C, 0x9D, 0xB6, 0xB9, 0xBD,
  41144. 0xC6, 0xD6, 0xDC, 0xF5, 0x00, 0x00, 0x00, 0x00,
  41145. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  41146. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  41147. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  41148. 0x11, 0x19, 0x28, 0x34
  41149. };
  41150. #endif
  41151. #ifndef WOLFSSL_NO_ML_DSA_65
  41152. static const byte pk_65[] = {
  41153. 0x6C, 0x9E, 0x7A, 0x1E, 0xE3, 0x66, 0x25, 0x76,
  41154. 0x0E, 0x5D, 0x2F, 0x33, 0xDF, 0x29, 0x29, 0xDA,
  41155. 0x56, 0x20, 0x32, 0x34, 0x06, 0x91, 0x60, 0xE5,
  41156. 0xF2, 0xBF, 0x03, 0x9C, 0x11, 0x06, 0x22, 0x73,
  41157. 0x07, 0x3C, 0x23, 0x75, 0x66, 0xCE, 0x05, 0x5D,
  41158. 0x87, 0x1F, 0x38, 0xAC, 0xD1, 0xA9, 0x85, 0x9A,
  41159. 0x82, 0x44, 0x67, 0xF1, 0x9B, 0xE6, 0x8E, 0x4F,
  41160. 0x00, 0x64, 0x5D, 0x22, 0x5C, 0x42, 0xC8, 0x5A,
  41161. 0x55, 0x7D, 0x2C, 0x5E, 0xCB, 0x44, 0x2B, 0x0F,
  41162. 0x02, 0x8A, 0x65, 0x28, 0x89, 0x8E, 0xE2, 0xB6,
  41163. 0x73, 0xD8, 0x63, 0xF3, 0x2E, 0xB9, 0xEC, 0x81,
  41164. 0x64, 0x12, 0x75, 0x41, 0xF3, 0x25, 0x19, 0xBB,
  41165. 0x88, 0xE0, 0x34, 0xA0, 0x3F, 0x46, 0xF7, 0xD1,
  41166. 0x93, 0xCD, 0x3D, 0xFB, 0xAD, 0xF6, 0x35, 0x57,
  41167. 0x92, 0x6C, 0x5C, 0x8F, 0x5B, 0x76, 0x6A, 0x7F,
  41168. 0xC5, 0xEC, 0x8B, 0x3F, 0x94, 0x8B, 0xF7, 0xA8,
  41169. 0x21, 0xB5, 0x4C, 0x94, 0x41, 0xAB, 0x0B, 0xD8,
  41170. 0x33, 0xFD, 0x63, 0x54, 0xCE, 0xC7, 0x06, 0xFA,
  41171. 0xA5, 0x00, 0xAB, 0xB5, 0x28, 0x9B, 0x90, 0xB1,
  41172. 0xBF, 0x91, 0x76, 0x77, 0xA2, 0x9D, 0x11, 0x5F,
  41173. 0x00, 0x94, 0xBD, 0xB4, 0x8D, 0xC7, 0x2E, 0x26,
  41174. 0x1D, 0xBA, 0x12, 0x0B, 0xA6, 0xFF, 0x5E, 0x52,
  41175. 0xA0, 0x1B, 0x17, 0x89, 0x81, 0xDD, 0x82, 0x96,
  41176. 0x44, 0x46, 0x56, 0xD9, 0x44, 0x2D, 0xF9, 0xCB,
  41177. 0xB6, 0xBF, 0xDA, 0xE5, 0x6A, 0x23, 0x0F, 0x6F,
  41178. 0x29, 0xF9, 0x4C, 0xDC, 0xC2, 0x65, 0x57, 0x6A,
  41179. 0xA8, 0x75, 0x2A, 0xCE, 0xD0, 0x7E, 0x99, 0x89,
  41180. 0x5C, 0xAE, 0xF0, 0x16, 0x8B, 0xF8, 0x3D, 0x23,
  41181. 0xFD, 0xAD, 0xFB, 0xB9, 0x28, 0xCB, 0xCD, 0xAB,
  41182. 0xA2, 0x5F, 0xE2, 0xCD, 0x26, 0xAD, 0xDF, 0xB0,
  41183. 0xDA, 0xCD, 0x74, 0x94, 0x0F, 0x35, 0x14, 0x26,
  41184. 0x94, 0x2F, 0x17, 0x6F, 0xFB, 0xC5, 0xF3, 0x45,
  41185. 0x6D, 0xB7, 0xC9, 0x12, 0xAA, 0x16, 0xB8, 0x6D,
  41186. 0x07, 0x45, 0xF8, 0x7C, 0x9F, 0x45, 0x37, 0x0A,
  41187. 0x84, 0x56, 0xA1, 0xAD, 0xB5, 0x1D, 0xB4, 0x05,
  41188. 0x2B, 0x5C, 0x9E, 0xAF, 0x60, 0xAD, 0x7B, 0x80,
  41189. 0xA4, 0x2E, 0xA4, 0xBF, 0x92, 0xC8, 0x41, 0x27,
  41190. 0x3A, 0xD7, 0x61, 0xDE, 0xDB, 0x0D, 0x34, 0xBF,
  41191. 0x57, 0x96, 0x00, 0xB1, 0x49, 0xFC, 0xCD, 0x42,
  41192. 0xAB, 0x15, 0x49, 0xBA, 0x0A, 0xBE, 0xDA, 0x57,
  41193. 0xEF, 0x71, 0xD1, 0xFC, 0xA5, 0x70, 0x2A, 0xAD,
  41194. 0x08, 0x32, 0x99, 0xBB, 0x98, 0x30, 0x01, 0x89,
  41195. 0xC2, 0x5F, 0x3B, 0x27, 0x0A, 0x87, 0x65, 0x8D,
  41196. 0x0B, 0x2E, 0xA5, 0x65, 0x24, 0x14, 0x7F, 0x73,
  41197. 0x9E, 0xB6, 0xC6, 0x76, 0xD7, 0xBE, 0x73, 0xDD,
  41198. 0x3B, 0x95, 0xB1, 0x0C, 0x55, 0xAB, 0x46, 0xFD,
  41199. 0x01, 0x54, 0x9C, 0x51, 0x68, 0xBF, 0x7D, 0xA1,
  41200. 0x3A, 0x49, 0x97, 0x85, 0xF3, 0x5A, 0x1E, 0x3B,
  41201. 0x56, 0xF4, 0xC5, 0x67, 0xF5, 0x4E, 0xA9, 0xAA,
  41202. 0x28, 0x17, 0xA3, 0x36, 0x38, 0x36, 0x43, 0xFA,
  41203. 0x2E, 0xA3, 0x1F, 0xB1, 0xB7, 0x3E, 0x10, 0x24,
  41204. 0x8D, 0xFC, 0xA0, 0x5C, 0x04, 0x13, 0x12, 0x66,
  41205. 0x49, 0x8E, 0x1C, 0x94, 0x91, 0x13, 0x5A, 0x50,
  41206. 0xE6, 0x3D, 0x02, 0xFA, 0xDF, 0x41, 0x65, 0xFC,
  41207. 0x9E, 0x15, 0xE3, 0xE1, 0xB3, 0x2F, 0xAB, 0x83,
  41208. 0x37, 0x68, 0x4C, 0x49, 0x19, 0x3E, 0x1B, 0xC4,
  41209. 0xED, 0xEA, 0xE3, 0x73, 0xA2, 0x67, 0xA7, 0x14,
  41210. 0xAC, 0x1F, 0x90, 0x9C, 0xC6, 0x57, 0xCD, 0x80,
  41211. 0x66, 0x64, 0x63, 0x27, 0xE0, 0xEE, 0xA0, 0x41,
  41212. 0xAC, 0x9F, 0x2A, 0xEF, 0xFC, 0x80, 0x69, 0x1B,
  41213. 0xF6, 0x0D, 0x3C, 0x94, 0xC6, 0x42, 0x55, 0x7E,
  41214. 0x42, 0x99, 0xD3, 0x95, 0x92, 0x22, 0x16, 0xC6,
  41215. 0x5E, 0x75, 0xB7, 0xE1, 0xA5, 0x02, 0x89, 0x60,
  41216. 0x38, 0x4B, 0xF8, 0x16, 0xC9, 0xF7, 0x05, 0x48,
  41217. 0x29, 0xE7, 0x98, 0x5B, 0x58, 0x41, 0xA7, 0x33,
  41218. 0xF3, 0x3F, 0xCE, 0x24, 0x55, 0xEF, 0xC8, 0x9B,
  41219. 0xAE, 0x84, 0xB4, 0x79, 0x90, 0xE8, 0xD0, 0xAF,
  41220. 0xC6, 0x19, 0x3E, 0x4A, 0xF9, 0xBC, 0x68, 0x0A,
  41221. 0xE2, 0x4F, 0xE5, 0x91, 0xE8, 0x8B, 0xA6, 0xA2,
  41222. 0xAE, 0x12, 0xDA, 0x38, 0x58, 0xD2, 0x1F, 0x49,
  41223. 0x2D, 0x24, 0xAB, 0xC4, 0xFE, 0x4F, 0xD5, 0x2D,
  41224. 0x5A, 0xBF, 0x24, 0xBD, 0x25, 0x46, 0x87, 0xB9,
  41225. 0x18, 0x79, 0x2F, 0x0A, 0x00, 0x3A, 0x52, 0x22,
  41226. 0xDF, 0x45, 0x03, 0x86, 0x85, 0xC7, 0x25, 0xCE,
  41227. 0x75, 0x79, 0xE0, 0x2C, 0xB1, 0x68, 0xBB, 0xC6,
  41228. 0x66, 0xAB, 0xF6, 0x69, 0x85, 0x6E, 0x10, 0x53,
  41229. 0x7C, 0x92, 0x91, 0x69, 0x2C, 0x0C, 0xB0, 0xCF,
  41230. 0xA9, 0x06, 0x27, 0x0A, 0xC2, 0xC7, 0xB7, 0xDC,
  41231. 0x31, 0xD4, 0xF9, 0x28, 0x3C, 0xB2, 0xDB, 0x8A,
  41232. 0x46, 0x2A, 0xEC, 0x0B, 0x98, 0x07, 0xBB, 0xF4,
  41233. 0xAB, 0x45, 0x76, 0xFE, 0xC6, 0x22, 0x6B, 0x41,
  41234. 0x79, 0x32, 0x2B, 0x67, 0xAE, 0xA5, 0x3B, 0xDD,
  41235. 0xF9, 0xC9, 0xBE, 0x5E, 0x0D, 0xBC, 0x43, 0xF7,
  41236. 0x87, 0x43, 0x06, 0x8A, 0xB5, 0xBE, 0x49, 0xF0,
  41237. 0xE6, 0x2F, 0x8E, 0x2E, 0xB1, 0xB6, 0xC6, 0x73,
  41238. 0x6C, 0x05, 0xC9, 0x41, 0x3D, 0x06, 0x5C, 0xE0,
  41239. 0xCC, 0xB7, 0x90, 0x54, 0x80, 0x41, 0xD7, 0xE8,
  41240. 0x32, 0x88, 0x1A, 0x83, 0x9B, 0x57, 0x29, 0xAF,
  41241. 0x94, 0xAB, 0x79, 0xFD, 0x8A, 0x16, 0xDF, 0xFF,
  41242. 0x78, 0xCA, 0xAA, 0x14, 0x1D, 0x97, 0xCC, 0x06,
  41243. 0x50, 0xF8, 0x62, 0x62, 0xF2, 0x61, 0x59, 0xBE,
  41244. 0x8B, 0x36, 0x1A, 0x4A, 0x04, 0x1E, 0x9A, 0x0B,
  41245. 0x65, 0x11, 0xBB, 0xE3, 0x35, 0x5A, 0x4B, 0xF5,
  41246. 0x7A, 0xC0, 0x98, 0x48, 0x84, 0x7E, 0xE0, 0x24,
  41247. 0x3C, 0x3B, 0xA7, 0x74, 0x77, 0x6F, 0x7E, 0x9A,
  41248. 0x22, 0x72, 0x75, 0xD7, 0x4E, 0x6E, 0x31, 0x01,
  41249. 0xD3, 0x82, 0x81, 0x87, 0x63, 0xED, 0x1E, 0x13,
  41250. 0x53, 0xAB, 0x9E, 0xEC, 0xCD, 0x92, 0x0C, 0xD2,
  41251. 0x89, 0x22, 0xD5, 0x59, 0xA4, 0x04, 0x8F, 0x40,
  41252. 0xF0, 0x62, 0x16, 0x4C, 0xB6, 0x61, 0xC4, 0xF4,
  41253. 0xAF, 0xA8, 0x1A, 0x3D, 0x55, 0x93, 0x3C, 0x47,
  41254. 0x91, 0xED, 0xDA, 0xA3, 0x93, 0x9E, 0x5A, 0xC3,
  41255. 0x42, 0xB0, 0xAD, 0x1F, 0x43, 0x8A, 0x53, 0x2C,
  41256. 0x6C, 0xE7, 0x86, 0x68, 0x1A, 0x87, 0x0D, 0x94,
  41257. 0xEC, 0x88, 0xA3, 0x34, 0xCC, 0xEF, 0xC6, 0xAC,
  41258. 0xE7, 0xD9, 0x88, 0xA1, 0xA8, 0x2B, 0xC0, 0xAC,
  41259. 0xCE, 0x78, 0x5F, 0x12, 0x3B, 0xE2, 0x3A, 0x7C,
  41260. 0x92, 0xAF, 0x10, 0x8E, 0x5E, 0xD4, 0xF0, 0x86,
  41261. 0x9E, 0x22, 0xDA, 0xE2, 0x73, 0x55, 0x6D, 0x1D,
  41262. 0xE3, 0x86, 0x62, 0x3A, 0x6C, 0x3F, 0x11, 0x5B,
  41263. 0xBD, 0x11, 0x92, 0x71, 0xD3, 0xFB, 0xA7, 0x96,
  41264. 0xF6, 0x18, 0xB5, 0x39, 0x59, 0xFB, 0x98, 0x01,
  41265. 0x2E, 0x7D, 0x5B, 0x9A, 0xC6, 0x88, 0x94, 0x0B,
  41266. 0x87, 0xE2, 0xC9, 0xC0, 0x65, 0x52, 0x4A, 0x00,
  41267. 0xD3, 0xA4, 0xF4, 0xDB, 0xF5, 0x2F, 0x4B, 0x1A,
  41268. 0x63, 0xEF, 0x5C, 0x46, 0x19, 0x3B, 0xAD, 0xF7,
  41269. 0xAD, 0x7F, 0x98, 0x8D, 0x44, 0x64, 0x34, 0x5B,
  41270. 0x2C, 0x3E, 0x54, 0x96, 0x84, 0xF2, 0xF9, 0x05,
  41271. 0xF6, 0xF8, 0x9D, 0xD6, 0x41, 0x47, 0x3E, 0xC0,
  41272. 0x51, 0x08, 0xA5, 0x2D, 0x8D, 0xBB, 0x91, 0x76,
  41273. 0x8C, 0x54, 0x1D, 0xE5, 0x20, 0xB1, 0x76, 0x66,
  41274. 0x97, 0x0A, 0xAE, 0xB5, 0x06, 0xE7, 0x5D, 0x8E,
  41275. 0xE9, 0xF4, 0xB4, 0x45, 0x5B, 0x71, 0xE0, 0x08,
  41276. 0x8A, 0xB2, 0x56, 0x55, 0x21, 0x3B, 0x75, 0x85,
  41277. 0x9D, 0x25, 0xF5, 0x59, 0xD3, 0xC3, 0x24, 0xD2,
  41278. 0x83, 0xD3, 0x97, 0xAB, 0xE6, 0xF0, 0xAA, 0xA3,
  41279. 0x86, 0x81, 0x57, 0x68, 0xD0, 0x33, 0x57, 0xD7,
  41280. 0x75, 0x96, 0x49, 0x02, 0x41, 0x31, 0x53, 0xE3,
  41281. 0x56, 0x0C, 0xCE, 0xF1, 0xFD, 0x44, 0xB6, 0x5F,
  41282. 0xF1, 0xB2, 0x87, 0xA9, 0x2A, 0x96, 0x93, 0xF0,
  41283. 0x34, 0xB7, 0xEE, 0x66, 0x89, 0x34, 0x70, 0x2D,
  41284. 0x75, 0x01, 0xCA, 0xF6, 0xDA, 0x4E, 0xE9, 0x8A,
  41285. 0xF4, 0xE8, 0xE6, 0x4B, 0x03, 0x40, 0xE0, 0xBB,
  41286. 0x8B, 0xDC, 0x53, 0x3B, 0x0E, 0xFE, 0xE1, 0x91,
  41287. 0x5A, 0x4B, 0x68, 0xB9, 0x3C, 0x5E, 0x95, 0x32,
  41288. 0x1E, 0xED, 0xC2, 0x34, 0xAE, 0xFE, 0x71, 0xAE,
  41289. 0x2E, 0x5D, 0xAC, 0xEC, 0x2F, 0x52, 0xF8, 0x37,
  41290. 0x23, 0xA2, 0x39, 0x2A, 0x7F, 0x8E, 0x13, 0xBC,
  41291. 0x03, 0x01, 0xCD, 0x10, 0x4D, 0x85, 0x2E, 0x62,
  41292. 0xA7, 0xF8, 0x28, 0xAD, 0x32, 0x9B, 0x3D, 0x95,
  41293. 0x96, 0xC5, 0x8E, 0x13, 0xFC, 0xC0, 0xED, 0x96,
  41294. 0xC1, 0xC4, 0x8D, 0x82, 0xA2, 0xC0, 0xF4, 0xD9,
  41295. 0xD2, 0x4D, 0xD8, 0x42, 0x1F, 0xDC, 0xCE, 0xFD,
  41296. 0x49, 0x7A, 0x9B, 0x05, 0xFF, 0xC5, 0x09, 0x04,
  41297. 0x77, 0x04, 0x01, 0x37, 0x3F, 0xEE, 0x7D, 0xC7,
  41298. 0x37, 0x73, 0x41, 0x8A, 0xEB, 0x4A, 0x1F, 0x59,
  41299. 0x9A, 0x4B, 0xB3, 0x8E, 0xDE, 0x8D, 0x10, 0xA3,
  41300. 0xCC, 0x83, 0xA1, 0xC7, 0x2D, 0xE9, 0x21, 0x96,
  41301. 0x9E, 0x3C, 0xE3, 0xE8, 0xEF, 0x2F, 0x7D, 0xA8,
  41302. 0x9D, 0x34, 0x4C, 0x80, 0xD6, 0x1C, 0xF9, 0xC5,
  41303. 0xA4, 0x23, 0xB1, 0xA4, 0xF3, 0x56, 0x7D, 0x96,
  41304. 0xDB, 0x2D, 0xA3, 0xDB, 0x9B, 0x5B, 0x5F, 0xA6,
  41305. 0x81, 0x56, 0xBE, 0x74, 0x52, 0xC8, 0xA0, 0x18,
  41306. 0x1B, 0xB9, 0xF0, 0xDC, 0x75, 0xCD, 0x97, 0x50,
  41307. 0x88, 0x3D, 0x0D, 0xDA, 0xE5, 0x3F, 0xC1, 0x56,
  41308. 0xD6, 0x7A, 0x74, 0x20, 0x08, 0x69, 0x04, 0x6B,
  41309. 0x41, 0xDF, 0x4B, 0xC4, 0x39, 0x69, 0x93, 0xC0,
  41310. 0x8A, 0xA4, 0x89, 0x7A, 0x0B, 0xDD, 0xEF, 0xB5,
  41311. 0x5F, 0x69, 0xCC, 0x1C, 0x4D, 0x7B, 0x5F, 0xB1,
  41312. 0x50, 0x40, 0x84, 0x27, 0xB4, 0x16, 0xF7, 0x31,
  41313. 0x83, 0xF2, 0xB3, 0xCC, 0x16, 0xE3, 0xB7, 0xDA,
  41314. 0x63, 0xCE, 0xE1, 0x14, 0x3A, 0xDA, 0x1A, 0x05,
  41315. 0x66, 0x26, 0xA0, 0x77, 0xB6, 0xD2, 0x1C, 0x3D,
  41316. 0xD9, 0x74, 0xED, 0x90, 0x7C, 0x5A, 0x09, 0x40,
  41317. 0x19, 0x22, 0x57, 0x37, 0xEF, 0xB9, 0x33, 0x19,
  41318. 0xAD, 0x3B, 0x40, 0xA4, 0xF4, 0x34, 0xAE, 0x49,
  41319. 0xD2, 0x83, 0x91, 0xC1, 0x7A, 0x99, 0x9C, 0x74,
  41320. 0x4A, 0x68, 0xC5, 0x5A, 0x91, 0xB8, 0x62, 0x72,
  41321. 0x95, 0x83, 0xD3, 0xDA, 0x46, 0xEE, 0x70, 0xC5,
  41322. 0xCC, 0x46, 0x16, 0x94, 0x16, 0x7D, 0x32, 0xD2,
  41323. 0x1D, 0xE7, 0x53, 0x27, 0x73, 0x2C, 0x63, 0xBB,
  41324. 0xFB, 0xD7, 0xB3, 0x0D, 0xBF, 0x20, 0x57, 0xA0,
  41325. 0xD6, 0x81, 0x51, 0x9F, 0x6E, 0x4A, 0xF6, 0x08,
  41326. 0xD4, 0xBC, 0xD0, 0xB4, 0x75, 0x07, 0x26, 0x77,
  41327. 0x0E, 0x15, 0x6A, 0xED, 0xE8, 0x54, 0x17, 0xBD,
  41328. 0x75, 0x9D, 0x5F, 0xFE, 0x40, 0x1C, 0xB2, 0x99,
  41329. 0x6F, 0x34, 0x43, 0x4D, 0xB4, 0x28, 0xD9, 0xA4,
  41330. 0x17, 0x03, 0x72, 0x01, 0xFC, 0xD2, 0x60, 0xFA,
  41331. 0xA9, 0x80, 0x84, 0x50, 0x2E, 0xED, 0x5C, 0x27,
  41332. 0xA8, 0x91, 0x6E, 0x44, 0xF5, 0x92, 0x98, 0x19,
  41333. 0xD2, 0x1A, 0x69, 0xCE, 0x16, 0xBC, 0xDC, 0x3C,
  41334. 0xC8, 0x14, 0x1E, 0x28, 0x5E, 0xF8, 0x97, 0xB1,
  41335. 0x40, 0x2C, 0x15, 0xC9, 0x52, 0x59, 0x01, 0x19,
  41336. 0x05, 0x1E, 0x36, 0x9A, 0x1B, 0x7B, 0xE4, 0x43,
  41337. 0xFE, 0xAE, 0x6E, 0x32, 0xBC, 0x8F, 0x3D, 0x64,
  41338. 0x7F, 0xC5, 0x31, 0x5A, 0x52, 0x00, 0xCD, 0x52,
  41339. 0x38, 0xDC, 0x66, 0x77, 0x46, 0x6E, 0xA8, 0x6E,
  41340. 0xF8, 0xD1, 0x8E, 0x5A, 0x79, 0xF2, 0x62, 0x48,
  41341. 0x3E, 0x89, 0x6B, 0x82, 0x77, 0xC7, 0x41, 0xF5,
  41342. 0x16, 0xFC, 0x04, 0x0C, 0x10, 0x90, 0xF2, 0x49,
  41343. 0x5B, 0xF1, 0x65, 0x0B, 0x02, 0xAF, 0x30, 0x45,
  41344. 0x67, 0x33, 0xA0, 0x71, 0xAF, 0x47, 0xD7, 0xA1,
  41345. 0x5B, 0xD8, 0xE3, 0x2A, 0x49, 0x80, 0x64, 0x55,
  41346. 0xD3, 0xBE, 0xA7, 0x4A, 0xEF, 0x5D, 0x00, 0x90,
  41347. 0x6A, 0xD2, 0xF0, 0xC0, 0x45, 0x35, 0x4E, 0xFD,
  41348. 0xE7, 0xC9, 0xA2, 0x76, 0xE7, 0x3D, 0x9E, 0xDD,
  41349. 0x11, 0xD1, 0xCA, 0x5C, 0x29, 0x7B, 0x9A, 0x68,
  41350. 0x51, 0xE7, 0xF6, 0x7E, 0x21, 0xEB, 0x06, 0x1B,
  41351. 0xB5, 0x5D, 0x9E, 0x67, 0x3C, 0x4A, 0x75, 0xFE,
  41352. 0xB8, 0x4D, 0x52, 0x62, 0x9E, 0xEC, 0xC5, 0x3C,
  41353. 0x24, 0xBE, 0xA9, 0x51, 0x53, 0x05, 0x1A, 0xC2,
  41354. 0x06, 0xC8, 0x7D, 0xF5, 0x54, 0x10, 0xCA, 0x1F,
  41355. 0xE6, 0xCF, 0xC3, 0xF4, 0x03, 0xA6, 0xD9, 0xD4,
  41356. 0x3E, 0xA8, 0x4C, 0x60, 0xC9, 0x45, 0xE6, 0x42,
  41357. 0xB2, 0x83, 0x63, 0x38, 0xB5, 0xAF, 0x9F, 0x69,
  41358. 0xE5, 0x27, 0x08, 0xB2, 0xE2, 0x25, 0x93, 0x3D,
  41359. 0xB3, 0x20, 0xBB, 0x3F, 0x79, 0x0D, 0x39, 0x7F,
  41360. 0x22, 0xD7, 0xB6, 0xF8, 0xA4, 0x33, 0xCD, 0xAC,
  41361. 0xE9, 0x81, 0x0A, 0xA0, 0xE2, 0x7C, 0x69, 0x95,
  41362. 0x55, 0x53, 0x0C, 0x56, 0x2D, 0xBF, 0x75, 0x17,
  41363. 0xA4, 0x16, 0x26, 0x28, 0xBF, 0x10, 0xD1, 0xB6,
  41364. 0xDB, 0xAC, 0xEF, 0x5C, 0x9E, 0xD5, 0x1E, 0x55,
  41365. 0xD9, 0xA8, 0x9D, 0x60, 0xE0, 0xFC, 0x37, 0x8C,
  41366. 0x47, 0xA2, 0x1D, 0x5E, 0x0F, 0x2D, 0xC3, 0xBC,
  41367. 0xEF, 0x5E, 0x05, 0xC6, 0xE0, 0x26, 0x15, 0x30,
  41368. 0xFB, 0x02, 0x7E, 0x50, 0x32, 0x55, 0x8C, 0xA2,
  41369. 0xB4, 0x70, 0x05, 0xBD, 0xDE, 0x99, 0x90, 0x99,
  41370. 0x30, 0x39, 0x1E, 0xAD, 0x7F, 0x3F, 0x0A, 0x96,
  41371. 0xB3, 0xDE, 0xDA, 0x54, 0xA1, 0x11, 0x45, 0xF5,
  41372. 0x30, 0xE5, 0x1D, 0xEF, 0x89, 0x2E, 0x5A, 0xB0,
  41373. 0x20, 0x4D, 0x61, 0x4E, 0x6E, 0x38, 0xAF, 0xE7,
  41374. 0x9C, 0xA9, 0x2C, 0x28, 0x15, 0x8D, 0x57, 0x01,
  41375. 0x20, 0x35, 0x3B, 0x7A, 0x4D, 0xE0, 0x88, 0x98,
  41376. 0x46, 0xD8, 0x35, 0x29, 0x49, 0x39, 0x55, 0x7E,
  41377. 0xD0, 0xAE, 0xDA, 0x27, 0x0D, 0x4D, 0x73, 0xED,
  41378. 0x84, 0xD3, 0xD4, 0x9F, 0x9F, 0x03, 0x2D, 0x43,
  41379. 0x45, 0x7B, 0xF5, 0x9B, 0xB7, 0xD6, 0x63, 0x59,
  41380. 0xDC, 0x53, 0xF9, 0xB4, 0x69, 0x63, 0xB2, 0x17,
  41381. 0x84, 0xB0, 0x6C, 0xBC, 0xF0, 0x4B, 0xEC, 0x1E,
  41382. 0x33, 0xA3, 0x33, 0x71, 0x53, 0x27, 0x16, 0xC9,
  41383. 0xED, 0xB3, 0xFB, 0xED, 0xB8, 0x19, 0x99, 0xB4,
  41384. 0x37, 0x2D, 0x09, 0x45, 0xC1, 0x0A, 0xE8, 0x26,
  41385. 0xC6, 0x0F, 0xFE, 0x93, 0x17, 0x0B, 0x6D, 0x29,
  41386. 0x4B, 0x38, 0x91, 0xB0, 0xD2, 0xA7, 0xB3, 0x5B,
  41387. 0x28, 0xA8, 0x97, 0x18, 0x45, 0xDC, 0x2F, 0xEC,
  41388. 0xE2, 0x37, 0xB8, 0x0F, 0x20, 0xB3, 0x79, 0xCC,
  41389. 0x4D, 0x13, 0x6D, 0xAB, 0x3F, 0xBB, 0x37, 0x92,
  41390. 0xC6, 0x3E, 0xC6, 0x1F, 0x5C, 0x75, 0x5B, 0xC9,
  41391. 0xDB, 0x35, 0x08, 0x6F, 0xBF, 0x46, 0xD2, 0xB7,
  41392. 0x97, 0x0D, 0xCA, 0x2A, 0x85, 0x23, 0xFD, 0xB4,
  41393. 0xC7, 0xA0, 0xB8, 0xE4, 0x2F, 0x8A, 0xF9, 0xAC,
  41394. 0xAD, 0x2A, 0x0E, 0xFC, 0x11, 0x36, 0x02, 0xA4,
  41395. 0xEA, 0x62, 0xE4, 0xEB, 0xB7, 0xD2, 0x69, 0xC3,
  41396. 0xA4, 0x0B, 0xA2, 0xC4, 0x4E, 0xDD, 0x29, 0x56
  41397. };
  41398. static const byte msg_65[] = {
  41399. 0xC4, 0xF5, 0x9F, 0xA2, 0xDE, 0x30, 0xC8, 0x42,
  41400. 0x0A, 0x7E, 0x7F, 0x09, 0x6B, 0xAF, 0x6A, 0xD6,
  41401. 0x9B, 0x1C, 0x15, 0xA5, 0xC6, 0xE6, 0x1C, 0x9D,
  41402. 0x82, 0xAF, 0xCF, 0xDB, 0x6E, 0xB8, 0xF2, 0x75,
  41403. 0xBF, 0x57, 0x87, 0x18, 0x6A, 0xAE, 0x78, 0x1F,
  41404. 0x48, 0x7F, 0x9F, 0x88, 0x75, 0x8C, 0x9C, 0x61,
  41405. 0xF3, 0x5D, 0x50, 0x83, 0xEE, 0x70, 0x42, 0x4B,
  41406. 0x0D, 0x0A, 0x51, 0x57, 0x50, 0x10, 0xC2, 0xA9,
  41407. 0x07, 0xF4, 0x96, 0x08, 0x11, 0x5D, 0x33, 0xEB,
  41408. 0xA0, 0x03, 0x15, 0x09, 0x32, 0x2A, 0xA7, 0xD3,
  41409. 0x06, 0x1F, 0xEC, 0x31, 0x62, 0xF9, 0x6A, 0x56,
  41410. 0x5F, 0x98, 0x76, 0x9E, 0x9A, 0x19, 0x23, 0x5D,
  41411. 0x89, 0xD1, 0xB2, 0x1D, 0x60, 0xA3, 0x81, 0xDF,
  41412. 0x8E, 0xB3, 0x7D, 0x58, 0xC6, 0xA2, 0xE4, 0x83,
  41413. 0xA8, 0xEB, 0x70, 0x73, 0x6E, 0x4B, 0x7B, 0xB9,
  41414. 0x11, 0xF7, 0xAB, 0x92, 0x3D, 0xC2, 0x9F, 0x1E
  41415. };
  41416. static const byte sig_65[] = {
  41417. 0xE8, 0x95, 0xDB, 0x64, 0xC5, 0x7B, 0xC3, 0xC2,
  41418. 0xA9, 0x7F, 0x0E, 0xC9, 0x33, 0x41, 0x0E, 0x98,
  41419. 0xF6, 0x21, 0x61, 0x03, 0xE3, 0x42, 0x3C, 0xAF,
  41420. 0x06, 0xA6, 0x71, 0x96, 0x4C, 0x51, 0x4A, 0x69,
  41421. 0x4E, 0xB6, 0xF6, 0x5C, 0xBD, 0x11, 0x37, 0xCC,
  41422. 0xCF, 0x88, 0x81, 0xFA, 0x40, 0x3C, 0x5F, 0xA0,
  41423. 0xE0, 0xB2, 0xF3, 0x6B, 0x9F, 0x40, 0x09, 0xC3,
  41424. 0x78, 0x21, 0x0D, 0x29, 0xE5, 0x4A, 0x7A, 0x5A,
  41425. 0x9B, 0x79, 0x31, 0x97, 0xCD, 0x6D, 0x2F, 0x38,
  41426. 0xD7, 0xE1, 0xF3, 0xAC, 0xA6, 0x9D, 0x48, 0x88,
  41427. 0x13, 0x89, 0x38, 0x1C, 0x89, 0xFA, 0x67, 0x6D,
  41428. 0xE4, 0x26, 0xD6, 0x34, 0xF9, 0xA1, 0x57, 0x05,
  41429. 0x5F, 0x17, 0x28, 0x3E, 0xCE, 0x82, 0x48, 0xCA,
  41430. 0xF1, 0x4D, 0xCF, 0x11, 0xE2, 0xD5, 0x63, 0x55,
  41431. 0xB0, 0x47, 0xDF, 0x63, 0x2A, 0x18, 0x48, 0x2E,
  41432. 0x79, 0xCB, 0x2D, 0x5A, 0x74, 0x39, 0x66, 0xBA,
  41433. 0xA8, 0xA7, 0x61, 0x21, 0xBB, 0x69, 0xC2, 0xE6,
  41434. 0x81, 0x55, 0xAC, 0xCB, 0x0A, 0x31, 0xDA, 0x6E,
  41435. 0xDC, 0x73, 0xCB, 0x09, 0xA9, 0xE6, 0x60, 0xFE,
  41436. 0xB2, 0x0F, 0x66, 0xC7, 0xBD, 0x96, 0x7A, 0xDE,
  41437. 0x32, 0x14, 0x9C, 0x55, 0x52, 0xEA, 0xEB, 0x2E,
  41438. 0xA1, 0x75, 0xB5, 0x62, 0x33, 0xF3, 0xB3, 0x70,
  41439. 0xED, 0xD8, 0x67, 0x92, 0x69, 0xCE, 0x0D, 0x2B,
  41440. 0x43, 0xF6, 0xB2, 0xF6, 0x5F, 0xE9, 0x57, 0xE7,
  41441. 0xAB, 0x37, 0xB9, 0x82, 0x04, 0x37, 0x54, 0xEA,
  41442. 0xC8, 0xA3, 0x0B, 0x36, 0xC1, 0x00, 0x04, 0xEF,
  41443. 0x13, 0xC6, 0x92, 0xE2, 0x19, 0xAA, 0x7A, 0xF0,
  41444. 0xA4, 0xC5, 0x28, 0x69, 0x10, 0xC7, 0x10, 0x0D,
  41445. 0xA4, 0x1E, 0x17, 0xBB, 0xEF, 0x2D, 0xA2, 0xAB,
  41446. 0x03, 0xAD, 0xF3, 0x07, 0x4B, 0xA1, 0xDA, 0x15,
  41447. 0xBC, 0xC8, 0x48, 0x05, 0xB8, 0x9B, 0x9D, 0xA8,
  41448. 0x8E, 0x9B, 0x40, 0x0A, 0xFB, 0x7E, 0x3B, 0xC8,
  41449. 0x33, 0x8D, 0x35, 0x4D, 0xA9, 0x53, 0xAC, 0x0B,
  41450. 0xAD, 0x82, 0x27, 0x56, 0xCA, 0x92, 0xE5, 0xDD,
  41451. 0x95, 0x07, 0xF4, 0x2B, 0xFE, 0xFC, 0xCB, 0x32,
  41452. 0xB4, 0xB9, 0x1A, 0x2B, 0xE5, 0xEF, 0x34, 0xC2,
  41453. 0xCF, 0x11, 0x77, 0xEA, 0xAF, 0xB2, 0x50, 0xAC,
  41454. 0x9A, 0xDE, 0xC4, 0xBE, 0x71, 0x80, 0x75, 0x89,
  41455. 0xF1, 0x00, 0x32, 0x27, 0xF9, 0xB7, 0x6B, 0x74,
  41456. 0xE0, 0x7B, 0xA6, 0x7A, 0xC6, 0x08, 0x19, 0xB2,
  41457. 0xAF, 0x76, 0x6A, 0x47, 0xFF, 0xFC, 0x7B, 0x76,
  41458. 0xD3, 0xA7, 0xC0, 0x77, 0xF5, 0xEC, 0x69, 0xAE,
  41459. 0xEA, 0x3E, 0x96, 0x38, 0x59, 0xB8, 0x2C, 0x2A,
  41460. 0xDE, 0x58, 0xBE, 0xC2, 0x15, 0x2E, 0xC8, 0x20,
  41461. 0x51, 0x10, 0x97, 0x5D, 0x37, 0xC6, 0x50, 0x5E,
  41462. 0x0D, 0xC7, 0x76, 0xFD, 0xE0, 0x71, 0x09, 0x7E,
  41463. 0x93, 0x01, 0x3D, 0x10, 0x04, 0xF4, 0xE1, 0xA2,
  41464. 0xFD, 0x79, 0xB8, 0x77, 0xED, 0x50, 0x25, 0xF5,
  41465. 0x27, 0xF3, 0xBF, 0xF1, 0x37, 0xF0, 0x41, 0xBB,
  41466. 0x9B, 0xD0, 0x01, 0xE9, 0x49, 0xF0, 0x8B, 0x4C,
  41467. 0xF8, 0x8D, 0xFD, 0x32, 0xFC, 0x7C, 0xDB, 0xCE,
  41468. 0xCC, 0xFD, 0xB0, 0xFA, 0x2D, 0xE7, 0x82, 0x3E,
  41469. 0x11, 0x0B, 0xCF, 0xF5, 0x8A, 0x41, 0x2C, 0xEA,
  41470. 0x27, 0x95, 0x75, 0x3E, 0x9C, 0x89, 0x67, 0x8C,
  41471. 0x3A, 0xE2, 0x42, 0x68, 0xF7, 0x48, 0x9F, 0x72,
  41472. 0x97, 0x4B, 0x69, 0x55, 0xED, 0xD0, 0x4E, 0x19,
  41473. 0x0D, 0x99, 0xBB, 0x0D, 0x7A, 0x25, 0x2F, 0xAD,
  41474. 0x5B, 0xBA, 0x60, 0x6C, 0x1A, 0x1F, 0x3A, 0xCA,
  41475. 0x73, 0x3B, 0xFA, 0xE3, 0x30, 0x9E, 0xA0, 0xA6,
  41476. 0xEB, 0x7D, 0x07, 0xE3, 0x6D, 0x8C, 0xA3, 0x36,
  41477. 0xD2, 0x64, 0x4F, 0xCE, 0x1A, 0x41, 0x89, 0x5D,
  41478. 0x01, 0x4D, 0x1A, 0x60, 0xCB, 0x10, 0x6F, 0x3F,
  41479. 0x80, 0x75, 0xF9, 0x37, 0x84, 0x61, 0x73, 0x8D,
  41480. 0x63, 0xD1, 0x15, 0xD0, 0x0B, 0x02, 0x4C, 0x67,
  41481. 0x78, 0x01, 0x05, 0x0A, 0x1B, 0x0B, 0x50, 0xDE,
  41482. 0x05, 0x7F, 0x85, 0xDB, 0x6A, 0xEB, 0x2C, 0x9D,
  41483. 0x6B, 0xB7, 0x40, 0x2A, 0x66, 0xE3, 0xAB, 0x4D,
  41484. 0xB0, 0x5C, 0x58, 0xBB, 0xDA, 0x12, 0xF6, 0x95,
  41485. 0x95, 0x8B, 0x8A, 0xC7, 0xB4, 0xE4, 0x5E, 0xC6,
  41486. 0xC9, 0x52, 0xF6, 0x79, 0xC1, 0xEE, 0xBD, 0xF8,
  41487. 0x60, 0xE3, 0x48, 0x98, 0x27, 0x79, 0xAA, 0x69,
  41488. 0x88, 0xEF, 0xC2, 0xAD, 0x1D, 0xC1, 0xEA, 0xE2,
  41489. 0x2A, 0x27, 0xA5, 0xB2, 0xC6, 0x1C, 0x97, 0xB3,
  41490. 0xB2, 0x49, 0x3C, 0xB6, 0xC1, 0x3C, 0x5F, 0x6E,
  41491. 0x20, 0xA6, 0x7B, 0x88, 0xD3, 0xC3, 0xAC, 0xCF,
  41492. 0xAF, 0x0A, 0x42, 0x57, 0x42, 0xDF, 0x24, 0x06,
  41493. 0x34, 0xD1, 0xEE, 0x59, 0x38, 0x28, 0xFE, 0x62,
  41494. 0x97, 0x44, 0x6C, 0x07, 0x6F, 0x97, 0x90, 0x55,
  41495. 0x98, 0x8A, 0xB8, 0x34, 0xB2, 0xBD, 0x82, 0xE1,
  41496. 0x4D, 0xC0, 0x86, 0x40, 0x0E, 0x1C, 0x95, 0x6C,
  41497. 0xC0, 0xC3, 0x0C, 0xE7, 0xBF, 0xD9, 0x62, 0x22,
  41498. 0x3D, 0x23, 0xFE, 0x94, 0x94, 0x96, 0x4A, 0x81,
  41499. 0x1B, 0x93, 0xE8, 0xD7, 0xB8, 0xF3, 0x4C, 0x89,
  41500. 0xAA, 0xD4, 0x5D, 0xD4, 0x11, 0x3F, 0x2A, 0xE7,
  41501. 0xBD, 0x94, 0xB5, 0x3F, 0xC8, 0x6E, 0x8B, 0x2A,
  41502. 0xE8, 0x2E, 0x51, 0xEC, 0x6F, 0x3E, 0xA4, 0xC3,
  41503. 0x0D, 0x60, 0xB8, 0x60, 0x72, 0x74, 0x86, 0x12,
  41504. 0xD1, 0x60, 0x70, 0x56, 0xB5, 0xFF, 0x6A, 0x45,
  41505. 0x00, 0xEE, 0xE7, 0x8A, 0x5A, 0x63, 0x9C, 0x7B,
  41506. 0x74, 0x16, 0x97, 0x77, 0x62, 0x68, 0x64, 0xDD,
  41507. 0x9E, 0xAE, 0xF0, 0xE3, 0xAD, 0x84, 0x93, 0xD8,
  41508. 0x31, 0xF7, 0x1D, 0xEA, 0x95, 0xBB, 0xFC, 0xF8,
  41509. 0x14, 0x23, 0xA2, 0x66, 0xDE, 0x56, 0xF3, 0xA8,
  41510. 0xFE, 0x8E, 0x6C, 0x3C, 0x0D, 0x61, 0x2F, 0xB6,
  41511. 0x2B, 0xD6, 0x42, 0x18, 0x8C, 0xA7, 0x1C, 0xB8,
  41512. 0x98, 0x34, 0xF3, 0x0B, 0xCC, 0x28, 0xBD, 0x17,
  41513. 0x88, 0x45, 0xF1, 0xF6, 0xF4, 0x6C, 0x03, 0xD3,
  41514. 0x06, 0xF7, 0xED, 0x4E, 0x68, 0x75, 0x94, 0x27,
  41515. 0xAE, 0xC2, 0x70, 0x11, 0x98, 0xC3, 0xC0, 0x5D,
  41516. 0x38, 0x5D, 0xFA, 0xFD, 0x52, 0x8C, 0xCE, 0x84,
  41517. 0x25, 0xBC, 0x55, 0x14, 0x69, 0xA0, 0xED, 0x68,
  41518. 0x1B, 0xEE, 0x4D, 0x12, 0xA8, 0x43, 0xE3, 0x33,
  41519. 0xB5, 0xA8, 0xE0, 0x51, 0x7F, 0xC6, 0x19, 0x06,
  41520. 0xF9, 0xC4, 0xE7, 0x80, 0x9B, 0xAE, 0xD4, 0xD3,
  41521. 0xD1, 0x6E, 0xB2, 0x2F, 0x1F, 0xA9, 0xAB, 0x40,
  41522. 0x2D, 0x98, 0x8E, 0xD5, 0x9F, 0x9F, 0xED, 0x04,
  41523. 0x55, 0xE9, 0x26, 0x0F, 0xD6, 0x27, 0xA2, 0x4A,
  41524. 0x17, 0xFE, 0x7C, 0xB6, 0x3E, 0x53, 0x0B, 0x48,
  41525. 0xF5, 0xFB, 0x66, 0x87, 0xA2, 0xE8, 0xC4, 0x9D,
  41526. 0xA7, 0x9F, 0xBD, 0x69, 0xA3, 0x40, 0x00, 0x56,
  41527. 0x66, 0x5D, 0xD1, 0x1D, 0x19, 0xA2, 0xBC, 0x4D,
  41528. 0xB1, 0xD3, 0x74, 0xAB, 0x6A, 0x6E, 0x42, 0x47,
  41529. 0x2A, 0x27, 0xAC, 0x6B, 0x98, 0xF6, 0x76, 0xE8,
  41530. 0xED, 0xAA, 0xDD, 0x51, 0x4F, 0x6D, 0x44, 0xDE,
  41531. 0xEC, 0xDA, 0xB5, 0xA6, 0xDF, 0xA0, 0xF8, 0x4F,
  41532. 0x13, 0x9A, 0x80, 0x3A, 0x25, 0x24, 0xBF, 0x33,
  41533. 0x5D, 0xC5, 0x2E, 0xA5, 0x8F, 0xA5, 0x0D, 0x98,
  41534. 0xFB, 0x5C, 0xD5, 0x5D, 0x5D, 0x50, 0xA6, 0x63,
  41535. 0xCF, 0x64, 0x7E, 0xEE, 0x56, 0xFE, 0x8E, 0x66,
  41536. 0x4B, 0x3B, 0xCA, 0xF9, 0xE3, 0x33, 0x97, 0x8A,
  41537. 0x79, 0x46, 0x97, 0x3F, 0xD1, 0x13, 0xE4, 0xFD,
  41538. 0x39, 0x24, 0xE6, 0xC0, 0x9E, 0x60, 0x38, 0x64,
  41539. 0x44, 0x21, 0x4D, 0xFA, 0x7A, 0x4D, 0x67, 0x1F,
  41540. 0xC2, 0x38, 0x90, 0x63, 0x7E, 0xB8, 0x59, 0x13,
  41541. 0x4D, 0x79, 0xE2, 0x65, 0xC5, 0x9C, 0xA3, 0xEC,
  41542. 0xCD, 0xDF, 0xA0, 0x18, 0x22, 0x3C, 0x9B, 0xAE,
  41543. 0x1C, 0xCA, 0x10, 0x39, 0x62, 0x07, 0x8B, 0xC5,
  41544. 0xF0, 0xDD, 0x02, 0x24, 0x6F, 0xA2, 0x83, 0x24,
  41545. 0xF7, 0xCB, 0x2F, 0xCF, 0xAD, 0x07, 0xC2, 0x5B,
  41546. 0x4B, 0xC2, 0xD8, 0x88, 0x06, 0x9B, 0x0C, 0xF5,
  41547. 0xF2, 0x3C, 0x76, 0x1C, 0x0E, 0x47, 0x10, 0x98,
  41548. 0x81, 0xCD, 0x31, 0x45, 0x6A, 0x64, 0xB9, 0x40,
  41549. 0xB4, 0xBB, 0x9B, 0x4C, 0x2C, 0x3B, 0x8E, 0x6B,
  41550. 0xA8, 0x34, 0xAA, 0xAE, 0x69, 0xFD, 0xFC, 0x47,
  41551. 0xD4, 0x4B, 0x3C, 0x96, 0x88, 0x7A, 0xBE, 0xD3,
  41552. 0x60, 0x15, 0xE7, 0xB6, 0x4E, 0x85, 0x42, 0x92,
  41553. 0x8F, 0x27, 0x7C, 0xBD, 0x2D, 0x3C, 0x51, 0x2C,
  41554. 0x24, 0xDE, 0xEF, 0xE5, 0x90, 0xE8, 0x1C, 0x68,
  41555. 0x4E, 0x06, 0x3E, 0x7A, 0xAD, 0xCF, 0x11, 0x7B,
  41556. 0x48, 0x94, 0x3D, 0xB7, 0x71, 0xFC, 0x22, 0x07,
  41557. 0xF5, 0x7A, 0x74, 0x53, 0x57, 0x55, 0x5D, 0x41,
  41558. 0x9C, 0x9C, 0xDC, 0xA3, 0x5C, 0xC1, 0xA7, 0x10,
  41559. 0x0A, 0x69, 0x13, 0xA3, 0xB6, 0xAA, 0xCF, 0x79,
  41560. 0x6F, 0xE3, 0xF9, 0x4D, 0xD2, 0xF8, 0x18, 0x98,
  41561. 0x27, 0x16, 0xCE, 0x03, 0x16, 0x54, 0x2A, 0x1B,
  41562. 0x95, 0x7E, 0x12, 0xDA, 0x43, 0xE2, 0x31, 0x54,
  41563. 0x2C, 0xC1, 0x4F, 0xCC, 0x66, 0xD7, 0x28, 0xA6,
  41564. 0x83, 0x26, 0xB2, 0xBC, 0x31, 0x12, 0x48, 0x33,
  41565. 0x0F, 0x3E, 0x98, 0xF8, 0x1E, 0xA3, 0x8C, 0xA9,
  41566. 0x24, 0xA8, 0xE4, 0xDA, 0x97, 0xCF, 0x67, 0x38,
  41567. 0x42, 0xC7, 0x59, 0xF9, 0x35, 0xBE, 0x88, 0x16,
  41568. 0x3C, 0xE9, 0x7F, 0xE4, 0xD9, 0x45, 0x71, 0x76,
  41569. 0xF5, 0xB8, 0x90, 0x8A, 0xF9, 0x48, 0xF7, 0x4D,
  41570. 0x5D, 0x1D, 0xDB, 0xC5, 0x21, 0x82, 0x5D, 0x93,
  41571. 0x1C, 0x63, 0xCA, 0x8A, 0x8E, 0x12, 0x24, 0x26,
  41572. 0x26, 0x30, 0x5A, 0xB6, 0xA2, 0xE0, 0x62, 0x45,
  41573. 0x64, 0xEE, 0x04, 0x19, 0x83, 0xC1, 0x8C, 0x29,
  41574. 0x52, 0xEC, 0x3D, 0x9D, 0x15, 0x9B, 0xDE, 0x39,
  41575. 0x85, 0xCF, 0x77, 0x89, 0x7E, 0xE2, 0xDC, 0x88,
  41576. 0x81, 0x12, 0x72, 0x1D, 0x48, 0x54, 0xE9, 0x14,
  41577. 0xA5, 0x39, 0x7E, 0x08, 0xB5, 0x4F, 0x4A, 0x54,
  41578. 0x32, 0x3F, 0xF8, 0x20, 0x82, 0x1B, 0xE0, 0x26,
  41579. 0xEA, 0x09, 0x1E, 0xCA, 0x6B, 0x7D, 0x80, 0xD9,
  41580. 0x1E, 0x3D, 0xCA, 0x2E, 0xF7, 0x84, 0x8B, 0x86,
  41581. 0xFC, 0xA6, 0xBB, 0x40, 0xCE, 0x48, 0x27, 0x1E,
  41582. 0x10, 0x08, 0x36, 0x8E, 0x3E, 0xBB, 0x5E, 0x39,
  41583. 0x5E, 0x1C, 0xCD, 0x0D, 0x17, 0x8F, 0x1A, 0x62,
  41584. 0x57, 0xD2, 0x6B, 0x6B, 0xA4, 0xB7, 0xCE, 0x53,
  41585. 0x2C, 0xAA, 0x1E, 0x76, 0xCE, 0x28, 0xFA, 0x4C,
  41586. 0xF9, 0xE0, 0x29, 0xE2, 0x48, 0x2B, 0x94, 0xD3,
  41587. 0xAC, 0xF9, 0x7A, 0x32, 0x6D, 0x23, 0x5D, 0x1B,
  41588. 0xDC, 0x89, 0xF7, 0x00, 0x02, 0x19, 0x84, 0x51,
  41589. 0xD9, 0xF1, 0xF1, 0x2C, 0xCD, 0x5B, 0xCA, 0xEC,
  41590. 0xDD, 0xE9, 0xE1, 0x4A, 0xC8, 0x07, 0x42, 0xEB,
  41591. 0x31, 0xE6, 0x46, 0x4C, 0x83, 0x21, 0x0A, 0x39,
  41592. 0xF3, 0x50, 0x98, 0xBE, 0x03, 0x78, 0xD0, 0x74,
  41593. 0xCE, 0x1C, 0xCD, 0x1E, 0xBC, 0x1C, 0x77, 0x70,
  41594. 0xF7, 0x78, 0xD6, 0x05, 0xF2, 0xBE, 0x59, 0xDB,
  41595. 0x7E, 0xA0, 0x7D, 0x80, 0xCC, 0xDF, 0x55, 0xF1,
  41596. 0x6E, 0x98, 0x5B, 0x14, 0x2F, 0xB7, 0xBD, 0xA0,
  41597. 0x7A, 0xA7, 0xDC, 0xA5, 0xB2, 0x01, 0xE1, 0x95,
  41598. 0x0C, 0xF9, 0xA7, 0x28, 0xF2, 0x1E, 0x9A, 0x9D,
  41599. 0x8A, 0xC4, 0xD1, 0x32, 0x7E, 0x3B, 0xC0, 0xFF,
  41600. 0x33, 0x9A, 0x25, 0x05, 0x22, 0xF6, 0x31, 0xDF,
  41601. 0x2E, 0x75, 0x95, 0x51, 0x54, 0x89, 0x3E, 0x4A,
  41602. 0x1A, 0xAF, 0x98, 0x66, 0xFE, 0xE1, 0x63, 0x7E,
  41603. 0xE1, 0xAA, 0x51, 0x06, 0xD2, 0x44, 0xE9, 0x9E,
  41604. 0x6F, 0x31, 0xFC, 0x56, 0x01, 0xBB, 0x7B, 0x79,
  41605. 0xBA, 0xD8, 0x28, 0x60, 0xB1, 0xD6, 0x05, 0x9D,
  41606. 0x9B, 0x13, 0x2E, 0x02, 0x64, 0x18, 0x02, 0x0D,
  41607. 0xB0, 0x6E, 0xB8, 0x39, 0x1F, 0xA1, 0x5B, 0x7A,
  41608. 0x0F, 0x29, 0xE3, 0x6D, 0x96, 0x6A, 0xBD, 0x3D,
  41609. 0x2A, 0x2F, 0xF3, 0xF2, 0xAA, 0xC3, 0x4C, 0x8B,
  41610. 0x45, 0xC7, 0xD2, 0x35, 0x5E, 0xDB, 0xB8, 0x0B,
  41611. 0x22, 0x4B, 0xC1, 0x06, 0xEB, 0xC6, 0x75, 0x0E,
  41612. 0x55, 0x07, 0x0F, 0x85, 0xA7, 0xCB, 0x60, 0x03,
  41613. 0x39, 0x4E, 0x51, 0x61, 0xAE, 0x26, 0xF5, 0xAB,
  41614. 0xF8, 0x3F, 0x0D, 0xCC, 0xCF, 0x69, 0xB8, 0x61,
  41615. 0x39, 0xAF, 0x86, 0x94, 0xFE, 0x1D, 0xC0, 0x07,
  41616. 0x81, 0xEA, 0xE0, 0x9C, 0xDB, 0x42, 0x18, 0x14,
  41617. 0x87, 0x80, 0x43, 0xDC, 0x9B, 0x05, 0x30, 0xE5,
  41618. 0x54, 0x5A, 0x16, 0x5E, 0x39, 0xA9, 0xB7, 0xDE,
  41619. 0x88, 0xB4, 0xAD, 0x2A, 0xEB, 0x90, 0xD3, 0xC3,
  41620. 0x29, 0x41, 0x2E, 0xD2, 0xFE, 0x1D, 0x97, 0xB7,
  41621. 0x32, 0xC8, 0x43, 0x9D, 0xF4, 0xF8, 0x3D, 0x22,
  41622. 0x88, 0x35, 0xB5, 0x38, 0xDC, 0x27, 0x8F, 0xF0,
  41623. 0xA2, 0xDC, 0x42, 0xF4, 0x1B, 0x00, 0xCE, 0x3A,
  41624. 0xCA, 0x06, 0xB0, 0x5C, 0x48, 0x39, 0xB8, 0x96,
  41625. 0x93, 0x15, 0x15, 0xD7, 0x8E, 0xA3, 0x67, 0x3A,
  41626. 0x37, 0x82, 0x79, 0xF4, 0xE8, 0x9C, 0xE0, 0x8E,
  41627. 0x34, 0x53, 0xFF, 0x2F, 0xB4, 0x53, 0xBE, 0x03,
  41628. 0x1C, 0x63, 0x18, 0x62, 0x8A, 0x73, 0x1D, 0x02,
  41629. 0x9F, 0xC7, 0xBE, 0xA2, 0xBA, 0x5E, 0xAC, 0x49,
  41630. 0x16, 0x27, 0x8B, 0x93, 0x8A, 0x6A, 0x6A, 0xCE,
  41631. 0xF5, 0xBF, 0xE2, 0x15, 0x8F, 0x2A, 0xF4, 0x3D,
  41632. 0x8E, 0x56, 0xA0, 0x64, 0x9D, 0xF2, 0x8A, 0x25,
  41633. 0x0D, 0x2F, 0x25, 0x36, 0xAB, 0xDE, 0x1E, 0x00,
  41634. 0x8E, 0xB6, 0x31, 0xF4, 0xBD, 0x0E, 0xB5, 0x55,
  41635. 0x73, 0xA4, 0x05, 0x39, 0xA6, 0x00, 0x41, 0x81,
  41636. 0xA9, 0xD2, 0xBF, 0x7A, 0x1E, 0x53, 0x50, 0x4F,
  41637. 0x11, 0xE0, 0x14, 0x84, 0x07, 0x33, 0x84, 0x41,
  41638. 0x31, 0xAC, 0x66, 0x89, 0x46, 0xE5, 0xB8, 0x27,
  41639. 0x28, 0x9A, 0xB6, 0xB2, 0x13, 0x66, 0xC5, 0xD0,
  41640. 0xE2, 0x64, 0x92, 0x19, 0xB9, 0x2C, 0x47, 0x60,
  41641. 0xDF, 0xB7, 0x05, 0xF7, 0xF6, 0x1A, 0x96, 0x56,
  41642. 0x4C, 0x9E, 0x84, 0x0D, 0x14, 0xB0, 0xBB, 0x0D,
  41643. 0xA8, 0x2D, 0xA5, 0x0F, 0x8B, 0x8E, 0x75, 0x2B,
  41644. 0xBF, 0xEA, 0x3B, 0x0A, 0x33, 0x7B, 0xE1, 0x24,
  41645. 0xF7, 0x2D, 0x8F, 0x82, 0x49, 0x19, 0x5B, 0xC1,
  41646. 0x9C, 0x3E, 0x0B, 0x62, 0xEA, 0xE4, 0x96, 0xD3,
  41647. 0x8C, 0xF7, 0x50, 0x0B, 0x4F, 0x10, 0x66, 0x5F,
  41648. 0xC2, 0xD2, 0x8B, 0x9E, 0xA9, 0x35, 0xF7, 0xE3,
  41649. 0x16, 0x47, 0x2F, 0x4F, 0xF4, 0x01, 0x26, 0x75,
  41650. 0x41, 0xBD, 0xB6, 0x23, 0x01, 0x55, 0x4B, 0x20,
  41651. 0x09, 0x92, 0x8C, 0x64, 0x45, 0xBB, 0xD0, 0xEF,
  41652. 0x21, 0xD0, 0x99, 0x72, 0xF3, 0x50, 0x81, 0xAB,
  41653. 0xA9, 0x09, 0x1A, 0x6C, 0x23, 0xFE, 0xD2, 0x9F,
  41654. 0x5C, 0xF9, 0xE0, 0x77, 0x9F, 0x7E, 0xFB, 0xAD,
  41655. 0x88, 0xE6, 0x2A, 0x45, 0x44, 0x42, 0xB3, 0x00,
  41656. 0x79, 0xBE, 0x0A, 0xC9, 0xC6, 0x48, 0x26, 0xB9,
  41657. 0x8C, 0x1E, 0x10, 0x01, 0xCB, 0x0F, 0xB0, 0xF0,
  41658. 0xA9, 0x5F, 0x79, 0x65, 0xFE, 0x93, 0x12, 0xBF,
  41659. 0xDA, 0xEC, 0x33, 0xF9, 0x50, 0x65, 0xC8, 0xE5,
  41660. 0x9D, 0x39, 0x50, 0xF8, 0x0A, 0xDC, 0x7F, 0xB3,
  41661. 0x34, 0xF2, 0x02, 0xD3, 0xE5, 0xF8, 0xDA, 0x48,
  41662. 0x1C, 0x9B, 0x54, 0xA7, 0x59, 0x83, 0x93, 0x0F,
  41663. 0xD1, 0xE5, 0xAC, 0xD1, 0x62, 0x84, 0xF0, 0x71,
  41664. 0x93, 0xFB, 0xCB, 0x50, 0xD0, 0xDC, 0x00, 0xEF,
  41665. 0xF8, 0x20, 0x31, 0x44, 0xC1, 0x1E, 0xC6, 0x14,
  41666. 0x20, 0xFC, 0x32, 0xD7, 0x98, 0x2C, 0xE8, 0x96,
  41667. 0x40, 0x6B, 0xE7, 0x69, 0xA7, 0x5D, 0xD8, 0xD3,
  41668. 0xCA, 0xC7, 0x53, 0xAB, 0xE5, 0xA2, 0x78, 0x65,
  41669. 0x5B, 0xF5, 0x4B, 0xE3, 0x3A, 0x1B, 0x83, 0x74,
  41670. 0xEB, 0xEE, 0xFF, 0x21, 0x2C, 0x39, 0xCE, 0x51,
  41671. 0x46, 0x68, 0xF1, 0xC4, 0x56, 0xEA, 0xA2, 0x53,
  41672. 0x28, 0x28, 0xC8, 0x42, 0x93, 0xF1, 0xA5, 0xBC,
  41673. 0x9E, 0xB5, 0xDE, 0xDF, 0x55, 0x8A, 0x9B, 0x4C,
  41674. 0x12, 0x39, 0xF7, 0x72, 0x72, 0xC6, 0x7E, 0x1A,
  41675. 0xB2, 0x8E, 0x1E, 0xFE, 0xC5, 0x89, 0x3E, 0x09,
  41676. 0xC1, 0x06, 0x62, 0xB5, 0x3C, 0x8B, 0x82, 0x55,
  41677. 0xB1, 0xC8, 0xDC, 0x8F, 0x8E, 0x51, 0x20, 0xA2,
  41678. 0x5C, 0x75, 0xEE, 0xFE, 0x79, 0xC4, 0x3F, 0x7A,
  41679. 0x8B, 0x37, 0xDF, 0x9D, 0x1E, 0x4F, 0x32, 0x48,
  41680. 0x69, 0x33, 0xDA, 0x1C, 0xB0, 0x66, 0x4C, 0x5D,
  41681. 0xB3, 0x9E, 0x21, 0xBC, 0x22, 0x7B, 0x0C, 0xDF,
  41682. 0xE7, 0xA5, 0x50, 0x7F, 0x07, 0xF2, 0x18, 0xA7,
  41683. 0xA4, 0x7D, 0xEB, 0xCD, 0x9D, 0xAD, 0x72, 0x47,
  41684. 0xB4, 0xD0, 0x45, 0xA1, 0x3A, 0xD4, 0xF7, 0x5E,
  41685. 0xAD, 0x2D, 0x45, 0xC3, 0x39, 0xD0, 0xDF, 0x04,
  41686. 0x57, 0x7F, 0x2E, 0x0F, 0xDC, 0x78, 0x03, 0x92,
  41687. 0x55, 0x30, 0x33, 0xC7, 0x38, 0x85, 0x2B, 0x1B,
  41688. 0xE4, 0xE6, 0x3E, 0xA3, 0x89, 0x7D, 0x6C, 0x9C,
  41689. 0x4B, 0x11, 0xAD, 0x6B, 0x58, 0xD3, 0xE2, 0xD3,
  41690. 0x42, 0xD3, 0x28, 0x40, 0xF6, 0x49, 0xDD, 0x83,
  41691. 0xE7, 0x59, 0x86, 0x6B, 0x73, 0x81, 0xA8, 0x4C,
  41692. 0x8A, 0xDD, 0xDF, 0x41, 0x3F, 0xAE, 0x18, 0xE6,
  41693. 0x43, 0x1B, 0x1E, 0xEA, 0x73, 0xA5, 0x6C, 0xD8,
  41694. 0x89, 0xB7, 0x6B, 0xC9, 0x78, 0x6B, 0xED, 0xED,
  41695. 0xCA, 0x25, 0x41, 0xE4, 0xC9, 0xB2, 0x4E, 0x28,
  41696. 0xF5, 0x8A, 0xD3, 0x74, 0xC1, 0xD9, 0x3D, 0xF2,
  41697. 0xD3, 0xF2, 0xC3, 0x7E, 0xC5, 0x94, 0xA0, 0x49,
  41698. 0x8C, 0x57, 0x45, 0x79, 0xA7, 0x33, 0x2F, 0x72,
  41699. 0xC0, 0xF9, 0x75, 0x08, 0x77, 0xFA, 0xD5, 0xB9,
  41700. 0x0B, 0x96, 0x8D, 0x88, 0xF1, 0x16, 0x82, 0xC4,
  41701. 0x07, 0x1E, 0x4E, 0xA3, 0x8B, 0x81, 0x6A, 0xEA,
  41702. 0xD6, 0xBE, 0x54, 0xD2, 0xF3, 0x71, 0x32, 0x4F,
  41703. 0x24, 0x75, 0xB8, 0x62, 0xC7, 0x54, 0x24, 0xEC,
  41704. 0xF9, 0x85, 0x8A, 0xA4, 0xE2, 0x00, 0xCF, 0xBA,
  41705. 0x41, 0x2D, 0x7E, 0x3E, 0x6C, 0x30, 0x8D, 0x8D,
  41706. 0xE1, 0x1D, 0xD1, 0x85, 0x33, 0x1A, 0xF9, 0xD4,
  41707. 0x1A, 0xFE, 0x88, 0x79, 0x96, 0x5D, 0x67, 0x46,
  41708. 0xEF, 0x21, 0xFD, 0x98, 0xD3, 0xED, 0x38, 0x06,
  41709. 0xFB, 0x5C, 0x46, 0x19, 0xC9, 0x8E, 0x34, 0x7D,
  41710. 0x76, 0xB8, 0xB8, 0x98, 0x49, 0x39, 0x55, 0x61,
  41711. 0xEE, 0x28, 0x6D, 0xFD, 0xFC, 0x6A, 0x04, 0xE1,
  41712. 0xD4, 0x7E, 0x9F, 0x5B, 0x5B, 0x49, 0x25, 0x77,
  41713. 0x84, 0xC3, 0x93, 0x64, 0xDF, 0xA8, 0x8A, 0xD6,
  41714. 0x30, 0xDF, 0xA5, 0x9C, 0xCA, 0x32, 0x37, 0xF4,
  41715. 0xA2, 0xB1, 0x41, 0xA8, 0x13, 0xD2, 0x2C, 0x6F,
  41716. 0xFE, 0x73, 0xC2, 0xD9, 0x9A, 0xDC, 0x82, 0x4D,
  41717. 0x93, 0xE0, 0x6A, 0x54, 0xB6, 0xDE, 0x62, 0xC3,
  41718. 0x12, 0x5D, 0x94, 0xB4, 0x9E, 0x95, 0x0D, 0xEC,
  41719. 0x36, 0x1F, 0x96, 0x1F, 0x56, 0xD3, 0x67, 0x1C,
  41720. 0x99, 0x25, 0x37, 0x7F, 0x6E, 0x67, 0x06, 0x65,
  41721. 0x32, 0x2B, 0x84, 0x89, 0xE8, 0x33, 0xD3, 0x83,
  41722. 0x0E, 0xCC, 0xDD, 0x0F, 0x53, 0xF4, 0xA4, 0xF9,
  41723. 0xD6, 0x8F, 0x14, 0x45, 0xF3, 0xAE, 0xD5, 0xC9,
  41724. 0xD7, 0x66, 0x40, 0x9B, 0x59, 0xBA, 0xE7, 0xA7,
  41725. 0x29, 0x12, 0xE9, 0x8B, 0x3B, 0xB5, 0x73, 0x42,
  41726. 0xD2, 0x9B, 0x6A, 0xCF, 0xD1, 0x43, 0x36, 0xB7,
  41727. 0xB8, 0xB6, 0xB7, 0x54, 0x9A, 0xF8, 0xCC, 0x88,
  41728. 0x45, 0xE1, 0x0C, 0x28, 0x11, 0x28, 0x72, 0x81,
  41729. 0x98, 0x5D, 0x5D, 0x47, 0x68, 0x5F, 0xC5, 0x89,
  41730. 0xF2, 0x67, 0x8E, 0xD8, 0x93, 0xF5, 0x7B, 0x85,
  41731. 0xAC, 0xED, 0x75, 0x63, 0x2E, 0x50, 0xDE, 0x5E,
  41732. 0x07, 0x4E, 0x6C, 0xED, 0xCF, 0x1A, 0xD4, 0x99,
  41733. 0xBC, 0xE6, 0x7A, 0x7F, 0x49, 0x85, 0x64, 0xDE,
  41734. 0xEC, 0x67, 0x7C, 0x70, 0x83, 0x88, 0xDE, 0x8F,
  41735. 0xD7, 0xB0, 0x99, 0xCF, 0xC1, 0x16, 0x09, 0x6C,
  41736. 0x45, 0xFE, 0x28, 0x89, 0x0B, 0x5E, 0xAF, 0x06,
  41737. 0x16, 0x99, 0x39, 0xFD, 0xA3, 0x5E, 0x12, 0x15,
  41738. 0xF2, 0x38, 0xE8, 0xCD, 0xED, 0xFE, 0x67, 0x00,
  41739. 0x65, 0xF5, 0xDE, 0x32, 0x72, 0xA2, 0x32, 0xFD,
  41740. 0x53, 0xC2, 0x50, 0xF5, 0xD7, 0x79, 0xB3, 0x16,
  41741. 0x94, 0xFB, 0xA9, 0x1B, 0x55, 0x48, 0x03, 0x67,
  41742. 0x6E, 0x4D, 0xEA, 0x28, 0x84, 0x63, 0xFE, 0x10,
  41743. 0x63, 0x00, 0x9E, 0x9C, 0xB7, 0x6C, 0x31, 0x7D,
  41744. 0xB4, 0x00, 0xAC, 0xF4, 0xD2, 0xD2, 0xB6, 0xD1,
  41745. 0x6E, 0xDE, 0xBA, 0x41, 0x08, 0x91, 0x3F, 0x60,
  41746. 0xAE, 0xB2, 0x52, 0xCD, 0xE4, 0x13, 0x69, 0x0C,
  41747. 0xEE, 0xFD, 0xCF, 0xA6, 0x38, 0x96, 0x3D, 0xBD,
  41748. 0x04, 0xF4, 0xCF, 0x21, 0xAD, 0x74, 0xDD, 0xE6,
  41749. 0x5F, 0x0F, 0x1E, 0x7C, 0xE7, 0x0A, 0xF1, 0x01,
  41750. 0xA6, 0xDE, 0x9A, 0x59, 0xDB, 0x21, 0xD3, 0x80,
  41751. 0x27, 0xDB, 0xBF, 0x76, 0x16, 0x78, 0x27, 0x95,
  41752. 0x0B, 0x69, 0x41, 0x82, 0x66, 0xAF, 0xA4, 0x44,
  41753. 0xC7, 0x28, 0xDE, 0x36, 0x24, 0xA1, 0xC8, 0x1E,
  41754. 0x5B, 0x16, 0x41, 0xDB, 0xE8, 0x79, 0xCD, 0x82,
  41755. 0x2F, 0xB2, 0x30, 0x3C, 0xC3, 0xA9, 0xFC, 0xEE,
  41756. 0xFE, 0x3D, 0xDF, 0x7D, 0xBD, 0x0B, 0x70, 0x57,
  41757. 0x24, 0x8A, 0x28, 0xD6, 0x06, 0x2D, 0x76, 0xEB,
  41758. 0x13, 0xB9, 0x2C, 0x9C, 0x9D, 0x00, 0x3B, 0x69,
  41759. 0xE1, 0x84, 0x2A, 0x54, 0xC0, 0x9C, 0xF6, 0xB4,
  41760. 0x84, 0x52, 0x08, 0x15, 0xE2, 0xBB, 0x23, 0x72,
  41761. 0x88, 0xC6, 0x4F, 0xC6, 0x96, 0xFD, 0x3B, 0xC4,
  41762. 0x5D, 0xB3, 0x0C, 0xB8, 0x64, 0x65, 0xDF, 0x11,
  41763. 0x88, 0xBF, 0x47, 0x95, 0x6E, 0x5B, 0x91, 0x6A,
  41764. 0x80, 0x09, 0x71, 0x5C, 0xC9, 0xA9, 0xA6, 0xDC,
  41765. 0xE4, 0x4C, 0x54, 0xF9, 0x28, 0x81, 0x6B, 0x41,
  41766. 0xD0, 0x18, 0xC5, 0xFE, 0x65, 0x2F, 0xFE, 0x4E,
  41767. 0x33, 0xF3, 0x52, 0xD3, 0x83, 0xA9, 0xC1, 0x36,
  41768. 0x5F, 0x02, 0xAB, 0xFD, 0x64, 0x7B, 0xD6, 0xB4,
  41769. 0x2A, 0xD1, 0x63, 0x73, 0x0F, 0x8B, 0xFD, 0xA1,
  41770. 0xE2, 0xBE, 0x5F, 0x61, 0x4D, 0x79, 0x59, 0x78,
  41771. 0x25, 0xBA, 0x09, 0xF4, 0x57, 0xD3, 0xCB, 0xE7,
  41772. 0x56, 0x1E, 0x7E, 0x89, 0xEA, 0xF0, 0x59, 0xE9,
  41773. 0x77, 0xD1, 0xEE, 0x88, 0x84, 0x8B, 0x78, 0x1F,
  41774. 0x21, 0xF7, 0x23, 0x89, 0x0F, 0xF1, 0xF9, 0x87,
  41775. 0x39, 0x28, 0x41, 0x2C, 0x8F, 0x11, 0xEE, 0xDD,
  41776. 0x2C, 0x0C, 0x39, 0xC9, 0x51, 0x27, 0x90, 0x98,
  41777. 0x6A, 0x19, 0xE1, 0x7B, 0x2B, 0x70, 0xA4, 0xD7,
  41778. 0xCF, 0x49, 0xD9, 0xD1, 0x8C, 0xAA, 0x0C, 0x20,
  41779. 0x23, 0x13, 0x4C, 0xAC, 0xD1, 0x69, 0x20, 0x0D,
  41780. 0x88, 0x17, 0xFA, 0x32, 0x1F, 0x04, 0xAC, 0xC9,
  41781. 0x10, 0x61, 0x3D, 0xFF, 0x25, 0x0E, 0xB3, 0x25,
  41782. 0xDB, 0xEF, 0x29, 0xEB, 0x56, 0x11, 0xB2, 0xAD,
  41783. 0x2A, 0x23, 0xED, 0xD5, 0x38, 0x04, 0x9B, 0x3F,
  41784. 0x43, 0xEF, 0xEB, 0x4D, 0x60, 0x98, 0x37, 0x92,
  41785. 0xB4, 0xBF, 0x05, 0x56, 0x79, 0x44, 0xAA, 0xDB,
  41786. 0x7A, 0xC4, 0xD3, 0xA5, 0xD8, 0x0A, 0x1B, 0x9D,
  41787. 0x84, 0x48, 0xB4, 0xC0, 0xC1, 0x15, 0xC3, 0xB5,
  41788. 0xAD, 0x38, 0x85, 0x35, 0x3F, 0x47, 0xD5, 0xFC,
  41789. 0xB9, 0xB7, 0xD6, 0x44, 0x6F, 0x1A, 0x72, 0x10,
  41790. 0xBB, 0xC6, 0x67, 0xFC, 0x41, 0x14, 0x15, 0xF2,
  41791. 0x3C, 0xD4, 0x0A, 0x2A, 0x3D, 0x64, 0x06, 0x1D,
  41792. 0x71, 0xC6, 0x71, 0x91, 0x57, 0x1A, 0x97, 0xD0,
  41793. 0x10, 0x88, 0xA2, 0x4B, 0x67, 0x11, 0x56, 0x7F,
  41794. 0xC8, 0x91, 0x06, 0x73, 0x2D, 0x88, 0x92, 0xFF,
  41795. 0x98, 0x5B, 0x8E, 0x6C, 0xF7, 0x01, 0x63, 0x82,
  41796. 0x9C, 0xC0, 0x85, 0xBE, 0x4E, 0x40, 0x83, 0x15,
  41797. 0x36, 0x1B, 0xB1, 0xB2, 0x00, 0x3D, 0x64, 0x13,
  41798. 0x22, 0x0B, 0x13, 0x45, 0x06, 0xD3, 0xC3, 0x04,
  41799. 0xC0, 0xBB, 0xBA, 0x9C, 0x9C, 0x45, 0xD3, 0x65,
  41800. 0x1E, 0x05, 0x71, 0xB6, 0xB1, 0x15, 0x17, 0x72,
  41801. 0x13, 0xD8, 0x59, 0x5E, 0x14, 0x3D, 0xB9, 0x0B,
  41802. 0xD7, 0x2F, 0x7E, 0xB9, 0x74, 0xD8, 0xD0, 0xA0,
  41803. 0x31, 0x74, 0x09, 0xD6, 0x4D, 0x58, 0x37, 0xEA,
  41804. 0xEC, 0x9B, 0x8D, 0x44, 0xDD, 0x7E, 0xCF, 0xF6,
  41805. 0xCD, 0xA9, 0xF7, 0x29, 0x38, 0x2A, 0x43, 0xB3,
  41806. 0x79, 0xCB, 0xDD, 0x43, 0xFF, 0xB1, 0x8A, 0xEA,
  41807. 0x35, 0xC1, 0xA9, 0x96, 0xCE, 0xF1, 0x48, 0x8D,
  41808. 0x3B, 0x7A, 0x81, 0xEE, 0x7C, 0xFC, 0x0B, 0x96,
  41809. 0x23, 0x41, 0x8A, 0xB3, 0x91, 0x9A, 0x6E, 0xDD,
  41810. 0xB9, 0x9F, 0x22, 0x2F, 0x0D, 0xDD, 0xB2, 0xF3,
  41811. 0x2A, 0x20, 0xC8, 0xF8, 0x4F, 0xBF, 0x4C, 0x49,
  41812. 0xB4, 0xCB, 0x3E, 0xB5, 0x0D, 0x9C, 0x4C, 0xD2,
  41813. 0x5A, 0x6F, 0x71, 0x75, 0x46, 0x70, 0x66, 0xD2,
  41814. 0x5E, 0x64, 0x37, 0xB6, 0x7F, 0x2D, 0xBC, 0x70,
  41815. 0xC2, 0xE6, 0xEB, 0x0B, 0xDE, 0x23, 0x86, 0xD0,
  41816. 0x30, 0x14, 0xA7, 0x89, 0xFB, 0x6D, 0xC0, 0x8E,
  41817. 0xE3, 0x3C, 0x0C, 0x67, 0x95, 0x1D, 0xA9, 0xD7,
  41818. 0x4B, 0x9C, 0x94, 0x84, 0x5D, 0x2A, 0x99, 0x03,
  41819. 0x7E, 0x09, 0x5F, 0xEF, 0x79, 0x19, 0x92, 0x0F,
  41820. 0xE5, 0x26, 0xEB, 0x5D, 0xD0, 0xBA, 0x1F, 0x97,
  41821. 0xDF, 0xBD, 0x2D, 0xDC, 0x31, 0x60, 0x9C, 0x1B,
  41822. 0x7B, 0x45, 0xEC, 0x3A, 0xDB, 0x58, 0x6F, 0xE3,
  41823. 0x03, 0x0A, 0x0C, 0x7A, 0x9D, 0xD0, 0x34, 0xA3,
  41824. 0xC2, 0xE6, 0xF9, 0x84, 0x90, 0x93, 0xCE, 0xE1,
  41825. 0x0A, 0x18, 0x19, 0x53, 0x54, 0x7F, 0x8B, 0xE3,
  41826. 0x28, 0x72, 0x0A, 0x4A, 0x5A, 0x82, 0x90, 0xB5,
  41827. 0xEE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  41828. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  41829. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
  41830. 0x0B, 0x10, 0x18, 0x1A, 0x21
  41831. };
  41832. #endif
  41833. #ifndef WOLFSSL_NO_ML_DSA_87
  41834. static const byte pk_87[] = {
  41835. 0x59, 0xB2, 0x37, 0x1F, 0xE7, 0xBA, 0xCC, 0x20,
  41836. 0x7F, 0xE1, 0xFE, 0xE8, 0x8A, 0x8B, 0x38, 0x05,
  41837. 0xA7, 0x05, 0x28, 0x65, 0x69, 0x17, 0x89, 0xBB,
  41838. 0x90, 0x54, 0x2F, 0xA4, 0x7F, 0x7E, 0xF2, 0xB7,
  41839. 0x5F, 0xCA, 0x13, 0xDB, 0xA5, 0x88, 0x8B, 0xEC,
  41840. 0x32, 0x05, 0x14, 0xDC, 0xB0, 0x5F, 0xD2, 0x6E,
  41841. 0xB5, 0x54, 0x1F, 0x6E, 0x57, 0x2E, 0xCE, 0xA6,
  41842. 0xC4, 0xF1, 0xD3, 0x8A, 0xA7, 0x02, 0x59, 0x09,
  41843. 0x4A, 0xA9, 0x45, 0xF1, 0x9F, 0xED, 0x0D, 0x98,
  41844. 0x0E, 0x65, 0xDB, 0xF6, 0x5D, 0xB8, 0x0F, 0x56,
  41845. 0x4F, 0xE2, 0x9D, 0x83, 0x6C, 0x54, 0x79, 0x28,
  41846. 0x8B, 0x55, 0xCF, 0x07, 0xF4, 0xE0, 0x01, 0x59,
  41847. 0xB6, 0x95, 0x5D, 0xAB, 0xDE, 0xCC, 0x8C, 0x4D,
  41848. 0x66, 0xAE, 0x68, 0x87, 0x28, 0xBA, 0x6D, 0x5C,
  41849. 0x04, 0x42, 0xF3, 0xC1, 0x23, 0x2C, 0x78, 0x2C,
  41850. 0x46, 0x5B, 0x9B, 0x7C, 0x50, 0x14, 0xB1, 0x46,
  41851. 0x40, 0x65, 0xCC, 0xD8, 0xA5, 0x6D, 0x6B, 0x1C,
  41852. 0x16, 0x51, 0x08, 0x69, 0xE0, 0x14, 0xE6, 0x93,
  41853. 0x39, 0x98, 0xEF, 0x72, 0x55, 0x20, 0xB4, 0x00,
  41854. 0x91, 0x3D, 0x93, 0xB0, 0xEC, 0x75, 0xE2, 0xFB,
  41855. 0x72, 0x5D, 0xC1, 0xAE, 0xC0, 0xC0, 0xCC, 0x73,
  41856. 0x43, 0xB9, 0xE5, 0x44, 0xBA, 0xA4, 0xD6, 0x79,
  41857. 0x86, 0x0E, 0x34, 0x7B, 0x2E, 0x94, 0x7D, 0x8D,
  41858. 0x24, 0x36, 0xF0, 0x92, 0x98, 0xA7, 0xBB, 0x83,
  41859. 0x36, 0xB9, 0xDE, 0x9C, 0xFD, 0x5C, 0xDB, 0xCD,
  41860. 0x91, 0xC7, 0x24, 0x92, 0x68, 0xCA, 0x03, 0xEF,
  41861. 0xAC, 0x27, 0x3A, 0xF5, 0x29, 0x68, 0xD5, 0x01,
  41862. 0x40, 0x6C, 0xD9, 0xC9, 0x61, 0x59, 0xD7, 0xC1,
  41863. 0x5A, 0xA2, 0x90, 0x03, 0x30, 0xC1, 0x18, 0x9C,
  41864. 0xFC, 0x2C, 0xD8, 0xB9, 0x12, 0xC4, 0x80, 0xE4,
  41865. 0x58, 0x29, 0x7E, 0xF1, 0x4D, 0xB6, 0x94, 0xA3,
  41866. 0xF1, 0xE7, 0x2C, 0x1D, 0xFA, 0x3A, 0x3D, 0x2A,
  41867. 0x8A, 0x69, 0xE0, 0x11, 0x60, 0x2B, 0x93, 0x02,
  41868. 0x0B, 0xAC, 0xD1, 0xC2, 0xF3, 0xAD, 0x06, 0xC9,
  41869. 0x5A, 0x7F, 0x36, 0xEB, 0xF5, 0x26, 0x1F, 0x6E,
  41870. 0xC1, 0x06, 0x81, 0x6B, 0xB3, 0x30, 0x3C, 0xC0,
  41871. 0x0B, 0xF4, 0xE8, 0x68, 0x8D, 0x2E, 0x85, 0x48,
  41872. 0xF1, 0x04, 0x90, 0xD9, 0xEB, 0x23, 0xC5, 0x67,
  41873. 0x93, 0xB3, 0x4B, 0x84, 0x06, 0xCB, 0xE4, 0x43,
  41874. 0xD8, 0x35, 0x6B, 0xCD, 0x0F, 0x4F, 0x61, 0xD0,
  41875. 0xD0, 0x17, 0xD5, 0x48, 0x31, 0xB9, 0xBA, 0x32,
  41876. 0x9F, 0x89, 0x48, 0xF2, 0x5C, 0x31, 0x22, 0xF9,
  41877. 0xDE, 0xDE, 0x8C, 0xEC, 0xBA, 0x51, 0x56, 0x9E,
  41878. 0xDF, 0xFF, 0x89, 0x5F, 0xA0, 0x20, 0x86, 0x2C,
  41879. 0x5D, 0xF7, 0x9F, 0x86, 0x40, 0x78, 0x48, 0x6B,
  41880. 0x5F, 0xB2, 0x28, 0xFD, 0x78, 0x9C, 0x35, 0xFD,
  41881. 0xE1, 0xC5, 0x4B, 0xFF, 0xBF, 0x4A, 0x02, 0x5A,
  41882. 0x7F, 0xE7, 0xD8, 0xC3, 0x49, 0x0A, 0x5D, 0x4E,
  41883. 0x62, 0xD0, 0x4F, 0x79, 0xF4, 0x18, 0x3C, 0xA6,
  41884. 0x83, 0x79, 0xF4, 0x64, 0x8B, 0xD5, 0xB2, 0x41,
  41885. 0x6D, 0xBE, 0x5B, 0x84, 0x5C, 0x9F, 0x4B, 0x7A,
  41886. 0x7E, 0x23, 0x39, 0xC0, 0x50, 0x6D, 0x58, 0x53,
  41887. 0x9E, 0xAE, 0xA9, 0x45, 0x1C, 0x9B, 0x2F, 0xE2,
  41888. 0xA1, 0x8C, 0x84, 0x9D, 0xCA, 0x7E, 0xED, 0x9D,
  41889. 0xAC, 0xC0, 0x58, 0xD0, 0x05, 0xFB, 0x73, 0x75,
  41890. 0xC4, 0xEF, 0x45, 0xB0, 0x01, 0x54, 0x3F, 0xC6,
  41891. 0x8E, 0x47, 0xDD, 0xB6, 0xD1, 0x4F, 0xF9, 0x37,
  41892. 0xD1, 0xAA, 0x0D, 0x4D, 0x74, 0x89, 0xDF, 0xFA,
  41893. 0x62, 0x10, 0x67, 0x9C, 0xCC, 0xEC, 0xF9, 0xB8,
  41894. 0x55, 0x1D, 0xCF, 0x68, 0x2D, 0x2A, 0xF1, 0xE5,
  41895. 0xBD, 0x86, 0x9F, 0x3E, 0x8D, 0x40, 0x0D, 0x5C,
  41896. 0x86, 0x1A, 0xE5, 0x1F, 0xE7, 0xEB, 0xBB, 0x54,
  41897. 0x57, 0xF2, 0xEA, 0xAF, 0xD0, 0x93, 0xA9, 0x59,
  41898. 0x8E, 0xC7, 0x21, 0xC6, 0x93, 0x27, 0xC5, 0x19,
  41899. 0x30, 0xF4, 0xB9, 0xFF, 0xB2, 0xAA, 0x7F, 0x1A,
  41900. 0x28, 0x43, 0x6B, 0x6D, 0x80, 0x8D, 0x75, 0x39,
  41901. 0x2B, 0xC4, 0x3C, 0x1B, 0x5B, 0x85, 0x9C, 0x66,
  41902. 0xC5, 0x4F, 0xA5, 0x15, 0xC7, 0xA6, 0x15, 0xA6,
  41903. 0x9E, 0x60, 0x92, 0x14, 0x34, 0xAA, 0x9C, 0xF9,
  41904. 0xF9, 0xE0, 0x3C, 0x3C, 0xA3, 0x5B, 0x5E, 0xBC,
  41905. 0x6A, 0x40, 0x9E, 0x82, 0x2F, 0xE7, 0x6E, 0x09,
  41906. 0x24, 0xC6, 0xC0, 0x62, 0xF1, 0x72, 0x4C, 0x38,
  41907. 0x2F, 0xF3, 0xC8, 0xAC, 0xB5, 0xC1, 0x66, 0x6C,
  41908. 0x2E, 0xC2, 0x6B, 0x76, 0x28, 0xE3, 0xD7, 0xC1,
  41909. 0x3D, 0xA8, 0xD7, 0x58, 0x89, 0x0E, 0x6C, 0xC0,
  41910. 0x17, 0xB7, 0x89, 0x25, 0x82, 0xE9, 0x5E, 0xDD,
  41911. 0x04, 0xBA, 0x93, 0x45, 0xDF, 0x70, 0xFA, 0xD5,
  41912. 0x6E, 0xA6, 0x8B, 0xF8, 0x87, 0x5B, 0x93, 0x2C,
  41913. 0x28, 0xB3, 0x28, 0x07, 0xC8, 0x63, 0x71, 0xE1,
  41914. 0x7D, 0xCC, 0x04, 0x72, 0x5C, 0xB5, 0x97, 0xB5,
  41915. 0x24, 0x46, 0x79, 0x63, 0xE1, 0xD4, 0xA6, 0x1B,
  41916. 0x5F, 0xBF, 0x9E, 0xC5, 0x04, 0xD5, 0xDD, 0xB6,
  41917. 0x17, 0x93, 0xDD, 0x4E, 0x34, 0xAE, 0x08, 0x2A,
  41918. 0x59, 0x90, 0xEF, 0xCE, 0x80, 0x1E, 0x93, 0x8C,
  41919. 0xCA, 0xE7, 0x38, 0xE0, 0x2E, 0x90, 0x59, 0x9D,
  41920. 0x97, 0x1C, 0x2D, 0x7C, 0x64, 0xE5, 0xB6, 0xF8,
  41921. 0x63, 0x9F, 0x75, 0x8E, 0xD6, 0x21, 0xC1, 0xF2,
  41922. 0x10, 0x73, 0xC0, 0x3E, 0xDB, 0x78, 0x2C, 0x7A,
  41923. 0x0F, 0x5D, 0x7C, 0x66, 0xF5, 0xCE, 0x16, 0x1D,
  41924. 0xED, 0x55, 0xB3, 0xE9, 0x2D, 0xC2, 0x71, 0x83,
  41925. 0xAB, 0x08, 0x3D, 0xBC, 0x1F, 0x39, 0x30, 0xAE,
  41926. 0x56, 0xED, 0xB8, 0xC5, 0x3E, 0x9A, 0x7E, 0x02,
  41927. 0x0F, 0xFF, 0x0C, 0x40, 0x42, 0xF5, 0x18, 0xB2,
  41928. 0x6F, 0x39, 0x0C, 0x96, 0xC8, 0x18, 0x3B, 0x79,
  41929. 0xB5, 0x3C, 0x7C, 0x7B, 0xC5, 0x15, 0x18, 0x7B,
  41930. 0x3D, 0xE8, 0xCA, 0xB0, 0x87, 0x69, 0xC5, 0xDD,
  41931. 0x6F, 0xF5, 0x49, 0x21, 0x12, 0xE8, 0xB0, 0xF2,
  41932. 0x8D, 0x09, 0xF4, 0x06, 0x7A, 0xDB, 0x04, 0x19,
  41933. 0x4F, 0x60, 0x25, 0x0E, 0x75, 0xAD, 0xE3, 0x31,
  41934. 0xA5, 0xC2, 0x55, 0x93, 0xBC, 0xD9, 0x2A, 0x6D,
  41935. 0x13, 0x50, 0x43, 0x95, 0x85, 0x86, 0x0B, 0xB6,
  41936. 0xFE, 0xED, 0xBD, 0x2F, 0x83, 0x9F, 0x31, 0x7A,
  41937. 0x01, 0x35, 0x88, 0x76, 0xC8, 0x8E, 0x89, 0x8A,
  41938. 0xC0, 0xC8, 0x53, 0x78, 0xF5, 0x72, 0xF2, 0x3C,
  41939. 0xDE, 0x93, 0x1D, 0x47, 0xDE, 0x71, 0xD3, 0x35,
  41940. 0x3D, 0xAB, 0x1F, 0x81, 0x0A, 0x61, 0xB1, 0x8D,
  41941. 0x24, 0xCD, 0x83, 0xDD, 0xAB, 0x8D, 0x53, 0xBA,
  41942. 0x9C, 0x7B, 0x82, 0x74, 0xB0, 0xFE, 0x82, 0xAF,
  41943. 0xF3, 0x0C, 0x57, 0x07, 0x2F, 0x64, 0x37, 0x87,
  41944. 0xCA, 0x1D, 0xF0, 0x3B, 0x99, 0xEB, 0x57, 0xDB,
  41945. 0xDA, 0x8C, 0x8E, 0xE8, 0xEB, 0x20, 0x1F, 0x28,
  41946. 0x47, 0xCB, 0xC9, 0xD3, 0x4F, 0xD8, 0x0C, 0xE6,
  41947. 0xBC, 0x5E, 0x1E, 0x32, 0x8E, 0xB6, 0xEF, 0xC8,
  41948. 0x3C, 0x4B, 0xD9, 0xD5, 0x2F, 0x32, 0x4E, 0x30,
  41949. 0xEE, 0x4B, 0x5E, 0x86, 0x35, 0x1E, 0x5C, 0x8C,
  41950. 0x4C, 0x54, 0x56, 0x83, 0x6D, 0x5A, 0x45, 0x22,
  41951. 0x03, 0xB3, 0xC3, 0x72, 0xC7, 0x87, 0xAE, 0x33,
  41952. 0x32, 0xC8, 0xA5, 0xE9, 0xDC, 0x21, 0x97, 0xD9,
  41953. 0xC3, 0x41, 0xB9, 0x75, 0x6B, 0xB1, 0xE6, 0x3C,
  41954. 0x75, 0xBB, 0xD5, 0xCF, 0x3E, 0x5C, 0xD4, 0xBF,
  41955. 0x47, 0xBD, 0x1F, 0xEB, 0xC3, 0xE3, 0x71, 0x09,
  41956. 0x12, 0xD6, 0x30, 0x32, 0xF6, 0xB9, 0x7D, 0xC1,
  41957. 0x9C, 0x4D, 0xE1, 0x96, 0xAC, 0xD9, 0x15, 0x77,
  41958. 0x15, 0xE2, 0xC1, 0x4E, 0x05, 0x4A, 0x93, 0x17,
  41959. 0xBF, 0x96, 0xA6, 0x84, 0xBB, 0x96, 0xCE, 0xFB,
  41960. 0x7D, 0x8F, 0xDC, 0xA8, 0xAA, 0x47, 0x7A, 0x2A,
  41961. 0xF6, 0xF7, 0x26, 0xD2, 0xCA, 0xC1, 0xA6, 0x03,
  41962. 0xCF, 0x13, 0x60, 0xEC, 0x11, 0xCA, 0x89, 0x7E,
  41963. 0x5B, 0xC7, 0x35, 0xAB, 0x69, 0xB8, 0x64, 0x7F,
  41964. 0x30, 0xCE, 0xD4, 0x94, 0x7B, 0xA9, 0xF6, 0x35,
  41965. 0xD9, 0xCB, 0x2D, 0x82, 0xA6, 0x62, 0xFF, 0x17,
  41966. 0xA0, 0xE1, 0x2D, 0x4D, 0x06, 0xD6, 0x41, 0xEE,
  41967. 0x76, 0xEB, 0x8B, 0x45, 0xC7, 0x1E, 0xDE, 0x38,
  41968. 0xC9, 0x05, 0xC5, 0x2B, 0xE7, 0x6C, 0x61, 0x09,
  41969. 0xF2, 0x61, 0x2F, 0xEE, 0x6C, 0x31, 0x94, 0x46,
  41970. 0x5C, 0x19, 0xBA, 0x5D, 0x3E, 0xBC, 0xF1, 0xF0,
  41971. 0xB5, 0xE5, 0x34, 0xE0, 0xF0, 0xF1, 0xD3, 0x1C,
  41972. 0xB1, 0xE7, 0xA3, 0x6C, 0x43, 0x03, 0xF2, 0x83,
  41973. 0xDB, 0xA8, 0x59, 0x1C, 0xC6, 0x09, 0x31, 0x1A,
  41974. 0x80, 0x9E, 0x44, 0x4E, 0x33, 0xA8, 0x93, 0x88,
  41975. 0x0C, 0xDB, 0xAE, 0x29, 0x11, 0x91, 0x46, 0xA3,
  41976. 0x68, 0xE4, 0xD2, 0xED, 0xD9, 0x1F, 0xE4, 0x71,
  41977. 0x64, 0x7F, 0xFE, 0x82, 0x1A, 0xA6, 0xD3, 0x1C,
  41978. 0x9F, 0xA4, 0x96, 0x95, 0xEB, 0x99, 0x41, 0xB0,
  41979. 0x8F, 0x7B, 0xE3, 0xF0, 0x6C, 0xDD, 0xF2, 0x73,
  41980. 0x9B, 0x8C, 0xAD, 0x2A, 0xB0, 0xDA, 0x4F, 0x5A,
  41981. 0x3C, 0x0A, 0x26, 0xDF, 0x6A, 0x17, 0xB1, 0x37,
  41982. 0xCA, 0xAB, 0x3B, 0x91, 0x9A, 0xB6, 0x36, 0xD6,
  41983. 0xC8, 0x9B, 0xED, 0xA3, 0x05, 0x88, 0x98, 0x62,
  41984. 0x87, 0x21, 0xF2, 0x77, 0x03, 0x15, 0xFE, 0xEE,
  41985. 0x88, 0x15, 0x95, 0xE2, 0x4C, 0xF4, 0x8B, 0x44,
  41986. 0x16, 0x60, 0xD0, 0xB2, 0xE9, 0xD5, 0xB9, 0x09,
  41987. 0x28, 0xC3, 0x81, 0xF2, 0xB0, 0xFA, 0x26, 0x34,
  41988. 0x2E, 0x4C, 0x9B, 0x88, 0xC0, 0x88, 0x7A, 0x46,
  41989. 0x87, 0x12, 0x4C, 0x01, 0x2D, 0x96, 0x9E, 0x1A,
  41990. 0xFD, 0x85, 0x32, 0x75, 0x4B, 0xA1, 0x21, 0x25,
  41991. 0xE9, 0x43, 0x3D, 0xCF, 0x6D, 0x7B, 0xC1, 0xA3,
  41992. 0x6A, 0x83, 0xE6, 0xA1, 0x0B, 0xA1, 0xCB, 0x76,
  41993. 0x52, 0xA8, 0x13, 0x50, 0x89, 0x9C, 0x2D, 0xFC,
  41994. 0x6E, 0x4F, 0xED, 0x38, 0xD0, 0x09, 0xE6, 0xD0,
  41995. 0xF1, 0xD4, 0x4C, 0xCC, 0xB9, 0x5E, 0x55, 0x1B,
  41996. 0x3A, 0xD5, 0x4B, 0x3A, 0xC8, 0x1E, 0x8B, 0xA4,
  41997. 0x66, 0x5E, 0xA4, 0x28, 0xB3, 0xC8, 0x61, 0xE8,
  41998. 0x67, 0x78, 0x90, 0xCF, 0x5F, 0x62, 0x5C, 0x19,
  41999. 0xA7, 0xC5, 0x94, 0x3A, 0x94, 0x01, 0xCB, 0x78,
  42000. 0xE7, 0x02, 0x6B, 0xAE, 0x92, 0xB6, 0x0A, 0x8B,
  42001. 0x68, 0x07, 0xC1, 0x77, 0x45, 0x41, 0x5C, 0xD8,
  42002. 0xE0, 0x30, 0xC6, 0x4C, 0x56, 0xE8, 0x22, 0x13,
  42003. 0x9A, 0x35, 0xDA, 0x42, 0x3F, 0x26, 0x43, 0x36,
  42004. 0xE0, 0xAF, 0xDF, 0x16, 0x74, 0x30, 0xDD, 0x36,
  42005. 0xE0, 0x06, 0x4B, 0x2F, 0x6E, 0x8D, 0x8B, 0xB6,
  42006. 0xBE, 0x99, 0xC5, 0xA9, 0xFB, 0x55, 0x1C, 0xC6,
  42007. 0x3E, 0x50, 0x8D, 0xB6, 0x36, 0x66, 0x7D, 0xDA,
  42008. 0x53, 0xF6, 0x11, 0xF0, 0x2F, 0xCD, 0x1F, 0x99,
  42009. 0x41, 0x0F, 0x1A, 0x7A, 0x82, 0x88, 0x2F, 0x96,
  42010. 0x23, 0xAD, 0xDC, 0x50, 0xEB, 0x01, 0xE1, 0xF3,
  42011. 0x99, 0x78, 0xBF, 0x68, 0x50, 0x6C, 0x71, 0xDB,
  42012. 0xBE, 0xE4, 0x2E, 0x4A, 0x80, 0x06, 0x9B, 0x0E,
  42013. 0x4C, 0x7F, 0xC4, 0xCC, 0x14, 0x71, 0xF4, 0xF1,
  42014. 0x02, 0x8D, 0xB2, 0x5C, 0x46, 0x87, 0xB6, 0x0D,
  42015. 0xF4, 0x25, 0x5D, 0xEC, 0x91, 0x48, 0x19, 0x7A,
  42016. 0x74, 0x79, 0x6E, 0xC7, 0x60, 0xA6, 0x6A, 0xFC,
  42017. 0x78, 0x84, 0x03, 0x86, 0x51, 0x92, 0x09, 0x73,
  42018. 0xA6, 0x9C, 0x20, 0x35, 0x16, 0x22, 0x26, 0x32,
  42019. 0xEC, 0x58, 0x75, 0xEA, 0x6D, 0x83, 0x80, 0x96,
  42020. 0xE7, 0xFE, 0x9B, 0x5B, 0x4F, 0xB6, 0x9C, 0x5E,
  42021. 0x94, 0x07, 0xE7, 0x0D, 0x27, 0xFA, 0x34, 0xB0,
  42022. 0xCD, 0xBD, 0x6E, 0x11, 0x9D, 0x87, 0xCE, 0x38,
  42023. 0x58, 0x1D, 0xF1, 0xD3, 0xE0, 0xDF, 0x3A, 0xE0,
  42024. 0x29, 0x04, 0x2A, 0x3B, 0x20, 0xE9, 0x23, 0xEB,
  42025. 0xCE, 0x19, 0xA4, 0x95, 0x87, 0x55, 0xEE, 0x2F,
  42026. 0x98, 0xFD, 0x23, 0x4C, 0x44, 0x13, 0xE2, 0xDB,
  42027. 0xC9, 0x35, 0x59, 0xA4, 0x28, 0xDC, 0x37, 0xF2,
  42028. 0xD1, 0x23, 0x5B, 0xD4, 0x41, 0x9B, 0x09, 0x9E,
  42029. 0x0F, 0x0D, 0xE5, 0x42, 0xC4, 0x69, 0x35, 0x99,
  42030. 0x1B, 0xE0, 0x69, 0x2A, 0x6D, 0x80, 0xB8, 0xFD,
  42031. 0x98, 0x86, 0xE0, 0xFA, 0x17, 0x69, 0xB4, 0x9E,
  42032. 0x8A, 0xE6, 0x30, 0x7C, 0xB0, 0xBC, 0x1B, 0x49,
  42033. 0x73, 0x2D, 0x26, 0xE2, 0x5C, 0xA1, 0xCD, 0x9D,
  42034. 0x40, 0x7E, 0x0D, 0x88, 0x64, 0x04, 0x09, 0x41,
  42035. 0x61, 0x1F, 0x93, 0x33, 0xB6, 0x36, 0x7E, 0x83,
  42036. 0x00, 0xFD, 0x64, 0x6A, 0xC5, 0xA7, 0x1A, 0xD9,
  42037. 0x13, 0xEE, 0xFD, 0x80, 0x8D, 0x5C, 0xAF, 0xBF,
  42038. 0x15, 0x21, 0xA3, 0x06, 0x2E, 0xC1, 0x84, 0xE5,
  42039. 0x21, 0x65, 0x50, 0x1E, 0x00, 0x55, 0x56, 0xDE,
  42040. 0x4D, 0xEE, 0x46, 0xF9, 0xE5, 0x3D, 0x7D, 0xEF,
  42041. 0x99, 0x09, 0xF3, 0xD5, 0xD9, 0x8C, 0xA8, 0x0D,
  42042. 0x87, 0x70, 0x7F, 0x7B, 0xC0, 0xFF, 0x8D, 0x87,
  42043. 0x9D, 0x65, 0xD4, 0xD7, 0x83, 0xD1, 0x96, 0xF2,
  42044. 0x46, 0x06, 0x93, 0x81, 0x1C, 0xDF, 0x33, 0x35,
  42045. 0x8E, 0x08, 0x2D, 0x81, 0xF4, 0xDB, 0x8F, 0x6C,
  42046. 0x20, 0x48, 0x61, 0x83, 0xA3, 0x6D, 0x4F, 0xBC,
  42047. 0xC8, 0xA1, 0xC6, 0xDA, 0x21, 0xAA, 0x4D, 0xD1,
  42048. 0x36, 0xE1, 0x9F, 0xEF, 0x2E, 0xA9, 0x93, 0x97,
  42049. 0x2B, 0xB9, 0x98, 0x9A, 0xC1, 0xC3, 0x8A, 0x79,
  42050. 0xF3, 0x18, 0x52, 0x17, 0x80, 0x04, 0x12, 0x3C,
  42051. 0x46, 0x27, 0x7D, 0x38, 0xA8, 0x8F, 0xC1, 0x58,
  42052. 0x9F, 0x25, 0x73, 0x32, 0x28, 0x4C, 0xD8, 0xA8,
  42053. 0x73, 0xC2, 0x5A, 0x1A, 0x6D, 0x40, 0x26, 0x5B,
  42054. 0x28, 0x5D, 0xF0, 0x93, 0x70, 0xE8, 0x8F, 0x72,
  42055. 0xFF, 0x70, 0xE4, 0x34, 0xE8, 0xF6, 0x60, 0x84,
  42056. 0xCC, 0xFE, 0xBD, 0xBB, 0xC4, 0xB9, 0x9E, 0xDF,
  42057. 0xBC, 0x75, 0x0C, 0xC5, 0xDE, 0xA6, 0x36, 0x17,
  42058. 0xF6, 0x47, 0xF5, 0xF0, 0x21, 0xD5, 0x7D, 0x64,
  42059. 0xD5, 0xEF, 0xF0, 0x48, 0x63, 0x4D, 0xB2, 0x20,
  42060. 0x9D, 0x7C, 0x8B, 0x82, 0xFB, 0x63, 0xB8, 0x82,
  42061. 0x3E, 0x4C, 0xA0, 0x57, 0x16, 0x8B, 0xAE, 0x88,
  42062. 0xD9, 0x71, 0x52, 0x91, 0x24, 0x0B, 0x37, 0x58,
  42063. 0xD7, 0x68, 0x45, 0x01, 0xF8, 0x61, 0x86, 0x7B,
  42064. 0x7A, 0x24, 0x1C, 0x06, 0x3B, 0x05, 0xD5, 0xE8,
  42065. 0xCA, 0x6B, 0x4C, 0x79, 0xCB, 0x24, 0x35, 0xD7,
  42066. 0xF9, 0x94, 0xCB, 0x76, 0x91, 0x5B, 0x4A, 0x54,
  42067. 0x87, 0x08, 0xB1, 0x1B, 0x29, 0x44, 0x96, 0x85,
  42068. 0x94, 0x1D, 0x43, 0xE6, 0x0A, 0x89, 0x76, 0xF9,
  42069. 0xA9, 0x60, 0x72, 0xF9, 0x10, 0x41, 0xF4, 0xC3,
  42070. 0xDF, 0x7C, 0x73, 0x96, 0x90, 0x12, 0xAE, 0x1B,
  42071. 0x30, 0xE4, 0xB9, 0xC4, 0xE1, 0x33, 0x55, 0x8D,
  42072. 0xAB, 0xC4, 0x6C, 0x10, 0x3C, 0x0C, 0xB1, 0xDF,
  42073. 0xB9, 0x9B, 0x58, 0x53, 0x74, 0xA5, 0x4F, 0x9B,
  42074. 0xA5, 0x6B, 0x72, 0x48, 0xB8, 0xC3, 0xF6, 0x6F,
  42075. 0x1D, 0x55, 0x76, 0x0D, 0x6A, 0xBB, 0x43, 0x03,
  42076. 0x75, 0x77, 0x4D, 0xFB, 0xA2, 0x05, 0x9C, 0x5D,
  42077. 0xDD, 0xB6, 0x59, 0xFD, 0x2E, 0x1D, 0xA9, 0xC3,
  42078. 0xF0, 0xB8, 0x08, 0x68, 0xC9, 0x2B, 0xCA, 0xC1,
  42079. 0x04, 0x03, 0xDC, 0xD1, 0x40, 0xD6, 0xA3, 0xD3,
  42080. 0xF3, 0x5F, 0x8E, 0xF1, 0xA2, 0xDD, 0x98, 0xDE,
  42081. 0x1A, 0x43, 0x34, 0x23, 0x85, 0x99, 0xED, 0xAD,
  42082. 0x92, 0x0D, 0xC0, 0xAA, 0x69, 0x8E, 0x9F, 0xE6,
  42083. 0x10, 0x6A, 0x07, 0x80, 0xC9, 0xC2, 0x45, 0xF2,
  42084. 0xC6, 0x5A, 0x0C, 0x3E, 0x5C, 0xD5, 0x36, 0x61,
  42085. 0x10, 0xB1, 0x76, 0x0F, 0xCD, 0x41, 0x4D, 0x45,
  42086. 0x0D, 0xB9, 0xD7, 0x6A, 0x22, 0xA9, 0xEA, 0xEA,
  42087. 0x0C, 0x9F, 0xB7, 0x2E, 0xD5, 0x43, 0xCE, 0x9F,
  42088. 0xA3, 0x31, 0x4B, 0xAB, 0x17, 0x68, 0x7E, 0x9D,
  42089. 0xE5, 0xAD, 0xAD, 0x75, 0x61, 0xF1, 0xA5, 0xBE,
  42090. 0xC1, 0x63, 0x39, 0x26, 0x9A, 0x87, 0xE0, 0x9A,
  42091. 0xCB, 0x29, 0xE4, 0xC4, 0x39, 0x60, 0x5E, 0x95,
  42092. 0x72, 0xAA, 0x9B, 0x7D, 0x0E, 0x83, 0x71, 0xA3,
  42093. 0x0E, 0x41, 0xA0, 0xA7, 0xBD, 0xC0, 0x2D, 0xA3,
  42094. 0xA6, 0x12, 0x1B, 0xF2, 0x61, 0xEA, 0xA0, 0x16,
  42095. 0xA2, 0x07, 0x4E, 0x44, 0x32, 0xCF, 0x63, 0xAF,
  42096. 0x96, 0xBE, 0x81, 0xCE, 0xB6, 0xE0, 0xC2, 0x67,
  42097. 0x6A, 0x85, 0x45, 0xC6, 0x6D, 0x2F, 0x30, 0xC9,
  42098. 0x8B, 0x54, 0x24, 0xF0, 0xFE, 0xF0, 0x4B, 0x3C,
  42099. 0x6C, 0x70, 0x64, 0xE2, 0xD2, 0xE1, 0x1C, 0xBE,
  42100. 0x60, 0xF8, 0x57, 0x23, 0xFF, 0xC0, 0xB7, 0x70,
  42101. 0xD6, 0x86, 0x6F, 0xFA, 0x58, 0x9E, 0x3F, 0x9B,
  42102. 0x2A, 0xBF, 0x75, 0x10, 0x40, 0x19, 0xAA, 0x69,
  42103. 0xCB, 0x58, 0x89, 0x5B, 0x47, 0x4A, 0x0A, 0xDE,
  42104. 0x2B, 0x60, 0xA4, 0xAB, 0x07, 0x7C, 0x3A, 0x6D,
  42105. 0xF6, 0x15, 0x33, 0x4E, 0xBB, 0xE7, 0x32, 0xE9,
  42106. 0x52, 0x20, 0x21, 0x39, 0x94, 0xD3, 0xBD, 0xC4,
  42107. 0x43, 0xC8, 0xEF, 0x94, 0xAD, 0x51, 0x5F, 0x45,
  42108. 0x41, 0x83, 0x55, 0x18, 0x33, 0x14, 0x48, 0x58,
  42109. 0x57, 0xAC, 0x12, 0xBA, 0x1D, 0x62, 0xCF, 0x4F,
  42110. 0xD4, 0xF4, 0xDE, 0x2A, 0x7F, 0xFF, 0x1E, 0xCF,
  42111. 0x0D, 0x29, 0x0C, 0x4C, 0xDF, 0xFA, 0x88, 0xD8,
  42112. 0xF4, 0x8C, 0x5B, 0x83, 0x7D, 0x3A, 0x94, 0xCD,
  42113. 0x17, 0xB3, 0xD1, 0x69, 0x96, 0x6E, 0xB0, 0x38,
  42114. 0xFE, 0x5A, 0x6E, 0x85, 0xDF, 0xC6, 0x0A, 0x00,
  42115. 0x23, 0x3F, 0x10, 0x73, 0x19, 0x73, 0xDC, 0x47,
  42116. 0x5D, 0x53, 0xBC, 0x7B, 0x9E, 0x60, 0x32, 0x0B,
  42117. 0xA7, 0x90, 0x5D, 0x88, 0x51, 0x9F, 0xA3, 0x25,
  42118. 0xDF, 0x5A, 0xB0, 0x2B, 0x40, 0xF2, 0xAB, 0xBD,
  42119. 0xB3, 0x7D, 0x22, 0x61, 0xCB, 0x81, 0x48, 0x27,
  42120. 0x7B, 0x87, 0xAE, 0x32, 0x97, 0x97, 0x6C, 0x80,
  42121. 0xC3, 0x51, 0x34, 0xE5, 0xF7, 0x86, 0x90, 0x45,
  42122. 0x64, 0xC1, 0x46, 0x99, 0x47, 0xF6, 0x20, 0xFE,
  42123. 0x09, 0xFD, 0xF3, 0x86, 0x2C, 0x40, 0x57, 0xA3,
  42124. 0xBC, 0xEF, 0x70, 0x75, 0x0C, 0xB7, 0x27, 0xF0,
  42125. 0x31, 0x28, 0x3A, 0x18, 0x26, 0xF1, 0x38, 0x1B,
  42126. 0x33, 0x48, 0xE3, 0xEA, 0x46, 0x88, 0x60, 0x9E,
  42127. 0xCB, 0x19, 0x3A, 0xFA, 0xAE, 0xE1, 0xCD, 0x97,
  42128. 0xE4, 0xDD, 0xAA, 0x02, 0xC0, 0xC3, 0x0E, 0x49,
  42129. 0xF1, 0x37, 0xD0, 0x82, 0x85, 0x94, 0x15, 0x28,
  42130. 0x10, 0x17, 0x59, 0xA7, 0x42, 0x2A, 0xA4, 0x99,
  42131. 0xC9, 0x00, 0xA3, 0x79, 0xDD, 0x73, 0xB3, 0x07,
  42132. 0x28, 0x4C, 0xCD, 0xDA, 0xF1, 0xFA, 0x1B, 0x0C,
  42133. 0x4B, 0x28, 0x0E, 0x3F, 0x9F, 0x1D, 0xB6, 0xD3,
  42134. 0x8E, 0xCF, 0x8A, 0x84, 0x1F, 0x9D, 0x4E, 0x40,
  42135. 0xEC, 0xA8, 0x62, 0x47, 0xD6, 0xCD, 0x9B, 0x31,
  42136. 0xEA, 0xCD, 0x6A, 0x46, 0xF0, 0xE3, 0x33, 0xB9,
  42137. 0xE8, 0x3D, 0x69, 0x0D, 0x7E, 0x13, 0x46, 0x76,
  42138. 0x19, 0xB4, 0x6A, 0xF9, 0xAF, 0xCF, 0xDC, 0x4A,
  42139. 0xA9, 0xA0, 0x49, 0xB1, 0x80, 0x26, 0x0D, 0x70,
  42140. 0xD9, 0xEE, 0xDB, 0x8A, 0x53, 0x30, 0x51, 0xAB,
  42141. 0x83, 0x51, 0x7A, 0xAD, 0xC2, 0xCD, 0x90, 0x0B,
  42142. 0x3E, 0xA5, 0x12, 0x60, 0xF4, 0x64, 0xAF, 0xC5,
  42143. 0xD2, 0xDC, 0x41, 0x10, 0x29, 0x77, 0x9B, 0x21,
  42144. 0xCE, 0x2C, 0xBD, 0x16, 0x02, 0x18, 0xDF, 0x41,
  42145. 0xF6, 0x61, 0xDA, 0x1A, 0xD9, 0x5A, 0xD4, 0x0B,
  42146. 0x8C, 0x35, 0x3C, 0x7F, 0x10, 0xFC, 0x23, 0xF8,
  42147. 0x30, 0xD1, 0x17, 0xBC, 0xAE, 0xF8, 0xCE, 0xCE,
  42148. 0xBC, 0xBF, 0xA4, 0x9D, 0x79, 0xD8, 0xD9, 0x39,
  42149. 0x1E, 0x8D, 0x08, 0x28, 0x1F, 0x00, 0x0A, 0x55,
  42150. 0xE9, 0x2D, 0xB3, 0x31, 0xBD, 0xEC, 0xD7, 0x31,
  42151. 0x83, 0xE0, 0x58, 0xFF, 0x3F, 0xE5, 0x83, 0x9A,
  42152. 0xF5, 0x0D, 0x8C, 0x55, 0xF2, 0x2F, 0x6A, 0xFF,
  42153. 0x5A, 0x33, 0xDA, 0x77, 0x4B, 0xA1, 0xB3, 0xE6,
  42154. 0x43, 0xF5, 0x87, 0x7C, 0xF5, 0x49, 0xC4, 0xF9,
  42155. 0x08, 0xEA, 0x64, 0xA3, 0x7D, 0xF3, 0xBF, 0xA4,
  42156. 0xCD, 0x5F, 0x70, 0xF8, 0xCD, 0x15, 0x44, 0x76,
  42157. 0xD3, 0x4B, 0xC8, 0x53, 0xC9, 0xE8, 0xF7, 0x97,
  42158. 0x9E, 0x5F, 0x4E, 0xBB, 0x88, 0x8A, 0xF7, 0x61
  42159. };
  42160. static const byte msg_87[] = {
  42161. 0x4A, 0xC4, 0x67, 0x5C, 0x96, 0xD9, 0x11, 0x7D,
  42162. 0x1E, 0xDE, 0xB8, 0x0D, 0x7C, 0xD2, 0x84, 0xA3,
  42163. 0xE1, 0xE1, 0xFE, 0x03, 0x8E, 0x30, 0x12, 0x05,
  42164. 0xB4, 0xC4, 0x08, 0xEB, 0x96, 0x52, 0x35, 0xAD,
  42165. 0x1C, 0x85, 0xF8, 0xBE, 0x3F, 0x77, 0xCA, 0x48,
  42166. 0x6F, 0xD2, 0x07, 0xF7, 0xC7, 0x5F, 0x41, 0x21,
  42167. 0xCD, 0x3C, 0xA2, 0xB2, 0x3D, 0x6B, 0xCE, 0x43,
  42168. 0x82, 0xA6, 0xD3, 0x61, 0x21, 0x81, 0x50, 0x25,
  42169. 0xD5, 0x80, 0x6C, 0xBE, 0xF4, 0x52, 0xE0, 0x83,
  42170. 0x93, 0x3C, 0x6E, 0x5C, 0x73, 0x94, 0xAC, 0x88,
  42171. 0x26, 0x2A, 0x6D, 0xE7, 0x77, 0x0B, 0x2D, 0x88,
  42172. 0x43, 0xEC, 0x10, 0x1F, 0xFB, 0x5E, 0x84, 0xDE,
  42173. 0x2F, 0x7A, 0x8B, 0x74, 0xE7, 0x67, 0x4B, 0x3B,
  42174. 0x23, 0x19, 0xBD, 0x6B, 0xF4, 0x11, 0x2F, 0x92,
  42175. 0xC5, 0xCF, 0xC0, 0xA5, 0x5F, 0x7F, 0xA0, 0x61,
  42176. 0xF4, 0x53, 0x25, 0x40, 0x8D, 0x03, 0x9D, 0x51
  42177. };
  42178. static const byte sig_87[] = {
  42179. 0x4B, 0x3F, 0x52, 0xF0, 0x81, 0xB3, 0xD9, 0x14,
  42180. 0xBC, 0x7C, 0x6C, 0x07, 0x3B, 0x18, 0x2B, 0x26,
  42181. 0x8A, 0xDF, 0x51, 0x89, 0xE2, 0x98, 0xA8, 0x69,
  42182. 0xBF, 0xB9, 0x91, 0xB1, 0x99, 0x99, 0x3C, 0x10,
  42183. 0x42, 0xDE, 0xF5, 0xB5, 0x92, 0x70, 0xB6, 0xCD,
  42184. 0x3F, 0xF8, 0xF9, 0x07, 0xA1, 0xCB, 0x0D, 0x3B,
  42185. 0x6F, 0xED, 0xCA, 0x14, 0x38, 0x38, 0xF8, 0xF8,
  42186. 0x1E, 0x0C, 0x37, 0x0F, 0xFE, 0xEE, 0x6B, 0x25,
  42187. 0xCD, 0x07, 0x03, 0x56, 0x41, 0xA0, 0x51, 0x94,
  42188. 0x4E, 0xAB, 0x51, 0x6C, 0xFB, 0xB8, 0x01, 0x53,
  42189. 0x6B, 0x4F, 0x26, 0x2B, 0x16, 0x19, 0x8E, 0x7D,
  42190. 0xDB, 0x1D, 0x61, 0xC3, 0x5A, 0x64, 0xD9, 0x0D,
  42191. 0x39, 0x48, 0xCE, 0xAA, 0xC8, 0xEE, 0x58, 0x0D,
  42192. 0xCE, 0xF5, 0x40, 0xED, 0x99, 0xD9, 0x12, 0xBB,
  42193. 0xA2, 0xBC, 0x4F, 0x51, 0x45, 0xBB, 0x94, 0x9C,
  42194. 0x73, 0xCC, 0xBD, 0x58, 0x26, 0x13, 0xB1, 0x0E,
  42195. 0xAA, 0xE8, 0x63, 0xAC, 0xA3, 0x46, 0x83, 0xEB,
  42196. 0x92, 0x2B, 0x3D, 0xAD, 0xFC, 0x74, 0xF7, 0x6F,
  42197. 0x47, 0xE4, 0x97, 0x86, 0x02, 0x59, 0x24, 0x02,
  42198. 0xD9, 0x15, 0x43, 0x94, 0xEB, 0x09, 0xFB, 0xC2,
  42199. 0xEB, 0xCC, 0xC5, 0x94, 0x73, 0x2F, 0x2D, 0x8B,
  42200. 0xC3, 0x83, 0x50, 0xE5, 0x53, 0x5A, 0x44, 0x12,
  42201. 0xA7, 0x7A, 0xDD, 0x79, 0x16, 0x60, 0x45, 0x76,
  42202. 0xFD, 0x6A, 0x36, 0x31, 0xE5, 0x15, 0xBA, 0xF2,
  42203. 0x6A, 0x6F, 0x9C, 0xA4, 0x06, 0x1E, 0xBB, 0xDD,
  42204. 0x3B, 0xEC, 0x71, 0x79, 0xAD, 0x58, 0x55, 0x2A,
  42205. 0x5B, 0x50, 0x8F, 0x31, 0x34, 0x8A, 0x56, 0xAD,
  42206. 0x1A, 0xDA, 0x7A, 0x05, 0x35, 0x2C, 0x72, 0xC0,
  42207. 0x04, 0xB9, 0x4C, 0x47, 0xE7, 0x04, 0x9A, 0x10,
  42208. 0xB3, 0xA5, 0x9B, 0xF2, 0x38, 0xA8, 0xDF, 0xC6,
  42209. 0xC7, 0x01, 0x9A, 0x17, 0xF0, 0x5D, 0x5B, 0xFC,
  42210. 0xB9, 0xD9, 0x3D, 0x9D, 0x1C, 0xCB, 0xCB, 0x47,
  42211. 0xF8, 0xC4, 0x38, 0x09, 0x8F, 0xDB, 0xDF, 0xE2,
  42212. 0x3F, 0x9F, 0x78, 0xBC, 0x28, 0x06, 0x99, 0x08,
  42213. 0xC6, 0xB9, 0x89, 0x8B, 0x43, 0x4C, 0xBF, 0x37,
  42214. 0x78, 0x7E, 0x1A, 0xF6, 0xA6, 0xB8, 0x27, 0xE8,
  42215. 0x30, 0xE9, 0xF7, 0x62, 0x9C, 0xD8, 0xF5, 0x10,
  42216. 0x70, 0xC4, 0xC8, 0xA8, 0xDE, 0xB2, 0x60, 0xD0,
  42217. 0x7C, 0x3E, 0x41, 0xD8, 0x49, 0x04, 0x84, 0x87,
  42218. 0x74, 0x91, 0xB3, 0x9A, 0xA6, 0xD9, 0xE1, 0x0D,
  42219. 0x91, 0x74, 0x8B, 0x64, 0xE3, 0x31, 0x60, 0x62,
  42220. 0x9D, 0x8A, 0xE4, 0x3E, 0xFD, 0x5F, 0x85, 0x78,
  42221. 0x1E, 0x69, 0xF7, 0x6B, 0x68, 0x95, 0xC1, 0x41,
  42222. 0xEB, 0xCD, 0xDF, 0xEE, 0xB4, 0x85, 0xA0, 0x0B,
  42223. 0xDB, 0xA4, 0xF7, 0xC9, 0x91, 0xF5, 0x3F, 0x2F,
  42224. 0x84, 0x93, 0x39, 0x26, 0xAF, 0x39, 0xE6, 0x96,
  42225. 0x4A, 0xBF, 0x2D, 0xFE, 0xBB, 0xC1, 0x9A, 0x7E,
  42226. 0x31, 0xC5, 0x07, 0x97, 0xB8, 0xDA, 0x29, 0x31,
  42227. 0xE1, 0x0F, 0x3D, 0xAC, 0x49, 0x3F, 0x19, 0x8D,
  42228. 0xFD, 0x78, 0x5D, 0x21, 0xAD, 0xB2, 0xC0, 0x62,
  42229. 0xB0, 0x97, 0xE8, 0x89, 0xA2, 0x07, 0x37, 0xF1,
  42230. 0x86, 0x00, 0x8F, 0x29, 0x28, 0xF6, 0xB8, 0x4D,
  42231. 0x6E, 0x09, 0xE9, 0x75, 0xA8, 0xF2, 0xAA, 0xAD,
  42232. 0xC7, 0x85, 0x23, 0x42, 0x34, 0xFD, 0xA0, 0x37,
  42233. 0x03, 0xA7, 0xC2, 0x1F, 0x81, 0x2D, 0x65, 0x0B,
  42234. 0xD2, 0x51, 0x0B, 0x30, 0xF0, 0x55, 0x00, 0x81,
  42235. 0x04, 0x7A, 0x15, 0x5C, 0x84, 0x85, 0x86, 0xA9,
  42236. 0x6F, 0x10, 0x0D, 0x77, 0x4F, 0x3E, 0x39, 0xE0,
  42237. 0x29, 0xB0, 0x77, 0x7C, 0xD3, 0x3E, 0x68, 0x31,
  42238. 0x8A, 0x11, 0xC1, 0x98, 0x02, 0x93, 0xFA, 0xD3,
  42239. 0xE7, 0x87, 0xD2, 0x0D, 0xFE, 0x7E, 0xEE, 0x70,
  42240. 0x53, 0xC0, 0x5E, 0xEB, 0x6A, 0x15, 0x9B, 0xAA,
  42241. 0xD4, 0x02, 0x0B, 0x9E, 0xC3, 0xF5, 0x37, 0xDA,
  42242. 0x4D, 0xAD, 0xAF, 0xB3, 0xB1, 0xBB, 0x1D, 0xBE,
  42243. 0xB2, 0xD5, 0xB8, 0xF9, 0xD0, 0x5A, 0x01, 0x97,
  42244. 0x98, 0xEA, 0xE0, 0xED, 0x09, 0x9D, 0xB0, 0x66,
  42245. 0xD7, 0x3E, 0xE8, 0xE9, 0xA5, 0x6D, 0xE3, 0x68,
  42246. 0xE8, 0x78, 0xA7, 0xFF, 0x39, 0x14, 0x0D, 0x80,
  42247. 0x21, 0xD5, 0x00, 0x85, 0xE6, 0x25, 0x29, 0x41,
  42248. 0xAB, 0x31, 0x53, 0x09, 0xCB, 0x53, 0xAA, 0xA4,
  42249. 0x9E, 0x86, 0x34, 0x7F, 0xBA, 0xD5, 0x4A, 0x1F,
  42250. 0x87, 0x3E, 0x0C, 0xB4, 0xB8, 0x6A, 0x8D, 0x5B,
  42251. 0x1B, 0x2A, 0x95, 0xD4, 0x85, 0xF3, 0x7A, 0x9F,
  42252. 0xB6, 0x10, 0x5D, 0xF8, 0x44, 0x0F, 0xDB, 0x85,
  42253. 0x78, 0xF2, 0x62, 0x4C, 0x07, 0x93, 0x29, 0x56,
  42254. 0x9A, 0x75, 0xF3, 0x6F, 0x2C, 0x55, 0xD8, 0xD0,
  42255. 0x30, 0xFB, 0xFE, 0xAA, 0x88, 0x89, 0xAD, 0x74,
  42256. 0x6C, 0x32, 0x3B, 0x1A, 0xC4, 0xEC, 0x8C, 0x40,
  42257. 0x3E, 0x77, 0x5A, 0x6F, 0xBE, 0x59, 0x6E, 0x7E,
  42258. 0x6A, 0x5A, 0x28, 0x63, 0x57, 0x66, 0x25, 0x14,
  42259. 0x99, 0x40, 0x97, 0x6F, 0x7C, 0xC9, 0x36, 0x17,
  42260. 0xB4, 0x3F, 0xB1, 0x34, 0x89, 0x07, 0x4E, 0xCA,
  42261. 0xC5, 0xBE, 0xB1, 0xA4, 0xDF, 0xE5, 0x8B, 0x9A,
  42262. 0xD2, 0xE0, 0xC6, 0xA1, 0x5B, 0x76, 0xA7, 0xC2,
  42263. 0xD2, 0x08, 0x72, 0x5A, 0x31, 0x23, 0xCA, 0x4E,
  42264. 0x6F, 0x2C, 0x58, 0x47, 0xEE, 0x5F, 0xA8, 0x38,
  42265. 0x49, 0x19, 0xEF, 0x89, 0x01, 0x1D, 0x21, 0x9B,
  42266. 0x25, 0x7B, 0x3E, 0x4D, 0xC4, 0xF2, 0x09, 0x51,
  42267. 0x60, 0x84, 0x4C, 0xAE, 0xEA, 0xFC, 0xF8, 0x57,
  42268. 0x26, 0x0F, 0x1C, 0x63, 0xD3, 0xB0, 0x5A, 0x67,
  42269. 0xD3, 0xD0, 0xF2, 0xB0, 0xEC, 0x9D, 0xCC, 0x27,
  42270. 0x23, 0xF1, 0x37, 0x55, 0x75, 0x0B, 0xAE, 0x62,
  42271. 0xFC, 0xC3, 0x61, 0xCF, 0xB5, 0x84, 0xF7, 0x74,
  42272. 0xC0, 0x9A, 0xDF, 0x9A, 0x04, 0x31, 0xB2, 0x3E,
  42273. 0x48, 0x8C, 0x35, 0x9C, 0x0A, 0xEF, 0x5B, 0x1C,
  42274. 0x97, 0x87, 0xBD, 0x8F, 0x52, 0xB0, 0x83, 0xBC,
  42275. 0x9D, 0xBC, 0xC9, 0xB3, 0x03, 0x9F, 0x77, 0x7C,
  42276. 0x7E, 0x8E, 0xAB, 0xC8, 0x00, 0x78, 0x05, 0x0C,
  42277. 0xE6, 0xD4, 0x9C, 0x3B, 0xB7, 0x01, 0x68, 0xFA,
  42278. 0x21, 0x77, 0x29, 0x8F, 0xB0, 0xA8, 0xF7, 0x2C,
  42279. 0x1C, 0xD2, 0x8D, 0x66, 0x2A, 0x07, 0xDA, 0xE6,
  42280. 0xC7, 0xAC, 0xB7, 0xFB, 0x8E, 0x7F, 0xDD, 0x01,
  42281. 0xDF, 0xB2, 0x7C, 0x62, 0xEE, 0x68, 0x3F, 0x4E,
  42282. 0x5F, 0x88, 0xC7, 0xC1, 0xDD, 0xDD, 0x5E, 0xEC,
  42283. 0xC1, 0xC3, 0xAF, 0x85, 0x3F, 0x1F, 0xF6, 0xB1,
  42284. 0xD9, 0xDE, 0x67, 0x2F, 0x1B, 0xF6, 0x47, 0x3A,
  42285. 0xF0, 0x02, 0x1D, 0x8A, 0x3D, 0x4D, 0xD0, 0x4A,
  42286. 0x2F, 0xCA, 0x23, 0x25, 0xC7, 0x21, 0xCF, 0x1C,
  42287. 0x82, 0x16, 0x76, 0xD0, 0xA0, 0xD5, 0x74, 0x18,
  42288. 0x66, 0x25, 0xDE, 0x83, 0x1C, 0x84, 0x11, 0xF6,
  42289. 0x41, 0x79, 0xF9, 0x16, 0x7F, 0x78, 0xBC, 0xB2,
  42290. 0x2F, 0xB4, 0x1C, 0x2C, 0xDB, 0x63, 0xC4, 0xDB,
  42291. 0x5E, 0x13, 0x87, 0x66, 0xD3, 0x80, 0x35, 0x89,
  42292. 0x59, 0x8F, 0x11, 0x4F, 0x41, 0xBA, 0x42, 0xCD,
  42293. 0xB1, 0x34, 0x10, 0x20, 0x44, 0x9B, 0xA9, 0x96,
  42294. 0x56, 0x11, 0x39, 0x90, 0xB4, 0xE0, 0x22, 0xD8,
  42295. 0xDA, 0x20, 0xD7, 0x44, 0x49, 0x1C, 0x6E, 0xEA,
  42296. 0xB6, 0x7B, 0x91, 0x8E, 0x80, 0xFF, 0xF3, 0x43,
  42297. 0xCC, 0x5B, 0x4C, 0x8E, 0x58, 0xC3, 0x48, 0x4B,
  42298. 0x01, 0x25, 0xA6, 0x0C, 0x36, 0xAE, 0xF7, 0x63,
  42299. 0x89, 0x4D, 0x35, 0x14, 0x8B, 0x57, 0x8F, 0x41,
  42300. 0x7C, 0x3A, 0x98, 0xA1, 0x43, 0xED, 0xFE, 0x9F,
  42301. 0x8C, 0x95, 0xBC, 0xC3, 0x46, 0xC6, 0xF5, 0xEA,
  42302. 0xF9, 0x7A, 0xAD, 0x11, 0xDA, 0xE0, 0x1C, 0x47,
  42303. 0x7C, 0x22, 0x7A, 0x88, 0xD1, 0x0E, 0xCF, 0xDC,
  42304. 0xF4, 0x50, 0xB3, 0x7F, 0x88, 0x19, 0x68, 0x02,
  42305. 0x78, 0x49, 0xD9, 0xB4, 0x3E, 0x2B, 0xFF, 0x90,
  42306. 0xC6, 0xA3, 0x4A, 0xE4, 0x1B, 0x8B, 0xBD, 0x74,
  42307. 0x30, 0x83, 0xD3, 0xC5, 0x87, 0x86, 0xB0, 0x36,
  42308. 0x67, 0x1C, 0xD6, 0xEE, 0xD9, 0x4D, 0xAE, 0x51,
  42309. 0xF7, 0x61, 0x32, 0x47, 0xEF, 0x86, 0x07, 0xAC,
  42310. 0xF7, 0x4A, 0x3C, 0xCE, 0x93, 0x2F, 0x1C, 0x38,
  42311. 0x69, 0xBD, 0xB3, 0x5C, 0xA1, 0x7F, 0xC6, 0xBA,
  42312. 0x9F, 0x9C, 0x95, 0x6F, 0xF1, 0xD4, 0xD8, 0x80,
  42313. 0x94, 0x32, 0x5C, 0xAB, 0xCE, 0x41, 0x23, 0x3F,
  42314. 0xB1, 0xD8, 0x08, 0xEF, 0x41, 0x01, 0x03, 0x96,
  42315. 0xDE, 0xB0, 0xEC, 0xF5, 0x07, 0x34, 0xD8, 0x18,
  42316. 0xDD, 0xAB, 0x70, 0x01, 0x5A, 0x0A, 0xBD, 0xD1,
  42317. 0x92, 0x6D, 0xFA, 0x49, 0x1F, 0x71, 0x1A, 0xA8,
  42318. 0x5D, 0xA2, 0xA8, 0xEC, 0x60, 0xE3, 0x25, 0x5C,
  42319. 0xCF, 0x97, 0x5C, 0x23, 0xCC, 0x4E, 0x8D, 0xAF,
  42320. 0xDD, 0xED, 0x9F, 0xEC, 0x60, 0xA6, 0x46, 0x7C,
  42321. 0x45, 0xB0, 0x3C, 0xA4, 0x76, 0x49, 0x9A, 0xA3,
  42322. 0x31, 0xB0, 0xE3, 0x99, 0x95, 0x76, 0xCE, 0xC3,
  42323. 0x19, 0x1A, 0x9A, 0x62, 0xBC, 0x1B, 0xEA, 0xC1,
  42324. 0xEA, 0xF2, 0x0E, 0x18, 0xCF, 0xC3, 0x21, 0x61,
  42325. 0x27, 0xDE, 0x4A, 0xAE, 0x2E, 0x75, 0x20, 0x1F,
  42326. 0x9E, 0x42, 0x7E, 0x39, 0xBF, 0x92, 0x11, 0x50,
  42327. 0xEA, 0xB9, 0x49, 0x55, 0x9C, 0x02, 0x2D, 0x87,
  42328. 0x6F, 0xA2, 0x42, 0xC2, 0xA8, 0x45, 0xBC, 0xA7,
  42329. 0x23, 0x5F, 0x72, 0x1B, 0x00, 0x56, 0x78, 0x8A,
  42330. 0x44, 0xEC, 0xC3, 0xEB, 0x98, 0xF0, 0xF5, 0x02,
  42331. 0xB8, 0x9F, 0x8E, 0x74, 0x10, 0xEA, 0x56, 0x79,
  42332. 0xAE, 0x7C, 0x04, 0x34, 0xF1, 0x3A, 0xD8, 0x16,
  42333. 0x42, 0x1D, 0x2F, 0xEE, 0x30, 0xCB, 0xCB, 0x2D,
  42334. 0xAA, 0x6B, 0x85, 0x1C, 0xD1, 0xB6, 0xE9, 0x96,
  42335. 0xDA, 0x7A, 0x75, 0x7E, 0x4C, 0x4D, 0x85, 0x72,
  42336. 0xC8, 0xB6, 0x00, 0xDE, 0x85, 0xDD, 0xB6, 0x53,
  42337. 0x20, 0xD1, 0xCB, 0x71, 0xD9, 0x37, 0x83, 0x49,
  42338. 0xC0, 0xC4, 0x01, 0xAD, 0x4F, 0x9E, 0x91, 0x27,
  42339. 0x21, 0x39, 0x22, 0x8A, 0x8D, 0xA2, 0xF4, 0xFD,
  42340. 0x2F, 0x48, 0x89, 0x1A, 0x4D, 0xCB, 0x06, 0x6D,
  42341. 0x50, 0x1D, 0x44, 0x74, 0x83, 0xB6, 0x11, 0xBB,
  42342. 0x3C, 0x80, 0x55, 0x0A, 0x90, 0xEA, 0x0B, 0x73,
  42343. 0x2D, 0x63, 0x9D, 0x8B, 0x39, 0x26, 0xB6, 0xE7,
  42344. 0xC3, 0x54, 0x53, 0xED, 0x3C, 0xC1, 0x10, 0xBA,
  42345. 0xF5, 0x56, 0xCF, 0x46, 0xD8, 0xFC, 0x21, 0x77,
  42346. 0xE7, 0x6F, 0xB2, 0x66, 0x3B, 0x8B, 0xDD, 0x17,
  42347. 0x1E, 0x94, 0xC0, 0xAC, 0xAF, 0x25, 0xB9, 0x15,
  42348. 0x3B, 0x22, 0xBC, 0xA7, 0x49, 0x91, 0x67, 0x56,
  42349. 0xFB, 0x3E, 0xD3, 0x01, 0x8E, 0x09, 0x44, 0xB6,
  42350. 0xC3, 0xB9, 0xB6, 0xBF, 0xA1, 0x5B, 0x9B, 0xE8,
  42351. 0x03, 0xAC, 0x79, 0x33, 0x3C, 0xD2, 0xC3, 0xA2,
  42352. 0x7A, 0x26, 0xBC, 0x17, 0xCD, 0xA2, 0x57, 0x79,
  42353. 0x8A, 0xE1, 0x6B, 0x28, 0xB4, 0x63, 0xB6, 0xDF,
  42354. 0x3F, 0xA8, 0x7C, 0x2D, 0x74, 0x2D, 0x0F, 0x68,
  42355. 0x85, 0xBE, 0xE0, 0xBE, 0xC6, 0xE2, 0x0D, 0x01,
  42356. 0xE5, 0xDA, 0xDC, 0x86, 0x82, 0x3E, 0x92, 0xD6,
  42357. 0x0F, 0xEC, 0x79, 0xB0, 0xD2, 0x40, 0x24, 0x87,
  42358. 0x53, 0xE4, 0x20, 0x48, 0x38, 0x4C, 0x80, 0x42,
  42359. 0x89, 0x60, 0x48, 0x21, 0xA5, 0x7F, 0x4F, 0x9F,
  42360. 0x50, 0xAE, 0x0C, 0x38, 0x52, 0x7F, 0xE5, 0xA3,
  42361. 0x49, 0x38, 0xDD, 0xBC, 0xDC, 0xD9, 0xA1, 0xD0,
  42362. 0x20, 0x83, 0x9B, 0xEB, 0xB6, 0x2F, 0x9F, 0x41,
  42363. 0xFB, 0xA0, 0x80, 0x52, 0xAB, 0xB8, 0x2F, 0xAD,
  42364. 0xA8, 0x84, 0xCB, 0xE5, 0x63, 0x79, 0x11, 0x03,
  42365. 0xAA, 0x58, 0x55, 0x46, 0xEB, 0xFE, 0xB1, 0x12,
  42366. 0x72, 0xCC, 0x2E, 0x87, 0xA3, 0xB7, 0x5B, 0x3C,
  42367. 0x6B, 0xB1, 0x85, 0x3A, 0xE7, 0xF9, 0xCF, 0x55,
  42368. 0x85, 0xB2, 0x65, 0x3C, 0xF5, 0xEE, 0xA2, 0x44,
  42369. 0xD2, 0x04, 0xEB, 0x26, 0x9C, 0x56, 0xA2, 0x09,
  42370. 0x85, 0x16, 0x06, 0x59, 0xCB, 0x07, 0x25, 0xEE,
  42371. 0x13, 0xCE, 0x35, 0xD5, 0x5E, 0xB0, 0x95, 0xA5,
  42372. 0x34, 0x14, 0xF2, 0x32, 0xDF, 0x81, 0x08, 0xB1,
  42373. 0x80, 0x24, 0xEB, 0x0D, 0xBF, 0x34, 0x5E, 0xB5,
  42374. 0xCD, 0xAD, 0x0B, 0xCE, 0x72, 0x63, 0x50, 0x9A,
  42375. 0x34, 0x1D, 0x54, 0xA7, 0xD5, 0x34, 0xE5, 0x53,
  42376. 0xEA, 0xEF, 0xFE, 0x4E, 0x24, 0x2E, 0xA2, 0x3B,
  42377. 0xCF, 0xE5, 0x9A, 0x58, 0xA6, 0x04, 0x25, 0x88,
  42378. 0x2C, 0xB7, 0xE3, 0xB0, 0xC9, 0xE4, 0xAF, 0xE8,
  42379. 0x69, 0x8E, 0x3D, 0xF5, 0x6A, 0xFD, 0x6D, 0x61,
  42380. 0x1E, 0x91, 0x68, 0x74, 0x7D, 0x87, 0x35, 0xCF,
  42381. 0x92, 0x46, 0xD9, 0x4F, 0x21, 0x26, 0xBE, 0x72,
  42382. 0x7F, 0xB4, 0x2B, 0x22, 0x41, 0xA8, 0x3B, 0x34,
  42383. 0xF0, 0xB9, 0xEB, 0x47, 0x93, 0x8D, 0x72, 0x65,
  42384. 0x02, 0xC5, 0x4E, 0x45, 0x72, 0x76, 0x63, 0x31,
  42385. 0x62, 0x8F, 0xA5, 0xCD, 0xA8, 0x93, 0xC3, 0x53,
  42386. 0x76, 0xAB, 0x45, 0x38, 0xFF, 0x87, 0x17, 0xC2,
  42387. 0x79, 0x5B, 0x0F, 0x51, 0xF0, 0x8E, 0x11, 0x37,
  42388. 0x61, 0x2B, 0x89, 0xB0, 0xC1, 0xE2, 0xCD, 0x1F,
  42389. 0x09, 0x9E, 0x88, 0x55, 0x69, 0x23, 0xAE, 0x57,
  42390. 0xA1, 0xDA, 0xD2, 0xAF, 0xB1, 0x23, 0x0B, 0x50,
  42391. 0x94, 0xA1, 0xB2, 0x1B, 0xAD, 0x7D, 0xBB, 0xC3,
  42392. 0x33, 0xA9, 0x7F, 0x17, 0x93, 0x04, 0x71, 0x8F,
  42393. 0x32, 0x89, 0xB6, 0xDE, 0x31, 0x31, 0x5B, 0x74,
  42394. 0xC1, 0xA7, 0x3A, 0xC7, 0x75, 0x6F, 0xAA, 0x4D,
  42395. 0x7E, 0xB5, 0x68, 0xBB, 0xC6, 0xF7, 0xE7, 0x88,
  42396. 0xCD, 0x08, 0x9B, 0x39, 0x55, 0x64, 0xD2, 0x17,
  42397. 0x6B, 0x00, 0x56, 0xDF, 0xFE, 0x95, 0x2C, 0x77,
  42398. 0x48, 0xB0, 0x48, 0x30, 0x67, 0x20, 0xF6, 0x02,
  42399. 0xB6, 0x7E, 0x8F, 0x6A, 0xDC, 0xC9, 0x1F, 0x8E,
  42400. 0x3A, 0xA4, 0xB8, 0xC4, 0xD7, 0xFA, 0xC2, 0x33,
  42401. 0xAA, 0xF9, 0x36, 0x53, 0xAD, 0x22, 0x09, 0xE2,
  42402. 0xFF, 0x92, 0xDA, 0x30, 0xC2, 0xD5, 0x3F, 0xDE,
  42403. 0xF6, 0xF4, 0xC9, 0x0E, 0xAA, 0x0D, 0xE6, 0x0D,
  42404. 0x59, 0x4A, 0xDA, 0x39, 0x15, 0xDB, 0x24, 0x27,
  42405. 0x9D, 0x86, 0x74, 0x76, 0xEA, 0xD7, 0x57, 0xB4,
  42406. 0xC0, 0x26, 0x4A, 0x1D, 0xB8, 0xA1, 0xF5, 0x7A,
  42407. 0x1B, 0x5D, 0x71, 0x73, 0xBB, 0x1A, 0x96, 0x0C,
  42408. 0xE0, 0x2F, 0xDE, 0xFE, 0xF1, 0x60, 0xD5, 0x12,
  42409. 0x66, 0x7D, 0x65, 0x52, 0x68, 0xFC, 0xC3, 0xA1,
  42410. 0x53, 0xA4, 0x31, 0x47, 0x82, 0xA0, 0xEB, 0xFF,
  42411. 0x84, 0xF6, 0x5F, 0x14, 0xA0, 0xE3, 0xE1, 0x2A,
  42412. 0x13, 0x25, 0x0C, 0x07, 0xD0, 0x8C, 0x22, 0x5B,
  42413. 0x11, 0xA6, 0x83, 0x1B, 0xC2, 0x5C, 0x40, 0x46,
  42414. 0x7B, 0x76, 0x80, 0x04, 0xDD, 0xE0, 0xE8, 0x74,
  42415. 0xA5, 0x11, 0x44, 0xC1, 0x89, 0x20, 0xBD, 0xF2,
  42416. 0x86, 0x09, 0x0B, 0x59, 0xF5, 0x15, 0x64, 0xEA,
  42417. 0x40, 0x70, 0xFB, 0xBF, 0x61, 0xE3, 0x69, 0x64,
  42418. 0x35, 0xF2, 0x8F, 0x63, 0x33, 0x2B, 0x64, 0x49,
  42419. 0x6D, 0xF3, 0xEC, 0x8B, 0x65, 0xD5, 0x4E, 0x1C,
  42420. 0xF4, 0x78, 0x9D, 0xDA, 0xB1, 0x22, 0xDA, 0x6B,
  42421. 0x26, 0x4D, 0x31, 0x2A, 0x71, 0x1C, 0x12, 0x9E,
  42422. 0x3B, 0x07, 0xF4, 0xC6, 0xDA, 0x25, 0xA5, 0x61,
  42423. 0x73, 0xAF, 0x58, 0xB9, 0x0A, 0x71, 0xB7, 0xAC,
  42424. 0xFA, 0x31, 0x61, 0xA8, 0x1F, 0x59, 0xD1, 0x79,
  42425. 0x14, 0xC9, 0x9B, 0xBA, 0xC4, 0xF9, 0xA3, 0x14,
  42426. 0x97, 0x7A, 0x89, 0xCE, 0xF7, 0x69, 0x69, 0x43,
  42427. 0x60, 0x9B, 0xB4, 0x82, 0x79, 0x64, 0xFB, 0x29,
  42428. 0x76, 0x40, 0x3B, 0xD4, 0x99, 0x6F, 0x1E, 0x84,
  42429. 0x2B, 0xF5, 0xAA, 0xAE, 0x1E, 0xCC, 0xA1, 0x12,
  42430. 0x55, 0xB9, 0xE6, 0x00, 0x1C, 0x20, 0xF7, 0x2F,
  42431. 0x1F, 0xD5, 0xE3, 0x2C, 0xDA, 0x32, 0xD8, 0xA7,
  42432. 0xAC, 0x5F, 0x62, 0xB0, 0x9A, 0x0E, 0x61, 0x58,
  42433. 0x47, 0xCA, 0x74, 0x6F, 0x48, 0x95, 0x15, 0xCF,
  42434. 0x8F, 0x18, 0x31, 0x62, 0x85, 0x9F, 0x53, 0xB9,
  42435. 0x7E, 0x9E, 0x5C, 0xA8, 0x00, 0xEE, 0x62, 0x4F,
  42436. 0x72, 0x98, 0x43, 0xA0, 0x00, 0x91, 0x64, 0xA4,
  42437. 0xA9, 0xFF, 0x76, 0xEB, 0x34, 0xE4, 0x70, 0x41,
  42438. 0x84, 0x84, 0x8A, 0x13, 0x9A, 0xD9, 0x7D, 0x90,
  42439. 0x9F, 0x7A, 0x7E, 0xD1, 0x14, 0xF0, 0x87, 0xA4,
  42440. 0xB2, 0xE1, 0xB4, 0xA3, 0x03, 0x23, 0x91, 0x16,
  42441. 0x0B, 0x6F, 0x3A, 0x36, 0x49, 0xFF, 0x15, 0xAE,
  42442. 0xA2, 0xB7, 0x10, 0x7A, 0xF8, 0xA3, 0xB5, 0xFC,
  42443. 0xAD, 0x61, 0xD4, 0x3D, 0x60, 0x2E, 0x62, 0x86,
  42444. 0xA9, 0x00, 0x87, 0x0C, 0xC8, 0xCE, 0x24, 0xE3,
  42445. 0x9E, 0x78, 0xF0, 0x39, 0x7A, 0x0D, 0x7E, 0x27,
  42446. 0xE8, 0xE2, 0xD4, 0x77, 0x6A, 0x44, 0xCB, 0xA2,
  42447. 0x18, 0xEB, 0xCD, 0x88, 0xB3, 0xC2, 0x8C, 0x18,
  42448. 0x2A, 0x7C, 0x9F, 0x4D, 0xBB, 0x2D, 0xBB, 0x5E,
  42449. 0x98, 0x15, 0x63, 0xD6, 0x6C, 0xEE, 0xB7, 0x7E,
  42450. 0x7F, 0x90, 0x34, 0xBD, 0x42, 0x9D, 0x27, 0x63,
  42451. 0x7C, 0xF7, 0x97, 0xDE, 0x82, 0xE0, 0x1F, 0xEB,
  42452. 0xBC, 0xE2, 0x17, 0x1E, 0xFD, 0x01, 0x6E, 0x40,
  42453. 0x2A, 0x42, 0xD7, 0x8E, 0xA1, 0xAC, 0xE2, 0xCB,
  42454. 0x37, 0x0E, 0x75, 0xC9, 0x0A, 0xDF, 0xA1, 0xA7,
  42455. 0x93, 0xB2, 0x16, 0x9C, 0xC2, 0x65, 0x22, 0xDB,
  42456. 0x2F, 0x54, 0x6A, 0xC1, 0xDE, 0x34, 0xC9, 0x08,
  42457. 0x71, 0x20, 0xC4, 0x2A, 0x9F, 0x10, 0xC0, 0x0D,
  42458. 0x49, 0x3C, 0x25, 0x73, 0x01, 0x66, 0xF9, 0xD2,
  42459. 0x19, 0xFB, 0xDA, 0xD2, 0x22, 0xC8, 0xB2, 0x81,
  42460. 0x15, 0x54, 0x33, 0x13, 0x21, 0x08, 0x48, 0xFB,
  42461. 0x2F, 0x04, 0xBF, 0xDC, 0xE1, 0x5D, 0x32, 0x0C,
  42462. 0x36, 0x34, 0xA8, 0xE4, 0xD6, 0x37, 0x55, 0x51,
  42463. 0x59, 0x00, 0xC7, 0x5B, 0xFD, 0x09, 0x0A, 0xD7,
  42464. 0x8D, 0xD5, 0x88, 0x65, 0x9F, 0xBF, 0x97, 0xC9,
  42465. 0x6E, 0x0D, 0x0A, 0xCC, 0x8E, 0x81, 0x5E, 0x60,
  42466. 0x8F, 0x9E, 0x86, 0x1D, 0x79, 0xAF, 0x30, 0x51,
  42467. 0xB9, 0x42, 0xB5, 0x25, 0x70, 0xB6, 0x29, 0x2B,
  42468. 0xF4, 0x8C, 0x2B, 0xFA, 0xA9, 0x07, 0x7D, 0xC7,
  42469. 0x6F, 0xE9, 0x02, 0x68, 0x32, 0x17, 0xB8, 0xBF,
  42470. 0x80, 0x9E, 0xD7, 0xA0, 0x05, 0x0A, 0xDD, 0xBB,
  42471. 0x65, 0xFD, 0xDF, 0xBD, 0x24, 0x01, 0x9C, 0x91,
  42472. 0x81, 0xB5, 0xAC, 0x81, 0x56, 0x61, 0x13, 0xD6,
  42473. 0x69, 0x4E, 0xA6, 0x29, 0x1D, 0x7F, 0x4A, 0x7F,
  42474. 0x56, 0xA4, 0x1E, 0xB9, 0x1F, 0x76, 0x36, 0x8D,
  42475. 0xF8, 0x2B, 0x16, 0x4B, 0x48, 0x59, 0x25, 0x9D,
  42476. 0x71, 0x89, 0x24, 0x0F, 0x1D, 0x88, 0x03, 0xF8,
  42477. 0x10, 0x72, 0x96, 0xD3, 0x78, 0xBA, 0xB4, 0xD2,
  42478. 0x4F, 0xE6, 0xD1, 0x0E, 0xF7, 0x88, 0x36, 0x7B,
  42479. 0xCE, 0x16, 0xC5, 0xAB, 0x77, 0xFB, 0xC1, 0x68,
  42480. 0xB8, 0x57, 0xF7, 0xBA, 0x5C, 0xDC, 0xBE, 0x50,
  42481. 0x67, 0xC8, 0x64, 0xF8, 0x79, 0x80, 0x9F, 0xE5,
  42482. 0x21, 0x7D, 0xEF, 0x02, 0x94, 0xBF, 0xAF, 0xDF,
  42483. 0x80, 0x9A, 0xBC, 0xE9, 0x53, 0x2D, 0xD9, 0xDA,
  42484. 0xB3, 0x44, 0x8F, 0x4D, 0xA6, 0x8E, 0xCA, 0x51,
  42485. 0x60, 0x94, 0x76, 0x27, 0x8E, 0xB8, 0xC4, 0xF6,
  42486. 0x9E, 0xA2, 0x96, 0x73, 0xF6, 0x94, 0x18, 0x04,
  42487. 0x1D, 0x26, 0x85, 0x7E, 0xBC, 0x24, 0xA4, 0x87,
  42488. 0xBB, 0x4B, 0x0B, 0xA6, 0x3A, 0xF8, 0x48, 0x54,
  42489. 0x5E, 0xE9, 0xBE, 0x89, 0xF1, 0x39, 0xD5, 0x02,
  42490. 0x09, 0x9B, 0x9D, 0x35, 0xDB, 0x38, 0x07, 0xB9,
  42491. 0x25, 0xCB, 0xA5, 0x76, 0xE2, 0x71, 0x70, 0xEA,
  42492. 0xEC, 0x48, 0xCC, 0x2C, 0xC1, 0x5B, 0x04, 0x36,
  42493. 0x77, 0x82, 0x5D, 0x0E, 0xE8, 0x1E, 0xB2, 0xCE,
  42494. 0xE3, 0xA8, 0xED, 0x14, 0xA7, 0x98, 0xB8, 0x79,
  42495. 0x53, 0x02, 0x20, 0xE5, 0x0C, 0xE8, 0xC0, 0x03,
  42496. 0xA3, 0x05, 0x38, 0x2A, 0x24, 0xD2, 0x3C, 0x27,
  42497. 0x7B, 0x99, 0xD1, 0xF4, 0xC5, 0x4F, 0x9A, 0x8D,
  42498. 0x33, 0xFA, 0x3D, 0x1E, 0x33, 0x7E, 0x18, 0xD7,
  42499. 0xCB, 0xBA, 0x5E, 0x5A, 0x47, 0xF2, 0xD5, 0xE0,
  42500. 0x96, 0xCF, 0x45, 0x51, 0xB2, 0x3B, 0x1B, 0x86,
  42501. 0x43, 0x6E, 0x81, 0xB4, 0xA0, 0x9D, 0x1E, 0x3D,
  42502. 0x38, 0x49, 0x2E, 0xC8, 0xB2, 0xA0, 0x09, 0x67,
  42503. 0x01, 0x6A, 0xB7, 0x6B, 0x9A, 0x9B, 0x18, 0x64,
  42504. 0x67, 0x14, 0x21, 0xDA, 0x56, 0xF5, 0x7D, 0x00,
  42505. 0x8D, 0x5C, 0xE1, 0xB8, 0x92, 0xA7, 0xE9, 0xC1,
  42506. 0xF6, 0x9F, 0x6C, 0x72, 0x2C, 0xF1, 0x09, 0xDB,
  42507. 0x50, 0x0E, 0x53, 0xF6, 0xBC, 0x07, 0x83, 0x7A,
  42508. 0xD1, 0xCD, 0x4C, 0xF4, 0xA6, 0x4D, 0xA7, 0x63,
  42509. 0xB4, 0xA9, 0xC4, 0x92, 0x9B, 0x0D, 0xCD, 0xDF,
  42510. 0x7C, 0x7E, 0x11, 0x86, 0xBE, 0x3F, 0xF0, 0xC3,
  42511. 0x21, 0x15, 0x84, 0x37, 0x82, 0x0C, 0x81, 0xE7,
  42512. 0x4F, 0xF3, 0x16, 0xAE, 0x32, 0x54, 0xE9, 0x72,
  42513. 0xFC, 0x19, 0x7A, 0x7F, 0x0E, 0x62, 0x02, 0x42,
  42514. 0xAC, 0x05, 0xA4, 0xE4, 0x3E, 0x98, 0x7C, 0x2A,
  42515. 0x83, 0x55, 0xB0, 0x35, 0x77, 0x45, 0xCA, 0x79,
  42516. 0xE6, 0xAE, 0x48, 0xAB, 0x29, 0xED, 0x4F, 0xA6,
  42517. 0x3D, 0x3A, 0x1F, 0x19, 0xB9, 0x99, 0xDE, 0x25,
  42518. 0x1F, 0xDE, 0x06, 0x40, 0xDD, 0x87, 0x87, 0x6D,
  42519. 0x55, 0x76, 0x28, 0x78, 0xAD, 0x1D, 0xB1, 0x2D,
  42520. 0x65, 0xBA, 0xFD, 0x14, 0xB6, 0xA9, 0xA7, 0x08,
  42521. 0x1B, 0xF2, 0x3F, 0x9F, 0x06, 0xD9, 0x0C, 0xE2,
  42522. 0x73, 0xC5, 0xA2, 0x6E, 0x01, 0x2C, 0xA9, 0x4D,
  42523. 0xD4, 0x81, 0xD3, 0x2E, 0x10, 0x93, 0x8C, 0x16,
  42524. 0x51, 0x63, 0xE8, 0x9B, 0xE8, 0xA9, 0x3A, 0x63,
  42525. 0x03, 0x4D, 0x34, 0x5B, 0x74, 0xE2, 0xA9, 0x4E,
  42526. 0xF6, 0x43, 0xD0, 0x6A, 0xF9, 0xE1, 0xF5, 0xC9,
  42527. 0xF1, 0x04, 0x93, 0x0D, 0xA0, 0x0E, 0x61, 0xE0,
  42528. 0x61, 0xEE, 0x8C, 0x3B, 0xB1, 0x7C, 0x11, 0xE0,
  42529. 0x5D, 0x45, 0xC1, 0x68, 0x2E, 0x4D, 0x59, 0x3C,
  42530. 0x91, 0x98, 0x23, 0x8D, 0x2B, 0xA2, 0x89, 0x77,
  42531. 0x9E, 0x7D, 0x0F, 0x22, 0x7B, 0xCB, 0x0B, 0x09,
  42532. 0x97, 0x2B, 0x19, 0x77, 0x0F, 0xF0, 0x11, 0xBF,
  42533. 0x6C, 0x60, 0xD9, 0xD1, 0x93, 0xCF, 0xAB, 0x32,
  42534. 0x74, 0x7A, 0x00, 0x95, 0xE1, 0xA4, 0xAD, 0x32,
  42535. 0x51, 0x4C, 0x78, 0x2E, 0xF3, 0xDE, 0x7A, 0x26,
  42536. 0xEA, 0x77, 0x1F, 0x55, 0x30, 0xD9, 0xDE, 0x97,
  42537. 0x36, 0xD0, 0xF6, 0xAE, 0x1A, 0xFB, 0x78, 0xEC,
  42538. 0x7C, 0xE4, 0x88, 0x4A, 0x1B, 0xB4, 0x36, 0xCF,
  42539. 0xCE, 0x45, 0x9C, 0xD9, 0x93, 0x58, 0x26, 0x09,
  42540. 0x06, 0xAA, 0xC9, 0x97, 0x16, 0xA5, 0x36, 0xCC,
  42541. 0x76, 0x87, 0xA0, 0x37, 0x5F, 0xDA, 0x11, 0x00,
  42542. 0x76, 0x18, 0xE5, 0x53, 0x53, 0x4E, 0x54, 0xD5,
  42543. 0xB2, 0x14, 0xF7, 0xAA, 0x6F, 0xC7, 0xDB, 0xE3,
  42544. 0x7C, 0x2B, 0xD2, 0xB6, 0x48, 0x50, 0xAE, 0x46,
  42545. 0x9A, 0x98, 0x58, 0x98, 0x7F, 0x3F, 0xA4, 0xB1,
  42546. 0xFD, 0x26, 0xD9, 0x54, 0xBF, 0xEC, 0x36, 0x5D,
  42547. 0xBE, 0x06, 0xDD, 0xCD, 0x61, 0x5E, 0x1F, 0xED,
  42548. 0x58, 0xA8, 0x86, 0x76, 0x40, 0x2D, 0x1D, 0x6B,
  42549. 0x58, 0x14, 0x85, 0x49, 0x8B, 0x5A, 0xDF, 0xFF,
  42550. 0xC4, 0x2D, 0x47, 0xD6, 0x1D, 0xF9, 0x93, 0x84,
  42551. 0xE2, 0x2C, 0x51, 0x57, 0xF0, 0x17, 0x8A, 0x6F,
  42552. 0xDA, 0xF8, 0xF4, 0xA9, 0x49, 0x1D, 0xAF, 0x29,
  42553. 0x8B, 0x2C, 0x3E, 0xC8, 0x80, 0x85, 0x02, 0x2C,
  42554. 0x0A, 0x7C, 0xF2, 0x45, 0xED, 0x0F, 0xB5, 0xA3,
  42555. 0x8C, 0xD1, 0x6F, 0x30, 0xD3, 0x7D, 0xA5, 0xC4,
  42556. 0x95, 0x9A, 0x55, 0x50, 0x1D, 0xAD, 0x50, 0xF1,
  42557. 0xB4, 0x8B, 0xBB, 0xDD, 0x86, 0xAB, 0x8B, 0xB5,
  42558. 0x22, 0xA9, 0x36, 0xDD, 0xF0, 0x00, 0x3B, 0x81,
  42559. 0xBE, 0x16, 0x23, 0x1A, 0x04, 0xE7, 0xA5, 0x89,
  42560. 0xC5, 0x6F, 0xFF, 0xB5, 0x1B, 0x07, 0x92, 0x7B,
  42561. 0x4A, 0xFA, 0x1D, 0xB7, 0xD4, 0x8B, 0xC6, 0xFB,
  42562. 0xC3, 0xF3, 0x67, 0x56, 0x37, 0x18, 0x4B, 0x7A,
  42563. 0xDB, 0x9B, 0xAD, 0xF4, 0xDE, 0x7C, 0x08, 0x5B,
  42564. 0xCA, 0x1D, 0x42, 0x8D, 0xC9, 0xFC, 0x82, 0x77,
  42565. 0xCB, 0xD8, 0x58, 0x84, 0xA5, 0x92, 0x1B, 0x52,
  42566. 0xBB, 0x05, 0xB7, 0x10, 0x61, 0x55, 0x08, 0x26,
  42567. 0x1B, 0xB4, 0x54, 0x6B, 0xD6, 0xE1, 0xFC, 0x73,
  42568. 0x0D, 0x16, 0xB0, 0x49, 0xEA, 0x12, 0x79, 0x8C,
  42569. 0xE2, 0xE6, 0xDF, 0x43, 0xF5, 0xB8, 0xF3, 0xEF,
  42570. 0x9A, 0xC8, 0xFB, 0xAE, 0x31, 0xB0, 0x11, 0xE1,
  42571. 0x0C, 0x4F, 0xC6, 0x2F, 0xFD, 0x7F, 0x39, 0xD1,
  42572. 0x6E, 0xC3, 0x2C, 0xA8, 0x21, 0x0E, 0xD1, 0x6E,
  42573. 0x04, 0x1D, 0xA4, 0x3D, 0x92, 0x74, 0x22, 0x95,
  42574. 0x14, 0x05, 0x4A, 0x0F, 0x82, 0xD4, 0x62, 0xFE,
  42575. 0x08, 0x0C, 0x6F, 0xFD, 0x7B, 0xBD, 0xBF, 0xBF,
  42576. 0x0B, 0xFF, 0xC6, 0xD5, 0xEC, 0xC4, 0x32, 0xA3,
  42577. 0x25, 0x6C, 0x0B, 0xE0, 0xDD, 0xFD, 0x5D, 0x90,
  42578. 0x80, 0xC6, 0x76, 0xC7, 0x95, 0x5D, 0x66, 0xE4,
  42579. 0x4D, 0x1C, 0xE5, 0x1F, 0xCC, 0x23, 0x82, 0xF8,
  42580. 0x68, 0xD7, 0x32, 0xE8, 0x58, 0x51, 0x72, 0x1B,
  42581. 0x48, 0xA0, 0x1D, 0x08, 0xC6, 0x39, 0x62, 0x6E,
  42582. 0xE0, 0x50, 0x9C, 0xB5, 0x81, 0xEF, 0xF5, 0x62,
  42583. 0x8F, 0xA6, 0xCC, 0xD1, 0x08, 0x9A, 0xC0, 0xE1,
  42584. 0x2D, 0xEB, 0xE0, 0x85, 0x17, 0x82, 0xE6, 0x4C,
  42585. 0x50, 0x49, 0xCB, 0xD6, 0x50, 0x10, 0x13, 0x96,
  42586. 0x5C, 0xC0, 0xCA, 0x25, 0xAC, 0xAB, 0x17, 0x6E,
  42587. 0xF7, 0xCA, 0xB9, 0x29, 0x40, 0x98, 0x5D, 0xDB,
  42588. 0x49, 0x02, 0x1D, 0xF6, 0xC6, 0x0D, 0x6C, 0x4A,
  42589. 0x48, 0x91, 0x16, 0x31, 0x1E, 0x86, 0xBA, 0x19,
  42590. 0xED, 0xF0, 0x0D, 0x74, 0x79, 0x73, 0x58, 0x20,
  42591. 0x7C, 0xDE, 0x50, 0x50, 0x6D, 0x00, 0x7F, 0xE0,
  42592. 0x3C, 0x88, 0x04, 0xC6, 0x64, 0x51, 0xF0, 0x2A,
  42593. 0x01, 0x82, 0xD3, 0x87, 0xB7, 0x59, 0x89, 0x40,
  42594. 0x96, 0xF6, 0x52, 0x32, 0x95, 0x2D, 0x18, 0x3D,
  42595. 0xBA, 0xAA, 0xBB, 0x6B, 0xC0, 0xE1, 0x91, 0xDC,
  42596. 0x2C, 0x3F, 0x75, 0xFC, 0x72, 0xBD, 0x61, 0xBA,
  42597. 0xB2, 0xEF, 0x19, 0xB6, 0x53, 0x2B, 0x23, 0x1C,
  42598. 0x4A, 0xFB, 0x1A, 0x9C, 0x2C, 0xB2, 0xF3, 0xD6,
  42599. 0xC4, 0x51, 0xE8, 0x44, 0x0D, 0x6A, 0x92, 0x3C,
  42600. 0xF7, 0x2A, 0x63, 0xE2, 0xED, 0x85, 0x54, 0x77,
  42601. 0x38, 0x87, 0x91, 0x0C, 0xA5, 0xC6, 0x71, 0xAD,
  42602. 0x4F, 0xD5, 0x92, 0x3C, 0xB9, 0x5E, 0xC7, 0x3F,
  42603. 0xFD, 0xFB, 0xDA, 0x4B, 0x66, 0x55, 0xF5, 0x5D,
  42604. 0xBF, 0xD1, 0x31, 0x7D, 0x02, 0x44, 0x22, 0x30,
  42605. 0x1E, 0xD6, 0x6A, 0x6E, 0x4C, 0x67, 0x20, 0x85,
  42606. 0xCE, 0xD1, 0xF4, 0xC7, 0xB0, 0x50, 0x30, 0xA1,
  42607. 0x00, 0xC4, 0x78, 0x8F, 0xEF, 0x4C, 0xD3, 0xE4,
  42608. 0x94, 0xA8, 0x53, 0xBD, 0xE6, 0x3E, 0x9D, 0x44,
  42609. 0x9A, 0xE3, 0xBB, 0x6B, 0xA1, 0x08, 0x32, 0x38,
  42610. 0xDA, 0x3F, 0x40, 0x90, 0x51, 0x5D, 0x14, 0x3C,
  42611. 0x67, 0xDB, 0xE5, 0x3D, 0x8D, 0x50, 0x7A, 0x52,
  42612. 0x29, 0xFF, 0xEB, 0x20, 0x72, 0xD0, 0xBD, 0x09,
  42613. 0x2F, 0xC9, 0xAE, 0x52, 0xDE, 0xAA, 0xAC, 0xD1,
  42614. 0xF0, 0xF1, 0x4B, 0x5A, 0xC8, 0x47, 0x52, 0xBF,
  42615. 0xD0, 0x02, 0x5E, 0x5F, 0x55, 0xB8, 0x69, 0x35,
  42616. 0x0F, 0x4B, 0x27, 0x19, 0xC5, 0xC0, 0x5A, 0xC1,
  42617. 0x66, 0x9B, 0xB0, 0xFD, 0x3C, 0x61, 0x4A, 0xCE,
  42618. 0x02, 0xA2, 0x70, 0x61, 0x3F, 0xD3, 0x30, 0x97,
  42619. 0x06, 0xDD, 0xCD, 0x5B, 0x1A, 0x6A, 0xD2, 0x6F,
  42620. 0x35, 0x9A, 0xDA, 0x80, 0xB3, 0x0E, 0x50, 0xA7,
  42621. 0xE5, 0x0B, 0xBD, 0x3A, 0xA4, 0x5D, 0x06, 0x54,
  42622. 0xDD, 0x7D, 0x05, 0x8B, 0x0B, 0xBF, 0x4D, 0x0D,
  42623. 0x92, 0x13, 0x51, 0x42, 0x21, 0x4E, 0xE7, 0x05,
  42624. 0x11, 0xF3, 0x67, 0x6A, 0xE6, 0x43, 0xB5, 0xF2,
  42625. 0x45, 0x06, 0x3B, 0x94, 0x19, 0xCF, 0x6B, 0x49,
  42626. 0xFD, 0x64, 0x7F, 0x27, 0xD7, 0xC4, 0x1C, 0x86,
  42627. 0x6E, 0x6C, 0xAD, 0x9D, 0x5E, 0x2E, 0x3E, 0x33,
  42628. 0x1B, 0xF6, 0xB9, 0xF7, 0x2A, 0xCA, 0x32, 0x9B,
  42629. 0xB6, 0x42, 0x59, 0xC3, 0xE7, 0x97, 0x83, 0xA2,
  42630. 0x66, 0x74, 0xB7, 0xD3, 0x8E, 0xBD, 0xE8, 0x31,
  42631. 0x84, 0x11, 0xF4, 0x76, 0x4E, 0xBD, 0xC4, 0xC7,
  42632. 0xE4, 0x1A, 0xCF, 0xF8, 0x5B, 0xBB, 0x30, 0x31,
  42633. 0x8D, 0x59, 0xC4, 0x2C, 0x92, 0x03, 0xAB, 0xD6,
  42634. 0x63, 0x6B, 0xA3, 0xF7, 0x72, 0xB6, 0x72, 0x51,
  42635. 0x21, 0xC0, 0x52, 0xDE, 0x99, 0x91, 0x0D, 0x55,
  42636. 0x15, 0x8C, 0x6F, 0x3E, 0xF8, 0xBB, 0x7F, 0xED,
  42637. 0xE2, 0xF8, 0x1E, 0x58, 0xA7, 0xAE, 0xB2, 0x5E,
  42638. 0x2E, 0x46, 0xFD, 0x72, 0x32, 0x30, 0x2F, 0xAF,
  42639. 0xA8, 0xFC, 0x37, 0xFC, 0x8B, 0x55, 0xD5, 0x94,
  42640. 0xB7, 0x6E, 0xC4, 0xA5, 0x3E, 0xB1, 0x1E, 0xB3,
  42641. 0xFD, 0x63, 0x44, 0x28, 0xAA, 0xA5, 0xD8, 0x6F,
  42642. 0x83, 0x9D, 0x08, 0x9A, 0xBE, 0x2F, 0xEF, 0xE2,
  42643. 0xAE, 0x52, 0x62, 0xFE, 0xFC, 0x73, 0x48, 0xD8,
  42644. 0x36, 0x69, 0x2E, 0xDB, 0x21, 0x5D, 0x6F, 0x8F,
  42645. 0x54, 0x8B, 0x88, 0x52, 0x90, 0xC2, 0x40, 0x3C,
  42646. 0x51, 0xC3, 0xE2, 0x69, 0xD4, 0x93, 0xFB, 0xD3,
  42647. 0x39, 0xB5, 0xDF, 0xB0, 0xA3, 0x8E, 0xED, 0xA7,
  42648. 0x75, 0x4D, 0xAF, 0xFA, 0x16, 0xE5, 0xBC, 0xA5,
  42649. 0xA9, 0xBB, 0xDE, 0x04, 0xB0, 0x14, 0xB7, 0xAE,
  42650. 0xA8, 0x98, 0x8F, 0x37, 0x49, 0xD5, 0x2D, 0x2F,
  42651. 0xC1, 0xC9, 0xF7, 0xC7, 0xB2, 0xC2, 0xD6, 0x92,
  42652. 0xE7, 0x89, 0x6E, 0x4C, 0x34, 0xF5, 0x7C, 0x55,
  42653. 0x8C, 0xFE, 0x83, 0x17, 0xA8, 0x37, 0x44, 0x09,
  42654. 0xD5, 0x66, 0x87, 0x9A, 0x08, 0x62, 0x8F, 0x64,
  42655. 0x4F, 0xB4, 0x5B, 0x81, 0x84, 0x55, 0xBC, 0xA6,
  42656. 0x04, 0x2B, 0x4E, 0x61, 0x87, 0xC1, 0xDD, 0x17,
  42657. 0x7E, 0x9E, 0x51, 0x46, 0x31, 0x99, 0x04, 0xB1,
  42658. 0x50, 0x5F, 0x3E, 0xE0, 0x0C, 0xD7, 0xFE, 0xAF,
  42659. 0x0E, 0x83, 0xC3, 0x02, 0x49, 0x56, 0xF7, 0x76,
  42660. 0x59, 0xAC, 0xC5, 0x6D, 0x8D, 0x91, 0x7A, 0x37,
  42661. 0xE8, 0xFF, 0x7E, 0xB8, 0x87, 0x13, 0xCC, 0xA3,
  42662. 0x34, 0xEA, 0x04, 0xB8, 0xE2, 0x58, 0xC9, 0x34,
  42663. 0x5D, 0xA9, 0xDE, 0x26, 0xA0, 0xA3, 0x66, 0x51,
  42664. 0x94, 0x51, 0xE1, 0x01, 0x2D, 0xE6, 0xAA, 0xBF,
  42665. 0x46, 0x97, 0xC9, 0xDE, 0x82, 0x1D, 0x70, 0x02,
  42666. 0x1C, 0x32, 0x50, 0xA1, 0x06, 0xCF, 0x4C, 0x23,
  42667. 0xA1, 0xB1, 0x78, 0x5F, 0x54, 0x9D, 0x3C, 0x8C,
  42668. 0xD7, 0x1B, 0x05, 0xFE, 0xA7, 0x53, 0xE0, 0x04,
  42669. 0x6A, 0x3A, 0xE0, 0xA9, 0xB1, 0xF4, 0x02, 0x77,
  42670. 0xCF, 0x45, 0x3A, 0x2B, 0xA1, 0x4C, 0xBA, 0x92,
  42671. 0x3C, 0xC6, 0x26, 0x97, 0x06, 0xDF, 0xFF, 0xD5,
  42672. 0x17, 0xC1, 0xE5, 0x93, 0x00, 0x79, 0x91, 0x2E,
  42673. 0x05, 0xA5, 0x57, 0x18, 0x97, 0xA0, 0x68, 0x65,
  42674. 0x51, 0x6C, 0x86, 0x69, 0x9F, 0x70, 0x7E, 0x00,
  42675. 0xCB, 0x38, 0xCE, 0x19, 0x34, 0x90, 0xAE, 0xE3,
  42676. 0x0B, 0xA4, 0x7D, 0xDD, 0xF3, 0xA5, 0xB4, 0xFB,
  42677. 0xCE, 0xBA, 0x73, 0xDC, 0x13, 0xD0, 0xA1, 0x60,
  42678. 0xEA, 0x64, 0x2D, 0x30, 0xD6, 0x3A, 0x02, 0x96,
  42679. 0x4E, 0xDF, 0xDB, 0x2F, 0x29, 0xDC, 0xD3, 0x2C,
  42680. 0xA9, 0x97, 0x4F, 0x89, 0xC3, 0x2D, 0x1F, 0xA9,
  42681. 0xA8, 0x3C, 0x94, 0xA2, 0x77, 0x0F, 0xCF, 0xCF,
  42682. 0x86, 0xE6, 0x46, 0x46, 0x88, 0x2B, 0xD5, 0x50,
  42683. 0xDD, 0xD6, 0x5B, 0x4E, 0x2D, 0x28, 0x7A, 0xF6,
  42684. 0xC1, 0x96, 0xF4, 0x2D, 0xBD, 0x39, 0xB0, 0x20,
  42685. 0xD7, 0xCD, 0xFB, 0xB6, 0xE6, 0xE7, 0x5F, 0xFA,
  42686. 0xAB, 0x26, 0x09, 0x9E, 0xC1, 0xD2, 0x5E, 0x32,
  42687. 0x34, 0xF7, 0x0D, 0xD9, 0x72, 0x28, 0x6A, 0xEA,
  42688. 0x0C, 0x34, 0x36, 0x59, 0x5F, 0xE4, 0x9F, 0xCA,
  42689. 0x89, 0x8B, 0xFA, 0x42, 0x16, 0x04, 0xC8, 0x2D,
  42690. 0x3E, 0x94, 0x85, 0x6D, 0x18, 0x69, 0x05, 0x07,
  42691. 0x6D, 0x18, 0x6C, 0x68, 0x41, 0x74, 0xBF, 0x42,
  42692. 0x90, 0xDF, 0x31, 0x76, 0x9E, 0xDC, 0x97, 0xA1,
  42693. 0xDF, 0x2D, 0xFE, 0xD0, 0x3C, 0xF4, 0x5C, 0xE6,
  42694. 0x78, 0xC8, 0xA1, 0x42, 0x9E, 0xB9, 0x78, 0xD0,
  42695. 0x2A, 0x79, 0xD4, 0xF8, 0xCF, 0x01, 0x68, 0xDA,
  42696. 0xAB, 0x48, 0x2C, 0x6C, 0x61, 0x2F, 0x04, 0xB1,
  42697. 0xC9, 0x36, 0x37, 0xFE, 0x77, 0xB3, 0x02, 0xCE,
  42698. 0xFA, 0x78, 0x8C, 0x11, 0x35, 0x6C, 0x52, 0xC5,
  42699. 0x4F, 0x37, 0xA9, 0xDC, 0xFD, 0xA5, 0x59, 0x27,
  42700. 0xA8, 0xEF, 0x0A, 0x0C, 0xEA, 0x7C, 0xC4, 0xAD,
  42701. 0xCE, 0xE4, 0x59, 0xEB, 0x64, 0xDF, 0x08, 0xED,
  42702. 0x0F, 0xC2, 0x9F, 0xDC, 0x3C, 0x7B, 0x76, 0x2B,
  42703. 0x39, 0x93, 0x32, 0x06, 0x33, 0x40, 0xD4, 0x73,
  42704. 0x96, 0x62, 0x19, 0xBF, 0xC8, 0x7B, 0x4A, 0x3C,
  42705. 0x91, 0xC8, 0x0F, 0x0E, 0x4B, 0xA8, 0x6A, 0xA1,
  42706. 0x87, 0x9C, 0x76, 0x62, 0x5C, 0x86, 0x80, 0xA2,
  42707. 0x27, 0xAB, 0x22, 0x78, 0x06, 0x59, 0xD4, 0xB5,
  42708. 0xD3, 0x0E, 0x0E, 0x9A, 0x0D, 0xCE, 0x09, 0x4D,
  42709. 0xAF, 0x53, 0x76, 0x79, 0x27, 0x3A, 0x9B, 0x27,
  42710. 0x7E, 0xD2, 0xA2, 0xE2, 0x50, 0xEE, 0xA0, 0x93,
  42711. 0x82, 0x04, 0xC9, 0xE9, 0x63, 0xD3, 0x38, 0x52,
  42712. 0x2A, 0x3D, 0x1A, 0x44, 0x40, 0xE2, 0xA1, 0x23,
  42713. 0x97, 0xA5, 0xB9, 0x7D, 0x35, 0x65, 0x73, 0x07,
  42714. 0xBE, 0xC9, 0x4C, 0xC0, 0xC7, 0x2C, 0x5C, 0x6B,
  42715. 0x09, 0xDA, 0xF2, 0xBA, 0xF0, 0x02, 0x0B, 0x7D,
  42716. 0x8C, 0xA5, 0x60, 0xBF, 0x65, 0x96, 0x92, 0x9A,
  42717. 0xC8, 0xD4, 0xE5, 0x46, 0x0F, 0x78, 0x37, 0xB4,
  42718. 0x1B, 0x4A, 0xE6, 0xFF, 0x12, 0x33, 0x9D, 0xB8,
  42719. 0xEB, 0xD7, 0x02, 0x8A, 0xAC, 0xFE, 0x0B, 0x42,
  42720. 0xE0, 0x2C, 0xDE, 0x90, 0x67, 0x83, 0xAB, 0xFF,
  42721. 0x69, 0x4E, 0x7C, 0xBE, 0x08, 0x97, 0xED, 0x6E,
  42722. 0xD4, 0x38, 0xAC, 0xDB, 0x00, 0xA4, 0x70, 0x9C,
  42723. 0xFE, 0xF7, 0x15, 0x0E, 0xBE, 0xB0, 0x8C, 0x8F,
  42724. 0xF6, 0xC1, 0x54, 0x38, 0x15, 0xF4, 0xB8, 0x95,
  42725. 0x1C, 0x3C, 0xAC, 0xE4, 0x99, 0x58, 0x64, 0x58,
  42726. 0xA7, 0x3C, 0x85, 0x72, 0x38, 0x9A, 0xFC, 0x97,
  42727. 0x03, 0xA7, 0xFE, 0xAF, 0x67, 0x34, 0x45, 0xFB,
  42728. 0x4B, 0x0C, 0xCA, 0xA5, 0x11, 0xD4, 0xA2, 0xCF,
  42729. 0x46, 0x3F, 0x57, 0xE3, 0xA6, 0xD7, 0x2D, 0xA0,
  42730. 0x4B, 0x25, 0x66, 0x99, 0xA3, 0x02, 0x12, 0xE7,
  42731. 0xC5, 0x76, 0x8E, 0xFC, 0x15, 0x1B, 0x71, 0x74,
  42732. 0x41, 0x56, 0x57, 0x5A, 0x2E, 0x94, 0x43, 0x31,
  42733. 0x92, 0x32, 0xD1, 0x59, 0xC6, 0xCC, 0x00, 0x6F,
  42734. 0xDB, 0x57, 0xC5, 0x81, 0x73, 0xAD, 0x8D, 0x2C,
  42735. 0x86, 0x6C, 0x88, 0x87, 0x43, 0x7C, 0x22, 0x38,
  42736. 0x88, 0xE2, 0x1E, 0xF6, 0x7E, 0x1A, 0x33, 0x2C,
  42737. 0x1F, 0xDF, 0xCC, 0x15, 0xEF, 0x17, 0x47, 0x6F,
  42738. 0xE0, 0xFB, 0x57, 0xD4, 0x22, 0x98, 0x94, 0x72,
  42739. 0x5E, 0x14, 0x74, 0xC1, 0xBA, 0x12, 0x16, 0x56,
  42740. 0x28, 0x17, 0xF1, 0x6C, 0x53, 0xEC, 0xE0, 0x1C,
  42741. 0x7F, 0x9E, 0x36, 0x64, 0xEE, 0xDB, 0xBA, 0x94,
  42742. 0x95, 0x29, 0x87, 0x43, 0x1A, 0xA2, 0xA5, 0x7D,
  42743. 0x33, 0x0E, 0xB1, 0x1B, 0x28, 0xE6, 0xBF, 0x77,
  42744. 0x0E, 0x34, 0x9E, 0xCE, 0x35, 0x0C, 0x83, 0xE9,
  42745. 0x0D, 0xA6, 0xFE, 0x0D, 0x0A, 0x4A, 0xB9, 0x71,
  42746. 0x5D, 0xB2, 0x8B, 0xDD, 0x39, 0x7F, 0xAF, 0xA1,
  42747. 0x42, 0x83, 0x02, 0x15, 0x1E, 0x1F, 0x22, 0x2B,
  42748. 0x44, 0x69, 0x87, 0x9E, 0xB5, 0xD0, 0xF0, 0x18,
  42749. 0x60, 0x6A, 0x75, 0x94, 0xBF, 0xC8, 0x2C, 0x39,
  42750. 0x4E, 0x91, 0xB9, 0x26, 0x44, 0x95, 0xC9, 0x06,
  42751. 0x3D, 0x50, 0x52, 0x62, 0x79, 0x9B, 0x9F, 0xCB,
  42752. 0xE6, 0x31, 0x6B, 0xBC, 0xC8, 0xD8, 0x09, 0x30,
  42753. 0x53, 0x63, 0x6A, 0x74, 0xD4, 0xFA, 0x00, 0x00,
  42754. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  42755. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  42756. 0x00, 0x00, 0x00, 0x02, 0x0F, 0x16, 0x1B, 0x1F,
  42757. 0x29, 0x2E, 0x36
  42758. };
  42759. #endif
  42760. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  42761. #ifndef WOLFSSL_NO_ML_DSA_44
  42762. static const byte pk_44_draft[] = {
  42763. 0x35, 0x07, 0x31, 0x3A, 0xE3, 0x7A, 0xF6, 0x96,
  42764. 0x6C, 0x11, 0xA9, 0xE4, 0x0B, 0xEB, 0xEC, 0xE9,
  42765. 0x2B, 0x67, 0x3F, 0xD2, 0x67, 0x3C, 0x1C, 0x4C,
  42766. 0x08, 0xF0, 0x45, 0xA9, 0xDD, 0x5A, 0xB8, 0x8C,
  42767. 0x0A, 0x51, 0xA9, 0xBA, 0x89, 0x0F, 0x4C, 0xCB,
  42768. 0x9D, 0x0A, 0x41, 0x3F, 0x9C, 0xF4, 0x13, 0x36,
  42769. 0x79, 0x49, 0x00, 0x90, 0xBB, 0x57, 0x3B, 0xBD,
  42770. 0x2E, 0x18, 0xB3, 0xD0, 0xA5, 0x0E, 0x6B, 0x67,
  42771. 0xFF, 0x98, 0x8C, 0xDD, 0x07, 0xE8, 0xA7, 0xA1,
  42772. 0x3F, 0xAE, 0xFB, 0xD6, 0xC0, 0xF8, 0xF3, 0x34,
  42773. 0xA5, 0x17, 0xC2, 0x34, 0x88, 0x92, 0x65, 0xA6,
  42774. 0xE8, 0x66, 0x57, 0xFE, 0x86, 0x08, 0xF7, 0xDF,
  42775. 0xA0, 0x5B, 0x70, 0x3E, 0x91, 0x6C, 0x63, 0xA0,
  42776. 0xA3, 0x75, 0x55, 0xF8, 0xB6, 0xAA, 0xD4, 0x1B,
  42777. 0x78, 0x5E, 0x42, 0x9F, 0x96, 0xE4, 0xA0, 0x50,
  42778. 0xB6, 0x94, 0x2D, 0xC3, 0xE3, 0x36, 0x2B, 0x9D,
  42779. 0x6B, 0x7A, 0xEF, 0xF5, 0x68, 0xF2, 0x11, 0xDF,
  42780. 0x87, 0xA0, 0x9A, 0xC4, 0x61, 0xFB, 0xA4, 0x1C,
  42781. 0x98, 0x3F, 0xC9, 0x52, 0x59, 0x3B, 0x47, 0x4D,
  42782. 0xF5, 0x24, 0xA3, 0xD8, 0x63, 0xE1, 0xED, 0xDC,
  42783. 0xFD, 0xEB, 0x96, 0xFB, 0xF3, 0xE7, 0x50, 0x9C,
  42784. 0x72, 0x61, 0xC7, 0x3C, 0xCE, 0xF2, 0xEB, 0x22,
  42785. 0x55, 0x6B, 0x9F, 0x25, 0xE4, 0x45, 0xE1, 0xFB,
  42786. 0x3E, 0x2E, 0x4E, 0x92, 0x4F, 0x8A, 0x85, 0xEB,
  42787. 0x63, 0x2C, 0x05, 0x0F, 0x9A, 0xEC, 0x0E, 0x9D,
  42788. 0x05, 0x81, 0x46, 0x82, 0xEA, 0x74, 0x91, 0xD5,
  42789. 0x2A, 0xBC, 0xCC, 0xBB, 0xD6, 0x7F, 0x5F, 0x9A,
  42790. 0xD3, 0xBD, 0xEB, 0x14, 0xBA, 0x84, 0x27, 0x13,
  42791. 0x32, 0xB5, 0xF3, 0x71, 0xAC, 0x47, 0x19, 0x6B,
  42792. 0x5E, 0x43, 0x50, 0xC2, 0xA8, 0x82, 0xF5, 0x97,
  42793. 0x9B, 0x27, 0x62, 0xFB, 0xB7, 0xFF, 0x6B, 0xC8,
  42794. 0x52, 0x1E, 0xFB, 0x97, 0x39, 0x1E, 0x7F, 0x01,
  42795. 0xF8, 0x34, 0x47, 0xAA, 0xB2, 0x64, 0xB5, 0x9E,
  42796. 0x28, 0x18, 0xCB, 0x4A, 0x94, 0xBE, 0x6A, 0x43,
  42797. 0x5B, 0xAE, 0x21, 0xA4, 0x63, 0x64, 0x46, 0x0C,
  42798. 0x6B, 0x36, 0x1C, 0x2A, 0x3B, 0x64, 0xFA, 0xA0,
  42799. 0xAB, 0xE3, 0x3B, 0x7D, 0xB0, 0x23, 0x99, 0x21,
  42800. 0x55, 0x59, 0xBF, 0xD6, 0xDB, 0xB8, 0xDB, 0x09,
  42801. 0x5E, 0xBC, 0x32, 0x3C, 0xAC, 0xAB, 0x1A, 0x63,
  42802. 0x32, 0x21, 0x10, 0xD5, 0x8D, 0x7A, 0x5F, 0xCE,
  42803. 0x72, 0x8D, 0x2A, 0xED, 0x1D, 0x30, 0x38, 0x5D,
  42804. 0x3E, 0x62, 0xC2, 0x8E, 0xC9, 0x9F, 0x8C, 0x50,
  42805. 0x3F, 0xC6, 0xCE, 0x86, 0x4D, 0x67, 0x3D, 0x09,
  42806. 0xB6, 0x27, 0x14, 0x57, 0x14, 0xED, 0xC9, 0x8F,
  42807. 0xAC, 0x9E, 0xAC, 0x6F, 0xB5, 0xB2, 0xE6, 0x8D,
  42808. 0x9D, 0x5E, 0xE6, 0x78, 0x77, 0x09, 0x94, 0x35,
  42809. 0x5E, 0x3B, 0x64, 0x04, 0x38, 0xD4, 0x5B, 0x04,
  42810. 0xB8, 0x6C, 0x33, 0x97, 0xE1, 0x58, 0x54, 0x32,
  42811. 0xB3, 0x0F, 0x37, 0x69, 0x39, 0xCE, 0x57, 0x31,
  42812. 0x5C, 0x75, 0xA8, 0x94, 0xD0, 0x39, 0x2D, 0xB4,
  42813. 0x73, 0xA7, 0xA4, 0x7C, 0xBE, 0x34, 0x03, 0x2D,
  42814. 0x99, 0x1D, 0xDF, 0x32, 0x26, 0xB7, 0x45, 0x1B,
  42815. 0x03, 0xCD, 0xEE, 0x9D, 0x58, 0xA8, 0xA7, 0x76,
  42816. 0x1B, 0x17, 0x42, 0xD9, 0x69, 0x0F, 0x26, 0x3A,
  42817. 0x9D, 0x70, 0x9B, 0x4E, 0x81, 0xEB, 0x96, 0x02,
  42818. 0xB5, 0xB3, 0x92, 0x31, 0xFE, 0xBC, 0x38, 0x11,
  42819. 0x5A, 0x47, 0xED, 0x0A, 0x2A, 0xE2, 0xB8, 0x47,
  42820. 0x13, 0x5E, 0x43, 0x97, 0xD5, 0xFA, 0x31, 0x02,
  42821. 0x58, 0xE9, 0x9E, 0xB5, 0x3F, 0x85, 0x92, 0x0E,
  42822. 0xB9, 0xDB, 0xE0, 0xEE, 0x56, 0x76, 0x64, 0x8F,
  42823. 0xF2, 0xE2, 0x47, 0x81, 0xD4, 0xA4, 0x82, 0x43,
  42824. 0x69, 0xAE, 0x8E, 0x48, 0x50, 0x84, 0x93, 0x3B,
  42825. 0x9C, 0x65, 0xD3, 0x6F, 0xCD, 0x90, 0xA0, 0xD8,
  42826. 0xA0, 0xE1, 0x79, 0xCC, 0xD5, 0x1F, 0x71, 0x73,
  42827. 0x93, 0xE7, 0xB2, 0xB0, 0x78, 0x17, 0xD7, 0x79,
  42828. 0xDE, 0xCC, 0x83, 0x7D, 0x5A, 0xF2, 0x0E, 0xA6,
  42829. 0xB1, 0x76, 0x61, 0x15, 0x88, 0x8E, 0xD7, 0xA6,
  42830. 0x51, 0xBF, 0x9C, 0xD1, 0x0A, 0xFC, 0xDA, 0x65,
  42831. 0xA5, 0x65, 0xFE, 0xB2, 0xED, 0x07, 0x74, 0x42,
  42832. 0x4C, 0xF5, 0x42, 0x3D, 0xAF, 0x5F, 0x4D, 0x72,
  42833. 0x51, 0xE6, 0x3F, 0x68, 0xCC, 0xC5, 0x2D, 0x89,
  42834. 0x01, 0xD8, 0x80, 0xB4, 0xFC, 0xEB, 0x3B, 0xBE,
  42835. 0x7C, 0xFA, 0x24, 0x27, 0xE1, 0x05, 0x94, 0x67,
  42836. 0xAD, 0xB3, 0x47, 0x7D, 0x28, 0x18, 0xC1, 0xC9,
  42837. 0xB8, 0xA1, 0x2A, 0x95, 0xBB, 0x5D, 0xC9, 0x42,
  42838. 0x4F, 0x64, 0x94, 0x07, 0x5F, 0x65, 0xD3, 0xA5,
  42839. 0x65, 0xEE, 0x67, 0x2C, 0x10, 0x65, 0x81, 0x4D,
  42840. 0x7F, 0xAF, 0x2E, 0x97, 0x9E, 0x11, 0xA3, 0xF5,
  42841. 0x3E, 0xDE, 0xB1, 0x1D, 0x44, 0x72, 0x90, 0x74,
  42842. 0xFD, 0x47, 0x82, 0xA6, 0x04, 0x3E, 0x28, 0x3C,
  42843. 0x15, 0xDF, 0xC4, 0x7A, 0x7C, 0xF5, 0x5A, 0xC6,
  42844. 0xFB, 0xE4, 0xC2, 0xE0, 0x6E, 0x4C, 0x09, 0x2E,
  42845. 0xE3, 0xE6, 0x3A, 0xEF, 0xF6, 0x54, 0xDC, 0x92,
  42846. 0xBE, 0x8F, 0x24, 0x8E, 0x70, 0x53, 0x90, 0x3D,
  42847. 0x06, 0xA5, 0x0A, 0x72, 0xA0, 0x7B, 0x22, 0x14,
  42848. 0x80, 0x43, 0xAD, 0xDC, 0x11, 0xFC, 0xFF, 0xCF,
  42849. 0x5E, 0xA4, 0x69, 0x1C, 0x09, 0x09, 0xC3, 0x3D,
  42850. 0xF5, 0xE7, 0x05, 0x6F, 0x16, 0x33, 0x75, 0xB4,
  42851. 0x9B, 0x7B, 0x26, 0xDB, 0xE7, 0x27, 0x56, 0xD3,
  42852. 0x91, 0x82, 0x9D, 0xEB, 0x96, 0x3E, 0xE8, 0x40,
  42853. 0xAB, 0x5D, 0x6C, 0xB7, 0xA6, 0x36, 0x07, 0xD4,
  42854. 0xE7, 0x7C, 0xD4, 0x5C, 0x36, 0xE4, 0xFC, 0x7C,
  42855. 0x8A, 0x36, 0x8D, 0x53, 0x43, 0xD4, 0xAC, 0x0B,
  42856. 0x1B, 0xBA, 0x32, 0x88, 0xFA, 0xCE, 0xC1, 0xB9,
  42857. 0x34, 0x3C, 0xAC, 0xA0, 0xF4, 0xF2, 0x83, 0xA8,
  42858. 0xBB, 0x6F, 0x12, 0xC6, 0xB5, 0x3C, 0xDE, 0xA8,
  42859. 0x49, 0x66, 0x97, 0xD7, 0x7E, 0x37, 0xF7, 0xCE,
  42860. 0x7C, 0xF8, 0xC8, 0xBB, 0x8C, 0xB5, 0x3B, 0x3F,
  42861. 0xB9, 0x51, 0x68, 0x00, 0xD7, 0x2E, 0x1C, 0x10,
  42862. 0xAF, 0x9F, 0x3C, 0xD2, 0xAC, 0xE5, 0xBE, 0x94,
  42863. 0xB9, 0x60, 0xF5, 0xB2, 0x70, 0x24, 0xE8, 0x8A,
  42864. 0x2C, 0xD8, 0x95, 0xAF, 0xAA, 0xA9, 0xA5, 0x2B,
  42865. 0xCA, 0xE0, 0x58, 0x44, 0x02, 0x3F, 0xF8, 0x21,
  42866. 0x0C, 0x29, 0xB7, 0xD5, 0x08, 0x9E, 0x69, 0x81,
  42867. 0xD4, 0x6C, 0xC5, 0x0B, 0xF6, 0xEF, 0xAB, 0x01,
  42868. 0xEA, 0xDF, 0x36, 0x2C, 0x5C, 0xFB, 0xEB, 0xC8,
  42869. 0x4F, 0x71, 0x80, 0xD7, 0x00, 0xC9, 0x32, 0x5D,
  42870. 0x02, 0x4F, 0x96, 0x94, 0x71, 0xCD, 0x98, 0xC4,
  42871. 0x25, 0x7A, 0x92, 0xF1, 0x9B, 0xA0, 0x34, 0x30,
  42872. 0x6C, 0x41, 0x59, 0xD5, 0x01, 0x5D, 0xD6, 0x56,
  42873. 0xEA, 0x05, 0xF2, 0xFC, 0xF8, 0x58, 0xFA, 0x12,
  42874. 0x9C, 0x5A, 0x5C, 0xD5, 0x3D, 0xC7, 0x5D, 0x1B,
  42875. 0x99, 0x2A, 0x6A, 0x4C, 0xF9, 0xEA, 0x9D, 0x70,
  42876. 0x53, 0xBC, 0xBE, 0xAD, 0x61, 0xC7, 0x2D, 0x77,
  42877. 0xEF, 0x61, 0xC7, 0xBE, 0x9C, 0x73, 0xC1, 0xD5,
  42878. 0xD4, 0x5C, 0x5F, 0x21, 0x6A, 0x5C, 0xEE, 0x78,
  42879. 0xAA, 0xC6, 0x6C, 0x56, 0xDB, 0x38, 0x5A, 0x94,
  42880. 0x12, 0xB8, 0x73, 0x7C, 0xDF, 0x9A, 0x27, 0xCD,
  42881. 0xC5, 0xD1, 0xD3, 0xCA, 0x0E, 0x37, 0x0A, 0xC1,
  42882. 0x6F, 0xAD, 0xE3, 0x32, 0x94, 0x6C, 0x20, 0xB5,
  42883. 0xED, 0xE6, 0x2D, 0x34, 0x39, 0x58, 0xD2, 0x1E,
  42884. 0x63, 0x8D, 0xFA, 0xFF, 0xB5, 0xE8, 0x40, 0xC8,
  42885. 0x42, 0x38, 0x7A, 0x01, 0x80, 0xFF, 0x52, 0x3F,
  42886. 0xE9, 0x89, 0x63, 0xAD, 0x91, 0x5F, 0xCE, 0x0A,
  42887. 0x47, 0x87, 0xF9, 0x6D, 0xD7, 0x79, 0xEF, 0xCE,
  42888. 0x10, 0x7B, 0x73, 0x43, 0xBE, 0x51, 0xA0, 0xDF,
  42889. 0xE5, 0xEC, 0xA9, 0x63, 0xF6, 0x5E, 0x72, 0x36,
  42890. 0x22, 0x86, 0xEE, 0x4E, 0x4A, 0x76, 0xFD, 0x86,
  42891. 0xBA, 0xE6, 0xD6, 0xC4, 0xD2, 0xE6, 0xFF, 0xB2,
  42892. 0x5B, 0x39, 0xF9, 0xC3, 0x29, 0xA8, 0x61, 0x3A,
  42893. 0x33, 0x34, 0x89, 0xC9, 0x83, 0xF9, 0xB2, 0x70,
  42894. 0x21, 0x54, 0x44, 0x94, 0x70, 0xAD, 0x70, 0x18,
  42895. 0x84, 0x38, 0x91, 0xFB, 0xDE, 0x5E, 0x3D, 0xE3,
  42896. 0xB2, 0xA7, 0x3C, 0x1D, 0x49, 0xA6, 0x66, 0x7C,
  42897. 0x4B, 0xEB, 0xB0, 0xA7, 0x7C, 0xC5, 0xAE, 0x45,
  42898. 0x1F, 0xBE, 0x0E, 0x2F, 0x11, 0xDC, 0x92, 0x08,
  42899. 0xAA, 0x18, 0x38, 0xFE, 0x61, 0xBE, 0x9D, 0xC3,
  42900. 0x3A, 0x1F, 0x2F, 0xB6, 0x6E, 0xB6, 0x54, 0x97,
  42901. 0x74, 0x06, 0xBC, 0x12, 0x2D, 0x64, 0x18, 0x14,
  42902. 0x25, 0x5A, 0xCB, 0x7B, 0xD7, 0x9D, 0xC3, 0x2C,
  42903. 0xC2, 0x0B, 0x19, 0x10, 0xD2, 0x57, 0xF0, 0xDF,
  42904. 0xA4, 0x95, 0xA4, 0x5A, 0xA0, 0x2D, 0x0F, 0xA0,
  42905. 0xBC, 0xF7, 0x60, 0x7F, 0x38, 0xE1, 0x17, 0x0D,
  42906. 0x36, 0x08, 0xF5, 0xF9, 0x75, 0x28, 0x75, 0xAC,
  42907. 0xA9, 0x2B, 0x75, 0xC4, 0x41, 0xE0, 0x0D, 0x5C,
  42908. 0xBC, 0x5F, 0x49, 0x16, 0x25, 0x38, 0x16, 0xE1,
  42909. 0x0C, 0x2C, 0x9C, 0x63, 0xA8, 0x5F, 0x70, 0xF4,
  42910. 0x64, 0xC7, 0x10, 0x19, 0x52, 0x19, 0x6E, 0x9B,
  42911. 0x5C, 0x09, 0x4F, 0xEE, 0xB6, 0x7C, 0x85, 0xC9,
  42912. 0x6E, 0xCB, 0x33, 0x32, 0x42, 0x9D, 0x57, 0x18,
  42913. 0xE6, 0x55, 0x94, 0x74, 0x02, 0xEE, 0xEB, 0xAA,
  42914. 0xF7, 0xD3, 0x45, 0x7A, 0x49, 0x6F, 0x83, 0x89,
  42915. 0x00, 0xE4, 0xAA, 0x20, 0x87, 0x10, 0xAD, 0xC0,
  42916. 0x0E, 0xF5, 0x93, 0x57, 0xE5, 0x45, 0x7A, 0xBD,
  42917. 0x82, 0x87, 0x50, 0x0F, 0xE1, 0x2C, 0x0C, 0x6D,
  42918. 0xEE, 0xC8, 0x94, 0xB8, 0x39, 0xF3, 0x3C, 0xFE,
  42919. 0x7E, 0xC1, 0x0F, 0xB4, 0x67, 0xA2, 0xDF, 0xC6,
  42920. 0x9D, 0xB5, 0x9D, 0xB8, 0x72, 0x50, 0xBD, 0xB3,
  42921. 0xDB, 0xF6, 0x87, 0x5E, 0x26, 0x93, 0xF0, 0xD4,
  42922. 0x0D, 0x68, 0xA4, 0x8B, 0xBD, 0x2C, 0x6E, 0xD8,
  42923. 0x4F, 0x81, 0x5D, 0x0D, 0xAC, 0x72, 0x65, 0xEC,
  42924. 0x4E, 0xF2, 0x4E, 0x5F, 0x67, 0x04, 0xF3, 0x08,
  42925. 0x29, 0x4D, 0xB2, 0xE2, 0xD5, 0x9F, 0xD4, 0xB9,
  42926. 0x13, 0xB4, 0x33, 0x80, 0x27, 0x84, 0x7E, 0xF4
  42927. };
  42928. static const byte msg_44_draft[] = {
  42929. 0x5C, 0x70, 0x7F, 0xBF, 0xF4, 0xFF, 0xE5, 0x9B,
  42930. 0x09, 0xAA, 0xF8, 0xDB, 0x21, 0xAD, 0xBE, 0xBA,
  42931. 0xC6, 0xB2, 0x65, 0x37, 0x9A, 0x9A, 0x43, 0x3A,
  42932. 0xA8, 0x23, 0x2B, 0x13, 0x9B, 0xBD, 0x46, 0x37,
  42933. 0x30, 0x60, 0xA7, 0x5B, 0xC4, 0x48, 0x63, 0x5F,
  42934. 0x41, 0x35, 0x38, 0x69, 0xF9, 0x6F, 0xB5, 0x65,
  42935. 0x26, 0xDB, 0xAE, 0xB7, 0x5C, 0xFE, 0x2C, 0x03,
  42936. 0xCB, 0x43, 0x08, 0x58, 0x5E, 0x27, 0xD1, 0x42,
  42937. 0x14, 0xF2, 0x4B, 0xD7, 0x13, 0xE4, 0x96, 0x74,
  42938. 0x6A, 0xC1, 0x36, 0xC7, 0x9D, 0x0F, 0x7D, 0xB0,
  42939. 0x7B, 0x8A, 0x3A, 0x6D, 0x00, 0x5B, 0x29, 0x7B,
  42940. 0x37, 0xBA, 0x3F, 0x5B, 0xBD, 0xCE, 0x21, 0x77,
  42941. 0xFD, 0xD6, 0x78, 0x77, 0x20, 0x31, 0xF0, 0x60,
  42942. 0x49, 0xAE, 0x12, 0x86, 0x7A, 0x64, 0xBD, 0x0B,
  42943. 0x9E, 0xC6, 0x26, 0x80, 0x9E, 0xCE, 0x19, 0x8D,
  42944. 0x6A, 0x6B, 0x09, 0x03, 0x45, 0xDF, 0x22, 0x7D
  42945. };
  42946. static const byte sig_44_draft[] = {
  42947. 0x08, 0xF0, 0x10, 0xFA, 0x63, 0x3F, 0x2B, 0xA1,
  42948. 0x46, 0x81, 0x34, 0xC4, 0xBC, 0xAB, 0x62, 0x17,
  42949. 0x0B, 0x64, 0xEA, 0x00, 0x2D, 0xD6, 0x8A, 0xE5,
  42950. 0xC2, 0x45, 0x29, 0xB9, 0xEC, 0x6F, 0x3B, 0xF2,
  42951. 0xDC, 0x2F, 0xC7, 0x34, 0x5A, 0x1E, 0xFE, 0x0C,
  42952. 0xCA, 0xB9, 0x6A, 0xD8, 0xDA, 0xBA, 0xAA, 0x80,
  42953. 0x90, 0xDC, 0x8C, 0x6C, 0x22, 0xFF, 0xC4, 0x90,
  42954. 0x9E, 0xE9, 0xA5, 0x45, 0xFC, 0xE8, 0x64, 0x53,
  42955. 0x9E, 0xC4, 0x17, 0xE1, 0xB2, 0x1A, 0x31, 0x40,
  42956. 0x26, 0x9D, 0x5E, 0x03, 0x6A, 0xC6, 0x09, 0x19,
  42957. 0xDD, 0xB3, 0x63, 0xE0, 0x35, 0xCD, 0xB4, 0x2E,
  42958. 0x25, 0x38, 0x6E, 0x6C, 0x76, 0xA9, 0x19, 0x75,
  42959. 0x68, 0x6E, 0xB7, 0xAB, 0xAD, 0x8F, 0x63, 0x64,
  42960. 0x97, 0x4E, 0x56, 0x82, 0x30, 0x45, 0x86, 0x22,
  42961. 0x64, 0xDA, 0xD2, 0xAE, 0x54, 0x70, 0x5C, 0xF1,
  42962. 0xEB, 0xD1, 0x84, 0x8D, 0xFF, 0x86, 0x15, 0xE6,
  42963. 0x20, 0xCE, 0x14, 0x89, 0xEF, 0xFA, 0x2E, 0xF8,
  42964. 0x60, 0xCA, 0x53, 0x52, 0xE4, 0xD5, 0xC8, 0x2E,
  42965. 0x50, 0xD5, 0x9D, 0x90, 0xA6, 0x12, 0xC7, 0xF1,
  42966. 0x70, 0x0D, 0xE2, 0x89, 0x5B, 0x31, 0x6A, 0x21,
  42967. 0x79, 0x9C, 0xBE, 0x77, 0x6E, 0xA6, 0xBF, 0x51,
  42968. 0x05, 0x2A, 0x83, 0x50, 0x7E, 0x86, 0x14, 0xD1,
  42969. 0x50, 0x53, 0x1F, 0x1C, 0x5E, 0x50, 0x24, 0x69,
  42970. 0x6C, 0x91, 0x55, 0x35, 0x19, 0x6F, 0xE0, 0xDC,
  42971. 0xB5, 0xD6, 0x48, 0x7E, 0x78, 0x61, 0x59, 0x2C,
  42972. 0xD0, 0x1B, 0x42, 0x58, 0xAF, 0x7A, 0x39, 0xCA,
  42973. 0x02, 0x1C, 0x50, 0xEF, 0xE9, 0xE1, 0xDE, 0x31,
  42974. 0x8D, 0x09, 0x51, 0xC9, 0xDB, 0x16, 0xF9, 0xB9,
  42975. 0x45, 0x54, 0x81, 0x16, 0xD7, 0x14, 0xD8, 0xBE,
  42976. 0x9C, 0xCA, 0x53, 0xFE, 0x8F, 0x24, 0x99, 0x0D,
  42977. 0xBA, 0x7F, 0x99, 0x42, 0x11, 0x9B, 0x32, 0xDD,
  42978. 0x93, 0x5C, 0xBA, 0x2D, 0xD3, 0xB3, 0xF2, 0x48,
  42979. 0x13, 0x9C, 0x80, 0xBB, 0x8D, 0xF4, 0xC7, 0xAA,
  42980. 0xEB, 0xC6, 0xFD, 0xB8, 0x35, 0x95, 0x87, 0x2B,
  42981. 0x9E, 0xCF, 0x48, 0xF3, 0x2D, 0xFF, 0x70, 0xF4,
  42982. 0xCE, 0x35, 0x68, 0x7E, 0x9D, 0xDF, 0xD5, 0x0C,
  42983. 0xCD, 0xE3, 0x51, 0xB0, 0x90, 0x86, 0xE5, 0xD1,
  42984. 0xF1, 0x3B, 0x72, 0x42, 0x73, 0x07, 0x03, 0xE2,
  42985. 0xFB, 0x40, 0x3F, 0xD4, 0xC8, 0x30, 0xB6, 0x86,
  42986. 0x49, 0x8A, 0x17, 0xDB, 0x8F, 0x46, 0x6C, 0x3A,
  42987. 0xC3, 0x49, 0xCD, 0x59, 0x68, 0x81, 0x66, 0x03,
  42988. 0xD7, 0x24, 0xAF, 0x1F, 0x77, 0xC7, 0xFB, 0xF7,
  42989. 0x83, 0xCD, 0xA2, 0x6D, 0x35, 0x0C, 0x8B, 0xBC,
  42990. 0x29, 0x3A, 0x7F, 0xAC, 0xB9, 0xF9, 0x78, 0x50,
  42991. 0x6A, 0x67, 0xFC, 0xDC, 0x6F, 0x01, 0x65, 0x06,
  42992. 0x82, 0x81, 0xB0, 0x7D, 0x25, 0x5D, 0x74, 0x0B,
  42993. 0x68, 0x5F, 0x51, 0x2C, 0x82, 0xF3, 0x1D, 0x92,
  42994. 0xF6, 0xA9, 0xA9, 0x6A, 0x77, 0x57, 0x58, 0xAA,
  42995. 0x7C, 0xBE, 0x35, 0xF4, 0x56, 0xDE, 0x42, 0x01,
  42996. 0x2D, 0xB8, 0x28, 0x83, 0x7B, 0xA0, 0xA9, 0x7D,
  42997. 0xC3, 0x30, 0x13, 0x52, 0xD0, 0xA1, 0xC8, 0xA1,
  42998. 0x2C, 0x51, 0x49, 0xAE, 0xA8, 0x04, 0xCB, 0xA8,
  42999. 0x66, 0x01, 0x26, 0xDF, 0x2D, 0x1C, 0x21, 0xA2,
  43000. 0x4E, 0xBD, 0xA5, 0x48, 0x2A, 0x2D, 0x56, 0x60,
  43001. 0x20, 0x98, 0x4D, 0x15, 0x7D, 0x02, 0xB6, 0x3A,
  43002. 0xE4, 0x11, 0xAE, 0xF7, 0x3E, 0x5D, 0x56, 0x4F,
  43003. 0x6A, 0xA3, 0x0A, 0xEA, 0xCC, 0x35, 0x8A, 0xB7,
  43004. 0xC4, 0x8F, 0x25, 0x3E, 0x42, 0x41, 0x2B, 0xA5,
  43005. 0x1F, 0xA7, 0x3B, 0x87, 0x22, 0x86, 0x79, 0xD5,
  43006. 0xE5, 0x2A, 0xA2, 0xCD, 0x68, 0xCE, 0xB8, 0x18,
  43007. 0x6D, 0xEF, 0x1C, 0x36, 0x7F, 0x75, 0x50, 0x36,
  43008. 0x1B, 0x58, 0xEB, 0x32, 0xA1, 0xC8, 0xAF, 0x47,
  43009. 0xE1, 0x26, 0x73, 0x1F, 0x5D, 0x73, 0x30, 0x13,
  43010. 0x2F, 0xC7, 0x8B, 0xA3, 0x03, 0xB4, 0xA8, 0x86,
  43011. 0x25, 0x29, 0xD1, 0x75, 0x10, 0xEE, 0x7F, 0x56,
  43012. 0xBC, 0x0D, 0x59, 0xB4, 0xAE, 0xC9, 0x44, 0x0A,
  43013. 0xF7, 0x0D, 0xBF, 0x17, 0x6A, 0x22, 0x9C, 0x75,
  43014. 0x2B, 0x3E, 0x22, 0xB8, 0x2F, 0x4B, 0x68, 0xF1,
  43015. 0x07, 0xE3, 0x47, 0x47, 0x21, 0x9C, 0xA3, 0x5B,
  43016. 0x31, 0x0A, 0x14, 0xD9, 0x7C, 0xA8, 0xC0, 0xC6,
  43017. 0x5C, 0xAD, 0x05, 0xD6, 0x15, 0xD3, 0xEC, 0xEC,
  43018. 0x32, 0xC2, 0xFF, 0xF4, 0x96, 0x9C, 0xC8, 0x65,
  43019. 0xA0, 0xB2, 0xD6, 0xF4, 0x98, 0xBB, 0xB1, 0x4E,
  43020. 0xA5, 0x11, 0x3B, 0x4E, 0xA8, 0xEB, 0x90, 0xAB,
  43021. 0xD8, 0x25, 0x10, 0xE3, 0x66, 0xB5, 0xA5, 0x11,
  43022. 0x60, 0xA0, 0xCB, 0xDF, 0x77, 0x8A, 0x80, 0x4C,
  43023. 0x07, 0x9B, 0x1B, 0x45, 0x95, 0x29, 0x1D, 0x88,
  43024. 0x85, 0xAC, 0x32, 0x94, 0x26, 0x87, 0x12, 0x0A,
  43025. 0x2F, 0x9E, 0xAE, 0x69, 0x79, 0x25, 0x5A, 0x50,
  43026. 0xF4, 0xDB, 0x15, 0x20, 0x9F, 0x7A, 0x7A, 0xF2,
  43027. 0xE5, 0x8A, 0x63, 0x6A, 0xDD, 0xBD, 0x06, 0xCB,
  43028. 0x42, 0xF0, 0x20, 0xA9, 0x3B, 0x52, 0xD8, 0x68,
  43029. 0x37, 0x71, 0x07, 0xB8, 0x5B, 0xFE, 0xA0, 0xEC,
  43030. 0xBD, 0x75, 0xFF, 0x9C, 0x89, 0xDF, 0x01, 0xE7,
  43031. 0x17, 0x7D, 0xA7, 0xE8, 0x27, 0x9E, 0xA2, 0x41,
  43032. 0x66, 0xE6, 0xDB, 0x8B, 0x5A, 0x3F, 0x6C, 0xC9,
  43033. 0xE3, 0x4F, 0x0D, 0xD0, 0x92, 0x1E, 0x27, 0x41,
  43034. 0xF2, 0xB3, 0x08, 0x32, 0x03, 0x6D, 0x2C, 0x4F,
  43035. 0x78, 0xEC, 0x99, 0xB3, 0x94, 0x6C, 0xC1, 0x89,
  43036. 0xD9, 0x34, 0x0F, 0xEF, 0x10, 0xF0, 0xDA, 0xCE,
  43037. 0x09, 0x69, 0x7A, 0x93, 0xC6, 0xFF, 0x19, 0x4F,
  43038. 0xBD, 0xDE, 0xA6, 0x54, 0x8A, 0xE5, 0x81, 0x3F,
  43039. 0x96, 0xD3, 0xA0, 0x77, 0x7C, 0xF2, 0x4B, 0xF1,
  43040. 0x68, 0xA2, 0x23, 0x3D, 0xD4, 0x16, 0xC1, 0x66,
  43041. 0xDA, 0x13, 0x53, 0xE1, 0x9F, 0x9A, 0x36, 0x09,
  43042. 0x4D, 0x72, 0x08, 0x09, 0xEB, 0x87, 0x74, 0x9A,
  43043. 0xB2, 0x8C, 0x60, 0x7F, 0xFB, 0x70, 0x17, 0x51,
  43044. 0xB1, 0xAC, 0x18, 0xDF, 0xCB, 0x43, 0x2A, 0xD3,
  43045. 0x89, 0xDA, 0x78, 0xAE, 0xDC, 0xEA, 0xB2, 0x22,
  43046. 0xCA, 0x2F, 0xF1, 0xE4, 0xA7, 0xCC, 0xAF, 0xB1,
  43047. 0x63, 0x1B, 0x5D, 0xDD, 0xD1, 0x49, 0xB8, 0x90,
  43048. 0x2E, 0xC9, 0xC0, 0x83, 0x0D, 0xAB, 0x88, 0x88,
  43049. 0x4C, 0x74, 0x72, 0x00, 0x7D, 0xFE, 0xF2, 0x46,
  43050. 0x73, 0xFD, 0x99, 0xEC, 0x89, 0x8B, 0x3B, 0x0F,
  43051. 0xCE, 0x35, 0x5A, 0xEA, 0x13, 0x4F, 0x67, 0x67,
  43052. 0xFD, 0x0D, 0x87, 0xFC, 0xB1, 0x36, 0x48, 0x07,
  43053. 0x33, 0x0B, 0xCA, 0xD4, 0xD7, 0xD0, 0xCC, 0xA1,
  43054. 0x8F, 0xF0, 0x3F, 0x01, 0x8B, 0x6B, 0x74, 0x44,
  43055. 0x2F, 0x1B, 0xE0, 0x65, 0x31, 0x1B, 0x4E, 0xDB,
  43056. 0x67, 0x65, 0xA9, 0x34, 0xE8, 0x4D, 0x0C, 0xF3,
  43057. 0x29, 0xED, 0x53, 0xAB, 0x8A, 0x98, 0x07, 0x2B,
  43058. 0xE0, 0xCD, 0xC0, 0x08, 0x82, 0x4A, 0x72, 0x28,
  43059. 0x72, 0xA2, 0xAC, 0xFE, 0xF7, 0xBF, 0x6E, 0x8E,
  43060. 0xF8, 0x3E, 0x04, 0x58, 0xA4, 0x36, 0x46, 0x33,
  43061. 0xAB, 0xDD, 0x0E, 0xBF, 0x01, 0xD2, 0xEF, 0x19,
  43062. 0x5B, 0x78, 0x2B, 0x30, 0x51, 0x25, 0x50, 0xD0,
  43063. 0xB5, 0x82, 0xC7, 0x20, 0x0D, 0xA1, 0x2C, 0x38,
  43064. 0xAF, 0x44, 0xFC, 0xBD, 0x49, 0xB8, 0x7F, 0x89,
  43065. 0xEF, 0xBE, 0x37, 0x5C, 0xCB, 0xA2, 0x11, 0x75,
  43066. 0x7D, 0xDA, 0xA8, 0x7B, 0x3A, 0x3C, 0x10, 0x11,
  43067. 0x4D, 0x9F, 0x99, 0xAB, 0x4B, 0xA2, 0x20, 0x7A,
  43068. 0x5F, 0x96, 0xEF, 0x1C, 0x00, 0xD7, 0x27, 0x17,
  43069. 0x77, 0x7C, 0x51, 0x58, 0x4B, 0x13, 0x97, 0x53,
  43070. 0x2A, 0xC6, 0x86, 0x4D, 0x3B, 0x8E, 0xBB, 0x4F,
  43071. 0xB8, 0xA0, 0x84, 0x87, 0xF6, 0xEF, 0x55, 0x12,
  43072. 0x2B, 0xCF, 0x9E, 0x5C, 0xD0, 0x0E, 0xBC, 0x1E,
  43073. 0x79, 0x53, 0xE7, 0x8C, 0x4D, 0x8B, 0xCB, 0x20,
  43074. 0xF6, 0xEA, 0x72, 0x0A, 0x63, 0x2F, 0x0C, 0xCF,
  43075. 0x57, 0x27, 0x26, 0xF4, 0x3A, 0x95, 0xCA, 0xBE,
  43076. 0xB5, 0x7C, 0x47, 0x60, 0x10, 0xCD, 0x28, 0x9E,
  43077. 0x02, 0x64, 0xC9, 0x8D, 0x82, 0x49, 0xD0, 0xD6,
  43078. 0x60, 0xF8, 0xDC, 0xC8, 0x4B, 0x7D, 0xB5, 0xEF,
  43079. 0x11, 0x17, 0xC7, 0x94, 0x5F, 0x0D, 0x99, 0xBE,
  43080. 0x75, 0x48, 0x49, 0xC6, 0x58, 0x43, 0x64, 0x99,
  43081. 0x1A, 0x5A, 0x41, 0xBA, 0xC2, 0x31, 0xB3, 0xE0,
  43082. 0x45, 0x1B, 0x81, 0xD2, 0x12, 0xBE, 0x90, 0xDB,
  43083. 0xFF, 0xBC, 0xCB, 0x99, 0xA3, 0xF0, 0x74, 0xE8,
  43084. 0x2C, 0x48, 0x58, 0xB3, 0x17, 0xA4, 0x9A, 0xD2,
  43085. 0x22, 0x46, 0xFB, 0xF5, 0x85, 0x8D, 0x07, 0xDF,
  43086. 0xDB, 0x78, 0x07, 0xF4, 0x99, 0xA8, 0x6C, 0xEE,
  43087. 0x6E, 0x96, 0x20, 0xB8, 0xC2, 0xA9, 0xFA, 0x8B,
  43088. 0x6E, 0xA6, 0x79, 0x6D, 0xF9, 0xC3, 0x0C, 0x77,
  43089. 0x74, 0xAE, 0xB0, 0x40, 0xA9, 0xE5, 0xA7, 0x0B,
  43090. 0x30, 0x40, 0x4B, 0x4F, 0xB1, 0x0A, 0x0B, 0x7B,
  43091. 0xEE, 0x1F, 0x69, 0xFA, 0xD0, 0xF0, 0x2D, 0x5D,
  43092. 0x00, 0xB5, 0x4D, 0xEB, 0x32, 0x84, 0xB2, 0xB7,
  43093. 0x60, 0xAA, 0x6C, 0xF9, 0x98, 0x18, 0xB3, 0xD9,
  43094. 0xC1, 0x54, 0x8D, 0xAC, 0x12, 0xB0, 0x3A, 0x26,
  43095. 0xB2, 0x23, 0x2D, 0x9B, 0xF8, 0x20, 0xEE, 0x90,
  43096. 0xE0, 0x6D, 0x31, 0xDE, 0xF5, 0xCA, 0xBA, 0x6A,
  43097. 0x53, 0x40, 0x29, 0x6C, 0x18, 0x62, 0xA5, 0x8A,
  43098. 0xB8, 0x17, 0xA0, 0xAB, 0xCB, 0xDC, 0xE1, 0x3B,
  43099. 0xD6, 0xC6, 0x29, 0xA3, 0x1C, 0x5F, 0x8D, 0x6E,
  43100. 0x73, 0xF6, 0x98, 0x10, 0x0F, 0x9F, 0x7E, 0xCA,
  43101. 0x4C, 0xD8, 0xEB, 0xE4, 0xB8, 0xDF, 0x72, 0x78,
  43102. 0x65, 0xAF, 0x4A, 0x20, 0xFE, 0x7C, 0xB4, 0xCA,
  43103. 0x07, 0x81, 0xFD, 0xC5, 0xC5, 0xFD, 0x33, 0x4D,
  43104. 0xB8, 0x37, 0x37, 0xC4, 0x21, 0x81, 0x66, 0x45,
  43105. 0xAE, 0x81, 0x34, 0x13, 0xA6, 0x40, 0x81, 0x39,
  43106. 0x55, 0x90, 0xE6, 0xF1, 0x42, 0x56, 0x74, 0xFF,
  43107. 0x06, 0x9B, 0x50, 0x1F, 0x0F, 0xDA, 0x6B, 0x31,
  43108. 0xC6, 0x4B, 0xC5, 0xC2, 0x14, 0xE7, 0x01, 0x5E,
  43109. 0xA9, 0xDA, 0x12, 0x2D, 0x6C, 0xE0, 0x8C, 0xEB,
  43110. 0x2D, 0xF6, 0x2C, 0x45, 0xBC, 0x01, 0x73, 0x34,
  43111. 0x6D, 0xAB, 0xBC, 0x15, 0x4C, 0x16, 0x03, 0x35,
  43112. 0x9D, 0xD4, 0xF0, 0xAC, 0x49, 0x84, 0x4A, 0xEE,
  43113. 0x46, 0x47, 0x64, 0x93, 0xF2, 0x49, 0x59, 0x86,
  43114. 0x26, 0xFB, 0x24, 0x6B, 0x99, 0xB3, 0x9A, 0xCB,
  43115. 0xB4, 0x2B, 0x28, 0x4E, 0x0C, 0x2D, 0x3F, 0x9E,
  43116. 0xCE, 0x32, 0x71, 0xC4, 0xD5, 0xE0, 0x6C, 0x48,
  43117. 0x25, 0xEA, 0x1A, 0x8F, 0x08, 0x57, 0x23, 0x85,
  43118. 0x89, 0xCD, 0xC5, 0x48, 0x37, 0x19, 0x8E, 0xD4,
  43119. 0x23, 0x4D, 0xD0, 0x31, 0x73, 0xA8, 0x8E, 0x43,
  43120. 0xEE, 0x95, 0x67, 0xF5, 0x7A, 0x93, 0x27, 0xD3,
  43121. 0x90, 0x36, 0x30, 0x4C, 0xA1, 0xCD, 0xB5, 0xF8,
  43122. 0x65, 0xC5, 0x89, 0x54, 0x57, 0x2C, 0xAE, 0xF8,
  43123. 0x75, 0xF1, 0x2E, 0x14, 0x14, 0x14, 0x0D, 0x97,
  43124. 0x5B, 0x24, 0x52, 0x46, 0x7A, 0x57, 0x6D, 0x9C,
  43125. 0x4C, 0x79, 0xDB, 0x0A, 0xE0, 0x23, 0x69, 0x52,
  43126. 0x9B, 0xF8, 0x1B, 0x54, 0x40, 0x18, 0xDF, 0xE0,
  43127. 0x1E, 0xF0, 0x61, 0xE4, 0x79, 0x81, 0xF9, 0x98,
  43128. 0x9A, 0x8C, 0x48, 0xFF, 0x86, 0x93, 0x0B, 0x68,
  43129. 0x96, 0x78, 0x2F, 0xF1, 0x2D, 0xDC, 0x60, 0x1F,
  43130. 0x8B, 0x1C, 0x04, 0x43, 0x4E, 0x60, 0x96, 0x5B,
  43131. 0x8A, 0xF6, 0x89, 0xCC, 0xC8, 0xB2, 0x9B, 0xBF,
  43132. 0x87, 0x16, 0x2E, 0xA8, 0x6F, 0x9B, 0x4B, 0xFD,
  43133. 0x74, 0x4E, 0x8F, 0x36, 0x33, 0x23, 0xDE, 0x94,
  43134. 0xD2, 0xA1, 0x72, 0x4F, 0xB2, 0xE6, 0x75, 0x3D,
  43135. 0x6E, 0x47, 0x9B, 0xDB, 0x58, 0xE5, 0x4A, 0x0C,
  43136. 0x09, 0x8F, 0x9C, 0x83, 0x63, 0x98, 0x8B, 0xA4,
  43137. 0xF7, 0x3D, 0x01, 0xA6, 0x8B, 0x93, 0x97, 0x48,
  43138. 0x84, 0x75, 0x32, 0xC7, 0xD7, 0x03, 0xDF, 0x7E,
  43139. 0x94, 0x8C, 0x8A, 0xA6, 0x78, 0x1A, 0xAE, 0xDE,
  43140. 0x36, 0x8A, 0xAD, 0x13, 0x7E, 0xF0, 0x16, 0xC2,
  43141. 0x3B, 0xAF, 0xF9, 0xD8, 0x66, 0x12, 0x30, 0x72,
  43142. 0x76, 0x6D, 0x21, 0x4C, 0xF3, 0xEF, 0x0D, 0x8C,
  43143. 0x11, 0xA4, 0x12, 0xBE, 0xF5, 0x7E, 0x8E, 0x6A,
  43144. 0x11, 0x13, 0x48, 0x8D, 0xC2, 0x62, 0xCF, 0x45,
  43145. 0x7C, 0xE3, 0x91, 0x88, 0x59, 0xFF, 0xB0, 0xF1,
  43146. 0xC3, 0xBC, 0x1D, 0x2A, 0x3E, 0x9B, 0x78, 0xF3,
  43147. 0xB1, 0x2E, 0xB0, 0x27, 0xD8, 0x16, 0xF8, 0x9B,
  43148. 0x2A, 0xAF, 0xF1, 0xAB, 0xB0, 0xF1, 0x8C, 0x7F,
  43149. 0x94, 0x31, 0x97, 0x85, 0xDA, 0xF0, 0xF4, 0x27,
  43150. 0x51, 0x3E, 0x5A, 0xE1, 0xDD, 0x6D, 0x9E, 0x98,
  43151. 0x39, 0xBB, 0xDF, 0xA2, 0xBA, 0x2C, 0x08, 0xAD,
  43152. 0x1D, 0x3F, 0x86, 0xF6, 0xC2, 0x1A, 0x8C, 0xAD,
  43153. 0xE0, 0xDC, 0xDD, 0x02, 0x47, 0x4C, 0x7E, 0x2D,
  43154. 0xDA, 0x1D, 0x70, 0x92, 0x39, 0xAA, 0x4E, 0xBA,
  43155. 0x14, 0xC7, 0xEC, 0x26, 0xBD, 0x9D, 0x1F, 0x6D,
  43156. 0x91, 0x58, 0x3C, 0xB5, 0xEF, 0x37, 0xB9, 0x66,
  43157. 0x4E, 0x04, 0x7C, 0x29, 0xCF, 0xD7, 0x8E, 0x47,
  43158. 0x84, 0xF3, 0xD2, 0x21, 0x84, 0xC5, 0xF8, 0xDC,
  43159. 0xC9, 0xF2, 0x52, 0xD5, 0x6A, 0xBF, 0xF1, 0xF1,
  43160. 0xDE, 0x9E, 0x7A, 0xF1, 0xD5, 0x5A, 0xF6, 0xEF,
  43161. 0x94, 0x66, 0xF9, 0x25, 0x44, 0x7F, 0x8D, 0x92,
  43162. 0xA2, 0x25, 0x1C, 0x72, 0x92, 0x30, 0x2A, 0xB7,
  43163. 0xEF, 0x18, 0xF3, 0x8C, 0xEF, 0x69, 0xA5, 0x5C,
  43164. 0x19, 0x3E, 0xC5, 0xBD, 0xEE, 0x2C, 0x2D, 0x71,
  43165. 0xDB, 0x89, 0xD4, 0x11, 0xA6, 0x27, 0x80, 0x8F,
  43166. 0x5A, 0x39, 0x9A, 0x04, 0x28, 0x4F, 0x9F, 0x00,
  43167. 0xBE, 0xF9, 0xF7, 0x9B, 0x46, 0x69, 0xD6, 0xAC,
  43168. 0x12, 0xE9, 0xA7, 0xC2, 0xD1, 0xC8, 0xAD, 0x5D,
  43169. 0xF7, 0xCB, 0x0C, 0x98, 0x78, 0x2D, 0x04, 0x4D,
  43170. 0x2D, 0x41, 0xAB, 0xC6, 0x3F, 0x81, 0x1D, 0xB9,
  43171. 0x2C, 0x1F, 0x3F, 0x59, 0x11, 0xF4, 0x80, 0x4F,
  43172. 0x0B, 0xCA, 0x9F, 0x81, 0x6E, 0x9C, 0xD1, 0xB4,
  43173. 0x74, 0x06, 0x48, 0x0A, 0x87, 0x2C, 0xFD, 0x4D,
  43174. 0x85, 0xD4, 0x21, 0x65, 0x7C, 0x96, 0x69, 0x53,
  43175. 0x51, 0xC0, 0xC4, 0xB0, 0xEB, 0x20, 0xDB, 0xE0,
  43176. 0x41, 0x09, 0xA7, 0x62, 0xB2, 0xF3, 0xC7, 0x6A,
  43177. 0x1D, 0x53, 0xA0, 0x39, 0xBA, 0xCF, 0x78, 0x9E,
  43178. 0xBF, 0x1D, 0xA5, 0x98, 0x09, 0x8E, 0xA7, 0x1A,
  43179. 0xE7, 0x95, 0xFF, 0x10, 0x38, 0xCC, 0x8F, 0x44,
  43180. 0xCB, 0xE7, 0xF6, 0xD6, 0x2C, 0xFF, 0xA8, 0x1C,
  43181. 0xFF, 0xA3, 0x65, 0xE8, 0x4E, 0xAE, 0xC7, 0xEF,
  43182. 0x61, 0xE1, 0x16, 0x4B, 0x8C, 0xA8, 0xC8, 0xFB,
  43183. 0xA5, 0x2C, 0xD1, 0x0A, 0x39, 0xAB, 0x4A, 0xF9,
  43184. 0xEE, 0x0B, 0x9B, 0xB4, 0x33, 0x5E, 0x25, 0x15,
  43185. 0xD0, 0xAA, 0x93, 0xC4, 0x53, 0x42, 0x91, 0xC5,
  43186. 0x98, 0x15, 0x34, 0x9A, 0x22, 0x1D, 0x9A, 0xE7,
  43187. 0x0E, 0x81, 0xF6, 0x99, 0x55, 0xB3, 0xD6, 0x49,
  43188. 0x1B, 0xB8, 0xA8, 0xBE, 0xDF, 0x54, 0xF0, 0x78,
  43189. 0xF7, 0x02, 0x97, 0x74, 0x84, 0x67, 0x6B, 0xAE,
  43190. 0x2F, 0xEC, 0x6E, 0x59, 0x20, 0x68, 0xD8, 0xE3,
  43191. 0x5A, 0x07, 0x48, 0xE1, 0x99, 0x90, 0xEE, 0xCD,
  43192. 0x17, 0x2B, 0xB6, 0xD6, 0xAA, 0x1A, 0xF8, 0x97,
  43193. 0x4E, 0xE0, 0x67, 0x9E, 0x4C, 0x35, 0xFE, 0x68,
  43194. 0x71, 0x54, 0x43, 0x5D, 0x43, 0x59, 0x19, 0xEB,
  43195. 0x58, 0x8E, 0x9A, 0xF6, 0xBD, 0x88, 0x71, 0xEE,
  43196. 0x89, 0xC6, 0xF2, 0x10, 0x04, 0x33, 0x13, 0x88,
  43197. 0xCD, 0x08, 0xB5, 0xE3, 0x5D, 0xA8, 0xBC, 0x43,
  43198. 0xB3, 0x84, 0x5F, 0x70, 0x94, 0xD9, 0xAC, 0xAE,
  43199. 0x74, 0x70, 0x13, 0x1E, 0x21, 0xFB, 0xD5, 0x7F,
  43200. 0xEC, 0x66, 0x2F, 0xA0, 0xB1, 0x1D, 0xE3, 0xF8,
  43201. 0xB9, 0x36, 0x48, 0x25, 0x3D, 0xBA, 0x7D, 0x44,
  43202. 0x08, 0xC5, 0x71, 0x74, 0xDA, 0xD3, 0x4F, 0x97,
  43203. 0x86, 0xF1, 0x16, 0x38, 0xD8, 0xC9, 0xE3, 0x3A,
  43204. 0xA7, 0x2E, 0x06, 0x4D, 0x9D, 0xE8, 0xFC, 0x38,
  43205. 0x58, 0x2A, 0x8D, 0x2D, 0x07, 0x99, 0xEA, 0xDF,
  43206. 0xF3, 0x00, 0x3B, 0xBC, 0x5F, 0x67, 0x1E, 0x4B,
  43207. 0x6C, 0xF1, 0x4A, 0x47, 0xB0, 0x71, 0x90, 0x5A,
  43208. 0x3B, 0x75, 0x93, 0x75, 0x56, 0x50, 0x4C, 0x70,
  43209. 0xF3, 0xC7, 0x95, 0xD5, 0xEA, 0xCB, 0x4C, 0x92,
  43210. 0x4F, 0x22, 0x4F, 0xD9, 0x34, 0x46, 0x76, 0xFB,
  43211. 0x79, 0xD6, 0xBD, 0x4E, 0x84, 0xEE, 0xE7, 0x78,
  43212. 0x7C, 0xB8, 0x92, 0x9F, 0xAD, 0xF2, 0x17, 0x5D,
  43213. 0x38, 0xB1, 0x88, 0x2E, 0xE9, 0x65, 0xAC, 0x4C,
  43214. 0x24, 0x27, 0x1D, 0x7B, 0xA3, 0x69, 0x96, 0x55,
  43215. 0x5C, 0x26, 0x40, 0xAF, 0x04, 0xB1, 0xCE, 0xA8,
  43216. 0x5D, 0x1E, 0x1F, 0xE5, 0x5A, 0xC3, 0xAE, 0xF9,
  43217. 0x14, 0x03, 0x58, 0x10, 0x1C, 0x8B, 0x1F, 0xDB,
  43218. 0x6C, 0x71, 0x68, 0x60, 0x13, 0x32, 0xF1, 0xA9,
  43219. 0x69, 0x45, 0x28, 0x69, 0x7C, 0xE3, 0xC9, 0x56,
  43220. 0xAF, 0xF3, 0xBD, 0x4B, 0x9E, 0x0A, 0x06, 0x6A,
  43221. 0x62, 0x20, 0x40, 0x65, 0xBD, 0xBC, 0xBF, 0xC7,
  43222. 0x0A, 0x2A, 0xCF, 0x56, 0x7C, 0x0E, 0x64, 0xBB,
  43223. 0x64, 0x71, 0x2D, 0x90, 0xBB, 0x32, 0x00, 0x0A,
  43224. 0x4A, 0x45, 0x44, 0x08, 0x75, 0x2C, 0x86, 0x13,
  43225. 0x86, 0x52, 0x8D, 0x3D, 0xFC, 0xF3, 0x5E, 0x5B,
  43226. 0x3F, 0x7A, 0xAA, 0x98, 0x84, 0xCF, 0x92, 0xF9,
  43227. 0x0B, 0x40, 0x8F, 0xC0, 0xA3, 0x71, 0x84, 0xAD,
  43228. 0xEE, 0xDF, 0xC4, 0x91, 0x7E, 0x87, 0x7D, 0x06,
  43229. 0xCA, 0x65, 0x8C, 0xE4, 0x8E, 0x03, 0xF0, 0x59,
  43230. 0x3E, 0xB4, 0x90, 0x4C, 0xEE, 0x88, 0x29, 0xE4,
  43231. 0x26, 0x7D, 0xA6, 0x54, 0x82, 0x49, 0xC1, 0x9D,
  43232. 0x80, 0xAB, 0x6B, 0xD7, 0xBE, 0x7D, 0x09, 0x80,
  43233. 0x5E, 0xB6, 0xD1, 0x1E, 0xD1, 0x1B, 0xE9, 0x8D,
  43234. 0xFC, 0x6E, 0x9C, 0x14, 0x0C, 0x15, 0x02, 0x87,
  43235. 0xF3, 0x9D, 0x21, 0xF8, 0xCB, 0xC8, 0xB9, 0xBD,
  43236. 0xE1, 0x70, 0xEA, 0xE4, 0x86, 0x4C, 0x97, 0xC1,
  43237. 0xEE, 0x4C, 0x18, 0x95, 0xEC, 0xD2, 0x4D, 0x35,
  43238. 0x9F, 0xC6, 0x56, 0x10, 0x3E, 0xC0, 0xB9, 0x7B,
  43239. 0x13, 0x1A, 0x37, 0x3D, 0x40, 0x4C, 0x88, 0x8B,
  43240. 0x9A, 0xA5, 0xB2, 0xB8, 0xB9, 0xC3, 0xEC, 0xF1,
  43241. 0x14, 0x33, 0x63, 0x67, 0x84, 0x98, 0xC8, 0xF4,
  43242. 0x06, 0x0C, 0x0E, 0x0F, 0x10, 0x12, 0x15, 0x16,
  43243. 0x45, 0x4E, 0x55, 0x5A, 0x5F, 0x8A, 0x94, 0x97,
  43244. 0xA8, 0xAF, 0xB2, 0xCC, 0xD4, 0xDC, 0xE7, 0xF1,
  43245. 0xFE, 0xFF, 0x11, 0x24, 0x53, 0x62, 0x94, 0xB7,
  43246. 0xB9, 0xD3, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00,
  43247. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  43248. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  43249. 0x10, 0x18, 0x32, 0x3B
  43250. };
  43251. #endif
  43252. #ifndef WOLFSSL_NO_ML_DSA_65
  43253. static const byte pk_65_draft[] = {
  43254. 0x6C, 0x84, 0x14, 0x38, 0x08, 0x56, 0xCB, 0x52,
  43255. 0xD7, 0x9C, 0x4B, 0x29, 0x13, 0x9F, 0xB1, 0x83,
  43256. 0x9B, 0x86, 0x06, 0xF5, 0x94, 0x8B, 0x9D, 0x72,
  43257. 0xA9, 0x56, 0xDC, 0xF1, 0x01, 0x16, 0xDA, 0x9E,
  43258. 0x2D, 0x79, 0x77, 0x01, 0x86, 0xFC, 0x74, 0xD9,
  43259. 0x42, 0xC0, 0xF4, 0xA3, 0xB5, 0x95, 0xFF, 0x6C,
  43260. 0x19, 0x80, 0x4B, 0x49, 0x90, 0x1C, 0x6A, 0xD5,
  43261. 0xFA, 0xF7, 0x16, 0x01, 0xC2, 0xB6, 0x00, 0x31,
  43262. 0x5E, 0x1F, 0x40, 0xC2, 0x05, 0x47, 0x67, 0xB0,
  43263. 0x09, 0x25, 0xDF, 0x3A, 0xA4, 0x90, 0xE8, 0xC7,
  43264. 0x6F, 0x05, 0xFB, 0xFB, 0x74, 0x91, 0x10, 0x75,
  43265. 0xE6, 0x51, 0x8C, 0x5F, 0x1D, 0x91, 0xB8, 0xA0,
  43266. 0xE5, 0xB5, 0x98, 0x30, 0xD3, 0xDF, 0x39, 0x94,
  43267. 0x76, 0x04, 0x11, 0xEB, 0xB9, 0x11, 0xED, 0x4C,
  43268. 0xC2, 0xC1, 0x60, 0xE3, 0x84, 0x9A, 0x93, 0x76,
  43269. 0x2D, 0xFC, 0xA7, 0xB9, 0x81, 0x2B, 0xC7, 0xAE,
  43270. 0xB2, 0xDD, 0xB2, 0x76, 0x7B, 0xEF, 0x36, 0x50,
  43271. 0x56, 0x05, 0xAE, 0x06, 0x92, 0x60, 0xBC, 0xC8,
  43272. 0xDC, 0x47, 0x87, 0xC4, 0x28, 0xCB, 0x3C, 0x07,
  43273. 0x6E, 0xF2, 0xA6, 0xB9, 0x35, 0x61, 0xD8, 0x94,
  43274. 0x3F, 0x45, 0xCA, 0xBE, 0x8F, 0x05, 0x53, 0xFF,
  43275. 0x2E, 0xA1, 0xAC, 0x95, 0xC1, 0xCE, 0x21, 0x59,
  43276. 0x3A, 0x17, 0x54, 0x59, 0xD7, 0xDF, 0x12, 0xC4,
  43277. 0x07, 0x0A, 0xDB, 0x0E, 0xEE, 0x55, 0xB4, 0xAB,
  43278. 0xAE, 0x59, 0xBE, 0x69, 0xC3, 0xFF, 0x0D, 0xE5,
  43279. 0xA9, 0xB0, 0x27, 0xFC, 0x7D, 0x8E, 0x6E, 0x05,
  43280. 0x7B, 0x71, 0x52, 0xEE, 0x6A, 0xB4, 0x80, 0xD1,
  43281. 0x05, 0xD3, 0x0B, 0x0F, 0x50, 0x51, 0xB6, 0x0C,
  43282. 0x79, 0x01, 0xC5, 0x25, 0xC4, 0x63, 0x5F, 0xE6,
  43283. 0x68, 0xCC, 0x00, 0xE9, 0xD3, 0x09, 0x7D, 0xB9,
  43284. 0x9D, 0x66, 0x32, 0x37, 0x15, 0xCE, 0x4F, 0x0B,
  43285. 0x79, 0xB4, 0x26, 0xB4, 0x54, 0x5E, 0x09, 0xF4,
  43286. 0xDE, 0x39, 0x32, 0x3D, 0xD1, 0x4C, 0xCB, 0x0D,
  43287. 0x17, 0x10, 0x8C, 0xD4, 0x6D, 0xEC, 0x61, 0x38,
  43288. 0xCD, 0xFA, 0x28, 0x72, 0xC1, 0xC4, 0xC8, 0xAE,
  43289. 0xAD, 0x5C, 0x8C, 0xE0, 0x41, 0x57, 0xE5, 0x53,
  43290. 0xA3, 0x75, 0x58, 0xC2, 0x34, 0x6A, 0x06, 0x19,
  43291. 0x4C, 0xB5, 0x0B, 0x49, 0x81, 0xBF, 0x4D, 0x09,
  43292. 0x0C, 0xE4, 0xE8, 0x60, 0x12, 0x6A, 0x82, 0x54,
  43293. 0xA4, 0xD4, 0xC0, 0x84, 0xC3, 0xE2, 0x02, 0x0B,
  43294. 0xC0, 0x75, 0x35, 0x21, 0x04, 0x9B, 0x0F, 0xD8,
  43295. 0x89, 0x97, 0xE0, 0x27, 0xAC, 0x51, 0xE7, 0x5C,
  43296. 0xF1, 0x35, 0x0C, 0x3F, 0x30, 0x3A, 0x0E, 0xCE,
  43297. 0x42, 0x64, 0x87, 0x15, 0x3D, 0xAF, 0x1F, 0xAA,
  43298. 0xD6, 0x80, 0x8B, 0x9D, 0x99, 0x07, 0xDA, 0x9F,
  43299. 0x35, 0x18, 0x5B, 0xD3, 0xBE, 0x8D, 0x9C, 0xEB,
  43300. 0xE9, 0x16, 0xCE, 0xD1, 0xFA, 0x29, 0x28, 0xD8,
  43301. 0x85, 0xA9, 0xCB, 0xA8, 0x81, 0x49, 0x70, 0x3F,
  43302. 0x5E, 0x47, 0x72, 0xE4, 0x85, 0x23, 0x12, 0x5D,
  43303. 0xDD, 0x02, 0x6E, 0x71, 0x4C, 0x49, 0xF4, 0xFB,
  43304. 0x4E, 0x54, 0x4B, 0xBF, 0x61, 0x7A, 0x40, 0xB0,
  43305. 0x0B, 0x68, 0xDF, 0x8F, 0x15, 0x5F, 0x58, 0x80,
  43306. 0xD4, 0x11, 0x87, 0x7E, 0x25, 0xB4, 0x2B, 0x24,
  43307. 0x48, 0xB3, 0x6B, 0xEC, 0x2F, 0x1F, 0x8F, 0x9A,
  43308. 0x77, 0x0C, 0x54, 0x51, 0x50, 0xA0, 0x27, 0x8E,
  43309. 0x9B, 0x72, 0x45, 0x00, 0xAE, 0xAA, 0xEA, 0x47,
  43310. 0x1C, 0x11, 0xCF, 0xF0, 0x4E, 0x30, 0xEA, 0xB2,
  43311. 0xF4, 0x73, 0xBC, 0x04, 0x8E, 0x32, 0xCD, 0x31,
  43312. 0xAE, 0xF2, 0x15, 0x79, 0xB6, 0x99, 0x22, 0x5B,
  43313. 0xF9, 0xE1, 0xB6, 0x70, 0x0C, 0x57, 0xE5, 0x09,
  43314. 0xFC, 0xA1, 0xF2, 0x36, 0x29, 0x4A, 0x59, 0x74,
  43315. 0xDA, 0xA1, 0x5F, 0xBC, 0xAD, 0x62, 0xD4, 0xBD,
  43316. 0xDC, 0x45, 0x32, 0xB2, 0x61, 0x41, 0x44, 0xDB,
  43317. 0xE2, 0x88, 0x07, 0x36, 0x8C, 0x28, 0x1A, 0x77,
  43318. 0x0E, 0xA2, 0x2B, 0x1E, 0x5A, 0x3F, 0xA5, 0xBA,
  43319. 0x14, 0x92, 0x6D, 0xC5, 0x5A, 0x54, 0xF8, 0x4A,
  43320. 0x2A, 0x77, 0xC5, 0xA7, 0x08, 0x41, 0xF0, 0x7B,
  43321. 0xC1, 0xDE, 0xEF, 0x74, 0x03, 0xB2, 0x47, 0xAB,
  43322. 0x42, 0xB8, 0x4A, 0xDF, 0x14, 0x1E, 0x03, 0x0C,
  43323. 0x98, 0x46, 0x84, 0x24, 0xDA, 0xAE, 0xB9, 0x9D,
  43324. 0x25, 0x77, 0xF9, 0x50, 0xC2, 0x37, 0x3C, 0xCA,
  43325. 0x1E, 0x2D, 0xC2, 0x76, 0x1B, 0x8E, 0xDD, 0x6D,
  43326. 0x08, 0xFF, 0x79, 0xE5, 0x28, 0x88, 0x0F, 0xFB,
  43327. 0x51, 0xC3, 0x6E, 0xD4, 0x20, 0xAC, 0x5D, 0x50,
  43328. 0xF2, 0x58, 0x2A, 0xA6, 0x64, 0xE5, 0x4E, 0xA5,
  43329. 0xF4, 0x18, 0x9E, 0xA0, 0x17, 0x6D, 0xAA, 0x61,
  43330. 0x22, 0xF6, 0x23, 0x5A, 0x70, 0xB1, 0x5C, 0xEB,
  43331. 0x4D, 0xDD, 0x65, 0xD3, 0xBE, 0x6E, 0xBF, 0x3D,
  43332. 0xC4, 0x31, 0x89, 0xEE, 0x0A, 0x2E, 0x31, 0x05,
  43333. 0x63, 0x8F, 0x23, 0x87, 0x36, 0x95, 0x28, 0x0F,
  43334. 0x1B, 0x74, 0x27, 0x43, 0x52, 0xD6, 0x0A, 0x48,
  43335. 0xE5, 0xD3, 0xDD, 0x02, 0xFB, 0x7A, 0x5E, 0xD8,
  43336. 0x3F, 0xE2, 0x7A, 0x69, 0x82, 0x51, 0x42, 0x1C,
  43337. 0x8E, 0x9C, 0x98, 0x80, 0x61, 0x02, 0x39, 0x6E,
  43338. 0x53, 0x73, 0x90, 0xAC, 0xFD, 0x8C, 0x1D, 0x0B,
  43339. 0x4F, 0x99, 0xB7, 0x02, 0xA9, 0xEA, 0x65, 0x98,
  43340. 0x78, 0x58, 0x3D, 0x92, 0x75, 0x89, 0x41, 0xB3,
  43341. 0x0E, 0xCE, 0x50, 0x7C, 0x10, 0x4B, 0x2C, 0xE4,
  43342. 0x87, 0x67, 0x9E, 0xCF, 0x68, 0xB4, 0xD8, 0xB9,
  43343. 0x80, 0x69, 0x8A, 0xCF, 0x6A, 0xA6, 0xA5, 0x7E,
  43344. 0x8E, 0xD6, 0xAF, 0x3F, 0xF1, 0x8D, 0x26, 0x68,
  43345. 0x95, 0x04, 0x28, 0xB5, 0x7D, 0x18, 0x2F, 0x73,
  43346. 0xBB, 0x49, 0xB9, 0xB0, 0x38, 0xCC, 0xC8, 0x2D,
  43347. 0x56, 0x12, 0x78, 0xA3, 0x86, 0xD5, 0x66, 0x45,
  43348. 0xEC, 0x3F, 0xAF, 0xFB, 0x41, 0x25, 0xE0, 0xE7,
  43349. 0xF3, 0x6B, 0x48, 0xB1, 0x4B, 0x45, 0x25, 0x47,
  43350. 0xA0, 0xB4, 0x81, 0xAA, 0x6B, 0x33, 0x42, 0x29,
  43351. 0x24, 0x91, 0x53, 0xE4, 0x2E, 0xDF, 0x7E, 0x49,
  43352. 0xDD, 0x6E, 0x76, 0x36, 0xBF, 0xC6, 0x15, 0xA2,
  43353. 0x3A, 0x40, 0x1E, 0xFD, 0x40, 0x34, 0xC8, 0x1B,
  43354. 0x4D, 0xCE, 0xF0, 0x27, 0xD3, 0x44, 0xDD, 0xCC,
  43355. 0xE0, 0xA7, 0x16, 0x18, 0xEB, 0x59, 0x10, 0xCE,
  43356. 0xC6, 0x22, 0x28, 0x81, 0x93, 0x85, 0x03, 0x3E,
  43357. 0x8D, 0x0A, 0xBD, 0x49, 0x3D, 0x98, 0x3E, 0x4F,
  43358. 0xC0, 0x87, 0xD7, 0x2B, 0x45, 0x5E, 0x4D, 0xB6,
  43359. 0x3A, 0x2F, 0x82, 0xCE, 0xFF, 0x65, 0xC1, 0xE6,
  43360. 0x28, 0xEA, 0xE6, 0x30, 0x59, 0x6D, 0xEC, 0x27,
  43361. 0xFB, 0x98, 0xB8, 0x4D, 0xBF, 0xDC, 0xDF, 0xAB,
  43362. 0x40, 0xE4, 0x72, 0x24, 0x49, 0x14, 0xAF, 0xF1,
  43363. 0x79, 0x32, 0x6D, 0x54, 0x2D, 0x40, 0x1A, 0x3C,
  43364. 0xBB, 0x86, 0xE5, 0xFF, 0x83, 0x51, 0xEF, 0xE5,
  43365. 0x3A, 0x73, 0xC5, 0x1A, 0xBB, 0x63, 0xFF, 0x55,
  43366. 0x3E, 0x7D, 0x79, 0x57, 0xEF, 0x89, 0x13, 0x5E,
  43367. 0x0F, 0x5B, 0xB1, 0xBD, 0x0C, 0x24, 0xF9, 0xE4,
  43368. 0x5E, 0x32, 0x36, 0x41, 0x3C, 0x60, 0xE1, 0x39,
  43369. 0x6A, 0x47, 0x56, 0x7C, 0x94, 0x39, 0x51, 0x0F,
  43370. 0x00, 0xD4, 0xA4, 0x3C, 0x14, 0x9A, 0x5C, 0xCC,
  43371. 0x04, 0xF3, 0xD4, 0x7E, 0x67, 0xA8, 0xE2, 0x94,
  43372. 0xA4, 0x61, 0xA5, 0xF6, 0x93, 0xDB, 0x0C, 0xAE,
  43373. 0x22, 0xCF, 0xAC, 0x61, 0xE8, 0x53, 0x47, 0x7D,
  43374. 0x33, 0x9A, 0x4E, 0x45, 0xF7, 0xB1, 0x7C, 0x3C,
  43375. 0x11, 0x6D, 0x56, 0xF3, 0xA0, 0x68, 0xFC, 0x5A,
  43376. 0xDF, 0xEF, 0x38, 0xFF, 0x85, 0x33, 0x2B, 0xD5,
  43377. 0x15, 0x3C, 0x4D, 0x8F, 0xB8, 0xF1, 0x48, 0xF1,
  43378. 0x17, 0x65, 0x9C, 0x2E, 0xA9, 0x4D, 0xB4, 0x2A,
  43379. 0xA0, 0xB0, 0xBE, 0xBB, 0x47, 0x5A, 0x11, 0x04,
  43380. 0x12, 0xF3, 0xCD, 0x33, 0x49, 0xFC, 0x1A, 0xD0,
  43381. 0x41, 0xB7, 0xD5, 0x30, 0x4A, 0x85, 0x93, 0x14,
  43382. 0x4E, 0xFA, 0x3A, 0x36, 0x1D, 0x1B, 0x0C, 0x76,
  43383. 0x13, 0xB8, 0x2C, 0x08, 0x6E, 0xA7, 0x12, 0x6E,
  43384. 0x43, 0xC6, 0x16, 0xCE, 0xE8, 0xF1, 0x44, 0x4E,
  43385. 0x99, 0x56, 0xE8, 0x7F, 0x5C, 0xAB, 0x95, 0xC7,
  43386. 0xC7, 0xFB, 0x17, 0x58, 0xEC, 0x7D, 0x97, 0x01,
  43387. 0x9E, 0x5B, 0xA9, 0x35, 0x43, 0xEF, 0x3B, 0xAC,
  43388. 0x1A, 0x17, 0x42, 0x99, 0xCA, 0x48, 0xBF, 0x78,
  43389. 0x59, 0xDB, 0xFB, 0xDF, 0xF2, 0x43, 0xB1, 0x14,
  43390. 0xF6, 0xBF, 0x42, 0x3C, 0xE9, 0x8B, 0x4D, 0x4D,
  43391. 0x09, 0x1D, 0xA4, 0x4F, 0x32, 0x74, 0xD5, 0x73,
  43392. 0xFD, 0xC9, 0x04, 0xBD, 0x88, 0x5E, 0x35, 0xC9,
  43393. 0x15, 0x2A, 0x65, 0x35, 0x48, 0x88, 0xF1, 0x1E,
  43394. 0xD4, 0xF3, 0xD6, 0x3F, 0x26, 0xA7, 0xBE, 0x2F,
  43395. 0x57, 0x26, 0xEA, 0xDA, 0xF4, 0x85, 0x86, 0x59,
  43396. 0x2B, 0xBD, 0xF6, 0xCE, 0xE2, 0x46, 0x76, 0x9E,
  43397. 0x0E, 0xDA, 0x2A, 0x80, 0x77, 0x1F, 0xED, 0x34,
  43398. 0x7D, 0x67, 0xAF, 0xEE, 0xC6, 0x8B, 0x89, 0x46,
  43399. 0x3F, 0xA0, 0x49, 0x6D, 0xBC, 0x15, 0xC8, 0x9E,
  43400. 0x8D, 0x56, 0x99, 0x83, 0xD1, 0xD6, 0x74, 0x73,
  43401. 0x3F, 0x2B, 0xF9, 0xDF, 0x4A, 0x98, 0x0E, 0xA8,
  43402. 0xC5, 0xE3, 0xAF, 0x15, 0x56, 0x0A, 0x0E, 0x28,
  43403. 0xD6, 0x72, 0xB5, 0x80, 0xAB, 0x65, 0x52, 0xED,
  43404. 0x76, 0xAA, 0xCB, 0x5F, 0x80, 0x26, 0x0B, 0x97,
  43405. 0x03, 0x76, 0x9D, 0x33, 0xF4, 0x13, 0x8A, 0xBC,
  43406. 0x10, 0xBF, 0x5B, 0x05, 0x82, 0xDC, 0xC6, 0x2D,
  43407. 0xBE, 0x58, 0xC8, 0x90, 0xF5, 0x1B, 0x41, 0x00,
  43408. 0x12, 0x77, 0x34, 0xFB, 0x7D, 0xB7, 0x44, 0x7A,
  43409. 0x72, 0x0A, 0xAE, 0x00, 0x9D, 0x00, 0xBE, 0x8C,
  43410. 0x61, 0x07, 0x92, 0xC6, 0x4F, 0x13, 0x1F, 0x2D,
  43411. 0x72, 0x11, 0x5C, 0x7E, 0x05, 0x8E, 0x48, 0xB9,
  43412. 0xDE, 0x64, 0xF5, 0x5B, 0x4D, 0x61, 0x0C, 0x36,
  43413. 0xD1, 0x12, 0x71, 0x6A, 0x31, 0xA3, 0xDF, 0xE2,
  43414. 0x66, 0x99, 0xE9, 0xC2, 0xAB, 0xA0, 0x56, 0x58,
  43415. 0xCE, 0xF1, 0xB2, 0xB0, 0x86, 0x7C, 0xF8, 0xD5,
  43416. 0x23, 0x3D, 0xB7, 0x4F, 0xA8, 0xDC, 0x3A, 0xD1,
  43417. 0x45, 0xF5, 0xD2, 0x85, 0x74, 0x36, 0x0A, 0x85,
  43418. 0xE3, 0xB0, 0xB1, 0x0A, 0xC0, 0xA6, 0x46, 0x7A,
  43419. 0x7B, 0x05, 0x98, 0x46, 0x28, 0xEC, 0xA1, 0x04,
  43420. 0x63, 0xF3, 0x48, 0xA3, 0x11, 0x1E, 0x00, 0x57,
  43421. 0x8D, 0x3C, 0xE5, 0x48, 0x0F, 0x53, 0x75, 0xA1,
  43422. 0xEE, 0x23, 0xEE, 0x82, 0x08, 0x7B, 0xAC, 0x41,
  43423. 0x23, 0x3A, 0x14, 0xAA, 0xA7, 0x24, 0x73, 0x4B,
  43424. 0x18, 0x74, 0xA4, 0xAC, 0xE1, 0x13, 0x37, 0x06,
  43425. 0x25, 0x8F, 0x5F, 0xEA, 0x3A, 0x0C, 0x16, 0x09,
  43426. 0xE3, 0x0C, 0x7F, 0xD2, 0x10, 0xDA, 0x0C, 0x4F,
  43427. 0xDE, 0x91, 0x62, 0xDF, 0x66, 0xFB, 0xAF, 0x79,
  43428. 0x2F, 0xA2, 0xAE, 0xAA, 0x51, 0x2F, 0x0F, 0xF7,
  43429. 0x83, 0x7B, 0x9C, 0xC0, 0x2E, 0xE9, 0xBD, 0x95,
  43430. 0x53, 0x9F, 0x00, 0x1B, 0xBD, 0x60, 0xDD, 0x8B,
  43431. 0x42, 0xD6, 0x16, 0xB2, 0xCA, 0x95, 0xF3, 0x83,
  43432. 0x5F, 0x5E, 0x47, 0xD4, 0x3B, 0x14, 0x34, 0xC4,
  43433. 0x56, 0x3F, 0xD8, 0x1C, 0x15, 0xBE, 0xFA, 0x20,
  43434. 0x2C, 0xF3, 0xD9, 0x54, 0x08, 0x73, 0xF6, 0x84,
  43435. 0xAF, 0xE1, 0x9A, 0xB5, 0xC0, 0x1F, 0xA9, 0x2E,
  43436. 0x95, 0xA8, 0xCD, 0x6F, 0x36, 0x07, 0x30, 0x85,
  43437. 0x6E, 0x59, 0xC9, 0xC6, 0xAB, 0x77, 0x0D, 0x65,
  43438. 0x75, 0x96, 0x2A, 0xF7, 0x58, 0x78, 0x57, 0x2A,
  43439. 0x2A, 0x26, 0x41, 0x3D, 0x01, 0xAB, 0x31, 0x8C,
  43440. 0x10, 0x0D, 0xFC, 0x34, 0xDC, 0x1D, 0xEF, 0xA5,
  43441. 0x92, 0x7C, 0x4B, 0x45, 0x99, 0x25, 0xD7, 0x3E,
  43442. 0x1E, 0xB9, 0x14, 0x70, 0xE3, 0x7A, 0x58, 0x45,
  43443. 0x5C, 0x22, 0xA9, 0x61, 0xFD, 0x53, 0xF7, 0xD9,
  43444. 0x90, 0x26, 0xFF, 0x88, 0x4B, 0xF4, 0xA2, 0x57,
  43445. 0x9F, 0x70, 0x63, 0x35, 0xEF, 0xB6, 0xFB, 0x22,
  43446. 0x50, 0xD5, 0x2A, 0xE5, 0x61, 0x89, 0x8B, 0xA1,
  43447. 0x60, 0x6E, 0x51, 0xE9, 0x6D, 0x37, 0xC9, 0xED,
  43448. 0x3E, 0xC6, 0xCF, 0xCB, 0x33, 0xBF, 0xBE, 0x9C,
  43449. 0x31, 0x43, 0xFD, 0x3B, 0x6B, 0x33, 0x4D, 0x5F,
  43450. 0x61, 0x92, 0x2B, 0x36, 0x9A, 0xFB, 0xB3, 0x1C,
  43451. 0x3E, 0x6E, 0x9B, 0x5F, 0x3A, 0xEB, 0xF9, 0x5C,
  43452. 0xB7, 0x08, 0x34, 0x6F, 0xEC, 0xF7, 0x15, 0x9C,
  43453. 0xAD, 0x94, 0xA9, 0x3D, 0x8C, 0xD4, 0xB8, 0xC4,
  43454. 0x89, 0x41, 0x92, 0xDF, 0xE5, 0x3E, 0xA4, 0x36,
  43455. 0xFB, 0xF3, 0xAF, 0x4E, 0x86, 0x4E, 0x8C, 0x39,
  43456. 0x91, 0xEA, 0x02, 0x0A, 0x81, 0x1F, 0x0A, 0xF5,
  43457. 0x0B, 0x42, 0x57, 0x43, 0x6A, 0x3F, 0xF5, 0x22,
  43458. 0xBE, 0x73, 0x67, 0x39, 0x1D, 0x0F, 0x95, 0x0B,
  43459. 0xA6, 0x45, 0x2F, 0xBF, 0xD8, 0xFD, 0x87, 0x28,
  43460. 0xF4, 0x0B, 0xD2, 0xFC, 0xB8, 0x94, 0x52, 0x99,
  43461. 0x85, 0xB4, 0x32, 0xDF, 0xEF, 0x62, 0x30, 0xEB,
  43462. 0x4D, 0xEE, 0x73, 0x7A, 0x8D, 0x10, 0xA3, 0xBC,
  43463. 0xDF, 0xB7, 0x63, 0xE0, 0x86, 0x9B, 0x22, 0x5C,
  43464. 0x1A, 0x8D, 0x0E, 0x1F, 0xBF, 0x2D, 0x16, 0x1C,
  43465. 0x2C, 0x65, 0xD6, 0xDF, 0xB9, 0x58, 0xE9, 0x82,
  43466. 0xD1, 0x17, 0x77, 0xAC, 0xBE, 0xAD, 0x8D, 0xFB,
  43467. 0x6B, 0x1F, 0x5E, 0xB2, 0x1E, 0xA9, 0x42, 0xF7,
  43468. 0xC4, 0x0D, 0xC2, 0x0D, 0x2E, 0x4E, 0xB3, 0xE7,
  43469. 0x29, 0xB4, 0xE2, 0x9F, 0x75, 0x01, 0xDA, 0x34,
  43470. 0x23, 0x45, 0x61, 0xF6, 0x28, 0x88, 0x12, 0xD6,
  43471. 0x12, 0xD4, 0x1D, 0xFA, 0x83, 0xC5, 0xB8, 0xD9,
  43472. 0x0F, 0xF3, 0x8B, 0xA5, 0x48, 0x20, 0x1B, 0x57,
  43473. 0x5B, 0x52, 0x93, 0xAD, 0x78, 0x12, 0x0D, 0x91,
  43474. 0xCE, 0xC0, 0x59, 0xCA, 0xE2, 0xE7, 0x6A, 0x9A,
  43475. 0xB4, 0x3E, 0xF1, 0x28, 0x1E, 0x2B, 0xEF, 0x3E,
  43476. 0x34, 0x8D, 0x28, 0xF2, 0x19, 0x47, 0xC8, 0x88,
  43477. 0x48, 0x96, 0x04, 0x59, 0x48, 0x97, 0x75, 0x17,
  43478. 0x6F, 0x8E, 0x40, 0xEE, 0x06, 0x42, 0x79, 0x53,
  43479. 0x68, 0x7F, 0xB6, 0x3E, 0x47, 0x0F, 0x7D, 0x59,
  43480. 0xFB, 0x60, 0xDF, 0x56, 0x9F, 0x8A, 0x11, 0xE2,
  43481. 0x8E, 0x09, 0x37, 0x16, 0x2C, 0x46, 0xAF, 0xC7,
  43482. 0xD2, 0x21, 0x0A, 0x88, 0x5F, 0xFA, 0x21, 0xB3,
  43483. 0xDB, 0xF5, 0x35, 0x4B, 0x29, 0x41, 0xF4, 0xED,
  43484. 0x5D, 0x50, 0x79, 0x08, 0x90, 0x84, 0x0C, 0xC3,
  43485. 0xB9, 0x73, 0xD2, 0xC3, 0xD0, 0x26, 0x02, 0xB2,
  43486. 0x9B, 0xAC, 0xCB, 0x6C, 0xE1, 0x7C, 0xED, 0xB9,
  43487. 0x7B, 0x08, 0x5A, 0x2A, 0xB3, 0x10, 0x57, 0x2B,
  43488. 0xA7, 0x37, 0x1D, 0x1F, 0x81, 0x20, 0xFF, 0xE3,
  43489. 0x7D, 0x0B, 0x0F, 0xCA, 0x35, 0xAF, 0xC5, 0xB5,
  43490. 0x62, 0xAA, 0x84, 0x99, 0x71, 0x5A, 0x29, 0x9C,
  43491. 0xE0, 0x59, 0xCC, 0xE3, 0xB0, 0xD1, 0x1C, 0xEF,
  43492. 0x0D, 0x92, 0x38, 0x96, 0x1A, 0xD4, 0xBE, 0x11,
  43493. 0xE9, 0xA6, 0xD1, 0xA4, 0x69, 0x21, 0x77, 0xC8,
  43494. 0xB0, 0xC5, 0x3F, 0x11, 0xA8, 0xED, 0x26, 0x50,
  43495. 0x21, 0x2E, 0x7A, 0x2F, 0x80, 0xEB, 0xFF, 0x6D,
  43496. 0xCF, 0xE4, 0x67, 0x21, 0x03, 0x65, 0x84, 0x34,
  43497. 0xD0, 0x32, 0x7A, 0xDD, 0xCD, 0x66, 0xBC, 0xB6
  43498. };
  43499. static const byte msg_65_draft[] = {
  43500. 0xDB, 0x84, 0x94, 0xBA, 0x19, 0xC4, 0x11, 0x8F,
  43501. 0xB1, 0x5D, 0x0A, 0xCF, 0x42, 0x54, 0xFD, 0x37,
  43502. 0x48, 0x3F, 0xCF, 0x47, 0x48, 0xFD, 0x18, 0x44,
  43503. 0xF7, 0x17, 0xCE, 0x6F, 0x69, 0x58, 0x9E, 0x61,
  43504. 0x77, 0x2C, 0xFE, 0xFA, 0x7F, 0x97, 0x58, 0x65,
  43505. 0x34, 0x09, 0xD4, 0xEE, 0x5A, 0x26, 0x4B, 0x83,
  43506. 0x4E, 0x60, 0xD6, 0xBB, 0x96, 0x49, 0x9E, 0xBE,
  43507. 0xB2, 0xB0, 0x6B, 0x0B, 0xA8, 0x74, 0xBF, 0x31,
  43508. 0xE6, 0x41, 0x39, 0x4C, 0xFA, 0xA6, 0xA2, 0xD3,
  43509. 0x0D, 0xDB, 0x8F, 0x04, 0x58, 0x76, 0x20, 0x8D,
  43510. 0x2F, 0x51, 0xDE, 0x15, 0xE2, 0x05, 0xE8, 0xC9,
  43511. 0x1B, 0x87, 0xEC, 0xEB, 0x05, 0xFF, 0x31, 0x83,
  43512. 0x27, 0x1B, 0x26, 0x49, 0x66, 0x5D, 0xD3, 0xCC,
  43513. 0x49, 0xBF, 0xDB, 0x99, 0x8D, 0x53, 0x9D, 0xA8,
  43514. 0x09, 0x30, 0x55, 0x16, 0xBB, 0xBE, 0x9C, 0x90,
  43515. 0x60, 0x21, 0x19, 0x1C, 0x52, 0x23, 0xE5, 0x25,
  43516. 0xA8, 0xFC, 0x36, 0x16, 0xA1, 0x76, 0x5E, 0xC3,
  43517. 0xF9, 0xC5, 0xDB, 0x53, 0xCC, 0x33, 0x7E, 0x03,
  43518. 0x9F, 0x18, 0x6A, 0xCF, 0xEA, 0x91, 0x14, 0x8E,
  43519. 0xE2, 0xA7, 0x9C, 0xCA, 0x36, 0x89, 0xED, 0xB6,
  43520. 0x2A, 0xAF, 0x28, 0xB5, 0xD7, 0x52, 0xFD, 0xE2,
  43521. 0x65, 0xEE, 0x52, 0x80, 0xB5, 0x19, 0x72, 0x6C,
  43522. 0x1C, 0xA9, 0x80, 0x32, 0x95, 0xC6, 0x74, 0xB7,
  43523. 0xEF, 0xAF, 0xA4, 0xD6, 0x1B, 0x30, 0x6A, 0x79,
  43524. 0xE3, 0xF6, 0xE7, 0xA8, 0x87, 0xC2, 0xFB, 0x53,
  43525. 0x5B, 0x3B, 0x0F, 0xB3, 0xD9, 0xEB, 0xC8, 0x76,
  43526. 0x03, 0xEA, 0xFE, 0xF1, 0x70, 0xC1, 0xF1, 0xD2,
  43527. 0x8E, 0x99, 0xBB
  43528. };
  43529. static const byte sig_65_draft[] = {
  43530. 0xF7, 0x78, 0x9A, 0x45, 0xA3, 0x58, 0x73, 0x30,
  43531. 0xE7, 0xFC, 0xF7, 0x06, 0x95, 0xF7, 0xF6, 0x96,
  43532. 0x88, 0xA2, 0xB8, 0xD0, 0xCE, 0x54, 0xF0, 0x90,
  43533. 0x21, 0x4F, 0x10, 0x9F, 0x56, 0x48, 0x4F, 0x98,
  43534. 0xC3, 0xAD, 0x1A, 0x53, 0xA5, 0x44, 0x1C, 0x2C,
  43535. 0xA7, 0x2A, 0x3B, 0x31, 0x91, 0xBC, 0x04, 0x6F,
  43536. 0x46, 0x37, 0x30, 0x45, 0xB9, 0xE5, 0x40, 0xC7,
  43537. 0x3D, 0xFE, 0x91, 0xB6, 0x1F, 0x05, 0x88, 0xD6,
  43538. 0x13, 0x59, 0x3F, 0xCE, 0x1B, 0x00, 0xEE, 0xF1,
  43539. 0xB2, 0x27, 0x03, 0x4C, 0x6F, 0xD3, 0xB1, 0x8B,
  43540. 0x3F, 0x22, 0x11, 0x10, 0xFB, 0x34, 0x5A, 0xA7,
  43541. 0x86, 0x31, 0xB8, 0xB5, 0x9F, 0xBD, 0xFD, 0xCC,
  43542. 0xDA, 0xE6, 0xA2, 0x4D, 0x25, 0x9D, 0x34, 0xAA,
  43543. 0xBA, 0xD2, 0x18, 0xB3, 0xAE, 0x4E, 0x77, 0x18,
  43544. 0x66, 0x53, 0xB8, 0x56, 0x3A, 0xA6, 0x12, 0x0A,
  43545. 0x0A, 0x53, 0x1A, 0x4E, 0x91, 0x37, 0x30, 0xDC,
  43546. 0x91, 0x4F, 0xE5, 0xE0, 0x08, 0xBE, 0xCE, 0x68,
  43547. 0x69, 0xB0, 0x2B, 0x07, 0xFD, 0xC1, 0x62, 0x14,
  43548. 0x54, 0x0D, 0x31, 0x6C, 0x43, 0xFA, 0x0C, 0x21,
  43549. 0x1B, 0x41, 0xAC, 0x7E, 0x52, 0x65, 0x67, 0x29,
  43550. 0xC7, 0x73, 0xE4, 0xC4, 0xB8, 0x8E, 0xD3, 0x11,
  43551. 0x88, 0x6D, 0xD4, 0xD2, 0x75, 0x41, 0x7D, 0x70,
  43552. 0x19, 0x66, 0x44, 0xEE, 0xD1, 0x5F, 0xA3, 0x15,
  43553. 0x06, 0x60, 0x03, 0xE3, 0x09, 0xF8, 0x32, 0xAF,
  43554. 0x91, 0x26, 0x2C, 0x94, 0x90, 0x11, 0xFC, 0xB0,
  43555. 0xAD, 0x2C, 0xCE, 0x65, 0xDD, 0x9E, 0xFF, 0x56,
  43556. 0x7E, 0xE2, 0x9C, 0xC4, 0x0A, 0x6F, 0xE0, 0x66,
  43557. 0x4E, 0x7D, 0x9F, 0x23, 0x65, 0x68, 0xFC, 0x94,
  43558. 0x29, 0x5D, 0xBB, 0x34, 0x28, 0x82, 0x33, 0xE8,
  43559. 0xC5, 0x11, 0xD2, 0x88, 0x15, 0xEC, 0x72, 0x10,
  43560. 0x32, 0x29, 0x6E, 0x1E, 0xDE, 0xCA, 0x7F, 0x72,
  43561. 0x6A, 0x6E, 0xB0, 0xF7, 0x6C, 0xC5, 0x82, 0x80,
  43562. 0x11, 0xC0, 0xE4, 0x01, 0x3C, 0xC7, 0xEE, 0x43,
  43563. 0x29, 0xB8, 0x1E, 0xCC, 0x0D, 0x52, 0xED, 0x1E,
  43564. 0x49, 0x1D, 0xD6, 0xD5, 0x5C, 0x52, 0x65, 0x66,
  43565. 0x5E, 0xD8, 0xAD, 0x21, 0x9B, 0x89, 0x4F, 0x31,
  43566. 0xC6, 0x8C, 0x61, 0x9A, 0xFC, 0xDB, 0x73, 0x58,
  43567. 0xE5, 0x55, 0x4C, 0x49, 0x5B, 0x8B, 0x6E, 0x33,
  43568. 0x25, 0x68, 0x8F, 0xB8, 0xC1, 0xA2, 0x53, 0x31,
  43569. 0xD5, 0x7B, 0xD3, 0x48, 0xA2, 0x7D, 0x39, 0x09,
  43570. 0x29, 0xBC, 0x46, 0xA1, 0x49, 0x6A, 0xB3, 0x5B,
  43571. 0x46, 0xBA, 0x61, 0xB6, 0xB9, 0xD2, 0x3C, 0xD0,
  43572. 0x63, 0x15, 0xFB, 0x72, 0xC2, 0x47, 0x76, 0x01,
  43573. 0x61, 0x30, 0xAD, 0xB1, 0xCF, 0x2D, 0xC7, 0x29,
  43574. 0x59, 0xEA, 0x9C, 0xAD, 0x96, 0xAF, 0x5D, 0xA9,
  43575. 0x96, 0x12, 0x6C, 0xDD, 0x85, 0xB1, 0x34, 0xCC,
  43576. 0x92, 0x7A, 0x51, 0xFD, 0x23, 0xF8, 0x47, 0x91,
  43577. 0xA3, 0xFC, 0xDA, 0x07, 0x7E, 0x15, 0x99, 0x17,
  43578. 0x48, 0xA0, 0x39, 0x4F, 0x33, 0x4E, 0xB8, 0xBC,
  43579. 0x48, 0xA9, 0x9A, 0xB9, 0xDF, 0xBB, 0x0F, 0x2A,
  43580. 0xAD, 0x6F, 0xBE, 0x48, 0x49, 0x61, 0xD3, 0xA4,
  43581. 0xE8, 0xF8, 0xB2, 0x1A, 0x6A, 0xC0, 0x92, 0xB2,
  43582. 0x26, 0xD6, 0xE1, 0x19, 0xFA, 0xD4, 0x4D, 0x8E,
  43583. 0x57, 0x6F, 0xE9, 0x6C, 0x6C, 0xDB, 0x68, 0x40,
  43584. 0xEA, 0x61, 0x4B, 0xAF, 0xC7, 0x07, 0x86, 0xC5,
  43585. 0x19, 0xE1, 0xD5, 0xDC, 0x0F, 0x98, 0x44, 0x43,
  43586. 0xC8, 0xB1, 0xE5, 0x4F, 0x8E, 0xE1, 0x76, 0xD9,
  43587. 0x8B, 0x2C, 0x70, 0x27, 0xF5, 0x7D, 0x7E, 0x3D,
  43588. 0xE9, 0xB2, 0xA0, 0xA3, 0x69, 0x11, 0xB8, 0xE4,
  43589. 0x71, 0x21, 0xDE, 0x0C, 0x07, 0xEB, 0xBA, 0x5D,
  43590. 0x7B, 0x59, 0x4E, 0xF2, 0x44, 0xC6, 0x83, 0x27,
  43591. 0xEC, 0x6C, 0x6D, 0x1D, 0xD5, 0x01, 0xF4, 0x83,
  43592. 0xFE, 0x9B, 0x95, 0x70, 0x59, 0x7E, 0x70, 0xDF,
  43593. 0x41, 0x3E, 0x7A, 0xF0, 0x38, 0x47, 0xF4, 0x09,
  43594. 0xED, 0x61, 0xE2, 0x84, 0x6E, 0x6C, 0x64, 0x1E,
  43595. 0x6A, 0x7F, 0xFA, 0x79, 0xDE, 0x6B, 0xFA, 0x37,
  43596. 0x3A, 0x06, 0x44, 0xB0, 0x0B, 0xF4, 0x1A, 0x03,
  43597. 0x49, 0x92, 0xA7, 0x94, 0xDA, 0x17, 0xC8, 0x88,
  43598. 0x85, 0x23, 0x90, 0x32, 0xC8, 0x51, 0x76, 0x4E,
  43599. 0x3E, 0x4D, 0xBD, 0xE7, 0xF1, 0x2A, 0x16, 0xC5,
  43600. 0xA2, 0x63, 0xE9, 0x64, 0xC1, 0xE7, 0xFD, 0xD3,
  43601. 0xCC, 0xE5, 0x76, 0xDD, 0x6D, 0x56, 0xB1, 0x81,
  43602. 0x82, 0x84, 0x8B, 0x75, 0x63, 0x64, 0x5D, 0x4E,
  43603. 0x42, 0xFF, 0x22, 0x74, 0x2A, 0x99, 0x67, 0x85,
  43604. 0x16, 0x9D, 0x7F, 0x50, 0x3B, 0x48, 0xA7, 0x15,
  43605. 0x8B, 0x3C, 0xBD, 0x29, 0x93, 0x5E, 0xD3, 0x20,
  43606. 0x49, 0xBE, 0xA1, 0xAD, 0x95, 0x3E, 0xF7, 0x07,
  43607. 0x32, 0x7B, 0x77, 0x8B, 0xFD, 0xDD, 0xFC, 0x60,
  43608. 0x51, 0x1D, 0xA1, 0x13, 0xA3, 0x4F, 0x65, 0x57,
  43609. 0x12, 0xE4, 0xE5, 0x9D, 0x6C, 0xCE, 0x40, 0x4E,
  43610. 0x94, 0xAB, 0xA6, 0x1E, 0x81, 0x35, 0x38, 0x8F,
  43611. 0xC2, 0x1C, 0x8E, 0x41, 0x34, 0x4F, 0x32, 0x4B,
  43612. 0x01, 0xAC, 0x8C, 0x06, 0x9F, 0x92, 0x57, 0x5D,
  43613. 0x34, 0xF8, 0x8B, 0xCA, 0x22, 0xCB, 0x30, 0x7E,
  43614. 0x37, 0x07, 0x00, 0x63, 0x32, 0x02, 0x56, 0xB8,
  43615. 0xBA, 0xD6, 0xEB, 0x7A, 0x81, 0xAF, 0xE9, 0xA2,
  43616. 0x54, 0x01, 0x6E, 0x1C, 0x8A, 0x12, 0x50, 0x89,
  43617. 0xAA, 0xA3, 0xED, 0xE8, 0x4E, 0x5B, 0x6C, 0x2E,
  43618. 0xCF, 0xAE, 0xFA, 0xA5, 0x2B, 0x9F, 0x57, 0x09,
  43619. 0x60, 0x2C, 0x06, 0xAE, 0xA4, 0xA0, 0x38, 0x4E,
  43620. 0x9B, 0x09, 0xE5, 0xB8, 0x81, 0x64, 0xB2, 0x74,
  43621. 0xEA, 0x32, 0x65, 0xFB, 0x51, 0x52, 0x39, 0x7D,
  43622. 0xFF, 0x5A, 0x3A, 0x08, 0x61, 0xE2, 0xBC, 0x12,
  43623. 0xD2, 0x10, 0x92, 0x89, 0x72, 0x97, 0x47, 0xE8,
  43624. 0x3F, 0xDF, 0x24, 0x3A, 0x1D, 0x17, 0xB9, 0x83,
  43625. 0x48, 0x37, 0x98, 0x45, 0xA9, 0xE9, 0x55, 0xE2,
  43626. 0xD6, 0xF9, 0x38, 0xDA, 0xA5, 0x91, 0x8E, 0x2A,
  43627. 0x14, 0xF9, 0x7B, 0xA2, 0xBE, 0x50, 0x1C, 0xCC,
  43628. 0xAF, 0xD6, 0x81, 0x91, 0x0F, 0x4A, 0x4F, 0x06,
  43629. 0x71, 0x5C, 0xE8, 0x40, 0x96, 0xF3, 0x7A, 0x91,
  43630. 0xDC, 0xCA, 0x2A, 0x8A, 0x4B, 0xE8, 0xDA, 0x79,
  43631. 0x21, 0xDB, 0xF8, 0xD3, 0xF4, 0xEF, 0xB9, 0x8C,
  43632. 0x6B, 0x4F, 0x94, 0x0E, 0xCE, 0xF8, 0x32, 0xB5,
  43633. 0x49, 0xD0, 0x68, 0x94, 0x7C, 0x3D, 0xFB, 0x58,
  43634. 0x09, 0xCB, 0x7B, 0x06, 0x0A, 0x3A, 0x0E, 0xF3,
  43635. 0xB2, 0x1C, 0x01, 0x64, 0x50, 0x1D, 0xDE, 0xA7,
  43636. 0xC9, 0xE5, 0xE7, 0x89, 0x7C, 0x6B, 0x1C, 0x46,
  43637. 0x34, 0x8B, 0x2C, 0x3E, 0x80, 0x5F, 0x6F, 0x22,
  43638. 0x87, 0xBA, 0x15, 0x8C, 0xF9, 0x25, 0xA7, 0xBA,
  43639. 0x7F, 0x08, 0x25, 0x49, 0x89, 0xC8, 0x7D, 0x24,
  43640. 0x97, 0x9A, 0xD9, 0x86, 0xAA, 0x97, 0xC5, 0x1B,
  43641. 0x01, 0xF4, 0x5D, 0x4A, 0x1F, 0x24, 0x75, 0x29,
  43642. 0x91, 0xF0, 0x42, 0x05, 0xEB, 0x55, 0x1F, 0xD0,
  43643. 0x2D, 0x41, 0x5F, 0x2D, 0xD1, 0xEF, 0xF1, 0x42,
  43644. 0xB0, 0xD7, 0x04, 0x16, 0xC6, 0xD8, 0x15, 0xEB,
  43645. 0x91, 0x73, 0x2B, 0x26, 0x8F, 0xB2, 0x0D, 0x08,
  43646. 0x67, 0x44, 0x2D, 0x71, 0xDE, 0xC0, 0x57, 0xB2,
  43647. 0x86, 0xCD, 0x93, 0x81, 0x1F, 0xF3, 0xF6, 0x46,
  43648. 0xEB, 0xD5, 0x65, 0xD5, 0x1D, 0x09, 0xA4, 0x2D,
  43649. 0x3A, 0xBA, 0xAC, 0x0F, 0x34, 0xCC, 0x81, 0x7B,
  43650. 0x18, 0x93, 0x8E, 0xCC, 0xBB, 0x1F, 0xEF, 0x05,
  43651. 0xBD, 0x3C, 0x2B, 0x49, 0x4F, 0xA5, 0x29, 0xED,
  43652. 0x4C, 0x63, 0x4C, 0x93, 0x25, 0xA4, 0x81, 0x73,
  43653. 0xF2, 0x0F, 0xFA, 0xC3, 0x2D, 0xC1, 0x01, 0xE6,
  43654. 0xEE, 0x03, 0xB2, 0xFC, 0xBE, 0xC2, 0x46, 0x8D,
  43655. 0xBC, 0x8F, 0x76, 0x75, 0x8C, 0x32, 0x15, 0x47,
  43656. 0x4F, 0x7E, 0xF2, 0x40, 0x65, 0xF7, 0x90, 0x60,
  43657. 0xAC, 0xA3, 0xC8, 0xD5, 0xD7, 0x4A, 0xF7, 0x0F,
  43658. 0x48, 0x30, 0x1D, 0xDB, 0x30, 0xC0, 0x5D, 0xB3,
  43659. 0xEF, 0xA7, 0x26, 0xCF, 0x88, 0x55, 0x59, 0x01,
  43660. 0x84, 0x12, 0x82, 0xAA, 0x08, 0xF6, 0x66, 0xA6,
  43661. 0x53, 0x51, 0xA6, 0xA2, 0x4E, 0xED, 0x6B, 0xE2,
  43662. 0x11, 0x77, 0x31, 0x07, 0xE1, 0x85, 0xE1, 0xB4,
  43663. 0x88, 0xA2, 0xE4, 0x91, 0xB6, 0xC1, 0x41, 0x52,
  43664. 0x84, 0x62, 0xA8, 0x64, 0x94, 0xB5, 0x4F, 0xDC,
  43665. 0xCE, 0xCC, 0xB6, 0xAA, 0x21, 0x25, 0x36, 0x86,
  43666. 0x69, 0x3A, 0xE7, 0x98, 0xC9, 0xCE, 0x9E, 0x0B,
  43667. 0xDD, 0xC6, 0xAE, 0x53, 0xD9, 0xB7, 0x06, 0xDC,
  43668. 0x4F, 0x4D, 0x81, 0xB9, 0xC7, 0x3C, 0x46, 0x1E,
  43669. 0xCD, 0x70, 0x35, 0xC5, 0x17, 0x2E, 0xFA, 0xE5,
  43670. 0x60, 0x2C, 0xAF, 0x88, 0xC6, 0x4E, 0x79, 0xE5,
  43671. 0x32, 0x40, 0x30, 0x55, 0x5D, 0xE2, 0x11, 0xF8,
  43672. 0x9F, 0xD4, 0x24, 0xC3, 0x38, 0xC3, 0x88, 0x3C,
  43673. 0x83, 0xCA, 0x94, 0x05, 0xC2, 0xB5, 0xD1, 0x44,
  43674. 0x5F, 0x7C, 0x98, 0xC4, 0x3E, 0xD3, 0xD2, 0xBE,
  43675. 0xCB, 0xE2, 0x5F, 0x5F, 0x3F, 0x54, 0x4C, 0xCC,
  43676. 0x5B, 0x5A, 0xEA, 0xE4, 0x7D, 0xDF, 0x3F, 0xB5,
  43677. 0x64, 0x9F, 0xF5, 0xD6, 0x1E, 0xAA, 0x02, 0xED,
  43678. 0xEB, 0xC7, 0x5C, 0xE4, 0x78, 0xBA, 0x00, 0x42,
  43679. 0x6C, 0xAF, 0x47, 0x4F, 0xA7, 0x9E, 0x5B, 0x08,
  43680. 0x9E, 0xB1, 0xA8, 0x82, 0xF1, 0x53, 0x54, 0x59,
  43681. 0x26, 0x95, 0x95, 0x2B, 0xA0, 0xA8, 0xEE, 0x91,
  43682. 0xE6, 0x49, 0xE3, 0xF2, 0xC3, 0x82, 0x26, 0x4D,
  43683. 0xAA, 0x30, 0xF6, 0xA6, 0xD2, 0x17, 0xF6, 0x12,
  43684. 0x9C, 0x19, 0x39, 0xB6, 0xDC, 0xAC, 0xCD, 0xA5,
  43685. 0xB6, 0x37, 0x32, 0x6E, 0x8A, 0x83, 0x61, 0xC3,
  43686. 0xB5, 0x6F, 0xCF, 0xFC, 0x48, 0x50, 0x36, 0x86,
  43687. 0x58, 0x22, 0xB9, 0xBB, 0x87, 0xB4, 0x35, 0x10,
  43688. 0xBC, 0xDD, 0x55, 0xBC, 0x35, 0x0D, 0xE7, 0xB2,
  43689. 0xAE, 0x90, 0xA2, 0x1E, 0x9E, 0x19, 0x97, 0x8E,
  43690. 0xDA, 0x10, 0xDF, 0x66, 0x76, 0x14, 0xA4, 0x4F,
  43691. 0xE2, 0xA8, 0x4D, 0x16, 0xBE, 0x04, 0x3E, 0xA8,
  43692. 0x77, 0x36, 0x33, 0xEA, 0x6B, 0xAD, 0xF6, 0x57,
  43693. 0x10, 0x05, 0x2F, 0x34, 0x1F, 0x65, 0xCB, 0xE9,
  43694. 0x28, 0xD3, 0x96, 0x2A, 0x5A, 0x2F, 0xE6, 0x4E,
  43695. 0x46, 0xD6, 0xBF, 0xB8, 0xFD, 0x0D, 0x99, 0x78,
  43696. 0xF0, 0x42, 0x3C, 0xBD, 0x19, 0x5F, 0x72, 0xF3,
  43697. 0xCB, 0x19, 0xD7, 0xEF, 0xD9, 0xEB, 0xE3, 0x3C,
  43698. 0xD2, 0xF5, 0x70, 0x9A, 0x57, 0x80, 0x7D, 0xF9,
  43699. 0x44, 0xEC, 0xE5, 0x68, 0xAA, 0xCA, 0x43, 0x36,
  43700. 0x42, 0x20, 0x83, 0xB0, 0x69, 0x7B, 0x6A, 0xA0,
  43701. 0x05, 0x86, 0xE4, 0xBF, 0x7D, 0xD6, 0x73, 0xA3,
  43702. 0xD5, 0x96, 0xB8, 0x61, 0x8A, 0xC3, 0xB4, 0x06,
  43703. 0x17, 0x50, 0xC6, 0xBE, 0x97, 0xCB, 0x53, 0x75,
  43704. 0x3D, 0x02, 0x39, 0x55, 0x56, 0x07, 0x5A, 0x26,
  43705. 0xF1, 0x40, 0xB9, 0x3F, 0x57, 0x7D, 0xAD, 0x50,
  43706. 0x5E, 0x1C, 0xF2, 0xB5, 0x51, 0xA0, 0x4C, 0x98,
  43707. 0xC7, 0xF0, 0x90, 0x18, 0x31, 0xB3, 0xCA, 0x61,
  43708. 0xD7, 0x5D, 0xA7, 0x93, 0xAC, 0x72, 0xA4, 0x4C,
  43709. 0x7A, 0x07, 0xF7, 0xDB, 0xBA, 0xD6, 0x0A, 0x55,
  43710. 0xF4, 0x9C, 0xBD, 0x79, 0xDE, 0xE4, 0x73, 0x9F,
  43711. 0xFD, 0x36, 0x77, 0x8E, 0xBD, 0x08, 0xEB, 0xDB,
  43712. 0x79, 0xEC, 0x07, 0xA1, 0x62, 0x39, 0xC5, 0xB9,
  43713. 0x21, 0x59, 0x9F, 0xEB, 0xFE, 0xA4, 0x6D, 0xDF,
  43714. 0x96, 0x6A, 0xA4, 0xA0, 0x15, 0x12, 0xE6, 0x10,
  43715. 0x94, 0x3F, 0x5D, 0xC5, 0x4B, 0x4C, 0x76, 0xB7,
  43716. 0x64, 0xB3, 0x80, 0xBF, 0x2F, 0x84, 0xED, 0xE3,
  43717. 0x21, 0x24, 0x91, 0x2F, 0x54, 0xF7, 0xB6, 0xE2,
  43718. 0x07, 0xB7, 0x38, 0x1F, 0x67, 0x0F, 0x7A, 0xA0,
  43719. 0xF3, 0xC3, 0xED, 0x10, 0x15, 0x74, 0x03, 0x84,
  43720. 0xDD, 0x61, 0xA9, 0x76, 0x5E, 0xE4, 0x69, 0x6E,
  43721. 0xAC, 0xF8, 0x2E, 0xA4, 0x10, 0x69, 0x18, 0x05,
  43722. 0xCB, 0x68, 0x89, 0x03, 0x53, 0x5D, 0x70, 0x46,
  43723. 0x10, 0x0D, 0xCC, 0x2B, 0xA7, 0xD8, 0x30, 0x2A,
  43724. 0xCB, 0x04, 0x30, 0xD5, 0x06, 0xCC, 0xC1, 0xC0,
  43725. 0xDD, 0xEA, 0x71, 0x11, 0xA7, 0x6F, 0x45, 0xB4,
  43726. 0x54, 0xE2, 0x5C, 0xDD, 0xFB, 0x63, 0x9B, 0x3D,
  43727. 0x66, 0x4C, 0x36, 0xD8, 0x84, 0x35, 0x13, 0xA3,
  43728. 0xFC, 0xAF, 0x9E, 0x60, 0x57, 0xE9, 0xBC, 0x06,
  43729. 0x82, 0x37, 0xFE, 0x24, 0x19, 0xA2, 0xD2, 0xD9,
  43730. 0x0B, 0x4A, 0x1F, 0xC2, 0xA7, 0x1A, 0x14, 0x6D,
  43731. 0x2B, 0xD0, 0x43, 0x64, 0xC7, 0x9B, 0x8E, 0xBA,
  43732. 0x8E, 0x3E, 0x88, 0xCE, 0x11, 0xE9, 0x16, 0xE4,
  43733. 0xA7, 0x52, 0x84, 0x21, 0x32, 0x8C, 0xF5, 0x4F,
  43734. 0xAA, 0xB2, 0xB1, 0x9F, 0x44, 0x46, 0x87, 0x81,
  43735. 0xF8, 0xAB, 0x84, 0xB7, 0xDD, 0x97, 0x2F, 0xF5,
  43736. 0x61, 0x50, 0x71, 0x43, 0x0A, 0x43, 0x74, 0xDA,
  43737. 0xFC, 0xAE, 0x1E, 0x60, 0x44, 0xAA, 0x98, 0xE9,
  43738. 0x85, 0x94, 0x1B, 0xA6, 0xB9, 0xDB, 0x8C, 0x02,
  43739. 0xF5, 0x89, 0x60, 0x3E, 0xEB, 0x8B, 0xE9, 0x0A,
  43740. 0x70, 0xEF, 0xC0, 0x88, 0xD7, 0x95, 0xE6, 0xDA,
  43741. 0x1F, 0x1F, 0x2E, 0x6E, 0xCE, 0xDD, 0x03, 0x1D,
  43742. 0x81, 0x99, 0xE6, 0x59, 0x12, 0xD4, 0x34, 0xD0,
  43743. 0x9B, 0xFB, 0xE5, 0x94, 0x40, 0x6D, 0xC1, 0x15,
  43744. 0x0E, 0x99, 0x35, 0x8C, 0xEA, 0x7F, 0xAD, 0x2E,
  43745. 0x7C, 0x44, 0xC3, 0x8B, 0x6E, 0x0C, 0xEE, 0xAB,
  43746. 0x9B, 0xDE, 0x0D, 0xB9, 0x7B, 0xCF, 0x5A, 0xC9,
  43747. 0x94, 0x10, 0xC9, 0x47, 0x0E, 0x26, 0x6B, 0x8B,
  43748. 0xE4, 0x5F, 0x66, 0x90, 0x83, 0x1F, 0x41, 0x45,
  43749. 0xE2, 0x63, 0x79, 0xDB, 0x80, 0x7C, 0x26, 0xDD,
  43750. 0xF9, 0x1E, 0x30, 0x9D, 0x4F, 0x4A, 0x3E, 0x7E,
  43751. 0xCA, 0xB7, 0x36, 0x2F, 0x15, 0xD2, 0x0E, 0xA4,
  43752. 0x33, 0xB7, 0xE7, 0x0A, 0x7D, 0xDE, 0x74, 0x16,
  43753. 0xCE, 0xA8, 0x71, 0x49, 0x8B, 0x2C, 0xE3, 0xF5,
  43754. 0x8D, 0x29, 0xD8, 0x62, 0x8C, 0x53, 0x18, 0x40,
  43755. 0xF0, 0x22, 0xDD, 0x3B, 0xD2, 0xF3, 0x80, 0x9B,
  43756. 0x11, 0x68, 0xD3, 0x8E, 0x63, 0xC7, 0xF6, 0x93,
  43757. 0x08, 0xA3, 0x1A, 0x2D, 0x4D, 0x5E, 0xEB, 0x97,
  43758. 0x42, 0x39, 0xB3, 0x4A, 0x62, 0xBC, 0x85, 0xE4,
  43759. 0xEC, 0xF9, 0x0C, 0x33, 0x6A, 0x0C, 0x37, 0xBD,
  43760. 0x9E, 0x0E, 0xF4, 0x26, 0x6B, 0x83, 0x5A, 0xC8,
  43761. 0x90, 0x6A, 0x83, 0xCF, 0x0B, 0x35, 0x13, 0x8A,
  43762. 0x65, 0xE5, 0xD9, 0xA6, 0x1F, 0xCC, 0x9B, 0x2D,
  43763. 0x5A, 0x33, 0x7B, 0x8A, 0xBE, 0xF8, 0x8A, 0x7F,
  43764. 0xB3, 0xC0, 0x94, 0x5D, 0x7C, 0xAF, 0x35, 0x61,
  43765. 0x1A, 0xE0, 0xE4, 0x46, 0x93, 0xA5, 0xBC, 0xE0,
  43766. 0xA6, 0xE2, 0xFE, 0xCA, 0xE9, 0xBD, 0xF4, 0xE3,
  43767. 0x56, 0xD6, 0x53, 0x6B, 0x58, 0x1A, 0x18, 0xF0,
  43768. 0x3A, 0x59, 0x16, 0x4E, 0xD5, 0x44, 0x7C, 0x7E,
  43769. 0xC8, 0xBD, 0x99, 0x7B, 0xE9, 0x53, 0xDE, 0xD9,
  43770. 0x32, 0x53, 0x5B, 0x5F, 0x43, 0x8A, 0x04, 0x31,
  43771. 0x9F, 0x5E, 0x0D, 0x8B, 0x0F, 0xEB, 0xC8, 0xDE,
  43772. 0x81, 0x46, 0x65, 0x8E, 0x52, 0xB9, 0x75, 0x9C,
  43773. 0x73, 0x93, 0x5B, 0x12, 0x0D, 0xC9, 0xB8, 0x54,
  43774. 0xF3, 0xC8, 0xF9, 0x4E, 0xC9, 0x33, 0x90, 0x57,
  43775. 0xD7, 0xD7, 0xCD, 0x91, 0xF7, 0xE0, 0xB9, 0x8D,
  43776. 0x84, 0xEC, 0x7B, 0x2F, 0x92, 0x32, 0x8D, 0x73,
  43777. 0x60, 0x18, 0xB0, 0x31, 0x65, 0xA8, 0x74, 0x5F,
  43778. 0x8E, 0x77, 0xEB, 0x80, 0x29, 0xF9, 0x78, 0x26,
  43779. 0x70, 0xCB, 0xD8, 0x6B, 0x43, 0x16, 0xC7, 0xBE,
  43780. 0x4A, 0x88, 0x03, 0x38, 0xBA, 0xCF, 0xB0, 0x15,
  43781. 0x69, 0x9B, 0xF3, 0x0D, 0x3A, 0x4B, 0x05, 0x32,
  43782. 0x54, 0x35, 0xBA, 0x5F, 0xA3, 0xB9, 0xD2, 0xB2,
  43783. 0xFE, 0x0B, 0x51, 0x9C, 0x2C, 0xB2, 0x46, 0xE5,
  43784. 0x3D, 0x1A, 0x34, 0x3D, 0x66, 0x1A, 0x66, 0x14,
  43785. 0x3C, 0x6F, 0x46, 0x8C, 0x55, 0x38, 0x64, 0x5C,
  43786. 0xC2, 0x6D, 0x4E, 0x2A, 0x87, 0x03, 0xEC, 0x9B,
  43787. 0x10, 0xFC, 0x89, 0xBE, 0x6F, 0x85, 0x99, 0x97,
  43788. 0x70, 0x8F, 0x31, 0x19, 0x4F, 0x0D, 0xFE, 0xE9,
  43789. 0x29, 0x98, 0xB2, 0x5E, 0x93, 0xB9, 0x70, 0x70,
  43790. 0xDE, 0x14, 0x40, 0x9D, 0x5B, 0xA4, 0x3D, 0xF8,
  43791. 0x8D, 0x15, 0xC2, 0xFB, 0xA9, 0x7B, 0xDD, 0xE6,
  43792. 0x18, 0xCC, 0x3F, 0xC0, 0x42, 0xF7, 0x74, 0x81,
  43793. 0x84, 0xBA, 0x9E, 0xC9, 0xCB, 0xA1, 0xB2, 0x00,
  43794. 0x68, 0x81, 0xD0, 0x51, 0x42, 0x64, 0x19, 0x8F,
  43795. 0xB6, 0x91, 0xC5, 0xC0, 0x38, 0xE0, 0x49, 0x50,
  43796. 0xCF, 0x69, 0x09, 0x93, 0x77, 0xFE, 0x66, 0xBA,
  43797. 0x64, 0xE2, 0x19, 0x52, 0xA4, 0x45, 0x81, 0x71,
  43798. 0x96, 0x64, 0xF5, 0xD9, 0x23, 0x97, 0xD2, 0x2A,
  43799. 0xA7, 0x03, 0x2B, 0xF5, 0x89, 0xAF, 0x8A, 0xCA,
  43800. 0x48, 0xDF, 0x6D, 0x14, 0xEB, 0x43, 0xCE, 0xF0,
  43801. 0xA9, 0xC8, 0xA8, 0xF9, 0xAD, 0x32, 0x95, 0x25,
  43802. 0xEF, 0x0A, 0xAA, 0x4F, 0x9E, 0x09, 0xC3, 0x51,
  43803. 0x3C, 0xF0, 0x29, 0xF3, 0xDE, 0xFC, 0xBB, 0x41,
  43804. 0x14, 0xFA, 0x0F, 0x66, 0x8D, 0xB4, 0x72, 0x2F,
  43805. 0xCC, 0xD9, 0xC2, 0x07, 0xB6, 0x6F, 0x10, 0x9E,
  43806. 0xD9, 0x5B, 0x45, 0x4B, 0xB6, 0x19, 0x5D, 0x59,
  43807. 0xC4, 0xA6, 0x78, 0xBA, 0x6F, 0x5A, 0x9B, 0x23,
  43808. 0x41, 0x21, 0xAD, 0x05, 0x16, 0xA1, 0xD4, 0x12,
  43809. 0x3D, 0x38, 0x26, 0xD9, 0x2A, 0x61, 0xB3, 0x5D,
  43810. 0xEB, 0x29, 0x5B, 0xAA, 0x2F, 0xE1, 0xB5, 0xEE,
  43811. 0x25, 0x02, 0x1D, 0xAE, 0xF8, 0x57, 0xB5, 0xDF,
  43812. 0x19, 0x2E, 0x17, 0x5E, 0x3A, 0x2A, 0x0D, 0x3F,
  43813. 0x08, 0x2F, 0x21, 0x1C, 0xB5, 0xBD, 0xC2, 0x36,
  43814. 0x27, 0x4F, 0x86, 0xC5, 0xDC, 0x74, 0xC3, 0x9B,
  43815. 0xE9, 0x7C, 0xCF, 0x5F, 0x57, 0x94, 0xEB, 0x64,
  43816. 0xEC, 0x64, 0x55, 0x45, 0x21, 0x0F, 0xC6, 0x67,
  43817. 0xD1, 0xE0, 0x74, 0x0E, 0x66, 0xCB, 0xED, 0xC2,
  43818. 0x06, 0x48, 0xCA, 0x1F, 0xA7, 0x34, 0x14, 0x59,
  43819. 0x6B, 0xA0, 0x89, 0x17, 0xA1, 0x9A, 0x46, 0x3A,
  43820. 0xD3, 0x02, 0x7C, 0x81, 0x83, 0x6B, 0x8F, 0x4F,
  43821. 0x02, 0xB9, 0x9F, 0xC5, 0x08, 0x3F, 0x06, 0xF3,
  43822. 0x4B, 0xD2, 0x30, 0x9C, 0x23, 0x42, 0xAD, 0x88,
  43823. 0xA8, 0x4F, 0xA9, 0x6E, 0x20, 0x7C, 0x01, 0x08,
  43824. 0xF6, 0x82, 0x54, 0x14, 0x94, 0x4F, 0x26, 0x4E,
  43825. 0xD6, 0xC4, 0x66, 0x7C, 0x78, 0x8D, 0x61, 0xA6,
  43826. 0xBC, 0x2C, 0x45, 0x6A, 0xF6, 0x6C, 0x2F, 0x76,
  43827. 0x9E, 0x16, 0x90, 0x17, 0x06, 0x91, 0x2C, 0xC9,
  43828. 0x0D, 0x4B, 0x6C, 0x90, 0xDC, 0xA1, 0x6C, 0xAC,
  43829. 0x8F, 0xFE, 0xD8, 0x39, 0x70, 0x20, 0xE2, 0x97,
  43830. 0x5E, 0x24, 0xFF, 0x4C, 0x80, 0x7C, 0x8A, 0xB7,
  43831. 0x31, 0xC8, 0x1D, 0x36, 0xCA, 0x84, 0xC9, 0x12,
  43832. 0x1A, 0x85, 0x13, 0xE0, 0xC9, 0xD0, 0xF4, 0x1B,
  43833. 0xC6, 0x8F, 0x88, 0xEA, 0xCA, 0xA3, 0x55, 0x99,
  43834. 0xFA, 0xE3, 0xBB, 0xA6, 0xFC, 0xC6, 0x52, 0x8D,
  43835. 0x47, 0xE4, 0x0C, 0x07, 0x64, 0xCF, 0x9C, 0x83,
  43836. 0x83, 0xB3, 0xA4, 0x45, 0x15, 0xE6, 0x1D, 0x92,
  43837. 0xCD, 0xAE, 0xC9, 0xCB, 0x90, 0x82, 0xB5, 0xA0,
  43838. 0xC0, 0x37, 0x94, 0x60, 0xD9, 0x17, 0x9A, 0x7D,
  43839. 0x9D, 0xF2, 0x9E, 0x0B, 0x4B, 0x6A, 0x41, 0x18,
  43840. 0x28, 0x52, 0x15, 0xE8, 0x7B, 0x6F, 0x11, 0x8E,
  43841. 0x97, 0x31, 0xE4, 0x66, 0xFB, 0x3F, 0xEB, 0xD1,
  43842. 0x95, 0xE1, 0x44, 0xFD, 0x20, 0x37, 0xD1, 0x16,
  43843. 0x62, 0x75, 0x79, 0xAC, 0x55, 0xFE, 0xD5, 0xE3,
  43844. 0x25, 0x85, 0xEC, 0x66, 0x38, 0xA0, 0xDF, 0xBE,
  43845. 0x6E, 0xD6, 0xC5, 0x87, 0x6C, 0xF8, 0x11, 0x4C,
  43846. 0x90, 0x2A, 0xEF, 0xA3, 0x63, 0xF4, 0xC9, 0xB7,
  43847. 0x2E, 0x7D, 0x5C, 0x85, 0x2D, 0xCC, 0x1A, 0xF2,
  43848. 0xB8, 0x85, 0x2A, 0x9D, 0x0F, 0x99, 0x59, 0x38,
  43849. 0x86, 0x50, 0x84, 0xCE, 0x52, 0x13, 0xB3, 0x08,
  43850. 0xA9, 0xCB, 0x37, 0xF6, 0x81, 0x96, 0x0D, 0x84,
  43851. 0xEF, 0xE1, 0xDF, 0x51, 0x34, 0xA5, 0x91, 0x5A,
  43852. 0xE5, 0x87, 0x8B, 0x10, 0xDA, 0x0F, 0xD4, 0xD9,
  43853. 0xAC, 0x2A, 0xEF, 0x0C, 0x7E, 0x01, 0xC2, 0xE9,
  43854. 0xE7, 0xC0, 0x17, 0xE7, 0xBA, 0x74, 0x0C, 0xEE,
  43855. 0x1A, 0x89, 0x94, 0x59, 0xBB, 0x75, 0x03, 0x3E,
  43856. 0xEA, 0xF3, 0x19, 0x0D, 0x67, 0x79, 0xED, 0x9E,
  43857. 0xDD, 0x84, 0x6A, 0x74, 0xE3, 0x21, 0x52, 0x8C,
  43858. 0x03, 0x08, 0x4A, 0x5D, 0x30, 0x87, 0x48, 0x39,
  43859. 0x71, 0x8A, 0x53, 0x54, 0x9B, 0x2E, 0xC6, 0xB2,
  43860. 0xB7, 0x30, 0xAA, 0x93, 0x5C, 0xA6, 0xE1, 0xC4,
  43861. 0xFD, 0x8B, 0xE0, 0x35, 0x7D, 0x93, 0xF6, 0x21,
  43862. 0x74, 0xEE, 0xED, 0xF8, 0xDA, 0xB7, 0x75, 0x5B,
  43863. 0x46, 0x65, 0x7E, 0x59, 0xD7, 0xAA, 0x00, 0xB9,
  43864. 0xF2, 0xF8, 0x5E, 0x4C, 0x0F, 0x77, 0xFA, 0x11,
  43865. 0xA5, 0xD6, 0x9A, 0x23, 0xB1, 0xEF, 0x3A, 0x09,
  43866. 0xF2, 0x19, 0xD8, 0x3B, 0x1F, 0x39, 0x1F, 0x84,
  43867. 0x13, 0x18, 0xEE, 0xF3, 0x5A, 0x32, 0x63, 0x67,
  43868. 0xBF, 0xA2, 0xB1, 0x5F, 0xD7, 0x14, 0x03, 0x20,
  43869. 0x92, 0xB9, 0xD0, 0x2B, 0xF6, 0x13, 0xAF, 0xF7,
  43870. 0x69, 0x6F, 0xAD, 0xF1, 0xDE, 0x2C, 0x81, 0x70,
  43871. 0x77, 0xCB, 0x7C, 0x99, 0x67, 0x76, 0xD6, 0x9E,
  43872. 0xC2, 0x41, 0xA2, 0x42, 0x54, 0xDA, 0x2D, 0x13,
  43873. 0x98, 0x76, 0x91, 0xEA, 0xC7, 0xEB, 0xA8, 0xCD,
  43874. 0x8D, 0xCF, 0xB3, 0x94, 0x7B, 0x1D, 0x99, 0xED,
  43875. 0xF9, 0x62, 0xD2, 0x15, 0xB3, 0x18, 0xBB, 0x5F,
  43876. 0x9A, 0xA0, 0x4D, 0x1C, 0x82, 0x62, 0x6A, 0x41,
  43877. 0x73, 0xD0, 0x2D, 0x41, 0x0C, 0x58, 0x6B, 0xCA,
  43878. 0x4E, 0x51, 0xCA, 0x4F, 0x3E, 0x15, 0x1B, 0x54,
  43879. 0xF1, 0x7A, 0x6B, 0xC9, 0x67, 0x76, 0x09, 0xBB,
  43880. 0xAF, 0x6C, 0x30, 0x38, 0xA6, 0x7C, 0xAD, 0xA6,
  43881. 0x6B, 0x4F, 0xDF, 0xB5, 0x10, 0x29, 0xE0, 0x78,
  43882. 0x07, 0xD7, 0x05, 0x96, 0x9D, 0x96, 0xC9, 0xAB,
  43883. 0xFB, 0x71, 0x62, 0xE4, 0x58, 0x10, 0xA1, 0xDC,
  43884. 0x4B, 0x56, 0xDA, 0x14, 0x77, 0xED, 0x90, 0x0A,
  43885. 0x89, 0xCC, 0xAC, 0x29, 0x8E, 0x17, 0x88, 0x42,
  43886. 0x69, 0xC3, 0x9E, 0x8D, 0x7A, 0xB9, 0x66, 0xF3,
  43887. 0x3D, 0xDA, 0xDB, 0xE5, 0x6A, 0x38, 0x4C, 0xA2,
  43888. 0x0A, 0x7B, 0x18, 0x99, 0xEC, 0x18, 0xE2, 0xAE,
  43889. 0x54, 0x70, 0x00, 0xB9, 0x04, 0xE3, 0x4E, 0x46,
  43890. 0x80, 0x1D, 0x85, 0x74, 0xDB, 0x00, 0x84, 0x17,
  43891. 0xBC, 0xFD, 0xD1, 0xA7, 0x4D, 0xC0, 0x18, 0xE5,
  43892. 0x07, 0xB7, 0x6B, 0x0F, 0xA0, 0x86, 0x26, 0x23,
  43893. 0x5B, 0x1C, 0xE2, 0x4B, 0xCF, 0xC3, 0x20, 0xFA,
  43894. 0xE3, 0x55, 0x1C, 0x1C, 0x92, 0x9B, 0x94, 0xC7,
  43895. 0xC4, 0x96, 0x53, 0x41, 0x82, 0x9D, 0x8A, 0x13,
  43896. 0x47, 0xD6, 0xA7, 0x38, 0x58, 0x03, 0xB0, 0x8B,
  43897. 0xCD, 0xA8, 0x4A, 0x27, 0xEA, 0x5E, 0x49, 0xCA,
  43898. 0x1E, 0x60, 0x06, 0xEA, 0x23, 0x2A, 0x53, 0xEE,
  43899. 0x41, 0x7E, 0xC8, 0x81, 0xD3, 0x32, 0x8A, 0x15,
  43900. 0x63, 0x82, 0xA6, 0xB2, 0x93, 0x89, 0x4D, 0xDF,
  43901. 0x9B, 0x36, 0x9C, 0xDE, 0x6B, 0x2F, 0xF5, 0x9C,
  43902. 0xB6, 0xA5, 0x64, 0xE2, 0x1C, 0x92, 0x79, 0xEC,
  43903. 0xA0, 0x31, 0x1F, 0x5D, 0x80, 0xCE, 0x39, 0xB9,
  43904. 0x8B, 0xF9, 0x0D, 0xB3, 0x27, 0xF7, 0x4D, 0x3F,
  43905. 0x76, 0x2D, 0x11, 0x7D, 0xF5, 0xF9, 0x13, 0x20,
  43906. 0x84, 0xFF, 0xB5, 0x55, 0xA5, 0xD1, 0x47, 0x22,
  43907. 0x1A, 0xF8, 0x63, 0xAB, 0xF7, 0x87, 0x15, 0xB7,
  43908. 0x21, 0x94, 0x52, 0x9A, 0x0E, 0x33, 0x4D, 0x4A,
  43909. 0x19, 0x1D, 0x42, 0xA9, 0x9B, 0xEA, 0x52, 0xAD,
  43910. 0xA2, 0xC7, 0xCC, 0x4A, 0x97, 0x74, 0xD5, 0xCB,
  43911. 0x28, 0xD4, 0xED, 0x82, 0xB6, 0x1F, 0x94, 0xE8,
  43912. 0x9F, 0x60, 0xF0, 0xC8, 0xEA, 0x52, 0xDC, 0x07,
  43913. 0x9D, 0x46, 0x58, 0xBF, 0x8C, 0x85, 0x6D, 0x61,
  43914. 0x52, 0xD9, 0x22, 0x51, 0x94, 0x8B, 0x3B, 0xA0,
  43915. 0x14, 0xD8, 0xBA, 0xF3, 0xDC, 0xD3, 0x6B, 0xC7,
  43916. 0x1F, 0x8E, 0x5B, 0x2C, 0xE6, 0xF5, 0x35, 0xB7,
  43917. 0xB9, 0xAE, 0x13, 0xDA, 0x4A, 0x1E, 0xAF, 0xFC,
  43918. 0x25, 0x3B, 0xE4, 0x3A, 0x9F, 0x60, 0x8E, 0xAC,
  43919. 0xE7, 0x33, 0xCF, 0xCE, 0x52, 0xEA, 0x5C, 0xDA,
  43920. 0x83, 0x59, 0xDB, 0x53, 0xFF, 0x3A, 0xF2, 0xCE,
  43921. 0xFE, 0x87, 0x79, 0xBC, 0xC5, 0x3C, 0x24, 0xA4,
  43922. 0xB1, 0x8D, 0x5E, 0x0D, 0x78, 0x1B, 0xEC, 0xF7,
  43923. 0x5B, 0x54, 0x77, 0x47, 0x3A, 0x20, 0x24, 0xAD,
  43924. 0x56, 0xC5, 0x4A, 0x7F, 0x99, 0x0E, 0xF6, 0xB1,
  43925. 0xDF, 0xAC, 0x50, 0x10, 0x88, 0x50, 0x9D, 0x3A,
  43926. 0x37, 0xF1, 0xC8, 0xD5, 0xC2, 0x64, 0x87, 0xE4,
  43927. 0x20, 0xB7, 0xF4, 0x35, 0x8E, 0x92, 0x69, 0x76,
  43928. 0x1F, 0xF1, 0xFA, 0x3A, 0xFC, 0xBE, 0xCA, 0xEB,
  43929. 0x68, 0xF5, 0xDD, 0xDE, 0x3A, 0xA8, 0xFD, 0x07,
  43930. 0x8C, 0xC4, 0x22, 0x4C, 0xEA, 0x67, 0x13, 0x2D,
  43931. 0x7E, 0xBF, 0x5D, 0x23, 0x2E, 0x43, 0xBA, 0xDD,
  43932. 0x21, 0x8C, 0x0B, 0x4D, 0xBE, 0x1E, 0x16, 0x52,
  43933. 0x98, 0x66, 0xB9, 0xAB, 0x93, 0x58, 0x85, 0xAC,
  43934. 0xB4, 0x15, 0xFB, 0xB1, 0xEE, 0xE6, 0x94, 0x08,
  43935. 0xA5, 0x21, 0xB4, 0x62, 0xEC, 0x59, 0xCD, 0x0D,
  43936. 0x3C, 0x54, 0x96, 0xD9, 0x85, 0xAE, 0xB0, 0xCE,
  43937. 0x37, 0x4F, 0x67, 0x72, 0xA4, 0xE6, 0x39, 0x3A,
  43938. 0x4E, 0xF0, 0x07, 0x43, 0x80, 0x90, 0xA8, 0xA9,
  43939. 0xE5, 0x2D, 0x2F, 0x55, 0x66, 0x6D, 0x70, 0xF0,
  43940. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  43941. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  43942. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
  43943. 0x08, 0x0E, 0x12, 0x19, 0x20
  43944. };
  43945. #endif
  43946. #ifndef WOLFSSL_NO_ML_DSA_87
  43947. static const byte pk_87_draft[] = {
  43948. 0x2D, 0x1E, 0x6B, 0xED, 0x84, 0x52, 0xEB, 0xF1,
  43949. 0x26, 0xED, 0xE7, 0x0C, 0xA0, 0xA2, 0xB5, 0x0D,
  43950. 0x03, 0x34, 0x2D, 0x5B, 0x13, 0xB2, 0xAE, 0x21,
  43951. 0x0F, 0x45, 0x62, 0xA3, 0xBF, 0x67, 0x0C, 0xB1,
  43952. 0x5C, 0xE9, 0x25, 0xFD, 0x22, 0xF2, 0x62, 0x42,
  43953. 0xBA, 0xE3, 0x10, 0xB3, 0xAA, 0x41, 0x3B, 0x6E,
  43954. 0x78, 0xD4, 0x42, 0xD9, 0x35, 0xD1, 0x72, 0x8A,
  43955. 0x32, 0x48, 0xCC, 0x20, 0x5C, 0xCD, 0x8D, 0x3F,
  43956. 0xD8, 0x34, 0x95, 0x55, 0x20, 0xCD, 0xFB, 0x2C,
  43957. 0x73, 0xE9, 0x0E, 0x60, 0x8B, 0x2C, 0x3F, 0xA8,
  43958. 0xB7, 0xD1, 0x79, 0xFD, 0xDC, 0xC8, 0x81, 0x11,
  43959. 0xC9, 0xE8, 0x41, 0x71, 0xE9, 0x70, 0x9B, 0x53,
  43960. 0x59, 0x33, 0xE4, 0x92, 0xB6, 0x81, 0x9C, 0x6A,
  43961. 0x92, 0xED, 0xA2, 0x5A, 0xC4, 0x07, 0x77, 0x1A,
  43962. 0x8F, 0xED, 0xB4, 0xE7, 0x11, 0xFB, 0x89, 0xEB,
  43963. 0x7B, 0xDF, 0xCC, 0xEA, 0xC5, 0x3B, 0x4E, 0xF4,
  43964. 0x6B, 0x6F, 0xBE, 0xE1, 0x32, 0xA9, 0xD7, 0xAD,
  43965. 0xB4, 0x36, 0xE7, 0x4A, 0x6D, 0x67, 0x11, 0x83,
  43966. 0xAF, 0x31, 0x1A, 0x7A, 0x31, 0x42, 0x9B, 0x01,
  43967. 0x21, 0x17, 0x52, 0x75, 0x85, 0xF7, 0x92, 0x0F,
  43968. 0x34, 0x8A, 0x69, 0x11, 0x88, 0x5A, 0x02, 0x08,
  43969. 0xB6, 0x6D, 0xE3, 0x07, 0x93, 0xB1, 0x3F, 0xE1,
  43970. 0xD5, 0x7B, 0xD9, 0x51, 0xF7, 0xAA, 0xC0, 0x34,
  43971. 0x9A, 0x78, 0x5D, 0x26, 0xDB, 0xF1, 0xF0, 0xA9,
  43972. 0x1E, 0x5C, 0x9F, 0x4F, 0xA7, 0x43, 0x5C, 0x44,
  43973. 0xA9, 0x43, 0xF1, 0x38, 0x11, 0x45, 0xED, 0xEB,
  43974. 0x1C, 0x8A, 0x05, 0xEE, 0xFF, 0xAB, 0x20, 0x2C,
  43975. 0xF6, 0x2C, 0xEE, 0x77, 0x42, 0x36, 0x3E, 0xE6,
  43976. 0x9D, 0x8E, 0x45, 0x0F, 0xF6, 0x7C, 0x39, 0x62,
  43977. 0xD6, 0xFF, 0x97, 0xBC, 0x3D, 0x02, 0xD6, 0xDF,
  43978. 0x4A, 0x35, 0xDA, 0x3F, 0x89, 0xA4, 0x88, 0x33,
  43979. 0xCD, 0xF2, 0x90, 0xF0, 0xE9, 0x37, 0x2F, 0x65,
  43980. 0xA5, 0x88, 0x65, 0xFD, 0x40, 0x44, 0xAD, 0x09,
  43981. 0x09, 0x92, 0xAA, 0x15, 0x9E, 0xEE, 0xF7, 0x2B,
  43982. 0x0D, 0xA7, 0xCB, 0x3A, 0x5E, 0x0A, 0xED, 0xD6,
  43983. 0x7D, 0x82, 0x8B, 0xBA, 0xCF, 0xE5, 0x9E, 0xE4,
  43984. 0x62, 0xAB, 0x69, 0x6B, 0xBA, 0xD0, 0xE5, 0xA9,
  43985. 0xBB, 0x1F, 0x5A, 0x51, 0xE0, 0xFA, 0x5D, 0xD4,
  43986. 0x4D, 0x8E, 0xC0, 0xDC, 0x43, 0x06, 0xDF, 0x23,
  43987. 0x67, 0xB2, 0x4A, 0xA2, 0xFB, 0x75, 0x2F, 0x82,
  43988. 0xD8, 0x44, 0xE4, 0xC0, 0xCE, 0x15, 0x9E, 0x3F,
  43989. 0xD6, 0xB4, 0x70, 0x5F, 0x3B, 0xD0, 0x56, 0x3E,
  43990. 0x0A, 0x7A, 0x4B, 0x94, 0xBF, 0xBA, 0x01, 0x2B,
  43991. 0x9C, 0x8B, 0x91, 0x35, 0xF2, 0xDB, 0x4C, 0x8C,
  43992. 0x8D, 0xD6, 0xEE, 0xC8, 0x65, 0x8D, 0xF3, 0x05,
  43993. 0x59, 0xBE, 0x3A, 0x17, 0xA7, 0x72, 0x10, 0x56,
  43994. 0x14, 0xEF, 0xB8, 0xC1, 0xBE, 0x18, 0x11, 0x0B,
  43995. 0xE6, 0x70, 0xF8, 0x39, 0xA5, 0x72, 0x7D, 0xF9,
  43996. 0x47, 0xFB, 0xAC, 0xFD, 0x1F, 0xC3, 0x71, 0x33,
  43997. 0x58, 0x44, 0x15, 0xD3, 0x7C, 0x93, 0x2E, 0x70,
  43998. 0x92, 0xFA, 0xBB, 0xF2, 0xD0, 0x9D, 0x25, 0xC4,
  43999. 0xCF, 0x4A, 0xB8, 0xEC, 0xBE, 0x5D, 0x8B, 0x7F,
  44000. 0xA4, 0x7C, 0xAB, 0xAD, 0xE7, 0x1E, 0x93, 0x83,
  44001. 0x92, 0x86, 0x1E, 0x8D, 0x15, 0xA4, 0x1C, 0x5B,
  44002. 0x42, 0x25, 0xDA, 0x3D, 0x16, 0xD3, 0x93, 0xF2,
  44003. 0x85, 0x50, 0x86, 0x0A, 0x86, 0x35, 0x6B, 0x14,
  44004. 0xAB, 0x5F, 0x22, 0xD0, 0xCF, 0x03, 0x7C, 0xEB,
  44005. 0xB4, 0x0E, 0xAC, 0x87, 0xA2, 0x41, 0x42, 0xA0,
  44006. 0x21, 0x93, 0x00, 0xB6, 0x47, 0x6F, 0x96, 0xD0,
  44007. 0x41, 0xD1, 0xC3, 0x0E, 0x3C, 0x52, 0xD2, 0x45,
  44008. 0xAB, 0x6A, 0xE7, 0xA1, 0xE5, 0xFD, 0x73, 0xC5,
  44009. 0x82, 0x9D, 0x60, 0x62, 0x8B, 0x6D, 0x87, 0xFC,
  44010. 0x88, 0x9C, 0x3E, 0xEF, 0xAE, 0xAA, 0xB6, 0x1C,
  44011. 0x18, 0xEE, 0xD7, 0x51, 0x1A, 0x96, 0xC4, 0x93,
  44012. 0x25, 0x05, 0xD3, 0x83, 0x3D, 0xD8, 0x33, 0x16,
  44013. 0x14, 0x44, 0x88, 0xE2, 0xAF, 0xC4, 0xEC, 0x59,
  44014. 0x18, 0x12, 0xB9, 0x99, 0xC1, 0xC9, 0x5F, 0x31,
  44015. 0x79, 0x00, 0x03, 0xF6, 0xC9, 0x55, 0x14, 0xAA,
  44016. 0x29, 0x08, 0x78, 0x24, 0xAF, 0x1D, 0x99, 0x12,
  44017. 0x36, 0xD9, 0x4A, 0xD9, 0x50, 0xEF, 0x66, 0xFC,
  44018. 0x7F, 0xF4, 0xBC, 0x3B, 0xA0, 0xF6, 0xFD, 0xF2,
  44019. 0x62, 0xCA, 0xA5, 0x9D, 0x2B, 0x55, 0xB8, 0x33,
  44020. 0xBC, 0xA6, 0x7A, 0xA5, 0x1E, 0xE1, 0x14, 0x5F,
  44021. 0x94, 0xE2, 0xDC, 0xF0, 0x5B, 0xBD, 0x43, 0x07,
  44022. 0xD8, 0xB1, 0xE0, 0x81, 0x3F, 0x84, 0x54, 0x90,
  44023. 0xBF, 0x23, 0x59, 0x92, 0x3C, 0xA5, 0x98, 0xAB,
  44024. 0x7D, 0x99, 0xD2, 0xF0, 0xED, 0x8E, 0x0B, 0xC9,
  44025. 0x9F, 0xAF, 0xB0, 0x13, 0xED, 0xC7, 0xDD, 0xB8,
  44026. 0x61, 0x72, 0x07, 0x3D, 0xCC, 0x35, 0x73, 0xA0,
  44027. 0xCF, 0x0C, 0xD9, 0x7E, 0x93, 0xDC, 0x63, 0xB8,
  44028. 0x82, 0xEC, 0xF4, 0x30, 0xCE, 0x43, 0x92, 0xEA,
  44029. 0x5E, 0xD8, 0xC8, 0xA1, 0xEC, 0x79, 0xDC, 0xAE,
  44030. 0x64, 0xD4, 0x33, 0xEB, 0x53, 0x8C, 0xFC, 0x49,
  44031. 0x79, 0xBF, 0x7A, 0x28, 0x65, 0x1E, 0x8C, 0xD5,
  44032. 0x21, 0xB0, 0x8E, 0xCA, 0xAD, 0xF8, 0x96, 0x9A,
  44033. 0x98, 0x10, 0x00, 0x35, 0x6D, 0x58, 0x9A, 0xEF,
  44034. 0x84, 0x84, 0x86, 0x72, 0xBA, 0xCD, 0x38, 0x66,
  44035. 0x96, 0x9B, 0xC2, 0x83, 0xB0, 0x65, 0xC1, 0xAB,
  44036. 0xCF, 0x63, 0x8C, 0x2D, 0xC3, 0x42, 0xB2, 0x7D,
  44037. 0xF6, 0xB8, 0xF0, 0x3D, 0x26, 0x21, 0x8F, 0xAE,
  44038. 0x4E, 0x96, 0xF2, 0x55, 0x66, 0xBC, 0x6F, 0xED,
  44039. 0xE7, 0x19, 0xD3, 0x8D, 0xC0, 0xCD, 0x55, 0x20,
  44040. 0x5F, 0x10, 0xCA, 0xDA, 0x09, 0xED, 0x91, 0x4A,
  44041. 0x43, 0x33, 0xD3, 0x82, 0x11, 0x5C, 0x2F, 0x5D,
  44042. 0xEC, 0xCD, 0x54, 0xF9, 0x6C, 0xE4, 0xE5, 0xF2,
  44043. 0x68, 0xBC, 0xE9, 0x27, 0xB2, 0x1D, 0xCA, 0xB5,
  44044. 0xCD, 0x04, 0x01, 0x1E, 0x92, 0xF5, 0xF6, 0x01,
  44045. 0x86, 0x2B, 0x20, 0x20, 0x9B, 0xB0, 0xF9, 0x56,
  44046. 0xD9, 0x33, 0xD5, 0x0A, 0xEC, 0x1B, 0xF4, 0xCE,
  44047. 0xD2, 0xB2, 0xC2, 0xD4, 0x3F, 0x9A, 0x25, 0x76,
  44048. 0x8E, 0x29, 0x87, 0x52, 0x64, 0x86, 0x4A, 0xA5,
  44049. 0x7B, 0x5A, 0x91, 0x72, 0x6E, 0xBE, 0x6D, 0x73,
  44050. 0x0A, 0x8D, 0x89, 0x53, 0x82, 0x33, 0x70, 0x44,
  44051. 0x20, 0xBE, 0xE0, 0xB0, 0x1B, 0x76, 0x30, 0x43,
  44052. 0xA5, 0x5B, 0x8F, 0xAB, 0x7E, 0xB8, 0x61, 0x5F,
  44053. 0x43, 0x70, 0x1B, 0x1A, 0x71, 0x61, 0x56, 0xF9,
  44054. 0x13, 0x31, 0x2A, 0x64, 0x33, 0x14, 0x00, 0x98,
  44055. 0x72, 0xEC, 0x32, 0x88, 0x09, 0xFB, 0x64, 0x46,
  44056. 0x3D, 0x56, 0x02, 0xD9, 0x76, 0xD3, 0xAA, 0x90,
  44057. 0x0F, 0xBD, 0xF0, 0xF9, 0x96, 0x43, 0x7B, 0x62,
  44058. 0x19, 0x26, 0x22, 0x6A, 0x93, 0x91, 0xEC, 0x07,
  44059. 0x34, 0xF5, 0x22, 0x32, 0xB3, 0x65, 0x66, 0xE0,
  44060. 0x6B, 0x11, 0x7F, 0x97, 0x9F, 0x1A, 0x89, 0x46,
  44061. 0xCE, 0x8F, 0xBD, 0xFD, 0x2F, 0xCC, 0x3D, 0xBF,
  44062. 0xF2, 0x83, 0xA4, 0x30, 0xE1, 0x02, 0x72, 0xF8,
  44063. 0x74, 0xE6, 0x21, 0x96, 0x77, 0xE1, 0x57, 0x8A,
  44064. 0xF7, 0x9E, 0xB3, 0x31, 0xAF, 0xD8, 0xC5, 0xD7,
  44065. 0x20, 0xDC, 0xFD, 0xCF, 0x79, 0x06, 0x0F, 0x1F,
  44066. 0xE5, 0x84, 0x3D, 0x0B, 0x9C, 0xB3, 0xC7, 0xAB,
  44067. 0xB8, 0xF1, 0xC0, 0xD0, 0xB5, 0xC7, 0x01, 0xE2,
  44068. 0x0E, 0x3B, 0xAF, 0x7E, 0xAC, 0x44, 0x5A, 0x75,
  44069. 0x50, 0x0A, 0x76, 0x1C, 0x13, 0xDB, 0x25, 0xD4,
  44070. 0x0D, 0x19, 0x75, 0x4C, 0x02, 0xD9, 0xF3, 0xDF,
  44071. 0x6D, 0xBB, 0xCF, 0x47, 0xA6, 0xAE, 0xF6, 0xD1,
  44072. 0xFB, 0xF4, 0xB4, 0x55, 0xD3, 0xA5, 0x87, 0xA1,
  44073. 0x55, 0xFB, 0xBF, 0xCD, 0xF6, 0xA1, 0x64, 0x57,
  44074. 0x12, 0x75, 0x9A, 0x11, 0xA3, 0xCE, 0x42, 0x70,
  44075. 0x84, 0x54, 0x93, 0x12, 0xE1, 0x3A, 0x0F, 0xFA,
  44076. 0xCA, 0xF2, 0x25, 0x91, 0xF1, 0x4D, 0x8F, 0x84,
  44077. 0xB1, 0xB5, 0x35, 0xAC, 0xE9, 0x81, 0x77, 0x34,
  44078. 0x4D, 0x6F, 0x5D, 0x14, 0x9D, 0xB9, 0xE1, 0xF0,
  44079. 0x3F, 0x3C, 0xE7, 0xAD, 0x48, 0xE6, 0x8C, 0x51,
  44080. 0x86, 0xF4, 0x4A, 0xB4, 0xD0, 0x98, 0xEC, 0x3A,
  44081. 0x4E, 0xAB, 0x58, 0x2F, 0x08, 0x9E, 0x5A, 0x9D,
  44082. 0x45, 0x30, 0xB0, 0x85, 0xDF, 0x4A, 0xE7, 0x92,
  44083. 0xC6, 0xC8, 0x18, 0x93, 0x08, 0xCE, 0x9A, 0x8C,
  44084. 0xE2, 0x91, 0x8D, 0x91, 0x57, 0x7B, 0x37, 0xC8,
  44085. 0x80, 0xA2, 0x31, 0x10, 0x0D, 0x4E, 0xEF, 0x51,
  44086. 0x07, 0x94, 0x8E, 0xF8, 0x3C, 0x3C, 0x2E, 0xD5,
  44087. 0x03, 0x26, 0xB8, 0x72, 0x7F, 0xB9, 0xBC, 0xD7,
  44088. 0x95, 0xC4, 0x31, 0x08, 0xEC, 0x6F, 0xEE, 0x11,
  44089. 0xAF, 0xC0, 0xA2, 0xEC, 0xD7, 0xC8, 0x0B, 0xBE,
  44090. 0x15, 0xAE, 0xC9, 0x17, 0xBE, 0x37, 0xE2, 0x40,
  44091. 0x83, 0x65, 0xDE, 0xB3, 0x4E, 0xB4, 0x15, 0xB3,
  44092. 0x5C, 0x14, 0xF6, 0x5F, 0xA9, 0x1F, 0x70, 0xB5,
  44093. 0x23, 0x93, 0x78, 0xB9, 0x47, 0xF9, 0x1D, 0x2B,
  44094. 0x1E, 0x8D, 0xB1, 0x25, 0x7E, 0xE5, 0x85, 0x3C,
  44095. 0x16, 0x9F, 0xD0, 0xC2, 0x67, 0x8B, 0x0D, 0xD2,
  44096. 0x72, 0x4E, 0x74, 0x30, 0xE1, 0xAF, 0xB8, 0x66,
  44097. 0xCB, 0x53, 0xDF, 0xC4, 0xFB, 0xA5, 0x6D, 0x03,
  44098. 0xF2, 0xAE, 0xEE, 0x90, 0xFE, 0xD7, 0x30, 0xAF,
  44099. 0x33, 0x98, 0x09, 0xEB, 0x75, 0xC7, 0x3E, 0xC8,
  44100. 0x2F, 0xE7, 0x22, 0x5F, 0x2F, 0x0A, 0xBD, 0xA4,
  44101. 0x22, 0x88, 0x28, 0x19, 0x35, 0x83, 0x12, 0x86,
  44102. 0xEE, 0x72, 0xB4, 0x26, 0x89, 0x2F, 0xC7, 0x11,
  44103. 0x6E, 0xDD, 0x14, 0x98, 0x22, 0xE7, 0x73, 0x3E,
  44104. 0xFA, 0x46, 0x75, 0xF9, 0x40, 0xC1, 0x84, 0x22,
  44105. 0xBC, 0x75, 0x36, 0xC7, 0x82, 0xD3, 0xAE, 0x6E,
  44106. 0x0D, 0xBF, 0x6F, 0xC3, 0x4B, 0x67, 0x49, 0x19,
  44107. 0xF3, 0x4B, 0x12, 0xF2, 0x83, 0xFD, 0x39, 0x56,
  44108. 0x44, 0x05, 0x3A, 0x24, 0x6A, 0x35, 0x69, 0x12,
  44109. 0xCF, 0xE4, 0x93, 0xFE, 0x26, 0xCC, 0xD6, 0x01,
  44110. 0xA0, 0x4A, 0x84, 0xA8, 0x1D, 0x85, 0xE6, 0x83,
  44111. 0x0F, 0x3C, 0xE6, 0x6D, 0xD2, 0xCB, 0xB1, 0x14,
  44112. 0x8C, 0xEC, 0x10, 0xB3, 0x63, 0x4B, 0x9C, 0xF5,
  44113. 0x11, 0xE0, 0xF9, 0x86, 0x6F, 0xA7, 0xC0, 0x3B,
  44114. 0x9D, 0x25, 0xD7, 0x54, 0xCA, 0x40, 0x4D, 0x26,
  44115. 0xBA, 0x71, 0x8E, 0x25, 0xF5, 0xA7, 0xE3, 0x9B,
  44116. 0x25, 0x20, 0x7F, 0x29, 0x05, 0xB6, 0x27, 0x14,
  44117. 0x17, 0x67, 0x26, 0x10, 0xAD, 0xA3, 0x06, 0x03,
  44118. 0xFE, 0x82, 0x85, 0x5D, 0x01, 0x04, 0x4D, 0xE0,
  44119. 0x64, 0x38, 0x38, 0x5E, 0x83, 0x1E, 0x21, 0x9A,
  44120. 0x39, 0x02, 0xF8, 0xF9, 0x69, 0x85, 0x52, 0xE5,
  44121. 0xEC, 0x6A, 0xAC, 0x96, 0x86, 0xA7, 0x88, 0x69,
  44122. 0xB5, 0xB5, 0x7E, 0x03, 0x1D, 0xA9, 0x68, 0xCA,
  44123. 0x45, 0x0F, 0xF9, 0x14, 0xD6, 0x7B, 0xCF, 0x9C,
  44124. 0x03, 0x6F, 0xD1, 0xD9, 0x6F, 0x01, 0x3D, 0xF8,
  44125. 0xF3, 0x11, 0xF3, 0x29, 0x17, 0x90, 0xE8, 0x9B,
  44126. 0xED, 0x58, 0x9B, 0xF0, 0xBC, 0xC7, 0xBA, 0xF4,
  44127. 0x60, 0xC8, 0xAA, 0x30, 0xB4, 0x2F, 0x22, 0x8F,
  44128. 0xD3, 0xAC, 0x18, 0xC2, 0xB7, 0xC4, 0x7B, 0x31,
  44129. 0x9E, 0x0F, 0x7E, 0x9D, 0xBF, 0xD4, 0x63, 0xC2,
  44130. 0x8B, 0x1B, 0x58, 0x50, 0x33, 0x53, 0x6D, 0x79,
  44131. 0xBB, 0xF8, 0x0D, 0x91, 0x33, 0xD9, 0x07, 0xE7,
  44132. 0xB0, 0x81, 0xD4, 0xB4, 0x47, 0x61, 0x93, 0xF0,
  44133. 0xFB, 0x68, 0xBC, 0x1B, 0x41, 0xC2, 0xF5, 0x43,
  44134. 0x30, 0x7E, 0x76, 0xF9, 0xB1, 0xA3, 0xD6, 0xD4,
  44135. 0x26, 0xEA, 0x77, 0x75, 0x12, 0x7A, 0xC8, 0x30,
  44136. 0x9B, 0xCF, 0x45, 0xBE, 0x74, 0x7D, 0x8A, 0x8B,
  44137. 0xEC, 0xED, 0x11, 0xE6, 0xA1, 0xD1, 0xB8, 0xF1,
  44138. 0x90, 0xAD, 0x6D, 0x6A, 0xC6, 0x54, 0xE9, 0xDB,
  44139. 0xAD, 0x4C, 0x97, 0x39, 0xC8, 0xD8, 0x44, 0xA9,
  44140. 0x1A, 0x37, 0x16, 0x7E, 0x68, 0x45, 0x0C, 0xBB,
  44141. 0x10, 0xF4, 0xAE, 0x8E, 0x2B, 0x69, 0xFA, 0x95,
  44142. 0x3E, 0xA5, 0xC9, 0x91, 0xD3, 0xF1, 0xA3, 0x89,
  44143. 0x3F, 0x90, 0x86, 0x93, 0x1B, 0xF1, 0xA0, 0x89,
  44144. 0xC7, 0xF2, 0x23, 0x57, 0xD4, 0x8E, 0x2F, 0xD5,
  44145. 0x71, 0xCD, 0x36, 0xF1, 0x90, 0xB3, 0x98, 0x3E,
  44146. 0x19, 0xEA, 0xC8, 0x0F, 0x12, 0x9D, 0xBF, 0x58,
  44147. 0xED, 0xDC, 0x6B, 0x9A, 0x79, 0x84, 0xFC, 0xF0,
  44148. 0x4C, 0xC3, 0xB4, 0x0D, 0xB8, 0x7A, 0x8D, 0xAD,
  44149. 0x75, 0x40, 0xD5, 0xD5, 0xDE, 0xC8, 0xCA, 0x39,
  44150. 0x3E, 0x45, 0xE4, 0xBC, 0xF4, 0x33, 0xEA, 0x64,
  44151. 0xE1, 0x5E, 0x94, 0x42, 0x91, 0xAB, 0xBC, 0x42,
  44152. 0x2A, 0xB3, 0xD0, 0x60, 0x23, 0xCE, 0x57, 0x8E,
  44153. 0xFF, 0xAD, 0xA2, 0x2B, 0x64, 0xD9, 0x94, 0xA0,
  44154. 0x80, 0x0F, 0x8E, 0x50, 0x17, 0x08, 0x1D, 0x16,
  44155. 0xCF, 0x51, 0xD0, 0xB9, 0x28, 0xB6, 0x59, 0xEF,
  44156. 0x78, 0xCC, 0xC9, 0x96, 0xF9, 0xCA, 0x87, 0x7A,
  44157. 0xEE, 0xD9, 0x15, 0x5E, 0xDF, 0x5D, 0xBC, 0xC2,
  44158. 0x58, 0xE6, 0x04, 0xEE, 0x17, 0xDC, 0xB3, 0xF9,
  44159. 0x90, 0xF9, 0x88, 0x32, 0x9E, 0xA1, 0xDB, 0x1C,
  44160. 0x38, 0x56, 0x53, 0x90, 0x30, 0x69, 0x2E, 0x52,
  44161. 0x00, 0x2C, 0xF3, 0x0F, 0xD5, 0x80, 0x2E, 0x02,
  44162. 0x5B, 0x99, 0xBF, 0xCD, 0x11, 0x12, 0x64, 0x5B,
  44163. 0x56, 0xC6, 0x0A, 0xE6, 0x38, 0xE7, 0x4D, 0x21,
  44164. 0xE5, 0x98, 0x78, 0x9D, 0xE6, 0xCB, 0x60, 0xB4,
  44165. 0x2E, 0xE4, 0x98, 0x56, 0xCB, 0xAD, 0xE6, 0xDD,
  44166. 0x53, 0xF4, 0xC5, 0x67, 0xA2, 0x9F, 0xA0, 0x5C,
  44167. 0x7C, 0xFB, 0x24, 0x5A, 0xA7, 0x72, 0xD0, 0xE7,
  44168. 0x63, 0xF2, 0x5D, 0xBF, 0xD8, 0xE9, 0xF1, 0x6B,
  44169. 0xB4, 0x29, 0xA6, 0x28, 0xE6, 0x93, 0xD3, 0x87,
  44170. 0xB6, 0xD9, 0x3C, 0x39, 0x8D, 0xEA, 0x28, 0xC0,
  44171. 0x96, 0x3D, 0xF5, 0xC2, 0x3C, 0x29, 0xF2, 0x80,
  44172. 0x21, 0x8A, 0x03, 0x9D, 0x64, 0xF8, 0xBA, 0x81,
  44173. 0xC1, 0xDD, 0xA2, 0x88, 0x2A, 0x84, 0x2E, 0x3C,
  44174. 0xB5, 0x03, 0x95, 0xED, 0xAA, 0x6E, 0xE2, 0x6F,
  44175. 0x5E, 0x99, 0x3C, 0x63, 0xEE, 0xB8, 0x4F, 0x66,
  44176. 0x32, 0x77, 0x42, 0x23, 0x36, 0x29, 0x89, 0xB0,
  44177. 0xED, 0x5F, 0xF2, 0x5A, 0x65, 0x66, 0x3F, 0xD2,
  44178. 0x8B, 0x48, 0x68, 0x65, 0xDC, 0xE0, 0xB0, 0xC2,
  44179. 0x72, 0x73, 0xF1, 0xA4, 0xC6, 0x56, 0x2C, 0x5D,
  44180. 0xD8, 0xC6, 0x5C, 0x41, 0xCE, 0x30, 0x89, 0x59,
  44181. 0xA9, 0xD6, 0x45, 0x96, 0xD0, 0x8E, 0x7B, 0x25,
  44182. 0xE0, 0x13, 0xFB, 0xFE, 0x7C, 0xEA, 0xF3, 0x67,
  44183. 0x0D, 0xB2, 0x9A, 0x21, 0x3C, 0xCE, 0x99, 0x75,
  44184. 0xA9, 0x13, 0xCE, 0xF4, 0x23, 0x6E, 0x64, 0x00,
  44185. 0x30, 0x87, 0x70, 0x9C, 0xAD, 0x61, 0x81, 0x71,
  44186. 0x0E, 0x95, 0x19, 0x26, 0xCA, 0x55, 0x29, 0x71,
  44187. 0x99, 0xA6, 0x08, 0xAE, 0x54, 0x58, 0x75, 0xCD,
  44188. 0xC3, 0x8F, 0xE3, 0x83, 0xC1, 0x45, 0x62, 0xB4,
  44189. 0x8D, 0xCA, 0x66, 0x02, 0xEA, 0x34, 0x05, 0x5D,
  44190. 0x98, 0x3F, 0x38, 0xE6, 0x1C, 0xCE, 0x53, 0x1A,
  44191. 0xD9, 0x3F, 0x58, 0xEC, 0x16, 0x28, 0x45, 0xF5,
  44192. 0x38, 0xCE, 0x48, 0x43, 0x87, 0x1D, 0x3C, 0x4A,
  44193. 0xDF, 0x05, 0xF3, 0x5E, 0x29, 0x7E, 0xA6, 0x2E,
  44194. 0xFC, 0xDD, 0x5E, 0xF9, 0x40, 0x1B, 0xA0, 0x42,
  44195. 0xA2, 0x35, 0x15, 0x0A, 0x09, 0xD9, 0x47, 0x4A,
  44196. 0x3F, 0xB0, 0x3A, 0xAA, 0x19, 0xE7, 0xE3, 0x7A,
  44197. 0x22, 0x8D, 0x5F, 0x5B, 0x07, 0x41, 0x4C, 0x3D,
  44198. 0xA2, 0xAD, 0x2E, 0x5C, 0x75, 0xEC, 0xF0, 0x4C,
  44199. 0x11, 0x2B, 0x90, 0x76, 0x9E, 0x19, 0x96, 0x0E,
  44200. 0x97, 0x5E, 0x8D, 0x19, 0x17, 0xB3, 0xBF, 0xDA,
  44201. 0x84, 0xFD, 0xC6, 0xD2, 0x32, 0x6F, 0xB8, 0xA3,
  44202. 0xB0, 0x0F, 0x95, 0xD9, 0xC5, 0x26, 0x50, 0x11,
  44203. 0x15, 0x72, 0xBE, 0xC2, 0x1B, 0x12, 0x12, 0x7C,
  44204. 0xA5, 0x70, 0xD8, 0xA9, 0x8A, 0xB9, 0x77, 0xEB,
  44205. 0xD8, 0xD7, 0x9A, 0x59, 0x37, 0x5E, 0xE1, 0x4F,
  44206. 0x64, 0xB5, 0xB0, 0x4F, 0xD9, 0x69, 0xFE, 0xB0,
  44207. 0x3D, 0x0A, 0xF7, 0x34, 0x89, 0xE3, 0xBA, 0xEF,
  44208. 0xE7, 0xC7, 0xBC, 0x8D, 0xC7, 0xE8, 0x54, 0x83,
  44209. 0xEE, 0x62, 0xF0, 0x23, 0x98, 0x58, 0x0F, 0x83,
  44210. 0xB9, 0x6D, 0xD8, 0x44, 0x77, 0xB9, 0xC4, 0x8F,
  44211. 0x0B, 0xB3, 0x9F, 0x54, 0x06, 0xA3, 0x70, 0x36,
  44212. 0xD6, 0xF3, 0x6E, 0x2B, 0x1B, 0x6B, 0x53, 0xFE,
  44213. 0x6F, 0xF6, 0x1C, 0x32, 0x7B, 0x29, 0xD4, 0xE0,
  44214. 0x5D, 0xD2, 0xB8, 0x11, 0x74, 0xC6, 0x0B, 0x59,
  44215. 0xC7, 0x9C, 0xB1, 0x97, 0x6B, 0xC0, 0x6E, 0x7A,
  44216. 0xC3, 0x4D, 0xF3, 0xE3, 0x8F, 0x7D, 0x2C, 0x1C,
  44217. 0x0E, 0x31, 0x51, 0xB7, 0x14, 0x7A, 0xB8, 0x31,
  44218. 0x77, 0x47, 0x70, 0x14, 0x3B, 0x92, 0x7B, 0x5F,
  44219. 0xEC, 0x5D, 0xF7, 0x76, 0xC1, 0xD7, 0x2D, 0xB6,
  44220. 0xBC, 0x99, 0x81, 0xD6, 0x58, 0x67, 0x71, 0x3C,
  44221. 0xF2, 0x97, 0xC8, 0xB0, 0xF1, 0xE9, 0x8D, 0x0E,
  44222. 0x16, 0xF0, 0xCC, 0x22, 0x7A, 0x39, 0xE4, 0x7E,
  44223. 0x50, 0xBA, 0x01, 0x16, 0x15, 0x6D, 0x5B, 0x54,
  44224. 0x67, 0x53, 0x66, 0x04, 0xBE, 0x05, 0xCC, 0x2E,
  44225. 0xF4, 0x0A, 0xBC, 0xE8, 0x52, 0xF1, 0x5D, 0xFA,
  44226. 0x2C, 0xAC, 0xF8, 0x6A, 0x78, 0x9E, 0x5B, 0x7B,
  44227. 0x0E, 0x5B, 0xB4, 0xB7, 0x77, 0xCD, 0x7C, 0xC9,
  44228. 0xF6, 0x54, 0x77, 0x9B, 0x10, 0x2F, 0x78, 0xB5,
  44229. 0xAA, 0x4B, 0x94, 0xC3, 0xB4, 0xFD, 0xE5, 0x5F,
  44230. 0xA7, 0xF7, 0xBF, 0x54, 0xAC, 0x22, 0x5E, 0x1F,
  44231. 0x26, 0x16, 0x5B, 0x65, 0xF1, 0x6D, 0x03, 0x21,
  44232. 0x66, 0x9F, 0xD9, 0xF6, 0xE4, 0x7F, 0xCA, 0x1D,
  44233. 0xD3, 0x47, 0x09, 0x6D, 0xF5, 0xDD, 0xA8, 0x64,
  44234. 0x66, 0xA5, 0x7C, 0x5B, 0x06, 0x8D, 0x9C, 0x67,
  44235. 0xB7, 0x32, 0x03, 0x66, 0xEA, 0x19, 0xC8, 0x99,
  44236. 0x3F, 0xF9, 0x0B, 0xD8, 0xFB, 0x06, 0x93, 0xFB,
  44237. 0xA3, 0x70, 0xE6, 0x6D, 0x2B, 0x20, 0x3B, 0x99,
  44238. 0x70, 0x11, 0xB0, 0xD1, 0x5B, 0x94, 0xE2, 0x8B,
  44239. 0xAA, 0x2E, 0xBF, 0x01, 0x77, 0x4F, 0x7A, 0xE7,
  44240. 0x8F, 0x84, 0xED, 0xBD, 0xAD, 0x9F, 0x65, 0xA4,
  44241. 0x50, 0x42, 0x7A, 0x47, 0x74, 0xC6, 0x0C, 0xC8,
  44242. 0x9A, 0x02, 0x0B, 0x37, 0xDA, 0x21, 0xC7, 0x91,
  44243. 0xDA, 0xC8, 0xF7, 0xA7, 0x45, 0x7E, 0x30, 0xD0,
  44244. 0x8B, 0x01, 0x37, 0x51, 0x60, 0x03, 0x9C, 0x30,
  44245. 0x1B, 0x60, 0x51, 0xA9, 0x65, 0xE8, 0xA7, 0xCC,
  44246. 0xA2, 0xAE, 0xF9, 0x3B, 0xD5, 0x2F, 0x82, 0xC0,
  44247. 0x20, 0xBE, 0xCE, 0x90, 0xA1, 0x29, 0x02, 0x4E,
  44248. 0xFE, 0xA4, 0xB2, 0xFA, 0x21, 0x27, 0x0F, 0x8E,
  44249. 0xB5, 0xED, 0x6A, 0xAA, 0xE5, 0x59, 0x29, 0xAA,
  44250. 0xC5, 0x99, 0xA5, 0x77, 0x97, 0x29, 0x57, 0x66,
  44251. 0x0C, 0xC4, 0x7A, 0xC4, 0xE3, 0xCE, 0x77, 0x2B,
  44252. 0xBF, 0x10, 0x05, 0x2D, 0xE7, 0xED, 0xB1, 0xB8,
  44253. 0xA4, 0x49, 0x41, 0xF8, 0x84, 0xC9, 0xF8, 0xBE,
  44254. 0x13, 0x17, 0x46, 0x69, 0x94, 0x56, 0x29, 0xF4,
  44255. 0x6D, 0xE2, 0x46, 0x74, 0x44, 0xF3, 0x10, 0x6A,
  44256. 0x73, 0xFA, 0x27, 0x9C, 0xF0, 0x2A, 0x80, 0x0A,
  44257. 0x04, 0x7E, 0x20, 0xBD, 0x4D, 0x82, 0x0B, 0x38,
  44258. 0x9C, 0x3B, 0xB6, 0xA8, 0x68, 0xA5, 0x38, 0x4C,
  44259. 0xF5, 0x72, 0x4C, 0x20, 0x4C, 0xEF, 0xB1, 0xA6,
  44260. 0xA1, 0xBE, 0xB9, 0x72, 0x3E, 0x36, 0xDD, 0xDD,
  44261. 0xD9, 0xC7, 0x07, 0xC8, 0xF6, 0x3E, 0x8B, 0xC2,
  44262. 0x66, 0x83, 0xCC, 0x8B, 0x43, 0xC7, 0xDF, 0xDA,
  44263. 0xA4, 0x08, 0xAC, 0x4D, 0xD2, 0xBA, 0x9A, 0xEC,
  44264. 0xBC, 0x3B, 0x6D, 0xDA, 0xED, 0xCE, 0x09, 0x4A,
  44265. 0xAB, 0x58, 0xFF, 0x73, 0x2B, 0x19, 0x66, 0x38,
  44266. 0xD8, 0xB8, 0xEF, 0xC4, 0x28, 0xBB, 0xA9, 0x61,
  44267. 0x57, 0x93, 0xC4, 0xDD, 0x9F, 0x00, 0xF9, 0x0D,
  44268. 0x62, 0xC6, 0x76, 0xD1, 0x27, 0xA0, 0xE1, 0x8C,
  44269. 0x14, 0xC6, 0xEE, 0x9C, 0x99, 0x05, 0x10, 0xB0,
  44270. 0x54, 0xAD, 0xB4, 0xB4, 0x17, 0x0A, 0xC7, 0x12,
  44271. 0x7F, 0x93, 0x17, 0x5C, 0x1E, 0xB2, 0x25, 0x12
  44272. };
  44273. static const byte msg_87_draft[] = {
  44274. 0x14, 0x42, 0x63, 0x34, 0x94, 0x09, 0x60, 0x77,
  44275. 0x3B, 0xFF, 0x65, 0xF0, 0x8D, 0x1D, 0xE4, 0x89,
  44276. 0xC4, 0xC3, 0xED, 0x36
  44277. };
  44278. static const byte sig_87_draft[] = {
  44279. 0x13, 0xE8, 0x99, 0xEE, 0xDC, 0xCC, 0x0F, 0xBA,
  44280. 0x62, 0x91, 0x44, 0xE4, 0xAC, 0x06, 0x79, 0x06,
  44281. 0xB5, 0x32, 0x6B, 0x8F, 0x9A, 0x6C, 0xCB, 0xAB,
  44282. 0xE1, 0x44, 0x4A, 0xDD, 0x46, 0x45, 0x16, 0x0D,
  44283. 0x22, 0x57, 0x82, 0x87, 0x10, 0xD1, 0xEE, 0x10,
  44284. 0x60, 0x21, 0xB5, 0x64, 0x1E, 0x78, 0x81, 0x55,
  44285. 0x75, 0xD4, 0xF0, 0x95, 0xD0, 0x15, 0xD8, 0x46,
  44286. 0x5C, 0x92, 0xD2, 0xDD, 0xF4, 0xAB, 0xDF, 0xBE,
  44287. 0xB1, 0x1E, 0xE5, 0xE0, 0x70, 0xE6, 0xDA, 0x52,
  44288. 0xE5, 0x48, 0xDC, 0x04, 0xFD, 0xEF, 0x54, 0x72,
  44289. 0xE7, 0xE5, 0xF1, 0x82, 0x10, 0xAA, 0xCB, 0xA0,
  44290. 0x4F, 0x4F, 0x18, 0xAE, 0x66, 0x86, 0xB9, 0xAF,
  44291. 0x96, 0x57, 0xE3, 0x8E, 0x3B, 0x9B, 0xDD, 0xB4,
  44292. 0xAA, 0x84, 0xE6, 0x7B, 0x4D, 0x81, 0x92, 0xD0,
  44293. 0x03, 0x87, 0x3D, 0xD3, 0xEE, 0xE7, 0x47, 0x00,
  44294. 0xFB, 0xD8, 0x1E, 0x38, 0x1C, 0x21, 0x98, 0xB7,
  44295. 0xCC, 0xC1, 0x37, 0xC1, 0x71, 0xB2, 0x2F, 0x93,
  44296. 0x53, 0x41, 0x9C, 0x48, 0xC1, 0x4B, 0x8D, 0x63,
  44297. 0x0F, 0x99, 0x63, 0x40, 0x27, 0x5F, 0x6E, 0x60,
  44298. 0x4B, 0x95, 0xC4, 0x35, 0x20, 0x8A, 0xED, 0x2B,
  44299. 0xCA, 0x1B, 0x41, 0x9F, 0x83, 0x63, 0xF0, 0x95,
  44300. 0x0E, 0x24, 0x0D, 0x6F, 0x9E, 0xAB, 0x11, 0x8E,
  44301. 0x4B, 0xD3, 0xDA, 0x0E, 0xC3, 0xA2, 0xBE, 0x26,
  44302. 0xA8, 0xA0, 0x98, 0x57, 0x71, 0x3C, 0x36, 0xDD,
  44303. 0x69, 0xC3, 0x4E, 0xDD, 0x2C, 0x61, 0x9E, 0x88,
  44304. 0x26, 0x70, 0x71, 0xCF, 0x9E, 0xE5, 0xA6, 0x0C,
  44305. 0xA3, 0x14, 0x2D, 0xF1, 0x63, 0xF0, 0x1D, 0x8D,
  44306. 0x79, 0x6A, 0xC8, 0x50, 0xCF, 0xF3, 0x66, 0x60,
  44307. 0x78, 0xB3, 0x18, 0xFB, 0x5B, 0xD1, 0x73, 0x60,
  44308. 0xC8, 0x76, 0xC9, 0xC9, 0x0D, 0x8A, 0x7F, 0x41,
  44309. 0x2C, 0x8A, 0x31, 0x61, 0x6B, 0xE7, 0xA3, 0x74,
  44310. 0x58, 0x71, 0x54, 0x84, 0x86, 0x71, 0x5C, 0x94,
  44311. 0x26, 0x3A, 0x17, 0xB3, 0x6C, 0xA4, 0x99, 0x25,
  44312. 0x45, 0x0C, 0x57, 0x8A, 0xD9, 0xD4, 0xB1, 0xC2,
  44313. 0x00, 0x43, 0xF4, 0x5E, 0x84, 0x31, 0x99, 0x4F,
  44314. 0xA6, 0xD2, 0x6A, 0x14, 0x1B, 0xAD, 0x9E, 0x49,
  44315. 0x6E, 0x00, 0x9E, 0x91, 0x46, 0x16, 0xCA, 0x57,
  44316. 0x0C, 0x09, 0xF6, 0x38, 0xD0, 0x62, 0xBE, 0xC6,
  44317. 0x87, 0x33, 0x3A, 0xC7, 0x28, 0x38, 0x34, 0x53,
  44318. 0x7E, 0xFB, 0x60, 0x42, 0xF3, 0x7D, 0x83, 0xF7,
  44319. 0x29, 0x5D, 0xEA, 0x30, 0xD5, 0x00, 0x90, 0xB6,
  44320. 0x38, 0x4C, 0x17, 0x29, 0xEF, 0x17, 0xA0, 0xD5,
  44321. 0x87, 0x50, 0xC0, 0x03, 0x75, 0x14, 0xE5, 0xE1,
  44322. 0x22, 0x78, 0x53, 0xBC, 0x5A, 0xA3, 0x1E, 0x95,
  44323. 0xBE, 0xEC, 0x37, 0xB1, 0x51, 0x82, 0x69, 0x26,
  44324. 0x2E, 0xA3, 0x5A, 0xDA, 0x4F, 0xDA, 0x77, 0x62,
  44325. 0x7E, 0xED, 0xDA, 0xAF, 0x57, 0x97, 0x1B, 0xA3,
  44326. 0x6D, 0x46, 0x7B, 0x19, 0xA9, 0x0B, 0x99, 0x1C,
  44327. 0xD2, 0x55, 0xDB, 0x79, 0xB0, 0x15, 0x48, 0x86,
  44328. 0x52, 0x30, 0x31, 0xD6, 0xC5, 0xB1, 0xAE, 0x8F,
  44329. 0xCF, 0x9A, 0x43, 0x10, 0xBB, 0xC8, 0x19, 0x74,
  44330. 0x84, 0xB2, 0x92, 0x3B, 0xFE, 0x0B, 0x12, 0x15,
  44331. 0xA1, 0xC4, 0xD8, 0xC6, 0x83, 0x90, 0x89, 0x8A,
  44332. 0xD5, 0x3E, 0x33, 0x69, 0xB7, 0x05, 0x3F, 0xB1,
  44333. 0x8B, 0x0D, 0x87, 0x40, 0x70, 0x90, 0x2A, 0x5D,
  44334. 0x3B, 0x3D, 0x91, 0xD8, 0x1D, 0x4D, 0xF1, 0x08,
  44335. 0x7E, 0xF7, 0xDC, 0x05, 0x84, 0xEB, 0xDC, 0x63,
  44336. 0xD7, 0xBA, 0x3C, 0x0D, 0x31, 0xF8, 0x6D, 0xA6,
  44337. 0xC0, 0xFD, 0x08, 0x11, 0x5C, 0x53, 0xF6, 0xAE,
  44338. 0xFE, 0xC0, 0x82, 0x9A, 0x68, 0xD2, 0xA3, 0x44,
  44339. 0x2E, 0xEE, 0x47, 0x36, 0x70, 0x2D, 0x66, 0x81,
  44340. 0x0D, 0x62, 0x30, 0x8A, 0x8C, 0xC8, 0x2A, 0xA6,
  44341. 0x21, 0x82, 0xF5, 0x98, 0xF4, 0x4E, 0x25, 0x37,
  44342. 0x11, 0xB5, 0xD6, 0x07, 0x88, 0xBD, 0x0D, 0x69,
  44343. 0x0E, 0xF9, 0x8F, 0x9A, 0xD5, 0x93, 0xE0, 0x3C,
  44344. 0xEF, 0x38, 0xB9, 0xC9, 0x77, 0x98, 0x3F, 0x69,
  44345. 0x11, 0xBA, 0x1A, 0xB9, 0xF7, 0x35, 0xE9, 0x28,
  44346. 0xCD, 0xA3, 0x8C, 0x03, 0xE6, 0xAD, 0x83, 0x62,
  44347. 0xF4, 0x60, 0xAE, 0x4C, 0xD0, 0xF4, 0x6E, 0x00,
  44348. 0xEE, 0xEC, 0x74, 0xB6, 0x12, 0x34, 0x98, 0xAB,
  44349. 0x31, 0xE7, 0xA7, 0x9D, 0x33, 0x4D, 0x72, 0xA7,
  44350. 0xA7, 0xEE, 0xF3, 0xB5, 0x51, 0xE7, 0x8D, 0x31,
  44351. 0xBC, 0x2C, 0xAF, 0xFB, 0x13, 0x9C, 0xAC, 0xA4,
  44352. 0xD7, 0x9C, 0x8B, 0xBD, 0x52, 0xBD, 0x78, 0xF4,
  44353. 0x90, 0x65, 0x09, 0xBE, 0x42, 0xE7, 0x76, 0x3A,
  44354. 0xE6, 0xAC, 0xB8, 0x98, 0x28, 0x5E, 0xC9, 0x32,
  44355. 0x3E, 0x68, 0x67, 0x6A, 0x8C, 0xC7, 0x4A, 0x58,
  44356. 0xC8, 0xDA, 0x8B, 0xE9, 0x11, 0xED, 0x6F, 0x51,
  44357. 0x3B, 0x66, 0x08, 0x70, 0x73, 0x10, 0xFB, 0x45,
  44358. 0xCB, 0xD9, 0x7D, 0x5F, 0xF0, 0xD2, 0xAB, 0xA3,
  44359. 0x6F, 0xCE, 0xF7, 0x3D, 0x46, 0xCB, 0x7F, 0x01,
  44360. 0xC2, 0xCF, 0xE3, 0x8E, 0x68, 0xE8, 0x4F, 0x4A,
  44361. 0x30, 0x19, 0x16, 0xD2, 0xF5, 0x10, 0xD8, 0x2B,
  44362. 0x49, 0x69, 0xBE, 0x7A, 0x0E, 0x9C, 0xC6, 0x0E,
  44363. 0xFF, 0x5C, 0x0A, 0x87, 0x17, 0xB8, 0x22, 0x83,
  44364. 0x8C, 0x77, 0xAF, 0x42, 0x06, 0xB1, 0x25, 0x45,
  44365. 0x08, 0x9B, 0xB2, 0xDD, 0x6A, 0x3F, 0xF0, 0x12,
  44366. 0xC8, 0x64, 0x15, 0xBB, 0xA0, 0x4F, 0xD7, 0xD4,
  44367. 0xEC, 0x70, 0x7A, 0xF3, 0xB1, 0x7F, 0x25, 0x57,
  44368. 0x47, 0x66, 0xF1, 0xE9, 0x27, 0x38, 0xE0, 0x62,
  44369. 0x10, 0xF4, 0x8A, 0x5E, 0xF2, 0x55, 0x0E, 0xBD,
  44370. 0xF8, 0x5A, 0x5C, 0xA3, 0x44, 0x97, 0xCF, 0x1D,
  44371. 0x4D, 0x3A, 0x75, 0x86, 0x48, 0xEC, 0x41, 0x17,
  44372. 0x24, 0x43, 0x83, 0x5E, 0x50, 0x91, 0xBE, 0x8F,
  44373. 0x04, 0x78, 0x23, 0xD9, 0x62, 0x0C, 0x2A, 0xD5,
  44374. 0x1C, 0x96, 0x11, 0xAA, 0xEE, 0x39, 0xB2, 0x1E,
  44375. 0x6D, 0x6A, 0xEC, 0x87, 0x0C, 0x89, 0x15, 0xE2,
  44376. 0x66, 0x47, 0x6A, 0x50, 0xEE, 0xCA, 0x59, 0x96,
  44377. 0x22, 0xF7, 0x09, 0x1A, 0x34, 0xC2, 0x3F, 0x14,
  44378. 0xB4, 0x04, 0x29, 0xD9, 0x5E, 0x3E, 0xF9, 0x8F,
  44379. 0xED, 0x3E, 0x74, 0x94, 0x37, 0xF0, 0x4B, 0xB4,
  44380. 0xA3, 0x37, 0x52, 0x2E, 0x68, 0x09, 0xFC, 0x10,
  44381. 0x45, 0x03, 0xE2, 0x53, 0xB4, 0x1C, 0x4F, 0x03,
  44382. 0x01, 0xAF, 0x46, 0x7F, 0x74, 0xD3, 0x31, 0x25,
  44383. 0xFA, 0x83, 0xEF, 0x71, 0x24, 0x45, 0xA1, 0x71,
  44384. 0xFA, 0x40, 0xEB, 0xF4, 0xE6, 0x55, 0x3E, 0x45,
  44385. 0x4A, 0xFE, 0x25, 0x68, 0x02, 0x1D, 0x2B, 0x2A,
  44386. 0x19, 0x8D, 0xEC, 0x9B, 0xF7, 0x20, 0xF9, 0xD7,
  44387. 0x2F, 0x81, 0x52, 0x0B, 0xE8, 0x74, 0x66, 0xAF,
  44388. 0x70, 0xD0, 0x0E, 0x0E, 0x86, 0x0F, 0xF9, 0xAB,
  44389. 0xD0, 0x39, 0x78, 0xC3, 0xE4, 0x29, 0xB5, 0xAA,
  44390. 0x17, 0xB9, 0x7F, 0x9A, 0xE9, 0x34, 0x48, 0x85,
  44391. 0x3D, 0x6E, 0xFD, 0x16, 0x8A, 0x30, 0xC6, 0xCB,
  44392. 0xE8, 0xDE, 0x2D, 0x28, 0x8D, 0x9A, 0x24, 0xEA,
  44393. 0x5D, 0x2A, 0x58, 0x23, 0x33, 0x2B, 0x84, 0xFD,
  44394. 0x2C, 0xE7, 0x93, 0xA2, 0x2B, 0xEC, 0x43, 0x98,
  44395. 0x48, 0xD4, 0xE6, 0x0F, 0x3B, 0xB9, 0xC7, 0x5D,
  44396. 0x7E, 0xB0, 0x87, 0x1E, 0x80, 0x3D, 0x61, 0xB0,
  44397. 0x7E, 0x74, 0x9E, 0xD7, 0x60, 0x72, 0xB2, 0x7C,
  44398. 0x87, 0xB6, 0x9D, 0x6C, 0x01, 0x42, 0x61, 0xF6,
  44399. 0x47, 0xAF, 0xA8, 0x8C, 0x4F, 0x1E, 0xC5, 0x5A,
  44400. 0x75, 0xA5, 0x0F, 0xB4, 0xC7, 0x9D, 0x2C, 0x94,
  44401. 0xC0, 0x50, 0x3D, 0xB2, 0x0D, 0xFD, 0xF7, 0x1F,
  44402. 0x62, 0x88, 0x74, 0x18, 0x8C, 0xDD, 0x73, 0x85,
  44403. 0xC0, 0x33, 0x81, 0xDA, 0xBB, 0x85, 0x4D, 0x4A,
  44404. 0xA9, 0xF4, 0x7B, 0x66, 0x43, 0x8C, 0x43, 0xFF,
  44405. 0x53, 0xEF, 0x5E, 0x78, 0xAB, 0x45, 0x0B, 0x45,
  44406. 0x01, 0x91, 0x27, 0x8A, 0xF6, 0xE2, 0x6A, 0x7B,
  44407. 0x5E, 0x64, 0x61, 0xF5, 0x77, 0xF9, 0x85, 0x2F,
  44408. 0x81, 0xC9, 0x02, 0x03, 0xC7, 0x13, 0xF5, 0xB1,
  44409. 0xF6, 0xC3, 0xEF, 0x55, 0x8C, 0x90, 0x32, 0x51,
  44410. 0x6D, 0x8D, 0x62, 0xFD, 0x5E, 0x24, 0xE4, 0xF0,
  44411. 0xF5, 0x07, 0x18, 0xF5, 0x6B, 0x5A, 0x59, 0xA0,
  44412. 0x09, 0xD5, 0x93, 0x8D, 0xAD, 0x55, 0x91, 0xF6,
  44413. 0x1F, 0x4C, 0x65, 0x9A, 0x76, 0x05, 0x26, 0xEF,
  44414. 0x41, 0x20, 0x2F, 0xA7, 0xE5, 0xF6, 0xC7, 0xD5,
  44415. 0xE0, 0xB0, 0xC0, 0xC4, 0x3B, 0x52, 0x4B, 0x66,
  44416. 0x71, 0x2C, 0x5A, 0x7C, 0x53, 0xC8, 0x4C, 0x50,
  44417. 0xB8, 0x3E, 0xB9, 0xC9, 0x8D, 0x2F, 0xD0, 0x84,
  44418. 0xC9, 0xC5, 0xF2, 0x1F, 0xEE, 0x77, 0x42, 0xE6,
  44419. 0xEF, 0xC8, 0xCB, 0xBE, 0x57, 0x18, 0xB7, 0x0C,
  44420. 0x06, 0x2D, 0x82, 0xE2, 0xF9, 0x86, 0xF3, 0x8D,
  44421. 0xF1, 0xE7, 0x15, 0x89, 0xDC, 0x79, 0x87, 0x24,
  44422. 0x35, 0x62, 0xA2, 0x31, 0x9D, 0x7C, 0x00, 0xB2,
  44423. 0x6E, 0x53, 0x1E, 0x93, 0xC3, 0x84, 0x44, 0x61,
  44424. 0x8C, 0xE7, 0x58, 0x73, 0x4F, 0xDE, 0xCF, 0xD0,
  44425. 0xC6, 0x85, 0x37, 0x28, 0xC6, 0x10, 0x00, 0x78,
  44426. 0x4E, 0xDF, 0xFE, 0xD7, 0xB3, 0x30, 0x86, 0xE1,
  44427. 0x68, 0xD6, 0xCB, 0x63, 0xE3, 0xDA, 0xCA, 0xF3,
  44428. 0x55, 0x2F, 0x88, 0x5B, 0x47, 0x82, 0x62, 0xDE,
  44429. 0x5E, 0x1E, 0x63, 0xCE, 0x7A, 0x4C, 0x66, 0x95,
  44430. 0xD1, 0x19, 0x38, 0x35, 0xE4, 0x5A, 0x67, 0x91,
  44431. 0x8C, 0x42, 0xD3, 0x9B, 0xF8, 0x80, 0x38, 0x53,
  44432. 0x30, 0x31, 0x0F, 0x2C, 0x7B, 0xF9, 0x1E, 0x6C,
  44433. 0x3E, 0x29, 0xB7, 0x81, 0xD0, 0x98, 0x70, 0xC2,
  44434. 0x6D, 0x76, 0xBD, 0x8A, 0xE2, 0x09, 0xC4, 0x2B,
  44435. 0xC7, 0x43, 0x2D, 0xBB, 0x4C, 0x16, 0x52, 0x63,
  44436. 0x57, 0xA5, 0x63, 0x4E, 0xEC, 0xDE, 0x93, 0xC5,
  44437. 0x1D, 0xD4, 0xD6, 0xF0, 0x06, 0x5B, 0x2E, 0xC5,
  44438. 0x7A, 0xD3, 0xB5, 0x82, 0x66, 0x53, 0x95, 0x97,
  44439. 0xC8, 0xF4, 0x2B, 0x55, 0x27, 0x1D, 0x6F, 0x90,
  44440. 0xE9, 0x86, 0xF6, 0x82, 0x8D, 0x95, 0x9E, 0xE8,
  44441. 0x00, 0xDB, 0xEB, 0xCF, 0x48, 0x23, 0x6B, 0xA3,
  44442. 0xDE, 0x25, 0x27, 0xE0, 0xEC, 0xA4, 0xA3, 0xC2,
  44443. 0xA3, 0x4B, 0xBC, 0xDD, 0x6C, 0xBB, 0x3A, 0x9C,
  44444. 0x96, 0xDC, 0x3B, 0xE1, 0x10, 0xD3, 0x49, 0x94,
  44445. 0x66, 0xE2, 0x85, 0x7F, 0xBA, 0x98, 0x12, 0x3A,
  44446. 0x6D, 0xBA, 0x90, 0x14, 0x87, 0x7E, 0x24, 0xEA,
  44447. 0xDC, 0xCA, 0x40, 0xF8, 0xAE, 0x94, 0xB2, 0xFE,
  44448. 0xD2, 0x36, 0xCB, 0xE5, 0xBC, 0xA9, 0xDF, 0xE0,
  44449. 0xCB, 0xA9, 0xA0, 0xF8, 0x62, 0x41, 0x33, 0x18,
  44450. 0x59, 0xF9, 0xD6, 0xC0, 0x87, 0xB2, 0x76, 0xDE,
  44451. 0xC9, 0x35, 0x6F, 0x1F, 0xEF, 0x69, 0xB3, 0x59,
  44452. 0xF9, 0xFB, 0x38, 0x4A, 0x84, 0x02, 0x2D, 0xEC,
  44453. 0xB7, 0x01, 0x08, 0xDA, 0xC8, 0xE9, 0x3B, 0xB6,
  44454. 0xC3, 0x00, 0xC0, 0x34, 0x5F, 0xC6, 0x40, 0xC0,
  44455. 0x06, 0xEA, 0xEB, 0xC1, 0x51, 0x13, 0x81, 0x2F,
  44456. 0xB3, 0x7D, 0xD9, 0x6E, 0x2A, 0x06, 0xA4, 0x63,
  44457. 0xAF, 0xCE, 0x66, 0xC5, 0x9F, 0x8D, 0x71, 0x4A,
  44458. 0xA1, 0xFF, 0x49, 0x4F, 0x08, 0x6F, 0xB9, 0xEA,
  44459. 0xDA, 0x18, 0x45, 0x63, 0xCA, 0x9D, 0x88, 0x08,
  44460. 0xB1, 0x6C, 0x19, 0xA8, 0x24, 0xAD, 0x85, 0x7D,
  44461. 0xDE, 0x51, 0xE5, 0x08, 0xB7, 0x04, 0x12, 0x35,
  44462. 0xF3, 0x00, 0xED, 0x2C, 0x79, 0x9C, 0x18, 0x23,
  44463. 0x05, 0x38, 0x95, 0x76, 0xCF, 0x39, 0x3C, 0xAE,
  44464. 0xB0, 0xD3, 0xBA, 0x3E, 0x4E, 0xE4, 0xB5, 0x77,
  44465. 0xA3, 0xE3, 0x7B, 0x27, 0x5F, 0xD8, 0x05, 0x19,
  44466. 0x42, 0xAE, 0x91, 0x54, 0xE5, 0xBD, 0x7C, 0x35,
  44467. 0xE0, 0xF8, 0x95, 0x52, 0x3A, 0x29, 0xB0, 0xE6,
  44468. 0xB7, 0xAE, 0x20, 0xBE, 0x21, 0xDF, 0xF5, 0x67,
  44469. 0xEC, 0x82, 0x52, 0xFF, 0x5B, 0xD0, 0xAA, 0x14,
  44470. 0x50, 0x15, 0xE1, 0x1C, 0x6A, 0x1B, 0x94, 0x1B,
  44471. 0xCC, 0x76, 0x01, 0xBF, 0x03, 0x94, 0x42, 0xF2,
  44472. 0x00, 0x61, 0x96, 0x58, 0xD9, 0xD0, 0x40, 0x21,
  44473. 0xFA, 0xCE, 0x6B, 0xAB, 0x5D, 0x49, 0xD8, 0xD7,
  44474. 0xBC, 0x9A, 0x66, 0xC2, 0xBA, 0x3F, 0xDC, 0x49,
  44475. 0x0D, 0xA5, 0x5C, 0xB4, 0x67, 0x08, 0x38, 0xEB,
  44476. 0x2D, 0x07, 0x24, 0x5B, 0xB1, 0x22, 0x7B, 0x02,
  44477. 0x4A, 0x8A, 0x53, 0x38, 0xE9, 0x42, 0x8E, 0xA5,
  44478. 0x57, 0x41, 0xD6, 0x71, 0xA7, 0x9D, 0x6A, 0x14,
  44479. 0xD2, 0x7D, 0x13, 0xFB, 0x59, 0xD0, 0xDA, 0xE5,
  44480. 0x23, 0x9E, 0x1B, 0xC4, 0x21, 0x87, 0xBB, 0x78,
  44481. 0xE0, 0x38, 0x01, 0x1D, 0xA0, 0xD1, 0x36, 0x3F,
  44482. 0xD0, 0xA7, 0x8F, 0x86, 0x26, 0x1E, 0xB0, 0x26,
  44483. 0xDE, 0x7E, 0x17, 0x3A, 0x90, 0xFC, 0xC0, 0x17,
  44484. 0xDD, 0x78, 0xF5, 0xA3, 0x2D, 0x3E, 0x29, 0xCE,
  44485. 0x38, 0x45, 0x76, 0xA9, 0x55, 0x11, 0xB6, 0xB4,
  44486. 0xE5, 0x6E, 0xDD, 0x01, 0x4B, 0x16, 0x07, 0x99,
  44487. 0xBD, 0x19, 0x77, 0xF5, 0xD7, 0x9E, 0x39, 0x9E,
  44488. 0xAA, 0x8E, 0x2B, 0x75, 0xC5, 0xEB, 0x33, 0x56,
  44489. 0x6C, 0xD8, 0xB6, 0x3F, 0x3F, 0x4E, 0x81, 0x7E,
  44490. 0x29, 0x0A, 0x68, 0xED, 0x1E, 0x9F, 0xDC, 0x6B,
  44491. 0xFA, 0x18, 0xE3, 0xE5, 0x7D, 0x05, 0x7F, 0x22,
  44492. 0xFA, 0xA2, 0xF6, 0x0F, 0xB6, 0x34, 0x56, 0x72,
  44493. 0x55, 0x16, 0x5E, 0xF4, 0x18, 0xD1, 0x82, 0xFA,
  44494. 0xDD, 0xF7, 0xB8, 0x9F, 0x7D, 0x30, 0x10, 0x69,
  44495. 0xC4, 0x85, 0xD8, 0xE8, 0x34, 0x89, 0xD4, 0x93,
  44496. 0xBE, 0x56, 0xEE, 0xDC, 0x43, 0xD4, 0x82, 0x00,
  44497. 0xFD, 0x1E, 0x2B, 0x06, 0x69, 0x07, 0x1B, 0xBF,
  44498. 0x33, 0x61, 0x39, 0x28, 0xCA, 0x31, 0x91, 0x0B,
  44499. 0xF2, 0xEA, 0x32, 0x8E, 0xA8, 0x64, 0x13, 0x9A,
  44500. 0xEF, 0x79, 0x1A, 0x9A, 0xBE, 0x52, 0x13, 0x32,
  44501. 0x49, 0x93, 0x7D, 0xA8, 0x8C, 0x48, 0xD4, 0xC0,
  44502. 0x1D, 0x10, 0x8A, 0x46, 0x85, 0xAD, 0x29, 0xDF,
  44503. 0x2E, 0xCD, 0x41, 0x83, 0x82, 0x01, 0x28, 0x44,
  44504. 0x0E, 0xE5, 0x37, 0x8D, 0x6B, 0xCA, 0x61, 0x98,
  44505. 0xDE, 0x89, 0xA9, 0x7B, 0xBB, 0x44, 0x48, 0xA2,
  44506. 0x8D, 0x82, 0x3A, 0x57, 0x40, 0x60, 0x7C, 0x6E,
  44507. 0x69, 0x98, 0x98, 0x93, 0xFA, 0x7E, 0x29, 0x9A,
  44508. 0x74, 0x53, 0xD8, 0xDC, 0xB3, 0x4B, 0xDB, 0x7E,
  44509. 0xFE, 0x95, 0xB0, 0xC7, 0x23, 0x14, 0xEF, 0xCB,
  44510. 0x49, 0x3C, 0x09, 0xD7, 0x7B, 0xD0, 0x11, 0x9B,
  44511. 0xAC, 0xF2, 0xC2, 0x2E, 0x7C, 0xCB, 0xCD, 0x59,
  44512. 0x7F, 0x6A, 0x09, 0xFE, 0xFE, 0xDF, 0xA0, 0xA7,
  44513. 0xAC, 0x3C, 0x90, 0xBA, 0x75, 0x19, 0xF4, 0x01,
  44514. 0x60, 0x56, 0xD5, 0xFB, 0x41, 0x2B, 0xA0, 0x2D,
  44515. 0x0D, 0x45, 0xCF, 0xF3, 0xA6, 0x3D, 0x36, 0xEE,
  44516. 0xE1, 0xE4, 0x68, 0xE6, 0xEA, 0x2F, 0x67, 0x3A,
  44517. 0x7A, 0x02, 0x92, 0x6B, 0xB3, 0x18, 0xBA, 0x73,
  44518. 0xEE, 0x1B, 0x2C, 0x13, 0x7D, 0xEF, 0x4A, 0x39,
  44519. 0xE8, 0x03, 0xFF, 0x57, 0x35, 0x53, 0xE9, 0xA5,
  44520. 0xC6, 0xAA, 0x1A, 0x17, 0x21, 0xCA, 0x54, 0x38,
  44521. 0x7C, 0xB1, 0xDF, 0xB8, 0xFA, 0x7D, 0xA7, 0x26,
  44522. 0xB2, 0xAE, 0x7A, 0x05, 0x45, 0x3B, 0x40, 0x0A,
  44523. 0x19, 0xE5, 0x32, 0x52, 0x78, 0x9D, 0xC3, 0x20,
  44524. 0x63, 0x24, 0xB2, 0x58, 0x4B, 0x86, 0x1F, 0x00,
  44525. 0xA2, 0x50, 0xF9, 0x9F, 0xD9, 0xDC, 0x7D, 0x51,
  44526. 0x3D, 0xD7, 0xA6, 0x5A, 0x04, 0x03, 0x4E, 0xB3,
  44527. 0x3D, 0x2D, 0x56, 0xA4, 0x96, 0xB3, 0x6A, 0xBA,
  44528. 0x0A, 0x30, 0x08, 0xE3, 0x0F, 0xC1, 0x38, 0x24,
  44529. 0x88, 0x5D, 0x9E, 0x6F, 0x68, 0x1A, 0x7D, 0xB6,
  44530. 0x2D, 0xDD, 0xE3, 0x50, 0x1B, 0xD4, 0x07, 0x75,
  44531. 0xE2, 0xE2, 0xCC, 0x09, 0xCC, 0x8E, 0x4E, 0x67,
  44532. 0x02, 0x72, 0x02, 0xA8, 0x11, 0x70, 0xA5, 0x7F,
  44533. 0x4A, 0xC1, 0x98, 0xC1, 0x7F, 0xBF, 0x95, 0xBB,
  44534. 0xCE, 0xD3, 0x6D, 0x49, 0x30, 0xB9, 0x50, 0x8C,
  44535. 0xFA, 0x3E, 0x8B, 0xF6, 0xE5, 0x54, 0xE9, 0x1B,
  44536. 0xD7, 0xD6, 0xE5, 0x32, 0x33, 0xBB, 0x91, 0xAD,
  44537. 0xC8, 0x15, 0x76, 0x1A, 0x04, 0x35, 0xDE, 0xCC,
  44538. 0xE1, 0x67, 0x26, 0x4C, 0x2F, 0x4E, 0x34, 0x34,
  44539. 0x3D, 0x1E, 0x5A, 0xF7, 0xBC, 0xE6, 0x0C, 0x9B,
  44540. 0x7B, 0x7E, 0xE5, 0xDF, 0x72, 0x9A, 0x0D, 0xDD,
  44541. 0x4B, 0xE6, 0x6F, 0x82, 0xFB, 0x5E, 0x2C, 0xC0,
  44542. 0x7B, 0x03, 0x85, 0x76, 0x11, 0x0E, 0xFD, 0xC7,
  44543. 0xD5, 0x50, 0x26, 0xBE, 0x75, 0x5E, 0xC1, 0xF0,
  44544. 0x2E, 0x47, 0x62, 0xD6, 0xF1, 0xDA, 0xDF, 0xF4,
  44545. 0x1C, 0xEE, 0x63, 0x52, 0xC4, 0x45, 0x37, 0xE6,
  44546. 0x85, 0xA5, 0x0A, 0x07, 0x54, 0x63, 0x21, 0x7B,
  44547. 0x92, 0xF7, 0x33, 0x0C, 0xD9, 0x29, 0xCF, 0xE3,
  44548. 0xAB, 0xB5, 0xFC, 0xAA, 0x26, 0x20, 0x93, 0x55,
  44549. 0x8A, 0x07, 0x33, 0xB2, 0x7D, 0x95, 0x02, 0x7A,
  44550. 0x76, 0x9E, 0x7D, 0xBB, 0xC1, 0xF3, 0x6E, 0x84,
  44551. 0x10, 0x30, 0x4B, 0x5D, 0x59, 0x73, 0x68, 0xEC,
  44552. 0x2A, 0x63, 0x2D, 0x46, 0xE8, 0xC2, 0xF8, 0xEA,
  44553. 0x2B, 0xC4, 0x4F, 0xA7, 0x6E, 0xF4, 0x74, 0xEB,
  44554. 0x96, 0xA3, 0x64, 0x40, 0x9B, 0x23, 0x63, 0x42,
  44555. 0x4B, 0x8F, 0x85, 0x00, 0x43, 0x04, 0xAD, 0x61,
  44556. 0x76, 0x93, 0xBD, 0xC3, 0x88, 0xC3, 0xFC, 0x29,
  44557. 0x61, 0xBD, 0xB1, 0x5A, 0x1F, 0x5B, 0x20, 0xEF,
  44558. 0x95, 0xED, 0x99, 0x84, 0x96, 0xB2, 0x93, 0x81,
  44559. 0x82, 0xFF, 0xE3, 0xB9, 0x27, 0xEA, 0x9A, 0x23,
  44560. 0xF6, 0x42, 0x8D, 0xD3, 0x5C, 0x86, 0x11, 0xC8,
  44561. 0x39, 0xE3, 0x16, 0xE9, 0xA5, 0x32, 0x7C, 0xC9,
  44562. 0xEA, 0x82, 0x50, 0x9B, 0x21, 0x5C, 0xC9, 0x66,
  44563. 0xBE, 0x1C, 0x78, 0x48, 0xEF, 0x39, 0x2D, 0xA1,
  44564. 0xC6, 0xF3, 0x69, 0xA3, 0x36, 0x25, 0x3A, 0xA1,
  44565. 0x15, 0x2B, 0x6D, 0xCF, 0xDA, 0xA7, 0xCA, 0xDD,
  44566. 0x4D, 0x9A, 0x1D, 0x58, 0x9F, 0x73, 0xD3, 0xEF,
  44567. 0x0F, 0xBF, 0x03, 0x88, 0x2F, 0xDE, 0xB9, 0x44,
  44568. 0xB5, 0xB6, 0xCF, 0xE2, 0x6F, 0x6A, 0xB5, 0x12,
  44569. 0x38, 0x29, 0x55, 0x8C, 0x4C, 0x73, 0x6F, 0x0B,
  44570. 0x68, 0x7A, 0xC7, 0x06, 0x83, 0x80, 0xFE, 0x7F,
  44571. 0x61, 0xBE, 0x6B, 0x40, 0xE3, 0xF0, 0x4D, 0x7B,
  44572. 0x36, 0x82, 0x0F, 0xD8, 0x63, 0x29, 0xB3, 0x10,
  44573. 0x9D, 0x02, 0xEC, 0x63, 0x90, 0xEA, 0xFC, 0x8C,
  44574. 0xA7, 0x30, 0x56, 0x2B, 0x68, 0x08, 0x24, 0x24,
  44575. 0xFD, 0xA9, 0x8D, 0x0B, 0x64, 0xBC, 0x97, 0x34,
  44576. 0xB4, 0x0B, 0x63, 0xF7, 0xE3, 0x7A, 0xF6, 0x89,
  44577. 0x0A, 0xF7, 0xC2, 0xD9, 0x2F, 0x79, 0xEE, 0xA3,
  44578. 0xCC, 0xEA, 0xC6, 0x0A, 0x6F, 0x38, 0x06, 0x92,
  44579. 0xF8, 0x02, 0xB1, 0x55, 0x6A, 0x78, 0xFE, 0x55,
  44580. 0x83, 0xFF, 0x20, 0xA9, 0xC6, 0xA7, 0xBF, 0xCC,
  44581. 0x86, 0x3A, 0x9E, 0x7B, 0x62, 0x01, 0x4D, 0x16,
  44582. 0x05, 0xDE, 0x89, 0x4F, 0xB5, 0x85, 0xE2, 0xD4,
  44583. 0xF9, 0x41, 0x15, 0xE0, 0x29, 0xE5, 0x85, 0x7E,
  44584. 0x6A, 0x0A, 0x73, 0x89, 0x27, 0x5F, 0x53, 0x0D,
  44585. 0x3D, 0x80, 0xCF, 0xAB, 0x1F, 0x22, 0x5D, 0x38,
  44586. 0x33, 0x5D, 0x24, 0x67, 0x91, 0x97, 0xD4, 0x8A,
  44587. 0x01, 0x8A, 0x34, 0x18, 0x7D, 0xE3, 0xBC, 0xCE,
  44588. 0xDE, 0x94, 0xFF, 0x8E, 0xC5, 0x34, 0xC0, 0x2D,
  44589. 0xA7, 0x24, 0xD4, 0x59, 0x8D, 0x66, 0x9E, 0x85,
  44590. 0xA9, 0xC6, 0x0E, 0x45, 0x21, 0x4F, 0xAA, 0x65,
  44591. 0x44, 0xD6, 0xA4, 0x7D, 0x1C, 0x4E, 0xD7, 0x40,
  44592. 0x9D, 0x55, 0xB1, 0xA7, 0xF1, 0x15, 0xAE, 0x15,
  44593. 0x44, 0x3A, 0x1C, 0x31, 0x06, 0x40, 0xD1, 0x16,
  44594. 0x23, 0x84, 0x93, 0xEF, 0x3E, 0xE2, 0x87, 0x9B,
  44595. 0xB8, 0x46, 0x1F, 0x7D, 0x68, 0x73, 0x64, 0x70,
  44596. 0xD4, 0xB5, 0x73, 0xAE, 0x45, 0x49, 0x93, 0xF5,
  44597. 0x32, 0x30, 0x1E, 0x35, 0xCB, 0x9E, 0xEE, 0xDF,
  44598. 0xFE, 0xA8, 0x2F, 0xAC, 0x49, 0x77, 0x53, 0xF7,
  44599. 0x50, 0x19, 0xF2, 0xB3, 0xB0, 0x2C, 0x70, 0xB6,
  44600. 0x4A, 0x57, 0x95, 0x31, 0xC3, 0x26, 0x07, 0x2A,
  44601. 0xCF, 0x1B, 0xD0, 0xAA, 0xA0, 0x9F, 0x0A, 0x97,
  44602. 0x8B, 0x78, 0xAB, 0x22, 0xBD, 0x61, 0x19, 0xF8,
  44603. 0x8D, 0xD2, 0xD5, 0x72, 0xF8, 0x91, 0x9D, 0x47,
  44604. 0x4F, 0x59, 0x1D, 0xAE, 0x9F, 0xCE, 0x47, 0x53,
  44605. 0xC9, 0x85, 0xFB, 0x25, 0x04, 0x25, 0xF2, 0x65,
  44606. 0x61, 0xFF, 0xA9, 0x44, 0x3F, 0x23, 0x76, 0x68,
  44607. 0x9F, 0xEB, 0x48, 0xC4, 0xCE, 0x51, 0x46, 0x04,
  44608. 0x52, 0x6A, 0x10, 0x0A, 0xF3, 0x3F, 0x0D, 0x43,
  44609. 0x37, 0xD1, 0x60, 0x42, 0x22, 0xC4, 0xD9, 0xF9,
  44610. 0x3A, 0x8E, 0x69, 0xE4, 0xCC, 0xD3, 0x66, 0x69,
  44611. 0x09, 0x0C, 0x5D, 0xFB, 0x0E, 0x95, 0x49, 0x42,
  44612. 0x29, 0xFF, 0x9B, 0x20, 0xCC, 0xB1, 0xAC, 0x81,
  44613. 0xB8, 0x1A, 0x36, 0xD6, 0x3A, 0x85, 0x0D, 0xDB,
  44614. 0x33, 0x33, 0x4D, 0xAA, 0x51, 0x46, 0xBF, 0x36,
  44615. 0xFE, 0x18, 0x80, 0x1E, 0x3B, 0xEB, 0xD0, 0xE9,
  44616. 0x1B, 0x5E, 0x1C, 0xFE, 0x7A, 0x98, 0x26, 0x85,
  44617. 0x0A, 0xF4, 0x39, 0x7D, 0x1B, 0x07, 0xD3, 0xB7,
  44618. 0x19, 0xE5, 0x7B, 0xB8, 0x32, 0xAF, 0x42, 0x34,
  44619. 0xC0, 0xCD, 0x9F, 0xD4, 0x0B, 0x88, 0x2F, 0xCE,
  44620. 0xDA, 0x93, 0x7E, 0xF9, 0xA2, 0xDA, 0x24, 0x59,
  44621. 0x2B, 0xCB, 0x5D, 0x1B, 0xE8, 0x3E, 0xC5, 0xF0,
  44622. 0x3D, 0xBD, 0xFB, 0xCB, 0x33, 0x5D, 0x90, 0xD5,
  44623. 0xC8, 0xA0, 0x2E, 0xE5, 0x3D, 0x50, 0x8E, 0xB5,
  44624. 0xDE, 0x4A, 0x96, 0x1B, 0x95, 0x8F, 0x75, 0x1E,
  44625. 0x5F, 0x89, 0xA1, 0xD2, 0x88, 0x95, 0xA3, 0xDB,
  44626. 0x7B, 0x62, 0xEF, 0x4A, 0xE1, 0x6D, 0x28, 0xFB,
  44627. 0x78, 0x9B, 0x32, 0x03, 0xAD, 0x24, 0x63, 0xD6,
  44628. 0xEA, 0xB8, 0x3A, 0x6D, 0x20, 0xCE, 0xA1, 0x31,
  44629. 0x4A, 0xE0, 0x2A, 0x3F, 0xF6, 0xF6, 0x53, 0x15,
  44630. 0x4A, 0xE1, 0x44, 0x23, 0x81, 0x86, 0x21, 0x47,
  44631. 0x41, 0xC2, 0x36, 0x14, 0x81, 0x83, 0xBC, 0x39,
  44632. 0xAE, 0xDF, 0x44, 0xDA, 0x97, 0xF7, 0x31, 0xCE,
  44633. 0x3D, 0xCB, 0x61, 0xA4, 0xCF, 0xE1, 0x4F, 0x9E,
  44634. 0x84, 0xAA, 0x05, 0xAB, 0x1C, 0x1B, 0x95, 0x1D,
  44635. 0x20, 0x15, 0x52, 0x33, 0xFA, 0xFA, 0xF1, 0x6C,
  44636. 0xF1, 0xBD, 0x0B, 0xAF, 0xE1, 0x99, 0xE6, 0x5D,
  44637. 0x56, 0x34, 0x53, 0xBF, 0xE5, 0x5D, 0x5F, 0x47,
  44638. 0x4A, 0xB1, 0x05, 0x94, 0xD7, 0x38, 0xA8, 0xC1,
  44639. 0x06, 0x28, 0x8D, 0x69, 0xD0, 0x7A, 0x16, 0x88,
  44640. 0x60, 0x14, 0x63, 0xF3, 0xBD, 0x21, 0x46, 0x81,
  44641. 0x9C, 0x83, 0x72, 0x6D, 0x14, 0xC6, 0xA8, 0x08,
  44642. 0x39, 0xB8, 0x79, 0x0B, 0x57, 0x16, 0xE7, 0x72,
  44643. 0xF6, 0xC2, 0x4C, 0x2B, 0xEB, 0x7E, 0x2C, 0xF3,
  44644. 0x7B, 0x3F, 0x42, 0xAC, 0xDD, 0x47, 0x3E, 0x8C,
  44645. 0xCD, 0xBE, 0x48, 0x4D, 0x6E, 0x07, 0xB0, 0x73,
  44646. 0xDE, 0xCB, 0x17, 0x4A, 0xC3, 0xB8, 0xBB, 0x2E,
  44647. 0xF5, 0x4E, 0x6D, 0xF9, 0xE0, 0x20, 0x71, 0xFA,
  44648. 0x60, 0x0A, 0xE5, 0x59, 0x67, 0xEB, 0x6F, 0x70,
  44649. 0x2F, 0x71, 0x91, 0x59, 0xF0, 0xEB, 0x06, 0x5C,
  44650. 0xC4, 0x60, 0x48, 0xE8, 0x75, 0xE7, 0xCF, 0x42,
  44651. 0x71, 0xAD, 0x2E, 0xDA, 0xF9, 0x10, 0x82, 0x9A,
  44652. 0xF6, 0x13, 0xBA, 0x89, 0xFC, 0x61, 0x2A, 0x00,
  44653. 0xFD, 0xAE, 0x53, 0x7B, 0x09, 0x3A, 0xE8, 0xCB,
  44654. 0xE6, 0xB7, 0x0D, 0x03, 0x01, 0xFA, 0x2E, 0x13,
  44655. 0xA9, 0x16, 0x38, 0x1C, 0x92, 0xEC, 0xB4, 0x51,
  44656. 0xA3, 0x6E, 0x3F, 0xA8, 0xB7, 0x37, 0x36, 0x20,
  44657. 0xC0, 0x71, 0xA3, 0x05, 0x34, 0xED, 0xCB, 0x4A,
  44658. 0x3F, 0x11, 0x31, 0x17, 0xA5, 0x02, 0xD6, 0xA7,
  44659. 0x2D, 0xE6, 0xC7, 0x7B, 0xBB, 0xF6, 0xAE, 0x99,
  44660. 0x85, 0x9A, 0xAC, 0xE6, 0x4A, 0x92, 0x8C, 0x37,
  44661. 0x4B, 0xD2, 0xC4, 0x65, 0x2A, 0xC9, 0x7E, 0xB7,
  44662. 0x44, 0xD2, 0x9A, 0x70, 0xCE, 0xA9, 0xA1, 0x9D,
  44663. 0x70, 0x13, 0x49, 0x7B, 0xCA, 0xB6, 0x96, 0x31,
  44664. 0x43, 0x3F, 0x9E, 0xD1, 0xFE, 0x20, 0xF8, 0x0B,
  44665. 0x59, 0x83, 0xE1, 0x28, 0x8B, 0xB6, 0xA2, 0xBE,
  44666. 0x91, 0x54, 0x3E, 0xD4, 0x79, 0x28, 0xBB, 0x5E,
  44667. 0x46, 0x2D, 0x01, 0xE9, 0xC0, 0xB7, 0xFF, 0xFA,
  44668. 0xC0, 0x6C, 0x10, 0xF1, 0x52, 0xF4, 0x3C, 0x32,
  44669. 0x9E, 0x89, 0xDF, 0x8A, 0x79, 0x99, 0x6A, 0x09,
  44670. 0x79, 0x8A, 0x36, 0x76, 0x40, 0xBE, 0x9F, 0xB5,
  44671. 0x3D, 0xCE, 0x27, 0xBD, 0x0B, 0xAA, 0x9B, 0xF0,
  44672. 0x21, 0xBF, 0x10, 0xD2, 0xFC, 0xFE, 0x5B, 0x13,
  44673. 0xFD, 0x7D, 0x84, 0xD1, 0xC1, 0xEB, 0xC0, 0xBC,
  44674. 0xEC, 0x26, 0xD0, 0x87, 0x80, 0xD1, 0x3B, 0x99,
  44675. 0x47, 0x67, 0x26, 0x61, 0xE0, 0xFA, 0x5F, 0xAE,
  44676. 0x6F, 0x31, 0x5B, 0x6D, 0xE4, 0x01, 0x68, 0xC2,
  44677. 0x35, 0x1D, 0xE3, 0x1F, 0x41, 0xFF, 0x6C, 0x53,
  44678. 0x32, 0x26, 0xE1, 0xBC, 0xE3, 0xF8, 0xE2, 0x16,
  44679. 0xAF, 0x3B, 0xE6, 0x4C, 0x69, 0x33, 0x72, 0xA0,
  44680. 0x66, 0xB1, 0x75, 0xF7, 0x26, 0xCF, 0xCD, 0x64,
  44681. 0x2B, 0xAE, 0x98, 0x02, 0x92, 0xC1, 0xCB, 0x65,
  44682. 0xE0, 0x1F, 0x07, 0x29, 0x64, 0x0A, 0xB0, 0x09,
  44683. 0xCB, 0x98, 0x89, 0x2D, 0x6C, 0xFE, 0x40, 0x03,
  44684. 0x34, 0x55, 0xDE, 0xE7, 0x30, 0x33, 0xB6, 0xD5,
  44685. 0xE1, 0x9C, 0x59, 0x9F, 0x8A, 0x40, 0x0E, 0xB1,
  44686. 0x41, 0x52, 0x7D, 0xF2, 0xBB, 0xDD, 0xEF, 0x50,
  44687. 0xBB, 0xD5, 0xFB, 0x55, 0xAA, 0x5E, 0xFD, 0xB3,
  44688. 0x5D, 0x08, 0x56, 0x9B, 0x02, 0x97, 0xE2, 0x48,
  44689. 0x14, 0x69, 0xF1, 0x7B, 0x87, 0xB5, 0x08, 0x93,
  44690. 0x6A, 0x9C, 0x5C, 0x11, 0x08, 0x9A, 0xE9, 0xE4,
  44691. 0xB0, 0xCA, 0xC5, 0x74, 0x93, 0x93, 0xC8, 0x03,
  44692. 0xE4, 0x70, 0x39, 0xF5, 0x1B, 0x5C, 0xBD, 0x42,
  44693. 0xA6, 0xC9, 0xE1, 0x9E, 0xC3, 0xF6, 0x3C, 0x23,
  44694. 0x32, 0xE8, 0x77, 0x68, 0xA9, 0x60, 0xFA, 0x02,
  44695. 0x18, 0x6B, 0x7A, 0x2B, 0x02, 0x92, 0x65, 0x09,
  44696. 0x11, 0x46, 0x73, 0x04, 0x63, 0xDF, 0x8B, 0x37,
  44697. 0x5F, 0x24, 0xAA, 0x83, 0xBD, 0xD4, 0x1D, 0x13,
  44698. 0x04, 0xFC, 0x2F, 0xB5, 0x2D, 0xA1, 0x0F, 0x1F,
  44699. 0xED, 0x65, 0x29, 0x08, 0xCF, 0x8C, 0x52, 0x8F,
  44700. 0xB2, 0x62, 0x5F, 0x39, 0x3F, 0xC8, 0xC7, 0xB3,
  44701. 0x3F, 0xAD, 0x45, 0xBA, 0xD4, 0x7D, 0x38, 0x3D,
  44702. 0x2C, 0x04, 0xCF, 0x32, 0xE8, 0x07, 0x42, 0x5F,
  44703. 0x93, 0xD2, 0x35, 0x07, 0x21, 0xB7, 0xB2, 0xF5,
  44704. 0x96, 0x64, 0x8E, 0xB5, 0xE1, 0x38, 0x6B, 0x43,
  44705. 0xD1, 0x2E, 0xFD, 0xDB, 0x8F, 0xE2, 0x43, 0x6A,
  44706. 0xEC, 0x27, 0x8E, 0xE7, 0x68, 0x75, 0xB5, 0x23,
  44707. 0xC5, 0x43, 0x1D, 0x99, 0x48, 0x57, 0x73, 0xD9,
  44708. 0xAD, 0xBC, 0xD0, 0x14, 0xDD, 0x87, 0xBC, 0x68,
  44709. 0xFB, 0x82, 0xEE, 0x47, 0x4B, 0x22, 0xA5, 0x43,
  44710. 0x3A, 0xF9, 0xF9, 0x91, 0xFC, 0x34, 0xB2, 0x58,
  44711. 0x34, 0xDF, 0x13, 0x09, 0x9A, 0x46, 0xF5, 0x68,
  44712. 0xAF, 0xD1, 0x15, 0x5F, 0x32, 0x1B, 0x9D, 0xA9,
  44713. 0xE9, 0xC0, 0x63, 0x47, 0xAB, 0x3C, 0x1F, 0x59,
  44714. 0xF7, 0xEA, 0x0E, 0xD6, 0xCF, 0x47, 0xB3, 0xE9,
  44715. 0xAF, 0x65, 0x7A, 0xA7, 0xAE, 0x9B, 0xF8, 0x26,
  44716. 0x0B, 0x96, 0x9D, 0xE4, 0xAD, 0x24, 0xD3, 0xA8,
  44717. 0xCE, 0x95, 0xE5, 0x77, 0xD0, 0x44, 0x13, 0x05,
  44718. 0x06, 0x4E, 0x07, 0xB9, 0xA2, 0xC7, 0x5C, 0x3C,
  44719. 0x43, 0x80, 0x1F, 0xCE, 0xB7, 0x36, 0xFE, 0x3D,
  44720. 0x27, 0x1B, 0xE1, 0xF3, 0x6B, 0xFF, 0xC8, 0xE4,
  44721. 0x3D, 0xB1, 0x4A, 0x16, 0x24, 0x76, 0xBA, 0xEA,
  44722. 0x9D, 0x34, 0x6B, 0x52, 0x11, 0xAB, 0xD0, 0x06,
  44723. 0x08, 0xB1, 0x5A, 0xF3, 0xB5, 0xE6, 0x3A, 0x00,
  44724. 0xFF, 0x92, 0x8D, 0x1E, 0xA1, 0xA1, 0x8D, 0x75,
  44725. 0xFA, 0x7C, 0x6C, 0x1B, 0x0F, 0xB6, 0x27, 0x2E,
  44726. 0x55, 0xC3, 0xFE, 0x7E, 0x4D, 0x42, 0x05, 0xE5,
  44727. 0xCF, 0x0A, 0x1F, 0x87, 0x18, 0x30, 0x4E, 0x14,
  44728. 0xF2, 0xB4, 0xCC, 0x54, 0x3D, 0x04, 0x37, 0x34,
  44729. 0x1A, 0x4A, 0x31, 0x16, 0x01, 0xA9, 0x2E, 0x92,
  44730. 0x56, 0x6B, 0x7D, 0xFB, 0x42, 0x64, 0xE8, 0x70,
  44731. 0xE1, 0xB3, 0xA8, 0x75, 0xED, 0xBC, 0x00, 0x3A,
  44732. 0x56, 0x19, 0x70, 0xCF, 0x8A, 0x66, 0x9F, 0x3D,
  44733. 0x1B, 0x69, 0x28, 0x8C, 0xC6, 0xE3, 0x59, 0xCE,
  44734. 0x28, 0xCA, 0x65, 0xF9, 0xDA, 0xE8, 0xCE, 0xCA,
  44735. 0x74, 0x3C, 0x1C, 0x8D, 0x9F, 0xFB, 0x55, 0x08,
  44736. 0x82, 0x4A, 0x83, 0x61, 0xE3, 0x3B, 0x43, 0x1A,
  44737. 0x2E, 0x9E, 0x9A, 0x99, 0x78, 0x47, 0xD2, 0xE6,
  44738. 0xE4, 0x3C, 0x83, 0xF0, 0x22, 0x62, 0xE2, 0x94,
  44739. 0x6D, 0xF7, 0x72, 0x6D, 0x54, 0xE3, 0xE6, 0xC9,
  44740. 0xCC, 0xDB, 0x6D, 0x3F, 0x13, 0x63, 0x46, 0xC1,
  44741. 0x1E, 0x59, 0x42, 0xE7, 0xA1, 0xBF, 0x85, 0x0C,
  44742. 0x2E, 0x99, 0xB4, 0xFA, 0xCE, 0x75, 0xFD, 0x40,
  44743. 0x88, 0x69, 0x33, 0x90, 0x7C, 0xCD, 0xFC, 0x0D,
  44744. 0xE1, 0x17, 0x70, 0x20, 0x31, 0x94, 0x1D, 0x00,
  44745. 0x1E, 0x2A, 0x68, 0x3C, 0x55, 0x78, 0xFD, 0x33,
  44746. 0x54, 0x21, 0x2C, 0xEA, 0xD9, 0x69, 0xBF, 0x1C,
  44747. 0x81, 0x23, 0x9E, 0xEC, 0xC7, 0x74, 0xFD, 0x0B,
  44748. 0x88, 0x3D, 0x0E, 0xEE, 0x82, 0x4B, 0x10, 0xB8,
  44749. 0x79, 0xCF, 0x70, 0x7C, 0xB2, 0x68, 0x47, 0x45,
  44750. 0x22, 0x06, 0x1E, 0x92, 0x7B, 0x12, 0x43, 0x24,
  44751. 0x41, 0x15, 0xC6, 0x69, 0xE9, 0xEB, 0x27, 0x2B,
  44752. 0x60, 0xA6, 0x44, 0xF5, 0x19, 0xEF, 0xEC, 0x06,
  44753. 0x34, 0x08, 0xB6, 0x58, 0x47, 0x2E, 0x91, 0x61,
  44754. 0xA1, 0xF7, 0x44, 0xFD, 0x66, 0x16, 0x9F, 0x0C,
  44755. 0xAE, 0x36, 0xB4, 0x2E, 0x23, 0x79, 0xCB, 0xE8,
  44756. 0x1E, 0x6E, 0x51, 0xA0, 0xF5, 0x34, 0x15, 0x18,
  44757. 0x4E, 0xA0, 0x06, 0xB2, 0x27, 0x0B, 0x33, 0xE2,
  44758. 0xCA, 0x36, 0x4C, 0xDB, 0x33, 0xAA, 0xAE, 0x77,
  44759. 0xFF, 0xD9, 0x53, 0xDB, 0x39, 0x70, 0x4D, 0x49,
  44760. 0x0C, 0xE9, 0xAC, 0x6F, 0x2D, 0xD1, 0xC7, 0xA1,
  44761. 0x8E, 0x61, 0x74, 0x19, 0xA9, 0xAA, 0xFB, 0x37,
  44762. 0xE7, 0x23, 0x9B, 0x23, 0x6A, 0x4B, 0x74, 0xCE,
  44763. 0x63, 0xE4, 0xA0, 0xAD, 0xFF, 0x85, 0x5D, 0xCD,
  44764. 0x78, 0xF6, 0x45, 0x8E, 0x76, 0x0B, 0xFD, 0x1D,
  44765. 0x2A, 0xB9, 0x5E, 0x83, 0xC0, 0x3B, 0x6F, 0xAE,
  44766. 0x0C, 0xD3, 0xC5, 0xCE, 0xEE, 0xEE, 0x1C, 0x69,
  44767. 0x51, 0x59, 0x65, 0xA3, 0x35, 0xFC, 0xF7, 0x8E,
  44768. 0x80, 0xAA, 0x73, 0x93, 0x39, 0x54, 0x21, 0x27,
  44769. 0x17, 0x0B, 0x2C, 0x3E, 0xE1, 0x0B, 0x0E, 0xAA,
  44770. 0x09, 0x9A, 0xC7, 0xAD, 0x4C, 0xD7, 0x6E, 0x7F,
  44771. 0xE4, 0xC1, 0x16, 0x4E, 0x62, 0xF4, 0xE5, 0x80,
  44772. 0x7D, 0xC0, 0x06, 0x1F, 0x77, 0xE4, 0xA8, 0xA5,
  44773. 0x28, 0xD7, 0x10, 0x37, 0x59, 0x30, 0xCB, 0x75,
  44774. 0x5B, 0x28, 0xBF, 0xFD, 0x92, 0x8C, 0xB0, 0x7B,
  44775. 0xB4, 0xA1, 0x07, 0xCD, 0xCA, 0xBB, 0x30, 0x8A,
  44776. 0x48, 0x65, 0x0D, 0xA4, 0xE5, 0x74, 0xD9, 0xBF,
  44777. 0x56, 0x07, 0xF5, 0x83, 0xDA, 0xC3, 0x40, 0xD7,
  44778. 0x20, 0x93, 0xEF, 0xB1, 0x2B, 0xBF, 0x93, 0x41,
  44779. 0x0F, 0x1E, 0xF5, 0xC9, 0x51, 0x6C, 0x74, 0x4D,
  44780. 0x23, 0x15, 0xEC, 0x9E, 0x00, 0x0A, 0x8D, 0xC5,
  44781. 0xD1, 0x7A, 0x7B, 0x6F, 0x0D, 0x07, 0x9D, 0x78,
  44782. 0x4B, 0x6D, 0x90, 0x19, 0x3F, 0x6E, 0x3E, 0xE7,
  44783. 0xEA, 0x0E, 0xAB, 0xFC, 0x6F, 0x68, 0xC5, 0x2B,
  44784. 0x37, 0xCB, 0xCE, 0x82, 0x18, 0xAF, 0xA3, 0x67,
  44785. 0x0A, 0x80, 0xBC, 0x17, 0xB9, 0x5D, 0x7B, 0x40,
  44786. 0x53, 0x62, 0x26, 0x35, 0x8F, 0x04, 0xAC, 0xD9,
  44787. 0x2A, 0x1B, 0xE1, 0x5B, 0x26, 0xA4, 0xE5, 0x81,
  44788. 0x7E, 0x62, 0x8B, 0xA6, 0x79, 0xB3, 0x52, 0x72,
  44789. 0x03, 0xCD, 0x36, 0x32, 0x62, 0x8E, 0xC8, 0x3A,
  44790. 0xA4, 0xF2, 0x18, 0x6D, 0x2F, 0x00, 0x5D, 0x5D,
  44791. 0xFE, 0x6F, 0x7F, 0xDB, 0x4F, 0xED, 0xAC, 0x9E,
  44792. 0x89, 0xD6, 0x66, 0xE3, 0x03, 0xBB, 0x56, 0x83,
  44793. 0x06, 0x15, 0x6C, 0x56, 0xF0, 0x95, 0x34, 0xE2,
  44794. 0x5C, 0x61, 0x9A, 0xB3, 0xB9, 0x50, 0x18, 0xF4,
  44795. 0x89, 0x6B, 0xAC, 0xAA, 0x48, 0x34, 0xF6, 0xD2,
  44796. 0xD8, 0xFE, 0x14, 0xA9, 0x38, 0xAA, 0x10, 0xE5,
  44797. 0x30, 0x54, 0xF0, 0x00, 0x84, 0x44, 0xAC, 0x2E,
  44798. 0xEA, 0x25, 0x38, 0xC1, 0x23, 0x0E, 0x6A, 0x18,
  44799. 0xC9, 0x2B, 0x01, 0xD9, 0x14, 0x7F, 0xDC, 0xEF,
  44800. 0xC9, 0xC8, 0xDA, 0xC1, 0xD4, 0xEC, 0xC8, 0xCF,
  44801. 0x1F, 0x96, 0x2E, 0xFA, 0x1B, 0x8C, 0xD3, 0xC9,
  44802. 0x69, 0x00, 0x0B, 0x7E, 0xBA, 0xC5, 0x98, 0xDC,
  44803. 0xA4, 0x5E, 0xB4, 0x0B, 0xCF, 0xB1, 0x98, 0x51,
  44804. 0x48, 0x38, 0x51, 0xCF, 0x34, 0x0F, 0x3E, 0x8C,
  44805. 0x23, 0x7A, 0x9E, 0xFF, 0x1C, 0x9F, 0x21, 0xE4,
  44806. 0x97, 0x55, 0x41, 0xC6, 0x1A, 0x8F, 0xEF, 0x2A,
  44807. 0xC6, 0x05, 0x7F, 0x59, 0xDC, 0xB2, 0x3A, 0x80,
  44808. 0xE8, 0x06, 0x10, 0xCD, 0x85, 0xDB, 0x20, 0x3C,
  44809. 0x35, 0xD2, 0x4B, 0xC8, 0x2B, 0x9C, 0xD7, 0x82,
  44810. 0x46, 0xF5, 0x9F, 0xEB, 0xB2, 0x48, 0x32, 0xD7,
  44811. 0xCD, 0x66, 0x4C, 0x99, 0x51, 0x88, 0xE0, 0x28,
  44812. 0x1C, 0xD7, 0x86, 0x79, 0x00, 0xDC, 0x0D, 0xF4,
  44813. 0x4D, 0x40, 0x90, 0x80, 0x26, 0x8B, 0x79, 0xE9,
  44814. 0x56, 0x82, 0x88, 0x5F, 0x22, 0x87, 0x70, 0x73,
  44815. 0x4F, 0xA5, 0x35, 0x18, 0xEC, 0x80, 0xCE, 0x23,
  44816. 0x06, 0xCE, 0x14, 0x48, 0x52, 0x4E, 0xF0, 0x18,
  44817. 0x43, 0x03, 0xD4, 0x50, 0xC7, 0x6E, 0xA6, 0x3B,
  44818. 0x73, 0x3E, 0xB0, 0xC8, 0xDC, 0x48, 0xBF, 0x12,
  44819. 0x42, 0x3A, 0xD2, 0x38, 0x89, 0xCF, 0xCD, 0xD8,
  44820. 0x91, 0xE5, 0x95, 0x00, 0x47, 0x24, 0x0D, 0xC0,
  44821. 0xC3, 0x8A, 0xB2, 0xDB, 0xC1, 0x65, 0xB8, 0x1E,
  44822. 0x63, 0x10, 0x02, 0xEA, 0x6F, 0x74, 0x11, 0x9E,
  44823. 0x27, 0xF9, 0xF8, 0x60, 0x73, 0xBF, 0x2D, 0xF7,
  44824. 0x10, 0x81, 0x86, 0x76, 0x98, 0x0C, 0x4C, 0xB6,
  44825. 0xBD, 0x53, 0xF9, 0xA5, 0x72, 0x17, 0x78, 0xB8,
  44826. 0x9F, 0x59, 0xC6, 0x8C, 0x89, 0x35, 0xF5, 0x03,
  44827. 0x1C, 0x8A, 0x93, 0x36, 0x7D, 0x71, 0x70, 0x57,
  44828. 0xFD, 0x4D, 0x5E, 0xFA, 0xBE, 0xDE, 0x70, 0x2C,
  44829. 0xC6, 0x45, 0xEF, 0xB6, 0xD7, 0xF4, 0x4C, 0x86,
  44830. 0x0F, 0xFF, 0x76, 0x37, 0xAA, 0xD9, 0x72, 0x24,
  44831. 0x8C, 0x84, 0x4D, 0x15, 0x13, 0x39, 0x20, 0x07,
  44832. 0x38, 0x91, 0xC3, 0x13, 0x5D, 0x29, 0x78, 0x68,
  44833. 0xB7, 0xDA, 0x86, 0xF0, 0x97, 0xD8, 0xFB, 0x39,
  44834. 0xC1, 0x3B, 0xA1, 0x4C, 0x4F, 0x24, 0x75, 0x16,
  44835. 0xAB, 0xA4, 0xC5, 0xF8, 0xCE, 0x38, 0x18, 0x48,
  44836. 0x2C, 0x8F, 0xF6, 0x0C, 0xCA, 0x51, 0xFD, 0xB2,
  44837. 0xCE, 0xE9, 0x6B, 0xC1, 0x13, 0x8D, 0xC0, 0x4A,
  44838. 0x86, 0xF8, 0x57, 0x72, 0x75, 0x91, 0xAA, 0xE6,
  44839. 0xF8, 0x7C, 0x30, 0x05, 0x9B, 0x3E, 0x81, 0xB6,
  44840. 0x80, 0x55, 0xB2, 0x4E, 0xA2, 0xFA, 0x98, 0x36,
  44841. 0x86, 0x49, 0x8B, 0xFC, 0x9D, 0x9E, 0x7D, 0x59,
  44842. 0x50, 0x79, 0xEB, 0x64, 0x6E, 0x85, 0xB2, 0x12,
  44843. 0xCE, 0xDD, 0x21, 0xD0, 0x08, 0x7E, 0x0F, 0x2A,
  44844. 0xF6, 0x63, 0xEB, 0x77, 0x2A, 0x98, 0x47, 0xB1,
  44845. 0xDF, 0x21, 0x97, 0xAF, 0x13, 0x62, 0x6B, 0x89,
  44846. 0x7C, 0x24, 0x63, 0x7A, 0xF5, 0xBF, 0xE8, 0x18,
  44847. 0x16, 0xA8, 0xC9, 0x0D, 0x30, 0x48, 0x37, 0x5B,
  44848. 0x69, 0x94, 0x97, 0x14, 0x3E, 0x57, 0x71, 0x85,
  44849. 0xA7, 0x0E, 0x11, 0x50, 0x58, 0xA3, 0xA9, 0x11,
  44850. 0x2B, 0x2C, 0x43, 0x51, 0xB6, 0xCA, 0xD0, 0x09,
  44851. 0x28, 0x2B, 0x4F, 0x7C, 0xB8, 0xBD, 0xFC, 0x28,
  44852. 0x57, 0x77, 0xD7, 0xDF, 0xE8, 0xF5, 0x00, 0x00,
  44853. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  44854. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  44855. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  44856. 0x00, 0x00, 0x00, 0x03, 0x06, 0x0B, 0x11, 0x17,
  44857. 0x1F, 0x27, 0x2E
  44858. };
  44859. #endif
  44860. #endif
  44861. key = (dilithium_key*)XMALLOC(sizeof(*key), NULL, DYNAMIC_TYPE_TMP_BUFFER);
  44862. ExpectNotNull(key);
  44863. if (key != NULL) {
  44864. XMEMSET(key, 0, sizeof(*key));
  44865. }
  44866. ExpectIntEQ(wc_dilithium_init_ex(key, NULL, INVALID_DEVID), 0);
  44867. #ifndef WOLFSSL_NO_ML_DSA_44
  44868. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44), 0);
  44869. ExpectIntEQ(wc_dilithium_import_public(pk_44, (word32)sizeof(pk_44), key),
  44870. 0);
  44871. ExpectIntEQ(wc_dilithium_verify_msg(sig_44, (word32)sizeof(sig_44), msg_44,
  44872. (word32)sizeof(msg_44), &res, key), 0);
  44873. ExpectIntEQ(res, 1);
  44874. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  44875. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_44_DRAFT), 0);
  44876. ExpectIntEQ(wc_dilithium_import_public(pk_44_draft,
  44877. (word32)sizeof(pk_44_draft), key), 0);
  44878. ExpectIntEQ(wc_dilithium_verify_msg(sig_44_draft,
  44879. (word32)sizeof(sig_44_draft), msg_44_draft,
  44880. (word32)sizeof(msg_44_draft), &res, key), 0);
  44881. ExpectIntEQ(res, 1);
  44882. #endif
  44883. #endif
  44884. #ifndef WOLFSSL_NO_ML_DSA_65
  44885. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65), 0);
  44886. ExpectIntEQ(wc_dilithium_import_public(pk_65, (word32)sizeof(pk_65), key),
  44887. 0);
  44888. ExpectIntEQ(wc_dilithium_verify_msg(sig_65, (word32)sizeof(sig_65), msg_65,
  44889. (word32)sizeof(msg_65), &res, key), 0);
  44890. ExpectIntEQ(res, 1);
  44891. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  44892. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_65_DRAFT), 0);
  44893. ExpectIntEQ(wc_dilithium_import_public(pk_65_draft,
  44894. (word32)sizeof(pk_65_draft), key), 0);
  44895. ExpectIntEQ(wc_dilithium_verify_msg(sig_65_draft,
  44896. (word32)sizeof(sig_65_draft), msg_65_draft,
  44897. (word32)sizeof(msg_65_draft), &res, key), 0);
  44898. ExpectIntEQ(res, 1);
  44899. #endif
  44900. #endif
  44901. #ifndef WOLFSSL_NO_ML_DSA_87
  44902. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87), 0);
  44903. ExpectIntEQ(wc_dilithium_import_public(pk_87, (word32)sizeof(pk_87), key),
  44904. 0);
  44905. ExpectIntEQ(wc_dilithium_verify_msg(sig_87, (word32)sizeof(sig_87), msg_87,
  44906. (word32)sizeof(msg_87), &res, key), 0);
  44907. ExpectIntEQ(res, 1);
  44908. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  44909. ExpectIntEQ(wc_dilithium_set_level(key, WC_ML_DSA_87_DRAFT), 0);
  44910. ExpectIntEQ(wc_dilithium_import_public(pk_87_draft,
  44911. (word32)sizeof(pk_87_draft), key), 0);
  44912. ExpectIntEQ(wc_dilithium_verify_msg(sig_87_draft,
  44913. (word32)sizeof(sig_87_draft), msg_87_draft,
  44914. (word32)sizeof(msg_87_draft), &res, key), 0);
  44915. ExpectIntEQ(res, 1);
  44916. #endif
  44917. #endif
  44918. wc_dilithium_free(key);
  44919. XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  44920. #endif
  44921. return EXPECT_RESULT();
  44922. }
  44923. /*
  44924. * Testing wc_SetSubjectBuffer
  44925. */
  44926. static int test_wc_SetSubjectBuffer(void)
  44927. {
  44928. EXPECT_DECLS;
  44929. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  44930. Cert cert;
  44931. XFILE file = XBADFILE;
  44932. byte* der = NULL;
  44933. word32 derSz;
  44934. derSz = FOURK_BUF;
  44935. ExpectNotNull(der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  44936. DYNAMIC_TYPE_TMP_BUFFER));
  44937. ExpectTrue((file = XFOPEN("./certs/ca-cert.der", "rb")) != XBADFILE);
  44938. ExpectTrue((derSz = (word32)XFREAD(der, 1, FOURK_BUF, file)) > 0);
  44939. if (file != XBADFILE)
  44940. XFCLOSE(file);
  44941. ExpectIntEQ(wc_InitCert(&cert), 0);
  44942. ExpectIntEQ(wc_SetSubjectBuffer(&cert, der, (int)derSz), 0);
  44943. ExpectIntEQ(wc_SetSubjectBuffer(NULL, der, (int)derSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  44944. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44945. #endif
  44946. return EXPECT_RESULT();
  44947. } /* End test_wc_SetSubjectBuffer*/
  44948. /*
  44949. * Testing wc_SetSubjectKeyIdFromPublicKey_ex
  44950. */
  44951. static int test_wc_SetSubjectKeyIdFromPublicKey_ex(void)
  44952. {
  44953. EXPECT_DECLS;
  44954. #if defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)
  44955. WC_RNG rng;
  44956. Cert cert;
  44957. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  44958. RsaKey rsaKey;
  44959. int bits = 2048;
  44960. #endif
  44961. #if defined(HAVE_ECC)
  44962. ecc_key eccKey;
  44963. int ret;
  44964. #endif
  44965. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  44966. ed25519_key ed25519Key;
  44967. #endif
  44968. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  44969. ed448_key ed448Key;
  44970. #endif
  44971. #ifndef HAVE_FIPS
  44972. ExpectIntEQ(wc_InitRng_ex(&rng, HEAP_HINT, testDevId), 0);
  44973. #else
  44974. ExpectIntEQ(wc_InitRng(&rng), 0);
  44975. #endif
  44976. ExpectIntEQ(wc_InitCert(&cert), 0);
  44977. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  44978. /* RSA */
  44979. XMEMSET(&rsaKey, 0, sizeof(RsaKey));
  44980. ExpectIntEQ(wc_InitRsaKey(&rsaKey, HEAP_HINT), 0);
  44981. ExpectIntEQ(MAKE_RSA_KEY(&rsaKey, bits, WC_RSA_EXPONENT, &rng), 0);
  44982. ExpectIntEQ(wc_SetSubjectKeyIdFromPublicKey_ex(&cert, RSA_TYPE, &rsaKey),
  44983. 0);
  44984. DoExpectIntEQ(wc_FreeRsaKey(&rsaKey), 0);
  44985. #endif
  44986. #if defined(HAVE_ECC)
  44987. /* ECC */
  44988. XMEMSET(&eccKey, 0, sizeof(ecc_key));
  44989. ExpectIntEQ(wc_ecc_init(&eccKey), 0);
  44990. ret = wc_ecc_make_key(&rng, KEY14, &eccKey);
  44991. #if defined(WOLFSSL_ASYNC_CRYPT)
  44992. ret = wc_AsyncWait(ret, &eccKey.asyncDev, WC_ASYNC_FLAG_NONE);
  44993. #endif
  44994. ExpectIntEQ(ret, 0);
  44995. ExpectIntEQ(wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ECC_TYPE, &eccKey),
  44996. 0);
  44997. DoExpectIntEQ(wc_ecc_free(&eccKey), 0);
  44998. #endif
  44999. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  45000. /* ED25519 */
  45001. XMEMSET(&ed25519Key, 0, sizeof(ed25519_key));
  45002. ExpectIntEQ(wc_ed25519_init(&ed25519Key), 0);
  45003. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &ed25519Key), 0);
  45004. ExpectIntEQ(wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ED25519_TYPE,
  45005. &ed25519Key), 0);
  45006. wc_ed25519_free(&ed25519Key);
  45007. #endif
  45008. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  45009. /* ED448 */
  45010. XMEMSET(&ed448Key, 0, sizeof(ed448_key));
  45011. ExpectIntEQ(wc_ed448_init(&ed448Key), 0);
  45012. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &ed448Key), 0);
  45013. ExpectIntEQ(wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ED448_TYPE,
  45014. &ed448Key), 0);
  45015. wc_ed448_free(&ed448Key);
  45016. #endif
  45017. wc_FreeRng(&rng);
  45018. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  45019. #endif /* WOLFSSL_CERT_EXT && WOLFSSL_CERT_GEN */
  45020. return EXPECT_RESULT();
  45021. } /* End test_wc_SetSubjectKeyIdFromPublicKey_ex*/
  45022. /*
  45023. * Testing wc_SetAuthKeyIdFromPublicKey_ex
  45024. */
  45025. static int test_wc_SetAuthKeyIdFromPublicKey_ex(void)
  45026. {
  45027. EXPECT_DECLS;
  45028. #if defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)
  45029. WC_RNG rng;
  45030. Cert cert;
  45031. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  45032. RsaKey rsaKey;
  45033. int bits = 2048;
  45034. #endif
  45035. #if defined(HAVE_ECC)
  45036. ecc_key eccKey;
  45037. int ret;
  45038. #endif
  45039. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  45040. ed25519_key ed25519Key;
  45041. #endif
  45042. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  45043. ed448_key ed448Key;
  45044. #endif
  45045. #ifndef HAVE_FIPS
  45046. ExpectIntEQ(wc_InitRng_ex(&rng, HEAP_HINT, testDevId), 0);
  45047. #else
  45048. ExpectIntEQ(wc_InitRng(&rng), 0);
  45049. #endif
  45050. ExpectIntEQ(wc_InitCert(&cert), 0);
  45051. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  45052. /* RSA */
  45053. XMEMSET(&rsaKey, 0, sizeof(RsaKey));
  45054. ExpectIntEQ(wc_InitRsaKey(&rsaKey, HEAP_HINT), 0);
  45055. ExpectIntEQ(MAKE_RSA_KEY(&rsaKey, bits, WC_RSA_EXPONENT, &rng), 0);
  45056. ExpectIntEQ(wc_SetAuthKeyIdFromPublicKey_ex(&cert, RSA_TYPE, &rsaKey), 0);
  45057. DoExpectIntEQ(wc_FreeRsaKey(&rsaKey), 0);
  45058. #endif
  45059. #if defined(HAVE_ECC)
  45060. /* ECC */
  45061. XMEMSET(&eccKey, 0, sizeof(ecc_key));
  45062. ExpectIntEQ(wc_ecc_init(&eccKey), 0);
  45063. ret = wc_ecc_make_key(&rng, KEY14, &eccKey);
  45064. #if defined(WOLFSSL_ASYNC_CRYPT)
  45065. ret = wc_AsyncWait(ret, &eccKey.asyncDev, WC_ASYNC_FLAG_NONE);
  45066. #endif
  45067. ExpectIntEQ(ret, 0);
  45068. ExpectIntEQ(wc_SetAuthKeyIdFromPublicKey_ex(&cert, ECC_TYPE, &eccKey), 0);
  45069. DoExpectIntEQ(wc_ecc_free(&eccKey), 0);
  45070. #endif
  45071. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
  45072. /* ED25519 */
  45073. XMEMSET(&ed25519Key, 0, sizeof(ed25519_key));
  45074. ExpectIntEQ(wc_ed25519_init(&ed25519Key), 0);
  45075. ExpectIntEQ(wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &ed25519Key), 0);
  45076. ExpectIntEQ(wc_SetAuthKeyIdFromPublicKey_ex(&cert, ED25519_TYPE,
  45077. &ed25519Key), 0);
  45078. wc_ed25519_free(&ed25519Key);
  45079. #endif
  45080. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
  45081. /* ED448 */
  45082. XMEMSET(&ed448Key, 0, sizeof(ed448_key));
  45083. ExpectIntEQ(wc_ed448_init(&ed448Key), 0);
  45084. ExpectIntEQ(wc_ed448_make_key(&rng, ED448_KEY_SIZE, &ed448Key), 0);
  45085. ExpectIntEQ(wc_SetAuthKeyIdFromPublicKey_ex(&cert, ED448_TYPE, &ed448Key),
  45086. 0);
  45087. wc_ed448_free(&ed448Key);
  45088. #endif
  45089. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  45090. #endif /* defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)*/
  45091. return EXPECT_RESULT();
  45092. } /* End test_wc_SetAuthKeyIdFromPublicKey_ex*/
  45093. /*
  45094. * Testing wc_PKCS7_New()
  45095. */
  45096. static int test_wc_PKCS7_New(void)
  45097. {
  45098. EXPECT_DECLS;
  45099. #if defined(HAVE_PKCS7)
  45100. PKCS7* pkcs7 = NULL;
  45101. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, testDevId));
  45102. wc_PKCS7_Free(pkcs7);
  45103. #endif
  45104. return EXPECT_RESULT();
  45105. } /* END test-wc_PKCS7_New */
  45106. /*
  45107. * Testing wc_PKCS7_Init()
  45108. */
  45109. static int test_wc_PKCS7_Init(void)
  45110. {
  45111. EXPECT_DECLS;
  45112. #if defined(HAVE_PKCS7)
  45113. PKCS7* pkcs7 = NULL;
  45114. void* heap = NULL;
  45115. ExpectNotNull(pkcs7 = wc_PKCS7_New(heap, testDevId));
  45116. ExpectIntEQ(wc_PKCS7_Init(pkcs7, heap, testDevId), 0);
  45117. /* Pass in bad args. */
  45118. ExpectIntEQ(wc_PKCS7_Init(NULL, heap, testDevId), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45119. wc_PKCS7_Free(pkcs7);
  45120. #endif
  45121. return EXPECT_RESULT();
  45122. } /* END test-wc_PKCS7_Init */
  45123. /*
  45124. * Testing wc_PKCS7_InitWithCert()
  45125. */
  45126. static int test_wc_PKCS7_InitWithCert(void)
  45127. {
  45128. EXPECT_DECLS;
  45129. #if defined(HAVE_PKCS7)
  45130. PKCS7* pkcs7 = NULL;
  45131. #ifndef NO_RSA
  45132. #if defined(USE_CERT_BUFFERS_2048)
  45133. unsigned char cert[sizeof(client_cert_der_2048)];
  45134. int certSz = (int)sizeof(cert);
  45135. XMEMSET(cert, 0, certSz);
  45136. XMEMCPY(cert, client_cert_der_2048, sizeof(client_cert_der_2048));
  45137. #elif defined(USE_CERT_BUFFERS_1024)
  45138. unsigned char cert[sizeof(client_cert_der_1024)];
  45139. int certSz = (int)sizeof(cert);
  45140. XMEMSET(cert, 0, certSz);
  45141. XMEMCPY(cert, client_cert_der_1024, sizeof_client_cert_der_1024);
  45142. #else
  45143. unsigned char cert[ONEK_BUF];
  45144. XFILE fp = XBADFILE;
  45145. int certSz;
  45146. ExpectTrue((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) !=
  45147. XBADFILE);
  45148. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_client_cert_der_1024,
  45149. fp), 0);
  45150. if (fp != XBADFILE)
  45151. XFCLOSE(fp);
  45152. #endif
  45153. #elif defined(HAVE_ECC)
  45154. #if defined(USE_CERT_BUFFERS_256)
  45155. unsigned char cert[sizeof(cliecc_cert_der_256)];
  45156. int certSz = (int)sizeof(cert);
  45157. XMEMSET(cert, 0, certSz);
  45158. XMEMCPY(cert, cliecc_cert_der_256, sizeof(cliecc_cert_der_256));
  45159. #else
  45160. unsigned char cert[ONEK_BUF];
  45161. XFILE fp = XBADFILE;
  45162. int certSz;
  45163. ExpectTrue((fp = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  45164. XBADFILE);
  45165. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof(cliecc_cert_der_256),
  45166. fp), 0);
  45167. if (fp != XBADFILE)
  45168. XFCLOSE(fp);
  45169. #endif
  45170. #else
  45171. #error PKCS7 requires ECC or RSA
  45172. #endif
  45173. #ifdef HAVE_ECC
  45174. {
  45175. /* bad test case from ZD 11011, malformed cert gives bad ECC key */
  45176. static unsigned char certWithInvalidEccKey[] = {
  45177. 0x30, 0x82, 0x03, 0x5F, 0x30, 0x82, 0x03, 0x04, 0xA0, 0x03, 0x02, 0x01,
  45178. 0x02, 0x02, 0x14, 0x61, 0xB3, 0x1E, 0x59, 0xF3, 0x68, 0x6C, 0xA4, 0x79,
  45179. 0x42, 0x83, 0x2F, 0x1A, 0x50, 0x71, 0x03, 0xBE, 0x31, 0xAA, 0x2C, 0x30,
  45180. 0x0A, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x02, 0x30,
  45181. 0x81, 0x8D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13,
  45182. 0x02, 0x55, 0x53, 0x31, 0x0F, 0x30, 0x0D, 0x06, 0x03, 0x55, 0x04, 0x08,
  45183. 0x0C, 0x06, 0x4F, 0x72, 0x65, 0x67, 0x6F, 0x6E, 0x31, 0x0E, 0x30, 0x0C,
  45184. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0C, 0x05, 0x53, 0x61, 0x6C, 0x65, 0x6D,
  45185. 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x0A, 0x43,
  45186. 0x6C, 0x69, 0x65, 0x6E, 0x74, 0x20, 0x45, 0x43, 0x43, 0x31, 0x0D, 0x30,
  45187. 0x0B, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x04, 0x46, 0x61, 0x73, 0x74,
  45188. 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x77,
  45189. 0x77, 0x77, 0x2E, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63,
  45190. 0x6F, 0x6D, 0x31, 0x1F, 0x30, 0x1D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86,
  45191. 0xF7, 0x0D, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40,
  45192. 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x30,
  45193. 0x1E, 0x17, 0x0D, 0x32, 0x30, 0x30, 0x36, 0x31, 0x39, 0x31, 0x33, 0x32,
  45194. 0x33, 0x34, 0x31, 0x5A, 0x17, 0x0D, 0x32, 0x33, 0x30, 0x33, 0x31, 0x36,
  45195. 0x31, 0x33, 0x32, 0x33, 0x34, 0x31, 0x5A, 0x30, 0x81, 0x8D, 0x31, 0x0B,
  45196. 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31,
  45197. 0x0F, 0x30, 0x0D, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0C, 0x06, 0x4F, 0x72,
  45198. 0x65, 0x67, 0x6F, 0x6E, 0x31, 0x0E, 0x30, 0x0C, 0x06, 0x03, 0x55, 0x04,
  45199. 0x07, 0x0C, 0x05, 0x53, 0x61, 0x6C, 0x65, 0x6D, 0x31, 0x13, 0x30, 0x11,
  45200. 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x0A, 0x43, 0x6C, 0x69, 0x65, 0x6E,
  45201. 0x74, 0x20, 0x45, 0x43, 0x43, 0x31, 0x0D, 0x30, 0x0B, 0x06, 0x03, 0x55,
  45202. 0x04, 0x0B, 0x0C, 0x04, 0x46, 0x61, 0x73, 0x74, 0x31, 0x18, 0x30, 0x26,
  45203. 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x77, 0x77, 0x77, 0x2E, 0x77,
  45204. 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x31, 0x1F,
  45205. 0x30, 0x1D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09,
  45206. 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40, 0x77, 0x6F, 0x6C, 0x66,
  45207. 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x30, 0x59, 0x30, 0x13, 0x06,
  45208. 0x07, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x02, 0x01, 0x06, 0x08, 0x2A, 0x86,
  45209. 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07, 0x03, 0x02, 0x00, 0x04, 0x55, 0xBF,
  45210. 0xF4, 0x0F, 0x44, 0x50, 0x9A, 0x3D, 0xCE, 0x9B, 0xB7, 0xF0, 0xC5, 0x4D,
  45211. 0xF5, 0x70, 0x7B, 0xD4, 0xEC, 0x24, 0x8E, 0x19, 0x80, 0xEC, 0x5A, 0x4C,
  45212. 0xA2, 0x24, 0x03, 0x62, 0x2C, 0x9B, 0xDA, 0xEF, 0xA2, 0x35, 0x12, 0x43,
  45213. 0x84, 0x76, 0x16, 0xC6, 0x56, 0x95, 0x06, 0xCC, 0x01, 0xA9, 0xBD, 0xF6,
  45214. 0x75, 0x1A, 0x42, 0xF7, 0xBD, 0xA9, 0xB2, 0x36, 0x22, 0x5F, 0xC7, 0x5D,
  45215. 0x7F, 0xB4, 0xA3, 0x82, 0x01, 0x3E, 0x30, 0x82, 0x01, 0x3A, 0x30, 0x1D,
  45216. 0x06, 0x03, 0x55, 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0xEB, 0xD4, 0x4B,
  45217. 0x59, 0x6B, 0x95, 0x61, 0x3F, 0x51, 0x57, 0xB6, 0x04, 0x4D, 0x89, 0x41,
  45218. 0x88, 0x44, 0x5C, 0xAB, 0xF2, 0x30, 0x81, 0xCD, 0x06, 0x03, 0x55, 0x1D,
  45219. 0x23, 0x04, 0x81, 0xC5, 0x30, 0x81, 0xC2, 0x80, 0x14, 0xEB, 0xD4, 0x4B,
  45220. 0x59, 0x72, 0x95, 0x61, 0x3F, 0x51, 0x57, 0xB6, 0x04, 0x4D, 0x89, 0x41,
  45221. 0x88, 0x44, 0x5C, 0xAB, 0xF2, 0xA1, 0x81, 0x93, 0xA4, 0x81, 0x90, 0x30,
  45222. 0x81, 0x8D, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13,
  45223. 0x02, 0x55, 0x53, 0x31, 0x0F, 0x30, 0x0D, 0x06, 0x03, 0x55, 0x08, 0x08,
  45224. 0x0C, 0x06, 0x4F, 0x72, 0x65, 0x67, 0x6F, 0x6E, 0x31, 0x0E, 0x30, 0x0C,
  45225. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0C, 0x05, 0x53, 0x61, 0x6C, 0x65, 0x6D,
  45226. 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x0A, 0x43,
  45227. 0x6C, 0x69, 0x65, 0x6E, 0x74, 0x20, 0x45, 0x43, 0x43, 0x31, 0x0D, 0x30,
  45228. 0x0B, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x04, 0x46, 0x61, 0x73, 0x74,
  45229. 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x77,
  45230. 0x77, 0x77, 0x2E, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63,
  45231. 0x6F, 0x6D, 0x30, 0x1F, 0x30, 0x1D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86,
  45232. 0xF7, 0x0D, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40,
  45233. 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x82,
  45234. 0x14, 0x61, 0xB3, 0x1E, 0x59, 0xF3, 0x68, 0x6C, 0xA4, 0x79, 0x42, 0x83,
  45235. 0x2F, 0x1A, 0x50, 0x71, 0x03, 0xBE, 0x32, 0xAA, 0x2C, 0x30, 0x0C, 0x06,
  45236. 0x03, 0x55, 0x1D, 0x13, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xFF, 0x30,
  45237. 0x1C, 0x06, 0x03, 0x55, 0x1D, 0x11, 0x04, 0x15, 0x30, 0x13, 0x82, 0x0B,
  45238. 0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x2E, 0x63, 0x6F, 0x6D, 0x87,
  45239. 0x04, 0x23, 0x00, 0x00, 0x01, 0x30, 0x1D, 0x06, 0x03, 0x55, 0x1D, 0x25,
  45240. 0x04, 0x16, 0x30, 0x14, 0x06, 0x08, 0x2B, 0x06, 0x01, 0x05, 0x05, 0x07,
  45241. 0x03, 0x01, 0x06, 0x08, 0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x02,
  45242. 0x30, 0x0A, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x04, 0x03, 0x02,
  45243. 0x03, 0x49, 0x00, 0x30, 0x46, 0x02, 0x21, 0x00, 0xE4, 0xA0, 0x23, 0x26,
  45244. 0x2B, 0x0B, 0x42, 0x0F, 0x97, 0x37, 0x6D, 0xCB, 0x14, 0x23, 0xC3, 0xC3,
  45245. 0xE6, 0x44, 0xCF, 0x5F, 0x4C, 0x26, 0xA3, 0x72, 0x64, 0x7A, 0x9C, 0xCB,
  45246. 0x64, 0xAB, 0xA6, 0xBE, 0x02, 0x21, 0x00, 0xAA, 0xC5, 0xA3, 0x50, 0xF6,
  45247. 0xF1, 0xA5, 0xDB, 0x05, 0xE0, 0x75, 0xD2, 0xF7, 0xBA, 0x49, 0x5F, 0x8F,
  45248. 0x7D, 0x1C, 0x44, 0xB1, 0x6E, 0xDF, 0xC8, 0xDA, 0x10, 0x48, 0x2D, 0x53,
  45249. 0x08, 0xA8, 0xB4
  45250. };
  45251. #endif
  45252. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45253. /* If initialization is not successful, it's free'd in init func. */
  45254. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (byte*)cert, (word32)certSz),
  45255. 0);
  45256. wc_PKCS7_Free(pkcs7);
  45257. pkcs7 = NULL;
  45258. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45259. /* Valid initialization usage. */
  45260. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45261. /* Pass in bad args. No need free for null checks, free at end.*/
  45262. ExpectIntEQ(wc_PKCS7_InitWithCert(NULL, (byte*)cert, (word32)certSz),
  45263. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45264. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, (word32)certSz),
  45265. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45266. #ifdef HAVE_ECC
  45267. ExpectIntLT(wc_PKCS7_InitWithCert(pkcs7, certWithInvalidEccKey,
  45268. sizeof(certWithInvalidEccKey)), 0);
  45269. }
  45270. #endif
  45271. wc_PKCS7_Free(pkcs7);
  45272. #endif
  45273. return EXPECT_RESULT();
  45274. } /* END test_wc_PKCS7_InitWithCert */
  45275. /*
  45276. * Testing wc_PKCS7_EncodeData()
  45277. */
  45278. static int test_wc_PKCS7_EncodeData(void)
  45279. {
  45280. EXPECT_DECLS;
  45281. #if defined(HAVE_PKCS7)
  45282. PKCS7* pkcs7 = NULL;
  45283. byte output[FOURK_BUF];
  45284. byte data[] = "My encoded DER cert.";
  45285. #ifndef NO_RSA
  45286. #if defined(USE_CERT_BUFFERS_2048)
  45287. unsigned char cert[sizeof(client_cert_der_2048)];
  45288. unsigned char key[sizeof(client_key_der_2048)];
  45289. int certSz = (int)sizeof(cert);
  45290. int keySz = (int)sizeof(key);
  45291. XMEMSET(cert, 0, certSz);
  45292. XMEMSET(key, 0, keySz);
  45293. XMEMCPY(cert, client_cert_der_2048, certSz);
  45294. XMEMCPY(key, client_key_der_2048, keySz);
  45295. #elif defined(USE_CERT_BUFFERS_1024)
  45296. unsigned char cert[sizeof(sizeof_client_cert_der_1024)];
  45297. unsigned char key[sizeof_client_key_der_1024];
  45298. int certSz = (int)sizeof(cert);
  45299. int keySz = (int)sizeof(key);
  45300. XMEMSET(cert, 0, certSz);
  45301. XMEMSET(key, 0, keySz);
  45302. XMEMCPY(cert, client_cert_der_1024, certSz);
  45303. XMEMCPY(key, client_key_der_1024, keySz);
  45304. #else
  45305. unsigned char cert[ONEK_BUF];
  45306. unsigned char key[ONEK_BUF];
  45307. XFILE fp = XBADFILE;
  45308. int certSz;
  45309. int keySz;
  45310. ExpectTrue((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) !=
  45311. XBADFILE);
  45312. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_client_cert_der_1024,
  45313. fp), 0);
  45314. if (fp != XBADFILE) {
  45315. XFCLOSE(fp);
  45316. fp = XBADFILE;
  45317. }
  45318. ExpectTrue((fp = XFOPEN("./certs/1024/client-key.der", "rb")) !=
  45319. XBADFILE);
  45320. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_client_key_der_1024, fp),
  45321. 0);
  45322. if (fp != XBADFILE)
  45323. XFCLOSE(fp);
  45324. #endif
  45325. #elif defined(HAVE_ECC)
  45326. #if defined(USE_CERT_BUFFERS_256)
  45327. unsigned char cert[sizeof(cliecc_cert_der_256)];
  45328. unsigned char key[sizeof(ecc_clikey_der_256)];
  45329. int certSz = (int)sizeof(cert);
  45330. int keySz = (int)sizeof(key);
  45331. XMEMSET(cert, 0, certSz);
  45332. XMEMSET(key, 0, keySz);
  45333. XMEMCPY(cert, cliecc_cert_der_256, sizeof_cliecc_cert_der_256);
  45334. XMEMCPY(key, ecc_clikey_der_256, sizeof_ecc_clikey_der_256);
  45335. #else
  45336. unsigned char cert[ONEK_BUF];
  45337. unsigned char key[ONEK_BUF];
  45338. XFILE fp = XBADFILE;
  45339. int certSz, keySz;
  45340. ExpectTrue((fp = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  45341. XBADFILE);
  45342. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_cliecc_cert_der_256,
  45343. fp), 0);
  45344. if (fp != XBADFILE) {
  45345. XFCLOSE(fp);
  45346. fp = XBADFILE;
  45347. }
  45348. ExpectTrue((fp = XFOPEN("./certs/client-ecc-key.der", "rb")) !=
  45349. XBADFILE);
  45350. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_ecc_clikey_der_256, fp),
  45351. 0);
  45352. if (fp != XBADFILE)
  45353. XFCLOSE(fp);
  45354. #endif
  45355. #endif
  45356. XMEMSET(output, 0, sizeof(output));
  45357. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45358. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  45359. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (byte*)cert, (word32)certSz), 0);
  45360. if (pkcs7 != NULL) {
  45361. pkcs7->content = data;
  45362. pkcs7->contentSz = sizeof(data);
  45363. pkcs7->privateKey = key;
  45364. pkcs7->privateKeySz = (word32)keySz;
  45365. }
  45366. ExpectIntGT(wc_PKCS7_EncodeData(pkcs7, output, (word32)sizeof(output)), 0);
  45367. /* Test bad args. */
  45368. ExpectIntEQ(wc_PKCS7_EncodeData(NULL, output, (word32)sizeof(output)),
  45369. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45370. ExpectIntEQ(wc_PKCS7_EncodeData(pkcs7, NULL, (word32)sizeof(output)),
  45371. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45372. ExpectIntEQ(wc_PKCS7_EncodeData(pkcs7, output, 5), WC_NO_ERR_TRACE(BUFFER_E));
  45373. wc_PKCS7_Free(pkcs7);
  45374. #endif
  45375. return EXPECT_RESULT();
  45376. } /* END test_wc_PKCS7_EncodeData */
  45377. #if defined(HAVE_PKCS7) && defined(HAVE_PKCS7_RSA_RAW_SIGN_CALLBACK) && \
  45378. !defined(NO_RSA) && !defined(NO_SHA256)
  45379. /* RSA sign raw digest callback */
  45380. static int rsaSignRawDigestCb(PKCS7* pkcs7, byte* digest, word32 digestSz,
  45381. byte* out, word32 outSz, byte* privateKey,
  45382. word32 privateKeySz, int devid, int hashOID)
  45383. {
  45384. /* specific DigestInfo ASN.1 encoding prefix for a SHA2565 digest */
  45385. byte digInfoEncoding[] = {
  45386. 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
  45387. 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05,
  45388. 0x00, 0x04, 0x20
  45389. };
  45390. int ret;
  45391. byte digestInfo[ONEK_BUF];
  45392. byte sig[FOURK_BUF];
  45393. word32 digestInfoSz = 0;
  45394. word32 idx = 0;
  45395. RsaKey rsa;
  45396. /* SHA-256 required only for this example callback due to above
  45397. * digInfoEncoding[] */
  45398. if (pkcs7 == NULL || digest == NULL || out == NULL ||
  45399. (sizeof(digestInfo) < sizeof(digInfoEncoding) + digestSz) ||
  45400. (hashOID != SHA256h)) {
  45401. return -1;
  45402. }
  45403. /* build DigestInfo */
  45404. XMEMCPY(digestInfo, digInfoEncoding, sizeof(digInfoEncoding));
  45405. digestInfoSz += sizeof(digInfoEncoding);
  45406. XMEMCPY(digestInfo + digestInfoSz, digest, digestSz);
  45407. digestInfoSz += digestSz;
  45408. /* set up RSA key */
  45409. ret = wc_InitRsaKey_ex(&rsa, pkcs7->heap, devid);
  45410. if (ret != 0) {
  45411. return ret;
  45412. }
  45413. ret = wc_RsaPrivateKeyDecode(privateKey, &idx, &rsa, privateKeySz);
  45414. /* sign DigestInfo */
  45415. if (ret == 0) {
  45416. ret = wc_RsaSSL_Sign(digestInfo, digestInfoSz, sig, sizeof(sig),
  45417. &rsa, pkcs7->rng);
  45418. if (ret > 0) {
  45419. if (ret > (int)outSz) {
  45420. /* output buffer too small */
  45421. ret = -1;
  45422. }
  45423. else {
  45424. /* success, ret holds sig size */
  45425. XMEMCPY(out, sig, ret);
  45426. }
  45427. }
  45428. }
  45429. wc_FreeRsaKey(&rsa);
  45430. return ret;
  45431. }
  45432. #endif
  45433. #if defined(HAVE_PKCS7) && defined(ASN_BER_TO_DER)
  45434. typedef struct encodeSignedDataStream {
  45435. byte out[FOURK_BUF*3];
  45436. int idx;
  45437. word32 outIdx;
  45438. } encodeSignedDataStream;
  45439. /* content is 8k of partially created bundle */
  45440. static int GetContentCB(PKCS7* pkcs7, byte** content, void* ctx)
  45441. {
  45442. int ret = 0;
  45443. encodeSignedDataStream* strm = (encodeSignedDataStream*)ctx;
  45444. if (strm->outIdx < pkcs7->contentSz) {
  45445. ret = (pkcs7->contentSz > strm->outIdx + FOURK_BUF)?
  45446. FOURK_BUF : pkcs7->contentSz - strm->outIdx;
  45447. *content = strm->out + strm->outIdx;
  45448. strm->outIdx += ret;
  45449. }
  45450. (void)pkcs7;
  45451. return ret;
  45452. }
  45453. static int StreamOutputCB(PKCS7* pkcs7, const byte* output, word32 outputSz,
  45454. void* ctx)
  45455. {
  45456. encodeSignedDataStream* strm = (encodeSignedDataStream*)ctx;
  45457. XMEMCPY(strm->out + strm->idx, output, outputSz);
  45458. strm->idx += outputSz;
  45459. (void)pkcs7;
  45460. return 0;
  45461. }
  45462. #endif
  45463. /*
  45464. * Testing wc_PKCS7_EncodeSignedData()
  45465. */
  45466. static int test_wc_PKCS7_EncodeSignedData(void)
  45467. {
  45468. EXPECT_DECLS;
  45469. #if defined(HAVE_PKCS7)
  45470. PKCS7* pkcs7 = NULL;
  45471. WC_RNG rng;
  45472. byte output[FOURK_BUF];
  45473. byte badOut[1];
  45474. word32 outputSz = (word32)sizeof(output);
  45475. word32 badOutSz = 0;
  45476. byte data[] = "Test data to encode.";
  45477. #ifndef NO_RSA
  45478. #if defined(USE_CERT_BUFFERS_2048)
  45479. byte key[sizeof(client_key_der_2048)];
  45480. byte cert[sizeof(client_cert_der_2048)];
  45481. word32 keySz = (word32)sizeof(key);
  45482. word32 certSz = (word32)sizeof(cert);
  45483. XMEMSET(key, 0, keySz);
  45484. XMEMSET(cert, 0, certSz);
  45485. XMEMCPY(key, client_key_der_2048, keySz);
  45486. XMEMCPY(cert, client_cert_der_2048, certSz);
  45487. #elif defined(USE_CERT_BUFFERS_1024)
  45488. byte key[sizeof_client_key_der_1024];
  45489. byte cert[sizeof(sizeof_client_cert_der_1024)];
  45490. word32 keySz = (word32)sizeof(key);
  45491. word32 certSz = (word32)sizeof(cert);
  45492. XMEMSET(key, 0, keySz);
  45493. XMEMSET(cert, 0, certSz);
  45494. XMEMCPY(key, client_key_der_1024, keySz);
  45495. XMEMCPY(cert, client_cert_der_1024, certSz);
  45496. #else
  45497. unsigned char cert[ONEK_BUF];
  45498. unsigned char key[ONEK_BUF];
  45499. XFILE fp = XBADFILE;
  45500. int certSz;
  45501. int keySz;
  45502. ExpectTrue((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) !=
  45503. XBADFILE);
  45504. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_client_cert_der_1024,
  45505. fp), 0);
  45506. if (fp != XBADFILE) {
  45507. XFCLOSE(fp);
  45508. fp = XBADFILE;
  45509. }
  45510. ExpectTrue((fp = XFOPEN("./certs/1024/client-key.der", "rb")) !=
  45511. XBADFILE);
  45512. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_client_key_der_1024, fp),
  45513. 0);
  45514. if (fp != XBADFILE)
  45515. XFCLOSE(fp);
  45516. #endif
  45517. #elif defined(HAVE_ECC)
  45518. #if defined(USE_CERT_BUFFERS_256)
  45519. unsigned char cert[sizeof(cliecc_cert_der_256)];
  45520. unsigned char key[sizeof(ecc_clikey_der_256)];
  45521. int certSz = (int)sizeof(cert);
  45522. int keySz = (int)sizeof(key);
  45523. XMEMSET(cert, 0, certSz);
  45524. XMEMSET(key, 0, keySz);
  45525. XMEMCPY(cert, cliecc_cert_der_256, certSz);
  45526. XMEMCPY(key, ecc_clikey_der_256, keySz);
  45527. #else
  45528. unsigned char cert[ONEK_BUF];
  45529. unsigned char key[ONEK_BUF];
  45530. XFILE fp = XBADFILE;
  45531. int certSz;
  45532. int keySz;
  45533. ExpectTrue((fp = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  45534. XBADFILE);
  45535. ExpectIntGT(certSz = (int)XFREAD(cert, 1, ONEK_BUF, fp), 0);
  45536. if (fp != XBADFILE) {
  45537. XFCLOSE(fp);
  45538. fp = XBADFILE;
  45539. }
  45540. ExpectTrue((fp = XFOPEN("./certs/client-ecc-key.der", "rb")) !=
  45541. XBADFILE);
  45542. ExpectIntGT(keySz = (int)XFREAD(key, 1, ONEK_BUF, fp), 0);
  45543. if (fp != XBADFILE)
  45544. XFCLOSE(fp);
  45545. #endif
  45546. #endif
  45547. XMEMSET(&rng, 0, sizeof(WC_RNG));
  45548. XMEMSET(output, 0, outputSz);
  45549. ExpectIntEQ(wc_InitRng(&rng), 0);
  45550. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45551. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  45552. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  45553. if (pkcs7 != NULL) {
  45554. pkcs7->content = data;
  45555. pkcs7->contentSz = (word32)sizeof(data);
  45556. pkcs7->privateKey = key;
  45557. pkcs7->privateKeySz = (word32)sizeof(key);
  45558. pkcs7->encryptOID = RSAk;
  45559. #ifdef NO_SHA
  45560. pkcs7->hashOID = SHA256h;
  45561. #else
  45562. pkcs7->hashOID = SHAh;
  45563. #endif
  45564. pkcs7->rng = &rng;
  45565. }
  45566. ExpectIntGT(wc_PKCS7_EncodeSignedData(pkcs7, output, outputSz), 0);
  45567. wc_PKCS7_Free(pkcs7);
  45568. pkcs7 = NULL;
  45569. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45570. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45571. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  45572. #ifdef ASN_BER_TO_DER
  45573. wc_PKCS7_Free(pkcs7);
  45574. /* reinitialize and test setting stream mode */
  45575. {
  45576. int signedSz = 0;
  45577. encodeSignedDataStream strm;
  45578. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45579. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  45580. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  45581. if (pkcs7 != NULL) {
  45582. pkcs7->content = data;
  45583. pkcs7->contentSz = (word32)sizeof(data);
  45584. pkcs7->privateKey = key;
  45585. pkcs7->privateKeySz = (word32)sizeof(key);
  45586. pkcs7->encryptOID = RSAk;
  45587. #ifdef NO_SHA
  45588. pkcs7->hashOID = SHA256h;
  45589. #else
  45590. pkcs7->hashOID = SHAh;
  45591. #endif
  45592. pkcs7->rng = &rng;
  45593. }
  45594. ExpectIntEQ(wc_PKCS7_GetStreamMode(pkcs7), 0);
  45595. ExpectIntEQ(wc_PKCS7_SetStreamMode(pkcs7, 1, NULL, NULL, NULL), 0);
  45596. ExpectIntEQ(wc_PKCS7_SetStreamMode(NULL, 1, NULL, NULL, NULL),
  45597. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45598. ExpectIntEQ(wc_PKCS7_GetStreamMode(pkcs7), 1);
  45599. ExpectIntGT(signedSz = wc_PKCS7_EncodeSignedData(pkcs7, output,
  45600. outputSz), 0);
  45601. wc_PKCS7_Free(pkcs7);
  45602. pkcs7 = NULL;
  45603. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45604. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45605. /* use exact signed buffer size since BER encoded */
  45606. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, (word32)signedSz), 0);
  45607. wc_PKCS7_Free(pkcs7);
  45608. /* now try with using callbacks for IO */
  45609. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45610. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  45611. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  45612. if (pkcs7 != NULL) {
  45613. pkcs7->contentSz = FOURK_BUF*2;
  45614. pkcs7->privateKey = key;
  45615. pkcs7->privateKeySz = (word32)sizeof(key);
  45616. pkcs7->encryptOID = RSAk;
  45617. #ifdef NO_SHA
  45618. pkcs7->hashOID = SHA256h;
  45619. #else
  45620. pkcs7->hashOID = SHAh;
  45621. #endif
  45622. pkcs7->rng = &rng;
  45623. }
  45624. XMEMSET(&strm, 0, sizeof(strm));
  45625. ExpectIntEQ(wc_PKCS7_SetStreamMode(pkcs7, 1, GetContentCB,
  45626. StreamOutputCB, (void*)&strm), 0);
  45627. ExpectIntGT(signedSz = wc_PKCS7_EncodeSignedData(pkcs7, NULL, 0), 0);
  45628. wc_PKCS7_Free(pkcs7);
  45629. pkcs7 = NULL;
  45630. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45631. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45632. /* use exact signed buffer size since BER encoded */
  45633. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, strm.out, (word32)signedSz), 0);
  45634. }
  45635. #endif
  45636. #ifndef NO_PKCS7_STREAM
  45637. wc_PKCS7_Free(pkcs7);
  45638. pkcs7 = NULL;
  45639. {
  45640. word32 z;
  45641. int ret;
  45642. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45643. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45644. /* test for streaming mode */
  45645. ret = -1;
  45646. for (z = 0; z < outputSz && ret != 0; z++) {
  45647. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45648. if (ret < 0){
  45649. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45650. }
  45651. }
  45652. ExpectIntEQ(ret, 0);
  45653. ExpectIntNE(pkcs7->contentSz, 0);
  45654. ExpectNotNull(pkcs7->contentDynamic);
  45655. }
  45656. #endif /* !NO_PKCS7_STREAM */
  45657. /* Pass in bad args. */
  45658. ExpectIntEQ(wc_PKCS7_EncodeSignedData(NULL, output, outputSz),
  45659. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45660. ExpectIntEQ(wc_PKCS7_EncodeSignedData(pkcs7, NULL, outputSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45661. ExpectIntEQ(wc_PKCS7_EncodeSignedData(pkcs7, badOut,
  45662. badOutSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45663. if (pkcs7 != NULL) {
  45664. pkcs7->hashOID = 0; /* bad hashOID */
  45665. }
  45666. ExpectIntEQ(wc_PKCS7_EncodeSignedData(pkcs7, output, outputSz),
  45667. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45668. #if defined(HAVE_PKCS7) && defined(HAVE_PKCS7_RSA_RAW_SIGN_CALLBACK) && \
  45669. !defined(NO_RSA) && !defined(NO_SHA256)
  45670. /* test RSA sign raw digest callback, if using RSA and compiled in.
  45671. * Example callback assumes SHA-256, so only run test if compiled in. */
  45672. wc_PKCS7_Free(pkcs7);
  45673. pkcs7 = NULL;
  45674. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45675. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  45676. if (pkcs7 != NULL) {
  45677. pkcs7->content = data;
  45678. pkcs7->contentSz = (word32)sizeof(data);
  45679. pkcs7->privateKey = key;
  45680. pkcs7->privateKeySz = (word32)sizeof(key);
  45681. pkcs7->encryptOID = RSAk;
  45682. pkcs7->hashOID = SHA256h;
  45683. pkcs7->rng = &rng;
  45684. }
  45685. ExpectIntEQ(wc_PKCS7_SetRsaSignRawDigestCb(pkcs7, rsaSignRawDigestCb), 0);
  45686. ExpectIntGT(wc_PKCS7_EncodeSignedData(pkcs7, output, outputSz), 0);
  45687. #endif
  45688. wc_PKCS7_Free(pkcs7);
  45689. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  45690. #endif
  45691. return EXPECT_RESULT();
  45692. } /* END test_wc_PKCS7_EncodeSignedData */
  45693. /*
  45694. * Testing wc_PKCS7_EncodeSignedData_ex() and wc_PKCS7_VerifySignedData_ex()
  45695. */
  45696. static int test_wc_PKCS7_EncodeSignedData_ex(void)
  45697. {
  45698. EXPECT_DECLS;
  45699. #if defined(HAVE_PKCS7)
  45700. int i;
  45701. PKCS7* pkcs7 = NULL;
  45702. WC_RNG rng;
  45703. byte outputHead[FOURK_BUF/2];
  45704. byte outputFoot[FOURK_BUF/2];
  45705. word32 outputHeadSz = (word32)sizeof(outputHead);
  45706. word32 outputFootSz = (word32)sizeof(outputFoot);
  45707. byte data[FOURK_BUF];
  45708. wc_HashAlg hash;
  45709. #ifdef NO_SHA
  45710. enum wc_HashType hashType = WC_HASH_TYPE_SHA256;
  45711. #else
  45712. enum wc_HashType hashType = WC_HASH_TYPE_SHA;
  45713. #endif
  45714. byte hashBuf[WC_MAX_DIGEST_SIZE];
  45715. word32 hashSz = (word32)wc_HashGetDigestSize(hashType);
  45716. #ifndef NO_RSA
  45717. #if defined(USE_CERT_BUFFERS_2048)
  45718. byte key[sizeof(client_key_der_2048)];
  45719. byte cert[sizeof(client_cert_der_2048)];
  45720. word32 keySz = (word32)sizeof(key);
  45721. word32 certSz = (word32)sizeof(cert);
  45722. XMEMSET(key, 0, keySz);
  45723. XMEMSET(cert, 0, certSz);
  45724. XMEMCPY(key, client_key_der_2048, keySz);
  45725. XMEMCPY(cert, client_cert_der_2048, certSz);
  45726. #elif defined(USE_CERT_BUFFERS_1024)
  45727. byte key[sizeof_client_key_der_1024];
  45728. byte cert[sizeof(sizeof_client_cert_der_1024)];
  45729. word32 keySz = (word32)sizeof(key);
  45730. word32 certSz = (word32)sizeof(cert);
  45731. XMEMSET(key, 0, keySz);
  45732. XMEMSET(cert, 0, certSz);
  45733. XMEMCPY(key, client_key_der_1024, keySz);
  45734. XMEMCPY(cert, client_cert_der_1024, certSz);
  45735. #else
  45736. unsigned char cert[ONEK_BUF];
  45737. unsigned char key[ONEK_BUF];
  45738. XFILE fp = XBADFILE;
  45739. int certSz;
  45740. int keySz;
  45741. ExpectTure((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) !=
  45742. XBADFILE);
  45743. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_client_cert_der_1024,
  45744. fp), 0);
  45745. if (fp != XBADFILE) {
  45746. XFCLOSE(fp);
  45747. fp = XBADFILE;
  45748. }
  45749. ExpectTrue((fp = XFOPEN("./certs/1024/client-key.der", "rb")) !=
  45750. XBADFILE);
  45751. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_client_key_der_1024, fp),
  45752. 0);
  45753. if (fp != XBADFILE)
  45754. XFCLOSE(fp);
  45755. #endif
  45756. #elif defined(HAVE_ECC)
  45757. #if defined(USE_CERT_BUFFERS_256)
  45758. unsigned char cert[sizeof(cliecc_cert_der_256)];
  45759. unsigned char key[sizeof(ecc_clikey_der_256)];
  45760. int certSz = (int)sizeof(cert);
  45761. int keySz = (int)sizeof(key);
  45762. XMEMSET(cert, 0, certSz);
  45763. XMEMSET(key, 0, keySz);
  45764. XMEMCPY(cert, cliecc_cert_der_256, sizeof_cliecc_cert_der_256);
  45765. XMEMCPY(key, ecc_clikey_der_256, sizeof_ecc_clikey_der_256);
  45766. #else
  45767. unsigned char cert[ONEK_BUF];
  45768. unsigned char key[ONEK_BUF];
  45769. XFILE fp = XBADFILE;
  45770. int certSz;
  45771. int keySz;
  45772. ExpectTrue((fp = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  45773. XBADFILE);
  45774. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_cliecc_cert_der_256,
  45775. fp), 0);
  45776. if (fp != XBADFILE) {
  45777. XFCLOSE(fp);
  45778. fp = XBADFILE;
  45779. }
  45780. ExpectTrue((fp = XFOPEN("./certs/client-ecc-key.der", "rb")) !=
  45781. XBADFILE);
  45782. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_ecc_clikey_der_256, fp),
  45783. 0);
  45784. if (fp != XBADFILE)
  45785. XFCLOSE(fp);
  45786. #endif
  45787. #endif
  45788. XMEMSET(&rng, 0, sizeof(WC_RNG));
  45789. /* initialize large data with sequence */
  45790. for (i=0; i<(int)sizeof(data); i++)
  45791. data[i] = i & 0xff;
  45792. XMEMSET(outputHead, 0, outputHeadSz);
  45793. XMEMSET(outputFoot, 0, outputFootSz);
  45794. ExpectIntEQ(wc_InitRng(&rng), 0);
  45795. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45796. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  45797. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  45798. if (pkcs7 != NULL) {
  45799. pkcs7->content = NULL; /* not used for ex */
  45800. pkcs7->contentSz = (word32)sizeof(data);
  45801. pkcs7->privateKey = key;
  45802. pkcs7->privateKeySz = (word32)sizeof(key);
  45803. pkcs7->encryptOID = RSAk;
  45804. #ifdef NO_SHA
  45805. pkcs7->hashOID = SHA256h;
  45806. #else
  45807. pkcs7->hashOID = SHAh;
  45808. #endif
  45809. pkcs7->rng = &rng;
  45810. }
  45811. /* calculate hash for content */
  45812. XMEMSET(&hash, 0, sizeof(wc_HashAlg));
  45813. ExpectIntEQ(wc_HashInit(&hash, hashType), 0);
  45814. ExpectIntEQ(wc_HashUpdate(&hash, hashType, data, sizeof(data)), 0);
  45815. ExpectIntEQ(wc_HashFinal(&hash, hashType, hashBuf), 0);
  45816. DoExpectIntEQ(wc_HashFree(&hash, hashType), 0);
  45817. /* Perform PKCS7 sign using hash directly */
  45818. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz,
  45819. outputHead, &outputHeadSz, outputFoot, &outputFootSz), 0);
  45820. ExpectIntGT(outputHeadSz, 0);
  45821. ExpectIntGT(outputFootSz, 0);
  45822. wc_PKCS7_Free(pkcs7);
  45823. pkcs7 = NULL;
  45824. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45825. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45826. /* required parameter even on verify when using _ex, if using outputHead
  45827. * and outputFoot */
  45828. if (pkcs7 != NULL) {
  45829. pkcs7->contentSz = (word32)sizeof(data);
  45830. }
  45831. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  45832. outputHead, outputHeadSz, outputFoot, outputFootSz), 0);
  45833. wc_PKCS7_Free(pkcs7);
  45834. pkcs7 = NULL;
  45835. /* assembly complete PKCS7 sign and use normal verify */
  45836. {
  45837. byte* output = NULL;
  45838. word32 outputSz = 0;
  45839. #ifndef NO_PKCS7_STREAM
  45840. word32 z;
  45841. int ret;
  45842. #endif /* !NO_PKCS7_STREAM */
  45843. ExpectNotNull(output = (byte*)XMALLOC(
  45844. outputHeadSz + sizeof(data) + outputFootSz, HEAP_HINT,
  45845. DYNAMIC_TYPE_TMP_BUFFER));
  45846. if (output != NULL) {
  45847. XMEMCPY(&output[outputSz], outputHead, outputHeadSz);
  45848. outputSz += outputHeadSz;
  45849. XMEMCPY(&output[outputSz], data, sizeof(data));
  45850. outputSz += sizeof(data);
  45851. XMEMCPY(&output[outputSz], outputFoot, outputFootSz);
  45852. outputSz += outputFootSz;
  45853. }
  45854. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45855. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45856. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  45857. #ifndef NO_PKCS7_STREAM
  45858. wc_PKCS7_Free(pkcs7);
  45859. pkcs7 = NULL;
  45860. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45861. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45862. /* test for streaming mode */
  45863. ret = -1;
  45864. for (z = 0; z < outputSz && ret != 0; z++) {
  45865. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  45866. if (ret < 0){
  45867. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45868. }
  45869. }
  45870. ExpectIntEQ(ret, 0);
  45871. ExpectIntNE(pkcs7->contentSz, 0);
  45872. ExpectNotNull(pkcs7->contentDynamic);
  45873. wc_PKCS7_Free(pkcs7);
  45874. pkcs7 = NULL;
  45875. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  45876. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  45877. #endif /* !NO_PKCS7_STREAM */
  45878. XFREE(output, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45879. }
  45880. /* Pass in bad args. */
  45881. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(NULL, hashBuf, hashSz, outputHead,
  45882. &outputHeadSz, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45883. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, NULL, hashSz, outputHead,
  45884. &outputHeadSz, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45885. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, 0, outputHead,
  45886. &outputHeadSz, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45887. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz, NULL,
  45888. &outputHeadSz, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45889. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz,
  45890. outputHead, NULL, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45891. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz,
  45892. outputHead, &outputHeadSz, NULL, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45893. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz,
  45894. outputHead, &outputHeadSz, outputFoot, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45895. if (pkcs7 != NULL) {
  45896. pkcs7->hashOID = 0; /* bad hashOID */
  45897. }
  45898. ExpectIntEQ(wc_PKCS7_EncodeSignedData_ex(pkcs7, hashBuf, hashSz,
  45899. outputHead, &outputHeadSz, outputFoot, &outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45900. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(NULL, hashBuf, hashSz, outputHead,
  45901. outputHeadSz, outputFoot, outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45902. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, NULL, hashSz, outputHead,
  45903. outputHeadSz, outputFoot, outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45904. #ifndef NO_PKCS7_STREAM
  45905. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, 0, outputHead,
  45906. outputHeadSz, outputFoot, outputFootSz), WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45907. #else
  45908. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, 0, outputHead,
  45909. outputHeadSz, outputFoot, outputFootSz), WC_NO_ERR_TRACE(BUFFER_E));
  45910. #endif
  45911. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz, NULL,
  45912. outputHeadSz, outputFoot, outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45913. #ifndef NO_PKCS7_STREAM
  45914. /* can pass in 0 buffer length with streaming API */
  45915. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  45916. outputHead, 0, outputFoot, outputFootSz), WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45917. #else
  45918. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  45919. outputHead, 0, outputFoot, outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45920. #endif
  45921. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  45922. outputHead, outputHeadSz, NULL, outputFootSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  45923. #ifndef NO_PKCS7_STREAM
  45924. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  45925. outputHead, outputHeadSz, outputFoot, 0), WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  45926. #else
  45927. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  45928. outputHead, outputHeadSz, outputFoot, 0), WC_NO_ERR_TRACE(BUFFER_E));
  45929. #endif
  45930. wc_PKCS7_Free(pkcs7);
  45931. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  45932. #endif
  45933. return EXPECT_RESULT();
  45934. } /* END test_wc_PKCS7_EncodeSignedData_ex */
  45935. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM)
  45936. /**
  45937. * Loads certs/keys from files or buffers into the argument buffers,
  45938. * helper function called by CreatePKCS7SignedData().
  45939. *
  45940. * Returns 0 on success, negative on error.
  45941. */
  45942. static int LoadPKCS7SignedDataCerts(
  45943. int useIntermediateCertChain, int pkAlgoType,
  45944. byte* intCARoot, word32* intCARootSz,
  45945. byte* intCA1, word32* intCA1Sz,
  45946. byte* intCA2, word32* intCA2Sz,
  45947. byte* cert, word32* certSz,
  45948. byte* key, word32* keySz)
  45949. {
  45950. EXPECT_DECLS;
  45951. int ret = 0;
  45952. XFILE fp = XBADFILE;
  45953. #ifndef NO_RSA
  45954. const char* intCARootRSA = "./certs/ca-cert.der";
  45955. const char* intCA1RSA = "./certs/intermediate/ca-int-cert.der";
  45956. const char* intCA2RSA = "./certs/intermediate/ca-int2-cert.der";
  45957. const char* intServCertRSA = "./certs/intermediate/server-int-cert.der";
  45958. const char* intServKeyRSA = "./certs/server-key.der";
  45959. #if !defined(USE_CERT_BUFFERS_2048) && !defined(USE_CERT_BUFFERS_1024)
  45960. const char* cli1024Cert = "./certs/1024/client-cert.der";
  45961. const char* cli1024Key = "./certs/1024/client-key.der";
  45962. #endif
  45963. #endif
  45964. #ifdef HAVE_ECC
  45965. const char* intCARootECC = "./certs/ca-ecc-cert.der";
  45966. const char* intCA1ECC = "./certs/intermediate/ca-int-ecc-cert.der";
  45967. const char* intCA2ECC = "./certs/intermediate/ca-int2-ecc-cert.der";
  45968. const char* intServCertECC = "./certs/intermediate/server-int-ecc-cert.der";
  45969. const char* intServKeyECC = "./certs/ecc-key.der";
  45970. #ifndef USE_CERT_BUFFERS_256
  45971. const char* cliEccCert = "./certs/client-ecc-cert.der";
  45972. const char* cliEccKey = "./certs/client-ecc-key.der";
  45973. #endif
  45974. #endif
  45975. if (cert == NULL || certSz == NULL || key == NULL || keySz == NULL ||
  45976. ((useIntermediateCertChain == 1) &&
  45977. (intCARoot == NULL || intCARootSz == NULL || intCA1 == NULL ||
  45978. intCA1Sz == NULL || intCA2 == NULL || intCA2Sz == NULL))) {
  45979. return BAD_FUNC_ARG;
  45980. }
  45981. /* Read/load certs and keys to use for signing based on PK type and chain */
  45982. switch (pkAlgoType) {
  45983. #ifndef NO_RSA
  45984. case RSA_TYPE:
  45985. if (useIntermediateCertChain == 1) {
  45986. ExpectTrue((fp = XFOPEN(intCARootRSA, "rb")) != XBADFILE);
  45987. *intCARootSz = (word32)XFREAD(intCARoot, 1, *intCARootSz, fp);
  45988. if (fp != XBADFILE) {
  45989. XFCLOSE(fp);
  45990. fp = XBADFILE;
  45991. }
  45992. ExpectIntGT(*intCARootSz, 0);
  45993. ExpectTrue((fp = XFOPEN(intCA1RSA, "rb")) != XBADFILE);
  45994. if (fp != XBADFILE) {
  45995. *intCA1Sz = (word32)XFREAD(intCA1, 1, *intCA1Sz, fp);
  45996. XFCLOSE(fp);
  45997. fp = XBADFILE;
  45998. }
  45999. ExpectIntGT(*intCA1Sz, 0);
  46000. ExpectTrue((fp = XFOPEN(intCA2RSA, "rb")) != XBADFILE);
  46001. if (fp != XBADFILE) {
  46002. *intCA2Sz = (word32)XFREAD(intCA2, 1, *intCA2Sz, fp);
  46003. XFCLOSE(fp);
  46004. fp = XBADFILE;
  46005. }
  46006. ExpectIntGT(*intCA2Sz, 0);
  46007. ExpectTrue((fp = XFOPEN(intServCertRSA, "rb")) != XBADFILE);
  46008. if (fp != XBADFILE) {
  46009. *certSz = (word32)XFREAD(cert, 1, *certSz, fp);
  46010. XFCLOSE(fp);
  46011. fp = XBADFILE;
  46012. }
  46013. ExpectIntGT(*certSz, 0);
  46014. ExpectTrue((fp = XFOPEN(intServKeyRSA, "rb")) != XBADFILE);
  46015. if (fp != XBADFILE) {
  46016. *keySz = (word32)XFREAD(key, 1, *keySz, fp);
  46017. XFCLOSE(fp);
  46018. fp = XBADFILE;
  46019. }
  46020. ExpectIntGT(*keySz, 0);
  46021. }
  46022. else {
  46023. #if defined(USE_CERT_BUFFERS_2048)
  46024. *keySz = sizeof_client_key_der_2048;
  46025. *certSz = sizeof_client_cert_der_2048;
  46026. XMEMCPY(key, client_key_der_2048, *keySz);
  46027. XMEMCPY(cert, client_cert_der_2048, *certSz);
  46028. #elif defined(USE_CERT_BUFFERS_1024)
  46029. *keySz = sizeof_client_key_der_1024;
  46030. *certSz = sizeof_client_cert_der_1024;
  46031. XMEMCPY(key, client_key_der_1024, *keySz);
  46032. XMEMCPY(cert, client_cert_der_1024, *certSz);
  46033. #else
  46034. ExpectTrue((fp = XFOPEN(cli1024Key, "rb")) != XBADFILE);
  46035. if (fp != XBADFILE) {
  46036. *keySz = (word32)XFREAD(key, 1, *keySz, fp);
  46037. XFCLOSE(fp);
  46038. fp = XBADFILE;
  46039. }
  46040. ExpectIntGT(*keySz, 0);
  46041. ExpectTrue((fp = XFOPEN(cli1024Cert, "rb")) != XBADFILE);
  46042. if (fp != XBADFILE) {
  46043. *certSz = (word32)XFREAD(cert, 1, *certSz, fp);
  46044. XFCLOSE(fp);
  46045. fp = XBADFILE;
  46046. }
  46047. ExpectIntGT(*certSz, 0);
  46048. #endif /* USE_CERT_BUFFERS_2048 */
  46049. }
  46050. break;
  46051. #endif /* !NO_RSA */
  46052. #ifdef HAVE_ECC
  46053. case ECC_TYPE:
  46054. if (useIntermediateCertChain == 1) {
  46055. ExpectTrue((fp = XFOPEN(intCARootECC, "rb")) != XBADFILE);
  46056. if (fp != XBADFILE) {
  46057. *intCARootSz = (word32)XFREAD(intCARoot, 1, *intCARootSz,
  46058. fp);
  46059. XFCLOSE(fp);
  46060. fp = XBADFILE;
  46061. }
  46062. ExpectIntGT(*intCARootSz, 0);
  46063. ExpectTrue((fp = XFOPEN(intCA1ECC, "rb")) != XBADFILE);
  46064. if (fp != XBADFILE) {
  46065. *intCA1Sz = (word32)XFREAD(intCA1, 1, *intCA1Sz, fp);
  46066. XFCLOSE(fp);
  46067. fp = XBADFILE;
  46068. }
  46069. ExpectIntGT(*intCA1Sz, 0);
  46070. ExpectTrue((fp = XFOPEN(intCA2ECC, "rb")) != XBADFILE);
  46071. if (fp != XBADFILE) {
  46072. *intCA2Sz = (word32)XFREAD(intCA2, 1, *intCA2Sz, fp);
  46073. XFCLOSE(fp);
  46074. fp = XBADFILE;
  46075. }
  46076. ExpectIntGT(*intCA2Sz, 0);
  46077. ExpectTrue((fp = XFOPEN(intServCertECC, "rb")) != XBADFILE);
  46078. if (fp != XBADFILE) {
  46079. *certSz = (word32)XFREAD(cert, 1, *certSz, fp);
  46080. XFCLOSE(fp);
  46081. fp = XBADFILE;
  46082. }
  46083. ExpectIntGT(*certSz, 0);
  46084. ExpectTrue((fp = XFOPEN(intServKeyECC, "rb")) != XBADFILE);
  46085. if (fp != XBADFILE) {
  46086. *keySz = (word32)XFREAD(key, 1, *keySz, fp);
  46087. XFCLOSE(fp);
  46088. fp = XBADFILE;
  46089. }
  46090. ExpectIntGT(*keySz, 0);
  46091. }
  46092. else {
  46093. #if defined(USE_CERT_BUFFERS_256)
  46094. *keySz = sizeof_ecc_clikey_der_256;
  46095. *certSz = sizeof_cliecc_cert_der_256;
  46096. XMEMCPY(key, ecc_clikey_der_256, *keySz);
  46097. XMEMCPY(cert, cliecc_cert_der_256, *certSz);
  46098. #else
  46099. ExpectTrue((fp = XFOPEN(cliEccKey, "rb")) != XBADFILE);
  46100. if (fp != XBADFILE) {
  46101. *keySz = (word32)XFREAD(key, 1, *keySz, fp);
  46102. XFCLOSE(fp);
  46103. fp = XBADFILE;
  46104. }
  46105. ExpectIntGT(*keySz, 0);
  46106. ExpectTrue((fp = XFOPEN(cliEccCert, "rb")) != XBADFILE);
  46107. if (fp != XBADFILE) {
  46108. *certSz = (word32)XFREAD(cert, 1, *certSz, fp);
  46109. XFCLOSE(fp);
  46110. fp = XBADFILE;
  46111. }
  46112. ExpectIntGT(*certSz, 0);
  46113. #endif /* USE_CERT_BUFFERS_256 */
  46114. }
  46115. break;
  46116. #endif /* HAVE_ECC */
  46117. default:
  46118. WOLFSSL_MSG("Unsupported SignedData PK type");
  46119. ret = BAD_FUNC_ARG;
  46120. break;
  46121. }
  46122. if (EXPECT_FAIL() && (ret == 0)) {
  46123. ret = BAD_FUNC_ARG;
  46124. }
  46125. return ret;
  46126. }
  46127. /**
  46128. * Creates a PKCS7/CMS SignedData bundle to use for testing.
  46129. *
  46130. * output output buffer to place SignedData
  46131. * outputSz size of output buffer
  46132. * data data buffer to be signed
  46133. * dataSz size of data buffer
  46134. * withAttribs [1/0] include attributes in SignedData message
  46135. * detachedSig [1/0] create detached signature, no content
  46136. * useIntCertChain [1/0] use certificate chain and include intermediate and
  46137. * root CAs in bundle
  46138. * pkAlgoType RSA_TYPE or ECC_TYPE, choose what key/cert type to use
  46139. *
  46140. * Return size of bundle created on success, negative on error */
  46141. static int CreatePKCS7SignedData(unsigned char* output, int outputSz,
  46142. byte* data, word32 dataSz,
  46143. int withAttribs, int detachedSig,
  46144. int useIntermediateCertChain,
  46145. int pkAlgoType)
  46146. {
  46147. EXPECT_DECLS;
  46148. int ret = 0;
  46149. WC_RNG rng;
  46150. PKCS7* pkcs7 = NULL;
  46151. static byte messageTypeOid[] =
  46152. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  46153. 0x09, 0x02 };
  46154. static byte messageType[] = { 0x13, 2, '1', '9' };
  46155. PKCS7Attrib attribs[] =
  46156. {
  46157. { messageTypeOid, sizeof(messageTypeOid), messageType,
  46158. sizeof(messageType) }
  46159. };
  46160. byte intCARoot[TWOK_BUF];
  46161. byte intCA1[TWOK_BUF];
  46162. byte intCA2[TWOK_BUF];
  46163. byte cert[TWOK_BUF];
  46164. byte key[TWOK_BUF];
  46165. word32 intCARootSz = sizeof(intCARoot);
  46166. word32 intCA1Sz = sizeof(intCA1);
  46167. word32 intCA2Sz = sizeof(intCA2);
  46168. word32 certSz = sizeof(cert);
  46169. word32 keySz = sizeof(key);
  46170. XMEMSET(intCARoot, 0, intCARootSz);
  46171. XMEMSET(intCA1, 0, intCA1Sz);
  46172. XMEMSET(intCA2, 0, intCA2Sz);
  46173. XMEMSET(cert, 0, certSz);
  46174. XMEMSET(key, 0, keySz);
  46175. ret = LoadPKCS7SignedDataCerts(useIntermediateCertChain, pkAlgoType,
  46176. intCARoot, &intCARootSz, intCA1, &intCA1Sz, intCA2, &intCA2Sz,
  46177. cert, &certSz, key, &keySz);
  46178. ExpectIntEQ(ret, 0);
  46179. XMEMSET(output, 0, outputSz);
  46180. ExpectIntEQ(wc_InitRng(&rng), 0);
  46181. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46182. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  46183. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, certSz), 0);
  46184. if (useIntermediateCertChain == 1) {
  46185. /* Add intermediate and root CA certs into SignedData Certs SET */
  46186. ExpectIntEQ(wc_PKCS7_AddCertificate(pkcs7, intCA2, intCA2Sz), 0);
  46187. ExpectIntEQ(wc_PKCS7_AddCertificate(pkcs7, intCA1, intCA1Sz), 0);
  46188. ExpectIntEQ(wc_PKCS7_AddCertificate(pkcs7, intCARoot, intCARootSz), 0);
  46189. }
  46190. if (pkcs7 != NULL) {
  46191. pkcs7->content = data;
  46192. pkcs7->contentSz = dataSz;
  46193. pkcs7->privateKey = key;
  46194. pkcs7->privateKeySz = (word32)sizeof(key);
  46195. if (pkAlgoType == RSA_TYPE) {
  46196. pkcs7->encryptOID = RSAk;
  46197. }
  46198. else {
  46199. pkcs7->encryptOID = ECDSAk;
  46200. }
  46201. #ifdef NO_SHA
  46202. pkcs7->hashOID = SHA256h;
  46203. #else
  46204. pkcs7->hashOID = SHAh;
  46205. #endif
  46206. pkcs7->rng = &rng;
  46207. if (withAttribs) {
  46208. /* include a signed attribute */
  46209. pkcs7->signedAttribs = attribs;
  46210. pkcs7->signedAttribsSz = (sizeof(attribs)/sizeof(PKCS7Attrib));
  46211. }
  46212. }
  46213. if (detachedSig) {
  46214. ExpectIntEQ(wc_PKCS7_SetDetached(pkcs7, 1), 0);
  46215. }
  46216. outputSz = wc_PKCS7_EncodeSignedData(pkcs7, output, (word32)outputSz);
  46217. ExpectIntGT(outputSz, 0);
  46218. wc_PKCS7_Free(pkcs7);
  46219. pkcs7 = NULL;
  46220. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46221. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46222. if (detachedSig && (pkcs7 != NULL)) {
  46223. pkcs7->content = data;
  46224. pkcs7->contentSz = dataSz;
  46225. }
  46226. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, (word32)outputSz), 0);
  46227. wc_PKCS7_Free(pkcs7);
  46228. wc_FreeRng(&rng);
  46229. if (EXPECT_FAIL()) {
  46230. outputSz = 0;
  46231. }
  46232. return outputSz;
  46233. }
  46234. #endif
  46235. /*
  46236. * Testing wc_PKCS_VerifySignedData()
  46237. */
  46238. static int test_wc_PKCS7_VerifySignedData_RSA(void)
  46239. {
  46240. EXPECT_DECLS;
  46241. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  46242. PKCS7* pkcs7 = NULL;
  46243. byte output[6000]; /* Large size needed for bundles with int CA certs */
  46244. word32 outputSz = sizeof(output);
  46245. byte data[] = "Test data to encode.";
  46246. byte badOut[1];
  46247. word32 badOutSz = 0;
  46248. byte badContent[] = "This is different content than was signed";
  46249. wc_HashAlg hash;
  46250. #ifdef NO_SHA
  46251. enum wc_HashType hashType = WC_HASH_TYPE_SHA256;
  46252. #else
  46253. enum wc_HashType hashType = WC_HASH_TYPE_SHA;
  46254. #endif
  46255. byte hashBuf[WC_MAX_DIGEST_SIZE];
  46256. word32 hashSz = (word32)wc_HashGetDigestSize(hashType);
  46257. #ifndef NO_RSA
  46258. PKCS7DecodedAttrib* decodedAttrib = NULL;
  46259. /* contentType OID (1.2.840.113549.1.9.3) */
  46260. static const byte contentTypeOid[] =
  46261. { 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xF7, 0x0d, 0x01, 0x09, 0x03 };
  46262. /* PKCS#7 DATA content type (contentType defaults to DATA) */
  46263. static const byte dataType[] =
  46264. { 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01 };
  46265. /* messageDigest OID (1.2.840.113549.1.9.4) */
  46266. static const byte messageDigestOid[] =
  46267. { 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x04 };
  46268. #ifndef NO_ASN_TIME
  46269. /* signingTime OID () */
  46270. static const byte signingTimeOid[] =
  46271. { 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x05};
  46272. #endif
  46273. #if !defined(NO_ASN) && !defined(NO_ASN_TIME)
  46274. int dateLength = 0;
  46275. byte dateFormat;
  46276. const byte* datePart = NULL;
  46277. struct tm timearg;
  46278. time_t now;
  46279. struct tm* nowTm = NULL;
  46280. #ifdef NEED_TMP_TIME
  46281. struct tm tmpTimeStorage;
  46282. struct tm* tmpTime = &tmpTimeStorage;
  46283. #endif
  46284. #endif /* !NO_ASN && !NO_ASN_TIME */
  46285. #ifndef NO_PKCS7_STREAM
  46286. word32 z;
  46287. int ret;
  46288. #endif /* !NO_PKCS7_STREAM */
  46289. XMEMSET(&hash, 0, sizeof(wc_HashAlg));
  46290. /* Success test with RSA certs/key */
  46291. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  46292. (word32)sizeof(data), 0, 0, 0, RSA_TYPE)), 0);
  46293. /* calculate hash for content, used later */
  46294. ExpectIntEQ(wc_HashInit(&hash, hashType), 0);
  46295. ExpectIntEQ(wc_HashUpdate(&hash, hashType, data, sizeof(data)), 0);
  46296. ExpectIntEQ(wc_HashFinal(&hash, hashType, hashBuf), 0);
  46297. DoExpectIntEQ(wc_HashFree(&hash, hashType), 0);
  46298. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46299. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  46300. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46301. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  46302. #ifndef NO_PKCS7_STREAM
  46303. wc_PKCS7_Free(pkcs7);
  46304. pkcs7 = NULL;
  46305. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46306. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46307. /* test for streaming */
  46308. ret = -1;
  46309. for (z = 0; z < outputSz && ret != 0; z++) {
  46310. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  46311. if (ret < 0){
  46312. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  46313. }
  46314. }
  46315. ExpectIntEQ(ret, 0);
  46316. ExpectIntNE(pkcs7->contentSz, 0);
  46317. ExpectNotNull(pkcs7->contentDynamic);
  46318. #endif /* !NO_PKCS7_STREAM */
  46319. /* Check that decoded signed attributes are correct */
  46320. /* messageDigest should be first */
  46321. if (pkcs7 != NULL) {
  46322. decodedAttrib = pkcs7->decodedAttrib;
  46323. }
  46324. ExpectNotNull(decodedAttrib);
  46325. ExpectIntEQ(decodedAttrib->oidSz, (word32)sizeof(messageDigestOid));
  46326. ExpectIntEQ(XMEMCMP(decodedAttrib->oid, messageDigestOid,
  46327. decodedAttrib->oidSz), 0);
  46328. /* + 2 for OCTET STRING and length bytes */
  46329. ExpectIntEQ(decodedAttrib->valueSz, hashSz + 2);
  46330. ExpectNotNull(decodedAttrib->value);
  46331. ExpectIntEQ(XMEMCMP(decodedAttrib->value + 2, hashBuf, hashSz), 0);
  46332. #ifndef NO_ASN_TIME
  46333. /* signingTime should be second */
  46334. if (decodedAttrib != NULL) {
  46335. decodedAttrib = decodedAttrib->next;
  46336. }
  46337. ExpectNotNull(decodedAttrib);
  46338. ExpectIntEQ(decodedAttrib->oidSz, (word32)sizeof(signingTimeOid));
  46339. ExpectIntEQ(XMEMCMP(decodedAttrib->oid, signingTimeOid,
  46340. decodedAttrib->oidSz), 0);
  46341. ExpectIntGT(decodedAttrib->valueSz, 0);
  46342. ExpectNotNull(decodedAttrib->value);
  46343. #endif
  46344. /* Verify signingTime if ASN and time are available */
  46345. #if !defined(NO_ASN) && !defined(NO_ASN_TIME)
  46346. ExpectIntEQ(wc_GetDateInfo(decodedAttrib->value, decodedAttrib->valueSz,
  46347. &datePart, &dateFormat, &dateLength), 0);
  46348. ExpectNotNull(datePart);
  46349. ExpectIntGT(dateLength, 0);
  46350. XMEMSET(&timearg, 0, sizeof(timearg));
  46351. ExpectIntEQ(wc_GetDateAsCalendarTime(datePart, dateLength, dateFormat,
  46352. &timearg), 0);
  46353. /* Get current time and compare year/month/day against attribute value */
  46354. ExpectIntEQ(wc_GetTime(&now, sizeof(now)), 0);
  46355. nowTm = (struct tm*)XGMTIME((time_t*)&now, tmpTime);
  46356. ExpectNotNull(nowTm);
  46357. ExpectIntEQ(timearg.tm_year, nowTm->tm_year);
  46358. ExpectIntEQ(timearg.tm_mon, nowTm->tm_mon);
  46359. ExpectIntEQ(timearg.tm_mday, nowTm->tm_mday);
  46360. #endif /* !NO_ASN && !NO_ASN_TIME */
  46361. /* contentType should be third */
  46362. if (decodedAttrib != NULL) {
  46363. decodedAttrib = decodedAttrib->next;
  46364. }
  46365. ExpectNotNull(decodedAttrib);
  46366. ExpectIntEQ(decodedAttrib->oidSz, (word32)sizeof(contentTypeOid));
  46367. ExpectIntEQ(XMEMCMP(decodedAttrib->oid, contentTypeOid,
  46368. decodedAttrib->oidSz), 0);
  46369. ExpectIntEQ(decodedAttrib->valueSz, (int)sizeof(dataType) + 2);
  46370. ExpectNotNull(decodedAttrib->value);
  46371. ExpectIntEQ(XMEMCMP(decodedAttrib->value + 2, dataType, sizeof(dataType)),
  46372. 0);
  46373. #endif /* !NO_RSA */
  46374. /* Test bad args. */
  46375. ExpectIntEQ(wc_PKCS7_VerifySignedData(NULL, output, outputSz),
  46376. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46377. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, NULL, outputSz),
  46378. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46379. #ifndef NO_PKCS7_STREAM
  46380. /* can pass in 0 buffer length with streaming API */
  46381. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, badOut,
  46382. badOutSz), WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  46383. #else
  46384. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, badOut,
  46385. badOutSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  46386. #endif
  46387. wc_PKCS7_Free(pkcs7);
  46388. pkcs7 = NULL;
  46389. #ifndef NO_RSA
  46390. /* Try RSA certs/key/sig first */
  46391. outputSz = sizeof(output);
  46392. XMEMSET(output, 0, outputSz);
  46393. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  46394. (word32)sizeof(data),
  46395. 1, 1, 0, RSA_TYPE)), 0);
  46396. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46397. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46398. if (pkcs7 != NULL) {
  46399. pkcs7->content = badContent;
  46400. pkcs7->contentSz = sizeof(badContent);
  46401. }
  46402. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz),
  46403. WC_NO_ERR_TRACE(SIG_VERIFY_E));
  46404. wc_PKCS7_Free(pkcs7);
  46405. pkcs7 = NULL;
  46406. #ifndef NO_PKCS7_STREAM
  46407. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46408. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46409. if (pkcs7 != NULL) {
  46410. pkcs7->content = badContent;
  46411. pkcs7->contentSz = sizeof(badContent);
  46412. }
  46413. /* test for streaming */
  46414. ret = -1;
  46415. for (z = 0; z < outputSz && ret != 0; z++) {
  46416. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  46417. if (ret == WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)){
  46418. continue;
  46419. }
  46420. else if (ret < 0) {
  46421. break;
  46422. }
  46423. }
  46424. ExpectIntEQ(ret, WC_NO_ERR_TRACE(SIG_VERIFY_E));
  46425. ExpectIntNE(pkcs7->contentSz, 0);
  46426. ExpectNotNull(pkcs7->contentDynamic);
  46427. wc_PKCS7_Free(pkcs7);
  46428. pkcs7 = NULL;
  46429. #endif /* !NO_PKCS7_STREAM */
  46430. /* Test success case with detached signature and valid content */
  46431. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46432. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46433. if (pkcs7 != NULL) {
  46434. pkcs7->content = data;
  46435. pkcs7->contentSz = sizeof(data);
  46436. }
  46437. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  46438. wc_PKCS7_Free(pkcs7);
  46439. pkcs7 = NULL;
  46440. #ifndef NO_PKCS7_STREAM
  46441. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46442. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46443. if (pkcs7 != NULL) {
  46444. pkcs7->content = data;
  46445. pkcs7->contentSz = sizeof(data);
  46446. }
  46447. /* test for streaming */
  46448. ret = -1;
  46449. for (z = 0; z < outputSz && ret != 0; z++) {
  46450. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  46451. if (ret < 0){
  46452. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  46453. }
  46454. }
  46455. ExpectIntEQ(ret, 0);
  46456. ExpectIntNE(pkcs7->contentSz, 0);
  46457. ExpectNotNull(pkcs7->contentDynamic);
  46458. wc_PKCS7_Free(pkcs7);
  46459. pkcs7 = NULL;
  46460. #endif /* !NO_PKCS7_STREAM */
  46461. /* verify using pre-computed content digest only (no content) */
  46462. {
  46463. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46464. ExpectIntEQ(wc_PKCS7_Init(pkcs7, NULL, 0), 0);
  46465. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  46466. output, outputSz, NULL, 0), 0);
  46467. wc_PKCS7_Free(pkcs7);
  46468. pkcs7 = NULL;
  46469. }
  46470. #endif /* !NO_RSA */
  46471. /* Test verify on signedData containing intermediate/root CA certs */
  46472. #ifndef NO_RSA
  46473. outputSz = sizeof(output);
  46474. XMEMSET(output, 0, outputSz);
  46475. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  46476. (word32)sizeof(data),
  46477. 0, 0, 1, RSA_TYPE)), 0);
  46478. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46479. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46480. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  46481. wc_PKCS7_Free(pkcs7);
  46482. pkcs7 = NULL;
  46483. #ifndef NO_PKCS7_STREAM
  46484. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46485. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46486. /* test for streaming */
  46487. ret = -1;
  46488. for (z = 0; z < outputSz && ret != 0; z++) {
  46489. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  46490. if (ret < 0){
  46491. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  46492. }
  46493. }
  46494. ExpectIntEQ(ret, 0);
  46495. ExpectIntNE(pkcs7->contentSz, 0);
  46496. ExpectNotNull(pkcs7->contentDynamic);
  46497. wc_PKCS7_Free(pkcs7);
  46498. pkcs7 = NULL;
  46499. #endif /* !NO_PKCS7_STREAM */
  46500. #endif /* !NO_RSA */
  46501. #if defined(ASN_BER_TO_DER) && !defined(NO_PKCS7_STREAM) && \
  46502. !defined(NO_FILESYSTEM)
  46503. {
  46504. XFILE signedBundle = XBADFILE;
  46505. int signedBundleSz = 0;
  46506. int chunkSz = 1;
  46507. int i, rc = 0;
  46508. byte* buf = NULL;
  46509. ExpectTrue((signedBundle = XFOPEN("./certs/test-stream-sign.p7b",
  46510. "rb")) != XBADFILE);
  46511. ExpectTrue(XFSEEK(signedBundle, 0, XSEEK_END) == 0);
  46512. ExpectIntGT(signedBundleSz = (int)XFTELL(signedBundle), 0);
  46513. ExpectTrue(XFSEEK(signedBundle, 0, XSEEK_SET) == 0);
  46514. ExpectNotNull(buf = (byte*)XMALLOC(signedBundleSz, HEAP_HINT,
  46515. DYNAMIC_TYPE_FILE));
  46516. if (buf != NULL) {
  46517. ExpectIntEQ(XFREAD(buf, 1, (size_t)signedBundleSz, signedBundle),
  46518. signedBundleSz);
  46519. }
  46520. if (signedBundle != XBADFILE) {
  46521. XFCLOSE(signedBundle);
  46522. signedBundle = XBADFILE;
  46523. }
  46524. if (buf != NULL) {
  46525. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46526. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46527. for (i = 0; i < signedBundleSz;) {
  46528. int sz = (i + chunkSz > signedBundleSz)? signedBundleSz - i :
  46529. chunkSz;
  46530. rc = wc_PKCS7_VerifySignedData(pkcs7, buf + i, (word32)sz);
  46531. if (rc < 0 ) {
  46532. if (rc == WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)) {
  46533. i += sz;
  46534. continue;
  46535. }
  46536. break;
  46537. }
  46538. else {
  46539. break;
  46540. }
  46541. }
  46542. ExpectIntEQ(rc, WC_NO_ERR_TRACE(PKCS7_SIGNEEDS_CHECK));
  46543. wc_PKCS7_Free(pkcs7);
  46544. pkcs7 = NULL;
  46545. }
  46546. /* now try with malformed bundle */
  46547. if (buf != NULL) {
  46548. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46549. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46550. buf[signedBundleSz - 2] = buf[signedBundleSz - 2] + 1;
  46551. for (i = 0; i < signedBundleSz;) {
  46552. int sz = (i + chunkSz > signedBundleSz)? signedBundleSz - i :
  46553. chunkSz;
  46554. rc = wc_PKCS7_VerifySignedData(pkcs7, buf + i, (word32)sz);
  46555. if (rc < 0 ) {
  46556. if (rc == WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)) {
  46557. i += sz;
  46558. continue;
  46559. }
  46560. break;
  46561. }
  46562. else {
  46563. break;
  46564. }
  46565. }
  46566. ExpectIntEQ(rc, WC_NO_ERR_TRACE(ASN_PARSE_E));
  46567. wc_PKCS7_Free(pkcs7);
  46568. pkcs7 = NULL;
  46569. }
  46570. if (buf != NULL)
  46571. XFREE(buf, HEAP_HINT, DYNAMIC_TYPE_FILE);
  46572. }
  46573. #endif /* BER and stream */
  46574. #endif
  46575. return EXPECT_RESULT();
  46576. } /* END test_wc_PKCS7_VerifySignedData()_RSA */
  46577. /*
  46578. * Testing wc_PKCS_VerifySignedData()
  46579. */
  46580. static int test_wc_PKCS7_VerifySignedData_ECC(void)
  46581. {
  46582. EXPECT_DECLS;
  46583. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && defined(HAVE_ECC)
  46584. PKCS7* pkcs7 = NULL;
  46585. byte output[6000]; /* Large size needed for bundles with int CA certs */
  46586. word32 outputSz = sizeof(output);
  46587. byte data[] = "Test data to encode.";
  46588. byte badContent[] = "This is different content than was signed";
  46589. wc_HashAlg hash;
  46590. #ifndef NO_PKCS7_STREAM
  46591. word32 z;
  46592. int ret;
  46593. #endif /* !NO_PKCS7_STREAM */
  46594. #ifdef NO_SHA
  46595. enum wc_HashType hashType = WC_HASH_TYPE_SHA256;
  46596. #else
  46597. enum wc_HashType hashType = WC_HASH_TYPE_SHA;
  46598. #endif
  46599. byte hashBuf[WC_MAX_DIGEST_SIZE];
  46600. word32 hashSz = (word32)wc_HashGetDigestSize(hashType);
  46601. XMEMSET(&hash, 0, sizeof(wc_HashAlg));
  46602. /* Success test with ECC certs/key */
  46603. outputSz = sizeof(output);
  46604. XMEMSET(output, 0, outputSz);
  46605. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  46606. (word32)sizeof(data), 0, 0, 0, ECC_TYPE)), 0);
  46607. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46608. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  46609. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46610. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  46611. wc_PKCS7_Free(pkcs7);
  46612. pkcs7 = NULL;
  46613. #ifndef NO_PKCS7_STREAM
  46614. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46615. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46616. /* test for streaming */
  46617. ret = -1;
  46618. for (z = 0; z < outputSz && ret != 0; z++) {
  46619. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  46620. if (ret < 0){
  46621. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  46622. }
  46623. }
  46624. ExpectIntEQ(ret, 0);
  46625. ExpectIntNE(pkcs7->contentSz, 0);
  46626. ExpectNotNull(pkcs7->contentDynamic);
  46627. wc_PKCS7_Free(pkcs7);
  46628. pkcs7 = NULL;
  46629. #endif /* !NO_PKCS7_STREAM */
  46630. /* Invalid content should error, use detached signature so we can
  46631. * easily change content */
  46632. outputSz = sizeof(output);
  46633. XMEMSET(output, 0, outputSz);
  46634. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  46635. (word32)sizeof(data), 1, 1, 0, ECC_TYPE)), 0);
  46636. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46637. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46638. if (pkcs7 != NULL) {
  46639. pkcs7->content = badContent;
  46640. pkcs7->contentSz = sizeof(badContent);
  46641. }
  46642. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz),
  46643. WC_NO_ERR_TRACE(SIG_VERIFY_E));
  46644. wc_PKCS7_Free(pkcs7);
  46645. pkcs7 = NULL;
  46646. #ifndef NO_PKCS7_STREAM
  46647. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46648. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46649. if (pkcs7 != NULL) {
  46650. pkcs7->content = badContent;
  46651. pkcs7->contentSz = sizeof(badContent);
  46652. }
  46653. /* test for streaming */
  46654. ret = -1;
  46655. for (z = 0; z < outputSz && ret != 0; z++) {
  46656. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  46657. if (ret == WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)){
  46658. continue;
  46659. }
  46660. else if (ret < 0) {
  46661. break;
  46662. }
  46663. }
  46664. ExpectIntEQ(ret, WC_NO_ERR_TRACE(SIG_VERIFY_E));
  46665. ExpectIntNE(pkcs7->contentSz, 0);
  46666. ExpectNotNull(pkcs7->contentDynamic);
  46667. wc_PKCS7_Free(pkcs7);
  46668. pkcs7 = NULL;
  46669. #endif /* !NO_PKCS7_STREAM */
  46670. /* Test success case with detached signature and valid content */
  46671. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46672. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46673. if (pkcs7 != NULL) {
  46674. pkcs7->content = data;
  46675. pkcs7->contentSz = sizeof(data);
  46676. }
  46677. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  46678. wc_PKCS7_Free(pkcs7);
  46679. pkcs7 = NULL;
  46680. #ifndef NO_PKCS7_STREAM
  46681. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46682. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46683. if (pkcs7 != NULL) {
  46684. pkcs7->content = data;
  46685. pkcs7->contentSz = sizeof(data);
  46686. }
  46687. /* test for streaming */
  46688. ret = -1;
  46689. for (z = 0; z < outputSz && ret != 0; z++) {
  46690. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  46691. if (ret < 0){
  46692. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  46693. }
  46694. }
  46695. ExpectIntEQ(ret, 0);
  46696. ExpectIntNE(pkcs7->contentSz, 0);
  46697. ExpectNotNull(pkcs7->contentDynamic);
  46698. wc_PKCS7_Free(pkcs7);
  46699. pkcs7 = NULL;
  46700. #endif /* !NO_PKCS7_STREAM */
  46701. /* verify using pre-computed content digest only (no content) */
  46702. {
  46703. /* calculate hash for content */
  46704. ExpectIntEQ(wc_HashInit(&hash, hashType), 0);
  46705. ExpectIntEQ(wc_HashUpdate(&hash, hashType, data, sizeof(data)), 0);
  46706. ExpectIntEQ(wc_HashFinal(&hash, hashType, hashBuf), 0);
  46707. ExpectIntEQ(wc_HashFree(&hash, hashType), 0);
  46708. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46709. ExpectIntEQ(wc_PKCS7_Init(pkcs7, NULL, 0), 0);
  46710. ExpectIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
  46711. output, outputSz, NULL, 0), 0);
  46712. wc_PKCS7_Free(pkcs7);
  46713. pkcs7 = NULL;
  46714. }
  46715. /* Test verify on signedData containing intermediate/root CA certs */
  46716. outputSz = sizeof(output);
  46717. XMEMSET(output, 0, outputSz);
  46718. ExpectIntGT((outputSz = (word32)CreatePKCS7SignedData(output, (int)outputSz, data,
  46719. (word32)sizeof(data), 0, 0, 1, ECC_TYPE)), 0);
  46720. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46721. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46722. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, output, outputSz), 0);
  46723. wc_PKCS7_Free(pkcs7);
  46724. pkcs7 = NULL;
  46725. #ifndef NO_PKCS7_STREAM
  46726. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  46727. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  46728. /* test for streaming */
  46729. ret = -1;
  46730. for (z = 0; z < outputSz && ret != 0; z++) {
  46731. ret = wc_PKCS7_VerifySignedData(pkcs7, output + z, 1);
  46732. if (ret < 0){
  46733. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  46734. }
  46735. }
  46736. ExpectIntEQ(ret, 0);
  46737. ExpectIntNE(pkcs7->contentSz, 0);
  46738. ExpectNotNull(pkcs7->contentDynamic);
  46739. wc_PKCS7_Free(pkcs7);
  46740. pkcs7 = NULL;
  46741. #endif /* !NO_PKCS7_STREAM */
  46742. #endif
  46743. return EXPECT_RESULT();
  46744. } /* END test_wc_PKCS7_VerifySignedData_ECC() */
  46745. #if defined(HAVE_PKCS7) && !defined(NO_AES) && defined(HAVE_AES_CBC) && \
  46746. !defined(NO_AES_256)
  46747. static const byte defKey[] = {
  46748. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46749. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46750. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46751. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  46752. };
  46753. static byte aesHandle[32]; /* simulated hardware key handle */
  46754. /* return 0 on success */
  46755. static int myDecryptionFunc(PKCS7* pkcs7, int encryptOID, byte* iv, int ivSz,
  46756. byte* aad, word32 aadSz, byte* authTag, word32 authTagSz,
  46757. byte* in, int inSz, byte* out, void* usrCtx)
  46758. {
  46759. int ret;
  46760. Aes aes;
  46761. if (usrCtx == NULL) {
  46762. /* no simulated handle passed in */
  46763. return -1;
  46764. }
  46765. switch (encryptOID) {
  46766. case AES256CBCb:
  46767. if (ivSz != AES_BLOCK_SIZE)
  46768. return BAD_FUNC_ARG;
  46769. break;
  46770. default:
  46771. WOLFSSL_MSG("Unsupported content cipher type for test");
  46772. return ALGO_ID_E;
  46773. };
  46774. /* simulate using handle to get key */
  46775. ret = wc_AesInit(&aes, HEAP_HINT, INVALID_DEVID);
  46776. if (ret == 0) {
  46777. ret = wc_AesSetKey(&aes, (byte*)usrCtx, 32, iv, AES_DECRYPTION);
  46778. if (ret == 0)
  46779. ret = wc_AesCbcDecrypt(&aes, out, in, (word32)inSz);
  46780. wc_AesFree(&aes);
  46781. }
  46782. (void)aad;
  46783. (void)aadSz;
  46784. (void)authTag;
  46785. (void)authTagSz;
  46786. (void)pkcs7;
  46787. return ret;
  46788. }
  46789. /* returns key size on success */
  46790. static int myCEKwrapFunc(PKCS7* pkcs7, byte* cek, word32 cekSz, byte* keyId,
  46791. word32 keyIdSz, byte* orginKey, word32 orginKeySz,
  46792. byte* out, word32 outSz, int keyWrapAlgo, int type, int direction)
  46793. {
  46794. int ret = -1;
  46795. (void)cekSz;
  46796. (void)cek;
  46797. (void)outSz;
  46798. (void)keyIdSz;
  46799. (void)direction;
  46800. (void)orginKey; /* used with KAKRI */
  46801. (void)orginKeySz;
  46802. if (out == NULL)
  46803. return BAD_FUNC_ARG;
  46804. if (keyId[0] != 0x00) {
  46805. return -1;
  46806. }
  46807. if (type != (int)PKCS7_KEKRI) {
  46808. return -1;
  46809. }
  46810. switch (keyWrapAlgo) {
  46811. case AES256_WRAP:
  46812. /* simulate setting a handle for later decryption but use key
  46813. * as handle in the test case here */
  46814. ret = wc_AesKeyUnWrap(defKey, sizeof(defKey), cek, cekSz,
  46815. aesHandle, sizeof(aesHandle), NULL);
  46816. if (ret < 0)
  46817. return ret;
  46818. ret = wc_PKCS7_SetDecodeEncryptedCtx(pkcs7, (void*)aesHandle);
  46819. if (ret < 0)
  46820. return ret;
  46821. /* return key size on success */
  46822. return sizeof(defKey);
  46823. default:
  46824. WOLFSSL_MSG("Unsupported key wrap algorithm in example");
  46825. return BAD_KEYWRAP_ALG_E;
  46826. };
  46827. }
  46828. #endif /* HAVE_PKCS7 && !NO_AES && HAVE_AES_CBC && !NO_AES_256 */
  46829. /*
  46830. * Testing wc_PKCS7_EncodeEnvelopedData()
  46831. */
  46832. static int test_wc_PKCS7_EncodeDecodeEnvelopedData(void)
  46833. {
  46834. EXPECT_DECLS;
  46835. #if defined(HAVE_PKCS7)
  46836. PKCS7* pkcs7 = NULL;
  46837. #ifdef ASN_BER_TO_DER
  46838. int encodedSz = 0;
  46839. #endif
  46840. #ifdef ECC_TIMING_RESISTANT
  46841. WC_RNG rng;
  46842. #endif
  46843. word32 tempWrd32 = 0;
  46844. byte* tmpBytePtr = NULL;
  46845. const char input[] = "Test data to encode.";
  46846. int i;
  46847. int testSz = 0;
  46848. #if !defined(NO_RSA) && (!defined(NO_AES) || (!defined(NO_SHA) || \
  46849. !defined(NO_SHA256) || defined(WOLFSSL_SHA512)))
  46850. byte* rsaCert = NULL;
  46851. byte* rsaPrivKey = NULL;
  46852. word32 rsaCertSz;
  46853. word32 rsaPrivKeySz;
  46854. #if !defined(NO_FILESYSTEM) && (!defined(USE_CERT_BUFFERS_1024) && \
  46855. !defined(USE_CERT_BUFFERS_2048) )
  46856. static const char* rsaClientCert = "./certs/client-cert.der";
  46857. static const char* rsaClientKey = "./certs/client-key.der";
  46858. rsaCertSz = (word32)sizeof(rsaClientCert);
  46859. rsaPrivKeySz = (word32)sizeof(rsaClientKey);
  46860. #endif
  46861. #endif
  46862. #if defined(HAVE_ECC) && (!defined(NO_AES) || (!defined(NO_SHA) ||\
  46863. !defined(NO_SHA256) || defined(WOLFSSL_SHA512)))
  46864. byte* eccCert = NULL;
  46865. byte* eccPrivKey = NULL;
  46866. word32 eccCertSz;
  46867. word32 eccPrivKeySz;
  46868. #if !defined(NO_FILESYSTEM) && !defined(USE_CERT_BUFFERS_256)
  46869. static const char* eccClientCert = "./certs/client-ecc-cert.der";
  46870. static const char* eccClientKey = "./certs/ecc-client-key.der";
  46871. #endif
  46872. #endif
  46873. /* Generic buffer size. */
  46874. byte output[ONEK_BUF];
  46875. byte decoded[sizeof(input)/sizeof(char)];
  46876. int decodedSz = 0;
  46877. #ifndef NO_FILESYSTEM
  46878. XFILE certFile = XBADFILE;
  46879. XFILE keyFile = XBADFILE;
  46880. #endif
  46881. #ifdef ECC_TIMING_RESISTANT
  46882. XMEMSET(&rng, 0, sizeof(WC_RNG));
  46883. #endif
  46884. #if !defined(NO_RSA) && (!defined(NO_AES) || (!defined(NO_SHA) ||\
  46885. !defined(NO_SHA256) || defined(WOLFSSL_SHA512)))
  46886. /* RSA certs and keys. */
  46887. #if defined(USE_CERT_BUFFERS_1024)
  46888. rsaCertSz = (word32)sizeof_client_cert_der_1024;
  46889. /* Allocate buffer space. */
  46890. ExpectNotNull(rsaCert = (byte*)XMALLOC(rsaCertSz, HEAP_HINT,
  46891. DYNAMIC_TYPE_TMP_BUFFER));
  46892. /* Init buffer. */
  46893. if (rsaCert != NULL) {
  46894. XMEMCPY(rsaCert, client_cert_der_1024, rsaCertSz);
  46895. }
  46896. rsaPrivKeySz = (word32)sizeof_client_key_der_1024;
  46897. ExpectNotNull(rsaPrivKey = (byte*)XMALLOC(rsaPrivKeySz, HEAP_HINT,
  46898. DYNAMIC_TYPE_TMP_BUFFER));
  46899. if (rsaPrivKey != NULL) {
  46900. XMEMCPY(rsaPrivKey, client_key_der_1024, rsaPrivKeySz);
  46901. }
  46902. #elif defined(USE_CERT_BUFFERS_2048)
  46903. rsaCertSz = (word32)sizeof_client_cert_der_2048;
  46904. /* Allocate buffer */
  46905. ExpectNotNull(rsaCert = (byte*)XMALLOC(rsaCertSz, HEAP_HINT,
  46906. DYNAMIC_TYPE_TMP_BUFFER));
  46907. /* Init buffer. */
  46908. if (rsaCert != NULL) {
  46909. XMEMCPY(rsaCert, client_cert_der_2048, rsaCertSz);
  46910. }
  46911. rsaPrivKeySz = (word32)sizeof_client_key_der_2048;
  46912. ExpectNotNull(rsaPrivKey = (byte*)XMALLOC(rsaPrivKeySz, HEAP_HINT,
  46913. DYNAMIC_TYPE_TMP_BUFFER));
  46914. if (rsaPrivKey != NULL) {
  46915. XMEMCPY(rsaPrivKey, client_key_der_2048, rsaPrivKeySz);
  46916. }
  46917. #else
  46918. /* File system. */
  46919. ExpectTrue((certFile = XFOPEN(rsaClientCert, "rb")) != XBADFILE);
  46920. rsaCertSz = (word32)FOURK_BUF;
  46921. ExpectNotNull(rsaCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  46922. DYNAMIC_TYPE_TMP_BUFFER));
  46923. ExpectTrue((rsaCertSz = (word32)XFREAD(rsaCert, 1, rsaCertSz,
  46924. certFile)) > 0);
  46925. if (certFile != XBADFILE)
  46926. XFCLOSE(certFile);
  46927. ExpectTrue((keyFile = XFOPEN(rsaClientKey, "rb")) != XBADFILE);
  46928. ExpectNotNull(rsaPrivKey = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  46929. DYNAMIC_TYPE_TMP_BUFFER));
  46930. rsaPrivKeySz = (word32)FOURK_BUF;
  46931. ExpectTrue((rsaPrivKeySz = (word32)XFREAD(rsaPrivKey, 1, rsaPrivKeySz,
  46932. keyFile)) > 0);
  46933. if (keyFile != XBADFILE)
  46934. XFCLOSE(keyFile);
  46935. #endif /* USE_CERT_BUFFERS */
  46936. #endif /* NO_RSA */
  46937. /* ECC */
  46938. #if defined(HAVE_ECC) && (!defined(NO_AES) || (!defined(NO_SHA) ||\
  46939. !defined(NO_SHA256) || defined(WOLFSSL_SHA512)))
  46940. #ifdef USE_CERT_BUFFERS_256
  46941. ExpectNotNull(eccCert = (byte*)XMALLOC(TWOK_BUF, HEAP_HINT,
  46942. DYNAMIC_TYPE_TMP_BUFFER));
  46943. /* Init buffer. */
  46944. eccCertSz = (word32)sizeof_cliecc_cert_der_256;
  46945. if (eccCert != NULL) {
  46946. XMEMCPY(eccCert, cliecc_cert_der_256, eccCertSz);
  46947. }
  46948. ExpectNotNull(eccPrivKey = (byte*)XMALLOC(TWOK_BUF, HEAP_HINT,
  46949. DYNAMIC_TYPE_TMP_BUFFER));
  46950. eccPrivKeySz = (word32)sizeof_ecc_clikey_der_256;
  46951. if (eccPrivKey != NULL) {
  46952. XMEMCPY(eccPrivKey, ecc_clikey_der_256, eccPrivKeySz);
  46953. }
  46954. #else /* File system. */
  46955. ExpectTrue((certFile = XFOPEN(eccClientCert, "rb")) != XBADFILE);
  46956. eccCertSz = (word32)FOURK_BUF;
  46957. ExpectNotNull(eccCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  46958. DYNAMIC_TYPE_TMP_BUFFER));
  46959. ExpectTrue((eccCertSz = (word32)XFREAD(eccCert, 1, eccCertSz,
  46960. certFile)) > 0);
  46961. if (certFile != XBADFILE) {
  46962. XFCLOSE(certFile);
  46963. }
  46964. ExpectTrue((keyFile = XFOPEN(eccClientKey, "rb")) != XBADFILE);
  46965. eccPrivKeySz = (word32)FOURK_BUF;
  46966. ExpectNotNull(eccPrivKey = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  46967. DYNAMIC_TYPE_TMP_BUFFER));
  46968. ExpectTrue((eccPrivKeySz = (word32)XFREAD(eccPrivKey, 1, eccPrivKeySz,
  46969. keyFile)) > 0);
  46970. if (keyFile != XBADFILE) {
  46971. XFCLOSE(keyFile);
  46972. }
  46973. #endif /* USE_CERT_BUFFERS_256 */
  46974. #endif /* END HAVE_ECC */
  46975. #ifndef NO_FILESYSTEM
  46976. /* Silence. */
  46977. (void)keyFile;
  46978. (void)certFile;
  46979. #endif
  46980. {
  46981. const pkcs7EnvelopedVector testVectors[] = {
  46982. /* DATA is a global variable defined in the makefile. */
  46983. #if !defined(NO_RSA)
  46984. #ifndef NO_DES3
  46985. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA, DES3b, 0, 0,
  46986. rsaCert, rsaCertSz, rsaPrivKey, rsaPrivKeySz},
  46987. #endif /* NO_DES3 */
  46988. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  46989. #ifndef NO_AES_128
  46990. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA, AES128CBCb,
  46991. 0, 0, rsaCert, rsaCertSz, rsaPrivKey, rsaPrivKeySz},
  46992. #endif
  46993. #ifndef NO_AES_192
  46994. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA, AES192CBCb,
  46995. 0, 0, rsaCert, rsaCertSz, rsaPrivKey, rsaPrivKeySz},
  46996. #endif
  46997. #ifndef NO_AES_256
  46998. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA, AES256CBCb,
  46999. 0, 0, rsaCert, rsaCertSz, rsaPrivKey, rsaPrivKeySz},
  47000. #endif
  47001. #endif /* NO_AES && HAVE_AES_CBC */
  47002. #endif /* NO_RSA */
  47003. #if defined(HAVE_ECC)
  47004. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  47005. #if !defined(NO_SHA) && !defined(NO_AES_128)
  47006. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA,
  47007. AES128CBCb, AES128_WRAP, dhSinglePass_stdDH_sha1kdf_scheme,
  47008. eccCert, eccCertSz, eccPrivKey, eccPrivKeySz},
  47009. #endif
  47010. #if !defined(NO_SHA256) && !defined(NO_AES_256)
  47011. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA,
  47012. AES256CBCb, AES256_WRAP, dhSinglePass_stdDH_sha256kdf_scheme,
  47013. eccCert, eccCertSz, eccPrivKey, eccPrivKeySz},
  47014. #endif
  47015. #if defined(WOLFSSL_SHA512) && !defined(NO_AES_256)
  47016. {(byte*)input, (word32)(sizeof(input)/sizeof(char)), DATA,
  47017. AES256CBCb, AES256_WRAP, dhSinglePass_stdDH_sha512kdf_scheme,
  47018. eccCert, eccCertSz, eccPrivKey, eccPrivKeySz},
  47019. #endif
  47020. #endif /* NO_AES && HAVE_AES_CBC*/
  47021. #endif /* END HAVE_ECC */
  47022. }; /* END pkcs7EnvelopedVector */
  47023. #ifdef ECC_TIMING_RESISTANT
  47024. ExpectIntEQ(wc_InitRng(&rng), 0);
  47025. #endif
  47026. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47027. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, testDevId), 0);
  47028. testSz = (int)sizeof(testVectors)/(int)sizeof(pkcs7EnvelopedVector);
  47029. for (i = 0; i < testSz; i++) {
  47030. #ifdef ASN_BER_TO_DER
  47031. encodeSignedDataStream strm;
  47032. /* test setting stream mode, the first one using IO callbacks */
  47033. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (testVectors + i)->cert,
  47034. (word32)(testVectors + i)->certSz), 0);
  47035. if (pkcs7 != NULL) {
  47036. #ifdef ECC_TIMING_RESISTANT
  47037. pkcs7->rng = &rng;
  47038. #endif
  47039. if (i != 0)
  47040. pkcs7->content = (byte*)(testVectors + i)->content;
  47041. pkcs7->contentSz = (testVectors + i)->contentSz;
  47042. pkcs7->contentOID = (testVectors + i)->contentOID;
  47043. pkcs7->encryptOID = (testVectors + i)->encryptOID;
  47044. pkcs7->keyWrapOID = (testVectors + i)->keyWrapOID;
  47045. pkcs7->keyAgreeOID = (testVectors + i)->keyAgreeOID;
  47046. pkcs7->privateKey = (testVectors + i)->privateKey;
  47047. pkcs7->privateKeySz = (testVectors + i)->privateKeySz;
  47048. }
  47049. if (i == 0) {
  47050. XMEMSET(&strm, 0, sizeof(strm));
  47051. ExpectIntEQ(wc_PKCS7_SetStreamMode(pkcs7, 1, GetContentCB,
  47052. StreamOutputCB, (void*)&strm), 0);
  47053. encodedSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, NULL, 0);
  47054. }
  47055. else {
  47056. ExpectIntEQ(wc_PKCS7_SetStreamMode(pkcs7, 1, NULL, NULL, NULL), 0);
  47057. encodedSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, output,
  47058. (word32)sizeof(output));
  47059. }
  47060. switch ((testVectors + i)->encryptOID) {
  47061. #ifndef NO_DES3
  47062. case DES3b:
  47063. case DESb:
  47064. ExpectIntEQ(encodedSz, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47065. break;
  47066. #endif
  47067. #ifdef HAVE_AESCCM
  47068. #ifdef WOLFSSL_AES_128
  47069. case AES128CCMb:
  47070. ExpectIntEQ(encodedSz, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47071. break;
  47072. #endif
  47073. #ifdef WOLFSSL_AES_192
  47074. case AES192CCMb:
  47075. ExpectIntEQ(encodedSz, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47076. break;
  47077. #endif
  47078. #ifdef WOLFSSL_AES_256
  47079. case AES256CCMb:
  47080. ExpectIntEQ(encodedSz, WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47081. break;
  47082. #endif
  47083. #endif
  47084. default:
  47085. ExpectIntGE(encodedSz, 0);
  47086. }
  47087. if (encodedSz > 0) {
  47088. if (i == 0) {
  47089. decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7,
  47090. strm.out, (word32)encodedSz, decoded,
  47091. (word32)sizeof(decoded));
  47092. }
  47093. else {
  47094. decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  47095. (word32)encodedSz, decoded, (word32)sizeof(decoded));
  47096. }
  47097. ExpectIntGE(decodedSz, 0);
  47098. /* Verify the size of each buffer. */
  47099. ExpectIntEQ((word32)sizeof(input)/sizeof(char), decodedSz);
  47100. }
  47101. wc_PKCS7_Free(pkcs7);
  47102. pkcs7 = NULL;
  47103. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47104. #endif
  47105. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (testVectors + i)->cert,
  47106. (word32)(testVectors + i)->certSz), 0);
  47107. if (pkcs7 != NULL) {
  47108. #ifdef ECC_TIMING_RESISTANT
  47109. pkcs7->rng = &rng;
  47110. #endif
  47111. pkcs7->content = (byte*)(testVectors + i)->content;
  47112. pkcs7->contentSz = (testVectors + i)->contentSz;
  47113. pkcs7->contentOID = (testVectors + i)->contentOID;
  47114. pkcs7->encryptOID = (testVectors + i)->encryptOID;
  47115. pkcs7->keyWrapOID = (testVectors + i)->keyWrapOID;
  47116. pkcs7->keyAgreeOID = (testVectors + i)->keyAgreeOID;
  47117. pkcs7->privateKey = (testVectors + i)->privateKey;
  47118. pkcs7->privateKeySz = (testVectors + i)->privateKeySz;
  47119. }
  47120. #ifdef ASN_BER_TO_DER
  47121. /* test without setting stream mode */
  47122. ExpectIntEQ(wc_PKCS7_GetStreamMode(pkcs7), 0);
  47123. #endif
  47124. ExpectIntGE(wc_PKCS7_EncodeEnvelopedData(pkcs7, output,
  47125. (word32)sizeof(output)), 0);
  47126. decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  47127. (word32)sizeof(output), decoded, (word32)sizeof(decoded));
  47128. ExpectIntGE(decodedSz, 0);
  47129. /* Verify the size of each buffer. */
  47130. ExpectIntEQ((word32)sizeof(input)/sizeof(char), decodedSz);
  47131. /* Don't free the last time through the loop. */
  47132. if (i < testSz - 1) {
  47133. wc_PKCS7_Free(pkcs7);
  47134. pkcs7 = NULL;
  47135. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47136. }
  47137. } /* END test loop. */
  47138. }
  47139. /* Test bad args. */
  47140. ExpectIntEQ(wc_PKCS7_EncodeEnvelopedData(NULL, output,
  47141. (word32)sizeof(output)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47142. ExpectIntEQ(wc_PKCS7_EncodeEnvelopedData(pkcs7, NULL,
  47143. (word32)sizeof(output)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47144. ExpectIntEQ(wc_PKCS7_EncodeEnvelopedData(pkcs7, output, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47145. /* Decode. */
  47146. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(NULL, output,
  47147. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  47148. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47149. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  47150. (word32)sizeof(output), NULL, (word32)sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47151. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  47152. (word32)sizeof(output), decoded, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47153. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, NULL,
  47154. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  47155. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47156. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output, 0, decoded,
  47157. (word32)sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47158. /* Should get a return of BAD_FUNC_ARG with structure data. Order matters.*/
  47159. #if defined(HAVE_ECC) && !defined(NO_AES) && defined(HAVE_AES_CBC)
  47160. /* only a failure for KARI test cases */
  47161. if (pkcs7 != NULL) {
  47162. tempWrd32 = pkcs7->singleCertSz;
  47163. pkcs7->singleCertSz = 0;
  47164. }
  47165. #if defined(WOLFSSL_ASN_TEMPLATE)
  47166. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  47167. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  47168. WC_NO_ERR_TRACE(BUFFER_E));
  47169. #else
  47170. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  47171. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  47172. WC_NO_ERR_TRACE(ASN_PARSE_E));
  47173. #endif
  47174. if (pkcs7 != NULL) {
  47175. pkcs7->singleCertSz = tempWrd32;
  47176. tmpBytePtr = pkcs7->singleCert;
  47177. pkcs7->singleCert = NULL;
  47178. }
  47179. #ifndef NO_RSA
  47180. #if defined(NO_PKCS7_STREAM)
  47181. /* when none streaming mode is used and PKCS7 is in bad state buffer error
  47182. * is returned from kari parse which gets set to bad func arg */
  47183. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  47184. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  47185. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47186. #else
  47187. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  47188. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  47189. WC_NO_ERR_TRACE(ASN_PARSE_E));
  47190. #endif
  47191. #endif /* !NO_RSA */
  47192. if (pkcs7 != NULL) {
  47193. pkcs7->singleCert = tmpBytePtr;
  47194. }
  47195. #endif
  47196. if (pkcs7 != NULL) {
  47197. tempWrd32 = pkcs7->privateKeySz;
  47198. pkcs7->privateKeySz = 0;
  47199. }
  47200. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  47201. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  47202. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47203. if (pkcs7 != NULL) {
  47204. pkcs7->privateKeySz = tempWrd32;
  47205. tmpBytePtr = pkcs7->privateKey;
  47206. pkcs7->privateKey = NULL;
  47207. }
  47208. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  47209. (word32)sizeof(output), decoded, (word32)sizeof(decoded)),
  47210. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47211. if (pkcs7 != NULL) {
  47212. pkcs7->privateKey = tmpBytePtr;
  47213. }
  47214. wc_PKCS7_Free(pkcs7);
  47215. pkcs7 = NULL;
  47216. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && !defined(NO_AES_256)
  47217. /* test of decrypt callback with KEKRI enveloped data */
  47218. {
  47219. int envelopedSz = 0;
  47220. const byte keyId[] = { 0x00 };
  47221. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47222. if (pkcs7 != NULL) {
  47223. pkcs7->content = (byte*)input;
  47224. pkcs7->contentSz = (word32)(sizeof(input)/sizeof(char));
  47225. pkcs7->contentOID = DATA;
  47226. pkcs7->encryptOID = AES256CBCb;
  47227. }
  47228. ExpectIntGT(wc_PKCS7_AddRecipient_KEKRI(pkcs7, AES256_WRAP,
  47229. (byte*)defKey, sizeof(defKey), (byte*)keyId,
  47230. sizeof(keyId), NULL, NULL, 0, NULL, 0, 0), 0);
  47231. ExpectIntEQ(wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID), 0);
  47232. ExpectIntGT((envelopedSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, output,
  47233. (word32)sizeof(output))), 0);
  47234. wc_PKCS7_Free(pkcs7);
  47235. pkcs7 = NULL;
  47236. /* decode envelopedData */
  47237. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47238. ExpectIntEQ(wc_PKCS7_SetWrapCEKCb(pkcs7, myCEKwrapFunc), 0);
  47239. ExpectIntEQ(wc_PKCS7_SetDecodeEncryptedCb(pkcs7, myDecryptionFunc), 0);
  47240. ExpectIntGT((decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, output,
  47241. (word32)envelopedSz, decoded, sizeof(decoded))), 0);
  47242. wc_PKCS7_Free(pkcs7);
  47243. pkcs7 = NULL;
  47244. }
  47245. #endif /* !NO_AES && !NO_AES_256 */
  47246. #ifndef NO_RSA
  47247. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47248. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47249. #endif /* NO_RSA */
  47250. #ifdef HAVE_ECC
  47251. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47252. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47253. #endif /* HAVE_ECC */
  47254. #ifdef ECC_TIMING_RESISTANT
  47255. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  47256. #endif
  47257. #if defined(USE_CERT_BUFFERS_2048) && !defined(NO_DES3) && \
  47258. !defined(NO_RSA) && !defined(NO_SHA)
  47259. {
  47260. byte out[7];
  47261. byte *cms = NULL;
  47262. word32 cmsSz;
  47263. XFILE cmsFile = XBADFILE;
  47264. XMEMSET(out, 0, sizeof(out));
  47265. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47266. ExpectTrue((cmsFile = XFOPEN("./certs/test/ktri-keyid-cms.msg", "rb"))
  47267. != XBADFILE);
  47268. cmsSz = (word32)FOURK_BUF;
  47269. ExpectNotNull(cms = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  47270. DYNAMIC_TYPE_TMP_BUFFER));
  47271. ExpectTrue((cmsSz = (word32)XFREAD(cms, 1, cmsSz, cmsFile)) > 0);
  47272. if (cmsFile != XBADFILE)
  47273. XFCLOSE(cmsFile);
  47274. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (byte*)client_cert_der_2048,
  47275. sizeof_client_cert_der_2048), 0);
  47276. if (pkcs7 != NULL) {
  47277. pkcs7->privateKey = (byte*)client_key_der_2048;
  47278. pkcs7->privateKeySz = sizeof_client_key_der_2048;
  47279. }
  47280. ExpectIntLT(wc_PKCS7_DecodeEnvelopedData(pkcs7, cms, cmsSz, out,
  47281. 2), 0);
  47282. ExpectIntGT(wc_PKCS7_DecodeEnvelopedData(pkcs7, cms, cmsSz, out,
  47283. sizeof(out)), 0);
  47284. XFREE(cms, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47285. ExpectIntEQ(XMEMCMP(out, "test", 4), 0);
  47286. wc_PKCS7_Free(pkcs7);
  47287. pkcs7 = NULL;
  47288. }
  47289. #endif /* USE_CERT_BUFFERS_2048 && !NO_DES3 && !NO_RSA && !NO_SHA */
  47290. #endif /* HAVE_PKCS7 */
  47291. return EXPECT_RESULT();
  47292. } /* END test_wc_PKCS7_EncodeDecodeEnvelopedData() */
  47293. /*
  47294. * Testing wc_PKCS7_EncodeEncryptedData()
  47295. */
  47296. static int test_wc_PKCS7_EncodeEncryptedData(void)
  47297. {
  47298. EXPECT_DECLS;
  47299. #if defined(HAVE_PKCS7) && !defined(NO_PKCS7_ENCRYPTED_DATA)
  47300. PKCS7* pkcs7 = NULL;
  47301. byte* tmpBytePtr = NULL;
  47302. byte encrypted[TWOK_BUF];
  47303. byte decoded[TWOK_BUF];
  47304. word32 tmpWrd32 = 0;
  47305. int tmpInt = 0;
  47306. int decodedSz = 0;
  47307. int encryptedSz = 0;
  47308. int testSz = 0;
  47309. int i = 0;
  47310. const byte data[] = { /* Hello World */
  47311. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  47312. 0x72,0x6c,0x64
  47313. };
  47314. #ifndef NO_DES3
  47315. byte desKey[] = {
  47316. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef
  47317. };
  47318. byte des3Key[] = {
  47319. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  47320. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  47321. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  47322. };
  47323. #endif
  47324. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  47325. #ifndef NO_AES_128
  47326. byte aes128Key[] = {
  47327. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47328. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  47329. };
  47330. #endif
  47331. #ifndef NO_AES_192
  47332. byte aes192Key[] = {
  47333. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47334. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47335. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  47336. };
  47337. #endif
  47338. #ifndef NO_AES_256
  47339. byte aes256Key[] = {
  47340. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47341. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47342. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47343. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  47344. };
  47345. #endif
  47346. #endif /* !NO_AES && HAVE_AES_CBC */
  47347. const pkcs7EncryptedVector testVectors[] =
  47348. {
  47349. #ifndef NO_DES3
  47350. {data, (word32)sizeof(data), DATA, DES3b, des3Key, sizeof(des3Key)},
  47351. {data, (word32)sizeof(data), DATA, DESb, desKey, sizeof(desKey)},
  47352. #endif /* !NO_DES3 */
  47353. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  47354. #ifndef NO_AES_128
  47355. {data, (word32)sizeof(data), DATA, AES128CBCb, aes128Key,
  47356. sizeof(aes128Key)},
  47357. #endif
  47358. #ifndef NO_AES_192
  47359. {data, (word32)sizeof(data), DATA, AES192CBCb, aes192Key,
  47360. sizeof(aes192Key)},
  47361. #endif
  47362. #ifndef NO_AES_256
  47363. {data, (word32)sizeof(data), DATA, AES256CBCb, aes256Key,
  47364. sizeof(aes256Key)},
  47365. #endif
  47366. #endif /* !NO_AES && HAVE_AES_CBC */
  47367. };
  47368. testSz = sizeof(testVectors) / sizeof(pkcs7EncryptedVector);
  47369. for (i = 0; i < testSz; i++) {
  47370. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47371. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, testDevId), 0);
  47372. if (pkcs7 != NULL) {
  47373. pkcs7->content = (byte*)testVectors[i].content;
  47374. pkcs7->contentSz = testVectors[i].contentSz;
  47375. pkcs7->contentOID = testVectors[i].contentOID;
  47376. pkcs7->encryptOID = testVectors[i].encryptOID;
  47377. pkcs7->encryptionKey = testVectors[i].encryptionKey;
  47378. pkcs7->encryptionKeySz = testVectors[i].encryptionKeySz;
  47379. pkcs7->heap = HEAP_HINT;
  47380. }
  47381. /* encode encryptedData */
  47382. ExpectIntGT(encryptedSz = wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  47383. sizeof(encrypted)), 0);
  47384. /* Decode encryptedData */
  47385. ExpectIntGT(decodedSz = wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted,
  47386. (word32)encryptedSz, decoded, sizeof(decoded)), 0);
  47387. ExpectIntEQ(XMEMCMP(decoded, data, decodedSz), 0);
  47388. /* Keep values for last itr. */
  47389. if (i < testSz - 1) {
  47390. wc_PKCS7_Free(pkcs7);
  47391. pkcs7 = NULL;
  47392. }
  47393. }
  47394. if (pkcs7 == NULL || testSz == 0) {
  47395. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47396. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, testDevId), 0);
  47397. }
  47398. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(NULL, encrypted,
  47399. sizeof(encrypted)),WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47400. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, NULL,
  47401. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47402. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  47403. 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47404. /* Testing the struct. */
  47405. if (pkcs7 != NULL) {
  47406. tmpBytePtr = pkcs7->content;
  47407. pkcs7->content = NULL;
  47408. }
  47409. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  47410. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47411. if (pkcs7 != NULL) {
  47412. pkcs7->content = tmpBytePtr;
  47413. tmpWrd32 = pkcs7->contentSz;
  47414. pkcs7->contentSz = 0;
  47415. }
  47416. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  47417. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47418. if (pkcs7 != NULL) {
  47419. pkcs7->contentSz = tmpWrd32;
  47420. tmpInt = pkcs7->encryptOID;
  47421. pkcs7->encryptOID = 0;
  47422. }
  47423. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  47424. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47425. if (pkcs7 != NULL) {
  47426. pkcs7->encryptOID = tmpInt;
  47427. tmpBytePtr = pkcs7->encryptionKey;
  47428. pkcs7->encryptionKey = NULL;
  47429. }
  47430. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  47431. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47432. if (pkcs7 != NULL) {
  47433. pkcs7->encryptionKey = tmpBytePtr;
  47434. tmpWrd32 = pkcs7->encryptionKeySz;
  47435. pkcs7->encryptionKeySz = 0;
  47436. }
  47437. ExpectIntEQ(wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  47438. sizeof(encrypted)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47439. if (pkcs7 != NULL) {
  47440. pkcs7->encryptionKeySz = tmpWrd32;
  47441. }
  47442. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(NULL, encrypted, (word32)encryptedSz,
  47443. decoded, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47444. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, NULL, (word32)encryptedSz,
  47445. decoded, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47446. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, 0,
  47447. decoded, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47448. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, (word32)encryptedSz,
  47449. NULL, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47450. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, (word32)encryptedSz,
  47451. decoded, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47452. /* Test struct fields */
  47453. if (pkcs7 != NULL) {
  47454. tmpBytePtr = pkcs7->encryptionKey;
  47455. pkcs7->encryptionKey = NULL;
  47456. }
  47457. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, (word32)encryptedSz,
  47458. decoded, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47459. if (pkcs7 != NULL) {
  47460. pkcs7->encryptionKey = tmpBytePtr;
  47461. pkcs7->encryptionKeySz = 0;
  47462. }
  47463. ExpectIntEQ(wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, (word32)encryptedSz,
  47464. decoded, sizeof(decoded)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47465. wc_PKCS7_Free(pkcs7);
  47466. #endif
  47467. return EXPECT_RESULT();
  47468. } /* END test_wc_PKCS7_EncodeEncryptedData() */
  47469. /*
  47470. * Testing wc_PKCS7_Degenerate()
  47471. */
  47472. static int test_wc_PKCS7_Degenerate(void)
  47473. {
  47474. EXPECT_DECLS;
  47475. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM)
  47476. PKCS7* pkcs7 = NULL;
  47477. char fName[] = "./certs/test-degenerate.p7b";
  47478. XFILE f = XBADFILE;
  47479. byte der[4096];
  47480. word32 derSz = 0;
  47481. #ifndef NO_PKCS7_STREAM
  47482. word32 z;
  47483. int ret;
  47484. #endif /* !NO_PKCS7_STREAM */
  47485. ExpectTrue((f = XFOPEN(fName, "rb")) != XBADFILE);
  47486. ExpectTrue((derSz = (word32)XFREAD(der, 1, sizeof(der), f)) > 0);
  47487. if (f != XBADFILE)
  47488. XFCLOSE(f);
  47489. /* test degenerate success */
  47490. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47491. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  47492. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  47493. #ifndef NO_RSA
  47494. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, der, derSz), 0);
  47495. #ifndef NO_PKCS7_STREAM
  47496. wc_PKCS7_Free(pkcs7);
  47497. pkcs7 = NULL;
  47498. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47499. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  47500. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  47501. /* test for streaming */
  47502. ret = -1;
  47503. for (z = 0; z < derSz && ret != 0; z++) {
  47504. ret = wc_PKCS7_VerifySignedData(pkcs7, der + z, 1);
  47505. if (ret < 0){
  47506. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  47507. }
  47508. }
  47509. ExpectIntEQ(ret, 0);
  47510. #endif /* !NO_PKCS7_STREAM */
  47511. #else
  47512. ExpectIntNE(wc_PKCS7_VerifySignedData(pkcs7, der, derSz), 0);
  47513. #endif /* NO_RSA */
  47514. wc_PKCS7_Free(pkcs7);
  47515. pkcs7 = NULL;
  47516. /* test with turning off degenerate cases */
  47517. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47518. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  47519. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  47520. wc_PKCS7_AllowDegenerate(pkcs7, 0); /* override allowing degenerate case */
  47521. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, der, derSz),
  47522. WC_NO_ERR_TRACE(PKCS7_NO_SIGNER_E));
  47523. #ifndef NO_PKCS7_STREAM
  47524. wc_PKCS7_Free(pkcs7);
  47525. pkcs7 = NULL;
  47526. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47527. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  47528. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  47529. wc_PKCS7_AllowDegenerate(pkcs7, 0); /* override allowing degenerate case */
  47530. /* test for streaming */
  47531. ret = -1;
  47532. for (z = 0; z < derSz && ret != 0; z++) {
  47533. ret = wc_PKCS7_VerifySignedData(pkcs7, der + z, 1);
  47534. if (ret == WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)){
  47535. continue;
  47536. }
  47537. else
  47538. break;
  47539. }
  47540. ExpectIntEQ(ret, WC_NO_ERR_TRACE(PKCS7_NO_SIGNER_E));
  47541. #endif /* !NO_PKCS7_STREAM */
  47542. wc_PKCS7_Free(pkcs7);
  47543. #endif
  47544. return EXPECT_RESULT();
  47545. } /* END test_wc_PKCS7_Degenerate() */
  47546. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && \
  47547. defined(ASN_BER_TO_DER) && !defined(NO_DES3) && !defined(NO_SHA)
  47548. static byte berContent[] = {
  47549. 0x30, 0x80, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86,
  47550. 0xF7, 0x0D, 0x01, 0x07, 0x03, 0xA0, 0x80, 0x30,
  47551. 0x80, 0x02, 0x01, 0x00, 0x31, 0x82, 0x01, 0x48,
  47552. 0x30, 0x82, 0x01, 0x44, 0x02, 0x01, 0x00, 0x30,
  47553. 0x81, 0xAC, 0x30, 0x81, 0x9E, 0x31, 0x0B, 0x30,
  47554. 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,
  47555. 0x55, 0x53, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03,
  47556. 0x55, 0x04, 0x08, 0x0C, 0x07, 0x4D, 0x6F, 0x6E,
  47557. 0x74, 0x61, 0x6E, 0x61, 0x31, 0x10, 0x30, 0x0E,
  47558. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0C, 0x07, 0x42,
  47559. 0x6F, 0x7A, 0x65, 0x6D, 0x61, 0x6E, 0x31, 0x15,
  47560. 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C,
  47561. 0x0C, 0x77, 0x6F, 0x6C, 0x66, 0x53, 0x53, 0x4C,
  47562. 0x5F, 0x31, 0x30, 0x32, 0x34, 0x31, 0x19, 0x30,
  47563. 0x17, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x10,
  47564. 0x50, 0x72, 0x6F, 0x67, 0x72, 0x61, 0x6D, 0x6D,
  47565. 0x69, 0x6E, 0x67, 0x2D, 0x31, 0x30, 0x32, 0x34,
  47566. 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04,
  47567. 0x03, 0x0C, 0x0F, 0x77, 0x77, 0x77, 0x2E, 0x77,
  47568. 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63,
  47569. 0x6F, 0x6D, 0x31, 0x1F, 0x30, 0x1D, 0x06, 0x09,
  47570. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09,
  47571. 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40,
  47572. 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E,
  47573. 0x63, 0x6F, 0x6D, 0x02, 0x09, 0x00, 0xBB, 0xD3,
  47574. 0x10, 0x03, 0xE6, 0x9D, 0x28, 0x03, 0x30, 0x0D,
  47575. 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  47576. 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x81, 0x80,
  47577. 0x2F, 0xF9, 0x77, 0x4F, 0x04, 0x5C, 0x16, 0x62,
  47578. 0xF0, 0x77, 0x8D, 0x95, 0x4C, 0xB1, 0x44, 0x9A,
  47579. 0x8C, 0x3C, 0x8C, 0xE4, 0xD1, 0xC1, 0x14, 0x72,
  47580. 0xD0, 0x4A, 0x1A, 0x94, 0x27, 0x0F, 0xAA, 0xE8,
  47581. 0xD0, 0xA2, 0xE7, 0xED, 0x4C, 0x7F, 0x0F, 0xC7,
  47582. 0x1B, 0xFB, 0x81, 0x0E, 0x76, 0x8F, 0xDD, 0x32,
  47583. 0x11, 0x68, 0xA0, 0x13, 0xD2, 0x8D, 0x95, 0xEF,
  47584. 0x80, 0x53, 0x81, 0x0E, 0x1F, 0xC8, 0xD6, 0x76,
  47585. 0x5C, 0x31, 0xD3, 0x77, 0x33, 0x29, 0xA6, 0x1A,
  47586. 0xD3, 0xC6, 0x14, 0x36, 0xCA, 0x8E, 0x7D, 0x72,
  47587. 0xA0, 0x29, 0x4C, 0xC7, 0x3A, 0xAF, 0xFE, 0xF7,
  47588. 0xFC, 0xD7, 0xE2, 0x8F, 0x6A, 0x20, 0x46, 0x09,
  47589. 0x40, 0x22, 0x2D, 0x79, 0x38, 0x11, 0xB1, 0x4A,
  47590. 0xE3, 0x48, 0xE8, 0x10, 0x37, 0xA0, 0x22, 0xF7,
  47591. 0xB4, 0x79, 0xD1, 0xA9, 0x3D, 0xC2, 0xAB, 0x37,
  47592. 0xAE, 0x82, 0x68, 0x1A, 0x16, 0xEF, 0x33, 0x0C,
  47593. 0x30, 0x80, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86,
  47594. 0xF7, 0x0D, 0x01, 0x07, 0x01, 0x30, 0x14, 0x06,
  47595. 0x08, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x03,
  47596. 0x07, 0x04, 0x08, 0xAD, 0xD0, 0x38, 0x9B, 0x16,
  47597. 0x4B, 0x7F, 0x99, 0xA0, 0x80, 0x04, 0x82, 0x03,
  47598. 0xE8, 0x6D, 0x48, 0xFB, 0x8A, 0xBD, 0xED, 0x6C,
  47599. 0xCD, 0xC6, 0x48, 0xFD, 0xB7, 0xB0, 0x7C, 0x86,
  47600. 0x2C, 0x8D, 0xF0, 0x23, 0x12, 0xD8, 0xA3, 0x2A,
  47601. 0x21, 0x6F, 0x8B, 0x75, 0xBB, 0x47, 0x7F, 0xC9,
  47602. 0xBA, 0xBA, 0xFF, 0x91, 0x09, 0x01, 0x7A, 0x5C,
  47603. 0x96, 0x02, 0xB8, 0x8E, 0xF8, 0x67, 0x7E, 0x8F,
  47604. 0xF9, 0x51, 0x0E, 0xFF, 0x8E, 0xE2, 0x61, 0xC0,
  47605. 0xDF, 0xFA, 0xE2, 0x4C, 0x50, 0x90, 0xAE, 0xA1,
  47606. 0x15, 0x38, 0x3D, 0xBE, 0x88, 0xD7, 0x57, 0xC0,
  47607. 0x11, 0x44, 0xA2, 0x61, 0x05, 0x49, 0x6A, 0x94,
  47608. 0x04, 0x10, 0xD9, 0xC2, 0x2D, 0x15, 0x20, 0x0D,
  47609. 0xBD, 0xA2, 0xEF, 0xE4, 0x68, 0xFA, 0x39, 0x75,
  47610. 0x7E, 0xD8, 0x64, 0x44, 0xCB, 0xE0, 0x00, 0x6D,
  47611. 0x57, 0x4E, 0x8A, 0x17, 0xA9, 0x83, 0x6C, 0x7F,
  47612. 0xFE, 0x01, 0xEE, 0xDE, 0x99, 0x3A, 0xB2, 0xFF,
  47613. 0xD3, 0x72, 0x78, 0xBA, 0xF1, 0x23, 0x54, 0x48,
  47614. 0x02, 0xD8, 0x38, 0xA9, 0x54, 0xE5, 0x4A, 0x81,
  47615. 0xB9, 0xC0, 0x67, 0xB2, 0x7D, 0x3C, 0x6F, 0xCE,
  47616. 0xA4, 0xDD, 0x34, 0x5F, 0x60, 0xB1, 0xA3, 0x7A,
  47617. 0xE4, 0x43, 0xF2, 0x89, 0x64, 0x35, 0x09, 0x32,
  47618. 0x51, 0xFB, 0x5C, 0x67, 0x0C, 0x3B, 0xFC, 0x36,
  47619. 0x6B, 0x37, 0x43, 0x6C, 0x03, 0xCD, 0x44, 0xC7,
  47620. 0x2B, 0x62, 0xD6, 0xD1, 0xF4, 0x07, 0x7B, 0x19,
  47621. 0x91, 0xF0, 0xD7, 0xF5, 0x54, 0xBC, 0x0F, 0x42,
  47622. 0x6B, 0x69, 0xF7, 0xA3, 0xC8, 0xEE, 0xB9, 0x7A,
  47623. 0x9E, 0x3D, 0xDF, 0x53, 0x47, 0xF7, 0x50, 0x67,
  47624. 0x00, 0xCF, 0x2B, 0x3B, 0xE9, 0x85, 0xEE, 0xBD,
  47625. 0x4C, 0x64, 0x66, 0x0B, 0x77, 0x80, 0x9D, 0xEF,
  47626. 0x11, 0x32, 0x77, 0xA8, 0xA4, 0x5F, 0xEE, 0x2D,
  47627. 0xE0, 0x43, 0x87, 0x76, 0x87, 0x53, 0x4E, 0xD7,
  47628. 0x1A, 0x04, 0x7B, 0xE1, 0xD1, 0xE1, 0xF5, 0x87,
  47629. 0x51, 0x13, 0xE0, 0xC2, 0xAA, 0xA3, 0x4B, 0xAA,
  47630. 0x9E, 0xB4, 0xA6, 0x1D, 0x4E, 0x28, 0x57, 0x0B,
  47631. 0x80, 0x90, 0x81, 0x4E, 0x04, 0xF5, 0x30, 0x8D,
  47632. 0x51, 0xCE, 0x57, 0x2F, 0x88, 0xC5, 0x70, 0xC4,
  47633. 0x06, 0x8F, 0xDD, 0x37, 0xC1, 0x34, 0x1E, 0x0E,
  47634. 0x15, 0x32, 0x23, 0x92, 0xAB, 0x40, 0xEA, 0xF7,
  47635. 0x43, 0xE2, 0x1D, 0xE2, 0x4B, 0xC9, 0x91, 0xF4,
  47636. 0x63, 0x21, 0x34, 0xDB, 0xE9, 0x86, 0x83, 0x1A,
  47637. 0xD2, 0x52, 0xEF, 0x7A, 0xA2, 0xEE, 0xA4, 0x11,
  47638. 0x56, 0xD3, 0x6C, 0xF5, 0x6D, 0xE4, 0xA5, 0x2D,
  47639. 0x99, 0x02, 0x10, 0xDF, 0x29, 0xC5, 0xE3, 0x0B,
  47640. 0xC4, 0xA1, 0xEE, 0x5F, 0x4A, 0x10, 0xEE, 0x85,
  47641. 0x73, 0x2A, 0x92, 0x15, 0x2C, 0xC8, 0xF4, 0x8C,
  47642. 0xD7, 0x3D, 0xBC, 0xAD, 0x18, 0xE0, 0x59, 0xD3,
  47643. 0xEE, 0x75, 0x90, 0x1C, 0xCC, 0x76, 0xC6, 0x64,
  47644. 0x17, 0xD2, 0xD0, 0x91, 0xA6, 0xD0, 0xC1, 0x4A,
  47645. 0xAA, 0x58, 0x22, 0xEC, 0x45, 0x98, 0xF2, 0xCC,
  47646. 0x4C, 0xE4, 0xBF, 0xED, 0xF6, 0x44, 0x72, 0x36,
  47647. 0x65, 0x3F, 0xE3, 0xB5, 0x8B, 0x3E, 0x54, 0x9C,
  47648. 0x82, 0x86, 0x5E, 0xB0, 0xF2, 0x12, 0xE5, 0x69,
  47649. 0xFA, 0x46, 0xA2, 0x54, 0xFC, 0xF5, 0x4B, 0xE0,
  47650. 0x24, 0x3B, 0x99, 0x04, 0x1A, 0x7A, 0xF7, 0xD1,
  47651. 0xFF, 0x68, 0x97, 0xB2, 0x85, 0x82, 0x95, 0x27,
  47652. 0x2B, 0xF4, 0xE7, 0x1A, 0x74, 0x19, 0xEC, 0x8C,
  47653. 0x4E, 0xA7, 0x0F, 0xAD, 0x4F, 0x5A, 0x02, 0x80,
  47654. 0xC1, 0x6A, 0x9E, 0x54, 0xE4, 0x8E, 0xA3, 0x41,
  47655. 0x3F, 0x6F, 0x9C, 0x82, 0x9F, 0x83, 0xB0, 0x44,
  47656. 0x01, 0x5F, 0x10, 0x9D, 0xD3, 0xB6, 0x33, 0x5B,
  47657. 0xAF, 0xAC, 0x6B, 0x57, 0x2A, 0x01, 0xED, 0x0E,
  47658. 0x17, 0xB9, 0x80, 0x76, 0x12, 0x1C, 0x51, 0x56,
  47659. 0xDD, 0x6D, 0x94, 0xAB, 0xD2, 0xE5, 0x15, 0x2D,
  47660. 0x3C, 0xC5, 0xE8, 0x62, 0x05, 0x8B, 0x40, 0xB1,
  47661. 0xC2, 0x83, 0xCA, 0xAC, 0x4B, 0x8B, 0x39, 0xF7,
  47662. 0xA0, 0x08, 0x43, 0x5C, 0xF7, 0xE8, 0xED, 0x40,
  47663. 0x72, 0x73, 0xE3, 0x6B, 0x18, 0x67, 0xA0, 0xB6,
  47664. 0x0F, 0xED, 0x8F, 0x9A, 0xE4, 0x27, 0x62, 0x23,
  47665. 0xAA, 0x6D, 0x6C, 0x31, 0xC9, 0x9D, 0x6B, 0xE0,
  47666. 0xBF, 0x9D, 0x7D, 0x2E, 0x76, 0x71, 0x06, 0x39,
  47667. 0xAC, 0x96, 0x1C, 0xAF, 0x30, 0xF2, 0x62, 0x9C,
  47668. 0x84, 0x3F, 0x43, 0x5E, 0x19, 0xA8, 0xE5, 0x3C,
  47669. 0x9D, 0x43, 0x3C, 0x43, 0x41, 0xE8, 0x82, 0xE7,
  47670. 0x5B, 0xF3, 0xE2, 0x15, 0xE3, 0x52, 0x20, 0xFD,
  47671. 0x0D, 0xB2, 0x4D, 0x48, 0xAD, 0x53, 0x7E, 0x0C,
  47672. 0xF0, 0xB9, 0xBE, 0xC9, 0x58, 0x4B, 0xC8, 0xA8,
  47673. 0xA3, 0x36, 0xF1, 0x2C, 0xD2, 0xE1, 0xC8, 0xC4,
  47674. 0x3C, 0x48, 0x70, 0xC2, 0x6D, 0x6C, 0x3D, 0x99,
  47675. 0xAC, 0x43, 0x19, 0x69, 0xCA, 0x67, 0x1A, 0xC9,
  47676. 0xE1, 0x47, 0xFA, 0x0A, 0xE6, 0x5B, 0x6F, 0x61,
  47677. 0xD0, 0x03, 0xE4, 0x03, 0x4B, 0xFD, 0xE2, 0xA5,
  47678. 0x8D, 0x83, 0x01, 0x7E, 0xC0, 0x7B, 0x2E, 0x0B,
  47679. 0x29, 0xDD, 0xD6, 0xDC, 0x71, 0x46, 0xBD, 0x9A,
  47680. 0x40, 0x46, 0x1E, 0x0A, 0xB1, 0x00, 0xE7, 0x71,
  47681. 0x29, 0x77, 0xFC, 0x9A, 0x76, 0x8A, 0x5F, 0x66,
  47682. 0x9B, 0x63, 0x91, 0x12, 0x78, 0xBF, 0x67, 0xAD,
  47683. 0xA1, 0x72, 0x9E, 0xC5, 0x3E, 0xE5, 0xCB, 0xAF,
  47684. 0xD6, 0x5A, 0x0D, 0xB6, 0x9B, 0xA3, 0x78, 0xE8,
  47685. 0xB0, 0x8F, 0x69, 0xED, 0xC1, 0x73, 0xD5, 0xE5,
  47686. 0x1C, 0x18, 0xA0, 0x58, 0x4C, 0x49, 0xBD, 0x91,
  47687. 0xCE, 0x15, 0x0D, 0xAA, 0x5A, 0x07, 0xEA, 0x1C,
  47688. 0xA7, 0x4B, 0x11, 0x31, 0x80, 0xAF, 0xA1, 0x0A,
  47689. 0xED, 0x6C, 0x70, 0xE4, 0xDB, 0x75, 0x86, 0xAE,
  47690. 0xBF, 0x4A, 0x05, 0x72, 0xDE, 0x84, 0x8C, 0x7B,
  47691. 0x59, 0x81, 0x58, 0xE0, 0xC0, 0x15, 0xB5, 0xF3,
  47692. 0xD5, 0x73, 0x78, 0x83, 0x53, 0xDA, 0x92, 0xC1,
  47693. 0xE6, 0x71, 0x74, 0xC7, 0x7E, 0xAA, 0x36, 0x06,
  47694. 0xF0, 0xDF, 0xBA, 0xFB, 0xEF, 0x54, 0xE8, 0x11,
  47695. 0xB2, 0x33, 0xA3, 0x0B, 0x9E, 0x0C, 0x59, 0x75,
  47696. 0x13, 0xFA, 0x7F, 0x88, 0xB9, 0x86, 0xBD, 0x1A,
  47697. 0xDB, 0x52, 0x12, 0xFB, 0x6D, 0x1A, 0xCB, 0x49,
  47698. 0x94, 0x94, 0xC4, 0xA9, 0x99, 0xC0, 0xA4, 0xB6,
  47699. 0x60, 0x36, 0x09, 0x94, 0x2A, 0xD5, 0xC4, 0x26,
  47700. 0xF4, 0xA3, 0x6A, 0x0E, 0x57, 0x8B, 0x7C, 0xA4,
  47701. 0x1D, 0x75, 0xE8, 0x2A, 0xF3, 0xC4, 0x3C, 0x7D,
  47702. 0x45, 0x6D, 0xD8, 0x24, 0xD1, 0x3B, 0xF7, 0xCF,
  47703. 0xE4, 0x45, 0x2A, 0x55, 0xE5, 0xA9, 0x1F, 0x1C,
  47704. 0x8F, 0x55, 0x8D, 0xC1, 0xF7, 0x74, 0xCC, 0x26,
  47705. 0xC7, 0xBA, 0x2E, 0x5C, 0xC1, 0x71, 0x0A, 0xAA,
  47706. 0xD9, 0x6D, 0x76, 0xA7, 0xF9, 0xD1, 0x18, 0xCB,
  47707. 0x5A, 0x52, 0x98, 0xA8, 0x0D, 0x3F, 0x06, 0xFC,
  47708. 0x49, 0x11, 0x21, 0x5F, 0x86, 0x19, 0x33, 0x81,
  47709. 0xB5, 0x7A, 0xDA, 0xA1, 0x47, 0xBF, 0x7C, 0xD7,
  47710. 0x05, 0x96, 0xC7, 0xF5, 0xC1, 0x61, 0xE5, 0x18,
  47711. 0xA5, 0x38, 0x68, 0xED, 0xB4, 0x17, 0x62, 0x0D,
  47712. 0x01, 0x5E, 0xC3, 0x04, 0xA6, 0xBA, 0xB1, 0x01,
  47713. 0x60, 0x5C, 0xC1, 0x3A, 0x34, 0x97, 0xD6, 0xDB,
  47714. 0x67, 0x73, 0x4D, 0x33, 0x96, 0x01, 0x67, 0x44,
  47715. 0xEA, 0x47, 0x5E, 0x44, 0xB5, 0xE5, 0xD1, 0x6C,
  47716. 0x20, 0xA9, 0x6D, 0x4D, 0xBC, 0x02, 0xF0, 0x70,
  47717. 0xE4, 0xDD, 0xE9, 0xD5, 0x5C, 0x28, 0x29, 0x0B,
  47718. 0xB4, 0x60, 0x2A, 0xF1, 0xF7, 0x1A, 0xF0, 0x36,
  47719. 0xAE, 0x51, 0x3A, 0xAE, 0x6E, 0x48, 0x7D, 0xC7,
  47720. 0x5C, 0xF3, 0xDC, 0xF6, 0xED, 0x27, 0x4E, 0x8E,
  47721. 0x48, 0x18, 0x3E, 0x08, 0xF1, 0xD8, 0x3D, 0x0D,
  47722. 0xE7, 0x2F, 0x65, 0x8A, 0x6F, 0xE2, 0x1E, 0x06,
  47723. 0xC1, 0x04, 0x58, 0x7B, 0x4A, 0x75, 0x60, 0x92,
  47724. 0x13, 0xC6, 0x40, 0x2D, 0x3A, 0x8A, 0xD1, 0x03,
  47725. 0x05, 0x1F, 0x28, 0x66, 0xC2, 0x57, 0x2A, 0x4C,
  47726. 0xE1, 0xA3, 0xCB, 0xA1, 0x95, 0x30, 0x10, 0xED,
  47727. 0xDF, 0xAE, 0x70, 0x49, 0x4E, 0xF6, 0xB4, 0x5A,
  47728. 0xB6, 0x22, 0x56, 0x37, 0x05, 0xE7, 0x3E, 0xB2,
  47729. 0xE3, 0x96, 0x62, 0xEC, 0x09, 0x53, 0xC0, 0x50,
  47730. 0x3D, 0xA7, 0xBC, 0x9B, 0x39, 0x02, 0x26, 0x16,
  47731. 0xB5, 0x34, 0x17, 0xD4, 0xCA, 0xFE, 0x1D, 0xE4,
  47732. 0x5A, 0xDA, 0x4C, 0xC2, 0xCA, 0x8E, 0x79, 0xBF,
  47733. 0xD8, 0x4C, 0xBB, 0xFA, 0x30, 0x7B, 0xA9, 0x3E,
  47734. 0x52, 0x19, 0xB1, 0x00, 0x00, 0x00, 0x00, 0x00,
  47735. 0x00, 0x00, 0x00, 0x00, 0x00
  47736. };
  47737. #endif /* HAVE_PKCS7 && !NO_FILESYSTEM && ASN_BER_TO_DER &&
  47738. * !NO_DES3 && !NO_SHA
  47739. */
  47740. /*
  47741. * Testing wc_PKCS7_BER()
  47742. */
  47743. static int test_wc_PKCS7_BER(void)
  47744. {
  47745. EXPECT_DECLS;
  47746. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && \
  47747. !defined(NO_SHA) && defined(ASN_BER_TO_DER)
  47748. PKCS7* pkcs7 = NULL;
  47749. char fName[] = "./certs/test-ber-exp02-05-2022.p7b";
  47750. XFILE f = XBADFILE;
  47751. byte der[4096];
  47752. #ifndef NO_DES3
  47753. byte decoded[2048];
  47754. #endif
  47755. word32 derSz = 0;
  47756. #ifndef NO_PKCS7_STREAM
  47757. word32 z;
  47758. int ret;
  47759. #endif /* !NO_PKCS7_STREAM */
  47760. ExpectTrue((f = XFOPEN(fName, "rb")) != XBADFILE);
  47761. ExpectTrue((derSz = (word32)XFREAD(der, 1, sizeof(der), f)) > 0);
  47762. if (f != XBADFILE) {
  47763. XFCLOSE(f);
  47764. f = XBADFILE;
  47765. }
  47766. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47767. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  47768. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  47769. #ifndef NO_RSA
  47770. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, der, derSz), 0);
  47771. #ifndef NO_PKCS7_STREAM
  47772. wc_PKCS7_Free(pkcs7);
  47773. pkcs7 = NULL;
  47774. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47775. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID), 0);
  47776. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  47777. /* test for streaming */
  47778. ret = -1;
  47779. for (z = 0; z < derSz && ret != 0; z++) {
  47780. ret = wc_PKCS7_VerifySignedData(pkcs7, der + z, 1);
  47781. if (ret < 0){
  47782. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  47783. }
  47784. }
  47785. ExpectIntEQ(ret, 0);
  47786. #endif /* !NO_PKCS7_STREAM */
  47787. #else
  47788. ExpectIntNE(wc_PKCS7_VerifySignedData(pkcs7, der, derSz), 0);
  47789. #endif
  47790. wc_PKCS7_Free(pkcs7);
  47791. pkcs7 = NULL;
  47792. #ifndef NO_DES3
  47793. /* decode BER content */
  47794. ExpectTrue((f = XFOPEN("./certs/1024/client-cert.der", "rb")) != XBADFILE);
  47795. ExpectTrue((derSz = (word32)XFREAD(der, 1, sizeof(der), f)) > 0);
  47796. if (f != XBADFILE) {
  47797. XFCLOSE(f);
  47798. f = XBADFILE;
  47799. }
  47800. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47801. #ifndef NO_RSA
  47802. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, der, derSz), 0);
  47803. #else
  47804. ExpectIntNE(wc_PKCS7_InitWithCert(pkcs7, der, derSz), 0);
  47805. #endif
  47806. ExpectTrue((f = XFOPEN("./certs/1024/client-key.der", "rb")) != XBADFILE);
  47807. ExpectTrue((derSz = (word32)XFREAD(der, 1, sizeof(der), f)) > 0);
  47808. if (f != XBADFILE) {
  47809. XFCLOSE(f);
  47810. f = XBADFILE;
  47811. }
  47812. if (pkcs7 != NULL) {
  47813. pkcs7->privateKey = der;
  47814. pkcs7->privateKeySz = derSz;
  47815. }
  47816. #ifndef NO_RSA
  47817. #ifdef WOLFSSL_SP_MATH
  47818. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, berContent,
  47819. sizeof(berContent), decoded, sizeof(decoded)), WC_NO_ERR_TRACE(WC_KEY_SIZE_E));
  47820. #else
  47821. ExpectIntGT(wc_PKCS7_DecodeEnvelopedData(pkcs7, berContent,
  47822. sizeof(berContent), decoded, sizeof(decoded)), 0);
  47823. #endif
  47824. #else
  47825. ExpectIntEQ(wc_PKCS7_DecodeEnvelopedData(pkcs7, berContent,
  47826. sizeof(berContent), decoded, sizeof(decoded)), WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  47827. #endif
  47828. wc_PKCS7_Free(pkcs7);
  47829. #endif /* !NO_DES3 */
  47830. #endif
  47831. return EXPECT_RESULT();
  47832. } /* END test_wc_PKCS7_BER() */
  47833. static int test_wc_PKCS7_signed_enveloped(void)
  47834. {
  47835. EXPECT_DECLS;
  47836. #if defined(HAVE_PKCS7) && !defined(NO_RSA) && !defined(NO_AES) && \
  47837. !defined(NO_FILESYSTEM)
  47838. XFILE f = XBADFILE;
  47839. PKCS7* pkcs7 = NULL;
  47840. #ifdef HAVE_AES_CBC
  47841. PKCS7* inner = NULL;
  47842. #endif
  47843. WC_RNG rng;
  47844. unsigned char key[FOURK_BUF/2];
  47845. unsigned char cert[FOURK_BUF/2];
  47846. unsigned char env[FOURK_BUF];
  47847. int envSz = FOURK_BUF;
  47848. int keySz = 0;
  47849. int certSz = 0;
  47850. unsigned char sig[FOURK_BUF * 2];
  47851. int sigSz = FOURK_BUF * 2;
  47852. #ifdef HAVE_AES_CBC
  47853. unsigned char decoded[FOURK_BUF];
  47854. int decodedSz = FOURK_BUF;
  47855. #endif
  47856. #ifndef NO_PKCS7_STREAM
  47857. int z;
  47858. int ret;
  47859. #endif /* !NO_PKCS7_STREAM */
  47860. XMEMSET(&rng, 0, sizeof(WC_RNG));
  47861. /* load cert */
  47862. ExpectTrue((f = XFOPEN(cliCertDerFile, "rb")) != XBADFILE);
  47863. ExpectIntGT((certSz = (int)XFREAD(cert, 1, sizeof(cert), f)), 0);
  47864. if (f != XBADFILE) {
  47865. XFCLOSE(f);
  47866. f = XBADFILE;
  47867. }
  47868. /* load key */
  47869. ExpectTrue((f = XFOPEN(cliKeyFile, "rb")) != XBADFILE);
  47870. ExpectIntGT((keySz = (int)XFREAD(key, 1, sizeof(key), f)), 0);
  47871. if (f != XBADFILE) {
  47872. XFCLOSE(f);
  47873. f = XBADFILE;
  47874. }
  47875. ExpectIntGT(keySz = wolfSSL_KeyPemToDer(key, keySz, key, keySz, NULL), 0);
  47876. /* sign cert for envelope */
  47877. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47878. ExpectIntEQ(wc_InitRng(&rng), 0);
  47879. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  47880. if (pkcs7 != NULL) {
  47881. pkcs7->content = cert;
  47882. pkcs7->contentSz = (word32)certSz;
  47883. pkcs7->contentOID = DATA;
  47884. pkcs7->privateKey = key;
  47885. pkcs7->privateKeySz = (word32)keySz;
  47886. pkcs7->encryptOID = RSAk;
  47887. pkcs7->hashOID = SHA256h;
  47888. pkcs7->rng = &rng;
  47889. }
  47890. ExpectIntGT((sigSz = wc_PKCS7_EncodeSignedData(pkcs7, sig, (word32)sigSz)), 0);
  47891. wc_PKCS7_Free(pkcs7);
  47892. pkcs7 = NULL;
  47893. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  47894. #ifdef HAVE_AES_CBC
  47895. /* create envelope */
  47896. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47897. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  47898. if (pkcs7 != NULL) {
  47899. pkcs7->content = sig;
  47900. pkcs7->contentSz = (word32)sigSz;
  47901. pkcs7->contentOID = DATA;
  47902. pkcs7->encryptOID = AES256CBCb;
  47903. pkcs7->privateKey = key;
  47904. pkcs7->privateKeySz = (word32)keySz;
  47905. }
  47906. ExpectIntGT((envSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, env, (word32)envSz)), 0);
  47907. ExpectIntLT(wc_PKCS7_EncodeEnvelopedData(pkcs7, env, 2), 0);
  47908. wc_PKCS7_Free(pkcs7);
  47909. pkcs7 = NULL;
  47910. #endif
  47911. /* create bad signed enveloped data */
  47912. sigSz = FOURK_BUF * 2;
  47913. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47914. ExpectIntEQ(wc_InitRng(&rng), 0);
  47915. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  47916. if (pkcs7 != NULL) {
  47917. pkcs7->content = env;
  47918. pkcs7->contentSz = (word32)envSz;
  47919. pkcs7->contentOID = DATA;
  47920. pkcs7->privateKey = key;
  47921. pkcs7->privateKeySz = (word32)keySz;
  47922. pkcs7->encryptOID = RSAk;
  47923. pkcs7->hashOID = SHA256h;
  47924. pkcs7->rng = &rng;
  47925. }
  47926. /* Set no certs in bundle for this test. */
  47927. if (pkcs7 != NULL) {
  47928. ExpectIntEQ(wc_PKCS7_SetNoCerts(pkcs7, 1), 0);
  47929. ExpectIntEQ(wc_PKCS7_SetNoCerts(NULL, 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  47930. ExpectIntEQ(wc_PKCS7_GetNoCerts(pkcs7), 1);
  47931. }
  47932. ExpectIntGT((sigSz = wc_PKCS7_EncodeSignedData(pkcs7, sig, (word32)sigSz)), 0);
  47933. wc_PKCS7_Free(pkcs7);
  47934. pkcs7 = NULL;
  47935. /* check verify fails */
  47936. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47937. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  47938. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, sig, (word32)sigSz),
  47939. WC_NO_ERR_TRACE(PKCS7_SIGNEEDS_CHECK));
  47940. /* try verifying the signature manually */
  47941. {
  47942. RsaKey rKey;
  47943. word32 idx = 0;
  47944. byte digest[MAX_SEQ_SZ + MAX_ALGO_SZ + MAX_OCTET_STR_SZ +
  47945. WC_MAX_DIGEST_SIZE];
  47946. int digestSz = 0;
  47947. ExpectIntEQ(wc_InitRsaKey(&rKey, HEAP_HINT), 0);
  47948. ExpectIntEQ(wc_RsaPrivateKeyDecode(key, &idx, &rKey, (word32)keySz), 0);
  47949. ExpectIntGT(digestSz = wc_RsaSSL_Verify(pkcs7->signature,
  47950. pkcs7->signatureSz, digest, sizeof(digest), &rKey), 0);
  47951. ExpectIntEQ(digestSz, pkcs7->pkcs7DigestSz);
  47952. ExpectIntEQ(XMEMCMP(digest, pkcs7->pkcs7Digest, digestSz), 0);
  47953. ExpectIntEQ(wc_FreeRsaKey(&rKey), 0);
  47954. /* verify was success */
  47955. }
  47956. wc_PKCS7_Free(pkcs7);
  47957. pkcs7 = NULL;
  47958. /* initializing the PKCS7 struct with the signing certificate should pass */
  47959. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47960. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  47961. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, sig, (word32)sigSz), 0);
  47962. #ifndef NO_PKCS7_STREAM
  47963. wc_PKCS7_Free(pkcs7);
  47964. pkcs7 = NULL;
  47965. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  47966. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  47967. /* test for streaming */
  47968. ret = -1;
  47969. for (z = 0; z < sigSz && ret != 0; z++) {
  47970. ret = wc_PKCS7_VerifySignedData(pkcs7, sig + z, 1);
  47971. if (ret < 0){
  47972. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  47973. }
  47974. }
  47975. ExpectIntEQ(ret, 0);
  47976. #endif /* !NO_PKCS7_STREAM */
  47977. wc_PKCS7_Free(pkcs7);
  47978. pkcs7 = NULL;
  47979. /* create valid degenerate bundle */
  47980. sigSz = FOURK_BUF * 2;
  47981. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47982. if (pkcs7 != NULL) {
  47983. pkcs7->content = env;
  47984. pkcs7->contentSz = (word32)envSz;
  47985. pkcs7->contentOID = DATA;
  47986. pkcs7->privateKey = key;
  47987. pkcs7->privateKeySz = (word32)keySz;
  47988. pkcs7->encryptOID = RSAk;
  47989. pkcs7->hashOID = SHA256h;
  47990. pkcs7->rng = &rng;
  47991. }
  47992. ExpectIntEQ(wc_PKCS7_SetSignerIdentifierType(pkcs7, DEGENERATE_SID), 0);
  47993. ExpectIntGT((sigSz = wc_PKCS7_EncodeSignedData(pkcs7, sig, (word32)sigSz)), 0);
  47994. wc_PKCS7_Free(pkcs7);
  47995. pkcs7 = NULL;
  47996. wc_FreeRng(&rng);
  47997. /* check verify */
  47998. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  47999. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, testDevId), 0);
  48000. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, sig, (word32)sigSz), 0);
  48001. ExpectNotNull(pkcs7->content);
  48002. #ifndef NO_PKCS7_STREAM
  48003. wc_PKCS7_Free(pkcs7);
  48004. pkcs7 = NULL;
  48005. /* create valid degenerate bundle */
  48006. sigSz = FOURK_BUF * 2;
  48007. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  48008. if (pkcs7 != NULL) {
  48009. pkcs7->content = env;
  48010. pkcs7->contentSz = (word32)envSz;
  48011. pkcs7->contentOID = DATA;
  48012. pkcs7->privateKey = key;
  48013. pkcs7->privateKeySz = (word32)keySz;
  48014. pkcs7->encryptOID = RSAk;
  48015. pkcs7->hashOID = SHA256h;
  48016. pkcs7->rng = &rng;
  48017. }
  48018. ExpectIntEQ(wc_PKCS7_SetSignerIdentifierType(pkcs7, DEGENERATE_SID), 0);
  48019. ExpectIntGT((sigSz = wc_PKCS7_EncodeSignedData(pkcs7, sig, (word32)sigSz)), 0);
  48020. wc_PKCS7_Free(pkcs7);
  48021. pkcs7 = NULL;
  48022. wc_FreeRng(&rng);
  48023. /* check verify */
  48024. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  48025. ExpectIntEQ(wc_PKCS7_Init(pkcs7, HEAP_HINT, testDevId), 0);
  48026. /* test for streaming */
  48027. ret = -1;
  48028. for (z = 0; z < sigSz && ret != 0; z++) {
  48029. ret = wc_PKCS7_VerifySignedData(pkcs7, sig + z, 1);
  48030. if (ret < 0){
  48031. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  48032. }
  48033. }
  48034. ExpectIntEQ(ret, 0);
  48035. #endif /* !NO_PKCS7_STREAM */
  48036. #ifdef HAVE_AES_CBC
  48037. /* check decode */
  48038. ExpectNotNull(inner = wc_PKCS7_New(NULL, 0));
  48039. ExpectIntEQ(wc_PKCS7_InitWithCert(inner, cert, (word32)certSz), 0);
  48040. if (inner != NULL) {
  48041. inner->privateKey = key;
  48042. inner->privateKeySz = (word32)keySz;
  48043. }
  48044. ExpectIntGT((decodedSz = wc_PKCS7_DecodeEnvelopedData(inner, pkcs7->content,
  48045. pkcs7->contentSz, decoded, (word32)decodedSz)), 0);
  48046. wc_PKCS7_Free(inner);
  48047. inner = NULL;
  48048. #endif
  48049. wc_PKCS7_Free(pkcs7);
  48050. pkcs7 = NULL;
  48051. #ifdef HAVE_AES_CBC
  48052. /* check cert set */
  48053. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  48054. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  48055. ExpectIntEQ(wc_PKCS7_VerifySignedData(pkcs7, decoded, (word32)decodedSz), 0);
  48056. ExpectNotNull(pkcs7->singleCert);
  48057. ExpectIntNE(pkcs7->singleCertSz, 0);
  48058. wc_PKCS7_Free(pkcs7);
  48059. pkcs7 = NULL;
  48060. #ifndef NO_PKCS7_STREAM
  48061. ExpectNotNull(pkcs7 = wc_PKCS7_New(NULL, 0));
  48062. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, NULL, 0), 0);
  48063. /* test for streaming */
  48064. ret = -1;
  48065. for (z = 0; z < decodedSz && ret != 0; z++) {
  48066. ret = wc_PKCS7_VerifySignedData(pkcs7, decoded + z, 1);
  48067. if (ret < 0){
  48068. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  48069. }
  48070. }
  48071. ExpectIntEQ(ret, 0);
  48072. ExpectNotNull(pkcs7->singleCert);
  48073. ExpectIntNE(pkcs7->singleCertSz, 0);
  48074. wc_PKCS7_Free(pkcs7);
  48075. pkcs7 = NULL;
  48076. #endif /* !NO_PKCS7_STREAM */
  48077. #endif
  48078. {
  48079. /* arbitrary custom SKID */
  48080. const byte customSKID[] = {
  48081. 0x40, 0x25, 0x77, 0x56
  48082. };
  48083. ExpectIntEQ(wc_InitRng(&rng), 0);
  48084. sigSz = FOURK_BUF * 2;
  48085. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  48086. if (pkcs7 != NULL) {
  48087. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, cert, (word32)certSz), 0);
  48088. pkcs7->content = cert;
  48089. pkcs7->contentSz = (word32)certSz;
  48090. pkcs7->contentOID = DATA;
  48091. pkcs7->privateKey = key;
  48092. pkcs7->privateKeySz = (word32)keySz;
  48093. pkcs7->encryptOID = RSAk;
  48094. pkcs7->hashOID = SHA256h;
  48095. pkcs7->rng = &rng;
  48096. ExpectIntEQ(wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID), 0);
  48097. ExpectIntEQ(wc_PKCS7_SetCustomSKID(pkcs7, customSKID,
  48098. sizeof(customSKID)), 0);
  48099. ExpectIntGT((sigSz = wc_PKCS7_EncodeSignedData(pkcs7, sig,
  48100. (word32)sigSz)), 0);
  48101. }
  48102. wc_PKCS7_Free(pkcs7);
  48103. pkcs7 = NULL;
  48104. wc_FreeRng(&rng);
  48105. }
  48106. #endif /* HAVE_PKCS7 && !NO_RSA && !NO_AES */
  48107. return EXPECT_RESULT();
  48108. }
  48109. static int test_wc_PKCS7_NoDefaultSignedAttribs(void)
  48110. {
  48111. EXPECT_DECLS;
  48112. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \
  48113. && !defined(NO_AES)
  48114. PKCS7* pkcs7 = NULL;
  48115. void* heap = NULL;
  48116. ExpectNotNull(pkcs7 = wc_PKCS7_New(heap, testDevId));
  48117. ExpectIntEQ(wc_PKCS7_Init(pkcs7, heap, testDevId), 0);
  48118. ExpectIntEQ(wc_PKCS7_NoDefaultSignedAttribs(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48119. ExpectIntEQ(wc_PKCS7_NoDefaultSignedAttribs(pkcs7), 0);
  48120. wc_PKCS7_Free(pkcs7);
  48121. #endif
  48122. return EXPECT_RESULT();
  48123. }
  48124. static int test_wc_PKCS7_SetOriEncryptCtx(void)
  48125. {
  48126. EXPECT_DECLS;
  48127. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \
  48128. && !defined(NO_AES)
  48129. PKCS7* pkcs7 = NULL;
  48130. void* heap = NULL;
  48131. WOLFSSL_CTX* ctx = NULL;
  48132. ExpectNotNull(pkcs7 = wc_PKCS7_New(heap, testDevId));
  48133. ExpectIntEQ(wc_PKCS7_Init(pkcs7, heap, testDevId), 0);
  48134. ExpectIntEQ(wc_PKCS7_SetOriEncryptCtx(NULL, ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48135. ExpectIntEQ(wc_PKCS7_SetOriEncryptCtx(pkcs7, ctx), 0);
  48136. wc_PKCS7_Free(pkcs7);
  48137. #endif
  48138. return EXPECT_RESULT();
  48139. }
  48140. static int test_wc_PKCS7_SetOriDecryptCtx(void)
  48141. {
  48142. EXPECT_DECLS;
  48143. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \
  48144. && !defined(NO_AES)
  48145. PKCS7* pkcs7 = NULL;
  48146. void* heap = NULL;
  48147. WOLFSSL_CTX* ctx = NULL;
  48148. ExpectNotNull(pkcs7 = wc_PKCS7_New(heap, testDevId));
  48149. ExpectIntEQ(wc_PKCS7_Init(pkcs7, heap, testDevId), 0);
  48150. ExpectIntEQ(wc_PKCS7_SetOriDecryptCtx(NULL, ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48151. ExpectIntEQ(wc_PKCS7_SetOriDecryptCtx(pkcs7, ctx), 0);
  48152. wc_PKCS7_Free(pkcs7);
  48153. #endif
  48154. return EXPECT_RESULT();
  48155. }
  48156. static int test_wc_PKCS7_DecodeCompressedData(void)
  48157. {
  48158. EXPECT_DECLS;
  48159. #if defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \
  48160. && !defined(NO_AES) && defined(HAVE_LIBZ)
  48161. PKCS7* pkcs7 = NULL;
  48162. void* heap = NULL;
  48163. byte out[4096];
  48164. byte* decompressed = NULL;
  48165. int outSz;
  48166. int decompressedSz;
  48167. const char* cert = "./certs/client-cert.pem";
  48168. byte* cert_buf = NULL;
  48169. size_t cert_sz = 0;
  48170. ExpectIntEQ(load_file(cert, &cert_buf, &cert_sz), 0);
  48171. ExpectNotNull((decompressed = (byte*)XMALLOC(cert_sz, heap,
  48172. DYNAMIC_TYPE_TMP_BUFFER)));
  48173. decompressedSz = (int)cert_sz;
  48174. ExpectNotNull((pkcs7 = wc_PKCS7_New(heap, testDevId)));
  48175. if (pkcs7 != NULL) {
  48176. pkcs7->content = (byte*)cert_buf;
  48177. pkcs7->contentSz = (word32)cert_sz;
  48178. pkcs7->contentOID = DATA;
  48179. }
  48180. ExpectIntGT((outSz = wc_PKCS7_EncodeCompressedData(pkcs7, out,
  48181. sizeof(out))), 0);
  48182. wc_PKCS7_Free(pkcs7);
  48183. pkcs7 = NULL;
  48184. /* compressed key should be smaller than when started */
  48185. ExpectIntLT(outSz, cert_sz);
  48186. /* test decompression */
  48187. ExpectNotNull((pkcs7 = wc_PKCS7_New(heap, testDevId)));
  48188. ExpectIntEQ(pkcs7->contentOID, 0);
  48189. /* fail case with out buffer too small */
  48190. ExpectIntLT(wc_PKCS7_DecodeCompressedData(pkcs7, out, outSz,
  48191. decompressed, outSz), 0);
  48192. /* success case */
  48193. ExpectIntEQ(wc_PKCS7_DecodeCompressedData(pkcs7, out, outSz,
  48194. decompressed, decompressedSz), cert_sz);
  48195. ExpectIntEQ(pkcs7->contentOID, DATA);
  48196. ExpectIntEQ(XMEMCMP(decompressed, cert_buf, cert_sz), 0);
  48197. XFREE(decompressed, heap, DYNAMIC_TYPE_TMP_BUFFER);
  48198. decompressed = NULL;
  48199. /* test decompression function with different 'max' inputs */
  48200. outSz = sizeof(out);
  48201. ExpectIntGT((outSz = wc_Compress(out, outSz, cert_buf, (word32)cert_sz, 0)),
  48202. 0);
  48203. ExpectIntLT(wc_DeCompressDynamic(&decompressed, 1, DYNAMIC_TYPE_TMP_BUFFER,
  48204. out, outSz, 0, heap), 0);
  48205. ExpectNull(decompressed);
  48206. ExpectIntGT(wc_DeCompressDynamic(&decompressed, -1, DYNAMIC_TYPE_TMP_BUFFER,
  48207. out, outSz, 0, heap), 0);
  48208. ExpectNotNull(decompressed);
  48209. ExpectIntEQ(XMEMCMP(decompressed, cert_buf, cert_sz), 0);
  48210. XFREE(decompressed, heap, DYNAMIC_TYPE_TMP_BUFFER);
  48211. decompressed = NULL;
  48212. ExpectIntGT(wc_DeCompressDynamic(&decompressed, DYNAMIC_TYPE_TMP_BUFFER, 5,
  48213. out, outSz, 0, heap), 0);
  48214. ExpectNotNull(decompressed);
  48215. ExpectIntEQ(XMEMCMP(decompressed, cert_buf, cert_sz), 0);
  48216. XFREE(decompressed, heap, DYNAMIC_TYPE_TMP_BUFFER);
  48217. if (cert_buf != NULL)
  48218. free(cert_buf);
  48219. wc_PKCS7_Free(pkcs7);
  48220. #endif
  48221. return EXPECT_RESULT();
  48222. }
  48223. static int test_wc_i2d_PKCS12(void)
  48224. {
  48225. EXPECT_DECLS;
  48226. #if !defined(NO_ASN) && !defined(NO_PWDBASED) && defined(HAVE_PKCS12) \
  48227. && !defined(NO_FILESYSTEM) && !defined(NO_RSA) \
  48228. && !defined(NO_AES) && !defined(NO_SHA)
  48229. WC_PKCS12* pkcs12 = NULL;
  48230. unsigned char der[FOURK_BUF * 2];
  48231. unsigned char* pt;
  48232. int derSz = 0;
  48233. unsigned char out[FOURK_BUF * 2];
  48234. int outSz = FOURK_BUF * 2;
  48235. const char p12_f[] = "./certs/test-servercert.p12";
  48236. XFILE f = XBADFILE;
  48237. ExpectTrue((f = XFOPEN(p12_f, "rb")) != XBADFILE);
  48238. ExpectIntGT(derSz = (int)XFREAD(der, 1, sizeof(der), f), 0);
  48239. if (f != XBADFILE)
  48240. XFCLOSE(f);
  48241. ExpectNotNull(pkcs12 = wc_PKCS12_new());
  48242. ExpectIntEQ(wc_d2i_PKCS12(der, (word32)derSz, pkcs12), 0);
  48243. ExpectIntEQ(wc_i2d_PKCS12(pkcs12, NULL, &outSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  48244. ExpectIntEQ(outSz, derSz);
  48245. outSz = derSz - 1;
  48246. pt = out;
  48247. ExpectIntLE(wc_i2d_PKCS12(pkcs12, &pt, &outSz), 0);
  48248. outSz = derSz;
  48249. ExpectIntEQ(wc_i2d_PKCS12(pkcs12, &pt, &outSz), derSz);
  48250. ExpectIntEQ((pt == out), 0);
  48251. pt = NULL;
  48252. ExpectIntEQ(wc_i2d_PKCS12(pkcs12, &pt, NULL), derSz);
  48253. XFREE(pt, NULL, DYNAMIC_TYPE_PKCS);
  48254. wc_PKCS12_free(pkcs12);
  48255. pkcs12 = NULL;
  48256. /* Run the same test but use wc_d2i_PKCS12_fp. */
  48257. ExpectNotNull(pkcs12 = wc_PKCS12_new());
  48258. ExpectIntEQ(wc_d2i_PKCS12_fp("./certs/test-servercert.p12", &pkcs12), 0);
  48259. ExpectIntEQ(wc_i2d_PKCS12(pkcs12, NULL, &outSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  48260. ExpectIntEQ(outSz, derSz);
  48261. wc_PKCS12_free(pkcs12);
  48262. pkcs12 = NULL;
  48263. /* wc_d2i_PKCS12_fp can also allocate the PKCS12 object for the caller. */
  48264. ExpectIntEQ(wc_d2i_PKCS12_fp("./certs/test-servercert.p12", &pkcs12), 0);
  48265. ExpectIntEQ(wc_i2d_PKCS12(pkcs12, NULL, &outSz), WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  48266. ExpectIntEQ(outSz, derSz);
  48267. wc_PKCS12_free(pkcs12);
  48268. pkcs12 = NULL;
  48269. #endif
  48270. return EXPECT_RESULT();
  48271. }
  48272. /* Testing wc_SignatureGetSize() for signature type ECC */
  48273. static int test_wc_SignatureGetSize_ecc(void)
  48274. {
  48275. EXPECT_DECLS;
  48276. #if !defined(NO_SIG_WRAPPER) && defined(HAVE_ECC) && !defined(NO_ECC256)
  48277. enum wc_SignatureType sig_type;
  48278. word32 key_len;
  48279. ecc_key ecc;
  48280. const char* qx =
  48281. "fa2737fb93488d19caef11ae7faf6b7f4bcd67b286e3fc54e8a65c2b74aeccb0";
  48282. const char* qy =
  48283. "d4ccd6dae698208aa8c3a6f39e45510d03be09b2f124bfc067856c324f9b4d09";
  48284. const char* d =
  48285. "be34baa8d040a3b991f9075b56ba292f755b90e4b6dc10dad36715c33cfdac25";
  48286. XMEMSET(&ecc, 0, sizeof(ecc_key));
  48287. ExpectIntEQ(wc_ecc_init(&ecc), 0);
  48288. ExpectIntEQ(wc_ecc_import_raw(&ecc, qx, qy, d, "SECP256R1"), 0);
  48289. /* Input for signature type ECC */
  48290. sig_type = WC_SIGNATURE_TYPE_ECC;
  48291. key_len = sizeof(ecc_key);
  48292. ExpectIntGT(wc_SignatureGetSize(sig_type, &ecc, key_len), 0);
  48293. /* Test bad args */
  48294. /* // NOLINTBEGIN(clang-analyzer-optin.core.EnumCastOutOfRange) */
  48295. sig_type = (enum wc_SignatureType) 100;
  48296. /* // NOLINTEND(clang-analyzer-optin.core.EnumCastOutOfRange) */
  48297. ExpectIntEQ(wc_SignatureGetSize(sig_type, &ecc, key_len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48298. sig_type = WC_SIGNATURE_TYPE_ECC;
  48299. ExpectIntEQ(wc_SignatureGetSize(sig_type, NULL, key_len), 0);
  48300. key_len = (word32)0;
  48301. ExpectIntEQ(wc_SignatureGetSize(sig_type, &ecc, key_len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48302. DoExpectIntEQ(wc_ecc_free(&ecc), 0);
  48303. #endif /* !NO_SIG_WRAPPER && HAVE_ECC && !NO_ECC256 */
  48304. return EXPECT_RESULT();
  48305. } /* END test_wc_SignatureGetSize_ecc() */
  48306. /* Testing wc_SignatureGetSize() for signature type rsa */
  48307. static int test_wc_SignatureGetSize_rsa(void)
  48308. {
  48309. EXPECT_DECLS;
  48310. #if !defined(NO_SIG_WRAPPER) && !defined(NO_RSA)
  48311. enum wc_SignatureType sig_type;
  48312. word32 key_len;
  48313. word32 idx = 0;
  48314. RsaKey rsa_key;
  48315. byte* tmp = NULL;
  48316. size_t bytes;
  48317. XMEMSET(&rsa_key, 0, sizeof(RsaKey));
  48318. #ifdef USE_CERT_BUFFERS_1024
  48319. bytes = (size_t)sizeof_client_key_der_1024;
  48320. if (bytes < (size_t)sizeof_client_key_der_1024)
  48321. bytes = (size_t)sizeof_client_cert_der_1024;
  48322. #elif defined(USE_CERT_BUFFERS_2048)
  48323. bytes = (size_t)sizeof_client_key_der_2048;
  48324. if (bytes < (size_t)sizeof_client_cert_der_2048)
  48325. bytes = (size_t)sizeof_client_cert_der_2048;
  48326. #else
  48327. bytes = FOURK_BUF;
  48328. #endif
  48329. ExpectNotNull(tmp = (byte*)XMALLOC(bytes, HEAP_HINT,
  48330. DYNAMIC_TYPE_TMP_BUFFER));
  48331. if (tmp != NULL) {
  48332. #ifdef USE_CERT_BUFFERS_1024
  48333. XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_der_1024);
  48334. #elif defined(USE_CERT_BUFFERS_2048)
  48335. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  48336. #elif !defined(NO_FILESYSTEM)
  48337. XFILE file = XBADFILE;
  48338. ExpectTrue((file = XFOPEN(clientKey, "rb")) != XBADFILE);
  48339. ExpectIntGT(bytes = (size_t)XFREAD(tmp, 1, FOURK_BUF, file), 0);
  48340. if (file != XBADFILE)
  48341. XFCLOSE(file);
  48342. }
  48343. #else
  48344. ExpectFail();
  48345. #endif
  48346. }
  48347. ExpectIntEQ(wc_InitRsaKey_ex(&rsa_key, HEAP_HINT, testDevId), 0);
  48348. ExpectIntEQ(wc_RsaPrivateKeyDecode(tmp, &idx, &rsa_key, (word32)bytes), 0);
  48349. /* Input for signature type RSA */
  48350. sig_type = WC_SIGNATURE_TYPE_RSA;
  48351. key_len = sizeof(RsaKey);
  48352. ExpectIntGT(wc_SignatureGetSize(sig_type, &rsa_key, key_len), 0);
  48353. /* Test bad args */
  48354. /* // NOLINTBEGIN(clang-analyzer-optin.core.EnumCastOutOfRange) */
  48355. sig_type = (enum wc_SignatureType)100;
  48356. /* // NOLINTEND(clang-analyzer-optin.core.EnumCastOutOfRange) */
  48357. ExpectIntEQ(wc_SignatureGetSize(sig_type, &rsa_key, key_len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48358. sig_type = WC_SIGNATURE_TYPE_RSA;
  48359. ExpectIntEQ(wc_SignatureGetSize(sig_type, NULL, key_len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48360. key_len = (word32)0;
  48361. ExpectIntEQ(wc_SignatureGetSize(sig_type, &rsa_key, key_len), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48362. DoExpectIntEQ(wc_FreeRsaKey(&rsa_key), 0);
  48363. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48364. #endif /* !NO_SIG_WRAPPER && !NO_RSA */
  48365. return EXPECT_RESULT();
  48366. } /* END test_wc_SignatureGetSize_rsa(void) */
  48367. /*----------------------------------------------------------------------------*
  48368. | hash.h Tests
  48369. *----------------------------------------------------------------------------*/
  48370. static int test_wc_HashInit(void)
  48371. {
  48372. EXPECT_DECLS;
  48373. int i; /* 0 indicates tests passed, 1 indicates failure */
  48374. wc_HashAlg hash;
  48375. /* enum for holding supported algorithms, #ifndef's restrict if disabled */
  48376. enum wc_HashType enumArray[] = {
  48377. #ifndef NO_MD5
  48378. WC_HASH_TYPE_MD5,
  48379. #endif
  48380. #ifndef NO_SHA
  48381. WC_HASH_TYPE_SHA,
  48382. #endif
  48383. #ifdef WOLFSSL_SHA224
  48384. WC_HASH_TYPE_SHA224,
  48385. #endif
  48386. #ifndef NO_SHA256
  48387. WC_HASH_TYPE_SHA256,
  48388. #endif
  48389. #ifdef WOLFSSL_SHA384
  48390. WC_HASH_TYPE_SHA384,
  48391. #endif
  48392. #ifdef WOLFSSL_SHA512
  48393. WC_HASH_TYPE_SHA512,
  48394. #endif
  48395. };
  48396. /* dynamically finds the length */
  48397. int enumlen = (sizeof(enumArray)/sizeof(enum wc_HashType));
  48398. /* For loop to test various arguments... */
  48399. for (i = 0; i < enumlen; i++) {
  48400. /* check for bad args */
  48401. ExpectIntEQ(wc_HashInit(&hash, enumArray[i]), 0);
  48402. wc_HashFree(&hash, enumArray[i]);
  48403. /* check for null ptr */
  48404. ExpectIntEQ(wc_HashInit(NULL, enumArray[i]), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48405. } /* end of for loop */
  48406. return EXPECT_RESULT();
  48407. } /* end of test_wc_HashInit */
  48408. /*
  48409. * Unit test function for wc_HashSetFlags()
  48410. */
  48411. static int test_wc_HashSetFlags(void)
  48412. {
  48413. EXPECT_DECLS;
  48414. #ifdef WOLFSSL_HASH_FLAGS
  48415. wc_HashAlg hash;
  48416. word32 flags = 0;
  48417. int i, j;
  48418. int notSupportedLen;
  48419. /* enum for holding supported algorithms, #ifndef's restrict if disabled */
  48420. enum wc_HashType enumArray[] = {
  48421. #ifndef NO_MD5
  48422. WC_HASH_TYPE_MD5,
  48423. #endif
  48424. #ifndef NO_SHA
  48425. WC_HASH_TYPE_SHA,
  48426. #endif
  48427. #ifdef WOLFSSL_SHA224
  48428. WC_HASH_TYPE_SHA224,
  48429. #endif
  48430. #ifndef NO_SHA256
  48431. WC_HASH_TYPE_SHA256,
  48432. #endif
  48433. #ifdef WOLFSSL_SHA384
  48434. WC_HASH_TYPE_SHA384,
  48435. #endif
  48436. #ifdef WOLFSSL_SHA512
  48437. WC_HASH_TYPE_SHA512,
  48438. #endif
  48439. #ifdef WOLFSSL_SHA3
  48440. WC_HASH_TYPE_SHA3_224,
  48441. #endif
  48442. };
  48443. enum wc_HashType notSupported[] = {
  48444. WC_HASH_TYPE_MD5_SHA,
  48445. WC_HASH_TYPE_MD2,
  48446. WC_HASH_TYPE_MD4,
  48447. WC_HASH_TYPE_BLAKE2B,
  48448. WC_HASH_TYPE_BLAKE2S,
  48449. WC_HASH_TYPE_NONE,
  48450. };
  48451. /* dynamically finds the length */
  48452. int enumlen = (sizeof(enumArray)/sizeof(enum wc_HashType));
  48453. /* For loop to test various arguments... */
  48454. for (i = 0; i < enumlen; i++) {
  48455. ExpectIntEQ(wc_HashInit(&hash, enumArray[i]), 0);
  48456. ExpectIntEQ(wc_HashSetFlags(&hash, enumArray[i], flags), 0);
  48457. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  48458. ExpectIntEQ(wc_HashSetFlags(NULL, enumArray[i], flags), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48459. wc_HashFree(&hash, enumArray[i]);
  48460. }
  48461. /* For loop to test not supported cases */
  48462. notSupportedLen = (sizeof(notSupported)/sizeof(enum wc_HashType));
  48463. for (j = 0; j < notSupportedLen; j++) {
  48464. ExpectIntEQ(wc_HashInit(&hash, notSupported[j]), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48465. ExpectIntEQ(wc_HashSetFlags(&hash, notSupported[j], flags),
  48466. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48467. ExpectIntEQ(wc_HashFree(&hash, notSupported[j]), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48468. }
  48469. #endif
  48470. return EXPECT_RESULT();
  48471. } /* END test_wc_HashSetFlags */
  48472. /*
  48473. * Unit test function for wc_HashGetFlags()
  48474. */
  48475. static int test_wc_HashGetFlags(void)
  48476. {
  48477. EXPECT_DECLS;
  48478. #ifdef WOLFSSL_HASH_FLAGS
  48479. wc_HashAlg hash;
  48480. word32 flags = 0;
  48481. int i, j;
  48482. /* enum for holding supported algorithms, #ifndef's restrict if disabled */
  48483. enum wc_HashType enumArray[] = {
  48484. #ifndef NO_MD5
  48485. WC_HASH_TYPE_MD5,
  48486. #endif
  48487. #ifndef NO_SHA
  48488. WC_HASH_TYPE_SHA,
  48489. #endif
  48490. #ifdef WOLFSSL_SHA224
  48491. WC_HASH_TYPE_SHA224,
  48492. #endif
  48493. #ifndef NO_SHA256
  48494. WC_HASH_TYPE_SHA256,
  48495. #endif
  48496. #ifdef WOLFSSL_SHA384
  48497. WC_HASH_TYPE_SHA384,
  48498. #endif
  48499. #ifdef WOLFSSL_SHA512
  48500. WC_HASH_TYPE_SHA512,
  48501. #endif
  48502. #ifdef WOLFSSL_SHA3
  48503. WC_HASH_TYPE_SHA3_224,
  48504. #endif
  48505. };
  48506. enum wc_HashType notSupported[] = {
  48507. WC_HASH_TYPE_MD5_SHA,
  48508. WC_HASH_TYPE_MD2,
  48509. WC_HASH_TYPE_MD4,
  48510. WC_HASH_TYPE_BLAKE2B,
  48511. WC_HASH_TYPE_BLAKE2S,
  48512. WC_HASH_TYPE_NONE,
  48513. };
  48514. int enumlen = (sizeof(enumArray)/sizeof(enum wc_HashType));
  48515. int notSupportedLen;
  48516. /* For loop to test various arguments... */
  48517. for (i = 0; i < enumlen; i++) {
  48518. ExpectIntEQ(wc_HashInit(&hash, enumArray[i]), 0);
  48519. ExpectIntEQ(wc_HashGetFlags(&hash, enumArray[i], &flags), 0);
  48520. ExpectTrue((flags & WC_HASH_FLAG_ISCOPY) == 0);
  48521. ExpectIntEQ(wc_HashGetFlags(NULL, enumArray[i], &flags), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48522. wc_HashFree(&hash, enumArray[i]);
  48523. }
  48524. /* For loop to test not supported cases */
  48525. notSupportedLen = (sizeof(notSupported)/sizeof(enum wc_HashType));
  48526. for (j = 0; j < notSupportedLen; j++) {
  48527. ExpectIntEQ(wc_HashInit(&hash, notSupported[j]), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48528. ExpectIntEQ(wc_HashGetFlags(&hash, notSupported[j], &flags),
  48529. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48530. ExpectIntEQ(wc_HashFree(&hash, notSupported[j]), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  48531. }
  48532. #endif
  48533. return EXPECT_RESULT();
  48534. } /* END test_wc_HashGetFlags */
  48535. /*----------------------------------------------------------------------------*
  48536. | Compatibility Tests
  48537. *----------------------------------------------------------------------------*/
  48538. /*----------------------------------------------------------------------------*
  48539. | ASN.1 Tests
  48540. *----------------------------------------------------------------------------*/
  48541. static int test_wolfSSL_ASN1_BIT_STRING(void)
  48542. {
  48543. EXPECT_DECLS;
  48544. #if !defined(NO_CERTS) && defined(OPENSSL_ALL)
  48545. ASN1_BIT_STRING* str = NULL;
  48546. ASN1_BIT_STRING* str2 = NULL;
  48547. unsigned char* der = NULL;
  48548. ExpectNotNull(str = ASN1_BIT_STRING_new());
  48549. /* Empty data testing. */
  48550. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 1), 0);
  48551. ASN1_BIT_STRING_free(str);
  48552. str = NULL;
  48553. ExpectNotNull(str = ASN1_BIT_STRING_new());
  48554. /* Invalid parameter testing. */
  48555. ExpectIntEQ(ASN1_BIT_STRING_set_bit(NULL, 42, 1), 0);
  48556. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, -1, 1), 0);
  48557. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 42, 2), 0);
  48558. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 42, -1), 0);
  48559. /* No bit string - bit is always 0. */
  48560. ExpectIntEQ(ASN1_BIT_STRING_get_bit(NULL, 42), 0);
  48561. ExpectIntEQ(ASN1_BIT_STRING_get_bit(NULL, -1), 0);
  48562. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, -1), 0);
  48563. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 0), 0);
  48564. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 42, 1), 1);
  48565. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 42), 1);
  48566. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 41), 0);
  48567. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, -1), 0);
  48568. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 84, 1), 1);
  48569. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 84), 1);
  48570. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 83), 0);
  48571. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 91, 0), 1);
  48572. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 91), 0);
  48573. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 89, 0), 1);
  48574. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 89), 0);
  48575. ExpectIntEQ(ASN1_BIT_STRING_set_bit(str, 42, 0), 1);
  48576. ExpectIntEQ(ASN1_BIT_STRING_get_bit(str, 42), 0);
  48577. ExpectIntEQ(i2d_ASN1_BIT_STRING(str, NULL), 14);
  48578. ExpectIntEQ(i2d_ASN1_BIT_STRING(str, &der), 14);
  48579. #ifdef WOLFSSL_ASN_TEMPLATE
  48580. {
  48581. const unsigned char* tmp = der;
  48582. ExpectNotNull(d2i_ASN1_BIT_STRING(&str2, &tmp, 14));
  48583. }
  48584. #endif
  48585. ASN1_BIT_STRING_free(str);
  48586. ASN1_BIT_STRING_free(str2);
  48587. ASN1_BIT_STRING_free(NULL);
  48588. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  48589. #endif
  48590. return EXPECT_RESULT();
  48591. }
  48592. static int test_wolfSSL_ASN1_INTEGER(void)
  48593. {
  48594. EXPECT_DECLS;
  48595. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  48596. ASN1_INTEGER* a = NULL;
  48597. ASN1_INTEGER* dup = NULL;
  48598. const unsigned char invalidLenDer[] = {
  48599. 0x02, 0x20, 0x00
  48600. };
  48601. const unsigned char longDer[] = {
  48602. 0x02, 0x20,
  48603. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  48604. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  48605. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  48606. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
  48607. };
  48608. const unsigned char* p;
  48609. /* Invalid parameter testing. */
  48610. ASN1_INTEGER_free(NULL);
  48611. ExpectNull(wolfSSL_ASN1_INTEGER_dup(NULL));
  48612. ExpectNotNull(a = ASN1_INTEGER_new());
  48613. ExpectNotNull(dup = wolfSSL_ASN1_INTEGER_dup(a));
  48614. ASN1_INTEGER_free(dup);
  48615. dup = NULL;
  48616. ASN1_INTEGER_free(a);
  48617. a = NULL;
  48618. p = invalidLenDer;
  48619. ExpectNull(d2i_ASN1_INTEGER(NULL, &p, sizeof(invalidLenDer)));
  48620. p = longDer;
  48621. ExpectNotNull(a = d2i_ASN1_INTEGER(NULL, &p, sizeof(longDer)));
  48622. ExpectPtrNE(p, longDer);
  48623. ExpectNotNull(dup = wolfSSL_ASN1_INTEGER_dup(a));
  48624. ASN1_INTEGER_free(dup);
  48625. ASN1_INTEGER_free(a);
  48626. #endif
  48627. return EXPECT_RESULT();
  48628. }
  48629. static int test_wolfSSL_ASN1_INTEGER_cmp(void)
  48630. {
  48631. EXPECT_DECLS;
  48632. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  48633. ASN1_INTEGER* a = NULL;
  48634. ASN1_INTEGER* b = NULL;
  48635. ExpectNotNull(a = ASN1_INTEGER_new());
  48636. ExpectNotNull(b = ASN1_INTEGER_new());
  48637. ExpectIntEQ(ASN1_INTEGER_set(a, 1), 1);
  48638. ExpectIntEQ(ASN1_INTEGER_set(b, 1), 1);
  48639. /* Invalid parameter testing. */
  48640. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(NULL, NULL), -1);
  48641. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(a, NULL), -1);
  48642. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(NULL, b), -1);
  48643. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  48644. ExpectIntEQ(ASN1_INTEGER_set(b, -1), 1);
  48645. ExpectIntGT(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  48646. ExpectIntEQ(ASN1_INTEGER_set(a, -2), 1);
  48647. ExpectIntLT(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  48648. ExpectIntEQ(ASN1_INTEGER_set(b, 1), 1);
  48649. ExpectIntLT(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  48650. ExpectIntEQ(ASN1_INTEGER_set(a, 0x01), 1);
  48651. ExpectIntEQ(ASN1_INTEGER_set(b, 0x1000), 1);
  48652. ExpectIntLT(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  48653. ExpectIntGT(wolfSSL_ASN1_INTEGER_cmp(b, a), 0);
  48654. ASN1_INTEGER_free(b);
  48655. ASN1_INTEGER_free(a);
  48656. #endif
  48657. return EXPECT_RESULT();
  48658. }
  48659. static int test_wolfSSL_ASN1_INTEGER_BN(void)
  48660. {
  48661. EXPECT_DECLS;
  48662. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  48663. ASN1_INTEGER* ai = NULL;
  48664. ASN1_INTEGER* ai2 = NULL;
  48665. BIGNUM* bn = NULL;
  48666. BIGNUM* bn2 = NULL;
  48667. ExpectNotNull(ai = ASN1_INTEGER_new());
  48668. ExpectNotNull(bn2 = BN_new());
  48669. /* Invalid parameter testing. */
  48670. ExpectNull(bn = ASN1_INTEGER_to_BN(NULL, NULL));
  48671. ExpectNull(ai2 = BN_to_ASN1_INTEGER(NULL, NULL));
  48672. /* at the moment hard setting since no set function */
  48673. if (ai != NULL) {
  48674. ai->data[0] = 0xff; /* No DER encoding. */
  48675. ai->length = 1;
  48676. }
  48677. #if defined(WOLFSSL_QT) || defined(WOLFSSL_HAPROXY)
  48678. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, NULL));
  48679. BN_free(bn);
  48680. bn = NULL;
  48681. #else
  48682. ExpectNull(ASN1_INTEGER_to_BN(ai, NULL));
  48683. #endif
  48684. if (ai != NULL) {
  48685. ai->data[0] = 0x02; /* tag for ASN_INTEGER */
  48686. ai->data[1] = 0x04; /* bad length of integer */
  48687. ai->data[2] = 0x03;
  48688. ai->length = 3;
  48689. }
  48690. #if defined(WOLFSSL_QT) || defined(WOLFSSL_HAPROXY)
  48691. /* Interpreted as a number 0x020403. */
  48692. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, NULL));
  48693. BN_free(bn);
  48694. bn = NULL;
  48695. #else
  48696. ExpectNull(ASN1_INTEGER_to_BN(ai, NULL));
  48697. #endif
  48698. if (ai != NULL) {
  48699. ai->data[0] = 0x02; /* tag for ASN_INTEGER */
  48700. ai->data[1] = 0x01; /* length of integer */
  48701. ai->data[2] = 0x03;
  48702. ai->length = 3;
  48703. }
  48704. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, NULL));
  48705. ExpectNotNull(ai2 = BN_to_ASN1_INTEGER(bn, NULL));
  48706. ExpectIntEQ(ASN1_INTEGER_cmp(ai, ai2), 0);
  48707. ExpectNotNull(bn2 = ASN1_INTEGER_to_BN(ai2, bn2));
  48708. ExpectIntEQ(BN_cmp(bn, bn2), 0);
  48709. if (ai != NULL) {
  48710. ai->data[0] = 0x02; /* tag for ASN_INTEGER */
  48711. ai->data[1] = 0x02; /* length of integer */
  48712. ai->data[2] = 0x00; /* padding byte to ensure positive */
  48713. ai->data[3] = 0xff;
  48714. ai->length = 4;
  48715. }
  48716. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, bn));
  48717. ExpectNotNull(ai2 = BN_to_ASN1_INTEGER(bn, ai2));
  48718. ExpectIntEQ(ASN1_INTEGER_cmp(ai, ai2), 0);
  48719. ExpectNotNull(bn2 = ASN1_INTEGER_to_BN(ai2, bn2));
  48720. ExpectIntEQ(BN_cmp(bn, bn2), 0);
  48721. if (ai != NULL) {
  48722. ai->data[0] = 0x02; /* tag for ASN_INTEGER */
  48723. ai->data[1] = 0x01; /* length of integer */
  48724. ai->data[2] = 0x00;
  48725. ai->length = 3;
  48726. }
  48727. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, bn));
  48728. ExpectNotNull(ai2 = BN_to_ASN1_INTEGER(bn, ai2));
  48729. ExpectIntEQ(ASN1_INTEGER_cmp(ai, ai2), 0);
  48730. ExpectNotNull(bn2 = ASN1_INTEGER_to_BN(ai2, bn2));
  48731. ExpectIntEQ(BN_cmp(bn, bn2), 0);
  48732. if (ai != NULL) {
  48733. ai->data[0] = 0x02; /* tag for ASN_INTEGER */
  48734. ai->data[1] = 0x01; /* length of integer */
  48735. ai->data[2] = 0x01;
  48736. ai->length = 3;
  48737. ai->negative = 1;
  48738. }
  48739. ExpectNotNull(bn = ASN1_INTEGER_to_BN(ai, bn));
  48740. ExpectNotNull(ai2 = BN_to_ASN1_INTEGER(bn, ai2));
  48741. ExpectIntEQ(ASN1_INTEGER_cmp(ai, ai2), 0);
  48742. ExpectNotNull(bn2 = ASN1_INTEGER_to_BN(ai2, bn2));
  48743. ExpectIntEQ(BN_cmp(bn, bn2), 0);
  48744. BN_free(bn2);
  48745. BN_free(bn);
  48746. ASN1_INTEGER_free(ai2);
  48747. ASN1_INTEGER_free(ai);
  48748. #endif
  48749. return EXPECT_RESULT();
  48750. }
  48751. static int test_wolfSSL_ASN1_INTEGER_get_set(void)
  48752. {
  48753. EXPECT_DECLS;
  48754. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  48755. ASN1_INTEGER *a = NULL;
  48756. long val;
  48757. ExpectNotNull(a = ASN1_INTEGER_new());
  48758. /* Invalid parameter testing. */
  48759. ExpectIntEQ(ASN1_INTEGER_get(NULL), 0);
  48760. #if defined(WOLFSSL_QT) || defined(WOLFSSL_HAPROXY)
  48761. ExpectIntEQ(ASN1_INTEGER_get(a), 0);
  48762. #else
  48763. ExpectIntEQ(ASN1_INTEGER_get(a), -1);
  48764. #endif
  48765. ASN1_INTEGER_free(a);
  48766. a = NULL;
  48767. ExpectNotNull(a = ASN1_INTEGER_new());
  48768. val = 0;
  48769. ExpectIntEQ(ASN1_INTEGER_set(NULL, val), 0);
  48770. ASN1_INTEGER_free(a);
  48771. a = NULL;
  48772. /* 0 */
  48773. ExpectNotNull(a = ASN1_INTEGER_new());
  48774. val = 0;
  48775. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  48776. ExpectTrue(ASN1_INTEGER_get(a) == val);
  48777. ASN1_INTEGER_free(a);
  48778. a = NULL;
  48779. /* 40 */
  48780. ExpectNotNull(a = ASN1_INTEGER_new());
  48781. val = 40;
  48782. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  48783. ExpectTrue(ASN1_INTEGER_get(a) == val);
  48784. ASN1_INTEGER_free(a);
  48785. a = NULL;
  48786. /* -40 */
  48787. ExpectNotNull(a = ASN1_INTEGER_new());
  48788. val = -40;
  48789. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  48790. ExpectTrue(ASN1_INTEGER_get(a) == val);
  48791. ASN1_INTEGER_free(a);
  48792. a = NULL;
  48793. /* 128 */
  48794. ExpectNotNull(a = ASN1_INTEGER_new());
  48795. val = 128;
  48796. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  48797. ExpectTrue(ASN1_INTEGER_get(a) == val);
  48798. ASN1_INTEGER_free(a);
  48799. a = NULL;
  48800. /* -128 */
  48801. ExpectNotNull(a = ASN1_INTEGER_new());
  48802. val = -128;
  48803. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  48804. ExpectTrue(ASN1_INTEGER_get(a) == val);
  48805. ASN1_INTEGER_free(a);
  48806. a = NULL;
  48807. /* 200 */
  48808. ExpectNotNull(a = ASN1_INTEGER_new());
  48809. val = 200;
  48810. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  48811. ExpectTrue(ASN1_INTEGER_get(a) == val);
  48812. ASN1_INTEGER_free(a);
  48813. a = NULL;
  48814. /* int max (2147483647) */
  48815. ExpectNotNull(a = ASN1_INTEGER_new());
  48816. val = 2147483647;
  48817. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  48818. ExpectTrue(ASN1_INTEGER_get(a) == val);
  48819. ASN1_INTEGER_free(a);
  48820. a = NULL;
  48821. /* int min (-2147483648) */
  48822. ExpectNotNull(a = ASN1_INTEGER_new());
  48823. val = -2147483647 - 1;
  48824. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  48825. ExpectTrue(ASN1_INTEGER_get(a) == val);
  48826. ASN1_INTEGER_free(a);
  48827. a = NULL;
  48828. /* long max positive */
  48829. ExpectNotNull(a = ASN1_INTEGER_new());
  48830. val = (long)(((unsigned long)-1) >> 1);
  48831. ExpectIntEQ(ASN1_INTEGER_set(a, val), 1);
  48832. ExpectTrue(ASN1_INTEGER_get(a) == val);
  48833. ASN1_INTEGER_free(a);
  48834. #endif
  48835. return EXPECT_RESULT();
  48836. }
  48837. #if defined(OPENSSL_EXTRA)
  48838. typedef struct ASN1IntTestVector {
  48839. const byte* der;
  48840. const size_t derSz;
  48841. const long value;
  48842. } ASN1IntTestVector;
  48843. #endif
  48844. static int test_wolfSSL_d2i_ASN1_INTEGER(void)
  48845. {
  48846. EXPECT_DECLS;
  48847. #if defined(OPENSSL_EXTRA)
  48848. size_t i;
  48849. WOLFSSL_ASN1_INTEGER* a = NULL;
  48850. WOLFSSL_ASN1_INTEGER* b = NULL;
  48851. WOLFSSL_ASN1_INTEGER* c = NULL;
  48852. const byte* p = NULL;
  48853. byte* p2 = NULL;
  48854. byte* reEncoded = NULL;
  48855. int reEncodedSz = 0;
  48856. static const byte zeroDer[] = {
  48857. 0x02, 0x01, 0x00
  48858. };
  48859. static const byte oneDer[] = {
  48860. 0x02, 0x01, 0x01
  48861. };
  48862. static const byte negativeDer[] = {
  48863. 0x02, 0x03, 0xC1, 0x16, 0x0D
  48864. };
  48865. static const byte positiveDer[] = {
  48866. 0x02, 0x03, 0x01, 0x00, 0x01
  48867. };
  48868. static const byte primeDer[] = {
  48869. 0x02, 0x82, 0x01, 0x01, 0x00, 0xc0, 0x95, 0x08, 0xe1, 0x57, 0x41,
  48870. 0xf2, 0x71, 0x6d, 0xb7, 0xd2, 0x45, 0x41, 0x27, 0x01, 0x65, 0xc6,
  48871. 0x45, 0xae, 0xf2, 0xbc, 0x24, 0x30, 0xb8, 0x95, 0xce, 0x2f, 0x4e,
  48872. 0xd6, 0xf6, 0x1c, 0x88, 0xbc, 0x7c, 0x9f, 0xfb, 0xa8, 0x67, 0x7f,
  48873. 0xfe, 0x5c, 0x9c, 0x51, 0x75, 0xf7, 0x8a, 0xca, 0x07, 0xe7, 0x35,
  48874. 0x2f, 0x8f, 0xe1, 0xbd, 0x7b, 0xc0, 0x2f, 0x7c, 0xab, 0x64, 0xa8,
  48875. 0x17, 0xfc, 0xca, 0x5d, 0x7b, 0xba, 0xe0, 0x21, 0xe5, 0x72, 0x2e,
  48876. 0x6f, 0x2e, 0x86, 0xd8, 0x95, 0x73, 0xda, 0xac, 0x1b, 0x53, 0xb9,
  48877. 0x5f, 0x3f, 0xd7, 0x19, 0x0d, 0x25, 0x4f, 0xe1, 0x63, 0x63, 0x51,
  48878. 0x8b, 0x0b, 0x64, 0x3f, 0xad, 0x43, 0xb8, 0xa5, 0x1c, 0x5c, 0x34,
  48879. 0xb3, 0xae, 0x00, 0xa0, 0x63, 0xc5, 0xf6, 0x7f, 0x0b, 0x59, 0x68,
  48880. 0x78, 0x73, 0xa6, 0x8c, 0x18, 0xa9, 0x02, 0x6d, 0xaf, 0xc3, 0x19,
  48881. 0x01, 0x2e, 0xb8, 0x10, 0xe3, 0xc6, 0xcc, 0x40, 0xb4, 0x69, 0xa3,
  48882. 0x46, 0x33, 0x69, 0x87, 0x6e, 0xc4, 0xbb, 0x17, 0xa6, 0xf3, 0xe8,
  48883. 0xdd, 0xad, 0x73, 0xbc, 0x7b, 0x2f, 0x21, 0xb5, 0xfd, 0x66, 0x51,
  48884. 0x0c, 0xbd, 0x54, 0xb3, 0xe1, 0x6d, 0x5f, 0x1c, 0xbc, 0x23, 0x73,
  48885. 0xd1, 0x09, 0x03, 0x89, 0x14, 0xd2, 0x10, 0xb9, 0x64, 0xc3, 0x2a,
  48886. 0xd0, 0xa1, 0x96, 0x4a, 0xbc, 0xe1, 0xd4, 0x1a, 0x5b, 0xc7, 0xa0,
  48887. 0xc0, 0xc1, 0x63, 0x78, 0x0f, 0x44, 0x37, 0x30, 0x32, 0x96, 0x80,
  48888. 0x32, 0x23, 0x95, 0xa1, 0x77, 0xba, 0x13, 0xd2, 0x97, 0x73, 0xe2,
  48889. 0x5d, 0x25, 0xc9, 0x6a, 0x0d, 0xc3, 0x39, 0x60, 0xa4, 0xb4, 0xb0,
  48890. 0x69, 0x42, 0x42, 0x09, 0xe9, 0xd8, 0x08, 0xbc, 0x33, 0x20, 0xb3,
  48891. 0x58, 0x22, 0xa7, 0xaa, 0xeb, 0xc4, 0xe1, 0xe6, 0x61, 0x83, 0xc5,
  48892. 0xd2, 0x96, 0xdf, 0xd9, 0xd0, 0x4f, 0xad, 0xd7
  48893. };
  48894. static const byte garbageDer[] = {0xDE, 0xAD, 0xBE, 0xEF};
  48895. static const ASN1IntTestVector testVectors[] = {
  48896. {zeroDer, sizeof(zeroDer), 0},
  48897. {oneDer, sizeof(oneDer), 1},
  48898. {negativeDer, sizeof(negativeDer), -4123123},
  48899. {positiveDer, sizeof(positiveDer), 65537},
  48900. {primeDer, sizeof(primeDer), 0}
  48901. };
  48902. static const size_t NUM_TEST_VECTORS =
  48903. sizeof(testVectors)/sizeof(testVectors[0]);
  48904. /* Check d2i error conditions */
  48905. /* NULL pointer to input. */
  48906. ExpectNull((a = wolfSSL_d2i_ASN1_INTEGER(&b, NULL, 1)));
  48907. ExpectNull(b);
  48908. /* NULL input. */
  48909. ExpectNull((a = wolfSSL_d2i_ASN1_INTEGER(&b, &p, 1)));
  48910. ExpectNull(b);
  48911. /* 0 length. */
  48912. p = testVectors[0].der;
  48913. ExpectNull((a = wolfSSL_d2i_ASN1_INTEGER(&b, &p, 0)));
  48914. ExpectNull(b);
  48915. /* Negative length. */
  48916. p = testVectors[0].der;
  48917. ExpectNull((a = wolfSSL_d2i_ASN1_INTEGER(&b, &p, -1)));
  48918. ExpectNull(b);
  48919. /* Garbage DER input. */
  48920. p = garbageDer;
  48921. ExpectNull((a = wolfSSL_d2i_ASN1_INTEGER(&b, &p, sizeof(garbageDer))));
  48922. ExpectNull(b);
  48923. /* Check i2d error conditions */
  48924. /* NULL input. */
  48925. ExpectIntLT(wolfSSL_i2d_ASN1_INTEGER(NULL, &p2), 0);
  48926. /* 0 length input data buffer (a->length == 0). */
  48927. ExpectNotNull((a = wolfSSL_ASN1_INTEGER_new()));
  48928. ExpectIntLT(wolfSSL_i2d_ASN1_INTEGER(a, &p2), 0);
  48929. if (a != NULL)
  48930. a->data = NULL;
  48931. /* NULL input data buffer. */
  48932. ExpectIntLT(wolfSSL_i2d_ASN1_INTEGER(a, &p2), 0);
  48933. if (a != NULL) {
  48934. /* Reset a->data. */
  48935. a->data = a->intData;
  48936. }
  48937. /* Set a to valid value. */
  48938. ExpectIntEQ(wolfSSL_ASN1_INTEGER_set(a, 1), WOLFSSL_SUCCESS);
  48939. /* NULL output buffer. */
  48940. ExpectIntEQ(wolfSSL_i2d_ASN1_INTEGER(a, NULL), 3);
  48941. wolfSSL_ASN1_INTEGER_free(a);
  48942. a = NULL;
  48943. for (i = 0; i < NUM_TEST_VECTORS; ++i) {
  48944. p = testVectors[i].der;
  48945. ExpectNotNull(a = wolfSSL_d2i_ASN1_INTEGER(&b, &p,
  48946. testVectors[i].derSz));
  48947. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(a, b), 0);
  48948. if (testVectors[i].derSz <= sizeof(long)) {
  48949. ExpectNotNull(c = wolfSSL_ASN1_INTEGER_new());
  48950. ExpectIntEQ(wolfSSL_ASN1_INTEGER_set(c, testVectors[i].value), 1);
  48951. ExpectIntEQ(wolfSSL_ASN1_INTEGER_cmp(a, c), 0);
  48952. wolfSSL_ASN1_INTEGER_free(c);
  48953. c = NULL;
  48954. }
  48955. /* Convert to DER without a pre-allocated output buffer. */
  48956. ExpectIntGT((reEncodedSz = wolfSSL_i2d_ASN1_INTEGER(a, &reEncoded)), 0);
  48957. ExpectIntEQ(reEncodedSz, testVectors[i].derSz);
  48958. ExpectIntEQ(XMEMCMP(reEncoded, testVectors[i].der, reEncodedSz), 0);
  48959. /* Convert to DER with a pre-allocated output buffer. In this case, the
  48960. * output buffer pointer should be incremented just past the end of the
  48961. * encoded data. */
  48962. p2 = reEncoded;
  48963. ExpectIntGT((reEncodedSz = wolfSSL_i2d_ASN1_INTEGER(a, &p2)), 0);
  48964. ExpectIntEQ(reEncodedSz, testVectors[i].derSz);
  48965. ExpectPtrEq(reEncoded, p2 - reEncodedSz);
  48966. ExpectIntEQ(XMEMCMP(reEncoded, testVectors[i].der, reEncodedSz), 0);
  48967. XFREE(reEncoded, NULL, DYNAMIC_TYPE_ASN1);
  48968. reEncoded = NULL;
  48969. wolfSSL_ASN1_INTEGER_free(a);
  48970. a = NULL;
  48971. }
  48972. #endif /* OPENSSL_EXTRA */
  48973. return EXPECT_RESULT();
  48974. }
  48975. static int test_wolfSSL_a2i_ASN1_INTEGER(void)
  48976. {
  48977. EXPECT_DECLS;
  48978. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  48979. BIO* bio = NULL;
  48980. BIO* out = NULL;
  48981. BIO* fixed = NULL;
  48982. ASN1_INTEGER* ai = NULL;
  48983. char buf[] = "123456\n12345\n1123456789123456\\\n78901234567890 \r\n\n";
  48984. char tmp[1024];
  48985. int tmpSz;
  48986. const char expected1[] = "123456";
  48987. const char expected2[] = "112345678912345678901234567890";
  48988. char longStr[] = "123456781234567812345678123456781234567812345678\n"
  48989. "123456781234567812345678123456781234567812345678\\\n12345678\n";
  48990. ExpectNotNull(out = BIO_new(BIO_s_mem()));
  48991. ExpectNotNull(ai = ASN1_INTEGER_new());
  48992. ExpectNotNull(bio = BIO_new_mem_buf(buf, -1));
  48993. /* Invalid parameter testing. */
  48994. ExpectIntEQ(a2i_ASN1_INTEGER(NULL, NULL, NULL, -1), 0);
  48995. ExpectIntEQ(a2i_ASN1_INTEGER(bio, NULL, NULL, -1), 0);
  48996. ExpectIntEQ(a2i_ASN1_INTEGER(NULL, ai, NULL, -1), 0);
  48997. ExpectIntEQ(a2i_ASN1_INTEGER(NULL, NULL, tmp, -1), 0);
  48998. ExpectIntEQ(a2i_ASN1_INTEGER(NULL, NULL, NULL, 1024), 0);
  48999. ExpectIntEQ(a2i_ASN1_INTEGER(NULL, ai, tmp, 1024), 0);
  49000. ExpectIntEQ(a2i_ASN1_INTEGER(bio, NULL, tmp, 1024), 0);
  49001. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, NULL, 1024), 0);
  49002. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, -1), 0);
  49003. ExpectIntEQ(i2a_ASN1_INTEGER(NULL, NULL), 0);
  49004. ExpectIntEQ(i2a_ASN1_INTEGER(bio, NULL), 0);
  49005. ExpectIntEQ(i2a_ASN1_INTEGER(NULL, ai), 0);
  49006. /* No data to read from BIO. */
  49007. ExpectIntEQ(a2i_ASN1_INTEGER(out, ai, tmp, 1024), 0);
  49008. /* read first line */
  49009. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 1);
  49010. ExpectIntEQ(i2a_ASN1_INTEGER(out, ai), 6);
  49011. XMEMSET(tmp, 0, 1024);
  49012. tmpSz = BIO_read(out, tmp, 1024);
  49013. ExpectIntEQ(tmpSz, 6);
  49014. ExpectIntEQ(XMEMCMP(tmp, expected1, tmpSz), 0);
  49015. /* fail on second line (not % 2) */
  49016. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 0);
  49017. /* read 3rd long line */
  49018. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 1);
  49019. ExpectIntEQ(i2a_ASN1_INTEGER(out, ai), 30);
  49020. XMEMSET(tmp, 0, 1024);
  49021. tmpSz = BIO_read(out, tmp, 1024);
  49022. ExpectIntEQ(tmpSz, 30);
  49023. ExpectIntEQ(XMEMCMP(tmp, expected2, tmpSz), 0);
  49024. /* fail on empty line */
  49025. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 0);
  49026. BIO_free(bio);
  49027. bio = NULL;
  49028. /* Make long integer, requiring dynamic memory, even longer. */
  49029. ExpectNotNull(bio = BIO_new_mem_buf(longStr, -1));
  49030. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 1);
  49031. ExpectIntEQ(i2a_ASN1_INTEGER(out, ai), 48);
  49032. XMEMSET(tmp, 0, 1024);
  49033. tmpSz = BIO_read(out, tmp, 1024);
  49034. ExpectIntEQ(tmpSz, 48);
  49035. ExpectIntEQ(a2i_ASN1_INTEGER(bio, ai, tmp, 1024), 1);
  49036. ExpectIntEQ(i2a_ASN1_INTEGER(out, ai), 56);
  49037. XMEMSET(tmp, 0, 1024);
  49038. tmpSz = BIO_read(out, tmp, 1024);
  49039. ExpectIntEQ(tmpSz, 56);
  49040. ExpectIntEQ(wolfSSL_ASN1_INTEGER_set(ai, 1), 1);
  49041. BIO_free(bio);
  49042. BIO_free(out);
  49043. ExpectNotNull(fixed = BIO_new(wolfSSL_BIO_s_fixed_mem()));
  49044. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  49045. /* Ensure there is 0 bytes available to write into. */
  49046. ExpectIntEQ(BIO_write(fixed, tmp, 1), 1);
  49047. ExpectIntEQ(i2a_ASN1_INTEGER(fixed, ai), 0);
  49048. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  49049. ExpectIntEQ(i2a_ASN1_INTEGER(fixed, ai), 0);
  49050. BIO_free(fixed);
  49051. ASN1_INTEGER_free(ai);
  49052. #endif
  49053. return EXPECT_RESULT();
  49054. }
  49055. static int test_wolfSSL_i2c_ASN1_INTEGER(void)
  49056. {
  49057. EXPECT_DECLS;
  49058. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  49059. ASN1_INTEGER *a = NULL;
  49060. unsigned char *pp = NULL,*tpp = NULL;
  49061. int ret = 0;
  49062. ExpectNotNull(a = wolfSSL_ASN1_INTEGER_new());
  49063. /* Invalid parameter testing. */
  49064. /* Set pp to an invalid value. */
  49065. pp = NULL;
  49066. ExpectIntEQ(i2c_ASN1_INTEGER(NULL, &pp), 0);
  49067. ExpectIntEQ(i2c_ASN1_INTEGER(a, &pp), 0);
  49068. ExpectIntEQ(i2c_ASN1_INTEGER(NULL, NULL), 0);
  49069. /* 40 */
  49070. if (a != NULL) {
  49071. a->intData[0] = ASN_INTEGER;
  49072. a->intData[1] = 1;
  49073. a->intData[2] = 40;
  49074. }
  49075. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 1);
  49076. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  49077. DYNAMIC_TYPE_TMP_BUFFER));
  49078. tpp = pp;
  49079. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  49080. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 1);
  49081. tpp--;
  49082. ExpectIntEQ(*tpp, 40);
  49083. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49084. pp = NULL;
  49085. /* 128 */
  49086. if (a != NULL) {
  49087. a->intData[0] = ASN_INTEGER;
  49088. a->intData[1] = 1;
  49089. a->intData[2] = 128;
  49090. }
  49091. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 2);
  49092. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  49093. DYNAMIC_TYPE_TMP_BUFFER));
  49094. tpp = pp;
  49095. if (tpp != NULL) {
  49096. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  49097. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 2);
  49098. tpp--;
  49099. ExpectIntEQ(*(tpp--), 128);
  49100. ExpectIntEQ(*tpp, 0);
  49101. }
  49102. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49103. pp = NULL;
  49104. /* -40 */
  49105. if (a != NULL) {
  49106. a->intData[0] = ASN_INTEGER;
  49107. a->intData[1] = 1;
  49108. a->intData[2] = 40;
  49109. a->negative = 1;
  49110. }
  49111. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 1);
  49112. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  49113. DYNAMIC_TYPE_TMP_BUFFER));
  49114. tpp = pp;
  49115. if (tpp != NULL) {
  49116. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  49117. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 1);
  49118. tpp--;
  49119. ExpectIntEQ(*tpp, 216);
  49120. }
  49121. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49122. pp = NULL;
  49123. /* -128 */
  49124. if (a != NULL) {
  49125. a->intData[0] = ASN_INTEGER;
  49126. a->intData[1] = 1;
  49127. a->intData[2] = 128;
  49128. a->negative = 1;
  49129. }
  49130. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 1);
  49131. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  49132. DYNAMIC_TYPE_TMP_BUFFER));
  49133. tpp = pp;
  49134. if (tpp != NULL) {
  49135. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  49136. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 1);
  49137. tpp--;
  49138. ExpectIntEQ(*tpp, 128);
  49139. }
  49140. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49141. pp = NULL;
  49142. /* -200 */
  49143. if (a != NULL) {
  49144. a->intData[0] = ASN_INTEGER;
  49145. a->intData[1] = 1;
  49146. a->intData[2] = 200;
  49147. a->negative = 1;
  49148. }
  49149. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 2);
  49150. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  49151. DYNAMIC_TYPE_TMP_BUFFER));
  49152. tpp = pp;
  49153. if (tpp != NULL) {
  49154. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  49155. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 2);
  49156. tpp--;
  49157. ExpectIntEQ(*(tpp--), 56);
  49158. ExpectIntEQ(*tpp, 255);
  49159. }
  49160. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49161. pp = NULL;
  49162. /* Empty */
  49163. if (a != NULL) {
  49164. a->intData[0] = ASN_INTEGER;
  49165. a->intData[1] = 0;
  49166. a->negative = 0;
  49167. }
  49168. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 1);
  49169. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  49170. DYNAMIC_TYPE_TMP_BUFFER));
  49171. tpp = pp;
  49172. if (tpp != NULL) {
  49173. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  49174. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 1);
  49175. tpp--;
  49176. ExpectIntEQ(*tpp, 0);
  49177. }
  49178. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49179. pp = NULL;
  49180. /* 0 */
  49181. if (a != NULL) {
  49182. a->intData[0] = ASN_INTEGER;
  49183. a->intData[1] = 1;
  49184. a->intData[2] = 0;
  49185. a->negative = 1;
  49186. }
  49187. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 1);
  49188. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  49189. DYNAMIC_TYPE_TMP_BUFFER));
  49190. if (tpp != NULL) {
  49191. tpp = pp;
  49192. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  49193. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 1);
  49194. tpp--;
  49195. ExpectIntEQ(*tpp, 0);
  49196. }
  49197. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49198. pp = NULL;
  49199. /* 0x100 */
  49200. if (a != NULL) {
  49201. a->intData[0] = ASN_INTEGER;
  49202. a->intData[1] = 2;
  49203. a->intData[2] = 0x01;
  49204. a->intData[3] = 0x00;
  49205. a->negative = 0;
  49206. }
  49207. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 2);
  49208. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  49209. DYNAMIC_TYPE_TMP_BUFFER));
  49210. if (tpp != NULL) {
  49211. tpp = pp;
  49212. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  49213. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 2);
  49214. tpp -= 2;
  49215. ExpectIntEQ(tpp[0], 0x01);
  49216. ExpectIntEQ(tpp[1], 0x00);
  49217. }
  49218. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49219. pp = NULL;
  49220. /* -0x8000 => 0x8000 */
  49221. if (a != NULL) {
  49222. a->intData[0] = ASN_INTEGER;
  49223. a->intData[1] = 2;
  49224. a->intData[2] = 0x80;
  49225. a->intData[3] = 0x00;
  49226. a->negative = 1;
  49227. }
  49228. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 2);
  49229. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  49230. DYNAMIC_TYPE_TMP_BUFFER));
  49231. tpp = pp;
  49232. if (tpp != NULL) {
  49233. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  49234. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 2);
  49235. tpp -= 2;
  49236. ExpectIntEQ(tpp[0], 0x80);
  49237. ExpectIntEQ(tpp[1], 0x00);
  49238. }
  49239. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49240. pp = NULL;
  49241. /* -0x8001 => 0xFF7FFF */
  49242. if (a != NULL) {
  49243. a->intData[0] = ASN_INTEGER;
  49244. a->intData[1] = 2;
  49245. a->intData[2] = 0x80;
  49246. a->intData[3] = 0x01;
  49247. a->negative = 1;
  49248. }
  49249. ExpectIntEQ(ret = i2c_ASN1_INTEGER(a, NULL), 3);
  49250. ExpectNotNull(pp = (unsigned char*)XMALLOC(ret + 1, NULL,
  49251. DYNAMIC_TYPE_TMP_BUFFER));
  49252. tpp = pp;
  49253. if (tpp != NULL) {
  49254. ExpectNotNull(XMEMSET(tpp, 0, ret + 1));
  49255. ExpectIntEQ(i2c_ASN1_INTEGER(a, &tpp), 3);
  49256. tpp -= 3;
  49257. ExpectIntEQ(tpp[0], 0xFF);
  49258. ExpectIntEQ(tpp[1], 0x7F);
  49259. ExpectIntEQ(tpp[2], 0xFF);
  49260. }
  49261. XFREE(pp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49262. wolfSSL_ASN1_INTEGER_free(a);
  49263. #endif /* OPENSSL_EXTRA && !NO_ASN */
  49264. return EXPECT_RESULT();
  49265. }
  49266. static int test_wolfSSL_ASN1_OBJECT(void)
  49267. {
  49268. EXPECT_DECLS;
  49269. #if defined(OPENSSL_EXTRA)
  49270. ASN1_OBJECT* a = NULL;
  49271. ASN1_OBJECT s;
  49272. const unsigned char der[] = { 0x06, 0x01, 0x00 };
  49273. /* Invalid parameter testing. */
  49274. ASN1_OBJECT_free(NULL);
  49275. ExpectNull(wolfSSL_ASN1_OBJECT_dup(NULL));
  49276. /* Test that a static ASN1_OBJECT can be freed. */
  49277. XMEMSET(&s, 0, sizeof(ASN1_OBJECT));
  49278. ASN1_OBJECT_free(&s);
  49279. ExpectNotNull(a = wolfSSL_ASN1_OBJECT_dup(&s));
  49280. ASN1_OBJECT_free(a);
  49281. a = NULL;
  49282. s.obj = der;
  49283. s.objSz = sizeof(der);
  49284. ExpectNotNull(a = wolfSSL_ASN1_OBJECT_dup(&s));
  49285. ASN1_OBJECT_free(a);
  49286. ASN1_OBJECT_free(&s);
  49287. #endif /* OPENSSL_EXTRA */
  49288. return EXPECT_RESULT();
  49289. }
  49290. static int test_wolfSSL_ASN1_get_object(void)
  49291. {
  49292. EXPECT_DECLS;
  49293. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  49294. const unsigned char* derBuf = cliecc_cert_der_256;
  49295. const unsigned char* nullPtr = NULL;
  49296. const unsigned char objDerInvalidLen[] = { 0x30, 0x81 };
  49297. const unsigned char objDerBadLen[] = { 0x30, 0x04 };
  49298. const unsigned char objDerNotObj[] = { 0x02, 0x01, 0x00 };
  49299. const unsigned char objDerNoData[] = { 0x06, 0x00 };
  49300. const unsigned char* p;
  49301. unsigned char objDer[10];
  49302. unsigned char* der;
  49303. unsigned char* derPtr;
  49304. int len = sizeof_cliecc_cert_der_256;
  49305. long asnLen = 0;
  49306. int tag = 0;
  49307. int cls = 0;
  49308. ASN1_OBJECT* a = NULL;
  49309. ASN1_OBJECT s;
  49310. XMEMSET(&s, 0, sizeof(ASN1_OBJECT));
  49311. /* Invalid encoding at length. */
  49312. p = objDerInvalidLen;
  49313. ExpectIntEQ(ASN1_get_object(&p, &asnLen, &tag, &cls, sizeof(objDerBadLen)),
  49314. 0x80);
  49315. p = objDerBadLen;
  49316. /* Error = 0x80, Constructed = 0x20 */
  49317. ExpectIntEQ(ASN1_get_object(&p, &asnLen, &tag, &cls, sizeof(objDerBadLen)),
  49318. 0x80 | 0x20);
  49319. /* Read a couple TLV triplets and make sure they match the expected values
  49320. */
  49321. /* SEQUENCE */
  49322. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls, len) & 0x80, 0);
  49323. ExpectIntEQ(asnLen, 861);
  49324. ExpectIntEQ(tag, 0x10);
  49325. ExpectIntEQ(cls, 0);
  49326. /* SEQUENCE */
  49327. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls,
  49328. len - (derBuf - cliecc_cert_der_256)) & 0x80, 0);
  49329. ExpectIntEQ(asnLen, 772);
  49330. ExpectIntEQ(tag, 0x10);
  49331. ExpectIntEQ(cls, 0);
  49332. /* [0] */
  49333. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls,
  49334. len - (derBuf - cliecc_cert_der_256)) & 0x80, 0);
  49335. ExpectIntEQ(asnLen, 3);
  49336. ExpectIntEQ(tag, 0);
  49337. ExpectIntEQ(cls, 0x80);
  49338. /* INTEGER */
  49339. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls,
  49340. len - (derBuf - cliecc_cert_der_256)) & 0x80, 0);
  49341. ExpectIntEQ(asnLen, 1);
  49342. ExpectIntEQ(tag, 0x2);
  49343. ExpectIntEQ(cls, 0);
  49344. derBuf += asnLen;
  49345. /* INTEGER */
  49346. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls,
  49347. len - (derBuf - cliecc_cert_der_256)) & 0x80, 0);
  49348. ExpectIntEQ(asnLen, 20);
  49349. ExpectIntEQ(tag, 0x2);
  49350. ExpectIntEQ(cls, 0);
  49351. derBuf += asnLen;
  49352. /* SEQUENCE */
  49353. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls,
  49354. len - (derBuf - cliecc_cert_der_256)) & 0x80, 0);
  49355. ExpectIntEQ(asnLen, 10);
  49356. ExpectIntEQ(tag, 0x10);
  49357. ExpectIntEQ(cls, 0);
  49358. /* Found OBJECT_ID. */
  49359. /* Invalid parameter testing. */
  49360. ExpectIntEQ(ASN1_get_object(NULL, NULL, NULL, NULL, 0), 0x80);
  49361. ExpectIntEQ(ASN1_get_object(&nullPtr, NULL, NULL, NULL, 0), 0x80);
  49362. ExpectIntEQ(ASN1_get_object(NULL, &asnLen, &tag, &cls, len), 0x80);
  49363. ExpectIntEQ(ASN1_get_object(&nullPtr, &asnLen, &tag, &cls, len), 0x80);
  49364. ExpectIntEQ(ASN1_get_object(&derBuf, NULL, &tag, &cls, len), 0x80);
  49365. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, NULL, &cls, len), 0x80);
  49366. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, NULL, len), 0x80);
  49367. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls, 0), 0x80);
  49368. ExpectIntEQ(ASN1_get_object(&derBuf, &asnLen, &tag, &cls, -1), 0x80);
  49369. ExpectNull(d2i_ASN1_OBJECT(NULL, NULL, -1));
  49370. ExpectNull(d2i_ASN1_OBJECT(NULL, &nullPtr, -1));
  49371. ExpectNull(d2i_ASN1_OBJECT(NULL, &derBuf, -1));
  49372. ExpectNull(d2i_ASN1_OBJECT(NULL, NULL, 0));
  49373. ExpectNull(d2i_ASN1_OBJECT(&a, NULL, len));
  49374. ExpectNull(d2i_ASN1_OBJECT(&a, &nullPtr, len));
  49375. ExpectNull(d2i_ASN1_OBJECT(&a, &derBuf, -1));
  49376. ExpectNull(c2i_ASN1_OBJECT(NULL, NULL, -1));
  49377. ExpectNull(c2i_ASN1_OBJECT(NULL, &nullPtr, -1));
  49378. ExpectNull(c2i_ASN1_OBJECT(NULL, &derBuf, -1));
  49379. ExpectNull(c2i_ASN1_OBJECT(NULL, NULL, 1));
  49380. ExpectNull(c2i_ASN1_OBJECT(NULL, &nullPtr, 1));
  49381. /* Invalid encoding at length. */
  49382. p = objDerInvalidLen;
  49383. ExpectNull(d2i_ASN1_OBJECT(&a, &p, sizeof(objDerInvalidLen)));
  49384. p = objDerBadLen;
  49385. ExpectNull(d2i_ASN1_OBJECT(&a, &p, sizeof(objDerBadLen)));
  49386. p = objDerNotObj;
  49387. ExpectNull(d2i_ASN1_OBJECT(&a, &p, sizeof(objDerNotObj)));
  49388. p = objDerNoData;
  49389. ExpectNull(d2i_ASN1_OBJECT(&a, &p, sizeof(objDerNoData)));
  49390. /* Create an ASN OBJECT from content */
  49391. p = derBuf + 2;
  49392. ExpectNotNull(a = c2i_ASN1_OBJECT(NULL, &p, 8));
  49393. ASN1_OBJECT_free(a);
  49394. a = NULL;
  49395. /* Create an ASN OBJECT from DER */
  49396. ExpectNotNull(d2i_ASN1_OBJECT(&a, &derBuf, len));
  49397. /* Invalid parameter testing. */
  49398. ExpectIntEQ(i2d_ASN1_OBJECT(NULL, NULL), 0);
  49399. ExpectIntEQ(i2d_ASN1_OBJECT(&s, NULL), 0);
  49400. ExpectIntEQ(i2d_ASN1_OBJECT(a, NULL), 10);
  49401. der = NULL;
  49402. ExpectIntEQ(i2d_ASN1_OBJECT(a, &der), 10);
  49403. derPtr = objDer;
  49404. ExpectIntEQ(i2d_ASN1_OBJECT(a, &derPtr), 10);
  49405. ExpectPtrNE(derPtr, objDer);
  49406. ExpectIntEQ(XMEMCMP(der, objDer, 10), 0);
  49407. XFREE(der, NULL, DYNAMIC_TYPE_OPENSSL);
  49408. ASN1_OBJECT_free(a);
  49409. #endif /* OPENSSL_EXTRA && HAVE_ECC && USE_CERT_BUFFERS_256 */
  49410. return EXPECT_RESULT();
  49411. }
  49412. static int test_wolfSSL_i2a_ASN1_OBJECT(void)
  49413. {
  49414. EXPECT_DECLS;
  49415. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && !defined(NO_BIO)
  49416. ASN1_OBJECT* obj = NULL;
  49417. ASN1_OBJECT* a = NULL;
  49418. BIO *bio = NULL;
  49419. const unsigned char notObjDer[] = { 0x04, 0x01, 0xff };
  49420. const unsigned char* p;
  49421. ExpectNotNull(obj = OBJ_nid2obj(NID_sha256));
  49422. ExpectTrue((bio = BIO_new(BIO_s_mem())) != NULL);
  49423. ExpectIntGT(wolfSSL_i2a_ASN1_OBJECT(bio, obj), 0);
  49424. ExpectIntGT(wolfSSL_i2a_ASN1_OBJECT(bio, NULL), 0);
  49425. ExpectIntEQ(wolfSSL_i2a_ASN1_OBJECT(NULL, obj), 0);
  49426. /* No DER encoding in ASN1_OBJECT. */
  49427. ExpectNotNull(a = wolfSSL_ASN1_OBJECT_new());
  49428. ExpectIntEQ(wolfSSL_i2a_ASN1_OBJECT(bio, a), 0);
  49429. ASN1_OBJECT_free(a);
  49430. a = NULL;
  49431. /* DER encoding */
  49432. p = notObjDer;
  49433. ExpectNotNull(a = c2i_ASN1_OBJECT(NULL, &p, 3));
  49434. ExpectIntEQ(wolfSSL_i2a_ASN1_OBJECT(bio, a), 5);
  49435. ASN1_OBJECT_free(a);
  49436. BIO_free(bio);
  49437. ASN1_OBJECT_free(obj);
  49438. #endif
  49439. return EXPECT_RESULT();
  49440. }
  49441. static int test_wolfSSL_i2t_ASN1_OBJECT(void)
  49442. {
  49443. EXPECT_DECLS;
  49444. #if defined(OPENSSL_EXTRA) && \
  49445. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)
  49446. char buf[50] = {0};
  49447. ASN1_OBJECT* obj;
  49448. const char* oid = "2.5.29.19";
  49449. const char* ln = "X509v3 Basic Constraints";
  49450. obj = NULL;
  49451. ExpectIntEQ(i2t_ASN1_OBJECT(NULL, sizeof(buf), obj), 0);
  49452. ExpectIntEQ(i2t_ASN1_OBJECT(buf, sizeof(buf), NULL), 0);
  49453. ExpectIntEQ(i2t_ASN1_OBJECT(buf, 0, NULL), 0);
  49454. ExpectNotNull(obj = OBJ_txt2obj(oid, 0));
  49455. XMEMSET(buf, 0, sizeof(buf));
  49456. ExpectIntEQ(i2t_ASN1_OBJECT(buf, sizeof(buf), obj), XSTRLEN(ln));
  49457. ExpectIntEQ(XSTRNCMP(buf, ln, XSTRLEN(ln)), 0);
  49458. ASN1_OBJECT_free(obj);
  49459. #endif /* OPENSSL_EXTRA && WOLFSSL_CERT_EXT && WOLFSSL_CERT_GEN */
  49460. return EXPECT_RESULT();
  49461. }
  49462. static int test_wolfSSL_sk_ASN1_OBJECT(void)
  49463. {
  49464. EXPECT_DECLS;
  49465. #if !defined(NO_ASN) && (defined(OPENSSL_EXTRA) || defined(WOLFSSL_WPAS_SMALL))
  49466. WOLFSSL_STACK* sk = NULL;
  49467. WOLFSSL_ASN1_OBJECT* obj;
  49468. ExpectNotNull(obj = wolfSSL_ASN1_OBJECT_new());
  49469. ExpectNotNull(sk = wolfSSL_sk_new_asn1_obj());
  49470. wolfSSL_sk_ASN1_OBJECT_free(sk);
  49471. sk = NULL;
  49472. ExpectNotNull(sk = wolfSSL_sk_new_asn1_obj());
  49473. ExpectIntEQ(wolfSSL_sk_ASN1_OBJECT_push(NULL, NULL), -1);
  49474. ExpectIntEQ(wolfSSL_sk_ASN1_OBJECT_push(sk, NULL), 0);
  49475. ExpectIntEQ(wolfSSL_sk_ASN1_OBJECT_push(NULL, obj), -1);
  49476. ExpectIntEQ(wolfSSL_sk_ASN1_OBJECT_push(sk, obj), 1);
  49477. wolfSSL_sk_ASN1_OBJECT_pop_free(sk, NULL);
  49478. sk = NULL;
  49479. /* obj freed in pop_free call. */
  49480. ExpectNotNull(obj = wolfSSL_ASN1_OBJECT_new());
  49481. ExpectNotNull(sk = wolfSSL_sk_new_asn1_obj());
  49482. ExpectIntEQ(wolfSSL_sk_ASN1_OBJECT_push(sk, obj), 1);
  49483. ExpectPtrEq(obj, wolfSSL_sk_ASN1_OBJECT_pop(sk));
  49484. wolfSSL_sk_ASN1_OBJECT_free(sk);
  49485. wolfSSL_ASN1_OBJECT_free(obj);
  49486. #endif /* !NO_ASN && (OPENSSL_EXTRA || WOLFSSL_WPAS_SMALL) */
  49487. return EXPECT_RESULT();
  49488. }
  49489. static int test_wolfSSL_ASN1_STRING(void)
  49490. {
  49491. EXPECT_DECLS;
  49492. #if defined(OPENSSL_EXTRA)
  49493. ASN1_STRING* str = NULL;
  49494. ASN1_STRING* c = NULL;
  49495. const char data[] = "hello wolfSSL";
  49496. const char data2[] = "Same len data";
  49497. const char longData[] =
  49498. "This string must be longer than CTC_NAME_SIZE that is defined as 64.";
  49499. ExpectNotNull(str = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  49500. ASN1_STRING_free(str);
  49501. str = NULL;
  49502. ExpectNotNull(str = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  49503. ExpectIntEQ(ASN1_STRING_type(str), V_ASN1_OCTET_STRING);
  49504. ExpectIntEQ(ASN1_STRING_type(NULL), 0);
  49505. /* Check setting to NULL works. */
  49506. ExpectIntEQ(ASN1_STRING_set(str, NULL, 0), 1);
  49507. ExpectIntEQ(ASN1_STRING_set(str, (const void*)data, sizeof(data)), 1);
  49508. ExpectIntEQ(ASN1_STRING_set(str, (const void*)data, -1), 1);
  49509. ExpectIntEQ(ASN1_STRING_set(str, NULL, -1), 0);
  49510. ExpectIntEQ(ASN1_STRING_set(NULL, NULL, 0), 0);
  49511. ExpectIntEQ(wolfSSL_ASN1_STRING_copy(NULL, NULL), 0);
  49512. ExpectIntEQ(wolfSSL_ASN1_STRING_copy(str, NULL), 0);
  49513. ExpectIntEQ(wolfSSL_ASN1_STRING_copy(NULL, str), 0);
  49514. ExpectNull(wolfSSL_ASN1_STRING_dup(NULL));
  49515. ExpectNotNull(c = wolfSSL_ASN1_STRING_dup(str));
  49516. ExpectIntEQ(ASN1_STRING_cmp(NULL, NULL), -1);
  49517. ExpectIntEQ(ASN1_STRING_cmp(str, NULL), -1);
  49518. ExpectIntEQ(ASN1_STRING_cmp(NULL, c), -1);
  49519. ExpectIntEQ(ASN1_STRING_cmp(str, c), 0);
  49520. ExpectIntEQ(ASN1_STRING_set(c, (const void*)data2, -1), 1);
  49521. ExpectIntGT(ASN1_STRING_cmp(str, c), 0);
  49522. ExpectIntEQ(ASN1_STRING_set(str, (const void*)longData, -1), 1);
  49523. ExpectIntEQ(wolfSSL_ASN1_STRING_copy(c, str), 1);
  49524. ExpectIntEQ(ASN1_STRING_cmp(str, c), 0);
  49525. /* Check setting back to smaller size frees dynamic data. */
  49526. ExpectIntEQ(ASN1_STRING_set(str, (const void*)data, -1), 1);
  49527. ExpectIntLT(ASN1_STRING_cmp(str, c), 0);
  49528. ExpectIntGT(ASN1_STRING_cmp(c, str), 0);
  49529. ExpectNull(ASN1_STRING_get0_data(NULL));
  49530. ExpectNotNull(ASN1_STRING_get0_data(str));
  49531. ExpectNull(ASN1_STRING_data(NULL));
  49532. ExpectNotNull(ASN1_STRING_data(str));
  49533. ExpectIntEQ(ASN1_STRING_length(NULL), 0);
  49534. ExpectIntGT(ASN1_STRING_length(str), 0);
  49535. ASN1_STRING_free(c);
  49536. ASN1_STRING_free(str);
  49537. ASN1_STRING_free(NULL);
  49538. #ifndef NO_WOLFSSL_STUB
  49539. ExpectNull(d2i_DISPLAYTEXT(NULL, NULL, 0));
  49540. #endif
  49541. #endif
  49542. return EXPECT_RESULT();
  49543. }
  49544. static int test_wolfSSL_ASN1_STRING_to_UTF8(void)
  49545. {
  49546. EXPECT_DECLS;
  49547. #if defined(OPENSSL_ALL) && !defined(NO_ASN) && !defined(NO_RSA) && \
  49548. !defined(NO_FILESYSTEM)
  49549. WOLFSSL_X509* x509 = NULL;
  49550. WOLFSSL_X509_NAME* subject = NULL;
  49551. WOLFSSL_X509_NAME_ENTRY* e = NULL;
  49552. WOLFSSL_ASN1_STRING* a = NULL;
  49553. FILE* file = XBADFILE;
  49554. int idx = 0;
  49555. char targetOutput[16] = "www.wolfssl.com";
  49556. unsigned char* actual_output = NULL;
  49557. int len = 0;
  49558. ExpectNotNull(file = fopen("./certs/server-cert.pem", "rb"));
  49559. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(file, NULL, NULL, NULL));
  49560. if (file != XBADFILE)
  49561. fclose(file);
  49562. /* wolfSSL_ASN1_STRING_to_UTF8(): NID_commonName */
  49563. ExpectNotNull(subject = wolfSSL_X509_get_subject_name(x509));
  49564. ExpectIntEQ((idx = wolfSSL_X509_NAME_get_index_by_NID(subject,
  49565. NID_commonName, -1)), 5);
  49566. ExpectNotNull(e = wolfSSL_X509_NAME_get_entry(subject, idx));
  49567. ExpectNotNull(a = wolfSSL_X509_NAME_ENTRY_get_data(e));
  49568. ExpectIntEQ((len = wolfSSL_ASN1_STRING_to_UTF8(&actual_output, a)), 15);
  49569. ExpectIntEQ(strncmp((const char*)actual_output, targetOutput, (size_t)len), 0);
  49570. a = NULL;
  49571. /* wolfSSL_ASN1_STRING_to_UTF8(NULL, valid) */
  49572. ExpectIntEQ((len = wolfSSL_ASN1_STRING_to_UTF8(NULL, a)), -1);
  49573. /* wolfSSL_ASN1_STRING_to_UTF8(valid, NULL) */
  49574. ExpectIntEQ((len = wolfSSL_ASN1_STRING_to_UTF8(&actual_output, NULL)), -1);
  49575. /* wolfSSL_ASN1_STRING_to_UTF8(NULL, NULL) */
  49576. ExpectIntEQ((len = wolfSSL_ASN1_STRING_to_UTF8(NULL, NULL)), -1);
  49577. wolfSSL_X509_free(x509);
  49578. XFREE(actual_output, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49579. ExpectNotNull(a = ASN1_STRING_new());
  49580. ExpectIntEQ(wolfSSL_ASN1_STRING_to_UTF8(&actual_output, a), -1);
  49581. ASN1_STRING_free(a);
  49582. #endif
  49583. return EXPECT_RESULT();
  49584. }
  49585. static int test_wolfSSL_i2s_ASN1_STRING(void)
  49586. {
  49587. EXPECT_DECLS;
  49588. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN)
  49589. WOLFSSL_ASN1_STRING* str = NULL;
  49590. const char* data = "test_wolfSSL_i2s_ASN1_STRING";
  49591. char* ret = NULL;
  49592. ExpectNotNull(str = ASN1_STRING_new());
  49593. ExpectNull(ret = wolfSSL_i2s_ASN1_STRING(NULL, NULL));
  49594. XFREE(ret, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49595. ret = NULL;
  49596. /* No data. */
  49597. ExpectNull(ret = wolfSSL_i2s_ASN1_STRING(NULL, str));
  49598. XFREE(ret, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49599. ret = NULL;
  49600. ExpectIntEQ(ASN1_STRING_set(str, data, 0), 1);
  49601. ExpectNotNull(ret = wolfSSL_i2s_ASN1_STRING(NULL, str));
  49602. XFREE(ret, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49603. ret = NULL;
  49604. ExpectIntEQ(ASN1_STRING_set(str, data, -1), 1);
  49605. /* No type. */
  49606. ExpectNotNull(ret = wolfSSL_i2s_ASN1_STRING(NULL, str));
  49607. XFREE(ret, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  49608. ASN1_STRING_free(str);
  49609. #endif
  49610. return EXPECT_RESULT();
  49611. }
  49612. static int test_wolfSSL_ASN1_STRING_canon(void)
  49613. {
  49614. EXPECT_DECLS;
  49615. #if defined(WOLFSSL_TEST_STATIC_BUILD)
  49616. #if !defined(NO_CERTS) && (defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA) || \
  49617. defined(OPENSSL_EXTRA_X509_SMALL))
  49618. WOLFSSL_ASN1_STRING* orig = NULL;
  49619. WOLFSSL_ASN1_STRING* canon = NULL;
  49620. const char* data = "test_wolfSSL_ASN1_STRING_canon";
  49621. const char* whitespaceOnly = "\t\r\n";
  49622. const char* modData = " \x01\f\t\x02\r\n\v\xff\nTt \n";
  49623. const char* canonData = "\x01 \x02 \xff tt";
  49624. const char longData[] =
  49625. "This string must be longer than CTC_NAME_SIZE that is defined as 64.";
  49626. ExpectNotNull(orig = ASN1_STRING_new());
  49627. ExpectNotNull(canon = ASN1_STRING_new());
  49628. /* Invalid parameter testing. */
  49629. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  49630. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  49631. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(NULL, orig), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  49632. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, orig), 1);
  49633. ExpectIntEQ(ASN1_STRING_cmp(orig, canon), 0);
  49634. ExpectIntEQ(ASN1_STRING_set(orig, longData, (int)XSTRLEN(data)), 1);
  49635. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, orig), 1);
  49636. ExpectIntEQ(ASN1_STRING_cmp(orig, canon), 0);
  49637. ExpectIntEQ(ASN1_STRING_set(orig, data, (int)XSTRLEN(data)), 1);
  49638. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, orig), 1);
  49639. ExpectIntEQ(ASN1_STRING_cmp(orig, canon), 0);
  49640. ASN1_STRING_free(orig);
  49641. orig = NULL;
  49642. ExpectNotNull(orig = ASN1_STRING_type_new(MBSTRING_UTF8));
  49643. ExpectIntEQ(ASN1_STRING_set(orig, modData, 15), 1);
  49644. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, orig), 1);
  49645. ExpectIntEQ(ASN1_STRING_set(orig, canonData, 8), 1);
  49646. ExpectIntEQ(ASN1_STRING_cmp(orig, canon), 0);
  49647. ASN1_STRING_free(orig);
  49648. orig = NULL;
  49649. ExpectNotNull(orig = ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING));
  49650. ExpectIntEQ(ASN1_STRING_set(orig, whitespaceOnly, 3), 1);
  49651. ExpectIntEQ(wolfSSL_ASN1_STRING_canon(canon, orig), 1);
  49652. ASN1_STRING_free(orig);
  49653. orig = NULL;
  49654. ExpectNotNull(orig = ASN1_STRING_type_new(MBSTRING_UTF8));
  49655. ExpectIntEQ(ASN1_STRING_cmp(orig, canon), 0);
  49656. ASN1_STRING_free(orig);
  49657. ASN1_STRING_free(canon);
  49658. #endif
  49659. #endif
  49660. return EXPECT_RESULT();
  49661. }
  49662. static int test_wolfSSL_ASN1_STRING_print(void)
  49663. {
  49664. EXPECT_DECLS;
  49665. #if defined(OPENSSL_ALL) && !defined(NO_ASN) && !defined(NO_CERTS) && \
  49666. !defined(NO_BIO)
  49667. ASN1_STRING* asnStr = NULL;
  49668. const char HELLO_DATA[]= \
  49669. {'H','e','l','l','o',' ','w','o','l','f','S','S','L','!'};
  49670. #define MAX_UNPRINTABLE_CHAR 32
  49671. #define MAX_BUF 255
  49672. unsigned char unprintableData[MAX_UNPRINTABLE_CHAR + sizeof(HELLO_DATA)];
  49673. unsigned char expected[sizeof(unprintableData)+1];
  49674. unsigned char rbuf[MAX_BUF];
  49675. BIO *bio = NULL;
  49676. int p_len;
  49677. int i;
  49678. /* setup */
  49679. for (i = 0; i < (int)sizeof(HELLO_DATA); i++) {
  49680. unprintableData[i] = (unsigned char)HELLO_DATA[i];
  49681. expected[i] = (unsigned char)HELLO_DATA[i];
  49682. }
  49683. for (i = 0; i < (int)MAX_UNPRINTABLE_CHAR; i++) {
  49684. unprintableData[sizeof(HELLO_DATA)+i] = i;
  49685. if (i == (int)'\n' || i == (int)'\r')
  49686. expected[sizeof(HELLO_DATA)+i] = i;
  49687. else
  49688. expected[sizeof(HELLO_DATA)+i] = '.';
  49689. }
  49690. unprintableData[sizeof(unprintableData)-1] = '\0';
  49691. expected[sizeof(expected)-1] = '\0';
  49692. XMEMSET(rbuf, 0, MAX_BUF);
  49693. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  49694. ExpectIntEQ(BIO_set_write_buf_size(bio, MAX_BUF), 0);
  49695. ExpectNotNull(asnStr = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  49696. ExpectIntEQ(ASN1_STRING_set(asnStr,(const void*)unprintableData,
  49697. (int)sizeof(unprintableData)), 1);
  49698. /* test */
  49699. ExpectIntEQ(wolfSSL_ASN1_STRING_print(NULL, NULL), 0);
  49700. ExpectIntEQ(wolfSSL_ASN1_STRING_print(bio, NULL), 0);
  49701. ExpectIntEQ(wolfSSL_ASN1_STRING_print(NULL, asnStr), 0);
  49702. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print(bio, asnStr), 46);
  49703. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 46), 46);
  49704. ExpectStrEQ((char*)rbuf, (const char*)expected);
  49705. BIO_free(bio);
  49706. bio = NULL;
  49707. ExpectNotNull(bio = BIO_new(wolfSSL_BIO_s_fixed_mem()));
  49708. ExpectIntEQ(BIO_set_write_buf_size(bio, 1), 1);
  49709. /* Ensure there is 0 bytes available to write into. */
  49710. ExpectIntEQ(BIO_write(bio, rbuf, 1), 1);
  49711. ExpectIntEQ(wolfSSL_ASN1_STRING_print(bio, asnStr), 0);
  49712. ExpectIntEQ(BIO_set_write_buf_size(bio, 1), 1);
  49713. ExpectIntEQ(wolfSSL_ASN1_STRING_print(bio, asnStr), 0);
  49714. ExpectIntEQ(BIO_set_write_buf_size(bio, 45), 1);
  49715. ExpectIntEQ(wolfSSL_ASN1_STRING_print(bio, asnStr), 0);
  49716. BIO_free(bio);
  49717. ASN1_STRING_free(asnStr);
  49718. #endif /* OPENSSL_EXTRA && !NO_ASN && !NO_CERTS && !NO_BIO */
  49719. return EXPECT_RESULT();
  49720. }
  49721. static int test_wolfSSL_ASN1_STRING_print_ex(void)
  49722. {
  49723. EXPECT_DECLS;
  49724. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && !defined(NO_BIO)
  49725. ASN1_STRING* asn_str = NULL;
  49726. const char data[] = "Hello wolfSSL!";
  49727. ASN1_STRING* esc_str = NULL;
  49728. const char esc_data[] = "a+;<>";
  49729. ASN1_STRING* neg_int = NULL;
  49730. const char neg_int_data[] = "\xff";
  49731. ASN1_STRING* neg_enum = NULL;
  49732. const char neg_enum_data[] = "\xff";
  49733. BIO *bio = NULL;
  49734. BIO *fixed = NULL;
  49735. unsigned long flags;
  49736. int p_len;
  49737. unsigned char rbuf[255];
  49738. /* setup */
  49739. XMEMSET(rbuf, 0, 255);
  49740. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  49741. ExpectIntEQ(BIO_set_write_buf_size(bio, 255), 0);
  49742. ExpectNotNull(fixed = BIO_new(wolfSSL_BIO_s_fixed_mem()));
  49743. ExpectNotNull(asn_str = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  49744. ExpectIntEQ(ASN1_STRING_set(asn_str, (const void*)data, sizeof(data)), 1);
  49745. ExpectNotNull(esc_str = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  49746. ExpectIntEQ(ASN1_STRING_set(esc_str, (const void*)esc_data,
  49747. sizeof(esc_data)), 1);
  49748. ExpectNotNull(neg_int = ASN1_STRING_type_new(V_ASN1_NEG_INTEGER));
  49749. ExpectIntEQ(ASN1_STRING_set(neg_int, (const void*)neg_int_data,
  49750. sizeof(neg_int_data) - 1), 1);
  49751. ExpectNotNull(neg_enum = ASN1_STRING_type_new(V_ASN1_NEG_ENUMERATED));
  49752. ExpectIntEQ(ASN1_STRING_set(neg_enum, (const void*)neg_enum_data,
  49753. sizeof(neg_enum_data) - 1), 1);
  49754. /* Invalid parameter testing. */
  49755. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(NULL, NULL, 0), 0);
  49756. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(bio, NULL, 0), 0);
  49757. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(NULL, asn_str, 0), 0);
  49758. /* no flags */
  49759. XMEMSET(rbuf, 0, 255);
  49760. flags = 0;
  49761. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, asn_str, flags), 15);
  49762. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 15), 15);
  49763. ExpectStrEQ((char*)rbuf, "Hello wolfSSL!");
  49764. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  49765. /* Ensure there is 0 bytes available to write into. */
  49766. ExpectIntEQ(BIO_write(fixed, rbuf, 1), 1);
  49767. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  49768. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  49769. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  49770. ExpectIntEQ(BIO_set_write_buf_size(fixed, 14), 1);
  49771. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  49772. /* RFC2253 Escape */
  49773. XMEMSET(rbuf, 0, 255);
  49774. flags = ASN1_STRFLGS_ESC_2253;
  49775. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, esc_str, flags), 9);
  49776. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 9), 9);
  49777. ExpectStrEQ((char*)rbuf, "a\\+\\;\\<\\>");
  49778. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  49779. /* Ensure there is 0 bytes available to write into. */
  49780. ExpectIntEQ(BIO_write(fixed, rbuf, 1), 1);
  49781. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, esc_str, flags), 0);
  49782. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  49783. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, esc_str, flags), 0);
  49784. ExpectIntEQ(BIO_set_write_buf_size(fixed, 8), 1);
  49785. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, esc_str, flags), 0);
  49786. /* Show type */
  49787. XMEMSET(rbuf, 0, 255);
  49788. flags = ASN1_STRFLGS_SHOW_TYPE;
  49789. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, asn_str, flags), 28);
  49790. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 28), 28);
  49791. ExpectStrEQ((char*)rbuf, "OCTET STRING:Hello wolfSSL!");
  49792. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  49793. /* Ensure there is 0 bytes available to write into. */
  49794. ExpectIntEQ(BIO_write(fixed, rbuf, 1), 1);
  49795. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  49796. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  49797. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  49798. ExpectIntEQ(BIO_set_write_buf_size(fixed, 12), 1);
  49799. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  49800. ExpectIntEQ(BIO_set_write_buf_size(fixed, 27), 1);
  49801. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  49802. /* Dump All */
  49803. XMEMSET(rbuf, 0, 255);
  49804. flags = ASN1_STRFLGS_DUMP_ALL;
  49805. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, asn_str, flags), 31);
  49806. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 31), 31);
  49807. ExpectStrEQ((char*)rbuf, "#48656C6C6F20776F6C6653534C2100");
  49808. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  49809. /* Ensure there is 0 bytes available to write into. */
  49810. ExpectIntEQ(BIO_write(fixed, rbuf, 1), 1);
  49811. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  49812. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  49813. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  49814. ExpectIntEQ(BIO_set_write_buf_size(fixed, 30), 1);
  49815. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  49816. /* Dump Der */
  49817. XMEMSET(rbuf, 0, 255);
  49818. flags = ASN1_STRFLGS_DUMP_ALL | ASN1_STRFLGS_DUMP_DER;
  49819. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, asn_str, flags), 35);
  49820. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 35), 35);
  49821. ExpectStrEQ((char*)rbuf, "#040F48656C6C6F20776F6C6653534C2100");
  49822. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  49823. /* Ensure there is 0 bytes available to write into. */
  49824. ExpectIntEQ(BIO_write(fixed, rbuf, 1), 1);
  49825. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  49826. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  49827. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  49828. ExpectIntEQ(BIO_set_write_buf_size(fixed, 2), 1);
  49829. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  49830. ExpectIntEQ(BIO_set_write_buf_size(fixed, 30), 1);
  49831. ExpectIntEQ(wolfSSL_ASN1_STRING_print_ex(fixed, asn_str, flags), 0);
  49832. /* Dump All + Show type */
  49833. XMEMSET(rbuf, 0, 255);
  49834. flags = ASN1_STRFLGS_DUMP_ALL | ASN1_STRFLGS_SHOW_TYPE;
  49835. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, asn_str, flags), 44);
  49836. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 44), 44);
  49837. ExpectStrEQ((char*)rbuf, "OCTET STRING:#48656C6C6F20776F6C6653534C2100");
  49838. /* Dump All + Show type - Negative Integer. */
  49839. XMEMSET(rbuf, 0, 255);
  49840. flags = ASN1_STRFLGS_DUMP_ALL | ASN1_STRFLGS_SHOW_TYPE;
  49841. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, neg_int, flags), 11);
  49842. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 11), 11);
  49843. ExpectStrEQ((char*)rbuf, "INTEGER:#FF");
  49844. /* Dump All + Show type - Negative Enumerated. */
  49845. XMEMSET(rbuf, 0, 255);
  49846. flags = ASN1_STRFLGS_DUMP_ALL | ASN1_STRFLGS_SHOW_TYPE;
  49847. ExpectIntEQ(p_len = wolfSSL_ASN1_STRING_print_ex(bio, neg_enum, flags), 14);
  49848. ExpectIntEQ(BIO_read(bio, (void*)rbuf, 14), 14);
  49849. ExpectStrEQ((char*)rbuf, "ENUMERATED:#FF");
  49850. BIO_free(fixed);
  49851. BIO_free(bio);
  49852. ASN1_STRING_free(asn_str);
  49853. ASN1_STRING_free(esc_str);
  49854. ASN1_STRING_free(neg_int);
  49855. ASN1_STRING_free(neg_enum);
  49856. ExpectStrEQ(wolfSSL_ASN1_tag2str(-1), "(unknown)");
  49857. ExpectStrEQ(wolfSSL_ASN1_tag2str(31), "(unknown)");
  49858. #endif
  49859. return EXPECT_RESULT();
  49860. }
  49861. static int test_wolfSSL_ASN1_UNIVERSALSTRING_to_string(void)
  49862. {
  49863. EXPECT_DECLS;
  49864. #if defined(OPENSSL_ALL) && !defined(NO_ASN)
  49865. ASN1_STRING* asn1str_test = NULL;
  49866. ASN1_STRING* asn1str_answer = NULL;
  49867. /* Each character is encoded using 4 bytes */
  49868. char input[] = {
  49869. 0, 0, 0, 'T',
  49870. 0, 0, 0, 'e',
  49871. 0, 0, 0, 's',
  49872. 0, 0, 0, 't',
  49873. };
  49874. char output[] = "Test";
  49875. char badInput[] = {
  49876. 1, 0, 0, 'T',
  49877. 0, 1, 0, 'e',
  49878. 0, 0, 1, 's',
  49879. };
  49880. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(NULL), 0);
  49881. /* Test wrong type. */
  49882. ExpectNotNull(asn1str_test = ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
  49883. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 0);
  49884. ASN1_STRING_free(asn1str_test);
  49885. asn1str_test = NULL;
  49886. ExpectNotNull(asn1str_test = ASN1_STRING_type_new(V_ASN1_UNIVERSALSTRING));
  49887. /* Test bad length. */
  49888. ExpectIntEQ(ASN1_STRING_set(asn1str_test, input, sizeof(input) - 1), 1);
  49889. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 0);
  49890. /* Test bad input. */
  49891. ExpectIntEQ(ASN1_STRING_set(asn1str_test, badInput + 0, 4), 1);
  49892. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 0);
  49893. ExpectIntEQ(ASN1_STRING_set(asn1str_test, badInput + 4, 4), 1);
  49894. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 0);
  49895. ExpectIntEQ(ASN1_STRING_set(asn1str_test, badInput + 8, 4), 1);
  49896. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 0);
  49897. ExpectIntEQ(ASN1_STRING_set(asn1str_test, input, sizeof(input)), 1);
  49898. ExpectIntEQ(ASN1_UNIVERSALSTRING_to_string(asn1str_test), 1);
  49899. ExpectNotNull(
  49900. asn1str_answer = ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING));
  49901. ExpectIntEQ(ASN1_STRING_set(asn1str_answer, output, sizeof(output)-1), 1);
  49902. ExpectIntEQ(ASN1_STRING_cmp(asn1str_test, asn1str_answer), 0);
  49903. ASN1_STRING_free(asn1str_test);
  49904. ASN1_STRING_free(asn1str_answer);
  49905. #endif /* OPENSSL_ALL && !NO_ASN */
  49906. return EXPECT_RESULT();
  49907. }
  49908. static int test_wolfSSL_ASN1_GENERALIZEDTIME_free(void)
  49909. {
  49910. EXPECT_DECLS;
  49911. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  49912. WOLFSSL_ASN1_GENERALIZEDTIME* asn1_gtime = NULL;
  49913. ExpectNotNull(asn1_gtime = ASN1_GENERALIZEDTIME_new());
  49914. if (asn1_gtime != NULL)
  49915. XMEMCPY(asn1_gtime->data, "20180504123500Z", ASN_GENERALIZED_TIME_SIZE);
  49916. ASN1_GENERALIZEDTIME_free(asn1_gtime);
  49917. #endif /* OPENSSL_EXTRA && !NO_ASN_TIME */
  49918. return EXPECT_RESULT();
  49919. }
  49920. static int test_wolfSSL_ASN1_GENERALIZEDTIME_print(void)
  49921. {
  49922. EXPECT_DECLS;
  49923. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME) && !defined(NO_BIO)
  49924. WOLFSSL_ASN1_GENERALIZEDTIME* gtime = NULL;
  49925. BIO* bio = NULL;
  49926. unsigned char buf[24];
  49927. int i;
  49928. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  49929. BIO_set_write_buf_size(bio, 24);
  49930. ExpectNotNull(gtime = ASN1_GENERALIZEDTIME_new());
  49931. /* Type not set. */
  49932. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(bio, gtime), 0);
  49933. ExpectIntEQ(wolfSSL_ASN1_TIME_set_string(gtime, "20180504123500Z"), 1);
  49934. /* Invalid parameters testing. */
  49935. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  49936. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(bio, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  49937. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(NULL, gtime), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  49938. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(bio, gtime), 1);
  49939. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 20);
  49940. ExpectIntEQ(XMEMCMP(buf, "May 04 12:35:00 2018", 20), 0);
  49941. BIO_free(bio);
  49942. bio = NULL;
  49943. ExpectNotNull(bio = BIO_new(wolfSSL_BIO_s_fixed_mem()));
  49944. ExpectIntEQ(BIO_set_write_buf_size(bio, 1), 1);
  49945. /* Ensure there is 0 bytes available to write into. */
  49946. ExpectIntEQ(BIO_write(bio, buf, 1), 1);
  49947. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(bio, gtime), 0);
  49948. for (i = 1; i < 20; i++) {
  49949. ExpectIntEQ(BIO_set_write_buf_size(bio, i), 1);
  49950. ExpectIntEQ(wolfSSL_ASN1_GENERALIZEDTIME_print(bio, gtime), 0);
  49951. }
  49952. BIO_free(bio);
  49953. wolfSSL_ASN1_GENERALIZEDTIME_free(gtime);
  49954. #endif /* OPENSSL_EXTRA && !NO_ASN_TIME && !NO_BIO */
  49955. return EXPECT_RESULT();
  49956. }
  49957. static int test_wolfSSL_ASN1_TIME(void)
  49958. {
  49959. EXPECT_DECLS;
  49960. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  49961. WOLFSSL_ASN1_TIME* asn_time = NULL;
  49962. unsigned char *data = NULL;
  49963. ExpectNotNull(asn_time = ASN1_TIME_new());
  49964. #ifndef NO_WOLFSSL_STUB
  49965. ExpectNotNull(ASN1_TIME_set(asn_time, 1));
  49966. #endif
  49967. ExpectIntEQ(ASN1_TIME_set_string(NULL, NULL), 0);
  49968. ExpectIntEQ(ASN1_TIME_set_string(asn_time, NULL), 0);
  49969. ExpectIntEQ(ASN1_TIME_set_string(NULL,
  49970. "String longer than CTC_DATA_SIZE that is 32 bytes"), 0);
  49971. ExpectIntEQ(ASN1_TIME_set_string(NULL, "101219181011Z"), 1);
  49972. ExpectIntEQ(ASN1_TIME_set_string(asn_time, "101219181011Z"), 1);
  49973. ExpectIntEQ(wolfSSL_ASN1_TIME_get_length(NULL), 0);
  49974. ExpectIntEQ(wolfSSL_ASN1_TIME_get_length(asn_time), ASN_UTC_TIME_SIZE - 1);
  49975. ExpectNull(wolfSSL_ASN1_TIME_get_data(NULL));
  49976. ExpectNotNull(data = wolfSSL_ASN1_TIME_get_data(asn_time));
  49977. ExpectIntEQ(XMEMCMP(data, "101219181011Z", 14), 0);
  49978. ExpectIntEQ(ASN1_TIME_check(NULL), 0);
  49979. ExpectIntEQ(ASN1_TIME_check(asn_time), 1);
  49980. ExpectIntEQ(ASN1_TIME_set_string_X509(asn_time, "101219181011Z"), 1);
  49981. ExpectIntEQ(ASN1_TIME_set_string_X509(asn_time, "101219181011Za"), 0);
  49982. ASN1_TIME_free(asn_time);
  49983. ASN1_TIME_free(NULL);
  49984. #endif
  49985. return EXPECT_RESULT();
  49986. }
  49987. static int test_wolfSSL_ASN1_TIME_to_string(void)
  49988. {
  49989. EXPECT_DECLS;
  49990. #ifndef NO_ASN_TIME
  49991. #if defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(WOLFSSL_NGINX) || \
  49992. defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)
  49993. WOLFSSL_ASN1_TIME* t = NULL;
  49994. char buf[ASN_GENERALIZED_TIME_SIZE];
  49995. ExpectNotNull((t = ASN1_TIME_new()));
  49996. ExpectIntEQ(ASN1_TIME_set_string(t, "030222211515Z"), 1);
  49997. /* Invalid parameter testing. */
  49998. ExpectNull(ASN1_TIME_to_string(NULL, NULL, 4));
  49999. ExpectNull(ASN1_TIME_to_string(t, NULL, 4));
  50000. ExpectNull(ASN1_TIME_to_string(NULL, buf, 4));
  50001. ExpectNull(ASN1_TIME_to_string(NULL, NULL, 5));
  50002. ExpectNull(ASN1_TIME_to_string(NULL, buf, 5));
  50003. ExpectNull(ASN1_TIME_to_string(t, NULL, 5));
  50004. ExpectNull(ASN1_TIME_to_string(t, buf, 4));
  50005. /* Buffer needs to be longer than minimum of 5 characters. */
  50006. ExpectNull(ASN1_TIME_to_string(t, buf, 5));
  50007. ASN1_TIME_free(t);
  50008. #endif
  50009. #endif /* NO_ASN_TIME */
  50010. return EXPECT_RESULT();
  50011. }
  50012. static int test_wolfSSL_ASN1_TIME_diff_compare(void)
  50013. {
  50014. EXPECT_DECLS;
  50015. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  50016. ASN1_TIME* fromTime = NULL;
  50017. ASN1_TIME* closeToTime = NULL;
  50018. ASN1_TIME* toTime = NULL;
  50019. ASN1_TIME* invalidTime = NULL;
  50020. int daysDiff = 0;
  50021. int secsDiff = 0;
  50022. ExpectNotNull((fromTime = ASN1_TIME_new()));
  50023. /* Feb 22, 2003, 21:15:15 */
  50024. ExpectIntEQ(ASN1_TIME_set_string(fromTime, "030222211515Z"), 1);
  50025. ExpectNotNull((closeToTime = ASN1_TIME_new()));
  50026. /* Feb 22, 2003, 21:16:15 */
  50027. ExpectIntEQ(ASN1_TIME_set_string(closeToTime, "030222211615Z"), 1);
  50028. ExpectNotNull((toTime = ASN1_TIME_new()));
  50029. /* Dec 19, 2010, 18:10:11 */
  50030. ExpectIntEQ(ASN1_TIME_set_string(toTime, "101219181011Z"), 1);
  50031. ExpectNotNull((invalidTime = ASN1_TIME_new()));
  50032. /* Dec 19, 2010, 18:10:11 but 'U' instead of 'Z' which is invalid. */
  50033. ExpectIntEQ(ASN1_TIME_set_string(invalidTime, "102519181011U"), 1);
  50034. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, invalidTime), 0);
  50035. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, invalidTime, toTime), 0);
  50036. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, toTime), 1);
  50037. /* Error conditions. */
  50038. ExpectIntEQ(ASN1_TIME_diff(NULL, &secsDiff, fromTime, toTime), 0);
  50039. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, NULL, fromTime, toTime), 0);
  50040. /* If both times are NULL, difference is 0. */
  50041. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, NULL, NULL), 1);
  50042. ExpectIntEQ(daysDiff, 0);
  50043. ExpectIntEQ(secsDiff, 0);
  50044. /* If one time is NULL, it defaults to the current time. */
  50045. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, NULL, toTime), 1);
  50046. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, NULL), 1);
  50047. /* Normal operation. Both times non-NULL. */
  50048. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, toTime), 1);
  50049. ExpectIntEQ(daysDiff, 2856);
  50050. ExpectIntEQ(secsDiff, 75296);
  50051. /* Swapping the times should return negative values. */
  50052. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, toTime, fromTime), 1);
  50053. ExpectIntEQ(daysDiff, -2856);
  50054. ExpectIntEQ(secsDiff, -75296);
  50055. /* Compare with invalid time string. */
  50056. ExpectIntEQ(ASN1_TIME_compare(fromTime, invalidTime), -2);
  50057. ExpectIntEQ(ASN1_TIME_compare(invalidTime, toTime), -2);
  50058. /* Compare with days difference of 0. */
  50059. ExpectIntEQ(ASN1_TIME_compare(fromTime, closeToTime), -1);
  50060. ExpectIntEQ(ASN1_TIME_compare(closeToTime, fromTime), 1);
  50061. /* Days and seconds differences not 0. */
  50062. ExpectIntEQ(ASN1_TIME_compare(fromTime, toTime), -1);
  50063. ExpectIntEQ(ASN1_TIME_compare(toTime, fromTime), 1);
  50064. /* Same time. */
  50065. ExpectIntEQ(ASN1_TIME_compare(fromTime, fromTime), 0);
  50066. /* Compare regression test: No seconds difference, just difference in days.
  50067. */
  50068. ASN1_TIME_set_string(fromTime, "19700101000000Z");
  50069. ASN1_TIME_set_string(toTime, "19800101000000Z");
  50070. ExpectIntEQ(ASN1_TIME_compare(fromTime, toTime), -1);
  50071. ExpectIntEQ(ASN1_TIME_compare(toTime, fromTime), 1);
  50072. ExpectIntEQ(ASN1_TIME_compare(fromTime, fromTime), 0);
  50073. /* Edge case with Unix epoch. */
  50074. ExpectNotNull(ASN1_TIME_set_string(fromTime, "19700101000000Z"));
  50075. ExpectNotNull(ASN1_TIME_set_string(toTime, "19800101000000Z"));
  50076. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, toTime), 1);
  50077. ExpectIntEQ(daysDiff, 3652);
  50078. ExpectIntEQ(secsDiff, 0);
  50079. /* Edge case with year > 2038 (year 2038 problem). */
  50080. ExpectNotNull(ASN1_TIME_set_string(toTime, "99991231235959Z"));
  50081. ExpectIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, toTime), 1);
  50082. ExpectIntEQ(daysDiff, 2932896);
  50083. ExpectIntEQ(secsDiff, 86399);
  50084. ASN1_TIME_free(fromTime);
  50085. ASN1_TIME_free(closeToTime);
  50086. ASN1_TIME_free(toTime);
  50087. ASN1_TIME_free(invalidTime);
  50088. #endif
  50089. return EXPECT_RESULT();
  50090. }
  50091. static int test_wolfSSL_ASN1_TIME_adj(void)
  50092. {
  50093. EXPECT_DECLS;
  50094. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME) && \
  50095. !defined(USER_TIME) && !defined(TIME_OVERRIDES)
  50096. const int year = 365*24*60*60;
  50097. const int day = 24*60*60;
  50098. const int hour = 60*60;
  50099. const int mini = 60;
  50100. const byte asn_utc_time = ASN_UTC_TIME;
  50101. #if !defined(TIME_T_NOT_64BIT) && !defined(NO_64BIT)
  50102. const byte asn_gen_time = ASN_GENERALIZED_TIME;
  50103. #endif
  50104. WOLFSSL_ASN1_TIME* asn_time = NULL;
  50105. WOLFSSL_ASN1_TIME* s = NULL;
  50106. int offset_day;
  50107. long offset_sec;
  50108. char date_str[CTC_DATE_SIZE + 1];
  50109. time_t t;
  50110. ExpectNotNull(s = wolfSSL_ASN1_TIME_new());
  50111. /* UTC notation test */
  50112. /* 2000/2/15 20:30:00 */
  50113. t = (time_t)30 * year + 45 * day + 20 * hour + 30 * mini + 7 * day;
  50114. offset_day = 7;
  50115. offset_sec = 45 * mini;
  50116. /* offset_sec = -45 * min;*/
  50117. ExpectNotNull(asn_time =
  50118. wolfSSL_ASN1_TIME_adj(s, t, offset_day, offset_sec));
  50119. ExpectTrue(asn_time->type == asn_utc_time);
  50120. ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
  50121. CTC_DATE_SIZE));
  50122. date_str[CTC_DATE_SIZE] = '\0';
  50123. ExpectIntEQ(0, XMEMCMP(date_str, "000222211500Z", 13));
  50124. /* negative offset */
  50125. offset_sec = -45 * mini;
  50126. asn_time = wolfSSL_ASN1_TIME_adj(s, t, offset_day, offset_sec);
  50127. ExpectNotNull(asn_time);
  50128. ExpectTrue(asn_time->type == asn_utc_time);
  50129. ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
  50130. CTC_DATE_SIZE));
  50131. date_str[CTC_DATE_SIZE] = '\0';
  50132. ExpectIntEQ(0, XMEMCMP(date_str, "000222194500Z", 13));
  50133. XFREE(s, NULL, DYNAMIC_TYPE_OPENSSL);
  50134. s = NULL;
  50135. XMEMSET(date_str, 0, sizeof(date_str));
  50136. /* Generalized time will overflow time_t if not long */
  50137. #if !defined(TIME_T_NOT_64BIT) && !defined(NO_64BIT)
  50138. s = (WOLFSSL_ASN1_TIME*)XMALLOC(sizeof(WOLFSSL_ASN1_TIME), NULL,
  50139. DYNAMIC_TYPE_OPENSSL);
  50140. /* GeneralizedTime notation test */
  50141. /* 2055/03/01 09:00:00 */
  50142. t = (time_t)85 * year + 59 * day + 9 * hour + 21 * day;
  50143. offset_day = 12;
  50144. offset_sec = 10 * mini;
  50145. ExpectNotNull(asn_time = wolfSSL_ASN1_TIME_adj(s, t, offset_day,
  50146. offset_sec));
  50147. ExpectTrue(asn_time->type == asn_gen_time);
  50148. ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
  50149. CTC_DATE_SIZE));
  50150. date_str[CTC_DATE_SIZE] = '\0';
  50151. ExpectIntEQ(0, XMEMCMP(date_str, "20550313091000Z", 15));
  50152. XFREE(s, NULL, DYNAMIC_TYPE_OPENSSL);
  50153. s = NULL;
  50154. XMEMSET(date_str, 0, sizeof(date_str));
  50155. #endif /* !TIME_T_NOT_64BIT && !NO_64BIT */
  50156. /* if WOLFSSL_ASN1_TIME struct is not allocated */
  50157. s = NULL;
  50158. t = (time_t)30 * year + 45 * day + 20 * hour + 30 * mini + 15 + 7 * day;
  50159. offset_day = 7;
  50160. offset_sec = 45 * mini;
  50161. ExpectNotNull(asn_time = wolfSSL_ASN1_TIME_adj(s, t, offset_day,
  50162. offset_sec));
  50163. ExpectTrue(asn_time->type == asn_utc_time);
  50164. ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
  50165. CTC_DATE_SIZE));
  50166. date_str[CTC_DATE_SIZE] = '\0';
  50167. ExpectIntEQ(0, XMEMCMP(date_str, "000222211515Z", 13));
  50168. XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
  50169. asn_time = NULL;
  50170. ExpectNotNull(asn_time = wolfSSL_ASN1_TIME_adj(NULL, t, offset_day,
  50171. offset_sec));
  50172. ExpectTrue(asn_time->type == asn_utc_time);
  50173. ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
  50174. CTC_DATE_SIZE));
  50175. date_str[CTC_DATE_SIZE] = '\0';
  50176. ExpectIntEQ(0, XMEMCMP(date_str, "000222211515Z", 13));
  50177. XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
  50178. #endif
  50179. return EXPECT_RESULT();
  50180. }
  50181. static int test_wolfSSL_ASN1_TIME_to_tm(void)
  50182. {
  50183. EXPECT_DECLS;
  50184. #if (defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(WOLFSSL_NGINX) || \
  50185. defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA) || \
  50186. defined(OPENSSL_ALL)) && !defined(NO_ASN_TIME)
  50187. ASN1_TIME asnTime;
  50188. struct tm tm;
  50189. time_t testTime = 1683926567; /* Fri May 12 09:22:47 PM UTC 2023 */
  50190. XMEMSET(&tm, 0, sizeof(struct tm));
  50191. XMEMSET(&asnTime, 0, sizeof(ASN1_TIME));
  50192. ExpectIntEQ(ASN1_TIME_set_string(&asnTime, "000222211515Z"), 1);
  50193. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, NULL), 1);
  50194. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 1);
  50195. ExpectIntEQ(tm.tm_sec, 15);
  50196. ExpectIntEQ(tm.tm_min, 15);
  50197. ExpectIntEQ(tm.tm_hour, 21);
  50198. ExpectIntEQ(tm.tm_mday, 22);
  50199. ExpectIntEQ(tm.tm_mon, 1);
  50200. ExpectIntEQ(tm.tm_year, 100);
  50201. ExpectIntEQ(tm.tm_isdst, 0);
  50202. #ifdef XMKTIME
  50203. ExpectIntEQ(tm.tm_wday, 2);
  50204. ExpectIntEQ(tm.tm_yday, 52);
  50205. #endif
  50206. ExpectIntEQ(ASN1_TIME_set_string(&asnTime, "500222211515Z"), 1);
  50207. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 1);
  50208. ExpectIntEQ(tm.tm_year, 50);
  50209. /* Get current time. */
  50210. ExpectIntEQ(ASN1_TIME_to_tm(NULL, NULL), 0);
  50211. ExpectIntEQ(ASN1_TIME_to_tm(NULL, &tm), 1);
  50212. XMEMSET(&asnTime, 0, sizeof(ASN1_TIME));
  50213. /* 0 length. */
  50214. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  50215. /* No type. */
  50216. asnTime.length = 1;
  50217. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  50218. /* Not UTCTIME length. */
  50219. asnTime.type = V_ASN1_UTCTIME;
  50220. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  50221. /* Not GENERALIZEDTIME length. */
  50222. asnTime.type = V_ASN1_GENERALIZEDTIME;
  50223. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  50224. /* Not Zulu timezone. */
  50225. ExpectIntEQ(ASN1_TIME_set_string(&asnTime, "000222211515U"), 1);
  50226. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  50227. ExpectIntEQ(ASN1_TIME_set_string(&asnTime, "20000222211515U"), 1);
  50228. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 0);
  50229. #ifdef XMKTIME
  50230. ExpectNotNull(ASN1_TIME_adj(&asnTime, testTime, 0, 0));
  50231. ExpectIntEQ(ASN1_TIME_to_tm(&asnTime, &tm), 1);
  50232. ExpectIntEQ(tm.tm_sec, 47);
  50233. ExpectIntEQ(tm.tm_min, 22);
  50234. ExpectIntEQ(tm.tm_hour, 21);
  50235. ExpectIntEQ(tm.tm_mday, 12);
  50236. ExpectIntEQ(tm.tm_mon, 4);
  50237. ExpectIntEQ(tm.tm_year, 123);
  50238. ExpectIntEQ(tm.tm_wday, 5);
  50239. ExpectIntEQ(tm.tm_yday, 131);
  50240. /* Confirm that when used with a tm struct from ASN1_TIME_adj, all other
  50241. fields are zeroed out as expected. */
  50242. ExpectIntEQ(tm.tm_isdst, 0);
  50243. #endif
  50244. #endif
  50245. return EXPECT_RESULT();
  50246. }
  50247. static int test_wolfSSL_ASN1_TIME_to_generalizedtime(void)
  50248. {
  50249. EXPECT_DECLS;
  50250. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME)
  50251. WOLFSSL_ASN1_TIME *t = NULL;
  50252. WOLFSSL_ASN1_TIME *out = NULL;
  50253. WOLFSSL_ASN1_TIME *gtime = NULL;
  50254. int tlen = 0;
  50255. unsigned char *data = NULL;
  50256. ExpectNotNull(t = wolfSSL_ASN1_TIME_new());
  50257. ExpectNull(wolfSSL_ASN1_TIME_to_generalizedtime(NULL, &out));
  50258. /* type not set. */
  50259. ExpectNull(wolfSSL_ASN1_TIME_to_generalizedtime(t, &out));
  50260. XFREE(t, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  50261. t = NULL;
  50262. /* UTC Time test */
  50263. ExpectNotNull(t = wolfSSL_ASN1_TIME_new());
  50264. if (t != NULL) {
  50265. XMEMSET(t->data, 0, ASN_GENERALIZED_TIME_SIZE);
  50266. t->type = ASN_UTC_TIME;
  50267. t->length = ASN_UTC_TIME_SIZE;
  50268. XMEMCPY(t->data, "050727123456Z", ASN_UTC_TIME_SIZE);
  50269. }
  50270. ExpectIntEQ(tlen = wolfSSL_ASN1_TIME_get_length(t), ASN_UTC_TIME_SIZE);
  50271. ExpectStrEQ((char*)(data = wolfSSL_ASN1_TIME_get_data(t)), "050727123456Z");
  50272. out = NULL;
  50273. ExpectNotNull(gtime = wolfSSL_ASN1_TIME_to_generalizedtime(t, &out));
  50274. wolfSSL_ASN1_TIME_free(gtime);
  50275. gtime = NULL;
  50276. ExpectNotNull(out = wolfSSL_ASN1_TIME_new());
  50277. ExpectNotNull(gtime = wolfSSL_ASN1_TIME_to_generalizedtime(t, &out));
  50278. ExpectPtrEq(gtime, out);
  50279. ExpectIntEQ(gtime->type, ASN_GENERALIZED_TIME);
  50280. ExpectIntEQ(gtime->length, ASN_GENERALIZED_TIME_SIZE);
  50281. ExpectStrEQ((char*)gtime->data, "20050727123456Z");
  50282. /* Generalized Time test */
  50283. ExpectNotNull(XMEMSET(t, 0, ASN_GENERALIZED_TIME_SIZE));
  50284. ExpectNotNull(XMEMSET(out, 0, ASN_GENERALIZED_TIME_SIZE));
  50285. ExpectNotNull(XMEMSET(data, 0, ASN_GENERALIZED_TIME_SIZE));
  50286. if (t != NULL) {
  50287. t->type = ASN_GENERALIZED_TIME;
  50288. t->length = ASN_GENERALIZED_TIME_SIZE;
  50289. XMEMCPY(t->data, "20050727123456Z", ASN_GENERALIZED_TIME_SIZE);
  50290. }
  50291. ExpectIntEQ(tlen = wolfSSL_ASN1_TIME_get_length(t),
  50292. ASN_GENERALIZED_TIME_SIZE);
  50293. ExpectStrEQ((char*)(data = wolfSSL_ASN1_TIME_get_data(t)),
  50294. "20050727123456Z");
  50295. ExpectNotNull(gtime = wolfSSL_ASN1_TIME_to_generalizedtime(t, &out));
  50296. ExpectIntEQ(gtime->type, ASN_GENERALIZED_TIME);
  50297. ExpectIntEQ(gtime->length, ASN_GENERALIZED_TIME_SIZE);
  50298. ExpectStrEQ((char*)gtime->data, "20050727123456Z");
  50299. /* UTC Time to Generalized Time 1900's test */
  50300. ExpectNotNull(XMEMSET(t, 0, ASN_GENERALIZED_TIME_SIZE));
  50301. ExpectNotNull(XMEMSET(out, 0, ASN_GENERALIZED_TIME_SIZE));
  50302. ExpectNotNull(XMEMSET(data, 0, ASN_GENERALIZED_TIME_SIZE));
  50303. if (t != NULL) {
  50304. t->type = ASN_UTC_TIME;
  50305. t->length = ASN_UTC_TIME_SIZE;
  50306. XMEMCPY(t->data, "500727123456Z", ASN_UTC_TIME_SIZE);
  50307. }
  50308. ExpectNotNull(gtime = wolfSSL_ASN1_TIME_to_generalizedtime(t, &out));
  50309. ExpectIntEQ(gtime->type, ASN_GENERALIZED_TIME);
  50310. ExpectIntEQ(gtime->length, ASN_GENERALIZED_TIME_SIZE);
  50311. ExpectStrEQ((char*)gtime->data, "19500727123456Z");
  50312. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  50313. /* Null parameter test */
  50314. ExpectNotNull(XMEMSET(t, 0, ASN_GENERALIZED_TIME_SIZE));
  50315. gtime = NULL;
  50316. out = NULL;
  50317. if (t != NULL) {
  50318. t->type = ASN_UTC_TIME;
  50319. t->length = ASN_UTC_TIME_SIZE;
  50320. XMEMCPY(t->data, "050727123456Z", ASN_UTC_TIME_SIZE);
  50321. }
  50322. ExpectNotNull(gtime = wolfSSL_ASN1_TIME_to_generalizedtime(t, NULL));
  50323. ExpectIntEQ(gtime->type, ASN_GENERALIZED_TIME);
  50324. ExpectIntEQ(gtime->length, ASN_GENERALIZED_TIME_SIZE);
  50325. ExpectStrEQ((char*)gtime->data, "20050727123456Z");
  50326. XFREE(gtime, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  50327. XFREE(t, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  50328. #endif
  50329. return EXPECT_RESULT();
  50330. }
  50331. static int test_wolfSSL_ASN1_TIME_print(void)
  50332. {
  50333. EXPECT_DECLS;
  50334. #if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(NO_BIO) && \
  50335. (defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(WOLFSSL_NGINX) || \
  50336. defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA) || \
  50337. defined(OPENSSL_ALL)) && defined(USE_CERT_BUFFERS_2048) && \
  50338. !defined(NO_ASN_TIME)
  50339. BIO* bio = NULL;
  50340. BIO* fixed = NULL;
  50341. X509* x509 = NULL;
  50342. const unsigned char* der = client_cert_der_2048;
  50343. ASN1_TIME* notAfter = NULL;
  50344. ASN1_TIME* notBefore = NULL;
  50345. unsigned char buf[25];
  50346. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  50347. ExpectNotNull(fixed = BIO_new(wolfSSL_BIO_s_fixed_mem()));
  50348. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(der,
  50349. sizeof_client_cert_der_2048, WOLFSSL_FILETYPE_ASN1));
  50350. ExpectNotNull(notBefore = X509_get_notBefore(x509));
  50351. ExpectIntEQ(ASN1_TIME_print(NULL, NULL), 0);
  50352. ExpectIntEQ(ASN1_TIME_print(bio, NULL), 0);
  50353. ExpectIntEQ(ASN1_TIME_print(NULL, notBefore), 0);
  50354. ExpectIntEQ(ASN1_TIME_print(bio, notBefore), 1);
  50355. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 24);
  50356. ExpectIntEQ(XMEMCMP(buf, "Dec 13 22:19:28 2023 GMT", sizeof(buf) - 1), 0);
  50357. /* Test BIO_write fails. */
  50358. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  50359. /* Ensure there is 0 bytes available to write into. */
  50360. ExpectIntEQ(BIO_write(fixed, buf, 1), 1);
  50361. ExpectIntEQ(ASN1_TIME_print(fixed, notBefore), 0);
  50362. ExpectIntEQ(BIO_set_write_buf_size(fixed, 1), 1);
  50363. ExpectIntEQ(ASN1_TIME_print(fixed, notBefore), 0);
  50364. ExpectIntEQ(BIO_set_write_buf_size(fixed, 23), 1);
  50365. ExpectIntEQ(ASN1_TIME_print(fixed, notBefore), 0);
  50366. /* create a bad time and test results */
  50367. ExpectNotNull(notAfter = X509_get_notAfter(x509));
  50368. ExpectIntEQ(ASN1_TIME_check(notAfter), 1);
  50369. if (EXPECT_SUCCESS()) {
  50370. notAfter->data[8] = 0;
  50371. notAfter->data[3] = 0;
  50372. }
  50373. ExpectIntNE(ASN1_TIME_print(bio, notAfter), 1);
  50374. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 14);
  50375. ExpectIntEQ(XMEMCMP(buf, "Bad time value", 14), 0);
  50376. ExpectIntEQ(ASN1_TIME_check(notAfter), 0);
  50377. BIO_free(bio);
  50378. BIO_free(fixed);
  50379. X509_free(x509);
  50380. #endif
  50381. return EXPECT_RESULT();
  50382. }
  50383. static int test_wolfSSL_ASN1_UTCTIME_print(void)
  50384. {
  50385. EXPECT_DECLS;
  50386. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME) && !defined(NO_BIO)
  50387. BIO* bio = NULL;
  50388. ASN1_UTCTIME* utc = NULL;
  50389. unsigned char buf[25];
  50390. const char* validDate = "190424111501Z"; /* UTC = YYMMDDHHMMSSZ */
  50391. const char* invalidDate = "190424111501X"; /* UTC = YYMMDDHHMMSSZ */
  50392. const char* genDate = "20190424111501Z"; /* GEN = YYYYMMDDHHMMSSZ */
  50393. /* Valid date */
  50394. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  50395. ExpectNotNull(utc = (ASN1_UTCTIME*)XMALLOC(sizeof(ASN1_UTCTIME), NULL,
  50396. DYNAMIC_TYPE_ASN1));
  50397. if (utc != NULL) {
  50398. utc->type = ASN_UTC_TIME;
  50399. utc->length = ASN_UTC_TIME_SIZE;
  50400. XMEMCPY(utc->data, (byte*)validDate, ASN_UTC_TIME_SIZE);
  50401. }
  50402. ExpectIntEQ(ASN1_UTCTIME_print(NULL, NULL), 0);
  50403. ExpectIntEQ(ASN1_UTCTIME_print(bio, NULL), 0);
  50404. ExpectIntEQ(ASN1_UTCTIME_print(NULL, utc), 0);
  50405. ExpectIntEQ(ASN1_UTCTIME_print(bio, utc), 1);
  50406. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 24);
  50407. ExpectIntEQ(XMEMCMP(buf, "Apr 24 11:15:01 2019 GMT", sizeof(buf)-1), 0);
  50408. XMEMSET(buf, 0, sizeof(buf));
  50409. BIO_free(bio);
  50410. bio = NULL;
  50411. /* Invalid format */
  50412. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  50413. if (utc != NULL) {
  50414. utc->type = ASN_UTC_TIME;
  50415. utc->length = ASN_UTC_TIME_SIZE;
  50416. XMEMCPY(utc->data, (byte*)invalidDate, ASN_UTC_TIME_SIZE);
  50417. }
  50418. ExpectIntEQ(ASN1_UTCTIME_print(bio, utc), 0);
  50419. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 14);
  50420. ExpectIntEQ(XMEMCMP(buf, "Bad time value", 14), 0);
  50421. /* Invalid type */
  50422. if (utc != NULL) {
  50423. utc->type = ASN_GENERALIZED_TIME;
  50424. utc->length = ASN_GENERALIZED_TIME_SIZE;
  50425. XMEMCPY(utc->data, (byte*)genDate, ASN_GENERALIZED_TIME_SIZE);
  50426. }
  50427. ExpectIntEQ(ASN1_UTCTIME_print(bio, utc), 0);
  50428. XFREE(utc, NULL, DYNAMIC_TYPE_ASN1);
  50429. BIO_free(bio);
  50430. #endif /* OPENSSL_EXTRA && !NO_ASN_TIME && !NO_BIO */
  50431. return EXPECT_RESULT();
  50432. }
  50433. static int test_wolfSSL_ASN1_TYPE(void)
  50434. {
  50435. EXPECT_DECLS;
  50436. #if defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD) || \
  50437. defined(WOLFSSL_HAPROXY) || defined(WOLFSSL_WPAS)
  50438. WOLFSSL_ASN1_TYPE* t = NULL;
  50439. WOLFSSL_ASN1_OBJECT* obj = NULL;
  50440. #ifndef NO_ASN_TIME
  50441. WOLFSSL_ASN1_TIME* time = NULL;
  50442. #endif
  50443. WOLFSSL_ASN1_STRING* str = NULL;
  50444. unsigned char data[] = { 0x00 };
  50445. ASN1_TYPE_set(NULL, V_ASN1_NULL, NULL);
  50446. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  50447. ASN1_TYPE_set(t, V_ASN1_EOC, NULL);
  50448. wolfSSL_ASN1_TYPE_free(t);
  50449. t = NULL;
  50450. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  50451. ASN1_TYPE_set(t, V_ASN1_NULL, NULL);
  50452. ASN1_TYPE_set(t, V_ASN1_NULL, data);
  50453. wolfSSL_ASN1_TYPE_free(t);
  50454. t = NULL;
  50455. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  50456. ExpectNotNull(obj = wolfSSL_ASN1_OBJECT_new());
  50457. ASN1_TYPE_set(t, V_ASN1_OBJECT, obj);
  50458. wolfSSL_ASN1_TYPE_free(t);
  50459. t = NULL;
  50460. #ifndef NO_ASN_TIME
  50461. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  50462. ExpectNotNull(time = wolfSSL_ASN1_TIME_new());
  50463. ASN1_TYPE_set(t, V_ASN1_UTCTIME, time);
  50464. wolfSSL_ASN1_TYPE_free(t);
  50465. t = NULL;
  50466. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  50467. ExpectNotNull(time = wolfSSL_ASN1_TIME_new());
  50468. ASN1_TYPE_set(t, V_ASN1_GENERALIZEDTIME, time);
  50469. wolfSSL_ASN1_TYPE_free(t);
  50470. t = NULL;
  50471. #endif
  50472. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  50473. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  50474. ASN1_TYPE_set(t, V_ASN1_UTF8STRING, str);
  50475. wolfSSL_ASN1_TYPE_free(t);
  50476. t = NULL;
  50477. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  50478. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  50479. ASN1_TYPE_set(t, V_ASN1_PRINTABLESTRING, str);
  50480. wolfSSL_ASN1_TYPE_free(t);
  50481. t = NULL;
  50482. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  50483. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  50484. ASN1_TYPE_set(t, V_ASN1_T61STRING, str);
  50485. wolfSSL_ASN1_TYPE_free(t);
  50486. t = NULL;
  50487. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  50488. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  50489. ASN1_TYPE_set(t, V_ASN1_IA5STRING, str);
  50490. wolfSSL_ASN1_TYPE_free(t);
  50491. t = NULL;
  50492. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  50493. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  50494. ASN1_TYPE_set(t, V_ASN1_UNIVERSALSTRING, str);
  50495. wolfSSL_ASN1_TYPE_free(t);
  50496. t = NULL;
  50497. ExpectNotNull(t = wolfSSL_ASN1_TYPE_new());
  50498. ExpectNotNull(str = wolfSSL_ASN1_STRING_new());
  50499. ASN1_TYPE_set(t, V_ASN1_SEQUENCE, str);
  50500. wolfSSL_ASN1_TYPE_free(t);
  50501. t = NULL;
  50502. #endif
  50503. return EXPECT_RESULT();
  50504. }
  50505. /* Testing code used in old dpp.c in hostap */
  50506. #if defined(OPENSSL_ALL) && defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  50507. typedef struct {
  50508. /* AlgorithmIdentifier ecPublicKey with optional parameters present
  50509. * as an OID identifying the curve */
  50510. X509_ALGOR *alg;
  50511. /* Compressed format public key per ANSI X9.63 */
  50512. ASN1_BIT_STRING *pub_key;
  50513. } DPP_BOOTSTRAPPING_KEY;
  50514. ASN1_SEQUENCE(DPP_BOOTSTRAPPING_KEY) = {
  50515. ASN1_SIMPLE(DPP_BOOTSTRAPPING_KEY, alg, X509_ALGOR),
  50516. ASN1_SIMPLE(DPP_BOOTSTRAPPING_KEY, pub_key, ASN1_BIT_STRING)
  50517. } ASN1_SEQUENCE_END(DPP_BOOTSTRAPPING_KEY)
  50518. IMPLEMENT_ASN1_FUNCTIONS(DPP_BOOTSTRAPPING_KEY)
  50519. typedef struct {
  50520. int type;
  50521. union {
  50522. ASN1_BIT_STRING *str1;
  50523. ASN1_BIT_STRING *str2;
  50524. ASN1_BIT_STRING *str3;
  50525. } d;
  50526. } ASN1_CHOICE_TEST;
  50527. ASN1_CHOICE(ASN1_CHOICE_TEST) = {
  50528. ASN1_IMP(ASN1_CHOICE_TEST, d.str1, ASN1_BIT_STRING, 1),
  50529. ASN1_IMP(ASN1_CHOICE_TEST, d.str2, ASN1_BIT_STRING, 2),
  50530. ASN1_IMP(ASN1_CHOICE_TEST, d.str3, ASN1_BIT_STRING, 3)
  50531. } ASN1_CHOICE_END(ASN1_CHOICE_TEST)
  50532. IMPLEMENT_ASN1_FUNCTIONS(ASN1_CHOICE_TEST)
  50533. /* Test nested objects */
  50534. typedef struct {
  50535. DPP_BOOTSTRAPPING_KEY* key;
  50536. ASN1_INTEGER* asnNum;
  50537. ASN1_INTEGER* expNum;
  50538. STACK_OF(ASN1_GENERALSTRING) *strList;
  50539. ASN1_CHOICE_TEST* str;
  50540. } TEST_ASN1_NEST1;
  50541. ASN1_SEQUENCE(TEST_ASN1_NEST1) = {
  50542. ASN1_SIMPLE(TEST_ASN1_NEST1, key, DPP_BOOTSTRAPPING_KEY),
  50543. ASN1_SIMPLE(TEST_ASN1_NEST1, asnNum, ASN1_INTEGER),
  50544. ASN1_EXP(TEST_ASN1_NEST1, expNum, ASN1_INTEGER, 0),
  50545. ASN1_EXP_SEQUENCE_OF(TEST_ASN1_NEST1, strList, ASN1_GENERALSTRING, 1),
  50546. ASN1_SIMPLE(TEST_ASN1_NEST1, str, ASN1_CHOICE_TEST)
  50547. } ASN1_SEQUENCE_END(TEST_ASN1_NEST1)
  50548. IMPLEMENT_ASN1_FUNCTIONS(TEST_ASN1_NEST1)
  50549. typedef struct {
  50550. ASN1_INTEGER* num;
  50551. DPP_BOOTSTRAPPING_KEY* key;
  50552. TEST_ASN1_NEST1* asn1_obj;
  50553. } TEST_ASN1_NEST2;
  50554. ASN1_SEQUENCE(TEST_ASN1_NEST2) = {
  50555. ASN1_SIMPLE(TEST_ASN1_NEST2, num, ASN1_INTEGER),
  50556. ASN1_SIMPLE(TEST_ASN1_NEST2, key, DPP_BOOTSTRAPPING_KEY),
  50557. ASN1_SIMPLE(TEST_ASN1_NEST2, asn1_obj, TEST_ASN1_NEST1)
  50558. } ASN1_SEQUENCE_END(TEST_ASN1_NEST2)
  50559. IMPLEMENT_ASN1_FUNCTIONS(TEST_ASN1_NEST2)
  50560. /* End nested objects */
  50561. typedef struct {
  50562. ASN1_INTEGER *integer;
  50563. } TEST_ASN1;
  50564. ASN1_SEQUENCE(TEST_ASN1) = {
  50565. ASN1_SIMPLE(TEST_ASN1, integer, ASN1_INTEGER),
  50566. } ASN1_SEQUENCE_END(TEST_ASN1)
  50567. IMPLEMENT_ASN1_FUNCTIONS(TEST_ASN1)
  50568. typedef STACK_OF(ASN1_INTEGER) TEST_ASN1_ITEM;
  50569. ASN1_ITEM_TEMPLATE(TEST_ASN1_ITEM) =
  50570. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, MemName, ASN1_INTEGER)
  50571. ASN1_ITEM_TEMPLATE_END(TEST_ASN1_ITEM)
  50572. IMPLEMENT_ASN1_FUNCTIONS(TEST_ASN1_ITEM)
  50573. #endif
  50574. static int test_wolfSSL_IMPLEMENT_ASN1_FUNCTIONS(void)
  50575. {
  50576. EXPECT_DECLS;
  50577. /* Testing code used in dpp.c in hostap */
  50578. #if defined(OPENSSL_ALL) && defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  50579. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  50580. EC_KEY *eckey = NULL;
  50581. EVP_PKEY *key = NULL;
  50582. size_t len = 0;
  50583. unsigned char *der = NULL;
  50584. unsigned char *der2 = NULL;
  50585. const unsigned char *tmp = NULL;
  50586. DPP_BOOTSTRAPPING_KEY *bootstrap = NULL, *bootstrap2 = NULL;
  50587. const unsigned char *in = ecc_clikey_der_256;
  50588. WOLFSSL_ASN1_OBJECT* ec_obj = NULL;
  50589. WOLFSSL_ASN1_OBJECT* group_obj = NULL;
  50590. const EC_GROUP *group = NULL;
  50591. const EC_POINT *point = NULL;
  50592. int nid;
  50593. TEST_ASN1 *test_asn1 = NULL;
  50594. TEST_ASN1 *test_asn1_2 = NULL;
  50595. const unsigned char badObjDer[] = { 0x06, 0x00 };
  50596. const unsigned char goodObjDer[] = {
  50597. 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01
  50598. };
  50599. WOLFSSL_ASN1_ITEM emptyTemplate;
  50600. XMEMSET(&emptyTemplate, 0, sizeof(WOLFSSL_ASN1_ITEM));
  50601. ExpectNotNull(bootstrap = DPP_BOOTSTRAPPING_KEY_new());
  50602. der = NULL;
  50603. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(NULL, &der), -1);
  50604. ExpectIntEQ(wolfSSL_ASN1_item_i2d(bootstrap, &der, NULL), -1);
  50605. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap, &der), -1);
  50606. ExpectNotNull(key = d2i_PrivateKey(EVP_PKEY_EC, NULL, &in,
  50607. (long)sizeof_ecc_clikey_der_256));
  50608. ExpectNotNull(eckey = EVP_PKEY_get1_EC_KEY(key));
  50609. ExpectNotNull(group = EC_KEY_get0_group(eckey));
  50610. ExpectNotNull(point = EC_KEY_get0_public_key(eckey));
  50611. nid = EC_GROUP_get_curve_name(group);
  50612. ec_obj = OBJ_nid2obj(EVP_PKEY_EC);
  50613. group_obj = OBJ_nid2obj(nid);
  50614. if ((ec_obj != NULL) && (group_obj != NULL)) {
  50615. ExpectIntEQ(X509_ALGOR_set0(bootstrap->alg, ec_obj, V_ASN1_OBJECT,
  50616. group_obj), 1);
  50617. if (EXPECT_SUCCESS()) {
  50618. ec_obj = NULL;
  50619. group_obj = NULL;
  50620. }
  50621. }
  50622. wolfSSL_ASN1_OBJECT_free(group_obj);
  50623. wolfSSL_ASN1_OBJECT_free(ec_obj);
  50624. ExpectIntEQ(EC_POINT_point2oct(group, point, 0, NULL, 0, NULL), 0);
  50625. #ifdef HAVE_COMP_KEY
  50626. ExpectIntGT((len = EC_POINT_point2oct(
  50627. group, point, POINT_CONVERSION_COMPRESSED,
  50628. NULL, 0, NULL)), 0);
  50629. #else
  50630. ExpectIntGT((len = EC_POINT_point2oct(
  50631. group, point, POINT_CONVERSION_UNCOMPRESSED,
  50632. NULL, 0, NULL)), 0);
  50633. #endif
  50634. ExpectNotNull(der = (unsigned char*)XMALLOC(len, NULL, DYNAMIC_TYPE_ASN1));
  50635. #ifdef HAVE_COMP_KEY
  50636. ExpectIntEQ(EC_POINT_point2oct(group, point, POINT_CONVERSION_COMPRESSED,
  50637. der, len-1, NULL), 0);
  50638. ExpectIntEQ(EC_POINT_point2oct(group, point, POINT_CONVERSION_COMPRESSED,
  50639. der, len, NULL), len);
  50640. #else
  50641. ExpectIntEQ(EC_POINT_point2oct(group, point, POINT_CONVERSION_UNCOMPRESSED,
  50642. der, len-1, NULL), 0);
  50643. ExpectIntEQ(EC_POINT_point2oct(group, point, POINT_CONVERSION_UNCOMPRESSED,
  50644. der, len, NULL), len);
  50645. #endif
  50646. if (EXPECT_SUCCESS()) {
  50647. bootstrap->pub_key->data = der;
  50648. bootstrap->pub_key->length = (int)len;
  50649. /* Not actually used */
  50650. bootstrap->pub_key->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07);
  50651. bootstrap->pub_key->flags |= ASN1_STRING_FLAG_BITS_LEFT;
  50652. }
  50653. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap, NULL), 16+len);
  50654. der = NULL;
  50655. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap, &der), 16+len);
  50656. der2 = NULL;
  50657. #ifdef WOLFSSL_ASN_TEMPLATE
  50658. tmp = der;
  50659. ExpectNotNull(d2i_DPP_BOOTSTRAPPING_KEY(&bootstrap2, &tmp, 16+len));
  50660. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap2, &der2), 16+len);
  50661. ExpectBufEQ(der, der2, 49);
  50662. #endif
  50663. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  50664. XFREE(der2, NULL, DYNAMIC_TYPE_ASN1);
  50665. EVP_PKEY_free(key);
  50666. EC_KEY_free(eckey);
  50667. DPP_BOOTSTRAPPING_KEY_free(bootstrap);
  50668. DPP_BOOTSTRAPPING_KEY_free(bootstrap2);
  50669. bootstrap = NULL;
  50670. DPP_BOOTSTRAPPING_KEY_free(NULL);
  50671. /* Create bootstrap key with bad OBJECT_ID DER data, parameter that is
  50672. * a NULL and an empty BIT_STRING. */
  50673. ExpectNotNull(bootstrap = DPP_BOOTSTRAPPING_KEY_new());
  50674. ExpectNotNull(bootstrap->alg->algorithm = wolfSSL_ASN1_OBJECT_new());
  50675. if (EXPECT_SUCCESS()) {
  50676. bootstrap->alg->algorithm->obj = badObjDer;
  50677. bootstrap->alg->algorithm->objSz = (unsigned int)sizeof(badObjDer);
  50678. }
  50679. ExpectNotNull(bootstrap->alg->parameter = wolfSSL_ASN1_TYPE_new());
  50680. if (EXPECT_SUCCESS()) {
  50681. bootstrap->alg->parameter->type = V_ASN1_NULL;
  50682. bootstrap->alg->parameter->value.ptr = NULL;
  50683. bootstrap->pub_key->data = NULL;
  50684. bootstrap->pub_key->length = 0;
  50685. /* Not actually used */
  50686. bootstrap->pub_key->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07);
  50687. bootstrap->pub_key->flags |= ASN1_STRING_FLAG_BITS_LEFT;
  50688. }
  50689. /* Encode with bad OBJECT_ID. */
  50690. der = NULL;
  50691. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap, &der), -1);
  50692. /* Fix OBJECT_ID and encode with empty BIT_STRING. */
  50693. if (EXPECT_SUCCESS()) {
  50694. bootstrap->alg->algorithm->obj = goodObjDer;
  50695. bootstrap->alg->algorithm->objSz = (unsigned int)sizeof(goodObjDer);
  50696. bootstrap->alg->algorithm->grp = 2;
  50697. }
  50698. der = NULL;
  50699. ExpectIntEQ(i2d_DPP_BOOTSTRAPPING_KEY(bootstrap, &der), 16);
  50700. ExpectIntEQ(wolfSSL_ASN1_item_i2d(bootstrap, &der, &emptyTemplate), -1);
  50701. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  50702. DPP_BOOTSTRAPPING_KEY_free(bootstrap);
  50703. /* Test integer */
  50704. ExpectNotNull(test_asn1 = TEST_ASN1_new());
  50705. der = NULL;
  50706. ExpectIntEQ(ASN1_INTEGER_set(test_asn1->integer, 100), 1);
  50707. ExpectIntEQ(i2d_TEST_ASN1(test_asn1, &der), 5);
  50708. tmp = der;
  50709. ExpectNotNull(d2i_TEST_ASN1(&test_asn1_2, &tmp, 5));
  50710. der2 = NULL;
  50711. ExpectIntEQ(i2d_TEST_ASN1(test_asn1_2, &der2), 5);
  50712. ExpectBufEQ(der, der2, 5);
  50713. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  50714. XFREE(der2, NULL, DYNAMIC_TYPE_ASN1);
  50715. TEST_ASN1_free(test_asn1);
  50716. TEST_ASN1_free(test_asn1_2);
  50717. /* Test integer cases. */
  50718. ExpectNull(wolfSSL_ASN1_item_new(NULL));
  50719. TEST_ASN1_free(NULL);
  50720. /* Test nested asn1 objects */
  50721. {
  50722. TEST_ASN1_NEST2 *nested_asn1 = NULL;
  50723. TEST_ASN1_NEST2 *nested_asn1_2 = NULL;
  50724. int i;
  50725. ExpectNotNull(nested_asn1 = TEST_ASN1_NEST2_new());
  50726. /* Populate nested_asn1 with some random data */
  50727. /* nested_asn1->num */
  50728. ExpectIntEQ(ASN1_INTEGER_set(nested_asn1->num, 30003), 1);
  50729. /* nested_asn1->key */
  50730. ec_obj = OBJ_nid2obj(EVP_PKEY_EC);
  50731. group_obj = OBJ_nid2obj(NID_secp256k1);
  50732. ExpectIntEQ(X509_ALGOR_set0(nested_asn1->key->alg, ec_obj,
  50733. V_ASN1_OBJECT, group_obj), 1);
  50734. ec_obj = NULL;
  50735. group_obj = NULL;
  50736. ExpectIntEQ(ASN1_BIT_STRING_set_bit(nested_asn1->key->pub_key, 50, 1),
  50737. 1);
  50738. /* nested_asn1->asn1_obj->key */
  50739. ec_obj = OBJ_nid2obj(EVP_PKEY_EC);
  50740. group_obj = OBJ_nid2obj(NID_secp256k1);
  50741. ExpectIntEQ(X509_ALGOR_set0(nested_asn1->asn1_obj->key->alg, ec_obj,
  50742. V_ASN1_OBJECT, group_obj), 1);
  50743. ec_obj = NULL;
  50744. group_obj = NULL;
  50745. ExpectIntEQ(ASN1_BIT_STRING_set_bit(nested_asn1->asn1_obj->key->pub_key,
  50746. 500, 1), 1);
  50747. /* nested_asn1->asn1_obj->asnNum */
  50748. ExpectIntEQ(ASN1_INTEGER_set(nested_asn1->asn1_obj->asnNum, 666666), 1);
  50749. /* nested_asn1->asn1_obj->expNum */
  50750. ExpectIntEQ(ASN1_INTEGER_set(nested_asn1->asn1_obj->expNum, 22222), 1);
  50751. /* nested_asn1->asn1_obj->strList */
  50752. for (i = 10; i >= 0; i--) {
  50753. ASN1_GENERALSTRING* genStr = NULL;
  50754. char fmtStr[20];
  50755. ExpectIntGT(snprintf(fmtStr, sizeof(fmtStr), "Bonjour #%d", i), 0);
  50756. ExpectNotNull(genStr = ASN1_GENERALSTRING_new());
  50757. ExpectIntEQ(ASN1_GENERALSTRING_set(genStr, fmtStr, -1), 1);
  50758. ExpectIntGT(
  50759. sk_ASN1_GENERALSTRING_push(nested_asn1->asn1_obj->strList,
  50760. genStr), 0);
  50761. }
  50762. /* nested_asn1->asn1_obj->str */
  50763. ExpectNotNull(nested_asn1->asn1_obj->str->d.str2
  50764. = ASN1_BIT_STRING_new());
  50765. ExpectIntEQ(ASN1_BIT_STRING_set_bit(nested_asn1->asn1_obj->str->d.str2,
  50766. 150, 1), 1);
  50767. nested_asn1->asn1_obj->str->type = 2;
  50768. der = NULL;
  50769. ExpectIntEQ(i2d_TEST_ASN1_NEST2(nested_asn1, &der), 285);
  50770. #ifdef WOLFSSL_ASN_TEMPLATE
  50771. tmp = der;
  50772. ExpectNotNull(d2i_TEST_ASN1_NEST2(&nested_asn1_2, &tmp, 285));
  50773. der2 = NULL;
  50774. ExpectIntEQ(i2d_TEST_ASN1_NEST2(nested_asn1_2, &der2), 285);
  50775. ExpectBufEQ(der, der2, 285);
  50776. XFREE(der2, NULL, DYNAMIC_TYPE_ASN1);
  50777. #endif
  50778. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  50779. TEST_ASN1_NEST2_free(nested_asn1);
  50780. TEST_ASN1_NEST2_free(nested_asn1_2);
  50781. }
  50782. /* Test ASN1_ITEM_TEMPLATE */
  50783. {
  50784. TEST_ASN1_ITEM* asn1_item = NULL;
  50785. TEST_ASN1_ITEM* asn1_item2 = NULL;
  50786. int i;
  50787. ExpectNotNull(asn1_item = TEST_ASN1_ITEM_new());
  50788. for (i = 0; i < 11; i++) {
  50789. ASN1_INTEGER* asn1_num = NULL;
  50790. ExpectNotNull(asn1_num = ASN1_INTEGER_new());
  50791. ExpectIntEQ(ASN1_INTEGER_set(asn1_num, i), 1);
  50792. ExpectIntGT(wolfSSL_sk_insert(asn1_item, asn1_num, -1), 0);
  50793. }
  50794. der = NULL;
  50795. ExpectIntEQ(i2d_TEST_ASN1_ITEM(asn1_item, &der), 35);
  50796. tmp = der;
  50797. ExpectNotNull(d2i_TEST_ASN1_ITEM(&asn1_item2, &tmp, 35));
  50798. der2 = NULL;
  50799. ExpectIntEQ(i2d_TEST_ASN1_ITEM(asn1_item2, &der2), 35);
  50800. ExpectBufEQ(der, der2, 35);
  50801. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  50802. XFREE(der2, NULL, DYNAMIC_TYPE_ASN1);
  50803. TEST_ASN1_ITEM_free(asn1_item);
  50804. TEST_ASN1_ITEM_free(asn1_item2);
  50805. }
  50806. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  50807. #endif /* OPENSSL_ALL && HAVE_ECC && USE_CERT_BUFFERS_256 */
  50808. return EXPECT_RESULT();
  50809. }
  50810. static int test_wolfSSL_i2d_ASN1_TYPE(void)
  50811. {
  50812. EXPECT_DECLS;
  50813. #if defined(OPENSSL_EXTRA)
  50814. /* Taken from one of sssd's certs othernames */
  50815. unsigned char str_bin[] = {
  50816. 0x04, 0x10, 0xa4, 0x9b, 0xc8, 0xf4, 0x85, 0x8e, 0x89, 0x4d, 0x85, 0x8d,
  50817. 0x27, 0xbd, 0x63, 0xaa, 0x93, 0x93
  50818. };
  50819. ASN1_TYPE* asn1type = NULL;
  50820. unsigned char* der = NULL;
  50821. /* Create ASN1_TYPE manually as we don't have a d2i version yet */
  50822. {
  50823. ASN1_STRING* str = NULL;
  50824. ExpectNotNull(str = ASN1_STRING_type_new(V_ASN1_SEQUENCE));
  50825. ExpectIntEQ(ASN1_STRING_set(str, str_bin, sizeof(str_bin)), 1);
  50826. ExpectNotNull(asn1type = ASN1_TYPE_new());
  50827. ASN1_TYPE_set(asn1type, V_ASN1_SEQUENCE, str);
  50828. }
  50829. ExpectIntEQ(i2d_ASN1_TYPE(asn1type, NULL), sizeof(str_bin));
  50830. ExpectIntEQ(i2d_ASN1_TYPE(asn1type, &der), sizeof(str_bin));
  50831. ExpectBufEQ(der, str_bin, sizeof(str_bin));
  50832. ASN1_TYPE_free(asn1type);
  50833. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  50834. #endif
  50835. return EXPECT_RESULT();
  50836. }
  50837. static int test_wolfSSL_i2d_ASN1_SEQUENCE(void)
  50838. {
  50839. EXPECT_DECLS;
  50840. #if defined(OPENSSL_EXTRA)
  50841. /* Taken from one of sssd's certs othernames */
  50842. unsigned char str_bin[] = {
  50843. 0x04, 0x10, 0xa4, 0x9b, 0xc8, 0xf4, 0x85, 0x8e, 0x89, 0x4d, 0x85, 0x8d,
  50844. 0x27, 0xbd, 0x63, 0xaa, 0x93, 0x93
  50845. };
  50846. ASN1_STRING* str = NULL;
  50847. unsigned char* der = NULL;
  50848. ExpectNotNull(str = ASN1_STRING_type_new(V_ASN1_SEQUENCE));
  50849. ExpectIntEQ(ASN1_STRING_set(str, str_bin, sizeof(str_bin)), 1);
  50850. ExpectIntEQ(i2d_ASN1_SEQUENCE(str, NULL), sizeof(str_bin));
  50851. ExpectIntEQ(i2d_ASN1_SEQUENCE(str, &der), sizeof(str_bin));
  50852. ASN1_STRING_free(str);
  50853. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  50854. #endif
  50855. return EXPECT_RESULT();
  50856. }
  50857. static int test_ASN1_strings(void)
  50858. {
  50859. EXPECT_DECLS;
  50860. #if defined(OPENSSL_EXTRA)
  50861. char text[] = "\0\0test string";
  50862. unsigned char* der = NULL;
  50863. ASN1_STRING* str = NULL;
  50864. /* Set the length byte */
  50865. text[1] = XSTRLEN(text + 2);
  50866. /* GENERALSTRING */
  50867. {
  50868. const unsigned char* p = (const unsigned char*)text;
  50869. text[0] = ASN_GENERALSTRING;
  50870. ExpectNotNull(d2i_ASN1_GENERALSTRING(&str, &p, sizeof(text)));
  50871. ExpectIntEQ(i2d_ASN1_GENERALSTRING(str, &der), 13);
  50872. ASN1_STRING_free(str);
  50873. str = NULL;
  50874. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  50875. der = NULL;
  50876. }
  50877. /* OCTET_STRING */
  50878. {
  50879. const unsigned char* p = (const unsigned char*)text;
  50880. text[0] = ASN_OCTET_STRING;
  50881. ExpectNotNull(d2i_ASN1_OCTET_STRING(&str, &p, sizeof(text)));
  50882. ExpectIntEQ(i2d_ASN1_OCTET_STRING(str, &der), 13);
  50883. ASN1_STRING_free(str);
  50884. str = NULL;
  50885. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  50886. der = NULL;
  50887. }
  50888. /* UTF8STRING */
  50889. {
  50890. const unsigned char* p = (const unsigned char*)text;
  50891. text[0] = ASN_UTF8STRING;
  50892. ExpectNotNull(d2i_ASN1_UTF8STRING(&str, &p, sizeof(text)));
  50893. ExpectIntEQ(i2d_ASN1_UTF8STRING(str, &der), 13);
  50894. ASN1_STRING_free(str);
  50895. str = NULL;
  50896. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  50897. der = NULL;
  50898. }
  50899. #endif
  50900. return EXPECT_RESULT();
  50901. }
  50902. static int test_wolfSSL_lhash(void)
  50903. {
  50904. EXPECT_DECLS;
  50905. #ifdef OPENSSL_ALL
  50906. const char testStr[] = "Like a true nature's child\n"
  50907. "We were born\n"
  50908. "Born to be wild";
  50909. #ifdef NO_SHA
  50910. ExpectIntEQ(lh_strhash(testStr), 0xf9dc8a43);
  50911. #else
  50912. ExpectIntEQ(lh_strhash(testStr), 0x5b7541dc);
  50913. #endif
  50914. #endif
  50915. return EXPECT_RESULT();
  50916. }
  50917. static int test_wolfSSL_X509_NAME(void)
  50918. {
  50919. EXPECT_DECLS;
  50920. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)) && \
  50921. !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  50922. !defined(NO_RSA) && defined(WOLFSSL_CERT_GEN) && \
  50923. (defined(WOLFSSL_CERT_REQ) || defined(WOLFSSL_CERT_EXT) || \
  50924. defined(OPENSSL_EXTRA))
  50925. X509* x509 = NULL;
  50926. const unsigned char* c = NULL;
  50927. unsigned char buf[4096];
  50928. int bytes = 0;
  50929. XFILE f = XBADFILE;
  50930. const X509_NAME* a = NULL;
  50931. const X509_NAME* b = NULL;
  50932. X509_NAME* d2i_name = NULL;
  50933. int sz = 0;
  50934. unsigned char* tmp = NULL;
  50935. char file[] = "./certs/ca-cert.der";
  50936. #ifndef OPENSSL_EXTRA_X509_SMALL
  50937. byte empty[] = { /* CN=empty emailAddress= */
  50938. 0x30, 0x21, 0x31, 0x0E, 0x30, 0x0C, 0x06, 0x03,
  50939. 0x55, 0x04, 0x03, 0x0C, 0x05, 0x65, 0x6D, 0x70,
  50940. 0x74, 0x79, 0x31, 0x0F, 0x30, 0x0D, 0x06, 0x09,
  50941. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09,
  50942. 0x01, 0x16, 0x00
  50943. };
  50944. #endif
  50945. #ifndef OPENSSL_EXTRA_X509_SMALL
  50946. /* test compile of deprecated function, returns 0 */
  50947. ExpectIntEQ(CRYPTO_thread_id(), 0);
  50948. #endif
  50949. ExpectNotNull(a = X509_NAME_new());
  50950. X509_NAME_free((X509_NAME*)a);
  50951. a = NULL;
  50952. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  50953. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  50954. if (f != XBADFILE)
  50955. XFCLOSE(f);
  50956. c = buf;
  50957. ExpectNotNull(x509 = wolfSSL_X509_d2i_ex(NULL, c, bytes, HEAP_HINT));
  50958. /* test cmp function */
  50959. ExpectNotNull(a = X509_get_issuer_name(x509));
  50960. ExpectNotNull(b = X509_get_subject_name(x509));
  50961. #ifndef OPENSSL_EXTRA_X509_SMALL
  50962. ExpectIntEQ(X509_NAME_cmp(a, b), 0); /* self signed should be 0 */
  50963. #endif
  50964. tmp = buf;
  50965. ExpectIntGT((sz = i2d_X509_NAME((X509_NAME*)a, &tmp)), 0);
  50966. if (sz > 0 && tmp == buf) {
  50967. fprintf(stderr, "\nERROR - %s line %d failed with:", __FILE__,
  50968. __LINE__);
  50969. fprintf(stderr, " Expected pointer to be incremented\n");
  50970. abort();
  50971. }
  50972. #ifndef OPENSSL_EXTRA_X509_SMALL
  50973. tmp = buf;
  50974. ExpectNotNull(d2i_name = d2i_X509_NAME(NULL, &tmp, sz));
  50975. #endif
  50976. /* if output parameter is NULL, should still return required size. */
  50977. ExpectIntGT((sz = i2d_X509_NAME((X509_NAME*)b, NULL)), 0);
  50978. /* retry but with the function creating a buffer */
  50979. tmp = NULL;
  50980. ExpectIntGT((sz = i2d_X509_NAME((X509_NAME*)b, &tmp)), 0);
  50981. XFREE(tmp, NULL, DYNAMIC_TYPE_OPENSSL);
  50982. tmp = NULL;
  50983. #ifdef WOLFSSL_CERT_NAME_ALL
  50984. /* test for givenName and name */
  50985. {
  50986. WOLFSSL_X509_NAME_ENTRY* entry = NULL;
  50987. const byte gName[] = "test-given-name";
  50988. const byte name[] = "test-name";
  50989. ExpectNotNull(entry = wolfSSL_X509_NAME_ENTRY_create_by_NID(NULL,
  50990. NID_givenName, ASN_UTF8STRING, gName, sizeof(gName)));
  50991. ExpectIntEQ(wolfSSL_X509_NAME_add_entry((X509_NAME*)b, entry, -1, 0),
  50992. 1);
  50993. wolfSSL_X509_NAME_ENTRY_free(entry);
  50994. entry = NULL;
  50995. ExpectNotNull(entry = wolfSSL_X509_NAME_ENTRY_create_by_NID(NULL,
  50996. NID_name, ASN_UTF8STRING, name, sizeof(name)));
  50997. ExpectIntEQ(wolfSSL_X509_NAME_add_entry((X509_NAME*)b, entry, -1, 0),
  50998. 1);
  50999. wolfSSL_X509_NAME_ENTRY_free(entry);
  51000. tmp = NULL;
  51001. ExpectIntGT((sz = i2d_X509_NAME((X509_NAME*)b, &tmp)), 0);
  51002. XFREE(tmp, NULL, DYNAMIC_TYPE_OPENSSL);
  51003. }
  51004. #endif
  51005. b = NULL;
  51006. ExpectNotNull(b = X509_NAME_dup((X509_NAME*)a));
  51007. #ifndef OPENSSL_EXTRA_X509_SMALL
  51008. ExpectIntEQ(X509_NAME_cmp(a, b), 0);
  51009. #endif
  51010. X509_NAME_free((X509_NAME*)b);
  51011. X509_NAME_free(d2i_name);
  51012. d2i_name = NULL;
  51013. X509_free(x509);
  51014. #ifndef OPENSSL_EXTRA_X509_SMALL
  51015. /* test with an empty domain component */
  51016. tmp = empty;
  51017. sz = sizeof(empty);
  51018. ExpectNotNull(d2i_name = d2i_X509_NAME(NULL, &tmp, sz));
  51019. ExpectIntEQ(X509_NAME_entry_count(d2i_name), 2);
  51020. /* size of empty emailAddress will be 0 */
  51021. tmp = buf;
  51022. ExpectIntEQ(X509_NAME_get_text_by_NID(d2i_name, NID_emailAddress,
  51023. (char*)tmp, sizeof(buf)), 0);
  51024. /* should contain no organization name */
  51025. tmp = buf;
  51026. ExpectIntEQ(X509_NAME_get_text_by_NID(d2i_name, NID_organizationName,
  51027. (char*)tmp, sizeof(buf)), -1);
  51028. X509_NAME_free(d2i_name);
  51029. #endif
  51030. #endif
  51031. return EXPECT_RESULT();
  51032. }
  51033. static int test_wolfSSL_X509_NAME_hash(void)
  51034. {
  51035. EXPECT_DECLS;
  51036. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && \
  51037. !defined(NO_RSA) && !defined(NO_SHA) && !defined(NO_BIO)
  51038. BIO* bio = NULL;
  51039. X509* x509 = NULL;
  51040. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  51041. ExpectIntGT(BIO_read_filename(bio, svrCertFile), 0);
  51042. ExpectNotNull(PEM_read_bio_X509(bio, &x509, NULL, NULL));
  51043. ExpectIntEQ(X509_NAME_hash(X509_get_subject_name(x509)), 0x137DC03F);
  51044. ExpectIntEQ(X509_NAME_hash(X509_get_issuer_name(x509)), 0xFDB2DA4);
  51045. X509_free(x509);
  51046. BIO_free(bio);
  51047. #endif
  51048. return EXPECT_RESULT();
  51049. }
  51050. static int test_wolfSSL_X509_NAME_print_ex(void)
  51051. {
  51052. EXPECT_DECLS;
  51053. #if (defined(OPENSSL_ALL) || (defined(OPENSSL_EXTRA) && \
  51054. (defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || \
  51055. defined(HAVE_LIGHTY) || defined(WOLFSSL_HAPROXY) || \
  51056. defined(WOLFSSL_OPENSSH) || defined(HAVE_SBLIM_SFCB)))) && \
  51057. !defined(NO_BIO) && !defined(NO_RSA)
  51058. int memSz = 0;
  51059. byte* mem = NULL;
  51060. BIO* bio = NULL;
  51061. BIO* membio = NULL;
  51062. X509* x509 = NULL;
  51063. X509_NAME* name = NULL;
  51064. const char* expNormal = "C=US, CN=wolfssl.com";
  51065. const char* expEqSpace = "C = US, CN = wolfssl.com";
  51066. const char* expReverse = "CN=wolfssl.com, C=US";
  51067. const char* expNotEscaped = "C= US,+\"\\ , CN=#wolfssl.com<>;";
  51068. const char* expNotEscapedRev = "CN=#wolfssl.com<>;, C= US,+\"\\ ";
  51069. const char* expRFC5523 =
  51070. "CN=\\#wolfssl.com\\<\\>\\;, C=\\ US\\,\\+\\\"\\\\\\ ";
  51071. /* Test with real cert (svrCertFile) first */
  51072. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  51073. ExpectIntGT(BIO_read_filename(bio, svrCertFile), 0);
  51074. ExpectNotNull(PEM_read_bio_X509(bio, &x509, NULL, NULL));
  51075. ExpectNotNull(name = X509_get_subject_name(x509));
  51076. /* Test without flags */
  51077. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  51078. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0, 0), WOLFSSL_SUCCESS);
  51079. BIO_free(membio);
  51080. membio = NULL;
  51081. /* Test flag: XN_FLAG_RFC2253 */
  51082. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  51083. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  51084. XN_FLAG_RFC2253), WOLFSSL_SUCCESS);
  51085. BIO_free(membio);
  51086. membio = NULL;
  51087. /* Test flag: XN_FLAG_RFC2253 | XN_FLAG_DN_REV */
  51088. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  51089. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  51090. XN_FLAG_RFC2253 | XN_FLAG_DN_REV), WOLFSSL_SUCCESS);
  51091. BIO_free(membio);
  51092. membio = NULL;
  51093. X509_free(x509);
  51094. BIO_free(bio);
  51095. name = NULL;
  51096. /* Test normal case without escaped characters */
  51097. {
  51098. /* Create name: "/C=US/CN=wolfssl.com" */
  51099. ExpectNotNull(name = X509_NAME_new());
  51100. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName",
  51101. MBSTRING_UTF8, (byte*)"US", 2, -1, 0),
  51102. WOLFSSL_SUCCESS);
  51103. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName",
  51104. MBSTRING_UTF8, (byte*)"wolfssl.com", 11, -1, 0),
  51105. WOLFSSL_SUCCESS);
  51106. /* Test without flags */
  51107. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  51108. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0, 0), WOLFSSL_SUCCESS);
  51109. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  51110. ExpectIntEQ(memSz, XSTRLEN(expNormal));
  51111. ExpectIntEQ(XSTRNCMP((char*)mem, expNormal, XSTRLEN(expNormal)), 0);
  51112. BIO_free(membio);
  51113. membio = NULL;
  51114. /* Test with XN_FLAG_ONELINE which should enable XN_FLAG_SPC_EQ for
  51115. spaces aroun '=' */
  51116. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  51117. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0, XN_FLAG_ONELINE),
  51118. WOLFSSL_SUCCESS);
  51119. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  51120. ExpectIntEQ(memSz, XSTRLEN(expEqSpace));
  51121. ExpectIntEQ(XSTRNCMP((char*)mem, expEqSpace, XSTRLEN(expEqSpace)), 0);
  51122. BIO_free(membio);
  51123. membio = NULL;
  51124. /* Test flags: XN_FLAG_RFC2253 - should be reversed */
  51125. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  51126. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  51127. XN_FLAG_RFC2253), WOLFSSL_SUCCESS);
  51128. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  51129. ExpectIntEQ(memSz, XSTRLEN(expReverse));
  51130. BIO_free(membio);
  51131. membio = NULL;
  51132. /* Test flags: XN_FLAG_DN_REV - reversed */
  51133. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  51134. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  51135. XN_FLAG_DN_REV), WOLFSSL_SUCCESS);
  51136. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  51137. ExpectIntEQ(memSz, XSTRLEN(expReverse));
  51138. ExpectIntEQ(XSTRNCMP((char*)mem, expReverse, XSTRLEN(expReverse)), 0);
  51139. BIO_free(membio);
  51140. membio = NULL;
  51141. X509_NAME_free(name);
  51142. name = NULL;
  51143. }
  51144. /* Test RFC2253 characters are escaped with backslashes */
  51145. {
  51146. ExpectNotNull(name = X509_NAME_new());
  51147. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName",
  51148. /* space at beginning and end, and: ,+"\ */
  51149. MBSTRING_UTF8, (byte*)" US,+\"\\ ", 8, -1, 0),
  51150. WOLFSSL_SUCCESS);
  51151. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName",
  51152. /* # at beginning, and: <>;*/
  51153. MBSTRING_UTF8, (byte*)"#wolfssl.com<>;", 15, -1, 0),
  51154. WOLFSSL_SUCCESS);
  51155. /* Test without flags */
  51156. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  51157. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0, 0), WOLFSSL_SUCCESS);
  51158. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  51159. ExpectIntEQ(memSz, XSTRLEN(expNotEscaped));
  51160. ExpectIntEQ(XSTRNCMP((char*)mem, expNotEscaped,
  51161. XSTRLEN(expNotEscaped)), 0);
  51162. BIO_free(membio);
  51163. membio = NULL;
  51164. /* Test flags: XN_FLAG_RFC5523 - should be reversed and escaped */
  51165. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  51166. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  51167. XN_FLAG_RFC2253), WOLFSSL_SUCCESS);
  51168. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  51169. ExpectIntEQ(memSz, XSTRLEN(expRFC5523));
  51170. ExpectIntEQ(XSTRNCMP((char*)mem, expRFC5523, XSTRLEN(expRFC5523)), 0);
  51171. BIO_free(membio);
  51172. membio = NULL;
  51173. /* Test flags: XN_FLAG_DN_REV - reversed but not escaped */
  51174. ExpectNotNull(membio = BIO_new(BIO_s_mem()));
  51175. ExpectIntEQ(X509_NAME_print_ex(membio, name, 0,
  51176. XN_FLAG_DN_REV), WOLFSSL_SUCCESS);
  51177. ExpectIntGE((memSz = BIO_get_mem_data(membio, &mem)), 0);
  51178. ExpectIntEQ(memSz, XSTRLEN(expNotEscapedRev));
  51179. ExpectIntEQ(XSTRNCMP((char*)mem, expNotEscapedRev,
  51180. XSTRLEN(expNotEscapedRev)), 0);
  51181. BIO_free(membio);
  51182. X509_NAME_free(name);
  51183. }
  51184. #endif
  51185. return EXPECT_RESULT();
  51186. }
  51187. #ifndef NO_BIO
  51188. static int test_wolfSSL_X509_INFO_multiple_info(void)
  51189. {
  51190. EXPECT_DECLS;
  51191. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  51192. STACK_OF(X509_INFO) *info_stack = NULL;
  51193. X509_INFO *info = NULL;
  51194. int len;
  51195. int i;
  51196. const char* files[] = {
  51197. cliCertFile,
  51198. cliKeyFile,
  51199. /* This needs to be the order as svrCertFile contains the
  51200. * intermediate cert as well. */
  51201. svrKeyFile,
  51202. svrCertFile,
  51203. NULL,
  51204. };
  51205. const char** curFile;
  51206. BIO *fileBIO = NULL;
  51207. BIO *concatBIO = NULL;
  51208. byte tmp[FOURK_BUF];
  51209. /* concatenate the cert and the key file to force PEM_X509_INFO_read_bio
  51210. * to group objects together. */
  51211. ExpectNotNull(concatBIO = BIO_new(BIO_s_mem()));
  51212. for (curFile = files; EXPECT_SUCCESS() && *curFile != NULL; curFile++) {
  51213. int fileLen = 0;
  51214. ExpectNotNull(fileBIO = BIO_new_file(*curFile, "rb"));
  51215. ExpectIntGT(fileLen = wolfSSL_BIO_get_len(fileBIO), 0);
  51216. if (EXPECT_SUCCESS()) {
  51217. while ((len = BIO_read(fileBIO, tmp, sizeof(tmp))) > 0) {
  51218. ExpectIntEQ(BIO_write(concatBIO, tmp, len), len);
  51219. fileLen -= len;
  51220. if (EXPECT_FAIL())
  51221. break;
  51222. }
  51223. /* Make sure we read the entire file */
  51224. ExpectIntEQ(fileLen, 0);
  51225. }
  51226. BIO_free(fileBIO);
  51227. fileBIO = NULL;
  51228. }
  51229. ExpectNotNull(info_stack = PEM_X509_INFO_read_bio(concatBIO, NULL, NULL,
  51230. NULL));
  51231. ExpectIntEQ(sk_X509_INFO_num(info_stack), 3);
  51232. for (i = 0; i < sk_X509_INFO_num(info_stack); i++) {
  51233. ExpectNotNull(info = sk_X509_INFO_value(info_stack, i));
  51234. ExpectNotNull(info->x509);
  51235. ExpectNull(info->crl);
  51236. if (i != 0) {
  51237. ExpectNotNull(info->x_pkey);
  51238. ExpectIntEQ(X509_check_private_key(info->x509,
  51239. info->x_pkey->dec_pkey), 1);
  51240. }
  51241. else {
  51242. ExpectNull(info->x_pkey);
  51243. }
  51244. }
  51245. sk_X509_INFO_pop_free(info_stack, X509_INFO_free);
  51246. BIO_free(concatBIO);
  51247. #endif
  51248. return EXPECT_RESULT();
  51249. }
  51250. #endif
  51251. #ifndef NO_BIO
  51252. static int test_wolfSSL_X509_INFO(void)
  51253. {
  51254. EXPECT_DECLS;
  51255. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  51256. STACK_OF(X509_INFO) *info_stack = NULL;
  51257. X509_INFO *info = NULL;
  51258. BIO *cert = NULL;
  51259. int i;
  51260. /* PEM in hex format to avoid null terminator */
  51261. byte data[] = {
  51262. 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47,
  51263. 0x49, 0x4e, 0x20, 0x43, 0x45, 0x52, 0x54, 0x63, 0x2d, 0x2d, 0x2d, 0x2d,
  51264. 0x2d, 0x0a, 0x4d, 0x49, 0x49, 0x44, 0x4d, 0x54, 0x42, 0x75, 0x51, 0x3d,
  51265. 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, 0x20, 0x2d, 0x2d,
  51266. 0x2d, 0x2d, 0x2d
  51267. };
  51268. /* PEM in hex format to avoid null terminator */
  51269. byte data2[] = {
  51270. 0x41, 0x53, 0x4e, 0x31, 0x20, 0x4f, 0x49, 0x44, 0x3a, 0x20, 0x70, 0x72,
  51271. 0x69, 0x6d, 0x65, 0x32, 0x35, 0x36, 0x76, 0x31, 0x0a, 0x2d, 0x2d, 0x2d,
  51272. 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x45, 0x43, 0x20, 0x50,
  51273. 0x41, 0x52, 0x41, 0x4d, 0x45, 0x54, 0x45, 0x52, 0x53, 0x2d, 0x2d, 0x2d,
  51274. 0x2d, 0x43, 0x65, 0x72, 0x74, 0x69, 0x2d, 0x0a, 0x42, 0x67, 0x67, 0x71,
  51275. 0x68, 0x6b, 0x6a, 0x4f, 0x50, 0x51, 0x4d, 0x42, 0x42, 0x77, 0x3d, 0x3d,
  51276. 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d
  51277. };
  51278. ExpectNotNull(cert = BIO_new_file(cliCertFileExt, "rb"));
  51279. ExpectNotNull(info_stack = PEM_X509_INFO_read_bio(cert, NULL, NULL, NULL));
  51280. for (i = 0; i < sk_X509_INFO_num(info_stack); i++) {
  51281. ExpectNotNull(info = sk_X509_INFO_value(info_stack, i));
  51282. ExpectNotNull(info->x509);
  51283. ExpectNull(info->crl);
  51284. ExpectNull(info->x_pkey);
  51285. }
  51286. sk_X509_INFO_pop_free(info_stack, X509_INFO_free);
  51287. info_stack = NULL;
  51288. BIO_free(cert);
  51289. cert = NULL;
  51290. ExpectNotNull(cert = BIO_new_file(cliCertFileExt, "rb"));
  51291. ExpectNotNull(info_stack = PEM_X509_INFO_read_bio(cert, NULL, NULL, NULL));
  51292. sk_X509_INFO_pop_free(info_stack, X509_INFO_free);
  51293. info_stack = NULL;
  51294. BIO_free(cert);
  51295. cert = NULL;
  51296. /* This case should fail due to invalid input. */
  51297. ExpectNotNull(cert = BIO_new(BIO_s_mem()));
  51298. ExpectIntEQ(BIO_write(cert, data, sizeof(data)), sizeof(data));
  51299. ExpectNull(info_stack = PEM_X509_INFO_read_bio(cert, NULL, NULL, NULL));
  51300. sk_X509_INFO_pop_free(info_stack, X509_INFO_free);
  51301. info_stack = NULL;
  51302. BIO_free(cert);
  51303. cert = NULL;
  51304. ExpectNotNull(cert = BIO_new(BIO_s_mem()));
  51305. ExpectIntEQ(BIO_write(cert, data2, sizeof(data2)), sizeof(data2));
  51306. ExpectNull(info_stack = PEM_X509_INFO_read_bio(cert, NULL, NULL, NULL));
  51307. sk_X509_INFO_pop_free(info_stack, X509_INFO_free);
  51308. BIO_free(cert);
  51309. #endif
  51310. return EXPECT_RESULT();
  51311. }
  51312. #endif
  51313. static int test_wolfSSL_X509_subject_name_hash(void)
  51314. {
  51315. EXPECT_DECLS;
  51316. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  51317. !defined(NO_RSA) && (!defined(NO_SHA) || !defined(NO_SHA256))
  51318. X509* x509 = NULL;
  51319. X509_NAME* subjectName = NULL;
  51320. unsigned long ret1 = 0;
  51321. unsigned long ret2 = 0;
  51322. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  51323. SSL_FILETYPE_PEM));
  51324. ExpectNotNull(subjectName = wolfSSL_X509_get_subject_name(x509));
  51325. /* These two
  51326. * - X509_subject_name_hash(x509)
  51327. * - X509_NAME_hash(X509_get_subject_name(x509))
  51328. * should give the same hash, if !defined(NO_SHA) is true. */
  51329. ret1 = X509_subject_name_hash(x509);
  51330. ExpectIntNE(ret1, 0);
  51331. #if !defined(NO_SHA)
  51332. ret2 = X509_NAME_hash(X509_get_subject_name(x509));
  51333. ExpectIntNE(ret2, 0);
  51334. ExpectIntEQ(ret1, ret2);
  51335. #else
  51336. (void) ret2;
  51337. #endif
  51338. X509_free(x509);
  51339. #endif
  51340. return EXPECT_RESULT();
  51341. }
  51342. static int test_wolfSSL_X509_issuer_name_hash(void)
  51343. {
  51344. EXPECT_DECLS;
  51345. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) \
  51346. && !defined(NO_RSA) && (!defined(NO_SHA) || !defined(NO_SHA256))
  51347. X509* x509 = NULL;
  51348. X509_NAME* issuertName = NULL;
  51349. unsigned long ret1 = 0;
  51350. unsigned long ret2 = 0;
  51351. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  51352. SSL_FILETYPE_PEM));
  51353. ExpectNotNull(issuertName = wolfSSL_X509_get_issuer_name(x509));
  51354. /* These two
  51355. * - X509_issuer_name_hash(x509)
  51356. * - X509_NAME_hash(X509_get_issuer_name(x509))
  51357. * should give the same hash, if !defined(NO_SHA) is true. */
  51358. ret1 = X509_issuer_name_hash(x509);
  51359. ExpectIntNE(ret1, 0);
  51360. #if !defined(NO_SHA)
  51361. ret2 = X509_NAME_hash(X509_get_issuer_name(x509));
  51362. ExpectIntNE(ret2, 0);
  51363. ExpectIntEQ(ret1, ret2);
  51364. #else
  51365. (void) ret2;
  51366. #endif
  51367. X509_free(x509);
  51368. #endif
  51369. return EXPECT_RESULT();
  51370. }
  51371. static int test_wolfSSL_X509_check_host(void)
  51372. {
  51373. EXPECT_DECLS;
  51374. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) \
  51375. && !defined(NO_SHA) && !defined(NO_RSA)
  51376. X509* x509 = NULL;
  51377. const char altName[] = "example.com";
  51378. const char badAltName[] = "a.example.com";
  51379. /* cliCertFile has subjectAltName set to 'example.com', '127.0.0.1' */
  51380. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  51381. SSL_FILETYPE_PEM));
  51382. ExpectIntEQ(X509_check_host(x509, altName, XSTRLEN(altName), 0, NULL),
  51383. WOLFSSL_SUCCESS);
  51384. ExpectIntEQ(X509_check_host(x509, badAltName, XSTRLEN(badAltName), 0, NULL),
  51385. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51386. ExpectIntEQ(X509_check_host(x509, NULL, 0, 0, NULL),
  51387. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51388. /* Check WOLFSSL_LEFT_MOST_WILDCARD_ONLY flag set */
  51389. ExpectIntEQ(X509_check_host(x509, altName, XSTRLEN(altName),
  51390. WOLFSSL_LEFT_MOST_WILDCARD_ONLY, NULL), WOLFSSL_SUCCESS);
  51391. ExpectIntEQ(X509_check_host(x509, NULL, 0,
  51392. WOLFSSL_LEFT_MOST_WILDCARD_ONLY, NULL),
  51393. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51394. ExpectIntEQ(X509_check_host(x509, badAltName, XSTRLEN(badAltName),
  51395. WOLFSSL_LEFT_MOST_WILDCARD_ONLY, NULL),
  51396. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51397. X509_free(x509);
  51398. ExpectIntEQ(X509_check_host(NULL, altName, XSTRLEN(altName), 0, NULL),
  51399. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51400. /* Check again with WOLFSSL_LEFT_MOST_WILDCARD_ONLY flag set */
  51401. ExpectIntEQ(X509_check_host(NULL, altName, XSTRLEN(altName),
  51402. WOLFSSL_LEFT_MOST_WILDCARD_ONLY, NULL),
  51403. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51404. #endif
  51405. return EXPECT_RESULT();
  51406. }
  51407. static int test_wolfSSL_X509_check_email(void)
  51408. {
  51409. EXPECT_DECLS;
  51410. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_CERT_GEN) && !defined(NO_RSA)
  51411. X509* x509 = NULL;
  51412. const char goodEmail[] = "info@wolfssl.com";
  51413. const char badEmail[] = "disinfo@wolfssl.com";
  51414. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  51415. SSL_FILETYPE_PEM));
  51416. /* Should fail on non-matching email address */
  51417. ExpectIntEQ(wolfSSL_X509_check_email(x509, badEmail, XSTRLEN(badEmail), 0),
  51418. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51419. /* Should succeed on matching email address */
  51420. ExpectIntEQ(wolfSSL_X509_check_email(x509, goodEmail, XSTRLEN(goodEmail), 0),
  51421. WOLFSSL_SUCCESS);
  51422. /* Should compute length internally when not provided */
  51423. ExpectIntEQ(wolfSSL_X509_check_email(x509, goodEmail, 0, 0),
  51424. WOLFSSL_SUCCESS);
  51425. /* Should fail when email address is NULL */
  51426. ExpectIntEQ(wolfSSL_X509_check_email(x509, NULL, 0, 0),
  51427. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51428. X509_free(x509);
  51429. /* Should fail when x509 is NULL */
  51430. ExpectIntEQ(wolfSSL_X509_check_email(NULL, goodEmail, 0, 0),
  51431. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51432. #endif /* OPENSSL_EXTRA && WOLFSSL_CERT_GEN */
  51433. return EXPECT_RESULT();
  51434. }
  51435. static int test_wc_PemToDer(void)
  51436. {
  51437. EXPECT_DECLS;
  51438. #if !defined(NO_CERTS) && defined(WOLFSSL_PEM_TO_DER) && !defined(NO_FILESYSTEM)
  51439. int ret;
  51440. DerBuffer* pDer = NULL;
  51441. const char* ca_cert = "./certs/server-cert.pem";
  51442. byte* cert_buf = NULL;
  51443. size_t cert_sz = 0;
  51444. int eccKey = 0;
  51445. EncryptedInfo info;
  51446. XMEMSET(&info, 0, sizeof(info));
  51447. ExpectIntEQ(ret = load_file(ca_cert, &cert_buf, &cert_sz), 0);
  51448. ExpectIntEQ(ret = wc_PemToDer(cert_buf, (long int)cert_sz, CERT_TYPE, &pDer, NULL,
  51449. &info, &eccKey), 0);
  51450. wc_FreeDer(&pDer);
  51451. pDer = NULL;
  51452. if (cert_buf != NULL) {
  51453. free(cert_buf);
  51454. cert_buf = NULL;
  51455. }
  51456. #ifdef HAVE_ECC
  51457. {
  51458. const char* ecc_private_key = "./certs/ecc-privOnlyKey.pem";
  51459. byte key_buf[256] = {0};
  51460. /* Test fail of loading a key with cert type */
  51461. ExpectIntEQ(load_file(ecc_private_key, &cert_buf, &cert_sz), 0);
  51462. key_buf[0] = '\n';
  51463. ExpectNotNull(XMEMCPY(key_buf + 1, cert_buf, cert_sz));
  51464. ExpectIntNE((ret = wc_PemToDer(key_buf, (long int)cert_sz + 1, CERT_TYPE,
  51465. &pDer, NULL, &info, &eccKey)), 0);
  51466. #ifdef OPENSSL_EXTRA
  51467. ExpectIntEQ((ret = wc_PemToDer(key_buf, cert_sz + 1, PRIVATEKEY_TYPE,
  51468. &pDer, NULL, &info, &eccKey)), 0);
  51469. #endif
  51470. wc_FreeDer(&pDer);
  51471. if (cert_buf != NULL)
  51472. free(cert_buf);
  51473. }
  51474. #endif
  51475. #endif
  51476. return EXPECT_RESULT();
  51477. }
  51478. static int test_wc_AllocDer(void)
  51479. {
  51480. EXPECT_DECLS;
  51481. #if !defined(NO_CERTS)
  51482. DerBuffer* pDer = NULL;
  51483. word32 testSize = 1024;
  51484. ExpectIntEQ(wc_AllocDer(NULL, testSize, CERT_TYPE, HEAP_HINT),
  51485. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51486. ExpectIntEQ(wc_AllocDer(&pDer, testSize, CERT_TYPE, HEAP_HINT), 0);
  51487. ExpectNotNull(pDer);
  51488. wc_FreeDer(&pDer);
  51489. #endif
  51490. return EXPECT_RESULT();
  51491. }
  51492. static int test_wc_CertPemToDer(void)
  51493. {
  51494. EXPECT_DECLS;
  51495. #if !defined(NO_CERTS) && defined(WOLFSSL_PEM_TO_DER) && !defined(NO_FILESYSTEM)
  51496. const char* ca_cert = "./certs/ca-cert.pem";
  51497. byte* cert_buf = NULL;
  51498. size_t cert_sz = 0;
  51499. size_t cert_dersz = 0;
  51500. byte* cert_der = NULL;
  51501. ExpectIntEQ(load_file(ca_cert, &cert_buf, &cert_sz), 0);
  51502. cert_dersz = cert_sz; /* DER will be smaller than PEM */
  51503. ExpectNotNull(cert_der = (byte*)malloc(cert_dersz));
  51504. ExpectIntGE(wc_CertPemToDer(cert_buf, (int)cert_sz, cert_der,
  51505. (int)cert_dersz, CERT_TYPE), 0);
  51506. ExpectIntEQ(wc_CertPemToDer(NULL, (int)cert_sz, NULL, -1, CERT_TYPE),
  51507. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51508. ExpectIntEQ(wc_CertPemToDer(cert_buf, (int)cert_sz, NULL, -1, CERT_TYPE),
  51509. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51510. ExpectIntEQ(wc_CertPemToDer(NULL, (int)cert_sz, cert_der, -1, CERT_TYPE),
  51511. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51512. ExpectIntEQ(wc_CertPemToDer(NULL, (int)cert_sz, NULL, (int)cert_dersz,
  51513. CERT_TYPE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51514. ExpectIntEQ(wc_CertPemToDer(NULL, (int)cert_sz, cert_der,
  51515. (int)cert_dersz, CERT_TYPE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51516. ExpectIntEQ(wc_CertPemToDer(cert_buf, (int)cert_sz, NULL,
  51517. (int)cert_dersz, CERT_TYPE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51518. ExpectIntEQ(wc_CertPemToDer(cert_buf, (int)cert_sz, cert_der, -1,
  51519. CERT_TYPE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51520. if (cert_der != NULL)
  51521. free(cert_der);
  51522. if (cert_buf != NULL)
  51523. free(cert_buf);
  51524. #endif
  51525. return EXPECT_RESULT();
  51526. }
  51527. static int test_wc_KeyPemToDer(void)
  51528. {
  51529. EXPECT_DECLS;
  51530. #if defined(WOLFSSL_PEM_TO_DER) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  51531. int ret = 0;
  51532. const byte cert_buf[] = \
  51533. "-----BEGIN PRIVATE KEY-----\n"
  51534. "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDMG5KgWxP002pA\n"
  51535. "QJIdA4H5N0oM1Wf0LrHcos5RYUlrHDkC2b5p2BUpVRPmgDAFD2+8leim98x0BvcB\n"
  51536. "k48TNzrVynuwyVEY664+iQyzEBO5v27HPRydOddprbLCvRO036XINGIjauy1jHFi\n"
  51537. "HaDVx3bexSwgp9aefUGAszFXi4q1J4GacV7Cr2b/wBqUHqWv4ZXPu6R9/UYngTkD\n"
  51538. "UDJL5gLlLfcLzNyyodKPHPCIAKdWn6mSVdcHk8XVpK4y9lgz4E7YDWA6ohKZgWgG\n"
  51539. "2RDha8CMilFMDgYa0G0SiS9g3PQx0qh3AMXJJsKSVhScFCZufAE0kV6KvjP7jAqP\n"
  51540. "XBiSkRGPAgMBAAECggEAW7hmRyY2jRX2UMJThrM9VIs6fRLnYI0dQ0tsEJj536ay\n"
  51541. "nevQjArc05KWW0Yujg+WRDZPcry3RUqd9Djlmhp/F3Si6dpF1b+PMS3wJYVrf9Sd\n"
  51542. "SO5W7faArU4vnyBNe0HnY1Ta5xSVI65lg1RSIs88RTZwsooJwXYDGf0shq0/21CE\n"
  51543. "V8HOb27DDYNcEnm35lzaONjFnMqQQT2Vs9anRrPiSEXNleEvTgLVXZtGTyCGTz6v\n"
  51544. "x86Y8eSWL9YNHvPE1I+mDPuocfSR7eRNgRu7SK3mn94W5mqd7Ns072YKX/2XN1mO\n"
  51545. "66+ZFHO6v4dK1u7cSjuwrU1EhLHpUsgDz6Bna5InyQKBgQDv5l8RPy8UneKSADaf\n"
  51546. "M5L/5675I/5t4nqVjvbnQje00YveLTAEjlJBNR93Biln3sYgnvNamYDCxyEuUZ/I\n"
  51547. "S/vmBL9PoxfGZow4FcsIBOEbIn3E0SYJgCBNWthquUvGpKsYDnThJuhO+1cVmxAJ\n"
  51548. "BUOjLFnJYHM0a+Vmk9GexT2OBwKBgQDZzkUBOK7Im3eiYytFocUJyhqMH30d49X9\n"
  51549. "ujC7kGw4UWAqVe7YCSvlBa8nzWpRWK2kRpu3M0272RU0V4geyWqT+nr/SvRRPtNP\n"
  51550. "F5dY8l3yR7hjtSejqqjOfBcZT6ETJxI4tiG0+Nl5BlfM5M+0nxnkWpRcHuOR3j79\n"
  51551. "YUFERyN+OQKBgQCjlOKeUAc6d65W/+4/AFvsQ378Q57qLtSHxsR1TKHPmlNVXFqx\n"
  51552. "wJo1/JNIBduWCEHxXHF0BdfW+RGXE/FwEt/hKLuLAhrkHmjelX2sKieU6R/5ZOQa\n"
  51553. "9lMQbDHGFDOncAF6leD85hriQGBRSzrT69MDIOrYdfwYcroqCAGX0cb3YQKBgQC8\n"
  51554. "iIFQylj5SyHmjcMSNjKSA8CxFDzAV8yPIdE3Oo+CvGXqn5HsrRuy1hXE9VmXapR8\n"
  51555. "A6ackSszdHiXY0FvrNe1mfdH7wDHJwPQjdIzazCJHS3uGQxj7sDKY7226ie6pXJv\n"
  51556. "ZrCMr2/IBAaSVGm6ppHKCeIsT4ybYm7R85KEYLPHeQKBgBeJOMBinXQfWN/1jT9b\n"
  51557. "6Ywrutvp2zP8hVxQGSZJ0WG4iewZyFLsPUlbWRXOSYNPElHmdD0ZomdLVm+lSpAA\n"
  51558. "XSH5FJ/IFCwqq7Eft6Gf8NFRV+NjPMUny+PnjHe4oFP8YK/Ek22K3ttNG8Hw69Aw\n"
  51559. "AQue5o6oVfhgLiJzMdo/77gw\n"
  51560. "-----END PRIVATE KEY-----\n";
  51561. const int cert_sz = sizeof(cert_buf);
  51562. const char cert_pw[] = "password";
  51563. int cert_dersz = 0;
  51564. byte* cert_der = NULL;
  51565. /* Bad arg: Cert buffer is NULL */
  51566. ExpectIntEQ(wc_KeyPemToDer(NULL, cert_sz, cert_der, cert_dersz, ""),
  51567. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51568. /* Bad arg: Cert DER buffer non-NULL but size zero (or less) */
  51569. ExpectIntEQ(wc_KeyPemToDer(cert_buf, cert_sz, (byte*)&cert_der, 0, ""),
  51570. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51571. /* Test normal operation */
  51572. cert_dersz = cert_sz; /* DER will be smaller than PEM */
  51573. ExpectNotNull(cert_der = (byte*)malloc((size_t)cert_dersz));
  51574. ExpectIntGE(ret = wc_KeyPemToDer(cert_buf, cert_sz, cert_der, cert_dersz,
  51575. cert_pw), 0);
  51576. ExpectIntLE(ret, cert_sz);
  51577. if (cert_der != NULL) {
  51578. free(cert_der);
  51579. cert_der = NULL;
  51580. }
  51581. /* Test NULL for DER buffer to return needed DER buffer size */
  51582. ExpectIntGT(ret = wc_KeyPemToDer(cert_buf, cert_sz, NULL, 0, ""), 0);
  51583. ExpectIntLE(ret, cert_sz);
  51584. if (EXPECT_SUCCESS())
  51585. cert_dersz = ret;
  51586. ExpectNotNull(cert_der = (byte*)malloc((size_t)cert_dersz));
  51587. ExpectIntGE(ret = wc_KeyPemToDer(cert_buf, cert_sz, cert_der, cert_dersz,
  51588. cert_pw), 0);
  51589. ExpectIntLE(ret, cert_sz);
  51590. if (cert_der != NULL)
  51591. free(cert_der);
  51592. #endif
  51593. return EXPECT_RESULT();
  51594. }
  51595. static int test_wc_PubKeyPemToDer(void)
  51596. {
  51597. EXPECT_DECLS;
  51598. #if defined(WOLFSSL_PEM_TO_DER) && !defined(NO_FILESYSTEM) && \
  51599. (defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_PUB_PEM_TO_DER))
  51600. int ret = 0;
  51601. const char* key = "./certs/ecc-client-keyPub.pem";
  51602. byte* cert_buf = NULL;
  51603. size_t cert_sz = 0, cert_dersz = 0;
  51604. byte* cert_der = NULL;
  51605. ExpectIntEQ(wc_PubKeyPemToDer(cert_buf, (int)cert_sz,
  51606. cert_der, (int)cert_dersz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51607. ExpectIntEQ(load_file(key, &cert_buf, &cert_sz), 0);
  51608. cert_dersz = cert_sz; /* DER will be smaller than PEM */
  51609. ExpectNotNull(cert_der = (byte*)malloc(cert_dersz));
  51610. ExpectIntGE(wc_PubKeyPemToDer(cert_buf, (int)cert_sz, cert_der,
  51611. (int)cert_dersz), 0);
  51612. if (cert_der != NULL) {
  51613. free(cert_der);
  51614. cert_der = NULL;
  51615. }
  51616. /* Test NULL for DER buffer to return needed DER buffer size */
  51617. ExpectIntGT(ret = wc_PubKeyPemToDer(cert_buf, (int)cert_sz, NULL, 0), 0);
  51618. ExpectIntLE(ret, cert_sz);
  51619. cert_dersz = (size_t)ret;
  51620. ExpectNotNull(cert_der = (byte*)malloc(cert_dersz));
  51621. ExpectIntGE(wc_PubKeyPemToDer(cert_buf, (int)cert_sz, cert_der,
  51622. (int)cert_dersz), 0);
  51623. if (cert_der != NULL) {
  51624. free(cert_der);
  51625. }
  51626. if (cert_buf != NULL) {
  51627. free(cert_buf);
  51628. }
  51629. #endif
  51630. return EXPECT_RESULT();
  51631. }
  51632. static int test_wc_PemPubKeyToDer(void)
  51633. {
  51634. EXPECT_DECLS;
  51635. #if !defined(NO_FILESYSTEM) && \
  51636. (defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_PUB_PEM_TO_DER))
  51637. const char* key = "./certs/ecc-client-keyPub.pem";
  51638. size_t cert_dersz = 1024;
  51639. byte* cert_der = NULL;
  51640. ExpectIntGE(wc_PemPubKeyToDer(NULL, cert_der, (int)cert_dersz),
  51641. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51642. ExpectNotNull(cert_der = (byte*)malloc(cert_dersz));
  51643. ExpectIntGE(wc_PemPubKeyToDer(key, cert_der, (int)cert_dersz), 0);
  51644. if (cert_der != NULL) {
  51645. free(cert_der);
  51646. }
  51647. #endif
  51648. return EXPECT_RESULT();
  51649. }
  51650. static int test_wc_GetPubKeyDerFromCert(void)
  51651. {
  51652. EXPECT_DECLS;
  51653. #if !defined(NO_RSA) || defined(HAVE_ECC)
  51654. int ret;
  51655. word32 idx = 0;
  51656. byte keyDer[TWOK_BUF]; /* large enough for up to RSA 2048 */
  51657. word32 keyDerSz = (word32)sizeof(keyDer);
  51658. DecodedCert decoded;
  51659. #if !defined(NO_RSA) && defined(WOLFSSL_CERT_REQ) && !defined(NO_FILESYSTEM)
  51660. byte certBuf[6000]; /* for PEM and CSR, client-cert.pem is 5-6kB */
  51661. word32 certBufSz = sizeof(certBuf);
  51662. #endif
  51663. #if ((!defined(USE_CERT_BUFFERS_2048) && !defined(USE_CERT_BUFFERS_1024)) || \
  51664. defined(WOLFSSL_CERT_REQ)) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  51665. XFILE fp = XBADFILE;
  51666. #endif
  51667. #ifndef NO_RSA
  51668. RsaKey rsaKey;
  51669. #if defined(USE_CERT_BUFFERS_2048)
  51670. byte* rsaCertDer = (byte*)client_cert_der_2048;
  51671. word32 rsaCertDerSz = sizeof_client_cert_der_2048;
  51672. #elif defined(USE_CERT_BUFFERS_1024)
  51673. byte* rsaCertDer = (byte*)client_cert_der_1024;
  51674. word32 rsaCertDerSz = sizeof_client_cert_der_1024;
  51675. #else
  51676. unsigned char rsaCertDer[TWOK_BUF];
  51677. word32 rsaCertDerSz;
  51678. #endif
  51679. #endif
  51680. #ifdef HAVE_ECC
  51681. ecc_key eccKey;
  51682. #if defined(USE_CERT_BUFFERS_256)
  51683. byte* eccCert = (byte*)cliecc_cert_der_256;
  51684. word32 eccCertSz = sizeof_cliecc_cert_der_256;
  51685. #else
  51686. unsigned char eccCert[ONEK_BUF];
  51687. word32 eccCertSz;
  51688. XFILE fp2 = XBADFILE;
  51689. #endif
  51690. #endif
  51691. #ifndef NO_RSA
  51692. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  51693. ExpectTrue((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) != XBADFILE);
  51694. ExpectIntGT(rsaCertDerSz = (word32)XFREAD(rsaCertDer, 1, sizeof(rsaCertDer),
  51695. fp), 0);
  51696. if (fp != XBADFILE) {
  51697. XFCLOSE(fp);
  51698. fp = XBADFILE;
  51699. }
  51700. #endif
  51701. /* good test case - RSA DER cert */
  51702. wc_InitDecodedCert(&decoded, rsaCertDer, rsaCertDerSz, NULL);
  51703. ExpectIntEQ(wc_ParseCert(&decoded, CERT_TYPE, NO_VERIFY, NULL), 0);
  51704. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, keyDer, &keyDerSz), 0);
  51705. ExpectIntGT(keyDerSz, 0);
  51706. /* sanity check, verify we can import DER public key */
  51707. ret = wc_InitRsaKey(&rsaKey, HEAP_HINT);
  51708. ExpectIntEQ(ret, 0);
  51709. ExpectIntEQ(wc_RsaPublicKeyDecode(keyDer, &idx, &rsaKey, keyDerSz), 0);
  51710. if (ret == 0) {
  51711. wc_FreeRsaKey(&rsaKey);
  51712. }
  51713. /* test LENGTH_ONLY_E case */
  51714. keyDerSz = 0;
  51715. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, NULL, &keyDerSz),
  51716. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  51717. ExpectIntGT(keyDerSz, 0);
  51718. /* bad args: DecodedCert NULL */
  51719. ExpectIntEQ(wc_GetPubKeyDerFromCert(NULL, keyDer, &keyDerSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51720. /* bad args: output key buff size */
  51721. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, keyDer, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51722. /* bad args: zero size output key buffer */
  51723. keyDerSz = 0;
  51724. ExpectIntEQ(ret = wc_GetPubKeyDerFromCert(&decoded, keyDer, &keyDerSz),
  51725. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51726. wc_FreeDecodedCert(&decoded);
  51727. /* Certificate Request Tests */
  51728. #if defined(WOLFSSL_CERT_REQ) && !defined(NO_FILESYSTEM)
  51729. {
  51730. XMEMSET(certBuf, 0, sizeof(certBuf));
  51731. ExpectTrue((fp = XFOPEN("./certs/csr.signed.der", "rb")) != XBADFILE);
  51732. ExpectIntGT(certBufSz = (word32)XFREAD(certBuf, 1, certBufSz, fp), 0);
  51733. if (fp != XBADFILE) {
  51734. XFCLOSE(fp);
  51735. }
  51736. wc_InitDecodedCert(&decoded, certBuf, certBufSz, NULL);
  51737. ExpectIntEQ(wc_ParseCert(&decoded, CERTREQ_TYPE, VERIFY, NULL), 0);
  51738. /* good test case - RSA DER certificate request */
  51739. keyDerSz = sizeof(keyDer);
  51740. ExpectIntEQ(ret = wc_GetPubKeyDerFromCert(&decoded, keyDer, &keyDerSz),
  51741. 0);
  51742. ExpectIntGT(keyDerSz, 0);
  51743. /* sanity check, verify we can import DER public key */
  51744. ret = wc_InitRsaKey(&rsaKey, HEAP_HINT);
  51745. ExpectIntEQ(ret, 0);
  51746. idx = 0;
  51747. ExpectIntEQ(wc_RsaPublicKeyDecode(keyDer, &idx, &rsaKey, keyDerSz), 0);
  51748. if (ret == 0) {
  51749. wc_FreeRsaKey(&rsaKey);
  51750. }
  51751. wc_FreeDecodedCert(&decoded);
  51752. }
  51753. #endif /* WOLFSSL_CERT_REQ */
  51754. #endif /* NO_RSA */
  51755. #ifdef HAVE_ECC
  51756. #ifndef USE_CERT_BUFFERS_256
  51757. ExpectTrue((fp2 = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  51758. XBADFILE);
  51759. ExpectIntGT(eccCertSz = (word32)XFREAD(eccCert, 1, ONEK_BUF, fp2), 0);
  51760. if (fp2 != XBADFILE) {
  51761. XFCLOSE(fp2);
  51762. }
  51763. #endif
  51764. wc_InitDecodedCert(&decoded, eccCert, eccCertSz, NULL);
  51765. ExpectIntEQ(wc_ParseCert(&decoded, CERT_TYPE, NO_VERIFY, NULL), 0);
  51766. /* good test case - ECC */
  51767. XMEMSET(keyDer, 0, sizeof(keyDer));
  51768. keyDerSz = sizeof(keyDer);
  51769. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, keyDer, &keyDerSz), 0);
  51770. ExpectIntGT(keyDerSz, 0);
  51771. /* sanity check, verify we can import DER public key */
  51772. ret = wc_ecc_init(&eccKey);
  51773. ExpectIntEQ(ret, 0);
  51774. idx = 0; /* reset idx to 0, used above in RSA case */
  51775. ExpectIntEQ(wc_EccPublicKeyDecode(keyDer, &idx, &eccKey, keyDerSz), 0);
  51776. if (ret == 0) {
  51777. wc_ecc_free(&eccKey);
  51778. }
  51779. /* test LENGTH_ONLY_E case */
  51780. keyDerSz = 0;
  51781. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, NULL, &keyDerSz),
  51782. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  51783. ExpectIntGT(keyDerSz, 0);
  51784. wc_FreeDecodedCert(&decoded);
  51785. #endif
  51786. #endif /* !NO_RSA || HAVE_ECC */
  51787. return EXPECT_RESULT();
  51788. }
  51789. static int test_wc_CheckCertSigPubKey(void)
  51790. {
  51791. EXPECT_DECLS;
  51792. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  51793. !defined(NO_RSA) && defined(WOLFSSL_PEM_TO_DER) && defined(HAVE_ECC)
  51794. int ret = 0;
  51795. const char* ca_cert = "./certs/ca-cert.pem";
  51796. byte* cert_buf = NULL;
  51797. size_t cert_sz = 0;
  51798. byte* cert_der = NULL;
  51799. word32 cert_dersz = 0;
  51800. byte keyDer[TWOK_BUF]; /* large enough for up to RSA 2048 */
  51801. word32 keyDerSz = (word32)sizeof(keyDer);
  51802. DecodedCert decoded;
  51803. ExpectIntEQ(load_file(ca_cert, &cert_buf, &cert_sz), 0);
  51804. cert_dersz = (word32)cert_sz; /* DER will be smaller than PEM */
  51805. ExpectNotNull(cert_der = (byte*)malloc(cert_dersz));
  51806. ExpectIntGE(ret = wc_CertPemToDer(cert_buf, (int)cert_sz, cert_der,
  51807. (int)cert_dersz, CERT_TYPE), 0);
  51808. wc_InitDecodedCert(&decoded, cert_der, cert_dersz, NULL);
  51809. ExpectIntEQ(wc_ParseCert(&decoded, CERT_TYPE, NO_VERIFY, NULL), 0);
  51810. ExpectIntEQ(wc_GetPubKeyDerFromCert(&decoded, keyDer, &keyDerSz), 0);
  51811. ExpectIntGT(keyDerSz, 0);
  51812. /* Good test case. */
  51813. ExpectIntEQ(wc_CheckCertSigPubKey(cert_der, cert_dersz, NULL, keyDer,
  51814. keyDerSz, RSAk), 0);
  51815. /* No certificate. */
  51816. ExpectIntEQ(wc_CheckCertSigPubKey(NULL, cert_dersz, NULL, keyDer, keyDerSz,
  51817. ECDSAk), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51818. /* Bad cert size. */
  51819. ExpectIntNE(ret = wc_CheckCertSigPubKey(cert_der, 0, NULL, keyDer, keyDerSz,
  51820. RSAk), 0);
  51821. ExpectTrue(ret == WC_NO_ERR_TRACE(ASN_PARSE_E) || ret == WC_NO_ERR_TRACE(BUFFER_E));
  51822. /* No public key. */
  51823. ExpectIntEQ(wc_CheckCertSigPubKey(cert_der, cert_dersz, NULL, NULL,
  51824. keyDerSz, RSAk), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  51825. /* Bad public key size. */
  51826. ExpectIntEQ(wc_CheckCertSigPubKey(cert_der, cert_dersz, NULL, keyDer, 0,
  51827. RSAk), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51828. /* Wrong aglo. */
  51829. ExpectIntEQ(wc_CheckCertSigPubKey(cert_der, cert_dersz, NULL, keyDer,
  51830. keyDerSz, ECDSAk), WC_NO_ERR_TRACE(ASN_PARSE_E));
  51831. wc_FreeDecodedCert(&decoded);
  51832. if (cert_der != NULL)
  51833. free(cert_der);
  51834. if (cert_buf != NULL)
  51835. free(cert_buf);
  51836. #endif
  51837. return EXPECT_RESULT();
  51838. }
  51839. static int test_wolfSSL_certs(void)
  51840. {
  51841. EXPECT_DECLS;
  51842. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  51843. !defined(NO_RSA)
  51844. X509* x509ext = NULL;
  51845. X509* x509 = NULL;
  51846. #ifdef OPENSSL_ALL
  51847. WOLFSSL_X509_EXTENSION* ext = NULL;
  51848. ASN1_OBJECT* obj = NULL;
  51849. #endif
  51850. WOLFSSL* ssl = NULL;
  51851. WOLFSSL_CTX* ctx = NULL;
  51852. STACK_OF(ASN1_OBJECT)* sk = NULL;
  51853. ASN1_STRING* asn1_str = NULL;
  51854. AUTHORITY_KEYID* akey = NULL;
  51855. BASIC_CONSTRAINTS* bc = NULL;
  51856. int crit = 0;
  51857. #ifndef NO_WOLFSSL_SERVER
  51858. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_server_method()));
  51859. #else
  51860. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_client_method()));
  51861. #endif
  51862. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile, SSL_FILETYPE_PEM));
  51863. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  51864. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, SSL_FILETYPE_PEM));
  51865. #if !defined(NO_CHECK_PRIVATE_KEY)
  51866. ExpectIntEQ(SSL_CTX_check_private_key(ctx), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51867. #endif
  51868. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  51869. #if !defined(NO_CHECK_PRIVATE_KEY)
  51870. ExpectIntEQ(SSL_CTX_check_private_key(ctx), SSL_SUCCESS);
  51871. #endif
  51872. ExpectNotNull(ssl = SSL_new(ctx));
  51873. /* Invalid parameters. */
  51874. ExpectIntEQ(SSL_use_certificate_file(NULL, NULL, WOLFSSL_FILETYPE_PEM),
  51875. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51876. ExpectIntEQ(SSL_use_certificate_file(ssl, NULL, WOLFSSL_FILETYPE_PEM),
  51877. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51878. ExpectIntEQ(SSL_use_certificate_file(NULL, "./certs/server-cert.pem",
  51879. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  51880. #if !defined(NO_CHECK_PRIVATE_KEY)
  51881. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  51882. #endif
  51883. #ifdef HAVE_PK_CALLBACKS
  51884. ExpectIntEQ((int)SSL_set_tlsext_debug_arg(ssl, NULL), WOLFSSL_SUCCESS);
  51885. #endif /* HAVE_PK_CALLBACKS */
  51886. /* Invalid parameters. */
  51887. ExpectNotNull(x509 = wolfSSL_X509_new());
  51888. ExpectIntEQ(SSL_use_certificate(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51889. ExpectIntEQ(SSL_use_certificate(ssl, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51890. ExpectIntEQ(SSL_use_certificate(NULL, x509), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51891. /* No data in certificate. */
  51892. ExpectIntEQ(SSL_use_certificate(ssl, x509), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51893. wolfSSL_X509_free(x509);
  51894. x509 = NULL;
  51895. /* create and use x509 */
  51896. #ifdef OPENSSL_ALL
  51897. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  51898. WOLFSSL_FILETYPE_PEM));
  51899. #endif
  51900. ExpectNotNull(x509ext = wolfSSL_X509_load_certificate_file(cliCertFileExt,
  51901. WOLFSSL_FILETYPE_PEM));
  51902. ExpectIntEQ(SSL_use_certificate(ssl, x509ext), WOLFSSL_SUCCESS);
  51903. #if !defined(NO_CHECK_PRIVATE_KEY)
  51904. /* with loading in a new cert the check on private key should now fail */
  51905. ExpectIntNE(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  51906. #endif
  51907. #if defined(USE_CERT_BUFFERS_2048)
  51908. /* Invalid parameters. */
  51909. ExpectIntEQ(SSL_use_certificate_ASN1(NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51910. ExpectIntEQ(SSL_use_certificate_ASN1(ssl, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51911. ExpectIntEQ(SSL_use_certificate_ASN1(NULL,
  51912. (unsigned char*)server_cert_der_2048, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51913. /* No data. */
  51914. ExpectIntEQ(SSL_use_certificate_ASN1(ssl,
  51915. (unsigned char*)server_cert_der_2048, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51916. ExpectIntEQ(SSL_use_certificate_ASN1(ssl,
  51917. (unsigned char*)server_cert_der_2048,
  51918. sizeof_server_cert_der_2048), WOLFSSL_SUCCESS);
  51919. #endif
  51920. #if !defined(NO_SHA) && !defined(NO_SHA256) && !defined(NO_PWDBASED)
  51921. /************* Get Digest of Certificate ******************/
  51922. {
  51923. byte digest[64]; /* max digest size */
  51924. word32 digestSz;
  51925. XMEMSET(digest, 0, sizeof(digest));
  51926. ExpectIntEQ(X509_digest(x509ext, wolfSSL_EVP_sha1(), digest, &digestSz),
  51927. WOLFSSL_SUCCESS);
  51928. ExpectIntEQ(X509_digest(x509ext, wolfSSL_EVP_sha256(), digest, &digestSz),
  51929. WOLFSSL_SUCCESS);
  51930. ExpectIntEQ(X509_digest(NULL, wolfSSL_EVP_sha1(), digest, &digestSz),
  51931. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51932. }
  51933. #endif /* !NO_SHA && !NO_SHA256 && !NO_PWDBASED */
  51934. /* test and checkout X509 extensions */
  51935. ExpectNotNull(bc = (BASIC_CONSTRAINTS*)X509_get_ext_d2i(x509ext,
  51936. NID_basic_constraints, &crit, NULL));
  51937. ExpectIntEQ(crit, 0);
  51938. #ifdef OPENSSL_ALL
  51939. ExpectNotNull(ext = X509V3_EXT_i2d(NID_basic_constraints, crit, bc));
  51940. X509_EXTENSION_free(ext);
  51941. ext = NULL;
  51942. ExpectNotNull(ext = X509_EXTENSION_new());
  51943. X509_EXTENSION_set_critical(ext, 1);
  51944. ExpectNotNull(obj = OBJ_nid2obj(NID_basic_constraints));
  51945. ExpectIntEQ(X509_EXTENSION_set_object(ext, obj), SSL_SUCCESS);
  51946. ASN1_OBJECT_free(obj);
  51947. obj = NULL;
  51948. X509_EXTENSION_free(ext);
  51949. ext = NULL;
  51950. ExpectNotNull(ext = X509_EXTENSION_new());
  51951. X509_EXTENSION_set_critical(ext, 0);
  51952. ExpectIntEQ(X509_EXTENSION_set_data(ext, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  51953. asn1_str = (ASN1_STRING*)X509_get_ext_d2i(x509ext, NID_key_usage, &crit,
  51954. NULL);
  51955. ExpectIntEQ(X509_EXTENSION_set_data(ext, asn1_str), SSL_SUCCESS);
  51956. ASN1_STRING_free(asn1_str); /* X509_EXTENSION_set_data has made a copy
  51957. * and X509_get_ext_d2i has created new */
  51958. asn1_str = NULL;
  51959. X509_EXTENSION_free(ext);
  51960. ext = NULL;
  51961. #endif
  51962. BASIC_CONSTRAINTS_free(bc);
  51963. bc = NULL;
  51964. ExpectNotNull(asn1_str = (ASN1_STRING*)X509_get_ext_d2i(x509ext,
  51965. NID_key_usage, &crit, NULL));
  51966. ExpectIntEQ(crit, 1);
  51967. ExpectIntEQ(asn1_str->type, NID_key_usage);
  51968. #ifdef OPENSSL_ALL
  51969. ExpectNotNull(ext = X509V3_EXT_i2d(NID_key_usage, crit, asn1_str));
  51970. X509_EXTENSION_free(ext);
  51971. ext = NULL;
  51972. #endif
  51973. ASN1_STRING_free(asn1_str);
  51974. asn1_str = NULL;
  51975. #ifdef OPENSSL_ALL
  51976. ExpectNotNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509,
  51977. NID_ext_key_usage, &crit, NULL));
  51978. ExpectNotNull(ext = X509V3_EXT_i2d(NID_ext_key_usage, crit, sk));
  51979. X509_EXTENSION_free(ext);
  51980. ext = NULL;
  51981. EXTENDED_KEY_USAGE_free(sk);
  51982. sk = NULL;
  51983. #else
  51984. sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext, NID_ext_key_usage,
  51985. &crit, NULL);
  51986. ExpectNull(sk);
  51987. #endif
  51988. ExpectNotNull(akey = (AUTHORITY_KEYID*)X509_get_ext_d2i(x509ext,
  51989. NID_authority_key_identifier, &crit, NULL));
  51990. #ifdef OPENSSL_ALL
  51991. ExpectNotNull(ext = X509V3_EXT_i2d(NID_authority_key_identifier, crit,
  51992. akey));
  51993. X509_EXTENSION_free(ext);
  51994. ext = NULL;
  51995. #endif
  51996. wolfSSL_AUTHORITY_KEYID_free(akey);
  51997. akey = NULL;
  51998. /* NID not yet supported */
  51999. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  52000. NID_private_key_usage_period, &crit, NULL));
  52001. ExpectIntEQ(crit, -1);
  52002. sk_ASN1_OBJECT_free(sk);
  52003. sk = NULL;
  52004. ExpectNotNull(sk = (STACK_OF(GENERAL_NAME)*)X509_get_ext_d2i(x509ext,
  52005. NID_subject_alt_name, &crit, NULL));
  52006. {
  52007. int i;
  52008. for (i = 0; i < sk_GENERAL_NAME_num(sk); i++) {
  52009. GENERAL_NAME* gen = sk_GENERAL_NAME_value(sk, i);
  52010. ExpectIntEQ(gen->type, GEN_DNS);
  52011. ExpectIntEQ(gen->d.dNSName->type, V_ASN1_IA5STRING);
  52012. }
  52013. }
  52014. sk_GENERAL_NAME_free(sk);
  52015. sk = NULL;
  52016. /* NID not yet supported */
  52017. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  52018. NID_issuer_alt_name, &crit, NULL));
  52019. ExpectIntEQ(crit, -1);
  52020. sk_ASN1_OBJECT_free(sk);
  52021. sk = NULL;
  52022. /* NID not yet supported */
  52023. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  52024. NID_info_access, &crit, NULL));
  52025. sk_ASN1_OBJECT_free(sk);
  52026. sk = NULL;
  52027. /* NID not yet supported */
  52028. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  52029. NID_sinfo_access, &crit, NULL));
  52030. ExpectIntEQ(crit, -1);
  52031. sk_ASN1_OBJECT_free(sk);
  52032. sk = NULL;
  52033. /* NID not yet supported */
  52034. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  52035. NID_name_constraints, &crit, NULL));
  52036. ExpectIntEQ(crit, -1);
  52037. sk_ASN1_OBJECT_free(sk);
  52038. sk = NULL;
  52039. /* no cert policy set */
  52040. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  52041. NID_certificate_policies, &crit, NULL));
  52042. sk_ASN1_OBJECT_free(sk);
  52043. sk = NULL;
  52044. /* NID not yet supported */
  52045. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  52046. NID_policy_mappings, &crit, NULL));
  52047. ExpectIntEQ(crit, -1);
  52048. sk_ASN1_OBJECT_free(sk);
  52049. sk = NULL;
  52050. /* NID not yet supported */
  52051. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  52052. NID_policy_constraints, &crit, NULL));
  52053. ExpectIntEQ(crit, -1);
  52054. sk_ASN1_OBJECT_free(sk);
  52055. sk = NULL;
  52056. /* NID not yet supported */
  52057. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  52058. NID_inhibit_any_policy, &crit, NULL));
  52059. ExpectIntEQ(crit, -1);
  52060. sk_ASN1_OBJECT_free(sk);
  52061. sk = NULL;
  52062. /* NID not yet supported */
  52063. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext,
  52064. NID_tlsfeature, &crit, NULL));
  52065. ExpectIntEQ(crit, -1);
  52066. sk_ASN1_OBJECT_free(sk);
  52067. sk = NULL;
  52068. /* test invalid cases */
  52069. crit = 0;
  52070. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509ext, -1, &crit,
  52071. NULL));
  52072. ExpectIntEQ(crit, -1);
  52073. /* NULL passed for criticality. */
  52074. ExpectNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(NULL,
  52075. NID_tlsfeature, NULL, NULL));
  52076. ExpectIntEQ(SSL_get_hit(ssl), 0);
  52077. #ifdef OPENSSL_ALL
  52078. X509_free(x509);
  52079. #endif
  52080. X509_free(x509ext);
  52081. SSL_free(ssl);
  52082. SSL_CTX_free(ctx);
  52083. #endif /* OPENSSL_EXTRA && !NO_CERTS */
  52084. return EXPECT_RESULT();
  52085. }
  52086. static int test_wolfSSL_X509_check_private_key(void)
  52087. {
  52088. EXPECT_DECLS;
  52089. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  52090. defined(USE_CERT_BUFFERS_2048) && !defined(NO_CHECK_PRIVATE_KEY)
  52091. X509* x509 = NULL;
  52092. EVP_PKEY* pkey = NULL;
  52093. const byte* key;
  52094. /* Check with correct key */
  52095. ExpectNotNull((x509 = X509_load_certificate_file(cliCertFile,
  52096. SSL_FILETYPE_PEM)));
  52097. key = client_key_der_2048;
  52098. ExpectNotNull(d2i_PrivateKey(EVP_PKEY_RSA, &pkey, &key,
  52099. (long)sizeof_client_key_der_2048));
  52100. ExpectIntEQ(X509_check_private_key(x509, pkey), 1);
  52101. EVP_PKEY_free(pkey);
  52102. pkey = NULL;
  52103. /* Check with wrong key */
  52104. key = server_key_der_2048;
  52105. ExpectNotNull(d2i_PrivateKey(EVP_PKEY_RSA, &pkey, &key,
  52106. (long)sizeof_server_key_der_2048));
  52107. ExpectIntEQ(X509_check_private_key(x509, pkey), 0);
  52108. /* test for incorrect parameter */
  52109. ExpectIntEQ(X509_check_private_key(NULL, pkey), 0);
  52110. ExpectIntEQ(X509_check_private_key(x509, NULL), 0);
  52111. ExpectIntEQ(X509_check_private_key(NULL, NULL), 0);
  52112. EVP_PKEY_free(pkey);
  52113. X509_free(x509);
  52114. #endif
  52115. return EXPECT_RESULT();
  52116. }
  52117. static int test_wolfSSL_private_keys(void)
  52118. {
  52119. EXPECT_DECLS;
  52120. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  52121. !defined(NO_FILESYSTEM)
  52122. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  52123. WOLFSSL* ssl = NULL;
  52124. WOLFSSL_CTX* ctx = NULL;
  52125. EVP_PKEY* pkey = NULL;
  52126. OpenSSL_add_all_digests();
  52127. OpenSSL_add_all_algorithms();
  52128. #ifndef NO_RSA
  52129. #ifndef NO_WOLFSSL_SERVER
  52130. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  52131. #else
  52132. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  52133. #endif
  52134. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  52135. WOLFSSL_FILETYPE_PEM));
  52136. /* Have to load a cert before you can check the private key against that
  52137. * certificates public key! */
  52138. #if !defined(NO_CHECK_PRIVATE_KEY)
  52139. ExpectIntEQ(wolfSSL_CTX_check_private_key(ctx), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52140. #endif
  52141. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  52142. WOLFSSL_FILETYPE_PEM));
  52143. #if !defined(NO_CHECK_PRIVATE_KEY)
  52144. ExpectIntEQ(wolfSSL_CTX_check_private_key(ctx), WOLFSSL_SUCCESS);
  52145. #endif
  52146. ExpectNotNull(ssl = SSL_new(ctx));
  52147. #if !defined(NO_CHECK_PRIVATE_KEY)
  52148. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  52149. #endif
  52150. /* Invalid parameters. */
  52151. ExpectIntEQ(SSL_use_PrivateKey_file(NULL, NULL, WOLFSSL_FILETYPE_PEM),
  52152. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52153. ExpectIntEQ(SSL_use_PrivateKey_file(NULL, svrKeyFile, WOLFSSL_FILETYPE_PEM),
  52154. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  52155. ExpectIntEQ(SSL_use_PrivateKey_file(ssl, NULL, WOLFSSL_FILETYPE_PEM),
  52156. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52157. #ifdef USE_CERT_BUFFERS_2048
  52158. {
  52159. const unsigned char* server_key = (const unsigned char*)server_key_der_2048;
  52160. unsigned char buf[FOURK_BUF];
  52161. word32 bufSz;
  52162. /* Invalid parameters. */
  52163. ExpectIntEQ(SSL_use_RSAPrivateKey_ASN1(NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52164. ExpectIntEQ(SSL_use_RSAPrivateKey_ASN1(ssl, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52165. ExpectIntEQ(SSL_use_RSAPrivateKey_ASN1(NULL,
  52166. (unsigned char*)client_key_der_2048, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52167. ExpectIntEQ(SSL_use_PrivateKey_ASN1(0, NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52168. ExpectIntEQ(SSL_use_PrivateKey_ASN1(0, ssl, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52169. ExpectIntEQ(SSL_use_PrivateKey_ASN1(0, NULL, (unsigned char*)server_key, 0),
  52170. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52171. ExpectIntEQ(SSL_CTX_use_PrivateKey_ASN1(0, NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52172. ExpectIntEQ(SSL_CTX_use_PrivateKey_ASN1(0, ctx, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52173. ExpectIntEQ(SSL_CTX_use_PrivateKey_ASN1(0, NULL, (unsigned char*)server_key,
  52174. 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52175. ExpectIntEQ(SSL_use_RSAPrivateKey_ASN1(ssl,
  52176. (unsigned char*)client_key_der_2048,
  52177. sizeof_client_key_der_2048), WOLFSSL_SUCCESS);
  52178. #if !defined(NO_CHECK_PRIVATE_KEY)
  52179. /* Should mismatch now that a different private key loaded */
  52180. ExpectIntNE(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  52181. #endif
  52182. ExpectIntEQ(SSL_use_PrivateKey_ASN1(0, ssl,
  52183. (unsigned char*)server_key,
  52184. sizeof_server_key_der_2048), WOLFSSL_SUCCESS);
  52185. #if !defined(NO_CHECK_PRIVATE_KEY)
  52186. /* After loading back in DER format of original key, should match */
  52187. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  52188. #endif
  52189. /* test loading private key to the WOLFSSL_CTX */
  52190. ExpectIntEQ(SSL_CTX_use_PrivateKey_ASN1(0, ctx,
  52191. (unsigned char*)client_key_der_2048,
  52192. sizeof_client_key_der_2048), WOLFSSL_SUCCESS);
  52193. #if !defined(NO_CHECK_PRIVATE_KEY)
  52194. /* Should mismatch now that a different private key loaded */
  52195. ExpectIntNE(wolfSSL_CTX_check_private_key(ctx), WOLFSSL_SUCCESS);
  52196. #endif
  52197. ExpectIntEQ(SSL_CTX_use_PrivateKey_ASN1(0, ctx,
  52198. (unsigned char*)server_key,
  52199. sizeof_server_key_der_2048), WOLFSSL_SUCCESS);
  52200. #if !defined(NO_CHECK_PRIVATE_KEY)
  52201. /* After loading back in DER format of original key, should match */
  52202. ExpectIntEQ(wolfSSL_CTX_check_private_key(ctx), WOLFSSL_SUCCESS);
  52203. #endif
  52204. /* Invalid parameters. */
  52205. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  52206. ExpectIntEQ(SSL_use_PrivateKey(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52207. ExpectIntEQ(SSL_use_PrivateKey(ssl, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52208. ExpectIntEQ(SSL_use_PrivateKey(NULL, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52209. /* pkey is empty - no key data to use. */
  52210. ExpectIntEQ(SSL_use_PrivateKey(ssl, pkey), WC_NO_ERR_TRACE(ASN_PARSE_E));
  52211. wolfSSL_EVP_PKEY_free(pkey);
  52212. pkey = NULL;
  52213. /* set PKEY and test again */
  52214. ExpectNotNull(wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, &pkey,
  52215. &server_key, (long)sizeof_server_key_der_2048));
  52216. ExpectIntEQ(SSL_use_PrivateKey(ssl, pkey), WOLFSSL_SUCCESS);
  52217. /* reuse PKEY structure and test
  52218. * this should be checked with a memory management sanity checker */
  52219. ExpectFalse(server_key == (const unsigned char*)server_key_der_2048);
  52220. server_key = (const unsigned char*)server_key_der_2048;
  52221. ExpectNotNull(wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, &pkey,
  52222. &server_key, (long)sizeof_server_key_der_2048));
  52223. ExpectIntEQ(SSL_use_PrivateKey(ssl, pkey), WOLFSSL_SUCCESS);
  52224. /* check striping PKCS8 header with wolfSSL_d2i_PrivateKey */
  52225. bufSz = FOURK_BUF;
  52226. ExpectIntGT((bufSz = (word32)wc_CreatePKCS8Key(buf, &bufSz,
  52227. (byte*)server_key_der_2048, sizeof_server_key_der_2048,
  52228. RSAk, NULL, 0)), 0);
  52229. server_key = (const unsigned char*)buf;
  52230. ExpectNotNull(wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, &pkey, &server_key,
  52231. (long)bufSz));
  52232. }
  52233. #endif
  52234. EVP_PKEY_free(pkey);
  52235. pkey = NULL;
  52236. SSL_free(ssl); /* frees x509 also since loaded into ssl */
  52237. ssl = NULL;
  52238. SSL_CTX_free(ctx);
  52239. ctx = NULL;
  52240. #endif /* end of RSA private key match tests */
  52241. #ifdef HAVE_ECC
  52242. #ifndef NO_WOLFSSL_SERVER
  52243. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  52244. #else
  52245. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  52246. #endif
  52247. ExpectTrue(SSL_CTX_use_certificate_file(ctx, eccCertFile,
  52248. WOLFSSL_FILETYPE_PEM));
  52249. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, eccKeyFile,
  52250. WOLFSSL_FILETYPE_PEM));
  52251. ExpectNotNull(ssl = SSL_new(ctx));
  52252. #if !defined(NO_CHECK_PRIVATE_KEY)
  52253. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  52254. #endif
  52255. SSL_free(ssl);
  52256. ssl = NULL;
  52257. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, cliEccKeyFile,
  52258. WOLFSSL_FILETYPE_PEM));
  52259. ExpectNotNull(ssl = SSL_new(ctx));
  52260. #ifdef WOLFSSL_VALIDATE_ECC_IMPORT
  52261. ExpectIntNE(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  52262. #endif
  52263. SSL_free(ssl);
  52264. ssl = NULL;
  52265. SSL_CTX_free(ctx);
  52266. ctx = NULL;
  52267. #endif /* end of ECC private key match tests */
  52268. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_IMPORT)
  52269. #ifndef NO_WOLFSSL_SERVER
  52270. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  52271. #else
  52272. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  52273. #endif
  52274. ExpectTrue(SSL_CTX_use_certificate_file(ctx, edCertFile,
  52275. WOLFSSL_FILETYPE_PEM));
  52276. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, edKeyFile,
  52277. WOLFSSL_FILETYPE_PEM));
  52278. ExpectNotNull(ssl = SSL_new(ctx));
  52279. #if !defined(NO_CHECK_PRIVATE_KEY)
  52280. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  52281. #endif
  52282. SSL_free(ssl);
  52283. ssl = NULL;
  52284. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, cliEdKeyFile,
  52285. WOLFSSL_FILETYPE_PEM));
  52286. ExpectNotNull(ssl = SSL_new(ctx));
  52287. #if !defined(NO_CHECK_PRIVATE_KEY)
  52288. ExpectIntNE(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  52289. #endif
  52290. SSL_free(ssl);
  52291. ssl = NULL;
  52292. SSL_CTX_free(ctx);
  52293. ctx = NULL;
  52294. #endif /* end of Ed25519 private key match tests */
  52295. #if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_IMPORT)
  52296. #ifndef NO_WOLFSSL_SERVER
  52297. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  52298. #else
  52299. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  52300. #endif
  52301. ExpectTrue(SSL_CTX_use_certificate_file(ctx, ed448CertFile,
  52302. WOLFSSL_FILETYPE_PEM));
  52303. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, ed448KeyFile,
  52304. WOLFSSL_FILETYPE_PEM));
  52305. ExpectNotNull(ssl = SSL_new(ctx));
  52306. #if !defined(NO_CHECK_PRIVATE_KEY)
  52307. ExpectIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  52308. #endif
  52309. SSL_free(ssl);
  52310. ssl = NULL;
  52311. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, cliEd448KeyFile,
  52312. WOLFSSL_FILETYPE_PEM));
  52313. ExpectNotNull(ssl = SSL_new(ctx));
  52314. #if !defined(NO_CHECK_PRIVATE_KEY)
  52315. ExpectIntNE(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
  52316. #endif
  52317. SSL_free(ssl);
  52318. ssl = NULL;
  52319. SSL_CTX_free(ctx);
  52320. ctx = NULL;
  52321. #endif /* end of Ed448 private key match tests */
  52322. EVP_cleanup();
  52323. /* test existence of no-op macros in wolfssl/openssl/ssl.h */
  52324. CONF_modules_free();
  52325. ENGINE_cleanup();
  52326. CONF_modules_unload();
  52327. (void)ssl;
  52328. (void)ctx;
  52329. (void)pkey;
  52330. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  52331. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) */
  52332. return EXPECT_RESULT();
  52333. }
  52334. static int test_wolfSSL_PEM_def_callback(void)
  52335. {
  52336. EXPECT_DECLS;
  52337. #ifdef OPENSSL_EXTRA
  52338. char buf[10];
  52339. const char* defpwd = "DEF PWD";
  52340. int defpwdLen = (int)XSTRLEN(defpwd);
  52341. int smallLen = 1;
  52342. /* Bad parameters. */
  52343. ExpectIntEQ(wolfSSL_PEM_def_callback(NULL, sizeof(buf), 0, NULL), 0);
  52344. ExpectIntEQ(wolfSSL_PEM_def_callback(NULL, sizeof(buf), 0, (void*)defpwd),
  52345. 0);
  52346. ExpectIntEQ(wolfSSL_PEM_def_callback(buf, sizeof(buf), 0, NULL), 0);
  52347. XMEMSET(buf, 0, sizeof(buf));
  52348. ExpectIntEQ(wolfSSL_PEM_def_callback(buf, sizeof(buf), 0, (void*)defpwd),
  52349. defpwdLen);
  52350. ExpectIntEQ(XMEMCMP(buf, defpwd, defpwdLen), 0);
  52351. ExpectIntEQ(buf[defpwdLen], 0);
  52352. /* Size of buffer is smaller than default password. */
  52353. XMEMSET(buf, 0, sizeof(buf));
  52354. ExpectIntEQ(wolfSSL_PEM_def_callback(buf, smallLen, 0, (void*)defpwd),
  52355. smallLen);
  52356. ExpectIntEQ(XMEMCMP(buf, defpwd, smallLen), 0);
  52357. ExpectIntEQ(buf[smallLen], 0);
  52358. #endif /* OPENSSL_EXTRA */
  52359. return EXPECT_RESULT();
  52360. }
  52361. static int test_wolfSSL_PEM_read_PrivateKey(void)
  52362. {
  52363. EXPECT_DECLS;
  52364. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && (!defined(NO_RSA) || \
  52365. !defined(NO_DSA) || defined(HAVE_ECC) || !defined(NO_DH))
  52366. XFILE file = XBADFILE;
  52367. #if !defined(NO_RSA)
  52368. const char* fname_rsa = "./certs/server-key.pem";
  52369. RSA* rsa = NULL;
  52370. WOLFSSL_EVP_PKEY_CTX* ctx = NULL;
  52371. unsigned char* sig = NULL;
  52372. size_t sigLen = 0;
  52373. const unsigned char tbs[] = {0, 1, 2, 3, 4, 5, 6, 7};
  52374. size_t tbsLen = sizeof(tbs);
  52375. #endif
  52376. #if !defined(NO_DSA)
  52377. const char* fname_dsa = "./certs/dsa2048.pem";
  52378. #endif
  52379. #if defined(HAVE_ECC)
  52380. const char* fname_ec = "./certs/ecc-key.pem";
  52381. #endif
  52382. #if !defined(NO_DH)
  52383. const char* fname_dh = "./certs/dh-priv-2048.pem";
  52384. #endif
  52385. EVP_PKEY* pkey = NULL;
  52386. /* Check error case. */
  52387. ExpectNull(pkey = PEM_read_PrivateKey(NULL, NULL, NULL, NULL));
  52388. /* not a PEM key. */
  52389. ExpectTrue((file = XFOPEN("./certs/ecc-key.der", "rb")) != XBADFILE);
  52390. ExpectNull(PEM_read_PrivateKey(file, NULL, NULL, NULL));
  52391. if (file != XBADFILE)
  52392. XFCLOSE(file);
  52393. file = XBADFILE;
  52394. #ifndef NO_RSA
  52395. /* Read in an RSA key. */
  52396. ExpectTrue((file = XFOPEN(fname_rsa, "rb")) != XBADFILE);
  52397. ExpectNotNull(pkey = PEM_read_PrivateKey(file, NULL, NULL, NULL));
  52398. if (file != XBADFILE)
  52399. XFCLOSE(file);
  52400. file = XBADFILE;
  52401. /* Make sure the key is usable by signing some data with it. */
  52402. ExpectNotNull(rsa = EVP_PKEY_get0_RSA(pkey));
  52403. ExpectIntGT((sigLen = RSA_size(rsa)), 0);
  52404. ExpectNotNull(sig = (unsigned char*)XMALLOC(sigLen, HEAP_HINT,
  52405. DYNAMIC_TYPE_TMP_BUFFER));
  52406. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  52407. ExpectIntEQ(EVP_PKEY_sign_init(ctx), WOLFSSL_SUCCESS);
  52408. ExpectIntEQ(EVP_PKEY_sign(ctx, sig, &sigLen, tbs, tbsLen),
  52409. WOLFSSL_SUCCESS);
  52410. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52411. EVP_PKEY_CTX_free(ctx);
  52412. EVP_PKEY_free(pkey);
  52413. pkey = NULL;
  52414. #endif
  52415. #ifndef NO_DSA
  52416. /* Read in a DSA key. */
  52417. ExpectTrue((file = XFOPEN(fname_dsa, "rb")) != XBADFILE);
  52418. #if defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || defined(WOLFSSL_OPENSSH)
  52419. ExpectNotNull(pkey = PEM_read_PrivateKey(file, NULL, NULL, NULL));
  52420. EVP_PKEY_free(pkey);
  52421. pkey = NULL;
  52422. #else
  52423. ExpectNull(PEM_read_PrivateKey(file, NULL, NULL, NULL));
  52424. #endif
  52425. if (file != XBADFILE)
  52426. XFCLOSE(file);
  52427. file = XBADFILE;
  52428. #endif
  52429. #ifdef HAVE_ECC
  52430. /* Read in an EC key. */
  52431. ExpectTrue((file = XFOPEN(fname_ec, "rb")) != XBADFILE);
  52432. ExpectNotNull(pkey = EVP_PKEY_new());
  52433. ExpectPtrEq(PEM_read_PrivateKey(file, &pkey, NULL, NULL), pkey);
  52434. if (file != XBADFILE)
  52435. XFCLOSE(file);
  52436. file = XBADFILE;
  52437. EVP_PKEY_free(pkey);
  52438. pkey = NULL;
  52439. #endif
  52440. #ifndef NO_DH
  52441. /* Read in a DH key. */
  52442. ExpectTrue((file = XFOPEN(fname_dh, "rb")) != XBADFILE);
  52443. #if (defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || \
  52444. defined(WOLFSSL_OPENSSH)) && (!defined(HAVE_FIPS) || \
  52445. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  52446. ExpectNotNull(pkey = PEM_read_PrivateKey(file, NULL, NULL, NULL));
  52447. EVP_PKEY_free(pkey);
  52448. pkey = NULL;
  52449. #else
  52450. ExpectNull(PEM_read_PrivateKey(file, NULL, NULL, NULL));
  52451. #endif
  52452. if (file != XBADFILE)
  52453. XFCLOSE(file);
  52454. file = XBADFILE;
  52455. #endif
  52456. #endif
  52457. return EXPECT_RESULT();
  52458. }
  52459. static int test_wolfSSL_PEM_read_PUBKEY(void)
  52460. {
  52461. EXPECT_DECLS;
  52462. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) \
  52463. && !defined(NO_FILESYSTEM)
  52464. XFILE file = XBADFILE;
  52465. const char* fname = "./certs/client-keyPub.pem";
  52466. EVP_PKEY* pkey = NULL;
  52467. /* Check error case. */
  52468. ExpectNull(pkey = PEM_read_PUBKEY(NULL, NULL, NULL, NULL));
  52469. /* Read in an RSA key. */
  52470. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  52471. ExpectNotNull(pkey = PEM_read_PUBKEY(file, NULL, NULL, NULL));
  52472. EVP_PKEY_free(pkey);
  52473. pkey = NULL;
  52474. if (file != XBADFILE)
  52475. XFCLOSE(file);
  52476. file = XBADFILE;
  52477. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  52478. ExpectNotNull(pkey = EVP_PKEY_new());
  52479. ExpectPtrEq(PEM_read_PUBKEY(file, &pkey, NULL, NULL), pkey);
  52480. EVP_PKEY_free(pkey);
  52481. if (file != XBADFILE)
  52482. XFCLOSE(file);
  52483. #endif
  52484. return EXPECT_RESULT();
  52485. }
  52486. /* test loading RSA key using BIO */
  52487. static int test_wolfSSL_PEM_PrivateKey_rsa(void)
  52488. {
  52489. EXPECT_DECLS;
  52490. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  52491. defined(USE_CERT_BUFFERS_2048) && !defined(NO_FILESYSTEM) && \
  52492. !defined(NO_BIO)
  52493. BIO* bio = NULL;
  52494. XFILE file = XBADFILE;
  52495. const char* fname = "./certs/server-key.pem";
  52496. const char* fname_rsa_p8 = "./certs/server-keyPkcs8.pem";
  52497. EVP_PKEY* pkey = NULL;
  52498. size_t sz = 0;
  52499. byte* buf = NULL;
  52500. EVP_PKEY* pkey2 = NULL;
  52501. EVP_PKEY* pkey3 = NULL;
  52502. RSA* rsa_key = NULL;
  52503. #if defined(WOLFSSL_KEY_GEN) || defined(WOLFSSL_CERT_GEN)
  52504. unsigned char extra[10];
  52505. int i;
  52506. BIO* pub_bio = NULL;
  52507. const unsigned char* server_key = (const unsigned char*)server_key_der_2048;
  52508. #endif
  52509. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  52510. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  52511. ExpectIntGT(sz = XFTELL(file), 0);
  52512. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  52513. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  52514. if (buf != NULL) {
  52515. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  52516. }
  52517. if (file != XBADFILE) {
  52518. XFCLOSE(file);
  52519. file = XBADFILE;
  52520. }
  52521. /* Test using BIO new mem and loading PEM private key */
  52522. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  52523. ExpectNotNull((pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL)));
  52524. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  52525. buf = NULL;
  52526. BIO_free(bio);
  52527. bio = NULL;
  52528. /* New empty EVP_PKEY */
  52529. ExpectNotNull(pkey2 = EVP_PKEY_new());
  52530. if (pkey2 != NULL) {
  52531. pkey2->type = EVP_PKEY_RSA;
  52532. }
  52533. /* Test parameter copy */
  52534. ExpectIntEQ(EVP_PKEY_copy_parameters(pkey2, pkey), 0);
  52535. EVP_PKEY_free(pkey2);
  52536. EVP_PKEY_free(pkey);
  52537. pkey = NULL;
  52538. /* Qt unit test case : rsa pkcs8 key */
  52539. ExpectTrue((file = XFOPEN(fname_rsa_p8, "rb")) != XBADFILE);
  52540. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  52541. ExpectIntGT(sz = XFTELL(file), 0);
  52542. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  52543. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  52544. if (buf) {
  52545. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  52546. }
  52547. if (file != XBADFILE) {
  52548. XFCLOSE(file);
  52549. file = XBADFILE;
  52550. }
  52551. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  52552. ExpectNotNull((pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL)));
  52553. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  52554. buf = NULL;
  52555. BIO_free(bio);
  52556. bio = NULL;
  52557. ExpectNotNull(pkey3 = EVP_PKEY_new());
  52558. ExpectNotNull(rsa_key = EVP_PKEY_get1_RSA(pkey));
  52559. ExpectIntEQ(EVP_PKEY_set1_RSA(pkey3, rsa_key), WOLFSSL_SUCCESS);
  52560. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  52561. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 1/* match */);
  52562. #else
  52563. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 0);
  52564. #endif
  52565. RSA_free(rsa_key);
  52566. EVP_PKEY_free(pkey3);
  52567. EVP_PKEY_free(pkey);
  52568. pkey = NULL;
  52569. pkey2 = NULL;
  52570. #if defined(WOLFSSL_KEY_GEN) || defined(WOLFSSL_CERT_GEN)
  52571. #define BIO_PEM_TEST_CHAR 'a'
  52572. XMEMSET(extra, BIO_PEM_TEST_CHAR, sizeof(extra));
  52573. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  52574. ExpectIntEQ(BIO_set_write_buf_size(bio, 4096), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52575. ExpectNotNull(pub_bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  52576. ExpectIntEQ(BIO_set_write_buf_size(pub_bio, 4096), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52577. ExpectNull(d2i_PrivateKey(EVP_PKEY_EC, &pkey, &server_key,
  52578. (long)sizeof_server_key_der_2048));
  52579. ExpectNull(pkey);
  52580. ExpectNotNull(wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, &pkey, &server_key,
  52581. (long)sizeof_server_key_der_2048));
  52582. ExpectIntEQ(PEM_write_bio_PrivateKey(NULL, pkey, NULL, NULL, 0, NULL, NULL),
  52583. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52584. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, NULL, NULL, NULL, 0, NULL, NULL),
  52585. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52586. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  52587. WOLFSSL_SUCCESS);
  52588. ExpectIntGT(BIO_pending(bio), 0);
  52589. ExpectIntEQ(BIO_pending(bio), 1679);
  52590. /* Check if the pubkey API writes only the public key */
  52591. #ifdef WOLFSSL_KEY_GEN
  52592. ExpectIntEQ(PEM_write_bio_PUBKEY(NULL, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52593. ExpectIntEQ(PEM_write_bio_PUBKEY(pub_bio, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52594. ExpectIntEQ(PEM_write_bio_PUBKEY(pub_bio, pkey), WOLFSSL_SUCCESS);
  52595. ExpectIntGT(BIO_pending(pub_bio), 0);
  52596. /* Previously both the private key and the pubkey calls would write
  52597. * out the private key and the PEM header was the only difference.
  52598. * The public PEM should be significantly shorter than the
  52599. * private key versison. */
  52600. ExpectIntEQ(BIO_pending(pub_bio), 451);
  52601. #else
  52602. /* Not supported. */
  52603. ExpectIntEQ(PEM_write_bio_PUBKEY(pub_bio, pkey), 0);
  52604. #endif
  52605. /* test creating new EVP_PKEY with good args */
  52606. ExpectNotNull((pkey2 = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL)));
  52607. if (pkey && pkey->pkey.ptr && pkey2 && pkey2->pkey.ptr) {
  52608. ExpectIntEQ((int)XMEMCMP(pkey->pkey.ptr, pkey2->pkey.ptr,
  52609. pkey->pkey_sz), 0);
  52610. }
  52611. /* test of reuse of EVP_PKEY */
  52612. ExpectNull(PEM_read_bio_PrivateKey(bio, &pkey, NULL, NULL));
  52613. ExpectIntEQ(BIO_pending(bio), 0);
  52614. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  52615. SSL_SUCCESS);
  52616. /* add 10 extra bytes after PEM */
  52617. ExpectIntEQ(BIO_write(bio, extra, 10), 10);
  52618. ExpectNotNull(PEM_read_bio_PrivateKey(bio, &pkey, NULL, NULL));
  52619. ExpectNotNull(pkey);
  52620. if (pkey && pkey->pkey.ptr && pkey2 && pkey2->pkey.ptr) {
  52621. ExpectIntEQ((int)XMEMCMP(pkey->pkey.ptr, pkey2->pkey.ptr,
  52622. pkey->pkey_sz), 0);
  52623. }
  52624. /* check 10 extra bytes still there */
  52625. ExpectIntEQ(BIO_pending(bio), 10);
  52626. ExpectIntEQ(BIO_read(bio, extra, 10), 10);
  52627. for (i = 0; i < 10; i++) {
  52628. ExpectIntEQ(extra[i], BIO_PEM_TEST_CHAR);
  52629. }
  52630. BIO_free(pub_bio);
  52631. BIO_free(bio);
  52632. bio = NULL;
  52633. EVP_PKEY_free(pkey);
  52634. pkey = NULL;
  52635. EVP_PKEY_free(pkey2);
  52636. #endif /* WOLFSSL_KEY_GEN || WOLFSSL_CERT_GEN */
  52637. #endif /* OPENSSL_EXTRA && !NO_CERTS && !NO_RSA && USE_CERT_BUFFERS_2048 &&
  52638. * !NO_FILESYSTEM && !NO_BIO */
  52639. return EXPECT_RESULT();
  52640. }
  52641. /* test loading ECC key using BIO */
  52642. static int test_wolfSSL_PEM_PrivateKey_ecc(void)
  52643. {
  52644. EXPECT_DECLS;
  52645. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && defined(HAVE_ECC) && \
  52646. !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  52647. BIO* bio = NULL;
  52648. EVP_PKEY* pkey = NULL;
  52649. XFILE file = XBADFILE;
  52650. const char* fname = "./certs/ecc-key.pem";
  52651. const char* fname_ecc_p8 = "./certs/ecc-keyPkcs8.pem";
  52652. size_t sz = 0;
  52653. byte* buf = NULL;
  52654. EVP_PKEY* pkey2 = NULL;
  52655. EVP_PKEY* pkey3 = NULL;
  52656. EC_KEY* ec_key = NULL;
  52657. int nid = 0;
  52658. BIO* pub_bio = NULL;
  52659. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  52660. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  52661. ExpectIntGT(sz = XFTELL(file), 0);
  52662. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  52663. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  52664. if (buf) {
  52665. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  52666. }
  52667. if (file != XBADFILE) {
  52668. XFCLOSE(file);
  52669. file = XBADFILE;
  52670. }
  52671. /* Test using BIO new mem and loading PEM private key */
  52672. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  52673. ExpectNotNull((pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL)));
  52674. BIO_free(bio);
  52675. bio = NULL;
  52676. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  52677. buf = NULL;
  52678. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  52679. ExpectNotNull(pub_bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  52680. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  52681. WOLFSSL_SUCCESS);
  52682. ExpectIntGT(BIO_pending(bio), 0);
  52683. /* No parameters. */
  52684. ExpectIntEQ(BIO_pending(bio), 227);
  52685. /* Check if the pubkey API writes only the public key */
  52686. #ifdef WOLFSSL_KEY_GEN
  52687. ExpectIntEQ(PEM_write_bio_PUBKEY(pub_bio, pkey), WOLFSSL_SUCCESS);
  52688. ExpectIntGT(BIO_pending(pub_bio), 0);
  52689. /* Previously both the private key and the pubkey calls would write
  52690. * out the private key and the PEM header was the only difference.
  52691. * The public PEM should be significantly shorter than the
  52692. * private key versison. */
  52693. ExpectIntEQ(BIO_pending(pub_bio), 178);
  52694. #endif
  52695. BIO_free(pub_bio);
  52696. BIO_free(bio);
  52697. bio = NULL;
  52698. ExpectNotNull(pkey2 = EVP_PKEY_new());
  52699. ExpectNotNull(pkey3 = EVP_PKEY_new());
  52700. if (pkey2 != NULL) {
  52701. pkey2->type = EVP_PKEY_EC;
  52702. }
  52703. /* Test parameter copy */
  52704. ExpectIntEQ(EVP_PKEY_copy_parameters(pkey2, pkey), 1);
  52705. /* Qt unit test case 1*/
  52706. ExpectNotNull(ec_key = EVP_PKEY_get1_EC_KEY(pkey));
  52707. ExpectIntEQ(EVP_PKEY_set1_EC_KEY(pkey3, ec_key), WOLFSSL_SUCCESS);
  52708. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  52709. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 1/* match */);
  52710. #else
  52711. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 0);
  52712. #endif
  52713. /* Test default digest */
  52714. ExpectIntEQ(EVP_PKEY_get_default_digest_nid(pkey, &nid), 1);
  52715. ExpectIntEQ(nid, NID_sha256);
  52716. EC_KEY_free(ec_key);
  52717. ec_key = NULL;
  52718. EVP_PKEY_free(pkey3);
  52719. pkey3 = NULL;
  52720. EVP_PKEY_free(pkey2);
  52721. pkey2 = NULL;
  52722. EVP_PKEY_free(pkey);
  52723. pkey = NULL;
  52724. /* Qt unit test case ec pkcs8 key */
  52725. ExpectTrue((file = XFOPEN(fname_ecc_p8, "rb")) != XBADFILE);
  52726. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  52727. ExpectIntGT(sz = XFTELL(file), 0);
  52728. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  52729. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  52730. if (buf) {
  52731. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  52732. }
  52733. if (file != XBADFILE) {
  52734. XFCLOSE(file);
  52735. file = XBADFILE;
  52736. }
  52737. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  52738. ExpectNotNull((pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL)));
  52739. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  52740. buf = NULL;
  52741. BIO_free(bio);
  52742. bio = NULL;
  52743. ExpectNotNull(pkey3 = EVP_PKEY_new());
  52744. /* Qt unit test case */
  52745. ExpectNotNull(ec_key = EVP_PKEY_get1_EC_KEY(pkey));
  52746. ExpectIntEQ(EVP_PKEY_set1_EC_KEY(pkey3, ec_key), WOLFSSL_SUCCESS);
  52747. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  52748. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 1/* match */);
  52749. #else
  52750. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey3), 0);
  52751. #endif
  52752. EC_KEY_free(ec_key);
  52753. EVP_PKEY_free(pkey3);
  52754. EVP_PKEY_free(pkey);
  52755. pkey = NULL;
  52756. #endif
  52757. return EXPECT_RESULT();
  52758. }
  52759. /* test loading DSA key using BIO */
  52760. static int test_wolfSSL_PEM_PrivateKey_dsa(void)
  52761. {
  52762. EXPECT_DECLS;
  52763. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_DSA) && \
  52764. !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  52765. #if defined(WOLFSSL_QT) || defined(OPENSSL_ALL)
  52766. BIO* bio = NULL;
  52767. EVP_PKEY* pkey = NULL;
  52768. ExpectNotNull(bio = BIO_new_file("./certs/dsa2048.pem", "rb"));
  52769. /* Private DSA EVP_PKEY */
  52770. ExpectNotNull(pkey = wolfSSL_PEM_read_bio_PrivateKey(bio, NULL, NULL,
  52771. NULL));
  52772. BIO_free(bio);
  52773. bio = NULL;
  52774. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  52775. #if defined(OPENSSL_ALL) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  52776. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, NULL, NULL, 0, NULL,
  52777. NULL), 0);
  52778. #endif
  52779. #ifdef WOLFSSL_KEY_GEN
  52780. ExpectIntEQ(PEM_write_bio_PUBKEY(bio, pkey), 1);
  52781. ExpectIntEQ(BIO_pending(bio), 1178);
  52782. BIO_reset(bio);
  52783. #endif
  52784. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  52785. 1);
  52786. ExpectIntEQ(BIO_pending(bio), 1196);
  52787. BIO_free(bio);
  52788. bio = NULL;
  52789. EVP_PKEY_free(pkey);
  52790. pkey = NULL;
  52791. #endif
  52792. #endif
  52793. return EXPECT_RESULT();
  52794. }
  52795. /* test loading DH key using BIO */
  52796. static int test_wolfSSL_PEM_PrivateKey_dh(void)
  52797. {
  52798. EXPECT_DECLS;
  52799. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_DH) && \
  52800. !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  52801. #if (defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || \
  52802. defined(WOLFSSL_OPENSSH)) && (!defined(HAVE_FIPS) || \
  52803. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  52804. BIO* bio = NULL;
  52805. EVP_PKEY* pkey = NULL;
  52806. ExpectNotNull(bio = BIO_new_file("./certs/dh-priv-2048.pem", "rb"));
  52807. /* Private DH EVP_PKEY */
  52808. ExpectNotNull(pkey = wolfSSL_PEM_read_bio_PrivateKey(bio, NULL, NULL,
  52809. NULL));
  52810. BIO_free(bio);
  52811. bio = NULL;
  52812. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  52813. #if defined(OPENSSL_ALL) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  52814. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, NULL, NULL, 0, NULL,
  52815. NULL), 0);
  52816. #endif
  52817. #ifdef WOLFSSL_KEY_GEN
  52818. ExpectIntEQ(PEM_write_bio_PUBKEY(bio, pkey), 0);
  52819. #endif
  52820. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  52821. 1);
  52822. ExpectIntEQ(BIO_pending(bio), 806);
  52823. BIO_free(bio);
  52824. bio = NULL;
  52825. EVP_PKEY_free(pkey);
  52826. pkey = NULL;
  52827. #endif
  52828. #endif
  52829. return EXPECT_RESULT();
  52830. }
  52831. static int test_wolfSSL_PEM_PrivateKey(void)
  52832. {
  52833. EXPECT_DECLS;
  52834. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  52835. (!defined(NO_RSA) || defined(HAVE_ECC)) && defined(USE_CERT_BUFFERS_2048)
  52836. #ifndef NO_BIO
  52837. BIO* bio = NULL;
  52838. #endif
  52839. EVP_PKEY* pkey = NULL;
  52840. const unsigned char* server_key = (const unsigned char*)server_key_der_2048;
  52841. #ifndef NO_BIO
  52842. /* test creating new EVP_PKEY with bad arg */
  52843. ExpectNull((pkey = PEM_read_bio_PrivateKey(NULL, NULL, NULL, NULL)));
  52844. /* Test bad EVP_PKEY type. */
  52845. /* New HMAC EVP_PKEY */
  52846. ExpectNotNull(bio = BIO_new_mem_buf("", 1));
  52847. ExpectNotNull(pkey = EVP_PKEY_new());
  52848. if (pkey != NULL) {
  52849. pkey->type = EVP_PKEY_HMAC;
  52850. }
  52851. ExpectIntEQ(PEM_write_bio_PrivateKey(bio, pkey, NULL, NULL, 0, NULL, NULL),
  52852. 0);
  52853. #if defined(OPENSSL_ALL) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  52854. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, NULL, NULL, 0, NULL,
  52855. NULL), 0);
  52856. #endif
  52857. #ifdef WOLFSSL_KEY_GEN
  52858. ExpectIntEQ(PEM_write_bio_PUBKEY(bio, pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52859. #endif
  52860. EVP_PKEY_free(pkey);
  52861. pkey = NULL;
  52862. BIO_free(bio);
  52863. bio = NULL;
  52864. /* key is DES encrypted */
  52865. #if !defined(NO_DES3) && defined(WOLFSSL_ENCRYPTED_KEYS) && \
  52866. !defined(NO_RSA) && !defined(NO_BIO) && !defined(NO_FILESYSTEM) && \
  52867. !defined(NO_MD5) && defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA)
  52868. {
  52869. XFILE f = XBADFILE;
  52870. wc_pem_password_cb* passwd_cb = NULL;
  52871. void* passwd_cb_userdata;
  52872. SSL_CTX* ctx = NULL;
  52873. char passwd[] = "bad password";
  52874. #ifndef WOLFSSL_NO_TLS12
  52875. #ifndef NO_WOLFSSL_SERVER
  52876. ExpectNotNull(ctx = SSL_CTX_new(TLSv1_2_server_method()));
  52877. #else
  52878. ExpectNotNull(ctx = SSL_CTX_new(TLSv1_2_client_method()));
  52879. #endif
  52880. #else
  52881. #ifndef NO_WOLFSSL_SERVER
  52882. ExpectNotNull(ctx = SSL_CTX_new(wolfTLSv1_3_server_method()));
  52883. #else
  52884. ExpectNotNull(ctx = SSL_CTX_new(wolfTLSv1_3_client_method()));
  52885. #endif
  52886. #endif
  52887. ExpectNotNull(bio = BIO_new_file("./certs/server-keyEnc.pem", "rb"));
  52888. SSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  52889. ExpectNotNull(passwd_cb = SSL_CTX_get_default_passwd_cb(ctx));
  52890. ExpectNull(passwd_cb_userdata =
  52891. SSL_CTX_get_default_passwd_cb_userdata(ctx));
  52892. /* fail case with password call back */
  52893. ExpectNull(pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL,
  52894. (void*)passwd));
  52895. BIO_free(bio);
  52896. ExpectNotNull(bio = BIO_new_file("./certs/server-keyEnc.pem", "rb"));
  52897. ExpectNull(pkey = PEM_read_bio_PrivateKey(bio, NULL, passwd_cb,
  52898. (void*)passwd));
  52899. BIO_free(bio);
  52900. ExpectTrue((f = XFOPEN("./certs/server-keyEnc.pem", "rb")) != XBADFILE);
  52901. ExpectNotNull(bio = BIO_new_fp(f, BIO_CLOSE));
  52902. if ((bio == NULL) && (f != XBADFILE)) {
  52903. XFCLOSE(f);
  52904. }
  52905. /* use callback that works */
  52906. ExpectNotNull(pkey = PEM_read_bio_PrivateKey(bio, NULL, passwd_cb,
  52907. (void*)"yassl123"));
  52908. ExpectIntEQ(SSL_CTX_use_PrivateKey(ctx, pkey), SSL_SUCCESS);
  52909. EVP_PKEY_free(pkey);
  52910. pkey = NULL;
  52911. BIO_free(bio);
  52912. bio = NULL;
  52913. SSL_CTX_free(ctx);
  52914. }
  52915. #endif /* !defined(NO_DES3) */
  52916. #endif /* !NO_BIO */
  52917. #if defined(HAVE_ECC) && !defined(NO_FILESYSTEM)
  52918. {
  52919. unsigned char buf[2048];
  52920. size_t bytes = 0;
  52921. XFILE f = XBADFILE;
  52922. SSL_CTX* ctx = NULL;
  52923. #ifndef WOLFSSL_NO_TLS12
  52924. #ifndef NO_WOLFSSL_SERVER
  52925. ExpectNotNull(ctx = SSL_CTX_new(TLSv1_2_server_method()));
  52926. #else
  52927. ExpectNotNull(ctx = SSL_CTX_new(TLSv1_2_client_method()));
  52928. #endif
  52929. #else
  52930. #ifndef NO_WOLFSSL_SERVER
  52931. ExpectNotNull(ctx = SSL_CTX_new(wolfTLSv1_3_server_method()));
  52932. #else
  52933. ExpectNotNull(ctx = SSL_CTX_new(wolfTLSv1_3_client_method()));
  52934. #endif
  52935. #endif
  52936. ExpectTrue((f = XFOPEN("./certs/ecc-key.der", "rb")) != XBADFILE);
  52937. ExpectIntGT(bytes = (size_t)XFREAD(buf, 1, sizeof(buf), f), 0);
  52938. if (f != XBADFILE)
  52939. XFCLOSE(f);
  52940. server_key = buf;
  52941. pkey = NULL;
  52942. ExpectNull(d2i_PrivateKey(EVP_PKEY_RSA, &pkey, &server_key, (long int)bytes));
  52943. ExpectNull(pkey);
  52944. ExpectNotNull(d2i_PrivateKey(EVP_PKEY_EC, &pkey, &server_key, (long int)bytes));
  52945. ExpectIntEQ(SSL_CTX_use_PrivateKey(ctx, pkey), SSL_SUCCESS);
  52946. EVP_PKEY_free(pkey);
  52947. pkey = NULL;
  52948. SSL_CTX_free(ctx);
  52949. server_key = NULL;
  52950. }
  52951. #endif
  52952. #ifndef NO_BIO
  52953. (void)bio;
  52954. #endif
  52955. (void)pkey;
  52956. (void)server_key;
  52957. #endif /* OPENSSL_EXTRA && !NO_CERTS && !NO_RSA && USE_CERT_BUFFERS_2048 */
  52958. return EXPECT_RESULT();
  52959. }
  52960. static int test_wolfSSL_PEM_file_RSAKey(void)
  52961. {
  52962. EXPECT_DECLS;
  52963. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \
  52964. defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA) && \
  52965. !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
  52966. RSA* rsa = NULL;
  52967. XFILE fp = XBADFILE;
  52968. ExpectTrue((fp = XFOPEN("./certs/rsa-pub-2048.pem", "rb")) != XBADFILE);
  52969. ExpectNotNull((rsa = PEM_read_RSA_PUBKEY(fp, NULL, NULL, NULL)));
  52970. if (fp != XBADFILE)
  52971. XFCLOSE(fp);
  52972. ExpectIntEQ(RSA_size(rsa), 256);
  52973. ExpectIntEQ(PEM_write_RSAPublicKey(XBADFILE, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52974. ExpectIntEQ(PEM_write_RSAPublicKey(stderr, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52975. ExpectIntEQ(PEM_write_RSAPublicKey(stderr, rsa), WOLFSSL_SUCCESS);
  52976. ExpectIntEQ(PEM_write_RSA_PUBKEY(XBADFILE, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52977. ExpectIntEQ(PEM_write_RSA_PUBKEY(stderr, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  52978. ExpectIntEQ(PEM_write_RSA_PUBKEY(stderr, rsa), WOLFSSL_SUCCESS);
  52979. RSA_free(rsa);
  52980. #endif /* defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \
  52981. (defined(WOLFSSL_KEY_GEN) || WOLFSSL_CERT_GEN) && \
  52982. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_CERTS) */
  52983. return EXPECT_RESULT();
  52984. }
  52985. static int test_wolfSSL_PEM_file_RSAPrivateKey(void)
  52986. {
  52987. EXPECT_DECLS;
  52988. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN) && \
  52989. !defined(NO_FILESYSTEM) && \
  52990. (defined(WOLFSSL_PEM_TO_DER) || defined(WOLFSSL_DER_TO_PEM))
  52991. RSA* rsa = NULL;
  52992. XFILE f = NULL;
  52993. ExpectTrue((f = XFOPEN(svrKeyFile, "r")) != XBADFILE);
  52994. ExpectNotNull((rsa = PEM_read_RSAPrivateKey(f, NULL, NULL, NULL)));
  52995. ExpectIntEQ(RSA_size(rsa), 256);
  52996. if (f != XBADFILE) {
  52997. XFCLOSE(f);
  52998. f = XBADFILE;
  52999. }
  53000. ExpectIntEQ(PEM_write_RSAPrivateKey(XBADFILE, rsa, NULL, NULL, 0, NULL,
  53001. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53002. ExpectIntEQ(PEM_write_RSAPrivateKey(stderr, NULL, NULL, NULL, 0, NULL,
  53003. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53004. ExpectIntEQ(PEM_write_RSAPrivateKey(stderr, rsa, NULL, NULL, 0, NULL, NULL),
  53005. WOLFSSL_SUCCESS);
  53006. RSA_free(rsa);
  53007. #ifdef HAVE_ECC
  53008. ExpectTrue((f = XFOPEN(eccKeyFile, "r")) != XBADFILE);
  53009. ExpectNull((rsa = PEM_read_RSAPrivateKey(f, NULL, NULL, NULL)));
  53010. if (f != XBADFILE)
  53011. XFCLOSE(f);
  53012. #endif /* HAVE_ECC */
  53013. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) */
  53014. return EXPECT_RESULT();
  53015. }
  53016. static int test_wolfSSL_PEM_read_RSA_PUBKEY(void)
  53017. {
  53018. EXPECT_DECLS;
  53019. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  53020. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  53021. XFILE file = XBADFILE;
  53022. const char* fname = "./certs/client-keyPub.pem";
  53023. RSA *rsa = NULL;
  53024. ExpectNull(wolfSSL_PEM_read_RSA_PUBKEY(XBADFILE, NULL, NULL, NULL));
  53025. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  53026. ExpectNotNull((rsa = PEM_read_RSA_PUBKEY(file, NULL, NULL, NULL)));
  53027. ExpectIntEQ(RSA_size(rsa), 256);
  53028. RSA_free(rsa);
  53029. if (file != XBADFILE)
  53030. XFCLOSE(file);
  53031. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) */
  53032. return EXPECT_RESULT();
  53033. }
  53034. #ifndef NO_BIO
  53035. static int test_wolfSSL_PEM_bio_RSAKey(void)
  53036. {
  53037. EXPECT_DECLS;
  53038. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \
  53039. defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA) && \
  53040. !defined(NO_FILESYSTEM) && !defined(NO_CERTS)
  53041. RSA* rsa = NULL;
  53042. BIO* bio = NULL;
  53043. /* PrivateKey */
  53044. ExpectNotNull(bio = BIO_new_file(svrKeyFile, "rb"));
  53045. ExpectNull((rsa = PEM_read_bio_RSAPrivateKey(NULL, NULL, NULL, NULL)));
  53046. ExpectNotNull(PEM_read_bio_RSAPrivateKey(bio, &rsa, NULL, NULL));
  53047. ExpectNotNull(rsa);
  53048. ExpectIntEQ(RSA_size(rsa), 256);
  53049. ExpectIntEQ(PEM_write_bio_RSAPrivateKey(NULL, NULL, NULL, NULL, 0, NULL, \
  53050. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53051. BIO_free(bio);
  53052. bio = NULL;
  53053. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  53054. ExpectIntEQ(PEM_write_bio_RSAPrivateKey(bio, rsa, NULL, NULL, 0, NULL, \
  53055. NULL), WOLFSSL_SUCCESS);
  53056. BIO_free(bio);
  53057. bio = NULL;
  53058. RSA_free(rsa);
  53059. rsa = NULL;
  53060. /* PUBKEY */
  53061. ExpectNotNull(bio = BIO_new_file("./certs/rsa-pub-2048.pem", "rb"));
  53062. ExpectNull((rsa = PEM_read_bio_RSA_PUBKEY(NULL, NULL, NULL, NULL)));
  53063. ExpectNotNull((rsa = PEM_read_bio_RSA_PUBKEY(bio, NULL, NULL, NULL)));
  53064. ExpectIntEQ(RSA_size(rsa), 256);
  53065. ExpectIntEQ(PEM_write_bio_RSA_PUBKEY(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53066. BIO_free(bio);
  53067. bio = NULL;
  53068. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  53069. ExpectIntEQ(PEM_write_bio_RSA_PUBKEY(bio, rsa), WOLFSSL_SUCCESS);
  53070. BIO_free(bio);
  53071. bio = NULL;
  53072. RSA_free(rsa);
  53073. rsa = NULL;
  53074. /* Ensure that keys beginning with BEGIN RSA PUBLIC KEY can be read, too. */
  53075. ExpectNotNull(bio = BIO_new_file("./certs/server-keyPub.pem", "rb"));
  53076. ExpectNotNull((rsa = PEM_read_bio_RSA_PUBKEY(bio, NULL, NULL, NULL)));
  53077. BIO_free(bio);
  53078. bio = NULL;
  53079. RSA_free(rsa);
  53080. rsa = NULL;
  53081. #ifdef HAVE_ECC
  53082. /* ensure that non-rsa keys do not work */
  53083. ExpectNotNull(bio = BIO_new_file(eccKeyFile, "rb")); /* ecc key */
  53084. ExpectNull((rsa = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, NULL)));
  53085. ExpectNull((rsa = PEM_read_bio_RSA_PUBKEY(bio, NULL, NULL, NULL)));
  53086. BIO_free(bio);
  53087. bio = NULL;
  53088. RSA_free(rsa);
  53089. rsa = NULL;
  53090. #endif /* HAVE_ECC */
  53091. #endif /* defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \
  53092. (defined(WOLFSSL_KEY_GEN) || WOLFSSL_CERT_GEN) && \
  53093. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_CERTS) */
  53094. return EXPECT_RESULT();
  53095. }
  53096. static int test_wolfSSL_PEM_bio_RSAPrivateKey(void)
  53097. {
  53098. EXPECT_DECLS;
  53099. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  53100. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  53101. RSA* rsa = NULL;
  53102. RSA* rsa_dup = NULL;
  53103. BIO* bio = NULL;
  53104. ExpectNotNull(bio = BIO_new_file(svrKeyFile, "rb"));
  53105. ExpectNotNull((rsa = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, NULL)));
  53106. ExpectIntEQ(RSA_size(rsa), 256);
  53107. #if defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA)
  53108. ExpectNull(rsa_dup = RSAPublicKey_dup(NULL));
  53109. /* Test duplicating empty key. */
  53110. ExpectNotNull(rsa_dup = RSA_new());
  53111. ExpectNull(RSAPublicKey_dup(rsa_dup));
  53112. RSA_free(rsa_dup);
  53113. rsa_dup = NULL;
  53114. ExpectNotNull(rsa_dup = RSAPublicKey_dup(rsa));
  53115. ExpectPtrNE(rsa_dup, rsa);
  53116. #endif
  53117. /* test if valgrind complains about unreleased memory */
  53118. RSA_up_ref(rsa);
  53119. RSA_free(rsa);
  53120. BIO_free(bio);
  53121. bio = NULL;
  53122. RSA_free(rsa);
  53123. rsa = NULL;
  53124. RSA_free(rsa_dup);
  53125. rsa_dup = NULL;
  53126. #ifdef HAVE_ECC
  53127. ExpectNotNull(bio = BIO_new_file(eccKeyFile, "rb"));
  53128. ExpectNull((rsa = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, NULL)));
  53129. BIO_free(bio);
  53130. #endif /* HAVE_ECC */
  53131. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) */
  53132. return EXPECT_RESULT();
  53133. }
  53134. static int test_wolfSSL_PEM_bio_DSAKey(void)
  53135. {
  53136. EXPECT_DECLS;
  53137. #ifndef HAVE_SELFTEST
  53138. #if (defined(WOLFSSL_QT) || defined(OPENSSL_ALL)) && !defined(NO_CERTS) && \
  53139. defined(WOLFSSL_KEY_GEN) && !defined(NO_FILESYSTEM) && !defined(NO_DSA)
  53140. DSA* dsa = NULL;
  53141. BIO* bio = NULL;
  53142. /* PrivateKey */
  53143. ExpectNotNull(bio = BIO_new_file("./certs/1024/dsa1024.pem", "rb"));
  53144. ExpectNull((dsa = PEM_read_bio_DSAPrivateKey(NULL, NULL, NULL, NULL)));
  53145. ExpectNotNull((dsa = PEM_read_bio_DSAPrivateKey(bio, NULL, NULL, NULL)));
  53146. ExpectIntEQ(BN_num_bytes(dsa->g), 128);
  53147. ExpectIntEQ(PEM_write_bio_DSAPrivateKey(NULL, NULL, NULL, NULL, 0, NULL,
  53148. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53149. BIO_free(bio);
  53150. bio = NULL;
  53151. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  53152. ExpectIntEQ(PEM_write_bio_DSAPrivateKey(bio, dsa, NULL, NULL, 0, NULL,
  53153. NULL), WOLFSSL_SUCCESS);
  53154. BIO_free(bio);
  53155. bio = NULL;
  53156. DSA_free(dsa);
  53157. dsa = NULL;
  53158. /* PUBKEY */
  53159. ExpectNotNull(bio = BIO_new_file("./certs/1024/dsa-pub-1024.pem", "rb"));
  53160. ExpectNull((dsa = PEM_read_bio_DSA_PUBKEY(NULL, NULL, NULL, NULL)));
  53161. ExpectNotNull((dsa = PEM_read_bio_DSA_PUBKEY(bio, NULL, NULL, NULL)));
  53162. ExpectIntEQ(BN_num_bytes(dsa->g), 128);
  53163. ExpectIntEQ(PEM_write_bio_DSA_PUBKEY(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53164. BIO_free(bio);
  53165. bio = NULL;
  53166. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  53167. ExpectIntEQ(PEM_write_bio_DSA_PUBKEY(bio, dsa), WOLFSSL_SUCCESS);
  53168. BIO_free(bio);
  53169. bio = NULL;
  53170. DSA_free(dsa);
  53171. dsa = NULL;
  53172. #ifdef HAVE_ECC
  53173. /* ensure that non-dsa keys do not work */
  53174. ExpectNotNull(bio = BIO_new_file(eccKeyFile, "rb")); /* ecc key */
  53175. ExpectNull((dsa = PEM_read_bio_DSAPrivateKey(bio, NULL, NULL, NULL)));
  53176. ExpectNull((dsa = PEM_read_bio_DSA_PUBKEY(bio, NULL, NULL, NULL)));
  53177. BIO_free(bio);
  53178. bio = NULL;
  53179. DSA_free(dsa);
  53180. dsa = NULL;
  53181. #endif /* HAVE_ECC */
  53182. #endif /* defined(WOLFSSL_QT) || defined(OPENSSL_ALL)) && \
  53183. !defined(NO_CERTS) && defined(WOLFSSL_KEY_GEN) && \
  53184. !defined(NO_FILESYSTEM) && !defined(NO_DSA) */
  53185. #endif /* HAVE_SELFTEST */
  53186. return EXPECT_RESULT();
  53187. }
  53188. static int test_wolfSSL_PEM_bio_ECKey(void)
  53189. {
  53190. EXPECT_DECLS;
  53191. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \
  53192. defined(WOLFSSL_KEY_GEN) && !defined(NO_FILESYSTEM) && defined(HAVE_ECC)
  53193. EC_KEY* ec = NULL;
  53194. EC_KEY* ec2;
  53195. BIO* bio = NULL;
  53196. #if defined(WOLFSSL_PEM_TO_DER) || defined(WOLFSSL_DER_TO_PEM)
  53197. unsigned char* pem = NULL;
  53198. int pLen;
  53199. #endif
  53200. static char ec_key_bad_1[] = "-----BEGIN PUBLIC KEY-----\n"
  53201. "MAA=\n"
  53202. "-----END PUBLIC KEY-----";
  53203. static char ec_priv_key_bad_1[] = "-----BEGIN EC PRIVATE KEY-----\n"
  53204. "MAA=\n"
  53205. "-----END EC PRIVATE KEY-----";
  53206. /* PrivateKey */
  53207. ExpectNotNull(bio = BIO_new_file("./certs/ecc-key.pem", "rb"));
  53208. ExpectNull((ec = PEM_read_bio_ECPrivateKey(NULL, NULL, NULL, NULL)));
  53209. ec2 = NULL;
  53210. ExpectNotNull((ec = PEM_read_bio_ECPrivateKey(bio, &ec2, NULL, NULL)));
  53211. ExpectIntEQ(ec == ec2, 1);
  53212. ExpectIntEQ(wc_ecc_size((ecc_key*)ec->internal), 32);
  53213. ExpectIntEQ(PEM_write_bio_ECPrivateKey(NULL, NULL, NULL, NULL, 0, NULL,
  53214. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53215. ExpectIntEQ(PEM_write_bio_ECPrivateKey(bio, NULL, NULL, NULL, 0, NULL,
  53216. NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53217. ExpectIntEQ(PEM_write_bio_ECPrivateKey(NULL, ec, NULL, NULL, 0, NULL, NULL),
  53218. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53219. BIO_free(bio);
  53220. bio = NULL;
  53221. /* Public key data - fail. */
  53222. ExpectNotNull(bio = BIO_new_file("./certs/ecc-client-keyPub.pem", "rb"));
  53223. ExpectNull(PEM_read_bio_ECPrivateKey(bio, NULL, NULL, NULL));
  53224. BIO_free(bio);
  53225. bio = NULL;
  53226. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  53227. ExpectIntEQ(PEM_write_bio_ECPrivateKey(bio, ec, NULL, NULL, 0, NULL, \
  53228. NULL), WOLFSSL_SUCCESS);
  53229. BIO_free(bio);
  53230. bio = NULL;
  53231. ExpectIntEQ(PEM_write_ECPrivateKey(XBADFILE, NULL, NULL, NULL, 0, NULL,
  53232. NULL),WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53233. ExpectIntEQ(PEM_write_ECPrivateKey(stderr, NULL, NULL, NULL, 0, NULL, NULL),
  53234. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53235. ExpectIntEQ(PEM_write_ECPrivateKey(XBADFILE, ec, NULL, NULL, 0, NULL, NULL),
  53236. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53237. ExpectIntEQ(PEM_write_ECPrivateKey(stderr, ec, NULL, NULL, 0, NULL, NULL),
  53238. WOLFSSL_SUCCESS);
  53239. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(NULL, NULL, NULL, 0, NULL,
  53240. NULL), 0);
  53241. #if defined(WOLFSSL_PEM_TO_DER) || defined(WOLFSSL_DER_TO_PEM)
  53242. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(ec, NULL, NULL, 0, NULL,
  53243. NULL), 0);
  53244. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(NULL, NULL, NULL, 0, &pem,
  53245. NULL), 0);
  53246. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(NULL, NULL, NULL, 0, NULL,
  53247. &pLen), 0);
  53248. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(NULL, NULL, NULL, 0, &pem,
  53249. &pLen), 0);
  53250. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(ec, NULL, NULL, 0, NULL,
  53251. &pLen), 0);
  53252. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(ec, NULL, NULL, 0, &pem,
  53253. NULL), 0);
  53254. ExpectIntEQ(wolfSSL_PEM_write_mem_ECPrivateKey(ec, NULL, NULL, 0, &pem,
  53255. &pLen), 1);
  53256. ExpectIntGT(pLen, 0);
  53257. XFREE(pem, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  53258. #endif
  53259. EC_KEY_free(ec);
  53260. ec = NULL;
  53261. /* PUBKEY */
  53262. ExpectNotNull(bio = BIO_new_file("./certs/ecc-client-keyPub.pem", "rb"));
  53263. ExpectNull((ec = PEM_read_bio_EC_PUBKEY(NULL, NULL, NULL, NULL)));
  53264. ec2 = NULL;
  53265. ExpectNotNull((ec = PEM_read_bio_EC_PUBKEY(bio, &ec2, NULL, NULL)));
  53266. ExpectIntEQ(ec == ec2, 1);
  53267. ExpectIntEQ(wc_ecc_size((ecc_key*)ec->internal), 32);
  53268. ExpectIntEQ(PEM_write_bio_EC_PUBKEY(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53269. BIO_free(bio);
  53270. bio = NULL;
  53271. /* Test 0x30, 0x00 fails. */
  53272. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_key_bad_1,
  53273. sizeof(ec_key_bad_1)));
  53274. ExpectNull(PEM_read_bio_EC_PUBKEY(bio, NULL, NULL, NULL));
  53275. BIO_free(bio);
  53276. bio = NULL;
  53277. /* Private key data - fail. */
  53278. ExpectNotNull(bio = BIO_new_file("./certs/ecc-key.pem", "rb"));
  53279. ExpectNull(PEM_read_bio_EC_PUBKEY(bio, NULL, NULL, NULL));
  53280. BIO_free(bio);
  53281. bio = NULL;
  53282. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  53283. ExpectIntEQ(PEM_write_bio_EC_PUBKEY(bio, ec), WOLFSSL_SUCCESS);
  53284. BIO_free(bio);
  53285. bio = NULL;
  53286. /* Same test as above, but with a file pointer rather than a BIO. */
  53287. ExpectIntEQ(PEM_write_EC_PUBKEY(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53288. ExpectIntEQ(PEM_write_EC_PUBKEY(NULL, ec), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53289. ExpectIntEQ(PEM_write_EC_PUBKEY(stderr, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53290. ExpectIntEQ(PEM_write_EC_PUBKEY(stderr, ec), WOLFSSL_SUCCESS);
  53291. EC_KEY_free(ec);
  53292. ec = NULL;
  53293. #ifndef NO_RSA
  53294. /* ensure that non-ec keys do not work */
  53295. ExpectNotNull(bio = BIO_new_file(svrKeyFile, "rb")); /* rsa key */
  53296. ExpectNull((ec = PEM_read_bio_ECPrivateKey(bio, NULL, NULL, NULL)));
  53297. ExpectNull((ec = PEM_read_bio_EC_PUBKEY(bio, NULL, NULL, NULL)));
  53298. BIO_free(bio);
  53299. bio = NULL;
  53300. EC_KEY_free(ec);
  53301. ec = NULL;
  53302. #endif /* !NO_RSA */
  53303. /* Test 0x30, 0x00 fails. */
  53304. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_priv_key_bad_1,
  53305. sizeof(ec_priv_key_bad_1)));
  53306. ExpectNull(PEM_read_bio_ECPrivateKey(bio, NULL, NULL, NULL));
  53307. BIO_free(bio);
  53308. bio = NULL;
  53309. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) */
  53310. return EXPECT_RESULT();
  53311. }
  53312. static int test_wolfSSL_PEM_PUBKEY(void)
  53313. {
  53314. EXPECT_DECLS;
  53315. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  53316. BIO* bio = NULL;
  53317. EVP_PKEY* pkey = NULL;
  53318. /* test creating new EVP_PKEY with bad arg */
  53319. ExpectNull((pkey = PEM_read_bio_PUBKEY(NULL, NULL, NULL, NULL)));
  53320. /* test loading ECC key using BIO */
  53321. #if defined(HAVE_ECC) && !defined(NO_FILESYSTEM)
  53322. {
  53323. XFILE file = XBADFILE;
  53324. const char* fname = "./certs/ecc-client-keyPub.pem";
  53325. size_t sz = 0;
  53326. byte* buf = NULL;
  53327. EVP_PKEY* pkey2 = NULL;
  53328. EC_KEY* ec_key = NULL;
  53329. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  53330. ExpectIntEQ(XFSEEK(file, 0, XSEEK_END), 0);
  53331. ExpectIntGT(sz = XFTELL(file), 0);
  53332. ExpectIntEQ(XFSEEK(file, 0, XSEEK_SET), 0);
  53333. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  53334. if (buf != NULL) {
  53335. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  53336. }
  53337. if (file != XBADFILE) {
  53338. XFCLOSE(file);
  53339. }
  53340. /* Test using BIO new mem and loading PEM private key */
  53341. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  53342. ExpectNotNull((pkey = PEM_read_bio_PUBKEY(bio, NULL, NULL, NULL)));
  53343. BIO_free(bio);
  53344. bio = NULL;
  53345. EVP_PKEY_free(pkey);
  53346. pkey = NULL;
  53347. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  53348. ExpectNotNull(pkey = EVP_PKEY_new());
  53349. ExpectPtrEq(PEM_read_bio_PUBKEY(bio, &pkey, NULL, NULL), pkey);
  53350. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  53351. BIO_free(bio);
  53352. bio = NULL;
  53353. /* Qt unit test case*/
  53354. ExpectNotNull(pkey2 = EVP_PKEY_new());
  53355. ExpectNotNull(ec_key = EVP_PKEY_get1_EC_KEY(pkey));
  53356. ExpectIntEQ(EVP_PKEY_set1_EC_KEY(pkey2, ec_key), WOLFSSL_SUCCESS);
  53357. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  53358. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey2), 1/* match */);
  53359. #else
  53360. ExpectIntEQ(EVP_PKEY_cmp(pkey, pkey2), 0);
  53361. #endif
  53362. EC_KEY_free(ec_key);
  53363. EVP_PKEY_free(pkey2);
  53364. EVP_PKEY_free(pkey);
  53365. pkey = NULL;
  53366. }
  53367. #endif
  53368. (void)bio;
  53369. (void)pkey;
  53370. #endif
  53371. return EXPECT_RESULT();
  53372. }
  53373. #endif /* !NO_BIO */
  53374. static int test_DSA_do_sign_verify(void)
  53375. {
  53376. EXPECT_DECLS;
  53377. #if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  53378. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && \
  53379. !defined(NO_DSA)
  53380. unsigned char digest[WC_SHA_DIGEST_SIZE];
  53381. DSA_SIG* sig = NULL;
  53382. DSA* dsa = NULL;
  53383. word32 bytes;
  53384. byte sigBin[DSA_SIG_SIZE];
  53385. int dsacheck;
  53386. #ifdef USE_CERT_BUFFERS_1024
  53387. byte tmp[ONEK_BUF];
  53388. XMEMSET(tmp, 0, sizeof(tmp));
  53389. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  53390. bytes = sizeof_dsa_key_der_1024;
  53391. #elif defined(USE_CERT_BUFFERS_2048)
  53392. byte tmp[TWOK_BUF];
  53393. XMEMSET(tmp, 0, sizeof(tmp));
  53394. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  53395. bytes = sizeof_dsa_key_der_2048;
  53396. #else
  53397. byte tmp[TWOK_BUF];
  53398. XFILE fp = XBADFILE;
  53399. XMEMSET(tmp, 0, sizeof(tmp));
  53400. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb") != XBADFILE);
  53401. ExpectIntGT(bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), fp), 0);
  53402. if (fp != XBADFILE)
  53403. XFCLOSE(fp);
  53404. #endif /* END USE_CERT_BUFFERS_1024 */
  53405. XMEMSET(digest, 202, sizeof(digest));
  53406. ExpectNotNull(dsa = DSA_new());
  53407. ExpectIntEQ(DSA_LoadDer(dsa, tmp, (int)bytes), 1);
  53408. ExpectIntEQ(wolfSSL_DSA_do_sign(digest, sigBin, dsa), 1);
  53409. ExpectIntEQ(wolfSSL_DSA_do_verify(digest, sigBin, dsa, &dsacheck), 1);
  53410. ExpectNotNull(sig = DSA_do_sign(digest, WC_SHA_DIGEST_SIZE, dsa));
  53411. ExpectIntEQ(DSA_do_verify(digest, WC_SHA_DIGEST_SIZE, sig, dsa), 1);
  53412. DSA_SIG_free(sig);
  53413. DSA_free(dsa);
  53414. #endif
  53415. #endif /* !HAVE_SELFTEST && !HAVE_FIPS */
  53416. return EXPECT_RESULT();
  53417. }
  53418. static int test_wolfSSL_tmp_dh(void)
  53419. {
  53420. EXPECT_DECLS;
  53421. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  53422. !defined(NO_RSA) && !defined(NO_DH) && !defined(NO_BIO)
  53423. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  53424. byte buff[6000];
  53425. static const unsigned char p[] = {
  53426. 0xb0, 0xa1, 0x08, 0x06, 0x9c, 0x08, 0x13, 0xba,
  53427. 0x59, 0x06, 0x3c, 0xbc, 0x30, 0xd5, 0xf5, 0x00,
  53428. 0xc1, 0x4f, 0x44, 0xa7, 0xd6, 0xef, 0x4a, 0xc6,
  53429. 0x25, 0x27, 0x1c, 0xe8, 0xd2, 0x96, 0x53, 0x0a,
  53430. 0x5c, 0x91, 0xdd, 0xa2, 0xc2, 0x94, 0x84, 0xbf,
  53431. 0x7d, 0xb2, 0x44, 0x9f, 0x9b, 0xd2, 0xc1, 0x8a,
  53432. 0xc5, 0xbe, 0x72, 0x5c, 0xa7, 0xe7, 0x91, 0xe6,
  53433. 0xd4, 0x9f, 0x73, 0x07, 0x85, 0x5b, 0x66, 0x48,
  53434. 0xc7, 0x70, 0xfa, 0xb4, 0xee, 0x02, 0xc9, 0x3d,
  53435. 0x9a, 0x4a, 0xda, 0x3d, 0xc1, 0x46, 0x3e, 0x19,
  53436. 0x69, 0xd1, 0x17, 0x46, 0x07, 0xa3, 0x4d, 0x9f,
  53437. 0x2b, 0x96, 0x17, 0x39, 0x6d, 0x30, 0x8d, 0x2a,
  53438. 0xf3, 0x94, 0xd3, 0x75, 0xcf, 0xa0, 0x75, 0xe6,
  53439. 0xf2, 0x92, 0x1f, 0x1a, 0x70, 0x05, 0xaa, 0x04,
  53440. 0x83, 0x57, 0x30, 0xfb, 0xda, 0x76, 0x93, 0x38,
  53441. 0x50, 0xe8, 0x27, 0xfd, 0x63, 0xee, 0x3c, 0xe5,
  53442. 0xb7, 0xc8, 0x09, 0xae, 0x6f, 0x50, 0x35, 0x8e,
  53443. 0x84, 0xce, 0x4a, 0x00, 0xe9, 0x12, 0x7e, 0x5a,
  53444. 0x31, 0xd7, 0x33, 0xfc, 0x21, 0x13, 0x76, 0xcc,
  53445. 0x16, 0x30, 0xdb, 0x0c, 0xfc, 0xc5, 0x62, 0xa7,
  53446. 0x35, 0xb8, 0xef, 0xb7, 0xb0, 0xac, 0xc0, 0x36,
  53447. 0xf6, 0xd9, 0xc9, 0x46, 0x48, 0xf9, 0x40, 0x90,
  53448. 0x00, 0x2b, 0x1b, 0xaa, 0x6c, 0xe3, 0x1a, 0xc3,
  53449. 0x0b, 0x03, 0x9e, 0x1b, 0xc2, 0x46, 0xe4, 0x48,
  53450. 0x4e, 0x22, 0x73, 0x6f, 0xc3, 0x5f, 0xd4, 0x9a,
  53451. 0xd6, 0x30, 0x07, 0x48, 0xd6, 0x8c, 0x90, 0xab,
  53452. 0xd4, 0xf6, 0xf1, 0xe3, 0x48, 0xd3, 0x58, 0x4b,
  53453. 0xa6, 0xb9, 0xcd, 0x29, 0xbf, 0x68, 0x1f, 0x08,
  53454. 0x4b, 0x63, 0x86, 0x2f, 0x5c, 0x6b, 0xd6, 0xb6,
  53455. 0x06, 0x65, 0xf7, 0xa6, 0xdc, 0x00, 0x67, 0x6b,
  53456. 0xbb, 0xc3, 0xa9, 0x41, 0x83, 0xfb, 0xc7, 0xfa,
  53457. 0xc8, 0xe2, 0x1e, 0x7e, 0xaf, 0x00, 0x3f, 0x93
  53458. };
  53459. int pSz = (int)sizeof(p);
  53460. #if !defined(WOLFSSL_OLD_PRIME_CHECK) && !defined(HAVE_FIPS) && \
  53461. !defined(HAVE_SELFTEST)
  53462. static const unsigned char bad_p[] = {
  53463. 0xb0, 0xa1, 0x08, 0x06, 0x9c, 0x08, 0x13, 0xba,
  53464. 0x59, 0x06, 0x3c, 0xbc, 0x30, 0xd5, 0xf5, 0x00,
  53465. 0xc1, 0x4f, 0x44, 0xa7, 0xd6, 0xef, 0x4a, 0xc6,
  53466. 0x25, 0x27, 0x1c, 0xe8, 0xd2, 0x96, 0x53, 0x0a,
  53467. 0x5c, 0x91, 0xdd, 0xa2, 0xc2, 0x94, 0x84, 0xbf,
  53468. 0x7d, 0xb2, 0x44, 0x9f, 0x9b, 0xd2, 0xc1, 0x8a,
  53469. 0xc5, 0xbe, 0x72, 0x5c, 0xa7, 0xe7, 0x91, 0xe6,
  53470. 0xd4, 0x9f, 0x73, 0x07, 0x85, 0x5b, 0x66, 0x48,
  53471. 0xc7, 0x70, 0xfa, 0xb4, 0xee, 0x02, 0xc9, 0x3d,
  53472. 0x9a, 0x4a, 0xda, 0x3d, 0xc1, 0x46, 0x3e, 0x19,
  53473. 0x69, 0xd1, 0x17, 0x46, 0x07, 0xa3, 0x4d, 0x9f,
  53474. 0x2b, 0x96, 0x17, 0x39, 0x6d, 0x30, 0x8d, 0x2a,
  53475. 0xf3, 0x94, 0xd3, 0x75, 0xcf, 0xa0, 0x75, 0xe6,
  53476. 0xf2, 0x92, 0x1f, 0x1a, 0x70, 0x05, 0xaa, 0x04,
  53477. 0x83, 0x57, 0x30, 0xfb, 0xda, 0x76, 0x93, 0x38,
  53478. 0x50, 0xe8, 0x27, 0xfd, 0x63, 0xee, 0x3c, 0xe5,
  53479. 0xb7, 0xc8, 0x09, 0xae, 0x6f, 0x50, 0x35, 0x8e,
  53480. 0x84, 0xce, 0x4a, 0x00, 0xe9, 0x12, 0x7e, 0x5a,
  53481. 0x31, 0xd7, 0x33, 0xfc, 0x21, 0x13, 0x76, 0xcc,
  53482. 0x16, 0x30, 0xdb, 0x0c, 0xfc, 0xc5, 0x62, 0xa7,
  53483. 0x35, 0xb8, 0xef, 0xb7, 0xb0, 0xac, 0xc0, 0x36,
  53484. 0xf6, 0xd9, 0xc9, 0x46, 0x48, 0xf9, 0x40, 0x90,
  53485. 0x00, 0x2b, 0x1b, 0xaa, 0x6c, 0xe3, 0x1a, 0xc3,
  53486. 0x0b, 0x03, 0x9e, 0x1b, 0xc2, 0x46, 0xe4, 0x48,
  53487. 0x4e, 0x22, 0x73, 0x6f, 0xc3, 0x5f, 0xd4, 0x9a,
  53488. 0xd6, 0x30, 0x07, 0x48, 0xd6, 0x8c, 0x90, 0xab,
  53489. 0xd4, 0xf6, 0xf1, 0xe3, 0x48, 0xd3, 0x58, 0x4b,
  53490. 0xa6, 0xb9, 0xcd, 0x29, 0xbf, 0x68, 0x1f, 0x08,
  53491. 0x4b, 0x63, 0x86, 0x2f, 0x5c, 0x6b, 0xd6, 0xb6,
  53492. 0x06, 0x65, 0xf7, 0xa6, 0xdc, 0x00, 0x67, 0x6b,
  53493. 0xbb, 0xc3, 0xa9, 0x41, 0x83, 0xfb, 0xc7, 0xfa,
  53494. 0xc8, 0xe2, 0x1e, 0x7e, 0xaf, 0x00, 0x3f, 0x91
  53495. };
  53496. #endif
  53497. static const unsigned char g[] = { 0x02 };
  53498. int gSz = (int)sizeof(g);
  53499. #if !defined(NO_DSA)
  53500. char file[] = "./certs/dsaparams.pem";
  53501. DSA* dsa = NULL;
  53502. #else
  53503. char file[] = "./certs/dh2048.pem";
  53504. #endif
  53505. XFILE f = XBADFILE;
  53506. int bytes = 0;
  53507. DH* dh = NULL;
  53508. DH* dh2 = NULL;
  53509. BIO* bio = NULL;
  53510. SSL* ssl = NULL;
  53511. SSL_CTX* ctx = NULL;
  53512. #ifndef NO_WOLFSSL_CLIENT
  53513. SSL* ssl_c = NULL;
  53514. SSL_CTX* ctx_c = NULL;
  53515. #endif
  53516. #ifndef NO_WOLFSSL_SERVER
  53517. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  53518. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  53519. WOLFSSL_FILETYPE_PEM));
  53520. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  53521. WOLFSSL_FILETYPE_PEM));
  53522. ExpectNotNull(ssl = SSL_new(ctx));
  53523. #endif
  53524. #ifndef NO_WOLFSSL_CLIENT
  53525. ExpectNotNull(ctx_c = SSL_CTX_new(wolfSSLv23_client_method()));
  53526. ExpectTrue(SSL_CTX_use_certificate_file(ctx_c, svrCertFile,
  53527. WOLFSSL_FILETYPE_PEM));
  53528. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx_c, svrKeyFile,
  53529. WOLFSSL_FILETYPE_PEM));
  53530. ExpectNotNull(ssl_c = SSL_new(ctx_c));
  53531. #ifdef NO_WOLFSSL_SERVER
  53532. ctx = ctx_c;
  53533. ssl = ssl_c;
  53534. #endif
  53535. #endif
  53536. XMEMSET(buff, 0, sizeof(buff));
  53537. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  53538. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  53539. if (f != XBADFILE)
  53540. XFCLOSE(f);
  53541. ExpectNotNull(bio = BIO_new_mem_buf((void*)buff, bytes));
  53542. #if !defined(NO_DSA)
  53543. dsa = wolfSSL_PEM_read_bio_DSAparams(bio, NULL, NULL, NULL);
  53544. ExpectNotNull(dsa);
  53545. dh = wolfSSL_DSA_dup_DH(dsa);
  53546. #else
  53547. dh = wolfSSL_PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
  53548. #endif
  53549. ExpectNotNull(dh);
  53550. #if defined(WOLFSSL_DH_EXTRA) && \
  53551. (defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || defined(WOLFSSL_OPENSSH))
  53552. ExpectNotNull(dh2 = wolfSSL_DH_dup(dh));
  53553. DH_free(dh2);
  53554. dh2 = NULL;
  53555. #endif
  53556. /* Failure cases */
  53557. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(NULL, NULL, 0, NULL, 0),
  53558. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  53559. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx , NULL, 0, NULL, 0),
  53560. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  53561. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(NULL, p , 0, NULL, 0),
  53562. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  53563. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(NULL, NULL, 0, g , 0),
  53564. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  53565. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx , p , 0, NULL, 0),
  53566. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  53567. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx , NULL, 0, g , 0),
  53568. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  53569. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(NULL, p , 0, g , 0),
  53570. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  53571. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx , p , 1, g , 1),
  53572. WC_NO_ERR_TRACE(DH_KEY_SIZE_E));
  53573. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx , buff, 6000, g , 1),
  53574. WC_NO_ERR_TRACE(DH_KEY_SIZE_E));
  53575. #if !defined(WOLFSSL_OLD_PRIME_CHECK) && !defined(HAVE_FIPS) && \
  53576. !defined(HAVE_SELFTEST)
  53577. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx, bad_p, pSz, g, gSz),
  53578. WC_NO_ERR_TRACE(DH_CHECK_PUB_E));
  53579. #endif
  53580. ExpectIntEQ((int)wolfSSL_SetTmpDH(NULL, NULL, 0, NULL, 0),
  53581. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53582. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl , NULL, 0, NULL, 0),
  53583. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53584. ExpectIntEQ((int)wolfSSL_SetTmpDH(NULL, p , 0, NULL, 0),
  53585. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53586. ExpectIntEQ((int)wolfSSL_SetTmpDH(NULL, NULL, 0, g , 0),
  53587. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53588. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl , p , 0, NULL, 0),
  53589. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53590. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl , NULL, 0, g , 0),
  53591. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53592. ExpectIntEQ((int)wolfSSL_SetTmpDH(NULL, p , 0, g , 0),
  53593. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  53594. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl , p , 1, g , 1),
  53595. WC_NO_ERR_TRACE(DH_KEY_SIZE_E));
  53596. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl , buff, 6000, g , 1),
  53597. WC_NO_ERR_TRACE(DH_KEY_SIZE_E));
  53598. #if !defined(WOLFSSL_OLD_PRIME_CHECK) && !defined(HAVE_FIPS) && \
  53599. !defined(HAVE_SELFTEST)
  53600. #ifndef NO_WOLFSSL_SERVER
  53601. /* Parameters will be tested later so it passes now. */
  53602. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl, bad_p, pSz, g, gSz),
  53603. WOLFSSL_SUCCESS);
  53604. #endif
  53605. #endif
  53606. #ifndef NO_WOLFSSL_CLIENT
  53607. ExpectIntEQ((int)wolfSSL_SetTmpDH(ssl_c, p, pSz, g, gSz),
  53608. WC_NO_ERR_TRACE(SIDE_ERROR));
  53609. #endif
  53610. ExpectIntEQ((int)SSL_CTX_set_tmp_dh(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  53611. ExpectIntEQ((int)SSL_CTX_set_tmp_dh(ctx , NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  53612. ExpectIntEQ((int)SSL_CTX_set_tmp_dh(NULL, dh ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  53613. ExpectIntEQ((int)SSL_set_tmp_dh(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  53614. ExpectIntEQ((int)SSL_set_tmp_dh(ssl , NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  53615. ExpectIntEQ((int)SSL_set_tmp_dh(NULL, dh ), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  53616. /* No p/g to use. */
  53617. dh2 = wolfSSL_DH_new();
  53618. ExpectIntEQ((int)SSL_CTX_set_tmp_dh(ctx , dh2 ), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  53619. ExpectIntEQ((int)SSL_set_tmp_dh(ssl , dh2 ), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  53620. DH_free(dh2);
  53621. dh2 = NULL;
  53622. ExpectIntEQ((int)wolfSSL_CTX_SetTmpDH(ctx, p, pSz, g, gSz),
  53623. WOLFSSL_SUCCESS);
  53624. ExpectIntEQ((int)SSL_CTX_set_tmp_dh(ctx, dh), WOLFSSL_SUCCESS);
  53625. #ifndef NO_WOLFSSL_SERVER
  53626. ExpectIntEQ((int)SSL_set_tmp_dh(ssl, dh), WOLFSSL_SUCCESS);
  53627. #else
  53628. ExpectIntEQ((int)SSL_set_tmp_dh(ssl, dh), WC_NO_ERR_TRACE(SIDE_ERROR));
  53629. #endif
  53630. BIO_free(bio);
  53631. #if !defined(NO_DSA)
  53632. DSA_free(dsa);
  53633. #endif
  53634. DH_free(dh);
  53635. dh = NULL;
  53636. #ifndef NO_WOLFSSL_CLIENT
  53637. if (ssl != ssl_c) {
  53638. SSL_free(ssl_c);
  53639. }
  53640. #endif
  53641. SSL_free(ssl);
  53642. #ifndef NO_WOLFSSL_CLIENT
  53643. if (ctx != ctx_c) {
  53644. SSL_CTX_free(ctx_c);
  53645. }
  53646. #endif
  53647. SSL_CTX_free(ctx);
  53648. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  53649. #endif
  53650. return EXPECT_RESULT();
  53651. }
  53652. static int test_wolfSSL_ctrl(void)
  53653. {
  53654. EXPECT_DECLS;
  53655. #if defined (OPENSSL_EXTRA) && !defined(NO_BIO)
  53656. byte buff[6000];
  53657. BIO* bio = NULL;
  53658. int bytes;
  53659. BUF_MEM* ptr = NULL;
  53660. XMEMSET(buff, 0, sizeof(buff));
  53661. bytes = sizeof(buff);
  53662. ExpectNotNull(bio = BIO_new_mem_buf((void*)buff, bytes));
  53663. ExpectNotNull(BIO_s_socket());
  53664. ExpectIntEQ((int)wolfSSL_BIO_get_mem_ptr(bio, &ptr), WOLFSSL_SUCCESS);
  53665. /* needs tested after stubs filled out @TODO
  53666. SSL_ctrl
  53667. SSL_CTX_ctrl
  53668. */
  53669. BIO_free(bio);
  53670. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_BIO) */
  53671. return EXPECT_RESULT();
  53672. }
  53673. static int test_wolfSSL_EVP_PKEY_new_mac_key(void)
  53674. {
  53675. EXPECT_DECLS;
  53676. #ifdef OPENSSL_EXTRA
  53677. static const unsigned char pw[] = "password";
  53678. static const int pwSz = sizeof(pw) - 1;
  53679. size_t checkPwSz = 0;
  53680. const unsigned char* checkPw = NULL;
  53681. WOLFSSL_EVP_PKEY* key = NULL;
  53682. ExpectNull(key = wolfSSL_EVP_PKEY_new_mac_key(0, NULL, pw, pwSz));
  53683. ExpectNull(key = wolfSSL_EVP_PKEY_new_mac_key(0, NULL, NULL, pwSz));
  53684. ExpectNotNull(key = wolfSSL_EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, pw,
  53685. pwSz));
  53686. if (key != NULL) {
  53687. ExpectIntEQ(key->type, EVP_PKEY_HMAC);
  53688. ExpectIntEQ(key->save_type, EVP_PKEY_HMAC);
  53689. ExpectIntEQ(key->pkey_sz, pwSz);
  53690. ExpectIntEQ(XMEMCMP(key->pkey.ptr, pw, pwSz), 0);
  53691. }
  53692. ExpectNotNull(checkPw = wolfSSL_EVP_PKEY_get0_hmac(key, &checkPwSz));
  53693. ExpectIntEQ((int)checkPwSz, pwSz);
  53694. ExpectIntEQ(XMEMCMP(checkPw, pw, pwSz), 0);
  53695. wolfSSL_EVP_PKEY_free(key);
  53696. key = NULL;
  53697. ExpectNotNull(key = wolfSSL_EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, pw,
  53698. 0));
  53699. ExpectIntEQ(key->pkey_sz, 0);
  53700. if (EXPECT_SUCCESS()) {
  53701. /* Allocation for key->pkey.ptr may fail - OK key len is 0 */
  53702. checkPw = wolfSSL_EVP_PKEY_get0_hmac(key, &checkPwSz);
  53703. }
  53704. ExpectTrue((checkPwSz == 0) || (checkPw != NULL));
  53705. ExpectIntEQ((int)checkPwSz, 0);
  53706. wolfSSL_EVP_PKEY_free(key);
  53707. key = NULL;
  53708. ExpectNotNull(key = wolfSSL_EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, NULL,
  53709. 0));
  53710. ExpectIntEQ(key->pkey_sz, 0);
  53711. if (EXPECT_SUCCESS()) {
  53712. /* Allocation for key->pkey.ptr may fail - OK key len is 0 */
  53713. checkPw = wolfSSL_EVP_PKEY_get0_hmac(key, &checkPwSz);
  53714. }
  53715. ExpectTrue((checkPwSz == 0) || (checkPw != NULL));
  53716. ExpectIntEQ((int)checkPwSz, 0);
  53717. wolfSSL_EVP_PKEY_free(key);
  53718. key = NULL;
  53719. #endif /* OPENSSL_EXTRA */
  53720. return EXPECT_RESULT();
  53721. }
  53722. static int test_wolfSSL_EVP_PKEY_new_CMAC_key(void)
  53723. {
  53724. EXPECT_DECLS;
  53725. #ifdef OPENSSL_EXTRA
  53726. #if defined(WOLFSSL_CMAC) && !defined(NO_AES) && defined(WOLFSSL_AES_DIRECT)
  53727. const char *priv = "ABCDEFGHIJKLMNOP";
  53728. const WOLFSSL_EVP_CIPHER* cipher = EVP_aes_128_cbc();
  53729. WOLFSSL_EVP_PKEY* key = NULL;
  53730. ExpectNull(key = wolfSSL_EVP_PKEY_new_CMAC_key(
  53731. NULL, NULL, AES_128_KEY_SIZE, cipher));
  53732. ExpectNull(key = wolfSSL_EVP_PKEY_new_CMAC_key(
  53733. NULL, (const unsigned char *)priv, 0, cipher));
  53734. ExpectNull(key = wolfSSL_EVP_PKEY_new_CMAC_key(
  53735. NULL, (const unsigned char *)priv, AES_128_KEY_SIZE, NULL));
  53736. ExpectNotNull(key = wolfSSL_EVP_PKEY_new_CMAC_key(
  53737. NULL, (const unsigned char *)priv, AES_128_KEY_SIZE, cipher));
  53738. wolfSSL_EVP_PKEY_free(key);
  53739. #endif /* WOLFSSL_CMAC && !NO_AES && WOLFSSL_AES_DIRECT */
  53740. #endif /* OPENSSL_EXTRA */
  53741. return EXPECT_RESULT();
  53742. }
  53743. static int test_wolfSSL_EVP_Digest(void)
  53744. {
  53745. EXPECT_DECLS;
  53746. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA256) && !defined(NO_PWDBASED)
  53747. const char* in = "abc";
  53748. int inLen = (int)XSTRLEN(in);
  53749. byte out[WC_SHA256_DIGEST_SIZE];
  53750. unsigned int outLen;
  53751. const char* expOut =
  53752. "\xBA\x78\x16\xBF\x8F\x01\xCF\xEA\x41\x41\x40\xDE\x5D\xAE\x22"
  53753. "\x23\xB0\x03\x61\xA3\x96\x17\x7A\x9C\xB4\x10\xFF\x61\xF2\x00"
  53754. "\x15\xAD";
  53755. ExpectIntEQ(wolfSSL_EVP_Digest((unsigned char*)in, inLen, out, &outLen,
  53756. "SHA256", NULL), 1);
  53757. ExpectIntEQ(outLen, WC_SHA256_DIGEST_SIZE);
  53758. ExpectIntEQ(XMEMCMP(out, expOut, WC_SHA256_DIGEST_SIZE), 0);
  53759. #endif /* OPEN_EXTRA && ! NO_SHA256 */
  53760. return EXPECT_RESULT();
  53761. }
  53762. static int test_wolfSSL_EVP_Digest_all(void)
  53763. {
  53764. EXPECT_DECLS;
  53765. #ifdef OPENSSL_EXTRA
  53766. const char* digests[] = {
  53767. #ifndef NO_MD5
  53768. "MD5",
  53769. #endif
  53770. #ifndef NO_SHA
  53771. "SHA",
  53772. #endif
  53773. #ifdef WOLFSSL_SHA224
  53774. "SHA224",
  53775. #endif
  53776. #ifndef NO_SHA256
  53777. "SHA256",
  53778. #endif
  53779. #ifdef WOLFSSL_SHA384
  53780. "SHA384",
  53781. #endif
  53782. #ifdef WOLFSSL_SHA512
  53783. "SHA512",
  53784. #endif
  53785. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
  53786. "SHA512_224",
  53787. #endif
  53788. #if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
  53789. "SHA512_256",
  53790. #endif
  53791. #ifdef WOLFSSL_SHA3
  53792. #ifndef WOLFSSL_NOSHA3_224
  53793. "SHA3_224",
  53794. #endif
  53795. #ifndef WOLFSSL_NOSHA3_256
  53796. "SHA3_256",
  53797. #endif
  53798. "SHA3_384",
  53799. #ifndef WOLFSSL_NOSHA3_512
  53800. "SHA3_512",
  53801. #endif
  53802. #endif /* WOLFSSL_SHA3 */
  53803. NULL
  53804. };
  53805. const char** d;
  53806. const unsigned char in[] = "abc";
  53807. int inLen = XSTR_SIZEOF(in);
  53808. byte out[WC_MAX_DIGEST_SIZE];
  53809. unsigned int outLen;
  53810. for (d = digests; *d != NULL; d++) {
  53811. ExpectIntEQ(EVP_Digest(in, inLen, out, &outLen, *d, NULL), 1);
  53812. ExpectIntGT(outLen, 0);
  53813. ExpectIntEQ(EVP_MD_size(*d), outLen);
  53814. }
  53815. #endif
  53816. return EXPECT_RESULT();
  53817. }
  53818. static int test_wolfSSL_EVP_MD_size(void)
  53819. {
  53820. EXPECT_DECLS;
  53821. #ifdef OPENSSL_EXTRA
  53822. WOLFSSL_EVP_MD_CTX mdCtx;
  53823. #ifdef WOLFSSL_SHA3
  53824. #ifndef WOLFSSL_NOSHA3_224
  53825. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53826. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA3_224"), 1);
  53827. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA3_224_DIGEST_SIZE);
  53828. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA3_224_BLOCK_SIZE);
  53829. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53830. #endif
  53831. #ifndef WOLFSSL_NOSHA3_256
  53832. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53833. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA3_256"), 1);
  53834. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA3_256_DIGEST_SIZE);
  53835. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA3_256_BLOCK_SIZE);
  53836. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53837. #endif
  53838. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53839. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA3_384"), 1);
  53840. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA3_384_DIGEST_SIZE);
  53841. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA3_384_BLOCK_SIZE);
  53842. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53843. #ifndef WOLFSSL_NOSHA3_512
  53844. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53845. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA3_512"), 1);
  53846. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA3_512_DIGEST_SIZE);
  53847. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA3_512_BLOCK_SIZE);
  53848. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53849. #endif
  53850. #endif /* WOLFSSL_SHA3 */
  53851. #ifndef NO_SHA256
  53852. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53853. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA256"), 1);
  53854. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  53855. WC_SHA256_DIGEST_SIZE);
  53856. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  53857. WC_SHA256_BLOCK_SIZE);
  53858. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA256_DIGEST_SIZE);
  53859. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA256_BLOCK_SIZE);
  53860. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53861. #endif
  53862. #ifndef NO_MD5
  53863. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53864. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "MD5"), 1);
  53865. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  53866. WC_MD5_DIGEST_SIZE);
  53867. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  53868. WC_MD5_BLOCK_SIZE);
  53869. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_MD5_DIGEST_SIZE);
  53870. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_MD5_BLOCK_SIZE);
  53871. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53872. #endif
  53873. #ifdef WOLFSSL_SHA224
  53874. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53875. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA224"), 1);
  53876. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  53877. WC_SHA224_DIGEST_SIZE);
  53878. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  53879. WC_SHA224_BLOCK_SIZE);
  53880. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA224_DIGEST_SIZE);
  53881. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA224_BLOCK_SIZE);
  53882. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53883. #endif
  53884. #ifdef WOLFSSL_SHA384
  53885. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53886. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA384"), 1);
  53887. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  53888. WC_SHA384_DIGEST_SIZE);
  53889. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  53890. WC_SHA384_BLOCK_SIZE);
  53891. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA384_DIGEST_SIZE);
  53892. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA384_BLOCK_SIZE);
  53893. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53894. #endif
  53895. #ifdef WOLFSSL_SHA512
  53896. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53897. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA512"), 1);
  53898. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  53899. WC_SHA512_DIGEST_SIZE);
  53900. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  53901. WC_SHA512_BLOCK_SIZE);
  53902. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA512_DIGEST_SIZE);
  53903. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA512_BLOCK_SIZE);
  53904. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53905. #endif
  53906. #ifndef NO_SHA
  53907. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53908. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA"), 1);
  53909. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  53910. WC_SHA_DIGEST_SIZE);
  53911. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  53912. WC_SHA_BLOCK_SIZE);
  53913. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA_DIGEST_SIZE);
  53914. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA_BLOCK_SIZE);
  53915. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53916. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53917. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA1"), 1);
  53918. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  53919. WC_SHA_DIGEST_SIZE);
  53920. ExpectIntEQ(wolfSSL_EVP_MD_block_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)),
  53921. WC_SHA_BLOCK_SIZE);
  53922. ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA_DIGEST_SIZE);
  53923. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA_BLOCK_SIZE);
  53924. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53925. #endif
  53926. /* error case */
  53927. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53928. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, ""), 0);
  53929. ExpectIntEQ(wolfSSL_EVP_MD_size(wolfSSL_EVP_MD_CTX_md(&mdCtx)), 0);
  53930. ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), 0);
  53931. /* Cleanup is valid on uninit'ed struct */
  53932. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53933. #endif /* OPENSSL_EXTRA */
  53934. return EXPECT_RESULT();
  53935. }
  53936. static int test_wolfSSL_EVP_MD_pkey_type(void)
  53937. {
  53938. EXPECT_DECLS;
  53939. #ifdef OPENSSL_EXTRA
  53940. const WOLFSSL_EVP_MD* md;
  53941. #ifndef NO_MD5
  53942. ExpectNotNull(md = EVP_md5());
  53943. ExpectIntEQ(EVP_MD_pkey_type(md), NID_md5WithRSAEncryption);
  53944. #endif
  53945. #ifndef NO_SHA
  53946. ExpectNotNull(md = EVP_sha1());
  53947. ExpectIntEQ(EVP_MD_pkey_type(md), NID_sha1WithRSAEncryption);
  53948. #endif
  53949. #ifdef WOLFSSL_SHA224
  53950. ExpectNotNull(md = EVP_sha224());
  53951. ExpectIntEQ(EVP_MD_pkey_type(md), NID_sha224WithRSAEncryption);
  53952. #endif
  53953. ExpectNotNull(md = EVP_sha256());
  53954. ExpectIntEQ(EVP_MD_pkey_type(md), NID_sha256WithRSAEncryption);
  53955. #ifdef WOLFSSL_SHA384
  53956. ExpectNotNull(md = EVP_sha384());
  53957. ExpectIntEQ(EVP_MD_pkey_type(md), NID_sha384WithRSAEncryption);
  53958. #endif
  53959. #ifdef WOLFSSL_SHA512
  53960. ExpectNotNull(md = EVP_sha512());
  53961. ExpectIntEQ(EVP_MD_pkey_type(md), NID_sha512WithRSAEncryption);
  53962. #endif
  53963. #endif
  53964. return EXPECT_RESULT();
  53965. }
  53966. #ifdef OPENSSL_EXTRA
  53967. static int test_hmac_signing(const WOLFSSL_EVP_MD *type, const byte* testKey,
  53968. size_t testKeySz, const char* testData, size_t testDataSz,
  53969. const byte* testResult, size_t testResultSz)
  53970. {
  53971. EXPECT_DECLS;
  53972. unsigned char check[WC_MAX_DIGEST_SIZE];
  53973. size_t checkSz = -1;
  53974. WOLFSSL_EVP_PKEY* key = NULL;
  53975. WOLFSSL_EVP_MD_CTX mdCtx;
  53976. ExpectNotNull(key = wolfSSL_EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL,
  53977. testKey, (int)testKeySz));
  53978. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53979. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, type, NULL, key), 1);
  53980. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData,
  53981. (unsigned int)testDataSz), 1);
  53982. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  53983. ExpectIntEQ((int)checkSz, (int)testResultSz);
  53984. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  53985. ExpectIntEQ((int)checkSz,(int)testResultSz);
  53986. ExpectIntEQ(XMEMCMP(testResult, check, testResultSz), 0);
  53987. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53988. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, type, NULL, key), 1);
  53989. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData,
  53990. (unsigned int)testDataSz), 1);
  53991. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, testResult, checkSz), 1);
  53992. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  53993. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  53994. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, type, NULL, key), 1);
  53995. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData, 4), 1);
  53996. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  53997. ExpectIntEQ((int)checkSz, (int)testResultSz);
  53998. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  53999. ExpectIntEQ((int)checkSz,(int)testResultSz);
  54000. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData + 4,
  54001. (unsigned int)testDataSz - 4), 1);
  54002. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  54003. ExpectIntEQ((int)checkSz,(int)testResultSz);
  54004. ExpectIntEQ(XMEMCMP(testResult, check, testResultSz), 0);
  54005. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  54006. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, type, NULL, key), 1);
  54007. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData, 4), 1);
  54008. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData + 4,
  54009. (unsigned int)testDataSz - 4), 1);
  54010. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, testResult, checkSz), 1);
  54011. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  54012. wolfSSL_EVP_PKEY_free(key);
  54013. return EXPECT_RESULT();
  54014. }
  54015. #endif
  54016. static int test_wolfSSL_EVP_MD_hmac_signing(void)
  54017. {
  54018. EXPECT_DECLS;
  54019. #ifdef OPENSSL_EXTRA
  54020. static const unsigned char testKey[] =
  54021. {
  54022. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  54023. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  54024. 0x0b, 0x0b, 0x0b, 0x0b
  54025. };
  54026. static const char testData[] = "Hi There";
  54027. #ifdef WOLFSSL_SHA224
  54028. static const unsigned char testResultSha224[] =
  54029. {
  54030. 0x89, 0x6f, 0xb1, 0x12, 0x8a, 0xbb, 0xdf, 0x19,
  54031. 0x68, 0x32, 0x10, 0x7c, 0xd4, 0x9d, 0xf3, 0x3f,
  54032. 0x47, 0xb4, 0xb1, 0x16, 0x99, 0x12, 0xba, 0x4f,
  54033. 0x53, 0x68, 0x4b, 0x22
  54034. };
  54035. #endif
  54036. #ifndef NO_SHA256
  54037. static const unsigned char testResultSha256[] =
  54038. {
  54039. 0xb0, 0x34, 0x4c, 0x61, 0xd8, 0xdb, 0x38, 0x53,
  54040. 0x5c, 0xa8, 0xaf, 0xce, 0xaf, 0x0b, 0xf1, 0x2b,
  54041. 0x88, 0x1d, 0xc2, 0x00, 0xc9, 0x83, 0x3d, 0xa7,
  54042. 0x26, 0xe9, 0x37, 0x6c, 0x2e, 0x32, 0xcf, 0xf7
  54043. };
  54044. #endif
  54045. #ifdef WOLFSSL_SHA384
  54046. static const unsigned char testResultSha384[] =
  54047. {
  54048. 0xaf, 0xd0, 0x39, 0x44, 0xd8, 0x48, 0x95, 0x62,
  54049. 0x6b, 0x08, 0x25, 0xf4, 0xab, 0x46, 0x90, 0x7f,
  54050. 0x15, 0xf9, 0xda, 0xdb, 0xe4, 0x10, 0x1e, 0xc6,
  54051. 0x82, 0xaa, 0x03, 0x4c, 0x7c, 0xeb, 0xc5, 0x9c,
  54052. 0xfa, 0xea, 0x9e, 0xa9, 0x07, 0x6e, 0xde, 0x7f,
  54053. 0x4a, 0xf1, 0x52, 0xe8, 0xb2, 0xfa, 0x9c, 0xb6
  54054. };
  54055. #endif
  54056. #ifdef WOLFSSL_SHA512
  54057. static const unsigned char testResultSha512[] =
  54058. {
  54059. 0x87, 0xaa, 0x7c, 0xde, 0xa5, 0xef, 0x61, 0x9d,
  54060. 0x4f, 0xf0, 0xb4, 0x24, 0x1a, 0x1d, 0x6c, 0xb0,
  54061. 0x23, 0x79, 0xf4, 0xe2, 0xce, 0x4e, 0xc2, 0x78,
  54062. 0x7a, 0xd0, 0xb3, 0x05, 0x45, 0xe1, 0x7c, 0xde,
  54063. 0xda, 0xa8, 0x33, 0xb7, 0xd6, 0xb8, 0xa7, 0x02,
  54064. 0x03, 0x8b, 0x27, 0x4e, 0xae, 0xa3, 0xf4, 0xe4,
  54065. 0xbe, 0x9d, 0x91, 0x4e, 0xeb, 0x61, 0xf1, 0x70,
  54066. 0x2e, 0x69, 0x6c, 0x20, 0x3a, 0x12, 0x68, 0x54
  54067. };
  54068. #endif
  54069. #ifdef WOLFSSL_SHA3
  54070. #ifndef WOLFSSL_NOSHA3_224
  54071. static const unsigned char testResultSha3_224[] =
  54072. {
  54073. 0x3b, 0x16, 0x54, 0x6b, 0xbc, 0x7b, 0xe2, 0x70,
  54074. 0x6a, 0x03, 0x1d, 0xca, 0xfd, 0x56, 0x37, 0x3d,
  54075. 0x98, 0x84, 0x36, 0x76, 0x41, 0xd8, 0xc5, 0x9a,
  54076. 0xf3, 0xc8, 0x60, 0xf7
  54077. };
  54078. #endif
  54079. #ifndef WOLFSSL_NOSHA3_256
  54080. static const unsigned char testResultSha3_256[] =
  54081. {
  54082. 0xba, 0x85, 0x19, 0x23, 0x10, 0xdf, 0xfa, 0x96,
  54083. 0xe2, 0xa3, 0xa4, 0x0e, 0x69, 0x77, 0x43, 0x51,
  54084. 0x14, 0x0b, 0xb7, 0x18, 0x5e, 0x12, 0x02, 0xcd,
  54085. 0xcc, 0x91, 0x75, 0x89, 0xf9, 0x5e, 0x16, 0xbb
  54086. };
  54087. #endif
  54088. #ifndef WOLFSSL_NOSHA3_384
  54089. static const unsigned char testResultSha3_384[] =
  54090. {
  54091. 0x68, 0xd2, 0xdc, 0xf7, 0xfd, 0x4d, 0xdd, 0x0a,
  54092. 0x22, 0x40, 0xc8, 0xa4, 0x37, 0x30, 0x5f, 0x61,
  54093. 0xfb, 0x73, 0x34, 0xcf, 0xb5, 0xd0, 0x22, 0x6e,
  54094. 0x1b, 0xc2, 0x7d, 0xc1, 0x0a, 0x2e, 0x72, 0x3a,
  54095. 0x20, 0xd3, 0x70, 0xb4, 0x77, 0x43, 0x13, 0x0e,
  54096. 0x26, 0xac, 0x7e, 0x3d, 0x53, 0x28, 0x86, 0xbd
  54097. };
  54098. #endif
  54099. #ifndef WOLFSSL_NOSHA3_512
  54100. static const unsigned char testResultSha3_512[] =
  54101. {
  54102. 0xeb, 0x3f, 0xbd, 0x4b, 0x2e, 0xaa, 0xb8, 0xf5,
  54103. 0xc5, 0x04, 0xbd, 0x3a, 0x41, 0x46, 0x5a, 0xac,
  54104. 0xec, 0x15, 0x77, 0x0a, 0x7c, 0xab, 0xac, 0x53,
  54105. 0x1e, 0x48, 0x2f, 0x86, 0x0b, 0x5e, 0xc7, 0xba,
  54106. 0x47, 0xcc, 0xb2, 0xc6, 0xf2, 0xaf, 0xce, 0x8f,
  54107. 0x88, 0xd2, 0x2b, 0x6d, 0xc6, 0x13, 0x80, 0xf2,
  54108. 0x3a, 0x66, 0x8f, 0xd3, 0x88, 0x8b, 0xb8, 0x05,
  54109. 0x37, 0xc0, 0xa0, 0xb8, 0x64, 0x07, 0x68, 0x9e
  54110. };
  54111. #endif
  54112. #endif
  54113. #ifndef NO_SHA256
  54114. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha256(), testKey,
  54115. sizeof(testKey), testData, XSTRLEN(testData), testResultSha256,
  54116. sizeof(testResultSha256)), TEST_SUCCESS);
  54117. #endif
  54118. #ifdef WOLFSSL_SHA224
  54119. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha224(), testKey,
  54120. sizeof(testKey), testData, XSTRLEN(testData), testResultSha224,
  54121. sizeof(testResultSha224)), TEST_SUCCESS);
  54122. #endif
  54123. #ifdef WOLFSSL_SHA384
  54124. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha384(), testKey,
  54125. sizeof(testKey), testData, XSTRLEN(testData), testResultSha384,
  54126. sizeof(testResultSha384)), TEST_SUCCESS);
  54127. #endif
  54128. #ifdef WOLFSSL_SHA512
  54129. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha512(), testKey,
  54130. sizeof(testKey), testData, XSTRLEN(testData), testResultSha512,
  54131. sizeof(testResultSha512)), TEST_SUCCESS);
  54132. #endif
  54133. #ifdef WOLFSSL_SHA3
  54134. #ifndef WOLFSSL_NOSHA3_224
  54135. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha3_224(), testKey,
  54136. sizeof(testKey), testData, XSTRLEN(testData), testResultSha3_224,
  54137. sizeof(testResultSha3_224)), TEST_SUCCESS);
  54138. #endif
  54139. #ifndef WOLFSSL_NOSHA3_256
  54140. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha3_256(), testKey,
  54141. sizeof(testKey), testData, XSTRLEN(testData), testResultSha3_256,
  54142. sizeof(testResultSha3_256)), TEST_SUCCESS);
  54143. #endif
  54144. #ifndef WOLFSSL_NOSHA3_384
  54145. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha3_384(), testKey,
  54146. sizeof(testKey), testData, XSTRLEN(testData), testResultSha3_384,
  54147. sizeof(testResultSha3_384)), TEST_SUCCESS);
  54148. #endif
  54149. #ifndef WOLFSSL_NOSHA3_512
  54150. ExpectIntEQ(test_hmac_signing(wolfSSL_EVP_sha3_512(), testKey,
  54151. sizeof(testKey), testData, XSTRLEN(testData), testResultSha3_512,
  54152. sizeof(testResultSha3_512)), TEST_SUCCESS);
  54153. #endif
  54154. #endif
  54155. #endif /* OPENSSL_EXTRA */
  54156. return EXPECT_RESULT();
  54157. }
  54158. static int test_wolfSSL_EVP_MD_rsa_signing(void)
  54159. {
  54160. EXPECT_DECLS;
  54161. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(USE_CERT_BUFFERS_2048)
  54162. WOLFSSL_EVP_PKEY* privKey = NULL;
  54163. WOLFSSL_EVP_PKEY* pubKey = NULL;
  54164. WOLFSSL_EVP_PKEY_CTX* keyCtx = NULL;
  54165. const char testData[] = "Hi There";
  54166. WOLFSSL_EVP_MD_CTX mdCtx;
  54167. WOLFSSL_EVP_MD_CTX mdCtxCopy;
  54168. int ret;
  54169. size_t checkSz = -1;
  54170. int sz = 2048 / 8;
  54171. const unsigned char* cp;
  54172. const unsigned char* p;
  54173. unsigned char check[2048/8];
  54174. size_t i;
  54175. int paddings[] = {
  54176. RSA_PKCS1_PADDING,
  54177. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && defined(WC_RSA_PSS)
  54178. RSA_PKCS1_PSS_PADDING,
  54179. #endif
  54180. };
  54181. cp = client_key_der_2048;
  54182. ExpectNotNull((privKey = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, &cp,
  54183. sizeof_client_key_der_2048)));
  54184. p = client_keypub_der_2048;
  54185. ExpectNotNull((pubKey = wolfSSL_d2i_PUBKEY(NULL, &p,
  54186. sizeof_client_keypub_der_2048)));
  54187. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  54188. wolfSSL_EVP_MD_CTX_init(&mdCtxCopy);
  54189. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  54190. NULL, privKey), 1);
  54191. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData,
  54192. (unsigned int)XSTRLEN(testData)), 1);
  54193. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  54194. ExpectIntEQ((int)checkSz, sz);
  54195. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  54196. ExpectIntEQ((int)checkSz,sz);
  54197. ExpectIntEQ(wolfSSL_EVP_MD_CTX_copy_ex(&mdCtxCopy, &mdCtx), 1);
  54198. ExpectIntEQ(wolfSSL_EVP_MD_CTX_copy_ex(&mdCtxCopy, &mdCtx), 1);
  54199. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtxCopy);
  54200. ExpectIntEQ(ret, 1);
  54201. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  54202. ExpectIntEQ(ret, 1);
  54203. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  54204. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  54205. NULL, pubKey), 1);
  54206. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData,
  54207. (unsigned int)XSTRLEN(testData)),
  54208. 1);
  54209. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, check, checkSz), 1);
  54210. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  54211. ExpectIntEQ(ret, 1);
  54212. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  54213. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  54214. NULL, privKey), 1);
  54215. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData, 4), 1);
  54216. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  54217. ExpectIntEQ((int)checkSz, sz);
  54218. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  54219. ExpectIntEQ((int)checkSz, sz);
  54220. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData + 4,
  54221. (unsigned int)XSTRLEN(testData) - 4), 1);
  54222. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  54223. ExpectIntEQ((int)checkSz, sz);
  54224. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  54225. ExpectIntEQ(ret, 1);
  54226. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  54227. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  54228. NULL, pubKey), 1);
  54229. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData, 4), 1);
  54230. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData + 4,
  54231. (unsigned int)XSTRLEN(testData) - 4),
  54232. 1);
  54233. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, check, checkSz), 1);
  54234. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  54235. ExpectIntEQ(ret, 1);
  54236. /* Check all signing padding types */
  54237. for (i = 0; i < sizeof(paddings)/sizeof(int); i++) {
  54238. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  54239. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, &keyCtx,
  54240. wolfSSL_EVP_sha256(), NULL, privKey), 1);
  54241. ExpectIntEQ(wolfSSL_EVP_PKEY_CTX_set_rsa_padding(keyCtx,
  54242. paddings[i]), 1);
  54243. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData,
  54244. (unsigned int)XSTRLEN(testData)), 1);
  54245. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  54246. ExpectIntEQ((int)checkSz, sz);
  54247. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  54248. ExpectIntEQ((int)checkSz,sz);
  54249. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  54250. ExpectIntEQ(ret, 1);
  54251. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  54252. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, &keyCtx,
  54253. wolfSSL_EVP_sha256(), NULL, pubKey), 1);
  54254. ExpectIntEQ(wolfSSL_EVP_PKEY_CTX_set_rsa_padding(keyCtx,
  54255. paddings[i]), 1);
  54256. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData,
  54257. (unsigned int)XSTRLEN(testData)), 1);
  54258. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, check, checkSz), 1);
  54259. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  54260. ExpectIntEQ(ret, 1);
  54261. }
  54262. wolfSSL_EVP_PKEY_free(pubKey);
  54263. wolfSSL_EVP_PKEY_free(privKey);
  54264. #endif
  54265. return EXPECT_RESULT();
  54266. }
  54267. static int test_wolfSSL_EVP_MD_ecc_signing(void)
  54268. {
  54269. EXPECT_DECLS;
  54270. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  54271. WOLFSSL_EVP_PKEY* privKey = NULL;
  54272. WOLFSSL_EVP_PKEY* pubKey = NULL;
  54273. const char testData[] = "Hi There";
  54274. WOLFSSL_EVP_MD_CTX mdCtx;
  54275. int ret;
  54276. size_t checkSz = -1;
  54277. const unsigned char* cp;
  54278. const unsigned char* p;
  54279. unsigned char check[2048/8];
  54280. cp = ecc_clikey_der_256;
  54281. ExpectNotNull(privKey = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL, &cp,
  54282. sizeof_ecc_clikey_der_256));
  54283. p = ecc_clikeypub_der_256;
  54284. ExpectNotNull((pubKey = wolfSSL_d2i_PUBKEY(NULL, &p,
  54285. sizeof_ecc_clikeypub_der_256)));
  54286. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  54287. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  54288. NULL, privKey), 1);
  54289. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData,
  54290. (unsigned int)XSTRLEN(testData)), 1);
  54291. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  54292. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  54293. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  54294. ExpectIntEQ(ret, 1);
  54295. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  54296. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  54297. NULL, pubKey), 1);
  54298. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData,
  54299. (unsigned int)XSTRLEN(testData)),
  54300. 1);
  54301. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, check, checkSz), 1);
  54302. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  54303. ExpectIntEQ(ret, 1);
  54304. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  54305. ExpectIntEQ(wolfSSL_EVP_DigestSignInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  54306. NULL, privKey), 1);
  54307. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData, 4), 1);
  54308. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, NULL, &checkSz), 1);
  54309. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  54310. ExpectIntEQ(wolfSSL_EVP_DigestSignUpdate(&mdCtx, testData + 4,
  54311. (unsigned int)XSTRLEN(testData) - 4), 1);
  54312. ExpectIntEQ(wolfSSL_EVP_DigestSignFinal(&mdCtx, check, &checkSz), 1);
  54313. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  54314. ExpectIntEQ(ret, 1);
  54315. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  54316. ExpectIntEQ(wolfSSL_EVP_DigestVerifyInit(&mdCtx, NULL, wolfSSL_EVP_sha256(),
  54317. NULL, pubKey), 1);
  54318. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData, 4), 1);
  54319. ExpectIntEQ(wolfSSL_EVP_DigestVerifyUpdate(&mdCtx, testData + 4,
  54320. (unsigned int)XSTRLEN(testData) - 4),
  54321. 1);
  54322. ExpectIntEQ(wolfSSL_EVP_DigestVerifyFinal(&mdCtx, check, checkSz), 1);
  54323. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  54324. ExpectIntEQ(ret, 1);
  54325. wolfSSL_EVP_PKEY_free(pubKey);
  54326. wolfSSL_EVP_PKEY_free(privKey);
  54327. #endif
  54328. return EXPECT_RESULT();
  54329. }
  54330. static int test_wolfSSL_CTX_add_extra_chain_cert(void)
  54331. {
  54332. EXPECT_DECLS;
  54333. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  54334. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_BIO)
  54335. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  54336. char caFile[] = "./certs/client-ca.pem";
  54337. char clientFile[] = "./certs/client-cert.pem";
  54338. SSL_CTX* ctx = NULL;
  54339. X509* x509 = NULL;
  54340. BIO *bio = NULL;
  54341. X509 *cert = NULL;
  54342. X509 *ca = NULL;
  54343. STACK_OF(X509) *chain = NULL;
  54344. STACK_OF(X509) *chain2 = NULL;
  54345. #ifndef NO_WOLFSSL_SERVER
  54346. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  54347. #else
  54348. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  54349. #endif
  54350. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(caFile,
  54351. WOLFSSL_FILETYPE_PEM));
  54352. /* Negative tests. */
  54353. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  54354. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  54355. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(NULL, x509), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  54356. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(ctx, x509), WOLFSSL_SUCCESS);
  54357. ExpectNotNull(x509 = wolfSSL_X509_new());
  54358. /* Empty certificate. */
  54359. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(ctx, x509), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  54360. wolfSSL_X509_free(x509);
  54361. x509 = NULL;
  54362. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(clientFile,
  54363. WOLFSSL_FILETYPE_PEM));
  54364. /* additional test of getting EVP_PKEY key size from X509
  54365. * Do not run with user RSA because wolfSSL_RSA_size is not currently
  54366. * allowed with user RSA */
  54367. {
  54368. EVP_PKEY* pkey = NULL;
  54369. #if defined(HAVE_ECC)
  54370. X509* ecX509 = NULL;
  54371. #endif /* HAVE_ECC */
  54372. ExpectNotNull(pkey = X509_get_pubkey(x509));
  54373. /* current RSA key is 2048 bit (256 bytes) */
  54374. ExpectIntEQ(EVP_PKEY_size(pkey), 256);
  54375. EVP_PKEY_free(pkey);
  54376. pkey = NULL;
  54377. #if defined(HAVE_ECC)
  54378. #if defined(USE_CERT_BUFFERS_256)
  54379. ExpectNotNull(ecX509 = wolfSSL_X509_load_certificate_buffer(
  54380. cliecc_cert_der_256, sizeof_cliecc_cert_der_256,
  54381. SSL_FILETYPE_ASN1));
  54382. #else
  54383. ExpectNotNull(ecX509 = wolfSSL_X509_load_certificate_file(
  54384. cliEccCertFile, SSL_FILETYPE_PEM));
  54385. #endif
  54386. pkey = X509_get_pubkey(ecX509);
  54387. ExpectNotNull(pkey);
  54388. /* current ECC key is 256 bit (32 bytes) */
  54389. ExpectIntEQ(EVP_PKEY_size(pkey), 32);
  54390. X509_free(ecX509);
  54391. ecX509 = NULL;
  54392. EVP_PKEY_free(pkey);
  54393. pkey = NULL;
  54394. #endif /* HAVE_ECC */
  54395. }
  54396. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(ctx, x509), SSL_SUCCESS);
  54397. if (EXPECT_SUCCESS()) {
  54398. x509 = NULL;
  54399. }
  54400. #ifdef WOLFSSL_ENCRYPTED_KEYS
  54401. ExpectNull(SSL_CTX_get_default_passwd_cb(ctx));
  54402. ExpectNull(SSL_CTX_get_default_passwd_cb_userdata(ctx));
  54403. #endif
  54404. SSL_CTX_free(ctx);
  54405. ctx = NULL;
  54406. #ifndef NO_WOLFSSL_SERVER
  54407. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  54408. #else
  54409. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  54410. #endif
  54411. /* Test haproxy use case */
  54412. ExpectNotNull(bio = BIO_new_file(svrCertFile, "r"));
  54413. /* Read Certificate */
  54414. ExpectNotNull(cert = PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL));
  54415. ExpectNotNull(ca = PEM_read_bio_X509(bio, NULL, NULL, NULL));
  54416. ExpectNotNull(chain = sk_X509_new_null());
  54417. ExpectIntEQ(sk_X509_push(chain, ca), 1);
  54418. if (EXPECT_SUCCESS()) {
  54419. ca = NULL;
  54420. }
  54421. ExpectNotNull(chain2 = X509_chain_up_ref(chain));
  54422. ExpectNotNull(ca = sk_X509_shift(chain2));
  54423. ExpectIntEQ(SSL_CTX_use_certificate(ctx, cert), 1);
  54424. ExpectIntEQ(SSL_CTX_add_extra_chain_cert(ctx, ca), 1);
  54425. if (EXPECT_SUCCESS()) {
  54426. ca = NULL;
  54427. }
  54428. BIO_free(bio);
  54429. X509_free(cert);
  54430. X509_free(ca);
  54431. X509_free(x509);
  54432. sk_X509_pop_free(chain, X509_free);
  54433. sk_X509_pop_free(chain2, X509_free);
  54434. SSL_CTX_free(ctx);
  54435. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  54436. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  54437. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined (NO_BIO) */
  54438. return EXPECT_RESULT();
  54439. }
  54440. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  54441. static int test_wolfSSL_ERR_peek_last_error_line(void)
  54442. {
  54443. EXPECT_DECLS;
  54444. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  54445. !defined(NO_FILESYSTEM) && defined(DEBUG_WOLFSSL) && \
  54446. !defined(NO_OLD_TLS) && !defined(WOLFSSL_NO_TLS12) && \
  54447. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(NO_ERROR_QUEUE)
  54448. callback_functions client_cb;
  54449. callback_functions server_cb;
  54450. int line = 0;
  54451. int flag = ERR_TXT_STRING;
  54452. const char* file = NULL;
  54453. const char* data = NULL;
  54454. /* create a failed connection and inspect the error */
  54455. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  54456. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  54457. client_cb.method = wolfTLSv1_1_client_method;
  54458. server_cb.method = wolfTLSv1_2_server_method;
  54459. test_wolfSSL_client_server_nofail(&client_cb, &server_cb);
  54460. ExpectIntGT(ERR_get_error_line_data(NULL, NULL, &data, &flag), 0);
  54461. ExpectNotNull(data);
  54462. /* check clearing error state */
  54463. ERR_remove_state(0);
  54464. ExpectIntEQ((int)ERR_peek_last_error_line(NULL, NULL), 0);
  54465. ERR_peek_last_error_line(NULL, &line);
  54466. ExpectIntEQ(line, 0);
  54467. ERR_peek_last_error_line(&file, NULL);
  54468. ExpectNull(file);
  54469. /* retry connection to fill error queue */
  54470. XMEMSET(&client_cb, 0, sizeof(callback_functions));
  54471. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  54472. client_cb.method = wolfTLSv1_1_client_method;
  54473. server_cb.method = wolfTLSv1_2_server_method;
  54474. test_wolfSSL_client_server_nofail(&client_cb, &server_cb);
  54475. /* check that error code was stored */
  54476. ExpectIntNE((int)ERR_peek_last_error_line(NULL, NULL), 0);
  54477. ERR_peek_last_error_line(NULL, &line);
  54478. ExpectIntNE(line, 0);
  54479. ERR_peek_last_error_line(&file, NULL);
  54480. ExpectNotNull(file);
  54481. fprintf(stderr, "\nTesting error print out\n");
  54482. ERR_print_errors_fp(stderr);
  54483. fprintf(stderr, "Done testing print out\n\n");
  54484. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) &&
  54485. * !defined(NO_FILESYSTEM) && !defined(DEBUG_WOLFSSL) */
  54486. return EXPECT_RESULT();
  54487. }
  54488. #endif /* !NO_WOLFSSL_CLIENT && !NO_WOLFSSL_SERVER */
  54489. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  54490. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  54491. static int verify_cb(int ok, X509_STORE_CTX *ctx)
  54492. {
  54493. (void) ok;
  54494. (void) ctx;
  54495. fprintf(stderr, "ENTER verify_cb\n");
  54496. return SSL_SUCCESS;
  54497. }
  54498. #endif
  54499. static int test_wolfSSL_X509_Name_canon(void)
  54500. {
  54501. EXPECT_DECLS;
  54502. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  54503. !defined(NO_FILESYSTEM) && !defined(NO_SHA) && \
  54504. defined(WOLFSSL_CERT_GEN) && \
  54505. (defined(WOLFSSL_CERT_REQ) || defined(WOLFSSL_CERT_EXT)) && !defined(NO_RSA)
  54506. const long ex_hash1 = 0x0fdb2da4;
  54507. const long ex_hash2 = 0x9f3e8c9e;
  54508. X509_NAME *name = NULL;
  54509. X509 *x509 = NULL;
  54510. XFILE file = XBADFILE;
  54511. unsigned long hash = 0;
  54512. byte digest[WC_MAX_DIGEST_SIZE] = {0};
  54513. byte *pbuf = NULL;
  54514. word32 len = 0;
  54515. (void) ex_hash2;
  54516. ExpectTrue((file = XFOPEN(caCertFile, "rb")) != XBADFILE);
  54517. ExpectNotNull(x509 = PEM_read_X509(file, NULL, NULL, NULL));
  54518. ExpectNotNull(name = X509_get_issuer_name(x509));
  54519. /* When output buffer is NULL, should return necessary output buffer
  54520. * length.*/
  54521. ExpectIntGT(wolfSSL_i2d_X509_NAME_canon(name, NULL), 0);
  54522. ExpectIntGT((len = (word32)wolfSSL_i2d_X509_NAME_canon(name, &pbuf)), 0);
  54523. ExpectIntEQ(wc_ShaHash((const byte*)pbuf, (word32)len, digest), 0);
  54524. hash = (((unsigned long)digest[3] << 24) |
  54525. ((unsigned long)digest[2] << 16) |
  54526. ((unsigned long)digest[1] << 8) |
  54527. ((unsigned long)digest[0]));
  54528. ExpectIntEQ(hash, ex_hash1);
  54529. if (file != XBADFILE) {
  54530. XFCLOSE(file);
  54531. file = XBADFILE;
  54532. }
  54533. X509_free(x509);
  54534. x509 = NULL;
  54535. XFREE(pbuf, NULL, DYNAMIC_TYPE_OPENSSL);
  54536. pbuf = NULL;
  54537. ExpectTrue((file = XFOPEN(cliCertFile, "rb")) != XBADFILE);
  54538. ExpectNotNull(x509 = PEM_read_X509(file, NULL, NULL, NULL));
  54539. ExpectNotNull(name = X509_get_issuer_name(x509));
  54540. ExpectIntGT((len = (word32)wolfSSL_i2d_X509_NAME_canon(name, &pbuf)), 0);
  54541. ExpectIntEQ(wc_ShaHash((const byte*)pbuf, (word32)len, digest), 0);
  54542. hash = (((unsigned long)digest[3] << 24) |
  54543. ((unsigned long)digest[2] << 16) |
  54544. ((unsigned long)digest[1] << 8) |
  54545. ((unsigned long)digest[0]));
  54546. ExpectIntEQ(hash, ex_hash2);
  54547. if (file != XBADFILE)
  54548. XFCLOSE(file);
  54549. X509_free(x509);
  54550. XFREE(pbuf, NULL, DYNAMIC_TYPE_OPENSSL);
  54551. #endif
  54552. return EXPECT_RESULT();
  54553. }
  54554. static int test_wolfSSL_X509_LOOKUP_ctrl_hash_dir(void)
  54555. {
  54556. EXPECT_DECLS;
  54557. #if defined(OPENSSL_ALL) && !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_DIR)
  54558. const int MAX_DIR = 4;
  54559. const char paths[][32] = {
  54560. "./certs/ed25519",
  54561. "./certs/ecc",
  54562. "./certs/crl",
  54563. "./certs/",
  54564. };
  54565. char CertCrl_path[MAX_FILENAME_SZ];
  54566. char *p;
  54567. X509_STORE* str = NULL;
  54568. X509_LOOKUP* lookup = NULL;
  54569. WOLFSSL_STACK* sk = NULL;
  54570. int len, total_len, i;
  54571. (void)sk;
  54572. XMEMSET(CertCrl_path, 0, MAX_FILENAME_SZ);
  54573. /* illegal string */
  54574. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  54575. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  54576. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_ADD_DIR, "",
  54577. SSL_FILETYPE_PEM,NULL), 0);
  54578. /* free store */
  54579. X509_STORE_free(str);
  54580. str = NULL;
  54581. /* short folder string */
  54582. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  54583. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  54584. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_ADD_DIR, "./",
  54585. SSL_FILETYPE_PEM,NULL), 1);
  54586. #if defined(WOLFSSL_INT_H)
  54587. /* only available when including internal.h */
  54588. ExpectNotNull(sk = lookup->dirs->dir_entry);
  54589. #endif
  54590. /* free store */
  54591. X509_STORE_free(str);
  54592. str = NULL;
  54593. /* typical function check */
  54594. p = &CertCrl_path[0];
  54595. total_len = 0;
  54596. for (i = MAX_DIR - 1; i>=0 && total_len < MAX_FILENAME_SZ; i--) {
  54597. len = (int)XSTRLEN((const char*)&paths[i]);
  54598. total_len += len;
  54599. XSTRNCPY(p, paths[i], MAX_FILENAME_SZ - total_len);
  54600. p += len;
  54601. if (i != 0) *(p++) = SEPARATOR_CHAR;
  54602. }
  54603. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  54604. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  54605. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_ADD_DIR, CertCrl_path,
  54606. SSL_FILETYPE_PEM,NULL), 1);
  54607. #if defined(WOLFSSL_INT_H)
  54608. /* only available when including internal.h */
  54609. ExpectNotNull(sk = lookup->dirs->dir_entry);
  54610. #endif
  54611. X509_STORE_free(str);
  54612. #endif
  54613. return EXPECT_RESULT();
  54614. }
  54615. static int test_wolfSSL_X509_LOOKUP_ctrl_file(void)
  54616. {
  54617. EXPECT_DECLS;
  54618. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  54619. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && \
  54620. defined(WOLFSSL_SIGNER_DER_CERT)
  54621. X509_STORE_CTX* ctx = NULL;
  54622. X509_STORE* str = NULL;
  54623. X509_LOOKUP* lookup = NULL;
  54624. X509* cert1 = NULL;
  54625. X509* x509Ca = NULL;
  54626. X509* x509Svr = NULL;
  54627. X509* issuer = NULL;
  54628. WOLFSSL_STACK* sk = NULL;
  54629. X509_NAME* caName = NULL;
  54630. X509_NAME* issuerName = NULL;
  54631. XFILE file1 = XBADFILE;
  54632. int i;
  54633. int cert_count = 0;
  54634. int cmp;
  54635. char der[] = "certs/ca-cert.der";
  54636. #ifdef HAVE_CRL
  54637. char pem[][100] = {
  54638. "./certs/crl/crl.pem",
  54639. "./certs/crl/crl2.pem",
  54640. "./certs/crl/caEccCrl.pem",
  54641. "./certs/crl/eccCliCRL.pem",
  54642. "./certs/crl/eccSrvCRL.pem",
  54643. ""
  54644. };
  54645. #endif
  54646. ExpectTrue((file1 = XFOPEN("./certs/ca-cert.pem", "rb")) != XBADFILE);
  54647. ExpectNotNull(cert1 = wolfSSL_PEM_read_X509(file1, NULL, NULL, NULL));
  54648. if (file1 != XBADFILE)
  54649. XFCLOSE(file1);
  54650. ExpectNotNull(ctx = X509_STORE_CTX_new());
  54651. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  54652. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  54653. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_FILE_LOAD, caCertFile,
  54654. SSL_FILETYPE_PEM,NULL), 1);
  54655. ExpectNotNull(sk = wolfSSL_CertManagerGetCerts(str->cm));
  54656. ExpectIntEQ((cert_count = sk_X509_num(sk)), 1);
  54657. /* check if CA cert is loaded into the store */
  54658. for (i = 0; i < cert_count; i++) {
  54659. x509Ca = sk_X509_value(sk, i);
  54660. ExpectIntEQ(0, wolfSSL_X509_cmp(x509Ca, cert1));
  54661. }
  54662. ExpectNotNull((x509Svr =
  54663. wolfSSL_X509_load_certificate_file(svrCertFile, SSL_FILETYPE_PEM)));
  54664. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, x509Svr, NULL), SSL_SUCCESS);
  54665. ExpectNull(X509_STORE_CTX_get0_current_issuer(NULL));
  54666. issuer = X509_STORE_CTX_get0_current_issuer(ctx);
  54667. ExpectNotNull(issuer);
  54668. caName = X509_get_subject_name(x509Ca);
  54669. ExpectNotNull(caName);
  54670. issuerName = X509_get_subject_name(issuer);
  54671. ExpectNotNull(issuerName);
  54672. cmp = X509_NAME_cmp(caName, issuerName);
  54673. ExpectIntEQ(cmp, 0);
  54674. /* load der format */
  54675. X509_free(issuer);
  54676. issuer = NULL;
  54677. X509_STORE_CTX_free(ctx);
  54678. ctx = NULL;
  54679. X509_STORE_free(str);
  54680. str = NULL;
  54681. sk_X509_pop_free(sk, NULL);
  54682. sk = NULL;
  54683. X509_free(x509Svr);
  54684. x509Svr = NULL;
  54685. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  54686. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  54687. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_FILE_LOAD, der,
  54688. SSL_FILETYPE_ASN1,NULL), 1);
  54689. ExpectNotNull(sk = wolfSSL_CertManagerGetCerts(str->cm));
  54690. ExpectIntEQ((cert_count = sk_X509_num(sk)), 1);
  54691. /* check if CA cert is loaded into the store */
  54692. for (i = 0; i < cert_count; i++) {
  54693. x509Ca = sk_X509_value(sk, i);
  54694. ExpectIntEQ(0, wolfSSL_X509_cmp(x509Ca, cert1));
  54695. }
  54696. X509_STORE_free(str);
  54697. str = NULL;
  54698. sk_X509_pop_free(sk, NULL);
  54699. sk = NULL;
  54700. X509_free(cert1);
  54701. cert1 = NULL;
  54702. #ifdef HAVE_CRL
  54703. ExpectNotNull(str = wolfSSL_X509_STORE_new());
  54704. ExpectNotNull(lookup = X509_STORE_add_lookup(str, X509_LOOKUP_file()));
  54705. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_FILE_LOAD, caCertFile,
  54706. SSL_FILETYPE_PEM,NULL), 1);
  54707. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_FILE_LOAD,
  54708. "certs/server-revoked-cert.pem",
  54709. SSL_FILETYPE_PEM,NULL), 1);
  54710. if (str) {
  54711. ExpectIntEQ(wolfSSL_CertManagerVerify(str->cm, svrCertFile,
  54712. WOLFSSL_FILETYPE_PEM), 1);
  54713. /* since store hasn't yet known the revoked cert*/
  54714. ExpectIntEQ(wolfSSL_CertManagerVerify(str->cm,
  54715. "certs/server-revoked-cert.pem",
  54716. WOLFSSL_FILETYPE_PEM), 1);
  54717. }
  54718. for (i = 0; pem[i][0] != '\0'; i++)
  54719. {
  54720. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_FILE_LOAD, pem[i],
  54721. SSL_FILETYPE_PEM, NULL), 1);
  54722. }
  54723. if (str) {
  54724. /* since store knows crl list */
  54725. ExpectIntEQ(wolfSSL_CertManagerVerify(str->cm,
  54726. "certs/server-revoked-cert.pem",
  54727. WOLFSSL_FILETYPE_PEM ), WC_NO_ERR_TRACE(CRL_CERT_REVOKED));
  54728. }
  54729. ExpectIntEQ(X509_LOOKUP_ctrl(NULL, 0, NULL, 0, NULL), 0);
  54730. X509_STORE_free(str);
  54731. #endif
  54732. #endif
  54733. return EXPECT_RESULT();
  54734. }
  54735. static int test_wolfSSL_X509_STORE_CTX_trusted_stack_cleanup(void)
  54736. {
  54737. int res = TEST_SKIPPED;
  54738. #if defined(OPENSSL_EXTRA)
  54739. X509_STORE_CTX_cleanup(NULL);
  54740. X509_STORE_CTX_trusted_stack(NULL, NULL);
  54741. res = TEST_SUCCESS;
  54742. #endif
  54743. return res;
  54744. }
  54745. static int test_wolfSSL_X509_STORE_CTX_get0_current_issuer(void)
  54746. {
  54747. EXPECT_DECLS;
  54748. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  54749. X509_STORE_CTX* ctx = NULL;
  54750. X509_STORE* str = NULL;
  54751. X509* x509Ca = NULL;
  54752. X509* x509Svr = NULL;
  54753. X509* issuer = NULL;
  54754. X509_NAME* caName = NULL;
  54755. X509_NAME* issuerName = NULL;
  54756. ExpectNotNull(ctx = X509_STORE_CTX_new());
  54757. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  54758. ExpectNotNull((x509Ca =
  54759. wolfSSL_X509_load_certificate_file(caCertFile, SSL_FILETYPE_PEM)));
  54760. ExpectIntEQ(X509_STORE_add_cert(str, x509Ca), SSL_SUCCESS);
  54761. ExpectNotNull((x509Svr =
  54762. wolfSSL_X509_load_certificate_file(svrCertFile, SSL_FILETYPE_PEM)));
  54763. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, x509Svr, NULL), SSL_SUCCESS);
  54764. ExpectNull(X509_STORE_CTX_get0_current_issuer(NULL));
  54765. ExpectNotNull(issuer = X509_STORE_CTX_get0_current_issuer(ctx));
  54766. ExpectNotNull(caName = X509_get_subject_name(x509Ca));
  54767. ExpectNotNull(issuerName = X509_get_subject_name(issuer));
  54768. #ifdef WOLFSSL_SIGNER_DER_CERT
  54769. ExpectIntEQ(X509_NAME_cmp(caName, issuerName), 0);
  54770. #endif
  54771. X509_free(issuer);
  54772. X509_STORE_CTX_free(ctx);
  54773. X509_free(x509Svr);
  54774. X509_STORE_free(str);
  54775. X509_free(x509Ca);
  54776. #endif
  54777. return EXPECT_RESULT();
  54778. }
  54779. static int test_wolfSSL_PKCS7_certs(void)
  54780. {
  54781. EXPECT_DECLS;
  54782. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && !defined(NO_BIO) && \
  54783. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && defined(HAVE_PKCS7)
  54784. STACK_OF(X509)* sk = NULL;
  54785. STACK_OF(X509_INFO)* info_sk = NULL;
  54786. PKCS7 *p7 = NULL;
  54787. BIO* bio = NULL;
  54788. const byte* p = NULL;
  54789. int buflen = 0;
  54790. int i;
  54791. /* Test twice. Once with d2i and once without to test
  54792. * that everything is free'd correctly. */
  54793. for (i = 0; i < 2; i++) {
  54794. ExpectNotNull(p7 = PKCS7_new());
  54795. if (p7 != NULL) {
  54796. p7->version = 1;
  54797. #ifdef NO_SHA
  54798. p7->hashOID = SHA256h;
  54799. #else
  54800. p7->hashOID = SHAh;
  54801. #endif
  54802. }
  54803. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  54804. ExpectIntGT(BIO_read_filename(bio, svrCertFile), 0);
  54805. ExpectNotNull(info_sk = PEM_X509_INFO_read_bio(bio, NULL, NULL, NULL));
  54806. ExpectIntEQ(sk_X509_INFO_num(info_sk), 2);
  54807. ExpectNotNull(sk = sk_X509_new_null());
  54808. while (EXPECT_SUCCESS() && (sk_X509_INFO_num(info_sk) > 0)) {
  54809. X509_INFO* info = NULL;
  54810. ExpectNotNull(info = sk_X509_INFO_shift(info_sk));
  54811. ExpectIntGT(sk_X509_push(sk, info->x509), 0);
  54812. if (EXPECT_SUCCESS() && (info != NULL)) {
  54813. info->x509 = NULL;
  54814. }
  54815. X509_INFO_free(info);
  54816. }
  54817. sk_X509_INFO_pop_free(info_sk, X509_INFO_free);
  54818. info_sk = NULL;
  54819. BIO_free(bio);
  54820. bio = NULL;
  54821. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  54822. ExpectIntEQ(wolfSSL_PKCS7_encode_certs(p7, sk, bio), 1);
  54823. if ((sk != NULL) && ((p7 == NULL) || (bio == NULL))) {
  54824. sk_X509_pop_free(sk, X509_free);
  54825. }
  54826. sk = NULL;
  54827. ExpectIntGT((buflen = BIO_get_mem_data(bio, &p)), 0);
  54828. if (i == 0) {
  54829. PKCS7_free(p7);
  54830. p7 = NULL;
  54831. ExpectNotNull(d2i_PKCS7(&p7, &p, buflen));
  54832. if (p7 != NULL) {
  54833. /* Reset certs to force wolfSSL_PKCS7_to_stack to regenerate
  54834. * them */
  54835. ((WOLFSSL_PKCS7*)p7)->certs = NULL;
  54836. }
  54837. /* PKCS7_free free's the certs */
  54838. ExpectNotNull(wolfSSL_PKCS7_to_stack(p7));
  54839. }
  54840. BIO_free(bio);
  54841. bio = NULL;
  54842. PKCS7_free(p7);
  54843. p7 = NULL;
  54844. }
  54845. #endif /* defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  54846. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && defined(HAVE_PKCS7) */
  54847. return EXPECT_RESULT();
  54848. }
  54849. static int test_wolfSSL_X509_STORE_CTX(void)
  54850. {
  54851. EXPECT_DECLS;
  54852. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  54853. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  54854. X509_STORE_CTX* ctx = NULL;
  54855. X509_STORE* str = NULL;
  54856. X509* x509 = NULL;
  54857. #ifdef OPENSSL_ALL
  54858. X509* x5092 = NULL;
  54859. STACK_OF(X509) *sk = NULL;
  54860. STACK_OF(X509) *sk2 = NULL;
  54861. STACK_OF(X509) *sk3 = NULL;
  54862. #endif
  54863. ExpectNotNull(ctx = X509_STORE_CTX_new());
  54864. ExpectNotNull((str = wolfSSL_X509_STORE_new()));
  54865. ExpectNotNull((x509 =
  54866. wolfSSL_X509_load_certificate_file(svrCertFile, SSL_FILETYPE_PEM)));
  54867. ExpectIntEQ(X509_STORE_add_cert(str, x509), SSL_SUCCESS);
  54868. #ifdef OPENSSL_ALL
  54869. /* sk_X509_new only in OPENSSL_ALL */
  54870. sk = sk_X509_new_null();
  54871. ExpectNotNull(sk);
  54872. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, x509, sk), SSL_SUCCESS);
  54873. #else
  54874. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, x509, NULL), SSL_SUCCESS);
  54875. #endif
  54876. ExpectIntEQ(SSL_get_ex_data_X509_STORE_CTX_idx(), 0);
  54877. X509_STORE_CTX_set_error(ctx, -5);
  54878. X509_STORE_CTX_set_error(NULL, -5);
  54879. X509_STORE_CTX_free(ctx);
  54880. ctx = NULL;
  54881. #ifdef OPENSSL_ALL
  54882. sk_X509_pop_free(sk, NULL);
  54883. sk = NULL;
  54884. #endif
  54885. X509_STORE_free(str);
  54886. str = NULL;
  54887. X509_free(x509);
  54888. x509 = NULL;
  54889. ExpectNotNull(ctx = X509_STORE_CTX_new());
  54890. X509_STORE_CTX_set_verify_cb(ctx, verify_cb);
  54891. X509_STORE_CTX_free(ctx);
  54892. ctx = NULL;
  54893. #ifdef OPENSSL_ALL
  54894. /* test X509_STORE_CTX_get(1)_chain */
  54895. ExpectNotNull((x509 = X509_load_certificate_file(svrCertFile,
  54896. SSL_FILETYPE_PEM)));
  54897. ExpectNotNull((x5092 = X509_load_certificate_file(cliCertFile,
  54898. SSL_FILETYPE_PEM)));
  54899. ExpectNotNull((sk = sk_X509_new_null()));
  54900. ExpectIntEQ(sk_X509_push(sk, x509), 1);
  54901. if (EXPECT_FAIL()) {
  54902. X509_free(x509);
  54903. x509 = NULL;
  54904. }
  54905. ExpectNotNull((str = X509_STORE_new()));
  54906. ExpectNotNull((ctx = X509_STORE_CTX_new()));
  54907. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, x5092, sk), 1);
  54908. ExpectNull((sk2 = X509_STORE_CTX_get_chain(NULL)));
  54909. ExpectNotNull((sk2 = X509_STORE_CTX_get_chain(ctx)));
  54910. ExpectIntEQ(sk_num(sk2), 1); /* sanity, make sure chain has 1 cert */
  54911. ExpectNull((sk3 = X509_STORE_CTX_get1_chain(NULL)));
  54912. ExpectNotNull((sk3 = X509_STORE_CTX_get1_chain(ctx)));
  54913. ExpectIntEQ(sk_num(sk3), 1); /* sanity, make sure chain has 1 cert */
  54914. X509_STORE_CTX_free(ctx);
  54915. ctx = NULL;
  54916. X509_STORE_free(str);
  54917. str = NULL;
  54918. /* CTX certs not freed yet */
  54919. X509_free(x5092);
  54920. x5092 = NULL;
  54921. sk_X509_pop_free(sk, NULL);
  54922. sk = NULL;
  54923. /* sk3 is dup so free here */
  54924. sk_X509_pop_free(sk3, NULL);
  54925. sk3 = NULL;
  54926. #endif
  54927. /* test X509_STORE_CTX_get/set_ex_data */
  54928. {
  54929. int i = 0, tmpData = 5;
  54930. void* tmpDataRet;
  54931. ExpectNotNull(ctx = X509_STORE_CTX_new());
  54932. #ifdef HAVE_EX_DATA
  54933. for (i = 0; i < MAX_EX_DATA; i++) {
  54934. ExpectIntEQ(X509_STORE_CTX_set_ex_data(ctx, i, &tmpData),
  54935. WOLFSSL_SUCCESS);
  54936. tmpDataRet = (int*)X509_STORE_CTX_get_ex_data(ctx, i);
  54937. ExpectNotNull(tmpDataRet);
  54938. ExpectIntEQ(tmpData, *(int*)tmpDataRet);
  54939. }
  54940. #else
  54941. ExpectIntEQ(X509_STORE_CTX_set_ex_data(ctx, i, &tmpData),
  54942. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  54943. tmpDataRet = (int*)X509_STORE_CTX_get_ex_data(ctx, i);
  54944. ExpectNull(tmpDataRet);
  54945. #endif
  54946. X509_STORE_CTX_free(ctx);
  54947. ctx = NULL;
  54948. }
  54949. /* test X509_STORE_get/set_ex_data */
  54950. {
  54951. int i = 0, tmpData = 99;
  54952. void* tmpDataRet;
  54953. ExpectNotNull(str = X509_STORE_new());
  54954. #ifdef HAVE_EX_DATA
  54955. for (i = 0; i < MAX_EX_DATA; i++) {
  54956. ExpectIntEQ(X509_STORE_set_ex_data(str, i, &tmpData),
  54957. WOLFSSL_SUCCESS);
  54958. tmpDataRet = (int*)X509_STORE_get_ex_data(str, i);
  54959. ExpectNotNull(tmpDataRet);
  54960. ExpectIntEQ(tmpData, *(int*)tmpDataRet);
  54961. }
  54962. #else
  54963. ExpectIntEQ(X509_STORE_set_ex_data(str, i, &tmpData),
  54964. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  54965. tmpDataRet = (int*)X509_STORE_get_ex_data(str, i);
  54966. ExpectNull(tmpDataRet);
  54967. #endif
  54968. X509_STORE_free(str);
  54969. str = NULL;
  54970. }
  54971. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  54972. * !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  54973. return EXPECT_RESULT();
  54974. }
  54975. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  54976. static int test_X509_STORE_untrusted_load_cert_to_stack(const char* filename,
  54977. STACK_OF(X509)* chain)
  54978. {
  54979. EXPECT_DECLS;
  54980. XFILE fp = XBADFILE;
  54981. X509* cert = NULL;
  54982. ExpectTrue((fp = XFOPEN(filename, "rb"))
  54983. != XBADFILE);
  54984. ExpectNotNull(cert = PEM_read_X509(fp, 0, 0, 0 ));
  54985. if (fp != XBADFILE) {
  54986. XFCLOSE(fp);
  54987. fp = XBADFILE;
  54988. }
  54989. ExpectIntGT(sk_X509_push(chain, cert), 0);
  54990. if (EXPECT_FAIL())
  54991. X509_free(cert);
  54992. return EXPECT_RESULT();
  54993. }
  54994. static int test_X509_STORE_untrusted_certs(const char** filenames, int ret,
  54995. int err, int loadCA)
  54996. {
  54997. EXPECT_DECLS;
  54998. X509_STORE_CTX* ctx = NULL;
  54999. X509_STORE* str = NULL;
  55000. XFILE fp = XBADFILE;
  55001. X509* cert = NULL;
  55002. STACK_OF(X509)* untrusted = NULL;
  55003. ExpectTrue((fp = XFOPEN("./certs/intermediate/server-int-cert.pem", "rb"))
  55004. != XBADFILE);
  55005. ExpectNotNull(cert = PEM_read_X509(fp, 0, 0, 0 ));
  55006. if (fp != XBADFILE) {
  55007. XFCLOSE(fp);
  55008. fp = XBADFILE;
  55009. }
  55010. ExpectNotNull(str = X509_STORE_new());
  55011. ExpectNotNull(ctx = X509_STORE_CTX_new());
  55012. ExpectNotNull(untrusted = sk_X509_new_null());
  55013. ExpectIntEQ(X509_STORE_set_flags(str, 0), 1);
  55014. if (loadCA) {
  55015. ExpectIntEQ(X509_STORE_load_locations(str, "./certs/ca-cert.pem", NULL),
  55016. 1);
  55017. }
  55018. for (; *filenames; filenames++) {
  55019. ExpectIntEQ(test_X509_STORE_untrusted_load_cert_to_stack(*filenames,
  55020. untrusted), TEST_SUCCESS);
  55021. }
  55022. ExpectIntEQ(X509_STORE_CTX_init(ctx, str, cert, untrusted), 1);
  55023. ExpectIntEQ(X509_verify_cert(ctx), ret);
  55024. ExpectIntEQ(X509_STORE_CTX_get_error(ctx), err);
  55025. X509_free(cert);
  55026. X509_STORE_free(str);
  55027. X509_STORE_CTX_free(ctx);
  55028. sk_X509_pop_free(untrusted, NULL);
  55029. return EXPECT_RESULT();
  55030. }
  55031. #endif
  55032. static int test_X509_STORE_untrusted(void)
  55033. {
  55034. EXPECT_DECLS;
  55035. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  55036. const char* untrusted1[] = {
  55037. "./certs/intermediate/ca-int2-cert.pem",
  55038. NULL
  55039. };
  55040. const char* untrusted2[] = {
  55041. "./certs/intermediate/ca-int-cert.pem",
  55042. "./certs/intermediate/ca-int2-cert.pem",
  55043. NULL
  55044. };
  55045. const char* untrusted3[] = {
  55046. "./certs/intermediate/ca-int-cert.pem",
  55047. "./certs/intermediate/ca-int2-cert.pem",
  55048. "./certs/ca-cert.pem",
  55049. NULL
  55050. };
  55051. /* Adding unrelated certs that should be ignored */
  55052. const char* untrusted4[] = {
  55053. "./certs/client-ca.pem",
  55054. "./certs/intermediate/ca-int-cert.pem",
  55055. "./certs/server-cert.pem",
  55056. "./certs/intermediate/ca-int2-cert.pem",
  55057. NULL
  55058. };
  55059. /* Only immediate issuer in untrusted chain. Fails since can't build chain
  55060. * to loaded CA. */
  55061. ExpectIntEQ(test_X509_STORE_untrusted_certs(untrusted1, 0,
  55062. X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY, 1), TEST_SUCCESS);
  55063. /* Succeeds because path to loaded CA is available. */
  55064. ExpectIntEQ(test_X509_STORE_untrusted_certs(untrusted2, 1, 0, 1),
  55065. TEST_SUCCESS);
  55066. /* Fails because root CA is in the untrusted stack */
  55067. ExpectIntEQ(test_X509_STORE_untrusted_certs(untrusted3, 0,
  55068. X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY, 0), TEST_SUCCESS);
  55069. /* Succeeds because path to loaded CA is available. */
  55070. ExpectIntEQ(test_X509_STORE_untrusted_certs(untrusted4, 1, 0, 1),
  55071. TEST_SUCCESS);
  55072. #endif
  55073. return EXPECT_RESULT();
  55074. }
  55075. static int test_wolfSSL_X509_STORE_set_flags(void)
  55076. {
  55077. EXPECT_DECLS;
  55078. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  55079. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  55080. X509_STORE* store = NULL;
  55081. X509* x509 = NULL;
  55082. ExpectNotNull((store = wolfSSL_X509_STORE_new()));
  55083. ExpectNotNull((x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  55084. WOLFSSL_FILETYPE_PEM)));
  55085. ExpectIntEQ(X509_STORE_add_cert(store, x509), WOLFSSL_SUCCESS);
  55086. #ifdef HAVE_CRL
  55087. ExpectIntEQ(X509_STORE_set_flags(store, WOLFSSL_CRL_CHECKALL),
  55088. WOLFSSL_SUCCESS);
  55089. #else
  55090. ExpectIntEQ(X509_STORE_set_flags(store, WOLFSSL_CRL_CHECKALL),
  55091. WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  55092. #endif
  55093. wolfSSL_X509_free(x509);
  55094. wolfSSL_X509_STORE_free(store);
  55095. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) &&
  55096. * !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  55097. return EXPECT_RESULT();
  55098. }
  55099. static int test_wolfSSL_X509_LOOKUP_load_file(void)
  55100. {
  55101. EXPECT_DECLS;
  55102. #if defined(OPENSSL_EXTRA) && defined(HAVE_CRL) && \
  55103. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && \
  55104. (!defined(NO_WOLFSSL_CLIENT) || !defined(WOLFSSL_NO_CLIENT_AUTH))
  55105. WOLFSSL_X509_STORE* store = NULL;
  55106. WOLFSSL_X509_LOOKUP* lookup = NULL;
  55107. ExpectNotNull(store = wolfSSL_X509_STORE_new());
  55108. ExpectNotNull(lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()));
  55109. ExpectIntEQ(wolfSSL_X509_LOOKUP_load_file(lookup, "certs/client-ca.pem",
  55110. X509_FILETYPE_PEM), 1);
  55111. ExpectIntEQ(wolfSSL_X509_LOOKUP_load_file(lookup, "certs/crl/crl2.pem",
  55112. X509_FILETYPE_PEM), 1);
  55113. if (store != NULL) {
  55114. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm, cliCertFile,
  55115. WOLFSSL_FILETYPE_PEM), 1);
  55116. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm, svrCertFile,
  55117. WOLFSSL_FILETYPE_PEM), WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  55118. }
  55119. ExpectIntEQ(wolfSSL_X509_LOOKUP_load_file(lookup, "certs/ca-cert.pem",
  55120. X509_FILETYPE_PEM), 1);
  55121. if (store != NULL) {
  55122. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm, svrCertFile,
  55123. WOLFSSL_FILETYPE_PEM), 1);
  55124. }
  55125. wolfSSL_X509_STORE_free(store);
  55126. #endif /* defined(OPENSSL_EXTRA) && defined(HAVE_CRL) &&
  55127. * !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  55128. return EXPECT_RESULT();
  55129. }
  55130. static int test_wolfSSL_X509_STORE_CTX_set_time(void)
  55131. {
  55132. EXPECT_DECLS;
  55133. #if defined(OPENSSL_EXTRA)
  55134. WOLFSSL_X509_STORE_CTX* ctx = NULL;
  55135. time_t c_time;
  55136. ExpectNotNull(ctx = wolfSSL_X509_STORE_CTX_new());
  55137. c_time = 365*24*60*60;
  55138. wolfSSL_X509_STORE_CTX_set_time(ctx, 0, c_time);
  55139. ExpectTrue((ctx->param->flags & WOLFSSL_USE_CHECK_TIME) ==
  55140. WOLFSSL_USE_CHECK_TIME);
  55141. ExpectTrue(ctx->param->check_time == c_time);
  55142. wolfSSL_X509_STORE_CTX_free(ctx);
  55143. #endif /* OPENSSL_EXTRA */
  55144. return EXPECT_RESULT();
  55145. }
  55146. static int test_wolfSSL_CTX_get0_set1_param(void)
  55147. {
  55148. EXPECT_DECLS;
  55149. #if defined(OPENSSL_EXTRA)
  55150. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  55151. SSL_CTX* ctx = NULL;
  55152. WOLFSSL_X509_VERIFY_PARAM* pParam = NULL;
  55153. WOLFSSL_X509_VERIFY_PARAM* pvpm = NULL;
  55154. char testIPv4[] = "127.0.0.1";
  55155. char testhostName[] = "foo.hoge.com";
  55156. #ifndef NO_WOLFSSL_SERVER
  55157. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  55158. #else
  55159. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  55160. #endif
  55161. ExpectNull(SSL_CTX_get0_param(NULL));
  55162. ExpectNotNull(pParam = SSL_CTX_get0_param(ctx));
  55163. ExpectNotNull(pvpm = (WOLFSSL_X509_VERIFY_PARAM *)XMALLOC(
  55164. sizeof(WOLFSSL_X509_VERIFY_PARAM), NULL, DYNAMIC_TYPE_OPENSSL));
  55165. ExpectNotNull(XMEMSET(pvpm, 0, sizeof(WOLFSSL_X509_VERIFY_PARAM)));
  55166. ExpectIntEQ(wolfSSL_X509_VERIFY_PARAM_set1_host(pvpm, testhostName,
  55167. (int)XSTRLEN(testhostName)), WOLFSSL_SUCCESS);
  55168. ExpectIntEQ(wolfSSL_X509_VERIFY_PARAM_set1_ip_asc(pvpm, testIPv4),
  55169. WOLFSSL_SUCCESS);
  55170. wolfSSL_X509_VERIFY_PARAM_set_hostflags(pvpm, 0x01);
  55171. ExpectIntEQ(SSL_CTX_set1_param(ctx, pvpm), 1);
  55172. ExpectIntEQ(0, XSTRNCMP(pParam->hostName, testhostName,
  55173. (int)XSTRLEN(testhostName)));
  55174. ExpectIntEQ(0x01, pParam->hostFlags);
  55175. ExpectIntEQ(0, XSTRNCMP(pParam->ipasc, testIPv4, WOLFSSL_MAX_IPSTR));
  55176. /* test for incorrect parameter */
  55177. ExpectIntEQ(1,SSL_CTX_set1_param(ctx, NULL));
  55178. ExpectIntEQ(1,SSL_CTX_set1_param(NULL, pvpm));
  55179. ExpectIntEQ(1,SSL_CTX_set1_param(NULL, NULL));
  55180. SSL_CTX_free(ctx);
  55181. XFREE(pvpm, NULL, DYNAMIC_TYPE_OPENSSL);
  55182. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  55183. #endif /* OPENSSL_EXTRA && !defined(NO_RSA)*/
  55184. return EXPECT_RESULT();
  55185. }
  55186. static int test_wolfSSL_get0_param(void)
  55187. {
  55188. EXPECT_DECLS;
  55189. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  55190. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  55191. SSL_CTX* ctx = NULL;
  55192. SSL* ssl = NULL;
  55193. #ifndef NO_WOLFSSL_SERVER
  55194. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  55195. #else
  55196. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  55197. #endif
  55198. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  55199. SSL_FILETYPE_PEM));
  55200. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  55201. ExpectNotNull(ssl = SSL_new(ctx));
  55202. ExpectNotNull(SSL_get0_param(ssl));
  55203. SSL_free(ssl);
  55204. SSL_CTX_free(ctx);
  55205. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  55206. #endif /* OPENSSL_EXTRA && !defined(NO_RSA)*/
  55207. return EXPECT_RESULT();
  55208. }
  55209. static int test_wolfSSL_X509_VERIFY_PARAM_set1_host(void)
  55210. {
  55211. EXPECT_DECLS;
  55212. #if defined(OPENSSL_EXTRA)
  55213. const char host[] = "www.example.com";
  55214. WOLFSSL_X509_VERIFY_PARAM* pParam = NULL;
  55215. ExpectNotNull(pParam = (WOLFSSL_X509_VERIFY_PARAM*)XMALLOC(
  55216. sizeof(WOLFSSL_X509_VERIFY_PARAM), HEAP_HINT, DYNAMIC_TYPE_OPENSSL));
  55217. if (pParam != NULL) {
  55218. XMEMSET(pParam, 0, sizeof(WOLFSSL_X509_VERIFY_PARAM));
  55219. X509_VERIFY_PARAM_set1_host(pParam, host, sizeof(host));
  55220. ExpectIntEQ(XMEMCMP(pParam->hostName, host, sizeof(host)), 0);
  55221. XMEMSET(pParam, 0, sizeof(WOLFSSL_X509_VERIFY_PARAM));
  55222. ExpectIntNE(XMEMCMP(pParam->hostName, host, sizeof(host)), 0);
  55223. XFREE(pParam, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  55224. }
  55225. #endif /* OPENSSL_EXTRA */
  55226. return EXPECT_RESULT();
  55227. }
  55228. static int test_wolfSSL_set1_host(void)
  55229. {
  55230. EXPECT_DECLS;
  55231. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  55232. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  55233. const char host[] = "www.test_wolfSSL_set1_host.com";
  55234. const char emptyStr[] = "";
  55235. SSL_CTX* ctx = NULL;
  55236. SSL* ssl = NULL;
  55237. WOLFSSL_X509_VERIFY_PARAM* pParam = NULL;
  55238. #ifndef NO_WOLFSSL_SERVER
  55239. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  55240. #else
  55241. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  55242. #endif
  55243. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  55244. SSL_FILETYPE_PEM));
  55245. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  55246. ExpectNotNull(ssl = SSL_new(ctx));
  55247. pParam = SSL_get0_param(ssl);
  55248. /* we should get back host string */
  55249. ExpectIntEQ(SSL_set1_host(ssl, host), WOLFSSL_SUCCESS);
  55250. ExpectIntEQ(XMEMCMP(pParam->hostName, host, sizeof(host)), 0);
  55251. /* we should get back empty string */
  55252. ExpectIntEQ(SSL_set1_host(ssl, emptyStr), WOLFSSL_SUCCESS);
  55253. ExpectIntEQ(XMEMCMP(pParam->hostName, emptyStr, sizeof(emptyStr)), 0);
  55254. /* we should get back host string */
  55255. ExpectIntEQ(SSL_set1_host(ssl, host), WOLFSSL_SUCCESS);
  55256. ExpectIntEQ(XMEMCMP(pParam->hostName, host, sizeof(host)), 0);
  55257. /* we should get back empty string */
  55258. ExpectIntEQ(SSL_set1_host(ssl, NULL), WOLFSSL_SUCCESS);
  55259. ExpectIntEQ(XMEMCMP(pParam->hostName, emptyStr, sizeof(emptyStr)), 0);
  55260. SSL_free(ssl);
  55261. SSL_CTX_free(ctx);
  55262. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  55263. #endif /* OPENSSL_EXTRA */
  55264. return EXPECT_RESULT();
  55265. }
  55266. static int test_wolfSSL_X509_VERIFY_PARAM_set1_ip(void)
  55267. {
  55268. EXPECT_DECLS;
  55269. #if defined(OPENSSL_EXTRA)
  55270. unsigned char buf[16] = {0};
  55271. WOLFSSL_X509_VERIFY_PARAM* param = NULL;
  55272. ExpectNotNull(param = X509_VERIFY_PARAM_new());
  55273. /* test 127.0.0.1 */
  55274. buf[0] =0x7f; buf[1] = 0; buf[2] = 0; buf[3] = 1;
  55275. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 4), SSL_SUCCESS);
  55276. ExpectIntEQ(XSTRNCMP(param->ipasc, "127.0.0.1", sizeof(param->ipasc)), 0);
  55277. /* test 2001:db8:3333:4444:5555:6666:7777:8888 */
  55278. buf[0]=32;buf[1]=1;buf[2]=13;buf[3]=184;
  55279. buf[4]=51;buf[5]=51;buf[6]=68;buf[7]=68;
  55280. buf[8]=85;buf[9]=85;buf[10]=102;buf[11]=102;
  55281. buf[12]=119;buf[13]=119;buf[14]=136;buf[15]=136;
  55282. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 16), SSL_SUCCESS);
  55283. ExpectIntEQ(XSTRNCMP(param->ipasc,
  55284. "2001:db8:3333:4444:5555:6666:7777:8888", sizeof(param->ipasc)), 0);
  55285. /* test 2001:db8:: */
  55286. buf[0]=32;buf[1]=1;buf[2]=13;buf[3]=184;
  55287. buf[4]=0;buf[5]=0;buf[6]=0;buf[7]=0;
  55288. buf[8]=0;buf[9]=0;buf[10]=0;buf[11]=0;
  55289. buf[12]=0;buf[13]=0;buf[14]=0;buf[15]=0;
  55290. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 16), SSL_SUCCESS);
  55291. ExpectIntEQ(XSTRNCMP(param->ipasc, "2001:db8::", sizeof(param->ipasc)), 0);
  55292. /* test ::1234:5678 */
  55293. buf[0]=0;buf[1]=0;buf[2]=0;buf[3]=0;
  55294. buf[4]=0;buf[5]=0;buf[6]=0;buf[7]=0;
  55295. buf[8]=0;buf[9]=0;buf[10]=0;buf[11]=0;
  55296. buf[12]=18;buf[13]=52;buf[14]=86;buf[15]=120;
  55297. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 16), SSL_SUCCESS);
  55298. ExpectIntEQ(XSTRNCMP(param->ipasc, "::1234:5678", sizeof(param->ipasc)), 0);
  55299. /* test 2001:db8::1234:5678 */
  55300. buf[0]=32;buf[1]=1;buf[2]=13;buf[3]=184;
  55301. buf[4]=0;buf[5]=0;buf[6]=0;buf[7]=0;
  55302. buf[8]=0;buf[9]=0;buf[10]=0;buf[11]=0;
  55303. buf[12]=18;buf[13]=52;buf[14]=86;buf[15]=120;
  55304. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 16), SSL_SUCCESS);
  55305. ExpectIntEQ(XSTRNCMP(param->ipasc, "2001:db8::1234:5678",
  55306. sizeof(param->ipasc)), 0);
  55307. /* test 2001:0db8:0001:0000:0000:0ab9:c0a8:0102*/
  55308. /* 2001:db8:1::ab9:c0a8:102 */
  55309. buf[0]=32;buf[1]=1;buf[2]=13;buf[3]=184;
  55310. buf[4]=0;buf[5]=1;buf[6]=0;buf[7]=0;
  55311. buf[8]=0;buf[9]=0;buf[10]=10;buf[11]=185;
  55312. buf[12]=192;buf[13]=168;buf[14]=1;buf[15]=2;
  55313. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip(param, &buf[0], 16), SSL_SUCCESS);
  55314. ExpectIntEQ(XSTRNCMP(param->ipasc, "2001:db8:1::ab9:c0a8:102",
  55315. sizeof(param->ipasc)), 0);
  55316. XFREE(param, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  55317. #endif /* OPENSSL_EXTRA */
  55318. return EXPECT_RESULT();
  55319. }
  55320. static int test_wolfSSL_X509_STORE_CTX_get0_store(void)
  55321. {
  55322. EXPECT_DECLS;
  55323. #if defined(OPENSSL_EXTRA)
  55324. X509_STORE* store = NULL;
  55325. X509_STORE_CTX* ctx = NULL;
  55326. X509_STORE_CTX* ctx_no_init = NULL;
  55327. ExpectNotNull((store = X509_STORE_new()));
  55328. ExpectNotNull(ctx = X509_STORE_CTX_new());
  55329. ExpectNotNull(ctx_no_init = X509_STORE_CTX_new());
  55330. ExpectIntEQ(X509_STORE_CTX_init(ctx, store, NULL, NULL), SSL_SUCCESS);
  55331. ExpectNull(X509_STORE_CTX_get0_store(NULL));
  55332. /* should return NULL if ctx has not bee initialized */
  55333. ExpectNull(X509_STORE_CTX_get0_store(ctx_no_init));
  55334. ExpectNotNull(X509_STORE_CTX_get0_store(ctx));
  55335. wolfSSL_X509_STORE_CTX_free(ctx);
  55336. wolfSSL_X509_STORE_CTX_free(ctx_no_init);
  55337. X509_STORE_free(store);
  55338. #endif /* OPENSSL_EXTRA */
  55339. return EXPECT_RESULT();
  55340. }
  55341. static int test_wolfSSL_CTX_set_client_CA_list(void)
  55342. {
  55343. EXPECT_DECLS;
  55344. #if defined(OPENSSL_ALL) && !defined(NO_RSA) && !defined(NO_CERTS) && \
  55345. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_BIO)
  55346. WOLFSSL_CTX* ctx = NULL;
  55347. WOLFSSL* ssl = NULL;
  55348. X509_NAME* name = NULL;
  55349. STACK_OF(X509_NAME)* names = NULL;
  55350. STACK_OF(X509_NAME)* ca_list = NULL;
  55351. int names_len = 0;
  55352. int i;
  55353. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  55354. /* Send two X501 names in cert request */
  55355. names = SSL_load_client_CA_file(cliCertFile);
  55356. ExpectNotNull(names);
  55357. ca_list = SSL_load_client_CA_file(caCertFile);
  55358. ExpectNotNull(ca_list);
  55359. ExpectNotNull(name = sk_X509_NAME_value(ca_list, 0));
  55360. ExpectIntEQ(sk_X509_NAME_push(names, name), 2);
  55361. if (EXPECT_FAIL()) {
  55362. wolfSSL_X509_NAME_free(name);
  55363. name = NULL;
  55364. }
  55365. SSL_CTX_set_client_CA_list(ctx, names);
  55366. /* This should only free the stack structure */
  55367. sk_X509_NAME_free(ca_list);
  55368. ca_list = NULL;
  55369. ExpectNotNull(ca_list = SSL_CTX_get_client_CA_list(ctx));
  55370. ExpectIntEQ(sk_X509_NAME_num(ca_list), sk_X509_NAME_num(names));
  55371. ExpectIntGT((names_len = sk_X509_NAME_num(names)), 0);
  55372. for (i = 0; i < names_len; i++) {
  55373. ExpectNotNull(name = sk_X509_NAME_value(names, i));
  55374. ExpectIntEQ(sk_X509_NAME_find(names, name), i);
  55375. }
  55376. /* Needed to be able to create ssl object */
  55377. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  55378. SSL_FILETYPE_PEM));
  55379. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  55380. ExpectNotNull(ssl = wolfSSL_new(ctx));
  55381. /* load again as old names are responsibility of ctx to free*/
  55382. names = SSL_load_client_CA_file(cliCertFile);
  55383. ExpectNotNull(names);
  55384. SSL_set_client_CA_list(ssl, names);
  55385. ExpectNotNull(ca_list = SSL_get_client_CA_list(ssl));
  55386. ExpectIntEQ(sk_X509_NAME_num(ca_list), sk_X509_NAME_num(names));
  55387. ExpectIntGT((names_len = sk_X509_NAME_num(names)), 0);
  55388. for (i = 0; i < names_len; i++) {
  55389. ExpectNotNull(name = sk_X509_NAME_value(names, i));
  55390. ExpectIntEQ(sk_X509_NAME_find(names, name), i);
  55391. }
  55392. #if !defined(SINGLE_THREADED) && defined(SESSION_CERTS)
  55393. {
  55394. tcp_ready ready;
  55395. func_args server_args;
  55396. callback_functions server_cb;
  55397. THREAD_TYPE serverThread;
  55398. WOLFSSL* ssl_client = NULL;
  55399. WOLFSSL_CTX* ctx_client = NULL;
  55400. SOCKET_T sockfd = 0;
  55401. /* wolfSSL_get_client_CA_list() with handshake */
  55402. StartTCP();
  55403. InitTcpReady(&ready);
  55404. XMEMSET(&server_args, 0, sizeof(func_args));
  55405. XMEMSET(&server_cb, 0, sizeof(callback_functions));
  55406. server_args.signal = &ready;
  55407. server_args.callbacks = &server_cb;
  55408. /* we are responsible for free'ing WOLFSSL_CTX */
  55409. server_cb.ctx = ctx;
  55410. server_cb.isSharedCtx = 1;
  55411. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_load_verify_locations(ctx,
  55412. cliCertFile, 0));
  55413. start_thread(test_server_nofail, &server_args, &serverThread);
  55414. wait_tcp_ready(&server_args);
  55415. tcp_connect(&sockfd, wolfSSLIP, server_args.signal->port, 0, 0, NULL);
  55416. ExpectNotNull(ctx_client =
  55417. wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  55418. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_load_verify_locations(
  55419. ctx_client, caCertFile, 0));
  55420. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_certificate_file(
  55421. ctx_client, cliCertFile, SSL_FILETYPE_PEM));
  55422. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_PrivateKey_file(
  55423. ctx_client, cliKeyFile, SSL_FILETYPE_PEM));
  55424. ExpectNotNull(ssl_client = wolfSSL_new(ctx_client));
  55425. ExpectIntEQ(wolfSSL_set_fd(ssl_client, sockfd), WOLFSSL_SUCCESS);
  55426. ExpectIntEQ(wolfSSL_connect(ssl_client), WOLFSSL_SUCCESS);
  55427. ExpectNotNull(ca_list = SSL_get_client_CA_list(ssl_client));
  55428. /* We are expecting two cert names to be sent */
  55429. ExpectIntEQ(sk_X509_NAME_num(ca_list), 2);
  55430. ExpectNotNull(names = SSL_CTX_get_client_CA_list(ctx));
  55431. for (i=0; i<sk_X509_NAME_num(ca_list); i++) {
  55432. ExpectNotNull(name = sk_X509_NAME_value(ca_list, i));
  55433. ExpectIntGE(sk_X509_NAME_find(names, name), 0);
  55434. }
  55435. wolfSSL_shutdown(ssl_client);
  55436. wolfSSL_free(ssl_client);
  55437. wolfSSL_CTX_free(ctx_client);
  55438. CloseSocket(sockfd);
  55439. join_thread(serverThread);
  55440. FreeTcpReady(&ready);
  55441. }
  55442. #endif
  55443. wolfSSL_free(ssl);
  55444. wolfSSL_CTX_free(ctx);
  55445. #endif /* OPENSSL_EXTRA && !NO_RSA && !NO_CERTS && !NO_WOLFSSL_CLIENT &&
  55446. * !NO_BIO */
  55447. return EXPECT_RESULT();
  55448. }
  55449. static int test_wolfSSL_CTX_add_client_CA(void)
  55450. {
  55451. EXPECT_DECLS;
  55452. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_CERTS) && \
  55453. !defined(NO_WOLFSSL_CLIENT)
  55454. WOLFSSL_CTX* ctx = NULL;
  55455. WOLFSSL_X509* x509 = NULL;
  55456. WOLFSSL_X509* x509_a = NULL;
  55457. STACK_OF(X509_NAME)* ca_list = NULL;
  55458. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  55459. /* Add client cert */
  55460. ExpectNotNull(x509 = X509_load_certificate_file(cliCertFile,
  55461. SSL_FILETYPE_PEM));
  55462. ExpectIntEQ(SSL_CTX_add_client_CA(ctx, x509), SSL_SUCCESS);
  55463. ExpectNotNull(ca_list = SSL_CTX_get_client_CA_list(ctx));
  55464. /* Add another client cert */
  55465. ExpectNotNull(x509_a = X509_load_certificate_file(cliCertFile,
  55466. SSL_FILETYPE_PEM));
  55467. ExpectIntEQ(SSL_CTX_add_client_CA(ctx, x509_a), SSL_SUCCESS);
  55468. /* test for incorrect parameter */
  55469. ExpectIntEQ(SSL_CTX_add_client_CA(NULL, x509), 0);
  55470. ExpectIntEQ(SSL_CTX_add_client_CA(ctx, NULL), 0);
  55471. ExpectIntEQ(SSL_CTX_add_client_CA(NULL, NULL), 0);
  55472. X509_free(x509);
  55473. X509_free(x509_a);
  55474. SSL_CTX_free(ctx);
  55475. #endif /* OPENSSL_EXTRA && !NO_RSA && !NO_CERTS && !NO_WOLFSSL_CLIENT */
  55476. return EXPECT_RESULT();
  55477. }
  55478. #if defined(WOLFSSL_TLS13) && defined(HAVE_ECH) && \
  55479. defined(HAVE_IO_TESTS_DEPENDENCIES)
  55480. static THREAD_RETURN WOLFSSL_THREAD server_task_ech(void* args)
  55481. {
  55482. callback_functions* callbacks = ((func_args*)args)->callbacks;
  55483. WOLFSSL_CTX* ctx = callbacks->ctx;
  55484. WOLFSSL* ssl = NULL;
  55485. SOCKET_T sfd = 0;
  55486. SOCKET_T cfd = 0;
  55487. word16 port;
  55488. char input[1024];
  55489. int idx;
  55490. int ret, err = 0;
  55491. const char* privateName = "ech-private-name.com";
  55492. int privateNameLen = (int)XSTRLEN(privateName);
  55493. ((func_args*)args)->return_code = TEST_FAIL;
  55494. port = ((func_args*)args)->signal->port;
  55495. AssertIntEQ(WOLFSSL_SUCCESS,
  55496. wolfSSL_CTX_load_verify_locations(ctx, cliCertFile, 0));
  55497. AssertIntEQ(WOLFSSL_SUCCESS,
  55498. wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  55499. WOLFSSL_FILETYPE_PEM));
  55500. AssertIntEQ(WOLFSSL_SUCCESS,
  55501. wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  55502. WOLFSSL_FILETYPE_PEM));
  55503. if (callbacks->ctx_ready)
  55504. callbacks->ctx_ready(ctx);
  55505. ssl = wolfSSL_new(ctx);
  55506. /* set the sni for the server */
  55507. wolfSSL_UseSNI(ssl, WOLFSSL_SNI_HOST_NAME, privateName, privateNameLen);
  55508. tcp_accept(&sfd, &cfd, (func_args*)args, port, 0, 0, 0, 0, 1, NULL, NULL);
  55509. CloseSocket(sfd);
  55510. AssertIntEQ(WOLFSSL_SUCCESS, wolfSSL_set_fd(ssl, cfd));
  55511. if (callbacks->ssl_ready)
  55512. callbacks->ssl_ready(ssl);
  55513. do {
  55514. err = 0; /* Reset error */
  55515. ret = wolfSSL_accept(ssl);
  55516. if (ret != WOLFSSL_SUCCESS) {
  55517. err = wolfSSL_get_error(ssl, 0);
  55518. }
  55519. } while (ret != WOLFSSL_SUCCESS && err == WC_NO_ERR_TRACE(WC_PENDING_E));
  55520. if (ret != WOLFSSL_SUCCESS) {
  55521. char buff[WOLFSSL_MAX_ERROR_SZ];
  55522. fprintf(stderr, "error = %d, %s\n", err, wolfSSL_ERR_error_string(err, buff));
  55523. }
  55524. else {
  55525. if (0 < (idx = wolfSSL_read(ssl, input, sizeof(input)-1))) {
  55526. input[idx] = 0;
  55527. fprintf(stderr, "Client message: %s\n", input);
  55528. }
  55529. AssertIntEQ(privateNameLen, wolfSSL_write(ssl, privateName,
  55530. privateNameLen));
  55531. ((func_args*)args)->return_code = TEST_SUCCESS;
  55532. }
  55533. if (callbacks->on_result)
  55534. callbacks->on_result(ssl);
  55535. wolfSSL_shutdown(ssl);
  55536. wolfSSL_free(ssl);
  55537. wolfSSL_CTX_free(ctx);
  55538. CloseSocket(cfd);
  55539. #ifdef FP_ECC
  55540. wc_ecc_fp_free();
  55541. #endif
  55542. WOLFSSL_RETURN_FROM_THREAD(0);
  55543. }
  55544. #endif /* HAVE_ECH && WOLFSSL_TLS13 */
  55545. #if defined(OPENSSL_EXTRA) && defined(HAVE_SECRET_CALLBACK)
  55546. static void keyLog_callback(const WOLFSSL* ssl, const char* line)
  55547. {
  55548. XFILE fp;
  55549. const byte lf = '\n';
  55550. AssertNotNull(ssl);
  55551. AssertNotNull(line);
  55552. fp = XFOPEN("./MyKeyLog.txt", "a");
  55553. XFWRITE(line, 1, XSTRLEN(line), fp);
  55554. XFWRITE((void*)&lf, 1, 1, fp);
  55555. XFFLUSH(fp);
  55556. XFCLOSE(fp);
  55557. }
  55558. #endif /* OPENSSL_EXTRA && HAVE_SECRET_CALLBACK */
  55559. static int test_wolfSSL_CTX_set_keylog_callback(void)
  55560. {
  55561. EXPECT_DECLS;
  55562. #if defined(OPENSSL_EXTRA) && defined(HAVE_SECRET_CALLBACK) && \
  55563. !defined(NO_WOLFSSL_CLIENT)
  55564. SSL_CTX* ctx = NULL;
  55565. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  55566. SSL_CTX_set_keylog_callback(ctx, keyLog_callback );
  55567. SSL_CTX_free(ctx);
  55568. SSL_CTX_set_keylog_callback(NULL, NULL);
  55569. #endif /* OPENSSL_EXTRA && HAVE_SECRET_CALLBACK && !NO_WOLFSSL_CLIENT */
  55570. return EXPECT_RESULT();
  55571. }
  55572. static int test_wolfSSL_CTX_get_keylog_callback(void)
  55573. {
  55574. EXPECT_DECLS;
  55575. #if defined(OPENSSL_EXTRA) && defined(HAVE_SECRET_CALLBACK) && \
  55576. !defined(NO_WOLFSSL_CLIENT)
  55577. SSL_CTX* ctx = NULL;
  55578. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  55579. ExpectPtrEq(SSL_CTX_get_keylog_callback(ctx),NULL);
  55580. SSL_CTX_set_keylog_callback(ctx, keyLog_callback );
  55581. ExpectPtrEq(SSL_CTX_get_keylog_callback(ctx),keyLog_callback);
  55582. SSL_CTX_set_keylog_callback(ctx, NULL );
  55583. ExpectPtrEq(SSL_CTX_get_keylog_callback(ctx),NULL);
  55584. SSL_CTX_free(ctx);
  55585. #endif /* OPENSSL_EXTRA && HAVE_SECRET_CALLBACK && !NO_WOLFSSL_CLIENT */
  55586. return EXPECT_RESULT();
  55587. }
  55588. #if defined(OPENSSL_EXTRA) && defined(HAVE_SECRET_CALLBACK)
  55589. static int test_wolfSSL_Tls12_Key_Logging_client_ctx_ready(WOLFSSL_CTX* ctx)
  55590. {
  55591. /* set keylog callback */
  55592. wolfSSL_CTX_set_keylog_callback(ctx, keyLog_callback);
  55593. return TEST_SUCCESS;
  55594. }
  55595. #endif
  55596. static int test_wolfSSL_Tls12_Key_Logging_test(void)
  55597. {
  55598. EXPECT_DECLS;
  55599. #if defined(OPENSSL_EXTRA) && defined(HAVE_SECRET_CALLBACK)
  55600. /* This test is intended for checking whether keylog callback is called
  55601. * in client during TLS handshake between the client and a server.
  55602. */
  55603. test_ssl_cbf server_cbf;
  55604. test_ssl_cbf client_cbf;
  55605. XFILE fp = XBADFILE;
  55606. char buff[500];
  55607. int found = 0;
  55608. XMEMSET(&server_cbf, 0, sizeof(test_ssl_cbf));
  55609. XMEMSET(&client_cbf, 0, sizeof(test_ssl_cbf));
  55610. server_cbf.method = wolfTLSv1_2_server_method;
  55611. client_cbf.ctx_ready = &test_wolfSSL_Tls12_Key_Logging_client_ctx_ready;
  55612. /* clean up keylog file */
  55613. ExpectTrue((fp = XFOPEN("./MyKeyLog.txt", "w")) != XBADFILE);
  55614. if (fp != XBADFILE) {
  55615. XFFLUSH(fp);
  55616. XFCLOSE(fp);
  55617. fp = XBADFILE;
  55618. }
  55619. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  55620. &server_cbf, NULL), TEST_SUCCESS);
  55621. /* check if the keylog file exists */
  55622. ExpectTrue((fp = XFOPEN("./MyKeyLog.txt", "r")) != XBADFILE);
  55623. XFFLUSH(fp); /* Just to make sure any buffers get flushed */
  55624. XMEMSET(buff, 0, sizeof(buff));
  55625. while (EXPECT_SUCCESS() && XFGETS(buff, (int)sizeof(buff), fp) != NULL) {
  55626. if (0 == strncmp(buff,"CLIENT_RANDOM ", sizeof("CLIENT_RANDOM ")-1)) {
  55627. found = 1;
  55628. break;
  55629. }
  55630. }
  55631. if (fp != XBADFILE) {
  55632. XFCLOSE(fp);
  55633. }
  55634. /* a log starting with "CLIENT_RANDOM " should exit in the file */
  55635. ExpectIntEQ(found, 1);
  55636. /* clean up */
  55637. ExpectIntEQ(rem_file("./MyKeyLog.txt"), 0);
  55638. #endif /* OPENSSL_EXTRA && HAVE_SECRET_CALLBACK */
  55639. return EXPECT_RESULT();
  55640. }
  55641. #if defined(WOLFSSL_TLS13) && defined(OPENSSL_EXTRA) && \
  55642. defined(HAVE_SECRET_CALLBACK)
  55643. static int test_wolfSSL_Tls13_Key_Logging_client_ctx_ready(WOLFSSL_CTX* ctx)
  55644. {
  55645. /* set keylog callback */
  55646. wolfSSL_CTX_set_keylog_callback(ctx, keyLog_callback);
  55647. return TEST_SUCCESS;
  55648. }
  55649. #endif
  55650. static int test_wolfSSL_Tls13_Key_Logging_test(void)
  55651. {
  55652. EXPECT_DECLS;
  55653. #if defined(WOLFSSL_TLS13) && defined(OPENSSL_EXTRA) && \
  55654. defined(HAVE_SECRET_CALLBACK)
  55655. /* This test is intended for checking whether keylog callback is called
  55656. * in client during TLS handshake between the client and a server.
  55657. */
  55658. test_ssl_cbf server_cbf;
  55659. test_ssl_cbf client_cbf;
  55660. XFILE fp = XBADFILE;
  55661. XMEMSET(&server_cbf, 0, sizeof(test_ssl_cbf));
  55662. XMEMSET(&client_cbf, 0, sizeof(test_ssl_cbf));
  55663. server_cbf.method = wolfTLSv1_3_server_method; /* TLS1.3 */
  55664. client_cbf.ctx_ready = &test_wolfSSL_Tls13_Key_Logging_client_ctx_ready;
  55665. /* clean up keylog file */
  55666. ExpectTrue((fp = XFOPEN("./MyKeyLog.txt", "w")) != XBADFILE);
  55667. if (fp != XBADFILE) {
  55668. XFCLOSE(fp);
  55669. fp = XBADFILE;
  55670. }
  55671. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  55672. &server_cbf, NULL), TEST_SUCCESS);
  55673. /* check if the keylog file exists */
  55674. {
  55675. char buff[300] = {0};
  55676. int found[4] = {0};
  55677. int numfnd = 0;
  55678. int i;
  55679. ExpectTrue((fp = XFOPEN("./MyKeyLog.txt", "r")) != XBADFILE);
  55680. while (EXPECT_SUCCESS() &&
  55681. XFGETS(buff, (int)sizeof(buff), fp) != NULL) {
  55682. if (0 == strncmp(buff, "CLIENT_HANDSHAKE_TRAFFIC_SECRET ",
  55683. sizeof("CLIENT_HANDSHAKE_TRAFFIC_SECRET ")-1)) {
  55684. found[0] = 1;
  55685. continue;
  55686. }
  55687. else if (0 == strncmp(buff, "SERVER_HANDSHAKE_TRAFFIC_SECRET ",
  55688. sizeof("SERVER_HANDSHAKE_TRAFFIC_SECRET ")-1)) {
  55689. found[1] = 1;
  55690. continue;
  55691. }
  55692. else if (0 == strncmp(buff, "CLIENT_TRAFFIC_SECRET_0 ",
  55693. sizeof("CLIENT_TRAFFIC_SECRET_0 ")-1)) {
  55694. found[2] = 1;
  55695. continue;
  55696. }
  55697. else if (0 == strncmp(buff, "SERVER_TRAFFIC_SECRET_0 ",
  55698. sizeof("SERVER_TRAFFIC_SECRET_0 ")-1)) {
  55699. found[3] = 1;
  55700. continue;
  55701. }
  55702. }
  55703. if (fp != XBADFILE)
  55704. XFCLOSE(fp);
  55705. for (i = 0; i < 4; i++) {
  55706. if (found[i] != 0)
  55707. numfnd++;
  55708. }
  55709. ExpectIntEQ(numfnd, 4);
  55710. }
  55711. #endif /* OPENSSL_EXTRA && HAVE_SECRET_CALLBACK && WOLFSSL_TLS13 */
  55712. return EXPECT_RESULT();
  55713. }
  55714. #if defined(WOLFSSL_TLS13) && defined(HAVE_ECH) && \
  55715. defined(HAVE_IO_TESTS_DEPENDENCIES)
  55716. static int test_wolfSSL_Tls13_ECH_params(void)
  55717. {
  55718. EXPECT_DECLS;
  55719. #if !defined(NO_WOLFSSL_CLIENT)
  55720. word32 outputLen = 0;
  55721. byte testBuf[72];
  55722. WOLFSSL_CTX *ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method());
  55723. WOLFSSL *ssl = wolfSSL_new(ctx);
  55724. ExpectNotNull(ctx);
  55725. ExpectNotNull(ssl);
  55726. /* invalid ctx */
  55727. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_GenerateEchConfig(NULL,
  55728. "ech-public-name.com", 0, 0, 0));
  55729. /* invalid public name */
  55730. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_GenerateEchConfig(ctx, NULL, 0,
  55731. 0, 0));
  55732. /* invalid algorithms */
  55733. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_GenerateEchConfig(ctx,
  55734. "ech-public-name.com", 1000, 1000, 1000));
  55735. /* invalid ctx */
  55736. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_GetEchConfigs(NULL, NULL,
  55737. &outputLen));
  55738. /* invalid output len */
  55739. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_CTX_GetEchConfigs(ctx, NULL, NULL));
  55740. /* invalid ssl */
  55741. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigsBase64(NULL,
  55742. (char*)testBuf, sizeof(testBuf)));
  55743. /* invalid configs64 */
  55744. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigsBase64(ssl, NULL,
  55745. sizeof(testBuf)));
  55746. /* invalid size */
  55747. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigsBase64(ssl,
  55748. (char*)testBuf, 0));
  55749. /* invalid ssl */
  55750. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigs(NULL, testBuf,
  55751. sizeof(testBuf)));
  55752. /* invalid configs */
  55753. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigs(ssl, NULL,
  55754. sizeof(testBuf)));
  55755. /* invalid size */
  55756. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigs(ssl, testBuf, 0));
  55757. /* invalid ssl */
  55758. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_GetEchConfigs(NULL, NULL, &outputLen));
  55759. /* invalid size */
  55760. ExpectIntNE(WOLFSSL_SUCCESS, wolfSSL_GetEchConfigs(ssl, NULL, NULL));
  55761. wolfSSL_free(ssl);
  55762. wolfSSL_CTX_free(ctx);
  55763. #endif /* !NO_WOLFSSL_CLIENT */
  55764. return EXPECT_RESULT();
  55765. }
  55766. static int test_wolfSSL_Tls13_ECH(void)
  55767. {
  55768. EXPECT_DECLS;
  55769. tcp_ready ready;
  55770. func_args client_args;
  55771. func_args server_args;
  55772. THREAD_TYPE serverThread;
  55773. callback_functions server_cbf;
  55774. callback_functions client_cbf;
  55775. SOCKET_T sockfd = 0;
  55776. WOLFSSL_CTX* ctx = NULL;
  55777. WOLFSSL* ssl = NULL;
  55778. const char* publicName = "ech-public-name.com";
  55779. const char* privateName = "ech-private-name.com";
  55780. int privateNameLen = 20;
  55781. char reply[1024];
  55782. int replyLen = 0;
  55783. byte rawEchConfig[128];
  55784. word32 rawEchConfigLen = sizeof(rawEchConfig);
  55785. InitTcpReady(&ready);
  55786. ready.port = 22222;
  55787. XMEMSET(&client_args, 0, sizeof(func_args));
  55788. XMEMSET(&server_args, 0, sizeof(func_args));
  55789. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  55790. XMEMSET(&client_cbf, 0, sizeof(callback_functions));
  55791. server_cbf.method = wolfTLSv1_3_server_method; /* TLS1.3 */
  55792. /* create the server context here so we can get the ech config */
  55793. ExpectNotNull(server_cbf.ctx =
  55794. wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  55795. /* generate ech config */
  55796. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_GenerateEchConfig(server_cbf.ctx,
  55797. publicName, 0, 0, 0));
  55798. /* get the config for the client to use */
  55799. ExpectIntEQ(WOLFSSL_SUCCESS,
  55800. wolfSSL_CTX_GetEchConfigs(server_cbf.ctx, rawEchConfig,
  55801. &rawEchConfigLen));
  55802. server_args.callbacks = &server_cbf;
  55803. server_args.signal = &ready;
  55804. /* start server task */
  55805. start_thread(server_task_ech, &server_args, &serverThread);
  55806. wait_tcp_ready(&server_args);
  55807. /* run as a TLS1.3 client */
  55808. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  55809. ExpectIntEQ(WOLFSSL_SUCCESS,
  55810. wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0));
  55811. ExpectIntEQ(WOLFSSL_SUCCESS,
  55812. wolfSSL_CTX_use_certificate_file(ctx, cliCertFile, SSL_FILETYPE_PEM));
  55813. ExpectIntEQ(WOLFSSL_SUCCESS,
  55814. wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, SSL_FILETYPE_PEM));
  55815. tcp_connect(&sockfd, wolfSSLIP, server_args.signal->port, 0, 0, NULL);
  55816. /* get connected the server task */
  55817. ExpectNotNull(ssl = wolfSSL_new(ctx));
  55818. /* set the ech configs for the client */
  55819. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetEchConfigs(ssl, rawEchConfig,
  55820. rawEchConfigLen));
  55821. /* set the sni for the client */
  55822. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_UseSNI(ssl, WOLFSSL_SNI_HOST_NAME,
  55823. privateName, privateNameLen));
  55824. ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS);
  55825. ExpectIntEQ(wolfSSL_connect(ssl), WOLFSSL_SUCCESS);
  55826. ExpectIntEQ(wolfSSL_write(ssl, privateName, privateNameLen),
  55827. privateNameLen);
  55828. ExpectIntGT((replyLen = wolfSSL_read(ssl, reply, sizeof(reply))), 0);
  55829. /* add th null terminator for string compare */
  55830. reply[replyLen] = 0;
  55831. /* check that the server replied with the private name */
  55832. ExpectStrEQ(privateName, reply);
  55833. wolfSSL_free(ssl);
  55834. wolfSSL_CTX_free(ctx);
  55835. CloseSocket(sockfd);
  55836. join_thread(serverThread);
  55837. FreeTcpReady(&ready);
  55838. return EXPECT_RESULT();
  55839. }
  55840. #endif /* HAVE_ECH && WOLFSSL_TLS13 */
  55841. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  55842. defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  55843. defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
  55844. static int post_auth_version_cb(WOLFSSL* ssl)
  55845. {
  55846. EXPECT_DECLS;
  55847. /* do handshake and then test version error */
  55848. ExpectIntEQ(wolfSSL_accept(ssl), WOLFSSL_SUCCESS);
  55849. ExpectStrEQ("TLSv1.2", wolfSSL_get_version(ssl));
  55850. return EXPECT_RESULT();
  55851. }
  55852. static int post_auth_version_client_cb(WOLFSSL* ssl)
  55853. {
  55854. EXPECT_DECLS;
  55855. /* do handshake and then test version error */
  55856. ExpectIntEQ(wolfSSL_connect(ssl), WOLFSSL_SUCCESS);
  55857. ExpectStrEQ("TLSv1.2", wolfSSL_get_version(ssl));
  55858. ExpectIntEQ(wolfSSL_verify_client_post_handshake(ssl), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  55859. #if defined(OPENSSL_ALL) && !defined(NO_ERROR_QUEUE)
  55860. /* check was added to error queue */
  55861. ExpectIntEQ(wolfSSL_ERR_get_error(), -WC_NO_ERR_TRACE(UNSUPPORTED_PROTO_VERSION));
  55862. /* check the string matches expected string */
  55863. #ifndef NO_ERROR_STRINGS
  55864. ExpectStrEQ(wolfSSL_ERR_error_string(-WC_NO_ERR_TRACE(UNSUPPORTED_PROTO_VERSION), NULL),
  55865. "WRONG_SSL_VERSION");
  55866. #endif
  55867. #endif
  55868. return EXPECT_RESULT();
  55869. }
  55870. static int post_auth_cb(WOLFSSL* ssl)
  55871. {
  55872. EXPECT_DECLS;
  55873. WOLFSSL_X509* x509 = NULL;
  55874. /* do handshake and then test version error */
  55875. ExpectIntEQ(wolfSSL_accept(ssl), WOLFSSL_SUCCESS);
  55876. ExpectStrEQ("TLSv1.3", wolfSSL_get_version(ssl));
  55877. ExpectNull(x509 = wolfSSL_get_peer_certificate(ssl));
  55878. wolfSSL_X509_free(x509);
  55879. ExpectIntEQ(wolfSSL_verify_client_post_handshake(ssl), WOLFSSL_SUCCESS);
  55880. return EXPECT_RESULT();
  55881. }
  55882. static int set_post_auth_cb(WOLFSSL* ssl)
  55883. {
  55884. if (!wolfSSL_is_server(ssl)) {
  55885. EXPECT_DECLS;
  55886. ExpectIntEQ(wolfSSL_allow_post_handshake_auth(ssl), 0);
  55887. return EXPECT_RESULT();
  55888. }
  55889. wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_POST_HANDSHAKE, NULL);
  55890. return TEST_SUCCESS;
  55891. }
  55892. #endif
  55893. static int test_wolfSSL_Tls13_postauth(void)
  55894. {
  55895. EXPECT_DECLS;
  55896. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  55897. defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  55898. defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
  55899. test_ssl_cbf server_cbf;
  55900. test_ssl_cbf client_cbf;
  55901. /* test version failure doing post auth with TLS 1.2 connection */
  55902. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  55903. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  55904. server_cbf.method = wolfTLSv1_2_server_method;
  55905. server_cbf.ssl_ready = set_post_auth_cb;
  55906. server_cbf.on_result = post_auth_version_cb;
  55907. client_cbf.ssl_ready = set_post_auth_cb;
  55908. client_cbf.on_result = post_auth_version_client_cb;
  55909. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  55910. &server_cbf, NULL), TEST_SUCCESS);
  55911. /* tests on post auth with TLS 1.3 */
  55912. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  55913. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  55914. server_cbf.method = wolfTLSv1_3_server_method;
  55915. server_cbf.ssl_ready = set_post_auth_cb;
  55916. client_cbf.ssl_ready = set_post_auth_cb;
  55917. server_cbf.on_result = post_auth_cb;
  55918. client_cbf.on_result = NULL;
  55919. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  55920. &server_cbf, NULL), TEST_SUCCESS);
  55921. #endif
  55922. return EXPECT_RESULT();
  55923. }
  55924. static int test_wolfSSL_X509_NID(void)
  55925. {
  55926. EXPECT_DECLS;
  55927. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)) && \
  55928. !defined(NO_RSA) && defined(USE_CERT_BUFFERS_2048) && !defined(NO_ASN)
  55929. int sigType;
  55930. int nameSz;
  55931. X509* cert = NULL;
  55932. EVP_PKEY* pubKeyTmp = NULL;
  55933. X509_NAME* name = NULL;
  55934. char commonName[80];
  55935. char countryName[80];
  55936. char localityName[80];
  55937. char stateName[80];
  55938. char orgName[80];
  55939. char orgUnit[80];
  55940. /* ------ PARSE ORIGINAL SELF-SIGNED CERTIFICATE ------ */
  55941. /* convert cert from DER to internal WOLFSSL_X509 struct */
  55942. ExpectNotNull(cert = wolfSSL_X509_d2i_ex(&cert, client_cert_der_2048,
  55943. sizeof_client_cert_der_2048, HEAP_HINT));
  55944. /* ------ EXTRACT CERTIFICATE ELEMENTS ------ */
  55945. /* extract PUBLIC KEY from cert */
  55946. ExpectNotNull(pubKeyTmp = X509_get_pubkey(cert));
  55947. /* extract signatureType */
  55948. ExpectIntNE((sigType = wolfSSL_X509_get_signature_type(cert)), 0);
  55949. /* extract subjectName info */
  55950. ExpectNotNull(name = X509_get_subject_name(cert));
  55951. ExpectIntEQ(X509_NAME_get_text_by_NID(name, -1, NULL, 0), -1);
  55952. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_commonName,
  55953. NULL, 0)), 0);
  55954. ExpectIntEQ(nameSz, 15);
  55955. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_commonName,
  55956. commonName, sizeof(commonName))), 0);
  55957. ExpectIntEQ(nameSz, 15);
  55958. ExpectIntEQ(XMEMCMP(commonName, "www.wolfssl.com", nameSz), 0);
  55959. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_commonName,
  55960. commonName, 9)), 0);
  55961. ExpectIntEQ(nameSz, 8);
  55962. ExpectIntEQ(XMEMCMP(commonName, "www.wolf", nameSz), 0);
  55963. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_countryName,
  55964. countryName, sizeof(countryName))), 0);
  55965. ExpectIntEQ(XMEMCMP(countryName, "US", nameSz), 0);
  55966. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_localityName,
  55967. localityName, sizeof(localityName))), 0);
  55968. ExpectIntEQ(XMEMCMP(localityName, "Bozeman", nameSz), 0);
  55969. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name,
  55970. NID_stateOrProvinceName, stateName, sizeof(stateName))), 0);
  55971. ExpectIntEQ(XMEMCMP(stateName, "Montana", nameSz), 0);
  55972. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name, NID_organizationName,
  55973. orgName, sizeof(orgName))), 0);
  55974. ExpectIntEQ(XMEMCMP(orgName, "wolfSSL_2048", nameSz), 0);
  55975. ExpectIntGT((nameSz = X509_NAME_get_text_by_NID(name,
  55976. NID_organizationalUnitName, orgUnit, sizeof(orgUnit))), 0);
  55977. ExpectIntEQ(XMEMCMP(orgUnit, "Programming-2048", nameSz), 0);
  55978. EVP_PKEY_free(pubKeyTmp);
  55979. X509_free(cert);
  55980. #endif
  55981. return EXPECT_RESULT();
  55982. }
  55983. static int test_wolfSSL_CTX_set_srp_username(void)
  55984. {
  55985. EXPECT_DECLS;
  55986. #if defined(OPENSSL_EXTRA) && defined(WOLFCRYPT_HAVE_SRP) \
  55987. && !defined(NO_SHA256) && !defined(WC_NO_RNG) && !defined(NO_WOLFSSL_CLIENT)
  55988. WOLFSSL_CTX* ctx = NULL;
  55989. WOLFSSL* ssl = NULL;
  55990. const char *username = "TESTUSER";
  55991. const char *password = "TESTPASSWORD";
  55992. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  55993. ExpectIntEQ(wolfSSL_CTX_set_srp_username(ctx, (char *)username),
  55994. SSL_SUCCESS);
  55995. wolfSSL_CTX_free(ctx);
  55996. ctx = NULL;
  55997. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  55998. ExpectIntEQ(wolfSSL_CTX_set_srp_password(ctx, (char *)password),
  55999. SSL_SUCCESS);
  56000. ExpectIntEQ(wolfSSL_CTX_set_srp_username(ctx, (char *)username),
  56001. SSL_SUCCESS);
  56002. ExpectNotNull(ssl = SSL_new(ctx));
  56003. ExpectNotNull(SSL_get_srp_username(ssl));
  56004. ExpectStrEQ(SSL_get_srp_username(ssl), username);
  56005. wolfSSL_free(ssl);
  56006. wolfSSL_CTX_free(ctx);
  56007. #endif /* OPENSSL_EXTRA && WOLFCRYPT_HAVE_SRP */
  56008. /* && !NO_SHA256 && !WC_NO_RNG && !NO_WOLFSSL_CLIENT */
  56009. return EXPECT_RESULT();
  56010. }
  56011. static int test_wolfSSL_CTX_set_srp_password(void)
  56012. {
  56013. EXPECT_DECLS;
  56014. #if defined(OPENSSL_EXTRA) && defined(WOLFCRYPT_HAVE_SRP) && \
  56015. !defined(NO_SHA256) && !defined(WC_NO_RNG) && !defined(NO_WOLFSSL_CLIENT)
  56016. WOLFSSL_CTX* ctx = NULL;
  56017. const char *username = "TESTUSER";
  56018. const char *password = "TESTPASSWORD";
  56019. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  56020. ExpectIntEQ(wolfSSL_CTX_set_srp_password(ctx, (char *)password),
  56021. SSL_SUCCESS);
  56022. wolfSSL_CTX_free(ctx);
  56023. ctx = NULL;
  56024. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  56025. ExpectIntEQ(wolfSSL_CTX_set_srp_username(ctx, (char *)username),
  56026. SSL_SUCCESS);
  56027. ExpectIntEQ(wolfSSL_CTX_set_srp_password(ctx, (char *)password),
  56028. SSL_SUCCESS);
  56029. wolfSSL_CTX_free(ctx);
  56030. #endif /* OPENSSL_EXTRA && WOLFCRYPT_HAVE_SRP */
  56031. /* && !NO_SHA256 && !WC_NO_RNG && !NO_WOLFSSL_CLIENT */
  56032. return EXPECT_RESULT();
  56033. }
  56034. static int test_wolfSSL_X509_STORE(void)
  56035. {
  56036. EXPECT_DECLS;
  56037. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  56038. X509_STORE *store = NULL;
  56039. #ifdef HAVE_CRL
  56040. X509_STORE_CTX *storeCtx = NULL;
  56041. X509 *ca = NULL;
  56042. X509 *cert = NULL;
  56043. const char srvCert[] = "./certs/server-revoked-cert.pem";
  56044. const char caCert[] = "./certs/ca-cert.pem";
  56045. #ifndef WOLFSSL_CRL_ALLOW_MISSING_CDP
  56046. X509_CRL *crl = NULL;
  56047. const char crlPem[] = "./certs/crl/crl.revoked";
  56048. XFILE fp = XBADFILE;
  56049. #endif /* !WOLFSSL_CRL_ALLOW_MISSING_CDP */
  56050. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  56051. ExpectNotNull((ca = wolfSSL_X509_load_certificate_file(caCert,
  56052. SSL_FILETYPE_PEM)));
  56053. ExpectIntEQ(X509_STORE_add_cert(store, ca), SSL_SUCCESS);
  56054. ExpectNotNull((cert = wolfSSL_X509_load_certificate_file(srvCert,
  56055. SSL_FILETYPE_PEM)));
  56056. ExpectNotNull((storeCtx = X509_STORE_CTX_new()));
  56057. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, cert, NULL), SSL_SUCCESS);
  56058. ExpectIntEQ(X509_verify_cert(storeCtx), SSL_SUCCESS);
  56059. X509_STORE_free(store);
  56060. store = NULL;
  56061. X509_STORE_CTX_free(storeCtx);
  56062. storeCtx = NULL;
  56063. X509_free(cert);
  56064. cert = NULL;
  56065. X509_free(ca);
  56066. ca = NULL;
  56067. #ifndef WOLFSSL_CRL_ALLOW_MISSING_CDP
  56068. /* should fail to verify now after adding in CRL */
  56069. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  56070. ExpectNotNull((ca = wolfSSL_X509_load_certificate_file(caCert,
  56071. SSL_FILETYPE_PEM)));
  56072. ExpectIntEQ(X509_STORE_add_cert(store, ca), SSL_SUCCESS);
  56073. ExpectTrue((fp = XFOPEN(crlPem, "rb")) != XBADFILE);
  56074. ExpectNotNull(crl = (X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  56075. NULL, NULL));
  56076. if (fp != XBADFILE)
  56077. XFCLOSE(fp);
  56078. ExpectIntEQ(X509_STORE_add_crl(store, crl), SSL_SUCCESS);
  56079. ExpectIntEQ(X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK),SSL_SUCCESS);
  56080. ExpectNotNull((storeCtx = X509_STORE_CTX_new()));
  56081. ExpectNotNull((cert = wolfSSL_X509_load_certificate_file(srvCert,
  56082. SSL_FILETYPE_PEM)));
  56083. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, cert, NULL), SSL_SUCCESS);
  56084. ExpectIntNE(X509_verify_cert(storeCtx), SSL_SUCCESS);
  56085. ExpectIntEQ(X509_STORE_CTX_get_error(storeCtx),
  56086. WOLFSSL_X509_V_ERR_CERT_REVOKED);
  56087. X509_CRL_free(crl);
  56088. crl = NULL;
  56089. X509_STORE_free(store);
  56090. store = NULL;
  56091. X509_STORE_CTX_free(storeCtx);
  56092. storeCtx = NULL;
  56093. X509_free(cert);
  56094. cert = NULL;
  56095. X509_free(ca);
  56096. ca = NULL;
  56097. #endif /* !WOLFSSL_CRL_ALLOW_MISSING_CDP */
  56098. #endif /* HAVE_CRL */
  56099. #ifndef WOLFCRYPT_ONLY
  56100. {
  56101. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  56102. SSL_CTX* ctx = NULL;
  56103. SSL* ssl = NULL;
  56104. int i;
  56105. for (i = 0; i < 2; i++) {
  56106. #ifndef NO_WOLFSSL_SERVER
  56107. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  56108. #else
  56109. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  56110. #endif
  56111. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  56112. SSL_CTX_set_cert_store(ctx, store);
  56113. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  56114. SSL_CTX_set_cert_store(ctx, store);
  56115. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  56116. ExpectIntEQ(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  56117. SSL_FILETYPE_PEM), SSL_SUCCESS);
  56118. ExpectIntEQ(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  56119. SSL_FILETYPE_PEM), SSL_SUCCESS);
  56120. ExpectNotNull(ssl = SSL_new(ctx));
  56121. if (i == 0) {
  56122. ExpectIntEQ(SSL_set0_verify_cert_store(ssl, store),
  56123. SSL_SUCCESS);
  56124. }
  56125. else {
  56126. ExpectIntEQ(SSL_set1_verify_cert_store(ssl, store), SSL_SUCCESS);
  56127. #ifdef OPENSSL_ALL
  56128. ExpectIntEQ(SSL_CTX_set1_verify_cert_store(ctx, store), SSL_SUCCESS);
  56129. #endif
  56130. }
  56131. if (EXPECT_FAIL() || (i == 1)) {
  56132. X509_STORE_free(store);
  56133. store = NULL;
  56134. }
  56135. SSL_free(ssl);
  56136. ssl = NULL;
  56137. SSL_CTX_free(ctx);
  56138. ctx = NULL;
  56139. }
  56140. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  56141. }
  56142. #endif
  56143. #endif
  56144. return EXPECT_RESULT();
  56145. }
  56146. static int test_wolfSSL_X509_STORE_load_locations(void)
  56147. {
  56148. EXPECT_DECLS;
  56149. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && \
  56150. !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_DIR) && !defined(NO_RSA)
  56151. SSL_CTX *ctx = NULL;
  56152. X509_STORE *store = NULL;
  56153. const char ca_file[] = "./certs/ca-cert.pem";
  56154. const char client_pem_file[] = "./certs/client-cert.pem";
  56155. const char client_der_file[] = "./certs/client-cert.der";
  56156. const char ecc_file[] = "./certs/ecc-key.pem";
  56157. const char certs_path[] = "./certs/";
  56158. const char bad_path[] = "./bad-path/";
  56159. #ifdef HAVE_CRL
  56160. const char crl_path[] = "./certs/crl/";
  56161. const char crl_file[] = "./certs/crl/crl.pem";
  56162. #endif
  56163. #ifndef NO_WOLFSSL_SERVER
  56164. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_server_method()));
  56165. #else
  56166. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_client_method()));
  56167. #endif
  56168. ExpectNotNull(store = SSL_CTX_get_cert_store(ctx));
  56169. ExpectIntEQ(wolfSSL_CertManagerLoadCA(store->cm, ca_file, NULL),
  56170. WOLFSSL_SUCCESS);
  56171. /* Test bad arguments */
  56172. ExpectIntEQ(X509_STORE_load_locations(NULL, ca_file, NULL),
  56173. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56174. ExpectIntEQ(X509_STORE_load_locations(store, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56175. ExpectIntEQ(X509_STORE_load_locations(store, client_der_file, NULL),
  56176. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56177. ExpectIntEQ(X509_STORE_load_locations(store, ecc_file, NULL),
  56178. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56179. ExpectIntEQ(X509_STORE_load_locations(store, NULL, bad_path),
  56180. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56181. #ifdef HAVE_CRL
  56182. /* Test with CRL */
  56183. ExpectIntEQ(X509_STORE_load_locations(store, crl_file, NULL),
  56184. WOLFSSL_SUCCESS);
  56185. ExpectIntEQ(X509_STORE_load_locations(store, NULL, crl_path),
  56186. WOLFSSL_SUCCESS);
  56187. #endif
  56188. /* Test with CA */
  56189. ExpectIntEQ(X509_STORE_load_locations(store, ca_file, NULL),
  56190. WOLFSSL_SUCCESS);
  56191. /* Test with client_cert and certs path */
  56192. ExpectIntEQ(X509_STORE_load_locations(store, client_pem_file, NULL),
  56193. WOLFSSL_SUCCESS);
  56194. ExpectIntEQ(X509_STORE_load_locations(store, NULL, certs_path),
  56195. WOLFSSL_SUCCESS);
  56196. #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
  56197. /* Clear nodes */
  56198. ERR_clear_error();
  56199. #endif
  56200. SSL_CTX_free(ctx);
  56201. #endif
  56202. return EXPECT_RESULT();
  56203. }
  56204. static int test_X509_STORE_get0_objects(void)
  56205. {
  56206. EXPECT_DECLS;
  56207. #if defined(OPENSSL_ALL) && !defined(NO_FILESYSTEM) && \
  56208. !defined(NO_WOLFSSL_DIR) && !defined(NO_RSA)
  56209. X509_STORE *store = NULL;
  56210. X509_STORE *store_cpy = NULL;
  56211. SSL_CTX *ctx = NULL;
  56212. X509_OBJECT *obj = NULL;
  56213. STACK_OF(X509_OBJECT) *objs = NULL;
  56214. int i;
  56215. /* Setup store */
  56216. #ifndef NO_WOLFSSL_SERVER
  56217. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_server_method()));
  56218. #else
  56219. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_client_method()));
  56220. #endif
  56221. ExpectNotNull(store_cpy = X509_STORE_new());
  56222. ExpectNotNull(store = SSL_CTX_get_cert_store(ctx));
  56223. ExpectIntEQ(X509_STORE_load_locations(store, cliCertFile, NULL),
  56224. WOLFSSL_SUCCESS);
  56225. ExpectIntEQ(X509_STORE_load_locations(store, caCertFile, NULL),
  56226. WOLFSSL_SUCCESS);
  56227. ExpectIntEQ(X509_STORE_load_locations(store, svrCertFile, NULL),
  56228. WOLFSSL_SUCCESS);
  56229. #ifdef HAVE_CRL
  56230. ExpectIntEQ(X509_STORE_load_locations(store, NULL, crlPemDir),
  56231. WOLFSSL_SUCCESS);
  56232. #endif
  56233. /* Store ready */
  56234. /* Similar to HaProxy ssl_set_cert_crl_file use case */
  56235. ExpectNotNull(objs = X509_STORE_get0_objects(store));
  56236. #ifdef HAVE_CRL
  56237. #ifdef WOLFSSL_SIGNER_DER_CERT
  56238. ExpectIntEQ(sk_X509_OBJECT_num(objs), 4);
  56239. #else
  56240. ExpectIntEQ(sk_X509_OBJECT_num(objs), 1);
  56241. #endif
  56242. #else
  56243. #ifdef WOLFSSL_SIGNER_DER_CERT
  56244. ExpectIntEQ(sk_X509_OBJECT_num(objs), 3);
  56245. #else
  56246. ExpectIntEQ(sk_X509_OBJECT_num(objs), 0);
  56247. #endif
  56248. #endif
  56249. for (i = 0; i < sk_X509_OBJECT_num(objs); i++) {
  56250. obj = (X509_OBJECT*)sk_X509_OBJECT_value(objs, i);
  56251. switch (X509_OBJECT_get_type(obj)) {
  56252. case X509_LU_X509:
  56253. {
  56254. X509* x509 = NULL;
  56255. X509_NAME *subj_name = NULL;
  56256. ExpectNotNull(x509 = X509_OBJECT_get0_X509(obj));
  56257. ExpectIntEQ(X509_STORE_add_cert(store_cpy, x509), WOLFSSL_SUCCESS);
  56258. ExpectNotNull(subj_name = X509_get_subject_name(x509));
  56259. ExpectPtrEq(obj, X509_OBJECT_retrieve_by_subject(objs, X509_LU_X509,
  56260. subj_name));
  56261. break;
  56262. }
  56263. case X509_LU_CRL:
  56264. #ifdef HAVE_CRL
  56265. {
  56266. X509_CRL* crl = NULL;
  56267. ExpectNotNull(crl = X509_OBJECT_get0_X509_CRL(obj));
  56268. ExpectIntEQ(X509_STORE_add_crl(store_cpy, crl), WOLFSSL_SUCCESS);
  56269. break;
  56270. }
  56271. #endif
  56272. case X509_LU_NONE:
  56273. default:
  56274. Fail(("X509_OBJECT_get_type should return x509 or crl "
  56275. "(when built with crl support)"),
  56276. ("Unrecognized X509_OBJECT type or none"));
  56277. }
  56278. }
  56279. X509_STORE_free(store_cpy);
  56280. SSL_CTX_free(ctx);
  56281. #endif
  56282. return EXPECT_RESULT();
  56283. }
  56284. static int test_wolfSSL_BN_CTX(void)
  56285. {
  56286. EXPECT_DECLS;
  56287. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  56288. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  56289. WOLFSSL_BN_CTX* bn_ctx = NULL;
  56290. WOLFSSL_BIGNUM* t = NULL;
  56291. ExpectNotNull(bn_ctx = wolfSSL_BN_CTX_new());
  56292. /* No implementation. */
  56293. BN_CTX_init(NULL);
  56294. ExpectNotNull(t = BN_CTX_get(NULL));
  56295. BN_free(t);
  56296. ExpectNotNull(t = BN_CTX_get(bn_ctx));
  56297. BN_free(t);
  56298. #ifndef NO_WOLFSSL_STUB
  56299. /* No implementation. */
  56300. BN_CTX_start(NULL);
  56301. BN_CTX_start(bn_ctx);
  56302. #endif
  56303. BN_CTX_free(NULL);
  56304. BN_CTX_free(bn_ctx);
  56305. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  56306. return EXPECT_RESULT();
  56307. }
  56308. static int test_wolfSSL_BN(void)
  56309. {
  56310. EXPECT_DECLS;
  56311. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  56312. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  56313. BIGNUM* a = NULL;
  56314. BIGNUM* b = NULL;
  56315. BIGNUM* c = NULL;
  56316. BIGNUM* d = NULL;
  56317. BIGNUM emptyBN;
  56318. /* Setup */
  56319. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  56320. /* internal not set emptyBN. */
  56321. ExpectNotNull(a = BN_new());
  56322. ExpectNotNull(b = BN_new());
  56323. ExpectNotNull(c = BN_dup(b));
  56324. ExpectNotNull(d = BN_new());
  56325. /* Invalid parameter testing. */
  56326. BN_free(NULL);
  56327. ExpectNull(BN_dup(NULL));
  56328. ExpectNull(BN_dup(&emptyBN));
  56329. ExpectNull(BN_copy(NULL, NULL));
  56330. ExpectNull(BN_copy(b, NULL));
  56331. ExpectNull(BN_copy(NULL, c));
  56332. ExpectNull(BN_copy(b, &emptyBN));
  56333. ExpectNull(BN_copy(&emptyBN, c));
  56334. BN_clear(NULL);
  56335. BN_clear(&emptyBN);
  56336. ExpectIntEQ(BN_num_bytes(NULL), 0);
  56337. ExpectIntEQ(BN_num_bytes(&emptyBN), 0);
  56338. ExpectIntEQ(BN_num_bits(NULL), 0);
  56339. ExpectIntEQ(BN_num_bits(&emptyBN), 0);
  56340. ExpectIntEQ(BN_is_negative(NULL), 0);
  56341. ExpectIntEQ(BN_is_negative(&emptyBN), 0);
  56342. /* END Invalid Parameters */
  56343. ExpectIntEQ(BN_set_word(a, 3), SSL_SUCCESS);
  56344. ExpectIntEQ(BN_set_word(b, 2), SSL_SUCCESS);
  56345. ExpectIntEQ(BN_set_word(c, 5), SSL_SUCCESS);
  56346. ExpectIntEQ(BN_num_bits(a), 2);
  56347. ExpectIntEQ(BN_num_bytes(a), 1);
  56348. #if !defined(WOLFSSL_SP_MATH) && (!defined(WOLFSSL_SP_MATH_ALL) || \
  56349. defined(WOLFSSL_SP_INT_NEGATIVE))
  56350. ExpectIntEQ(BN_set_word(a, 1), SSL_SUCCESS);
  56351. ExpectIntEQ(BN_set_word(b, 5), SSL_SUCCESS);
  56352. ExpectIntEQ(BN_is_word(a, (WOLFSSL_BN_ULONG)BN_get_word(a)), SSL_SUCCESS);
  56353. ExpectIntEQ(BN_is_word(a, 3), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56354. ExpectIntEQ(BN_sub(c, a, b), SSL_SUCCESS);
  56355. #if defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  56356. {
  56357. /* Do additional tests on negative BN conversions. */
  56358. char* ret = NULL;
  56359. ASN1_INTEGER* asn1 = NULL;
  56360. BIGNUM* tmp = NULL;
  56361. /* Sanity check we have a negative BN. */
  56362. ExpectIntEQ(BN_is_negative(c), 1);
  56363. ExpectNotNull(ret = BN_bn2dec(c));
  56364. ExpectIntEQ(XMEMCMP(ret, "-4", sizeof("-4")), 0);
  56365. XFREE(ret, NULL, DYNAMIC_TYPE_OPENSSL);
  56366. ret = NULL;
  56367. /* Convert to ASN1_INTEGER and back to BN. */
  56368. ExpectNotNull(asn1 = BN_to_ASN1_INTEGER(c, NULL));
  56369. ExpectNotNull(tmp = ASN1_INTEGER_to_BN(asn1, NULL));
  56370. /* After converting back BN should be negative and correct. */
  56371. ExpectIntEQ(BN_is_negative(tmp), 1);
  56372. ExpectNotNull(ret = BN_bn2dec(tmp));
  56373. ExpectIntEQ(XMEMCMP(ret, "-4", sizeof("-4")), 0);
  56374. XFREE(ret, NULL, DYNAMIC_TYPE_OPENSSL);
  56375. ASN1_INTEGER_free(asn1);
  56376. BN_free(tmp);
  56377. }
  56378. #endif
  56379. ExpectIntEQ(BN_get_word(c), 4);
  56380. #endif
  56381. ExpectIntEQ(BN_set_word(a, 3), 1);
  56382. ExpectIntEQ(BN_set_word(b, 3), 1);
  56383. ExpectIntEQ(BN_set_word(c, 4), 1);
  56384. /* NULL == NULL, NULL < num, num > NULL */
  56385. ExpectIntEQ(BN_cmp(NULL, NULL), 0);
  56386. ExpectIntEQ(BN_cmp(&emptyBN, &emptyBN), 0);
  56387. ExpectIntLT(BN_cmp(NULL, b), 0);
  56388. ExpectIntLT(BN_cmp(&emptyBN, b), 0);
  56389. ExpectIntGT(BN_cmp(a, NULL), 0);
  56390. ExpectIntGT(BN_cmp(a, &emptyBN), 0);
  56391. ExpectIntEQ(BN_cmp(a, b), 0);
  56392. ExpectIntLT(BN_cmp(a, c), 0);
  56393. ExpectIntGT(BN_cmp(c, b), 0);
  56394. #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM)
  56395. ExpectIntEQ(BN_print_fp(XBADFILE, NULL), 0);
  56396. ExpectIntEQ(BN_print_fp(XBADFILE, &emptyBN), 0);
  56397. ExpectIntEQ(BN_print_fp(stderr, NULL), 0);
  56398. ExpectIntEQ(BN_print_fp(stderr, &emptyBN), 0);
  56399. ExpectIntEQ(BN_print_fp(XBADFILE, a), 0);
  56400. ExpectIntEQ(BN_print_fp(stderr, a), 1);
  56401. #endif
  56402. BN_clear(a);
  56403. BN_free(a);
  56404. BN_free(b);
  56405. BN_free(c);
  56406. BN_clear_free(d);
  56407. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  56408. return EXPECT_RESULT();
  56409. }
  56410. static int test_wolfSSL_BN_init(void)
  56411. {
  56412. EXPECT_DECLS;
  56413. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  56414. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  56415. #if !defined(USE_INTEGER_HEAP_MATH) && !defined(HAVE_WOLF_BIGINT)
  56416. BIGNUM* ap = NULL;
  56417. BIGNUM bv;
  56418. BIGNUM cv;
  56419. BIGNUM dv;
  56420. ExpectNotNull(ap = BN_new());
  56421. BN_init(NULL);
  56422. XMEMSET(&bv, 0, sizeof(bv));
  56423. ExpectNull(BN_dup(&bv));
  56424. BN_init(&bv);
  56425. BN_init(&cv);
  56426. BN_init(&dv);
  56427. ExpectIntEQ(BN_set_word(ap, 3), SSL_SUCCESS);
  56428. ExpectIntEQ(BN_set_word(&bv, 2), SSL_SUCCESS);
  56429. ExpectIntEQ(BN_set_word(&cv, 5), SSL_SUCCESS);
  56430. /* a^b mod c = */
  56431. ExpectIntEQ(BN_mod_exp(&dv, NULL, &bv, &cv, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56432. ExpectIntEQ(BN_mod_exp(&dv, ap, &bv, &cv, NULL), WOLFSSL_SUCCESS);
  56433. /* check result 3^2 mod 5 */
  56434. ExpectIntEQ(BN_get_word(&dv), 4);
  56435. /* a*b mod c = */
  56436. ExpectIntEQ(BN_mod_mul(&dv, NULL, &bv, &cv, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  56437. ExpectIntEQ(BN_mod_mul(&dv, ap, &bv, &cv, NULL), SSL_SUCCESS);
  56438. /* check result 3*2 mod 5 */
  56439. ExpectIntEQ(BN_get_word(&dv), 1);
  56440. BN_free(ap);
  56441. #endif
  56442. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  56443. return EXPECT_RESULT();
  56444. }
  56445. static int test_wolfSSL_BN_enc_dec(void)
  56446. {
  56447. EXPECT_DECLS;
  56448. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && !defined(WOLFSSL_SP_MATH)
  56449. BIGNUM* a = NULL;
  56450. BIGNUM* b = NULL;
  56451. BIGNUM* c = NULL;
  56452. BIGNUM emptyBN;
  56453. char* str = NULL;
  56454. const char* emptyStr = "";
  56455. const char* numberStr = "12345";
  56456. const char* badStr = "g12345";
  56457. #if defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  56458. const char* twoStr = "2";
  56459. #endif
  56460. unsigned char binNum[] = { 0x01, 0x02, 0x03, 0x04, 0x05 };
  56461. unsigned char outNum[5];
  56462. /* Setup */
  56463. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  56464. ExpectNotNull(a = BN_new());
  56465. ExpectNotNull(b = BN_new());
  56466. /* Invalid parameters */
  56467. ExpectIntEQ(BN_bn2bin(NULL, NULL), -1);
  56468. ExpectIntEQ(BN_bn2bin(&emptyBN, NULL), -1);
  56469. ExpectIntEQ(BN_bn2bin(NULL, outNum), -1);
  56470. ExpectIntEQ(BN_bn2bin(&emptyBN, outNum), -1);
  56471. ExpectNull(BN_bn2hex(NULL));
  56472. ExpectNull(BN_bn2hex(&emptyBN));
  56473. ExpectNull(BN_bn2dec(NULL));
  56474. ExpectNull(BN_bn2dec(&emptyBN));
  56475. ExpectNotNull(BN_bin2bn(NULL, sizeof(binNum), a));
  56476. BN_free(a);
  56477. ExpectNotNull(a = BN_new());
  56478. ExpectIntEQ(BN_set_word(a, 2), 1);
  56479. ExpectNull(BN_bin2bn(binNum, -1, a));
  56480. ExpectNull(BN_bin2bn(binNum, -1, NULL));
  56481. ExpectNull(BN_bin2bn(binNum, sizeof(binNum), &emptyBN));
  56482. ExpectIntEQ(BN_hex2bn(NULL, NULL), 0);
  56483. ExpectIntEQ(BN_hex2bn(NULL, numberStr), 0);
  56484. ExpectIntEQ(BN_hex2bn(&a, NULL), 0);
  56485. ExpectIntEQ(BN_hex2bn(&a, emptyStr), 0);
  56486. ExpectIntEQ(BN_hex2bn(&a, badStr), 0);
  56487. ExpectIntEQ(BN_hex2bn(&c, badStr), 0);
  56488. ExpectIntEQ(BN_dec2bn(NULL, NULL), 0);
  56489. ExpectIntEQ(BN_dec2bn(NULL, numberStr), 0);
  56490. ExpectIntEQ(BN_dec2bn(&a, NULL), 0);
  56491. ExpectIntEQ(BN_dec2bn(&a, emptyStr), 0);
  56492. ExpectIntEQ(BN_dec2bn(&a, badStr), 0);
  56493. ExpectIntEQ(BN_dec2bn(&c, badStr), 0);
  56494. ExpectIntEQ(BN_set_word(a, 2), 1);
  56495. ExpectIntEQ(BN_bn2bin(a, NULL), 1);
  56496. ExpectIntEQ(BN_bn2bin(a, outNum), 1);
  56497. ExpectNotNull(BN_bin2bn(outNum, 1, b));
  56498. ExpectIntEQ(BN_cmp(a, b), 0);
  56499. ExpectNotNull(BN_bin2bn(binNum, sizeof(binNum), b));
  56500. ExpectIntEQ(BN_cmp(a, b), -1);
  56501. ExpectNotNull(str = BN_bn2hex(a));
  56502. ExpectNotNull(BN_hex2bn(&b, str));
  56503. ExpectIntEQ(BN_cmp(a, b), 0);
  56504. ExpectNotNull(BN_hex2bn(&b, numberStr));
  56505. ExpectIntEQ(BN_cmp(a, b), -1);
  56506. XFREE(str, NULL, DYNAMIC_TYPE_OPENSSL);
  56507. str = NULL;
  56508. #if defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  56509. ExpectNotNull(str = BN_bn2dec(a));
  56510. ExpectStrEQ(str, twoStr);
  56511. XFREE(str, NULL, DYNAMIC_TYPE_OPENSSL);
  56512. str = NULL;
  56513. #ifndef NO_RSA
  56514. ExpectNotNull(str = BN_bn2dec(a));
  56515. ExpectNotNull(BN_dec2bn(&b, str));
  56516. ExpectIntEQ(BN_cmp(a, b), 0);
  56517. ExpectNotNull(BN_dec2bn(&b, numberStr));
  56518. ExpectIntEQ(BN_cmp(a, b), -1);
  56519. XFREE(str, NULL, DYNAMIC_TYPE_OPENSSL);
  56520. str = NULL;
  56521. #else
  56522. /* No implementation - fail with good parameters. */
  56523. ExpectIntEQ(BN_dec2bn(&a, numberStr), 0);
  56524. #endif
  56525. #endif
  56526. BN_free(b);
  56527. BN_free(a);
  56528. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  56529. return EXPECT_RESULT();
  56530. }
  56531. static int test_wolfSSL_BN_word(void)
  56532. {
  56533. EXPECT_DECLS;
  56534. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && !defined(WOLFSSL_SP_MATH)
  56535. BIGNUM* a = NULL;
  56536. BIGNUM* b = NULL;
  56537. BIGNUM* c = NULL;
  56538. BIGNUM av;
  56539. ExpectNotNull(a = BN_new());
  56540. ExpectNotNull(b = BN_new());
  56541. ExpectNotNull(c = BN_new());
  56542. XMEMSET(&av, 0, sizeof(av));
  56543. /* Invalid parameter. */
  56544. ExpectIntEQ(BN_add_word(NULL, 3), 0);
  56545. ExpectIntEQ(BN_add_word(&av, 3), 0);
  56546. ExpectIntEQ(BN_sub_word(NULL, 3), 0);
  56547. ExpectIntEQ(BN_sub_word(&av, 3), 0);
  56548. ExpectIntEQ(BN_set_word(NULL, 3), 0);
  56549. ExpectIntEQ(BN_set_word(&av, 3), 0);
  56550. ExpectIntEQ(BN_get_word(NULL), 0);
  56551. ExpectIntEQ(BN_get_word(&av), 0);
  56552. ExpectIntEQ(BN_is_word(NULL, 3), 0);
  56553. ExpectIntEQ(BN_is_word(&av, 3), 0);
  56554. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_RSA) || !defined(NO_DH) || \
  56555. !defined(NO_DSA))
  56556. ExpectIntEQ(BN_mod_word(NULL, 3), -1);
  56557. ExpectIntEQ(BN_mod_word(&av, 3), -1);
  56558. #endif
  56559. ExpectIntEQ(BN_one(NULL), 0);
  56560. ExpectIntEQ(BN_one(&av), 0);
  56561. BN_zero(NULL);
  56562. BN_zero(&av);
  56563. ExpectIntEQ(BN_is_one(NULL), 0);
  56564. ExpectIntEQ(BN_is_one(&av), 0);
  56565. ExpectIntEQ(BN_is_zero(NULL), 0);
  56566. ExpectIntEQ(BN_is_zero(&av), 0);
  56567. ExpectIntEQ(BN_set_word(a, 3), 1);
  56568. ExpectIntEQ(BN_set_word(b, 2), 1);
  56569. ExpectIntEQ(BN_set_word(c, 5), 1);
  56570. /* a + 3 = */
  56571. ExpectIntEQ(BN_add_word(a, 3), 1);
  56572. /* check result 3 + 3*/
  56573. ExpectIntEQ(BN_get_word(a), 6);
  56574. ExpectIntEQ(BN_is_word(a, 6), 1);
  56575. ExpectIntEQ(BN_is_word(a, 5), 0);
  56576. /* set a back to 3 */
  56577. ExpectIntEQ(BN_set_word(a, 3), 1);
  56578. /* a - 3 = */
  56579. ExpectIntEQ(BN_sub_word(a, 3), 1);
  56580. /* check result 3 - 3*/
  56581. ExpectIntEQ(BN_get_word(a), 0);
  56582. ExpectIntEQ(BN_one(a), 1);
  56583. ExpectIntEQ(BN_is_word(a, 1), 1);
  56584. ExpectIntEQ(BN_is_word(a, 0), 0);
  56585. ExpectIntEQ(BN_is_one(a), 1);
  56586. ExpectIntEQ(BN_is_zero(a), 0);
  56587. BN_zero(a);
  56588. ExpectIntEQ(BN_is_word(a, 0), 1);
  56589. ExpectIntEQ(BN_is_word(a, 1), 0);
  56590. ExpectIntEQ(BN_is_zero(a), 1);
  56591. ExpectIntEQ(BN_is_one(a), 0);
  56592. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_RSA) || !defined(NO_DH) || \
  56593. !defined(NO_DSA))
  56594. ExpectIntEQ(BN_set_word(a, 5), 1);
  56595. ExpectIntEQ(BN_mod_word(a, 3), 2);
  56596. ExpectIntEQ(BN_mod_word(a, 0), -1);
  56597. #endif
  56598. BN_free(c);
  56599. BN_free(b);
  56600. BN_free(a);
  56601. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  56602. return EXPECT_RESULT();
  56603. }
  56604. static int test_wolfSSL_BN_bits(void)
  56605. {
  56606. EXPECT_DECLS;
  56607. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  56608. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  56609. BIGNUM* a = NULL;
  56610. BIGNUM emptyBN;
  56611. /* Setup */
  56612. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  56613. ExpectNotNull(a = BN_new());
  56614. /* Invalid parameters. */
  56615. ExpectIntEQ(BN_set_bit(NULL, 1), 0);
  56616. ExpectIntEQ(BN_set_bit(&emptyBN, 1), 0);
  56617. ExpectIntEQ(BN_set_bit(a, -1), 0);
  56618. ExpectIntEQ(BN_clear_bit(NULL, 1), 0);
  56619. ExpectIntEQ(BN_clear_bit(&emptyBN, 1), 0);
  56620. ExpectIntEQ(BN_clear_bit(a, -1), 0);
  56621. ExpectIntEQ(BN_is_bit_set(NULL, 1), 0);
  56622. ExpectIntEQ(BN_is_bit_set(&emptyBN, 1), 0);
  56623. ExpectIntEQ(BN_is_bit_set(a, -1), 0);
  56624. ExpectIntEQ(BN_is_odd(NULL), 0);
  56625. ExpectIntEQ(BN_is_odd(&emptyBN), 0);
  56626. ExpectIntEQ(BN_set_word(a, 0), 1);
  56627. ExpectIntEQ(BN_is_zero(a), 1);
  56628. ExpectIntEQ(BN_set_bit(a, 0x45), 1);
  56629. ExpectIntEQ(BN_is_zero(a), 0);
  56630. ExpectIntEQ(BN_is_bit_set(a, 0x45), 1);
  56631. ExpectIntEQ(BN_clear_bit(a, 0x45), 1);
  56632. ExpectIntEQ(BN_is_bit_set(a, 0x45), 0);
  56633. ExpectIntEQ(BN_is_zero(a), 1);
  56634. ExpectIntEQ(BN_set_bit(a, 0), 1);
  56635. ExpectIntEQ(BN_is_odd(a), 1);
  56636. ExpectIntEQ(BN_clear_bit(a, 0), 1);
  56637. ExpectIntEQ(BN_is_odd(a), 0);
  56638. ExpectIntEQ(BN_set_bit(a, 1), 1);
  56639. ExpectIntEQ(BN_is_odd(a), 0);
  56640. ExpectIntEQ(BN_set_bit(a, 129), 1);
  56641. ExpectIntEQ(BN_get_word(a), WOLFSSL_BN_MAX_VAL);
  56642. #ifndef NO_WOLFSSL_STUB
  56643. ExpectIntEQ(BN_mask_bits(a, 1), 0);
  56644. #endif
  56645. BN_free(a);
  56646. #endif
  56647. return EXPECT_RESULT();
  56648. }
  56649. static int test_wolfSSL_BN_shift(void)
  56650. {
  56651. EXPECT_DECLS;
  56652. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  56653. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  56654. BIGNUM* a = NULL;
  56655. BIGNUM* b = NULL;
  56656. BIGNUM emptyBN;
  56657. /* Setup */
  56658. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  56659. ExpectNotNull(a = BN_new());
  56660. ExpectNotNull(b = BN_new());
  56661. /* Invalid parameters. */
  56662. ExpectIntEQ(BN_lshift(NULL, NULL, 1), 0);
  56663. ExpectIntEQ(BN_lshift(&emptyBN, NULL, 1), 0);
  56664. ExpectIntEQ(BN_lshift(NULL, &emptyBN, 1), 0);
  56665. ExpectIntEQ(BN_lshift(b, NULL, 1), 0);
  56666. ExpectIntEQ(BN_lshift(b, &emptyBN, 1), 0);
  56667. ExpectIntEQ(BN_lshift(NULL, a, 1), 0);
  56668. ExpectIntEQ(BN_lshift(&emptyBN, a, 1), 0);
  56669. ExpectIntEQ(BN_lshift(b, a, -1), 0);
  56670. ExpectIntEQ(BN_rshift(NULL, NULL, 1), 0);
  56671. ExpectIntEQ(BN_rshift(&emptyBN, NULL, 1), 0);
  56672. ExpectIntEQ(BN_rshift(NULL, &emptyBN, 1), 0);
  56673. ExpectIntEQ(BN_rshift(b, NULL, 1), 0);
  56674. ExpectIntEQ(BN_rshift(b, &emptyBN, 1), 0);
  56675. ExpectIntEQ(BN_rshift(NULL, a, 1), 0);
  56676. ExpectIntEQ(BN_rshift(&emptyBN, a, 1), 0);
  56677. ExpectIntEQ(BN_rshift(b, a, -1), 0);
  56678. ExpectIntEQ(BN_set_word(a, 1), 1);
  56679. ExpectIntEQ(BN_lshift(b, a, 1), 1);
  56680. ExpectIntEQ(BN_is_word(b, 2), 1);
  56681. ExpectIntEQ(BN_lshift(a, a, 1), 1);
  56682. ExpectIntEQ(BN_is_word(a, 2), 1);
  56683. ExpectIntEQ(BN_rshift(b, a, 1), 1);
  56684. ExpectIntEQ(BN_is_word(b, 1), 1);
  56685. ExpectIntEQ(BN_rshift(a, a, 1), 1);
  56686. ExpectIntEQ(BN_is_word(a, 1), 1);
  56687. BN_free(b);
  56688. BN_free(a);
  56689. #endif
  56690. return EXPECT_RESULT();
  56691. }
  56692. static int test_wolfSSL_BN_math(void)
  56693. {
  56694. EXPECT_DECLS;
  56695. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  56696. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  56697. BIGNUM* a = NULL;
  56698. BIGNUM* b = NULL;
  56699. BIGNUM* r = NULL;
  56700. BIGNUM* rem = NULL;
  56701. BIGNUM emptyBN;
  56702. BN_ULONG val1;
  56703. BN_ULONG val2;
  56704. /* Setup */
  56705. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  56706. ExpectNotNull(a = BN_new());
  56707. ExpectNotNull(b = BN_new());
  56708. ExpectNotNull(r = BN_new());
  56709. ExpectNotNull(rem = BN_new());
  56710. /* Invalid parameters. */
  56711. ExpectIntEQ(BN_add(NULL, NULL, NULL), 0);
  56712. ExpectIntEQ(BN_add(r, NULL, NULL), 0);
  56713. ExpectIntEQ(BN_add(NULL, a, NULL), 0);
  56714. ExpectIntEQ(BN_add(NULL, NULL, b), 0);
  56715. ExpectIntEQ(BN_add(r, a, NULL), 0);
  56716. ExpectIntEQ(BN_add(r, NULL, b), 0);
  56717. ExpectIntEQ(BN_add(NULL, a, b), 0);
  56718. ExpectIntEQ(BN_add(&emptyBN, &emptyBN, &emptyBN), 0);
  56719. ExpectIntEQ(BN_add(r, &emptyBN, &emptyBN), 0);
  56720. ExpectIntEQ(BN_add(&emptyBN, a, &emptyBN), 0);
  56721. ExpectIntEQ(BN_add(&emptyBN, &emptyBN, b), 0);
  56722. ExpectIntEQ(BN_add(r, a, &emptyBN), 0);
  56723. ExpectIntEQ(BN_add(r, &emptyBN, b), 0);
  56724. ExpectIntEQ(BN_add(&emptyBN, a, b), 0);
  56725. ExpectIntEQ(BN_sub(NULL, NULL, NULL), 0);
  56726. ExpectIntEQ(BN_sub(r, NULL, NULL), 0);
  56727. ExpectIntEQ(BN_sub(NULL, a, NULL), 0);
  56728. ExpectIntEQ(BN_sub(NULL, NULL, b), 0);
  56729. ExpectIntEQ(BN_sub(r, a, NULL), 0);
  56730. ExpectIntEQ(BN_sub(r, NULL, b), 0);
  56731. ExpectIntEQ(BN_sub(NULL, a, b), 0);
  56732. ExpectIntEQ(BN_sub(&emptyBN, &emptyBN, &emptyBN), 0);
  56733. ExpectIntEQ(BN_sub(r, &emptyBN, &emptyBN), 0);
  56734. ExpectIntEQ(BN_sub(&emptyBN, a, &emptyBN), 0);
  56735. ExpectIntEQ(BN_sub(&emptyBN, &emptyBN, b), 0);
  56736. ExpectIntEQ(BN_sub(r, a, &emptyBN), 0);
  56737. ExpectIntEQ(BN_sub(r, &emptyBN, b), 0);
  56738. ExpectIntEQ(BN_sub(&emptyBN, a, b), 0);
  56739. ExpectIntEQ(BN_mul(NULL, NULL, NULL, NULL), 0);
  56740. ExpectIntEQ(BN_mul(r, NULL, NULL, NULL), 0);
  56741. ExpectIntEQ(BN_mul(NULL, a, NULL, NULL), 0);
  56742. ExpectIntEQ(BN_mul(NULL, NULL, b, NULL), 0);
  56743. ExpectIntEQ(BN_mul(r, a, NULL, NULL), 0);
  56744. ExpectIntEQ(BN_mul(r, NULL, b, NULL), 0);
  56745. ExpectIntEQ(BN_mul(NULL, a, b, NULL), 0);
  56746. ExpectIntEQ(BN_mul(&emptyBN, &emptyBN, &emptyBN, NULL), 0);
  56747. ExpectIntEQ(BN_mul(r, &emptyBN, &emptyBN, NULL), 0);
  56748. ExpectIntEQ(BN_mul(&emptyBN, a, &emptyBN, NULL), 0);
  56749. ExpectIntEQ(BN_mul(&emptyBN, &emptyBN, b, NULL), 0);
  56750. ExpectIntEQ(BN_mul(r, a, &emptyBN, NULL), 0);
  56751. ExpectIntEQ(BN_mul(r, &emptyBN, b, NULL), 0);
  56752. ExpectIntEQ(BN_mul(&emptyBN, a, b, NULL), 0);
  56753. ExpectIntEQ(BN_div(NULL, NULL, NULL, NULL, NULL), 0);
  56754. ExpectIntEQ(BN_div(r, NULL, NULL, NULL, NULL), 0);
  56755. ExpectIntEQ(BN_div(NULL, rem, NULL, NULL, NULL), 0);
  56756. ExpectIntEQ(BN_div(NULL, NULL, a, NULL, NULL), 0);
  56757. ExpectIntEQ(BN_div(NULL, NULL, NULL, b, NULL), 0);
  56758. ExpectIntEQ(BN_div(NULL, rem, a, b, NULL), 0);
  56759. ExpectIntEQ(BN_div(r, NULL, a, b, NULL), 0);
  56760. ExpectIntEQ(BN_div(r, rem, NULL, b, NULL), 0);
  56761. ExpectIntEQ(BN_div(r, rem, a, NULL, NULL), 0);
  56762. ExpectIntEQ(BN_div(&emptyBN, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  56763. ExpectIntEQ(BN_div(r, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  56764. ExpectIntEQ(BN_div(&emptyBN, rem, &emptyBN, &emptyBN, NULL), 0);
  56765. ExpectIntEQ(BN_div(&emptyBN, &emptyBN, a, &emptyBN, NULL), 0);
  56766. ExpectIntEQ(BN_div(&emptyBN, &emptyBN, &emptyBN, b, NULL), 0);
  56767. ExpectIntEQ(BN_div(&emptyBN, rem, a, b, NULL), 0);
  56768. ExpectIntEQ(BN_div(r, &emptyBN, a, b, NULL), 0);
  56769. ExpectIntEQ(BN_div(r, rem, &emptyBN, b, NULL), 0);
  56770. ExpectIntEQ(BN_div(r, rem, a, &emptyBN, NULL), 0);
  56771. ExpectIntEQ(BN_mod(NULL, NULL, NULL, NULL), 0);
  56772. ExpectIntEQ(BN_mod(r, NULL, NULL, NULL), 0);
  56773. ExpectIntEQ(BN_mod(NULL, a, NULL, NULL), 0);
  56774. ExpectIntEQ(BN_mod(NULL, NULL, b, NULL), 0);
  56775. ExpectIntEQ(BN_mod(r, a, NULL, NULL), 0);
  56776. ExpectIntEQ(BN_mod(r, NULL, b, NULL), 0);
  56777. ExpectIntEQ(BN_mod(NULL, a, b, NULL), 0);
  56778. ExpectIntEQ(BN_mod(&emptyBN, &emptyBN, &emptyBN, NULL), 0);
  56779. ExpectIntEQ(BN_mod(r, &emptyBN, &emptyBN, NULL), 0);
  56780. ExpectIntEQ(BN_mod(&emptyBN, a, &emptyBN, NULL), 0);
  56781. ExpectIntEQ(BN_mod(&emptyBN, &emptyBN, b, NULL), 0);
  56782. ExpectIntEQ(BN_mod(r, a, &emptyBN, NULL), 0);
  56783. ExpectIntEQ(BN_mod(r, &emptyBN, b, NULL), 0);
  56784. ExpectIntEQ(BN_mod(&emptyBN, a, b, NULL), 0);
  56785. /* END Invalid parameters. */
  56786. val1 = 8;
  56787. val2 = 3;
  56788. ExpectIntEQ(BN_set_word(a, val1), 1);
  56789. ExpectIntEQ(BN_set_word(b, val2), 1);
  56790. ExpectIntEQ(BN_add(r, a, b), 1);
  56791. ExpectIntEQ(BN_is_word(r, val1 + val2), 1);
  56792. ExpectIntEQ(BN_sub(r, a, b), 1);
  56793. ExpectIntEQ(BN_is_word(r, val1 - val2), 1);
  56794. ExpectIntEQ(BN_mul(r, a, b, NULL), 1);
  56795. ExpectIntEQ(BN_is_word(r, val1 * val2), 1);
  56796. ExpectIntEQ(BN_div(r, rem, a, b, NULL), 1);
  56797. ExpectIntEQ(BN_is_word(r, val1 / val2), 1);
  56798. ExpectIntEQ(BN_is_word(rem, val1 % val2), 1);
  56799. ExpectIntEQ(BN_mod(r, a, b, NULL), 1);
  56800. ExpectIntEQ(BN_is_word(r, val1 % val2), 1);
  56801. BN_free(rem);
  56802. BN_free(r);
  56803. BN_free(b);
  56804. BN_free(a);
  56805. #endif
  56806. return EXPECT_RESULT();
  56807. }
  56808. static int test_wolfSSL_BN_math_mod(void)
  56809. {
  56810. EXPECT_DECLS;
  56811. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  56812. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  56813. BIGNUM* a = NULL;
  56814. BIGNUM* b = NULL;
  56815. BIGNUM* m = NULL;
  56816. BIGNUM* r = NULL;
  56817. BIGNUM* t = NULL;
  56818. BIGNUM emptyBN;
  56819. BN_ULONG val1;
  56820. BN_ULONG val2;
  56821. BN_ULONG val3;
  56822. /* Setup */
  56823. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  56824. ExpectNotNull(a = BN_new());
  56825. ExpectNotNull(b = BN_new());
  56826. ExpectNotNull(m = BN_new());
  56827. ExpectNotNull(r = BN_new());
  56828. /* Invalid parameters. */
  56829. ExpectIntEQ(BN_mod_add(NULL, NULL, NULL, NULL, NULL), 0);
  56830. ExpectIntEQ(BN_mod_add(r, NULL, NULL, NULL, NULL), 0);
  56831. ExpectIntEQ(BN_mod_add(NULL, a, NULL, NULL, NULL), 0);
  56832. ExpectIntEQ(BN_mod_add(NULL, NULL, b, NULL, NULL), 0);
  56833. ExpectIntEQ(BN_mod_add(NULL, NULL, NULL, m, NULL), 0);
  56834. ExpectIntEQ(BN_mod_add(NULL, a, b, m, NULL), 0);
  56835. ExpectIntEQ(BN_mod_add(r, NULL, b, m, NULL), 0);
  56836. ExpectIntEQ(BN_mod_add(r, a, NULL, m, NULL), 0);
  56837. ExpectIntEQ(BN_mod_add(r, a, m, NULL, NULL), 0);
  56838. ExpectIntEQ(BN_mod_add(&emptyBN, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  56839. ExpectIntEQ(BN_mod_add(r, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  56840. ExpectIntEQ(BN_mod_add(&emptyBN, a, &emptyBN, &emptyBN, NULL), 0);
  56841. ExpectIntEQ(BN_mod_add(&emptyBN, &emptyBN, b, &emptyBN, NULL), 0);
  56842. ExpectIntEQ(BN_mod_add(&emptyBN, &emptyBN, &emptyBN, m, NULL), 0);
  56843. ExpectIntEQ(BN_mod_add(&emptyBN, a, b, m, NULL), 0);
  56844. ExpectIntEQ(BN_mod_add(r, &emptyBN, b, m, NULL), 0);
  56845. ExpectIntEQ(BN_mod_add(r, a, &emptyBN, m, NULL), 0);
  56846. ExpectIntEQ(BN_mod_add(r, a, m, &emptyBN, NULL), 0);
  56847. ExpectIntEQ(BN_mod_mul(NULL, NULL, NULL, NULL, NULL), 0);
  56848. ExpectIntEQ(BN_mod_mul(r, NULL, NULL, NULL, NULL), 0);
  56849. ExpectIntEQ(BN_mod_mul(NULL, a, NULL, NULL, NULL), 0);
  56850. ExpectIntEQ(BN_mod_mul(NULL, NULL, b, NULL, NULL), 0);
  56851. ExpectIntEQ(BN_mod_mul(NULL, NULL, NULL, m, NULL), 0);
  56852. ExpectIntEQ(BN_mod_mul(NULL, a, b, m, NULL), 0);
  56853. ExpectIntEQ(BN_mod_mul(r, NULL, b, m, NULL), 0);
  56854. ExpectIntEQ(BN_mod_mul(r, a, NULL, m, NULL), 0);
  56855. ExpectIntEQ(BN_mod_mul(r, a, m, NULL, NULL), 0);
  56856. ExpectIntEQ(BN_mod_mul(&emptyBN, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  56857. ExpectIntEQ(BN_mod_mul(r, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  56858. ExpectIntEQ(BN_mod_mul(&emptyBN, a, &emptyBN, &emptyBN, NULL), 0);
  56859. ExpectIntEQ(BN_mod_mul(&emptyBN, &emptyBN, b, &emptyBN, NULL), 0);
  56860. ExpectIntEQ(BN_mod_mul(&emptyBN, &emptyBN, &emptyBN, m, NULL), 0);
  56861. ExpectIntEQ(BN_mod_mul(&emptyBN, a, b, m, NULL), 0);
  56862. ExpectIntEQ(BN_mod_mul(r, &emptyBN, b, m, NULL), 0);
  56863. ExpectIntEQ(BN_mod_mul(r, a, &emptyBN, m, NULL), 0);
  56864. ExpectIntEQ(BN_mod_mul(r, a, m, &emptyBN, NULL), 0);
  56865. ExpectIntEQ(BN_mod_exp(NULL, NULL, NULL, NULL, NULL), 0);
  56866. ExpectIntEQ(BN_mod_exp(r, NULL, NULL, NULL, NULL), 0);
  56867. ExpectIntEQ(BN_mod_exp(NULL, a, NULL, NULL, NULL), 0);
  56868. ExpectIntEQ(BN_mod_exp(NULL, NULL, b, NULL, NULL), 0);
  56869. ExpectIntEQ(BN_mod_exp(NULL, NULL, NULL, m, NULL), 0);
  56870. ExpectIntEQ(BN_mod_exp(NULL, a, b, m, NULL), 0);
  56871. ExpectIntEQ(BN_mod_exp(r, NULL, b, m, NULL), 0);
  56872. ExpectIntEQ(BN_mod_exp(r, a, NULL, m, NULL), 0);
  56873. ExpectIntEQ(BN_mod_exp(r, a, m, NULL, NULL), 0);
  56874. ExpectIntEQ(BN_mod_exp(&emptyBN, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  56875. ExpectIntEQ(BN_mod_exp(r, &emptyBN, &emptyBN, &emptyBN, NULL), 0);
  56876. ExpectIntEQ(BN_mod_exp(&emptyBN, a, &emptyBN, &emptyBN, NULL), 0);
  56877. ExpectIntEQ(BN_mod_exp(&emptyBN, &emptyBN, b, &emptyBN, NULL), 0);
  56878. ExpectIntEQ(BN_mod_exp(&emptyBN, &emptyBN, &emptyBN, m, NULL), 0);
  56879. ExpectIntEQ(BN_mod_exp(&emptyBN, a, b, m, NULL), 0);
  56880. ExpectIntEQ(BN_mod_exp(r, &emptyBN, b, m, NULL), 0);
  56881. ExpectIntEQ(BN_mod_exp(r, a, &emptyBN, m, NULL), 0);
  56882. ExpectIntEQ(BN_mod_exp(r, a, m, &emptyBN, NULL), 0);
  56883. ExpectNull(BN_mod_inverse(r, NULL, NULL, NULL));
  56884. ExpectNull(BN_mod_inverse(r, a, NULL, NULL));
  56885. ExpectNull(BN_mod_inverse(r, NULL, m, NULL));
  56886. ExpectNull(BN_mod_inverse(r, NULL, m, NULL));
  56887. ExpectNull(BN_mod_inverse(r, a, NULL, NULL));
  56888. ExpectNull(BN_mod_inverse(&emptyBN, &emptyBN, &emptyBN, NULL));
  56889. ExpectNull(BN_mod_inverse(r, &emptyBN, &emptyBN, NULL));
  56890. ExpectNull(BN_mod_inverse(&emptyBN, a, &emptyBN, NULL));
  56891. ExpectNull(BN_mod_inverse(&emptyBN, &emptyBN, m, NULL));
  56892. ExpectNull(BN_mod_inverse(&emptyBN, a, m, NULL));
  56893. ExpectNull(BN_mod_inverse(r, &emptyBN, m, NULL));
  56894. ExpectNull(BN_mod_inverse(r, a, &emptyBN, NULL));
  56895. /* END Invalid parameters. */
  56896. val1 = 9;
  56897. val2 = 13;
  56898. val3 = 5;
  56899. ExpectIntEQ(BN_set_word(a, val1), 1);
  56900. ExpectIntEQ(BN_set_word(b, val2), 1);
  56901. ExpectIntEQ(BN_set_word(m, val3), 1);
  56902. ExpectIntEQ(BN_mod_add(r, a, b, m, NULL), 1);
  56903. ExpectIntEQ(BN_is_word(r, (val1 + val2) % val3), 1);
  56904. ExpectIntEQ(BN_mod_mul(r, a, b, m, NULL), 1);
  56905. ExpectIntEQ(BN_is_word(r, (val1 * val2) % val3), 1);
  56906. ExpectIntEQ(BN_set_word(a, 2), 1);
  56907. ExpectIntEQ(BN_set_word(b, 3), 1);
  56908. ExpectIntEQ(BN_set_word(m, 5), 1);
  56909. /* (2 ^ 3) % 5 = 8 % 5 = 3 */
  56910. ExpectIntEQ(BN_mod_exp(r, a, b, m, NULL), 1);
  56911. ExpectIntEQ(BN_is_word(r, 3), 1);
  56912. /* (2 * 3) % 5 = 6 % 5 = 1 => inv = 3 */
  56913. ExpectNotNull(BN_mod_inverse(r, a, m, NULL));
  56914. ExpectIntEQ(BN_is_word(r, 3), 1);
  56915. ExpectNotNull(t = BN_mod_inverse(NULL, a, m, NULL));
  56916. ExpectIntEQ(BN_is_word(t, 3), 1);
  56917. BN_free(t);
  56918. /* No inverse case. No inverse when a divides b. */
  56919. ExpectIntEQ(BN_set_word(a, 3), 1);
  56920. ExpectIntEQ(BN_set_word(m, 9), 1);
  56921. ExpectNull(BN_mod_inverse(r, a, m, NULL));
  56922. BN_free(r);
  56923. BN_free(m);
  56924. BN_free(b);
  56925. BN_free(a);
  56926. #endif
  56927. return EXPECT_RESULT();
  56928. }
  56929. static int test_wolfSSL_BN_math_other(void)
  56930. {
  56931. EXPECT_DECLS;
  56932. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  56933. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  56934. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  56935. BIGNUM* a = NULL;
  56936. BIGNUM* b = NULL;
  56937. BIGNUM* r = NULL;
  56938. BIGNUM emptyBN;
  56939. /* Setup */
  56940. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  56941. ExpectNotNull(a = BN_new());
  56942. ExpectNotNull(b = BN_new());
  56943. ExpectNotNull(r = BN_new());
  56944. /* Invalid parameters. */
  56945. ExpectIntEQ(BN_gcd(NULL, NULL, NULL, NULL), 0);
  56946. ExpectIntEQ(BN_gcd(r, NULL, NULL, NULL), 0);
  56947. ExpectIntEQ(BN_gcd(NULL, a, NULL, NULL), 0);
  56948. ExpectIntEQ(BN_gcd(NULL, NULL, b, NULL), 0);
  56949. ExpectIntEQ(BN_gcd(NULL, a, b, NULL), 0);
  56950. ExpectIntEQ(BN_gcd(r, NULL, b, NULL), 0);
  56951. ExpectIntEQ(BN_gcd(r, a, NULL, NULL), 0);
  56952. ExpectIntEQ(BN_gcd(&emptyBN, &emptyBN, &emptyBN, NULL), 0);
  56953. ExpectIntEQ(BN_gcd(r, &emptyBN, &emptyBN, NULL), 0);
  56954. ExpectIntEQ(BN_gcd(&emptyBN, a, &emptyBN, NULL), 0);
  56955. ExpectIntEQ(BN_gcd(&emptyBN, &emptyBN, b, NULL), 0);
  56956. ExpectIntEQ(BN_gcd(&emptyBN, a, b, NULL), 0);
  56957. ExpectIntEQ(BN_gcd(r, &emptyBN, b, NULL), 0);
  56958. ExpectIntEQ(BN_gcd(r, a, &emptyBN, NULL), 0);
  56959. /* END Invalid parameters. */
  56960. /* No common factors between 2 and 3. */
  56961. ExpectIntEQ(BN_set_word(a, 2), 1);
  56962. ExpectIntEQ(BN_set_word(b, 3), 1);
  56963. ExpectIntEQ(BN_gcd(r, a, b, NULL), 1);
  56964. ExpectIntEQ(BN_is_word(r, 1), 1);
  56965. /* 3 is largest value that divides both 6 and 9. */
  56966. ExpectIntEQ(BN_set_word(a, 6), 1);
  56967. ExpectIntEQ(BN_set_word(b, 9), 1);
  56968. ExpectIntEQ(BN_gcd(r, a, b, NULL), 1);
  56969. ExpectIntEQ(BN_is_word(r, 3), 1);
  56970. /* GCD of 0 and 0 is undefined. */
  56971. ExpectIntEQ(BN_set_word(a, 0), 1);
  56972. ExpectIntEQ(BN_set_word(b, 0), 1);
  56973. ExpectIntEQ(BN_gcd(r, a, b, NULL), 0);
  56974. /* Teardown */
  56975. BN_free(r);
  56976. BN_free(b);
  56977. BN_free(a);
  56978. #endif
  56979. #endif
  56980. return EXPECT_RESULT();
  56981. }
  56982. static int test_wolfSSL_BN_rand(void)
  56983. {
  56984. EXPECT_DECLS;
  56985. #if defined(OPENSSL_EXTRA) && !defined(OPENSSL_EXTRA_NO_BN)
  56986. BIGNUM* bn = NULL;
  56987. BIGNUM* range = NULL;
  56988. BIGNUM emptyBN;
  56989. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  56990. ExpectNotNull(bn = BN_new());
  56991. ExpectNotNull(range = BN_new());
  56992. /* Invalid parameters. */
  56993. ExpectIntEQ(BN_rand(NULL, -1, 0, 0), 0);
  56994. ExpectIntEQ(BN_rand(bn, -1, 0, 0), 0);
  56995. ExpectIntEQ(BN_rand(NULL, 1, 0, 0), 0);
  56996. ExpectIntEQ(BN_rand(&emptyBN, -1, 0, 0), 0);
  56997. ExpectIntEQ(BN_rand(bn, -1, 0, 0), 0);
  56998. ExpectIntEQ(BN_rand(&emptyBN, 1, 0, 0), 0);
  56999. ExpectIntEQ(BN_pseudo_rand(NULL, -1, 0, 0), 0);
  57000. ExpectIntEQ(BN_pseudo_rand(bn, -1, 0, 0), 0);
  57001. ExpectIntEQ(BN_pseudo_rand(NULL, 1, 0, 0), 0);
  57002. ExpectIntEQ(BN_pseudo_rand(&emptyBN, -1, 0, 0), 0);
  57003. ExpectIntEQ(BN_pseudo_rand(bn, -1, 0, 0), 0);
  57004. ExpectIntEQ(BN_pseudo_rand(&emptyBN, 1, 0, 0), 0);
  57005. ExpectIntEQ(BN_rand_range(NULL, NULL), 0);
  57006. ExpectIntEQ(BN_rand_range(bn, NULL), 0);
  57007. ExpectIntEQ(BN_rand_range(NULL, range), 0);
  57008. ExpectIntEQ(BN_rand_range(&emptyBN, &emptyBN), 0);
  57009. ExpectIntEQ(BN_rand_range(bn, &emptyBN), 0);
  57010. ExpectIntEQ(BN_rand_range(&emptyBN, range), 0);
  57011. /* 0 bit random value must be 0 and so cannot set bit in any position. */
  57012. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ONE,
  57013. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  57014. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_TWO,
  57015. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  57016. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ANY,
  57017. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  57018. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ONE,
  57019. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  57020. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_TWO,
  57021. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  57022. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ONE,
  57023. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  57024. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_TWO,
  57025. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  57026. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ANY,
  57027. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  57028. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ONE,
  57029. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  57030. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_TWO,
  57031. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  57032. /* 1 bit random value must have no more than one top bit set. */
  57033. ExpectIntEQ(BN_rand(bn, 1, WOLFSSL_BN_RAND_TOP_TWO,
  57034. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  57035. ExpectIntEQ(BN_rand(bn, 1, WOLFSSL_BN_RAND_TOP_TWO,
  57036. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  57037. ExpectIntEQ(BN_pseudo_rand(bn, 1, WOLFSSL_BN_RAND_TOP_TWO,
  57038. WOLFSSL_BN_RAND_BOTTOM_ANY), 0);
  57039. ExpectIntEQ(BN_pseudo_rand(bn, 1, WOLFSSL_BN_RAND_TOP_TWO,
  57040. WOLFSSL_BN_RAND_BOTTOM_ODD), 0);
  57041. /* END Invalid parameters. */
  57042. /* 0 bit random: 0. */
  57043. ExpectIntEQ(BN_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ANY,
  57044. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  57045. ExpectIntEQ(BN_is_zero(bn), 1);
  57046. ExpectIntEQ(BN_set_word(bn, 2), 1); /* Make sure not zero. */
  57047. ExpectIntEQ(BN_pseudo_rand(bn, 0, WOLFSSL_BN_RAND_TOP_ANY,
  57048. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  57049. ExpectIntEQ(BN_is_zero(bn), 1);
  57050. /* 1 bit random: 0 or 1. */
  57051. ExpectIntEQ(BN_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ANY,
  57052. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  57053. ExpectIntLT(BN_get_word(bn), 2); /* Make sure valid range. */
  57054. ExpectIntEQ(BN_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ONE,
  57055. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  57056. ExpectIntEQ(BN_get_word(bn), 1);
  57057. ExpectIntEQ(BN_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ONE,
  57058. WOLFSSL_BN_RAND_BOTTOM_ODD), 1);
  57059. ExpectIntEQ(BN_get_word(bn), 1);
  57060. ExpectIntEQ(BN_pseudo_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ANY,
  57061. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  57062. ExpectIntLT(BN_get_word(bn), 2); /* Make sure valid range. */
  57063. ExpectIntEQ(BN_pseudo_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ONE,
  57064. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  57065. ExpectIntEQ(BN_get_word(bn), 1);
  57066. ExpectIntEQ(BN_pseudo_rand(bn, 1, WOLFSSL_BN_RAND_TOP_ONE,
  57067. WOLFSSL_BN_RAND_BOTTOM_ODD), 1);
  57068. ExpectIntEQ(BN_get_word(bn), 1);
  57069. ExpectIntEQ(BN_rand(bn, 8, WOLFSSL_BN_RAND_TOP_ONE,
  57070. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  57071. ExpectIntEQ(BN_num_bits(bn), 8);
  57072. ExpectIntEQ(BN_is_bit_set(bn, 7), 1);
  57073. ExpectIntEQ(BN_pseudo_rand(bn, 8, WOLFSSL_BN_RAND_TOP_ONE,
  57074. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  57075. ExpectIntEQ(BN_num_bits(bn), 8);
  57076. ExpectIntEQ(BN_is_bit_set(bn, 7), 1);
  57077. ExpectIntEQ(BN_rand(bn, 8, WOLFSSL_BN_RAND_TOP_TWO,
  57078. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  57079. ExpectIntEQ(BN_is_bit_set(bn, 7), 1);
  57080. ExpectIntEQ(BN_is_bit_set(bn, 6), 1);
  57081. ExpectIntEQ(BN_pseudo_rand(bn, 8, WOLFSSL_BN_RAND_TOP_TWO,
  57082. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  57083. ExpectIntEQ(BN_is_bit_set(bn, 7), 1);
  57084. ExpectIntEQ(BN_is_bit_set(bn, 6), 1);
  57085. ExpectIntEQ(BN_rand(bn, 8, WOLFSSL_BN_RAND_TOP_ONE,
  57086. WOLFSSL_BN_RAND_BOTTOM_ODD), 1);
  57087. ExpectIntEQ(BN_is_bit_set(bn, 0), 1);
  57088. ExpectIntEQ(BN_pseudo_rand(bn, 8, WOLFSSL_BN_RAND_TOP_ONE,
  57089. WOLFSSL_BN_RAND_BOTTOM_ODD), 1);
  57090. ExpectIntEQ(BN_is_bit_set(bn, 0), 1);
  57091. /* Regression test: Older versions of wolfSSL_BN_rand would round the
  57092. * requested number of bits up to the nearest multiple of 8. E.g. in this
  57093. * case, requesting a 13-bit random number would actually return a 16-bit
  57094. * random number. */
  57095. ExpectIntEQ(BN_rand(bn, 13, WOLFSSL_BN_RAND_TOP_ONE,
  57096. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  57097. ExpectIntEQ(BN_num_bits(bn), 13);
  57098. ExpectIntEQ(BN_rand(range, 64, WOLFSSL_BN_RAND_TOP_ONE,
  57099. WOLFSSL_BN_RAND_BOTTOM_ANY), 1);
  57100. ExpectIntEQ(BN_rand_range(bn, range), 1);
  57101. ExpectIntEQ(BN_set_word(range, 0), 1);
  57102. ExpectIntEQ(BN_rand_range(bn, range), 1);
  57103. ExpectIntEQ(BN_set_word(range, 1), 1);
  57104. ExpectIntEQ(BN_rand_range(bn, range), 1);
  57105. BN_free(bn);
  57106. BN_free(range);
  57107. #endif
  57108. return EXPECT_RESULT();
  57109. }
  57110. static int test_wolfSSL_BN_prime(void)
  57111. {
  57112. EXPECT_DECLS;
  57113. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
  57114. !defined(OPENSSL_EXTRA_NO_BN) && !defined(WOLFSSL_SP_MATH)
  57115. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_RSA) || !defined(NO_DH) || !defined(NO_DSA))
  57116. BIGNUM* a = NULL;
  57117. BIGNUM* add = NULL;
  57118. BIGNUM* rem = NULL;
  57119. BIGNUM emptyBN;
  57120. XMEMSET(&emptyBN, 0, sizeof(emptyBN));
  57121. ExpectNotNull(a = BN_new());
  57122. ExpectNotNull(add = BN_new());
  57123. ExpectNotNull(rem = BN_new());
  57124. /* Invalid parameters. */
  57125. /* BN_generate_prime_ex()
  57126. * prime - must have valid BIGNUM
  57127. * bits - Greater then 0
  57128. * safe - not supported, must be 0
  57129. * add - not supported, must be NULL
  57130. * rem - not supported, must be NULL
  57131. * cb - anything
  57132. */
  57133. ExpectIntEQ(BN_generate_prime_ex(NULL, -1, 1, add, rem, NULL), 0);
  57134. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, -1, 1, add, rem, NULL), 0);
  57135. ExpectIntEQ(BN_generate_prime_ex(a, -1, 1, add, rem, NULL), 0);
  57136. ExpectIntEQ(BN_generate_prime_ex(NULL, 2, 1, add, rem, NULL), 0);
  57137. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, 2, 1, add, rem, NULL), 0);
  57138. ExpectIntEQ(BN_generate_prime_ex(NULL, -1, 0, add, rem, NULL), 0);
  57139. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, -1, 0, add, rem, NULL), 0);
  57140. ExpectIntEQ(BN_generate_prime_ex(NULL, -1, 1, NULL, rem, NULL), 0);
  57141. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, -1, 1, NULL, rem, NULL), 0);
  57142. ExpectIntEQ(BN_generate_prime_ex(NULL, -1, 1, add, NULL, NULL), 0);
  57143. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, -1, 1, add, NULL, NULL), 0);
  57144. ExpectIntEQ(BN_generate_prime_ex(NULL, 2, 0, NULL, NULL, NULL), 0);
  57145. ExpectIntEQ(BN_generate_prime_ex(&emptyBN, 2, 0, NULL, NULL, NULL), 0);
  57146. ExpectIntEQ(BN_generate_prime_ex(a, -1, 0, NULL, NULL, NULL), 0);
  57147. ExpectIntEQ(BN_generate_prime_ex(a, 0, 0, NULL, NULL, NULL), 0);
  57148. ExpectIntEQ(BN_generate_prime_ex(a, 2, 1, NULL, NULL, NULL), 0);
  57149. ExpectIntEQ(BN_generate_prime_ex(a, 2, 0, add, NULL, NULL), 0);
  57150. ExpectIntEQ(BN_generate_prime_ex(a, 2, 0, NULL, rem, NULL), 0);
  57151. ExpectIntEQ(BN_is_prime_ex(NULL, -1, NULL, NULL), -1);
  57152. ExpectIntEQ(BN_is_prime_ex(&emptyBN, -1, NULL, NULL), -1);
  57153. ExpectIntEQ(BN_is_prime_ex(a, -1, NULL, NULL), -1);
  57154. ExpectIntEQ(BN_is_prime_ex(a, 2048, NULL, NULL), -1);
  57155. ExpectIntEQ(BN_is_prime_ex(NULL, 1, NULL, NULL), -1);
  57156. ExpectIntEQ(BN_is_prime_ex(&emptyBN, 1, NULL, NULL), -1);
  57157. /* END Invalid parameters. */
  57158. ExpectIntEQ(BN_generate_prime_ex(a, 512, 0, NULL, NULL, NULL), 1);
  57159. ExpectIntEQ(BN_is_prime_ex(a, 8, NULL, NULL), 1);
  57160. ExpectIntEQ(BN_clear_bit(a, 0), 1);
  57161. ExpectIntEQ(BN_is_prime_ex(a, 8, NULL, NULL), 0);
  57162. BN_free(rem);
  57163. BN_free(add);
  57164. BN_free(a);
  57165. #endif
  57166. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_ASN) */
  57167. return EXPECT_RESULT();
  57168. }
  57169. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  57170. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  57171. #define TEST_ARG 0x1234
  57172. static void msg_cb(int write_p, int version, int content_type,
  57173. const void *buf, size_t len, SSL *ssl, void *arg)
  57174. {
  57175. (void)write_p;
  57176. (void)version;
  57177. (void)content_type;
  57178. (void)buf;
  57179. (void)len;
  57180. (void)ssl;
  57181. AssertTrue(arg == (void*)TEST_ARG);
  57182. }
  57183. #endif
  57184. #if defined(OPENSSL_EXTRA) && defined(DEBUG_WOLFSSL) && \
  57185. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  57186. #if defined(SESSION_CERTS)
  57187. #include "wolfssl/internal.h"
  57188. #endif
  57189. static int msgCb(SSL_CTX *ctx, SSL *ssl)
  57190. {
  57191. EXPECT_DECLS;
  57192. #if defined(OPENSSL_ALL) && defined(SESSION_CERTS) && !defined(NO_BIO)
  57193. STACK_OF(X509)* sk = NULL;
  57194. X509* x509 = NULL;
  57195. int i, num;
  57196. BIO* bio = NULL;
  57197. #endif
  57198. ExpectNotNull(ctx);
  57199. ExpectNotNull(ssl);
  57200. fprintf(stderr, "\n===== msgcb called ====\n");
  57201. #if defined(SESSION_CERTS) && defined(TEST_PEER_CERT_CHAIN)
  57202. ExpectTrue(SSL_get_peer_cert_chain(ssl) != NULL);
  57203. ExpectIntEQ(((WOLFSSL_X509_CHAIN *)SSL_get_peer_cert_chain(ssl))->count, 2);
  57204. ExpectNotNull(SSL_get0_verified_chain(ssl));
  57205. #endif
  57206. #if defined(OPENSSL_ALL) && defined(SESSION_CERTS) && !defined(NO_BIO)
  57207. ExpectNotNull(bio = BIO_new_fp(stderr, BIO_NOCLOSE));
  57208. ExpectNotNull(sk = SSL_get_peer_cert_chain(ssl));
  57209. if (sk == NULL) {
  57210. BIO_free(bio);
  57211. return TEST_FAIL;
  57212. }
  57213. num = sk_X509_num(sk);
  57214. ExpectTrue(num > 0);
  57215. for (i = 0; i < num; i++) {
  57216. ExpectNotNull(x509 = sk_X509_value(sk,i));
  57217. if (x509 == NULL)
  57218. break;
  57219. fprintf(stderr, "Certificate at index [%d] = :\n",i);
  57220. X509_print(bio,x509);
  57221. fprintf(stderr, "\n\n");
  57222. }
  57223. BIO_free(bio);
  57224. #endif
  57225. return EXPECT_RESULT();
  57226. }
  57227. #endif
  57228. static int test_wolfSSL_msgCb(void)
  57229. {
  57230. EXPECT_DECLS;
  57231. #if defined(OPENSSL_EXTRA) && defined(DEBUG_WOLFSSL) && \
  57232. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  57233. test_ssl_cbf client_cb;
  57234. test_ssl_cbf server_cb;
  57235. XMEMSET(&client_cb, 0, sizeof(client_cb));
  57236. XMEMSET(&server_cb, 0, sizeof(server_cb));
  57237. #ifndef WOLFSSL_NO_TLS12
  57238. client_cb.method = wolfTLSv1_2_client_method;
  57239. server_cb.method = wolfTLSv1_2_server_method;
  57240. #else
  57241. client_cb.method = wolfTLSv1_3_client_method;
  57242. server_cb.method = wolfTLSv1_3_server_method;
  57243. #endif
  57244. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb,
  57245. &server_cb, msgCb), TEST_SUCCESS);
  57246. #endif
  57247. return EXPECT_RESULT();
  57248. }
  57249. static int test_wolfSSL_either_side(void)
  57250. {
  57251. EXPECT_DECLS;
  57252. #if (defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)) && \
  57253. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  57254. test_ssl_cbf client_cb;
  57255. test_ssl_cbf server_cb;
  57256. XMEMSET(&client_cb, 0, sizeof(client_cb));
  57257. XMEMSET(&server_cb, 0, sizeof(server_cb));
  57258. /* Use different CTX for client and server */
  57259. client_cb.ctx = wolfSSL_CTX_new(wolfSSLv23_method());
  57260. ExpectNotNull(client_cb.ctx);
  57261. server_cb.ctx = wolfSSL_CTX_new(wolfSSLv23_method());
  57262. ExpectNotNull(server_cb.ctx);
  57263. /* we are responsible for free'ing WOLFSSL_CTX */
  57264. server_cb.isSharedCtx = client_cb.isSharedCtx = 1;
  57265. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb,
  57266. &server_cb, NULL), TEST_SUCCESS);
  57267. wolfSSL_CTX_free(client_cb.ctx);
  57268. wolfSSL_CTX_free(server_cb.ctx);
  57269. #endif
  57270. return EXPECT_RESULT();
  57271. }
  57272. static int test_wolfSSL_DTLS_either_side(void)
  57273. {
  57274. EXPECT_DECLS;
  57275. #if (defined(OPENSSL_EXTRA) || defined(WOLFSSL_EITHER_SIDE)) && \
  57276. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS)
  57277. test_ssl_cbf client_cb;
  57278. test_ssl_cbf server_cb;
  57279. XMEMSET(&client_cb, 0, sizeof(client_cb));
  57280. XMEMSET(&server_cb, 0, sizeof(server_cb));
  57281. /* Use different CTX for client and server */
  57282. client_cb.ctx = wolfSSL_CTX_new(wolfDTLS_method());
  57283. ExpectNotNull(client_cb.ctx);
  57284. server_cb.ctx = wolfSSL_CTX_new(wolfDTLS_method());
  57285. ExpectNotNull(server_cb.ctx);
  57286. /* we are responsible for free'ing WOLFSSL_CTX */
  57287. server_cb.isSharedCtx = client_cb.isSharedCtx = 1;
  57288. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cb,
  57289. &server_cb, NULL), TEST_SUCCESS);
  57290. wolfSSL_CTX_free(client_cb.ctx);
  57291. wolfSSL_CTX_free(server_cb.ctx);
  57292. #endif
  57293. return EXPECT_RESULT();
  57294. }
  57295. static int test_generate_cookie(void)
  57296. {
  57297. EXPECT_DECLS;
  57298. #if defined(WOLFSSL_DTLS) && defined(OPENSSL_EXTRA) && defined(USE_WOLFSSL_IO)
  57299. SSL_CTX* ctx = NULL;
  57300. SSL* ssl = NULL;
  57301. byte buf[FOURK_BUF] = {0};
  57302. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLS_method()));
  57303. ExpectNotNull(ssl = SSL_new(ctx));
  57304. /* Test unconnected */
  57305. ExpectIntEQ(EmbedGenerateCookie(ssl, buf, FOURK_BUF, NULL), WC_NO_ERR_TRACE(GEN_COOKIE_E));
  57306. wolfSSL_CTX_SetGenCookie(ctx, EmbedGenerateCookie);
  57307. wolfSSL_SetCookieCtx(ssl, ctx);
  57308. ExpectNotNull(wolfSSL_GetCookieCtx(ssl));
  57309. ExpectNull(wolfSSL_GetCookieCtx(NULL));
  57310. SSL_free(ssl);
  57311. SSL_CTX_free(ctx);
  57312. #endif
  57313. return EXPECT_RESULT();
  57314. }
  57315. static int test_wolfSSL_set_options(void)
  57316. {
  57317. EXPECT_DECLS;
  57318. #if !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  57319. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  57320. WOLFSSL* ssl = NULL;
  57321. WOLFSSL_CTX* ctx = NULL;
  57322. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
  57323. char appData[] = "extra msg";
  57324. #endif
  57325. #ifdef OPENSSL_EXTRA
  57326. unsigned char protos[] = {
  57327. 7, 't', 'l', 's', '/', '1', '.', '2',
  57328. 8, 'h', 't', 't', 'p', '/', '1', '.', '1'
  57329. };
  57330. unsigned int len = sizeof(protos);
  57331. void *arg = (void *)TEST_ARG;
  57332. #endif
  57333. #ifndef NO_WOLFSSL_SERVER
  57334. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  57335. #else
  57336. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  57337. #endif
  57338. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  57339. WOLFSSL_FILETYPE_PEM));
  57340. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  57341. WOLFSSL_FILETYPE_PEM));
  57342. ExpectTrue(wolfSSL_CTX_set_options(ctx, WOLFSSL_OP_NO_TLSv1)
  57343. == WOLFSSL_OP_NO_TLSv1);
  57344. ExpectTrue(wolfSSL_CTX_get_options(ctx) == WOLFSSL_OP_NO_TLSv1);
  57345. ExpectIntGT((int)wolfSSL_CTX_set_options(ctx, (WOLFSSL_OP_COOKIE_EXCHANGE |
  57346. WOLFSSL_OP_NO_SSLv2)), 0);
  57347. ExpectTrue((wolfSSL_CTX_set_options(ctx, WOLFSSL_OP_COOKIE_EXCHANGE) &
  57348. WOLFSSL_OP_COOKIE_EXCHANGE) == WOLFSSL_OP_COOKIE_EXCHANGE);
  57349. ExpectTrue((wolfSSL_CTX_set_options(ctx, WOLFSSL_OP_NO_TLSv1_2) &
  57350. WOLFSSL_OP_NO_TLSv1_2) == WOLFSSL_OP_NO_TLSv1_2);
  57351. ExpectTrue((wolfSSL_CTX_set_options(ctx, WOLFSSL_OP_NO_COMPRESSION) &
  57352. WOLFSSL_OP_NO_COMPRESSION) == WOLFSSL_OP_NO_COMPRESSION);
  57353. ExpectFalse((wolfSSL_CTX_clear_options(ctx, WOLFSSL_OP_NO_COMPRESSION) &
  57354. WOLFSSL_OP_NO_COMPRESSION));
  57355. wolfSSL_CTX_free(ctx);
  57356. ctx = NULL;
  57357. #ifndef NO_WOLFSSL_SERVER
  57358. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  57359. #else
  57360. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  57361. #endif
  57362. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  57363. WOLFSSL_FILETYPE_PEM));
  57364. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  57365. WOLFSSL_FILETYPE_PEM));
  57366. #ifdef OPENSSL_EXTRA
  57367. ExpectTrue(wolfSSL_CTX_set_msg_callback(ctx, msg_cb) == WOLFSSL_SUCCESS);
  57368. #endif
  57369. ExpectNotNull(ssl = wolfSSL_new(ctx));
  57370. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
  57371. #ifdef HAVE_EX_DATA
  57372. ExpectIntEQ(wolfSSL_set_app_data(ssl, (void*)appData), WOLFSSL_SUCCESS);
  57373. ExpectNotNull(wolfSSL_get_app_data((const WOLFSSL*)ssl));
  57374. if (ssl != NULL) {
  57375. ExpectIntEQ(XMEMCMP(wolfSSL_get_app_data((const WOLFSSL*)ssl),
  57376. appData, sizeof(appData)), 0);
  57377. }
  57378. #else
  57379. ExpectIntEQ(wolfSSL_set_app_data(ssl, (void*)appData), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57380. ExpectNull(wolfSSL_get_app_data((const WOLFSSL*)ssl));
  57381. #endif
  57382. #endif
  57383. ExpectTrue(wolfSSL_set_options(ssl, WOLFSSL_OP_NO_TLSv1) ==
  57384. WOLFSSL_OP_NO_TLSv1);
  57385. ExpectTrue(wolfSSL_get_options(ssl) == WOLFSSL_OP_NO_TLSv1);
  57386. ExpectIntGT((int)wolfSSL_set_options(ssl, (WOLFSSL_OP_COOKIE_EXCHANGE |
  57387. WOLFSSL_OP_NO_SSLv2)), 0);
  57388. ExpectTrue((wolfSSL_set_options(ssl, WOLFSSL_OP_COOKIE_EXCHANGE) &
  57389. WOLFSSL_OP_COOKIE_EXCHANGE) == WOLFSSL_OP_COOKIE_EXCHANGE);
  57390. ExpectTrue((wolfSSL_set_options(ssl, WOLFSSL_OP_NO_TLSv1_2) &
  57391. WOLFSSL_OP_NO_TLSv1_2) == WOLFSSL_OP_NO_TLSv1_2);
  57392. ExpectTrue((wolfSSL_set_options(ssl, WOLFSSL_OP_NO_COMPRESSION) &
  57393. WOLFSSL_OP_NO_COMPRESSION) == WOLFSSL_OP_NO_COMPRESSION);
  57394. #ifdef OPENSSL_EXTRA
  57395. ExpectFalse((wolfSSL_clear_options(ssl, WOLFSSL_OP_NO_COMPRESSION) &
  57396. WOLFSSL_OP_NO_COMPRESSION));
  57397. #endif
  57398. #ifdef OPENSSL_EXTRA
  57399. ExpectTrue(wolfSSL_set_msg_callback(ssl, msg_cb) == WOLFSSL_SUCCESS);
  57400. wolfSSL_set_msg_callback_arg(ssl, arg);
  57401. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  57402. ExpectTrue(wolfSSL_CTX_set_alpn_protos(ctx, protos, len) == 0);
  57403. #else
  57404. ExpectTrue(wolfSSL_CTX_set_alpn_protos(ctx, protos, len) == WOLFSSL_SUCCESS);
  57405. #endif
  57406. #endif
  57407. #if defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY) || \
  57408. defined(WOLFSSL_MYSQL_COMPATIBLE) || defined(OPENSSL_ALL) || \
  57409. defined(HAVE_LIGHTY) || defined(HAVE_STUNNEL)
  57410. #if defined(HAVE_ALPN) && !defined(NO_BIO)
  57411. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  57412. ExpectTrue(wolfSSL_set_alpn_protos(ssl, protos, len) == 0);
  57413. #else
  57414. ExpectTrue(wolfSSL_set_alpn_protos(ssl, protos, len) == WOLFSSL_SUCCESS);
  57415. #endif
  57416. #endif /* HAVE_ALPN && !NO_BIO */
  57417. #endif
  57418. wolfSSL_free(ssl);
  57419. wolfSSL_CTX_free(ctx);
  57420. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  57421. #endif /* !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  57422. return EXPECT_RESULT();
  57423. }
  57424. static int test_wolfSSL_sk_SSL_CIPHER(void)
  57425. {
  57426. EXPECT_DECLS;
  57427. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  57428. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  57429. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  57430. SSL* ssl = NULL;
  57431. SSL_CTX* ctx = NULL;
  57432. STACK_OF(SSL_CIPHER) *sk = NULL;
  57433. STACK_OF(SSL_CIPHER) *dupSk = NULL;
  57434. #ifndef NO_WOLFSSL_SERVER
  57435. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  57436. #else
  57437. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  57438. #endif
  57439. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile, SSL_FILETYPE_PEM));
  57440. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  57441. ExpectNotNull(ssl = SSL_new(ctx));
  57442. ExpectNotNull(sk = SSL_get_ciphers(ssl));
  57443. ExpectNotNull(dupSk = sk_SSL_CIPHER_dup(sk));
  57444. ExpectIntGT(sk_SSL_CIPHER_num(sk), 0);
  57445. ExpectIntEQ(sk_SSL_CIPHER_num(sk), sk_SSL_CIPHER_num(dupSk));
  57446. /* error case because connection has not been established yet */
  57447. ExpectIntEQ(sk_SSL_CIPHER_find(sk, SSL_get_current_cipher(ssl)), -1);
  57448. sk_SSL_CIPHER_free(dupSk);
  57449. /* sk is pointer to internal struct that should be free'd in SSL_free */
  57450. SSL_free(ssl);
  57451. SSL_CTX_free(ctx);
  57452. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  57453. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  57454. !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  57455. return EXPECT_RESULT();
  57456. }
  57457. static int test_wolfSSL_set1_curves_list(void)
  57458. {
  57459. EXPECT_DECLS;
  57460. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  57461. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  57462. SSL* ssl = NULL;
  57463. SSL_CTX* ctx = NULL;
  57464. #ifndef NO_WOLFSSL_SERVER
  57465. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  57466. #else
  57467. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  57468. #endif
  57469. ExpectTrue(SSL_CTX_use_certificate_file(ctx, eccCertFile,
  57470. SSL_FILETYPE_PEM));
  57471. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, eccKeyFile, SSL_FILETYPE_PEM));
  57472. ExpectNotNull(ssl = SSL_new(ctx));
  57473. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57474. #ifdef HAVE_ECC
  57475. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "P-25X"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57476. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "P-256"), WOLFSSL_SUCCESS);
  57477. #endif
  57478. #ifdef HAVE_CURVE25519
  57479. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "X25519"), WOLFSSL_SUCCESS);
  57480. #else
  57481. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "X25519"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57482. #endif
  57483. #ifdef HAVE_CURVE448
  57484. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "X448"), WOLFSSL_SUCCESS);
  57485. #else
  57486. ExpectIntEQ(SSL_CTX_set1_curves_list(ctx, "X448"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57487. #endif
  57488. ExpectIntEQ(SSL_set1_curves_list(ssl, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57489. #ifdef HAVE_ECC
  57490. ExpectIntEQ(SSL_set1_curves_list(ssl, "P-25X"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57491. ExpectIntEQ(SSL_set1_curves_list(ssl, "P-256"), WOLFSSL_SUCCESS);
  57492. #endif
  57493. #ifdef HAVE_CURVE25519
  57494. ExpectIntEQ(SSL_set1_curves_list(ssl, "X25519"), WOLFSSL_SUCCESS);
  57495. #else
  57496. ExpectIntEQ(SSL_set1_curves_list(ssl, "X25519"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57497. #endif
  57498. #ifdef HAVE_CURVE448
  57499. ExpectIntEQ(SSL_set1_curves_list(ssl, "X448"), WOLFSSL_SUCCESS);
  57500. #else
  57501. ExpectIntEQ(SSL_set1_curves_list(ssl, "X448"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57502. #endif
  57503. SSL_free(ssl);
  57504. SSL_CTX_free(ctx);
  57505. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  57506. #endif
  57507. return EXPECT_RESULT();
  57508. }
  57509. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  57510. (defined(OPENSSL_EXTRA) || defined(HAVE_CURL)) && defined(HAVE_ECC)
  57511. static int test_wolfSSL_curves_mismatch_ctx_ready(WOLFSSL_CTX* ctx)
  57512. {
  57513. static int counter = 0;
  57514. EXPECT_DECLS;
  57515. if (counter % 2) {
  57516. ExpectIntEQ(wolfSSL_CTX_set1_curves_list(ctx, "P-256"),
  57517. WOLFSSL_SUCCESS);
  57518. }
  57519. else {
  57520. ExpectIntEQ(wolfSSL_CTX_set1_curves_list(ctx, "P-384"),
  57521. WOLFSSL_SUCCESS);
  57522. }
  57523. /* Ciphersuites that require curves */
  57524. wolfSSL_CTX_set_cipher_list(ctx, "TLS13-AES256-GCM-SHA384:"
  57525. "TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES128-GCM-SHA256:"
  57526. "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:"
  57527. "ECDHE-ECDSA-AES128-GCM-SHA256:"
  57528. "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-CHACHA20-POLY1305:"
  57529. "ECDHE-ECDSA-CHACHA20-POLY1305");
  57530. counter++;
  57531. return EXPECT_RESULT();
  57532. }
  57533. #endif
  57534. static int test_wolfSSL_curves_mismatch(void)
  57535. {
  57536. EXPECT_DECLS;
  57537. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  57538. (defined(OPENSSL_EXTRA) || defined(HAVE_CURL)) && defined(HAVE_ECC)
  57539. test_ssl_cbf func_cb_client;
  57540. test_ssl_cbf func_cb_server;
  57541. size_t i;
  57542. struct {
  57543. method_provider client_meth;
  57544. method_provider server_meth;
  57545. const char* desc;
  57546. int client_last_err;
  57547. int server_last_err;
  57548. } test_params[] = {
  57549. #ifdef WOLFSSL_TLS13
  57550. {wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLS 1.3",
  57551. WC_NO_ERR_TRACE(FATAL_ERROR), WC_NO_ERR_TRACE(BAD_KEY_SHARE_DATA)},
  57552. #endif
  57553. #ifndef WOLFSSL_NO_TLS12
  57554. {wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLS 1.2",
  57555. WC_NO_ERR_TRACE(FATAL_ERROR),
  57556. #ifdef OPENSSL_EXTRA
  57557. WC_NO_ERR_TRACE(WOLFSSL_ERROR_SYSCALL)
  57558. #else
  57559. WC_NO_ERR_TRACE(MATCH_SUITE_ERROR)
  57560. #endif
  57561. },
  57562. #endif
  57563. #ifndef NO_OLD_TLS
  57564. {wolfTLSv1_1_client_method, wolfTLSv1_1_server_method, "TLS 1.1",
  57565. WC_NO_ERR_TRACE(FATAL_ERROR),
  57566. #ifdef OPENSSL_EXTRA
  57567. WC_NO_ERR_TRACE(WOLFSSL_ERROR_SYSCALL)
  57568. #else
  57569. WC_NO_ERR_TRACE(MATCH_SUITE_ERROR)
  57570. #endif
  57571. },
  57572. #endif
  57573. };
  57574. for (i = 0; i < XELEM_CNT(test_params) && !EXPECT_FAIL(); i++) {
  57575. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  57576. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  57577. printf("\tTesting with %s...\n", test_params[i].desc);
  57578. func_cb_client.ctx_ready = &test_wolfSSL_curves_mismatch_ctx_ready;
  57579. func_cb_server.ctx_ready = &test_wolfSSL_curves_mismatch_ctx_ready;
  57580. func_cb_client.method = test_params[i].client_meth;
  57581. func_cb_server.method = test_params[i].server_meth;
  57582. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  57583. &func_cb_server, NULL), -1001);
  57584. ExpectIntEQ(func_cb_client.last_err, test_params[i].client_last_err);
  57585. ExpectIntEQ(func_cb_server.last_err, test_params[i].server_last_err);
  57586. if (!EXPECT_SUCCESS())
  57587. break;
  57588. printf("\t%s passed\n", test_params[i].desc);
  57589. }
  57590. #endif
  57591. return EXPECT_RESULT();
  57592. }
  57593. static int test_wolfSSL_set1_sigalgs_list(void)
  57594. {
  57595. EXPECT_DECLS;
  57596. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  57597. #if !defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)
  57598. SSL* ssl = NULL;
  57599. SSL_CTX* ctx = NULL;
  57600. #ifndef NO_WOLFSSL_SERVER
  57601. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  57602. #else
  57603. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  57604. #endif
  57605. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  57606. SSL_FILETYPE_PEM));
  57607. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  57608. ExpectNotNull(ssl = SSL_new(ctx));
  57609. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57610. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57611. ExpectIntEQ(wolfSSL_set1_sigalgs_list(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57612. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57613. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, ""), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57614. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, ""), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57615. #ifndef NO_RSA
  57616. #ifndef NO_SHA256
  57617. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(NULL, "RSA+SHA256"),
  57618. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57619. ExpectIntEQ(wolfSSL_set1_sigalgs_list(NULL, "RSA+SHA256"),
  57620. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57621. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA+SHA256"),
  57622. WOLFSSL_SUCCESS);
  57623. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA+SHA256"),
  57624. WOLFSSL_SUCCESS);
  57625. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA-SHA256"),
  57626. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57627. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA-SHA256"),
  57628. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57629. #ifdef WC_RSA_PSS
  57630. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA-PSS+SHA256"),
  57631. WOLFSSL_SUCCESS);
  57632. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA-PSS+SHA256"),
  57633. WOLFSSL_SUCCESS);
  57634. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "PSS+SHA256"),
  57635. WOLFSSL_SUCCESS);
  57636. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "PSS+SHA256"),
  57637. WOLFSSL_SUCCESS);
  57638. #endif
  57639. #ifdef WOLFSSL_SHA512
  57640. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx,
  57641. "RSA+SHA256:RSA+SHA512"), WOLFSSL_SUCCESS);
  57642. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl,
  57643. "RSA+SHA256:RSA+SHA512"), WOLFSSL_SUCCESS);
  57644. #elif defined(WOLFSSL_SHA384)
  57645. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx,
  57646. "RSA+SHA256:RSA+SHA384"), WOLFSSL_SUCCESS);
  57647. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl,
  57648. "RSA+SHA256:RSA+SHA384"), WOLFSSL_SUCCESS);
  57649. #endif
  57650. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57651. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57652. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA:RSA+SHA256"),
  57653. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57654. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA:RSA+SHA256"),
  57655. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57656. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "RSA+SHA256+SHA256"),
  57657. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57658. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "RSA+SHA256+RSA"),
  57659. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57660. #endif
  57661. #endif
  57662. #ifdef HAVE_ECC
  57663. #ifndef NO_SHA256
  57664. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "ECDSA+SHA256"),
  57665. WOLFSSL_SUCCESS);
  57666. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "ECDSA+SHA256"),
  57667. WOLFSSL_SUCCESS);
  57668. #ifdef WOLFSSL_SHA512
  57669. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx,
  57670. "ECDSA+SHA256:ECDSA+SHA512"), WOLFSSL_SUCCESS);
  57671. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl,
  57672. "ECDSA+SHA256:ECDSA+SHA512"), WOLFSSL_SUCCESS);
  57673. #elif defined(WOLFSSL_SHA384)
  57674. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx,
  57675. "ECDSA+SHA256:ECDSA+SHA384"), WOLFSSL_SUCCESS);
  57676. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl,
  57677. "ECDSA+SHA256:ECDSA+SHA384"), WOLFSSL_SUCCESS);
  57678. #endif
  57679. #endif
  57680. #endif
  57681. #ifdef HAVE_ED25519
  57682. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "ED25519"), WOLFSSL_SUCCESS);
  57683. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "ED25519"), WOLFSSL_SUCCESS);
  57684. #endif
  57685. #ifdef HAVE_ED448
  57686. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "ED448"), WOLFSSL_SUCCESS);
  57687. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "ED448"), WOLFSSL_SUCCESS);
  57688. #endif
  57689. #ifndef NO_DSA
  57690. #ifndef NO_SHA256
  57691. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "DSA+SHA256"),
  57692. WOLFSSL_SUCCESS);
  57693. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "DSA+SHA256"),
  57694. WOLFSSL_SUCCESS);
  57695. #endif
  57696. #if !defined(NO_SHA) && (!defined(NO_OLD_TLS) || \
  57697. defined(WOLFSSL_ALLOW_TLS_SHA1))
  57698. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx, "DSA+SHA1"),
  57699. WOLFSSL_SUCCESS);
  57700. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl, "DSA+SHA1"),
  57701. WOLFSSL_SUCCESS);
  57702. #endif
  57703. #endif
  57704. SSL_free(ssl);
  57705. SSL_CTX_free(ctx);
  57706. #endif /* !NO_WOLFSSL_CLIENT || !NO_WOLFSSL_SERVER */
  57707. #endif
  57708. return EXPECT_RESULT();
  57709. }
  57710. /* Testing wolfSSL_set_tlsext_status_type function.
  57711. * PRE: OPENSSL and HAVE_CERTIFICATE_STATUS_REQUEST defined.
  57712. */
  57713. static int test_wolfSSL_set_tlsext_status_type(void)
  57714. {
  57715. EXPECT_DECLS;
  57716. #if defined(OPENSSL_EXTRA) && defined(HAVE_CERTIFICATE_STATUS_REQUEST) && \
  57717. !defined(NO_RSA) && !defined(NO_WOLFSSL_SERVER)
  57718. SSL* ssl = NULL;
  57719. SSL_CTX* ctx = NULL;
  57720. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  57721. ExpectTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile,
  57722. SSL_FILETYPE_PEM));
  57723. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
  57724. ExpectNotNull(ssl = SSL_new(ctx));
  57725. ExpectIntEQ(SSL_set_tlsext_status_type(ssl,TLSEXT_STATUSTYPE_ocsp),
  57726. SSL_SUCCESS);
  57727. ExpectIntEQ(SSL_get_tlsext_status_type(ssl), TLSEXT_STATUSTYPE_ocsp);
  57728. SSL_free(ssl);
  57729. SSL_CTX_free(ctx);
  57730. #endif /* OPENSSL_EXTRA && HAVE_CERTIFICATE_STATUS_REQUEST && !NO_RSA */
  57731. return EXPECT_RESULT();
  57732. }
  57733. #ifndef NO_BIO
  57734. static int test_wolfSSL_PEM_read_bio(void)
  57735. {
  57736. EXPECT_DECLS;
  57737. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  57738. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  57739. byte buff[6000];
  57740. XFILE f = XBADFILE;
  57741. int bytes = 0;
  57742. X509* x509 = NULL;
  57743. BIO* bio = NULL;
  57744. BUF_MEM* buf = NULL;
  57745. ExpectTrue((f = XFOPEN(cliCertFile, "rb")) != XBADFILE);
  57746. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  57747. if (f != XBADFILE)
  57748. XFCLOSE(f);
  57749. ExpectNull(x509 = PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL));
  57750. ExpectNotNull(bio = BIO_new_mem_buf((void*)buff, bytes));
  57751. ExpectIntEQ(BIO_set_mem_eof_return(bio, -0xDEAD), 1);
  57752. ExpectNotNull(x509 = PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL));
  57753. ExpectIntEQ((int)BIO_set_fd(bio, 0, BIO_CLOSE), 1);
  57754. /* BIO should return the set EOF value */
  57755. ExpectIntEQ(BIO_read(bio, buff, sizeof(buff)), -0xDEAD);
  57756. ExpectIntEQ(BIO_set_close(bio, BIO_NOCLOSE), 1);
  57757. ExpectIntEQ(BIO_set_close(NULL, BIO_NOCLOSE), 1);
  57758. ExpectIntEQ(SSL_SUCCESS, BIO_get_mem_ptr(bio, &buf));
  57759. BIO_free(bio);
  57760. BUF_MEM_free(buf);
  57761. X509_free(x509);
  57762. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) &&
  57763. * !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  57764. return EXPECT_RESULT();
  57765. }
  57766. #if defined(OPENSSL_EXTRA)
  57767. static long bioCallback(BIO *bio, int cmd, const char* argp, int argi,
  57768. long argl, long ret)
  57769. {
  57770. (void)bio;
  57771. (void)cmd;
  57772. (void)argp;
  57773. (void)argi;
  57774. (void)argl;
  57775. return ret;
  57776. }
  57777. #endif
  57778. static int test_wolfSSL_BIO(void)
  57779. {
  57780. EXPECT_DECLS;
  57781. #if defined(OPENSSL_EXTRA)
  57782. const unsigned char* p = NULL;
  57783. byte buff[20];
  57784. BIO* bio1 = NULL;
  57785. BIO* bio2 = NULL;
  57786. BIO* bio3 = NULL;
  57787. char* bufPt = NULL;
  57788. int i;
  57789. for (i = 0; i < 20; i++) {
  57790. buff[i] = i;
  57791. }
  57792. /* test BIO_free with NULL */
  57793. ExpectIntEQ(BIO_free(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57794. /* Creating and testing type BIO_s_bio */
  57795. ExpectNotNull(bio1 = BIO_new(BIO_s_bio()));
  57796. ExpectNotNull(bio2 = BIO_new(BIO_s_bio()));
  57797. ExpectNotNull(bio3 = BIO_new(BIO_s_bio()));
  57798. /* read/write before set up */
  57799. ExpectIntEQ(BIO_read(bio1, buff, 2), WOLFSSL_BIO_UNSET);
  57800. ExpectIntEQ(BIO_write(bio1, buff, 2), WOLFSSL_BIO_UNSET);
  57801. ExpectIntEQ(BIO_set_nbio(bio1, 1), 1);
  57802. ExpectIntEQ(BIO_set_write_buf_size(bio1, 20), WOLFSSL_SUCCESS);
  57803. ExpectIntEQ(BIO_set_write_buf_size(bio2, 8), WOLFSSL_SUCCESS);
  57804. ExpectIntEQ(BIO_make_bio_pair(bio1, bio2), WOLFSSL_SUCCESS);
  57805. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 10), 10);
  57806. ExpectNotNull(XMEMCPY(bufPt, buff, 10));
  57807. ExpectIntEQ(BIO_write(bio1, buff + 10, 10), 10);
  57808. /* write buffer full */
  57809. ExpectIntEQ(BIO_write(bio1, buff, 10), WOLFSSL_BIO_ERROR);
  57810. ExpectIntEQ(BIO_flush(bio1), WOLFSSL_SUCCESS);
  57811. ExpectIntEQ((int)BIO_ctrl_pending(bio1), 0);
  57812. /* write the other direction with pair */
  57813. ExpectIntEQ((int)BIO_nwrite(bio2, &bufPt, 10), 8);
  57814. ExpectNotNull(XMEMCPY(bufPt, buff, 8));
  57815. ExpectIntEQ(BIO_write(bio2, buff, 10), WOLFSSL_BIO_ERROR);
  57816. /* try read */
  57817. ExpectIntEQ((int)BIO_ctrl_pending(bio1), 8);
  57818. ExpectIntEQ((int)BIO_ctrl_pending(bio2), 20);
  57819. /* try read using ctrl function */
  57820. ExpectIntEQ((int)BIO_ctrl(bio1, BIO_CTRL_WPENDING, 0, NULL), 8);
  57821. ExpectIntEQ((int)BIO_ctrl(bio1, BIO_CTRL_PENDING, 0, NULL), 8);
  57822. ExpectIntEQ((int)BIO_ctrl(bio2, BIO_CTRL_WPENDING, 0, NULL), 20);
  57823. ExpectIntEQ((int)BIO_ctrl(bio2, BIO_CTRL_PENDING, 0, NULL), 20);
  57824. ExpectIntEQ(BIO_nread(bio2, &bufPt, (int)BIO_ctrl_pending(bio2)), 20);
  57825. for (i = 0; i < 20; i++) {
  57826. ExpectIntEQ((int)bufPt[i], i);
  57827. }
  57828. ExpectIntEQ(BIO_nread(bio2, &bufPt, 1), 0);
  57829. ExpectIntEQ(BIO_nread(bio1, &bufPt, (int)BIO_ctrl_pending(bio1)), 8);
  57830. for (i = 0; i < 8; i++) {
  57831. ExpectIntEQ((int)bufPt[i], i);
  57832. }
  57833. ExpectIntEQ(BIO_nread(bio1, &bufPt, 1), 0);
  57834. ExpectIntEQ(BIO_ctrl_reset_read_request(bio1), 1);
  57835. /* new pair */
  57836. ExpectIntEQ(BIO_make_bio_pair(bio1, bio3), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57837. BIO_free(bio2); /* free bio2 and automatically remove from pair */
  57838. bio2 = NULL;
  57839. ExpectIntEQ(BIO_make_bio_pair(bio1, bio3), WOLFSSL_SUCCESS);
  57840. ExpectIntEQ((int)BIO_ctrl_pending(bio3), 0);
  57841. ExpectIntEQ(BIO_nread(bio3, &bufPt, 10), 0);
  57842. /* test wrap around... */
  57843. ExpectIntEQ(BIO_reset(bio1), 1);
  57844. ExpectIntEQ(BIO_reset(bio3), 1);
  57845. /* fill write buffer, read only small amount then write again */
  57846. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 20), 20);
  57847. ExpectNotNull(XMEMCPY(bufPt, buff, 20));
  57848. ExpectIntEQ(BIO_nread(bio3, &bufPt, 4), 4);
  57849. for (i = 0; i < 4; i++) {
  57850. ExpectIntEQ(bufPt[i], i);
  57851. }
  57852. /* try writing over read index */
  57853. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 5), 4);
  57854. ExpectNotNull(XMEMSET(bufPt, 0, 4));
  57855. ExpectIntEQ((int)BIO_ctrl_pending(bio3), 20);
  57856. /* read and write 0 bytes */
  57857. ExpectIntEQ(BIO_nread(bio3, &bufPt, 0), 0);
  57858. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 0), 0);
  57859. /* should read only to end of write buffer then need to read again */
  57860. ExpectIntEQ(BIO_nread(bio3, &bufPt, 20), 16);
  57861. for (i = 0; i < 16; i++) {
  57862. ExpectIntEQ(bufPt[i], buff[4 + i]);
  57863. }
  57864. ExpectIntEQ(BIO_nread(bio3, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  57865. ExpectIntEQ(BIO_nread0(bio3, &bufPt), 4);
  57866. for (i = 0; i < 4; i++) {
  57867. ExpectIntEQ(bufPt[i], 0);
  57868. }
  57869. /* read index should not have advanced with nread0 */
  57870. ExpectIntEQ(BIO_nread(bio3, &bufPt, 5), 4);
  57871. for (i = 0; i < 4; i++) {
  57872. ExpectIntEQ(bufPt[i], 0);
  57873. }
  57874. /* write and fill up buffer checking reset of index state */
  57875. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 20), 20);
  57876. ExpectNotNull(XMEMCPY(bufPt, buff, 20));
  57877. /* test reset on data in bio1 write buffer */
  57878. ExpectIntEQ(BIO_reset(bio1), 1);
  57879. ExpectIntEQ((int)BIO_ctrl_pending(bio3), 0);
  57880. ExpectIntEQ(BIO_nread(bio3, &bufPt, 3), 0);
  57881. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 20), 20);
  57882. ExpectIntEQ((int)BIO_ctrl(bio1, BIO_CTRL_INFO, 0, &p), 20);
  57883. ExpectNotNull(p);
  57884. ExpectNotNull(XMEMCPY(bufPt, buff, 20));
  57885. ExpectIntEQ(BIO_nread(bio3, &bufPt, 6), 6);
  57886. for (i = 0; i < 6; i++) {
  57887. ExpectIntEQ(bufPt[i], i);
  57888. }
  57889. /* test case of writing twice with offset read index */
  57890. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 3), 3);
  57891. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 4), 3); /* try overwriting */
  57892. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 4), WOLFSSL_BIO_ERROR);
  57893. ExpectIntEQ(BIO_nread(bio3, &bufPt, 0), 0);
  57894. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 4), WOLFSSL_BIO_ERROR);
  57895. ExpectIntEQ(BIO_nread(bio3, &bufPt, 1), 1);
  57896. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 4), 1);
  57897. ExpectIntEQ(BIO_nwrite(bio1, &bufPt, 4), WOLFSSL_BIO_ERROR);
  57898. BIO_free(bio1);
  57899. bio1 = NULL;
  57900. BIO_free(bio3);
  57901. bio3 = NULL;
  57902. #if defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO)
  57903. {
  57904. BIO* bioA = NULL;
  57905. BIO* bioB = NULL;
  57906. ExpectIntEQ(BIO_new_bio_pair(NULL, 256, NULL, 256), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  57907. ExpectIntEQ(BIO_new_bio_pair(&bioA, 256, &bioB, 256), WOLFSSL_SUCCESS);
  57908. BIO_free(bioA);
  57909. bioA = NULL;
  57910. BIO_free(bioB);
  57911. bioB = NULL;
  57912. }
  57913. #endif /* OPENSSL_ALL || WOLFSSL_ASIO */
  57914. /* BIOs with file pointers */
  57915. #if !defined(NO_FILESYSTEM)
  57916. {
  57917. XFILE f1 = XBADFILE;
  57918. XFILE f2 = XBADFILE;
  57919. BIO* f_bio1 = NULL;
  57920. BIO* f_bio2 = NULL;
  57921. unsigned char cert[300];
  57922. char testFile[] = "tests/bio_write_test.txt";
  57923. char msg[] = "bio_write_test.txt contains the first 300 bytes of certs/server-cert.pem\ncreated by tests/unit.test\n\n";
  57924. ExpectNotNull(f_bio1 = BIO_new(BIO_s_file()));
  57925. ExpectNotNull(f_bio2 = BIO_new(BIO_s_file()));
  57926. /* Failure due to wrong BIO type */
  57927. ExpectIntEQ((int)BIO_set_mem_eof_return(f_bio1, -1), 0);
  57928. ExpectIntEQ((int)BIO_set_mem_eof_return(NULL, -1), 0);
  57929. ExpectTrue((f1 = XFOPEN(svrCertFile, "rwb")) != XBADFILE);
  57930. ExpectIntEQ((int)BIO_set_fp(f_bio1, f1, BIO_CLOSE), WOLFSSL_SUCCESS);
  57931. ExpectIntEQ(BIO_write_filename(f_bio2, testFile),
  57932. WOLFSSL_SUCCESS);
  57933. ExpectIntEQ(BIO_read(f_bio1, cert, sizeof(cert)), sizeof(cert));
  57934. ExpectIntEQ(BIO_tell(f_bio1),sizeof(cert));
  57935. ExpectIntEQ(BIO_write(f_bio2, msg, sizeof(msg)), sizeof(msg));
  57936. ExpectIntEQ(BIO_tell(f_bio2),sizeof(msg));
  57937. ExpectIntEQ(BIO_write(f_bio2, cert, sizeof(cert)), sizeof(cert));
  57938. ExpectIntEQ(BIO_tell(f_bio2),sizeof(cert) + sizeof(msg));
  57939. ExpectIntEQ((int)BIO_get_fp(f_bio2, &f2), WOLFSSL_SUCCESS);
  57940. ExpectIntEQ(BIO_reset(f_bio2), 1);
  57941. ExpectIntEQ(BIO_tell(NULL),-1);
  57942. ExpectIntEQ(BIO_tell(f_bio2),0);
  57943. ExpectIntEQ(BIO_seek(f_bio2, 4), 0);
  57944. ExpectIntEQ(BIO_tell(f_bio2),4);
  57945. BIO_free(f_bio1);
  57946. f_bio1 = NULL;
  57947. BIO_free(f_bio2);
  57948. f_bio2 = NULL;
  57949. ExpectNotNull(f_bio1 = BIO_new_file(svrCertFile, "rwb"));
  57950. ExpectIntEQ((int)BIO_set_mem_eof_return(f_bio1, -1), 0);
  57951. ExpectIntEQ(BIO_read(f_bio1, cert, sizeof(cert)), sizeof(cert));
  57952. BIO_free(f_bio1);
  57953. f_bio1 = NULL;
  57954. }
  57955. #endif /* !defined(NO_FILESYSTEM) */
  57956. /* BIO info callback */
  57957. {
  57958. const char* testArg = "test";
  57959. BIO* cb_bio = NULL;
  57960. ExpectNotNull(cb_bio = BIO_new(BIO_s_mem()));
  57961. BIO_set_callback(cb_bio, bioCallback);
  57962. ExpectNotNull(BIO_get_callback(cb_bio));
  57963. BIO_set_callback(cb_bio, NULL);
  57964. ExpectNull(BIO_get_callback(cb_bio));
  57965. BIO_set_callback_arg(cb_bio, (char*)testArg);
  57966. ExpectStrEQ(BIO_get_callback_arg(cb_bio), testArg);
  57967. ExpectNull(BIO_get_callback_arg(NULL));
  57968. BIO_free(cb_bio);
  57969. cb_bio = NULL;
  57970. }
  57971. /* BIO_vfree */
  57972. ExpectNotNull(bio1 = BIO_new(BIO_s_bio()));
  57973. BIO_vfree(NULL);
  57974. BIO_vfree(bio1);
  57975. #endif
  57976. return EXPECT_RESULT();
  57977. }
  57978. static int test_wolfSSL_BIO_BIO_ring_read(void)
  57979. {
  57980. EXPECT_DECLS;
  57981. #if defined(OPENSSL_ALL)
  57982. BIO* bio1 = NULL;
  57983. BIO* bio2 = NULL;
  57984. byte data[50];
  57985. byte tmp[50];
  57986. XMEMSET(data, 42, sizeof(data));
  57987. ExpectIntEQ(BIO_new_bio_pair(&bio1, sizeof(data), &bio2, sizeof(data)),
  57988. SSL_SUCCESS);
  57989. ExpectIntEQ(BIO_write(bio1, data, 40), 40);
  57990. ExpectIntEQ(BIO_read(bio1, tmp, 20), -1);
  57991. ExpectIntEQ(BIO_read(bio2, tmp, 20), 20);
  57992. ExpectBufEQ(tmp, data, 20);
  57993. ExpectIntEQ(BIO_write(bio1, data, 20), 20);
  57994. ExpectIntEQ(BIO_read(bio2, tmp, 40), 40);
  57995. ExpectBufEQ(tmp, data, 40);
  57996. BIO_free(bio1);
  57997. BIO_free(bio2);
  57998. #endif
  57999. return EXPECT_RESULT();
  58000. }
  58001. #endif /* !NO_BIO */
  58002. static int test_wolfSSL_a2i_IPADDRESS(void)
  58003. {
  58004. EXPECT_DECLS;
  58005. #if defined(OPENSSL_ALL) && !defined(WOLFSSL_USER_IO)
  58006. const unsigned char* data = NULL;
  58007. int dataSz = 0;
  58008. ASN1_OCTET_STRING *st = NULL;
  58009. const unsigned char ipv4_exp[] = {0x7F, 0, 0, 1};
  58010. const unsigned char ipv6_exp[] = {
  58011. 0x20, 0x21, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00,
  58012. 0x00, 0x00, 0xff, 0x00, 0x00, 0x42, 0x77, 0x77
  58013. };
  58014. const unsigned char ipv6_home[] = {
  58015. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  58016. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
  58017. };
  58018. ExpectNull(st = a2i_IPADDRESS("127.0.0.1bad"));
  58019. ExpectNotNull(st = a2i_IPADDRESS("127.0.0.1"));
  58020. ExpectNotNull(data = ASN1_STRING_get0_data(st));
  58021. ExpectIntEQ(dataSz = ASN1_STRING_length(st), WOLFSSL_IP4_ADDR_LEN);
  58022. ExpectIntEQ(XMEMCMP(data, ipv4_exp, dataSz), 0);
  58023. ASN1_STRING_free(st);
  58024. st = NULL;
  58025. ExpectNotNull(st = a2i_IPADDRESS("::1"));
  58026. ExpectNotNull(data = ASN1_STRING_get0_data(st));
  58027. ExpectIntEQ(dataSz = ASN1_STRING_length(st), WOLFSSL_IP6_ADDR_LEN);
  58028. ExpectIntEQ(XMEMCMP(data, ipv6_home, dataSz), 0);
  58029. ASN1_STRING_free(st);
  58030. st = NULL;
  58031. ExpectNotNull(st = a2i_IPADDRESS("2021:db8::ff00:42:7777"));
  58032. ExpectNotNull(data = ASN1_STRING_get0_data(st));
  58033. ExpectIntEQ(dataSz = ASN1_STRING_length(st), WOLFSSL_IP6_ADDR_LEN);
  58034. ExpectIntEQ(XMEMCMP(data, ipv6_exp, dataSz), 0);
  58035. ASN1_STRING_free(st);
  58036. #endif
  58037. return EXPECT_RESULT();
  58038. }
  58039. static int test_wolfSSL_X509_cmp_time(void)
  58040. {
  58041. EXPECT_DECLS;
  58042. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME) \
  58043. && !defined(USER_TIME) && !defined(TIME_OVERRIDES)
  58044. WOLFSSL_ASN1_TIME asn_time;
  58045. time_t t;
  58046. ExpectIntEQ(0, wolfSSL_X509_cmp_time(NULL, &t));
  58047. XMEMSET(&asn_time, 0, sizeof(WOLFSSL_ASN1_TIME));
  58048. ExpectIntEQ(0, wolfSSL_X509_cmp_time(&asn_time, &t));
  58049. ExpectIntEQ(ASN1_TIME_set_string(&asn_time, "000222211515Z"), 1);
  58050. ExpectIntEQ(-1, wolfSSL_X509_cmp_time(&asn_time, NULL));
  58051. #endif
  58052. return EXPECT_RESULT();
  58053. }
  58054. static int test_wolfSSL_X509_time_adj(void)
  58055. {
  58056. EXPECT_DECLS;
  58057. #if defined(OPENSSL_EXTRA) && !defined(NO_ASN_TIME) && \
  58058. !defined(USER_TIME) && !defined(TIME_OVERRIDES) && \
  58059. defined(USE_CERT_BUFFERS_2048) && !defined(NO_RSA) && \
  58060. !defined(NO_ASN_TIME)
  58061. X509* x509 = NULL;
  58062. time_t t;
  58063. time_t not_before;
  58064. time_t not_after;
  58065. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(
  58066. client_cert_der_2048, sizeof_client_cert_der_2048,
  58067. WOLFSSL_FILETYPE_ASN1));
  58068. t = 0;
  58069. not_before = wc_Time(0);
  58070. not_after = wc_Time(0) + (60 * 24 * 30); /* 30 days after */
  58071. ExpectNotNull(X509_time_adj(X509_get_notBefore(x509), not_before, &t));
  58072. ExpectNotNull(X509_time_adj(X509_get_notAfter(x509), not_after, &t));
  58073. /* Check X509_gmtime_adj, too. */
  58074. ExpectNotNull(X509_gmtime_adj(X509_get_notAfter(x509), not_after));
  58075. X509_free(x509);
  58076. #endif
  58077. return EXPECT_RESULT();
  58078. }
  58079. static int test_wolfSSL_X509_bad_altname(void)
  58080. {
  58081. EXPECT_DECLS;
  58082. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  58083. const unsigned char malformed_alt_name_cert[] = {
  58084. 0x30, 0x82, 0x02, 0xf9, 0x30, 0x82, 0x01, 0xe1, 0xa0, 0x03, 0x02, 0x01,
  58085. 0x02, 0x02, 0x02, 0x10, 0x21, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48,
  58086. 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x0f, 0x31, 0x0d,
  58087. 0x30, 0x0b, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x04, 0x61, 0x61, 0x31,
  58088. 0x31, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x36, 0x30, 0x32, 0x30, 0x37, 0x31,
  58089. 0x37, 0x32, 0x34, 0x30, 0x30, 0x5a, 0x17, 0x0d, 0x33, 0x34, 0x30, 0x32,
  58090. 0x31, 0x34, 0x30, 0x36, 0x32, 0x36, 0x35, 0x33, 0x5a, 0x30, 0x0f, 0x31,
  58091. 0x0d, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x04, 0x61, 0x61,
  58092. 0x61, 0x61, 0x30, 0x82, 0x01, 0x20, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86,
  58093. 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01,
  58094. 0x0d, 0x00, 0x30, 0x82, 0x01, 0x08, 0x02, 0x82, 0x01, 0x01, 0x00, 0xa8,
  58095. 0x8a, 0x5e, 0x26, 0x23, 0x1b, 0x31, 0xd3, 0x37, 0x1a, 0x70, 0xb2, 0xec,
  58096. 0x3f, 0x74, 0xd4, 0xb4, 0x44, 0xe3, 0x7a, 0xa5, 0xc0, 0xf5, 0xaa, 0x97,
  58097. 0x26, 0x9a, 0x04, 0xff, 0xda, 0xbe, 0xe5, 0x09, 0x03, 0x98, 0x3d, 0xb5,
  58098. 0xbf, 0x01, 0x2c, 0x9a, 0x0a, 0x3a, 0xfb, 0xbc, 0x3c, 0xe7, 0xbe, 0x83,
  58099. 0x5c, 0xb3, 0x70, 0xe8, 0x5c, 0xe3, 0xd1, 0x83, 0xc3, 0x94, 0x08, 0xcd,
  58100. 0x1a, 0x87, 0xe5, 0xe0, 0x5b, 0x9c, 0x5c, 0x6e, 0xb0, 0x7d, 0xe2, 0x58,
  58101. 0x6c, 0xc3, 0xb5, 0xc8, 0x9d, 0x11, 0xf1, 0x5d, 0x96, 0x0d, 0x66, 0x1e,
  58102. 0x56, 0x7f, 0x8f, 0x59, 0xa7, 0xa5, 0xe1, 0xc5, 0xe7, 0x81, 0x4c, 0x09,
  58103. 0x9d, 0x5e, 0x96, 0xf0, 0x9a, 0xc2, 0x8b, 0x70, 0xd5, 0xab, 0x79, 0x58,
  58104. 0x5d, 0xb7, 0x58, 0xaa, 0xfd, 0x75, 0x52, 0xaa, 0x4b, 0xa7, 0x25, 0x68,
  58105. 0x76, 0x59, 0x00, 0xee, 0x78, 0x2b, 0x91, 0xc6, 0x59, 0x91, 0x99, 0x38,
  58106. 0x3e, 0xa1, 0x76, 0xc3, 0xf5, 0x23, 0x6b, 0xe6, 0x07, 0xea, 0x63, 0x1c,
  58107. 0x97, 0x49, 0xef, 0xa0, 0xfe, 0xfd, 0x13, 0xc9, 0xa9, 0x9f, 0xc2, 0x0b,
  58108. 0xe6, 0x87, 0x92, 0x5b, 0xcc, 0xf5, 0x42, 0x95, 0x4a, 0xa4, 0x6d, 0x64,
  58109. 0xba, 0x7d, 0xce, 0xcb, 0x04, 0xd0, 0xf8, 0xe7, 0xe3, 0xda, 0x75, 0x60,
  58110. 0xd3, 0x8b, 0x6a, 0x64, 0xfc, 0x78, 0x56, 0x21, 0x69, 0x5a, 0xe8, 0xa7,
  58111. 0x8f, 0xfb, 0x8f, 0x82, 0xe3, 0xae, 0x36, 0xa2, 0x93, 0x66, 0x92, 0xcb,
  58112. 0x82, 0xa3, 0xbe, 0x84, 0x00, 0x86, 0xdc, 0x7e, 0x6d, 0x53, 0x77, 0x84,
  58113. 0x17, 0xb9, 0x55, 0x43, 0x0d, 0xf1, 0x16, 0x1f, 0xd5, 0x43, 0x75, 0x99,
  58114. 0x66, 0x19, 0x52, 0xd0, 0xac, 0x5f, 0x74, 0xad, 0xb2, 0x90, 0x15, 0x50,
  58115. 0x04, 0x74, 0x43, 0xdf, 0x6c, 0x35, 0xd0, 0xfd, 0x32, 0x37, 0xb3, 0x8d,
  58116. 0xf5, 0xe5, 0x09, 0x02, 0x01, 0x03, 0xa3, 0x61, 0x30, 0x5f, 0x30, 0x0c,
  58117. 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x02, 0x30, 0x00,
  58118. 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, 0x08, 0x30, 0x06, 0x82,
  58119. 0x04, 0x61, 0x2a, 0x00, 0x2a, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e,
  58120. 0x04, 0x16, 0x04, 0x14, 0x92, 0x6a, 0x1e, 0x52, 0x3a, 0x1a, 0x57, 0x9f,
  58121. 0xc9, 0x82, 0x9a, 0xce, 0xc8, 0xc0, 0xa9, 0x51, 0x9d, 0x2f, 0xc7, 0x72,
  58122. 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80,
  58123. 0x14, 0x6b, 0xf9, 0xa4, 0x2d, 0xa5, 0xe9, 0x39, 0x89, 0xa8, 0x24, 0x58,
  58124. 0x79, 0x87, 0x11, 0xfc, 0x6f, 0x07, 0x91, 0xef, 0xa6, 0x30, 0x0d, 0x06,
  58125. 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00,
  58126. 0x03, 0x82, 0x01, 0x01, 0x00, 0x3f, 0xd5, 0x37, 0x2f, 0xc7, 0xf8, 0x8b,
  58127. 0x39, 0x1c, 0xe3, 0xdf, 0x77, 0xee, 0xc6, 0x4b, 0x5f, 0x84, 0xcf, 0xfa,
  58128. 0x33, 0x2c, 0xb2, 0xb5, 0x4b, 0x09, 0xee, 0x56, 0xc0, 0xf2, 0xf0, 0xeb,
  58129. 0xad, 0x1c, 0x02, 0xef, 0xae, 0x09, 0x53, 0xc0, 0x06, 0xad, 0x4e, 0xfd,
  58130. 0x3e, 0x8c, 0x13, 0xb3, 0xbf, 0x80, 0x05, 0x36, 0xb5, 0x3f, 0x2b, 0xc7,
  58131. 0x60, 0x53, 0x14, 0xbf, 0x33, 0x63, 0x47, 0xc3, 0xc6, 0x28, 0xda, 0x10,
  58132. 0x12, 0xe2, 0xc4, 0xeb, 0xc5, 0x64, 0x66, 0xc0, 0xcc, 0x6b, 0x84, 0xda,
  58133. 0x0c, 0xe9, 0xf6, 0xe3, 0xf8, 0x8e, 0x3d, 0x95, 0x5f, 0xba, 0x9f, 0xe1,
  58134. 0xc7, 0xed, 0x6e, 0x97, 0xcc, 0xbd, 0x7d, 0xe5, 0x4e, 0xab, 0xbc, 0x1b,
  58135. 0xf1, 0x3a, 0x09, 0x33, 0x09, 0xe1, 0xcc, 0xec, 0x21, 0x16, 0x8e, 0xb1,
  58136. 0x74, 0x9e, 0xc8, 0x13, 0x7c, 0xdf, 0x07, 0xaa, 0xeb, 0x70, 0xd7, 0x91,
  58137. 0x5c, 0xc4, 0xef, 0x83, 0x88, 0xc3, 0xe4, 0x97, 0xfa, 0xe4, 0xdf, 0xd7,
  58138. 0x0d, 0xff, 0xba, 0x78, 0x22, 0xfc, 0x3f, 0xdc, 0xd8, 0x02, 0x8d, 0x93,
  58139. 0x57, 0xf9, 0x9e, 0x39, 0x3a, 0x77, 0x00, 0xd9, 0x19, 0xaa, 0x68, 0xa1,
  58140. 0xe6, 0x9e, 0x13, 0xeb, 0x37, 0x16, 0xf5, 0x77, 0xa4, 0x0b, 0x40, 0x04,
  58141. 0xd3, 0xa5, 0x49, 0x78, 0x35, 0xfa, 0x3b, 0xf6, 0x02, 0xab, 0x85, 0xee,
  58142. 0xcb, 0x9b, 0x62, 0xda, 0x05, 0x00, 0x22, 0x2f, 0xf8, 0xbd, 0x0b, 0xe5,
  58143. 0x2c, 0xb2, 0x53, 0x78, 0x0a, 0xcb, 0x69, 0xc0, 0xb6, 0x9f, 0x96, 0xff,
  58144. 0x58, 0x22, 0x70, 0x9c, 0x01, 0x2e, 0x56, 0x60, 0x5d, 0x37, 0xe3, 0x40,
  58145. 0x25, 0xc9, 0x90, 0xc8, 0x0f, 0x41, 0x68, 0xb4, 0xfd, 0x10, 0xe2, 0x09,
  58146. 0x99, 0x08, 0x5d, 0x7b, 0xc9, 0xe3, 0x29, 0xd4, 0x5a, 0xcf, 0xc9, 0x34,
  58147. 0x55, 0xa1, 0x40, 0x44, 0xd6, 0x88, 0x16, 0xbb, 0xdd
  58148. };
  58149. X509* x509 = NULL;
  58150. int certSize = (int)sizeof(malformed_alt_name_cert) / sizeof(unsigned char);
  58151. const char *name = "aaaaa";
  58152. int nameLen = (int)XSTRLEN(name);
  58153. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(
  58154. malformed_alt_name_cert, certSize, SSL_FILETYPE_ASN1));
  58155. /* malformed_alt_name_cert has a malformed alternative
  58156. * name of "a*\0*". Ensure that it does not match "aaaaa" */
  58157. ExpectIntNE(wolfSSL_X509_check_host(x509, name, nameLen,
  58158. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), 1);
  58159. /* Also make sure WOLFSSL_LEFT_MOST_WILDCARD_ONLY fails too */
  58160. ExpectIntNE(wolfSSL_X509_check_host(x509, name, nameLen,
  58161. WOLFSSL_ALWAYS_CHECK_SUBJECT | WOLFSSL_LEFT_MOST_WILDCARD_ONLY,
  58162. NULL), 1);
  58163. X509_free(x509);
  58164. #endif
  58165. return EXPECT_RESULT();
  58166. }
  58167. static int test_wolfSSL_X509_name_match(void)
  58168. {
  58169. EXPECT_DECLS;
  58170. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  58171. /* A certificate with the subject alternative name a* */
  58172. const unsigned char cert_der[] = {
  58173. 0x30, 0x82, 0x03, 0xac, 0x30, 0x82, 0x02, 0x94, 0xa0, 0x03, 0x02, 0x01,
  58174. 0x02, 0x02, 0x14, 0x0f, 0xa5, 0x10, 0x85, 0xef, 0x58, 0x10, 0x59, 0xfc,
  58175. 0x0f, 0x20, 0x1f, 0x53, 0xf5, 0x30, 0x39, 0x34, 0x49, 0x54, 0x05, 0x30,
  58176. 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b,
  58177. 0x05, 0x00, 0x30, 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
  58178. 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55,
  58179. 0x04, 0x08, 0x0c, 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31,
  58180. 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f,
  58181. 0x7a, 0x65, 0x6d, 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55,
  58182. 0x04, 0x0a, 0x0c, 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20,
  58183. 0x49, 0x6e, 0x63, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b,
  58184. 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e,
  58185. 0x67, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f,
  58186. 0x77, 0x77, 0x77, 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e,
  58187. 0x63, 0x6f, 0x6d, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x34, 0x30, 0x35, 0x33,
  58188. 0x30, 0x32, 0x30, 0x31, 0x35, 0x35, 0x38, 0x5a, 0x17, 0x0d, 0x33, 0x34,
  58189. 0x30, 0x35, 0x32, 0x38, 0x32, 0x30, 0x31, 0x35, 0x35, 0x38, 0x5a, 0x30,
  58190. 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,
  58191. 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c,
  58192. 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31, 0x10, 0x30, 0x0e,
  58193. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f, 0x7a, 0x65, 0x6d,
  58194. 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c,
  58195. 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x49, 0x6e, 0x63,
  58196. 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45,
  58197. 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18,
  58198. 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x77, 0x77,
  58199. 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d,
  58200. 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
  58201. 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00,
  58202. 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xf4, 0xca, 0x3d,
  58203. 0xd4, 0xbc, 0x9b, 0xea, 0x74, 0xfe, 0x73, 0xf4, 0x16, 0x23, 0x0b, 0x4a,
  58204. 0x09, 0x54, 0xf6, 0x7b, 0x10, 0x99, 0x11, 0x93, 0xb2, 0xdb, 0x4d, 0x7d,
  58205. 0x23, 0xab, 0xf9, 0xcd, 0xf6, 0x54, 0xd4, 0xf6, 0x39, 0x57, 0xee, 0x97,
  58206. 0xb2, 0xb9, 0xfc, 0x7e, 0x9c, 0xb3, 0xfb, 0x56, 0xb6, 0x84, 0xd6, 0x2d,
  58207. 0x59, 0x1c, 0xed, 0xda, 0x9b, 0x19, 0xf5, 0x8a, 0xa7, 0x8a, 0x89, 0xd6,
  58208. 0xa1, 0xc0, 0xe6, 0x16, 0xad, 0x04, 0xcf, 0x5a, 0x1f, 0xdf, 0x62, 0x6c,
  58209. 0x68, 0x45, 0xe9, 0x55, 0x2e, 0x42, 0xa3, 0x1b, 0x3b, 0x86, 0x23, 0x22,
  58210. 0xa1, 0x20, 0x48, 0xd1, 0x52, 0xc0, 0x8b, 0xab, 0xe2, 0x8a, 0x15, 0x68,
  58211. 0xbd, 0x89, 0x6f, 0x9f, 0x45, 0x75, 0xb4, 0x27, 0xc1, 0x72, 0x41, 0xfd,
  58212. 0x79, 0x89, 0xb0, 0x74, 0xa2, 0xe9, 0x61, 0x48, 0x4c, 0x54, 0xad, 0x6b,
  58213. 0x61, 0xbf, 0x0e, 0x27, 0x58, 0xb4, 0xf6, 0x9c, 0x2c, 0x9f, 0xc2, 0x3e,
  58214. 0x3b, 0xb3, 0x90, 0x41, 0xbc, 0x61, 0xcd, 0x01, 0x57, 0x90, 0x82, 0xec,
  58215. 0x46, 0xba, 0x4f, 0x89, 0x8e, 0x7f, 0x49, 0x4f, 0x46, 0x69, 0x37, 0x8b,
  58216. 0xa0, 0xba, 0x85, 0xe8, 0x42, 0xff, 0x9a, 0xa1, 0x53, 0x81, 0x5c, 0xf3,
  58217. 0x8e, 0x85, 0x1c, 0xd4, 0x90, 0x60, 0xa0, 0x37, 0x59, 0x04, 0x65, 0xa6,
  58218. 0xb5, 0x12, 0x00, 0xc3, 0x04, 0x51, 0xa7, 0x83, 0x96, 0x62, 0x3d, 0x49,
  58219. 0x97, 0xe8, 0x6b, 0x9a, 0x5d, 0x51, 0x24, 0xee, 0xad, 0x45, 0x18, 0x0f,
  58220. 0x3f, 0x97, 0xec, 0xdf, 0xcf, 0x42, 0x8a, 0x96, 0xc7, 0xd8, 0x82, 0x87,
  58221. 0x7f, 0x57, 0x70, 0x22, 0xfb, 0x29, 0x3e, 0x3c, 0xa3, 0xc1, 0xd5, 0x71,
  58222. 0xb3, 0x84, 0x06, 0x53, 0xa3, 0x86, 0x20, 0x35, 0xe3, 0x41, 0xb9, 0xd8,
  58223. 0x00, 0x22, 0x4f, 0x6d, 0xe6, 0xfd, 0xf0, 0xf4, 0xa2, 0x39, 0x0a, 0x1a,
  58224. 0x23, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x30, 0x30, 0x2e, 0x30, 0x0d,
  58225. 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, 0x06, 0x30, 0x04, 0x82, 0x02, 0x61,
  58226. 0x2a, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14,
  58227. 0x45, 0x05, 0xf3, 0x4d, 0x3e, 0x7e, 0x9c, 0xf5, 0x08, 0xee, 0x2c, 0x13,
  58228. 0x32, 0xe3, 0xf2, 0x14, 0xe8, 0x0e, 0x71, 0x21, 0x30, 0x0d, 0x06, 0x09,
  58229. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03,
  58230. 0x82, 0x01, 0x01, 0x00, 0xa8, 0x28, 0xe5, 0x22, 0x65, 0xcf, 0x47, 0xfe,
  58231. 0x82, 0x17, 0x99, 0x20, 0xdb, 0xb1, 0x57, 0xd4, 0x91, 0x1a, 0x83, 0xde,
  58232. 0xc1, 0xaf, 0xc4, 0x1f, 0xfb, 0xa4, 0x6a, 0xad, 0xdc, 0x58, 0x72, 0xd9,
  58233. 0x9b, 0xab, 0xa5, 0xbb, 0xf4, 0x98, 0xd4, 0xdf, 0x36, 0xcb, 0xb5, 0x78,
  58234. 0xce, 0x4b, 0x25, 0x5b, 0x24, 0x92, 0xfe, 0xe8, 0xd4, 0xe4, 0xbd, 0x6f,
  58235. 0x71, 0x1a, 0x81, 0x2a, 0x6f, 0x35, 0x93, 0xf7, 0xcc, 0xed, 0xe5, 0x06,
  58236. 0xd2, 0x96, 0x41, 0xb5, 0xa9, 0x8a, 0xc0, 0xc9, 0x17, 0xe3, 0x13, 0x5e,
  58237. 0x94, 0x5e, 0xfa, 0xfc, 0xf0, 0x00, 0x2e, 0xe1, 0xd8, 0x1b, 0x23, 0x3f,
  58238. 0x7c, 0x4d, 0x9f, 0xfb, 0xb7, 0x95, 0xc1, 0x94, 0x7f, 0x7f, 0xb5, 0x4f,
  58239. 0x93, 0x6d, 0xc3, 0x2b, 0xb2, 0x28, 0x36, 0xd2, 0x7c, 0x01, 0x3c, 0xae,
  58240. 0x35, 0xdb, 0xc8, 0x95, 0x1b, 0x5f, 0x6c, 0x0f, 0x57, 0xb3, 0xcc, 0x97,
  58241. 0x98, 0x80, 0x06, 0xaa, 0xe4, 0x93, 0x1f, 0xb7, 0xa0, 0x54, 0xf1, 0x4f,
  58242. 0x6f, 0x11, 0xdf, 0xab, 0xd3, 0xbf, 0xf0, 0x3a, 0x81, 0x60, 0xaf, 0x7a,
  58243. 0xf7, 0x09, 0xd5, 0xae, 0x0c, 0x7d, 0xae, 0x8d, 0x47, 0x06, 0xbe, 0x11,
  58244. 0x6e, 0xf8, 0x7e, 0x49, 0xf8, 0xac, 0x24, 0x0a, 0x4b, 0xc2, 0xf6, 0xe8,
  58245. 0x2c, 0xec, 0x35, 0xef, 0xa9, 0x13, 0xb8, 0xd2, 0x9c, 0x92, 0x61, 0x91,
  58246. 0xec, 0x7b, 0x0c, 0xea, 0x9a, 0x71, 0x36, 0x15, 0x34, 0x2b, 0x7a, 0x25,
  58247. 0xac, 0xfe, 0xc7, 0x26, 0x89, 0x70, 0x3e, 0x64, 0x68, 0x97, 0x4b, 0xaa,
  58248. 0xc1, 0x24, 0x14, 0xbd, 0x45, 0x2f, 0xe0, 0xfe, 0xf4, 0x2b, 0x8e, 0x08,
  58249. 0x3e, 0xe4, 0xb5, 0x3d, 0x5d, 0xf4, 0xc3, 0xd6, 0x9c, 0xb5, 0x33, 0x1b,
  58250. 0x3b, 0xda, 0x6e, 0x99, 0x7b, 0x09, 0xd1, 0x30, 0x97, 0x23, 0x52, 0x6d,
  58251. 0x1b, 0x71, 0x3a, 0xf4, 0x54, 0xf0, 0xe5, 0x9e
  58252. };
  58253. WOLFSSL_X509* x509 = NULL;
  58254. int certSize = (int)(sizeof(cert_der) / sizeof(unsigned char));
  58255. const char *name1 = "aaaaa";
  58256. int nameLen1 = (int)(XSTRLEN(name1));
  58257. const char *name2 = "a";
  58258. int nameLen2 = (int)(XSTRLEN(name2));
  58259. const char *name3 = "abbbb";
  58260. int nameLen3 = (int)(XSTRLEN(name3));
  58261. const char *name4 = "bbb";
  58262. int nameLen4 = (int)(XSTRLEN(name4));
  58263. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(
  58264. cert_der, certSize, WOLFSSL_FILETYPE_ASN1));
  58265. /* Ensure that "a*" matches "aaaaa" */
  58266. ExpectIntEQ(wolfSSL_X509_check_host(x509, name1, nameLen1,
  58267. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  58268. /* Ensure that "a*" matches "a" */
  58269. ExpectIntEQ(wolfSSL_X509_check_host(x509, name2, nameLen2,
  58270. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  58271. /* Ensure that "a*" matches "abbbb" */
  58272. ExpectIntEQ(wolfSSL_X509_check_host(x509, name3, nameLen3,
  58273. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  58274. /* Ensure that "a*" does not match "bbb" */
  58275. ExpectIntNE(wolfSSL_X509_check_host(x509, name4, nameLen4,
  58276. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), 1);
  58277. /* WOLFSSL_LEFT_MOST_WILDCARD_ONLY flag should fail on all cases, since
  58278. * 'a*' alt name does not have wildcard left-most */
  58279. /* Ensure that "a*" does not match "aaaaa" */
  58280. ExpectIntNE(wolfSSL_X509_check_host(x509, name1, nameLen1,
  58281. WOLFSSL_ALWAYS_CHECK_SUBJECT | WOLFSSL_LEFT_MOST_WILDCARD_ONLY,
  58282. NULL), WOLFSSL_SUCCESS);
  58283. /* Ensure that "a*" does not match "a" */
  58284. ExpectIntNE(wolfSSL_X509_check_host(x509, name2, nameLen2,
  58285. WOLFSSL_ALWAYS_CHECK_SUBJECT | WOLFSSL_LEFT_MOST_WILDCARD_ONLY,
  58286. NULL), WOLFSSL_SUCCESS);
  58287. /* Ensure that "a*" does not match "abbbb" */
  58288. ExpectIntNE(wolfSSL_X509_check_host(x509, name3, nameLen3,
  58289. WOLFSSL_ALWAYS_CHECK_SUBJECT | WOLFSSL_LEFT_MOST_WILDCARD_ONLY,
  58290. NULL), WOLFSSL_SUCCESS);
  58291. /* Ensure that "a*" does not match "bbb" */
  58292. ExpectIntNE(wolfSSL_X509_check_host(x509, name4, nameLen4,
  58293. WOLFSSL_ALWAYS_CHECK_SUBJECT | WOLFSSL_LEFT_MOST_WILDCARD_ONLY,
  58294. NULL), WOLFSSL_SUCCESS);
  58295. wolfSSL_X509_free(x509);
  58296. #endif
  58297. return EXPECT_RESULT();
  58298. }
  58299. static int test_wolfSSL_X509_name_match2(void)
  58300. {
  58301. EXPECT_DECLS;
  58302. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  58303. /* A certificate with the subject alternative name a*b* */
  58304. const unsigned char cert_der[] = {
  58305. 0x30, 0x82, 0x03, 0xae, 0x30, 0x82, 0x02, 0x96, 0xa0, 0x03, 0x02, 0x01,
  58306. 0x02, 0x02, 0x14, 0x41, 0x8c, 0x8b, 0xaa, 0x0e, 0xd8, 0x5a, 0xc0, 0x52,
  58307. 0x46, 0x0e, 0xe5, 0xd8, 0xb9, 0x48, 0x93, 0x7e, 0x8a, 0x7c, 0x65, 0x30,
  58308. 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b,
  58309. 0x05, 0x00, 0x30, 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
  58310. 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55,
  58311. 0x04, 0x08, 0x0c, 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31,
  58312. 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f,
  58313. 0x7a, 0x65, 0x6d, 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55,
  58314. 0x04, 0x0a, 0x0c, 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20,
  58315. 0x49, 0x6e, 0x63, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b,
  58316. 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e,
  58317. 0x67, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f,
  58318. 0x77, 0x77, 0x77, 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e,
  58319. 0x63, 0x6f, 0x6d, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x34, 0x30, 0x35, 0x33,
  58320. 0x30, 0x32, 0x30, 0x34, 0x33, 0x34, 0x30, 0x5a, 0x17, 0x0d, 0x33, 0x34,
  58321. 0x30, 0x35, 0x32, 0x38, 0x32, 0x30, 0x34, 0x33, 0x34, 0x30, 0x5a, 0x30,
  58322. 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,
  58323. 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c,
  58324. 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31, 0x10, 0x30, 0x0e,
  58325. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f, 0x7a, 0x65, 0x6d,
  58326. 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c,
  58327. 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x49, 0x6e, 0x63,
  58328. 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45,
  58329. 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18,
  58330. 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x77, 0x77,
  58331. 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d,
  58332. 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
  58333. 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00,
  58334. 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xa5, 0x60, 0x80,
  58335. 0xf3, 0xee, 0x19, 0xd2, 0xe4, 0x15, 0x94, 0x54, 0x12, 0x88, 0xee, 0xda,
  58336. 0x11, 0x11, 0x87, 0x99, 0x88, 0xb3, 0x71, 0xc7, 0x97, 0x78, 0x1b, 0x57,
  58337. 0x37, 0x1d, 0x0b, 0x1f, 0x2f, 0x2c, 0x35, 0x13, 0x75, 0xd3, 0x31, 0x3e,
  58338. 0x6f, 0x80, 0x21, 0xa5, 0xa3, 0xad, 0x10, 0x81, 0xb6, 0x37, 0xd4, 0x55,
  58339. 0x2e, 0xc1, 0xb8, 0x37, 0xa3, 0x3c, 0xe8, 0x81, 0x03, 0x3c, 0xda, 0x5f,
  58340. 0x6f, 0x45, 0x32, 0x2b, 0x0e, 0x99, 0x27, 0xfd, 0xe5, 0x6c, 0x07, 0xd9,
  58341. 0x4e, 0x0a, 0x8b, 0x23, 0x74, 0x96, 0x25, 0x97, 0xae, 0x6d, 0x19, 0xba,
  58342. 0xbf, 0x0f, 0xc8, 0xa1, 0xe5, 0xea, 0xa8, 0x00, 0x09, 0xc3, 0x9a, 0xef,
  58343. 0x09, 0x33, 0xc1, 0x33, 0x2e, 0x7b, 0x6d, 0xa7, 0x66, 0x87, 0xb6, 0x3a,
  58344. 0xb9, 0xdb, 0x4c, 0x5e, 0xb5, 0x55, 0x69, 0x37, 0x17, 0x92, 0x1f, 0xe3,
  58345. 0x53, 0x1a, 0x2d, 0x25, 0xd0, 0xcf, 0x72, 0x37, 0xc2, 0x89, 0x83, 0x78,
  58346. 0xcf, 0xac, 0x2e, 0x46, 0x92, 0x5c, 0x4a, 0xba, 0x7d, 0xa0, 0x22, 0x34,
  58347. 0xb1, 0x22, 0x26, 0x99, 0xda, 0xe8, 0x97, 0xe2, 0x0c, 0xd3, 0xbc, 0x97,
  58348. 0x7e, 0xa8, 0xb9, 0xe3, 0xe2, 0x7f, 0x56, 0xef, 0x22, 0xee, 0x15, 0x95,
  58349. 0xa6, 0xd1, 0xf4, 0xa7, 0xac, 0x4a, 0xab, 0xc1, 0x1a, 0xda, 0xc5, 0x5f,
  58350. 0xa5, 0x5e, 0x2f, 0x15, 0x9c, 0x36, 0xbe, 0xd3, 0x47, 0xb6, 0x86, 0xb9,
  58351. 0xc6, 0x59, 0x39, 0x36, 0xad, 0x84, 0x53, 0x95, 0x72, 0x91, 0x89, 0x51,
  58352. 0x32, 0x77, 0xf1, 0xa5, 0x93, 0xfe, 0xf0, 0x41, 0x7c, 0x64, 0xf1, 0xb0,
  58353. 0x8b, 0x81, 0x8d, 0x3a, 0x2c, 0x9e, 0xbe, 0x2e, 0x8b, 0xf7, 0x80, 0x63,
  58354. 0x35, 0x32, 0xfa, 0x26, 0xe0, 0x63, 0xbf, 0x5e, 0xaf, 0xf0, 0x08, 0xe0,
  58355. 0x80, 0x65, 0x38, 0xfa, 0x21, 0xaa, 0x91, 0x34, 0x48, 0x3d, 0x32, 0x5c,
  58356. 0xbf, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x32, 0x30, 0x30, 0x30, 0x0f,
  58357. 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, 0x08, 0x30, 0x06, 0x82, 0x04, 0x61,
  58358. 0x2a, 0x62, 0x2a, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16,
  58359. 0x04, 0x14, 0x3d, 0x55, 0x74, 0xf8, 0x3a, 0x26, 0x03, 0x8c, 0x6a, 0x2e,
  58360. 0x91, 0x0e, 0x18, 0x70, 0xb4, 0xa4, 0xcc, 0x04, 0x00, 0xd3, 0x30, 0x0d,
  58361. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05,
  58362. 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x8f, 0x3b, 0xff, 0x46, 0x0c, 0xb5,
  58363. 0x21, 0xdc, 0xcf, 0x61, 0x9a, 0x25, 0x93, 0x99, 0x68, 0x2f, 0x16, 0x71,
  58364. 0x15, 0x00, 0x5f, 0xb0, 0x9b, 0x43, 0x5c, 0x47, 0xe2, 0x8e, 0xc8, 0xea,
  58365. 0xb3, 0x30, 0x4d, 0x87, 0x90, 0xcf, 0x24, 0x37, 0x5c, 0xfd, 0xc8, 0xc6,
  58366. 0x09, 0x36, 0xb2, 0xfb, 0xfd, 0xc1, 0x82, 0x92, 0x77, 0x5b, 0x9d, 0xeb,
  58367. 0xac, 0x47, 0xbc, 0xda, 0x7c, 0x89, 0x19, 0x03, 0x9e, 0xcd, 0x96, 0x2a,
  58368. 0x90, 0x55, 0x23, 0x19, 0xac, 0x9d, 0x49, 0xfb, 0xa0, 0x31, 0x7d, 0x6b,
  58369. 0x1a, 0x16, 0x13, 0xb1, 0xa9, 0xc9, 0xc4, 0xaf, 0xf1, 0xb4, 0xa7, 0x9b,
  58370. 0x08, 0x64, 0x6a, 0x09, 0xcd, 0x4a, 0x03, 0x4c, 0x93, 0xb6, 0xcf, 0x29,
  58371. 0xdb, 0x56, 0x88, 0x8e, 0xed, 0x08, 0x6d, 0x8d, 0x76, 0xa3, 0xd7, 0xc6,
  58372. 0x69, 0xa1, 0xf5, 0xd2, 0xd0, 0x0a, 0x4b, 0xfa, 0x88, 0x66, 0x6c, 0xe5,
  58373. 0x4a, 0xee, 0x13, 0xad, 0xad, 0x22, 0x25, 0x73, 0x39, 0x56, 0x74, 0x0e,
  58374. 0xda, 0xcd, 0x35, 0x67, 0xe3, 0x81, 0x5c, 0xc5, 0xae, 0x3c, 0x4f, 0x47,
  58375. 0x3e, 0x97, 0xde, 0xac, 0xf6, 0xe1, 0x26, 0xe2, 0xe0, 0x66, 0x48, 0x20,
  58376. 0x7c, 0x02, 0x81, 0x3e, 0x7d, 0x34, 0xb7, 0x73, 0x3e, 0x2e, 0xd6, 0x20,
  58377. 0x1c, 0xdf, 0xf1, 0xae, 0x86, 0x8b, 0xb2, 0xc2, 0x9b, 0x68, 0x9c, 0xf6,
  58378. 0x1a, 0x5e, 0x30, 0x06, 0x39, 0x0a, 0x1f, 0x7b, 0xd7, 0x18, 0x4b, 0x06,
  58379. 0x9d, 0xff, 0x84, 0x57, 0xcc, 0x92, 0xad, 0x81, 0x0a, 0x19, 0x11, 0xc4,
  58380. 0xac, 0x59, 0x00, 0xe8, 0x5a, 0x70, 0x78, 0xd6, 0x9f, 0xe0, 0x82, 0x2a,
  58381. 0x1f, 0x09, 0x36, 0x1c, 0x52, 0x98, 0xf7, 0x95, 0x8f, 0xf9, 0x48, 0x4f,
  58382. 0x30, 0x52, 0xb5, 0xf3, 0x8d, 0x13, 0x93, 0x27, 0xbe, 0xb4, 0x75, 0x39,
  58383. 0x65, 0xc6, 0x48, 0x4e, 0x32, 0xd7, 0xf4, 0xc3, 0x26, 0x8d
  58384. };
  58385. WOLFSSL_X509* x509 = NULL;
  58386. int certSize = (int)(sizeof(cert_der) / sizeof(unsigned char));
  58387. const char *name1 = "ab";
  58388. int nameLen1 = (int)(XSTRLEN(name1));
  58389. const char *name2 = "acccbccc";
  58390. int nameLen2 = (int)(XSTRLEN(name2));
  58391. const char *name3 = "accb";
  58392. int nameLen3 = (int)(XSTRLEN(name3));
  58393. const char *name4 = "accda";
  58394. int nameLen4 = (int)(XSTRLEN(name4));
  58395. const char *name5 = "acc\0bcc";
  58396. int nameLen5 = 7;
  58397. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(
  58398. cert_der, certSize, WOLFSSL_FILETYPE_ASN1));
  58399. /* Ensure that "a*b*" matches "ab" */
  58400. ExpectIntEQ(wolfSSL_X509_check_host(x509, name1, nameLen1,
  58401. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  58402. /* Ensure that "a*b*" matches "acccbccc" */
  58403. ExpectIntEQ(wolfSSL_X509_check_host(x509, name2, nameLen2,
  58404. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  58405. /* Ensure that "a*b*" matches "accb" */
  58406. ExpectIntEQ(wolfSSL_X509_check_host(x509, name3, nameLen3,
  58407. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  58408. /* Ensure that "a*b*" does not match "accda" */
  58409. ExpectIntNE(wolfSSL_X509_check_host(x509, name4, nameLen4,
  58410. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  58411. /* WOLFSSL_LEFT_MOST_WILDCARD_ONLY flag should fail on all cases, since
  58412. * 'a*b*' alt name does not have wildcard left-most */
  58413. ExpectIntEQ(wolfSSL_X509_check_host(x509, name1, nameLen1,
  58414. WOLFSSL_ALWAYS_CHECK_SUBJECT | WOLFSSL_LEFT_MOST_WILDCARD_ONLY,
  58415. NULL), WOLFSSL_FAILURE);
  58416. ExpectIntEQ(wolfSSL_X509_check_host(x509, name2, nameLen2,
  58417. WOLFSSL_ALWAYS_CHECK_SUBJECT | WOLFSSL_LEFT_MOST_WILDCARD_ONLY,
  58418. NULL), WOLFSSL_FAILURE);
  58419. ExpectIntEQ(wolfSSL_X509_check_host(x509, name3, nameLen3,
  58420. WOLFSSL_ALWAYS_CHECK_SUBJECT | WOLFSSL_LEFT_MOST_WILDCARD_ONLY,
  58421. NULL), WOLFSSL_FAILURE);
  58422. ExpectIntEQ(wolfSSL_X509_check_host(x509, name4, nameLen4,
  58423. WOLFSSL_ALWAYS_CHECK_SUBJECT | WOLFSSL_LEFT_MOST_WILDCARD_ONLY,
  58424. NULL), WOLFSSL_FAILURE);
  58425. /* Ensure that "a*b*" matches "ab", testing openssl behavior replication
  58426. * on check len input handling, 0 for len is OK as it should then use
  58427. * strlen(name1) */
  58428. ExpectIntEQ(wolfSSL_X509_check_host(x509, name1, 0,
  58429. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  58430. /* Openssl also allows for len to include NULL terminator */
  58431. ExpectIntEQ(wolfSSL_X509_check_host(x509, name1, nameLen1 + 1,
  58432. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  58433. /* Ensure that check string with NULL terminator in middle is
  58434. * rejected */
  58435. ExpectIntNE(wolfSSL_X509_check_host(x509, name5, nameLen5,
  58436. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  58437. wolfSSL_X509_free(x509);
  58438. #endif
  58439. return EXPECT_RESULT();
  58440. }
  58441. static int test_wolfSSL_X509_name_match3(void)
  58442. {
  58443. EXPECT_DECLS;
  58444. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  58445. /* A certificate with the subject alternative name *.example.com */
  58446. const unsigned char cert_der[] = {
  58447. 0x30, 0x82, 0x03, 0xb7, 0x30, 0x82, 0x02, 0x9f, 0xa0, 0x03, 0x02, 0x01,
  58448. 0x02, 0x02, 0x14, 0x59, 0xbb, 0xf6, 0xde, 0xb8, 0x3d, 0x0e, 0x8c, 0xe4,
  58449. 0xbd, 0x98, 0xa3, 0xbe, 0x3e, 0x8f, 0xdc, 0xbd, 0x7f, 0xcc, 0xae, 0x30,
  58450. 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b,
  58451. 0x05, 0x00, 0x30, 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
  58452. 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55,
  58453. 0x04, 0x08, 0x0c, 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31,
  58454. 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f,
  58455. 0x7a, 0x65, 0x6d, 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55,
  58456. 0x04, 0x0a, 0x0c, 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20,
  58457. 0x49, 0x6e, 0x63, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b,
  58458. 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e,
  58459. 0x67, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f,
  58460. 0x77, 0x77, 0x77, 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e,
  58461. 0x63, 0x6f, 0x6d, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x34, 0x30, 0x35, 0x33,
  58462. 0x31, 0x30, 0x30, 0x33, 0x37, 0x34, 0x39, 0x5a, 0x17, 0x0d, 0x33, 0x34,
  58463. 0x30, 0x35, 0x32, 0x39, 0x30, 0x30, 0x33, 0x37, 0x34, 0x39, 0x5a, 0x30,
  58464. 0x77, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,
  58465. 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c,
  58466. 0x07, 0x4d, 0x6f, 0x6e, 0x74, 0x61, 0x6e, 0x61, 0x31, 0x10, 0x30, 0x0e,
  58467. 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x42, 0x6f, 0x7a, 0x65, 0x6d,
  58468. 0x61, 0x6e, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c,
  58469. 0x0b, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x49, 0x6e, 0x63,
  58470. 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45,
  58471. 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18,
  58472. 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x77, 0x77,
  58473. 0x2e, 0x77, 0x6f, 0x6c, 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d,
  58474. 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
  58475. 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00,
  58476. 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xda, 0x78, 0x16,
  58477. 0x05, 0x65, 0xf2, 0x85, 0xf2, 0x61, 0x7f, 0xb1, 0x4d, 0x73, 0xe2, 0x82,
  58478. 0xb5, 0x3d, 0xf7, 0x9d, 0x05, 0x65, 0xed, 0x9d, 0xc3, 0x29, 0x7a, 0x92,
  58479. 0x2c, 0x06, 0x5f, 0xc8, 0x13, 0x55, 0x42, 0x4e, 0xbd, 0xe2, 0x56, 0x2a,
  58480. 0x4b, 0xac, 0xe6, 0x1b, 0x10, 0xc9, 0xdb, 0x9a, 0x45, 0x36, 0xed, 0xf3,
  58481. 0x26, 0x8c, 0x22, 0x88, 0x1e, 0x6d, 0x2b, 0x41, 0xfa, 0x0d, 0x43, 0x88,
  58482. 0x88, 0xde, 0x8d, 0x2e, 0xca, 0x6e, 0x7c, 0x62, 0x66, 0x3e, 0xfa, 0x4e,
  58483. 0x71, 0xea, 0x7d, 0x3b, 0x32, 0x33, 0x5c, 0x7a, 0x7e, 0xea, 0x74, 0xbd,
  58484. 0xb6, 0x8f, 0x4c, 0x1c, 0x7a, 0x79, 0x94, 0xf1, 0xe8, 0x02, 0x67, 0x98,
  58485. 0x25, 0xb4, 0x31, 0x80, 0xc1, 0xae, 0xbf, 0xef, 0xf2, 0x6c, 0x78, 0x42,
  58486. 0xef, 0xb5, 0xc6, 0x01, 0x47, 0x79, 0x8d, 0x92, 0xce, 0xc1, 0xb5, 0x98,
  58487. 0x76, 0xf0, 0x84, 0xa2, 0x53, 0x90, 0xe5, 0x39, 0xc7, 0xbd, 0xf2, 0xbb,
  58488. 0xe3, 0x3f, 0x00, 0xf6, 0xf0, 0x46, 0x86, 0xee, 0x55, 0xbd, 0x2c, 0x1f,
  58489. 0x97, 0x24, 0x7c, 0xbc, 0xda, 0x2f, 0x1b, 0x53, 0xef, 0x26, 0x56, 0xcc,
  58490. 0xb7, 0xd8, 0xca, 0x17, 0x20, 0x4e, 0x62, 0x03, 0x66, 0x32, 0xb3, 0xd1,
  58491. 0x71, 0x26, 0x6c, 0xff, 0xd1, 0x9e, 0x44, 0x86, 0x2a, 0xae, 0xba, 0x43,
  58492. 0x00, 0x13, 0x7e, 0x50, 0xdd, 0x3e, 0x27, 0x39, 0x70, 0x1c, 0x0c, 0x0b,
  58493. 0xe8, 0xa2, 0xae, 0x03, 0x09, 0x2e, 0xd8, 0x71, 0xee, 0x7b, 0x1a, 0x09,
  58494. 0x2d, 0xe1, 0xd5, 0xde, 0xf5, 0xa3, 0x36, 0x77, 0x90, 0x97, 0x99, 0xd7,
  58495. 0x6c, 0xb7, 0x5c, 0x9d, 0xf7, 0x7e, 0x41, 0x89, 0xfe, 0xe4, 0x08, 0xc6,
  58496. 0x0b, 0xe4, 0x9b, 0x5f, 0x51, 0xa6, 0x08, 0xb8, 0x99, 0x81, 0xe9, 0xce,
  58497. 0xb4, 0x2d, 0xb2, 0x92, 0x9f, 0xe5, 0x1a, 0x98, 0x76, 0x20, 0x70, 0x54,
  58498. 0x93, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x3b, 0x30, 0x39, 0x30, 0x18,
  58499. 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, 0x11, 0x30, 0x0f, 0x82, 0x0d, 0x2a,
  58500. 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d,
  58501. 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x60,
  58502. 0xd4, 0x26, 0xbb, 0xcc, 0x7c, 0x29, 0xa2, 0x88, 0x3c, 0x76, 0x7d, 0xb4,
  58503. 0x86, 0x8b, 0x47, 0x64, 0x5b, 0x87, 0xe0, 0x30, 0x0d, 0x06, 0x09, 0x2a,
  58504. 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82,
  58505. 0x01, 0x01, 0x00, 0xc3, 0x0d, 0x03, 0x67, 0xbb, 0x47, 0x8b, 0xf3, 0x20,
  58506. 0xdc, 0x7d, 0x2e, 0xe1, 0xd9, 0xf0, 0x01, 0xc4, 0x66, 0xc2, 0xe1, 0xcd,
  58507. 0xc3, 0x4a, 0x72, 0xf0, 0x6e, 0x38, 0xcf, 0x63, 0x01, 0x96, 0x9e, 0x84,
  58508. 0xb9, 0xce, 0x1d, 0xba, 0x4b, 0xe0, 0x70, 0x86, 0x2b, 0x5a, 0xab, 0xec,
  58509. 0xbf, 0xc2, 0xaa, 0x64, 0xa2, 0x6c, 0xd2, 0x42, 0x52, 0xd4, 0xbe, 0x8a,
  58510. 0xca, 0x9c, 0x03, 0xf3, 0xd6, 0x5f, 0xcd, 0x23, 0x9f, 0xf5, 0xa9, 0x04,
  58511. 0x40, 0x5b, 0x66, 0x78, 0xc0, 0xac, 0xa1, 0xdb, 0x5d, 0xd1, 0x94, 0xfc,
  58512. 0x47, 0x94, 0xf5, 0x45, 0xe3, 0x70, 0x13, 0x3f, 0x66, 0x6d, 0xdd, 0x73,
  58513. 0x68, 0x68, 0xe2, 0xd2, 0x89, 0xcb, 0x7f, 0xc6, 0xca, 0xd6, 0x96, 0x0b,
  58514. 0xcc, 0xdd, 0xa1, 0x74, 0xda, 0x33, 0xe8, 0x9e, 0xda, 0xb7, 0xd9, 0x12,
  58515. 0xab, 0x85, 0x9d, 0x0c, 0xde, 0xa0, 0x7d, 0x7e, 0xa1, 0x91, 0xed, 0xe5,
  58516. 0x32, 0x7c, 0xc5, 0xea, 0x1d, 0x4a, 0xb5, 0x38, 0x63, 0x17, 0xf3, 0x4f,
  58517. 0x2c, 0x4a, 0x58, 0x86, 0x09, 0x33, 0x86, 0xc4, 0xe7, 0x56, 0x6f, 0x32,
  58518. 0x71, 0xb7, 0xd0, 0x83, 0x12, 0x9e, 0x26, 0x0a, 0x3a, 0x45, 0xcb, 0xd7,
  58519. 0x4e, 0xab, 0xa4, 0xc3, 0xee, 0x4c, 0xc0, 0x38, 0xa1, 0xfa, 0xba, 0xfa,
  58520. 0xb7, 0x80, 0x69, 0x67, 0xa3, 0xef, 0x89, 0xba, 0xce, 0x89, 0x91, 0x3d,
  58521. 0x6a, 0x76, 0xe9, 0x3b, 0x32, 0x86, 0x76, 0x85, 0x6b, 0x4f, 0x7f, 0xbc,
  58522. 0x7a, 0x5b, 0x31, 0x92, 0x79, 0x35, 0xf8, 0xb9, 0xb1, 0xd7, 0xdb, 0xa9,
  58523. 0x6a, 0x8a, 0x91, 0x60, 0x65, 0xd4, 0x76, 0x54, 0x55, 0x57, 0xb9, 0x35,
  58524. 0xe0, 0xf5, 0xbb, 0x8f, 0xd4, 0x40, 0x75, 0xbb, 0x47, 0xa8, 0xf9, 0x0f,
  58525. 0xea, 0xc9, 0x6e, 0x84, 0xd5, 0xf5, 0x58, 0x2d, 0xe5, 0x76, 0x7b, 0xdf,
  58526. 0x97, 0x05, 0x5e, 0xaf, 0x50, 0xf5, 0x48
  58527. };
  58528. WOLFSSL_X509* x509 = NULL;
  58529. int certSize = (int)(sizeof(cert_der) / sizeof(unsigned char));
  58530. const char *name1 = "foo.example.com";
  58531. int nameLen1 = (int)(XSTRLEN(name1));
  58532. const char *name2 = "x.y.example.com";
  58533. int nameLen2 = (int)(XSTRLEN(name2));
  58534. const char *name3 = "example.com";
  58535. int nameLen3 = (int)(XSTRLEN(name3));
  58536. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_buffer(
  58537. cert_der, certSize, WOLFSSL_FILETYPE_ASN1));
  58538. /* Ensure that "*.example.com" matches "foo.example.com" */
  58539. ExpectIntEQ(wolfSSL_X509_check_host(x509, name1, nameLen1,
  58540. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  58541. /* Ensure that "*.example.com" does NOT match "x.y.example.com" */
  58542. ExpectIntNE(wolfSSL_X509_check_host(x509, name2, nameLen2,
  58543. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  58544. /* Ensure that "*.example.com" does NOT match "example.com" */
  58545. ExpectIntNE(wolfSSL_X509_check_host(x509, name3, nameLen3,
  58546. WOLFSSL_ALWAYS_CHECK_SUBJECT, NULL), WOLFSSL_SUCCESS);
  58547. /* WOLFSSL_LEFT_MOST_WILDCARD_ONLY, should match "foo.example.com" */
  58548. ExpectIntEQ(wolfSSL_X509_check_host(x509, name1, nameLen1,
  58549. WOLFSSL_ALWAYS_CHECK_SUBJECT | WOLFSSL_LEFT_MOST_WILDCARD_ONLY,
  58550. NULL), WOLFSSL_SUCCESS);
  58551. /* WOLFSSL_LEFT_MOST_WILDCARD_ONLY, should NOT match "x.y.example.com" */
  58552. ExpectIntNE(wolfSSL_X509_check_host(x509, name2, nameLen2,
  58553. WOLFSSL_ALWAYS_CHECK_SUBJECT | WOLFSSL_LEFT_MOST_WILDCARD_ONLY,
  58554. NULL), WOLFSSL_SUCCESS);
  58555. /* WOLFSSL_LEFT_MOST_WILDCARD_ONLY, should NOT match "example.com" */
  58556. ExpectIntNE(wolfSSL_X509_check_host(x509, name3, nameLen3,
  58557. WOLFSSL_ALWAYS_CHECK_SUBJECT | WOLFSSL_LEFT_MOST_WILDCARD_ONLY,
  58558. NULL), WOLFSSL_SUCCESS);
  58559. wolfSSL_X509_free(x509);
  58560. #endif
  58561. return EXPECT_RESULT();
  58562. }
  58563. static int test_wolfSSL_X509_max_altnames(void)
  58564. {
  58565. EXPECT_DECLS;
  58566. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA)
  58567. /* Only test if max alt names has not been modified */
  58568. #if WOLFSSL_MAX_ALT_NAMES <= 1024
  58569. WOLFSSL_CTX* ctx = NULL;
  58570. /* File contains a certificate encoded with 130 subject alternative names */
  58571. const char* over_max_altnames_cert = \
  58572. "./certs/test/cert-over-max-altnames.pem";
  58573. #ifndef NO_WOLFSSL_SERVER
  58574. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  58575. #else
  58576. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  58577. #endif
  58578. ExpectIntNE(wolfSSL_CTX_load_verify_locations_ex(ctx,
  58579. over_max_altnames_cert, NULL, WOLFSSL_LOAD_FLAG_NONE),
  58580. WOLFSSL_SUCCESS);
  58581. wolfSSL_CTX_free(ctx);
  58582. #endif
  58583. #endif
  58584. return EXPECT_RESULT();
  58585. }
  58586. static int test_wolfSSL_X509_max_name_constraints(void)
  58587. {
  58588. EXPECT_DECLS;
  58589. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \
  58590. !defined(IGNORE_NAME_CONSTRAINTS)
  58591. /* Only test if max name constraints has not been modified */
  58592. #if WOLFSSL_MAX_NAME_CONSTRAINTS == 128
  58593. WOLFSSL_CTX* ctx = NULL;
  58594. /* File contains a certificate with 130 name constraints */
  58595. const char* over_max_nc = "./certs/test/cert-over-max-nc.pem";
  58596. #ifndef NO_WOLFSSL_SERVER
  58597. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  58598. #else
  58599. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  58600. #endif
  58601. ExpectIntNE(wolfSSL_CTX_load_verify_locations_ex(ctx, over_max_nc,
  58602. NULL, WOLFSSL_LOAD_FLAG_NONE), WOLFSSL_SUCCESS);
  58603. wolfSSL_CTX_free(ctx);
  58604. #endif
  58605. #endif
  58606. return EXPECT_RESULT();
  58607. }
  58608. static int test_wolfSSL_X509(void)
  58609. {
  58610. EXPECT_DECLS;
  58611. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  58612. !defined(NO_RSA)
  58613. X509* x509 = NULL;
  58614. #ifndef NO_BIO
  58615. BIO* bio = NULL;
  58616. X509_STORE_CTX* ctx = NULL;
  58617. X509_STORE* store = NULL;
  58618. #endif
  58619. char der[] = "certs/ca-cert.der";
  58620. XFILE fp = XBADFILE;
  58621. ExpectNotNull(x509 = X509_new());
  58622. X509_free(x509);
  58623. x509 = NULL;
  58624. #ifndef NO_BIO
  58625. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  58626. SSL_FILETYPE_PEM));
  58627. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  58628. #ifdef WOLFSSL_CERT_GEN
  58629. ExpectIntEQ(i2d_X509_bio(bio, x509), SSL_SUCCESS);
  58630. #endif
  58631. ExpectNotNull(ctx = X509_STORE_CTX_new());
  58632. ExpectIntEQ(X509_verify_cert(ctx), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  58633. ExpectNotNull(store = X509_STORE_new());
  58634. ExpectIntEQ(X509_STORE_add_cert(store, x509), SSL_SUCCESS);
  58635. ExpectIntEQ(X509_STORE_CTX_init(ctx, store, x509, NULL), SSL_SUCCESS);
  58636. ExpectIntEQ(X509_verify_cert(ctx), SSL_SUCCESS);
  58637. X509_STORE_CTX_free(ctx);
  58638. X509_STORE_free(store);
  58639. X509_free(x509);
  58640. x509 = NULL;
  58641. BIO_free(bio);
  58642. #endif
  58643. /** d2i_X509_fp test **/
  58644. ExpectTrue((fp = XFOPEN(der, "rb")) != XBADFILE);
  58645. ExpectNotNull(x509 = (X509 *)d2i_X509_fp(fp, (X509 **)NULL));
  58646. ExpectNotNull(x509);
  58647. X509_free(x509);
  58648. x509 = NULL;
  58649. if (fp != XBADFILE) {
  58650. XFCLOSE(fp);
  58651. fp = XBADFILE;
  58652. }
  58653. ExpectTrue((fp = XFOPEN(der, "rb")) != XBADFILE);
  58654. ExpectNotNull((X509 *)d2i_X509_fp(fp, (X509 **)&x509));
  58655. ExpectNotNull(x509);
  58656. X509_free(x509);
  58657. if (fp != XBADFILE)
  58658. XFCLOSE(fp);
  58659. /* X509_up_ref test */
  58660. ExpectIntEQ(X509_up_ref(NULL), 0);
  58661. ExpectNotNull(x509 = X509_new()); /* refCount = 1 */
  58662. ExpectIntEQ(X509_up_ref(x509), 1); /* refCount = 2 */
  58663. ExpectIntEQ(X509_up_ref(x509), 1); /* refCount = 3 */
  58664. X509_free(x509); /* refCount = 2 */
  58665. X509_free(x509); /* refCount = 1 */
  58666. X509_free(x509); /* refCount = 0, free */
  58667. #endif
  58668. return EXPECT_RESULT();
  58669. }
  58670. static int test_wolfSSL_X509_get_ext_count(void)
  58671. {
  58672. EXPECT_DECLS;
  58673. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  58674. !defined(NO_RSA)
  58675. int ret = 0;
  58676. WOLFSSL_X509* x509 = NULL;
  58677. const char ocspRootCaFile[] = "./certs/ocsp/root-ca-cert.pem";
  58678. XFILE f = XBADFILE;
  58679. /* NULL parameter check */
  58680. ExpectIntEQ(X509_get_ext_count(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  58681. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  58682. SSL_FILETYPE_PEM));
  58683. ExpectIntEQ(X509_get_ext_count(x509), 5);
  58684. wolfSSL_X509_free(x509);
  58685. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(ocspRootCaFile,
  58686. SSL_FILETYPE_PEM));
  58687. ExpectIntEQ(X509_get_ext_count(x509), 5);
  58688. wolfSSL_X509_free(x509);
  58689. ExpectTrue((f = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  58690. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  58691. if (f != XBADFILE)
  58692. XFCLOSE(f);
  58693. /* wolfSSL_X509_get_ext_count() valid input */
  58694. ExpectIntEQ((ret = wolfSSL_X509_get_ext_count(x509)), 5);
  58695. /* wolfSSL_X509_get_ext_count() NULL argument */
  58696. ExpectIntEQ((ret = wolfSSL_X509_get_ext_count(NULL)), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  58697. wolfSSL_X509_free(x509);
  58698. #endif
  58699. return EXPECT_RESULT();
  58700. }
  58701. static int test_wolfSSL_X509_sign2(void)
  58702. {
  58703. EXPECT_DECLS;
  58704. /* test requires WOLFSSL_AKID_NAME to match expected output */
  58705. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_CERTS) && \
  58706. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_ALT_NAMES) && \
  58707. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_AKID_NAME) && \
  58708. (defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || \
  58709. defined(WOLFSSL_IP_ALT_NAME))
  58710. WOLFSSL_X509 *x509 = NULL;
  58711. WOLFSSL_X509 *ca = NULL;
  58712. const unsigned char *der = NULL;
  58713. const unsigned char *pt = NULL;
  58714. WOLFSSL_EVP_PKEY *priv = NULL;
  58715. WOLFSSL_X509_NAME *name = NULL;
  58716. int derSz;
  58717. #ifndef NO_ASN_TIME
  58718. WOLFSSL_ASN1_TIME *notBefore = NULL;
  58719. WOLFSSL_ASN1_TIME *notAfter = NULL;
  58720. const int year = 365*24*60*60;
  58721. const int day = 24*60*60;
  58722. const int hour = 60*60;
  58723. const int mini = 60;
  58724. time_t t;
  58725. #endif
  58726. const unsigned char expected[] = {
  58727. 0x30, 0x82, 0x05, 0x13, 0x30, 0x82, 0x03, 0xFB, 0xA0, 0x03, 0x02, 0x01,
  58728. 0x02, 0x02, 0x14, 0x08, 0xB0, 0x54, 0x7A, 0x03, 0x5A, 0xEC, 0x55, 0x8A,
  58729. 0x12, 0xE8, 0xF9, 0x8E, 0x34, 0xB6, 0x13, 0xD9, 0x59, 0xB8, 0xE8, 0x30,
  58730. 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B,
  58731. 0x05, 0x00, 0x30, 0x81, 0x94, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55,
  58732. 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03,
  58733. 0x55, 0x04, 0x08, 0x0C, 0x07, 0x4D, 0x6F, 0x6E, 0x74, 0x61, 0x6E, 0x61,
  58734. 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0C, 0x07, 0x42,
  58735. 0x6F, 0x7A, 0x65, 0x6D, 0x61, 0x6E, 0x31, 0x11, 0x30, 0x0F, 0x06, 0x03,
  58736. 0x55, 0x04, 0x0A, 0x0C, 0x08, 0x53, 0x61, 0x77, 0x74, 0x6F, 0x6F, 0x74,
  58737. 0x68, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x0A,
  58738. 0x43, 0x6F, 0x6E, 0x73, 0x75, 0x6C, 0x74, 0x69, 0x6E, 0x67, 0x31, 0x18,
  58739. 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x77, 0x77, 0x77,
  58740. 0x2E, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D,
  58741. 0x31, 0x1F, 0x30, 0x1D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  58742. 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40, 0x77, 0x6F,
  58743. 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x30, 0x1E, 0x17,
  58744. 0x0D, 0x30, 0x30, 0x30, 0x32, 0x31, 0x35, 0x32, 0x30, 0x33, 0x30, 0x30,
  58745. 0x30, 0x5A, 0x17, 0x0D, 0x30, 0x31, 0x30, 0x32, 0x31, 0x34, 0x32, 0x30,
  58746. 0x33, 0x30, 0x30, 0x30, 0x5A, 0x30, 0x81, 0x9E, 0x31, 0x0B, 0x30, 0x09,
  58747. 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30,
  58748. 0x0E, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0C, 0x07, 0x4D, 0x6F, 0x6E, 0x74,
  58749. 0x61, 0x6E, 0x61, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x04, 0x07,
  58750. 0x0C, 0x07, 0x42, 0x6F, 0x7A, 0x65, 0x6D, 0x61, 0x6E, 0x31, 0x15, 0x30,
  58751. 0x13, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x0C, 0x77, 0x6F, 0x6C, 0x66,
  58752. 0x53, 0x53, 0x4C, 0x5F, 0x32, 0x30, 0x34, 0x38, 0x31, 0x19, 0x30, 0x17,
  58753. 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x10, 0x50, 0x72, 0x6F, 0x67, 0x72,
  58754. 0x61, 0x6D, 0x6D, 0x69, 0x6E, 0x67, 0x2D, 0x32, 0x30, 0x34, 0x38, 0x31,
  58755. 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x77, 0x77,
  58756. 0x77, 0x2E, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F,
  58757. 0x6D, 0x31, 0x1F, 0x30, 0x1D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7,
  58758. 0x0D, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6E, 0x66, 0x6F, 0x40, 0x77,
  58759. 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x30, 0x82,
  58760. 0x01, 0x22, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  58761. 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0F, 0x00, 0x30, 0x82,
  58762. 0x01, 0x0A, 0x02, 0x82, 0x01, 0x01, 0x00, 0xC3, 0x03, 0xD1, 0x2B, 0xFE,
  58763. 0x39, 0xA4, 0x32, 0x45, 0x3B, 0x53, 0xC8, 0x84, 0x2B, 0x2A, 0x7C, 0x74,
  58764. 0x9A, 0xBD, 0xAA, 0x2A, 0x52, 0x07, 0x47, 0xD6, 0xA6, 0x36, 0xB2, 0x07,
  58765. 0x32, 0x8E, 0xD0, 0xBA, 0x69, 0x7B, 0xC6, 0xC3, 0x44, 0x9E, 0xD4, 0x81,
  58766. 0x48, 0xFD, 0x2D, 0x68, 0xA2, 0x8B, 0x67, 0xBB, 0xA1, 0x75, 0xC8, 0x36,
  58767. 0x2C, 0x4A, 0xD2, 0x1B, 0xF7, 0x8B, 0xBA, 0xCF, 0x0D, 0xF9, 0xEF, 0xEC,
  58768. 0xF1, 0x81, 0x1E, 0x7B, 0x9B, 0x03, 0x47, 0x9A, 0xBF, 0x65, 0xCC, 0x7F,
  58769. 0x65, 0x24, 0x69, 0xA6, 0xE8, 0x14, 0x89, 0x5B, 0xE4, 0x34, 0xF7, 0xC5,
  58770. 0xB0, 0x14, 0x93, 0xF5, 0x67, 0x7B, 0x3A, 0x7A, 0x78, 0xE1, 0x01, 0x56,
  58771. 0x56, 0x91, 0xA6, 0x13, 0x42, 0x8D, 0xD2, 0x3C, 0x40, 0x9C, 0x4C, 0xEF,
  58772. 0xD1, 0x86, 0xDF, 0x37, 0x51, 0x1B, 0x0C, 0xA1, 0x3B, 0xF5, 0xF1, 0xA3,
  58773. 0x4A, 0x35, 0xE4, 0xE1, 0xCE, 0x96, 0xDF, 0x1B, 0x7E, 0xBF, 0x4E, 0x97,
  58774. 0xD0, 0x10, 0xE8, 0xA8, 0x08, 0x30, 0x81, 0xAF, 0x20, 0x0B, 0x43, 0x14,
  58775. 0xC5, 0x74, 0x67, 0xB4, 0x32, 0x82, 0x6F, 0x8D, 0x86, 0xC2, 0x88, 0x40,
  58776. 0x99, 0x36, 0x83, 0xBA, 0x1E, 0x40, 0x72, 0x22, 0x17, 0xD7, 0x52, 0x65,
  58777. 0x24, 0x73, 0xB0, 0xCE, 0xEF, 0x19, 0xCD, 0xAE, 0xFF, 0x78, 0x6C, 0x7B,
  58778. 0xC0, 0x12, 0x03, 0xD4, 0x4E, 0x72, 0x0D, 0x50, 0x6D, 0x3B, 0xA3, 0x3B,
  58779. 0xA3, 0x99, 0x5E, 0x9D, 0xC8, 0xD9, 0x0C, 0x85, 0xB3, 0xD9, 0x8A, 0xD9,
  58780. 0x54, 0x26, 0xDB, 0x6D, 0xFA, 0xAC, 0xBB, 0xFF, 0x25, 0x4C, 0xC4, 0xD1,
  58781. 0x79, 0xF4, 0x71, 0xD3, 0x86, 0x40, 0x18, 0x13, 0xB0, 0x63, 0xB5, 0x72,
  58782. 0x4E, 0x30, 0xC4, 0x97, 0x84, 0x86, 0x2D, 0x56, 0x2F, 0xD7, 0x15, 0xF7,
  58783. 0x7F, 0xC0, 0xAE, 0xF5, 0xFC, 0x5B, 0xE5, 0xFB, 0xA1, 0xBA, 0xD3, 0x02,
  58784. 0x03, 0x01, 0x00, 0x01, 0xA3, 0x82, 0x01, 0x4F, 0x30, 0x82, 0x01, 0x4B,
  58785. 0x30, 0x0C, 0x06, 0x03, 0x55, 0x1D, 0x13, 0x04, 0x05, 0x30, 0x03, 0x01,
  58786. 0x01, 0xFF, 0x30, 0x1C, 0x06, 0x03, 0x55, 0x1D, 0x11, 0x04, 0x15, 0x30,
  58787. 0x13, 0x82, 0x0B, 0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x2E, 0x63,
  58788. 0x6F, 0x6D, 0x87, 0x04, 0x7F, 0x00, 0x00, 0x01, 0x30, 0x1D, 0x06, 0x03,
  58789. 0x55, 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0x33, 0xD8, 0x45, 0x66, 0xD7,
  58790. 0x68, 0x87, 0x18, 0x7E, 0x54, 0x0D, 0x70, 0x27, 0x91, 0xC7, 0x26, 0xD7,
  58791. 0x85, 0x65, 0xC0, 0x30, 0x81, 0xDE, 0x06, 0x03, 0x55, 0x1D, 0x23, 0x04,
  58792. 0x81, 0xD6, 0x30, 0x81, 0xD3, 0x80, 0x14, 0x33, 0xD8, 0x45, 0x66, 0xD7,
  58793. 0x68, 0x87, 0x18, 0x7E, 0x54, 0x0D, 0x70, 0x27, 0x91, 0xC7, 0x26, 0xD7,
  58794. 0x85, 0x65, 0xC0, 0xA1, 0x81, 0xA4, 0xA4, 0x81, 0xA1, 0x30, 0x81, 0x9E,
  58795. 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55,
  58796. 0x53, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0C, 0x07,
  58797. 0x4D, 0x6F, 0x6E, 0x74, 0x61, 0x6E, 0x61, 0x31, 0x10, 0x30, 0x0E, 0x06,
  58798. 0x03, 0x55, 0x04, 0x07, 0x0C, 0x07, 0x42, 0x6F, 0x7A, 0x65, 0x6D, 0x61,
  58799. 0x6E, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x0C,
  58800. 0x77, 0x6F, 0x6C, 0x66, 0x53, 0x53, 0x4C, 0x5F, 0x32, 0x30, 0x34, 0x38,
  58801. 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x10, 0x50,
  58802. 0x72, 0x6F, 0x67, 0x72, 0x61, 0x6D, 0x6D, 0x69, 0x6E, 0x67, 0x2D, 0x32,
  58803. 0x30, 0x34, 0x38, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03,
  58804. 0x0C, 0x0F, 0x77, 0x77, 0x77, 0x2E, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73,
  58805. 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x31, 0x1F, 0x30, 0x1D, 0x06, 0x09, 0x2A,
  58806. 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x01, 0x16, 0x10, 0x69, 0x6E,
  58807. 0x66, 0x6F, 0x40, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73, 0x6C, 0x2E, 0x63,
  58808. 0x6F, 0x6D, 0x82, 0x14, 0x08, 0xB0, 0x54, 0x7A, 0x03, 0x5A, 0xEC, 0x55,
  58809. 0x8A, 0x12, 0xE8, 0xF9, 0x8E, 0x34, 0xB6, 0x13, 0xD9, 0x59, 0xB8, 0xE8,
  58810. 0x30, 0x1D, 0x06, 0x03, 0x55, 0x1D, 0x25, 0x04, 0x16, 0x30, 0x14, 0x06,
  58811. 0x08, 0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x01, 0x06, 0x08, 0x2B,
  58812. 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x02, 0x30, 0x0D, 0x06, 0x09, 0x2A,
  58813. 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B, 0x05, 0x00, 0x03, 0x82,
  58814. 0x01, 0x01, 0x00, 0x14, 0xFB, 0xD0, 0xCE, 0x31, 0x7F, 0xA5, 0x59, 0xFA,
  58815. 0x7C, 0x68, 0x26, 0xA7, 0xE8, 0x0D, 0x9F, 0x50, 0x57, 0xFA, 0x1C, 0x7C,
  58816. 0x5E, 0x43, 0xA4, 0x97, 0x47, 0xB6, 0x41, 0xAC, 0x63, 0xD3, 0x61, 0x8C,
  58817. 0x1F, 0x42, 0xEF, 0x53, 0xD0, 0xBA, 0x31, 0x4D, 0x99, 0x74, 0xA4, 0x60,
  58818. 0xDC, 0xC6, 0x6F, 0xCC, 0x1E, 0x25, 0x98, 0xE1, 0xA4, 0xA0, 0x67, 0x69,
  58819. 0x97, 0xE3, 0x97, 0x7C, 0x83, 0x28, 0xF1, 0xF4, 0x7D, 0x03, 0xA8, 0x31,
  58820. 0x77, 0xCC, 0xD1, 0x37, 0xEF, 0x7B, 0x4A, 0x71, 0x2D, 0x11, 0x7E, 0x92,
  58821. 0xF5, 0x67, 0xB7, 0x56, 0xBA, 0x28, 0xF8, 0xD6, 0xCE, 0x2A, 0x71, 0xE3,
  58822. 0x70, 0x6B, 0x09, 0x0F, 0x67, 0x6F, 0x7A, 0xE0, 0x89, 0xF6, 0x5E, 0x23,
  58823. 0x0C, 0x0A, 0x44, 0x4E, 0x65, 0x8E, 0x7B, 0x68, 0xD0, 0xAD, 0x76, 0x3E,
  58824. 0x2A, 0x0E, 0xA2, 0x05, 0x11, 0x74, 0x24, 0x08, 0x60, 0xED, 0x9F, 0x98,
  58825. 0x18, 0xE9, 0x91, 0x58, 0x36, 0xEC, 0xEC, 0x25, 0x6B, 0xBA, 0x9C, 0x87,
  58826. 0x38, 0x68, 0xDC, 0xDC, 0x15, 0x6F, 0x20, 0x68, 0xC4, 0xBF, 0x05, 0x5B,
  58827. 0x4A, 0x0C, 0x44, 0x2B, 0x92, 0x3F, 0x10, 0x99, 0xDC, 0xF6, 0x6C, 0x0E,
  58828. 0x34, 0x26, 0x6E, 0x6D, 0x4E, 0x12, 0xBC, 0x60, 0x8F, 0x27, 0x1D, 0x7A,
  58829. 0x00, 0x50, 0xBE, 0x23, 0xDE, 0x48, 0x47, 0x9F, 0xAD, 0x2F, 0x94, 0x3D,
  58830. 0x16, 0x73, 0x48, 0x6B, 0xC8, 0x97, 0xE6, 0xB4, 0xB3, 0x4B, 0xE1, 0x68,
  58831. 0x08, 0xC3, 0xE5, 0x34, 0x5F, 0x9B, 0xDA, 0xAB, 0xCA, 0x6D, 0x55, 0x32,
  58832. 0xEF, 0x6C, 0xEF, 0x9B, 0x8B, 0x5B, 0xC7, 0xF0, 0xC2, 0x0F, 0x8E, 0x93,
  58833. 0x09, 0x60, 0x3C, 0x0B, 0xDC, 0xBD, 0xDB, 0x4A, 0x2D, 0xD0, 0x98, 0xAA,
  58834. 0xAB, 0x6C, 0x6F, 0x6D, 0x6B, 0x6A, 0x5C, 0x33, 0xAC, 0xAD, 0xA8, 0x1B,
  58835. 0x38, 0x5D, 0x9F, 0xDA, 0xE7, 0x70, 0x07
  58836. };
  58837. pt = ca_key_der_2048;
  58838. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, &pt,
  58839. sizeof_ca_key_der_2048));
  58840. pt = client_cert_der_2048;
  58841. ExpectNotNull(x509 = wolfSSL_d2i_X509(NULL, &pt,
  58842. sizeof_client_cert_der_2048));
  58843. pt = ca_cert_der_2048;
  58844. ExpectNotNull(ca = wolfSSL_d2i_X509(NULL, &pt, sizeof_ca_cert_der_2048));
  58845. ExpectNotNull(name = wolfSSL_X509_get_subject_name(ca));
  58846. ExpectIntEQ(wolfSSL_X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  58847. #ifndef NO_ASN_TIME
  58848. t = (time_t)30 * year + 45 * day + 20 * hour + 30 * mini + 7 * day;
  58849. ExpectNotNull(notBefore = wolfSSL_ASN1_TIME_adj(NULL, t, 0, 0));
  58850. ExpectNotNull(notAfter = wolfSSL_ASN1_TIME_adj(NULL, t, 365, 0));
  58851. ExpectIntEQ(notAfter->length, 13);
  58852. ExpectTrue(wolfSSL_X509_set_notBefore(x509, notBefore));
  58853. ExpectTrue(wolfSSL_X509_set_notAfter(x509, notAfter));
  58854. #endif
  58855. ExpectIntGT(wolfSSL_X509_sign(x509, priv, EVP_sha256()), 0);
  58856. ExpectNotNull((der = wolfSSL_X509_get_der(x509, &derSz)));
  58857. ExpectIntEQ(derSz, sizeof(expected));
  58858. #ifndef NO_ASN_TIME
  58859. ExpectIntEQ(XMEMCMP(der, expected, derSz), 0);
  58860. #endif
  58861. wolfSSL_X509_free(ca);
  58862. wolfSSL_X509_free(x509);
  58863. wolfSSL_EVP_PKEY_free(priv);
  58864. #ifndef NO_ASN_TIME
  58865. wolfSSL_ASN1_TIME_free(notBefore);
  58866. wolfSSL_ASN1_TIME_free(notAfter);
  58867. #endif
  58868. #endif
  58869. return EXPECT_RESULT();
  58870. }
  58871. static int test_wolfSSL_X509_sign(void)
  58872. {
  58873. EXPECT_DECLS;
  58874. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_ASN_TIME) && \
  58875. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && !defined(NO_RSA)
  58876. int ret = 0;
  58877. char *cn = NULL;
  58878. word32 cnSz = 0;
  58879. X509_NAME *name = NULL;
  58880. X509 *x509 = NULL;
  58881. X509 *ca = NULL;
  58882. DecodedCert dCert;
  58883. EVP_PKEY *pub = NULL;
  58884. EVP_PKEY *priv = NULL;
  58885. EVP_MD_CTX *mctx = NULL;
  58886. #if defined(USE_CERT_BUFFERS_1024)
  58887. const unsigned char* rsaPriv = client_key_der_1024;
  58888. const unsigned char* rsaPub = client_keypub_der_1024;
  58889. const unsigned char* certIssuer = client_cert_der_1024;
  58890. long clientKeySz = (long)sizeof_client_key_der_1024;
  58891. long clientPubKeySz = (long)sizeof_client_keypub_der_1024;
  58892. long certIssuerSz = (long)sizeof_client_cert_der_1024;
  58893. #elif defined(USE_CERT_BUFFERS_2048)
  58894. const unsigned char* rsaPriv = client_key_der_2048;
  58895. const unsigned char* rsaPub = client_keypub_der_2048;
  58896. const unsigned char* certIssuer = client_cert_der_2048;
  58897. long clientKeySz = (long)sizeof_client_key_der_2048;
  58898. long clientPubKeySz = (long)sizeof_client_keypub_der_2048;
  58899. long certIssuerSz = (long)sizeof_client_cert_der_2048;
  58900. #endif
  58901. byte sn[16];
  58902. int snSz = sizeof(sn);
  58903. /* Set X509_NAME fields */
  58904. ExpectNotNull(name = X509_NAME_new());
  58905. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "countryName", MBSTRING_UTF8,
  58906. (byte*)"US", 2, -1, 0), SSL_SUCCESS);
  58907. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  58908. (byte*)"wolfssl.com", 11, -1, 0), SSL_SUCCESS);
  58909. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  58910. (byte*)"support@wolfssl.com", 19, -1, 0), SSL_SUCCESS);
  58911. /* Get private and public keys */
  58912. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL, &rsaPriv,
  58913. clientKeySz));
  58914. ExpectNotNull(pub = wolfSSL_d2i_PUBKEY(NULL, &rsaPub, clientPubKeySz));
  58915. ExpectNotNull(x509 = X509_new());
  58916. /* Set version 3 */
  58917. ExpectIntNE(X509_set_version(x509, 2L), 0);
  58918. /* Set subject name, add pubkey, and sign certificate */
  58919. ExpectIntEQ(X509_set_subject_name(x509, name), SSL_SUCCESS);
  58920. X509_NAME_free(name);
  58921. name = NULL;
  58922. ExpectIntEQ(X509_set_pubkey(x509, pub), SSL_SUCCESS);
  58923. #ifdef WOLFSSL_ALT_NAMES
  58924. /* Add some subject alt names */
  58925. ExpectIntNE(wolfSSL_X509_add_altname(NULL,
  58926. "ipsum", ASN_DNS_TYPE), SSL_SUCCESS);
  58927. ExpectIntEQ(wolfSSL_X509_add_altname(x509,
  58928. NULL, ASN_DNS_TYPE), SSL_SUCCESS);
  58929. ExpectIntEQ(wolfSSL_X509_add_altname(x509,
  58930. "sphygmomanometer",
  58931. ASN_DNS_TYPE), SSL_SUCCESS);
  58932. ExpectIntEQ(wolfSSL_X509_add_altname(x509,
  58933. "supercalifragilisticexpialidocious",
  58934. ASN_DNS_TYPE), SSL_SUCCESS);
  58935. ExpectIntEQ(wolfSSL_X509_add_altname(x509,
  58936. "Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch",
  58937. ASN_DNS_TYPE), SSL_SUCCESS);
  58938. #ifdef WOLFSSL_IP_ALT_NAME
  58939. {
  58940. unsigned char ip4_type[] = {127,128,0,255};
  58941. unsigned char ip6_type[] = {0xdd, 0xcc, 0xba, 0xab,
  58942. 0xff, 0xee, 0x99, 0x88,
  58943. 0x77, 0x66, 0x55, 0x44,
  58944. 0x00, 0x33, 0x22, 0x11};
  58945. ExpectIntEQ(wolfSSL_X509_add_altname_ex(x509, (char*)ip4_type,
  58946. sizeof(ip4_type), ASN_IP_TYPE), SSL_SUCCESS);
  58947. ExpectIntEQ(wolfSSL_X509_add_altname_ex(x509, (char*)ip6_type,
  58948. sizeof(ip6_type), ASN_IP_TYPE), SSL_SUCCESS);
  58949. }
  58950. #endif
  58951. #endif /* WOLFSSL_ALT_NAMES */
  58952. {
  58953. ASN1_UTCTIME* infinite_past = NULL;
  58954. ExpectNotNull(infinite_past = ASN1_UTCTIME_set(NULL, 0));
  58955. ExpectIntEQ(X509_set1_notBefore(x509, infinite_past), 1);
  58956. ASN1_UTCTIME_free(infinite_past);
  58957. }
  58958. /* test valid sign case */
  58959. ExpectIntGT(ret = X509_sign(x509, priv, EVP_sha256()), 0);
  58960. /* test valid X509_sign_ctx case */
  58961. ExpectNotNull(mctx = EVP_MD_CTX_new());
  58962. ExpectIntEQ(EVP_DigestSignInit(mctx, NULL, EVP_sha256(), NULL, priv), 1);
  58963. ExpectIntGT(X509_sign_ctx(x509, mctx), 0);
  58964. #if defined(OPENSSL_ALL) && defined(WOLFSSL_ALT_NAMES)
  58965. ExpectIntEQ(X509_get_ext_count(x509), 1);
  58966. #endif
  58967. #if defined(WOLFSSL_ALT_NAMES) && defined(WOLFSSL_IP_ALT_NAME)
  58968. ExpectIntEQ(wolfSSL_X509_check_ip_asc(x509, "127.128.0.255", 0), 1);
  58969. ExpectIntEQ(wolfSSL_X509_check_ip_asc(x509, "DDCC:BAAB:FFEE:9988:7766:5544:0033:2211", 0), 1);
  58970. #endif
  58971. ExpectIntEQ(wolfSSL_X509_get_serial_number(x509, sn, &snSz),
  58972. WOLFSSL_SUCCESS);
  58973. DEBUG_WRITE_CERT_X509(x509, "signed.pem");
  58974. /* Variation in size depends on ASN.1 encoding when MSB is set.
  58975. * WOLFSSL_ASN_TEMPLATE code does not generate a serial number
  58976. * with the MSB set. See GenerateInteger in asn.c */
  58977. #ifndef USE_CERT_BUFFERS_1024
  58978. #ifndef WOLFSSL_ALT_NAMES
  58979. /* Valid case - size should be 781-786 with 16 byte serial number */
  58980. ExpectTrue((781 + snSz <= ret) && (ret <= 781 + 5 + snSz));
  58981. #elif defined(WOLFSSL_IP_ALT_NAME)
  58982. /* Valid case - size should be 955-960 with 16 byte serial number */
  58983. ExpectTrue((939 + snSz <= ret) && (ret <= 939 + 5 + snSz));
  58984. #else
  58985. /* Valid case - size should be 926-931 with 16 byte serial number */
  58986. ExpectTrue((910 + snSz <= ret) && (ret <= 910 + 5 + snSz));
  58987. #endif
  58988. #else
  58989. #ifndef WOLFSSL_ALT_NAMES
  58990. /* Valid case - size should be 537-542 with 16 byte serial number */
  58991. ExpectTrue((521 + snSz <= ret) && (ret <= 521 + 5 + snSz));
  58992. #elif defined(OPENSSL_ALL) || defined(WOLFSSL_IP_ALT_NAME)
  58993. /* Valid case - size should be 695-670 with 16 byte serial number */
  58994. ExpectTrue((679 + snSz <= ret) && (ret <= 679 + 5 + snSz));
  58995. #else
  58996. /* Valid case - size should be 666-671 with 16 byte serial number */
  58997. ExpectTrue((650 + snSz <= ret) && (ret <= 650 + 5 + snSz));
  58998. #endif
  58999. #endif
  59000. /* check that issuer name is as expected after signature */
  59001. InitDecodedCert(&dCert, certIssuer, (word32)certIssuerSz, 0);
  59002. ExpectIntEQ(ParseCert(&dCert, CERT_TYPE, NO_VERIFY, NULL), 0);
  59003. ExpectNotNull(ca = d2i_X509(NULL, &certIssuer, (int)certIssuerSz));
  59004. ExpectNotNull(name = X509_get_subject_name(ca));
  59005. cnSz = X509_NAME_get_sz(name);
  59006. ExpectNotNull(cn = (char*)XMALLOC(cnSz, HEAP_HINT, DYNAMIC_TYPE_OPENSSL));
  59007. ExpectNotNull(cn = X509_NAME_oneline(name, cn, (int)cnSz));
  59008. ExpectIntEQ(0, XSTRNCMP(cn, dCert.subject, XSTRLEN(cn)));
  59009. XFREE(cn, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  59010. cn = NULL;
  59011. #ifdef WOLFSSL_MULTI_ATTRIB
  59012. /* test adding multiple OU's to the signer */
  59013. ExpectNotNull(name = X509_get_subject_name(ca));
  59014. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "OU", MBSTRING_UTF8,
  59015. (byte*)"OU1", 3, -1, 0), SSL_SUCCESS);
  59016. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "OU", MBSTRING_UTF8,
  59017. (byte*)"OU2", 3, -1, 0), SSL_SUCCESS);
  59018. ExpectIntGT(X509_sign(ca, priv, EVP_sha256()), 0);
  59019. #endif
  59020. ExpectNotNull(name = X509_get_subject_name(ca));
  59021. ExpectIntEQ(X509_set_issuer_name(x509, name), SSL_SUCCESS);
  59022. ExpectIntGT(X509_sign(x509, priv, EVP_sha256()), 0);
  59023. ExpectNotNull(name = X509_get_issuer_name(x509));
  59024. cnSz = X509_NAME_get_sz(name);
  59025. ExpectNotNull(cn = (char*)XMALLOC(cnSz, HEAP_HINT, DYNAMIC_TYPE_OPENSSL));
  59026. ExpectNotNull(cn = X509_NAME_oneline(name, cn, (int)cnSz));
  59027. /* compare and don't include the multi-attrib "/OU=OU1/OU=OU2" above */
  59028. ExpectIntEQ(0, XSTRNCMP(cn, dCert.issuer, XSTRLEN(dCert.issuer)));
  59029. XFREE(cn, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  59030. cn = NULL;
  59031. FreeDecodedCert(&dCert);
  59032. /* Test invalid parameters */
  59033. ExpectIntEQ(X509_sign(NULL, priv, EVP_sha256()), 0);
  59034. ExpectIntEQ(X509_sign(x509, NULL, EVP_sha256()), 0);
  59035. ExpectIntEQ(X509_sign(x509, priv, NULL), 0);
  59036. ExpectIntEQ(X509_sign_ctx(NULL, mctx), 0);
  59037. EVP_MD_CTX_free(mctx);
  59038. mctx = NULL;
  59039. ExpectNotNull(mctx = EVP_MD_CTX_new());
  59040. ExpectIntEQ(X509_sign_ctx(x509, mctx), 0);
  59041. ExpectIntEQ(X509_sign_ctx(x509, NULL), 0);
  59042. /* test invalid version number */
  59043. #if defined(OPENSSL_ALL)
  59044. ExpectIntNE(X509_set_version(x509, 6L), 0);
  59045. ExpectIntGT(X509_sign(x509, priv, EVP_sha256()), 0);
  59046. /* uses ParseCert which fails on bad version number */
  59047. ExpectIntEQ(X509_get_ext_count(x509), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  59048. #endif
  59049. EVP_MD_CTX_free(mctx);
  59050. EVP_PKEY_free(priv);
  59051. EVP_PKEY_free(pub);
  59052. X509_free(x509);
  59053. X509_free(ca);
  59054. #endif
  59055. return EXPECT_RESULT();
  59056. }
  59057. static int test_wolfSSL_X509_get0_tbs_sigalg(void)
  59058. {
  59059. EXPECT_DECLS;
  59060. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD))
  59061. X509* x509 = NULL;
  59062. const X509_ALGOR* alg;
  59063. ExpectNotNull(x509 = X509_new());
  59064. ExpectNull(alg = X509_get0_tbs_sigalg(NULL));
  59065. ExpectNotNull(alg = X509_get0_tbs_sigalg(x509));
  59066. X509_free(x509);
  59067. #endif
  59068. return EXPECT_RESULT();
  59069. }
  59070. static int test_wolfSSL_X509_ALGOR_get0(void)
  59071. {
  59072. EXPECT_DECLS;
  59073. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && \
  59074. !defined(NO_SHA256) && !defined(NO_RSA)
  59075. X509* x509 = NULL;
  59076. const ASN1_OBJECT* obj = NULL;
  59077. const X509_ALGOR* alg = NULL;
  59078. X509_ALGOR* alg2 = NULL;
  59079. int pptype = 0;
  59080. const void *ppval = NULL;
  59081. byte* der = NULL;
  59082. const byte* tmp = NULL;
  59083. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  59084. SSL_FILETYPE_PEM));
  59085. ExpectNotNull(alg = X509_get0_tbs_sigalg(x509));
  59086. /* Invalid case */
  59087. X509_ALGOR_get0(&obj, NULL, NULL, NULL);
  59088. ExpectNull(obj);
  59089. /* Valid case */
  59090. X509_ALGOR_get0(&obj, &pptype, &ppval, alg);
  59091. ExpectNotNull(obj);
  59092. ExpectNull(ppval);
  59093. ExpectIntNE(pptype, 0);
  59094. /* Make sure NID of X509_ALGOR is Sha256 with RSA */
  59095. ExpectIntEQ(OBJ_obj2nid(obj), NID_sha256WithRSAEncryption);
  59096. ExpectIntEQ(i2d_X509_ALGOR(alg, &der), 15);
  59097. tmp = der;
  59098. ExpectNotNull(d2i_X509_ALGOR(&alg2, &tmp, 15));
  59099. XFREE(der, NULL, DYNAMIC_TYPE_ASN1);
  59100. X509_free(x509);
  59101. X509_ALGOR_free(alg2);
  59102. #endif
  59103. return EXPECT_RESULT();
  59104. }
  59105. static int test_wolfSSL_X509_VERIFY_PARAM(void)
  59106. {
  59107. EXPECT_DECLS;
  59108. #if defined(OPENSSL_EXTRA)
  59109. X509_VERIFY_PARAM *paramTo = NULL;
  59110. X509_VERIFY_PARAM *paramFrom = NULL;
  59111. char testIPv4[] = "127.0.0.1";
  59112. char testIPv6[] = "0001:0000:0000:0000:0000:0000:0000:0000/32";
  59113. char testhostName1[] = "foo.hoge.com";
  59114. char testhostName2[] = "foobar.hoge.com";
  59115. ExpectNotNull(paramTo = X509_VERIFY_PARAM_new());
  59116. ExpectNotNull(XMEMSET(paramTo, 0, sizeof(X509_VERIFY_PARAM)));
  59117. ExpectNotNull(paramFrom = X509_VERIFY_PARAM_new());
  59118. ExpectNotNull(XMEMSET(paramFrom, 0, sizeof(X509_VERIFY_PARAM)));
  59119. ExpectIntEQ(X509_VERIFY_PARAM_set1_host(paramFrom, testhostName1,
  59120. (int)XSTRLEN(testhostName1)), 1);
  59121. ExpectIntEQ(0, XSTRNCMP(paramFrom->hostName, testhostName1,
  59122. (int)XSTRLEN(testhostName1)));
  59123. X509_VERIFY_PARAM_set_hostflags(NULL, 0x00);
  59124. X509_VERIFY_PARAM_set_hostflags(paramFrom, 0x01);
  59125. ExpectIntEQ(0x01, paramFrom->hostFlags);
  59126. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(NULL, testIPv4), 0);
  59127. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramFrom, testIPv4), 1);
  59128. ExpectIntEQ(0, XSTRNCMP(paramFrom->ipasc, testIPv4, WOLFSSL_MAX_IPSTR));
  59129. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramFrom, NULL), 1);
  59130. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramFrom, testIPv6), 1);
  59131. ExpectIntEQ(0, XSTRNCMP(paramFrom->ipasc, testIPv6, WOLFSSL_MAX_IPSTR));
  59132. /* null pointer */
  59133. ExpectIntEQ(X509_VERIFY_PARAM_set1(NULL, paramFrom), 0);
  59134. /* in the case of "from" null, returns success */
  59135. ExpectIntEQ(X509_VERIFY_PARAM_set1(paramTo, NULL), 1);
  59136. ExpectIntEQ(X509_VERIFY_PARAM_set1(NULL, NULL), 0);
  59137. /* inherit flags test : VPARAM_DEFAULT */
  59138. ExpectIntEQ(X509_VERIFY_PARAM_set1(paramTo, paramFrom), 1);
  59139. ExpectIntEQ(0, XSTRNCMP(paramTo->hostName, testhostName1,
  59140. (int)XSTRLEN(testhostName1)));
  59141. ExpectIntEQ(0x01, paramTo->hostFlags);
  59142. ExpectIntEQ(0, XSTRNCMP(paramTo->ipasc, testIPv6, WOLFSSL_MAX_IPSTR));
  59143. /* inherit flags test : VPARAM OVERWRITE */
  59144. ExpectIntEQ(X509_VERIFY_PARAM_set1_host(paramTo, testhostName2,
  59145. (int)XSTRLEN(testhostName2)), 1);
  59146. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramTo, testIPv4), 1);
  59147. X509_VERIFY_PARAM_set_hostflags(paramTo, 0x00);
  59148. if (paramTo != NULL) {
  59149. paramTo->inherit_flags = X509_VP_FLAG_OVERWRITE;
  59150. }
  59151. ExpectIntEQ(X509_VERIFY_PARAM_set1(paramTo, paramFrom), 1);
  59152. ExpectIntEQ(0, XSTRNCMP(paramTo->hostName, testhostName1,
  59153. (int)XSTRLEN(testhostName1)));
  59154. ExpectIntEQ(0x01, paramTo->hostFlags);
  59155. ExpectIntEQ(0, XSTRNCMP(paramTo->ipasc, testIPv6, WOLFSSL_MAX_IPSTR));
  59156. /* inherit flags test : VPARAM_RESET_FLAGS */
  59157. ExpectIntEQ(X509_VERIFY_PARAM_set1_host(paramTo, testhostName2,
  59158. (int)XSTRLEN(testhostName2)), 1);
  59159. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramTo, testIPv4), 1);
  59160. X509_VERIFY_PARAM_set_hostflags(paramTo, 0x10);
  59161. if (paramTo != NULL) {
  59162. paramTo->inherit_flags = X509_VP_FLAG_RESET_FLAGS;
  59163. }
  59164. ExpectIntEQ(X509_VERIFY_PARAM_set1(paramTo, paramFrom), 1);
  59165. ExpectIntEQ(0, XSTRNCMP(paramTo->hostName, testhostName1,
  59166. (int)XSTRLEN(testhostName1)));
  59167. ExpectIntEQ(0x01, paramTo->hostFlags);
  59168. ExpectIntEQ(0, XSTRNCMP(paramTo->ipasc, testIPv6, WOLFSSL_MAX_IPSTR));
  59169. /* inherit flags test : VPARAM_LOCKED */
  59170. ExpectIntEQ(X509_VERIFY_PARAM_set1_host(paramTo, testhostName2,
  59171. (int)XSTRLEN(testhostName2)), 1);
  59172. ExpectIntEQ(X509_VERIFY_PARAM_set1_ip_asc(paramTo, testIPv4), 1);
  59173. X509_VERIFY_PARAM_set_hostflags(paramTo, 0x00);
  59174. if (paramTo != NULL) {
  59175. paramTo->inherit_flags = X509_VP_FLAG_LOCKED;
  59176. }
  59177. ExpectIntEQ(X509_VERIFY_PARAM_set1(paramTo, paramFrom), 1);
  59178. ExpectIntEQ(0, XSTRNCMP(paramTo->hostName, testhostName2,
  59179. (int)XSTRLEN(testhostName2)));
  59180. ExpectIntEQ(0x00, paramTo->hostFlags);
  59181. ExpectIntEQ(0, XSTRNCMP(paramTo->ipasc, testIPv4, WOLFSSL_MAX_IPSTR));
  59182. /* test for incorrect parameters */
  59183. ExpectIntEQ(X509_VERIFY_PARAM_set_flags(NULL, X509_V_FLAG_CRL_CHECK_ALL),
  59184. 0);
  59185. ExpectIntEQ(X509_VERIFY_PARAM_set_flags(NULL, 0), 0);
  59186. /* inherit flags test : VPARAM_ONCE, not testable yet */
  59187. ExpectIntEQ(X509_VERIFY_PARAM_set_flags(paramTo, X509_V_FLAG_CRL_CHECK_ALL),
  59188. 1);
  59189. ExpectIntEQ(X509_VERIFY_PARAM_get_flags(paramTo),
  59190. X509_V_FLAG_CRL_CHECK_ALL);
  59191. ExpectIntEQ(X509_VERIFY_PARAM_clear_flags(paramTo,
  59192. X509_V_FLAG_CRL_CHECK_ALL), 1);
  59193. ExpectIntEQ(X509_VERIFY_PARAM_get_flags(paramTo), 0);
  59194. X509_VERIFY_PARAM_free(paramTo);
  59195. X509_VERIFY_PARAM_free(paramFrom);
  59196. X509_VERIFY_PARAM_free(NULL); /* to confirm NULL parameter gives no harm */
  59197. #endif
  59198. return EXPECT_RESULT();
  59199. }
  59200. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  59201. !defined(WOLFSSL_HOSTNAME_VERIFY_ALT_NAME_ONLY)
  59202. static int test_wolfSSL_check_domain_verify_count = 0;
  59203. static WC_INLINE int test_wolfSSL_check_domain_verify_cb(int preverify,
  59204. WOLFSSL_X509_STORE_CTX* store)
  59205. {
  59206. EXPECT_DECLS;
  59207. ExpectIntEQ(X509_STORE_CTX_get_error(store), 0);
  59208. ExpectIntEQ(preverify, 1);
  59209. ExpectIntGT(++test_wolfSSL_check_domain_verify_count, 0);
  59210. return EXPECT_SUCCESS();
  59211. }
  59212. static int test_wolfSSL_check_domain_client_cb(WOLFSSL* ssl)
  59213. {
  59214. EXPECT_DECLS;
  59215. X509_VERIFY_PARAM *param = NULL;
  59216. ExpectNotNull(param = SSL_get0_param(ssl));
  59217. /* Domain check should only be done on the leaf cert */
  59218. X509_VERIFY_PARAM_set_hostflags(param,
  59219. X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS);
  59220. ExpectIntEQ(X509_VERIFY_PARAM_set1_host(param,
  59221. "wolfSSL Server Chain", 0), 1);
  59222. wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_PEER,
  59223. test_wolfSSL_check_domain_verify_cb);
  59224. return EXPECT_RESULT();
  59225. }
  59226. static int test_wolfSSL_check_domain_server_cb(WOLFSSL_CTX* ctx)
  59227. {
  59228. EXPECT_DECLS;
  59229. /* Use a cert with different domains in chain */
  59230. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file(ctx,
  59231. "certs/intermediate/server-chain.pem"), WOLFSSL_SUCCESS);
  59232. return EXPECT_RESULT();
  59233. }
  59234. static int test_wolfSSL_check_domain(void)
  59235. {
  59236. EXPECT_DECLS;
  59237. test_ssl_cbf func_cb_client;
  59238. test_ssl_cbf func_cb_server;
  59239. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  59240. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  59241. func_cb_client.ssl_ready = &test_wolfSSL_check_domain_client_cb;
  59242. func_cb_server.ctx_ready = &test_wolfSSL_check_domain_server_cb;
  59243. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  59244. &func_cb_server, NULL), TEST_SUCCESS);
  59245. /* Should have been called once for each cert in sent chain */
  59246. #ifdef WOLFSSL_VERIFY_CB_ALL_CERTS
  59247. ExpectIntEQ(test_wolfSSL_check_domain_verify_count, 3);
  59248. #else
  59249. ExpectIntEQ(test_wolfSSL_check_domain_verify_count, 1);
  59250. #endif
  59251. return EXPECT_RESULT();
  59252. }
  59253. #else
  59254. static int test_wolfSSL_check_domain(void)
  59255. {
  59256. EXPECT_DECLS;
  59257. return EXPECT_RESULT();
  59258. }
  59259. #endif /* OPENSSL_EXTRA && HAVE_SSL_MEMIO_TESTS_DEPENDENCIES */
  59260. static int test_wolfSSL_X509_get_X509_PUBKEY(void)
  59261. {
  59262. EXPECT_DECLS;
  59263. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD))
  59264. X509* x509 = NULL;
  59265. X509_PUBKEY* pubKey;
  59266. ExpectNotNull(x509 = X509_new());
  59267. ExpectNull(pubKey = wolfSSL_X509_get_X509_PUBKEY(NULL));
  59268. ExpectNotNull(pubKey = wolfSSL_X509_get_X509_PUBKEY(x509));
  59269. X509_free(x509);
  59270. #endif
  59271. return EXPECT_RESULT();
  59272. }
  59273. static int test_wolfSSL_X509_PUBKEY_RSA(void)
  59274. {
  59275. EXPECT_DECLS;
  59276. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && \
  59277. !defined(NO_SHA256) && !defined(NO_RSA)
  59278. X509* x509 = NULL;
  59279. ASN1_OBJECT* obj = NULL;
  59280. const ASN1_OBJECT* pa_oid = NULL;
  59281. X509_PUBKEY* pubKey = NULL;
  59282. X509_PUBKEY* pubKey2 = NULL;
  59283. EVP_PKEY* evpKey = NULL;
  59284. const unsigned char *pk = NULL;
  59285. int ppklen;
  59286. int pptype;
  59287. X509_ALGOR *pa = NULL;
  59288. const void *pval;
  59289. ExpectNotNull(x509 = X509_load_certificate_file(cliCertFile,
  59290. SSL_FILETYPE_PEM));
  59291. ExpectNotNull(pubKey = X509_get_X509_PUBKEY(x509));
  59292. ExpectIntEQ(X509_PUBKEY_get0_param(&obj, &pk, &ppklen, &pa, pubKey), 1);
  59293. ExpectNotNull(pk);
  59294. ExpectNotNull(pa);
  59295. ExpectNotNull(pubKey);
  59296. ExpectIntGT(ppklen, 0);
  59297. ExpectIntEQ(OBJ_obj2nid(obj), NID_rsaEncryption);
  59298. ExpectNotNull(evpKey = X509_PUBKEY_get(pubKey));
  59299. ExpectNotNull(pubKey2 = X509_PUBKEY_new());
  59300. ExpectIntEQ(X509_PUBKEY_set(&pubKey2, evpKey), 1);
  59301. ExpectIntEQ(X509_PUBKEY_get0_param(&obj, &pk, &ppklen, &pa, pubKey2), 1);
  59302. ExpectNotNull(pk);
  59303. ExpectNotNull(pa);
  59304. ExpectIntGT(ppklen, 0);
  59305. X509_ALGOR_get0(&pa_oid, &pptype, &pval, pa);
  59306. ExpectNotNull(pa_oid);
  59307. ExpectNull(pval);
  59308. ExpectIntEQ(pptype, V_ASN1_NULL);
  59309. ExpectIntEQ(OBJ_obj2nid(pa_oid), EVP_PKEY_RSA);
  59310. X509_PUBKEY_free(pubKey2);
  59311. X509_free(x509);
  59312. EVP_PKEY_free(evpKey);
  59313. #endif
  59314. return EXPECT_RESULT();
  59315. }
  59316. static int test_wolfSSL_X509_PUBKEY_EC(void)
  59317. {
  59318. EXPECT_DECLS;
  59319. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && defined(HAVE_ECC)
  59320. X509* x509 = NULL;
  59321. ASN1_OBJECT* obj = NULL;
  59322. ASN1_OBJECT* poid = NULL;
  59323. const ASN1_OBJECT* pa_oid = NULL;
  59324. X509_PUBKEY* pubKey = NULL;
  59325. X509_PUBKEY* pubKey2 = NULL;
  59326. EVP_PKEY* evpKey = NULL;
  59327. const unsigned char *pk = NULL;
  59328. int ppklen;
  59329. int pptype;
  59330. X509_ALGOR *pa = NULL;
  59331. const void *pval;
  59332. char buf[50];
  59333. ExpectNotNull(x509 = X509_load_certificate_file(cliEccCertFile,
  59334. SSL_FILETYPE_PEM));
  59335. ExpectNotNull(pubKey = X509_get_X509_PUBKEY(x509));
  59336. ExpectNotNull(evpKey = X509_PUBKEY_get(pubKey));
  59337. ExpectNotNull(pubKey2 = X509_PUBKEY_new());
  59338. ExpectIntEQ(X509_PUBKEY_set(&pubKey2, evpKey), 1);
  59339. ExpectIntEQ(X509_PUBKEY_get0_param(&obj, &pk, &ppklen, &pa, pubKey2), 1);
  59340. ExpectNotNull(pk);
  59341. ExpectNotNull(pa);
  59342. ExpectIntGT(ppklen, 0);
  59343. X509_ALGOR_get0(&pa_oid, &pptype, &pval, pa);
  59344. ExpectNotNull(pa_oid);
  59345. ExpectNotNull(pval);
  59346. ExpectIntEQ(pptype, V_ASN1_OBJECT);
  59347. ExpectIntEQ(OBJ_obj2nid(pa_oid), EVP_PKEY_EC);
  59348. poid = (ASN1_OBJECT *)pval;
  59349. ExpectIntGT(OBJ_obj2txt(buf, (int)sizeof(buf), poid, 0), 0);
  59350. ExpectIntEQ(OBJ_txt2nid(buf), NID_X9_62_prime256v1);
  59351. X509_PUBKEY_free(pubKey2);
  59352. X509_free(x509);
  59353. EVP_PKEY_free(evpKey);
  59354. #endif
  59355. return EXPECT_RESULT();
  59356. }
  59357. static int test_wolfSSL_X509_PUBKEY_DSA(void)
  59358. {
  59359. EXPECT_DECLS;
  59360. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && !defined(NO_DSA)
  59361. word32 bytes;
  59362. #ifdef USE_CERT_BUFFERS_1024
  59363. byte tmp[ONEK_BUF];
  59364. #elif defined(USE_CERT_BUFFERS_2048)
  59365. byte tmp[TWOK_BUF];
  59366. #else
  59367. byte tmp[TWOK_BUF];
  59368. #endif /* END USE_CERT_BUFFERS_1024 */
  59369. const unsigned char* dsaKeyDer = tmp;
  59370. ASN1_OBJECT* obj = NULL;
  59371. ASN1_STRING* str;
  59372. const ASN1_OBJECT* pa_oid = NULL;
  59373. X509_PUBKEY* pubKey = NULL;
  59374. EVP_PKEY* evpKey = NULL;
  59375. const unsigned char *pk = NULL;
  59376. int ppklen, pptype;
  59377. X509_ALGOR *pa = NULL;
  59378. const void *pval;
  59379. #ifdef USE_CERT_BUFFERS_1024
  59380. XMEMSET(tmp, 0, sizeof(tmp));
  59381. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  59382. bytes = sizeof_dsa_key_der_1024;
  59383. #elif defined(USE_CERT_BUFFERS_2048)
  59384. XMEMSET(tmp, 0, sizeof(tmp));
  59385. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  59386. bytes = sizeof_dsa_key_der_2048;
  59387. #else
  59388. {
  59389. XFILE fp = XBADFILE;
  59390. XMEMSET(tmp, 0, sizeof(tmp));
  59391. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb")) != XBADFILE);
  59392. ExpectIntGT(bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), fp), 0);
  59393. if (fp != XBADFILE)
  59394. XFCLOSE(fp);
  59395. }
  59396. #endif
  59397. /* Initialize pkey with der format dsa key */
  59398. ExpectNotNull(d2i_PrivateKey(EVP_PKEY_DSA, &evpKey, &dsaKeyDer, bytes));
  59399. ExpectNotNull(pubKey = X509_PUBKEY_new());
  59400. ExpectIntEQ(X509_PUBKEY_set(&pubKey, evpKey), 1);
  59401. ExpectIntEQ(X509_PUBKEY_get0_param(&obj, &pk, &ppklen, &pa, pubKey), 1);
  59402. ExpectNotNull(pk);
  59403. ExpectNotNull(pa);
  59404. ExpectIntGT(ppklen, 0);
  59405. X509_ALGOR_get0(&pa_oid, &pptype, &pval, pa);
  59406. ExpectNotNull(pa_oid);
  59407. ExpectNotNull(pval);
  59408. ExpectIntEQ(pptype, V_ASN1_SEQUENCE);
  59409. ExpectIntEQ(OBJ_obj2nid(pa_oid), EVP_PKEY_DSA);
  59410. str = (ASN1_STRING *)pval;
  59411. DEBUG_WRITE_DER(ASN1_STRING_data(str), ASN1_STRING_length(str), "str.der");
  59412. #ifdef USE_CERT_BUFFERS_1024
  59413. ExpectIntEQ(ASN1_STRING_length(str), 291);
  59414. #else
  59415. ExpectIntEQ(ASN1_STRING_length(str), 549);
  59416. #endif /* END USE_CERT_BUFFERS_1024 */
  59417. X509_PUBKEY_free(pubKey);
  59418. EVP_PKEY_free(evpKey);
  59419. #endif
  59420. return EXPECT_RESULT();
  59421. }
  59422. static int test_wolfSSL_BUF(void)
  59423. {
  59424. EXPECT_DECLS;
  59425. #if defined(OPENSSL_EXTRA)
  59426. BUF_MEM* buf = NULL;
  59427. ExpectNotNull(buf = BUF_MEM_new());
  59428. ExpectIntEQ(BUF_MEM_grow(buf, 10), 10);
  59429. ExpectIntEQ(BUF_MEM_grow(buf, -1), 0);
  59430. BUF_MEM_free(buf);
  59431. #endif
  59432. return EXPECT_RESULT();
  59433. }
  59434. #if defined(OPENSSL_EXTRA) && !defined(WOLFSSL_NO_OPENSSL_RAND_CB)
  59435. static int stub_rand_seed(const void *buf, int num)
  59436. {
  59437. (void)buf;
  59438. (void)num;
  59439. return 123;
  59440. }
  59441. static int stub_rand_bytes(unsigned char *buf, int num)
  59442. {
  59443. (void)buf;
  59444. (void)num;
  59445. return 456;
  59446. }
  59447. static byte* was_stub_rand_cleanup_called(void)
  59448. {
  59449. static byte was_called = 0;
  59450. return &was_called;
  59451. }
  59452. static void stub_rand_cleanup(void)
  59453. {
  59454. byte* was_called = was_stub_rand_cleanup_called();
  59455. *was_called = 1;
  59456. return;
  59457. }
  59458. static byte* was_stub_rand_add_called(void)
  59459. {
  59460. static byte was_called = 0;
  59461. return &was_called;
  59462. }
  59463. static int stub_rand_add(const void *buf, int num, double entropy)
  59464. {
  59465. byte* was_called = was_stub_rand_add_called();
  59466. (void)buf;
  59467. (void)num;
  59468. (void)entropy;
  59469. *was_called = 1;
  59470. return 0;
  59471. }
  59472. static int stub_rand_pseudo_bytes(unsigned char *buf, int num)
  59473. {
  59474. (void)buf;
  59475. (void)num;
  59476. return 9876;
  59477. }
  59478. static int stub_rand_status(void)
  59479. {
  59480. return 5432;
  59481. }
  59482. #endif /* OPENSSL_EXTRA && !WOLFSSL_NO_OPENSSL_RAND_CB */
  59483. static int test_wolfSSL_RAND_set_rand_method(void)
  59484. {
  59485. EXPECT_DECLS;
  59486. #if defined(OPENSSL_EXTRA) && !defined(WOLFSSL_NO_OPENSSL_RAND_CB)
  59487. RAND_METHOD rand_methods = {NULL, NULL, NULL, NULL, NULL, NULL};
  59488. unsigned char* buf = NULL;
  59489. int num = 0;
  59490. double entropy = 0;
  59491. int ret;
  59492. byte* was_cleanup_called = was_stub_rand_cleanup_called();
  59493. byte* was_add_called = was_stub_rand_add_called();
  59494. ExpectNotNull(buf = (byte*)XMALLOC(32 * sizeof(byte), NULL,
  59495. DYNAMIC_TYPE_TMP_BUFFER));
  59496. ExpectIntNE(wolfSSL_RAND_status(), 5432);
  59497. ExpectIntEQ(*was_cleanup_called, 0);
  59498. RAND_cleanup();
  59499. ExpectIntEQ(*was_cleanup_called, 0);
  59500. rand_methods.seed = &stub_rand_seed;
  59501. rand_methods.bytes = &stub_rand_bytes;
  59502. rand_methods.cleanup = &stub_rand_cleanup;
  59503. rand_methods.add = &stub_rand_add;
  59504. rand_methods.pseudorand = &stub_rand_pseudo_bytes;
  59505. rand_methods.status = &stub_rand_status;
  59506. ExpectIntEQ(RAND_set_rand_method(&rand_methods), WOLFSSL_SUCCESS);
  59507. ExpectIntEQ(RAND_seed(buf, num), 123);
  59508. ExpectIntEQ(RAND_bytes(buf, num), 456);
  59509. ExpectIntEQ(RAND_pseudo_bytes(buf, num), 9876);
  59510. ExpectIntEQ(RAND_status(), 5432);
  59511. ExpectIntEQ(*was_add_called, 0);
  59512. /* The function pointer for RAND_add returns int, but RAND_add itself
  59513. * returns void. */
  59514. RAND_add(buf, num, entropy);
  59515. ExpectIntEQ(*was_add_called, 1);
  59516. was_add_called = 0;
  59517. ExpectIntEQ(*was_cleanup_called, 0);
  59518. RAND_cleanup();
  59519. ExpectIntEQ(*was_cleanup_called, 1);
  59520. *was_cleanup_called = 0;
  59521. ret = RAND_set_rand_method(NULL);
  59522. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  59523. ExpectIntNE(RAND_status(), 5432);
  59524. ExpectIntEQ(*was_cleanup_called, 0);
  59525. RAND_cleanup();
  59526. ExpectIntEQ(*was_cleanup_called, 0);
  59527. RAND_set_rand_method(NULL);
  59528. XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  59529. #endif /* OPENSSL_EXTRA && !WOLFSSL_NO_OPENSSL_RAND_CB */
  59530. return EXPECT_RESULT();
  59531. }
  59532. static int test_wolfSSL_RAND_bytes(void)
  59533. {
  59534. EXPECT_DECLS;
  59535. #if defined(OPENSSL_EXTRA)
  59536. const int size1 = RNG_MAX_BLOCK_LEN; /* in bytes */
  59537. const int size2 = RNG_MAX_BLOCK_LEN + 1; /* in bytes */
  59538. const int size3 = RNG_MAX_BLOCK_LEN * 2; /* in bytes */
  59539. const int size4 = RNG_MAX_BLOCK_LEN * 4; /* in bytes */
  59540. int max_bufsize;
  59541. byte *my_buf = NULL;
  59542. /* sanity check */
  59543. ExpectIntEQ(RAND_bytes(NULL, 16), 0);
  59544. ExpectIntEQ(RAND_bytes(NULL, 0), 0);
  59545. max_bufsize = size4;
  59546. ExpectNotNull(my_buf = (byte*)XMALLOC(max_bufsize * sizeof(byte), NULL,
  59547. DYNAMIC_TYPE_TMP_BUFFER));
  59548. ExpectIntEQ(RAND_bytes(my_buf, 0), 1);
  59549. ExpectIntEQ(RAND_bytes(my_buf, -1), 0);
  59550. ExpectNotNull(XMEMSET(my_buf, 0, max_bufsize));
  59551. ExpectIntEQ(RAND_bytes(my_buf, size1), 1);
  59552. ExpectIntEQ(RAND_bytes(my_buf, size2), 1);
  59553. ExpectIntEQ(RAND_bytes(my_buf, size3), 1);
  59554. ExpectIntEQ(RAND_bytes(my_buf, size4), 1);
  59555. XFREE(my_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  59556. #endif
  59557. return EXPECT_RESULT();
  59558. }
  59559. static int test_wolfSSL_RAND(void)
  59560. {
  59561. EXPECT_DECLS;
  59562. #if defined(OPENSSL_EXTRA)
  59563. byte seed[16];
  59564. XMEMSET(seed, 0, sizeof(seed));
  59565. /* No global methods set. */
  59566. ExpectIntEQ(RAND_seed(seed, sizeof(seed)), 1);
  59567. ExpectIntEQ(RAND_poll(), 1);
  59568. RAND_cleanup();
  59569. ExpectIntEQ(RAND_egd(NULL), -1);
  59570. #ifndef NO_FILESYSTEM
  59571. {
  59572. char fname[100];
  59573. ExpectNotNull(RAND_file_name(fname, (sizeof(fname) - 1)));
  59574. ExpectIntEQ(RAND_write_file(NULL), 0);
  59575. }
  59576. #endif
  59577. #endif
  59578. return EXPECT_RESULT();
  59579. }
  59580. static int test_wolfSSL_PKCS8_Compat(void)
  59581. {
  59582. EXPECT_DECLS;
  59583. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && defined(HAVE_ECC) && \
  59584. !defined(NO_BIO)
  59585. PKCS8_PRIV_KEY_INFO* pt = NULL;
  59586. BIO* bio = NULL;
  59587. XFILE f = XBADFILE;
  59588. int bytes = 0;
  59589. char pkcs8_buffer[512];
  59590. #if defined(OPENSSL_ALL) || defined(WOLFSSL_WPAS_SMALL)
  59591. EVP_PKEY *pkey = NULL;
  59592. #endif
  59593. /* file from wolfssl/certs/ directory */
  59594. ExpectTrue((f = XFOPEN("./certs/ecc-keyPkcs8.pem", "rb")) != XBADFILE);
  59595. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer), f)),
  59596. 0);
  59597. if (f != XBADFILE)
  59598. XFCLOSE(f);
  59599. ExpectNotNull(bio = BIO_new_mem_buf((void*)pkcs8_buffer, bytes));
  59600. ExpectNotNull(pt = d2i_PKCS8_PRIV_KEY_INFO_bio(bio, NULL));
  59601. #if defined(OPENSSL_ALL) || defined(WOLFSSL_WPAS_SMALL)
  59602. ExpectNotNull(pkey = EVP_PKCS82PKEY(pt));
  59603. ExpectIntEQ(EVP_PKEY_type(pkey->type), EVP_PKEY_EC);
  59604. /* gets PKCS8 pointer to pkey */
  59605. ExpectNotNull(EVP_PKEY2PKCS8(pkey));
  59606. EVP_PKEY_free(pkey);
  59607. #endif
  59608. BIO_free(bio);
  59609. PKCS8_PRIV_KEY_INFO_free(pt);
  59610. #endif
  59611. return EXPECT_RESULT();
  59612. }
  59613. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  59614. static int NoPasswordCallBack(char* passwd, int sz, int rw, void* userdata)
  59615. {
  59616. (void)passwd;
  59617. (void)sz;
  59618. (void)rw;
  59619. (void)userdata;
  59620. return -1;
  59621. }
  59622. #endif
  59623. static int test_wolfSSL_PKCS8_d2i(void)
  59624. {
  59625. EXPECT_DECLS;
  59626. #if !defined(HAVE_FIPS) && defined(OPENSSL_EXTRA)
  59627. /* This test ends up using HMAC as a part of PBKDF2, and HMAC
  59628. * requires a 12 byte password in FIPS mode. This test ends up
  59629. * trying to use an 8 byte password. */
  59630. #ifndef NO_FILESYSTEM
  59631. unsigned char pkcs8_buffer[2048];
  59632. const unsigned char* p = NULL;
  59633. int bytes = 0;
  59634. XFILE file = XBADFILE;
  59635. WOLFSSL_EVP_PKEY* pkey = NULL;
  59636. #ifndef NO_BIO
  59637. BIO* bio = NULL;
  59638. #if defined(OPENSSL_ALL) && \
  59639. ((!defined(NO_RSA) && !defined(NO_DES3)) || \
  59640. defined(HAVE_ECC)) && \
  59641. !defined(NO_BIO) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  59642. WOLFSSL_EVP_PKEY* evpPkey = NULL;
  59643. #endif
  59644. #endif
  59645. #ifndef NO_RSA
  59646. const char rsaDerPkcs8File[] = "./certs/server-keyPkcs8.der";
  59647. const char rsaPemPkcs8File[] = "./certs/server-keyPkcs8.pem";
  59648. #ifndef NO_DES3
  59649. const char rsaDerPkcs8EncFile[] = "./certs/server-keyPkcs8Enc.der";
  59650. #endif
  59651. #endif /* NO_RSA */
  59652. #ifdef HAVE_ECC
  59653. const char ecDerPkcs8File[] = "certs/ecc-keyPkcs8.der";
  59654. const char ecPemPkcs8File[] = "certs/ecc-keyPkcs8.pem";
  59655. #ifndef NO_DES3
  59656. const char ecDerPkcs8EncFile[] = "certs/ecc-keyPkcs8Enc.der";
  59657. #endif
  59658. #endif /* HAVE_ECC */
  59659. #endif /* !NO_FILESYSTEM */
  59660. #if defined(OPENSSL_ALL) && (!defined(NO_RSA) || defined(HAVE_ECC))
  59661. #ifndef NO_RSA
  59662. #ifdef USE_CERT_BUFFERS_1024
  59663. const unsigned char* rsa = (unsigned char*)server_key_der_1024;
  59664. int rsaSz = sizeof_server_key_der_1024;
  59665. #else
  59666. const unsigned char* rsa = (unsigned char*)server_key_der_2048;
  59667. int rsaSz = sizeof_server_key_der_2048;
  59668. #endif
  59669. #endif
  59670. #ifdef HAVE_ECC
  59671. const unsigned char* ec = (unsigned char*)ecc_key_der_256;
  59672. int ecSz = sizeof_ecc_key_der_256;
  59673. #endif
  59674. #endif /* OPENSSL_ALL && (!NO_RSA || HAVE_ECC) */
  59675. #ifndef NO_FILESYSTEM
  59676. (void)pkcs8_buffer;
  59677. (void)p;
  59678. (void)bytes;
  59679. (void)file;
  59680. #ifndef NO_BIO
  59681. (void)bio;
  59682. #endif
  59683. #endif
  59684. #ifdef OPENSSL_ALL
  59685. #ifndef NO_RSA
  59686. /* Try to auto-detect normal RSA private key */
  59687. ExpectNotNull(pkey = d2i_AutoPrivateKey(NULL, &rsa, rsaSz));
  59688. EVP_PKEY_free(pkey);
  59689. pkey = NULL;
  59690. #endif
  59691. #ifdef HAVE_ECC
  59692. /* Try to auto-detect normal EC private key */
  59693. ExpectNotNull(pkey = d2i_AutoPrivateKey(NULL, &ec, ecSz));
  59694. EVP_PKEY_free(pkey);
  59695. pkey = NULL;
  59696. #endif
  59697. #endif /* OPENSSL_ALL */
  59698. #ifndef NO_FILESYSTEM
  59699. #if defined(OPENSSL_ALL) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  59700. ExpectIntEQ(PEM_write_PKCS8PrivateKey(XBADFILE, pkey, NULL, NULL, 0, NULL,
  59701. NULL), 0);
  59702. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, NULL, NULL, NULL, 0, NULL,
  59703. NULL), 0);
  59704. #endif
  59705. #ifndef NO_RSA
  59706. /* Get DER encoded RSA PKCS#8 data. */
  59707. ExpectTrue((file = XFOPEN(rsaDerPkcs8File, "rb")) != XBADFILE);
  59708. ExpectNotNull(XMEMSET(pkcs8_buffer, 0, sizeof(pkcs8_buffer)));
  59709. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  59710. file)), 0);
  59711. if (file != XBADFILE) {
  59712. XFCLOSE(file);
  59713. file = XBADFILE;
  59714. }
  59715. p = pkcs8_buffer;
  59716. #ifdef OPENSSL_ALL
  59717. /* Try to decode - auto-detect key type. */
  59718. ExpectNotNull(pkey = d2i_AutoPrivateKey(NULL, &p, bytes));
  59719. #else
  59720. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_RSA, NULL, &p, bytes));
  59721. #endif
  59722. /* Get PEM encoded RSA PKCS#8 data. */
  59723. ExpectTrue((file = XFOPEN(rsaPemPkcs8File, "rb")) != XBADFILE);
  59724. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  59725. file)), 0);
  59726. if (file != XBADFILE) {
  59727. XFCLOSE(file);
  59728. file = XBADFILE;
  59729. }
  59730. #if defined(OPENSSL_ALL) && \
  59731. !defined(NO_BIO) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  59732. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  59733. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(NULL, pkey, NULL, NULL, 0, NULL,
  59734. NULL), 0);
  59735. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, NULL, NULL, NULL, 0, NULL,
  59736. NULL), 0);
  59737. /* Write PKCS#8 PEM to BIO. */
  59738. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, NULL, NULL, 0, NULL,
  59739. NULL), bytes);
  59740. /* Write PKCS#8 PEM to stderr. */
  59741. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, NULL, NULL, 0, NULL,
  59742. NULL), bytes);
  59743. /* Compare file and written data */
  59744. ExpectIntEQ(BIO_get_mem_data(bio, &p), bytes);
  59745. ExpectIntEQ(XMEMCMP(p, pkcs8_buffer, bytes), 0);
  59746. BIO_free(bio);
  59747. bio = NULL;
  59748. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  59749. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, EVP_aes_128_gcm(),
  59750. NULL, 0, PasswordCallBack, (void*)"yassl123"), 0);
  59751. #endif
  59752. #if !defined(NO_DES3) && !defined(NO_SHA)
  59753. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  59754. /* Write Encrypted PKCS#8 PEM to BIO. */
  59755. bytes = 1834;
  59756. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, EVP_des_ede3_cbc(),
  59757. NULL, 0, PasswordCallBack, (void*)"yassl123"), bytes);
  59758. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, EVP_des_ede3_cbc(),
  59759. NULL, 0, PasswordCallBack, (void*)"yassl123"), bytes);
  59760. ExpectNotNull(evpPkey = PEM_read_bio_PrivateKey(bio, NULL, PasswordCallBack,
  59761. (void*)"yassl123"));
  59762. EVP_PKEY_free(evpPkey);
  59763. evpPkey = NULL;
  59764. BIO_free(bio);
  59765. bio = NULL;
  59766. #endif /* !NO_DES3 && !NO_SHA */
  59767. #endif /* !NO_BIO && !NO_PWDBASED && HAVE_PKCS8 */
  59768. EVP_PKEY_free(pkey);
  59769. pkey = NULL;
  59770. /* PKCS#8 encrypted RSA key */
  59771. #ifndef NO_DES3
  59772. ExpectTrue((file = XFOPEN(rsaDerPkcs8EncFile, "rb")) != XBADFILE);
  59773. ExpectNotNull(XMEMSET(pkcs8_buffer, 0, sizeof(pkcs8_buffer)));
  59774. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  59775. file)), 0);
  59776. if (file != XBADFILE) {
  59777. XFCLOSE(file);
  59778. file = XBADFILE;
  59779. }
  59780. #if defined(OPENSSL_ALL) && \
  59781. !defined(NO_BIO) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  59782. ExpectNotNull(bio = BIO_new_mem_buf((void*)pkcs8_buffer, bytes));
  59783. ExpectNotNull(pkey = d2i_PKCS8PrivateKey_bio(bio, NULL, PasswordCallBack,
  59784. (void*)"yassl123"));
  59785. EVP_PKEY_free(pkey);
  59786. pkey = NULL;
  59787. BIO_free(bio);
  59788. bio = NULL;
  59789. #endif /* OPENSSL_ALL && !NO_BIO && !NO_PWDBASED && HAVE_PKCS8 */
  59790. #endif /* !NO_DES3 */
  59791. #endif /* NO_RSA */
  59792. #ifdef HAVE_ECC
  59793. /* PKCS#8 encode EC key */
  59794. ExpectTrue((file = XFOPEN(ecDerPkcs8File, "rb")) != XBADFILE);
  59795. ExpectNotNull(XMEMSET(pkcs8_buffer, 0, sizeof(pkcs8_buffer)));
  59796. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  59797. file)), 0);
  59798. if (file != XBADFILE) {
  59799. XFCLOSE(file);
  59800. file = XBADFILE;
  59801. }
  59802. p = pkcs8_buffer;
  59803. #ifdef OPENSSL_ALL
  59804. /* Try to decode - auto-detect key type. */
  59805. ExpectNotNull(pkey = d2i_AutoPrivateKey(NULL, &p, bytes));
  59806. #else
  59807. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &p, bytes));
  59808. #endif
  59809. /* Get PEM encoded RSA PKCS#8 data. */
  59810. ExpectTrue((file = XFOPEN(ecPemPkcs8File, "rb")) != XBADFILE);
  59811. ExpectNotNull(XMEMSET(pkcs8_buffer, 0, sizeof(pkcs8_buffer)));
  59812. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  59813. file)), 0);
  59814. if (file != XBADFILE) {
  59815. XFCLOSE(file);
  59816. file = XBADFILE;
  59817. }
  59818. #if defined(OPENSSL_ALL) && \
  59819. !defined(NO_BIO) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8) && \
  59820. defined(HAVE_AES_CBC)
  59821. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  59822. /* Write PKCS#8 PEM to BIO. */
  59823. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, NULL, NULL, 0, NULL,
  59824. NULL), bytes);
  59825. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, NULL, NULL, 0, NULL,
  59826. NULL), bytes);
  59827. /* Compare file and written data */
  59828. ExpectIntEQ(BIO_get_mem_data(bio, &p), bytes);
  59829. ExpectIntEQ(XMEMCMP(p, pkcs8_buffer, bytes), 0);
  59830. BIO_free(bio);
  59831. bio = NULL;
  59832. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  59833. /* Write Encrypted PKCS#8 PEM to BIO. */
  59834. bytes = 379;
  59835. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, EVP_aes_256_cbc(),
  59836. NULL, 0, NoPasswordCallBack, (void*)"yassl123"), 0);
  59837. ExpectIntEQ(PEM_write_bio_PKCS8PrivateKey(bio, pkey, EVP_aes_256_cbc(),
  59838. NULL, 0, PasswordCallBack, (void*)"yassl123"), bytes);
  59839. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, EVP_aes_128_cbc(),
  59840. NULL, 0, PasswordCallBack, (void*)"yassl123"), bytes);
  59841. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, EVP_aes_128_cbc(),
  59842. (char*)"yassl123", 8, PasswordCallBack, NULL), bytes);
  59843. ExpectIntEQ(PEM_write_PKCS8PrivateKey(stderr, pkey, EVP_aes_256_cbc(),
  59844. NULL, 0, PasswordCallBack, (void*)"yassl123"), bytes);
  59845. ExpectNotNull(evpPkey = PEM_read_bio_PrivateKey(bio, NULL, PasswordCallBack,
  59846. (void*)"yassl123"));
  59847. EVP_PKEY_free(evpPkey);
  59848. evpPkey = NULL;
  59849. BIO_free(bio);
  59850. bio = NULL;
  59851. #endif /* OPENSSL_ALL && !NO_BIO && !NO_PWDBASED && HAVE_PKCS8 && HAVE_AES_CBC */
  59852. EVP_PKEY_free(pkey);
  59853. pkey = NULL;
  59854. /* PKCS#8 encrypted EC key */
  59855. #ifndef NO_DES3
  59856. ExpectTrue((file = XFOPEN(ecDerPkcs8EncFile, "rb")) != XBADFILE);
  59857. ExpectNotNull(XMEMSET(pkcs8_buffer, 0, sizeof(pkcs8_buffer)));
  59858. ExpectIntGT((bytes = (int)XFREAD(pkcs8_buffer, 1, sizeof(pkcs8_buffer),
  59859. file)), 0);
  59860. if (file != XBADFILE) {
  59861. XFCLOSE(file);
  59862. file = XBADFILE;
  59863. }
  59864. #if defined(OPENSSL_ALL) && \
  59865. !defined(NO_BIO) && !defined(NO_PWDBASED) && defined(HAVE_PKCS8)
  59866. ExpectNotNull(bio = BIO_new_mem_buf((void*)pkcs8_buffer, bytes));
  59867. ExpectNotNull(pkey = d2i_PKCS8PrivateKey_bio(bio, NULL, PasswordCallBack,
  59868. (void*)"yassl123"));
  59869. EVP_PKEY_free(pkey);
  59870. pkey = NULL;
  59871. BIO_free(bio);
  59872. bio = NULL;
  59873. #endif /* OPENSSL_ALL && !NO_BIO && !NO_PWDBASED && HAVE_PKCS8 */
  59874. #endif /* !NO_DES3 */
  59875. #endif /* HAVE_ECC */
  59876. #endif /* !NO_FILESYSTEM */
  59877. #endif /* HAVE_FIPS && OPENSSL_EXTRA */
  59878. return EXPECT_RESULT();
  59879. }
  59880. #if !defined(SINGLE_THREADED) && defined(ERROR_QUEUE_PER_THREAD) && \
  59881. !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  59882. defined(DEBUG_WOLFSSL)
  59883. #define LOGGING_THREADS 5
  59884. #define ERROR_COUNT 10
  59885. /* copied from logging.c since this is not exposed otherwise */
  59886. #ifndef ERROR_QUEUE_MAX
  59887. #ifdef ERROR_QUEUE_PER_THREAD
  59888. #define ERROR_QUEUE_MAX 16
  59889. #else
  59890. /* this breaks from compat of unlimited error queue size */
  59891. #define ERROR_QUEUE_MAX 100
  59892. #endif
  59893. #endif
  59894. static volatile int loggingThreadsReady;
  59895. static THREAD_RETURN WOLFSSL_THREAD test_logging(void* args)
  59896. {
  59897. const char* file;
  59898. int line;
  59899. unsigned long err;
  59900. int errorCount = 0;
  59901. int i;
  59902. (void)args;
  59903. while (!loggingThreadsReady);
  59904. for (i = 0; i < ERROR_COUNT; i++)
  59905. ERR_put_error(ERR_LIB_PEM, SYS_F_ACCEPT, -990 - i, __FILE__, __LINE__);
  59906. while ((err = ERR_get_error_line(&file, &line))) {
  59907. AssertIntEQ(err, 990 + errorCount);
  59908. errorCount++;
  59909. }
  59910. AssertIntEQ(errorCount, ERROR_COUNT);
  59911. /* test max queue behavior, trying to add an arbitrary 3 errors over */
  59912. ERR_clear_error(); /* ERR_get_error_line() does not remove */
  59913. errorCount = 0;
  59914. for (i = 0; i < ERROR_QUEUE_MAX + 3; i++)
  59915. ERR_put_error(ERR_LIB_PEM, SYS_F_ACCEPT, -990 - i, __FILE__, __LINE__);
  59916. while ((err = ERR_get_error_line(&file, &line))) {
  59917. AssertIntEQ(err, 990 + errorCount);
  59918. errorCount++;
  59919. }
  59920. /* test that the 3 errors over the max were dropped */
  59921. AssertIntEQ(errorCount, ERROR_QUEUE_MAX);
  59922. WOLFSSL_RETURN_FROM_THREAD(0);
  59923. }
  59924. #endif
  59925. static int test_error_queue_per_thread(void)
  59926. {
  59927. int res = TEST_SKIPPED;
  59928. #if !defined(SINGLE_THREADED) && defined(ERROR_QUEUE_PER_THREAD) && \
  59929. !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  59930. defined(DEBUG_WOLFSSL)
  59931. THREAD_TYPE loggingThreads[LOGGING_THREADS];
  59932. int i;
  59933. ERR_clear_error(); /* clear out any error nodes */
  59934. loggingThreadsReady = 0;
  59935. for (i = 0; i < LOGGING_THREADS; i++)
  59936. start_thread(test_logging, NULL, &loggingThreads[i]);
  59937. loggingThreadsReady = 1;
  59938. for (i = 0; i < LOGGING_THREADS; i++)
  59939. join_thread(loggingThreads[i]);
  59940. res = TEST_SUCCESS;
  59941. #endif
  59942. return res;
  59943. }
  59944. static int test_wolfSSL_ERR_put_error(void)
  59945. {
  59946. EXPECT_DECLS;
  59947. #if !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  59948. defined(DEBUG_WOLFSSL)
  59949. const char* file;
  59950. int line;
  59951. ERR_clear_error(); /* clear out any error nodes */
  59952. ERR_put_error(0,SYS_F_ACCEPT, 0, "this file", 0);
  59953. ExpectIntEQ(ERR_get_error_line(&file, &line), 0);
  59954. ERR_put_error(0,SYS_F_BIND, 1, "this file", 1);
  59955. ExpectIntEQ(ERR_get_error_line(&file, &line), 1);
  59956. ERR_put_error(0,SYS_F_CONNECT, 2, "this file", 2);
  59957. ExpectIntEQ(ERR_get_error_line(&file, &line), 2);
  59958. ERR_put_error(0,SYS_F_FOPEN, 3, "this file", 3);
  59959. ExpectIntEQ(ERR_get_error_line(&file, &line), 3);
  59960. ERR_put_error(0,SYS_F_FREAD, 4, "this file", 4);
  59961. ExpectIntEQ(ERR_get_error_line(&file, &line), 4);
  59962. ERR_put_error(0,SYS_F_GETADDRINFO, 5, "this file", 5);
  59963. ExpectIntEQ(ERR_get_error_line(&file, &line), 5);
  59964. ERR_put_error(0,SYS_F_GETSOCKOPT, 6, "this file", 6);
  59965. ExpectIntEQ(ERR_get_error_line(&file, &line), 6);
  59966. ERR_put_error(0,SYS_F_GETSOCKNAME, 7, "this file", 7);
  59967. ExpectIntEQ(ERR_get_error_line(&file, &line), 7);
  59968. ERR_put_error(0,SYS_F_GETHOSTBYNAME, 8, "this file", 8);
  59969. ExpectIntEQ(ERR_get_error_line(&file, &line), 8);
  59970. ERR_put_error(0,SYS_F_GETNAMEINFO, 9, "this file", 9);
  59971. ExpectIntEQ(ERR_get_error_line(&file, &line), 9);
  59972. ERR_put_error(0,SYS_F_GETSERVBYNAME, 10, "this file", 10);
  59973. ExpectIntEQ(ERR_get_error_line(&file, &line), 10);
  59974. ERR_put_error(0,SYS_F_IOCTLSOCKET, 11, "this file", 11);
  59975. ExpectIntEQ(ERR_get_error_line(&file, &line), 11);
  59976. ERR_put_error(0,SYS_F_LISTEN, 12, "this file", 12);
  59977. ExpectIntEQ(ERR_get_error_line(&file, &line), 12);
  59978. ERR_put_error(0,SYS_F_OPENDIR, 13, "this file", 13);
  59979. ExpectIntEQ(ERR_get_error_line(&file, &line), 13);
  59980. ERR_put_error(0,SYS_F_SETSOCKOPT, 14, "this file", 14);
  59981. ExpectIntEQ(ERR_get_error_line(&file, &line), 14);
  59982. ERR_put_error(0,SYS_F_SOCKET, 15, "this file", 15);
  59983. ExpectIntEQ(ERR_get_error_line(&file, &line), 15);
  59984. #if defined(OPENSSL_ALL) && defined(WOLFSSL_PYTHON)
  59985. ERR_put_error(ERR_LIB_ASN1, SYS_F_ACCEPT, ASN1_R_HEADER_TOO_LONG,
  59986. "this file", 100);
  59987. ExpectIntEQ(wolfSSL_ERR_peek_last_error_line(&file, &line),
  59988. (ERR_LIB_ASN1 << 24) | ASN1_R_HEADER_TOO_LONG);
  59989. ExpectIntEQ(line, 100);
  59990. ExpectIntEQ(wolfSSL_ERR_peek_error(),
  59991. (ERR_LIB_ASN1 << 24) | ASN1_R_HEADER_TOO_LONG);
  59992. ExpectIntEQ(ERR_get_error_line(&file, &line), ASN1_R_HEADER_TOO_LONG);
  59993. #endif
  59994. /* try reading past end of error queue */
  59995. file = NULL;
  59996. ExpectIntEQ(ERR_get_error_line(&file, &line), 0);
  59997. ExpectNull(file);
  59998. ExpectIntEQ(ERR_get_error_line_data(&file, &line, NULL, NULL), 0);
  59999. PEMerr(4,4);
  60000. ExpectIntEQ(ERR_get_error(), 4);
  60001. /* Empty and free up all error nodes */
  60002. ERR_clear_error();
  60003. /* Verify all nodes are cleared */
  60004. ERR_put_error(0,SYS_F_ACCEPT, 0, "this file", 0);
  60005. ERR_clear_error();
  60006. ExpectIntEQ(ERR_get_error_line(&file, &line), 0);
  60007. #endif
  60008. return EXPECT_RESULT();
  60009. }
  60010. /*
  60011. * This is a regression test for a bug where the peek/get error functions were
  60012. * drawing from the end of the queue rather than the front.
  60013. */
  60014. static int test_wolfSSL_ERR_get_error_order(void)
  60015. {
  60016. EXPECT_DECLS;
  60017. #if defined(WOLFSSL_HAVE_ERROR_QUEUE) && defined(OPENSSL_EXTRA)
  60018. /* Empty the queue. */
  60019. wolfSSL_ERR_clear_error();
  60020. wolfSSL_ERR_put_error(0, 0, WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), "test", 0);
  60021. wolfSSL_ERR_put_error(0, 0, WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E), "test", 0);
  60022. ExpectIntEQ(wolfSSL_ERR_peek_error(), -WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  60023. ExpectIntEQ(wolfSSL_ERR_get_error(), -WC_NO_ERR_TRACE(ASN_NO_SIGNER_E));
  60024. ExpectIntEQ(wolfSSL_ERR_peek_error(), -WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E));
  60025. ExpectIntEQ(wolfSSL_ERR_get_error(), -WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E));
  60026. #endif /* WOLFSSL_HAVE_ERROR_QUEUE && OPENSSL_EXTRA */
  60027. return EXPECT_RESULT();
  60028. }
  60029. #ifndef NO_BIO
  60030. static int test_wolfSSL_ERR_print_errors(void)
  60031. {
  60032. EXPECT_DECLS;
  60033. #if !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  60034. defined(DEBUG_WOLFSSL) && !defined(NO_ERROR_STRINGS)
  60035. BIO* bio = NULL;
  60036. char buf[1024];
  60037. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  60038. ERR_clear_error(); /* clear out any error nodes */
  60039. ERR_put_error(0,SYS_F_ACCEPT, -173, "ssl.c", 0);
  60040. /* Choosing -600 as an unused errno. */
  60041. ERR_put_error(0,SYS_F_BIND, -600, "asn.c", 100);
  60042. ERR_print_errors(bio);
  60043. ExpectIntEQ(BIO_gets(bio, buf, sizeof(buf)), 56);
  60044. ExpectIntEQ(XSTRNCMP(
  60045. "error:173:wolfSSL library:Bad function argument:ssl.c:0",
  60046. buf, 55), 0);
  60047. ExpectIntEQ(BIO_gets(bio, buf, sizeof(buf)), 57);
  60048. ExpectIntEQ(XSTRNCMP(
  60049. "error:600:wolfSSL library:unknown error number:asn.c:100",
  60050. buf, 56), 0);
  60051. ExpectIntEQ(BIO_gets(bio, buf, sizeof(buf)), 1);
  60052. ExpectIntEQ(buf[0], '\0');
  60053. ExpectIntEQ(ERR_get_error_line(NULL, NULL), 0);
  60054. BIO_free(bio);
  60055. #endif
  60056. return EXPECT_RESULT();
  60057. }
  60058. #if !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  60059. defined(DEBUG_WOLFSSL)
  60060. static int test_wolfSSL_error_cb(const char *str, size_t len, void *u)
  60061. {
  60062. wolfSSL_BIO_write((BIO*)u, str, (int)len);
  60063. return 0;
  60064. }
  60065. #endif
  60066. static int test_wolfSSL_ERR_print_errors_cb(void)
  60067. {
  60068. EXPECT_DECLS;
  60069. #if !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
  60070. defined(DEBUG_WOLFSSL)
  60071. BIO* bio = NULL;
  60072. char buf[1024];
  60073. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  60074. ERR_clear_error(); /* clear out any error nodes */
  60075. ERR_put_error(0,SYS_F_ACCEPT, -173, "ssl.c", 0);
  60076. ERR_put_error(0,SYS_F_BIND, -275, "asn.c", 100);
  60077. ERR_print_errors_cb(test_wolfSSL_error_cb, bio);
  60078. ExpectIntEQ(BIO_gets(bio, buf, sizeof(buf)), 108);
  60079. ExpectIntEQ(XSTRNCMP(
  60080. "wolfSSL error occurred, error = 173 line:0 file:ssl.c",
  60081. buf, 53), 0);
  60082. ExpectIntEQ(XSTRNCMP(
  60083. "wolfSSL error occurred, error = 275 line:100 file:asn.c",
  60084. buf + 53, 55), 0);
  60085. ExpectIntEQ(BIO_gets(bio, buf, sizeof(buf)), 0);
  60086. BIO_free(bio);
  60087. #endif
  60088. return EXPECT_RESULT();
  60089. }
  60090. /*
  60091. * Testing WOLFSSL_ERROR_MSG
  60092. */
  60093. static int test_WOLFSSL_ERROR_MSG(void)
  60094. {
  60095. int res = TEST_SKIPPED;
  60096. #if defined(DEBUG_WOLFSSL) || defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) ||\
  60097. defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA)
  60098. const char* msg = TEST_STRING;
  60099. WOLFSSL_ERROR_MSG(msg);
  60100. res = TEST_SUCCESS;
  60101. #endif
  60102. return res;
  60103. } /* End test_WOLFSSL_ERROR_MSG */
  60104. /*
  60105. * Testing wc_ERR_remove_state
  60106. */
  60107. static int test_wc_ERR_remove_state(void)
  60108. {
  60109. int res = TEST_SKIPPED;
  60110. #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
  60111. wc_ERR_remove_state();
  60112. res = TEST_SUCCESS;
  60113. #endif
  60114. return res;
  60115. } /* End test_wc_ERR_remove_state */
  60116. /*
  60117. * Testing wc_ERR_print_errors_fp
  60118. */
  60119. static int test_wc_ERR_print_errors_fp(void)
  60120. {
  60121. EXPECT_DECLS;
  60122. #if (defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)) && \
  60123. (!defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM))
  60124. long sz;
  60125. XFILE fp = XBADFILE;
  60126. WOLFSSL_ERROR(WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60127. ExpectTrue((fp = XFOPEN("./tests/test-log-dump-to-file.txt", "ar")) !=
  60128. XBADFILE);
  60129. wc_ERR_print_errors_fp(fp);
  60130. #if defined(DEBUG_WOLFSSL)
  60131. ExpectTrue(XFSEEK(fp, 0, XSEEK_END) == 0);
  60132. #ifdef NO_ERROR_QUEUE
  60133. ExpectIntEQ(sz = XFTELL(fp), 0);
  60134. #else
  60135. ExpectIntNE(sz = XFTELL(fp), 0);
  60136. #endif
  60137. #endif
  60138. if (fp != XBADFILE)
  60139. XFCLOSE(fp);
  60140. (void)sz;
  60141. #endif
  60142. return EXPECT_RESULT();
  60143. } /* End test_wc_ERR_print_errors_fp */
  60144. #ifdef DEBUG_WOLFSSL
  60145. static void Logging_cb(const int logLevel, const char *const logMessage)
  60146. {
  60147. (void)logLevel;
  60148. (void)logMessage;
  60149. }
  60150. #endif
  60151. /*
  60152. * Testing wolfSSL_GetLoggingCb
  60153. */
  60154. static int test_wolfSSL_GetLoggingCb(void)
  60155. {
  60156. EXPECT_DECLS;
  60157. #ifdef DEBUG_WOLFSSL
  60158. /* Testing without wolfSSL_SetLoggingCb() */
  60159. ExpectNull(wolfSSL_GetLoggingCb());
  60160. /* Testing with wolfSSL_SetLoggingCb() */
  60161. ExpectIntEQ(wolfSSL_SetLoggingCb(Logging_cb), 0);
  60162. ExpectNotNull(wolfSSL_GetLoggingCb());
  60163. ExpectIntEQ(wolfSSL_SetLoggingCb(NULL), 0);
  60164. #endif
  60165. ExpectNull(wolfSSL_GetLoggingCb());
  60166. return EXPECT_RESULT();
  60167. } /* End test_wolfSSL_GetLoggingCb */
  60168. #endif /* !NO_BIO */
  60169. static int test_wolfSSL_MD4(void)
  60170. {
  60171. EXPECT_DECLS;
  60172. #if defined(OPENSSL_EXTRA) && !defined(NO_MD4)
  60173. MD4_CTX md4;
  60174. unsigned char out[16]; /* MD4_DIGEST_SIZE */
  60175. const char* msg = "12345678901234567890123456789012345678901234567890123456"
  60176. "789012345678901234567890";
  60177. const char* test = "\xe3\x3b\x4d\xdc\x9c\x38\xf2\x19\x9c\x3e\x7b\x16\x4f"
  60178. "\xcc\x05\x36";
  60179. int msgSz = (int)XSTRLEN(msg);
  60180. XMEMSET(out, 0, sizeof(out));
  60181. MD4_Init(&md4);
  60182. MD4_Update(&md4, (const void*)msg, (word32)msgSz);
  60183. MD4_Final(out, &md4);
  60184. ExpectIntEQ(XMEMCMP(out, test, sizeof(out)), 0);
  60185. #endif
  60186. return EXPECT_RESULT();
  60187. }
  60188. static int test_wolfSSL_MD5(void)
  60189. {
  60190. EXPECT_DECLS;
  60191. #if defined(OPENSSL_EXTRA) && !defined(NO_MD5)
  60192. byte input1[] = "";
  60193. byte input2[] = "message digest";
  60194. byte hash[WC_MD5_DIGEST_SIZE];
  60195. unsigned char output1[] =
  60196. "\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\x09\x98\xec\xf8\x42\x7e";
  60197. unsigned char output2[] =
  60198. "\xf9\x6b\x69\x7d\x7c\xb7\x93\x8d\x52\x5a\x2f\x31\xaa\xf1\x61\xd0";
  60199. WOLFSSL_MD5_CTX md5;
  60200. XMEMSET(&md5, 0, sizeof(md5));
  60201. /* Test cases for illegal parameters */
  60202. ExpectIntEQ(MD5_Init(NULL), 0);
  60203. ExpectIntEQ(MD5_Init(&md5), 1);
  60204. ExpectIntEQ(MD5_Update(NULL, input1, 0), 0);
  60205. ExpectIntEQ(MD5_Update(NULL, NULL, 0), 0);
  60206. ExpectIntEQ(MD5_Update(&md5, NULL, 1), 0);
  60207. ExpectIntEQ(MD5_Final(NULL, &md5), 0);
  60208. ExpectIntEQ(MD5_Final(hash, NULL), 0);
  60209. ExpectIntEQ(MD5_Final(NULL, NULL), 0);
  60210. /* Init MD5 CTX */
  60211. ExpectIntEQ(wolfSSL_MD5_Init(&md5), 1);
  60212. ExpectIntEQ(wolfSSL_MD5_Update(&md5, input1, XSTRLEN((const char*)&input1)),
  60213. 1);
  60214. ExpectIntEQ(wolfSSL_MD5_Final(hash, &md5), 1);
  60215. ExpectIntEQ(XMEMCMP(&hash, output1, WC_MD5_DIGEST_SIZE), 0);
  60216. /* Init MD5 CTX */
  60217. ExpectIntEQ(wolfSSL_MD5_Init(&md5), 1);
  60218. ExpectIntEQ(wolfSSL_MD5_Update(&md5, input2,
  60219. (int)XSTRLEN((const char*)input2)), 1);
  60220. ExpectIntEQ(wolfSSL_MD5_Final(hash, &md5), 1);
  60221. ExpectIntEQ(XMEMCMP(&hash, output2, WC_MD5_DIGEST_SIZE), 0);
  60222. #if !defined(NO_OLD_NAMES) && \
  60223. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2)))
  60224. ExpectPtrNE(MD5(NULL, 1, (byte*)&hash), &hash);
  60225. ExpectPtrEq(MD5(input1, 0, (byte*)&hash), &hash);
  60226. ExpectPtrNE(MD5(input1, 1, NULL), NULL);
  60227. ExpectPtrNE(MD5(NULL, 0, NULL), NULL);
  60228. ExpectPtrEq(MD5(input1, (int)XSTRLEN((const char*)&input1), (byte*)&hash),
  60229. &hash);
  60230. ExpectIntEQ(XMEMCMP(&hash, output1, WC_MD5_DIGEST_SIZE), 0);
  60231. ExpectPtrEq(MD5(input2, (int)XSTRLEN((const char*)&input2), (byte*)&hash),
  60232. &hash);
  60233. ExpectIntEQ(XMEMCMP(&hash, output2, WC_MD5_DIGEST_SIZE), 0);
  60234. {
  60235. byte data[] = "Data to be hashed.";
  60236. XMEMSET(hash, 0, WC_MD5_DIGEST_SIZE);
  60237. ExpectNotNull(MD5(data, sizeof(data), NULL));
  60238. ExpectNotNull(MD5(data, sizeof(data), hash));
  60239. ExpectNotNull(MD5(NULL, 0, hash));
  60240. ExpectNull(MD5(NULL, sizeof(data), hash));
  60241. }
  60242. #endif
  60243. #endif
  60244. return EXPECT_RESULT();
  60245. }
  60246. static int test_wolfSSL_MD5_Transform(void)
  60247. {
  60248. EXPECT_DECLS;
  60249. #if defined(OPENSSL_EXTRA) && !defined(NO_MD5)
  60250. byte input1[] = "";
  60251. byte input2[] = "abc";
  60252. byte local[WC_MD5_BLOCK_SIZE];
  60253. word32 sLen = 0;
  60254. #ifdef BIG_ENDIAN_ORDER
  60255. unsigned char output1[] =
  60256. "\x03\x1f\x1d\xac\x6e\xa5\x8e\xd0\x1f\xab\x67\xb7\x74\x31\x77\x91";
  60257. unsigned char output2[] =
  60258. "\xef\xd3\x79\x8d\x67\x17\x25\x90\xa4\x13\x79\xc7\xe3\xa7\x7b\xbc";
  60259. #else
  60260. unsigned char output1[] =
  60261. "\xac\x1d\x1f\x03\xd0\x8e\xa5\x6e\xb7\x67\xab\x1f\x91\x77\x31\x74";
  60262. unsigned char output2[] =
  60263. "\x8d\x79\xd3\xef\x90\x25\x17\x67\xc7\x79\x13\xa4\xbc\x7b\xa7\xe3";
  60264. #endif
  60265. union {
  60266. wc_Md5 native;
  60267. MD5_CTX compat;
  60268. } md5;
  60269. XMEMSET(&md5.compat, 0, sizeof(md5.compat));
  60270. XMEMSET(&local, 0, sizeof(local));
  60271. /* sanity check */
  60272. ExpectIntEQ(MD5_Transform(NULL, NULL), 0);
  60273. ExpectIntEQ(MD5_Transform(NULL, (const byte*)&input1), 0);
  60274. ExpectIntEQ(MD5_Transform(&md5.compat, NULL), 0);
  60275. ExpectIntEQ(wc_Md5Transform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60276. ExpectIntEQ(wc_Md5Transform(NULL, (const byte*)&input1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60277. ExpectIntEQ(wc_Md5Transform(&md5.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60278. /* Init MD5 CTX */
  60279. ExpectIntEQ(wolfSSL_MD5_Init(&md5.compat), 1);
  60280. /* Do Transform*/
  60281. sLen = (word32)XSTRLEN((char*)input1);
  60282. XMEMCPY(local, input1, sLen);
  60283. ExpectIntEQ(MD5_Transform(&md5.compat, (const byte*)&local[0]), 1);
  60284. ExpectIntEQ(XMEMCMP(md5.native.digest, output1, WC_MD5_DIGEST_SIZE), 0);
  60285. /* Init MD5 CTX */
  60286. ExpectIntEQ(MD5_Init(&md5.compat), 1);
  60287. sLen = (word32)XSTRLEN((char*)input2);
  60288. XMEMSET(local, 0, WC_MD5_BLOCK_SIZE);
  60289. XMEMCPY(local, input2, sLen);
  60290. ExpectIntEQ(MD5_Transform(&md5.compat, (const byte*)&local[0]), 1);
  60291. ExpectIntEQ(XMEMCMP(md5.native.digest, output2, WC_MD5_DIGEST_SIZE), 0);
  60292. #endif
  60293. return EXPECT_RESULT();
  60294. }
  60295. static int test_wolfSSL_SHA(void)
  60296. {
  60297. EXPECT_DECLS;
  60298. #if defined(OPENSSL_EXTRA) && !defined(HAVE_SELFTEST)
  60299. #if !defined(NO_SHA) && defined(NO_OLD_SHA_NAMES) && \
  60300. (!defined(HAVE_FIPS) || \
  60301. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2))
  60302. {
  60303. const unsigned char in[] = "abc";
  60304. unsigned char expected[] = "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E"
  60305. "\x25\x71\x78\x50\xC2\x6C\x9C\xD0\xD8\x9D";
  60306. unsigned char out[WC_SHA_DIGEST_SIZE];
  60307. unsigned char* p = NULL;
  60308. WOLFSSL_SHA_CTX sha;
  60309. XMEMSET(out, 0, WC_SHA_DIGEST_SIZE);
  60310. ExpectNotNull(SHA1(in, XSTRLEN((char*)in), out));
  60311. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA_DIGEST_SIZE), 0);
  60312. /* SHA interface test */
  60313. XMEMSET(out, 0, WC_SHA_DIGEST_SIZE);
  60314. ExpectNull(SHA(NULL, XSTRLEN((char*)in), out));
  60315. ExpectNotNull(SHA(in, 0, out));
  60316. ExpectNotNull(SHA(in, XSTRLEN((char*)in), NULL));
  60317. ExpectNotNull(SHA(NULL, 0, out));
  60318. ExpectNotNull(SHA(NULL, 0, NULL));
  60319. ExpectNotNull(SHA(in, XSTRLEN((char*)in), out));
  60320. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA_DIGEST_SIZE), 0);
  60321. ExpectNotNull(p = SHA(in, XSTRLEN((char*)in), NULL));
  60322. ExpectIntEQ(XMEMCMP(p, expected, WC_SHA_DIGEST_SIZE), 0);
  60323. ExpectIntEQ(wolfSSL_SHA_Init(&sha), 1);
  60324. ExpectIntEQ(wolfSSL_SHA_Update(&sha, in, XSTRLEN((char*)in)), 1);
  60325. ExpectIntEQ(wolfSSL_SHA_Final(out, &sha), 1);
  60326. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA_DIGEST_SIZE), 0);
  60327. ExpectIntEQ(wolfSSL_SHA1_Init(&sha), 1);
  60328. ExpectIntEQ(wolfSSL_SHA1_Update(&sha, in, XSTRLEN((char*)in)), 1);
  60329. ExpectIntEQ(wolfSSL_SHA1_Final(out, &sha), 1);
  60330. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA_DIGEST_SIZE), 0);
  60331. }
  60332. #endif
  60333. #if !defined(NO_SHA256)
  60334. {
  60335. const unsigned char in[] = "abc";
  60336. unsigned char expected[] =
  60337. "\xBA\x78\x16\xBF\x8F\x01\xCF\xEA\x41\x41\x40\xDE\x5D\xAE\x22"
  60338. "\x23\xB0\x03\x61\xA3\x96\x17\x7A\x9C\xB4\x10\xFF\x61\xF2\x00"
  60339. "\x15\xAD";
  60340. unsigned char out[WC_SHA256_DIGEST_SIZE];
  60341. unsigned char* p = NULL;
  60342. XMEMSET(out, 0, WC_SHA256_DIGEST_SIZE);
  60343. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  60344. ExpectNotNull(SHA256(in, XSTRLEN((char*)in), out));
  60345. #else
  60346. ExpectNotNull(wolfSSL_SHA256(in, XSTRLEN((char*)in), out));
  60347. #endif
  60348. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA256_DIGEST_SIZE), 0);
  60349. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  60350. ExpectNotNull(p = SHA256(in, XSTRLEN((char*)in), NULL));
  60351. #else
  60352. ExpectNotNull(p = wolfSSL_SHA256(in, XSTRLEN((char*)in), NULL));
  60353. #endif
  60354. ExpectIntEQ(XMEMCMP(p, expected, WC_SHA256_DIGEST_SIZE), 0);
  60355. }
  60356. #endif
  60357. #if defined(WOLFSSL_SHA384)
  60358. {
  60359. const unsigned char in[] = "abc";
  60360. unsigned char expected[] =
  60361. "\xcb\x00\x75\x3f\x45\xa3\x5e\x8b\xb5\xa0\x3d\x69\x9a\xc6\x50"
  60362. "\x07\x27\x2c\x32\xab\x0e\xde\xd1\x63\x1a\x8b\x60\x5a\x43\xff"
  60363. "\x5b\xed\x80\x86\x07\x2b\xa1\xe7\xcc\x23\x58\xba\xec\xa1\x34"
  60364. "\xc8\x25\xa7";
  60365. unsigned char out[WC_SHA384_DIGEST_SIZE];
  60366. unsigned char* p = NULL;
  60367. XMEMSET(out, 0, WC_SHA384_DIGEST_SIZE);
  60368. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  60369. ExpectNotNull(SHA384(in, XSTRLEN((char*)in), out));
  60370. #else
  60371. ExpectNotNull(wolfSSL_SHA384(in, XSTRLEN((char*)in), out));
  60372. #endif
  60373. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA384_DIGEST_SIZE), 0);
  60374. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  60375. ExpectNotNull(p = SHA384(in, XSTRLEN((char*)in), NULL));
  60376. #else
  60377. ExpectNotNull(p = wolfSSL_SHA384(in, XSTRLEN((char*)in), NULL));
  60378. #endif
  60379. ExpectIntEQ(XMEMCMP(p, expected, WC_SHA384_DIGEST_SIZE), 0);
  60380. }
  60381. #endif
  60382. #if defined(WOLFSSL_SHA512)
  60383. {
  60384. const unsigned char in[] = "abc";
  60385. unsigned char expected[] =
  60386. "\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41"
  60387. "\x31\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b\x55"
  60388. "\xd3\x9a\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c\x23\xa3"
  60389. "\xfe\xeb\xbd\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a\x9a\xc9\x4f"
  60390. "\xa5\x4c\xa4\x9f";
  60391. unsigned char out[WC_SHA512_DIGEST_SIZE];
  60392. unsigned char* p = NULL;
  60393. XMEMSET(out, 0, WC_SHA512_DIGEST_SIZE);
  60394. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  60395. ExpectNotNull(SHA512(in, XSTRLEN((char*)in), out));
  60396. #else
  60397. ExpectNotNull(wolfSSL_SHA512(in, XSTRLEN((char*)in), out));
  60398. #endif
  60399. ExpectIntEQ(XMEMCMP(out, expected, WC_SHA512_DIGEST_SIZE), 0);
  60400. #if !defined(NO_OLD_NAMES) && !defined(HAVE_FIPS)
  60401. ExpectNotNull(p = SHA512(in, XSTRLEN((char*)in), NULL));
  60402. #else
  60403. ExpectNotNull(p = wolfSSL_SHA512(in, XSTRLEN((char*)in), NULL));
  60404. #endif
  60405. ExpectIntEQ(XMEMCMP(p, expected, WC_SHA512_DIGEST_SIZE), 0);
  60406. }
  60407. #endif
  60408. #endif
  60409. return EXPECT_RESULT();
  60410. }
  60411. static int test_wolfSSL_SHA_Transform(void)
  60412. {
  60413. EXPECT_DECLS;
  60414. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA)
  60415. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  60416. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  60417. byte input1[] = "";
  60418. byte input2[] = "abc";
  60419. byte local[WC_SHA_BLOCK_SIZE];
  60420. word32 sLen = 0;
  60421. #ifdef BIG_ENDIAN_ORDER
  60422. unsigned char output1[] =
  60423. "\x92\xb4\x04\xe5\x56\x58\x8c\xed\x6c\x1a\xcd\x4e\xbf\x05\x3f\x68"
  60424. "\x09\xf7\x3a\x93";
  60425. unsigned char output2[] =
  60426. "\x97\xb2\x74\x8b\x4f\x5b\xbc\xca\x5b\xc0\xe6\xea\x2d\x40\xb4\xa0"
  60427. "\x7c\x6e\x08\xb8";
  60428. #else
  60429. unsigned char output1[] =
  60430. "\xe5\x04\xb4\x92\xed\x8c\x58\x56\x4e\xcd\x1a\x6c\x68\x3f\x05\xbf"
  60431. "\x93\x3a\xf7\x09";
  60432. unsigned char output2[] =
  60433. "\x8b\x74\xb2\x97\xca\xbc\x5b\x4f\xea\xe6\xc0\x5b\xa0\xb4\x40\x2d"
  60434. "\xb8\x08\x6e\x7c";
  60435. #endif
  60436. union {
  60437. wc_Sha native;
  60438. SHA_CTX compat;
  60439. } sha;
  60440. union {
  60441. wc_Sha native;
  60442. SHA_CTX compat;
  60443. } sha1;
  60444. XMEMSET(&sha.compat, 0, sizeof(sha.compat));
  60445. XMEMSET(&local, 0, sizeof(local));
  60446. /* sanity check */
  60447. ExpectIntEQ(SHA_Transform(NULL, NULL), 0);
  60448. ExpectIntEQ(SHA_Transform(NULL, (const byte*)&input1), 0);
  60449. ExpectIntEQ(SHA_Transform(&sha.compat, NULL), 0);
  60450. ExpectIntEQ(SHA1_Transform(NULL, NULL), 0);
  60451. ExpectIntEQ(SHA1_Transform(NULL, (const byte*)&input1), 0);
  60452. ExpectIntEQ(SHA1_Transform(&sha.compat, NULL), 0);
  60453. ExpectIntEQ(wc_ShaTransform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60454. ExpectIntEQ(wc_ShaTransform(NULL, (const byte*)&input1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60455. ExpectIntEQ(wc_ShaTransform(&sha.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60456. /* Init SHA CTX */
  60457. ExpectIntEQ(SHA_Init(&sha.compat), 1);
  60458. /* Do Transform*/
  60459. sLen = (word32)XSTRLEN((char*)input1);
  60460. XMEMCPY(local, input1, sLen);
  60461. ExpectIntEQ(SHA_Transform(&sha.compat, (const byte*)&local[0]), 1);
  60462. ExpectIntEQ(XMEMCMP(sha.native.digest, output1, WC_SHA_DIGEST_SIZE), 0);
  60463. ExpectIntEQ(SHA_Final(local, &sha.compat), 1); /* frees resources */
  60464. /* Init SHA CTX */
  60465. ExpectIntEQ(SHA_Init(&sha.compat), 1);
  60466. sLen = (word32)XSTRLEN((char*)input2);
  60467. XMEMSET(local, 0, WC_SHA_BLOCK_SIZE);
  60468. XMEMCPY(local, input2, sLen);
  60469. ExpectIntEQ(SHA_Transform(&sha.compat, (const byte*)&local[0]), 1);
  60470. ExpectIntEQ(XMEMCMP(sha.native.digest, output2, WC_SHA_DIGEST_SIZE), 0);
  60471. ExpectIntEQ(SHA_Final(local, &sha.compat), 1); /* frees resources */
  60472. /* SHA1 */
  60473. XMEMSET(local, 0, WC_SHA_BLOCK_SIZE);
  60474. /* Init SHA CTX */
  60475. ExpectIntEQ(SHA1_Init(&sha1.compat), 1);
  60476. /* Do Transform*/
  60477. sLen = (word32)XSTRLEN((char*)input1);
  60478. XMEMCPY(local, input1, sLen);
  60479. ExpectIntEQ(SHA1_Transform(&sha1.compat, (const byte*)&local[0]), 1);
  60480. ExpectIntEQ(XMEMCMP(sha1.native.digest, output1, WC_SHA_DIGEST_SIZE), 0);
  60481. ExpectIntEQ(SHA1_Final(local, &sha1.compat), 1); /* frees resources */
  60482. /* Init SHA CTX */
  60483. ExpectIntEQ(SHA1_Init(&sha1.compat), 1);
  60484. sLen = (word32)XSTRLEN((char*)input2);
  60485. XMEMSET(local, 0, WC_SHA_BLOCK_SIZE);
  60486. XMEMCPY(local, input2, sLen);
  60487. ExpectIntEQ(SHA1_Transform(&sha1.compat, (const byte*)&local[0]), 1);
  60488. ExpectIntEQ(XMEMCMP(sha1.native.digest, output2, WC_SHA_DIGEST_SIZE), 0);
  60489. ExpectIntEQ(SHA_Final(local, &sha1.compat), 1); /* frees resources */
  60490. #endif
  60491. #endif
  60492. return EXPECT_RESULT();
  60493. }
  60494. static int test_wolfSSL_SHA224(void)
  60495. {
  60496. EXPECT_DECLS;
  60497. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA224) && \
  60498. !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  60499. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2))
  60500. unsigned char input[] =
  60501. "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  60502. unsigned char output[] =
  60503. "\x75\x38\x8b\x16\x51\x27\x76\xcc\x5d\xba\x5d\xa1\xfd\x89\x01"
  60504. "\x50\xb0\xc6\x45\x5c\xb4\xf5\x8b\x19\x52\x52\x25\x25";
  60505. size_t inLen;
  60506. byte hash[WC_SHA224_DIGEST_SIZE];
  60507. unsigned char* p = NULL;
  60508. inLen = XSTRLEN((char*)input);
  60509. XMEMSET(hash, 0, WC_SHA224_DIGEST_SIZE);
  60510. ExpectNull(SHA224(NULL, inLen, hash));
  60511. ExpectNotNull(SHA224(input, 0, hash));
  60512. ExpectNotNull(SHA224(input, inLen, NULL));
  60513. ExpectNotNull(SHA224(NULL, 0, hash));
  60514. ExpectNotNull(SHA224(NULL, 0, NULL));
  60515. ExpectNotNull(SHA224(input, inLen, hash));
  60516. ExpectIntEQ(XMEMCMP(hash, output, WC_SHA224_DIGEST_SIZE), 0);
  60517. ExpectNotNull(p = SHA224(input, inLen, NULL));
  60518. ExpectIntEQ(XMEMCMP(p, output, WC_SHA224_DIGEST_SIZE), 0);
  60519. #endif
  60520. return EXPECT_RESULT();
  60521. }
  60522. static int test_wolfSSL_SHA256(void)
  60523. {
  60524. EXPECT_DECLS;
  60525. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA256) && \
  60526. defined(NO_OLD_SHA_NAMES) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  60527. unsigned char input[] =
  60528. "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  60529. unsigned char output[] =
  60530. "\x24\x8D\x6A\x61\xD2\x06\x38\xB8\xE5\xC0\x26\x93\x0C\x3E\x60"
  60531. "\x39\xA3\x3C\xE4\x59\x64\xFF\x21\x67\xF6\xEC\xED\xD4\x19\xDB"
  60532. "\x06\xC1";
  60533. size_t inLen;
  60534. byte hash[WC_SHA256_DIGEST_SIZE];
  60535. inLen = XSTRLEN((char*)input);
  60536. XMEMSET(hash, 0, WC_SHA256_DIGEST_SIZE);
  60537. ExpectNotNull(SHA256(input, inLen, hash));
  60538. ExpectIntEQ(XMEMCMP(hash, output, WC_SHA256_DIGEST_SIZE), 0);
  60539. #endif
  60540. return EXPECT_RESULT();
  60541. }
  60542. static int test_wolfSSL_SHA256_Transform(void)
  60543. {
  60544. EXPECT_DECLS;
  60545. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA256)
  60546. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  60547. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) && \
  60548. !defined(WOLFSSL_DEVCRYPTO_HASH) && !defined(WOLFSSL_AFALG_HASH) && \
  60549. !defined(WOLFSSL_KCAPI_HASH)
  60550. byte input1[] = "";
  60551. byte input2[] = "abc";
  60552. byte local[WC_SHA256_BLOCK_SIZE];
  60553. word32 sLen = 0;
  60554. #ifdef BIG_ENDIAN_ORDER
  60555. unsigned char output1[] =
  60556. "\xda\x56\x98\xbe\x17\xb9\xb4\x69\x62\x33\x57\x99\x77\x9f\xbe\xca"
  60557. "\x8c\xe5\xd4\x91\xc0\xd2\x62\x43\xba\xfe\xf9\xea\x18\x37\xa9\xd8";
  60558. unsigned char output2[] =
  60559. "\x1d\x4e\xd4\x67\x67\x7c\x61\x67\x44\x10\x76\x26\x78\x10\xff\xb8"
  60560. "\x40\xc8\x9a\x39\x73\x16\x60\x8c\xa6\x61\xd6\x05\x91\xf2\x8c\x35";
  60561. #else
  60562. unsigned char output1[] =
  60563. "\xbe\x98\x56\xda\x69\xb4\xb9\x17\x99\x57\x33\x62\xca\xbe\x9f\x77"
  60564. "\x91\xd4\xe5\x8c\x43\x62\xd2\xc0\xea\xf9\xfe\xba\xd8\xa9\x37\x18";
  60565. unsigned char output2[] =
  60566. "\x67\xd4\x4e\x1d\x67\x61\x7c\x67\x26\x76\x10\x44\xb8\xff\x10\x78"
  60567. "\x39\x9a\xc8\x40\x8c\x60\x16\x73\x05\xd6\x61\xa6\x35\x8c\xf2\x91";
  60568. #endif
  60569. union {
  60570. wc_Sha256 native;
  60571. SHA256_CTX compat;
  60572. } sha256;
  60573. XMEMSET(&sha256.compat, 0, sizeof(sha256.compat));
  60574. XMEMSET(&local, 0, sizeof(local));
  60575. /* sanity check */
  60576. ExpectIntEQ(SHA256_Transform(NULL, NULL), 0);
  60577. ExpectIntEQ(SHA256_Transform(NULL, (const byte*)&input1), 0);
  60578. ExpectIntEQ(SHA256_Transform(&sha256.compat, NULL), 0);
  60579. ExpectIntEQ(wc_Sha256Transform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60580. ExpectIntEQ(wc_Sha256Transform(NULL, (const byte*)&input1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60581. ExpectIntEQ(wc_Sha256Transform(&sha256.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60582. /* Init SHA256 CTX */
  60583. ExpectIntEQ(SHA256_Init(&sha256.compat), 1);
  60584. /* Do Transform*/
  60585. sLen = (word32)XSTRLEN((char*)input1);
  60586. XMEMCPY(local, input1, sLen);
  60587. ExpectIntEQ(SHA256_Transform(&sha256.compat, (const byte*)&local[0]), 1);
  60588. ExpectIntEQ(XMEMCMP(sha256.native.digest, output1, WC_SHA256_DIGEST_SIZE),
  60589. 0);
  60590. ExpectIntEQ(SHA256_Final(local, &sha256.compat), 1); /* frees resources */
  60591. /* Init SHA256 CTX */
  60592. ExpectIntEQ(SHA256_Init(&sha256.compat), 1);
  60593. sLen = (word32)XSTRLEN((char*)input2);
  60594. XMEMSET(local, 0, WC_SHA256_BLOCK_SIZE);
  60595. XMEMCPY(local, input2, sLen);
  60596. ExpectIntEQ(SHA256_Transform(&sha256.compat, (const byte*)&local[0]), 1);
  60597. ExpectIntEQ(XMEMCMP(sha256.native.digest, output2, WC_SHA256_DIGEST_SIZE),
  60598. 0);
  60599. ExpectIntEQ(SHA256_Final(local, &sha256.compat), 1); /* frees resources */
  60600. #endif
  60601. #endif
  60602. return EXPECT_RESULT();
  60603. }
  60604. static int test_wolfSSL_SHA512_Transform(void)
  60605. {
  60606. EXPECT_DECLS;
  60607. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA512)
  60608. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  60609. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) && \
  60610. !defined(WOLFSSL_KCAPI_HASH)
  60611. byte input1[] = "";
  60612. byte input2[] = "abc";
  60613. byte local[WC_SHA512_BLOCK_SIZE];
  60614. word32 sLen = 0;
  60615. #ifdef BIG_ENDIAN_ORDER
  60616. unsigned char output1[] =
  60617. "\xcf\x78\x81\xd5\x77\x4a\xcb\xe8\x53\x33\x62\xe0\xfb\xc7\x80\x70"
  60618. "\x02\x67\x63\x9d\x87\x46\x0e\xda\x30\x86\xcb\x40\xe8\x59\x31\xb0"
  60619. "\x71\x7d\xc9\x52\x88\xa0\x23\xa3\x96\xba\xb2\xc1\x4c\xe0\xb5\xe0"
  60620. "\x6f\xc4\xfe\x04\xea\xe3\x3e\x0b\x91\xf4\xd8\x0c\xbd\x66\x8b\xee";
  60621. unsigned char output2[] =
  60622. "\x11\x10\x93\x4e\xeb\xa0\xcc\x0d\xfd\x33\x43\x9c\xfb\x04\xc8\x21"
  60623. "\xa9\xb4\x26\x3d\xca\xab\x31\x41\xe2\xc6\xaa\xaf\xe1\x67\xd7\xab"
  60624. "\x31\x8f\x2e\x54\x2c\xba\x4e\x83\xbe\x88\xec\x9d\x8f\x2b\x38\x98"
  60625. "\x14\xd2\x4e\x9d\x53\x8b\x5e\x4d\xde\x68\x6c\x69\xaf\x20\x96\xf0";
  60626. #else
  60627. unsigned char output1[] =
  60628. "\xe8\xcb\x4a\x77\xd5\x81\x78\xcf\x70\x80\xc7\xfb\xe0\x62\x33\x53"
  60629. "\xda\x0e\x46\x87\x9d\x63\x67\x02\xb0\x31\x59\xe8\x40\xcb\x86\x30"
  60630. "\xa3\x23\xa0\x88\x52\xc9\x7d\x71\xe0\xb5\xe0\x4c\xc1\xb2\xba\x96"
  60631. "\x0b\x3e\xe3\xea\x04\xfe\xc4\x6f\xee\x8b\x66\xbd\x0c\xd8\xf4\x91";
  60632. unsigned char output2[] =
  60633. "\x0d\xcc\xa0\xeb\x4e\x93\x10\x11\x21\xc8\x04\xfb\x9c\x43\x33\xfd"
  60634. "\x41\x31\xab\xca\x3d\x26\xb4\xa9\xab\xd7\x67\xe1\xaf\xaa\xc6\xe2"
  60635. "\x83\x4e\xba\x2c\x54\x2e\x8f\x31\x98\x38\x2b\x8f\x9d\xec\x88\xbe"
  60636. "\x4d\x5e\x8b\x53\x9d\x4e\xd2\x14\xf0\x96\x20\xaf\x69\x6c\x68\xde";
  60637. #endif
  60638. union {
  60639. wc_Sha512 native;
  60640. SHA512_CTX compat;
  60641. } sha512;
  60642. XMEMSET(&sha512.compat, 0, sizeof(sha512.compat));
  60643. XMEMSET(&local, 0, sizeof(local));
  60644. /* sanity check */
  60645. ExpectIntEQ(SHA512_Transform(NULL, NULL), 0);
  60646. ExpectIntEQ(SHA512_Transform(NULL, (const byte*)&input1), 0);
  60647. ExpectIntEQ(SHA512_Transform(&sha512.compat, NULL), 0);
  60648. ExpectIntEQ(wc_Sha512Transform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60649. ExpectIntEQ(wc_Sha512Transform(NULL, (const byte*)&input1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60650. ExpectIntEQ(wc_Sha512Transform(&sha512.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60651. /* Init SHA512 CTX */
  60652. ExpectIntEQ(wolfSSL_SHA512_Init(&sha512.compat), 1);
  60653. /* Do Transform*/
  60654. sLen = (word32)XSTRLEN((char*)input1);
  60655. XMEMCPY(local, input1, sLen);
  60656. ExpectIntEQ(SHA512_Transform(&sha512.compat, (const byte*)&local[0]), 1);
  60657. ExpectIntEQ(XMEMCMP(sha512.native.digest, output1,
  60658. WC_SHA512_DIGEST_SIZE), 0);
  60659. ExpectIntEQ(SHA512_Final(local, &sha512.compat), 1); /* frees resources */
  60660. /* Init SHA512 CTX */
  60661. ExpectIntEQ(SHA512_Init(&sha512.compat), 1);
  60662. sLen = (word32)XSTRLEN((char*)input2);
  60663. XMEMSET(local, 0, WC_SHA512_BLOCK_SIZE);
  60664. XMEMCPY(local, input2, sLen);
  60665. ExpectIntEQ(SHA512_Transform(&sha512.compat, (const byte*)&local[0]), 1);
  60666. ExpectIntEQ(XMEMCMP(sha512.native.digest, output2,
  60667. WC_SHA512_DIGEST_SIZE), 0);
  60668. ExpectIntEQ(SHA512_Final(local, &sha512.compat), 1); /* frees resources */
  60669. (void)input1;
  60670. #endif
  60671. #endif
  60672. return EXPECT_RESULT();
  60673. }
  60674. static int test_wolfSSL_SHA512_224_Transform(void)
  60675. {
  60676. EXPECT_DECLS;
  60677. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA512) && \
  60678. !defined(WOLFSSL_NOSHA512_224)
  60679. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  60680. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) && \
  60681. !defined(WOLFSSL_KCAPI_HASH)
  60682. byte input1[] = "";
  60683. byte input2[] = "abc";
  60684. byte local[WC_SHA512_BLOCK_SIZE];
  60685. word32 sLen = 0;
  60686. unsigned char output1[] =
  60687. "\x94\x24\x66\xd4\x60\x3a\xeb\x23\x1d\xa8\x69\x31\x3c\xd2\xde\x11"
  60688. "\x48\x0f\x4a\x5a\xdf\x3a\x8d\x87\xcf\xcd\xbf\xa5\x03\x21\x50\xf1"
  60689. "\x8a\x0d\x0f\x0d\x3c\x07\xba\x52\xe0\xaa\x3c\xbb\xf1\xd3\x3f\xca"
  60690. "\x12\xa7\x61\xf8\x47\xda\x0d\x1b\x79\xc2\x65\x13\x92\xc1\x9c\xa5";
  60691. unsigned char output2[] =
  60692. "\x51\x28\xe7\x0b\xca\x1e\xbc\x5f\xd7\x34\x0b\x48\x30\xd7\xc2\x75"
  60693. "\x6d\x8d\x48\x2c\x1f\xc7\x9e\x2b\x20\x5e\xbb\x0f\x0e\x4d\xb7\x61"
  60694. "\x31\x76\x33\xa0\xb4\x3d\x5f\x93\xc1\x73\xac\xf7\x21\xff\x69\x17"
  60695. "\xce\x66\xe5\x1e\x31\xe7\xf3\x22\x0f\x0b\x34\xd7\x5a\x57\xeb\xbf";
  60696. union {
  60697. wc_Sha512 native;
  60698. SHA512_CTX compat;
  60699. } sha512;
  60700. #ifdef BIG_ENDIAN_ORDER
  60701. ByteReverseWords64((word64*)output1, (word64*)output1, sizeof(output1));
  60702. ByteReverseWords64((word64*)output2, (word64*)output2, sizeof(output2));
  60703. #endif
  60704. XMEMSET(&sha512.compat, 0, sizeof(sha512.compat));
  60705. XMEMSET(&local, 0, sizeof(local));
  60706. /* sanity check */
  60707. ExpectIntEQ(SHA512_224_Transform(NULL, NULL), 0);
  60708. ExpectIntEQ(SHA512_224_Transform(NULL, (const byte*)&input1), 0);
  60709. ExpectIntEQ(SHA512_224_Transform(&sha512.compat, NULL), 0);
  60710. ExpectIntEQ(wc_Sha512_224Transform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60711. ExpectIntEQ(wc_Sha512_224Transform(NULL, (const byte*)&input1),
  60712. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60713. ExpectIntEQ(wc_Sha512_224Transform(&sha512.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60714. /* Init SHA512 CTX */
  60715. ExpectIntEQ(wolfSSL_SHA512_224_Init(&sha512.compat), 1);
  60716. /* Do Transform*/
  60717. sLen = (word32)XSTRLEN((char*)input1);
  60718. XMEMCPY(local, input1, sLen);
  60719. ExpectIntEQ(SHA512_224_Transform(&sha512.compat, (const byte*)&local[0]),
  60720. 1);
  60721. ExpectIntEQ(XMEMCMP(sha512.native.digest, output1,
  60722. WC_SHA512_DIGEST_SIZE), 0);
  60723. /* frees resources */
  60724. ExpectIntEQ(SHA512_224_Final(local, &sha512.compat), 1);
  60725. /* Init SHA512 CTX */
  60726. ExpectIntEQ(SHA512_224_Init(&sha512.compat), 1);
  60727. sLen = (word32)XSTRLEN((char*)input2);
  60728. XMEMSET(local, 0, WC_SHA512_BLOCK_SIZE);
  60729. XMEMCPY(local, input2, sLen);
  60730. ExpectIntEQ(SHA512_224_Transform(&sha512.compat, (const byte*)&local[0]),
  60731. 1);
  60732. ExpectIntEQ(XMEMCMP(sha512.native.digest, output2,
  60733. WC_SHA512_DIGEST_SIZE), 0);
  60734. /* frees resources */
  60735. ExpectIntEQ(SHA512_224_Final(local, &sha512.compat), 1);
  60736. #endif
  60737. #endif
  60738. return EXPECT_RESULT();
  60739. }
  60740. static int test_wolfSSL_SHA512_256_Transform(void)
  60741. {
  60742. EXPECT_DECLS;
  60743. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA512) && \
  60744. !defined(WOLFSSL_NOSHA512_256)
  60745. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  60746. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))) && \
  60747. !defined(WOLFSSL_KCAPI_HASH)
  60748. byte input1[] = "";
  60749. byte input2[] = "abc";
  60750. byte local[WC_SHA512_BLOCK_SIZE];
  60751. word32 sLen = 0;
  60752. unsigned char output1[] =
  60753. "\xf8\x37\x37\x5a\xd7\x2e\x56\xec\xe2\x51\xa8\x31\x3a\xa0\x63\x2b"
  60754. "\x7e\x7c\x64\xcc\xd9\xff\x2b\x6b\xeb\xc3\xd4\x4d\x7f\x8a\x3a\xb5"
  60755. "\x61\x85\x0b\x37\x30\x9f\x3b\x08\x5e\x7b\xd3\xbc\x6d\x00\x61\xc0"
  60756. "\x65\x9a\xd7\x73\xda\x40\xbe\xc1\xe5\x2f\xc6\x5d\xb7\x9f\xbe\x60";
  60757. unsigned char output2[] =
  60758. "\x22\xad\xc0\x30\xee\xd4\x6a\xef\x13\xee\x5a\x95\x8b\x1f\xb7\xb6"
  60759. "\xb6\xba\xc0\x44\xb8\x18\x3b\xf0\xf6\x4b\x70\x9f\x03\xba\x64\xa1"
  60760. "\xe1\xe3\x45\x15\x91\x7d\xcb\x0b\x9a\xf0\xd2\x8e\x47\x8b\x37\x78"
  60761. "\x91\x41\xa6\xc4\xb0\x29\x8f\x8b\xdd\x78\x5c\xf2\x73\x3f\x21\x31";
  60762. union {
  60763. wc_Sha512 native;
  60764. SHA512_CTX compat;
  60765. } sha512;
  60766. #ifdef BIG_ENDIAN_ORDER
  60767. ByteReverseWords64((word64*)output1, (word64*)output1, sizeof(output1));
  60768. ByteReverseWords64((word64*)output2, (word64*)output2, sizeof(output2));
  60769. #endif
  60770. XMEMSET(&sha512.compat, 0, sizeof(sha512.compat));
  60771. XMEMSET(&local, 0, sizeof(local));
  60772. /* sanity check */
  60773. ExpectIntEQ(SHA512_256_Transform(NULL, NULL), 0);
  60774. ExpectIntEQ(SHA512_256_Transform(NULL, (const byte*)&input1), 0);
  60775. ExpectIntEQ(SHA512_256_Transform(&sha512.compat, NULL), 0);
  60776. ExpectIntEQ(wc_Sha512_256Transform(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60777. ExpectIntEQ(wc_Sha512_256Transform(NULL, (const byte*)&input1),
  60778. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60779. ExpectIntEQ(wc_Sha512_256Transform(&sha512.native, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  60780. /* Init SHA512 CTX */
  60781. ExpectIntEQ(wolfSSL_SHA512_256_Init(&sha512.compat), 1);
  60782. /* Do Transform*/
  60783. sLen = (word32)XSTRLEN((char*)input1);
  60784. XMEMCPY(local, input1, sLen);
  60785. ExpectIntEQ(SHA512_256_Transform(&sha512.compat, (const byte*)&local[0]),
  60786. 1);
  60787. ExpectIntEQ(XMEMCMP(sha512.native.digest, output1,
  60788. WC_SHA512_DIGEST_SIZE), 0);
  60789. /* frees resources */
  60790. ExpectIntEQ(SHA512_256_Final(local, &sha512.compat), 1);
  60791. /* Init SHA512 CTX */
  60792. ExpectIntEQ(SHA512_256_Init(&sha512.compat), 1);
  60793. sLen = (word32)XSTRLEN((char*)input2);
  60794. XMEMSET(local, 0, WC_SHA512_BLOCK_SIZE);
  60795. XMEMCPY(local, input2, sLen);
  60796. ExpectIntEQ(SHA512_256_Transform(&sha512.compat, (const byte*)&local[0]),
  60797. 1);
  60798. ExpectIntEQ(XMEMCMP(sha512.native.digest, output2,
  60799. WC_SHA512_DIGEST_SIZE), 0);
  60800. /* frees resources */
  60801. ExpectIntEQ(SHA512_256_Final(local, &sha512.compat), 1);
  60802. #endif
  60803. #endif
  60804. return EXPECT_RESULT();
  60805. }
  60806. #if defined(OPENSSL_EXTRA) && !defined(NO_HMAC)
  60807. /* helper function for test_wolfSSL_HMAC_CTX, digest size is expected to be a
  60808. * buffer of 64 bytes.
  60809. *
  60810. * returns the size of the digest buffer on success and a negative value on
  60811. * failure.
  60812. */
  60813. static int test_HMAC_CTX_helper(const EVP_MD* type, unsigned char* digest,
  60814. int* sz)
  60815. {
  60816. EXPECT_DECLS;
  60817. HMAC_CTX ctx1;
  60818. HMAC_CTX ctx2;
  60819. unsigned char key[] = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  60820. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
  60821. unsigned char long_key[] =
  60822. "0123456789012345678901234567890123456789"
  60823. "0123456789012345678901234567890123456789"
  60824. "0123456789012345678901234567890123456789"
  60825. "0123456789012345678901234567890123456789";
  60826. unsigned char msg[] = "message to hash";
  60827. unsigned int digestSz = 64;
  60828. int keySz = sizeof(key);
  60829. int long_keySz = sizeof(long_key);
  60830. int msgSz = sizeof(msg);
  60831. unsigned char digest2[64];
  60832. unsigned int digestSz2 = 64;
  60833. HMAC_CTX_init(&ctx1);
  60834. ExpectIntEQ(HMAC_Init(&ctx1, (const void*)key, keySz, type), SSL_SUCCESS);
  60835. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  60836. ExpectIntEQ(HMAC_CTX_copy(&ctx2, &ctx1), SSL_SUCCESS);
  60837. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  60838. ExpectIntEQ(HMAC_Final(&ctx1, digest, &digestSz), SSL_SUCCESS);
  60839. HMAC_CTX_cleanup(&ctx1);
  60840. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  60841. ExpectIntEQ(HMAC_Final(&ctx2, digest2, &digestSz2), SSL_SUCCESS);
  60842. HMAC_CTX_cleanup(&ctx2);
  60843. ExpectIntEQ(digestSz, digestSz2);
  60844. ExpectIntEQ(XMEMCMP(digest, digest2, digestSz), 0);
  60845. /* test HMAC_Init with NULL key */
  60846. /* init after copy */
  60847. HMAC_CTX_init(&ctx1);
  60848. ExpectIntEQ(HMAC_Init(&ctx1, (const void*)key, keySz, type), SSL_SUCCESS);
  60849. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  60850. ExpectIntEQ(HMAC_CTX_copy(&ctx2, &ctx1), SSL_SUCCESS);
  60851. ExpectIntEQ(HMAC_Init(&ctx1, NULL, 0, NULL), SSL_SUCCESS);
  60852. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  60853. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  60854. ExpectIntEQ(HMAC_Final(&ctx1, digest, &digestSz), SSL_SUCCESS);
  60855. HMAC_CTX_cleanup(&ctx1);
  60856. ExpectIntEQ(HMAC_Init(&ctx2, NULL, 0, NULL), SSL_SUCCESS);
  60857. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  60858. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  60859. ExpectIntEQ(HMAC_Final(&ctx2, digest2, &digestSz), SSL_SUCCESS);
  60860. HMAC_CTX_cleanup(&ctx2);
  60861. ExpectIntEQ(digestSz, digestSz2);
  60862. ExpectIntEQ(XMEMCMP(digest, digest2, digestSz), 0);
  60863. /* long key */
  60864. HMAC_CTX_init(&ctx1);
  60865. ExpectIntEQ(HMAC_Init(&ctx1, (const void*)long_key, long_keySz, type),
  60866. SSL_SUCCESS);
  60867. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  60868. ExpectIntEQ(HMAC_CTX_copy(&ctx2, &ctx1), SSL_SUCCESS);
  60869. ExpectIntEQ(HMAC_Init(&ctx1, NULL, 0, NULL), SSL_SUCCESS);
  60870. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  60871. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  60872. ExpectIntEQ(HMAC_Final(&ctx1, digest, &digestSz), SSL_SUCCESS);
  60873. HMAC_CTX_cleanup(&ctx1);
  60874. ExpectIntEQ(HMAC_Init(&ctx2, NULL, 0, NULL), SSL_SUCCESS);
  60875. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  60876. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  60877. ExpectIntEQ(HMAC_Final(&ctx2, digest2, &digestSz), SSL_SUCCESS);
  60878. HMAC_CTX_cleanup(&ctx2);
  60879. ExpectIntEQ(digestSz, digestSz2);
  60880. ExpectIntEQ(XMEMCMP(digest, digest2, digestSz), 0);
  60881. /* init before copy */
  60882. HMAC_CTX_init(&ctx1);
  60883. ExpectIntEQ(HMAC_Init(&ctx1, (const void*)key, keySz, type), SSL_SUCCESS);
  60884. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  60885. ExpectIntEQ(HMAC_Init(&ctx1, NULL, 0, NULL), SSL_SUCCESS);
  60886. ExpectIntEQ(HMAC_CTX_copy(&ctx2, &ctx1), SSL_SUCCESS);
  60887. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  60888. ExpectIntEQ(HMAC_Update(&ctx1, msg, msgSz), SSL_SUCCESS);
  60889. ExpectIntEQ(HMAC_Final(&ctx1, digest, &digestSz), SSL_SUCCESS);
  60890. HMAC_CTX_cleanup(&ctx1);
  60891. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  60892. ExpectIntEQ(HMAC_Update(&ctx2, msg, msgSz), SSL_SUCCESS);
  60893. ExpectIntEQ(HMAC_Final(&ctx2, digest2, &digestSz), SSL_SUCCESS);
  60894. HMAC_CTX_cleanup(&ctx2);
  60895. ExpectIntEQ(digestSz, digestSz2);
  60896. ExpectIntEQ(XMEMCMP(digest, digest2, digestSz), 0);
  60897. *sz = (int)digestSz;
  60898. return EXPECT_RESULT();
  60899. }
  60900. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_HMAC) */
  60901. static int test_wolfSSL_HMAC_CTX(void)
  60902. {
  60903. EXPECT_DECLS;
  60904. #if defined(OPENSSL_EXTRA) && !defined(NO_HMAC)
  60905. unsigned char digest[64];
  60906. int digestSz;
  60907. WOLFSSL_HMAC_CTX* hmac_ctx = NULL;
  60908. WOLFSSL_HMAC_CTX ctx1;
  60909. WOLFSSL_HMAC_CTX ctx2;
  60910. ExpectNotNull(hmac_ctx = wolfSSL_HMAC_CTX_new());
  60911. ExpectIntEQ(wolfSSL_HMAC_CTX_Init(NULL), 1);
  60912. ExpectIntEQ(wolfSSL_HMAC_CTX_Init(hmac_ctx), 1);
  60913. wolfSSL_HMAC_CTX_free(NULL);
  60914. wolfSSL_HMAC_CTX_free(hmac_ctx);
  60915. XMEMSET(&ctx2, 0, sizeof(WOLFSSL_HMAC_CTX));
  60916. ExpectIntEQ(HMAC_CTX_init(NULL), 1);
  60917. ExpectIntEQ(HMAC_CTX_init(&ctx2), 1);
  60918. ExpectIntEQ(HMAC_CTX_copy(NULL, NULL), 0);
  60919. ExpectIntEQ(HMAC_CTX_copy(NULL, &ctx2), 0);
  60920. ExpectIntEQ(HMAC_CTX_copy(&ctx2, NULL), 0);
  60921. #if defined(HAVE_SELFTEST) || (defined(HAVE_FIPS) && \
  60922. ((! defined(HAVE_FIPS_VERSION)) || \
  60923. defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION <= 2)))
  60924. /* Copy object that hasn't had a digest set - MD5. */
  60925. ExpectIntEQ(HMAC_CTX_copy(&ctx1, &ctx2), 1);
  60926. #else
  60927. /* Copy object that hasn't had a digest set. */
  60928. ExpectIntEQ(HMAC_CTX_copy(&ctx1, &ctx2), 0);
  60929. #endif
  60930. HMAC_CTX_cleanup(NULL);
  60931. HMAC_CTX_cleanup(&ctx2);
  60932. ExpectNull(HMAC_CTX_get_md(NULL));
  60933. #ifndef NO_SHA
  60934. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha1(), digest, &digestSz)),
  60935. TEST_SUCCESS);
  60936. ExpectIntEQ(digestSz, 20);
  60937. ExpectIntEQ(XMEMCMP("\xD9\x68\x77\x23\x70\xFB\x53\x70\x53\xBA\x0E\xDC\xDA"
  60938. "\xBF\x03\x98\x31\x19\xB2\xCC", digest, digestSz), 0);
  60939. #endif /* !NO_SHA */
  60940. #ifdef WOLFSSL_SHA224
  60941. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha224(), digest, &digestSz)),
  60942. TEST_SUCCESS);
  60943. ExpectIntEQ(digestSz, 28);
  60944. ExpectIntEQ(XMEMCMP("\x57\xFD\xF4\xE1\x2D\xB0\x79\xD7\x4B\x25\x7E\xB1\x95"
  60945. "\x9C\x11\xAC\x2D\x1E\x78\x94\x4F\x3A\x0F\xED\xF8\xAD"
  60946. "\x02\x0E", digest, digestSz), 0);
  60947. #endif /* WOLFSSL_SHA224 */
  60948. #ifndef NO_SHA256
  60949. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha256(), digest, &digestSz)),
  60950. TEST_SUCCESS);
  60951. ExpectIntEQ(digestSz, 32);
  60952. ExpectIntEQ(XMEMCMP("\x13\xAB\x76\x91\x0C\x37\x86\x8D\xB3\x7E\x30\x0C\xFC"
  60953. "\xB0\x2E\x8E\x4A\xD7\xD4\x25\xCC\x3A\xA9\x0F\xA2\xF2"
  60954. "\x47\x1E\x62\x6F\x5D\xF2", digest, digestSz), 0);
  60955. #endif /* !NO_SHA256 */
  60956. #ifdef WOLFSSL_SHA384
  60957. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha384(), digest, &digestSz)),
  60958. TEST_SUCCESS);
  60959. ExpectIntEQ(digestSz, 48);
  60960. ExpectIntEQ(XMEMCMP("\x9E\xCB\x07\x0C\x11\x76\x3F\x23\xC3\x25\x0E\xC4\xB7"
  60961. "\x28\x77\x95\x99\xD5\x9D\x7A\xBB\x1A\x9F\xB7\xFD\x25"
  60962. "\xC9\x72\x47\x9F\x8F\x86\x76\xD6\x20\x57\x87\xB7\xE7"
  60963. "\xCD\xFB\xC2\xCC\x9F\x2B\xC5\x41\xAB",
  60964. digest, digestSz), 0);
  60965. #endif /* WOLFSSL_SHA384 */
  60966. #ifdef WOLFSSL_SHA512
  60967. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha512(), digest, &digestSz)),
  60968. TEST_SUCCESS);
  60969. ExpectIntEQ(digestSz, 64);
  60970. ExpectIntEQ(XMEMCMP("\xD4\x21\x0C\x8B\x60\x6F\xF4\xBF\x07\x2F\x26\xCC\xAD"
  60971. "\xBC\x06\x0B\x34\x78\x8B\x4F\xD6\xC0\x42\xF1\x33\x10"
  60972. "\x6C\x4F\x1E\x55\x59\xDD\x2A\x9F\x15\x88\x62\xF8\x60"
  60973. "\xA3\x99\x91\xE2\x08\x7B\xF7\x95\x3A\xB0\x92\x48\x60"
  60974. "\x88\x8B\x5B\xB8\x5F\xE9\xB6\xB1\x96\xE3\xB5\xF0",
  60975. digest, digestSz), 0);
  60976. #endif /* WOLFSSL_SHA512 */
  60977. #ifdef WOLFSSL_SHA3
  60978. #ifndef WOLFSSL_NOSHA3_224
  60979. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha3_224(), digest, &digestSz)),
  60980. TEST_SUCCESS);
  60981. ExpectIntEQ(digestSz, 28);
  60982. ExpectIntEQ(XMEMCMP("\xdc\x53\x25\x3f\xc0\x9d\x2b\x0c\x7f\x59\x11\x17\x08"
  60983. "\x5c\xe8\x43\x31\x01\x5a\xb3\xe3\x08\x37\x71\x26\x0b"
  60984. "\x29\x0f", digest, digestSz), 0);
  60985. #endif
  60986. #ifndef WOLFSSL_NOSHA3_256
  60987. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha3_256(), digest, &digestSz)),
  60988. TEST_SUCCESS);
  60989. ExpectIntEQ(digestSz, 32);
  60990. ExpectIntEQ(XMEMCMP("\x0f\x00\x89\x82\x15\xce\xd6\x45\x01\x83\xce\xc8\x35"
  60991. "\xab\x71\x07\xc9\xfe\x61\x22\x38\xf9\x09\xad\x35\x65"
  60992. "\x43\x77\x24\xd4\x1e\xf4", digest, digestSz), 0);
  60993. #endif
  60994. #ifndef WOLFSSL_NOSHA3_384
  60995. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha3_384(), digest, &digestSz)),
  60996. TEST_SUCCESS);
  60997. ExpectIntEQ(digestSz, 48);
  60998. ExpectIntEQ(XMEMCMP("\x0f\x6a\xc0\xfb\xc3\xf2\x80\xb1\xb4\x04\xb6\xc8\x45"
  60999. "\x23\x3b\xb4\xbe\xc6\xea\x85\x07\xca\x8c\x71\xbb\x6e"
  61000. "\x79\xf6\xf9\x2b\x98\xf5\xef\x11\x39\xd4\x5d\xd3\xca"
  61001. "\xc0\xe6\x81\xf7\x73\xf9\x85\x5d\x4f",
  61002. digest, digestSz), 0);
  61003. #endif
  61004. #ifndef WOLFSSL_NOSHA3_512
  61005. ExpectIntEQ((test_HMAC_CTX_helper(EVP_sha3_512(), digest, &digestSz)),
  61006. TEST_SUCCESS);
  61007. ExpectIntEQ(digestSz, 64);
  61008. ExpectIntEQ(XMEMCMP("\x3e\x77\xe3\x59\x42\x89\xed\xc3\xa4\x26\x3d\xa4\x75"
  61009. "\xd2\x84\x8c\xb2\xf3\x25\x04\x47\x61\xce\x1c\x42\x86"
  61010. "\xcd\xf4\x56\xaa\x2f\x84\xb1\x3b\x18\xed\xe6\xd6\x48"
  61011. "\x15\xb0\x29\xc5\x9d\x32\xef\xdd\x3e\x09\xf6\xed\x9e"
  61012. "\x70\xbc\x1c\x63\xf7\x3b\x3e\xe1\xdc\x84\x9c\x1c",
  61013. digest, digestSz), 0);
  61014. #endif
  61015. #endif
  61016. #if !defined(NO_MD5) && (!defined(HAVE_FIPS_VERSION) || \
  61017. HAVE_FIPS_VERSION <= 2)
  61018. ExpectIntEQ((test_HMAC_CTX_helper(EVP_md5(), digest, &digestSz)),
  61019. TEST_SUCCESS);
  61020. ExpectIntEQ(digestSz, 16);
  61021. ExpectIntEQ(XMEMCMP("\xB7\x27\xC4\x41\xE5\x2E\x62\xBA\x54\xED\x72\x70\x9F"
  61022. "\xE4\x98\xDD", digest, digestSz), 0);
  61023. #endif /* !NO_MD5 */
  61024. #endif
  61025. return EXPECT_RESULT();
  61026. }
  61027. #if defined(OPENSSL_EXTRA) && (!defined(NO_SHA256) || \
  61028. defined(WOLFSSL_SHA224) || defined(WOLFSSL_SHA384) || \
  61029. defined(WOLFSSL_SHA512) || defined(WOLFSSL_SHA3))
  61030. static int test_openssl_hmac(const WOLFSSL_EVP_MD* md, int md_len)
  61031. {
  61032. EXPECT_DECLS;
  61033. static const unsigned char key[] = "simple test key";
  61034. HMAC_CTX* hmac = NULL;
  61035. ENGINE* e = NULL;
  61036. unsigned char hash[WC_MAX_DIGEST_SIZE];
  61037. unsigned int len;
  61038. ExpectNotNull(hmac = HMAC_CTX_new());
  61039. HMAC_CTX_init(hmac);
  61040. #if defined(HAVE_SELFTEST) || (defined(HAVE_FIPS) && \
  61041. ((! defined(HAVE_FIPS_VERSION)) || \
  61042. defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION <= 2)))
  61043. /* Get size on object that hasn't had a digest set - MD5. */
  61044. ExpectIntEQ(HMAC_size(hmac), 16);
  61045. ExpectIntEQ(HMAC_Init(hmac, NULL, 0, NULL), 1);
  61046. ExpectIntEQ(HMAC_Init(hmac, (void*)key, (int)sizeof(key), NULL), 1);
  61047. ExpectIntEQ(HMAC_Init(hmac, NULL, 0, md), 1);
  61048. #else
  61049. ExpectIntEQ(HMAC_size(hmac), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  61050. ExpectIntEQ(HMAC_Init(hmac, NULL, 0, NULL), 0);
  61051. ExpectIntEQ(HMAC_Init(hmac, (void*)key, (int)sizeof(key), NULL), 0);
  61052. ExpectIntEQ(HMAC_Init(hmac, NULL, 0, md), 0);
  61053. #endif
  61054. ExpectIntEQ(HMAC_Init_ex(NULL, (void*)key, (int)sizeof(key), md, e), 0);
  61055. ExpectIntEQ(HMAC_Init_ex(hmac, (void*)key, (int)sizeof(key), md, e), 1);
  61056. /* re-using test key as data to hash */
  61057. ExpectIntEQ(HMAC_Update(NULL, key, (int)sizeof(key)), 0);
  61058. ExpectIntEQ(HMAC_Update(hmac, key, (int)sizeof(key)), 1);
  61059. ExpectIntEQ(HMAC_Update(hmac, key, 0), 1);
  61060. ExpectIntEQ(HMAC_Update(hmac, NULL, 0), 1);
  61061. ExpectIntEQ(HMAC_Update(hmac, NULL, (int)sizeof(key)), 1);
  61062. ExpectIntEQ(HMAC_Final(NULL, NULL, &len), 0);
  61063. ExpectIntEQ(HMAC_Final(hmac, NULL, &len), 0);
  61064. ExpectIntEQ(HMAC_Final(NULL, hash, &len), 0);
  61065. ExpectIntEQ(HMAC_Final(hmac, hash, &len), 1);
  61066. ExpectIntEQ(HMAC_Final(hmac, hash, NULL), 1);
  61067. ExpectIntEQ(len, md_len);
  61068. ExpectIntEQ(HMAC_size(NULL), 0);
  61069. ExpectIntEQ(HMAC_size(hmac), md_len);
  61070. ExpectStrEQ(HMAC_CTX_get_md(hmac), md);
  61071. HMAC_cleanup(NULL);
  61072. HMAC_cleanup(hmac);
  61073. HMAC_CTX_free(hmac);
  61074. len = 0;
  61075. ExpectNull(HMAC(NULL, key, (int)sizeof(key), NULL, 0, hash, &len));
  61076. ExpectNull(HMAC(md, NULL, (int)sizeof(key), NULL, 0, hash, &len));
  61077. ExpectNull(HMAC(md, key, (int)sizeof(key), NULL, 0, NULL, &len));
  61078. ExpectNotNull(HMAC(md, key, (int)sizeof(key), NULL, 0, hash, &len));
  61079. ExpectIntEQ(len, md_len);
  61080. ExpectNotNull(HMAC(md, key, (int)sizeof(key), NULL, 0, hash, NULL));
  61081. /* With data. */
  61082. ExpectNotNull(HMAC(md, key, (int)sizeof(key), key, (int)sizeof(key), hash,
  61083. &len));
  61084. /* With NULL data. */
  61085. ExpectNull(HMAC(md, key, (int)sizeof(key), NULL, (int)sizeof(key), hash,
  61086. &len));
  61087. /* With zero length data. */
  61088. ExpectNotNull(HMAC(md, key, (int)sizeof(key), key, 0, hash, &len));
  61089. return EXPECT_RESULT();
  61090. }
  61091. #endif
  61092. static int test_wolfSSL_HMAC(void)
  61093. {
  61094. EXPECT_DECLS;
  61095. #if defined(OPENSSL_EXTRA) && (!defined(NO_SHA256) || \
  61096. defined(WOLFSSL_SHA224) || defined(WOLFSSL_SHA384) || \
  61097. defined(WOLFSSL_SHA512) || defined(WOLFSSL_SHA3))
  61098. #ifndef NO_SHA256
  61099. ExpectIntEQ(test_openssl_hmac(EVP_sha256(), (int)WC_SHA256_DIGEST_SIZE),
  61100. TEST_SUCCESS);
  61101. #endif
  61102. #ifdef WOLFSSL_SHA224
  61103. ExpectIntEQ(test_openssl_hmac(EVP_sha224(), (int)WC_SHA224_DIGEST_SIZE),
  61104. TEST_SUCCESS);
  61105. #endif
  61106. #ifdef WOLFSSL_SHA384
  61107. ExpectIntEQ(test_openssl_hmac(EVP_sha384(), (int)WC_SHA384_DIGEST_SIZE),
  61108. TEST_SUCCESS);
  61109. #endif
  61110. #ifdef WOLFSSL_SHA512
  61111. ExpectIntEQ(test_openssl_hmac(EVP_sha512(), (int)WC_SHA512_DIGEST_SIZE),
  61112. TEST_SUCCESS);
  61113. #endif
  61114. #ifdef WOLFSSL_SHA3
  61115. #ifndef WOLFSSL_NOSHA3_224
  61116. ExpectIntEQ(test_openssl_hmac(EVP_sha3_224(),
  61117. (int)WC_SHA3_224_DIGEST_SIZE), TEST_SUCCESS);
  61118. #endif
  61119. #ifndef WOLFSSL_NOSHA3_256
  61120. ExpectIntEQ(test_openssl_hmac(EVP_sha3_256(),
  61121. (int)WC_SHA3_256_DIGEST_SIZE), TEST_SUCCESS);
  61122. #endif
  61123. #ifndef WOLFSSL_NOSHA3_384
  61124. ExpectIntEQ(test_openssl_hmac(EVP_sha3_384(),
  61125. (int)WC_SHA3_384_DIGEST_SIZE), TEST_SUCCESS);
  61126. #endif
  61127. #ifndef WOLFSSL_NOSHA3_512
  61128. ExpectIntEQ(test_openssl_hmac(EVP_sha3_512(),
  61129. (int)WC_SHA3_512_DIGEST_SIZE), TEST_SUCCESS);
  61130. #endif
  61131. #endif
  61132. #ifndef NO_SHA
  61133. ExpectIntEQ(test_openssl_hmac(EVP_sha1(), (int)WC_SHA_DIGEST_SIZE),
  61134. TEST_SUCCESS);
  61135. #endif
  61136. #endif
  61137. return EXPECT_RESULT();
  61138. }
  61139. static int test_wolfSSL_CMAC(void)
  61140. {
  61141. EXPECT_DECLS;
  61142. #if defined(WOLFSSL_CMAC) && defined(OPENSSL_EXTRA) && \
  61143. defined(WOLFSSL_AES_DIRECT)
  61144. int i;
  61145. byte key[AES_256_KEY_SIZE];
  61146. CMAC_CTX* cmacCtx = NULL;
  61147. byte out[AES_BLOCK_SIZE];
  61148. size_t outLen = AES_BLOCK_SIZE;
  61149. for (i=0; i < AES_256_KEY_SIZE; ++i) {
  61150. key[i] = i;
  61151. }
  61152. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  61153. /* Check CMAC_CTX_get0_cipher_ctx; return value not used. */
  61154. ExpectNotNull(CMAC_CTX_get0_cipher_ctx(cmacCtx));
  61155. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_128_KEY_SIZE, EVP_aes_128_cbc(),
  61156. NULL), 1);
  61157. /* re-using test key as data to hash */
  61158. ExpectIntEQ(CMAC_Update(cmacCtx, key, AES_128_KEY_SIZE), 1);
  61159. ExpectIntEQ(CMAC_Update(cmacCtx, NULL, 0), 1);
  61160. ExpectIntEQ(CMAC_Final(cmacCtx, out, &outLen), 1);
  61161. ExpectIntEQ(outLen, AES_BLOCK_SIZE);
  61162. /* No Update works. */
  61163. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_128_KEY_SIZE, EVP_aes_128_cbc(),
  61164. NULL), 1);
  61165. ExpectIntEQ(CMAC_Final(cmacCtx, out, NULL), 1);
  61166. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_128_KEY_SIZE, EVP_aes_128_cbc(),
  61167. NULL), 1);
  61168. /* Test parameters with CMAC_Update. */
  61169. ExpectIntEQ(CMAC_Update(NULL, NULL, 0), 0);
  61170. ExpectIntEQ(CMAC_Update(NULL, key, 0), 0);
  61171. ExpectIntEQ(CMAC_Update(NULL, NULL, AES_128_KEY_SIZE), 0);
  61172. ExpectIntEQ(CMAC_Update(NULL, key, AES_128_KEY_SIZE), 0);
  61173. ExpectIntEQ(CMAC_Update(cmacCtx, key, 0), 1);
  61174. ExpectIntEQ(CMAC_Update(cmacCtx, NULL, 0), 1);
  61175. ExpectIntEQ(CMAC_Update(cmacCtx, NULL, AES_128_KEY_SIZE), 1);
  61176. /* Test parameters with CMAC_Final. */
  61177. ExpectIntEQ(CMAC_Final(NULL, NULL, NULL), 0);
  61178. ExpectIntEQ(CMAC_Final(NULL, out, NULL), 0);
  61179. ExpectIntEQ(CMAC_Final(NULL, NULL, &outLen), 0);
  61180. ExpectIntEQ(CMAC_Final(NULL, out, &outLen), 0);
  61181. ExpectIntEQ(CMAC_Final(cmacCtx, NULL, NULL), 1);
  61182. ExpectIntEQ(CMAC_Final(cmacCtx, NULL, &outLen), 1);
  61183. ExpectIntEQ(CMAC_Final(cmacCtx, out, NULL), 1);
  61184. CMAC_CTX_free(cmacCtx);
  61185. /* Test parameters with CMAC Init. */
  61186. cmacCtx = NULL;
  61187. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  61188. ExpectNotNull(CMAC_CTX_get0_cipher_ctx(cmacCtx));
  61189. ExpectIntEQ(CMAC_Init(NULL, NULL, 0, NULL, NULL), 0);
  61190. ExpectIntEQ(CMAC_Init(NULL, key, AES_192_KEY_SIZE, EVP_aes_192_cbc(),
  61191. NULL), 0);
  61192. ExpectIntEQ(CMAC_Init(cmacCtx, NULL, AES_192_KEY_SIZE, EVP_aes_192_cbc(),
  61193. NULL), 0);
  61194. /* give a key too small for the cipher, verify we get failure */
  61195. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_128_KEY_SIZE, EVP_aes_192_cbc(),
  61196. NULL), 0);
  61197. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_192_KEY_SIZE, NULL, NULL), 0);
  61198. #if defined(HAVE_AESGCM) && defined(WOLFSSL_AES_128)
  61199. /* Only AES-CBC supported. */
  61200. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_128_KEY_SIZE, EVP_aes_128_gcm(),
  61201. NULL), 0);
  61202. #endif
  61203. CMAC_CTX_free(cmacCtx);
  61204. ExpectNull(CMAC_CTX_get0_cipher_ctx(NULL));
  61205. cmacCtx = NULL;
  61206. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  61207. /* No Init. */
  61208. ExpectIntEQ(CMAC_Final(cmacCtx, out, &outLen), 0);
  61209. CMAC_CTX_free(cmacCtx);
  61210. /* Test AES-256-CBC */
  61211. cmacCtx = NULL;
  61212. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  61213. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_256_KEY_SIZE, EVP_aes_256_cbc(),
  61214. NULL), 1);
  61215. ExpectIntEQ(CMAC_Update(cmacCtx, key, AES_128_KEY_SIZE), 1);
  61216. ExpectIntEQ(CMAC_Final(cmacCtx, out, NULL), 1);
  61217. CMAC_CTX_free(cmacCtx);
  61218. /* Test AES-192-CBC */
  61219. cmacCtx = NULL;
  61220. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  61221. ExpectIntEQ(CMAC_Init(cmacCtx, key, AES_192_KEY_SIZE, EVP_aes_192_cbc(),
  61222. NULL), 1);
  61223. ExpectIntEQ(CMAC_Update(cmacCtx, key, AES_128_KEY_SIZE), 1);
  61224. ExpectIntEQ(CMAC_Final(cmacCtx, out, NULL), 1);
  61225. CMAC_CTX_free(cmacCtx);
  61226. cmacCtx = NULL;
  61227. ExpectNotNull(cmacCtx = CMAC_CTX_new());
  61228. CMAC_CTX_free(cmacCtx);
  61229. #endif /* WOLFSSL_CMAC && OPENSSL_EXTRA && WOLFSSL_AES_DIRECT */
  61230. return EXPECT_RESULT();
  61231. }
  61232. static int test_wolfSSL_DES(void)
  61233. {
  61234. EXPECT_DECLS;
  61235. #if defined(OPENSSL_EXTRA) && !defined(NO_DES3)
  61236. const_DES_cblock myDes;
  61237. DES_cblock iv;
  61238. DES_key_schedule key;
  61239. word32 i = 0;
  61240. DES_LONG dl = 0;
  61241. unsigned char msg[] = "hello wolfssl";
  61242. unsigned char weakKey[][8] = {
  61243. { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
  61244. { 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE },
  61245. { 0xE0, 0xE0, 0xE0, 0xE0, 0xF1, 0xF1, 0xF1, 0xF1 },
  61246. { 0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E }
  61247. };
  61248. unsigned char semiWeakKey[][8] = {
  61249. { 0x01, 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E },
  61250. { 0x1F, 0x01, 0x1F, 0x01, 0x0E, 0x01, 0x0E, 0x01 },
  61251. { 0x01, 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1 },
  61252. { 0xE0, 0x01, 0xE0, 0x01, 0xF1, 0x01, 0xF1, 0x01 },
  61253. { 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE },
  61254. { 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01, 0xFE, 0x01 },
  61255. { 0x1F, 0xE0, 0x1F, 0xE0, 0x0E, 0xF1, 0x0E, 0xF1 },
  61256. { 0xE0, 0x1F, 0xE0, 0x1F, 0xF1, 0x0E, 0xF1, 0x0E },
  61257. { 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E, 0xFE },
  61258. { 0xFE, 0x1F, 0xFE, 0x1F, 0xFE, 0x0E, 0xFE, 0x0E },
  61259. { 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE },
  61260. { 0xFE, 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1 }
  61261. };
  61262. DES_check_key(1);
  61263. DES_set_key(&myDes, &key);
  61264. /* check, check of odd parity */
  61265. XMEMSET(myDes, 4, sizeof(const_DES_cblock));
  61266. myDes[0] = 6; /* set even parity */
  61267. XMEMSET(key, 5, sizeof(DES_key_schedule));
  61268. ExpectIntEQ(DES_set_key_checked(&myDes, &key), -1);
  61269. ExpectIntNE(key[0], myDes[0]); /* should not have copied over key */
  61270. ExpectIntEQ(DES_set_key_checked(NULL, NULL), -2);
  61271. ExpectIntEQ(DES_set_key_checked(&myDes, NULL), -2);
  61272. ExpectIntEQ(DES_set_key_checked(NULL, &key), -2);
  61273. /* set odd parity for success case */
  61274. DES_set_odd_parity(&myDes);
  61275. ExpectIntEQ(DES_check_key_parity(&myDes), 1);
  61276. fprintf(stderr, "%02x %02x %02x %02x", myDes[0], myDes[1], myDes[2],
  61277. myDes[3]);
  61278. ExpectIntEQ(DES_set_key_checked(&myDes, &key), 0);
  61279. for (i = 0; i < sizeof(DES_key_schedule); i++) {
  61280. ExpectIntEQ(key[i], myDes[i]);
  61281. }
  61282. ExpectIntEQ(DES_is_weak_key(&myDes), 0);
  61283. /* check weak key */
  61284. XMEMSET(myDes, 1, sizeof(const_DES_cblock));
  61285. XMEMSET(key, 5, sizeof(DES_key_schedule));
  61286. ExpectIntEQ(DES_set_key_checked(&myDes, &key), -2);
  61287. ExpectIntNE(key[0], myDes[0]); /* should not have copied over key */
  61288. DES_set_key_unchecked(NULL, NULL);
  61289. DES_set_key_unchecked(&myDes, NULL);
  61290. DES_set_key_unchecked(NULL, &key);
  61291. /* compare arrays, should be the same */
  61292. /* now do unchecked copy of a weak key over */
  61293. DES_set_key_unchecked(&myDes, &key);
  61294. /* compare arrays, should be the same */
  61295. for (i = 0; i < sizeof(DES_key_schedule); i++) {
  61296. ExpectIntEQ(key[i], myDes[i]);
  61297. }
  61298. ExpectIntEQ(DES_is_weak_key(&myDes), 1);
  61299. myDes[7] = 2;
  61300. ExpectIntEQ(DES_set_key_checked(&myDes, &key), 0);
  61301. ExpectIntEQ(DES_is_weak_key(&myDes), 0);
  61302. ExpectIntEQ(DES_is_weak_key(NULL), 1);
  61303. /* Test all weak keys. */
  61304. for (i = 0; i < sizeof(weakKey) / sizeof(*weakKey); i++) {
  61305. ExpectIntEQ(DES_set_key_checked(&weakKey[i], &key), -2);
  61306. }
  61307. /* Test all semi-weak keys. */
  61308. for (i = 0; i < sizeof(semiWeakKey) / sizeof(*semiWeakKey); i++) {
  61309. ExpectIntEQ(DES_set_key_checked(&semiWeakKey[i], &key), -2);
  61310. }
  61311. /* check DES_key_sched API */
  61312. XMEMSET(key, 1, sizeof(DES_key_schedule));
  61313. ExpectIntEQ(DES_key_sched(&myDes, NULL), 0);
  61314. ExpectIntEQ(DES_key_sched(NULL, &key), 0);
  61315. ExpectIntEQ(DES_key_sched(&myDes, &key), 0);
  61316. /* compare arrays, should be the same */
  61317. for (i = 0; i < sizeof(DES_key_schedule); i++) {
  61318. ExpectIntEQ(key[i], myDes[i]);
  61319. }
  61320. ExpectIntEQ((DES_cbc_cksum(NULL, NULL, 0, NULL, NULL)), 0);
  61321. ExpectIntEQ((DES_cbc_cksum(msg, NULL, 0, NULL, NULL)), 0);
  61322. ExpectIntEQ((DES_cbc_cksum(NULL, &key, 0, NULL, NULL)), 0);
  61323. ExpectIntEQ((DES_cbc_cksum(NULL, NULL, 0, &myDes, NULL)), 0);
  61324. ExpectIntEQ((DES_cbc_cksum(NULL, NULL, 0, NULL, &iv)), 0);
  61325. ExpectIntEQ((DES_cbc_cksum(NULL, &key, sizeof(msg), &myDes, &iv)), 0);
  61326. ExpectIntEQ((DES_cbc_cksum(msg, NULL, sizeof(msg), &myDes, &iv)), 0);
  61327. ExpectIntEQ((DES_cbc_cksum(msg, &key, sizeof(msg), NULL, &iv)), 0);
  61328. ExpectIntEQ((DES_cbc_cksum(msg, &key, sizeof(msg), &myDes, NULL)), 0);
  61329. /* DES_cbc_cksum should return the last 4 of the last 8 bytes after
  61330. * DES_cbc_encrypt on the input */
  61331. XMEMSET(iv, 0, sizeof(DES_cblock));
  61332. XMEMSET(myDes, 5, sizeof(DES_key_schedule));
  61333. ExpectIntGT((dl = DES_cbc_cksum(msg, &key, sizeof(msg), &myDes, &iv)), 0);
  61334. ExpectIntEQ(dl, 480052723);
  61335. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_DES3) */
  61336. return EXPECT_RESULT();
  61337. }
  61338. static int test_wolfSSL_DES_ncbc(void)
  61339. {
  61340. EXPECT_DECLS;
  61341. #if defined(OPENSSL_EXTRA) && !defined(NO_DES3)
  61342. const_DES_cblock myDes;
  61343. DES_cblock iv = {1};
  61344. DES_key_schedule key = {0};
  61345. unsigned char msg[] = "hello wolfssl";
  61346. unsigned char out[DES_BLOCK_SIZE * 2] = {0};
  61347. unsigned char pln[DES_BLOCK_SIZE * 2] = {0};
  61348. unsigned char exp[] = {0x31, 0x98, 0x2F, 0x3A, 0x55, 0xBF, 0xD8, 0xC4};
  61349. unsigned char exp2[] = {0xC7, 0x45, 0x8B, 0x28, 0x10, 0x53, 0xE0, 0x58};
  61350. /* partial block test */
  61351. DES_set_key(&key, &myDes);
  61352. DES_ncbc_encrypt(msg, out, 3, &myDes, &iv, DES_ENCRYPT);
  61353. ExpectIntEQ(XMEMCMP(exp, out, DES_BLOCK_SIZE), 0);
  61354. ExpectIntEQ(XMEMCMP(exp, iv, DES_BLOCK_SIZE), 0);
  61355. DES_set_key(&key, &myDes);
  61356. XMEMSET((byte*)&iv, 0, DES_BLOCK_SIZE);
  61357. *((byte*)&iv) = 1;
  61358. DES_ncbc_encrypt(out, pln, 3, &myDes, &iv, DES_DECRYPT);
  61359. ExpectIntEQ(XMEMCMP(msg, pln, 3), 0);
  61360. ExpectIntEQ(XMEMCMP(exp, iv, DES_BLOCK_SIZE), 0);
  61361. /* full block test */
  61362. DES_set_key(&key, &myDes);
  61363. XMEMSET(pln, 0, DES_BLOCK_SIZE);
  61364. XMEMSET((byte*)&iv, 0, DES_BLOCK_SIZE);
  61365. *((byte*)&iv) = 1;
  61366. DES_ncbc_encrypt(msg, out, 8, &myDes, &iv, DES_ENCRYPT);
  61367. ExpectIntEQ(XMEMCMP(exp2, out, DES_BLOCK_SIZE), 0);
  61368. ExpectIntEQ(XMEMCMP(exp2, iv, DES_BLOCK_SIZE), 0);
  61369. DES_set_key(&key, &myDes);
  61370. XMEMSET((byte*)&iv, 0, DES_BLOCK_SIZE);
  61371. *((byte*)&iv) = 1;
  61372. DES_ncbc_encrypt(out, pln, 8, &myDes, &iv, DES_DECRYPT);
  61373. ExpectIntEQ(XMEMCMP(msg, pln, 8), 0);
  61374. ExpectIntEQ(XMEMCMP(exp2, iv, DES_BLOCK_SIZE), 0);
  61375. #endif
  61376. return EXPECT_RESULT();
  61377. }
  61378. static int test_wolfSSL_DES_ecb_encrypt(void)
  61379. {
  61380. EXPECT_DECLS;
  61381. #if defined(OPENSSL_EXTRA) && !defined(NO_DES3) && defined(WOLFSSL_DES_ECB)
  61382. WOLFSSL_DES_cblock input1, input2, output1, output2, back1, back2;
  61383. WOLFSSL_DES_key_schedule key;
  61384. XMEMCPY(key, "12345678", sizeof(WOLFSSL_DES_key_schedule));
  61385. XMEMCPY(input1, "Iamhuman", sizeof(WOLFSSL_DES_cblock));
  61386. XMEMCPY(input2, "Whoisit?", sizeof(WOLFSSL_DES_cblock));
  61387. XMEMSET(output1, 0, sizeof(WOLFSSL_DES_cblock));
  61388. XMEMSET(output2, 0, sizeof(WOLFSSL_DES_cblock));
  61389. XMEMSET(back1, 0, sizeof(WOLFSSL_DES_cblock));
  61390. XMEMSET(back2, 0, sizeof(WOLFSSL_DES_cblock));
  61391. wolfSSL_DES_ecb_encrypt(NULL, NULL, NULL, DES_ENCRYPT);
  61392. wolfSSL_DES_ecb_encrypt(&input1, NULL, NULL, DES_ENCRYPT);
  61393. wolfSSL_DES_ecb_encrypt(NULL, &output1, NULL, DES_ENCRYPT);
  61394. wolfSSL_DES_ecb_encrypt(NULL, NULL, &key, DES_ENCRYPT);
  61395. wolfSSL_DES_ecb_encrypt(&input1, &output1, NULL, DES_ENCRYPT);
  61396. wolfSSL_DES_ecb_encrypt(&input1, NULL, &key, DES_ENCRYPT);
  61397. wolfSSL_DES_ecb_encrypt(NULL, &output1, &key, DES_ENCRYPT);
  61398. /* Encrypt messages */
  61399. wolfSSL_DES_ecb_encrypt(&input1, &output1, &key, DES_ENCRYPT);
  61400. wolfSSL_DES_ecb_encrypt(&input2, &output2, &key, DES_ENCRYPT);
  61401. {
  61402. /* Decrypt messages */
  61403. int ret1 = 0;
  61404. int ret2 = 0;
  61405. wolfSSL_DES_ecb_encrypt(&output1, &back1, &key, DES_DECRYPT);
  61406. ExpectIntEQ(ret1 = XMEMCMP((unsigned char *)back1,
  61407. (unsigned char *)input1, sizeof(WOLFSSL_DES_cblock)), 0);
  61408. wolfSSL_DES_ecb_encrypt(&output2, &back2, &key, DES_DECRYPT);
  61409. ExpectIntEQ(ret2 = XMEMCMP((unsigned char *)back2,
  61410. (unsigned char *)input2, sizeof(WOLFSSL_DES_cblock)), 0);
  61411. }
  61412. #endif
  61413. return EXPECT_RESULT();
  61414. }
  61415. static int test_wolfSSL_DES_ede3_cbc_encrypt(void)
  61416. {
  61417. EXPECT_DECLS;
  61418. #if defined(OPENSSL_EXTRA) && !defined(NO_DES3)
  61419. unsigned char input1[8], input2[8];
  61420. unsigned char output1[8], output2[8];
  61421. unsigned char back1[8], back2[8];
  61422. WOLFSSL_DES_cblock iv1, iv2;
  61423. WOLFSSL_DES_key_schedule key1, key2, key3;
  61424. int i;
  61425. XMEMCPY(key1, "12345678", sizeof(WOLFSSL_DES_key_schedule));
  61426. XMEMCPY(key2, "23456781", sizeof(WOLFSSL_DES_key_schedule));
  61427. XMEMCPY(key3, "34567823", sizeof(WOLFSSL_DES_key_schedule));
  61428. XMEMCPY(input1, "Iamhuman", sizeof(input1));
  61429. XMEMCPY(input2, "Whoisit?", sizeof(input2));
  61430. XMEMSET(output1, 0, sizeof(output1));
  61431. XMEMSET(output2, 0, sizeof(output2));
  61432. XMEMSET(back1, 0, sizeof(back1));
  61433. XMEMSET(back2, 0, sizeof(back2));
  61434. XMEMCPY(iv1, "87654321", sizeof(WOLFSSL_DES_cblock));
  61435. XMEMCPY(iv2, "98765432", sizeof(WOLFSSL_DES_cblock));
  61436. /* Encrypt messages */
  61437. wolfSSL_DES_ede3_cbc_encrypt(input1, output1, 8, &key1, &key2, &key3, &iv1,
  61438. DES_ENCRYPT);
  61439. wolfSSL_DES_ede3_cbc_encrypt(input2, output2, 8, &key1, &key2, &key3, &iv2,
  61440. DES_ENCRYPT);
  61441. {
  61442. XMEMCPY(iv1, "87654321", sizeof(WOLFSSL_DES_cblock));
  61443. XMEMCPY(iv2, "98765432", sizeof(WOLFSSL_DES_cblock));
  61444. /* Decrypt messages */
  61445. wolfSSL_DES_ede3_cbc_encrypt(output1, back1, 8, &key1, &key2, &key3,
  61446. &iv1, DES_DECRYPT);
  61447. ExpectIntEQ(XMEMCMP(back1, input1, sizeof(input1)), 0);
  61448. wolfSSL_DES_ede3_cbc_encrypt(output2, back2, 8, &key1, &key2, &key3,
  61449. &iv2, DES_DECRYPT);
  61450. ExpectIntEQ(XMEMCMP(back2, input2, sizeof(input2)), 0);
  61451. }
  61452. for (i = 0; i < 8; i++) {
  61453. XMEMSET(output1, 0, sizeof(output1));
  61454. XMEMSET(output2, 0, sizeof(output2));
  61455. XMEMSET(back1, 0, sizeof(back1));
  61456. XMEMSET(back2, 0, sizeof(back2));
  61457. XMEMCPY(iv1, "87654321", sizeof(WOLFSSL_DES_cblock));
  61458. XMEMCPY(iv2, "98765432", sizeof(WOLFSSL_DES_cblock));
  61459. /* Encrypt partial messages */
  61460. wolfSSL_DES_ede3_cbc_encrypt(input1, output1, i, &key1, &key2, &key3,
  61461. &iv1, DES_ENCRYPT);
  61462. wolfSSL_DES_ede3_cbc_encrypt(input2, output2, i, &key1, &key2, &key3,
  61463. &iv2, DES_ENCRYPT);
  61464. {
  61465. XMEMCPY(iv1, "87654321", sizeof(WOLFSSL_DES_cblock));
  61466. XMEMCPY(iv2, "98765432", sizeof(WOLFSSL_DES_cblock));
  61467. /* Decrypt messages */
  61468. wolfSSL_DES_ede3_cbc_encrypt(output1, back1, i, &key1, &key2,
  61469. &key3, &iv1, DES_DECRYPT);
  61470. ExpectIntEQ(XMEMCMP(back1, input1, i), 0);
  61471. wolfSSL_DES_ede3_cbc_encrypt(output2, back2, i, &key1, &key2,
  61472. &key3, &iv2, DES_DECRYPT);
  61473. ExpectIntEQ(XMEMCMP(back2, input2, i), 0);
  61474. }
  61475. }
  61476. #endif
  61477. return EXPECT_RESULT();
  61478. }
  61479. static int test_wolfSSL_AES_encrypt(void)
  61480. {
  61481. EXPECT_DECLS;
  61482. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AES_ECB) \
  61483. && !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
  61484. AES_KEY enc;
  61485. AES_KEY dec;
  61486. const byte msg[] = {
  61487. 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
  61488. 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a
  61489. };
  61490. const byte exp[] = {
  61491. 0xf3, 0xee, 0xd1, 0xbd, 0xb5, 0xd2, 0xa0, 0x3c,
  61492. 0x06, 0x4b, 0x5a, 0x7e, 0x3d, 0xb1, 0x81, 0xf8,
  61493. };
  61494. const byte key[] = {
  61495. 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
  61496. 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
  61497. 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
  61498. 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4
  61499. };
  61500. byte eout[sizeof(msg)];
  61501. byte dout[sizeof(msg)];
  61502. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &enc), 0);
  61503. ExpectIntEQ(AES_set_decrypt_key(key, sizeof(key)*8, &dec), 0);
  61504. wolfSSL_AES_encrypt(NULL, NULL, NULL);
  61505. wolfSSL_AES_encrypt(msg, NULL, NULL);
  61506. wolfSSL_AES_encrypt(NULL, eout, NULL);
  61507. wolfSSL_AES_encrypt(NULL, NULL, &enc);
  61508. wolfSSL_AES_encrypt(msg, eout, NULL);
  61509. wolfSSL_AES_encrypt(msg, NULL, &enc);
  61510. wolfSSL_AES_encrypt(NULL, eout, &enc);
  61511. wolfSSL_AES_decrypt(NULL, NULL, NULL);
  61512. wolfSSL_AES_decrypt(eout, NULL, NULL);
  61513. wolfSSL_AES_decrypt(NULL, dout, NULL);
  61514. wolfSSL_AES_decrypt(NULL, NULL, &dec);
  61515. wolfSSL_AES_decrypt(eout, dout, NULL);
  61516. wolfSSL_AES_decrypt(eout, NULL, &dec);
  61517. wolfSSL_AES_decrypt(NULL, dout, &dec);
  61518. wolfSSL_AES_encrypt(msg, eout, &enc);
  61519. ExpectIntEQ(XMEMCMP(eout, exp, AES_BLOCK_SIZE), 0);
  61520. wolfSSL_AES_decrypt(eout, dout, &dec);
  61521. ExpectIntEQ(XMEMCMP(dout, msg, AES_BLOCK_SIZE), 0);
  61522. #endif
  61523. return EXPECT_RESULT();
  61524. }
  61525. static int test_wolfSSL_AES_ecb_encrypt(void)
  61526. {
  61527. EXPECT_DECLS;
  61528. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AES_ECB) \
  61529. && !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
  61530. AES_KEY aes;
  61531. const byte msg[] =
  61532. {
  61533. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  61534. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  61535. };
  61536. const byte verify[] =
  61537. {
  61538. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  61539. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  61540. };
  61541. const byte key[] =
  61542. {
  61543. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  61544. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  61545. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  61546. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  61547. };
  61548. byte out[AES_BLOCK_SIZE];
  61549. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &aes), 0);
  61550. XMEMSET(out, 0, AES_BLOCK_SIZE);
  61551. AES_ecb_encrypt(msg, out, &aes, AES_ENCRYPT);
  61552. ExpectIntEQ(XMEMCMP(out, verify, AES_BLOCK_SIZE), 0);
  61553. #ifdef HAVE_AES_DECRYPT
  61554. ExpectIntEQ(AES_set_decrypt_key(key, sizeof(key)*8, &aes), 0);
  61555. XMEMSET(out, 0, AES_BLOCK_SIZE);
  61556. AES_ecb_encrypt(verify, out, &aes, AES_DECRYPT);
  61557. ExpectIntEQ(XMEMCMP(out, msg, AES_BLOCK_SIZE), 0);
  61558. #endif
  61559. /* test bad arguments */
  61560. AES_ecb_encrypt(NULL, out, &aes, AES_DECRYPT);
  61561. AES_ecb_encrypt(verify, NULL, &aes, AES_DECRYPT);
  61562. AES_ecb_encrypt(verify, out, NULL, AES_DECRYPT);
  61563. #endif
  61564. return EXPECT_RESULT();
  61565. }
  61566. static int test_wolfSSL_AES_cbc_encrypt(void)
  61567. {
  61568. EXPECT_DECLS;
  61569. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(OPENSSL_EXTRA) && \
  61570. !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
  61571. AES_KEY aes;
  61572. AES_KEY* aesN = NULL;
  61573. size_t len = 0;
  61574. size_t lenB = 0;
  61575. int keySz0 = 0;
  61576. int keySzN = -1;
  61577. byte out[AES_BLOCK_SIZE] = {0};
  61578. byte* outN = NULL;
  61579. /* Test vectors retrieved from:
  61580. * <begin URL>
  61581. * https://csrc.nist.gov/
  61582. * CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/
  61583. * documents/aes/KAT_AES.zip
  61584. * </end URL>
  61585. */
  61586. const byte* pt128N = NULL;
  61587. byte* key128N = NULL;
  61588. byte* iv128N = NULL;
  61589. byte iv128tmp[AES_BLOCK_SIZE] = {0};
  61590. const byte pt128[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  61591. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
  61592. const byte ct128[] = { 0x87,0x85,0xb1,0xa7,0x5b,0x0f,0x3b,0xd9,
  61593. 0x58,0xdc,0xd0,0xe2,0x93,0x18,0xc5,0x21 };
  61594. const byte iv128[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  61595. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
  61596. byte key128[] = { 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  61597. 0xff,0xff,0xf0,0x00,0x00,0x00,0x00,0x00 };
  61598. len = sizeof(pt128);
  61599. #define STRESS_T(a, b, c, d, e, f, g, h, i) \
  61600. wolfSSL_AES_cbc_encrypt(a, b, c, d, e, f); \
  61601. ExpectIntNE(XMEMCMP(b, g, h), i)
  61602. #define RESET_IV(x, y) XMEMCPY(x, y, AES_BLOCK_SIZE)
  61603. /* Stressing wolfSSL_AES_cbc_encrypt() */
  61604. STRESS_T(pt128N, out, len, &aes, iv128tmp, 1, ct128, AES_BLOCK_SIZE, 0);
  61605. STRESS_T(pt128, out, len, &aes, iv128N, 1, ct128, AES_BLOCK_SIZE, 0);
  61606. wolfSSL_AES_cbc_encrypt(pt128, outN, len, &aes, iv128tmp, AES_ENCRYPT);
  61607. ExpectIntNE(XMEMCMP(out, ct128, AES_BLOCK_SIZE), 0);
  61608. wolfSSL_AES_cbc_encrypt(pt128, out, len, aesN, iv128tmp, AES_ENCRYPT);
  61609. ExpectIntNE(XMEMCMP(out, ct128, AES_BLOCK_SIZE), 0);
  61610. STRESS_T(pt128, out, lenB, &aes, iv128tmp, 1, ct128, AES_BLOCK_SIZE, 0);
  61611. /* Stressing wolfSSL_AES_set_encrypt_key */
  61612. ExpectIntNE(wolfSSL_AES_set_encrypt_key(key128N, sizeof(key128)*8, &aes),0);
  61613. ExpectIntNE(wolfSSL_AES_set_encrypt_key(key128, sizeof(key128)*8, aesN),0);
  61614. ExpectIntNE(wolfSSL_AES_set_encrypt_key(key128, keySz0, &aes), 0);
  61615. ExpectIntNE(wolfSSL_AES_set_encrypt_key(key128, keySzN, &aes), 0);
  61616. /* Stressing wolfSSL_AES_set_decrypt_key */
  61617. ExpectIntNE(wolfSSL_AES_set_decrypt_key(key128N, sizeof(key128)*8, &aes),0);
  61618. ExpectIntNE(wolfSSL_AES_set_decrypt_key(key128N, sizeof(key128)*8, aesN),0);
  61619. ExpectIntNE(wolfSSL_AES_set_decrypt_key(key128, keySz0, &aes), 0);
  61620. ExpectIntNE(wolfSSL_AES_set_decrypt_key(key128, keySzN, &aes), 0);
  61621. #ifdef WOLFSSL_AES_128
  61622. /* wolfSSL_AES_cbc_encrypt() 128-bit */
  61623. XMEMSET(out, 0, AES_BLOCK_SIZE);
  61624. RESET_IV(iv128tmp, iv128);
  61625. ExpectIntEQ(wolfSSL_AES_set_encrypt_key(key128, sizeof(key128)*8, &aes), 0);
  61626. wolfSSL_AES_cbc_encrypt(pt128, out, len, &aes, iv128tmp, AES_ENCRYPT);
  61627. ExpectIntEQ(XMEMCMP(out, ct128, AES_BLOCK_SIZE), 0);
  61628. wc_AesFree((Aes*)&aes);
  61629. #ifdef HAVE_AES_DECRYPT
  61630. /* wolfSSL_AES_cbc_encrypt() 128-bit in decrypt mode */
  61631. XMEMSET(out, 0, AES_BLOCK_SIZE);
  61632. RESET_IV(iv128tmp, iv128);
  61633. len = sizeof(ct128);
  61634. ExpectIntEQ(wolfSSL_AES_set_decrypt_key(key128, sizeof(key128)*8, &aes), 0);
  61635. wolfSSL_AES_cbc_encrypt(ct128, out, len, &aes, iv128tmp, AES_DECRYPT);
  61636. ExpectIntEQ(XMEMCMP(out, pt128, AES_BLOCK_SIZE), 0);
  61637. wc_AesFree((Aes*)&aes);
  61638. #endif
  61639. #endif /* WOLFSSL_AES_128 */
  61640. #ifdef WOLFSSL_AES_192
  61641. {
  61642. /* Test vectors from NIST Special Publication 800-38A, 2001 Edition
  61643. * Appendix F.2.3 */
  61644. byte iv192tmp[AES_BLOCK_SIZE] = {0};
  61645. const byte pt192[] = { 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  61646. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a };
  61647. const byte ct192[] = { 0x4f,0x02,0x1d,0xb2,0x43,0xbc,0x63,0x3d,
  61648. 0x71,0x78,0x18,0x3a,0x9f,0xa0,0x71,0xe8 };
  61649. const byte iv192[] = { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  61650. 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F };
  61651. byte key192[] = { 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  61652. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  61653. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b };
  61654. len = sizeof(pt192);
  61655. /* wolfSSL_AES_cbc_encrypt() 192-bit */
  61656. XMEMSET(out, 0, AES_BLOCK_SIZE);
  61657. RESET_IV(iv192tmp, iv192);
  61658. ExpectIntEQ(wolfSSL_AES_set_encrypt_key(key192, sizeof(key192)*8, &aes), 0);
  61659. wolfSSL_AES_cbc_encrypt(pt192, out, len, &aes, iv192tmp, AES_ENCRYPT);
  61660. ExpectIntEQ(XMEMCMP(out, ct192, AES_BLOCK_SIZE), 0);
  61661. wc_AesFree((Aes*)&aes);
  61662. #ifdef HAVE_AES_DECRYPT
  61663. /* wolfSSL_AES_cbc_encrypt() 192-bit in decrypt mode */
  61664. len = sizeof(ct192);
  61665. RESET_IV(iv192tmp, iv192);
  61666. XMEMSET(out, 0, AES_BLOCK_SIZE);
  61667. ExpectIntEQ(wolfSSL_AES_set_decrypt_key(key192, sizeof(key192)*8, &aes), 0);
  61668. wolfSSL_AES_cbc_encrypt(ct192, out, len, &aes, iv192tmp, AES_DECRYPT);
  61669. ExpectIntEQ(XMEMCMP(out, pt192, AES_BLOCK_SIZE), 0);
  61670. wc_AesFree((Aes*)&aes);
  61671. #endif
  61672. }
  61673. #endif /* WOLFSSL_AES_192 */
  61674. #ifdef WOLFSSL_AES_256
  61675. {
  61676. /* Test vectors from NIST Special Publication 800-38A, 2001 Edition,
  61677. * Appendix F.2.5 */
  61678. byte iv256tmp[AES_BLOCK_SIZE] = {0};
  61679. const byte pt256[] = { 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  61680. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a };
  61681. const byte ct256[] = { 0xf5,0x8c,0x4c,0x04,0xd6,0xe5,0xf1,0xba,
  61682. 0x77,0x9e,0xab,0xfb,0x5f,0x7b,0xfb,0xd6 };
  61683. const byte iv256[] = { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  61684. 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F };
  61685. byte key256[] = { 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  61686. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  61687. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  61688. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4 };
  61689. len = sizeof(pt256);
  61690. /* wolfSSL_AES_cbc_encrypt() 256-bit */
  61691. XMEMSET(out, 0, AES_BLOCK_SIZE);
  61692. RESET_IV(iv256tmp, iv256);
  61693. ExpectIntEQ(wolfSSL_AES_set_encrypt_key(key256, sizeof(key256)*8, &aes), 0);
  61694. wolfSSL_AES_cbc_encrypt(pt256, out, len, &aes, iv256tmp, AES_ENCRYPT);
  61695. ExpectIntEQ(XMEMCMP(out, ct256, AES_BLOCK_SIZE), 0);
  61696. wc_AesFree((Aes*)&aes);
  61697. #ifdef HAVE_AES_DECRYPT
  61698. /* wolfSSL_AES_cbc_encrypt() 256-bit in decrypt mode */
  61699. len = sizeof(ct256);
  61700. RESET_IV(iv256tmp, iv256);
  61701. XMEMSET(out, 0, AES_BLOCK_SIZE);
  61702. ExpectIntEQ(wolfSSL_AES_set_decrypt_key(key256, sizeof(key256)*8, &aes), 0);
  61703. wolfSSL_AES_cbc_encrypt(ct256, out, len, &aes, iv256tmp, AES_DECRYPT);
  61704. ExpectIntEQ(XMEMCMP(out, pt256, AES_BLOCK_SIZE), 0);
  61705. wc_AesFree((Aes*)&aes);
  61706. #endif
  61707. #if defined(HAVE_AES_KEYWRAP) && !defined(HAVE_FIPS) && \
  61708. !defined(HAVE_SELFTEST)
  61709. {
  61710. byte wrapCipher[sizeof(key256) + KEYWRAP_BLOCK_SIZE] = { 0 };
  61711. byte wrapPlain[sizeof(key256)] = { 0 };
  61712. byte wrapIV[KEYWRAP_BLOCK_SIZE] = { 0 };
  61713. /* wolfSSL_AES_wrap_key() 256-bit NULL iv */
  61714. ExpectIntEQ(wolfSSL_AES_set_encrypt_key(key256, sizeof(key256)*8, &aes), 0);
  61715. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, NULL, wrapCipher, key256,
  61716. 15), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  61717. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, NULL, wrapCipher, key256,
  61718. sizeof(key256)), sizeof(wrapCipher));
  61719. wc_AesFree((Aes*)&aes);
  61720. /* wolfSSL_AES_unwrap_key() 256-bit NULL iv */
  61721. ExpectIntEQ(wolfSSL_AES_set_decrypt_key(key256, sizeof(key256)*8, &aes), 0);
  61722. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, NULL, wrapPlain, wrapCipher,
  61723. 23), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  61724. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, NULL, wrapPlain, wrapCipher,
  61725. sizeof(wrapCipher)), sizeof(wrapPlain));
  61726. ExpectIntEQ(XMEMCMP(wrapPlain, key256, sizeof(key256)), 0);
  61727. XMEMSET(wrapCipher, 0, sizeof(wrapCipher));
  61728. XMEMSET(wrapPlain, 0, sizeof(wrapPlain));
  61729. wc_AesFree((Aes*)&aes);
  61730. /* wolfSSL_AES_wrap_key() 256-bit custom iv */
  61731. ExpectIntEQ(wolfSSL_AES_set_encrypt_key(key256, sizeof(key256)*8, &aes), 0);
  61732. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, wrapIV, wrapCipher, key256,
  61733. sizeof(key256)), sizeof(wrapCipher));
  61734. wc_AesFree((Aes*)&aes);
  61735. /* wolfSSL_AES_unwrap_key() 256-bit custom iv */
  61736. ExpectIntEQ(wolfSSL_AES_set_decrypt_key(key256, sizeof(key256)*8, &aes), 0);
  61737. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, wrapIV, wrapPlain, wrapCipher,
  61738. sizeof(wrapCipher)), sizeof(wrapPlain));
  61739. ExpectIntEQ(XMEMCMP(wrapPlain, key256, sizeof(key256)), 0);
  61740. wc_AesFree((Aes*)&aes);
  61741. ExpectIntEQ(wolfSSL_AES_wrap_key(NULL, NULL, NULL, NULL, 0), 0);
  61742. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, NULL, NULL, NULL, 0), 0);
  61743. ExpectIntEQ(wolfSSL_AES_wrap_key(NULL, wrapIV, NULL, NULL, 0), 0);
  61744. ExpectIntEQ(wolfSSL_AES_wrap_key(NULL, NULL, wrapCipher, NULL, 0), 0);
  61745. ExpectIntEQ(wolfSSL_AES_wrap_key(NULL, NULL, NULL, key256, 0), 0);
  61746. ExpectIntEQ(wolfSSL_AES_wrap_key(NULL, wrapIV, wrapCipher, key256, 0), 0);
  61747. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, NULL, wrapCipher, key256, 0), 0);
  61748. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, wrapIV, NULL, key256, 0), 0);
  61749. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, wrapIV, wrapCipher, NULL, 0), 0);
  61750. ExpectIntEQ(wolfSSL_AES_unwrap_key(NULL, NULL, NULL, NULL, 0), 0);
  61751. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, NULL, NULL, NULL, 0), 0);
  61752. ExpectIntEQ(wolfSSL_AES_unwrap_key(NULL, wrapIV, NULL, NULL, 0), 0);
  61753. ExpectIntEQ(wolfSSL_AES_unwrap_key(NULL, NULL, wrapPlain, NULL, 0), 0);
  61754. ExpectIntEQ(wolfSSL_AES_unwrap_key(NULL, NULL, NULL, wrapCipher, 0), 0);
  61755. ExpectIntEQ(wolfSSL_AES_unwrap_key(NULL, wrapIV, wrapPlain, wrapCipher, 0),
  61756. 0);
  61757. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, NULL, wrapPlain, wrapCipher, 0),
  61758. 0);
  61759. ExpectIntEQ(wolfSSL_AES_unwrap_key(&aes, wrapIV, NULL, wrapCipher, 0), 0);
  61760. ExpectIntEQ(wolfSSL_AES_wrap_key(&aes, wrapIV, wrapPlain, NULL, 0), 0);
  61761. }
  61762. #endif /* HAVE_AES_KEYWRAP */
  61763. }
  61764. #endif /* WOLFSSL_AES_256 */
  61765. #endif
  61766. return EXPECT_RESULT();
  61767. }
  61768. static int test_wolfSSL_AES_cfb128_encrypt(void)
  61769. {
  61770. EXPECT_DECLS;
  61771. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(WOLFSSL_AES_CFB) && \
  61772. !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
  61773. AES_KEY aesEnc;
  61774. AES_KEY aesDec;
  61775. const byte msg[] = {
  61776. 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
  61777. 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a
  61778. };
  61779. const byte exp[] = {
  61780. 0x16, 0xc9, 0x90, 0x6c, 0x04, 0x0c, 0xd1, 0x2f,
  61781. 0x84, 0x7b, 0x18, 0xed, 0xed, 0x6a, 0xb5, 0xfd
  61782. };
  61783. const byte key[] = {
  61784. 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
  61785. 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
  61786. 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
  61787. 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4
  61788. };
  61789. const byte ivData[] = {
  61790. 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
  61791. 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
  61792. };
  61793. byte out[AES_BLOCK_SIZE];
  61794. byte iv[AES_BLOCK_SIZE];
  61795. word32 i;
  61796. int num;
  61797. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &aesEnc), 0);
  61798. XMEMCPY(iv, ivData, sizeof(iv));
  61799. XMEMSET(out, 0, AES_BLOCK_SIZE);
  61800. AES_cfb128_encrypt(msg, out, sizeof(msg), &aesEnc, iv, NULL, AES_ENCRYPT);
  61801. ExpectIntEQ(XMEMCMP(out, exp, sizeof(msg)), 0);
  61802. ExpectIntNE(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  61803. #ifdef HAVE_AES_DECRYPT
  61804. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &aesDec), 0);
  61805. XMEMCPY(iv, ivData, sizeof(iv));
  61806. XMEMSET(out, 0, AES_BLOCK_SIZE);
  61807. AES_cfb128_encrypt(exp, out, sizeof(msg), &aesDec, iv, NULL, AES_DECRYPT);
  61808. ExpectIntEQ(XMEMCMP(out, msg, sizeof(msg)), 0);
  61809. ExpectIntNE(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  61810. #endif
  61811. for (i = 0; EXPECT_SUCCESS() && (i <= sizeof(msg)); i++) {
  61812. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &aesEnc), 0);
  61813. XMEMCPY(iv, ivData, sizeof(iv));
  61814. XMEMSET(out, 0, AES_BLOCK_SIZE);
  61815. AES_cfb128_encrypt(msg, out, i, &aesEnc, iv, &num, AES_ENCRYPT);
  61816. ExpectIntEQ(num, i % AES_BLOCK_SIZE);
  61817. ExpectIntEQ(XMEMCMP(out, exp, i), 0);
  61818. if (i == 0) {
  61819. ExpectIntEQ(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  61820. }
  61821. else {
  61822. ExpectIntNE(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  61823. }
  61824. #ifdef HAVE_AES_DECRYPT
  61825. ExpectIntEQ(AES_set_encrypt_key(key, sizeof(key)*8, &aesDec), 0);
  61826. XMEMCPY(iv, ivData, sizeof(iv));
  61827. XMEMSET(out, 0, AES_BLOCK_SIZE);
  61828. AES_cfb128_encrypt(exp, out, i, &aesDec, iv, &num, AES_DECRYPT);
  61829. ExpectIntEQ(num, i % AES_BLOCK_SIZE);
  61830. ExpectIntEQ(XMEMCMP(out, msg, i), 0);
  61831. if (i == 0) {
  61832. ExpectIntEQ(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  61833. }
  61834. else {
  61835. ExpectIntNE(XMEMCMP(iv, ivData, sizeof(iv)), 0);
  61836. }
  61837. #endif
  61838. }
  61839. if (EXPECT_SUCCESS()) {
  61840. /* test bad arguments */
  61841. AES_cfb128_encrypt(NULL, NULL, 0, NULL, NULL, NULL, AES_DECRYPT);
  61842. AES_cfb128_encrypt(msg, NULL, 0, NULL, NULL, NULL, AES_DECRYPT);
  61843. AES_cfb128_encrypt(NULL, out, 0, NULL, NULL, NULL, AES_DECRYPT);
  61844. AES_cfb128_encrypt(NULL, NULL, 0, &aesDec, NULL, NULL, AES_DECRYPT);
  61845. AES_cfb128_encrypt(NULL, NULL, 0, NULL, iv, NULL, AES_DECRYPT);
  61846. AES_cfb128_encrypt(NULL, out, 0, &aesDec, iv, NULL, AES_DECRYPT);
  61847. AES_cfb128_encrypt(msg, NULL, 0, &aesDec, iv, NULL, AES_DECRYPT);
  61848. AES_cfb128_encrypt(msg, out, 0, NULL, iv, NULL, AES_DECRYPT);
  61849. AES_cfb128_encrypt(msg, out, 0, &aesDec, NULL, NULL, AES_DECRYPT);
  61850. }
  61851. #endif
  61852. return EXPECT_RESULT();
  61853. }
  61854. static int test_wolfSSL_CRYPTO_cts128(void)
  61855. {
  61856. EXPECT_DECLS;
  61857. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(OPENSSL_EXTRA) && \
  61858. defined(HAVE_CTS) && !defined(WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API)
  61859. byte tmp[64]; /* Largest vector size */
  61860. /* Test vectors taken form RFC3962 Appendix B */
  61861. const testVector vects[] = {
  61862. {
  61863. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  61864. "\x20",
  61865. "\xc6\x35\x35\x68\xf2\xbf\x8c\xb4\xd8\xa5\x80\x36\x2d\xa7\xff\x7f"
  61866. "\x97",
  61867. 17, 17
  61868. },
  61869. {
  61870. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  61871. "\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20",
  61872. "\xfc\x00\x78\x3e\x0e\xfd\xb2\xc1\xd4\x45\xd4\xc8\xef\xf7\xed\x22"
  61873. "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5",
  61874. 31, 31
  61875. },
  61876. {
  61877. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  61878. "\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20\x43",
  61879. "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5\xa8"
  61880. "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84",
  61881. 32, 32
  61882. },
  61883. {
  61884. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  61885. "\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20\x43"
  61886. "\x68\x69\x63\x6b\x65\x6e\x2c\x20\x70\x6c\x65\x61\x73\x65\x2c",
  61887. "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84"
  61888. "\xb3\xff\xfd\x94\x0c\x16\xa1\x8c\x1b\x55\x49\xd2\xf8\x38\x02\x9e"
  61889. "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5",
  61890. 47, 47
  61891. },
  61892. {
  61893. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  61894. "\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20\x43"
  61895. "\x68\x69\x63\x6b\x65\x6e\x2c\x20\x70\x6c\x65\x61\x73\x65\x2c\x20",
  61896. "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84"
  61897. "\x9d\xad\x8b\xbb\x96\xc4\xcd\xc0\x3b\xc1\x03\xe1\xa1\x94\xbb\xd8"
  61898. "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5\xa8",
  61899. 48, 48
  61900. },
  61901. {
  61902. "\x49\x20\x77\x6f\x75\x6c\x64\x20\x6c\x69\x6b\x65\x20\x74\x68\x65"
  61903. "\x20\x47\x65\x6e\x65\x72\x61\x6c\x20\x47\x61\x75\x27\x73\x20\x43"
  61904. "\x68\x69\x63\x6b\x65\x6e\x2c\x20\x70\x6c\x65\x61\x73\x65\x2c\x20"
  61905. "\x61\x6e\x64\x20\x77\x6f\x6e\x74\x6f\x6e\x20\x73\x6f\x75\x70\x2e",
  61906. "\x97\x68\x72\x68\xd6\xec\xcc\xc0\xc0\x7b\x25\xe2\x5e\xcf\xe5\x84"
  61907. "\x39\x31\x25\x23\xa7\x86\x62\xd5\xbe\x7f\xcb\xcc\x98\xeb\xf5\xa8"
  61908. "\x48\x07\xef\xe8\x36\xee\x89\xa5\x26\x73\x0d\xbc\x2f\x7b\xc8\x40"
  61909. "\x9d\xad\x8b\xbb\x96\xc4\xcd\xc0\x3b\xc1\x03\xe1\xa1\x94\xbb\xd8",
  61910. 64, 64
  61911. }
  61912. };
  61913. byte keyBytes[AES_128_KEY_SIZE] = {
  61914. 0x63, 0x68, 0x69, 0x63, 0x6b, 0x65, 0x6e, 0x20,
  61915. 0x74, 0x65, 0x72, 0x69, 0x79, 0x61, 0x6b, 0x69
  61916. };
  61917. size_t i;
  61918. AES_KEY encKey;
  61919. byte iv[AES_IV_SIZE]; /* All-zero IV for all cases */
  61920. XMEMSET(tmp, 0, sizeof(tmp));
  61921. for (i = 0; i < sizeof(vects)/sizeof(vects[0]); i++) {
  61922. AES_KEY decKey;
  61923. ExpectIntEQ(AES_set_encrypt_key(keyBytes, AES_128_KEY_SIZE * 8,
  61924. &encKey), 0);
  61925. ExpectIntEQ(AES_set_decrypt_key(keyBytes, AES_128_KEY_SIZE * 8,
  61926. &decKey), 0);
  61927. XMEMSET(iv, 0, sizeof(iv));
  61928. ExpectIntEQ(CRYPTO_cts128_encrypt((const unsigned char*)vects[i].input,
  61929. tmp, vects[i].inLen, &encKey, iv, (cbc128_f)AES_cbc_encrypt),
  61930. vects[i].outLen);
  61931. ExpectIntEQ(XMEMCMP(tmp, vects[i].output, vects[i].outLen), 0);
  61932. XMEMSET(iv, 0, sizeof(iv));
  61933. ExpectIntEQ(CRYPTO_cts128_decrypt((const unsigned char*)vects[i].output,
  61934. tmp, vects[i].outLen, &decKey, iv, (cbc128_f)AES_cbc_encrypt),
  61935. vects[i].inLen);
  61936. ExpectIntEQ(XMEMCMP(tmp, vects[i].input, vects[i].inLen), 0);
  61937. }
  61938. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, NULL, 17, NULL, NULL, NULL), 0);
  61939. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, NULL, 17, NULL, NULL, NULL), 0);
  61940. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, tmp, 17, NULL, NULL, NULL), 0);
  61941. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, NULL, 17, &encKey, NULL, NULL), 0);
  61942. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, NULL, 17, NULL, iv, NULL), 0);
  61943. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, NULL, 17, NULL, NULL,
  61944. (cbc128_f)AES_cbc_encrypt), 0);
  61945. ExpectIntEQ(CRYPTO_cts128_encrypt(NULL, tmp, 17, &encKey, iv,
  61946. (cbc128_f)AES_cbc_encrypt), 0);
  61947. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, NULL, 17, &encKey, iv,
  61948. (cbc128_f)AES_cbc_encrypt), 0);
  61949. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, tmp, 17, NULL, iv,
  61950. (cbc128_f)AES_cbc_encrypt), 0);
  61951. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, tmp, 17, &encKey, NULL,
  61952. (cbc128_f)AES_cbc_encrypt), 0);
  61953. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, tmp, 17, &encKey, iv, NULL), 0);
  61954. /* Length too small. */
  61955. ExpectIntEQ(CRYPTO_cts128_encrypt(tmp, tmp, 0, &encKey, iv,
  61956. (cbc128_f)AES_cbc_encrypt), 0);
  61957. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, NULL, 17, NULL, NULL, NULL), 0);
  61958. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, NULL, 17, NULL, NULL, NULL), 0);
  61959. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, tmp, 17, NULL, NULL, NULL), 0);
  61960. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, NULL, 17, &encKey, NULL, NULL), 0);
  61961. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, NULL, 17, NULL, iv, NULL), 0);
  61962. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, NULL, 17, NULL, NULL,
  61963. (cbc128_f)AES_cbc_encrypt), 0);
  61964. ExpectIntEQ(CRYPTO_cts128_decrypt(NULL, tmp, 17, &encKey, iv,
  61965. (cbc128_f)AES_cbc_encrypt), 0);
  61966. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, NULL, 17, &encKey, iv,
  61967. (cbc128_f)AES_cbc_encrypt), 0);
  61968. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, tmp, 17, NULL, iv,
  61969. (cbc128_f)AES_cbc_encrypt), 0);
  61970. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, tmp, 17, &encKey, NULL,
  61971. (cbc128_f)AES_cbc_encrypt), 0);
  61972. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, tmp, 17, &encKey, iv, NULL), 0);
  61973. /* Length too small. */
  61974. ExpectIntEQ(CRYPTO_cts128_decrypt(tmp, tmp, 0, &encKey, iv,
  61975. (cbc128_f)AES_cbc_encrypt), 0);
  61976. #endif /* !NO_AES && HAVE_AES_CBC && OPENSSL_EXTRA && HAVE_CTS */
  61977. return EXPECT_RESULT();
  61978. }
  61979. static int test_wolfSSL_RC4(void)
  61980. {
  61981. EXPECT_DECLS;
  61982. #if !defined(NO_RC4) && defined(OPENSSL_EXTRA)
  61983. WOLFSSL_RC4_KEY rc4Key;
  61984. unsigned char key[] = {
  61985. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  61986. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  61987. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  61988. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  61989. };
  61990. unsigned char data[] = {
  61991. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  61992. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  61993. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  61994. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  61995. };
  61996. unsigned char enc[sizeof(data)];
  61997. unsigned char dec[sizeof(data)];
  61998. word32 i;
  61999. word32 j;
  62000. wolfSSL_RC4_set_key(NULL, -1, NULL);
  62001. wolfSSL_RC4_set_key(&rc4Key, -1, NULL);
  62002. wolfSSL_RC4_set_key(NULL, 0, NULL);
  62003. wolfSSL_RC4_set_key(NULL, -1, key);
  62004. wolfSSL_RC4_set_key(&rc4Key, 0, NULL);
  62005. wolfSSL_RC4_set_key(&rc4Key, -1, key);
  62006. wolfSSL_RC4_set_key(NULL, 0, key);
  62007. wolfSSL_RC4(NULL, 0, NULL, NULL);
  62008. wolfSSL_RC4(&rc4Key, 0, NULL, NULL);
  62009. wolfSSL_RC4(NULL, 0, data, NULL);
  62010. wolfSSL_RC4(NULL, 0, NULL, enc);
  62011. wolfSSL_RC4(&rc4Key, 0, data, NULL);
  62012. wolfSSL_RC4(&rc4Key, 0, NULL, enc);
  62013. wolfSSL_RC4(NULL, 0, data, enc);
  62014. ExpectIntEQ(1, 1);
  62015. for (i = 0; EXPECT_SUCCESS() && (i <= sizeof(key)); i++) {
  62016. for (j = 0; EXPECT_SUCCESS() && (j <= sizeof(data)); j++) {
  62017. XMEMSET(enc, 0, sizeof(enc));
  62018. XMEMSET(dec, 0, sizeof(dec));
  62019. /* Encrypt */
  62020. wolfSSL_RC4_set_key(&rc4Key, (int)i, key);
  62021. wolfSSL_RC4(&rc4Key, j, data, enc);
  62022. /* Decrypt */
  62023. wolfSSL_RC4_set_key(&rc4Key, (int)i, key);
  62024. wolfSSL_RC4(&rc4Key, j, enc, dec);
  62025. ExpectIntEQ(XMEMCMP(dec, data, j), 0);
  62026. }
  62027. }
  62028. #endif
  62029. return EXPECT_RESULT();
  62030. }
  62031. static int test_wolfSSL_OBJ(void)
  62032. {
  62033. /* Password "wolfSSL test" is only 12 (96-bit) too short for testing in FIPS
  62034. * mode
  62035. */
  62036. EXPECT_DECLS;
  62037. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA256) && !defined(NO_ASN) && \
  62038. !defined(HAVE_FIPS) && !defined(NO_SHA) && defined(WOLFSSL_CERT_EXT) && \
  62039. defined(WOLFSSL_CERT_GEN) && !defined(NO_BIO) && \
  62040. !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM)
  62041. ASN1_OBJECT *obj = NULL;
  62042. ASN1_OBJECT *obj2 = NULL;
  62043. char buf[50];
  62044. XFILE fp = XBADFILE;
  62045. X509 *x509 = NULL;
  62046. X509_NAME *x509Name = NULL;
  62047. X509_NAME_ENTRY *x509NameEntry = NULL;
  62048. ASN1_OBJECT *asn1Name = NULL;
  62049. int numNames = 0;
  62050. BIO *bio = NULL;
  62051. int nid;
  62052. int i, j;
  62053. const char *f[] = {
  62054. #ifndef NO_RSA
  62055. "./certs/ca-cert.der",
  62056. #endif
  62057. #ifdef HAVE_ECC
  62058. "./certs/ca-ecc-cert.der",
  62059. "./certs/ca-ecc384-cert.der",
  62060. #endif
  62061. NULL};
  62062. ASN1_OBJECT *field_name_obj = NULL;
  62063. int lastpos = -1;
  62064. int tmp = -1;
  62065. ASN1_STRING *asn1 = NULL;
  62066. unsigned char *buf_dyn = NULL;
  62067. ExpectIntEQ(OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  62068. ExpectNotNull(obj = OBJ_nid2obj(NID_any_policy));
  62069. ExpectIntEQ(OBJ_obj2nid(obj), NID_any_policy);
  62070. ExpectIntEQ(OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1), 11);
  62071. ExpectIntGT(OBJ_obj2txt(buf, (int)sizeof(buf), obj, 0), 0);
  62072. ASN1_OBJECT_free(obj);
  62073. obj = NULL;
  62074. ExpectNotNull(obj = OBJ_nid2obj(NID_sha256));
  62075. ExpectIntEQ(OBJ_obj2nid(obj), NID_sha256);
  62076. ExpectIntEQ(OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1), 22);
  62077. #ifdef WOLFSSL_CERT_EXT
  62078. ExpectIntEQ(OBJ_txt2nid(buf), NID_sha256);
  62079. #endif
  62080. ExpectIntGT(OBJ_obj2txt(buf, (int)sizeof(buf), obj, 0), 0);
  62081. ExpectNotNull(obj2 = OBJ_dup(obj));
  62082. ExpectIntEQ(OBJ_cmp(obj, obj2), 0);
  62083. ASN1_OBJECT_free(obj);
  62084. obj = NULL;
  62085. ASN1_OBJECT_free(obj2);
  62086. obj2 = NULL;
  62087. for (i = 0; f[i] != NULL; i++)
  62088. {
  62089. ExpectTrue((fp = XFOPEN(f[i], "rb")) != XBADFILE);
  62090. ExpectNotNull(x509 = d2i_X509_fp(fp, NULL));
  62091. if (fp != XBADFILE) {
  62092. XFCLOSE(fp);
  62093. fp = XBADFILE;
  62094. }
  62095. ExpectNotNull(x509Name = X509_get_issuer_name(x509));
  62096. ExpectIntNE((numNames = X509_NAME_entry_count(x509Name)), 0);
  62097. /* Get the Common Name by using OBJ_txt2obj */
  62098. ExpectNotNull(field_name_obj = OBJ_txt2obj("CN", 0));
  62099. do
  62100. {
  62101. lastpos = tmp;
  62102. tmp = X509_NAME_get_index_by_OBJ(x509Name, field_name_obj, lastpos);
  62103. } while (tmp > -1);
  62104. ExpectIntNE(lastpos, -1);
  62105. ASN1_OBJECT_free(field_name_obj);
  62106. field_name_obj = NULL;
  62107. ExpectNotNull(x509NameEntry = X509_NAME_get_entry(x509Name, lastpos));
  62108. ExpectNotNull(asn1 = X509_NAME_ENTRY_get_data(x509NameEntry));
  62109. ExpectIntGE(ASN1_STRING_to_UTF8(&buf_dyn, asn1), 0);
  62110. /*
  62111. * All Common Names should be www.wolfssl.com
  62112. * This makes testing easier as we can test for the expected value.
  62113. */
  62114. ExpectStrEQ((char*)buf_dyn, "www.wolfssl.com");
  62115. OPENSSL_free(buf_dyn);
  62116. buf_dyn = NULL;
  62117. bio = BIO_new(BIO_s_mem());
  62118. ExpectTrue(bio != NULL);
  62119. for (j = 0; j < numNames; j++)
  62120. {
  62121. ExpectNotNull(x509NameEntry = X509_NAME_get_entry(x509Name, j));
  62122. ExpectNotNull(asn1Name = X509_NAME_ENTRY_get_object(x509NameEntry));
  62123. ExpectTrue((nid = OBJ_obj2nid(asn1Name)) > 0);
  62124. }
  62125. BIO_free(bio);
  62126. bio = NULL;
  62127. X509_free(x509);
  62128. x509 = NULL;
  62129. }
  62130. #ifdef HAVE_PKCS12
  62131. {
  62132. PKCS12 *p12 = NULL;
  62133. int boolRet;
  62134. EVP_PKEY *pkey = NULL;
  62135. const char *p12_f[] = {
  62136. #if !defined(NO_DES3) && !defined(NO_RSA)
  62137. "./certs/test-servercert.p12",
  62138. #endif
  62139. NULL};
  62140. for (i = 0; p12_f[i] != NULL; i++)
  62141. {
  62142. ExpectTrue((fp = XFOPEN(p12_f[i], "rb")) != XBADFILE);
  62143. ExpectNotNull(p12 = d2i_PKCS12_fp(fp, NULL));
  62144. if (fp != XBADFILE) {
  62145. XFCLOSE(fp);
  62146. fp = XBADFILE;
  62147. }
  62148. ExpectTrue((boolRet = PKCS12_parse(p12, "wolfSSL test",
  62149. &pkey, &x509, NULL)) > 0);
  62150. wc_PKCS12_free(p12);
  62151. p12 = NULL;
  62152. EVP_PKEY_free(pkey);
  62153. x509Name = X509_get_issuer_name(x509);
  62154. ExpectNotNull(x509Name);
  62155. ExpectIntNE((numNames = X509_NAME_entry_count(x509Name)), 0);
  62156. ExpectTrue((bio = BIO_new(BIO_s_mem())) != NULL);
  62157. for (j = 0; j < numNames; j++)
  62158. {
  62159. ExpectNotNull(x509NameEntry = X509_NAME_get_entry(x509Name, j));
  62160. ExpectNotNull(asn1Name =
  62161. X509_NAME_ENTRY_get_object(x509NameEntry));
  62162. ExpectTrue((nid = OBJ_obj2nid(asn1Name)) > 0);
  62163. }
  62164. BIO_free(bio);
  62165. bio = NULL;
  62166. X509_free(x509);
  62167. x509 = NULL;
  62168. }
  62169. }
  62170. #endif /* HAVE_PKCS12 */
  62171. #endif
  62172. return EXPECT_RESULT();
  62173. }
  62174. static int test_wolfSSL_OBJ_cmp(void)
  62175. {
  62176. EXPECT_DECLS;
  62177. #if defined(OPENSSL_EXTRA) && !defined(NO_SHA256)
  62178. ASN1_OBJECT *obj = NULL;
  62179. ASN1_OBJECT *obj2 = NULL;
  62180. ExpectNotNull(obj = OBJ_nid2obj(NID_any_policy));
  62181. ExpectNotNull(obj2 = OBJ_nid2obj(NID_sha256));
  62182. ExpectIntEQ(OBJ_cmp(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  62183. ExpectIntEQ(OBJ_cmp(obj, NULL), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  62184. ExpectIntEQ(OBJ_cmp(NULL, obj2), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  62185. ExpectIntEQ(OBJ_cmp(obj, obj2), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  62186. ExpectIntEQ(OBJ_cmp(obj, obj), 0);
  62187. ExpectIntEQ(OBJ_cmp(obj2, obj2), 0);
  62188. ASN1_OBJECT_free(obj);
  62189. ASN1_OBJECT_free(obj2);
  62190. #endif
  62191. return EXPECT_RESULT();
  62192. }
  62193. static int test_wolfSSL_OBJ_txt2nid(void)
  62194. {
  62195. EXPECT_DECLS;
  62196. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
  62197. defined(WOLFSSL_APACHE_HTTPD)
  62198. int i;
  62199. static const struct {
  62200. const char* sn;
  62201. const char* ln;
  62202. const char* oid;
  62203. int nid;
  62204. } testVals[] = {
  62205. #ifdef WOLFSSL_APACHE_HTTPD
  62206. { "tlsfeature", "TLS Feature", "1.3.6.1.5.5.7.1.24", NID_tlsfeature },
  62207. { "id-on-dnsSRV", "SRVName", "1.3.6.1.5.5.7.8.7",
  62208. NID_id_on_dnsSRV },
  62209. { "msUPN", "Microsoft User Principal Name",
  62210. "1.3.6.1.4.1.311.20.2.3", NID_ms_upn },
  62211. #endif
  62212. { NULL, NULL, NULL, NID_undef }
  62213. };
  62214. /* Invalid cases */
  62215. ExpectIntEQ(OBJ_txt2nid(NULL), NID_undef);
  62216. ExpectIntEQ(OBJ_txt2nid("Bad name"), NID_undef);
  62217. /* Valid cases */
  62218. for (i = 0; testVals[i].sn != NULL; i++) {
  62219. ExpectIntEQ(OBJ_txt2nid(testVals[i].sn), testVals[i].nid);
  62220. ExpectIntEQ(OBJ_txt2nid(testVals[i].ln), testVals[i].nid);
  62221. ExpectIntEQ(OBJ_txt2nid(testVals[i].oid), testVals[i].nid);
  62222. }
  62223. #endif
  62224. return EXPECT_RESULT();
  62225. }
  62226. static int test_wolfSSL_OBJ_txt2obj(void)
  62227. {
  62228. EXPECT_DECLS;
  62229. #if defined(WOLFSSL_APACHE_HTTPD) || (defined(OPENSSL_EXTRA) && \
  62230. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN))
  62231. int i;
  62232. char buf[50];
  62233. ASN1_OBJECT* obj = NULL;
  62234. static const struct {
  62235. const char* oidStr;
  62236. const char* sn;
  62237. const char* ln;
  62238. } objs_list[] = {
  62239. #if defined(WOLFSSL_APACHE_HTTPD)
  62240. { "1.3.6.1.5.5.7.1.24", "tlsfeature", "TLS Feature" },
  62241. { "1.3.6.1.5.5.7.8.7", "id-on-dnsSRV", "SRVName" },
  62242. #endif
  62243. { "2.5.29.19", "basicConstraints", "X509v3 Basic Constraints"},
  62244. { NULL, NULL, NULL }
  62245. };
  62246. static const struct {
  62247. const char* numeric;
  62248. const char* name;
  62249. } objs_named[] = {
  62250. /* In dictionary but not in normal list. */
  62251. { "1.3.6.1.5.5.7.3.8", "Time Stamping" },
  62252. /* Made up OID. */
  62253. { "1.3.5.7", "1.3.5.7" },
  62254. { NULL, NULL }
  62255. };
  62256. ExpectNull(obj = OBJ_txt2obj("Bad name", 0));
  62257. ASN1_OBJECT_free(obj);
  62258. obj = NULL;
  62259. ExpectNull(obj = OBJ_txt2obj(NULL, 0));
  62260. ASN1_OBJECT_free(obj);
  62261. obj = NULL;
  62262. for (i = 0; objs_list[i].oidStr != NULL; i++) {
  62263. /* Test numerical value of oid (oidStr) */
  62264. ExpectNotNull(obj = OBJ_txt2obj(objs_list[i].oidStr, 1));
  62265. /* Convert object back to text to confirm oid is correct */
  62266. wolfSSL_OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1);
  62267. ExpectIntEQ(XSTRNCMP(buf, objs_list[i].oidStr, (int)XSTRLEN(buf)), 0);
  62268. ASN1_OBJECT_free(obj);
  62269. obj = NULL;
  62270. XMEMSET(buf, 0, sizeof(buf));
  62271. /* Test short name (sn) */
  62272. ExpectNull(obj = OBJ_txt2obj(objs_list[i].sn, 1));
  62273. ExpectNotNull(obj = OBJ_txt2obj(objs_list[i].sn, 0));
  62274. /* Convert object back to text to confirm oid is correct */
  62275. wolfSSL_OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1);
  62276. ExpectIntEQ(XSTRNCMP(buf, objs_list[i].oidStr, (int)XSTRLEN(buf)), 0);
  62277. ASN1_OBJECT_free(obj);
  62278. obj = NULL;
  62279. XMEMSET(buf, 0, sizeof(buf));
  62280. /* Test long name (ln) - should fail when no_name = 1 */
  62281. ExpectNull(obj = OBJ_txt2obj(objs_list[i].ln, 1));
  62282. ExpectNotNull(obj = OBJ_txt2obj(objs_list[i].ln, 0));
  62283. /* Convert object back to text to confirm oid is correct */
  62284. wolfSSL_OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1);
  62285. ExpectIntEQ(XSTRNCMP(buf, objs_list[i].oidStr, (int)XSTRLEN(buf)), 0);
  62286. ASN1_OBJECT_free(obj);
  62287. obj = NULL;
  62288. XMEMSET(buf, 0, sizeof(buf));
  62289. }
  62290. for (i = 0; objs_named[i].numeric != NULL; i++) {
  62291. ExpectNotNull(obj = OBJ_txt2obj(objs_named[i].numeric, 1));
  62292. wolfSSL_OBJ_obj2txt(buf, (int)sizeof(buf), obj, 0);
  62293. ExpectIntEQ(XSTRNCMP(buf, objs_named[i].name, (int)XSTRLEN(buf)), 0);
  62294. wolfSSL_OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1);
  62295. ExpectIntEQ(XSTRNCMP(buf, objs_named[i].numeric, (int)XSTRLEN(buf)), 0);
  62296. ASN1_OBJECT_free(obj);
  62297. obj = NULL;
  62298. }
  62299. #endif
  62300. return EXPECT_RESULT();
  62301. }
  62302. static int test_wolfSSL_PEM_write_bio_X509(void)
  62303. {
  62304. EXPECT_DECLS;
  62305. #if defined(OPENSSL_EXTRA) && defined(OPENSSL_ALL) && \
  62306. defined(WOLFSSL_AKID_NAME) && defined(WOLFSSL_CERT_EXT) && \
  62307. defined(WOLFSSL_CERT_GEN) && !defined(NO_BIO) && !defined(NO_RSA) && \
  62308. !defined(NO_FILESYSTEM)
  62309. /* This test contains the hard coded expected
  62310. * lengths. Update if necessary */
  62311. XFILE fp = XBADFILE;
  62312. WOLFSSL_EVP_PKEY *priv = NULL;
  62313. BIO* input = NULL;
  62314. BIO* output = NULL;
  62315. X509* x509a = NULL;
  62316. X509* x509b = NULL;
  62317. ASN1_TIME* notBeforeA = NULL;
  62318. ASN1_TIME* notAfterA = NULL;
  62319. #ifndef NO_ASN_TIME
  62320. ASN1_TIME* notBeforeB = NULL;
  62321. ASN1_TIME* notAfterB = NULL;
  62322. #endif
  62323. int expectedLen;
  62324. ExpectTrue((fp = XFOPEN("certs/server-key.pem", "rb")) != XBADFILE);
  62325. ExpectNotNull(priv = wolfSSL_PEM_read_PrivateKey(fp, NULL, NULL, NULL));
  62326. if (fp != XBADFILE) {
  62327. XFCLOSE(fp);
  62328. fp = XBADFILE;
  62329. }
  62330. ExpectNotNull(input = BIO_new_file("certs/test/cert-ext-multiple.pem",
  62331. "rb"));
  62332. ExpectIntEQ(wolfSSL_BIO_get_len(input), 2000);
  62333. /* read PEM into X509 struct, get notBefore / notAfter to verify against */
  62334. ExpectNotNull(PEM_read_bio_X509(input, &x509a, NULL, NULL));
  62335. ExpectNotNull(notBeforeA = X509_get_notBefore(x509a));
  62336. ExpectNotNull(notAfterA = X509_get_notAfter(x509a));
  62337. /* write X509 back to PEM BIO; no need to sign as nothing changed. */
  62338. ExpectNotNull(output = BIO_new(wolfSSL_BIO_s_mem()));
  62339. ExpectIntEQ(PEM_write_bio_X509(output, x509a), WOLFSSL_SUCCESS);
  62340. /* compare length against expected */
  62341. expectedLen = 2000;
  62342. ExpectIntEQ(wolfSSL_BIO_get_len(output), expectedLen);
  62343. #ifndef NO_ASN_TIME
  62344. /* read exported X509 PEM back into struct, sanity check on export,
  62345. * make sure notBefore/notAfter are the same and certs are identical. */
  62346. ExpectNotNull(PEM_read_bio_X509(output, &x509b, NULL, NULL));
  62347. ExpectNotNull(notBeforeB = X509_get_notBefore(x509b));
  62348. ExpectNotNull(notAfterB = X509_get_notAfter(x509b));
  62349. ExpectIntEQ(ASN1_TIME_compare(notBeforeA, notBeforeB), 0);
  62350. ExpectIntEQ(ASN1_TIME_compare(notAfterA, notAfterB), 0);
  62351. ExpectIntEQ(0, wolfSSL_X509_cmp(x509a, x509b));
  62352. X509_free(x509b);
  62353. x509b = NULL;
  62354. #endif
  62355. /* Reset output buffer */
  62356. BIO_free(output);
  62357. output = NULL;
  62358. ExpectNotNull(output = BIO_new(wolfSSL_BIO_s_mem()));
  62359. /* Test forcing the AKID to be generated just from KeyIdentifier */
  62360. if (EXPECT_SUCCESS() && x509a->authKeyIdSrc != NULL) {
  62361. XMEMMOVE(x509a->authKeyIdSrc, x509a->authKeyId, x509a->authKeyIdSz);
  62362. x509a->authKeyId = x509a->authKeyIdSrc;
  62363. x509a->authKeyIdSrc = NULL;
  62364. x509a->authKeyIdSrcSz = 0;
  62365. }
  62366. /* Resign to re-generate the der */
  62367. ExpectIntGT(wolfSSL_X509_sign(x509a, priv, EVP_sha256()), 0);
  62368. ExpectIntEQ(PEM_write_bio_X509(output, x509a), WOLFSSL_SUCCESS);
  62369. /* Check that we generate a smaller output since the AKID will
  62370. * only contain the KeyIdentifier without any additional
  62371. * information */
  62372. /* Here we copy the validity struct from the original */
  62373. expectedLen = 1688;
  62374. ExpectIntEQ(wolfSSL_BIO_get_len(output), expectedLen);
  62375. /* Reset buffers and x509 */
  62376. BIO_free(input);
  62377. input = NULL;
  62378. BIO_free(output);
  62379. output = NULL;
  62380. X509_free(x509a);
  62381. x509a = NULL;
  62382. /* test CA and basicConstSet values are encoded when
  62383. * the cert is a CA */
  62384. ExpectNotNull(input = BIO_new_file("certs/server-cert.pem", "rb"));
  62385. /* read PEM into X509 struct */
  62386. ExpectNotNull(PEM_read_bio_X509(input, &x509a, NULL, NULL));
  62387. /* write X509 back to PEM BIO; no need to sign as nothing changed */
  62388. ExpectNotNull(output = BIO_new(wolfSSL_BIO_s_mem()));
  62389. ExpectIntEQ(PEM_write_bio_X509(output, x509a), WOLFSSL_SUCCESS);
  62390. /* read exported X509 PEM back into struct, ensure isCa and basicConstSet
  62391. * values are maintained and certs are identical.*/
  62392. ExpectNotNull(PEM_read_bio_X509(output, &x509b, NULL, NULL));
  62393. ExpectIntEQ(x509b->isCa, 1);
  62394. ExpectIntEQ(x509b->basicConstSet, 1);
  62395. ExpectIntEQ(0, wolfSSL_X509_cmp(x509a, x509b));
  62396. X509_free(x509a);
  62397. x509a = NULL;
  62398. X509_free(x509b);
  62399. x509b = NULL;
  62400. BIO_free(input);
  62401. input = NULL;
  62402. BIO_free(output);
  62403. output = NULL;
  62404. /* test CA and basicConstSet values are encoded when
  62405. * the cert is not CA */
  62406. ExpectNotNull(input = BIO_new_file("certs/client-uri-cert.pem", "rb"));
  62407. /* read PEM into X509 struct */
  62408. ExpectNotNull(PEM_read_bio_X509(input, &x509a, NULL, NULL));
  62409. /* write X509 back to PEM BIO; no need to sign as nothing changed */
  62410. ExpectNotNull(output = BIO_new(wolfSSL_BIO_s_mem()));
  62411. ExpectIntEQ(PEM_write_bio_X509(output, x509a), WOLFSSL_SUCCESS);
  62412. /* read exported X509 PEM back into struct, ensure isCa and
  62413. * basicConstSet values are maintained and certs are identical */
  62414. ExpectNotNull(PEM_read_bio_X509(output, &x509b, NULL, NULL));
  62415. ExpectIntEQ(x509b->isCa, 0);
  62416. ExpectIntEQ(x509b->basicConstSet, 1);
  62417. ExpectIntEQ(0, wolfSSL_X509_cmp(x509a, x509b));
  62418. wolfSSL_EVP_PKEY_free(priv);
  62419. X509_free(x509a);
  62420. X509_free(x509b);
  62421. BIO_free(input);
  62422. BIO_free(output);
  62423. #endif
  62424. return EXPECT_RESULT();
  62425. }
  62426. static int test_wolfSSL_X509_NAME_ENTRY(void)
  62427. {
  62428. EXPECT_DECLS;
  62429. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  62430. !defined(NO_RSA) && defined(WOLFSSL_CERT_GEN)
  62431. X509* x509 = NULL;
  62432. #ifndef NO_BIO
  62433. BIO* bio = NULL;
  62434. #endif
  62435. X509_NAME* nm = NULL;
  62436. X509_NAME_ENTRY* entry = NULL;
  62437. unsigned char cn[] = "another name to add";
  62438. #ifdef OPENSSL_ALL
  62439. int i;
  62440. int names_len = 0;
  62441. #endif
  62442. ExpectNotNull(x509 =
  62443. wolfSSL_X509_load_certificate_file(cliCertFile, SSL_FILETYPE_PEM));
  62444. #ifndef NO_BIO
  62445. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  62446. ExpectIntEQ(PEM_write_bio_X509_AUX(bio, x509), SSL_SUCCESS);
  62447. #endif
  62448. #ifdef WOLFSSL_CERT_REQ
  62449. {
  62450. X509_REQ* req = NULL;
  62451. #ifndef NO_BIO
  62452. BIO* bReq = NULL;
  62453. #endif
  62454. ExpectNotNull(req =
  62455. wolfSSL_X509_load_certificate_file(cliCertFile, SSL_FILETYPE_PEM));
  62456. #ifndef NO_BIO
  62457. ExpectNotNull(bReq = BIO_new(BIO_s_mem()));
  62458. ExpectIntEQ(PEM_write_bio_X509_REQ(bReq, req), SSL_SUCCESS);
  62459. BIO_free(bReq);
  62460. #endif
  62461. X509_free(req);
  62462. }
  62463. #endif
  62464. ExpectNotNull(nm = X509_get_subject_name(x509));
  62465. /* Test add entry */
  62466. ExpectNotNull(entry = X509_NAME_ENTRY_create_by_NID(NULL, NID_commonName,
  62467. 0x0c, cn, (int)sizeof(cn)));
  62468. ExpectIntEQ(X509_NAME_add_entry(nm, entry, -1, 0), SSL_SUCCESS);
  62469. #ifdef WOLFSSL_CERT_EXT
  62470. ExpectIntEQ(X509_NAME_add_entry_by_txt(nm, "emailAddress", MBSTRING_UTF8,
  62471. (byte*)"support@wolfssl.com", 19, -1,
  62472. 1), WOLFSSL_SUCCESS);
  62473. #endif
  62474. X509_NAME_ENTRY_free(entry);
  62475. entry = NULL;
  62476. #ifdef WOLFSSL_CERT_REQ
  62477. {
  62478. unsigned char srv_pkcs9p[] = "Server";
  62479. unsigned char fvrtDrnk[] = "tequila";
  62480. unsigned char* der = NULL;
  62481. char* subject = NULL;
  62482. ExpectIntEQ(X509_NAME_add_entry_by_NID(nm, NID_pkcs9_contentType,
  62483. MBSTRING_ASC, srv_pkcs9p, -1, -1, 0), SSL_SUCCESS);
  62484. ExpectIntEQ(X509_NAME_add_entry_by_NID(nm, NID_favouriteDrink,
  62485. MBSTRING_ASC, fvrtDrnk, -1, -1, 0), SSL_SUCCESS);
  62486. ExpectIntGT(wolfSSL_i2d_X509_NAME(nm, &der), 0);
  62487. ExpectNotNull(der);
  62488. ExpectNotNull(subject = X509_NAME_oneline(nm, 0, 0));
  62489. ExpectNotNull(XSTRSTR(subject, "favouriteDrink=tequila"));
  62490. ExpectNotNull(XSTRSTR(subject, "contentType=Server"));
  62491. #ifdef DEBUG_WOLFSSL
  62492. if (subject != NULL) {
  62493. fprintf(stderr, "\n\t%s\n", subject);
  62494. }
  62495. #endif
  62496. XFREE(subject, 0, DYNAMIC_TYPE_OPENSSL);
  62497. XFREE(der, NULL, DYNAMIC_TYPE_OPENSSL);
  62498. }
  62499. #endif
  62500. /* Test add entry by text */
  62501. ExpectNotNull(entry = X509_NAME_ENTRY_create_by_txt(NULL, "commonName",
  62502. 0x0c, cn, (int)sizeof(cn)));
  62503. #if defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO) \
  62504. || defined(WOLFSSL_HAPROXY) || defined(WOLFSSL_NGINX)
  62505. ExpectNull(X509_NAME_ENTRY_create_by_txt(&entry, "unknown",
  62506. V_ASN1_UTF8STRING, cn, (int)sizeof(cn)));
  62507. #endif
  62508. ExpectIntEQ(X509_NAME_add_entry(nm, entry, -1, 0), SSL_SUCCESS);
  62509. X509_NAME_ENTRY_free(entry);
  62510. entry = NULL;
  62511. /* Test add entry by NID */
  62512. ExpectIntEQ(X509_NAME_add_entry_by_NID(nm, NID_commonName, MBSTRING_UTF8,
  62513. cn, -1, -1, 0), SSL_SUCCESS);
  62514. #ifdef OPENSSL_ALL
  62515. /* stack of name entry */
  62516. ExpectIntGT((names_len = sk_X509_NAME_ENTRY_num(nm->entries)), 0);
  62517. for (i = 0; i < names_len; i++) {
  62518. ExpectNotNull(entry = sk_X509_NAME_ENTRY_value(nm->entries, i));
  62519. }
  62520. #endif
  62521. #ifndef NO_BIO
  62522. BIO_free(bio);
  62523. #endif
  62524. X509_free(x509); /* free's nm */
  62525. #endif
  62526. return EXPECT_RESULT();
  62527. }
  62528. /* Note the lack of wolfSSL_ prefix...this is a compatibility layer test. */
  62529. static int test_GENERAL_NAME_set0_othername(void) {
  62530. EXPECT_DECLS;
  62531. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  62532. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && \
  62533. defined(WOLFSSL_CUSTOM_OID) && defined(WOLFSSL_ALT_NAMES) && \
  62534. defined(WOLFSSL_CERT_EXT) && !defined(NO_FILESYSTEM) && \
  62535. defined(WOLFSSL_FPKI)
  62536. /* ./configure --enable-opensslall --enable-certgen --enable-certreq
  62537. * --enable-certext --enable-debug 'CPPFLAGS=-DWOLFSSL_CUSTOM_OID
  62538. * -DWOLFSSL_ALT_NAMES -DWOLFSSL_FPKI' */
  62539. const char * cert_fname = "./certs/server-cert.der";
  62540. const char * key_fname = "./certs/server-key.der";
  62541. X509* x509 = NULL;
  62542. GENERAL_NAME* gn = NULL;
  62543. GENERAL_NAMES* gns = NULL;
  62544. ASN1_OBJECT* upn_oid = NULL;
  62545. ASN1_UTF8STRING *utf8str = NULL;
  62546. ASN1_TYPE *value = NULL;
  62547. X509_EXTENSION * ext = NULL;
  62548. byte* pt = NULL;
  62549. byte der[4096];
  62550. int derSz = 0;
  62551. EVP_PKEY* priv = NULL;
  62552. XFILE f = XBADFILE;
  62553. ExpectTrue((f = XFOPEN(cert_fname, "rb")) != XBADFILE);
  62554. ExpectNotNull(x509 = d2i_X509_fp(f, NULL));
  62555. if (f != XBADFILE) {
  62556. XFCLOSE(f);
  62557. f = XBADFILE;
  62558. }
  62559. ExpectNotNull(gn = GENERAL_NAME_new());
  62560. ExpectNotNull(upn_oid = OBJ_txt2obj("1.3.6.1.4.1.311.20.2.3", 1));
  62561. ExpectNotNull(utf8str = ASN1_UTF8STRING_new());
  62562. ExpectIntEQ(ASN1_STRING_set(utf8str, "othername@wolfssl.com", -1), 1);
  62563. ExpectNotNull(value = ASN1_TYPE_new());
  62564. ASN1_TYPE_set(value, V_ASN1_UTF8STRING, utf8str);
  62565. if ((value == NULL) || (value->value.ptr != (char*)utf8str)) {
  62566. wolfSSL_ASN1_STRING_free(utf8str);
  62567. }
  62568. ExpectIntEQ(GENERAL_NAME_set0_othername(gn, upn_oid, value), 1);
  62569. if (EXPECT_FAIL()) {
  62570. ASN1_TYPE_free(value);
  62571. }
  62572. ExpectNotNull(gns = sk_GENERAL_NAME_new(NULL));
  62573. ExpectIntEQ(sk_GENERAL_NAME_push(gns, gn), 1);
  62574. if (EXPECT_FAIL()) {
  62575. GENERAL_NAME_free(gn);
  62576. gn = NULL;
  62577. }
  62578. ExpectNotNull(ext = X509V3_EXT_i2d(NID_subject_alt_name, 0, gns));
  62579. ExpectIntEQ(X509_add_ext(x509, ext, -1), 1);
  62580. ExpectTrue((f = XFOPEN(key_fname, "rb")) != XBADFILE);
  62581. ExpectIntGT(derSz = (int)XFREAD(der, 1, sizeof(der), f), 0);
  62582. if (f != XBADFILE) {
  62583. XFCLOSE(f);
  62584. f = XBADFILE;
  62585. }
  62586. pt = der;
  62587. ExpectNotNull(priv = d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  62588. (const unsigned char**)&pt, derSz));
  62589. ExpectIntGT(X509_sign(x509, priv, EVP_sha256()), 0);
  62590. sk_GENERAL_NAME_pop_free(gns, GENERAL_NAME_free);
  62591. gns = NULL;
  62592. ExpectNotNull(gns = (GENERAL_NAMES*)X509_get_ext_d2i(x509,
  62593. NID_subject_alt_name, NULL, NULL));
  62594. ExpectIntEQ(sk_GENERAL_NAME_num(gns), 3);
  62595. ExpectNotNull(gn = sk_GENERAL_NAME_value(gns, 2));
  62596. ExpectIntEQ(gn->type, 0);
  62597. sk_GENERAL_NAME_pop_free(gns, GENERAL_NAME_free);
  62598. ASN1_OBJECT_free(upn_oid);
  62599. X509_EXTENSION_free(ext);
  62600. X509_free(x509);
  62601. EVP_PKEY_free(priv);
  62602. #endif
  62603. return EXPECT_RESULT();
  62604. }
  62605. /* Note the lack of wolfSSL_ prefix...this is a compatibility layer test. */
  62606. static int test_othername_and_SID_ext(void) {
  62607. EXPECT_DECLS;
  62608. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  62609. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && \
  62610. defined(WOLFSSL_CUSTOM_OID) && defined(WOLFSSL_ALT_NAMES) && \
  62611. defined(WOLFSSL_CERT_EXT) && !defined(NO_FILESYSTEM) && \
  62612. defined(WOLFSSL_FPKI) && defined(WOLFSSL_ASN_TEMPLATE)
  62613. /* ./configure --enable-opensslall --enable-certgen --enable-certreq
  62614. * --enable-certext --enable-debug 'CPPFLAGS=-DWOLFSSL_CUSTOM_OID
  62615. * -DWOLFSSL_ALT_NAMES -DWOLFSSL_FPKI' */
  62616. const char* csr_fname = "./certs/csr.signed.der";
  62617. const char* key_fname = "./certs/server-key.der";
  62618. byte der[4096];
  62619. int derSz = 0;
  62620. X509_REQ* x509 = NULL;
  62621. STACK_OF(X509_EXTENSION) *exts = NULL;
  62622. X509_EXTENSION * san_ext = NULL;
  62623. X509_EXTENSION * ext = NULL;
  62624. GENERAL_NAME* gn = NULL;
  62625. GENERAL_NAMES* gns = NULL;
  62626. ASN1_OBJECT* upn_oid = NULL;
  62627. ASN1_UTF8STRING *utf8str = NULL;
  62628. ASN1_TYPE *value = NULL;
  62629. ASN1_STRING *extval = NULL;
  62630. /* SID extension. SID data format explained here:
  62631. * https://blog.qdsecurity.se/2022/05/27/manually-injecting-a-sid-in-a-certificate/
  62632. */
  62633. byte SidExtension[] = {
  62634. 48, 64, 160, 62, 6, 10, 43, 6, 1, 4, 1, 130, 55, 25, 2, 1, 160,
  62635. 48, 4, 46, 83, 45, 49, 45, 53, 45, 50, 49, 45, 50, 56, 52, 51, 57,
  62636. 48, 55, 52, 49, 56, 45, 51, 57, 50, 54, 50, 55, 55, 52, 50, 49, 45,
  62637. 51, 56, 49, 53, 57, 57, 51, 57, 55, 50, 45, 52, 54, 48, 49};
  62638. byte expectedAltName[] = {
  62639. 0x30, 0x27, 0xA0, 0x25, 0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82,
  62640. 0x37, 0x14, 0x02, 0x03, 0xA0, 0x17, 0x0C, 0x15, 0x6F, 0x74, 0x68, 0x65,
  62641. 0x72, 0x6E, 0x61, 0x6D, 0x65, 0x40, 0x77, 0x6F, 0x6C, 0x66, 0x73, 0x73,
  62642. 0x6C, 0x2E, 0x63, 0x6F, 0x6D};
  62643. X509_EXTENSION *sid_ext = NULL;
  62644. ASN1_OBJECT* sid_oid = NULL;
  62645. ASN1_OCTET_STRING *sid_data = NULL;
  62646. ASN1_OBJECT* alt_names_oid = NULL;
  62647. EVP_PKEY* priv = NULL;
  62648. XFILE f = XBADFILE;
  62649. byte* pt = NULL;
  62650. BIO* bio = NULL;
  62651. ExpectTrue((f = XFOPEN(csr_fname, "rb")) != XBADFILE);
  62652. ExpectNotNull(x509 = d2i_X509_REQ_fp(f, NULL));
  62653. if (f != XBADFILE) {
  62654. XFCLOSE(f);
  62655. f = XBADFILE;
  62656. }
  62657. ExpectIntEQ(X509_REQ_set_version(x509, 2), 1);
  62658. ExpectNotNull(gn = GENERAL_NAME_new());
  62659. ExpectNotNull(upn_oid = OBJ_txt2obj("1.3.6.1.4.1.311.20.2.3", 1));
  62660. ExpectNotNull(utf8str = ASN1_UTF8STRING_new());
  62661. ExpectIntEQ(ASN1_STRING_set(utf8str, "othername@wolfssl.com", -1), 1);
  62662. ExpectNotNull(value = ASN1_TYPE_new());
  62663. ASN1_TYPE_set(value, V_ASN1_UTF8STRING, utf8str);
  62664. if (EXPECT_FAIL()) {
  62665. ASN1_UTF8STRING_free(utf8str);
  62666. }
  62667. ExpectIntEQ(GENERAL_NAME_set0_othername(gn, upn_oid, value), 1);
  62668. if (EXPECT_FAIL()) {
  62669. ASN1_TYPE_free(value);
  62670. GENERAL_NAME_free(gn);
  62671. gn = NULL;
  62672. }
  62673. ExpectNotNull(gns = sk_GENERAL_NAME_new(NULL));
  62674. ExpectIntEQ(sk_GENERAL_NAME_push(gns, gn), 1);
  62675. if (EXPECT_FAIL()) {
  62676. GENERAL_NAME_free(gn);
  62677. }
  62678. ExpectNotNull(san_ext = X509V3_EXT_i2d(NID_subject_alt_name, 0, gns));
  62679. ExpectNotNull(sid_oid = OBJ_txt2obj("1.3.6.1.4.1.311.25.2", 1));
  62680. ExpectNotNull(sid_data = ASN1_OCTET_STRING_new());
  62681. ASN1_OCTET_STRING_set(sid_data, SidExtension, sizeof(SidExtension));
  62682. ExpectNotNull(sid_ext = X509_EXTENSION_create_by_OBJ(NULL, sid_oid, 0,
  62683. sid_data));
  62684. ExpectNotNull(exts = sk_X509_EXTENSION_new_null());
  62685. /* Ensure an empty stack doesn't raise an error. */
  62686. ExpectIntEQ(X509_REQ_add_extensions(x509, exts), 1);
  62687. ExpectIntEQ(sk_X509_EXTENSION_push(exts, san_ext), 1);
  62688. if (EXPECT_FAIL()) {
  62689. X509_EXTENSION_free(san_ext);
  62690. }
  62691. ExpectIntEQ(sk_X509_EXTENSION_push(exts, sid_ext), 2);
  62692. if (EXPECT_FAIL()) {
  62693. X509_EXTENSION_free(sid_ext);
  62694. }
  62695. ExpectIntEQ(X509_REQ_add_extensions(x509, exts), 1);
  62696. ExpectTrue((f = XFOPEN(key_fname, "rb")) != XBADFILE);
  62697. ExpectIntGT(derSz = (int)XFREAD(der, 1, sizeof(der), f), 0);
  62698. if (f != XBADFILE)
  62699. XFCLOSE(f);
  62700. pt = der;
  62701. ExpectNotNull(priv = d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  62702. (const unsigned char**)&pt, derSz));
  62703. ExpectIntGT(X509_REQ_sign(x509, priv, EVP_sha256()), 0);
  62704. pt = der;
  62705. ExpectIntGT(derSz = i2d_X509_REQ(x509, &pt), 0);
  62706. X509_REQ_free(x509);
  62707. x509 = NULL;
  62708. pt = der;
  62709. ExpectNotNull(d2i_X509_REQ_INFO(&x509, (const unsigned char**)&pt, derSz));
  62710. sk_GENERAL_NAME_pop_free(gns, GENERAL_NAME_free);
  62711. gns = NULL;
  62712. sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
  62713. exts = NULL;
  62714. ASN1_OBJECT_free(upn_oid);
  62715. ASN1_OBJECT_free(sid_oid);
  62716. ASN1_OCTET_STRING_free(sid_data);
  62717. X509_REQ_free(x509);
  62718. EVP_PKEY_free(priv);
  62719. /* At this point everything used to generate what is in der is cleaned up.
  62720. * We now read back from der to confirm the extensions were inserted
  62721. * correctly. */
  62722. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem());
  62723. ExpectNotNull(bio);
  62724. ExpectIntEQ(BIO_write(bio, der, derSz), derSz); /* d2i consumes BIO */
  62725. ExpectNotNull(d2i_X509_REQ_bio(bio, &x509));
  62726. ExpectNotNull(x509);
  62727. BIO_free(bio);
  62728. ExpectNotNull(exts = (STACK_OF(X509_EXTENSION)*)X509_REQ_get_extensions(
  62729. x509));
  62730. ExpectIntEQ(sk_X509_EXTENSION_num(exts), 2);
  62731. /* Check the SID extension. */
  62732. ExpectNotNull(sid_oid = OBJ_txt2obj("1.3.6.1.4.1.311.25.2", 1));
  62733. ExpectNotNull(ext = sk_X509_EXTENSION_value(exts,
  62734. X509_get_ext_by_OBJ(x509, sid_oid, -1)));
  62735. ExpectNotNull(extval = X509_EXTENSION_get_data(ext));
  62736. ExpectIntEQ(extval->length, sizeof(SidExtension));
  62737. ExpectIntEQ(XMEMCMP(SidExtension, extval->data, sizeof(SidExtension)), 0);
  62738. ASN1_OBJECT_free(sid_oid);
  62739. /* Check the AltNames extension. */
  62740. ExpectNotNull(alt_names_oid = OBJ_txt2obj("subjectAltName", 0));
  62741. ExpectNotNull(ext = sk_X509_EXTENSION_value(exts,
  62742. X509_get_ext_by_OBJ(x509, alt_names_oid, -1)));
  62743. ExpectNotNull(extval = X509_EXTENSION_get_data(ext));
  62744. ExpectIntEQ(extval->length, sizeof(expectedAltName));
  62745. ExpectIntEQ(XMEMCMP(expectedAltName, extval->data, sizeof(expectedAltName)),
  62746. 0);
  62747. ASN1_OBJECT_free(alt_names_oid);
  62748. /* Cleanup */
  62749. ExpectNotNull(gns = (GENERAL_NAMES*)X509_get_ext_d2i(x509,
  62750. NID_subject_alt_name, NULL, NULL));
  62751. ExpectIntEQ(sk_GENERAL_NAME_num(gns), 1);
  62752. ExpectNotNull(gn = sk_GENERAL_NAME_value(gns, 0));
  62753. ExpectIntEQ(gn->type, 0);
  62754. sk_GENERAL_NAME_pop_free(gns, GENERAL_NAME_free);
  62755. sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
  62756. X509_REQ_free(x509);
  62757. #endif
  62758. return EXPECT_RESULT();
  62759. }
  62760. static int test_wolfSSL_X509_set_name(void)
  62761. {
  62762. EXPECT_DECLS;
  62763. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  62764. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ)
  62765. X509* x509 = NULL;
  62766. X509_NAME* name = NULL;
  62767. ExpectNotNull(name = X509_NAME_new());
  62768. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  62769. (byte*)"wolfssl.com", 11, 0, 1),
  62770. WOLFSSL_SUCCESS);
  62771. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  62772. (byte*)"support@wolfssl.com", 19, -1,
  62773. 1), WOLFSSL_SUCCESS);
  62774. ExpectNotNull(x509 = X509_new());
  62775. ExpectIntEQ(X509_set_subject_name(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  62776. ExpectIntEQ(X509_set_subject_name(x509, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  62777. ExpectIntEQ(X509_set_subject_name(NULL, name), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  62778. ExpectIntEQ(X509_set_subject_name(x509, name), WOLFSSL_SUCCESS);
  62779. ExpectIntEQ(X509_set_issuer_name(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  62780. ExpectIntEQ(X509_set_issuer_name(x509, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  62781. ExpectIntEQ(X509_set_issuer_name(NULL, name), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  62782. ExpectIntEQ(X509_set_issuer_name(x509, name), WOLFSSL_SUCCESS);
  62783. X509_free(x509);
  62784. X509_NAME_free(name);
  62785. #endif /* OPENSSL_ALL && !NO_CERTS */
  62786. return EXPECT_RESULT();
  62787. }
  62788. static int test_wolfSSL_X509_set_notAfter(void)
  62789. {
  62790. EXPECT_DECLS;
  62791. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) \
  62792. && !defined(NO_ASN_TIME) && !defined(USER_TIME) && \
  62793. !defined(TIME_OVERRIDES) && !defined(NO_CERTS) && \
  62794. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) &&\
  62795. !defined(TIME_T_NOT_64BIT) && !defined(NO_64BIT) && !defined(NO_BIO)
  62796. /* Generalized time will overflow time_t if not long */
  62797. X509* x = NULL;
  62798. BIO* bio = NULL;
  62799. ASN1_TIME *asn_time = NULL;
  62800. ASN1_TIME *time_check = NULL;
  62801. const int year = 365*24*60*60;
  62802. const int day = 24*60*60;
  62803. const int hour = 60*60;
  62804. const int mini = 60;
  62805. int offset_day;
  62806. unsigned char buf[25];
  62807. time_t t;
  62808. /*
  62809. * Setup asn_time. APACHE HTTPD uses time(NULL)
  62810. */
  62811. t = (time_t)107 * year + 31 * day + 34 * hour + 30 * mini + 7 * day;
  62812. offset_day = 7;
  62813. /*
  62814. * Free these.
  62815. */
  62816. asn_time = wolfSSL_ASN1_TIME_adj(NULL, t, offset_day, 0);
  62817. ExpectNotNull(asn_time);
  62818. ExpectNotNull(x = X509_new());
  62819. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  62820. /*
  62821. * Tests
  62822. */
  62823. ExpectTrue(wolfSSL_X509_set_notAfter(x, asn_time));
  62824. /* time_check is simply (ANS1_TIME*)x->notAfter */
  62825. ExpectNotNull(time_check = X509_get_notAfter(x));
  62826. /* ANS1_TIME_check validates by checking if argument can be parsed */
  62827. ExpectIntEQ(ASN1_TIME_check(time_check), WOLFSSL_SUCCESS);
  62828. /* Convert to human readable format and compare to intended date */
  62829. ExpectIntEQ(ASN1_TIME_print(bio, time_check), 1);
  62830. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 24);
  62831. ExpectIntEQ(XMEMCMP(buf, "Jan 20 10:30:00 2077 GMT", sizeof(buf) - 1), 0);
  62832. ExpectFalse(wolfSSL_X509_set_notAfter(NULL, NULL));
  62833. ExpectFalse(wolfSSL_X509_set_notAfter(x, NULL));
  62834. ExpectFalse(wolfSSL_X509_set_notAfter(NULL, asn_time));
  62835. /*
  62836. * Cleanup
  62837. */
  62838. XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
  62839. X509_free(x);
  62840. BIO_free(bio);
  62841. #endif
  62842. return EXPECT_RESULT();
  62843. }
  62844. static int test_wolfSSL_X509_set_notBefore(void)
  62845. {
  62846. EXPECT_DECLS;
  62847. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) \
  62848. && !defined(NO_ASN_TIME) && !defined(USER_TIME) && \
  62849. !defined(TIME_OVERRIDES) && !defined(NO_CERTS) && \
  62850. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && !defined(NO_BIO)
  62851. X509* x = NULL;
  62852. BIO* bio = NULL;
  62853. ASN1_TIME *asn_time = NULL;
  62854. ASN1_TIME *time_check = NULL;
  62855. const int year = 365*24*60*60;
  62856. const int day = 24*60*60;
  62857. const int hour = 60*60;
  62858. const int mini = 60;
  62859. int offset_day;
  62860. unsigned char buf[25];
  62861. time_t t;
  62862. /*
  62863. * Setup asn_time. APACHE HTTPD uses time(NULL)
  62864. */
  62865. t = (time_t)49 * year + 125 * day + 20 * hour + 30 * mini + 7 * day;
  62866. offset_day = 7;
  62867. /*
  62868. * Free these.
  62869. */
  62870. asn_time = wolfSSL_ASN1_TIME_adj(NULL, t, offset_day, 0);
  62871. ExpectNotNull(asn_time);
  62872. ExpectNotNull(x = X509_new());
  62873. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  62874. ExpectIntEQ(ASN1_TIME_check(asn_time), WOLFSSL_SUCCESS);
  62875. /*
  62876. * Main Tests
  62877. */
  62878. ExpectTrue(wolfSSL_X509_set_notBefore(x, asn_time));
  62879. /* time_check == (ANS1_TIME*)x->notBefore */
  62880. ExpectNotNull(time_check = X509_get_notBefore(x));
  62881. /* ANS1_TIME_check validates by checking if argument can be parsed */
  62882. ExpectIntEQ(ASN1_TIME_check(time_check), WOLFSSL_SUCCESS);
  62883. /* Convert to human readable format and compare to intended date */
  62884. ExpectIntEQ(ASN1_TIME_print(bio, time_check), 1);
  62885. ExpectIntEQ(BIO_read(bio, buf, sizeof(buf)), 24);
  62886. ExpectIntEQ(XMEMCMP(buf, "May 8 20:30:00 2019 GMT", sizeof(buf) - 1), 0);
  62887. ExpectFalse(wolfSSL_X509_set_notBefore(NULL, NULL));
  62888. ExpectFalse(wolfSSL_X509_set_notBefore(x, NULL));
  62889. ExpectFalse(wolfSSL_X509_set_notBefore(NULL, asn_time));
  62890. /*
  62891. * Cleanup
  62892. */
  62893. XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
  62894. X509_free(x);
  62895. BIO_free(bio);
  62896. #endif
  62897. return EXPECT_RESULT();
  62898. }
  62899. static int test_wolfSSL_X509_set_version(void)
  62900. {
  62901. EXPECT_DECLS;
  62902. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_APACHE_HTTPD)) && \
  62903. !defined(NO_CERTS) && defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ)
  62904. X509* x509 = NULL;
  62905. long v = 2L;
  62906. long maxInt = INT_MAX;
  62907. ExpectNotNull(x509 = X509_new());
  62908. /* These should pass. */
  62909. ExpectTrue(wolfSSL_X509_set_version(x509, v));
  62910. ExpectIntEQ(v, wolfSSL_X509_get_version(x509));
  62911. /* Fail Case: When v(long) is greater than x509->version(int). */
  62912. v = maxInt+1;
  62913. ExpectFalse(wolfSSL_X509_set_version(x509, v));
  62914. ExpectFalse(wolfSSL_X509_set_version(NULL, 2L));
  62915. ExpectFalse(wolfSSL_X509_set_version(NULL, maxInt+1));
  62916. /* Cleanup */
  62917. X509_free(x509);
  62918. #endif
  62919. return EXPECT_RESULT();
  62920. }
  62921. #ifndef NO_BIO
  62922. static int test_wolfSSL_BIO_gets(void)
  62923. {
  62924. EXPECT_DECLS;
  62925. #if defined(OPENSSL_EXTRA)
  62926. BIO* bio = NULL;
  62927. BIO* bio2 = NULL;
  62928. char msg[] = "\nhello wolfSSL\n security plus\t---...**adf\na...b.c";
  62929. char emp[] = "";
  62930. char bio_buffer[20];
  62931. int bufferSz = 20;
  62932. #ifdef OPENSSL_ALL
  62933. BUF_MEM* emp_bm = NULL;
  62934. BUF_MEM* msg_bm = NULL;
  62935. #endif
  62936. /* try with bad args */
  62937. ExpectNull(bio = BIO_new_mem_buf(NULL, sizeof(msg)));
  62938. #ifdef OPENSSL_ALL
  62939. ExpectIntEQ(BIO_set_mem_buf(bio, NULL, BIO_NOCLOSE), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  62940. #endif
  62941. /* try with real msg */
  62942. ExpectNotNull(bio = BIO_new_mem_buf((void*)msg, -1));
  62943. XMEMSET(bio_buffer, 0, bufferSz);
  62944. ExpectNotNull(BIO_push(bio, BIO_new(BIO_s_bio())));
  62945. ExpectNull(bio2 = BIO_find_type(bio, BIO_TYPE_FILE));
  62946. ExpectNotNull(bio2 = BIO_find_type(bio, BIO_TYPE_BIO));
  62947. ExpectFalse(bio2 != BIO_next(bio));
  62948. /* make buffer filled with no terminating characters */
  62949. XMEMSET(bio_buffer, 1, bufferSz);
  62950. /* BIO_gets reads a line of data */
  62951. ExpectIntEQ(BIO_gets(bio, bio_buffer, -3), 0);
  62952. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 1);
  62953. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 14);
  62954. ExpectStrEQ(bio_buffer, "hello wolfSSL\n");
  62955. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 19);
  62956. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 8);
  62957. ExpectIntEQ(BIO_gets(bio, bio_buffer, -1), 0);
  62958. #ifdef OPENSSL_ALL
  62959. /* test setting the mem_buf manually */
  62960. BIO_free(bio);
  62961. ExpectNotNull(bio = BIO_new_mem_buf((void*)msg, -1));
  62962. ExpectNotNull(emp_bm = BUF_MEM_new());
  62963. ExpectNotNull(msg_bm = BUF_MEM_new());
  62964. ExpectIntEQ(BUF_MEM_grow(msg_bm, sizeof(msg)), sizeof(msg));
  62965. if (EXPECT_SUCCESS()) {
  62966. XFREE(msg_bm->data, NULL, DYNAMIC_TYPE_OPENSSL);
  62967. msg_bm->data = NULL;
  62968. }
  62969. /* emp size is 1 for terminator */
  62970. ExpectIntEQ(BUF_MEM_grow(emp_bm, sizeof(emp)), sizeof(emp));
  62971. if (EXPECT_SUCCESS()) {
  62972. XFREE(emp_bm->data, NULL, DYNAMIC_TYPE_OPENSSL);
  62973. emp_bm->data = emp;
  62974. msg_bm->data = msg;
  62975. }
  62976. ExpectIntEQ(BIO_set_mem_buf(bio, emp_bm, BIO_CLOSE), WOLFSSL_SUCCESS);
  62977. /* check reading an empty string */
  62978. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 1); /* just terminator */
  62979. ExpectStrEQ(emp, bio_buffer);
  62980. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 0); /* Nothing to read */
  62981. /* BIO_gets reads a line of data */
  62982. ExpectIntEQ(BIO_set_mem_buf(bio, msg_bm, BIO_NOCLOSE), WOLFSSL_SUCCESS);
  62983. ExpectIntEQ(BIO_gets(bio, bio_buffer, -3), 0);
  62984. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 1);
  62985. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 14);
  62986. ExpectStrEQ(bio_buffer, "hello wolfSSL\n");
  62987. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 19);
  62988. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 8);
  62989. ExpectIntEQ(BIO_gets(bio, bio_buffer, -1), 0);
  62990. if (EXPECT_SUCCESS())
  62991. emp_bm->data = NULL;
  62992. BUF_MEM_free(emp_bm);
  62993. if (EXPECT_SUCCESS())
  62994. msg_bm->data = NULL;
  62995. BUF_MEM_free(msg_bm);
  62996. #endif
  62997. /* check not null terminated string */
  62998. BIO_free(bio);
  62999. bio = NULL;
  63000. msg[0] = 0x33;
  63001. msg[1] = 0x33;
  63002. msg[2] = 0x33;
  63003. ExpectNotNull(bio = BIO_new_mem_buf((void*)msg, 3));
  63004. ExpectIntEQ(BIO_gets(bio, bio_buffer, 3), 2);
  63005. ExpectIntEQ(bio_buffer[0], msg[0]);
  63006. ExpectIntEQ(bio_buffer[1], msg[1]);
  63007. ExpectIntNE(bio_buffer[2], msg[2]);
  63008. BIO_free(bio);
  63009. bio = NULL;
  63010. msg[3] = 0x33;
  63011. bio_buffer[3] = 0x33;
  63012. ExpectNotNull(bio = BIO_new_mem_buf((void*)msg, 3));
  63013. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 3);
  63014. ExpectIntEQ(bio_buffer[0], msg[0]);
  63015. ExpectIntEQ(bio_buffer[1], msg[1]);
  63016. ExpectIntEQ(bio_buffer[2], msg[2]);
  63017. ExpectIntNE(bio_buffer[3], 0x33); /* make sure null terminator was set */
  63018. /* check reading an empty string */
  63019. BIO_free(bio);
  63020. bio = NULL;
  63021. ExpectNotNull(bio = BIO_new_mem_buf((void*)emp, sizeof(emp)));
  63022. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 1); /* just terminator */
  63023. ExpectStrEQ(emp, bio_buffer);
  63024. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 0); /* Nothing to read */
  63025. /* check error cases */
  63026. BIO_free(bio);
  63027. bio = NULL;
  63028. ExpectIntEQ(BIO_gets(NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  63029. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  63030. ExpectIntEQ(BIO_gets(bio, bio_buffer, 2), 0); /* nothing to read */
  63031. #if !defined(NO_FILESYSTEM)
  63032. {
  63033. BIO* f_bio = NULL;
  63034. XFILE f = XBADFILE;
  63035. ExpectNotNull(f_bio = BIO_new(BIO_s_file()));
  63036. ExpectIntLE(BIO_gets(f_bio, bio_buffer, bufferSz), 0);
  63037. ExpectTrue((f = XFOPEN(svrCertFile, "rb")) != XBADFILE);
  63038. ExpectIntEQ((int)BIO_set_fp(f_bio, f, BIO_CLOSE), SSL_SUCCESS);
  63039. if (EXPECT_FAIL() && (f != XBADFILE)) {
  63040. XFCLOSE(f);
  63041. }
  63042. ExpectIntGT(BIO_gets(f_bio, bio_buffer, bufferSz), 0);
  63043. BIO_free(f_bio);
  63044. f_bio = NULL;
  63045. }
  63046. #endif /* NO_FILESYSTEM */
  63047. BIO_free(bio);
  63048. bio = NULL;
  63049. BIO_free(bio2);
  63050. bio2 = NULL;
  63051. /* try with type BIO */
  63052. XMEMCPY(msg, "\nhello wolfSSL\n security plus\t---...**adf\na...b.c",
  63053. sizeof(msg));
  63054. ExpectNotNull(bio = BIO_new(BIO_s_bio()));
  63055. ExpectIntEQ(BIO_gets(bio, bio_buffer, 2), 0); /* nothing to read */
  63056. ExpectNotNull(bio2 = BIO_new(BIO_s_bio()));
  63057. ExpectIntEQ(BIO_set_write_buf_size(bio, 10), SSL_SUCCESS);
  63058. ExpectIntEQ(BIO_set_write_buf_size(bio2, sizeof(msg)), SSL_SUCCESS);
  63059. ExpectIntEQ(BIO_make_bio_pair(bio, bio2), SSL_SUCCESS);
  63060. ExpectIntEQ(BIO_write(bio2, msg, sizeof(msg)), sizeof(msg));
  63061. ExpectIntEQ(BIO_gets(bio, bio_buffer, -3), 0);
  63062. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 1);
  63063. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 14);
  63064. ExpectStrEQ(bio_buffer, "hello wolfSSL\n");
  63065. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 19);
  63066. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 8);
  63067. ExpectIntEQ(BIO_gets(bio, bio_buffer, -1), 0);
  63068. BIO_free(bio);
  63069. bio = NULL;
  63070. BIO_free(bio2);
  63071. bio2 = NULL;
  63072. /* check reading an empty string */
  63073. ExpectNotNull(bio = BIO_new(BIO_s_bio()));
  63074. ExpectIntEQ(BIO_set_write_buf_size(bio, sizeof(emp)), SSL_SUCCESS);
  63075. ExpectIntEQ(BIO_gets(bio, bio_buffer, bufferSz), 0); /* Nothing to read */
  63076. ExpectStrEQ(emp, bio_buffer);
  63077. BIO_free(bio);
  63078. bio = NULL;
  63079. #endif
  63080. return EXPECT_RESULT();
  63081. }
  63082. static int test_wolfSSL_BIO_puts(void)
  63083. {
  63084. EXPECT_DECLS;
  63085. #if defined(OPENSSL_EXTRA)
  63086. BIO* bio = NULL;
  63087. char input[] = "hello\0world\n.....ok\n\0";
  63088. char output[128];
  63089. XMEMSET(output, 0, sizeof(output));
  63090. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  63091. ExpectIntEQ(BIO_puts(bio, input), 5);
  63092. ExpectIntEQ(BIO_pending(bio), 5);
  63093. ExpectIntEQ(BIO_puts(bio, input + 6), 14);
  63094. ExpectIntEQ(BIO_pending(bio), 19);
  63095. ExpectIntEQ(BIO_gets(bio, output, sizeof(output)), 11);
  63096. ExpectStrEQ(output, "helloworld\n");
  63097. ExpectIntEQ(BIO_pending(bio), 8);
  63098. ExpectIntEQ(BIO_gets(bio, output, sizeof(output)), 8);
  63099. ExpectStrEQ(output, ".....ok\n");
  63100. ExpectIntEQ(BIO_pending(bio), 0);
  63101. ExpectIntEQ(BIO_puts(bio, ""), -1);
  63102. BIO_free(bio);
  63103. #endif
  63104. return EXPECT_RESULT();
  63105. }
  63106. static int test_wolfSSL_BIO_dump(void)
  63107. {
  63108. EXPECT_DECLS;
  63109. #if defined(OPENSSL_EXTRA)
  63110. BIO* bio;
  63111. static const unsigned char data[] = {
  63112. 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2A, 0x86, 0x48, 0xCE,
  63113. 0x3D, 0x02, 0x01, 0x06, 0x08, 0x2A, 0x86, 0x48, 0xCE, 0x3D,
  63114. 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x55, 0xBF, 0xF4,
  63115. 0x0F, 0x44, 0x50, 0x9A, 0x3D, 0xCE, 0x9B, 0xB7, 0xF0, 0xC5,
  63116. 0x4D, 0xF5, 0x70, 0x7B, 0xD4, 0xEC, 0x24, 0x8E, 0x19, 0x80,
  63117. 0xEC, 0x5A, 0x4C, 0xA2, 0x24, 0x03, 0x62, 0x2C, 0x9B, 0xDA,
  63118. 0xEF, 0xA2, 0x35, 0x12, 0x43, 0x84, 0x76, 0x16, 0xC6, 0x56,
  63119. 0x95, 0x06, 0xCC, 0x01, 0xA9, 0xBD, 0xF6, 0x75, 0x1A, 0x42,
  63120. 0xF7, 0xBD, 0xA9, 0xB2, 0x36, 0x22, 0x5F, 0xC7, 0x5D, 0x7F,
  63121. 0xB4
  63122. };
  63123. /* Generated with OpenSSL. */
  63124. static const char expected[] =
  63125. "0000 - 30 59 30 13 06 07 2a 86-48 ce 3d 02 01 06 08 2a 0Y0...*.H.=....*\n"
  63126. "0010 - 86 48 ce 3d 03 01 07 03-42 00 04 55 bf f4 0f 44 .H.=....B..U...D\n"
  63127. "0020 - 50 9a 3d ce 9b b7 f0 c5-4d f5 70 7b d4 ec 24 8e P.=.....M.p{..$.\n"
  63128. "0030 - 19 80 ec 5a 4c a2 24 03-62 2c 9b da ef a2 35 12 ...ZL.$.b,....5.\n"
  63129. "0040 - 43 84 76 16 c6 56 95 06-cc 01 a9 bd f6 75 1a 42 C.v..V.......u.B\n"
  63130. "0050 - f7 bd a9 b2 36 22 5f c7-5d 7f b4 ....6\"_.]..\n";
  63131. static const char expectedAll[] =
  63132. "0000 - 00 01 02 03 04 05 06 07-08 09 0a 0b 0c 0d 0e 0f ................\n"
  63133. "0010 - 10 11 12 13 14 15 16 17-18 19 1a 1b 1c 1d 1e 1f ................\n"
  63134. "0020 - 20 21 22 23 24 25 26 27-28 29 2a 2b 2c 2d 2e 2f !\"#$%&'()*+,-./\n"
  63135. "0030 - 30 31 32 33 34 35 36 37-38 39 3a 3b 3c 3d 3e 3f 0123456789:;<=>?\n"
  63136. "0040 - 40 41 42 43 44 45 46 47-48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO\n"
  63137. "0050 - 50 51 52 53 54 55 56 57-58 59 5a 5b 5c 5d 5e 5f PQRSTUVWXYZ[\\]^_\n"
  63138. "0060 - 60 61 62 63 64 65 66 67-68 69 6a 6b 6c 6d 6e 6f `abcdefghijklmno\n"
  63139. "0070 - 70 71 72 73 74 75 76 77-78 79 7a 7b 7c 7d 7e 7f pqrstuvwxyz{|}~.\n"
  63140. "0080 - 80 81 82 83 84 85 86 87-88 89 8a 8b 8c 8d 8e 8f ................\n"
  63141. "0090 - 90 91 92 93 94 95 96 97-98 99 9a 9b 9c 9d 9e 9f ................\n"
  63142. "00a0 - a0 a1 a2 a3 a4 a5 a6 a7-a8 a9 aa ab ac ad ae af ................\n"
  63143. "00b0 - b0 b1 b2 b3 b4 b5 b6 b7-b8 b9 ba bb bc bd be bf ................\n"
  63144. "00c0 - c0 c1 c2 c3 c4 c5 c6 c7-c8 c9 ca cb cc cd ce cf ................\n"
  63145. "00d0 - d0 d1 d2 d3 d4 d5 d6 d7-d8 d9 da db dc dd de df ................\n"
  63146. "00e0 - e0 e1 e2 e3 e4 e5 e6 e7-e8 e9 ea eb ec ed ee ef ................\n"
  63147. "00f0 - f0 f1 f2 f3 f4 f5 f6 f7-f8 f9 fa fb fc fd fe ff ................\n";
  63148. char output[16 * 80];
  63149. int i;
  63150. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  63151. /* Example key dumped. */
  63152. ExpectIntEQ(BIO_dump(bio, (const char*)data, (int)sizeof(data)),
  63153. sizeof(expected) - 1);
  63154. ExpectIntEQ(BIO_read(bio, output, sizeof(output)), sizeof(expected) - 1);
  63155. ExpectIntEQ(XMEMCMP(output, expected, sizeof(expected) - 1), 0);
  63156. /* Try every possible value for a character. */
  63157. for (i = 0; i < 256; i++)
  63158. output[i] = i;
  63159. ExpectIntEQ(BIO_dump(bio, output, 256), sizeof(expectedAll) - 1);
  63160. ExpectIntEQ(BIO_read(bio, output, sizeof(output)), sizeof(expectedAll) - 1);
  63161. ExpectIntEQ(XMEMCMP(output, expectedAll, sizeof(expectedAll) - 1), 0);
  63162. BIO_free(bio);
  63163. #endif
  63164. return EXPECT_RESULT();
  63165. }
  63166. #if defined(OPENSSL_ALL) && !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  63167. !defined(NO_RSA) && defined(HAVE_EXT_CACHE) && \
  63168. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(USE_WOLFSSL_IO)
  63169. static int forceWantRead(WOLFSSL *ssl, char *buf, int sz, void *ctx)
  63170. {
  63171. (void)ssl;
  63172. (void)buf;
  63173. (void)sz;
  63174. (void)ctx;
  63175. return WOLFSSL_CBIO_ERR_WANT_READ;
  63176. }
  63177. #endif
  63178. static int test_wolfSSL_BIO_should_retry(void)
  63179. {
  63180. EXPECT_DECLS;
  63181. #if defined(OPENSSL_ALL) && !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  63182. !defined(NO_RSA) && defined(HAVE_EXT_CACHE) && \
  63183. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(USE_WOLFSSL_IO)
  63184. tcp_ready ready;
  63185. func_args server_args;
  63186. THREAD_TYPE serverThread;
  63187. SOCKET_T sockfd = 0;
  63188. WOLFSSL_CTX* ctx = NULL;
  63189. WOLFSSL* ssl = NULL;
  63190. char msg[64] = "hello wolfssl!";
  63191. char reply[1024];
  63192. int msgSz = (int)XSTRLEN(msg);
  63193. int ret;
  63194. BIO* bio = NULL;
  63195. XMEMSET(&server_args, 0, sizeof(func_args));
  63196. #ifdef WOLFSSL_TIRTOS
  63197. fdOpenSession(Task_self());
  63198. #endif
  63199. StartTCP();
  63200. InitTcpReady(&ready);
  63201. #if defined(USE_WINDOWS_API)
  63202. /* use RNG to get random port if using windows */
  63203. ready.port = GetRandomPort();
  63204. #endif
  63205. server_args.signal = &ready;
  63206. start_thread(test_server_nofail, &server_args, &serverThread);
  63207. wait_tcp_ready(&server_args);
  63208. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  63209. #ifdef OPENSSL_COMPATIBLE_DEFAULTS
  63210. ExpectIntEQ(wolfSSL_CTX_clear_mode(ctx, SSL_MODE_AUTO_RETRY), 0);
  63211. #endif
  63212. ExpectIntEQ(WOLFSSL_SUCCESS,
  63213. wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0));
  63214. ExpectIntEQ(WOLFSSL_SUCCESS,
  63215. wolfSSL_CTX_use_certificate_file(ctx, cliCertFile, SSL_FILETYPE_PEM));
  63216. ExpectIntEQ(WOLFSSL_SUCCESS,
  63217. wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, SSL_FILETYPE_PEM));
  63218. tcp_connect(&sockfd, wolfSSLIP, server_args.signal->port, 0, 0, NULL);
  63219. /* force retry */
  63220. ExpectNotNull(bio = wolfSSL_BIO_new_ssl(ctx, 1));
  63221. ExpectIntEQ(BIO_get_ssl(bio, &ssl), 1);
  63222. ExpectNotNull(ssl);
  63223. ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS);
  63224. wolfSSL_SSLSetIORecv(ssl, forceWantRead);
  63225. if (EXPECT_FAIL()) {
  63226. wolfSSL_free(ssl);
  63227. ssl = NULL;
  63228. }
  63229. ExpectIntLE(BIO_write(bio, msg, msgSz), 0);
  63230. ExpectIntNE(BIO_should_retry(bio), 0);
  63231. ExpectIntEQ(BIO_should_read(bio), 0);
  63232. ExpectIntEQ(BIO_should_write(bio), 0);
  63233. /* now perform successful connection */
  63234. wolfSSL_SSLSetIORecv(ssl, EmbedReceive);
  63235. ExpectIntEQ(BIO_write(bio, msg, msgSz), msgSz);
  63236. ExpectIntNE(BIO_read(bio, reply, sizeof(reply)), 0);
  63237. ret = wolfSSL_get_error(ssl, -1);
  63238. if (ret == WOLFSSL_ERROR_WANT_READ || ret == WOLFSSL_ERROR_WANT_WRITE) {
  63239. ExpectIntNE(BIO_should_retry(bio), 0);
  63240. if (ret == WOLFSSL_ERROR_WANT_READ)
  63241. ExpectIntEQ(BIO_should_read(bio), 1);
  63242. else
  63243. ExpectIntEQ(BIO_should_read(bio), 0);
  63244. if (ret == WOLFSSL_ERROR_WANT_WRITE)
  63245. ExpectIntEQ(BIO_should_write(bio), 1);
  63246. else
  63247. ExpectIntEQ(BIO_should_write(bio), 0);
  63248. }
  63249. else {
  63250. ExpectIntEQ(BIO_should_retry(bio), 0);
  63251. ExpectIntEQ(BIO_should_read(bio), 0);
  63252. ExpectIntEQ(BIO_should_write(bio), 0);
  63253. }
  63254. ExpectIntEQ(XMEMCMP(reply, "I hear you fa shizzle!",
  63255. XSTRLEN("I hear you fa shizzle!")), 0);
  63256. BIO_free(bio);
  63257. wolfSSL_CTX_free(ctx);
  63258. CloseSocket(sockfd);
  63259. join_thread(serverThread);
  63260. FreeTcpReady(&ready);
  63261. #ifdef WOLFSSL_TIRTOS
  63262. fdOpenSession(Task_self());
  63263. #endif
  63264. #endif
  63265. return EXPECT_RESULT();
  63266. }
  63267. static int test_wolfSSL_BIO_connect(void)
  63268. {
  63269. EXPECT_DECLS;
  63270. #if defined(OPENSSL_ALL) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  63271. defined(HAVE_HTTP_CLIENT) && !defined(NO_WOLFSSL_CLIENT)
  63272. tcp_ready ready;
  63273. func_args server_args;
  63274. THREAD_TYPE serverThread;
  63275. BIO *tcpBio = NULL;
  63276. BIO *sslBio = NULL;
  63277. SSL_CTX* ctx = NULL;
  63278. SSL *ssl = NULL;
  63279. SSL *sslPtr;
  63280. char msg[] = "hello wolfssl!";
  63281. char reply[30];
  63282. char buff[10] = {0};
  63283. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  63284. ExpectIntEQ(WOLFSSL_SUCCESS,
  63285. wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0));
  63286. ExpectIntEQ(WOLFSSL_SUCCESS,
  63287. wolfSSL_CTX_use_certificate_file(ctx, cliCertFile, SSL_FILETYPE_PEM));
  63288. ExpectIntEQ(WOLFSSL_SUCCESS,
  63289. wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, SSL_FILETYPE_PEM));
  63290. /* Setup server */
  63291. XMEMSET(&server_args, 0, sizeof(func_args));
  63292. StartTCP();
  63293. InitTcpReady(&ready);
  63294. #if defined(USE_WINDOWS_API)
  63295. /* use RNG to get random port if using windows */
  63296. ready.port = GetRandomPort();
  63297. #endif
  63298. server_args.signal = &ready;
  63299. start_thread(test_server_nofail, &server_args, &serverThread);
  63300. wait_tcp_ready(&server_args);
  63301. ExpectIntGT(XSNPRINTF(buff, sizeof(buff), "%d", ready.port), 0);
  63302. /* Start the test proper */
  63303. /* Setup the TCP BIO */
  63304. ExpectNotNull(tcpBio = BIO_new_connect(wolfSSLIP));
  63305. ExpectIntEQ(BIO_set_conn_port(tcpBio, buff), 1);
  63306. /* Setup the SSL object */
  63307. ExpectNotNull(ssl = SSL_new(ctx));
  63308. SSL_set_connect_state(ssl);
  63309. /* Setup the SSL BIO */
  63310. ExpectNotNull(sslBio = BIO_new(BIO_f_ssl()));
  63311. ExpectIntEQ(BIO_set_ssl(sslBio, ssl, BIO_CLOSE), 1);
  63312. if (EXPECT_FAIL()) {
  63313. wolfSSL_free(ssl);
  63314. }
  63315. /* Verify that BIO_get_ssl works. */
  63316. ExpectIntEQ(BIO_get_ssl(sslBio, &sslPtr), 1);
  63317. ExpectPtrEq(ssl, sslPtr);
  63318. /* Link BIO's so that sslBio uses tcpBio for IO */
  63319. ExpectPtrEq(BIO_push(sslBio, tcpBio), sslBio);
  63320. /* Do TCP connect */
  63321. ExpectIntEQ(BIO_do_connect(sslBio), 1);
  63322. /* Do TLS handshake */
  63323. ExpectIntEQ(BIO_do_handshake(sslBio), 1);
  63324. /* Test writing */
  63325. ExpectIntEQ(BIO_write(sslBio, msg, sizeof(msg)), sizeof(msg));
  63326. /* Expect length of default wolfSSL reply */
  63327. ExpectIntEQ(BIO_read(sslBio, reply, sizeof(reply)), 23);
  63328. /* Clean it all up */
  63329. BIO_free_all(sslBio);
  63330. /* Server clean up */
  63331. join_thread(serverThread);
  63332. FreeTcpReady(&ready);
  63333. /* Run the same test, but use BIO_new_ssl_connect and set the IP and port
  63334. * after. */
  63335. XMEMSET(&server_args, 0, sizeof(func_args));
  63336. StartTCP();
  63337. InitTcpReady(&ready);
  63338. #if defined(USE_WINDOWS_API)
  63339. /* use RNG to get random port if using windows */
  63340. ready.port = GetRandomPort();
  63341. #endif
  63342. server_args.signal = &ready;
  63343. start_thread(test_server_nofail, &server_args, &serverThread);
  63344. wait_tcp_ready(&server_args);
  63345. ExpectIntGT(XSNPRINTF(buff, sizeof(buff), "%d", ready.port), 0);
  63346. ExpectNotNull(sslBio = BIO_new_ssl_connect(ctx));
  63347. ExpectIntEQ(BIO_set_conn_hostname(sslBio, (char*)wolfSSLIP), 1);
  63348. ExpectIntEQ(BIO_set_conn_port(sslBio, buff), 1);
  63349. ExpectIntEQ(BIO_do_connect(sslBio), 1);
  63350. ExpectIntEQ(BIO_do_handshake(sslBio), 1);
  63351. ExpectIntEQ(BIO_write(sslBio, msg, sizeof(msg)), sizeof(msg));
  63352. ExpectIntEQ(BIO_read(sslBio, reply, sizeof(reply)), 23);
  63353. /* Attempt to close the TLS connection gracefully. */
  63354. BIO_ssl_shutdown(sslBio);
  63355. BIO_free_all(sslBio);
  63356. join_thread(serverThread);
  63357. FreeTcpReady(&ready);
  63358. SSL_CTX_free(ctx);
  63359. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
  63360. wc_ecc_fp_free(); /* free per thread cache */
  63361. #endif
  63362. #endif
  63363. return EXPECT_RESULT();
  63364. }
  63365. static int test_wolfSSL_BIO_tls(void)
  63366. {
  63367. EXPECT_DECLS;
  63368. #if !defined(NO_BIO) && defined(OPENSSL_EXTRA) && !defined(NO_WOLFSSL_CLIENT)
  63369. SSL_CTX* ctx = NULL;
  63370. SSL *ssl = NULL;
  63371. BIO *readBio = NULL;
  63372. BIO *writeBio = NULL;
  63373. int ret;
  63374. int err = 0;
  63375. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_method()));
  63376. ExpectNotNull(ssl = SSL_new(ctx));
  63377. ExpectNotNull(readBio = BIO_new(BIO_s_mem()));
  63378. ExpectNotNull(writeBio = BIO_new(BIO_s_mem()));
  63379. /* Qt reads data from write-bio,
  63380. * then writes the read data into plain packet.
  63381. * Qt reads data from plain packet,
  63382. * then writes the read data into read-bio.
  63383. */
  63384. SSL_set_bio(ssl, readBio, writeBio);
  63385. do {
  63386. #ifdef WOLFSSL_ASYNC_CRYPT
  63387. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  63388. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  63389. if (ret < 0) { break; } else if (ret == 0) { continue; }
  63390. }
  63391. #endif
  63392. ret = SSL_connect(ssl);
  63393. err = SSL_get_error(ssl, 0);
  63394. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  63395. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  63396. /* in this use case, should return WANT READ
  63397. * so that Qt will read the data from plain packet for next state.
  63398. */
  63399. ExpectIntEQ(err, SSL_ERROR_WANT_READ);
  63400. SSL_free(ssl);
  63401. SSL_CTX_free(ctx);
  63402. #endif
  63403. return EXPECT_RESULT();
  63404. }
  63405. static int test_wolfSSL_BIO_datagram(void)
  63406. {
  63407. EXPECT_DECLS;
  63408. #if !defined(NO_BIO) && defined(WOLFSSL_DTLS) && defined(WOLFSSL_HAVE_BIO_ADDR) && defined(OPENSSL_EXTRA)
  63409. int ret;
  63410. SOCKET_T fd1 = SOCKET_INVALID, fd2 = SOCKET_INVALID;
  63411. WOLFSSL_BIO *bio1 = NULL, *bio2 = NULL;
  63412. WOLFSSL_BIO_ADDR *bio_addr1 = NULL, *bio_addr2 = NULL;
  63413. SOCKADDR_IN sin1, sin2;
  63414. socklen_t slen;
  63415. static const char test_msg[] = "I am a datagram, short and stout.";
  63416. char test_msg_recvd[sizeof(test_msg) + 10];
  63417. #ifdef USE_WINDOWS_API
  63418. static const DWORD timeout = 250; /* ms */
  63419. #else
  63420. static const struct timeval timeout = { 0, 250000 };
  63421. #endif
  63422. StartTCP();
  63423. if (EXPECT_SUCCESS()) {
  63424. fd1 = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  63425. ExpectIntNE(fd1, SOCKET_INVALID);
  63426. }
  63427. if (EXPECT_SUCCESS()) {
  63428. fd2 = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  63429. ExpectIntNE(fd2, SOCKET_INVALID);
  63430. }
  63431. if (EXPECT_SUCCESS()) {
  63432. bio1 = wolfSSL_BIO_new_dgram(fd1, 1 /* closeF */);
  63433. ExpectNotNull(bio1);
  63434. }
  63435. if (EXPECT_SUCCESS()) {
  63436. bio2 = wolfSSL_BIO_new_dgram(fd2, 1 /* closeF */);
  63437. ExpectNotNull(bio2);
  63438. }
  63439. if (EXPECT_SUCCESS()) {
  63440. sin1.sin_family = AF_INET;
  63441. sin1.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  63442. sin1.sin_port = 0;
  63443. slen = (socklen_t)sizeof(sin1);
  63444. ExpectIntEQ(bind(fd1, (const struct sockaddr *)&sin1, slen), 0);
  63445. ExpectIntEQ(setsockopt(fd1, SOL_SOCKET, SO_RCVTIMEO, (const char *)&timeout, sizeof(timeout)), 0);
  63446. ExpectIntEQ(getsockname(fd1, (struct sockaddr *)&sin1, &slen), 0);
  63447. }
  63448. if (EXPECT_SUCCESS()) {
  63449. sin2.sin_family = AF_INET;
  63450. sin2.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  63451. sin2.sin_port = 0;
  63452. slen = (socklen_t)sizeof(sin2);
  63453. ExpectIntEQ(bind(fd2, (const struct sockaddr *)&sin2, slen), 0);
  63454. ExpectIntEQ(setsockopt(fd2, SOL_SOCKET, SO_RCVTIMEO, (const char *)&timeout, sizeof(timeout)), 0);
  63455. ExpectIntEQ(getsockname(fd2, (struct sockaddr *)&sin2, &slen), 0);
  63456. }
  63457. if (EXPECT_SUCCESS()) {
  63458. bio_addr1 = wolfSSL_BIO_ADDR_new();
  63459. ExpectNotNull(bio_addr1);
  63460. }
  63461. if (EXPECT_SUCCESS()) {
  63462. bio_addr2 = wolfSSL_BIO_ADDR_new();
  63463. ExpectNotNull(bio_addr2);
  63464. }
  63465. if (EXPECT_SUCCESS()) {
  63466. /* for OpenSSL compatibility, direct copying of sockaddrs into BIO_ADDRs must work right. */
  63467. XMEMCPY(&bio_addr2->sa_in, &sin2, sizeof(sin2));
  63468. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio1, BIO_CTRL_DGRAM_SET_PEER, 0, bio_addr2), WOLFSSL_SUCCESS);
  63469. wolfSSL_BIO_ADDR_clear(bio_addr2);
  63470. }
  63471. test_msg_recvd[0] = 0;
  63472. ExpectIntEQ(wolfSSL_BIO_write(bio1, test_msg, sizeof(test_msg)), (int)sizeof(test_msg));
  63473. ExpectIntEQ(wolfSSL_BIO_read(bio2, test_msg_recvd, sizeof(test_msg_recvd)), (int)sizeof(test_msg));
  63474. ExpectIntEQ(XMEMCMP(test_msg_recvd, test_msg, sizeof(test_msg)), 0);
  63475. #ifdef WOLFSSL_BIO_HAVE_FLOW_STATS
  63476. ExpectIntEQ(wolfSSL_BIO_number_written(bio1), sizeof(test_msg));
  63477. ExpectIntEQ(wolfSSL_BIO_number_read(bio2), sizeof(test_msg));
  63478. #endif
  63479. /* bio2 should now have bio1's addr stored as its peer_addr, because the
  63480. * BIOs aren't "connected" yet. use it to send a reply.
  63481. */
  63482. test_msg_recvd[0] = 0;
  63483. ExpectIntEQ(wolfSSL_BIO_write(bio2, test_msg, sizeof(test_msg)), (int)sizeof(test_msg));
  63484. ExpectIntEQ(wolfSSL_BIO_read(bio1, test_msg_recvd, sizeof(test_msg_recvd)), (int)sizeof(test_msg));
  63485. ExpectIntEQ(XMEMCMP(test_msg_recvd, test_msg, sizeof(test_msg)), 0);
  63486. ExpectIntEQ(wolfSSL_BIO_read(bio1, test_msg_recvd, sizeof(test_msg_recvd)), WOLFSSL_BIO_ERROR);
  63487. ExpectIntNE(BIO_should_retry(bio1), 0);
  63488. ExpectIntEQ(wolfSSL_BIO_read(bio2, test_msg_recvd, sizeof(test_msg_recvd)), WOLFSSL_BIO_ERROR);
  63489. ExpectIntNE(BIO_should_retry(bio2), 0);
  63490. /* now "connect" the sockets. */
  63491. ExpectIntEQ(connect(fd1, (const struct sockaddr *)&sin2, (socklen_t)sizeof(sin2)), 0);
  63492. ExpectIntEQ(connect(fd2, (const struct sockaddr *)&sin1, (socklen_t)sizeof(sin1)), 0);
  63493. if (EXPECT_SUCCESS()) {
  63494. XMEMCPY(&bio_addr2->sa_in, &sin2, sizeof(sin2));
  63495. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio1, BIO_CTRL_DGRAM_SET_CONNECTED, 0, bio_addr2), WOLFSSL_SUCCESS);
  63496. wolfSSL_BIO_ADDR_clear(bio_addr2);
  63497. }
  63498. if (EXPECT_SUCCESS()) {
  63499. XMEMCPY(&bio_addr1->sa_in, &sin1, sizeof(sin1));
  63500. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio2, BIO_CTRL_DGRAM_SET_CONNECTED, 0, bio_addr1), WOLFSSL_SUCCESS);
  63501. wolfSSL_BIO_ADDR_clear(bio_addr1);
  63502. }
  63503. test_msg_recvd[0] = 0;
  63504. ExpectIntEQ(wolfSSL_BIO_write(bio2, test_msg, sizeof(test_msg)), (int)sizeof(test_msg));
  63505. ExpectIntEQ(wolfSSL_BIO_read(bio1, test_msg_recvd, sizeof(test_msg_recvd)), (int)sizeof(test_msg));
  63506. ExpectIntEQ(XMEMCMP(test_msg_recvd, test_msg, sizeof(test_msg)), 0);
  63507. test_msg_recvd[0] = 0;
  63508. ExpectIntEQ(wolfSSL_BIO_write(bio1, test_msg, sizeof(test_msg)), (int)sizeof(test_msg));
  63509. ExpectIntEQ(wolfSSL_BIO_read(bio2, test_msg_recvd, sizeof(test_msg_recvd)), (int)sizeof(test_msg));
  63510. ExpectIntEQ(XMEMCMP(test_msg_recvd, test_msg, sizeof(test_msg)), 0);
  63511. #ifdef __linux__
  63512. /* now "disconnect" the sockets and attempt transmits expected to fail. */
  63513. sin1.sin_family = AF_UNSPEC;
  63514. ExpectIntEQ(connect(fd1, (const struct sockaddr *)&sin1, (socklen_t)sizeof(sin1)), 0);
  63515. ExpectIntEQ(connect(fd2, (const struct sockaddr *)&sin1, (socklen_t)sizeof(sin1)), 0);
  63516. sin1.sin_family = AF_INET;
  63517. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio1, BIO_CTRL_DGRAM_SET_CONNECTED, 0, NULL), WOLFSSL_SUCCESS);
  63518. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio2, BIO_CTRL_DGRAM_SET_CONNECTED, 0, NULL), WOLFSSL_SUCCESS);
  63519. if (EXPECT_SUCCESS()) {
  63520. sin2.sin_addr.s_addr = htonl(0xc0a8c0a8); /* 192.168.192.168 -- invalid for loopback interface. */
  63521. XMEMCPY(&bio_addr2->sa_in, &sin2, sizeof(sin2));
  63522. ExpectIntEQ((int)wolfSSL_BIO_ctrl(bio1, BIO_CTRL_DGRAM_SET_PEER, 0, bio_addr2), WOLFSSL_SUCCESS);
  63523. wolfSSL_BIO_ADDR_clear(bio_addr2);
  63524. }
  63525. test_msg_recvd[0] = 0;
  63526. errno = 0;
  63527. ExpectIntEQ(wolfSSL_BIO_write(bio1, test_msg, sizeof(test_msg)), -1);
  63528. ExpectTrue((errno == EINVAL) || (errno == ENETUNREACH));
  63529. #endif /* __linux__ */
  63530. if (bio1) {
  63531. ret = wolfSSL_BIO_free(bio1);
  63532. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  63533. } else if (fd1 != SOCKET_INVALID)
  63534. CloseSocket(fd1);
  63535. if (bio2) {
  63536. ret = wolfSSL_BIO_free(bio2);
  63537. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  63538. } else if (fd2 != SOCKET_INVALID)
  63539. CloseSocket(fd2);
  63540. if (bio_addr1)
  63541. wolfSSL_BIO_ADDR_free(bio_addr1);
  63542. if (bio_addr2)
  63543. wolfSSL_BIO_ADDR_free(bio_addr2);
  63544. #endif /* !NO_BIO && WOLFSSL_DTLS && WOLFSSL_HAVE_BIO_ADDR && OPENSSL_EXTRA */
  63545. return EXPECT_RESULT();
  63546. }
  63547. #if defined(OPENSSL_ALL) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  63548. defined(HAVE_HTTP_CLIENT)
  63549. static THREAD_RETURN WOLFSSL_THREAD test_wolfSSL_BIO_accept_client(void* args)
  63550. {
  63551. BIO* clientBio;
  63552. SSL* sslClient;
  63553. SSL_CTX* ctx;
  63554. char connectAddr[20]; /* IP + port */;
  63555. (void)args;
  63556. AssertIntGT(snprintf(connectAddr, sizeof(connectAddr), "%s:%d", wolfSSLIP, wolfSSLPort), 0);
  63557. AssertNotNull(clientBio = BIO_new_connect(connectAddr));
  63558. AssertIntEQ(BIO_do_connect(clientBio), 1);
  63559. AssertNotNull(ctx = SSL_CTX_new(SSLv23_method()));
  63560. AssertNotNull(sslClient = SSL_new(ctx));
  63561. AssertIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0), WOLFSSL_SUCCESS);
  63562. SSL_set_bio(sslClient, clientBio, clientBio);
  63563. AssertIntEQ(SSL_connect(sslClient), 1);
  63564. SSL_free(sslClient);
  63565. SSL_CTX_free(ctx);
  63566. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
  63567. wc_ecc_fp_free(); /* free per thread cache */
  63568. #endif
  63569. WOLFSSL_RETURN_FROM_THREAD(0);
  63570. }
  63571. #endif
  63572. static int test_wolfSSL_BIO_accept(void)
  63573. {
  63574. EXPECT_DECLS;
  63575. #if defined(OPENSSL_ALL) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  63576. defined(HAVE_HTTP_CLIENT)
  63577. BIO* serverBindBio = NULL;
  63578. BIO* serverAcceptBio = NULL;
  63579. SSL* sslServer = NULL;
  63580. SSL_CTX* ctx = NULL;
  63581. func_args args;
  63582. THREAD_TYPE thread;
  63583. char port[10]; /* 10 bytes should be enough to store the string
  63584. * representation of the port */
  63585. ExpectIntGT(snprintf(port, sizeof(port), "%d", wolfSSLPort), 0);
  63586. ExpectNotNull(serverBindBio = BIO_new_accept(port));
  63587. /* First BIO_do_accept binds the port */
  63588. ExpectIntEQ(BIO_do_accept(serverBindBio), 1);
  63589. XMEMSET(&args, 0, sizeof(func_args));
  63590. start_thread(test_wolfSSL_BIO_accept_client, &args, &thread);
  63591. ExpectIntEQ(BIO_do_accept(serverBindBio), 1);
  63592. /* Let's plug it into SSL to test */
  63593. ExpectNotNull(ctx = SSL_CTX_new(SSLv23_method()));
  63594. ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  63595. SSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  63596. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  63597. SSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  63598. ExpectNotNull(sslServer = SSL_new(ctx));
  63599. ExpectNotNull(serverAcceptBio = BIO_pop(serverBindBio));
  63600. SSL_set_bio(sslServer, serverAcceptBio, serverAcceptBio);
  63601. ExpectIntEQ(SSL_accept(sslServer), 1);
  63602. join_thread(thread);
  63603. BIO_free(serverBindBio);
  63604. SSL_free(sslServer);
  63605. SSL_CTX_free(ctx);
  63606. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
  63607. wc_ecc_fp_free(); /* free per thread cache */
  63608. #endif
  63609. #endif
  63610. return EXPECT_RESULT();
  63611. }
  63612. static int test_wolfSSL_BIO_write(void)
  63613. {
  63614. EXPECT_DECLS;
  63615. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_BASE64_ENCODE)
  63616. BIO* bio = NULL;
  63617. BIO* bio64 = NULL;
  63618. BIO* bio_mem = NULL;
  63619. BIO* ptr = NULL;
  63620. int sz;
  63621. char msg[] = "conversion test";
  63622. char out[40];
  63623. char expected[] = "Y29udmVyc2lvbiB0ZXN0AA==\n";
  63624. void* bufPtr = NULL;
  63625. BUF_MEM* buf = NULL;
  63626. ExpectNotNull(bio64 = BIO_new(BIO_f_base64()));
  63627. ExpectNotNull(bio = BIO_push(bio64, BIO_new(BIO_s_mem())));
  63628. if (EXPECT_FAIL()) {
  63629. BIO_free(bio64);
  63630. }
  63631. /* now should convert to base64 then write to memory */
  63632. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), sizeof(msg));
  63633. BIO_flush(bio);
  63634. /* test BIO chain */
  63635. ExpectIntEQ(SSL_SUCCESS, (int)BIO_get_mem_ptr(bio, &buf));
  63636. ExpectNotNull(buf);
  63637. ExpectIntEQ(buf->length, 25);
  63638. ExpectIntEQ(BIO_get_mem_data(bio, &bufPtr), 25);
  63639. ExpectPtrEq(buf->data, bufPtr);
  63640. ExpectNotNull(ptr = BIO_find_type(bio, BIO_TYPE_MEM));
  63641. sz = sizeof(out);
  63642. XMEMSET(out, 0, sz);
  63643. ExpectIntEQ((sz = BIO_read(ptr, out, sz)), 25);
  63644. ExpectIntEQ(XMEMCMP(out, expected, sz), 0);
  63645. /* write then read should return the same message */
  63646. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), sizeof(msg));
  63647. sz = sizeof(out);
  63648. XMEMSET(out, 0, sz);
  63649. ExpectIntEQ(BIO_read(bio, out, sz), 16);
  63650. ExpectIntEQ(XMEMCMP(out, msg, sizeof(msg)), 0);
  63651. /* now try encoding with no line ending */
  63652. BIO_set_flags(bio64, BIO_FLAGS_BASE64_NO_NL);
  63653. #ifdef HAVE_EX_DATA
  63654. BIO_set_ex_data(bio64, 0, (void*) "data");
  63655. ExpectIntEQ(strcmp((const char*)BIO_get_ex_data(bio64, 0), "data"), 0);
  63656. #endif
  63657. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), sizeof(msg));
  63658. BIO_flush(bio);
  63659. sz = sizeof(out);
  63660. XMEMSET(out, 0, sz);
  63661. ExpectIntEQ((sz = BIO_read(ptr, out, sz)), 24);
  63662. ExpectIntEQ(XMEMCMP(out, expected, sz), 0);
  63663. BIO_free_all(bio); /* frees bio64 also */
  63664. bio = NULL;
  63665. /* test with more than one bio64 in list */
  63666. ExpectNotNull(bio64 = BIO_new(BIO_f_base64()));
  63667. ExpectNotNull(bio = BIO_push(BIO_new(BIO_f_base64()), bio64));
  63668. if (EXPECT_FAIL()) {
  63669. BIO_free(bio64);
  63670. bio64 = NULL;
  63671. }
  63672. ExpectNotNull(bio_mem = BIO_new(BIO_s_mem()));
  63673. ExpectNotNull(BIO_push(bio64, bio_mem));
  63674. if (EXPECT_FAIL()) {
  63675. BIO_free(bio_mem);
  63676. }
  63677. /* now should convert to base64 when stored and then decode with read */
  63678. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), 25);
  63679. BIO_flush(bio);
  63680. sz = sizeof(out);
  63681. XMEMSET(out, 0, sz);
  63682. ExpectIntEQ((sz = BIO_read(bio, out, sz)), 16);
  63683. ExpectIntEQ(XMEMCMP(out, msg, sz), 0);
  63684. BIO_clear_flags(bio64, ~0);
  63685. BIO_set_retry_read(bio);
  63686. BIO_free_all(bio); /* frees bio64s also */
  63687. bio = NULL;
  63688. ExpectNotNull(bio = BIO_new_mem_buf(out, 0));
  63689. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), sizeof(msg));
  63690. BIO_free(bio);
  63691. #endif
  63692. return EXPECT_RESULT();
  63693. }
  63694. static int test_wolfSSL_BIO_printf(void)
  63695. {
  63696. EXPECT_DECLS;
  63697. #if defined(OPENSSL_ALL)
  63698. BIO* bio = NULL;
  63699. int sz = 7;
  63700. char msg[] = "TLS 1.3 for the world";
  63701. char out[60];
  63702. char expected[] = "TLS 1.3 for the world : sz = 7";
  63703. XMEMSET(out, 0, sizeof(out));
  63704. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  63705. ExpectIntEQ(BIO_printf(bio, "%s : sz = %d", msg, sz), 30);
  63706. ExpectIntEQ(BIO_printf(NULL, ""), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  63707. ExpectIntEQ(BIO_read(bio, out, sizeof(out)), 30);
  63708. ExpectIntEQ(XSTRNCMP(out, expected, sizeof(expected)), 0);
  63709. BIO_free(bio);
  63710. #endif
  63711. return EXPECT_RESULT();
  63712. }
  63713. static int test_wolfSSL_BIO_f_md(void)
  63714. {
  63715. EXPECT_DECLS;
  63716. #if defined(OPENSSL_ALL) && !defined(NO_SHA256)
  63717. BIO* bio = NULL;
  63718. BIO* mem = NULL;
  63719. char msg[] = "message to hash";
  63720. char out[60];
  63721. EVP_MD_CTX* ctx = NULL;
  63722. const unsigned char testKey[] =
  63723. {
  63724. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  63725. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  63726. 0x0b, 0x0b, 0x0b, 0x0b
  63727. };
  63728. const char testData[] = "Hi There";
  63729. const unsigned char testResult[] =
  63730. {
  63731. 0xb0, 0x34, 0x4c, 0x61, 0xd8, 0xdb, 0x38, 0x53,
  63732. 0x5c, 0xa8, 0xaf, 0xce, 0xaf, 0x0b, 0xf1, 0x2b,
  63733. 0x88, 0x1d, 0xc2, 0x00, 0xc9, 0x83, 0x3d, 0xa7,
  63734. 0x26, 0xe9, 0x37, 0x6c, 0x2e, 0x32, 0xcf, 0xf7
  63735. };
  63736. const unsigned char expectedHash[] =
  63737. {
  63738. 0x66, 0x49, 0x3C, 0xE8, 0x8A, 0x57, 0xB0, 0x60,
  63739. 0xDC, 0x55, 0x7D, 0xFC, 0x1F, 0xA5, 0xE5, 0x07,
  63740. 0x70, 0x5A, 0xF6, 0xD7, 0xC4, 0x1F, 0x1A, 0xE4,
  63741. 0x2D, 0xA6, 0xFD, 0xD1, 0x29, 0x7D, 0x60, 0x0D
  63742. };
  63743. const unsigned char emptyHash[] =
  63744. {
  63745. 0xE3, 0xB0, 0xC4, 0x42, 0x98, 0xFC, 0x1C, 0x14,
  63746. 0x9A, 0xFB, 0xF4, 0xC8, 0x99, 0x6F, 0xB9, 0x24,
  63747. 0x27, 0xAE, 0x41, 0xE4, 0x64, 0x9B, 0x93, 0x4C,
  63748. 0xA4, 0x95, 0x99, 0x1B, 0x78, 0x52, 0xB8, 0x55
  63749. };
  63750. unsigned char check[sizeof(testResult) + 1];
  63751. size_t checkSz = -1;
  63752. EVP_PKEY* key = NULL;
  63753. XMEMSET(out, 0, sizeof(out));
  63754. ExpectNotNull(bio = BIO_new(BIO_f_md()));
  63755. ExpectNotNull(mem = BIO_new(BIO_s_mem()));
  63756. ExpectIntEQ(BIO_get_md_ctx(bio, &ctx), 1);
  63757. ExpectIntEQ(EVP_DigestInit(ctx, EVP_sha256()), 1);
  63758. /* should not be able to write/read yet since just digest wrapper and no
  63759. * data is passing through the bio */
  63760. ExpectIntEQ(BIO_write(bio, msg, 0), 0);
  63761. ExpectIntEQ(BIO_pending(bio), 0);
  63762. ExpectIntEQ(BIO_read(bio, out, sizeof(out)), 0);
  63763. ExpectIntEQ(BIO_gets(bio, out, 3), 0);
  63764. ExpectIntEQ(BIO_gets(bio, out, sizeof(out)), 32);
  63765. ExpectIntEQ(XMEMCMP(emptyHash, out, 32), 0);
  63766. BIO_reset(bio);
  63767. /* append BIO mem to bio in order to read/write */
  63768. ExpectNotNull(bio = BIO_push(bio, mem));
  63769. XMEMSET(out, 0, sizeof(out));
  63770. ExpectIntEQ(BIO_write(mem, msg, sizeof(msg)), 16);
  63771. ExpectIntEQ(BIO_pending(bio), 16);
  63772. /* this just reads the message and does not hash it (gets calls final) */
  63773. ExpectIntEQ(BIO_read(bio, out, sizeof(out)), 16);
  63774. ExpectIntEQ(XMEMCMP(out, msg, sizeof(msg)), 0);
  63775. /* create a message digest using BIO */
  63776. XMEMSET(out, 0, sizeof(out));
  63777. ExpectIntEQ(BIO_write(bio, msg, sizeof(msg)), 16);
  63778. ExpectIntEQ(BIO_pending(mem), 16);
  63779. ExpectIntEQ(BIO_pending(bio), 16);
  63780. ExpectIntEQ(BIO_gets(bio, out, sizeof(out)), 32);
  63781. ExpectIntEQ(XMEMCMP(expectedHash, out, 32), 0);
  63782. BIO_free(bio);
  63783. bio = NULL;
  63784. BIO_free(mem);
  63785. mem = NULL;
  63786. /* test with HMAC */
  63787. XMEMSET(out, 0, sizeof(out));
  63788. ExpectNotNull(bio = BIO_new(BIO_f_md()));
  63789. ExpectNotNull(mem = BIO_new(BIO_s_mem()));
  63790. BIO_get_md_ctx(bio, &ctx);
  63791. ExpectNotNull(key = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, testKey,
  63792. (int)sizeof(testKey)));
  63793. EVP_DigestSignInit(ctx, NULL, EVP_sha256(), NULL, key);
  63794. ExpectNotNull(bio = BIO_push(bio, mem));
  63795. BIO_write(bio, testData, (int)strlen(testData));
  63796. ExpectIntEQ(EVP_DigestSignFinal(ctx, NULL, &checkSz), 1);
  63797. ExpectIntEQ(EVP_DigestSignFinal(ctx, check, &checkSz), 1);
  63798. ExpectIntEQ(XMEMCMP(check, testResult, sizeof(testResult)), 0);
  63799. EVP_PKEY_free(key);
  63800. BIO_free(bio);
  63801. BIO_free(mem);
  63802. #endif
  63803. return EXPECT_RESULT();
  63804. }
  63805. static int test_wolfSSL_BIO_up_ref(void)
  63806. {
  63807. EXPECT_DECLS;
  63808. #if defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA)
  63809. BIO* bio = NULL;
  63810. ExpectNotNull(bio = BIO_new(BIO_f_md()));
  63811. ExpectIntEQ(BIO_up_ref(NULL), 0);
  63812. ExpectIntEQ(BIO_up_ref(bio), 1);
  63813. BIO_free(bio);
  63814. ExpectIntEQ(BIO_up_ref(bio), 1);
  63815. BIO_free(bio);
  63816. BIO_free(bio);
  63817. #endif
  63818. return EXPECT_RESULT();
  63819. }
  63820. static int test_wolfSSL_BIO_reset(void)
  63821. {
  63822. EXPECT_DECLS;
  63823. #if defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA)
  63824. BIO* bio = NULL;
  63825. byte buf[16];
  63826. ExpectNotNull(bio = BIO_new_mem_buf("secure your data",
  63827. (word32)XSTRLEN("secure your data")));
  63828. ExpectIntEQ(BIO_read(bio, buf, 6), 6);
  63829. ExpectIntEQ(XMEMCMP(buf, "secure", 6), 0);
  63830. XMEMSET(buf, 0, 16);
  63831. ExpectIntEQ(BIO_read(bio, buf, 16), 10);
  63832. ExpectIntEQ(XMEMCMP(buf, " your data", 10), 0);
  63833. /* You cannot write to MEM BIO with read-only mode. */
  63834. ExpectIntEQ(BIO_write(bio, "WriteToReadonly", 15), 0);
  63835. ExpectIntEQ(BIO_read(bio, buf, 16), -1);
  63836. XMEMSET(buf, 0, 16);
  63837. ExpectIntEQ(BIO_reset(bio), 1);
  63838. ExpectIntEQ(BIO_read(bio, buf, 16), 16);
  63839. ExpectIntEQ(XMEMCMP(buf, "secure your data", 16), 0);
  63840. BIO_free(bio);
  63841. #endif
  63842. return EXPECT_RESULT();
  63843. }
  63844. #endif /* !NO_BIO */
  63845. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  63846. /* test that the callback arg is correct */
  63847. static int certCbArg = 0;
  63848. static int certCb(WOLFSSL* ssl, void* arg)
  63849. {
  63850. if (ssl == NULL || arg != &certCbArg)
  63851. return 0;
  63852. if (wolfSSL_is_server(ssl)) {
  63853. if (wolfSSL_use_certificate_file(ssl, svrCertFile,
  63854. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS)
  63855. return 0;
  63856. if (wolfSSL_use_PrivateKey_file(ssl, svrKeyFile,
  63857. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS)
  63858. return 0;
  63859. }
  63860. else {
  63861. if (wolfSSL_use_certificate_file(ssl, cliCertFile,
  63862. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS)
  63863. return 0;
  63864. if (wolfSSL_use_PrivateKey_file(ssl, cliKeyFile,
  63865. WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS)
  63866. return 0;
  63867. }
  63868. return 1;
  63869. }
  63870. static int certSetupCb(WOLFSSL_CTX* ctx)
  63871. {
  63872. SSL_CTX_set_cert_cb(ctx, certCb, &certCbArg);
  63873. return TEST_SUCCESS;
  63874. }
  63875. /**
  63876. * This is only done because test_wolfSSL_client_server_nofail_memio has no way
  63877. * to stop certificate and key loading
  63878. */
  63879. static int certClearCb(WOLFSSL* ssl)
  63880. {
  63881. /* Clear the loaded certs to force the callbacks to set them up */
  63882. SSL_certs_clear(ssl);
  63883. return TEST_SUCCESS;
  63884. }
  63885. #endif
  63886. static int test_wolfSSL_cert_cb(void)
  63887. {
  63888. EXPECT_DECLS;
  63889. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  63890. test_ssl_cbf func_cb_client;
  63891. test_ssl_cbf func_cb_server;
  63892. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  63893. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  63894. func_cb_client.ctx_ready = certSetupCb;
  63895. func_cb_client.ssl_ready = certClearCb;
  63896. func_cb_server.ctx_ready = certSetupCb;
  63897. func_cb_server.ssl_ready = certClearCb;
  63898. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  63899. &func_cb_server, NULL), TEST_SUCCESS);
  63900. #endif
  63901. return EXPECT_RESULT();
  63902. }
  63903. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  63904. static const char* test_wolfSSL_cert_cb_dyn_ciphers_client_cipher = NULL;
  63905. static const char* test_wolfSSL_cert_cb_dyn_ciphers_client_sigalgs = NULL;
  63906. static int test_wolfSSL_cert_cb_dyn_ciphers_client_ctx_ready(WOLFSSL_CTX* ctx)
  63907. {
  63908. EXPECT_DECLS;
  63909. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx,
  63910. test_wolfSSL_cert_cb_dyn_ciphers_client_cipher), WOLFSSL_SUCCESS);
  63911. ExpectIntEQ(wolfSSL_CTX_set1_sigalgs_list(ctx,
  63912. test_wolfSSL_cert_cb_dyn_ciphers_client_sigalgs), WOLFSSL_SUCCESS);
  63913. return EXPECT_RESULT();
  63914. }
  63915. static int test_wolfSSL_cert_cb_dyn_ciphers_certCB(WOLFSSL* ssl, void* arg)
  63916. {
  63917. const byte* suites = NULL;
  63918. word16 suiteSz = 0;
  63919. const byte* hashSigAlgo = NULL;
  63920. word16 hashSigAlgoSz = 0;
  63921. word16 idx = 0;
  63922. int haveRSA = 0;
  63923. int haveECC = 0;
  63924. (void)arg;
  63925. if (wolfSSL_get_client_suites_sigalgs(ssl, &suites, &suiteSz, &hashSigAlgo,
  63926. &hashSigAlgoSz) != WOLFSSL_SUCCESS)
  63927. return 0;
  63928. if (suites == NULL || suiteSz == 0 || hashSigAlgo == NULL ||
  63929. hashSigAlgoSz == 0)
  63930. return 0;
  63931. for (idx = 0; idx < suiteSz; idx += 2) {
  63932. WOLFSSL_CIPHERSUITE_INFO info =
  63933. wolfSSL_get_ciphersuite_info(suites[idx], suites[idx+1]);
  63934. if (info.rsaAuth)
  63935. haveRSA = 1;
  63936. else if (info.eccAuth)
  63937. haveECC = 1;
  63938. }
  63939. if (hashSigAlgoSz > 0) {
  63940. /* sigalgs extension takes precedence over ciphersuites */
  63941. haveRSA = 0;
  63942. haveECC = 0;
  63943. }
  63944. for (idx = 0; idx < hashSigAlgoSz; idx += 2) {
  63945. int hashAlgo = 0;
  63946. int sigAlgo = 0;
  63947. if (wolfSSL_get_sigalg_info(hashSigAlgo[idx+0], hashSigAlgo[idx+1],
  63948. &hashAlgo, &sigAlgo) != 0)
  63949. return 0;
  63950. if (sigAlgo == RSAk || sigAlgo == RSAPSSk)
  63951. haveRSA = 1;
  63952. else if (sigAlgo == ECDSAk)
  63953. haveECC = 1;
  63954. }
  63955. if (haveRSA) {
  63956. if (wolfSSL_use_certificate_file(ssl, svrCertFile, WOLFSSL_FILETYPE_PEM)
  63957. != WOLFSSL_SUCCESS)
  63958. return 0;
  63959. if (wolfSSL_use_PrivateKey_file(ssl, svrKeyFile, WOLFSSL_FILETYPE_PEM)
  63960. != WOLFSSL_SUCCESS)
  63961. return 0;
  63962. }
  63963. else if (haveECC) {
  63964. if (wolfSSL_use_certificate_file(ssl, eccCertFile, WOLFSSL_FILETYPE_PEM)
  63965. != WOLFSSL_SUCCESS)
  63966. return 0;
  63967. if (wolfSSL_use_PrivateKey_file(ssl, eccKeyFile, WOLFSSL_FILETYPE_PEM)
  63968. != WOLFSSL_SUCCESS)
  63969. return 0;
  63970. }
  63971. return 1;
  63972. }
  63973. static int test_wolfSSL_cert_cb_dyn_ciphers_server_ctx_ready(WOLFSSL_CTX* ctx)
  63974. {
  63975. SSL_CTX_set_cert_cb(ctx, test_wolfSSL_cert_cb_dyn_ciphers_certCB, NULL);
  63976. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_NONE, NULL);
  63977. return TEST_SUCCESS;
  63978. }
  63979. #endif
  63980. /* Testing dynamic ciphers offered by client */
  63981. static int test_wolfSSL_cert_cb_dyn_ciphers(void)
  63982. {
  63983. EXPECT_DECLS;
  63984. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  63985. test_ssl_cbf func_cb_client;
  63986. test_ssl_cbf func_cb_server;
  63987. struct {
  63988. method_provider client_meth;
  63989. const char* client_ciphers;
  63990. const char* client_sigalgs;
  63991. const char* client_ca;
  63992. method_provider server_meth;
  63993. } test_params[] = {
  63994. #if !defined(NO_SHA256) && defined(HAVE_AESGCM)
  63995. #ifdef WOLFSSL_TLS13
  63996. #if !defined(NO_RSA) && defined(WC_RSA_PSS)
  63997. {wolfTLSv1_3_client_method,
  63998. "TLS13-AES256-GCM-SHA384:TLS13-AES128-GCM-SHA256",
  63999. "RSA-PSS+SHA256", caCertFile, wolfTLSv1_3_server_method},
  64000. #endif
  64001. #ifdef HAVE_ECC
  64002. {wolfTLSv1_3_client_method,
  64003. "TLS13-AES256-GCM-SHA384:TLS13-AES128-GCM-SHA256",
  64004. "ECDSA+SHA256", caEccCertFile, wolfTLSv1_3_server_method},
  64005. #endif
  64006. #endif
  64007. #ifndef WOLFSSL_NO_TLS12
  64008. #if !defined(NO_RSA) && defined(WC_RSA_PSS) && !defined(NO_DH)
  64009. {wolfTLSv1_2_client_method,
  64010. "DHE-RSA-AES128-GCM-SHA256",
  64011. "RSA-PSS+SHA256", caCertFile, wolfTLSv1_2_server_method},
  64012. #endif
  64013. #ifdef HAVE_ECC
  64014. {wolfTLSv1_2_client_method,
  64015. "ECDHE-ECDSA-AES128-GCM-SHA256",
  64016. "ECDSA+SHA256", caEccCertFile, wolfTLSv1_2_server_method},
  64017. #endif
  64018. #endif
  64019. #endif
  64020. };
  64021. size_t i;
  64022. size_t testCount = sizeof(test_params)/sizeof(*test_params);
  64023. if (testCount > 0) {
  64024. for (i = 0; i < testCount; i++) {
  64025. printf("\tTesting %s ciphers with %s sigalgs\n",
  64026. test_params[i].client_ciphers,
  64027. test_params[i].client_sigalgs);
  64028. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  64029. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  64030. test_wolfSSL_cert_cb_dyn_ciphers_client_cipher =
  64031. test_params[i].client_ciphers;
  64032. test_wolfSSL_cert_cb_dyn_ciphers_client_sigalgs =
  64033. test_params[i].client_sigalgs;
  64034. func_cb_client.method = test_params[i].client_meth;
  64035. func_cb_client.caPemFile = test_params[i].client_ca;
  64036. func_cb_client.ctx_ready =
  64037. test_wolfSSL_cert_cb_dyn_ciphers_client_ctx_ready;
  64038. func_cb_server.ctx_ready =
  64039. test_wolfSSL_cert_cb_dyn_ciphers_server_ctx_ready;
  64040. func_cb_server.ssl_ready = certClearCb; /* Reuse from prev test */
  64041. func_cb_server.method = test_params[i].server_meth;
  64042. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  64043. &func_cb_server, NULL), TEST_SUCCESS);
  64044. }
  64045. }
  64046. #endif
  64047. return EXPECT_RESULT();
  64048. }
  64049. static int test_wolfSSL_ciphersuite_auth(void)
  64050. {
  64051. EXPECT_DECLS;
  64052. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EXTRA)
  64053. WOLFSSL_CIPHERSUITE_INFO info;
  64054. (void)info;
  64055. #ifndef WOLFSSL_NO_TLS12
  64056. #ifdef HAVE_CHACHA
  64057. info = wolfSSL_get_ciphersuite_info(CHACHA_BYTE,
  64058. TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256);
  64059. ExpectIntEQ(info.rsaAuth, 1);
  64060. ExpectIntEQ(info.eccAuth, 0);
  64061. ExpectIntEQ(info.eccStatic, 0);
  64062. ExpectIntEQ(info.psk, 0);
  64063. info = wolfSSL_get_ciphersuite_info(CHACHA_BYTE,
  64064. TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256);
  64065. ExpectIntEQ(info.rsaAuth, 0);
  64066. ExpectIntEQ(info.eccAuth, 1);
  64067. ExpectIntEQ(info.eccStatic, 0);
  64068. ExpectIntEQ(info.psk, 0);
  64069. info = wolfSSL_get_ciphersuite_info(CHACHA_BYTE,
  64070. TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256);
  64071. ExpectIntEQ(info.rsaAuth, 0);
  64072. ExpectIntEQ(info.eccAuth, 0);
  64073. ExpectIntEQ(info.eccStatic, 0);
  64074. ExpectIntEQ(info.psk, 1);
  64075. #endif
  64076. #if defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)
  64077. #ifndef NO_RSA
  64078. info = wolfSSL_get_ciphersuite_info(ECC_BYTE,
  64079. TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA);
  64080. ExpectIntEQ(info.rsaAuth, 1);
  64081. ExpectIntEQ(info.eccAuth, 0);
  64082. ExpectIntEQ(info.eccStatic, 0);
  64083. ExpectIntEQ(info.psk, 0);
  64084. info = wolfSSL_get_ciphersuite_info(ECC_BYTE,
  64085. TLS_ECDH_RSA_WITH_AES_128_CBC_SHA);
  64086. ExpectIntEQ(info.rsaAuth, 1);
  64087. ExpectIntEQ(info.eccAuth, 0);
  64088. ExpectIntEQ(info.eccStatic, 1);
  64089. ExpectIntEQ(info.psk, 0);
  64090. info = wolfSSL_get_ciphersuite_info(ECC_BYTE,
  64091. TLS_ECDH_RSA_WITH_AES_256_CBC_SHA);
  64092. ExpectIntEQ(info.rsaAuth, 1);
  64093. ExpectIntEQ(info.eccAuth, 0);
  64094. ExpectIntEQ(info.eccStatic, 1);
  64095. ExpectIntEQ(info.psk, 0);
  64096. #endif
  64097. info = wolfSSL_get_ciphersuite_info(ECC_BYTE,
  64098. TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA);
  64099. ExpectIntEQ(info.rsaAuth, 0);
  64100. ExpectIntEQ(info.eccAuth, 1);
  64101. ExpectIntEQ(info.eccStatic, 0);
  64102. ExpectIntEQ(info.psk, 0);
  64103. info = wolfSSL_get_ciphersuite_info(ECC_BYTE,
  64104. TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA);
  64105. ExpectIntEQ(info.rsaAuth, 0);
  64106. ExpectIntEQ(info.eccAuth, 1);
  64107. ExpectIntEQ(info.eccStatic, 1);
  64108. ExpectIntEQ(info.psk, 0);
  64109. info = wolfSSL_get_ciphersuite_info(ECDHE_PSK_BYTE,
  64110. TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256);
  64111. ExpectIntEQ(info.rsaAuth, 0);
  64112. ExpectIntEQ(info.eccAuth, 0);
  64113. ExpectIntEQ(info.eccStatic, 0);
  64114. ExpectIntEQ(info.psk, 1);
  64115. #endif
  64116. #endif
  64117. #ifdef WOLFSSL_TLS13
  64118. info = wolfSSL_get_ciphersuite_info(TLS13_BYTE,
  64119. TLS_AES_128_GCM_SHA256);
  64120. ExpectIntEQ(info.rsaAuth, 0);
  64121. ExpectIntEQ(info.eccAuth, 0);
  64122. ExpectIntEQ(info.eccStatic, 0);
  64123. ExpectIntEQ(info.psk, 0);
  64124. #endif
  64125. #endif
  64126. return EXPECT_RESULT();
  64127. }
  64128. static int test_wolfSSL_sigalg_info(void)
  64129. {
  64130. EXPECT_DECLS;
  64131. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_EXTRA)
  64132. byte hashSigAlgo[WOLFSSL_MAX_SIGALGO];
  64133. word16 len = 0;
  64134. word16 idx = 0;
  64135. int allSigAlgs = SIG_ECDSA | SIG_RSA | SIG_SM2 | SIG_FALCON | SIG_DILITHIUM;
  64136. InitSuitesHashSigAlgo(hashSigAlgo, allSigAlgs, 1, 0xFFFFFFFF, &len);
  64137. for (idx = 0; idx < len; idx += 2) {
  64138. int hashAlgo = 0;
  64139. int sigAlgo = 0;
  64140. ExpectIntEQ(wolfSSL_get_sigalg_info(hashSigAlgo[idx+0],
  64141. hashSigAlgo[idx+1], &hashAlgo, &sigAlgo), 0);
  64142. ExpectIntNE(hashAlgo, 0);
  64143. ExpectIntNE(sigAlgo, 0);
  64144. }
  64145. InitSuitesHashSigAlgo(hashSigAlgo, allSigAlgs | SIG_ANON, 1,
  64146. 0xFFFFFFFF, &len);
  64147. for (idx = 0; idx < len; idx += 2) {
  64148. int hashAlgo = 0;
  64149. int sigAlgo = 0;
  64150. ExpectIntEQ(wolfSSL_get_sigalg_info(hashSigAlgo[idx+0],
  64151. hashSigAlgo[idx+1], &hashAlgo, &sigAlgo), 0);
  64152. ExpectIntNE(hashAlgo, 0);
  64153. }
  64154. #endif
  64155. return EXPECT_RESULT();
  64156. }
  64157. static int test_wolfSSL_SESSION(void)
  64158. {
  64159. EXPECT_DECLS;
  64160. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  64161. !defined(NO_RSA) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  64162. !defined(NO_SESSION_CACHE)
  64163. WOLFSSL* ssl = NULL;
  64164. WOLFSSL_CTX* ctx = NULL;
  64165. WOLFSSL_SESSION* sess = NULL;
  64166. WOLFSSL_SESSION* sess_copy = NULL;
  64167. #ifdef OPENSSL_EXTRA
  64168. #ifdef HAVE_EXT_CACHE
  64169. unsigned char* sessDer = NULL;
  64170. unsigned char* ptr = NULL;
  64171. int sz = 0;
  64172. #endif
  64173. const unsigned char context[] = "user app context";
  64174. unsigned int contextSz = (unsigned int)sizeof(context);
  64175. #endif
  64176. int ret = 0, err = 0;
  64177. SOCKET_T sockfd;
  64178. tcp_ready ready;
  64179. func_args server_args;
  64180. THREAD_TYPE serverThread;
  64181. char msg[80];
  64182. const char* sendGET = "GET";
  64183. /* TLS v1.3 requires session tickets */
  64184. /* CHACHA and POLY1305 required for myTicketEncCb */
  64185. #if !defined(WOLFSSL_NO_TLS12) && (!defined(WOLFSSL_TLS13) || \
  64186. !(defined(HAVE_SESSION_TICKET) && ((defined(HAVE_CHACHA) && \
  64187. defined(HAVE_POLY1305)) || defined(HAVE_AESGCM))))
  64188. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method()));
  64189. #else
  64190. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  64191. #endif
  64192. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, cliCertFile,
  64193. WOLFSSL_FILETYPE_PEM));
  64194. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, cliKeyFile,
  64195. WOLFSSL_FILETYPE_PEM));
  64196. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0),
  64197. WOLFSSL_SUCCESS);
  64198. #ifdef WOLFSSL_ENCRYPTED_KEYS
  64199. wolfSSL_CTX_set_default_passwd_cb(ctx, PasswordCallBack);
  64200. #endif
  64201. #ifdef HAVE_SESSION_TICKET
  64202. /* Use session tickets, for ticket tests below */
  64203. ExpectIntEQ(wolfSSL_CTX_UseSessionTicket(ctx), WOLFSSL_SUCCESS);
  64204. #endif
  64205. XMEMSET(&server_args, 0, sizeof(func_args));
  64206. #ifdef WOLFSSL_TIRTOS
  64207. fdOpenSession(Task_self());
  64208. #endif
  64209. StartTCP();
  64210. InitTcpReady(&ready);
  64211. #if defined(USE_WINDOWS_API)
  64212. /* use RNG to get random port if using windows */
  64213. ready.port = GetRandomPort();
  64214. #endif
  64215. server_args.signal = &ready;
  64216. start_thread(test_server_nofail, &server_args, &serverThread);
  64217. wait_tcp_ready(&server_args);
  64218. /* client connection */
  64219. ExpectNotNull(ssl = wolfSSL_new(ctx));
  64220. tcp_connect(&sockfd, wolfSSLIP, ready.port, 0, 0, ssl);
  64221. ExpectIntEQ(wolfSSL_set_fd(ssl, sockfd), WOLFSSL_SUCCESS);
  64222. #ifdef WOLFSSL_ASYNC_CRYPT
  64223. err = 0; /* Reset error */
  64224. #endif
  64225. do {
  64226. #ifdef WOLFSSL_ASYNC_CRYPT
  64227. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  64228. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  64229. if (ret < 0) { break; } else if (ret == 0) { continue; }
  64230. }
  64231. #endif
  64232. ret = wolfSSL_connect(ssl);
  64233. err = wolfSSL_get_error(ssl, 0);
  64234. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  64235. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  64236. #ifdef WOLFSSL_ASYNC_CRYPT
  64237. err = 0; /* Reset error */
  64238. #endif
  64239. do {
  64240. #ifdef WOLFSSL_ASYNC_CRYPT
  64241. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  64242. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  64243. if (ret < 0) { break; } else if (ret == 0) { continue; }
  64244. }
  64245. #endif
  64246. ret = wolfSSL_write(ssl, sendGET, (int)XSTRLEN(sendGET));
  64247. err = wolfSSL_get_error(ssl, 0);
  64248. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  64249. ExpectIntEQ(ret, (int)XSTRLEN(sendGET));
  64250. #ifdef WOLFSSL_ASYNC_CRYPT
  64251. err = 0; /* Reset error */
  64252. #endif
  64253. do {
  64254. #ifdef WOLFSSL_ASYNC_CRYPT
  64255. if (err == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  64256. ret = wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
  64257. if (ret < 0) { break; } else if (ret == 0) { continue; }
  64258. }
  64259. #endif
  64260. ret = wolfSSL_read(ssl, msg, sizeof(msg));
  64261. err = wolfSSL_get_error(ssl, 0);
  64262. } while (err == WC_NO_ERR_TRACE(WC_PENDING_E));
  64263. ExpectIntEQ(ret, 23);
  64264. ExpectPtrNE((sess = wolfSSL_get1_session(ssl)), NULL); /* ref count 1 */
  64265. ExpectPtrNE((sess_copy = wolfSSL_get1_session(ssl)), NULL); /* ref count 2 */
  64266. ExpectIntEQ(wolfSSL_SessionIsSetup(sess), 1);
  64267. #ifdef HAVE_EXT_CACHE
  64268. ExpectPtrEq(sess, sess_copy); /* they should be the same pointer but without
  64269. * HAVE_EXT_CACHE we get new objects each time */
  64270. #endif
  64271. wolfSSL_SESSION_free(sess_copy); sess_copy = NULL;
  64272. wolfSSL_SESSION_free(sess); sess = NULL; /* free session ref */
  64273. sess = wolfSSL_get_session(ssl);
  64274. #ifdef OPENSSL_EXTRA
  64275. ExpectIntEQ(SSL_SESSION_is_resumable(NULL), 0);
  64276. ExpectIntEQ(SSL_SESSION_is_resumable(sess), 1);
  64277. ExpectIntEQ(wolfSSL_SESSION_has_ticket(NULL), 0);
  64278. ExpectIntEQ(wolfSSL_SESSION_get_ticket_lifetime_hint(NULL), 0);
  64279. #ifdef HAVE_SESSION_TICKET
  64280. ExpectIntEQ(wolfSSL_SESSION_has_ticket(sess), 1);
  64281. ExpectIntEQ(wolfSSL_SESSION_get_ticket_lifetime_hint(sess),
  64282. SESSION_TICKET_HINT_DEFAULT);
  64283. #else
  64284. ExpectIntEQ(wolfSSL_SESSION_has_ticket(sess), 0);
  64285. #endif
  64286. #else
  64287. (void)sess;
  64288. #endif /* OPENSSL_EXTRA */
  64289. /* Retain copy of the session for later testing */
  64290. ExpectNotNull(sess = wolfSSL_get1_session(ssl));
  64291. wolfSSL_shutdown(ssl);
  64292. wolfSSL_free(ssl); ssl = NULL;
  64293. CloseSocket(sockfd);
  64294. join_thread(serverThread);
  64295. FreeTcpReady(&ready);
  64296. #ifdef WOLFSSL_TIRTOS
  64297. fdOpenSession(Task_self());
  64298. #endif
  64299. #if defined(SESSION_CERTS) && defined(OPENSSL_EXTRA)
  64300. {
  64301. X509 *x509 = NULL;
  64302. char buf[30];
  64303. int bufSz = 0;
  64304. ExpectNotNull(x509 = SSL_SESSION_get0_peer(sess));
  64305. ExpectIntGT((bufSz = X509_NAME_get_text_by_NID(
  64306. X509_get_subject_name(x509), NID_organizationalUnitName, buf,
  64307. sizeof(buf))), 0);
  64308. ExpectIntNE((bufSz == 7 || bufSz == 16), 0); /* should be one of these*/
  64309. if (bufSz == 7) {
  64310. ExpectIntEQ(XMEMCMP(buf, "Support", bufSz), 0);
  64311. }
  64312. if (bufSz == 16) {
  64313. ExpectIntEQ(XMEMCMP(buf, "Programming-2048", bufSz), 0);
  64314. }
  64315. }
  64316. #endif
  64317. #ifdef HAVE_EXT_CACHE
  64318. ExpectNotNull(sess_copy = wolfSSL_SESSION_dup(sess));
  64319. wolfSSL_SESSION_free(sess_copy); sess_copy = NULL;
  64320. sess_copy = NULL;
  64321. #endif
  64322. #if defined(OPENSSL_EXTRA) && defined(HAVE_EXT_CACHE)
  64323. /* get session from DER and update the timeout */
  64324. ExpectIntEQ(wolfSSL_i2d_SSL_SESSION(NULL, &sessDer), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  64325. ExpectIntGT((sz = wolfSSL_i2d_SSL_SESSION(sess, &sessDer)), 0);
  64326. wolfSSL_SESSION_free(sess); sess = NULL;
  64327. sess = NULL;
  64328. ptr = sessDer;
  64329. ExpectNull(sess = wolfSSL_d2i_SSL_SESSION(NULL, NULL, sz));
  64330. ExpectNotNull(sess = wolfSSL_d2i_SSL_SESSION(NULL,
  64331. (const unsigned char**)&ptr, sz));
  64332. XFREE(sessDer, NULL, DYNAMIC_TYPE_OPENSSL);
  64333. sessDer = NULL;
  64334. ExpectIntGT(wolfSSL_SESSION_get_time(sess), 0);
  64335. ExpectIntEQ(wolfSSL_SSL_SESSION_set_timeout(sess, 500), SSL_SUCCESS);
  64336. #endif
  64337. /* successful set session test */
  64338. ExpectNotNull(ssl = wolfSSL_new(ctx));
  64339. ExpectIntEQ(wolfSSL_set_session(ssl, sess), WOLFSSL_SUCCESS);
  64340. #ifdef HAVE_SESSION_TICKET
  64341. /* Test set/get session ticket */
  64342. {
  64343. const char* ticket = "This is a session ticket";
  64344. char buf[64] = {0};
  64345. word32 bufSz = (word32)sizeof(buf);
  64346. ExpectIntEQ(SSL_SUCCESS,
  64347. wolfSSL_set_SessionTicket(ssl, (byte *)ticket,
  64348. (word32)XSTRLEN(ticket)));
  64349. ExpectIntEQ(SSL_SUCCESS,
  64350. wolfSSL_get_SessionTicket(ssl, (byte *)buf, &bufSz));
  64351. ExpectStrEQ(ticket, buf);
  64352. }
  64353. #endif
  64354. #ifdef OPENSSL_EXTRA
  64355. /* session timeout case */
  64356. /* make the session to be expired */
  64357. ExpectIntEQ(SSL_SESSION_set_timeout(sess,1), SSL_SUCCESS);
  64358. XSLEEP_MS(1200);
  64359. /* SSL_set_session should reject specified session but return success
  64360. * if WOLFSSL_ERROR_CODE_OPENSSL macro is defined for OpenSSL compatibility.
  64361. */
  64362. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  64363. ExpectIntEQ(wolfSSL_set_session(ssl,sess), SSL_SUCCESS);
  64364. #else
  64365. ExpectIntEQ(wolfSSL_set_session(ssl,sess), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64366. #endif
  64367. ExpectIntEQ(wolfSSL_SSL_SESSION_set_timeout(sess, 500), SSL_SUCCESS);
  64368. #ifdef WOLFSSL_SESSION_ID_CTX
  64369. /* fail case with miss match session context IDs (use compatibility API) */
  64370. ExpectIntEQ(SSL_set_session_id_context(ssl, context, contextSz),
  64371. SSL_SUCCESS);
  64372. ExpectIntEQ(wolfSSL_set_session(ssl, sess), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64373. wolfSSL_free(ssl); ssl = NULL;
  64374. ExpectIntEQ(SSL_CTX_set_session_id_context(NULL, context, contextSz),
  64375. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64376. ExpectIntEQ(SSL_CTX_set_session_id_context(ctx, context, contextSz),
  64377. SSL_SUCCESS);
  64378. ExpectNotNull(ssl = wolfSSL_new(ctx));
  64379. ExpectIntEQ(wolfSSL_set_session(ssl, sess), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64380. #endif
  64381. #endif /* OPENSSL_EXTRA */
  64382. wolfSSL_free(ssl);
  64383. wolfSSL_SESSION_free(sess);
  64384. wolfSSL_CTX_free(ctx);
  64385. #endif
  64386. return EXPECT_RESULT();
  64387. }
  64388. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  64389. !defined(NO_RSA) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  64390. !defined(NO_SESSION_CACHE) && defined(OPENSSL_EXTRA) && \
  64391. !defined(WOLFSSL_NO_TLS12)
  64392. static WOLFSSL_SESSION* test_wolfSSL_SESSION_expire_sess = NULL;
  64393. static void test_wolfSSL_SESSION_expire_downgrade_ctx_ready(WOLFSSL_CTX* ctx)
  64394. {
  64395. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  64396. /* returns previous timeout value */
  64397. AssertIntEQ(wolfSSL_CTX_set_timeout(ctx, 1), 500);
  64398. #else
  64399. AssertIntEQ(wolfSSL_CTX_set_timeout(ctx, 1), WOLFSSL_SUCCESS);
  64400. #endif
  64401. }
  64402. /* set the session to timeout in a second */
  64403. static void test_wolfSSL_SESSION_expire_downgrade_ssl_ready(WOLFSSL* ssl)
  64404. {
  64405. AssertIntEQ(wolfSSL_set_timeout(ssl, 2), 1);
  64406. }
  64407. /* store the client side session from the first successful connection */
  64408. static void test_wolfSSL_SESSION_expire_downgrade_ssl_result(WOLFSSL* ssl)
  64409. {
  64410. AssertPtrNE((test_wolfSSL_SESSION_expire_sess = wolfSSL_get1_session(ssl)),
  64411. NULL); /* ref count 1 */
  64412. }
  64413. /* wait till session is expired then set it in the WOLFSSL struct for use */
  64414. static void test_wolfSSL_SESSION_expire_downgrade_ssl_ready_wait(WOLFSSL* ssl)
  64415. {
  64416. AssertIntEQ(wolfSSL_set_timeout(ssl, 1), 1);
  64417. AssertIntEQ(wolfSSL_set_session(ssl, test_wolfSSL_SESSION_expire_sess),
  64418. WOLFSSL_SUCCESS);
  64419. XSLEEP_MS(2000); /* wait 2 seconds for session to expire */
  64420. }
  64421. /* set expired session in the WOLFSSL struct for use */
  64422. static void test_wolfSSL_SESSION_expire_downgrade_ssl_ready_set(WOLFSSL* ssl)
  64423. {
  64424. XSLEEP_MS(1200); /* wait a second for session to expire */
  64425. /* set the expired session, call to set session fails but continuing on
  64426. after failure should be handled here */
  64427. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_ERROR_CODE_OPENSSL)
  64428. AssertIntEQ(wolfSSL_set_session(ssl, test_wolfSSL_SESSION_expire_sess),
  64429. WOLFSSL_SUCCESS);
  64430. #else
  64431. AssertIntNE(wolfSSL_set_session(ssl, test_wolfSSL_SESSION_expire_sess),
  64432. WOLFSSL_SUCCESS);
  64433. #endif
  64434. }
  64435. /* check that the expired session was not reused */
  64436. static void test_wolfSSL_SESSION_expire_downgrade_ssl_result_reuse(WOLFSSL* ssl)
  64437. {
  64438. /* since the session has expired it should not have been reused */
  64439. AssertIntEQ(wolfSSL_session_reused(ssl), 0);
  64440. }
  64441. #endif
  64442. static int test_wolfSSL_SESSION_expire_downgrade(void)
  64443. {
  64444. EXPECT_DECLS;
  64445. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  64446. !defined(NO_RSA) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  64447. !defined(NO_SESSION_CACHE) && defined(OPENSSL_EXTRA) && \
  64448. !defined(WOLFSSL_NO_TLS12)
  64449. WOLFSSL_CTX* ctx = NULL;
  64450. callback_functions server_cbf, client_cbf;
  64451. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  64452. XMEMSET(&client_cbf, 0, sizeof(callback_functions));
  64453. /* force server side to use TLS 1.2 */
  64454. server_cbf.ctx = ctx;
  64455. server_cbf.method = wolfTLSv1_2_server_method;
  64456. client_cbf.method = wolfSSLv23_client_method;
  64457. server_cbf.ctx_ready = test_wolfSSL_SESSION_expire_downgrade_ctx_ready;
  64458. client_cbf.ssl_ready = test_wolfSSL_SESSION_expire_downgrade_ssl_ready;
  64459. client_cbf.on_result = test_wolfSSL_SESSION_expire_downgrade_ssl_result;
  64460. test_wolfSSL_client_server_nofail(&client_cbf, &server_cbf);
  64461. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  64462. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  64463. /* set the previously created session and wait till expired */
  64464. server_cbf.ctx = ctx;
  64465. client_cbf.method = wolfSSLv23_client_method;
  64466. server_cbf.ctx_ready = test_wolfSSL_SESSION_expire_downgrade_ctx_ready;
  64467. client_cbf.ssl_ready = test_wolfSSL_SESSION_expire_downgrade_ssl_ready_wait;
  64468. client_cbf.on_result =
  64469. test_wolfSSL_SESSION_expire_downgrade_ssl_result_reuse;
  64470. test_wolfSSL_client_server_nofail(&client_cbf, &server_cbf);
  64471. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  64472. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  64473. /* set the previously created expired session */
  64474. server_cbf.ctx = ctx;
  64475. client_cbf.method = wolfSSLv23_client_method;
  64476. server_cbf.ctx_ready = test_wolfSSL_SESSION_expire_downgrade_ctx_ready;
  64477. client_cbf.ssl_ready = test_wolfSSL_SESSION_expire_downgrade_ssl_ready_set;
  64478. client_cbf.on_result =
  64479. test_wolfSSL_SESSION_expire_downgrade_ssl_result_reuse;
  64480. test_wolfSSL_client_server_nofail(&client_cbf, &server_cbf);
  64481. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  64482. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  64483. wolfSSL_SESSION_free(test_wolfSSL_SESSION_expire_sess);
  64484. wolfSSL_CTX_free(ctx);
  64485. #endif
  64486. return EXPECT_RESULT();
  64487. }
  64488. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  64489. defined(HAVE_EX_DATA) && !defined(NO_SESSION_CACHE)
  64490. #ifdef WOLFSSL_ATOMIC_OPS
  64491. typedef wolfSSL_Atomic_Int SessRemCounter_t;
  64492. #else
  64493. typedef int SessRemCounter_t;
  64494. #endif
  64495. static SessRemCounter_t clientSessRemCountMalloc;
  64496. static SessRemCounter_t serverSessRemCountMalloc;
  64497. static SessRemCounter_t clientSessRemCountFree;
  64498. static SessRemCounter_t serverSessRemCountFree;
  64499. static WOLFSSL_CTX* serverSessCtx = NULL;
  64500. static WOLFSSL_SESSION* serverSess = NULL;
  64501. #if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \
  64502. !defined(NO_SESSION_CACHE_REF)
  64503. static WOLFSSL_CTX* clientSessCtx = NULL;
  64504. static WOLFSSL_SESSION* clientSess = NULL;
  64505. #endif
  64506. static int serverSessRemIdx = 3;
  64507. static int sessRemCtx_Server = WOLFSSL_SERVER_END;
  64508. static int sessRemCtx_Client = WOLFSSL_CLIENT_END;
  64509. static void SessRemCtxCb(WOLFSSL_CTX *ctx, WOLFSSL_SESSION *sess)
  64510. {
  64511. int* side;
  64512. (void)ctx;
  64513. side = (int*)SSL_SESSION_get_ex_data(sess, serverSessRemIdx);
  64514. if (side != NULL) {
  64515. if (*side == WOLFSSL_CLIENT_END)
  64516. (void)wolfSSL_Atomic_Int_FetchAdd(&clientSessRemCountFree, 1);
  64517. else
  64518. (void)wolfSSL_Atomic_Int_FetchAdd(&serverSessRemCountFree, 1);
  64519. SSL_SESSION_set_ex_data(sess, serverSessRemIdx, NULL);
  64520. }
  64521. }
  64522. static int SessRemCtxSetupCb(WOLFSSL_CTX* ctx)
  64523. {
  64524. SSL_CTX_sess_set_remove_cb(ctx, SessRemCtxCb);
  64525. #if defined(WOLFSSL_TLS13) && !defined(HAVE_SESSION_TICKET) && \
  64526. !defined(NO_SESSION_CACHE_REF)
  64527. {
  64528. EXPECT_DECLS;
  64529. /* Allow downgrade, set min version, and disable TLS 1.3.
  64530. * Do this because without NO_SESSION_CACHE_REF we will want to return a
  64531. * reference to the session cache. But with WOLFSSL_TLS13 and without
  64532. * HAVE_SESSION_TICKET we won't have a session ID to be able to place
  64533. * the session in the cache. In this case we need to downgrade to
  64534. * previous versions to just use the legacy session ID field. */
  64535. ExpectIntEQ(SSL_CTX_set_min_proto_version(ctx, SSL3_VERSION),
  64536. SSL_SUCCESS);
  64537. ExpectIntEQ(SSL_CTX_set_max_proto_version(ctx, TLS1_2_VERSION),
  64538. SSL_SUCCESS);
  64539. return EXPECT_RESULT();
  64540. }
  64541. #else
  64542. return TEST_SUCCESS;
  64543. #endif
  64544. }
  64545. static int SessRemSslSetupCb(WOLFSSL* ssl)
  64546. {
  64547. EXPECT_DECLS;
  64548. int* side;
  64549. if (SSL_is_server(ssl)) {
  64550. side = &sessRemCtx_Server;
  64551. (void)wolfSSL_Atomic_Int_FetchAdd(&serverSessRemCountMalloc, 1);
  64552. ExpectNotNull(serverSess = SSL_get1_session(ssl));
  64553. ExpectIntEQ(SSL_CTX_up_ref(serverSessCtx = SSL_get_SSL_CTX(ssl)),
  64554. SSL_SUCCESS);
  64555. }
  64556. else {
  64557. side = &sessRemCtx_Client;
  64558. (void)wolfSSL_Atomic_Int_FetchAdd(&clientSessRemCountMalloc, 1);
  64559. #if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \
  64560. !defined(NO_SESSION_CACHE_REF)
  64561. ExpectNotNull(clientSess = SSL_get1_session(ssl));
  64562. ExpectIntEQ(SSL_CTX_up_ref(clientSessCtx = SSL_get_SSL_CTX(ssl)),
  64563. SSL_SUCCESS);
  64564. #endif
  64565. }
  64566. ExpectIntEQ(SSL_SESSION_set_ex_data(SSL_get_session(ssl),
  64567. serverSessRemIdx, side), SSL_SUCCESS);
  64568. return EXPECT_RESULT();
  64569. }
  64570. #endif
  64571. static int test_wolfSSL_CTX_sess_set_remove_cb(void)
  64572. {
  64573. EXPECT_DECLS;
  64574. #if defined(OPENSSL_EXTRA) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  64575. defined(HAVE_EX_DATA) && !defined(NO_SESSION_CACHE)
  64576. /* Check that the remove callback gets called for external data in a
  64577. * session object */
  64578. test_ssl_cbf func_cb;
  64579. wolfSSL_Atomic_Int_Init(&clientSessRemCountMalloc, 0);
  64580. wolfSSL_Atomic_Int_Init(&serverSessRemCountMalloc, 0);
  64581. wolfSSL_Atomic_Int_Init(&clientSessRemCountFree, 0);
  64582. wolfSSL_Atomic_Int_Init(&serverSessRemCountFree, 0);
  64583. XMEMSET(&func_cb, 0, sizeof(func_cb));
  64584. func_cb.ctx_ready = SessRemCtxSetupCb;
  64585. func_cb.on_result = SessRemSslSetupCb;
  64586. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb, &func_cb,
  64587. NULL), TEST_SUCCESS);
  64588. /* Both should have been allocated */
  64589. ExpectIntEQ(clientSessRemCountMalloc, 1);
  64590. ExpectIntEQ(serverSessRemCountMalloc, 1);
  64591. /* This should not be called yet. Session wasn't evicted from cache yet. */
  64592. ExpectIntEQ(clientSessRemCountFree, 0);
  64593. #if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \
  64594. !defined(NO_SESSION_CACHE_REF)
  64595. /* Force a cache lookup */
  64596. ExpectNotNull(SSL_SESSION_get_ex_data(clientSess, serverSessRemIdx));
  64597. /* Force a cache update */
  64598. ExpectNotNull(SSL_SESSION_set_ex_data(clientSess, serverSessRemIdx - 1, 0));
  64599. /* This should set the timeout to 0 and call the remove callback from within
  64600. * the session cache. */
  64601. ExpectIntEQ(SSL_CTX_remove_session(clientSessCtx, clientSess), 0);
  64602. ExpectNull(SSL_SESSION_get_ex_data(clientSess, serverSessRemIdx));
  64603. ExpectIntEQ(clientSessRemCountFree, 1);
  64604. #endif
  64605. /* Server session is in the cache so ex_data isn't free'd with the SSL
  64606. * object */
  64607. ExpectIntEQ(serverSessRemCountFree, 0);
  64608. /* Force a cache lookup */
  64609. ExpectNotNull(SSL_SESSION_get_ex_data(serverSess, serverSessRemIdx));
  64610. /* Force a cache update */
  64611. ExpectNotNull(SSL_SESSION_set_ex_data(serverSess, serverSessRemIdx - 1, 0));
  64612. /* This should set the timeout to 0 and call the remove callback from within
  64613. * the session cache. */
  64614. ExpectIntEQ(SSL_CTX_remove_session(serverSessCtx, serverSess), 0);
  64615. ExpectNull(SSL_SESSION_get_ex_data(serverSess, serverSessRemIdx));
  64616. ExpectIntEQ(serverSessRemCountFree, 1);
  64617. /* Need to free the references that we kept */
  64618. SSL_CTX_free(serverSessCtx);
  64619. SSL_SESSION_free(serverSess);
  64620. #if (defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET)) || \
  64621. !defined(NO_SESSION_CACHE_REF)
  64622. SSL_CTX_free(clientSessCtx);
  64623. SSL_SESSION_free(clientSess);
  64624. #endif
  64625. #endif
  64626. return EXPECT_RESULT();
  64627. }
  64628. static int test_wolfSSL_ticket_keys(void)
  64629. {
  64630. EXPECT_DECLS;
  64631. #if defined(HAVE_SESSION_TICKET) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  64632. !defined(NO_WOLFSSL_SERVER)
  64633. WOLFSSL_CTX* ctx = NULL;
  64634. byte keys[WOLFSSL_TICKET_KEYS_SZ];
  64635. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  64636. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(NULL, NULL, 0),
  64637. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64638. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(ctx, NULL, 0),
  64639. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64640. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(ctx, keys, 0),
  64641. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64642. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(NULL, keys, 0),
  64643. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64644. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(NULL, NULL, sizeof(keys)),
  64645. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64646. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(ctx, NULL, sizeof(keys)),
  64647. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64648. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(NULL, keys, sizeof(keys)),
  64649. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64650. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(NULL, NULL, 0),
  64651. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64652. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(ctx, NULL, 0),
  64653. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64654. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(ctx, keys, 0),
  64655. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64656. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(NULL, keys, 0),
  64657. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64658. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(NULL, NULL, sizeof(keys)),
  64659. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64660. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(ctx, NULL, sizeof(keys)),
  64661. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64662. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(NULL, keys, sizeof(keys)),
  64663. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64664. ExpectIntEQ(wolfSSL_CTX_get_tlsext_ticket_keys(ctx, keys, sizeof(keys)),
  64665. WOLFSSL_SUCCESS);
  64666. ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_keys(ctx, keys, sizeof(keys)),
  64667. WOLFSSL_SUCCESS);
  64668. wolfSSL_CTX_free(ctx);
  64669. #endif
  64670. return EXPECT_RESULT();
  64671. }
  64672. #ifndef NO_BIO
  64673. static int test_wolfSSL_d2i_PUBKEY(void)
  64674. {
  64675. EXPECT_DECLS;
  64676. #if defined(OPENSSL_EXTRA)
  64677. BIO* bio = NULL;
  64678. EVP_PKEY* pkey = NULL;
  64679. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  64680. ExpectNull(d2i_PUBKEY_bio(NULL, NULL));
  64681. #if defined(USE_CERT_BUFFERS_2048) && !defined(NO_RSA)
  64682. /* RSA PUBKEY test */
  64683. ExpectIntGT(BIO_write(bio, client_keypub_der_2048,
  64684. sizeof_client_keypub_der_2048), 0);
  64685. ExpectNotNull(pkey = d2i_PUBKEY_bio(bio, NULL));
  64686. EVP_PKEY_free(pkey);
  64687. pkey = NULL;
  64688. #endif
  64689. #if defined(USE_CERT_BUFFERS_256) && defined(HAVE_ECC)
  64690. /* ECC PUBKEY test */
  64691. ExpectIntGT(BIO_write(bio, ecc_clikeypub_der_256,
  64692. sizeof_ecc_clikeypub_der_256), 0);
  64693. ExpectNotNull(pkey = d2i_PUBKEY_bio(bio, NULL));
  64694. EVP_PKEY_free(pkey);
  64695. pkey = NULL;
  64696. #endif
  64697. #if defined(USE_CERT_BUFFERS_2048) && !defined(NO_DSA)
  64698. /* DSA PUBKEY test */
  64699. ExpectIntGT(BIO_write(bio, dsa_pub_key_der_2048,
  64700. sizeof_dsa_pub_key_der_2048), 0);
  64701. ExpectNotNull(pkey = d2i_PUBKEY_bio(bio, NULL));
  64702. EVP_PKEY_free(pkey);
  64703. pkey = NULL;
  64704. #endif
  64705. #if defined(USE_CERT_BUFFERS_2048) && !defined(NO_DH) && \
  64706. defined(OPENSSL_EXTRA) && defined(WOLFSSL_DH_EXTRA)
  64707. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  64708. (HAVE_FIPS_VERSION > 2))
  64709. /* DH PUBKEY test */
  64710. ExpectIntGT(BIO_write(bio, dh_pub_key_der_2048,
  64711. sizeof_dh_pub_key_der_2048), 0);
  64712. ExpectNotNull(pkey = d2i_PUBKEY_bio(bio, NULL));
  64713. EVP_PKEY_free(pkey);
  64714. pkey = NULL;
  64715. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  64716. #endif /* USE_CERT_BUFFERS_2048 && !NO_DH && && OPENSSL_EXTRA */
  64717. BIO_free(bio);
  64718. (void)pkey;
  64719. #endif
  64720. return EXPECT_RESULT();
  64721. }
  64722. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO)) && !defined(NO_RSA)
  64723. static int test_wolfSSL_d2i_PrivateKeys_bio(void)
  64724. {
  64725. EXPECT_DECLS;
  64726. BIO* bio = NULL;
  64727. EVP_PKEY* pkey = NULL;
  64728. WOLFSSL_CTX* ctx = NULL;
  64729. #if defined(WOLFSSL_KEY_GEN)
  64730. unsigned char buff[4096];
  64731. unsigned char* bufPtr = buff;
  64732. #endif
  64733. /* test creating new EVP_PKEY with bad arg */
  64734. ExpectNull((pkey = d2i_PrivateKey_bio(NULL, NULL)));
  64735. /* test loading RSA key using BIO */
  64736. #if !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  64737. {
  64738. XFILE file = XBADFILE;
  64739. const char* fname = "./certs/server-key.der";
  64740. size_t sz = 0;
  64741. byte* buf = NULL;
  64742. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  64743. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  64744. ExpectTrue((sz = XFTELL(file)) != 0);
  64745. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  64746. ExpectNotNull(buf = (byte*)XMALLOC(sz, HEAP_HINT, DYNAMIC_TYPE_FILE));
  64747. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  64748. if (file != XBADFILE) {
  64749. XFCLOSE(file);
  64750. }
  64751. /* Test using BIO new mem and loading DER private key */
  64752. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  64753. ExpectNotNull((pkey = d2i_PrivateKey_bio(bio, NULL)));
  64754. XFREE(buf, HEAP_HINT, DYNAMIC_TYPE_FILE);
  64755. BIO_free(bio);
  64756. bio = NULL;
  64757. EVP_PKEY_free(pkey);
  64758. pkey = NULL;
  64759. }
  64760. #endif
  64761. /* test loading ECC key using BIO */
  64762. #if defined(HAVE_ECC) && !defined(NO_FILESYSTEM)
  64763. {
  64764. XFILE file = XBADFILE;
  64765. const char* fname = "./certs/ecc-key.der";
  64766. size_t sz = 0;
  64767. byte* buf = NULL;
  64768. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  64769. ExpectTrue(XFSEEK(file, 0, XSEEK_END) == 0);
  64770. ExpectTrue((sz = XFTELL(file)) != 0);
  64771. ExpectTrue(XFSEEK(file, 0, XSEEK_SET) == 0);
  64772. ExpectNotNull(buf = (byte*)XMALLOC(sz, HEAP_HINT, DYNAMIC_TYPE_FILE));
  64773. ExpectIntEQ(XFREAD(buf, 1, sz, file), sz);
  64774. if (file != XBADFILE)
  64775. XFCLOSE(file);
  64776. /* Test using BIO new mem and loading DER private key */
  64777. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  64778. ExpectNotNull((pkey = d2i_PrivateKey_bio(bio, NULL)));
  64779. XFREE(buf, HEAP_HINT, DYNAMIC_TYPE_FILE);
  64780. BIO_free(bio);
  64781. bio = NULL;
  64782. EVP_PKEY_free(pkey);
  64783. pkey = NULL;
  64784. }
  64785. #endif
  64786. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  64787. #ifndef NO_WOLFSSL_SERVER
  64788. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  64789. #else
  64790. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method()));
  64791. #endif
  64792. #if defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA)
  64793. {
  64794. RSA* rsa = NULL;
  64795. /* Tests bad parameters */
  64796. ExpectNull(d2i_RSAPrivateKey_bio(NULL, NULL));
  64797. /* RSA not set yet, expecting to fail*/
  64798. rsa = wolfSSL_RSA_new();
  64799. ExpectIntEQ(SSL_CTX_use_RSAPrivateKey(ctx, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  64800. wolfSSL_RSA_free(rsa);
  64801. rsa = NULL;
  64802. #if defined(USE_CERT_BUFFERS_2048) && defined(WOLFSSL_KEY_GEN)
  64803. /* set RSA using bio*/
  64804. ExpectIntGT(BIO_write(bio, client_key_der_2048,
  64805. sizeof_client_key_der_2048), 0);
  64806. ExpectNotNull(d2i_RSAPrivateKey_bio(bio, &rsa));
  64807. ExpectNotNull(rsa);
  64808. /* Tests bad parameters */
  64809. ExpectIntEQ(SSL_CTX_use_RSAPrivateKey(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  64810. ExpectIntEQ(SSL_CTX_use_RSAPrivateKey(ctx, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  64811. ExpectIntEQ(SSL_CTX_use_RSAPrivateKey(NULL, rsa), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  64812. ExpectIntEQ(SSL_CTX_use_RSAPrivateKey(ctx, rsa), WOLFSSL_SUCCESS);
  64813. /* i2d RSAprivate key tests */
  64814. ExpectIntEQ(wolfSSL_i2d_RSAPrivateKey(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  64815. ExpectIntEQ(wolfSSL_i2d_RSAPrivateKey(rsa, NULL), 1192);
  64816. ExpectIntEQ(wolfSSL_i2d_RSAPrivateKey(rsa, &bufPtr),
  64817. sizeof_client_key_der_2048);
  64818. bufPtr -= sizeof_client_key_der_2048;
  64819. ExpectIntEQ(XMEMCMP(bufPtr, client_key_der_2048,
  64820. sizeof_client_key_der_2048), 0);
  64821. bufPtr = NULL;
  64822. ExpectIntEQ(wolfSSL_i2d_RSAPrivateKey(rsa, &bufPtr),
  64823. sizeof_client_key_der_2048);
  64824. ExpectNotNull(bufPtr);
  64825. ExpectIntEQ(XMEMCMP(bufPtr, client_key_der_2048,
  64826. sizeof_client_key_der_2048), 0);
  64827. XFREE(bufPtr, NULL, DYNAMIC_TYPE_OPENSSL);
  64828. RSA_free(rsa);
  64829. rsa = NULL;
  64830. ExpectIntGT(BIO_write(bio, client_key_der_2048,
  64831. sizeof_client_key_der_2048), 0);
  64832. ExpectNotNull(d2i_RSA_PUBKEY_bio(bio, &rsa));
  64833. (void)BIO_reset(bio);
  64834. RSA_free(rsa);
  64835. rsa = RSA_new();
  64836. ExpectIntEQ(wolfSSL_i2d_RSAPrivateKey(rsa, NULL), 0);
  64837. #endif /* USE_CERT_BUFFERS_2048 WOLFSSL_KEY_GEN */
  64838. RSA_free(rsa);
  64839. }
  64840. #endif /* WOLFSSL_KEY_GEN && !NO_RSA */
  64841. SSL_CTX_free(ctx);
  64842. ctx = NULL;
  64843. BIO_free(bio);
  64844. bio = NULL;
  64845. return EXPECT_RESULT();
  64846. }
  64847. #endif /* OPENSSL_ALL || (WOLFSSL_ASIO && !NO_RSA) */
  64848. #endif /* !NO_BIO */
  64849. static int test_wolfSSL_sk_GENERAL_NAME(void)
  64850. {
  64851. EXPECT_DECLS;
  64852. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  64853. !defined(NO_RSA)
  64854. X509* x509 = NULL;
  64855. GENERAL_NAME* gn = NULL;
  64856. unsigned char buf[4096];
  64857. const unsigned char* bufPt = NULL;
  64858. int bytes = 0;
  64859. int i;
  64860. int j;
  64861. XFILE f = XBADFILE;
  64862. STACK_OF(GENERAL_NAME)* sk = NULL;
  64863. ExpectTrue((f = XFOPEN(cliCertDerFileExt, "rb")) != XBADFILE);
  64864. ExpectIntGT((bytes = (int)XFREAD(buf, 1, sizeof(buf), f)), 0);
  64865. if (f != XBADFILE)
  64866. XFCLOSE(f);
  64867. for (j = 0; j < 2; ++j) {
  64868. bufPt = buf;
  64869. ExpectNotNull(x509 = d2i_X509(NULL, &bufPt, bytes));
  64870. ExpectNotNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509,
  64871. NID_subject_alt_name, NULL, NULL));
  64872. ExpectIntEQ(sk_GENERAL_NAME_num(sk), 1);
  64873. for (i = 0; i < sk_GENERAL_NAME_num(sk); i++) {
  64874. ExpectNotNull(gn = sk_GENERAL_NAME_value(sk, i));
  64875. if (gn != NULL) {
  64876. switch (gn->type) {
  64877. case GEN_DNS:
  64878. fprintf(stderr, "found type GEN_DNS\n");
  64879. break;
  64880. case GEN_EMAIL:
  64881. fprintf(stderr, "found type GEN_EMAIL\n");
  64882. break;
  64883. case GEN_URI:
  64884. fprintf(stderr, "found type GEN_URI\n");
  64885. break;
  64886. }
  64887. }
  64888. }
  64889. X509_free(x509);
  64890. x509 = NULL;
  64891. if (j == 0) {
  64892. sk_GENERAL_NAME_pop_free(sk, GENERAL_NAME_free);
  64893. }
  64894. else {
  64895. /*
  64896. * We had a bug where GENERAL_NAMES_free didn't free all the memory
  64897. * it was supposed to. This is a regression test for that bug.
  64898. */
  64899. GENERAL_NAMES_free(sk);
  64900. }
  64901. sk = NULL;
  64902. }
  64903. #endif
  64904. return EXPECT_RESULT();
  64905. }
  64906. static int test_wolfSSL_GENERAL_NAME_print(void)
  64907. {
  64908. EXPECT_DECLS;
  64909. #if defined(OPENSSL_ALL) && !defined(NO_BIO) && !defined(NO_RSA)
  64910. X509* x509 = NULL;
  64911. GENERAL_NAME* gn = NULL;
  64912. unsigned char buf[4096];
  64913. const unsigned char* bufPt = NULL;
  64914. int bytes = 0;
  64915. XFILE f = XBADFILE;
  64916. STACK_OF(GENERAL_NAME)* sk = NULL;
  64917. BIO* out = NULL;
  64918. unsigned char outbuf[128];
  64919. X509_EXTENSION* ext = NULL;
  64920. AUTHORITY_INFO_ACCESS* aia = NULL;
  64921. ACCESS_DESCRIPTION* ad = NULL;
  64922. ASN1_IA5STRING *dnsname = NULL;
  64923. const unsigned char v4Addr[] = {192,168,53,1};
  64924. const unsigned char v6Addr[] =
  64925. {0x20, 0x21, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00,
  64926. 0x00, 0x00, 0xff, 0x00, 0x00, 0x42, 0x77, 0x77};
  64927. const unsigned char email[] =
  64928. {'i', 'n', 'f', 'o', '@', 'w', 'o', 'l',
  64929. 'f', 's', 's', 'l', '.', 'c', 'o', 'm'};
  64930. const char* dnsStr = "DNS:example.com";
  64931. const char* uriStr = "URI:http://127.0.0.1:22220";
  64932. const char* v4addStr = "IP Address:192.168.53.1";
  64933. const char* v6addStr = "IP Address:2021:DB8:0:0:0:FF00:42:7777";
  64934. const char* emailStr = "email:info@wolfssl.com";
  64935. const char* othrStr = "othername:<unsupported>";
  64936. const char* x400Str = "X400Name:<unsupported>";
  64937. const char* ediStr = "EdiPartyName:<unsupported>";
  64938. /* BIO to output */
  64939. ExpectNotNull(out = BIO_new(BIO_s_mem()));
  64940. /* test for NULL param */
  64941. gn = NULL;
  64942. ExpectIntEQ(GENERAL_NAME_print(NULL, NULL), 0);
  64943. ExpectIntEQ(GENERAL_NAME_print(NULL, gn), 0);
  64944. ExpectIntEQ(GENERAL_NAME_print(out, NULL), 0);
  64945. /* test for GEN_DNS */
  64946. ExpectTrue((f = XFOPEN(cliCertDerFileExt, "rb")) != XBADFILE);
  64947. ExpectIntGT((bytes = (int)XFREAD(buf, 1, sizeof(buf), f)), 0);
  64948. if (f != XBADFILE) {
  64949. XFCLOSE(f);
  64950. f = XBADFILE;
  64951. }
  64952. bufPt = buf;
  64953. ExpectNotNull(x509 = d2i_X509(NULL, &bufPt, bytes));
  64954. ExpectNotNull(sk = (STACK_OF(ASN1_OBJECT)*)X509_get_ext_d2i(x509,
  64955. NID_subject_alt_name, NULL, NULL));
  64956. ExpectNotNull(gn = sk_GENERAL_NAME_value(sk, 0));
  64957. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  64958. XMEMSET(outbuf, 0, sizeof(outbuf));
  64959. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  64960. ExpectIntEQ(XSTRNCMP((const char*)outbuf, dnsStr, XSTRLEN(dnsStr)), 0);
  64961. sk_GENERAL_NAME_pop_free(sk, GENERAL_NAME_free);
  64962. gn = NULL;
  64963. sk = NULL;
  64964. X509_free(x509);
  64965. x509 = NULL;
  64966. /* Lets test for setting as well. */
  64967. ExpectNotNull(gn = GENERAL_NAME_new());
  64968. ExpectNotNull(dnsname = ASN1_IA5STRING_new());
  64969. ExpectIntEQ(ASN1_STRING_set(dnsname, "example.com", -1), 1);
  64970. GENERAL_NAME_set0_value(gn, GEN_DNS, dnsname);
  64971. dnsname = NULL;
  64972. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  64973. XMEMSET(outbuf, 0, sizeof(outbuf));
  64974. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  64975. ExpectIntEQ(XSTRNCMP((const char*)outbuf, dnsStr, XSTRLEN(dnsStr)), 0);
  64976. GENERAL_NAME_free(gn);
  64977. /* test for GEN_URI */
  64978. ExpectTrue((f = XFOPEN("./certs/ocsp/root-ca-cert.pem", "rb")) != XBADFILE);
  64979. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  64980. if (f != XBADFILE) {
  64981. XFCLOSE(f);
  64982. f = XBADFILE;
  64983. }
  64984. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, 4));
  64985. ExpectNotNull(aia = (WOLFSSL_AUTHORITY_INFO_ACCESS*)wolfSSL_X509V3_EXT_d2i(
  64986. ext));
  64987. ExpectNotNull(ad = (WOLFSSL_ACCESS_DESCRIPTION *)wolfSSL_sk_value(aia, 0));
  64988. if (ad != NULL) {
  64989. gn = ad->location;
  64990. }
  64991. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  64992. gn = NULL;
  64993. XMEMSET(outbuf,0,sizeof(outbuf));
  64994. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  64995. ExpectIntEQ(XSTRNCMP((const char*)outbuf, uriStr, XSTRLEN(uriStr)), 0);
  64996. wolfSSL_sk_ACCESS_DESCRIPTION_pop_free(aia, NULL);
  64997. aia = NULL;
  64998. aia = (AUTHORITY_INFO_ACCESS*)wolfSSL_X509V3_EXT_d2i(ext);
  64999. ExpectNotNull(aia);
  65000. AUTHORITY_INFO_ACCESS_pop_free(aia, NULL);
  65001. aia = NULL;
  65002. X509_free(x509);
  65003. x509 = NULL;
  65004. /* test for GEN_IPADD */
  65005. /* ip v4 address */
  65006. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  65007. if (gn != NULL) {
  65008. gn->type = GEN_IPADD;
  65009. if (gn->d.iPAddress != NULL) {
  65010. gn->d.iPAddress->length = sizeof(v4Addr);
  65011. }
  65012. }
  65013. ExpectIntEQ(wolfSSL_ASN1_STRING_set(gn->d.iPAddress, v4Addr,
  65014. sizeof(v4Addr)), 1);
  65015. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  65016. XMEMSET(outbuf,0,sizeof(outbuf));
  65017. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  65018. ExpectIntEQ(XSTRNCMP((const char*)outbuf, v4addStr, XSTRLEN(v4addStr)), 0);
  65019. GENERAL_NAME_free(gn);
  65020. gn = NULL;
  65021. /* ip v6 address */
  65022. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  65023. if (gn != NULL) {
  65024. gn->type = GEN_IPADD;
  65025. if (gn->d.iPAddress != NULL) {
  65026. gn->d.iPAddress->length = sizeof(v6Addr);
  65027. }
  65028. }
  65029. ExpectIntEQ(wolfSSL_ASN1_STRING_set(gn->d.iPAddress, v6Addr,
  65030. sizeof(v6Addr)), 1);
  65031. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  65032. XMEMSET(outbuf,0,sizeof(outbuf));
  65033. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  65034. ExpectIntEQ(XSTRNCMP((const char*)outbuf, v6addStr, XSTRLEN(v6addStr)), 0);
  65035. GENERAL_NAME_free(gn);
  65036. gn = NULL;
  65037. /* test for GEN_EMAIL */
  65038. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  65039. if (gn != NULL) {
  65040. gn->type = GEN_EMAIL;
  65041. if (gn->d.rfc822Name != NULL) {
  65042. gn->d.rfc822Name->length = sizeof(email);
  65043. }
  65044. }
  65045. ExpectIntEQ(wolfSSL_ASN1_STRING_set(gn->d.rfc822Name, email, sizeof(email)),
  65046. 1);
  65047. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  65048. XMEMSET(outbuf,0,sizeof(outbuf));
  65049. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  65050. ExpectIntEQ(XSTRNCMP((const char*)outbuf, emailStr, XSTRLEN(emailStr)), 0);
  65051. GENERAL_NAME_free(gn);
  65052. gn = NULL;
  65053. /* test for GEN_OTHERNAME */
  65054. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  65055. if (gn != NULL) {
  65056. gn->type = GEN_OTHERNAME;
  65057. }
  65058. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  65059. XMEMSET(outbuf,0,sizeof(outbuf));
  65060. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  65061. ExpectIntEQ(XSTRNCMP((const char*)outbuf, othrStr, XSTRLEN(othrStr)), 0);
  65062. GENERAL_NAME_free(gn);
  65063. gn = NULL;
  65064. /* test for GEN_X400 */
  65065. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  65066. if (gn != NULL) {
  65067. gn->type = GEN_X400;
  65068. }
  65069. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  65070. XMEMSET(outbuf,0,sizeof(outbuf));
  65071. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  65072. ExpectIntEQ(XSTRNCMP((const char*)outbuf, x400Str, XSTRLEN(x400Str)), 0);
  65073. /* Restore to GEN_IA5 (default) to avoid memory leak. */
  65074. if (gn != NULL) {
  65075. gn->type = GEN_IA5;
  65076. }
  65077. GENERAL_NAME_free(gn);
  65078. gn = NULL;
  65079. /* test for GEN_EDIPARTY */
  65080. ExpectNotNull(gn = wolfSSL_GENERAL_NAME_new());
  65081. if (gn != NULL) {
  65082. gn->type = GEN_EDIPARTY;
  65083. }
  65084. ExpectIntEQ(GENERAL_NAME_print(out, gn), 1);
  65085. XMEMSET(outbuf,0,sizeof(outbuf));
  65086. ExpectIntGT(BIO_read(out, outbuf, sizeof(outbuf)), 0);
  65087. ExpectIntEQ(XSTRNCMP((const char*)outbuf, ediStr, XSTRLEN(ediStr)), 0);
  65088. /* Restore to GEN_IA5 (default) to avoid memory leak. */
  65089. if (gn != NULL) {
  65090. gn->type = GEN_IA5;
  65091. }
  65092. GENERAL_NAME_free(gn);
  65093. gn = NULL;
  65094. BIO_free(out);
  65095. #endif /* OPENSSL_ALL */
  65096. return EXPECT_RESULT();
  65097. }
  65098. static int test_wolfSSL_sk_DIST_POINT(void)
  65099. {
  65100. EXPECT_DECLS;
  65101. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
  65102. !defined(NO_RSA)
  65103. X509* x509 = NULL;
  65104. unsigned char buf[4096];
  65105. const unsigned char* bufPt;
  65106. int bytes = 0;
  65107. int i = 0;
  65108. int j = 0;
  65109. XFILE f = XBADFILE;
  65110. DIST_POINT* dp = NULL;
  65111. DIST_POINT_NAME* dpn = NULL;
  65112. GENERAL_NAME* gn = NULL;
  65113. ASN1_IA5STRING* uri = NULL;
  65114. STACK_OF(DIST_POINT)* dps = NULL;
  65115. STACK_OF(GENERAL_NAME)* gns = NULL;
  65116. const char cliCertDerCrlDistPoint[] = "./certs/client-crl-dist.der";
  65117. ExpectTrue((f = XFOPEN(cliCertDerCrlDistPoint, "rb")) != XBADFILE);
  65118. ExpectIntGT((bytes = (int)XFREAD(buf, 1, sizeof(buf), f)), 0);
  65119. if (f != XBADFILE)
  65120. XFCLOSE(f);
  65121. bufPt = buf;
  65122. ExpectNotNull(x509 = d2i_X509(NULL, &bufPt, bytes));
  65123. ExpectNotNull(dps = (STACK_OF(DIST_POINT)*)X509_get_ext_d2i(x509,
  65124. NID_crl_distribution_points, NULL, NULL));
  65125. ExpectIntEQ(sk_DIST_POINT_num(dps), 1);
  65126. for (i = 0; i < sk_DIST_POINT_num(dps); i++) {
  65127. ExpectNotNull(dp = sk_DIST_POINT_value(dps, i));
  65128. ExpectNotNull(dpn = dp->distpoint);
  65129. /* this should be type 0, fullname */
  65130. ExpectIntEQ(dpn->type, 0);
  65131. ExpectNotNull(gns = dp->distpoint->name.fullname);
  65132. ExpectIntEQ(sk_GENERAL_NAME_num(gns), 1);
  65133. for (j = 0; j < sk_GENERAL_NAME_num(gns); j++) {
  65134. ExpectNotNull(gn = sk_GENERAL_NAME_value(gns, j));
  65135. ExpectIntEQ(gn->type, GEN_URI);
  65136. ExpectNotNull(uri = gn->d.uniformResourceIdentifier);
  65137. ExpectNotNull(uri->data);
  65138. ExpectIntGT(uri->length, 0);
  65139. }
  65140. }
  65141. X509_free(x509);
  65142. CRL_DIST_POINTS_free(dps);
  65143. #endif
  65144. return EXPECT_RESULT();
  65145. }
  65146. static int test_wolfSSL_verify_mode(void)
  65147. {
  65148. EXPECT_DECLS;
  65149. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  65150. WOLFSSL* ssl = NULL;
  65151. WOLFSSL_CTX* ctx = NULL;
  65152. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  65153. ExpectNotNull(ssl = SSL_new(ctx));
  65154. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_CTX_get_verify_mode(ctx));
  65155. SSL_free(ssl);
  65156. ssl = NULL;
  65157. SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, 0);
  65158. ExpectNotNull(ssl = SSL_new(ctx));
  65159. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_CTX_get_verify_mode(ctx));
  65160. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_PEER);
  65161. wolfSSL_set_verify(ssl, SSL_VERIFY_NONE, 0);
  65162. ExpectIntEQ(SSL_CTX_get_verify_mode(ctx), SSL_VERIFY_PEER);
  65163. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_NONE);
  65164. SSL_free(ssl);
  65165. ssl = NULL;
  65166. wolfSSL_CTX_set_verify(ctx,
  65167. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  65168. ExpectNotNull(ssl = SSL_new(ctx));
  65169. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_CTX_get_verify_mode(ctx));
  65170. ExpectIntEQ(SSL_get_verify_mode(ssl),
  65171. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT);
  65172. wolfSSL_set_verify(ssl, SSL_VERIFY_PEER, 0);
  65173. ExpectIntEQ(SSL_CTX_get_verify_mode(ctx),
  65174. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT);
  65175. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_PEER);
  65176. wolfSSL_set_verify(ssl, SSL_VERIFY_NONE, 0);
  65177. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_NONE);
  65178. wolfSSL_set_verify(ssl, SSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  65179. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_FAIL_IF_NO_PEER_CERT);
  65180. wolfSSL_set_verify(ssl, SSL_VERIFY_FAIL_EXCEPT_PSK, 0);
  65181. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_FAIL_EXCEPT_PSK);
  65182. #if defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
  65183. wolfSSL_set_verify(ssl, SSL_VERIFY_POST_HANDSHAKE, 0);
  65184. ExpectIntEQ(SSL_get_verify_mode(ssl), SSL_VERIFY_POST_HANDSHAKE);
  65185. #endif
  65186. ExpectIntEQ(SSL_CTX_get_verify_mode(ctx),
  65187. WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT);
  65188. SSL_free(ssl);
  65189. SSL_CTX_free(ctx);
  65190. #endif
  65191. return EXPECT_RESULT();
  65192. }
  65193. static int test_wolfSSL_verify_depth(void)
  65194. {
  65195. EXPECT_DECLS;
  65196. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_WOLFSSL_CLIENT)
  65197. WOLFSSL* ssl = NULL;
  65198. WOLFSSL_CTX* ctx = NULL;
  65199. long depth = 0;
  65200. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  65201. ExpectIntGT((depth = SSL_CTX_get_verify_depth(ctx)), 0);
  65202. ExpectNotNull(ssl = SSL_new(ctx));
  65203. ExpectIntEQ(SSL_get_verify_depth(ssl), SSL_CTX_get_verify_depth(ctx));
  65204. SSL_free(ssl);
  65205. ssl = NULL;
  65206. SSL_CTX_set_verify_depth(ctx, -1);
  65207. ExpectIntEQ(depth, SSL_CTX_get_verify_depth(ctx));
  65208. SSL_CTX_set_verify_depth(ctx, 2);
  65209. ExpectIntEQ(2, SSL_CTX_get_verify_depth(ctx));
  65210. ExpectNotNull(ssl = SSL_new(ctx));
  65211. ExpectIntEQ(2, SSL_get_verify_depth(ssl));
  65212. SSL_free(ssl);
  65213. SSL_CTX_free(ctx);
  65214. #endif
  65215. return EXPECT_RESULT();
  65216. }
  65217. static int test_wolfSSL_verify_result(void)
  65218. {
  65219. EXPECT_DECLS;
  65220. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
  65221. defined(OPENSSL_ALL)) && !defined(NO_WOLFSSL_CLIENT)
  65222. WOLFSSL* ssl = NULL;
  65223. WOLFSSL_CTX* ctx = NULL;
  65224. long result = 0xDEADBEEF;
  65225. ExpectIntEQ(WC_NO_ERR_TRACE(WOLFSSL_FAILURE), wolfSSL_get_verify_result(ssl));
  65226. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  65227. ExpectNotNull(ssl = SSL_new(ctx));
  65228. wolfSSL_set_verify_result(ssl, result);
  65229. ExpectIntEQ(result, wolfSSL_get_verify_result(ssl));
  65230. SSL_free(ssl);
  65231. SSL_CTX_free(ctx);
  65232. #endif
  65233. return EXPECT_RESULT();
  65234. }
  65235. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_WOLFSSL_CLIENT)
  65236. static void sslMsgCb(int w, int version, int type, const void* buf,
  65237. size_t sz, SSL* ssl, void* arg)
  65238. {
  65239. int i;
  65240. unsigned char* pt = (unsigned char*)buf;
  65241. fprintf(stderr, "%s %d bytes of version %d , type %d : ",
  65242. (w)?"Writing":"Reading", (int)sz, version, type);
  65243. for (i = 0; i < (int)sz; i++) fprintf(stderr, "%02X", pt[i]);
  65244. fprintf(stderr, "\n");
  65245. (void)ssl;
  65246. (void)arg;
  65247. }
  65248. #endif /* OPENSSL_EXTRA */
  65249. static int test_wolfSSL_msg_callback(void)
  65250. {
  65251. EXPECT_DECLS;
  65252. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_WOLFSSL_CLIENT)
  65253. WOLFSSL* ssl = NULL;
  65254. WOLFSSL_CTX* ctx = NULL;
  65255. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  65256. ExpectNotNull(ssl = SSL_new(ctx));
  65257. ExpectIntEQ(SSL_set_msg_callback(ssl, NULL), SSL_SUCCESS);
  65258. ExpectIntEQ(SSL_set_msg_callback(ssl, &sslMsgCb), SSL_SUCCESS);
  65259. ExpectIntEQ(SSL_set_msg_callback(NULL, &sslMsgCb), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  65260. SSL_free(ssl);
  65261. SSL_CTX_free(ctx);
  65262. #endif
  65263. return EXPECT_RESULT();
  65264. }
  65265. /* test_EVP_Cipher_extra, Extra-test on EVP_CipherUpdate/Final. see also test.c */
  65266. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) &&\
  65267. (!defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128))
  65268. static void binary_dump(void *ptr, int size)
  65269. {
  65270. #ifdef WOLFSSL_EVP_PRINT
  65271. int i = 0;
  65272. unsigned char *p = (unsigned char *) ptr;
  65273. fprintf(stderr, "{");
  65274. while ((p != NULL) && (i < size)) {
  65275. if ((i % 8) == 0) {
  65276. fprintf(stderr, "\n");
  65277. fprintf(stderr, " ");
  65278. }
  65279. fprintf(stderr, "0x%02x, ", p[i]);
  65280. i++;
  65281. }
  65282. fprintf(stderr, "\n};\n");
  65283. #else
  65284. (void) ptr;
  65285. (void) size;
  65286. #endif
  65287. }
  65288. static int last_val = 0x0f;
  65289. static int check_result(unsigned char *data, int len)
  65290. {
  65291. int i;
  65292. for ( ; len; ) {
  65293. last_val = (last_val + 1) % 16;
  65294. for (i = 0; i < 16; len--, i++, data++)
  65295. if (*data != last_val) {
  65296. return -1;
  65297. }
  65298. }
  65299. return 0;
  65300. }
  65301. static int r_offset;
  65302. static int w_offset;
  65303. static void init_offset(void)
  65304. {
  65305. r_offset = 0;
  65306. w_offset = 0;
  65307. }
  65308. static void get_record(unsigned char *data, unsigned char *buf, int len)
  65309. {
  65310. XMEMCPY(buf, data+r_offset, len);
  65311. r_offset += len;
  65312. }
  65313. static void set_record(unsigned char *data, unsigned char *buf, int len)
  65314. {
  65315. XMEMCPY(data+w_offset, buf, len);
  65316. w_offset += len;
  65317. }
  65318. static void set_plain(unsigned char *plain, int rec)
  65319. {
  65320. int i, j;
  65321. unsigned char *p = plain;
  65322. #define BLOCKSZ 16
  65323. for (i=0; i<(rec/BLOCKSZ); i++) {
  65324. for (j=0; j<BLOCKSZ; j++)
  65325. *p++ = (i % 16);
  65326. }
  65327. }
  65328. #endif
  65329. static int test_wolfSSL_EVP_Cipher_extra(void)
  65330. {
  65331. EXPECT_DECLS;
  65332. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) &&\
  65333. (!defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128))
  65334. /* aes128-cbc, keylen=16, ivlen=16 */
  65335. byte aes128_cbc_key[] = {
  65336. 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef,
  65337. 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef,
  65338. };
  65339. byte aes128_cbc_iv[] = {
  65340. 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
  65341. 0x99, 0x00, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
  65342. };
  65343. /* teset data size table */
  65344. int test_drive1[] = {8, 3, 5, 512, 8, 3, 8, 512, 0};
  65345. int test_drive2[] = {8, 3, 8, 512, 0};
  65346. int test_drive3[] = {512, 512, 504, 512, 512, 8, 512, 0};
  65347. int *test_drive[] = {test_drive1, test_drive2, test_drive3, NULL};
  65348. int test_drive_len[100];
  65349. int ret = 0;
  65350. EVP_CIPHER_CTX *evp = NULL;
  65351. int ilen = 0;
  65352. int klen = 0;
  65353. int i, j;
  65354. const EVP_CIPHER *type;
  65355. byte *iv;
  65356. byte *key;
  65357. int ivlen;
  65358. int keylen;
  65359. #define RECORDS 16
  65360. #define BUFFSZ 512
  65361. byte plain [BUFFSZ * RECORDS];
  65362. byte cipher[BUFFSZ * RECORDS];
  65363. byte inb[BUFFSZ];
  65364. byte outb[BUFFSZ+16];
  65365. int outl = 0;
  65366. int inl;
  65367. iv = aes128_cbc_iv;
  65368. ivlen = sizeof(aes128_cbc_iv);
  65369. key = aes128_cbc_key;
  65370. keylen = sizeof(aes128_cbc_key);
  65371. type = EVP_aes_128_cbc();
  65372. set_plain(plain, BUFFSZ * RECORDS);
  65373. SSL_library_init();
  65374. ExpectNotNull(evp = EVP_CIPHER_CTX_new());
  65375. ExpectIntNE((ret = EVP_CipherInit(evp, type, NULL, iv, 0)), 0);
  65376. ExpectIntEQ(EVP_CIPHER_CTX_nid(evp), NID_aes_128_cbc);
  65377. klen = EVP_CIPHER_CTX_key_length(evp);
  65378. if (klen > 0 && keylen != klen) {
  65379. ExpectIntNE(EVP_CIPHER_CTX_set_key_length(evp, keylen), 0);
  65380. }
  65381. ilen = EVP_CIPHER_CTX_iv_length(evp);
  65382. if (ilen > 0 && ivlen != ilen) {
  65383. ExpectIntNE(EVP_CIPHER_CTX_set_iv_length(evp, ivlen), 0);
  65384. }
  65385. ExpectIntNE((ret = EVP_CipherInit(evp, NULL, key, iv, 1)), 0);
  65386. for (j = 0; j<RECORDS; j++)
  65387. {
  65388. inl = BUFFSZ;
  65389. get_record(plain, inb, inl);
  65390. ExpectIntNE((ret = EVP_CipherUpdate(evp, outb, &outl, inb, inl)), 0);
  65391. set_record(cipher, outb, outl);
  65392. }
  65393. for (i = 0; test_drive[i]; i++) {
  65394. ExpectIntNE((ret = EVP_CipherInit(evp, NULL, key, iv, 1)), 0);
  65395. init_offset();
  65396. test_drive_len[i] = 0;
  65397. for (j = 0; test_drive[i][j]; j++)
  65398. {
  65399. inl = test_drive[i][j];
  65400. test_drive_len[i] += inl;
  65401. get_record(plain, inb, inl);
  65402. ExpectIntNE((ret = EVP_EncryptUpdate(evp, outb, &outl, inb, inl)),
  65403. 0);
  65404. /* output to cipher buffer, so that following Dec test can detect
  65405. if any error */
  65406. set_record(cipher, outb, outl);
  65407. }
  65408. EVP_CipherFinal(evp, outb, &outl);
  65409. if (outl > 0)
  65410. set_record(cipher, outb, outl);
  65411. }
  65412. for (i = 0; test_drive[i]; i++) {
  65413. last_val = 0x0f;
  65414. ExpectIntNE((ret = EVP_CipherInit(evp, NULL, key, iv, 0)), 0);
  65415. init_offset();
  65416. for (j = 0; test_drive[i][j]; j++) {
  65417. inl = test_drive[i][j];
  65418. get_record(cipher, inb, inl);
  65419. ExpectIntNE((ret = EVP_DecryptUpdate(evp, outb, &outl, inb, inl)),
  65420. 0);
  65421. binary_dump(outb, outl);
  65422. ExpectIntEQ((ret = check_result(outb, outl)), 0);
  65423. ExpectFalse(outl > ((inl/16+1)*16) && outl > 16);
  65424. }
  65425. ret = EVP_CipherFinal(evp, outb, &outl);
  65426. binary_dump(outb, outl);
  65427. ret = (((test_drive_len[i] % 16) != 0) && (ret == 0)) ||
  65428. (((test_drive_len[i] % 16) == 0) && (ret == 1));
  65429. ExpectTrue(ret);
  65430. }
  65431. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(evp), WOLFSSL_SUCCESS);
  65432. EVP_CIPHER_CTX_free(evp);
  65433. evp = NULL;
  65434. /* Do an extra test to verify correct behavior with empty input. */
  65435. ExpectNotNull(evp = EVP_CIPHER_CTX_new());
  65436. ExpectIntNE((ret = EVP_CipherInit(evp, type, NULL, iv, 0)), 0);
  65437. ExpectIntEQ(EVP_CIPHER_CTX_nid(evp), NID_aes_128_cbc);
  65438. klen = EVP_CIPHER_CTX_key_length(evp);
  65439. if (klen > 0 && keylen != klen) {
  65440. ExpectIntNE(EVP_CIPHER_CTX_set_key_length(evp, keylen), 0);
  65441. }
  65442. ilen = EVP_CIPHER_CTX_iv_length(evp);
  65443. if (ilen > 0 && ivlen != ilen) {
  65444. ExpectIntNE(EVP_CIPHER_CTX_set_iv_length(evp, ivlen), 0);
  65445. }
  65446. ExpectIntNE((ret = EVP_CipherInit(evp, NULL, key, iv, 1)), 0);
  65447. /* outl should be set to 0 after passing NULL, 0 for input args. */
  65448. outl = -1;
  65449. ExpectIntNE((ret = EVP_CipherUpdate(evp, outb, &outl, NULL, 0)), 0);
  65450. ExpectIntEQ(outl, 0);
  65451. EVP_CIPHER_CTX_free(evp);
  65452. #endif /* test_EVP_Cipher */
  65453. return EXPECT_RESULT();
  65454. }
  65455. static int test_wolfSSL_PEM_read_DHparams(void)
  65456. {
  65457. EXPECT_DECLS;
  65458. #if defined(OPENSSL_ALL) && !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA) && \
  65459. !defined(NO_FILESYSTEM)
  65460. DH* dh = NULL;
  65461. XFILE fp = XBADFILE;
  65462. unsigned char derOut[300];
  65463. unsigned char* derOutBuf = derOut;
  65464. int derOutSz = 0;
  65465. unsigned char derExpected[300];
  65466. int derExpectedSz = 0;
  65467. XMEMSET(derOut, 0, sizeof(derOut));
  65468. XMEMSET(derExpected, 0, sizeof(derExpected));
  65469. /* open DH param file, read into DH struct */
  65470. ExpectTrue((fp = XFOPEN(dhParamFile, "rb")) != XBADFILE);
  65471. /* bad args */
  65472. ExpectNull(dh = PEM_read_DHparams(NULL, &dh, NULL, NULL));
  65473. ExpectNull(dh = PEM_read_DHparams(NULL, NULL, NULL, NULL));
  65474. /* good args */
  65475. ExpectNotNull(dh = PEM_read_DHparams(fp, &dh, NULL, NULL));
  65476. if (fp != XBADFILE) {
  65477. XFCLOSE(fp);
  65478. fp = XBADFILE;
  65479. }
  65480. /* read in certs/dh2048.der for comparison against exported params */
  65481. ExpectTrue((fp = XFOPEN("./certs/dh2048.der", "rb")) != XBADFILE);
  65482. ExpectIntGT(derExpectedSz = (int)XFREAD(derExpected, 1, sizeof(derExpected),
  65483. fp), 0);
  65484. if (fp != XBADFILE) {
  65485. XFCLOSE(fp);
  65486. fp = XBADFILE;
  65487. }
  65488. /* export DH back to DER and compare */
  65489. derOutSz = wolfSSL_i2d_DHparams(dh, &derOutBuf);
  65490. ExpectIntEQ(derOutSz, derExpectedSz);
  65491. ExpectIntEQ(XMEMCMP(derOut, derExpected, derOutSz), 0);
  65492. DH_free(dh);
  65493. dh = NULL;
  65494. /* Test parsing with X9.42 header */
  65495. ExpectTrue((fp = XFOPEN("./certs/x942dh2048.pem", "rb")) != XBADFILE);
  65496. ExpectNotNull(dh = PEM_read_DHparams(fp, &dh, NULL, NULL));
  65497. if (fp != XBADFILE)
  65498. XFCLOSE(fp);
  65499. DH_free(dh);
  65500. dh = NULL;
  65501. #endif
  65502. return EXPECT_RESULT();
  65503. }
  65504. static int test_wolfSSL_X509_get_serialNumber(void)
  65505. {
  65506. EXPECT_DECLS;
  65507. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
  65508. ASN1_INTEGER* a = NULL;
  65509. BIGNUM* bn = NULL;
  65510. X509* x509 = NULL;
  65511. char *serialHex = NULL;
  65512. byte serial[3];
  65513. int serialSz;
  65514. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  65515. SSL_FILETYPE_PEM));
  65516. ExpectNotNull(a = X509_get_serialNumber(x509));
  65517. /* check on value of ASN1 Integer */
  65518. ExpectNotNull(bn = ASN1_INTEGER_to_BN(a, NULL));
  65519. a = NULL;
  65520. /* test setting serial number and then retrieving it */
  65521. ExpectNotNull(a = ASN1_INTEGER_new());
  65522. ExpectIntEQ(ASN1_INTEGER_set(a, 3), 1);
  65523. ExpectIntEQ(X509_set_serialNumber(x509, a), WOLFSSL_SUCCESS);
  65524. serialSz = sizeof(serial);
  65525. ExpectIntEQ(wolfSSL_X509_get_serial_number(x509, serial, &serialSz),
  65526. WOLFSSL_SUCCESS);
  65527. ExpectIntEQ(serialSz, 1);
  65528. ExpectIntEQ(serial[0], 3);
  65529. ASN1_INTEGER_free(a);
  65530. a = NULL;
  65531. /* test setting serial number with 0's in it */
  65532. serial[0] = 0x01;
  65533. serial[1] = 0x00;
  65534. serial[2] = 0x02;
  65535. ExpectNotNull(a = wolfSSL_ASN1_INTEGER_new());
  65536. if (a != NULL) {
  65537. a->data[0] = ASN_INTEGER;
  65538. a->data[1] = sizeof(serial);
  65539. XMEMCPY(&a->data[2], serial, sizeof(serial));
  65540. a->length = sizeof(serial) + 2;
  65541. }
  65542. ExpectIntEQ(X509_set_serialNumber(x509, a), WOLFSSL_SUCCESS);
  65543. XMEMSET(serial, 0, sizeof(serial));
  65544. serialSz = sizeof(serial);
  65545. ExpectIntEQ(wolfSSL_X509_get_serial_number(x509, serial, &serialSz),
  65546. WOLFSSL_SUCCESS);
  65547. ExpectIntEQ(serialSz, 3);
  65548. ExpectIntEQ(serial[0], 0x01);
  65549. ExpectIntEQ(serial[1], 0x00);
  65550. ExpectIntEQ(serial[2], 0x02);
  65551. ASN1_INTEGER_free(a);
  65552. a = NULL;
  65553. X509_free(x509); /* free's a */
  65554. ExpectNotNull(serialHex = BN_bn2hex(bn));
  65555. #ifndef WC_DISABLE_RADIX_ZERO_PAD
  65556. ExpectStrEQ(serialHex, "01");
  65557. #else
  65558. ExpectStrEQ(serialHex, "1");
  65559. #endif
  65560. OPENSSL_free(serialHex);
  65561. ExpectIntEQ(BN_get_word(bn), 1);
  65562. BN_free(bn);
  65563. /* hard test free'ing with dynamic buffer to make sure there is no leaks */
  65564. ExpectNotNull(a = ASN1_INTEGER_new());
  65565. if (a != NULL) {
  65566. ExpectNotNull(a->data = (unsigned char*)XMALLOC(100, NULL,
  65567. DYNAMIC_TYPE_OPENSSL));
  65568. a->isDynamic = 1;
  65569. ASN1_INTEGER_free(a);
  65570. }
  65571. #endif
  65572. return EXPECT_RESULT();
  65573. }
  65574. static int test_wolfSSL_OpenSSL_add_all_algorithms(void)
  65575. {
  65576. EXPECT_DECLS;
  65577. #if defined(OPENSSL_EXTRA)
  65578. ExpectIntEQ(wolfSSL_add_all_algorithms(), WOLFSSL_SUCCESS);
  65579. ExpectIntEQ(wolfSSL_OpenSSL_add_all_algorithms_noconf(), WOLFSSL_SUCCESS);
  65580. ExpectIntEQ(wolfSSL_OpenSSL_add_all_algorithms_conf(), WOLFSSL_SUCCESS);
  65581. #endif
  65582. return EXPECT_RESULT();
  65583. }
  65584. static int test_wolfSSL_OPENSSL_hexstr2buf(void)
  65585. {
  65586. EXPECT_DECLS;
  65587. #if defined(OPENSSL_EXTRA)
  65588. #define MAX_HEXSTR_BUFSZ 9
  65589. #define NUM_CASES 5
  65590. struct Output {
  65591. const unsigned char buffer[MAX_HEXSTR_BUFSZ];
  65592. long ret;
  65593. };
  65594. int i;
  65595. int j;
  65596. const char* inputs[NUM_CASES] = {
  65597. "aabcd1357e",
  65598. "01:12:23:34:a5:b6:c7:d8:e9",
  65599. ":01:02",
  65600. "012",
  65601. ":ab:ac:d"
  65602. };
  65603. struct Output expectedOutputs[NUM_CASES] = {
  65604. {{0xaa, 0xbc, 0xd1, 0x35, 0x7e}, 5},
  65605. {{0x01, 0x12, 0x23, 0x34, 0xa5, 0xb6, 0xc7, 0xd8, 0xe9}, 9},
  65606. {{0x01, 0x02}, 2},
  65607. {{0x00}, 0},
  65608. {{0x00}, 0}
  65609. };
  65610. long len = 0;
  65611. unsigned char* returnedBuf = NULL;
  65612. for (i = 0; i < NUM_CASES && !EXPECT_FAIL(); ++i) {
  65613. returnedBuf = wolfSSL_OPENSSL_hexstr2buf(inputs[i], &len);
  65614. if (returnedBuf == NULL) {
  65615. ExpectIntEQ(expectedOutputs[i].ret, 0);
  65616. continue;
  65617. }
  65618. ExpectIntEQ(expectedOutputs[i].ret, len);
  65619. for (j = 0; j < len; ++j) {
  65620. ExpectIntEQ(expectedOutputs[i].buffer[j], returnedBuf[j]);
  65621. }
  65622. OPENSSL_free(returnedBuf);
  65623. returnedBuf = NULL;
  65624. }
  65625. #endif
  65626. return EXPECT_RESULT();
  65627. }
  65628. static int test_wolfSSL_X509_CA_num(void)
  65629. {
  65630. EXPECT_DECLS;
  65631. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_FILESYSTEM) && \
  65632. defined(HAVE_ECC) && !defined(NO_RSA)
  65633. WOLFSSL_X509_STORE *store = NULL;
  65634. WOLFSSL_X509 *x509_1 = NULL;
  65635. WOLFSSL_X509 *x509_2 = NULL;
  65636. int ca_num = 0;
  65637. ExpectNotNull(store = wolfSSL_X509_STORE_new());
  65638. ExpectNotNull(x509_1 = wolfSSL_X509_load_certificate_file(svrCertFile,
  65639. WOLFSSL_FILETYPE_PEM));
  65640. ExpectIntEQ(wolfSSL_X509_STORE_add_cert(store, x509_1), 1);
  65641. ExpectIntEQ(ca_num = wolfSSL_X509_CA_num(store), 1);
  65642. ExpectNotNull(x509_2 = wolfSSL_X509_load_certificate_file(eccCertFile,
  65643. WOLFSSL_FILETYPE_PEM));
  65644. ExpectIntEQ(wolfSSL_X509_STORE_add_cert(store, x509_2), 1);
  65645. ExpectIntEQ(ca_num = wolfSSL_X509_CA_num(store), 2);
  65646. wolfSSL_X509_free(x509_1);
  65647. wolfSSL_X509_free(x509_2);
  65648. wolfSSL_X509_STORE_free(store);
  65649. #endif
  65650. return EXPECT_RESULT();
  65651. }
  65652. static int test_wolfSSL_X509_check_ca(void)
  65653. {
  65654. EXPECT_DECLS;
  65655. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  65656. WOLFSSL_X509 *x509 = NULL;
  65657. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  65658. WOLFSSL_FILETYPE_PEM));
  65659. ExpectIntEQ(wolfSSL_X509_check_ca(x509), 1);
  65660. wolfSSL_X509_free(x509);
  65661. #endif
  65662. return EXPECT_RESULT();
  65663. }
  65664. static int test_wolfSSL_X509_check_ip_asc(void)
  65665. {
  65666. EXPECT_DECLS;
  65667. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  65668. WOLFSSL_X509 *x509 = NULL;
  65669. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  65670. WOLFSSL_FILETYPE_PEM));
  65671. #if 0
  65672. /* TODO: add cert gen for testing positive case */
  65673. ExpectIntEQ(wolfSSL_X509_check_ip_asc(x509, "127.0.0.1", 0), 1);
  65674. #endif
  65675. ExpectIntEQ(wolfSSL_X509_check_ip_asc(x509, "0.0.0.0", 0), 0);
  65676. ExpectIntEQ(wolfSSL_X509_check_ip_asc(x509, NULL, 0), 0);
  65677. wolfSSL_X509_free(x509);
  65678. #endif
  65679. return EXPECT_RESULT();
  65680. }
  65681. static int test_wolfSSL_make_cert(void)
  65682. {
  65683. EXPECT_DECLS;
  65684. #if !defined(NO_RSA) && !defined(NO_ASN_TIME) && defined(WOLFSSL_CERT_GEN) && \
  65685. defined(WOLFSSL_CERT_EXT)
  65686. int ret = 0;
  65687. Cert cert;
  65688. CertName name;
  65689. RsaKey key;
  65690. WC_RNG rng;
  65691. byte der[FOURK_BUF];
  65692. word32 idx = 0;
  65693. const byte mySerial[8] = {1,2,3,4,5,6,7,8};
  65694. #ifdef OPENSSL_EXTRA
  65695. const unsigned char* pt = NULL;
  65696. int certSz = 0;
  65697. X509* x509 = NULL;
  65698. X509_NAME* x509name = NULL;
  65699. X509_NAME_ENTRY* entry = NULL;
  65700. ASN1_STRING* entryValue = NULL;
  65701. #endif
  65702. XMEMSET(&name, 0, sizeof(CertName));
  65703. /* set up cert name */
  65704. XMEMCPY(name.country, "US", sizeof("US"));
  65705. name.countryEnc = CTC_PRINTABLE;
  65706. XMEMCPY(name.state, "Oregon", sizeof("Oregon"));
  65707. name.stateEnc = CTC_UTF8;
  65708. XMEMCPY(name.locality, "Portland", sizeof("Portland"));
  65709. name.localityEnc = CTC_UTF8;
  65710. XMEMCPY(name.sur, "Test", sizeof("Test"));
  65711. name.surEnc = CTC_UTF8;
  65712. XMEMCPY(name.org, "wolfSSL", sizeof("wolfSSL"));
  65713. name.orgEnc = CTC_UTF8;
  65714. XMEMCPY(name.unit, "Development", sizeof("Development"));
  65715. name.unitEnc = CTC_UTF8;
  65716. XMEMCPY(name.commonName, "www.wolfssl.com", sizeof("www.wolfssl.com"));
  65717. name.commonNameEnc = CTC_UTF8;
  65718. XMEMCPY(name.serialDev, "wolfSSL12345", sizeof("wolfSSL12345"));
  65719. name.serialDevEnc = CTC_PRINTABLE;
  65720. XMEMCPY(name.userId, "TestUserID", sizeof("TestUserID"));
  65721. name.userIdEnc = CTC_PRINTABLE;
  65722. #ifdef WOLFSSL_MULTI_ATTRIB
  65723. #if CTC_MAX_ATTRIB > 2
  65724. {
  65725. NameAttrib* n;
  65726. n = &name.name[0];
  65727. n->id = ASN_DOMAIN_COMPONENT;
  65728. n->type = CTC_UTF8;
  65729. n->sz = sizeof("com");
  65730. XMEMCPY(n->value, "com", sizeof("com"));
  65731. n = &name.name[1];
  65732. n->id = ASN_DOMAIN_COMPONENT;
  65733. n->type = CTC_UTF8;
  65734. n->sz = sizeof("wolfssl");
  65735. XMEMCPY(n->value, "wolfssl", sizeof("wolfssl"));
  65736. }
  65737. #endif
  65738. #endif /* WOLFSSL_MULTI_ATTRIB */
  65739. ExpectIntEQ(wc_InitRsaKey(&key, HEAP_HINT), 0);
  65740. #ifndef HAVE_FIPS
  65741. ExpectIntEQ(wc_InitRng_ex(&rng, HEAP_HINT, testDevId), 0);
  65742. #else
  65743. ExpectIntEQ(wc_InitRng(&rng), 0);
  65744. #endif
  65745. /* load test RSA key */
  65746. idx = 0;
  65747. #if defined(USE_CERT_BUFFERS_1024)
  65748. ExpectIntEQ(wc_RsaPrivateKeyDecode(server_key_der_1024, &idx, &key,
  65749. sizeof_server_key_der_1024), 0);
  65750. #elif defined(USE_CERT_BUFFERS_2048)
  65751. ExpectIntEQ(wc_RsaPrivateKeyDecode(server_key_der_2048, &idx, &key,
  65752. sizeof_server_key_der_2048), 0);
  65753. #else
  65754. /* error case, no RSA key loaded, happens later */
  65755. (void)idx;
  65756. #endif
  65757. XMEMSET(&cert, 0 , sizeof(Cert));
  65758. ExpectIntEQ(wc_InitCert(&cert), 0);
  65759. XMEMCPY(&cert.subject, &name, sizeof(CertName));
  65760. XMEMCPY(cert.serial, mySerial, sizeof(mySerial));
  65761. cert.serialSz = (int)sizeof(mySerial);
  65762. cert.isCA = 1;
  65763. #ifndef NO_SHA256
  65764. cert.sigType = CTC_SHA256wRSA;
  65765. #else
  65766. cert.sigType = CTC_SHAwRSA;
  65767. #endif
  65768. /* add SKID from the Public Key */
  65769. ExpectIntEQ(wc_SetSubjectKeyIdFromPublicKey(&cert, &key, NULL), 0);
  65770. /* add AKID from the Public Key */
  65771. ExpectIntEQ(wc_SetAuthKeyIdFromPublicKey(&cert, &key, NULL), 0);
  65772. ret = 0;
  65773. do {
  65774. #if defined(WOLFSSL_ASYNC_CRYPT)
  65775. ret = wc_AsyncWait(ret, &key.asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  65776. #endif
  65777. if (ret >= 0) {
  65778. ret = wc_MakeSelfCert(&cert, der, FOURK_BUF, &key, &rng);
  65779. }
  65780. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  65781. ExpectIntGT(ret, 0);
  65782. #ifdef OPENSSL_EXTRA
  65783. /* der holds a certificate with DC's now check X509 parsing of it */
  65784. certSz = ret;
  65785. pt = der;
  65786. ExpectNotNull(x509 = d2i_X509(NULL, &pt, certSz));
  65787. ExpectNotNull(x509name = X509_get_subject_name(x509));
  65788. #ifdef WOLFSSL_MULTI_ATTRIB
  65789. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_domainComponent,
  65790. -1)), 5);
  65791. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_domainComponent,
  65792. (int)idx)), 6);
  65793. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_domainComponent,
  65794. (int)idx)), -1);
  65795. #endif /* WOLFSSL_MULTI_ATTRIB */
  65796. /* compare DN at index 0 */
  65797. ExpectNotNull(entry = X509_NAME_get_entry(x509name, 0));
  65798. ExpectNotNull(entryValue = X509_NAME_ENTRY_get_data(entry));
  65799. ExpectIntEQ(ASN1_STRING_length(entryValue), 2);
  65800. ExpectStrEQ((const char*)ASN1_STRING_data(entryValue), "US");
  65801. #ifndef WOLFSSL_MULTI_ATTRIB
  65802. /* compare Serial Number */
  65803. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_serialNumber,
  65804. -1)), 7);
  65805. ExpectNotNull(entry = X509_NAME_get_entry(x509name, idx));
  65806. ExpectNotNull(entryValue = X509_NAME_ENTRY_get_data(entry));
  65807. ExpectIntEQ(ASN1_STRING_length(entryValue), XSTRLEN("wolfSSL12345"));
  65808. ExpectStrEQ((const char*)ASN1_STRING_data(entryValue), "wolfSSL12345");
  65809. #endif
  65810. #ifdef WOLFSSL_MULTI_ATTRIB
  65811. /* get first and second DC and compare result */
  65812. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_domainComponent,
  65813. -1)), 5);
  65814. ExpectNotNull(entry = X509_NAME_get_entry(x509name, (int)idx));
  65815. ExpectNotNull(entryValue = X509_NAME_ENTRY_get_data(entry));
  65816. ExpectStrEQ((const char *)ASN1_STRING_data(entryValue), "com");
  65817. ExpectIntEQ((idx = X509_NAME_get_index_by_NID(x509name, NID_domainComponent,
  65818. (int)idx)), 6);
  65819. ExpectNotNull(entry = X509_NAME_get_entry(x509name, (int)idx));
  65820. ExpectNotNull(entryValue = X509_NAME_ENTRY_get_data(entry));
  65821. ExpectStrEQ((const char *)ASN1_STRING_data(entryValue), "wolfssl");
  65822. #endif /* WOLFSSL_MULTI_ATTRIB */
  65823. /* try invalid index locations for regression test and sanity check */
  65824. ExpectNull(entry = X509_NAME_get_entry(x509name, 11));
  65825. ExpectNull(entry = X509_NAME_get_entry(x509name, 20));
  65826. X509_free(x509);
  65827. #endif /* OPENSSL_EXTRA */
  65828. wc_FreeRsaKey(&key);
  65829. wc_FreeRng(&rng);
  65830. #endif
  65831. return EXPECT_RESULT();
  65832. }
  65833. static int test_x509_get_key_id(void)
  65834. {
  65835. EXPECT_DECLS;
  65836. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  65837. X509 *x509 = NULL;
  65838. const ASN1_STRING* str = NULL;
  65839. byte* keyId = NULL;
  65840. ExpectNotNull(x509 = X509_load_certificate_file(cliCertFile,
  65841. WOLFSSL_FILETYPE_PEM));
  65842. ExpectNotNull(str = X509_get0_subject_key_id(x509));
  65843. ExpectNotNull(keyId = wolfSSL_X509_get_subjectKeyID(x509, NULL, NULL));
  65844. ExpectBufEQ(keyId, ASN1_STRING_data((ASN1_STRING*)str),
  65845. ASN1_STRING_length(str));
  65846. X509_free(x509);
  65847. #endif
  65848. return EXPECT_RESULT();
  65849. }
  65850. static int test_wolfSSL_X509_get_version(void)
  65851. {
  65852. EXPECT_DECLS;
  65853. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  65854. WOLFSSL_X509 *x509 = NULL;
  65855. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  65856. WOLFSSL_FILETYPE_PEM));
  65857. ExpectIntEQ((int)wolfSSL_X509_get_version(x509), 2);
  65858. wolfSSL_X509_free(x509);
  65859. #endif
  65860. return EXPECT_RESULT();
  65861. }
  65862. #if defined(OPENSSL_ALL)
  65863. static int test_wolfSSL_sk_CIPHER_description(void)
  65864. {
  65865. EXPECT_DECLS;
  65866. #if !defined(NO_RSA)
  65867. const long flags = SSL_OP_NO_SSLv2 | SSL_OP_NO_COMPRESSION;
  65868. int i;
  65869. int numCiphers = 0;
  65870. const SSL_METHOD *method = NULL;
  65871. const SSL_CIPHER *cipher = NULL;
  65872. STACK_OF(SSL_CIPHER) *supportedCiphers = NULL;
  65873. SSL_CTX *ctx = NULL;
  65874. SSL *ssl = NULL;
  65875. char buf[256];
  65876. char test_str[9] = "0000000";
  65877. const char badStr[] = "unknown";
  65878. const char certPath[] = "./certs/client-cert.pem";
  65879. XMEMSET(buf, 0, sizeof(buf));
  65880. ExpectNotNull(method = TLSv1_2_client_method());
  65881. ExpectNotNull(ctx = SSL_CTX_new(method));
  65882. SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, 0);
  65883. SSL_CTX_set_verify_depth(ctx, 4);
  65884. SSL_CTX_set_options(ctx, flags);
  65885. ExpectIntEQ(SSL_CTX_load_verify_locations(ctx, certPath, NULL),
  65886. WOLFSSL_SUCCESS);
  65887. ExpectNotNull(ssl = SSL_new(ctx));
  65888. /* SSL_get_ciphers returns a stack of all configured ciphers
  65889. * A flag, getCipherAtOffset, is set to later have SSL_CIPHER_description
  65890. */
  65891. ExpectNotNull(supportedCiphers = SSL_get_ciphers(ssl));
  65892. /* loop through the amount of supportedCiphers */
  65893. numCiphers = sk_num(supportedCiphers);
  65894. for (i = 0; i < numCiphers; ++i) {
  65895. int j;
  65896. /* sk_value increments "sk->data.cipher->cipherOffset".
  65897. * wolfSSL_sk_CIPHER_description sets the description for
  65898. * the cipher based on the provided offset.
  65899. */
  65900. if ((cipher = (const WOLFSSL_CIPHER*)sk_value(supportedCiphers, i))) {
  65901. SSL_CIPHER_description(cipher, buf, sizeof(buf));
  65902. }
  65903. /* Search cipher description string for "unknown" descriptor */
  65904. for (j = 0; j < (int)XSTRLEN(buf); j++) {
  65905. int k = 0;
  65906. while ((k < (int)XSTRLEN(badStr)) && (buf[j] == badStr[k])) {
  65907. test_str[k] = badStr[k];
  65908. j++;
  65909. k++;
  65910. }
  65911. }
  65912. /* Fail if test_str == badStr == "unknown" */
  65913. ExpectStrNE(test_str,badStr);
  65914. }
  65915. SSL_free(ssl);
  65916. SSL_CTX_free(ctx);
  65917. #endif
  65918. return EXPECT_RESULT();
  65919. }
  65920. static int test_wolfSSL_get_ciphers_compat(void)
  65921. {
  65922. EXPECT_DECLS;
  65923. #if !defined(NO_RSA)
  65924. const SSL_METHOD *method = NULL;
  65925. const char certPath[] = "./certs/client-cert.pem";
  65926. STACK_OF(SSL_CIPHER) *supportedCiphers = NULL;
  65927. SSL_CTX *ctx = NULL;
  65928. WOLFSSL *ssl = NULL;
  65929. const long flags = SSL_OP_NO_SSLv2 | SSL_OP_NO_COMPRESSION;
  65930. ExpectNotNull(method = SSLv23_client_method());
  65931. ExpectNotNull(ctx = SSL_CTX_new(method));
  65932. SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, 0);
  65933. SSL_CTX_set_verify_depth(ctx, 4);
  65934. SSL_CTX_set_options(ctx, flags);
  65935. ExpectIntEQ(SSL_CTX_load_verify_locations(ctx, certPath, NULL),
  65936. WOLFSSL_SUCCESS);
  65937. ExpectNotNull(ssl = SSL_new(ctx));
  65938. /* Test Bad NULL input */
  65939. ExpectNull(supportedCiphers = SSL_get_ciphers(NULL));
  65940. /* Test for Good input */
  65941. ExpectNotNull(supportedCiphers = SSL_get_ciphers(ssl));
  65942. /* Further usage of SSL_get_ciphers/wolfSSL_get_ciphers_compat is
  65943. * tested in test_wolfSSL_sk_CIPHER_description according to Qt usage */
  65944. SSL_free(ssl);
  65945. SSL_CTX_free(ctx);
  65946. #endif
  65947. return EXPECT_RESULT();
  65948. }
  65949. static int test_wolfSSL_X509_PUBKEY_get(void)
  65950. {
  65951. EXPECT_DECLS;
  65952. WOLFSSL_X509_PUBKEY pubkey;
  65953. WOLFSSL_X509_PUBKEY* key;
  65954. WOLFSSL_EVP_PKEY evpkey ;
  65955. WOLFSSL_EVP_PKEY* evpPkey;
  65956. WOLFSSL_EVP_PKEY* retEvpPkey;
  65957. XMEMSET(&pubkey, 0, sizeof(WOLFSSL_X509_PUBKEY));
  65958. XMEMSET(&evpkey, 0, sizeof(WOLFSSL_EVP_PKEY));
  65959. key = &pubkey;
  65960. evpPkey = &evpkey;
  65961. evpPkey->type = WOLFSSL_SUCCESS;
  65962. key->pkey = evpPkey;
  65963. ExpectNotNull(retEvpPkey = wolfSSL_X509_PUBKEY_get(key));
  65964. ExpectIntEQ(retEvpPkey->type, WOLFSSL_SUCCESS);
  65965. ExpectNull(retEvpPkey = wolfSSL_X509_PUBKEY_get(NULL));
  65966. key->pkey = NULL;
  65967. ExpectNull(retEvpPkey = wolfSSL_X509_PUBKEY_get(key));
  65968. return EXPECT_RESULT();
  65969. }
  65970. static int test_wolfSSL_EVP_PKEY_set1_get1_DSA(void)
  65971. {
  65972. EXPECT_DECLS;
  65973. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  65974. DSA *dsa = NULL;
  65975. DSA *setDsa = NULL;
  65976. EVP_PKEY *pkey = NULL;
  65977. EVP_PKEY *set1Pkey = NULL;
  65978. SHA_CTX sha;
  65979. byte signature[DSA_SIG_SIZE];
  65980. byte hash[WC_SHA_DIGEST_SIZE];
  65981. word32 bytes;
  65982. int answer;
  65983. #ifdef USE_CERT_BUFFERS_1024
  65984. const unsigned char* dsaKeyDer = dsa_key_der_1024;
  65985. int dsaKeySz = sizeof_dsa_key_der_1024;
  65986. byte tmp[ONEK_BUF];
  65987. XMEMSET(tmp, 0, sizeof(tmp));
  65988. XMEMCPY(tmp, dsaKeyDer , dsaKeySz);
  65989. bytes = dsaKeySz;
  65990. #elif defined(USE_CERT_BUFFERS_2048)
  65991. const unsigned char* dsaKeyDer = dsa_key_der_2048;
  65992. int dsaKeySz = sizeof_dsa_key_der_2048;
  65993. byte tmp[TWOK_BUF];
  65994. XMEMSET(tmp, 0, sizeof(tmp));
  65995. XMEMCPY(tmp, dsaKeyDer , dsaKeySz);
  65996. bytes = (word32)dsaKeySz;
  65997. #else
  65998. byte tmp[TWOK_BUF];
  65999. const unsigned char* dsaKeyDer = (const unsigned char*)tmp;
  66000. int dsaKeySz;
  66001. XFILE fp = XBADFILE;
  66002. XMEMSET(tmp, 0, sizeof(tmp));
  66003. ExpectTrue((fp = XFOPEN("./certs/dsa2048.der", "rb")) != XBADFILE);
  66004. ExpectIntGT(dsaKeySz = bytes = (word32) XFREAD(tmp, 1, sizeof(tmp), fp), 0);
  66005. if (fp != XBADFILE)
  66006. XFCLOSE(fp);
  66007. #endif /* END USE_CERT_BUFFERS_1024 */
  66008. /* Create hash to later Sign and Verify */
  66009. ExpectIntEQ(SHA1_Init(&sha), WOLFSSL_SUCCESS);
  66010. ExpectIntEQ(SHA1_Update(&sha, tmp, bytes), WOLFSSL_SUCCESS);
  66011. ExpectIntEQ(SHA1_Final(hash,&sha), WOLFSSL_SUCCESS);
  66012. /* Initialize pkey with der format dsa key */
  66013. ExpectNotNull(d2i_PrivateKey(EVP_PKEY_DSA, &pkey, &dsaKeyDer,
  66014. (long)dsaKeySz));
  66015. /* Test wolfSSL_EVP_PKEY_get1_DSA */
  66016. /* Should Fail: NULL argument */
  66017. ExpectNull(dsa = EVP_PKEY_get0_DSA(NULL));
  66018. ExpectNull(dsa = EVP_PKEY_get1_DSA(NULL));
  66019. /* Should Pass: Initialized pkey argument */
  66020. ExpectNotNull(dsa = EVP_PKEY_get0_DSA(pkey));
  66021. ExpectNotNull(dsa = EVP_PKEY_get1_DSA(pkey));
  66022. #ifdef USE_CERT_BUFFERS_1024
  66023. ExpectIntEQ(DSA_bits(dsa), 1024);
  66024. #else
  66025. ExpectIntEQ(DSA_bits(dsa), 2048);
  66026. #endif
  66027. /* Sign */
  66028. ExpectIntEQ(wolfSSL_DSA_do_sign(hash, signature, dsa), WOLFSSL_SUCCESS);
  66029. /* Verify. */
  66030. ExpectIntEQ(wolfSSL_DSA_do_verify(hash, signature, dsa, &answer),
  66031. WOLFSSL_SUCCESS);
  66032. /* Test wolfSSL_EVP_PKEY_set1_DSA */
  66033. /* Should Fail: set1Pkey not initialized */
  66034. ExpectIntNE(EVP_PKEY_set1_DSA(set1Pkey, dsa), WOLFSSL_SUCCESS);
  66035. /* Initialize set1Pkey */
  66036. set1Pkey = EVP_PKEY_new();
  66037. /* Should Fail Verify: setDsa not initialized from set1Pkey */
  66038. ExpectIntNE(wolfSSL_DSA_do_verify(hash,signature,setDsa,&answer),
  66039. WOLFSSL_SUCCESS);
  66040. /* Should Pass: set dsa into set1Pkey */
  66041. ExpectIntEQ(EVP_PKEY_set1_DSA(set1Pkey, dsa), WOLFSSL_SUCCESS);
  66042. DSA_free(dsa);
  66043. DSA_free(setDsa);
  66044. EVP_PKEY_free(pkey);
  66045. EVP_PKEY_free(set1Pkey);
  66046. #endif /* !NO_DSA && !HAVE_SELFTEST && WOLFSSL_KEY_GEN */
  66047. return EXPECT_RESULT();
  66048. } /* END test_EVP_PKEY_set1_get1_DSA */
  66049. static int test_wolfSSL_DSA_generate_parameters(void)
  66050. {
  66051. EXPECT_DECLS;
  66052. #if !defined(NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN) && \
  66053. !defined(HAVE_FIPS)
  66054. DSA *dsa = NULL;
  66055. ExpectNotNull(dsa = DSA_generate_parameters(2048, NULL, 0, NULL, NULL, NULL,
  66056. NULL));
  66057. DSA_free(dsa);
  66058. #endif
  66059. return EXPECT_RESULT();
  66060. }
  66061. static int test_wolfSSL_DSA_SIG(void)
  66062. {
  66063. EXPECT_DECLS;
  66064. #if !defined(NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN) && \
  66065. !defined(HAVE_FIPS)
  66066. DSA *dsa = NULL;
  66067. DSA *dsa2 = NULL;
  66068. DSA_SIG *sig = NULL;
  66069. const BIGNUM *p = NULL;
  66070. const BIGNUM *q = NULL;
  66071. const BIGNUM *g = NULL;
  66072. const BIGNUM *pub = NULL;
  66073. const BIGNUM *priv = NULL;
  66074. BIGNUM *dup_p = NULL;
  66075. BIGNUM *dup_q = NULL;
  66076. BIGNUM *dup_g = NULL;
  66077. BIGNUM *dup_pub = NULL;
  66078. BIGNUM *dup_priv = NULL;
  66079. const byte digest[WC_SHA_DIGEST_SIZE] = {0};
  66080. ExpectNotNull(dsa = DSA_new());
  66081. ExpectIntEQ(DSA_generate_parameters_ex(dsa, 2048, NULL, 0, NULL, NULL,
  66082. NULL), 1);
  66083. ExpectIntEQ(DSA_generate_key(dsa), 1);
  66084. DSA_get0_pqg(dsa, &p, &q, &g);
  66085. DSA_get0_key(dsa, &pub, &priv);
  66086. ExpectNotNull(dup_p = BN_dup(p));
  66087. ExpectNotNull(dup_q = BN_dup(q));
  66088. ExpectNotNull(dup_g = BN_dup(g));
  66089. ExpectNotNull(dup_pub = BN_dup(pub));
  66090. ExpectNotNull(dup_priv = BN_dup(priv));
  66091. ExpectNotNull(sig = DSA_do_sign(digest, sizeof(digest), dsa));
  66092. ExpectNotNull(dsa2 = DSA_new());
  66093. ExpectIntEQ(DSA_set0_pqg(dsa2, dup_p, dup_q, dup_g), 1);
  66094. if (EXPECT_FAIL()) {
  66095. BN_free(dup_p);
  66096. BN_free(dup_q);
  66097. BN_free(dup_g);
  66098. }
  66099. ExpectIntEQ(DSA_set0_key(dsa2, dup_pub, dup_priv), 1);
  66100. if (EXPECT_FAIL()) {
  66101. BN_free(dup_pub);
  66102. BN_free(dup_priv);
  66103. }
  66104. ExpectIntEQ(DSA_do_verify(digest, sizeof(digest), sig, dsa2), 1);
  66105. DSA_free(dsa);
  66106. DSA_free(dsa2);
  66107. DSA_SIG_free(sig);
  66108. #endif
  66109. return EXPECT_RESULT();
  66110. }
  66111. static int test_wolfSSL_EVP_PKEY_set1_get1_EC_KEY (void)
  66112. {
  66113. EXPECT_DECLS;
  66114. #ifdef HAVE_ECC
  66115. WOLFSSL_EC_KEY* ecKey = NULL;
  66116. WOLFSSL_EC_KEY* ecGet1 = NULL;
  66117. EVP_PKEY* pkey = NULL;
  66118. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  66119. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  66120. /* Test wolfSSL_EVP_PKEY_set1_EC_KEY */
  66121. ExpectIntEQ(wolfSSL_EVP_PKEY_set1_EC_KEY(NULL, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66122. ExpectIntEQ(wolfSSL_EVP_PKEY_set1_EC_KEY(pkey, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66123. /* Should fail since ecKey is empty */
  66124. ExpectIntEQ(wolfSSL_EVP_PKEY_set1_EC_KEY(pkey, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66125. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  66126. ExpectIntEQ(wolfSSL_EVP_PKEY_set1_EC_KEY(pkey, ecKey), WOLFSSL_SUCCESS);
  66127. /* Test wolfSSL_EVP_PKEY_get1_EC_KEY */
  66128. ExpectNull(wolfSSL_EVP_PKEY_get1_EC_KEY(NULL));
  66129. ExpectNotNull(ecGet1 = wolfSSL_EVP_PKEY_get1_EC_KEY(pkey));
  66130. wolfSSL_EC_KEY_free(ecKey);
  66131. wolfSSL_EC_KEY_free(ecGet1);
  66132. EVP_PKEY_free(pkey);
  66133. #endif /* HAVE_ECC */
  66134. return EXPECT_RESULT();
  66135. } /* END test_EVP_PKEY_set1_get1_EC_KEY */
  66136. static int test_wolfSSL_EVP_PKEY_set1_get1_DH (void)
  66137. {
  66138. EXPECT_DECLS;
  66139. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT) || defined(WOLFSSL_OPENSSH)
  66140. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  66141. #if !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA) && !defined(NO_FILESYSTEM)
  66142. DH *dh = NULL;
  66143. DH *setDh = NULL;
  66144. EVP_PKEY *pkey = NULL;
  66145. XFILE f = XBADFILE;
  66146. unsigned char buf[4096];
  66147. const unsigned char* pt = buf;
  66148. const char* dh2048 = "./certs/dh2048.der";
  66149. long len = 0;
  66150. int code = -1;
  66151. XMEMSET(buf, 0, sizeof(buf));
  66152. ExpectTrue((f = XFOPEN(dh2048, "rb")) != XBADFILE);
  66153. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  66154. if (f != XBADFILE)
  66155. XFCLOSE(f);
  66156. /* Load dh2048.der into DH with internal format */
  66157. ExpectNotNull(setDh = wolfSSL_d2i_DHparams(NULL, &pt, len));
  66158. ExpectIntEQ(wolfSSL_DH_check(setDh, &code), WOLFSSL_SUCCESS);
  66159. ExpectIntEQ(code, 0);
  66160. code = -1;
  66161. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  66162. /* Set DH into PKEY */
  66163. ExpectIntEQ(wolfSSL_EVP_PKEY_set1_DH(pkey, setDh), WOLFSSL_SUCCESS);
  66164. /* Get DH from PKEY */
  66165. ExpectNotNull(dh = wolfSSL_EVP_PKEY_get1_DH(pkey));
  66166. ExpectIntEQ(wolfSSL_DH_check(dh, &code), WOLFSSL_SUCCESS);
  66167. ExpectIntEQ(code, 0);
  66168. EVP_PKEY_free(pkey);
  66169. DH_free(setDh);
  66170. setDh = NULL;
  66171. DH_free(dh);
  66172. dh = NULL;
  66173. #endif /* !NO_DH && WOLFSSL_DH_EXTRA && !NO_FILESYSTEM */
  66174. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  66175. #endif /* OPENSSL_ALL || WOLFSSL_QT || WOLFSSL_OPENSSH */
  66176. return EXPECT_RESULT();
  66177. } /* END test_EVP_PKEY_set1_get1_DH */
  66178. static int test_wolfSSL_CTX_ctrl(void)
  66179. {
  66180. EXPECT_DECLS;
  66181. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  66182. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  66183. char caFile[] = "./certs/client-ca.pem";
  66184. char clientFile[] = "./certs/client-cert.pem";
  66185. SSL_CTX* ctx = NULL;
  66186. X509* x509 = NULL;
  66187. #if !defined(NO_DH) && !defined(NO_DSA) && !defined(NO_BIO)
  66188. byte buf[6000];
  66189. char file[] = "./certs/dsaparams.pem";
  66190. XFILE f = XBADFILE;
  66191. int bytes = 0;
  66192. BIO* bio = NULL;
  66193. DSA* dsa = NULL;
  66194. DH* dh = NULL;
  66195. #endif
  66196. #ifdef HAVE_ECC
  66197. WOLFSSL_EC_KEY* ecKey = NULL;
  66198. #endif
  66199. ExpectNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
  66200. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(caFile,
  66201. WOLFSSL_FILETYPE_PEM));
  66202. ExpectIntEQ((int)SSL_CTX_add_extra_chain_cert(ctx, x509), WOLFSSL_SUCCESS);
  66203. if (EXPECT_FAIL()) {
  66204. wolfSSL_X509_free(x509);
  66205. }
  66206. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(clientFile,
  66207. WOLFSSL_FILETYPE_PEM));
  66208. #if !defined(NO_DH) && !defined(NO_DSA) && !defined(NO_BIO)
  66209. /* Initialize DH */
  66210. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  66211. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  66212. if (f != XBADFILE)
  66213. XFCLOSE(f);
  66214. ExpectNotNull(bio = BIO_new_mem_buf((void*)buf, bytes));
  66215. ExpectNotNull(dsa = wolfSSL_PEM_read_bio_DSAparams(bio, NULL, NULL, NULL));
  66216. ExpectNotNull(dh = wolfSSL_DSA_dup_DH(dsa));
  66217. #endif
  66218. #ifdef HAVE_ECC
  66219. /* Initialize WOLFSSL_EC_KEY */
  66220. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  66221. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  66222. #endif
  66223. /* additional test of getting EVP_PKEY key size from X509
  66224. * Do not run with user RSA because wolfSSL_RSA_size is not currently
  66225. * allowed with user RSA */
  66226. {
  66227. EVP_PKEY* pkey = NULL;
  66228. #if defined(HAVE_ECC)
  66229. X509* ecX509 = NULL;
  66230. #endif /* HAVE_ECC */
  66231. ExpectNotNull(pkey = X509_get_pubkey(x509));
  66232. /* current RSA key is 2048 bit (256 bytes) */
  66233. ExpectIntEQ(EVP_PKEY_size(pkey), 256);
  66234. EVP_PKEY_free(pkey);
  66235. pkey = NULL;
  66236. #if defined(HAVE_ECC)
  66237. #if defined(USE_CERT_BUFFERS_256)
  66238. ExpectNotNull(ecX509 = wolfSSL_X509_load_certificate_buffer(
  66239. cliecc_cert_der_256, sizeof_cliecc_cert_der_256,
  66240. SSL_FILETYPE_ASN1));
  66241. #else
  66242. ExpectNotNull(ecX509 = wolfSSL_X509_load_certificate_file(
  66243. cliEccCertFile, SSL_FILETYPE_PEM));
  66244. #endif
  66245. ExpectNotNull(pkey = X509_get_pubkey(ecX509));
  66246. /* current ECC key is 256 bit (32 bytes) */
  66247. ExpectIntEQ(EVP_PKEY_size(pkey), 32);
  66248. X509_free(ecX509);
  66249. EVP_PKEY_free(pkey);
  66250. #endif /* HAVE_ECC */
  66251. }
  66252. /* Tests should fail with passed in NULL pointer */
  66253. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_EXTRA_CHAIN_CERT, 0, NULL),
  66254. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66255. #if !defined(NO_DH) && !defined(NO_DSA)
  66256. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_TMP_DH, 0, NULL),
  66257. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66258. #endif
  66259. #ifdef HAVE_ECC
  66260. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_TMP_ECDH, 0, NULL),
  66261. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66262. #endif
  66263. /* Test with SSL_CTRL_EXTRA_CHAIN_CERT
  66264. * wolfSSL_CTX_ctrl should succesffuly call SSL_CTX_add_extra_chain_cert
  66265. */
  66266. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_EXTRA_CHAIN_CERT, 0, x509),
  66267. SSL_SUCCESS);
  66268. if (EXPECT_FAIL()) {
  66269. wolfSSL_X509_free(x509);
  66270. }
  66271. /* Test with SSL_CTRL_OPTIONS
  66272. * wolfSSL_CTX_ctrl should succesffuly call SSL_CTX_set_options
  66273. */
  66274. ExpectTrue(wolfSSL_CTX_ctrl(ctx, SSL_CTRL_OPTIONS, SSL_OP_NO_TLSv1,
  66275. NULL) == SSL_OP_NO_TLSv1);
  66276. ExpectTrue(SSL_CTX_get_options(ctx) == SSL_OP_NO_TLSv1);
  66277. /* Test with SSL_CTRL_SET_TMP_DH
  66278. * wolfSSL_CTX_ctrl should succesffuly call wolfSSL_SSL_CTX_set_tmp_dh
  66279. */
  66280. #if !defined(NO_DH) && !defined(NO_DSA) && !defined(NO_BIO)
  66281. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_TMP_DH, 0, dh),
  66282. SSL_SUCCESS);
  66283. #endif
  66284. /* Test with SSL_CTRL_SET_TMP_ECDH
  66285. * wolfSSL_CTX_ctrl should succesffuly call wolfSSL_SSL_CTX_set_tmp_ecdh
  66286. */
  66287. #ifdef HAVE_ECC
  66288. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_TMP_ECDH, 0, ecKey),
  66289. SSL_SUCCESS);
  66290. #endif
  66291. #ifdef WOLFSSL_ENCRYPTED_KEYS
  66292. ExpectNull(SSL_CTX_get_default_passwd_cb(ctx));
  66293. ExpectNull(SSL_CTX_get_default_passwd_cb_userdata(ctx));
  66294. #endif
  66295. /* Test for min/max proto */
  66296. #ifndef WOLFSSL_NO_TLS12
  66297. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_MIN_PROTO_VERSION,
  66298. 0, NULL), SSL_SUCCESS);
  66299. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_MIN_PROTO_VERSION,
  66300. TLS1_2_VERSION, NULL), SSL_SUCCESS);
  66301. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_2_VERSION);
  66302. #endif
  66303. #ifdef WOLFSSL_TLS13
  66304. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_PROTO_VERSION,
  66305. 0, NULL), SSL_SUCCESS);
  66306. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_PROTO_VERSION,
  66307. TLS1_3_VERSION, NULL), SSL_SUCCESS);
  66308. ExpectIntEQ(wolfSSL_CTX_get_max_proto_version(ctx), TLS1_3_VERSION);
  66309. #ifndef WOLFSSL_NO_TLS12
  66310. ExpectIntEQ((int)wolfSSL_CTX_ctrl(ctx, SSL_CTRL_SET_MAX_PROTO_VERSION,
  66311. TLS1_2_VERSION, NULL), SSL_SUCCESS);
  66312. ExpectIntEQ(wolfSSL_CTX_get_max_proto_version(ctx), TLS1_2_VERSION);
  66313. #endif
  66314. #endif
  66315. /* Cleanup and Pass */
  66316. #if !defined(NO_DH) && !defined(NO_DSA)
  66317. #ifndef NO_BIO
  66318. BIO_free(bio);
  66319. DSA_free(dsa);
  66320. DH_free(dh);
  66321. dh = NULL;
  66322. #endif
  66323. #endif
  66324. #ifdef HAVE_ECC
  66325. wolfSSL_EC_KEY_free(ecKey);
  66326. #endif
  66327. SSL_CTX_free(ctx);
  66328. #endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  66329. * !defined(NO_FILESYSTEM) && !defined(NO_RSA) */
  66330. return EXPECT_RESULT();
  66331. }
  66332. static int test_wolfSSL_EVP_PKEY_assign(void)
  66333. {
  66334. EXPECT_DECLS;
  66335. #if !defined(NO_RSA) || !defined(NO_DSA) || defined(HAVE_ECC)
  66336. int type;
  66337. WOLFSSL_EVP_PKEY* pkey = NULL;
  66338. #ifndef NO_RSA
  66339. WOLFSSL_RSA* rsa = NULL;
  66340. #endif
  66341. #ifndef NO_DSA
  66342. WOLFSSL_DSA* dsa = NULL;
  66343. #endif
  66344. #ifdef HAVE_ECC
  66345. WOLFSSL_EC_KEY* ecKey = NULL;
  66346. #endif
  66347. #ifndef NO_RSA
  66348. type = EVP_PKEY_RSA;
  66349. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  66350. ExpectNotNull(rsa = wolfSSL_RSA_new());
  66351. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(NULL, type, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66352. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66353. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, -1, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66354. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, rsa), WOLFSSL_SUCCESS);
  66355. if (EXPECT_FAIL()) {
  66356. wolfSSL_RSA_free(rsa);
  66357. }
  66358. wolfSSL_EVP_PKEY_free(pkey);
  66359. pkey = NULL;
  66360. #endif /* NO_RSA */
  66361. #ifndef NO_DSA
  66362. type = EVP_PKEY_DSA;
  66363. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  66364. ExpectNotNull(dsa = wolfSSL_DSA_new());
  66365. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(NULL, type, dsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66366. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66367. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, -1, dsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66368. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, dsa), WOLFSSL_SUCCESS);
  66369. if (EXPECT_FAIL()) {
  66370. wolfSSL_DSA_free(dsa);
  66371. }
  66372. wolfSSL_EVP_PKEY_free(pkey);
  66373. pkey = NULL;
  66374. #endif /* NO_DSA */
  66375. #ifdef HAVE_ECC
  66376. type = EVP_PKEY_EC;
  66377. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  66378. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  66379. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(NULL, type, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66380. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66381. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, -1, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66382. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66383. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  66384. ExpectIntEQ(wolfSSL_EVP_PKEY_assign(pkey, type, ecKey), WOLFSSL_SUCCESS);
  66385. if (EXPECT_FAIL()) {
  66386. wolfSSL_EC_KEY_free(ecKey);
  66387. }
  66388. wolfSSL_EVP_PKEY_free(pkey);
  66389. pkey = NULL;
  66390. #endif /* HAVE_ECC */
  66391. #endif /* !NO_RSA || !NO_DSA || HAVE_ECC */
  66392. return EXPECT_RESULT();
  66393. }
  66394. static int test_wolfSSL_EVP_PKEY_assign_DH(void)
  66395. {
  66396. EXPECT_DECLS;
  66397. #if !defined(NO_DH) && \
  66398. !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  66399. XFILE f = XBADFILE;
  66400. unsigned char buf[4096];
  66401. const unsigned char* pt = buf;
  66402. const char* params1 = "./certs/dh2048.der";
  66403. long len = 0;
  66404. WOLFSSL_DH* dh = NULL;
  66405. WOLFSSL_EVP_PKEY* pkey = NULL;
  66406. XMEMSET(buf, 0, sizeof(buf));
  66407. /* Load DH parameters DER. */
  66408. ExpectTrue((f = XFOPEN(params1, "rb")) != XBADFILE);
  66409. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  66410. if (f != XBADFILE)
  66411. XFCLOSE(f);
  66412. ExpectNotNull(dh = wolfSSL_d2i_DHparams(NULL, &pt, len));
  66413. ExpectIntEQ(DH_generate_key(dh), WOLFSSL_SUCCESS);
  66414. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  66415. /* Bad cases */
  66416. ExpectIntEQ(wolfSSL_EVP_PKEY_assign_DH(NULL, dh), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66417. ExpectIntEQ(wolfSSL_EVP_PKEY_assign_DH(pkey, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66418. ExpectIntEQ(wolfSSL_EVP_PKEY_assign_DH(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66419. /* Good case */
  66420. ExpectIntEQ(wolfSSL_EVP_PKEY_assign_DH(pkey, dh), WOLFSSL_SUCCESS);
  66421. if (EXPECT_FAIL()) {
  66422. wolfSSL_DH_free(dh);
  66423. }
  66424. EVP_PKEY_free(pkey);
  66425. #endif
  66426. return EXPECT_RESULT();
  66427. }
  66428. static int test_wolfSSL_EVP_PKEY_base_id(void)
  66429. {
  66430. EXPECT_DECLS;
  66431. WOLFSSL_EVP_PKEY* pkey = NULL;
  66432. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  66433. ExpectIntEQ(wolfSSL_EVP_PKEY_base_id(NULL), NID_undef);
  66434. ExpectIntEQ(wolfSSL_EVP_PKEY_base_id(pkey), EVP_PKEY_RSA);
  66435. EVP_PKEY_free(pkey);
  66436. return EXPECT_RESULT();
  66437. }
  66438. static int test_wolfSSL_EVP_PKEY_id(void)
  66439. {
  66440. EXPECT_DECLS;
  66441. WOLFSSL_EVP_PKEY* pkey = NULL;
  66442. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  66443. ExpectIntEQ(wolfSSL_EVP_PKEY_id(NULL), 0);
  66444. ExpectIntEQ(wolfSSL_EVP_PKEY_id(pkey), EVP_PKEY_RSA);
  66445. EVP_PKEY_free(pkey);
  66446. return EXPECT_RESULT();
  66447. }
  66448. static int test_wolfSSL_EVP_PKEY_paramgen(void)
  66449. {
  66450. EXPECT_DECLS;
  66451. /* ECC check taken from ecc.c. It is the condition that defines ECC256 */
  66452. #if defined(OPENSSL_ALL) && !defined(NO_ECC_SECP) && \
  66453. ((!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && \
  66454. ECC_MIN_KEY_SZ <= 256)
  66455. EVP_PKEY_CTX* ctx = NULL;
  66456. EVP_PKEY* pkey = NULL;
  66457. /* Test error conditions. */
  66458. ExpectIntEQ(EVP_PKEY_paramgen(NULL, &pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66459. ExpectNotNull(ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL));
  66460. ExpectIntEQ(EVP_PKEY_paramgen(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66461. #ifndef NO_RSA
  66462. EVP_PKEY_CTX_free(ctx);
  66463. /* Parameter generation for RSA not supported yet. */
  66464. ExpectNotNull(ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_RSA, NULL));
  66465. ExpectIntEQ(EVP_PKEY_paramgen(ctx, &pkey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66466. #endif
  66467. #ifdef HAVE_ECC
  66468. EVP_PKEY_CTX_free(ctx);
  66469. ExpectNotNull(ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL));
  66470. ExpectIntEQ(EVP_PKEY_paramgen_init(ctx), WOLFSSL_SUCCESS);
  66471. ExpectIntEQ(EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx,
  66472. NID_X9_62_prime256v1), WOLFSSL_SUCCESS);
  66473. ExpectIntEQ(EVP_PKEY_paramgen(ctx, &pkey), WOLFSSL_SUCCESS);
  66474. ExpectIntEQ(EVP_PKEY_CTX_set_ec_param_enc(ctx, OPENSSL_EC_NAMED_CURVE),
  66475. WOLFSSL_SUCCESS);
  66476. ExpectIntEQ(EVP_PKEY_keygen_init(ctx), WOLFSSL_SUCCESS);
  66477. ExpectIntEQ(EVP_PKEY_keygen(ctx, &pkey), WOLFSSL_SUCCESS);
  66478. #endif
  66479. EVP_PKEY_CTX_free(ctx);
  66480. EVP_PKEY_free(pkey);
  66481. #endif
  66482. return EXPECT_RESULT();
  66483. }
  66484. static int test_wolfSSL_EVP_PKEY_keygen(void)
  66485. {
  66486. EXPECT_DECLS;
  66487. WOLFSSL_EVP_PKEY* pkey = NULL;
  66488. EVP_PKEY_CTX* ctx = NULL;
  66489. #if !defined(NO_DH) && (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0))
  66490. WOLFSSL_EVP_PKEY* params = NULL;
  66491. DH* dh = NULL;
  66492. const BIGNUM* pubkey = NULL;
  66493. const BIGNUM* privkey = NULL;
  66494. ASN1_INTEGER* asn1int = NULL;
  66495. unsigned int length = 0;
  66496. byte* derBuffer = NULL;
  66497. #endif
  66498. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  66499. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  66500. /* Bad cases */
  66501. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen(NULL, &pkey), 0);
  66502. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen(ctx, NULL), 0);
  66503. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen(NULL, NULL), 0);
  66504. /* Good case */
  66505. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen(ctx, &pkey), 0);
  66506. EVP_PKEY_CTX_free(ctx);
  66507. ctx = NULL;
  66508. EVP_PKEY_free(pkey);
  66509. pkey = NULL;
  66510. #if !defined(NO_DH) && (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0))
  66511. /* Test DH keygen */
  66512. {
  66513. ExpectNotNull(params = wolfSSL_EVP_PKEY_new());
  66514. ExpectNotNull(dh = DH_get_2048_256());
  66515. ExpectIntEQ(EVP_PKEY_set1_DH(params, dh), WOLFSSL_SUCCESS);
  66516. ExpectNotNull(ctx = EVP_PKEY_CTX_new(params, NULL));
  66517. ExpectIntEQ(EVP_PKEY_keygen_init(ctx), WOLFSSL_SUCCESS);
  66518. ExpectIntEQ(EVP_PKEY_keygen(ctx, &pkey), WOLFSSL_SUCCESS);
  66519. DH_free(dh);
  66520. dh = NULL;
  66521. EVP_PKEY_CTX_free(ctx);
  66522. EVP_PKEY_free(params);
  66523. /* try exporting generated key to DER, to verify */
  66524. ExpectNotNull(dh = EVP_PKEY_get1_DH(pkey));
  66525. DH_get0_key(dh, &pubkey, &privkey);
  66526. ExpectNotNull(pubkey);
  66527. ExpectNotNull(privkey);
  66528. ExpectNotNull(asn1int = BN_to_ASN1_INTEGER(pubkey, NULL));
  66529. ExpectIntGT((length = i2d_ASN1_INTEGER(asn1int, &derBuffer)), 0);
  66530. ASN1_INTEGER_free(asn1int);
  66531. DH_free(dh);
  66532. dh = NULL;
  66533. XFREE(derBuffer, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  66534. EVP_PKEY_free(pkey);
  66535. }
  66536. #endif
  66537. return EXPECT_RESULT();
  66538. }
  66539. static int test_wolfSSL_EVP_PKEY_keygen_init(void)
  66540. {
  66541. EXPECT_DECLS;
  66542. WOLFSSL_EVP_PKEY* pkey = NULL;
  66543. EVP_PKEY_CTX *ctx = NULL;
  66544. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  66545. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  66546. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen_init(ctx), WOLFSSL_SUCCESS);
  66547. ExpectIntEQ(wolfSSL_EVP_PKEY_keygen_init(NULL), WOLFSSL_SUCCESS);
  66548. EVP_PKEY_CTX_free(ctx);
  66549. EVP_PKEY_free(pkey);
  66550. return EXPECT_RESULT();
  66551. }
  66552. static int test_wolfSSL_EVP_PKEY_missing_parameters(void)
  66553. {
  66554. EXPECT_DECLS;
  66555. #if defined(OPENSSL_ALL) && !defined(NO_WOLFSSL_STUB)
  66556. WOLFSSL_EVP_PKEY* pkey = NULL;
  66557. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  66558. ExpectIntEQ(wolfSSL_EVP_PKEY_missing_parameters(pkey), 0);
  66559. ExpectIntEQ(wolfSSL_EVP_PKEY_missing_parameters(NULL), 0);
  66560. EVP_PKEY_free(pkey);
  66561. #endif
  66562. return EXPECT_RESULT();
  66563. }
  66564. static int test_wolfSSL_EVP_PKEY_copy_parameters(void)
  66565. {
  66566. EXPECT_DECLS;
  66567. #if defined(OPENSSL_EXTRA) && !defined(NO_DH) && defined(WOLFSSL_KEY_GEN) && \
  66568. !defined(HAVE_SELFTEST) && (defined(OPENSSL_ALL) || defined(WOLFSSL_QT) || \
  66569. defined(WOLFSSL_OPENSSH)) && defined(WOLFSSL_DH_EXTRA) && \
  66570. !defined(NO_FILESYSTEM)
  66571. WOLFSSL_EVP_PKEY* params = NULL;
  66572. WOLFSSL_EVP_PKEY* copy = NULL;
  66573. DH* dh = NULL;
  66574. BIGNUM* p1;
  66575. BIGNUM* g1;
  66576. BIGNUM* q1;
  66577. BIGNUM* p2;
  66578. BIGNUM* g2;
  66579. BIGNUM* q2;
  66580. /* create DH with DH_get_2048_256 params */
  66581. ExpectNotNull(params = wolfSSL_EVP_PKEY_new());
  66582. ExpectNotNull(dh = DH_get_2048_256());
  66583. ExpectIntEQ(EVP_PKEY_set1_DH(params, dh), WOLFSSL_SUCCESS);
  66584. DH_get0_pqg(dh, (const BIGNUM**)&p1,
  66585. (const BIGNUM**)&q1,
  66586. (const BIGNUM**)&g1);
  66587. DH_free(dh);
  66588. dh = NULL;
  66589. /* create DH with random generated DH params */
  66590. ExpectNotNull(copy = wolfSSL_EVP_PKEY_new());
  66591. ExpectNotNull(dh = DH_generate_parameters(2048, 2, NULL, NULL));
  66592. ExpectIntEQ(EVP_PKEY_set1_DH(copy, dh), WOLFSSL_SUCCESS);
  66593. DH_free(dh);
  66594. dh = NULL;
  66595. ExpectIntEQ(EVP_PKEY_copy_parameters(copy, params), WOLFSSL_SUCCESS);
  66596. ExpectNotNull(dh = EVP_PKEY_get1_DH(copy));
  66597. ExpectNotNull(dh->p);
  66598. ExpectNotNull(dh->g);
  66599. ExpectNotNull(dh->q);
  66600. DH_get0_pqg(dh, (const BIGNUM**)&p2,
  66601. (const BIGNUM**)&q2,
  66602. (const BIGNUM**)&g2);
  66603. ExpectIntEQ(BN_cmp(p1, p2), 0);
  66604. ExpectIntEQ(BN_cmp(q1, q2), 0);
  66605. ExpectIntEQ(BN_cmp(g1, g2), 0);
  66606. DH_free(dh);
  66607. dh = NULL;
  66608. EVP_PKEY_free(copy);
  66609. EVP_PKEY_free(params);
  66610. #endif
  66611. return EXPECT_RESULT();
  66612. }
  66613. static int test_wolfSSL_EVP_PKEY_CTX_set_rsa_keygen_bits(void)
  66614. {
  66615. EXPECT_DECLS;
  66616. WOLFSSL_EVP_PKEY* pkey = NULL;
  66617. EVP_PKEY_CTX* ctx = NULL;
  66618. int bits = 2048;
  66619. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  66620. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  66621. ExpectIntEQ(wolfSSL_EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, bits),
  66622. WOLFSSL_SUCCESS);
  66623. EVP_PKEY_CTX_free(ctx);
  66624. EVP_PKEY_free(pkey);
  66625. return EXPECT_RESULT();
  66626. }
  66627. static int test_wolfSSL_EVP_CIPHER_CTX_iv_length(void)
  66628. {
  66629. EXPECT_DECLS;
  66630. /* This is large enough to be used for all key sizes */
  66631. byte key[AES_256_KEY_SIZE] = {0};
  66632. byte iv[AES_BLOCK_SIZE] = {0};
  66633. int i;
  66634. int nids[] = {
  66635. #ifdef HAVE_AES_CBC
  66636. NID_aes_128_cbc,
  66637. #endif
  66638. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  66639. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  66640. #ifdef HAVE_AESGCM
  66641. NID_aes_128_gcm,
  66642. #endif
  66643. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  66644. #ifdef WOLFSSL_AES_COUNTER
  66645. NID_aes_128_ctr,
  66646. #endif
  66647. #ifndef NO_DES3
  66648. NID_des_cbc,
  66649. NID_des_ede3_cbc,
  66650. #endif
  66651. };
  66652. int iv_lengths[] = {
  66653. #ifdef HAVE_AES_CBC
  66654. AES_BLOCK_SIZE,
  66655. #endif
  66656. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  66657. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  66658. #ifdef HAVE_AESGCM
  66659. GCM_NONCE_MID_SZ,
  66660. #endif
  66661. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  66662. #ifdef WOLFSSL_AES_COUNTER
  66663. AES_BLOCK_SIZE,
  66664. #endif
  66665. #ifndef NO_DES3
  66666. DES_BLOCK_SIZE,
  66667. DES_BLOCK_SIZE,
  66668. #endif
  66669. };
  66670. int nidsLen = (sizeof(nids)/sizeof(int));
  66671. for (i = 0; i < nidsLen; i++) {
  66672. const EVP_CIPHER* init = wolfSSL_EVP_get_cipherbynid(nids[i]);
  66673. EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
  66674. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  66675. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  66676. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_iv_length(ctx), iv_lengths[i]);
  66677. EVP_CIPHER_CTX_free(ctx);
  66678. }
  66679. return EXPECT_RESULT();
  66680. }
  66681. static int test_wolfSSL_EVP_CIPHER_CTX_key_length(void)
  66682. {
  66683. EXPECT_DECLS;
  66684. byte key[AES_256_KEY_SIZE] = {0};
  66685. byte iv[AES_BLOCK_SIZE] = {0};
  66686. int i;
  66687. int nids[] = {
  66688. #ifdef HAVE_AES_CBC
  66689. NID_aes_128_cbc,
  66690. NID_aes_256_cbc,
  66691. #endif
  66692. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  66693. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  66694. #ifdef HAVE_AESGCM
  66695. NID_aes_128_gcm,
  66696. NID_aes_256_gcm,
  66697. #endif
  66698. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  66699. #ifdef WOLFSSL_AES_COUNTER
  66700. NID_aes_128_ctr,
  66701. NID_aes_256_ctr,
  66702. #endif
  66703. #ifndef NO_DES3
  66704. NID_des_cbc,
  66705. NID_des_ede3_cbc,
  66706. #endif
  66707. };
  66708. int key_lengths[] = {
  66709. #ifdef HAVE_AES_CBC
  66710. AES_128_KEY_SIZE,
  66711. AES_256_KEY_SIZE,
  66712. #endif
  66713. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  66714. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  66715. #ifdef HAVE_AESGCM
  66716. AES_128_KEY_SIZE,
  66717. AES_256_KEY_SIZE,
  66718. #endif
  66719. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  66720. #ifdef WOLFSSL_AES_COUNTER
  66721. AES_128_KEY_SIZE,
  66722. AES_256_KEY_SIZE,
  66723. #endif
  66724. #ifndef NO_DES3
  66725. DES_KEY_SIZE,
  66726. DES3_KEY_SIZE,
  66727. #endif
  66728. };
  66729. int nidsLen = (sizeof(nids)/sizeof(int));
  66730. for (i = 0; i < nidsLen; i++) {
  66731. const EVP_CIPHER *init = wolfSSL_EVP_get_cipherbynid(nids[i]);
  66732. EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
  66733. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  66734. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  66735. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_key_length(ctx), key_lengths[i]);
  66736. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_key_length(ctx, key_lengths[i]),
  66737. WOLFSSL_SUCCESS);
  66738. EVP_CIPHER_CTX_free(ctx);
  66739. }
  66740. return EXPECT_RESULT();
  66741. }
  66742. static int test_wolfSSL_EVP_CIPHER_CTX_set_iv(void)
  66743. {
  66744. EXPECT_DECLS;
  66745. #if defined(HAVE_AESGCM) && !defined(NO_DES3)
  66746. int ivLen, keyLen;
  66747. EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
  66748. #ifdef HAVE_AESGCM
  66749. byte key[AES_128_KEY_SIZE] = {0};
  66750. byte iv[AES_BLOCK_SIZE] = {0};
  66751. const EVP_CIPHER *init = EVP_aes_128_gcm();
  66752. #else
  66753. byte key[DES3_KEY_SIZE] = {0};
  66754. byte iv[DES_BLOCK_SIZE] = {0};
  66755. const EVP_CIPHER *init = EVP_des_ede3_cbc();
  66756. #endif
  66757. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  66758. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  66759. ivLen = wolfSSL_EVP_CIPHER_CTX_iv_length(ctx);
  66760. keyLen = wolfSSL_EVP_CIPHER_CTX_key_length(ctx);
  66761. /* Bad cases */
  66762. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(NULL, iv, ivLen),
  66763. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66764. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(ctx, NULL, ivLen),
  66765. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66766. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(ctx, iv, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66767. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(NULL, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66768. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(ctx, iv, keyLen),
  66769. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  66770. /* Good case */
  66771. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_set_iv(ctx, iv, ivLen), 1);
  66772. EVP_CIPHER_CTX_free(ctx);
  66773. #endif
  66774. return EXPECT_RESULT();
  66775. }
  66776. static int test_wolfSSL_EVP_PKEY_CTX_new_id(void)
  66777. {
  66778. EXPECT_DECLS;
  66779. WOLFSSL_ENGINE* e = NULL;
  66780. int id = 0;
  66781. EVP_PKEY_CTX *ctx = NULL;
  66782. ExpectNotNull(ctx = wolfSSL_EVP_PKEY_CTX_new_id(id, e));
  66783. EVP_PKEY_CTX_free(ctx);
  66784. return EXPECT_RESULT();
  66785. }
  66786. static int test_wolfSSL_EVP_rc4(void)
  66787. {
  66788. EXPECT_DECLS;
  66789. #if !defined(NO_RC4)
  66790. ExpectNotNull(wolfSSL_EVP_rc4());
  66791. #endif
  66792. return EXPECT_RESULT();
  66793. }
  66794. static int test_wolfSSL_EVP_enc_null(void)
  66795. {
  66796. EXPECT_DECLS;
  66797. ExpectNotNull(wolfSSL_EVP_enc_null());
  66798. return EXPECT_RESULT();
  66799. }
  66800. static int test_wolfSSL_EVP_rc2_cbc(void)
  66801. {
  66802. EXPECT_DECLS;
  66803. #if defined(WOLFSSL_QT) && !defined(NO_WOLFSSL_STUB)
  66804. ExpectNull(wolfSSL_EVP_rc2_cbc());
  66805. #endif
  66806. return EXPECT_RESULT();
  66807. }
  66808. static int test_wolfSSL_EVP_mdc2(void)
  66809. {
  66810. EXPECT_DECLS;
  66811. #if !defined(NO_WOLFSSL_STUB)
  66812. ExpectNull(wolfSSL_EVP_mdc2());
  66813. #endif
  66814. return EXPECT_RESULT();
  66815. }
  66816. static int test_wolfSSL_EVP_md4(void)
  66817. {
  66818. EXPECT_DECLS;
  66819. #if !defined(NO_MD4)
  66820. ExpectNotNull(wolfSSL_EVP_md4());
  66821. #endif
  66822. return EXPECT_RESULT();
  66823. }
  66824. static int test_wolfSSL_EVP_aes_256_gcm(void)
  66825. {
  66826. EXPECT_DECLS;
  66827. #ifdef HAVE_AESGCM
  66828. ExpectNotNull(wolfSSL_EVP_aes_256_gcm());
  66829. #endif
  66830. return EXPECT_RESULT();
  66831. }
  66832. static int test_wolfSSL_EVP_aes_192_gcm(void)
  66833. {
  66834. EXPECT_DECLS;
  66835. #ifdef HAVE_AESGCM
  66836. ExpectNotNull(wolfSSL_EVP_aes_192_gcm());
  66837. #endif
  66838. return EXPECT_RESULT();
  66839. }
  66840. static int test_wolfSSL_EVP_aes_256_ccm(void)
  66841. {
  66842. EXPECT_DECLS;
  66843. #ifdef HAVE_AESCCM
  66844. ExpectNotNull(wolfSSL_EVP_aes_256_ccm());
  66845. #endif
  66846. return EXPECT_RESULT();
  66847. }
  66848. static int test_wolfSSL_EVP_aes_192_ccm(void)
  66849. {
  66850. EXPECT_DECLS;
  66851. #ifdef HAVE_AESCCM
  66852. ExpectNotNull(wolfSSL_EVP_aes_192_ccm());
  66853. #endif
  66854. return EXPECT_RESULT();
  66855. }
  66856. static int test_wolfSSL_EVP_aes_128_ccm(void)
  66857. {
  66858. EXPECT_DECLS;
  66859. #ifdef HAVE_AESCCM
  66860. ExpectNotNull(wolfSSL_EVP_aes_128_ccm());
  66861. #endif
  66862. return EXPECT_RESULT();
  66863. }
  66864. static int test_wolfSSL_EVP_ripemd160(void)
  66865. {
  66866. EXPECT_DECLS;
  66867. #if !defined(NO_WOLFSSL_STUB)
  66868. ExpectNull(wolfSSL_EVP_ripemd160());
  66869. #endif
  66870. return EXPECT_RESULT();
  66871. }
  66872. static int test_wolfSSL_EVP_get_digestbynid(void)
  66873. {
  66874. EXPECT_DECLS;
  66875. #ifndef NO_MD5
  66876. ExpectNotNull(wolfSSL_EVP_get_digestbynid(NID_md5));
  66877. #endif
  66878. #ifndef NO_SHA
  66879. ExpectNotNull(wolfSSL_EVP_get_digestbynid(NID_sha1));
  66880. #endif
  66881. #ifndef NO_SHA256
  66882. ExpectNotNull(wolfSSL_EVP_get_digestbynid(NID_sha256));
  66883. #endif
  66884. ExpectNull(wolfSSL_EVP_get_digestbynid(0));
  66885. return EXPECT_RESULT();
  66886. }
  66887. static int test_wolfSSL_EVP_MD_nid(void)
  66888. {
  66889. EXPECT_DECLS;
  66890. #ifndef NO_MD5
  66891. ExpectIntEQ(EVP_MD_nid(EVP_md5()), NID_md5);
  66892. #endif
  66893. #ifndef NO_SHA
  66894. ExpectIntEQ(EVP_MD_nid(EVP_sha1()), NID_sha1);
  66895. #endif
  66896. #ifndef NO_SHA256
  66897. ExpectIntEQ(EVP_MD_nid(EVP_sha256()), NID_sha256);
  66898. #endif
  66899. ExpectIntEQ(EVP_MD_nid(NULL), NID_undef);
  66900. return EXPECT_RESULT();
  66901. }
  66902. static int test_wolfSSL_EVP_PKEY_get0_EC_KEY(void)
  66903. {
  66904. EXPECT_DECLS;
  66905. #if defined(HAVE_ECC)
  66906. WOLFSSL_EVP_PKEY* pkey = NULL;
  66907. ExpectNull(EVP_PKEY_get0_EC_KEY(NULL));
  66908. ExpectNotNull(pkey = EVP_PKEY_new());
  66909. ExpectNull(EVP_PKEY_get0_EC_KEY(pkey));
  66910. EVP_PKEY_free(pkey);
  66911. #endif
  66912. return EXPECT_RESULT();
  66913. }
  66914. static int test_wolfSSL_EVP_X_STATE(void)
  66915. {
  66916. EXPECT_DECLS;
  66917. #if !defined(NO_DES3) && !defined(NO_RC4)
  66918. byte key[DES3_KEY_SIZE] = {0};
  66919. byte iv[DES_IV_SIZE] = {0};
  66920. EVP_CIPHER_CTX *ctx = NULL;
  66921. const EVP_CIPHER *init = NULL;
  66922. /* Bad test cases */
  66923. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  66924. ExpectNotNull(init = EVP_des_ede3_cbc());
  66925. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  66926. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  66927. ExpectNull(wolfSSL_EVP_X_STATE(NULL));
  66928. ExpectNull(wolfSSL_EVP_X_STATE(ctx));
  66929. EVP_CIPHER_CTX_free(ctx);
  66930. ctx = NULL;
  66931. /* Good test case */
  66932. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  66933. ExpectNotNull(init = wolfSSL_EVP_rc4());
  66934. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  66935. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  66936. ExpectNotNull(wolfSSL_EVP_X_STATE(ctx));
  66937. EVP_CIPHER_CTX_free(ctx);
  66938. #endif
  66939. return EXPECT_RESULT();
  66940. }
  66941. static int test_wolfSSL_EVP_X_STATE_LEN(void)
  66942. {
  66943. EXPECT_DECLS;
  66944. #if !defined(NO_DES3) && !defined(NO_RC4)
  66945. byte key[DES3_KEY_SIZE] = {0};
  66946. byte iv[DES_IV_SIZE] = {0};
  66947. EVP_CIPHER_CTX *ctx = NULL;
  66948. const EVP_CIPHER *init = NULL;
  66949. /* Bad test cases */
  66950. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  66951. ExpectNotNull(init = EVP_des_ede3_cbc());
  66952. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  66953. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  66954. ExpectIntEQ(wolfSSL_EVP_X_STATE_LEN(NULL), 0);
  66955. ExpectIntEQ(wolfSSL_EVP_X_STATE_LEN(ctx), 0);
  66956. EVP_CIPHER_CTX_free(ctx);
  66957. ctx = NULL;
  66958. /* Good test case */
  66959. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  66960. ExpectNotNull(init = wolfSSL_EVP_rc4());
  66961. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  66962. ExpectIntEQ(EVP_CipherInit(ctx, init, key, iv, 1), WOLFSSL_SUCCESS);
  66963. ExpectIntEQ(wolfSSL_EVP_X_STATE_LEN(ctx), sizeof(Arc4));
  66964. EVP_CIPHER_CTX_free(ctx);
  66965. #endif
  66966. return EXPECT_RESULT();
  66967. }
  66968. static int test_wolfSSL_EVP_CIPHER_block_size(void)
  66969. {
  66970. EXPECT_DECLS;
  66971. #if defined(HAVE_AES_CBC) || defined(HAVE_AESGCM) || \
  66972. defined(WOLFSSL_AES_COUNTER) || defined(HAVE_AES_ECB) || \
  66973. defined(WOLFSSL_AES_OFB) || !defined(NO_RC4) || \
  66974. (defined(HAVE_CHACHA) && defined(HAVE_POLY1305))
  66975. #ifdef HAVE_AES_CBC
  66976. #ifdef WOLFSSL_AES_128
  66977. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_cbc()), AES_BLOCK_SIZE);
  66978. #endif
  66979. #ifdef WOLFSSL_AES_192
  66980. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_cbc()), AES_BLOCK_SIZE);
  66981. #endif
  66982. #ifdef WOLFSSL_AES_256
  66983. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_cbc()), AES_BLOCK_SIZE);
  66984. #endif
  66985. #endif
  66986. #ifdef HAVE_AESGCM
  66987. #ifdef WOLFSSL_AES_128
  66988. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_gcm()), 1);
  66989. #endif
  66990. #ifdef WOLFSSL_AES_192
  66991. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_gcm()), 1);
  66992. #endif
  66993. #ifdef WOLFSSL_AES_256
  66994. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_gcm()), 1);
  66995. #endif
  66996. #endif
  66997. #ifdef HAVE_AESCCM
  66998. #ifdef WOLFSSL_AES_128
  66999. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_ccm()), 1);
  67000. #endif
  67001. #ifdef WOLFSSL_AES_192
  67002. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_ccm()), 1);
  67003. #endif
  67004. #ifdef WOLFSSL_AES_256
  67005. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_ccm()), 1);
  67006. #endif
  67007. #endif
  67008. #ifdef WOLFSSL_AES_COUNTER
  67009. #ifdef WOLFSSL_AES_128
  67010. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_ctr()), 1);
  67011. #endif
  67012. #ifdef WOLFSSL_AES_192
  67013. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_ctr()), 1);
  67014. #endif
  67015. #ifdef WOLFSSL_AES_256
  67016. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_ctr()), 1);
  67017. #endif
  67018. #endif
  67019. #ifdef HAVE_AES_ECB
  67020. #ifdef WOLFSSL_AES_128
  67021. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_ecb()), AES_BLOCK_SIZE);
  67022. #endif
  67023. #ifdef WOLFSSL_AES_192
  67024. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_ecb()), AES_BLOCK_SIZE);
  67025. #endif
  67026. #ifdef WOLFSSL_AES_256
  67027. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_ecb()), AES_BLOCK_SIZE);
  67028. #endif
  67029. #endif
  67030. #ifdef WOLFSSL_AES_OFB
  67031. #ifdef WOLFSSL_AES_128
  67032. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_128_ofb()), 1);
  67033. #endif
  67034. #ifdef WOLFSSL_AES_192
  67035. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_192_ofb()), 1);
  67036. #endif
  67037. #ifdef WOLFSSL_AES_256
  67038. ExpectIntEQ(EVP_CIPHER_block_size(EVP_aes_256_ofb()), 1);
  67039. #endif
  67040. #endif
  67041. #ifndef NO_RC4
  67042. ExpectIntEQ(EVP_CIPHER_block_size(wolfSSL_EVP_rc4()), 1);
  67043. #endif
  67044. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  67045. ExpectIntEQ(EVP_CIPHER_block_size(wolfSSL_EVP_chacha20_poly1305()), 1);
  67046. #endif
  67047. #endif
  67048. #ifdef WOLFSSL_SM4_ECB
  67049. ExpectIntEQ(EVP_CIPHER_block_size(EVP_sm4_ecb()), SM4_BLOCK_SIZE);
  67050. #endif
  67051. #ifdef WOLFSSL_SM4_CBC
  67052. ExpectIntEQ(EVP_CIPHER_block_size(EVP_sm4_cbc()), SM4_BLOCK_SIZE);
  67053. #endif
  67054. #ifdef WOLFSSL_SM4_CTR
  67055. ExpectIntEQ(EVP_CIPHER_block_size(EVP_sm4_ctr()), 1);
  67056. #endif
  67057. #ifdef WOLFSSL_SM4_GCM
  67058. ExpectIntEQ(EVP_CIPHER_block_size(EVP_sm4_gcm()), 1);
  67059. #endif
  67060. #ifdef WOLFSSL_SM4_CCM
  67061. ExpectIntEQ(EVP_CIPHER_block_size(EVP_sm4_ccm()), 1);
  67062. #endif
  67063. return EXPECT_RESULT();
  67064. }
  67065. static int test_wolfSSL_EVP_CIPHER_iv_length(void)
  67066. {
  67067. EXPECT_DECLS;
  67068. int nids[] = {
  67069. #if defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT)
  67070. #ifdef WOLFSSL_AES_128
  67071. NID_aes_128_cbc,
  67072. #endif
  67073. #ifdef WOLFSSL_AES_192
  67074. NID_aes_192_cbc,
  67075. #endif
  67076. #ifdef WOLFSSL_AES_256
  67077. NID_aes_256_cbc,
  67078. #endif
  67079. #endif /* HAVE_AES_CBC || WOLFSSL_AES_DIRECT */
  67080. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  67081. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  67082. #ifdef HAVE_AESGCM
  67083. #ifdef WOLFSSL_AES_128
  67084. NID_aes_128_gcm,
  67085. #endif
  67086. #ifdef WOLFSSL_AES_192
  67087. NID_aes_192_gcm,
  67088. #endif
  67089. #ifdef WOLFSSL_AES_256
  67090. NID_aes_256_gcm,
  67091. #endif
  67092. #endif /* HAVE_AESGCM */
  67093. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  67094. #ifdef WOLFSSL_AES_COUNTER
  67095. #ifdef WOLFSSL_AES_128
  67096. NID_aes_128_ctr,
  67097. #endif
  67098. #ifdef WOLFSSL_AES_192
  67099. NID_aes_192_ctr,
  67100. #endif
  67101. #ifdef WOLFSSL_AES_256
  67102. NID_aes_256_ctr,
  67103. #endif
  67104. #endif
  67105. #ifndef NO_DES3
  67106. NID_des_cbc,
  67107. NID_des_ede3_cbc,
  67108. #endif
  67109. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  67110. NID_chacha20_poly1305,
  67111. #endif
  67112. };
  67113. int iv_lengths[] = {
  67114. #if defined(HAVE_AES_CBC) || defined(WOLFSSL_AES_DIRECT)
  67115. #ifdef WOLFSSL_AES_128
  67116. AES_BLOCK_SIZE,
  67117. #endif
  67118. #ifdef WOLFSSL_AES_192
  67119. AES_BLOCK_SIZE,
  67120. #endif
  67121. #ifdef WOLFSSL_AES_256
  67122. AES_BLOCK_SIZE,
  67123. #endif
  67124. #endif /* HAVE_AES_CBC || WOLFSSL_AES_DIRECT */
  67125. #if (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)) || \
  67126. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  67127. #ifdef HAVE_AESGCM
  67128. #ifdef WOLFSSL_AES_128
  67129. GCM_NONCE_MID_SZ,
  67130. #endif
  67131. #ifdef WOLFSSL_AES_192
  67132. GCM_NONCE_MID_SZ,
  67133. #endif
  67134. #ifdef WOLFSSL_AES_256
  67135. GCM_NONCE_MID_SZ,
  67136. #endif
  67137. #endif /* HAVE_AESGCM */
  67138. #endif /* (HAVE_FIPS && !HAVE_SELFTEST) || HAVE_FIPS_VERSION > 2 */
  67139. #ifdef WOLFSSL_AES_COUNTER
  67140. #ifdef WOLFSSL_AES_128
  67141. AES_BLOCK_SIZE,
  67142. #endif
  67143. #ifdef WOLFSSL_AES_192
  67144. AES_BLOCK_SIZE,
  67145. #endif
  67146. #ifdef WOLFSSL_AES_256
  67147. AES_BLOCK_SIZE,
  67148. #endif
  67149. #endif
  67150. #ifndef NO_DES3
  67151. DES_BLOCK_SIZE,
  67152. DES_BLOCK_SIZE,
  67153. #endif
  67154. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  67155. CHACHA20_POLY1305_AEAD_IV_SIZE,
  67156. #endif
  67157. };
  67158. int i;
  67159. int nidsLen = (sizeof(nids)/sizeof(int));
  67160. for (i = 0; i < nidsLen; i++) {
  67161. const EVP_CIPHER *c = EVP_get_cipherbynid(nids[i]);
  67162. ExpectIntEQ(EVP_CIPHER_iv_length(c), iv_lengths[i]);
  67163. }
  67164. return EXPECT_RESULT();
  67165. }
  67166. static int test_wolfSSL_EVP_SignInit_ex(void)
  67167. {
  67168. EXPECT_DECLS;
  67169. WOLFSSL_EVP_MD_CTX mdCtx;
  67170. WOLFSSL_ENGINE* e = 0;
  67171. const EVP_MD* md = EVP_sha256();
  67172. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  67173. ExpectIntEQ(wolfSSL_EVP_SignInit_ex(&mdCtx, md, e), WOLFSSL_SUCCESS);
  67174. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  67175. return EXPECT_RESULT();
  67176. }
  67177. static int test_wolfSSL_EVP_DigestFinal_ex(void)
  67178. {
  67179. EXPECT_DECLS;
  67180. #if !defined(NO_SHA256)
  67181. WOLFSSL_EVP_MD_CTX mdCtx;
  67182. unsigned int s = 0;
  67183. unsigned char md[WC_SHA256_DIGEST_SIZE];
  67184. unsigned char md2[WC_SHA256_DIGEST_SIZE];
  67185. /* Bad Case */
  67186. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  67187. (HAVE_FIPS_VERSION > 2))
  67188. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  67189. ExpectIntEQ(wolfSSL_EVP_DigestFinal_ex(&mdCtx, md, &s), 0);
  67190. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
  67191. #else
  67192. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  67193. ExpectIntEQ(wolfSSL_EVP_DigestFinal_ex(&mdCtx, md, &s), WOLFSSL_SUCCESS);
  67194. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), WOLFSSL_SUCCESS);
  67195. #endif
  67196. /* Good Case */
  67197. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  67198. ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, EVP_sha256()), WOLFSSL_SUCCESS);
  67199. ExpectIntEQ(wolfSSL_EVP_DigestFinal_ex(&mdCtx, md2, &s), WOLFSSL_SUCCESS);
  67200. ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), WOLFSSL_SUCCESS);
  67201. #endif
  67202. return EXPECT_RESULT();
  67203. }
  67204. static int test_wolfSSL_QT_EVP_PKEY_CTX_free(void)
  67205. {
  67206. EXPECT_DECLS;
  67207. #if defined(OPENSSL_EXTRA)
  67208. EVP_PKEY* pkey = NULL;
  67209. EVP_PKEY_CTX* ctx = NULL;
  67210. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  67211. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  67212. #if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
  67213. /* void */
  67214. EVP_PKEY_CTX_free(ctx);
  67215. #else
  67216. /* int */
  67217. ExpectIntEQ(EVP_PKEY_CTX_free(ctx), WOLFSSL_SUCCESS);
  67218. #endif
  67219. EVP_PKEY_free(pkey);
  67220. #endif
  67221. return EXPECT_RESULT();
  67222. }
  67223. static int test_wolfSSL_EVP_PKEY_param_check(void)
  67224. {
  67225. EXPECT_DECLS;
  67226. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
  67227. #if !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA) && !defined(NO_FILESYSTEM)
  67228. DH *dh = NULL;
  67229. DH *setDh = NULL;
  67230. EVP_PKEY *pkey = NULL;
  67231. EVP_PKEY_CTX* ctx = NULL;
  67232. FILE* f = NULL;
  67233. unsigned char buf[512];
  67234. const unsigned char* pt = buf;
  67235. const char* dh2048 = "./certs/dh2048.der";
  67236. long len = 0;
  67237. int code = -1;
  67238. XMEMSET(buf, 0, sizeof(buf));
  67239. ExpectTrue((f = XFOPEN(dh2048, "rb")) != XBADFILE);
  67240. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  67241. if (f != XBADFILE)
  67242. XFCLOSE(f);
  67243. /* Load dh2048.der into DH with internal format */
  67244. ExpectNotNull(setDh = d2i_DHparams(NULL, &pt, len));
  67245. ExpectIntEQ(DH_check(setDh, &code), WOLFSSL_SUCCESS);
  67246. ExpectIntEQ(code, 0);
  67247. code = -1;
  67248. pkey = wolfSSL_EVP_PKEY_new();
  67249. /* Set DH into PKEY */
  67250. ExpectIntEQ(EVP_PKEY_set1_DH(pkey, setDh), WOLFSSL_SUCCESS);
  67251. /* create ctx from pkey */
  67252. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  67253. ExpectIntEQ(EVP_PKEY_param_check(ctx), 1/* valid */);
  67254. /* TODO: more invalid cases */
  67255. ExpectIntEQ(EVP_PKEY_param_check(NULL), 0);
  67256. EVP_PKEY_CTX_free(ctx);
  67257. EVP_PKEY_free(pkey);
  67258. DH_free(setDh);
  67259. setDh = NULL;
  67260. DH_free(dh);
  67261. dh = NULL;
  67262. #endif
  67263. #endif
  67264. return EXPECT_RESULT();
  67265. }
  67266. static int test_wolfSSL_EVP_BytesToKey(void)
  67267. {
  67268. EXPECT_DECLS;
  67269. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  67270. byte key[AES_BLOCK_SIZE] = {0};
  67271. byte iv[AES_BLOCK_SIZE] = {0};
  67272. int count = 0;
  67273. const EVP_MD* md = EVP_sha256();
  67274. const EVP_CIPHER *type;
  67275. const unsigned char *salt = (unsigned char *)"salt1234";
  67276. int sz = 5;
  67277. const byte data[] = {
  67278. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  67279. 0x72,0x6c,0x64
  67280. };
  67281. type = wolfSSL_EVP_get_cipherbynid(NID_aes_128_cbc);
  67282. /* Bad cases */
  67283. ExpectIntEQ(EVP_BytesToKey(NULL, md, salt, data, sz, count, key, iv),
  67284. 0);
  67285. ExpectIntEQ(EVP_BytesToKey(type, md, salt, NULL, sz, count, key, iv),
  67286. 16);
  67287. md = "2";
  67288. ExpectIntEQ(EVP_BytesToKey(type, md, salt, data, sz, count, key, iv),
  67289. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  67290. /* Good case */
  67291. md = EVP_sha256();
  67292. ExpectIntEQ(EVP_BytesToKey(type, md, salt, data, sz, count, key, iv),
  67293. 16);
  67294. #endif
  67295. return EXPECT_RESULT();
  67296. }
  67297. static int test_evp_cipher_aes_gcm(void)
  67298. {
  67299. EXPECT_DECLS;
  67300. #if defined(HAVE_AESGCM) && ((!defined(HAVE_FIPS) && \
  67301. !defined(HAVE_SELFTEST)) || (defined(HAVE_FIPS_VERSION) && \
  67302. (HAVE_FIPS_VERSION >= 2)))
  67303. /*
  67304. * This test checks data at various points in the encrypt/decrypt process
  67305. * against known values produced using the same test with OpenSSL. This
  67306. * interop testing is critical for verifying the correctness of our
  67307. * EVP_Cipher implementation with AES-GCM. Specifically, this test exercises
  67308. * a flow supported by OpenSSL that uses the control command
  67309. * EVP_CTRL_GCM_IV_GEN to increment the IV between cipher operations without
  67310. * the need to call EVP_CipherInit. OpenSSH uses this flow, for example. We
  67311. * had a bug with OpenSSH where wolfSSL OpenSSH servers could only talk to
  67312. * wolfSSL OpenSSH clients because there was a bug in this flow that
  67313. * happened to "cancel out" if both sides of the connection had the bug.
  67314. */
  67315. enum {
  67316. NUM_ENCRYPTIONS = 3,
  67317. AAD_SIZE = 4
  67318. };
  67319. byte plainText1[] = {
  67320. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
  67321. 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  67322. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23
  67323. };
  67324. byte plainText2[] = {
  67325. 0x42, 0x49, 0x3b, 0x27, 0x03, 0x35, 0x59, 0x14, 0x41, 0x47, 0x37, 0x14,
  67326. 0x0e, 0x34, 0x0d, 0x28, 0x63, 0x09, 0x0a, 0x5b, 0x22, 0x57, 0x42, 0x22,
  67327. 0x0f, 0x5c, 0x1e, 0x53, 0x45, 0x15, 0x62, 0x08, 0x60, 0x43, 0x50, 0x2c
  67328. };
  67329. byte plainText3[] = {
  67330. 0x36, 0x0d, 0x2b, 0x09, 0x4a, 0x56, 0x3b, 0x4c, 0x21, 0x22, 0x58, 0x0e,
  67331. 0x5b, 0x57, 0x10
  67332. };
  67333. byte* plainTexts[NUM_ENCRYPTIONS] = {
  67334. plainText1,
  67335. plainText2,
  67336. plainText3
  67337. };
  67338. const int plainTextSzs[NUM_ENCRYPTIONS] = {
  67339. sizeof(plainText1),
  67340. sizeof(plainText2),
  67341. sizeof(plainText3)
  67342. };
  67343. byte aad1[AAD_SIZE] = {
  67344. 0x00, 0x00, 0x00, 0x01
  67345. };
  67346. byte aad2[AAD_SIZE] = {
  67347. 0x00, 0x00, 0x00, 0x10
  67348. };
  67349. byte aad3[AAD_SIZE] = {
  67350. 0x00, 0x00, 0x01, 0x00
  67351. };
  67352. byte* aads[NUM_ENCRYPTIONS] = {
  67353. aad1,
  67354. aad2,
  67355. aad3
  67356. };
  67357. const byte iv[GCM_NONCE_MID_SZ] = {
  67358. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF
  67359. };
  67360. byte currentIv[GCM_NONCE_MID_SZ];
  67361. const byte key[] = {
  67362. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
  67363. 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  67364. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f
  67365. };
  67366. const byte expIvs[NUM_ENCRYPTIONS][GCM_NONCE_MID_SZ] = {
  67367. {
  67368. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE,
  67369. 0xEF
  67370. },
  67371. {
  67372. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE,
  67373. 0xF0
  67374. },
  67375. {
  67376. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE,
  67377. 0xF1
  67378. }
  67379. };
  67380. const byte expTags[NUM_ENCRYPTIONS][AES_BLOCK_SIZE] = {
  67381. {
  67382. 0x65, 0x4F, 0xF7, 0xA0, 0xBB, 0x7B, 0x90, 0xB7, 0x9C, 0xC8, 0x14,
  67383. 0x3D, 0x32, 0x18, 0x34, 0xA9
  67384. },
  67385. {
  67386. 0x50, 0x3A, 0x13, 0x8D, 0x91, 0x1D, 0xEC, 0xBB, 0xBA, 0x5B, 0x57,
  67387. 0xA2, 0xFD, 0x2D, 0x6B, 0x7F
  67388. },
  67389. {
  67390. 0x3B, 0xED, 0x18, 0x9C, 0xB3, 0xE3, 0x61, 0x1E, 0x11, 0xEB, 0x13,
  67391. 0x5B, 0xEC, 0x52, 0x49, 0x32,
  67392. }
  67393. };
  67394. const byte expCipherText1[] = {
  67395. 0xCB, 0x93, 0x4F, 0xC8, 0x22, 0xE2, 0xC0, 0x35, 0xAA, 0x6B, 0x41, 0x15,
  67396. 0x17, 0x30, 0x2F, 0x97, 0x20, 0x74, 0x39, 0x28, 0xF8, 0xEB, 0xC5, 0x51,
  67397. 0x7B, 0xD9, 0x8A, 0x36, 0xB8, 0xDA, 0x24, 0x80, 0xE7, 0x9E, 0x09, 0xDE
  67398. };
  67399. const byte expCipherText2[] = {
  67400. 0xF9, 0x32, 0xE1, 0x87, 0x37, 0x0F, 0x04, 0xC1, 0xB5, 0x59, 0xF0, 0x45,
  67401. 0x3A, 0x0D, 0xA0, 0x26, 0xFF, 0xA6, 0x8D, 0x38, 0xFE, 0xB8, 0xE5, 0xC2,
  67402. 0x2A, 0x98, 0x4A, 0x54, 0x8F, 0x1F, 0xD6, 0x13, 0x03, 0xB2, 0x1B, 0xC0
  67403. };
  67404. const byte expCipherText3[] = {
  67405. 0xD0, 0x37, 0x59, 0x1C, 0x2F, 0x85, 0x39, 0x4D, 0xED, 0xC2, 0x32, 0x5B,
  67406. 0x80, 0x5E, 0x6B,
  67407. };
  67408. const byte* expCipherTexts[NUM_ENCRYPTIONS] = {
  67409. expCipherText1,
  67410. expCipherText2,
  67411. expCipherText3
  67412. };
  67413. byte* cipherText = NULL;
  67414. byte* calcPlainText = NULL;
  67415. byte tag[AES_BLOCK_SIZE];
  67416. EVP_CIPHER_CTX* encCtx = NULL;
  67417. EVP_CIPHER_CTX* decCtx = NULL;
  67418. int i, j, outl;
  67419. /****************************************************/
  67420. for (i = 0; i < 3; ++i) {
  67421. ExpectNotNull(encCtx = EVP_CIPHER_CTX_new());
  67422. ExpectNotNull(decCtx = EVP_CIPHER_CTX_new());
  67423. /* First iteration, set key before IV. */
  67424. if (i == 0) {
  67425. ExpectIntEQ(EVP_CipherInit(encCtx, EVP_aes_256_gcm(), key, NULL, 1),
  67426. SSL_SUCCESS);
  67427. /*
  67428. * The call to EVP_CipherInit below (with NULL key) should clear the
  67429. * authIvGenEnable flag set by EVP_CTRL_GCM_SET_IV_FIXED. As such, a
  67430. * subsequent EVP_CTRL_GCM_IV_GEN should fail. This matches OpenSSL
  67431. * behavior.
  67432. */
  67433. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_SET_IV_FIXED, -1,
  67434. (void*)iv), SSL_SUCCESS);
  67435. ExpectIntEQ(EVP_CipherInit(encCtx, NULL, NULL, iv, 1),
  67436. SSL_SUCCESS);
  67437. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_IV_GEN, -1,
  67438. currentIv), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  67439. ExpectIntEQ(EVP_CipherInit(decCtx, EVP_aes_256_gcm(), key, NULL, 0),
  67440. SSL_SUCCESS);
  67441. ExpectIntEQ(EVP_CipherInit(decCtx, NULL, NULL, iv, 0),
  67442. SSL_SUCCESS);
  67443. }
  67444. /* Second iteration, IV before key. */
  67445. else {
  67446. ExpectIntEQ(EVP_CipherInit(encCtx, EVP_aes_256_gcm(), NULL, iv, 1),
  67447. SSL_SUCCESS);
  67448. ExpectIntEQ(EVP_CipherInit(encCtx, NULL, key, NULL, 1),
  67449. SSL_SUCCESS);
  67450. ExpectIntEQ(EVP_CipherInit(decCtx, EVP_aes_256_gcm(), NULL, iv, 0),
  67451. SSL_SUCCESS);
  67452. ExpectIntEQ(EVP_CipherInit(decCtx, NULL, key, NULL, 0),
  67453. SSL_SUCCESS);
  67454. }
  67455. /*
  67456. * EVP_CTRL_GCM_IV_GEN should fail if EVP_CTRL_GCM_SET_IV_FIXED hasn't
  67457. * been issued first.
  67458. */
  67459. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_IV_GEN, -1,
  67460. currentIv), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  67461. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_SET_IV_FIXED, -1,
  67462. (void*)iv), SSL_SUCCESS);
  67463. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(decCtx, EVP_CTRL_GCM_SET_IV_FIXED, -1,
  67464. (void*)iv), SSL_SUCCESS);
  67465. for (j = 0; j < NUM_ENCRYPTIONS; ++j) {
  67466. /*************** Encrypt ***************/
  67467. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_IV_GEN, -1,
  67468. currentIv), SSL_SUCCESS);
  67469. /* Check current IV against expected. */
  67470. ExpectIntEQ(XMEMCMP(currentIv, expIvs[j], GCM_NONCE_MID_SZ), 0);
  67471. /* Add AAD. */
  67472. if (i == 2) {
  67473. /* Test streaming API. */
  67474. ExpectIntEQ(EVP_CipherUpdate(encCtx, NULL, &outl, aads[j],
  67475. AAD_SIZE), SSL_SUCCESS);
  67476. }
  67477. else {
  67478. ExpectIntEQ(EVP_Cipher(encCtx, NULL, aads[j], AAD_SIZE),
  67479. AAD_SIZE);
  67480. }
  67481. ExpectNotNull(cipherText = (byte*)XMALLOC(plainTextSzs[j], NULL,
  67482. DYNAMIC_TYPE_TMP_BUFFER));
  67483. /* Encrypt plaintext. */
  67484. if (i == 2) {
  67485. ExpectIntEQ(EVP_CipherUpdate(encCtx, cipherText, &outl,
  67486. plainTexts[j], plainTextSzs[j]),
  67487. SSL_SUCCESS);
  67488. }
  67489. else {
  67490. ExpectIntEQ(EVP_Cipher(encCtx, cipherText, plainTexts[j],
  67491. plainTextSzs[j]), plainTextSzs[j]);
  67492. }
  67493. if (i == 2) {
  67494. ExpectIntEQ(EVP_CipherFinal(encCtx, cipherText, &outl),
  67495. SSL_SUCCESS);
  67496. }
  67497. else {
  67498. /*
  67499. * Calling EVP_Cipher with NULL input and output for AES-GCM is
  67500. * akin to calling EVP_CipherFinal.
  67501. */
  67502. ExpectIntGE(EVP_Cipher(encCtx, NULL, NULL, 0), 0);
  67503. }
  67504. /* Check ciphertext against expected. */
  67505. ExpectIntEQ(XMEMCMP(cipherText, expCipherTexts[j], plainTextSzs[j]),
  67506. 0);
  67507. /* Get and check tag against expected. */
  67508. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(encCtx, EVP_CTRL_GCM_GET_TAG,
  67509. sizeof(tag), tag), SSL_SUCCESS);
  67510. ExpectIntEQ(XMEMCMP(tag, expTags[j], sizeof(tag)), 0);
  67511. /*************** Decrypt ***************/
  67512. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(decCtx, EVP_CTRL_GCM_IV_GEN, -1,
  67513. currentIv), SSL_SUCCESS);
  67514. /* Check current IV against expected. */
  67515. ExpectIntEQ(XMEMCMP(currentIv, expIvs[j], GCM_NONCE_MID_SZ), 0);
  67516. /* Add AAD. */
  67517. if (i == 2) {
  67518. /* Test streaming API. */
  67519. ExpectIntEQ(EVP_CipherUpdate(decCtx, NULL, &outl, aads[j],
  67520. AAD_SIZE), SSL_SUCCESS);
  67521. }
  67522. else {
  67523. ExpectIntEQ(EVP_Cipher(decCtx, NULL, aads[j], AAD_SIZE),
  67524. AAD_SIZE);
  67525. }
  67526. /* Set expected tag. */
  67527. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(decCtx, EVP_CTRL_GCM_SET_TAG,
  67528. sizeof(tag), tag), SSL_SUCCESS);
  67529. /* Decrypt ciphertext. */
  67530. ExpectNotNull(calcPlainText = (byte*)XMALLOC(plainTextSzs[j], NULL,
  67531. DYNAMIC_TYPE_TMP_BUFFER));
  67532. if (i == 2) {
  67533. ExpectIntEQ(EVP_CipherUpdate(decCtx, calcPlainText, &outl,
  67534. cipherText, plainTextSzs[j]),
  67535. SSL_SUCCESS);
  67536. }
  67537. else {
  67538. /* This first EVP_Cipher call will check the tag, too. */
  67539. ExpectIntEQ(EVP_Cipher(decCtx, calcPlainText, cipherText,
  67540. plainTextSzs[j]), plainTextSzs[j]);
  67541. }
  67542. if (i == 2) {
  67543. ExpectIntEQ(EVP_CipherFinal(decCtx, calcPlainText, &outl),
  67544. SSL_SUCCESS);
  67545. }
  67546. else {
  67547. ExpectIntGE(EVP_Cipher(decCtx, NULL, NULL, 0), 0);
  67548. }
  67549. /* Check plaintext against expected. */
  67550. ExpectIntEQ(XMEMCMP(calcPlainText, plainTexts[j], plainTextSzs[j]),
  67551. 0);
  67552. XFREE(cipherText, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  67553. cipherText = NULL;
  67554. XFREE(calcPlainText, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  67555. calcPlainText = NULL;
  67556. }
  67557. EVP_CIPHER_CTX_free(encCtx);
  67558. encCtx = NULL;
  67559. EVP_CIPHER_CTX_free(decCtx);
  67560. decCtx = NULL;
  67561. }
  67562. #endif
  67563. return EXPECT_RESULT();
  67564. }
  67565. static int test_wolfSSL_OBJ_ln(void)
  67566. {
  67567. EXPECT_DECLS;
  67568. const int nid_set[] = {
  67569. NID_commonName,
  67570. NID_serialNumber,
  67571. NID_countryName,
  67572. NID_localityName,
  67573. NID_stateOrProvinceName,
  67574. NID_organizationName,
  67575. NID_organizationalUnitName,
  67576. NID_domainComponent,
  67577. NID_businessCategory,
  67578. NID_jurisdictionCountryName,
  67579. NID_jurisdictionStateOrProvinceName,
  67580. NID_emailAddress
  67581. };
  67582. const char* ln_set[] = {
  67583. "commonName",
  67584. "serialNumber",
  67585. "countryName",
  67586. "localityName",
  67587. "stateOrProvinceName",
  67588. "organizationName",
  67589. "organizationalUnitName",
  67590. "domainComponent",
  67591. "businessCategory",
  67592. "jurisdictionCountryName",
  67593. "jurisdictionStateOrProvinceName",
  67594. "emailAddress",
  67595. };
  67596. size_t i = 0, maxIdx = sizeof(ln_set)/sizeof(char*);
  67597. ExpectIntEQ(OBJ_ln2nid(NULL), NID_undef);
  67598. #ifdef HAVE_ECC
  67599. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  67600. {
  67601. EC_builtin_curve r[27];
  67602. size_t nCurves = sizeof(r) / sizeof(r[0]);
  67603. nCurves = EC_get_builtin_curves(r, nCurves);
  67604. for (i = 0; i < nCurves; i++) {
  67605. /* skip ECC_CURVE_INVALID */
  67606. if (r[i].nid != ECC_CURVE_INVALID) {
  67607. ExpectIntEQ(OBJ_ln2nid(r[i].comment), r[i].nid);
  67608. ExpectStrEQ(OBJ_nid2ln(r[i].nid), r[i].comment);
  67609. }
  67610. }
  67611. }
  67612. #endif
  67613. #endif
  67614. for (i = 0; i < maxIdx; i++) {
  67615. ExpectIntEQ(OBJ_ln2nid(ln_set[i]), nid_set[i]);
  67616. ExpectStrEQ(OBJ_nid2ln(nid_set[i]), ln_set[i]);
  67617. }
  67618. return EXPECT_RESULT();
  67619. }
  67620. static int test_wolfSSL_OBJ_sn(void)
  67621. {
  67622. EXPECT_DECLS;
  67623. int i = 0, maxIdx = 7;
  67624. const int nid_set[] = {NID_commonName,NID_countryName,NID_localityName,
  67625. NID_stateOrProvinceName,NID_organizationName,
  67626. NID_organizationalUnitName,NID_emailAddress};
  67627. const char* sn_open_set[] = {"CN","C","L","ST","O","OU","emailAddress"};
  67628. const char* sn_wolf_set[] = {WOLFSSL_COMMON_NAME,WOLFSSL_COUNTRY_NAME,
  67629. WOLFSSL_LOCALITY_NAME, WOLFSSL_STATE_NAME,
  67630. WOLFSSL_ORG_NAME, WOLFSSL_ORGUNIT_NAME,
  67631. WOLFSSL_EMAIL_ADDR};
  67632. ExpectIntEQ(wolfSSL_OBJ_sn2nid(NULL), NID_undef);
  67633. for (i = 0; i < maxIdx; i++) {
  67634. ExpectIntEQ(wolfSSL_OBJ_sn2nid(sn_wolf_set[i]), nid_set[i]);
  67635. ExpectStrEQ(wolfSSL_OBJ_nid2sn(nid_set[i]), sn_open_set[i]);
  67636. }
  67637. return EXPECT_RESULT();
  67638. }
  67639. #if !defined(NO_BIO)
  67640. static word32 TXT_DB_hash(const WOLFSSL_STRING *s)
  67641. {
  67642. return (word32)lh_strhash(s[3]);
  67643. }
  67644. static int TXT_DB_cmp(const WOLFSSL_STRING *a, const WOLFSSL_STRING *b)
  67645. {
  67646. return XSTRCMP(a[3], b[3]);
  67647. }
  67648. #endif
  67649. static int test_wolfSSL_TXT_DB(void)
  67650. {
  67651. EXPECT_DECLS;
  67652. #if !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  67653. BIO *bio = NULL;
  67654. TXT_DB *db = NULL;
  67655. const int columns = 6;
  67656. const char *fields[6] = {
  67657. "V",
  67658. "320926161116Z",
  67659. "",
  67660. "12BD",
  67661. "unknown",
  67662. "/CN=rsa doe",
  67663. };
  67664. char** fields_copy = NULL;
  67665. /* Test read */
  67666. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  67667. ExpectIntGT(BIO_read_filename(bio, "./tests/TXT_DB.txt"), 0);
  67668. ExpectNotNull(db = TXT_DB_read(bio, columns));
  67669. ExpectNotNull(fields_copy = (char**)XMALLOC(sizeof(fields), NULL,
  67670. DYNAMIC_TYPE_OPENSSL));
  67671. if (fields_copy != NULL) {
  67672. XMEMCPY(fields_copy, fields, sizeof(fields));
  67673. }
  67674. ExpectIntEQ(TXT_DB_insert(db, fields_copy), 1);
  67675. if (EXPECT_FAIL()) {
  67676. XFREE(fields_copy, NULL, DYNAMIC_TYPE_OPENSSL);
  67677. }
  67678. BIO_free(bio);
  67679. bio = NULL;
  67680. /* Test write */
  67681. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  67682. ExpectIntEQ(TXT_DB_write(bio, db), 1484);
  67683. BIO_free(bio);
  67684. /* Test index */
  67685. ExpectIntEQ(TXT_DB_create_index(db, 3, NULL,
  67686. (wolf_sk_hash_cb)(long unsigned int)TXT_DB_hash,
  67687. (wolf_lh_compare_cb)TXT_DB_cmp), 1);
  67688. ExpectNotNull(TXT_DB_get_by_index(db, 3, (WOLFSSL_STRING*)fields));
  67689. fields[3] = "12DA";
  67690. ExpectNotNull(TXT_DB_get_by_index(db, 3, (WOLFSSL_STRING*)fields));
  67691. fields[3] = "FFFF";
  67692. ExpectNull(TXT_DB_get_by_index(db, 3, (WOLFSSL_STRING*)fields));
  67693. fields[3] = "";
  67694. ExpectNull(TXT_DB_get_by_index(db, 3, (WOLFSSL_STRING*)fields));
  67695. TXT_DB_free(db);
  67696. #endif
  67697. return EXPECT_RESULT();
  67698. }
  67699. static int test_wolfSSL_NCONF(void)
  67700. {
  67701. EXPECT_DECLS;
  67702. #if !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  67703. const char* confFile = "./tests/NCONF_test.cnf";
  67704. CONF* conf = NULL;
  67705. long eline = 0;
  67706. long num = 0;
  67707. ExpectNotNull(conf = NCONF_new(NULL));
  67708. ExpectIntEQ(NCONF_load(conf, confFile, &eline), 1);
  67709. ExpectIntEQ(NCONF_get_number(conf, NULL, "port", &num), 1);
  67710. ExpectIntEQ(num, 1234);
  67711. ExpectIntEQ(NCONF_get_number(conf, "section2", "port", &num), 1);
  67712. ExpectIntEQ(num, 4321);
  67713. ExpectStrEQ(NCONF_get_string(conf, NULL, "dir"), "./test-dir");
  67714. ExpectStrEQ(NCONF_get_string(conf, "section1", "file1_copy"),
  67715. "./test-dir/file1");
  67716. ExpectStrEQ(NCONF_get_string(conf, "section2", "file_list"),
  67717. "./test-dir/file1:./test-dir/file2:./section1:file2");
  67718. NCONF_free(conf);
  67719. #endif
  67720. return EXPECT_RESULT();
  67721. }
  67722. #endif /* OPENSSL_ALL */
  67723. static int test_wolfSSL_X509V3_EXT_get(void) {
  67724. EXPECT_DECLS;
  67725. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  67726. XFILE f = XBADFILE;
  67727. int numOfExt =0;
  67728. int extNid = 0;
  67729. int i = 0;
  67730. WOLFSSL_X509* x509 = NULL;
  67731. WOLFSSL_X509_EXTENSION* ext = NULL;
  67732. const WOLFSSL_v3_ext_method* method = NULL;
  67733. ExpectTrue((f = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  67734. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  67735. if (f != XBADFILE)
  67736. XFCLOSE(f);
  67737. /* wolfSSL_X509V3_EXT_get() return struct and nid test */
  67738. ExpectIntEQ((numOfExt = wolfSSL_X509_get_ext_count(x509)), 5);
  67739. for (i = 0; i < numOfExt; i++) {
  67740. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  67741. ExpectIntNE((extNid = ext->obj->nid), NID_undef);
  67742. ExpectNotNull(method = wolfSSL_X509V3_EXT_get(ext));
  67743. ExpectIntEQ(method->ext_nid, extNid);
  67744. }
  67745. /* wolfSSL_X509V3_EXT_get() NULL argument test */
  67746. ExpectNull(method = wolfSSL_X509V3_EXT_get(NULL));
  67747. wolfSSL_X509_free(x509);
  67748. #endif
  67749. return EXPECT_RESULT();
  67750. }
  67751. static int test_wolfSSL_X509V3_EXT_nconf(void)
  67752. {
  67753. EXPECT_DECLS;
  67754. #ifdef OPENSSL_ALL
  67755. const char *ext_names[] = {
  67756. "subjectKeyIdentifier",
  67757. "authorityKeyIdentifier",
  67758. "subjectAltName",
  67759. "keyUsage",
  67760. "extendedKeyUsage",
  67761. };
  67762. size_t ext_names_count = sizeof(ext_names)/sizeof(*ext_names);
  67763. int ext_nids[] = {
  67764. NID_subject_key_identifier,
  67765. NID_authority_key_identifier,
  67766. NID_subject_alt_name,
  67767. NID_key_usage,
  67768. NID_ext_key_usage,
  67769. };
  67770. size_t ext_nids_count = sizeof(ext_nids)/sizeof(*ext_nids);
  67771. const char *ext_values[] = {
  67772. "hash",
  67773. "hash",
  67774. "DNS:example.com, IP:127.0.0.1",
  67775. "digitalSignature,nonRepudiation,keyEncipherment,dataEncipherment,"
  67776. "keyAgreement,keyCertSign,cRLSign,encipherOnly,decipherOnly",
  67777. "serverAuth,clientAuth,codeSigning,emailProtection,timeStamping,"
  67778. "OCSPSigning",
  67779. };
  67780. size_t i;
  67781. X509_EXTENSION* ext = NULL;
  67782. X509* x509 = NULL;
  67783. unsigned int keyUsageFlags;
  67784. unsigned int extKeyUsageFlags;
  67785. ExpectNotNull(x509 = X509_new());
  67786. /* keyUsage / extKeyUsage should match string above */
  67787. keyUsageFlags = KU_DIGITAL_SIGNATURE
  67788. | KU_NON_REPUDIATION
  67789. | KU_KEY_ENCIPHERMENT
  67790. | KU_DATA_ENCIPHERMENT
  67791. | KU_KEY_AGREEMENT
  67792. | KU_KEY_CERT_SIGN
  67793. | KU_CRL_SIGN
  67794. | KU_ENCIPHER_ONLY
  67795. | KU_DECIPHER_ONLY;
  67796. extKeyUsageFlags = XKU_SSL_CLIENT
  67797. | XKU_SSL_SERVER
  67798. | XKU_CODE_SIGN
  67799. | XKU_SMIME
  67800. | XKU_TIMESTAMP
  67801. | XKU_OCSP_SIGN;
  67802. for (i = 0; i < ext_names_count; i++) {
  67803. ExpectNotNull(ext = X509V3_EXT_nconf(NULL, NULL, ext_names[i],
  67804. ext_values[i]));
  67805. X509_EXTENSION_free(ext);
  67806. ext = NULL;
  67807. }
  67808. for (i = 0; i < ext_nids_count; i++) {
  67809. ExpectNotNull(ext = X509V3_EXT_nconf_nid(NULL, NULL, ext_nids[i],
  67810. ext_values[i]));
  67811. X509_EXTENSION_free(ext);
  67812. ext = NULL;
  67813. }
  67814. /* Test adding extension to X509 */
  67815. for (i = 0; i < ext_nids_count; i++) {
  67816. ExpectNotNull(ext = X509V3_EXT_nconf(NULL, NULL, ext_names[i],
  67817. ext_values[i]));
  67818. ExpectIntEQ(X509_add_ext(x509, ext, -1), WOLFSSL_SUCCESS);
  67819. if (ext_nids[i] == NID_key_usage) {
  67820. ExpectIntEQ(X509_get_key_usage(x509), keyUsageFlags);
  67821. }
  67822. else if (ext_nids[i] == NID_ext_key_usage) {
  67823. ExpectIntEQ(X509_get_extended_key_usage(x509), extKeyUsageFlags);
  67824. }
  67825. X509_EXTENSION_free(ext);
  67826. ext = NULL;
  67827. }
  67828. X509_free(x509);
  67829. #endif
  67830. return EXPECT_RESULT();
  67831. }
  67832. static int test_wolfSSL_X509V3_EXT(void) {
  67833. EXPECT_DECLS;
  67834. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  67835. XFILE f = XBADFILE;
  67836. int numOfExt = 0, nid = 0, i = 0, expected, actual = 0;
  67837. char* str = NULL;
  67838. unsigned char* data = NULL;
  67839. const WOLFSSL_v3_ext_method* method = NULL;
  67840. WOLFSSL_X509* x509 = NULL;
  67841. WOLFSSL_X509_EXTENSION* ext = NULL;
  67842. WOLFSSL_X509_EXTENSION* ext2 = NULL;
  67843. WOLFSSL_ASN1_OBJECT *obj = NULL;
  67844. WOLFSSL_ASN1_OBJECT *adObj = NULL;
  67845. WOLFSSL_ASN1_STRING* asn1str = NULL;
  67846. WOLFSSL_AUTHORITY_KEYID* aKeyId = NULL;
  67847. WOLFSSL_AUTHORITY_INFO_ACCESS* aia = NULL;
  67848. WOLFSSL_BASIC_CONSTRAINTS* bc = NULL;
  67849. WOLFSSL_ACCESS_DESCRIPTION* ad = NULL;
  67850. WOLFSSL_GENERAL_NAME* gn = NULL;
  67851. /* Check NULL argument */
  67852. ExpectNull(wolfSSL_X509V3_EXT_d2i(NULL));
  67853. /* Using OCSP cert with X509V3 extensions */
  67854. ExpectTrue((f = XFOPEN("./certs/ocsp/root-ca-cert.pem", "rb")) != XBADFILE);
  67855. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  67856. if (f != XBADFILE)
  67857. XFCLOSE(f);
  67858. ExpectIntEQ((numOfExt = wolfSSL_X509_get_ext_count(x509)), 5);
  67859. /* Basic Constraints */
  67860. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  67861. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(ext));
  67862. ExpectIntEQ((nid = wolfSSL_OBJ_obj2nid(obj)), NID_basic_constraints);
  67863. ExpectNotNull(bc = (WOLFSSL_BASIC_CONSTRAINTS*)wolfSSL_X509V3_EXT_d2i(ext));
  67864. ExpectIntEQ(bc->ca, 1);
  67865. ExpectNull(bc->pathlen);
  67866. wolfSSL_BASIC_CONSTRAINTS_free(bc);
  67867. bc = NULL;
  67868. i++;
  67869. /* Subject Key Identifier */
  67870. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  67871. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(ext));
  67872. ExpectIntEQ((nid = wolfSSL_OBJ_obj2nid(obj)), NID_subject_key_identifier);
  67873. ExpectNotNull(asn1str = (WOLFSSL_ASN1_STRING*)wolfSSL_X509V3_EXT_d2i(ext));
  67874. ExpectNotNull(ext2 = wolfSSL_X509V3_EXT_i2d(NID_subject_key_identifier, 0,
  67875. asn1str));
  67876. X509_EXTENSION_free(ext2);
  67877. ext2 = NULL;
  67878. ExpectNotNull(method = wolfSSL_X509V3_EXT_get(ext));
  67879. ExpectNotNull(method->i2s);
  67880. ExpectNotNull(str = method->i2s((WOLFSSL_v3_ext_method*)method, asn1str));
  67881. wolfSSL_ASN1_STRING_free(asn1str);
  67882. asn1str = NULL;
  67883. if (str != NULL) {
  67884. actual = strcmp(str,
  67885. "73:B0:1C:A4:2F:82:CB:CF:47:A5:38:D7:B0:04:82:3A:7E:72:15:21");
  67886. }
  67887. ExpectIntEQ(actual, 0);
  67888. XFREE(str, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  67889. str = NULL;
  67890. i++;
  67891. /* Authority Key Identifier */
  67892. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  67893. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(ext));
  67894. ExpectIntEQ((nid = wolfSSL_OBJ_obj2nid(obj)), NID_authority_key_identifier);
  67895. ExpectNotNull(aKeyId = (WOLFSSL_AUTHORITY_KEYID*)wolfSSL_X509V3_EXT_d2i(
  67896. ext));
  67897. ExpectNotNull(method = wolfSSL_X509V3_EXT_get(ext));
  67898. ExpectNotNull(asn1str = aKeyId->keyid);
  67899. ExpectNotNull(str = wolfSSL_i2s_ASN1_STRING((WOLFSSL_v3_ext_method*)method,
  67900. asn1str));
  67901. asn1str = NULL;
  67902. if (str != NULL) {
  67903. actual = strcmp(str,
  67904. "73:B0:1C:A4:2F:82:CB:CF:47:A5:38:D7:B0:04:82:3A:7E:72:15:21");
  67905. }
  67906. ExpectIntEQ(actual, 0);
  67907. XFREE(str, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  67908. str = NULL;
  67909. wolfSSL_AUTHORITY_KEYID_free(aKeyId);
  67910. aKeyId = NULL;
  67911. i++;
  67912. /* Key Usage */
  67913. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  67914. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(ext));
  67915. ExpectIntEQ((nid = wolfSSL_OBJ_obj2nid(obj)), NID_key_usage);
  67916. ExpectNotNull(asn1str = (WOLFSSL_ASN1_STRING*)wolfSSL_X509V3_EXT_d2i(ext));
  67917. #if defined(WOLFSSL_QT)
  67918. ExpectNotNull(data = (unsigned char*)ASN1_STRING_get0_data(asn1str));
  67919. #else
  67920. ExpectNotNull(data = wolfSSL_ASN1_STRING_data(asn1str));
  67921. #endif
  67922. expected = KEYUSE_KEY_CERT_SIGN | KEYUSE_CRL_SIGN;
  67923. if (data != NULL) {
  67924. #ifdef BIG_ENDIAN_ORDER
  67925. actual = data[1];
  67926. #else
  67927. actual = data[0];
  67928. #endif
  67929. }
  67930. ExpectIntEQ(actual, expected);
  67931. wolfSSL_ASN1_STRING_free(asn1str);
  67932. asn1str = NULL;
  67933. #if 1
  67934. i++;
  67935. /* Authority Info Access */
  67936. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, i));
  67937. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(ext));
  67938. ExpectIntEQ((nid = wolfSSL_OBJ_obj2nid(obj)), NID_info_access);
  67939. ExpectNotNull(aia = (WOLFSSL_AUTHORITY_INFO_ACCESS*)wolfSSL_X509V3_EXT_d2i(
  67940. ext));
  67941. #if defined(WOLFSSL_QT)
  67942. ExpectIntEQ(OPENSSL_sk_num(aia), 1); /* Only one URI entry for this cert */
  67943. #else
  67944. ExpectIntEQ(wolfSSL_sk_num(aia), 1); /* Only one URI entry for this cert */
  67945. #endif
  67946. /* URI entry is an ACCESS_DESCRIPTION type */
  67947. #if defined(WOLFSSL_QT)
  67948. ExpectNotNull(ad = (WOLFSSL_ACCESS_DESCRIPTION*)wolfSSL_sk_value(aia, 0));
  67949. #else
  67950. ExpectNotNull(ad = (WOLFSSL_ACCESS_DESCRIPTION*)OPENSSL_sk_value(aia, 0));
  67951. #endif
  67952. ExpectNotNull(adObj = ad->method);
  67953. /* Make sure nid is OCSP */
  67954. ExpectIntEQ(wolfSSL_OBJ_obj2nid(adObj), NID_ad_OCSP);
  67955. /* GENERAL_NAME stores URI as an ASN1_STRING */
  67956. ExpectNotNull(gn = ad->location);
  67957. ExpectIntEQ(gn->type, GEN_URI); /* Type should always be GEN_URI */
  67958. ExpectNotNull(asn1str = gn->d.uniformResourceIdentifier);
  67959. ExpectIntEQ(wolfSSL_ASN1_STRING_length(asn1str), 22);
  67960. #if defined(WOLFSSL_QT)
  67961. ExpectNotNull(str = (char*)ASN1_STRING_get0_data(asn1str));
  67962. #else
  67963. ExpectNotNull(str = (char*)wolfSSL_ASN1_STRING_data(asn1str));
  67964. #endif
  67965. if (str != NULL) {
  67966. actual = strcmp(str, "http://127.0.0.1:22220");
  67967. }
  67968. ExpectIntEQ(actual, 0);
  67969. wolfSSL_sk_ACCESS_DESCRIPTION_pop_free(aia, NULL);
  67970. aia = NULL;
  67971. #else
  67972. (void) aia; (void) ad; (void) adObj; (void) gn;
  67973. #endif
  67974. wolfSSL_X509_free(x509);
  67975. #endif
  67976. return EXPECT_RESULT();
  67977. }
  67978. static int test_wolfSSL_X509_get_extension_flags(void)
  67979. {
  67980. EXPECT_DECLS;
  67981. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  67982. XFILE f = XBADFILE;
  67983. X509* x509 = NULL;
  67984. unsigned int extFlags;
  67985. unsigned int keyUsageFlags;
  67986. unsigned int extKeyUsageFlags;
  67987. /* client-int-cert.pem has the following extension flags. */
  67988. extFlags = EXFLAG_KUSAGE | EXFLAG_XKUSAGE;
  67989. /* and the following key usage flags. */
  67990. keyUsageFlags = KU_DIGITAL_SIGNATURE
  67991. | KU_NON_REPUDIATION
  67992. | KU_KEY_ENCIPHERMENT;
  67993. /* and the following extended key usage flags. */
  67994. extKeyUsageFlags = XKU_SSL_CLIENT | XKU_SMIME;
  67995. ExpectTrue((f = XFOPEN("./certs/intermediate/client-int-cert.pem", "rb")) !=
  67996. XBADFILE);
  67997. ExpectNotNull(x509 = PEM_read_X509(f, NULL, NULL, NULL));
  67998. if (f != XBADFILE) {
  67999. XFCLOSE(f);
  68000. f = XBADFILE;
  68001. }
  68002. ExpectIntEQ(X509_get_extension_flags(x509), extFlags);
  68003. ExpectIntEQ(X509_get_key_usage(x509), keyUsageFlags);
  68004. ExpectIntEQ(X509_get_extended_key_usage(x509), extKeyUsageFlags);
  68005. X509_free(x509);
  68006. x509 = NULL;
  68007. /* client-cert-ext.pem has the following extension flags. */
  68008. extFlags = EXFLAG_KUSAGE;
  68009. /* and the following key usage flags. */
  68010. keyUsageFlags = KU_DIGITAL_SIGNATURE
  68011. | KU_KEY_CERT_SIGN
  68012. | KU_CRL_SIGN;
  68013. ExpectTrue((f = fopen("./certs/client-cert-ext.pem", "rb")) != XBADFILE);
  68014. ExpectNotNull(x509 = PEM_read_X509(f, NULL, NULL, NULL));
  68015. if (f != XBADFILE)
  68016. XFCLOSE(f);
  68017. ExpectIntEQ(X509_get_extension_flags(x509), extFlags);
  68018. ExpectIntEQ(X509_get_key_usage(x509), keyUsageFlags);
  68019. X509_free(x509);
  68020. #endif /* OPENSSL_ALL */
  68021. return EXPECT_RESULT();
  68022. }
  68023. static int test_wolfSSL_X509_get_ext(void)
  68024. {
  68025. EXPECT_DECLS;
  68026. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  68027. int ret = 0;
  68028. XFILE f = XBADFILE;
  68029. WOLFSSL_X509* x509 = NULL;
  68030. WOLFSSL_X509_EXTENSION* foundExtension;
  68031. ExpectTrue((f = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  68032. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  68033. if (f != XBADFILE)
  68034. XFCLOSE(f);
  68035. ExpectIntEQ((ret = wolfSSL_X509_get_ext_count(x509)), 5);
  68036. /* wolfSSL_X509_get_ext() valid input */
  68037. ExpectNotNull(foundExtension = wolfSSL_X509_get_ext(x509, 0));
  68038. /* wolfSSL_X509_get_ext() valid x509, idx out of bounds */
  68039. ExpectNull(foundExtension = wolfSSL_X509_get_ext(x509, -1));
  68040. ExpectNull(foundExtension = wolfSSL_X509_get_ext(x509, 100));
  68041. /* wolfSSL_X509_get_ext() NULL x509, idx out of bounds */
  68042. ExpectNull(foundExtension = wolfSSL_X509_get_ext(NULL, -1));
  68043. ExpectNull(foundExtension = wolfSSL_X509_get_ext(NULL, 100));
  68044. /* wolfSSL_X509_get_ext() NULL x509, valid idx */
  68045. ExpectNull(foundExtension = wolfSSL_X509_get_ext(NULL, 0));
  68046. wolfSSL_X509_free(x509);
  68047. #endif
  68048. return EXPECT_RESULT();
  68049. }
  68050. static int test_wolfSSL_X509_get_ext_by_NID(void)
  68051. {
  68052. EXPECT_DECLS;
  68053. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  68054. int rc = 0;
  68055. XFILE f = XBADFILE;
  68056. WOLFSSL_X509* x509 = NULL;
  68057. ASN1_OBJECT* obj = NULL;
  68058. ExpectTrue((f = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  68059. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  68060. if (f != XBADFILE)
  68061. XFCLOSE(f);
  68062. ExpectIntGE(rc = wolfSSL_X509_get_ext_by_NID(x509, NID_basic_constraints,
  68063. -1), 0);
  68064. /* Start search from last location (should fail) */
  68065. ExpectIntGE(rc = wolfSSL_X509_get_ext_by_NID(x509, NID_basic_constraints,
  68066. rc), -1);
  68067. ExpectIntGE(rc = wolfSSL_X509_get_ext_by_NID(x509, NID_basic_constraints,
  68068. -2), -1);
  68069. ExpectIntEQ(rc = wolfSSL_X509_get_ext_by_NID(NULL, NID_basic_constraints,
  68070. -1), -1);
  68071. ExpectIntEQ(rc = wolfSSL_X509_get_ext_by_NID(x509, NID_undef, -1), -1);
  68072. /* NID_ext_key_usage, check also its nid and oid */
  68073. ExpectIntGT(rc = wolfSSL_X509_get_ext_by_NID(x509, NID_ext_key_usage, -1),
  68074. -1);
  68075. ExpectNotNull(obj = wolfSSL_X509_EXTENSION_get_object(wolfSSL_X509_get_ext(
  68076. x509, rc)));
  68077. ExpectIntEQ(obj->nid, NID_ext_key_usage);
  68078. ExpectIntEQ(obj->type, EXT_KEY_USAGE_OID);
  68079. wolfSSL_X509_free(x509);
  68080. #endif
  68081. return EXPECT_RESULT();
  68082. }
  68083. static int test_wolfSSL_X509_get_ext_subj_alt_name(void)
  68084. {
  68085. EXPECT_DECLS;
  68086. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  68087. int rc = 0;
  68088. XFILE f = XBADFILE;
  68089. WOLFSSL_X509* x509 = NULL;
  68090. WOLFSSL_X509_EXTENSION* ext = NULL;
  68091. WOLFSSL_ASN1_STRING* sanString = NULL;
  68092. byte* sanDer = NULL;
  68093. const byte expectedDer[] = {
  68094. 0x30, 0x13, 0x82, 0x0b, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e,
  68095. 0x63, 0x6f, 0x6d, 0x87, 0x04, 0x7f, 0x00, 0x00, 0x01};
  68096. ExpectTrue((f = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  68097. ExpectNotNull(x509 = PEM_read_X509(f, NULL, NULL, NULL));
  68098. if (f != XBADFILE)
  68099. XFCLOSE(f);
  68100. ExpectIntNE(rc = X509_get_ext_by_NID(x509, NID_subject_alt_name, -1), -1);
  68101. ExpectNotNull(ext = X509_get_ext(x509, rc));
  68102. ExpectNotNull(sanString = X509_EXTENSION_get_data(ext));
  68103. ExpectIntEQ(ASN1_STRING_length(sanString), sizeof(expectedDer));
  68104. ExpectNotNull(sanDer = ASN1_STRING_data(sanString));
  68105. ExpectIntEQ(XMEMCMP(sanDer, expectedDer, sizeof(expectedDer)), 0);
  68106. X509_free(x509);
  68107. #endif
  68108. return EXPECT_RESULT();
  68109. }
  68110. static int test_wolfSSL_X509_EXTENSION_new(void)
  68111. {
  68112. EXPECT_DECLS;
  68113. #if defined (OPENSSL_ALL)
  68114. WOLFSSL_X509_EXTENSION* ext = NULL;
  68115. ExpectNotNull(ext = wolfSSL_X509_EXTENSION_new());
  68116. ExpectNotNull(ext->obj = wolfSSL_ASN1_OBJECT_new());
  68117. wolfSSL_X509_EXTENSION_free(ext);
  68118. #endif
  68119. return EXPECT_RESULT();
  68120. }
  68121. static int test_wolfSSL_X509_EXTENSION_get_object(void)
  68122. {
  68123. EXPECT_DECLS;
  68124. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  68125. WOLFSSL_X509* x509 = NULL;
  68126. WOLFSSL_X509_EXTENSION* ext = NULL;
  68127. WOLFSSL_ASN1_OBJECT* o = NULL;
  68128. XFILE file = XBADFILE;
  68129. ExpectTrue((file = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  68130. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(file, NULL, NULL, NULL));
  68131. if (file != XBADFILE)
  68132. XFCLOSE(file);
  68133. /* wolfSSL_X509_EXTENSION_get_object() testing ext idx 0 */
  68134. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, 0));
  68135. ExpectNull(wolfSSL_X509_EXTENSION_get_object(NULL));
  68136. ExpectNotNull(o = wolfSSL_X509_EXTENSION_get_object(ext));
  68137. ExpectIntEQ(o->nid, 128);
  68138. /* wolfSSL_X509_EXTENSION_get_object() NULL argument */
  68139. ExpectNull(o = wolfSSL_X509_EXTENSION_get_object(NULL));
  68140. wolfSSL_X509_free(x509);
  68141. #endif
  68142. return EXPECT_RESULT();
  68143. }
  68144. static int test_wolfSSL_X509_EXTENSION_get_data(void)
  68145. {
  68146. EXPECT_DECLS;
  68147. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  68148. WOLFSSL_X509* x509 = NULL;
  68149. WOLFSSL_X509_EXTENSION* ext = NULL;
  68150. WOLFSSL_ASN1_STRING* str = NULL;
  68151. XFILE file = XBADFILE;
  68152. ExpectTrue((file = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  68153. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(file, NULL, NULL, NULL));
  68154. if (file != XBADFILE)
  68155. XFCLOSE(file);
  68156. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, 0));
  68157. ExpectNull(str = wolfSSL_X509_EXTENSION_get_data(NULL));
  68158. ExpectNotNull(str = wolfSSL_X509_EXTENSION_get_data(ext));
  68159. wolfSSL_X509_free(x509);
  68160. #endif
  68161. return EXPECT_RESULT();
  68162. }
  68163. static int test_wolfSSL_X509_EXTENSION_get_critical(void)
  68164. {
  68165. EXPECT_DECLS;
  68166. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_RSA)
  68167. WOLFSSL_X509* x509 = NULL;
  68168. WOLFSSL_X509_EXTENSION* ext = NULL;
  68169. XFILE file = XBADFILE;
  68170. int crit = 0;
  68171. ExpectTrue((file = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  68172. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(file, NULL, NULL, NULL));
  68173. if (file != XBADFILE)
  68174. XFCLOSE(file);
  68175. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, 0));
  68176. ExpectIntEQ(crit = wolfSSL_X509_EXTENSION_get_critical(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  68177. ExpectIntEQ(crit = wolfSSL_X509_EXTENSION_get_critical(ext), 0);
  68178. wolfSSL_X509_free(x509);
  68179. #endif
  68180. return EXPECT_RESULT();
  68181. }
  68182. static int test_wolfSSL_X509V3_EXT_print(void)
  68183. {
  68184. EXPECT_DECLS;
  68185. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_ALL) && !defined(NO_BIO) && \
  68186. !defined(NO_RSA)
  68187. {
  68188. XFILE f = XBADFILE;
  68189. WOLFSSL_X509* x509 = NULL;
  68190. X509_EXTENSION * ext = NULL;
  68191. int loc = 0;
  68192. BIO *bio = NULL;
  68193. ExpectTrue((f = XFOPEN(svrCertFile, "rb")) != XBADFILE);
  68194. ExpectNotNull(x509 = wolfSSL_PEM_read_X509(f, NULL, NULL, NULL));
  68195. if (f != XBADFILE)
  68196. fclose(f);
  68197. ExpectNotNull(bio = wolfSSL_BIO_new(BIO_s_mem()));
  68198. ExpectIntGT(loc = wolfSSL_X509_get_ext_by_NID(x509,
  68199. NID_basic_constraints, -1), -1);
  68200. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, loc));
  68201. ExpectIntEQ(wolfSSL_X509V3_EXT_print(bio, ext, 0, 0), WOLFSSL_SUCCESS);
  68202. ExpectIntGT(loc = wolfSSL_X509_get_ext_by_NID(x509,
  68203. NID_subject_key_identifier, -1), -1);
  68204. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, loc));
  68205. ExpectIntEQ(wolfSSL_X509V3_EXT_print(bio, ext, 0, 0), WOLFSSL_SUCCESS);
  68206. ExpectIntGT(loc = wolfSSL_X509_get_ext_by_NID(x509,
  68207. NID_authority_key_identifier, -1), -1);
  68208. ExpectNotNull(ext = wolfSSL_X509_get_ext(x509, loc));
  68209. ExpectIntEQ(wolfSSL_X509V3_EXT_print(bio, ext, 0, 0), WOLFSSL_SUCCESS);
  68210. wolfSSL_BIO_free(bio);
  68211. wolfSSL_X509_free(x509);
  68212. }
  68213. {
  68214. X509 *x509 = NULL;
  68215. BIO *bio = NULL;
  68216. X509_EXTENSION *ext = NULL;
  68217. unsigned int i = 0;
  68218. unsigned int idx = 0;
  68219. /* Some NIDs to test with */
  68220. int nids[] = {
  68221. /* NID_key_usage, currently X509_get_ext returns this as a bit
  68222. * string, which messes up X509V3_EXT_print */
  68223. /* NID_ext_key_usage, */
  68224. NID_subject_alt_name,
  68225. };
  68226. int* n = NULL;
  68227. ExpectNotNull(bio = BIO_new_fp(stderr, BIO_NOCLOSE));
  68228. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFileExt,
  68229. WOLFSSL_FILETYPE_PEM));
  68230. ExpectIntGT(fprintf(stderr, "\nPrinting extension values:\n"), 0);
  68231. for (i = 0, n = nids; i<(sizeof(nids)/sizeof(int)); i++, n++) {
  68232. /* X509_get_ext_by_NID should return 3 for now. If that changes then
  68233. * update the index */
  68234. ExpectIntEQ((idx = X509_get_ext_by_NID(x509, *n, -1)), 3);
  68235. ExpectNotNull(ext = X509_get_ext(x509, (int)idx));
  68236. ExpectIntEQ(X509V3_EXT_print(bio, ext, 0, 0), 1);
  68237. ExpectIntGT(fprintf(stderr, "\n"), 0);
  68238. }
  68239. BIO_free(bio);
  68240. X509_free(x509);
  68241. }
  68242. #endif
  68243. return EXPECT_RESULT();
  68244. }
  68245. static int test_wolfSSL_X509_cmp(void)
  68246. {
  68247. EXPECT_DECLS;
  68248. #if defined(OPENSSL_ALL) && !defined(NO_RSA)
  68249. XFILE file1 = XBADFILE;
  68250. XFILE file2 = XBADFILE;
  68251. WOLFSSL_X509* cert1 = NULL;
  68252. WOLFSSL_X509* cert2 = NULL;
  68253. ExpectTrue((file1 = XFOPEN("./certs/server-cert.pem", "rb")) != XBADFILE);
  68254. ExpectTrue((file2 = XFOPEN("./certs/3072/client-cert.pem", "rb")) !=
  68255. XBADFILE);
  68256. ExpectNotNull(cert1 = wolfSSL_PEM_read_X509(file1, NULL, NULL, NULL));
  68257. ExpectNotNull(cert2 = wolfSSL_PEM_read_X509(file2, NULL, NULL, NULL));
  68258. if (file1 != XBADFILE)
  68259. fclose(file1);
  68260. if (file2 != XBADFILE)
  68261. fclose(file2);
  68262. /* wolfSSL_X509_cmp() testing matching certs */
  68263. ExpectIntEQ(0, wolfSSL_X509_cmp(cert1, cert1));
  68264. /* wolfSSL_X509_cmp() testing mismatched certs */
  68265. ExpectIntEQ(-1, wolfSSL_X509_cmp(cert1, cert2));
  68266. /* wolfSSL_X509_cmp() testing NULL, valid args */
  68267. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wolfSSL_X509_cmp(NULL, cert2));
  68268. /* wolfSSL_X509_cmp() testing valid, NULL args */
  68269. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wolfSSL_X509_cmp(cert1, NULL));
  68270. /* wolfSSL_X509_cmp() testing NULL, NULL args */
  68271. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wolfSSL_X509_cmp(NULL, NULL));
  68272. wolfSSL_X509_free(cert1);
  68273. wolfSSL_X509_free(cert2);
  68274. #endif
  68275. return EXPECT_RESULT();
  68276. }
  68277. static int test_wolfSSL_EVP_PKEY_up_ref(void)
  68278. {
  68279. EXPECT_DECLS;
  68280. #if defined(OPENSSL_ALL)
  68281. EVP_PKEY* pkey;
  68282. pkey = EVP_PKEY_new();
  68283. ExpectNotNull(pkey);
  68284. ExpectIntEQ(EVP_PKEY_up_ref(NULL), 0);
  68285. ExpectIntEQ(EVP_PKEY_up_ref(pkey), 1);
  68286. EVP_PKEY_free(pkey);
  68287. ExpectIntEQ(EVP_PKEY_up_ref(pkey), 1);
  68288. EVP_PKEY_free(pkey);
  68289. EVP_PKEY_free(pkey);
  68290. #endif
  68291. return EXPECT_RESULT();
  68292. }
  68293. static int test_wolfSSL_d2i_and_i2d_PublicKey(void)
  68294. {
  68295. EXPECT_DECLS;
  68296. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  68297. EVP_PKEY* pkey = NULL;
  68298. const unsigned char* p;
  68299. unsigned char *der = NULL;
  68300. unsigned char *tmp = NULL;
  68301. int derLen;
  68302. p = client_keypub_der_2048;
  68303. /* Check that key can be successfully decoded. */
  68304. ExpectNotNull(pkey = wolfSSL_d2i_PublicKey(EVP_PKEY_RSA, NULL, &p,
  68305. sizeof_client_keypub_der_2048));
  68306. /* Check that key can be successfully encoded. */
  68307. ExpectIntGE((derLen = wolfSSL_i2d_PublicKey(pkey, &der)), 0);
  68308. /* Ensure that the encoded version matches the original. */
  68309. ExpectIntEQ(derLen, sizeof_client_keypub_der_2048);
  68310. ExpectIntEQ(XMEMCMP(der, client_keypub_der_2048, derLen), 0);
  68311. /* Do same test except with pre-allocated buffer to ensure the der pointer
  68312. * is advanced. */
  68313. tmp = der;
  68314. ExpectIntGE((derLen = wolfSSL_i2d_PublicKey(pkey, &tmp)), 0);
  68315. ExpectIntEQ(derLen, sizeof_client_keypub_der_2048);
  68316. ExpectIntEQ(XMEMCMP(der, client_keypub_der_2048, derLen), 0);
  68317. ExpectTrue(der + derLen == tmp);
  68318. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  68319. EVP_PKEY_free(pkey);
  68320. #endif
  68321. return EXPECT_RESULT();
  68322. }
  68323. static int test_wolfSSL_d2i_and_i2d_PublicKey_ecc(void)
  68324. {
  68325. EXPECT_DECLS;
  68326. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && !defined(NO_CERTS) && \
  68327. !defined(NO_ASN) && !defined(NO_PWDBASED)
  68328. EVP_PKEY* pkey = NULL;
  68329. const unsigned char* p;
  68330. unsigned char *der = NULL;
  68331. unsigned char *tmp = NULL;
  68332. int derLen;
  68333. unsigned char pub_buf[65];
  68334. const int pub_len = 65;
  68335. BN_CTX* ctx;
  68336. EC_GROUP* curve = NULL;
  68337. EC_KEY* ephemeral_key = NULL;
  68338. const EC_POINT* h = NULL;
  68339. /* Generate an x963 key pair and get public part into pub_buf */
  68340. ExpectNotNull(ctx = BN_CTX_new());
  68341. ExpectNotNull(curve = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
  68342. ExpectNotNull(ephemeral_key = EC_KEY_new_by_curve_name(
  68343. NID_X9_62_prime256v1));
  68344. ExpectIntEQ(EC_KEY_generate_key(ephemeral_key), 1);
  68345. ExpectNotNull(h = EC_KEY_get0_public_key(ephemeral_key));
  68346. ExpectIntEQ(pub_len, EC_POINT_point2oct(curve, h,
  68347. POINT_CONVERSION_UNCOMPRESSED, pub_buf, pub_len, ctx));
  68348. /* Prepare the EVP_PKEY */
  68349. ExpectNotNull(pkey = EVP_PKEY_new());
  68350. p = pub_buf;
  68351. /* Check that key can be successfully decoded. */
  68352. ExpectNotNull(wolfSSL_d2i_PublicKey(EVP_PKEY_EC, &pkey, &p,
  68353. pub_len));
  68354. /* Check that key can be successfully encoded. */
  68355. ExpectIntGE((derLen = wolfSSL_i2d_PublicKey(pkey, &der)), 0);
  68356. /* Ensure that the encoded version matches the original. */
  68357. ExpectIntEQ(derLen, pub_len);
  68358. ExpectIntEQ(XMEMCMP(der, pub_buf, derLen), 0);
  68359. /* Do same test except with pre-allocated buffer to ensure the der pointer
  68360. * is advanced. */
  68361. tmp = der;
  68362. ExpectIntGE((derLen = wolfSSL_i2d_PublicKey(pkey, &tmp)), 0);
  68363. ExpectIntEQ(derLen, pub_len);
  68364. ExpectIntEQ(XMEMCMP(der, pub_buf, derLen), 0);
  68365. ExpectTrue(der + derLen == tmp);
  68366. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  68367. EVP_PKEY_free(pkey);
  68368. EC_KEY_free(ephemeral_key);
  68369. EC_GROUP_free(curve);
  68370. #endif
  68371. return EXPECT_RESULT();
  68372. }
  68373. static int test_wolfSSL_d2i_and_i2d_DSAparams(void)
  68374. {
  68375. EXPECT_DECLS;
  68376. #if defined(OPENSSL_EXTRA) && !defined(NO_DSA)
  68377. DSA* dsa = NULL;
  68378. byte derIn[] = {
  68379. 0x30, 0x82, 0x01, 0x1f, 0x02, 0x81, 0x81, 0x00,
  68380. 0xcd, 0xde, 0x25, 0x68, 0x80, 0x53, 0x0d, 0xe5,
  68381. 0x77, 0xd6, 0xd2, 0x90, 0x39, 0x3f, 0x90, 0xa2,
  68382. 0x3f, 0x33, 0x94, 0x6e, 0xe8, 0x4f, 0x2b, 0x63,
  68383. 0xab, 0x30, 0xab, 0x15, 0xba, 0x11, 0xea, 0x8a,
  68384. 0x5d, 0x8d, 0xcc, 0xb8, 0xd4, 0xa1, 0xd5, 0xc1,
  68385. 0x47, 0x9d, 0x5a, 0x73, 0x6a, 0x62, 0x49, 0xd1,
  68386. 0x06, 0x07, 0x67, 0xf6, 0x2f, 0xa3, 0x39, 0xbd,
  68387. 0x4e, 0x0d, 0xb4, 0xd3, 0x22, 0x23, 0x84, 0xec,
  68388. 0x93, 0x26, 0x5a, 0x49, 0xee, 0x7c, 0x89, 0x48,
  68389. 0x66, 0x4d, 0xe8, 0xe8, 0xd8, 0x50, 0xfb, 0xa5,
  68390. 0x71, 0x9f, 0x22, 0x18, 0xe5, 0xe6, 0x0b, 0x46,
  68391. 0x87, 0x66, 0xee, 0x52, 0x8f, 0x46, 0x4f, 0xb5,
  68392. 0x03, 0xce, 0xed, 0xe3, 0xbe, 0xe5, 0xb5, 0x81,
  68393. 0xd2, 0x59, 0xe9, 0xc0, 0xad, 0x4d, 0xd0, 0x4d,
  68394. 0x26, 0xf7, 0xba, 0x50, 0xe8, 0xc9, 0x8f, 0xfe,
  68395. 0x24, 0x19, 0x3d, 0x2e, 0xa7, 0x52, 0x3c, 0x6d,
  68396. 0x02, 0x15, 0x00, 0xfb, 0x47, 0xfb, 0xec, 0x81,
  68397. 0x20, 0xc8, 0x1c, 0xe9, 0x4a, 0xba, 0x04, 0x6f,
  68398. 0x19, 0x9b, 0x94, 0xee, 0x82, 0x67, 0xd3, 0x02,
  68399. 0x81, 0x81, 0x00, 0x9b, 0x95, 0xbb, 0x85, 0xc5,
  68400. 0x58, 0x4a, 0x32, 0x9c, 0xaa, 0x44, 0x85, 0xd6,
  68401. 0x68, 0xdc, 0x3e, 0x14, 0xf4, 0xce, 0x6d, 0xa3,
  68402. 0x49, 0x38, 0xea, 0xd6, 0x61, 0x48, 0x92, 0x5a,
  68403. 0x40, 0x95, 0x49, 0x38, 0xaa, 0xe1, 0x39, 0x29,
  68404. 0x68, 0x58, 0x47, 0x8a, 0x4b, 0x01, 0xe1, 0x2e,
  68405. 0x8e, 0x6c, 0x63, 0x6f, 0x40, 0xca, 0x50, 0x3f,
  68406. 0x8c, 0x0b, 0x99, 0xe4, 0x72, 0x42, 0xb8, 0xb1,
  68407. 0xc2, 0x26, 0x48, 0xf1, 0x9c, 0x83, 0xc6, 0x37,
  68408. 0x2e, 0x5a, 0xae, 0x11, 0x09, 0xd9, 0xf3, 0xad,
  68409. 0x1f, 0x6f, 0xad, 0xad, 0x50, 0xe3, 0x78, 0x32,
  68410. 0xe6, 0xde, 0x8e, 0xaa, 0xbf, 0xd1, 0x00, 0x9f,
  68411. 0xb3, 0x02, 0x12, 0x19, 0xa2, 0x15, 0xec, 0x14,
  68412. 0x18, 0x5c, 0x0e, 0x26, 0xce, 0xf9, 0xae, 0xcc,
  68413. 0x7b, 0xb5, 0xd1, 0x26, 0xfc, 0x85, 0xfe, 0x14,
  68414. 0x93, 0xb6, 0x9d, 0x7d, 0x76, 0xe3, 0x35, 0x97,
  68415. 0x1e, 0xde, 0xc4
  68416. };
  68417. int derInLen = sizeof(derIn);
  68418. byte* derOut = NULL;
  68419. int derOutLen;
  68420. byte* p = derIn;
  68421. /* Check that params can be successfully decoded. */
  68422. ExpectNotNull(dsa = d2i_DSAparams(NULL, (const byte**)&p, derInLen));
  68423. /* Check that params can be successfully encoded. */
  68424. ExpectIntGE((derOutLen = i2d_DSAparams(dsa, &derOut)), 0);
  68425. /* Ensure that the encoded version matches the original. */
  68426. ExpectIntEQ(derInLen, derOutLen);
  68427. ExpectIntEQ(XMEMCMP(derIn, derOut, derInLen), 0);
  68428. XFREE(derOut, HEAP_HINT, DYNAMIC_TYPE_OPENSSL);
  68429. DSA_free(dsa);
  68430. #endif
  68431. return EXPECT_RESULT();
  68432. }
  68433. static int test_wolfSSL_i2d_PrivateKey(void)
  68434. {
  68435. EXPECT_DECLS;
  68436. #if (!defined(NO_RSA) || defined(HAVE_ECC)) && defined(OPENSSL_EXTRA) && \
  68437. !defined(NO_ASN) && !defined(NO_PWDBASED)
  68438. #if !defined(NO_RSA) && defined(USE_CERT_BUFFERS_2048)
  68439. {
  68440. EVP_PKEY* pkey = NULL;
  68441. const unsigned char* server_key =
  68442. (const unsigned char*)server_key_der_2048;
  68443. unsigned char buf[FOURK_BUF];
  68444. unsigned char* pt = NULL;
  68445. int bufSz = 0;
  68446. ExpectNotNull(pkey = d2i_PrivateKey(EVP_PKEY_RSA, NULL, &server_key,
  68447. (long)sizeof_server_key_der_2048));
  68448. ExpectIntEQ(i2d_PrivateKey(pkey, NULL), 1193);
  68449. pt = buf;
  68450. ExpectIntEQ((bufSz = i2d_PrivateKey(pkey, &pt)), 1193);
  68451. ExpectIntNE((pt - buf), 0);
  68452. ExpectIntEQ(XMEMCMP(buf, server_key_der_2048, bufSz), 0);
  68453. EVP_PKEY_free(pkey);
  68454. }
  68455. #endif
  68456. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  68457. {
  68458. EVP_PKEY* pkey = NULL;
  68459. const unsigned char* client_key =
  68460. (const unsigned char*)ecc_clikey_der_256;
  68461. unsigned char buf[FOURK_BUF];
  68462. unsigned char* pt = NULL;
  68463. int bufSz = 0;
  68464. ExpectNotNull((pkey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &client_key,
  68465. (long)sizeof_ecc_clikey_der_256)));
  68466. ExpectIntEQ(i2d_PrivateKey(pkey, NULL), 121);
  68467. pt = buf;
  68468. ExpectIntEQ((bufSz = i2d_PrivateKey(pkey, &pt)), 121);
  68469. ExpectIntNE((pt - buf), 0);
  68470. ExpectIntEQ(XMEMCMP(buf, ecc_clikey_der_256, bufSz), 0);
  68471. EVP_PKEY_free(pkey);
  68472. }
  68473. #endif
  68474. #endif
  68475. return EXPECT_RESULT();
  68476. }
  68477. static int test_wolfSSL_OCSP_id_get0_info(void)
  68478. {
  68479. EXPECT_DECLS;
  68480. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_HAPROXY)) && \
  68481. defined(HAVE_OCSP) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  68482. X509* cert = NULL;
  68483. X509* issuer = NULL;
  68484. OCSP_CERTID* id = NULL;
  68485. OCSP_CERTID* id2 = NULL;
  68486. ASN1_STRING* name = NULL;
  68487. ASN1_OBJECT* pmd = NULL;
  68488. ASN1_STRING* keyHash = NULL;
  68489. ASN1_INTEGER* serial = NULL;
  68490. ASN1_INTEGER* x509Int = NULL;
  68491. ExpectNotNull(cert = wolfSSL_X509_load_certificate_file(svrCertFile,
  68492. SSL_FILETYPE_PEM));
  68493. ExpectNotNull(issuer = wolfSSL_X509_load_certificate_file(caCertFile,
  68494. SSL_FILETYPE_PEM));
  68495. ExpectNotNull(id = OCSP_cert_to_id(NULL, cert, issuer));
  68496. ExpectNotNull(id2 = OCSP_cert_to_id(NULL, cert, issuer));
  68497. ExpectIntEQ(OCSP_id_get0_info(NULL, NULL, NULL, NULL, NULL), 0);
  68498. ExpectIntEQ(OCSP_id_get0_info(NULL, NULL, NULL, NULL, id), 1);
  68499. /* name, pmd, keyHash not supported yet, expect failure if not NULL */
  68500. ExpectIntEQ(OCSP_id_get0_info(&name, NULL, NULL, NULL, id), 0);
  68501. ExpectIntEQ(OCSP_id_get0_info(NULL, &pmd, NULL, NULL, id), 0);
  68502. ExpectIntEQ(OCSP_id_get0_info(NULL, NULL, &keyHash, NULL, id), 0);
  68503. ExpectIntEQ(OCSP_id_get0_info(NULL, NULL, NULL, &serial, id), 1);
  68504. ExpectNotNull(serial);
  68505. /* compare serial number to one in cert, should be equal */
  68506. ExpectNotNull(x509Int = X509_get_serialNumber(cert));
  68507. ExpectIntEQ(x509Int->length, serial->length);
  68508. ExpectIntEQ(XMEMCMP(x509Int->data, serial->data, serial->length), 0);
  68509. /* test OCSP_id_cmp */
  68510. ExpectIntNE(OCSP_id_cmp(NULL, NULL), 0);
  68511. ExpectIntNE(OCSP_id_cmp(id, NULL), 0);
  68512. ExpectIntNE(OCSP_id_cmp(NULL, id2), 0);
  68513. ExpectIntEQ(OCSP_id_cmp(id, id2), 0);
  68514. if (id != NULL) {
  68515. id->issuerHash[0] = ~id->issuerHash[0];
  68516. }
  68517. ExpectIntNE(OCSP_id_cmp(id, id2), 0);
  68518. OCSP_CERTID_free(id);
  68519. OCSP_CERTID_free(id2);
  68520. X509_free(cert); /* free's x509Int */
  68521. X509_free(issuer);
  68522. #endif
  68523. return EXPECT_RESULT();
  68524. }
  68525. static int test_wolfSSL_i2d_OCSP_CERTID(void)
  68526. {
  68527. EXPECT_DECLS;
  68528. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_HAPROXY)) && defined(HAVE_OCSP)
  68529. WOLFSSL_OCSP_CERTID certId;
  68530. byte* targetBuffer = NULL;
  68531. byte* p;
  68532. /* OCSP CertID bytes taken from PCAP */
  68533. byte rawCertId[] = {
  68534. 0x30, 0x49, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05,
  68535. 0x00, 0x04, 0x14, 0x80, 0x51, 0x06, 0x01, 0x32, 0xad, 0x9a, 0xc2, 0x7d,
  68536. 0x51, 0x87, 0xa0, 0xe8, 0x87, 0xfb, 0x01, 0x62, 0x01, 0x55, 0xee, 0x04,
  68537. 0x14, 0x03, 0xde, 0x50, 0x35, 0x56, 0xd1, 0x4c, 0xbb, 0x66, 0xf0, 0xa3,
  68538. 0xe2, 0x1b, 0x1b, 0xc3, 0x97, 0xb2, 0x3d, 0xd1, 0x55, 0x02, 0x10, 0x01,
  68539. 0xfd, 0xa3, 0xeb, 0x6e, 0xca, 0x75, 0xc8, 0x88, 0x43, 0x8b, 0x72, 0x4b,
  68540. 0xcf, 0xbc, 0x91
  68541. };
  68542. int ret = 0;
  68543. int i;
  68544. XMEMSET(&certId, 0, sizeof(WOLFSSL_OCSP_CERTID));
  68545. certId.rawCertId = rawCertId;
  68546. certId.rawCertIdSize = sizeof(rawCertId);
  68547. ExpectNotNull(targetBuffer = (byte*)XMALLOC(sizeof(rawCertId), NULL,
  68548. DYNAMIC_TYPE_TMP_BUFFER));
  68549. p = targetBuffer;
  68550. /* Function returns the size of the encoded data. */
  68551. ExpectIntEQ(ret = wolfSSL_i2d_OCSP_CERTID(&certId, &p), sizeof(rawCertId));
  68552. /* If target buffer is not null, function increments targetBuffer to point
  68553. * just past the end of the encoded data. */
  68554. ExpectPtrEq(p, (targetBuffer + sizeof(rawCertId)));
  68555. for (i = 0; EXPECT_SUCCESS() && i < ret; ++i) {
  68556. ExpectIntEQ(targetBuffer[i], rawCertId[i]);
  68557. }
  68558. XFREE(targetBuffer, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  68559. targetBuffer = NULL;
  68560. /* If target buffer is null, function allocates memory for a buffer and
  68561. * copies the encoded data into it. targetBuffer then points to the start of
  68562. * this newly allocate buffer. */
  68563. ExpectIntEQ(ret = wolfSSL_i2d_OCSP_CERTID(&certId, &targetBuffer),
  68564. sizeof(rawCertId));
  68565. for (i = 0; EXPECT_SUCCESS() && i < ret; ++i) {
  68566. ExpectIntEQ(targetBuffer[i], rawCertId[i]);
  68567. }
  68568. XFREE(targetBuffer, NULL, DYNAMIC_TYPE_OPENSSL);
  68569. #endif
  68570. return EXPECT_RESULT();
  68571. }
  68572. static int test_wolfSSL_d2i_OCSP_CERTID(void)
  68573. {
  68574. EXPECT_DECLS;
  68575. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_HAPROXY)) && defined(HAVE_OCSP)
  68576. WOLFSSL_OCSP_CERTID* certId;
  68577. WOLFSSL_OCSP_CERTID* certIdGood;
  68578. WOLFSSL_OCSP_CERTID* certIdBad;
  68579. const unsigned char* rawCertIdPtr;
  68580. const unsigned char rawCertId[] = {
  68581. 0x30, 0x49, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05,
  68582. 0x00, 0x04, 0x14, 0x80, 0x51, 0x06, 0x01, 0x32, 0xad, 0x9a, 0xc2, 0x7d,
  68583. 0x51, 0x87, 0xa0, 0xe8, 0x87, 0xfb, 0x01, 0x62, 0x01, 0x55, 0xee, 0x04,
  68584. 0x14, 0x03, 0xde, 0x50, 0x35, 0x56, 0xd1, 0x4c, 0xbb, 0x66, 0xf0, 0xa3,
  68585. 0xe2, 0x1b, 0x1b, 0xc3, 0x97, 0xb2, 0x3d, 0xd1, 0x55, 0x02, 0x10, 0x01,
  68586. 0xfd, 0xa3, 0xeb, 0x6e, 0xca, 0x75, 0xc8, 0x88, 0x43, 0x8b, 0x72, 0x4b,
  68587. 0xcf, 0xbc, 0x91
  68588. };
  68589. rawCertIdPtr = &rawCertId[0];
  68590. /* If the cert ID is NULL the function should allocate it and copy the
  68591. * data to it. */
  68592. certId = NULL;
  68593. ExpectNotNull(certId = wolfSSL_d2i_OCSP_CERTID(&certId, &rawCertIdPtr,
  68594. sizeof(rawCertId)));
  68595. ExpectIntEQ(certId->rawCertIdSize, sizeof(rawCertId));
  68596. if (certId != NULL) {
  68597. XFREE(certId->rawCertId, NULL, DYNAMIC_TYPE_OPENSSL);
  68598. XFREE(certId, NULL, DYNAMIC_TYPE_OPENSSL);
  68599. }
  68600. /* If the cert ID is not NULL the function will just copy the data to it. */
  68601. ExpectNotNull(certId = (WOLFSSL_OCSP_CERTID*)XMALLOC(sizeof(*certId), NULL,
  68602. DYNAMIC_TYPE_TMP_BUFFER));
  68603. ExpectNotNull(certId);
  68604. ExpectNotNull(XMEMSET(certId, 0, sizeof(*certId)));
  68605. /* Reset rawCertIdPtr since it was push forward in the previous call. */
  68606. rawCertIdPtr = &rawCertId[0];
  68607. ExpectNotNull(certIdGood = wolfSSL_d2i_OCSP_CERTID(&certId, &rawCertIdPtr,
  68608. sizeof(rawCertId)));
  68609. ExpectPtrEq(certIdGood, certId);
  68610. ExpectIntEQ(certId->rawCertIdSize, sizeof(rawCertId));
  68611. if (certId != NULL) {
  68612. XFREE(certId->rawCertId, NULL, DYNAMIC_TYPE_OPENSSL);
  68613. XFREE(certId, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  68614. certId = NULL;
  68615. }
  68616. /* The below tests should fail when passed bad parameters. NULL should
  68617. * always be returned. */
  68618. ExpectNull(certIdBad = wolfSSL_d2i_OCSP_CERTID(NULL, &rawCertIdPtr,
  68619. sizeof(rawCertId)));
  68620. ExpectNull(certIdBad = wolfSSL_d2i_OCSP_CERTID(&certId, NULL,
  68621. sizeof(rawCertId)));
  68622. ExpectNull(certIdBad = wolfSSL_d2i_OCSP_CERTID(&certId, &rawCertIdPtr, 0));
  68623. #endif
  68624. return EXPECT_RESULT();
  68625. }
  68626. static int test_wolfSSL_OCSP_id_cmp(void)
  68627. {
  68628. EXPECT_DECLS;
  68629. #if defined(OPENSSL_ALL) && defined(HAVE_OCSP)
  68630. OCSP_CERTID id1;
  68631. OCSP_CERTID id2;
  68632. XMEMSET(&id1, 0, sizeof(id1));
  68633. XMEMSET(&id2, 0, sizeof(id2));
  68634. ExpectIntEQ(OCSP_id_cmp(&id1, &id2), 0);
  68635. ExpectIntNE(OCSP_id_cmp(NULL, NULL), 0);
  68636. ExpectIntNE(OCSP_id_cmp(&id1, NULL), 0);
  68637. ExpectIntNE(OCSP_id_cmp(NULL, &id2), 0);
  68638. #endif
  68639. return EXPECT_RESULT();
  68640. }
  68641. static int test_wolfSSL_OCSP_SINGLERESP_get0_id(void)
  68642. {
  68643. EXPECT_DECLS;
  68644. #if defined(HAVE_OCSP) && defined(OPENSSL_EXTRA)
  68645. WOLFSSL_OCSP_SINGLERESP single;
  68646. const WOLFSSL_OCSP_CERTID* certId;
  68647. XMEMSET(&single, 0, sizeof(single));
  68648. certId = wolfSSL_OCSP_SINGLERESP_get0_id(&single);
  68649. ExpectPtrEq(&single, certId);
  68650. ExpectNull(wolfSSL_OCSP_SINGLERESP_get0_id(NULL));
  68651. #endif
  68652. return EXPECT_RESULT();
  68653. }
  68654. static int test_wolfSSL_OCSP_single_get0_status(void)
  68655. {
  68656. EXPECT_DECLS;
  68657. #if defined(HAVE_OCSP) && defined(OPENSSL_EXTRA) && \
  68658. defined(WOLFSSL_OCSP_PARSE_STATUS)
  68659. WOLFSSL_OCSP_SINGLERESP single;
  68660. CertStatus certStatus;
  68661. WOLFSSL_ASN1_TIME* thisDate;
  68662. WOLFSSL_ASN1_TIME* nextDate;
  68663. int ret, i;
  68664. XMEMSET(&single, 0, sizeof(WOLFSSL_OCSP_SINGLERESP));
  68665. XMEMSET(&certStatus, 0, sizeof(CertStatus));
  68666. /* Fill the date fields with some dummy data. */
  68667. for (i = 0; i < CTC_DATE_SIZE; ++i) {
  68668. certStatus.thisDateParsed.data[i] = i;
  68669. certStatus.nextDateParsed.data[i] = i;
  68670. }
  68671. certStatus.status = CERT_GOOD;
  68672. single.status = &certStatus;
  68673. ret = wolfSSL_OCSP_single_get0_status(&single, NULL, NULL, &thisDate,
  68674. &nextDate);
  68675. ExpectIntEQ(ret, CERT_GOOD);
  68676. ExpectPtrEq(thisDate, &certStatus.thisDateParsed);
  68677. ExpectPtrEq(nextDate, &certStatus.nextDateParsed);
  68678. ExpectIntEQ(wolfSSL_OCSP_single_get0_status(NULL, NULL, NULL, NULL, NULL),
  68679. CERT_GOOD);
  68680. ExpectIntEQ(wolfSSL_OCSP_single_get0_status(&single, NULL, NULL, NULL,
  68681. NULL), CERT_GOOD);
  68682. #endif
  68683. return EXPECT_RESULT();
  68684. }
  68685. static int test_wolfSSL_OCSP_resp_count(void)
  68686. {
  68687. EXPECT_DECLS;
  68688. #if defined(HAVE_OCSP) && defined(OPENSSL_EXTRA)
  68689. WOLFSSL_OCSP_BASICRESP basicResp;
  68690. WOLFSSL_OCSP_SINGLERESP singleRespOne;
  68691. WOLFSSL_OCSP_SINGLERESP singleRespTwo;
  68692. XMEMSET(&basicResp, 0, sizeof(WOLFSSL_OCSP_BASICRESP));
  68693. XMEMSET(&singleRespOne, 0, sizeof(WOLFSSL_OCSP_SINGLERESP));
  68694. XMEMSET(&singleRespTwo, 0, sizeof(WOLFSSL_OCSP_SINGLERESP));
  68695. ExpectIntEQ(wolfSSL_OCSP_resp_count(&basicResp), 0);
  68696. basicResp.single = &singleRespOne;
  68697. ExpectIntEQ(wolfSSL_OCSP_resp_count(&basicResp), 1);
  68698. singleRespOne.next = &singleRespTwo;
  68699. ExpectIntEQ(wolfSSL_OCSP_resp_count(&basicResp), 2);
  68700. #endif
  68701. return EXPECT_RESULT();
  68702. }
  68703. static int test_wolfSSL_OCSP_resp_get0(void)
  68704. {
  68705. EXPECT_DECLS;
  68706. #if defined(HAVE_OCSP) && defined(OPENSSL_EXTRA)
  68707. WOLFSSL_OCSP_BASICRESP basicResp;
  68708. WOLFSSL_OCSP_SINGLERESP singleRespOne;
  68709. WOLFSSL_OCSP_SINGLERESP singleRespTwo;
  68710. XMEMSET(&basicResp, 0, sizeof(WOLFSSL_OCSP_BASICRESP));
  68711. XMEMSET(&singleRespOne, 0, sizeof(WOLFSSL_OCSP_SINGLERESP));
  68712. XMEMSET(&singleRespTwo, 0, sizeof(WOLFSSL_OCSP_SINGLERESP));
  68713. basicResp.single = &singleRespOne;
  68714. singleRespOne.next = &singleRespTwo;
  68715. ExpectPtrEq(wolfSSL_OCSP_resp_get0(&basicResp, 0), &singleRespOne);
  68716. ExpectPtrEq(wolfSSL_OCSP_resp_get0(&basicResp, 1), &singleRespTwo);
  68717. #endif
  68718. return EXPECT_RESULT();
  68719. }
  68720. static int test_wolfSSL_OCSP_parse_url(void)
  68721. {
  68722. EXPECT_DECLS;
  68723. #if defined(OPENSSL_EXTRA) && defined(HAVE_OCSP)
  68724. #define CK_OPU_OK(u, h, po, pa, s) do { \
  68725. char* host = NULL; \
  68726. char* port = NULL; \
  68727. char* path = NULL; \
  68728. int isSsl = 0; \
  68729. ExpectIntEQ(OCSP_parse_url(u, &host, &port, &path, &isSsl), 1); \
  68730. ExpectStrEQ(host, h); \
  68731. ExpectStrEQ(port, po); \
  68732. ExpectStrEQ(path, pa); \
  68733. ExpectIntEQ(isSsl, s); \
  68734. XFREE(host, NULL, DYNAMIC_TYPE_OPENSSL); \
  68735. XFREE(port, NULL, DYNAMIC_TYPE_OPENSSL); \
  68736. XFREE(path, NULL, DYNAMIC_TYPE_OPENSSL); \
  68737. } while(0)
  68738. #define CK_OPU_FAIL(u) do { \
  68739. char* host = NULL; \
  68740. char* port = NULL; \
  68741. char* path = NULL; \
  68742. int isSsl = 0; \
  68743. ExpectIntEQ(OCSP_parse_url(u, &host, &port, &path, &isSsl), 0); \
  68744. XFREE(host, NULL, DYNAMIC_TYPE_OPENSSL); \
  68745. XFREE(port, NULL, DYNAMIC_TYPE_OPENSSL); \
  68746. XFREE(path, NULL, DYNAMIC_TYPE_OPENSSL); \
  68747. } while(0)
  68748. CK_OPU_OK("http://localhost", "localhost", "80", "/", 0);
  68749. CK_OPU_OK("https://wolfssl.com", "wolfssl.com", "443", "/", 1);
  68750. CK_OPU_OK("https://www.wolfssl.com/fips-140-3-announcement-to-the-world/",
  68751. "www.wolfssl.com", "443", "/fips-140-3-announcement-to-the-world/", 1);
  68752. CK_OPU_OK("http://localhost:1234", "localhost", "1234", "/", 0);
  68753. CK_OPU_OK("https://localhost:1234", "localhost", "1234", "/", 1);
  68754. CK_OPU_FAIL("ftp://localhost");
  68755. /* two strings to cppcheck doesn't mark it as a c++ style comment */
  68756. CK_OPU_FAIL("http/""/localhost");
  68757. CK_OPU_FAIL("http:/localhost");
  68758. CK_OPU_FAIL("https://localhost/path:1234");
  68759. #undef CK_OPU_OK
  68760. #undef CK_OPU_FAIL
  68761. #endif
  68762. return EXPECT_RESULT();
  68763. }
  68764. #if defined(OPENSSL_ALL) && defined(HAVE_OCSP) && \
  68765. defined(WOLFSSL_SIGNER_DER_CERT) && !defined(NO_FILESYSTEM)
  68766. static time_t test_wolfSSL_OCSP_REQ_CTX_time_cb(time_t* t)
  68767. {
  68768. if (t != NULL) {
  68769. *t = 1722006780;
  68770. }
  68771. return 1722006780;
  68772. }
  68773. #endif
  68774. static int test_wolfSSL_OCSP_REQ_CTX(void)
  68775. {
  68776. EXPECT_DECLS;
  68777. #if defined(OPENSSL_ALL) && defined(HAVE_OCSP) && \
  68778. defined(WOLFSSL_SIGNER_DER_CERT) && !defined(NO_FILESYSTEM)
  68779. /* This buffer was taken from the ocsp-stapling.test test case 1. The ocsp
  68780. * response was captured in wireshark. It contains both the http and binary
  68781. * parts. The time test_wolfSSL_OCSP_REQ_CTX_time_cb is set exactly so that
  68782. * the time check passes. */
  68783. unsigned char ocspRespBin[] = {
  68784. 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x30, 0x20, 0x32, 0x30, 0x30,
  68785. 0x20, 0x4f, 0x4b, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74,
  68786. 0x2d, 0x74, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x69,
  68787. 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x6f, 0x63, 0x73, 0x70, 0x2d,
  68788. 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x0d, 0x0a, 0x43, 0x6f,
  68789. 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68,
  68790. 0x3a, 0x20, 0x31, 0x38, 0x32, 0x31, 0x0d, 0x0a, 0x0d, 0x0a, 0x30, 0x82,
  68791. 0x07, 0x19, 0x0a, 0x01, 0x00, 0xa0, 0x82, 0x07, 0x12, 0x30, 0x82, 0x07,
  68792. 0x0e, 0x06, 0x09, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x01, 0x01,
  68793. 0x04, 0x82, 0x06, 0xff, 0x30, 0x82, 0x06, 0xfb, 0x30, 0x82, 0x01, 0x19,
  68794. 0xa1, 0x81, 0xa1, 0x30, 0x81, 0x9e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03,
  68795. 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x06,
  68796. 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e,
  68797. 0x67, 0x74, 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04,
  68798. 0x07, 0x0c, 0x07, 0x53, 0x65, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10,
  68799. 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x77, 0x6f, 0x6c,
  68800. 0x66, 0x53, 0x53, 0x4c, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04,
  68801. 0x0b, 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69,
  68802. 0x6e, 0x67, 0x31, 0x1f, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c,
  68803. 0x16, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x4f, 0x43, 0x53,
  68804. 0x50, 0x20, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x64, 0x65, 0x72, 0x31,
  68805. 0x1f, 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,
  68806. 0x09, 0x01, 0x16, 0x10, 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c,
  68807. 0x66, 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x18, 0x0f, 0x32, 0x30,
  68808. 0x32, 0x34, 0x30, 0x37, 0x32, 0x36, 0x31, 0x35, 0x31, 0x32, 0x30, 0x35,
  68809. 0x5a, 0x30, 0x62, 0x30, 0x60, 0x30, 0x38, 0x30, 0x07, 0x06, 0x05, 0x2b,
  68810. 0x0e, 0x03, 0x02, 0x1a, 0x04, 0x14, 0x71, 0x4d, 0x82, 0x23, 0x40, 0x59,
  68811. 0xc0, 0x96, 0xa1, 0x37, 0x43, 0xfa, 0x31, 0xdb, 0xba, 0xb1, 0x43, 0x18,
  68812. 0xda, 0x04, 0x04, 0x14, 0x83, 0xc6, 0x3a, 0x89, 0x2c, 0x81, 0xf4, 0x02,
  68813. 0xd7, 0x9d, 0x4c, 0xe2, 0x2a, 0xc0, 0x71, 0x82, 0x64, 0x44, 0xda, 0x0e,
  68814. 0x02, 0x01, 0x05, 0x80, 0x00, 0x18, 0x0f, 0x32, 0x30, 0x32, 0x34, 0x30,
  68815. 0x37, 0x32, 0x36, 0x31, 0x35, 0x31, 0x32, 0x30, 0x35, 0x5a, 0xa0, 0x11,
  68816. 0x18, 0x0f, 0x32, 0x30, 0x32, 0x34, 0x30, 0x37, 0x32, 0x36, 0x31, 0x35,
  68817. 0x31, 0x33, 0x30, 0x35, 0x5a, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48,
  68818. 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01,
  68819. 0x00, 0x89, 0x7a, 0xe9, 0x6b, 0x66, 0x47, 0x8e, 0x52, 0x16, 0xf9, 0x8a,
  68820. 0x5a, 0x1e, 0x7a, 0x35, 0xbb, 0x1d, 0x6c, 0xd8, 0x31, 0xbb, 0x24, 0xd2,
  68821. 0xd7, 0xa4, 0x30, 0x27, 0x06, 0x17, 0x66, 0xd1, 0xf9, 0x8d, 0x24, 0xb0,
  68822. 0x49, 0x37, 0x62, 0x13, 0x78, 0x5e, 0xa6, 0x6d, 0xea, 0xe3, 0xd0, 0x30,
  68823. 0x82, 0x7d, 0xb6, 0xf6, 0x55, 0x82, 0x11, 0xdc, 0xe7, 0x0f, 0xd6, 0x24,
  68824. 0xb4, 0x80, 0x23, 0x4f, 0xfd, 0xa7, 0x9a, 0x4b, 0xac, 0xf2, 0xd3, 0xde,
  68825. 0x42, 0x10, 0xfb, 0x4b, 0x29, 0x06, 0x02, 0x7b, 0x47, 0x36, 0x70, 0x75,
  68826. 0x45, 0x38, 0x8d, 0x3e, 0x55, 0x9c, 0xce, 0x78, 0xd8, 0x18, 0x45, 0x47,
  68827. 0x2d, 0x2a, 0x46, 0x65, 0x13, 0x93, 0x1a, 0x98, 0x90, 0xc6, 0x2d, 0xd5,
  68828. 0x05, 0x2a, 0xfc, 0xcb, 0xac, 0x53, 0x73, 0x93, 0x42, 0x4e, 0xdb, 0x17,
  68829. 0x91, 0xcb, 0xe1, 0x08, 0x03, 0xd1, 0x33, 0x57, 0x4b, 0x1d, 0xb8, 0x71,
  68830. 0x84, 0x01, 0x04, 0x47, 0x6f, 0x06, 0xfa, 0x76, 0x7d, 0xd9, 0x37, 0x64,
  68831. 0x57, 0x37, 0x3a, 0x8f, 0x4d, 0x88, 0x11, 0xa5, 0xd4, 0xaa, 0xcb, 0x49,
  68832. 0x47, 0x86, 0xdd, 0xcf, 0x46, 0xa6, 0xfa, 0x8e, 0xf2, 0x62, 0x0f, 0xc9,
  68833. 0x25, 0xf2, 0x39, 0x62, 0x3e, 0x2d, 0x35, 0xc4, 0x76, 0x7b, 0xae, 0xd5,
  68834. 0xe8, 0x85, 0xa1, 0xa6, 0x2d, 0x41, 0xd6, 0x8e, 0x3c, 0xfa, 0xdc, 0x6c,
  68835. 0x66, 0xe2, 0x61, 0xe7, 0xe5, 0x90, 0xa1, 0xfd, 0x7f, 0xdb, 0x18, 0xd0,
  68836. 0xeb, 0x6d, 0x73, 0x08, 0x5f, 0x6a, 0x65, 0x44, 0x50, 0xad, 0x38, 0x9d,
  68837. 0xb6, 0xfb, 0xbf, 0x28, 0x55, 0x84, 0x65, 0xfa, 0x0e, 0x34, 0xfc, 0x43,
  68838. 0x19, 0x80, 0x5c, 0x7d, 0x2d, 0x5b, 0xd8, 0x60, 0xec, 0x0e, 0xf9, 0x1e,
  68839. 0x6e, 0x32, 0x3f, 0x35, 0xf7, 0xec, 0x7e, 0x47, 0xba, 0xb5, 0xd2, 0xaa,
  68840. 0x5a, 0x9d, 0x07, 0x2c, 0xc5, 0xa0, 0x82, 0x04, 0xc6, 0x30, 0x82, 0x04,
  68841. 0xc2, 0x30, 0x82, 0x04, 0xbe, 0x30, 0x82, 0x03, 0xa6, 0xa0, 0x03, 0x02,
  68842. 0x01, 0x02, 0x02, 0x01, 0x04, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48,
  68843. 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x81, 0x97, 0x31,
  68844. 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53,
  68845. 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x57,
  68846. 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67, 0x74, 0x6f, 0x6e, 0x31, 0x10, 0x30,
  68847. 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x53, 0x65, 0x61, 0x74,
  68848. 0x74, 0x6c, 0x65, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a,
  68849. 0x0c, 0x07, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x31, 0x14, 0x30,
  68850. 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69,
  68851. 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18, 0x30, 0x16, 0x06,
  68852. 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53,
  68853. 0x4c, 0x20, 0x72, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x31, 0x1f, 0x30,
  68854. 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01,
  68855. 0x16, 0x10, 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, 0x66, 0x73,
  68856. 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x34,
  68857. 0x30, 0x37, 0x32, 0x36, 0x31, 0x35, 0x31, 0x32, 0x30, 0x34, 0x5a, 0x17,
  68858. 0x0d, 0x32, 0x37, 0x30, 0x34, 0x32, 0x32, 0x31, 0x35, 0x31, 0x32, 0x30,
  68859. 0x34, 0x5a, 0x30, 0x81, 0x9e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55,
  68860. 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03,
  68861. 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67,
  68862. 0x74, 0x6f, 0x6e, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07,
  68863. 0x0c, 0x07, 0x53, 0x65, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10, 0x30,
  68864. 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x77, 0x6f, 0x6c, 0x66,
  68865. 0x53, 0x53, 0x4c, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b,
  68866. 0x0c, 0x0b, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e,
  68867. 0x67, 0x31, 0x1f, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x16,
  68868. 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x20, 0x4f, 0x43, 0x53, 0x50,
  68869. 0x20, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x64, 0x65, 0x72, 0x31, 0x1f,
  68870. 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09,
  68871. 0x01, 0x16, 0x10, 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, 0x66,
  68872. 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x82, 0x01, 0x22, 0x30,
  68873. 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  68874. 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02,
  68875. 0x82, 0x01, 0x01, 0x00, 0xb8, 0xba, 0x23, 0xb4, 0xf6, 0xc3, 0x7b, 0x14,
  68876. 0xc3, 0xa4, 0xf5, 0x1d, 0x61, 0xa1, 0xf5, 0x1e, 0x63, 0xb9, 0x85, 0x23,
  68877. 0x34, 0x50, 0x6d, 0xf8, 0x7c, 0xa2, 0x8a, 0x04, 0x8b, 0xd5, 0x75, 0x5c,
  68878. 0x2d, 0xf7, 0x63, 0x88, 0xd1, 0x07, 0x7a, 0xea, 0x0b, 0x45, 0x35, 0x2b,
  68879. 0xeb, 0x1f, 0xb1, 0x22, 0xb4, 0x94, 0x41, 0x38, 0xe2, 0x9d, 0x74, 0xd6,
  68880. 0x8b, 0x30, 0x22, 0x10, 0x51, 0xc5, 0xdb, 0xca, 0x3f, 0x46, 0x2b, 0xfe,
  68881. 0xe5, 0x5a, 0x3f, 0x41, 0x74, 0x67, 0x75, 0x95, 0xa9, 0x94, 0xd5, 0xc3,
  68882. 0xee, 0x42, 0xf8, 0x8d, 0xeb, 0x92, 0x95, 0xe1, 0xd9, 0x65, 0xb7, 0x43,
  68883. 0xc4, 0x18, 0xde, 0x16, 0x80, 0x90, 0xce, 0x24, 0x35, 0x21, 0xc4, 0x55,
  68884. 0xac, 0x5a, 0x51, 0xe0, 0x2e, 0x2d, 0xb3, 0x0a, 0x5a, 0x4f, 0x4a, 0x73,
  68885. 0x31, 0x50, 0xee, 0x4a, 0x16, 0xbd, 0x39, 0x8b, 0xad, 0x05, 0x48, 0x87,
  68886. 0xb1, 0x99, 0xe2, 0x10, 0xa7, 0x06, 0x72, 0x67, 0xca, 0x5c, 0xd1, 0x97,
  68887. 0xbd, 0xc8, 0xf1, 0x76, 0xf8, 0xe0, 0x4a, 0xec, 0xbc, 0x93, 0xf4, 0x66,
  68888. 0x4c, 0x28, 0x71, 0xd1, 0xd8, 0x66, 0x03, 0xb4, 0x90, 0x30, 0xbb, 0x17,
  68889. 0xb0, 0xfe, 0x97, 0xf5, 0x1e, 0xe8, 0xc7, 0x5d, 0x9b, 0x8b, 0x11, 0x19,
  68890. 0x12, 0x3c, 0xab, 0x82, 0x71, 0x78, 0xff, 0xae, 0x3f, 0x32, 0xb2, 0x08,
  68891. 0x71, 0xb2, 0x1b, 0x8c, 0x27, 0xac, 0x11, 0xb8, 0xd8, 0x43, 0x49, 0xcf,
  68892. 0xb0, 0x70, 0xb1, 0xf0, 0x8c, 0xae, 0xda, 0x24, 0x87, 0x17, 0x3b, 0xd8,
  68893. 0x04, 0x65, 0x6c, 0x00, 0x76, 0x50, 0xef, 0x15, 0x08, 0xd7, 0xb4, 0x73,
  68894. 0x68, 0x26, 0x14, 0x87, 0x95, 0xc3, 0x5f, 0x6e, 0x61, 0xb8, 0x87, 0x84,
  68895. 0xfa, 0x80, 0x1a, 0x0a, 0x8b, 0x98, 0xf3, 0xe3, 0xff, 0x4e, 0x44, 0x1c,
  68896. 0x65, 0x74, 0x7c, 0x71, 0x54, 0x65, 0xe5, 0x39, 0x02, 0x03, 0x01, 0x00,
  68897. 0x01, 0xa3, 0x82, 0x01, 0x0a, 0x30, 0x82, 0x01, 0x06, 0x30, 0x09, 0x06,
  68898. 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, 0x00, 0x30, 0x1d, 0x06, 0x03,
  68899. 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x32, 0x67, 0xe1, 0xb1, 0x79,
  68900. 0xd2, 0x81, 0xfc, 0x9f, 0x23, 0x0c, 0x70, 0x40, 0x50, 0xb5, 0x46, 0x56,
  68901. 0xb8, 0x30, 0x36, 0x30, 0x81, 0xc4, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04,
  68902. 0x81, 0xbc, 0x30, 0x81, 0xb9, 0x80, 0x14, 0x73, 0xb0, 0x1c, 0xa4, 0x2f,
  68903. 0x82, 0xcb, 0xcf, 0x47, 0xa5, 0x38, 0xd7, 0xb0, 0x04, 0x82, 0x3a, 0x7e,
  68904. 0x72, 0x15, 0x21, 0xa1, 0x81, 0x9d, 0xa4, 0x81, 0x9a, 0x30, 0x81, 0x97,
  68905. 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55,
  68906. 0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a,
  68907. 0x57, 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67, 0x74, 0x6f, 0x6e, 0x31, 0x10,
  68908. 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x53, 0x65, 0x61,
  68909. 0x74, 0x74, 0x6c, 0x65, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04,
  68910. 0x0a, 0x0c, 0x07, 0x77, 0x6f, 0x6c, 0x66, 0x53, 0x53, 0x4c, 0x31, 0x14,
  68911. 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x45, 0x6e, 0x67,
  68912. 0x69, 0x6e, 0x65, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x31, 0x18, 0x30, 0x16,
  68913. 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x6f, 0x6c, 0x66, 0x53,
  68914. 0x53, 0x4c, 0x20, 0x72, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x31, 0x1f,
  68915. 0x30, 0x1d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09,
  68916. 0x01, 0x16, 0x10, 0x69, 0x6e, 0x66, 0x6f, 0x40, 0x77, 0x6f, 0x6c, 0x66,
  68917. 0x73, 0x73, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x82, 0x01, 0x63, 0x30, 0x13,
  68918. 0x06, 0x03, 0x55, 0x1d, 0x25, 0x04, 0x0c, 0x30, 0x0a, 0x06, 0x08, 0x2b,
  68919. 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x09, 0x30, 0x0d, 0x06, 0x09, 0x2a,
  68920. 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82,
  68921. 0x01, 0x01, 0x00, 0x37, 0xb9, 0x66, 0xd3, 0xa1, 0x08, 0xfc, 0x37, 0x58,
  68922. 0x4e, 0xe0, 0x8c, 0xd3, 0x7f, 0xa6, 0x0f, 0x59, 0xd3, 0x14, 0xf7, 0x4b,
  68923. 0x36, 0xf7, 0x2e, 0x98, 0xeb, 0x7c, 0x03, 0x3f, 0x3a, 0xd6, 0x9c, 0xcd,
  68924. 0xb4, 0x9e, 0x8d, 0x5f, 0x92, 0xa6, 0x6f, 0x63, 0x87, 0x34, 0xe8, 0x83,
  68925. 0xfd, 0x6d, 0x34, 0x64, 0xb5, 0xf0, 0x9c, 0x71, 0x02, 0xb8, 0xf6, 0x2f,
  68926. 0x10, 0xa0, 0x92, 0x8f, 0x3f, 0x86, 0x3e, 0xe2, 0x01, 0x5a, 0x56, 0x39,
  68927. 0x0a, 0x8d, 0xb1, 0xbe, 0x03, 0xf7, 0xf8, 0xa7, 0x88, 0x46, 0xef, 0x81,
  68928. 0xa0, 0xad, 0x86, 0xc9, 0xe6, 0x23, 0x89, 0x1d, 0xa6, 0x24, 0x45, 0xf2,
  68929. 0x6a, 0x83, 0x2d, 0x8e, 0x92, 0x17, 0x1e, 0x44, 0x19, 0xfa, 0x0f, 0x47,
  68930. 0x6b, 0x8f, 0x4a, 0xa2, 0xda, 0xab, 0xd5, 0x2b, 0xcd, 0xcb, 0x14, 0xf0,
  68931. 0xb5, 0xcf, 0x7c, 0x76, 0x42, 0x32, 0x90, 0x21, 0xdc, 0xdd, 0x52, 0xfc,
  68932. 0x53, 0x7e, 0xff, 0x7f, 0xd9, 0x58, 0x6b, 0x1f, 0x73, 0xee, 0x83, 0xf4,
  68933. 0x67, 0xfa, 0x4a, 0x4f, 0x24, 0xe4, 0x2b, 0x10, 0x74, 0x89, 0x52, 0x9a,
  68934. 0xf7, 0xa4, 0xe0, 0xaf, 0xf5, 0x63, 0xd7, 0xfa, 0x0b, 0x2c, 0xc9, 0x39,
  68935. 0x5d, 0xbd, 0x44, 0x93, 0x69, 0xa4, 0x1d, 0x01, 0xe2, 0x66, 0xe7, 0xc1,
  68936. 0x11, 0x44, 0x7d, 0x0a, 0x7e, 0x5d, 0x1d, 0x26, 0xc5, 0x4a, 0x26, 0x2e,
  68937. 0xa3, 0x58, 0xc4, 0xf7, 0x10, 0xcb, 0xba, 0xe6, 0x27, 0xfc, 0xdb, 0x54,
  68938. 0xe2, 0x60, 0x08, 0xc2, 0x0e, 0x4b, 0xd4, 0xaa, 0x22, 0x23, 0x93, 0x9f,
  68939. 0xe1, 0xcb, 0x85, 0xa4, 0x41, 0x6f, 0x26, 0xa7, 0x77, 0x8a, 0xef, 0x66,
  68940. 0xd0, 0xf8, 0x33, 0xf6, 0xfd, 0x6d, 0x37, 0x7a, 0x89, 0xcc, 0x88, 0x3b,
  68941. 0x82, 0xd0, 0xa9, 0xdf, 0xf1, 0x3d, 0xdc, 0xb0, 0x06, 0x1c, 0xe4, 0x4b,
  68942. 0x57, 0xb4, 0x0c, 0x65, 0xb9, 0xb4, 0x6c
  68943. };
  68944. OCSP_REQ_CTX *ctx = NULL;
  68945. OCSP_REQUEST *req = NULL;
  68946. OCSP_CERTID *cid = NULL;
  68947. OCSP_RESPONSE *rsp = NULL;
  68948. BIO* bio1 = NULL;
  68949. BIO* bio2 = NULL;
  68950. X509* cert = NULL;
  68951. X509 *issuer = NULL;
  68952. X509_LOOKUP *lookup = NULL;
  68953. X509_STORE *store = NULL;
  68954. STACK_OF(X509_OBJECT) *str_objs = NULL;
  68955. X509_OBJECT *x509_obj = NULL;
  68956. ExpectNotNull(bio1 = BIO_new(BIO_s_bio()));
  68957. ExpectNotNull(bio2 = BIO_new(BIO_s_bio()));
  68958. ExpectIntEQ(BIO_make_bio_pair(bio1, bio2), WOLFSSL_SUCCESS);
  68959. /* Load the leaf cert */
  68960. ExpectNotNull(cert = wolfSSL_X509_load_certificate_file(
  68961. "certs/ocsp/server1-cert.pem", WOLFSSL_FILETYPE_PEM));
  68962. ExpectNotNull(store = X509_STORE_new());
  68963. ExpectNotNull(lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()));
  68964. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/ocsp/server1-cert.pem",
  68965. X509_FILETYPE_PEM), 1);
  68966. ExpectNotNull(str_objs = X509_STORE_get0_objects(store));
  68967. ExpectNotNull(x509_obj = X509_OBJECT_retrieve_by_subject(str_objs,
  68968. X509_LU_X509, X509_get_issuer_name(cert)));
  68969. ExpectNotNull(issuer = X509_OBJECT_get0_X509(x509_obj));
  68970. ExpectNotNull(req = OCSP_REQUEST_new());
  68971. ExpectNotNull(cid = OCSP_cert_to_id(EVP_sha1(), cert, issuer));
  68972. ExpectNotNull(OCSP_request_add0_id(req, cid));
  68973. ExpectIntEQ(OCSP_request_add1_nonce(req, NULL, -1), 1);
  68974. ExpectNotNull(ctx = OCSP_sendreq_new(bio1, "/", NULL, -1));
  68975. ExpectIntEQ(OCSP_REQ_CTX_add1_header(ctx, "Host", "127.0.0.1"), 1);
  68976. ExpectIntEQ(OCSP_REQ_CTX_set1_req(ctx, req), 1);
  68977. ExpectIntEQ(OCSP_sendreq_nbio(&rsp, ctx), -1);
  68978. ExpectIntEQ(BIO_write(bio2, ocspRespBin, sizeof(ocspRespBin)),
  68979. sizeof(ocspRespBin));
  68980. ExpectIntEQ(wc_SetTimeCb(test_wolfSSL_OCSP_REQ_CTX_time_cb), 0);
  68981. ExpectIntEQ(OCSP_sendreq_nbio(&rsp, ctx), 1);
  68982. ExpectIntEQ(wc_SetTimeCb(NULL), 0);
  68983. ExpectNotNull(rsp);
  68984. OCSP_REQ_CTX_free(ctx);
  68985. OCSP_REQUEST_free(req);
  68986. OCSP_RESPONSE_free(rsp);
  68987. BIO_free(bio1);
  68988. BIO_free(bio2);
  68989. X509_free(cert);
  68990. X509_STORE_free(store);
  68991. #endif
  68992. return EXPECT_RESULT();
  68993. }
  68994. static int test_wolfSSL_EVP_PKEY_derive(void)
  68995. {
  68996. EXPECT_DECLS;
  68997. #if defined(OPENSSL_ALL) || defined(WOLFSSL_QT) || defined(WOLFSSL_OPENSSH)
  68998. #if (!defined(NO_DH) && defined(WOLFSSL_DH_EXTRA)) || defined(HAVE_ECC)
  68999. EVP_PKEY_CTX *ctx = NULL;
  69000. unsigned char *skey = NULL;
  69001. size_t skeylen;
  69002. EVP_PKEY *pkey = NULL;
  69003. EVP_PKEY *peerkey = NULL;
  69004. const unsigned char* key;
  69005. #if !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA)
  69006. /* DH */
  69007. key = dh_key_der_2048;
  69008. ExpectNotNull((pkey = d2i_PrivateKey(EVP_PKEY_DH, NULL, &key,
  69009. sizeof_dh_key_der_2048)));
  69010. ExpectIntEQ(DH_generate_key(EVP_PKEY_get0_DH(pkey)), 1);
  69011. key = dh_key_der_2048;
  69012. ExpectNotNull((peerkey = d2i_PrivateKey(EVP_PKEY_DH, NULL, &key,
  69013. sizeof_dh_key_der_2048)));
  69014. ExpectIntEQ(DH_generate_key(EVP_PKEY_get0_DH(peerkey)), 1);
  69015. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  69016. ExpectIntEQ(EVP_PKEY_derive_init(ctx), 1);
  69017. ExpectIntEQ(EVP_PKEY_derive_set_peer(ctx, peerkey), 1);
  69018. ExpectIntEQ(EVP_PKEY_derive(ctx, NULL, &skeylen), 1);
  69019. ExpectNotNull(skey = (unsigned char*)XMALLOC(skeylen, NULL,
  69020. DYNAMIC_TYPE_OPENSSL));
  69021. ExpectIntEQ(EVP_PKEY_derive(ctx, skey, &skeylen), 1);
  69022. EVP_PKEY_CTX_free(ctx);
  69023. ctx = NULL;
  69024. EVP_PKEY_free(peerkey);
  69025. peerkey = NULL;
  69026. EVP_PKEY_free(pkey);
  69027. pkey = NULL;
  69028. XFREE(skey, NULL, DYNAMIC_TYPE_OPENSSL);
  69029. skey = NULL;
  69030. #endif
  69031. #ifdef HAVE_ECC
  69032. /* ECDH */
  69033. key = ecc_clikey_der_256;
  69034. ExpectNotNull((pkey = d2i_PrivateKey(EVP_PKEY_EC, NULL, &key,
  69035. sizeof_ecc_clikey_der_256)));
  69036. key = ecc_clikeypub_der_256;
  69037. ExpectNotNull((peerkey = d2i_PUBKEY(NULL, &key,
  69038. sizeof_ecc_clikeypub_der_256)));
  69039. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  69040. ExpectIntEQ(EVP_PKEY_derive_init(ctx), 1);
  69041. ExpectIntEQ(EVP_PKEY_derive_set_peer(ctx, peerkey), 1);
  69042. ExpectIntEQ(EVP_PKEY_derive(ctx, NULL, &skeylen), 1);
  69043. ExpectNotNull(skey = (unsigned char*)XMALLOC(skeylen, NULL,
  69044. DYNAMIC_TYPE_OPENSSL));
  69045. ExpectIntEQ(EVP_PKEY_derive(ctx, skey, &skeylen), 1);
  69046. EVP_PKEY_CTX_free(ctx);
  69047. EVP_PKEY_free(peerkey);
  69048. EVP_PKEY_free(pkey);
  69049. XFREE(skey, NULL, DYNAMIC_TYPE_OPENSSL);
  69050. #endif /* HAVE_ECC */
  69051. #endif /* (!NO_DH && WOLFSSL_DH_EXTRA) || HAVE_ECC */
  69052. #endif /* OPENSSL_ALL || WOLFSSL_QT || WOLFSSL_OPENSSH */
  69053. return EXPECT_RESULT();
  69054. }
  69055. static int test_wolfSSL_EVP_PBE_scrypt(void)
  69056. {
  69057. EXPECT_DECLS;
  69058. #if defined(OPENSSL_EXTRA) && defined(HAVE_SCRYPT) && defined(HAVE_PBKDF2) && \
  69059. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 5))
  69060. #if !defined(NO_PWDBASED) && !defined(NO_SHA256)
  69061. int ret;
  69062. const char pwd[] = {'p','a','s','s','w','o','r','d'};
  69063. int pwdlen = sizeof(pwd);
  69064. const byte salt[] = {'N','a','C','l'};
  69065. int saltlen = sizeof(salt);
  69066. byte key[80];
  69067. word64 numOvr32 = (word64)INT32_MAX + 1;
  69068. /* expected derived key for N:16, r:1, p:1 */
  69069. const byte expectedKey[] = {
  69070. 0xAE, 0xC6, 0xB7, 0x48, 0x3E, 0xD2, 0x6E, 0x08, 0x80, 0x2B,
  69071. 0x41, 0xF4, 0x03, 0x20, 0x86, 0xA0, 0xE8, 0x86, 0xBE, 0x7A,
  69072. 0xC4, 0x8F, 0xCF, 0xD9, 0x2F, 0xF0, 0xCE, 0xF8, 0x10, 0x97,
  69073. 0x52, 0xF4, 0xAC, 0x74, 0xB0, 0x77, 0x26, 0x32, 0x56, 0xA6,
  69074. 0x5A, 0x99, 0x70, 0x1B, 0x7A, 0x30, 0x4D, 0x46, 0x61, 0x1C,
  69075. 0x8A, 0xA3, 0x91, 0xE7, 0x99, 0xCE, 0x10, 0xA2, 0x77, 0x53,
  69076. 0xE7, 0xE9, 0xC0, 0x9A};
  69077. /* N r p mx key keylen */
  69078. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 0, 1, 1, 0, key, 64);
  69079. ExpectIntEQ(ret, 0); /* N must be greater than 1 */
  69080. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 3, 1, 1, 0, key, 64);
  69081. ExpectIntEQ(ret, 0); /* N must be power of 2 */
  69082. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 0, 1, 0, key, 64);
  69083. ExpectIntEQ(ret, 0); /* r must be greater than 0 */
  69084. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 1, 0, 0, key, 64);
  69085. ExpectIntEQ(ret, 0); /* p must be greater than 0 */
  69086. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 1, 1, 0, key, 0);
  69087. ExpectIntEQ(ret, 0); /* keylen must be greater than 0 */
  69088. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 9, 1, 0, key, 64);
  69089. ExpectIntEQ(ret, 0); /* r must be smaller than 9 */
  69090. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 1, 1, 0, NULL, 64);
  69091. ExpectIntEQ(ret, 1); /* should succeed if key is NULL */
  69092. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 1, 1, 0, key, 64);
  69093. ExpectIntEQ(ret, 1); /* should succeed */
  69094. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, numOvr32, 1, 0,
  69095. key, 64);
  69096. ExpectIntEQ(ret, 0); /* should fail since r is greater than INT32_MAC */
  69097. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 2, 1, numOvr32, 0,
  69098. key, 64);
  69099. ExpectIntEQ(ret, 0); /* should fail since p is greater than INT32_MAC */
  69100. ret = EVP_PBE_scrypt(pwd, pwdlen, NULL, 0, 2, 1, 1, 0, key, 64);
  69101. ExpectIntEQ(ret, 1); /* should succeed even if salt is NULL */
  69102. ret = EVP_PBE_scrypt(pwd, pwdlen, NULL, 4, 2, 1, 1, 0, key, 64);
  69103. ExpectIntEQ(ret, 0); /* if salt is NULL, saltlen must be 0, otherwise fail*/
  69104. ret = EVP_PBE_scrypt(NULL, 0, salt, saltlen, 2, 1, 1, 0, key, 64);
  69105. ExpectIntEQ(ret, 1); /* should succeed if pwd is NULL and pwdlen is 0*/
  69106. ret = EVP_PBE_scrypt(NULL, 4, salt, saltlen, 2, 1, 1, 0, key, 64);
  69107. ExpectIntEQ(ret, 0); /* if pwd is NULL, pwdlen must be 0 */
  69108. ret = EVP_PBE_scrypt(NULL, 0, NULL, 0, 2, 1, 1, 0, key, 64);
  69109. ExpectIntEQ(ret, 1); /* should succeed even both pwd and salt are NULL */
  69110. ret = EVP_PBE_scrypt(pwd, pwdlen, salt, saltlen, 16, 1, 1, 0, key, 64);
  69111. ExpectIntEQ(ret, 1);
  69112. ret = XMEMCMP(expectedKey, key, sizeof(expectedKey));
  69113. ExpectIntEQ(ret, 0); /* derived key must be the same as expected-key */
  69114. #endif /* !NO_PWDBASED && !NO_SHA256 */
  69115. #endif /* OPENSSL_EXTRA && HAVE_SCRYPT && HAVE_PBKDF2 */
  69116. return EXPECT_RESULT();
  69117. }
  69118. static int test_no_op_functions(void)
  69119. {
  69120. EXPECT_DECLS;
  69121. #if defined(OPENSSL_EXTRA)
  69122. /* this makes sure wolfSSL can compile and run these no-op functions */
  69123. SSL_load_error_strings();
  69124. ENGINE_load_builtin_engines();
  69125. OpenSSL_add_all_ciphers();
  69126. ExpectIntEQ(CRYPTO_malloc_init(), 0);
  69127. #endif
  69128. return EXPECT_RESULT();
  69129. }
  69130. static int test_wolfSSL_CRYPTO_memcmp(void)
  69131. {
  69132. EXPECT_DECLS;
  69133. #ifdef OPENSSL_EXTRA
  69134. char a[] = "wolfSSL (formerly CyaSSL) is a small, fast, portable "
  69135. "implementation of TLS/SSL for embedded devices to the cloud.";
  69136. char b[] = "wolfSSL (formerly CyaSSL) is a small, fast, portable "
  69137. "implementation of TLS/SSL for embedded devices to the cloud.";
  69138. char c[] = "wolfSSL (formerly CyaSSL) is a small, fast, portable "
  69139. "implementation of TLS/SSL for embedded devices to the cloud!";
  69140. ExpectIntEQ(CRYPTO_memcmp(a, b, sizeof(a)), 0);
  69141. ExpectIntNE(CRYPTO_memcmp(a, c, sizeof(a)), 0);
  69142. #endif
  69143. return EXPECT_RESULT();
  69144. }
  69145. /*----------------------------------------------------------------------------*
  69146. | wolfCrypt ASN
  69147. *----------------------------------------------------------------------------*/
  69148. static int test_wc_CreateEncryptedPKCS8Key(void)
  69149. {
  69150. EXPECT_DECLS;
  69151. #if defined(HAVE_PKCS8) && !defined(NO_PWDBASED) && defined(WOLFSSL_AES_256) \
  69152. && !defined(NO_AES_CBC) && !defined(NO_RSA) && !defined(NO_SHA) && \
  69153. !defined(NO_ASN_CRYPT)
  69154. WC_RNG rng;
  69155. byte* encKey = NULL;
  69156. word32 encKeySz = 0;
  69157. word32 decKeySz = 0;
  69158. const char password[] = "Lorem ipsum dolor sit amet";
  69159. word32 passwordSz = (word32)XSTRLEN(password);
  69160. word32 tradIdx = 0;
  69161. XMEMSET(&rng, 0, sizeof(WC_RNG));
  69162. ExpectIntEQ(wc_InitRng(&rng), 0);
  69163. PRIVATE_KEY_UNLOCK();
  69164. /* Call with NULL for out buffer to get necessary length. */
  69165. ExpectIntEQ(wc_CreateEncryptedPKCS8Key((byte*)server_key_der_2048,
  69166. sizeof_server_key_der_2048, NULL, &encKeySz, password, (int)passwordSz,
  69167. PKCS5, PBES2, AES256CBCb, NULL, 0, WC_PKCS12_ITT_DEFAULT, &rng, NULL),
  69168. WC_NO_ERR_TRACE(LENGTH_ONLY_E));
  69169. ExpectNotNull(encKey = (byte*)XMALLOC(encKeySz, HEAP_HINT,
  69170. DYNAMIC_TYPE_TMP_BUFFER));
  69171. /* Call with the allocated out buffer. */
  69172. ExpectIntGT(wc_CreateEncryptedPKCS8Key((byte*)server_key_der_2048,
  69173. sizeof_server_key_der_2048, encKey, &encKeySz, password, (int)passwordSz,
  69174. PKCS5, PBES2, AES256CBCb, NULL, 0, WC_PKCS12_ITT_DEFAULT, &rng, NULL),
  69175. 0);
  69176. /* Decrypt the encrypted PKCS8 key we just made. */
  69177. ExpectIntGT((decKeySz = (word32)wc_DecryptPKCS8Key(encKey, encKeySz, password,
  69178. (int)passwordSz)), 0);
  69179. /* encKey now holds the decrypted key (decrypted in place). */
  69180. ExpectIntGT(wc_GetPkcs8TraditionalOffset(encKey, &tradIdx, decKeySz), 0);
  69181. /* Check that the decrypted key matches the key prior to encryption. */
  69182. ExpectIntEQ(XMEMCMP(encKey + tradIdx, server_key_der_2048,
  69183. sizeof_server_key_der_2048), 0);
  69184. PRIVATE_KEY_LOCK();
  69185. XFREE(encKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  69186. wc_FreeRng(&rng);
  69187. #endif
  69188. return EXPECT_RESULT();
  69189. }
  69190. static int test_wc_GetPkcs8TraditionalOffset(void)
  69191. {
  69192. EXPECT_DECLS;
  69193. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(HAVE_PKCS8)
  69194. int length;
  69195. int derSz = 0;
  69196. word32 inOutIdx;
  69197. const char* path = "./certs/server-keyPkcs8.der";
  69198. const char* pathAttributes = "./certs/ca-key-pkcs8-attribute.der";
  69199. XFILE file = XBADFILE;
  69200. byte der[2048];
  69201. ExpectTrue((file = XFOPEN(path, "rb")) != XBADFILE);
  69202. ExpectIntGT(derSz = (int)XFREAD(der, 1, sizeof(der), file), 0);
  69203. if (file != XBADFILE)
  69204. XFCLOSE(file);
  69205. file = XBADFILE; /* reset file to avoid warning of use after close */
  69206. /* valid case */
  69207. inOutIdx = 0;
  69208. ExpectIntGT(length = wc_GetPkcs8TraditionalOffset(der, &inOutIdx, (word32)derSz),
  69209. 0);
  69210. /* inOutIdx > sz */
  69211. inOutIdx = 4000;
  69212. ExpectIntEQ(length = wc_GetPkcs8TraditionalOffset(der, &inOutIdx, (word32)derSz),
  69213. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  69214. /* null input */
  69215. inOutIdx = 0;
  69216. ExpectIntEQ(length = wc_GetPkcs8TraditionalOffset(NULL, &inOutIdx, 0),
  69217. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  69218. /* invalid input, fill buffer with 1's */
  69219. XMEMSET(der, 1, sizeof(der));
  69220. inOutIdx = 0;
  69221. ExpectIntEQ(length = wc_GetPkcs8TraditionalOffset(der, &inOutIdx, (word32)derSz),
  69222. WC_NO_ERR_TRACE(ASN_PARSE_E));
  69223. /* test parsing with attributes */
  69224. ExpectTrue((file = XFOPEN(pathAttributes, "rb")) != XBADFILE);
  69225. ExpectIntGT(derSz = (int)XFREAD(der, 1, sizeof(der), file), 0);
  69226. if (file != XBADFILE)
  69227. XFCLOSE(file);
  69228. inOutIdx = 0;
  69229. ExpectIntGT(length = wc_GetPkcs8TraditionalOffset(der, &inOutIdx,
  69230. (word32)derSz), 0);
  69231. #endif /* NO_ASN */
  69232. return EXPECT_RESULT();
  69233. }
  69234. static int test_wc_SetSubjectRaw(void)
  69235. {
  69236. EXPECT_DECLS;
  69237. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  69238. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT) && !defined(NO_RSA)
  69239. const char* joiCertFile = "./certs/test/cert-ext-joi.der";
  69240. WOLFSSL_X509* x509 = NULL;
  69241. int peerCertSz;
  69242. const byte* peerCertBuf = NULL;
  69243. Cert forgedCert;
  69244. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(joiCertFile,
  69245. WOLFSSL_FILETYPE_ASN1));
  69246. ExpectNotNull(peerCertBuf = wolfSSL_X509_get_der(x509, &peerCertSz));
  69247. ExpectIntEQ(0, wc_InitCert(&forgedCert));
  69248. ExpectIntEQ(0, wc_SetSubjectRaw(&forgedCert, peerCertBuf, peerCertSz));
  69249. wolfSSL_FreeX509(x509);
  69250. #endif
  69251. return EXPECT_RESULT();
  69252. }
  69253. static int test_wc_GetSubjectRaw(void)
  69254. {
  69255. EXPECT_DECLS;
  69256. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  69257. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT)
  69258. Cert cert;
  69259. byte *subjectRaw;
  69260. ExpectIntEQ(0, wc_InitCert(&cert));
  69261. ExpectIntEQ(0, wc_GetSubjectRaw(&subjectRaw, &cert));
  69262. #endif
  69263. return EXPECT_RESULT();
  69264. }
  69265. static int test_wc_SetIssuerRaw(void)
  69266. {
  69267. EXPECT_DECLS;
  69268. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  69269. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT) && !defined(NO_RSA)
  69270. const char* joiCertFile = "./certs/test/cert-ext-joi.der";
  69271. WOLFSSL_X509* x509 = NULL;
  69272. int peerCertSz;
  69273. const byte* peerCertBuf = NULL;
  69274. Cert forgedCert;
  69275. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(joiCertFile,
  69276. WOLFSSL_FILETYPE_ASN1));
  69277. ExpectNotNull(peerCertBuf = wolfSSL_X509_get_der(x509, &peerCertSz));
  69278. ExpectIntEQ(0, wc_InitCert(&forgedCert));
  69279. ExpectIntEQ(0, wc_SetIssuerRaw(&forgedCert, peerCertBuf, peerCertSz));
  69280. wolfSSL_FreeX509(x509);
  69281. #endif
  69282. return EXPECT_RESULT();
  69283. }
  69284. static int test_wc_SetIssueBuffer(void)
  69285. {
  69286. EXPECT_DECLS;
  69287. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  69288. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT) && !defined(NO_RSA)
  69289. const char* joiCertFile = "./certs/test/cert-ext-joi.der";
  69290. WOLFSSL_X509* x509 = NULL;
  69291. int peerCertSz;
  69292. const byte* peerCertBuf = NULL;
  69293. Cert forgedCert;
  69294. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(joiCertFile,
  69295. WOLFSSL_FILETYPE_ASN1));
  69296. ExpectNotNull(peerCertBuf = wolfSSL_X509_get_der(x509, &peerCertSz));
  69297. ExpectIntEQ(0, wc_InitCert(&forgedCert));
  69298. ExpectIntEQ(0, wc_SetIssuerBuffer(&forgedCert, peerCertBuf, peerCertSz));
  69299. wolfSSL_FreeX509(x509);
  69300. #endif
  69301. return EXPECT_RESULT();
  69302. }
  69303. /*
  69304. * Testing wc_SetSubjectKeyId
  69305. */
  69306. static int test_wc_SetSubjectKeyId(void)
  69307. {
  69308. EXPECT_DECLS;
  69309. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  69310. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT) && defined(HAVE_ECC)
  69311. Cert cert;
  69312. const char* file = "certs/ecc-client-keyPub.pem";
  69313. ExpectIntEQ(0, wc_InitCert(&cert));
  69314. ExpectIntEQ(0, wc_SetSubjectKeyId(&cert, file));
  69315. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SetSubjectKeyId(NULL, file));
  69316. ExpectIntGT(0, wc_SetSubjectKeyId(&cert, "badfile.name"));
  69317. #endif
  69318. return EXPECT_RESULT();
  69319. } /* END test_wc_SetSubjectKeyId */
  69320. /*
  69321. * Testing wc_SetSubject
  69322. */
  69323. static int test_wc_SetSubject(void)
  69324. {
  69325. EXPECT_DECLS;
  69326. #if !defined(NO_ASN) && !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && \
  69327. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_EXT) && defined(HAVE_ECC)
  69328. Cert cert;
  69329. const char* file = "./certs/ca-ecc-cert.pem";
  69330. ExpectIntEQ(0, wc_InitCert(&cert));
  69331. ExpectIntEQ(0, wc_SetSubject(&cert, file));
  69332. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_SetSubject(NULL, file));
  69333. ExpectIntGT(0, wc_SetSubject(&cert, "badfile.name"));
  69334. #endif
  69335. return EXPECT_RESULT();
  69336. } /* END test_wc_SetSubject */
  69337. static int test_CheckCertSignature(void)
  69338. {
  69339. EXPECT_DECLS;
  69340. #if !defined(NO_CERTS) && defined(WOLFSSL_SMALL_CERT_VERIFY)
  69341. WOLFSSL_CERT_MANAGER* cm = NULL;
  69342. #if !defined(NO_FILESYSTEM) && (!defined(NO_RSA) || defined(HAVE_ECC))
  69343. XFILE fp = XBADFILE;
  69344. byte cert[4096];
  69345. int certSz;
  69346. #endif
  69347. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_CheckCertSignature(NULL, 0, NULL, NULL));
  69348. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  69349. ExpectIntEQ(WC_NO_ERR_TRACE(BAD_FUNC_ARG), wc_CheckCertSignature(NULL, 0, NULL, cm));
  69350. #ifndef NO_RSA
  69351. #ifdef USE_CERT_BUFFERS_1024
  69352. ExpectIntEQ(WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), wc_CheckCertSignature(server_cert_der_1024,
  69353. sizeof_server_cert_der_1024, NULL, cm));
  69354. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCABuffer(cm,
  69355. ca_cert_der_1024, sizeof_ca_cert_der_1024,
  69356. WOLFSSL_FILETYPE_ASN1));
  69357. ExpectIntEQ(0, wc_CheckCertSignature(server_cert_der_1024,
  69358. sizeof_server_cert_der_1024, NULL, cm));
  69359. #elif defined(USE_CERT_BUFFERS_2048)
  69360. ExpectIntEQ(WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), wc_CheckCertSignature(server_cert_der_2048,
  69361. sizeof_server_cert_der_2048, NULL, cm));
  69362. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCABuffer(cm,
  69363. ca_cert_der_2048, sizeof_ca_cert_der_2048,
  69364. WOLFSSL_FILETYPE_ASN1));
  69365. ExpectIntEQ(0, wc_CheckCertSignature(server_cert_der_2048,
  69366. sizeof_server_cert_der_2048, NULL, cm));
  69367. #endif
  69368. #endif
  69369. #if defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  69370. ExpectIntEQ(WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), wc_CheckCertSignature(serv_ecc_der_256,
  69371. sizeof_serv_ecc_der_256, NULL, cm));
  69372. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCABuffer(cm,
  69373. ca_ecc_cert_der_256, sizeof_ca_ecc_cert_der_256,
  69374. WOLFSSL_FILETYPE_ASN1));
  69375. ExpectIntEQ(0, wc_CheckCertSignature(serv_ecc_der_256, sizeof_serv_ecc_der_256,
  69376. NULL, cm));
  69377. #endif
  69378. #if !defined(NO_FILESYSTEM)
  69379. wolfSSL_CertManagerFree(cm);
  69380. cm = NULL;
  69381. ExpectNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
  69382. #ifndef NO_RSA
  69383. ExpectTrue((fp = XFOPEN("./certs/server-cert.der", "rb")) != XBADFILE);
  69384. ExpectIntGT((certSz = (int)XFREAD(cert, 1, sizeof(cert), fp)), 0);
  69385. if (fp != XBADFILE) {
  69386. XFCLOSE(fp);
  69387. fp = XBADFILE;
  69388. }
  69389. ExpectIntEQ(WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), wc_CheckCertSignature(cert, certSz, NULL, cm));
  69390. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCA(cm,
  69391. "./certs/ca-cert.pem", NULL));
  69392. ExpectIntEQ(0, wc_CheckCertSignature(cert, certSz, NULL, cm));
  69393. #endif
  69394. #ifdef HAVE_ECC
  69395. ExpectTrue((fp = XFOPEN("./certs/server-ecc.der", "rb")) != XBADFILE);
  69396. ExpectIntGT((certSz = (int)XFREAD(cert, 1, sizeof(cert), fp)), 0);
  69397. if (fp != XBADFILE) {
  69398. XFCLOSE(fp);
  69399. fp = XBADFILE;
  69400. }
  69401. ExpectIntEQ(WC_NO_ERR_TRACE(ASN_NO_SIGNER_E), wc_CheckCertSignature(cert, certSz, NULL, cm));
  69402. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CertManagerLoadCA(cm,
  69403. "./certs/ca-ecc-cert.pem", NULL));
  69404. ExpectIntEQ(0, wc_CheckCertSignature(cert, certSz, NULL, cm));
  69405. #endif
  69406. #endif
  69407. #if !defined(NO_FILESYSTEM) && (!defined(NO_RSA) || defined(HAVE_ECC))
  69408. (void)fp;
  69409. (void)cert;
  69410. (void)certSz;
  69411. #endif
  69412. wolfSSL_CertManagerFree(cm);
  69413. #endif
  69414. return EXPECT_RESULT();
  69415. }
  69416. static int test_wc_ParseCert(void)
  69417. {
  69418. EXPECT_DECLS;
  69419. #if !defined(NO_CERTS) && !defined(NO_RSA)
  69420. DecodedCert decodedCert;
  69421. const byte* rawCert = client_cert_der_2048;
  69422. const int rawCertSize = sizeof_client_cert_der_2048;
  69423. wc_InitDecodedCert(&decodedCert, rawCert, rawCertSize, NULL);
  69424. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL), 0);
  69425. #ifndef IGNORE_NAME_CONSTRAINTS
  69426. /* check that the subjects emailAddress was not put in the alt name list */
  69427. ExpectNotNull(decodedCert.subjectEmail);
  69428. ExpectNull(decodedCert.altEmailNames);
  69429. #endif
  69430. wc_FreeDecodedCert(&decodedCert);
  69431. #endif
  69432. return EXPECT_RESULT();
  69433. }
  69434. /* Test wc_ParseCert decoding of various encodings and scenarios ensuring that
  69435. * the API safely errors out on badly-formed ASN input.
  69436. * NOTE: Test not compatible with released FIPS implementations!
  69437. */
  69438. static int test_wc_ParseCert_Error(void)
  69439. {
  69440. EXPECT_DECLS;
  69441. #if !defined(NO_CERTS) && !defined(NO_RSA) && !defined(HAVE_SELFTEST) && \
  69442. (!defined(HAVE_FIPS) || \
  69443. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  69444. DecodedCert decodedCert;
  69445. int i;
  69446. /* Certificate data */
  69447. const byte c0[] = { 0x30, 0x04, 0x30, 0x02, 0x02, 0x80, 0x00, 0x00};
  69448. const byte c1[] = { 0x30, 0x04, 0x30, 0x04, 0x02, 0x80, 0x00, 0x00};
  69449. const byte c2[] = { 0x30, 0x06, 0x30, 0x04, 0x02, 0x80, 0x00, 0x00};
  69450. const byte c3[] = { 0x30, 0x07, 0x30, 0x05, 0x02, 0x80, 0x10, 0x00, 0x00};
  69451. const byte c4[] = { 0x02, 0x80, 0x10, 0x00, 0x00};
  69452. /* Test data */
  69453. const struct testStruct {
  69454. const byte* c;
  69455. word32 cSz;
  69456. const int expRet;
  69457. } t[] = {
  69458. {c0, sizeof(c0), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Invalid bit-string length */
  69459. {c1, sizeof(c1), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Invalid bit-string length */
  69460. {c2, sizeof(c2), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Invalid integer length (zero) */
  69461. {c3, sizeof(c3), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Valid INTEGER, but buffer too short */
  69462. {c4, sizeof(c4), WC_NO_ERR_TRACE(ASN_PARSE_E)}, /* Valid INTEGER, but not in bit-string */
  69463. };
  69464. const int tSz = (int)(sizeof(t) / sizeof(struct testStruct));
  69465. for (i = 0; i < tSz; i++) {
  69466. WOLFSSL_MSG_EX("i == %d", i);
  69467. wc_InitDecodedCert(&decodedCert, t[i].c, t[i].cSz, NULL);
  69468. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL), t[i].expRet);
  69469. wc_FreeDecodedCert(&decodedCert);
  69470. }
  69471. #endif
  69472. return EXPECT_RESULT();
  69473. }
  69474. static int test_MakeCertWithPathLen(void)
  69475. {
  69476. EXPECT_DECLS;
  69477. #if defined(WOLFSSL_CERT_REQ) && !defined(NO_ASN_TIME) && \
  69478. defined(WOLFSSL_CERT_GEN) && defined(HAVE_ECC)
  69479. const byte expectedPathLen = 7;
  69480. Cert cert;
  69481. DecodedCert decodedCert;
  69482. byte der[FOURK_BUF];
  69483. int derSize = 0;
  69484. WC_RNG rng;
  69485. ecc_key key;
  69486. int ret;
  69487. XMEMSET(&rng, 0, sizeof(WC_RNG));
  69488. XMEMSET(&key, 0, sizeof(ecc_key));
  69489. XMEMSET(&cert, 0, sizeof(Cert));
  69490. XMEMSET(&decodedCert, 0, sizeof(DecodedCert));
  69491. ExpectIntEQ(wc_InitRng(&rng), 0);
  69492. ExpectIntEQ(wc_ecc_init(&key), 0);
  69493. ExpectIntEQ(wc_ecc_make_key(&rng, 32, &key), 0);
  69494. ExpectIntEQ(wc_InitCert(&cert), 0);
  69495. (void)XSTRNCPY(cert.subject.country, "US", CTC_NAME_SIZE);
  69496. (void)XSTRNCPY(cert.subject.state, "state", CTC_NAME_SIZE);
  69497. (void)XSTRNCPY(cert.subject.locality, "Bozeman", CTC_NAME_SIZE);
  69498. (void)XSTRNCPY(cert.subject.org, "yourOrgNameHere", CTC_NAME_SIZE);
  69499. (void)XSTRNCPY(cert.subject.unit, "yourUnitNameHere", CTC_NAME_SIZE);
  69500. (void)XSTRNCPY(cert.subject.commonName, "www.yourDomain.com",
  69501. CTC_NAME_SIZE);
  69502. (void)XSTRNCPY(cert.subject.email, "yourEmail@yourDomain.com",
  69503. CTC_NAME_SIZE);
  69504. cert.selfSigned = 1;
  69505. cert.isCA = 1;
  69506. cert.pathLen = expectedPathLen;
  69507. cert.pathLenSet = 1;
  69508. cert.sigType = CTC_SHA256wECDSA;
  69509. #ifdef WOLFSSL_CERT_EXT
  69510. cert.keyUsage |= KEYUSE_KEY_CERT_SIGN;
  69511. #endif
  69512. ExpectIntGE(wc_MakeCert(&cert, der, FOURK_BUF, NULL, &key, &rng), 0);
  69513. ExpectIntGE(derSize = wc_SignCert(cert.bodySz, cert.sigType, der,
  69514. FOURK_BUF, NULL, &key, &rng), 0);
  69515. wc_InitDecodedCert(&decodedCert, der, (word32)derSize, NULL);
  69516. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL), 0);
  69517. ExpectIntEQ(decodedCert.pathLength, expectedPathLen);
  69518. wc_FreeDecodedCert(&decodedCert);
  69519. ret = wc_ecc_free(&key);
  69520. ExpectIntEQ(ret, 0);
  69521. ret = wc_FreeRng(&rng);
  69522. ExpectIntEQ(ret, 0);
  69523. #endif
  69524. return EXPECT_RESULT();
  69525. }
  69526. static int test_MakeCertWith0Ser(void)
  69527. {
  69528. EXPECT_DECLS;
  69529. #if defined(WOLFSSL_CERT_REQ) && !defined(NO_ASN_TIME) && \
  69530. defined(WOLFSSL_CERT_GEN) && defined(HAVE_ECC) && \
  69531. defined(WOLFSSL_ASN_TEMPLATE)
  69532. Cert cert;
  69533. DecodedCert decodedCert;
  69534. byte der[FOURK_BUF];
  69535. int derSize = 0;
  69536. WC_RNG rng;
  69537. ecc_key key;
  69538. int ret;
  69539. XMEMSET(&rng, 0, sizeof(WC_RNG));
  69540. XMEMSET(&key, 0, sizeof(ecc_key));
  69541. XMEMSET(&cert, 0, sizeof(Cert));
  69542. XMEMSET(&decodedCert, 0, sizeof(DecodedCert));
  69543. ExpectIntEQ(wc_InitRng(&rng), 0);
  69544. ExpectIntEQ(wc_ecc_init(&key), 0);
  69545. ExpectIntEQ(wc_ecc_make_key(&rng, 32, &key), 0);
  69546. ExpectIntEQ(wc_InitCert(&cert), 0);
  69547. (void)XSTRNCPY(cert.subject.country, "US", CTC_NAME_SIZE);
  69548. (void)XSTRNCPY(cert.subject.state, "state", CTC_NAME_SIZE);
  69549. (void)XSTRNCPY(cert.subject.locality, "Bozeman", CTC_NAME_SIZE);
  69550. (void)XSTRNCPY(cert.subject.org, "yourOrgNameHere", CTC_NAME_SIZE);
  69551. (void)XSTRNCPY(cert.subject.unit, "yourUnitNameHere", CTC_NAME_SIZE);
  69552. (void)XSTRNCPY(cert.subject.commonName, "www.yourDomain.com",
  69553. CTC_NAME_SIZE);
  69554. (void)XSTRNCPY(cert.subject.email, "yourEmail@yourDomain.com",
  69555. CTC_NAME_SIZE);
  69556. cert.selfSigned = 1;
  69557. cert.isCA = 1;
  69558. cert.sigType = CTC_SHA256wECDSA;
  69559. #ifdef WOLFSSL_CERT_EXT
  69560. cert.keyUsage |= KEYUSE_KEY_CERT_SIGN;
  69561. #endif
  69562. /* set serial number to 0 */
  69563. cert.serialSz = 1;
  69564. cert.serial[0] = 0;
  69565. ExpectIntGE(wc_MakeCert(&cert, der, FOURK_BUF, NULL, &key, &rng), 0);
  69566. ExpectIntGE(derSize = wc_SignCert(cert.bodySz, cert.sigType, der,
  69567. FOURK_BUF, NULL, &key, &rng), 0);
  69568. wc_InitDecodedCert(&decodedCert, der, (word32)derSize, NULL);
  69569. #if !defined(WOLFSSL_NO_ASN_STRICT) && !defined(WOLFSSL_PYTHON)
  69570. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL),
  69571. WC_NO_ERR_TRACE(ASN_PARSE_E));
  69572. #else
  69573. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL), 0);
  69574. #endif
  69575. wc_FreeDecodedCert(&decodedCert);
  69576. ret = wc_ecc_free(&key);
  69577. ExpectIntEQ(ret, 0);
  69578. ret = wc_FreeRng(&rng);
  69579. ExpectIntEQ(ret, 0);
  69580. #endif
  69581. return EXPECT_RESULT();
  69582. }
  69583. static int test_MakeCertWithCaFalse(void)
  69584. {
  69585. EXPECT_DECLS;
  69586. #if defined(WOLFSSL_ALLOW_ENCODING_CA_FALSE) && defined(WOLFSSL_CERT_REQ) && \
  69587. !defined(NO_ASN_TIME) && defined(WOLFSSL_CERT_GEN) && defined(HAVE_ECC)
  69588. const byte expectedIsCa = 0;
  69589. Cert cert;
  69590. DecodedCert decodedCert;
  69591. byte der[FOURK_BUF];
  69592. int derSize = 0;
  69593. WC_RNG rng;
  69594. ecc_key key;
  69595. int ret;
  69596. XMEMSET(&rng, 0, sizeof(WC_RNG));
  69597. XMEMSET(&key, 0, sizeof(ecc_key));
  69598. XMEMSET(&cert, 0, sizeof(Cert));
  69599. XMEMSET(&decodedCert, 0, sizeof(DecodedCert));
  69600. ExpectIntEQ(wc_InitRng(&rng), 0);
  69601. ExpectIntEQ(wc_ecc_init(&key), 0);
  69602. ExpectIntEQ(wc_ecc_make_key(&rng, 32, &key), 0);
  69603. ExpectIntEQ(wc_InitCert(&cert), 0);
  69604. (void)XSTRNCPY(cert.subject.country, "US", CTC_NAME_SIZE);
  69605. (void)XSTRNCPY(cert.subject.state, "state", CTC_NAME_SIZE);
  69606. (void)XSTRNCPY(cert.subject.locality, "Bozeman", CTC_NAME_SIZE);
  69607. (void)XSTRNCPY(cert.subject.org, "yourOrgNameHere", CTC_NAME_SIZE);
  69608. (void)XSTRNCPY(cert.subject.unit, "yourUnitNameHere", CTC_NAME_SIZE);
  69609. (void)XSTRNCPY(cert.subject.commonName, "www.yourDomain.com",
  69610. CTC_NAME_SIZE);
  69611. (void)XSTRNCPY(cert.subject.email, "yourEmail@yourDomain.com",
  69612. CTC_NAME_SIZE);
  69613. cert.selfSigned = 1;
  69614. cert.isCA = expectedIsCa;
  69615. cert.isCaSet = 1;
  69616. cert.sigType = CTC_SHA256wECDSA;
  69617. ExpectIntGE(wc_MakeCert(&cert, der, FOURK_BUF, NULL, &key, &rng), 0);
  69618. ExpectIntGE(derSize = wc_SignCert(cert.bodySz, cert.sigType, der,
  69619. FOURK_BUF, NULL, &key, &rng), 0);
  69620. wc_InitDecodedCert(&decodedCert, der, derSize, NULL);
  69621. ExpectIntEQ(wc_ParseCert(&decodedCert, CERT_TYPE, NO_VERIFY, NULL), 0);
  69622. ExpectIntEQ(decodedCert.isCA, expectedIsCa);
  69623. wc_FreeDecodedCert(&decodedCert);
  69624. ret = wc_ecc_free(&key);
  69625. ExpectIntEQ(ret, 0);
  69626. ret = wc_FreeRng(&rng);
  69627. ExpectIntEQ(ret, 0);
  69628. #endif
  69629. return EXPECT_RESULT();
  69630. }
  69631. /*----------------------------------------------------------------------------*
  69632. | wolfCrypt ECC
  69633. *----------------------------------------------------------------------------*/
  69634. static int test_wc_ecc_get_curve_size_from_name(void)
  69635. {
  69636. EXPECT_DECLS;
  69637. #ifdef HAVE_ECC
  69638. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  69639. ExpectIntEQ(wc_ecc_get_curve_size_from_name("SECP256R1"), 32);
  69640. #endif
  69641. /* invalid case */
  69642. ExpectIntEQ(wc_ecc_get_curve_size_from_name("BADCURVE"), -1);
  69643. /* NULL input */
  69644. ExpectIntEQ(wc_ecc_get_curve_size_from_name(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  69645. #endif /* HAVE_ECC */
  69646. return EXPECT_RESULT();
  69647. }
  69648. static int test_wc_ecc_get_curve_id_from_name(void)
  69649. {
  69650. EXPECT_DECLS;
  69651. #ifdef HAVE_ECC
  69652. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  69653. ExpectIntEQ(wc_ecc_get_curve_id_from_name("SECP256R1"),
  69654. ECC_SECP256R1);
  69655. #endif
  69656. /* invalid case */
  69657. ExpectIntEQ(wc_ecc_get_curve_id_from_name("BADCURVE"), -1);
  69658. /* NULL input */
  69659. ExpectIntEQ(wc_ecc_get_curve_id_from_name(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  69660. #endif /* HAVE_ECC */
  69661. return EXPECT_RESULT();
  69662. }
  69663. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && \
  69664. !defined(HAVE_SELFTEST) && \
  69665. !(defined(HAVE_FIPS) || defined(HAVE_FIPS_VERSION))
  69666. static int test_wc_ecc_get_curve_id_from_dp_params(void)
  69667. {
  69668. EXPECT_DECLS;
  69669. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  69670. ecc_key* key;
  69671. const ecc_set_type* params = NULL;
  69672. int ret;
  69673. #endif
  69674. WOLFSSL_EC_KEY *ecKey = NULL;
  69675. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  69676. ExpectIntEQ(wc_ecc_get_curve_id_from_name("SECP256R1"), ECC_SECP256R1);
  69677. ExpectNotNull(ecKey = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  69678. if (EXPECT_SUCCESS()) {
  69679. ret = EC_KEY_generate_key(ecKey);
  69680. } else
  69681. ret = 0;
  69682. if (ret == 1) {
  69683. /* normal test */
  69684. key = (ecc_key*)ecKey->internal;
  69685. if (key != NULL) {
  69686. params = key->dp;
  69687. }
  69688. ExpectIntEQ(wc_ecc_get_curve_id_from_dp_params(params),
  69689. ECC_SECP256R1);
  69690. }
  69691. #endif
  69692. /* invalid case, NULL input*/
  69693. ExpectIntEQ(wc_ecc_get_curve_id_from_dp_params(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  69694. wolfSSL_EC_KEY_free(ecKey);
  69695. return EXPECT_RESULT();
  69696. }
  69697. #endif /* defined(OPENSSL_EXTRA) && defined(HAVE_ECC) */
  69698. static int test_wc_ecc_get_curve_id_from_params(void)
  69699. {
  69700. EXPECT_DECLS;
  69701. #ifdef HAVE_ECC
  69702. const byte prime[] =
  69703. {
  69704. 0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x01,
  69705. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  69706. 0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,
  69707. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
  69708. };
  69709. const byte primeInvalid[] =
  69710. {
  69711. 0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x01,
  69712. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  69713. 0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,
  69714. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x01,0x01
  69715. };
  69716. const byte Af[] =
  69717. {
  69718. 0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x01,
  69719. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  69720. 0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,
  69721. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC
  69722. };
  69723. const byte Bf[] =
  69724. {
  69725. 0x5A,0xC6,0x35,0xD8,0xAA,0x3A,0x93,0xE7,
  69726. 0xB3,0xEB,0xBD,0x55,0x76,0x98,0x86,0xBC,
  69727. 0x65,0x1D,0x06,0xB0,0xCC,0x53,0xB0,0xF6,
  69728. 0x3B,0xCE,0x3C,0x3E,0x27,0xD2,0x60,0x4B
  69729. };
  69730. const byte order[] =
  69731. {
  69732. 0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,
  69733. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  69734. 0xBC,0xE6,0xFA,0xAD,0xA7,0x17,0x9E,0x84,
  69735. 0xF3,0xB9,0xCA,0xC2,0xFC,0x63,0x25,0x51
  69736. };
  69737. const byte Gx[] =
  69738. {
  69739. 0x6B,0x17,0xD1,0xF2,0xE1,0x2C,0x42,0x47,
  69740. 0xF8,0xBC,0xE6,0xE5,0x63,0xA4,0x40,0xF2,
  69741. 0x77,0x03,0x7D,0x81,0x2D,0xEB,0x33,0xA0,
  69742. 0xF4,0xA1,0x39,0x45,0xD8,0x98,0xC2,0x96
  69743. };
  69744. const byte Gy[] =
  69745. {
  69746. 0x4F,0xE3,0x42,0xE2,0xFE,0x1A,0x7F,0x9B,
  69747. 0x8E,0xE7,0xEB,0x4A,0x7C,0x0F,0x9E,0x16,
  69748. 0x2B,0xCE,0x33,0x57,0x6B,0x31,0x5E,0xCE,
  69749. 0xCB,0xB6,0x40,0x68,0x37,0xBF,0x51,0xF5
  69750. };
  69751. int cofactor = 1;
  69752. int fieldSize = 256;
  69753. #if !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  69754. ExpectIntEQ(wc_ecc_get_curve_id_from_params(fieldSize,
  69755. prime, sizeof(prime), Af, sizeof(Af), Bf, sizeof(Bf),
  69756. order, sizeof(order), Gx, sizeof(Gx), Gy, sizeof(Gy), cofactor),
  69757. ECC_SECP256R1);
  69758. #endif
  69759. /* invalid case, fieldSize = 0 */
  69760. ExpectIntEQ(wc_ecc_get_curve_id_from_params(0, prime, sizeof(prime),
  69761. Af, sizeof(Af), Bf, sizeof(Bf), order, sizeof(order),
  69762. Gx, sizeof(Gx), Gy, sizeof(Gy), cofactor), ECC_CURVE_INVALID);
  69763. /* invalid case, NULL prime */
  69764. ExpectIntEQ(wc_ecc_get_curve_id_from_params(fieldSize, NULL, sizeof(prime),
  69765. Af, sizeof(Af), Bf, sizeof(Bf), order, sizeof(order),
  69766. Gx, sizeof(Gx), Gy, sizeof(Gy), cofactor), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  69767. /* invalid case, invalid prime */
  69768. ExpectIntEQ(wc_ecc_get_curve_id_from_params(fieldSize,
  69769. primeInvalid, sizeof(primeInvalid),
  69770. Af, sizeof(Af), Bf, sizeof(Bf), order, sizeof(order),
  69771. Gx, sizeof(Gx), Gy, sizeof(Gy), cofactor), ECC_CURVE_INVALID);
  69772. #endif
  69773. return EXPECT_RESULT();
  69774. }
  69775. static int test_wolfSSL_EVP_PKEY_encrypt(void)
  69776. {
  69777. EXPECT_DECLS;
  69778. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  69779. WOLFSSL_RSA* rsa = NULL;
  69780. WOLFSSL_EVP_PKEY* pkey = NULL;
  69781. WOLFSSL_EVP_PKEY_CTX* ctx = NULL;
  69782. const char* in = "What is easy to do is easy not to do.";
  69783. size_t inlen = XSTRLEN(in);
  69784. size_t outEncLen = 0;
  69785. byte* outEnc = NULL;
  69786. byte* outDec = NULL;
  69787. size_t outDecLen = 0;
  69788. size_t rsaKeySz = 2048/8; /* Bytes */
  69789. #if !defined(HAVE_FIPS) && defined(WC_RSA_NO_PADDING)
  69790. byte* inTmp = NULL;
  69791. byte* outEncTmp = NULL;
  69792. byte* outDecTmp = NULL;
  69793. #endif
  69794. ExpectNotNull(outEnc = (byte*)XMALLOC(rsaKeySz, HEAP_HINT,
  69795. DYNAMIC_TYPE_TMP_BUFFER));
  69796. if (outEnc != NULL) {
  69797. XMEMSET(outEnc, 0, rsaKeySz);
  69798. }
  69799. ExpectNotNull(outDec = (byte*)XMALLOC(rsaKeySz, HEAP_HINT,
  69800. DYNAMIC_TYPE_TMP_BUFFER));
  69801. if (outDec != NULL) {
  69802. XMEMSET(outDec, 0, rsaKeySz);
  69803. }
  69804. ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  69805. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  69806. ExpectIntEQ(EVP_PKEY_assign_RSA(pkey, rsa), WOLFSSL_SUCCESS);
  69807. if (EXPECT_FAIL()) {
  69808. RSA_free(rsa);
  69809. }
  69810. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  69811. ExpectIntEQ(EVP_PKEY_encrypt_init(ctx), WOLFSSL_SUCCESS);
  69812. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING),
  69813. WOLFSSL_SUCCESS);
  69814. /* Test pkey references count is decremented. pkey shouldn't be destroyed
  69815. since ctx uses it.*/
  69816. ExpectIntEQ(pkey->ref.count, 2);
  69817. EVP_PKEY_free(pkey);
  69818. ExpectIntEQ(pkey->ref.count, 1);
  69819. /* Encrypt data */
  69820. /* Check that we can get the required output buffer length by passing in a
  69821. * NULL output buffer. */
  69822. ExpectIntEQ(EVP_PKEY_encrypt(ctx, NULL, &outEncLen,
  69823. (const unsigned char*)in, inlen), WOLFSSL_SUCCESS);
  69824. ExpectIntEQ(rsaKeySz, outEncLen);
  69825. /* Now do the actual encryption. */
  69826. ExpectIntEQ(EVP_PKEY_encrypt(ctx, outEnc, &outEncLen,
  69827. (const unsigned char*)in, inlen), WOLFSSL_SUCCESS);
  69828. /* Decrypt data */
  69829. ExpectIntEQ(EVP_PKEY_decrypt_init(ctx), WOLFSSL_SUCCESS);
  69830. /* Check that we can get the required output buffer length by passing in a
  69831. * NULL output buffer. */
  69832. ExpectIntEQ(EVP_PKEY_decrypt(ctx, NULL, &outDecLen, outEnc, outEncLen),
  69833. WOLFSSL_SUCCESS);
  69834. ExpectIntEQ(rsaKeySz, outDecLen);
  69835. /* Now do the actual decryption. */
  69836. ExpectIntEQ(EVP_PKEY_decrypt(ctx, outDec, &outDecLen, outEnc, outEncLen),
  69837. WOLFSSL_SUCCESS);
  69838. ExpectIntEQ(XMEMCMP(in, outDec, outDecLen), 0);
  69839. #if !defined(HAVE_FIPS) && defined(WC_RSA_NO_PADDING)
  69840. /* The input length must be the same size as the RSA key.*/
  69841. ExpectNotNull(inTmp = (byte*)XMALLOC(rsaKeySz, HEAP_HINT,
  69842. DYNAMIC_TYPE_TMP_BUFFER));
  69843. if (inTmp != NULL) {
  69844. XMEMSET(inTmp, 9, rsaKeySz);
  69845. }
  69846. ExpectNotNull(outEncTmp = (byte*)XMALLOC(rsaKeySz, HEAP_HINT,
  69847. DYNAMIC_TYPE_TMP_BUFFER));
  69848. if (outEncTmp != NULL) {
  69849. XMEMSET(outEncTmp, 0, rsaKeySz);
  69850. }
  69851. ExpectNotNull(outDecTmp = (byte*)XMALLOC(rsaKeySz, HEAP_HINT,
  69852. DYNAMIC_TYPE_TMP_BUFFER));
  69853. if (outDecTmp != NULL) {
  69854. XMEMSET(outDecTmp, 0, rsaKeySz);
  69855. }
  69856. ExpectIntEQ(EVP_PKEY_encrypt_init(ctx), WOLFSSL_SUCCESS);
  69857. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_NO_PADDING),
  69858. WOLFSSL_SUCCESS);
  69859. ExpectIntEQ(EVP_PKEY_encrypt(ctx, outEncTmp, &outEncLen, inTmp, rsaKeySz),
  69860. WOLFSSL_SUCCESS);
  69861. ExpectIntEQ(EVP_PKEY_decrypt_init(ctx), WOLFSSL_SUCCESS);
  69862. ExpectIntEQ(EVP_PKEY_decrypt(ctx, outDecTmp, &outDecLen, outEncTmp,
  69863. outEncLen), WOLFSSL_SUCCESS);
  69864. ExpectIntEQ(XMEMCMP(inTmp, outDecTmp, outDecLen), 0);
  69865. #endif
  69866. EVP_PKEY_CTX_free(ctx);
  69867. XFREE(outEnc, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  69868. XFREE(outDec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  69869. #if !defined(HAVE_FIPS) && defined(WC_RSA_NO_PADDING)
  69870. XFREE(inTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  69871. XFREE(outEncTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  69872. XFREE(outDecTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  69873. #endif
  69874. #endif
  69875. return EXPECT_RESULT();
  69876. }
  69877. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  69878. !defined(HAVE_SELFTEST)
  69879. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  69880. #ifndef TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  69881. #define TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  69882. #endif
  69883. #endif
  69884. #endif
  69885. #if defined(OPENSSL_EXTRA)
  69886. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  69887. #ifndef TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  69888. #define TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  69889. #endif
  69890. #endif
  69891. #endif
  69892. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  69893. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  69894. #ifndef TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  69895. #define TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  69896. #endif
  69897. #endif
  69898. #endif
  69899. #ifdef TEST_WOLFSSL_EVP_PKEY_SIGN_VERIFY
  69900. static int test_wolfSSL_EVP_PKEY_sign_verify(int keyType)
  69901. {
  69902. EXPECT_DECLS;
  69903. #if defined(OPENSSL_EXTRA)
  69904. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  69905. !defined(HAVE_SELFTEST)
  69906. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  69907. WOLFSSL_RSA* rsa = NULL;
  69908. #endif
  69909. #endif
  69910. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  69911. WOLFSSL_DSA* dsa = NULL;
  69912. #endif /* !NO_DSA && !HAVE_SELFTEST && WOLFSSL_KEY_GEN */
  69913. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  69914. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  69915. WOLFSSL_EC_KEY* ecKey = NULL;
  69916. #endif
  69917. #endif
  69918. WOLFSSL_EVP_PKEY* pkey = NULL;
  69919. WOLFSSL_EVP_PKEY_CTX* ctx = NULL;
  69920. WOLFSSL_EVP_PKEY_CTX* ctx_verify = NULL;
  69921. const char* in = "What is easy to do is easy not to do.";
  69922. size_t inlen = XSTRLEN(in);
  69923. byte hash[SHA256_DIGEST_LENGTH] = {0};
  69924. byte zero[SHA256_DIGEST_LENGTH] = {0};
  69925. SHA256_CTX c;
  69926. byte* sig = NULL;
  69927. byte* sigVerify = NULL;
  69928. size_t siglen;
  69929. size_t siglenOnlyLen;
  69930. size_t keySz = 2048/8; /* Bytes */
  69931. ExpectNotNull(sig =
  69932. (byte*)XMALLOC(keySz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER));
  69933. ExpectNotNull(sigVerify =
  69934. (byte*)XMALLOC(keySz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER));
  69935. siglen = keySz;
  69936. ExpectNotNull(XMEMSET(sig, 0, keySz));
  69937. ExpectNotNull(XMEMSET(sigVerify, 0, keySz));
  69938. /* Generate hash */
  69939. SHA256_Init(&c);
  69940. SHA256_Update(&c, in, inlen);
  69941. SHA256_Final(hash, &c);
  69942. #ifdef WOLFSSL_SMALL_STACK_CACHE
  69943. /* workaround for small stack cache case */
  69944. wc_Sha256Free((wc_Sha256*)&c);
  69945. #endif
  69946. /* Generate key */
  69947. ExpectNotNull(pkey = EVP_PKEY_new());
  69948. switch (keyType) {
  69949. case EVP_PKEY_RSA:
  69950. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  69951. !defined(HAVE_SELFTEST)
  69952. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  69953. {
  69954. ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  69955. ExpectIntEQ(EVP_PKEY_assign_RSA(pkey, rsa), WOLFSSL_SUCCESS);
  69956. }
  69957. #endif
  69958. #endif
  69959. break;
  69960. case EVP_PKEY_DSA:
  69961. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  69962. ExpectNotNull(dsa = DSA_new());
  69963. ExpectIntEQ(DSA_generate_parameters_ex(dsa, 2048,
  69964. NULL, 0, NULL, NULL, NULL), 1);
  69965. ExpectIntEQ(DSA_generate_key(dsa), 1);
  69966. ExpectIntEQ(EVP_PKEY_set1_DSA(pkey, dsa), WOLFSSL_SUCCESS);
  69967. #endif /* !NO_DSA && !HAVE_SELFTEST && WOLFSSL_KEY_GEN */
  69968. break;
  69969. case EVP_PKEY_EC:
  69970. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  69971. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  69972. {
  69973. ExpectNotNull(ecKey = EC_KEY_new());
  69974. ExpectIntEQ(EC_KEY_generate_key(ecKey), 1);
  69975. ExpectIntEQ(
  69976. EVP_PKEY_assign_EC_KEY(pkey, ecKey), WOLFSSL_SUCCESS);
  69977. if (EXPECT_FAIL()) {
  69978. EC_KEY_free(ecKey);
  69979. }
  69980. }
  69981. #endif
  69982. #endif
  69983. break;
  69984. }
  69985. ExpectNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
  69986. ExpectIntEQ(EVP_PKEY_sign_init(ctx), WOLFSSL_SUCCESS);
  69987. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  69988. !defined(HAVE_SELFTEST)
  69989. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  69990. if (keyType == EVP_PKEY_RSA)
  69991. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING),
  69992. WOLFSSL_SUCCESS);
  69993. #endif
  69994. #endif
  69995. /* Check returning only length */
  69996. ExpectIntEQ(EVP_PKEY_sign(ctx, NULL, &siglenOnlyLen, hash,
  69997. SHA256_DIGEST_LENGTH), WOLFSSL_SUCCESS);
  69998. ExpectIntGT(siglenOnlyLen, 0);
  69999. /* Sign data */
  70000. ExpectIntEQ(EVP_PKEY_sign(ctx, sig, &siglen, hash,
  70001. SHA256_DIGEST_LENGTH), WOLFSSL_SUCCESS);
  70002. ExpectIntGE(siglenOnlyLen, siglen);
  70003. /* Verify signature */
  70004. ExpectNotNull(ctx_verify = EVP_PKEY_CTX_new(pkey, NULL));
  70005. ExpectIntEQ(EVP_PKEY_verify_init(ctx_verify), WOLFSSL_SUCCESS);
  70006. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  70007. !defined(HAVE_SELFTEST)
  70008. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  70009. if (keyType == EVP_PKEY_RSA)
  70010. ExpectIntEQ(
  70011. EVP_PKEY_CTX_set_rsa_padding(ctx_verify, RSA_PKCS1_PADDING),
  70012. WOLFSSL_SUCCESS);
  70013. #endif
  70014. #endif
  70015. ExpectIntEQ(EVP_PKEY_verify(
  70016. ctx_verify, sig, siglen, hash, SHA256_DIGEST_LENGTH),
  70017. WOLFSSL_SUCCESS);
  70018. ExpectIntEQ(EVP_PKEY_verify(
  70019. ctx_verify, sig, siglen, zero, SHA256_DIGEST_LENGTH),
  70020. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70021. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  70022. !defined(HAVE_SELFTEST)
  70023. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  70024. if (keyType == EVP_PKEY_RSA) {
  70025. #if defined(WC_RSA_NO_PADDING) || defined(WC_RSA_DIRECT)
  70026. /* Try RSA sign/verify with no padding. */
  70027. ExpectIntEQ(EVP_PKEY_sign_init(ctx), WOLFSSL_SUCCESS);
  70028. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_NO_PADDING),
  70029. WOLFSSL_SUCCESS);
  70030. ExpectIntEQ(EVP_PKEY_sign(ctx, sigVerify, &siglen, sig,
  70031. siglen), WOLFSSL_SUCCESS);
  70032. ExpectIntGE(siglenOnlyLen, siglen);
  70033. ExpectIntEQ(EVP_PKEY_verify_init(ctx_verify), WOLFSSL_SUCCESS);
  70034. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx_verify,
  70035. RSA_NO_PADDING), WOLFSSL_SUCCESS);
  70036. ExpectIntEQ(EVP_PKEY_verify(ctx_verify, sigVerify, siglen, sig,
  70037. siglen), WOLFSSL_SUCCESS);
  70038. #endif
  70039. /* Wrong padding schemes. */
  70040. ExpectIntEQ(EVP_PKEY_sign_init(ctx), WOLFSSL_SUCCESS);
  70041. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx,
  70042. RSA_PKCS1_OAEP_PADDING), WOLFSSL_SUCCESS);
  70043. ExpectIntNE(EVP_PKEY_sign(ctx, sigVerify, &siglen, sig,
  70044. siglen), WOLFSSL_SUCCESS);
  70045. ExpectIntEQ(EVP_PKEY_verify_init(ctx_verify), WOLFSSL_SUCCESS);
  70046. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx_verify,
  70047. RSA_PKCS1_OAEP_PADDING), WOLFSSL_SUCCESS);
  70048. ExpectIntNE(EVP_PKEY_verify(ctx_verify, sigVerify, siglen, sig,
  70049. siglen), WOLFSSL_SUCCESS);
  70050. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING),
  70051. WOLFSSL_SUCCESS);
  70052. ExpectIntEQ(EVP_PKEY_CTX_set_rsa_padding(ctx_verify,
  70053. RSA_PKCS1_PADDING), WOLFSSL_SUCCESS);
  70054. }
  70055. #endif
  70056. #endif
  70057. /* error cases */
  70058. siglen = keySz; /* Reset because sig size may vary slightly */
  70059. ExpectIntNE(EVP_PKEY_sign_init(NULL), WOLFSSL_SUCCESS);
  70060. ExpectIntEQ(EVP_PKEY_sign_init(ctx), WOLFSSL_SUCCESS);
  70061. ExpectIntNE(EVP_PKEY_sign(NULL, sig, &siglen, (byte*)in, inlen),
  70062. WOLFSSL_SUCCESS);
  70063. ExpectIntEQ(EVP_PKEY_sign(ctx, sig, &siglen, (byte*)in, inlen),
  70064. WOLFSSL_SUCCESS);
  70065. EVP_PKEY_free(pkey);
  70066. pkey = NULL;
  70067. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  70068. DSA_free(dsa);
  70069. dsa = NULL;
  70070. #endif /* !NO_DSA && !HAVE_SELFTEST && WOLFSSL_KEY_GEN */
  70071. EVP_PKEY_CTX_free(ctx_verify);
  70072. ctx_verify = NULL;
  70073. EVP_PKEY_CTX_free(ctx);
  70074. ctx = NULL;
  70075. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  70076. XFREE(sigVerify, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  70077. #endif /* OPENSSL_EXTRA */
  70078. return EXPECT_RESULT();
  70079. }
  70080. #endif
  70081. static int test_wolfSSL_EVP_PKEY_sign_verify_rsa(void)
  70082. {
  70083. EXPECT_DECLS;
  70084. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  70085. !defined(HAVE_SELFTEST)
  70086. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  70087. ExpectIntEQ(test_wolfSSL_EVP_PKEY_sign_verify(EVP_PKEY_RSA), TEST_SUCCESS);
  70088. #endif
  70089. #endif
  70090. return EXPECT_RESULT();
  70091. }
  70092. static int test_wolfSSL_EVP_PKEY_sign_verify_dsa(void)
  70093. {
  70094. EXPECT_DECLS;
  70095. #if defined(OPENSSL_EXTRA)
  70096. #if !defined (NO_DSA) && !defined(HAVE_SELFTEST) && defined(WOLFSSL_KEY_GEN)
  70097. ExpectIntEQ(test_wolfSSL_EVP_PKEY_sign_verify(EVP_PKEY_DSA), TEST_SUCCESS);
  70098. #endif
  70099. #endif
  70100. return EXPECT_RESULT();
  70101. }
  70102. static int test_wolfSSL_EVP_PKEY_sign_verify_ec(void)
  70103. {
  70104. EXPECT_DECLS;
  70105. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  70106. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  70107. ExpectIntEQ(test_wolfSSL_EVP_PKEY_sign_verify(EVP_PKEY_EC), TEST_SUCCESS);
  70108. #endif
  70109. #endif
  70110. return EXPECT_RESULT();
  70111. }
  70112. static int test_EVP_PKEY_rsa(void)
  70113. {
  70114. EXPECT_DECLS;
  70115. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  70116. WOLFSSL_RSA* rsa = NULL;
  70117. WOLFSSL_EVP_PKEY* pkey = NULL;
  70118. ExpectNotNull(rsa = wolfSSL_RSA_new());
  70119. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  70120. ExpectIntEQ(EVP_PKEY_assign_RSA(NULL, rsa), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70121. ExpectIntEQ(EVP_PKEY_assign_RSA(pkey, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70122. ExpectIntEQ(EVP_PKEY_assign_RSA(pkey, rsa), WOLFSSL_SUCCESS);
  70123. if (EXPECT_FAIL()) {
  70124. wolfSSL_RSA_free(rsa);
  70125. }
  70126. ExpectPtrEq(EVP_PKEY_get0_RSA(pkey), rsa);
  70127. wolfSSL_EVP_PKEY_free(pkey);
  70128. #endif
  70129. return EXPECT_RESULT();
  70130. }
  70131. static int test_EVP_PKEY_ec(void)
  70132. {
  70133. EXPECT_DECLS;
  70134. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  70135. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  70136. WOLFSSL_EC_KEY* ecKey = NULL;
  70137. WOLFSSL_EVP_PKEY* pkey = NULL;
  70138. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  70139. ExpectNotNull(pkey = wolfSSL_EVP_PKEY_new());
  70140. ExpectIntEQ(EVP_PKEY_assign_EC_KEY(NULL, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70141. ExpectIntEQ(EVP_PKEY_assign_EC_KEY(pkey, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70142. /* Should fail since ecKey is empty */
  70143. ExpectIntEQ(EVP_PKEY_assign_EC_KEY(pkey, ecKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70144. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  70145. ExpectIntEQ(EVP_PKEY_assign_EC_KEY(pkey, ecKey), WOLFSSL_SUCCESS);
  70146. if (EXPECT_FAIL()) {
  70147. wolfSSL_EC_KEY_free(ecKey);
  70148. }
  70149. wolfSSL_EVP_PKEY_free(pkey);
  70150. #endif
  70151. #endif
  70152. return EXPECT_RESULT();
  70153. }
  70154. static int test_EVP_PKEY_cmp(void)
  70155. {
  70156. EXPECT_DECLS;
  70157. #if defined(OPENSSL_EXTRA)
  70158. EVP_PKEY *a = NULL;
  70159. EVP_PKEY *b = NULL;
  70160. const unsigned char *in;
  70161. #if !defined(NO_RSA) && defined(USE_CERT_BUFFERS_2048)
  70162. in = client_key_der_2048;
  70163. ExpectNotNull(a = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  70164. &in, (long)sizeof_client_key_der_2048));
  70165. in = client_key_der_2048;
  70166. ExpectNotNull(b = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  70167. &in, (long)sizeof_client_key_der_2048));
  70168. /* Test success case RSA */
  70169. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  70170. ExpectIntEQ(EVP_PKEY_cmp(a, b), 1);
  70171. #else
  70172. ExpectIntEQ(EVP_PKEY_cmp(a, b), 0);
  70173. #endif /* WOLFSSL_ERROR_CODE_OPENSSL */
  70174. EVP_PKEY_free(b);
  70175. b = NULL;
  70176. EVP_PKEY_free(a);
  70177. a = NULL;
  70178. #endif
  70179. #if defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  70180. in = ecc_clikey_der_256;
  70181. ExpectNotNull(a = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL,
  70182. &in, (long)sizeof_ecc_clikey_der_256));
  70183. in = ecc_clikey_der_256;
  70184. ExpectNotNull(b = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL,
  70185. &in, (long)sizeof_ecc_clikey_der_256));
  70186. /* Test success case ECC */
  70187. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  70188. ExpectIntEQ(EVP_PKEY_cmp(a, b), 1);
  70189. #else
  70190. ExpectIntEQ(EVP_PKEY_cmp(a, b), 0);
  70191. #endif /* WOLFSSL_ERROR_CODE_OPENSSL */
  70192. EVP_PKEY_free(b);
  70193. b = NULL;
  70194. EVP_PKEY_free(a);
  70195. a = NULL;
  70196. #endif
  70197. /* Test failure cases */
  70198. #if !defined(NO_RSA) && defined(USE_CERT_BUFFERS_2048) && \
  70199. defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
  70200. in = client_key_der_2048;
  70201. ExpectNotNull(a = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
  70202. &in, (long)sizeof_client_key_der_2048));
  70203. in = ecc_clikey_der_256;
  70204. ExpectNotNull(b = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL,
  70205. &in, (long)sizeof_ecc_clikey_der_256));
  70206. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  70207. ExpectIntEQ(EVP_PKEY_cmp(a, b), -1);
  70208. #else
  70209. ExpectIntNE(EVP_PKEY_cmp(a, b), 0);
  70210. #endif /* WOLFSSL_ERROR_CODE_OPENSSL */
  70211. EVP_PKEY_free(b);
  70212. b = NULL;
  70213. EVP_PKEY_free(a);
  70214. a = NULL;
  70215. #endif
  70216. /* invalid or empty failure cases */
  70217. a = EVP_PKEY_new();
  70218. b = EVP_PKEY_new();
  70219. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  70220. ExpectIntEQ(EVP_PKEY_cmp(NULL, NULL), 0);
  70221. ExpectIntEQ(EVP_PKEY_cmp(a, NULL), 0);
  70222. ExpectIntEQ(EVP_PKEY_cmp(NULL, b), 0);
  70223. #ifdef NO_RSA
  70224. /* Type check will fail since RSA is the default EVP key type */
  70225. ExpectIntEQ(EVP_PKEY_cmp(a, b), -2);
  70226. #else
  70227. ExpectIntEQ(EVP_PKEY_cmp(a, b), 0);
  70228. #endif
  70229. #else
  70230. ExpectIntNE(EVP_PKEY_cmp(NULL, NULL), 0);
  70231. ExpectIntNE(EVP_PKEY_cmp(a, NULL), 0);
  70232. ExpectIntNE(EVP_PKEY_cmp(NULL, b), 0);
  70233. ExpectIntNE(EVP_PKEY_cmp(a, b), 0);
  70234. #endif
  70235. EVP_PKEY_free(b);
  70236. EVP_PKEY_free(a);
  70237. (void)in;
  70238. #endif
  70239. return EXPECT_RESULT();
  70240. }
  70241. static int test_ERR_load_crypto_strings(void)
  70242. {
  70243. #if defined(OPENSSL_ALL)
  70244. ERR_load_crypto_strings();
  70245. return TEST_SUCCESS;
  70246. #else
  70247. return TEST_SKIPPED;
  70248. #endif
  70249. }
  70250. #if defined(OPENSSL_ALL) && !defined(NO_CERTS)
  70251. static void free_x509(X509* x)
  70252. {
  70253. AssertIntEQ((x == (X509*)1 || x == (X509*)2), 1);
  70254. }
  70255. #endif
  70256. static int test_sk_X509(void)
  70257. {
  70258. EXPECT_DECLS;
  70259. #if defined(OPENSSL_ALL) && !defined(NO_CERTS)
  70260. {
  70261. STACK_OF(X509)* s = NULL;
  70262. ExpectNotNull(s = sk_X509_new_null());
  70263. ExpectIntEQ(sk_X509_num(s), 0);
  70264. sk_X509_pop_free(s, NULL);
  70265. ExpectNotNull(s = sk_X509_new_null());
  70266. ExpectIntEQ(sk_X509_num(s), 0);
  70267. sk_X509_pop_free(s, NULL);
  70268. ExpectNotNull(s = sk_X509_new_null());
  70269. sk_X509_push(s, (X509*)1);
  70270. ExpectIntEQ(sk_X509_num(s), 1);
  70271. ExpectIntEQ((sk_X509_value(s, 0) == (X509*)1), 1);
  70272. sk_X509_push(s, (X509*)2);
  70273. ExpectIntEQ(sk_X509_num(s), 2);
  70274. ExpectIntEQ((sk_X509_value(s, 0) == (X509*)2), 1);
  70275. ExpectIntEQ((sk_X509_value(s, 1) == (X509*)1), 1);
  70276. sk_X509_push(s, (X509*)2);
  70277. sk_X509_pop_free(s, free_x509);
  70278. }
  70279. {
  70280. /* Push a list of 10 X509s onto stack, then verify that
  70281. * value(), push(), shift(), and pop() behave as expected. */
  70282. STACK_OF(X509)* s = NULL;
  70283. X509* xList[10];
  70284. int i = 0;
  70285. const int len = (sizeof(xList) / sizeof(xList[0]));
  70286. for (i = 0; i < len; ++i) {
  70287. xList[i] = NULL;
  70288. ExpectNotNull(xList[i] = X509_new());
  70289. }
  70290. /* test push, pop, and free */
  70291. ExpectNotNull(s = sk_X509_new_null());
  70292. for (i = 0; i < len; ++i) {
  70293. sk_X509_push(s, xList[i]);
  70294. ExpectIntEQ(sk_X509_num(s), i + 1);
  70295. ExpectIntEQ((sk_X509_value(s, 0) == xList[i]), 1);
  70296. ExpectIntEQ((sk_X509_value(s, i) == xList[0]), 1);
  70297. }
  70298. /* pop returns and removes last pushed on stack, which is index 0
  70299. * in sk_x509_value */
  70300. for (i = 0; i < len; ++i) {
  70301. X509 * x = sk_X509_value(s, 0);
  70302. X509 * y = sk_X509_pop(s);
  70303. X509 * z = xList[len - 1 - i];
  70304. ExpectIntEQ((x == y), 1);
  70305. ExpectIntEQ((x == z), 1);
  70306. ExpectIntEQ(sk_X509_num(s), len - 1 - i);
  70307. }
  70308. sk_free(s);
  70309. s = NULL;
  70310. /* test push, shift, and free */
  70311. ExpectNotNull(s = sk_X509_new_null());
  70312. for (i = 0; i < len; ++i) {
  70313. sk_X509_push(s, xList[i]);
  70314. ExpectIntEQ(sk_X509_num(s), i + 1);
  70315. ExpectIntEQ((sk_X509_value(s, 0) == xList[i]), 1);
  70316. ExpectIntEQ((sk_X509_value(s, i) == xList[0]), 1);
  70317. }
  70318. /* shift returns and removes first pushed on stack, which is index i
  70319. * in sk_x509_value() */
  70320. for (i = 0; i < len; ++i) {
  70321. X509 * x = sk_X509_value(s, len - 1 - i);
  70322. X509 * y = sk_X509_shift(s);
  70323. X509 * z = xList[i];
  70324. ExpectIntEQ((x == y), 1);
  70325. ExpectIntEQ((x == z), 1);
  70326. ExpectIntEQ(sk_X509_num(s), len - 1 - i);
  70327. }
  70328. sk_free(s);
  70329. for (i = 0; i < len; ++i)
  70330. X509_free(xList[i]);
  70331. }
  70332. #endif
  70333. return EXPECT_RESULT();
  70334. }
  70335. static int test_sk_X509_CRL(void)
  70336. {
  70337. EXPECT_DECLS;
  70338. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && defined(HAVE_CRL)
  70339. X509_CRL* crl = NULL;
  70340. XFILE fp = XBADFILE;
  70341. STACK_OF(X509_CRL)* s = NULL;
  70342. ExpectTrue((fp = XFOPEN("./certs/crl/crl.pem", "rb")) != XBADFILE);
  70343. ExpectNotNull(crl = (X509_CRL*)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  70344. NULL, NULL));
  70345. if (fp != XBADFILE)
  70346. XFCLOSE(fp);
  70347. ExpectNotNull(s = sk_X509_CRL_new());
  70348. ExpectIntEQ(sk_X509_CRL_num(s), 0);
  70349. ExpectIntEQ(sk_X509_CRL_push(s, crl), 1);
  70350. if (EXPECT_FAIL()) {
  70351. X509_CRL_free(crl);
  70352. }
  70353. ExpectIntEQ(sk_X509_CRL_num(s), 1);
  70354. ExpectPtrEq(sk_X509_CRL_value(s, 0), crl);
  70355. sk_X509_CRL_free(s);
  70356. #endif
  70357. return EXPECT_RESULT();
  70358. }
  70359. static int test_X509_get_signature_nid(void)
  70360. {
  70361. EXPECT_DECLS;
  70362. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  70363. X509* x509 = NULL;
  70364. ExpectIntEQ(X509_get_signature_nid(NULL), 0);
  70365. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  70366. SSL_FILETYPE_PEM));
  70367. ExpectIntEQ(X509_get_signature_nid(x509), NID_sha256WithRSAEncryption);
  70368. X509_free(x509);
  70369. #endif
  70370. return EXPECT_RESULT();
  70371. }
  70372. static int test_X509_REQ(void)
  70373. {
  70374. EXPECT_DECLS;
  70375. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  70376. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && !defined(NO_BIO)
  70377. X509_NAME* name = NULL;
  70378. #ifndef NO_RSA
  70379. X509_NAME* subject = NULL;
  70380. #endif
  70381. #if !defined(NO_RSA) || defined(HAVE_ECC)
  70382. X509_REQ* req = NULL;
  70383. EVP_PKEY* priv = NULL;
  70384. EVP_PKEY* pub = NULL;
  70385. unsigned char* der = NULL;
  70386. int len;
  70387. #endif
  70388. #ifndef NO_RSA
  70389. EVP_MD_CTX *mctx = NULL;
  70390. EVP_PKEY_CTX *pkctx = NULL;
  70391. #ifdef USE_CERT_BUFFERS_1024
  70392. const unsigned char* rsaPriv = (const unsigned char*)client_key_der_1024;
  70393. const unsigned char* rsaPub = (unsigned char*)client_keypub_der_1024;
  70394. #elif defined(USE_CERT_BUFFERS_2048)
  70395. const unsigned char* rsaPriv = (const unsigned char*)client_key_der_2048;
  70396. const unsigned char* rsaPub = (unsigned char*)client_keypub_der_2048;
  70397. #endif
  70398. #endif
  70399. #ifdef HAVE_ECC
  70400. const unsigned char* ecPriv = (const unsigned char*)ecc_clikey_der_256;
  70401. const unsigned char* ecPub = (unsigned char*)ecc_clikeypub_der_256;
  70402. #endif
  70403. ExpectNotNull(name = X509_NAME_new());
  70404. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "commonName", MBSTRING_UTF8,
  70405. (byte*)"wolfssl.com", 11, 0, 1), WOLFSSL_SUCCESS);
  70406. ExpectIntEQ(X509_NAME_add_entry_by_txt(name, "emailAddress", MBSTRING_UTF8,
  70407. (byte*)"support@wolfssl.com", 19, -1, 1), WOLFSSL_SUCCESS);
  70408. #ifndef NO_RSA
  70409. ExpectNotNull(priv = d2i_PrivateKey(EVP_PKEY_RSA, NULL, &rsaPriv,
  70410. (long)sizeof_client_key_der_2048));
  70411. ExpectNotNull(pub = d2i_PUBKEY(NULL, &rsaPub,
  70412. (long)sizeof_client_keypub_der_2048));
  70413. ExpectNotNull(req = X509_REQ_new());
  70414. ExpectIntEQ(X509_REQ_set_subject_name(NULL, name), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70415. ExpectIntEQ(X509_REQ_set_subject_name(req, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70416. ExpectIntEQ(X509_REQ_set_subject_name(req, name), WOLFSSL_SUCCESS);
  70417. ExpectIntEQ(X509_REQ_set_pubkey(NULL, pub), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70418. ExpectIntEQ(X509_REQ_set_pubkey(req, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70419. ExpectIntEQ(X509_REQ_set_pubkey(req, pub), WOLFSSL_SUCCESS);
  70420. ExpectIntEQ(X509_REQ_sign(NULL, priv, EVP_sha256()), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70421. ExpectIntEQ(X509_REQ_sign(req, NULL, EVP_sha256()), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70422. ExpectIntEQ(X509_REQ_sign(req, priv, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70423. ExpectIntEQ(X509_REQ_sign(req, priv, EVP_sha256()), WOLFSSL_SUCCESS);
  70424. len = i2d_X509_REQ(req, &der);
  70425. DEBUG_WRITE_DER(der, len, "req.der");
  70426. #ifdef USE_CERT_BUFFERS_1024
  70427. ExpectIntEQ(len, 381);
  70428. #else
  70429. ExpectIntEQ(len, 643);
  70430. #endif
  70431. XFREE(der, NULL, DYNAMIC_TYPE_OPENSSL);
  70432. der = NULL;
  70433. mctx = EVP_MD_CTX_new();
  70434. ExpectIntEQ(EVP_DigestSignInit(mctx, &pkctx, EVP_sha256(), NULL, priv),
  70435. WOLFSSL_SUCCESS);
  70436. ExpectIntEQ(X509_REQ_sign_ctx(req, mctx), WOLFSSL_SUCCESS);
  70437. EVP_MD_CTX_free(mctx);
  70438. mctx = NULL;
  70439. X509_REQ_free(NULL);
  70440. X509_REQ_free(req);
  70441. req = NULL;
  70442. /* Test getting the subject from a newly created X509_REQ */
  70443. ExpectNotNull(req = X509_REQ_new());
  70444. ExpectNotNull(subject = X509_REQ_get_subject_name(req));
  70445. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_commonName,
  70446. MBSTRING_UTF8, (unsigned char*)"www.wolfssl.com", -1, -1, 0), 1);
  70447. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_countryName,
  70448. MBSTRING_UTF8, (unsigned char*)"US", -1, -1, 0), 1);
  70449. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_localityName,
  70450. MBSTRING_UTF8, (unsigned char*)"Bozeman", -1, -1, 0), 1);
  70451. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_stateOrProvinceName,
  70452. MBSTRING_UTF8, (unsigned char*)"Montana", -1, -1, 0), 1);
  70453. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_organizationName,
  70454. MBSTRING_UTF8, (unsigned char*)"wolfSSL", -1, -1, 0), 1);
  70455. ExpectIntEQ(X509_NAME_add_entry_by_NID(subject, NID_organizationalUnitName,
  70456. MBSTRING_UTF8, (unsigned char*)"Testing", -1, -1, 0), 1);
  70457. ExpectIntEQ(X509_REQ_set_pubkey(req, pub), WOLFSSL_SUCCESS);
  70458. ExpectIntEQ(X509_REQ_sign(req, priv, EVP_sha256()), WOLFSSL_SUCCESS);
  70459. len = i2d_X509_REQ(req, &der);
  70460. DEBUG_WRITE_DER(der, len, "req2.der");
  70461. #ifdef USE_CERT_BUFFERS_1024
  70462. ExpectIntEQ(len, 435);
  70463. #else
  70464. ExpectIntEQ(len, 696);
  70465. #endif
  70466. XFREE(der, NULL, DYNAMIC_TYPE_OPENSSL);
  70467. der = NULL;
  70468. EVP_PKEY_free(pub);
  70469. pub = NULL;
  70470. EVP_PKEY_free(priv);
  70471. priv = NULL;
  70472. X509_REQ_free(req);
  70473. req = NULL;
  70474. #endif
  70475. #ifdef HAVE_ECC
  70476. ExpectNotNull(priv = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL, &ecPriv,
  70477. sizeof_ecc_clikey_der_256));
  70478. ExpectNotNull(pub = wolfSSL_d2i_PUBKEY(NULL, &ecPub,
  70479. sizeof_ecc_clikeypub_der_256));
  70480. ExpectNotNull(req = X509_REQ_new());
  70481. ExpectIntEQ(X509_REQ_set_subject_name(req, name), WOLFSSL_SUCCESS);
  70482. ExpectIntEQ(X509_REQ_set_pubkey(req, pub), WOLFSSL_SUCCESS);
  70483. ExpectIntEQ(X509_REQ_sign(req, priv, EVP_sha256()), WOLFSSL_SUCCESS);
  70484. /* Signature is random and may be shorter or longer. */
  70485. ExpectIntGE((len = i2d_X509_REQ(req, &der)), 245);
  70486. ExpectIntLE(len, 253);
  70487. XFREE(der, NULL, DYNAMIC_TYPE_OPENSSL);
  70488. X509_REQ_free(req);
  70489. EVP_PKEY_free(pub);
  70490. EVP_PKEY_free(priv);
  70491. #ifdef FP_ECC
  70492. wc_ecc_fp_free();
  70493. #endif
  70494. #endif /* HAVE_ECC */
  70495. X509_NAME_free(name);
  70496. #endif
  70497. return EXPECT_RESULT();
  70498. }
  70499. static int test_wolfssl_PKCS7(void)
  70500. {
  70501. EXPECT_DECLS;
  70502. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7) && !defined(NO_BIO) && \
  70503. !defined(NO_RSA)
  70504. PKCS7* pkcs7 = NULL;
  70505. byte data[FOURK_BUF];
  70506. word32 len = sizeof(data);
  70507. const byte* p = data;
  70508. byte content[] = "Test data to encode.";
  70509. #if !defined(NO_RSA) & defined(USE_CERT_BUFFERS_2048)
  70510. BIO* bio = NULL;
  70511. byte key[sizeof(client_key_der_2048)];
  70512. word32 keySz = (word32)sizeof(key);
  70513. byte* out = NULL;
  70514. #endif
  70515. ExpectIntGT((len = (word32)CreatePKCS7SignedData(data, (int)len, content,
  70516. (word32)sizeof(content), 0, 0, 0, RSA_TYPE)), 0);
  70517. ExpectNull(pkcs7 = d2i_PKCS7(NULL, NULL, (int)len));
  70518. ExpectNull(pkcs7 = d2i_PKCS7(NULL, &p, 0));
  70519. ExpectNotNull(pkcs7 = d2i_PKCS7(NULL, &p, (int)len));
  70520. ExpectIntEQ(wolfSSL_PKCS7_verify(NULL, NULL, NULL, NULL, NULL,
  70521. PKCS7_NOVERIFY), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70522. PKCS7_free(pkcs7);
  70523. pkcs7 = NULL;
  70524. /* fail case, without PKCS7_NOVERIFY */
  70525. p = data;
  70526. ExpectNotNull(pkcs7 = d2i_PKCS7(NULL, &p, (int)len));
  70527. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, NULL, NULL,
  70528. 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70529. PKCS7_free(pkcs7);
  70530. pkcs7 = NULL;
  70531. /* success case, with PKCS7_NOVERIFY */
  70532. p = data;
  70533. ExpectNotNull(pkcs7 = d2i_PKCS7(NULL, &p, (int)len));
  70534. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, NULL, NULL,
  70535. PKCS7_NOVERIFY), WOLFSSL_SUCCESS);
  70536. #if !defined(NO_RSA) & defined(USE_CERT_BUFFERS_2048)
  70537. /* test i2d */
  70538. XMEMCPY(key, client_key_der_2048, keySz);
  70539. if (pkcs7 != NULL) {
  70540. pkcs7->privateKey = key;
  70541. pkcs7->privateKeySz = (word32)sizeof(key);
  70542. pkcs7->encryptOID = RSAk;
  70543. #ifdef NO_SHA
  70544. pkcs7->hashOID = SHA256h;
  70545. #else
  70546. pkcs7->hashOID = SHAh;
  70547. #endif
  70548. }
  70549. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  70550. ExpectIntEQ(i2d_PKCS7_bio(bio, pkcs7), 1);
  70551. #ifndef NO_ASN_TIME
  70552. ExpectIntEQ(i2d_PKCS7(pkcs7, &out), 655);
  70553. #else
  70554. ExpectIntEQ(i2d_PKCS7(pkcs7, &out), 625);
  70555. #endif
  70556. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  70557. BIO_free(bio);
  70558. #endif
  70559. PKCS7_free(NULL);
  70560. PKCS7_free(pkcs7);
  70561. #endif
  70562. return EXPECT_RESULT();
  70563. }
  70564. static int test_wolfSSL_PKCS7_sign(void)
  70565. {
  70566. EXPECT_DECLS;
  70567. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7) && !defined(NO_BIO) && \
  70568. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  70569. PKCS7* p7 = NULL;
  70570. PKCS7* p7Ver = NULL;
  70571. byte* out = NULL;
  70572. byte* tmpPtr = NULL;
  70573. int outLen = 0;
  70574. int flags = 0;
  70575. byte data[] = "Test data to encode.";
  70576. const char* cert = "./certs/server-cert.pem";
  70577. const char* key = "./certs/server-key.pem";
  70578. const char* ca = "./certs/ca-cert.pem";
  70579. WOLFSSL_BIO* certBio = NULL;
  70580. WOLFSSL_BIO* keyBio = NULL;
  70581. WOLFSSL_BIO* caBio = NULL;
  70582. WOLFSSL_BIO* inBio = NULL;
  70583. X509* signCert = NULL;
  70584. EVP_PKEY* signKey = NULL;
  70585. X509* caCert = NULL;
  70586. X509_STORE* store = NULL;
  70587. #ifndef NO_PKCS7_STREAM
  70588. int z;
  70589. int ret;
  70590. #endif /* !NO_PKCS7_STREAM */
  70591. /* read signer cert/key into BIO */
  70592. ExpectNotNull(certBio = BIO_new_file(cert, "r"));
  70593. ExpectNotNull(keyBio = BIO_new_file(key, "r"));
  70594. ExpectNotNull(signCert = PEM_read_bio_X509(certBio, NULL, 0, NULL));
  70595. ExpectNotNull(signKey = PEM_read_bio_PrivateKey(keyBio, NULL, 0, NULL));
  70596. /* read CA cert into store (for verify) */
  70597. ExpectNotNull(caBio = BIO_new_file(ca, "r"));
  70598. ExpectNotNull(caCert = PEM_read_bio_X509(caBio, NULL, 0, NULL));
  70599. ExpectNotNull(store = X509_STORE_new());
  70600. ExpectIntEQ(X509_STORE_add_cert(store, caCert), 1);
  70601. /* data to be signed into BIO */
  70602. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  70603. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  70604. /* PKCS7_sign, bad args: signer NULL */
  70605. ExpectNull(p7 = PKCS7_sign(NULL, signKey, NULL, inBio, 0));
  70606. /* PKCS7_sign, bad args: signer key NULL */
  70607. ExpectNull(p7 = PKCS7_sign(signCert, NULL, NULL, inBio, 0));
  70608. /* PKCS7_sign, bad args: in data NULL without PKCS7_STREAM */
  70609. ExpectNull(p7 = PKCS7_sign(signCert, signKey, NULL, NULL, 0));
  70610. /* PKCS7_sign, bad args: PKCS7_NOCERTS flag not supported */
  70611. ExpectNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, PKCS7_NOCERTS));
  70612. /* PKCS7_sign, bad args: PKCS7_PARTIAL flag not supported */
  70613. ExpectNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, PKCS7_PARTIAL));
  70614. /* TEST SUCCESS: Not detached, not streaming, not MIME */
  70615. {
  70616. flags = PKCS7_BINARY;
  70617. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  70618. ExpectIntGT((outLen = i2d_PKCS7(p7, &out)), 0);
  70619. /* verify with d2i_PKCS7 */
  70620. tmpPtr = out;
  70621. ExpectNotNull(p7Ver = d2i_PKCS7(NULL, (const byte**)&tmpPtr, outLen));
  70622. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, NULL, NULL, flags), 1);
  70623. PKCS7_free(p7Ver);
  70624. p7Ver = NULL;
  70625. /* verify with wc_PKCS7_VerifySignedData */
  70626. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  70627. ExpectIntEQ(wc_PKCS7_Init(p7Ver, HEAP_HINT, INVALID_DEVID), 0);
  70628. ExpectIntEQ(wc_PKCS7_VerifySignedData(p7Ver, out, (word32)outLen), 0);
  70629. #ifndef NO_PKCS7_STREAM
  70630. /* verify with wc_PKCS7_VerifySignedData streaming */
  70631. wc_PKCS7_Free(p7Ver);
  70632. p7Ver = NULL;
  70633. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  70634. ExpectIntEQ(wc_PKCS7_Init(p7Ver, HEAP_HINT, INVALID_DEVID), 0);
  70635. /* test for streaming */
  70636. ret = -1;
  70637. for (z = 0; z < outLen && ret != 0; z++) {
  70638. ret = wc_PKCS7_VerifySignedData(p7Ver, out + z, 1);
  70639. if (ret < 0){
  70640. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  70641. }
  70642. }
  70643. ExpectIntEQ(ret, 0);
  70644. #endif /* !NO_PKCS7_STREAM */
  70645. /* compare the signer found to expected signer */
  70646. ExpectIntNE(p7Ver->verifyCertSz, 0);
  70647. tmpPtr = NULL;
  70648. ExpectIntEQ(i2d_X509(signCert, &tmpPtr), p7Ver->verifyCertSz);
  70649. ExpectIntEQ(XMEMCMP(tmpPtr, p7Ver->verifyCert, p7Ver->verifyCertSz), 0);
  70650. XFREE(tmpPtr, NULL, DYNAMIC_TYPE_OPENSSL);
  70651. tmpPtr = NULL;
  70652. wc_PKCS7_Free(p7Ver);
  70653. p7Ver = NULL;
  70654. ExpectNotNull(out);
  70655. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  70656. out = NULL;
  70657. PKCS7_free(p7);
  70658. p7 = NULL;
  70659. }
  70660. /* TEST SUCCESS: Not detached, streaming, not MIME. Also bad arg
  70661. * tests for PKCS7_final() while we have a PKCS7 pointer to use */
  70662. {
  70663. /* re-populate input BIO, may have been consumed */
  70664. BIO_free(inBio);
  70665. inBio = NULL;
  70666. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  70667. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  70668. flags = PKCS7_BINARY | PKCS7_STREAM;
  70669. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  70670. ExpectIntEQ(PKCS7_final(p7, inBio, flags), 1);
  70671. ExpectIntGT((outLen = i2d_PKCS7(p7, &out)), 0);
  70672. /* PKCS7_final, bad args: PKCS7 null */
  70673. ExpectIntEQ(PKCS7_final(NULL, inBio, 0), 0);
  70674. /* PKCS7_final, bad args: PKCS7 null */
  70675. ExpectIntEQ(PKCS7_final(p7, NULL, 0), 0);
  70676. tmpPtr = out;
  70677. ExpectNotNull(p7Ver = d2i_PKCS7(NULL, (const byte**)&tmpPtr, outLen));
  70678. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, NULL, NULL, flags), 1);
  70679. PKCS7_free(p7Ver);
  70680. p7Ver = NULL;
  70681. ExpectNotNull(out);
  70682. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  70683. out = NULL;
  70684. PKCS7_free(p7);
  70685. p7 = NULL;
  70686. }
  70687. /* TEST SUCCESS: Detached, not streaming, not MIME */
  70688. {
  70689. /* re-populate input BIO, may have been consumed */
  70690. BIO_free(inBio);
  70691. inBio = NULL;
  70692. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  70693. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  70694. flags = PKCS7_BINARY | PKCS7_DETACHED;
  70695. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  70696. ExpectIntGT((outLen = i2d_PKCS7(p7, &out)), 0);
  70697. /* verify with wolfCrypt, d2i_PKCS7 does not support detached content */
  70698. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  70699. if (p7Ver != NULL) {
  70700. p7Ver->content = data;
  70701. p7Ver->contentSz = sizeof(data);
  70702. }
  70703. ExpectIntEQ(wc_PKCS7_VerifySignedData(p7Ver, out, (word32)outLen), 0);
  70704. wc_PKCS7_Free(p7Ver);
  70705. p7Ver = NULL;
  70706. #ifndef NO_PKCS7_STREAM
  70707. /* verify with wc_PKCS7_VerifySignedData streaming */
  70708. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  70709. if (p7Ver != NULL) {
  70710. p7Ver->content = data;
  70711. p7Ver->contentSz = sizeof(data);
  70712. }
  70713. /* test for streaming */
  70714. ret = -1;
  70715. for (z = 0; z < outLen && ret != 0; z++) {
  70716. ret = wc_PKCS7_VerifySignedData(p7Ver, out + z, 1);
  70717. if (ret < 0){
  70718. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  70719. }
  70720. }
  70721. ExpectIntEQ(ret, 0);
  70722. wc_PKCS7_Free(p7Ver);
  70723. p7Ver = NULL;
  70724. #endif /* !NO_PKCS7_STREAM */
  70725. /* verify expected failure (NULL return) from d2i_PKCS7, it does not
  70726. * yet support detached content */
  70727. tmpPtr = out;
  70728. ExpectNull(p7Ver = d2i_PKCS7(NULL, (const byte**)&tmpPtr, outLen));
  70729. PKCS7_free(p7Ver);
  70730. p7Ver = NULL;
  70731. ExpectNotNull(out);
  70732. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  70733. out = NULL;
  70734. PKCS7_free(p7);
  70735. p7 = NULL;
  70736. }
  70737. /* TEST SUCCESS: Detached, streaming, not MIME */
  70738. {
  70739. /* re-populate input BIO, may have been consumed */
  70740. BIO_free(inBio);
  70741. inBio = NULL;
  70742. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  70743. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  70744. flags = PKCS7_BINARY | PKCS7_DETACHED | PKCS7_STREAM;
  70745. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  70746. ExpectIntEQ(PKCS7_final(p7, inBio, flags), 1);
  70747. ExpectIntGT((outLen = i2d_PKCS7(p7, &out)), 0);
  70748. /* verify with wolfCrypt, d2i_PKCS7 does not support detached content */
  70749. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  70750. if (p7Ver != NULL) {
  70751. p7Ver->content = data;
  70752. p7Ver->contentSz = sizeof(data);
  70753. }
  70754. ExpectIntEQ(wc_PKCS7_VerifySignedData(p7Ver, out, (word32)outLen), 0);
  70755. wc_PKCS7_Free(p7Ver);
  70756. p7Ver = NULL;
  70757. ExpectNotNull(out);
  70758. #ifndef NO_PKCS7_STREAM
  70759. /* verify with wc_PKCS7_VerifySignedData streaming */
  70760. ExpectNotNull(p7Ver = wc_PKCS7_New(HEAP_HINT, testDevId));
  70761. if (p7Ver != NULL) {
  70762. p7Ver->content = data;
  70763. p7Ver->contentSz = sizeof(data);
  70764. }
  70765. /* test for streaming */
  70766. ret = -1;
  70767. for (z = 0; z < outLen && ret != 0; z++) {
  70768. ret = wc_PKCS7_VerifySignedData(p7Ver, out + z, 1);
  70769. if (ret < 0){
  70770. ExpectIntEQ(ret, WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E));
  70771. }
  70772. }
  70773. ExpectIntEQ(ret, 0);
  70774. ExpectNotNull(out);
  70775. wc_PKCS7_Free(p7Ver);
  70776. p7Ver = NULL;
  70777. #endif /* !NO_PKCS7_STREAM */
  70778. XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  70779. PKCS7_free(p7);
  70780. p7 = NULL;
  70781. }
  70782. X509_STORE_free(store);
  70783. X509_free(caCert);
  70784. X509_free(signCert);
  70785. EVP_PKEY_free(signKey);
  70786. BIO_free(inBio);
  70787. BIO_free(keyBio);
  70788. BIO_free(certBio);
  70789. BIO_free(caBio);
  70790. #endif
  70791. return EXPECT_RESULT();
  70792. }
  70793. static int test_wolfSSL_PKCS7_SIGNED_new(void)
  70794. {
  70795. EXPECT_DECLS;
  70796. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7)
  70797. PKCS7_SIGNED* pkcs7 = NULL;
  70798. ExpectNotNull(pkcs7 = PKCS7_SIGNED_new());
  70799. ExpectIntEQ(pkcs7->contentOID, SIGNED_DATA);
  70800. PKCS7_SIGNED_free(pkcs7);
  70801. #endif
  70802. return EXPECT_RESULT();
  70803. }
  70804. #ifndef NO_BIO
  70805. static int test_wolfSSL_PEM_write_bio_PKCS7(void)
  70806. {
  70807. EXPECT_DECLS;
  70808. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM)
  70809. PKCS7* pkcs7 = NULL;
  70810. BIO* bio = NULL;
  70811. const byte* cert_buf = NULL;
  70812. int ret = 0;
  70813. WC_RNG rng;
  70814. const byte data[] = { /* Hello World */
  70815. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  70816. 0x72,0x6c,0x64
  70817. };
  70818. #ifndef NO_RSA
  70819. #if defined(USE_CERT_BUFFERS_2048)
  70820. byte key[sizeof(client_key_der_2048)];
  70821. byte cert[sizeof(client_cert_der_2048)];
  70822. word32 keySz = (word32)sizeof(key);
  70823. word32 certSz = (word32)sizeof(cert);
  70824. XMEMSET(key, 0, keySz);
  70825. XMEMSET(cert, 0, certSz);
  70826. XMEMCPY(key, client_key_der_2048, keySz);
  70827. XMEMCPY(cert, client_cert_der_2048, certSz);
  70828. #elif defined(USE_CERT_BUFFERS_1024)
  70829. byte key[sizeof_client_key_der_1024];
  70830. byte cert[sizeof(sizeof_client_cert_der_1024)];
  70831. word32 keySz = (word32)sizeof(key);
  70832. word32 certSz = (word32)sizeof(cert);
  70833. XMEMSET(key, 0, keySz);
  70834. XMEMSET(cert, 0, certSz);
  70835. XMEMCPY(key, client_key_der_1024, keySz);
  70836. XMEMCPY(cert, client_cert_der_1024, certSz);
  70837. #else
  70838. unsigned char cert[ONEK_BUF];
  70839. unsigned char key[ONEK_BUF];
  70840. XFILE fp = XBADFILE;
  70841. int certSz;
  70842. int keySz;
  70843. ExpectTrue((fp = XFOPEN("./certs/1024/client-cert.der", "rb")) !=
  70844. XBADFILE);
  70845. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_client_cert_der_1024,
  70846. fp), 0);
  70847. if (fp != XBADFILE) {
  70848. XFCLOSE(fp);
  70849. fp = XBADFILE;
  70850. }
  70851. ExpectTrue((fp = XFOPEN("./certs/1024/client-key.der", "rb")) !=
  70852. XBADFILE);
  70853. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_client_key_der_1024, fp),
  70854. 0);
  70855. if (fp != XBADFILE) {
  70856. XFCLOSE(fp);
  70857. fp = XBADFILE;
  70858. }
  70859. #endif
  70860. #elif defined(HAVE_ECC)
  70861. #if defined(USE_CERT_BUFFERS_256)
  70862. unsigned char cert[sizeof(cliecc_cert_der_256)];
  70863. unsigned char key[sizeof(ecc_clikey_der_256)];
  70864. int certSz = (int)sizeof(cert);
  70865. int keySz = (int)sizeof(key);
  70866. XMEMSET(cert, 0, certSz);
  70867. XMEMSET(key, 0, keySz);
  70868. XMEMCPY(cert, cliecc_cert_der_256, sizeof_cliecc_cert_der_256);
  70869. XMEMCPY(key, ecc_clikey_der_256, sizeof_ecc_clikey_der_256);
  70870. #else
  70871. unsigned char cert[ONEK_BUF];
  70872. unsigned char key[ONEK_BUF];
  70873. XFILE fp = XBADFILE;
  70874. int certSz, keySz;
  70875. ExpectTrue((fp = XFOPEN("./certs/client-ecc-cert.der", "rb")) !=
  70876. XBADFILE);
  70877. ExpectIntGT(certSz = (int)XFREAD(cert, 1, sizeof_cliecc_cert_der_256,
  70878. fp), 0);
  70879. if (fp != XBADFILE) {
  70880. XFCLOSE(fp);
  70881. fp = XBADFILE;
  70882. }
  70883. ExpectTrue((fp = XFOPEN("./certs/client-ecc-key.der", "rb")) !=
  70884. XBADFILE);
  70885. ExpectIntGT(keySz = (int)XFREAD(key, 1, sizeof_ecc_clikey_der_256, fp),
  70886. 0);
  70887. if (fp != XBADFILE) {
  70888. XFCLOSE(fp);
  70889. fp = XBADFILE;
  70890. }
  70891. #endif
  70892. #else
  70893. #error PKCS7 requires ECC or RSA
  70894. #endif
  70895. ExpectNotNull(pkcs7 = wc_PKCS7_New(HEAP_HINT, testDevId));
  70896. /* initialize with DER encoded cert */
  70897. ExpectIntEQ(wc_PKCS7_InitWithCert(pkcs7, (byte*)cert, (word32)certSz), 0);
  70898. /* init rng */
  70899. XMEMSET(&rng, 0, sizeof(WC_RNG));
  70900. ExpectIntEQ(wc_InitRng(&rng), 0);
  70901. if (pkcs7 != NULL) {
  70902. pkcs7->rng = &rng;
  70903. pkcs7->content = (byte*)data; /* not used for ex */
  70904. pkcs7->contentSz = (word32)sizeof(data);
  70905. pkcs7->contentOID = SIGNED_DATA;
  70906. pkcs7->privateKey = key;
  70907. pkcs7->privateKeySz = (word32)sizeof(key);
  70908. pkcs7->encryptOID = RSAk;
  70909. #ifdef NO_SHA
  70910. pkcs7->hashOID = SHA256h;
  70911. #else
  70912. pkcs7->hashOID = SHAh;
  70913. #endif
  70914. pkcs7->signedAttribs = NULL;
  70915. pkcs7->signedAttribsSz = 0;
  70916. }
  70917. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  70918. /* Write PKCS#7 PEM to BIO, the function converts the DER to PEM cert*/
  70919. ExpectIntEQ(PEM_write_bio_PKCS7(bio, pkcs7), WOLFSSL_SUCCESS);
  70920. /* Read PKCS#7 PEM from BIO */
  70921. ret = wolfSSL_BIO_get_mem_data(bio, &cert_buf);
  70922. ExpectIntGE(ret, 0);
  70923. BIO_free(bio);
  70924. wc_PKCS7_Free(pkcs7);
  70925. wc_FreeRng(&rng);
  70926. #endif
  70927. return EXPECT_RESULT();
  70928. }
  70929. #ifdef HAVE_SMIME
  70930. /* // NOLINTBEGIN(clang-analyzer-unix.Stream) */
  70931. static int test_wolfSSL_SMIME_read_PKCS7(void)
  70932. {
  70933. EXPECT_DECLS;
  70934. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7) && !defined(NO_FILESYSTEM) && \
  70935. !defined(NO_RSA)
  70936. PKCS7* pkcs7 = NULL;
  70937. BIO* bio = NULL;
  70938. BIO* bcont = NULL;
  70939. BIO* out = NULL;
  70940. const byte* outBuf = NULL;
  70941. int outBufLen = 0;
  70942. static const char contTypeText[] = "Content-Type: text/plain\r\n\r\n";
  70943. XFILE smimeTestFile = XBADFILE;
  70944. ExpectTrue((smimeTestFile = XFOPEN("./certs/test/smime-test.p7s", "r")) !=
  70945. XBADFILE);
  70946. /* smime-test.p7s */
  70947. bio = wolfSSL_BIO_new(wolfSSL_BIO_s_file());
  70948. ExpectNotNull(bio);
  70949. ExpectIntEQ(wolfSSL_BIO_set_fp(bio, smimeTestFile, BIO_CLOSE), SSL_SUCCESS);
  70950. pkcs7 = wolfSSL_SMIME_read_PKCS7(bio, &bcont);
  70951. ExpectNotNull(pkcs7);
  70952. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, bcont, NULL,
  70953. PKCS7_NOVERIFY), SSL_SUCCESS);
  70954. if (smimeTestFile != XBADFILE) {
  70955. XFCLOSE(smimeTestFile);
  70956. smimeTestFile = XBADFILE;
  70957. }
  70958. if (bcont) BIO_free(bcont);
  70959. bcont = NULL;
  70960. wolfSSL_PKCS7_free(pkcs7);
  70961. pkcs7 = NULL;
  70962. /* smime-test-multipart.p7s */
  70963. smimeTestFile = XFOPEN("./certs/test/smime-test-multipart.p7s", "r");
  70964. ExpectFalse(smimeTestFile == XBADFILE);
  70965. ExpectIntEQ(wolfSSL_BIO_set_fp(bio, smimeTestFile, BIO_CLOSE), SSL_SUCCESS);
  70966. pkcs7 = wolfSSL_SMIME_read_PKCS7(bio, &bcont);
  70967. ExpectNotNull(pkcs7);
  70968. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, bcont, NULL,
  70969. PKCS7_NOVERIFY), SSL_SUCCESS);
  70970. if (smimeTestFile != XBADFILE) {
  70971. XFCLOSE(smimeTestFile);
  70972. smimeTestFile = XBADFILE;
  70973. }
  70974. if (bcont) BIO_free(bcont);
  70975. bcont = NULL;
  70976. wolfSSL_PKCS7_free(pkcs7);
  70977. pkcs7 = NULL;
  70978. /* smime-test-multipart-badsig.p7s */
  70979. smimeTestFile = XFOPEN("./certs/test/smime-test-multipart-badsig.p7s", "r");
  70980. ExpectFalse(smimeTestFile == XBADFILE);
  70981. ExpectIntEQ(wolfSSL_BIO_set_fp(bio, smimeTestFile, BIO_CLOSE), SSL_SUCCESS);
  70982. pkcs7 = wolfSSL_SMIME_read_PKCS7(bio, &bcont);
  70983. ExpectNotNull(pkcs7); /* can read in the unverified smime bundle */
  70984. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, bcont, NULL,
  70985. PKCS7_NOVERIFY), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  70986. if (smimeTestFile != XBADFILE) {
  70987. XFCLOSE(smimeTestFile);
  70988. smimeTestFile = XBADFILE;
  70989. }
  70990. if (bcont) BIO_free(bcont);
  70991. bcont = NULL;
  70992. wolfSSL_PKCS7_free(pkcs7);
  70993. pkcs7 = NULL;
  70994. /* smime-test-canon.p7s */
  70995. smimeTestFile = XFOPEN("./certs/test/smime-test-canon.p7s", "r");
  70996. ExpectFalse(smimeTestFile == XBADFILE);
  70997. ExpectIntEQ(wolfSSL_BIO_set_fp(bio, smimeTestFile, BIO_CLOSE), SSL_SUCCESS);
  70998. pkcs7 = wolfSSL_SMIME_read_PKCS7(bio, &bcont);
  70999. ExpectNotNull(pkcs7);
  71000. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, bcont, NULL,
  71001. PKCS7_NOVERIFY), SSL_SUCCESS);
  71002. if (smimeTestFile != XBADFILE) {
  71003. XFCLOSE(smimeTestFile);
  71004. smimeTestFile = XBADFILE;
  71005. }
  71006. if (bcont) BIO_free(bcont);
  71007. bcont = NULL;
  71008. wolfSSL_PKCS7_free(pkcs7);
  71009. pkcs7 = NULL;
  71010. /* Test PKCS7_TEXT, PKCS7_verify() should remove Content-Type: text/plain */
  71011. smimeTestFile = XFOPEN("./certs/test/smime-test-canon.p7s", "r");
  71012. ExpectFalse(smimeTestFile == XBADFILE);
  71013. ExpectIntEQ(wolfSSL_BIO_set_fp(bio, smimeTestFile, BIO_CLOSE), SSL_SUCCESS);
  71014. pkcs7 = wolfSSL_SMIME_read_PKCS7(bio, &bcont);
  71015. ExpectNotNull(pkcs7);
  71016. out = wolfSSL_BIO_new(BIO_s_mem());
  71017. ExpectNotNull(out);
  71018. ExpectIntEQ(wolfSSL_PKCS7_verify(pkcs7, NULL, NULL, bcont, out,
  71019. PKCS7_NOVERIFY | PKCS7_TEXT), SSL_SUCCESS);
  71020. ExpectIntGT((outBufLen = BIO_get_mem_data(out, &outBuf)), 0);
  71021. /* Content-Type should not show up at beginning of output buffer */
  71022. ExpectIntGT(outBufLen, XSTRLEN(contTypeText));
  71023. ExpectIntGT(XMEMCMP(outBuf, contTypeText, XSTRLEN(contTypeText)), 0);
  71024. BIO_free(out);
  71025. BIO_free(bio);
  71026. if (bcont) BIO_free(bcont);
  71027. wolfSSL_PKCS7_free(pkcs7);
  71028. #endif
  71029. return EXPECT_RESULT();
  71030. }
  71031. /* // NOLINTEND(clang-analyzer-unix.Stream) */
  71032. static int test_wolfSSL_SMIME_write_PKCS7(void)
  71033. {
  71034. EXPECT_DECLS;
  71035. #if defined(OPENSSL_ALL) && defined(HAVE_PKCS7) && !defined(NO_RSA)
  71036. PKCS7* p7 = NULL;
  71037. PKCS7* p7Ver = NULL;
  71038. int flags = 0;
  71039. byte data[] = "Test data to encode.";
  71040. const char* cert = "./certs/server-cert.pem";
  71041. const char* key = "./certs/server-key.pem";
  71042. const char* ca = "./certs/ca-cert.pem";
  71043. WOLFSSL_BIO* certBio = NULL;
  71044. WOLFSSL_BIO* keyBio = NULL;
  71045. WOLFSSL_BIO* caBio = NULL;
  71046. WOLFSSL_BIO* inBio = NULL;
  71047. WOLFSSL_BIO* outBio = NULL;
  71048. WOLFSSL_BIO* content = NULL;
  71049. X509* signCert = NULL;
  71050. EVP_PKEY* signKey = NULL;
  71051. X509* caCert = NULL;
  71052. X509_STORE* store = NULL;
  71053. /* read signer cert/key into BIO */
  71054. ExpectNotNull(certBio = BIO_new_file(cert, "r"));
  71055. ExpectNotNull(keyBio = BIO_new_file(key, "r"));
  71056. ExpectNotNull(signCert = PEM_read_bio_X509(certBio, NULL, 0, NULL));
  71057. ExpectNotNull(signKey = PEM_read_bio_PrivateKey(keyBio, NULL, 0, NULL));
  71058. /* read CA cert into store (for verify) */
  71059. ExpectNotNull(caBio = BIO_new_file(ca, "r"));
  71060. ExpectNotNull(caCert = PEM_read_bio_X509(caBio, NULL, 0, NULL));
  71061. ExpectNotNull(store = X509_STORE_new());
  71062. ExpectIntEQ(X509_STORE_add_cert(store, caCert), 1);
  71063. /* generate and verify SMIME: not detached */
  71064. {
  71065. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  71066. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  71067. flags = PKCS7_STREAM;
  71068. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  71069. ExpectNotNull(outBio = BIO_new(BIO_s_mem()));
  71070. ExpectIntEQ(SMIME_write_PKCS7(outBio, p7, inBio, flags), 1);
  71071. /* bad arg: out NULL */
  71072. ExpectIntEQ(SMIME_write_PKCS7(NULL, p7, inBio, flags), 0);
  71073. /* bad arg: pkcs7 NULL */
  71074. ExpectIntEQ(SMIME_write_PKCS7(outBio, NULL, inBio, flags), 0);
  71075. ExpectNotNull(p7Ver = SMIME_read_PKCS7(outBio, &content));
  71076. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, NULL, NULL, flags), 1);
  71077. BIO_free(content);
  71078. content = NULL;
  71079. BIO_free(inBio);
  71080. inBio = NULL;
  71081. BIO_free(outBio);
  71082. outBio = NULL;
  71083. PKCS7_free(p7Ver);
  71084. p7Ver = NULL;
  71085. PKCS7_free(p7);
  71086. p7 = NULL;
  71087. }
  71088. /* generate and verify SMIME: not detached, add Content-Type */
  71089. {
  71090. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  71091. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  71092. flags = PKCS7_STREAM | PKCS7_TEXT;
  71093. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  71094. ExpectNotNull(outBio = BIO_new(BIO_s_mem()));
  71095. ExpectIntEQ(SMIME_write_PKCS7(outBio, p7, inBio, flags), 1);
  71096. ExpectNotNull(p7Ver = SMIME_read_PKCS7(outBio, &content));
  71097. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, NULL, NULL, flags), 1);
  71098. BIO_free(content);
  71099. content = NULL;
  71100. BIO_free(inBio);
  71101. inBio = NULL;
  71102. BIO_free(outBio);
  71103. outBio = NULL;
  71104. PKCS7_free(p7Ver);
  71105. p7Ver = NULL;
  71106. PKCS7_free(p7);
  71107. p7 = NULL;
  71108. }
  71109. /* generate and verify SMIME: detached */
  71110. {
  71111. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  71112. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  71113. flags = PKCS7_DETACHED | PKCS7_STREAM;
  71114. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  71115. ExpectNotNull(outBio = BIO_new(BIO_s_mem()));
  71116. ExpectIntEQ(SMIME_write_PKCS7(outBio, p7, inBio, flags), 1);
  71117. ExpectNotNull(p7Ver = SMIME_read_PKCS7(outBio, &content));
  71118. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, content, NULL, flags), 1);
  71119. BIO_free(content);
  71120. content = NULL;
  71121. BIO_free(inBio);
  71122. inBio = NULL;
  71123. BIO_free(outBio);
  71124. outBio = NULL;
  71125. PKCS7_free(p7Ver);
  71126. p7Ver = NULL;
  71127. PKCS7_free(p7);
  71128. p7 = NULL;
  71129. }
  71130. /* generate and verify SMIME: PKCS7_TEXT to add Content-Type header */
  71131. {
  71132. ExpectNotNull(inBio = BIO_new(BIO_s_mem()));
  71133. ExpectIntGT(BIO_write(inBio, data, sizeof(data)), 0);
  71134. flags = PKCS7_STREAM | PKCS7_DETACHED | PKCS7_TEXT;
  71135. ExpectNotNull(p7 = PKCS7_sign(signCert, signKey, NULL, inBio, flags));
  71136. ExpectNotNull(outBio = BIO_new(BIO_s_mem()));
  71137. ExpectIntEQ(SMIME_write_PKCS7(outBio, p7, inBio, flags), 1);
  71138. ExpectNotNull(p7Ver = SMIME_read_PKCS7(outBio, &content));
  71139. ExpectIntEQ(PKCS7_verify(p7Ver, NULL, store, content, NULL, flags), 1);
  71140. BIO_free(content);
  71141. content = NULL;
  71142. BIO_free(inBio);
  71143. inBio = NULL;
  71144. BIO_free(outBio);
  71145. outBio = NULL;
  71146. PKCS7_free(p7Ver);
  71147. p7Ver = NULL;
  71148. PKCS7_free(p7);
  71149. p7 = NULL;
  71150. }
  71151. X509_STORE_free(store);
  71152. X509_free(caCert);
  71153. X509_free(signCert);
  71154. EVP_PKEY_free(signKey);
  71155. BIO_free(keyBio);
  71156. BIO_free(certBio);
  71157. BIO_free(caBio);
  71158. #endif
  71159. return EXPECT_RESULT();
  71160. }
  71161. #endif /* HAVE_SMIME */
  71162. #endif /* !NO_BIO */
  71163. /* Test of X509 store use outside of SSL context w/ CRL lookup (ALWAYS
  71164. * returns 0) */
  71165. static int test_X509_STORE_No_SSL_CTX(void)
  71166. {
  71167. EXPECT_DECLS;
  71168. #if defined(OPENSSL_ALL) && defined(WOLFSSL_CERT_GEN) && \
  71169. (defined(WOLFSSL_CERT_REQ) || defined(WOLFSSL_CERT_EXT)) && \
  71170. !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_DIR) && \
  71171. (defined(OPENSSL_EXTRA) || defined(WOLFSSL_WPAS_SMALL)) && \
  71172. defined(HAVE_CRL) && !defined(NO_RSA)
  71173. X509_STORE * store = NULL;
  71174. X509_STORE_CTX * storeCtx = NULL;
  71175. X509_CRL * crl = NULL;
  71176. X509 * ca = NULL;
  71177. X509 * cert = NULL;
  71178. const char cliCrlPem[] = "./certs/crl/cliCrl.pem";
  71179. const char srvCert[] = "./certs/server-cert.pem";
  71180. const char caCert[] = "./certs/ca-cert.pem";
  71181. const char caDir[] = "./certs/crl/hash_pem";
  71182. XFILE fp = XBADFILE;
  71183. X509_LOOKUP * lookup = NULL;
  71184. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  71185. /* Set up store with CA */
  71186. ExpectNotNull((ca = wolfSSL_X509_load_certificate_file(caCert,
  71187. SSL_FILETYPE_PEM)));
  71188. ExpectIntEQ(X509_STORE_add_cert(store, ca), SSL_SUCCESS);
  71189. /* Add CRL lookup directory to store
  71190. * NOTE: test uses ./certs/crl/hash_pem/0fdb2da4.r0, which is a copy
  71191. * of crl.pem */
  71192. ExpectNotNull((lookup = X509_STORE_add_lookup(store,
  71193. X509_LOOKUP_hash_dir())));
  71194. ExpectIntEQ(X509_LOOKUP_ctrl(lookup, X509_L_ADD_DIR, caDir,
  71195. X509_FILETYPE_PEM, NULL), SSL_SUCCESS);
  71196. ExpectIntEQ(X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK),
  71197. SSL_SUCCESS);
  71198. /* Add CRL to store NOT containing the verified certificate, which
  71199. * forces use of the CRL lookup directory */
  71200. ExpectTrue((fp = XFOPEN(cliCrlPem, "rb")) != XBADFILE);
  71201. ExpectNotNull(crl = (X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  71202. NULL, NULL));
  71203. if (fp != XBADFILE)
  71204. XFCLOSE(fp);
  71205. ExpectIntEQ(X509_STORE_add_crl(store, crl), SSL_SUCCESS);
  71206. /* Create verification context outside of an SSL session */
  71207. ExpectNotNull((storeCtx = X509_STORE_CTX_new()));
  71208. ExpectNotNull((cert = wolfSSL_X509_load_certificate_file(srvCert,
  71209. SSL_FILETYPE_PEM)));
  71210. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, cert, NULL), SSL_SUCCESS);
  71211. /* Perform verification, which should NOT indicate CRL missing due to the
  71212. * store CM's X509 store pointer being NULL */
  71213. ExpectIntNE(X509_verify_cert(storeCtx), WC_NO_ERR_TRACE(CRL_MISSING));
  71214. X509_CRL_free(crl);
  71215. X509_STORE_free(store);
  71216. X509_STORE_CTX_free(storeCtx);
  71217. X509_free(cert);
  71218. X509_free(ca);
  71219. #endif
  71220. return EXPECT_RESULT();
  71221. }
  71222. /* Test of X509 store use outside of SSL context w/ CRL lookup, but
  71223. * with X509_LOOKUP_add_dir and X509_FILETYPE_ASN1. */
  71224. static int test_X509_LOOKUP_add_dir(void)
  71225. {
  71226. EXPECT_DECLS;
  71227. #if defined(OPENSSL_ALL) && defined(WOLFSSL_CERT_GEN) && \
  71228. (defined(WOLFSSL_CERT_REQ) || defined(WOLFSSL_CERT_EXT)) && \
  71229. !defined(NO_FILESYSTEM) && !defined(NO_WOLFSSL_DIR) && \
  71230. (defined(OPENSSL_EXTRA) || defined(WOLFSSL_WPAS_SMALL)) && \
  71231. defined(HAVE_CRL) && !defined(NO_RSA)
  71232. X509_STORE * store = NULL;
  71233. X509_STORE_CTX * storeCtx = NULL;
  71234. X509_CRL * crl = NULL;
  71235. X509 * ca = NULL;
  71236. X509 * cert = NULL;
  71237. const char cliCrlPem[] = "./certs/crl/cliCrl.pem";
  71238. const char srvCert[] = "./certs/server-cert.pem";
  71239. const char caCert[] = "./certs/ca-cert.pem";
  71240. const char caDir[] = "./certs/crl/hash_der";
  71241. XFILE fp = XBADFILE;
  71242. X509_LOOKUP * lookup = NULL;
  71243. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  71244. /* Set up store with CA */
  71245. ExpectNotNull((ca = wolfSSL_X509_load_certificate_file(caCert,
  71246. SSL_FILETYPE_PEM)));
  71247. ExpectIntEQ(X509_STORE_add_cert(store, ca), SSL_SUCCESS);
  71248. /* Add CRL lookup directory to store.
  71249. * Test uses ./certs/crl/hash_der/0fdb2da4.r0, which is a copy
  71250. * of crl.der */
  71251. ExpectNotNull((lookup = X509_STORE_add_lookup(store,
  71252. X509_LOOKUP_hash_dir())));
  71253. ExpectIntEQ(X509_LOOKUP_add_dir(lookup, caDir, X509_FILETYPE_ASN1),
  71254. SSL_SUCCESS);
  71255. ExpectIntEQ(X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK),
  71256. SSL_SUCCESS);
  71257. /* Add CRL to store NOT containing the verified certificate, which
  71258. * forces use of the CRL lookup directory */
  71259. ExpectTrue((fp = XFOPEN(cliCrlPem, "rb")) != XBADFILE);
  71260. ExpectNotNull(crl = (X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  71261. NULL, NULL));
  71262. if (fp != XBADFILE) {
  71263. XFCLOSE(fp);
  71264. fp = XBADFILE;
  71265. }
  71266. ExpectIntEQ(X509_STORE_add_crl(store, crl), SSL_SUCCESS);
  71267. /* Create verification context outside of an SSL session */
  71268. ExpectNotNull((storeCtx = X509_STORE_CTX_new()));
  71269. ExpectNotNull((cert = wolfSSL_X509_load_certificate_file(srvCert,
  71270. SSL_FILETYPE_PEM)));
  71271. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, cert, NULL), SSL_SUCCESS);
  71272. /* Perform verification, which should NOT return CRL missing */
  71273. ExpectIntNE(X509_verify_cert(storeCtx), WC_NO_ERR_TRACE(CRL_MISSING));
  71274. X509_CRL_free(crl);
  71275. crl = NULL;
  71276. X509_STORE_free(store);
  71277. store = NULL;
  71278. X509_STORE_CTX_free(storeCtx);
  71279. storeCtx = NULL;
  71280. X509_free(cert);
  71281. cert = NULL;
  71282. X509_free(ca);
  71283. ca = NULL;
  71284. /* Now repeat the same, but look for X509_FILETYPE_PEM.
  71285. * We should get CRL_MISSING at the end, because the lookup
  71286. * dir has only ASN1 CRLs. */
  71287. ExpectNotNull(store = (X509_STORE *)X509_STORE_new());
  71288. ExpectNotNull((ca = wolfSSL_X509_load_certificate_file(caCert,
  71289. SSL_FILETYPE_PEM)));
  71290. ExpectIntEQ(X509_STORE_add_cert(store, ca), SSL_SUCCESS);
  71291. ExpectNotNull((lookup = X509_STORE_add_lookup(store,
  71292. X509_LOOKUP_hash_dir())));
  71293. ExpectIntEQ(X509_LOOKUP_add_dir(lookup, caDir, X509_FILETYPE_PEM),
  71294. SSL_SUCCESS);
  71295. ExpectIntEQ(X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK),
  71296. SSL_SUCCESS);
  71297. ExpectTrue((fp = XFOPEN(cliCrlPem, "rb")) != XBADFILE);
  71298. ExpectNotNull(crl = (X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  71299. NULL, NULL));
  71300. if (fp != XBADFILE) {
  71301. XFCLOSE(fp);
  71302. fp = XBADFILE;
  71303. }
  71304. ExpectIntEQ(X509_STORE_add_crl(store, crl), SSL_SUCCESS);
  71305. ExpectNotNull((storeCtx = X509_STORE_CTX_new()));
  71306. ExpectNotNull((cert = wolfSSL_X509_load_certificate_file(srvCert,
  71307. SSL_FILETYPE_PEM)));
  71308. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, cert, NULL), SSL_SUCCESS);
  71309. /* Now we SHOULD get CRL_MISSING, because we looked for PEM
  71310. * in dir containing only ASN1/DER. */
  71311. ExpectIntEQ(X509_verify_cert(storeCtx), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71312. ExpectIntEQ(X509_STORE_CTX_get_error(storeCtx),
  71313. X509_V_ERR_UNABLE_TO_GET_CRL);
  71314. X509_CRL_free(crl);
  71315. X509_STORE_free(store);
  71316. X509_STORE_CTX_free(storeCtx);
  71317. X509_free(cert);
  71318. X509_free(ca);
  71319. #endif
  71320. return EXPECT_RESULT();
  71321. }
  71322. /*----------------------------------------------------------------------------*
  71323. | Certificate Failure Checks
  71324. *----------------------------------------------------------------------------*/
  71325. #if !defined(NO_CERTS) && (!defined(NO_WOLFSSL_CLIENT) || \
  71326. !defined(WOLFSSL_NO_CLIENT_AUTH)) && !defined(NO_FILESYSTEM)
  71327. #if !defined(NO_RSA) || defined(HAVE_ECC)
  71328. /* Use the Cert Manager(CM) API to generate the error ASN_SIG_CONFIRM_E */
  71329. static int verify_sig_cm(const char* ca, byte* cert_buf, size_t cert_sz,
  71330. int type)
  71331. {
  71332. int ret;
  71333. WOLFSSL_CERT_MANAGER* cm = NULL;
  71334. switch (type) {
  71335. case TESTING_RSA:
  71336. #ifdef NO_RSA
  71337. fprintf(stderr, "RSA disabled, skipping test\n");
  71338. return ASN_SIG_CONFIRM_E;
  71339. #else
  71340. break;
  71341. #endif
  71342. case TESTING_ECC:
  71343. #ifndef HAVE_ECC
  71344. fprintf(stderr, "ECC disabled, skipping test\n");
  71345. return ASN_SIG_CONFIRM_E;
  71346. #else
  71347. break;
  71348. #endif
  71349. default:
  71350. fprintf(stderr, "Bad function argument\n");
  71351. return BAD_FUNC_ARG;
  71352. }
  71353. cm = wolfSSL_CertManagerNew();
  71354. if (cm == NULL) {
  71355. fprintf(stderr, "wolfSSL_CertManagerNew failed\n");
  71356. return -1;
  71357. }
  71358. #ifndef NO_FILESYSTEM
  71359. ret = wolfSSL_CertManagerLoadCA(cm, ca, 0);
  71360. if (ret != WOLFSSL_SUCCESS) {
  71361. fprintf(stderr, "wolfSSL_CertManagerLoadCA failed\n");
  71362. wolfSSL_CertManagerFree(cm);
  71363. return ret;
  71364. }
  71365. #else
  71366. (void)ca;
  71367. #endif
  71368. ret = wolfSSL_CertManagerVerifyBuffer(cm, cert_buf, (long int)cert_sz,
  71369. WOLFSSL_FILETYPE_ASN1);
  71370. /* Let ExpectIntEQ handle return code */
  71371. wolfSSL_CertManagerFree(cm);
  71372. return ret;
  71373. }
  71374. #endif
  71375. #if !defined(NO_FILESYSTEM)
  71376. static int test_RsaSigFailure_cm(void)
  71377. {
  71378. EXPECT_DECLS;
  71379. #ifndef NO_RSA
  71380. const char* ca_cert = "./certs/ca-cert.pem";
  71381. const char* server_cert = "./certs/server-cert.der";
  71382. byte* cert_buf = NULL;
  71383. size_t cert_sz = 0;
  71384. ExpectIntEQ(load_file(server_cert, &cert_buf, &cert_sz), 0);
  71385. if ((cert_buf != NULL) && (cert_sz > 0)) {
  71386. /* corrupt DER - invert last byte, which is signature */
  71387. cert_buf[cert_sz-1] = ~cert_buf[cert_sz-1];
  71388. /* test bad cert */
  71389. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  71390. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_RSA),
  71391. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  71392. #elif defined(NO_ASN_CRYPT)
  71393. /* RSA verify is not called when ASN crypt support is disabled */
  71394. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_RSA),
  71395. WOLFSSL_SUCCESS);
  71396. #else
  71397. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_RSA),
  71398. WC_NO_ERR_TRACE(ASN_SIG_CONFIRM_E));
  71399. #endif
  71400. }
  71401. /* load_file() uses malloc. */
  71402. if (cert_buf != NULL) {
  71403. free(cert_buf);
  71404. }
  71405. #endif /* !NO_RSA */
  71406. return EXPECT_RESULT();
  71407. }
  71408. static int test_EccSigFailure_cm(void)
  71409. {
  71410. EXPECT_DECLS;
  71411. #ifdef HAVE_ECC
  71412. /* self-signed ECC cert, so use server cert as CA */
  71413. const char* ca_cert = "./certs/ca-ecc-cert.pem";
  71414. const char* server_cert = "./certs/server-ecc.der";
  71415. byte* cert_buf = NULL;
  71416. size_t cert_sz = 0;
  71417. ExpectIntEQ(load_file(server_cert, &cert_buf, &cert_sz), 0);
  71418. if (cert_buf != NULL && cert_sz > 0) {
  71419. /* corrupt DER - invert last byte, which is signature */
  71420. cert_buf[cert_sz-1] = ~cert_buf[cert_sz-1];
  71421. /* test bad cert */
  71422. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  71423. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_ECC),
  71424. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  71425. #elif defined(NO_ASN_CRYPT)
  71426. /* ECC verify is not called when ASN crypt support is disabled */
  71427. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_ECC),
  71428. WOLFSSL_SUCCESS);
  71429. #else
  71430. ExpectIntEQ(verify_sig_cm(ca_cert, cert_buf, cert_sz, TESTING_ECC),
  71431. WC_NO_ERR_TRACE(ASN_SIG_CONFIRM_E));
  71432. #endif
  71433. }
  71434. /* load_file() uses malloc. */
  71435. if (cert_buf != NULL) {
  71436. free(cert_buf);
  71437. }
  71438. #ifdef FP_ECC
  71439. wc_ecc_fp_free();
  71440. #endif
  71441. #endif /* HAVE_ECC */
  71442. return EXPECT_RESULT();
  71443. }
  71444. #endif /* !NO_FILESYSTEM */
  71445. #endif /* NO_CERTS */
  71446. #ifdef WOLFSSL_TLS13
  71447. #if defined(WOLFSSL_SEND_HRR_COOKIE) && !defined(NO_WOLFSSL_SERVER)
  71448. #ifdef WC_SHA384_DIGEST_SIZE
  71449. static byte fixedKey[WC_SHA384_DIGEST_SIZE] = { 0, };
  71450. #else
  71451. static byte fixedKey[WC_SHA256_DIGEST_SIZE] = { 0, };
  71452. #endif
  71453. #endif
  71454. #ifdef WOLFSSL_EARLY_DATA
  71455. static const char earlyData[] = "Early Data";
  71456. static char earlyDataBuffer[1];
  71457. #endif
  71458. static int test_tls13_apis(void)
  71459. {
  71460. EXPECT_DECLS;
  71461. int ret;
  71462. #ifndef WOLFSSL_NO_TLS12
  71463. #ifndef NO_WOLFSSL_CLIENT
  71464. WOLFSSL_CTX* clientTls12Ctx = NULL;
  71465. WOLFSSL* clientTls12Ssl = NULL;
  71466. #endif
  71467. #ifndef NO_WOLFSSL_SERVER
  71468. WOLFSSL_CTX* serverTls12Ctx = NULL;
  71469. WOLFSSL* serverTls12Ssl = NULL;
  71470. #endif
  71471. #endif
  71472. #ifndef NO_WOLFSSL_CLIENT
  71473. WOLFSSL_CTX* clientCtx = NULL;
  71474. WOLFSSL* clientSsl = NULL;
  71475. #endif
  71476. #ifndef NO_WOLFSSL_SERVER
  71477. WOLFSSL_CTX* serverCtx = NULL;
  71478. WOLFSSL* serverSsl = NULL;
  71479. #if !defined(NO_CERTS) && !defined(NO_FILESYSTEM)
  71480. const char* ourCert = svrCertFile;
  71481. const char* ourKey = svrKeyFile;
  71482. #endif
  71483. #endif
  71484. int required;
  71485. #ifdef WOLFSSL_EARLY_DATA
  71486. int outSz;
  71487. #endif
  71488. #if defined(HAVE_ECC) && defined(HAVE_SUPPORTED_CURVES)
  71489. int groups[2] = { WOLFSSL_ECC_SECP256R1,
  71490. #ifdef WOLFSSL_HAVE_KYBER
  71491. #ifndef WOLFSSL_NO_KYBER512
  71492. WOLFSSL_KYBER_LEVEL1
  71493. #elif !defined(WOLFSSL_NO_KYBER768)
  71494. WOLFSSL_KYBER_LEVEL3
  71495. #else
  71496. WOLFSSL_KYBER_LEVEL5
  71497. #endif
  71498. #else
  71499. WOLFSSL_ECC_SECP256R1
  71500. #endif
  71501. };
  71502. #if !defined(NO_WOLFSSL_SERVER) || !defined(NO_WOLFSSL_CLIENT)
  71503. int bad_groups[2] = { 0xDEAD, 0xBEEF };
  71504. #endif /* !NO_WOLFSSL_SERVER || !NO_WOLFSSL_CLIENT */
  71505. int numGroups = 2;
  71506. #endif
  71507. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC)
  71508. char groupList[] =
  71509. #ifdef HAVE_CURVE25519
  71510. "X25519:"
  71511. #endif
  71512. #ifdef HAVE_CURVE448
  71513. "X448:"
  71514. #endif
  71515. #ifndef NO_ECC_SECP
  71516. #if (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 521
  71517. "P-521:secp521r1:"
  71518. #endif
  71519. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 384
  71520. "P-384:secp384r1:"
  71521. #endif
  71522. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  71523. "P-256:secp256r1"
  71524. #if defined(WOLFSSL_HAVE_KYBER)
  71525. #ifndef WOLFSSL_NO_KYBER512
  71526. ":P256_KYBER_LEVEL1"
  71527. #elif !defined(WOLFSSL_NO_KYBER768)
  71528. ":P256_KYBER_LEVEL3"
  71529. #else
  71530. ":P256_KYBER_LEVEL5"
  71531. #endif
  71532. #endif
  71533. #endif
  71534. #endif /* !defined(NO_ECC_SECP) */
  71535. #if defined(WOLFSSL_HAVE_KYBER)
  71536. #ifndef WOLFSSL_NO_KYBER512
  71537. ":KYBER_LEVEL1"
  71538. #elif !defined(WOLFSSL_NO_KYBER768)
  71539. ":KYBER_LEVEL3"
  71540. #else
  71541. ":KYBER_LEVEL5"
  71542. #endif
  71543. #endif
  71544. "";
  71545. #endif /* defined(OPENSSL_EXTRA) && defined(HAVE_ECC) */
  71546. #if defined(WOLFSSL_HAVE_KYBER)
  71547. int kyberLevel;
  71548. #endif
  71549. (void)ret;
  71550. #ifndef WOLFSSL_NO_TLS12
  71551. #ifndef NO_WOLFSSL_CLIENT
  71552. clientTls12Ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method());
  71553. clientTls12Ssl = wolfSSL_new(clientTls12Ctx);
  71554. #endif
  71555. #ifndef NO_WOLFSSL_SERVER
  71556. serverTls12Ctx = wolfSSL_CTX_new(wolfTLSv1_2_server_method());
  71557. #if !defined(NO_CERTS) && !defined(NO_FILESYSTEM)
  71558. wolfSSL_CTX_use_certificate_chain_file(serverTls12Ctx, ourCert);
  71559. wolfSSL_CTX_use_PrivateKey_file(serverTls12Ctx, ourKey,
  71560. WOLFSSL_FILETYPE_PEM);
  71561. #endif
  71562. serverTls12Ssl = wolfSSL_new(serverTls12Ctx);
  71563. #endif
  71564. #endif
  71565. #ifndef NO_WOLFSSL_CLIENT
  71566. clientCtx = wolfSSL_CTX_new(wolfTLSv1_3_client_method());
  71567. clientSsl = wolfSSL_new(clientCtx);
  71568. #endif
  71569. #ifndef NO_WOLFSSL_SERVER
  71570. serverCtx = wolfSSL_CTX_new(wolfTLSv1_3_server_method());
  71571. #if !defined(NO_CERTS) && !defined(NO_FILESYSTEM)
  71572. wolfSSL_CTX_use_certificate_chain_file(serverCtx, ourCert);
  71573. wolfSSL_CTX_use_PrivateKey_file(serverCtx, ourKey, WOLFSSL_FILETYPE_PEM);
  71574. #endif
  71575. serverSsl = wolfSSL_new(serverCtx);
  71576. ExpectNotNull(serverSsl);
  71577. #endif
  71578. #ifdef WOLFSSL_SEND_HRR_COOKIE
  71579. ExpectIntEQ(wolfSSL_send_hrr_cookie(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71580. #ifndef NO_WOLFSSL_CLIENT
  71581. ExpectIntEQ(wolfSSL_send_hrr_cookie(clientSsl, NULL, 0), WC_NO_ERR_TRACE(SIDE_ERROR));
  71582. #endif
  71583. #ifndef NO_WOLFSSL_SERVER
  71584. #ifndef WOLFSSL_NO_TLS12
  71585. ExpectIntEQ(wolfSSL_send_hrr_cookie(serverTls12Ssl, NULL, 0),
  71586. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71587. #endif
  71588. ExpectIntEQ(wolfSSL_send_hrr_cookie(serverSsl, NULL, 0), WOLFSSL_SUCCESS);
  71589. ExpectIntEQ(wolfSSL_send_hrr_cookie(serverSsl, fixedKey, sizeof(fixedKey)),
  71590. WOLFSSL_SUCCESS);
  71591. #endif
  71592. #endif
  71593. #ifdef HAVE_SUPPORTED_CURVES
  71594. #ifdef HAVE_ECC
  71595. ExpectIntEQ(wolfSSL_UseKeyShare(NULL, WOLFSSL_ECC_SECP256R1),
  71596. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71597. #ifndef NO_WOLFSSL_SERVER
  71598. do {
  71599. ret = wolfSSL_UseKeyShare(serverSsl, WOLFSSL_ECC_SECP256R1);
  71600. #ifdef WOLFSSL_ASYNC_CRYPT
  71601. if (ret == WC_NO_ERR_TRACE(WC_PENDING_E))
  71602. wolfSSL_AsyncPoll(serverSsl, WOLF_POLL_FLAG_CHECK_HW);
  71603. #endif
  71604. }
  71605. while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  71606. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  71607. #endif
  71608. #ifndef NO_WOLFSSL_CLIENT
  71609. #ifndef WOLFSSL_NO_TLS12
  71610. do {
  71611. ret = wolfSSL_UseKeyShare(clientTls12Ssl, WOLFSSL_ECC_SECP256R1);
  71612. #ifdef WOLFSSL_ASYNC_CRYPT
  71613. if (ret == WC_NO_ERR_TRACE(WC_PENDING_E))
  71614. wolfSSL_AsyncPoll(clientTls12Ssl, WOLF_POLL_FLAG_CHECK_HW);
  71615. #endif
  71616. }
  71617. while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  71618. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  71619. #endif
  71620. do {
  71621. ret = wolfSSL_UseKeyShare(clientSsl, WOLFSSL_ECC_SECP256R1);
  71622. #ifdef WOLFSSL_ASYNC_CRYPT
  71623. if (ret == WC_NO_ERR_TRACE(WC_PENDING_E))
  71624. wolfSSL_AsyncPoll(clientSsl, WOLF_POLL_FLAG_CHECK_HW);
  71625. #endif
  71626. }
  71627. while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  71628. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  71629. #endif
  71630. #elif defined(HAVE_CURVE25519)
  71631. ExpectIntEQ(wolfSSL_UseKeyShare(NULL, WOLFSSL_ECC_X25519), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71632. #ifndef NO_WOLFSSL_SERVER
  71633. ExpectIntEQ(wolfSSL_UseKeyShare(serverSsl, WOLFSSL_ECC_X25519),
  71634. WOLFSSL_SUCCESS);
  71635. #endif
  71636. #ifndef NO_WOLFSSL_CLIENT
  71637. #ifndef WOLFSSL_NO_TLS12
  71638. ExpectIntEQ(wolfSSL_UseKeyShare(clientTls12Ssl, WOLFSSL_ECC_X25519),
  71639. WOLFSSL_SUCCESS);
  71640. #endif
  71641. ExpectIntEQ(wolfSSL_UseKeyShare(clientSsl, WOLFSSL_ECC_X25519),
  71642. WOLFSSL_SUCCESS);
  71643. #endif
  71644. #elif defined(HAVE_CURVE448)
  71645. ExpectIntEQ(wolfSSL_UseKeyShare(NULL, WOLFSSL_ECC_X448), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71646. #ifndef NO_WOLFSSL_SERVER
  71647. ExpectIntEQ(wolfSSL_UseKeyShare(serverSsl, WOLFSSL_ECC_X448),
  71648. WOLFSSL_SUCCESS);
  71649. #endif
  71650. #ifndef NO_WOLFSSL_CLIENT
  71651. #ifndef WOLFSSL_NO_TLS12
  71652. ExpectIntEQ(wolfSSL_UseKeyShare(clientTls12Ssl, WOLFSSL_ECC_X448),
  71653. WOLFSSL_SUCCESS);
  71654. #endif
  71655. ExpectIntEQ(wolfSSL_UseKeyShare(clientSsl, WOLFSSL_ECC_X448),
  71656. WOLFSSL_SUCCESS);
  71657. #endif
  71658. #else
  71659. ExpectIntEQ(wolfSSL_UseKeyShare(NULL, WOLFSSL_ECC_SECP256R1),
  71660. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71661. #ifndef NO_WOLFSSL_CLIENT
  71662. #ifndef WOLFSSL_NO_TLS12
  71663. ExpectIntEQ(wolfSSL_UseKeyShare(clientTls12Ssl, WOLFSSL_ECC_SECP256R1),
  71664. WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  71665. #endif
  71666. ExpectIntEQ(wolfSSL_UseKeyShare(clientSsl, WOLFSSL_ECC_SECP256R1),
  71667. WC_NO_ERR_TRACE(NOT_COMPILED_IN));
  71668. #endif
  71669. #endif
  71670. #if defined(WOLFSSL_HAVE_KYBER)
  71671. #ifndef WOLFSSL_NO_KYBER768
  71672. kyberLevel = WOLFSSL_KYBER_LEVEL3;
  71673. #elif !defined(WOLFSSL_NO_KYBER1024)
  71674. kyberLevel = WOLFSSL_KYBER_LEVEL5;
  71675. #else
  71676. kyberLevel = WOLFSSL_KYBER_LEVEL1;
  71677. #endif
  71678. ExpectIntEQ(wolfSSL_UseKeyShare(NULL, kyberLevel), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71679. #ifndef NO_WOLFSSL_SERVER
  71680. ExpectIntEQ(wolfSSL_UseKeyShare(serverSsl, kyberLevel),
  71681. WOLFSSL_SUCCESS);
  71682. #endif
  71683. #ifndef NO_WOLFSSL_CLIENT
  71684. #ifndef WOLFSSL_NO_TLS12
  71685. ExpectIntEQ(wolfSSL_UseKeyShare(clientTls12Ssl, kyberLevel),
  71686. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71687. #endif
  71688. ExpectIntEQ(wolfSSL_UseKeyShare(clientSsl, kyberLevel),
  71689. WOLFSSL_SUCCESS);
  71690. #endif
  71691. #endif
  71692. ExpectIntEQ(wolfSSL_NoKeyShares(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71693. #ifndef NO_WOLFSSL_SERVER
  71694. ExpectIntEQ(wolfSSL_NoKeyShares(serverSsl), WC_NO_ERR_TRACE(SIDE_ERROR));
  71695. #endif
  71696. #ifndef NO_WOLFSSL_CLIENT
  71697. #ifndef WOLFSSL_NO_TLS12
  71698. ExpectIntEQ(wolfSSL_NoKeyShares(clientTls12Ssl), WOLFSSL_SUCCESS);
  71699. #endif
  71700. ExpectIntEQ(wolfSSL_NoKeyShares(clientSsl), WOLFSSL_SUCCESS);
  71701. #endif
  71702. #endif /* HAVE_SUPPORTED_CURVES */
  71703. ExpectIntEQ(wolfSSL_CTX_no_ticket_TLSv13(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71704. #ifndef NO_WOLFSSL_CLIENT
  71705. ExpectIntEQ(wolfSSL_CTX_no_ticket_TLSv13(clientCtx), WC_NO_ERR_TRACE(SIDE_ERROR));
  71706. #endif
  71707. #ifndef NO_WOLFSSL_SERVER
  71708. #ifndef WOLFSSL_NO_TLS12
  71709. ExpectIntEQ(wolfSSL_CTX_no_ticket_TLSv13(serverTls12Ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71710. #endif
  71711. ExpectIntEQ(wolfSSL_CTX_no_ticket_TLSv13(serverCtx), 0);
  71712. #endif
  71713. ExpectIntEQ(wolfSSL_no_ticket_TLSv13(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71714. #ifndef NO_WOLFSSL_CLIENT
  71715. ExpectIntEQ(wolfSSL_no_ticket_TLSv13(clientSsl), WC_NO_ERR_TRACE(SIDE_ERROR));
  71716. #endif
  71717. #ifndef NO_WOLFSSL_SERVER
  71718. #ifndef WOLFSSL_NO_TLS12
  71719. ExpectIntEQ(wolfSSL_no_ticket_TLSv13(serverTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71720. #endif
  71721. ExpectIntEQ(wolfSSL_no_ticket_TLSv13(serverSsl), 0);
  71722. #endif
  71723. ExpectIntEQ(wolfSSL_CTX_no_dhe_psk(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71724. #ifndef NO_WOLFSSL_CLIENT
  71725. #ifndef WOLFSSL_NO_TLS12
  71726. ExpectIntEQ(wolfSSL_CTX_no_dhe_psk(clientTls12Ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71727. #endif
  71728. ExpectIntEQ(wolfSSL_CTX_no_dhe_psk(clientCtx), 0);
  71729. #endif
  71730. #ifndef NO_WOLFSSL_SERVER
  71731. ExpectIntEQ(wolfSSL_CTX_no_dhe_psk(serverCtx), 0);
  71732. #endif
  71733. ExpectIntEQ(wolfSSL_no_dhe_psk(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71734. #ifndef NO_WOLFSSL_CLIENT
  71735. #ifndef WOLFSSL_NO_TLS12
  71736. ExpectIntEQ(wolfSSL_no_dhe_psk(clientTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71737. #endif
  71738. ExpectIntEQ(wolfSSL_no_dhe_psk(clientSsl), 0);
  71739. #endif
  71740. #ifndef NO_WOLFSSL_SERVER
  71741. ExpectIntEQ(wolfSSL_no_dhe_psk(serverSsl), 0);
  71742. #endif
  71743. ExpectIntEQ(wolfSSL_update_keys(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71744. #ifndef NO_WOLFSSL_CLIENT
  71745. #ifndef WOLFSSL_NO_TLS12
  71746. ExpectIntEQ(wolfSSL_update_keys(clientTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71747. #endif
  71748. ExpectIntEQ(wolfSSL_update_keys(clientSsl), WC_NO_ERR_TRACE(BUILD_MSG_ERROR));
  71749. #endif
  71750. #ifndef NO_WOLFSSL_SERVER
  71751. ExpectIntEQ(wolfSSL_update_keys(serverSsl), WC_NO_ERR_TRACE(BUILD_MSG_ERROR));
  71752. #endif
  71753. ExpectIntEQ(wolfSSL_key_update_response(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71754. ExpectIntEQ(wolfSSL_key_update_response(NULL, &required), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71755. #ifndef NO_WOLFSSL_CLIENT
  71756. #ifndef WOLFSSL_NO_TLS12
  71757. ExpectIntEQ(wolfSSL_key_update_response(clientTls12Ssl, &required),
  71758. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71759. #endif
  71760. ExpectIntEQ(wolfSSL_key_update_response(clientSsl, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71761. #endif
  71762. #ifndef NO_WOLFSSL_SERVER
  71763. ExpectIntEQ(wolfSSL_key_update_response(serverSsl, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71764. #endif
  71765. #if !defined(NO_CERTS) && defined(WOLFSSL_POST_HANDSHAKE_AUTH)
  71766. ExpectIntEQ(wolfSSL_CTX_allow_post_handshake_auth(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71767. #ifndef NO_WOLFSSL_SERVER
  71768. ExpectIntEQ(wolfSSL_CTX_allow_post_handshake_auth(serverCtx), WC_NO_ERR_TRACE(SIDE_ERROR));
  71769. #endif
  71770. #ifndef NO_WOLFSSL_CLIENT
  71771. #ifndef WOLFSSL_NO_TLS12
  71772. ExpectIntEQ(wolfSSL_CTX_allow_post_handshake_auth(clientTls12Ctx),
  71773. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71774. #endif
  71775. ExpectIntEQ(wolfSSL_CTX_allow_post_handshake_auth(clientCtx), 0);
  71776. #endif
  71777. ExpectIntEQ(wolfSSL_allow_post_handshake_auth(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71778. #ifndef NO_WOLFSSL_SERVER
  71779. ExpectIntEQ(wolfSSL_allow_post_handshake_auth(serverSsl), WC_NO_ERR_TRACE(SIDE_ERROR));
  71780. #endif
  71781. #ifndef NO_WOLFSSL_CLIENT
  71782. #ifndef WOLFSSL_NO_TLS12
  71783. ExpectIntEQ(wolfSSL_allow_post_handshake_auth(clientTls12Ssl),
  71784. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71785. #endif
  71786. ExpectIntEQ(wolfSSL_allow_post_handshake_auth(clientSsl), 0);
  71787. #endif
  71788. ExpectIntEQ(wolfSSL_request_certificate(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71789. #ifndef NO_WOLFSSL_CLIENT
  71790. ExpectIntEQ(wolfSSL_request_certificate(clientSsl), WC_NO_ERR_TRACE(SIDE_ERROR));
  71791. #endif
  71792. #ifndef NO_WOLFSSL_SERVER
  71793. #ifndef WOLFSSL_NO_TLS12
  71794. ExpectIntEQ(wolfSSL_request_certificate(serverTls12Ssl),
  71795. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71796. #endif
  71797. ExpectIntEQ(wolfSSL_request_certificate(serverSsl), WC_NO_ERR_TRACE(NOT_READY_ERROR));
  71798. #endif
  71799. #endif
  71800. #ifdef HAVE_ECC
  71801. #ifndef WOLFSSL_NO_SERVER_GROUPS_EXT
  71802. ExpectIntEQ(wolfSSL_preferred_group(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71803. #ifndef NO_WOLFSSL_SERVER
  71804. ExpectIntEQ(wolfSSL_preferred_group(serverSsl), WC_NO_ERR_TRACE(SIDE_ERROR));
  71805. #endif
  71806. #ifndef NO_WOLFSSL_CLIENT
  71807. #ifndef WOLFSSL_NO_TLS12
  71808. ExpectIntEQ(wolfSSL_preferred_group(clientTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71809. #endif
  71810. ExpectIntEQ(wolfSSL_preferred_group(clientSsl), WC_NO_ERR_TRACE(NOT_READY_ERROR));
  71811. #endif
  71812. #endif
  71813. #ifdef HAVE_SUPPORTED_CURVES
  71814. ExpectIntEQ(wolfSSL_CTX_set_groups(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71815. #ifndef NO_WOLFSSL_CLIENT
  71816. ExpectIntEQ(wolfSSL_CTX_set_groups(clientCtx, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71817. #endif
  71818. ExpectIntEQ(wolfSSL_CTX_set_groups(NULL, groups, numGroups), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71819. #ifndef NO_WOLFSSL_CLIENT
  71820. #ifndef WOLFSSL_NO_TLS12
  71821. ExpectIntEQ(wolfSSL_CTX_set_groups(clientTls12Ctx, groups, numGroups),
  71822. WOLFSSL_SUCCESS);
  71823. #endif
  71824. ExpectIntEQ(wolfSSL_CTX_set_groups(clientCtx, groups,
  71825. WOLFSSL_MAX_GROUP_COUNT + 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71826. ExpectIntEQ(wolfSSL_CTX_set_groups(clientCtx, groups, numGroups),
  71827. WOLFSSL_SUCCESS);
  71828. ExpectIntEQ(wolfSSL_CTX_set_groups(clientCtx, bad_groups, numGroups),
  71829. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71830. #endif
  71831. #ifndef NO_WOLFSSL_SERVER
  71832. ExpectIntEQ(wolfSSL_CTX_set_groups(serverCtx, groups, numGroups),
  71833. WOLFSSL_SUCCESS);
  71834. ExpectIntEQ(wolfSSL_CTX_set_groups(serverCtx, bad_groups, numGroups),
  71835. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71836. #endif
  71837. ExpectIntEQ(wolfSSL_set_groups(NULL, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71838. #ifndef NO_WOLFSSL_CLIENT
  71839. ExpectIntEQ(wolfSSL_set_groups(clientSsl, NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71840. #endif
  71841. ExpectIntEQ(wolfSSL_set_groups(NULL, groups, numGroups), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71842. #ifndef NO_WOLFSSL_CLIENT
  71843. #ifndef WOLFSSL_NO_TLS12
  71844. ExpectIntEQ(wolfSSL_set_groups(clientTls12Ssl, groups, numGroups),
  71845. WOLFSSL_SUCCESS);
  71846. #endif
  71847. ExpectIntEQ(wolfSSL_set_groups(clientSsl, groups,
  71848. WOLFSSL_MAX_GROUP_COUNT + 1), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71849. ExpectIntEQ(wolfSSL_set_groups(clientSsl, groups, numGroups),
  71850. WOLFSSL_SUCCESS);
  71851. ExpectIntEQ(wolfSSL_set_groups(clientSsl, bad_groups, numGroups),
  71852. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71853. #endif
  71854. #ifndef NO_WOLFSSL_SERVER
  71855. ExpectIntEQ(wolfSSL_set_groups(serverSsl, groups, numGroups),
  71856. WOLFSSL_SUCCESS);
  71857. ExpectIntEQ(wolfSSL_set_groups(serverSsl, bad_groups, numGroups),
  71858. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71859. #endif
  71860. #ifdef OPENSSL_EXTRA
  71861. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71862. #ifndef NO_WOLFSSL_CLIENT
  71863. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(clientCtx, NULL),
  71864. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71865. #endif
  71866. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(NULL, groupList),
  71867. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71868. #ifndef NO_WOLFSSL_CLIENT
  71869. #ifndef WOLFSSL_NO_TLS12
  71870. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(clientTls12Ctx, groupList),
  71871. WOLFSSL_SUCCESS);
  71872. #endif
  71873. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(clientCtx, groupList),
  71874. WOLFSSL_SUCCESS);
  71875. #endif
  71876. #ifndef NO_WOLFSSL_SERVER
  71877. ExpectIntEQ(wolfSSL_CTX_set1_groups_list(serverCtx, groupList),
  71878. WOLFSSL_SUCCESS);
  71879. #endif
  71880. ExpectIntEQ(wolfSSL_set1_groups_list(NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71881. #ifndef NO_WOLFSSL_CLIENT
  71882. ExpectIntEQ(wolfSSL_set1_groups_list(clientSsl, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71883. #endif
  71884. ExpectIntEQ(wolfSSL_set1_groups_list(NULL, groupList), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  71885. #ifndef NO_WOLFSSL_CLIENT
  71886. #ifndef WOLFSSL_NO_TLS12
  71887. ExpectIntEQ(wolfSSL_set1_groups_list(clientTls12Ssl, groupList),
  71888. WOLFSSL_SUCCESS);
  71889. #endif
  71890. ExpectIntEQ(wolfSSL_set1_groups_list(clientSsl, groupList),
  71891. WOLFSSL_SUCCESS);
  71892. #endif
  71893. #ifndef NO_WOLFSSL_SERVER
  71894. ExpectIntEQ(wolfSSL_set1_groups_list(serverSsl, groupList),
  71895. WOLFSSL_SUCCESS);
  71896. #endif
  71897. #endif /* OPENSSL_EXTRA */
  71898. #endif /* HAVE_SUPPORTED_CURVES */
  71899. #endif /* HAVE_ECC */
  71900. #ifdef WOLFSSL_EARLY_DATA
  71901. #ifndef OPENSSL_EXTRA
  71902. ExpectIntEQ(wolfSSL_CTX_set_max_early_data(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71903. ExpectIntEQ(wolfSSL_CTX_get_max_early_data(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71904. #else
  71905. ExpectIntEQ(SSL_CTX_set_max_early_data(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71906. ExpectIntEQ(SSL_CTX_get_max_early_data(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71907. #endif
  71908. #ifndef NO_WOLFSSL_CLIENT
  71909. #ifndef OPENSSL_EXTRA
  71910. ExpectIntEQ(wolfSSL_CTX_set_max_early_data(clientCtx, 0), WC_NO_ERR_TRACE(SIDE_ERROR));
  71911. ExpectIntEQ(wolfSSL_CTX_get_max_early_data(clientCtx), WC_NO_ERR_TRACE(SIDE_ERROR));
  71912. #else
  71913. ExpectIntEQ(SSL_CTX_set_max_early_data(clientCtx, 0), WC_NO_ERR_TRACE(SIDE_ERROR));
  71914. ExpectIntEQ(SSL_CTX_get_max_early_data(clientCtx), WC_NO_ERR_TRACE(SIDE_ERROR));
  71915. #endif
  71916. #endif
  71917. #ifndef NO_WOLFSSL_SERVER
  71918. #ifndef WOLFSSL_NO_TLS12
  71919. #ifndef OPENSSL_EXTRA
  71920. ExpectIntEQ(wolfSSL_CTX_set_max_early_data(serverTls12Ctx, 0),
  71921. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71922. ExpectIntEQ(wolfSSL_CTX_get_max_early_data(serverTls12Ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71923. #else
  71924. ExpectIntEQ(SSL_CTX_set_max_early_data(serverTls12Ctx, 0),
  71925. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71926. ExpectIntEQ(SSL_CTX_get_max_early_data(serverTls12Ctx), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71927. #endif
  71928. #endif
  71929. #ifndef OPENSSL_EXTRA
  71930. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  71931. ExpectIntEQ(wolfSSL_CTX_set_max_early_data(serverCtx, 32),
  71932. WOLFSSL_SUCCESS);
  71933. #else
  71934. ExpectIntEQ(wolfSSL_CTX_set_max_early_data(serverCtx, 32), 0);
  71935. #endif
  71936. ExpectIntEQ(wolfSSL_CTX_get_max_early_data(serverCtx), 32);
  71937. #else
  71938. ExpectIntEQ(SSL_CTX_set_max_early_data(serverCtx, 32), 1);
  71939. ExpectIntEQ(SSL_CTX_get_max_early_data(serverCtx), 32);
  71940. #endif
  71941. #endif
  71942. #ifndef OPENSSL_EXTRA
  71943. ExpectIntEQ(wolfSSL_set_max_early_data(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71944. ExpectIntEQ(wolfSSL_get_max_early_data(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71945. #else
  71946. ExpectIntEQ(SSL_set_max_early_data(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71947. ExpectIntEQ(SSL_get_max_early_data(NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71948. #endif
  71949. #ifndef NO_WOLFSSL_CLIENT
  71950. #ifndef OPENSSL_EXTRA
  71951. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  71952. ExpectIntEQ(wolfSSL_set_max_early_data(clientSsl, 17), WOLFSSL_SUCCESS);
  71953. #else
  71954. ExpectIntEQ(wolfSSL_set_max_early_data(clientSsl, 17), 0);
  71955. #endif
  71956. ExpectIntEQ(wolfSSL_get_max_early_data(clientSsl), 17);
  71957. #else
  71958. ExpectIntEQ(SSL_set_max_early_data(clientSsl, 17), WOLFSSL_SUCCESS);
  71959. ExpectIntEQ(SSL_get_max_early_data(clientSsl), 17);
  71960. #endif
  71961. #endif
  71962. #ifndef NO_WOLFSSL_SERVER
  71963. #ifndef WOLFSSL_NO_TLS12
  71964. #ifndef OPENSSL_EXTRA
  71965. ExpectIntEQ(wolfSSL_set_max_early_data(serverTls12Ssl, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71966. ExpectIntEQ(wolfSSL_get_max_early_data(serverTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71967. #else
  71968. ExpectIntEQ(SSL_set_max_early_data(serverTls12Ssl, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71969. ExpectIntEQ(SSL_get_max_early_data(serverTls12Ssl), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71970. #endif
  71971. #endif
  71972. #ifndef OPENSSL_EXTRA
  71973. #ifdef WOLFSSL_ERROR_CODE_OPENSSL
  71974. ExpectIntEQ(wolfSSL_set_max_early_data(serverSsl, 16), WOLFSSL_SUCCESS);
  71975. #else
  71976. ExpectIntEQ(wolfSSL_set_max_early_data(serverSsl, 16), 0);
  71977. #endif
  71978. ExpectIntEQ(wolfSSL_get_max_early_data(serverSsl), 16);
  71979. #else
  71980. ExpectIntEQ(SSL_set_max_early_data(serverSsl, 16), 1);
  71981. ExpectIntEQ(SSL_get_max_early_data(serverSsl), 16);
  71982. #endif
  71983. #endif
  71984. ExpectIntEQ(wolfSSL_write_early_data(NULL, earlyData, sizeof(earlyData),
  71985. &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71986. #ifndef NO_WOLFSSL_CLIENT
  71987. ExpectIntEQ(wolfSSL_write_early_data(clientSsl, NULL, sizeof(earlyData),
  71988. &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71989. ExpectIntEQ(wolfSSL_write_early_data(clientSsl, earlyData, -1, &outSz),
  71990. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71991. ExpectIntEQ(wolfSSL_write_early_data(clientSsl, earlyData,
  71992. sizeof(earlyData), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  71993. #endif
  71994. #ifndef NO_WOLFSSL_SERVER
  71995. ExpectIntEQ(wolfSSL_write_early_data(serverSsl, earlyData,
  71996. sizeof(earlyData), &outSz), WC_NO_ERR_TRACE(SIDE_ERROR));
  71997. #endif
  71998. #ifndef NO_WOLFSSL_CLIENT
  71999. #ifndef WOLFSSL_NO_TLS12
  72000. ExpectIntEQ(wolfSSL_write_early_data(clientTls12Ssl, earlyData,
  72001. sizeof(earlyData), &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  72002. #endif
  72003. ExpectIntEQ(wolfSSL_write_early_data(clientSsl, earlyData,
  72004. sizeof(earlyData), &outSz), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  72005. #endif
  72006. ExpectIntEQ(wolfSSL_read_early_data(NULL, earlyDataBuffer,
  72007. sizeof(earlyDataBuffer), &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  72008. #ifndef NO_WOLFSSL_SERVER
  72009. ExpectIntEQ(wolfSSL_read_early_data(serverSsl, NULL,
  72010. sizeof(earlyDataBuffer), &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  72011. ExpectIntEQ(wolfSSL_read_early_data(serverSsl, earlyDataBuffer, -1,
  72012. &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  72013. ExpectIntEQ(wolfSSL_read_early_data(serverSsl, earlyDataBuffer,
  72014. sizeof(earlyDataBuffer), NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  72015. #endif
  72016. #ifndef NO_WOLFSSL_CLIENT
  72017. ExpectIntEQ(wolfSSL_read_early_data(clientSsl, earlyDataBuffer,
  72018. sizeof(earlyDataBuffer), &outSz), WC_NO_ERR_TRACE(SIDE_ERROR));
  72019. #endif
  72020. #ifndef NO_WOLFSSL_SERVER
  72021. #ifndef WOLFSSL_NO_TLS12
  72022. ExpectIntEQ(wolfSSL_read_early_data(serverTls12Ssl, earlyDataBuffer,
  72023. sizeof(earlyDataBuffer), &outSz), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  72024. #endif
  72025. ExpectIntEQ(wolfSSL_read_early_data(serverSsl, earlyDataBuffer,
  72026. sizeof(earlyDataBuffer), &outSz), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  72027. #endif
  72028. #endif
  72029. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_EARLY_DATA)
  72030. ExpectIntLT(SSL_get_early_data_status(NULL), 0);
  72031. #endif
  72032. #ifndef NO_WOLFSSL_SERVER
  72033. wolfSSL_free(serverSsl);
  72034. wolfSSL_CTX_free(serverCtx);
  72035. #endif
  72036. #ifndef NO_WOLFSSL_CLIENT
  72037. wolfSSL_free(clientSsl);
  72038. wolfSSL_CTX_free(clientCtx);
  72039. #endif
  72040. #ifndef WOLFSSL_NO_TLS12
  72041. #ifndef NO_WOLFSSL_SERVER
  72042. wolfSSL_free(serverTls12Ssl);
  72043. wolfSSL_CTX_free(serverTls12Ctx);
  72044. #endif
  72045. #ifndef NO_WOLFSSL_CLIENT
  72046. wolfSSL_free(clientTls12Ssl);
  72047. wolfSSL_CTX_free(clientTls12Ctx);
  72048. #endif
  72049. #endif
  72050. return EXPECT_RESULT();
  72051. }
  72052. #if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_SERVER) && \
  72053. defined(HAVE_ECC) && defined(BUILD_TLS_AES_128_GCM_SHA256) && \
  72054. defined(BUILD_TLS_AES_256_GCM_SHA384)
  72055. /* Called when writing. */
  72056. static int CsSend(WOLFSSL* ssl, char* buf, int sz, void* ctx)
  72057. {
  72058. (void)ssl;
  72059. (void)buf;
  72060. (void)sz;
  72061. (void)ctx;
  72062. /* Force error return from wolfSSL_accept_TLSv13(). */
  72063. return WANT_WRITE;
  72064. }
  72065. /* Called when reading. */
  72066. static int CsRecv(WOLFSSL* ssl, char* buf, int sz, void* ctx)
  72067. {
  72068. WOLFSSL_BUFFER_INFO* msg = (WOLFSSL_BUFFER_INFO*)ctx;
  72069. int len = (int)msg->length;
  72070. (void)ssl;
  72071. (void)sz;
  72072. /* Pass back as much of message as will fit in buffer. */
  72073. if (len > sz)
  72074. len = sz;
  72075. XMEMCPY(buf, msg->buffer, len);
  72076. /* Move over returned data. */
  72077. msg->buffer += len;
  72078. msg->length -= len;
  72079. /* Amount actually copied. */
  72080. return len;
  72081. }
  72082. #endif
  72083. static int test_tls13_cipher_suites(void)
  72084. {
  72085. EXPECT_DECLS;
  72086. #if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_SERVER) && \
  72087. defined(HAVE_ECC) && defined(BUILD_TLS_AES_128_GCM_SHA256) && \
  72088. defined(BUILD_TLS_AES_256_GCM_SHA384)
  72089. WOLFSSL_CTX* ctx = NULL;
  72090. WOLFSSL *ssl = NULL;
  72091. int i;
  72092. byte clientHello[] = {
  72093. 0x16, 0x03, 0x03, 0x01, 0x9b, 0x01, 0x00, 0x01,
  72094. 0x97, 0x03, 0x03, 0xf4, 0x65, 0xbd, 0x22, 0xfe,
  72095. 0x6e, 0xab, 0x66, 0xdd, 0xcf, 0xe9, 0x65, 0x55,
  72096. 0xe8, 0xdf, 0xc3, 0x8e, 0x4b, 0x00, 0xbc, 0xf8,
  72097. 0x23, 0x57, 0x1b, 0xa0, 0xc8, 0xa9, 0xe2, 0x8c,
  72098. 0x91, 0x6e, 0xf9, 0x20, 0xf7, 0x5c, 0xc5, 0x5b,
  72099. 0x75, 0x8c, 0x47, 0x0a, 0x0e, 0xc4, 0x1a, 0xda,
  72100. 0xef, 0x75, 0xe5, 0x21, 0x00, 0x00, 0x00, 0x00,
  72101. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  72102. 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
  72103. /* Cipher suites: 0x13, 0x01 = TLS13-AES128-GCM-SHA256, twice. */
  72104. 0x13, 0x01,
  72105. 0x13, 0x01, 0x01, 0x00, 0x01, 0x4a, 0x00, 0x2d,
  72106. 0x00, 0x03, 0x02, 0x00, 0x01, 0x00, 0x33, 0x00,
  72107. 0x47, 0x00, 0x45, 0x00, 0x17, 0x00, 0x41, 0x04,
  72108. 0x90, 0xfc, 0xe2, 0x97, 0x05, 0x7c, 0xb5, 0x23,
  72109. 0x5d, 0x5f, 0x5b, 0xcd, 0x0c, 0x1e, 0xe0, 0xe9,
  72110. 0xab, 0x38, 0x6b, 0x1e, 0x20, 0x5c, 0x1c, 0x90,
  72111. 0x2a, 0x9e, 0x68, 0x8e, 0x70, 0x05, 0x10, 0xa8,
  72112. 0x02, 0x1b, 0xf9, 0x5c, 0xef, 0xc9, 0xaf, 0xca,
  72113. 0x1a, 0x3b, 0x16, 0x8b, 0xe4, 0x1b, 0x3c, 0x15,
  72114. 0xb8, 0x0d, 0xbd, 0xaf, 0x62, 0x8d, 0xa7, 0x13,
  72115. 0xa0, 0x7c, 0xe0, 0x59, 0x0c, 0x4f, 0x8a, 0x6d,
  72116. 0x00, 0x2b, 0x00, 0x03, 0x02, 0x03, 0x04, 0x00,
  72117. 0x0d, 0x00, 0x20, 0x00, 0x1e, 0x06, 0x03, 0x05,
  72118. 0x03, 0x04, 0x03, 0x02, 0x03, 0x08, 0x06, 0x08,
  72119. 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08,
  72120. 0x09, 0x06, 0x01, 0x05, 0x01, 0x04, 0x01, 0x03,
  72121. 0x01, 0x02, 0x01, 0x00, 0x0a, 0x00, 0x04, 0x00,
  72122. 0x02, 0x00, 0x17, 0x00, 0x16, 0x00, 0x00, 0x00,
  72123. 0x23, 0x00, 0x00, 0x00, 0x29, 0x00, 0xb9, 0x00,
  72124. 0x94, 0x00, 0x8e, 0x0f, 0x12, 0xfa, 0x84, 0x1f,
  72125. 0x76, 0x94, 0xd7, 0x09, 0x5e, 0xad, 0x08, 0x51,
  72126. 0xb6, 0x80, 0x28, 0x31, 0x8b, 0xfd, 0xc6, 0xbd,
  72127. 0x9e, 0xf5, 0x3b, 0x4d, 0x02, 0xbe, 0x1d, 0x73,
  72128. 0xea, 0x13, 0x68, 0x00, 0x4c, 0xfd, 0x3d, 0x48,
  72129. 0x51, 0xf9, 0x06, 0xbb, 0x92, 0xed, 0x42, 0x9f,
  72130. 0x7f, 0x2c, 0x73, 0x9f, 0xd9, 0xb4, 0xef, 0x05,
  72131. 0x26, 0x5b, 0x60, 0x5c, 0x0a, 0xfc, 0xa3, 0xbd,
  72132. 0x2d, 0x2d, 0x8b, 0xf9, 0xaa, 0x5c, 0x96, 0x3a,
  72133. 0xf2, 0xec, 0xfa, 0xe5, 0x57, 0x2e, 0x87, 0xbe,
  72134. 0x27, 0xc5, 0x3d, 0x4f, 0x5d, 0xdd, 0xde, 0x1c,
  72135. 0x1b, 0xb3, 0xcc, 0x27, 0x27, 0x57, 0x5a, 0xd9,
  72136. 0xea, 0x99, 0x27, 0x23, 0xa6, 0x0e, 0xea, 0x9c,
  72137. 0x0d, 0x85, 0xcb, 0x72, 0xeb, 0xd7, 0x93, 0xe3,
  72138. 0xfe, 0xf7, 0x5c, 0xc5, 0x5b, 0x75, 0x8c, 0x47,
  72139. 0x0a, 0x0e, 0xc4, 0x1a, 0xda, 0xef, 0x75, 0xe5,
  72140. 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  72141. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  72142. 0x00, 0xfb, 0x92, 0xce, 0xaa, 0x00, 0x21, 0x20,
  72143. 0xcb, 0x73, 0x25, 0x80, 0x46, 0x78, 0x4f, 0xe5,
  72144. 0x34, 0xf6, 0x91, 0x13, 0x7f, 0xc8, 0x8d, 0xdc,
  72145. 0x81, 0x04, 0xb7, 0x0d, 0x49, 0x85, 0x2e, 0x12,
  72146. 0x7a, 0x07, 0x23, 0xe9, 0x13, 0xa4, 0x6d, 0x8c
  72147. };
  72148. WOLFSSL_BUFFER_INFO msg;
  72149. /* Offset into ClientHello message data of first cipher suite. */
  72150. const int csOff = 78;
  72151. /* Server cipher list. */
  72152. const char* serverCs = "TLS13-AES256-GCM-SHA384:TLS13-AES128-GCM-SHA256";
  72153. /* Suite list with duplicates. */
  72154. const char* dupCs = "TLS13-AES128-GCM-SHA256:"
  72155. "TLS13-AES128-GCM-SHA256:"
  72156. "TLS13-AES256-GCM-SHA384:"
  72157. "TLS13-AES256-GCM-SHA384:"
  72158. "TLS13-AES128-GCM-SHA256";
  72159. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_SET_CIPHER_BYTES)
  72160. const byte dupCsBytes[] = { TLS13_BYTE, TLS_AES_256_GCM_SHA384,
  72161. TLS13_BYTE, TLS_AES_256_GCM_SHA384,
  72162. TLS13_BYTE, TLS_AES_128_GCM_SHA256,
  72163. TLS13_BYTE, TLS_AES_128_GCM_SHA256,
  72164. TLS13_BYTE, TLS_AES_256_GCM_SHA384 };
  72165. #endif
  72166. /* Set up wolfSSL context. */
  72167. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  72168. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, eccCertFile,
  72169. WOLFSSL_FILETYPE_PEM));
  72170. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, eccKeyFile,
  72171. WOLFSSL_FILETYPE_PEM));
  72172. /* Read from 'msg'. */
  72173. wolfSSL_SetIORecv(ctx, CsRecv);
  72174. /* No where to send to - dummy sender. */
  72175. wolfSSL_SetIOSend(ctx, CsSend);
  72176. /* Test cipher suite list with many copies of a cipher suite. */
  72177. ExpectNotNull(ssl = wolfSSL_new(ctx));
  72178. msg.buffer = clientHello;
  72179. msg.length = (unsigned int)sizeof(clientHello);
  72180. wolfSSL_SetIOReadCtx(ssl, &msg);
  72181. /* Force server to have as many occurrences of same cipher suite as
  72182. * possible. */
  72183. if (ssl != NULL) {
  72184. Suites* suites = (Suites*)WOLFSSL_SUITES(ssl);
  72185. suites->suiteSz = WOLFSSL_MAX_SUITE_SZ;
  72186. for (i = 0; i < suites->suiteSz; i += 2) {
  72187. suites->suites[i + 0] = TLS13_BYTE;
  72188. suites->suites[i + 1] = TLS_AES_128_GCM_SHA256;
  72189. }
  72190. }
  72191. /* Test multiple occurrences of same cipher suite. */
  72192. ExpectIntEQ(wolfSSL_accept_TLSv13(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  72193. wolfSSL_free(ssl);
  72194. ssl = NULL;
  72195. /* Set client order opposite to server order:
  72196. * TLS13-AES128-GCM-SHA256:TLS13-AES256-GCM-SHA384 */
  72197. clientHello[csOff + 0] = TLS13_BYTE;
  72198. clientHello[csOff + 1] = TLS_AES_128_GCM_SHA256;
  72199. clientHello[csOff + 2] = TLS13_BYTE;
  72200. clientHello[csOff + 3] = TLS_AES_256_GCM_SHA384;
  72201. /* Test server order negotiation. */
  72202. ExpectNotNull(ssl = wolfSSL_new(ctx));
  72203. msg.buffer = clientHello;
  72204. msg.length = (unsigned int)sizeof(clientHello);
  72205. wolfSSL_SetIOReadCtx(ssl, &msg);
  72206. /* Server order: TLS13-AES256-GCM-SHA384:TLS13-AES128-GCM-SHA256 */
  72207. ExpectIntEQ(wolfSSL_set_cipher_list(ssl, serverCs), WOLFSSL_SUCCESS);
  72208. /* Negotiate cipher suites in server order: TLS13-AES256-GCM-SHA384 */
  72209. ExpectIntEQ(wolfSSL_accept_TLSv13(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  72210. /* Check refined order - server order. */
  72211. ExpectIntEQ(ssl->suites->suiteSz, 4);
  72212. ExpectIntEQ(ssl->suites->suites[0], TLS13_BYTE);
  72213. ExpectIntEQ(ssl->suites->suites[1], TLS_AES_256_GCM_SHA384);
  72214. ExpectIntEQ(ssl->suites->suites[2], TLS13_BYTE);
  72215. ExpectIntEQ(ssl->suites->suites[3], TLS_AES_128_GCM_SHA256);
  72216. wolfSSL_free(ssl);
  72217. ssl = NULL;
  72218. /* Test client order negotiation. */
  72219. ExpectNotNull(ssl = wolfSSL_new(ctx));
  72220. msg.buffer = clientHello;
  72221. msg.length = (unsigned int)sizeof(clientHello);
  72222. wolfSSL_SetIOReadCtx(ssl, &msg);
  72223. /* Server order: TLS13-AES256-GCM-SHA384:TLS13-AES128-GCM-SHA256 */
  72224. ExpectIntEQ(wolfSSL_set_cipher_list(ssl, serverCs), WOLFSSL_SUCCESS);
  72225. ExpectIntEQ(wolfSSL_UseClientSuites(ssl), 0);
  72226. /* Negotiate cipher suites in client order: TLS13-AES128-GCM-SHA256 */
  72227. ExpectIntEQ(wolfSSL_accept_TLSv13(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  72228. /* Check refined order - client order. */
  72229. ExpectIntEQ(ssl->suites->suiteSz, 4);
  72230. ExpectIntEQ(ssl->suites->suites[0], TLS13_BYTE);
  72231. ExpectIntEQ(ssl->suites->suites[1], TLS_AES_128_GCM_SHA256);
  72232. ExpectIntEQ(ssl->suites->suites[2], TLS13_BYTE);
  72233. ExpectIntEQ(ssl->suites->suites[3], TLS_AES_256_GCM_SHA384);
  72234. wolfSSL_free(ssl);
  72235. ssl = NULL;
  72236. /* Check duplicate detection is working. */
  72237. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx, dupCs), WOLFSSL_SUCCESS);
  72238. ExpectIntEQ(ctx->suites->suiteSz, 4);
  72239. ExpectIntEQ(ctx->suites->suites[0], TLS13_BYTE);
  72240. ExpectIntEQ(ctx->suites->suites[1], TLS_AES_128_GCM_SHA256);
  72241. ExpectIntEQ(ctx->suites->suites[2], TLS13_BYTE);
  72242. ExpectIntEQ(ctx->suites->suites[3], TLS_AES_256_GCM_SHA384);
  72243. #if defined(OPENSSL_EXTRA) || defined(WOLFSSL_SET_CIPHER_BYTES)
  72244. ExpectIntEQ(wolfSSL_CTX_set_cipher_list_bytes(ctx, dupCsBytes,
  72245. sizeof(dupCsBytes)), WOLFSSL_SUCCESS);
  72246. ExpectIntEQ(ctx->suites->suiteSz, 4);
  72247. ExpectIntEQ(ctx->suites->suites[0], TLS13_BYTE);
  72248. ExpectIntEQ(ctx->suites->suites[1], TLS_AES_256_GCM_SHA384);
  72249. ExpectIntEQ(ctx->suites->suites[2], TLS13_BYTE);
  72250. ExpectIntEQ(ctx->suites->suites[3], TLS_AES_128_GCM_SHA256);
  72251. #endif
  72252. wolfSSL_CTX_free(ctx);
  72253. #endif
  72254. return EXPECT_RESULT();
  72255. }
  72256. #endif
  72257. #if defined(HAVE_PK_CALLBACKS) && !defined(WOLFSSL_NO_TLS12)
  72258. #if !defined(NO_FILESYSTEM) && !defined(NO_DH) && \
  72259. !defined(NO_AES) && defined(HAVE_AES_CBC) && \
  72260. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  72261. static int my_DhCallback(WOLFSSL* ssl, struct DhKey* key,
  72262. const unsigned char* priv, unsigned int privSz,
  72263. const unsigned char* pubKeyDer, unsigned int pubKeySz,
  72264. unsigned char* out, unsigned int* outlen,
  72265. void* ctx)
  72266. {
  72267. int result;
  72268. /* Test fail when context associated with WOLFSSL is NULL */
  72269. if (ctx == NULL) {
  72270. return -1;
  72271. }
  72272. (void)ssl;
  72273. /* return 0 on success */
  72274. PRIVATE_KEY_UNLOCK();
  72275. result = wc_DhAgree(key, out, outlen, priv, privSz, pubKeyDer, pubKeySz);
  72276. PRIVATE_KEY_LOCK();
  72277. return result;
  72278. }
  72279. static int test_dh_ctx_setup(WOLFSSL_CTX* ctx) {
  72280. EXPECT_DECLS;
  72281. wolfSSL_CTX_SetDhAgreeCb(ctx, my_DhCallback);
  72282. #if defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  72283. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx, "DHE-RSA-AES128-SHA256"),
  72284. WOLFSSL_SUCCESS);
  72285. #endif
  72286. #if defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256)
  72287. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(ctx, "DHE-RSA-AES256-SHA256"),
  72288. WOLFSSL_SUCCESS);
  72289. #endif
  72290. return EXPECT_RESULT();
  72291. }
  72292. static int test_dh_ssl_setup(WOLFSSL* ssl)
  72293. {
  72294. EXPECT_DECLS;
  72295. static int dh_test_ctx = 1;
  72296. int ret;
  72297. wolfSSL_SetDhAgreeCtx(ssl, &dh_test_ctx);
  72298. ExpectIntEQ(*((int*)wolfSSL_GetDhAgreeCtx(ssl)), dh_test_ctx);
  72299. ret = wolfSSL_SetTmpDH_file(ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  72300. if (ret != WOLFSSL_SUCCESS && ret != WC_NO_ERR_TRACE(SIDE_ERROR)) {
  72301. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  72302. }
  72303. return EXPECT_RESULT();
  72304. }
  72305. static int test_dh_ssl_setup_fail(WOLFSSL* ssl)
  72306. {
  72307. EXPECT_DECLS;
  72308. int ret;
  72309. wolfSSL_SetDhAgreeCtx(ssl, NULL);
  72310. ExpectNull(wolfSSL_GetDhAgreeCtx(ssl));
  72311. ret = wolfSSL_SetTmpDH_file(ssl, dhParamFile, WOLFSSL_FILETYPE_PEM);
  72312. if (ret != WOLFSSL_SUCCESS && ret != WC_NO_ERR_TRACE(SIDE_ERROR)) {
  72313. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  72314. }
  72315. return EXPECT_RESULT();
  72316. }
  72317. #endif
  72318. static int test_DhCallbacks(void)
  72319. {
  72320. EXPECT_DECLS;
  72321. #if !defined(NO_FILESYSTEM) && !defined(NO_DH) && \
  72322. !defined(NO_AES) && defined(HAVE_AES_CBC) && \
  72323. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  72324. WOLFSSL_CTX *ctx = NULL;
  72325. WOLFSSL *ssl = NULL;
  72326. int test;
  72327. test_ssl_cbf func_cb_client;
  72328. test_ssl_cbf func_cb_server;
  72329. /* Test that DH callback APIs work. */
  72330. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  72331. ExpectIntEQ(wolfSSL_CTX_set_cipher_list(NULL, "NONE"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72332. wolfSSL_CTX_SetDhAgreeCb(ctx, &my_DhCallback);
  72333. /* load client ca cert */
  72334. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, 0),
  72335. WOLFSSL_SUCCESS);
  72336. /* test with NULL arguments */
  72337. wolfSSL_SetDhAgreeCtx(NULL, &test);
  72338. ExpectNull(wolfSSL_GetDhAgreeCtx(NULL));
  72339. /* test success case */
  72340. test = 1;
  72341. ExpectNotNull(ssl = wolfSSL_new(ctx));
  72342. wolfSSL_SetDhAgreeCtx(ssl, &test);
  72343. ExpectIntEQ(*((int*)wolfSSL_GetDhAgreeCtx(ssl)), test);
  72344. wolfSSL_free(ssl);
  72345. wolfSSL_CTX_free(ctx);
  72346. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  72347. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  72348. /* set callbacks to use DH functions */
  72349. func_cb_client.ctx_ready = &test_dh_ctx_setup;
  72350. func_cb_client.ssl_ready = &test_dh_ssl_setup;
  72351. func_cb_client.method = wolfTLSv1_2_client_method;
  72352. func_cb_server.ctx_ready = &test_dh_ctx_setup;
  72353. func_cb_server.ssl_ready = &test_dh_ssl_setup;
  72354. func_cb_server.method = wolfTLSv1_2_server_method;
  72355. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  72356. &func_cb_server, NULL), TEST_SUCCESS);
  72357. /* Test fail */
  72358. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  72359. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  72360. /* set callbacks to use DH functions */
  72361. func_cb_client.ctx_ready = &test_dh_ctx_setup;
  72362. func_cb_client.ssl_ready = &test_dh_ssl_setup_fail;
  72363. func_cb_client.method = wolfTLSv1_2_client_method;
  72364. func_cb_server.ctx_ready = &test_dh_ctx_setup;
  72365. func_cb_server.ssl_ready = &test_dh_ssl_setup_fail;
  72366. func_cb_server.method = wolfTLSv1_2_server_method;
  72367. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  72368. &func_cb_server, NULL), -1001);
  72369. #endif
  72370. return EXPECT_RESULT();
  72371. }
  72372. #endif /* HAVE_PK_CALLBACKS */
  72373. #ifdef HAVE_HASHDRBG
  72374. #ifdef TEST_RESEED_INTERVAL
  72375. static int test_wc_RNG_GenerateBlock_Reseed(void)
  72376. {
  72377. EXPECT_DECLS;
  72378. int i;
  72379. WC_RNG rng;
  72380. byte key[32];
  72381. XMEMSET(&rng, 0, sizeof(WC_RNG));
  72382. ExpectIntEQ(wc_InitRng(&rng), 0);
  72383. for (i = 0; i < WC_RESEED_INTERVAL + 10; i++) {
  72384. ExpectIntEQ(wc_RNG_GenerateBlock(&rng, key, sizeof(key)), 0);
  72385. }
  72386. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  72387. return EXPECT_RESULT();
  72388. }
  72389. #endif /* TEST_RESEED_INTERVAL */
  72390. static int test_wc_RNG_GenerateBlock(void)
  72391. {
  72392. EXPECT_DECLS;
  72393. int i;
  72394. WC_RNG rng;
  72395. byte key[32];
  72396. XMEMSET(&rng, 0, sizeof(WC_RNG));
  72397. ExpectIntEQ(wc_InitRng(&rng), 0);
  72398. for (i = 0; i < 10; i++) {
  72399. ExpectIntEQ(wc_RNG_GenerateBlock(&rng, key, sizeof(key)), 0);
  72400. }
  72401. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  72402. return EXPECT_RESULT();
  72403. }
  72404. #endif /* HAVE_HASHDRBG */
  72405. /*
  72406. * Testing get_rand_digit
  72407. */
  72408. static int test_get_rand_digit(void)
  72409. {
  72410. EXPECT_DECLS;
  72411. #if !defined(WC_NO_RNG) && defined(WOLFSSL_PUBLIC_MP)
  72412. WC_RNG rng;
  72413. mp_digit d;
  72414. XMEMSET(&rng, 0, sizeof(WC_RNG));
  72415. ExpectIntEQ(wc_InitRng(&rng), 0);
  72416. ExpectIntEQ(get_rand_digit(&rng, &d), 0);
  72417. ExpectIntEQ(get_rand_digit(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  72418. ExpectIntEQ(get_rand_digit(NULL, &d), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  72419. ExpectIntEQ(get_rand_digit(&rng, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  72420. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  72421. #endif
  72422. return EXPECT_RESULT();
  72423. } /* End test_get_rand_digit*/
  72424. /*
  72425. * Testing get_digit_count
  72426. */
  72427. static int test_get_digit_count(void)
  72428. {
  72429. EXPECT_DECLS;
  72430. #if !defined(WOLFSSL_SP_MATH) && defined(WOLFSSL_PUBLIC_MP)
  72431. mp_int a;
  72432. XMEMSET(&a, 0, sizeof(mp_int));
  72433. ExpectIntEQ(mp_init(&a), 0);
  72434. ExpectIntEQ(get_digit_count(NULL), 0);
  72435. ExpectIntEQ(get_digit_count(&a), 0);
  72436. mp_clear(&a);
  72437. #endif
  72438. return EXPECT_RESULT();
  72439. } /* End test_get_digit_count*/
  72440. /*
  72441. * Testing mp_cond_copy
  72442. */
  72443. static int test_mp_cond_copy(void)
  72444. {
  72445. EXPECT_DECLS;
  72446. #if (defined(HAVE_ECC) || defined(WOLFSSL_MP_COND_COPY)) && \
  72447. defined(WOLFSSL_PUBLIC_MP)
  72448. mp_int a;
  72449. mp_int b;
  72450. int copy = 0;
  72451. XMEMSET(&a, 0, sizeof(mp_int));
  72452. XMEMSET(&b, 0, sizeof(mp_int));
  72453. ExpectIntEQ(mp_init(&a), MP_OKAY);
  72454. ExpectIntEQ(mp_init(&b), MP_OKAY);
  72455. ExpectIntEQ(mp_cond_copy(NULL, copy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  72456. ExpectIntEQ(mp_cond_copy(NULL, copy, &b), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  72457. ExpectIntEQ(mp_cond_copy(&a, copy, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  72458. ExpectIntEQ(mp_cond_copy(&a, copy, &b), 0);
  72459. mp_clear(&a);
  72460. mp_clear(&b);
  72461. #endif
  72462. return EXPECT_RESULT();
  72463. } /* End test_mp_cond_copy*/
  72464. /*
  72465. * Testing mp_rand
  72466. */
  72467. static int test_mp_rand(void)
  72468. {
  72469. EXPECT_DECLS;
  72470. #if defined(WC_RSA_BLINDING) && defined(WOLFSSL_PUBLIC_MP)
  72471. mp_int a;
  72472. WC_RNG rng;
  72473. int digits = 1;
  72474. XMEMSET(&a, 0, sizeof(mp_int));
  72475. XMEMSET(&rng, 0, sizeof(WC_RNG));
  72476. ExpectIntEQ(mp_init(&a), MP_OKAY);
  72477. ExpectIntEQ(wc_InitRng(&rng), 0);
  72478. ExpectIntEQ(mp_rand(&a, digits, NULL), WC_NO_ERR_TRACE(MISSING_RNG_E));
  72479. ExpectIntEQ(mp_rand(NULL, digits, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  72480. ExpectIntEQ(mp_rand(&a, 0, &rng), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  72481. ExpectIntEQ(mp_rand(&a, digits, &rng), 0);
  72482. mp_clear(&a);
  72483. DoExpectIntEQ(wc_FreeRng(&rng), 0);
  72484. #endif
  72485. return EXPECT_RESULT();
  72486. } /* End test_mp_rand*/
  72487. /*
  72488. * Testing get_digit
  72489. */
  72490. static int test_get_digit(void)
  72491. {
  72492. EXPECT_DECLS;
  72493. #if defined(WOLFSSL_PUBLIC_MP)
  72494. mp_int a;
  72495. int n = 0;
  72496. XMEMSET(&a, 0, sizeof(mp_int));
  72497. ExpectIntEQ(mp_init(&a), MP_OKAY);
  72498. ExpectIntEQ(get_digit(NULL, n), 0);
  72499. ExpectIntEQ(get_digit(&a, n), 0);
  72500. mp_clear(&a);
  72501. #endif
  72502. return EXPECT_RESULT();
  72503. } /* End test_get_digit*/
  72504. /*
  72505. * Testing wc_export_int
  72506. */
  72507. static int test_wc_export_int(void)
  72508. {
  72509. EXPECT_DECLS;
  72510. #if (defined(HAVE_ECC) || defined(WOLFSSL_EXPORT_INT)) && \
  72511. defined(WOLFSSL_PUBLIC_MP)
  72512. mp_int mp;
  72513. byte buf[32];
  72514. word32 keySz = (word32)sizeof(buf);
  72515. word32 len = (word32)sizeof(buf);
  72516. XMEMSET(&mp, 0, sizeof(mp_int));
  72517. ExpectIntEQ(mp_init(&mp), MP_OKAY);
  72518. ExpectIntEQ(mp_set(&mp, 1234), 0);
  72519. ExpectIntEQ(wc_export_int(NULL, buf, &len, keySz, WC_TYPE_UNSIGNED_BIN),
  72520. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  72521. len = sizeof(buf)-1;
  72522. ExpectIntEQ(wc_export_int(&mp, buf, &len, keySz, WC_TYPE_UNSIGNED_BIN),
  72523. WC_NO_ERR_TRACE(BUFFER_E));
  72524. len = sizeof(buf);
  72525. ExpectIntEQ(wc_export_int(&mp, buf, &len, keySz, WC_TYPE_UNSIGNED_BIN), 0);
  72526. len = 4; /* test input too small */
  72527. ExpectIntEQ(wc_export_int(&mp, buf, &len, 0, WC_TYPE_HEX_STR), WC_NO_ERR_TRACE(BUFFER_E));
  72528. len = sizeof(buf);
  72529. ExpectIntEQ(wc_export_int(&mp, buf, &len, 0, WC_TYPE_HEX_STR), 0);
  72530. /* hex version of 1234 is 04D2 and should be 4 digits + 1 null */
  72531. ExpectIntEQ(len, 5);
  72532. mp_clear(&mp);
  72533. #endif
  72534. return EXPECT_RESULT();
  72535. } /* End test_wc_export_int*/
  72536. static int test_wc_InitRngNonce(void)
  72537. {
  72538. EXPECT_DECLS;
  72539. #if !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST) && \
  72540. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  72541. HAVE_FIPS_VERSION >= 2))
  72542. WC_RNG rng;
  72543. byte nonce[] = "\x0D\x74\xDB\x42\xA9\x10\x77\xDE"
  72544. "\x45\xAC\x13\x7A\xE1\x48\xAF\x16";
  72545. word32 nonceSz = sizeof(nonce);
  72546. ExpectIntEQ(wc_InitRngNonce(&rng, nonce, nonceSz), 0);
  72547. ExpectIntEQ(wc_FreeRng(&rng), 0);
  72548. #endif
  72549. return EXPECT_RESULT();
  72550. } /* End test_wc_InitRngNonce*/
  72551. /*
  72552. * Testing wc_InitRngNonce_ex
  72553. */
  72554. static int test_wc_InitRngNonce_ex(void)
  72555. {
  72556. EXPECT_DECLS;
  72557. #if !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST) && \
  72558. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  72559. HAVE_FIPS_VERSION >= 2))
  72560. WC_RNG rng;
  72561. byte nonce[] = "\x0D\x74\xDB\x42\xA9\x10\x77\xDE"
  72562. "\x45\xAC\x13\x7A\xE1\x48\xAF\x16";
  72563. word32 nonceSz = sizeof(nonce);
  72564. ExpectIntEQ(wc_InitRngNonce_ex(&rng, nonce, nonceSz, HEAP_HINT, testDevId),
  72565. 0);
  72566. ExpectIntEQ(wc_FreeRng(&rng), 0);
  72567. #endif
  72568. return EXPECT_RESULT();
  72569. } /* End test_wc_InitRngNonce_ex */
  72570. static int test_wolfSSL_X509_CRL(void)
  72571. {
  72572. EXPECT_DECLS;
  72573. #if defined(OPENSSL_EXTRA) && defined(HAVE_CRL)
  72574. X509_CRL *crl = NULL;
  72575. char pem[][100] = {
  72576. "./certs/crl/crl.pem",
  72577. "./certs/crl/crl2.pem",
  72578. "./certs/crl/caEccCrl.pem",
  72579. "./certs/crl/eccCliCRL.pem",
  72580. "./certs/crl/eccSrvCRL.pem",
  72581. ""
  72582. };
  72583. #ifndef NO_BIO
  72584. BIO *bio = NULL;
  72585. #endif
  72586. #ifdef HAVE_TEST_d2i_X509_CRL_fp
  72587. char der[][100] = {
  72588. "./certs/crl/crl.der",
  72589. "./certs/crl/crl2.der",
  72590. ""};
  72591. #endif
  72592. XFILE fp = XBADFILE;
  72593. int i;
  72594. for (i = 0; pem[i][0] != '\0'; i++)
  72595. {
  72596. ExpectTrue((fp = XFOPEN(pem[i], "rb")) != XBADFILE);
  72597. ExpectNotNull(crl = (X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  72598. NULL, NULL));
  72599. ExpectNotNull(crl);
  72600. X509_CRL_free(crl);
  72601. if (fp != XBADFILE) {
  72602. XFCLOSE(fp);
  72603. fp = XBADFILE;
  72604. }
  72605. ExpectTrue((fp = XFOPEN(pem[i], "rb")) != XBADFILE);
  72606. ExpectNotNull((X509_CRL *)PEM_read_X509_CRL(fp, (X509_CRL **)&crl, NULL,
  72607. NULL));
  72608. if (EXPECT_FAIL()) {
  72609. crl = NULL;
  72610. }
  72611. ExpectNotNull(crl);
  72612. X509_CRL_free(crl);
  72613. crl = NULL;
  72614. if (fp != XBADFILE) {
  72615. XFCLOSE(fp);
  72616. fp = XBADFILE;
  72617. }
  72618. }
  72619. #ifndef NO_BIO
  72620. for (i = 0; pem[i][0] != '\0'; i++)
  72621. {
  72622. ExpectNotNull(bio = BIO_new_file(pem[i], "rb"));
  72623. ExpectNotNull(crl = PEM_read_bio_X509_CRL(bio, NULL, NULL, NULL));
  72624. X509_CRL_free(crl);
  72625. crl = NULL;
  72626. BIO_free(bio);
  72627. bio = NULL;
  72628. }
  72629. #endif
  72630. #ifdef HAVE_TEST_d2i_X509_CRL_fp
  72631. for (i = 0; der[i][0] != '\0'; i++) {
  72632. ExpectTrue((fp = XFOPEN(der[i], "rb")) != XBADFILE);
  72633. ExpectTrue((fp != XBADFILE));
  72634. ExpectNotNull(crl = (X509_CRL *)d2i_X509_CRL_fp((fp, X509_CRL **)NULL));
  72635. ExpectNotNull(crl);
  72636. X509_CRL_free(crl);
  72637. if (fp != XBADFILE) {
  72638. XFCLOSE(fp);
  72639. fp = XBADFILE;
  72640. }
  72641. fp = XFOPEN(der[i], "rb");
  72642. ExpectTrue((fp != XBADFILE));
  72643. ExpectNotNull((X509_CRL *)d2i_X509_CRL_fp(fp, (X509_CRL **)&crl));
  72644. if (EXPECT_FAIL()) {
  72645. crl = NULL;
  72646. }
  72647. ExpectNotNull(crl);
  72648. X509_CRL_free(crl);
  72649. crl = NULL;
  72650. if (fp != XBADFILE) {
  72651. XFCLOSE(fp);
  72652. fp = XBADFILE;
  72653. }
  72654. }
  72655. #endif
  72656. #endif
  72657. return EXPECT_RESULT();
  72658. }
  72659. static int test_wolfSSL_X509_load_crl_file(void)
  72660. {
  72661. EXPECT_DECLS;
  72662. #if defined(OPENSSL_EXTRA) && defined(HAVE_CRL) && !defined(NO_FILESYSTEM) && \
  72663. !defined(NO_STDIO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_BIO) && \
  72664. !defined(WOLFSSL_CRL_ALLOW_MISSING_CDP)
  72665. int i;
  72666. char pem[][100] = {
  72667. "./certs/crl/crl.pem",
  72668. "./certs/crl/crl2.pem",
  72669. "./certs/crl/caEccCrl.pem",
  72670. "./certs/crl/eccCliCRL.pem",
  72671. "./certs/crl/eccSrvCRL.pem",
  72672. #ifdef WC_RSA_PSS
  72673. "./certs/crl/crl_rsapss.pem",
  72674. #endif
  72675. ""
  72676. };
  72677. char der[][100] = {
  72678. "./certs/crl/crl.der",
  72679. "./certs/crl/crl2.der",
  72680. ""
  72681. };
  72682. WOLFSSL_X509_STORE* store = NULL;
  72683. WOLFSSL_X509_LOOKUP* lookup = NULL;
  72684. ExpectNotNull(store = wolfSSL_X509_STORE_new());
  72685. ExpectNotNull(lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()));
  72686. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/ca-cert.pem",
  72687. X509_FILETYPE_PEM), 1);
  72688. #ifdef WC_RSA_PSS
  72689. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/rsapss/ca-rsapss.pem",
  72690. X509_FILETYPE_PEM), 1);
  72691. #endif
  72692. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/server-revoked-cert.pem",
  72693. X509_FILETYPE_PEM), 1);
  72694. if (store) {
  72695. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm, svrCertFile,
  72696. WOLFSSL_FILETYPE_PEM), 1);
  72697. /* since store hasn't yet known the revoked cert*/
  72698. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm,
  72699. "certs/server-revoked-cert.pem", WOLFSSL_FILETYPE_PEM), 1);
  72700. }
  72701. for (i = 0; pem[i][0] != '\0'; i++) {
  72702. ExpectIntEQ(X509_load_crl_file(lookup, pem[i], WOLFSSL_FILETYPE_PEM),
  72703. 1);
  72704. }
  72705. if (store) {
  72706. /* since store knows crl list */
  72707. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm,
  72708. "certs/server-revoked-cert.pem", WOLFSSL_FILETYPE_PEM),
  72709. WC_NO_ERR_TRACE(CRL_CERT_REVOKED));
  72710. #ifdef WC_RSA_PSS
  72711. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm,
  72712. "certs/rsapss/server-rsapss-cert.pem", WOLFSSL_FILETYPE_PEM),
  72713. WC_NO_ERR_TRACE(CRL_CERT_REVOKED));
  72714. #endif
  72715. }
  72716. /* once feeing store */
  72717. X509_STORE_free(store);
  72718. store = NULL;
  72719. ExpectNotNull(store = wolfSSL_X509_STORE_new());
  72720. ExpectNotNull(lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()));
  72721. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/ca-cert.pem",
  72722. X509_FILETYPE_PEM), 1);
  72723. ExpectIntEQ(X509_LOOKUP_load_file(lookup, "certs/server-revoked-cert.pem",
  72724. X509_FILETYPE_PEM), 1);
  72725. if (store) {
  72726. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm, svrCertFile,
  72727. WOLFSSL_FILETYPE_PEM), 1);
  72728. /* since store hasn't yet known the revoked cert*/
  72729. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm,
  72730. "certs/server-revoked-cert.pem", WOLFSSL_FILETYPE_PEM), 1);
  72731. }
  72732. for (i = 0; der[i][0] != '\0'; i++) {
  72733. ExpectIntEQ(X509_load_crl_file(lookup, der[i], WOLFSSL_FILETYPE_ASN1),
  72734. 1);
  72735. }
  72736. if (store) {
  72737. /* since store knows crl list */
  72738. ExpectIntEQ(wolfSSL_CertManagerVerify(store->cm,
  72739. "certs/server-revoked-cert.pem", WOLFSSL_FILETYPE_PEM),
  72740. WC_NO_ERR_TRACE(CRL_CERT_REVOKED));
  72741. }
  72742. /* test for incorrect parameter */
  72743. ExpectIntEQ(X509_load_crl_file(NULL, pem[0], 0), 0);
  72744. ExpectIntEQ(X509_load_crl_file(lookup, NULL, 0), 0);
  72745. ExpectIntEQ(X509_load_crl_file(NULL, NULL, 0), 0);
  72746. X509_STORE_free(store);
  72747. store = NULL;
  72748. #endif
  72749. return EXPECT_RESULT();
  72750. }
  72751. static int test_wolfSSL_i2d_X509(void)
  72752. {
  72753. EXPECT_DECLS;
  72754. #if defined(OPENSSL_EXTRA) && defined(USE_CERT_BUFFERS_2048) && !defined(NO_RSA)
  72755. const unsigned char* cert_buf = server_cert_der_2048;
  72756. unsigned char* out = NULL;
  72757. unsigned char* tmp = NULL;
  72758. X509* cert = NULL;
  72759. ExpectNotNull(d2i_X509(&cert, &cert_buf, sizeof_server_cert_der_2048));
  72760. /* Pointer should be advanced */
  72761. ExpectPtrGT(cert_buf, server_cert_der_2048);
  72762. ExpectIntGT(i2d_X509(cert, &out), 0);
  72763. ExpectNotNull(out);
  72764. tmp = out;
  72765. ExpectIntGT(i2d_X509(cert, &tmp), 0);
  72766. ExpectPtrGT(tmp, out);
  72767. if (out != NULL)
  72768. XFREE(out, NULL, DYNAMIC_TYPE_OPENSSL);
  72769. X509_free(cert);
  72770. #endif
  72771. return EXPECT_RESULT();
  72772. }
  72773. static int test_wolfSSL_d2i_X509_REQ(void)
  72774. {
  72775. EXPECT_DECLS;
  72776. #if defined(WOLFSSL_CERT_REQ) && !defined(NO_RSA) && !defined(NO_BIO) && \
  72777. (defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA)) && \
  72778. !defined(WOLFSSL_SP_MATH)
  72779. /* ./certs/csr.signed.der, ./certs/csr.ext.der, and ./certs/csr.attr.der
  72780. * were generated by libest
  72781. * ./certs/csr.attr.der contains sample attributes
  72782. * ./certs/csr.ext.der contains sample extensions */
  72783. const char* csrFile = "./certs/csr.signed.der";
  72784. const char* csrPopFile = "./certs/csr.attr.der";
  72785. const char* csrExtFile = "./certs/csr.ext.der";
  72786. /* ./certs/csr.dsa.pem is generated using
  72787. * openssl req -newkey dsa:certs/dsaparams.pem \
  72788. * -keyout certs/csr.dsa.key.pem -keyform PEM -out certs/csr.dsa.pem \
  72789. * -outform PEM
  72790. * with the passphrase "wolfSSL"
  72791. */
  72792. #if !defined(NO_DSA) && !defined(HAVE_SELFTEST)
  72793. const char* csrDsaFile = "./certs/csr.dsa.pem";
  72794. XFILE f = XBADFILE;
  72795. #endif
  72796. BIO* bio = NULL;
  72797. X509* req = NULL;
  72798. EVP_PKEY *pub_key = NULL;
  72799. {
  72800. ExpectNotNull(bio = BIO_new_file(csrFile, "rb"));
  72801. ExpectNotNull(d2i_X509_REQ_bio(bio, &req));
  72802. /*
  72803. * Extract the public key from the CSR
  72804. */
  72805. ExpectNotNull(pub_key = X509_REQ_get_pubkey(req));
  72806. /*
  72807. * Verify the signature in the CSR
  72808. */
  72809. ExpectIntEQ(X509_REQ_verify(req, pub_key), 1);
  72810. X509_free(req);
  72811. req = NULL;
  72812. BIO_free(bio);
  72813. bio = NULL;
  72814. EVP_PKEY_free(pub_key);
  72815. pub_key = NULL;
  72816. }
  72817. {
  72818. #ifdef OPENSSL_ALL
  72819. X509_ATTRIBUTE* attr = NULL;
  72820. ASN1_TYPE *at = NULL;
  72821. #endif
  72822. ExpectNotNull(bio = BIO_new_file(csrPopFile, "rb"));
  72823. ExpectNotNull(d2i_X509_REQ_bio(bio, &req));
  72824. /*
  72825. * Extract the public key from the CSR
  72826. */
  72827. ExpectNotNull(pub_key = X509_REQ_get_pubkey(req));
  72828. /*
  72829. * Verify the signature in the CSR
  72830. */
  72831. ExpectIntEQ(X509_REQ_verify(req, pub_key), 1);
  72832. #ifdef OPENSSL_ALL
  72833. /*
  72834. * Obtain the challenge password from the CSR
  72835. */
  72836. ExpectIntEQ(X509_REQ_get_attr_by_NID(req, NID_pkcs9_challengePassword,
  72837. -1), 1);
  72838. ExpectNotNull(attr = X509_REQ_get_attr(req, 1));
  72839. ExpectNotNull(at = X509_ATTRIBUTE_get0_type(attr, 0));
  72840. ExpectNotNull(at->value.asn1_string);
  72841. ExpectStrEQ((char*)ASN1_STRING_data(at->value.asn1_string),
  72842. "2xIE+qqp/rhyTXP+");
  72843. ExpectIntEQ(X509_get_ext_by_NID(req, NID_subject_alt_name, -1), -1);
  72844. #endif
  72845. X509_free(req);
  72846. req = NULL;
  72847. BIO_free(bio);
  72848. bio = NULL;
  72849. EVP_PKEY_free(pub_key);
  72850. pub_key = NULL;
  72851. }
  72852. {
  72853. #ifdef OPENSSL_ALL
  72854. X509_ATTRIBUTE* attr = NULL;
  72855. ASN1_TYPE *at = NULL;
  72856. STACK_OF(X509_EXTENSION) *exts = NULL;
  72857. #endif
  72858. ExpectNotNull(bio = BIO_new_file(csrExtFile, "rb"));
  72859. /* This CSR contains an Extension Request attribute so
  72860. * we test extension parsing in a CSR attribute here. */
  72861. ExpectNotNull(d2i_X509_REQ_bio(bio, &req));
  72862. /*
  72863. * Extract the public key from the CSR
  72864. */
  72865. ExpectNotNull(pub_key = X509_REQ_get_pubkey(req));
  72866. /*
  72867. * Verify the signature in the CSR
  72868. */
  72869. ExpectIntEQ(X509_REQ_verify(req, pub_key), 1);
  72870. #ifdef OPENSSL_ALL
  72871. ExpectNotNull(exts = (STACK_OF(X509_EXTENSION)*)X509_REQ_get_extensions(
  72872. req));
  72873. ExpectIntEQ(sk_X509_EXTENSION_num(exts), 2);
  72874. sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
  72875. /*
  72876. * Obtain the challenge password from the CSR
  72877. */
  72878. ExpectIntEQ(X509_REQ_get_attr_by_NID(req, NID_pkcs9_challengePassword,
  72879. -1), 0);
  72880. ExpectNotNull(attr = X509_REQ_get_attr(req, 0));
  72881. ExpectNotNull(at = X509_ATTRIBUTE_get0_type(attr, 0));
  72882. ExpectNotNull(at->value.asn1_string);
  72883. ExpectStrEQ((char*)ASN1_STRING_data(at->value.asn1_string), "IGCu/xNL4/0/wOgo");
  72884. ExpectIntGE(X509_get_ext_by_NID(req, NID_key_usage, -1), 0);
  72885. ExpectIntGE(X509_get_ext_by_NID(req, NID_subject_alt_name, -1), 0);
  72886. #endif
  72887. X509_free(req);
  72888. req = NULL;
  72889. BIO_free(bio);
  72890. bio = NULL;
  72891. EVP_PKEY_free(pub_key);
  72892. pub_key = NULL;
  72893. }
  72894. #if !defined(NO_DSA) && !defined(HAVE_SELFTEST)
  72895. {
  72896. ExpectNotNull(bio = BIO_new_file(csrDsaFile, "rb"));
  72897. ExpectNotNull(PEM_read_bio_X509_REQ(bio, &req, NULL, NULL));
  72898. /*
  72899. * Extract the public key from the CSR
  72900. */
  72901. ExpectNotNull(pub_key = X509_REQ_get_pubkey(req));
  72902. /*
  72903. * Verify the signature in the CSR
  72904. */
  72905. ExpectIntEQ(X509_REQ_verify(req, pub_key), 1);
  72906. X509_free(req);
  72907. req = NULL;
  72908. BIO_free(bio);
  72909. /* Run the same test, but with a file pointer instead of a BIO.
  72910. * (PEM_read_X509_REQ)*/
  72911. ExpectTrue((f = XFOPEN(csrDsaFile, "rb")) != XBADFILE);
  72912. ExpectNotNull(PEM_read_X509_REQ(f, &req, NULL, NULL));
  72913. ExpectIntEQ(X509_REQ_verify(req, pub_key), 1);
  72914. X509_free(req);
  72915. EVP_PKEY_free(pub_key);
  72916. }
  72917. #endif /* !NO_DSA && !HAVE_SELFTEST */
  72918. #endif /* WOLFSSL_CERT_REQ && (OPENSSL_ALL || OPENSSL_EXTRA) */
  72919. return EXPECT_RESULT();
  72920. }
  72921. static int test_wolfSSL_PEM_read_X509(void)
  72922. {
  72923. EXPECT_DECLS;
  72924. #if defined(OPENSSL_EXTRA) && defined(HAVE_CRL) && !defined(NO_FILESYSTEM) && \
  72925. !defined(NO_RSA)
  72926. X509 *x509 = NULL;
  72927. XFILE fp = XBADFILE;
  72928. ExpectTrue((fp = XFOPEN(svrCertFile, "rb")) != XBADFILE);
  72929. ExpectNotNull(x509 = (X509 *)PEM_read_X509(fp, (X509 **)NULL, NULL, NULL));
  72930. X509_free(x509);
  72931. if (fp != XBADFILE)
  72932. XFCLOSE(fp);
  72933. #endif
  72934. return EXPECT_RESULT();
  72935. }
  72936. static int test_wolfSSL_PEM_read(void)
  72937. {
  72938. EXPECT_DECLS;
  72939. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_BIO)
  72940. const char* filename = "./certs/server-keyEnc.pem";
  72941. XFILE fp = XBADFILE;
  72942. char* name = NULL;
  72943. char* header = NULL;
  72944. byte* data = NULL;
  72945. long len;
  72946. EVP_CIPHER_INFO cipher;
  72947. WOLFSSL_BIO* bio = NULL;
  72948. byte* fileData = NULL;
  72949. size_t fileDataSz = 0;
  72950. byte* out;
  72951. ExpectNotNull(bio = BIO_new_file(filename, "rb"));
  72952. ExpectIntEQ(PEM_read_bio(bio, NULL, &header, &data, &len), 0);
  72953. ExpectIntEQ(PEM_read_bio(bio, &name, NULL, &data, &len), 0);
  72954. ExpectIntEQ(PEM_read_bio(bio, &name, &header, NULL, &len), 0);
  72955. ExpectIntEQ(PEM_read_bio(bio, &name, &header, &data, NULL), 0);
  72956. ExpectIntEQ(PEM_read_bio(bio, &name, &header, &data, &len), 1);
  72957. ExpectIntEQ(XSTRNCMP(name, "RSA PRIVATE KEY", 15), 0);
  72958. ExpectIntGT(XSTRLEN(header), 0);
  72959. ExpectIntGT(len, 0);
  72960. XFREE(name, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72961. name = NULL;
  72962. XFREE(header, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72963. header = NULL;
  72964. XFREE(data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  72965. data = NULL;
  72966. BIO_free(bio);
  72967. bio = NULL;
  72968. ExpectTrue((fp = XFOPEN(filename, "rb")) != XBADFILE);
  72969. /* Fail cases. */
  72970. ExpectIntEQ(PEM_read(fp, NULL, &header, &data, &len), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72971. ExpectIntEQ(PEM_read(fp, &name, NULL, &data, &len), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72972. ExpectIntEQ(PEM_read(fp, &name, &header, NULL, &len), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72973. ExpectIntEQ(PEM_read(fp, &name, &header, &data, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  72974. ExpectIntEQ(PEM_read(fp, &name, &header, &data, &len), WOLFSSL_SUCCESS);
  72975. ExpectIntEQ(XSTRNCMP(name, "RSA PRIVATE KEY", 15), 0);
  72976. ExpectIntGT(XSTRLEN(header), 0);
  72977. ExpectIntGT(len, 0);
  72978. ExpectIntEQ(XFSEEK(fp, 0, SEEK_END), 0);
  72979. ExpectIntGT((fileDataSz = XFTELL(fp)), 0);
  72980. ExpectIntEQ(XFSEEK(fp, 0, SEEK_SET), 0);
  72981. ExpectNotNull(fileData = (unsigned char*)XMALLOC(fileDataSz, NULL,
  72982. DYNAMIC_TYPE_TMP_BUFFER));
  72983. ExpectIntEQ(XFREAD(fileData, 1, fileDataSz, fp), fileDataSz);
  72984. if (fp != XBADFILE) {
  72985. XFCLOSE(fp);
  72986. fp = XBADFILE;
  72987. }
  72988. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  72989. /* Fail cases. */
  72990. ExpectIntEQ(PEM_write_bio(NULL, name, header, data, len), 0);
  72991. ExpectIntEQ(PEM_write_bio(bio, NULL, header, data, len), 0);
  72992. ExpectIntEQ(PEM_write_bio(bio, name, NULL, data, len), 0);
  72993. ExpectIntEQ(PEM_write_bio(bio, name, header, NULL, len), 0);
  72994. ExpectIntEQ(PEM_write_bio(bio, name, header, data, len), fileDataSz);
  72995. ExpectIntEQ(wolfSSL_BIO_get_mem_data(bio, &out), fileDataSz);
  72996. ExpectIntEQ(XMEMCMP(out, fileData, fileDataSz), 0);
  72997. /* Fail cases. */
  72998. ExpectIntEQ(PEM_write(XBADFILE, name, header, data, len), 0);
  72999. ExpectIntEQ(PEM_write(stderr, NULL, header, data, len), 0);
  73000. ExpectIntEQ(PEM_write(stderr, name, NULL, data, len), 0);
  73001. ExpectIntEQ(PEM_write(stderr, name, header, NULL, len), 0);
  73002. /* Pass case */
  73003. ExpectIntEQ(PEM_write(stderr, name, header, data, len), fileDataSz);
  73004. XFREE(name, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  73005. name = NULL;
  73006. XFREE(header, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  73007. header = NULL;
  73008. XFREE(data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  73009. data = NULL;
  73010. /* Read out of a fixed buffer BIO - forces malloc in PEM_read_bio. */
  73011. ExpectIntEQ(PEM_read_bio(bio, &name, &header, &data, &len), 1);
  73012. ExpectIntEQ(XSTRNCMP(name, "RSA PRIVATE KEY", 15), 0);
  73013. ExpectIntGT(XSTRLEN(header), 0);
  73014. ExpectIntGT(len, 0);
  73015. /* Fail cases. */
  73016. ExpectIntEQ(PEM_get_EVP_CIPHER_INFO(NULL, &cipher), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73017. ExpectIntEQ(PEM_get_EVP_CIPHER_INFO(header, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73018. ExpectIntEQ(PEM_get_EVP_CIPHER_INFO((char*)"", &cipher), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73019. #ifndef NO_DES3
  73020. ExpectIntEQ(PEM_get_EVP_CIPHER_INFO(header, &cipher), WOLFSSL_SUCCESS);
  73021. #endif
  73022. /* Fail cases. */
  73023. ExpectIntEQ(PEM_do_header(NULL, data, &len, PasswordCallBack,
  73024. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73025. ExpectIntEQ(PEM_do_header(&cipher, NULL, &len, PasswordCallBack,
  73026. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73027. ExpectIntEQ(PEM_do_header(&cipher, data, NULL, PasswordCallBack,
  73028. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73029. ExpectIntEQ(PEM_do_header(&cipher, data, &len, NULL,
  73030. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73031. ExpectIntEQ(PEM_do_header(&cipher, data, &len, NoPasswordCallBack,
  73032. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73033. #if !defined(NO_DES3) && !defined(NO_MD5)
  73034. ExpectIntEQ(PEM_do_header(&cipher, data, &len, PasswordCallBack,
  73035. (void*)"yassl123"), WOLFSSL_SUCCESS);
  73036. #else
  73037. ExpectIntEQ(PEM_do_header(&cipher, data, &len, PasswordCallBack,
  73038. (void*)"yassl123"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73039. #endif
  73040. BIO_free(bio);
  73041. bio = NULL;
  73042. XFREE(fileData, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  73043. fileData = NULL;
  73044. XFREE(name, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  73045. XFREE(header, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  73046. XFREE(data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  73047. name = NULL;
  73048. header = NULL;
  73049. data = NULL;
  73050. ExpectTrue((fp = XFOPEN(svrKeyFile, "rb")) != XBADFILE);
  73051. ExpectIntEQ(PEM_read(fp, &name, &header, &data, &len), WOLFSSL_SUCCESS);
  73052. ExpectIntEQ(XSTRNCMP(name, "RSA PRIVATE KEY", 15), 0);
  73053. ExpectIntEQ(XSTRLEN(header), 0);
  73054. ExpectIntGT(len, 0);
  73055. ExpectIntEQ(XFSEEK(fp, 0, SEEK_END), 0);
  73056. ExpectIntGT((fileDataSz = XFTELL(fp)), 0);
  73057. ExpectIntEQ(XFSEEK(fp, 0, SEEK_SET), 0);
  73058. ExpectNotNull(fileData = (unsigned char*)XMALLOC(fileDataSz, NULL,
  73059. DYNAMIC_TYPE_TMP_BUFFER));
  73060. ExpectIntEQ(XFREAD(fileData, 1, fileDataSz, fp), fileDataSz);
  73061. if (fp != XBADFILE)
  73062. XFCLOSE(fp);
  73063. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  73064. ExpectIntEQ(PEM_write_bio(bio, name, header, data, len), fileDataSz);
  73065. ExpectIntEQ(wolfSSL_BIO_get_mem_data(bio, &out), fileDataSz);
  73066. ExpectIntEQ(XMEMCMP(out, fileData, fileDataSz), 0);
  73067. BIO_free(bio);
  73068. XFREE(fileData, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  73069. XFREE(name, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  73070. XFREE(header, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  73071. XFREE(data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  73072. #endif
  73073. return EXPECT_RESULT();
  73074. }
  73075. static int test_wolfssl_EVP_aes_gcm_AAD_2_parts(void)
  73076. {
  73077. EXPECT_DECLS;
  73078. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AESGCM) && \
  73079. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  73080. const byte iv[12] = { 0 };
  73081. const byte key[16] = { 0 };
  73082. const byte cleartext[16] = { 0 };
  73083. const byte aad[] = {
  73084. 0x01, 0x10, 0x00, 0x2a, 0x08, 0x00, 0x04, 0x00,
  73085. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
  73086. 0x00, 0x00, 0xdc, 0x4d, 0xad, 0x6b, 0x06, 0x93,
  73087. 0x4f
  73088. };
  73089. byte out1Part[16];
  73090. byte outTag1Part[16];
  73091. byte out2Part[16];
  73092. byte outTag2Part[16];
  73093. byte decryptBuf[16];
  73094. int len = 0;
  73095. int tlen;
  73096. EVP_CIPHER_CTX* ctx = NULL;
  73097. /* ENCRYPT */
  73098. /* Send AAD and data in 1 part */
  73099. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  73100. tlen = 0;
  73101. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_aes_128_gcm(), NULL, NULL, NULL),
  73102. 1);
  73103. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), 1);
  73104. ExpectIntEQ(EVP_EncryptUpdate(ctx, NULL, &len, aad, sizeof(aad)), 1);
  73105. ExpectIntEQ(EVP_EncryptUpdate(ctx, out1Part, &len, cleartext,
  73106. sizeof(cleartext)), 1);
  73107. tlen += len;
  73108. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, out1Part, &len), 1);
  73109. tlen += len;
  73110. ExpectIntEQ(tlen, sizeof(cleartext));
  73111. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, 16,
  73112. outTag1Part), 1);
  73113. EVP_CIPHER_CTX_free(ctx);
  73114. ctx = NULL;
  73115. /* DECRYPT */
  73116. /* Send AAD and data in 1 part */
  73117. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  73118. tlen = 0;
  73119. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_aes_128_gcm(), NULL, NULL, NULL),
  73120. 1);
  73121. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), 1);
  73122. ExpectIntEQ(EVP_DecryptUpdate(ctx, NULL, &len, aad, sizeof(aad)), 1);
  73123. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptBuf, &len, out1Part,
  73124. sizeof(cleartext)), 1);
  73125. tlen += len;
  73126. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, 16,
  73127. outTag1Part), 1);
  73128. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptBuf, &len), 1);
  73129. tlen += len;
  73130. ExpectIntEQ(tlen, sizeof(cleartext));
  73131. EVP_CIPHER_CTX_free(ctx);
  73132. ctx = NULL;
  73133. ExpectIntEQ(XMEMCMP(decryptBuf, cleartext, len), 0);
  73134. /* ENCRYPT */
  73135. /* Send AAD and data in 2 parts */
  73136. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  73137. tlen = 0;
  73138. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_aes_128_gcm(), NULL, NULL, NULL),
  73139. 1);
  73140. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), 1);
  73141. ExpectIntEQ(EVP_EncryptUpdate(ctx, NULL, &len, aad, 1), 1);
  73142. ExpectIntEQ(EVP_EncryptUpdate(ctx, NULL, &len, aad + 1, sizeof(aad) - 1),
  73143. 1);
  73144. ExpectIntEQ(EVP_EncryptUpdate(ctx, out2Part, &len, cleartext, 1), 1);
  73145. tlen += len;
  73146. ExpectIntEQ(EVP_EncryptUpdate(ctx, out2Part + tlen, &len, cleartext + 1,
  73147. sizeof(cleartext) - 1), 1);
  73148. tlen += len;
  73149. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, out2Part + tlen, &len), 1);
  73150. tlen += len;
  73151. ExpectIntEQ(tlen, sizeof(cleartext));
  73152. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, 16,
  73153. outTag2Part), 1);
  73154. ExpectIntEQ(XMEMCMP(out1Part, out2Part, sizeof(out1Part)), 0);
  73155. ExpectIntEQ(XMEMCMP(outTag1Part, outTag2Part, sizeof(outTag1Part)), 0);
  73156. EVP_CIPHER_CTX_free(ctx);
  73157. ctx = NULL;
  73158. /* DECRYPT */
  73159. /* Send AAD and data in 2 parts */
  73160. ExpectNotNull(ctx = EVP_CIPHER_CTX_new());
  73161. tlen = 0;
  73162. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_aes_128_gcm(), NULL, NULL, NULL),
  73163. 1);
  73164. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), 1);
  73165. ExpectIntEQ(EVP_DecryptUpdate(ctx, NULL, &len, aad, 1), 1);
  73166. ExpectIntEQ(EVP_DecryptUpdate(ctx, NULL, &len, aad + 1, sizeof(aad) - 1),
  73167. 1);
  73168. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptBuf, &len, out1Part, 1), 1);
  73169. tlen += len;
  73170. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptBuf + tlen, &len, out1Part + 1,
  73171. sizeof(cleartext) - 1), 1);
  73172. tlen += len;
  73173. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, 16,
  73174. outTag1Part), 1);
  73175. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptBuf + tlen, &len), 1);
  73176. tlen += len;
  73177. ExpectIntEQ(tlen, sizeof(cleartext));
  73178. ExpectIntEQ(XMEMCMP(decryptBuf, cleartext, len), 0);
  73179. /* Test AAD reuse */
  73180. EVP_CIPHER_CTX_free(ctx);
  73181. #endif
  73182. return EXPECT_RESULT();
  73183. }
  73184. static int test_wolfssl_EVP_aes_gcm_zeroLen(void)
  73185. {
  73186. EXPECT_DECLS;
  73187. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AESGCM) && \
  73188. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  73189. /* Zero length plain text */
  73190. byte key[] = {
  73191. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73192. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73193. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73194. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  73195. }; /* align */
  73196. byte iv[] = {
  73197. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  73198. }; /* align */
  73199. byte plaintxt[1];
  73200. int ivSz = 12;
  73201. int plaintxtSz = 0;
  73202. unsigned char tag[16];
  73203. unsigned char tag_kat[] = {
  73204. 0x53,0x0f,0x8a,0xfb,0xc7,0x45,0x36,0xb9,
  73205. 0xa9,0x63,0xb4,0xf1,0xc4,0xcb,0x73,0x8b
  73206. };
  73207. byte ciphertxt[AES_BLOCK_SIZE * 4] = {0};
  73208. byte decryptedtxt[AES_BLOCK_SIZE * 4] = {0};
  73209. int ciphertxtSz = 0;
  73210. int decryptedtxtSz = 0;
  73211. int len = 0;
  73212. EVP_CIPHER_CTX *en = EVP_CIPHER_CTX_new();
  73213. EVP_CIPHER_CTX *de = EVP_CIPHER_CTX_new();
  73214. ExpectIntEQ(1, EVP_EncryptInit_ex(en, EVP_aes_256_gcm(), NULL, key, iv));
  73215. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  73216. ExpectIntEQ(1, EVP_EncryptUpdate(en, ciphertxt, &ciphertxtSz , plaintxt,
  73217. plaintxtSz));
  73218. ExpectIntEQ(1, EVP_EncryptFinal_ex(en, ciphertxt, &len));
  73219. ciphertxtSz += len;
  73220. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_GCM_GET_TAG, 16, tag));
  73221. ExpectIntEQ(1, EVP_CIPHER_CTX_cleanup(en));
  73222. ExpectIntEQ(0, ciphertxtSz);
  73223. ExpectIntEQ(0, XMEMCMP(tag, tag_kat, sizeof(tag)));
  73224. EVP_CIPHER_CTX_init(de);
  73225. ExpectIntEQ(1, EVP_DecryptInit_ex(de, EVP_aes_256_gcm(), NULL, key, iv));
  73226. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  73227. ExpectIntEQ(1, EVP_DecryptUpdate(de, NULL, &len, ciphertxt, len));
  73228. decryptedtxtSz = len;
  73229. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_GCM_SET_TAG, 16, tag));
  73230. ExpectIntEQ(1, EVP_DecryptFinal_ex(de, decryptedtxt, &len));
  73231. decryptedtxtSz += len;
  73232. ExpectIntEQ(0, decryptedtxtSz);
  73233. EVP_CIPHER_CTX_free(en);
  73234. EVP_CIPHER_CTX_free(de);
  73235. #endif
  73236. return EXPECT_RESULT();
  73237. }
  73238. static int test_wolfssl_EVP_aes_gcm(void)
  73239. {
  73240. EXPECT_DECLS;
  73241. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AESGCM) && \
  73242. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  73243. /* A 256 bit key, AES_128 will use the first 128 bit*/
  73244. byte *key = (byte*)"01234567890123456789012345678901";
  73245. /* A 128 bit IV */
  73246. byte *iv = (byte*)"0123456789012345";
  73247. int ivSz = AES_BLOCK_SIZE;
  73248. /* Message to be encrypted */
  73249. byte *plaintxt = (byte*)"for things to change you have to change";
  73250. /* Additional non-confidential data */
  73251. byte *aad = (byte*)"Don't spend major time on minor things.";
  73252. unsigned char tag[AES_BLOCK_SIZE] = {0};
  73253. int plaintxtSz = (int)XSTRLEN((char*)plaintxt);
  73254. int aadSz = (int)XSTRLEN((char*)aad);
  73255. byte ciphertxt[AES_BLOCK_SIZE * 4] = {0};
  73256. byte decryptedtxt[AES_BLOCK_SIZE * 4] = {0};
  73257. int ciphertxtSz = 0;
  73258. int decryptedtxtSz = 0;
  73259. int len = 0;
  73260. int i = 0;
  73261. EVP_CIPHER_CTX en[2];
  73262. EVP_CIPHER_CTX de[2];
  73263. for (i = 0; i < 2; i++) {
  73264. EVP_CIPHER_CTX_init(&en[i]);
  73265. if (i == 0) {
  73266. /* Default uses 96-bits IV length */
  73267. #ifdef WOLFSSL_AES_128
  73268. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_128_gcm(), NULL,
  73269. key, iv));
  73270. #elif defined(WOLFSSL_AES_192)
  73271. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_192_gcm(), NULL,
  73272. key, iv));
  73273. #elif defined(WOLFSSL_AES_256)
  73274. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_256_gcm(), NULL,
  73275. key, iv));
  73276. #endif
  73277. }
  73278. else {
  73279. #ifdef WOLFSSL_AES_128
  73280. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_128_gcm(), NULL,
  73281. NULL, NULL));
  73282. #elif defined(WOLFSSL_AES_192)
  73283. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_192_gcm(), NULL,
  73284. NULL, NULL));
  73285. #elif defined(WOLFSSL_AES_256)
  73286. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_256_gcm(), NULL,
  73287. NULL, NULL));
  73288. #endif
  73289. /* non-default must to set the IV length first */
  73290. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_SET_IVLEN,
  73291. ivSz, NULL));
  73292. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  73293. }
  73294. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], NULL, &len, aad, aadSz));
  73295. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], ciphertxt, &len, plaintxt,
  73296. plaintxtSz));
  73297. ciphertxtSz = len;
  73298. ExpectIntEQ(1, EVP_EncryptFinal_ex(&en[i], ciphertxt, &len));
  73299. ciphertxtSz += len;
  73300. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_GET_TAG,
  73301. AES_BLOCK_SIZE, tag));
  73302. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&en[i]), 1);
  73303. EVP_CIPHER_CTX_init(&de[i]);
  73304. if (i == 0) {
  73305. /* Default uses 96-bits IV length */
  73306. #ifdef WOLFSSL_AES_128
  73307. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_gcm(), NULL,
  73308. key, iv));
  73309. #elif defined(WOLFSSL_AES_192)
  73310. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_gcm(), NULL,
  73311. key, iv));
  73312. #elif defined(WOLFSSL_AES_256)
  73313. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_gcm(), NULL,
  73314. key, iv));
  73315. #endif
  73316. }
  73317. else {
  73318. #ifdef WOLFSSL_AES_128
  73319. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_gcm(), NULL,
  73320. NULL, NULL));
  73321. #elif defined(WOLFSSL_AES_192)
  73322. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_gcm(), NULL,
  73323. NULL, NULL));
  73324. #elif defined(WOLFSSL_AES_256)
  73325. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_gcm(), NULL,
  73326. NULL, NULL));
  73327. #endif
  73328. /* non-default must to set the IV length first */
  73329. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN,
  73330. ivSz, NULL));
  73331. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  73332. }
  73333. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  73334. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  73335. ciphertxtSz));
  73336. decryptedtxtSz = len;
  73337. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG,
  73338. AES_BLOCK_SIZE, tag));
  73339. ExpectIntEQ(1, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  73340. decryptedtxtSz += len;
  73341. ExpectIntEQ(ciphertxtSz, decryptedtxtSz);
  73342. ExpectIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
  73343. /* modify tag*/
  73344. if (i == 0) {
  73345. /* Default uses 96-bits IV length */
  73346. #ifdef WOLFSSL_AES_128
  73347. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_gcm(), NULL,
  73348. key, iv));
  73349. #elif defined(WOLFSSL_AES_192)
  73350. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_gcm(), NULL,
  73351. key, iv));
  73352. #elif defined(WOLFSSL_AES_256)
  73353. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_gcm(), NULL,
  73354. key, iv));
  73355. #endif
  73356. }
  73357. else {
  73358. #ifdef WOLFSSL_AES_128
  73359. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_gcm(), NULL,
  73360. NULL, NULL));
  73361. #elif defined(WOLFSSL_AES_192)
  73362. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_gcm(), NULL,
  73363. NULL, NULL));
  73364. #elif defined(WOLFSSL_AES_256)
  73365. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_gcm(), NULL,
  73366. NULL, NULL));
  73367. #endif
  73368. /* non-default must to set the IV length first */
  73369. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN,
  73370. ivSz, NULL));
  73371. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  73372. }
  73373. tag[AES_BLOCK_SIZE-1]+=0xBB;
  73374. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  73375. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG,
  73376. AES_BLOCK_SIZE, tag));
  73377. /* fail due to wrong tag */
  73378. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  73379. ciphertxtSz));
  73380. ExpectIntEQ(0, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  73381. ExpectIntEQ(0, len);
  73382. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&de[i]), 1);
  73383. }
  73384. #endif /* OPENSSL_EXTRA && !NO_AES && HAVE_AESGCM */
  73385. return EXPECT_RESULT();
  73386. }
  73387. static int test_wolfssl_EVP_aria_gcm(void)
  73388. {
  73389. int res = TEST_SKIPPED;
  73390. #if defined(OPENSSL_EXTRA) && defined(HAVE_ARIA) && \
  73391. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  73392. /* A 256 bit key, AES_128 will use the first 128 bit*/
  73393. byte *key = (byte*)"01234567890123456789012345678901";
  73394. /* A 128 bit IV */
  73395. byte *iv = (byte*)"0123456789012345";
  73396. int ivSz = ARIA_BLOCK_SIZE;
  73397. /* Message to be encrypted */
  73398. const int plaintxtSz = 40;
  73399. byte plaintxt[WC_ARIA_GCM_GET_CIPHERTEXT_SIZE(plaintxtSz)];
  73400. XMEMCPY(plaintxt,"for things to change you have to change",plaintxtSz);
  73401. /* Additional non-confidential data */
  73402. byte *aad = (byte*)"Don't spend major time on minor things.";
  73403. unsigned char tag[ARIA_BLOCK_SIZE] = {0};
  73404. int aadSz = (int)XSTRLEN((char*)aad);
  73405. byte ciphertxt[WC_ARIA_GCM_GET_CIPHERTEXT_SIZE(plaintxtSz)];
  73406. byte decryptedtxt[plaintxtSz];
  73407. int ciphertxtSz = 0;
  73408. int decryptedtxtSz = 0;
  73409. int len = 0;
  73410. int i = 0;
  73411. #define TEST_ARIA_GCM_COUNT 6
  73412. EVP_CIPHER_CTX en[TEST_ARIA_GCM_COUNT];
  73413. EVP_CIPHER_CTX de[TEST_ARIA_GCM_COUNT];
  73414. for (i = 0; i < TEST_ARIA_GCM_COUNT; i++) {
  73415. EVP_CIPHER_CTX_init(&en[i]);
  73416. switch (i) {
  73417. case 0:
  73418. /* Default uses 96-bits IV length */
  73419. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_128_gcm(), NULL, key, iv));
  73420. break;
  73421. case 1:
  73422. /* Default uses 96-bits IV length */
  73423. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_192_gcm(), NULL, key, iv));
  73424. break;
  73425. case 2:
  73426. /* Default uses 96-bits IV length */
  73427. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_256_gcm(), NULL, key, iv));
  73428. break;
  73429. case 3:
  73430. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_128_gcm(), NULL, NULL, NULL));
  73431. /* non-default must to set the IV length first */
  73432. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  73433. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  73434. break;
  73435. case 4:
  73436. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_192_gcm(), NULL, NULL, NULL));
  73437. /* non-default must to set the IV length first */
  73438. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  73439. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  73440. break;
  73441. case 5:
  73442. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aria_256_gcm(), NULL, NULL, NULL));
  73443. /* non-default must to set the IV length first */
  73444. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  73445. AssertIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  73446. break;
  73447. }
  73448. XMEMSET(ciphertxt,0,sizeof(ciphertxt));
  73449. AssertIntEQ(1, EVP_EncryptUpdate(&en[i], NULL, &len, aad, aadSz));
  73450. AssertIntEQ(1, EVP_EncryptUpdate(&en[i], ciphertxt, &len, plaintxt, plaintxtSz));
  73451. ciphertxtSz = len;
  73452. AssertIntEQ(1, EVP_EncryptFinal_ex(&en[i], ciphertxt, &len));
  73453. AssertIntNE(0, XMEMCMP(plaintxt, ciphertxt, plaintxtSz));
  73454. ciphertxtSz += len;
  73455. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_GET_TAG, ARIA_BLOCK_SIZE, tag));
  73456. AssertIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&en[i]), 1);
  73457. EVP_CIPHER_CTX_init(&de[i]);
  73458. switch (i) {
  73459. case 0:
  73460. /* Default uses 96-bits IV length */
  73461. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_128_gcm(), NULL, key, iv));
  73462. break;
  73463. case 1:
  73464. /* Default uses 96-bits IV length */
  73465. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_192_gcm(), NULL, key, iv));
  73466. break;
  73467. case 2:
  73468. /* Default uses 96-bits IV length */
  73469. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_256_gcm(), NULL, key, iv));
  73470. break;
  73471. case 3:
  73472. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_128_gcm(), NULL, NULL, NULL));
  73473. /* non-default must to set the IV length first */
  73474. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  73475. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  73476. break;
  73477. case 4:
  73478. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_192_gcm(), NULL, NULL, NULL));
  73479. /* non-default must to set the IV length first */
  73480. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  73481. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  73482. break;
  73483. case 5:
  73484. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aria_256_gcm(), NULL, NULL, NULL));
  73485. /* non-default must to set the IV length first */
  73486. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  73487. AssertIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  73488. break;
  73489. }
  73490. XMEMSET(decryptedtxt,0,sizeof(decryptedtxt));
  73491. AssertIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  73492. AssertIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt, ciphertxtSz));
  73493. decryptedtxtSz = len;
  73494. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG, ARIA_BLOCK_SIZE, tag));
  73495. AssertIntEQ(1, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  73496. decryptedtxtSz += len;
  73497. AssertIntEQ(plaintxtSz, decryptedtxtSz);
  73498. AssertIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
  73499. XMEMSET(decryptedtxt,0,sizeof(decryptedtxt));
  73500. /* modify tag*/
  73501. tag[AES_BLOCK_SIZE-1]+=0xBB;
  73502. AssertIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  73503. AssertIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG, ARIA_BLOCK_SIZE, tag));
  73504. /* fail due to wrong tag */
  73505. AssertIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt, ciphertxtSz));
  73506. AssertIntEQ(0, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  73507. AssertIntEQ(0, len);
  73508. AssertIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&de[i]), 1);
  73509. }
  73510. res = TEST_RES_CHECK(1);
  73511. #endif /* OPENSSL_EXTRA && !NO_AES && HAVE_AESGCM */
  73512. return res;
  73513. }
  73514. static int test_wolfssl_EVP_aes_ccm_zeroLen(void)
  73515. {
  73516. EXPECT_DECLS;
  73517. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AESCCM) && \
  73518. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  73519. /* Zero length plain text */
  73520. byte key[] = {
  73521. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73522. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73523. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73524. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  73525. }; /* align */
  73526. byte iv[] = {
  73527. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  73528. }; /* align */
  73529. byte plaintxt[1];
  73530. int ivSz = 12;
  73531. int plaintxtSz = 0;
  73532. unsigned char tag[16];
  73533. byte ciphertxt[AES_BLOCK_SIZE * 4] = {0};
  73534. byte decryptedtxt[AES_BLOCK_SIZE * 4] = {0};
  73535. int ciphertxtSz = 0;
  73536. int decryptedtxtSz = 0;
  73537. int len = 0;
  73538. EVP_CIPHER_CTX *en = EVP_CIPHER_CTX_new();
  73539. EVP_CIPHER_CTX *de = EVP_CIPHER_CTX_new();
  73540. ExpectIntEQ(1, EVP_EncryptInit_ex(en, EVP_aes_256_ccm(), NULL, key, iv));
  73541. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_CCM_SET_IVLEN, ivSz, NULL));
  73542. ExpectIntEQ(1, EVP_EncryptUpdate(en, ciphertxt, &ciphertxtSz , plaintxt,
  73543. plaintxtSz));
  73544. ExpectIntEQ(1, EVP_EncryptFinal_ex(en, ciphertxt, &len));
  73545. ciphertxtSz += len;
  73546. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_CCM_GET_TAG, 16, tag));
  73547. ExpectIntEQ(1, EVP_CIPHER_CTX_cleanup(en));
  73548. ExpectIntEQ(0, ciphertxtSz);
  73549. EVP_CIPHER_CTX_init(de);
  73550. ExpectIntEQ(1, EVP_DecryptInit_ex(de, EVP_aes_256_ccm(), NULL, key, iv));
  73551. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_CCM_SET_IVLEN, ivSz, NULL));
  73552. ExpectIntEQ(1, EVP_DecryptUpdate(de, NULL, &len, ciphertxt, len));
  73553. decryptedtxtSz = len;
  73554. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_CCM_SET_TAG, 16, tag));
  73555. ExpectIntEQ(1, EVP_DecryptFinal_ex(de, decryptedtxt, &len));
  73556. decryptedtxtSz += len;
  73557. ExpectIntEQ(0, decryptedtxtSz);
  73558. EVP_CIPHER_CTX_free(en);
  73559. EVP_CIPHER_CTX_free(de);
  73560. #endif
  73561. return EXPECT_RESULT();
  73562. }
  73563. static int test_wolfssl_EVP_aes_ccm(void)
  73564. {
  73565. EXPECT_DECLS;
  73566. #if defined(OPENSSL_EXTRA) && !defined(NO_AES) && defined(HAVE_AESCCM) && \
  73567. !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  73568. /* A 256 bit key, AES_128 will use the first 128 bit*/
  73569. byte *key = (byte*)"01234567890123456789012345678901";
  73570. /* A 128 bit IV */
  73571. byte *iv = (byte*)"0123456789012";
  73572. int ivSz = (int)XSTRLEN((char*)iv);
  73573. /* Message to be encrypted */
  73574. byte *plaintxt = (byte*)"for things to change you have to change";
  73575. /* Additional non-confidential data */
  73576. byte *aad = (byte*)"Don't spend major time on minor things.";
  73577. unsigned char tag[AES_BLOCK_SIZE] = {0};
  73578. int plaintxtSz = (int)XSTRLEN((char*)plaintxt);
  73579. int aadSz = (int)XSTRLEN((char*)aad);
  73580. byte ciphertxt[AES_BLOCK_SIZE * 4] = {0};
  73581. byte decryptedtxt[AES_BLOCK_SIZE * 4] = {0};
  73582. int ciphertxtSz = 0;
  73583. int decryptedtxtSz = 0;
  73584. int len = 0;
  73585. int i = 0;
  73586. int ret;
  73587. EVP_CIPHER_CTX en[2];
  73588. EVP_CIPHER_CTX de[2];
  73589. for (i = 0; i < 2; i++) {
  73590. EVP_CIPHER_CTX_init(&en[i]);
  73591. if (i == 0) {
  73592. /* Default uses 96-bits IV length */
  73593. #ifdef WOLFSSL_AES_128
  73594. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_128_ccm(), NULL,
  73595. key, iv));
  73596. #elif defined(WOLFSSL_AES_192)
  73597. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_192_ccm(), NULL,
  73598. key, iv));
  73599. #elif defined(WOLFSSL_AES_256)
  73600. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_256_ccm(), NULL,
  73601. key, iv));
  73602. #endif
  73603. }
  73604. else {
  73605. #ifdef WOLFSSL_AES_128
  73606. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_128_ccm(), NULL,
  73607. NULL, NULL));
  73608. #elif defined(WOLFSSL_AES_192)
  73609. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_192_ccm(), NULL,
  73610. NULL, NULL));
  73611. #elif defined(WOLFSSL_AES_256)
  73612. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_aes_256_ccm(), NULL,
  73613. NULL, NULL));
  73614. #endif
  73615. /* non-default must to set the IV length first */
  73616. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_CCM_SET_IVLEN,
  73617. ivSz, NULL));
  73618. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  73619. }
  73620. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], NULL, &len, aad, aadSz));
  73621. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], ciphertxt, &len, plaintxt,
  73622. plaintxtSz));
  73623. ciphertxtSz = len;
  73624. ExpectIntEQ(1, EVP_EncryptFinal_ex(&en[i], ciphertxt, &len));
  73625. ciphertxtSz += len;
  73626. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_CCM_GET_TAG,
  73627. AES_BLOCK_SIZE, tag));
  73628. ret = wolfSSL_EVP_CIPHER_CTX_cleanup(&en[i]);
  73629. ExpectIntEQ(ret, 1);
  73630. EVP_CIPHER_CTX_init(&de[i]);
  73631. if (i == 0) {
  73632. /* Default uses 96-bits IV length */
  73633. #ifdef WOLFSSL_AES_128
  73634. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_ccm(), NULL,
  73635. key, iv));
  73636. #elif defined(WOLFSSL_AES_192)
  73637. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_ccm(), NULL,
  73638. key, iv));
  73639. #elif defined(WOLFSSL_AES_256)
  73640. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_ccm(), NULL,
  73641. key, iv));
  73642. #endif
  73643. }
  73644. else {
  73645. #ifdef WOLFSSL_AES_128
  73646. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_128_ccm(), NULL,
  73647. NULL, NULL));
  73648. #elif defined(WOLFSSL_AES_192)
  73649. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_192_ccm(), NULL,
  73650. NULL, NULL));
  73651. #elif defined(WOLFSSL_AES_256)
  73652. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_aes_256_ccm(), NULL,
  73653. NULL, NULL));
  73654. #endif
  73655. /* non-default must to set the IV length first */
  73656. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_IVLEN,
  73657. ivSz, NULL));
  73658. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  73659. }
  73660. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  73661. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  73662. ciphertxtSz));
  73663. decryptedtxtSz = len;
  73664. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_TAG,
  73665. AES_BLOCK_SIZE, tag));
  73666. ExpectIntEQ(1, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  73667. decryptedtxtSz += len;
  73668. ExpectIntEQ(ciphertxtSz, decryptedtxtSz);
  73669. ExpectIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
  73670. /* modify tag*/
  73671. tag[AES_BLOCK_SIZE-1]+=0xBB;
  73672. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  73673. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_TAG,
  73674. AES_BLOCK_SIZE, tag));
  73675. /* fail due to wrong tag */
  73676. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  73677. ciphertxtSz));
  73678. ExpectIntEQ(0, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  73679. ExpectIntEQ(0, len);
  73680. ret = wolfSSL_EVP_CIPHER_CTX_cleanup(&de[i]);
  73681. ExpectIntEQ(ret, 1);
  73682. }
  73683. #endif /* OPENSSL_EXTRA && !NO_AES && HAVE_AESCCM */
  73684. return EXPECT_RESULT();
  73685. }
  73686. static int test_wolfssl_EVP_chacha20_poly1305(void)
  73687. {
  73688. EXPECT_DECLS;
  73689. #if defined(OPENSSL_EXTRA) && defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  73690. byte key[CHACHA20_POLY1305_AEAD_KEYSIZE];
  73691. byte iv [CHACHA20_POLY1305_AEAD_IV_SIZE];
  73692. byte plainText[] = {0xDE, 0xAD, 0xBE, 0xEF};
  73693. byte aad[] = {0xAA, 0XBB, 0xCC, 0xDD, 0xEE, 0xFF};
  73694. byte cipherText[sizeof(plainText)];
  73695. byte decryptedText[sizeof(plainText)];
  73696. byte tag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE];
  73697. EVP_CIPHER_CTX* ctx = NULL;
  73698. int outSz;
  73699. XMEMSET(key, 0, sizeof(key));
  73700. XMEMSET(iv, 0, sizeof(iv));
  73701. /* Encrypt. */
  73702. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  73703. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_chacha20_poly1305(), NULL, NULL,
  73704. NULL), WOLFSSL_SUCCESS);
  73705. /* Invalid IV length. */
  73706. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN,
  73707. CHACHA20_POLY1305_AEAD_IV_SIZE-1, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73708. /* Valid IV length. */
  73709. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN,
  73710. CHACHA20_POLY1305_AEAD_IV_SIZE, NULL), WOLFSSL_SUCCESS);
  73711. /* Invalid tag length. */
  73712. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
  73713. CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE-1, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73714. /* Valid tag length. */
  73715. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
  73716. CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, NULL), WOLFSSL_SUCCESS);
  73717. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  73718. ExpectIntEQ(EVP_EncryptUpdate(ctx, NULL, &outSz, aad, sizeof(aad)),
  73719. WOLFSSL_SUCCESS);
  73720. ExpectIntEQ(outSz, sizeof(aad));
  73721. ExpectIntEQ(EVP_EncryptUpdate(ctx, cipherText, &outSz, plainText,
  73722. sizeof(plainText)), WOLFSSL_SUCCESS);
  73723. ExpectIntEQ(outSz, sizeof(plainText));
  73724. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, cipherText, &outSz), WOLFSSL_SUCCESS);
  73725. ExpectIntEQ(outSz, 0);
  73726. /* Invalid tag length. */
  73727. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG,
  73728. CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE-1, tag), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73729. /* Valid tag length. */
  73730. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG,
  73731. CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, tag), WOLFSSL_SUCCESS);
  73732. EVP_CIPHER_CTX_free(ctx);
  73733. ctx = NULL;
  73734. /* Decrypt. */
  73735. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  73736. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_chacha20_poly1305(), NULL, NULL,
  73737. NULL), WOLFSSL_SUCCESS);
  73738. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN,
  73739. CHACHA20_POLY1305_AEAD_IV_SIZE, NULL), WOLFSSL_SUCCESS);
  73740. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
  73741. CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, tag), WOLFSSL_SUCCESS);
  73742. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  73743. ExpectIntEQ(EVP_DecryptUpdate(ctx, NULL, &outSz, aad, sizeof(aad)),
  73744. WOLFSSL_SUCCESS);
  73745. ExpectIntEQ(outSz, sizeof(aad));
  73746. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  73747. sizeof(cipherText)), WOLFSSL_SUCCESS);
  73748. ExpectIntEQ(outSz, sizeof(cipherText));
  73749. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  73750. WOLFSSL_SUCCESS);
  73751. ExpectIntEQ(outSz, 0);
  73752. EVP_CIPHER_CTX_free(ctx);
  73753. ctx = NULL;
  73754. /* Test partial Inits. CipherInit() allow setting of key and iv
  73755. * in separate calls. */
  73756. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  73757. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, EVP_chacha20_poly1305(),
  73758. key, NULL, 1), WOLFSSL_SUCCESS);
  73759. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, NULL, NULL, iv, 1),
  73760. WOLFSSL_SUCCESS);
  73761. ExpectIntEQ(wolfSSL_EVP_CipherUpdate(ctx, NULL, &outSz,
  73762. aad, sizeof(aad)), WOLFSSL_SUCCESS);
  73763. ExpectIntEQ(outSz, sizeof(aad));
  73764. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  73765. sizeof(cipherText)), WOLFSSL_SUCCESS);
  73766. ExpectIntEQ(outSz, sizeof(cipherText));
  73767. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  73768. WOLFSSL_SUCCESS);
  73769. ExpectIntEQ(outSz, 0);
  73770. EVP_CIPHER_CTX_free(ctx);
  73771. #endif
  73772. return EXPECT_RESULT();
  73773. }
  73774. static int test_wolfssl_EVP_chacha20(void)
  73775. {
  73776. EXPECT_DECLS;
  73777. #if defined(OPENSSL_EXTRA) && defined(HAVE_CHACHA)
  73778. byte key[CHACHA_MAX_KEY_SZ];
  73779. byte iv [WOLFSSL_EVP_CHACHA_IV_BYTES];
  73780. byte plainText[] = {0xDE, 0xAD, 0xBE, 0xEF};
  73781. byte cipherText[sizeof(plainText)];
  73782. byte decryptedText[sizeof(plainText)];
  73783. EVP_CIPHER_CTX* ctx = NULL;
  73784. int outSz;
  73785. XMEMSET(key, 0, sizeof(key));
  73786. XMEMSET(iv, 0, sizeof(iv));
  73787. /* Encrypt. */
  73788. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  73789. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_chacha20(), NULL, NULL,
  73790. NULL), WOLFSSL_SUCCESS);
  73791. /* Any tag length must fail - not an AEAD cipher. */
  73792. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG,
  73793. 16, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73794. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  73795. ExpectIntEQ(EVP_EncryptUpdate(ctx, cipherText, &outSz, plainText,
  73796. sizeof(plainText)), WOLFSSL_SUCCESS);
  73797. ExpectIntEQ(outSz, sizeof(plainText));
  73798. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, cipherText, &outSz), WOLFSSL_SUCCESS);
  73799. ExpectIntEQ(outSz, 0);
  73800. EVP_CIPHER_CTX_free(ctx);
  73801. ctx = NULL;
  73802. /* Decrypt. */
  73803. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  73804. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_chacha20(), NULL, NULL,
  73805. NULL), WOLFSSL_SUCCESS);
  73806. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  73807. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  73808. sizeof(cipherText)), WOLFSSL_SUCCESS);
  73809. ExpectIntEQ(outSz, sizeof(cipherText));
  73810. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  73811. WOLFSSL_SUCCESS);
  73812. ExpectIntEQ(outSz, 0);
  73813. EVP_CIPHER_CTX_free(ctx);
  73814. ctx = NULL;
  73815. /* Test partial Inits. CipherInit() allow setting of key and iv
  73816. * in separate calls. */
  73817. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  73818. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, EVP_chacha20(),
  73819. key, NULL, 1), WOLFSSL_SUCCESS);
  73820. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, NULL, NULL, iv, 1),
  73821. WOLFSSL_SUCCESS);
  73822. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  73823. sizeof(cipherText)), WOLFSSL_SUCCESS);
  73824. ExpectIntEQ(outSz, sizeof(cipherText));
  73825. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  73826. WOLFSSL_SUCCESS);
  73827. ExpectIntEQ(outSz, 0);
  73828. EVP_CIPHER_CTX_free(ctx);
  73829. #endif
  73830. return EXPECT_RESULT();
  73831. }
  73832. static int test_wolfssl_EVP_sm4_ecb(void)
  73833. {
  73834. int res = TEST_SKIPPED;
  73835. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_ECB)
  73836. EXPECT_DECLS;
  73837. byte key[SM4_KEY_SIZE];
  73838. byte plainText[SM4_BLOCK_SIZE] = {
  73839. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF,
  73840. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF
  73841. };
  73842. byte cipherText[sizeof(plainText) + SM4_BLOCK_SIZE];
  73843. byte decryptedText[sizeof(plainText) + SM4_BLOCK_SIZE];
  73844. EVP_CIPHER_CTX* ctx;
  73845. int outSz;
  73846. XMEMSET(key, 0, sizeof(key));
  73847. /* Encrypt. */
  73848. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  73849. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_sm4_ecb(), NULL, NULL, NULL),
  73850. WOLFSSL_SUCCESS);
  73851. /* Any tag length must fail - not an AEAD cipher. */
  73852. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, 16, NULL),
  73853. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73854. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, NULL),
  73855. WOLFSSL_SUCCESS);
  73856. ExpectIntEQ(EVP_EncryptUpdate(ctx, cipherText, &outSz, plainText,
  73857. sizeof(plainText)), WOLFSSL_SUCCESS);
  73858. ExpectIntEQ(outSz, sizeof(plainText));
  73859. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, cipherText + outSz, &outSz),
  73860. WOLFSSL_SUCCESS);
  73861. ExpectIntEQ(outSz, SM4_BLOCK_SIZE);
  73862. ExpectBufNE(cipherText, plainText, sizeof(plainText));
  73863. EVP_CIPHER_CTX_free(ctx);
  73864. /* Decrypt. */
  73865. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  73866. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_sm4_ecb(), NULL, NULL, NULL),
  73867. WOLFSSL_SUCCESS);
  73868. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, NULL),
  73869. WOLFSSL_SUCCESS);
  73870. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  73871. sizeof(cipherText)), WOLFSSL_SUCCESS);
  73872. ExpectIntEQ(outSz, sizeof(plainText));
  73873. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText + outSz, &outSz),
  73874. WOLFSSL_SUCCESS);
  73875. ExpectIntEQ(outSz, 0);
  73876. ExpectBufEQ(decryptedText, plainText, sizeof(plainText));
  73877. EVP_CIPHER_CTX_free(ctx);
  73878. res = EXPECT_RESULT();
  73879. #endif
  73880. return res;
  73881. }
  73882. static int test_wolfssl_EVP_sm4_cbc(void)
  73883. {
  73884. int res = TEST_SKIPPED;
  73885. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_CBC)
  73886. EXPECT_DECLS;
  73887. byte key[SM4_KEY_SIZE];
  73888. byte iv[SM4_BLOCK_SIZE];
  73889. byte plainText[SM4_BLOCK_SIZE] = {
  73890. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF,
  73891. 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF
  73892. };
  73893. byte cipherText[sizeof(plainText) + SM4_BLOCK_SIZE];
  73894. byte decryptedText[sizeof(plainText) + SM4_BLOCK_SIZE];
  73895. EVP_CIPHER_CTX* ctx;
  73896. int outSz;
  73897. XMEMSET(key, 0, sizeof(key));
  73898. XMEMSET(iv, 0, sizeof(iv));
  73899. /* Encrypt. */
  73900. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  73901. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_sm4_cbc(), NULL, NULL, NULL),
  73902. WOLFSSL_SUCCESS);
  73903. /* Any tag length must fail - not an AEAD cipher. */
  73904. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, 16, NULL),
  73905. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73906. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  73907. ExpectIntEQ(EVP_EncryptUpdate(ctx, cipherText, &outSz, plainText,
  73908. sizeof(plainText)), WOLFSSL_SUCCESS);
  73909. ExpectIntEQ(outSz, sizeof(plainText));
  73910. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, cipherText + outSz, &outSz),
  73911. WOLFSSL_SUCCESS);
  73912. ExpectIntEQ(outSz, SM4_BLOCK_SIZE);
  73913. ExpectBufNE(cipherText, plainText, sizeof(plainText));
  73914. EVP_CIPHER_CTX_free(ctx);
  73915. /* Decrypt. */
  73916. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  73917. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_sm4_cbc(), NULL, NULL, NULL),
  73918. WOLFSSL_SUCCESS);
  73919. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  73920. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  73921. sizeof(cipherText)), WOLFSSL_SUCCESS);
  73922. ExpectIntEQ(outSz, sizeof(plainText));
  73923. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText + outSz, &outSz),
  73924. WOLFSSL_SUCCESS);
  73925. ExpectIntEQ(outSz, 0);
  73926. ExpectBufEQ(decryptedText, plainText, sizeof(plainText));
  73927. EVP_CIPHER_CTX_free(ctx);
  73928. /* Test partial Inits. CipherInit() allow setting of key and iv
  73929. * in separate calls. */
  73930. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  73931. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, EVP_sm4_cbc(), key, NULL, 0),
  73932. WOLFSSL_SUCCESS);
  73933. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, NULL, NULL, iv, 0),
  73934. WOLFSSL_SUCCESS);
  73935. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  73936. sizeof(cipherText)), WOLFSSL_SUCCESS);
  73937. ExpectIntEQ(outSz, sizeof(plainText));
  73938. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText + outSz, &outSz),
  73939. WOLFSSL_SUCCESS);
  73940. ExpectIntEQ(outSz, 0);
  73941. ExpectBufEQ(decryptedText, plainText, sizeof(plainText));
  73942. EVP_CIPHER_CTX_free(ctx);
  73943. res = EXPECT_RESULT();
  73944. #endif
  73945. return res;
  73946. }
  73947. static int test_wolfssl_EVP_sm4_ctr(void)
  73948. {
  73949. int res = TEST_SKIPPED;
  73950. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_CTR)
  73951. EXPECT_DECLS;
  73952. byte key[SM4_KEY_SIZE];
  73953. byte iv[SM4_BLOCK_SIZE];
  73954. byte plainText[] = {0xDE, 0xAD, 0xBE, 0xEF};
  73955. byte cipherText[sizeof(plainText)];
  73956. byte decryptedText[sizeof(plainText)];
  73957. EVP_CIPHER_CTX* ctx;
  73958. int outSz;
  73959. XMEMSET(key, 0, sizeof(key));
  73960. XMEMSET(iv, 0, sizeof(iv));
  73961. /* Encrypt. */
  73962. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  73963. ExpectIntEQ(EVP_EncryptInit_ex(ctx, EVP_sm4_ctr(), NULL, NULL, NULL),
  73964. WOLFSSL_SUCCESS);
  73965. /* Any tag length must fail - not an AEAD cipher. */
  73966. ExpectIntEQ(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, 16, NULL),
  73967. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  73968. ExpectIntEQ(EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  73969. ExpectIntEQ(EVP_EncryptUpdate(ctx, cipherText, &outSz, plainText,
  73970. sizeof(plainText)), WOLFSSL_SUCCESS);
  73971. ExpectIntEQ(outSz, sizeof(plainText));
  73972. ExpectIntEQ(EVP_EncryptFinal_ex(ctx, cipherText, &outSz), WOLFSSL_SUCCESS);
  73973. ExpectIntEQ(outSz, 0);
  73974. ExpectBufNE(cipherText, plainText, sizeof(plainText));
  73975. EVP_CIPHER_CTX_free(ctx);
  73976. /* Decrypt. */
  73977. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  73978. ExpectIntEQ(EVP_DecryptInit_ex(ctx, EVP_sm4_ctr(), NULL, NULL, NULL),
  73979. WOLFSSL_SUCCESS);
  73980. ExpectIntEQ(EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv), WOLFSSL_SUCCESS);
  73981. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  73982. sizeof(cipherText)), WOLFSSL_SUCCESS);
  73983. ExpectIntEQ(outSz, sizeof(cipherText));
  73984. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  73985. WOLFSSL_SUCCESS);
  73986. ExpectIntEQ(outSz, 0);
  73987. ExpectBufEQ(decryptedText, plainText, sizeof(plainText));
  73988. EVP_CIPHER_CTX_free(ctx);
  73989. /* Test partial Inits. CipherInit() allow setting of key and iv
  73990. * in separate calls. */
  73991. ExpectNotNull((ctx = EVP_CIPHER_CTX_new()));
  73992. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, EVP_sm4_ctr(), key, NULL, 1),
  73993. WOLFSSL_SUCCESS);
  73994. ExpectIntEQ(wolfSSL_EVP_CipherInit(ctx, NULL, NULL, iv, 1),
  73995. WOLFSSL_SUCCESS);
  73996. ExpectIntEQ(EVP_DecryptUpdate(ctx, decryptedText, &outSz, cipherText,
  73997. sizeof(cipherText)), WOLFSSL_SUCCESS);
  73998. ExpectIntEQ(outSz, sizeof(cipherText));
  73999. ExpectIntEQ(EVP_DecryptFinal_ex(ctx, decryptedText, &outSz),
  74000. WOLFSSL_SUCCESS);
  74001. ExpectIntEQ(outSz, 0);
  74002. ExpectBufEQ(decryptedText, plainText, sizeof(plainText));
  74003. EVP_CIPHER_CTX_free(ctx);
  74004. res = EXPECT_RESULT();
  74005. #endif
  74006. return res;
  74007. }
  74008. static int test_wolfssl_EVP_sm4_gcm_zeroLen(void)
  74009. {
  74010. int res = TEST_SKIPPED;
  74011. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_GCM)
  74012. /* Zero length plain text */
  74013. EXPECT_DECLS;
  74014. byte key[] = {
  74015. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  74016. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  74017. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  74018. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  74019. }; /* align */
  74020. byte iv[] = {
  74021. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  74022. }; /* align */
  74023. byte plaintxt[1];
  74024. int ivSz = 12;
  74025. int plaintxtSz = 0;
  74026. unsigned char tag[16];
  74027. unsigned char tag_kat[16] = {
  74028. 0x23,0x2f,0x0c,0xfe,0x30,0x8b,0x49,0xea,
  74029. 0x6f,0xc8,0x82,0x29,0xb5,0xdc,0x85,0x8d
  74030. };
  74031. byte ciphertxt[SM4_BLOCK_SIZE * 4] = {0};
  74032. byte decryptedtxt[SM4_BLOCK_SIZE * 4] = {0};
  74033. int ciphertxtSz = 0;
  74034. int decryptedtxtSz = 0;
  74035. int len = 0;
  74036. EVP_CIPHER_CTX *en = EVP_CIPHER_CTX_new();
  74037. EVP_CIPHER_CTX *de = EVP_CIPHER_CTX_new();
  74038. ExpectIntEQ(1, EVP_EncryptInit_ex(en, EVP_sm4_gcm(), NULL, key, iv));
  74039. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  74040. ExpectIntEQ(1, EVP_EncryptUpdate(en, ciphertxt, &ciphertxtSz , plaintxt,
  74041. plaintxtSz));
  74042. ExpectIntEQ(1, EVP_EncryptFinal_ex(en, ciphertxt, &len));
  74043. ciphertxtSz += len;
  74044. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_GCM_GET_TAG, 16, tag));
  74045. ExpectIntEQ(1, EVP_CIPHER_CTX_cleanup(en));
  74046. ExpectIntEQ(0, ciphertxtSz);
  74047. ExpectIntEQ(0, XMEMCMP(tag, tag_kat, sizeof(tag)));
  74048. EVP_CIPHER_CTX_init(de);
  74049. ExpectIntEQ(1, EVP_DecryptInit_ex(de, EVP_sm4_gcm(), NULL, key, iv));
  74050. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_GCM_SET_IVLEN, ivSz, NULL));
  74051. ExpectIntEQ(1, EVP_DecryptUpdate(de, NULL, &len, ciphertxt, len));
  74052. decryptedtxtSz = len;
  74053. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_GCM_SET_TAG, 16, tag));
  74054. ExpectIntEQ(1, EVP_DecryptFinal_ex(de, decryptedtxt, &len));
  74055. decryptedtxtSz += len;
  74056. ExpectIntEQ(0, decryptedtxtSz);
  74057. EVP_CIPHER_CTX_free(en);
  74058. EVP_CIPHER_CTX_free(de);
  74059. res = EXPECT_RESULT();
  74060. #endif /* OPENSSL_EXTRA && WOLFSSL_SM4_GCM */
  74061. return res;
  74062. }
  74063. static int test_wolfssl_EVP_sm4_gcm(void)
  74064. {
  74065. int res = TEST_SKIPPED;
  74066. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_GCM)
  74067. EXPECT_DECLS;
  74068. byte *key = (byte*)"0123456789012345";
  74069. /* A 128 bit IV */
  74070. byte *iv = (byte*)"0123456789012345";
  74071. int ivSz = SM4_BLOCK_SIZE;
  74072. /* Message to be encrypted */
  74073. byte *plaintxt = (byte*)"for things to change you have to change";
  74074. /* Additional non-confidential data */
  74075. byte *aad = (byte*)"Don't spend major time on minor things.";
  74076. unsigned char tag[SM4_BLOCK_SIZE] = {0};
  74077. int plaintxtSz = (int)XSTRLEN((char*)plaintxt);
  74078. int aadSz = (int)XSTRLEN((char*)aad);
  74079. byte ciphertxt[SM4_BLOCK_SIZE * 4] = {0};
  74080. byte decryptedtxt[SM4_BLOCK_SIZE * 4] = {0};
  74081. int ciphertxtSz = 0;
  74082. int decryptedtxtSz = 0;
  74083. int len = 0;
  74084. int i = 0;
  74085. EVP_CIPHER_CTX en[2];
  74086. EVP_CIPHER_CTX de[2];
  74087. for (i = 0; i < 2; i++) {
  74088. EVP_CIPHER_CTX_init(&en[i]);
  74089. if (i == 0) {
  74090. /* Default uses 96-bits IV length */
  74091. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_sm4_gcm(), NULL, key,
  74092. iv));
  74093. }
  74094. else {
  74095. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_sm4_gcm(), NULL, NULL,
  74096. NULL));
  74097. /* non-default must to set the IV length first */
  74098. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_SET_IVLEN,
  74099. ivSz, NULL));
  74100. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  74101. }
  74102. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], NULL, &len, aad, aadSz));
  74103. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], ciphertxt, &len, plaintxt,
  74104. plaintxtSz));
  74105. ciphertxtSz = len;
  74106. ExpectIntEQ(1, EVP_EncryptFinal_ex(&en[i], ciphertxt, &len));
  74107. ciphertxtSz += len;
  74108. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_GCM_GET_TAG,
  74109. SM4_BLOCK_SIZE, tag));
  74110. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&en[i]), 1);
  74111. EVP_CIPHER_CTX_init(&de[i]);
  74112. if (i == 0) {
  74113. /* Default uses 96-bits IV length */
  74114. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_sm4_gcm(), NULL, key,
  74115. iv));
  74116. }
  74117. else {
  74118. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_sm4_gcm(), NULL, NULL,
  74119. NULL));
  74120. /* non-default must to set the IV length first */
  74121. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_IVLEN,
  74122. ivSz, NULL));
  74123. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  74124. }
  74125. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  74126. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  74127. ciphertxtSz));
  74128. decryptedtxtSz = len;
  74129. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG,
  74130. SM4_BLOCK_SIZE, tag));
  74131. ExpectIntEQ(1, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  74132. decryptedtxtSz += len;
  74133. ExpectIntEQ(ciphertxtSz, decryptedtxtSz);
  74134. ExpectIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
  74135. /* modify tag*/
  74136. tag[SM4_BLOCK_SIZE-1]+=0xBB;
  74137. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  74138. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_GCM_SET_TAG,
  74139. SM4_BLOCK_SIZE, tag));
  74140. /* fail due to wrong tag */
  74141. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  74142. ciphertxtSz));
  74143. ExpectIntEQ(0, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  74144. ExpectIntEQ(0, len);
  74145. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&de[i]), 1);
  74146. }
  74147. res = EXPECT_RESULT();
  74148. #endif /* OPENSSL_EXTRA && WOLFSSL_SM4_GCM */
  74149. return res;
  74150. }
  74151. static int test_wolfssl_EVP_sm4_ccm_zeroLen(void)
  74152. {
  74153. int res = TEST_SKIPPED;
  74154. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_CCM)
  74155. /* Zero length plain text */
  74156. EXPECT_DECLS;
  74157. byte key[] = {
  74158. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  74159. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  74160. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  74161. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  74162. }; /* align */
  74163. byte iv[] = {
  74164. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  74165. }; /* align */
  74166. byte plaintxt[1];
  74167. int ivSz = 12;
  74168. int plaintxtSz = 0;
  74169. unsigned char tag[16];
  74170. byte ciphertxt[SM4_BLOCK_SIZE * 4] = {0};
  74171. byte decryptedtxt[SM4_BLOCK_SIZE * 4] = {0};
  74172. int ciphertxtSz = 0;
  74173. int decryptedtxtSz = 0;
  74174. int len = 0;
  74175. EVP_CIPHER_CTX *en = EVP_CIPHER_CTX_new();
  74176. EVP_CIPHER_CTX *de = EVP_CIPHER_CTX_new();
  74177. ExpectIntEQ(1, EVP_EncryptInit_ex(en, EVP_sm4_ccm(), NULL, key, iv));
  74178. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_CCM_SET_IVLEN, ivSz, NULL));
  74179. ExpectIntEQ(1, EVP_EncryptUpdate(en, ciphertxt, &ciphertxtSz , plaintxt,
  74180. plaintxtSz));
  74181. ExpectIntEQ(1, EVP_EncryptFinal_ex(en, ciphertxt, &len));
  74182. ciphertxtSz += len;
  74183. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(en, EVP_CTRL_CCM_GET_TAG, 16, tag));
  74184. ExpectIntEQ(1, EVP_CIPHER_CTX_cleanup(en));
  74185. ExpectIntEQ(0, ciphertxtSz);
  74186. EVP_CIPHER_CTX_init(de);
  74187. ExpectIntEQ(1, EVP_DecryptInit_ex(de, EVP_sm4_ccm(), NULL, key, iv));
  74188. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_CCM_SET_IVLEN, ivSz, NULL));
  74189. ExpectIntEQ(1, EVP_DecryptUpdate(de, NULL, &len, ciphertxt, len));
  74190. decryptedtxtSz = len;
  74191. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(de, EVP_CTRL_CCM_SET_TAG, 16, tag));
  74192. ExpectIntEQ(1, EVP_DecryptFinal_ex(de, decryptedtxt, &len));
  74193. decryptedtxtSz += len;
  74194. ExpectIntEQ(0, decryptedtxtSz);
  74195. EVP_CIPHER_CTX_free(en);
  74196. EVP_CIPHER_CTX_free(de);
  74197. res = EXPECT_RESULT();
  74198. #endif /* OPENSSL_EXTRA && WOLFSSL_SM4_CCM */
  74199. return res;
  74200. }
  74201. static int test_wolfssl_EVP_sm4_ccm(void)
  74202. {
  74203. int res = TEST_SKIPPED;
  74204. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM4_CCM)
  74205. EXPECT_DECLS;
  74206. byte *key = (byte*)"0123456789012345";
  74207. byte *iv = (byte*)"0123456789012";
  74208. int ivSz = (int)XSTRLEN((char*)iv);
  74209. /* Message to be encrypted */
  74210. byte *plaintxt = (byte*)"for things to change you have to change";
  74211. /* Additional non-confidential data */
  74212. byte *aad = (byte*)"Don't spend major time on minor things.";
  74213. unsigned char tag[SM4_BLOCK_SIZE] = {0};
  74214. int plaintxtSz = (int)XSTRLEN((char*)plaintxt);
  74215. int aadSz = (int)XSTRLEN((char*)aad);
  74216. byte ciphertxt[SM4_BLOCK_SIZE * 4] = {0};
  74217. byte decryptedtxt[SM4_BLOCK_SIZE * 4] = {0};
  74218. int ciphertxtSz = 0;
  74219. int decryptedtxtSz = 0;
  74220. int len = 0;
  74221. int i = 0;
  74222. EVP_CIPHER_CTX en[2];
  74223. EVP_CIPHER_CTX de[2];
  74224. for (i = 0; i < 2; i++) {
  74225. EVP_CIPHER_CTX_init(&en[i]);
  74226. if (i == 0) {
  74227. /* Default uses 96-bits IV length */
  74228. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_sm4_ccm(), NULL, key,
  74229. iv));
  74230. }
  74231. else {
  74232. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], EVP_sm4_ccm(), NULL, NULL,
  74233. NULL));
  74234. /* non-default must to set the IV length first */
  74235. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_CCM_SET_IVLEN,
  74236. ivSz, NULL));
  74237. ExpectIntEQ(1, EVP_EncryptInit_ex(&en[i], NULL, NULL, key, iv));
  74238. }
  74239. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], NULL, &len, aad, aadSz));
  74240. ExpectIntEQ(1, EVP_EncryptUpdate(&en[i], ciphertxt, &len, plaintxt,
  74241. plaintxtSz));
  74242. ciphertxtSz = len;
  74243. ExpectIntEQ(1, EVP_EncryptFinal_ex(&en[i], ciphertxt, &len));
  74244. ciphertxtSz += len;
  74245. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&en[i], EVP_CTRL_CCM_GET_TAG,
  74246. SM4_BLOCK_SIZE, tag));
  74247. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&en[i]), 1);
  74248. EVP_CIPHER_CTX_init(&de[i]);
  74249. if (i == 0) {
  74250. /* Default uses 96-bits IV length */
  74251. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_sm4_ccm(), NULL, key,
  74252. iv));
  74253. }
  74254. else {
  74255. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], EVP_sm4_ccm(), NULL, NULL,
  74256. NULL));
  74257. /* non-default must to set the IV length first */
  74258. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_IVLEN,
  74259. ivSz, NULL));
  74260. ExpectIntEQ(1, EVP_DecryptInit_ex(&de[i], NULL, NULL, key, iv));
  74261. }
  74262. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  74263. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  74264. ciphertxtSz));
  74265. decryptedtxtSz = len;
  74266. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_TAG,
  74267. SM4_BLOCK_SIZE, tag));
  74268. ExpectIntEQ(1, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  74269. decryptedtxtSz += len;
  74270. ExpectIntEQ(ciphertxtSz, decryptedtxtSz);
  74271. ExpectIntEQ(0, XMEMCMP(plaintxt, decryptedtxt, decryptedtxtSz));
  74272. /* modify tag*/
  74273. tag[SM4_BLOCK_SIZE-1]+=0xBB;
  74274. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], NULL, &len, aad, aadSz));
  74275. ExpectIntEQ(1, EVP_CIPHER_CTX_ctrl(&de[i], EVP_CTRL_CCM_SET_TAG,
  74276. SM4_BLOCK_SIZE, tag));
  74277. /* fail due to wrong tag */
  74278. ExpectIntEQ(1, EVP_DecryptUpdate(&de[i], decryptedtxt, &len, ciphertxt,
  74279. ciphertxtSz));
  74280. ExpectIntEQ(0, EVP_DecryptFinal_ex(&de[i], decryptedtxt, &len));
  74281. ExpectIntEQ(0, len);
  74282. ExpectIntEQ(wolfSSL_EVP_CIPHER_CTX_cleanup(&de[i]), 1);
  74283. }
  74284. res = EXPECT_RESULT();
  74285. #endif /* OPENSSL_EXTRA && WOLFSSL_SM4_CCM */
  74286. return res;
  74287. }
  74288. static int test_wolfSSL_EVP_PKEY_hkdf(void)
  74289. {
  74290. EXPECT_DECLS;
  74291. #if defined(OPENSSL_EXTRA) && defined(HAVE_HKDF)
  74292. EVP_PKEY_CTX* ctx = NULL;
  74293. byte salt[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  74294. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
  74295. byte key[] = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  74296. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
  74297. byte info[] = {0X01, 0x02, 0x03, 0x04, 0x05};
  74298. byte info2[] = {0X06, 0x07, 0x08, 0x09, 0x0A};
  74299. byte outKey[34];
  74300. size_t outKeySz = sizeof(outKey);
  74301. /* These expected outputs were gathered by running the same test below using
  74302. * OpenSSL. */
  74303. const byte extractAndExpand[] = {
  74304. 0x8B, 0xEB, 0x90, 0xA9, 0x04, 0xFF, 0x05, 0x10, 0xE4, 0xB5, 0xB1, 0x10,
  74305. 0x31, 0x34, 0xFF, 0x07, 0x5B, 0xE3, 0xC6, 0x93, 0xD4, 0xF8, 0xC7, 0xEE,
  74306. 0x96, 0xDA, 0x78, 0x7A, 0xE2, 0x9A, 0x2D, 0x05, 0x4B, 0xF6
  74307. };
  74308. const byte extractOnly[] = {
  74309. 0xE7, 0x6B, 0x9E, 0x0F, 0xE4, 0x02, 0x1D, 0x62, 0xEA, 0x97, 0x74, 0x5E,
  74310. 0xF4, 0x3C, 0x65, 0x4D, 0xC1, 0x46, 0x98, 0xAA, 0x79, 0x9A, 0xCB, 0x9C,
  74311. 0xCC, 0x3E, 0x7F, 0x2A, 0x2B, 0x41, 0xA1, 0x9E
  74312. };
  74313. const byte expandOnly[] = {
  74314. 0xFF, 0x29, 0x29, 0x56, 0x9E, 0xA7, 0x66, 0x02, 0xDB, 0x4F, 0xDB, 0x53,
  74315. 0x7D, 0x21, 0x67, 0x52, 0xC3, 0x0E, 0xF3, 0xFC, 0x71, 0xCE, 0x67, 0x2B,
  74316. 0xEA, 0x3B, 0xE9, 0xFC, 0xDD, 0xC8, 0xCC, 0xB7, 0x42, 0x74
  74317. };
  74318. const byte extractAndExpandAddInfo[] = {
  74319. 0x5A, 0x74, 0x79, 0x83, 0xA3, 0xA4, 0x2E, 0xB7, 0xD4, 0x08, 0xC2, 0x6A,
  74320. 0x2F, 0xA5, 0xE3, 0x4E, 0xF1, 0xF4, 0x87, 0x3E, 0xA6, 0xC7, 0x88, 0x45,
  74321. 0xD7, 0xE2, 0x15, 0xBC, 0xB8, 0x10, 0xEF, 0x6C, 0x4D, 0x7A
  74322. };
  74323. ExpectNotNull((ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL)));
  74324. ExpectIntEQ(EVP_PKEY_derive_init(ctx), WOLFSSL_SUCCESS);
  74325. /* NULL ctx. */
  74326. ExpectIntEQ(EVP_PKEY_CTX_set_hkdf_md(NULL, EVP_sha256()), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74327. /* NULL md. */
  74328. ExpectIntEQ(EVP_PKEY_CTX_set_hkdf_md(ctx, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74329. ExpectIntEQ(EVP_PKEY_CTX_set_hkdf_md(ctx, EVP_sha256()), WOLFSSL_SUCCESS);
  74330. /* NULL ctx. */
  74331. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_salt(NULL, salt, sizeof(salt)),
  74332. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74333. /* NULL salt is ok. */
  74334. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_salt(ctx, NULL, sizeof(salt)),
  74335. WOLFSSL_SUCCESS);
  74336. /* Salt length <= 0. */
  74337. /* Length 0 salt is ok. */
  74338. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_salt(ctx, salt, 0), WOLFSSL_SUCCESS);
  74339. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_salt(ctx, salt, -1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74340. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_salt(ctx, salt, sizeof(salt)),
  74341. WOLFSSL_SUCCESS);
  74342. /* NULL ctx. */
  74343. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_key(NULL, key, sizeof(key)),
  74344. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74345. /* NULL key. */
  74346. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_key(ctx, NULL, sizeof(key)),
  74347. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74348. /* Key length <= 0 */
  74349. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_key(ctx, key, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74350. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_key(ctx, key, -1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74351. ExpectIntEQ(EVP_PKEY_CTX_set1_hkdf_key(ctx, key, sizeof(key)),
  74352. WOLFSSL_SUCCESS);
  74353. /* NULL ctx. */
  74354. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(NULL, info, sizeof(info)),
  74355. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74356. /* NULL info is ok. */
  74357. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(ctx, NULL, sizeof(info)),
  74358. WOLFSSL_SUCCESS);
  74359. /* Info length <= 0 */
  74360. /* Length 0 info is ok. */
  74361. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(ctx, info, 0), WOLFSSL_SUCCESS);
  74362. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(ctx, info, -1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74363. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(ctx, info, sizeof(info)),
  74364. WOLFSSL_SUCCESS);
  74365. /* NULL ctx. */
  74366. ExpectIntEQ(EVP_PKEY_CTX_hkdf_mode(NULL, EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY),
  74367. WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  74368. /* Extract and expand (default). */
  74369. ExpectIntEQ(EVP_PKEY_derive(ctx, outKey, &outKeySz), WOLFSSL_SUCCESS);
  74370. ExpectIntEQ(outKeySz, sizeof(extractAndExpand));
  74371. ExpectIntEQ(XMEMCMP(outKey, extractAndExpand, outKeySz), 0);
  74372. /* Extract only. */
  74373. ExpectIntEQ(EVP_PKEY_CTX_hkdf_mode(ctx, EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY),
  74374. WOLFSSL_SUCCESS);
  74375. ExpectIntEQ(EVP_PKEY_derive(ctx, outKey, &outKeySz), WOLFSSL_SUCCESS);
  74376. ExpectIntEQ(outKeySz, sizeof(extractOnly));
  74377. ExpectIntEQ(XMEMCMP(outKey, extractOnly, outKeySz), 0);
  74378. outKeySz = sizeof(outKey);
  74379. /* Expand only. */
  74380. ExpectIntEQ(EVP_PKEY_CTX_hkdf_mode(ctx, EVP_PKEY_HKDEF_MODE_EXPAND_ONLY),
  74381. WOLFSSL_SUCCESS);
  74382. ExpectIntEQ(EVP_PKEY_derive(ctx, outKey, &outKeySz), WOLFSSL_SUCCESS);
  74383. ExpectIntEQ(outKeySz, sizeof(expandOnly));
  74384. ExpectIntEQ(XMEMCMP(outKey, expandOnly, outKeySz), 0);
  74385. outKeySz = sizeof(outKey);
  74386. /* Extract and expand with appended additional info. */
  74387. ExpectIntEQ(EVP_PKEY_CTX_add1_hkdf_info(ctx, info2, sizeof(info2)),
  74388. WOLFSSL_SUCCESS);
  74389. ExpectIntEQ(EVP_PKEY_CTX_hkdf_mode(ctx,
  74390. EVP_PKEY_HKDEF_MODE_EXTRACT_AND_EXPAND), WOLFSSL_SUCCESS);
  74391. ExpectIntEQ(EVP_PKEY_derive(ctx, outKey, &outKeySz), WOLFSSL_SUCCESS);
  74392. ExpectIntEQ(outKeySz, sizeof(extractAndExpandAddInfo));
  74393. ExpectIntEQ(XMEMCMP(outKey, extractAndExpandAddInfo, outKeySz), 0);
  74394. EVP_PKEY_CTX_free(ctx);
  74395. #endif /* OPENSSL_EXTRA && HAVE_HKDF */
  74396. return EXPECT_RESULT();
  74397. }
  74398. #ifndef NO_BIO
  74399. static int test_wolfSSL_PEM_X509_INFO_read_bio(void)
  74400. {
  74401. EXPECT_DECLS;
  74402. #if defined(OPENSSL_ALL) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  74403. BIO* bio = NULL;
  74404. X509_INFO* info = NULL;
  74405. STACK_OF(X509_INFO)* sk = NULL;
  74406. char* subject = NULL;
  74407. char exp1[] = "/C=US/ST=Montana/L=Bozeman/O=Sawtooth/OU=Consulting/"
  74408. "CN=www.wolfssl.com/emailAddress=info@wolfssl.com";
  74409. char exp2[] = "/C=US/ST=Montana/L=Bozeman/O=wolfSSL/OU=Support/"
  74410. "CN=www.wolfssl.com/emailAddress=info@wolfssl.com";
  74411. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  74412. ExpectIntGT(BIO_read_filename(bio, svrCertFile), 0);
  74413. ExpectNotNull(sk = PEM_X509_INFO_read_bio(bio, NULL, NULL, NULL));
  74414. ExpectIntEQ(sk_X509_INFO_num(sk), 2);
  74415. /* using dereference to maintain testing for Apache port*/
  74416. ExpectNotNull(info = sk_X509_INFO_pop(sk));
  74417. ExpectNotNull(subject = X509_NAME_oneline(X509_get_subject_name(info->x509),
  74418. 0, 0));
  74419. ExpectIntEQ(0, XSTRNCMP(subject, exp1, sizeof(exp1)));
  74420. XFREE(subject, 0, DYNAMIC_TYPE_OPENSSL);
  74421. X509_INFO_free(info);
  74422. info = NULL;
  74423. ExpectNotNull(info = sk_X509_INFO_pop(sk));
  74424. ExpectNotNull(subject = X509_NAME_oneline(X509_get_subject_name(info->x509),
  74425. 0, 0));
  74426. ExpectIntEQ(0, XSTRNCMP(subject, exp2, sizeof(exp2)));
  74427. XFREE(subject, 0, DYNAMIC_TYPE_OPENSSL);
  74428. X509_INFO_free(info);
  74429. ExpectNull(info = sk_X509_INFO_pop(sk));
  74430. sk_X509_INFO_pop_free(sk, X509_INFO_free);
  74431. BIO_free(bio);
  74432. #endif
  74433. return EXPECT_RESULT();
  74434. }
  74435. #endif /* !NO_BIO */
  74436. static int test_wolfSSL_X509_NAME_ENTRY_get_object(void)
  74437. {
  74438. EXPECT_DECLS;
  74439. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  74440. X509 *x509 = NULL;
  74441. X509_NAME* name = NULL;
  74442. int idx = 0;
  74443. X509_NAME_ENTRY *ne = NULL;
  74444. ASN1_OBJECT *object = NULL;
  74445. ExpectNotNull(x509 = wolfSSL_X509_load_certificate_file(cliCertFile,
  74446. WOLFSSL_FILETYPE_PEM));
  74447. ExpectNotNull(name = X509_get_subject_name(x509));
  74448. ExpectIntGE(idx = X509_NAME_get_index_by_NID(name, NID_commonName, -1), 0);
  74449. ExpectNotNull(ne = X509_NAME_get_entry(name, idx));
  74450. ExpectNotNull(object = X509_NAME_ENTRY_get_object(ne));
  74451. X509_free(x509);
  74452. #endif
  74453. return EXPECT_RESULT();
  74454. }
  74455. static int test_wolfSSL_X509_STORE_get1_certs(void)
  74456. {
  74457. EXPECT_DECLS;
  74458. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SIGNER_DER_CERT) && \
  74459. !defined(NO_FILESYSTEM) && !defined(NO_RSA)
  74460. X509_STORE_CTX *storeCtx = NULL;
  74461. X509_STORE *store = NULL;
  74462. X509 *caX509 = NULL;
  74463. X509 *svrX509 = NULL;
  74464. X509_NAME *subject = NULL;
  74465. WOLF_STACK_OF(WOLFSSL_X509) *certs = NULL;
  74466. ExpectNotNull(caX509 = X509_load_certificate_file(caCertFile,
  74467. SSL_FILETYPE_PEM));
  74468. ExpectNotNull((svrX509 = wolfSSL_X509_load_certificate_file(svrCertFile,
  74469. SSL_FILETYPE_PEM)));
  74470. ExpectNotNull(storeCtx = X509_STORE_CTX_new());
  74471. ExpectNotNull(store = X509_STORE_new());
  74472. ExpectNotNull(subject = X509_get_subject_name(caX509));
  74473. /* Errors */
  74474. ExpectNull(X509_STORE_get1_certs(storeCtx, subject));
  74475. ExpectNull(X509_STORE_get1_certs(NULL, subject));
  74476. ExpectNull(X509_STORE_get1_certs(storeCtx, NULL));
  74477. ExpectIntEQ(X509_STORE_add_cert(store, caX509), SSL_SUCCESS);
  74478. ExpectIntEQ(X509_STORE_CTX_init(storeCtx, store, caX509, NULL),
  74479. SSL_SUCCESS);
  74480. /* Should find the cert */
  74481. ExpectNotNull(certs = X509_STORE_get1_certs(storeCtx, subject));
  74482. ExpectIntEQ(1, wolfSSL_sk_X509_num(certs));
  74483. sk_X509_pop_free(certs, NULL);
  74484. certs = NULL;
  74485. /* Should not find the cert */
  74486. ExpectNotNull(subject = X509_get_subject_name(svrX509));
  74487. ExpectNotNull(certs = X509_STORE_get1_certs(storeCtx, subject));
  74488. ExpectIntEQ(0, wolfSSL_sk_X509_num(certs));
  74489. sk_X509_pop_free(certs, NULL);
  74490. certs = NULL;
  74491. X509_STORE_free(store);
  74492. X509_STORE_CTX_free(storeCtx);
  74493. X509_free(svrX509);
  74494. X509_free(caX509);
  74495. #endif /* OPENSSL_EXTRA && WOLFSSL_SIGNER_DER_CERT && !NO_FILESYSTEM */
  74496. return EXPECT_RESULT();
  74497. }
  74498. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  74499. defined(WOLFSSL_LOCAL_X509_STORE) && \
  74500. (defined(OPENSSL_ALL) || defined(WOLFSSL_QT)) && defined(HAVE_CRL)
  74501. static int test_wolfSSL_X509_STORE_set_get_crl_provider(X509_STORE_CTX* ctx,
  74502. X509_CRL** crl_out, X509* cert) {
  74503. X509_CRL *crl = NULL;
  74504. XFILE fp = XBADFILE;
  74505. char* cert_issuer = X509_NAME_oneline(X509_get_issuer_name(cert), NULL, 0);
  74506. int ret = 0;
  74507. (void)ctx;
  74508. if (cert_issuer == NULL)
  74509. return 0;
  74510. if ((fp = XFOPEN("certs/crl/crl.pem", "rb")) != XBADFILE) {
  74511. PEM_read_X509_CRL(fp, &crl, NULL, NULL);
  74512. XFCLOSE(fp);
  74513. if (crl != NULL) {
  74514. char* crl_issuer = X509_NAME_oneline(
  74515. X509_CRL_get_issuer(crl), NULL, 0);
  74516. if ((crl_issuer != NULL) &&
  74517. (XSTRCMP(cert_issuer, crl_issuer) == 0)) {
  74518. *crl_out = X509_CRL_dup(crl);
  74519. if (*crl_out != NULL)
  74520. ret = 1;
  74521. }
  74522. OPENSSL_free(crl_issuer);
  74523. }
  74524. }
  74525. X509_CRL_free(crl);
  74526. OPENSSL_free(cert_issuer);
  74527. return ret;
  74528. }
  74529. static int test_wolfSSL_X509_STORE_set_get_crl_provider2(X509_STORE_CTX* ctx,
  74530. X509_CRL** crl_out, X509* cert) {
  74531. (void)ctx;
  74532. (void)cert;
  74533. *crl_out = NULL;
  74534. return 1;
  74535. }
  74536. #ifndef NO_WOLFSSL_STUB
  74537. static int test_wolfSSL_X509_STORE_set_get_crl_check(X509_STORE_CTX* ctx,
  74538. X509_CRL* crl) {
  74539. (void)ctx;
  74540. (void)crl;
  74541. return 1;
  74542. }
  74543. #endif
  74544. static int test_wolfSSL_X509_STORE_set_get_crl_verify(int ok,
  74545. X509_STORE_CTX* ctx) {
  74546. int cert_error = X509_STORE_CTX_get_error(ctx);
  74547. X509_VERIFY_PARAM* param = X509_STORE_CTX_get0_param(ctx);
  74548. int flags = X509_VERIFY_PARAM_get_flags(param);
  74549. if ((flags & (X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL)) !=
  74550. (X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL)) {
  74551. /* Make sure the flags are set */
  74552. return 0;
  74553. }
  74554. /* Ignore CRL missing error */
  74555. #ifndef OPENSSL_COMPATIBLE_DEFAULTS
  74556. if (cert_error == WC_NO_ERR_TRACE(CRL_MISSING))
  74557. #else
  74558. if (cert_error == X509_V_ERR_UNABLE_TO_GET_CRL)
  74559. #endif
  74560. return 1;
  74561. return ok;
  74562. }
  74563. static int test_wolfSSL_X509_STORE_set_get_crl_ctx_ready(WOLFSSL_CTX* ctx)
  74564. {
  74565. EXPECT_DECLS;
  74566. X509_STORE* cert_store = NULL;
  74567. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL),
  74568. WOLFSSL_SUCCESS);
  74569. ExpectNotNull(cert_store = SSL_CTX_get_cert_store(ctx));
  74570. X509_STORE_set_get_crl(cert_store,
  74571. test_wolfSSL_X509_STORE_set_get_crl_provider);
  74572. #ifndef NO_WOLFSSL_STUB
  74573. X509_STORE_set_check_crl(cert_store,
  74574. test_wolfSSL_X509_STORE_set_get_crl_check);
  74575. #endif
  74576. return EXPECT_RESULT();
  74577. }
  74578. static int test_wolfSSL_X509_STORE_set_get_crl_ctx_ready2(WOLFSSL_CTX* ctx)
  74579. {
  74580. EXPECT_DECLS;
  74581. X509_STORE* cert_store = NULL;
  74582. X509_VERIFY_PARAM* param = NULL;
  74583. SSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  74584. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL),
  74585. WOLFSSL_SUCCESS);
  74586. ExpectNotNull(cert_store = SSL_CTX_get_cert_store(ctx));
  74587. X509_STORE_set_get_crl(cert_store,
  74588. test_wolfSSL_X509_STORE_set_get_crl_provider2);
  74589. #ifndef NO_WOLFSSL_STUB
  74590. X509_STORE_set_check_crl(cert_store,
  74591. test_wolfSSL_X509_STORE_set_get_crl_check);
  74592. #endif
  74593. X509_STORE_set_verify_cb(cert_store,
  74594. test_wolfSSL_X509_STORE_set_get_crl_verify);
  74595. ExpectNotNull(X509_STORE_get0_param(cert_store));
  74596. ExpectNotNull(param = X509_VERIFY_PARAM_new());
  74597. ExpectIntEQ(X509_VERIFY_PARAM_inherit(param,
  74598. X509_STORE_get0_param(cert_store)), 1);
  74599. ExpectIntEQ(X509_VERIFY_PARAM_set_flags(
  74600. param, X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL), 1);
  74601. ExpectIntEQ(X509_STORE_set1_param(cert_store, param), 1);
  74602. ExpectIntEQ(X509_STORE_set_flags(cert_store,
  74603. X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL), 1);
  74604. X509_VERIFY_PARAM_free(param);
  74605. return EXPECT_RESULT();
  74606. }
  74607. #endif
  74608. /* This test mimics the usage of the CRL provider in gRPC */
  74609. static int test_wolfSSL_X509_STORE_set_get_crl(void)
  74610. {
  74611. EXPECT_DECLS;
  74612. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  74613. defined(WOLFSSL_LOCAL_X509_STORE) && \
  74614. (defined(OPENSSL_ALL) || defined(WOLFSSL_QT)) && defined(HAVE_CRL)
  74615. test_ssl_cbf func_cb_client;
  74616. test_ssl_cbf func_cb_server;
  74617. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  74618. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  74619. func_cb_client.ctx_ready = test_wolfSSL_X509_STORE_set_get_crl_ctx_ready;
  74620. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  74621. &func_cb_server, NULL), TEST_SUCCESS);
  74622. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  74623. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  74624. func_cb_client.ctx_ready = test_wolfSSL_X509_STORE_set_get_crl_ctx_ready2;
  74625. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&func_cb_client,
  74626. &func_cb_server, NULL), TEST_SUCCESS);
  74627. #endif
  74628. return EXPECT_RESULT();
  74629. }
  74630. static int test_wolfSSL_dup_CA_list(void)
  74631. {
  74632. int res = TEST_SKIPPED;
  74633. #if defined(OPENSSL_ALL)
  74634. EXPECT_DECLS;
  74635. STACK_OF(X509_NAME) *originalStack = NULL;
  74636. STACK_OF(X509_NAME) *copyStack = NULL;
  74637. int originalCount = 0;
  74638. int copyCount = 0;
  74639. X509_NAME *name = NULL;
  74640. int i;
  74641. originalStack = sk_X509_NAME_new_null();
  74642. ExpectNotNull(originalStack);
  74643. for (i = 0; i < 3; i++) {
  74644. name = X509_NAME_new();
  74645. ExpectNotNull(name);
  74646. ExpectIntEQ(sk_X509_NAME_push(originalStack, name), i+1);
  74647. if (EXPECT_FAIL()) {
  74648. X509_NAME_free(name);
  74649. }
  74650. }
  74651. copyStack = SSL_dup_CA_list(originalStack);
  74652. ExpectNotNull(copyStack);
  74653. originalCount = sk_X509_NAME_num(originalStack);
  74654. copyCount = sk_X509_NAME_num(copyStack);
  74655. ExpectIntEQ(originalCount, copyCount);
  74656. sk_X509_NAME_pop_free(originalStack, X509_NAME_free);
  74657. sk_X509_NAME_pop_free(copyStack, X509_NAME_free);
  74658. originalStack = NULL;
  74659. copyStack = NULL;
  74660. res = EXPECT_RESULT();
  74661. #endif /* OPENSSL_ALL */
  74662. return res;
  74663. }
  74664. static int test_ForceZero(void)
  74665. {
  74666. EXPECT_DECLS;
  74667. unsigned char data[32];
  74668. unsigned int i, j, len;
  74669. /* Test case with 0 length */
  74670. ForceZero(data, 0);
  74671. /* Test ForceZero */
  74672. for (i = 0; i < sizeof(data); i++) {
  74673. for (len = 1; len < sizeof(data) - i; len++) {
  74674. for (j = 0; j < sizeof(data); j++)
  74675. data[j] = ((unsigned char)j + 1);
  74676. ForceZero(data + i, len);
  74677. for (j = 0; j < sizeof(data); j++) {
  74678. if (j < i || j >= i + len) {
  74679. ExpectIntNE(data[j], 0x00);
  74680. }
  74681. else {
  74682. ExpectIntEQ(data[j], 0x00);
  74683. }
  74684. }
  74685. }
  74686. }
  74687. return EXPECT_RESULT();
  74688. }
  74689. #ifndef NO_BIO
  74690. static int test_wolfSSL_X509_print(void)
  74691. {
  74692. EXPECT_DECLS;
  74693. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && \
  74694. !defined(NO_RSA) && defined(XSNPRINTF)
  74695. X509 *x509 = NULL;
  74696. BIO *bio = NULL;
  74697. #if defined(OPENSSL_ALL) && !defined(NO_WOLFSSL_DIR)
  74698. const X509_ALGOR *cert_sig_alg = NULL;
  74699. #endif
  74700. ExpectNotNull(x509 = X509_load_certificate_file(svrCertFile,
  74701. WOLFSSL_FILETYPE_PEM));
  74702. /* print to memory */
  74703. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  74704. ExpectIntEQ(X509_print(bio, x509), SSL_SUCCESS);
  74705. #if defined(OPENSSL_ALL) || defined(WOLFSSL_IP_ALT_NAME)
  74706. #if defined(WC_DISABLE_RADIX_ZERO_PAD)
  74707. /* Will print IP address subject alt name. */
  74708. ExpectIntEQ(BIO_get_mem_data(bio, NULL), 3349);
  74709. #elif defined(NO_ASN_TIME)
  74710. /* Will print IP address subject alt name but not Validity. */
  74711. ExpectIntEQ(BIO_get_mem_data(bio, NULL), 3235);
  74712. #else
  74713. /* Will print IP address subject alt name. */
  74714. ExpectIntEQ(BIO_get_mem_data(bio, NULL), 3350);
  74715. #endif
  74716. #elif defined(NO_ASN_TIME)
  74717. /* With NO_ASN_TIME defined, X509_print skips printing Validity. */
  74718. ExpectIntEQ(BIO_get_mem_data(bio, NULL), 3213);
  74719. #else
  74720. ExpectIntEQ(BIO_get_mem_data(bio, NULL), 3328);
  74721. #endif
  74722. BIO_free(bio);
  74723. bio = NULL;
  74724. ExpectNotNull(bio = BIO_new_fd(STDERR_FILENO, BIO_NOCLOSE));
  74725. #if defined(OPENSSL_ALL) && !defined(NO_WOLFSSL_DIR)
  74726. /* Print signature */
  74727. ExpectNotNull(cert_sig_alg = X509_get0_tbs_sigalg(x509));
  74728. ExpectIntEQ(X509_signature_print(bio, cert_sig_alg, NULL), SSL_SUCCESS);
  74729. #endif
  74730. /* print to stderr */
  74731. #if !defined(NO_WOLFSSL_DIR)
  74732. ExpectIntEQ(X509_print(bio, x509), SSL_SUCCESS);
  74733. #endif
  74734. /* print again */
  74735. ExpectIntEQ(X509_print_fp(stderr, x509), SSL_SUCCESS);
  74736. X509_free(x509);
  74737. BIO_free(bio);
  74738. #endif
  74739. return EXPECT_RESULT();
  74740. }
  74741. static int test_wolfSSL_X509_CRL_print(void)
  74742. {
  74743. EXPECT_DECLS;
  74744. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && defined(HAVE_CRL)\
  74745. && !defined(NO_FILESYSTEM) && defined(XSNPRINTF)
  74746. X509_CRL* crl = NULL;
  74747. BIO *bio = NULL;
  74748. XFILE fp = XBADFILE;
  74749. ExpectTrue((fp = XFOPEN("./certs/crl/crl.pem", "rb")) != XBADFILE);
  74750. ExpectNotNull(crl = (X509_CRL*)PEM_read_X509_CRL(fp, (X509_CRL **)NULL,
  74751. NULL, NULL));
  74752. if (fp != XBADFILE)
  74753. XFCLOSE(fp);
  74754. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  74755. ExpectIntEQ(X509_CRL_print(bio, crl), SSL_SUCCESS);
  74756. X509_CRL_free(crl);
  74757. BIO_free(bio);
  74758. #endif
  74759. return EXPECT_RESULT();
  74760. }
  74761. static int test_wolfSSL_BIO_get_len(void)
  74762. {
  74763. EXPECT_DECLS;
  74764. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  74765. BIO *bio = NULL;
  74766. const char txt[] = "Some example text to push to the BIO.";
  74767. ExpectIntEQ(wolfSSL_BIO_get_len(bio), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  74768. ExpectNotNull(bio = wolfSSL_BIO_new(wolfSSL_BIO_s_mem()));
  74769. ExpectIntEQ(wolfSSL_BIO_write(bio, txt, sizeof(txt)), sizeof(txt));
  74770. ExpectIntEQ(wolfSSL_BIO_get_len(bio), sizeof(txt));
  74771. BIO_free(bio);
  74772. bio = NULL;
  74773. ExpectNotNull(bio = BIO_new_fd(STDERR_FILENO, BIO_NOCLOSE));
  74774. ExpectIntEQ(wolfSSL_BIO_get_len(bio), WC_NO_ERR_TRACE(WOLFSSL_BAD_FILE));
  74775. BIO_free(bio);
  74776. #endif
  74777. return EXPECT_RESULT();
  74778. }
  74779. #endif /* !NO_BIO */
  74780. static int test_wolfSSL_RSA(void)
  74781. {
  74782. EXPECT_DECLS;
  74783. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  74784. RSA* rsa = NULL;
  74785. const BIGNUM *n = NULL;
  74786. const BIGNUM *e = NULL;
  74787. const BIGNUM *d = NULL;
  74788. const BIGNUM *p = NULL;
  74789. const BIGNUM *q = NULL;
  74790. const BIGNUM *dmp1 = NULL;
  74791. const BIGNUM *dmq1 = NULL;
  74792. const BIGNUM *iqmp = NULL;
  74793. ExpectNotNull(rsa = RSA_new());
  74794. ExpectIntEQ(RSA_size(NULL), 0);
  74795. ExpectIntEQ(RSA_size(rsa), 0);
  74796. ExpectIntEQ(RSA_set0_key(rsa, NULL, NULL, NULL), 0);
  74797. ExpectIntEQ(RSA_set0_crt_params(rsa, NULL, NULL, NULL), 0);
  74798. ExpectIntEQ(RSA_set0_factors(rsa, NULL, NULL), 0);
  74799. #ifdef WOLFSSL_RSA_KEY_CHECK
  74800. ExpectIntEQ(RSA_check_key(rsa), 0);
  74801. #endif
  74802. RSA_free(rsa);
  74803. rsa = NULL;
  74804. ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  74805. ExpectIntEQ(RSA_size(rsa), 256);
  74806. #if (!defined(HAVE_FIPS) || FIPS_VERSION3_GT(6,0,0)) && !defined(HAVE_SELFTEST)
  74807. {
  74808. /* Test setting only subset of parameters */
  74809. RSA *rsa2 = NULL;
  74810. unsigned char hash[SHA256_DIGEST_LENGTH];
  74811. unsigned char signature[2048/8];
  74812. unsigned int signatureLen = 0;
  74813. XMEMSET(hash, 0, sizeof(hash));
  74814. RSA_get0_key(rsa, &n, &e, &d);
  74815. RSA_get0_factors(rsa, &p, &q);
  74816. RSA_get0_crt_params(rsa, &dmp1, &dmq1, &iqmp);
  74817. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  74818. &signatureLen, rsa), 1);
  74819. /* Quick sanity check */
  74820. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  74821. signatureLen, rsa), 1);
  74822. /* Verifying */
  74823. ExpectNotNull(rsa2 = RSA_new());
  74824. ExpectIntEQ(RSA_set0_key(rsa2, BN_dup(n), BN_dup(e), NULL), 1);
  74825. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  74826. signatureLen, rsa2), 1);
  74827. ExpectIntEQ(RSA_set0_factors(rsa2, BN_dup(p), BN_dup(q)), 1);
  74828. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  74829. signatureLen, rsa2), 1);
  74830. ExpectIntEQ(RSA_set0_crt_params(rsa2, BN_dup(dmp1), BN_dup(dmq1),
  74831. BN_dup(iqmp)), 1);
  74832. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  74833. signatureLen, rsa2), 1);
  74834. RSA_free(rsa2);
  74835. rsa2 = NULL;
  74836. /* Signing */
  74837. XMEMSET(signature, 0, sizeof(signature));
  74838. ExpectNotNull(rsa2 = RSA_new());
  74839. ExpectIntEQ(RSA_set0_key(rsa2, BN_dup(n), BN_dup(e), BN_dup(d)), 1);
  74840. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  74841. &signatureLen, rsa2), 1);
  74842. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  74843. signatureLen, rsa), 1);
  74844. ExpectIntEQ(RSA_set0_factors(rsa2, BN_dup(p), BN_dup(q)), 1);
  74845. XMEMSET(signature, 0, sizeof(signature));
  74846. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  74847. &signatureLen, rsa2), 1);
  74848. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  74849. signatureLen, rsa), 1);
  74850. ExpectIntEQ(RSA_set0_crt_params(rsa2, BN_dup(dmp1), BN_dup(dmq1),
  74851. BN_dup(iqmp)), 1);
  74852. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  74853. &signatureLen, rsa2), 1);
  74854. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  74855. signatureLen, rsa), 1);
  74856. RSA_free(rsa2);
  74857. rsa2 = NULL;
  74858. }
  74859. #endif
  74860. #ifdef WOLFSSL_RSA_KEY_CHECK
  74861. ExpectIntEQ(RSA_check_key(NULL), 0);
  74862. ExpectIntEQ(RSA_check_key(rsa), 1);
  74863. #endif
  74864. /* sanity check */
  74865. ExpectIntEQ(RSA_bits(NULL), 0);
  74866. /* key */
  74867. ExpectIntEQ(RSA_bits(rsa), 2048);
  74868. RSA_get0_key(rsa, &n, &e, &d);
  74869. ExpectPtrEq(rsa->n, n);
  74870. ExpectPtrEq(rsa->e, e);
  74871. ExpectPtrEq(rsa->d, d);
  74872. n = NULL;
  74873. e = NULL;
  74874. d = NULL;
  74875. ExpectNotNull(n = BN_new());
  74876. ExpectNotNull(e = BN_new());
  74877. ExpectNotNull(d = BN_new());
  74878. ExpectIntEQ(RSA_set0_key(rsa, (BIGNUM*)n, (BIGNUM*)e, (BIGNUM*)d), 1);
  74879. if (EXPECT_FAIL()) {
  74880. BN_free((BIGNUM*)n);
  74881. BN_free((BIGNUM*)e);
  74882. BN_free((BIGNUM*)d);
  74883. }
  74884. ExpectPtrEq(rsa->n, n);
  74885. ExpectPtrEq(rsa->e, e);
  74886. ExpectPtrEq(rsa->d, d);
  74887. ExpectIntEQ(RSA_set0_key(rsa, NULL, NULL, NULL), 1);
  74888. ExpectIntEQ(RSA_set0_key(NULL, (BIGNUM*)n, (BIGNUM*)e, (BIGNUM*)d), 0);
  74889. /* crt_params */
  74890. RSA_get0_crt_params(rsa, &dmp1, &dmq1, &iqmp);
  74891. ExpectPtrEq(rsa->dmp1, dmp1);
  74892. ExpectPtrEq(rsa->dmq1, dmq1);
  74893. ExpectPtrEq(rsa->iqmp, iqmp);
  74894. dmp1 = NULL;
  74895. dmq1 = NULL;
  74896. iqmp = NULL;
  74897. ExpectNotNull(dmp1 = BN_new());
  74898. ExpectNotNull(dmq1 = BN_new());
  74899. ExpectNotNull(iqmp = BN_new());
  74900. ExpectIntEQ(RSA_set0_crt_params(rsa, (BIGNUM*)dmp1, (BIGNUM*)dmq1,
  74901. (BIGNUM*)iqmp), 1);
  74902. if (EXPECT_FAIL()) {
  74903. BN_free((BIGNUM*)dmp1);
  74904. BN_free((BIGNUM*)dmq1);
  74905. BN_free((BIGNUM*)iqmp);
  74906. }
  74907. ExpectPtrEq(rsa->dmp1, dmp1);
  74908. ExpectPtrEq(rsa->dmq1, dmq1);
  74909. ExpectPtrEq(rsa->iqmp, iqmp);
  74910. ExpectIntEQ(RSA_set0_crt_params(rsa, NULL, NULL, NULL), 1);
  74911. ExpectIntEQ(RSA_set0_crt_params(NULL, (BIGNUM*)dmp1, (BIGNUM*)dmq1,
  74912. (BIGNUM*)iqmp), 0);
  74913. RSA_get0_crt_params(NULL, NULL, NULL, NULL);
  74914. RSA_get0_crt_params(rsa, NULL, NULL, NULL);
  74915. RSA_get0_crt_params(NULL, &dmp1, &dmq1, &iqmp);
  74916. ExpectNull(dmp1);
  74917. ExpectNull(dmq1);
  74918. ExpectNull(iqmp);
  74919. /* factors */
  74920. RSA_get0_factors(rsa, NULL, NULL);
  74921. RSA_get0_factors(rsa, &p, &q);
  74922. ExpectPtrEq(rsa->p, p);
  74923. ExpectPtrEq(rsa->q, q);
  74924. p = NULL;
  74925. q = NULL;
  74926. ExpectNotNull(p = BN_new());
  74927. ExpectNotNull(q = BN_new());
  74928. ExpectIntEQ(RSA_set0_factors(rsa, (BIGNUM*)p, (BIGNUM*)q), 1);
  74929. if (EXPECT_FAIL()) {
  74930. BN_free((BIGNUM*)p);
  74931. BN_free((BIGNUM*)q);
  74932. }
  74933. ExpectPtrEq(rsa->p, p);
  74934. ExpectPtrEq(rsa->q, q);
  74935. ExpectIntEQ(RSA_set0_factors(rsa, NULL, NULL), 1);
  74936. ExpectIntEQ(RSA_set0_factors(NULL, (BIGNUM*)p, (BIGNUM*)q), 0);
  74937. RSA_get0_factors(NULL, NULL, NULL);
  74938. RSA_get0_factors(NULL, &p, &q);
  74939. ExpectNull(p);
  74940. ExpectNull(q);
  74941. ExpectIntEQ(BN_hex2bn(&rsa->n, "1FFFFF"), 1);
  74942. ExpectIntEQ(RSA_bits(rsa), 21);
  74943. RSA_free(rsa);
  74944. rsa = NULL;
  74945. #if !defined(USE_FAST_MATH) || (FP_MAX_BITS >= (3072*2))
  74946. ExpectNotNull(rsa = RSA_generate_key(3072, 17, NULL, NULL));
  74947. ExpectIntEQ(RSA_size(rsa), 384);
  74948. ExpectIntEQ(RSA_bits(rsa), 3072);
  74949. RSA_free(rsa);
  74950. rsa = NULL;
  74951. #endif
  74952. /* remove for now with odd key size until adjusting rsa key size check with
  74953. wc_MakeRsaKey()
  74954. ExpectNotNull(rsa = RSA_generate_key(2999, 65537, NULL, NULL));
  74955. RSA_free(rsa);
  74956. rsa = NULL;
  74957. */
  74958. ExpectNull(RSA_generate_key(-1, 3, NULL, NULL));
  74959. ExpectNull(RSA_generate_key(RSA_MIN_SIZE - 1, 3, NULL, NULL));
  74960. ExpectNull(RSA_generate_key(RSA_MAX_SIZE + 1, 3, NULL, NULL));
  74961. ExpectNull(RSA_generate_key(2048, 0, NULL, NULL));
  74962. #if !defined(NO_FILESYSTEM) && !defined(NO_ASN)
  74963. {
  74964. byte buff[FOURK_BUF];
  74965. byte der[FOURK_BUF];
  74966. const char PrivKeyPemFile[] = "certs/client-keyEnc.pem";
  74967. XFILE f = XBADFILE;
  74968. int bytes = 0;
  74969. /* test loading encrypted RSA private pem w/o password */
  74970. ExpectTrue((f = XFOPEN(PrivKeyPemFile, "rb")) != XBADFILE);
  74971. ExpectIntGT(bytes = (int)XFREAD(buff, 1, sizeof(buff), f), 0);
  74972. if (f != XBADFILE)
  74973. XFCLOSE(f);
  74974. XMEMSET(der, 0, sizeof(der));
  74975. /* test that error value is returned with no password */
  74976. ExpectIntLT(wc_KeyPemToDer(buff, bytes, der, (word32)sizeof(der), ""),
  74977. 0);
  74978. }
  74979. #endif
  74980. #endif
  74981. return EXPECT_RESULT();
  74982. }
  74983. static int test_wolfSSL_RSA_DER(void)
  74984. {
  74985. EXPECT_DECLS;
  74986. #if defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA) && defined(OPENSSL_EXTRA)
  74987. RSA *rsa = NULL;
  74988. int i;
  74989. const unsigned char *buff = NULL;
  74990. unsigned char *newBuff = NULL;
  74991. struct tbl_s
  74992. {
  74993. const unsigned char *der;
  74994. int sz;
  74995. } tbl[] = {
  74996. #ifdef USE_CERT_BUFFERS_1024
  74997. {client_key_der_1024, sizeof_client_key_der_1024},
  74998. {server_key_der_1024, sizeof_server_key_der_1024},
  74999. #endif
  75000. #ifdef USE_CERT_BUFFERS_2048
  75001. {client_key_der_2048, sizeof_client_key_der_2048},
  75002. {server_key_der_2048, sizeof_server_key_der_2048},
  75003. #endif
  75004. {NULL, 0}
  75005. };
  75006. /* Public Key DER */
  75007. struct tbl_s pub[] = {
  75008. #ifdef USE_CERT_BUFFERS_1024
  75009. {client_keypub_der_1024, sizeof_client_keypub_der_1024},
  75010. #endif
  75011. #ifdef USE_CERT_BUFFERS_2048
  75012. {client_keypub_der_2048, sizeof_client_keypub_der_2048},
  75013. #endif
  75014. {NULL, 0}
  75015. };
  75016. ExpectNull(d2i_RSAPublicKey(&rsa, NULL, pub[0].sz));
  75017. buff = pub[0].der;
  75018. ExpectNull(d2i_RSAPublicKey(&rsa, &buff, 1));
  75019. ExpectNull(d2i_RSAPrivateKey(&rsa, NULL, tbl[0].sz));
  75020. buff = tbl[0].der;
  75021. ExpectNull(d2i_RSAPrivateKey(&rsa, &buff, 1));
  75022. ExpectIntEQ(i2d_RSAPublicKey(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  75023. rsa = RSA_new();
  75024. ExpectIntEQ(i2d_RSAPublicKey(rsa, NULL), 0);
  75025. RSA_free(rsa);
  75026. rsa = NULL;
  75027. for (i = 0; tbl[i].der != NULL; i++)
  75028. {
  75029. /* Passing in pointer results in pointer moving. */
  75030. buff = tbl[i].der;
  75031. ExpectNotNull(d2i_RSAPublicKey(&rsa, &buff, tbl[i].sz));
  75032. ExpectNotNull(rsa);
  75033. RSA_free(rsa);
  75034. rsa = NULL;
  75035. }
  75036. for (i = 0; tbl[i].der != NULL; i++)
  75037. {
  75038. /* Passing in pointer results in pointer moving. */
  75039. buff = tbl[i].der;
  75040. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &buff, tbl[i].sz));
  75041. ExpectNotNull(rsa);
  75042. RSA_free(rsa);
  75043. rsa = NULL;
  75044. }
  75045. for (i = 0; pub[i].der != NULL; i++)
  75046. {
  75047. buff = pub[i].der;
  75048. ExpectNotNull(d2i_RSAPublicKey(&rsa, &buff, pub[i].sz));
  75049. ExpectNotNull(rsa);
  75050. ExpectIntEQ(i2d_RSAPublicKey(rsa, NULL), pub[i].sz);
  75051. newBuff = NULL;
  75052. ExpectIntEQ(i2d_RSAPublicKey(rsa, &newBuff), pub[i].sz);
  75053. ExpectNotNull(newBuff);
  75054. ExpectIntEQ(XMEMCMP((void *)newBuff, (void *)pub[i].der, pub[i].sz), 0);
  75055. XFREE((void *)newBuff, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  75056. RSA_free(rsa);
  75057. rsa = NULL;
  75058. }
  75059. #endif
  75060. return EXPECT_RESULT();
  75061. }
  75062. static int test_wolfSSL_RSA_print(void)
  75063. {
  75064. EXPECT_DECLS;
  75065. #if defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && \
  75066. !defined(NO_STDIO_FILESYSTEM) && \
  75067. !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && \
  75068. !defined(NO_BIO) && defined(XFPRINTF)
  75069. BIO *bio = NULL;
  75070. WOLFSSL_RSA* rsa = NULL;
  75071. ExpectNotNull(bio = BIO_new_fd(STDERR_FILENO, BIO_NOCLOSE));
  75072. ExpectNotNull(rsa = RSA_new());
  75073. ExpectIntEQ(RSA_print(NULL, rsa, 0), -1);
  75074. ExpectIntEQ(RSA_print_fp(XBADFILE, rsa, 0), 0);
  75075. ExpectIntEQ(RSA_print(bio, NULL, 0), -1);
  75076. ExpectIntEQ(RSA_print_fp(stderr, NULL, 0), 0);
  75077. /* Some very large number of indent spaces. */
  75078. ExpectIntEQ(RSA_print(bio, rsa, 128), -1);
  75079. /* RSA is empty. */
  75080. ExpectIntEQ(RSA_print(bio, rsa, 0), 0);
  75081. ExpectIntEQ(RSA_print_fp(stderr, rsa, 0), 0);
  75082. RSA_free(rsa);
  75083. rsa = NULL;
  75084. ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  75085. ExpectIntEQ(RSA_print(bio, rsa, 0), 1);
  75086. ExpectIntEQ(RSA_print(bio, rsa, 4), 1);
  75087. ExpectIntEQ(RSA_print(bio, rsa, -1), 1);
  75088. ExpectIntEQ(RSA_print_fp(stderr, rsa, 0), 1);
  75089. ExpectIntEQ(RSA_print_fp(stderr, rsa, 4), 1);
  75090. ExpectIntEQ(RSA_print_fp(stderr, rsa, -1), 1);
  75091. BIO_free(bio);
  75092. RSA_free(rsa);
  75093. #endif
  75094. return EXPECT_RESULT();
  75095. }
  75096. static int test_wolfSSL_RSA_padding_add_PKCS1_PSS(void)
  75097. {
  75098. EXPECT_DECLS;
  75099. #ifndef NO_RSA
  75100. #if defined(OPENSSL_ALL) && defined(WC_RSA_PSS) && !defined(WC_NO_RNG)
  75101. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  75102. RSA *rsa = NULL;
  75103. const unsigned char *derBuf = client_key_der_2048;
  75104. unsigned char em[256] = {0}; /* len = 2048/8 */
  75105. /* Random data simulating a hash */
  75106. const unsigned char mHash[WC_SHA256_DIGEST_SIZE] = {
  75107. 0x28, 0x6e, 0xfd, 0xf8, 0x76, 0xc7, 0x00, 0x3d, 0x91, 0x4e, 0x59, 0xe4,
  75108. 0x8e, 0xb7, 0x40, 0x7b, 0xd1, 0x0c, 0x98, 0x4b, 0xe3, 0x3d, 0xb3, 0xeb,
  75109. 0x6f, 0x8a, 0x3c, 0x42, 0xab, 0x21, 0xad, 0x28
  75110. };
  75111. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &derBuf, sizeof_client_key_der_2048));
  75112. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(NULL, em, mHash, EVP_sha256(),
  75113. RSA_PSS_SALTLEN_DIGEST), 0);
  75114. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, NULL, mHash, EVP_sha256(),
  75115. RSA_PSS_SALTLEN_DIGEST), 0);
  75116. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, NULL, EVP_sha256(),
  75117. RSA_PSS_SALTLEN_DIGEST), 0);
  75118. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, NULL,
  75119. RSA_PSS_SALTLEN_DIGEST), 0);
  75120. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, EVP_sha256(), -5), 0);
  75121. ExpectIntEQ(RSA_verify_PKCS1_PSS(NULL, mHash, EVP_sha256(), em,
  75122. RSA_PSS_SALTLEN_MAX_SIGN), 0);
  75123. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, NULL, EVP_sha256(), em,
  75124. RSA_PSS_SALTLEN_MAX_SIGN), 0);
  75125. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, NULL, em,
  75126. RSA_PSS_SALTLEN_MAX_SIGN), 0);
  75127. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), NULL,
  75128. RSA_PSS_SALTLEN_MAX_SIGN), 0);
  75129. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em,
  75130. RSA_PSS_SALTLEN_MAX_SIGN), 0);
  75131. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em, -5), 0);
  75132. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, EVP_sha256(),
  75133. RSA_PSS_SALTLEN_DIGEST), 1);
  75134. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em,
  75135. RSA_PSS_SALTLEN_DIGEST), 1);
  75136. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, EVP_sha256(),
  75137. RSA_PSS_SALTLEN_MAX_SIGN), 1);
  75138. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em,
  75139. RSA_PSS_SALTLEN_MAX_SIGN), 1);
  75140. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, EVP_sha256(),
  75141. RSA_PSS_SALTLEN_MAX), 1);
  75142. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em,
  75143. RSA_PSS_SALTLEN_MAX), 1);
  75144. ExpectIntEQ(RSA_padding_add_PKCS1_PSS(rsa, em, mHash, EVP_sha256(), 10), 1);
  75145. ExpectIntEQ(RSA_verify_PKCS1_PSS(rsa, mHash, EVP_sha256(), em, 10), 1);
  75146. RSA_free(rsa);
  75147. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  75148. #endif /* OPENSSL_ALL && WC_RSA_PSS && !WC_NO_RNG*/
  75149. #endif
  75150. return EXPECT_RESULT();
  75151. }
  75152. static int test_wolfSSL_RSA_sign_sha3(void)
  75153. {
  75154. EXPECT_DECLS;
  75155. #if !defined(NO_RSA) && defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
  75156. #if defined(OPENSSL_ALL) && defined(WC_RSA_PSS) && !defined(WC_NO_RNG)
  75157. RSA* rsa = NULL;
  75158. const unsigned char *derBuf = client_key_der_2048;
  75159. unsigned char sigRet[256] = {0};
  75160. unsigned int sigLen = sizeof(sigRet);
  75161. /* Random data simulating a hash */
  75162. const unsigned char mHash[WC_SHA3_256_DIGEST_SIZE] = {
  75163. 0x28, 0x6e, 0xfd, 0xf8, 0x76, 0xc7, 0x00, 0x3d, 0x91, 0x4e, 0x59, 0xe4,
  75164. 0x8e, 0xb7, 0x40, 0x7b, 0xd1, 0x0c, 0x98, 0x4b, 0xe3, 0x3d, 0xb3, 0xeb,
  75165. 0x6f, 0x8a, 0x3c, 0x42, 0xab, 0x21, 0xad, 0x28
  75166. };
  75167. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &derBuf, sizeof_client_key_der_2048));
  75168. ExpectIntEQ(RSA_sign(NID_sha3_256, mHash, sizeof(mHash), sigRet, &sigLen,
  75169. rsa), 1);
  75170. RSA_free(rsa);
  75171. #endif /* OPENSSL_ALL && WC_RSA_PSS && !WC_NO_RNG*/
  75172. #endif /* !NO_RSA && WOLFSSL_SHA3 && !WOLFSSL_NOSHA3_256*/
  75173. return EXPECT_RESULT();
  75174. }
  75175. static int test_wolfSSL_RSA_get0_key(void)
  75176. {
  75177. EXPECT_DECLS;
  75178. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  75179. RSA *rsa = NULL;
  75180. const BIGNUM* n = NULL;
  75181. const BIGNUM* e = NULL;
  75182. const BIGNUM* d = NULL;
  75183. const unsigned char* der;
  75184. int derSz;
  75185. #ifdef USE_CERT_BUFFERS_1024
  75186. der = client_key_der_1024;
  75187. derSz = sizeof_client_key_der_1024;
  75188. #elif defined(USE_CERT_BUFFERS_2048)
  75189. der = client_key_der_2048;
  75190. derSz = sizeof_client_key_der_2048;
  75191. #else
  75192. der = NULL;
  75193. derSz = 0;
  75194. #endif
  75195. if (der != NULL) {
  75196. RSA_get0_key(NULL, NULL, NULL, NULL);
  75197. RSA_get0_key(rsa, NULL, NULL, NULL);
  75198. RSA_get0_key(NULL, &n, &e, &d);
  75199. ExpectNull(n);
  75200. ExpectNull(e);
  75201. ExpectNull(d);
  75202. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, derSz));
  75203. ExpectNotNull(rsa);
  75204. RSA_get0_key(rsa, NULL, NULL, NULL);
  75205. RSA_get0_key(rsa, &n, NULL, NULL);
  75206. ExpectNotNull(n);
  75207. RSA_get0_key(rsa, NULL, &e, NULL);
  75208. ExpectNotNull(e);
  75209. RSA_get0_key(rsa, NULL, NULL, &d);
  75210. ExpectNotNull(d);
  75211. RSA_get0_key(rsa, &n, &e, &d);
  75212. ExpectNotNull(n);
  75213. ExpectNotNull(e);
  75214. ExpectNotNull(d);
  75215. RSA_free(rsa);
  75216. }
  75217. #endif
  75218. return EXPECT_RESULT();
  75219. }
  75220. static int test_wolfSSL_RSA_meth(void)
  75221. {
  75222. EXPECT_DECLS;
  75223. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  75224. RSA *rsa = NULL;
  75225. RSA_METHOD *rsa_meth = NULL;
  75226. #ifdef WOLFSSL_KEY_GEN
  75227. ExpectNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  75228. RSA_free(rsa);
  75229. rsa = NULL;
  75230. #else
  75231. ExpectNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
  75232. #endif
  75233. ExpectNotNull(RSA_get_default_method());
  75234. wolfSSL_RSA_meth_free(NULL);
  75235. ExpectNull(wolfSSL_RSA_meth_new(NULL, 0));
  75236. ExpectNotNull(rsa_meth = RSA_meth_new("placeholder RSA method",
  75237. RSA_METHOD_FLAG_NO_CHECK));
  75238. #ifndef NO_WOLFSSL_STUB
  75239. ExpectIntEQ(RSA_meth_set_pub_enc(rsa_meth, NULL), 1);
  75240. ExpectIntEQ(RSA_meth_set_pub_dec(rsa_meth, NULL), 1);
  75241. ExpectIntEQ(RSA_meth_set_priv_enc(rsa_meth, NULL), 1);
  75242. ExpectIntEQ(RSA_meth_set_priv_dec(rsa_meth, NULL), 1);
  75243. ExpectIntEQ(RSA_meth_set_init(rsa_meth, NULL), 1);
  75244. ExpectIntEQ(RSA_meth_set_finish(rsa_meth, NULL), 1);
  75245. ExpectIntEQ(RSA_meth_set0_app_data(rsa_meth, NULL), 1);
  75246. #endif
  75247. ExpectIntEQ(RSA_flags(NULL), 0);
  75248. RSA_set_flags(NULL, RSA_FLAG_CACHE_PUBLIC);
  75249. RSA_clear_flags(NULL, RSA_FLAG_CACHE_PUBLIC);
  75250. ExpectIntEQ(RSA_test_flags(NULL, RSA_FLAG_CACHE_PUBLIC), 0);
  75251. ExpectNotNull(rsa = RSA_new());
  75252. /* No method set. */
  75253. ExpectIntEQ(RSA_flags(rsa), 0);
  75254. RSA_set_flags(rsa, RSA_FLAG_CACHE_PUBLIC);
  75255. RSA_clear_flags(rsa, RSA_FLAG_CACHE_PUBLIC);
  75256. ExpectIntEQ(RSA_test_flags(rsa, RSA_FLAG_CACHE_PUBLIC), 0);
  75257. ExpectIntEQ(RSA_set_method(NULL, rsa_meth), 1);
  75258. ExpectIntEQ(RSA_set_method(rsa, rsa_meth), 1);
  75259. if (EXPECT_FAIL()) {
  75260. wolfSSL_RSA_meth_free(rsa_meth);
  75261. }
  75262. ExpectNull(RSA_get_method(NULL));
  75263. ExpectPtrEq(RSA_get_method(rsa), rsa_meth);
  75264. ExpectIntEQ(RSA_flags(rsa), RSA_METHOD_FLAG_NO_CHECK);
  75265. RSA_set_flags(rsa, RSA_FLAG_CACHE_PUBLIC);
  75266. ExpectIntNE(RSA_test_flags(rsa, RSA_FLAG_CACHE_PUBLIC), 0);
  75267. ExpectIntEQ(RSA_flags(rsa), RSA_FLAG_CACHE_PUBLIC |
  75268. RSA_METHOD_FLAG_NO_CHECK);
  75269. RSA_clear_flags(rsa, RSA_FLAG_CACHE_PUBLIC);
  75270. ExpectIntEQ(RSA_test_flags(rsa, RSA_FLAG_CACHE_PUBLIC), 0);
  75271. ExpectIntNE(RSA_flags(rsa), RSA_FLAG_CACHE_PUBLIC);
  75272. /* rsa_meth is freed here */
  75273. RSA_free(rsa);
  75274. #endif
  75275. return EXPECT_RESULT();
  75276. }
  75277. static int test_wolfSSL_RSA_verify(void)
  75278. {
  75279. EXPECT_DECLS;
  75280. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_FILESYSTEM)
  75281. #ifndef NO_BIO
  75282. XFILE fp = XBADFILE;
  75283. RSA *pKey = NULL;
  75284. RSA *pubKey = NULL;
  75285. X509 *cert = NULL;
  75286. const char *text = "Hello wolfSSL !";
  75287. unsigned char hash[SHA256_DIGEST_LENGTH];
  75288. unsigned char signature[2048/8];
  75289. unsigned int signatureLength;
  75290. byte *buf = NULL;
  75291. BIO *bio = NULL;
  75292. SHA256_CTX c;
  75293. EVP_PKEY *evpPkey = NULL;
  75294. EVP_PKEY *evpPubkey = NULL;
  75295. size_t sz;
  75296. /* generate hash */
  75297. SHA256_Init(&c);
  75298. SHA256_Update(&c, text, strlen(text));
  75299. SHA256_Final(hash, &c);
  75300. #ifdef WOLFSSL_SMALL_STACK_CACHE
  75301. /* workaround for small stack cache case */
  75302. wc_Sha256Free((wc_Sha256*)&c);
  75303. #endif
  75304. /* read privete key file */
  75305. ExpectTrue((fp = XFOPEN(svrKeyFile, "rb")) != XBADFILE);
  75306. ExpectIntEQ(XFSEEK(fp, 0, XSEEK_END), 0);
  75307. ExpectTrue((sz = XFTELL(fp)) > 0);
  75308. ExpectIntEQ(XFSEEK(fp, 0, XSEEK_SET), 0);
  75309. ExpectNotNull(buf = (byte*)XMALLOC(sz, NULL, DYNAMIC_TYPE_FILE));
  75310. ExpectIntEQ(XFREAD(buf, 1, sz, fp), sz);
  75311. if (fp != XBADFILE) {
  75312. XFCLOSE(fp);
  75313. fp = XBADFILE;
  75314. }
  75315. /* read private key and sign hash data */
  75316. ExpectNotNull(bio = BIO_new_mem_buf(buf, (int)sz));
  75317. ExpectNotNull(evpPkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL));
  75318. ExpectNotNull(pKey = EVP_PKEY_get1_RSA(evpPkey));
  75319. ExpectIntEQ(RSA_sign(NID_sha256, hash, SHA256_DIGEST_LENGTH,
  75320. signature, &signatureLength, pKey), SSL_SUCCESS);
  75321. /* read public key and verify signed data */
  75322. ExpectTrue((fp = XFOPEN(svrCertFile,"rb")) != XBADFILE);
  75323. ExpectNotNull(cert = PEM_read_X509(fp, 0, 0, 0 ));
  75324. if (fp != XBADFILE)
  75325. XFCLOSE(fp);
  75326. ExpectNotNull(evpPubkey = X509_get_pubkey(cert));
  75327. ExpectNotNull(pubKey = EVP_PKEY_get1_RSA(evpPubkey));
  75328. ExpectIntEQ(RSA_verify(NID_sha256, hash, SHA256_DIGEST_LENGTH, signature,
  75329. signatureLength, pubKey), SSL_SUCCESS);
  75330. ExpectIntEQ(RSA_verify(NID_sha256, NULL, SHA256_DIGEST_LENGTH, NULL,
  75331. signatureLength, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  75332. ExpectIntEQ(RSA_verify(NID_sha256, NULL, SHA256_DIGEST_LENGTH, signature,
  75333. signatureLength, pubKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  75334. ExpectIntEQ(RSA_verify(NID_sha256, hash, SHA256_DIGEST_LENGTH, NULL,
  75335. signatureLength, pubKey), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  75336. ExpectIntEQ(RSA_verify(NID_sha256, hash, SHA256_DIGEST_LENGTH, signature,
  75337. signatureLength, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  75338. RSA_free(pKey);
  75339. EVP_PKEY_free(evpPkey);
  75340. RSA_free(pubKey);
  75341. EVP_PKEY_free(evpPubkey);
  75342. X509_free(cert);
  75343. BIO_free(bio);
  75344. XFREE(buf, NULL, DYNAMIC_TYPE_FILE);
  75345. #endif
  75346. #endif
  75347. return EXPECT_RESULT();
  75348. }
  75349. static int test_wolfSSL_RSA_sign(void)
  75350. {
  75351. EXPECT_DECLS;
  75352. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  75353. RSA *rsa;
  75354. unsigned char hash[SHA256_DIGEST_LENGTH];
  75355. #ifdef USE_CERT_BUFFERS_1024
  75356. const unsigned char* privDer = client_key_der_1024;
  75357. size_t privDerSz = sizeof_client_key_der_1024;
  75358. const unsigned char* pubDer = client_keypub_der_1024;
  75359. size_t pubDerSz = sizeof_client_keypub_der_1024;
  75360. unsigned char signature[1024/8];
  75361. #else
  75362. const unsigned char* privDer = client_key_der_2048;
  75363. size_t privDerSz = sizeof_client_key_der_2048;
  75364. const unsigned char* pubDer = client_keypub_der_2048;
  75365. size_t pubDerSz = sizeof_client_keypub_der_2048;
  75366. unsigned char signature[2048/8];
  75367. #endif
  75368. unsigned int signatureLen;
  75369. const unsigned char* der;
  75370. XMEMSET(hash, 0, sizeof(hash));
  75371. der = privDer;
  75372. rsa = NULL;
  75373. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  75374. /* Invalid parameters. */
  75375. ExpectIntEQ(RSA_sign(NID_rsaEncryption, NULL, 0, NULL, NULL, NULL), 0);
  75376. ExpectIntEQ(RSA_sign(NID_rsaEncryption, hash, sizeof(hash), signature,
  75377. &signatureLen, rsa), 0);
  75378. ExpectIntEQ(RSA_sign(NID_sha256, NULL, sizeof(hash), signature,
  75379. &signatureLen, rsa), 0);
  75380. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), NULL,
  75381. &signatureLen, rsa), 0);
  75382. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  75383. NULL, rsa), 0);
  75384. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  75385. &signatureLen, NULL), 0);
  75386. ExpectIntEQ(RSA_sign(NID_sha256, hash, sizeof(hash), signature,
  75387. &signatureLen, rsa), 1);
  75388. RSA_free(rsa);
  75389. der = pubDer;
  75390. rsa = NULL;
  75391. ExpectNotNull(d2i_RSAPublicKey(&rsa, &der, pubDerSz));
  75392. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  75393. signatureLen, rsa), 1);
  75394. RSA_free(rsa);
  75395. #endif
  75396. return EXPECT_RESULT();
  75397. }
  75398. static int test_wolfSSL_RSA_sign_ex(void)
  75399. {
  75400. EXPECT_DECLS;
  75401. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  75402. RSA *rsa = NULL;
  75403. unsigned char hash[SHA256_DIGEST_LENGTH];
  75404. #ifdef USE_CERT_BUFFERS_1024
  75405. const unsigned char* privDer = client_key_der_1024;
  75406. size_t privDerSz = sizeof_client_key_der_1024;
  75407. const unsigned char* pubDer = client_keypub_der_1024;
  75408. size_t pubDerSz = sizeof_client_keypub_der_1024;
  75409. unsigned char signature[1024/8];
  75410. #else
  75411. const unsigned char* privDer = client_key_der_2048;
  75412. size_t privDerSz = sizeof_client_key_der_2048;
  75413. const unsigned char* pubDer = client_keypub_der_2048;
  75414. size_t pubDerSz = sizeof_client_keypub_der_2048;
  75415. unsigned char signature[2048/8];
  75416. #endif
  75417. unsigned int signatureLen;
  75418. const unsigned char* der;
  75419. unsigned char encodedHash[51];
  75420. unsigned int encodedHashLen;
  75421. const unsigned char expEncHash[] = {
  75422. 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
  75423. 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05,
  75424. 0x00, 0x04, 0x20,
  75425. /* Hash data */
  75426. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  75427. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  75428. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  75429. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  75430. };
  75431. XMEMSET(hash, 0, sizeof(hash));
  75432. ExpectNotNull(rsa = wolfSSL_RSA_new());
  75433. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  75434. &signatureLen, rsa, 1), 0);
  75435. wolfSSL_RSA_free(rsa);
  75436. der = privDer;
  75437. rsa = NULL;
  75438. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  75439. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_rsaEncryption,NULL, 0, NULL, NULL, NULL,
  75440. -1), 0);
  75441. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_rsaEncryption, hash, sizeof(hash),
  75442. signature, &signatureLen, rsa, 1), 0);
  75443. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, NULL, sizeof(hash), signature,
  75444. &signatureLen, rsa, 1), 0);
  75445. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), NULL,
  75446. &signatureLen, rsa, 1), 0);
  75447. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  75448. NULL, rsa, 1), 0);
  75449. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  75450. &signatureLen, NULL, 1), 0);
  75451. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  75452. &signatureLen, rsa, -1), 0);
  75453. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, NULL, sizeof(hash), signature,
  75454. &signatureLen, rsa, 0), 0);
  75455. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), NULL,
  75456. &signatureLen, rsa, 0), 0);
  75457. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  75458. NULL, rsa, 0), 0);
  75459. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), signature,
  75460. &signatureLen, rsa, 1), 1);
  75461. /* Test returning encoded hash. */
  75462. ExpectIntEQ(wolfSSL_RSA_sign_ex(NID_sha256, hash, sizeof(hash), encodedHash,
  75463. &encodedHashLen, rsa, 0), 1);
  75464. ExpectIntEQ(encodedHashLen, sizeof(expEncHash));
  75465. ExpectIntEQ(XMEMCMP(encodedHash, expEncHash, sizeof(expEncHash)), 0);
  75466. RSA_free(rsa);
  75467. der = pubDer;
  75468. rsa = NULL;
  75469. ExpectNotNull(d2i_RSAPublicKey(&rsa, &der, pubDerSz));
  75470. ExpectIntEQ(RSA_verify(NID_sha256, hash, sizeof(hash), signature,
  75471. signatureLen, rsa), 1);
  75472. RSA_free(rsa);
  75473. #endif
  75474. return EXPECT_RESULT();
  75475. }
  75476. static int test_wolfSSL_RSA_public_decrypt(void)
  75477. {
  75478. EXPECT_DECLS;
  75479. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  75480. RSA *rsa;
  75481. unsigned char msg[SHA256_DIGEST_LENGTH];
  75482. #ifdef USE_CERT_BUFFERS_1024
  75483. const unsigned char* pubDer = client_keypub_der_1024;
  75484. size_t pubDerSz = sizeof_client_keypub_der_1024;
  75485. unsigned char decMsg[1024/8];
  75486. const unsigned char encMsg[] = {
  75487. 0x45, 0x8e, 0x6e, 0x7a, 0x9c, 0xe1, 0x67, 0x36,
  75488. 0x72, 0xfc, 0x9d, 0x05, 0xdf, 0xc2, 0xaf, 0x54,
  75489. 0xc5, 0x2f, 0x94, 0xb8, 0xc7, 0x82, 0x40, 0xfa,
  75490. 0xa7, 0x8c, 0xb1, 0x89, 0x40, 0xc3, 0x59, 0x5a,
  75491. 0x77, 0x08, 0x54, 0x93, 0x43, 0x7f, 0xc4, 0xb7,
  75492. 0xc4, 0x78, 0xf1, 0xf8, 0xab, 0xbf, 0xc2, 0x81,
  75493. 0x5d, 0x97, 0xea, 0x7a, 0x60, 0x90, 0x51, 0xb7,
  75494. 0x47, 0x78, 0x48, 0x1e, 0x88, 0x6b, 0x89, 0xde,
  75495. 0xce, 0x41, 0x41, 0xae, 0x49, 0xf6, 0xfd, 0x2d,
  75496. 0x2d, 0x9c, 0x70, 0x7d, 0xf9, 0xcf, 0x77, 0x5f,
  75497. 0x06, 0xc7, 0x20, 0xe3, 0x57, 0xd4, 0xd8, 0x1a,
  75498. 0x96, 0xa2, 0x39, 0xb0, 0x6e, 0x8e, 0x68, 0xf8,
  75499. 0x57, 0x7b, 0x26, 0x88, 0x17, 0xc4, 0xb7, 0xf1,
  75500. 0x59, 0xfa, 0xb6, 0x95, 0xdd, 0x1e, 0xe8, 0xd8,
  75501. 0x4e, 0xbd, 0xcd, 0x41, 0xad, 0xc7, 0xe2, 0x39,
  75502. 0xb8, 0x00, 0xca, 0xf5, 0x59, 0xdf, 0xf8, 0x43
  75503. };
  75504. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  75505. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2)) && \
  75506. defined(WC_RSA_NO_PADDING)
  75507. const unsigned char encMsgNoPad[] = {
  75508. 0x0d, 0x41, 0x5a, 0xc7, 0x60, 0xd7, 0xbe, 0xb6,
  75509. 0x42, 0xd1, 0x65, 0xb1, 0x7e, 0x59, 0x54, 0xcc,
  75510. 0x76, 0x62, 0xd0, 0x2f, 0x4d, 0xe3, 0x23, 0x62,
  75511. 0xc8, 0x14, 0xfe, 0x5e, 0xa1, 0xc7, 0x05, 0xee,
  75512. 0x9e, 0x28, 0x2e, 0xf5, 0xfd, 0xa4, 0xc0, 0x43,
  75513. 0x55, 0xa2, 0x6b, 0x6b, 0x16, 0xa7, 0x63, 0x06,
  75514. 0xa7, 0x78, 0x4f, 0xda, 0xae, 0x10, 0x6d, 0xd1,
  75515. 0x2e, 0x1d, 0xbb, 0xbc, 0xc4, 0x1d, 0x82, 0xe4,
  75516. 0xc6, 0x76, 0x77, 0xa6, 0x0a, 0xef, 0xd2, 0x89,
  75517. 0xff, 0x30, 0x85, 0x22, 0xa0, 0x68, 0x88, 0x54,
  75518. 0xa3, 0xd1, 0x92, 0xd1, 0x3f, 0x57, 0xe4, 0xc7,
  75519. 0x43, 0x5a, 0x8b, 0xb3, 0x86, 0xaf, 0xd5, 0x6d,
  75520. 0x07, 0xe1, 0xa0, 0x5f, 0xe1, 0x9a, 0x06, 0xba,
  75521. 0x56, 0xd2, 0xb0, 0x73, 0xf5, 0xb3, 0xd0, 0x5f,
  75522. 0xc0, 0xbf, 0x22, 0x4c, 0x54, 0x4e, 0x11, 0xe2,
  75523. 0xc5, 0xf8, 0x66, 0x39, 0x9d, 0x70, 0x90, 0x31
  75524. };
  75525. #endif
  75526. #else
  75527. const unsigned char* pubDer = client_keypub_der_2048;
  75528. size_t pubDerSz = sizeof_client_keypub_der_2048;
  75529. unsigned char decMsg[2048/8];
  75530. const unsigned char encMsg[] = {
  75531. 0x16, 0x5d, 0xbb, 0x00, 0x38, 0x73, 0x01, 0x34,
  75532. 0xca, 0x59, 0xc6, 0x8b, 0x64, 0x70, 0x89, 0xf5,
  75533. 0x50, 0x2d, 0x1d, 0x69, 0x1f, 0x07, 0x1e, 0x31,
  75534. 0xae, 0x9b, 0xa6, 0x6e, 0xee, 0x80, 0xd9, 0x9e,
  75535. 0x59, 0x33, 0x70, 0x30, 0x28, 0x42, 0x7d, 0x24,
  75536. 0x36, 0x95, 0x6b, 0xf9, 0x0a, 0x23, 0xcb, 0xce,
  75537. 0x66, 0xa5, 0x07, 0x5e, 0x11, 0xa7, 0xdc, 0xfb,
  75538. 0xd9, 0xc2, 0x51, 0xf0, 0x05, 0xc9, 0x39, 0xb3,
  75539. 0xae, 0xff, 0xfb, 0xe9, 0xb1, 0x9a, 0x54, 0xac,
  75540. 0x1d, 0xca, 0x42, 0x1a, 0xfd, 0x7c, 0x97, 0xa0,
  75541. 0x60, 0x2b, 0xcd, 0xb6, 0x36, 0x33, 0xfc, 0x44,
  75542. 0x69, 0xf7, 0x2e, 0x8c, 0x3b, 0x5f, 0xb4, 0x9f,
  75543. 0xa7, 0x02, 0x8f, 0x6d, 0x6b, 0x79, 0x10, 0x32,
  75544. 0x7d, 0xf4, 0x5d, 0xa1, 0x63, 0x22, 0x59, 0xc4,
  75545. 0x44, 0x8e, 0x44, 0x24, 0x8b, 0x14, 0x9d, 0x2b,
  75546. 0xb5, 0xd3, 0xad, 0x9a, 0x87, 0x0d, 0xe7, 0x70,
  75547. 0x6d, 0xe9, 0xae, 0xaa, 0x52, 0xbf, 0x1a, 0x9b,
  75548. 0xc8, 0x3d, 0x45, 0x7c, 0xd1, 0x90, 0xe3, 0xd9,
  75549. 0x57, 0xcf, 0xc3, 0x29, 0x69, 0x05, 0x07, 0x96,
  75550. 0x2e, 0x46, 0x74, 0x0a, 0xa7, 0x76, 0x8b, 0xc0,
  75551. 0x1c, 0x04, 0x80, 0x08, 0xa0, 0x94, 0x7e, 0xbb,
  75552. 0x2d, 0x99, 0xe9, 0xab, 0x18, 0x4d, 0x48, 0x2d,
  75553. 0x94, 0x5e, 0x50, 0x21, 0x42, 0xdf, 0xf5, 0x61,
  75554. 0x42, 0x7d, 0x86, 0x5d, 0x9e, 0x89, 0xc9, 0x5b,
  75555. 0x24, 0xab, 0xa1, 0xd8, 0x20, 0x45, 0xcb, 0x81,
  75556. 0xcf, 0xc5, 0x25, 0x7d, 0x11, 0x6e, 0xbd, 0x80,
  75557. 0xac, 0xba, 0xdc, 0xef, 0xb9, 0x05, 0x9c, 0xd5,
  75558. 0xc2, 0x26, 0x57, 0x69, 0x8b, 0x08, 0x27, 0xc7,
  75559. 0xea, 0xbe, 0xaf, 0x52, 0x21, 0x95, 0x9f, 0xa0,
  75560. 0x2f, 0x2f, 0x53, 0x7c, 0x2f, 0xa3, 0x0b, 0x79,
  75561. 0x39, 0x01, 0xa3, 0x37, 0x46, 0xa8, 0xc4, 0x34,
  75562. 0x41, 0x20, 0x7c, 0x3f, 0x70, 0x9a, 0x47, 0xe8
  75563. };
  75564. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  75565. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2)) && \
  75566. defined(WC_RSA_NO_PADDING)
  75567. const unsigned char encMsgNoPad[] = {
  75568. 0x79, 0x69, 0xdc, 0x0d, 0xff, 0x09, 0xeb, 0x91,
  75569. 0xbc, 0xda, 0xe4, 0xd3, 0xcd, 0xd5, 0xd3, 0x1c,
  75570. 0xb9, 0x66, 0xa8, 0x02, 0xf3, 0x75, 0x40, 0xf1,
  75571. 0x38, 0x4a, 0x37, 0x7b, 0x19, 0xc8, 0xcd, 0xea,
  75572. 0x79, 0xa8, 0x51, 0x32, 0x00, 0x3f, 0x4c, 0xde,
  75573. 0xaa, 0xe5, 0xe2, 0x7c, 0x10, 0xcd, 0x6e, 0x00,
  75574. 0xc6, 0xc4, 0x63, 0x98, 0x58, 0x9b, 0x38, 0xca,
  75575. 0xf0, 0x5d, 0xc8, 0xf0, 0x57, 0xf6, 0x21, 0x50,
  75576. 0x3f, 0x63, 0x05, 0x9f, 0xbf, 0xb6, 0x3b, 0x50,
  75577. 0x85, 0x06, 0x34, 0x08, 0x57, 0xb9, 0x44, 0xce,
  75578. 0xe4, 0x66, 0xbf, 0x0c, 0xfe, 0x36, 0xa4, 0x5b,
  75579. 0xed, 0x2d, 0x7d, 0xed, 0xf1, 0xbd, 0xda, 0x3e,
  75580. 0x19, 0x1f, 0x99, 0xc8, 0xe4, 0xc2, 0xbb, 0xb5,
  75581. 0x6c, 0x83, 0x22, 0xd1, 0xe7, 0x57, 0xcf, 0x1b,
  75582. 0x91, 0x0c, 0xa5, 0x47, 0x06, 0x71, 0x8f, 0x93,
  75583. 0xf3, 0xad, 0xdb, 0xe3, 0xf8, 0xa0, 0x0b, 0xcd,
  75584. 0x89, 0x4e, 0xa5, 0xb5, 0x03, 0x68, 0x61, 0x89,
  75585. 0x0b, 0xe2, 0x03, 0x8b, 0x1f, 0x54, 0xae, 0x0f,
  75586. 0xfa, 0xf0, 0xb7, 0x0f, 0x8c, 0x84, 0x35, 0x13,
  75587. 0x8d, 0x65, 0x1f, 0x2c, 0xd5, 0xce, 0xc4, 0x6c,
  75588. 0x98, 0x67, 0xe4, 0x1a, 0x85, 0x67, 0x69, 0x17,
  75589. 0x17, 0x5a, 0x5d, 0xfd, 0x23, 0xdd, 0x03, 0x3f,
  75590. 0x6d, 0x7a, 0xb6, 0x8b, 0x99, 0xc0, 0xb6, 0x70,
  75591. 0x86, 0xac, 0xf6, 0x02, 0xc2, 0x28, 0x42, 0xed,
  75592. 0x06, 0xcf, 0xca, 0x3d, 0x07, 0x16, 0xf0, 0x0e,
  75593. 0x04, 0x55, 0x1e, 0x59, 0x3f, 0x32, 0xc7, 0x12,
  75594. 0xc5, 0x0d, 0x9d, 0x64, 0x7d, 0x2e, 0xd4, 0xbc,
  75595. 0x8c, 0x24, 0x42, 0x94, 0x2b, 0xf6, 0x11, 0x7f,
  75596. 0xb1, 0x1c, 0x09, 0x12, 0x6f, 0x5e, 0x2e, 0x7a,
  75597. 0xc6, 0x01, 0xe0, 0x98, 0x31, 0xb7, 0x13, 0x03,
  75598. 0xce, 0x29, 0xe1, 0xef, 0x9d, 0xdf, 0x9b, 0xa5,
  75599. 0xba, 0x0b, 0xad, 0xf2, 0xeb, 0x2f, 0xf9, 0xd1
  75600. };
  75601. #endif
  75602. #endif
  75603. const unsigned char* der;
  75604. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  75605. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2)) && \
  75606. defined(WC_RSA_NO_PADDING)
  75607. int i;
  75608. #endif
  75609. XMEMSET(msg, 0, sizeof(msg));
  75610. der = pubDer;
  75611. rsa = NULL;
  75612. ExpectNotNull(d2i_RSAPublicKey(&rsa, &der, pubDerSz));
  75613. ExpectIntEQ(RSA_public_decrypt(0, NULL, NULL, NULL, 0), -1);
  75614. ExpectIntEQ(RSA_public_decrypt(-1, encMsg, decMsg, rsa,
  75615. RSA_PKCS1_PADDING), -1);
  75616. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsg), NULL, decMsg, rsa,
  75617. RSA_PKCS1_PADDING), -1);
  75618. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsg), encMsg, NULL, rsa,
  75619. RSA_PKCS1_PADDING), -1);
  75620. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsg), encMsg, decMsg, NULL,
  75621. RSA_PKCS1_PADDING), -1);
  75622. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsg), encMsg, decMsg, rsa,
  75623. RSA_PKCS1_PSS_PADDING), -1);
  75624. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsg), encMsg, decMsg, rsa,
  75625. RSA_PKCS1_PADDING), 32);
  75626. ExpectIntEQ(XMEMCMP(decMsg, msg, sizeof(msg)), 0);
  75627. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || \
  75628. (defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION > 2)) && \
  75629. defined(WC_RSA_NO_PADDING)
  75630. ExpectIntEQ(RSA_public_decrypt(sizeof(encMsgNoPad), encMsgNoPad, decMsg,
  75631. rsa, RSA_NO_PADDING), sizeof(decMsg));
  75632. /* Zeros before actual data. */
  75633. for (i = 0; i < (int)(sizeof(decMsg) - sizeof(msg)); i += sizeof(msg)) {
  75634. ExpectIntEQ(XMEMCMP(decMsg + i, msg, sizeof(msg)), 0);
  75635. }
  75636. /* Check actual data. */
  75637. XMEMSET(msg, 0x01, sizeof(msg));
  75638. ExpectIntEQ(XMEMCMP(decMsg + i, msg, sizeof(msg)), 0);
  75639. #endif
  75640. RSA_free(rsa);
  75641. #endif
  75642. return EXPECT_RESULT();
  75643. }
  75644. static int test_wolfSSL_RSA_private_encrypt(void)
  75645. {
  75646. EXPECT_DECLS;
  75647. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  75648. RSA *rsa;
  75649. unsigned char msg[SHA256_DIGEST_LENGTH];
  75650. #ifdef USE_CERT_BUFFERS_1024
  75651. const unsigned char* privDer = client_key_der_1024;
  75652. size_t privDerSz = sizeof_client_key_der_1024;
  75653. unsigned char encMsg[1024/8];
  75654. const unsigned char expEncMsg[] = {
  75655. 0x45, 0x8e, 0x6e, 0x7a, 0x9c, 0xe1, 0x67, 0x36,
  75656. 0x72, 0xfc, 0x9d, 0x05, 0xdf, 0xc2, 0xaf, 0x54,
  75657. 0xc5, 0x2f, 0x94, 0xb8, 0xc7, 0x82, 0x40, 0xfa,
  75658. 0xa7, 0x8c, 0xb1, 0x89, 0x40, 0xc3, 0x59, 0x5a,
  75659. 0x77, 0x08, 0x54, 0x93, 0x43, 0x7f, 0xc4, 0xb7,
  75660. 0xc4, 0x78, 0xf1, 0xf8, 0xab, 0xbf, 0xc2, 0x81,
  75661. 0x5d, 0x97, 0xea, 0x7a, 0x60, 0x90, 0x51, 0xb7,
  75662. 0x47, 0x78, 0x48, 0x1e, 0x88, 0x6b, 0x89, 0xde,
  75663. 0xce, 0x41, 0x41, 0xae, 0x49, 0xf6, 0xfd, 0x2d,
  75664. 0x2d, 0x9c, 0x70, 0x7d, 0xf9, 0xcf, 0x77, 0x5f,
  75665. 0x06, 0xc7, 0x20, 0xe3, 0x57, 0xd4, 0xd8, 0x1a,
  75666. 0x96, 0xa2, 0x39, 0xb0, 0x6e, 0x8e, 0x68, 0xf8,
  75667. 0x57, 0x7b, 0x26, 0x88, 0x17, 0xc4, 0xb7, 0xf1,
  75668. 0x59, 0xfa, 0xb6, 0x95, 0xdd, 0x1e, 0xe8, 0xd8,
  75669. 0x4e, 0xbd, 0xcd, 0x41, 0xad, 0xc7, 0xe2, 0x39,
  75670. 0xb8, 0x00, 0xca, 0xf5, 0x59, 0xdf, 0xf8, 0x43
  75671. };
  75672. #ifdef WC_RSA_NO_PADDING
  75673. const unsigned char expEncMsgNoPad[] = {
  75674. 0x0d, 0x41, 0x5a, 0xc7, 0x60, 0xd7, 0xbe, 0xb6,
  75675. 0x42, 0xd1, 0x65, 0xb1, 0x7e, 0x59, 0x54, 0xcc,
  75676. 0x76, 0x62, 0xd0, 0x2f, 0x4d, 0xe3, 0x23, 0x62,
  75677. 0xc8, 0x14, 0xfe, 0x5e, 0xa1, 0xc7, 0x05, 0xee,
  75678. 0x9e, 0x28, 0x2e, 0xf5, 0xfd, 0xa4, 0xc0, 0x43,
  75679. 0x55, 0xa2, 0x6b, 0x6b, 0x16, 0xa7, 0x63, 0x06,
  75680. 0xa7, 0x78, 0x4f, 0xda, 0xae, 0x10, 0x6d, 0xd1,
  75681. 0x2e, 0x1d, 0xbb, 0xbc, 0xc4, 0x1d, 0x82, 0xe4,
  75682. 0xc6, 0x76, 0x77, 0xa6, 0x0a, 0xef, 0xd2, 0x89,
  75683. 0xff, 0x30, 0x85, 0x22, 0xa0, 0x68, 0x88, 0x54,
  75684. 0xa3, 0xd1, 0x92, 0xd1, 0x3f, 0x57, 0xe4, 0xc7,
  75685. 0x43, 0x5a, 0x8b, 0xb3, 0x86, 0xaf, 0xd5, 0x6d,
  75686. 0x07, 0xe1, 0xa0, 0x5f, 0xe1, 0x9a, 0x06, 0xba,
  75687. 0x56, 0xd2, 0xb0, 0x73, 0xf5, 0xb3, 0xd0, 0x5f,
  75688. 0xc0, 0xbf, 0x22, 0x4c, 0x54, 0x4e, 0x11, 0xe2,
  75689. 0xc5, 0xf8, 0x66, 0x39, 0x9d, 0x70, 0x90, 0x31
  75690. };
  75691. #endif
  75692. #else
  75693. const unsigned char* privDer = client_key_der_2048;
  75694. size_t privDerSz = sizeof_client_key_der_2048;
  75695. unsigned char encMsg[2048/8];
  75696. const unsigned char expEncMsg[] = {
  75697. 0x16, 0x5d, 0xbb, 0x00, 0x38, 0x73, 0x01, 0x34,
  75698. 0xca, 0x59, 0xc6, 0x8b, 0x64, 0x70, 0x89, 0xf5,
  75699. 0x50, 0x2d, 0x1d, 0x69, 0x1f, 0x07, 0x1e, 0x31,
  75700. 0xae, 0x9b, 0xa6, 0x6e, 0xee, 0x80, 0xd9, 0x9e,
  75701. 0x59, 0x33, 0x70, 0x30, 0x28, 0x42, 0x7d, 0x24,
  75702. 0x36, 0x95, 0x6b, 0xf9, 0x0a, 0x23, 0xcb, 0xce,
  75703. 0x66, 0xa5, 0x07, 0x5e, 0x11, 0xa7, 0xdc, 0xfb,
  75704. 0xd9, 0xc2, 0x51, 0xf0, 0x05, 0xc9, 0x39, 0xb3,
  75705. 0xae, 0xff, 0xfb, 0xe9, 0xb1, 0x9a, 0x54, 0xac,
  75706. 0x1d, 0xca, 0x42, 0x1a, 0xfd, 0x7c, 0x97, 0xa0,
  75707. 0x60, 0x2b, 0xcd, 0xb6, 0x36, 0x33, 0xfc, 0x44,
  75708. 0x69, 0xf7, 0x2e, 0x8c, 0x3b, 0x5f, 0xb4, 0x9f,
  75709. 0xa7, 0x02, 0x8f, 0x6d, 0x6b, 0x79, 0x10, 0x32,
  75710. 0x7d, 0xf4, 0x5d, 0xa1, 0x63, 0x22, 0x59, 0xc4,
  75711. 0x44, 0x8e, 0x44, 0x24, 0x8b, 0x14, 0x9d, 0x2b,
  75712. 0xb5, 0xd3, 0xad, 0x9a, 0x87, 0x0d, 0xe7, 0x70,
  75713. 0x6d, 0xe9, 0xae, 0xaa, 0x52, 0xbf, 0x1a, 0x9b,
  75714. 0xc8, 0x3d, 0x45, 0x7c, 0xd1, 0x90, 0xe3, 0xd9,
  75715. 0x57, 0xcf, 0xc3, 0x29, 0x69, 0x05, 0x07, 0x96,
  75716. 0x2e, 0x46, 0x74, 0x0a, 0xa7, 0x76, 0x8b, 0xc0,
  75717. 0x1c, 0x04, 0x80, 0x08, 0xa0, 0x94, 0x7e, 0xbb,
  75718. 0x2d, 0x99, 0xe9, 0xab, 0x18, 0x4d, 0x48, 0x2d,
  75719. 0x94, 0x5e, 0x50, 0x21, 0x42, 0xdf, 0xf5, 0x61,
  75720. 0x42, 0x7d, 0x86, 0x5d, 0x9e, 0x89, 0xc9, 0x5b,
  75721. 0x24, 0xab, 0xa1, 0xd8, 0x20, 0x45, 0xcb, 0x81,
  75722. 0xcf, 0xc5, 0x25, 0x7d, 0x11, 0x6e, 0xbd, 0x80,
  75723. 0xac, 0xba, 0xdc, 0xef, 0xb9, 0x05, 0x9c, 0xd5,
  75724. 0xc2, 0x26, 0x57, 0x69, 0x8b, 0x08, 0x27, 0xc7,
  75725. 0xea, 0xbe, 0xaf, 0x52, 0x21, 0x95, 0x9f, 0xa0,
  75726. 0x2f, 0x2f, 0x53, 0x7c, 0x2f, 0xa3, 0x0b, 0x79,
  75727. 0x39, 0x01, 0xa3, 0x37, 0x46, 0xa8, 0xc4, 0x34,
  75728. 0x41, 0x20, 0x7c, 0x3f, 0x70, 0x9a, 0x47, 0xe8
  75729. };
  75730. #ifdef WC_RSA_NO_PADDING
  75731. const unsigned char expEncMsgNoPad[] = {
  75732. 0x79, 0x69, 0xdc, 0x0d, 0xff, 0x09, 0xeb, 0x91,
  75733. 0xbc, 0xda, 0xe4, 0xd3, 0xcd, 0xd5, 0xd3, 0x1c,
  75734. 0xb9, 0x66, 0xa8, 0x02, 0xf3, 0x75, 0x40, 0xf1,
  75735. 0x38, 0x4a, 0x37, 0x7b, 0x19, 0xc8, 0xcd, 0xea,
  75736. 0x79, 0xa8, 0x51, 0x32, 0x00, 0x3f, 0x4c, 0xde,
  75737. 0xaa, 0xe5, 0xe2, 0x7c, 0x10, 0xcd, 0x6e, 0x00,
  75738. 0xc6, 0xc4, 0x63, 0x98, 0x58, 0x9b, 0x38, 0xca,
  75739. 0xf0, 0x5d, 0xc8, 0xf0, 0x57, 0xf6, 0x21, 0x50,
  75740. 0x3f, 0x63, 0x05, 0x9f, 0xbf, 0xb6, 0x3b, 0x50,
  75741. 0x85, 0x06, 0x34, 0x08, 0x57, 0xb9, 0x44, 0xce,
  75742. 0xe4, 0x66, 0xbf, 0x0c, 0xfe, 0x36, 0xa4, 0x5b,
  75743. 0xed, 0x2d, 0x7d, 0xed, 0xf1, 0xbd, 0xda, 0x3e,
  75744. 0x19, 0x1f, 0x99, 0xc8, 0xe4, 0xc2, 0xbb, 0xb5,
  75745. 0x6c, 0x83, 0x22, 0xd1, 0xe7, 0x57, 0xcf, 0x1b,
  75746. 0x91, 0x0c, 0xa5, 0x47, 0x06, 0x71, 0x8f, 0x93,
  75747. 0xf3, 0xad, 0xdb, 0xe3, 0xf8, 0xa0, 0x0b, 0xcd,
  75748. 0x89, 0x4e, 0xa5, 0xb5, 0x03, 0x68, 0x61, 0x89,
  75749. 0x0b, 0xe2, 0x03, 0x8b, 0x1f, 0x54, 0xae, 0x0f,
  75750. 0xfa, 0xf0, 0xb7, 0x0f, 0x8c, 0x84, 0x35, 0x13,
  75751. 0x8d, 0x65, 0x1f, 0x2c, 0xd5, 0xce, 0xc4, 0x6c,
  75752. 0x98, 0x67, 0xe4, 0x1a, 0x85, 0x67, 0x69, 0x17,
  75753. 0x17, 0x5a, 0x5d, 0xfd, 0x23, 0xdd, 0x03, 0x3f,
  75754. 0x6d, 0x7a, 0xb6, 0x8b, 0x99, 0xc0, 0xb6, 0x70,
  75755. 0x86, 0xac, 0xf6, 0x02, 0xc2, 0x28, 0x42, 0xed,
  75756. 0x06, 0xcf, 0xca, 0x3d, 0x07, 0x16, 0xf0, 0x0e,
  75757. 0x04, 0x55, 0x1e, 0x59, 0x3f, 0x32, 0xc7, 0x12,
  75758. 0xc5, 0x0d, 0x9d, 0x64, 0x7d, 0x2e, 0xd4, 0xbc,
  75759. 0x8c, 0x24, 0x42, 0x94, 0x2b, 0xf6, 0x11, 0x7f,
  75760. 0xb1, 0x1c, 0x09, 0x12, 0x6f, 0x5e, 0x2e, 0x7a,
  75761. 0xc6, 0x01, 0xe0, 0x98, 0x31, 0xb7, 0x13, 0x03,
  75762. 0xce, 0x29, 0xe1, 0xef, 0x9d, 0xdf, 0x9b, 0xa5,
  75763. 0xba, 0x0b, 0xad, 0xf2, 0xeb, 0x2f, 0xf9, 0xd1
  75764. };
  75765. #endif
  75766. #endif
  75767. const unsigned char* der;
  75768. XMEMSET(msg, 0x00, sizeof(msg));
  75769. der = privDer;
  75770. rsa = NULL;
  75771. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  75772. ExpectIntEQ(RSA_private_encrypt(0, NULL, NULL, NULL, 0), -1);
  75773. ExpectIntEQ(RSA_private_encrypt(0, msg, encMsg, rsa, RSA_PKCS1_PADDING),
  75774. -1);
  75775. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), NULL, encMsg, rsa,
  75776. RSA_PKCS1_PADDING), -1);
  75777. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), msg, NULL, rsa,
  75778. RSA_PKCS1_PADDING), -1);
  75779. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), msg, encMsg, NULL,
  75780. RSA_PKCS1_PADDING), -1);
  75781. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), msg, encMsg, rsa,
  75782. RSA_PKCS1_PSS_PADDING), -1);
  75783. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), msg, encMsg, rsa,
  75784. RSA_PKCS1_PADDING), sizeof(encMsg));
  75785. ExpectIntEQ(XMEMCMP(encMsg, expEncMsg, sizeof(expEncMsg)), 0);
  75786. #ifdef WC_RSA_NO_PADDING
  75787. /* Non-zero message. */
  75788. XMEMSET(msg, 0x01, sizeof(msg));
  75789. ExpectIntEQ(RSA_private_encrypt(sizeof(msg), msg, encMsg, rsa,
  75790. RSA_NO_PADDING), sizeof(encMsg));
  75791. ExpectIntEQ(XMEMCMP(encMsg, expEncMsgNoPad, sizeof(expEncMsgNoPad)), 0);
  75792. #endif
  75793. RSA_free(rsa);
  75794. #endif
  75795. return EXPECT_RESULT();
  75796. }
  75797. static int test_wolfSSL_RSA_public_encrypt(void)
  75798. {
  75799. EXPECT_DECLS;
  75800. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  75801. RSA* rsa = NULL;
  75802. const unsigned char msg[2048/8] = { 0 };
  75803. unsigned char encMsg[2048/8];
  75804. ExpectNotNull(rsa = RSA_new());
  75805. ExpectIntEQ(RSA_public_encrypt(-1, msg, encMsg, rsa,
  75806. RSA_PKCS1_PADDING), -1);
  75807. ExpectIntEQ(RSA_public_encrypt(sizeof(msg), NULL, encMsg, rsa,
  75808. RSA_PKCS1_PADDING), -1);
  75809. ExpectIntEQ(RSA_public_encrypt(sizeof(msg), msg, NULL, rsa,
  75810. RSA_PKCS1_PADDING), -1);
  75811. ExpectIntEQ(RSA_public_encrypt(sizeof(msg), msg, encMsg, NULL,
  75812. RSA_PKCS1_PADDING), -1);
  75813. ExpectIntEQ(RSA_public_encrypt(sizeof(msg), msg, encMsg, rsa,
  75814. RSA_PKCS1_PSS_PADDING), -1);
  75815. /* Empty RSA key. */
  75816. ExpectIntEQ(RSA_public_encrypt(sizeof(msg), msg, encMsg, rsa,
  75817. RSA_PKCS1_PADDING), -1);
  75818. RSA_free(rsa);
  75819. #endif
  75820. return EXPECT_RESULT();
  75821. }
  75822. static int test_wolfSSL_RSA_private_decrypt(void)
  75823. {
  75824. EXPECT_DECLS;
  75825. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  75826. RSA* rsa = NULL;
  75827. unsigned char msg[2048/8];
  75828. const unsigned char encMsg[2048/8] = { 0 };
  75829. ExpectNotNull(rsa = RSA_new());
  75830. ExpectIntEQ(RSA_private_decrypt(-1, encMsg, msg, rsa,
  75831. RSA_PKCS1_PADDING), -1);
  75832. ExpectIntEQ(RSA_private_decrypt(sizeof(encMsg), NULL, msg, rsa,
  75833. RSA_PKCS1_PADDING), -1);
  75834. ExpectIntEQ(RSA_private_decrypt(sizeof(encMsg), encMsg, NULL, rsa,
  75835. RSA_PKCS1_PADDING), -1);
  75836. ExpectIntEQ(RSA_private_decrypt(sizeof(encMsg), encMsg, msg, NULL,
  75837. RSA_PKCS1_PADDING), -1);
  75838. ExpectIntEQ(RSA_private_decrypt(sizeof(encMsg), encMsg, msg, rsa,
  75839. RSA_PKCS1_PSS_PADDING), -1);
  75840. /* Empty RSA key. */
  75841. ExpectIntEQ(RSA_private_decrypt(sizeof(encMsg), encMsg, msg, rsa,
  75842. RSA_PKCS1_PADDING), -1);
  75843. RSA_free(rsa);
  75844. #endif
  75845. return EXPECT_RESULT();
  75846. }
  75847. static int test_wolfSSL_RSA_GenAdd(void)
  75848. {
  75849. EXPECT_DECLS;
  75850. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  75851. RSA *rsa;
  75852. #ifdef USE_CERT_BUFFERS_1024
  75853. const unsigned char* privDer = client_key_der_1024;
  75854. size_t privDerSz = sizeof_client_key_der_1024;
  75855. const unsigned char* pubDer = client_keypub_der_1024;
  75856. size_t pubDerSz = sizeof_client_keypub_der_1024;
  75857. #else
  75858. const unsigned char* privDer = client_key_der_2048;
  75859. size_t privDerSz = sizeof_client_key_der_2048;
  75860. const unsigned char* pubDer = client_keypub_der_2048;
  75861. size_t pubDerSz = sizeof_client_keypub_der_2048;
  75862. #endif
  75863. const unsigned char* der;
  75864. der = privDer;
  75865. rsa = NULL;
  75866. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  75867. ExpectIntEQ(wolfSSL_RSA_GenAdd(NULL), -1);
  75868. #ifndef RSA_LOW_MEM
  75869. ExpectIntEQ(wolfSSL_RSA_GenAdd(rsa), 1);
  75870. #else
  75871. /* dmp1 and dmq1 are not set (allocated) when RSA_LOW_MEM. */
  75872. ExpectIntEQ(wolfSSL_RSA_GenAdd(rsa), -1);
  75873. #endif
  75874. RSA_free(rsa);
  75875. der = pubDer;
  75876. rsa = NULL;
  75877. ExpectNotNull(d2i_RSAPublicKey(&rsa, &der, pubDerSz));
  75878. /* Need private values. */
  75879. ExpectIntEQ(wolfSSL_RSA_GenAdd(rsa), -1);
  75880. RSA_free(rsa);
  75881. #endif
  75882. return EXPECT_RESULT();
  75883. }
  75884. static int test_wolfSSL_RSA_blinding_on(void)
  75885. {
  75886. EXPECT_DECLS;
  75887. #if defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_WOLFSSL_STUB)
  75888. RSA *rsa;
  75889. WOLFSSL_BN_CTX *bnCtx = NULL;
  75890. #ifdef USE_CERT_BUFFERS_1024
  75891. const unsigned char* privDer = client_key_der_1024;
  75892. size_t privDerSz = sizeof_client_key_der_1024;
  75893. #else
  75894. const unsigned char* privDer = client_key_der_2048;
  75895. size_t privDerSz = sizeof_client_key_der_2048;
  75896. #endif
  75897. const unsigned char* der;
  75898. der = privDer;
  75899. rsa = NULL;
  75900. ExpectNotNull(d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  75901. ExpectNotNull(bnCtx = wolfSSL_BN_CTX_new());
  75902. /* Does nothing so all parameters are valid. */
  75903. ExpectIntEQ(wolfSSL_RSA_blinding_on(NULL, NULL), 1);
  75904. ExpectIntEQ(wolfSSL_RSA_blinding_on(rsa, NULL), 1);
  75905. ExpectIntEQ(wolfSSL_RSA_blinding_on(NULL, bnCtx), 1);
  75906. ExpectIntEQ(wolfSSL_RSA_blinding_on(rsa, bnCtx), 1);
  75907. wolfSSL_BN_CTX_free(bnCtx);
  75908. RSA_free(rsa);
  75909. #endif
  75910. return EXPECT_RESULT();
  75911. }
  75912. static int test_wolfSSL_RSA_ex_data(void)
  75913. {
  75914. EXPECT_DECLS;
  75915. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA)
  75916. RSA* rsa = NULL;
  75917. unsigned char data[1];
  75918. ExpectNotNull(rsa = RSA_new());
  75919. ExpectNull(wolfSSL_RSA_get_ex_data(NULL, 0));
  75920. ExpectNull(wolfSSL_RSA_get_ex_data(rsa, 0));
  75921. #ifdef MAX_EX_DATA
  75922. ExpectNull(wolfSSL_RSA_get_ex_data(rsa, MAX_EX_DATA));
  75923. ExpectIntEQ(wolfSSL_RSA_set_ex_data(rsa, MAX_EX_DATA, data), 0);
  75924. #endif
  75925. ExpectIntEQ(wolfSSL_RSA_set_ex_data(NULL, 0, NULL), 0);
  75926. ExpectIntEQ(wolfSSL_RSA_set_ex_data(NULL, 0, data), 0);
  75927. #ifdef HAVE_EX_DATA
  75928. ExpectIntEQ(wolfSSL_RSA_set_ex_data(rsa, 0, NULL), 1);
  75929. ExpectIntEQ(wolfSSL_RSA_set_ex_data(rsa, 0, data), 1);
  75930. ExpectPtrEq(wolfSSL_RSA_get_ex_data(rsa, 0), data);
  75931. #else
  75932. ExpectIntEQ(wolfSSL_RSA_set_ex_data(rsa, 0, NULL), 0);
  75933. ExpectIntEQ(wolfSSL_RSA_set_ex_data(rsa, 0, data), 0);
  75934. ExpectNull(wolfSSL_RSA_get_ex_data(rsa, 0));
  75935. #endif
  75936. RSA_free(rsa);
  75937. #endif /* !NO_RSA && OPENSSL_EXTRA */
  75938. return EXPECT_RESULT();
  75939. }
  75940. static int test_wolfSSL_RSA_LoadDer(void)
  75941. {
  75942. EXPECT_DECLS;
  75943. #if !defined(NO_RSA) && (defined(OPENSSL_EXTRA) || \
  75944. defined(OPENSSL_EXTRA_X509_SMALL))
  75945. RSA *rsa = NULL;
  75946. #ifdef USE_CERT_BUFFERS_1024
  75947. const unsigned char* privDer = client_key_der_1024;
  75948. size_t privDerSz = sizeof_client_key_der_1024;
  75949. #else
  75950. const unsigned char* privDer = client_key_der_2048;
  75951. size_t privDerSz = sizeof_client_key_der_2048;
  75952. #endif
  75953. ExpectNotNull(rsa = RSA_new());
  75954. ExpectIntEQ(wolfSSL_RSA_LoadDer(NULL, privDer, (int)privDerSz), -1);
  75955. ExpectIntEQ(wolfSSL_RSA_LoadDer(rsa, NULL, (int)privDerSz), -1);
  75956. ExpectIntEQ(wolfSSL_RSA_LoadDer(rsa, privDer, 0), -1);
  75957. ExpectIntEQ(wolfSSL_RSA_LoadDer(rsa, privDer, (int)privDerSz), 1);
  75958. RSA_free(rsa);
  75959. #endif /* !NO_RSA && OPENSSL_EXTRA */
  75960. return EXPECT_RESULT();
  75961. }
  75962. /* Local API. */
  75963. static int test_wolfSSL_RSA_To_Der(void)
  75964. {
  75965. EXPECT_DECLS;
  75966. #ifdef WOLFSSL_TEST_STATIC_BUILD
  75967. #if defined(WOLFSSL_KEY_GEN) && defined(OPENSSL_EXTRA) && !defined(NO_RSA)
  75968. RSA* rsa;
  75969. #ifdef USE_CERT_BUFFERS_1024
  75970. const unsigned char* privDer = client_key_der_1024;
  75971. size_t privDerSz = sizeof_client_key_der_1024;
  75972. const unsigned char* pubDer = client_keypub_der_1024;
  75973. size_t pubDerSz = sizeof_client_keypub_der_1024;
  75974. unsigned char out[sizeof(client_key_der_1024)];
  75975. #else
  75976. const unsigned char* privDer = client_key_der_2048;
  75977. size_t privDerSz = sizeof_client_key_der_2048;
  75978. const unsigned char* pubDer = client_keypub_der_2048;
  75979. size_t pubDerSz = sizeof_client_keypub_der_2048;
  75980. unsigned char out[sizeof(client_key_der_2048)];
  75981. #endif
  75982. const unsigned char* der;
  75983. unsigned char* outDer = NULL;
  75984. der = privDer;
  75985. rsa = NULL;
  75986. ExpectNotNull(wolfSSL_d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  75987. ExpectIntEQ(wolfSSL_RSA_To_Der(NULL, &outDer, 0, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  75988. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 2, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  75989. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, NULL, 0, HEAP_HINT), privDerSz);
  75990. outDer = out;
  75991. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 0, HEAP_HINT), privDerSz);
  75992. ExpectIntEQ(XMEMCMP(out, privDer, privDerSz), 0);
  75993. outDer = NULL;
  75994. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 0, HEAP_HINT), privDerSz);
  75995. ExpectNotNull(outDer);
  75996. ExpectIntEQ(XMEMCMP(outDer, privDer, privDerSz), 0);
  75997. XFREE(outDer, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  75998. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, NULL, 1, HEAP_HINT), pubDerSz);
  75999. outDer = out;
  76000. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 1, HEAP_HINT), pubDerSz);
  76001. ExpectIntEQ(XMEMCMP(out, pubDer, pubDerSz), 0);
  76002. RSA_free(rsa);
  76003. ExpectNotNull(rsa = RSA_new());
  76004. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 0, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  76005. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 1, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  76006. RSA_free(rsa);
  76007. der = pubDer;
  76008. rsa = NULL;
  76009. ExpectNotNull(wolfSSL_d2i_RSAPublicKey(&rsa, &der, pubDerSz));
  76010. ExpectIntEQ(wolfSSL_RSA_To_Der(rsa, &outDer, 0, HEAP_HINT), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  76011. RSA_free(rsa);
  76012. #endif
  76013. #endif
  76014. return EXPECT_RESULT();
  76015. }
  76016. /* wolfSSL_PEM_read_RSAPublicKey is a stub function. */
  76017. static int test_wolfSSL_PEM_read_RSAPublicKey(void)
  76018. {
  76019. EXPECT_DECLS;
  76020. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM)
  76021. XFILE file = XBADFILE;
  76022. const char* fname = "./certs/server-keyPub.pem";
  76023. RSA *rsa = NULL;
  76024. ExpectNull(wolfSSL_PEM_read_RSAPublicKey(XBADFILE, NULL, NULL, NULL));
  76025. ExpectTrue((file = XFOPEN(fname, "rb")) != XBADFILE);
  76026. ExpectNotNull(rsa = PEM_read_RSA_PUBKEY(file, NULL, NULL, NULL));
  76027. ExpectIntEQ(RSA_size(rsa), 256);
  76028. RSA_free(rsa);
  76029. if (file != XBADFILE)
  76030. XFCLOSE(file);
  76031. #endif
  76032. return EXPECT_RESULT();
  76033. }
  76034. /* wolfSSL_PEM_read_RSAPublicKey is a stub function. */
  76035. static int test_wolfSSL_PEM_write_RSA_PUBKEY(void)
  76036. {
  76037. EXPECT_DECLS;
  76038. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA) && !defined(NO_FILESYSTEM) && \
  76039. defined(WOLFSSL_KEY_GEN)
  76040. RSA* rsa = NULL;
  76041. ExpectIntEQ(wolfSSL_PEM_write_RSA_PUBKEY(XBADFILE, NULL), 0);
  76042. ExpectIntEQ(wolfSSL_PEM_write_RSA_PUBKEY(stderr, NULL), 0);
  76043. /* Valid but stub so returns 0. */
  76044. ExpectIntEQ(wolfSSL_PEM_write_RSA_PUBKEY(stderr, rsa), 0);
  76045. #endif
  76046. return EXPECT_RESULT();
  76047. }
  76048. static int test_wolfSSL_PEM_write_RSAPrivateKey(void)
  76049. {
  76050. EXPECT_DECLS;
  76051. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN) && \
  76052. (defined(WOLFSSL_PEM_TO_DER) || \
  76053. defined(WOLFSSL_DER_TO_PEM)) && !defined(NO_FILESYSTEM)
  76054. RSA* rsa = NULL;
  76055. #ifdef USE_CERT_BUFFERS_1024
  76056. const unsigned char* privDer = client_key_der_1024;
  76057. size_t privDerSz = sizeof_client_key_der_1024;
  76058. #else
  76059. const unsigned char* privDer = client_key_der_2048;
  76060. size_t privDerSz = sizeof_client_key_der_2048;
  76061. #endif
  76062. const unsigned char* der;
  76063. #ifndef NO_AES
  76064. unsigned char passwd[] = "password";
  76065. #endif
  76066. ExpectNotNull(rsa = RSA_new());
  76067. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(stderr, rsa, NULL, NULL, 0,
  76068. NULL, NULL), 0);
  76069. RSA_free(rsa);
  76070. der = privDer;
  76071. rsa = NULL;
  76072. ExpectNotNull(wolfSSL_d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  76073. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(XBADFILE, rsa, NULL, NULL, 0,
  76074. NULL, NULL), 0);
  76075. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(stderr, NULL, NULL, NULL, 0,
  76076. NULL, NULL), 0);
  76077. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(stderr, rsa, NULL, NULL, 0,
  76078. NULL, NULL), 1);
  76079. #ifndef NO_AES
  76080. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(stderr, rsa, EVP_aes_128_cbc(),
  76081. NULL, 0, NULL, NULL), 1);
  76082. ExpectIntEQ(wolfSSL_PEM_write_RSAPrivateKey(stderr, rsa, EVP_aes_128_cbc(),
  76083. passwd, sizeof(passwd) - 1, NULL, NULL), 1);
  76084. #endif
  76085. RSA_free(rsa);
  76086. #endif
  76087. return EXPECT_RESULT();
  76088. }
  76089. static int test_wolfSSL_PEM_write_mem_RSAPrivateKey(void)
  76090. {
  76091. EXPECT_DECLS;
  76092. #if !defined(NO_RSA) && defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN) && \
  76093. (defined(WOLFSSL_PEM_TO_DER) || defined(WOLFSSL_DER_TO_PEM))
  76094. RSA* rsa = NULL;
  76095. #ifdef USE_CERT_BUFFERS_1024
  76096. const unsigned char* privDer = client_key_der_1024;
  76097. size_t privDerSz = sizeof_client_key_der_1024;
  76098. #else
  76099. const unsigned char* privDer = client_key_der_2048;
  76100. size_t privDerSz = sizeof_client_key_der_2048;
  76101. #endif
  76102. const unsigned char* der;
  76103. #ifndef NO_AES
  76104. unsigned char passwd[] = "password";
  76105. #endif
  76106. unsigned char* pem = NULL;
  76107. int plen;
  76108. ExpectNotNull(rsa = RSA_new());
  76109. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, NULL, NULL, 0, &pem,
  76110. &plen), 0);
  76111. RSA_free(rsa);
  76112. der = privDer;
  76113. rsa = NULL;
  76114. ExpectNotNull(wolfSSL_d2i_RSAPrivateKey(&rsa, &der, privDerSz));
  76115. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(NULL, NULL, NULL, 0, &pem,
  76116. &plen), 0);
  76117. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, NULL, NULL, 0, NULL,
  76118. &plen), 0);
  76119. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, NULL, NULL, 0, &pem,
  76120. NULL), 0);
  76121. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, NULL, NULL, 0, &pem,
  76122. &plen), 1);
  76123. XFREE(pem, NULL, DYNAMIC_TYPE_KEY);
  76124. pem = NULL;
  76125. #ifndef NO_AES
  76126. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, EVP_aes_128_cbc(),
  76127. NULL, 0, &pem, &plen), 1);
  76128. XFREE(pem, NULL, DYNAMIC_TYPE_KEY);
  76129. pem = NULL;
  76130. ExpectIntEQ(wolfSSL_PEM_write_mem_RSAPrivateKey(rsa, EVP_aes_128_cbc(),
  76131. passwd, sizeof(passwd) - 1, &pem, &plen), 1);
  76132. XFREE(pem, NULL, DYNAMIC_TYPE_KEY);
  76133. #endif
  76134. RSA_free(rsa);
  76135. #endif
  76136. return EXPECT_RESULT();
  76137. }
  76138. static int test_wolfSSL_DH(void)
  76139. {
  76140. EXPECT_DECLS;
  76141. #if defined(OPENSSL_EXTRA) && !defined(NO_DH)
  76142. DH *dh = NULL;
  76143. BIGNUM* p;
  76144. BIGNUM* q;
  76145. BIGNUM* g;
  76146. BIGNUM* pub = NULL;
  76147. BIGNUM* priv = NULL;
  76148. #if defined(OPENSSL_ALL)
  76149. #if !defined(HAVE_FIPS) || \
  76150. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
  76151. FILE* f = NULL;
  76152. unsigned char buf[268];
  76153. const unsigned char* pt = buf;
  76154. long len = 0;
  76155. dh = NULL;
  76156. XMEMSET(buf, 0, sizeof(buf));
  76157. /* Test 2048 bit parameters */
  76158. ExpectTrue((f = XFOPEN("./certs/dh2048.der", "rb")) != XBADFILE);
  76159. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  76160. if (f != XBADFILE)
  76161. XFCLOSE(f);
  76162. ExpectNotNull(dh = d2i_DHparams(NULL, &pt, len));
  76163. ExpectNotNull(dh->p);
  76164. ExpectNotNull(dh->g);
  76165. ExpectTrue(pt == buf);
  76166. ExpectIntEQ(DH_generate_key(dh), 1);
  76167. /* first, test for expected successful key agreement. */
  76168. if (EXPECT_SUCCESS()) {
  76169. DH *dh2 = NULL;
  76170. unsigned char buf2[268];
  76171. int sz1 = 0, sz2 = 0;
  76172. ExpectNotNull(dh2 = d2i_DHparams(NULL, &pt, len));
  76173. ExpectIntEQ(DH_generate_key(dh2), 1);
  76174. ExpectIntGT(sz1=DH_compute_key(buf, dh2->pub_key, dh), 0);
  76175. ExpectIntGT(sz2=DH_compute_key(buf2, dh->pub_key, dh2), 0);
  76176. ExpectIntEQ(sz1, sz2);
  76177. ExpectIntEQ(XMEMCMP(buf, buf2, (size_t)sz1), 0);
  76178. ExpectIntNE(sz1 = DH_size(dh), 0);
  76179. ExpectIntEQ(DH_compute_key_padded(buf, dh2->pub_key, dh), sz1);
  76180. ExpectIntEQ(DH_compute_key_padded(buf2, dh->pub_key, dh2), sz1);
  76181. ExpectIntEQ(XMEMCMP(buf, buf2, (size_t)sz1), 0);
  76182. if (dh2 != NULL)
  76183. DH_free(dh2);
  76184. }
  76185. ExpectIntEQ(DH_generate_key(dh), 1);
  76186. ExpectIntEQ(DH_compute_key(NULL, NULL, NULL), -1);
  76187. ExpectNotNull(pub = BN_new());
  76188. ExpectIntEQ(BN_set_word(pub, 1), 1);
  76189. ExpectIntEQ(DH_compute_key(buf, NULL, NULL), -1);
  76190. ExpectIntEQ(DH_compute_key(NULL, pub, NULL), -1);
  76191. ExpectIntEQ(DH_compute_key(NULL, NULL, dh), -1);
  76192. ExpectIntEQ(DH_compute_key(buf, pub, NULL), -1);
  76193. ExpectIntEQ(DH_compute_key(buf, NULL, dh), -1);
  76194. ExpectIntEQ(DH_compute_key(NULL, pub, dh), -1);
  76195. ExpectIntEQ(DH_compute_key(buf, pub, dh), -1);
  76196. BN_free(pub);
  76197. pub = NULL;
  76198. DH_get0_pqg(dh, (const BIGNUM**)&p,
  76199. (const BIGNUM**)&q,
  76200. (const BIGNUM**)&g);
  76201. ExpectPtrEq(p, dh->p);
  76202. ExpectPtrEq(q, dh->q);
  76203. ExpectPtrEq(g, dh->g);
  76204. DH_get0_key(NULL, (const BIGNUM**)&pub, (const BIGNUM**)&priv);
  76205. DH_get0_key(dh, (const BIGNUM**)&pub, (const BIGNUM**)&priv);
  76206. ExpectPtrEq(pub, dh->pub_key);
  76207. ExpectPtrEq(priv, dh->priv_key);
  76208. DH_get0_key(dh, (const BIGNUM**)&pub, NULL);
  76209. ExpectPtrEq(pub, dh->pub_key);
  76210. DH_get0_key(dh, NULL, (const BIGNUM**)&priv);
  76211. ExpectPtrEq(priv, dh->priv_key);
  76212. pub = NULL;
  76213. priv = NULL;
  76214. ExpectNotNull(pub = BN_new());
  76215. ExpectNotNull(priv = BN_new());
  76216. ExpectIntEQ(DH_set0_key(NULL, pub, priv), 0);
  76217. ExpectIntEQ(DH_set0_key(dh, pub, priv), 1);
  76218. if (EXPECT_FAIL()) {
  76219. BN_free(pub);
  76220. BN_free(priv);
  76221. }
  76222. pub = NULL;
  76223. priv = NULL;
  76224. ExpectNotNull(pub = BN_new());
  76225. ExpectIntEQ(DH_set0_key(dh, pub, NULL), 1);
  76226. if (EXPECT_FAIL()) {
  76227. BN_free(pub);
  76228. }
  76229. ExpectNotNull(priv = BN_new());
  76230. ExpectIntEQ(DH_set0_key(dh, NULL, priv), 1);
  76231. if (EXPECT_FAIL()) {
  76232. BN_free(priv);
  76233. }
  76234. ExpectPtrEq(pub, dh->pub_key);
  76235. ExpectPtrEq(priv, dh->priv_key);
  76236. pub = NULL;
  76237. priv = NULL;
  76238. DH_free(dh);
  76239. dh = NULL;
  76240. ExpectNotNull(dh = DH_new());
  76241. p = NULL;
  76242. ExpectNotNull(p = BN_new());
  76243. ExpectIntEQ(BN_set_word(p, 1), 1);
  76244. ExpectIntEQ(DH_compute_key(buf, p, dh), -1);
  76245. ExpectNotNull(pub = BN_new());
  76246. ExpectNotNull(priv = BN_new());
  76247. ExpectIntEQ(DH_set0_key(dh, pub, priv), 1);
  76248. if (EXPECT_FAIL()) {
  76249. BN_free(pub);
  76250. BN_free(priv);
  76251. }
  76252. pub = NULL;
  76253. priv = NULL;
  76254. ExpectIntEQ(DH_compute_key(buf, p, dh), -1);
  76255. BN_free(p);
  76256. p = NULL;
  76257. DH_free(dh);
  76258. dh = NULL;
  76259. #ifdef WOLFSSL_KEY_GEN
  76260. ExpectNotNull(dh = DH_generate_parameters(2048, 2, NULL, NULL));
  76261. ExpectIntEQ(wolfSSL_DH_generate_parameters_ex(NULL, 2048, 2, NULL), 0);
  76262. DH_free(dh);
  76263. dh = NULL;
  76264. #endif
  76265. #endif /* !HAVE_FIPS || (HAVE_FIPS_VERSION && HAVE_FIPS_VERSION > 2) */
  76266. #endif /* OPENSSL_ALL */
  76267. (void)dh;
  76268. (void)p;
  76269. (void)q;
  76270. (void)g;
  76271. (void)pub;
  76272. (void)priv;
  76273. ExpectNotNull(dh = wolfSSL_DH_new());
  76274. /* invalid parameters test */
  76275. DH_get0_pqg(NULL, (const BIGNUM**)&p,
  76276. (const BIGNUM**)&q,
  76277. (const BIGNUM**)&g);
  76278. DH_get0_pqg(dh, NULL,
  76279. (const BIGNUM**)&q,
  76280. (const BIGNUM**)&g);
  76281. DH_get0_pqg(dh, NULL, NULL, (const BIGNUM**)&g);
  76282. DH_get0_pqg(dh, NULL, NULL, NULL);
  76283. DH_get0_pqg(dh, (const BIGNUM**)&p,
  76284. (const BIGNUM**)&q,
  76285. (const BIGNUM**)&g);
  76286. ExpectPtrEq(p, NULL);
  76287. ExpectPtrEq(q, NULL);
  76288. ExpectPtrEq(g, NULL);
  76289. DH_free(dh);
  76290. dh = NULL;
  76291. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS) && !defined(WOLFSSL_DH_EXTRA)) \
  76292. || (defined(HAVE_FIPS_VERSION) && FIPS_VERSION_GT(2,0))
  76293. #if defined(OPENSSL_ALL) || \
  76294. defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
  76295. dh = wolfSSL_DH_new();
  76296. ExpectNotNull(dh);
  76297. p = wolfSSL_BN_new();
  76298. ExpectNotNull(p);
  76299. ExpectIntEQ(BN_set_word(p, 11), 1);
  76300. g = wolfSSL_BN_new();
  76301. ExpectNotNull(g);
  76302. ExpectIntEQ(BN_set_word(g, 2), 1);
  76303. q = wolfSSL_BN_new();
  76304. ExpectNotNull(q);
  76305. ExpectIntEQ(BN_set_word(q, 5), 1);
  76306. ExpectIntEQ(wolfSSL_DH_set0_pqg(NULL, NULL, NULL, NULL), 0);
  76307. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, NULL, NULL, NULL), 0);
  76308. ExpectIntEQ(wolfSSL_DH_set0_pqg(NULL, p, NULL, NULL), 0);
  76309. ExpectIntEQ(wolfSSL_DH_set0_pqg(NULL, NULL, q, NULL), 0);
  76310. ExpectIntEQ(wolfSSL_DH_set0_pqg(NULL, NULL, NULL, g), 0);
  76311. ExpectIntEQ(wolfSSL_DH_set0_pqg(NULL, p, q, g), 0);
  76312. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, NULL, q, g), 0);
  76313. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, q, NULL), 0);
  76314. /* Don't need q. */
  76315. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, NULL, g), 1);
  76316. if (EXPECT_FAIL()) {
  76317. BN_free(p);
  76318. BN_free(g);
  76319. }
  76320. p = NULL;
  76321. g = NULL;
  76322. /* Setting again will free the p and g. */
  76323. wolfSSL_BN_free(q);
  76324. q = NULL;
  76325. DH_free(dh);
  76326. dh = NULL;
  76327. dh = wolfSSL_DH_new();
  76328. ExpectNotNull(dh);
  76329. p = wolfSSL_BN_new();
  76330. ExpectNotNull(p);
  76331. ExpectIntEQ(BN_set_word(p, 11), 1);
  76332. g = wolfSSL_BN_new();
  76333. ExpectNotNull(g);
  76334. ExpectIntEQ(BN_set_word(g, 2), 1);
  76335. q = wolfSSL_BN_new();
  76336. ExpectNotNull(q);
  76337. ExpectIntEQ(BN_set_word(q, 5), 1);
  76338. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, q, g), 1);
  76339. /* p, q and g are now owned by dh - don't free. */
  76340. if (EXPECT_FAIL()) {
  76341. BN_free(p);
  76342. BN_free(q);
  76343. BN_free(g);
  76344. }
  76345. p = NULL;
  76346. q = NULL;
  76347. g = NULL;
  76348. p = wolfSSL_BN_new();
  76349. ExpectNotNull(p);
  76350. ExpectIntEQ(BN_set_word(p, 11), 1);
  76351. g = wolfSSL_BN_new();
  76352. ExpectNotNull(g);
  76353. ExpectIntEQ(BN_set_word(g, 2), 1);
  76354. q = wolfSSL_BN_new();
  76355. ExpectNotNull(q);
  76356. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, NULL, NULL), 1);
  76357. if (EXPECT_FAIL()) {
  76358. BN_free(p);
  76359. }
  76360. p = NULL;
  76361. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, NULL, q, NULL), 1);
  76362. if (EXPECT_FAIL()) {
  76363. BN_free(q);
  76364. }
  76365. q = NULL;
  76366. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, NULL, NULL, g), 1);
  76367. if (EXPECT_FAIL()) {
  76368. BN_free(g);
  76369. }
  76370. g = NULL;
  76371. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, NULL, NULL, NULL), 1);
  76372. /* p, q and g are now owned by dh - don't free. */
  76373. DH_free(dh);
  76374. dh = NULL;
  76375. ExpectIntEQ(DH_generate_key(NULL), 0);
  76376. ExpectNotNull(dh = DH_new());
  76377. ExpectIntEQ(DH_generate_key(dh), 0);
  76378. p = wolfSSL_BN_new();
  76379. ExpectNotNull(p);
  76380. ExpectIntEQ(BN_set_word(p, 0), 1);
  76381. g = wolfSSL_BN_new();
  76382. ExpectNotNull(g);
  76383. ExpectIntEQ(BN_set_word(g, 2), 1);
  76384. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, NULL, g), 1);
  76385. if (EXPECT_FAIL()) {
  76386. BN_free(p);
  76387. BN_free(g);
  76388. }
  76389. p = NULL;
  76390. g = NULL;
  76391. ExpectIntEQ(DH_generate_key(dh), 0);
  76392. DH_free(dh);
  76393. dh = NULL;
  76394. #endif
  76395. #endif
  76396. /* Test DH_up_ref() */
  76397. dh = wolfSSL_DH_new();
  76398. ExpectNotNull(dh);
  76399. ExpectIntEQ(wolfSSL_DH_up_ref(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  76400. ExpectIntEQ(wolfSSL_DH_up_ref(dh), WOLFSSL_SUCCESS);
  76401. DH_free(dh); /* decrease ref count */
  76402. DH_free(dh); /* free WOLFSSL_DH */
  76403. dh = NULL;
  76404. q = NULL;
  76405. ExpectNull((dh = DH_new_by_nid(NID_sha1)));
  76406. #if (defined(HAVE_PUBLIC_FFDHE) || (defined(HAVE_FIPS) && \
  76407. FIPS_VERSION_EQ(2,0))) || (!defined(HAVE_PUBLIC_FFDHE) && \
  76408. (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0)))
  76409. #ifdef HAVE_FFDHE_2048
  76410. ExpectNotNull((dh = DH_new_by_nid(NID_ffdhe2048)));
  76411. DH_free(dh);
  76412. dh = NULL;
  76413. q = NULL;
  76414. #endif
  76415. #ifdef HAVE_FFDHE_3072
  76416. ExpectNotNull((dh = DH_new_by_nid(NID_ffdhe3072)));
  76417. DH_free(dh);
  76418. dh = NULL;
  76419. q = NULL;
  76420. #endif
  76421. #ifdef HAVE_FFDHE_4096
  76422. ExpectNotNull((dh = DH_new_by_nid(NID_ffdhe4096)));
  76423. DH_free(dh);
  76424. dh = NULL;
  76425. q = NULL;
  76426. #endif
  76427. #else
  76428. ExpectNull((dh = DH_new_by_nid(NID_ffdhe2048)));
  76429. #endif /* (HAVE_PUBLIC_FFDHE || (HAVE_FIPS && HAVE_FIPS_VERSION == 2)) ||
  76430. * (!HAVE_PUBLIC_FFDHE && (!HAVE_FIPS || HAVE_FIPS_VERSION > 2))*/
  76431. ExpectIntEQ(wolfSSL_DH_size(NULL), -1);
  76432. #endif /* OPENSSL_EXTRA && !NO_DH */
  76433. return EXPECT_RESULT();
  76434. }
  76435. static int test_wolfSSL_DH_dup(void)
  76436. {
  76437. EXPECT_DECLS;
  76438. #if !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA)
  76439. #if defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || defined(WOLFSSL_OPENSSH) || \
  76440. defined(OPENSSL_EXTRA)
  76441. DH *dh = NULL;
  76442. DH *dhDup = NULL;
  76443. ExpectNotNull(dh = wolfSSL_DH_new());
  76444. ExpectNull(dhDup = wolfSSL_DH_dup(NULL));
  76445. ExpectNull(dhDup = wolfSSL_DH_dup(dh));
  76446. #if defined(OPENSSL_ALL) || \
  76447. defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
  76448. {
  76449. WOLFSSL_BIGNUM* p = NULL;
  76450. WOLFSSL_BIGNUM* g = NULL;
  76451. ExpectNotNull(p = wolfSSL_BN_new());
  76452. ExpectNotNull(g = wolfSSL_BN_new());
  76453. ExpectIntEQ(wolfSSL_BN_set_word(p, 11), WOLFSSL_SUCCESS);
  76454. ExpectIntEQ(wolfSSL_BN_set_word(g, 2), WOLFSSL_SUCCESS);
  76455. ExpectIntEQ(wolfSSL_DH_set0_pqg(dh, p, NULL, g), 1);
  76456. if (EXPECT_FAIL()) {
  76457. wolfSSL_BN_free(p);
  76458. wolfSSL_BN_free(g);
  76459. }
  76460. ExpectNotNull(dhDup = wolfSSL_DH_dup(dh));
  76461. wolfSSL_DH_free(dhDup);
  76462. }
  76463. #endif
  76464. wolfSSL_DH_free(dh);
  76465. #endif
  76466. #endif
  76467. return EXPECT_RESULT();
  76468. }
  76469. static int test_wolfSSL_DH_check(void)
  76470. {
  76471. EXPECT_DECLS;
  76472. #ifdef OPENSSL_ALL
  76473. #ifndef NO_DH
  76474. #ifndef NO_BIO
  76475. #ifndef NO_DSA
  76476. byte buf[6000];
  76477. char file[] = "./certs/dsaparams.pem";
  76478. XFILE f = XBADFILE;
  76479. int bytes = 0;
  76480. BIO* bio = NULL;
  76481. DSA* dsa = NULL;
  76482. #elif !defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0)
  76483. static const byte dh2048[] = {
  76484. 0x30, 0x82, 0x01, 0x08, 0x02, 0x82, 0x01, 0x01,
  76485. 0x00, 0xb0, 0xa1, 0x08, 0x06, 0x9c, 0x08, 0x13,
  76486. 0xba, 0x59, 0x06, 0x3c, 0xbc, 0x30, 0xd5, 0xf5,
  76487. 0x00, 0xc1, 0x4f, 0x44, 0xa7, 0xd6, 0xef, 0x4a,
  76488. 0xc6, 0x25, 0x27, 0x1c, 0xe8, 0xd2, 0x96, 0x53,
  76489. 0x0a, 0x5c, 0x91, 0xdd, 0xa2, 0xc2, 0x94, 0x84,
  76490. 0xbf, 0x7d, 0xb2, 0x44, 0x9f, 0x9b, 0xd2, 0xc1,
  76491. 0x8a, 0xc5, 0xbe, 0x72, 0x5c, 0xa7, 0xe7, 0x91,
  76492. 0xe6, 0xd4, 0x9f, 0x73, 0x07, 0x85, 0x5b, 0x66,
  76493. 0x48, 0xc7, 0x70, 0xfa, 0xb4, 0xee, 0x02, 0xc9,
  76494. 0x3d, 0x9a, 0x4a, 0xda, 0x3d, 0xc1, 0x46, 0x3e,
  76495. 0x19, 0x69, 0xd1, 0x17, 0x46, 0x07, 0xa3, 0x4d,
  76496. 0x9f, 0x2b, 0x96, 0x17, 0x39, 0x6d, 0x30, 0x8d,
  76497. 0x2a, 0xf3, 0x94, 0xd3, 0x75, 0xcf, 0xa0, 0x75,
  76498. 0xe6, 0xf2, 0x92, 0x1f, 0x1a, 0x70, 0x05, 0xaa,
  76499. 0x04, 0x83, 0x57, 0x30, 0xfb, 0xda, 0x76, 0x93,
  76500. 0x38, 0x50, 0xe8, 0x27, 0xfd, 0x63, 0xee, 0x3c,
  76501. 0xe5, 0xb7, 0xc8, 0x09, 0xae, 0x6f, 0x50, 0x35,
  76502. 0x8e, 0x84, 0xce, 0x4a, 0x00, 0xe9, 0x12, 0x7e,
  76503. 0x5a, 0x31, 0xd7, 0x33, 0xfc, 0x21, 0x13, 0x76,
  76504. 0xcc, 0x16, 0x30, 0xdb, 0x0c, 0xfc, 0xc5, 0x62,
  76505. 0xa7, 0x35, 0xb8, 0xef, 0xb7, 0xb0, 0xac, 0xc0,
  76506. 0x36, 0xf6, 0xd9, 0xc9, 0x46, 0x48, 0xf9, 0x40,
  76507. 0x90, 0x00, 0x2b, 0x1b, 0xaa, 0x6c, 0xe3, 0x1a,
  76508. 0xc3, 0x0b, 0x03, 0x9e, 0x1b, 0xc2, 0x46, 0xe4,
  76509. 0x48, 0x4e, 0x22, 0x73, 0x6f, 0xc3, 0x5f, 0xd4,
  76510. 0x9a, 0xd6, 0x30, 0x07, 0x48, 0xd6, 0x8c, 0x90,
  76511. 0xab, 0xd4, 0xf6, 0xf1, 0xe3, 0x48, 0xd3, 0x58,
  76512. 0x4b, 0xa6, 0xb9, 0xcd, 0x29, 0xbf, 0x68, 0x1f,
  76513. 0x08, 0x4b, 0x63, 0x86, 0x2f, 0x5c, 0x6b, 0xd6,
  76514. 0xb6, 0x06, 0x65, 0xf7, 0xa6, 0xdc, 0x00, 0x67,
  76515. 0x6b, 0xbb, 0xc3, 0xa9, 0x41, 0x83, 0xfb, 0xc7,
  76516. 0xfa, 0xc8, 0xe2, 0x1e, 0x7e, 0xaf, 0x00, 0x3f,
  76517. 0x93, 0x02, 0x01, 0x02
  76518. };
  76519. const byte* params;
  76520. #endif
  76521. DH* dh = NULL;
  76522. WOLFSSL_BIGNUM* p = NULL;
  76523. WOLFSSL_BIGNUM* g = NULL;
  76524. WOLFSSL_BIGNUM* pTmp = NULL;
  76525. WOLFSSL_BIGNUM* gTmp = NULL;
  76526. int codes = -1;
  76527. #ifndef NO_DSA
  76528. /* Initialize DH */
  76529. ExpectTrue((f = XFOPEN(file, "rb")) != XBADFILE);
  76530. ExpectIntGT(bytes = (int)XFREAD(buf, 1, sizeof(buf), f), 0);
  76531. if (f != XBADFILE)
  76532. XFCLOSE(f);
  76533. ExpectNotNull(bio = BIO_new_mem_buf((void*)buf, bytes));
  76534. ExpectNotNull(dsa = wolfSSL_PEM_read_bio_DSAparams(bio, NULL, NULL, NULL));
  76535. ExpectNotNull(dh = wolfSSL_DSA_dup_DH(dsa));
  76536. ExpectNotNull(dh);
  76537. BIO_free(bio);
  76538. DSA_free(dsa);
  76539. #elif !defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0)
  76540. params = dh2048;
  76541. ExpectNotNull(dh = wolfSSL_d2i_DHparams(NULL, &params,
  76542. (long)sizeof(dh2048)));
  76543. #else
  76544. ExpectNotNull(dh = wolfSSL_DH_new_by_nid(NID_ffdhe2048));
  76545. #endif
  76546. /* Test assumed to be valid dh.
  76547. * Should return WOLFSSL_SUCCESS
  76548. * codes should be 0
  76549. * Invalid codes = {DH_NOT_SUITABLE_GENERATOR, DH_CHECK_P_NOT_PRIME}
  76550. */
  76551. ExpectIntEQ(wolfSSL_DH_check(dh, &codes), 1);
  76552. ExpectIntEQ(codes, 0);
  76553. /* Test NULL dh: expected BAD_FUNC_ARG */
  76554. ExpectIntEQ(wolfSSL_DH_check(NULL, &codes), 0);
  76555. /* Break dh prime to test if codes = DH_CHECK_P_NOT_PRIME */
  76556. if (dh != NULL) {
  76557. pTmp = dh->p;
  76558. dh->p = NULL;
  76559. }
  76560. ExpectIntEQ(wolfSSL_DH_check(dh, &codes), 1);
  76561. ExpectIntEQ(wolfSSL_DH_check(dh, NULL), 0);
  76562. ExpectIntEQ(codes, DH_CHECK_P_NOT_PRIME);
  76563. /* set dh->p back to normal so it won't fail on next tests */
  76564. if (dh != NULL) {
  76565. dh->p = pTmp;
  76566. pTmp = NULL;
  76567. }
  76568. /* Break dh generator to test if codes = DH_NOT_SUITABLE_GENERATOR */
  76569. if (dh != NULL) {
  76570. gTmp = dh->g;
  76571. dh->g = NULL;
  76572. }
  76573. ExpectIntEQ(wolfSSL_DH_check(dh, &codes), 1);
  76574. ExpectIntEQ(wolfSSL_DH_check(dh, NULL), 0);
  76575. ExpectIntEQ(codes, DH_NOT_SUITABLE_GENERATOR);
  76576. if (dh != NULL) {
  76577. dh->g = gTmp;
  76578. gTmp = NULL;
  76579. }
  76580. /* Cleanup */
  76581. DH_free(dh);
  76582. dh = NULL;
  76583. dh = DH_new();
  76584. ExpectNotNull(dh);
  76585. /* Check empty DH. */
  76586. ExpectIntEQ(wolfSSL_DH_check(dh, &codes), 1);
  76587. ExpectIntEQ(wolfSSL_DH_check(dh, NULL), 0);
  76588. ExpectIntEQ(codes, DH_NOT_SUITABLE_GENERATOR | DH_CHECK_P_NOT_PRIME);
  76589. /* Check non-prime valued p. */
  76590. ExpectNotNull(p = BN_new());
  76591. ExpectIntEQ(BN_set_word(p, 4), 1);
  76592. ExpectNotNull(g = BN_new());
  76593. ExpectIntEQ(BN_set_word(g, 2), 1);
  76594. ExpectIntEQ(DH_set0_pqg(dh, p, NULL, g), 1);
  76595. if (EXPECT_FAIL()) {
  76596. wolfSSL_BN_free(p);
  76597. wolfSSL_BN_free(g);
  76598. }
  76599. ExpectIntEQ(wolfSSL_DH_check(dh, &codes), 1);
  76600. ExpectIntEQ(wolfSSL_DH_check(dh, NULL), 0);
  76601. ExpectIntEQ(codes, DH_CHECK_P_NOT_PRIME);
  76602. DH_free(dh);
  76603. dh = NULL;
  76604. #endif
  76605. #endif /* !NO_DH && !NO_DSA */
  76606. #endif
  76607. return EXPECT_RESULT();
  76608. }
  76609. static int test_wolfSSL_DH_prime(void)
  76610. {
  76611. EXPECT_DECLS;
  76612. #if defined(OPENSSL_EXTRA) && !defined(NO_DH)
  76613. WOLFSSL_BIGNUM* bn = NULL;
  76614. #if WOLFSSL_MAX_BN_BITS >= 768
  76615. WOLFSSL_BIGNUM* bn2 = NULL;
  76616. #endif
  76617. bn = wolfSSL_DH_768_prime(NULL);
  76618. #if WOLFSSL_MAX_BN_BITS >= 768
  76619. ExpectNotNull(bn);
  76620. bn2 = wolfSSL_DH_768_prime(bn);
  76621. ExpectNotNull(bn2);
  76622. ExpectTrue(bn == bn2);
  76623. wolfSSL_BN_free(bn);
  76624. bn = NULL;
  76625. #else
  76626. ExpectNull(bn);
  76627. #endif
  76628. bn = wolfSSL_DH_1024_prime(NULL);
  76629. #if WOLFSSL_MAX_BN_BITS >= 1024
  76630. ExpectNotNull(bn);
  76631. wolfSSL_BN_free(bn);
  76632. bn = NULL;
  76633. #else
  76634. ExpectNull(bn);
  76635. #endif
  76636. bn = wolfSSL_DH_2048_prime(NULL);
  76637. #if WOLFSSL_MAX_BN_BITS >= 2048
  76638. ExpectNotNull(bn);
  76639. wolfSSL_BN_free(bn);
  76640. bn = NULL;
  76641. #else
  76642. ExpectNull(bn);
  76643. #endif
  76644. bn = wolfSSL_DH_3072_prime(NULL);
  76645. #if WOLFSSL_MAX_BN_BITS >= 3072
  76646. ExpectNotNull(bn);
  76647. wolfSSL_BN_free(bn);
  76648. bn = NULL;
  76649. #else
  76650. ExpectNull(bn);
  76651. #endif
  76652. bn = wolfSSL_DH_4096_prime(NULL);
  76653. #if WOLFSSL_MAX_BN_BITS >= 4096
  76654. ExpectNotNull(bn);
  76655. wolfSSL_BN_free(bn);
  76656. bn = NULL;
  76657. #else
  76658. ExpectNull(bn);
  76659. #endif
  76660. bn = wolfSSL_DH_6144_prime(NULL);
  76661. #if WOLFSSL_MAX_BN_BITS >= 6144
  76662. ExpectNotNull(bn);
  76663. wolfSSL_BN_free(bn);
  76664. bn = NULL;
  76665. #else
  76666. ExpectNull(bn);
  76667. #endif
  76668. bn = wolfSSL_DH_8192_prime(NULL);
  76669. #if WOLFSSL_MAX_BN_BITS >= 8192
  76670. ExpectNotNull(bn);
  76671. wolfSSL_BN_free(bn);
  76672. bn = NULL;
  76673. #else
  76674. ExpectNull(bn);
  76675. #endif
  76676. #endif
  76677. return EXPECT_RESULT();
  76678. }
  76679. static int test_wolfSSL_DH_1536_prime(void)
  76680. {
  76681. EXPECT_DECLS;
  76682. #if defined(OPENSSL_EXTRA) && !defined(NO_DH)
  76683. BIGNUM* bn = NULL;
  76684. unsigned char bits[200];
  76685. int sz = 192; /* known binary size */
  76686. const byte expected[] = {
  76687. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  76688. 0xC9,0x0F,0xDA,0xA2,0x21,0x68,0xC2,0x34,
  76689. 0xC4,0xC6,0x62,0x8B,0x80,0xDC,0x1C,0xD1,
  76690. 0x29,0x02,0x4E,0x08,0x8A,0x67,0xCC,0x74,
  76691. 0x02,0x0B,0xBE,0xA6,0x3B,0x13,0x9B,0x22,
  76692. 0x51,0x4A,0x08,0x79,0x8E,0x34,0x04,0xDD,
  76693. 0xEF,0x95,0x19,0xB3,0xCD,0x3A,0x43,0x1B,
  76694. 0x30,0x2B,0x0A,0x6D,0xF2,0x5F,0x14,0x37,
  76695. 0x4F,0xE1,0x35,0x6D,0x6D,0x51,0xC2,0x45,
  76696. 0xE4,0x85,0xB5,0x76,0x62,0x5E,0x7E,0xC6,
  76697. 0xF4,0x4C,0x42,0xE9,0xA6,0x37,0xED,0x6B,
  76698. 0x0B,0xFF,0x5C,0xB6,0xF4,0x06,0xB7,0xED,
  76699. 0xEE,0x38,0x6B,0xFB,0x5A,0x89,0x9F,0xA5,
  76700. 0xAE,0x9F,0x24,0x11,0x7C,0x4B,0x1F,0xE6,
  76701. 0x49,0x28,0x66,0x51,0xEC,0xE4,0x5B,0x3D,
  76702. 0xC2,0x00,0x7C,0xB8,0xA1,0x63,0xBF,0x05,
  76703. 0x98,0xDA,0x48,0x36,0x1C,0x55,0xD3,0x9A,
  76704. 0x69,0x16,0x3F,0xA8,0xFD,0x24,0xCF,0x5F,
  76705. 0x83,0x65,0x5D,0x23,0xDC,0xA3,0xAD,0x96,
  76706. 0x1C,0x62,0xF3,0x56,0x20,0x85,0x52,0xBB,
  76707. 0x9E,0xD5,0x29,0x07,0x70,0x96,0x96,0x6D,
  76708. 0x67,0x0C,0x35,0x4E,0x4A,0xBC,0x98,0x04,
  76709. 0xF1,0x74,0x6C,0x08,0xCA,0x23,0x73,0x27,
  76710. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  76711. };
  76712. ExpectNotNull(bn = get_rfc3526_prime_1536(NULL));
  76713. ExpectIntEQ(sz, BN_bn2bin((const BIGNUM*)bn, bits));
  76714. ExpectIntEQ(0, XMEMCMP(expected, bits, sz));
  76715. BN_free(bn);
  76716. #endif
  76717. return EXPECT_RESULT();
  76718. }
  76719. static int test_wolfSSL_DH_get_2048_256(void)
  76720. {
  76721. EXPECT_DECLS;
  76722. #if defined(OPENSSL_EXTRA) && !defined(NO_DH)
  76723. WOLFSSL_DH* dh = NULL;
  76724. const WOLFSSL_BIGNUM* pBn;
  76725. const WOLFSSL_BIGNUM* gBn;
  76726. const WOLFSSL_BIGNUM* qBn;
  76727. const byte pExpected[] = {
  76728. 0x87, 0xA8, 0xE6, 0x1D, 0xB4, 0xB6, 0x66, 0x3C, 0xFF, 0xBB, 0xD1, 0x9C,
  76729. 0x65, 0x19, 0x59, 0x99, 0x8C, 0xEE, 0xF6, 0x08, 0x66, 0x0D, 0xD0, 0xF2,
  76730. 0x5D, 0x2C, 0xEE, 0xD4, 0x43, 0x5E, 0x3B, 0x00, 0xE0, 0x0D, 0xF8, 0xF1,
  76731. 0xD6, 0x19, 0x57, 0xD4, 0xFA, 0xF7, 0xDF, 0x45, 0x61, 0xB2, 0xAA, 0x30,
  76732. 0x16, 0xC3, 0xD9, 0x11, 0x34, 0x09, 0x6F, 0xAA, 0x3B, 0xF4, 0x29, 0x6D,
  76733. 0x83, 0x0E, 0x9A, 0x7C, 0x20, 0x9E, 0x0C, 0x64, 0x97, 0x51, 0x7A, 0xBD,
  76734. 0x5A, 0x8A, 0x9D, 0x30, 0x6B, 0xCF, 0x67, 0xED, 0x91, 0xF9, 0xE6, 0x72,
  76735. 0x5B, 0x47, 0x58, 0xC0, 0x22, 0xE0, 0xB1, 0xEF, 0x42, 0x75, 0xBF, 0x7B,
  76736. 0x6C, 0x5B, 0xFC, 0x11, 0xD4, 0x5F, 0x90, 0x88, 0xB9, 0x41, 0xF5, 0x4E,
  76737. 0xB1, 0xE5, 0x9B, 0xB8, 0xBC, 0x39, 0xA0, 0xBF, 0x12, 0x30, 0x7F, 0x5C,
  76738. 0x4F, 0xDB, 0x70, 0xC5, 0x81, 0xB2, 0x3F, 0x76, 0xB6, 0x3A, 0xCA, 0xE1,
  76739. 0xCA, 0xA6, 0xB7, 0x90, 0x2D, 0x52, 0x52, 0x67, 0x35, 0x48, 0x8A, 0x0E,
  76740. 0xF1, 0x3C, 0x6D, 0x9A, 0x51, 0xBF, 0xA4, 0xAB, 0x3A, 0xD8, 0x34, 0x77,
  76741. 0x96, 0x52, 0x4D, 0x8E, 0xF6, 0xA1, 0x67, 0xB5, 0xA4, 0x18, 0x25, 0xD9,
  76742. 0x67, 0xE1, 0x44, 0xE5, 0x14, 0x05, 0x64, 0x25, 0x1C, 0xCA, 0xCB, 0x83,
  76743. 0xE6, 0xB4, 0x86, 0xF6, 0xB3, 0xCA, 0x3F, 0x79, 0x71, 0x50, 0x60, 0x26,
  76744. 0xC0, 0xB8, 0x57, 0xF6, 0x89, 0x96, 0x28, 0x56, 0xDE, 0xD4, 0x01, 0x0A,
  76745. 0xBD, 0x0B, 0xE6, 0x21, 0xC3, 0xA3, 0x96, 0x0A, 0x54, 0xE7, 0x10, 0xC3,
  76746. 0x75, 0xF2, 0x63, 0x75, 0xD7, 0x01, 0x41, 0x03, 0xA4, 0xB5, 0x43, 0x30,
  76747. 0xC1, 0x98, 0xAF, 0x12, 0x61, 0x16, 0xD2, 0x27, 0x6E, 0x11, 0x71, 0x5F,
  76748. 0x69, 0x38, 0x77, 0xFA, 0xD7, 0xEF, 0x09, 0xCA, 0xDB, 0x09, 0x4A, 0xE9,
  76749. 0x1E, 0x1A, 0x15, 0x97
  76750. };
  76751. const byte gExpected[] = {
  76752. 0x3F, 0xB3, 0x2C, 0x9B, 0x73, 0x13, 0x4D, 0x0B, 0x2E, 0x77, 0x50, 0x66,
  76753. 0x60, 0xED, 0xBD, 0x48, 0x4C, 0xA7, 0xB1, 0x8F, 0x21, 0xEF, 0x20, 0x54,
  76754. 0x07, 0xF4, 0x79, 0x3A, 0x1A, 0x0B, 0xA1, 0x25, 0x10, 0xDB, 0xC1, 0x50,
  76755. 0x77, 0xBE, 0x46, 0x3F, 0xFF, 0x4F, 0xED, 0x4A, 0xAC, 0x0B, 0xB5, 0x55,
  76756. 0xBE, 0x3A, 0x6C, 0x1B, 0x0C, 0x6B, 0x47, 0xB1, 0xBC, 0x37, 0x73, 0xBF,
  76757. 0x7E, 0x8C, 0x6F, 0x62, 0x90, 0x12, 0x28, 0xF8, 0xC2, 0x8C, 0xBB, 0x18,
  76758. 0xA5, 0x5A, 0xE3, 0x13, 0x41, 0x00, 0x0A, 0x65, 0x01, 0x96, 0xF9, 0x31,
  76759. 0xC7, 0x7A, 0x57, 0xF2, 0xDD, 0xF4, 0x63, 0xE5, 0xE9, 0xEC, 0x14, 0x4B,
  76760. 0x77, 0x7D, 0xE6, 0x2A, 0xAA, 0xB8, 0xA8, 0x62, 0x8A, 0xC3, 0x76, 0xD2,
  76761. 0x82, 0xD6, 0xED, 0x38, 0x64, 0xE6, 0x79, 0x82, 0x42, 0x8E, 0xBC, 0x83,
  76762. 0x1D, 0x14, 0x34, 0x8F, 0x6F, 0x2F, 0x91, 0x93, 0xB5, 0x04, 0x5A, 0xF2,
  76763. 0x76, 0x71, 0x64, 0xE1, 0xDF, 0xC9, 0x67, 0xC1, 0xFB, 0x3F, 0x2E, 0x55,
  76764. 0xA4, 0xBD, 0x1B, 0xFF, 0xE8, 0x3B, 0x9C, 0x80, 0xD0, 0x52, 0xB9, 0x85,
  76765. 0xD1, 0x82, 0xEA, 0x0A, 0xDB, 0x2A, 0x3B, 0x73, 0x13, 0xD3, 0xFE, 0x14,
  76766. 0xC8, 0x48, 0x4B, 0x1E, 0x05, 0x25, 0x88, 0xB9, 0xB7, 0xD2, 0xBB, 0xD2,
  76767. 0xDF, 0x01, 0x61, 0x99, 0xEC, 0xD0, 0x6E, 0x15, 0x57, 0xCD, 0x09, 0x15,
  76768. 0xB3, 0x35, 0x3B, 0xBB, 0x64, 0xE0, 0xEC, 0x37, 0x7F, 0xD0, 0x28, 0x37,
  76769. 0x0D, 0xF9, 0x2B, 0x52, 0xC7, 0x89, 0x14, 0x28, 0xCD, 0xC6, 0x7E, 0xB6,
  76770. 0x18, 0x4B, 0x52, 0x3D, 0x1D, 0xB2, 0x46, 0xC3, 0x2F, 0x63, 0x07, 0x84,
  76771. 0x90, 0xF0, 0x0E, 0xF8, 0xD6, 0x47, 0xD1, 0x48, 0xD4, 0x79, 0x54, 0x51,
  76772. 0x5E, 0x23, 0x27, 0xCF, 0xEF, 0x98, 0xC5, 0x82, 0x66, 0x4B, 0x4C, 0x0F,
  76773. 0x6C, 0xC4, 0x16, 0x59
  76774. };
  76775. const byte qExpected[] = {
  76776. 0x8C, 0xF8, 0x36, 0x42, 0xA7, 0x09, 0xA0, 0x97, 0xB4, 0x47, 0x99, 0x76,
  76777. 0x40, 0x12, 0x9D, 0xA2, 0x99, 0xB1, 0xA4, 0x7D, 0x1E, 0xB3, 0x75, 0x0B,
  76778. 0xA3, 0x08, 0xB0, 0xFE, 0x64, 0xF5, 0xFB, 0xD3
  76779. };
  76780. int pSz = 0;
  76781. int qSz = 0;
  76782. int gSz = 0;
  76783. byte* pReturned = NULL;
  76784. byte* qReturned = NULL;
  76785. byte* gReturned = NULL;
  76786. ExpectNotNull((dh = wolfSSL_DH_get_2048_256()));
  76787. wolfSSL_DH_get0_pqg(dh, &pBn, &qBn, &gBn);
  76788. ExpectIntGT((pSz = wolfSSL_BN_num_bytes(pBn)), 0);
  76789. ExpectNotNull(pReturned = (byte*)XMALLOC(pSz, NULL,
  76790. DYNAMIC_TYPE_TMP_BUFFER));
  76791. ExpectIntGT((pSz = wolfSSL_BN_bn2bin(pBn, pReturned)), 0);
  76792. ExpectIntEQ(pSz, sizeof(pExpected));
  76793. ExpectIntEQ(XMEMCMP(pExpected, pReturned, pSz), 0);
  76794. ExpectIntGT((qSz = wolfSSL_BN_num_bytes(qBn)), 0);
  76795. ExpectNotNull(qReturned = (byte*)XMALLOC(qSz, NULL,
  76796. DYNAMIC_TYPE_TMP_BUFFER));
  76797. ExpectIntGT((qSz = wolfSSL_BN_bn2bin(qBn, qReturned)), 0);
  76798. ExpectIntEQ(qSz, sizeof(qExpected));
  76799. ExpectIntEQ(XMEMCMP(qExpected, qReturned, qSz), 0);
  76800. ExpectIntGT((gSz = wolfSSL_BN_num_bytes(gBn)), 0);
  76801. ExpectNotNull(gReturned = (byte*)XMALLOC(gSz, NULL,
  76802. DYNAMIC_TYPE_TMP_BUFFER));
  76803. ExpectIntGT((gSz = wolfSSL_BN_bn2bin(gBn, gReturned)), 0);
  76804. ExpectIntEQ(gSz, sizeof(gExpected));
  76805. ExpectIntEQ(XMEMCMP(gExpected, gReturned, gSz), 0);
  76806. wolfSSL_DH_free(dh);
  76807. XFREE(pReturned, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  76808. XFREE(gReturned, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  76809. XFREE(qReturned, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  76810. #endif
  76811. return EXPECT_RESULT();
  76812. }
  76813. static int test_wolfSSL_PEM_write_DHparams(void)
  76814. {
  76815. EXPECT_DECLS;
  76816. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO) && \
  76817. !defined(NO_DH) && defined(WOLFSSL_DH_EXTRA) && !defined(NO_FILESYSTEM)
  76818. DH* dh = NULL;
  76819. BIO* bio = NULL;
  76820. XFILE fp = XBADFILE;
  76821. byte pem[2048];
  76822. int pemSz = 0;
  76823. const char expected[] =
  76824. "-----BEGIN DH PARAMETERS-----\n"
  76825. "MIIBCAKCAQEAsKEIBpwIE7pZBjy8MNX1AMFPRKfW70rGJScc6NKWUwpckd2iwpSE\n"
  76826. "v32yRJ+b0sGKxb5yXKfnkebUn3MHhVtmSMdw+rTuAsk9mkraPcFGPhlp0RdGB6NN\n"
  76827. "nyuWFzltMI0q85TTdc+gdebykh8acAWqBINXMPvadpM4UOgn/WPuPOW3yAmub1A1\n"
  76828. "joTOSgDpEn5aMdcz/CETdswWMNsM/MVipzW477ewrMA29tnJRkj5QJAAKxuqbOMa\n"
  76829. "wwsDnhvCRuRITiJzb8Nf1JrWMAdI1oyQq9T28eNI01hLprnNKb9oHwhLY4YvXGvW\n"
  76830. "tgZl96bcAGdru8OpQYP7x/rI4h5+rwA/kwIBAg==\n"
  76831. "-----END DH PARAMETERS-----\n";
  76832. const char badPem[] =
  76833. "-----BEGIN DH PARAMETERS-----\n"
  76834. "-----END DH PARAMETERS-----\n";
  76835. const char emptySeqPem[] =
  76836. "-----BEGIN DH PARAMETERS-----\n"
  76837. "MAA=\n"
  76838. "-----END DH PARAMETERS-----\n";
  76839. ExpectTrue((fp = XFOPEN(dhParamFile, "rb")) != XBADFILE);
  76840. ExpectIntGT((pemSz = (int)XFREAD(pem, 1, sizeof(pem), fp)), 0);
  76841. if (fp != XBADFILE) {
  76842. XFCLOSE(fp);
  76843. fp = XBADFILE;
  76844. }
  76845. ExpectNull(PEM_read_bio_DHparams(NULL, NULL, NULL, NULL));
  76846. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  76847. ExpectNull(dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL));
  76848. ExpectIntEQ(BIO_write(bio, badPem, (int)sizeof(badPem)),
  76849. (int)sizeof(badPem));
  76850. ExpectNull(dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL));
  76851. BIO_free(bio);
  76852. bio = NULL;
  76853. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  76854. ExpectNull(dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL));
  76855. ExpectIntEQ(BIO_write(bio, emptySeqPem, (int)sizeof(emptySeqPem)),
  76856. (int)sizeof(emptySeqPem));
  76857. ExpectNull(dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL));
  76858. BIO_free(bio);
  76859. bio = NULL;
  76860. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  76861. ExpectIntEQ(BIO_write(bio, pem, pemSz), pemSz);
  76862. ExpectNotNull(dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL));
  76863. BIO_free(bio);
  76864. bio = NULL;
  76865. ExpectNotNull(fp = XFOPEN("./test-write-dhparams.pem", "wb"));
  76866. ExpectIntEQ(PEM_write_DHparams(fp, dh), WOLFSSL_SUCCESS);
  76867. ExpectIntEQ(PEM_write_DHparams(fp, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  76868. DH_free(dh);
  76869. dh = NULL;
  76870. dh = wolfSSL_DH_new();
  76871. ExpectIntEQ(PEM_write_DHparams(fp, dh), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  76872. if (fp != XBADFILE) {
  76873. XFCLOSE(fp);
  76874. fp = XBADFILE;
  76875. }
  76876. wolfSSL_DH_free(dh);
  76877. dh = NULL;
  76878. /* check results */
  76879. XMEMSET(pem, 0, sizeof(pem));
  76880. ExpectTrue((fp = XFOPEN("./test-write-dhparams.pem", "rb")) != XBADFILE);
  76881. ExpectIntGT((pemSz = (int)XFREAD(pem, 1, sizeof(pem), fp)), 0);
  76882. ExpectIntEQ(XMEMCMP(pem, expected, pemSz), 0);
  76883. if (fp != XBADFILE)
  76884. XFCLOSE(fp);
  76885. #endif
  76886. return EXPECT_RESULT();
  76887. }
  76888. static int test_wolfSSL_d2i_DHparams(void)
  76889. {
  76890. EXPECT_DECLS;
  76891. #ifdef OPENSSL_ALL
  76892. #if !defined(NO_DH) && (defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072))
  76893. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  76894. XFILE f = XBADFILE;
  76895. unsigned char buf[4096];
  76896. const unsigned char* pt = buf;
  76897. #ifdef HAVE_FFDHE_2048
  76898. const char* params1 = "./certs/dh2048.der";
  76899. #endif
  76900. #ifdef HAVE_FFDHE_3072
  76901. const char* params2 = "./certs/dh3072.der";
  76902. #endif
  76903. long len = 0;
  76904. WOLFSSL_DH* dh = NULL;
  76905. XMEMSET(buf, 0, sizeof(buf));
  76906. /* Test 2048 bit parameters */
  76907. #ifdef HAVE_FFDHE_2048
  76908. ExpectTrue((f = XFOPEN(params1, "rb")) != XBADFILE);
  76909. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  76910. if (f != XBADFILE) {
  76911. XFCLOSE(f);
  76912. f = XBADFILE;
  76913. }
  76914. /* Valid case */
  76915. ExpectNotNull(dh = wolfSSL_d2i_DHparams(NULL, &pt, len));
  76916. ExpectNotNull(dh->p);
  76917. ExpectNotNull(dh->g);
  76918. ExpectTrue(pt == buf);
  76919. ExpectIntEQ(DH_set_length(NULL, BN_num_bits(dh->p)), 0);
  76920. ExpectIntEQ(DH_set_length(dh, BN_num_bits(dh->p)), 1);
  76921. ExpectIntEQ(DH_generate_key(dh), WOLFSSL_SUCCESS);
  76922. /* Invalid cases */
  76923. ExpectNull(wolfSSL_d2i_DHparams(NULL, NULL, len));
  76924. ExpectNull(wolfSSL_d2i_DHparams(NULL, &pt, -1));
  76925. ExpectNull(wolfSSL_d2i_DHparams(NULL, &pt, 10));
  76926. DH_free(dh);
  76927. dh = NULL;
  76928. *buf = 0;
  76929. pt = buf;
  76930. #endif /* HAVE_FFDHE_2048 */
  76931. /* Test 3072 bit parameters */
  76932. #ifdef HAVE_FFDHE_3072
  76933. ExpectTrue((f = XFOPEN(params2, "rb")) != XBADFILE);
  76934. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  76935. if (f != XBADFILE) {
  76936. XFCLOSE(f);
  76937. f = XBADFILE;
  76938. }
  76939. /* Valid case */
  76940. ExpectNotNull(dh = wolfSSL_d2i_DHparams(&dh, &pt, len));
  76941. ExpectNotNull(dh->p);
  76942. ExpectNotNull(dh->g);
  76943. ExpectTrue(pt != buf);
  76944. ExpectIntEQ(DH_generate_key(dh), 1);
  76945. /* Invalid cases */
  76946. ExpectNull(wolfSSL_d2i_DHparams(NULL, NULL, len));
  76947. ExpectNull(wolfSSL_d2i_DHparams(NULL, &pt, -1));
  76948. DH_free(dh);
  76949. dh = NULL;
  76950. #endif /* HAVE_FFDHE_3072 */
  76951. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  76952. #endif /* !NO_DH */
  76953. #endif
  76954. return EXPECT_RESULT();
  76955. }
  76956. static int test_wolfSSL_DH_LoadDer(void)
  76957. {
  76958. EXPECT_DECLS;
  76959. #if !defined(NO_DH) && (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0)) && \
  76960. defined(OPENSSL_EXTRA)
  76961. static const byte dh2048[] = {
  76962. 0x30, 0x82, 0x01, 0x08, 0x02, 0x82, 0x01, 0x01,
  76963. 0x00, 0xb0, 0xa1, 0x08, 0x06, 0x9c, 0x08, 0x13,
  76964. 0xba, 0x59, 0x06, 0x3c, 0xbc, 0x30, 0xd5, 0xf5,
  76965. 0x00, 0xc1, 0x4f, 0x44, 0xa7, 0xd6, 0xef, 0x4a,
  76966. 0xc6, 0x25, 0x27, 0x1c, 0xe8, 0xd2, 0x96, 0x53,
  76967. 0x0a, 0x5c, 0x91, 0xdd, 0xa2, 0xc2, 0x94, 0x84,
  76968. 0xbf, 0x7d, 0xb2, 0x44, 0x9f, 0x9b, 0xd2, 0xc1,
  76969. 0x8a, 0xc5, 0xbe, 0x72, 0x5c, 0xa7, 0xe7, 0x91,
  76970. 0xe6, 0xd4, 0x9f, 0x73, 0x07, 0x85, 0x5b, 0x66,
  76971. 0x48, 0xc7, 0x70, 0xfa, 0xb4, 0xee, 0x02, 0xc9,
  76972. 0x3d, 0x9a, 0x4a, 0xda, 0x3d, 0xc1, 0x46, 0x3e,
  76973. 0x19, 0x69, 0xd1, 0x17, 0x46, 0x07, 0xa3, 0x4d,
  76974. 0x9f, 0x2b, 0x96, 0x17, 0x39, 0x6d, 0x30, 0x8d,
  76975. 0x2a, 0xf3, 0x94, 0xd3, 0x75, 0xcf, 0xa0, 0x75,
  76976. 0xe6, 0xf2, 0x92, 0x1f, 0x1a, 0x70, 0x05, 0xaa,
  76977. 0x04, 0x83, 0x57, 0x30, 0xfb, 0xda, 0x76, 0x93,
  76978. 0x38, 0x50, 0xe8, 0x27, 0xfd, 0x63, 0xee, 0x3c,
  76979. 0xe5, 0xb7, 0xc8, 0x09, 0xae, 0x6f, 0x50, 0x35,
  76980. 0x8e, 0x84, 0xce, 0x4a, 0x00, 0xe9, 0x12, 0x7e,
  76981. 0x5a, 0x31, 0xd7, 0x33, 0xfc, 0x21, 0x13, 0x76,
  76982. 0xcc, 0x16, 0x30, 0xdb, 0x0c, 0xfc, 0xc5, 0x62,
  76983. 0xa7, 0x35, 0xb8, 0xef, 0xb7, 0xb0, 0xac, 0xc0,
  76984. 0x36, 0xf6, 0xd9, 0xc9, 0x46, 0x48, 0xf9, 0x40,
  76985. 0x90, 0x00, 0x2b, 0x1b, 0xaa, 0x6c, 0xe3, 0x1a,
  76986. 0xc3, 0x0b, 0x03, 0x9e, 0x1b, 0xc2, 0x46, 0xe4,
  76987. 0x48, 0x4e, 0x22, 0x73, 0x6f, 0xc3, 0x5f, 0xd4,
  76988. 0x9a, 0xd6, 0x30, 0x07, 0x48, 0xd6, 0x8c, 0x90,
  76989. 0xab, 0xd4, 0xf6, 0xf1, 0xe3, 0x48, 0xd3, 0x58,
  76990. 0x4b, 0xa6, 0xb9, 0xcd, 0x29, 0xbf, 0x68, 0x1f,
  76991. 0x08, 0x4b, 0x63, 0x86, 0x2f, 0x5c, 0x6b, 0xd6,
  76992. 0xb6, 0x06, 0x65, 0xf7, 0xa6, 0xdc, 0x00, 0x67,
  76993. 0x6b, 0xbb, 0xc3, 0xa9, 0x41, 0x83, 0xfb, 0xc7,
  76994. 0xfa, 0xc8, 0xe2, 0x1e, 0x7e, 0xaf, 0x00, 0x3f,
  76995. 0x93, 0x02, 0x01, 0x02
  76996. };
  76997. WOLFSSL_DH* dh = NULL;
  76998. ExpectNotNull(dh = wolfSSL_DH_new());
  76999. ExpectIntEQ(wolfSSL_DH_LoadDer(NULL, NULL, 0), -1);
  77000. ExpectIntEQ(wolfSSL_DH_LoadDer(dh, NULL, 0), -1);
  77001. ExpectIntEQ(wolfSSL_DH_LoadDer(NULL, dh2048, sizeof(dh2048)), -1);
  77002. ExpectIntEQ(wolfSSL_DH_LoadDer(dh, dh2048, sizeof(dh2048)), 1);
  77003. wolfSSL_DH_free(dh);
  77004. #endif
  77005. return EXPECT_RESULT();
  77006. }
  77007. static int test_wolfSSL_i2d_DHparams(void)
  77008. {
  77009. EXPECT_DECLS;
  77010. #ifdef OPENSSL_ALL
  77011. #if !defined(NO_DH) && (defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072))
  77012. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  77013. XFILE f = XBADFILE;
  77014. unsigned char buf[4096];
  77015. const unsigned char* pt;
  77016. unsigned char* pt2;
  77017. #ifdef HAVE_FFDHE_2048
  77018. const char* params1 = "./certs/dh2048.der";
  77019. #endif
  77020. #ifdef HAVE_FFDHE_3072
  77021. const char* params2 = "./certs/dh3072.der";
  77022. #endif
  77023. long len = 0;
  77024. WOLFSSL_DH* dh = NULL;
  77025. /* Test 2048 bit parameters */
  77026. #ifdef HAVE_FFDHE_2048
  77027. pt = buf;
  77028. pt2 = buf;
  77029. ExpectTrue((f = XFOPEN(params1, "rb")) != XBADFILE);
  77030. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  77031. if (f != XBADFILE) {
  77032. XFCLOSE(f);
  77033. f = XBADFILE;
  77034. }
  77035. /* Valid case */
  77036. ExpectNotNull(dh = wolfSSL_d2i_DHparams(NULL, &pt, len));
  77037. ExpectTrue(pt == buf);
  77038. ExpectIntEQ(DH_generate_key(dh), 1);
  77039. ExpectIntEQ(wolfSSL_i2d_DHparams(dh, &pt2), 268);
  77040. /* Invalid case */
  77041. ExpectIntEQ(wolfSSL_i2d_DHparams(NULL, &pt2), 0);
  77042. /* Return length only */
  77043. ExpectIntEQ(wolfSSL_i2d_DHparams(dh, NULL), 268);
  77044. DH_free(dh);
  77045. dh = NULL;
  77046. *buf = 0;
  77047. #endif
  77048. /* Test 3072 bit parameters */
  77049. #ifdef HAVE_FFDHE_3072
  77050. pt = buf;
  77051. pt2 = buf;
  77052. ExpectTrue((f = XFOPEN(params2, "rb")) != XBADFILE);
  77053. ExpectTrue((len = (long)XFREAD(buf, 1, sizeof(buf), f)) > 0);
  77054. if (f != XBADFILE) {
  77055. XFCLOSE(f);
  77056. f = XBADFILE;
  77057. }
  77058. /* Valid case */
  77059. ExpectNotNull(dh = wolfSSL_d2i_DHparams(NULL, &pt, len));
  77060. ExpectTrue(pt == buf);
  77061. ExpectIntEQ(DH_generate_key(dh), 1);
  77062. ExpectIntEQ(wolfSSL_i2d_DHparams(dh, &pt2), 396);
  77063. /* Invalid case */
  77064. ExpectIntEQ(wolfSSL_i2d_DHparams(NULL, &pt2), 0);
  77065. /* Return length only */
  77066. ExpectIntEQ(wolfSSL_i2d_DHparams(dh, NULL), 396);
  77067. DH_free(dh);
  77068. dh = NULL;
  77069. #endif
  77070. dh = DH_new();
  77071. ExpectNotNull(dh);
  77072. pt2 = buf;
  77073. ExpectIntEQ(wolfSSL_i2d_DHparams(dh, &pt2), 0);
  77074. DH_free(dh);
  77075. dh = NULL;
  77076. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  77077. #endif /* !NO_DH && (HAVE_FFDHE_2048 || HAVE_FFDHE_3072) */
  77078. #endif
  77079. return EXPECT_RESULT();
  77080. }
  77081. #if defined(HAVE_ECC) && !defined(OPENSSL_NO_PK)
  77082. /*----------------------------------------------------------------------------*
  77083. | EC
  77084. *----------------------------------------------------------------------------*/
  77085. static int test_wolfSSL_EC_GROUP(void)
  77086. {
  77087. EXPECT_DECLS;
  77088. #ifdef OPENSSL_EXTRA
  77089. EC_GROUP *group = NULL;
  77090. EC_GROUP *group2 = NULL;
  77091. EC_GROUP *group3 = NULL;
  77092. #ifndef HAVE_ECC_BRAINPOOL
  77093. EC_GROUP *group4 = NULL;
  77094. #endif
  77095. WOLFSSL_BIGNUM* order = NULL;
  77096. int group_bits;
  77097. int i;
  77098. static const int knownEccNids[] = {
  77099. NID_X9_62_prime192v1,
  77100. NID_X9_62_prime192v2,
  77101. NID_X9_62_prime192v3,
  77102. NID_X9_62_prime239v1,
  77103. NID_X9_62_prime239v2,
  77104. NID_X9_62_prime239v3,
  77105. NID_X9_62_prime256v1,
  77106. NID_secp112r1,
  77107. NID_secp112r2,
  77108. NID_secp128r1,
  77109. NID_secp128r2,
  77110. NID_secp160r1,
  77111. NID_secp160r2,
  77112. NID_secp224r1,
  77113. NID_secp384r1,
  77114. NID_secp521r1,
  77115. NID_secp160k1,
  77116. NID_secp192k1,
  77117. NID_secp224k1,
  77118. NID_secp256k1,
  77119. NID_brainpoolP160r1,
  77120. NID_brainpoolP192r1,
  77121. NID_brainpoolP224r1,
  77122. NID_brainpoolP256r1,
  77123. NID_brainpoolP320r1,
  77124. NID_brainpoolP384r1,
  77125. NID_brainpoolP512r1,
  77126. };
  77127. int knowEccNidsLen = (int)(sizeof(knownEccNids) / sizeof(*knownEccNids));
  77128. static const int knownEccEnums[] = {
  77129. ECC_SECP192R1,
  77130. ECC_PRIME192V2,
  77131. ECC_PRIME192V3,
  77132. ECC_PRIME239V1,
  77133. ECC_PRIME239V2,
  77134. ECC_PRIME239V3,
  77135. ECC_SECP256R1,
  77136. ECC_SECP112R1,
  77137. ECC_SECP112R2,
  77138. ECC_SECP128R1,
  77139. ECC_SECP128R2,
  77140. ECC_SECP160R1,
  77141. ECC_SECP160R2,
  77142. ECC_SECP224R1,
  77143. ECC_SECP384R1,
  77144. ECC_SECP521R1,
  77145. ECC_SECP160K1,
  77146. ECC_SECP192K1,
  77147. ECC_SECP224K1,
  77148. ECC_SECP256K1,
  77149. ECC_BRAINPOOLP160R1,
  77150. ECC_BRAINPOOLP192R1,
  77151. ECC_BRAINPOOLP224R1,
  77152. ECC_BRAINPOOLP256R1,
  77153. ECC_BRAINPOOLP320R1,
  77154. ECC_BRAINPOOLP384R1,
  77155. ECC_BRAINPOOLP512R1,
  77156. };
  77157. int knowEccEnumsLen = (int)(sizeof(knownEccEnums) / sizeof(*knownEccEnums));
  77158. ExpectNotNull(group = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
  77159. ExpectNotNull(group2 = EC_GROUP_dup(group));
  77160. ExpectNotNull(group3 = wolfSSL_EC_GROUP_new_by_curve_name(NID_secp384r1));
  77161. #ifndef HAVE_ECC_BRAINPOOL
  77162. ExpectNotNull(group4 = wolfSSL_EC_GROUP_new_by_curve_name(
  77163. NID_brainpoolP256r1));
  77164. #endif
  77165. ExpectNull(EC_GROUP_dup(NULL));
  77166. ExpectIntEQ(wolfSSL_EC_GROUP_get_curve_name(NULL), 0);
  77167. ExpectIntEQ(wolfSSL_EC_GROUP_get_curve_name(group), NID_X9_62_prime256v1);
  77168. ExpectIntEQ((group_bits = EC_GROUP_order_bits(NULL)), 0);
  77169. ExpectIntEQ((group_bits = EC_GROUP_order_bits(group)), 256);
  77170. #ifndef HAVE_ECC_BRAINPOOL
  77171. ExpectIntEQ((group_bits = EC_GROUP_order_bits(group4)), 0);
  77172. #endif
  77173. ExpectIntEQ(wolfSSL_EC_GROUP_get_degree(NULL), 0);
  77174. ExpectIntEQ(wolfSSL_EC_GROUP_get_degree(group), 256);
  77175. ExpectNotNull(order = BN_new());
  77176. ExpectIntEQ(wolfSSL_EC_GROUP_get_order(NULL, NULL, NULL), 0);
  77177. ExpectIntEQ(wolfSSL_EC_GROUP_get_order(group, NULL, NULL), 0);
  77178. ExpectIntEQ(wolfSSL_EC_GROUP_get_order(NULL, order, NULL), 0);
  77179. ExpectIntEQ(wolfSSL_EC_GROUP_get_order(group, order, NULL), 1);
  77180. wolfSSL_BN_free(order);
  77181. ExpectNotNull(EC_GROUP_method_of(group));
  77182. ExpectIntEQ(EC_METHOD_get_field_type(NULL), 0);
  77183. ExpectIntEQ(EC_METHOD_get_field_type(EC_GROUP_method_of(group)),
  77184. NID_X9_62_prime_field);
  77185. ExpectIntEQ(wolfSSL_EC_GROUP_cmp(NULL, NULL, NULL), -1);
  77186. ExpectIntEQ(wolfSSL_EC_GROUP_cmp(group, NULL, NULL), -1);
  77187. ExpectIntEQ(wolfSSL_EC_GROUP_cmp(NULL, group, NULL), -1);
  77188. ExpectIntEQ(wolfSSL_EC_GROUP_cmp(group, group3, NULL), 1);
  77189. #ifndef NO_WOLFSSL_STUB
  77190. wolfSSL_EC_GROUP_set_asn1_flag(group, OPENSSL_EC_NAMED_CURVE);
  77191. #endif
  77192. #ifndef HAVE_ECC_BRAINPOOL
  77193. EC_GROUP_free(group4);
  77194. #endif
  77195. EC_GROUP_free(group3);
  77196. EC_GROUP_free(group2);
  77197. EC_GROUP_free(group);
  77198. for (i = 0; i < knowEccNidsLen; i++) {
  77199. group = NULL;
  77200. ExpectNotNull(group = EC_GROUP_new_by_curve_name(knownEccNids[i]));
  77201. ExpectIntGT(wolfSSL_EC_GROUP_get_degree(group), 0);
  77202. EC_GROUP_free(group);
  77203. }
  77204. for (i = 0; i < knowEccEnumsLen; i++) {
  77205. group = NULL;
  77206. ExpectNotNull(group = EC_GROUP_new_by_curve_name(knownEccEnums[i]));
  77207. ExpectIntEQ(wolfSSL_EC_GROUP_get_curve_name(group), knownEccNids[i]);
  77208. EC_GROUP_free(group);
  77209. }
  77210. #endif
  77211. return EXPECT_RESULT();
  77212. }
  77213. static int test_wolfSSL_PEM_read_bio_ECPKParameters(void)
  77214. {
  77215. EXPECT_DECLS;
  77216. #if !defined(NO_FILESYSTEM) && defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  77217. EC_GROUP *group = NULL;
  77218. BIO* bio = NULL;
  77219. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && \
  77220. ECC_MIN_KEY_SZ <= 384 && !defined(NO_ECC_SECP)
  77221. EC_GROUP *ret = NULL;
  77222. static char ec_nc_p384[] = "-----BEGIN EC PARAMETERS-----\n"
  77223. "BgUrgQQAIg==\n"
  77224. "-----END EC PARAMETERS-----";
  77225. #endif
  77226. static char ec_nc_bad_1[] = "-----BEGIN EC PARAMETERS-----\n"
  77227. "MAA=\n"
  77228. "-----END EC PARAMETERS-----";
  77229. static char ec_nc_bad_2[] = "-----BEGIN EC PARAMETERS-----\n"
  77230. "BgA=\n"
  77231. "-----END EC PARAMETERS-----";
  77232. static char ec_nc_bad_3[] = "-----BEGIN EC PARAMETERS-----\n"
  77233. "BgE=\n"
  77234. "-----END EC PARAMETERS-----";
  77235. static char ec_nc_bad_4[] = "-----BEGIN EC PARAMETERS-----\n"
  77236. "BgE*\n"
  77237. "-----END EC PARAMETERS-----";
  77238. /* Test that first parameter, bio, being NULL fails. */
  77239. ExpectNull(PEM_read_bio_ECPKParameters(NULL, NULL, NULL, NULL));
  77240. /* Test that reading named parameters works. */
  77241. ExpectNotNull(bio = BIO_new(BIO_s_file()));
  77242. ExpectIntEQ(BIO_read_filename(bio, eccKeyFile), WOLFSSL_SUCCESS);
  77243. ExpectNotNull(group = PEM_read_bio_ECPKParameters(bio, NULL, NULL, NULL));
  77244. ExpectIntEQ(EC_GROUP_get_curve_name(group), NID_X9_62_prime256v1);
  77245. BIO_free(bio);
  77246. bio = NULL;
  77247. EC_GROUP_free(group);
  77248. group = NULL;
  77249. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && \
  77250. ECC_MIN_KEY_SZ <= 384 && !defined(NO_ECC_SECP)
  77251. /* Test that reusing group works. */
  77252. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_p384,
  77253. sizeof(ec_nc_p384)));
  77254. ExpectNotNull(group = PEM_read_bio_ECPKParameters(bio, &group, NULL, NULL));
  77255. ExpectIntEQ(EC_GROUP_get_curve_name(group), NID_secp384r1);
  77256. BIO_free(bio);
  77257. bio = NULL;
  77258. EC_GROUP_free(group);
  77259. group = NULL;
  77260. /* Test that returning through group works. */
  77261. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_p384,
  77262. sizeof(ec_nc_p384)));
  77263. ExpectNotNull(ret = PEM_read_bio_ECPKParameters(bio, &group, NULL, NULL));
  77264. ExpectIntEQ(group == ret, 1);
  77265. ExpectIntEQ(EC_GROUP_get_curve_name(group), NID_secp384r1);
  77266. BIO_free(bio);
  77267. bio = NULL;
  77268. EC_GROUP_free(group);
  77269. group = NULL;
  77270. #endif
  77271. /* Test 0x30, 0x00 (not and object id) fails. */
  77272. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_bad_1,
  77273. sizeof(ec_nc_bad_1)));
  77274. ExpectNull(PEM_read_bio_ECPKParameters(bio, NULL, NULL, NULL));
  77275. BIO_free(bio);
  77276. bio = NULL;
  77277. /* Test 0x06, 0x00 (empty object id) fails. */
  77278. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_bad_2,
  77279. sizeof(ec_nc_bad_2)));
  77280. ExpectNull(PEM_read_bio_ECPKParameters(bio, NULL, NULL, NULL));
  77281. BIO_free(bio);
  77282. bio = NULL;
  77283. /* Test 0x06, 0x01 (badly formed object id) fails. */
  77284. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_bad_3,
  77285. sizeof(ec_nc_bad_3)));
  77286. ExpectNull(PEM_read_bio_ECPKParameters(bio, NULL, NULL, NULL));
  77287. BIO_free(bio);
  77288. bio = NULL;
  77289. /* Test invalid PEM encoding - invalid character. */
  77290. ExpectNotNull(bio = BIO_new_mem_buf((unsigned char*)ec_nc_bad_4,
  77291. sizeof(ec_nc_bad_4)));
  77292. ExpectNull(PEM_read_bio_ECPKParameters(bio, NULL, NULL, NULL));
  77293. BIO_free(bio);
  77294. #endif
  77295. return EXPECT_RESULT();
  77296. }
  77297. static int test_wolfSSL_EC_POINT(void)
  77298. {
  77299. EXPECT_DECLS;
  77300. #if !defined(WOLFSSL_SP_MATH) && \
  77301. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2)))
  77302. #ifdef OPENSSL_EXTRA
  77303. BN_CTX* ctx = NULL;
  77304. EC_GROUP* group = NULL;
  77305. #ifndef HAVE_ECC_BRAINPOOL
  77306. EC_GROUP* group2 = NULL;
  77307. #endif
  77308. EC_POINT* Gxy = NULL;
  77309. EC_POINT* new_point = NULL;
  77310. EC_POINT* set_point = NULL;
  77311. EC_POINT* get_point = NULL;
  77312. EC_POINT* infinity = NULL;
  77313. BIGNUM* k = NULL;
  77314. BIGNUM* Gx = NULL;
  77315. BIGNUM* Gy = NULL;
  77316. BIGNUM* Gz = NULL;
  77317. BIGNUM* X = NULL;
  77318. BIGNUM* Y = NULL;
  77319. BIGNUM* set_point_bn = NULL;
  77320. char* hexStr = NULL;
  77321. const char* kTest = "F4F8338AFCC562C5C3F3E1E46A7EFECD"
  77322. "17AF381913FF7A96314EA47055EA0FD0";
  77323. /* NISTP256R1 Gx/Gy */
  77324. const char* kGx = "6B17D1F2E12C4247F8BCE6E563A440F2"
  77325. "77037D812DEB33A0F4A13945D898C296";
  77326. const char* kGy = "4FE342E2FE1A7F9B8EE7EB4A7C0F9E16"
  77327. "2BCE33576B315ECECBB6406837BF51F5";
  77328. const char* uncompG
  77329. = "046B17D1F2E12C4247F8BCE6E563A440F2"
  77330. "77037D812DEB33A0F4A13945D898C296"
  77331. "4FE342E2FE1A7F9B8EE7EB4A7C0F9E16"
  77332. "2BCE33576B315ECECBB6406837BF51F5";
  77333. const char* compG
  77334. = "036B17D1F2E12C4247F8BCE6E563A440F2"
  77335. "77037D812DEB33A0F4A13945D898C296";
  77336. #ifndef HAVE_SELFTEST
  77337. EC_POINT *tmp = NULL;
  77338. size_t bin_len;
  77339. unsigned int blen = 0;
  77340. unsigned char* buf = NULL;
  77341. unsigned char bufInf[1] = { 0x00 };
  77342. const unsigned char binUncompG[] = {
  77343. 0x04, 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc,
  77344. 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2, 0x77, 0x03, 0x7d, 0x81, 0x2d,
  77345. 0xeb, 0x33, 0xa0, 0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
  77346. 0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b, 0x8e, 0xe7, 0xeb,
  77347. 0x4a, 0x7c, 0x0f, 0x9e, 0x16, 0x2b, 0xce, 0x33, 0x57, 0x6b, 0x31,
  77348. 0x5e, 0xce, 0xcb, 0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf5,
  77349. };
  77350. const unsigned char binUncompGBad[] = {
  77351. 0x09, 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc,
  77352. 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2, 0x77, 0x03, 0x7d, 0x81, 0x2d,
  77353. 0xeb, 0x33, 0xa0, 0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
  77354. 0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b, 0x8e, 0xe7, 0xeb,
  77355. 0x4a, 0x7c, 0x0f, 0x9e, 0x16, 0x2b, 0xce, 0x33, 0x57, 0x6b, 0x31,
  77356. 0x5e, 0xce, 0xcb, 0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf5,
  77357. };
  77358. #ifdef HAVE_COMP_KEY
  77359. const unsigned char binCompG[] = {
  77360. 0x03, 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc,
  77361. 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2, 0x77, 0x03, 0x7d, 0x81, 0x2d,
  77362. 0xeb, 0x33, 0xa0, 0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
  77363. };
  77364. #endif
  77365. #endif
  77366. ExpectNotNull(ctx = BN_CTX_new());
  77367. ExpectNotNull(group = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
  77368. #ifndef HAVE_ECC_BRAINPOOL
  77369. /* Used to make groups curve_idx == -1. */
  77370. ExpectNotNull(group2 = EC_GROUP_new_by_curve_name(NID_brainpoolP256r1));
  77371. #endif
  77372. ExpectNull(EC_POINT_new(NULL));
  77373. ExpectNotNull(Gxy = EC_POINT_new(group));
  77374. ExpectNotNull(new_point = EC_POINT_new(group));
  77375. ExpectNotNull(set_point = EC_POINT_new(group));
  77376. ExpectNotNull(X = BN_new());
  77377. ExpectNotNull(Y = BN_new());
  77378. ExpectNotNull(set_point_bn = BN_new());
  77379. ExpectNotNull(infinity = EC_POINT_new(group));
  77380. /* load test values */
  77381. ExpectIntEQ(BN_hex2bn(&k, kTest), WOLFSSL_SUCCESS);
  77382. ExpectIntEQ(BN_hex2bn(&Gx, kGx), WOLFSSL_SUCCESS);
  77383. ExpectIntEQ(BN_hex2bn(&Gy, kGy), WOLFSSL_SUCCESS);
  77384. ExpectIntEQ(BN_hex2bn(&Gz, "1"), WOLFSSL_SUCCESS);
  77385. /* populate coordinates for input point */
  77386. if (Gxy != NULL) {
  77387. Gxy->X = Gx;
  77388. Gxy->Y = Gy;
  77389. Gxy->Z = Gz;
  77390. }
  77391. /* Test handling of NULL point. */
  77392. EC_POINT_clear_free(NULL);
  77393. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(NULL, NULL,
  77394. NULL, NULL, ctx), 0);
  77395. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(group, NULL,
  77396. NULL, NULL, ctx), 0);
  77397. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(NULL, Gxy,
  77398. NULL, NULL, ctx), 0);
  77399. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(NULL, NULL,
  77400. X, NULL, ctx), 0);
  77401. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(NULL, NULL,
  77402. NULL, Y, ctx), 0);
  77403. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(NULL, Gxy,
  77404. X, Y, ctx), 0);
  77405. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(group, NULL,
  77406. X, Y, ctx), 0);
  77407. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(group, Gxy,
  77408. NULL, Y, ctx), 0);
  77409. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(group, Gxy,
  77410. X, NULL, ctx), 0);
  77411. /* Getting point at infinity returns an error. */
  77412. ExpectIntEQ(wolfSSL_EC_POINT_get_affine_coordinates_GFp(group, infinity,
  77413. X, Y, ctx), 0);
  77414. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  77415. !defined(HAVE_SELFTEST) && !defined(WOLFSSL_SP_MATH) && \
  77416. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  77417. ExpectIntEQ(EC_POINT_add(NULL, NULL, NULL, NULL, ctx), 0);
  77418. ExpectIntEQ(EC_POINT_add(group, NULL, NULL, NULL, ctx), 0);
  77419. ExpectIntEQ(EC_POINT_add(NULL, new_point, NULL, NULL, ctx), 0);
  77420. ExpectIntEQ(EC_POINT_add(NULL, NULL, new_point, NULL, ctx), 0);
  77421. ExpectIntEQ(EC_POINT_add(NULL, NULL, NULL, Gxy, ctx), 0);
  77422. ExpectIntEQ(EC_POINT_add(NULL, new_point, new_point, Gxy, ctx), 0);
  77423. ExpectIntEQ(EC_POINT_add(group, NULL, new_point, Gxy, ctx), 0);
  77424. ExpectIntEQ(EC_POINT_add(group, new_point, NULL, Gxy, ctx), 0);
  77425. ExpectIntEQ(EC_POINT_add(group, new_point, new_point, NULL, ctx), 0);
  77426. ExpectIntEQ(EC_POINT_mul(NULL, NULL, Gx, Gxy, k, ctx), 0);
  77427. ExpectIntEQ(EC_POINT_mul(NULL, new_point, Gx, Gxy, k, ctx), 0);
  77428. ExpectIntEQ(EC_POINT_mul(group, NULL, Gx, Gxy, k, ctx), 0);
  77429. ExpectIntEQ(EC_POINT_add(group, new_point, new_point, Gxy, ctx), 1);
  77430. /* perform point multiplication */
  77431. ExpectIntEQ(EC_POINT_mul(group, new_point, Gx, Gxy, k, ctx), 1);
  77432. ExpectIntEQ(BN_is_zero(new_point->X), 0);
  77433. ExpectIntEQ(BN_is_zero(new_point->Y), 0);
  77434. ExpectIntEQ(BN_is_zero(new_point->Z), 0);
  77435. ExpectIntEQ(EC_POINT_mul(group, new_point, NULL, Gxy, k, ctx), 1);
  77436. ExpectIntEQ(BN_is_zero(new_point->X), 0);
  77437. ExpectIntEQ(BN_is_zero(new_point->Y), 0);
  77438. ExpectIntEQ(BN_is_zero(new_point->Z), 0);
  77439. ExpectIntEQ(EC_POINT_mul(group, new_point, Gx, NULL, NULL, ctx), 1);
  77440. ExpectIntEQ(BN_is_zero(new_point->X), 0);
  77441. ExpectIntEQ(BN_is_zero(new_point->Y), 0);
  77442. ExpectIntEQ(BN_is_zero(new_point->Z), 0);
  77443. ExpectIntEQ(EC_POINT_mul(group, new_point, NULL, NULL, NULL, ctx), 1);
  77444. ExpectIntEQ(BN_is_zero(new_point->X), 1);
  77445. ExpectIntEQ(BN_is_zero(new_point->Y), 1);
  77446. ExpectIntEQ(BN_is_zero(new_point->Z), 1);
  77447. /* Set point to something. */
  77448. ExpectIntEQ(EC_POINT_add(group, new_point, Gxy, Gxy, ctx), 1);
  77449. #else
  77450. ExpectIntEQ(EC_POINT_set_affine_coordinates_GFp(group, new_point, Gx, Gy,
  77451. ctx), 1);
  77452. ExpectIntEQ(BN_is_zero(new_point->X), 0);
  77453. ExpectIntEQ(BN_is_zero(new_point->Y), 0);
  77454. ExpectIntEQ(BN_is_zero(new_point->Z), 0);
  77455. #endif
  77456. /* check if point X coordinate is zero */
  77457. ExpectIntEQ(BN_is_zero(new_point->X), 0);
  77458. #if defined(USE_ECC_B_PARAM) && !defined(HAVE_SELFTEST) && \
  77459. (!defined(HAVE_FIPS) || FIPS_VERSION_GT(2,0))
  77460. ExpectIntEQ(EC_POINT_is_on_curve(group, new_point, ctx), 1);
  77461. #endif
  77462. /* extract the coordinates from point */
  77463. ExpectIntEQ(EC_POINT_get_affine_coordinates_GFp(group, new_point, X, Y,
  77464. ctx), WOLFSSL_SUCCESS);
  77465. /* check if point X coordinate is zero */
  77466. ExpectIntEQ(BN_is_zero(X), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  77467. /* set the same X and Y points in another object */
  77468. ExpectIntEQ(EC_POINT_set_affine_coordinates_GFp(group, set_point, X, Y,
  77469. ctx), WOLFSSL_SUCCESS);
  77470. /* compare points as they should be the same */
  77471. ExpectIntEQ(EC_POINT_cmp(NULL, NULL, NULL, ctx), -1);
  77472. ExpectIntEQ(EC_POINT_cmp(group, NULL, NULL, ctx), -1);
  77473. ExpectIntEQ(EC_POINT_cmp(NULL, new_point, NULL, ctx), -1);
  77474. ExpectIntEQ(EC_POINT_cmp(NULL, NULL, set_point, ctx), -1);
  77475. ExpectIntEQ(EC_POINT_cmp(NULL, new_point, set_point, ctx), -1);
  77476. ExpectIntEQ(EC_POINT_cmp(group, NULL, set_point, ctx), -1);
  77477. ExpectIntEQ(EC_POINT_cmp(group, new_point, NULL, ctx), -1);
  77478. ExpectIntEQ(EC_POINT_cmp(group, new_point, set_point, ctx), 0);
  77479. /* Test copying */
  77480. ExpectIntEQ(EC_POINT_copy(NULL, NULL), 0);
  77481. ExpectIntEQ(EC_POINT_copy(NULL, set_point), 0);
  77482. ExpectIntEQ(EC_POINT_copy(new_point, NULL), 0);
  77483. ExpectIntEQ(EC_POINT_copy(new_point, set_point), 1);
  77484. /* Test inverting */
  77485. ExpectIntEQ(EC_POINT_invert(NULL, NULL, ctx), 0);
  77486. ExpectIntEQ(EC_POINT_invert(NULL, new_point, ctx), 0);
  77487. ExpectIntEQ(EC_POINT_invert(group, NULL, ctx), 0);
  77488. ExpectIntEQ(EC_POINT_invert(group, new_point, ctx), 1);
  77489. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  77490. !defined(HAVE_SELFTEST) && !defined(WOLFSSL_SP_MATH) && \
  77491. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  77492. {
  77493. EC_POINT* orig_point = NULL;
  77494. ExpectNotNull(orig_point = EC_POINT_new(group));
  77495. ExpectIntEQ(EC_POINT_add(group, orig_point, set_point, set_point, NULL),
  77496. 1);
  77497. /* new_point should be set_point inverted so adding it will revert
  77498. * the point back to set_point */
  77499. ExpectIntEQ(EC_POINT_add(group, orig_point, orig_point, new_point,
  77500. NULL), 1);
  77501. ExpectIntEQ(EC_POINT_cmp(group, orig_point, set_point, NULL), 0);
  77502. EC_POINT_free(orig_point);
  77503. }
  77504. #endif
  77505. /* Test getting affine converts from projective. */
  77506. ExpectIntEQ(EC_POINT_copy(set_point, new_point), 1);
  77507. /* Force non-affine coordinates */
  77508. ExpectIntEQ(BN_add(new_point->Z, (WOLFSSL_BIGNUM*)BN_value_one(),
  77509. (WOLFSSL_BIGNUM*)BN_value_one()), 1);
  77510. if (new_point != NULL) {
  77511. new_point->inSet = 0;
  77512. }
  77513. /* extract the coordinates from point */
  77514. ExpectIntEQ(EC_POINT_get_affine_coordinates_GFp(group, new_point, X, Y,
  77515. ctx), WOLFSSL_SUCCESS);
  77516. /* check if point ordinates have changed. */
  77517. ExpectIntNE(BN_cmp(X, set_point->X), 0);
  77518. ExpectIntNE(BN_cmp(Y, set_point->Y), 0);
  77519. /* Test check for infinity */
  77520. #ifndef WOLF_CRYPTO_CB_ONLY_ECC
  77521. ExpectIntEQ(EC_POINT_is_at_infinity(NULL, NULL), 0);
  77522. ExpectIntEQ(EC_POINT_is_at_infinity(NULL, infinity), 0);
  77523. ExpectIntEQ(EC_POINT_is_at_infinity(group, NULL), 0);
  77524. ExpectIntEQ(EC_POINT_is_at_infinity(group, infinity), 1);
  77525. ExpectIntEQ(EC_POINT_is_at_infinity(group, Gxy), 0);
  77526. #else
  77527. ExpectIntEQ(EC_POINT_is_at_infinity(group, infinity), 0);
  77528. #endif
  77529. ExpectPtrEq(EC_POINT_point2bn(group, set_point,
  77530. POINT_CONVERSION_UNCOMPRESSED, set_point_bn, ctx), set_point_bn);
  77531. /* check bn2hex */
  77532. hexStr = BN_bn2hex(k);
  77533. ExpectStrEQ(hexStr, kTest);
  77534. #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM) && \
  77535. defined(XFPRINTF)
  77536. BN_print_fp(stderr, k);
  77537. fprintf(stderr, "\n");
  77538. #endif
  77539. XFREE(hexStr, NULL, DYNAMIC_TYPE_ECC);
  77540. hexStr = BN_bn2hex(Gx);
  77541. ExpectStrEQ(hexStr, kGx);
  77542. #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM) && \
  77543. defined(XFPRINTF)
  77544. BN_print_fp(stderr, Gx);
  77545. fprintf(stderr, "\n");
  77546. #endif
  77547. XFREE(hexStr, NULL, DYNAMIC_TYPE_ECC);
  77548. hexStr = BN_bn2hex(Gy);
  77549. ExpectStrEQ(hexStr, kGy);
  77550. #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM) && \
  77551. defined(XFPRINTF)
  77552. BN_print_fp(stderr, Gy);
  77553. fprintf(stderr, "\n");
  77554. #endif
  77555. XFREE(hexStr, NULL, DYNAMIC_TYPE_ECC);
  77556. /* Test point to hex */
  77557. ExpectNull(EC_POINT_point2hex(NULL, NULL, POINT_CONVERSION_UNCOMPRESSED,
  77558. ctx));
  77559. ExpectNull(EC_POINT_point2hex(NULL, Gxy, POINT_CONVERSION_UNCOMPRESSED,
  77560. ctx));
  77561. ExpectNull(EC_POINT_point2hex(group, NULL, POINT_CONVERSION_UNCOMPRESSED,
  77562. ctx));
  77563. #ifndef HAVE_ECC_BRAINPOOL
  77564. /* Group not supported in wolfCrypt. */
  77565. ExpectNull(EC_POINT_point2hex(group2, Gxy, POINT_CONVERSION_UNCOMPRESSED,
  77566. ctx));
  77567. #endif
  77568. hexStr = EC_POINT_point2hex(group, Gxy, POINT_CONVERSION_UNCOMPRESSED, ctx);
  77569. ExpectNotNull(hexStr);
  77570. ExpectStrEQ(hexStr, uncompG);
  77571. ExpectNotNull(get_point = EC_POINT_hex2point(group, hexStr, NULL, ctx));
  77572. ExpectIntEQ(EC_POINT_cmp(group, Gxy, get_point, ctx), 0);
  77573. XFREE(hexStr, NULL, DYNAMIC_TYPE_ECC);
  77574. hexStr = EC_POINT_point2hex(group, Gxy, POINT_CONVERSION_COMPRESSED, ctx);
  77575. ExpectNotNull(hexStr);
  77576. ExpectStrEQ(hexStr, compG);
  77577. #ifdef HAVE_COMP_KEY
  77578. ExpectNotNull(get_point = EC_POINT_hex2point
  77579. (group, hexStr, get_point, ctx));
  77580. ExpectIntEQ(EC_POINT_cmp(group, Gxy, get_point, ctx), 0);
  77581. #endif
  77582. XFREE(hexStr, NULL, DYNAMIC_TYPE_ECC);
  77583. EC_POINT_free(get_point);
  77584. #ifndef HAVE_SELFTEST
  77585. /* Test point to oct */
  77586. ExpectIntEQ(EC_POINT_point2oct(NULL, NULL, POINT_CONVERSION_UNCOMPRESSED,
  77587. NULL, 0, ctx), 0);
  77588. ExpectIntEQ(EC_POINT_point2oct(NULL, Gxy, POINT_CONVERSION_UNCOMPRESSED,
  77589. NULL, 0, ctx), 0);
  77590. ExpectIntEQ(EC_POINT_point2oct(group, NULL, POINT_CONVERSION_UNCOMPRESSED,
  77591. NULL, 0, ctx), 0);
  77592. bin_len = EC_POINT_point2oct(group, Gxy, POINT_CONVERSION_UNCOMPRESSED,
  77593. NULL, 0, ctx);
  77594. ExpectIntEQ(bin_len, sizeof(binUncompG));
  77595. ExpectNotNull(buf = (unsigned char*)XMALLOC(bin_len, NULL,
  77596. DYNAMIC_TYPE_ECC));
  77597. ExpectIntEQ(EC_POINT_point2oct(group, Gxy, POINT_CONVERSION_UNCOMPRESSED,
  77598. buf, bin_len, ctx), bin_len);
  77599. ExpectIntEQ(XMEMCMP(buf, binUncompG, sizeof(binUncompG)), 0);
  77600. XFREE(buf, NULL, DYNAMIC_TYPE_ECC);
  77601. /* Infinity (x=0, y=0) encodes as '0x00'. */
  77602. ExpectIntEQ(EC_POINT_point2oct(group, infinity,
  77603. POINT_CONVERSION_UNCOMPRESSED, NULL, 0, ctx), 1);
  77604. ExpectIntEQ(EC_POINT_point2oct(group, infinity,
  77605. POINT_CONVERSION_UNCOMPRESSED, bufInf, 0, ctx), 0);
  77606. ExpectIntEQ(EC_POINT_point2oct(group, infinity,
  77607. POINT_CONVERSION_UNCOMPRESSED, bufInf, 1, ctx), 1);
  77608. ExpectIntEQ(bufInf[0], 0);
  77609. wolfSSL_EC_POINT_dump(NULL, NULL);
  77610. /* Test point i2d */
  77611. ExpectIntEQ(ECPoint_i2d(NULL, NULL, NULL, &blen), 0);
  77612. ExpectIntEQ(ECPoint_i2d(NULL, Gxy, NULL, &blen), 0);
  77613. ExpectIntEQ(ECPoint_i2d(group, NULL, NULL, &blen), 0);
  77614. ExpectIntEQ(ECPoint_i2d(group, Gxy, NULL, NULL), 0);
  77615. ExpectIntEQ(ECPoint_i2d(group, Gxy, NULL, &blen), 1);
  77616. ExpectIntEQ(blen, sizeof(binUncompG));
  77617. ExpectNotNull(buf = (unsigned char*)XMALLOC(blen, NULL, DYNAMIC_TYPE_ECC));
  77618. blen -= 1;
  77619. ExpectIntEQ(ECPoint_i2d(group, Gxy, buf, &blen), 0);
  77620. blen += 1;
  77621. ExpectIntEQ(ECPoint_i2d(group, Gxy, buf, &blen), 1);
  77622. ExpectIntEQ(XMEMCMP(buf, binUncompG, sizeof(binUncompG)), 0);
  77623. XFREE(buf, NULL, DYNAMIC_TYPE_ECC);
  77624. #ifdef HAVE_COMP_KEY
  77625. /* Test point to oct compressed */
  77626. bin_len = EC_POINT_point2oct(group, Gxy, POINT_CONVERSION_COMPRESSED, NULL,
  77627. 0, ctx);
  77628. ExpectIntEQ(bin_len, sizeof(binCompG));
  77629. ExpectNotNull(buf = (unsigned char*)XMALLOC(bin_len, NULL,
  77630. DYNAMIC_TYPE_ECC));
  77631. ExpectIntEQ(EC_POINT_point2oct(group, Gxy, POINT_CONVERSION_COMPRESSED, buf,
  77632. bin_len, ctx), bin_len);
  77633. ExpectIntEQ(XMEMCMP(buf, binCompG, sizeof(binCompG)), 0);
  77634. XFREE(buf, NULL, DYNAMIC_TYPE_ECC);
  77635. #endif
  77636. /* Test point BN */
  77637. ExpectNull(wolfSSL_EC_POINT_point2bn(NULL, NULL,
  77638. POINT_CONVERSION_UNCOMPRESSED, NULL, ctx));
  77639. ExpectNull(wolfSSL_EC_POINT_point2bn(NULL, Gxy,
  77640. POINT_CONVERSION_UNCOMPRESSED, NULL, ctx));
  77641. ExpectNull(wolfSSL_EC_POINT_point2bn(group, NULL,
  77642. POINT_CONVERSION_UNCOMPRESSED, NULL, ctx));
  77643. ExpectNull(wolfSSL_EC_POINT_point2bn(group, Gxy, 0, NULL, ctx));
  77644. /* Test oct to point */
  77645. ExpectNotNull(tmp = EC_POINT_new(group));
  77646. ExpectIntEQ(EC_POINT_oct2point(NULL, NULL, binUncompG, sizeof(binUncompG),
  77647. ctx), 0);
  77648. ExpectIntEQ(EC_POINT_oct2point(NULL, tmp, binUncompG, sizeof(binUncompG),
  77649. ctx), 0);
  77650. ExpectIntEQ(EC_POINT_oct2point(group, NULL, binUncompG, sizeof(binUncompG),
  77651. ctx), 0);
  77652. ExpectIntEQ(EC_POINT_oct2point(group, tmp, binUncompGBad,
  77653. sizeof(binUncompGBad), ctx), 0);
  77654. ExpectIntEQ(EC_POINT_oct2point(group, tmp, binUncompG, sizeof(binUncompG),
  77655. ctx), 1);
  77656. ExpectIntEQ(EC_POINT_cmp(group, tmp, Gxy, ctx), 0);
  77657. EC_POINT_free(tmp);
  77658. tmp = NULL;
  77659. /* Test setting BN ordinates. */
  77660. ExpectNotNull(tmp = EC_POINT_new(group));
  77661. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(NULL, NULL, NULL,
  77662. NULL, ctx), 0);
  77663. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(group, NULL, NULL,
  77664. NULL, ctx), 0);
  77665. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(NULL, tmp, NULL,
  77666. NULL, ctx), 0);
  77667. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(NULL, NULL, Gx,
  77668. NULL, ctx), 0);
  77669. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(NULL, NULL, NULL,
  77670. Gy, ctx), 0);
  77671. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(NULL, tmp, Gx, Gy,
  77672. ctx), 0);
  77673. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(group, NULL, Gx, Gy,
  77674. ctx), 0);
  77675. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(group, tmp, NULL,
  77676. Gy, ctx), 0);
  77677. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(group, tmp, Gx,
  77678. NULL, ctx), 0);
  77679. ExpectIntEQ(wolfSSL_EC_POINT_set_affine_coordinates_GFp(group, tmp, Gx, Gy,
  77680. ctx), 1);
  77681. EC_POINT_free(tmp);
  77682. tmp = NULL;
  77683. /* Test point d2i */
  77684. ExpectNotNull(tmp = EC_POINT_new(group));
  77685. ExpectIntEQ(ECPoint_d2i(NULL, sizeof(binUncompG), NULL, NULL), 0);
  77686. ExpectIntEQ(ECPoint_d2i(binUncompG, sizeof(binUncompG), NULL, NULL), 0);
  77687. ExpectIntEQ(ECPoint_d2i(NULL, sizeof(binUncompG), group, NULL), 0);
  77688. ExpectIntEQ(ECPoint_d2i(NULL, sizeof(binUncompG), NULL, tmp), 0);
  77689. ExpectIntEQ(ECPoint_d2i(NULL, sizeof(binUncompG), group, tmp), 0);
  77690. ExpectIntEQ(ECPoint_d2i(binUncompG, sizeof(binUncompG), NULL, tmp), 0);
  77691. ExpectIntEQ(ECPoint_d2i(binUncompG, sizeof(binUncompG), group, NULL), 0);
  77692. ExpectIntEQ(ECPoint_d2i(binUncompGBad, sizeof(binUncompG), group, tmp), 0);
  77693. ExpectIntEQ(ECPoint_d2i(binUncompG, sizeof(binUncompG), group, tmp), 1);
  77694. ExpectIntEQ(EC_POINT_cmp(group, tmp, Gxy, ctx), 0);
  77695. EC_POINT_free(tmp);
  77696. tmp = NULL;
  77697. #ifdef HAVE_COMP_KEY
  77698. /* Test oct compressed to point */
  77699. ExpectNotNull(tmp = EC_POINT_new(group));
  77700. ExpectIntEQ(EC_POINT_oct2point(group, tmp, binCompG, sizeof(binCompG), ctx),
  77701. 1);
  77702. ExpectIntEQ(EC_POINT_cmp(group, tmp, Gxy, ctx), 0);
  77703. EC_POINT_free(tmp);
  77704. tmp = NULL;
  77705. /* Test point d2i - compressed */
  77706. ExpectNotNull(tmp = EC_POINT_new(group));
  77707. ExpectIntEQ(ECPoint_d2i(binCompG, sizeof(binCompG), group, tmp), 1);
  77708. ExpectIntEQ(EC_POINT_cmp(group, tmp, Gxy, ctx), 0);
  77709. EC_POINT_free(tmp);
  77710. tmp = NULL;
  77711. #endif
  77712. #endif
  77713. /* test BN_mod_add */
  77714. ExpectIntEQ(BN_mod_add(new_point->Z, (WOLFSSL_BIGNUM*)BN_value_one(),
  77715. (WOLFSSL_BIGNUM*)BN_value_one(), (WOLFSSL_BIGNUM*)BN_value_one(), NULL),
  77716. 1);
  77717. ExpectIntEQ(BN_is_zero(new_point->Z), 1);
  77718. /* cleanup */
  77719. BN_free(X);
  77720. BN_free(Y);
  77721. BN_free(k);
  77722. BN_free(set_point_bn);
  77723. EC_POINT_free(infinity);
  77724. EC_POINT_free(new_point);
  77725. EC_POINT_free(set_point);
  77726. EC_POINT_clear_free(Gxy);
  77727. #ifndef HAVE_ECC_BRAINPOOL
  77728. EC_GROUP_free(group2);
  77729. #endif
  77730. EC_GROUP_free(group);
  77731. BN_CTX_free(ctx);
  77732. #endif
  77733. #endif /* !WOLFSSL_SP_MATH && ( !HAVE_FIPS || HAVE_FIPS_VERSION > 2) */
  77734. return EXPECT_RESULT();
  77735. }
  77736. static int test_wolfSSL_SPAKE(void)
  77737. {
  77738. EXPECT_DECLS;
  77739. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && !defined(WOLFSSL_ATECC508A) \
  77740. && !defined(WOLFSSL_ATECC608A) && !defined(HAVE_SELFTEST) && \
  77741. !defined(WOLFSSL_SP_MATH) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  77742. BIGNUM* x = NULL; /* kdc priv */
  77743. BIGNUM* y = NULL; /* client priv */
  77744. BIGNUM* w = NULL; /* shared value */
  77745. byte M_bytes[] = {
  77746. /* uncompressed */
  77747. 0x04,
  77748. /* x */
  77749. 0x88, 0x6e, 0x2f, 0x97, 0xac, 0xe4, 0x6e, 0x55, 0xba, 0x9d, 0xd7, 0x24,
  77750. 0x25, 0x79, 0xf2, 0x99, 0x3b, 0x64, 0xe1, 0x6e, 0xf3, 0xdc, 0xab, 0x95,
  77751. 0xaf, 0xd4, 0x97, 0x33, 0x3d, 0x8f, 0xa1, 0x2f,
  77752. /* y */
  77753. 0x5f, 0xf3, 0x55, 0x16, 0x3e, 0x43, 0xce, 0x22, 0x4e, 0x0b, 0x0e, 0x65,
  77754. 0xff, 0x02, 0xac, 0x8e, 0x5c, 0x7b, 0xe0, 0x94, 0x19, 0xc7, 0x85, 0xe0,
  77755. 0xca, 0x54, 0x7d, 0x55, 0xa1, 0x2e, 0x2d, 0x20
  77756. };
  77757. EC_POINT* M = NULL; /* shared value */
  77758. byte N_bytes[] = {
  77759. /* uncompressed */
  77760. 0x04,
  77761. /* x */
  77762. 0xd8, 0xbb, 0xd6, 0xc6, 0x39, 0xc6, 0x29, 0x37, 0xb0, 0x4d, 0x99, 0x7f,
  77763. 0x38, 0xc3, 0x77, 0x07, 0x19, 0xc6, 0x29, 0xd7, 0x01, 0x4d, 0x49, 0xa2,
  77764. 0x4b, 0x4f, 0x98, 0xba, 0xa1, 0x29, 0x2b, 0x49,
  77765. /* y */
  77766. 0x07, 0xd6, 0x0a, 0xa6, 0xbf, 0xad, 0xe4, 0x50, 0x08, 0xa6, 0x36, 0x33,
  77767. 0x7f, 0x51, 0x68, 0xc6, 0x4d, 0x9b, 0xd3, 0x60, 0x34, 0x80, 0x8c, 0xd5,
  77768. 0x64, 0x49, 0x0b, 0x1e, 0x65, 0x6e, 0xdb, 0xe7
  77769. };
  77770. EC_POINT* N = NULL; /* shared value */
  77771. EC_POINT* T = NULL; /* kdc pub */
  77772. EC_POINT* tmp1 = NULL; /* kdc pub */
  77773. EC_POINT* tmp2 = NULL; /* kdc pub */
  77774. EC_POINT* S = NULL; /* client pub */
  77775. EC_POINT* client_secret = NULL;
  77776. EC_POINT* kdc_secret = NULL;
  77777. EC_GROUP* group = NULL;
  77778. BN_CTX* bn_ctx = NULL;
  77779. /* Values taken from a test run of Kerberos 5 */
  77780. ExpectNotNull(group = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
  77781. ExpectNotNull(bn_ctx = BN_CTX_new());
  77782. ExpectNotNull(M = EC_POINT_new(group));
  77783. ExpectNotNull(N = EC_POINT_new(group));
  77784. ExpectNotNull(T = EC_POINT_new(group));
  77785. ExpectNotNull(tmp1 = EC_POINT_new(group));
  77786. ExpectNotNull(tmp2 = EC_POINT_new(group));
  77787. ExpectNotNull(S = EC_POINT_new(group));
  77788. ExpectNotNull(client_secret = EC_POINT_new(group));
  77789. ExpectNotNull(kdc_secret = EC_POINT_new(group));
  77790. ExpectIntEQ(BN_hex2bn(&x, "DAC3027CD692B4BDF0EDFE9B7D0E4E7"
  77791. "E5D8768A725EAEEA6FC68EC239A17C0"), 1);
  77792. ExpectIntEQ(BN_hex2bn(&y, "6F6A1D394E26B1655A54B26DCE30D49"
  77793. "90CC47EBE08F809EF3FF7F6AEAABBB5"), 1);
  77794. ExpectIntEQ(BN_hex2bn(&w, "1D992AB8BA851B9BA05353453D81EE9"
  77795. "506AB395478F0AAB647752CF117B36250"), 1);
  77796. ExpectIntEQ(EC_POINT_oct2point(group, M, M_bytes, sizeof(M_bytes), bn_ctx),
  77797. 1);
  77798. ExpectIntEQ(EC_POINT_oct2point(group, N, N_bytes, sizeof(N_bytes), bn_ctx),
  77799. 1);
  77800. /* Function pattern similar to ossl_keygen and ossl_result in krb5 */
  77801. /* kdc */
  77802. /* T=x*P+w*M */
  77803. /* All in one function call */
  77804. ExpectIntEQ(EC_POINT_mul(group, T, x, M, w, bn_ctx), 1);
  77805. /* Spread into separate calls */
  77806. ExpectIntEQ(EC_POINT_mul(group, tmp1, x, NULL, NULL, bn_ctx), 1);
  77807. ExpectIntEQ(EC_POINT_mul(group, tmp2, NULL, M, w, bn_ctx), 1);
  77808. ExpectIntEQ(EC_POINT_add(group, tmp1, tmp1, tmp2, bn_ctx),
  77809. 1);
  77810. ExpectIntEQ(EC_POINT_cmp(group, T, tmp1, bn_ctx), 0);
  77811. /* client */
  77812. /* S=y*P+w*N */
  77813. /* All in one function call */
  77814. ExpectIntEQ(EC_POINT_mul(group, S, y, N, w, bn_ctx), 1);
  77815. /* Spread into separate calls */
  77816. ExpectIntEQ(EC_POINT_mul(group, tmp1, y, NULL, NULL, bn_ctx), 1);
  77817. ExpectIntEQ(EC_POINT_mul(group, tmp2, NULL, N, w, bn_ctx), 1);
  77818. ExpectIntEQ(EC_POINT_add(group, tmp1, tmp1, tmp2, bn_ctx),
  77819. 1);
  77820. ExpectIntEQ(EC_POINT_cmp(group, S, tmp1, bn_ctx), 0);
  77821. /* K=y*(T-w*M) */
  77822. ExpectIntEQ(EC_POINT_mul(group, client_secret, NULL, M, w, bn_ctx), 1);
  77823. ExpectIntEQ(EC_POINT_invert(group, client_secret, bn_ctx), 1);
  77824. ExpectIntEQ(EC_POINT_add(group, client_secret, T, client_secret, bn_ctx),
  77825. 1);
  77826. ExpectIntEQ(EC_POINT_mul(group, client_secret, NULL, client_secret, y,
  77827. bn_ctx), 1);
  77828. /* kdc */
  77829. /* K=x*(S-w*N) */
  77830. ExpectIntEQ(EC_POINT_mul(group, kdc_secret, NULL, N, w, bn_ctx), 1);
  77831. ExpectIntEQ(EC_POINT_invert(group, kdc_secret, bn_ctx), 1);
  77832. ExpectIntEQ(EC_POINT_add(group, kdc_secret, S, kdc_secret, bn_ctx),
  77833. 1);
  77834. ExpectIntEQ(EC_POINT_mul(group, kdc_secret, NULL, kdc_secret, x, bn_ctx),
  77835. 1);
  77836. /* kdc_secret == client_secret */
  77837. ExpectIntEQ(EC_POINT_cmp(group, client_secret, kdc_secret, bn_ctx), 0);
  77838. BN_free(x);
  77839. BN_free(y);
  77840. BN_free(w);
  77841. EC_POINT_free(M);
  77842. EC_POINT_free(N);
  77843. EC_POINT_free(T);
  77844. EC_POINT_free(tmp1);
  77845. EC_POINT_free(tmp2);
  77846. EC_POINT_free(S);
  77847. EC_POINT_free(client_secret);
  77848. EC_POINT_free(kdc_secret);
  77849. EC_GROUP_free(group);
  77850. BN_CTX_free(bn_ctx);
  77851. #endif
  77852. return EXPECT_RESULT();
  77853. }
  77854. static int test_wolfSSL_EC_KEY_generate(void)
  77855. {
  77856. EXPECT_DECLS;
  77857. #ifdef OPENSSL_EXTRA
  77858. WOLFSSL_EC_KEY* key = NULL;
  77859. #ifndef HAVE_ECC_BRAINPOOL
  77860. WOLFSSL_EC_GROUP* group = NULL;
  77861. #endif
  77862. ExpectNotNull(key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  77863. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(NULL), 0);
  77864. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(key), 1);
  77865. wolfSSL_EC_KEY_free(key);
  77866. key = NULL;
  77867. #ifndef HAVE_ECC_BRAINPOOL
  77868. ExpectNotNull(group = wolfSSL_EC_GROUP_new_by_curve_name(
  77869. NID_brainpoolP256r1));
  77870. ExpectNotNull(key = wolfSSL_EC_KEY_new());
  77871. ExpectIntEQ(wolfSSL_EC_KEY_set_group(key, group), 1);
  77872. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(key), 0);
  77873. wolfSSL_EC_KEY_free(key);
  77874. wolfSSL_EC_GROUP_free(group);
  77875. #endif
  77876. #endif
  77877. return EXPECT_RESULT();
  77878. }
  77879. static int test_EC_i2d(void)
  77880. {
  77881. EXPECT_DECLS;
  77882. #if defined(OPENSSL_EXTRA) && !defined(HAVE_FIPS)
  77883. EC_KEY *key = NULL;
  77884. EC_KEY *copy = NULL;
  77885. int len = 0;
  77886. unsigned char *buf = NULL;
  77887. unsigned char *p = NULL;
  77888. const unsigned char *tmp = NULL;
  77889. const unsigned char octBad[] = {
  77890. 0x09, 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc,
  77891. 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2, 0x77, 0x03, 0x7d, 0x81, 0x2d,
  77892. 0xeb, 0x33, 0xa0, 0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
  77893. 0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b, 0x8e, 0xe7, 0xeb,
  77894. 0x4a, 0x7c, 0x0f, 0x9e, 0x16, 0x2b, 0xce, 0x33, 0x57, 0x6b, 0x31,
  77895. 0x5e, 0xce, 0xcb, 0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf5,
  77896. };
  77897. ExpectNotNull(key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  77898. ExpectIntEQ(EC_KEY_generate_key(key), 1);
  77899. ExpectIntGT((len = i2d_EC_PUBKEY(key, NULL)), 0);
  77900. ExpectNotNull(buf = (unsigned char*)XMALLOC(len, NULL,
  77901. DYNAMIC_TYPE_TMP_BUFFER));
  77902. p = buf;
  77903. ExpectIntEQ(i2d_EC_PUBKEY(key, &p), len);
  77904. ExpectNull(o2i_ECPublicKey(NULL, NULL, -1));
  77905. ExpectNull(o2i_ECPublicKey(&copy, NULL, -1));
  77906. ExpectNull(o2i_ECPublicKey(&key, NULL, -1));
  77907. ExpectNull(o2i_ECPublicKey(NULL, &tmp, -1));
  77908. ExpectNull(o2i_ECPublicKey(NULL, NULL, 0));
  77909. ExpectNull(o2i_ECPublicKey(&key, NULL, 0));
  77910. ExpectNull(o2i_ECPublicKey(&key, &tmp, 0));
  77911. tmp = buf;
  77912. ExpectNull(o2i_ECPublicKey(NULL, &tmp, 0));
  77913. ExpectNull(o2i_ECPublicKey(&copy, &tmp, 0));
  77914. ExpectNull(o2i_ECPublicKey(NULL, &tmp, -1));
  77915. ExpectNull(o2i_ECPublicKey(&key, &tmp, -1));
  77916. ExpectIntEQ(i2o_ECPublicKey(NULL, NULL), 0);
  77917. ExpectIntEQ(i2o_ECPublicKey(NULL, &buf), 0);
  77918. tmp = buf;
  77919. ExpectNull(d2i_ECPrivateKey(NULL, &tmp, 0));
  77920. ExpectNull(d2i_ECPrivateKey(NULL, &tmp, 1));
  77921. ExpectNull(d2i_ECPrivateKey(&copy, &tmp, 0));
  77922. ExpectNull(d2i_ECPrivateKey(&copy, &tmp, 1));
  77923. ExpectNull(d2i_ECPrivateKey(&key, &tmp, 0));
  77924. {
  77925. EC_KEY *pubkey = NULL;
  77926. BIO* bio = NULL;
  77927. ExpectNotNull(bio = BIO_new(BIO_s_mem()));
  77928. ExpectIntGT(BIO_write(bio, buf, len), 0);
  77929. ExpectNotNull(d2i_EC_PUBKEY_bio(bio, &pubkey));
  77930. BIO_free(bio);
  77931. EC_KEY_free(pubkey);
  77932. }
  77933. ExpectIntEQ(i2d_ECPrivateKey(NULL, &p), 0);
  77934. ExpectIntEQ(i2d_ECPrivateKey(NULL, NULL), 0);
  77935. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer(NULL, NULL, -1), -1);
  77936. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(NULL, NULL, -1, 0), -1);
  77937. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, NULL, -1, 0), -1);
  77938. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(NULL, buf, -1, 0), -1);
  77939. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(NULL, NULL, 0, 0), -1);
  77940. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(NULL, NULL, -1,
  77941. WOLFSSL_EC_KEY_LOAD_PUBLIC), -1);
  77942. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(NULL, buf, len,
  77943. WOLFSSL_EC_KEY_LOAD_PUBLIC), -1);
  77944. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, NULL, len,
  77945. WOLFSSL_EC_KEY_LOAD_PUBLIC), -1);
  77946. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, buf, -1,
  77947. WOLFSSL_EC_KEY_LOAD_PUBLIC), -1);
  77948. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, buf, len, 0), -1);
  77949. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, buf, len,
  77950. WOLFSSL_EC_KEY_LOAD_PRIVATE), -1);
  77951. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, octBad, sizeof(octBad),
  77952. WOLFSSL_EC_KEY_LOAD_PRIVATE), -1);
  77953. ExpectIntEQ(wolfSSL_EC_KEY_LoadDer_ex(key, octBad, sizeof(octBad),
  77954. WOLFSSL_EC_KEY_LOAD_PUBLIC), -1);
  77955. XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  77956. buf = NULL;
  77957. buf = NULL;
  77958. ExpectIntGT((len = i2d_ECPrivateKey(key, NULL)), 0);
  77959. ExpectNotNull(buf = (unsigned char*)XMALLOC(len, NULL,
  77960. DYNAMIC_TYPE_TMP_BUFFER));
  77961. p = buf;
  77962. ExpectIntEQ(i2d_ECPrivateKey(key, &p), len);
  77963. p = NULL;
  77964. ExpectIntEQ(i2d_ECPrivateKey(key, &p), len);
  77965. XFREE(p, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  77966. p = NULL;
  77967. /* Bad point is also an invalid private key. */
  77968. tmp = octBad;
  77969. ExpectNull(d2i_ECPrivateKey(&copy, &tmp, sizeof(octBad)));
  77970. tmp = buf;
  77971. ExpectNotNull(d2i_ECPrivateKey(&copy, &tmp, len));
  77972. XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  77973. buf = NULL;
  77974. buf = NULL;
  77975. ExpectIntGT((len = i2o_ECPublicKey(key, NULL)), 0);
  77976. ExpectNotNull(buf = (unsigned char*)XMALLOC(len, NULL,
  77977. DYNAMIC_TYPE_TMP_BUFFER));
  77978. p = buf;
  77979. ExpectIntGT((len = i2o_ECPublicKey(key, &p)), 0);
  77980. p = NULL;
  77981. ExpectIntGT((len = i2o_ECPublicKey(key, &p)), 0);
  77982. tmp = buf;
  77983. ExpectNotNull(o2i_ECPublicKey(&copy, &tmp, len));
  77984. tmp = octBad;
  77985. ExpectNull(o2i_ECPublicKey(&key, &tmp, sizeof(octBad)));
  77986. ExpectIntEQ(EC_KEY_check_key(NULL), 0);
  77987. ExpectIntEQ(EC_KEY_check_key(key), 1);
  77988. XFREE(p, NULL, DYNAMIC_TYPE_OPENSSL);
  77989. XFREE(buf, NULL, DYNAMIC_TYPE_OPENSSL);
  77990. EC_KEY_free(key);
  77991. EC_KEY_free(copy);
  77992. #endif
  77993. return EXPECT_RESULT();
  77994. }
  77995. static int test_wolfSSL_EC_curve(void)
  77996. {
  77997. EXPECT_DECLS;
  77998. #if defined(OPENSSL_EXTRA)
  77999. int nid = NID_secp160k1;
  78000. const char* nid_name = NULL;
  78001. ExpectNull(EC_curve_nid2nist(NID_sha256));
  78002. ExpectNotNull(nid_name = EC_curve_nid2nist(nid));
  78003. ExpectIntEQ(XMEMCMP(nid_name, "K-160", XSTRLEN("K-160")), 0);
  78004. ExpectIntEQ(EC_curve_nist2nid("INVALID"), 0);
  78005. ExpectIntEQ(EC_curve_nist2nid(nid_name), nid);
  78006. #endif
  78007. return EXPECT_RESULT();
  78008. }
  78009. static int test_wolfSSL_EC_KEY_dup(void)
  78010. {
  78011. EXPECT_DECLS;
  78012. #if defined(OPENSSL_ALL) && !defined(NO_CERTS)
  78013. WOLFSSL_EC_KEY* ecKey = NULL;
  78014. WOLFSSL_EC_KEY* dupKey = NULL;
  78015. ecc_key* srcKey = NULL;
  78016. ecc_key* destKey = NULL;
  78017. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  78018. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  78019. /* Valid cases */
  78020. ExpectNotNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  78021. ExpectIntEQ(EC_KEY_check_key(dupKey), 1);
  78022. /* Compare pubkey */
  78023. if (ecKey != NULL) {
  78024. srcKey = (ecc_key*)ecKey->internal;
  78025. }
  78026. if (dupKey != NULL) {
  78027. destKey = (ecc_key*)dupKey->internal;
  78028. }
  78029. ExpectIntEQ(wc_ecc_cmp_point(&srcKey->pubkey, &destKey->pubkey), 0);
  78030. /* compare EC_GROUP */
  78031. ExpectIntEQ(wolfSSL_EC_GROUP_cmp(ecKey->group, dupKey->group, NULL), MP_EQ);
  78032. /* compare EC_POINT */
  78033. ExpectIntEQ(wolfSSL_EC_POINT_cmp(ecKey->group, ecKey->pub_key, \
  78034. dupKey->pub_key, NULL), MP_EQ);
  78035. /* compare BIGNUM */
  78036. ExpectIntEQ(wolfSSL_BN_cmp(ecKey->priv_key, dupKey->priv_key), MP_EQ);
  78037. wolfSSL_EC_KEY_free(dupKey);
  78038. dupKey = NULL;
  78039. /* Invalid cases */
  78040. /* NULL key */
  78041. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(NULL));
  78042. /* NULL ecc_key */
  78043. if (ecKey != NULL) {
  78044. wc_ecc_free((ecc_key*)ecKey->internal);
  78045. XFREE(ecKey->internal, NULL, DYNAMIC_TYPE_ECC);
  78046. ecKey->internal = NULL; /* Set ecc_key to NULL */
  78047. }
  78048. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  78049. wolfSSL_EC_KEY_free(ecKey);
  78050. ecKey = NULL;
  78051. wolfSSL_EC_KEY_free(dupKey);
  78052. dupKey = NULL;
  78053. /* NULL Group */
  78054. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  78055. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  78056. if (ecKey != NULL) {
  78057. wolfSSL_EC_GROUP_free(ecKey->group);
  78058. ecKey->group = NULL; /* Set group to NULL */
  78059. }
  78060. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  78061. wolfSSL_EC_KEY_free(ecKey);
  78062. ecKey = NULL;
  78063. wolfSSL_EC_KEY_free(dupKey);
  78064. dupKey = NULL;
  78065. /* NULL public key */
  78066. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  78067. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  78068. if (ecKey != NULL) {
  78069. wc_ecc_del_point((ecc_point*)ecKey->pub_key->internal);
  78070. ecKey->pub_key->internal = NULL; /* Set ecc_point to NULL */
  78071. }
  78072. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  78073. if (ecKey != NULL) {
  78074. wolfSSL_EC_POINT_free(ecKey->pub_key);
  78075. ecKey->pub_key = NULL; /* Set pub_key to NULL */
  78076. }
  78077. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  78078. wolfSSL_EC_KEY_free(ecKey);
  78079. ecKey = NULL;
  78080. wolfSSL_EC_KEY_free(dupKey);
  78081. dupKey = NULL;
  78082. /* NULL private key */
  78083. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  78084. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
  78085. if (ecKey != NULL) {
  78086. wolfSSL_BN_free(ecKey->priv_key);
  78087. ecKey->priv_key = NULL; /* Set priv_key to NULL */
  78088. }
  78089. ExpectNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  78090. wolfSSL_EC_KEY_free(ecKey);
  78091. ecKey = NULL;
  78092. wolfSSL_EC_KEY_free(dupKey);
  78093. dupKey = NULL;
  78094. /* Test EC_KEY_up_ref */
  78095. ExpectNotNull(ecKey = wolfSSL_EC_KEY_new());
  78096. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), WOLFSSL_SUCCESS);
  78097. ExpectIntEQ(wolfSSL_EC_KEY_up_ref(NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  78098. ExpectIntEQ(wolfSSL_EC_KEY_up_ref(ecKey), WOLFSSL_SUCCESS);
  78099. /* reference count doesn't follow duplicate */
  78100. ExpectNotNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
  78101. ExpectIntEQ(wolfSSL_EC_KEY_up_ref(dupKey), WOLFSSL_SUCCESS); /* +1 */
  78102. ExpectIntEQ(wolfSSL_EC_KEY_up_ref(dupKey), WOLFSSL_SUCCESS); /* +2 */
  78103. wolfSSL_EC_KEY_free(dupKey); /* 3 */
  78104. wolfSSL_EC_KEY_free(dupKey); /* 2 */
  78105. wolfSSL_EC_KEY_free(dupKey); /* 1, free */
  78106. wolfSSL_EC_KEY_free(ecKey); /* 2 */
  78107. wolfSSL_EC_KEY_free(ecKey); /* 1, free */
  78108. #endif
  78109. return EXPECT_RESULT();
  78110. }
  78111. static int test_wolfSSL_EC_KEY_set_group(void)
  78112. {
  78113. EXPECT_DECLS;
  78114. #if defined(HAVE_ECC) && !defined(NO_ECC256) && !defined(NO_ECC_SECP) && \
  78115. defined(OPENSSL_EXTRA)
  78116. EC_KEY *key = NULL;
  78117. EC_GROUP *group = NULL;
  78118. const EC_GROUP *group2 = NULL;
  78119. ExpectNotNull(group = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
  78120. ExpectNotNull(key = EC_KEY_new());
  78121. ExpectNull(EC_KEY_get0_group(NULL));
  78122. ExpectIntEQ(EC_KEY_set_group(NULL, NULL), 0);
  78123. ExpectIntEQ(EC_KEY_set_group(key, NULL), 0);
  78124. ExpectIntEQ(EC_KEY_set_group(NULL, group), 0);
  78125. ExpectIntEQ(EC_KEY_set_group(key, group), WOLFSSL_SUCCESS);
  78126. ExpectNotNull(group2 = EC_KEY_get0_group(key));
  78127. ExpectIntEQ(EC_GROUP_cmp(group2, group, NULL), 0);
  78128. EC_GROUP_free(group);
  78129. EC_KEY_free(key);
  78130. #endif
  78131. return EXPECT_RESULT();
  78132. }
  78133. static int test_wolfSSL_EC_KEY_set_conv_form(void)
  78134. {
  78135. EXPECT_DECLS;
  78136. #if defined(HAVE_ECC) && defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  78137. BIO* bio = NULL;
  78138. EC_KEY* key = NULL;
  78139. /* Error condition: NULL key. */
  78140. ExpectIntLT(EC_KEY_get_conv_form(NULL), 0);
  78141. ExpectNotNull(bio = BIO_new_file("./certs/ecc-keyPub.pem", "rb"));
  78142. ExpectNotNull(key = PEM_read_bio_EC_PUBKEY(bio, NULL, NULL, NULL));
  78143. /* Conversion form defaults to uncompressed. */
  78144. ExpectIntEQ(EC_KEY_get_conv_form(key), POINT_CONVERSION_UNCOMPRESSED);
  78145. #ifdef HAVE_COMP_KEY
  78146. /* Explicitly set to compressed. */
  78147. EC_KEY_set_conv_form(key, POINT_CONVERSION_COMPRESSED);
  78148. ExpectIntEQ(EC_KEY_get_conv_form(key), POINT_CONVERSION_COMPRESSED);
  78149. #else
  78150. /* Will still work just won't change anything. */
  78151. EC_KEY_set_conv_form(key, POINT_CONVERSION_COMPRESSED);
  78152. ExpectIntEQ(EC_KEY_get_conv_form(key), POINT_CONVERSION_UNCOMPRESSED);
  78153. EC_KEY_set_conv_form(key, POINT_CONVERSION_UNCOMPRESSED);
  78154. ExpectIntEQ(EC_KEY_get_conv_form(key), POINT_CONVERSION_UNCOMPRESSED);
  78155. #endif
  78156. EC_KEY_set_conv_form(NULL, POINT_CONVERSION_UNCOMPRESSED);
  78157. BIO_free(bio);
  78158. EC_KEY_free(key);
  78159. #endif
  78160. return EXPECT_RESULT();
  78161. }
  78162. static int test_wolfSSL_EC_KEY_private_key(void)
  78163. {
  78164. EXPECT_DECLS;
  78165. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  78166. WOLFSSL_EC_KEY* key = NULL;
  78167. WOLFSSL_BIGNUM* priv = NULL;
  78168. WOLFSSL_BIGNUM* priv2 = NULL;
  78169. WOLFSSL_BIGNUM* bn;
  78170. ExpectNotNull(key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  78171. ExpectNotNull(priv = wolfSSL_BN_new());
  78172. ExpectNotNull(priv2 = wolfSSL_BN_new());
  78173. ExpectIntNE(BN_set_word(priv, 2), 0);
  78174. ExpectIntNE(BN_set_word(priv2, 2), 0);
  78175. ExpectNull(wolfSSL_EC_KEY_get0_private_key(NULL));
  78176. /* No private key set. */
  78177. ExpectNull(wolfSSL_EC_KEY_get0_private_key(key));
  78178. ExpectIntEQ(wolfSSL_EC_KEY_set_private_key(NULL, NULL), 0);
  78179. ExpectIntEQ(wolfSSL_EC_KEY_set_private_key(key, NULL), 0);
  78180. ExpectIntEQ(wolfSSL_EC_KEY_set_private_key(NULL, priv), 0);
  78181. ExpectIntEQ(wolfSSL_EC_KEY_set_private_key(key, priv), 1);
  78182. ExpectNotNull(bn = wolfSSL_EC_KEY_get0_private_key(key));
  78183. ExpectPtrNE(bn, priv);
  78184. ExpectIntEQ(wolfSSL_EC_KEY_set_private_key(key, priv2), 1);
  78185. ExpectNotNull(bn = wolfSSL_EC_KEY_get0_private_key(key));
  78186. ExpectPtrNE(bn, priv2);
  78187. wolfSSL_BN_free(priv2);
  78188. wolfSSL_BN_free(priv);
  78189. wolfSSL_EC_KEY_free(key);
  78190. #endif
  78191. return EXPECT_RESULT();
  78192. }
  78193. static int test_wolfSSL_EC_KEY_public_key(void)
  78194. {
  78195. EXPECT_DECLS;
  78196. #if defined(OPENSSL_EXTRA) && !defined(NO_BIO)
  78197. WOLFSSL_EC_KEY* key = NULL;
  78198. WOLFSSL_EC_POINT* pub = NULL;
  78199. WOLFSSL_EC_POINT* point = NULL;
  78200. ExpectNotNull(key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  78201. ExpectNull(wolfSSL_EC_KEY_get0_public_key(NULL));
  78202. ExpectNotNull(wolfSSL_EC_KEY_get0_public_key(key));
  78203. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(key), 1);
  78204. ExpectNotNull(pub = wolfSSL_EC_KEY_get0_public_key(key));
  78205. ExpectIntEQ(wolfSSL_EC_KEY_set_public_key(NULL, NULL), 0);
  78206. ExpectIntEQ(wolfSSL_EC_KEY_set_public_key(key, NULL), 0);
  78207. ExpectIntEQ(wolfSSL_EC_KEY_set_public_key(NULL, pub), 0);
  78208. ExpectIntEQ(wolfSSL_EC_KEY_set_public_key(key, pub), 1);
  78209. ExpectNotNull(point = wolfSSL_EC_KEY_get0_public_key(key));
  78210. ExpectPtrEq(point, pub);
  78211. wolfSSL_EC_KEY_free(key);
  78212. #endif
  78213. return EXPECT_RESULT();
  78214. }
  78215. static int test_wolfSSL_EC_KEY_print_fp(void)
  78216. {
  78217. EXPECT_DECLS;
  78218. #if defined(HAVE_ECC) && ((defined(HAVE_ECC224) && defined(HAVE_ECC256)) || \
  78219. defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 224 && \
  78220. defined(OPENSSL_EXTRA) && defined(XFPRINTF) && !defined(NO_FILESYSTEM) && \
  78221. !defined(NO_STDIO_FILESYSTEM)
  78222. EC_KEY* key = NULL;
  78223. /* Bad file pointer. */
  78224. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(NULL, key, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  78225. /* NULL key. */
  78226. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(stderr, NULL, 0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  78227. ExpectNotNull((key = wolfSSL_EC_KEY_new_by_curve_name(NID_secp224r1)));
  78228. /* Negative indent. */
  78229. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(stderr, key, -1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  78230. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(stderr, key, 4), WOLFSSL_SUCCESS);
  78231. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(key), WOLFSSL_SUCCESS);
  78232. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(stderr, key, 4), WOLFSSL_SUCCESS);
  78233. wolfSSL_EC_KEY_free(key);
  78234. ExpectNotNull((key = wolfSSL_EC_KEY_new_by_curve_name(
  78235. NID_X9_62_prime256v1)));
  78236. ExpectIntEQ(wolfSSL_EC_KEY_generate_key(key), WOLFSSL_SUCCESS);
  78237. ExpectIntEQ(wolfSSL_EC_KEY_print_fp(stderr, key, 4), WOLFSSL_SUCCESS);
  78238. wolfSSL_EC_KEY_free(key);
  78239. #endif
  78240. return EXPECT_RESULT();
  78241. }
  78242. static int test_wolfSSL_EC_get_builtin_curves(void)
  78243. {
  78244. EXPECT_DECLS;
  78245. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)
  78246. #if !defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION>2))
  78247. EC_builtin_curve* curves = NULL;
  78248. size_t crv_len = 0;
  78249. size_t i = 0;
  78250. ExpectIntGT((crv_len = EC_get_builtin_curves(NULL, 0)), 0);
  78251. ExpectNotNull(curves = (EC_builtin_curve*)XMALLOC(
  78252. sizeof(EC_builtin_curve) * crv_len, NULL, DYNAMIC_TYPE_TMP_BUFFER));
  78253. ExpectIntEQ((EC_get_builtin_curves(curves, 0)), crv_len);
  78254. ExpectIntEQ(EC_get_builtin_curves(curves, crv_len), crv_len);
  78255. for (i = 0; EXPECT_SUCCESS() && (i < crv_len); i++) {
  78256. if (curves[i].comment != NULL) {
  78257. ExpectStrEQ(OBJ_nid2sn(curves[i].nid), curves[i].comment);
  78258. }
  78259. }
  78260. if (crv_len > 1) {
  78261. ExpectIntEQ(EC_get_builtin_curves(curves, crv_len - 1), crv_len - 1);
  78262. }
  78263. XFREE(curves, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  78264. #endif /* !HAVE_FIPS || HAVE_FIPS_VERSION > 2 */
  78265. #endif /* OPENSSL_EXTRA || OPENSSL_ALL */
  78266. return EXPECT_RESULT();
  78267. }
  78268. static int test_wolfSSL_ECDSA_SIG(void)
  78269. {
  78270. EXPECT_DECLS;
  78271. #ifdef OPENSSL_EXTRA
  78272. WOLFSSL_ECDSA_SIG* sig = NULL;
  78273. WOLFSSL_ECDSA_SIG* sig2 = NULL;
  78274. WOLFSSL_BIGNUM* r = NULL;
  78275. WOLFSSL_BIGNUM* s = NULL;
  78276. const WOLFSSL_BIGNUM* r2 = NULL;
  78277. const WOLFSSL_BIGNUM* s2 = NULL;
  78278. const unsigned char* cp = NULL;
  78279. unsigned char* p = NULL;
  78280. unsigned char outSig[8];
  78281. unsigned char sigData[8] =
  78282. { 0x30, 0x06, 0x02, 0x01, 0x01, 0x02, 0x01, 0x01 };
  78283. unsigned char sigDataBad[8] =
  78284. { 0x30, 0x07, 0x02, 0x01, 0x01, 0x02, 0x01, 0x01 };
  78285. wolfSSL_ECDSA_SIG_free(NULL);
  78286. ExpectNotNull(sig = wolfSSL_ECDSA_SIG_new());
  78287. ExpectNotNull(r = wolfSSL_BN_new());
  78288. ExpectNotNull(s = wolfSSL_BN_new());
  78289. ExpectIntEQ(wolfSSL_BN_set_word(r, 1), 1);
  78290. ExpectIntEQ(wolfSSL_BN_set_word(s, 1), 1);
  78291. wolfSSL_ECDSA_SIG_get0(NULL, NULL, NULL);
  78292. wolfSSL_ECDSA_SIG_get0(NULL, &r2, NULL);
  78293. wolfSSL_ECDSA_SIG_get0(NULL, NULL, &s2);
  78294. wolfSSL_ECDSA_SIG_get0(NULL, &r2, &s2);
  78295. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(NULL, NULL, NULL), 0);
  78296. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(sig, NULL, NULL), 0);
  78297. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(NULL, r, NULL), 0);
  78298. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(NULL, NULL, s), 0);
  78299. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(NULL, r, s), 0);
  78300. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(sig, NULL, s), 0);
  78301. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(sig, r, NULL), 0);
  78302. r2 = NULL;
  78303. s2 = NULL;
  78304. wolfSSL_ECDSA_SIG_get0(NULL, &r2, &s2);
  78305. ExpectNull(r2);
  78306. ExpectNull(s2);
  78307. ExpectIntEQ(wolfSSL_ECDSA_SIG_set0(sig, r, s), 1);
  78308. if (EXPECT_FAIL()) {
  78309. wolfSSL_BN_free(r);
  78310. wolfSSL_BN_free(s);
  78311. }
  78312. wolfSSL_ECDSA_SIG_get0(sig, &r2, &s2);
  78313. ExpectPtrEq(r2, r);
  78314. ExpectPtrEq(s2, s);
  78315. r2 = NULL;
  78316. wolfSSL_ECDSA_SIG_get0(sig, &r2, NULL);
  78317. ExpectPtrEq(r2, r);
  78318. s2 = NULL;
  78319. wolfSSL_ECDSA_SIG_get0(sig, NULL, &s2);
  78320. ExpectPtrEq(s2, s);
  78321. /* r and s are freed when sig is freed. */
  78322. wolfSSL_ECDSA_SIG_free(sig);
  78323. sig = NULL;
  78324. ExpectNull(wolfSSL_d2i_ECDSA_SIG(NULL, NULL, sizeof(sigData)));
  78325. cp = sigDataBad;
  78326. ExpectNull(wolfSSL_d2i_ECDSA_SIG(NULL, &cp, sizeof(sigDataBad)));
  78327. cp = sigData;
  78328. ExpectNotNull((sig = wolfSSL_d2i_ECDSA_SIG(NULL, &cp, sizeof(sigData))));
  78329. ExpectIntEQ((cp == sigData + 8), 1);
  78330. cp = sigData;
  78331. ExpectNull(wolfSSL_d2i_ECDSA_SIG(&sig, NULL, sizeof(sigData)));
  78332. ExpectNotNull((sig2 = wolfSSL_d2i_ECDSA_SIG(&sig, &cp, sizeof(sigData))));
  78333. ExpectIntEQ((sig == sig2), 1);
  78334. cp = outSig;
  78335. p = outSig;
  78336. ExpectIntEQ(wolfSSL_i2d_ECDSA_SIG(NULL, &p), 0);
  78337. ExpectIntEQ(wolfSSL_i2d_ECDSA_SIG(NULL, NULL), 0);
  78338. ExpectIntEQ(wolfSSL_i2d_ECDSA_SIG(sig, NULL), 8);
  78339. ExpectIntEQ(wolfSSL_i2d_ECDSA_SIG(sig, &p), sizeof(sigData));
  78340. ExpectIntEQ((p == outSig + 8), 1);
  78341. ExpectIntEQ(XMEMCMP(sigData, outSig, 8), 0);
  78342. p = NULL;
  78343. ExpectIntEQ(wolfSSL_i2d_ECDSA_SIG(sig, &p), 8);
  78344. #ifndef WOLFSSL_I2D_ECDSA_SIG_ALLOC
  78345. ExpectNull(p);
  78346. #else
  78347. ExpectNotNull(p);
  78348. ExpectIntEQ(XMEMCMP(p, outSig, 8), 0);
  78349. XFREE(p, NULL, DYNAMIC_TYPE_OPENSSL);
  78350. #endif
  78351. wolfSSL_ECDSA_SIG_free(sig);
  78352. #endif
  78353. return EXPECT_RESULT();
  78354. }
  78355. static int test_ECDSA_size_sign(void)
  78356. {
  78357. EXPECT_DECLS;
  78358. #if defined(OPENSSL_EXTRA) && !defined(NO_ECC256) && !defined(NO_ECC_SECP)
  78359. EC_KEY* key = NULL;
  78360. ECDSA_SIG* ecdsaSig = NULL;
  78361. int id;
  78362. byte hash[WC_MAX_DIGEST_SIZE];
  78363. byte hash2[WC_MAX_DIGEST_SIZE];
  78364. byte sig[ECC_MAX_SIG_SIZE];
  78365. unsigned int sigSz = sizeof(sig);
  78366. XMEMSET(hash, 123, sizeof(hash));
  78367. XMEMSET(hash2, 234, sizeof(hash2));
  78368. id = wc_ecc_get_curve_id_from_name("SECP256R1");
  78369. ExpectIntEQ(id, ECC_SECP256R1);
  78370. ExpectNotNull(key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  78371. ExpectIntEQ(EC_KEY_generate_key(key), 1);
  78372. ExpectIntGE(ECDSA_size(NULL), 0);
  78373. ExpectIntEQ(ECDSA_sign(0, hash, sizeof(hash), sig, &sigSz, NULL), 0);
  78374. ExpectIntEQ(ECDSA_sign(0, NULL, sizeof(hash), sig, &sigSz, key), 0);
  78375. ExpectIntEQ(ECDSA_sign(0, hash, sizeof(hash), NULL, &sigSz, key), 0);
  78376. ExpectIntEQ(ECDSA_verify(0, hash, sizeof(hash), sig, (int)sigSz, NULL), 0);
  78377. ExpectIntEQ(ECDSA_verify(0, NULL, sizeof(hash), sig, (int)sigSz, key), 0);
  78378. ExpectIntEQ(ECDSA_verify(0, hash, sizeof(hash), NULL, (int)sigSz, key), 0);
  78379. ExpectIntEQ(ECDSA_sign(0, hash, sizeof(hash), sig, &sigSz, key), 1);
  78380. ExpectIntGE(ECDSA_size(key), sigSz);
  78381. ExpectIntEQ(ECDSA_verify(0, hash, sizeof(hash), sig, (int)sigSz, key), 1);
  78382. ExpectIntEQ(ECDSA_verify(0, hash2, sizeof(hash2), sig, (int)sigSz, key), 0);
  78383. ExpectNull(ECDSA_do_sign(NULL, sizeof(hash), NULL));
  78384. ExpectNull(ECDSA_do_sign(NULL, sizeof(hash), key));
  78385. ExpectNull(ECDSA_do_sign(hash, sizeof(hash), NULL));
  78386. ExpectNotNull(ecdsaSig = ECDSA_do_sign(hash, sizeof(hash), key));
  78387. ExpectIntEQ(ECDSA_do_verify(NULL, sizeof(hash), NULL, NULL), -1);
  78388. ExpectIntEQ(ECDSA_do_verify(hash, sizeof(hash), NULL, NULL), -1);
  78389. ExpectIntEQ(ECDSA_do_verify(NULL, sizeof(hash), ecdsaSig, NULL), -1);
  78390. ExpectIntEQ(ECDSA_do_verify(NULL, sizeof(hash), NULL, key), -1);
  78391. ExpectIntEQ(ECDSA_do_verify(NULL, sizeof(hash), ecdsaSig, key), -1);
  78392. ExpectIntEQ(ECDSA_do_verify(hash, sizeof(hash), NULL, key), -1);
  78393. ExpectIntEQ(ECDSA_do_verify(hash, sizeof(hash), ecdsaSig, NULL), -1);
  78394. ExpectIntEQ(ECDSA_do_verify(hash, sizeof(hash), ecdsaSig, key), 1);
  78395. ExpectIntEQ(ECDSA_do_verify(hash2, sizeof(hash2), ecdsaSig, key), 0);
  78396. ECDSA_SIG_free(ecdsaSig);
  78397. EC_KEY_free(key);
  78398. #endif /* OPENSSL_EXTRA && !NO_ECC256 && !NO_ECC_SECP */
  78399. return EXPECT_RESULT();
  78400. }
  78401. static int test_ECDH_compute_key(void)
  78402. {
  78403. EXPECT_DECLS;
  78404. #if defined(OPENSSL_EXTRA) && !defined(NO_ECC256) && !defined(NO_ECC_SECP) && \
  78405. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  78406. EC_KEY* key1 = NULL;
  78407. EC_KEY* key2 = NULL;
  78408. EC_POINT* pub1 = NULL;
  78409. EC_POINT* pub2 = NULL;
  78410. byte secret1[32];
  78411. byte secret2[32];
  78412. int i;
  78413. ExpectNotNull(key1 = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  78414. ExpectIntEQ(EC_KEY_generate_key(key1), 1);
  78415. ExpectNotNull(pub1 = wolfSSL_EC_KEY_get0_public_key(key1));
  78416. ExpectNotNull(key2 = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  78417. ExpectIntEQ(EC_KEY_generate_key(key2), 1);
  78418. ExpectNotNull(pub2 = wolfSSL_EC_KEY_get0_public_key(key2));
  78419. ExpectIntEQ(ECDH_compute_key(NULL, sizeof(secret1), NULL, NULL, NULL), 0);
  78420. ExpectIntEQ(ECDH_compute_key(secret1, sizeof(secret1), NULL, NULL, NULL),
  78421. 0);
  78422. ExpectIntEQ(ECDH_compute_key(NULL, sizeof(secret1), pub2, NULL, NULL), 0);
  78423. ExpectIntEQ(ECDH_compute_key(NULL, sizeof(secret1), NULL, key1, NULL), 0);
  78424. ExpectIntEQ(ECDH_compute_key(NULL, sizeof(secret1), pub2, key1, NULL), 0);
  78425. ExpectIntEQ(ECDH_compute_key(secret1, sizeof(secret1), NULL, key1, NULL),
  78426. 0);
  78427. ExpectIntEQ(ECDH_compute_key(secret1, sizeof(secret1), pub2, NULL, NULL),
  78428. 0);
  78429. ExpectIntEQ(ECDH_compute_key(secret1, sizeof(secret1) - 16, pub2, key1,
  78430. NULL), 0);
  78431. ExpectIntEQ(ECDH_compute_key(secret1, sizeof(secret1), pub2, key1, NULL),
  78432. sizeof(secret1));
  78433. ExpectIntEQ(ECDH_compute_key(secret2, sizeof(secret2), pub1, key2, NULL),
  78434. sizeof(secret2));
  78435. for (i = 0; i < (int)sizeof(secret1); i++) {
  78436. ExpectIntEQ(secret1[i], secret2[i]);
  78437. }
  78438. EC_KEY_free(key2);
  78439. EC_KEY_free(key1);
  78440. #endif /* OPENSSL_EXTRA && !NO_ECC256 && !NO_ECC_SECP &&
  78441. * !WOLF_CRYPTO_CB_ONLY_ECC */
  78442. return EXPECT_RESULT();
  78443. }
  78444. #endif /* HAVE_ECC && !OPENSSL_NO_PK */
  78445. #if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
  78446. defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_CERT_REQ) && \
  78447. !defined(NO_ASN_TIME)
  78448. static int test_openssl_make_self_signed_certificate(EVP_PKEY* pkey,
  78449. int expectedDerSz)
  78450. {
  78451. EXPECT_DECLS;
  78452. X509* x509 = NULL;
  78453. BIGNUM* serial_number = NULL;
  78454. X509_NAME* name = NULL;
  78455. time_t epoch_off = 0;
  78456. ASN1_INTEGER* asn1_serial_number = NULL;
  78457. long not_before, not_after;
  78458. int derSz;
  78459. ExpectNotNull(x509 = X509_new());
  78460. ExpectIntNE(X509_set_pubkey(x509, pkey), 0);
  78461. ExpectNotNull(serial_number = BN_new());
  78462. ExpectIntNE(BN_pseudo_rand(serial_number, 64, 0, 0), 0);
  78463. ExpectNotNull(asn1_serial_number = X509_get_serialNumber(x509));
  78464. ExpectNotNull(BN_to_ASN1_INTEGER(serial_number, asn1_serial_number));
  78465. /* version 3 */
  78466. ExpectIntNE(X509_set_version(x509, 2L), 0);
  78467. ExpectNotNull(name = X509_NAME_new());
  78468. ExpectIntNE(X509_NAME_add_entry_by_NID(name, NID_commonName, MBSTRING_UTF8,
  78469. (unsigned char*)"www.wolfssl.com", -1, -1, 0), 0);
  78470. ExpectIntNE(X509_NAME_add_entry_by_NID(name, NID_pkcs9_contentType,
  78471. MBSTRING_UTF8,(unsigned char*)"Server", -1, -1, 0), 0);
  78472. ExpectIntNE(X509_set_subject_name(x509, name), 0);
  78473. ExpectIntNE(X509_set_issuer_name(x509, name), 0);
  78474. not_before = (long)wc_Time(NULL);
  78475. not_after = not_before + (365 * 24 * 60 * 60);
  78476. ExpectNotNull(X509_time_adj(X509_get_notBefore(x509), not_before,
  78477. &epoch_off));
  78478. ExpectNotNull(X509_time_adj(X509_get_notAfter(x509), not_after,
  78479. &epoch_off));
  78480. ExpectIntNE(X509_sign(x509, pkey, EVP_sha256()), 0);
  78481. ExpectNotNull(wolfSSL_X509_get_der(x509, &derSz));
  78482. ExpectIntGE(derSz, expectedDerSz);
  78483. BN_free(serial_number);
  78484. X509_NAME_free(name);
  78485. X509_free(x509);
  78486. return EXPECT_RESULT();
  78487. }
  78488. #endif
  78489. static int test_openssl_generate_key_and_cert(void)
  78490. {
  78491. EXPECT_DECLS;
  78492. #if defined(OPENSSL_EXTRA)
  78493. int expectedDerSz;
  78494. EVP_PKEY* pkey = NULL;
  78495. #ifdef HAVE_ECC
  78496. EC_KEY* ec_key = NULL;
  78497. #endif
  78498. #if !defined(NO_RSA)
  78499. int key_length = 2048;
  78500. BIGNUM* exponent = NULL;
  78501. RSA* rsa = NULL;
  78502. ExpectNotNull(pkey = EVP_PKEY_new());
  78503. ExpectNotNull(exponent = BN_new());
  78504. ExpectNotNull(rsa = RSA_new());
  78505. ExpectIntNE(BN_set_word(exponent, WC_RSA_EXPONENT), 0);
  78506. #ifndef WOLFSSL_KEY_GEN
  78507. ExpectIntEQ(RSA_generate_key_ex(rsa, key_length, exponent, NULL), 0);
  78508. #if defined(USE_CERT_BUFFERS_1024)
  78509. ExpectIntNE(wolfSSL_RSA_LoadDer_ex(rsa, server_key_der_1024,
  78510. sizeof_server_key_der_1024, WOLFSSL_RSA_LOAD_PRIVATE), 0);
  78511. key_length = 1024;
  78512. #elif defined(USE_CERT_BUFFERS_2048)
  78513. ExpectIntNE(wolfSSL_RSA_LoadDer_ex(rsa, server_key_der_2048,
  78514. sizeof_server_key_der_2048, WOLFSSL_RSA_LOAD_PRIVATE), 0);
  78515. #else
  78516. RSA_free(rsa);
  78517. rsa = NULL;
  78518. #endif
  78519. #else
  78520. ExpectIntEQ(RSA_generate_key_ex(NULL, key_length, exponent, NULL), 0);
  78521. ExpectIntEQ(RSA_generate_key_ex(rsa, 0, exponent, NULL), 0);
  78522. ExpectIntEQ(RSA_generate_key_ex(rsa, key_length, NULL, NULL), 0);
  78523. ExpectIntNE(RSA_generate_key_ex(rsa, key_length, exponent, NULL), 0);
  78524. #endif
  78525. if (rsa) {
  78526. ExpectIntNE(EVP_PKEY_assign_RSA(pkey, rsa), 0);
  78527. if (EXPECT_FAIL()) {
  78528. RSA_free(rsa);
  78529. }
  78530. #if !defined(NO_CERTS) && defined(WOLFSSL_CERT_GEN) && \
  78531. defined(WOLFSSL_CERT_REQ) && !defined(NO_ASN_TIME)
  78532. expectedDerSz = 743;
  78533. ExpectIntEQ(test_openssl_make_self_signed_certificate(pkey,
  78534. expectedDerSz), TEST_SUCCESS);
  78535. #endif
  78536. }
  78537. EVP_PKEY_free(pkey);
  78538. pkey = NULL;
  78539. BN_free(exponent);
  78540. #endif /* !NO_RSA */
  78541. #ifdef HAVE_ECC
  78542. ExpectNotNull(pkey = EVP_PKEY_new());
  78543. ExpectNotNull(ec_key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
  78544. #ifndef NO_WOLFSSL_STUB
  78545. EC_KEY_set_asn1_flag(ec_key, OPENSSL_EC_NAMED_CURVE);
  78546. #endif
  78547. ExpectIntNE(EC_KEY_generate_key(ec_key), 0);
  78548. ExpectIntNE(EVP_PKEY_assign_EC_KEY(pkey, ec_key), 0);
  78549. if (EXPECT_FAIL()) {
  78550. EC_KEY_free(ec_key);
  78551. }
  78552. #if !defined(NO_CERTS) && defined(WOLFSSL_CERT_GEN) && \
  78553. defined(WOLFSSL_CERT_REQ) && !defined(NO_ASN_TIME)
  78554. expectedDerSz = 344;
  78555. ExpectIntEQ(test_openssl_make_self_signed_certificate(pkey, expectedDerSz),
  78556. TEST_SUCCESS);
  78557. #endif
  78558. EVP_PKEY_free(pkey);
  78559. #endif /* HAVE_ECC */
  78560. (void)pkey;
  78561. (void)expectedDerSz;
  78562. #endif /* OPENSSL_EXTRA */
  78563. return EXPECT_RESULT();
  78564. }
  78565. static int test_stubs_are_stubs(void)
  78566. {
  78567. EXPECT_DECLS;
  78568. #if defined(OPENSSL_EXTRA) && !defined(NO_WOLFSSL_STUB) && \
  78569. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  78570. WOLFSSL_CTX* ctx = NULL;
  78571. WOLFSSL_CTX* ctxN = NULL;
  78572. #ifndef NO_WOLFSSL_CLIENT
  78573. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  78574. #elif !defined(NO_WOLFSSL_SERVER)
  78575. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  78576. #endif
  78577. #define CHECKZERO_RET(x, y, z) ExpectIntEQ((int) x(y), 0); \
  78578. ExpectIntEQ((int) x(z), 0)
  78579. /* test logic, all stubs return same result regardless of ctx being NULL
  78580. * as there are no sanity checks, it's just a stub! If at some
  78581. * point a stub is not a stub it should begin to return BAD_FUNC_ARG
  78582. * if invalid inputs are supplied. Test calling both
  78583. * with and without valid inputs, if a stub functionality remains unchanged.
  78584. */
  78585. CHECKZERO_RET(wolfSSL_CTX_sess_accept, ctx, ctxN);
  78586. CHECKZERO_RET(wolfSSL_CTX_sess_connect, ctx, ctxN);
  78587. CHECKZERO_RET(wolfSSL_CTX_sess_accept_good, ctx, ctxN);
  78588. CHECKZERO_RET(wolfSSL_CTX_sess_connect_good, ctx, ctxN);
  78589. CHECKZERO_RET(wolfSSL_CTX_sess_accept_renegotiate, ctx, ctxN);
  78590. CHECKZERO_RET(wolfSSL_CTX_sess_connect_renegotiate, ctx, ctxN);
  78591. CHECKZERO_RET(wolfSSL_CTX_sess_hits, ctx, ctxN);
  78592. CHECKZERO_RET(wolfSSL_CTX_sess_cb_hits, ctx, ctxN);
  78593. CHECKZERO_RET(wolfSSL_CTX_sess_cache_full, ctx, ctxN);
  78594. CHECKZERO_RET(wolfSSL_CTX_sess_misses, ctx, ctxN);
  78595. CHECKZERO_RET(wolfSSL_CTX_sess_timeouts, ctx, ctxN);
  78596. /* when implemented this should take WOLFSSL object instead, right now
  78597. * always returns 0 */
  78598. ExpectPtrEq(SSL_get_current_expansion(NULL), NULL);
  78599. wolfSSL_CTX_free(ctx);
  78600. ctx = NULL;
  78601. ExpectStrEQ(SSL_COMP_get_name(NULL), "not supported");
  78602. ExpectPtrEq(SSL_get_current_expansion(NULL), NULL);
  78603. #endif /* OPENSSL_EXTRA && !NO_WOLFSSL_STUB && (!NO_WOLFSSL_CLIENT ||
  78604. * !NO_WOLFSSL_SERVER) */
  78605. return EXPECT_RESULT();
  78606. }
  78607. static int test_CONF_modules_xxx(void)
  78608. {
  78609. int res = TEST_SKIPPED;
  78610. #if defined(OPENSSL_EXTRA)
  78611. CONF_modules_free();
  78612. CONF_modules_unload(0);
  78613. CONF_modules_unload(1);
  78614. CONF_modules_unload(-1);
  78615. res = TEST_SUCCESS;
  78616. #endif /* OPENSSL_EXTRA */
  78617. return res;
  78618. }
  78619. static int test_CRYPTO_set_dynlock_xxx(void)
  78620. {
  78621. int res = TEST_SKIPPED;
  78622. #if defined(OPENSSL_EXTRA)
  78623. CRYPTO_set_dynlock_create_callback(
  78624. (struct CRYPTO_dynlock_value *(*)(const char*, int))NULL);
  78625. CRYPTO_set_dynlock_create_callback(
  78626. (struct CRYPTO_dynlock_value *(*)(const char*, int))1);
  78627. CRYPTO_set_dynlock_destroy_callback(
  78628. (void (*)(struct CRYPTO_dynlock_value*, const char*, int))NULL);
  78629. CRYPTO_set_dynlock_destroy_callback(
  78630. (void (*)(struct CRYPTO_dynlock_value*, const char*, int))1);
  78631. CRYPTO_set_dynlock_lock_callback(
  78632. (void (*)(int, struct CRYPTO_dynlock_value *, const char*, int))NULL);
  78633. CRYPTO_set_dynlock_lock_callback(
  78634. (void (*)(int, struct CRYPTO_dynlock_value *, const char*, int))1);
  78635. res = TEST_SUCCESS;
  78636. #endif /* OPENSSL_EXTRA */
  78637. return res;
  78638. }
  78639. static int test_CRYPTO_THREADID_xxx(void)
  78640. {
  78641. EXPECT_DECLS;
  78642. #if defined(OPENSSL_EXTRA)
  78643. CRYPTO_THREADID_current((CRYPTO_THREADID*)NULL);
  78644. CRYPTO_THREADID_current((CRYPTO_THREADID*)1);
  78645. ExpectIntEQ(CRYPTO_THREADID_hash((const CRYPTO_THREADID*)NULL), 0);
  78646. #endif /* OPENSSL_EXTRA */
  78647. return EXPECT_RESULT();
  78648. }
  78649. static int test_ENGINE_cleanup(void)
  78650. {
  78651. int res = TEST_SKIPPED;
  78652. #if defined(OPENSSL_EXTRA)
  78653. ENGINE_cleanup();
  78654. res = TEST_SUCCESS;
  78655. #endif /* OPENSSL_EXTRA */
  78656. return res;
  78657. }
  78658. static int test_wolfSSL_CTX_LoadCRL(void)
  78659. {
  78660. EXPECT_DECLS;
  78661. #if defined(HAVE_CRL) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) && \
  78662. (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER))
  78663. WOLFSSL_CTX* ctx = NULL;
  78664. WOLFSSL* ssl = NULL;
  78665. const char* badPath = "dummypath";
  78666. const char* validPath = "./certs/crl";
  78667. const char* validFilePath = "./certs/crl/cliCrl.pem";
  78668. const char* issuerCert = "./certs/client-cert.pem";
  78669. int derType = WOLFSSL_FILETYPE_ASN1;
  78670. int pemType = WOLFSSL_FILETYPE_PEM;
  78671. #ifdef HAVE_CRL_MONITOR
  78672. int monitor = WOLFSSL_CRL_MONITOR;
  78673. #else
  78674. int monitor = 0;
  78675. #endif
  78676. WOLFSSL_CERT_MANAGER* cm = NULL;
  78677. #define FAIL_T1(x, y, z, p, d) ExpectIntEQ((int) x(y, z, p, d), \
  78678. WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  78679. #define FAIL_T2(x, y, z, p, d) ExpectIntEQ((int) x(y, z, p, d), \
  78680. WC_NO_ERR_TRACE(NOT_COMPILED_IN))
  78681. #define SUCC_T(x, y, z, p, d) ExpectIntEQ((int) x(y, z, p, d), \
  78682. WOLFSSL_SUCCESS)
  78683. #ifndef NO_WOLFSSL_CLIENT
  78684. #define NEW_CTX(ctx) ExpectNotNull( \
  78685. (ctx) = wolfSSL_CTX_new(wolfSSLv23_client_method()))
  78686. #elif !defined(NO_WOLFSSL_SERVER)
  78687. #define NEW_CTX(ctx) ExpectNotNull( \
  78688. (ctx) = wolfSSL_CTX_new(wolfSSLv23_server_method()))
  78689. #else
  78690. #define NEW_CTX(ctx) return
  78691. #endif
  78692. FAIL_T1(wolfSSL_CTX_LoadCRL, ctx, validPath, pemType, monitor);
  78693. NEW_CTX(ctx);
  78694. #ifndef HAVE_CRL_MONITOR
  78695. FAIL_T2(wolfSSL_CTX_LoadCRL, ctx, validPath, pemType, WOLFSSL_CRL_MONITOR);
  78696. wolfSSL_CTX_free(ctx);
  78697. NEW_CTX(ctx);
  78698. #endif
  78699. SUCC_T (wolfSSL_CTX_LoadCRL, ctx, validPath, pemType, monitor);
  78700. SUCC_T (wolfSSL_CTX_LoadCRL, ctx, badPath, pemType, monitor);
  78701. SUCC_T (wolfSSL_CTX_LoadCRL, ctx, badPath, derType, monitor);
  78702. wolfSSL_CTX_free(ctx);
  78703. ctx = NULL;
  78704. NEW_CTX(ctx);
  78705. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, issuerCert, NULL),
  78706. WOLFSSL_SUCCESS);
  78707. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx, validFilePath, pemType), WOLFSSL_SUCCESS);
  78708. wolfSSL_CTX_free(ctx);
  78709. ctx = NULL;
  78710. NEW_CTX(ctx);
  78711. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx, issuerCert, NULL),
  78712. WOLFSSL_SUCCESS);
  78713. ExpectNotNull(ssl = wolfSSL_new(ctx));
  78714. ExpectIntEQ(wolfSSL_LoadCRLFile(ssl, validFilePath, pemType), WOLFSSL_SUCCESS);
  78715. wolfSSL_free(ssl);
  78716. ssl = NULL;
  78717. wolfSSL_CTX_free(ctx);
  78718. ctx = NULL;
  78719. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  78720. ExpectIntEQ(wolfSSL_CertManagerLoadCA(cm, issuerCert, NULL),
  78721. WOLFSSL_SUCCESS);
  78722. ExpectIntEQ(wolfSSL_CertManagerLoadCRLFile(cm, validFilePath, pemType),
  78723. WOLFSSL_SUCCESS);
  78724. wolfSSL_CertManagerFree(cm);
  78725. #endif
  78726. return EXPECT_RESULT();
  78727. }
  78728. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_CRL) && \
  78729. !defined(WOLFSSL_CRL_ALLOW_MISSING_CDP)
  78730. static int test_multiple_crls_same_issuer_ctx_ready(WOLFSSL_CTX* ctx)
  78731. {
  78732. EXPECT_DECLS;
  78733. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  78734. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx, "./certs/crl/crl.pem",
  78735. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  78736. return EXPECT_RESULT();
  78737. }
  78738. #endif
  78739. static int test_multiple_crls_same_issuer(void)
  78740. {
  78741. EXPECT_DECLS;
  78742. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_CRL) && \
  78743. !defined(WOLFSSL_CRL_ALLOW_MISSING_CDP)
  78744. test_ssl_cbf client_cbs, server_cbs;
  78745. struct {
  78746. const char* server_cert;
  78747. const char* server_key;
  78748. } test_params[] = {
  78749. { "./certs/server-cert.pem", "./certs/server-key.pem" },
  78750. { "./certs/server-revoked-cert.pem", "./certs/server-revoked-key.pem" }
  78751. };
  78752. size_t i;
  78753. for (i = 0; i < (sizeof(test_params)/sizeof(*test_params)); i++) {
  78754. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  78755. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  78756. server_cbs.certPemFile = test_params[i].server_cert;
  78757. server_cbs.keyPemFile = test_params[i].server_key;
  78758. client_cbs.crlPemFile = "./certs/crl/extra-crls/general-server-crl.pem";
  78759. client_cbs.ctx_ready = test_multiple_crls_same_issuer_ctx_ready;
  78760. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  78761. &server_cbs, NULL), -1001);
  78762. }
  78763. #endif
  78764. return EXPECT_RESULT();
  78765. }
  78766. static int test_SetTmpEC_DHE_Sz(void)
  78767. {
  78768. EXPECT_DECLS;
  78769. #if defined(HAVE_ECC) && !defined(NO_WOLFSSL_CLIENT)
  78770. WOLFSSL_CTX *ctx = NULL;
  78771. WOLFSSL *ssl = NULL;
  78772. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  78773. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_SetTmpEC_DHE_Sz(ctx, 32));
  78774. ExpectNotNull(ssl = wolfSSL_new(ctx));
  78775. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_SetTmpEC_DHE_Sz(ssl, 32));
  78776. wolfSSL_free(ssl);
  78777. wolfSSL_CTX_free(ctx);
  78778. #endif
  78779. return EXPECT_RESULT();
  78780. }
  78781. static int test_wolfSSL_CTX_get0_privatekey(void)
  78782. {
  78783. EXPECT_DECLS;
  78784. #ifdef OPENSSL_ALL
  78785. WOLFSSL_CTX* ctx = NULL;
  78786. (void)ctx;
  78787. #ifndef NO_RSA
  78788. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_method()));
  78789. ExpectNull(SSL_CTX_get0_privatekey(ctx));
  78790. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  78791. WOLFSSL_FILETYPE_PEM));
  78792. ExpectNull(SSL_CTX_get0_privatekey(ctx));
  78793. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  78794. WOLFSSL_FILETYPE_PEM));
  78795. ExpectNotNull(SSL_CTX_get0_privatekey(ctx));
  78796. wolfSSL_CTX_free(ctx);
  78797. ctx = NULL;
  78798. #endif
  78799. #ifdef HAVE_ECC
  78800. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_method()));
  78801. ExpectNull(SSL_CTX_get0_privatekey(ctx));
  78802. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, eccCertFile,
  78803. WOLFSSL_FILETYPE_PEM));
  78804. ExpectNull(SSL_CTX_get0_privatekey(ctx));
  78805. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, eccKeyFile,
  78806. WOLFSSL_FILETYPE_PEM));
  78807. ExpectNotNull(SSL_CTX_get0_privatekey(ctx));
  78808. wolfSSL_CTX_free(ctx);
  78809. #endif
  78810. #endif
  78811. return EXPECT_RESULT();
  78812. }
  78813. static int test_wolfSSL_dtls_set_mtu(void)
  78814. {
  78815. EXPECT_DECLS;
  78816. #if (defined(WOLFSSL_DTLS_MTU) || defined(WOLFSSL_SCTP)) && \
  78817. !defined(NO_WOLFSSL_SERVER) && defined(WOLFSSL_DTLS) && \
  78818. !defined(WOLFSSL_NO_TLS12)
  78819. WOLFSSL_CTX* ctx = NULL;
  78820. WOLFSSL* ssl = NULL;
  78821. const char* testCertFile;
  78822. const char* testKeyFile;
  78823. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfDTLSv1_2_server_method()));
  78824. #ifndef NO_RSA
  78825. testCertFile = svrCertFile;
  78826. testKeyFile = svrKeyFile;
  78827. #elif defined(HAVE_ECC)
  78828. testCertFile = eccCertFile;
  78829. testKeyFile = eccKeyFile;
  78830. #endif
  78831. if (testCertFile != NULL && testKeyFile != NULL) {
  78832. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx, testCertFile,
  78833. WOLFSSL_FILETYPE_PEM));
  78834. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  78835. WOLFSSL_FILETYPE_PEM));
  78836. }
  78837. ExpectNotNull(ssl = wolfSSL_new(ctx));
  78838. ExpectIntEQ(wolfSSL_CTX_dtls_set_mtu(NULL, 1488), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  78839. ExpectIntEQ(wolfSSL_dtls_set_mtu(NULL, 1488), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  78840. ExpectIntEQ(wolfSSL_CTX_dtls_set_mtu(ctx, 20000), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  78841. ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl, 20000), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  78842. ExpectIntEQ(wolfSSL_get_error(ssl, WC_NO_ERR_TRACE(WOLFSSL_FAILURE)), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  78843. ExpectIntEQ(wolfSSL_CTX_dtls_set_mtu(ctx, 1488), WOLFSSL_SUCCESS);
  78844. ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl, 1488), WOLFSSL_SUCCESS);
  78845. wolfSSL_free(ssl);
  78846. wolfSSL_CTX_free(ctx);
  78847. #endif
  78848. return EXPECT_RESULT();
  78849. }
  78850. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(SINGLE_THREADED) && \
  78851. defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12)
  78852. static WC_INLINE void generateDTLSMsg(byte* out, int outSz, word32 seq,
  78853. enum HandShakeType hsType, word16 length)
  78854. {
  78855. size_t idx = 0;
  78856. byte* l;
  78857. /* record layer */
  78858. /* handshake type */
  78859. out[idx++] = handshake;
  78860. /* protocol version */
  78861. out[idx++] = 0xfe;
  78862. out[idx++] = 0xfd; /* DTLS 1.2 */
  78863. /* epoch 0 */
  78864. XMEMSET(out + idx, 0, 2);
  78865. idx += 2;
  78866. /* sequence number */
  78867. XMEMSET(out + idx, 0, 6);
  78868. c32toa(seq, out + idx + 2);
  78869. idx += 6;
  78870. /* length in BE */
  78871. if (length)
  78872. c16toa(length, out + idx);
  78873. else
  78874. c16toa(outSz - idx - 2, out + idx);
  78875. idx += 2;
  78876. /* handshake layer */
  78877. /* handshake type */
  78878. out[idx++] = (byte)hsType;
  78879. /* length */
  78880. l = out + idx;
  78881. idx += 3;
  78882. /* message seq */
  78883. c16toa(0, out + idx);
  78884. idx += 2;
  78885. /* frag offset */
  78886. c32to24(0, out + idx);
  78887. idx += 3;
  78888. /* frag length */
  78889. c32to24((word32)outSz - (word32)idx - 3, l);
  78890. c32to24((word32)outSz - (word32)idx - 3, out + idx);
  78891. idx += 3;
  78892. XMEMSET(out + idx, 0, outSz - idx);
  78893. }
  78894. static void test_wolfSSL_dtls_plaintext_server(WOLFSSL* ssl)
  78895. {
  78896. byte msg[] = "This is a msg for the client";
  78897. byte reply[40];
  78898. AssertIntGT(wolfSSL_read(ssl, reply, sizeof(reply)),0);
  78899. reply[sizeof(reply) - 1] = '\0';
  78900. fprintf(stderr, "Client message: %s\n", reply);
  78901. AssertIntEQ(wolfSSL_write(ssl, msg, sizeof(msg)), sizeof(msg));
  78902. }
  78903. static void test_wolfSSL_dtls_plaintext_client(WOLFSSL* ssl)
  78904. {
  78905. byte ch[50];
  78906. int fd = wolfSSL_get_fd(ssl);
  78907. byte msg[] = "This is a msg for the server";
  78908. byte reply[40];
  78909. generateDTLSMsg(ch, sizeof(ch), 20, client_hello, 0);
  78910. /* Server should ignore this datagram */
  78911. AssertIntEQ(send(fd, ch, sizeof(ch), 0), sizeof(ch));
  78912. generateDTLSMsg(ch, sizeof(ch), 20, client_hello, 10000);
  78913. /* Server should ignore this datagram */
  78914. AssertIntEQ(send(fd, ch, sizeof(ch), 0), sizeof(ch));
  78915. AssertIntEQ(wolfSSL_write(ssl, msg, sizeof(msg)), sizeof(msg));
  78916. AssertIntGT(wolfSSL_read(ssl, reply, sizeof(reply)),0);
  78917. reply[sizeof(reply) - 1] = '\0';
  78918. fprintf(stderr, "Server response: %s\n", reply);
  78919. }
  78920. static int test_wolfSSL_dtls_plaintext(void)
  78921. {
  78922. callback_functions func_cb_client;
  78923. callback_functions func_cb_server;
  78924. size_t i;
  78925. struct test_params {
  78926. method_provider client_meth;
  78927. method_provider server_meth;
  78928. ssl_callback on_result_server;
  78929. ssl_callback on_result_client;
  78930. } params[] = {
  78931. {wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method,
  78932. test_wolfSSL_dtls_plaintext_server,
  78933. test_wolfSSL_dtls_plaintext_client},
  78934. };
  78935. for (i = 0; i < sizeof(params)/sizeof(*params); i++) {
  78936. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  78937. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  78938. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  78939. func_cb_server.method = params[i].server_meth;
  78940. func_cb_client.method = params[i].client_meth;
  78941. func_cb_client.on_result = params[i].on_result_client;
  78942. func_cb_server.on_result = params[i].on_result_server;
  78943. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  78944. if (!func_cb_client.return_code)
  78945. return TEST_FAIL;
  78946. if (!func_cb_server.return_code)
  78947. return TEST_FAIL;
  78948. }
  78949. return TEST_RES_CHECK(1);
  78950. }
  78951. #else
  78952. static int test_wolfSSL_dtls_plaintext(void) {
  78953. return TEST_SKIPPED;
  78954. }
  78955. #endif
  78956. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(SINGLE_THREADED) && \
  78957. defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12)
  78958. static void test_wolfSSL_dtls12_fragments_spammer(WOLFSSL* ssl)
  78959. {
  78960. byte b[1100]; /* buffer for the messages to send */
  78961. size_t idx = 0;
  78962. size_t seq_offset = 0;
  78963. size_t msg_offset = 0;
  78964. int i;
  78965. int fd = wolfSSL_get_fd(ssl);
  78966. int ret = wolfSSL_connect_cert(ssl); /* This gets us past the cookie */
  78967. word32 seq_number = 100; /* start high so server definitely reads this */
  78968. word16 msg_number = 50; /* start high so server has to buffer this */
  78969. AssertIntEQ(ret, 1);
  78970. /* Now let's start spamming the peer with fragments it needs to store */
  78971. XMEMSET(b, -1, sizeof(b));
  78972. /* record layer */
  78973. /* handshake type */
  78974. b[idx++] = 22;
  78975. /* protocol version */
  78976. b[idx++] = 0xfe;
  78977. b[idx++] = 0xfd; /* DTLS 1.2 */
  78978. /* epoch 0 */
  78979. XMEMSET(b + idx, 0, 2);
  78980. idx += 2;
  78981. /* sequence number */
  78982. XMEMSET(b + idx, 0, 6);
  78983. seq_offset = idx + 2; /* increment only the low 32 bits */
  78984. idx += 6;
  78985. /* static length in BE */
  78986. c16toa(42, b + idx);
  78987. idx += 2;
  78988. /* handshake layer */
  78989. /* cert type */
  78990. b[idx++] = 11;
  78991. /* length */
  78992. c32to24(1000, b + idx);
  78993. idx += 3;
  78994. /* message seq */
  78995. c16toa(0, b + idx);
  78996. msg_offset = idx;
  78997. idx += 2;
  78998. /* frag offset */
  78999. c32to24(500, b + idx);
  79000. idx += 3;
  79001. /* frag length */
  79002. c32to24(30, b + idx);
  79003. idx += 3;
  79004. (void)idx; /* inhibit clang-analyzer-deadcode.DeadStores */
  79005. for (i = 0; i < DTLS_POOL_SZ * 2 && ret > 0;
  79006. seq_number++, msg_number++, i++) {
  79007. struct timespec delay;
  79008. XMEMSET(&delay, 0, sizeof(delay));
  79009. delay.tv_nsec = 10000000; /* wait 0.01 seconds */
  79010. c32toa(seq_number, b + seq_offset);
  79011. c16toa(msg_number, b + msg_offset);
  79012. ret = (int)send(fd, b, 55, 0);
  79013. nanosleep(&delay, NULL);
  79014. }
  79015. }
  79016. #ifdef WOLFSSL_DTLS13
  79017. static void test_wolfSSL_dtls13_fragments_spammer(WOLFSSL* ssl)
  79018. {
  79019. const word16 sendCountMax = 100;
  79020. byte b[150]; /* buffer for the messages to send */
  79021. size_t idx = 0;
  79022. size_t msg_offset = 0;
  79023. int fd = wolfSSL_get_fd(ssl);
  79024. word16 msg_number = 10; /* start high so server has to buffer this */
  79025. int ret = wolfSSL_connect_cert(ssl); /* This gets us past the cookie */
  79026. AssertIntEQ(ret, 1);
  79027. /* Now let's start spamming the peer with fragments it needs to store */
  79028. XMEMSET(b, -1, sizeof(b));
  79029. /* handshake type */
  79030. b[idx++] = 11;
  79031. /* length */
  79032. c32to24(10000, b + idx);
  79033. idx += 3;
  79034. /* message_seq */
  79035. msg_offset = idx;
  79036. idx += 2;
  79037. /* fragment_offset */
  79038. c32to24(5000, b + idx);
  79039. idx += 3;
  79040. /* fragment_length */
  79041. c32to24(100, b + idx);
  79042. idx += 3;
  79043. /* fragment contents */
  79044. idx += 100;
  79045. for (; ret > 0 && msg_number < sendCountMax; msg_number++) {
  79046. byte sendBuf[150];
  79047. int sendSz = sizeof(sendBuf);
  79048. struct timespec delay;
  79049. XMEMSET(&delay, 0, sizeof(delay));
  79050. delay.tv_nsec = 10000000; /* wait 0.01 seconds */
  79051. c16toa(msg_number, b + msg_offset);
  79052. sendSz = BuildTls13Message(ssl, sendBuf, sendSz, b,
  79053. (int)idx, handshake, 0, 0, 0);
  79054. ret = (int)send(fd, sendBuf, (size_t)sendSz, 0);
  79055. nanosleep(&delay, NULL);
  79056. }
  79057. }
  79058. #endif
  79059. static int test_wolfSSL_dtls_fragments(void)
  79060. {
  79061. EXPECT_DECLS;
  79062. callback_functions func_cb_client;
  79063. callback_functions func_cb_server;
  79064. size_t i;
  79065. struct test_params {
  79066. method_provider client_meth;
  79067. method_provider server_meth;
  79068. ssl_callback spammer;
  79069. } params[] = {
  79070. #if !defined(WOLFSSL_NO_TLS12)
  79071. {wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method,
  79072. test_wolfSSL_dtls12_fragments_spammer},
  79073. #endif
  79074. #ifdef WOLFSSL_DTLS13
  79075. {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method,
  79076. test_wolfSSL_dtls13_fragments_spammer},
  79077. #endif
  79078. };
  79079. for (i = 0; i < sizeof(params)/sizeof(*params); i++) {
  79080. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  79081. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  79082. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  79083. func_cb_server.method = params[i].server_meth;
  79084. func_cb_client.method = params[i].client_meth;
  79085. func_cb_client.ssl_ready = params[i].spammer;
  79086. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  79087. ExpectFalse(func_cb_client.return_code);
  79088. ExpectFalse(func_cb_server.return_code);
  79089. /* The socket should be closed by the server resulting in a
  79090. * socket error, fatal error or reading a close notify alert */
  79091. if (func_cb_client.last_err != WC_NO_ERR_TRACE(SOCKET_ERROR_E) &&
  79092. func_cb_client.last_err != WOLFSSL_ERROR_ZERO_RETURN &&
  79093. func_cb_client.last_err != WC_NO_ERR_TRACE(FATAL_ERROR)) {
  79094. ExpectIntEQ(func_cb_client.last_err, WC_NO_ERR_TRACE(SOCKET_ERROR_E));
  79095. }
  79096. /* Check the server returned an error indicating the msg buffer
  79097. * was full */
  79098. ExpectIntEQ(func_cb_server.last_err, WC_NO_ERR_TRACE(DTLS_TOO_MANY_FRAGMENTS_E));
  79099. if (EXPECT_FAIL())
  79100. break;
  79101. }
  79102. return EXPECT_RESULT();
  79103. }
  79104. static void test_wolfSSL_dtls_send_alert(WOLFSSL* ssl)
  79105. {
  79106. int fd, ret;
  79107. byte alert_msg[] = {
  79108. 0x15, /* alert type */
  79109. 0xfe, 0xfd, /* version */
  79110. 0x00, 0x00, /* epoch */
  79111. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, /* seq number */
  79112. 0x00, 0x02, /* length */
  79113. 0x02, /* level: fatal */
  79114. 0x46 /* protocol version */
  79115. };
  79116. fd = wolfSSL_get_fd(ssl);
  79117. ret = (int)send(fd, alert_msg, sizeof(alert_msg), 0);
  79118. AssertIntGT(ret, 0);
  79119. }
  79120. static int _test_wolfSSL_ignore_alert_before_cookie(byte version12)
  79121. {
  79122. callback_functions client_cbs, server_cbs;
  79123. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  79124. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  79125. client_cbs.doUdp = server_cbs.doUdp = 1;
  79126. if (version12) {
  79127. #if !defined(WOLFSSL_NO_TLS12)
  79128. client_cbs.method = wolfDTLSv1_2_client_method;
  79129. server_cbs.method = wolfDTLSv1_2_server_method;
  79130. #else
  79131. return TEST_SKIPPED;
  79132. #endif
  79133. }
  79134. else
  79135. {
  79136. #ifdef WOLFSSL_DTLS13
  79137. client_cbs.method = wolfDTLSv1_3_client_method;
  79138. server_cbs.method = wolfDTLSv1_3_server_method;
  79139. #else
  79140. return TEST_SKIPPED;
  79141. #endif /* WOLFSSL_DTLS13 */
  79142. }
  79143. client_cbs.ssl_ready = test_wolfSSL_dtls_send_alert;
  79144. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  79145. if (!client_cbs.return_code)
  79146. return TEST_FAIL;
  79147. if (!server_cbs.return_code)
  79148. return TEST_FAIL;
  79149. return TEST_SUCCESS;
  79150. }
  79151. static int test_wolfSSL_ignore_alert_before_cookie(void)
  79152. {
  79153. int ret;
  79154. ret =_test_wolfSSL_ignore_alert_before_cookie(0);
  79155. if (ret != 0)
  79156. return ret;
  79157. ret =_test_wolfSSL_ignore_alert_before_cookie(1);
  79158. if (ret != 0)
  79159. return ret;
  79160. return 0;
  79161. }
  79162. static void test_wolfSSL_send_bad_record(WOLFSSL* ssl)
  79163. {
  79164. int ret;
  79165. int fd;
  79166. byte bad_msg[] = {
  79167. 0x17, /* app data */
  79168. 0xaa, 0xfd, /* bad version */
  79169. 0x00, 0x01, /* epoch 1 */
  79170. 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, /* not seen seq number */
  79171. 0x00, 0x26, /* length: 38 bytes */
  79172. 0xae, 0x30, 0x31, 0xb1, 0xf1, 0xb9, 0x6f, 0xda, 0x17, 0x19, 0xd9, 0x57,
  79173. 0xa9, 0x9d, 0x5c, 0x51, 0x9b, 0x53, 0x63, 0xa5, 0x24, 0x70, 0xa1,
  79174. 0xae, 0xdf, 0x1c, 0xb9, 0xfc, 0xe3, 0xd7, 0x77, 0x6d, 0xb6, 0x89, 0x0f,
  79175. 0x03, 0x18, 0x72
  79176. };
  79177. fd = wolfSSL_get_fd(ssl);
  79178. AssertIntGE(fd, 0);
  79179. ret = (int)send(fd, bad_msg, sizeof(bad_msg), 0);
  79180. AssertIntEQ(ret, sizeof(bad_msg));
  79181. ret = wolfSSL_write(ssl, "badrecordtest", sizeof("badrecordtest"));
  79182. AssertIntEQ(ret, sizeof("badrecordtest"));
  79183. }
  79184. static void test_wolfSSL_read_string(WOLFSSL* ssl)
  79185. {
  79186. byte buf[100];
  79187. int ret;
  79188. ret = wolfSSL_read(ssl, buf, sizeof(buf));
  79189. AssertIntGT(ret, 0);
  79190. AssertIntEQ(strcmp((char*)buf, "badrecordtest"), 0);
  79191. }
  79192. static int _test_wolfSSL_dtls_bad_record(
  79193. method_provider client_method, method_provider server_method)
  79194. {
  79195. callback_functions client_cbs, server_cbs;
  79196. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  79197. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  79198. client_cbs.doUdp = server_cbs.doUdp = 1;
  79199. client_cbs.method = client_method;
  79200. server_cbs.method = server_method;
  79201. client_cbs.on_result = test_wolfSSL_send_bad_record;
  79202. server_cbs.on_result = test_wolfSSL_read_string;
  79203. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  79204. if (!client_cbs.return_code)
  79205. return TEST_FAIL;
  79206. if (!server_cbs.return_code)
  79207. return TEST_FAIL;
  79208. return TEST_SUCCESS;
  79209. }
  79210. static int test_wolfSSL_dtls_bad_record(void)
  79211. {
  79212. int ret = TEST_SUCCESS;
  79213. #if !defined(WOLFSSL_NO_TLS12)
  79214. ret = _test_wolfSSL_dtls_bad_record(wolfDTLSv1_2_client_method,
  79215. wolfDTLSv1_2_server_method);
  79216. #endif
  79217. #ifdef WOLFSSL_DTLS13
  79218. if (ret == TEST_SUCCESS) {
  79219. ret = _test_wolfSSL_dtls_bad_record(wolfDTLSv1_3_client_method,
  79220. wolfDTLSv1_3_server_method);
  79221. }
  79222. #endif /* WOLFSSL_DTLS13 */
  79223. return ret;
  79224. }
  79225. #else
  79226. static int test_wolfSSL_dtls_fragments(void) {
  79227. return TEST_SKIPPED;
  79228. }
  79229. static int test_wolfSSL_ignore_alert_before_cookie(void) {
  79230. return TEST_SKIPPED;
  79231. }
  79232. static int test_wolfSSL_dtls_bad_record(void) {
  79233. return TEST_SKIPPED;
  79234. }
  79235. #endif
  79236. #if defined(WOLFSSL_DTLS13) && !defined(WOLFSSL_TLS13_IGNORE_AEAD_LIMITS) && \
  79237. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  79238. defined(HAVE_IO_TESTS_DEPENDENCIES)
  79239. static byte test_AEAD_fail_decryption = 0;
  79240. static byte test_AEAD_seq_num = 0;
  79241. static byte test_AEAD_done = 0;
  79242. static int test_AEAD_cbiorecv(WOLFSSL *ssl, char *buf, int sz, void *ctx)
  79243. {
  79244. int ret = (int)recv(wolfSSL_get_fd(ssl), buf, sz, 0);
  79245. if (ret > 0) {
  79246. if (test_AEAD_fail_decryption) {
  79247. /* Modify the packet to trigger a decryption failure */
  79248. buf[ret/2] ^= 0xFF;
  79249. if (test_AEAD_fail_decryption == 1)
  79250. test_AEAD_fail_decryption = 0;
  79251. }
  79252. }
  79253. (void)ctx;
  79254. return ret;
  79255. }
  79256. static void test_AEAD_get_limits(WOLFSSL* ssl, w64wrapper* hardLimit,
  79257. w64wrapper* keyUpdateLimit, w64wrapper* sendLimit)
  79258. {
  79259. if (sendLimit)
  79260. w64Zero(sendLimit);
  79261. switch (ssl->specs.bulk_cipher_algorithm) {
  79262. case wolfssl_aes_gcm:
  79263. if (sendLimit)
  79264. *sendLimit = AEAD_AES_LIMIT;
  79265. FALL_THROUGH;
  79266. case wolfssl_chacha:
  79267. if (hardLimit)
  79268. *hardLimit = DTLS_AEAD_AES_GCM_CHACHA_FAIL_LIMIT;
  79269. if (keyUpdateLimit)
  79270. *keyUpdateLimit = DTLS_AEAD_AES_GCM_CHACHA_FAIL_KU_LIMIT;
  79271. break;
  79272. case wolfssl_aes_ccm:
  79273. if (sendLimit)
  79274. *sendLimit = DTLS_AEAD_AES_CCM_LIMIT;
  79275. if (ssl->specs.aead_mac_size == AES_CCM_8_AUTH_SZ) {
  79276. if (hardLimit)
  79277. *hardLimit = DTLS_AEAD_AES_CCM_8_FAIL_LIMIT;
  79278. if (keyUpdateLimit)
  79279. *keyUpdateLimit = DTLS_AEAD_AES_CCM_8_FAIL_KU_LIMIT;
  79280. }
  79281. else {
  79282. if (hardLimit)
  79283. *hardLimit = DTLS_AEAD_AES_CCM_FAIL_LIMIT;
  79284. if (keyUpdateLimit)
  79285. *keyUpdateLimit = DTLS_AEAD_AES_CCM_FAIL_KU_LIMIT;
  79286. }
  79287. break;
  79288. default:
  79289. fprintf(stderr, "Unrecognized bulk cipher");
  79290. AssertFalse(1);
  79291. break;
  79292. }
  79293. }
  79294. static void test_AEAD_limit_client(WOLFSSL* ssl)
  79295. {
  79296. int ret;
  79297. int i;
  79298. int didReKey = 0;
  79299. char msgBuf[20];
  79300. w64wrapper hardLimit;
  79301. w64wrapper keyUpdateLimit;
  79302. w64wrapper counter;
  79303. w64wrapper sendLimit;
  79304. test_AEAD_get_limits(ssl, &hardLimit, &keyUpdateLimit, &sendLimit);
  79305. w64Zero(&counter);
  79306. AssertTrue(w64Equal(Dtls13GetEpoch(ssl, ssl->dtls13Epoch)->dropCount, counter));
  79307. wolfSSL_SSLSetIORecv(ssl, test_AEAD_cbiorecv);
  79308. for (i = 0; i < 10; i++) {
  79309. /* Test some failed decryptions */
  79310. test_AEAD_fail_decryption = 1;
  79311. w64Increment(&counter);
  79312. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  79313. /* Should succeed since decryption failures are dropped */
  79314. AssertIntGT(ret, 0);
  79315. AssertTrue(w64Equal(Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount, counter));
  79316. }
  79317. test_AEAD_fail_decryption = 1;
  79318. Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount = keyUpdateLimit;
  79319. w64Increment(&Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount);
  79320. /* 100 read calls should be enough to complete the key update */
  79321. w64Zero(&counter);
  79322. for (i = 0; i < 100; i++) {
  79323. /* Key update should be sent and negotiated */
  79324. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  79325. AssertIntGT(ret, 0);
  79326. /* Epoch after one key update is 4 */
  79327. if (w64Equal(ssl->dtls13PeerEpoch, w64From32(0, 4)) &&
  79328. w64Equal(Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount, counter)) {
  79329. didReKey = 1;
  79330. break;
  79331. }
  79332. }
  79333. AssertTrue(didReKey);
  79334. if (!w64IsZero(sendLimit)) {
  79335. /* Test the sending limit for AEAD ciphers */
  79336. Dtls13GetEpoch(ssl, ssl->dtls13Epoch)->nextSeqNumber = sendLimit;
  79337. test_AEAD_seq_num = 1;
  79338. ret = wolfSSL_write(ssl, msgBuf, sizeof(msgBuf));
  79339. AssertIntGT(ret, 0);
  79340. didReKey = 0;
  79341. w64Zero(&counter);
  79342. /* 100 read calls should be enough to complete the key update */
  79343. for (i = 0; i < 100; i++) {
  79344. /* Key update should be sent and negotiated */
  79345. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  79346. AssertIntGT(ret, 0);
  79347. /* Epoch after another key update is 5 */
  79348. if (w64Equal(ssl->dtls13Epoch, w64From32(0, 5)) &&
  79349. w64Equal(Dtls13GetEpoch(ssl, ssl->dtls13Epoch)->dropCount, counter)) {
  79350. didReKey = 1;
  79351. break;
  79352. }
  79353. }
  79354. AssertTrue(didReKey);
  79355. }
  79356. test_AEAD_fail_decryption = 2;
  79357. Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount = hardLimit;
  79358. w64Decrement(&Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch)->dropCount);
  79359. /* Connection should fail with a DECRYPT_ERROR */
  79360. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  79361. AssertIntEQ(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  79362. AssertIntEQ(wolfSSL_get_error(ssl, ret), WC_NO_ERR_TRACE(DECRYPT_ERROR));
  79363. test_AEAD_done = 1;
  79364. }
  79365. int counter = 0;
  79366. static void test_AEAD_limit_server(WOLFSSL* ssl)
  79367. {
  79368. char msgBuf[] = "Sending data";
  79369. int ret = WOLFSSL_SUCCESS;
  79370. w64wrapper sendLimit;
  79371. SOCKET_T fd = wolfSSL_get_fd(ssl);
  79372. struct timespec delay;
  79373. XMEMSET(&delay, 0, sizeof(delay));
  79374. delay.tv_nsec = 100000000; /* wait 0.1 seconds */
  79375. tcp_set_nonblocking(&fd); /* So that read doesn't block */
  79376. wolfSSL_dtls_set_using_nonblock(ssl, 1);
  79377. test_AEAD_get_limits(ssl, NULL, NULL, &sendLimit);
  79378. while (!test_AEAD_done && ret > 0) {
  79379. counter++;
  79380. if (test_AEAD_seq_num) {
  79381. /* We need to update the seq number so that we can understand the
  79382. * peer. Otherwise we will incorrectly interpret the seq number. */
  79383. Dtls13Epoch* e = Dtls13GetEpoch(ssl, ssl->dtls13PeerEpoch);
  79384. AssertNotNull(e);
  79385. e->nextPeerSeqNumber = sendLimit;
  79386. test_AEAD_seq_num = 0;
  79387. }
  79388. (void)wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  79389. ret = wolfSSL_write(ssl, msgBuf, sizeof(msgBuf));
  79390. nanosleep(&delay, NULL);
  79391. }
  79392. }
  79393. static int test_wolfSSL_dtls_AEAD_limit(void)
  79394. {
  79395. callback_functions func_cb_client;
  79396. callback_functions func_cb_server;
  79397. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  79398. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  79399. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  79400. func_cb_server.method = wolfDTLSv1_3_server_method;
  79401. func_cb_client.method = wolfDTLSv1_3_client_method;
  79402. func_cb_server.on_result = test_AEAD_limit_server;
  79403. func_cb_client.on_result = test_AEAD_limit_client;
  79404. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  79405. if (!func_cb_client.return_code)
  79406. return TEST_FAIL;
  79407. if (!func_cb_server.return_code)
  79408. return TEST_FAIL;
  79409. return TEST_SUCCESS;
  79410. }
  79411. #else
  79412. static int test_wolfSSL_dtls_AEAD_limit(void)
  79413. {
  79414. return TEST_SKIPPED;
  79415. }
  79416. #endif
  79417. #if defined(WOLFSSL_DTLS) && \
  79418. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(SINGLE_THREADED) && \
  79419. !defined(DEBUG_VECTOR_REGISTER_ACCESS_FUZZING)
  79420. static void test_wolfSSL_dtls_send_ch(WOLFSSL* ssl)
  79421. {
  79422. int fd, ret;
  79423. byte ch_msg[] = {
  79424. 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  79425. 0xfa, 0x01, 0x00, 0x01, 0xee, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  79426. 0xee, 0xfe, 0xfd, 0xc0, 0xca, 0xb5, 0x6f, 0x3d, 0x23, 0xcc, 0x53, 0x9a,
  79427. 0x67, 0x17, 0x70, 0xd3, 0xfb, 0x23, 0x16, 0x9e, 0x4e, 0xd6, 0x7e, 0x29,
  79428. 0xab, 0xfa, 0x4c, 0xa5, 0x84, 0x95, 0xc3, 0xdb, 0x21, 0x9a, 0x52, 0x00,
  79429. 0x00, 0x00, 0x36, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0,
  79430. 0x2b, 0xc0, 0x30, 0xc0, 0x2f, 0x00, 0x9f, 0x00, 0x9e, 0xcc, 0xa9, 0xcc,
  79431. 0xa8, 0xcc, 0xaa, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x28, 0xc0, 0x24, 0xc0,
  79432. 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x6b, 0x00, 0x67, 0x00,
  79433. 0x39, 0x00, 0x33, 0xcc, 0x14, 0xcc, 0x13, 0xcc, 0x15, 0x01, 0x00, 0x01,
  79434. 0x8e, 0x00, 0x2b, 0x00, 0x03, 0x02, 0xfe, 0xfc, 0x00, 0x0d, 0x00, 0x20,
  79435. 0x00, 0x1e, 0x06, 0x03, 0x05, 0x03, 0x04, 0x03, 0x02, 0x03, 0x08, 0x06,
  79436. 0x08, 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08, 0x09, 0x06, 0x01,
  79437. 0x05, 0x01, 0x04, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, 0x0a, 0x00, 0x0c,
  79438. 0x00, 0x0a, 0x00, 0x19, 0x00, 0x18, 0x00, 0x17, 0x00, 0x15, 0x01, 0x00,
  79439. 0x00, 0x16, 0x00, 0x00, 0x00, 0x33, 0x01, 0x4b, 0x01, 0x49, 0x00, 0x17,
  79440. 0x00, 0x41, 0x04, 0x96, 0xcb, 0x2e, 0x4e, 0xd9, 0x88, 0x71, 0xc7, 0xf3,
  79441. 0x1a, 0x16, 0xdd, 0x7a, 0x7c, 0xf7, 0x67, 0x8a, 0x5d, 0x9a, 0x55, 0xa6,
  79442. 0x4a, 0x90, 0xd9, 0xfb, 0xc7, 0xfb, 0xbe, 0x09, 0xa9, 0x8a, 0xb5, 0x7a,
  79443. 0xd1, 0xde, 0x83, 0x74, 0x27, 0x31, 0x1c, 0xaa, 0xae, 0xef, 0x58, 0x43,
  79444. 0x13, 0x7d, 0x15, 0x4d, 0x7f, 0x68, 0xf6, 0x8a, 0x38, 0xef, 0x0e, 0xb3,
  79445. 0xcf, 0xb8, 0x4a, 0xa9, 0xb4, 0xd7, 0xcb, 0x01, 0x00, 0x01, 0x00, 0x1d,
  79446. 0x0a, 0x22, 0x8a, 0xd1, 0x78, 0x85, 0x1e, 0x5a, 0xe1, 0x1d, 0x1e, 0xb7,
  79447. 0x2d, 0xbc, 0x5f, 0x52, 0xbc, 0x97, 0x5d, 0x8b, 0x6a, 0x8b, 0x9d, 0x1e,
  79448. 0xb1, 0xfc, 0x8a, 0xb2, 0x56, 0xcd, 0xed, 0x4b, 0xfb, 0x66, 0x3f, 0x59,
  79449. 0x3f, 0x15, 0x5d, 0x09, 0x9e, 0x2f, 0x60, 0x5b, 0x31, 0x81, 0x27, 0xf0,
  79450. 0x1c, 0xda, 0xcd, 0x48, 0x66, 0xc6, 0xbb, 0x25, 0xf0, 0x5f, 0xda, 0x4c,
  79451. 0xcf, 0x1d, 0x88, 0xc8, 0xda, 0x1b, 0x53, 0xea, 0xbd, 0xce, 0x6d, 0xf6,
  79452. 0x4a, 0x76, 0xdb, 0x75, 0x99, 0xaf, 0xcf, 0x76, 0x4a, 0xfb, 0xe3, 0xef,
  79453. 0xb2, 0xcb, 0xae, 0x4a, 0xc0, 0xe8, 0x63, 0x1f, 0xd6, 0xe8, 0xe6, 0x45,
  79454. 0xf9, 0xea, 0x0d, 0x06, 0x19, 0xfc, 0xb1, 0xfd, 0x5d, 0x92, 0x89, 0x7b,
  79455. 0xc7, 0x9f, 0x1a, 0xb3, 0x2b, 0xc7, 0xad, 0x0e, 0xfb, 0x13, 0x41, 0x83,
  79456. 0x84, 0x58, 0x3a, 0x25, 0xb9, 0x49, 0x35, 0x1c, 0x23, 0xcb, 0xd6, 0xe7,
  79457. 0xc2, 0x8c, 0x4b, 0x2a, 0x73, 0xa1, 0xdf, 0x4f, 0x73, 0x9b, 0xb3, 0xd2,
  79458. 0xb2, 0x95, 0x00, 0x3c, 0x26, 0x09, 0x89, 0x71, 0x05, 0x39, 0xc8, 0x98,
  79459. 0x8f, 0xed, 0x32, 0x15, 0x78, 0xcd, 0xd3, 0x7e, 0xfb, 0x5a, 0x78, 0x2a,
  79460. 0xdc, 0xca, 0x20, 0x09, 0xb5, 0x14, 0xf9, 0xd4, 0x58, 0xf6, 0x69, 0xf8,
  79461. 0x65, 0x9f, 0xb7, 0xe4, 0x93, 0xf1, 0xa3, 0x84, 0x7e, 0x1b, 0x23, 0x5d,
  79462. 0xea, 0x59, 0x3e, 0x4d, 0xca, 0xfd, 0xa5, 0x55, 0xdd, 0x99, 0xb5, 0x02,
  79463. 0xf8, 0x0d, 0xe5, 0xf4, 0x06, 0xb0, 0x43, 0x9e, 0x2e, 0xbf, 0x05, 0x33,
  79464. 0x65, 0x7b, 0x13, 0x8c, 0xf9, 0x16, 0x4d, 0xc5, 0x15, 0x0b, 0x40, 0x2f,
  79465. 0x66, 0x94, 0xf2, 0x43, 0x95, 0xe7, 0xa9, 0xb6, 0x39, 0x99, 0x73, 0xb3,
  79466. 0xb0, 0x06, 0xfe, 0x52, 0x9e, 0x57, 0xba, 0x75, 0xfd, 0x76, 0x7b, 0x20,
  79467. 0x31, 0x68, 0x4c
  79468. };
  79469. fd = wolfSSL_get_fd(ssl);
  79470. ret = (int)send(fd, ch_msg, sizeof(ch_msg), 0);
  79471. AssertIntGT(ret, 0);
  79472. /* consume the HRR otherwise handshake will fail */
  79473. ret = (int)recv(fd, ch_msg, sizeof(ch_msg), 0);
  79474. AssertIntGT(ret, 0);
  79475. }
  79476. #if defined(WOLFSSL_DTLS13) && defined(WOLFSSL_SEND_HRR_COOKIE)
  79477. static void test_wolfSSL_dtls_send_ch_with_invalid_cookie(WOLFSSL* ssl)
  79478. {
  79479. int fd, ret;
  79480. byte ch_msh_invalid_cookie[] = {
  79481. 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02,
  79482. 0x4e, 0x01, 0x00, 0x02, 0x42, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02,
  79483. 0x42, 0xfe, 0xfd, 0x69, 0xca, 0x77, 0x60, 0x6f, 0xfc, 0xd1, 0x5b, 0x60,
  79484. 0x5d, 0xf1, 0xa6, 0x5c, 0x44, 0x71, 0xae, 0xca, 0x62, 0x19, 0x0c, 0xb6,
  79485. 0xf7, 0x2c, 0xa6, 0xd5, 0xd2, 0x99, 0x9d, 0x18, 0xae, 0xac, 0x11, 0x00,
  79486. 0x00, 0x00, 0x36, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0,
  79487. 0x2b, 0xc0, 0x30, 0xc0, 0x2f, 0x00, 0x9f, 0x00, 0x9e, 0xcc, 0xa9, 0xcc,
  79488. 0xa8, 0xcc, 0xaa, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x28, 0xc0, 0x24, 0xc0,
  79489. 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x6b, 0x00, 0x67, 0x00,
  79490. 0x39, 0x00, 0x33, 0xcc, 0x14, 0xcc, 0x13, 0xcc, 0x15, 0x01, 0x00, 0x01,
  79491. 0xe2, 0x00, 0x2b, 0x00, 0x03, 0x02, 0xfe, 0xfc, 0x00, 0x0d, 0x00, 0x20,
  79492. 0x00, 0x1e, 0x06, 0x03, 0x05, 0x03, 0x04, 0x03, 0x02, 0x03, 0x08, 0x06,
  79493. 0x08, 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08, 0x09, 0x06, 0x01,
  79494. 0x05, 0x01, 0x04, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, 0x2c, 0x00, 0x45,
  79495. 0x00, 0x43, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  79496. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  79497. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  79498. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  79499. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  79500. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x2d, 0x00,
  79501. 0x03, 0x02, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x0c, 0x00, 0x0a, 0x00, 0x19,
  79502. 0x00, 0x18, 0x00, 0x17, 0x00, 0x15, 0x01, 0x00, 0x00, 0x16, 0x00, 0x00,
  79503. 0x00, 0x33, 0x01, 0x4b, 0x01, 0x49, 0x00, 0x17, 0x00, 0x41, 0x04, 0x7c,
  79504. 0x5a, 0xc2, 0x5a, 0xfd, 0xcd, 0x2b, 0x08, 0xb2, 0xeb, 0x8e, 0xc0, 0x02,
  79505. 0x03, 0x9d, 0xb1, 0xc1, 0x0d, 0x7b, 0x7f, 0x46, 0x43, 0xdf, 0xf3, 0xee,
  79506. 0x2b, 0x78, 0x0e, 0x29, 0x8c, 0x42, 0x11, 0x2c, 0xde, 0xd7, 0x41, 0x0f,
  79507. 0x28, 0x94, 0x80, 0x41, 0x70, 0xc4, 0x17, 0xfd, 0x6d, 0xfa, 0xee, 0x9a,
  79508. 0xf2, 0xc4, 0x15, 0x4c, 0x5f, 0x54, 0xb6, 0x78, 0x6e, 0xf9, 0x63, 0x27,
  79509. 0x33, 0xb8, 0x7b, 0x01, 0x00, 0x01, 0x00, 0xd4, 0x46, 0x62, 0x9c, 0xbf,
  79510. 0x8f, 0x1b, 0x65, 0x9b, 0xf0, 0x29, 0x64, 0xd8, 0x50, 0x0e, 0x74, 0xf1,
  79511. 0x58, 0x10, 0xc9, 0xd9, 0x82, 0x5b, 0xd9, 0xbe, 0x14, 0xdf, 0xde, 0x86,
  79512. 0xb4, 0x2e, 0x15, 0xee, 0x4f, 0xf6, 0x74, 0x9e, 0x59, 0x11, 0x36, 0x2d,
  79513. 0xb9, 0x67, 0xaa, 0x5a, 0x09, 0x9b, 0x45, 0xf1, 0x01, 0x4c, 0x4e, 0xf6,
  79514. 0xda, 0x6a, 0xae, 0xa7, 0x73, 0x7b, 0x2e, 0xb6, 0x24, 0x89, 0x99, 0xb7,
  79515. 0x52, 0x16, 0x62, 0x0a, 0xab, 0x58, 0xf8, 0x3f, 0x10, 0x5b, 0x83, 0xfd,
  79516. 0x7b, 0x81, 0x77, 0x81, 0x8d, 0xef, 0x24, 0x56, 0x6d, 0xba, 0x49, 0xd4,
  79517. 0x8b, 0xb5, 0xa0, 0xb1, 0xc9, 0x8c, 0x32, 0x95, 0x1c, 0x5e, 0x0a, 0x4b,
  79518. 0xf6, 0x00, 0x50, 0x0a, 0x87, 0x99, 0x59, 0xcf, 0x6f, 0x9d, 0x02, 0xd0,
  79519. 0x1b, 0xa1, 0x96, 0x45, 0x28, 0x76, 0x40, 0x33, 0x28, 0xc9, 0xa1, 0xfd,
  79520. 0x46, 0xab, 0x2c, 0x9e, 0x5e, 0xc6, 0x74, 0x19, 0x9a, 0xf5, 0x9b, 0x51,
  79521. 0x11, 0x4f, 0xc8, 0xb9, 0x99, 0x6b, 0x4e, 0x3e, 0x31, 0x64, 0xb4, 0x92,
  79522. 0xf4, 0x0d, 0x41, 0x4b, 0x2c, 0x65, 0x23, 0xf7, 0x47, 0xe3, 0xa5, 0x2e,
  79523. 0xe4, 0x9c, 0x2b, 0xc9, 0x41, 0x22, 0x83, 0x8a, 0x23, 0xef, 0x29, 0x7e,
  79524. 0x4f, 0x3f, 0xa3, 0xbf, 0x73, 0x2b, 0xd7, 0xcc, 0xc8, 0xc6, 0xe9, 0xbc,
  79525. 0x01, 0xb7, 0x32, 0x63, 0xd4, 0x7e, 0x7f, 0x9a, 0xaf, 0x5f, 0x05, 0x31,
  79526. 0x53, 0xd6, 0x1f, 0xa2, 0xd0, 0xdf, 0x67, 0x56, 0xf1, 0x9c, 0x4a, 0x9d,
  79527. 0x83, 0xb4, 0xef, 0xb3, 0xf2, 0xcc, 0xf1, 0x91, 0x6c, 0x47, 0xc3, 0x8b,
  79528. 0xd0, 0x92, 0x79, 0x3d, 0xa0, 0xc0, 0x3a, 0x57, 0x26, 0x6d, 0x0a, 0xad,
  79529. 0x5f, 0xad, 0xb4, 0x74, 0x48, 0x4a, 0x51, 0xe1, 0xb5, 0x82, 0x0a, 0x4c,
  79530. 0x4f, 0x9d, 0xaf, 0xee, 0x5a, 0xa2, 0x4d, 0x4d, 0x5f, 0xe0, 0x17, 0x00,
  79531. 0x23, 0x00, 0x00
  79532. };
  79533. byte alert_reply[50];
  79534. byte expected_alert_reply[] = {
  79535. 0x15, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
  79536. 0x02, 0x02, 0x2f
  79537. };
  79538. fd = wolfSSL_get_fd(ssl);
  79539. ret = (int)send(fd, ch_msh_invalid_cookie, sizeof(ch_msh_invalid_cookie), 0);
  79540. AssertIntGT(ret, 0);
  79541. /* should reply with an illegal_parameter reply */
  79542. ret = (int)recv(fd, alert_reply, sizeof(alert_reply), 0);
  79543. AssertIntEQ(ret, sizeof(expected_alert_reply));
  79544. AssertIntEQ(XMEMCMP(alert_reply, expected_alert_reply, sizeof(expected_alert_reply)), 0);
  79545. }
  79546. #endif
  79547. static word32 test_wolfSSL_dtls_stateless_HashWOLFSSL(const WOLFSSL* ssl)
  79548. {
  79549. #ifndef NO_MD5
  79550. enum wc_HashType hashType = WC_HASH_TYPE_MD5;
  79551. #elif !defined(NO_SHA)
  79552. enum wc_HashType hashType = WC_HASH_TYPE_SHA;
  79553. #elif !defined(NO_SHA256)
  79554. enum wc_HashType hashType = WC_HASH_TYPE_SHA256;
  79555. #else
  79556. #error "We need a digest to hash the WOLFSSL object"
  79557. #endif
  79558. byte hashBuf[WC_MAX_DIGEST_SIZE];
  79559. wc_HashAlg hash;
  79560. const TLSX* exts = ssl->extensions;
  79561. WOLFSSL sslCopy; /* Use a copy to omit certain fields */
  79562. HS_Hashes* hsHashes = ssl->hsHashes; /* Is re-allocated in
  79563. * InitHandshakeHashes */
  79564. XMEMCPY(&sslCopy, ssl, sizeof(*ssl));
  79565. XMEMSET(hashBuf, 0, sizeof(hashBuf));
  79566. /* Following fields are not important to compare */
  79567. XMEMSET(sslCopy.buffers.inputBuffer.staticBuffer, 0, STATIC_BUFFER_LEN);
  79568. sslCopy.buffers.inputBuffer.buffer = NULL;
  79569. sslCopy.buffers.inputBuffer.bufferSize = 0;
  79570. sslCopy.buffers.inputBuffer.dynamicFlag = 0;
  79571. sslCopy.buffers.inputBuffer.offset = 0;
  79572. XMEMSET(sslCopy.buffers.outputBuffer.staticBuffer, 0, STATIC_BUFFER_LEN);
  79573. sslCopy.buffers.outputBuffer.buffer = NULL;
  79574. sslCopy.buffers.outputBuffer.bufferSize = 0;
  79575. sslCopy.buffers.outputBuffer.dynamicFlag = 0;
  79576. sslCopy.buffers.outputBuffer.offset = 0;
  79577. sslCopy.error = 0;
  79578. sslCopy.curSize = 0;
  79579. sslCopy.curStartIdx = 0;
  79580. sslCopy.keys.curSeq_lo = 0;
  79581. XMEMSET(&sslCopy.curRL, 0, sizeof(sslCopy.curRL));
  79582. #ifdef WOLFSSL_DTLS13
  79583. XMEMSET(&sslCopy.keys.curSeq, 0, sizeof(sslCopy.keys.curSeq));
  79584. sslCopy.dtls13FastTimeout = 0;
  79585. #endif
  79586. sslCopy.keys.dtls_peer_handshake_number = 0;
  79587. XMEMSET(&sslCopy.alert_history, 0, sizeof(sslCopy.alert_history));
  79588. sslCopy.hsHashes = NULL;
  79589. #ifdef WOLFSSL_ASYNC_IO
  79590. #ifdef WOLFSSL_ASYNC_CRYPT
  79591. sslCopy.asyncDev = NULL;
  79592. #endif
  79593. sslCopy.async = NULL;
  79594. #endif
  79595. AssertIntEQ(wc_HashInit(&hash, hashType), 0);
  79596. AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)&sslCopy, sizeof(sslCopy)), 0);
  79597. /* hash extension list */
  79598. while (exts != NULL) {
  79599. AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)exts, sizeof(*exts)), 0);
  79600. exts = exts->next;
  79601. }
  79602. /* Hash suites */
  79603. if (sslCopy.suites != NULL) {
  79604. AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)sslCopy.suites,
  79605. sizeof(struct Suites)), 0);
  79606. }
  79607. /* Hash hsHashes */
  79608. AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)hsHashes,
  79609. sizeof(*hsHashes)), 0);
  79610. AssertIntEQ(wc_HashFinal(&hash, hashType, hashBuf), 0);
  79611. AssertIntEQ(wc_HashFree(&hash, hashType), 0);
  79612. return MakeWordFromHash(hashBuf);
  79613. }
  79614. static CallbackIORecv test_wolfSSL_dtls_compare_stateless_cb;
  79615. static int test_wolfSSL_dtls_compare_stateless_cb_call_once;
  79616. static int test_wolfSSL_dtls_compare_stateless_read_cb_once(WOLFSSL *ssl,
  79617. char *buf, int sz, void *ctx)
  79618. {
  79619. if (test_wolfSSL_dtls_compare_stateless_cb_call_once) {
  79620. test_wolfSSL_dtls_compare_stateless_cb_call_once = 0;
  79621. return test_wolfSSL_dtls_compare_stateless_cb(ssl, buf, sz, ctx);
  79622. }
  79623. else {
  79624. return WOLFSSL_CBIO_ERR_WANT_READ;
  79625. }
  79626. }
  79627. static void test_wolfSSL_dtls_compare_stateless(WOLFSSL* ssl)
  79628. {
  79629. /* Compare the ssl object before and after one ClientHello msg */
  79630. SOCKET_T fd = wolfSSL_get_fd(ssl);
  79631. int res;
  79632. int err;
  79633. word32 initHash;
  79634. test_wolfSSL_dtls_compare_stateless_cb = ssl->CBIORecv;
  79635. test_wolfSSL_dtls_compare_stateless_cb_call_once = 1;
  79636. wolfSSL_dtls_set_using_nonblock(ssl, 1);
  79637. ssl->CBIORecv = test_wolfSSL_dtls_compare_stateless_read_cb_once;
  79638. initHash = test_wolfSSL_dtls_stateless_HashWOLFSSL(ssl);
  79639. (void)initHash;
  79640. res = tcp_select(fd, 5);
  79641. /* We are expecting a msg. A timeout indicates failure. */
  79642. AssertIntEQ(res, TEST_RECV_READY);
  79643. res = wolfSSL_accept(ssl);
  79644. err = wolfSSL_get_error(ssl, res);
  79645. AssertIntEQ(res, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  79646. AssertIntEQ(err, WOLFSSL_ERROR_WANT_READ);
  79647. AssertIntEQ(initHash, test_wolfSSL_dtls_stateless_HashWOLFSSL(ssl));
  79648. wolfSSL_dtls_set_using_nonblock(ssl, 0);
  79649. ssl->CBIORecv = test_wolfSSL_dtls_compare_stateless_cb;
  79650. }
  79651. #if defined(WOLFSSL_DTLS13) && defined(WOLFSSL_SEND_HRR_COOKIE)
  79652. static void test_wolfSSL_dtls_enable_hrrcookie(WOLFSSL* ssl)
  79653. {
  79654. int ret;
  79655. ret = wolfSSL_send_hrr_cookie(ssl, NULL, 0);
  79656. AssertIntEQ(ret, WOLFSSL_SUCCESS);
  79657. test_wolfSSL_dtls_compare_stateless(ssl);
  79658. }
  79659. #endif
  79660. static int test_wolfSSL_dtls_stateless(void)
  79661. {
  79662. callback_functions client_cbs, server_cbs;
  79663. size_t i;
  79664. struct {
  79665. method_provider client_meth;
  79666. method_provider server_meth;
  79667. ssl_callback client_ssl_ready;
  79668. ssl_callback server_ssl_ready;
  79669. } test_params[] = {
  79670. #if !defined(WOLFSSL_NO_TLS12)
  79671. {wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method,
  79672. test_wolfSSL_dtls_send_ch, test_wolfSSL_dtls_compare_stateless},
  79673. #endif
  79674. #if defined(WOLFSSL_DTLS13) && defined(WOLFSSL_SEND_HRR_COOKIE)
  79675. {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method,
  79676. test_wolfSSL_dtls_send_ch, test_wolfSSL_dtls_enable_hrrcookie},
  79677. {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method,
  79678. test_wolfSSL_dtls_send_ch_with_invalid_cookie, test_wolfSSL_dtls_enable_hrrcookie},
  79679. #endif
  79680. };
  79681. if (0 == sizeof(test_params)){
  79682. return TEST_SKIPPED;
  79683. }
  79684. for (i = 0; i < sizeof(test_params)/sizeof(*test_params); i++) {
  79685. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  79686. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  79687. client_cbs.doUdp = server_cbs.doUdp = 1;
  79688. client_cbs.method = test_params[i].client_meth;
  79689. server_cbs.method = test_params[i].server_meth;
  79690. client_cbs.ssl_ready = test_params[i].client_ssl_ready;
  79691. server_cbs.ssl_ready = test_params[i].server_ssl_ready;
  79692. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  79693. if (!client_cbs.return_code)
  79694. return TEST_FAIL;
  79695. if (!server_cbs.return_code)
  79696. return TEST_FAIL;
  79697. }
  79698. return TEST_SUCCESS;
  79699. }
  79700. #else
  79701. static int test_wolfSSL_dtls_stateless(void)
  79702. {
  79703. return TEST_SKIPPED;
  79704. }
  79705. #endif /* WOLFSSL_DTLS13 && WOLFSSL_SEND_HRR_COOKIE &&
  79706. * HAVE_IO_TESTS_DEPENDENCIES && !SINGLE_THREADED */
  79707. #ifdef HAVE_CERT_CHAIN_VALIDATION
  79708. static int load_ca_into_cm(WOLFSSL_CERT_MANAGER* cm, char* certA)
  79709. {
  79710. int ret;
  79711. if ((ret = wolfSSL_CertManagerLoadCA(cm, certA, 0)) != WOLFSSL_SUCCESS) {
  79712. fprintf(stderr, "loading cert %s failed\n", certA);
  79713. fprintf(stderr, "Error: (%d): %s\n", ret,
  79714. wolfSSL_ERR_reason_error_string((word32)ret));
  79715. return -1;
  79716. }
  79717. return 0;
  79718. }
  79719. static int verify_cert_with_cm(WOLFSSL_CERT_MANAGER* cm, char* certA)
  79720. {
  79721. int ret;
  79722. if ((ret = wolfSSL_CertManagerVerify(cm, certA, WOLFSSL_FILETYPE_PEM))
  79723. != WOLFSSL_SUCCESS) {
  79724. fprintf(stderr, "could not verify the cert: %s\n", certA);
  79725. fprintf(stderr, "Error: (%d): %s\n", ret,
  79726. wolfSSL_ERR_reason_error_string((word32)ret));
  79727. return -1;
  79728. }
  79729. else {
  79730. fprintf(stderr, "successfully verified: %s\n", certA);
  79731. }
  79732. return 0;
  79733. }
  79734. #define LOAD_ONE_CA(a, b, c, d) \
  79735. do { \
  79736. (a) = load_ca_into_cm(c, d); \
  79737. if ((a) != 0) \
  79738. return (b); \
  79739. else \
  79740. (b)--; \
  79741. } while(0)
  79742. #define VERIFY_ONE_CERT(a, b, c, d) \
  79743. do { \
  79744. (a) = verify_cert_with_cm(c, d);\
  79745. if ((a) != 0) \
  79746. return (b); \
  79747. else \
  79748. (b)--; \
  79749. } while(0)
  79750. static int test_chainG(WOLFSSL_CERT_MANAGER* cm)
  79751. {
  79752. int ret;
  79753. int i = -1;
  79754. /* Chain G is a valid chain per RFC 5280 section 4.2.1.9 */
  79755. char chainGArr[9][50] = {"certs/ca-cert.pem",
  79756. "certs/test-pathlen/chainG-ICA7-pathlen100.pem",
  79757. "certs/test-pathlen/chainG-ICA6-pathlen10.pem",
  79758. "certs/test-pathlen/chainG-ICA5-pathlen20.pem",
  79759. "certs/test-pathlen/chainG-ICA4-pathlen5.pem",
  79760. "certs/test-pathlen/chainG-ICA3-pathlen99.pem",
  79761. "certs/test-pathlen/chainG-ICA2-pathlen1.pem",
  79762. "certs/test-pathlen/chainG-ICA1-pathlen0.pem",
  79763. "certs/test-pathlen/chainG-entity.pem"};
  79764. LOAD_ONE_CA(ret, i, cm, chainGArr[0]); /* if failure, i = -1 here */
  79765. LOAD_ONE_CA(ret, i, cm, chainGArr[1]); /* if failure, i = -2 here */
  79766. LOAD_ONE_CA(ret, i, cm, chainGArr[2]); /* if failure, i = -3 here */
  79767. LOAD_ONE_CA(ret, i, cm, chainGArr[3]); /* if failure, i = -4 here */
  79768. LOAD_ONE_CA(ret, i, cm, chainGArr[4]); /* if failure, i = -5 here */
  79769. LOAD_ONE_CA(ret, i, cm, chainGArr[5]); /* if failure, i = -6 here */
  79770. LOAD_ONE_CA(ret, i, cm, chainGArr[6]); /* if failure, i = -7 here */
  79771. LOAD_ONE_CA(ret, i, cm, chainGArr[7]); /* if failure, i = -8 here */
  79772. VERIFY_ONE_CERT(ret, i, cm, chainGArr[1]); /* if failure, i = -9 here */
  79773. VERIFY_ONE_CERT(ret, i, cm, chainGArr[2]); /* if failure, i = -10 here */
  79774. VERIFY_ONE_CERT(ret, i, cm, chainGArr[3]); /* if failure, i = -11 here */
  79775. VERIFY_ONE_CERT(ret, i, cm, chainGArr[4]); /* if failure, i = -12 here */
  79776. VERIFY_ONE_CERT(ret, i, cm, chainGArr[5]); /* if failure, i = -13 here */
  79777. VERIFY_ONE_CERT(ret, i, cm, chainGArr[6]); /* if failure, i = -14 here */
  79778. VERIFY_ONE_CERT(ret, i, cm, chainGArr[7]); /* if failure, i = -15 here */
  79779. VERIFY_ONE_CERT(ret, i, cm, chainGArr[8]); /* if failure, i = -16 here */
  79780. /* test validating the entity twice, should have no effect on pathLen since
  79781. * entity/leaf cert */
  79782. VERIFY_ONE_CERT(ret, i, cm, chainGArr[8]); /* if failure, i = -17 here */
  79783. return ret;
  79784. }
  79785. static int test_chainH(WOLFSSL_CERT_MANAGER* cm)
  79786. {
  79787. int ret;
  79788. int i = -1;
  79789. /* Chain H is NOT a valid chain per RFC5280 section 4.2.1.9:
  79790. * ICA4-pathlen of 2 signing ICA3-pathlen of 2 (reduce max path len to 2)
  79791. * ICA3-pathlen of 2 signing ICA2-pathlen of 2 (reduce max path len to 1)
  79792. * ICA2-pathlen of 2 signing ICA1-pathlen of 0 (reduce max path len to 0)
  79793. * ICA1-pathlen of 0 signing entity (pathlen is already 0, ERROR)
  79794. * Test should successfully verify ICA4, ICA3, ICA2 and then fail on ICA1
  79795. */
  79796. char chainHArr[6][50] = {"certs/ca-cert.pem",
  79797. "certs/test-pathlen/chainH-ICA4-pathlen2.pem",
  79798. "certs/test-pathlen/chainH-ICA3-pathlen2.pem",
  79799. "certs/test-pathlen/chainH-ICA2-pathlen2.pem",
  79800. "certs/test-pathlen/chainH-ICA1-pathlen0.pem",
  79801. "certs/test-pathlen/chainH-entity.pem"};
  79802. LOAD_ONE_CA(ret, i, cm, chainHArr[0]); /* if failure, i = -1 here */
  79803. LOAD_ONE_CA(ret, i, cm, chainHArr[1]); /* if failure, i = -2 here */
  79804. LOAD_ONE_CA(ret, i, cm, chainHArr[2]); /* if failure, i = -3 here */
  79805. LOAD_ONE_CA(ret, i, cm, chainHArr[3]); /* if failure, i = -4 here */
  79806. LOAD_ONE_CA(ret, i, cm, chainHArr[4]); /* if failure, i = -5 here */
  79807. VERIFY_ONE_CERT(ret, i, cm, chainHArr[1]); /* if failure, i = -6 here */
  79808. VERIFY_ONE_CERT(ret, i, cm, chainHArr[2]); /* if failure, i = -7 here */
  79809. VERIFY_ONE_CERT(ret, i, cm, chainHArr[3]); /* if failure, i = -8 here */
  79810. VERIFY_ONE_CERT(ret, i, cm, chainHArr[4]); /* if failure, i = -9 here */
  79811. VERIFY_ONE_CERT(ret, i, cm, chainHArr[5]); /* if failure, i = -10 here */
  79812. return ret;
  79813. }
  79814. static int test_chainI(WOLFSSL_CERT_MANAGER* cm)
  79815. {
  79816. int ret;
  79817. int i = -1;
  79818. /* Chain I is a valid chain per RFC5280 section 4.2.1.9:
  79819. * ICA3-pathlen of 2 signing ICA2 without a pathlen (reduce maxPathLen to 2)
  79820. * ICA2-no_pathlen signing ICA1-no_pathlen (reduce maxPathLen to 1)
  79821. * ICA1-no_pathlen signing entity (reduce maxPathLen to 0)
  79822. * Test should successfully verify ICA4, ICA3, ICA2 and then fail on ICA1
  79823. */
  79824. char chainIArr[5][50] = {"certs/ca-cert.pem",
  79825. "certs/test-pathlen/chainI-ICA3-pathlen2.pem",
  79826. "certs/test-pathlen/chainI-ICA2-no_pathlen.pem",
  79827. "certs/test-pathlen/chainI-ICA1-no_pathlen.pem",
  79828. "certs/test-pathlen/chainI-entity.pem"};
  79829. LOAD_ONE_CA(ret, i, cm, chainIArr[0]); /* if failure, i = -1 here */
  79830. LOAD_ONE_CA(ret, i, cm, chainIArr[1]); /* if failure, i = -2 here */
  79831. LOAD_ONE_CA(ret, i, cm, chainIArr[2]); /* if failure, i = -3 here */
  79832. LOAD_ONE_CA(ret, i, cm, chainIArr[3]); /* if failure, i = -4 here */
  79833. VERIFY_ONE_CERT(ret, i, cm, chainIArr[1]); /* if failure, i = -5 here */
  79834. VERIFY_ONE_CERT(ret, i, cm, chainIArr[2]); /* if failure, i = -6 here */
  79835. VERIFY_ONE_CERT(ret, i, cm, chainIArr[3]); /* if failure, i = -7 here */
  79836. VERIFY_ONE_CERT(ret, i, cm, chainIArr[4]); /* if failure, i = -8 here */
  79837. return ret;
  79838. }
  79839. static int test_chainJ(WOLFSSL_CERT_MANAGER* cm)
  79840. {
  79841. int ret;
  79842. int i = -1;
  79843. /* Chain J is NOT a valid chain per RFC5280 section 4.2.1.9:
  79844. * ICA4-pathlen of 2 signing ICA3 without a pathlen (reduce maxPathLen to 2)
  79845. * ICA3-pathlen of 2 signing ICA2 without a pathlen (reduce maxPathLen to 1)
  79846. * ICA2-no_pathlen signing ICA1-no_pathlen (reduce maxPathLen to 0)
  79847. * ICA1-no_pathlen signing entity (ERROR, pathlen zero and non-leaf cert)
  79848. */
  79849. char chainJArr[6][50] = {"certs/ca-cert.pem",
  79850. "certs/test-pathlen/chainJ-ICA4-pathlen2.pem",
  79851. "certs/test-pathlen/chainJ-ICA3-no_pathlen.pem",
  79852. "certs/test-pathlen/chainJ-ICA2-no_pathlen.pem",
  79853. "certs/test-pathlen/chainJ-ICA1-no_pathlen.pem",
  79854. "certs/test-pathlen/chainJ-entity.pem"};
  79855. LOAD_ONE_CA(ret, i, cm, chainJArr[0]); /* if failure, i = -1 here */
  79856. LOAD_ONE_CA(ret, i, cm, chainJArr[1]); /* if failure, i = -2 here */
  79857. LOAD_ONE_CA(ret, i, cm, chainJArr[2]); /* if failure, i = -3 here */
  79858. LOAD_ONE_CA(ret, i, cm, chainJArr[3]); /* if failure, i = -4 here */
  79859. LOAD_ONE_CA(ret, i, cm, chainJArr[4]); /* if failure, i = -5 here */
  79860. VERIFY_ONE_CERT(ret, i, cm, chainJArr[1]); /* if failure, i = -6 here */
  79861. VERIFY_ONE_CERT(ret, i, cm, chainJArr[2]); /* if failure, i = -7 here */
  79862. VERIFY_ONE_CERT(ret, i, cm, chainJArr[3]); /* if failure, i = -8 here */
  79863. VERIFY_ONE_CERT(ret, i, cm, chainJArr[4]); /* if failure, i = -9 here */
  79864. VERIFY_ONE_CERT(ret, i, cm, chainJArr[5]); /* if failure, i = -10 here */
  79865. return ret;
  79866. }
  79867. static int test_various_pathlen_chains(void)
  79868. {
  79869. EXPECT_DECLS;
  79870. WOLFSSL_CERT_MANAGER* cm = NULL;
  79871. /* Test chain G (large chain with varying pathLens) */
  79872. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  79873. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  79874. ExpectIntEQ(test_chainG(cm), -1);
  79875. #else
  79876. ExpectIntEQ(test_chainG(cm), 0);
  79877. #endif /* NO_WOLFSSL_CLIENT && NO_WOLFSSL_SERVER */
  79878. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  79879. wolfSSL_CertManagerFree(cm);
  79880. /* end test chain G */
  79881. /* Test chain H (5 chain with same pathLens) */
  79882. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  79883. ExpectIntLT(test_chainH(cm), 0);
  79884. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  79885. wolfSSL_CertManagerFree(cm);
  79886. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  79887. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  79888. wolfSSL_CertManagerFree(cm);
  79889. /* end test chain H */
  79890. /* Test chain I (only first ICA has pathLen set and it's set to 2,
  79891. * followed by 2 ICA's, should pass) */
  79892. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  79893. #if defined(NO_WOLFSSL_CLIENT) && defined(NO_WOLFSSL_SERVER)
  79894. ExpectIntEQ(test_chainI(cm), -1);
  79895. #else
  79896. ExpectIntEQ(test_chainI(cm), 0);
  79897. #endif /* NO_WOLFSSL_CLIENT && NO_WOLFSSL_SERVER */
  79898. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  79899. wolfSSL_CertManagerFree(cm);
  79900. cm = NULL;
  79901. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  79902. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  79903. wolfSSL_CertManagerFree(cm);
  79904. cm = NULL;
  79905. /* Test chain J (Again only first ICA has pathLen set and it's set to 2,
  79906. * this time followed by 3 ICA's, should fail */
  79907. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  79908. ExpectIntLT(test_chainJ(cm), 0);
  79909. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  79910. wolfSSL_CertManagerFree(cm);
  79911. cm = NULL;
  79912. ExpectNotNull(cm = wolfSSL_CertManagerNew());
  79913. ExpectIntEQ(wolfSSL_CertManagerUnloadCAs(cm), WOLFSSL_SUCCESS);
  79914. wolfSSL_CertManagerFree(cm);
  79915. return EXPECT_RESULT();
  79916. }
  79917. #endif /* !NO_RSA && !NO_SHA && !NO_FILESYSTEM && !NO_CERTS */
  79918. #if defined(HAVE_KEYING_MATERIAL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  79919. static int test_export_keying_material_cb(WOLFSSL_CTX *ctx, WOLFSSL *ssl)
  79920. {
  79921. EXPECT_DECLS;
  79922. byte ekm[100] = {0};
  79923. (void)ctx;
  79924. /* Success Cases */
  79925. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  79926. "Test label", XSTR_SIZEOF("Test label"), NULL, 0, 0), 1);
  79927. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  79928. "Test label", XSTR_SIZEOF("Test label"), NULL, 0, 1), 1);
  79929. /* Use some random context */
  79930. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  79931. "Test label", XSTR_SIZEOF("Test label"), ekm, 10, 1), 1);
  79932. /* Failure cases */
  79933. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  79934. "client finished", XSTR_SIZEOF("client finished"), NULL, 0, 0), 0);
  79935. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  79936. "server finished", XSTR_SIZEOF("server finished"), NULL, 0, 0), 0);
  79937. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  79938. "master secret", XSTR_SIZEOF("master secret"), NULL, 0, 0), 0);
  79939. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  79940. "extended master secret", XSTR_SIZEOF("extended master secret"),
  79941. NULL, 0, 0), 0);
  79942. ExpectIntEQ(wolfSSL_export_keying_material(ssl, ekm, sizeof(ekm),
  79943. "key expansion", XSTR_SIZEOF("key expansion"), NULL, 0, 0), 0);
  79944. return EXPECT_RESULT();
  79945. }
  79946. static int test_export_keying_material_ssl_cb(WOLFSSL* ssl)
  79947. {
  79948. wolfSSL_KeepArrays(ssl);
  79949. return TEST_SUCCESS;
  79950. }
  79951. static int test_export_keying_material(void)
  79952. {
  79953. EXPECT_DECLS;
  79954. test_ssl_cbf serverCb;
  79955. test_ssl_cbf clientCb;
  79956. XMEMSET(&serverCb, 0, sizeof(serverCb));
  79957. XMEMSET(&clientCb, 0, sizeof(clientCb));
  79958. clientCb.ssl_ready = test_export_keying_material_ssl_cb;
  79959. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&clientCb,
  79960. &serverCb, test_export_keying_material_cb), TEST_SUCCESS);
  79961. return EXPECT_RESULT();
  79962. }
  79963. #endif /* HAVE_KEYING_MATERIAL */
  79964. static int test_wolfSSL_THREADID_hash(void)
  79965. {
  79966. EXPECT_DECLS;
  79967. #if defined(OPENSSL_EXTRA)
  79968. CRYPTO_THREADID id;
  79969. CRYPTO_THREADID_current(NULL);
  79970. /* Hash result is word32. */
  79971. ExpectTrue(CRYPTO_THREADID_hash(NULL) == 0UL);
  79972. XMEMSET(&id, 0, sizeof(id));
  79973. ExpectTrue(CRYPTO_THREADID_hash(&id) == 0UL);
  79974. #endif /* OPENSSL_EXTRA */
  79975. return EXPECT_RESULT();
  79976. }
  79977. static int test_wolfSSL_set_ecdh_auto(void)
  79978. {
  79979. EXPECT_DECLS;
  79980. #if defined(OPENSSL_EXTRA)
  79981. WOLFSSL* ssl = NULL;
  79982. ExpectIntEQ(SSL_set_ecdh_auto(NULL,0), 1);
  79983. ExpectIntEQ(SSL_set_ecdh_auto(NULL,1), 1);
  79984. ExpectIntEQ(SSL_set_ecdh_auto(ssl,0), 1);
  79985. ExpectIntEQ(SSL_set_ecdh_auto(ssl,1), 1);
  79986. #endif /* OPENSSL_EXTRA */
  79987. return EXPECT_RESULT();
  79988. }
  79989. static int test_wolfSSL_CTX_set_ecdh_auto(void)
  79990. {
  79991. EXPECT_DECLS;
  79992. #if defined(OPENSSL_EXTRA)
  79993. WOLFSSL_CTX* ctx = NULL;
  79994. ExpectIntEQ(SSL_CTX_set_ecdh_auto(NULL,0), 1);
  79995. ExpectIntEQ(SSL_CTX_set_ecdh_auto(NULL,1), 1);
  79996. ExpectIntEQ(SSL_CTX_set_ecdh_auto(ctx,0), 1);
  79997. ExpectIntEQ(SSL_CTX_set_ecdh_auto(ctx,1), 1);
  79998. #endif /* OPENSSL_EXTRA */
  79999. return EXPECT_RESULT();
  80000. }
  80001. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_ERROR_CODE_OPENSSL) && \
  80002. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  80003. static THREAD_RETURN WOLFSSL_THREAD SSL_read_test_server_thread(void* args)
  80004. {
  80005. EXPECT_DECLS;
  80006. callback_functions* callbacks = NULL;
  80007. WOLFSSL_CTX* ctx = NULL;
  80008. WOLFSSL* ssl = NULL;
  80009. SOCKET_T sfd = 0;
  80010. SOCKET_T cfd = 0;
  80011. word16 port;
  80012. char msg[] = "I hear you fa shizzle!";
  80013. int len = (int) XSTRLEN(msg);
  80014. char input[1024];
  80015. int ret = 0;
  80016. int err = 0;
  80017. if (!args)
  80018. WOLFSSL_RETURN_FROM_THREAD(0);
  80019. ((func_args*)args)->return_code = TEST_FAIL;
  80020. callbacks = ((func_args*)args)->callbacks;
  80021. ctx = wolfSSL_CTX_new(callbacks->method());
  80022. #if defined(USE_WINDOWS_API)
  80023. port = ((func_args*)args)->signal->port;
  80024. #else
  80025. /* Let tcp_listen assign port */
  80026. port = 0;
  80027. #endif
  80028. #ifdef WOLFSSL_TIRTOS
  80029. fdOpenSession(Task_self());
  80030. #endif
  80031. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_load_verify_locations(ctx,
  80032. caCertFile, 0));
  80033. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_certificate_file(ctx,
  80034. svrCertFile, WOLFSSL_FILETYPE_PEM));
  80035. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_PrivateKey_file(ctx,
  80036. svrKeyFile, WOLFSSL_FILETYPE_PEM));
  80037. #if !defined(NO_FILESYSTEM) && !defined(NO_DH)
  80038. ExpectIntEQ(wolfSSL_CTX_SetTmpDH_file(ctx, dhParamFile,
  80039. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  80040. #elif !defined(NO_DH)
  80041. SetDHCtx(ctx); /* will repick suites with DHE, higher priority than PSK */
  80042. #endif
  80043. if (callbacks->ctx_ready)
  80044. callbacks->ctx_ready(ctx);
  80045. ssl = wolfSSL_new(ctx);
  80046. ExpectNotNull(ssl);
  80047. /* listen and accept */
  80048. tcp_accept(&sfd, &cfd, (func_args*)args, port, 0, 0, 0, 0, 1, 0, 0);
  80049. CloseSocket(sfd);
  80050. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_set_fd(ssl, cfd));
  80051. if (callbacks->ssl_ready)
  80052. callbacks->ssl_ready(ssl);
  80053. if (EXPECT_SUCCESS()) {
  80054. do {
  80055. err = 0; /* Reset error */
  80056. ret = wolfSSL_accept(ssl);
  80057. if (ret != WOLFSSL_SUCCESS) {
  80058. err = wolfSSL_get_error(ssl, 0);
  80059. }
  80060. } while (ret != WOLFSSL_SUCCESS && err == WC_NO_ERR_TRACE(WC_PENDING_E));
  80061. }
  80062. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  80063. /* read and write data */
  80064. XMEMSET(input, 0, sizeof(input));
  80065. while (EXPECT_SUCCESS()) {
  80066. ret = wolfSSL_read(ssl, input, sizeof(input));
  80067. if (ret > 0) {
  80068. break;
  80069. }
  80070. else {
  80071. err = wolfSSL_get_error(ssl,ret);
  80072. if (err == WOLFSSL_ERROR_WANT_READ) {
  80073. continue;
  80074. }
  80075. break;
  80076. }
  80077. }
  80078. if (EXPECT_SUCCESS() && (err == WOLFSSL_ERROR_ZERO_RETURN)) {
  80079. do {
  80080. ret = wolfSSL_write(ssl, msg, len);
  80081. if (ret > 0) {
  80082. break;
  80083. }
  80084. } while (ret < 0);
  80085. }
  80086. /* bidirectional shutdown */
  80087. while (EXPECT_SUCCESS()) {
  80088. ret = wolfSSL_shutdown(ssl);
  80089. ExpectIntNE(ret, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  80090. if (ret == WOLFSSL_SUCCESS) {
  80091. break;
  80092. }
  80093. }
  80094. if (EXPECT_SUCCESS()) {
  80095. /* wait for the peer to disconnect the tcp connection */
  80096. do {
  80097. ret = wolfSSL_read(ssl, input, sizeof(input));
  80098. err = wolfSSL_get_error(ssl, ret);
  80099. } while (ret > 0 || err != WOLFSSL_ERROR_ZERO_RETURN);
  80100. }
  80101. /* detect TCP disconnect */
  80102. ExpectIntLE(ret,WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80103. ExpectIntEQ(wolfSSL_get_error(ssl, ret), WOLFSSL_ERROR_ZERO_RETURN);
  80104. ((func_args*)args)->return_code = EXPECT_RESULT();
  80105. wolfSSL_free(ssl);
  80106. wolfSSL_CTX_free(ctx);
  80107. CloseSocket(cfd);
  80108. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
  80109. wc_ecc_fp_free(); /* free per thread cache */
  80110. #endif
  80111. WOLFSSL_RETURN_FROM_THREAD(0);
  80112. }
  80113. static THREAD_RETURN WOLFSSL_THREAD SSL_read_test_client_thread(void* args)
  80114. {
  80115. EXPECT_DECLS;
  80116. callback_functions* callbacks = NULL;
  80117. WOLFSSL_CTX* ctx = NULL;
  80118. WOLFSSL* ssl = NULL;
  80119. SOCKET_T sfd = 0;
  80120. char msg[] = "hello wolfssl server!";
  80121. int len = (int) XSTRLEN(msg);
  80122. char input[1024];
  80123. int idx;
  80124. int ret, err;
  80125. if (!args)
  80126. WOLFSSL_RETURN_FROM_THREAD(0);
  80127. ((func_args*)args)->return_code = TEST_FAIL;
  80128. callbacks = ((func_args*)args)->callbacks;
  80129. ctx = wolfSSL_CTX_new(callbacks->method());
  80130. #ifdef WOLFSSL_TIRTOS
  80131. fdOpenSession(Task_self());
  80132. #endif
  80133. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_load_verify_locations(ctx,
  80134. caCertFile, 0));
  80135. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_certificate_file(ctx,
  80136. cliCertFile, WOLFSSL_FILETYPE_PEM));
  80137. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_use_PrivateKey_file(ctx,
  80138. cliKeyFile, WOLFSSL_FILETYPE_PEM));
  80139. ExpectNotNull((ssl = wolfSSL_new(ctx)));
  80140. tcp_connect(&sfd, wolfSSLIP, ((func_args*)args)->signal->port, 0, 0, ssl);
  80141. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_set_fd(ssl, sfd));
  80142. if (EXPECT_SUCCESS()) {
  80143. do {
  80144. err = 0; /* Reset error */
  80145. ret = wolfSSL_connect(ssl);
  80146. if (ret != WOLFSSL_SUCCESS) {
  80147. err = wolfSSL_get_error(ssl, 0);
  80148. }
  80149. } while (ret != WOLFSSL_SUCCESS && err == WC_NO_ERR_TRACE(WC_PENDING_E));
  80150. }
  80151. ExpectIntGE(wolfSSL_write(ssl, msg, len), 0);
  80152. if (EXPECT_SUCCESS()) {
  80153. if (0 < (idx = wolfSSL_read(ssl, input, sizeof(input)-1))) {
  80154. input[idx] = 0;
  80155. }
  80156. }
  80157. if (EXPECT_SUCCESS()) {
  80158. ret = wolfSSL_shutdown(ssl);
  80159. if (ret == WOLFSSL_SHUTDOWN_NOT_DONE) {
  80160. ret = wolfSSL_shutdown(ssl);
  80161. }
  80162. }
  80163. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  80164. ((func_args*)args)->return_code = EXPECT_RESULT();
  80165. wolfSSL_free(ssl);
  80166. wolfSSL_CTX_free(ctx);
  80167. CloseSocket(sfd);
  80168. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS)
  80169. wc_ecc_fp_free(); /* free per thread cache */
  80170. #endif
  80171. WOLFSSL_RETURN_FROM_THREAD(0);
  80172. }
  80173. #endif /* OPENSSL_EXTRA && WOLFSSL_ERROR_CODE_OPENSSL &&
  80174. HAVE_IO_TESTS_DEPENDENCIES && !WOLFSSL_NO_TLS12 */
  80175. /* This test is to check wolfSSL_read behaves as same as
  80176. * openSSL when it is called after SSL_shutdown completes.
  80177. */
  80178. static int test_wolfSSL_read_detect_TCP_disconnect(void)
  80179. {
  80180. EXPECT_DECLS;
  80181. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_ERROR_CODE_OPENSSL) && \
  80182. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  80183. tcp_ready ready;
  80184. func_args client_args;
  80185. func_args server_args;
  80186. THREAD_TYPE serverThread;
  80187. THREAD_TYPE clientThread;
  80188. callback_functions server_cbf;
  80189. callback_functions client_cbf;
  80190. #ifdef WOLFSSL_TIRTOS
  80191. fdOpenSession(Task_self());
  80192. #endif
  80193. StartTCP();
  80194. InitTcpReady(&ready);
  80195. #if defined(USE_WINDOWS_API)
  80196. /* use RNG to get random port if using windows */
  80197. ready.port = GetRandomPort();
  80198. #endif
  80199. XMEMSET(&client_args, 0, sizeof(func_args));
  80200. XMEMSET(&server_args, 0, sizeof(func_args));
  80201. XMEMSET(&server_cbf, 0, sizeof(callback_functions));
  80202. XMEMSET(&client_cbf, 0, sizeof(callback_functions));
  80203. server_cbf.method = wolfTLSv1_2_server_method;
  80204. client_cbf.method = wolfTLSv1_2_client_method;
  80205. server_args.callbacks = &server_cbf;
  80206. client_args.callbacks = &client_cbf;
  80207. server_args.signal = &ready;
  80208. client_args.signal = &ready;
  80209. start_thread(SSL_read_test_server_thread, &server_args, &serverThread);
  80210. wait_tcp_ready(&server_args);
  80211. start_thread(SSL_read_test_client_thread, &client_args, &clientThread);
  80212. join_thread(clientThread);
  80213. join_thread(serverThread);
  80214. ExpectTrue(client_args.return_code);
  80215. ExpectTrue(server_args.return_code);
  80216. FreeTcpReady(&ready);
  80217. #endif
  80218. return EXPECT_RESULT();
  80219. }
  80220. static int test_wolfSSL_CTX_get_min_proto_version(void)
  80221. {
  80222. EXPECT_DECLS;
  80223. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)
  80224. WOLFSSL_CTX *ctx = NULL;
  80225. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_method()));
  80226. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, SSL3_VERSION),
  80227. WOLFSSL_SUCCESS);
  80228. #ifdef WOLFSSL_ALLOW_SSLV3
  80229. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), SSL3_VERSION);
  80230. #else
  80231. ExpectIntGT(wolfSSL_CTX_get_min_proto_version(ctx), SSL3_VERSION);
  80232. #endif
  80233. wolfSSL_CTX_free(ctx);
  80234. ctx = NULL;
  80235. #ifndef NO_OLD_TLS
  80236. #ifdef WOLFSSL_ALLOW_TLSV10
  80237. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_method()));
  80238. #else
  80239. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_method()));
  80240. #endif
  80241. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, TLS1_VERSION),
  80242. WOLFSSL_SUCCESS);
  80243. #ifdef WOLFSSL_ALLOW_TLSV10
  80244. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_VERSION);
  80245. #else
  80246. ExpectIntGT(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_VERSION);
  80247. #endif
  80248. wolfSSL_CTX_free(ctx);
  80249. ctx = NULL;
  80250. #endif
  80251. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_method()));
  80252. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, TLS1_1_VERSION),
  80253. WOLFSSL_SUCCESS);
  80254. #ifndef NO_OLD_TLS
  80255. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_1_VERSION);
  80256. #else
  80257. ExpectIntGT(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_1_VERSION);
  80258. #endif
  80259. wolfSSL_CTX_free(ctx);
  80260. ctx = NULL;
  80261. #ifndef WOLFSSL_NO_TLS12
  80262. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_2_method()));
  80263. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, TLS1_2_VERSION),
  80264. WOLFSSL_SUCCESS);
  80265. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_2_VERSION);
  80266. wolfSSL_CTX_free(ctx);
  80267. ctx = NULL;
  80268. #endif
  80269. #ifdef WOLFSSL_TLS13
  80270. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_method()));
  80271. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx, TLS1_3_VERSION),
  80272. WOLFSSL_SUCCESS);
  80273. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx), TLS1_3_VERSION);
  80274. wolfSSL_CTX_free(ctx);
  80275. ctx = NULL;
  80276. #endif
  80277. #endif /* defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL) */
  80278. return EXPECT_RESULT();
  80279. }
  80280. #if defined(OPENSSL_ALL) || (defined(OPENSSL_EXTRA) && \
  80281. (defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || \
  80282. defined(HAVE_LIGHTY) || defined(WOLFSSL_HAPROXY) || \
  80283. defined(WOLFSSL_OPENSSH) || defined(HAVE_SBLIM_SFCB)))
  80284. static int test_wolfSSL_set_SSL_CTX(void)
  80285. {
  80286. EXPECT_DECLS;
  80287. #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) \
  80288. && !defined(WOLFSSL_NO_TLS12) && defined(WOLFSSL_TLS13) && \
  80289. !defined(NO_RSA)
  80290. WOLFSSL_CTX *ctx1 = NULL;
  80291. WOLFSSL_CTX *ctx2 = NULL;
  80292. WOLFSSL *ssl = NULL;
  80293. const byte *session_id1 = (const byte *)"CTX1";
  80294. const byte *session_id2 = (const byte *)"CTX2";
  80295. ExpectNotNull(ctx1 = wolfSSL_CTX_new(wolfTLS_server_method()));
  80296. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx1, svrCertFile,
  80297. WOLFSSL_FILETYPE_PEM));
  80298. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx1, svrKeyFile,
  80299. WOLFSSL_FILETYPE_PEM));
  80300. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx1, TLS1_2_VERSION),
  80301. WOLFSSL_SUCCESS);
  80302. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx1), TLS1_2_VERSION);
  80303. ExpectIntEQ(wolfSSL_CTX_get_max_proto_version(ctx1), TLS1_3_VERSION);
  80304. ExpectIntEQ(wolfSSL_CTX_set_session_id_context(ctx1, session_id1, 4),
  80305. WOLFSSL_SUCCESS);
  80306. ExpectNotNull(ctx2 = wolfSSL_CTX_new(wolfTLS_server_method()));
  80307. ExpectTrue(wolfSSL_CTX_use_certificate_file(ctx2, svrCertFile,
  80308. WOLFSSL_FILETYPE_PEM));
  80309. ExpectTrue(wolfSSL_CTX_use_PrivateKey_file(ctx2, svrKeyFile,
  80310. WOLFSSL_FILETYPE_PEM));
  80311. ExpectIntEQ(wolfSSL_CTX_set_min_proto_version(ctx2, TLS1_2_VERSION),
  80312. WOLFSSL_SUCCESS);
  80313. ExpectIntEQ(wolfSSL_CTX_set_max_proto_version(ctx2, TLS1_2_VERSION),
  80314. WOLFSSL_SUCCESS);
  80315. ExpectIntEQ(wolfSSL_CTX_get_min_proto_version(ctx2), TLS1_2_VERSION);
  80316. ExpectIntEQ(wolfSSL_CTX_get_max_proto_version(ctx2), TLS1_2_VERSION);
  80317. ExpectIntEQ(wolfSSL_CTX_set_session_id_context(ctx2, session_id2, 4),
  80318. WOLFSSL_SUCCESS);
  80319. #ifdef HAVE_SESSION_TICKET
  80320. ExpectIntEQ((wolfSSL_CTX_get_options(ctx1) & SSL_OP_NO_TICKET), 0);
  80321. wolfSSL_CTX_set_options(ctx2, SSL_OP_NO_TICKET);
  80322. ExpectIntNE((wolfSSL_CTX_get_options(ctx2) & SSL_OP_NO_TICKET), 0);
  80323. #endif
  80324. ExpectNotNull(ssl = wolfSSL_new(ctx2));
  80325. ExpectIntNE((wolfSSL_get_options(ssl) & WOLFSSL_OP_NO_TLSv1_3), 0);
  80326. #ifdef WOLFSSL_INT_H
  80327. #ifdef WOLFSSL_SESSION_ID_CTX
  80328. ExpectIntEQ(XMEMCMP(ssl->sessionCtx, session_id2, 4), 0);
  80329. #endif
  80330. #ifdef WOLFSSL_COPY_CERT
  80331. if (ctx2 != NULL && ctx2->certificate != NULL) {
  80332. ExpectFalse(ssl->buffers.certificate == ctx2->certificate);
  80333. }
  80334. if (ctx2 != NULL && ctx2->certChain != NULL) {
  80335. ExpectFalse(ssl->buffers.certChain == ctx2->certChain);
  80336. }
  80337. #else
  80338. ExpectTrue(ssl->buffers.certificate == ctx2->certificate);
  80339. ExpectTrue(ssl->buffers.certChain == ctx2->certChain);
  80340. #endif
  80341. #endif
  80342. #ifdef HAVE_SESSION_TICKET
  80343. ExpectIntNE((wolfSSL_get_options(ssl) & SSL_OP_NO_TICKET), 0);
  80344. #endif
  80345. /* Set the ctx1 that has TLSv1.3 as max proto version */
  80346. ExpectNotNull(wolfSSL_set_SSL_CTX(ssl, ctx1));
  80347. /* MUST not change proto versions of ssl */
  80348. ExpectIntNE((wolfSSL_get_options(ssl) & WOLFSSL_OP_NO_TLSv1_3), 0);
  80349. #ifdef HAVE_SESSION_TICKET
  80350. /* MUST not change */
  80351. ExpectIntNE((wolfSSL_get_options(ssl) & SSL_OP_NO_TICKET), 0);
  80352. #endif
  80353. /* MUST change */
  80354. #ifdef WOLFSSL_INT_H
  80355. #ifdef WOLFSSL_COPY_CERT
  80356. if (ctx1 != NULL && ctx1->certificate != NULL) {
  80357. ExpectFalse(ssl->buffers.certificate == ctx1->certificate);
  80358. }
  80359. if (ctx1 != NULL && ctx1->certChain != NULL) {
  80360. ExpectFalse(ssl->buffers.certChain == ctx1->certChain);
  80361. }
  80362. #else
  80363. ExpectTrue(ssl->buffers.certificate == ctx1->certificate);
  80364. ExpectTrue(ssl->buffers.certChain == ctx1->certChain);
  80365. #endif
  80366. #ifdef WOLFSSL_SESSION_ID_CTX
  80367. ExpectIntEQ(XMEMCMP(ssl->sessionCtx, session_id1, 4), 0);
  80368. #endif
  80369. #endif
  80370. wolfSSL_free(ssl);
  80371. wolfSSL_CTX_free(ctx1);
  80372. wolfSSL_CTX_free(ctx2);
  80373. #endif /* defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL) */
  80374. return EXPECT_RESULT();
  80375. }
  80376. #endif /* defined(OPENSSL_ALL) || (defined(OPENSSL_EXTRA) && \
  80377. (defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || \
  80378. defined(HAVE_LIGHTY) || defined(WOLFSSL_HAPROXY) || \
  80379. defined(WOLFSSL_OPENSSH) || defined(HAVE_SBLIM_SFCB))) */
  80380. static int test_wolfSSL_security_level(void)
  80381. {
  80382. EXPECT_DECLS;
  80383. #if defined(OPENSSL_EXTRA)
  80384. SSL_CTX *ctx = NULL;
  80385. #ifdef WOLFSSL_TLS13
  80386. #ifdef NO_WOLFSSL_SERVER
  80387. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  80388. #else
  80389. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  80390. #endif
  80391. SSL_CTX_set_security_level(NULL, 1);
  80392. SSL_CTX_set_security_level(ctx, 1);
  80393. ExpectIntEQ(SSL_CTX_get_security_level(NULL), 0);
  80394. /* Stub so nothing happens. */
  80395. ExpectIntEQ(SSL_CTX_get_security_level(ctx), 0);
  80396. SSL_CTX_free(ctx);
  80397. #else
  80398. (void)ctx;
  80399. #endif
  80400. #endif
  80401. return EXPECT_RESULT();
  80402. }
  80403. static int test_wolfSSL_SSL_in_init(void)
  80404. {
  80405. EXPECT_DECLS;
  80406. #if defined(OPENSSL_ALL) && !defined(NO_BIO)
  80407. SSL_CTX* ctx = NULL;
  80408. SSL* ssl = NULL;
  80409. const char* testCertFile;
  80410. const char* testKeyFile;
  80411. #ifdef WOLFSSL_TLS13
  80412. #ifdef NO_WOLFSSL_SERVER
  80413. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  80414. #else
  80415. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  80416. #endif
  80417. #else
  80418. #ifdef NO_WOLFSSL_SERVER
  80419. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  80420. #else
  80421. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  80422. #endif
  80423. #endif
  80424. #ifndef NO_RSA
  80425. testCertFile = svrCertFile;
  80426. testKeyFile = svrKeyFile;
  80427. #elif defined(HAVE_ECC)
  80428. testCertFile = eccCertFile;
  80429. testKeyFile = eccKeyFile;
  80430. #else
  80431. testCertFile = NULL;
  80432. testKeyFile = NULL;
  80433. #endif
  80434. if ((testCertFile != NULL) && (testKeyFile != NULL)) {
  80435. ExpectTrue(SSL_CTX_use_certificate_file(ctx, testCertFile,
  80436. SSL_FILETYPE_PEM));
  80437. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  80438. SSL_FILETYPE_PEM));
  80439. }
  80440. ExpectNotNull(ssl = SSL_new(ctx));
  80441. ExpectIntEQ(SSL_in_init(ssl), 1);
  80442. SSL_CTX_free(ctx);
  80443. SSL_free(ssl);
  80444. #endif
  80445. return EXPECT_RESULT();
  80446. }
  80447. static int test_wolfSSL_CTX_set_timeout(void)
  80448. {
  80449. EXPECT_DECLS;
  80450. #if !defined(NO_WOLFSSL_SERVER) && !defined(NO_SESSION_CACHE)
  80451. int timeout;
  80452. WOLFSSL_CTX* ctx = NULL;
  80453. (void)timeout;
  80454. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  80455. #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
  80456. /* in WOLFSSL_ERROR_CODE_OPENSSL macro guard,
  80457. * wolfSSL_CTX_set_timeout returns previous timeout value on success.
  80458. */
  80459. ExpectIntEQ(wolfSSL_CTX_set_timeout(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  80460. /* giving 0 as timeout value sets default timeout */
  80461. timeout = wolfSSL_CTX_set_timeout(ctx, 0);
  80462. ExpectIntEQ(wolfSSL_CTX_set_timeout(ctx, 20), timeout);
  80463. ExpectIntEQ(wolfSSL_CTX_set_timeout(ctx, 30), 20);
  80464. #else
  80465. ExpectIntEQ(wolfSSL_CTX_set_timeout(NULL, 0), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  80466. ExpectIntEQ(wolfSSL_CTX_set_timeout(ctx, 100), 1);
  80467. ExpectIntEQ(wolfSSL_CTX_set_timeout(ctx, 0), 1);
  80468. #endif
  80469. wolfSSL_CTX_free(ctx);
  80470. #endif /* !NO_WOLFSSL_SERVER && !NO_SESSION_CACHE*/
  80471. return EXPECT_RESULT();
  80472. }
  80473. static int test_wolfSSL_OpenSSL_version(void)
  80474. {
  80475. EXPECT_DECLS;
  80476. #if defined(OPENSSL_EXTRA)
  80477. const char* ver;
  80478. #if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
  80479. ExpectNotNull(ver = OpenSSL_version(0));
  80480. #else
  80481. ExpectNotNull(ver = OpenSSL_version());
  80482. #endif
  80483. ExpectIntEQ(XMEMCMP(ver, "wolfSSL " LIBWOLFSSL_VERSION_STRING,
  80484. XSTRLEN("wolfSSL " LIBWOLFSSL_VERSION_STRING)), 0);
  80485. #endif
  80486. return EXPECT_RESULT();
  80487. }
  80488. static int test_CONF_CTX_CMDLINE(void)
  80489. {
  80490. EXPECT_DECLS;
  80491. #if defined(OPENSSL_ALL)
  80492. SSL_CTX* ctx = NULL;
  80493. SSL_CONF_CTX* cctx = NULL;
  80494. ExpectNotNull(cctx = SSL_CONF_CTX_new());
  80495. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  80496. SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
  80497. /* set flags */
  80498. ExpectIntEQ(SSL_CONF_CTX_set_flags(cctx, WOLFSSL_CONF_FLAG_CMDLINE),
  80499. WOLFSSL_CONF_FLAG_CMDLINE);
  80500. ExpectIntEQ(SSL_CONF_CTX_set_flags(cctx, WOLFSSL_CONF_FLAG_CERTIFICATE),
  80501. WOLFSSL_CONF_FLAG_CMDLINE | WOLFSSL_CONF_FLAG_CERTIFICATE);
  80502. /* cmd invalid command */
  80503. ExpectIntEQ(SSL_CONF_cmd(cctx, "foo", "foobar"), -2);
  80504. ExpectIntEQ(SSL_CONF_cmd(cctx, "foo", NULL), -2);
  80505. ExpectIntEQ(SSL_CONF_cmd(cctx, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80506. ExpectIntEQ(SSL_CONF_cmd(cctx, NULL, "foobar"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80507. ExpectIntEQ(SSL_CONF_cmd(NULL, "-curves", "foobar"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80508. /* cmd Certificate and Private Key*/
  80509. {
  80510. #if !defined(NO_CERTS) && !defined(NO_RSA)
  80511. const char* ourCert = svrCertFile;
  80512. const char* ourKey = svrKeyFile;
  80513. ExpectIntEQ(SSL_CONF_cmd(cctx, "-cert", NULL), -3);
  80514. ExpectIntEQ(SSL_CONF_cmd(cctx, "-cert", ourCert), WOLFSSL_SUCCESS);
  80515. ExpectIntEQ(SSL_CONF_cmd(cctx, "-key", NULL), -3);
  80516. ExpectIntEQ(SSL_CONF_cmd(cctx, "-key", ourKey), WOLFSSL_SUCCESS);
  80517. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  80518. #endif
  80519. }
  80520. /* cmd curves */
  80521. {
  80522. #if defined(HAVE_ECC)
  80523. const char* curve = "secp256r1";
  80524. ExpectIntEQ(SSL_CONF_cmd(cctx, "-curves", NULL), -3);
  80525. ExpectIntEQ(SSL_CONF_cmd(cctx, "-curves", curve), WOLFSSL_SUCCESS);
  80526. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  80527. #endif
  80528. }
  80529. /* cmd CipherString */
  80530. {
  80531. char* cipher = wolfSSL_get_cipher_list(0/*top priority*/);
  80532. ExpectIntEQ(SSL_CONF_cmd(cctx, "-cipher", NULL), -3);
  80533. ExpectIntEQ(SSL_CONF_cmd(cctx, "-cipher", cipher), WOLFSSL_SUCCESS);
  80534. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  80535. }
  80536. /* cmd DH parameter */
  80537. {
  80538. #if !defined(NO_DH) && !defined(NO_BIO)
  80539. const char* ourdhcert = "./certs/dh2048.pem";
  80540. ExpectIntEQ(SSL_CONF_cmd(cctx, "-dhparam", NULL), -3);
  80541. ExpectIntEQ(SSL_CONF_cmd(cctx, "-dhparam", ourdhcert), WOLFSSL_SUCCESS);
  80542. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  80543. #endif
  80544. }
  80545. SSL_CTX_free(ctx);
  80546. SSL_CONF_CTX_free(cctx);
  80547. #endif /* OPENSSL_EXTRA */
  80548. return EXPECT_RESULT();
  80549. }
  80550. static int test_CONF_CTX_FILE(void)
  80551. {
  80552. EXPECT_DECLS;
  80553. #if defined(OPENSSL_ALL)
  80554. SSL_CTX* ctx = NULL;
  80555. SSL_CONF_CTX* cctx = NULL;
  80556. ExpectNotNull(cctx = SSL_CONF_CTX_new());
  80557. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  80558. SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
  80559. /* set flags */
  80560. ExpectIntEQ(SSL_CONF_CTX_set_flags(cctx, WOLFSSL_CONF_FLAG_FILE),
  80561. WOLFSSL_CONF_FLAG_FILE);
  80562. ExpectIntEQ(SSL_CONF_CTX_set_flags(cctx, WOLFSSL_CONF_FLAG_CERTIFICATE),
  80563. WOLFSSL_CONF_FLAG_FILE | WOLFSSL_CONF_FLAG_CERTIFICATE);
  80564. /* sanity check */
  80565. ExpectIntEQ(SSL_CONF_cmd(cctx, "foo", "foobar"), -2);
  80566. ExpectIntEQ(SSL_CONF_cmd(cctx, "foo", NULL), -2);
  80567. ExpectIntEQ(SSL_CONF_cmd(cctx, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80568. ExpectIntEQ(SSL_CONF_cmd(cctx, NULL, "foobar"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80569. ExpectIntEQ(SSL_CONF_cmd(NULL, "-curves", "foobar"), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80570. /* cmd Certificate and Private Key*/
  80571. {
  80572. #if !defined(NO_CERTS) && !defined(NO_RSA)
  80573. const char* ourCert = svrCertFile;
  80574. const char* ourKey = svrKeyFile;
  80575. ExpectIntEQ(SSL_CONF_cmd(cctx, "Certificate", NULL), -3);
  80576. ExpectIntEQ(SSL_CONF_cmd(cctx, "PrivateKey", NULL), -3);
  80577. ExpectIntEQ(SSL_CONF_cmd(cctx, "Certificate", ourCert),
  80578. WOLFSSL_SUCCESS);
  80579. ExpectIntEQ(SSL_CONF_cmd(cctx, "PrivateKey", ourKey), WOLFSSL_SUCCESS);
  80580. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  80581. #endif
  80582. }
  80583. /* cmd curves */
  80584. {
  80585. #if defined(HAVE_ECC)
  80586. const char* curve = "secp256r1";
  80587. ExpectIntEQ(SSL_CONF_cmd(cctx, "Curves", NULL), -3);
  80588. ExpectIntEQ(SSL_CONF_cmd(cctx, "Curves", curve), WOLFSSL_SUCCESS);
  80589. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  80590. #endif
  80591. }
  80592. /* cmd CipherString */
  80593. {
  80594. char* cipher = wolfSSL_get_cipher_list(0/*top priority*/);
  80595. ExpectIntEQ(SSL_CONF_cmd(cctx, "CipherString", NULL), -3);
  80596. ExpectIntEQ(SSL_CONF_cmd(cctx, "CipherString", cipher),
  80597. WOLFSSL_SUCCESS);
  80598. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  80599. }
  80600. /* cmd DH parameter */
  80601. {
  80602. #if !defined(NO_DH) && !defined(NO_BIO) && defined(HAVE_FFDHE_3072)
  80603. const char* ourdhcert = "./certs/dh3072.pem";
  80604. ExpectIntEQ(SSL_CONF_cmd(cctx, "DHParameters", NULL), -3);
  80605. ExpectIntEQ(SSL_CONF_cmd(cctx, "DHParameters", ourdhcert),
  80606. WOLFSSL_SUCCESS);
  80607. ExpectIntEQ(SSL_CONF_CTX_finish(cctx), WOLFSSL_SUCCESS);
  80608. #endif
  80609. }
  80610. SSL_CTX_free(ctx);
  80611. SSL_CONF_CTX_free(cctx);
  80612. #endif /* OPENSSL_EXTRA */
  80613. return EXPECT_RESULT();
  80614. }
  80615. static int test_wolfSSL_CRYPTO_get_ex_new_index(void)
  80616. {
  80617. EXPECT_DECLS;
  80618. #ifdef HAVE_EX_DATA
  80619. int idx1, idx2;
  80620. /* test for unsupported class index */
  80621. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_X509_STORE,
  80622. 0,NULL, NULL, NULL, NULL ), -1);
  80623. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(
  80624. WOLF_CRYPTO_EX_INDEX_X509_STORE_CTX,
  80625. 0,NULL, NULL, NULL, NULL ), -1);
  80626. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_DH,
  80627. 0,NULL, NULL, NULL, NULL ), -1);
  80628. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_DSA,
  80629. 0,NULL, NULL, NULL, NULL ), -1);
  80630. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_EC_KEY,
  80631. 0,NULL, NULL, NULL, NULL ), -1);
  80632. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_RSA,
  80633. 0,NULL, NULL, NULL, NULL ), -1);
  80634. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_ENGINE,
  80635. 0,NULL, NULL, NULL, NULL ), -1);
  80636. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_UI,
  80637. 0,NULL, NULL, NULL, NULL ), -1);
  80638. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_BIO,
  80639. 0,NULL, NULL, NULL, NULL ), -1);
  80640. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_APP,
  80641. 0,NULL, NULL, NULL, NULL ), -1);
  80642. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_UI_METHOD,
  80643. 0,NULL, NULL, NULL, NULL ), -1);
  80644. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_DRBG,
  80645. 0,NULL, NULL, NULL, NULL ), -1);
  80646. ExpectIntEQ(wolfSSL_CRYPTO_get_ex_new_index(20,
  80647. 0,NULL, NULL, NULL, NULL ), -1);
  80648. /* test for supported class index */
  80649. idx1 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL,
  80650. 0,NULL, NULL, NULL, NULL );
  80651. idx2 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL,
  80652. 0,NULL, NULL, NULL, NULL );
  80653. ExpectIntNE(idx1, -1);
  80654. ExpectIntNE(idx2, -1);
  80655. ExpectIntNE(idx1, idx2);
  80656. idx1 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL_CTX,
  80657. 0,NULL, NULL, NULL, NULL );
  80658. idx2 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL_CTX,
  80659. 0,NULL, NULL, NULL, NULL );
  80660. ExpectIntNE(idx1, -1);
  80661. ExpectIntNE(idx2, -1);
  80662. ExpectIntNE(idx1, idx2);
  80663. idx1 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_X509,
  80664. 0,NULL, NULL, NULL, NULL );
  80665. idx2 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_X509,
  80666. 0,NULL, NULL, NULL, NULL );
  80667. ExpectIntNE(idx1, -1);
  80668. ExpectIntNE(idx2, -1);
  80669. ExpectIntNE(idx1, idx2);
  80670. idx1 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL_SESSION,
  80671. 0,NULL, NULL, NULL, NULL );
  80672. idx2 = wolfSSL_CRYPTO_get_ex_new_index(WOLF_CRYPTO_EX_INDEX_SSL_SESSION,
  80673. 0,NULL, NULL, NULL, NULL );
  80674. ExpectIntNE(idx1, -1);
  80675. ExpectIntNE(idx2, -1);
  80676. ExpectIntNE(idx1, idx2);
  80677. #endif /* HAVE_EX_DATA */
  80678. return EXPECT_RESULT();
  80679. }
  80680. #if defined(HAVE_EX_DATA) && defined(HAVE_EXT_CACHE) && \
  80681. (defined(OPENSSL_ALL) || (defined(OPENSSL_EXTRA) && \
  80682. (defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || \
  80683. defined(HAVE_LIGHTY) || defined(WOLFSSL_HAPROXY) || \
  80684. defined(WOLFSSL_OPENSSH) || defined(HAVE_SBLIM_SFCB))))
  80685. #define SESSION_NEW_IDX_LONG 0xDEADBEEF
  80686. #define SESSION_NEW_IDX_VAL ((void*)0xAEADAEAD)
  80687. #define SESSION_DUP_IDX_VAL ((void*)0xDEDEDEDE)
  80688. #define SESSION_NEW_IDX_PTR "Testing"
  80689. static void test_wolfSSL_SESSION_get_ex_new_index_new_cb(void* p, void* ptr,
  80690. CRYPTO_EX_DATA* a, int idx, long argValue, void* arg)
  80691. {
  80692. AssertNotNull(p);
  80693. AssertNull(ptr);
  80694. AssertIntEQ(CRYPTO_set_ex_data(a, idx, SESSION_NEW_IDX_VAL), SSL_SUCCESS);
  80695. AssertIntEQ(argValue, SESSION_NEW_IDX_LONG);
  80696. AssertStrEQ(arg, SESSION_NEW_IDX_PTR);
  80697. }
  80698. static int test_wolfSSL_SESSION_get_ex_new_index_dup_cb(CRYPTO_EX_DATA* out,
  80699. const CRYPTO_EX_DATA* in, void* inPtr, int idx, long argV,
  80700. void* arg)
  80701. {
  80702. EXPECT_DECLS;
  80703. ExpectNotNull(out);
  80704. ExpectNotNull(in);
  80705. ExpectPtrEq(*(void**)inPtr, SESSION_NEW_IDX_VAL);
  80706. ExpectPtrEq(CRYPTO_get_ex_data(in, idx), SESSION_NEW_IDX_VAL);
  80707. ExpectPtrEq(CRYPTO_get_ex_data(out, idx), SESSION_NEW_IDX_VAL);
  80708. ExpectIntEQ(argV, SESSION_NEW_IDX_LONG);
  80709. ExpectStrEQ(arg, SESSION_NEW_IDX_PTR);
  80710. *(void**)inPtr = SESSION_DUP_IDX_VAL;
  80711. if (EXPECT_SUCCESS()) {
  80712. return SSL_SUCCESS;
  80713. }
  80714. else {
  80715. return SSL_FAILURE;
  80716. }
  80717. }
  80718. static int test_wolfSSL_SESSION_get_ex_new_index_free_cb_called = 0;
  80719. static void test_wolfSSL_SESSION_get_ex_new_index_free_cb(void* p, void* ptr,
  80720. CRYPTO_EX_DATA* a, int idx, long argValue, void* arg)
  80721. {
  80722. EXPECT_DECLS;
  80723. ExpectNotNull(p);
  80724. ExpectNull(ptr);
  80725. ExpectPtrNE(CRYPTO_get_ex_data(a, idx), 0);
  80726. ExpectIntEQ(argValue, SESSION_NEW_IDX_LONG);
  80727. ExpectStrEQ(arg, SESSION_NEW_IDX_PTR);
  80728. if (EXPECT_SUCCESS()) {
  80729. test_wolfSSL_SESSION_get_ex_new_index_free_cb_called++;
  80730. }
  80731. }
  80732. static int test_wolfSSL_SESSION_get_ex_new_index(void)
  80733. {
  80734. EXPECT_DECLS;
  80735. int idx = SSL_SESSION_get_ex_new_index(SESSION_NEW_IDX_LONG,
  80736. (void*)SESSION_NEW_IDX_PTR,
  80737. test_wolfSSL_SESSION_get_ex_new_index_new_cb,
  80738. test_wolfSSL_SESSION_get_ex_new_index_dup_cb,
  80739. test_wolfSSL_SESSION_get_ex_new_index_free_cb);
  80740. SSL_SESSION* s = SSL_SESSION_new();
  80741. SSL_SESSION* d = NULL;
  80742. ExpectNotNull(s);
  80743. ExpectPtrEq(SSL_SESSION_get_ex_data(s, idx), SESSION_NEW_IDX_VAL);
  80744. ExpectNotNull(d = SSL_SESSION_dup(s));
  80745. ExpectPtrEq(SSL_SESSION_get_ex_data(d, idx), SESSION_DUP_IDX_VAL);
  80746. SSL_SESSION_free(s);
  80747. ExpectIntEQ(test_wolfSSL_SESSION_get_ex_new_index_free_cb_called, 1);
  80748. SSL_SESSION_free(d);
  80749. ExpectIntEQ(test_wolfSSL_SESSION_get_ex_new_index_free_cb_called, 2);
  80750. crypto_ex_cb_free(crypto_ex_cb_ctx_session);
  80751. crypto_ex_cb_ctx_session = NULL;
  80752. return EXPECT_RESULT();
  80753. }
  80754. #else
  80755. static int test_wolfSSL_SESSION_get_ex_new_index(void)
  80756. {
  80757. return TEST_SKIPPED;
  80758. }
  80759. #endif
  80760. static int test_wolfSSL_set_psk_use_session_callback(void)
  80761. {
  80762. EXPECT_DECLS;
  80763. #if defined(OPENSSL_EXTRA) && !defined(NO_PSK)
  80764. SSL_CTX* ctx = NULL;
  80765. SSL* ssl = NULL;
  80766. const char* testCertFile;
  80767. const char* testKeyFile;
  80768. #ifdef WOLFSSL_TLS13
  80769. #ifdef NO_WOLFSSL_SERVER
  80770. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
  80771. #else
  80772. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_server_method()));
  80773. #endif
  80774. #else
  80775. #ifdef NO_WOLFSSL_SERVER
  80776. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  80777. #else
  80778. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  80779. #endif
  80780. #endif
  80781. #ifndef NO_RSA
  80782. testCertFile = svrCertFile;
  80783. testKeyFile = svrKeyFile;
  80784. #elif defined(HAVE_ECC)
  80785. testCertFile = eccCertFile;
  80786. testKeyFile = eccKeyFile;
  80787. #else
  80788. testCertFile = NULL;
  80789. testKeyFile = NULL;
  80790. #endif
  80791. if ((testCertFile != NULL) && (testKeyFile != NULL)) {
  80792. ExpectTrue(SSL_CTX_use_certificate_file(ctx, testCertFile,
  80793. SSL_FILETYPE_PEM));
  80794. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  80795. SSL_FILETYPE_PEM));
  80796. }
  80797. ExpectNotNull(ssl = SSL_new(ctx));
  80798. SSL_set_psk_use_session_callback(ssl, my_psk_use_session_cb);
  80799. SSL_CTX_free(ctx);
  80800. SSL_free(ssl);
  80801. #endif
  80802. return EXPECT_RESULT();
  80803. }
  80804. /* similar to error_test() in wolfcrypt/test/test.c, but adding error codes from
  80805. * TLS layer.
  80806. */
  80807. static int error_test(void)
  80808. {
  80809. EXPECT_DECLS;
  80810. const char* errStr;
  80811. const char* unknownStr = wc_GetErrorString(0);
  80812. #ifdef NO_ERROR_STRINGS
  80813. /* Ensure a valid error code's string matches an invalid code's.
  80814. * The string is that error strings are not available.
  80815. */
  80816. errStr = wc_GetErrorString(OPEN_RAN_E);
  80817. ExpectIntEQ(XSTRCMP(errStr, unknownStr), 0);
  80818. if (EXPECT_FAIL())
  80819. return OPEN_RAN_E;
  80820. #else
  80821. int i;
  80822. int j = 0;
  80823. /* Values that are not or no longer error codes. */
  80824. static const struct {
  80825. int first;
  80826. int last;
  80827. } missing[] = {
  80828. #ifndef OPENSSL_EXTRA
  80829. { 0, 0 },
  80830. #endif
  80831. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
  80832. defined(HAVE_WEBSERVER) || defined(HAVE_MEMCACHED)
  80833. { -11, -12 },
  80834. { -15, -17 },
  80835. { -19, -19 },
  80836. { -26, -27 },
  80837. { -30, WC_FIRST_E+1 },
  80838. #else
  80839. { -9, WC_FIRST_E+1 },
  80840. #endif
  80841. { -124, -124 },
  80842. { -166, -169 },
  80843. { -300, -300 },
  80844. { -334, -336 },
  80845. { -346, -349 },
  80846. { -356, -356 },
  80847. { -358, -358 },
  80848. { -384, -384 },
  80849. { -466, -499 },
  80850. { WOLFSSL_LAST_E-1, WOLFSSL_LAST_E-1 }
  80851. };
  80852. /* Check that all errors have a string and it's the same through the two
  80853. * APIs. Check that the values that are not errors map to the unknown
  80854. * string.
  80855. */
  80856. for (i = 0; i >= WOLFSSL_LAST_E-1; i--) {
  80857. int this_missing = 0;
  80858. for (j = 0; j < (int)XELEM_CNT(missing); ++j) {
  80859. if ((i <= missing[j].first) && (i >= missing[j].last)) {
  80860. this_missing = 1;
  80861. break;
  80862. }
  80863. }
  80864. errStr = wolfSSL_ERR_reason_error_string((word32)i);
  80865. if (! this_missing) {
  80866. ExpectIntNE(XSTRCMP(errStr, unknownStr), 0);
  80867. if (EXPECT_FAIL()) {
  80868. return i;
  80869. }
  80870. ExpectTrue(XSTRLEN(errStr) < WOLFSSL_MAX_ERROR_SZ);
  80871. if (EXPECT_FAIL()) {
  80872. return i;
  80873. }
  80874. }
  80875. else {
  80876. j++;
  80877. ExpectIntEQ(XSTRCMP(errStr, unknownStr), 0);
  80878. if (EXPECT_FAIL()) {
  80879. return i;
  80880. }
  80881. }
  80882. }
  80883. #endif
  80884. return 1;
  80885. }
  80886. static int test_wolfSSL_ERR_strings(void)
  80887. {
  80888. EXPECT_DECLS;
  80889. #if !defined(NO_ERROR_STRINGS)
  80890. const char* err1 = "unsupported cipher suite";
  80891. const char* err2 = "wolfSSL PEM routines";
  80892. const char* err = NULL;
  80893. (void)err;
  80894. (void)err1;
  80895. (void)err2;
  80896. #if defined(OPENSSL_EXTRA)
  80897. ExpectNotNull(err = ERR_reason_error_string(WC_NO_ERR_TRACE(UNSUPPORTED_SUITE)));
  80898. ExpectIntEQ(XSTRNCMP(err, err1, XSTRLEN(err1)), 0);
  80899. ExpectNotNull(err = ERR_func_error_string(WC_NO_ERR_TRACE(UNSUPPORTED_SUITE)));
  80900. ExpectIntEQ((*err == '\0'), 1);
  80901. ExpectNotNull(err = ERR_lib_error_string(PEM_R_PROBLEMS_GETTING_PASSWORD));
  80902. ExpectIntEQ(XSTRNCMP(err, err2, XSTRLEN(err2)), 0);
  80903. #else
  80904. ExpectNotNull(err = wolfSSL_ERR_reason_error_string(WC_NO_ERR_TRACE((word32)UNSUPPORTED_SUITE)));
  80905. ExpectIntEQ(XSTRNCMP(err, err1, XSTRLEN(err1)), 0);
  80906. ExpectNotNull(err = wolfSSL_ERR_func_error_string(WC_NO_ERR_TRACE((word32)UNSUPPORTED_SUITE)));
  80907. ExpectIntEQ((*err == '\0'), 1);
  80908. /* The value -MIN_CODE_E+2 is PEM_R_PROBLEMS_GETTING_PASSWORD. */
  80909. ExpectNotNull(err = wolfSSL_ERR_lib_error_string(-MIN_CODE_E+2));
  80910. ExpectIntEQ((*err == '\0'), 1);
  80911. #endif
  80912. #endif
  80913. ExpectIntEQ(error_test(), 1);
  80914. return EXPECT_RESULT();
  80915. }
  80916. static int test_wolfSSL_EVP_shake128(void)
  80917. {
  80918. EXPECT_DECLS;
  80919. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA3) && \
  80920. defined(WOLFSSL_SHAKE128)
  80921. const EVP_MD* md = NULL;
  80922. ExpectNotNull(md = EVP_shake128());
  80923. ExpectIntEQ(XSTRNCMP(md, "SHAKE128", XSTRLEN("SHAKE128")), 0);
  80924. #endif
  80925. return EXPECT_RESULT();
  80926. }
  80927. static int test_wolfSSL_EVP_shake256(void)
  80928. {
  80929. EXPECT_DECLS;
  80930. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA3) && \
  80931. defined(WOLFSSL_SHAKE256)
  80932. const EVP_MD* md = NULL;
  80933. ExpectNotNull(md = EVP_shake256());
  80934. ExpectIntEQ(XSTRNCMP(md, "SHAKE256", XSTRLEN("SHAKE256")), 0);
  80935. #endif
  80936. return EXPECT_RESULT();
  80937. }
  80938. /*
  80939. * Testing EVP digest API with SM3
  80940. */
  80941. static int test_wolfSSL_EVP_sm3(void)
  80942. {
  80943. int res = TEST_SKIPPED;
  80944. #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_SM3)
  80945. EXPECT_DECLS;
  80946. const EVP_MD* md = NULL;
  80947. EVP_MD_CTX* mdCtx = NULL;
  80948. byte data[WC_SM3_BLOCK_SIZE * 4];
  80949. byte hash[WC_SM3_DIGEST_SIZE];
  80950. byte calcHash[WC_SM3_DIGEST_SIZE];
  80951. byte expHash[WC_SM3_DIGEST_SIZE] = {
  80952. 0x38, 0x48, 0x15, 0xa7, 0x0e, 0xae, 0x0b, 0x27,
  80953. 0x5c, 0xde, 0x9d, 0xa5, 0xd1, 0xa4, 0x30, 0xa1,
  80954. 0xca, 0xd4, 0x54, 0x58, 0x44, 0xa2, 0x96, 0x1b,
  80955. 0xd7, 0x14, 0x80, 0x3f, 0x80, 0x1a, 0x07, 0xb6
  80956. };
  80957. word32 chunk;
  80958. word32 i;
  80959. unsigned int sz;
  80960. int ret;
  80961. XMEMSET(data, 0, sizeof(data));
  80962. md = EVP_sm3();
  80963. ExpectTrue(md != NULL);
  80964. ExpectIntEQ(XSTRNCMP(md, "SM3", XSTRLEN("SM3")), 0);
  80965. mdCtx = EVP_MD_CTX_new();
  80966. ExpectTrue(mdCtx != NULL);
  80967. /* Invalid Parameters */
  80968. ExpectIntEQ(EVP_DigestInit(NULL, md), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80969. /* Valid Parameters */
  80970. ExpectIntEQ(EVP_DigestInit(mdCtx, md), WOLFSSL_SUCCESS);
  80971. ExpectIntEQ(EVP_DigestUpdate(NULL, NULL, 1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80972. ExpectIntEQ(EVP_DigestUpdate(mdCtx, NULL, 1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80973. ExpectIntEQ(EVP_DigestUpdate(NULL, data, 1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80974. /* Valid Parameters */
  80975. ExpectIntEQ(EVP_DigestUpdate(mdCtx, NULL, 0), WOLFSSL_SUCCESS);
  80976. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, 1), WOLFSSL_SUCCESS);
  80977. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, 1), WOLFSSL_SUCCESS);
  80978. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, WC_SM3_BLOCK_SIZE),
  80979. WOLFSSL_SUCCESS);
  80980. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, WC_SM3_BLOCK_SIZE - 2),
  80981. WOLFSSL_SUCCESS);
  80982. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, WC_SM3_BLOCK_SIZE * 2),
  80983. WOLFSSL_SUCCESS);
  80984. /* Ensure too many bytes for lengths. */
  80985. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, WC_SM3_PAD_SIZE),
  80986. WOLFSSL_SUCCESS);
  80987. /* Invalid Parameters */
  80988. ExpectIntEQ(EVP_DigestFinal(NULL, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80989. ExpectIntEQ(EVP_DigestFinal(mdCtx, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80990. ExpectIntEQ(EVP_DigestFinal(NULL, hash, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80991. ExpectIntEQ(EVP_DigestFinal(NULL, hash, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80992. ExpectIntEQ(EVP_DigestFinal(mdCtx, NULL, NULL), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  80993. /* Valid Parameters */
  80994. ExpectIntEQ(EVP_DigestFinal(mdCtx, hash, NULL), WOLFSSL_SUCCESS);
  80995. ExpectBufEQ(hash, expHash, WC_SM3_DIGEST_SIZE);
  80996. /* Chunk tests. */
  80997. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data, sizeof(data)), WOLFSSL_SUCCESS);
  80998. ExpectIntEQ(EVP_DigestFinal(mdCtx, calcHash, &sz), WOLFSSL_SUCCESS);
  80999. ExpectIntEQ(sz, WC_SM3_DIGEST_SIZE);
  81000. for (chunk = 1; chunk <= WC_SM3_BLOCK_SIZE + 1; chunk++) {
  81001. for (i = 0; i + chunk <= (word32)sizeof(data); i += chunk) {
  81002. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data + i, chunk),
  81003. WOLFSSL_SUCCESS);
  81004. }
  81005. if (i < (word32)sizeof(data)) {
  81006. ExpectIntEQ(EVP_DigestUpdate(mdCtx, data + i,
  81007. (word32)sizeof(data) - i), WOLFSSL_SUCCESS);
  81008. }
  81009. ExpectIntEQ(EVP_DigestFinal(mdCtx, hash, NULL), WOLFSSL_SUCCESS);
  81010. ExpectBufEQ(hash, calcHash, WC_SM3_DIGEST_SIZE);
  81011. }
  81012. /* Not testing when the low 32-bit length overflows. */
  81013. ret = EVP_MD_CTX_cleanup(mdCtx);
  81014. ExpectIntEQ(ret, WOLFSSL_SUCCESS);
  81015. wolfSSL_EVP_MD_CTX_free(mdCtx);
  81016. res = EXPECT_RESULT();
  81017. #endif
  81018. return res;
  81019. } /* END test_EVP_sm3 */
  81020. static int test_EVP_blake2(void)
  81021. {
  81022. EXPECT_DECLS;
  81023. #if defined(OPENSSL_EXTRA) && (defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S))
  81024. const EVP_MD* md = NULL;
  81025. (void)md;
  81026. #if defined(HAVE_BLAKE2)
  81027. ExpectNotNull(md = EVP_blake2b512());
  81028. ExpectIntEQ(XSTRNCMP(md, "BLAKE2B512", XSTRLEN("BLAKE2B512")), 0);
  81029. #endif
  81030. #if defined(HAVE_BLAKE2S)
  81031. ExpectNotNull(md = EVP_blake2s256());
  81032. ExpectIntEQ(XSTRNCMP(md, "BLAKE2S256", XSTRLEN("BLAKE2S256")), 0);
  81033. #endif
  81034. #endif
  81035. return EXPECT_RESULT();
  81036. }
  81037. #if defined(OPENSSL_EXTRA)
  81038. static void list_md_fn(const EVP_MD* m, const char* from,
  81039. const char* to, void* arg)
  81040. {
  81041. const char* mn;
  81042. BIO *bio;
  81043. (void) from;
  81044. (void) to;
  81045. (void) arg;
  81046. (void) mn;
  81047. (void) bio;
  81048. if (!m) {
  81049. /* alias */
  81050. AssertNull(m);
  81051. AssertNotNull(to);
  81052. }
  81053. else {
  81054. AssertNotNull(m);
  81055. AssertNull(to);
  81056. }
  81057. AssertNotNull(from);
  81058. #if !defined(NO_FILESYSTEM) && defined(DEBUG_WOLFSSL_VERBOSE)
  81059. mn = EVP_get_digestbyname(from);
  81060. /* print to stderr */
  81061. AssertNotNull(arg);
  81062. bio = BIO_new(BIO_s_file());
  81063. BIO_set_fp(bio, arg, BIO_NOCLOSE);
  81064. BIO_printf(bio, "Use %s message digest algorithm\n", mn);
  81065. BIO_free(bio);
  81066. #endif
  81067. }
  81068. #endif
  81069. static int test_EVP_MD_do_all(void)
  81070. {
  81071. int res = TEST_SKIPPED;
  81072. #if defined(OPENSSL_EXTRA)
  81073. EVP_MD_do_all(NULL, stderr);
  81074. EVP_MD_do_all(list_md_fn, stderr);
  81075. res = TEST_SUCCESS;
  81076. #endif
  81077. return res;
  81078. }
  81079. #if defined(OPENSSL_EXTRA)
  81080. static void obj_name_t(const OBJ_NAME* nm, void* arg)
  81081. {
  81082. (void)arg;
  81083. (void)nm;
  81084. AssertIntGT(nm->type, OBJ_NAME_TYPE_UNDEF);
  81085. #if !defined(NO_FILESYSTEM) && defined(DEBUG_WOLFSSL_VERBOSE)
  81086. /* print to stderr */
  81087. AssertNotNull(arg);
  81088. BIO *bio = BIO_new(BIO_s_file());
  81089. BIO_set_fp(bio, arg, BIO_NOCLOSE);
  81090. BIO_printf(bio, "%s\n", nm);
  81091. BIO_free(bio);
  81092. #endif
  81093. }
  81094. #endif
  81095. static int test_OBJ_NAME_do_all(void)
  81096. {
  81097. int res = TEST_SKIPPED;
  81098. #if defined(OPENSSL_EXTRA)
  81099. OBJ_NAME_do_all(OBJ_NAME_TYPE_MD_METH, NULL, NULL);
  81100. OBJ_NAME_do_all(OBJ_NAME_TYPE_CIPHER_METH, NULL, stderr);
  81101. OBJ_NAME_do_all(OBJ_NAME_TYPE_MD_METH, obj_name_t, stderr);
  81102. OBJ_NAME_do_all(OBJ_NAME_TYPE_PKEY_METH, obj_name_t, stderr);
  81103. OBJ_NAME_do_all(OBJ_NAME_TYPE_COMP_METH, obj_name_t, stderr);
  81104. OBJ_NAME_do_all(OBJ_NAME_TYPE_NUM, obj_name_t, stderr);
  81105. OBJ_NAME_do_all(OBJ_NAME_TYPE_UNDEF, obj_name_t, stderr);
  81106. OBJ_NAME_do_all(OBJ_NAME_TYPE_CIPHER_METH, obj_name_t, stderr);
  81107. OBJ_NAME_do_all(-1, obj_name_t, stderr);
  81108. res = TEST_SUCCESS;
  81109. #endif
  81110. return res;
  81111. }
  81112. static int test_SSL_CIPHER_get_xxx(void)
  81113. {
  81114. EXPECT_DECLS;
  81115. #if defined(OPENSSL_ALL) && !defined(NO_CERTS) && \
  81116. !defined(NO_FILESYSTEM)
  81117. const SSL_CIPHER* cipher = NULL;
  81118. STACK_OF(SSL_CIPHER) *supportedCiphers = NULL;
  81119. int i, numCiphers = 0;
  81120. SSL_CTX* ctx = NULL;
  81121. SSL* ssl = NULL;
  81122. const char* testCertFile;
  81123. const char* testKeyFile;
  81124. char buf[256] = {0};
  81125. const char* cipher_id = NULL;
  81126. int expect_nid1 = NID_undef;
  81127. int expect_nid2 = NID_undef;
  81128. int expect_nid3 = NID_undef;
  81129. int expect_nid4 = NID_undef;
  81130. int expect_nid5 = 0;
  81131. const char* cipher_id2 = NULL;
  81132. int expect_nid21 = NID_undef;
  81133. int expect_nid22 = NID_undef;
  81134. int expect_nid23 = NID_undef;
  81135. int expect_nid24 = NID_undef;
  81136. int expect_nid25 = 0;
  81137. (void)cipher;
  81138. (void)supportedCiphers;
  81139. (void)i;
  81140. (void)numCiphers;
  81141. (void)ctx;
  81142. (void)ssl;
  81143. (void)testCertFile;
  81144. (void)testKeyFile;
  81145. #if defined(WOLFSSL_TLS13)
  81146. cipher_id = "TLS13-AES128-GCM-SHA256";
  81147. expect_nid1 = NID_auth_rsa;
  81148. expect_nid2 = NID_aes_128_gcm;
  81149. expect_nid3 = NID_sha256;
  81150. expect_nid4 = NID_kx_any;
  81151. expect_nid5 = 1;
  81152. #if !defined(WOLFSSL_NO_TLS12)
  81153. cipher_id2 = "ECDHE-RSA-AES256-GCM-SHA384";
  81154. expect_nid21 = NID_auth_rsa;
  81155. expect_nid22 = NID_aes_256_gcm;
  81156. expect_nid23 = NID_sha384;
  81157. expect_nid24 = NID_kx_ecdhe;
  81158. expect_nid25 = 1;
  81159. #endif
  81160. #endif
  81161. #ifdef NO_WOLFSSL_SERVER
  81162. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_client_method()));
  81163. #else
  81164. ExpectNotNull(ctx = wolfSSL_CTX_new(wolfSSLv23_server_method()));
  81165. #endif
  81166. if (cipher_id) {
  81167. #ifndef NO_RSA
  81168. testCertFile = svrCertFile;
  81169. testKeyFile = svrKeyFile;
  81170. #elif defined(HAVE_ECC)
  81171. testCertFile = eccCertFile;
  81172. testKeyFile = eccKeyFile;
  81173. #else
  81174. testCertFile = NULL;
  81175. testKeyFile = NULL;
  81176. #endif
  81177. if (testCertFile != NULL && testKeyFile != NULL) {
  81178. ExpectTrue(SSL_CTX_use_certificate_file(ctx, testCertFile,
  81179. SSL_FILETYPE_PEM));
  81180. ExpectTrue(SSL_CTX_use_PrivateKey_file(ctx, testKeyFile,
  81181. SSL_FILETYPE_PEM));
  81182. }
  81183. ExpectNotNull(ssl = SSL_new(ctx));
  81184. ExpectIntEQ(SSL_in_init(ssl), 1);
  81185. supportedCiphers = SSL_get_ciphers(ssl);
  81186. numCiphers = sk_num(supportedCiphers);
  81187. for (i = 0; i < numCiphers; ++i) {
  81188. if ((cipher = (const WOLFSSL_CIPHER*)sk_value(supportedCiphers, i))) {
  81189. SSL_CIPHER_description(cipher, buf, sizeof(buf));
  81190. }
  81191. if (XMEMCMP(cipher_id, buf, XSTRLEN(cipher_id)) == 0) {
  81192. break;
  81193. }
  81194. }
  81195. /* test case for */
  81196. if (i != numCiphers) {
  81197. ExpectIntEQ(wolfSSL_CIPHER_get_auth_nid(cipher), expect_nid1);
  81198. ExpectIntEQ(wolfSSL_CIPHER_get_cipher_nid(cipher), expect_nid2);
  81199. ExpectIntEQ(wolfSSL_CIPHER_get_digest_nid(cipher), expect_nid3);
  81200. ExpectIntEQ(wolfSSL_CIPHER_get_kx_nid(cipher), expect_nid4);
  81201. ExpectIntEQ(wolfSSL_CIPHER_is_aead(cipher), expect_nid5);
  81202. }
  81203. if (cipher_id2) {
  81204. for (i = 0; i < numCiphers; ++i) {
  81205. if ((cipher = (const WOLFSSL_CIPHER*)sk_value(supportedCiphers, i))) {
  81206. SSL_CIPHER_description(cipher, buf, sizeof(buf));
  81207. }
  81208. if (XMEMCMP(cipher_id2, buf, XSTRLEN(cipher_id2)) == 0) {
  81209. break;
  81210. }
  81211. }
  81212. /* test case for */
  81213. if (i != numCiphers) {
  81214. ExpectIntEQ(wolfSSL_CIPHER_get_auth_nid(cipher), expect_nid21);
  81215. ExpectIntEQ(wolfSSL_CIPHER_get_cipher_nid(cipher), expect_nid22);
  81216. ExpectIntEQ(wolfSSL_CIPHER_get_digest_nid(cipher), expect_nid23);
  81217. ExpectIntEQ(wolfSSL_CIPHER_get_kx_nid(cipher), expect_nid24);
  81218. ExpectIntEQ(wolfSSL_CIPHER_is_aead(cipher), expect_nid25);
  81219. }
  81220. }
  81221. }
  81222. SSL_CTX_free(ctx);
  81223. SSL_free(ssl);
  81224. #endif
  81225. return EXPECT_RESULT();
  81226. }
  81227. #if defined(WOLF_CRYPTO_CB) && defined(HAVE_IO_TESTS_DEPENDENCIES)
  81228. static int load_pem_key_file_as_der(const char* privKeyFile, DerBuffer** pDer,
  81229. int* keyFormat)
  81230. {
  81231. int ret;
  81232. byte* key_buf = NULL;
  81233. size_t key_sz = 0;
  81234. EncryptedInfo encInfo;
  81235. XMEMSET(&encInfo, 0, sizeof(encInfo));
  81236. ret = load_file(privKeyFile, &key_buf, &key_sz);
  81237. if (ret == 0) {
  81238. ret = wc_PemToDer(key_buf, key_sz, PRIVATEKEY_TYPE, pDer,
  81239. NULL, &encInfo, keyFormat);
  81240. }
  81241. if (key_buf != NULL) {
  81242. free(key_buf); key_buf = NULL;
  81243. }
  81244. (void)encInfo; /* not used in this test */
  81245. #ifdef DEBUG_WOLFSSL
  81246. fprintf(stderr, "%s (%d): Loading PEM %s (len %d) to DER (len %d)\n",
  81247. (ret == 0) ? "Success" : "Failure", ret, privKeyFile, (int)key_sz,
  81248. (*pDer)->length);
  81249. #endif
  81250. return ret;
  81251. }
  81252. static int test_CryptoCb_Func(int thisDevId, wc_CryptoInfo* info, void* ctx)
  81253. {
  81254. int ret = WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE);
  81255. const char* privKeyFile = (const char*)ctx;
  81256. DerBuffer* pDer = NULL;
  81257. int keyFormat = 0;
  81258. if (info->algo_type == WC_ALGO_TYPE_PK) {
  81259. #ifdef DEBUG_WOLFSSL
  81260. fprintf(stderr, "test_CryptoCb_Func: Pk Type %d\n", info->pk.type);
  81261. #endif
  81262. #ifndef NO_RSA
  81263. if (info->pk.type == WC_PK_TYPE_RSA) {
  81264. switch (info->pk.rsa.type) {
  81265. case RSA_PUBLIC_ENCRYPT:
  81266. case RSA_PUBLIC_DECRYPT:
  81267. /* perform software based RSA public op */
  81268. ret = WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE); /* fallback to software */
  81269. break;
  81270. case RSA_PRIVATE_ENCRYPT:
  81271. case RSA_PRIVATE_DECRYPT:
  81272. {
  81273. RsaKey key;
  81274. /* perform software based RSA private op */
  81275. #ifdef DEBUG_WOLFSSL
  81276. fprintf(stderr, "test_CryptoCb_Func: RSA Priv\n");
  81277. #endif
  81278. ret = load_pem_key_file_as_der(privKeyFile, &pDer,
  81279. &keyFormat);
  81280. if (ret != 0) {
  81281. return ret;
  81282. }
  81283. ret = wc_InitRsaKey(&key, HEAP_HINT);
  81284. if (ret == 0) {
  81285. word32 keyIdx = 0;
  81286. /* load RSA private key and perform private transform */
  81287. ret = wc_RsaPrivateKeyDecode(pDer->buffer, &keyIdx,
  81288. &key, pDer->length);
  81289. if (ret == 0) {
  81290. ret = wc_RsaFunction(
  81291. info->pk.rsa.in, info->pk.rsa.inLen,
  81292. info->pk.rsa.out, info->pk.rsa.outLen,
  81293. info->pk.rsa.type, &key, info->pk.rsa.rng);
  81294. }
  81295. else {
  81296. /* if decode fails, then fall-back to software based crypto */
  81297. fprintf(stderr, "test_CryptoCb_Func: RSA private "
  81298. "key decode failed %d, falling back to "
  81299. "software\n", ret);
  81300. ret = CRYPTOCB_UNAVAILABLE;
  81301. }
  81302. wc_FreeRsaKey(&key);
  81303. }
  81304. wc_FreeDer(&pDer); pDer = NULL;
  81305. break;
  81306. }
  81307. }
  81308. #ifdef DEBUG_WOLFSSL
  81309. fprintf(stderr, "test_CryptoCb_Func: RSA Type %d, Ret %d, Out %d\n",
  81310. info->pk.rsa.type, ret, *info->pk.rsa.outLen);
  81311. #endif
  81312. }
  81313. #ifdef WOLF_CRYPTO_CB_RSA_PAD
  81314. else if (info->pk.type == WC_PK_TYPE_RSA_PKCS ||
  81315. info->pk.type == WC_PK_TYPE_RSA_PSS ||
  81316. info->pk.type == WC_PK_TYPE_RSA_OAEP) {
  81317. RsaKey key;
  81318. if (info->pk.rsa.type == RSA_PUBLIC_ENCRYPT ||
  81319. info->pk.rsa.type == RSA_PUBLIC_DECRYPT) {
  81320. /* Have all public key ops fall back to SW */
  81321. return CRYPTOCB_UNAVAILABLE;
  81322. }
  81323. if (info->pk.rsa.padding == NULL) {
  81324. return BAD_FUNC_ARG;
  81325. }
  81326. /* Initialize key */
  81327. ret = load_pem_key_file_as_der(privKeyFile, &pDer,
  81328. &keyFormat);
  81329. if (ret != 0) {
  81330. return ret;
  81331. }
  81332. ret = wc_InitRsaKey(&key, HEAP_HINT);
  81333. if (ret == 0) {
  81334. word32 keyIdx = 0;
  81335. /* load RSA private key and perform private transform */
  81336. ret = wc_RsaPrivateKeyDecode(pDer->buffer, &keyIdx,
  81337. &key, pDer->length);
  81338. }
  81339. /* Perform RSA operation */
  81340. if ((ret == 0) && (info->pk.type == WC_PK_TYPE_RSA_PKCS)) {
  81341. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  81342. ret = wc_RsaSSL_Sign(info->pk.rsa.in, info->pk.rsa.inLen,
  81343. info->pk.rsa.out, *info->pk.rsa.outLen, &key,
  81344. info->pk.rsa.rng);
  81345. #else
  81346. ret = CRYPTOCB_UNAVAILABLE;
  81347. #endif
  81348. }
  81349. if ((ret == 0) && (info->pk.type == WC_PK_TYPE_RSA_PSS)) {
  81350. #ifdef WC_RSA_PSS
  81351. ret = wc_RsaPSS_Sign_ex(info->pk.rsa.in, info->pk.rsa.inLen,
  81352. info->pk.rsa.out, *info->pk.rsa.outLen,
  81353. info->pk.rsa.padding->hash, info->pk.rsa.padding->mgf,
  81354. info->pk.rsa.padding->saltLen, &key, info->pk.rsa.rng);
  81355. #else
  81356. ret = CRYPTOCB_UNAVAILABLE;
  81357. #endif
  81358. }
  81359. if ((ret == 0) && (info->pk.type == WC_PK_TYPE_RSA_OAEP)) {
  81360. #if !defined(WC_NO_RSA_OAEP) || defined(WC_RSA_NO_PADDING)
  81361. ret = wc_RsaPrivateDecrypt_ex(
  81362. info->pk.rsa.in, info->pk.rsa.inLen,
  81363. info->pk.rsa.out, *info->pk.rsa.outLen,
  81364. &key, WC_RSA_OAEP_PAD, info->pk.rsa.padding->hash,
  81365. info->pk.rsa.padding->mgf, info->pk.rsa.padding->label,
  81366. info->pk.rsa.padding->labelSz);
  81367. #else
  81368. ret = CRYPTOCB_UNAVAILABLE;
  81369. #endif
  81370. }
  81371. if (ret > 0) {
  81372. *info->pk.rsa.outLen = ret;
  81373. }
  81374. wc_FreeRsaKey(&key);
  81375. wc_FreeDer(&pDer); pDer = NULL;
  81376. }
  81377. #endif /* ifdef WOLF_CRYPTO_CB_RSA_PAD */
  81378. #endif /* !NO_RSA */
  81379. #ifdef HAVE_ECC
  81380. if (info->pk.type == WC_PK_TYPE_EC_KEYGEN) {
  81381. /* mark this key as ephemeral */
  81382. if (info->pk.eckg.key != NULL) {
  81383. XSTRNCPY(info->pk.eckg.key->label, "ephemeral",
  81384. sizeof(info->pk.eckg.key->label));
  81385. info->pk.eckg.key->labelLen = (int)XSTRLEN(info->pk.eckg.key->label);
  81386. }
  81387. }
  81388. else if (info->pk.type == WC_PK_TYPE_ECDSA_SIGN) {
  81389. ecc_key key;
  81390. /* perform software based ECC sign */
  81391. #ifdef DEBUG_WOLFSSL
  81392. fprintf(stderr, "test_CryptoCb_Func: ECC Sign\n");
  81393. #endif
  81394. if (info->pk.eccsign.key != NULL &&
  81395. XSTRCMP(info->pk.eccsign.key->label, "ephemeral") == 0) {
  81396. /* this is an empheral key */
  81397. #ifdef DEBUG_WOLFSSL
  81398. fprintf(stderr, "test_CryptoCb_Func: skipping signing op on "
  81399. "ephemeral key\n");
  81400. #endif
  81401. return CRYPTOCB_UNAVAILABLE;
  81402. }
  81403. ret = load_pem_key_file_as_der(privKeyFile, &pDer, &keyFormat);
  81404. if (ret != 0) {
  81405. return ret;
  81406. }
  81407. ret = wc_ecc_init(&key);
  81408. if (ret == 0) {
  81409. word32 keyIdx = 0;
  81410. /* load ECC private key and perform private transform */
  81411. ret = wc_EccPrivateKeyDecode(pDer->buffer, &keyIdx,
  81412. &key, pDer->length);
  81413. if (ret == 0) {
  81414. ret = wc_ecc_sign_hash(
  81415. info->pk.eccsign.in, info->pk.eccsign.inlen,
  81416. info->pk.eccsign.out, info->pk.eccsign.outlen,
  81417. info->pk.eccsign.rng, &key);
  81418. }
  81419. else {
  81420. /* if decode fails, then fall-back to software based crypto */
  81421. fprintf(stderr, "test_CryptoCb_Func: ECC private key "
  81422. "decode failed %d, falling back to software\n", ret);
  81423. ret = CRYPTOCB_UNAVAILABLE;
  81424. }
  81425. wc_ecc_free(&key);
  81426. }
  81427. wc_FreeDer(&pDer); pDer = NULL;
  81428. #ifdef DEBUG_WOLFSSL
  81429. fprintf(stderr, "test_CryptoCb_Func: ECC Ret %d, Out %d\n",
  81430. ret, *info->pk.eccsign.outlen);
  81431. #endif
  81432. }
  81433. #endif /* HAVE_ECC */
  81434. #ifdef HAVE_ED25519
  81435. if (info->pk.type == WC_PK_TYPE_ED25519_SIGN) {
  81436. ed25519_key key;
  81437. /* perform software based ED25519 sign */
  81438. #ifdef DEBUG_WOLFSSL
  81439. fprintf(stderr, "test_CryptoCb_Func: ED25519 Sign\n");
  81440. #endif
  81441. ret = load_pem_key_file_as_der(privKeyFile, &pDer, &keyFormat);
  81442. if (ret != 0) {
  81443. return ret;
  81444. }
  81445. ret = wc_ed25519_init(&key);
  81446. if (ret == 0) {
  81447. word32 keyIdx = 0;
  81448. /* load ED25519 private key and perform private transform */
  81449. ret = wc_Ed25519PrivateKeyDecode(pDer->buffer, &keyIdx,
  81450. &key, pDer->length);
  81451. if (ret == 0) {
  81452. /* calculate public key */
  81453. ret = wc_ed25519_make_public(&key, key.p, ED25519_PUB_KEY_SIZE);
  81454. if (ret == 0) {
  81455. key.pubKeySet = 1;
  81456. ret = wc_ed25519_sign_msg_ex(
  81457. info->pk.ed25519sign.in, info->pk.ed25519sign.inLen,
  81458. info->pk.ed25519sign.out, info->pk.ed25519sign.outLen,
  81459. &key, info->pk.ed25519sign.type,
  81460. info->pk.ed25519sign.context,
  81461. info->pk.ed25519sign.contextLen);
  81462. }
  81463. }
  81464. else {
  81465. /* if decode fails, then fall-back to software based crypto */
  81466. fprintf(stderr, "test_CryptoCb_Func: ED25519 private key "
  81467. "decode failed %d, falling back to software\n", ret);
  81468. ret = CRYPTOCB_UNAVAILABLE;
  81469. }
  81470. wc_ed25519_free(&key);
  81471. }
  81472. wc_FreeDer(&pDer); pDer = NULL;
  81473. #ifdef DEBUG_WOLFSSL
  81474. fprintf(stderr, "test_CryptoCb_Func: ED25519 Ret %d, Out %d\n",
  81475. ret, *info->pk.ed25519sign.outLen);
  81476. #endif
  81477. }
  81478. #endif /* HAVE_ED25519 */
  81479. }
  81480. (void)thisDevId;
  81481. (void)keyFormat;
  81482. return ret;
  81483. }
  81484. /* tlsVer: WOLFSSL_TLSV1_2 or WOLFSSL_TLSV1_3 */
  81485. static int test_wc_CryptoCb_TLS(int tlsVer,
  81486. const char* cliCaPemFile, const char* cliCertPemFile,
  81487. const char* cliPrivKeyPemFile, const char* cliPubKeyPemFile,
  81488. const char* svrCaPemFile, const char* svrCertPemFile,
  81489. const char* svrPrivKeyPemFile, const char* svrPubKeyPemFile)
  81490. {
  81491. EXPECT_DECLS;
  81492. callback_functions client_cbf;
  81493. callback_functions server_cbf;
  81494. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  81495. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  81496. if (tlsVer == WOLFSSL_TLSV1_3) {
  81497. #ifdef WOLFSSL_TLS13
  81498. server_cbf.method = wolfTLSv1_3_server_method;
  81499. client_cbf.method = wolfTLSv1_3_client_method;
  81500. #endif
  81501. }
  81502. else if (tlsVer == WOLFSSL_TLSV1_2) {
  81503. #ifndef WOLFSSL_NO_TLS12
  81504. server_cbf.method = wolfTLSv1_2_server_method;
  81505. client_cbf.method = wolfTLSv1_2_client_method;
  81506. #endif
  81507. }
  81508. else if (tlsVer == WOLFSSL_TLSV1_1) {
  81509. #ifndef NO_OLD_TLS
  81510. server_cbf.method = wolfTLSv1_1_server_method;
  81511. client_cbf.method = wolfTLSv1_1_client_method;
  81512. #endif
  81513. }
  81514. else if (tlsVer == WOLFSSL_TLSV1) {
  81515. #if !defined(NO_OLD_TLS) && defined(WOLFSSL_ALLOW_TLSV10)
  81516. server_cbf.method = wolfTLSv1_server_method;
  81517. client_cbf.method = wolfTLSv1_client_method;
  81518. #endif
  81519. }
  81520. else if (tlsVer == WOLFSSL_SSLV3) {
  81521. #if !defined(NO_OLD_TLS) && defined(WOLFSSL_ALLOW_SSLV3) && \
  81522. defined(WOLFSSL_STATIC_RSA)
  81523. server_cbf.method = wolfSSLv3_server_method;
  81524. client_cbf.method = wolfSSLv3_client_method;
  81525. #endif
  81526. }
  81527. else if (tlsVer == WOLFSSL_DTLSV1_2) {
  81528. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12)
  81529. server_cbf.method = wolfDTLSv1_2_server_method;
  81530. client_cbf.method = wolfDTLSv1_2_client_method;
  81531. #endif
  81532. }
  81533. else if (tlsVer == WOLFSSL_DTLSV1) {
  81534. #if defined(WOLFSSL_DTLS) && !defined(NO_OLD_TLS)
  81535. server_cbf.method = wolfDTLSv1_server_method;
  81536. client_cbf.method = wolfDTLSv1_client_method;
  81537. #endif
  81538. }
  81539. if (server_cbf.method == NULL) {
  81540. /* not enabled */
  81541. return TEST_SUCCESS;
  81542. }
  81543. /* Setup the keys for the TLS test */
  81544. client_cbf.certPemFile = cliCertPemFile;
  81545. client_cbf.keyPemFile = cliPubKeyPemFile;
  81546. client_cbf.caPemFile = cliCaPemFile;
  81547. server_cbf.certPemFile = svrCertPemFile;
  81548. server_cbf.keyPemFile = svrPubKeyPemFile;
  81549. server_cbf.caPemFile = svrCaPemFile;
  81550. /* Setup a crypto callback with pointer to private key file for testing */
  81551. client_cbf.devId = 1;
  81552. wc_CryptoCb_RegisterDevice(client_cbf.devId, test_CryptoCb_Func,
  81553. (void*)cliPrivKeyPemFile);
  81554. server_cbf.devId = 2;
  81555. wc_CryptoCb_RegisterDevice(server_cbf.devId, test_CryptoCb_Func,
  81556. (void*)svrPrivKeyPemFile);
  81557. /* Perform TLS server and client test */
  81558. /* First test is at WOLFSSL_CTX level */
  81559. test_wolfSSL_client_server(&client_cbf, &server_cbf);
  81560. /* Check for success */
  81561. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  81562. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  81563. if (EXPECT_SUCCESS()) {
  81564. /* Second test is a WOLFSSL object level */
  81565. client_cbf.loadToSSL = 1; server_cbf.loadToSSL = 1;
  81566. test_wolfSSL_client_server(&client_cbf, &server_cbf);
  81567. }
  81568. /* Check for success */
  81569. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  81570. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  81571. /* Un register the devId's */
  81572. wc_CryptoCb_UnRegisterDevice(client_cbf.devId);
  81573. client_cbf.devId = INVALID_DEVID;
  81574. wc_CryptoCb_UnRegisterDevice(server_cbf.devId);
  81575. server_cbf.devId = INVALID_DEVID;
  81576. return EXPECT_RESULT();
  81577. }
  81578. #endif /* WOLF_CRYPTO_CB && HAVE_IO_TESTS_DEPENDENCIES */
  81579. static int test_wc_CryptoCb(void)
  81580. {
  81581. EXPECT_DECLS;
  81582. #ifdef WOLF_CRYPTO_CB
  81583. /* TODO: Add crypto callback API tests */
  81584. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  81585. #if !defined(NO_RSA) || defined(HAVE_ECC) || defined(HAVE_ED25519)
  81586. int tlsVer;
  81587. #endif
  81588. #ifndef NO_RSA
  81589. for (tlsVer = WOLFSSL_SSLV3; tlsVer <= WOLFSSL_DTLSV1; tlsVer++) {
  81590. ExpectIntEQ(test_wc_CryptoCb_TLS(tlsVer,
  81591. svrCertFile, cliCertFile, cliKeyFile, cliKeyPubFile,
  81592. cliCertFile, svrCertFile, svrKeyFile, svrKeyPubFile),
  81593. TEST_SUCCESS);
  81594. }
  81595. #endif
  81596. #ifdef HAVE_ECC
  81597. for (tlsVer = WOLFSSL_TLSV1; tlsVer <= WOLFSSL_DTLSV1; tlsVer++) {
  81598. ExpectIntEQ(test_wc_CryptoCb_TLS(tlsVer,
  81599. caEccCertFile, cliEccCertFile, cliEccKeyFile, cliEccKeyPubFile,
  81600. cliEccCertFile, eccCertFile, eccKeyFile, eccKeyPubFile),
  81601. TEST_SUCCESS);
  81602. }
  81603. #endif
  81604. #ifdef HAVE_ED25519
  81605. for (tlsVer = WOLFSSL_TLSV1_2; tlsVer <= WOLFSSL_DTLSV1_2; tlsVer++) {
  81606. if (tlsVer == WOLFSSL_DTLSV1) continue;
  81607. ExpectIntEQ(test_wc_CryptoCb_TLS(tlsVer,
  81608. caEdCertFile, cliEdCertFile, cliEdKeyFile, cliEdKeyPubFile,
  81609. cliEdCertFile, edCertFile, edKeyFile, edKeyPubFile),
  81610. TEST_SUCCESS);
  81611. }
  81612. #endif
  81613. #endif /* HAVE_IO_TESTS_DEPENDENCIES */
  81614. #endif /* WOLF_CRYPTO_CB */
  81615. return EXPECT_RESULT();
  81616. }
  81617. #if defined(WOLFSSL_STATIC_MEMORY) && defined(HAVE_IO_TESTS_DEPENDENCIES)
  81618. /* tlsVer: Example: WOLFSSL_TLSV1_2 or WOLFSSL_TLSV1_3 */
  81619. static int test_wolfSSL_CTX_StaticMemory_TLS(int tlsVer,
  81620. const char* cliCaPemFile, const char* cliCertPemFile,
  81621. const char* cliPrivKeyPemFile,
  81622. const char* svrCaPemFile, const char* svrCertPemFile,
  81623. const char* svrPrivKeyPemFile,
  81624. byte* cliMem, word32 cliMemSz, byte* svrMem, word32 svrMemSz)
  81625. {
  81626. EXPECT_DECLS;
  81627. callback_functions client_cbf;
  81628. callback_functions server_cbf;
  81629. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  81630. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  81631. if (tlsVer == WOLFSSL_TLSV1_3) {
  81632. #ifdef WOLFSSL_TLS13
  81633. server_cbf.method_ex = wolfTLSv1_3_server_method_ex;
  81634. client_cbf.method_ex = wolfTLSv1_3_client_method_ex;
  81635. #endif
  81636. }
  81637. else if (tlsVer == WOLFSSL_TLSV1_2) {
  81638. #ifndef WOLFSSL_NO_TLS12
  81639. server_cbf.method_ex = wolfTLSv1_2_server_method_ex;
  81640. client_cbf.method_ex = wolfTLSv1_2_client_method_ex;
  81641. #endif
  81642. }
  81643. else if (tlsVer == WOLFSSL_TLSV1_1) {
  81644. #ifndef NO_OLD_TLS
  81645. server_cbf.method_ex = wolfTLSv1_1_server_method_ex;
  81646. client_cbf.method_ex = wolfTLSv1_1_client_method_ex;
  81647. #endif
  81648. }
  81649. else if (tlsVer == WOLFSSL_TLSV1) {
  81650. #if !defined(NO_OLD_TLS) && defined(WOLFSSL_ALLOW_TLSV10)
  81651. server_cbf.method_ex = wolfTLSv1_server_method_ex;
  81652. client_cbf.method_ex = wolfTLSv1_client_method_ex;
  81653. #endif
  81654. }
  81655. else if (tlsVer == WOLFSSL_SSLV3) {
  81656. #if !defined(NO_OLD_TLS) && defined(WOLFSSL_ALLOW_SSLV3) && \
  81657. defined(WOLFSSL_STATIC_RSA)
  81658. server_cbf.method_ex = wolfSSLv3_server_method_ex;
  81659. client_cbf.method_ex = wolfSSLv3_client_method_ex;
  81660. #endif
  81661. }
  81662. else if (tlsVer == WOLFSSL_DTLSV1_2) {
  81663. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12)
  81664. server_cbf.method_ex = wolfDTLSv1_2_server_method_ex;
  81665. client_cbf.method_ex = wolfDTLSv1_2_client_method_ex;
  81666. #endif
  81667. }
  81668. else if (tlsVer == WOLFSSL_DTLSV1) {
  81669. #if defined(WOLFSSL_DTLS) && !defined(NO_OLD_TLS)
  81670. server_cbf.method_ex = wolfDTLSv1_server_method_ex;
  81671. client_cbf.method_ex = wolfDTLSv1_client_method_ex;
  81672. #endif
  81673. }
  81674. if (server_cbf.method_ex == NULL) {
  81675. /* not enabled */
  81676. return TEST_SUCCESS;
  81677. }
  81678. /* Setup the keys for the TLS test */
  81679. client_cbf.certPemFile = cliCertPemFile;
  81680. client_cbf.keyPemFile = cliPrivKeyPemFile;
  81681. client_cbf.caPemFile = cliCaPemFile;
  81682. server_cbf.certPemFile = svrCertPemFile;
  81683. server_cbf.keyPemFile = svrPrivKeyPemFile;
  81684. server_cbf.caPemFile = svrCaPemFile;
  81685. client_cbf.mem = cliMem;
  81686. client_cbf.memSz = cliMemSz;
  81687. server_cbf.mem = svrMem;
  81688. server_cbf.memSz = svrMemSz;
  81689. client_cbf.devId = INVALID_DEVID;
  81690. server_cbf.devId = INVALID_DEVID;
  81691. /* Perform TLS server and client test */
  81692. /* First test is at WOLFSSL_CTX level */
  81693. test_wolfSSL_client_server(&client_cbf, &server_cbf);
  81694. /* Check for success */
  81695. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  81696. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  81697. if (EXPECT_SUCCESS()) {
  81698. /* Second test is a WOLFSSL object level */
  81699. client_cbf.loadToSSL = 1; server_cbf.loadToSSL = 1;
  81700. test_wolfSSL_client_server(&client_cbf, &server_cbf);
  81701. }
  81702. /* Check for success */
  81703. ExpectIntEQ(server_cbf.return_code, TEST_SUCCESS);
  81704. ExpectIntEQ(client_cbf.return_code, TEST_SUCCESS);
  81705. return EXPECT_RESULT();
  81706. }
  81707. #endif /* WOLFSSL_STATIC_MEMORY && HAVE_IO_TESTS_DEPENDENCIES */
  81708. #if defined(WOLFSSL_STATIC_MEMORY) && !defined(WOLFCRYPT_ONLY)
  81709. static int test_wolfSSL_CTX_StaticMemory_SSL(WOLFSSL_CTX* ctx)
  81710. {
  81711. EXPECT_DECLS;
  81712. WOLFSSL *ssl1 = NULL, *ssl2 = NULL, *ssl3 = NULL;
  81713. WOLFSSL_MEM_STATS mem_stats;
  81714. WOLFSSL_MEM_CONN_STATS ssl_stats;
  81715. #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA)
  81716. ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx, svrCertFile,
  81717. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  81718. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx, svrKeyFile,
  81719. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  81720. #endif
  81721. ExpectNotNull((ssl1 = wolfSSL_new(ctx)));
  81722. ExpectNotNull((ssl2 = wolfSSL_new(ctx)));
  81723. #ifndef WOLFSSL_STATIC_MEMORY_LEAN
  81724. /* this should fail because kMaxCtxClients == 2 */
  81725. ExpectNull((ssl3 = wolfSSL_new(ctx)));
  81726. #else
  81727. (void)ssl3;
  81728. #endif
  81729. if (wolfSSL_is_static_memory(ssl1, &ssl_stats) == 1) {
  81730. #if defined(DEBUG_WOLFSSL) && !defined(WOLFSSL_STATIC_MEMORY_LEAN)
  81731. wolfSSL_PrintStatsConn(&ssl_stats);
  81732. #endif
  81733. (void)ssl_stats;
  81734. }
  81735. /* display collected statistics */
  81736. if (wolfSSL_CTX_is_static_memory(ctx, &mem_stats) == 1) {
  81737. #if defined(DEBUG_WOLFSSL) && !defined(WOLFSSL_STATIC_MEMORY_LEAN)
  81738. wolfSSL_PrintStats(&mem_stats);
  81739. #endif
  81740. (void)mem_stats;
  81741. }
  81742. wolfSSL_free(ssl1);
  81743. wolfSSL_free(ssl2);
  81744. return EXPECT_RESULT();
  81745. }
  81746. #endif /* WOLFSSL_STATIC_MEMORY && !WOLFCRYPT_ONLY */
  81747. static int test_wolfSSL_CTX_StaticMemory(void)
  81748. {
  81749. EXPECT_DECLS;
  81750. #if defined(WOLFSSL_STATIC_MEMORY) && !defined(WOLFCRYPT_ONLY)
  81751. wolfSSL_method_func method_func;
  81752. WOLFSSL_CTX* ctx;
  81753. const int kMaxCtxClients = 2;
  81754. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  81755. #if !defined(NO_RSA) || defined(HAVE_ECC) || defined(HAVE_ED25519)
  81756. int tlsVer;
  81757. byte cliMem[TEST_TLS_STATIC_MEMSZ];
  81758. #endif
  81759. #endif
  81760. byte svrMem[TEST_TLS_STATIC_MEMSZ];
  81761. #ifndef NO_WOLFSSL_SERVER
  81762. #ifndef WOLFSSL_NO_TLS12
  81763. method_func = wolfTLSv1_2_server_method_ex;
  81764. #else
  81765. method_func = wolfTLSv1_3_server_method_ex;
  81766. #endif
  81767. #else
  81768. #ifndef WOLFSSL_NO_TLS12
  81769. method_func = wolfTLSv1_2_client_method_ex;
  81770. #else
  81771. method_func = wolfTLSv1_3_client_method_ex;
  81772. #endif
  81773. #endif
  81774. /* Test creating CTX directly from static memory pool */
  81775. ctx = NULL;
  81776. ExpectIntEQ(wolfSSL_CTX_load_static_memory(&ctx, method_func, svrMem,
  81777. sizeof(svrMem), 0, kMaxCtxClients), WOLFSSL_SUCCESS);
  81778. ExpectIntEQ(test_wolfSSL_CTX_StaticMemory_SSL(ctx), TEST_SUCCESS);
  81779. wolfSSL_CTX_free(ctx);
  81780. ctx = NULL;
  81781. /* Test for heap allocated CTX, then assigning static pool to it */
  81782. ExpectNotNull(ctx = wolfSSL_CTX_new(method_func(NULL)));
  81783. ExpectIntEQ(wolfSSL_CTX_load_static_memory(&ctx, NULL, svrMem,
  81784. sizeof(svrMem), 0, kMaxCtxClients), WOLFSSL_SUCCESS);
  81785. ExpectIntEQ(test_wolfSSL_CTX_StaticMemory_SSL(ctx), TEST_SUCCESS);
  81786. wolfSSL_CTX_free(ctx);
  81787. /* TLS Level Tests using static memory */
  81788. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  81789. #ifndef NO_RSA
  81790. for (tlsVer = WOLFSSL_SSLV3; tlsVer <= WOLFSSL_DTLSV1; tlsVer++) {
  81791. ExpectIntEQ(test_wolfSSL_CTX_StaticMemory_TLS(tlsVer,
  81792. svrCertFile, cliCertFile, cliKeyFile,
  81793. cliCertFile, svrCertFile, svrKeyFile,
  81794. cliMem, (word32)sizeof(cliMem), svrMem, (word32)sizeof(svrMem)),
  81795. TEST_SUCCESS);
  81796. }
  81797. #endif
  81798. #ifdef HAVE_ECC
  81799. for (tlsVer = WOLFSSL_TLSV1; tlsVer <= WOLFSSL_DTLSV1; tlsVer++) {
  81800. ExpectIntEQ(test_wolfSSL_CTX_StaticMemory_TLS(tlsVer,
  81801. caEccCertFile, cliEccCertFile, cliEccKeyFile,
  81802. cliEccCertFile, eccCertFile, eccKeyFile,
  81803. cliMem, (word32)sizeof(cliMem), svrMem, (word32)sizeof(svrMem)),
  81804. TEST_SUCCESS);
  81805. }
  81806. #endif
  81807. #ifdef HAVE_ED25519
  81808. for (tlsVer = WOLFSSL_TLSV1_2; tlsVer <= WOLFSSL_DTLSV1_2; tlsVer++) {
  81809. if (tlsVer == WOLFSSL_DTLSV1) continue;
  81810. ExpectIntEQ(test_wolfSSL_CTX_StaticMemory_TLS(tlsVer,
  81811. caEdCertFile, cliEdCertFile, cliEdKeyFile,
  81812. cliEdCertFile, edCertFile, edKeyFile,
  81813. cliMem, (word32)sizeof(cliMem), svrMem, (word32)sizeof(svrMem)),
  81814. TEST_SUCCESS);
  81815. }
  81816. #endif
  81817. #endif /* HAVE_IO_TESTS_DEPENDENCIES */
  81818. #endif /* WOLFSSL_STATIC_MEMORY && !WOLFCRYPT_ONLY */
  81819. return EXPECT_RESULT();
  81820. }
  81821. static int test_openssl_FIPS_drbg(void)
  81822. {
  81823. EXPECT_DECLS;
  81824. #if defined(OPENSSL_EXTRA) && !defined(WC_NO_RNG) && defined(HAVE_HASHDRBG)
  81825. DRBG_CTX* dctx = NULL;
  81826. byte data1[32], data2[32], zeroData[32];
  81827. byte testSeed[16];
  81828. size_t dlen = sizeof(data1);
  81829. int i;
  81830. XMEMSET(data1, 0, dlen);
  81831. XMEMSET(data2, 0, dlen);
  81832. XMEMSET(zeroData, 0, sizeof(zeroData));
  81833. for (i = 0; i < (int)sizeof(testSeed); i++) {
  81834. testSeed[i] = (byte)i;
  81835. }
  81836. ExpectNotNull(dctx = FIPS_get_default_drbg());
  81837. ExpectIntEQ(FIPS_drbg_init(dctx, 0, 0), WOLFSSL_SUCCESS);
  81838. ExpectIntEQ(FIPS_drbg_set_callbacks(dctx, NULL, NULL, 20, NULL, NULL),
  81839. WOLFSSL_SUCCESS);
  81840. ExpectIntEQ(FIPS_drbg_instantiate(dctx, NULL, 0), WOLFSSL_SUCCESS);
  81841. ExpectIntEQ(FIPS_drbg_generate(dctx, data1, dlen, 0, NULL, 0),
  81842. WOLFSSL_SUCCESS);
  81843. ExpectIntNE(XMEMCMP(data1, zeroData, dlen), 0);
  81844. ExpectIntEQ(FIPS_drbg_reseed(dctx, testSeed, sizeof(testSeed)),
  81845. WOLFSSL_SUCCESS);
  81846. ExpectIntEQ(FIPS_drbg_generate(dctx, data2, dlen, 0, NULL, 0),
  81847. WOLFSSL_SUCCESS);
  81848. ExpectIntNE(XMEMCMP(data1, zeroData, dlen), 0);
  81849. ExpectIntNE(XMEMCMP(data1, data2, dlen), 0);
  81850. ExpectIntEQ(FIPS_drbg_uninstantiate(dctx), WOLFSSL_SUCCESS);
  81851. #ifndef HAVE_GLOBAL_RNG
  81852. /* gets freed by wolfSSL_Cleanup() when HAVE_GLOBAL_RNG defined */
  81853. wolfSSL_FIPS_drbg_free(dctx);
  81854. #endif
  81855. #endif
  81856. return EXPECT_RESULT();
  81857. }
  81858. static int test_wolfSSL_FIPS_mode(void)
  81859. {
  81860. EXPECT_DECLS;
  81861. #if defined(OPENSSL_ALL)
  81862. #ifdef HAVE_FIPS
  81863. ExpectIntEQ(wolfSSL_FIPS_mode(), 1);
  81864. ExpectIntEQ(wolfSSL_FIPS_mode_set(0), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  81865. ExpectIntEQ(wolfSSL_FIPS_mode_set(1), WOLFSSL_SUCCESS);
  81866. #else
  81867. ExpectIntEQ(wolfSSL_FIPS_mode(), 0);
  81868. ExpectIntEQ(wolfSSL_FIPS_mode_set(0), WOLFSSL_SUCCESS);
  81869. ExpectIntEQ(wolfSSL_FIPS_mode_set(1), WC_NO_ERR_TRACE(WOLFSSL_FAILURE));
  81870. #endif
  81871. #endif
  81872. return EXPECT_RESULT();
  81873. }
  81874. #ifdef WOLFSSL_DTLS
  81875. /* Prints out the current window */
  81876. static void DUW_TEST_print_window_binary(word32 h, word32 l, word32* w) {
  81877. #ifdef WOLFSSL_DEBUG_DTLS_WINDOW
  81878. int i;
  81879. for (i = WOLFSSL_DTLS_WINDOW_WORDS - 1; i >= 0; i--) {
  81880. word32 b = w[i];
  81881. int j;
  81882. /* Prints out a 32 bit binary number in big endian order */
  81883. for (j = 0; j < 32; j++, b <<= 1) {
  81884. if (b & (((word32)1) << 31))
  81885. fprintf(stderr, "1");
  81886. else
  81887. fprintf(stderr, "0");
  81888. }
  81889. fprintf(stderr, " ");
  81890. }
  81891. fprintf(stderr, "cur_hi %u cur_lo %u\n", h, l);
  81892. #else
  81893. (void)h;
  81894. (void)l;
  81895. (void)w;
  81896. #endif
  81897. }
  81898. /* a - cur_hi
  81899. * b - cur_lo
  81900. * c - next_hi
  81901. * d - next_lo
  81902. * e - window
  81903. * f - expected next_hi
  81904. * g - expected next_lo
  81905. * h - expected window[1]
  81906. * i - expected window[0]
  81907. */
  81908. #define DUW_TEST(a,b,c,d,e,f,g,h,i) do { \
  81909. ExpectIntEQ(wolfSSL_DtlsUpdateWindow((a), (b), &(c), &(d), (e)), 1); \
  81910. DUW_TEST_print_window_binary((a), (b), (e)); \
  81911. ExpectIntEQ((c), (f)); \
  81912. ExpectIntEQ((d), (g)); \
  81913. ExpectIntEQ((e)[1], (h)); \
  81914. ExpectIntEQ((e)[0], (i)); \
  81915. } while (0)
  81916. static int test_wolfSSL_DtlsUpdateWindow(void)
  81917. {
  81918. EXPECT_DECLS;
  81919. word32 window[WOLFSSL_DTLS_WINDOW_WORDS];
  81920. word32 next_lo = 0;
  81921. word16 next_hi = 0;
  81922. #ifdef WOLFSSL_DEBUG_DTLS_WINDOW
  81923. fprintf(stderr, "\n");
  81924. #endif
  81925. XMEMSET(window, 0, sizeof window);
  81926. DUW_TEST(0, 0, next_hi, next_lo, window, 0, 1, 0, 0x01);
  81927. DUW_TEST(0, 1, next_hi, next_lo, window, 0, 2, 0, 0x03);
  81928. DUW_TEST(0, 5, next_hi, next_lo, window, 0, 6, 0, 0x31);
  81929. DUW_TEST(0, 4, next_hi, next_lo, window, 0, 6, 0, 0x33);
  81930. DUW_TEST(0, 100, next_hi, next_lo, window, 0, 101, 0, 0x01);
  81931. DUW_TEST(0, 101, next_hi, next_lo, window, 0, 102, 0, 0x03);
  81932. DUW_TEST(0, 133, next_hi, next_lo, window, 0, 134, 0x03, 0x01);
  81933. DUW_TEST(0, 200, next_hi, next_lo, window, 0, 201, 0, 0x01);
  81934. DUW_TEST(0, 264, next_hi, next_lo, window, 0, 265, 0, 0x01);
  81935. DUW_TEST(0, 0xFFFFFFFF, next_hi, next_lo, window, 1, 0, 0, 0x01);
  81936. DUW_TEST(0, 0xFFFFFFFD, next_hi, next_lo, window, 1, 0, 0, 0x05);
  81937. DUW_TEST(0, 0xFFFFFFFE, next_hi, next_lo, window, 1, 0, 0, 0x07);
  81938. DUW_TEST(1, 3, next_hi, next_lo, window, 1, 4, 0, 0x71);
  81939. DUW_TEST(1, 0, next_hi, next_lo, window, 1, 4, 0, 0x79);
  81940. DUW_TEST(1, 0xFFFFFFFF, next_hi, next_lo, window, 2, 0, 0, 0x01);
  81941. DUW_TEST(2, 3, next_hi, next_lo, window, 2, 4, 0, 0x11);
  81942. DUW_TEST(2, 0, next_hi, next_lo, window, 2, 4, 0, 0x19);
  81943. DUW_TEST(2, 25, next_hi, next_lo, window, 2, 26, 0, 0x6400001);
  81944. DUW_TEST(2, 27, next_hi, next_lo, window, 2, 28, 0, 0x19000005);
  81945. DUW_TEST(2, 29, next_hi, next_lo, window, 2, 30, 0, 0x64000015);
  81946. DUW_TEST(2, 33, next_hi, next_lo, window, 2, 34, 6, 0x40000151);
  81947. DUW_TEST(2, 60, next_hi, next_lo, window, 2, 61, 0x3200000A, 0x88000001);
  81948. DUW_TEST(1, 0xFFFFFFF0, next_hi, next_lo, window, 2, 61, 0x3200000A, 0x88000001);
  81949. DUW_TEST(2, 0xFFFFFFFD, next_hi, next_lo, window, 2, 0xFFFFFFFE, 0, 0x01);
  81950. DUW_TEST(3, 1, next_hi, next_lo, window, 3, 2, 0, 0x11);
  81951. DUW_TEST(99, 66, next_hi, next_lo, window, 99, 67, 0, 0x01);
  81952. DUW_TEST(50, 66, next_hi, next_lo, window, 99, 67, 0, 0x01);
  81953. DUW_TEST(100, 68, next_hi, next_lo, window, 100, 69, 0, 0x01);
  81954. DUW_TEST(99, 50, next_hi, next_lo, window, 100, 69, 0, 0x01);
  81955. DUW_TEST(99, 0xFFFFFFFF, next_hi, next_lo, window, 100, 69, 0, 0x01);
  81956. DUW_TEST(150, 0xFFFFFFFF, next_hi, next_lo, window, 151, 0, 0, 0x01);
  81957. DUW_TEST(152, 0xFFFFFFFF, next_hi, next_lo, window, 153, 0, 0, 0x01);
  81958. return EXPECT_RESULT();
  81959. }
  81960. #endif /* WOLFSSL_DTLS */
  81961. #ifdef WOLFSSL_DTLS
  81962. static int DFB_TEST(WOLFSSL* ssl, word32 seq, word32 len, word32 f_offset,
  81963. word32 f_len, word32 f_count, byte ready, word32 bytesReceived)
  81964. {
  81965. DtlsMsg* cur;
  81966. static byte msg[100];
  81967. static byte msgInit = 0;
  81968. if (!msgInit) {
  81969. int i;
  81970. for (i = 0; i < 100; i++)
  81971. msg[i] = i + 1;
  81972. msgInit = 1;
  81973. }
  81974. /* Sanitize test parameters */
  81975. if (len > sizeof(msg))
  81976. return -1;
  81977. if (f_offset + f_len > sizeof(msg))
  81978. return -1;
  81979. DtlsMsgStore(ssl, 0, seq, msg + f_offset, len, certificate, f_offset, f_len, NULL);
  81980. if (ssl->dtls_rx_msg_list == NULL)
  81981. return -100;
  81982. if ((cur = DtlsMsgFind(ssl->dtls_rx_msg_list, 0, seq)) == NULL)
  81983. return -200;
  81984. if (cur->fragBucketListCount != f_count)
  81985. return -300;
  81986. if (cur->ready != ready)
  81987. return -400;
  81988. if (cur->bytesReceived != bytesReceived)
  81989. return -500;
  81990. if (ready) {
  81991. if (cur->fragBucketList != NULL)
  81992. return -600;
  81993. if (XMEMCMP(cur->fullMsg, msg, cur->sz) != 0)
  81994. return -700;
  81995. }
  81996. else {
  81997. DtlsFragBucket* fb;
  81998. if (cur->fragBucketList == NULL)
  81999. return -800;
  82000. for (fb = cur->fragBucketList; fb != NULL; fb = fb->m.m.next) {
  82001. if (XMEMCMP(fb->buf, msg + fb->m.m.offset, fb->m.m.sz) != 0)
  82002. return -900;
  82003. }
  82004. }
  82005. return 0;
  82006. }
  82007. static int test_wolfSSL_DTLS_fragment_buckets(void)
  82008. {
  82009. EXPECT_DECLS;
  82010. WOLFSSL ssl[1];
  82011. XMEMSET(ssl, 0, sizeof(*ssl));
  82012. ExpectIntEQ(DFB_TEST(ssl, 0, 100, 0, 100, 0, 1, 100), 0); /* 0-100 */
  82013. ExpectIntEQ(DFB_TEST(ssl, 1, 100, 0, 20, 1, 0, 20), 0); /* 0-20 */
  82014. ExpectIntEQ(DFB_TEST(ssl, 1, 100, 20, 20, 1, 0, 40), 0); /* 20-40 */
  82015. ExpectIntEQ(DFB_TEST(ssl, 1, 100, 40, 20, 1, 0, 60), 0); /* 40-60 */
  82016. ExpectIntEQ(DFB_TEST(ssl, 1, 100, 60, 20, 1, 0, 80), 0); /* 60-80 */
  82017. ExpectIntEQ(DFB_TEST(ssl, 1, 100, 80, 20, 0, 1, 100), 0); /* 80-100 */
  82018. /* Test all permutations of 3 regions */
  82019. /* 1 2 3 */
  82020. ExpectIntEQ(DFB_TEST(ssl, 2, 100, 0, 30, 1, 0, 30), 0); /* 0-30 */
  82021. ExpectIntEQ(DFB_TEST(ssl, 2, 100, 30, 30, 1, 0, 60), 0); /* 30-60 */
  82022. ExpectIntEQ(DFB_TEST(ssl, 2, 100, 60, 40, 0, 1, 100), 0); /* 60-100 */
  82023. /* 1 3 2 */
  82024. ExpectIntEQ(DFB_TEST(ssl, 3, 100, 0, 30, 1, 0, 30), 0); /* 0-30 */
  82025. ExpectIntEQ(DFB_TEST(ssl, 3, 100, 60, 40, 2, 0, 70), 0); /* 60-100 */
  82026. ExpectIntEQ(DFB_TEST(ssl, 3, 100, 30, 30, 0, 1, 100), 0); /* 30-60 */
  82027. /* 2 1 3 */
  82028. ExpectIntEQ(DFB_TEST(ssl, 4, 100, 30, 30, 1, 0, 30), 0); /* 30-60 */
  82029. ExpectIntEQ(DFB_TEST(ssl, 4, 100, 0, 30, 1, 0, 60), 0); /* 0-30 */
  82030. ExpectIntEQ(DFB_TEST(ssl, 4, 100, 60, 40, 0, 1, 100), 0); /* 60-100 */
  82031. /* 2 3 1 */
  82032. ExpectIntEQ(DFB_TEST(ssl, 5, 100, 30, 30, 1, 0, 30), 0); /* 30-60 */
  82033. ExpectIntEQ(DFB_TEST(ssl, 5, 100, 60, 40, 1, 0, 70), 0); /* 60-100 */
  82034. ExpectIntEQ(DFB_TEST(ssl, 5, 100, 0, 30, 0, 1, 100), 0); /* 0-30 */
  82035. /* 3 1 2 */
  82036. ExpectIntEQ(DFB_TEST(ssl, 6, 100, 60, 40, 1, 0, 40), 0); /* 60-100 */
  82037. ExpectIntEQ(DFB_TEST(ssl, 6, 100, 0, 30, 2, 0, 70), 0); /* 0-30 */
  82038. ExpectIntEQ(DFB_TEST(ssl, 6, 100, 30, 30, 0, 1, 100), 0); /* 30-60 */
  82039. /* 3 2 1 */
  82040. ExpectIntEQ(DFB_TEST(ssl, 7, 100, 60, 40, 1, 0, 40), 0); /* 60-100 */
  82041. ExpectIntEQ(DFB_TEST(ssl, 7, 100, 30, 30, 1, 0, 70), 0); /* 30-60 */
  82042. ExpectIntEQ(DFB_TEST(ssl, 7, 100, 0, 30, 0, 1, 100), 0); /* 0-30 */
  82043. /* Test overlapping regions */
  82044. ExpectIntEQ(DFB_TEST(ssl, 8, 100, 0, 30, 1, 0, 30), 0); /* 0-30 */
  82045. ExpectIntEQ(DFB_TEST(ssl, 8, 100, 20, 10, 1, 0, 30), 0); /* 20-30 */
  82046. ExpectIntEQ(DFB_TEST(ssl, 8, 100, 70, 10, 2, 0, 40), 0); /* 70-80 */
  82047. ExpectIntEQ(DFB_TEST(ssl, 8, 100, 20, 30, 2, 0, 60), 0); /* 20-50 */
  82048. ExpectIntEQ(DFB_TEST(ssl, 8, 100, 40, 60, 0, 1, 100), 0); /* 40-100 */
  82049. /* Test overlapping multiple regions */
  82050. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 0, 20, 1, 0, 20), 0); /* 0-20 */
  82051. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 30, 5, 2, 0, 25), 0); /* 30-35 */
  82052. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 40, 5, 3, 0, 30), 0); /* 40-45 */
  82053. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 50, 5, 4, 0, 35), 0); /* 50-55 */
  82054. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 60, 5, 5, 0, 40), 0); /* 60-65 */
  82055. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 70, 5, 6, 0, 45), 0); /* 70-75 */
  82056. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 30, 25, 4, 0, 55), 0); /* 30-55 */
  82057. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 55, 15, 2, 0, 65), 0); /* 55-70 */
  82058. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 75, 25, 2, 0, 90), 0); /* 75-100 */
  82059. ExpectIntEQ(DFB_TEST(ssl, 9, 100, 10, 25, 0, 1, 100), 0); /* 10-35 */
  82060. ExpectIntEQ(DFB_TEST(ssl, 10, 100, 0, 20, 1, 0, 20), 0); /* 0-20 */
  82061. ExpectIntEQ(DFB_TEST(ssl, 10, 100, 30, 20, 2, 0, 40), 0); /* 30-50 */
  82062. ExpectIntEQ(DFB_TEST(ssl, 10, 100, 0, 40, 1, 0, 50), 0); /* 0-40 */
  82063. ExpectIntEQ(DFB_TEST(ssl, 10, 100, 50, 50, 0, 1, 100), 0); /* 10-35 */
  82064. DtlsMsgListDelete(ssl->dtls_rx_msg_list, ssl->heap);
  82065. ssl->dtls_rx_msg_list = NULL;
  82066. ssl->dtls_rx_msg_list_sz = 0;
  82067. return EXPECT_RESULT();
  82068. }
  82069. #endif
  82070. #if !defined(NO_FILESYSTEM) && \
  82071. defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  82072. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  82073. static int test_wolfSSL_dtls_stateless2(void)
  82074. {
  82075. EXPECT_DECLS;
  82076. WOLFSSL *ssl_c = NULL;
  82077. WOLFSSL *ssl_c2 = NULL;
  82078. WOLFSSL *ssl_s = NULL;
  82079. struct test_memio_ctx test_ctx;
  82080. WOLFSSL_CTX *ctx_c = NULL;
  82081. WOLFSSL_CTX *ctx_s = NULL;
  82082. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82083. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82084. wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  82085. ExpectNotNull(ssl_c2 = wolfSSL_new(ctx_c));
  82086. wolfSSL_SetIOWriteCtx(ssl_c2, &test_ctx);
  82087. wolfSSL_SetIOReadCtx(ssl_c2, &test_ctx);
  82088. /* send CH */
  82089. ExpectTrue((wolfSSL_connect(ssl_c2) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  82090. (ssl_c2->error == WC_NO_ERR_TRACE(WANT_READ)));
  82091. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  82092. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  82093. ExpectIntNE(test_ctx.c_len, 0);
  82094. /* consume HRR */
  82095. test_ctx.c_len = 0;
  82096. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  82097. wolfSSL_free(ssl_c2);
  82098. wolfSSL_free(ssl_c);
  82099. wolfSSL_free(ssl_s);
  82100. wolfSSL_CTX_free(ctx_c);
  82101. wolfSSL_CTX_free(ctx_s);
  82102. return EXPECT_RESULT();
  82103. }
  82104. #ifdef HAVE_MAX_FRAGMENT
  82105. static int test_wolfSSL_dtls_stateless_maxfrag(void)
  82106. {
  82107. EXPECT_DECLS;
  82108. WOLFSSL *ssl_c = NULL;
  82109. WOLFSSL *ssl_c2 = NULL;
  82110. WOLFSSL *ssl_s = NULL;
  82111. struct test_memio_ctx test_ctx;
  82112. WOLFSSL_CTX *ctx_c = NULL;
  82113. WOLFSSL_CTX *ctx_s = NULL;
  82114. word16 max_fragment = 0;
  82115. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82116. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82117. wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  82118. ExpectNotNull(ssl_c2 = wolfSSL_new(ctx_c));
  82119. ExpectIntEQ(wolfSSL_UseMaxFragment(ssl_c2, WOLFSSL_MFL_2_8),
  82120. WOLFSSL_SUCCESS);
  82121. wolfSSL_SetIOWriteCtx(ssl_c2, &test_ctx);
  82122. wolfSSL_SetIOReadCtx(ssl_c2, &test_ctx);
  82123. if (ssl_s != NULL) {
  82124. max_fragment = ssl_s->max_fragment;
  82125. }
  82126. /* send CH */
  82127. ExpectTrue((wolfSSL_connect(ssl_c2) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  82128. (ssl_c2->error == WC_NO_ERR_TRACE(WANT_READ)));
  82129. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  82130. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  82131. /* CH without cookie shouldn't change state */
  82132. ExpectIntEQ(ssl_s->max_fragment, max_fragment);
  82133. ExpectIntNE(test_ctx.c_len, 0);
  82134. /* consume HRR from buffer */
  82135. test_ctx.c_len = 0;
  82136. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  82137. wolfSSL_free(ssl_c2);
  82138. wolfSSL_free(ssl_c);
  82139. wolfSSL_free(ssl_s);
  82140. wolfSSL_CTX_free(ctx_c);
  82141. wolfSSL_CTX_free(ctx_s);
  82142. return EXPECT_RESULT();
  82143. }
  82144. #endif /* HAVE_MAX_FRAGMENT */
  82145. #if defined(WOLFSSL_DTLS_NO_HVR_ON_RESUME)
  82146. #define ROUNDS_WITH_HVR 4
  82147. #define ROUNDS_WITHOUT_HVR 2
  82148. #define HANDSHAKE_TYPE_OFFSET DTLS_RECORD_HEADER_SZ
  82149. static int buf_is_hvr(const byte *data, int len)
  82150. {
  82151. if (len < DTLS_RECORD_HEADER_SZ + DTLS_HANDSHAKE_HEADER_SZ)
  82152. return 0;
  82153. return data[HANDSHAKE_TYPE_OFFSET] == hello_verify_request;
  82154. }
  82155. static int _test_wolfSSL_dtls_stateless_resume(byte useticket, byte bad)
  82156. {
  82157. EXPECT_DECLS;
  82158. struct test_memio_ctx test_ctx;
  82159. WOLFSSL_CTX *ctx_c = NULL;
  82160. WOLFSSL_CTX *ctx_s = NULL;
  82161. WOLFSSL *ssl_c = NULL;
  82162. WOLFSSL *ssl_s = NULL;
  82163. WOLFSSL_SESSION *sess = NULL;
  82164. int round_trips;
  82165. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82166. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c,
  82167. &ssl_s, wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  82168. #ifdef HAVE_SESSION_TICKET
  82169. if (useticket) {
  82170. ExpectIntEQ(wolfSSL_UseSessionTicket(ssl_c), WOLFSSL_SUCCESS);
  82171. }
  82172. #endif
  82173. round_trips = ROUNDS_WITH_HVR;
  82174. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, round_trips,
  82175. &round_trips), 0);
  82176. ExpectIntEQ(round_trips, ROUNDS_WITH_HVR);
  82177. ExpectNotNull(sess = wolfSSL_get1_session(ssl_c));
  82178. wolfSSL_shutdown(ssl_c);
  82179. wolfSSL_shutdown(ssl_s);
  82180. wolfSSL_free(ssl_c);
  82181. ssl_c = NULL;
  82182. wolfSSL_free(ssl_s);
  82183. ssl_s = NULL;
  82184. test_ctx.c_len = test_ctx.s_len = 0;
  82185. /* make resumption invalid */
  82186. if (bad && (sess != NULL)) {
  82187. if (useticket) {
  82188. #ifdef HAVE_SESSION_TICKET
  82189. if (sess->ticket != NULL) {
  82190. sess->ticket[0] = !sess->ticket[0];
  82191. }
  82192. #endif /* HAVE_SESSION_TICKET */
  82193. }
  82194. else {
  82195. sess->sessionID[0] = !sess->sessionID[0];
  82196. }
  82197. }
  82198. ExpectNotNull(ssl_c = wolfSSL_new(ctx_c));
  82199. ExpectNotNull(ssl_s = wolfSSL_new(ctx_s));
  82200. wolfSSL_SetIOWriteCtx(ssl_c, &test_ctx);
  82201. wolfSSL_SetIOReadCtx(ssl_c, &test_ctx);
  82202. wolfSSL_SetIOWriteCtx(ssl_s, &test_ctx);
  82203. wolfSSL_SetIOReadCtx(ssl_s, &test_ctx);
  82204. ExpectIntEQ(wolfSSL_set_session(ssl_c, sess), WOLFSSL_SUCCESS);
  82205. ExpectTrue((wolfSSL_connect(ssl_c) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  82206. (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ)));
  82207. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  82208. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  82209. ExpectFalse(bad && !buf_is_hvr(test_ctx.c_buff, test_ctx.c_len));
  82210. ExpectFalse(!bad && buf_is_hvr(test_ctx.c_buff, test_ctx.c_len));
  82211. if (!useticket) {
  82212. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, &round_trips), 0);
  82213. ExpectFalse(bad && round_trips != ROUNDS_WITH_HVR - 1);
  82214. ExpectFalse(!bad && round_trips != ROUNDS_WITHOUT_HVR - 1);
  82215. }
  82216. wolfSSL_SESSION_free(sess);
  82217. wolfSSL_free(ssl_c);
  82218. wolfSSL_free(ssl_s);
  82219. wolfSSL_CTX_free(ctx_c);
  82220. wolfSSL_CTX_free(ctx_s);
  82221. return EXPECT_RESULT();
  82222. }
  82223. static int test_wolfSSL_dtls_stateless_resume(void)
  82224. {
  82225. EXPECT_DECLS;
  82226. #ifdef HAVE_SESSION_TICKET
  82227. ExpectIntEQ(_test_wolfSSL_dtls_stateless_resume(1, 0), TEST_SUCCESS);
  82228. ExpectIntEQ(_test_wolfSSL_dtls_stateless_resume(1, 1), TEST_SUCCESS);
  82229. #endif /* HAVE_SESION_TICKET */
  82230. ExpectIntEQ(_test_wolfSSL_dtls_stateless_resume(0, 0), TEST_SUCCESS);
  82231. ExpectIntEQ(_test_wolfSSL_dtls_stateless_resume(0, 1), TEST_SUCCESS);
  82232. return EXPECT_RESULT();
  82233. }
  82234. #endif /* WOLFSSL_DTLS_NO_HVR_ON_RESUME */
  82235. #if !defined(NO_OLD_TLS)
  82236. static int test_wolfSSL_dtls_stateless_downgrade(void)
  82237. {
  82238. EXPECT_DECLS;
  82239. WOLFSSL_CTX *ctx_c = NULL;
  82240. WOLFSSL_CTX *ctx_c2 = NULL;
  82241. WOLFSSL_CTX *ctx_s = NULL;
  82242. WOLFSSL *ssl_c = NULL;
  82243. WOLFSSL *ssl_c2 = NULL;
  82244. WOLFSSL *ssl_s = NULL;
  82245. struct test_memio_ctx test_ctx;
  82246. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82247. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82248. wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  82249. ExpectIntEQ(wolfSSL_CTX_SetMinVersion(ctx_s, WOLFSSL_DTLSV1),
  82250. WOLFSSL_SUCCESS);
  82251. ExpectNotNull(ctx_c2 = wolfSSL_CTX_new(wolfDTLSv1_client_method()));
  82252. wolfSSL_SetIORecv(ctx_c2, test_memio_read_cb);
  82253. wolfSSL_SetIOSend(ctx_c2, test_memio_write_cb);
  82254. ExpectNotNull(ssl_c2 = wolfSSL_new(ctx_c2));
  82255. wolfSSL_SetIOWriteCtx(ssl_c2, &test_ctx);
  82256. wolfSSL_SetIOReadCtx(ssl_c2, &test_ctx);
  82257. /* send CH */
  82258. ExpectTrue((wolfSSL_connect(ssl_c2) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  82259. (ssl_c2->error == WC_NO_ERR_TRACE(WANT_READ)));
  82260. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  82261. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  82262. ExpectIntNE(test_ctx.c_len, 0);
  82263. /* consume HRR */
  82264. test_ctx.c_len = 0;
  82265. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  82266. wolfSSL_free(ssl_c2);
  82267. wolfSSL_free(ssl_c);
  82268. wolfSSL_free(ssl_s);
  82269. wolfSSL_CTX_free(ctx_c);
  82270. wolfSSL_CTX_free(ctx_c2);
  82271. wolfSSL_CTX_free(ctx_s);
  82272. return EXPECT_RESULT();
  82273. }
  82274. #endif /* !defined(NO_OLD_TLS) */
  82275. #endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  82276. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)*/
  82277. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  82278. !defined(NO_OLD_TLS) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  82279. static int test_WOLFSSL_dtls_version_alert(void)
  82280. {
  82281. EXPECT_DECLS;
  82282. struct test_memio_ctx test_ctx;
  82283. WOLFSSL_CTX *ctx_c = NULL;
  82284. WOLFSSL_CTX *ctx_s = NULL;
  82285. WOLFSSL *ssl_c = NULL;
  82286. WOLFSSL *ssl_s = NULL;
  82287. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82288. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82289. wolfDTLSv1_2_client_method, wolfDTLSv1_server_method), 0);
  82290. /* client hello */
  82291. ExpectTrue((wolfSSL_connect(ssl_c) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  82292. (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ)));
  82293. /* hrr */
  82294. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  82295. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  82296. /* client hello 1 */
  82297. ExpectTrue((wolfSSL_connect(ssl_c) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  82298. (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ)));
  82299. /* server hello */
  82300. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  82301. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  82302. /* should fail */
  82303. ExpectTrue((wolfSSL_connect(ssl_c) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  82304. (ssl_c->error == WC_NO_ERR_TRACE(VERSION_ERROR)));
  82305. /* shuould fail */
  82306. ExpectTrue((wolfSSL_accept(ssl_s) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  82307. (ssl_s->error == WC_NO_ERR_TRACE(VERSION_ERROR) || ssl_s->error == WC_NO_ERR_TRACE(FATAL_ERROR)));
  82308. wolfSSL_free(ssl_c);
  82309. wolfSSL_free(ssl_s);
  82310. wolfSSL_CTX_free(ctx_c);
  82311. wolfSSL_CTX_free(ctx_s);
  82312. return EXPECT_RESULT();
  82313. }
  82314. #else
  82315. static int test_WOLFSSL_dtls_version_alert(void)
  82316. {
  82317. return TEST_SKIPPED;
  82318. }
  82319. #endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) &&
  82320. * !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) &&
  82321. * !defined(NO_OLD_TLS) && !defined(NO_RSA)
  82322. */
  82323. #if defined(WOLFSSL_TICKET_NONCE_MALLOC) && defined(HAVE_SESSION_TICKET) \
  82324. && defined(WOLFSSL_TLS13) && \
  82325. (!defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))\
  82326. && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  82327. static int send_new_session_ticket(WOLFSSL *ssl, byte nonceLength, byte filler)
  82328. {
  82329. struct test_memio_ctx *test_ctx;
  82330. byte buf[2048];
  82331. int idx, sz;
  82332. word32 tmp;
  82333. int ret;
  82334. idx = 5; /* space for record header */
  82335. buf[idx] = session_ticket; /* type */
  82336. idx++;
  82337. tmp = OPAQUE32_LEN +
  82338. OPAQUE32_LEN +
  82339. OPAQUE8_LEN + nonceLength +
  82340. OPAQUE16_LEN + OPAQUE8_LEN + OPAQUE16_LEN;
  82341. c32to24(tmp, buf + idx);
  82342. idx += OPAQUE24_LEN;
  82343. c32toa((word32)12345, buf+idx); /* lifetime */
  82344. idx += OPAQUE32_LEN;
  82345. c32toa((word32)12345, buf+idx); /* add */
  82346. idx += OPAQUE32_LEN;
  82347. buf[idx] = nonceLength; /* nonce length */
  82348. idx++;
  82349. XMEMSET(&buf[idx], filler, nonceLength); /* nonce */
  82350. idx += nonceLength;
  82351. tmp = 1; /* ticket len */
  82352. c16toa((word16)tmp, buf+idx);
  82353. idx += 2;
  82354. buf[idx] = 0xFF; /* ticket */
  82355. idx++;
  82356. tmp = 0; /* ext len */
  82357. c16toa((word16)tmp, buf+idx);
  82358. idx += 2;
  82359. sz = BuildTls13Message(ssl, buf, 2048, buf+5, idx - 5,
  82360. handshake, 0, 0, 0);
  82361. AssertIntGT(sz, 0);
  82362. test_ctx = (struct test_memio_ctx*)wolfSSL_GetIOWriteCtx(ssl);
  82363. AssertNotNull(test_ctx);
  82364. ret = test_memio_write_cb(ssl, (char*)buf, sz, test_ctx);
  82365. return !(ret == sz);
  82366. }
  82367. static int test_ticket_nonce_check(WOLFSSL_SESSION *sess, byte len)
  82368. {
  82369. int ret = 0;
  82370. if ((sess == NULL) || (sess->ticketNonce.len != len)) {
  82371. ret = -1;
  82372. }
  82373. else {
  82374. int i;
  82375. for (i = 0; i < len; i++) {
  82376. if (sess->ticketNonce.data[i] != len) {
  82377. ret = -1;
  82378. break;
  82379. }
  82380. }
  82381. }
  82382. return ret;
  82383. }
  82384. static int test_ticket_nonce_malloc_do(WOLFSSL *ssl_s, WOLFSSL *ssl_c, byte len)
  82385. {
  82386. EXPECT_DECLS;
  82387. char *buf[1024];
  82388. ExpectIntEQ(send_new_session_ticket(ssl_s, len, len), 0);
  82389. ExpectTrue((wolfSSL_recv(ssl_c, buf, 1024, 0) == WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)) &&
  82390. (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ)));
  82391. ExpectIntEQ(test_ticket_nonce_check(ssl_c->session, len), 0);
  82392. return EXPECT_RESULT();
  82393. }
  82394. static int test_ticket_nonce_cache(WOLFSSL *ssl_s, WOLFSSL *ssl_c, byte len)
  82395. {
  82396. EXPECT_DECLS;
  82397. WOLFSSL_SESSION *sess = NULL;
  82398. WOLFSSL_SESSION *cached = NULL;
  82399. WOLFSSL_CTX *ctx = ssl_c->ctx;
  82400. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, len), TEST_SUCCESS);
  82401. ExpectNotNull(sess = wolfSSL_get1_session(ssl_c));
  82402. ExpectIntEQ(AddSessionToCache(ctx, sess, sess->sessionID, sess->sessionIDSz,
  82403. NULL, ssl_c->options.side, 1,NULL), 0);
  82404. ExpectNotNull(cached = wolfSSL_SESSION_new());
  82405. ExpectIntEQ(wolfSSL_GetSessionFromCache(ssl_c, cached), WOLFSSL_SUCCESS);
  82406. ExpectIntEQ(test_ticket_nonce_check(cached, len), 0);
  82407. wolfSSL_SESSION_free(cached);
  82408. wolfSSL_SESSION_free(sess);
  82409. return EXPECT_RESULT();
  82410. }
  82411. static int test_ticket_nonce_malloc(void)
  82412. {
  82413. EXPECT_DECLS;
  82414. struct test_memio_ctx test_ctx;
  82415. WOLFSSL_CTX *ctx_c = NULL;
  82416. WOLFSSL_CTX *ctx_s = NULL;
  82417. WOLFSSL *ssl_c = NULL;
  82418. WOLFSSL *ssl_s = NULL;
  82419. byte small;
  82420. byte medium;
  82421. byte big;
  82422. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82423. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82424. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  82425. /* will send ticket manually */
  82426. ExpectIntEQ(wolfSSL_no_ticket_TLSv13(ssl_s), 0);
  82427. wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_NONE, 0);
  82428. wolfSSL_set_verify(ssl_c, WOLFSSL_VERIFY_NONE, 0);
  82429. while (EXPECT_SUCCESS() && (ssl_c->options.handShakeDone == 0) &&
  82430. (ssl_s->options.handShakeDone == 0)) {
  82431. ExpectTrue((wolfSSL_connect(ssl_c) == WOLFSSL_SUCCESS) ||
  82432. (ssl_c->error == WC_NO_ERR_TRACE(WANT_READ)));
  82433. ExpectTrue((wolfSSL_accept(ssl_s) == WOLFSSL_SUCCESS) ||
  82434. (ssl_s->error == WC_NO_ERR_TRACE(WANT_READ)));
  82435. }
  82436. small = TLS13_TICKET_NONCE_STATIC_SZ;
  82437. #if TLS13_TICKET_NONCE_STATIC_SZ + 20 <= 255
  82438. medium = small + 20;
  82439. #else
  82440. medium = 255;
  82441. #endif
  82442. #if TLS13_TICKET_NONCE_STATIC_SZ + 20 + 20 <= 255
  82443. big = small + 20;
  82444. #else
  82445. big = 255;
  82446. #endif
  82447. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, small), TEST_SUCCESS);
  82448. ExpectPtrEq(ssl_c->session->ticketNonce.data,
  82449. ssl_c->session->ticketNonce.dataStatic);
  82450. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, medium),
  82451. TEST_SUCCESS);
  82452. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, big), TEST_SUCCESS);
  82453. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, medium),
  82454. TEST_SUCCESS);
  82455. ExpectIntEQ(test_ticket_nonce_malloc_do(ssl_s, ssl_c, small), TEST_SUCCESS);
  82456. ExpectIntEQ(test_ticket_nonce_cache(ssl_s, ssl_c, small), TEST_SUCCESS);
  82457. ExpectIntEQ(test_ticket_nonce_cache(ssl_s, ssl_c, medium), TEST_SUCCESS);
  82458. ExpectIntEQ(test_ticket_nonce_cache(ssl_s, ssl_c, big), TEST_SUCCESS);
  82459. ExpectIntEQ(test_ticket_nonce_cache(ssl_s, ssl_c, medium), TEST_SUCCESS);
  82460. ExpectIntEQ(test_ticket_nonce_cache(ssl_s, ssl_c, small), TEST_SUCCESS);
  82461. wolfSSL_free(ssl_c);
  82462. wolfSSL_free(ssl_s);
  82463. wolfSSL_CTX_free(ctx_c);
  82464. wolfSSL_CTX_free(ctx_s);
  82465. return EXPECT_RESULT();
  82466. }
  82467. #endif /* WOLFSSL_TICKET_NONCE_MALLOC */
  82468. #if defined(HAVE_SESSION_TICKET) && !defined(WOLFSSL_NO_TLS12) && \
  82469. !defined(WOLFSSL_TICKET_DECRYPT_NO_CREATE) && \
  82470. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  82471. !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && !defined(NO_RSA) && \
  82472. defined(HAVE_ECC) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  82473. static int test_ticket_ret_create(void)
  82474. {
  82475. EXPECT_DECLS;
  82476. WOLFSSL_CTX *ctx_c = NULL;
  82477. WOLFSSL_CTX *ctx_s = NULL;
  82478. WOLFSSL *ssl_c = NULL;
  82479. WOLFSSL *ssl_s = NULL;
  82480. byte ticket[SESSION_TICKET_LEN];
  82481. struct test_memio_ctx test_ctx;
  82482. WOLFSSL_SESSION *sess = NULL;
  82483. word16 ticketLen = 0;
  82484. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82485. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  82486. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  82487. wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_NONE, 0);
  82488. wolfSSL_set_verify(ssl_c, WOLFSSL_VERIFY_NONE, 0);
  82489. ExpectIntEQ(wolfSSL_CTX_UseSessionTicket(ctx_c), WOLFSSL_SUCCESS);
  82490. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  82491. ExpectNotNull(sess = wolfSSL_get1_session(ssl_c));
  82492. ExpectIntLE(sess->ticketLen, SESSION_TICKET_LEN);
  82493. if (sess != NULL) {
  82494. ticketLen = sess->ticketLen;
  82495. XMEMCPY(ticket, sess->ticket, sess->ticketLen);
  82496. }
  82497. wolfSSL_free(ssl_c);
  82498. ssl_c = NULL;
  82499. wolfSSL_free(ssl_s);
  82500. ssl_s = NULL;
  82501. ExpectNotNull(ssl_s = wolfSSL_new(ctx_s));
  82502. wolfSSL_SetIOWriteCtx(ssl_s, &test_ctx);
  82503. wolfSSL_SetIOReadCtx(ssl_s, &test_ctx);
  82504. ExpectNotNull(ssl_c = wolfSSL_new(ctx_c));
  82505. wolfSSL_SetIOWriteCtx(ssl_c, &test_ctx);
  82506. wolfSSL_SetIOReadCtx(ssl_c, &test_ctx);
  82507. ExpectIntEQ(wolfSSL_set_session(ssl_c, sess), WOLFSSL_SUCCESS);
  82508. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  82509. ExpectIntLE(ssl_c->session->ticketLen, SESSION_TICKET_LEN);
  82510. ExpectIntEQ(ssl_c->session->ticketLen, ticketLen);
  82511. ExpectTrue(XMEMCMP(ssl_c->session->ticket, ticket, ticketLen) != 0);
  82512. wolfSSL_SESSION_free(sess);
  82513. wolfSSL_free(ssl_c);
  82514. wolfSSL_free(ssl_s);
  82515. wolfSSL_CTX_free(ctx_c);
  82516. wolfSSL_CTX_free(ctx_s);
  82517. return EXPECT_RESULT();
  82518. }
  82519. #else
  82520. static int test_ticket_ret_create(void)
  82521. {
  82522. return TEST_SKIPPED;
  82523. }
  82524. #endif
  82525. #if defined(WOLFSSL_TLS13) && !defined(NO_PSK) && \
  82526. defined(HAVE_SESSION_TICKET) && defined(OPENSSL_EXTRA) && \
  82527. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_AESGCM) && \
  82528. !defined(NO_SHA256) && defined(WOLFSSL_AES_128) && \
  82529. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  82530. static void test_ticket_and_psk_mixing_on_result(WOLFSSL* ssl)
  82531. {
  82532. int ret;
  82533. WOLFSSL_SESSION* session = NULL;
  82534. AssertIntEQ(wolfSSL_get_current_cipher_suite(ssl), 0x1301);
  82535. if (!wolfSSL_is_server(ssl)) {
  82536. session = wolfSSL_SESSION_dup(wolfSSL_get_session(ssl));
  82537. AssertNotNull(session);
  82538. }
  82539. do {
  82540. ret = wolfSSL_shutdown(ssl);
  82541. } while (ret == WOLFSSL_SHUTDOWN_NOT_DONE);
  82542. AssertIntEQ(wolfSSL_clear(ssl), WOLFSSL_SUCCESS);
  82543. wolfSSL_set_psk_callback_ctx(ssl, (void*)"TLS13-AES256-GCM-SHA384");
  82544. #ifndef OPENSSL_COMPATIBLE_DEFAULTS
  82545. /* OpenSSL considers PSK to be verified. We error out with NO_PEER_CERT. */
  82546. wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_NONE, NULL);
  82547. #endif
  82548. if (!wolfSSL_is_server(ssl)) {
  82549. /* client */
  82550. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384:"
  82551. "TLS13-AES128-GCM-SHA256"), WOLFSSL_SUCCESS);
  82552. wolfSSL_set_session(ssl, session);
  82553. wolfSSL_SESSION_free(session);
  82554. wolfSSL_set_psk_client_tls13_callback(ssl, my_psk_client_tls13_cb);
  82555. AssertIntEQ(wolfSSL_connect(ssl), WOLFSSL_SUCCESS);
  82556. }
  82557. else {
  82558. /* server */
  82559. /* Different ciphersuite so that the ticket will be invalidated based on
  82560. * the ciphersuite */
  82561. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384"),
  82562. WOLFSSL_SUCCESS);
  82563. wolfSSL_set_psk_server_tls13_callback(ssl, my_psk_server_tls13_cb);
  82564. AssertIntEQ(wolfSSL_accept(ssl), WOLFSSL_SUCCESS);
  82565. }
  82566. }
  82567. static void test_ticket_and_psk_mixing_ssl_ready(WOLFSSL* ssl)
  82568. {
  82569. AssertIntEQ(wolfSSL_UseSessionTicket(ssl), WOLFSSL_SUCCESS);
  82570. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES128-GCM-SHA256"),
  82571. WOLFSSL_SUCCESS);
  82572. }
  82573. static int test_ticket_and_psk_mixing(void)
  82574. {
  82575. EXPECT_DECLS;
  82576. /* Test mixing tickets and regular PSK */
  82577. callback_functions client_cbs, server_cbs;
  82578. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  82579. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  82580. client_cbs.method = wolfTLSv1_3_client_method;
  82581. server_cbs.method = wolfTLSv1_3_server_method;
  82582. client_cbs.ssl_ready = test_ticket_and_psk_mixing_ssl_ready;
  82583. client_cbs.on_result = test_ticket_and_psk_mixing_on_result;
  82584. server_cbs.on_result = test_ticket_and_psk_mixing_on_result;
  82585. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  82586. ExpectIntEQ(client_cbs.return_code, TEST_SUCCESS);
  82587. ExpectIntEQ(server_cbs.return_code, TEST_SUCCESS);
  82588. return EXPECT_RESULT();
  82589. }
  82590. #else
  82591. static int test_ticket_and_psk_mixing(void)
  82592. {
  82593. return TEST_SKIPPED;
  82594. }
  82595. #endif
  82596. #if defined(WOLFSSL_TLS13) && !defined(NO_PSK) && defined(HAVE_SESSION_TICKET) \
  82597. && defined(OPENSSL_EXTRA) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
  82598. defined(HAVE_AESGCM) && !defined(NO_SHA256) && defined(WOLFSSL_AES_128) && \
  82599. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  82600. static int test_prioritize_psk_cb_called = FALSE;
  82601. static unsigned int test_prioritize_psk_cb(WOLFSSL* ssl,
  82602. const char* identity, unsigned char* key, unsigned int key_max_len,
  82603. const char** ciphersuite)
  82604. {
  82605. test_prioritize_psk_cb_called = TRUE;
  82606. return my_psk_server_tls13_cb(ssl, identity, key, key_max_len, ciphersuite);
  82607. }
  82608. static void test_prioritize_psk_on_result(WOLFSSL* ssl)
  82609. {
  82610. int ret;
  82611. WOLFSSL_SESSION* session = NULL;
  82612. AssertIntEQ(wolfSSL_get_current_cipher_suite(ssl), 0x1301);
  82613. if (!wolfSSL_is_server(ssl)) {
  82614. session = wolfSSL_SESSION_dup(wolfSSL_get_session(ssl));
  82615. AssertNotNull(session);
  82616. }
  82617. do {
  82618. ret = wolfSSL_shutdown(ssl);
  82619. } while (ret == WOLFSSL_SHUTDOWN_NOT_DONE);
  82620. AssertIntEQ(wolfSSL_clear(ssl), WOLFSSL_SUCCESS);
  82621. wolfSSL_set_psk_callback_ctx(ssl, (void*)"TLS13-AES256-GCM-SHA384");
  82622. /* Previous connection was made with TLS13-AES128-GCM-SHA256. Order is
  82623. * important. */
  82624. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384:"
  82625. "TLS13-AES128-GCM-SHA256"), WOLFSSL_SUCCESS);
  82626. #ifndef OPENSSL_COMPATIBLE_DEFAULTS
  82627. /* OpenSSL considers PSK to be verified. We error out with NO_PEER_CERT. */
  82628. wolfSSL_set_verify(ssl, WOLFSSL_VERIFY_NONE, NULL);
  82629. #endif
  82630. if (!wolfSSL_is_server(ssl)) {
  82631. /* client */
  82632. wolfSSL_set_psk_client_tls13_callback(ssl, my_psk_client_tls13_cb);
  82633. wolfSSL_set_session(ssl, session);
  82634. wolfSSL_SESSION_free(session);
  82635. AssertIntEQ(wolfSSL_connect(ssl), WOLFSSL_SUCCESS);
  82636. }
  82637. else {
  82638. /* server */
  82639. wolfSSL_set_psk_server_tls13_callback(ssl, test_prioritize_psk_cb);
  82640. AssertIntEQ(wolfSSL_accept(ssl), WOLFSSL_SUCCESS);
  82641. #ifdef WOLFSSL_PRIORITIZE_PSK
  82642. /* The ticket should be first tried with all ciphersuites and chosen */
  82643. AssertFalse(test_prioritize_psk_cb_called);
  82644. #else
  82645. /* Ciphersuites should be tried with each PSK. This triggers the PSK
  82646. * callback that sets this var. */
  82647. AssertTrue(test_prioritize_psk_cb_called);
  82648. #endif
  82649. }
  82650. }
  82651. static void test_prioritize_psk_ssl_ready(WOLFSSL* ssl)
  82652. {
  82653. if (!wolfSSL_is_server(ssl))
  82654. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES128-GCM-SHA256"),
  82655. WOLFSSL_SUCCESS);
  82656. else
  82657. AssertIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384:"
  82658. "TLS13-AES128-GCM-SHA256"), WOLFSSL_SUCCESS);
  82659. }
  82660. static int test_prioritize_psk(void)
  82661. {
  82662. EXPECT_DECLS;
  82663. /* We always send the ticket first. With WOLFSSL_PRIORITIZE_PSK the order
  82664. * of the PSK's will be followed instead of the ciphersuite. */
  82665. callback_functions client_cbs, server_cbs;
  82666. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  82667. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  82668. client_cbs.method = wolfTLSv1_3_client_method;
  82669. server_cbs.method = wolfTLSv1_3_server_method;
  82670. client_cbs.ssl_ready = test_prioritize_psk_ssl_ready;
  82671. server_cbs.ssl_ready = test_prioritize_psk_ssl_ready;
  82672. client_cbs.on_result = test_prioritize_psk_on_result;
  82673. server_cbs.on_result = test_prioritize_psk_on_result;
  82674. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  82675. ExpectIntEQ(client_cbs.return_code, TEST_SUCCESS);
  82676. ExpectIntEQ(server_cbs.return_code, TEST_SUCCESS);
  82677. return EXPECT_RESULT();
  82678. }
  82679. #else
  82680. static int test_prioritize_psk(void)
  82681. {
  82682. return TEST_SKIPPED;
  82683. }
  82684. #endif
  82685. #if defined(WOLFSSL_TLS13) && defined(OPENSSL_EXTRA) && \
  82686. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_AESGCM) && \
  82687. !defined(NO_SHA256) && defined(WOLFSSL_AES_128) && \
  82688. !defined(WOLFSSL_NO_TLS12)
  82689. static int test_wolfSSL_CTX_set_ciphersuites_ctx_ready_server(WOLFSSL_CTX* ctx)
  82690. {
  82691. EXPECT_DECLS;
  82692. ExpectTrue(SSL_CTX_set_cipher_list(ctx, "DEFAULT"));
  82693. /* Set TLS 1.3 specific suite */
  82694. ExpectTrue(SSL_CTX_set_ciphersuites(ctx, "TLS13-AES128-GCM-SHA256"));
  82695. return EXPECT_RESULT();
  82696. }
  82697. static int test_wolfSSL_CTX_set_ciphersuites(void)
  82698. {
  82699. EXPECT_DECLS;
  82700. /* Test using SSL_CTX_set_cipher_list and SSL_CTX_set_ciphersuites and then
  82701. * do a 1.2 connection. */
  82702. test_ssl_cbf client_cbs, server_cbs;
  82703. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  82704. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  82705. client_cbs.method = wolfTLSv1_2_client_method;
  82706. server_cbs.method = wolfTLS_server_method; /* Allow downgrade */
  82707. server_cbs.ctx_ready = test_wolfSSL_CTX_set_ciphersuites_ctx_ready_server;
  82708. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  82709. &server_cbs, NULL), TEST_SUCCESS);
  82710. return EXPECT_RESULT();
  82711. }
  82712. #else
  82713. static int test_wolfSSL_CTX_set_ciphersuites(void)
  82714. {
  82715. return TEST_SKIPPED;
  82716. }
  82717. #endif
  82718. #if defined(HAVE_CRL) && defined(WOLFSSL_CHECK_ALERT_ON_ERR) && \
  82719. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  82720. static int test_wolfSSL_CRL_CERT_REVOKED_alert_ctx_ready(WOLFSSL_CTX* ctx)
  82721. {
  82722. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  82723. return TEST_SUCCESS;
  82724. }
  82725. static int test_wolfSSL_CRL_CERT_REVOKED_alert_on_cleanup(WOLFSSL* ssl)
  82726. {
  82727. EXPECT_DECLS;
  82728. WOLFSSL_ALERT_HISTORY h;
  82729. ExpectIntEQ(wolfSSL_get_alert_history(ssl, &h), WOLFSSL_SUCCESS);
  82730. ExpectIntEQ(h.last_rx.level, alert_fatal);
  82731. ExpectIntEQ(h.last_rx.code, certificate_revoked);
  82732. return EXPECT_RESULT();
  82733. }
  82734. static int test_wolfSSL_CRL_CERT_REVOKED_alert(void)
  82735. {
  82736. EXPECT_DECLS;
  82737. test_ssl_cbf client_cbs, server_cbs;
  82738. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  82739. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  82740. server_cbs.certPemFile = "./certs/server-revoked-cert.pem";
  82741. server_cbs.keyPemFile = "./certs/server-revoked-key.pem";
  82742. client_cbs.crlPemFile = "./certs/crl/crl.revoked";
  82743. client_cbs.ctx_ready = test_wolfSSL_CRL_CERT_REVOKED_alert_ctx_ready;
  82744. server_cbs.on_cleanup = test_wolfSSL_CRL_CERT_REVOKED_alert_on_cleanup;
  82745. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  82746. &server_cbs, NULL), -1001);
  82747. return EXPECT_RESULT();
  82748. }
  82749. #else
  82750. static int test_wolfSSL_CRL_CERT_REVOKED_alert(void)
  82751. {
  82752. return TEST_SKIPPED;
  82753. }
  82754. #endif
  82755. #if defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET) \
  82756. && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_AESGCM) && \
  82757. !defined(NO_SHA256) && defined(WOLFSSL_AES_128) && \
  82758. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256) && \
  82759. !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  82760. static WOLFSSL_CTX* test_TLS_13_ticket_different_ciphers_ctx = NULL;
  82761. static WOLFSSL_SESSION* test_TLS_13_ticket_different_ciphers_session = NULL;
  82762. static int test_TLS_13_ticket_different_ciphers_run = 0;
  82763. static int test_TLS_13_ticket_different_ciphers_ssl_ready(WOLFSSL* ssl)
  82764. {
  82765. EXPECT_DECLS;
  82766. switch (test_TLS_13_ticket_different_ciphers_run) {
  82767. case 0:
  82768. /* First run */
  82769. ExpectIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES128-GCM-SHA256"),
  82770. WOLFSSL_SUCCESS);
  82771. if (wolfSSL_is_server(ssl)) {
  82772. ExpectNotNull(test_TLS_13_ticket_different_ciphers_ctx =
  82773. wolfSSL_get_SSL_CTX(ssl));
  82774. ExpectIntEQ(WOLFSSL_SUCCESS, wolfSSL_CTX_up_ref(
  82775. test_TLS_13_ticket_different_ciphers_ctx));
  82776. }
  82777. break;
  82778. case 1:
  82779. /* Second run */
  82780. ExpectIntEQ(wolfSSL_set_cipher_list(ssl, "TLS13-AES256-GCM-SHA384:"
  82781. "TLS13-AES128-GCM-SHA256"),
  82782. WOLFSSL_SUCCESS);
  82783. if (!wolfSSL_is_server(ssl)) {
  82784. ExpectIntEQ(wolfSSL_set_session(ssl,
  82785. test_TLS_13_ticket_different_ciphers_session),
  82786. WOLFSSL_SUCCESS);
  82787. }
  82788. break;
  82789. default:
  82790. /* Bad state? */
  82791. Fail(("Should not enter here"), ("Should not enter here"));
  82792. }
  82793. return EXPECT_RESULT();
  82794. }
  82795. static int test_TLS_13_ticket_different_ciphers_on_result(WOLFSSL* ssl)
  82796. {
  82797. EXPECT_DECLS;
  82798. switch (test_TLS_13_ticket_different_ciphers_run) {
  82799. case 0:
  82800. /* First run */
  82801. ExpectNotNull(test_TLS_13_ticket_different_ciphers_session =
  82802. wolfSSL_get1_session(ssl));
  82803. break;
  82804. case 1:
  82805. /* Second run */
  82806. ExpectTrue(wolfSSL_session_reused(ssl));
  82807. break;
  82808. default:
  82809. /* Bad state? */
  82810. Fail(("Should not enter here"), ("Should not enter here"));
  82811. }
  82812. return EXPECT_RESULT();
  82813. }
  82814. static int test_TLS_13_ticket_different_ciphers(void)
  82815. {
  82816. EXPECT_DECLS;
  82817. /* Check that we handle the connection when the ticket doesn't match
  82818. * the first ciphersuite. */
  82819. test_ssl_cbf client_cbs, server_cbs;
  82820. struct test_params {
  82821. method_provider client_meth;
  82822. method_provider server_meth;
  82823. int doUdp;
  82824. } params[] = {
  82825. #ifdef WOLFSSL_DTLS13
  82826. /* Test that the stateless code handles sessions correctly */
  82827. {wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, 1},
  82828. #endif
  82829. {wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, 0},
  82830. };
  82831. size_t i;
  82832. for (i = 0; i < sizeof(params)/sizeof(*params); i++) {
  82833. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  82834. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  82835. test_TLS_13_ticket_different_ciphers_run = 0;
  82836. client_cbs.doUdp = server_cbs.doUdp = params[i].doUdp;
  82837. client_cbs.method = params[i].client_meth;
  82838. server_cbs.method = params[i].server_meth;
  82839. client_cbs.ssl_ready = test_TLS_13_ticket_different_ciphers_ssl_ready;
  82840. server_cbs.ssl_ready = test_TLS_13_ticket_different_ciphers_ssl_ready;
  82841. client_cbs.on_result = test_TLS_13_ticket_different_ciphers_on_result;
  82842. server_cbs.ticNoInit = 1;
  82843. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  82844. &server_cbs, NULL), TEST_SUCCESS);
  82845. test_TLS_13_ticket_different_ciphers_run++;
  82846. server_cbs.ctx = test_TLS_13_ticket_different_ciphers_ctx;
  82847. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  82848. &server_cbs, NULL), TEST_SUCCESS);
  82849. wolfSSL_SESSION_free(test_TLS_13_ticket_different_ciphers_session);
  82850. test_TLS_13_ticket_different_ciphers_session = NULL;
  82851. wolfSSL_CTX_free(test_TLS_13_ticket_different_ciphers_ctx);
  82852. test_TLS_13_ticket_different_ciphers_ctx = NULL;
  82853. }
  82854. return EXPECT_RESULT();
  82855. }
  82856. #else
  82857. static int test_TLS_13_ticket_different_ciphers(void)
  82858. {
  82859. return TEST_SKIPPED;
  82860. }
  82861. #endif
  82862. #if defined(WOLFSSL_EXTRA_ALERTS) && !defined(WOLFSSL_NO_TLS12) && \
  82863. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  82864. #define TEST_WRONG_CS_CLIENT "DHE-RSA-AES128-SHA"
  82865. /* AKA TLS_DHE_RSA_WITH_AES_128_CBC_SHA */
  82866. byte test_extra_alerts_wrong_cs_sh[] = {
  82867. 0x16, 0x03, 0x03, 0x00, 0x56, 0x02, 0x00, 0x00, 0x52, 0x03, 0x03, 0xef,
  82868. 0x0c, 0x30, 0x98, 0xa2, 0xac, 0xfa, 0x68, 0xe9, 0x3e, 0xaa, 0x5c, 0xcf,
  82869. 0xa7, 0x42, 0x72, 0xaf, 0xa0, 0xe8, 0x39, 0x2b, 0x3e, 0x81, 0xa7, 0x7a,
  82870. 0xa5, 0x62, 0x8a, 0x0e, 0x41, 0xba, 0xda, 0x20, 0x18, 0x9f, 0xe1, 0x8c,
  82871. 0x1d, 0xc0, 0x37, 0x9c, 0xf4, 0x90, 0x5d, 0x8d, 0xa0, 0x79, 0xa7, 0x4b,
  82872. 0xa8, 0x79, 0xdf, 0xcd, 0x8d, 0xf5, 0xb5, 0x50, 0x5f, 0xf1, 0xdb, 0x4d,
  82873. 0xbb, 0x07, 0x54, 0x1c,
  82874. 0x00, 0x02, /* TLS_RSA_WITH_NULL_SHA */
  82875. 0x00, 0x00, 0x0a, 0x00, 0x0b, 0x00,
  82876. 0x02, 0x01, 0x00, 0x00, 0x17, 0x00, 0x00
  82877. };
  82878. static int test_extra_alerts_wrong_cs(void)
  82879. {
  82880. EXPECT_DECLS;
  82881. #ifdef BUILD_TLS_DHE_RSA_WITH_AES_128_CBC_SHA
  82882. struct test_memio_ctx test_ctx;
  82883. WOLFSSL_CTX *ctx_c = NULL;
  82884. WOLFSSL_ALERT_HISTORY h;
  82885. WOLFSSL *ssl_c = NULL;
  82886. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82887. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
  82888. wolfTLSv1_2_client_method, NULL), 0);
  82889. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_c, TEST_WRONG_CS_CLIENT),
  82890. WOLFSSL_SUCCESS);
  82891. /* CH */
  82892. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  82893. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82894. WOLFSSL_ERROR_WANT_READ);
  82895. /* consume CH */
  82896. test_ctx.s_len = 0;
  82897. /* inject SH */
  82898. XMEMCPY(test_ctx.c_buff, test_extra_alerts_wrong_cs_sh,
  82899. sizeof(test_extra_alerts_wrong_cs_sh));
  82900. test_ctx.c_len = sizeof(test_extra_alerts_wrong_cs_sh);
  82901. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  82902. ExpectIntNE(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82903. WOLFSSL_ERROR_WANT_READ);
  82904. ExpectIntEQ(wolfSSL_get_alert_history(ssl_c, &h), WOLFSSL_SUCCESS);
  82905. ExpectIntEQ(h.last_tx.code, handshake_failure);
  82906. ExpectIntEQ(h.last_tx.level, alert_fatal);
  82907. wolfSSL_free(ssl_c);
  82908. wolfSSL_CTX_free(ctx_c);
  82909. #endif
  82910. return EXPECT_RESULT();
  82911. }
  82912. #else
  82913. static int test_extra_alerts_wrong_cs(void)
  82914. {
  82915. return TEST_SKIPPED;
  82916. }
  82917. #endif
  82918. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_TLS12) && \
  82919. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  82920. #define TEST_CS_DOWNGRADE_CLIENT "ECDHE-RSA-AES256-GCM-SHA384"
  82921. byte test_wrong_cs_downgrade_sh[] = {
  82922. 0x16, 0x03, 0x03, 0x00, 0x56, 0x02, 0x00, 0x00, 0x52, 0x03, 0x03, 0x10,
  82923. 0x2c, 0x88, 0xd9, 0x7a, 0x23, 0xc9, 0xbd, 0x11, 0x3b, 0x64, 0x24, 0xab,
  82924. 0x5b, 0x45, 0x33, 0xf6, 0x2c, 0x34, 0xe4, 0xcf, 0xf4, 0x78, 0xc8, 0x62,
  82925. 0x06, 0xc7, 0xe5, 0x30, 0x39, 0xbf, 0xa1, 0x20, 0xa3, 0x06, 0x74, 0xc3,
  82926. 0xa9, 0x74, 0x52, 0x8a, 0xfb, 0xae, 0xf0, 0xd8, 0x6f, 0xb2, 0x9d, 0xfe,
  82927. 0x78, 0xf0, 0x3f, 0x51, 0x8f, 0x9c, 0xcf, 0xbe, 0x61, 0x43, 0x9d, 0xf8,
  82928. 0x85, 0xe5, 0x2f, 0x54,
  82929. 0xc0, 0x2f, /* ECDHE-RSA-AES128-GCM-SHA256 */
  82930. 0x00, 0x00, 0x0a, 0x00, 0x0b, 0x00,
  82931. 0x02, 0x01, 0x00, 0x00, 0x17, 0x00, 0x00
  82932. };
  82933. static int test_wrong_cs_downgrade(void)
  82934. {
  82935. EXPECT_DECLS;
  82936. #ifdef BUILD_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
  82937. struct test_memio_ctx test_ctx;
  82938. WOLFSSL_CTX *ctx_c = NULL;
  82939. WOLFSSL *ssl_c = NULL;
  82940. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  82941. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
  82942. wolfSSLv23_client_method, NULL), 0);
  82943. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_c, TEST_CS_DOWNGRADE_CLIENT),
  82944. WOLFSSL_SUCCESS);
  82945. /* CH */
  82946. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  82947. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82948. WOLFSSL_ERROR_WANT_READ);
  82949. /* consume CH */
  82950. test_ctx.s_len = 0;
  82951. /* inject SH */
  82952. XMEMCPY(test_ctx.c_buff, test_wrong_cs_downgrade_sh,
  82953. sizeof(test_wrong_cs_downgrade_sh));
  82954. test_ctx.c_len = sizeof(test_wrong_cs_downgrade_sh);
  82955. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  82956. #ifdef OPENSSL_EXTRA
  82957. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82958. WC_NO_ERR_TRACE(WOLFSSL_ERROR_SYSCALL));
  82959. #else
  82960. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  82961. WC_NO_ERR_TRACE(MATCH_SUITE_ERROR));
  82962. #endif /* OPENSSL_EXTRA */
  82963. wolfSSL_free(ssl_c);
  82964. wolfSSL_CTX_free(ctx_c);
  82965. #endif
  82966. return EXPECT_RESULT();
  82967. }
  82968. #else
  82969. static int test_wrong_cs_downgrade(void)
  82970. {
  82971. return TEST_SKIPPED;
  82972. }
  82973. #endif
  82974. #if !defined(WOLFSSL_NO_TLS12) && defined(WOLFSSL_EXTRA_ALERTS) && \
  82975. defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_SP_MATH)
  82976. static void test_remove_msg(byte *msg, int tail_len, int *len, int msg_length)
  82977. {
  82978. tail_len -= msg_length;
  82979. XMEMMOVE(msg, msg + msg_length, tail_len);
  82980. *len = *len - msg_length;
  82981. }
  82982. static int test_remove_hs_msg_from_buffer(byte *buf, int *len, byte type,
  82983. byte *found)
  82984. {
  82985. const unsigned int _HANDSHAKE_HEADER_SZ = 4;
  82986. const unsigned int _RECORD_HEADER_SZ = 5;
  82987. const int _change_cipher_hs = 55;
  82988. const int _change_cipher = 20;
  82989. const int _handshake = 22;
  82990. unsigned int tail_len;
  82991. byte *idx, *curr;
  82992. word8 currType;
  82993. word16 rLength;
  82994. word32 hLength;
  82995. idx = buf;
  82996. tail_len = (unsigned int)*len;
  82997. *found = 0;
  82998. while (tail_len > _RECORD_HEADER_SZ) {
  82999. curr = idx;
  83000. currType = *idx;
  83001. ato16(idx + 3, &rLength);
  83002. idx += _RECORD_HEADER_SZ;
  83003. tail_len -= _RECORD_HEADER_SZ;
  83004. if (tail_len < rLength)
  83005. return -1;
  83006. if (type == _change_cipher_hs && currType == _change_cipher) {
  83007. if (rLength != 1)
  83008. return -1;
  83009. /* match */
  83010. test_remove_msg(curr, *len - (int)(curr - buf),
  83011. len, _RECORD_HEADER_SZ + 1);
  83012. *found = 1;
  83013. return 0;
  83014. }
  83015. if (currType != _handshake) {
  83016. idx += rLength;
  83017. tail_len -= rLength;
  83018. continue;
  83019. }
  83020. if (rLength < _HANDSHAKE_HEADER_SZ)
  83021. return -1;
  83022. currType = *idx;
  83023. ato24(idx+1, &hLength);
  83024. hLength += _HANDSHAKE_HEADER_SZ;
  83025. if (tail_len < hLength)
  83026. return -1;
  83027. if (currType != type) {
  83028. idx += hLength;
  83029. tail_len -= hLength;
  83030. continue;
  83031. }
  83032. /* match */
  83033. test_remove_msg(curr, *len - (int)(curr - buf), len,
  83034. hLength + _RECORD_HEADER_SZ);
  83035. *found = 1;
  83036. return 0;
  83037. }
  83038. /* not found */
  83039. return 0;
  83040. }
  83041. static int test_remove_hs_message(byte hs_message_type,
  83042. int extra_round, byte alert_type)
  83043. {
  83044. EXPECT_DECLS;
  83045. WOLFSSL_CTX *ctx_c = NULL;
  83046. WOLFSSL_CTX *ctx_s = NULL;
  83047. WOLFSSL *ssl_c = NULL;
  83048. WOLFSSL *ssl_s = NULL;
  83049. struct test_memio_ctx test_ctx;
  83050. WOLFSSL_ALERT_HISTORY h;
  83051. byte found = 0;
  83052. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83053. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83054. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  83055. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  83056. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83057. WOLFSSL_ERROR_WANT_READ);
  83058. ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  83059. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83060. WOLFSSL_ERROR_WANT_READ);
  83061. if (extra_round) {
  83062. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  83063. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83064. WOLFSSL_ERROR_WANT_READ);
  83065. /* this will complete handshake from server side */
  83066. ExpectIntEQ(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  83067. }
  83068. ExpectIntEQ(test_remove_hs_msg_from_buffer(test_ctx.c_buff,
  83069. &test_ctx.c_len, hs_message_type, &found), 0);
  83070. if (!found) {
  83071. wolfSSL_free(ssl_c);
  83072. wolfSSL_CTX_free(ctx_c);
  83073. wolfSSL_free(ssl_s);
  83074. wolfSSL_CTX_free(ctx_s);
  83075. return TEST_SKIPPED;
  83076. }
  83077. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  83078. ExpectIntNE(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83079. WOLFSSL_ERROR_WANT_READ);
  83080. ExpectIntEQ(wolfSSL_get_alert_history(ssl_c, &h), WOLFSSL_SUCCESS);
  83081. ExpectTrue(alert_type == 0xff || h.last_tx.code == alert_type);
  83082. ExpectIntEQ(h.last_tx.level, alert_fatal);
  83083. wolfSSL_free(ssl_c);
  83084. wolfSSL_CTX_free(ctx_c);
  83085. wolfSSL_free(ssl_s);
  83086. wolfSSL_CTX_free(ctx_s);
  83087. return EXPECT_RESULT();
  83088. }
  83089. static int test_extra_alerts_skip_hs(void)
  83090. {
  83091. EXPECT_DECLS;
  83092. const byte _server_key_exchange = 12;
  83093. const byte _server_hello = 2;
  83094. const byte _certificate = 11;
  83095. /* server_hello */
  83096. ExpectIntNE(test_remove_hs_message(_server_hello, 0,
  83097. unexpected_message), TEST_FAIL);
  83098. ExpectIntNE(test_remove_hs_message(_certificate, 0,
  83099. 0xff), TEST_FAIL);
  83100. ExpectIntNE(test_remove_hs_message(_server_key_exchange, 0,
  83101. unexpected_message), TEST_FAIL);
  83102. return EXPECT_RESULT();
  83103. }
  83104. #else
  83105. static int test_extra_alerts_skip_hs(void)
  83106. {
  83107. return TEST_SKIPPED;
  83108. }
  83109. #endif
  83110. #if !defined(WOLFSSL_NO_TLS12) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)\
  83111. && defined(WOLFSSL_EXTRA_ALERTS) && !defined(NO_PSK) && !defined(NO_DH)
  83112. static unsigned int test_server_psk_cb(WOLFSSL* ssl, const char* id,
  83113. unsigned char* key, unsigned int key_max_len)
  83114. {
  83115. (void)ssl;
  83116. (void)id;
  83117. (void)key_max_len;
  83118. /* zero means error */
  83119. key[0] = 0x10;
  83120. return 1;
  83121. }
  83122. static int test_extra_alerts_bad_psk(void)
  83123. {
  83124. EXPECT_DECLS;
  83125. WOLFSSL_CTX *ctx_c = NULL;
  83126. WOLFSSL_CTX *ctx_s = NULL;
  83127. WOLFSSL *ssl_c = NULL;
  83128. WOLFSSL *ssl_s = NULL;
  83129. struct test_memio_ctx test_ctx;
  83130. WOLFSSL_ALERT_HISTORY h;
  83131. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83132. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83133. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  83134. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_c, "DHE-PSK-AES128-GCM-SHA256"),
  83135. WOLFSSL_SUCCESS);
  83136. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_s, "DHE-PSK-AES128-GCM-SHA256"),
  83137. WOLFSSL_SUCCESS);
  83138. wolfSSL_set_psk_server_callback(ssl_s, test_server_psk_cb);
  83139. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  83140. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83141. WOLFSSL_ERROR_WANT_READ);
  83142. ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  83143. ExpectIntEQ(wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83144. WOLFSSL_ERROR_WANT_READ);
  83145. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  83146. ExpectIntNE(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83147. WOLFSSL_ERROR_WANT_READ);
  83148. ExpectIntEQ(wolfSSL_get_alert_history(ssl_c, &h), WOLFSSL_SUCCESS);
  83149. ExpectIntEQ(h.last_tx.code, handshake_failure);
  83150. ExpectIntEQ(h.last_tx.level, alert_fatal);
  83151. wolfSSL_free(ssl_c);
  83152. wolfSSL_CTX_free(ctx_c);
  83153. wolfSSL_free(ssl_s);
  83154. wolfSSL_CTX_free(ctx_s);
  83155. return EXPECT_RESULT();
  83156. }
  83157. #else
  83158. static int test_extra_alerts_bad_psk(void)
  83159. {
  83160. return TEST_SKIPPED;
  83161. }
  83162. #endif
  83163. #if defined(OPENSSL_EXTRA) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  83164. /*
  83165. * Emulates wolfSSL_shutdown that goes on EAGAIN,
  83166. * by returning on output WOLFSSL_ERROR_WANT_WRITE.*/
  83167. static int custom_wolfSSL_shutdown(WOLFSSL *ssl, char *buf,
  83168. int sz, void *ctx)
  83169. {
  83170. (void)ssl;
  83171. (void)buf;
  83172. (void)ctx;
  83173. (void)sz;
  83174. return WOLFSSL_CBIO_ERR_WANT_WRITE;
  83175. }
  83176. static int test_multiple_alerts_EAGAIN(void)
  83177. {
  83178. EXPECT_DECLS;
  83179. size_t size_of_last_packet = 0;
  83180. /* declare wolfSSL objects */
  83181. struct test_memio_ctx test_ctx;
  83182. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  83183. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  83184. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83185. /* Create and initialize WOLFSSL_CTX and WOLFSSL objects */
  83186. #ifdef USE_TLSV13
  83187. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83188. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  83189. #else
  83190. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83191. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  83192. #endif
  83193. ExpectNotNull(ctx_c);
  83194. ExpectNotNull(ssl_c);
  83195. ExpectNotNull(ctx_s);
  83196. ExpectNotNull(ssl_s);
  83197. /* Load client certificates into WOLFSSL_CTX */
  83198. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx_c, "./certs/ca-cert.pem", NULL), WOLFSSL_SUCCESS);
  83199. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  83200. /*
  83201. * We set the custom callback for the IO to emulate multiple EAGAINs
  83202. * on shutdown, so we can check that we don't send multiple packets.
  83203. * */
  83204. wolfSSL_SSLSetIOSend(ssl_c, custom_wolfSSL_shutdown);
  83205. /*
  83206. * We call wolfSSL_shutdown multiple times to reproduce the behaviour,
  83207. * to check that it doesn't add the CLOSE_NOTIFY packet multiple times
  83208. * on the output buffer.
  83209. * */
  83210. wolfSSL_shutdown(ssl_c);
  83211. wolfSSL_shutdown(ssl_c);
  83212. if (ssl_c != NULL) {
  83213. size_of_last_packet = ssl_c->buffers.outputBuffer.length;
  83214. }
  83215. wolfSSL_shutdown(ssl_c);
  83216. /*
  83217. * Finally we check the length of the output buffer.
  83218. * */
  83219. ExpectIntEQ((ssl_c->buffers.outputBuffer.length - size_of_last_packet), 0);
  83220. /* Cleanup and return */
  83221. wolfSSL_CTX_free(ctx_c);
  83222. wolfSSL_free(ssl_c);
  83223. wolfSSL_CTX_free(ctx_s);
  83224. wolfSSL_free(ssl_s);
  83225. return EXPECT_RESULT();
  83226. }
  83227. #else
  83228. static int test_multiple_alerts_EAGAIN(void)
  83229. {
  83230. return TEST_SKIPPED;
  83231. }
  83232. #endif
  83233. #if defined(WOLFSSL_TLS13) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)\
  83234. && !defined(NO_PSK)
  83235. static unsigned int test_tls13_bad_psk_binder_client_cb(WOLFSSL* ssl,
  83236. const char* hint, char* identity, unsigned int id_max_len,
  83237. unsigned char* key, unsigned int key_max_len)
  83238. {
  83239. (void)ssl;
  83240. (void)hint;
  83241. (void)key_max_len;
  83242. /* see internal.h MAX_PSK_ID_LEN for PSK identity limit */
  83243. XSTRNCPY(identity, "Client_identity", id_max_len);
  83244. key[0] = 0x20;
  83245. return 1;
  83246. }
  83247. static unsigned int test_tls13_bad_psk_binder_server_cb(WOLFSSL* ssl,
  83248. const char* id, unsigned char* key, unsigned int key_max_len)
  83249. {
  83250. (void)ssl;
  83251. (void)id;
  83252. (void)key_max_len;
  83253. /* zero means error */
  83254. key[0] = 0x10;
  83255. return 1;
  83256. }
  83257. #endif
  83258. static int test_tls13_bad_psk_binder(void)
  83259. {
  83260. EXPECT_DECLS;
  83261. #if defined(WOLFSSL_TLS13) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)\
  83262. && !defined(NO_PSK)
  83263. WOLFSSL_CTX *ctx_c = NULL;
  83264. WOLFSSL_CTX *ctx_s = NULL;
  83265. WOLFSSL *ssl_c = NULL;
  83266. WOLFSSL *ssl_s = NULL;
  83267. struct test_memio_ctx test_ctx;
  83268. WOLFSSL_ALERT_HISTORY h;
  83269. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83270. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83271. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  83272. wolfSSL_set_psk_client_callback(ssl_c, test_tls13_bad_psk_binder_client_cb);
  83273. wolfSSL_set_psk_server_callback(ssl_s, test_tls13_bad_psk_binder_server_cb);
  83274. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  83275. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83276. WOLFSSL_ERROR_WANT_READ);
  83277. ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  83278. ExpectIntEQ( wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83279. WC_NO_ERR_TRACE(BAD_BINDER));
  83280. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  83281. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  83282. WC_NO_ERR_TRACE(FATAL_ERROR));
  83283. ExpectIntEQ(wolfSSL_get_alert_history(ssl_c, &h), WOLFSSL_SUCCESS);
  83284. ExpectIntEQ(h.last_rx.code, illegal_parameter);
  83285. ExpectIntEQ(h.last_rx.level, alert_fatal);
  83286. wolfSSL_free(ssl_c);
  83287. wolfSSL_CTX_free(ctx_c);
  83288. wolfSSL_free(ssl_s);
  83289. wolfSSL_CTX_free(ctx_s);
  83290. #endif
  83291. return EXPECT_RESULT();
  83292. }
  83293. #if defined(WOLFSSL_HARDEN_TLS) && !defined(WOLFSSL_NO_TLS12) && \
  83294. defined(HAVE_IO_TESTS_DEPENDENCIES)
  83295. static int test_harden_no_secure_renegotiation_io_cb(WOLFSSL *ssl, char *buf,
  83296. int sz, void *ctx)
  83297. {
  83298. static int sentServerHello = FALSE;
  83299. if (!sentServerHello) {
  83300. byte renegExt[] = { 0xFF, 0x01, 0x00, 0x01, 0x00 };
  83301. size_t i;
  83302. if (sz < (int)sizeof(renegExt))
  83303. return WOLFSSL_CBIO_ERR_GENERAL;
  83304. /* Remove SCR from ServerHello */
  83305. for (i = 0; i < sz - sizeof(renegExt); i++) {
  83306. if (XMEMCMP(buf + i, renegExt, sizeof(renegExt)) == 0) {
  83307. /* Found the extension. Change it to something unrecognized. */
  83308. buf[i+1] = 0x11;
  83309. break;
  83310. }
  83311. }
  83312. sentServerHello = TRUE;
  83313. }
  83314. return EmbedSend(ssl, buf, sz, ctx);
  83315. }
  83316. static void test_harden_no_secure_renegotiation_ssl_ready(WOLFSSL* ssl)
  83317. {
  83318. wolfSSL_SSLSetIOSend(ssl, test_harden_no_secure_renegotiation_io_cb);
  83319. }
  83320. static void test_harden_no_secure_renegotiation_on_cleanup(WOLFSSL* ssl)
  83321. {
  83322. WOLFSSL_ALERT_HISTORY h;
  83323. AssertIntEQ(wolfSSL_get_alert_history(ssl, &h), WOLFSSL_SUCCESS);
  83324. AssertIntEQ(h.last_rx.code, handshake_failure);
  83325. AssertIntEQ(h.last_rx.level, alert_fatal);
  83326. }
  83327. static int test_harden_no_secure_renegotiation(void)
  83328. {
  83329. EXPECT_DECLS;
  83330. callback_functions client_cbs, server_cbs;
  83331. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  83332. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  83333. client_cbs.method = wolfTLSv1_2_client_method;
  83334. server_cbs.method = wolfTLSv1_2_server_method;
  83335. server_cbs.ssl_ready = test_harden_no_secure_renegotiation_ssl_ready;
  83336. server_cbs.on_cleanup = test_harden_no_secure_renegotiation_on_cleanup;
  83337. test_wolfSSL_client_server_nofail(&client_cbs, &server_cbs);
  83338. ExpectIntEQ(client_cbs.return_code, TEST_FAIL);
  83339. ExpectIntEQ(client_cbs.last_err, WC_NO_ERR_TRACE(SECURE_RENEGOTIATION_E));
  83340. ExpectIntEQ(server_cbs.return_code, TEST_FAIL);
  83341. ExpectTrue(server_cbs.last_err == WC_NO_ERR_TRACE(SOCKET_ERROR_E) ||
  83342. server_cbs.last_err == WC_NO_ERR_TRACE(FATAL_ERROR));
  83343. return EXPECT_RESULT();
  83344. }
  83345. #else
  83346. static int test_harden_no_secure_renegotiation(void)
  83347. {
  83348. return TEST_SKIPPED;
  83349. }
  83350. #endif
  83351. #if defined(HAVE_OCSP) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  83352. static int test_override_alt_cert_chain_cert_cb(int preverify,
  83353. WOLFSSL_X509_STORE_CTX* store)
  83354. {
  83355. fprintf(stderr, "preverify: %d\n", preverify);
  83356. fprintf(stderr, "store->error: %d\n", store->error);
  83357. fprintf(stderr, "error reason: %s\n", wolfSSL_ERR_reason_error_string(store->error));
  83358. if (store->error == WC_NO_ERR_TRACE(OCSP_INVALID_STATUS)) {
  83359. fprintf(stderr, "Overriding OCSP error\n");
  83360. return 1;
  83361. }
  83362. #ifndef WOLFSSL_ALT_CERT_CHAINS
  83363. else if ((store->error == WC_NO_ERR_TRACE(ASN_NO_SIGNER_E) ||
  83364. store->error == WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E)
  83365. #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \
  83366. defined(HAVE_WEBSERVER)
  83367. || store->error == WOLFSSL_X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY
  83368. #endif
  83369. ) && store->error_depth == store->totalCerts - 1) {
  83370. fprintf(stderr, "Overriding no signer error only for root cert\n");
  83371. return 1;
  83372. }
  83373. #endif
  83374. else
  83375. return preverify;
  83376. }
  83377. static int test_override_alt_cert_chain_ocsp_cb(void* ioCtx, const char* url,
  83378. int urlSz, unsigned char* request, int requestSz,
  83379. unsigned char** response)
  83380. {
  83381. (void)ioCtx;
  83382. (void)url;
  83383. (void)urlSz;
  83384. (void)request;
  83385. (void)requestSz;
  83386. (void)response;
  83387. return -1;
  83388. }
  83389. static int test_override_alt_cert_chain_client_ctx_ready(WOLFSSL_CTX* ctx)
  83390. {
  83391. EXPECT_DECLS;
  83392. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER,
  83393. test_override_alt_cert_chain_cert_cb);
  83394. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, WOLFSSL_OCSP_CHECKALL |
  83395. WOLFSSL_OCSP_URL_OVERRIDE), WOLFSSL_SUCCESS);
  83396. ExpectIntEQ(wolfSSL_CTX_SetOCSP_Cb(ctx,
  83397. test_override_alt_cert_chain_ocsp_cb, NULL, NULL), WOLFSSL_SUCCESS);
  83398. ExpectIntEQ(wolfSSL_CTX_SetOCSP_OverrideURL(ctx, "not a url"),
  83399. WOLFSSL_SUCCESS);
  83400. return EXPECT_RESULT();
  83401. }
  83402. static int test_override_alt_cert_chain_client_ctx_ready2(WOLFSSL_CTX* ctx)
  83403. {
  83404. EXPECT_DECLS;
  83405. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, NULL);
  83406. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx, WOLFSSL_OCSP_CHECKALL |
  83407. WOLFSSL_OCSP_URL_OVERRIDE), WOLFSSL_SUCCESS);
  83408. ExpectIntEQ(wolfSSL_CTX_SetOCSP_Cb(ctx,
  83409. test_override_alt_cert_chain_ocsp_cb, NULL, NULL), WOLFSSL_SUCCESS);
  83410. ExpectIntEQ(wolfSSL_CTX_SetOCSP_OverrideURL(ctx, "not a url"),
  83411. WOLFSSL_SUCCESS);
  83412. return EXPECT_RESULT();
  83413. }
  83414. static int test_override_alt_cert_chain_server_ctx_ready(WOLFSSL_CTX* ctx)
  83415. {
  83416. EXPECT_DECLS;
  83417. ExpectIntEQ(wolfSSL_CTX_use_certificate_chain_file(ctx,
  83418. "./certs/intermediate/server-chain-alt.pem"), WOLFSSL_SUCCESS);
  83419. return EXPECT_RESULT();
  83420. }
  83421. static int test_override_alt_cert_chain(void)
  83422. {
  83423. EXPECT_DECLS;
  83424. size_t i;
  83425. struct test_params {
  83426. ctx_cb client_ctx_cb;
  83427. ctx_cb server_ctx_cb;
  83428. int result;
  83429. } params[] = {
  83430. {test_override_alt_cert_chain_client_ctx_ready,
  83431. test_override_alt_cert_chain_server_ctx_ready, TEST_SUCCESS},
  83432. {test_override_alt_cert_chain_client_ctx_ready2,
  83433. test_override_alt_cert_chain_server_ctx_ready, -1001},
  83434. };
  83435. for (i = 0; i < sizeof(params)/sizeof(*params); i++) {
  83436. test_ssl_cbf client_cbs, server_cbs;
  83437. XMEMSET(&client_cbs, 0, sizeof(client_cbs));
  83438. XMEMSET(&server_cbs, 0, sizeof(server_cbs));
  83439. fprintf(stderr, "test config: %d\n", (int)i);
  83440. client_cbs.ctx_ready = params[i].client_ctx_cb;
  83441. server_cbs.ctx_ready = params[i].server_ctx_cb;
  83442. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbs,
  83443. &server_cbs, NULL), params[i].result);
  83444. ExpectIntEQ(client_cbs.return_code,
  83445. params[i].result <= 0 ? -1000 : TEST_SUCCESS);
  83446. ExpectIntEQ(server_cbs.return_code,
  83447. params[i].result <= 0 ? -1000 : TEST_SUCCESS);
  83448. }
  83449. return EXPECT_RESULT();
  83450. }
  83451. #else
  83452. static int test_override_alt_cert_chain(void)
  83453. {
  83454. return TEST_SKIPPED;
  83455. }
  83456. #endif
  83457. #if defined(HAVE_RPK)
  83458. #define svrRpkCertFile "./certs/rpk/server-cert-rpk.der"
  83459. #define clntRpkCertFile "./certs/rpk/client-cert-rpk.der"
  83460. #if defined(WOLFSSL_ALWAYS_VERIFY_CB) && defined(WOLFSSL_TLS13)
  83461. static int MyRpkVerifyCb(int mode, WOLFSSL_X509_STORE_CTX* strctx)
  83462. {
  83463. int ret = WOLFSSL_SUCCESS;
  83464. (void)mode;
  83465. (void)strctx;
  83466. WOLFSSL_ENTER("MyRpkVerifyCb");
  83467. return ret;
  83468. }
  83469. #endif /* WOLFSSL_ALWAYS_VERIFY_CB && WOLFSSL_TLS13 */
  83470. static WC_INLINE int test_rpk_memio_setup(
  83471. struct test_memio_ctx *ctx,
  83472. WOLFSSL_CTX **ctx_c,
  83473. WOLFSSL_CTX **ctx_s,
  83474. WOLFSSL **ssl_c,
  83475. WOLFSSL **ssl_s,
  83476. method_provider method_c,
  83477. method_provider method_s,
  83478. const char* certfile_c, int fmt_cc, /* client cert file path and format */
  83479. const char* certfile_s, int fmt_cs, /* server cert file path and format */
  83480. const char* pkey_c, int fmt_kc, /* client private key and format */
  83481. const char* pkey_s, int fmt_ks /* server private key and format */
  83482. )
  83483. {
  83484. int ret;
  83485. if (ctx_c != NULL && *ctx_c == NULL) {
  83486. *ctx_c = wolfSSL_CTX_new(method_c());
  83487. if (*ctx_c == NULL) {
  83488. return -1;
  83489. }
  83490. wolfSSL_CTX_set_verify(*ctx_c, WOLFSSL_VERIFY_PEER, NULL);
  83491. ret = wolfSSL_CTX_load_verify_locations(*ctx_c, caCertFile, 0);
  83492. if (ret != WOLFSSL_SUCCESS) {
  83493. return -1;
  83494. }
  83495. wolfSSL_SetIORecv(*ctx_c, test_memio_read_cb);
  83496. wolfSSL_SetIOSend(*ctx_c, test_memio_write_cb);
  83497. ret = wolfSSL_CTX_use_certificate_file(*ctx_c, certfile_c, fmt_cc);
  83498. if (ret != WOLFSSL_SUCCESS) {
  83499. return -1;
  83500. }
  83501. ret = wolfSSL_CTX_use_PrivateKey_file(*ctx_c, pkey_c, fmt_kc);
  83502. if (ret != WOLFSSL_SUCCESS) {
  83503. return -1;
  83504. }
  83505. }
  83506. if (ctx_s != NULL && *ctx_s == NULL) {
  83507. *ctx_s = wolfSSL_CTX_new(method_s());
  83508. if (*ctx_s == NULL) {
  83509. return -1;
  83510. }
  83511. wolfSSL_CTX_set_verify(*ctx_s, WOLFSSL_VERIFY_PEER, NULL);
  83512. ret = wolfSSL_CTX_load_verify_locations(*ctx_s, cliCertFile, 0);
  83513. if (ret != WOLFSSL_SUCCESS) {
  83514. return -1;
  83515. }
  83516. ret = wolfSSL_CTX_use_PrivateKey_file(*ctx_s, pkey_s, fmt_ks);
  83517. if (ret != WOLFSSL_SUCCESS) {
  83518. return -1;
  83519. }
  83520. ret = wolfSSL_CTX_use_certificate_file(*ctx_s, certfile_s, fmt_cs);
  83521. if (ret != WOLFSSL_SUCCESS) {
  83522. return -1;
  83523. }
  83524. wolfSSL_SetIORecv(*ctx_s, test_memio_read_cb);
  83525. wolfSSL_SetIOSend(*ctx_s, test_memio_write_cb);
  83526. if (ctx->s_ciphers != NULL) {
  83527. ret = wolfSSL_CTX_set_cipher_list(*ctx_s, ctx->s_ciphers);
  83528. if (ret != WOLFSSL_SUCCESS) {
  83529. return -1;
  83530. }
  83531. }
  83532. }
  83533. if (ctx_c != NULL && ssl_c != NULL) {
  83534. *ssl_c = wolfSSL_new(*ctx_c);
  83535. if (*ssl_c == NULL) {
  83536. return -1;
  83537. }
  83538. wolfSSL_SetIOWriteCtx(*ssl_c, ctx);
  83539. wolfSSL_SetIOReadCtx(*ssl_c, ctx);
  83540. }
  83541. if (ctx_s != NULL && ssl_s != NULL) {
  83542. *ssl_s = wolfSSL_new(*ctx_s);
  83543. if (*ssl_s == NULL) {
  83544. return -1;
  83545. }
  83546. wolfSSL_SetIOWriteCtx(*ssl_s, ctx);
  83547. wolfSSL_SetIOReadCtx(*ssl_s, ctx);
  83548. #if !defined(NO_DH)
  83549. SetDH(*ssl_s);
  83550. #endif
  83551. }
  83552. return 0;
  83553. }
  83554. #endif /* HAVE_RPK */
  83555. static int test_rpk_set_xxx_cert_type(void)
  83556. {
  83557. EXPECT_DECLS;
  83558. #if defined(HAVE_RPK)
  83559. char ctype[MAX_CLIENT_CERT_TYPE_CNT + 1]; /* prepare bigger buffer */
  83560. WOLFSSL_CTX* ctx = NULL;
  83561. WOLFSSL* ssl = NULL;
  83562. int tp;
  83563. ctx = wolfSSL_CTX_new(wolfTLS_client_method());
  83564. ExpectNotNull(ctx);
  83565. ssl = wolfSSL_new(ctx);
  83566. ExpectNotNull(ssl);
  83567. /*--------------------------------------------*/
  83568. /* tests for wolfSSL_CTX_set_client_cert_type */
  83569. /*--------------------------------------------*/
  83570. /* illegal parameter test caces */
  83571. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(NULL, ctype,
  83572. MAX_CLIENT_CERT_TYPE_CNT),
  83573. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83574. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  83575. sizeof(ctype)),
  83576. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83577. ctype[0] = WOLFSSL_CERT_TYPE_RPK; /* set an identical cert type */
  83578. ctype[1] = WOLFSSL_CERT_TYPE_RPK;
  83579. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  83580. MAX_CLIENT_CERT_TYPE_CNT),
  83581. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83582. ctype[0] = WOLFSSL_CERT_TYPE_X509;
  83583. ctype[1] = 10; /* set unknown cert type */
  83584. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  83585. MAX_CLIENT_CERT_TYPE_CNT),
  83586. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83587. /* pass larger type count */
  83588. ctype[0] = WOLFSSL_CERT_TYPE_RPK;
  83589. ctype[1] = WOLFSSL_CERT_TYPE_X509;
  83590. ctype[2] = 1; /* pass unacceptable type count */
  83591. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  83592. MAX_CLIENT_CERT_TYPE_CNT + 1),
  83593. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83594. /* should accept NULL for type buffer */
  83595. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, NULL,
  83596. MAX_CLIENT_CERT_TYPE_CNT),
  83597. WOLFSSL_SUCCESS);
  83598. /* should accept zero for type count */
  83599. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  83600. 0),
  83601. WOLFSSL_SUCCESS);
  83602. ExpectIntEQ(wolfSSL_CTX_set_client_cert_type(ctx, ctype,
  83603. MAX_CLIENT_CERT_TYPE_CNT),
  83604. WOLFSSL_SUCCESS);
  83605. /*--------------------------------------------*/
  83606. /* tests for wolfSSL_CTX_set_server_cert_type */
  83607. /*--------------------------------------------*/
  83608. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(NULL, ctype,
  83609. MAX_SERVER_CERT_TYPE_CNT),
  83610. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83611. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  83612. sizeof(ctype)),
  83613. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83614. ctype[0] = WOLFSSL_CERT_TYPE_RPK; /* set an identical cert type */
  83615. ctype[1] = WOLFSSL_CERT_TYPE_RPK;
  83616. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  83617. MAX_SERVER_CERT_TYPE_CNT),
  83618. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83619. ctype[0] = WOLFSSL_CERT_TYPE_X509;
  83620. ctype[1] = 10; /* set unknown cert type */
  83621. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  83622. MAX_SERVER_CERT_TYPE_CNT),
  83623. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83624. /* pass larger type count */
  83625. ctype[0] = WOLFSSL_CERT_TYPE_RPK;
  83626. ctype[1] = WOLFSSL_CERT_TYPE_X509;
  83627. ctype[2] = 1; /* pass unacceptable type count */
  83628. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  83629. MAX_SERVER_CERT_TYPE_CNT + 1),
  83630. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83631. /* should accept NULL for type buffer */
  83632. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, NULL,
  83633. MAX_SERVER_CERT_TYPE_CNT),
  83634. WOLFSSL_SUCCESS);
  83635. /* should accept zero for type count */
  83636. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  83637. 0),
  83638. WOLFSSL_SUCCESS);
  83639. ExpectIntEQ(wolfSSL_CTX_set_server_cert_type(ctx, ctype,
  83640. MAX_CLIENT_CERT_TYPE_CNT),
  83641. WOLFSSL_SUCCESS);
  83642. /*--------------------------------------------*/
  83643. /* tests for wolfSSL_set_client_cert_type */
  83644. /*--------------------------------------------*/
  83645. ExpectIntEQ(wolfSSL_set_client_cert_type(NULL, ctype,
  83646. MAX_CLIENT_CERT_TYPE_CNT),
  83647. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83648. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  83649. sizeof(ctype)),
  83650. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83651. ctype[0] = WOLFSSL_CERT_TYPE_RPK; /* set an identical cert type */
  83652. ctype[1] = WOLFSSL_CERT_TYPE_RPK;
  83653. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  83654. MAX_CLIENT_CERT_TYPE_CNT),
  83655. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83656. ctype[0] = WOLFSSL_CERT_TYPE_X509;
  83657. ctype[1] = 10; /* set unknown cert type */
  83658. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  83659. MAX_CLIENT_CERT_TYPE_CNT),
  83660. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83661. /* pass larger type count */
  83662. ctype[0] = WOLFSSL_CERT_TYPE_RPK;
  83663. ctype[1] = WOLFSSL_CERT_TYPE_X509;
  83664. ctype[2] = 1; /* pass unacceptable type count */
  83665. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  83666. MAX_CLIENT_CERT_TYPE_CNT + 1),
  83667. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83668. /* should accept NULL for type buffer */
  83669. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, NULL,
  83670. MAX_CLIENT_CERT_TYPE_CNT),
  83671. WOLFSSL_SUCCESS);
  83672. /* should accept zero for type count */
  83673. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  83674. 0),
  83675. WOLFSSL_SUCCESS);
  83676. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl, ctype,
  83677. MAX_CLIENT_CERT_TYPE_CNT),
  83678. WOLFSSL_SUCCESS);
  83679. /*--------------------------------------------*/
  83680. /* tests for wolfSSL_CTX_set_server_cert_type */
  83681. /*--------------------------------------------*/
  83682. ExpectIntEQ(wolfSSL_set_server_cert_type(NULL, ctype,
  83683. MAX_SERVER_CERT_TYPE_CNT),
  83684. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83685. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  83686. sizeof(ctype)),
  83687. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83688. ctype[0] = WOLFSSL_CERT_TYPE_RPK; /* set an identical cert type */
  83689. ctype[1] = WOLFSSL_CERT_TYPE_RPK;
  83690. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  83691. MAX_SERVER_CERT_TYPE_CNT),
  83692. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83693. ctype[0] = WOLFSSL_CERT_TYPE_X509;
  83694. ctype[1] = 10; /* set unknown cert type */
  83695. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  83696. MAX_SERVER_CERT_TYPE_CNT),
  83697. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83698. /* pass larger type count */
  83699. ctype[0] = WOLFSSL_CERT_TYPE_RPK;
  83700. ctype[1] = WOLFSSL_CERT_TYPE_X509;
  83701. ctype[2] = 1; /* pass unacceptable type count */
  83702. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  83703. MAX_SERVER_CERT_TYPE_CNT + 1),
  83704. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83705. /* should accept NULL for type buffer */
  83706. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, NULL,
  83707. MAX_SERVER_CERT_TYPE_CNT),
  83708. WOLFSSL_SUCCESS);
  83709. /* should accept zero for type count */
  83710. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  83711. 0),
  83712. WOLFSSL_SUCCESS);
  83713. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl, ctype,
  83714. MAX_SERVER_CERT_TYPE_CNT),
  83715. WOLFSSL_SUCCESS);
  83716. /*------------------------------------------------*/
  83717. /* tests for wolfSSL_get_negotiated_xxx_cert_type */
  83718. /*------------------------------------------------*/
  83719. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(NULL, &tp),
  83720. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83721. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl, NULL),
  83722. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83723. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(NULL, &tp),
  83724. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83725. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl, NULL),
  83726. WC_NO_ERR_TRACE(BAD_FUNC_ARG));
  83727. /* clean up */
  83728. wolfSSL_free(ssl);
  83729. wolfSSL_CTX_free(ctx);
  83730. #endif
  83731. return EXPECT_RESULT();
  83732. }
  83733. static int test_tls13_rpk_handshake(void)
  83734. {
  83735. EXPECT_DECLS;
  83736. #if defined(HAVE_RPK) && (!defined(WOLFSSL_NO_TLS12) || defined(WOLFSSL_TLS13))
  83737. #ifdef WOLFSSL_TLS13
  83738. int ret = 0;
  83739. #endif
  83740. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  83741. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  83742. struct test_memio_ctx test_ctx;
  83743. int err;
  83744. char certType_c[MAX_CLIENT_CERT_TYPE_CNT];
  83745. char certType_s[MAX_CLIENT_CERT_TYPE_CNT];
  83746. int typeCnt_c;
  83747. int typeCnt_s;
  83748. int tp = 0;
  83749. #if defined(WOLFSSL_ALWAYS_VERIFY_CB) && defined(WOLFSSL_TLS13)
  83750. int isServer;
  83751. #endif
  83752. (void)err;
  83753. (void)typeCnt_c;
  83754. (void)typeCnt_s;
  83755. (void)certType_c;
  83756. (void)certType_s;
  83757. #ifndef WOLFSSL_NO_TLS12
  83758. /* TLS1.2
  83759. * Both client and server load x509 cert and start handshaking.
  83760. * Check no negotiation occurred.
  83761. */
  83762. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83763. ExpectIntEQ(
  83764. test_rpk_memio_setup(
  83765. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83766. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method,
  83767. cliCertFile, WOLFSSL_FILETYPE_PEM,
  83768. svrCertFile, WOLFSSL_FILETYPE_PEM,
  83769. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  83770. svrKeyFile, WOLFSSL_FILETYPE_PEM)
  83771. , 0);
  83772. /* set client certificate type in client end */
  83773. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  83774. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  83775. typeCnt_c = 2;
  83776. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  83777. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  83778. typeCnt_s = 2;
  83779. /* both client and server do not call client/server_cert_type APIs,
  83780. * expecting default settings works and no negotiation performed.
  83781. */
  83782. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  83783. return TEST_FAIL;
  83784. /* confirm no negotiation occurred */
  83785. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  83786. WOLFSSL_SUCCESS);
  83787. ExpectIntEQ((int)tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  83788. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  83789. WOLFSSL_SUCCESS);
  83790. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  83791. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  83792. WOLFSSL_SUCCESS);
  83793. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  83794. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  83795. WOLFSSL_SUCCESS);
  83796. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  83797. (void)typeCnt_c;
  83798. (void)typeCnt_s;
  83799. wolfSSL_free(ssl_c);
  83800. wolfSSL_CTX_free(ctx_c);
  83801. wolfSSL_free(ssl_s);
  83802. wolfSSL_CTX_free(ctx_s);
  83803. ssl_c = ssl_s = NULL;
  83804. ctx_c = ctx_s = NULL;
  83805. #endif
  83806. #ifdef WOLFSSL_TLS13
  83807. /* Both client and server load x509 cert and start handshaking.
  83808. * Check no negotiation occurred.
  83809. */
  83810. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83811. ExpectIntEQ(
  83812. test_rpk_memio_setup(
  83813. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83814. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  83815. cliCertFile, WOLFSSL_FILETYPE_PEM,
  83816. svrCertFile, WOLFSSL_FILETYPE_PEM,
  83817. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  83818. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  83819. , 0);
  83820. /* set client certificate type in client end */
  83821. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  83822. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  83823. typeCnt_c = 2;
  83824. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  83825. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  83826. typeCnt_s = 2;
  83827. /* both client and server do not call client/server_cert_type APIs,
  83828. * expecting default settings works and no negotiation performed.
  83829. */
  83830. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  83831. return TEST_FAIL;
  83832. /* confirm no negotiation occurred */
  83833. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  83834. WOLFSSL_SUCCESS);
  83835. ExpectIntEQ((int)tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  83836. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  83837. WOLFSSL_SUCCESS);
  83838. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  83839. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  83840. WOLFSSL_SUCCESS);
  83841. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  83842. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  83843. WOLFSSL_SUCCESS);
  83844. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  83845. (void)typeCnt_c;
  83846. (void)typeCnt_s;
  83847. wolfSSL_free(ssl_c);
  83848. wolfSSL_CTX_free(ctx_c);
  83849. wolfSSL_free(ssl_s);
  83850. wolfSSL_CTX_free(ctx_s);
  83851. ssl_c = ssl_s = NULL;
  83852. ctx_c = ctx_s = NULL;
  83853. /* Both client and server load RPK cert and start handshaking.
  83854. * Confirm negotiated cert types match as expected.
  83855. */
  83856. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83857. ExpectIntEQ(
  83858. test_rpk_memio_setup(
  83859. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83860. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  83861. clntRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  83862. svrRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  83863. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  83864. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  83865. , 0);
  83866. /* set client certificate type in client end */
  83867. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  83868. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  83869. typeCnt_c = 2;
  83870. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  83871. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  83872. typeCnt_s = 2;
  83873. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  83874. WOLFSSL_SUCCESS);
  83875. /* set server certificate type in client end */
  83876. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  83877. WOLFSSL_SUCCESS);
  83878. /* set client certificate type in server end */
  83879. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  83880. WOLFSSL_SUCCESS);
  83881. /* set server certificate type in server end */
  83882. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  83883. WOLFSSL_SUCCESS);
  83884. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  83885. return TEST_FAIL;
  83886. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  83887. WOLFSSL_SUCCESS);
  83888. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83889. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  83890. WOLFSSL_SUCCESS);
  83891. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83892. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  83893. WOLFSSL_SUCCESS);
  83894. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83895. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  83896. WOLFSSL_SUCCESS);
  83897. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83898. wolfSSL_free(ssl_c);
  83899. wolfSSL_CTX_free(ctx_c);
  83900. wolfSSL_free(ssl_s);
  83901. wolfSSL_CTX_free(ctx_s);
  83902. ssl_c = ssl_s = NULL;
  83903. ctx_c = ctx_s = NULL;
  83904. #endif
  83905. #ifndef WOLFSSL_NO_TLS12
  83906. /* TLS1.2
  83907. * Both client and server load RPK cert and start handshaking.
  83908. * Confirm negotiated cert types match as expected.
  83909. */
  83910. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83911. ExpectIntEQ(
  83912. test_rpk_memio_setup(
  83913. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83914. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method,
  83915. clntRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  83916. svrRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  83917. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  83918. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  83919. , 0);
  83920. /* set client certificate type in client end */
  83921. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  83922. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  83923. typeCnt_c = 2;
  83924. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  83925. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  83926. typeCnt_s = 2;
  83927. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  83928. WOLFSSL_SUCCESS);
  83929. /* set server certificate type in client end */
  83930. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  83931. WOLFSSL_SUCCESS);
  83932. /* set client certificate type in server end */
  83933. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  83934. WOLFSSL_SUCCESS);
  83935. /* set server certificate type in server end */
  83936. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  83937. WOLFSSL_SUCCESS);
  83938. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  83939. return TEST_FAIL;
  83940. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  83941. WOLFSSL_SUCCESS);
  83942. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83943. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  83944. WOLFSSL_SUCCESS);
  83945. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83946. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  83947. WOLFSSL_SUCCESS);
  83948. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83949. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  83950. WOLFSSL_SUCCESS);
  83951. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  83952. wolfSSL_free(ssl_c);
  83953. wolfSSL_CTX_free(ctx_c);
  83954. wolfSSL_free(ssl_s);
  83955. wolfSSL_CTX_free(ctx_s);
  83956. ssl_c = ssl_s = NULL;
  83957. ctx_c = ctx_s = NULL;
  83958. #endif
  83959. #ifdef WOLFSSL_TLS13
  83960. /* Both client and server load x509 cert.
  83961. * Have client call set_client_cert_type with both RPK and x509.
  83962. * This doesn't makes client add client cert type extension to ClientHello,
  83963. * since it does not load RPK cert actually.
  83964. */
  83965. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  83966. ExpectIntEQ(
  83967. test_rpk_memio_setup(
  83968. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  83969. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  83970. cliCertFile, WOLFSSL_FILETYPE_PEM,
  83971. svrCertFile, WOLFSSL_FILETYPE_PEM,
  83972. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  83973. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  83974. , 0);
  83975. /* set client certificate type in client end
  83976. *
  83977. * client indicates both RPK and x509 certs are available but loaded RPK
  83978. * cert only. It does not have client add client-cert-type extension in CH.
  83979. */
  83980. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  83981. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  83982. typeCnt_c = 2;
  83983. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  83984. WOLFSSL_SUCCESS);
  83985. /* client indicates both RPK and x509 certs are acceptable */
  83986. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  83987. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  83988. typeCnt_s = 2;
  83989. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  83990. WOLFSSL_SUCCESS);
  83991. /* server indicates both RPK and x509 certs are acceptable */
  83992. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  83993. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  83994. typeCnt_c = 2;
  83995. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  83996. WOLFSSL_SUCCESS);
  83997. /* server should indicate only RPK cert is available */
  83998. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  83999. certType_s[1] = -1;
  84000. typeCnt_s = 1;
  84001. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  84002. WOLFSSL_SUCCESS);
  84003. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  84004. return TEST_FAIL;
  84005. /* Negotiation for client-cert-type should NOT happen. Therefore -1 should
  84006. * be returned as cert type.
  84007. */
  84008. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  84009. WOLFSSL_SUCCESS);
  84010. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  84011. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  84012. WOLFSSL_SUCCESS);
  84013. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  84014. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  84015. WOLFSSL_SUCCESS);
  84016. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  84017. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  84018. WOLFSSL_SUCCESS);
  84019. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  84020. wolfSSL_free(ssl_c);
  84021. wolfSSL_CTX_free(ctx_c);
  84022. wolfSSL_free(ssl_s);
  84023. wolfSSL_CTX_free(ctx_s);
  84024. ssl_c = ssl_s = NULL;
  84025. ctx_c = ctx_s = NULL;
  84026. /* Have client load RPK cert and have server load x509 cert.
  84027. * Check the negotiation result from both ends.
  84028. */
  84029. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84030. ExpectIntEQ(
  84031. test_rpk_memio_setup(
  84032. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84033. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  84034. clntRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  84035. svrCertFile, WOLFSSL_FILETYPE_PEM,
  84036. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  84037. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  84038. , 0);
  84039. /* have client tell to use RPK cert */
  84040. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  84041. certType_c[1] = -1;
  84042. typeCnt_c = 1;
  84043. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  84044. WOLFSSL_SUCCESS);
  84045. /* have client tell to accept both RPK and x509 cert */
  84046. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  84047. certType_s[1] = WOLFSSL_CERT_TYPE_RPK;
  84048. typeCnt_s = 2;
  84049. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  84050. WOLFSSL_SUCCESS);
  84051. /* have server accept to both RPK and x509 cert */
  84052. certType_c[0] = WOLFSSL_CERT_TYPE_X509;
  84053. certType_c[1] = WOLFSSL_CERT_TYPE_RPK;
  84054. typeCnt_c = 2;
  84055. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  84056. WOLFSSL_SUCCESS);
  84057. /* does not call wolfSSL_set_server_cert_type intentionally in sesrver
  84058. * end, expecting the default setting works.
  84059. */
  84060. if (test_memio_do_handshake(ssl_c, ssl_s, 10, NULL) != 0)
  84061. return TEST_FAIL;
  84062. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  84063. WOLFSSL_SUCCESS);
  84064. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  84065. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  84066. WOLFSSL_SUCCESS);
  84067. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  84068. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  84069. WOLFSSL_SUCCESS);
  84070. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  84071. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  84072. WOLFSSL_SUCCESS);
  84073. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  84074. wolfSSL_free(ssl_c);
  84075. wolfSSL_CTX_free(ctx_c);
  84076. wolfSSL_free(ssl_s);
  84077. wolfSSL_CTX_free(ctx_s);
  84078. ssl_c = ssl_s = NULL;
  84079. ctx_c = ctx_s = NULL;
  84080. /* Have both client and server load RPK cert, however, have server
  84081. * indicate its cert type x509.
  84082. * Client is expected to detect the cert type mismatch then to send alert
  84083. * with "unsupported_certificate".
  84084. */
  84085. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84086. ExpectIntEQ(
  84087. test_rpk_memio_setup(
  84088. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84089. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  84090. clntRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  84091. svrRpkCertFile, WOLFSSL_FILETYPE_ASN1, /* server sends RPK cert */
  84092. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  84093. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  84094. , 0);
  84095. /* have client tell to use RPK cert */
  84096. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  84097. certType_c[1] = -1;
  84098. typeCnt_c = 1;
  84099. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  84100. WOLFSSL_SUCCESS);
  84101. /* have client tell to accept both RPK and x509 cert */
  84102. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  84103. certType_s[1] = WOLFSSL_CERT_TYPE_RPK;
  84104. typeCnt_s = 2;
  84105. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  84106. WOLFSSL_SUCCESS);
  84107. /* have server accept to both RPK and x509 cert */
  84108. certType_c[0] = WOLFSSL_CERT_TYPE_X509;
  84109. certType_c[1] = WOLFSSL_CERT_TYPE_RPK;
  84110. typeCnt_c = 2;
  84111. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  84112. WOLFSSL_SUCCESS);
  84113. /* have server tell to use x509 cert intentionally. This will bring
  84114. * certificate type mismatch in client side.
  84115. */
  84116. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  84117. certType_s[1] = -1;
  84118. typeCnt_s = 1;
  84119. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  84120. WOLFSSL_SUCCESS);
  84121. /* expect client detect cert type mismatch then send Alert */
  84122. ret = test_memio_do_handshake(ssl_c, ssl_s, 10, NULL);
  84123. if (ret != -1)
  84124. return TEST_FAIL;
  84125. ExpectIntEQ(wolfSSL_get_error(ssl_c, ret), WC_NO_ERR_TRACE(UNSUPPORTED_CERTIFICATE));
  84126. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  84127. WOLFSSL_SUCCESS);
  84128. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  84129. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  84130. WOLFSSL_SUCCESS);
  84131. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  84132. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  84133. WOLFSSL_SUCCESS);
  84134. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  84135. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  84136. WOLFSSL_SUCCESS);
  84137. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  84138. wolfSSL_free(ssl_c);
  84139. wolfSSL_CTX_free(ctx_c);
  84140. wolfSSL_free(ssl_s);
  84141. wolfSSL_CTX_free(ctx_s);
  84142. ssl_c = ssl_s = NULL;
  84143. ctx_c = ctx_s = NULL;
  84144. /* Have client load x509 cert and server load RPK cert,
  84145. * however, have client indicate its cert type RPK.
  84146. * Server is expected to detect the cert type mismatch then to send alert
  84147. * with "unsupported_certificate".
  84148. */
  84149. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84150. ExpectIntEQ(
  84151. test_rpk_memio_setup(
  84152. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84153. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  84154. cliCertFile, WOLFSSL_FILETYPE_PEM,
  84155. svrRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  84156. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  84157. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  84158. , 0);
  84159. /* have client tell to use RPK cert intentionally */
  84160. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  84161. certType_c[1] = -1;
  84162. typeCnt_c = 1;
  84163. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  84164. WOLFSSL_SUCCESS);
  84165. /* have client tell to accept both RPK and x509 cert */
  84166. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  84167. certType_s[1] = WOLFSSL_CERT_TYPE_RPK;
  84168. typeCnt_s = 2;
  84169. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  84170. WOLFSSL_SUCCESS);
  84171. /* have server accept to both RPK and x509 cert */
  84172. certType_c[0] = WOLFSSL_CERT_TYPE_X509;
  84173. certType_c[1] = WOLFSSL_CERT_TYPE_RPK;
  84174. typeCnt_c = 2;
  84175. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  84176. WOLFSSL_SUCCESS);
  84177. /* have server tell to use x509 cert intentionally. This will bring
  84178. * certificate type mismatch in client side.
  84179. */
  84180. certType_s[0] = WOLFSSL_CERT_TYPE_X509;
  84181. certType_s[1] = -1;
  84182. typeCnt_s = 1;
  84183. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  84184. WOLFSSL_SUCCESS);
  84185. ret = test_memio_do_handshake(ssl_c, ssl_s, 10, NULL);
  84186. /* expect server detect cert type mismatch then send Alert */
  84187. ExpectIntNE(ret, 0);
  84188. err = wolfSSL_get_error(ssl_c, ret);
  84189. ExpectIntEQ(err, WC_NO_ERR_TRACE(UNSUPPORTED_CERTIFICATE));
  84190. /* client did not load RPK cert actually, so negotiation did not happen */
  84191. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  84192. WOLFSSL_SUCCESS);
  84193. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  84194. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  84195. WOLFSSL_SUCCESS);
  84196. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  84197. /* client did not load RPK cert actually, so negotiation did not happen */
  84198. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  84199. WOLFSSL_SUCCESS);
  84200. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_UNKNOWN);
  84201. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  84202. WOLFSSL_SUCCESS);
  84203. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_X509);
  84204. wolfSSL_free(ssl_c);
  84205. wolfSSL_CTX_free(ctx_c);
  84206. wolfSSL_free(ssl_s);
  84207. wolfSSL_CTX_free(ctx_s);
  84208. ssl_c = ssl_s = NULL;
  84209. ctx_c = ctx_s = NULL;
  84210. #if defined(WOLFSSL_ALWAYS_VERIFY_CB)
  84211. /* Both client and server load RPK cert and set certificate verify
  84212. * callbacks then start handshaking.
  84213. * Confirm both side can refer the peer's cert.
  84214. */
  84215. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84216. ExpectIntEQ(
  84217. test_rpk_memio_setup(
  84218. &test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84219. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  84220. clntRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  84221. svrRpkCertFile, WOLFSSL_FILETYPE_ASN1,
  84222. cliKeyFile, WOLFSSL_FILETYPE_PEM,
  84223. svrKeyFile, WOLFSSL_FILETYPE_PEM )
  84224. , 0);
  84225. /* set client certificate type in client end */
  84226. certType_c[0] = WOLFSSL_CERT_TYPE_RPK;
  84227. certType_c[1] = WOLFSSL_CERT_TYPE_X509;
  84228. typeCnt_c = 2;
  84229. certType_s[0] = WOLFSSL_CERT_TYPE_RPK;
  84230. certType_s[1] = WOLFSSL_CERT_TYPE_X509;
  84231. typeCnt_s = 2;
  84232. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_c, certType_c, typeCnt_c),
  84233. WOLFSSL_SUCCESS);
  84234. /* set server certificate type in client end */
  84235. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_c, certType_s, typeCnt_s),
  84236. WOLFSSL_SUCCESS);
  84237. /* set client certificate type in server end */
  84238. ExpectIntEQ(wolfSSL_set_client_cert_type(ssl_s, certType_c, typeCnt_c),
  84239. WOLFSSL_SUCCESS);
  84240. /* set server certificate type in server end */
  84241. ExpectIntEQ(wolfSSL_set_server_cert_type(ssl_s, certType_s, typeCnt_s),
  84242. WOLFSSL_SUCCESS);
  84243. /* set certificate verify callback to both client and server */
  84244. isServer = 0;
  84245. wolfSSL_SetCertCbCtx(ssl_c, &isServer);
  84246. wolfSSL_set_verify(ssl_c, SSL_VERIFY_PEER, MyRpkVerifyCb);
  84247. isServer = 1;
  84248. wolfSSL_SetCertCbCtx(ssl_c, &isServer);
  84249. wolfSSL_set_verify(ssl_s, SSL_VERIFY_PEER, MyRpkVerifyCb);
  84250. ret = test_memio_do_handshake(ssl_c, ssl_s, 10, NULL);
  84251. if (ret != 0)
  84252. return TEST_FAIL;
  84253. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_c, &tp),
  84254. WOLFSSL_SUCCESS);
  84255. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  84256. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_c, &tp),
  84257. WOLFSSL_SUCCESS);
  84258. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  84259. ExpectIntEQ(wolfSSL_get_negotiated_client_cert_type(ssl_s, &tp),
  84260. WOLFSSL_SUCCESS);
  84261. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  84262. ExpectIntEQ(wolfSSL_get_negotiated_server_cert_type(ssl_s, &tp),
  84263. WOLFSSL_SUCCESS);
  84264. ExpectIntEQ(tp, WOLFSSL_CERT_TYPE_RPK);
  84265. wolfSSL_free(ssl_c);
  84266. wolfSSL_CTX_free(ctx_c);
  84267. wolfSSL_free(ssl_s);
  84268. wolfSSL_CTX_free(ctx_s);
  84269. ssl_c = ssl_s = NULL;
  84270. ctx_c = ctx_s = NULL;
  84271. #endif /* WOLFSSL_ALWAYS_VERIFY_CB */
  84272. #endif /* WOLFSSL_TLS13 */
  84273. #endif /* HAVE_RPK && (!WOLFSSL_NO_TLS12 || WOLFSSL_TLS13) */
  84274. return EXPECT_RESULT();
  84275. }
  84276. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13)
  84277. static int test_dtls13_bad_epoch_ch(void)
  84278. {
  84279. EXPECT_DECLS;
  84280. WOLFSSL_CTX *ctx_c = NULL;
  84281. WOLFSSL_CTX *ctx_s = NULL;
  84282. WOLFSSL *ssl_c = NULL;
  84283. WOLFSSL *ssl_s = NULL;
  84284. struct test_memio_ctx test_ctx;
  84285. const int EPOCH_OFF = 3;
  84286. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84287. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84288. wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0);
  84289. /* disable hrr cookie so we can later check msgsReceived.got_client_hello
  84290. * with just one message */
  84291. ExpectIntEQ(wolfSSL_disable_hrr_cookie(ssl_s), WOLFSSL_SUCCESS);
  84292. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  84293. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  84294. WOLFSSL_ERROR_WANT_READ);
  84295. ExpectIntGE(test_ctx.s_len, EPOCH_OFF + 2);
  84296. /* first CH should use epoch 0x0 */
  84297. ExpectTrue((test_ctx.s_buff[EPOCH_OFF] == 0x0) &&
  84298. (test_ctx.s_buff[EPOCH_OFF + 1] == 0x0));
  84299. /* change epoch to 2 */
  84300. test_ctx.s_buff[EPOCH_OFF + 1] = 0x2;
  84301. ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  84302. ExpectIntEQ(wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  84303. WOLFSSL_ERROR_WANT_READ);
  84304. ExpectIntNE(ssl_s->msgsReceived.got_client_hello, 1);
  84305. /* resend the CH */
  84306. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  84307. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  84308. wolfSSL_free(ssl_c);
  84309. wolfSSL_CTX_free(ctx_c);
  84310. wolfSSL_free(ssl_s);
  84311. wolfSSL_CTX_free(ctx_s);
  84312. return EXPECT_RESULT();
  84313. }
  84314. #else
  84315. static int test_dtls13_bad_epoch_ch(void)
  84316. {
  84317. return TEST_SKIPPED;
  84318. }
  84319. #endif
  84320. #if ((defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  84321. defined(HAVE_SESSION_TICKET) && defined(WOLFSSL_TICKET_HAVE_ID) && \
  84322. !defined(WOLFSSL_TLS13_MIDDLEBOX_COMPAT)) || \
  84323. (!defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \
  84324. !defined(NO_DES3))) || !defined(WOLFSSL_NO_TLS12)) && \
  84325. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  84326. defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && !defined(NO_SESSION_CACHE)
  84327. static int test_short_session_id_ssl_ready(WOLFSSL* ssl)
  84328. {
  84329. EXPECT_DECLS;
  84330. WOLFSSL_SESSION *sess = NULL;
  84331. /* Setup the session to avoid errors */
  84332. ssl->session->timeout = (word32)-1;
  84333. ssl->session->side = WOLFSSL_CLIENT_END;
  84334. #if defined(SESSION_CERTS) || (defined(WOLFSSL_TLS13) && \
  84335. defined(HAVE_SESSION_TICKET))
  84336. ssl->session->version = ssl->version;
  84337. #endif
  84338. /* Force a short session ID to be sent */
  84339. ssl->session->sessionIDSz = 4;
  84340. #ifndef NO_SESSION_CACHE_REF
  84341. /* Allow the client cache to be used */
  84342. ssl->session->idLen = 4;
  84343. #endif
  84344. ssl->session->isSetup = 1;
  84345. ExpectNotNull(sess = wolfSSL_get_session(ssl));
  84346. ExpectIntEQ(wolfSSL_set_session(ssl, sess), WOLFSSL_SUCCESS);
  84347. return EXPECT_RESULT();
  84348. }
  84349. static int test_short_session_id(void)
  84350. {
  84351. EXPECT_DECLS;
  84352. test_ssl_cbf client_cbf;
  84353. test_ssl_cbf server_cbf;
  84354. size_t i;
  84355. struct {
  84356. method_provider client_meth;
  84357. method_provider server_meth;
  84358. const char* tls_version;
  84359. } params[] = {
  84360. #if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && \
  84361. defined(HAVE_SESSION_TICKET) && defined(WOLFSSL_TICKET_HAVE_ID) && \
  84362. !defined(WOLFSSL_TLS13_MIDDLEBOX_COMPAT)
  84363. /* With WOLFSSL_TLS13_MIDDLEBOX_COMPAT a short ID will result in an error */
  84364. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLSv1_3" },
  84365. #ifdef WOLFSSL_DTLS13
  84366. { wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, "DTLSv1_3" },
  84367. #endif
  84368. #endif
  84369. #ifndef WOLFSSL_NO_TLS12
  84370. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLSv1_2" },
  84371. #ifdef WOLFSSL_DTLS
  84372. { wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, "DTLSv1_2" },
  84373. #endif
  84374. #endif
  84375. #if !defined(NO_OLD_TLS) && ((!defined(NO_AES) && !defined(NO_AES_CBC)) || \
  84376. !defined(NO_DES3))
  84377. { wolfTLSv1_1_client_method, wolfTLSv1_1_server_method, "TLSv1_1" },
  84378. #ifdef WOLFSSL_DTLS
  84379. { wolfDTLSv1_client_method, wolfDTLSv1_server_method, "DTLSv1_0" },
  84380. #endif
  84381. #endif
  84382. };
  84383. fprintf(stderr, "\n");
  84384. for (i = 0; i < sizeof(params)/sizeof(*params) && !EXPECT_FAIL(); i++) {
  84385. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  84386. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  84387. fprintf(stderr, "\tTesting short ID with %s\n", params[i].tls_version);
  84388. client_cbf.ssl_ready = test_short_session_id_ssl_ready;
  84389. client_cbf.method = params[i].client_meth;
  84390. server_cbf.method = params[i].server_meth;
  84391. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  84392. &server_cbf, NULL), TEST_SUCCESS);
  84393. }
  84394. return EXPECT_RESULT();
  84395. }
  84396. #else
  84397. static int test_short_session_id(void)
  84398. {
  84399. return TEST_SKIPPED;
  84400. }
  84401. #endif
  84402. #if defined(HAVE_NULL_CIPHER) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) \
  84403. && defined(WOLFSSL_DTLS13)
  84404. static byte* test_find_string(const char *string,
  84405. byte *buf, int buf_size)
  84406. {
  84407. int string_size, i;
  84408. string_size = (int)XSTRLEN(string);
  84409. for (i = 0; i < buf_size - string_size - 1; i++) {
  84410. if (XSTRCMP((char*)&buf[i], string) == 0)
  84411. return &buf[i];
  84412. }
  84413. return NULL;
  84414. }
  84415. static int test_wolfSSL_dtls13_null_cipher(void)
  84416. {
  84417. EXPECT_DECLS;
  84418. WOLFSSL_CTX *ctx_c = NULL;
  84419. WOLFSSL_CTX *ctx_s = NULL;
  84420. WOLFSSL *ssl_c = NULL;
  84421. WOLFSSL *ssl_s = NULL;
  84422. struct test_memio_ctx test_ctx;
  84423. const char *test_str = "test";
  84424. int test_str_size;
  84425. byte buf[255], *ptr = NULL;
  84426. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84427. test_ctx.c_ciphers = test_ctx.s_ciphers = "TLS13-SHA256-SHA256";
  84428. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84429. wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0);
  84430. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  84431. test_str_size = XSTRLEN("test") + 1;
  84432. ExpectIntEQ(wolfSSL_write(ssl_c, test_str, test_str_size), test_str_size);
  84433. ExpectIntEQ(wolfSSL_read(ssl_s, buf, sizeof(buf)), test_str_size);
  84434. ExpectIntEQ(XSTRCMP((char*)buf, test_str), 0);
  84435. ExpectIntEQ(wolfSSL_write(ssl_c, test_str, test_str_size), test_str_size);
  84436. /* check that the packet was sent cleartext */
  84437. ExpectNotNull(ptr = test_find_string(test_str, test_ctx.s_buff,
  84438. test_ctx.s_len));
  84439. if (ptr != NULL) {
  84440. /* modify the message */
  84441. *ptr = 'H';
  84442. /* bad messages should be ignored in DTLS */
  84443. ExpectIntEQ(wolfSSL_read(ssl_s, buf, sizeof(buf)), -1);
  84444. ExpectIntEQ(ssl_s->error, WC_NO_ERR_TRACE(WANT_READ));
  84445. }
  84446. ExpectIntEQ(wolfSSL_shutdown(ssl_c), WOLFSSL_SHUTDOWN_NOT_DONE);
  84447. ExpectIntEQ(wolfSSL_shutdown(ssl_s), WOLFSSL_SHUTDOWN_NOT_DONE);
  84448. ExpectIntEQ(wolfSSL_shutdown(ssl_c), 1);
  84449. ExpectIntEQ(wolfSSL_shutdown(ssl_s), 1);
  84450. wolfSSL_free(ssl_c);
  84451. wolfSSL_free(ssl_s);
  84452. wolfSSL_CTX_free(ctx_c);
  84453. wolfSSL_CTX_free(ctx_s);
  84454. return TEST_SUCCESS;
  84455. }
  84456. #else
  84457. static int test_wolfSSL_dtls13_null_cipher(void)
  84458. {
  84459. return TEST_SKIPPED;
  84460. }
  84461. #endif
  84462. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  84463. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  84464. !defined(SINGLE_THREADED) && !defined(NO_RSA)
  84465. static int test_dtls_msg_get_connected_port(int fd, word16 *port)
  84466. {
  84467. SOCKADDR_S peer;
  84468. XSOCKLENT len;
  84469. int ret;
  84470. XMEMSET((byte*)&peer, 0, sizeof(peer));
  84471. len = sizeof(peer);
  84472. ret = getpeername(fd, (SOCKADDR*)&peer, &len);
  84473. if (ret != 0 || len > (XSOCKLENT)sizeof(peer))
  84474. return -1;
  84475. switch (peer.ss_family) {
  84476. #ifdef WOLFSSL_IPV6
  84477. case WOLFSSL_IP6: {
  84478. *port = ntohs(((SOCKADDR_IN6*)&peer)->sin6_port);
  84479. break;
  84480. }
  84481. #endif /* WOLFSSL_IPV6 */
  84482. case WOLFSSL_IP4:
  84483. *port = ntohs(((SOCKADDR_IN*)&peer)->sin_port);
  84484. break;
  84485. default:
  84486. return -1;
  84487. }
  84488. return 0;
  84489. }
  84490. static int test_dtls_msg_from_other_peer_cb(WOLFSSL_CTX *ctx, WOLFSSL *ssl)
  84491. {
  84492. char buf[1] = {'t'};
  84493. SOCKADDR_IN_T addr;
  84494. int sock_fd;
  84495. word16 port;
  84496. int err;
  84497. (void)ssl;
  84498. (void)ctx;
  84499. if (ssl == NULL)
  84500. return -1;
  84501. err = test_dtls_msg_get_connected_port(wolfSSL_get_fd(ssl), &port);
  84502. if (err != 0)
  84503. return -1;
  84504. sock_fd = socket(AF_INET_V, SOCK_DGRAM, 0);
  84505. if (sock_fd == -1)
  84506. return -1;
  84507. build_addr(&addr, wolfSSLIP, port, 1, 0);
  84508. /* send a packet to the server. Being another socket, the kernel will ensure
  84509. * the source port will be different. */
  84510. err = (int)sendto(sock_fd, buf, sizeof(buf), 0, (SOCKADDR*)&addr,
  84511. sizeof(addr));
  84512. close(sock_fd);
  84513. if (err == -1)
  84514. return -1;
  84515. return 0;
  84516. }
  84517. /* setup a SSL session but just after the handshake send a packet to the server
  84518. * with a source address different than the one of the connected client. The I/O
  84519. * callback EmbedRecvFrom should just ignore the packet. Sending of the packet
  84520. * is done in test_dtls_msg_from_other_peer_cb */
  84521. static int test_dtls_msg_from_other_peer(void)
  84522. {
  84523. EXPECT_DECLS;
  84524. callback_functions client_cbs;
  84525. callback_functions server_cbs;
  84526. XMEMSET((byte*)&client_cbs, 0, sizeof(client_cbs));
  84527. XMEMSET((byte*)&server_cbs, 0, sizeof(server_cbs));
  84528. client_cbs.method = wolfDTLSv1_2_client_method;
  84529. server_cbs.method = wolfDTLSv1_2_server_method;
  84530. client_cbs.doUdp = 1;
  84531. server_cbs.doUdp = 1;
  84532. test_wolfSSL_client_server_nofail_ex(&client_cbs, &server_cbs,
  84533. test_dtls_msg_from_other_peer_cb);
  84534. ExpectIntEQ(client_cbs.return_code, WOLFSSL_SUCCESS);
  84535. ExpectIntEQ(server_cbs.return_code, WOLFSSL_SUCCESS);
  84536. return EXPECT_RESULT();
  84537. }
  84538. #else
  84539. static int test_dtls_msg_from_other_peer(void)
  84540. {
  84541. return TEST_SKIPPED;
  84542. }
  84543. #endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  84544. * !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  84545. * !defined(SINGLE_THREADED) && !defined(NO_RSA) */
  84546. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_IPV6) && \
  84547. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  84548. defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  84549. static int test_dtls_ipv6_check(void)
  84550. {
  84551. EXPECT_DECLS;
  84552. WOLFSSL_CTX *ctx_c = NULL;
  84553. WOLFSSL_CTX *ctx_s = NULL;
  84554. WOLFSSL *ssl_c = NULL;
  84555. WOLFSSL *ssl_s = NULL;
  84556. SOCKADDR_IN fake_addr6;
  84557. int sockfd = -1;
  84558. ExpectNotNull(ctx_c = wolfSSL_CTX_new(wolfDTLSv1_2_client_method()));
  84559. ExpectNotNull(ssl_c = wolfSSL_new(ctx_c));
  84560. ExpectNotNull(ctx_s = wolfSSL_CTX_new(wolfDTLSv1_2_server_method()));
  84561. ExpectIntEQ(wolfSSL_CTX_use_PrivateKey_file(ctx_s, svrKeyFile,
  84562. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  84563. ExpectIntEQ(wolfSSL_CTX_use_certificate_file(ctx_s, svrCertFile,
  84564. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  84565. ExpectNotNull(ssl_s = wolfSSL_new(ctx_s));
  84566. XMEMSET((byte*)&fake_addr6, 0, sizeof(fake_addr6));
  84567. /* mimic a sockaddr_in6 struct, this way we can't test without
  84568. * WOLFSSL_IPV6 */
  84569. fake_addr6.sin_family = WOLFSSL_IP6;
  84570. ExpectIntNE(sockfd = socket(AF_INET, SOCK_DGRAM, 0), -1);
  84571. ExpectIntEQ(wolfSSL_set_fd(ssl_c, sockfd), WOLFSSL_SUCCESS);
  84572. /* can't return error here, as the peer is opaque for wolfssl library at
  84573. * this point */
  84574. ExpectIntEQ(wolfSSL_dtls_set_peer(ssl_c, &fake_addr6, sizeof(fake_addr6)),
  84575. WOLFSSL_SUCCESS);
  84576. ExpectIntNE(fcntl(sockfd, F_SETFL, O_NONBLOCK), -1);
  84577. wolfSSL_dtls_set_using_nonblock(ssl_c, 1);
  84578. ExpectIntNE(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  84579. ExpectIntEQ(ssl_c->error, WC_NO_ERR_TRACE(SOCKET_ERROR_E));
  84580. ExpectIntEQ(wolfSSL_dtls_set_peer(ssl_s, &fake_addr6, sizeof(fake_addr6)),
  84581. WOLFSSL_SUCCESS);
  84582. /* reuse the socket */
  84583. ExpectIntEQ(wolfSSL_set_fd(ssl_c, sockfd), WOLFSSL_SUCCESS);
  84584. wolfSSL_dtls_set_using_nonblock(ssl_s, 1);
  84585. ExpectIntNE(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
  84586. ExpectIntEQ(ssl_s->error, WC_NO_ERR_TRACE(SOCKET_ERROR_E));
  84587. if (sockfd != -1)
  84588. close(sockfd);
  84589. wolfSSL_free(ssl_c);
  84590. wolfSSL_CTX_free(ctx_c);
  84591. wolfSSL_free(ssl_s);
  84592. wolfSSL_CTX_free(ctx_s);
  84593. return EXPECT_RESULT();
  84594. }
  84595. #else
  84596. static int test_dtls_ipv6_check(void)
  84597. {
  84598. return TEST_SKIPPED;
  84599. }
  84600. #endif
  84601. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  84602. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_SECURE_RENEGOTIATION)
  84603. static WOLFSSL_SESSION* test_wolfSSL_SCR_after_resumption_session = NULL;
  84604. static void test_wolfSSL_SCR_after_resumption_ctx_ready(WOLFSSL_CTX* ctx)
  84605. {
  84606. AssertIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS);
  84607. }
  84608. static void test_wolfSSL_SCR_after_resumption_on_result(WOLFSSL* ssl)
  84609. {
  84610. if (test_wolfSSL_SCR_after_resumption_session == NULL) {
  84611. test_wolfSSL_SCR_after_resumption_session = wolfSSL_get1_session(ssl);
  84612. AssertNotNull(test_wolfSSL_SCR_after_resumption_session);
  84613. }
  84614. else {
  84615. char testMsg[] = "Message after SCR";
  84616. char msgBuf[sizeof(testMsg)];
  84617. int ret;
  84618. if (!wolfSSL_is_server(ssl)) {
  84619. AssertIntEQ(WOLFSSL_SUCCESS,
  84620. wolfSSL_set_session(ssl,
  84621. test_wolfSSL_SCR_after_resumption_session));
  84622. }
  84623. AssertIntEQ(wolfSSL_Rehandshake(ssl), WOLFSSL_SUCCESS);
  84624. AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)),
  84625. sizeof(testMsg));
  84626. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  84627. if (ret != sizeof(msgBuf)) /* Possibly APP_DATA_READY error. Retry. */
  84628. ret = wolfSSL_read(ssl, msgBuf, sizeof(msgBuf));
  84629. AssertIntEQ(ret, sizeof(msgBuf));
  84630. }
  84631. }
  84632. static void test_wolfSSL_SCR_after_resumption_ssl_ready(WOLFSSL* ssl)
  84633. {
  84634. AssertIntEQ(WOLFSSL_SUCCESS,
  84635. wolfSSL_set_session(ssl, test_wolfSSL_SCR_after_resumption_session));
  84636. }
  84637. static int test_wolfSSL_SCR_after_resumption(void)
  84638. {
  84639. EXPECT_DECLS;
  84640. callback_functions func_cb_client;
  84641. callback_functions func_cb_server;
  84642. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  84643. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  84644. func_cb_client.method = wolfTLSv1_2_client_method;
  84645. func_cb_client.ctx_ready = test_wolfSSL_SCR_after_resumption_ctx_ready;
  84646. func_cb_client.on_result = test_wolfSSL_SCR_after_resumption_on_result;
  84647. func_cb_server.method = wolfTLSv1_2_server_method;
  84648. func_cb_server.ctx_ready = test_wolfSSL_SCR_after_resumption_ctx_ready;
  84649. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  84650. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  84651. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  84652. func_cb_client.ssl_ready = test_wolfSSL_SCR_after_resumption_ssl_ready;
  84653. func_cb_server.on_result = test_wolfSSL_SCR_after_resumption_on_result;
  84654. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  84655. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  84656. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  84657. wolfSSL_SESSION_free(test_wolfSSL_SCR_after_resumption_session);
  84658. return EXPECT_RESULT();
  84659. }
  84660. #else
  84661. static int test_wolfSSL_SCR_after_resumption(void)
  84662. {
  84663. return TEST_SKIPPED;
  84664. }
  84665. #endif
  84666. static int test_wolfSSL_configure_args(void)
  84667. {
  84668. EXPECT_DECLS;
  84669. #if defined(LIBWOLFSSL_CONFIGURE_ARGS) && defined(HAVE_WC_INTROSPECTION)
  84670. ExpectNotNull(wolfSSL_configure_args());
  84671. #endif
  84672. return EXPECT_RESULT();
  84673. }
  84674. static int test_dtls_no_extensions(void)
  84675. {
  84676. EXPECT_DECLS;
  84677. #if defined(WOLFSSL_DTLS) && defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
  84678. !defined(WOLFSSL_NO_TLS12)
  84679. WOLFSSL *ssl_s = NULL;
  84680. WOLFSSL_CTX *ctx_s = NULL;
  84681. struct test_memio_ctx test_ctx;
  84682. const byte chNoExtensions[] = {
  84683. /* Handshake type */
  84684. 0x16,
  84685. /* Version */
  84686. 0xfe, 0xff,
  84687. /* Epoch */
  84688. 0x00, 0x00,
  84689. /* Seq number */
  84690. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  84691. /* Length */
  84692. 0x00, 0x40,
  84693. /* CH type */
  84694. 0x01,
  84695. /* Length */
  84696. 0x00, 0x00, 0x34,
  84697. /* Msg Seq */
  84698. 0x00, 0x00,
  84699. /* Frag offset */
  84700. 0x00, 0x00, 0x00,
  84701. /* Frag length */
  84702. 0x00, 0x00, 0x34,
  84703. /* Version */
  84704. 0xfe, 0xff,
  84705. /* Random */
  84706. 0x62, 0xfe, 0xbc, 0xfe, 0x2b, 0xfe, 0x3f, 0xeb, 0x03, 0xc4, 0xea, 0x37,
  84707. 0xe7, 0x47, 0x7e, 0x8a, 0xd9, 0xbf, 0x77, 0x0f, 0x6c, 0xb6, 0x77, 0x0b,
  84708. 0x03, 0x3f, 0x82, 0x2b, 0x21, 0x64, 0x57, 0x1d,
  84709. /* Session Length */
  84710. 0x00,
  84711. /* Cookie Length */
  84712. 0x00,
  84713. /* CS Length */
  84714. 0x00, 0x0c,
  84715. /* CS */
  84716. 0xc0, 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x39, 0x00, 0x33,
  84717. /* Comp Meths Length */
  84718. 0x01,
  84719. /* Comp Meths */
  84720. 0x00
  84721. /* And finally... no extensions */
  84722. };
  84723. int i;
  84724. #ifdef OPENSSL_EXTRA
  84725. int repeats = 2;
  84726. #else
  84727. int repeats = 1;
  84728. #endif
  84729. for (i = 0; i < repeats; i++) {
  84730. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84731. ssl_s = NULL;
  84732. ctx_s = NULL;
  84733. ExpectIntEQ(test_memio_setup(&test_ctx, NULL, &ctx_s, NULL, &ssl_s,
  84734. NULL, wolfDTLS_server_method), 0);
  84735. XMEMCPY(test_ctx.s_buff, chNoExtensions, sizeof(chNoExtensions));
  84736. test_ctx.s_len = sizeof(chNoExtensions);
  84737. #ifdef OPENSSL_EXTRA
  84738. if (i > 0) {
  84739. ExpectIntEQ(wolfSSL_set_max_proto_version(ssl_s, DTLS1_2_VERSION),
  84740. WOLFSSL_SUCCESS);
  84741. }
  84742. #endif
  84743. ExpectIntEQ(wolfSSL_accept(ssl_s), -1);
  84744. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  84745. /* Expecting a handshake msg. Either HVR or SH. */
  84746. ExpectIntGT(test_ctx.c_len, 0);
  84747. ExpectIntEQ(test_ctx.c_buff[0], 0x16);
  84748. wolfSSL_free(ssl_s);
  84749. wolfSSL_CTX_free(ctx_s);
  84750. }
  84751. #endif
  84752. return EXPECT_RESULT();
  84753. }
  84754. static int test_tls_alert_no_server_hello(void)
  84755. {
  84756. EXPECT_DECLS;
  84757. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  84758. WOLFSSL *ssl_c = NULL;
  84759. WOLFSSL_CTX *ctx_c = NULL;
  84760. struct test_memio_ctx test_ctx;
  84761. unsigned char alert_msg[] = { 0x15, 0x03, 0x01, 0x00, 0x02, 0x02, 0x28 };
  84762. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84763. ssl_c = NULL;
  84764. ctx_c = NULL;
  84765. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
  84766. wolfTLSv1_2_client_method, NULL), 0);
  84767. XMEMCPY(test_ctx.c_buff, alert_msg, sizeof(alert_msg));
  84768. test_ctx.c_len = sizeof(alert_msg);
  84769. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  84770. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WC_NO_ERR_TRACE(FATAL_ERROR));
  84771. wolfSSL_free(ssl_c);
  84772. wolfSSL_CTX_free(ctx_c);
  84773. #endif
  84774. return EXPECT_RESULT();
  84775. }
  84776. static int test_TLSX_CA_NAMES_bad_extension(void)
  84777. {
  84778. EXPECT_DECLS;
  84779. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_TLS13) && \
  84780. !defined(NO_CERTS) && !defined(WOLFSSL_NO_CA_NAMES) && \
  84781. defined(OPENSSL_EXTRA) && defined(WOLFSSL_SHA384) && \
  84782. defined(HAVE_NULL_CIPHER)
  84783. /* This test should only fail (with BUFFER_ERROR) when we actually try to
  84784. * parse the CA Names extension. Otherwise it will return other non-related
  84785. * errors. If CA Names will be parsed in more configurations, that should
  84786. * be reflected in the macro guard above. */
  84787. WOLFSSL *ssl_c = NULL;
  84788. WOLFSSL_CTX *ctx_c = NULL;
  84789. struct test_memio_ctx test_ctx;
  84790. /* HRR + SH using TLS_DHE_PSK_WITH_NULL_SHA384 */
  84791. const byte shBadCaNamesExt[] = {
  84792. 0x16, 0x03, 0x04, 0x00, 0x3f, 0x02, 0x00, 0x00, 0x3b, 0x03, 0x03, 0xcf,
  84793. 0x21, 0xad, 0x74, 0xe5, 0x9a, 0x61, 0x11, 0xbe, 0x1d, 0x8c, 0x02, 0x1e,
  84794. 0x65, 0xb8, 0x91, 0xc2, 0xa2, 0x11, 0x16, 0x7a, 0xbb, 0x8c, 0x5e, 0x07,
  84795. 0x9e, 0x09, 0xe2, 0xc8, 0xa8, 0x33, 0x9c, 0x00, 0x13, 0x03, 0x00, 0x00,
  84796. 0x13, 0x94, 0x7e, 0x00, 0x03, 0x0b, 0xf7, 0x03, 0x00, 0x2b, 0x00, 0x02,
  84797. 0x03, 0x04, 0x00, 0x33, 0x00, 0x02, 0x00, 0x19, 0x16, 0x03, 0x03, 0x00,
  84798. 0x5c, 0x02, 0x00, 0x00, 0x3b, 0x03, 0x03, 0x03, 0xcf, 0x21, 0xad, 0x74,
  84799. 0x00, 0x00, 0x83, 0x3f, 0x3b, 0x80, 0x01, 0xac, 0x65, 0x8c, 0x19, 0x2a,
  84800. 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x02, 0x00, 0x9e, 0x09, 0x1c, 0xe8,
  84801. 0xa8, 0x09, 0x9c, 0x00, 0xc0, 0xb5, 0x00, 0x00, 0x11, 0x8f, 0x00, 0x00,
  84802. 0x03, 0x3f, 0x00, 0x0c, 0x00, 0x2b, 0x00, 0x02, 0x03, 0x04, 0x13, 0x05,
  84803. 0x00, 0x00, 0x08, 0x00, 0x00, 0x06, 0x00, 0x04, 0x00, 0x09, 0x00, 0x00,
  84804. 0x0d, 0x00, 0x00, 0x11, 0x00, 0x00, 0x0d, 0x00, 0x2f, 0x00, 0x01, 0xff,
  84805. 0xff, 0xff, 0xff, 0xfa, 0x0d, 0x00, 0x00, 0x00, 0xad, 0x02
  84806. };
  84807. const byte shBadCaNamesExt2[] = {
  84808. 0x16, 0x03, 0x04, 0x00, 0x3f, 0x02, 0x00, 0x00, 0x3b, 0x03, 0x03, 0xcf,
  84809. 0x21, 0xad, 0x74, 0xe5, 0x9a, 0x61, 0x11, 0xbe, 0x1d, 0x8c, 0x02, 0x1e,
  84810. 0x65, 0xb8, 0x91, 0xc2, 0xa2, 0x11, 0x16, 0x7a, 0xbb, 0x8c, 0x5e, 0x07,
  84811. 0x9e, 0x09, 0xe2, 0xc8, 0xa8, 0x33, 0x9c, 0x00, 0x13, 0x03, 0x00, 0x00,
  84812. 0x13, 0x94, 0x7e, 0x00, 0x03, 0x0b, 0xf7, 0x03, 0x00, 0x2b, 0x00, 0x02,
  84813. 0x03, 0x04, 0x00, 0x33, 0x00, 0x02, 0x00, 0x19, 0x16, 0x03, 0x03, 0x00,
  84814. 0x5e, 0x02, 0x00, 0x00, 0x3b, 0x03, 0x03, 0x7f, 0xd0, 0x2d, 0xea, 0x6e,
  84815. 0x53, 0xa1, 0x6a, 0xc9, 0xc8, 0x54, 0xef, 0x75, 0xe4, 0xd9, 0xc6, 0x3e,
  84816. 0x74, 0xcb, 0x30, 0x80, 0xcc, 0x83, 0x3a, 0x00, 0x00, 0x00, 0x00, 0x00,
  84817. 0x00, 0xc0, 0x5a, 0x00, 0xc0, 0xb5, 0x00, 0x00, 0x11, 0x8f, 0x00, 0x00,
  84818. 0x03, 0x03, 0x00, 0x0c, 0x00, 0x2b, 0x00, 0x02, 0x03, 0x04, 0x53, 0x25,
  84819. 0x00, 0x00, 0x08, 0x00, 0x00, 0x06, 0x00, 0x04, 0x02, 0x05, 0x00, 0x00,
  84820. 0x0d, 0x00, 0x00, 0x11, 0x00, 0x00, 0x0d, 0x00, 0x2f, 0x00, 0x06, 0x00,
  84821. 0x04, 0x00, 0x03, 0x30, 0x00, 0x13, 0x94, 0x00, 0x06, 0x00, 0x04, 0x02
  84822. };
  84823. int i = 0;
  84824. for (i = 0; i < 2; i++) {
  84825. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84826. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
  84827. wolfTLSv1_3_client_method, NULL), 0);
  84828. switch (i) {
  84829. case 0:
  84830. XMEMCPY(test_ctx.c_buff, shBadCaNamesExt,
  84831. sizeof(shBadCaNamesExt));
  84832. test_ctx.c_len = sizeof(shBadCaNamesExt);
  84833. break;
  84834. case 1:
  84835. XMEMCPY(test_ctx.c_buff, shBadCaNamesExt2,
  84836. sizeof(shBadCaNamesExt2));
  84837. test_ctx.c_len = sizeof(shBadCaNamesExt2);
  84838. break;
  84839. }
  84840. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  84841. #ifndef WOLFSSL_DISABLE_EARLY_SANITY_CHECKS
  84842. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WC_NO_ERR_TRACE(OUT_OF_ORDER_E));
  84843. #else
  84844. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WC_NO_ERR_TRACE(BUFFER_ERROR));
  84845. #endif
  84846. wolfSSL_free(ssl_c);
  84847. ssl_c = NULL;
  84848. wolfSSL_CTX_free(ctx_c);
  84849. ctx_c = NULL;
  84850. }
  84851. #endif
  84852. return EXPECT_RESULT();
  84853. }
  84854. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  84855. defined(HAVE_IO_TESTS_DEPENDENCIES)
  84856. static void test_dtls_1_0_hvr_downgrade_ctx_ready(WOLFSSL_CTX* ctx)
  84857. {
  84858. AssertIntEQ(wolfSSL_CTX_SetMinVersion(ctx, WOLFSSL_DTLSV1_2),
  84859. WOLFSSL_SUCCESS);
  84860. }
  84861. static int test_dtls_1_0_hvr_downgrade(void)
  84862. {
  84863. EXPECT_DECLS;
  84864. callback_functions func_cb_client;
  84865. callback_functions func_cb_server;
  84866. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  84867. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  84868. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  84869. func_cb_client.method = wolfDTLS_client_method;
  84870. func_cb_server.method = wolfDTLSv1_2_server_method;
  84871. func_cb_client.ctx_ready = test_dtls_1_0_hvr_downgrade_ctx_ready;
  84872. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  84873. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  84874. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  84875. return EXPECT_RESULT();
  84876. }
  84877. #else
  84878. static int test_dtls_1_0_hvr_downgrade(void)
  84879. {
  84880. EXPECT_DECLS;
  84881. return EXPECT_RESULT();
  84882. }
  84883. #endif
  84884. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12) && \
  84885. defined(HAVE_SESSION_TICKET)
  84886. static WOLFSSL_SESSION* test_session_ticket_no_id_session = NULL;
  84887. static void test_session_ticket_no_id_on_result(WOLFSSL* ssl)
  84888. {
  84889. test_session_ticket_no_id_session = wolfSSL_get1_session(ssl);
  84890. AssertNotNull(test_session_ticket_no_id_session);
  84891. }
  84892. static void test_session_ticket_no_id_ctx_ready(WOLFSSL_CTX* ctx)
  84893. {
  84894. AssertIntEQ(wolfSSL_CTX_UseSessionTicket(ctx), WOLFSSL_SUCCESS);
  84895. }
  84896. static void test_session_ticket_no_id_ssl_ready(WOLFSSL* ssl)
  84897. {
  84898. test_session_ticket_no_id_session->sessionIDSz = 0;
  84899. AssertIntEQ(WOLFSSL_SUCCESS,
  84900. wolfSSL_set_session(ssl, test_session_ticket_no_id_session));
  84901. }
  84902. static int test_session_ticket_no_id(void)
  84903. {
  84904. /* We are testing an expired (invalid crypto context in out case since the
  84905. * ctx changes) session ticket being sent with the session ID being 0
  84906. * length. */
  84907. EXPECT_DECLS;
  84908. callback_functions func_cb_client;
  84909. callback_functions func_cb_server;
  84910. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  84911. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  84912. func_cb_client.method = wolfTLSv1_2_client_method;
  84913. func_cb_client.ctx_ready = test_session_ticket_no_id_ctx_ready;
  84914. func_cb_client.on_result = test_session_ticket_no_id_on_result;
  84915. func_cb_server.method = wolfTLSv1_2_server_method;
  84916. func_cb_server.ctx_ready = test_session_ticket_no_id_ctx_ready;
  84917. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  84918. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  84919. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  84920. XMEMSET(&func_cb_client, 0, sizeof(func_cb_client));
  84921. XMEMSET(&func_cb_server, 0, sizeof(func_cb_server));
  84922. func_cb_client.method = wolfTLSv1_2_client_method;
  84923. func_cb_client.ctx_ready = test_session_ticket_no_id_ctx_ready;
  84924. func_cb_client.ssl_ready = test_session_ticket_no_id_ssl_ready;
  84925. func_cb_server.method = wolfTLSv1_2_server_method;
  84926. func_cb_server.ctx_ready = test_session_ticket_no_id_ctx_ready;
  84927. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  84928. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  84929. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  84930. wolfSSL_SESSION_free(test_session_ticket_no_id_session);
  84931. return EXPECT_RESULT();
  84932. }
  84933. #else
  84934. static int test_session_ticket_no_id(void)
  84935. {
  84936. EXPECT_DECLS;
  84937. return EXPECT_RESULT();
  84938. }
  84939. #endif
  84940. static int test_session_ticket_hs_update(void)
  84941. {
  84942. EXPECT_DECLS;
  84943. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_TLS13) && \
  84944. defined(HAVE_SESSION_TICKET) && !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
  84945. struct test_memio_ctx test_ctx;
  84946. struct test_memio_ctx test_ctx2;
  84947. struct test_memio_ctx test_ctx3;
  84948. WOLFSSL_CTX *ctx_c = NULL;
  84949. WOLFSSL_CTX *ctx_s = NULL;
  84950. WOLFSSL *ssl_c = NULL;
  84951. WOLFSSL *ssl_c2 = NULL;
  84952. WOLFSSL *ssl_c3 = NULL;
  84953. WOLFSSL *ssl_s = NULL;
  84954. WOLFSSL *ssl_s2 = NULL;
  84955. WOLFSSL *ssl_s3 = NULL;
  84956. WOLFSSL_SESSION *sess = NULL;
  84957. byte read_data[1];
  84958. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  84959. XMEMSET(&test_ctx2, 0, sizeof(test_ctx2));
  84960. XMEMSET(&test_ctx3, 0, sizeof(test_ctx3));
  84961. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  84962. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  84963. /* Generate tickets */
  84964. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  84965. wolfSSL_SetLoggingPrefix("client");
  84966. /* Read the ticket msg */
  84967. ExpectIntEQ(wolfSSL_read(ssl_c, read_data, sizeof(read_data)),
  84968. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  84969. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  84970. WOLFSSL_ERROR_WANT_READ);
  84971. wolfSSL_SetLoggingPrefix(NULL);
  84972. ExpectIntEQ(test_memio_setup(&test_ctx2, &ctx_c, &ctx_s, &ssl_c2, &ssl_s2,
  84973. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  84974. ExpectIntEQ(test_memio_setup(&test_ctx3, &ctx_c, &ctx_s, &ssl_c3, &ssl_s3,
  84975. wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
  84976. ExpectNotNull(sess = wolfSSL_get1_session(ssl_c));
  84977. ExpectIntEQ(wolfSSL_set_session(ssl_c2, sess), WOLFSSL_SUCCESS);
  84978. ExpectIntEQ(wolfSSL_set_session(ssl_c3, sess), WOLFSSL_SUCCESS);
  84979. wolfSSL_SetLoggingPrefix("client");
  84980. /* Exchange initial flights for the second connection */
  84981. ExpectIntEQ(wolfSSL_connect(ssl_c2), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  84982. ExpectIntEQ(wolfSSL_get_error(ssl_c2, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  84983. WOLFSSL_ERROR_WANT_READ);
  84984. wolfSSL_SetLoggingPrefix(NULL);
  84985. wolfSSL_SetLoggingPrefix("server");
  84986. ExpectIntEQ(wolfSSL_accept(ssl_s2), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  84987. ExpectIntEQ(wolfSSL_get_error(ssl_s2, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  84988. WOLFSSL_ERROR_WANT_READ);
  84989. wolfSSL_SetLoggingPrefix(NULL);
  84990. /* Complete third connection so that new tickets are exchanged */
  84991. ExpectIntEQ(test_memio_do_handshake(ssl_c3, ssl_s3, 10, NULL), 0);
  84992. /* Read the ticket msg */
  84993. wolfSSL_SetLoggingPrefix("client");
  84994. ExpectIntEQ(wolfSSL_read(ssl_c3, read_data, sizeof(read_data)),
  84995. WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  84996. ExpectIntEQ(wolfSSL_get_error(ssl_c3, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  84997. WOLFSSL_ERROR_WANT_READ);
  84998. wolfSSL_SetLoggingPrefix(NULL);
  84999. /* Complete second connection */
  85000. ExpectIntEQ(test_memio_do_handshake(ssl_c2, ssl_s2, 10, NULL), 0);
  85001. ExpectIntEQ(wolfSSL_session_reused(ssl_c2), 1);
  85002. ExpectIntEQ(wolfSSL_session_reused(ssl_c3), 1);
  85003. wolfSSL_free(ssl_c);
  85004. wolfSSL_free(ssl_c2);
  85005. wolfSSL_free(ssl_c3);
  85006. wolfSSL_free(ssl_s);
  85007. wolfSSL_free(ssl_s2);
  85008. wolfSSL_free(ssl_s3);
  85009. wolfSSL_CTX_free(ctx_c);
  85010. wolfSSL_CTX_free(ctx_s);
  85011. wolfSSL_SESSION_free(sess);
  85012. #endif
  85013. return EXPECT_RESULT();
  85014. }
  85015. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  85016. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_SECURE_RENEGOTIATION)
  85017. static void test_dtls_downgrade_scr_server_ctx_ready_server(WOLFSSL_CTX* ctx)
  85018. {
  85019. AssertIntEQ(wolfSSL_CTX_SetMinVersion(ctx, WOLFSSL_DTLSV1_2),
  85020. WOLFSSL_SUCCESS);
  85021. AssertIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS);
  85022. }
  85023. static void test_dtls_downgrade_scr_server_ctx_ready(WOLFSSL_CTX* ctx)
  85024. {
  85025. AssertIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS);
  85026. }
  85027. static void test_dtls_downgrade_scr_server_on_result(WOLFSSL* ssl)
  85028. {
  85029. char testMsg[] = "Message after SCR";
  85030. char msgBuf[sizeof(testMsg)];
  85031. if (wolfSSL_is_server(ssl)) {
  85032. AssertIntEQ(wolfSSL_Rehandshake(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  85033. AssertIntEQ(wolfSSL_get_error(ssl, -1), WC_NO_ERR_TRACE(APP_DATA_READY));
  85034. AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf));
  85035. AssertIntEQ(wolfSSL_Rehandshake(ssl), WOLFSSL_SUCCESS);
  85036. AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)),
  85037. sizeof(testMsg));
  85038. }
  85039. else {
  85040. AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)),
  85041. sizeof(testMsg));
  85042. AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf));
  85043. }
  85044. }
  85045. static int test_dtls_downgrade_scr_server(void)
  85046. {
  85047. EXPECT_DECLS;
  85048. callback_functions func_cb_client;
  85049. callback_functions func_cb_server;
  85050. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  85051. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  85052. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  85053. func_cb_client.method = wolfDTLSv1_2_client_method;
  85054. func_cb_server.method = wolfDTLS_server_method;
  85055. func_cb_client.ctx_ready = test_dtls_downgrade_scr_server_ctx_ready;
  85056. func_cb_server.ctx_ready = test_dtls_downgrade_scr_server_ctx_ready_server;
  85057. func_cb_client.on_result = test_dtls_downgrade_scr_server_on_result;
  85058. func_cb_server.on_result = test_dtls_downgrade_scr_server_on_result;
  85059. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  85060. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  85061. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  85062. return EXPECT_RESULT();
  85063. }
  85064. #else
  85065. static int test_dtls_downgrade_scr_server(void)
  85066. {
  85067. EXPECT_DECLS;
  85068. return EXPECT_RESULT();
  85069. }
  85070. #endif
  85071. #if defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  85072. defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(HAVE_SECURE_RENEGOTIATION)
  85073. static void test_dtls_downgrade_scr_ctx_ready(WOLFSSL_CTX* ctx)
  85074. {
  85075. AssertIntEQ(wolfSSL_CTX_SetMinVersion(ctx, WOLFSSL_DTLSV1_2),
  85076. WOLFSSL_SUCCESS);
  85077. AssertIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx), WOLFSSL_SUCCESS);
  85078. }
  85079. static void test_dtls_downgrade_scr_on_result(WOLFSSL* ssl)
  85080. {
  85081. char testMsg[] = "Message after SCR";
  85082. char msgBuf[sizeof(testMsg)];
  85083. if (wolfSSL_is_server(ssl)) {
  85084. AssertIntEQ(wolfSSL_Rehandshake(ssl), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  85085. AssertIntEQ(wolfSSL_get_error(ssl, -1), WC_NO_ERR_TRACE(APP_DATA_READY));
  85086. AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf));
  85087. AssertIntEQ(wolfSSL_Rehandshake(ssl), WOLFSSL_SUCCESS);
  85088. AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)),
  85089. sizeof(testMsg));
  85090. }
  85091. else {
  85092. AssertIntEQ(wolfSSL_write(ssl, testMsg, sizeof(testMsg)),
  85093. sizeof(testMsg));
  85094. AssertIntEQ(wolfSSL_read(ssl, msgBuf, sizeof(msgBuf)), sizeof(msgBuf));
  85095. }
  85096. }
  85097. static int test_dtls_downgrade_scr(void)
  85098. {
  85099. EXPECT_DECLS;
  85100. callback_functions func_cb_client;
  85101. callback_functions func_cb_server;
  85102. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  85103. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  85104. func_cb_client.doUdp = func_cb_server.doUdp = 1;
  85105. func_cb_client.method = wolfDTLS_client_method;
  85106. func_cb_server.method = wolfDTLSv1_2_server_method;
  85107. func_cb_client.ctx_ready = test_dtls_downgrade_scr_ctx_ready;
  85108. func_cb_client.on_result = test_dtls_downgrade_scr_on_result;
  85109. func_cb_server.on_result = test_dtls_downgrade_scr_on_result;
  85110. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  85111. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  85112. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  85113. return EXPECT_RESULT();
  85114. }
  85115. #else
  85116. static int test_dtls_downgrade_scr(void)
  85117. {
  85118. EXPECT_DECLS;
  85119. return EXPECT_RESULT();
  85120. }
  85121. #endif
  85122. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \
  85123. && !defined(WOLFSSL_NO_TLS12)
  85124. static int test_dtls_client_hello_timeout_downgrade_read_cb(WOLFSSL *ssl,
  85125. char *data, int sz, void *ctx)
  85126. {
  85127. static int call_counter = 0;
  85128. call_counter++;
  85129. (void)ssl;
  85130. (void)data;
  85131. (void)sz;
  85132. (void)ctx;
  85133. switch (call_counter) {
  85134. case 1:
  85135. case 2:
  85136. return WOLFSSL_CBIO_ERR_TIMEOUT;
  85137. case 3:
  85138. return WOLFSSL_CBIO_ERR_WANT_READ;
  85139. default:
  85140. AssertIntLE(call_counter, 3);
  85141. return -1;
  85142. }
  85143. }
  85144. #endif
  85145. /* Make sure we don't send acks before getting a server hello */
  85146. static int test_dtls_client_hello_timeout_downgrade(void)
  85147. {
  85148. EXPECT_DECLS;
  85149. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \
  85150. && !defined(WOLFSSL_NO_TLS12)
  85151. WOLFSSL_CTX *ctx_c = NULL;
  85152. WOLFSSL_CTX *ctx_s = NULL;
  85153. WOLFSSL *ssl_c = NULL;
  85154. WOLFSSL *ssl_s = NULL;
  85155. struct test_memio_ctx test_ctx;
  85156. DtlsRecordLayerHeader* dtlsRH;
  85157. size_t len;
  85158. byte sequence_number[8];
  85159. int i;
  85160. for (i = 0; i < 2; i++) {
  85161. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85162. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  85163. wolfDTLS_client_method, wolfDTLSv1_2_server_method), 0);
  85164. if (i == 0) {
  85165. /* First time simulate timeout in IO layer */
  85166. /* CH1 */
  85167. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85168. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85169. /* HVR */
  85170. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  85171. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85172. /* CH2 */
  85173. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85174. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85175. /* SH flight */
  85176. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  85177. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85178. /* Drop the SH */
  85179. dtlsRH = (DtlsRecordLayerHeader*)(test_ctx.c_buff);
  85180. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  85181. XMEMMOVE(test_ctx.c_buff, test_ctx.c_buff +
  85182. sizeof(DtlsRecordLayerHeader) + len, test_ctx.c_len -
  85183. (sizeof(DtlsRecordLayerHeader) + len));
  85184. test_ctx.c_len -= sizeof(DtlsRecordLayerHeader) + len;
  85185. /* Read the remainder of the flight */
  85186. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85187. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85188. wolfSSL_SSLSetIORecv(ssl_c,
  85189. test_dtls_client_hello_timeout_downgrade_read_cb);
  85190. /* CH3 */
  85191. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85192. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85193. wolfSSL_SSLSetIORecv(ssl_c, test_memio_read_cb);
  85194. }
  85195. else {
  85196. /* Second time call wolfSSL_dtls_got_timeout */
  85197. /* CH1 */
  85198. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85199. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85200. /* HVR */
  85201. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  85202. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85203. /* CH2 */
  85204. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85205. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85206. /* SH flight */
  85207. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  85208. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85209. /* Drop the SH */
  85210. dtlsRH = (DtlsRecordLayerHeader*)(test_ctx.c_buff);
  85211. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  85212. XMEMMOVE(test_ctx.c_buff, test_ctx.c_buff +
  85213. sizeof(DtlsRecordLayerHeader) + len, test_ctx.c_len -
  85214. (sizeof(DtlsRecordLayerHeader) + len));
  85215. test_ctx.c_len -= sizeof(DtlsRecordLayerHeader) + len;
  85216. /* Read the remainder of the flight */
  85217. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85218. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85219. /* Quick timeout should be set as we received at least one msg */
  85220. ExpectIntEQ(wolfSSL_dtls13_use_quick_timeout(ssl_c), 1);
  85221. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  85222. /* Quick timeout should be cleared after a quick timeout */
  85223. /* CH3 */
  85224. ExpectIntEQ(wolfSSL_dtls13_use_quick_timeout(ssl_c), 0);
  85225. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  85226. }
  85227. /* Parse out to make sure we got exactly one ClientHello message */
  85228. XMEMSET(&sequence_number, 0, sizeof(sequence_number));
  85229. /* Second ClientHello after HVR */
  85230. sequence_number[7] = 2;
  85231. dtlsRH = (DtlsRecordLayerHeader*)test_ctx.s_buff;
  85232. ExpectIntEQ(dtlsRH->type, handshake);
  85233. ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR);
  85234. ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR);
  85235. ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number,
  85236. sizeof(sequence_number)), 0);
  85237. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  85238. ExpectIntEQ(sizeof(DtlsRecordLayerHeader) + len, test_ctx.s_len);
  85239. /* Connection should be able to continue */
  85240. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  85241. wolfSSL_free(ssl_c);
  85242. wolfSSL_free(ssl_s);
  85243. wolfSSL_CTX_free(ctx_c);
  85244. wolfSSL_CTX_free(ctx_s);
  85245. ssl_c = NULL;
  85246. ssl_s = NULL;
  85247. ctx_c = NULL;
  85248. ctx_s = NULL;
  85249. if (!EXPECT_SUCCESS())
  85250. break;
  85251. }
  85252. #endif
  85253. return EXPECT_RESULT();
  85254. }
  85255. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13)
  85256. static int test_dtls_client_hello_timeout_read_cb(WOLFSSL *ssl, char *data,
  85257. int sz, void *ctx)
  85258. {
  85259. static int call_counter = 0;
  85260. call_counter++;
  85261. (void)ssl;
  85262. (void)data;
  85263. (void)sz;
  85264. (void)ctx;
  85265. switch (call_counter) {
  85266. case 1:
  85267. return WOLFSSL_CBIO_ERR_TIMEOUT;
  85268. case 2:
  85269. return WOLFSSL_CBIO_ERR_WANT_READ;
  85270. default:
  85271. AssertIntLE(call_counter, 2);
  85272. return -1;
  85273. }
  85274. }
  85275. #endif
  85276. /* Make sure we don't send acks before getting a server hello */
  85277. static int test_dtls_client_hello_timeout(void)
  85278. {
  85279. EXPECT_DECLS;
  85280. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13)
  85281. WOLFSSL *ssl_c = NULL;
  85282. WOLFSSL_CTX *ctx_c = NULL;
  85283. struct test_memio_ctx test_ctx;
  85284. DtlsRecordLayerHeader* dtlsRH;
  85285. size_t idx;
  85286. size_t len;
  85287. byte sequence_number[8];
  85288. int i;
  85289. for (i = 0; i < 2; i++) {
  85290. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85291. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
  85292. wolfDTLSv1_3_client_method, NULL), 0);
  85293. if (i == 0) {
  85294. /* First time simulate timeout in IO layer */
  85295. wolfSSL_SSLSetIORecv(ssl_c, test_dtls_client_hello_timeout_read_cb);
  85296. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  85297. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85298. }
  85299. else {
  85300. /* Second time call wolfSSL_dtls_got_timeout */
  85301. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  85302. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85303. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  85304. }
  85305. /* Parse out to make sure we got exactly two ClientHello messages */
  85306. idx = 0;
  85307. XMEMSET(&sequence_number, 0, sizeof(sequence_number));
  85308. /* First ClientHello */
  85309. dtlsRH = (DtlsRecordLayerHeader*)(test_ctx.s_buff + idx);
  85310. ExpectIntEQ(dtlsRH->type, handshake);
  85311. ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR);
  85312. ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR);
  85313. ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number,
  85314. sizeof(sequence_number)), 0);
  85315. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  85316. ExpectIntLT(idx + sizeof(DtlsRecordLayerHeader) + len, test_ctx.s_len);
  85317. idx += sizeof(DtlsRecordLayerHeader) + len;
  85318. /* Second ClientHello */
  85319. sequence_number[7] = 1;
  85320. dtlsRH = (DtlsRecordLayerHeader*)(test_ctx.s_buff + idx);
  85321. ExpectIntEQ(dtlsRH->type, handshake);
  85322. ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR);
  85323. ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR);
  85324. ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number,
  85325. sizeof(sequence_number)), 0);
  85326. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  85327. ExpectIntEQ(idx + sizeof(DtlsRecordLayerHeader) + len, test_ctx.s_len);
  85328. wolfSSL_free(ssl_c);
  85329. wolfSSL_CTX_free(ctx_c);
  85330. ssl_c = NULL;
  85331. ctx_c = NULL;
  85332. if (!EXPECT_SUCCESS())
  85333. break;
  85334. }
  85335. #endif
  85336. return EXPECT_RESULT();
  85337. }
  85338. /* DTLS test when dropping the changed cipher spec message */
  85339. static int test_dtls_dropped_ccs(void)
  85340. {
  85341. EXPECT_DECLS;
  85342. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) \
  85343. && !defined(WOLFSSL_NO_TLS12)
  85344. WOLFSSL_CTX *ctx_c = NULL;
  85345. WOLFSSL_CTX *ctx_s = NULL;
  85346. WOLFSSL *ssl_c = NULL;
  85347. WOLFSSL *ssl_s = NULL;
  85348. struct test_memio_ctx test_ctx;
  85349. DtlsRecordLayerHeader* dtlsRH;
  85350. size_t len;
  85351. byte data[1];
  85352. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85353. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  85354. wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  85355. /* CH1 */
  85356. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85357. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85358. /* HVR */
  85359. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  85360. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85361. /* CH2 */
  85362. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85363. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85364. /* Server first flight */
  85365. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  85366. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85367. /* Client flight */
  85368. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85369. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85370. /* Server ccs + finished */
  85371. ExpectIntEQ(wolfSSL_negotiate(ssl_s), 1);
  85372. /* Drop the ccs */
  85373. dtlsRH = (DtlsRecordLayerHeader*)test_ctx.c_buff;
  85374. len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
  85375. ExpectIntEQ(len, 1);
  85376. ExpectIntEQ(dtlsRH->type, change_cipher_spec);
  85377. if (EXPECT_SUCCESS()) {
  85378. XMEMMOVE(test_ctx.c_buff, test_ctx.c_buff +
  85379. sizeof(DtlsRecordLayerHeader) + len, test_ctx.c_len -
  85380. (sizeof(DtlsRecordLayerHeader) + len));
  85381. }
  85382. test_ctx.c_len -= sizeof(DtlsRecordLayerHeader) + len;
  85383. /* Client rtx flight */
  85384. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85385. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85386. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  85387. /* Server ccs + finished rtx */
  85388. ExpectIntEQ(wolfSSL_read(ssl_s, data, sizeof(data)), -1);
  85389. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85390. /* Client processes finished */
  85391. ExpectIntEQ(wolfSSL_negotiate(ssl_c), 1);
  85392. wolfSSL_free(ssl_c);
  85393. wolfSSL_free(ssl_s);
  85394. wolfSSL_CTX_free(ctx_c);
  85395. wolfSSL_CTX_free(ctx_s);
  85396. #endif
  85397. return EXPECT_RESULT();
  85398. }
  85399. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) \
  85400. && !defined(WOLFSSL_NO_TLS12)
  85401. static int test_dtls_seq_num_downgrade_check_num(byte* ioBuf, int ioBufLen,
  85402. byte seq_num)
  85403. {
  85404. EXPECT_DECLS;
  85405. DtlsRecordLayerHeader* dtlsRH;
  85406. byte sequence_number[8];
  85407. XMEMSET(&sequence_number, 0, sizeof(sequence_number));
  85408. ExpectIntGE(ioBufLen, sizeof(*dtlsRH));
  85409. dtlsRH = (DtlsRecordLayerHeader*)ioBuf;
  85410. ExpectIntEQ(dtlsRH->type, handshake);
  85411. ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR);
  85412. ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR);
  85413. sequence_number[7] = seq_num;
  85414. ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number,
  85415. sizeof(sequence_number)), 0);
  85416. return EXPECT_RESULT();
  85417. }
  85418. #endif
  85419. /*
  85420. * Make sure that we send the correct sequence number after a HelloVerifyRequest
  85421. * and after a HelloRetryRequest. This is testing the server side as it is
  85422. * operating statelessly and should copy the sequence number of the ClientHello.
  85423. */
  85424. static int test_dtls_seq_num_downgrade(void)
  85425. {
  85426. EXPECT_DECLS;
  85427. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) \
  85428. && !defined(WOLFSSL_NO_TLS12)
  85429. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  85430. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  85431. struct test_memio_ctx test_ctx;
  85432. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85433. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  85434. wolfDTLSv1_2_client_method, wolfDTLS_server_method), 0);
  85435. /* CH1 */
  85436. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85437. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85438. ExpectIntEQ(test_dtls_seq_num_downgrade_check_num(test_ctx.s_buff,
  85439. test_ctx.s_len, 0), TEST_SUCCESS);
  85440. /* HVR */
  85441. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  85442. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85443. ExpectIntEQ(test_dtls_seq_num_downgrade_check_num(test_ctx.c_buff,
  85444. test_ctx.c_len, 0), TEST_SUCCESS);
  85445. /* CH2 */
  85446. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85447. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85448. ExpectIntEQ(test_dtls_seq_num_downgrade_check_num(test_ctx.s_buff,
  85449. test_ctx.s_len, 1), TEST_SUCCESS);
  85450. /* Server first flight */
  85451. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  85452. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85453. ExpectIntEQ(test_dtls_seq_num_downgrade_check_num(test_ctx.c_buff,
  85454. test_ctx.c_len, 1), TEST_SUCCESS);
  85455. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  85456. wolfSSL_free(ssl_c);
  85457. wolfSSL_CTX_free(ctx_c);
  85458. wolfSSL_free(ssl_s);
  85459. wolfSSL_CTX_free(ctx_s);
  85460. #endif
  85461. return EXPECT_RESULT();
  85462. }
  85463. /**
  85464. * Make sure we don't send RSA Signature Hash Algorithms in the
  85465. * CertificateRequest when we don't have any such ciphers set.
  85466. * @return EXPECT_RESULT()
  85467. */
  85468. static int test_certreq_sighash_algos(void)
  85469. {
  85470. EXPECT_DECLS;
  85471. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
  85472. !defined(WOLFSSL_MAX_STRENGTH) && defined(HAVE_ECC) && \
  85473. defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256) && \
  85474. defined(HAVE_AES_CBC) && !defined(WOLFSSL_NO_TLS12)
  85475. WOLFSSL_CTX *ctx_c = NULL;
  85476. WOLFSSL_CTX *ctx_s = NULL;
  85477. WOLFSSL *ssl_c = NULL;
  85478. WOLFSSL *ssl_s = NULL;
  85479. struct test_memio_ctx test_ctx;
  85480. int idx = 0;
  85481. int maxIdx = 0;
  85482. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85483. test_ctx.c_ciphers = test_ctx.s_ciphers =
  85484. "ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA384";
  85485. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  85486. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  85487. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx_c,
  85488. "./certs/ca-ecc-cert.pem", NULL), WOLFSSL_SUCCESS);
  85489. wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_PEER, NULL);
  85490. ExpectIntEQ(wolfSSL_use_PrivateKey_file(ssl_s, "./certs/ecc-key.pem",
  85491. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  85492. ExpectIntEQ(wolfSSL_use_certificate_file(ssl_s, "./certs/server-ecc.pem",
  85493. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  85494. ExpectIntEQ(wolfSSL_connect(ssl_c), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  85495. ExpectIntEQ(wolfSSL_get_error(ssl_c, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  85496. WOLFSSL_ERROR_WANT_READ);
  85497. ExpectIntEQ(wolfSSL_accept(ssl_s), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
  85498. ExpectIntEQ(wolfSSL_get_error(ssl_s, WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR)),
  85499. WOLFSSL_ERROR_WANT_READ);
  85500. /* Find the CertificateRequest message */
  85501. for (idx = 0; idx < test_ctx.c_len && EXPECT_SUCCESS();) {
  85502. word16 len;
  85503. ExpectIntEQ(test_ctx.c_buff[idx++], handshake);
  85504. ExpectIntEQ(test_ctx.c_buff[idx++], SSLv3_MAJOR);
  85505. ExpectIntEQ(test_ctx.c_buff[idx++], TLSv1_2_MINOR);
  85506. ato16(test_ctx.c_buff + idx, &len);
  85507. idx += OPAQUE16_LEN;
  85508. if (test_ctx.c_buff[idx] == certificate_request) {
  85509. idx++;
  85510. /* length */
  85511. idx += OPAQUE24_LEN;
  85512. /* cert types */
  85513. idx += 1 + test_ctx.c_buff[idx];
  85514. /* Sig algos */
  85515. ato16(test_ctx.c_buff + idx, &len);
  85516. idx += OPAQUE16_LEN;
  85517. maxIdx = idx + (int)len;
  85518. for (; idx < maxIdx && EXPECT_SUCCESS(); idx += OPAQUE16_LEN) {
  85519. if (test_ctx.c_buff[idx+1] == ED25519_SA_MINOR ||
  85520. test_ctx.c_buff[idx+1] == ED448_SA_MINOR)
  85521. ExpectIntEQ(test_ctx.c_buff[idx], NEW_SA_MAJOR);
  85522. else
  85523. ExpectIntEQ(test_ctx.c_buff[idx+1], ecc_dsa_sa_algo);
  85524. }
  85525. break;
  85526. }
  85527. else {
  85528. idx += (int)len;
  85529. }
  85530. }
  85531. ExpectIntLT(idx, test_ctx.c_len);
  85532. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  85533. wolfSSL_free(ssl_c);
  85534. wolfSSL_free(ssl_s);
  85535. wolfSSL_CTX_free(ctx_c);
  85536. wolfSSL_CTX_free(ctx_s);
  85537. #endif
  85538. return EXPECT_RESULT();
  85539. }
  85540. #if defined(HAVE_CRL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  85541. !defined(WOLFSSL_CRL_ALLOW_MISSING_CDP)
  85542. static int test_revoked_loaded_int_cert_ctx_ready1(WOLFSSL_CTX* ctx)
  85543. {
  85544. EXPECT_DECLS;
  85545. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, myVerify);
  85546. myVerifyAction = VERIFY_USE_PREVERFIY;
  85547. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  85548. "./certs/ca-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  85549. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  85550. "./certs/intermediate/ca-int-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  85551. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL),
  85552. WOLFSSL_SUCCESS);
  85553. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  85554. "./certs/crl/extra-crls/ca-int-cert-revoked.pem",
  85555. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  85556. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  85557. "./certs/crl/ca-int.pem",
  85558. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  85559. return EXPECT_RESULT();
  85560. }
  85561. static int test_revoked_loaded_int_cert_ctx_ready2(WOLFSSL_CTX* ctx)
  85562. {
  85563. EXPECT_DECLS;
  85564. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, myVerify);
  85565. myVerifyAction = VERIFY_USE_PREVERFIY;
  85566. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  85567. "./certs/ca-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  85568. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  85569. "./certs/intermediate/ca-int-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  85570. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  85571. "./certs/intermediate/ca-int2-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  85572. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL),
  85573. WOLFSSL_SUCCESS);
  85574. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  85575. "./certs/crl/ca-int2.pem",
  85576. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  85577. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  85578. "./certs/crl/extra-crls/ca-int-cert-revoked.pem",
  85579. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  85580. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  85581. "./certs/crl/ca-int.pem",
  85582. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  85583. return EXPECT_RESULT();
  85584. }
  85585. static int test_revoked_loaded_int_cert_ctx_ready3_crl_missing_cb(int ret,
  85586. WOLFSSL_CRL* crl, WOLFSSL_CERT_MANAGER* cm, void* ctx)
  85587. {
  85588. (void)crl;
  85589. (void)cm;
  85590. (void)ctx;
  85591. if (ret == WC_NO_ERR_TRACE(CRL_MISSING))
  85592. return 1;
  85593. return 0;
  85594. }
  85595. /* Here we are allowing missing CRL's but want to error out when its revoked */
  85596. static int test_revoked_loaded_int_cert_ctx_ready3(WOLFSSL_CTX* ctx)
  85597. {
  85598. EXPECT_DECLS;
  85599. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, myVerify);
  85600. myVerifyAction = VERIFY_USE_PREVERFIY;
  85601. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  85602. "./certs/ca-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  85603. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  85604. "./certs/intermediate/ca-int-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  85605. ExpectIntEQ(wolfSSL_CTX_load_verify_locations_ex(ctx,
  85606. "./certs/intermediate/ca-int2-cert.pem", NULL, 0), WOLFSSL_SUCCESS);
  85607. ExpectIntEQ(wolfSSL_CTX_EnableCRL(ctx, WOLFSSL_CRL_CHECKALL),
  85608. WOLFSSL_SUCCESS);
  85609. ExpectIntEQ(wolfSSL_CTX_LoadCRLFile(ctx,
  85610. "./certs/crl/extra-crls/ca-int-cert-revoked.pem",
  85611. WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
  85612. ExpectIntEQ(wolfSSL_CTX_SetCRL_ErrorCb(ctx,
  85613. test_revoked_loaded_int_cert_ctx_ready3_crl_missing_cb, NULL),
  85614. WOLFSSL_SUCCESS);
  85615. return EXPECT_RESULT();
  85616. }
  85617. #endif
  85618. static int test_revoked_loaded_int_cert(void)
  85619. {
  85620. EXPECT_DECLS;
  85621. #if defined(HAVE_CRL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && \
  85622. !defined(WOLFSSL_CRL_ALLOW_MISSING_CDP)
  85623. test_ssl_cbf client_cbf;
  85624. test_ssl_cbf server_cbf;
  85625. struct {
  85626. const char* certPemFile;
  85627. const char* keyPemFile;
  85628. ctx_cb client_ctx_ready;
  85629. } test_params[] = {
  85630. {"./certs/intermediate/ca-int2-cert.pem",
  85631. "./certs/intermediate/ca-int2-key.pem",
  85632. test_revoked_loaded_int_cert_ctx_ready1},
  85633. {"./certs/intermediate/server-chain.pem",
  85634. "./certs/server-key.pem", test_revoked_loaded_int_cert_ctx_ready2},
  85635. {"./certs/intermediate/server-chain-short.pem",
  85636. "./certs/server-key.pem", test_revoked_loaded_int_cert_ctx_ready2},
  85637. {"./certs/intermediate/server-chain-short.pem",
  85638. "./certs/server-key.pem", test_revoked_loaded_int_cert_ctx_ready3},
  85639. };
  85640. size_t i;
  85641. printf("\n");
  85642. for (i = 0; i < XELEM_CNT(test_params); i++) {
  85643. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  85644. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  85645. printf("\tTesting with %s...\n", test_params[i].certPemFile);
  85646. server_cbf.certPemFile = test_params[i].certPemFile;
  85647. server_cbf.keyPemFile = test_params[i].keyPemFile;
  85648. client_cbf.ctx_ready = test_params[i].client_ctx_ready;
  85649. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  85650. &server_cbf, NULL), -1001);
  85651. ExpectIntEQ(client_cbf.last_err, WC_NO_ERR_TRACE(CRL_CERT_REVOKED));
  85652. ExpectIntEQ(server_cbf.last_err, WC_NO_ERR_TRACE(FATAL_ERROR));
  85653. if (!EXPECT_SUCCESS())
  85654. break;
  85655. printf("\t%s passed\n", test_params[i].certPemFile);
  85656. }
  85657. #endif
  85658. return EXPECT_RESULT();
  85659. }
  85660. static int test_dtls13_frag_ch_pq(void)
  85661. {
  85662. EXPECT_DECLS;
  85663. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \
  85664. && defined(WOLFSSL_DTLS_CH_FRAG) && defined(HAVE_LIBOQS)
  85665. WOLFSSL_CTX *ctx_c = NULL;
  85666. WOLFSSL_CTX *ctx_s = NULL;
  85667. WOLFSSL *ssl_c = NULL;
  85668. WOLFSSL *ssl_s = NULL;
  85669. struct test_memio_ctx test_ctx;
  85670. const char *test_str = "test";
  85671. int test_str_size;
  85672. byte buf[255];
  85673. int group = WOLFSSL_KYBER_LEVEL5;
  85674. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85675. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  85676. wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0);
  85677. /* Add in a large post-quantum key share to make the CH long. */
  85678. ExpectIntEQ(wolfSSL_set_groups(ssl_c, &group, 1), WOLFSSL_SUCCESS);
  85679. ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, group), WOLFSSL_SUCCESS);
  85680. ExpectIntEQ(wolfSSL_dtls13_allow_ch_frag(ssl_s, 1), WOLFSSL_SUCCESS);
  85681. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  85682. ExpectStrEQ(wolfSSL_get_curve_name(ssl_c), "KYBER_LEVEL5");
  85683. ExpectStrEQ(wolfSSL_get_curve_name(ssl_s), "KYBER_LEVEL5");
  85684. test_str_size = XSTRLEN("test") + 1;
  85685. ExpectIntEQ(wolfSSL_write(ssl_c, test_str, test_str_size), test_str_size);
  85686. ExpectIntEQ(wolfSSL_read(ssl_s, buf, sizeof(buf)), test_str_size);
  85687. ExpectIntEQ(XSTRCMP((char*)buf, test_str), 0);
  85688. ExpectIntEQ(wolfSSL_write(ssl_c, test_str, test_str_size), test_str_size);
  85689. wolfSSL_free(ssl_c);
  85690. wolfSSL_free(ssl_s);
  85691. wolfSSL_CTX_free(ctx_c);
  85692. wolfSSL_CTX_free(ctx_s);
  85693. #endif
  85694. return EXPECT_RESULT();
  85695. }
  85696. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) \
  85697. && defined(WOLFSSL_DTLS_MTU) && defined(WOLFSSL_DTLS_CH_FRAG)
  85698. static int test_dtls_frag_ch_count_records(byte* b, int len)
  85699. {
  85700. DtlsRecordLayerHeader* dtlsRH;
  85701. int records = 0;
  85702. size_t recordLen;
  85703. while (len > 0) {
  85704. records++;
  85705. dtlsRH = (DtlsRecordLayerHeader*)b;
  85706. recordLen = (dtlsRH->length[0] << 8) | dtlsRH->length[1];
  85707. b += sizeof(DtlsRecordLayerHeader) + recordLen;
  85708. len -= sizeof(DtlsRecordLayerHeader) + recordLen;
  85709. }
  85710. return records;
  85711. }
  85712. #endif
  85713. static int test_dtls_frag_ch(void)
  85714. {
  85715. EXPECT_DECLS;
  85716. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \
  85717. && defined(WOLFSSL_DTLS_MTU) && defined(WOLFSSL_DTLS_CH_FRAG)
  85718. WOLFSSL_CTX *ctx_c = NULL;
  85719. WOLFSSL_CTX *ctx_s = NULL;
  85720. WOLFSSL *ssl_c = NULL;
  85721. WOLFSSL *ssl_s = NULL;
  85722. struct test_memio_ctx test_ctx;
  85723. static unsigned int DUMMY_MTU = 256;
  85724. unsigned char four_frag_CH[] = {
  85725. 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  85726. 0xda, 0x01, 0x00, 0x02, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  85727. 0xce, 0xfe, 0xfd, 0xf3, 0x94, 0x01, 0x33, 0x2c, 0xcf, 0x2c, 0x47, 0xb1,
  85728. 0xe5, 0xa1, 0x7b, 0x19, 0x3e, 0xac, 0x68, 0xdd, 0xe6, 0x17, 0x6b, 0x85,
  85729. 0xad, 0x5f, 0xfc, 0x7f, 0x6e, 0xf0, 0xb9, 0xe0, 0x2e, 0xca, 0x47, 0x00,
  85730. 0x00, 0x00, 0x36, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0,
  85731. 0x2b, 0xc0, 0x30, 0xc0, 0x2f, 0x00, 0x9f, 0x00, 0x9e, 0xcc, 0xa9, 0xcc,
  85732. 0xa8, 0xcc, 0xaa, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x28, 0xc0, 0x24, 0xc0,
  85733. 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x6b, 0x00, 0x67, 0x00,
  85734. 0x39, 0x00, 0x33, 0xcc, 0x14, 0xcc, 0x13, 0xcc, 0x15, 0x01, 0x00, 0x02,
  85735. 0x7c, 0x00, 0x2b, 0x00, 0x03, 0x02, 0xfe, 0xfc, 0x00, 0x0d, 0x00, 0x20,
  85736. 0x00, 0x1e, 0x06, 0x03, 0x05, 0x03, 0x04, 0x03, 0x02, 0x03, 0x08, 0x06,
  85737. 0x08, 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08, 0x09, 0x06, 0x01,
  85738. 0x05, 0x01, 0x04, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, 0x0a, 0x00, 0x0c,
  85739. 0x00, 0x0a, 0x00, 0x19, 0x00, 0x18, 0x00, 0x17, 0x00, 0x15, 0x01, 0x00,
  85740. 0x00, 0x16, 0x00, 0x00, 0x00, 0x33, 0x02, 0x39, 0x02, 0x37, 0x00, 0x17,
  85741. 0x00, 0x41, 0x04, 0x94, 0xdf, 0x36, 0xd7, 0xb3, 0x90, 0x6d, 0x01, 0xa1,
  85742. 0xe6, 0xed, 0x67, 0xf4, 0xd9, 0x9d, 0x2c, 0xac, 0x57, 0x74, 0xff, 0x19,
  85743. 0xbe, 0x5a, 0xc9, 0x30, 0x11, 0xb7, 0x2b, 0x59, 0x47, 0x80, 0x7c, 0xa9,
  85744. 0xb7, 0x31, 0x8c, 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  85745. 0x00, 0x01, 0x00, 0xda, 0x01, 0x00, 0x02, 0xdc, 0x00, 0x00, 0x00, 0x00,
  85746. 0xce, 0x00, 0x00, 0xce, 0x9e, 0x13, 0x74, 0x3b, 0x86, 0xba, 0x69, 0x1f,
  85747. 0x12, 0xf7, 0xcd, 0x78, 0x53, 0xe8, 0x50, 0x4d, 0x71, 0x3f, 0x4b, 0x4e,
  85748. 0xeb, 0x3e, 0xe5, 0x43, 0x54, 0x78, 0x17, 0x6d, 0x00, 0x18, 0x00, 0x61,
  85749. 0x04, 0xd1, 0x99, 0x66, 0x4f, 0xda, 0xc7, 0x12, 0x3b, 0xff, 0xb2, 0xd6,
  85750. 0x2f, 0x35, 0xb6, 0x17, 0x1f, 0xb3, 0xd0, 0xb6, 0x52, 0xff, 0x97, 0x8b,
  85751. 0x01, 0xe8, 0xd9, 0x68, 0x71, 0x40, 0x02, 0xd5, 0x68, 0x3a, 0x58, 0xb2,
  85752. 0x5d, 0xee, 0xa4, 0xe9, 0x5f, 0xf4, 0xaf, 0x3e, 0x30, 0x9c, 0x3e, 0x2b,
  85753. 0xda, 0x61, 0x43, 0x99, 0x02, 0x35, 0x33, 0x9f, 0xcf, 0xb5, 0xd3, 0x28,
  85754. 0x19, 0x9d, 0x1c, 0xbe, 0x69, 0x07, 0x9e, 0xfc, 0xe4, 0x8e, 0xcd, 0x86,
  85755. 0x4a, 0x1b, 0xf0, 0xfc, 0x17, 0x94, 0x66, 0x53, 0xda, 0x24, 0x5e, 0xaf,
  85756. 0xce, 0xec, 0x62, 0x4c, 0x06, 0xb4, 0x52, 0x94, 0xb1, 0x4a, 0x7a, 0x8c,
  85757. 0x4f, 0x00, 0x19, 0x00, 0x85, 0x04, 0x00, 0x27, 0xeb, 0x99, 0x49, 0x7f,
  85758. 0xcb, 0x2c, 0x46, 0x54, 0x2d, 0x93, 0x5d, 0x25, 0x92, 0x58, 0x5e, 0x06,
  85759. 0xc3, 0x7c, 0xfb, 0x9a, 0xa7, 0xec, 0xcd, 0x9f, 0xe1, 0x6b, 0x2d, 0x78,
  85760. 0xf5, 0x16, 0xa9, 0x20, 0x52, 0x48, 0x19, 0x0f, 0x1a, 0xd0, 0xce, 0xd8,
  85761. 0x68, 0xb1, 0x4e, 0x7f, 0x33, 0x03, 0x7d, 0x0c, 0x39, 0xdb, 0x9c, 0x4b,
  85762. 0xf4, 0xe7, 0xc2, 0xf5, 0xdd, 0x51, 0x9b, 0x03, 0xa8, 0x53, 0x2b, 0xe6,
  85763. 0x00, 0x15, 0x4b, 0xff, 0xd2, 0xa0, 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00,
  85764. 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xda, 0x01, 0x00, 0x02, 0xdc, 0x00,
  85765. 0x00, 0x00, 0x01, 0x9c, 0x00, 0x00, 0xce, 0x58, 0x30, 0x10, 0x3d, 0x46,
  85766. 0xcc, 0xca, 0x1a, 0x44, 0xc8, 0x58, 0x9b, 0x27, 0x17, 0x67, 0x31, 0x96,
  85767. 0x8a, 0x66, 0x39, 0xf4, 0xcc, 0xc1, 0x9f, 0x12, 0x1f, 0x01, 0x30, 0x50,
  85768. 0x16, 0xd6, 0x89, 0x97, 0xa3, 0x66, 0xd7, 0x99, 0x50, 0x09, 0x6e, 0x80,
  85769. 0x87, 0xe4, 0xa2, 0x88, 0xae, 0xb4, 0x23, 0x57, 0x2f, 0x12, 0x60, 0xe7,
  85770. 0x7d, 0x44, 0x2d, 0xad, 0xbe, 0xe9, 0x0d, 0x01, 0x00, 0x01, 0x00, 0xd5,
  85771. 0xdd, 0x62, 0xee, 0xf3, 0x0e, 0xd9, 0x30, 0x0e, 0x38, 0xf3, 0x48, 0xf4,
  85772. 0xc9, 0x8f, 0x8c, 0x20, 0xf7, 0xd3, 0xa8, 0xb3, 0x87, 0x3c, 0x98, 0x5d,
  85773. 0x70, 0xc5, 0x03, 0x76, 0xb7, 0xd5, 0x0b, 0x7b, 0x23, 0x97, 0x6b, 0xe3,
  85774. 0xb5, 0x18, 0xeb, 0x64, 0x55, 0x18, 0xb2, 0x8a, 0x90, 0x1a, 0x8f, 0x0e,
  85775. 0x15, 0xda, 0xb1, 0x8e, 0x7f, 0xee, 0x1f, 0xe0, 0x3b, 0xb9, 0xed, 0xfc,
  85776. 0x4e, 0x3f, 0x78, 0x16, 0x39, 0x95, 0x5f, 0xb7, 0xcb, 0x65, 0x55, 0x72,
  85777. 0x7b, 0x7d, 0x86, 0x2f, 0x8a, 0xe5, 0xee, 0xf7, 0x57, 0x40, 0xf3, 0xc4,
  85778. 0x96, 0x4f, 0x11, 0x4d, 0x85, 0xf9, 0x56, 0xfa, 0x3d, 0xf0, 0xc9, 0xa4,
  85779. 0xec, 0x1e, 0xaa, 0x47, 0x90, 0x53, 0xdf, 0xe1, 0xb7, 0x78, 0x18, 0xeb,
  85780. 0xdd, 0x0d, 0x89, 0xb7, 0xf6, 0x15, 0x0e, 0x55, 0x12, 0xb3, 0x23, 0x17,
  85781. 0x0b, 0x59, 0x6f, 0x83, 0x05, 0x6b, 0xa6, 0xf8, 0x6c, 0x3a, 0x9b, 0x1b,
  85782. 0x50, 0x93, 0x51, 0xea, 0x95, 0x2d, 0x99, 0x96, 0x38, 0x16, 0xfe, 0xfd,
  85783. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x7e, 0x01, 0x00,
  85784. 0x02, 0xdc, 0x00, 0x00, 0x00, 0x02, 0x6a, 0x00, 0x00, 0x72, 0x2d, 0x66,
  85785. 0x3e, 0xf2, 0x36, 0x5a, 0xf2, 0x23, 0x8f, 0x28, 0x09, 0xa9, 0x55, 0x8c,
  85786. 0x8f, 0xc0, 0x0d, 0x61, 0x98, 0x33, 0x56, 0x87, 0x7a, 0xfd, 0xa7, 0x50,
  85787. 0x71, 0x84, 0x2e, 0x41, 0x58, 0x00, 0x87, 0xd9, 0x27, 0xe5, 0x7b, 0xf4,
  85788. 0x6d, 0x84, 0x4e, 0x2e, 0x0c, 0x80, 0x0c, 0xf3, 0x8a, 0x02, 0x4b, 0x99,
  85789. 0x3a, 0x1f, 0x9f, 0x18, 0x7d, 0x1c, 0xec, 0xad, 0x60, 0x54, 0xa6, 0xa3,
  85790. 0x2c, 0x82, 0x5e, 0xf8, 0x8f, 0xae, 0xe1, 0xc4, 0x82, 0x7e, 0x43, 0x43,
  85791. 0xc5, 0x99, 0x49, 0x05, 0xd3, 0xf6, 0xdf, 0xa1, 0xb5, 0x2d, 0x0c, 0x13,
  85792. 0x2f, 0x1e, 0xb6, 0x28, 0x7c, 0x5c, 0xa1, 0x02, 0x6b, 0x8d, 0xa3, 0xeb,
  85793. 0xd4, 0x58, 0xe6, 0xa0, 0x7e, 0x6b, 0xaa, 0x09, 0x43, 0x67, 0x71, 0x87,
  85794. 0xa5, 0xcb, 0x68, 0xf3
  85795. };
  85796. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85797. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  85798. wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0);
  85799. /* Fragment msgs */
  85800. ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl_c, DUMMY_MTU), WOLFSSL_SUCCESS);
  85801. ExpectIntEQ(wolfSSL_dtls_set_mtu(ssl_s, DUMMY_MTU), WOLFSSL_SUCCESS);
  85802. /* Add in some key shares to make the CH long */
  85803. ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_ECC_SECP256R1),
  85804. WOLFSSL_SUCCESS);
  85805. ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_ECC_SECP384R1),
  85806. WOLFSSL_SUCCESS);
  85807. ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_ECC_SECP521R1),
  85808. WOLFSSL_SUCCESS);
  85809. ExpectIntEQ(wolfSSL_UseKeyShare(ssl_c, WOLFSSL_FFDHE_2048),
  85810. WOLFSSL_SUCCESS);
  85811. ExpectIntEQ(wolfSSL_dtls13_allow_ch_frag(ssl_s, 1), WOLFSSL_SUCCESS);
  85812. /* Reject fragmented first CH */
  85813. ExpectIntEQ(test_dtls_frag_ch_count_records(four_frag_CH,
  85814. sizeof(four_frag_CH)), 4);
  85815. XMEMCPY(test_ctx.s_buff, four_frag_CH, sizeof(four_frag_CH));
  85816. test_ctx.s_len = sizeof(four_frag_CH);
  85817. while (test_ctx.s_len > 0 && EXPECT_SUCCESS()) {
  85818. int s_len = test_ctx.s_len;
  85819. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  85820. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85821. /* Fail if we didn't advance the buffer to avoid infinite loops */
  85822. ExpectIntLT(test_ctx.s_len, s_len);
  85823. }
  85824. /* Expect all fragments read */
  85825. ExpectIntEQ(test_ctx.s_len, 0);
  85826. /* Expect quietly dropping fragmented first CH */
  85827. ExpectIntEQ(test_ctx.c_len, 0);
  85828. #if defined(WOLFSSL_TLS13) && defined(HAVE_ECH)
  85829. /* Disable ECH as it pushes it over our MTU */
  85830. wolfSSL_SetEchEnable(ssl_c, 0);
  85831. #endif
  85832. /* Limit options to make the CH a fixed length */
  85833. /* See wolfSSL_parse_cipher_list for reason why we provide 1.3 AND 1.2
  85834. * ciphersuite. This is only necessary when building with OPENSSL_EXTRA. */
  85835. ExpectTrue(wolfSSL_set_cipher_list(ssl_c, "TLS13-AES256-GCM-SHA384"
  85836. #ifdef OPENSSL_EXTRA
  85837. ":DHE-RSA-AES256-GCM-SHA384"
  85838. #endif
  85839. ));
  85840. /* CH1 */
  85841. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85842. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85843. /* Count records. Expect 1 unfragmented CH */
  85844. ExpectIntEQ(test_dtls_frag_ch_count_records(test_ctx.s_buff,
  85845. test_ctx.s_len), 1);
  85846. /* HRR */
  85847. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  85848. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85849. /* CH2 */
  85850. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85851. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85852. /* Count records. Expect fragmented CH */
  85853. ExpectIntGT(test_dtls_frag_ch_count_records(test_ctx.s_buff,
  85854. test_ctx.s_len), 1);
  85855. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  85856. wolfSSL_free(ssl_c);
  85857. wolfSSL_free(ssl_s);
  85858. wolfSSL_CTX_free(ctx_c);
  85859. wolfSSL_CTX_free(ctx_s);
  85860. ssl_c = ssl_s = NULL;
  85861. ctx_c = ctx_s = NULL;
  85862. #endif
  85863. return EXPECT_RESULT();
  85864. }
  85865. static int test_dtls_empty_keyshare_with_cookie(void)
  85866. {
  85867. EXPECT_DECLS;
  85868. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13)
  85869. WOLFSSL_CTX *ctx_s = NULL;
  85870. WOLFSSL *ssl_s = NULL;
  85871. struct test_memio_ctx test_ctx;
  85872. unsigned char ch_empty_keyshare_with_cookie[] = {
  85873. 0x16, 0xfe, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
  85874. 0x12, 0x01, 0x00, 0x01, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01,
  85875. 0x06, 0xfe, 0xfd, 0xfb, 0x8c, 0x9b, 0x28, 0xae, 0x50, 0x1c, 0x4d, 0xf3,
  85876. 0xb8, 0xcf, 0x4d, 0xd8, 0x7e, 0x93, 0x13, 0x7b, 0x9e, 0xd9, 0xeb, 0xe9,
  85877. 0x13, 0x4b, 0x0d, 0x7f, 0x2e, 0x43, 0x62, 0x8c, 0xe4, 0x57, 0x79, 0x00,
  85878. 0x00, 0x00, 0x36, 0x13, 0x01, 0x13, 0x02, 0x13, 0x03, 0xc0, 0x2c, 0xc0,
  85879. 0x2b, 0xc0, 0x30, 0xc0, 0x2f, 0x00, 0x9f, 0x00, 0x9e, 0xcc, 0xa9, 0xcc,
  85880. 0xa8, 0xcc, 0xaa, 0xc0, 0x27, 0xc0, 0x23, 0xc0, 0x28, 0xc0, 0x24, 0xc0,
  85881. 0x0a, 0xc0, 0x09, 0xc0, 0x14, 0xc0, 0x13, 0x00, 0x6b, 0x00, 0x67, 0x00,
  85882. 0x39, 0x00, 0x33, 0xcc, 0x14, 0xcc, 0x13, 0xcc, 0x15, 0x01, 0x00, 0x00,
  85883. 0xa6, 0x00, 0x2b, 0x00, 0x03, 0x02, 0xfe, 0xfc, 0x00, 0x2c, 0x00, 0x47,
  85884. 0x00, 0x45, 0x20, 0xee, 0x4b, 0x17, 0x70, 0x63, 0xa0, 0x4c, 0x82, 0xbf,
  85885. 0x43, 0x01, 0x7d, 0x8d, 0xc1, 0x1b, 0x4e, 0x9b, 0xa0, 0x3c, 0x53, 0x1f,
  85886. 0xb7, 0xd1, 0x10, 0x81, 0xa8, 0xdf, 0xdf, 0x8c, 0x7f, 0xf3, 0x11, 0x13,
  85887. 0x01, 0x02, 0x3d, 0x3b, 0x7d, 0x14, 0x2c, 0x31, 0xb3, 0x60, 0x72, 0x4d,
  85888. 0xe5, 0x1a, 0xb2, 0xa3, 0x61, 0x77, 0x73, 0x03, 0x40, 0x0e, 0x5f, 0xc5,
  85889. 0x61, 0x38, 0x43, 0x56, 0x21, 0x4a, 0x95, 0xd5, 0x35, 0xa8, 0x0d, 0x00,
  85890. 0x0d, 0x00, 0x2a, 0x00, 0x28, 0x06, 0x03, 0x05, 0x03, 0x04, 0x03, 0x02,
  85891. 0x03, 0xfe, 0x0b, 0xfe, 0x0e, 0xfe, 0xa0, 0xfe, 0xa3, 0xfe, 0xa5, 0x08,
  85892. 0x06, 0x08, 0x0b, 0x08, 0x05, 0x08, 0x0a, 0x08, 0x04, 0x08, 0x09, 0x06,
  85893. 0x01, 0x05, 0x01, 0x04, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00, 0x0a, 0x00,
  85894. 0x18, 0x00, 0x16, 0x00, 0x19, 0x00, 0x18, 0x00, 0x17, 0x00, 0x15, 0x01,
  85895. 0x00, 0x02, 0x3a, 0x02, 0x3c, 0x02, 0x3d, 0x2f, 0x3a, 0x2f, 0x3c, 0x2f,
  85896. 0x3d, 0x00, 0x16, 0x00, 0x00, 0x00, 0x33, 0x00, 0x02, 0x00, 0x00
  85897. };
  85898. DtlsRecordLayerHeader* dtlsRH;
  85899. byte sequence_number[8];
  85900. XMEMSET(&sequence_number, 0, sizeof(sequence_number));
  85901. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85902. XMEMCPY(test_ctx.s_buff, ch_empty_keyshare_with_cookie,
  85903. sizeof(ch_empty_keyshare_with_cookie));
  85904. test_ctx.s_len = sizeof(ch_empty_keyshare_with_cookie);
  85905. ExpectIntEQ(test_memio_setup(&test_ctx, NULL, &ctx_s, NULL, &ssl_s,
  85906. NULL, wolfDTLSv1_3_server_method), 0);
  85907. /* CH1 */
  85908. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  85909. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85910. /* Expect an alert. A plaintext alert should be exactly 15 bytes. */
  85911. ExpectIntEQ(test_ctx.c_len, 15);
  85912. dtlsRH = (DtlsRecordLayerHeader*)test_ctx.c_buff;
  85913. ExpectIntEQ(dtlsRH->type, alert);
  85914. ExpectIntEQ(dtlsRH->pvMajor, DTLS_MAJOR);
  85915. ExpectIntEQ(dtlsRH->pvMinor, DTLSv1_2_MINOR);
  85916. sequence_number[7] = 1;
  85917. ExpectIntEQ(XMEMCMP(sequence_number, dtlsRH->sequence_number,
  85918. sizeof(sequence_number)), 0);
  85919. ExpectIntEQ(dtlsRH->length[0], 0);
  85920. ExpectIntEQ(dtlsRH->length[1], 2);
  85921. ExpectIntEQ(test_ctx.c_buff[13], alert_fatal);
  85922. ExpectIntEQ(test_ctx.c_buff[14], illegal_parameter);
  85923. wolfSSL_free(ssl_s);
  85924. wolfSSL_CTX_free(ctx_s);
  85925. #endif
  85926. return EXPECT_RESULT();
  85927. }
  85928. static int test_dtls_old_seq_number(void)
  85929. {
  85930. EXPECT_DECLS;
  85931. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS)
  85932. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  85933. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  85934. struct test_memio_ctx test_ctx;
  85935. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  85936. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  85937. wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
  85938. /* CH1 */
  85939. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85940. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85941. /* HVR */
  85942. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  85943. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85944. /* CH2 */
  85945. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85946. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85947. /* Server first flight */
  85948. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  85949. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85950. /* Client second flight */
  85951. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  85952. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  85953. /* Modify the sequence number */
  85954. {
  85955. DtlsRecordLayerHeader* dtlsRH = (DtlsRecordLayerHeader*)test_ctx.s_buff;
  85956. XMEMSET(dtlsRH->sequence_number, 0, sizeof(dtlsRH->sequence_number));
  85957. }
  85958. /* Server second flight */
  85959. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  85960. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  85961. /* Server should not do anything as a pkt was dropped */
  85962. ExpectIntEQ(test_ctx.c_len, 0);
  85963. ExpectIntEQ(test_ctx.s_len, 0);
  85964. /* Trigger rtx */
  85965. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
  85966. /* Complete connection */
  85967. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  85968. wolfSSL_free(ssl_c);
  85969. wolfSSL_CTX_free(ctx_c);
  85970. wolfSSL_free(ssl_s);
  85971. wolfSSL_CTX_free(ctx_s);
  85972. #endif
  85973. return EXPECT_RESULT();
  85974. }
  85975. static int test_dtls12_basic_connection_id(void)
  85976. {
  85977. EXPECT_DECLS;
  85978. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS_CID)
  85979. unsigned char client_cid[] = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
  85980. unsigned char server_cid[] = { 0, 1, 2, 3, 4, 5 };
  85981. unsigned char readBuf[40];
  85982. const char* params[] = {
  85983. #ifndef NO_RSA
  85984. #ifndef NO_SHA256
  85985. #if defined(WOLFSSL_AES_128) && defined(WOLFSSL_STATIC_RSA)
  85986. "AES128-SHA256",
  85987. #ifdef HAVE_AESCCM
  85988. "AES128-CCM8",
  85989. #endif
  85990. "DHE-RSA-AES128-SHA256",
  85991. "ECDHE-RSA-AES128-SHA256",
  85992. #ifdef HAVE_AESGCM
  85993. "DHE-RSA-AES128-GCM-SHA256",
  85994. "ECDHE-RSA-AES128-GCM-SHA256",
  85995. #endif
  85996. #endif /* WOLFSSL_AES_128 && WOLFSSL_STATIC_RSA */
  85997. #endif /* NO_SHA256 */
  85998. #endif /* NO_RSA */
  85999. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  86000. "DHE-RSA-CHACHA20-POLY1305",
  86001. "DHE-RSA-CHACHA20-POLY1305-OLD",
  86002. "ECDHE-RSA-CHACHA20-POLY1305",
  86003. "ECDHE-RSA-CHACHA20-POLY1305-OLD",
  86004. #endif
  86005. #ifndef NO_PSK
  86006. "DHE-PSK-AES128-CBC-SHA256",
  86007. "DHE-PSK-AES256-GCM-SHA384",
  86008. #ifndef HAVE_NULL_CIPHER
  86009. "DHE-PSK-NULL-SHA256",
  86010. #endif
  86011. "DHE-PSK-AES128-CCM",
  86012. #endif
  86013. };
  86014. size_t i;
  86015. struct {
  86016. byte drop:1;
  86017. byte changeCID:1;
  86018. } run_params[] = {
  86019. { .drop = 0, .changeCID = 0 },
  86020. { .drop = 1, .changeCID = 0 },
  86021. { .drop = 0, .changeCID = 1 },
  86022. };
  86023. /* We check if the side included the CID in their output */
  86024. #define CLIENT_CID() mymemmem(test_ctx.s_buff, test_ctx.s_len, \
  86025. client_cid, sizeof(client_cid))
  86026. #define SERVER_CID() mymemmem(test_ctx.c_buff, test_ctx.c_len, \
  86027. server_cid, sizeof(server_cid))
  86028. printf("\n");
  86029. for (i = 0; i < XELEM_CNT(params) && EXPECT_SUCCESS(); i++) {
  86030. size_t j;
  86031. for (j = 0; j < XELEM_CNT(run_params); j++) {
  86032. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  86033. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  86034. struct test_memio_ctx test_ctx;
  86035. printf("Testing %s run #%ld ... ", params[i], j);
  86036. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  86037. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c,
  86038. &ssl_s, wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method),
  86039. 0);
  86040. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_c, params[i]), 1);
  86041. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_s, params[i]), 1);
  86042. ExpectIntEQ(wolfSSL_dtls_cid_use(ssl_c), 1);
  86043. ExpectIntEQ(wolfSSL_dtls_cid_set(ssl_c, server_cid,
  86044. sizeof(server_cid)), 1);
  86045. ExpectIntEQ(wolfSSL_dtls_cid_use(ssl_s), 1);
  86046. ExpectIntEQ(wolfSSL_dtls_cid_set(ssl_s, client_cid,
  86047. sizeof(client_cid)), 1);
  86048. #ifndef NO_PSK
  86049. if (XSTRSTR(params[i], "-PSK-") != NULL) {
  86050. wolfSSL_set_psk_client_callback(ssl_c, my_psk_client_cb);
  86051. wolfSSL_set_psk_server_callback(ssl_s, my_psk_server_cb);
  86052. }
  86053. #endif
  86054. #ifdef HAVE_SECURE_RENEGOTIATION
  86055. ExpectIntEQ(wolfSSL_UseSecureRenegotiation(ssl_c), 1);
  86056. ExpectIntEQ(wolfSSL_UseSecureRenegotiation(ssl_s), 1);
  86057. #endif
  86058. /* CH1 */
  86059. wolfSSL_SetLoggingPrefix("client");
  86060. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  86061. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  86062. ExpectNull(CLIENT_CID());
  86063. if (run_params[j].drop) {
  86064. test_ctx.c_len = test_ctx.s_len = 0;
  86065. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), 1);
  86066. ExpectNull(CLIENT_CID());
  86067. }
  86068. /* HVR */
  86069. wolfSSL_SetLoggingPrefix("server");
  86070. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  86071. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  86072. ExpectNull(SERVER_CID());
  86073. /* No point dropping HVR */
  86074. /* CH2 */
  86075. wolfSSL_SetLoggingPrefix("client");
  86076. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  86077. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  86078. ExpectNull(CLIENT_CID());
  86079. if (run_params[j].drop) {
  86080. test_ctx.c_len = test_ctx.s_len = 0;
  86081. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), 1);
  86082. ExpectNull(CLIENT_CID());
  86083. }
  86084. /* Server first flight */
  86085. wolfSSL_SetLoggingPrefix("server");
  86086. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  86087. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  86088. ExpectNull(SERVER_CID());
  86089. if (run_params[j].drop) {
  86090. test_ctx.c_len = test_ctx.s_len = 0;
  86091. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_s), 1);
  86092. ExpectNull(SERVER_CID());
  86093. }
  86094. /* Client second flight */
  86095. wolfSSL_SetLoggingPrefix("client");
  86096. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  86097. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  86098. ExpectNotNull(CLIENT_CID());
  86099. if (run_params[j].drop) {
  86100. test_ctx.c_len = test_ctx.s_len = 0;
  86101. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), 1);
  86102. ExpectNotNull(CLIENT_CID());
  86103. }
  86104. /* Server second flight */
  86105. wolfSSL_SetLoggingPrefix("server");
  86106. ExpectIntEQ(wolfSSL_negotiate(ssl_s), 1);
  86107. ExpectNotNull(SERVER_CID());
  86108. if (run_params[j].drop) {
  86109. test_ctx.c_len = test_ctx.s_len = 0;
  86110. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_s), 1);
  86111. ExpectNotNull(SERVER_CID());
  86112. }
  86113. /* Client complete connection */
  86114. wolfSSL_SetLoggingPrefix("client");
  86115. ExpectIntEQ(wolfSSL_negotiate(ssl_c), 1);
  86116. ExpectNull(CLIENT_CID());
  86117. /* Write some data */
  86118. wolfSSL_SetLoggingPrefix("client");
  86119. ExpectIntEQ(wolfSSL_write(ssl_c, params[i],
  86120. (int)XSTRLEN(params[i])), XSTRLEN(params[i]));
  86121. ExpectNotNull(CLIENT_CID());
  86122. wolfSSL_SetLoggingPrefix("server");
  86123. ExpectIntEQ(wolfSSL_write(ssl_s, params[i],
  86124. (int)XSTRLEN(params[i])), XSTRLEN(params[i]));
  86125. ExpectNotNull(SERVER_CID());
  86126. /* Read the data */
  86127. wolfSSL_SetLoggingPrefix("client");
  86128. XMEMSET(readBuf, 0, sizeof(readBuf));
  86129. ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)),
  86130. XSTRLEN(params[i]));
  86131. ExpectStrEQ(readBuf, params[i]);
  86132. XMEMSET(readBuf, 0, sizeof(readBuf));
  86133. wolfSSL_SetLoggingPrefix("server");
  86134. ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)),
  86135. XSTRLEN(params[i]));
  86136. ExpectStrEQ(readBuf, params[i]);
  86137. /* Write short data */
  86138. wolfSSL_SetLoggingPrefix("client");
  86139. ExpectIntEQ(wolfSSL_write(ssl_c, params[i], 1), 1);
  86140. ExpectNotNull(CLIENT_CID());
  86141. wolfSSL_SetLoggingPrefix("server");
  86142. ExpectIntEQ(wolfSSL_write(ssl_s, params[i], 1), 1);
  86143. ExpectNotNull(SERVER_CID());
  86144. /* Read the short data */
  86145. XMEMSET(readBuf, 0, sizeof(readBuf));
  86146. wolfSSL_SetLoggingPrefix("client");
  86147. ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)), 1);
  86148. ExpectIntEQ(readBuf[0], params[i][0]);
  86149. XMEMSET(readBuf, 0, sizeof(readBuf));
  86150. wolfSSL_SetLoggingPrefix("server");
  86151. ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)), 1);
  86152. ExpectIntEQ(readBuf[0], params[i][0]);
  86153. #ifdef HAVE_SECURE_RENEGOTIATION
  86154. /* do two SCR's */
  86155. wolfSSL_SetLoggingPrefix("client");
  86156. ExpectIntEQ(wolfSSL_Rehandshake(ssl_c), -1);
  86157. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  86158. ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)), -1);
  86159. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  86160. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  86161. /* SCR's after the first one have extra internal logic */
  86162. wolfSSL_SetLoggingPrefix("client");
  86163. ExpectIntEQ(wolfSSL_Rehandshake(ssl_c), -1);
  86164. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  86165. ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)), -1);
  86166. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  86167. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  86168. if (run_params[j].changeCID) {
  86169. ExpectIntEQ(wolfSSL_dtls_cid_set(ssl_c, client_cid,
  86170. sizeof(client_cid)), 0);
  86171. /* Forcefully change the CID */
  86172. ssl_c->dtlsCidInfo->rx->id[0] = -1;
  86173. /* We need to init the rehandshake from the client, otherwise
  86174. * we won't be able to test changing the CID. It would be
  86175. * rejected by the record CID matching code. */
  86176. wolfSSL_SetLoggingPrefix("client");
  86177. ExpectIntEQ(wolfSSL_Rehandshake(ssl_c), -1);
  86178. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1),
  86179. WOLFSSL_ERROR_WANT_READ);
  86180. ExpectNotNull(CLIENT_CID());
  86181. ExpectIntEQ(wolfSSL_SSL_renegotiate_pending(ssl_c), 1);
  86182. /* Server first flight */
  86183. wolfSSL_SetLoggingPrefix("server");
  86184. ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)), -1);
  86185. /* We expect the server to reject the CID change. */
  86186. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), DTLS_CID_ERROR);
  86187. goto loop_exit;
  86188. }
  86189. /* Server init'd SCR */
  86190. /* Server request */
  86191. wolfSSL_SetLoggingPrefix("server");
  86192. ExpectIntEQ(wolfSSL_Rehandshake(ssl_s), -1);
  86193. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  86194. ExpectNotNull(SERVER_CID());
  86195. ExpectIntEQ(wolfSSL_SSL_renegotiate_pending(ssl_s), 1);
  86196. if (run_params[j].drop) {
  86197. test_ctx.c_len = test_ctx.s_len = 0;
  86198. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_s), 1);
  86199. ExpectNotNull(SERVER_CID());
  86200. }
  86201. /* Init SCR on client side with the server's request */
  86202. /* CH no HVR on SCR */
  86203. XMEMSET(readBuf, 0, sizeof(readBuf));
  86204. wolfSSL_SetLoggingPrefix("client");
  86205. ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)), -1);
  86206. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  86207. ExpectNotNull(CLIENT_CID());
  86208. ExpectIntEQ(wolfSSL_SSL_renegotiate_pending(ssl_c), 1);
  86209. if (run_params[j].drop) {
  86210. test_ctx.c_len = test_ctx.s_len = 0;
  86211. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), 1);
  86212. ExpectNotNull(CLIENT_CID());
  86213. }
  86214. /* Server first flight */
  86215. wolfSSL_SetLoggingPrefix("server");
  86216. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  86217. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  86218. ExpectNotNull(SERVER_CID());
  86219. if (run_params[j].drop) {
  86220. test_ctx.c_len = test_ctx.s_len = 0;
  86221. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_s), 1);
  86222. ExpectNotNull(SERVER_CID());
  86223. }
  86224. /* Client second flight */
  86225. wolfSSL_SetLoggingPrefix("client");
  86226. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  86227. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  86228. ExpectNotNull(CLIENT_CID());
  86229. if (run_params[j].drop) {
  86230. test_ctx.c_len = test_ctx.s_len = 0;
  86231. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), 1);
  86232. ExpectNotNull(CLIENT_CID());
  86233. }
  86234. ExpectIntEQ(wolfSSL_write(ssl_c, params[i],
  86235. (int)XSTRLEN(params[i])), XSTRLEN(params[i]));
  86236. /* Server second flight */
  86237. wolfSSL_SetLoggingPrefix("server");
  86238. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  86239. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), APP_DATA_READY);
  86240. XMEMSET(readBuf, 0, sizeof(readBuf));
  86241. ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)),
  86242. XSTRLEN(params[i]));
  86243. ExpectStrEQ(readBuf, params[i]);
  86244. if (!run_params[j].drop) {
  86245. ExpectIntEQ(wolfSSL_write(ssl_s, params[i],
  86246. (int)XSTRLEN(params[i])), XSTRLEN(params[i]));
  86247. }
  86248. ExpectIntEQ(wolfSSL_negotiate(ssl_s), 1);
  86249. ExpectNotNull(SERVER_CID());
  86250. if (run_params[j].drop) {
  86251. test_ctx.c_len = test_ctx.s_len = 0;
  86252. ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_s), 1);
  86253. ExpectNotNull(SERVER_CID());
  86254. }
  86255. /* Test loading old epoch */
  86256. /* Client complete connection */
  86257. wolfSSL_SetLoggingPrefix("client");
  86258. if (!run_params[j].drop) {
  86259. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  86260. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), APP_DATA_READY);
  86261. XMEMSET(readBuf, 0, sizeof(readBuf));
  86262. ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)),
  86263. XSTRLEN(params[i]));
  86264. ExpectStrEQ(readBuf, params[i]);
  86265. }
  86266. ExpectIntEQ(wolfSSL_negotiate(ssl_c), 1);
  86267. ExpectNull(CLIENT_CID());
  86268. ExpectIntEQ(wolfSSL_SSL_renegotiate_pending(ssl_c), 0);
  86269. ExpectIntEQ(wolfSSL_SSL_renegotiate_pending(ssl_s), 0);
  86270. #endif
  86271. /* Close connection */
  86272. wolfSSL_SetLoggingPrefix("client");
  86273. ExpectIntEQ(wolfSSL_shutdown(ssl_c), WOLFSSL_SHUTDOWN_NOT_DONE);
  86274. ExpectNotNull(CLIENT_CID());
  86275. wolfSSL_SetLoggingPrefix("server");
  86276. ExpectIntEQ(wolfSSL_shutdown(ssl_s), WOLFSSL_SHUTDOWN_NOT_DONE);
  86277. ExpectNotNull(SERVER_CID());
  86278. wolfSSL_SetLoggingPrefix("client");
  86279. ExpectIntEQ(wolfSSL_shutdown(ssl_c), 1);
  86280. wolfSSL_SetLoggingPrefix("server");
  86281. ExpectIntEQ(wolfSSL_shutdown(ssl_s), 1);
  86282. #ifdef HAVE_SECURE_RENEGOTIATION
  86283. loop_exit:
  86284. #endif
  86285. wolfSSL_SetLoggingPrefix(NULL);
  86286. wolfSSL_free(ssl_c);
  86287. wolfSSL_CTX_free(ctx_c);
  86288. wolfSSL_free(ssl_s);
  86289. wolfSSL_CTX_free(ctx_s);
  86290. if (EXPECT_SUCCESS())
  86291. printf("ok\n");
  86292. else
  86293. printf("failed\n");
  86294. }
  86295. }
  86296. #undef CLIENT_CID
  86297. #undef SERVER_CID
  86298. #endif
  86299. return EXPECT_RESULT();
  86300. }
  86301. static int test_dtls13_basic_connection_id(void)
  86302. {
  86303. EXPECT_DECLS;
  86304. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS13) \
  86305. && defined(WOLFSSL_DTLS_CID)
  86306. unsigned char client_cid[] = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
  86307. unsigned char server_cid[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  86308. unsigned char readBuf[30];
  86309. const char* params[] = {
  86310. #ifndef NO_SHA256
  86311. #ifdef WOLFSSL_AES_128
  86312. #ifdef HAVE_AESGCM
  86313. "TLS13-AES128-GCM-SHA256",
  86314. #endif
  86315. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  86316. "TLS13-CHACHA20-POLY1305-SHA256",
  86317. #endif
  86318. #ifdef HAVE_AESCCM
  86319. "TLS13-AES128-CCM-8-SHA256",
  86320. "TLS13-AES128-CCM-SHA256",
  86321. #endif
  86322. #endif
  86323. #ifdef HAVE_NULL_CIPHER
  86324. "TLS13-SHA256-SHA256",
  86325. #endif
  86326. #endif
  86327. };
  86328. size_t i;
  86329. /* We check if the side included the CID in their output */
  86330. #define CLIENT_CID() mymemmem(test_ctx.s_buff, test_ctx.s_len, \
  86331. client_cid, sizeof(client_cid))
  86332. #define SERVER_CID() mymemmem(test_ctx.c_buff, test_ctx.c_len, \
  86333. server_cid, sizeof(server_cid))
  86334. printf("\n");
  86335. for (i = 0; i < XELEM_CNT(params) && EXPECT_SUCCESS(); i++) {
  86336. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  86337. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  86338. struct test_memio_ctx test_ctx;
  86339. printf("Testing %s ... ", params[i]);
  86340. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  86341. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  86342. wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0);
  86343. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_c, params[i]), WOLFSSL_SUCCESS);
  86344. ExpectIntEQ(wolfSSL_set_cipher_list(ssl_s, params[i]), WOLFSSL_SUCCESS);
  86345. ExpectIntEQ(wolfSSL_dtls_cid_use(ssl_c), 1);
  86346. ExpectIntEQ(wolfSSL_dtls_cid_set(ssl_c, server_cid, sizeof(server_cid)),
  86347. 1);
  86348. ExpectIntEQ(wolfSSL_dtls_cid_use(ssl_s), 1);
  86349. ExpectIntEQ(wolfSSL_dtls_cid_set(ssl_s, client_cid, sizeof(client_cid)),
  86350. 1);
  86351. /* CH1 */
  86352. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  86353. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  86354. ExpectNull(CLIENT_CID());
  86355. /* HRR */
  86356. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  86357. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  86358. ExpectNull(SERVER_CID());
  86359. /* CH2 */
  86360. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  86361. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  86362. ExpectNull(CLIENT_CID());
  86363. /* Server first flight */
  86364. ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
  86365. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  86366. ExpectNotNull(SERVER_CID());
  86367. /* Client second flight */
  86368. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  86369. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  86370. ExpectNotNull(CLIENT_CID());
  86371. /* Server process flight */
  86372. ExpectIntEQ(wolfSSL_negotiate(ssl_s), 1);
  86373. /* Client process flight */
  86374. ExpectIntEQ(wolfSSL_negotiate(ssl_c), 1);
  86375. /* Write some data */
  86376. ExpectIntEQ(wolfSSL_write(ssl_c, params[i], (int)XSTRLEN(params[i])),
  86377. XSTRLEN(params[i]));
  86378. ExpectNotNull(CLIENT_CID());
  86379. ExpectIntEQ(wolfSSL_write(ssl_s, params[i], (int)XSTRLEN(params[i])),
  86380. XSTRLEN(params[i]));
  86381. ExpectNotNull(SERVER_CID());
  86382. /* Read the data */
  86383. XMEMSET(readBuf, 0, sizeof(readBuf));
  86384. ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)),
  86385. XSTRLEN(params[i]));
  86386. ExpectStrEQ(readBuf, params[i]);
  86387. XMEMSET(readBuf, 0, sizeof(readBuf));
  86388. ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)),
  86389. XSTRLEN(params[i]));
  86390. ExpectStrEQ(readBuf, params[i]);
  86391. /* Write short data */
  86392. ExpectIntEQ(wolfSSL_write(ssl_c, params[i], 1), 1);
  86393. ExpectNotNull(CLIENT_CID());
  86394. ExpectIntEQ(wolfSSL_write(ssl_s, params[i], 1), 1);
  86395. ExpectNotNull(SERVER_CID());
  86396. /* Read the short data */
  86397. XMEMSET(readBuf, 0, sizeof(readBuf));
  86398. ExpectIntEQ(wolfSSL_read(ssl_c, readBuf, sizeof(readBuf)), 1);
  86399. ExpectIntEQ(readBuf[0], params[i][0]);
  86400. XMEMSET(readBuf, 0, sizeof(readBuf));
  86401. ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)), 1);
  86402. ExpectIntEQ(readBuf[0], params[i][0]);
  86403. /* Close connection */
  86404. ExpectIntEQ(wolfSSL_shutdown(ssl_c), WOLFSSL_SHUTDOWN_NOT_DONE);
  86405. ExpectNotNull(CLIENT_CID());
  86406. ExpectIntEQ(wolfSSL_shutdown(ssl_s), WOLFSSL_SHUTDOWN_NOT_DONE);
  86407. ExpectNotNull(SERVER_CID());
  86408. ExpectIntEQ(wolfSSL_shutdown(ssl_c), 1);
  86409. ExpectIntEQ(wolfSSL_shutdown(ssl_s), 1);
  86410. if (EXPECT_SUCCESS())
  86411. printf("ok\n");
  86412. else
  86413. printf("failed\n");
  86414. wolfSSL_free(ssl_c);
  86415. wolfSSL_CTX_free(ctx_c);
  86416. wolfSSL_free(ssl_s);
  86417. wolfSSL_CTX_free(ctx_s);
  86418. }
  86419. #undef CLIENT_CID
  86420. #undef SERVER_CID
  86421. #endif
  86422. return EXPECT_RESULT();
  86423. }
  86424. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(WOLFSSL_TLS13) && \
  86425. defined(HAVE_LIBOQS)
  86426. static void test_tls13_pq_groups_ctx_ready(WOLFSSL_CTX* ctx)
  86427. {
  86428. int group = WOLFSSL_KYBER_LEVEL5;
  86429. AssertIntEQ(wolfSSL_CTX_set_groups(ctx, &group, 1), WOLFSSL_SUCCESS);
  86430. }
  86431. static void test_tls13_pq_groups_on_result(WOLFSSL* ssl)
  86432. {
  86433. AssertStrEQ(wolfSSL_get_curve_name(ssl), "KYBER_LEVEL5");
  86434. }
  86435. #endif
  86436. static int test_tls13_pq_groups(void)
  86437. {
  86438. EXPECT_DECLS;
  86439. #if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(WOLFSSL_TLS13) && \
  86440. defined(HAVE_LIBOQS)
  86441. callback_functions func_cb_client;
  86442. callback_functions func_cb_server;
  86443. XMEMSET(&func_cb_client, 0, sizeof(callback_functions));
  86444. XMEMSET(&func_cb_server, 0, sizeof(callback_functions));
  86445. func_cb_client.method = wolfTLSv1_3_client_method;
  86446. func_cb_server.method = wolfTLSv1_3_server_method;
  86447. func_cb_client.ctx_ready = test_tls13_pq_groups_ctx_ready;
  86448. func_cb_client.on_result = test_tls13_pq_groups_on_result;
  86449. func_cb_server.on_result = test_tls13_pq_groups_on_result;
  86450. test_wolfSSL_client_server_nofail(&func_cb_client, &func_cb_server);
  86451. ExpectIntEQ(func_cb_client.return_code, TEST_SUCCESS);
  86452. ExpectIntEQ(func_cb_server.return_code, TEST_SUCCESS);
  86453. #endif
  86454. return EXPECT_RESULT();
  86455. }
  86456. static int test_tls13_early_data(void)
  86457. {
  86458. EXPECT_DECLS;
  86459. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
  86460. defined(WOLFSSL_EARLY_DATA) && defined(HAVE_SESSION_TICKET)
  86461. int written = 0;
  86462. int read = 0;
  86463. size_t i;
  86464. int splitEarlyData;
  86465. char msg[] = "This is early data";
  86466. char msg2[] = "This is client data";
  86467. char msg3[] = "This is server data";
  86468. char msg4[] = "This is server immediate data";
  86469. char msgBuf[50];
  86470. struct {
  86471. method_provider client_meth;
  86472. method_provider server_meth;
  86473. const char* tls_version;
  86474. int isUdp;
  86475. } params[] = {
  86476. #ifdef WOLFSSL_TLS13
  86477. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  86478. "TLS 1.3", 0 },
  86479. #endif
  86480. #ifdef WOLFSSL_DTLS13
  86481. { wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method,
  86482. "DTLS 1.3", 1 },
  86483. #endif
  86484. };
  86485. for (i = 0; i < sizeof(params)/sizeof(*params) && !EXPECT_FAIL(); i++) {
  86486. for (splitEarlyData = 0; splitEarlyData < 2; splitEarlyData++) {
  86487. struct test_memio_ctx test_ctx;
  86488. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  86489. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  86490. WOLFSSL_SESSION *sess = NULL;
  86491. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  86492. fprintf(stderr, "\tEarly data with %s\n", params[i].tls_version);
  86493. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c,
  86494. &ssl_s, params[i].client_meth, params[i].server_meth), 0);
  86495. /* Get a ticket so that we can do 0-RTT on the next connection */
  86496. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  86497. /* Make sure we read the ticket */
  86498. ExpectIntEQ(wolfSSL_read(ssl_c, msgBuf, sizeof(msgBuf)), -1);
  86499. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  86500. ExpectNotNull(sess = wolfSSL_get1_session(ssl_c));
  86501. wolfSSL_free(ssl_c);
  86502. ssl_c = NULL;
  86503. wolfSSL_free(ssl_s);
  86504. ssl_s = NULL;
  86505. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  86506. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  86507. params[i].client_meth, params[i].server_meth), 0);
  86508. ExpectIntEQ(wolfSSL_set_session(ssl_c, sess), WOLFSSL_SUCCESS);
  86509. #ifdef WOLFSSL_DTLS13
  86510. if (params[i].isUdp) {
  86511. #ifdef WOLFSSL_DTLS13_NO_HRR_ON_RESUME
  86512. ExpectIntEQ(wolfSSL_dtls13_no_hrr_on_resume(ssl_s, 1), WOLFSSL_SUCCESS);
  86513. #else
  86514. /* Let's test this but we generally don't recommend turning off the
  86515. * cookie exchange */
  86516. ExpectIntEQ(wolfSSL_disable_hrr_cookie(ssl_s), WOLFSSL_SUCCESS);
  86517. #endif
  86518. }
  86519. #endif
  86520. /* Test 0-RTT data */
  86521. ExpectIntEQ(wolfSSL_write_early_data(ssl_c, msg, sizeof(msg),
  86522. &written), sizeof(msg));
  86523. ExpectIntEQ(written, sizeof(msg));
  86524. if (splitEarlyData) {
  86525. ExpectIntEQ(wolfSSL_write_early_data(ssl_c, msg, sizeof(msg),
  86526. &written), sizeof(msg));
  86527. ExpectIntEQ(written, sizeof(msg));
  86528. }
  86529. /* Read first 0-RTT data (if split otherwise entire data) */
  86530. ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf, sizeof(msgBuf),
  86531. &read), sizeof(msg));
  86532. ExpectIntEQ(read, sizeof(msg));
  86533. ExpectStrEQ(msg, msgBuf);
  86534. /* Test 0.5-RTT data */
  86535. ExpectIntEQ(wolfSSL_write(ssl_s, msg4, sizeof(msg4)), sizeof(msg4));
  86536. if (splitEarlyData) {
  86537. /* Read second 0-RTT data */
  86538. ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf, sizeof(msgBuf),
  86539. &read), sizeof(msg));
  86540. ExpectIntEQ(read, sizeof(msg));
  86541. ExpectStrEQ(msg, msgBuf);
  86542. }
  86543. if (params[i].isUdp) {
  86544. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  86545. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WC_NO_ERR_TRACE(APP_DATA_READY));
  86546. /* Read server 0.5-RTT data */
  86547. ExpectIntEQ(wolfSSL_read(ssl_c, msgBuf, sizeof(msgBuf)), sizeof(msg4));
  86548. ExpectStrEQ(msg4, msgBuf);
  86549. /* Complete handshake */
  86550. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  86551. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  86552. /* Use wolfSSL_is_init_finished to check if handshake is complete. Normally
  86553. * a user would loop until it is true but here we control both sides so we
  86554. * just assert the expected value. wolfSSL_read_early_data does not provide
  86555. * handshake status to us with non-blocking IO and we can't use
  86556. * wolfSSL_accept as TLS layer may return ZERO_RETURN due to early data
  86557. * parsing logic. */
  86558. ExpectFalse(wolfSSL_is_init_finished(ssl_s));
  86559. ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf, sizeof(msgBuf),
  86560. &read), 0);
  86561. ExpectIntEQ(read, 0);
  86562. ExpectTrue(wolfSSL_is_init_finished(ssl_s));
  86563. ExpectIntEQ(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  86564. }
  86565. else {
  86566. ExpectIntEQ(wolfSSL_connect(ssl_c), WOLFSSL_SUCCESS);
  86567. ExpectFalse(wolfSSL_is_init_finished(ssl_s));
  86568. ExpectIntEQ(wolfSSL_read_early_data(ssl_s, msgBuf, sizeof(msgBuf),
  86569. &read), 0);
  86570. ExpectIntEQ(read, 0);
  86571. ExpectTrue(wolfSSL_is_init_finished(ssl_s));
  86572. /* Read server 0.5-RTT data */
  86573. ExpectIntEQ(wolfSSL_read(ssl_c, msgBuf, sizeof(msgBuf)), sizeof(msg4));
  86574. ExpectStrEQ(msg4, msgBuf);
  86575. }
  86576. /* Test bi-directional write */
  86577. ExpectIntEQ(wolfSSL_write(ssl_c, msg2, sizeof(msg2)), sizeof(msg2));
  86578. ExpectIntEQ(wolfSSL_read(ssl_s, msgBuf, sizeof(msgBuf)), sizeof(msg2));
  86579. ExpectStrEQ(msg2, msgBuf);
  86580. ExpectIntEQ(wolfSSL_write(ssl_s, msg3, sizeof(msg3)), sizeof(msg3));
  86581. ExpectIntEQ(wolfSSL_read(ssl_c, msgBuf, sizeof(msgBuf)), sizeof(msg3));
  86582. ExpectStrEQ(msg3, msgBuf);
  86583. ExpectTrue(wolfSSL_session_reused(ssl_c));
  86584. ExpectTrue(wolfSSL_session_reused(ssl_s));
  86585. wolfSSL_SESSION_free(sess);
  86586. wolfSSL_free(ssl_c);
  86587. wolfSSL_free(ssl_s);
  86588. wolfSSL_CTX_free(ctx_c);
  86589. wolfSSL_CTX_free(ctx_s);
  86590. }
  86591. }
  86592. #endif
  86593. return EXPECT_RESULT();
  86594. }
  86595. #ifdef HAVE_CERTIFICATE_STATUS_REQUEST
  86596. static int test_self_signed_stapling_client_v1_ctx_ready(WOLFSSL_CTX* ctx)
  86597. {
  86598. EXPECT_DECLS;
  86599. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), 1);
  86600. ExpectIntEQ(wolfSSL_CTX_UseOCSPStapling(ctx, WOLFSSL_CSR_OCSP,
  86601. WOLFSSL_CSR_OCSP_USE_NONCE), 1);
  86602. return EXPECT_RESULT();
  86603. }
  86604. #endif
  86605. #ifdef HAVE_CERTIFICATE_STATUS_REQUEST_V2
  86606. static int test_self_signed_stapling_client_v2_ctx_ready(WOLFSSL_CTX* ctx)
  86607. {
  86608. EXPECT_DECLS;
  86609. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), 1);
  86610. ExpectIntEQ(wolfSSL_CTX_UseOCSPStaplingV2(ctx, WOLFSSL_CSR2_OCSP,
  86611. WOLFSSL_CSR2_OCSP_USE_NONCE), 1);
  86612. return EXPECT_RESULT();
  86613. }
  86614. static int test_self_signed_stapling_client_v2_multi_ctx_ready(WOLFSSL_CTX* ctx)
  86615. {
  86616. EXPECT_DECLS;
  86617. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), 1);
  86618. ExpectIntEQ(wolfSSL_CTX_UseOCSPStaplingV2(ctx, WOLFSSL_CSR2_OCSP_MULTI,
  86619. 0), 1);
  86620. return EXPECT_RESULT();
  86621. }
  86622. #endif
  86623. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) \
  86624. || defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  86625. static int test_self_signed_stapling_server_ctx_ready(WOLFSSL_CTX* ctx)
  86626. {
  86627. EXPECT_DECLS;
  86628. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx), 1);
  86629. return EXPECT_RESULT();
  86630. }
  86631. #endif
  86632. static int test_self_signed_stapling(void)
  86633. {
  86634. EXPECT_DECLS;
  86635. #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) \
  86636. || defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
  86637. test_ssl_cbf client_cbf;
  86638. test_ssl_cbf server_cbf;
  86639. size_t i;
  86640. struct {
  86641. method_provider client_meth;
  86642. method_provider server_meth;
  86643. ctx_cb client_ctx;
  86644. const char* tls_version;
  86645. } params[] = {
  86646. #if defined(WOLFSSL_TLS13) && defined(HAVE_CERTIFICATE_STATUS_REQUEST)
  86647. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method,
  86648. test_self_signed_stapling_client_v1_ctx_ready, "TLSv1_3 v1" },
  86649. #endif
  86650. #ifndef WOLFSSL_NO_TLS12
  86651. #ifdef HAVE_CERTIFICATE_STATUS_REQUEST
  86652. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method,
  86653. test_self_signed_stapling_client_v1_ctx_ready, "TLSv1_2 v1" },
  86654. #endif
  86655. #ifdef HAVE_CERTIFICATE_STATUS_REQUEST_V2
  86656. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method,
  86657. test_self_signed_stapling_client_v2_ctx_ready, "TLSv1_2 v2" },
  86658. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method,
  86659. test_self_signed_stapling_client_v2_multi_ctx_ready,
  86660. "TLSv1_2 v2 multi" },
  86661. #endif
  86662. #endif
  86663. };
  86664. for (i = 0; i < sizeof(params)/sizeof(*params) && !EXPECT_FAIL(); i++) {
  86665. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  86666. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  86667. printf("\nTesting self-signed cert with status request: %s\n",
  86668. params[i].tls_version);
  86669. client_cbf.method = params[i].client_meth;
  86670. client_cbf.ctx_ready = params[i].client_ctx;
  86671. server_cbf.method = params[i].server_meth;
  86672. server_cbf.certPemFile = "certs/ca-cert.pem";
  86673. server_cbf.keyPemFile = "certs/ca-key.pem";
  86674. server_cbf.ctx_ready = test_self_signed_stapling_server_ctx_ready;
  86675. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  86676. &server_cbf, NULL), TEST_SUCCESS);
  86677. }
  86678. #endif
  86679. return EXPECT_RESULT();
  86680. }
  86681. static int test_tls_multi_handshakes_one_record(void)
  86682. {
  86683. EXPECT_DECLS;
  86684. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  86685. struct test_memio_ctx test_ctx;
  86686. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  86687. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  86688. RecordLayerHeader* rh = NULL;
  86689. byte *len ;
  86690. int newRecIdx = RECORD_HEADER_SZ;
  86691. int idx = 0;
  86692. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  86693. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  86694. wolfTLS_client_method, wolfTLSv1_2_server_method), 0);
  86695. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  86696. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  86697. ExpectIntEQ(wolfSSL_accept(ssl_s), -1);
  86698. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  86699. /* Combine server handshake msgs into one record */
  86700. while (idx < test_ctx.c_len) {
  86701. word16 recLen;
  86702. rh = (RecordLayerHeader*)(test_ctx.c_buff + idx);
  86703. len = &rh->length[0];
  86704. ato16((const byte*)len, &recLen);
  86705. idx += RECORD_HEADER_SZ;
  86706. XMEMMOVE(test_ctx.c_buff + newRecIdx, test_ctx.c_buff + idx,
  86707. (size_t)recLen);
  86708. newRecIdx += recLen;
  86709. idx += recLen;
  86710. }
  86711. rh = (RecordLayerHeader*)(test_ctx.c_buff);
  86712. len = &rh->length[0];
  86713. c16toa((word16)newRecIdx - RECORD_HEADER_SZ, len);
  86714. test_ctx.c_len = newRecIdx;
  86715. ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
  86716. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  86717. wolfSSL_free(ssl_c);
  86718. wolfSSL_free(ssl_s);
  86719. wolfSSL_CTX_free(ctx_c);
  86720. wolfSSL_CTX_free(ctx_s);
  86721. #endif
  86722. return EXPECT_RESULT();
  86723. }
  86724. static int test_write_dup(void)
  86725. {
  86726. EXPECT_DECLS;
  86727. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(HAVE_WRITE_DUP)
  86728. size_t i, j;
  86729. char hiWorld[] = "dup message";
  86730. char readData[sizeof(hiWorld) + 5];
  86731. struct {
  86732. method_provider client_meth;
  86733. method_provider server_meth;
  86734. const char* version_name;
  86735. int version;
  86736. } methods[] = {
  86737. #ifndef WOLFSSL_NO_TLS12
  86738. {wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLS 1.2", WOLFSSL_TLSV1_2},
  86739. #endif
  86740. #ifdef WOLFSSL_TLS13
  86741. {wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLS 1.3", WOLFSSL_TLSV1_3},
  86742. #endif
  86743. };
  86744. struct {
  86745. const char* cipher;
  86746. int version;
  86747. } ciphers[] = {
  86748. /* For simplicity the macros are copied from internal.h */
  86749. /* TLS 1.2 */
  86750. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305) && !defined(NO_SHA256)
  86751. #if defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)
  86752. #ifndef NO_RSA
  86753. {"ECDHE-RSA-CHACHA20-POLY1305", WOLFSSL_TLSV1_2},
  86754. #endif
  86755. #endif
  86756. #if !defined(NO_DH) && !defined(NO_RSA) && !defined(NO_TLS_DH)
  86757. {"DHE-RSA-CHACHA20-POLY1305", WOLFSSL_TLSV1_2},
  86758. #endif
  86759. #endif
  86760. #if !defined(NO_DH) && !defined(NO_AES) && !defined(NO_TLS) && \
  86761. !defined(NO_RSA) && defined(HAVE_AESGCM) && !defined(NO_TLS_DH)
  86762. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
  86763. {"DHE-RSA-AES128-GCM-SHA256", WOLFSSL_TLSV1_2},
  86764. #endif
  86765. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  86766. {"DHE-RSA-AES256-GCM-SHA384", WOLFSSL_TLSV1_2},
  86767. #endif
  86768. #endif
  86769. #if (defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)) \
  86770. && !defined(NO_TLS) && !defined(NO_AES)
  86771. #ifdef HAVE_AESGCM
  86772. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
  86773. #ifndef NO_RSA
  86774. {"ECDHE-RSA-AES128-GCM-SHA256", WOLFSSL_TLSV1_2},
  86775. #endif
  86776. #endif
  86777. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  86778. #ifndef NO_RSA
  86779. {"ECDHE-RSA-AES256-GCM-SHA384", WOLFSSL_TLSV1_2},
  86780. #endif
  86781. #endif
  86782. #endif
  86783. #endif
  86784. /* TLS 1.3 */
  86785. #ifdef WOLFSSL_TLS13
  86786. #ifdef HAVE_AESGCM
  86787. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
  86788. {"TLS13-AES128-GCM-SHA256", WOLFSSL_TLSV1_3},
  86789. #endif
  86790. #if defined(WOLFSSL_SHA384) && defined(WOLFSSL_AES_256)
  86791. {"TLS13-AES256-GCM-SHA384", WOLFSSL_TLSV1_3},
  86792. #endif
  86793. #endif
  86794. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  86795. #ifndef NO_SHA256
  86796. {"TLS13-CHACHA20-POLY1305-SHA256", WOLFSSL_TLSV1_3},
  86797. #endif
  86798. #endif
  86799. #ifdef HAVE_AESCCM
  86800. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_128)
  86801. {"TLS13-AES128-CCM-SHA256", WOLFSSL_TLSV1_3},
  86802. #endif
  86803. #endif
  86804. #endif
  86805. };
  86806. for (i = 0; i < XELEM_CNT(methods); i++) {
  86807. for (j = 0; j < XELEM_CNT(ciphers) && !EXPECT_FAIL(); j++) {
  86808. struct test_memio_ctx test_ctx;
  86809. WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
  86810. WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
  86811. WOLFSSL *ssl_c2 = NULL;
  86812. if (methods[i].version != ciphers[j].version)
  86813. continue;
  86814. if (i == 0 && j == 0)
  86815. printf("\n");
  86816. printf("Testing %s with %s... ", methods[i].version_name,
  86817. ciphers[j].cipher);
  86818. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  86819. test_ctx.c_ciphers = test_ctx.s_ciphers = ciphers[j].cipher;
  86820. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  86821. methods[i].client_meth, methods[i].server_meth), 0);
  86822. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
  86823. ExpectNotNull(ssl_c2 = wolfSSL_write_dup(ssl_c));
  86824. ExpectIntEQ(wolfSSL_write(ssl_c, hiWorld, sizeof(hiWorld)),
  86825. WC_NO_ERR_TRACE(WRITE_DUP_WRITE_E));
  86826. ExpectIntEQ(wolfSSL_write(ssl_c2, hiWorld, sizeof(hiWorld)),
  86827. sizeof(hiWorld));
  86828. ExpectIntEQ(wolfSSL_read(ssl_s, readData, sizeof(readData)),
  86829. sizeof(hiWorld));
  86830. ExpectIntEQ(wolfSSL_write(ssl_s, hiWorld, sizeof(hiWorld)),
  86831. sizeof(hiWorld));
  86832. ExpectIntEQ(wolfSSL_read(ssl_c2, readData, sizeof(readData)),
  86833. WC_NO_ERR_TRACE(WRITE_DUP_READ_E));
  86834. ExpectIntEQ(wolfSSL_read(ssl_c, readData, sizeof(readData)),
  86835. sizeof(hiWorld));
  86836. if (EXPECT_SUCCESS())
  86837. printf("ok\n");
  86838. else
  86839. printf("failed\n");
  86840. wolfSSL_free(ssl_c);
  86841. wolfSSL_free(ssl_c2);
  86842. wolfSSL_free(ssl_s);
  86843. wolfSSL_CTX_free(ctx_c);
  86844. wolfSSL_CTX_free(ctx_s);
  86845. }
  86846. }
  86847. #endif
  86848. return EXPECT_RESULT();
  86849. }
  86850. static int test_read_write_hs(void)
  86851. {
  86852. EXPECT_DECLS;
  86853. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
  86854. WOLFSSL_CTX *ctx_s = NULL, *ctx_c = NULL;
  86855. WOLFSSL *ssl_s = NULL, *ssl_c = NULL;
  86856. struct test_memio_ctx test_ctx;
  86857. byte test_buffer[16];
  86858. unsigned int test;
  86859. /* test == 0 : client writes, server reads */
  86860. /* test == 1 : server writes, client reads */
  86861. for (test = 0; test < 2; test++) {
  86862. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  86863. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  86864. wolfTLSv1_2_client_method,
  86865. wolfTLSv1_2_server_method), 0);
  86866. ExpectIntEQ(wolfSSL_set_group_messages(ssl_s), WOLFSSL_SUCCESS);
  86867. /* CH -> */
  86868. if (test == 0) {
  86869. ExpectIntEQ(wolfSSL_write(ssl_c, "hello", 5), -1);
  86870. } else {
  86871. ExpectIntEQ(wolfSSL_read(ssl_c, test_buffer,
  86872. sizeof(test_buffer)), -1);
  86873. }
  86874. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  86875. /* <- SH + SKE + SHD */
  86876. if (test == 0) {
  86877. ExpectIntEQ(wolfSSL_read(ssl_s, test_buffer,
  86878. sizeof(test_buffer)), -1);
  86879. } else {
  86880. ExpectIntEQ(wolfSSL_write(ssl_s, "hello", 5), -1);
  86881. }
  86882. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
  86883. /* -> CKE + CLIENT FINISHED */
  86884. if (test == 0) {
  86885. ExpectIntEQ(wolfSSL_write(ssl_c, "hello", 5), -1);
  86886. } else {
  86887. ExpectIntEQ(wolfSSL_read(ssl_c, test_buffer,
  86888. sizeof(test_buffer)), -1);
  86889. }
  86890. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  86891. /* abide clang static analyzer */
  86892. if (ssl_s != NULL) {
  86893. /* disable group message to separate sending of ChangeCipherspec
  86894. * from Finished */
  86895. ssl_s->options.groupMessages = 0;
  86896. }
  86897. /* allow writing of CS, but not FINISHED */
  86898. test_ctx.c_len = TEST_MEMIO_BUF_SZ - 6;
  86899. /* <- CS */
  86900. if (test == 0) {
  86901. ExpectIntEQ(wolfSSL_read(ssl_s, test_buffer,
  86902. sizeof(test_buffer)), -1);
  86903. } else {
  86904. ExpectIntEQ(wolfSSL_write(ssl_s, "hello", 5), -1);
  86905. }
  86906. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_WRITE);
  86907. /* move CS message where the client can read it */
  86908. memmove(test_ctx.c_buff,
  86909. (test_ctx.c_buff + TEST_MEMIO_BUF_SZ - 6), 6);
  86910. test_ctx.c_len = 6;
  86911. /* read CS */
  86912. if (test == 0) {
  86913. ExpectIntEQ(wolfSSL_write(ssl_c, "hello", 5), -1);
  86914. } else {
  86915. ExpectIntEQ(wolfSSL_read(ssl_c, test_buffer,
  86916. sizeof(test_buffer)), -1);
  86917. }
  86918. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  86919. ExpectIntEQ(test_ctx.c_len, 0);
  86920. if (test == 0) {
  86921. /* send SERVER FINISHED */
  86922. ExpectIntEQ(wolfSSL_read(ssl_s, test_buffer,
  86923. sizeof(test_buffer)), -1);
  86924. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1),
  86925. WOLFSSL_ERROR_WANT_READ);
  86926. } else {
  86927. /* send SERVER FINISHED + App Data */
  86928. ExpectIntEQ(wolfSSL_write(ssl_s, "hello", 5), 5);
  86929. }
  86930. ExpectIntGT(test_ctx.c_len, 0);
  86931. /* Send and receive the data */
  86932. if (test == 0) {
  86933. ExpectIntEQ(wolfSSL_write(ssl_c, "hello", 5), 5);
  86934. ExpectIntEQ(wolfSSL_read(ssl_s, test_buffer,
  86935. sizeof(test_buffer)), 5);
  86936. } else {
  86937. ExpectIntEQ(wolfSSL_read(ssl_c, test_buffer,
  86938. sizeof(test_buffer)), 5);
  86939. }
  86940. ExpectBufEQ(test_buffer, "hello", 5);
  86941. wolfSSL_free(ssl_c);
  86942. wolfSSL_free(ssl_s);
  86943. wolfSSL_CTX_free(ctx_c);
  86944. wolfSSL_CTX_free(ctx_s);
  86945. ssl_c = ssl_s = NULL;
  86946. ctx_c = ctx_s = NULL;
  86947. }
  86948. #endif
  86949. return EXPECT_RESULT();
  86950. }
  86951. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(OPENSSL_EXTRA)
  86952. static const char* test_get_signature_nid_siglag;
  86953. static int test_get_signature_nid_sig;
  86954. static int test_get_signature_nid_hash;
  86955. static int test_get_signature_nid_ssl_ready(WOLFSSL* ssl)
  86956. {
  86957. EXPECT_DECLS;
  86958. ExpectIntEQ(wolfSSL_set_cipher_list(ssl, "ALL"), WOLFSSL_SUCCESS);
  86959. if (!wolfSSL_is_server(ssl)) {
  86960. ExpectIntEQ(wolfSSL_set1_sigalgs_list(ssl,
  86961. test_get_signature_nid_siglag), WOLFSSL_SUCCESS);
  86962. }
  86963. return EXPECT_RESULT();
  86964. }
  86965. static int test_get_signature_nid_on_hs_client(WOLFSSL_CTX **ctx, WOLFSSL **ssl)
  86966. {
  86967. EXPECT_DECLS;
  86968. int nid = 0;
  86969. (void)ctx;
  86970. if (XSTRSTR(wolfSSL_get_cipher(*ssl), "TLS_RSA_") == NULL) {
  86971. ExpectIntEQ(SSL_get_peer_signature_type_nid(*ssl, &nid), WOLFSSL_SUCCESS);
  86972. ExpectIntEQ(nid, test_get_signature_nid_sig);
  86973. ExpectIntEQ(SSL_get_peer_signature_nid(*ssl, &nid), WOLFSSL_SUCCESS);
  86974. ExpectIntEQ(nid, test_get_signature_nid_hash);
  86975. }
  86976. else /* No sigalg info on static ciphersuite */
  86977. return TEST_SUCCESS;
  86978. return EXPECT_RESULT();
  86979. }
  86980. static int test_get_signature_nid_on_hs_server(WOLFSSL_CTX **ctx, WOLFSSL **ssl)
  86981. {
  86982. EXPECT_DECLS;
  86983. int nid = 0;
  86984. (void)ctx;
  86985. ExpectIntEQ(SSL_get_signature_type_nid(*ssl, &nid), WOLFSSL_SUCCESS);
  86986. ExpectIntEQ(nid, test_get_signature_nid_sig);
  86987. ExpectIntEQ(SSL_get_signature_nid(*ssl, &nid), WOLFSSL_SUCCESS);
  86988. ExpectIntEQ(nid, test_get_signature_nid_hash);
  86989. return EXPECT_RESULT();
  86990. }
  86991. #endif
  86992. static int test_get_signature_nid(void)
  86993. {
  86994. EXPECT_DECLS;
  86995. #if defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && defined(OPENSSL_EXTRA)
  86996. test_ssl_cbf client_cbf;
  86997. test_ssl_cbf server_cbf;
  86998. size_t i;
  86999. #define TGSN_TLS12_RSA(sigalg, sig_nid, hash_nid) \
  87000. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_2, svrCertFile, svrKeyFile, \
  87001. caCertFile }
  87002. #define TGSN_TLS12_ECDSA(sigalg, sig_nid, hash_nid) \
  87003. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_2, eccCertFile, eccKeyFile, \
  87004. caEccCertFile }
  87005. #define TGSN_TLS13_RSA(sigalg, sig_nid, hash_nid) \
  87006. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_3, svrCertFile, svrKeyFile, \
  87007. caCertFile }
  87008. #define TGSN_TLS13_ECDSA(sigalg, sig_nid, hash_nid) \
  87009. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_3, eccCertFile, eccKeyFile, \
  87010. caEccCertFile }
  87011. #define TGSN_TLS13_ED25519(sigalg, sig_nid, hash_nid) \
  87012. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_3, edCertFile, edKeyFile, \
  87013. caEdCertFile }
  87014. #define TGSN_TLS13_ED448(sigalg, sig_nid, hash_nid) \
  87015. { sigalg, sig_nid, hash_nid, WOLFSSL_TLSV1_3, ed448CertFile, ed448KeyFile, \
  87016. caEd448CertFile }
  87017. struct {
  87018. const char* siglag;
  87019. int sig_nid;
  87020. int hash_nid;
  87021. int tls_ver;
  87022. const char* server_cert;
  87023. const char* server_key;
  87024. const char* client_ca;
  87025. } params[] = {
  87026. #ifndef NO_RSA
  87027. #ifndef NO_SHA256
  87028. TGSN_TLS12_RSA("RSA+SHA256", NID_rsaEncryption, NID_sha256),
  87029. #ifdef WC_RSA_PSS
  87030. TGSN_TLS12_RSA("RSA-PSS+SHA256", NID_rsassaPss, NID_sha256),
  87031. TGSN_TLS13_RSA("RSA-PSS+SHA256", NID_rsassaPss, NID_sha256),
  87032. #endif
  87033. #endif
  87034. #ifdef WOLFSSL_SHA512
  87035. TGSN_TLS12_RSA("RSA+SHA512", NID_rsaEncryption, NID_sha512),
  87036. #ifdef WC_RSA_PSS
  87037. TGSN_TLS12_RSA("RSA-PSS+SHA512", NID_rsassaPss, NID_sha512),
  87038. TGSN_TLS13_RSA("RSA-PSS+SHA512", NID_rsassaPss, NID_sha512),
  87039. #endif
  87040. #endif
  87041. #endif
  87042. #ifdef HAVE_ECC
  87043. #ifndef NO_SHA256
  87044. TGSN_TLS12_ECDSA("ECDSA+SHA256", NID_X9_62_id_ecPublicKey, NID_sha256),
  87045. TGSN_TLS13_ECDSA("ECDSA+SHA256", NID_X9_62_id_ecPublicKey, NID_sha256),
  87046. #endif
  87047. #endif
  87048. #ifdef HAVE_ED25519
  87049. TGSN_TLS13_ED25519("ED25519", NID_ED25519, NID_sha512),
  87050. #endif
  87051. #ifdef HAVE_ED448
  87052. TGSN_TLS13_ED448("ED448", NID_ED448, NID_sha512),
  87053. #endif
  87054. };
  87055. printf("\n");
  87056. for (i = 0; i < XELEM_CNT(params) && !EXPECT_FAIL(); i++) {
  87057. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  87058. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  87059. printf("Testing %s with %s...", tls_desc[params[i].tls_ver],
  87060. params[i].siglag);
  87061. switch (params[i].tls_ver) {
  87062. #ifndef WOLFSSL_NO_TLS12
  87063. case WOLFSSL_TLSV1_2:
  87064. client_cbf.method = wolfTLSv1_2_client_method;
  87065. server_cbf.method = wolfTLSv1_2_server_method;
  87066. break;
  87067. #endif
  87068. #ifdef WOLFSSL_TLS13
  87069. case WOLFSSL_TLSV1_3:
  87070. client_cbf.method = wolfTLSv1_3_client_method;
  87071. server_cbf.method = wolfTLSv1_3_server_method;
  87072. break;
  87073. #endif
  87074. default:
  87075. printf("skipping\n");
  87076. continue;
  87077. }
  87078. test_get_signature_nid_siglag = params[i].siglag;
  87079. test_get_signature_nid_sig = params[i].sig_nid;
  87080. test_get_signature_nid_hash = params[i].hash_nid;
  87081. client_cbf.ssl_ready = test_get_signature_nid_ssl_ready;
  87082. server_cbf.ssl_ready = test_get_signature_nid_ssl_ready;
  87083. client_cbf.on_handshake = test_get_signature_nid_on_hs_client;
  87084. server_cbf.on_handshake = test_get_signature_nid_on_hs_server;
  87085. server_cbf.certPemFile = params[i].server_cert;
  87086. server_cbf.keyPemFile = params[i].server_key;
  87087. client_cbf.caPemFile = params[i].client_ca;
  87088. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  87089. &server_cbf, NULL), TEST_SUCCESS);
  87090. if (EXPECT_SUCCESS())
  87091. printf("passed\n");
  87092. }
  87093. #endif
  87094. return EXPECT_RESULT();
  87095. }
  87096. #if !defined(NO_CERTS) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  87097. static word32 test_tls_cert_store_unchanged_HashCaTable(Signer** caTable)
  87098. {
  87099. #ifndef NO_MD5
  87100. enum wc_HashType hashType = WC_HASH_TYPE_MD5;
  87101. #elif !defined(NO_SHA)
  87102. enum wc_HashType hashType = WC_HASH_TYPE_SHA;
  87103. #elif !defined(NO_SHA256)
  87104. enum wc_HashType hashType = WC_HASH_TYPE_SHA256;
  87105. #else
  87106. #error "We need a digest to hash the Signer object"
  87107. #endif
  87108. byte hashBuf[WC_MAX_DIGEST_SIZE];
  87109. wc_HashAlg hash;
  87110. size_t i;
  87111. AssertIntEQ(wc_HashInit(&hash, hashType), 0);
  87112. for (i = 0; i < CA_TABLE_SIZE; i++) {
  87113. Signer* cur;
  87114. for (cur = caTable[i]; cur != NULL; cur = cur->next)
  87115. AssertIntEQ(wc_HashUpdate(&hash, hashType, (byte*)cur,
  87116. sizeof(*cur)), 0);
  87117. }
  87118. AssertIntEQ(wc_HashFinal(&hash, hashType, hashBuf), 0);
  87119. AssertIntEQ(wc_HashFree(&hash, hashType), 0);
  87120. return MakeWordFromHash(hashBuf);
  87121. }
  87122. static word32 test_tls_cert_store_unchanged_before_hashes[2];
  87123. static size_t test_tls_cert_store_unchanged_before_hashes_idx;
  87124. static word32 test_tls_cert_store_unchanged_after_hashes[2];
  87125. static size_t test_tls_cert_store_unchanged_after_hashes_idx;
  87126. static int test_tls_cert_store_unchanged_ctx_ready(WOLFSSL_CTX* ctx)
  87127. {
  87128. EXPECT_DECLS;
  87129. ExpectIntNE(test_tls_cert_store_unchanged_before_hashes
  87130. [test_tls_cert_store_unchanged_before_hashes_idx++] =
  87131. test_tls_cert_store_unchanged_HashCaTable(ctx->cm->caTable), 0);
  87132. wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER |
  87133. WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
  87134. return EXPECT_RESULT();
  87135. }
  87136. static int test_tls_cert_store_unchanged_ctx_cleanup(WOLFSSL_CTX* ctx)
  87137. {
  87138. EXPECT_DECLS;
  87139. ExpectIntEQ(wolfSSL_CTX_UnloadIntermediateCerts(ctx), WOLFSSL_SUCCESS);
  87140. ExpectIntNE(test_tls_cert_store_unchanged_after_hashes
  87141. [test_tls_cert_store_unchanged_after_hashes_idx++] =
  87142. test_tls_cert_store_unchanged_HashCaTable(ctx->cm->caTable), 0);
  87143. return EXPECT_RESULT();
  87144. }
  87145. static int test_tls_cert_store_unchanged_on_hs(WOLFSSL_CTX **ctx, WOLFSSL **ssl)
  87146. {
  87147. EXPECT_DECLS;
  87148. WOLFSSL_CERT_MANAGER* cm;
  87149. (void)ssl;
  87150. /* WARNING: this approach bypasses the reference counter check in
  87151. * wolfSSL_CTX_UnloadIntermediateCerts. It is not recommended as it may
  87152. * cause unexpected behaviour when other active connections try accessing
  87153. * the caTable. */
  87154. ExpectNotNull(cm = wolfSSL_CTX_GetCertManager(*ctx));
  87155. ExpectIntEQ(wolfSSL_CertManagerUnloadIntermediateCerts(cm),
  87156. WOLFSSL_SUCCESS);
  87157. ExpectIntNE(test_tls_cert_store_unchanged_after_hashes
  87158. [test_tls_cert_store_unchanged_after_hashes_idx++] =
  87159. test_tls_cert_store_unchanged_HashCaTable((*ctx)->cm->caTable), 0);
  87160. return EXPECT_RESULT();
  87161. }
  87162. static int test_tls_cert_store_unchanged_ssl_ready(WOLFSSL* ssl)
  87163. {
  87164. EXPECT_DECLS;
  87165. WOLFSSL_CTX* ctx;
  87166. ExpectNotNull(ctx = wolfSSL_get_SSL_CTX(ssl));
  87167. return EXPECT_RESULT();
  87168. }
  87169. #endif
  87170. static int test_tls_cert_store_unchanged(void)
  87171. {
  87172. EXPECT_DECLS;
  87173. #if !defined(NO_CERTS) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  87174. test_ssl_cbf client_cbf;
  87175. test_ssl_cbf server_cbf;
  87176. int i;
  87177. for (i = 0; i < 2; i++) {
  87178. XMEMSET(&client_cbf, 0, sizeof(client_cbf));
  87179. XMEMSET(&server_cbf, 0, sizeof(server_cbf));
  87180. test_tls_cert_store_unchanged_before_hashes_idx = 0;
  87181. XMEMSET(test_tls_cert_store_unchanged_before_hashes, 0,
  87182. sizeof(test_tls_cert_store_unchanged_before_hashes));
  87183. test_tls_cert_store_unchanged_after_hashes_idx = 0;
  87184. XMEMSET(test_tls_cert_store_unchanged_after_hashes, 0,
  87185. sizeof(test_tls_cert_store_unchanged_after_hashes));
  87186. client_cbf.ctx_ready = test_tls_cert_store_unchanged_ctx_ready;
  87187. server_cbf.ctx_ready = test_tls_cert_store_unchanged_ctx_ready;
  87188. client_cbf.ssl_ready = test_tls_cert_store_unchanged_ssl_ready;
  87189. server_cbf.ssl_ready = test_tls_cert_store_unchanged_ssl_ready;
  87190. switch (i) {
  87191. case 0:
  87192. client_cbf.on_ctx_cleanup =
  87193. test_tls_cert_store_unchanged_ctx_cleanup;
  87194. server_cbf.on_ctx_cleanup =
  87195. test_tls_cert_store_unchanged_ctx_cleanup;
  87196. break;
  87197. case 1:
  87198. client_cbf.on_handshake = test_tls_cert_store_unchanged_on_hs;
  87199. server_cbf.on_handshake = test_tls_cert_store_unchanged_on_hs;
  87200. break;
  87201. default:
  87202. Fail(("Should not enter here"), ("Entered here"));
  87203. }
  87204. client_cbf.certPemFile = "certs/intermediate/client-chain.pem";
  87205. server_cbf.certPemFile = "certs/intermediate/server-chain.pem";
  87206. server_cbf.caPemFile = caCertFile;
  87207. ExpectIntEQ(test_wolfSSL_client_server_nofail_memio(&client_cbf,
  87208. &server_cbf, NULL), TEST_SUCCESS);
  87209. ExpectBufEQ(test_tls_cert_store_unchanged_before_hashes,
  87210. test_tls_cert_store_unchanged_after_hashes,
  87211. sizeof(test_tls_cert_store_unchanged_after_hashes));
  87212. }
  87213. #endif
  87214. return EXPECT_RESULT();
  87215. }
  87216. static int test_wolfSSL_SendUserCanceled(void)
  87217. {
  87218. EXPECT_DECLS;
  87219. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
  87220. size_t i;
  87221. struct {
  87222. method_provider client_meth;
  87223. method_provider server_meth;
  87224. const char* tls_version;
  87225. } params[] = {
  87226. #if defined(WOLFSSL_TLS13)
  87227. /* With WOLFSSL_TLS13_MIDDLEBOX_COMPAT a short ID will result in an error */
  87228. { wolfTLSv1_3_client_method, wolfTLSv1_3_server_method, "TLSv1_3" },
  87229. #ifdef WOLFSSL_DTLS13
  87230. { wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method, "DTLSv1_3" },
  87231. #endif
  87232. #endif
  87233. #ifndef WOLFSSL_NO_TLS12
  87234. { wolfTLSv1_2_client_method, wolfTLSv1_2_server_method, "TLSv1_2" },
  87235. #ifdef WOLFSSL_DTLS
  87236. { wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method, "DTLSv1_2" },
  87237. #endif
  87238. #endif
  87239. #if !defined(NO_OLD_TLS)
  87240. { wolfTLSv1_1_client_method, wolfTLSv1_1_server_method, "TLSv1_1" },
  87241. #ifdef WOLFSSL_DTLS
  87242. { wolfDTLSv1_client_method, wolfDTLSv1_server_method, "DTLSv1_0" },
  87243. #endif
  87244. #endif
  87245. };
  87246. for (i = 0; i < sizeof(params)/sizeof(*params) && !EXPECT_FAIL(); i++) {
  87247. WOLFSSL_CTX *ctx_c = NULL;
  87248. WOLFSSL_CTX *ctx_s = NULL;
  87249. WOLFSSL *ssl_c = NULL;
  87250. WOLFSSL *ssl_s = NULL;
  87251. struct test_memio_ctx test_ctx;
  87252. WOLFSSL_ALERT_HISTORY h;
  87253. printf("Testing %s\n", params[i].tls_version);
  87254. XMEMSET(&h, 0, sizeof(h));
  87255. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  87256. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  87257. params[i].client_meth, params[i].server_meth), 0);
  87258. /* CH1 */
  87259. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  87260. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
  87261. ExpectIntEQ(wolfSSL_SendUserCanceled(ssl_s), WOLFSSL_SHUTDOWN_NOT_DONE);
  87262. /* Alert closed connection */
  87263. ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
  87264. ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_ZERO_RETURN);
  87265. /* Last alert will be close notify because user_canceled should be
  87266. * followed by a close_notify */
  87267. ExpectIntEQ(wolfSSL_get_alert_history(ssl_c, &h), WOLFSSL_SUCCESS);
  87268. ExpectIntEQ(h.last_rx.code, close_notify);
  87269. ExpectIntEQ(h.last_rx.level, alert_warning);
  87270. wolfSSL_free(ssl_c);
  87271. wolfSSL_free(ssl_s);
  87272. wolfSSL_CTX_free(ctx_c);
  87273. wolfSSL_CTX_free(ctx_s);
  87274. }
  87275. #endif
  87276. return EXPECT_RESULT();
  87277. }
  87278. #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
  87279. defined(HAVE_OCSP) && \
  87280. defined(HAVE_CERTIFICATE_STATUS_REQUEST) && \
  87281. !defined(WOLFSSL_NO_TLS12)
  87282. static int test_ocsp_callback_fails_cb(void* ctx, const char* url, int urlSz,
  87283. byte* ocspReqBuf, int ocspReqSz, byte** ocspRespBuf)
  87284. {
  87285. (void)ctx;
  87286. (void)url;
  87287. (void)urlSz;
  87288. (void)ocspReqBuf;
  87289. (void)ocspReqSz;
  87290. (void)ocspRespBuf;
  87291. return -1;
  87292. }
  87293. static int test_ocsp_callback_fails(void)
  87294. {
  87295. WOLFSSL_CTX *ctx_c = NULL;
  87296. WOLFSSL_CTX *ctx_s = NULL;
  87297. WOLFSSL *ssl_c = NULL;
  87298. WOLFSSL *ssl_s = NULL;
  87299. struct test_memio_ctx test_ctx;
  87300. EXPECT_DECLS;
  87301. XMEMSET(&test_ctx, 0, sizeof(test_ctx));
  87302. ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
  87303. wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
  87304. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx_c), WOLFSSL_SUCCESS);
  87305. ExpectIntEQ(wolfSSL_CTX_EnableOCSPStapling(ctx_s), WOLFSSL_SUCCESS);
  87306. ExpectIntEQ(wolfSSL_UseOCSPStapling(ssl_c, WOLFSSL_CSR_OCSP,0), WOLFSSL_SUCCESS);
  87307. /* override URL to avoid exing from SendCertificateStatus because of no AuthInfo on the certificate */
  87308. ExpectIntEQ(wolfSSL_CTX_SetOCSP_OverrideURL(ctx_s, "http://dummy.test"), WOLFSSL_SUCCESS);
  87309. ExpectIntEQ(wolfSSL_CTX_EnableOCSP(ctx_s, WOLFSSL_OCSP_NO_NONCE | WOLFSSL_OCSP_URL_OVERRIDE), WOLFSSL_SUCCESS);
  87310. ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx_s, caCertFile, 0), WOLFSSL_SUCCESS);
  87311. ExpectIntEQ(wolfSSL_SetOCSP_Cb(ssl_s, test_ocsp_callback_fails_cb, NULL, NULL), WOLFSSL_SUCCESS);
  87312. ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), -1);
  87313. ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WC_NO_ERR_TRACE(OCSP_INVALID_STATUS));
  87314. wolfSSL_free(ssl_c);
  87315. wolfSSL_free(ssl_s);
  87316. wolfSSL_CTX_free(ctx_c);
  87317. wolfSSL_CTX_free(ctx_s);
  87318. return EXPECT_RESULT();
  87319. }
  87320. #else
  87321. static int test_ocsp_callback_fails(void)
  87322. {
  87323. return TEST_SKIPPED;
  87324. }
  87325. #endif /* defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
  87326. defined(HAVE_OCSP) && \
  87327. defined(HAVE_CERTIFICATE_STATUS_REQUEST) */
  87328. /*----------------------------------------------------------------------------*
  87329. | Main
  87330. *----------------------------------------------------------------------------*/
  87331. typedef int (*TEST_FUNC)(void);
  87332. typedef struct {
  87333. const char *name;
  87334. TEST_FUNC func;
  87335. byte run:1;
  87336. byte fail:1;
  87337. } TEST_CASE;
  87338. #define TEST_DECL(func) { #func, func, 0, 0 }
  87339. int testAll = 1;
  87340. TEST_CASE testCases[] = {
  87341. TEST_DECL(test_fileAccess),
  87342. /*********************************
  87343. * wolfcrypt
  87344. *********************************/
  87345. TEST_DECL(test_ForceZero),
  87346. TEST_DECL(test_wolfCrypt_Init),
  87347. TEST_DECL(test_wc_LoadStaticMemory_ex),
  87348. /* Locking with Compat Mutex */
  87349. TEST_DECL(test_wc_SetMutexCb),
  87350. TEST_DECL(test_wc_LockMutex_ex),
  87351. /* Digests */
  87352. TEST_DECL(test_wc_InitMd5),
  87353. TEST_DECL(test_wc_Md5Update),
  87354. TEST_DECL(test_wc_Md5Final),
  87355. TEST_DECL(test_wc_InitSha),
  87356. TEST_DECL(test_wc_ShaUpdate),
  87357. TEST_DECL(test_wc_ShaFinal),
  87358. TEST_DECL(test_wc_InitSha256),
  87359. TEST_DECL(test_wc_Sha256Update),
  87360. TEST_DECL(test_wc_Sha256Final),
  87361. TEST_DECL(test_wc_Sha256FinalRaw),
  87362. TEST_DECL(test_wc_Sha256GetFlags),
  87363. TEST_DECL(test_wc_Sha256Free),
  87364. TEST_DECL(test_wc_Sha256GetHash),
  87365. TEST_DECL(test_wc_Sha256Copy),
  87366. TEST_DECL(test_wc_InitSha224),
  87367. TEST_DECL(test_wc_Sha224Update),
  87368. TEST_DECL(test_wc_Sha224Final),
  87369. TEST_DECL(test_wc_Sha224SetFlags),
  87370. TEST_DECL(test_wc_Sha224GetFlags),
  87371. TEST_DECL(test_wc_Sha224Free),
  87372. TEST_DECL(test_wc_Sha224GetHash),
  87373. TEST_DECL(test_wc_Sha224Copy),
  87374. TEST_DECL(test_wc_InitSha512),
  87375. TEST_DECL(test_wc_Sha512Update),
  87376. TEST_DECL(test_wc_Sha512Final),
  87377. TEST_DECL(test_wc_Sha512GetFlags),
  87378. TEST_DECL(test_wc_Sha512FinalRaw),
  87379. TEST_DECL(test_wc_Sha512Free),
  87380. TEST_DECL(test_wc_Sha512GetHash),
  87381. TEST_DECL(test_wc_Sha512Copy),
  87382. TEST_DECL(test_wc_InitSha512_224),
  87383. TEST_DECL(test_wc_Sha512_224Update),
  87384. TEST_DECL(test_wc_Sha512_224Final),
  87385. TEST_DECL(test_wc_Sha512_224GetFlags),
  87386. TEST_DECL(test_wc_Sha512_224FinalRaw),
  87387. TEST_DECL(test_wc_Sha512_224Free),
  87388. TEST_DECL(test_wc_Sha512_224GetHash),
  87389. TEST_DECL(test_wc_Sha512_224Copy),
  87390. TEST_DECL(test_wc_InitSha512_256),
  87391. TEST_DECL(test_wc_Sha512_256Update),
  87392. TEST_DECL(test_wc_Sha512_256Final),
  87393. TEST_DECL(test_wc_Sha512_256GetFlags),
  87394. TEST_DECL(test_wc_Sha512_256FinalRaw),
  87395. TEST_DECL(test_wc_Sha512_256Free),
  87396. TEST_DECL(test_wc_Sha512_256GetHash),
  87397. TEST_DECL(test_wc_Sha512_256Copy),
  87398. TEST_DECL(test_wc_InitSha384),
  87399. TEST_DECL(test_wc_Sha384Update),
  87400. TEST_DECL(test_wc_Sha384Final),
  87401. TEST_DECL(test_wc_Sha384GetFlags),
  87402. TEST_DECL(test_wc_Sha384FinalRaw),
  87403. TEST_DECL(test_wc_Sha384Free),
  87404. TEST_DECL(test_wc_Sha384GetHash),
  87405. TEST_DECL(test_wc_Sha384Copy),
  87406. TEST_DECL(test_wc_InitBlake2b),
  87407. TEST_DECL(test_wc_InitBlake2b_WithKey),
  87408. TEST_DECL(test_wc_InitBlake2s_WithKey),
  87409. TEST_DECL(test_wc_InitRipeMd),
  87410. TEST_DECL(test_wc_RipeMdUpdate),
  87411. TEST_DECL(test_wc_RipeMdFinal),
  87412. TEST_DECL(test_wc_InitSha3),
  87413. TEST_DECL(testing_wc_Sha3_Update),
  87414. TEST_DECL(test_wc_Sha3_224_Final),
  87415. TEST_DECL(test_wc_Sha3_256_Final),
  87416. TEST_DECL(test_wc_Sha3_384_Final),
  87417. TEST_DECL(test_wc_Sha3_512_Final),
  87418. TEST_DECL(test_wc_Sha3_224_Copy),
  87419. TEST_DECL(test_wc_Sha3_256_Copy),
  87420. TEST_DECL(test_wc_Sha3_384_Copy),
  87421. TEST_DECL(test_wc_Sha3_512_Copy),
  87422. TEST_DECL(test_wc_Sha3_GetFlags),
  87423. TEST_DECL(test_wc_InitShake256),
  87424. TEST_DECL(testing_wc_Shake256_Update),
  87425. TEST_DECL(test_wc_Shake256_Final),
  87426. TEST_DECL(test_wc_Shake256_Copy),
  87427. TEST_DECL(test_wc_Shake256Hash),
  87428. /* SM3 Digest */
  87429. TEST_DECL(test_wc_InitSm3Free),
  87430. TEST_DECL(test_wc_Sm3UpdateFinal),
  87431. TEST_DECL(test_wc_Sm3GetHash),
  87432. TEST_DECL(test_wc_Sm3Copy),
  87433. TEST_DECL(test_wc_Sm3FinalRaw),
  87434. TEST_DECL(test_wc_Sm3GetSetFlags),
  87435. TEST_DECL(test_wc_Sm3Hash),
  87436. TEST_DECL(test_wc_HashInit),
  87437. TEST_DECL(test_wc_HashSetFlags),
  87438. TEST_DECL(test_wc_HashGetFlags),
  87439. /* HMAC */
  87440. TEST_DECL(test_wc_Md5HmacSetKey),
  87441. TEST_DECL(test_wc_Md5HmacUpdate),
  87442. TEST_DECL(test_wc_Md5HmacFinal),
  87443. TEST_DECL(test_wc_ShaHmacSetKey),
  87444. TEST_DECL(test_wc_ShaHmacUpdate),
  87445. TEST_DECL(test_wc_ShaHmacFinal),
  87446. TEST_DECL(test_wc_Sha224HmacSetKey),
  87447. TEST_DECL(test_wc_Sha224HmacUpdate),
  87448. TEST_DECL(test_wc_Sha224HmacFinal),
  87449. TEST_DECL(test_wc_Sha256HmacSetKey),
  87450. TEST_DECL(test_wc_Sha256HmacUpdate),
  87451. TEST_DECL(test_wc_Sha256HmacFinal),
  87452. TEST_DECL(test_wc_Sha384HmacSetKey),
  87453. TEST_DECL(test_wc_Sha384HmacUpdate),
  87454. TEST_DECL(test_wc_Sha384HmacFinal),
  87455. /* CMAC */
  87456. TEST_DECL(test_wc_InitCmac),
  87457. TEST_DECL(test_wc_CmacUpdate),
  87458. TEST_DECL(test_wc_CmacFinal),
  87459. TEST_DECL(test_wc_AesCmacGenerate),
  87460. /* Cipher */
  87461. TEST_DECL(test_wc_AesGcmStream),
  87462. TEST_DECL(test_wc_Des3_SetIV),
  87463. TEST_DECL(test_wc_Des3_SetKey),
  87464. TEST_DECL(test_wc_Des3_CbcEncryptDecrypt),
  87465. TEST_DECL(test_wc_Des3_CbcEncryptDecryptWithKey),
  87466. TEST_DECL(test_wc_Des3_EcbEncrypt),
  87467. TEST_DECL(test_wc_Chacha_SetKey),
  87468. TEST_DECL(test_wc_Chacha_Process),
  87469. TEST_DECL(test_wc_ChaCha20Poly1305_aead),
  87470. TEST_DECL(test_wc_Poly1305SetKey),
  87471. TEST_DECL(test_wc_CamelliaSetKey),
  87472. TEST_DECL(test_wc_CamelliaSetIV),
  87473. TEST_DECL(test_wc_CamelliaEncryptDecryptDirect),
  87474. TEST_DECL(test_wc_CamelliaCbcEncryptDecrypt),
  87475. TEST_DECL(test_wc_Arc4SetKey),
  87476. TEST_DECL(test_wc_Arc4Process),
  87477. TEST_DECL(test_wc_Rc2SetKey),
  87478. TEST_DECL(test_wc_Rc2SetIV),
  87479. TEST_DECL(test_wc_Rc2EcbEncryptDecrypt),
  87480. TEST_DECL(test_wc_Rc2CbcEncryptDecrypt),
  87481. /* AES cipher and GMAC. */
  87482. TEST_DECL(test_wc_AesSetKey),
  87483. TEST_DECL(test_wc_AesSetIV),
  87484. TEST_DECL(test_wc_AesCbcEncryptDecrypt),
  87485. TEST_DECL(test_wc_AesCtrEncryptDecrypt),
  87486. TEST_DECL(test_wc_AesGcmSetKey),
  87487. TEST_DECL(test_wc_AesGcmEncryptDecrypt),
  87488. TEST_DECL(test_wc_AesGcmMixedEncDecLongIV),
  87489. TEST_DECL(test_wc_GmacSetKey),
  87490. TEST_DECL(test_wc_GmacUpdate),
  87491. TEST_DECL(test_wc_AesCcmSetKey),
  87492. TEST_DECL(test_wc_AesCcmEncryptDecrypt),
  87493. #if defined(WOLFSSL_AES_EAX) && \
  87494. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  87495. TEST_DECL(test_wc_AesEaxVectors),
  87496. TEST_DECL(test_wc_AesEaxEncryptAuth),
  87497. TEST_DECL(test_wc_AesEaxDecryptAuth),
  87498. #endif /* WOLFSSL_AES_EAX */
  87499. /* SM4 cipher */
  87500. TEST_DECL(test_wc_Sm4),
  87501. TEST_DECL(test_wc_Sm4Ecb),
  87502. TEST_DECL(test_wc_Sm4Cbc),
  87503. TEST_DECL(test_wc_Sm4Ctr),
  87504. TEST_DECL(test_wc_Sm4Gcm),
  87505. TEST_DECL(test_wc_Sm4Ccm),
  87506. /* RNG tests */
  87507. #ifdef HAVE_HASHDRBG
  87508. #ifdef TEST_RESEED_INTERVAL
  87509. TEST_DECL(test_wc_RNG_GenerateBlock_Reseed),
  87510. #endif
  87511. TEST_DECL(test_wc_RNG_GenerateBlock),
  87512. #endif
  87513. TEST_DECL(test_get_rand_digit),
  87514. TEST_DECL(test_wc_InitRngNonce),
  87515. TEST_DECL(test_wc_InitRngNonce_ex),
  87516. /* MP API tests */
  87517. TEST_DECL(test_get_digit_count),
  87518. TEST_DECL(test_mp_cond_copy),
  87519. TEST_DECL(test_mp_rand),
  87520. TEST_DECL(test_get_digit),
  87521. TEST_DECL(test_wc_export_int),
  87522. /* RSA */
  87523. TEST_DECL(test_wc_InitRsaKey),
  87524. TEST_DECL(test_wc_RsaPrivateKeyDecode),
  87525. TEST_DECL(test_wc_RsaPublicKeyDecode),
  87526. TEST_DECL(test_wc_RsaPublicKeyDecodeRaw),
  87527. TEST_DECL(test_wc_RsaPrivateKeyDecodeRaw),
  87528. TEST_DECL(test_wc_MakeRsaKey),
  87529. TEST_DECL(test_wc_CheckProbablePrime),
  87530. TEST_DECL(test_wc_RsaPSS_Verify),
  87531. TEST_DECL(test_wc_RsaPSS_VerifyCheck),
  87532. TEST_DECL(test_wc_RsaPSS_VerifyCheckInline),
  87533. TEST_DECL(test_wc_RsaKeyToDer),
  87534. TEST_DECL(test_wc_RsaKeyToPublicDer),
  87535. TEST_DECL(test_wc_RsaPublicEncryptDecrypt),
  87536. TEST_DECL(test_wc_RsaPublicEncryptDecrypt_ex),
  87537. TEST_DECL(test_wc_RsaEncryptSize),
  87538. TEST_DECL(test_wc_RsaSSL_SignVerify),
  87539. TEST_DECL(test_wc_RsaFlattenPublicKey),
  87540. TEST_DECL(test_RsaDecryptBoundsCheck),
  87541. /* DSA */
  87542. TEST_DECL(test_wc_InitDsaKey),
  87543. TEST_DECL(test_wc_DsaSignVerify),
  87544. TEST_DECL(test_wc_DsaPublicPrivateKeyDecode),
  87545. TEST_DECL(test_wc_MakeDsaKey),
  87546. TEST_DECL(test_wc_DsaKeyToDer),
  87547. TEST_DECL(test_wc_DsaKeyToPublicDer),
  87548. TEST_DECL(test_wc_DsaImportParamsRaw),
  87549. TEST_DECL(test_wc_DsaImportParamsRawCheck),
  87550. TEST_DECL(test_wc_DsaExportParamsRaw),
  87551. TEST_DECL(test_wc_DsaExportKeyRaw),
  87552. /* DH */
  87553. TEST_DECL(test_wc_DhPublicKeyDecode),
  87554. /* wolfCrypt ECC tests */
  87555. TEST_DECL(test_wc_ecc_get_curve_size_from_name),
  87556. TEST_DECL(test_wc_ecc_get_curve_id_from_name),
  87557. TEST_DECL(test_wc_ecc_get_curve_id_from_params),
  87558. #if defined(OPENSSL_EXTRA) && defined(HAVE_ECC) && \
  87559. !defined(HAVE_SELFTEST) && \
  87560. !(defined(HAVE_FIPS) || defined(HAVE_FIPS_VERSION))
  87561. TEST_DECL(test_wc_ecc_get_curve_id_from_dp_params),
  87562. #endif
  87563. TEST_DECL(test_wc_ecc_make_key),
  87564. TEST_DECL(test_wc_ecc_init),
  87565. TEST_DECL(test_wc_ecc_check_key),
  87566. TEST_DECL(test_wc_ecc_get_generator),
  87567. TEST_DECL(test_wc_ecc_size),
  87568. TEST_DECL(test_wc_ecc_params),
  87569. TEST_DECL(test_wc_ecc_signVerify_hash),
  87570. TEST_DECL(test_wc_ecc_shared_secret),
  87571. TEST_DECL(test_wc_ecc_export_x963),
  87572. TEST_DECL(test_wc_ecc_export_x963_ex),
  87573. TEST_DECL(test_wc_ecc_import_x963),
  87574. TEST_DECL(test_wc_ecc_import_private_key),
  87575. TEST_DECL(test_wc_ecc_export_private_only),
  87576. TEST_DECL(test_wc_ecc_rs_to_sig),
  87577. TEST_DECL(test_wc_ecc_import_raw),
  87578. TEST_DECL(test_wc_ecc_import_unsigned),
  87579. TEST_DECL(test_wc_ecc_sig_size),
  87580. TEST_DECL(test_wc_ecc_ctx_new),
  87581. TEST_DECL(test_wc_ecc_ctx_reset),
  87582. TEST_DECL(test_wc_ecc_ctx_set_peer_salt),
  87583. TEST_DECL(test_wc_ecc_ctx_set_info),
  87584. TEST_DECL(test_wc_ecc_encryptDecrypt),
  87585. TEST_DECL(test_wc_ecc_del_point),
  87586. TEST_DECL(test_wc_ecc_pointFns),
  87587. TEST_DECL(test_wc_ecc_shared_secret_ssh),
  87588. TEST_DECL(test_wc_ecc_verify_hash_ex),
  87589. TEST_DECL(test_wc_ecc_mulmod),
  87590. TEST_DECL(test_wc_ecc_is_valid_idx),
  87591. TEST_DECL(test_wc_ecc_get_curve_id_from_oid),
  87592. TEST_DECL(test_wc_ecc_sig_size_calc),
  87593. TEST_DECL(test_wc_EccPrivateKeyToDer),
  87594. /* SM2 elliptic curve */
  87595. TEST_DECL(test_wc_ecc_sm2_make_key),
  87596. TEST_DECL(test_wc_ecc_sm2_shared_secret),
  87597. TEST_DECL(test_wc_ecc_sm2_create_digest),
  87598. TEST_DECL(test_wc_ecc_sm2_verify_hash_ex),
  87599. TEST_DECL(test_wc_ecc_sm2_verify_hash),
  87600. TEST_DECL(test_wc_ecc_sm2_sign_hash_ex),
  87601. TEST_DECL(test_wc_ecc_sm2_sign_hash),
  87602. /* Curve25519 */
  87603. TEST_DECL(test_wc_curve25519_init),
  87604. TEST_DECL(test_wc_curve25519_size),
  87605. TEST_DECL(test_wc_curve25519_export_key_raw),
  87606. TEST_DECL(test_wc_curve25519_export_key_raw_ex),
  87607. TEST_DECL(test_wc_curve25519_make_key),
  87608. TEST_DECL(test_wc_curve25519_shared_secret_ex),
  87609. TEST_DECL(test_wc_curve25519_make_pub),
  87610. TEST_DECL(test_wc_curve25519_export_public_ex),
  87611. TEST_DECL(test_wc_curve25519_export_private_raw_ex),
  87612. TEST_DECL(test_wc_curve25519_import_private_raw_ex),
  87613. TEST_DECL(test_wc_curve25519_import_private),
  87614. /* ED25519 */
  87615. TEST_DECL(test_wc_ed25519_make_key),
  87616. TEST_DECL(test_wc_ed25519_init),
  87617. TEST_DECL(test_wc_ed25519_sign_msg),
  87618. TEST_DECL(test_wc_ed25519_import_public),
  87619. TEST_DECL(test_wc_ed25519_import_private_key),
  87620. TEST_DECL(test_wc_ed25519_export),
  87621. TEST_DECL(test_wc_ed25519_size),
  87622. TEST_DECL(test_wc_ed25519_exportKey),
  87623. TEST_DECL(test_wc_Ed25519PublicKeyToDer),
  87624. TEST_DECL(test_wc_Ed25519KeyToDer),
  87625. TEST_DECL(test_wc_Ed25519PrivateKeyToDer),
  87626. /* Curve448 */
  87627. TEST_DECL(test_wc_curve448_make_key),
  87628. TEST_DECL(test_wc_curve448_shared_secret_ex),
  87629. TEST_DECL(test_wc_curve448_export_public_ex),
  87630. TEST_DECL(test_wc_curve448_export_private_raw_ex),
  87631. TEST_DECL(test_wc_curve448_export_key_raw),
  87632. TEST_DECL(test_wc_curve448_import_private_raw_ex),
  87633. TEST_DECL(test_wc_curve448_import_private),
  87634. TEST_DECL(test_wc_curve448_init),
  87635. TEST_DECL(test_wc_curve448_size),
  87636. /* Ed448 */
  87637. TEST_DECL(test_wc_ed448_make_key),
  87638. TEST_DECL(test_wc_ed448_init),
  87639. TEST_DECL(test_wc_ed448_sign_msg),
  87640. TEST_DECL(test_wc_ed448_import_public),
  87641. TEST_DECL(test_wc_ed448_import_private_key),
  87642. TEST_DECL(test_wc_ed448_export),
  87643. TEST_DECL(test_wc_ed448_size),
  87644. TEST_DECL(test_wc_ed448_exportKey),
  87645. TEST_DECL(test_wc_Ed448PublicKeyToDer),
  87646. TEST_DECL(test_wc_Ed448KeyToDer),
  87647. TEST_DECL(test_wc_Ed448PrivateKeyToDer),
  87648. TEST_DECL(test_wc_Curve448PrivateKeyToDer),
  87649. /* Kyber */
  87650. TEST_DECL(test_wc_kyber_make_key_kats),
  87651. TEST_DECL(test_wc_kyber_encapsulate_kats),
  87652. TEST_DECL(test_wc_kyber_decapsulate_kats),
  87653. /* Dilithium */
  87654. TEST_DECL(test_wc_dilithium),
  87655. TEST_DECL(test_wc_dilithium_make_key),
  87656. TEST_DECL(test_wc_dilithium_sign),
  87657. TEST_DECL(test_wc_dilithium_verify),
  87658. TEST_DECL(test_wc_dilithium_sign_vfy),
  87659. TEST_DECL(test_wc_dilithium_check_key),
  87660. TEST_DECL(test_wc_dilithium_public_der_decode),
  87661. TEST_DECL(test_wc_dilithium_der),
  87662. TEST_DECL(test_wc_dilithium_make_key_from_seed),
  87663. TEST_DECL(test_wc_dilithium_sig_kats),
  87664. TEST_DECL(test_wc_dilithium_verify_kats),
  87665. /* Signature API */
  87666. TEST_DECL(test_wc_SignatureGetSize_ecc),
  87667. TEST_DECL(test_wc_SignatureGetSize_rsa),
  87668. /* PEM and DER APIs. */
  87669. TEST_DECL(test_wc_PemToDer),
  87670. TEST_DECL(test_wc_AllocDer),
  87671. TEST_DECL(test_wc_CertPemToDer),
  87672. TEST_DECL(test_wc_KeyPemToDer),
  87673. TEST_DECL(test_wc_PubKeyPemToDer),
  87674. TEST_DECL(test_wc_PemPubKeyToDer),
  87675. TEST_DECL(test_wc_GetPubKeyDerFromCert),
  87676. TEST_DECL(test_wc_CheckCertSigPubKey),
  87677. /* wolfCrypt ASN tests */
  87678. TEST_DECL(test_ToTraditional),
  87679. TEST_DECL(test_wc_CreateEncryptedPKCS8Key),
  87680. TEST_DECL(test_wc_GetPkcs8TraditionalOffset),
  87681. /* Certificate */
  87682. TEST_DECL(test_wc_SetSubjectRaw),
  87683. TEST_DECL(test_wc_GetSubjectRaw),
  87684. TEST_DECL(test_wc_SetIssuerRaw),
  87685. TEST_DECL(test_wc_SetIssueBuffer),
  87686. TEST_DECL(test_wc_SetSubjectKeyId),
  87687. TEST_DECL(test_wc_SetSubject),
  87688. TEST_DECL(test_CheckCertSignature),
  87689. TEST_DECL(test_wc_ParseCert),
  87690. TEST_DECL(test_wc_ParseCert_Error),
  87691. TEST_DECL(test_MakeCertWithPathLen),
  87692. TEST_DECL(test_MakeCertWith0Ser),
  87693. TEST_DECL(test_MakeCertWithCaFalse),
  87694. TEST_DECL(test_wc_SetKeyUsage),
  87695. TEST_DECL(test_wc_SetAuthKeyIdFromPublicKey_ex),
  87696. TEST_DECL(test_wc_SetSubjectBuffer),
  87697. TEST_DECL(test_wc_SetSubjectKeyIdFromPublicKey_ex),
  87698. /* wolfcrypt PKCS#7 */
  87699. TEST_DECL(test_wc_PKCS7_New),
  87700. TEST_DECL(test_wc_PKCS7_Init),
  87701. TEST_DECL(test_wc_PKCS7_InitWithCert),
  87702. TEST_DECL(test_wc_PKCS7_EncodeData),
  87703. TEST_DECL(test_wc_PKCS7_EncodeSignedData),
  87704. TEST_DECL(test_wc_PKCS7_EncodeSignedData_ex),
  87705. TEST_DECL(test_wc_PKCS7_VerifySignedData_RSA),
  87706. TEST_DECL(test_wc_PKCS7_VerifySignedData_ECC),
  87707. TEST_DECL(test_wc_PKCS7_EncodeDecodeEnvelopedData),
  87708. TEST_DECL(test_wc_PKCS7_EncodeEncryptedData),
  87709. TEST_DECL(test_wc_PKCS7_Degenerate),
  87710. TEST_DECL(test_wc_PKCS7_BER),
  87711. TEST_DECL(test_wc_PKCS7_signed_enveloped),
  87712. TEST_DECL(test_wc_PKCS7_NoDefaultSignedAttribs),
  87713. TEST_DECL(test_wc_PKCS7_SetOriEncryptCtx),
  87714. TEST_DECL(test_wc_PKCS7_SetOriDecryptCtx),
  87715. TEST_DECL(test_wc_PKCS7_DecodeCompressedData),
  87716. /* wolfCrypt PKCS#12 */
  87717. TEST_DECL(test_wc_i2d_PKCS12),
  87718. /*
  87719. * test_wolfCrypt_Cleanup needs to come after the above wolfCrypt tests to
  87720. * avoid memory leaks.
  87721. */
  87722. TEST_DECL(test_wolfCrypt_Cleanup),
  87723. TEST_DECL(test_wolfSSL_Init),
  87724. TEST_DECL(test_dual_alg_support),
  87725. /*********************************
  87726. * OpenSSL compatibility API tests
  87727. *********************************/
  87728. /* If at some point a stub get implemented this test should fail indicating
  87729. * a need to implement a new test case
  87730. */
  87731. TEST_DECL(test_stubs_are_stubs),
  87732. /* ASN.1 compatibility API tests */
  87733. TEST_DECL(test_wolfSSL_ASN1_BIT_STRING),
  87734. TEST_DECL(test_wolfSSL_ASN1_INTEGER),
  87735. TEST_DECL(test_wolfSSL_ASN1_INTEGER_cmp),
  87736. TEST_DECL(test_wolfSSL_ASN1_INTEGER_BN),
  87737. TEST_DECL(test_wolfSSL_ASN1_INTEGER_get_set),
  87738. TEST_DECL(test_wolfSSL_d2i_ASN1_INTEGER),
  87739. TEST_DECL(test_wolfSSL_a2i_ASN1_INTEGER),
  87740. TEST_DECL(test_wolfSSL_i2c_ASN1_INTEGER),
  87741. TEST_DECL(test_wolfSSL_ASN1_OBJECT),
  87742. TEST_DECL(test_wolfSSL_ASN1_get_object),
  87743. TEST_DECL(test_wolfSSL_i2a_ASN1_OBJECT),
  87744. TEST_DECL(test_wolfSSL_i2t_ASN1_OBJECT),
  87745. TEST_DECL(test_wolfSSL_sk_ASN1_OBJECT),
  87746. TEST_DECL(test_wolfSSL_ASN1_STRING),
  87747. TEST_DECL(test_wolfSSL_ASN1_STRING_to_UTF8),
  87748. TEST_DECL(test_wolfSSL_i2s_ASN1_STRING),
  87749. TEST_DECL(test_wolfSSL_ASN1_STRING_canon),
  87750. TEST_DECL(test_wolfSSL_ASN1_STRING_print),
  87751. TEST_DECL(test_wolfSSL_ASN1_STRING_print_ex),
  87752. TEST_DECL(test_wolfSSL_ASN1_UNIVERSALSTRING_to_string),
  87753. TEST_DECL(test_wolfSSL_ASN1_GENERALIZEDTIME_free),
  87754. TEST_DECL(test_wolfSSL_ASN1_GENERALIZEDTIME_print),
  87755. TEST_DECL(test_wolfSSL_ASN1_TIME),
  87756. TEST_DECL(test_wolfSSL_ASN1_TIME_to_string),
  87757. TEST_DECL(test_wolfSSL_ASN1_TIME_diff_compare),
  87758. TEST_DECL(test_wolfSSL_ASN1_TIME_adj),
  87759. TEST_DECL(test_wolfSSL_ASN1_TIME_to_tm),
  87760. TEST_DECL(test_wolfSSL_ASN1_TIME_to_generalizedtime),
  87761. TEST_DECL(test_wolfSSL_ASN1_TIME_print),
  87762. TEST_DECL(test_wolfSSL_ASN1_UTCTIME_print),
  87763. TEST_DECL(test_wolfSSL_ASN1_TYPE),
  87764. TEST_DECL(test_wolfSSL_IMPLEMENT_ASN1_FUNCTIONS),
  87765. TEST_DECL(test_wolfSSL_i2d_ASN1_TYPE),
  87766. TEST_DECL(test_wolfSSL_i2d_ASN1_SEQUENCE),
  87767. TEST_DECL(test_ASN1_strings),
  87768. TEST_DECL(test_wolfSSL_lhash),
  87769. TEST_DECL(test_wolfSSL_certs),
  87770. TEST_DECL(test_wolfSSL_private_keys),
  87771. TEST_DECL(test_wolfSSL_PEM_def_callback),
  87772. TEST_DECL(test_wolfSSL_PEM_read_PrivateKey),
  87773. TEST_DECL(test_wolfSSL_PEM_read_RSA_PUBKEY),
  87774. TEST_DECL(test_wolfSSL_PEM_read_PUBKEY),
  87775. TEST_DECL(test_wolfSSL_PEM_PrivateKey_rsa),
  87776. TEST_DECL(test_wolfSSL_PEM_PrivateKey_ecc),
  87777. TEST_DECL(test_wolfSSL_PEM_PrivateKey_dsa),
  87778. TEST_DECL(test_wolfSSL_PEM_PrivateKey_dh),
  87779. TEST_DECL(test_wolfSSL_PEM_PrivateKey),
  87780. TEST_DECL(test_wolfSSL_PEM_file_RSAKey),
  87781. TEST_DECL(test_wolfSSL_PEM_file_RSAPrivateKey),
  87782. #ifndef NO_BIO
  87783. TEST_DECL(test_wolfSSL_BIO),
  87784. TEST_DECL(test_wolfSSL_BIO_BIO_ring_read),
  87785. TEST_DECL(test_wolfSSL_PEM_read_bio),
  87786. TEST_DECL(test_wolfSSL_PEM_bio_RSAKey),
  87787. TEST_DECL(test_wolfSSL_PEM_bio_DSAKey),
  87788. TEST_DECL(test_wolfSSL_PEM_bio_ECKey),
  87789. TEST_DECL(test_wolfSSL_PEM_bio_RSAPrivateKey),
  87790. TEST_DECL(test_wolfSSL_PEM_PUBKEY),
  87791. #endif
  87792. /* EVP API testing */
  87793. TEST_DECL(test_wolfSSL_EVP_ENCODE_CTX_new),
  87794. TEST_DECL(test_wolfSSL_EVP_ENCODE_CTX_free),
  87795. TEST_DECL(test_wolfSSL_EVP_EncodeInit),
  87796. TEST_DECL(test_wolfSSL_EVP_EncodeUpdate),
  87797. TEST_DECL(test_wolfSSL_EVP_EncodeFinal),
  87798. TEST_DECL(test_wolfSSL_EVP_DecodeInit),
  87799. TEST_DECL(test_wolfSSL_EVP_DecodeUpdate),
  87800. TEST_DECL(test_wolfSSL_EVP_DecodeFinal),
  87801. TEST_DECL(test_wolfSSL_EVP_shake128),
  87802. TEST_DECL(test_wolfSSL_EVP_shake256),
  87803. TEST_DECL(test_wolfSSL_EVP_sm3),
  87804. TEST_DECL(test_EVP_blake2),
  87805. #ifdef OPENSSL_ALL
  87806. TEST_DECL(test_wolfSSL_EVP_md4),
  87807. TEST_DECL(test_wolfSSL_EVP_ripemd160),
  87808. TEST_DECL(test_wolfSSL_EVP_get_digestbynid),
  87809. TEST_DECL(test_wolfSSL_EVP_MD_nid),
  87810. TEST_DECL(test_wolfSSL_EVP_DigestFinal_ex),
  87811. #endif
  87812. TEST_DECL(test_EVP_MD_do_all),
  87813. TEST_DECL(test_wolfSSL_EVP_MD_size),
  87814. TEST_DECL(test_wolfSSL_EVP_MD_pkey_type),
  87815. TEST_DECL(test_wolfSSL_EVP_Digest),
  87816. TEST_DECL(test_wolfSSL_EVP_Digest_all),
  87817. TEST_DECL(test_wolfSSL_EVP_MD_hmac_signing),
  87818. TEST_DECL(test_wolfSSL_EVP_MD_rsa_signing),
  87819. TEST_DECL(test_wolfSSL_EVP_MD_ecc_signing),
  87820. TEST_DECL(test_wolfssl_EVP_aes_gcm),
  87821. TEST_DECL(test_wolfssl_EVP_aes_gcm_AAD_2_parts),
  87822. TEST_DECL(test_wolfssl_EVP_aes_gcm_zeroLen),
  87823. TEST_DECL(test_wolfssl_EVP_aes_ccm),
  87824. TEST_DECL(test_wolfssl_EVP_aes_ccm_zeroLen),
  87825. TEST_DECL(test_wolfssl_EVP_chacha20),
  87826. TEST_DECL(test_wolfssl_EVP_chacha20_poly1305),
  87827. TEST_DECL(test_wolfssl_EVP_sm4_ecb),
  87828. TEST_DECL(test_wolfssl_EVP_sm4_cbc),
  87829. TEST_DECL(test_wolfssl_EVP_sm4_ctr),
  87830. TEST_DECL(test_wolfssl_EVP_sm4_gcm_zeroLen),
  87831. TEST_DECL(test_wolfssl_EVP_sm4_gcm),
  87832. TEST_DECL(test_wolfssl_EVP_sm4_ccm_zeroLen),
  87833. TEST_DECL(test_wolfssl_EVP_sm4_ccm),
  87834. #ifdef OPENSSL_ALL
  87835. TEST_DECL(test_wolfSSL_EVP_aes_256_gcm),
  87836. TEST_DECL(test_wolfSSL_EVP_aes_192_gcm),
  87837. TEST_DECL(test_wolfSSL_EVP_aes_256_ccm),
  87838. TEST_DECL(test_wolfSSL_EVP_aes_192_ccm),
  87839. TEST_DECL(test_wolfSSL_EVP_aes_128_ccm),
  87840. TEST_DECL(test_wolfSSL_EVP_rc4),
  87841. TEST_DECL(test_wolfSSL_EVP_enc_null),
  87842. TEST_DECL(test_wolfSSL_EVP_rc2_cbc),
  87843. TEST_DECL(test_wolfSSL_EVP_mdc2),
  87844. TEST_DECL(test_evp_cipher_aes_gcm),
  87845. #endif
  87846. TEST_DECL(test_wolfssl_EVP_aria_gcm),
  87847. TEST_DECL(test_wolfSSL_EVP_Cipher_extra),
  87848. #ifdef OPENSSL_EXTRA
  87849. TEST_DECL(test_wolfSSL_EVP_get_cipherbynid),
  87850. TEST_DECL(test_wolfSSL_EVP_CIPHER_CTX),
  87851. #endif
  87852. #ifdef OPENSSL_ALL
  87853. TEST_DECL(test_wolfSSL_EVP_CIPHER_CTX_iv_length),
  87854. TEST_DECL(test_wolfSSL_EVP_CIPHER_CTX_key_length),
  87855. TEST_DECL(test_wolfSSL_EVP_CIPHER_CTX_set_iv),
  87856. TEST_DECL(test_wolfSSL_EVP_CIPHER_block_size),
  87857. TEST_DECL(test_wolfSSL_EVP_CIPHER_iv_length),
  87858. TEST_DECL(test_wolfSSL_EVP_X_STATE),
  87859. TEST_DECL(test_wolfSSL_EVP_X_STATE_LEN),
  87860. TEST_DECL(test_wolfSSL_EVP_BytesToKey),
  87861. #endif
  87862. TEST_DECL(test_wolfSSL_EVP_PKEY_print_public),
  87863. TEST_DECL(test_wolfSSL_EVP_PKEY_new_mac_key),
  87864. TEST_DECL(test_wolfSSL_EVP_PKEY_new_CMAC_key),
  87865. TEST_DECL(test_wolfSSL_EVP_PKEY_up_ref),
  87866. TEST_DECL(test_wolfSSL_EVP_PKEY_hkdf),
  87867. TEST_DECL(test_wolfSSL_EVP_PKEY_derive),
  87868. TEST_DECL(test_wolfSSL_d2i_and_i2d_PublicKey),
  87869. TEST_DECL(test_wolfSSL_d2i_and_i2d_PublicKey_ecc),
  87870. #ifndef NO_BIO
  87871. TEST_DECL(test_wolfSSL_d2i_PUBKEY),
  87872. #endif
  87873. TEST_DECL(test_wolfSSL_d2i_and_i2d_DSAparams),
  87874. TEST_DECL(test_wolfSSL_i2d_PrivateKey),
  87875. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO)) && !defined(NO_RSA)
  87876. #ifndef NO_BIO
  87877. TEST_DECL(test_wolfSSL_d2i_PrivateKeys_bio),
  87878. #endif /* !NO_BIO */
  87879. #endif
  87880. #ifdef OPENSSL_ALL
  87881. TEST_DECL(test_wolfSSL_EVP_PKEY_set1_get1_DSA),
  87882. TEST_DECL(test_wolfSSL_EVP_PKEY_set1_get1_EC_KEY),
  87883. TEST_DECL(test_wolfSSL_EVP_PKEY_set1_get1_DH),
  87884. TEST_DECL(test_wolfSSL_EVP_PKEY_assign),
  87885. TEST_DECL(test_wolfSSL_EVP_PKEY_assign_DH),
  87886. TEST_DECL(test_wolfSSL_EVP_PKEY_base_id),
  87887. TEST_DECL(test_wolfSSL_EVP_PKEY_id),
  87888. TEST_DECL(test_wolfSSL_EVP_PKEY_paramgen),
  87889. TEST_DECL(test_wolfSSL_EVP_PKEY_keygen),
  87890. TEST_DECL(test_wolfSSL_EVP_PKEY_keygen_init),
  87891. TEST_DECL(test_wolfSSL_EVP_PKEY_missing_parameters),
  87892. TEST_DECL(test_wolfSSL_EVP_PKEY_copy_parameters),
  87893. TEST_DECL(test_wolfSSL_EVP_PKEY_CTX_set_rsa_keygen_bits),
  87894. TEST_DECL(test_wolfSSL_EVP_PKEY_CTX_new_id),
  87895. TEST_DECL(test_wolfSSL_EVP_PKEY_get0_EC_KEY),
  87896. #endif
  87897. TEST_DECL(test_EVP_PKEY_rsa),
  87898. TEST_DECL(test_EVP_PKEY_ec),
  87899. TEST_DECL(test_wolfSSL_EVP_PKEY_encrypt),
  87900. TEST_DECL(test_wolfSSL_EVP_PKEY_sign_verify_rsa),
  87901. TEST_DECL(test_wolfSSL_EVP_PKEY_sign_verify_dsa),
  87902. TEST_DECL(test_wolfSSL_EVP_PKEY_sign_verify_ec),
  87903. TEST_DECL(test_EVP_PKEY_cmp),
  87904. #ifdef OPENSSL_ALL
  87905. TEST_DECL(test_wolfSSL_EVP_SignInit_ex),
  87906. TEST_DECL(test_wolfSSL_EVP_PKEY_param_check),
  87907. TEST_DECL(test_wolfSSL_QT_EVP_PKEY_CTX_free),
  87908. #endif
  87909. TEST_DECL(test_wolfSSL_EVP_PBE_scrypt),
  87910. TEST_DECL(test_wolfSSL_CTX_add_extra_chain_cert),
  87911. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  87912. TEST_DECL(test_wolfSSL_ERR_peek_last_error_line),
  87913. #endif
  87914. #ifndef NO_BIO
  87915. TEST_DECL(test_wolfSSL_ERR_print_errors_cb),
  87916. TEST_DECL(test_wolfSSL_GetLoggingCb),
  87917. TEST_DECL(test_WOLFSSL_ERROR_MSG),
  87918. TEST_DECL(test_wc_ERR_remove_state),
  87919. TEST_DECL(test_wc_ERR_print_errors_fp),
  87920. #endif
  87921. TEST_DECL(test_wolfSSL_configure_args),
  87922. TEST_DECL(test_wolfSSL_sk_SSL_CIPHER),
  87923. TEST_DECL(test_wolfSSL_set1_curves_list),
  87924. TEST_DECL(test_wolfSSL_curves_mismatch),
  87925. TEST_DECL(test_wolfSSL_set1_sigalgs_list),
  87926. TEST_DECL(test_wolfSSL_OtherName),
  87927. TEST_DECL(test_wolfSSL_FPKI),
  87928. TEST_DECL(test_wolfSSL_URI),
  87929. TEST_DECL(test_wolfSSL_TBS),
  87930. TEST_DECL(test_wolfSSL_X509_STORE_CTX),
  87931. TEST_DECL(test_X509_STORE_untrusted),
  87932. TEST_DECL(test_wolfSSL_X509_STORE_CTX_trusted_stack_cleanup),
  87933. TEST_DECL(test_wolfSSL_X509_STORE_CTX_get0_current_issuer),
  87934. TEST_DECL(test_wolfSSL_X509_STORE_set_flags),
  87935. TEST_DECL(test_wolfSSL_X509_LOOKUP_load_file),
  87936. TEST_DECL(test_wolfSSL_X509_Name_canon),
  87937. TEST_DECL(test_wolfSSL_X509_LOOKUP_ctrl_file),
  87938. TEST_DECL(test_wolfSSL_X509_LOOKUP_ctrl_hash_dir),
  87939. TEST_DECL(test_wolfSSL_X509_NID),
  87940. TEST_DECL(test_wolfSSL_X509_STORE_CTX_set_time),
  87941. TEST_DECL(test_wolfSSL_get0_param),
  87942. TEST_DECL(test_wolfSSL_X509_VERIFY_PARAM_set1_host),
  87943. TEST_DECL(test_wolfSSL_set1_host),
  87944. TEST_DECL(test_wolfSSL_X509_VERIFY_PARAM_set1_ip),
  87945. TEST_DECL(test_wolfSSL_X509_STORE_CTX_get0_store),
  87946. TEST_DECL(test_wolfSSL_X509_STORE),
  87947. TEST_DECL(test_wolfSSL_X509_STORE_load_locations),
  87948. TEST_DECL(test_X509_STORE_get0_objects),
  87949. TEST_DECL(test_wolfSSL_X509_load_crl_file),
  87950. TEST_DECL(test_wolfSSL_X509_STORE_get1_certs),
  87951. TEST_DECL(test_wolfSSL_X509_STORE_set_get_crl),
  87952. TEST_DECL(test_wolfSSL_X509_NAME_ENTRY_get_object),
  87953. TEST_DECL(test_wolfSSL_X509_cmp_time),
  87954. TEST_DECL(test_wolfSSL_X509_time_adj),
  87955. /* X509 tests */
  87956. TEST_DECL(test_wolfSSL_X509_subject_name_hash),
  87957. TEST_DECL(test_wolfSSL_X509_issuer_name_hash),
  87958. TEST_DECL(test_wolfSSL_X509_check_host),
  87959. TEST_DECL(test_wolfSSL_X509_check_email),
  87960. TEST_DECL(test_wolfSSL_X509_check_private_key),
  87961. TEST_DECL(test_wolfSSL_X509),
  87962. TEST_DECL(test_wolfSSL_X509_VERIFY_PARAM),
  87963. TEST_DECL(test_wolfSSL_X509_sign),
  87964. TEST_DECL(test_wolfSSL_X509_sign2),
  87965. TEST_DECL(test_wolfSSL_X509_verify),
  87966. TEST_DECL(test_wolfSSL_X509_get0_tbs_sigalg),
  87967. TEST_DECL(test_wolfSSL_X509_ALGOR_get0),
  87968. TEST_DECL(test_wolfSSL_X509_get_X509_PUBKEY),
  87969. TEST_DECL(test_wolfSSL_X509_PUBKEY_RSA),
  87970. TEST_DECL(test_wolfSSL_X509_PUBKEY_EC),
  87971. TEST_DECL(test_wolfSSL_X509_PUBKEY_DSA),
  87972. TEST_DECL(test_wolfSSL_PEM_write_bio_X509),
  87973. TEST_DECL(test_wolfSSL_X509_NAME_get_entry),
  87974. TEST_DECL(test_wolfSSL_X509_NAME),
  87975. TEST_DECL(test_wolfSSL_X509_NAME_hash),
  87976. TEST_DECL(test_wolfSSL_X509_NAME_print_ex),
  87977. TEST_DECL(test_wolfSSL_X509_NAME_ENTRY),
  87978. TEST_DECL(test_wolfSSL_X509_set_name),
  87979. TEST_DECL(test_wolfSSL_X509_set_notAfter),
  87980. TEST_DECL(test_wolfSSL_X509_set_notBefore),
  87981. TEST_DECL(test_wolfSSL_X509_set_version),
  87982. TEST_DECL(test_wolfSSL_X509_get_serialNumber),
  87983. TEST_DECL(test_wolfSSL_X509_CRL),
  87984. TEST_DECL(test_wolfSSL_i2d_X509),
  87985. TEST_DECL(test_wolfSSL_d2i_X509_REQ),
  87986. TEST_DECL(test_wolfSSL_PEM_read_X509),
  87987. TEST_DECL(test_wolfSSL_X509_check_ca),
  87988. TEST_DECL(test_wolfSSL_X509_check_ip_asc),
  87989. TEST_DECL(test_wolfSSL_X509_bad_altname),
  87990. TEST_DECL(test_wolfSSL_X509_name_match),
  87991. TEST_DECL(test_wolfSSL_X509_name_match2),
  87992. TEST_DECL(test_wolfSSL_X509_name_match3),
  87993. TEST_DECL(test_wolfSSL_X509_max_altnames),
  87994. TEST_DECL(test_wolfSSL_X509_max_name_constraints),
  87995. TEST_DECL(test_wolfSSL_make_cert),
  87996. /* X509 ACERT tests */
  87997. TEST_DECL(test_wolfSSL_X509_ACERT_verify),
  87998. TEST_DECL(test_wolfSSL_X509_ACERT_misc_api),
  87999. TEST_DECL(test_wolfSSL_X509_ACERT_buffer),
  88000. TEST_DECL(test_wolfSSL_X509_ACERT_asn),
  88001. #ifndef NO_BIO
  88002. TEST_DECL(test_wolfSSL_X509_INFO_multiple_info),
  88003. TEST_DECL(test_wolfSSL_X509_INFO),
  88004. TEST_DECL(test_wolfSSL_PEM_X509_INFO_read_bio),
  88005. #endif
  88006. #ifdef OPENSSL_ALL
  88007. TEST_DECL(test_wolfSSL_X509_PUBKEY_get),
  88008. #endif
  88009. TEST_DECL(test_wolfSSL_X509_CA_num),
  88010. TEST_DECL(test_x509_get_key_id),
  88011. TEST_DECL(test_wolfSSL_X509_get_version),
  88012. #ifndef NO_BIO
  88013. TEST_DECL(test_wolfSSL_X509_print),
  88014. TEST_DECL(test_wolfSSL_X509_CRL_print),
  88015. #endif
  88016. TEST_DECL(test_X509_get_signature_nid),
  88017. /* X509 extension testing. */
  88018. TEST_DECL(test_wolfSSL_X509_get_extension_flags),
  88019. TEST_DECL(test_wolfSSL_X509_get_ext),
  88020. TEST_DECL(test_wolfSSL_X509_get_ext_by_NID),
  88021. TEST_DECL(test_wolfSSL_X509_get_ext_subj_alt_name),
  88022. TEST_DECL(test_wolfSSL_X509_get_ext_count),
  88023. TEST_DECL(test_wolfSSL_X509_EXTENSION_new),
  88024. TEST_DECL(test_wolfSSL_X509_EXTENSION_get_object),
  88025. TEST_DECL(test_wolfSSL_X509_EXTENSION_get_data),
  88026. TEST_DECL(test_wolfSSL_X509_EXTENSION_get_critical),
  88027. TEST_DECL(test_wolfSSL_X509V3_EXT_get),
  88028. TEST_DECL(test_wolfSSL_X509V3_EXT_nconf),
  88029. TEST_DECL(test_wolfSSL_X509V3_EXT),
  88030. TEST_DECL(test_wolfSSL_X509V3_EXT_print),
  88031. TEST_DECL(test_wolfSSL_X509_cmp),
  88032. TEST_DECL(test_GENERAL_NAME_set0_othername),
  88033. TEST_DECL(test_othername_and_SID_ext),
  88034. TEST_DECL(test_wolfSSL_dup_CA_list),
  88035. /* OpenSSL sk_X509 API test */
  88036. TEST_DECL(test_sk_X509),
  88037. /* OpenSSL sk_X509_CRL API test */
  88038. TEST_DECL(test_sk_X509_CRL),
  88039. /* OpenSSL X509 REQ API test */
  88040. TEST_DECL(test_X509_REQ),
  88041. /* OpenSSL compatibility outside SSL context w/ CRL lookup directory */
  88042. TEST_DECL(test_X509_STORE_No_SSL_CTX),
  88043. TEST_DECL(test_X509_LOOKUP_add_dir),
  88044. /* RAND compatibility API */
  88045. TEST_DECL(test_wolfSSL_RAND_set_rand_method),
  88046. TEST_DECL(test_wolfSSL_RAND_bytes),
  88047. TEST_DECL(test_wolfSSL_RAND),
  88048. /* BN compatibility API */
  88049. TEST_DECL(test_wolfSSL_BN_CTX),
  88050. TEST_DECL(test_wolfSSL_BN),
  88051. TEST_DECL(test_wolfSSL_BN_init),
  88052. TEST_DECL(test_wolfSSL_BN_enc_dec),
  88053. TEST_DECL(test_wolfSSL_BN_word),
  88054. TEST_DECL(test_wolfSSL_BN_bits),
  88055. TEST_DECL(test_wolfSSL_BN_shift),
  88056. TEST_DECL(test_wolfSSL_BN_math),
  88057. TEST_DECL(test_wolfSSL_BN_math_mod),
  88058. TEST_DECL(test_wolfSSL_BN_math_other),
  88059. TEST_DECL(test_wolfSSL_BN_rand),
  88060. TEST_DECL(test_wolfSSL_BN_prime),
  88061. /* OpenSSL PKCS5 API test */
  88062. TEST_DECL(test_wolfSSL_PKCS5),
  88063. /* OpenSSL PKCS8 API test */
  88064. TEST_DECL(test_wolfSSL_PKCS8_Compat),
  88065. TEST_DECL(test_wolfSSL_PKCS8_d2i),
  88066. /* OpenSSL PKCS7 API test */
  88067. TEST_DECL(test_wolfssl_PKCS7),
  88068. TEST_DECL(test_wolfSSL_PKCS7_certs),
  88069. TEST_DECL(test_wolfSSL_PKCS7_sign),
  88070. TEST_DECL(test_wolfSSL_PKCS7_SIGNED_new),
  88071. #ifndef NO_BIO
  88072. TEST_DECL(test_wolfSSL_PEM_write_bio_PKCS7),
  88073. #ifdef HAVE_SMIME
  88074. TEST_DECL(test_wolfSSL_SMIME_read_PKCS7),
  88075. TEST_DECL(test_wolfSSL_SMIME_write_PKCS7),
  88076. #endif /* HAVE_SMIME */
  88077. #endif /* !NO_BIO */
  88078. /* OpenSSL PKCS12 API test */
  88079. TEST_DECL(test_wolfSSL_PKCS12),
  88080. /* Can't memory test as callbacks use Assert. */
  88081. TEST_DECL(test_error_queue_per_thread),
  88082. TEST_DECL(test_wolfSSL_ERR_put_error),
  88083. TEST_DECL(test_wolfSSL_ERR_get_error_order),
  88084. #ifndef NO_BIO
  88085. TEST_DECL(test_wolfSSL_ERR_print_errors),
  88086. #endif
  88087. TEST_DECL(test_OBJ_NAME_do_all),
  88088. TEST_DECL(test_wolfSSL_OBJ),
  88089. TEST_DECL(test_wolfSSL_OBJ_cmp),
  88090. TEST_DECL(test_wolfSSL_OBJ_txt2nid),
  88091. TEST_DECL(test_wolfSSL_OBJ_txt2obj),
  88092. #ifdef OPENSSL_ALL
  88093. TEST_DECL(test_wolfSSL_OBJ_ln),
  88094. TEST_DECL(test_wolfSSL_OBJ_sn),
  88095. #endif
  88096. #ifndef NO_BIO
  88097. TEST_DECL(test_wolfSSL_BIO_gets),
  88098. TEST_DECL(test_wolfSSL_BIO_puts),
  88099. TEST_DECL(test_wolfSSL_BIO_dump),
  88100. /* Can't memory test as server hangs. */
  88101. TEST_DECL(test_wolfSSL_BIO_should_retry),
  88102. TEST_DECL(test_wolfSSL_BIO_write),
  88103. TEST_DECL(test_wolfSSL_BIO_printf),
  88104. TEST_DECL(test_wolfSSL_BIO_f_md),
  88105. TEST_DECL(test_wolfSSL_BIO_up_ref),
  88106. TEST_DECL(test_wolfSSL_BIO_reset),
  88107. TEST_DECL(test_wolfSSL_BIO_get_len),
  88108. #endif
  88109. TEST_DECL(test_wolfSSL_check_domain),
  88110. TEST_DECL(test_wolfSSL_cert_cb),
  88111. TEST_DECL(test_wolfSSL_cert_cb_dyn_ciphers),
  88112. TEST_DECL(test_wolfSSL_ciphersuite_auth),
  88113. TEST_DECL(test_wolfSSL_sigalg_info),
  88114. /* Can't memory test as tcp_connect aborts. */
  88115. TEST_DECL(test_wolfSSL_SESSION),
  88116. TEST_DECL(test_wolfSSL_SESSION_expire_downgrade),
  88117. TEST_DECL(test_wolfSSL_CTX_sess_set_remove_cb),
  88118. TEST_DECL(test_wolfSSL_ticket_keys),
  88119. TEST_DECL(test_wolfSSL_sk_GENERAL_NAME),
  88120. TEST_DECL(test_wolfSSL_GENERAL_NAME_print),
  88121. TEST_DECL(test_wolfSSL_sk_DIST_POINT),
  88122. TEST_DECL(test_wolfSSL_verify_mode),
  88123. TEST_DECL(test_wolfSSL_verify_depth),
  88124. TEST_DECL(test_wolfSSL_verify_result),
  88125. TEST_DECL(test_wolfSSL_msg_callback),
  88126. TEST_DECL(test_wolfSSL_OCSP_id_get0_info),
  88127. TEST_DECL(test_wolfSSL_i2d_OCSP_CERTID),
  88128. TEST_DECL(test_wolfSSL_d2i_OCSP_CERTID),
  88129. TEST_DECL(test_wolfSSL_OCSP_id_cmp),
  88130. TEST_DECL(test_wolfSSL_OCSP_SINGLERESP_get0_id),
  88131. TEST_DECL(test_wolfSSL_OCSP_single_get0_status),
  88132. TEST_DECL(test_wolfSSL_OCSP_resp_count),
  88133. TEST_DECL(test_wolfSSL_OCSP_resp_get0),
  88134. TEST_DECL(test_wolfSSL_OCSP_parse_url),
  88135. TEST_DECL(test_wolfSSL_OCSP_REQ_CTX),
  88136. TEST_DECL(test_wolfSSL_PEM_read),
  88137. TEST_DECL(test_wolfSSL_OpenSSL_version),
  88138. TEST_DECL(test_wolfSSL_OpenSSL_add_all_algorithms),
  88139. TEST_DECL(test_wolfSSL_OPENSSL_hexstr2buf),
  88140. TEST_DECL(test_CONF_modules_xxx),
  88141. #ifdef OPENSSL_ALL
  88142. TEST_DECL(test_wolfSSL_TXT_DB),
  88143. TEST_DECL(test_wolfSSL_NCONF),
  88144. #endif
  88145. TEST_DECL(test_wolfSSL_CRYPTO_memcmp),
  88146. TEST_DECL(test_wolfSSL_CRYPTO_get_ex_new_index),
  88147. TEST_DECL(test_wolfSSL_SESSION_get_ex_new_index),
  88148. TEST_DECL(test_CRYPTO_set_dynlock_xxx),
  88149. TEST_DECL(test_CRYPTO_THREADID_xxx),
  88150. TEST_DECL(test_ENGINE_cleanup),
  88151. /* test the no op functions for compatibility */
  88152. TEST_DECL(test_no_op_functions),
  88153. /* OpenSSL error API tests */
  88154. TEST_DECL(test_ERR_load_crypto_strings),
  88155. #ifdef OPENSSL_ALL
  88156. TEST_DECL(test_wolfSSL_sk_CIPHER_description),
  88157. TEST_DECL(test_wolfSSL_get_ciphers_compat),
  88158. TEST_DECL(test_wolfSSL_CTX_ctrl),
  88159. #endif /* OPENSSL_ALL */
  88160. #if (defined(OPENSSL_ALL) || defined(WOLFSSL_ASIO)) && !defined(NO_RSA)
  88161. TEST_DECL(test_wolfSSL_CTX_use_certificate_ASN1),
  88162. #endif /* (OPENSSL_ALL || WOLFSSL_ASIO) && !NO_RSA */
  88163. /*********************************
  88164. * Crypto API tests
  88165. *********************************/
  88166. TEST_DECL(test_wolfSSL_MD4),
  88167. TEST_DECL(test_wolfSSL_MD5),
  88168. TEST_DECL(test_wolfSSL_MD5_Transform),
  88169. TEST_DECL(test_wolfSSL_SHA),
  88170. TEST_DECL(test_wolfSSL_SHA_Transform),
  88171. TEST_DECL(test_wolfSSL_SHA224),
  88172. TEST_DECL(test_wolfSSL_SHA256),
  88173. TEST_DECL(test_wolfSSL_SHA256_Transform),
  88174. TEST_DECL(test_wolfSSL_SHA512_Transform),
  88175. TEST_DECL(test_wolfSSL_SHA512_224_Transform),
  88176. TEST_DECL(test_wolfSSL_SHA512_256_Transform),
  88177. TEST_DECL(test_wolfSSL_HMAC_CTX),
  88178. TEST_DECL(test_wolfSSL_HMAC),
  88179. TEST_DECL(test_wolfSSL_CMAC),
  88180. TEST_DECL(test_wolfSSL_DES),
  88181. TEST_DECL(test_wolfSSL_DES_ncbc),
  88182. TEST_DECL(test_wolfSSL_DES_ecb_encrypt),
  88183. TEST_DECL(test_wolfSSL_DES_ede3_cbc_encrypt),
  88184. TEST_DECL(test_wolfSSL_AES_encrypt),
  88185. TEST_DECL(test_wolfSSL_AES_ecb_encrypt),
  88186. TEST_DECL(test_wolfSSL_AES_cbc_encrypt),
  88187. TEST_DECL(test_wolfSSL_AES_cfb128_encrypt),
  88188. TEST_DECL(test_wolfSSL_CRYPTO_cts128),
  88189. TEST_DECL(test_wolfSSL_RC4),
  88190. TEST_DECL(test_wolfSSL_RSA),
  88191. TEST_DECL(test_wolfSSL_RSA_DER),
  88192. TEST_DECL(test_wolfSSL_RSA_print),
  88193. TEST_DECL(test_wolfSSL_RSA_padding_add_PKCS1_PSS),
  88194. TEST_DECL(test_wolfSSL_RSA_sign_sha3),
  88195. TEST_DECL(test_wolfSSL_RSA_get0_key),
  88196. TEST_DECL(test_wolfSSL_RSA_meth),
  88197. TEST_DECL(test_wolfSSL_RSA_verify),
  88198. TEST_DECL(test_wolfSSL_RSA_sign),
  88199. TEST_DECL(test_wolfSSL_RSA_sign_ex),
  88200. TEST_DECL(test_wolfSSL_RSA_public_decrypt),
  88201. TEST_DECL(test_wolfSSL_RSA_private_encrypt),
  88202. TEST_DECL(test_wolfSSL_RSA_public_encrypt),
  88203. TEST_DECL(test_wolfSSL_RSA_private_decrypt),
  88204. TEST_DECL(test_wolfSSL_RSA_GenAdd),
  88205. TEST_DECL(test_wolfSSL_RSA_blinding_on),
  88206. TEST_DECL(test_wolfSSL_RSA_ex_data),
  88207. TEST_DECL(test_wolfSSL_RSA_LoadDer),
  88208. TEST_DECL(test_wolfSSL_RSA_To_Der),
  88209. TEST_DECL(test_wolfSSL_PEM_read_RSAPublicKey),
  88210. TEST_DECL(test_wolfSSL_PEM_write_RSA_PUBKEY),
  88211. TEST_DECL(test_wolfSSL_PEM_write_RSAPrivateKey),
  88212. TEST_DECL(test_wolfSSL_PEM_write_mem_RSAPrivateKey),
  88213. TEST_DECL(test_wolfSSL_DH),
  88214. TEST_DECL(test_wolfSSL_DH_dup),
  88215. TEST_DECL(test_wolfSSL_DH_check),
  88216. TEST_DECL(test_wolfSSL_DH_prime),
  88217. TEST_DECL(test_wolfSSL_DH_1536_prime),
  88218. TEST_DECL(test_wolfSSL_DH_get_2048_256),
  88219. TEST_DECL(test_wolfSSL_PEM_write_DHparams),
  88220. TEST_DECL(test_wolfSSL_PEM_read_DHparams),
  88221. TEST_DECL(test_wolfSSL_d2i_DHparams),
  88222. TEST_DECL(test_wolfSSL_DH_LoadDer),
  88223. TEST_DECL(test_wolfSSL_i2d_DHparams),
  88224. #if defined(HAVE_ECC) && !defined(OPENSSL_NO_PK)
  88225. TEST_DECL(test_wolfSSL_EC_GROUP),
  88226. TEST_DECL(test_wolfSSL_PEM_read_bio_ECPKParameters),
  88227. TEST_DECL(test_wolfSSL_EC_POINT),
  88228. TEST_DECL(test_wolfSSL_SPAKE),
  88229. TEST_DECL(test_wolfSSL_EC_KEY_generate),
  88230. TEST_DECL(test_EC_i2d),
  88231. TEST_DECL(test_wolfSSL_EC_curve),
  88232. TEST_DECL(test_wolfSSL_EC_KEY_dup),
  88233. TEST_DECL(test_wolfSSL_EC_KEY_set_group),
  88234. TEST_DECL(test_wolfSSL_EC_KEY_set_conv_form),
  88235. TEST_DECL(test_wolfSSL_EC_KEY_private_key),
  88236. TEST_DECL(test_wolfSSL_EC_KEY_public_key),
  88237. TEST_DECL(test_wolfSSL_EC_KEY_print_fp),
  88238. TEST_DECL(test_wolfSSL_EC_get_builtin_curves),
  88239. TEST_DECL(test_wolfSSL_ECDSA_SIG),
  88240. TEST_DECL(test_ECDSA_size_sign),
  88241. TEST_DECL(test_ECDH_compute_key),
  88242. #endif
  88243. #ifdef OPENSSL_EXTRA
  88244. TEST_DECL(test_EC25519),
  88245. TEST_DECL(test_ED25519),
  88246. TEST_DECL(test_EC448),
  88247. TEST_DECL(test_ED448),
  88248. #endif
  88249. TEST_DECL(test_DSA_do_sign_verify),
  88250. #ifdef OPENSSL_ALL
  88251. TEST_DECL(test_wolfSSL_DSA_generate_parameters),
  88252. TEST_DECL(test_wolfSSL_DSA_SIG),
  88253. #endif
  88254. TEST_DECL(test_openssl_generate_key_and_cert),
  88255. TEST_DECL(test_wolfSSL_FIPS_mode),
  88256. TEST_DECL(test_openssl_FIPS_drbg),
  88257. /*********************************
  88258. * CertManager API tests
  88259. *********************************/
  88260. TEST_DECL(test_wolfSSL_CertManagerAPI),
  88261. TEST_DECL(test_wolfSSL_CertManagerLoadCABuffer),
  88262. TEST_DECL(test_wolfSSL_CertManagerLoadCABuffer_ex),
  88263. TEST_DECL(test_wolfSSL_CertManagerGetCerts),
  88264. TEST_DECL(test_wolfSSL_CertManagerSetVerify),
  88265. TEST_DECL(test_wolfSSL_CertManagerNameConstraint),
  88266. TEST_DECL(test_wolfSSL_CertManagerNameConstraint2),
  88267. TEST_DECL(test_wolfSSL_CertManagerNameConstraint3),
  88268. TEST_DECL(test_wolfSSL_CertManagerNameConstraint4),
  88269. TEST_DECL(test_wolfSSL_CertManagerNameConstraint5),
  88270. TEST_DECL(test_wolfSSL_CertManagerCRL),
  88271. TEST_DECL(test_wolfSSL_CertManagerCheckOCSPResponse),
  88272. TEST_DECL(test_wolfSSL_CheckOCSPResponse),
  88273. #ifdef HAVE_CERT_CHAIN_VALIDATION
  88274. TEST_DECL(test_various_pathlen_chains),
  88275. #endif
  88276. /*********************************
  88277. * SSL/TLS API tests
  88278. *********************************/
  88279. TEST_DECL(test_wolfSSL_Method_Allocators),
  88280. #ifndef NO_WOLFSSL_SERVER
  88281. TEST_DECL(test_wolfSSL_CTX_new),
  88282. #endif
  88283. TEST_DECL(test_server_wolfSSL_new),
  88284. TEST_DECL(test_client_wolfSSL_new),
  88285. #if (!defined(NO_WOLFSSL_CLIENT) || !defined(NO_WOLFSSL_SERVER)) && \
  88286. (!defined(NO_RSA) || defined(HAVE_ECC)) && !defined(NO_FILESYSTEM)
  88287. TEST_DECL(test_for_double_Free),
  88288. #endif
  88289. TEST_DECL(test_wolfSSL_set_options),
  88290. #ifdef WOLFSSL_TLS13
  88291. /* TLS v1.3 API tests */
  88292. TEST_DECL(test_tls13_apis),
  88293. TEST_DECL(test_tls13_cipher_suites),
  88294. #endif
  88295. TEST_DECL(test_wolfSSL_tmp_dh),
  88296. TEST_DECL(test_wolfSSL_ctrl),
  88297. #if defined(OPENSSL_ALL) || (defined(OPENSSL_EXTRA) && \
  88298. (defined(HAVE_STUNNEL) || defined(WOLFSSL_NGINX) || \
  88299. defined(HAVE_LIGHTY) || defined(WOLFSSL_HAPROXY) || \
  88300. defined(WOLFSSL_OPENSSH) || defined(HAVE_SBLIM_SFCB)))
  88301. TEST_DECL(test_wolfSSL_set_SSL_CTX),
  88302. #endif
  88303. TEST_DECL(test_wolfSSL_CTX_get_min_proto_version),
  88304. TEST_DECL(test_wolfSSL_security_level),
  88305. TEST_DECL(test_wolfSSL_SSL_in_init),
  88306. TEST_DECL(test_wolfSSL_CTX_set_timeout),
  88307. TEST_DECL(test_wolfSSL_set_psk_use_session_callback),
  88308. TEST_DECL(test_CONF_CTX_FILE),
  88309. TEST_DECL(test_CONF_CTX_CMDLINE),
  88310. #if !defined(NO_CERTS) && (!defined(NO_WOLFSSL_CLIENT) || \
  88311. !defined(WOLFSSL_NO_CLIENT_AUTH)) && !defined(NO_FILESYSTEM)
  88312. /* Use the Cert Manager(CM) API to generate the error ASN_SIG_CONFIRM_E */
  88313. /* Bad certificate signature tests */
  88314. TEST_DECL(test_EccSigFailure_cm),
  88315. TEST_DECL(test_RsaSigFailure_cm),
  88316. #endif /* NO_CERTS */
  88317. /* PKCS8 testing */
  88318. TEST_DECL(test_wolfSSL_no_password_cb),
  88319. TEST_DECL(test_wolfSSL_PKCS8),
  88320. TEST_DECL(test_wolfSSL_PKCS8_ED25519),
  88321. TEST_DECL(test_wolfSSL_PKCS8_ED448),
  88322. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  88323. TEST_DECL(test_wolfSSL_get_finished),
  88324. /* Uses Assert in handshake callback. */
  88325. TEST_DECL(test_wolfSSL_CTX_add_session),
  88326. /* Large number of memory allocations. */
  88327. TEST_DECL(test_wolfSSL_CTX_add_session_ext_tls13),
  88328. /* Large number of memory allocations. */
  88329. TEST_DECL(test_wolfSSL_CTX_add_session_ext_dtls13),
  88330. /* Large number of memory allocations. */
  88331. TEST_DECL(test_wolfSSL_CTX_add_session_ext_tls12),
  88332. /* Large number of memory allocations. */
  88333. TEST_DECL(test_wolfSSL_CTX_add_session_ext_dtls12),
  88334. /* Large number of memory allocations. */
  88335. TEST_DECL(test_wolfSSL_CTX_add_session_ext_tls11),
  88336. /* Large number of memory allocations. */
  88337. TEST_DECL(test_wolfSSL_CTX_add_session_ext_dtls1),
  88338. #endif
  88339. TEST_DECL(test_SSL_CIPHER_get_xxx),
  88340. TEST_DECL(test_wolfSSL_ERR_strings),
  88341. TEST_DECL(test_wolfSSL_CTX_set_cipher_list_bytes),
  88342. TEST_DECL(test_wolfSSL_CTX_use_certificate),
  88343. TEST_DECL(test_wolfSSL_CTX_use_certificate_file),
  88344. TEST_DECL(test_wolfSSL_CTX_use_certificate_buffer),
  88345. TEST_DECL(test_wolfSSL_use_certificate_buffer),
  88346. TEST_DECL(test_wolfSSL_CTX_use_PrivateKey_file),
  88347. TEST_DECL(test_wolfSSL_CTX_use_RSAPrivateKey_file),
  88348. TEST_DECL(test_wolfSSL_use_RSAPrivateKey_file),
  88349. TEST_DECL(test_wolfSSL_CTX_use_PrivateKey),
  88350. TEST_DECL(test_wolfSSL_CTX_load_verify_locations),
  88351. /* Large number of memory allocations. */
  88352. TEST_DECL(test_wolfSSL_CTX_load_system_CA_certs),
  88353. #ifdef HAVE_CERT_CHAIN_VALIDATION
  88354. TEST_DECL(test_wolfSSL_CertRsaPss),
  88355. #endif
  88356. TEST_DECL(test_wolfSSL_CTX_load_verify_locations_ex),
  88357. TEST_DECL(test_wolfSSL_CTX_load_verify_buffer_ex),
  88358. TEST_DECL(test_wolfSSL_CTX_load_verify_chain_buffer_format),
  88359. TEST_DECL(test_wolfSSL_CTX_add1_chain_cert),
  88360. TEST_DECL(test_wolfSSL_CTX_use_certificate_chain_buffer_format),
  88361. TEST_DECL(test_wolfSSL_CTX_use_certificate_chain_file_format),
  88362. TEST_DECL(test_wolfSSL_use_certificate_chain_file),
  88363. TEST_DECL(test_wolfSSL_CTX_trust_peer_cert),
  88364. TEST_DECL(test_wolfSSL_CTX_LoadCRL),
  88365. TEST_DECL(test_multiple_crls_same_issuer),
  88366. TEST_DECL(test_wolfSSL_CTX_SetTmpDH_file),
  88367. TEST_DECL(test_wolfSSL_CTX_SetTmpDH_buffer),
  88368. TEST_DECL(test_wolfSSL_CTX_SetMinMaxDhKey_Sz),
  88369. TEST_DECL(test_wolfSSL_CTX_der_load_verify_locations),
  88370. TEST_DECL(test_wolfSSL_CTX_enable_disable),
  88371. TEST_DECL(test_wolfSSL_CTX_ticket_API),
  88372. TEST_DECL(test_wolfSSL_SetTmpDH_file),
  88373. TEST_DECL(test_wolfSSL_SetTmpDH_buffer),
  88374. TEST_DECL(test_wolfSSL_SetMinMaxDhKey_Sz),
  88375. TEST_DECL(test_SetTmpEC_DHE_Sz),
  88376. TEST_DECL(test_wolfSSL_CTX_get0_privatekey),
  88377. #ifdef WOLFSSL_DTLS
  88378. TEST_DECL(test_wolfSSL_DtlsUpdateWindow),
  88379. TEST_DECL(test_wolfSSL_DTLS_fragment_buckets),
  88380. #endif
  88381. TEST_DECL(test_wolfSSL_dtls_set_mtu),
  88382. /* Uses Assert in handshake callback. */
  88383. TEST_DECL(test_wolfSSL_dtls_plaintext),
  88384. #if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
  88385. defined(HAVE_IO_TESTS_DEPENDENCIES)
  88386. TEST_DECL(test_wolfSSL_read_write),
  88387. /* Can't memory test as server hangs if client fails before second connect.
  88388. */
  88389. TEST_DECL(test_wolfSSL_reuse_WOLFSSLobj),
  88390. TEST_DECL(test_wolfSSL_CTX_verifyDepth_ServerClient_1),
  88391. TEST_DECL(test_wolfSSL_CTX_verifyDepth_ServerClient_2),
  88392. TEST_DECL(test_wolfSSL_CTX_verifyDepth_ServerClient_3),
  88393. TEST_DECL(test_wolfSSL_CTX_set_cipher_list),
  88394. /* Can't memory test as server hangs. */
  88395. TEST_DECL(test_wolfSSL_dtls_export),
  88396. /* Uses Assert in handshake callback. */
  88397. TEST_DECL(test_wolfSSL_tls_export),
  88398. #endif
  88399. TEST_DECL(test_wolfSSL_dtls_export_peers),
  88400. TEST_DECL(test_wolfSSL_SetMinVersion),
  88401. TEST_DECL(test_wolfSSL_CTX_SetMinVersion),
  88402. /* wolfSSL handshake APIs. */
  88403. TEST_DECL(test_wolfSSL_CTX_get0_set1_param),
  88404. TEST_DECL(test_wolfSSL_a2i_IPADDRESS),
  88405. TEST_DECL(test_wolfSSL_BUF),
  88406. TEST_DECL(test_wolfSSL_set_tlsext_status_type),
  88407. /* Can't memory test as server hangs. */
  88408. TEST_DECL(test_wolfSSL_CTX_set_client_CA_list),
  88409. TEST_DECL(test_wolfSSL_CTX_add_client_CA),
  88410. TEST_DECL(test_wolfSSL_CTX_set_srp_username),
  88411. TEST_DECL(test_wolfSSL_CTX_set_srp_password),
  88412. TEST_DECL(test_wolfSSL_CTX_set_keylog_callback),
  88413. TEST_DECL(test_wolfSSL_CTX_get_keylog_callback),
  88414. TEST_DECL(test_wolfSSL_Tls12_Key_Logging_test),
  88415. /* Can't memory test as server hangs. */
  88416. TEST_DECL(test_wolfSSL_Tls13_Key_Logging_test),
  88417. TEST_DECL(test_wolfSSL_Tls13_postauth),
  88418. TEST_DECL(test_wolfSSL_set_ecdh_auto),
  88419. TEST_DECL(test_wolfSSL_CTX_set_ecdh_auto),
  88420. TEST_DECL(test_wolfSSL_set_minmax_proto_version),
  88421. TEST_DECL(test_wolfSSL_CTX_set_max_proto_version),
  88422. TEST_DECL(test_wolfSSL_THREADID_hash),
  88423. /* TLS extensions tests */
  88424. #ifdef HAVE_IO_TESTS_DEPENDENCIES
  88425. #ifdef HAVE_SNI
  88426. TEST_DECL(test_wolfSSL_UseSNI_params),
  88427. /* Uses Assert in handshake callback. */
  88428. TEST_DECL(test_wolfSSL_UseSNI_connection),
  88429. TEST_DECL(test_wolfSSL_SNI_GetFromBuffer),
  88430. #endif /* HAVE_SNI */
  88431. #endif
  88432. TEST_DECL(test_wolfSSL_UseTrustedCA),
  88433. TEST_DECL(test_wolfSSL_UseMaxFragment),
  88434. TEST_DECL(test_wolfSSL_UseTruncatedHMAC),
  88435. TEST_DECL(test_wolfSSL_UseSupportedCurve),
  88436. #if defined(HAVE_ALPN) && defined(HAVE_IO_TESTS_DEPENDENCIES)
  88437. /* Uses Assert in handshake callback. */
  88438. TEST_DECL(test_wolfSSL_UseALPN_connection),
  88439. TEST_DECL(test_wolfSSL_UseALPN_params),
  88440. #endif
  88441. #ifdef HAVE_ALPN_PROTOS_SUPPORT
  88442. /* Uses Assert in handshake callback. */
  88443. TEST_DECL(test_wolfSSL_set_alpn_protos),
  88444. #endif
  88445. TEST_DECL(test_wolfSSL_DisableExtendedMasterSecret),
  88446. TEST_DECL(test_wolfSSL_wolfSSL_UseSecureRenegotiation),
  88447. TEST_DECL(test_wolfSSL_SCR_Reconnect),
  88448. TEST_DECL(test_tls_ext_duplicate),
  88449. #if defined(WOLFSSL_TLS13) && defined(HAVE_ECH) && \
  88450. defined(HAVE_IO_TESTS_DEPENDENCIES)
  88451. TEST_DECL(test_wolfSSL_Tls13_ECH_params),
  88452. /* Uses Assert in handshake callback. */
  88453. TEST_DECL(test_wolfSSL_Tls13_ECH),
  88454. #endif
  88455. TEST_DECL(test_wolfSSL_X509_TLS_version_test_1),
  88456. TEST_DECL(test_wolfSSL_X509_TLS_version_test_2),
  88457. /* OCSP Stapling */
  88458. TEST_DECL(test_wolfSSL_UseOCSPStapling),
  88459. TEST_DECL(test_wolfSSL_UseOCSPStaplingV2),
  88460. TEST_DECL(test_self_signed_stapling),
  88461. TEST_DECL(test_ocsp_callback_fails),
  88462. /* Multicast */
  88463. TEST_DECL(test_wolfSSL_mcast),
  88464. TEST_DECL(test_wolfSSL_read_detect_TCP_disconnect),
  88465. TEST_DECL(test_wolfSSL_msgCb),
  88466. TEST_DECL(test_wolfSSL_either_side),
  88467. TEST_DECL(test_wolfSSL_DTLS_either_side),
  88468. /* Uses Assert in handshake callback. */
  88469. TEST_DECL(test_wolfSSL_dtls_fragments),
  88470. /* Uses Assert in handshake callback. */
  88471. TEST_DECL(test_wolfSSL_dtls_AEAD_limit),
  88472. /* Uses Assert in handshake callback. */
  88473. TEST_DECL(test_wolfSSL_ignore_alert_before_cookie),
  88474. /* Uses Assert in handshake callback. */
  88475. TEST_DECL(test_wolfSSL_dtls_bad_record),
  88476. /* Uses Assert in handshake callback. */
  88477. TEST_DECL(test_wolfSSL_dtls_stateless),
  88478. TEST_DECL(test_generate_cookie),
  88479. #ifndef NO_BIO
  88480. /* Can't memory test as server hangs. */
  88481. TEST_DECL(test_wolfSSL_BIO_connect),
  88482. /* Can't memory test as server Asserts in thread. */
  88483. TEST_DECL(test_wolfSSL_BIO_accept),
  88484. TEST_DECL(test_wolfSSL_BIO_tls),
  88485. TEST_DECL(test_wolfSSL_BIO_datagram),
  88486. #endif
  88487. #if defined(HAVE_PK_CALLBACKS) && !defined(WOLFSSL_NO_TLS12)
  88488. TEST_DECL(test_DhCallbacks),
  88489. #endif
  88490. #if defined(HAVE_KEYING_MATERIAL) && defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES)
  88491. TEST_DECL(test_export_keying_material),
  88492. #endif
  88493. /* Can't memory test as client/server Asserts in thread. */
  88494. TEST_DECL(test_ticket_and_psk_mixing),
  88495. /* Can't memory test as client/server Asserts in thread. */
  88496. TEST_DECL(test_prioritize_psk),
  88497. /* Can't memory test as client/server hangs. */
  88498. TEST_DECL(test_wc_CryptoCb),
  88499. /* Can't memory test as client/server hangs. */
  88500. TEST_DECL(test_wolfSSL_CTX_StaticMemory),
  88501. #if !defined(NO_FILESYSTEM) && \
  88502. defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  88503. !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
  88504. #ifdef WOLFSSL_DTLS_NO_HVR_ON_RESUME
  88505. TEST_DECL(test_wolfSSL_dtls_stateless_resume),
  88506. #endif /* WOLFSSL_DTLS_NO_HVR_ON_RESUME */
  88507. #ifdef HAVE_MAX_FRAGMENT
  88508. TEST_DECL(test_wolfSSL_dtls_stateless_maxfrag),
  88509. #endif /* HAVE_MAX_FRAGMENT */
  88510. #ifndef NO_RSA
  88511. TEST_DECL(test_wolfSSL_dtls_stateless2),
  88512. #if !defined(NO_OLD_TLS)
  88513. TEST_DECL(test_wolfSSL_dtls_stateless_downgrade),
  88514. #endif /* !defined(NO_OLD_TLS) */
  88515. #endif /* ! NO_RSA */
  88516. #endif /* defined(WOLFSSL_DTLS) && !defined(WOLFSSL_NO_TLS12) && \
  88517. * !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) */
  88518. TEST_DECL(test_wolfSSL_CTX_set_ciphersuites),
  88519. TEST_DECL(test_wolfSSL_CRL_CERT_REVOKED_alert),
  88520. TEST_DECL(test_TLS_13_ticket_different_ciphers),
  88521. TEST_DECL(test_WOLFSSL_dtls_version_alert),
  88522. #if defined(WOLFSSL_TICKET_NONCE_MALLOC) && defined(HAVE_SESSION_TICKET) \
  88523. && defined(WOLFSSL_TLS13) && \
  88524. (!defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))
  88525. TEST_DECL(test_ticket_nonce_malloc),
  88526. #endif
  88527. TEST_DECL(test_ticket_ret_create),
  88528. TEST_DECL(test_wrong_cs_downgrade),
  88529. TEST_DECL(test_extra_alerts_wrong_cs),
  88530. TEST_DECL(test_extra_alerts_skip_hs),
  88531. TEST_DECL(test_extra_alerts_bad_psk),
  88532. TEST_DECL(test_multiple_alerts_EAGAIN),
  88533. TEST_DECL(test_tls13_bad_psk_binder),
  88534. /* Can't memory test as client/server Asserts. */
  88535. TEST_DECL(test_harden_no_secure_renegotiation),
  88536. TEST_DECL(test_override_alt_cert_chain),
  88537. TEST_DECL(test_rpk_set_xxx_cert_type),
  88538. TEST_DECL(test_tls13_rpk_handshake),
  88539. TEST_DECL(test_dtls13_bad_epoch_ch),
  88540. TEST_DECL(test_short_session_id),
  88541. TEST_DECL(test_wolfSSL_dtls13_null_cipher),
  88542. /* Can't memory test as client/server hangs. */
  88543. TEST_DECL(test_dtls_msg_from_other_peer),
  88544. TEST_DECL(test_dtls_ipv6_check),
  88545. TEST_DECL(test_wolfSSL_SCR_after_resumption),
  88546. TEST_DECL(test_dtls_no_extensions),
  88547. TEST_DECL(test_tls_alert_no_server_hello),
  88548. TEST_DECL(test_TLSX_CA_NAMES_bad_extension),
  88549. TEST_DECL(test_dtls_1_0_hvr_downgrade),
  88550. TEST_DECL(test_session_ticket_no_id),
  88551. TEST_DECL(test_session_ticket_hs_update),
  88552. TEST_DECL(test_dtls_downgrade_scr_server),
  88553. TEST_DECL(test_dtls_downgrade_scr),
  88554. TEST_DECL(test_dtls_client_hello_timeout_downgrade),
  88555. TEST_DECL(test_dtls_client_hello_timeout),
  88556. TEST_DECL(test_dtls_dropped_ccs),
  88557. TEST_DECL(test_dtls_seq_num_downgrade),
  88558. TEST_DECL(test_certreq_sighash_algos),
  88559. TEST_DECL(test_revoked_loaded_int_cert),
  88560. TEST_DECL(test_dtls_frag_ch),
  88561. TEST_DECL(test_dtls13_frag_ch_pq),
  88562. TEST_DECL(test_dtls_empty_keyshare_with_cookie),
  88563. TEST_DECL(test_dtls_old_seq_number),
  88564. TEST_DECL(test_dtls12_basic_connection_id),
  88565. TEST_DECL(test_dtls13_basic_connection_id),
  88566. TEST_DECL(test_tls13_pq_groups),
  88567. TEST_DECL(test_tls13_early_data),
  88568. TEST_DECL(test_tls_multi_handshakes_one_record),
  88569. TEST_DECL(test_write_dup),
  88570. TEST_DECL(test_read_write_hs),
  88571. TEST_DECL(test_get_signature_nid),
  88572. TEST_DECL(test_tls_cert_store_unchanged),
  88573. TEST_DECL(test_wolfSSL_SendUserCanceled),
  88574. /* This test needs to stay at the end to clean up any caches allocated. */
  88575. TEST_DECL(test_wolfSSL_Cleanup)
  88576. };
  88577. #define TEST_CASE_CNT (int)(sizeof(testCases) / sizeof(*testCases))
  88578. static void TestSetup(void)
  88579. {
  88580. /* Stub, for now. Add common test setup code here. */
  88581. }
  88582. static void TestCleanup(void)
  88583. {
  88584. #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
  88585. /* Clear any errors added to the error queue during the test run. */
  88586. wolfSSL_ERR_clear_error();
  88587. #endif /* OPENSSL_EXTRA || DEBUG_WOLFSSL_VERBOSE */
  88588. }
  88589. /* Print out all API test cases with numeric identifier.
  88590. */
  88591. void ApiTest_PrintTestCases(void)
  88592. {
  88593. int i;
  88594. printf("All Test Cases:\n");
  88595. for (i = 0; i < TEST_CASE_CNT; i++) {
  88596. printf("%3d: %s\n", i + 1, testCases[i].name);
  88597. }
  88598. }
  88599. /* Add test case with index to the list to run.
  88600. *
  88601. * @param [in] idx Index of test case to run starting at 1.
  88602. * @return 0 on success.
  88603. * @return BAD_FUNC_ARG when index is out of range of test case identifiers.
  88604. */
  88605. int ApiTest_RunIdx(int idx)
  88606. {
  88607. if (idx < 1 || idx > TEST_CASE_CNT) {
  88608. printf("Index out of range (1 - %d): %d\n", TEST_CASE_CNT, idx);
  88609. return BAD_FUNC_ARG;
  88610. }
  88611. testAll = 0;
  88612. testCases[idx-1].run = 1;
  88613. return 0;
  88614. }
  88615. /* Add test case with name to the list to run.
  88616. *
  88617. * @param [in] name Name of test case to run.
  88618. * @return 0 on success.
  88619. * @return BAD_FUNC_ARG when name is not a known test case name.
  88620. */
  88621. int ApiTest_RunName(char* name)
  88622. {
  88623. int i;
  88624. for (i = 0; i < TEST_CASE_CNT; i++) {
  88625. if (XSTRCMP(testCases[i].name, name) == 0) {
  88626. testAll = 0;
  88627. testCases[i].run = 1;
  88628. return 0;
  88629. }
  88630. }
  88631. printf("Test case name not found: %s\n", name);
  88632. printf("Use --list to see all test case names.\n");
  88633. return BAD_FUNC_ARG;
  88634. }
  88635. /* Converts the result code to a string.
  88636. *
  88637. * @param [in] res Test result code.
  88638. * @return String describing test result.
  88639. */
  88640. static const char* apitest_res_string(int res)
  88641. {
  88642. const char* str = "invalid result";
  88643. switch (res) {
  88644. case TEST_SUCCESS:
  88645. str = "passed";
  88646. break;
  88647. case TEST_FAIL:
  88648. str = "failed";
  88649. break;
  88650. case TEST_SKIPPED:
  88651. str = "skipped";
  88652. break;
  88653. }
  88654. return str;
  88655. }
  88656. #ifndef WOLFSSL_UNIT_TEST_NO_TIMING
  88657. static double gettime_secs(void)
  88658. #if defined(_MSC_VER) && defined(_WIN32)
  88659. {
  88660. /* there's no gettimeofday for Windows, so we'll use system time */
  88661. #define EPOCH_DIFF 11644473600LL
  88662. FILETIME currentFileTime;
  88663. GetSystemTimePreciseAsFileTime(&currentFileTime);
  88664. ULARGE_INTEGER uli = { 0, 0 };
  88665. uli.LowPart = currentFileTime.dwLowDateTime;
  88666. uli.HighPart = currentFileTime.dwHighDateTime;
  88667. /* Convert to seconds since Unix epoch */
  88668. return (double)((uli.QuadPart - (EPOCH_DIFF * 10000000)) / 10000000.0);
  88669. }
  88670. #else
  88671. {
  88672. struct timeval tv;
  88673. LIBCALL_CHECK_RET(gettimeofday(&tv, 0));
  88674. return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
  88675. }
  88676. #endif
  88677. #endif
  88678. int ApiTest(void)
  88679. {
  88680. int i;
  88681. int ret;
  88682. int res = 0;
  88683. #ifndef WOLFSSL_UNIT_TEST_NO_TIMING
  88684. double timeDiff;
  88685. #endif
  88686. printf(" Begin API Tests\n");
  88687. fflush(stdout);
  88688. /* we must perform init and cleanup if not all tests are running */
  88689. if (!testAll) {
  88690. #ifdef WOLFCRYPT_ONLY
  88691. if (wolfCrypt_Init() != 0) {
  88692. printf("wolfCrypt Initialization failed\n");
  88693. res = 1;
  88694. }
  88695. #else
  88696. if (wolfSSL_Init() != WOLFSSL_SUCCESS) {
  88697. printf("wolfSSL Initialization failed\n");
  88698. res = 1;
  88699. }
  88700. #endif
  88701. }
  88702. #ifdef WOLFSSL_DUMP_MEMIO_STREAM
  88703. if (res == 0) {
  88704. if (create_tmp_dir(tmpDirName, sizeof(tmpDirName) - 1) == NULL) {
  88705. printf("failed to create tmp dir\n");
  88706. res = 1;
  88707. }
  88708. else {
  88709. tmpDirNameSet = 1;
  88710. }
  88711. }
  88712. #endif
  88713. if (res == 0) {
  88714. for (i = 0; i < TEST_CASE_CNT; ++i) {
  88715. EXPECT_DECLS;
  88716. #ifdef WOLFSSL_DUMP_MEMIO_STREAM
  88717. currentTestName = testCases[i].name;
  88718. #endif
  88719. /* When not testing all cases then skip if not marked for running.
  88720. */
  88721. if (!testAll && !testCases[i].run) {
  88722. continue;
  88723. }
  88724. TestSetup();
  88725. printf(" %3d: %-52s:", i + 1, testCases[i].name);
  88726. fflush(stdout);
  88727. #ifndef WOLFSSL_UNIT_TEST_NO_TIMING
  88728. timeDiff = gettime_secs();
  88729. #endif
  88730. ret = testCases[i].func();
  88731. #ifndef WOLFSSL_UNIT_TEST_NO_TIMING
  88732. timeDiff = gettime_secs() - timeDiff;
  88733. #endif
  88734. #ifndef WOLFSSL_UNIT_TEST_NO_TIMING
  88735. if (ret != TEST_SKIPPED) {
  88736. printf(" %s (%9.5lf)\n", apitest_res_string(ret), timeDiff);
  88737. }
  88738. else
  88739. #endif
  88740. {
  88741. printf(" %s\n", apitest_res_string(ret));
  88742. }
  88743. fflush(stdout);
  88744. /* if return code is < 0 and not skipped then assert error */
  88745. Expect((ret > 0 || ret == TEST_SKIPPED),
  88746. ("Test failed\n"),
  88747. ("ret %d", ret));
  88748. testCases[i].fail = ((ret <= 0) && (ret != TEST_SKIPPED));
  88749. res |= ((ret <= 0) && (ret != TEST_SKIPPED));
  88750. TestCleanup();
  88751. }
  88752. }
  88753. #if defined(HAVE_ECC) && defined(FP_ECC) && defined(HAVE_THREAD_LS) \
  88754. && (defined(NO_MAIN_DRIVER) || defined(HAVE_STACK_SIZE))
  88755. wc_ecc_fp_free(); /* free per thread cache */
  88756. #endif
  88757. if (!testAll) {
  88758. #ifdef WOLFCRYPT_ONLY
  88759. wolfCrypt_Cleanup();
  88760. #else
  88761. wolfSSL_Cleanup();
  88762. #endif
  88763. }
  88764. (void)testDevId;
  88765. if (res != 0) {
  88766. printf("\nFAILURES:\n");
  88767. for (i = 0; i < TEST_CASE_CNT; ++i) {
  88768. if (testCases[i].fail) {
  88769. printf(" %3d: %s\n", i + 1, testCases[i].name);
  88770. }
  88771. }
  88772. printf("\n");
  88773. fflush(stdout);
  88774. }
  88775. #ifdef WOLFSSL_DUMP_MEMIO_STREAM
  88776. if (tmpDirNameSet) {
  88777. printf("\nBinary dumps of the memio streams can be found in the\n"
  88778. "%s directory. This can be imported into\n"
  88779. "Wireshark by transforming the file with\n"
  88780. "\tod -Ax -tx1 -v stream.dump > stream.dump.hex\n"
  88781. "And then loading test_output.dump.hex into Wireshark using\n"
  88782. "the \"Import from Hex Dump...\" option and selecting the\n"
  88783. "TCP encapsulation option.\n", tmpDirName);
  88784. }
  88785. #endif
  88786. printf(" End API Tests\n");
  88787. fflush(stdout);
  88788. return res;
  88789. }